Skip to content

Commit

Permalink
Merge pull request #26 from telekom/feature/notrack-vxlan
Browse files Browse the repository at this point in the history
NOTRACK of UDP 4789 packets to VTEP IP
  • Loading branch information
chdxD1 authored Jun 29, 2023
2 parents d023958 + e03e030 commit a1f166d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/frr/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (m *FRRManager) Configure(in FRRConfiguration) (bool, error) {
}

func (f *FRRManager) renderSubtemplates(in FRRConfiguration) (*FRRTemplateConfig, error) {
vrfRouterId, err := (&nl.NetlinkManager{}).GetRouterIDForVRFs()
vrfRouterId, err := (&nl.NetlinkManager{}).GetUnderlayIP()
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/nl/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
type NetlinkManager struct {
}

func (n *NetlinkManager) GetRouterIDForVRFs() (net.IP, error) {
func (n *NetlinkManager) GetUnderlayIP() (net.IP, error) {
_, ip, err := getInterfaceAndIP(UNDERLAY_LOOPBACK)
return ip, err
}
Expand Down
27 changes: 22 additions & 5 deletions pkg/notrack/notrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import (
"github.com/vishvananda/netlink"
"k8s.io/utils/strings/slices"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/telekom/das-schiff-network-operator/pkg/nl"
)

const (
IPTABLES_TABLE = "raw"
IPTABLES_CHAIN = "PREROUTING"
IPTABLES_TABLE = "raw"
IPTABLES_PREROUTING = "PREROUTING"
IPTABLES_OUTPUT = "OUTPUT"
)

var (
Expand All @@ -39,7 +42,7 @@ func buildRule(link string) []string {
}

func reconcileIPTables(notrackLinks []string, ipt *iptables.IPTables) error {
rules, err := ipt.List(IPTABLES_TABLE, IPTABLES_CHAIN)
rules, err := ipt.List(IPTABLES_TABLE, IPTABLES_PREROUTING)
if err != nil {
return err
}
Expand All @@ -55,7 +58,7 @@ func reconcileIPTables(notrackLinks []string, ipt *iptables.IPTables) error {
}

if !slices.Contains(notrackLinks, link) {
if err := ipt.Delete(IPTABLES_TABLE, IPTABLES_CHAIN, buildRule(link)...); err != nil {
if err := ipt.Delete(IPTABLES_TABLE, IPTABLES_PREROUTING, buildRule(link)...); err != nil {
return err
}
}
Expand All @@ -66,7 +69,7 @@ func reconcileIPTables(notrackLinks []string, ipt *iptables.IPTables) error {
if slices.Contains(existingLinks, notrackLink) {
continue
}
if err := ipt.Append(IPTABLES_TABLE, IPTABLES_CHAIN, buildRule(notrackLink)...); err != nil {
if err := ipt.Append(IPTABLES_TABLE, IPTABLES_PREROUTING, buildRule(notrackLink)...); err != nil {
return err
}
}
Expand All @@ -85,6 +88,8 @@ func RunIPTablesSync() {
os.Exit(1)
}

netlinkManager := &nl.NetlinkManager{}

go func() {
for {
links, err := netlink.LinkList()
Expand All @@ -109,6 +114,18 @@ func RunIPTablesSync() {
if err := reconcileIPTables(notrackLinks, ipt6); err != nil {
notrackLog.Error(err, "error reconciling notrack in IPv6 iptables")
}

if underlayIP, err := netlinkManager.GetUnderlayIP(); err == nil {
if err := ipt4.AppendUnique(IPTABLES_TABLE, IPTABLES_PREROUTING, "-d", underlayIP.String(), "-p", "udp", "--dport", "4789", "-j", "NOTRACK"); err != nil {
notrackLog.Error(err, "error reconciling VXLAN notrack in IPv4 iptables")
}
if err := ipt4.AppendUnique(IPTABLES_TABLE, IPTABLES_OUTPUT, "-s", underlayIP.String(), "-p", "udp", "--dport", "4789", "-j", "NOTRACK"); err != nil {
notrackLog.Error(err, "error reconciling VXLAN notrack in IPv4 iptables")
}
} else {
notrackLog.Error(err, "error reconciling VXLAN notrack in IPv4 iptables")
}

time.Sleep(20 * time.Second)
}
}()
Expand Down

0 comments on commit a1f166d

Please sign in to comment.