mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-12 18:00:49 +01:00
e6e9f0322f
Before this change, NetBird Agent wasn't handling peer interface configuration changes dynamically. Also, remote peer configuration changes have not been applied (e.g. AllowedIPs changed). Not a very common cause, but still it should be handled. Now, Agent reacts to PeerConfig changes sent from the management service and restarts remote connections if AllowedIps have been changed.
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package iface
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
"os/exec"
|
|
)
|
|
|
|
// Create Creates a new Wireguard interface, sets a given IP and brings it up.
|
|
func (w *WGIface) Create() error {
|
|
w.mu.Lock()
|
|
defer w.mu.Unlock()
|
|
|
|
return w.createWithUserspace()
|
|
}
|
|
|
|
// assignAddr Adds IP address to the tunnel interface and network route based on the range provided
|
|
func (w *WGIface) assignAddr() error {
|
|
//mask,_ := w.Address.Network.Mask.Size()
|
|
//
|
|
//address := fmt.Sprintf("%s/%d",w.Address.IP.String() , mask)
|
|
|
|
cmd := exec.Command("ifconfig", w.Name, "inet", w.Address.IP.String(), w.Address.IP.String())
|
|
if out, err := cmd.CombinedOutput(); err != nil {
|
|
log.Infof("adding addreess command \"%v\" failed with output %s and error: ", cmd.String(), out)
|
|
return err
|
|
}
|
|
|
|
routeCmd := exec.Command("route", "add", "-net", w.Address.Network.String(), "-interface", w.Name)
|
|
if out, err := routeCmd.CombinedOutput(); err != nil {
|
|
log.Printf("adding route command \"%v\" failed with output %s and error: ", routeCmd.String(), out)
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|