Skip to content

Commit 03694af

Browse files
committed
Add skip_routes option
1 parent 70068d5 commit 03694af

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ networks:
153153
bridge: my-bridge
154154
ipv6: 'true'
155155
ignore_conflicts: 'false'
156+
skip_routes: 'false'
156157
ipam:
157158
driver: 'null'
158159
```
@@ -168,8 +169,10 @@ Note:
168169
- If the `docker run` command times out waiting for a lease, you can try increasing the initial timeout value by
169170
passing `-o lease_timeout=60s` when creating the network (e.g. to increase to 60 seconds)
170171
- By default, a bridge can only be used for a single DHCP network. There is additionally a check to see if a bridge is
171-
is used by any other Docker networks. To disable this check (it's also possible this check might mistakenly detect a
172-
conflict), pass `-o ignore_conflicts=true` when creating the network.
172+
is used by any other Docker networks. To disable this check (it's also possible this check might mistakenly detect a
173+
conflict), pass `-o ignore_conflicts=true` when creating the network.
174+
- `docker-net-dhcp` will try to copy static routes from the host bridge to the container. To disable this behaviour,
175+
pass `-o skip_routes=true` when creating the network.
173176

174177
## Debugging
175178

pkg/plugin/network.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func (p *Plugin) DeleteEndpoint(r DeleteEndpointRequest) error {
326326
return nil
327327
}
328328

329-
func (p *Plugin) addRoutes(v6 bool, bridge netlink.Link, r JoinRequest, hint joinHint, res *JoinResponse) error {
329+
func (p *Plugin) addRoutes(opts *DHCPNetworkOptions, v6 bool, bridge netlink.Link, r JoinRequest, hint joinHint, res *JoinResponse) error {
330330
family := unix.AF_INET
331331
if v6 {
332332
family = unix.AF_INET6
@@ -370,6 +370,11 @@ func (p *Plugin) addRoutes(v6 bool, bridge netlink.Link, r JoinRequest, hint joi
370370
continue
371371
}
372372

373+
if opts.SkipRoutes {
374+
// Don't do static routes at all
375+
continue
376+
}
377+
373378
if route.Protocol == unix.RTPROT_KERNEL ||
374379
(family == unix.AF_INET && route.Dst.Contains(hint.IPv4.IP)) ||
375380
(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)
443448
return res, fmt.Errorf("failed to get bridge interface: %w", err)
444449
}
445450

446-
if err := p.addRoutes(false, bridge, r, hint, &res); err != nil {
451+
if err := p.addRoutes(&opts, false, bridge, r, hint, &res); err != nil {
447452
return res, err
448453
}
449454
if opts.IPv6 {
450-
if err := p.addRoutes(true, bridge, r, hint, &res); err != nil {
455+
if err := p.addRoutes(&opts, true, bridge, r, hint, &res); err != nil {
451456
return res, err
452457
}
453458
}

pkg/plugin/plugin.go

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type DHCPNetworkOptions struct {
3333
IPv6 bool
3434
LeaseTimeout time.Duration `mapstructure:"lease_timeout"`
3535
IgnoreConflicts bool `mapstructure:"ignore_conflicts"`
36+
SkipRoutes bool `mapstructure:"skip_routes"`
3637
}
3738

3839
func decodeOpts(input interface{}) (DHCPNetworkOptions, error) {

0 commit comments

Comments
 (0)