def unpack(cls, afi, safi, data, addpath, nexthop, action): labels, rd, path_identifier, mask, size, prefix, left = NLRI._nlri( afi, safi, data, action, addpath) nlri = cls(afi, safi, prefix, mask, nexthop, action) if path_identifier: nlri.path_info = PathInfo(None, None, path_identifier) return len(data) - len(left), nlri
def unpack (cls,afi,safi,bgp,addpath,nexthop,action): labels,rd,mask,size,prefix,left = NLRI._nlri(afi,safi,bgp,action) nlri = cls(afi,safi,prefix,mask,nexthop,action) if labels: nlri.labels = Labels(labels) if rd: nlri.rd = RouteDistinguisher(rd) return len(bgp) - len(left),nlri
def unpack (cls,afi,safi,bgp,addpath,nexthop,action): labels,rd,path_identifier,mask,size,prefix,left = NLRI._nlri(afi,safi,bgp,action,addpath) nlri = cls(afi,safi,prefix,mask,nexthop,action) if labels: nlri.labels = Labels(labels) if rd: nlri.rd = RouteDistinguisher(rd) if path_identifier: nlri.path_info = PathInfo(None,None,path_identifier) return len(bgp) - len(left),nlri
def unpack(cls, afi, safi, bgp, addpath, nexthop, action): labels, rd, path_identifier, mask, size, prefix, left = NLRI._nlri( afi, safi, bgp, action, addpath) nlri = cls(afi, safi, prefix, mask, nexthop, action) if labels: nlri.labels = Labels(labels) if rd: nlri.rd = RouteDistinguisher(rd) if path_identifier: nlri.path_info = PathInfo(None, None, path_identifier) return len(bgp) - len(left), nlri
def unpack (cls,afi,safi,data,addpath,nexthop,action): if addpath: path_identifier = PathInfo(None,None,data[:4]) data = data[4:] length = 4 else: path_identifier = None length = 0 labels,rd,mask,size,prefix,left = NLRI._nlri(afi,safi,data,action) nlri = cls(afi,safi,prefix,mask,nexthop,action) if addpath: nlri.path_info = path_identifier return length + len(data) - len(left),nlri
def unpack(cls, afi, safi, data, addpath, nexthop, action): if addpath: path_identifier = PathInfo(None, None, data[:4]) data = data[4:] length = 4 else: path_identifier = None length = 0 labels, rd, mask, size, prefix, left = NLRI._nlri( afi, safi, data, action) nlri = cls(afi, safi, prefix, mask, nexthop, action) if addpath: nlri.path_info = path_identifier return length + len(data) - len(left), nlri
def unpack (cls,afi,safi,bgp,has_multiple_path,nexthop,action): total = len(bgp) length,bgp = ord(bgp[0]),bgp[1:] if length & 0xF0 == 0xF0: # bigger than 240 extra,bgp = ord(bgp[0]),bgp[1:] length = ((length & 0x0F) << 16) + extra if length > len(bgp): raise Notify(3,10,'invalid length at the start of the the flow') bgp = bgp[:length] nlri = Flow(afi,safi,nexthop) nlri.action = action if safi == SAFI.flow_vpn: nlri.rd = RouteDistinguisher(bgp[:8]) bgp = bgp[8:] seen = [] while bgp: what,bgp = ord(bgp[0]),bgp[1:] if what not in decode.get(afi,{}): raise Notify(3,10,'unknown flowspec component received for address family %d' % what) seen.append(what) if sorted(seen) != seen: raise Notify(3,10,'components are not sent in the right order %s' % seen) decoder = decode[afi][what] klass = factory[afi][what] if decoder == 'prefix': if afi == AFI.ipv4: _,rd,mask,size,prefix,left = NLRI._nlri(afi,safi,bgp,action) adding = klass(prefix,mask) if not nlri.add(adding): raise Notify(3,10,'components are incompatible (two sources, two destinations, mix ipv4/ipv6) %s' % seen) # logger.parser(LazyFormat("added flow %s (%s) payload " % (klass.NAME,adding),od,bgp[:-len(left)])) bgp = left else: byte,bgp = bgp[1],bgp[0]+bgp[2:] offset = ord(byte) _,rd,mask,size,prefix,left = NLRI._nlri(afi,safi,bgp,action) adding = klass(prefix,mask,offset) if not nlri.add(adding): raise Notify(3,10,'components are incompatible (two sources, two destinations, mix ipv4/ipv6) %s' % seen) # logger.parser(LazyFormat("added flow %s (%s) payload " % (klass.NAME,adding),od,bgp[:-len(left)])) bgp = left else: end = False while not end: byte,bgp = ord(bgp[0]),bgp[1:] end = CommonOperator.eol(byte) operator = CommonOperator.operator(byte) length = CommonOperator.length(byte) value,bgp = bgp[:length],bgp[length:] adding = klass.decoder(value) nlri.add(klass(operator,adding)) # logger.parser(LazyFormat("added flow %s (%s) operator %d len %d payload " % (klass.NAME,adding,byte,length),od,value)) return total-len(bgp),nlri
def unpack(cls, afi, safi, bgp, has_multiple_path, nexthop, action): total = len(bgp) length, bgp = ord(bgp[0]), bgp[1:] if length & 0xF0 == 0xF0: # bigger than 240 extra, bgp = ord(bgp[0]), bgp[1:] length = ((length & 0x0F) << 16) + extra if length > len(bgp): raise Notify(3, 10, 'invalid length at the start of the the flow') bgp = bgp[:length] nlri = Flow(afi, safi, nexthop) nlri.action = action if safi == SAFI.flow_vpn: nlri.rd = RouteDistinguisher(bgp[:8]) bgp = bgp[8:] seen = [] while bgp: what, bgp = ord(bgp[0]), bgp[1:] if what not in decode.get(afi, {}): raise Notify( 3, 10, 'unknown flowspec component received for address family %d' % what) seen.append(what) if sorted(seen) != seen: raise Notify( 3, 10, 'components are not sent in the right order %s' % seen) decoded = decode[afi][what] klass = factory[afi][what] if decoded == 'prefix': if afi == AFI.ipv4: _, rd, _, mask, size, prefix, left = NLRI._nlri( afi, safi, bgp, action, False) adding = klass(prefix, mask) if not nlri.add(adding): raise Notify( 3, 10, 'components are incompatible (two sources, two destinations, mix ipv4/ipv6) %s' % seen) # logger.parser(LazyFormat("added flow %s (%s) payload " % (klass.NAME,adding),bgp[:-len(left)])) bgp = left else: byte, bgp = bgp[1], bgp[0] + bgp[2:] offset = ord(byte) _, rd, _, mask, size, prefix, left = NLRI._nlri( afi, safi, bgp, action, False) adding = klass(prefix, mask, offset) if not nlri.add(adding): raise Notify( 3, 10, 'components are incompatible (two sources, two destinations, mix ipv4/ipv6) %s' % seen) # logger.parser(LazyFormat("added flow %s (%s) payload " % (klass.NAME,adding),bgp[:-len(left)])) bgp = left else: end = False while not end: byte, bgp = ord(bgp[0]), bgp[1:] end = CommonOperator.eol(byte) operator = CommonOperator.operator(byte) length = CommonOperator.length(byte) value, bgp = bgp[:length], bgp[length:] adding = klass.decoder(value) nlri.add(klass(operator, adding)) # logger.parser(LazyFormat("added flow %s (%s) operator %d len %d payload " % (klass.NAME,adding,byte,length),value)) return total - len(bgp), nlri
def unpack (cls, afi, safi, data, addpath, nexthop, action): labels,rd,path_identifier,mask,size,prefix,left = NLRI._nlri(afi,safi,data,action,addpath) nlri = cls(afi,safi,prefix,mask,nexthop,action) if path_identifier: nlri.path_info = PathInfo(None,None,path_identifier) return len(data) - len(left),nlri