allow configuring extra addresses on interfaces
Useful when you need IPv6 and IPv4 addresses on a WireGuard tunnel.
This commit is contained in:
parent
40f8eb5b1b
commit
f52deeed03
@ -50,7 +50,10 @@ const goldenInterfaces = `
|
||||
},
|
||||
{
|
||||
"name": "wg0",
|
||||
"addr": "fe80::1/64"
|
||||
"addr": "fe80::1/64",
|
||||
"extra_addrs": [
|
||||
"10.22.100.1/24"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -461,6 +464,12 @@ peer: AVU3LodtnFaFnJmMyNNW7cUk4462lqnVULTFkjWYvRo=
|
||||
if !upRe.MatchString(string(out)) {
|
||||
t.Errorf("regexp %s does not match %s", upRe, string(out))
|
||||
}
|
||||
|
||||
addr4Re := regexp.MustCompile(`(?m)^\s*inet 10.22.100.1/24 brd 10.22.100.255 scope global wg0\s*$`)
|
||||
if !addr4Re.MatchString(string(out)) {
|
||||
t.Errorf("regexp %s does not match %s", addr4Re, string(out))
|
||||
}
|
||||
|
||||
addr6Re := regexp.MustCompile(`(?m)^\s*inet6 fe80::1/64 scope link\s*$`)
|
||||
if !addr6Re.MatchString(string(out)) {
|
||||
t.Errorf("regexp %s does not match %s", addr6Re, string(out))
|
||||
|
@ -196,6 +196,7 @@ type InterfaceDetails struct {
|
||||
SpoofHardwareAddr string `json:"spoof_hardware_addr"` // e.g. dc:9b:9c:ee:72:fd
|
||||
Name string `json:"name"` // e.g. uplink0, or lan0
|
||||
Addr string `json:"addr"` // e.g. 192.168.42.1/24
|
||||
ExtraAddrs []string `json:"extra_addrs"` // e.g. ["192.168.23.1/24"]
|
||||
}
|
||||
|
||||
type BridgeDetails struct {
|
||||
@ -399,6 +400,20 @@ func applyInterfaces(dir, root string) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, addr := range details.ExtraAddrs {
|
||||
addr, err := netlink.ParseAddr(addr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ParseAddr(%q): %v", addr, err)
|
||||
}
|
||||
|
||||
if err := netlink.AddrReplace(l, addr); err != nil {
|
||||
return fmt.Errorf("AddrReplace(%s, %v): %v", attr.Name, addr, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: allow static route configuration (ExtraRoutes)
|
||||
// 2a02:168:4a00:22::/64 via fe80::2 dev wg0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user