mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-08 01:04:47 +01:00
b64f5ffcb4
Small code cleaning in the iface package. These changes necessary to get a clean code in case if we involve more platforms. The OS related functions has been distributed into separate files and it has been mixed with not OS related logic. The goal is to get a clear picture of the layer between WireGuard and business logic.
33 lines
943 B
Go
33 lines
943 B
Go
package iface
|
|
|
|
import (
|
|
"os/exec"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// 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 {
|
|
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
|
|
}
|