Skip to content

Commit

Permalink
Add skip_routes option
Browse files Browse the repository at this point in the history
  • Loading branch information
devplayer0 committed Jul 15, 2021
1 parent 70068d5 commit 03694af
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ networks:
bridge: my-bridge
ipv6: 'true'
ignore_conflicts: 'false'
skip_routes: 'false'
ipam:
driver: 'null'
```
Expand All @@ -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
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
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.
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.
- `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

Expand Down
11 changes: 8 additions & 3 deletions pkg/plugin/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (p *Plugin) DeleteEndpoint(r DeleteEndpointRequest) error {
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
if v6 {
family = unix.AF_INET6
Expand Down Expand Up @@ -370,6 +370,11 @@ func (p *Plugin) addRoutes(v6 bool, bridge netlink.Link, r JoinRequest, hint joi
continue
}

if opts.SkipRoutes {
// Don't do static routes at all
continue
}

if route.Protocol == unix.RTPROT_KERNEL ||
(family == unix.AF_INET && route.Dst.Contains(hint.IPv4.IP)) ||
(family == unix.AF_INET6 && route.Dst.Contains(hint.IPv6.IP)) {
Expand Down Expand Up @@ -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)
}

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
}
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
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type DHCPNetworkOptions struct {
IPv6 bool
LeaseTimeout time.Duration `mapstructure:"lease_timeout"`
IgnoreConflicts bool `mapstructure:"ignore_conflicts"`
SkipRoutes bool `mapstructure:"skip_routes"`
}

func decodeOpts(input interface{}) (DHCPNetworkOptions, error) {
Expand Down

0 comments on commit 03694af

Please sign in to comment.