diff --git a/yabgp/config.py b/yabgp/config.py index 8addda7..590bf4e 100644 --- a/yabgp/config.py +++ b/yabgp/config.py @@ -91,11 +91,11 @@ help='The remote BGP peer AS number'), cfg.IntOpt('local_as', help='The Local BGP AS number'), - cfg.StrOpt('remote_addr', - help='The remote address of the peer'), - cfg.StrOpt('local_addr', - default='0.0.0.0', - help='The local address of the BGP'), + cfg.IPOpt('remote_addr', + help='The remote address of the peer'), + cfg.IPOpt('local_addr', + default='0.0.0.0', + help='The local address of the BGP'), cfg.StrOpt('md5', help='The MD5 string use to auth', secret=True), diff --git a/yabgp/message/attribute/mpreachnlri.py b/yabgp/message/attribute/mpreachnlri.py index 865408f..d829833 100644 --- a/yabgp/message/attribute/mpreachnlri.py +++ b/yabgp/message/attribute/mpreachnlri.py @@ -118,7 +118,7 @@ def parse(cls, value): else: nlri = repr(nlri_bin) - return dict(afi_safi=(afi, safi), nexthop=nexthop_bin, nlri=nlri) + return dict(afi_safi=(afi, safi), nexthop=nexthop_bin, nlri=nlri_bin) @classmethod def construct(cls, value): @@ -143,7 +143,7 @@ def construct(cls, value): nlri = IPv4FlowSpec.construct(value=value['nlri']) if nlri: attr_value = struct.pack('!H', afi) + struct.pack('!B', safi) + \ - struct.pack('!B', len(nexthop)) + nexthop + '\x00' + nlri + struct.pack('!B', len(nexthop)) + nexthop + b'\x00' + nlri return struct.pack('!B', cls.FLAG) + struct.pack('!B', cls.ID) \ + struct.pack('!B', len(attr_value)) + attr_value except Exception as e: diff --git a/yabgp/message/attribute/nlri/ipv6_unicast.py b/yabgp/message/attribute/nlri/ipv6_unicast.py index 8ff68d4..52a6991 100644 --- a/yabgp/message/attribute/nlri/ipv6_unicast.py +++ b/yabgp/message/attribute/nlri/ipv6_unicast.py @@ -31,15 +31,20 @@ def parse(nlri_data): """ nlri_list = [] while nlri_data: - prefix_bit_len = struct.unpack('!B', nlri_data[0])[0] + if isinstance(nlri_data[0], int): + prefix_bit_len = int(nlri_data[0]) + else: + prefix_bit_len = struct.unpack('!B', nlri_data[0])[0] + print (type(nlri_data)) if prefix_bit_len % 8 == 0: prefix_byte_len = prefix_bit_len / 8 else: prefix_byte_len = prefix_bit_len / 8 + 1 - prefix_addr = netaddr.IPAddress(int(binascii.b2a_hex(nlri_data[1:prefix_byte_len + 1]), 16)).__str__() \ + offset = int(prefix_byte_len + 1) + prefix_addr = str(netaddr.IPAddress(int(binascii.b2a_hex(nlri_data[1:offset]), 16))) \ + '/%s' % prefix_bit_len nlri_list.append(prefix_addr) - nlri_data = nlri_data[prefix_byte_len + 1:] + nlri_data = nlri_data[int(prefix_byte_len) + 1:] return nlri_list