Skip to content

Commit

Permalink
Merge pull request kosmos-io#289 from OrangeBao/fix_iptables
Browse files Browse the repository at this point in the history
feat: add rp filter nic
  • Loading branch information
kosmos-robot authored Nov 24, 2023
2 parents 499bbb8 + abc7606 commit a060f6e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions pkg/clusterlink/network/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package network
import (
"fmt"
"net"
"os"
"strings"
"syscall"

"github.com/pkg/errors"
Expand Down Expand Up @@ -323,14 +325,24 @@ func UpdateDefaultIptablesAndKernalConfig(name string, ipFamily int) error {
return err
}

// tunl0 device
if err := UpdateDefaultIp4tablesBehavior("tunl0"); err != nil {
klog.Errorf("Try to add iptables rule for tunl0: %v", err)
nicNames := []string{"tunl0", "vxlan.calico"}

deviceNameStr := os.Getenv("AGENT_RP_FILTER_DEVICES")
if len(deviceNameStr) > 0 {
nicNames = append(nicNames, strings.Split(deviceNameStr, ",")...)
}

// tunl0 device
if err := EnableLooseModeByIFaceNmae("tunl0"); err != nil {
klog.Errorf("Try to change kernel parameters(rp_filter) for tunl0: %v", err)
for _, nicName := range nicNames {
if len(nicName) == 0 {
continue
}
if err := UpdateDefaultIp4tablesBehavior(nicName); err != nil {
klog.Errorf("Try to add iptables rule for %s: %v", nicName, err)
}

if err := EnableLooseModeByIFaceNmae(nicName); err != nil {
klog.Errorf("Try to change kernel parameters(rp_filter) for %s: %v", nicName, err)
}
}
}

Expand Down

0 comments on commit a060f6e

Please sign in to comment.