@ -10,6 +10,7 @@ import (
"strings"
"github.com/coreos/go-iptables/iptables"
"github.com/go-multierror/multierror"
"github.com/tailscale/wireguard-go/device"
"github.com/tailscale/wireguard-go/tun"
"inet.af/netaddr"
@ -145,7 +146,7 @@ func (r *linuxRouter) Up() error {
func ( r * linuxRouter ) Close ( ) error {
if err := r . dns . Down ( ) ; err != nil {
return fmt . Errorf ( "dns down: % v ", err )
return fmt . Errorf ( "dns down: % w ", err )
}
if err := r . downInterface ( ) ; err != nil {
return err
@ -165,23 +166,28 @@ func (r *linuxRouter) Close() error {
// Set implements the Router interface.
func ( r * linuxRouter ) Set ( cfg * Config ) error {
var errs [ ] error
if cfg == nil {
cfg = & shutdownConfig
}
if err := r . dns . Set ( cfg . DNS ) ; err != nil {
errs = append ( errs , fmt . Errorf ( "dns set: %w" , err ) )
}
if err := r . setNetfilterMode ( cfg . NetfilterMode ) ; err != nil {
return err
errs = append ( errs , err )
}
newRoutes , err := cidrDiff ( "route" , r . routes , cfg . Routes , r . addRoute , r . delRoute , r . logf )
if err != nil {
return err
errs = append ( errs , err )
}
r . routes = newRoutes
newAddrs , err := cidrDiff ( "addr" , r . addrs , cfg . LocalAddrs , r . addAddress , r . delAddress , r . logf )
if err != nil {
return err
errs = append ( errs , err )
}
r . addrs = newAddrs
@ -190,20 +196,16 @@ func (r *linuxRouter) Set(cfg *Config) error {
// state already correct, nothing to do.
case cfg . SNATSubnetRoutes :
if err := r . addSNATRule ( ) ; err != nil {
return err
errs = append ( errs , err )
}
default :
if err := r . delSNATRule ( ) ; err != nil {
return err
errs = append ( errs , err )
}
}
r . snatSubnetRoutes = cfg . SNATSubnetRoutes
if err := r . dns . Set ( cfg . DNS ) ; err != nil {
return fmt . Errorf ( "dns set: %v" , err )
}
return nil
return multierror . New ( errs )
}
// setNetfilterMode switches the router to the given netfilter