From a25522edddf05653bef26c5ff220f34f7354791f Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Mon, 26 Feb 2018 16:55:04 +0900 Subject: packet/bgp: Return nil for invalid redirect IP address 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 --- packet/bgp/bgp.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'packet/bgp/bgp.go') diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 17b53f29..2fea8b44 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -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 { @@ -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 { -- cgit v1.2.3