From 4f9f0dfc3e1b29a6e12a1f487d4040daa827adc2 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Tue, 2 Oct 2018 11:02:36 +0530 Subject: [PATCH] Replace weave-local-pods ipset with physdev iptables rule by-pass ingress network policy chains and accept the packet if destination is not one of the local pods return the packets so the egress network policy chains are skipped in case packet's source is not one of the local pods Fixes #3344 --- prog/weave-npc/main.go | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/prog/weave-npc/main.go b/prog/weave-npc/main.go index 9d054206..ab895977 100644 --- a/prog/weave-npc/main.go +++ b/prog/weave-npc/main.go @@ -125,6 +125,12 @@ func createBaseRules(ipt *iptables.IPTables, ips ipset.Interface) error { } } + // If the destination address is not any of the local pods, let it through + if err := ipt.Append(npc.TableFilter, npc.MainChain, + "-m", "physdev", "--physdev-out=vethwe-bridge", "-j", "ACCEPT"); err != nil { + return err + } + if err := ipt.Append(npc.TableFilter, npc.MainChain, "-m", "state", "--state", "NEW", "-j", string(npc.DefaultChain)); err != nil { return err @@ -135,21 +141,6 @@ func createBaseRules(ipt *iptables.IPTables, ips ipset.Interface) error { return err } - // If the destination address is not any of the local pods, let it through - found, err := ipsetExist(ips, npc.LocalIpset) - if err != nil { - return err - } - if !found { - if err := ips.Create(npc.LocalIpset, ipset.HashIP); err != nil { - return err - } - } - if err := ipt.Append(npc.TableFilter, npc.MainChain, - "-m", "set", "!", "--match-set", npc.LocalIpset, "dst", "-j", "ACCEPT"); err != nil { - return err - } - if err := ipt.Append(npc.TableFilter, npc.EgressMarkChain, "-j", "MARK", "--set-xmark", npc.EgressMark); err != nil { return err @@ -158,7 +149,7 @@ func createBaseRules(ipt *iptables.IPTables, ips ipset.Interface) error { // Egress rules: // // -A WEAVE-NPC-EGRESS -m state --state RELATED,ESTABLISHED -j ACCEPT - // -A WEAVE-NPC-EGRESS -m set ! --match-set weave-local-pods src -j RETURN + // -A WEAVE-NPC-EGRESS -m physdev --physdev-in=vethwe-bridge -j RETURN // -A WEAVE-NPC-EGRESS -d 224.0.0.0/4 -j RETURN // -A WEAVE-NPC-EGRESS -m state --state NEW -j WEAVE-NPC-EGRESS-DEFAULT // -A WEAVE-NPC-EGRESS -m state --state NEW -m mark ! --mark 0x40000/0x40000 -j WEAVE-NPC-EGRESS-CUSTOM @@ -179,7 +170,7 @@ func createBaseRules(ipt *iptables.IPTables, ips ipset.Interface) error { ruleSpecs := [][]string{ {"-m", "state", "--state", "RELATED,ESTABLISHED", "-j", "ACCEPT"}, - {"-m", "state", "--state", "NEW", "-m", "set", "!", "--match-set", npc.LocalIpset, "src", "-j", "RETURN"}, + {"-m", "physdev", "--physdev-in=vethwe-bridge", "-j", "RETURN"}, } if allowMcast { ruleSpecs = append(ruleSpecs, []string{"-d", "224.0.0.0/4", "-j", "RETURN"})