@@ -1063,6 +1063,93 @@ COMMIT
10631063 Expect (buf .filterRules .String ()).To (Equal (finalizedRules ))
10641064 })
10651065
1066+ It ("ingress rules endport" , func () {
1067+ port0 := intstr .FromInt (8888 )
1068+ port1 := intstr .FromInt (9999 )
1069+ endport := int32 (11111 )
1070+ protoTCP := v1 .ProtocolTCP
1071+ ingressPolicies1 := & multiv1beta2.MultiNetworkPolicy {
1072+ ObjectMeta : metav1.ObjectMeta {
1073+ Name : "ingressPolicies1" ,
1074+ Namespace : "testns1" ,
1075+ },
1076+ Spec : multiv1beta2.MultiNetworkPolicySpec {
1077+ Ingress : []multiv1beta2.MultiNetworkPolicyIngressRule {
1078+ {
1079+ Ports : []multiv1beta2.MultiNetworkPolicyPort {
1080+ {
1081+ Protocol : & protoTCP ,
1082+ Port : & port0 ,
1083+ },
1084+ {
1085+ Protocol : & protoTCP ,
1086+ Port : & port1 ,
1087+ EndPort : & endport ,
1088+ },
1089+ },
1090+ },
1091+ },
1092+ },
1093+ }
1094+
1095+ ipt := fakeiptables .NewFake ()
1096+ Expect (ipt ).NotTo (BeNil ())
1097+ buf := newIptableBuffer ()
1098+ Expect (buf ).NotTo (BeNil ())
1099+
1100+ // verify buf initialized at init
1101+ buf .Init (ipt )
1102+ s := NewFakeServer ("samplehost" )
1103+ Expect (s ).NotTo (BeNil ())
1104+
1105+ Expect (s .netdefChanges .Update (
1106+ nil ,
1107+ NewNetDef ("testns1" , "net-attach1" , NewCNIConfig ("testCNI" , "multi" )))).To (BeTrue ())
1108+ Expect (s .netdefChanges .GetPluginType (types.NamespacedName {Namespace : "testns1" , Name : "net-attach1" })).To (Equal ("multi" ))
1109+
1110+ pod1 := NewFakePodWithNetAnnotation (
1111+ "testns1" ,
1112+ "testpod1" ,
1113+ "net-attach1" ,
1114+ NewFakeNetworkStatus ("testns1" , "net-attach1" , "192.168.1.1" , "10.1.1.1" ),
1115+ nil )
1116+ AddPod (s , pod1 )
1117+ podInfo1 , err := s .podMap .GetPodInfo (pod1 )
1118+ Expect (err ).NotTo (HaveOccurred ())
1119+
1120+ buf .renderIngress (s , podInfo1 , 0 , ingressPolicies1 , []string {"testns1/net-attach1" })
1121+
1122+ portRules :=
1123+ `-A MULTI-0-INGRESS-0-PORTS -i net1 -m tcp -p tcp --dport 8888 -j MARK --set-xmark 0x10000/0x10000
1124+ -A MULTI-0-INGRESS-0-PORTS -i net1 -m tcp -p tcp --dport 9999:11111 -j MARK --set-xmark 0x10000/0x10000
1125+ `
1126+
1127+ Expect (buf .ingressPorts .String ()).To (Equal (portRules ))
1128+
1129+ buf .FinalizeRules ()
1130+ finalizedRules :=
1131+ `*filter
1132+ :MULTI-INGRESS - [0:0]
1133+ :MULTI-INGRESS-COMMON - [0:0]
1134+ :MULTI-EGRESS - [0:0]
1135+ :MULTI-EGRESS-COMMON - [0:0]
1136+ :MULTI-0-INGRESS - [0:0]
1137+ :MULTI-0-INGRESS-0-PORTS - [0:0]
1138+ :MULTI-0-INGRESS-0-FROM - [0:0]
1139+ -A MULTI-INGRESS -m comment --comment "policy:ingressPolicies1 net-attach-def:testns1/net-attach1" -i net1 -j MULTI-0-INGRESS
1140+ -A MULTI-INGRESS -m mark --mark 0x30000/0x30000 -j RETURN
1141+ -A MULTI-0-INGRESS -j MARK --set-xmark 0x0/0x30000
1142+ -A MULTI-0-INGRESS -j MULTI-0-INGRESS-0-PORTS
1143+ -A MULTI-0-INGRESS -j MULTI-0-INGRESS-0-FROM
1144+ -A MULTI-0-INGRESS -m mark --mark 0x30000/0x30000 -j RETURN
1145+ -A MULTI-0-INGRESS-0-PORTS -i net1 -m tcp -p tcp --dport 8888 -j MARK --set-xmark 0x10000/0x10000
1146+ -A MULTI-0-INGRESS-0-PORTS -i net1 -m tcp -p tcp --dport 9999:11111 -j MARK --set-xmark 0x10000/0x10000
1147+ -A MULTI-0-INGRESS-0-FROM -m comment --comment "no ingress from, skipped" -j MARK --set-xmark 0x20000/0x20000
1148+ COMMIT
1149+ `
1150+ Expect (buf .filterRules .String ()).To (Equal (finalizedRules ))
1151+ })
1152+
10661153 It ("ingress rules podselector/matchlabels" , func () {
10671154 port := intstr .FromInt (8888 )
10681155 protoTCP := v1 .ProtocolTCP
0 commit comments