-
Notifications
You must be signed in to change notification settings - Fork 0
/
if.go
41 lines (35 loc) · 779 Bytes
/
if.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
//go:build !darwin
// +build !darwin
package main
import (
"github.com/songgao/water"
"github.com/vishvananda/netlink"
)
func newif(name string) (*water.Interface, error) {
config := water.Config{
DeviceType: water.TUN,
// PlatformSpecificParams: water.PlatformSpecificParams{Persist: !c.NetLinkBootstrap},
}
config.Name = name
return water.New(config)
}
func applyif(name, address string) error {
link, err := netlink.LinkByName(name)
if err != nil {
return err
}
addr, err := netlink.ParseAddr(address)
if err != nil {
return err
}
if err := netlink.LinkSetMTU(link, MTU); err != nil {
return err
}
if err := netlink.AddrAdd(link, addr); err != nil {
return err
}
if err := netlink.LinkSetUp(link); err != nil {
return err
}
return nil
}