diff --git a/pkg/plugin/dhcp_manager.go b/pkg/plugin/dhcp_manager.go index 70f0446..f4ab068 100644 --- a/pkg/plugin/dhcp_manager.go +++ b/pkg/plugin/dhcp_manager.go @@ -78,7 +78,7 @@ func (m *dhcpManager) renew(v6 bool, info udhcpc.Info) error { Warn("udhcpc renew with changed IP") } - if !v6 && info.Gateway != "" { + if !v6 && info.Gateway != "" && m.opts.Gateway == "" { newGateway := net.ParseIP(info.Gateway) routes, err := m.netHandle.RouteListFiltered(unix.AF_INET, &netlink.Route{ diff --git a/pkg/plugin/network.go b/pkg/plugin/network.go index ac9e7b0..0e4b0ff 100644 --- a/pkg/plugin/network.go +++ b/pkg/plugin/network.go @@ -238,7 +238,11 @@ func (p *Plugin) CreateEndpoint(ctx context.Context, r CreateEndpointRequest) (C } else { res.Interface.Address = info.IP hint.IPv4 = ip - hint.Gateway = info.Gateway + if opts.Gateway != "" { + hint.Gateway = opts.Gateway + } else { + hint.Gateway = info.Gateway + } } p.joinHints[r.EndpointID] = hint diff --git a/pkg/plugin/plugin.go b/pkg/plugin/plugin.go index 9180748..3724f16 100644 --- a/pkg/plugin/plugin.go +++ b/pkg/plugin/plugin.go @@ -30,6 +30,7 @@ func IsDHCPPlugin(driver string) bool { // DHCPNetworkOptions contains options for the DHCP network driver type DHCPNetworkOptions struct { Bridge string + Gateway string IPv6 bool LeaseTimeout time.Duration `mapstructure:"lease_timeout"` IgnoreConflicts bool `mapstructure:"ignore_conflicts"`