Skip to content

Commit 59140d6

Browse files
authored
Merge pull request kubernetes#75295 from DataDog/lbernail/strict-arp-flag
[kube-proxy/ipvs] Add flag to enable strict ARP
2 parents 88dc966 + 09f821d commit 59140d6

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed

cmd/kube-proxy/app/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
166166
fs.DurationVar(&o.config.IPVS.SyncPeriod.Duration, "ipvs-sync-period", o.config.IPVS.SyncPeriod.Duration, "The maximum interval of how often ipvs rules are refreshed (e.g. '5s', '1m', '2h22m'). Must be greater than 0.")
167167
fs.DurationVar(&o.config.IPVS.MinSyncPeriod.Duration, "ipvs-min-sync-period", o.config.IPVS.MinSyncPeriod.Duration, "The minimum interval of how often the ipvs rules can be refreshed as endpoints and services change (e.g. '5s', '1m', '2h22m').")
168168
fs.StringSliceVar(&o.config.IPVS.ExcludeCIDRs, "ipvs-exclude-cidrs", o.config.IPVS.ExcludeCIDRs, "A comma-separated list of CIDR's which the ipvs proxier should not touch when cleaning up IPVS rules.")
169+
fs.BoolVar(&o.config.IPVS.StrictARP, "ipvs-strict-arp", o.config.IPVS.StrictARP, "Enable strict ARP by setting arp_ignore to 1 and arp_announce to 2")
169170
fs.DurationVar(&o.config.ConfigSyncPeriod.Duration, "config-sync-period", o.config.ConfigSyncPeriod.Duration, "How often configuration from the apiserver is refreshed. Must be greater than 0.")
170171
fs.BoolVar(&o.config.IPTables.MasqueradeAll, "masquerade-all", o.config.IPTables.MasqueradeAll, "If using the pure iptables proxy, SNAT all traffic sent via Service cluster IPs (this not commonly needed)")
171172
fs.StringVar(&o.config.ClusterCIDR, "cluster-cidr", o.config.ClusterCIDR, "The CIDR range of pods in the cluster. When configured, traffic sent to a Service cluster IP from outside this range will be masqueraded and traffic sent from pods to an external LoadBalancer IP will be directed to the respective cluster IP instead")

cmd/kube-proxy/app/server_others.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func newProxyServer(
196196
config.IPVS.SyncPeriod.Duration,
197197
config.IPVS.MinSyncPeriod.Duration,
198198
config.IPVS.ExcludeCIDRs,
199+
config.IPVS.StrictARP,
199200
config.IPTables.MasqueradeAll,
200201
int(*config.IPTables.MasqueradeBit),
201202
config.ClusterCIDR,

pkg/proxy/apis/config/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ type KubeProxyIPVSConfiguration struct {
5555
// excludeCIDRs is a list of CIDR's which the ipvs proxier should not touch
5656
// when cleaning up ipvs services.
5757
ExcludeCIDRs []string
58+
// strict ARP configure arp_ignore and arp_announce to avoid answering ARP queries
59+
// from kube-ipvs0 interface
60+
StrictARP bool
5861
}
5962

6063
// KubeProxyConntrackConfiguration contains conntrack settings for

pkg/proxy/apis/config/v1alpha1/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/proxy/ipvs/proxier.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ type Proxier struct {
194194
syncPeriod time.Duration
195195
minSyncPeriod time.Duration
196196
// Values are CIDR's to exclude when cleaning up IPVS rules.
197-
excludeCIDRs []string
197+
excludeCIDRs []string
198+
// Set to true to set sysctls arp_ignore and arp_announce
199+
strictARP bool
198200
iptables utiliptables.Interface
199201
ipvs utilipvs.Interface
200202
ipset utilipset.Interface
@@ -285,6 +287,7 @@ func NewProxier(ipt utiliptables.Interface,
285287
syncPeriod time.Duration,
286288
minSyncPeriod time.Duration,
287289
excludeCIDRs []string,
290+
strictARP bool,
288291
masqueradeAll bool,
289292
masqueradeBit int,
290293
clusterCIDR string,
@@ -344,17 +347,19 @@ func NewProxier(ipt utiliptables.Interface,
344347
}
345348
}
346349

347-
// Set the arp_ignore sysctl we need for
348-
if val, _ := sysctl.GetSysctl(sysctlArpIgnore); val != 1 {
349-
if err := sysctl.SetSysctl(sysctlArpIgnore, 1); err != nil {
350-
return nil, fmt.Errorf("can't set sysctl %s: %v", sysctlArpIgnore, err)
350+
if strictARP {
351+
// Set the arp_ignore sysctl we need for
352+
if val, _ := sysctl.GetSysctl(sysctlArpIgnore); val != 1 {
353+
if err := sysctl.SetSysctl(sysctlArpIgnore, 1); err != nil {
354+
return nil, fmt.Errorf("can't set sysctl %s: %v", sysctlArpIgnore, err)
355+
}
351356
}
352-
}
353357

354-
// Set the arp_announce sysctl we need for
355-
if val, _ := sysctl.GetSysctl(sysctlArpAnnounce); val != 2 {
356-
if err := sysctl.SetSysctl(sysctlArpAnnounce, 2); err != nil {
357-
return nil, fmt.Errorf("can't set sysctl %s: %v", sysctlArpAnnounce, err)
358+
// Set the arp_announce sysctl we need for
359+
if val, _ := sysctl.GetSysctl(sysctlArpAnnounce); val != 2 {
360+
if err := sysctl.SetSysctl(sysctlArpAnnounce, 2); err != nil {
361+
return nil, fmt.Errorf("can't set sysctl %s: %v", sysctlArpAnnounce, err)
362+
}
358363
}
359364
}
360365

pkg/proxy/ipvs/proxier_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func NewFakeProxier(ipt utiliptables.Interface, ipvs utilipvs.Interface, ipset u
155155
ipvs: ipvs,
156156
ipset: ipset,
157157
clusterCIDR: "10.0.0.0/24",
158+
strictARP: false,
158159
hostname: testHostname,
159160
portsMap: make(map[utilproxy.LocalPort]utilproxy.Closeable),
160161
portMapper: &fakePortOpener{[]*utilproxy.LocalPort{}},

staging/src/k8s.io/kube-proxy/config/v1alpha1/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ type KubeProxyIPVSConfiguration struct {
5151
// excludeCIDRs is a list of CIDR's which the ipvs proxier should not touch
5252
// when cleaning up ipvs services.
5353
ExcludeCIDRs []string `json:"excludeCIDRs"`
54+
// strict ARP configure arp_ignore and arp_announce to avoid answering ARP queries
55+
// from kube-ipvs0 interface
56+
StrictARP bool `json:"strictARP"`
5457
}
5558

5659
// KubeProxyConntrackConfiguration contains conntrack settings for

0 commit comments

Comments
 (0)