Skip to content

packet/bgp: Reduce struct size of "IPAddrPrefix" struct#1612

Open
iwaseyusuke wants to merge 3 commits intoosrg:masterfrom
iwaseyusuke:packet-bgp-Reduce_struct_size_of_IPAddrPrefix
Open

packet/bgp: Reduce struct size of "IPAddrPrefix" struct#1612
iwaseyusuke wants to merge 3 commits intoosrg:masterfrom
iwaseyusuke:packet-bgp-Reduce_struct_size_of_IPAddrPrefix

Conversation

@iwaseyusuke
Copy link
Copy Markdown
Contributor

This patch refactors the inheritance (embedding) relationship of IPAddrPrefix and its derivatives and removes "addrlen" field. "addrlen" is used only to determine whether the given prefix is IPv4 or IPv6.

This patch refactors the inheritance (embedding) relationship of
IPAddrPrefix and its derivatives and removes "addrlen" field. "addrlen"
is used only to determine whether the given prefix is IPv4 or IPv6.

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Comment thread server/zclient.go
case bgp.RF_IPv4_UC, bgp.RF_IPv4_VPN:
if path.GetRouteFamily() == bgp.RF_IPv4_UC {
prefix = path.GetNlri().(*bgp.IPAddrPrefix).IPAddrPrefixDefault.Prefix.To4()
prefix = path.GetNlri().(*bgp.IPAddrPrefix).Prefix.To4()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be refactored to future proof the code from panics, even if currently this is highly unlikely, i.e.:

switch T := path.GetNlri().(type) {
case *bgp.IPAddrPrefix:
  prefix = T.Prefix.To4()
case *bgp.LabeledVPNIPAddrPrefix):
  ...
default:
  ... what is sane in this case? Right now that is a panic about concrete types, can we do better?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants