Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature: Conntrack no matching connections process #741

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions pkg/yurttunnel/trafficforward/iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (
yurttunnelServerPortChain = "TUNNEL-PORT"
yurttunnelPortChainPrefix = "TUNNEL-PORT-"
defaultSyncPeriod = 15

// NoConnectionToDelete is the error string returned by conntrack when no matching connections are found
NoConnectionToDelete = "0 flow entries have been deleted"
)

var (
Expand Down Expand Up @@ -449,33 +452,37 @@ func toCIDR(ip net.IP) string {
return fmt.Sprintf("%s/%d", ip.String(), size)
}

func (im *iptablesManager) clearConnTrackEntries(ips, ports []string) {
func (im *iptablesManager) clearConnTrackEntries(ips, ports []string) error {
if len(im.conntrackPath) == 0 {
return
return nil
}
klog.Infof("clear conntrack entries for ports %q and nodes %q", ports, ips)
for _, port := range ports {
for _, ip := range ips {
im.clearConnTrackEntriesForIPPort(ip, port)
if err := im.clearConnTrackEntriesForIPPort(ip, port); err != nil {
return err
}
}
}
return nil
}

func (im *iptablesManager) clearConnTrackEntriesForIPPort(ip, port string) {
func (im *iptablesManager) clearConnTrackEntriesForIPPort(ip, port string) error {
parameters := parametersWithFamily(utilnet.IsIPv6String(ip),
"-D", "--orig-dst",
ip, "-p",
"tcp", "--dport", port)
output, err := im.execer.
Command(im.conntrackPath, parameters...).
CombinedOutput()
if err != nil {

if err != nil && !strings.Contains(err.Error(), NoConnectionToDelete) {
klog.Errorf("clear conntrack for %s:%s failed: %q, error message: %s",
ip, port, string(output), err)
return
return fmt.Errorf("clear conntrack for %s:%s failed: %q, error message: %s",
ip, port, string(output), err)
}
klog.Infof("clear conntrack for %s:%s successfully: %q",
ip, port, string(output))
return nil
}

func parametersWithFamily(isIPv6 bool, parameters ...string) []string {
Expand Down