Skip to content

Commit f1fb7c3

Browse files
author
Anthony Xu
committed
in security group, CS put a rule in ebtables filter table FORWARD chain to prevent user from changing VM mac address
util.pread2(['ebtables', '-A', vm_chain, '-i', vif, '-s', '!', vm_mac, '-j', 'DROP']) if user changes the VM mac address, all egress packet from the VM will be dropped, but the egress packet still contaminate the bridge cache with fake MAC, This patch moves the rule to ebtables nat table PREROUTING chain, then the egress packet with modified MAC will not contaminate the bridge cache. Anthony
1 parent e4f8068 commit f1fb7c3

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

scripts/vm/hypervisor/xenserver/ovs-vif-flows.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,35 @@ def apply_flows(bridge, this_vif_ofport, vif_ofports):
5252
pluginlib.add_flow(bridge, priority=1100,
5353
nw_dst='224.0.0.0/24', actions=action)
5454

55+
def clear_rules(vif):
56+
try:
57+
delcmd = "/sbin/ebtables -t nat -L PREROUTING | grep " + vif
58+
delcmds = pluginlib.do_cmd(['/bin/bash', '-c', delcmd]).split('\n')
59+
for cmd in delcmds:
60+
try:
61+
cmd = '/sbin/ebtables -t nat -D PREROUTING ' + cmd
62+
pluginlib.do_cmd(['/bin/bash', '-c', cmd])
63+
except:
64+
pass
65+
except:
66+
pass
67+
5568

5669
def main(command, vif_raw):
5770
if command not in ('online', 'offline'):
5871
return
72+
73+
vif_name, dom_id, vif_index = vif_raw.split('-')
74+
# validate vif and dom-id
75+
this_vif = "%s%s.%s" % (vif_name, dom_id, vif_index)
5976
# Make sure the networking stack is not linux bridge!
6077
net_stack = pluginlib.do_cmd(['cat', '/etc/xensource/network.conf'])
6178
if net_stack.lower() == "bridge":
79+
if command == 'offline':
80+
clear_rules(this_vif)
6281
# Nothing to do here!
6382
return
6483

65-
vif_name, dom_id, vif_index = vif_raw.split('-')
66-
# validate vif and dom-id
67-
this_vif = "%s%s.%s" % (vif_name, dom_id, vif_index)
68-
6984
bridge = pluginlib.do_cmd([pluginlib.VSCTL_PATH, 'iface-to-br', this_vif])
7085

7186
# find xs network for this bridge, verify is used for ovs tunnel network

scripts/vm/hypervisor/xenserver/vmops

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ def can_bridge_firewall(session, args):
486486
try:
487487
util.pread2(['ebtables', '-V'])
488488
util.pread2(['ipset', '-V'])
489+
cmd = ['cat', '/etc/xensource/network.conf']
490+
result = util.pread2(cmd)
491+
if result.lower().strip() != "bridge":
492+
return 'false'
493+
489494
except:
490495
return 'false'
491496

@@ -749,7 +754,11 @@ def default_ebtables_antispoof_rules(vm_chain, vifs, vm_ip, vm_mac):
749754
try:
750755
for vif in vifs:
751756
# only allow source mac that belongs to the vm
752-
util.pread2(['ebtables', '-A', vm_chain, '-i', vif, '-s', '!', vm_mac, '-j', 'DROP'])
757+
try:
758+
util.pread2(['ebtables', '-t', 'nat', '-I', 'PREROUTING', '-i', vif, '-s', '!' , vm_mac, '-j', 'DROP'])
759+
except:
760+
util.pread2(['ebtables', '-A', vm_chain, '-i', vif, '-s', '!', vm_mac, '-j', 'DROP'])
761+
753762
# do not allow fake dhcp responses
754763
util.pread2(['ebtables', '-A', vm_chain, '-i', vif, '-p', 'IPv4', '--ip-proto', 'udp', '--ip-dport', '68', '-j', 'DROP'])
755764
# do not allow snooping of dhcp requests

0 commit comments

Comments
 (0)