(n *Nylon)
| 19 | } |
| 20 | |
| 21 | func NewWireGuardDevice(n *Nylon) (dev *device.Device, tunDevice tun.Device, realItf string, err error) { |
| 22 | x := n.AuxConfig["vnet"] |
| 23 | if x == nil { |
| 24 | return nil, nil, "", fmt.Errorf("expected aux config \"vnet\", but it was not present") |
| 25 | } |
| 26 | vn := x.(VirtualNet) |
| 27 | |
| 28 | itfName := "nylon-vn" |
| 29 | |
| 30 | bind := vn.Bind(n.LocalCfg.Id) |
| 31 | tdev := vn.Tun(n.LocalCfg.Id) |
| 32 | |
| 33 | wgLog := n.Log.With("module", log.ScopePolyamide) |
| 34 | |
| 35 | // setup WireGuard |
| 36 | dev = device.NewDevice(tdev, bind, &device.Logger{ |
| 37 | Verbosef: func(format string, args ...any) { |
| 38 | if n.DBG_log_wireguard { |
| 39 | wgLog.Debug(fmt.Sprintf(format, args...)) |
| 40 | } |
| 41 | }, |
| 42 | Errorf: func(format string, args ...any) { |
| 43 | if strings.Contains(format, "Failed to send PolySock packets") { |
| 44 | return |
| 45 | } |
| 46 | wgLog.Error(fmt.Sprintf(format, args...)) |
| 47 | }, |
| 48 | }) |
| 49 | |
| 50 | n.Log.Info("Created WireGuard interface", "name", itfName) |
| 51 | return dev, tdev, itfName, nil |
| 52 | } |
| 53 | |
| 54 | func CleanupWireGuardDevice(n *Nylon) error { |
| 55 | if n.Device != nil { |
no test coverage detected