libnet/d/bridge: fix bridgeInterface.addresses()
addresses() would incorrectly return all IP addresses assigned to any interface in the network namespace if exists() is false. This went unnoticed as the unit test covering this case tested the method inside a clean new network namespace, which had no interfaces brought up and therefore no IP addresses assigned. Modifying testutils.SetupTestOSContext() to bring up the loopback interface 'lo' resulted in the loopback addresses 127.0.0.1 and [::1] being assigned to the loopback interface, causing addresses() to return the loopback addresses and TestAddressesEmptyInterface to start failing. Fix the implementation of addresses() so that it only ever returns addresses for the bridge interface. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
parent
c2a087a9f7
commit
7b2308980c
1 changed files with 4 additions and 0 deletions
|
@ -57,6 +57,10 @@ func (i *bridgeInterface) exists() bool {
|
|||
|
||||
// addresses returns all IPv4 addresses and all IPv6 addresses for the bridge interface.
|
||||
func (i *bridgeInterface) addresses() ([]netlink.Addr, []netlink.Addr, error) {
|
||||
if !i.exists() {
|
||||
// A nonexistent interface, by definition, cannot have any addresses.
|
||||
return nil, nil, nil
|
||||
}
|
||||
v4addr, err := i.nlh.AddrList(i.Link, netlink.FAMILY_V4)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Failed to retrieve V4 addresses: %v", err)
|
||||
|
|
Loading…
Reference in a new issue