diff --git a/go.mod b/go.mod index 6b7fb2f..4a69e1c 100644 --- a/go.mod +++ b/go.mod @@ -8,4 +8,5 @@ require ( github.com/stretchr/testify v1.3.0 github.com/vishvananda/netlink v1.0.0 github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc // indirect + golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65 ) diff --git a/go.sum b/go.sum index 179d6a0..abea526 100644 --- a/go.sum +++ b/go.sum @@ -38,5 +38,7 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313 h1:pczuHS43Cp2ktBEEmLwScxgjWsBSzdaQiKzUyf3DTTc= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65 h1:hOY+O8MxdkPV10pNf7/XEHaySCiPKxixMKUshfHsGn0= +golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/wg.go b/wg.go index 7e0a315..b9b8dac 100644 --- a/wg.go +++ b/wg.go @@ -12,41 +12,7 @@ import ( "github.com/mdlayher/wireguardctrl" "github.com/sirupsen/logrus" "github.com/vishvananda/netlink" -) - -const ( - defaultRoutingTable = 254 - - // From linux/rtnetlink.h - RTPROT_UNSPEC = 0 - RTPROT_REDIRECT = 1 /* Route installed by ICMP redirects; not used by current IPv4 */ - RTPROT_KERNEL = 2 /* Route installed by kernel */ - RTPROT_BOOT = 3 /* Route installed during boot */ - RTPROT_STATIC = 4 /* Route installed by administrator */ - - /* Values of protocol >= RTPROT_STATIC are not interpreted by kernel; - they are just passed from user and back as is. - It will be used by hypothetical multiple routing daemons. - Note that protocol values should be standardized in order to - avoid conflicts. - */ - - RTPROT_GATED = 8 /* Apparently, GateD */ - RTPROT_RA = 9 /* RDISC/ND router advertisements */ - RTPROT_MRT = 10 /* Merit MRT */ - RTPROT_ZEBRA = 11 /* Zebra */ - RTPROT_BIRD = 12 /* BIRD */ - RTPROT_DNROUTED = 13 /* DECnet routing daemon */ - RTPROT_XORP = 14 /* XORP */ - RTPROT_NTK = 15 /* Netsukuku */ - RTPROT_DHCP = 16 /* DHCP client */ - RTPROT_MROUTED = 17 /* Multicast daemon */ - RTPROT_BABEL = 42 /* Babel daemon */ - RTPROT_BGP = 186 /* BGP Routes */ - RTPROT_ISIS = 187 /* ISIS Routes */ - RTPROT_OSPF = 188 /* OSPF Routes */ - RTPROT_RIP = 189 /* RIP Routes */ - RTPROT_EIGRP = 192 /* EIGRP Routes */ + "golang.org/x/sys/unix" ) // Up sets and configures the wg interface. Mostly equivalent to `wg-quick up iface` @@ -289,15 +255,15 @@ func SyncAddress(cfg *Config, link netlink.Link, log logrus.FieldLogger) error { func fillRouteDefaults(rt *netlink.Route) { // fill defaults if rt.Table == 0 { - rt.Table = defaultRoutingTable + rt.Table = unix.RT_CLASS_MAIN } if rt.Protocol == 0 { - rt.Protocol = RTPROT_BOOT + rt.Protocol = unix.RTPROT_BOOT } if rt.Type == 0 { - rt.Type = 1 // RTN_UNICAST + rt.Type = unix.RTN_UNICAST } } @@ -358,7 +324,7 @@ func SyncRoutes(cfg *Config, link netlink.Link, managedRoutes []net.IPNet, log l "type": rt.Type, "metric": rt.Priority, }) - if !(rt.Table == cfg.Table || (cfg.Table == 0 && rt.Table == defaultRoutingTable)) { + if !(rt.Table == cfg.Table || (cfg.Table == 0 && rt.Table == unix.RT_CLASS_MAIN)) { log.Debug("wrong table for route, skipping") continue }