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 {
|
||||
Device string
|
||||
Cidr *net.IPNet
|
||||
MTU int
|
||||
Device string
|
||||
Cidr *net.IPNet
|
||||
MTU int
|
||||
UnsafeRoutes []route
|
||||
|
||||
*water.Interface
|
||||
}
|
||||
|
@ -21,13 +22,11 @@ func newTun(deviceName string, cidr *net.IPNet, defaultMTU int, routes []route,
|
|||
if len(routes) > 0 {
|
||||
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()
|
||||
return &Tun{
|
||||
Cidr: cidr,
|
||||
MTU: defaultMTU,
|
||||
Cidr: cidr,
|
||||
MTU: defaultMTU,
|
||||
UnsafeRoutes: unsafeRoutes,
|
||||
}, 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 {
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue