mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-08-19 01:15:58 +02:00
Fixing an issue where packets are dropped each time
we change wg configuration
This commit is contained in:
13
pkg/wg/wg.go
13
pkg/wg/wg.go
@@ -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
|
||||
|
Reference in New Issue
Block a user