Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

iwaseyusuke
Copy link
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 <[email protected]>
@@ -231,18 +231,18 @@ func newIPRouteBody(dst pathList) (body *zebra.IPRouteBody, isWithdraw bool) {
switch path.GetRouteFamily() {
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()

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