Set ip if configured, otherwise just bring up link
This commit is contained in:
parent
e719f111f1
commit
7aa7548df6
10
up.go
10
up.go
@ -17,6 +17,8 @@ func RunPostUp(conf *DsnetConfig) {
|
|||||||
ShellOut(conf.PostUp, "PostUp")
|
ShellOut(conf.PostUp, "PostUp")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateLink sets up the WG interface and link with the correct
|
||||||
|
// address
|
||||||
func CreateLink(conf *DsnetConfig) {
|
func CreateLink(conf *DsnetConfig) {
|
||||||
linkAttrs := netlink.NewLinkAttrs()
|
linkAttrs := netlink.NewLinkAttrs()
|
||||||
linkAttrs.Name = conf.InterfaceName
|
linkAttrs.Name = conf.InterfaceName
|
||||||
@ -31,6 +33,7 @@ func CreateLink(conf *DsnetConfig) {
|
|||||||
ExitFail("Could not add interface '%s' (%v)", conf.InterfaceName, err)
|
ExitFail("Could not add interface '%s' (%v)", conf.InterfaceName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.IP != nil {
|
||||||
addr := &netlink.Addr{
|
addr := &netlink.Addr{
|
||||||
IPNet: &net.IPNet{
|
IPNet: &net.IPNet{
|
||||||
IP: conf.IP,
|
IP: conf.IP,
|
||||||
@ -40,9 +43,11 @@ func CreateLink(conf *DsnetConfig) {
|
|||||||
|
|
||||||
err = netlink.AddrAdd(link, addr)
|
err = netlink.AddrAdd(link, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ExitFail("Could not add addr %s to interface %s", addr.IP, err)
|
ExitFail("Could not add ipv4 addr %s to interface %s", addr.IP, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.IP6 != nil {
|
||||||
addr6 := &netlink.Addr{
|
addr6 := &netlink.Addr{
|
||||||
IPNet: &net.IPNet{
|
IPNet: &net.IPNet{
|
||||||
IP: conf.IP6,
|
IP: conf.IP6,
|
||||||
@ -52,7 +57,8 @@ func CreateLink(conf *DsnetConfig) {
|
|||||||
|
|
||||||
err = netlink.AddrAdd(link, addr6)
|
err = netlink.AddrAdd(link, addr6)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ExitFail("Could not add addr %s to interface %s", addr.IP, err)
|
ExitFail("Could not add ipv6 addr %s to interface %s", addr6.IP, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bring up interface (UNKNOWN state instead of UP, a wireguard quirk)
|
// bring up interface (UNKNOWN state instead of UP, a wireguard quirk)
|
||||||
|
Loading…
Reference in New Issue
Block a user