From 8608901e248b410fadfae9414a7a3270f9d482ff Mon Sep 17 00:00:00 2001 From: tanshanshan Date: Mon, 23 Jul 2018 11:30:56 +0800 Subject: [PATCH] reuse iptablesContainerPortalArgs --- pkg/proxy/userspace/proxier.go | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/pkg/proxy/userspace/proxier.go b/pkg/proxy/userspace/proxier.go index 1efced08641..292e96832d5 100644 --- a/pkg/proxy/userspace/proxier.go +++ b/pkg/proxy/userspace/proxier.go @@ -708,7 +708,7 @@ func (proxier *Proxier) openNodePort(nodePort int, protocol api.Protocol, proxyI } // Handle traffic from containers. - args := proxier.iptablesContainerNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name) + args := proxier.iptablesContainerPortalArgs(nil, false, false, nodePort, protocol, proxyIP, proxyPort, name) existed, err := proxier.iptables.EnsureRule(iptables.Append, iptables.TableNAT, iptablesContainerNodePortChain, args...) if err != nil { glog.Errorf("Failed to install iptables %s rule for service %q", iptablesContainerNodePortChain, name) @@ -811,7 +811,7 @@ func (proxier *Proxier) closeNodePort(nodePort int, protocol api.Protocol, proxy el := []error{} // Handle traffic from containers. - args := proxier.iptablesContainerNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name) + args := proxier.iptablesContainerPortalArgs(nil, false, false, nodePort, protocol, proxyIP, proxyPort, name) if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesContainerNodePortChain, args...); err != nil { glog.Errorf("Failed to delete iptables %s rule for service %q", iptablesContainerNodePortChain, name) el = append(el, err) @@ -1061,23 +1061,6 @@ func (proxier *Proxier) iptablesHostPortalArgs(destIP net.IP, addDstLocalMatch b return args } -// Build a slice of iptables args for a from-container public-port rule. -// See iptablesContainerPortalArgs -// TODO: Should we just reuse iptablesContainerPortalArgs? -func (proxier *Proxier) iptablesContainerNodePortArgs(nodePort int, protocol api.Protocol, proxyIP net.IP, proxyPort int, service proxy.ServicePortName) []string { - args := iptablesCommonPortalArgs(nil, false, false, nodePort, protocol, service) - - if proxyIP.Equal(zeroIPv4) || proxyIP.Equal(zeroIPv6) { - // TODO: Can we REDIRECT with IPv6? - args = append(args, "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", proxyPort)) - } else { - // TODO: Can we DNAT with IPv6? - args = append(args, "-j", "DNAT", "--to-destination", net.JoinHostPort(proxyIP.String(), strconv.Itoa(proxyPort))) - } - - return args -} - // Build a slice of iptables args for a from-host public-port rule. // See iptablesHostPortalArgs // TODO: Should we just reuse iptablesHostPortalArgs?