Skip to content

Commit 10d2ca8

Browse files
author
Naredula Janardhana Reddy
committed
bug 10617: blocking between security groups for egress rules fixed.
1 parent d18a1dd commit 10d2ca8

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎scripts/vm/hypervisor/xenserver/vmops‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def cleanup_rules(session, args):
889889
instance = 'VM'
890890

891891
try:
892-
chainscmd = "iptables-save | grep '^:' | awk '{print $1}' | cut -d':' -f2 | sed 's/-def/-%s/'|sort|uniq" % instance
892+
chainscmd = "iptables-save | grep '^:' | awk '{print $1}' | cut -d':' -f2 | sed 's/-def/-%s/' | sed 's/-egress//' |sort|uniq" % instance
893893
chains = util.pread2(['/bin/bash', '-c', chainscmd]).split('\n')
894894
cleaned = 0
895895
cleanup = []
@@ -1055,14 +1055,23 @@ def network_rules(session, args):
10551055
util.SMlog(" failed to create ipset for rule " + str(tokens))
10561056

10571057
if protocol == 'all':
1058-
iptables = ['iptables', '-I', vmchain, '-m', 'state', '--state', 'NEW', '-m', 'set', '--match-set', ipsetname, 'src', '-j', 'ACCEPT']
1058+
if type == 'egress':
1059+
iptables = ['iptables', '-I', vmchain, '-m', 'state', '--state', 'NEW', '-m', 'set', '--match-set', ipsetname, 'dst', '-j', 'ACCEPT']
1060+
else:
1061+
iptables = ['iptables', '-I', vmchain, '-m', 'state', '--state', 'NEW', '-m', 'set', '--match-set', ipsetname, 'src', '-j', 'ACCEPT']
10591062
elif protocol != 'icmp':
1060-
iptables = ['iptables', '-I', vmchain, '-p', protocol, '-m', protocol, '--dport', range, '-m', 'state', '--state', 'NEW', '-m', 'set', '--match-set', ipsetname, 'src', '-j', 'ACCEPT']
1063+
if type == 'egress':
1064+
iptables = ['iptables', '-I', vmchain, '-p', protocol, '-m', protocol, '--dport', range, '-m', 'state', '--state', 'NEW', '-m', 'set', '--match-set', ipsetname, 'dst', '-j', 'ACCEPT']
1065+
else:
1066+
iptables = ['iptables', '-I', vmchain, '-p', protocol, '-m', protocol, '--dport', range, '-m', 'state', '--state', 'NEW', '-m', 'set', '--match-set', ipsetname, 'src', '-j', 'ACCEPT']
10611067
else:
10621068
range = start + "/" + end
10631069
if start == "-1":
10641070
range = "any"
1065-
iptables = ['iptables', '-I', vmchain, '-p', 'icmp', '--icmp-type', range, '-m', 'set', '--match-set', ipsetname, 'src', '-j', 'ACCEPT']
1071+
if type == 'egress':
1072+
iptables = ['iptables', '-I', vmchain, '-p', 'icmp', '--icmp-type', range, '-m', 'set', '--match-set', ipsetname, 'dst', '-j', 'ACCEPT']
1073+
else:
1074+
iptables = ['iptables', '-I', vmchain, '-p', 'icmp', '--icmp-type', range, '-m', 'set', '--match-set', ipsetname, 'src', '-j', 'ACCEPT']
10661075
util.pread2(iptables)
10671076
util.SMlog(iptables)
10681077

‎scripts/vm/network/security_group.py‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def cleanup_rules_for_dead_vms():
487487
def cleanup_rules():
488488
try:
489489

490-
chainscmd = "iptables-save | grep '^:' | grep -v '.*-def' | awk '{print $1}' | cut -d':' -f2"
490+
chainscmd = "iptables-save | grep '^:' | grep -v '.*-def' | grep -v '.*-egress' | awk '{print $1}' | cut -d':' -f2"
491491
chains = execute(chainscmd).split('\n')
492492
cleaned = 0
493493
cleanup = []
@@ -620,16 +620,25 @@ def add_network_rules(vm_name, vm_id, vm_ip, signature, seqno, vmMac, rules, vif
620620
if ips:
621621
if protocol == 'all':
622622
for ip in ips:
623-
execute("iptables -I " + vmchain + " -m state --state NEW -s " + ip + " -j ACCEPT")
623+
if ruletype == 'egress':
624+
execute("iptables -I " + vmchain + " -m state --state NEW -d " + ip + " -j ACCEPT")
625+
else:
626+
execute("iptables -I " + vmchain + " -m state --state NEW -s " + ip + " -j ACCEPT")
624627
elif protocol != 'icmp':
625628
for ip in ips:
626-
execute("iptables -I " + vmchain + " -p " + protocol + " -m " + protocol + " --dport " + range + " -m state --state NEW -s " + ip + " -j ACCEPT")
629+
if ruletype == 'egress':
630+
execute("iptables -I " + vmchain + " -p " + protocol + " -m " + protocol + " --dport " + range + " -m state --state NEW -d " + ip + " -j ACCEPT")
631+
else:
632+
execute("iptables -I " + vmchain + " -p " + protocol + " -m " + protocol + " --dport " + range + " -m state --state NEW -s " + ip + " -j ACCEPT")
627633
else:
628634
range = start + "/" + end
629635
if start == "-1":
630636
range = "any"
631637
for ip in ips:
632-
execute("iptables -I " + vmchain + " -p icmp --icmp-type " + range + " -s " + ip + " -j ACCEPT")
638+
if ruletype == 'egress':
639+
execute("iptables -I " + vmchain + " -p icmp --icmp-type " + range + " -d " + ip + " -j ACCEPT")
640+
else:
641+
execute("iptables -I " + vmchain + " -p icmp --icmp-type " + range + " -s " + ip + " -j ACCEPT")
633642

634643
if allow_any and protocol != 'all':
635644
if protocol != 'icmp':

0 commit comments

Comments
 (0)