-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface_linux.go
49 lines (42 loc) · 955 Bytes
/
interface_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//go:build !tun
// +build !tun
package l2
import (
"fmt"
"net"
"github.com/songgao/water"
"github.com/vishvananda/netlink"
)
func (Network) Interface(
localNode *Node,
ipnet net.IPNet,
mtu MTU,
) Interface {
interfaceType := water.DeviceType(water.TAP)
iface, err := water.New(water.Config{
DeviceType: interfaceType,
PlatformSpecificParams: water.PlatformSpecificParams{
Name: fmt.Sprintf("L2-%s-%d", localNode.LanIP.String(), localNode.ID),
MultiQueue: true,
},
})
ce.WithInfo("new interface")(err)
link, err := netlink.LinkByName(iface.Name())
ce(err)
hwAddr := ip2Mac(localNode.LanIP)
ce(netlink.LinkSetHardwareAddr(link, hwAddr))
err = netlink.LinkSetUp(link)
ce(err)
err = netlink.AddrAdd(link, &netlink.Addr{
IPNet: &net.IPNet{
IP: localNode.LanIP,
Mask: ipnet.Mask,
},
})
ce(err)
err = netlink.LinkSetMTU(link, int(mtu))
ce(err)
err = netlink.SetPromiscOn(link)
ce(err)
return iface
}