From 7acda14a5d8024ea206be03aefd2c06b804e1063 Mon Sep 17 00:00:00 2001 From: Hiroshi Yokoi Date: Thu, 31 Jul 2014 14:59:49 +0900 Subject: bgp: add code to handle RD 0:0 at the head of nexthop network address in MP_REACH_NLRI path attribute The second is patch to add or skip RD 0:0 label for the next_hop address in MP_REACH_NLRI attribute. According to RFC, next_hop address seems to be required to contain RD of 0 when advertise VPN prefix. This is defined in RFC 4659(3.2.1.1. BGP Speaker Requesting IPv6 Transport) for VPN-IPv6 and in RFC 4364(4.3.2. Route Distribution Among PEs by BGP) for VPN-IPv4. Signed-off-by: Hiroshi Yokoi Signed-off-by: FUJITA Tomonori --- ryu/lib/packet/bgp.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py index b077be31..b91ece7e 100644 --- a/ryu/lib/packet/bgp.py +++ b/ryu/lib/packet/bgp.py @@ -1771,6 +1771,7 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute): _VALUE_PACK_STR = '!HBB' # afi, safi, next hop len _ATTR_FLAGS = BGP_ATTR_FLAG_OPTIONAL _class_prefixes = ['_BinAddrPrefix'] + _rd_length = 8 def __init__(self, afi, safi, next_hop, nlri, next_hop_len=0, reserved='\0', @@ -1806,8 +1807,16 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute): while binnlri: n, binnlri = addr_cls.parser(binnlri) nlri.append(n) - if RouteFamily(afi, safi) in (RF_IPv6_UC, RF_IPv6_VPN): + + rf = RouteFamily(afi, safi) + if rf == RF_IPv6_UC: next_hop = addrconv.ipv6.bin_to_text(next_hop_bin) + elif rf == RF_IPv6_VPN: + next_hop = addrconv.ipv6.bin_to_text(next_hop_bin[cls._rd_length:]) + next_hop_len -= cls._rd_length + elif rf == RF_IPv4_VPN: + next_hop = addrconv.ipv4.bin_to_text(next_hop_bin[cls._rd_length:]) + next_hop_len -= cls._rd_length else: next_hop = addrconv.ipv4.bin_to_text(next_hop_bin) return { @@ -1822,12 +1831,22 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute): def serialize_value(self): # fixup self.next_hop_len = len(self._next_hop_bin) + + if RouteFamily(self.afi, self.safi) in (RF_IPv4_VPN, RF_IPv6_VPN): + empty_label_stack = '\x00' * self._rd_length + next_hop_len = len(self._next_hop_bin) + len(empty_label_stack) + next_hop_bin = empty_label_stack + next_hop_bin += self._next_hop_bin + else: + next_hop_len = self.next_hop_len + next_hop_bin = self._next_hop_bin + self.reserved = '\0' buf = bytearray() msg_pack_into(self._VALUE_PACK_STR, buf, 0, self.afi, - self.safi, self.next_hop_len) - buf += self._next_hop_bin + self.safi, next_hop_len) + buf += next_hop_bin buf += self.reserved binnlri = bytearray() for n in self.nlri: -- cgit v1.2.3