@@ -888,37 +888,23 @@ func (npc *NetworkPolicyController) syncPodFirewallChains(version string) (map[s
888888 }
889889 }
890890
891- // ensure there is rule in filter table and FORWARD chain to jump to pod specific firewall chain
892- // this rule applies to the traffic getting forwarded/routed (traffic from the pod destinted
893- // to pod on a different node)
894- comment = "rule to jump traffic from POD name:" + pod .name + " namespace: " + pod .namespace +
895- " to chain " + podFwChainName
896- args = []string {"-m" , "comment" , "--comment" , comment , "-s" , pod .ip , "-j" , podFwChainName }
897- exists , err = iptablesCmdHandler .Exists ("filter" , "FORWARD" , args ... )
898- if err != nil {
899- return nil , fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
900- }
901- if ! exists {
902- err := iptablesCmdHandler .Insert ("filter" , "FORWARD" , 1 , args ... )
891+ egressFilterChains := []string {"FORWARD" , "OUTPUT" , "INPUT" }
892+ for _ , chain := range egressFilterChains {
893+ // ensure there is rule in filter table and FORWARD chain to jump to pod specific firewall chain
894+ // this rule applies to the traffic getting forwarded/routed (traffic from the pod destinted
895+ // to pod on a different node)
896+ comment = "rule to jump traffic from POD name:" + pod .name + " namespace: " + pod .namespace +
897+ " to chain " + podFwChainName
898+ args = []string {"-m" , "comment" , "--comment" , comment , "-s" , pod .ip , "-j" , podFwChainName }
899+ exists , err = iptablesCmdHandler .Exists ("filter" , chain , args ... )
903900 if err != nil {
904901 return nil , fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
905902 }
906- }
907-
908- // ensure there is rule in filter table and OUTPUT chain to jump to pod specific firewall chain
909- // this rule applies to the traffic getting proxied (traffic from the pod accessing service
910- // resulting in traffic DNAT'ed to a pod IP)
911- comment = "rule to jump traffic from POD name:" + pod .name + " namespace: " + pod .namespace +
912- " to chain " + podFwChainName
913- args = []string {"-m" , "comment" , "--comment" , comment , "-s" , pod .ip , "-j" , podFwChainName }
914- exists , err = iptablesCmdHandler .Exists ("filter" , "OUTPUT" , args ... )
915- if err != nil {
916- return nil , fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
917- }
918- if ! exists {
919- err := iptablesCmdHandler .Insert ("filter" , "OUTPUT" , 1 , args ... )
920- if err != nil {
921- return nil , fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
903+ if ! exists {
904+ err := iptablesCmdHandler .Insert ("filter" , chain , 1 , args ... )
905+ if err != nil {
906+ return nil , fmt .Errorf ("Failed to run iptables command: %s" , err .Error ())
907+ }
922908 }
923909 }
924910
0 commit comments