Skip to content

Commit 91c0c7e

Browse files
murali-reddyDaanHoogland
authored andcommitted
CLOUDSTACK-6685: OVS distributed firewall: source CIDR mismatch while
populating ingress & egress network ACL fix ensures propoer values for nw_src and nw_dst are popoluated depending on the ingress or egress acl
1 parent ccd0e23 commit 91c0c7e

1 file changed

Lines changed: 82 additions & 30 deletions

File tree

‎scripts/vm/hypervisor/xenserver/cloudstack_pluginlib.py‎

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,12 @@ def configure_vpc_bridge_for_routing_policies(bridge, json_config, sequence_no):
634634
protocol = acl_item.protocol
635635
if protocol == "all":
636636
protocol = "*"
637+
elif protocol == "tcp":
638+
protocol = "6"
639+
elif protocol == "udp":
640+
protocol == "17"
641+
elif protocol == "icmp":
642+
protocol == "1"
637643
source_cidrs = acl_item.sourcecidrs
638644
acl_priority = 1000 + number
639645
if direction == "ingress":
@@ -647,50 +653,96 @@ def configure_vpc_bridge_for_routing_policies(bridge, json_config, sequence_no):
647653
if source_port_start is None and source_port_end is None:
648654
if source_cidr.startswith('0.0.0.0'):
649655
if action == "deny":
650-
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
651-
" nw_dst=%s " %tier_cidr + " nw_proto=%s " %protocol +
652-
" actions=drop" + "\n")
656+
if direction == "ingress":
657+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
658+
" nw_dst=%s " %tier_cidr + " nw_proto=%s " %protocol +
659+
" actions=drop" + "\n")
660+
else:
661+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
662+
" nw_src=%s " %tier_cidr + " nw_proto=%s " %protocol +
663+
" actions=drop" + "\n")
653664
if action == "allow":
654-
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
655-
" nw_dst=%s " %tier_cidr + " nw_proto=%s " %protocol +
656-
" actions=resubmit(,%s)"%resubmit_table + "\n")
657-
665+
if direction == "ingress":
666+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
667+
" nw_dst=%s " %tier_cidr + " nw_proto=%s " %protocol +
668+
" actions=resubmit(,%s)"%resubmit_table + "\n")
669+
else:
670+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
671+
" nw_src=%s " %tier_cidr + " nw_proto=%s " %protocol +
672+
" actions=resubmit(,%s)"%resubmit_table + "\n")
658673
else:
659674
if action == "deny":
660-
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
661-
" nw_src=%s " %source_cidr + " nw_dst=%s " %tier_cidr +
662-
" nw_proto=%s " %protocol + " actions=drop" + "\n")
675+
if direction == "ingress":
676+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
677+
" nw_src=%s " %source_cidr + " nw_dst=%s " %tier_cidr +
678+
" nw_proto=%s " %protocol + " actions=drop" + "\n")
679+
else:
680+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
681+
" nw_src=%s " %tier_cidr + " nw_dst=%s " %source_cidr +
682+
" nw_proto=%s " %protocol + " actions=drop" + "\n")
663683
if action == "allow":
664-
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
665-
" nw_src=%s "%source_cidr + " nw_dst=%s " %tier_cidr +
666-
" nw_proto=%s " %protocol +
667-
" actions=resubmit(,%s)"%resubmit_table + "\n")
684+
if direction == "ingress":
685+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
686+
" nw_src=%s "%source_cidr + " nw_dst=%s " %tier_cidr +
687+
" nw_proto=%s " %protocol +
688+
" actions=resubmit(,%s)"%resubmit_table + "\n")
689+
else:
690+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
691+
" nw_src=%s "%tier_cidr + " nw_dst=%s " %source_cidr +
692+
" nw_proto=%s " %protocol +
693+
" actions=resubmit(,%s)"%resubmit_table + "\n")
668694
continue
669695

670696
# add flow rule to do action (allow/deny) for flows where source IP of the packet is in
671697
# source_cidr and destination ip is in tier_cidr
672-
port = source_port_start
673-
while (port < source_port_end):
698+
port = int(source_port_start)
699+
while (port <= int(source_port_end)):
674700
if source_cidr.startswith('0.0.0.0'):
675701
if action == "deny":
676-
ofspec.write("table=%s " %matching_table + " priority=%s " %acl_priority + " ip " +
677-
" tp_dst=%s " %port + " nw_dst=%s " %tier_cidr +
678-
" nw_proto=%s " %protocol + " actions=drop" + "\n")
702+
if direction == "ingress":
703+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
704+
" tp_dst=%s " %port + " nw_dst=%s " %tier_cidr +
705+
" nw_proto=%s " %protocol + " actions=drop" + "\n")
706+
else:
707+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
708+
" tp_dst=%s " %port + " nw_src=%s " %tier_cidr +
709+
" nw_proto=%s " %protocol + " actions=drop" + "\n")
679710
if action == "allow":
680-
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
681-
" tp_dst=%s " %port + " nw_dst=%s " %tier_cidr +
682-
" nw_proto=%s " %protocol +
683-
" actions=resubmit(,%s)"%resubmit_table + "\n")
711+
if direction == "ingress":
712+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
713+
" tp_dst=%s " %port + " nw_dst=%s " %tier_cidr +
714+
" nw_proto=%s " %protocol +
715+
" actions=resubmit(,%s)"%resubmit_table + "\n")
716+
else:
717+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
718+
" tp_dst=%s " %port + " nw_src=%s " %tier_cidr +
719+
" nw_proto=%s " %protocol +
720+
" actions=resubmit(,%s)"%resubmit_table + "\n")
684721
else:
685722
if action == "deny":
686-
ofspec.write("table=%s " %matching_table + " priority=%s " %acl_priority + " ip " +
687-
" tp_dst=%s " %port + " nw_src=%s "%source_cidr + " nw_dst=%s "%tier_cidr +
688-
" nw_proto=%s " %protocol + " actions=drop" + "\n")
723+
if direction == "ingress":
724+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
725+
" tp_dst=%s " %port + " nw_src=%s " %source_cidr +
726+
" nw_dst=%s " %tier_cidr +
727+
" nw_proto=%s " %protocol + " actions=drop" + "\n")
728+
else:
729+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
730+
" tp_dst=%s " %port + " nw_src=%s " %tier_cidr +
731+
" nw_dst=%s " %source_cidr +
732+
" nw_proto=%s " %protocol + " actions=drop" + "\n")
689733
if action == "allow":
690-
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
691-
" tp_dst=%s " %port + " nw_src=%s "%source_cidr + " nw_dst=%s "%tier_cidr +
692-
" nw_proto=%s " %protocol +
693-
" actions=resubmit(,%s)"%resubmit_table + "\n")
734+
if direction == "ingress":
735+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
736+
" tp_dst=%s " %port + " nw_src=%s "%source_cidr +
737+
" nw_dst=%s " %tier_cidr +
738+
" nw_proto=%s " %protocol +
739+
" actions=resubmit(,%s)"%resubmit_table + "\n")
740+
else:
741+
ofspec.write("table=%s "%matching_table + " priority=%s " %acl_priority + " ip " +
742+
" tp_dst=%s " %port + " nw_src=%s "%tier_cidr +
743+
" nw_dst=%s " %source_cidr +
744+
" nw_proto=%s " %protocol +
745+
" actions=resubmit(,%s)"%resubmit_table + "\n")
694746
port = port + 1
695747

696748
# add a default rule in egress table to allow packets (so forward packet to L3 lookup table)

0 commit comments

Comments
 (0)