From ee328e731d14e6de370f29bd747e80d1596e533b Mon Sep 17 00:00:00 2001 From: Ananth Suryanarayana Date: Thu, 18 Aug 2016 15:54:12 -0700 Subject: [PATCH] Drop multicast routes associated with invalid label range Labels have to be non-zero numbers Change-Id: I634f46610eca3240fc7d184b6ebf6529ac92088a Closes-Bug: #1614770 --- src/bgp/bgp_xmpp_channel.cc | 8 ++++++++ src/bgp/test/bgp_xmpp_parse_test.cc | 24 +++++++++++++++++++++++ src/bgp/testdata/bad_mcast_item_12.xml | 27 ++++++++++++++++++++++++++ src/bgp/testdata/bad_mcast_item_13.xml | 27 ++++++++++++++++++++++++++ src/bgp/testdata/bad_mcast_item_14.xml | 27 ++++++++++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 src/bgp/testdata/bad_mcast_item_12.xml create mode 100644 src/bgp/testdata/bad_mcast_item_13.xml create mode 100644 src/bgp/testdata/bad_mcast_item_14.xml diff --git a/src/bgp/bgp_xmpp_channel.cc b/src/bgp/bgp_xmpp_channel.cc index c2a38d4ce70..3b2cf4967b5 100644 --- a/src/bgp/bgp_xmpp_channel.cc +++ b/src/bgp/bgp_xmpp_channel.cc @@ -1111,6 +1111,14 @@ bool BgpXmppChannel::ProcessMcastItem(string vrf_name, return false; } + if (!labels[0] || !labels[1] || labels[1] < labels[0]) { + BGP_LOG_PEER_INSTANCE(Peer(), vrf_name, + SandeshLevel::SYS_WARN, BGP_LOG_FLAG_ALL, + "Bad label range " << label_range << + " for multicast route " << mc_prefix.ToString()); + return false; + } + BgpAttrSpec attrs; LabelBlockPtr lbptr = lb_mgr_->LocateBlock(labels[0], labels[1]); diff --git a/src/bgp/test/bgp_xmpp_parse_test.cc b/src/bgp/test/bgp_xmpp_parse_test.cc index 8ae56baa41a..7c74936d3cb 100644 --- a/src/bgp/test/bgp_xmpp_parse_test.cc +++ b/src/bgp/test/bgp_xmpp_parse_test.cc @@ -336,6 +336,30 @@ TEST_F(BgpXmppParseTest, McastItemError11) { EXPECT_FALSE(ProcessMcastItem(item)); } +// Error in nexthop label with min label as 0 +TEST_F(BgpXmppParseTest, McastItemError12) { + string data = FileRead("controller/src/bgp/testdata/bad_mcast_item_12.xml"); + impl_->LoadDoc(data); + xml_node item = pugi_->FindNode("item"); + EXPECT_FALSE(ProcessMcastItem(item)); +} + +// Error in nexthop label with both labels as 0 +TEST_F(BgpXmppParseTest, McastItemError13) { + string data = FileRead("controller/src/bgp/testdata/bad_mcast_item_13.xml"); + impl_->LoadDoc(data); + xml_node item = pugi_->FindNode("item"); + EXPECT_FALSE(ProcessMcastItem(item)); +} + +// Error in nexthop label with right label in the range less then left label +TEST_F(BgpXmppParseTest, McastItemError14) { + string data = FileRead("controller/src/bgp/testdata/bad_mcast_item_14.xml"); + impl_->LoadDoc(data); + xml_node item = pugi_->FindNode("item"); + EXPECT_FALSE(ProcessMcastItem(item)); +} + // Error in parsing message, XML document is fine. TEST_F(BgpXmppParseTest, EnetItemError1) { string data = FileRead("controller/src/bgp/testdata/bad_enet_item_1.xml"); diff --git a/src/bgp/testdata/bad_mcast_item_12.xml b/src/bgp/testdata/bad_mcast_item_12.xml new file mode 100644 index 00000000000..0cc742aed13 --- /dev/null +++ b/src/bgp/testdata/bad_mcast_item_12.xml @@ -0,0 +1,27 @@ + + + + 1 + 241 + 255.255.255.255 + 10.1.1.1 + + + + 1 +
192.168.1.1
+ + + gre + +
+
+ 1 + + 0 + + 7999998> + + 100 +
+
diff --git a/src/bgp/testdata/bad_mcast_item_13.xml b/src/bgp/testdata/bad_mcast_item_13.xml new file mode 100644 index 00000000000..5356fb36199 --- /dev/null +++ b/src/bgp/testdata/bad_mcast_item_13.xml @@ -0,0 +1,27 @@ + + + + 1 + 241 + 255.255.255.255 + 10.1.1.1 + + + + 1 +
192.168.1.1
+ + + gre + +
+
+ 1 + + 0 + + 7999998> + + 100 +
+
diff --git a/src/bgp/testdata/bad_mcast_item_14.xml b/src/bgp/testdata/bad_mcast_item_14.xml new file mode 100644 index 00000000000..efd972c565c --- /dev/null +++ b/src/bgp/testdata/bad_mcast_item_14.xml @@ -0,0 +1,27 @@ + + + + 1 + 241 + 255.255.255.255 + 10.1.1.1 + + + + 1 +
192.168.1.1
+ + + gre + +
+
+ 1 + + 0 + + 7999998> + + 100 +
+