Support unsafe_routes on Darwin (#139)
* Support unsafe_routes on darwin * fix formatting in tun_darwin.go (spaces to tabs)
This commit is contained in:
parent
e9b0498b21
commit
4e0da13180
|
@ -10,9 +10,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Tun struct {
|
type Tun struct {
|
||||||
Device string
|
Device string
|
||||||
Cidr *net.IPNet
|
Cidr *net.IPNet
|
||||||
MTU int
|
MTU int
|
||||||
|
UnsafeRoutes []route
|
||||||
|
|
||||||
*water.Interface
|
*water.Interface
|
||||||
}
|
}
|
||||||
|
@ -21,13 +22,11 @@ func newTun(deviceName string, cidr *net.IPNet, defaultMTU int, routes []route,
|
||||||
if len(routes) > 0 {
|
if len(routes) > 0 {
|
||||||
return nil, fmt.Errorf("Route MTU not supported in Darwin")
|
return nil, fmt.Errorf("Route MTU not supported in Darwin")
|
||||||
}
|
}
|
||||||
if len(unsafeRoutes) > 0 {
|
|
||||||
return nil, fmt.Errorf("unsafeRoutes not supported in Darwin")
|
|
||||||
}
|
|
||||||
// NOTE: You cannot set the deviceName under Darwin, so you must check tun.Device after calling .Activate()
|
// NOTE: You cannot set the deviceName under Darwin, so you must check tun.Device after calling .Activate()
|
||||||
return &Tun{
|
return &Tun{
|
||||||
Cidr: cidr,
|
Cidr: cidr,
|
||||||
MTU: defaultMTU,
|
MTU: defaultMTU,
|
||||||
|
UnsafeRoutes: unsafeRoutes,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +51,12 @@ func (c *Tun) Activate() error {
|
||||||
if err = exec.Command("ifconfig", c.Device, "mtu", strconv.Itoa(c.MTU)).Run(); err != nil {
|
if err = exec.Command("ifconfig", c.Device, "mtu", strconv.Itoa(c.MTU)).Run(); err != nil {
|
||||||
return fmt.Errorf("failed to run 'ifconfig': %s", err)
|
return fmt.Errorf("failed to run 'ifconfig': %s", err)
|
||||||
}
|
}
|
||||||
|
// Unsafe path routes
|
||||||
|
for _, r := range c.UnsafeRoutes {
|
||||||
|
if err = exec.Command("route", "-n", "add", "-net", r.route.String(), "-interface", c.Device).Run(); err != nil {
|
||||||
|
return fmt.Errorf("failed to run 'route add' for unsafe_route %s: %s", r.route.String(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue