X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=net.py;h=c03035fe07893fd07206243e4f8ea1d1fe375687;hb=187bb4c3140fd0820a92d61eeda004b52403a955;hp=b0874a686c3286a32edbad52a52322c384033e2a;hpb=e64ef2834756a1a4e3f8d0dc843eb144f528f11e;p=nodemanager.git diff --git a/net.py b/net.py index b0874a6..c03035f 100644 --- a/net.py +++ b/net.py @@ -1,4 +1,5 @@ # +# $Id$ # """network configuration""" @@ -7,6 +8,7 @@ import bwlimit import logger import string import iptables +import os def GetSlivers(plc, data): InitNodeLimit(data) @@ -21,12 +23,10 @@ def InitNodeLimit(data): for dev in devs: macs[sioc.gifhwaddr(dev).lower()] = dev - # XXX Exempt Internet2 destinations from node bwlimits - # bwlimit.exempt_init('Internet2', internet2_ips) for network in data['networks']: # Get interface name preferably from MAC address, falling # back on IP address. - if macs.has_key(network['mac']): + if macs.has_key(network['mac'].lower()): dev = macs[network['mac'].lower()] elif ips.has_key(network['ip']): dev = ips[network['ip']] @@ -59,9 +59,23 @@ def InitI2(plc, data): logger.log("This is an Internet2 node. Setting rules.") i2nodes = [] i2nodeids = plc.GetNodeGroups(["Internet2"])[0]['node_ids'] - for node in plc.GetNodeNetworks({"node_id": i2nodeids}, ["ip"]): + for node in plc.GetInterfaces({"node_id": i2nodeids}, ["ip"]): + # Get the IPs i2nodes.append(node['ip']) + # this will create the set if it doesn't already exist + # and add IPs that don't exist in the set rather than + # just recreateing the set. bwlimit.exempt_init('Internet2', i2nodes) + + # set the iptables classification rule if it doesnt exist. + cmd = '-A POSTROUTING -m set --set Internet2 dst -j CLASSIFY --set-class 0001:2000 --add-mark' + rules = [] + ipt = os.popen("/sbin/iptables-save") + for line in ipt.readlines(): rules.append(line.strip(" \n")) + ipt.close() + if cmd not in rules: + logger.verbose("net: Adding iptables rule for Internet2") + os.popen("/sbin/iptables -t mangle " + cmd) def InitNAT(plc, data): # query running network interfaces @@ -84,19 +98,19 @@ def InitNAT(plc, data): continue try: - settings = plc.GetNodeNetworkSettings({'nodenetwork_setting_id': network['nodenetwork_setting_ids']}) + settings = plc.GetInterfaceSettings({'interface_setting_id': network['interface_setting_ids']}) except: continue # XXX arbitrary names for setting in settings: - if setting['category'] != 'firewall': + if setting['category'].upper() != 'FIREWALL': continue - if setting['name'] == 'external': + if setting['name'].upper() == 'EXTERNAL': # Enable NAT for this interface ipt.add_ext(dev) - elif setting['name'] == 'internal': + elif setting['name'].upper() == 'INTERNAL': ipt.add_int(dev) - elif setting['name'] == 'pf': # XXX Uglier code is hard to find... + elif setting['name'].upper() == 'PF': # XXX Uglier code is hard to find... for pf in setting['value'].split("\n"): fields = {} for field in pf.split(","):