MCPcopy Create free account
hub / github.com/encodeous/nylon / NewWireGuardDevice

Function NewWireGuardDevice

core/sys_virtual.go:21–52  ·  view source on GitHub ↗
(n *Nylon)

Source from the content-addressed store, hash-verified

19}
20
21func 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
54func CleanupWireGuardDevice(n *Nylon) error {
55 if n.Device != nil {

Callers 1

initWireGuardMethod · 0.70

Calls 4

NewDeviceFunction · 0.92
BindMethod · 0.65
TunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected