All checks were successful
Documentation / publish (push) Successful in 2m55s
Release Pipeline / set-release-target (push) Successful in 3s
Release Pipeline / upload-assets (run-dnsmasq-in-netns.sh, scripts/run-dnsmasq-in-netns.sh) (push) Successful in 7s
Release Pipeline / checksums (push) Successful in 9s
Release Pipeline / upload-assets (agent.service, systemd/agent.service) (push) Successful in 8s
Release Pipeline / upload-assets (dhcp@.service, systemd/dhcp@.service) (push) Successful in 7s
Release Pipeline / upload-assets (dnsmasq@.service, systemd/dnsmasq@.service) (push) Successful in 7s
Release Pipeline / upload-assets (metadata@.service, systemd/metadata@.service) (push) Successful in 7s
Release Pipeline / upload-assets (run-dhcp-in-netns.sh, scripts/run-dhcp-in-netns.sh) (push) Successful in 7s
Release Pipeline / build (agent, amd64, linux) (push) Successful in 0s
Release Pipeline / build (dhcp, amd64, linux) (push) Successful in 0s
Release Pipeline / build (metadata, amd64, linux) (push) Successful in 0s
Release Pipeline / release (push) Successful in 32s
Release Pipeline / publish (push) Successful in 0s
Release Pipeline / build (push) Successful in 2m12s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package netif
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/vishvananda/netlink"
|
|
)
|
|
|
|
func addr(cidr string, scope, flags int) netlink.Addr {
|
|
ip, network, err := net.ParseCIDR(cidr)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
network.IP = ip
|
|
return netlink.Addr{IPNet: network, Scope: scope, Flags: flags}
|
|
}
|
|
|
|
func TestVtepAddress_PicksThePrimaryGlobalIPv4(t *testing.T) {
|
|
addrs := []netlink.Addr{
|
|
addr("127.0.0.1/8", 254, 0),
|
|
addr("169.254.0.3/28", 0, 0x01),
|
|
addr("192.168.14.11/24", 0, 0x80),
|
|
addr("192.168.14.99/24", 0, 0x01),
|
|
}
|
|
got, err := vtepAddress("br-000000", addrs)
|
|
if err != nil || got.String() != "192.168.14.11" {
|
|
t.Errorf("vtepAddress = %v, %v, want 192.168.14.11", got, err)
|
|
}
|
|
}
|
|
|
|
func TestVtepAddress_SkipsLinkScopeAndSecondaryAddresses(t *testing.T) {
|
|
addrs := []netlink.Addr{
|
|
addr("169.254.0.3/28", 253, 0),
|
|
addr("192.168.14.99/24", 0, 0x01),
|
|
addr("192.168.14.12/24", 0, 0),
|
|
}
|
|
got, err := vtepAddress("br-000000", addrs)
|
|
if err != nil || got.String() != "192.168.14.12" {
|
|
t.Errorf("vtepAddress = %v, %v, want 192.168.14.12", got, err)
|
|
}
|
|
}
|
|
|
|
func TestVtepAddress_RefusesAnInterfaceWithoutUsableAddress(t *testing.T) {
|
|
for name, addrs := range map[string][]netlink.Addr{
|
|
"no address": nil,
|
|
"only secondary": {addr("192.168.14.99/24", 0, 0x01)},
|
|
"only link": {addr("169.254.0.3/28", 253, 0)},
|
|
"only IPv6": {addr("fd00::11/64", 0, 0)},
|
|
} {
|
|
_, err := vtepAddress("br-000000", addrs)
|
|
if err == nil || !strings.Contains(err.Error(), "no primary global IPv4 address on br-000000") {
|
|
t.Errorf("%s: error = %v", name, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestVtepAddress_ReturnsAFourByteAddress(t *testing.T) {
|
|
got, err := vtepAddress("br-000000", []netlink.Addr{addr("192.168.14.11/24", 0, 0)})
|
|
if err != nil || len(got) != 4 {
|
|
t.Errorf("vtepAddress = %v (%d bytes), %v", got, len(got), err)
|
|
}
|
|
}
|