Add `skip_routes` option

master v0.1.4
Jack O'Sullivan 3 years ago
parent 70068d5294
commit 03694af592

@ -153,6 +153,7 @@ networks:
bridge: my-bridge bridge: my-bridge
ipv6: 'true' ipv6: 'true'
ignore_conflicts: 'false' ignore_conflicts: 'false'
skip_routes: 'false'
ipam: ipam:
driver: 'null' driver: 'null'
``` ```
@ -168,8 +169,10 @@ Note:
- If the `docker run` command times out waiting for a lease, you can try increasing the initial timeout value by - If the `docker run` command times out waiting for a lease, you can try increasing the initial timeout value by
passing `-o lease_timeout=60s` when creating the network (e.g. to increase to 60 seconds) passing `-o lease_timeout=60s` when creating the network (e.g. to increase to 60 seconds)
- By default, a bridge can only be used for a single DHCP network. There is additionally a check to see if a bridge is - By default, a bridge can only be used for a single DHCP network. There is additionally a check to see if a bridge is
is used by any other Docker networks. To disable this check (it's also possible this check might mistakenly detect a is used by any other Docker networks. To disable this check (it's also possible this check might mistakenly detect a
conflict), pass `-o ignore_conflicts=true` when creating the network. conflict), pass `-o ignore_conflicts=true` when creating the network.
- `docker-net-dhcp` will try to copy static routes from the host bridge to the container. To disable this behaviour,
pass `-o skip_routes=true` when creating the network.
## Debugging ## Debugging

@ -326,7 +326,7 @@ func (p *Plugin) DeleteEndpoint(r DeleteEndpointRequest) error {
return nil return nil
} }
func (p *Plugin) addRoutes(v6 bool, bridge netlink.Link, r JoinRequest, hint joinHint, res *JoinResponse) error { func (p *Plugin) addRoutes(opts *DHCPNetworkOptions, v6 bool, bridge netlink.Link, r JoinRequest, hint joinHint, res *JoinResponse) error {
family := unix.AF_INET family := unix.AF_INET
if v6 { if v6 {
family = unix.AF_INET6 family = unix.AF_INET6
@ -370,6 +370,11 @@ func (p *Plugin) addRoutes(v6 bool, bridge netlink.Link, r JoinRequest, hint joi
continue continue
} }
if opts.SkipRoutes {
// Don't do static routes at all
continue
}
if route.Protocol == unix.RTPROT_KERNEL || if route.Protocol == unix.RTPROT_KERNEL ||
(family == unix.AF_INET && route.Dst.Contains(hint.IPv4.IP)) || (family == unix.AF_INET && route.Dst.Contains(hint.IPv4.IP)) ||
(family == unix.AF_INET6 && route.Dst.Contains(hint.IPv6.IP)) { (family == unix.AF_INET6 && route.Dst.Contains(hint.IPv6.IP)) {
@ -443,11 +448,11 @@ func (p *Plugin) Join(ctx context.Context, r JoinRequest) (JoinResponse, error)
return res, fmt.Errorf("failed to get bridge interface: %w", err) return res, fmt.Errorf("failed to get bridge interface: %w", err)
} }
if err := p.addRoutes(false, bridge, r, hint, &res); err != nil { if err := p.addRoutes(&opts, false, bridge, r, hint, &res); err != nil {
return res, err return res, err
} }
if opts.IPv6 { if opts.IPv6 {
if err := p.addRoutes(true, bridge, r, hint, &res); err != nil { if err := p.addRoutes(&opts, true, bridge, r, hint, &res); err != nil {
return res, err return res, err
} }
} }

@ -33,6 +33,7 @@ type DHCPNetworkOptions struct {
IPv6 bool IPv6 bool
LeaseTimeout time.Duration `mapstructure:"lease_timeout"` LeaseTimeout time.Duration `mapstructure:"lease_timeout"`
IgnoreConflicts bool `mapstructure:"ignore_conflicts"` IgnoreConflicts bool `mapstructure:"ignore_conflicts"`
SkipRoutes bool `mapstructure:"skip_routes"`
} }
func decodeOpts(input interface{}) (DHCPNetworkOptions, error) { func decodeOpts(input interface{}) (DHCPNetworkOptions, error) {

Loading…
Cancel
Save