Skip to content

Commit

Permalink
packet/bgp: Return nil for invalid redirect IP address
Browse files Browse the repository at this point in the history
When initializing IPv4AddressSpecificExtended or
IPv6AddressSpecificExtended structure, nil value will be returned when
an invalid IP address is given.
But the redirect action extended community types;
 - RedirectIPv4AddressSpecificExtended
 - RedirectIPv6AddressSpecificExtended
which embed IP address specific extended community types, are not aware
of nil value when initializing, so these redirect action extended
community can be unexpectedly initialized with nil value.

This patch fixes to check return value of the embedded structure and
also return nil when failure of initializing it.

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
  • Loading branch information
iwaseyusuke committed Apr 3, 2018
1 parent 9697e9d commit a25522e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packet/bgp/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7280,7 +7280,11 @@ func (e *RedirectIPv4AddressSpecificExtended) GetTypes() (ExtendedCommunityAttrT
}

func NewRedirectIPv4AddressSpecificExtended(ipv4 string, localAdmin uint16) *RedirectIPv4AddressSpecificExtended {
return &RedirectIPv4AddressSpecificExtended{*NewIPv4AddressSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, ipv4, localAdmin, false)}
e := NewIPv4AddressSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, ipv4, localAdmin, false)
if e == nil {
return nil
}
return &RedirectIPv4AddressSpecificExtended{*e}
}

type RedirectIPv6AddressSpecificExtended struct {
Expand Down Expand Up @@ -7312,7 +7316,11 @@ func (e *RedirectIPv6AddressSpecificExtended) GetTypes() (ExtendedCommunityAttrT
}

func NewRedirectIPv6AddressSpecificExtended(ipv6 string, localAdmin uint16) *RedirectIPv6AddressSpecificExtended {
return &RedirectIPv6AddressSpecificExtended{*NewIPv6AddressSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, ipv6, localAdmin, false)}
e := NewIPv6AddressSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, ipv6, localAdmin, false)
if e == nil {
return nil
}
return &RedirectIPv6AddressSpecificExtended{*e}
}

type RedirectFourOctetAsSpecificExtended struct {
Expand Down

0 comments on commit a25522e

Please sign in to comment.