Select Git revision
takt
authored and
Daniel Czerwonk
committed
* Add caches * Replace IPs and Prefixes with pointers to these * Fix nil pointer derefs * Fix nil pointer deref * Fix community encoding * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix tests * Fix BGP path hashing * Fix path attr decoding * Fix tests * Fix tests * Fix tests * Fix tests * Cleanup * Cleanup * Revert config change * Fix Benchmark. Fix ClusterList PA. * Fix ClusterList tests * Add client * Remove stale test * Cleanup * Increase verbosity on decode failure * Improve chache layer performance * Improve bgp path cache performance * Cleanup
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
helper.go 800 B
package packet
import (
"fmt"
bnet "github.com/bio-routing/bio-rd/net"
)
func serializePrefix(pfx bnet.Prefix) []byte {
if pfx.Pfxlen() == 0 {
return []byte{}
}
numBytes := BytesInAddr(pfx.Pfxlen())
b := make([]byte, numBytes+1)
b[0] = pfx.Pfxlen()
copy(b[1:numBytes+1], pfx.Addr().Bytes()[0:numBytes])
return b
}
func deserializePrefix(b []byte, pfxLen uint8, afi uint16) (*bnet.Prefix, error) {
numBytes := BytesInAddr(pfxLen)
if numBytes != uint8(len(b)) {
return nil, fmt.Errorf("could not parse prefix of length %d. Expected %d bytes, got %d", pfxLen, numBytes, len(b))
}
ipBytes := make([]byte, afiAddrLenBytes[afi])
copy(ipBytes, b)
ip, err := bnet.IPFromBytes(ipBytes)
if err != nil {
return nil, err
}
return bnet.NewPfx(ip.Dedup(), pfxLen).Dedup(), nil
}