mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	[kube-proxy/ipvs] Add flag to enable strict ARP
This commit is contained in:
		@@ -166,6 +166,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
 | 
				
			|||||||
	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.")
 | 
						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.")
 | 
				
			||||||
	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').")
 | 
						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').")
 | 
				
			||||||
	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.")
 | 
						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.")
 | 
				
			||||||
 | 
						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")
 | 
				
			||||||
	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.")
 | 
						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.")
 | 
				
			||||||
	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)")
 | 
						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)")
 | 
				
			||||||
	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")
 | 
						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")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -196,6 +196,7 @@ func newProxyServer(
 | 
				
			|||||||
			config.IPVS.SyncPeriod.Duration,
 | 
								config.IPVS.SyncPeriod.Duration,
 | 
				
			||||||
			config.IPVS.MinSyncPeriod.Duration,
 | 
								config.IPVS.MinSyncPeriod.Duration,
 | 
				
			||||||
			config.IPVS.ExcludeCIDRs,
 | 
								config.IPVS.ExcludeCIDRs,
 | 
				
			||||||
 | 
								config.IPVS.StrictARP,
 | 
				
			||||||
			config.IPTables.MasqueradeAll,
 | 
								config.IPTables.MasqueradeAll,
 | 
				
			||||||
			int(*config.IPTables.MasqueradeBit),
 | 
								int(*config.IPTables.MasqueradeBit),
 | 
				
			||||||
			config.ClusterCIDR,
 | 
								config.ClusterCIDR,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -55,6 +55,9 @@ type KubeProxyIPVSConfiguration struct {
 | 
				
			|||||||
	// excludeCIDRs is a list of CIDR's which the ipvs proxier should not touch
 | 
						// excludeCIDRs is a list of CIDR's which the ipvs proxier should not touch
 | 
				
			||||||
	// when cleaning up ipvs services.
 | 
						// when cleaning up ipvs services.
 | 
				
			||||||
	ExcludeCIDRs []string
 | 
						ExcludeCIDRs []string
 | 
				
			||||||
 | 
						// strict ARP configure arp_ignore and arp_announce to avoid answering ARP queries
 | 
				
			||||||
 | 
						// from kube-ipvs0 interface
 | 
				
			||||||
 | 
						StrictARP bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// KubeProxyConntrackConfiguration contains conntrack settings for
 | 
					// KubeProxyConntrackConfiguration contains conntrack settings for
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -226,6 +226,7 @@ func autoConvert_v1alpha1_KubeProxyIPVSConfiguration_To_config_KubeProxyIPVSConf
 | 
				
			|||||||
	out.MinSyncPeriod = in.MinSyncPeriod
 | 
						out.MinSyncPeriod = in.MinSyncPeriod
 | 
				
			||||||
	out.Scheduler = in.Scheduler
 | 
						out.Scheduler = in.Scheduler
 | 
				
			||||||
	out.ExcludeCIDRs = *(*[]string)(unsafe.Pointer(&in.ExcludeCIDRs))
 | 
						out.ExcludeCIDRs = *(*[]string)(unsafe.Pointer(&in.ExcludeCIDRs))
 | 
				
			||||||
 | 
						out.StrictARP = in.StrictARP
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -239,6 +240,7 @@ func autoConvert_config_KubeProxyIPVSConfiguration_To_v1alpha1_KubeProxyIPVSConf
 | 
				
			|||||||
	out.MinSyncPeriod = in.MinSyncPeriod
 | 
						out.MinSyncPeriod = in.MinSyncPeriod
 | 
				
			||||||
	out.Scheduler = in.Scheduler
 | 
						out.Scheduler = in.Scheduler
 | 
				
			||||||
	out.ExcludeCIDRs = *(*[]string)(unsafe.Pointer(&in.ExcludeCIDRs))
 | 
						out.ExcludeCIDRs = *(*[]string)(unsafe.Pointer(&in.ExcludeCIDRs))
 | 
				
			||||||
 | 
						out.StrictARP = in.StrictARP
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -194,7 +194,9 @@ type Proxier struct {
 | 
				
			|||||||
	syncPeriod    time.Duration
 | 
						syncPeriod    time.Duration
 | 
				
			||||||
	minSyncPeriod time.Duration
 | 
						minSyncPeriod time.Duration
 | 
				
			||||||
	// Values are CIDR's to exclude when cleaning up IPVS rules.
 | 
						// Values are CIDR's to exclude when cleaning up IPVS rules.
 | 
				
			||||||
	excludeCIDRs   []string
 | 
						excludeCIDRs []string
 | 
				
			||||||
 | 
						// Set to true to set sysctls arp_ignore and arp_announce
 | 
				
			||||||
 | 
						strictARP      bool
 | 
				
			||||||
	iptables       utiliptables.Interface
 | 
						iptables       utiliptables.Interface
 | 
				
			||||||
	ipvs           utilipvs.Interface
 | 
						ipvs           utilipvs.Interface
 | 
				
			||||||
	ipset          utilipset.Interface
 | 
						ipset          utilipset.Interface
 | 
				
			||||||
@@ -285,6 +287,7 @@ func NewProxier(ipt utiliptables.Interface,
 | 
				
			|||||||
	syncPeriod time.Duration,
 | 
						syncPeriod time.Duration,
 | 
				
			||||||
	minSyncPeriod time.Duration,
 | 
						minSyncPeriod time.Duration,
 | 
				
			||||||
	excludeCIDRs []string,
 | 
						excludeCIDRs []string,
 | 
				
			||||||
 | 
						strictARP bool,
 | 
				
			||||||
	masqueradeAll bool,
 | 
						masqueradeAll bool,
 | 
				
			||||||
	masqueradeBit int,
 | 
						masqueradeBit int,
 | 
				
			||||||
	clusterCIDR string,
 | 
						clusterCIDR string,
 | 
				
			||||||
@@ -344,17 +347,19 @@ func NewProxier(ipt utiliptables.Interface,
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set the arp_ignore sysctl we need for
 | 
						if strictARP {
 | 
				
			||||||
	if val, _ := sysctl.GetSysctl(sysctlArpIgnore); val != 1 {
 | 
							// Set the arp_ignore sysctl we need for
 | 
				
			||||||
		if err := sysctl.SetSysctl(sysctlArpIgnore, 1); err != nil {
 | 
							if val, _ := sysctl.GetSysctl(sysctlArpIgnore); val != 1 {
 | 
				
			||||||
			return nil, fmt.Errorf("can't set sysctl %s: %v", sysctlArpIgnore, err)
 | 
								if err := sysctl.SetSysctl(sysctlArpIgnore, 1); err != nil {
 | 
				
			||||||
 | 
									return nil, fmt.Errorf("can't set sysctl %s: %v", sysctlArpIgnore, err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set the arp_announce sysctl we need for
 | 
							// Set the arp_announce sysctl we need for
 | 
				
			||||||
	if val, _ := sysctl.GetSysctl(sysctlArpAnnounce); val != 2 {
 | 
							if val, _ := sysctl.GetSysctl(sysctlArpAnnounce); val != 2 {
 | 
				
			||||||
		if err := sysctl.SetSysctl(sysctlArpAnnounce, 2); err != nil {
 | 
								if err := sysctl.SetSysctl(sysctlArpAnnounce, 2); err != nil {
 | 
				
			||||||
			return nil, fmt.Errorf("can't set sysctl %s: %v", sysctlArpAnnounce, err)
 | 
									return nil, fmt.Errorf("can't set sysctl %s: %v", sysctlArpAnnounce, err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -155,6 +155,7 @@ func NewFakeProxier(ipt utiliptables.Interface, ipvs utilipvs.Interface, ipset u
 | 
				
			|||||||
		ipvs:              ipvs,
 | 
							ipvs:              ipvs,
 | 
				
			||||||
		ipset:             ipset,
 | 
							ipset:             ipset,
 | 
				
			||||||
		clusterCIDR:       "10.0.0.0/24",
 | 
							clusterCIDR:       "10.0.0.0/24",
 | 
				
			||||||
 | 
							strictARP:         false,
 | 
				
			||||||
		hostname:          testHostname,
 | 
							hostname:          testHostname,
 | 
				
			||||||
		portsMap:          make(map[utilproxy.LocalPort]utilproxy.Closeable),
 | 
							portsMap:          make(map[utilproxy.LocalPort]utilproxy.Closeable),
 | 
				
			||||||
		portMapper:        &fakePortOpener{[]*utilproxy.LocalPort{}},
 | 
							portMapper:        &fakePortOpener{[]*utilproxy.LocalPort{}},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,6 +51,9 @@ type KubeProxyIPVSConfiguration struct {
 | 
				
			|||||||
	// excludeCIDRs is a list of CIDR's which the ipvs proxier should not touch
 | 
						// excludeCIDRs is a list of CIDR's which the ipvs proxier should not touch
 | 
				
			||||||
	// when cleaning up ipvs services.
 | 
						// when cleaning up ipvs services.
 | 
				
			||||||
	ExcludeCIDRs []string `json:"excludeCIDRs"`
 | 
						ExcludeCIDRs []string `json:"excludeCIDRs"`
 | 
				
			||||||
 | 
						// strict ARP configure arp_ignore and arp_announce to avoid answering ARP queries
 | 
				
			||||||
 | 
						// from kube-ipvs0 interface
 | 
				
			||||||
 | 
						StrictARP bool `json:"strictARP"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// KubeProxyConntrackConfiguration contains conntrack settings for
 | 
					// KubeProxyConntrackConfiguration contains conntrack settings for
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user