From ff064e662af44ab355f7fff6126a2fa672409778 Mon Sep 17 00:00:00 2001 From: Hiroshi Yokoi Date: Fri, 19 Sep 2014 17:24:32 +0900 Subject: [PATCH] bgp: ignore link-local address According to RFC 2545, both a global address and a link-local address can be sent as a next_hop address in BGPUpdate message. Since the link-local address is not needed in Ryu BGP, Ryu BGP ignore it if the address family is IPv6 unicast. Signed-off-by: Hiroshi Yokoi Signed-off-by: FUJITA Tomonori --- ryu/lib/packet/bgp.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py index 60e3b49c..ff6d7afe 100644 --- a/ryu/lib/packet/bgp.py +++ b/ryu/lib/packet/bgp.py @@ -2014,6 +2014,16 @@ class BGPPathAttributeMpReachNLRI(_PathAttribute): elif afi == addr_family.IP: next_hop = addrconv.ipv4.bin_to_text(next_hop_bin) elif afi == addr_family.IP6: + # next_hop_bin can include global address and link-local address + # according to RFC2545. Since a link-local address isn't needed in + # Ryu BGPSpeaker, we ignore it if both addresses were sent. + # The link-local address is supposed to follow after + # a global address and next_hop_len will be 32 bytes, + # so we use the first 16 bytes, which is a global address, + # as a next_hop and change the next_hop_len to 16. + if next_hop_len == 32: + next_hop_bin = next_hop_bin[:16] + next_hop_len = 16 next_hop = addrconv.ipv6.bin_to_text(next_hop_bin) else: raise ValueError('Invalid address familly(%d)' % afi)