Fixing an issue where packets are dropped each time

we change wg configuration
This commit is contained in:
Tim Beatham
2023-11-01 10:39:46 +00:00
parent a1caf2e8ae
commit e63edea763
6 changed files with 30 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
package wg
import (
"errors"
"fmt"
"net"
"os/exec"
@@ -75,19 +76,29 @@ func flushInterface(ifName string) error {
// EnableInterface flushes the interface and sets the ip address of the
// interface
func (m *WgInterfaceManipulatorImpl) EnableInterface(ifName string, ip string) error {
if len(ifName) == 0 {
return errors.New("ifName not provided")
}
err := flushInterface(ifName)
if err != nil {
return err
}
cmd := exec.Command("/usr/bin/ip", "link", "set", "up", "dev", ifName)
if err := cmd.Run(); err != nil {
return err
}
hostIp, _, err := net.ParseCIDR(ip)
if err != nil {
return err
}
cmd := exec.Command("/usr/bin/ip", "addr", "add", hostIp.String()+"/64", "dev", ifName)
cmd = exec.Command("/usr/bin/ip", "addr", "add", hostIp.String()+"/64", "dev", ifName)
if err := cmd.Run(); err != nil {
return err