From a2369dadf4290189376af0d775cba66071834499 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Tue, 5 Nov 2013 13:24:15 +0100 Subject: [PATCH] [ipv6only] Modifications pour pettre des machines sans ipv4 et pare feu pour nat64 --- gestion/config/config.py | 1 + gestion/config/config_srv.py | 3 +-- gestion/config/dns.py | 2 +- gestion/config/extractionbcfg2.py | 14 +++++++------ gestion/gen_confs/bind.py | 16 ++++++++++----- gestion/gen_confs/dhcpd_new.py | 2 +- gestion/gen_confs/firewall4.py | 3 ++- gestion/gen_confs/firewall6.py | 34 +++++++++++++++++++++++++++++++ gestion/ipt.py | 13 +++++++----- 9 files changed, 67 insertions(+), 21 deletions(-) diff --git a/gestion/config/config.py b/gestion/config/config.py index 9c119c7f..0f4dadd3 100644 --- a/gestion/config/config.py +++ b/gestion/config/config.py @@ -249,6 +249,7 @@ prefix = { 'subnet' : [ '2a01:240:fe3d::/48' ], 'evenementiel' : [ '2a01:240:fe3d:d2::/64' ], 'bornes' : [ '2a01:240:fe3d:c04::/64' ], 'wifi-adh' : [ '2a01:240:fe3d:c04::/64' ], + 'v6only' : [ '2001:470:c8b9:a4::/64' ], } # Domaines dans lesquels les machines sont placées suivant leur type diff --git a/gestion/config/config_srv.py b/gestion/config/config_srv.py index 3ae27ad1..7b65dc1d 100644 --- a/gestion/config/config_srv.py +++ b/gestion/config/config_srv.py @@ -2,8 +2,7 @@ # -*- coding: utf-8 -*- # Généré par gestion/extractionbcfg2.py sur bcfg2, à partir de Metadata/groups.xml -# Fichier obsolète (backward comp ftw) adm_only = [] -role = {'zamok': ['adherents-server'], 'dyson': ['sniffer'], 'titanic': ['failover-proxy'], 'komaz': ['wifi-router', 'appt-proxy', 'main-router'], 'dhcp': ['appt-proxy'], 'ovh': ['externe'], 'routeur': ['appt-proxy']} +role = {'zamok': ['adherents-server'], 'nat64': ['routeur-nat64'], 'komaz': ['wifi-router', 'appt-proxy', 'main-router'], 'dyson': ['sniffer'], 'isc': ['appt-proxy'], 'dhcp': ['appt-proxy'], 'ovh': ['externe'], 'routeur': ['appt-proxy']} diff --git a/gestion/config/dns.py b/gestion/config/dns.py index 27299bfa..88804d86 100644 --- a/gestion/config/dns.py +++ b/gestion/config/dns.py @@ -53,7 +53,7 @@ recursiv = { 'wifi' : ['138.231.136.98', '138.231.136.152'], 'evenementiel' : ['138.231.136.98', '138.231.136.152'], 'adm' : ['10.231.136.98', '10.231.136.152'], - 'gratuit' : ['10.42.0.10'], + 'gratuit' : ['10.42.0.164'], 'accueil' : ['10.51.0.10'], 'isolement' : ['10.52.0.10'], 'personnel-ens' : ['10.2.9.10', '138.231.136.98', '138.231.136.152'], diff --git a/gestion/config/extractionbcfg2.py b/gestion/config/extractionbcfg2.py index 98613d3e..ba5903e7 100755 --- a/gestion/config/extractionbcfg2.py +++ b/gestion/config/extractionbcfg2.py @@ -18,20 +18,22 @@ role = %(role_dict)s srvDict = { 'external' : [], 'connection-main' : [], - 'failover-proxy-server' : [], +# 'failover-proxy-server' : [], 'vlan-ens' : [], 'users' : [], 'sniffer' : [], - 'router-wifi' : [] + 'router-wifi' : [], + 'routeur-nat64' : [], } tr = { 'external' : 'externe', 'connection-main' : 'main-router', 'vlan-ens' : 'appt-proxy', - 'failover-proxy-server' : 'failover-proxy', +# 'failover-proxy-server' : 'failover-proxy', 'router-wifi' : 'wifi-router', 'users' : 'adherents-server', - 'sniffer' : 'sniffer' + 'sniffer' : 'sniffer', + 'routeur-nat64' : 'routeur-nat64', } fin = open('/var/lib/bcfg2/Metadata/groups.xml') @@ -46,7 +48,6 @@ for key in srvDict.keys(): print "Erreur, il n'y a pas de serveur associé à l'attribut %s" % key exit(1) - # On cherche les serveurs qui sont seulement sur le vlan adm admOnly = parsedGroups.xpath('//Group[@name="adm-only"]/../@name') @@ -60,8 +61,9 @@ for key, values in srvDict.items(): else: out[value] = [tr[key]] -fout = open('/usr/scripts/gestion/config_srv.py', 'w') +fout = open('/usr/scripts/gestion/config/config_srv.py', 'w') fout.write(template % {'adm_list': admOnly.__str__(), 'role_dict' : out.__str__()}) fout.close() + diff --git a/gestion/gen_confs/bind.py b/gestion/gen_confs/bind.py index e4876ad1..b14cdbbd 100755 --- a/gestion/gen_confs/bind.py +++ b/gestion/gen_confs/bind.py @@ -356,7 +356,9 @@ zone "%(NOM_zone)s" { # Le direct if zone in self.zones_direct : - ligne = "%s\tIN\tA\t%s\n" % ( nom, machine.ip() ) + ligne='' + if machine.ip() != '': + ligne += "%s\tIN\tA\t%s\n" % ( nom, machine.ip() ) # Si la machine est une borne wifi, on ajoute la position if isinstance(machine,ldap_crans.BorneWifi) and machine.position(): ligne +="%s\tIN\tTXT\t\"LOC %s,%s \"\n" % (nom,machine.position()[0],machine.position()[1]) @@ -402,9 +404,10 @@ zone "%(NOM_zone)s" { alias = alias.encode('utf-8') # Cas particulier : nom de l'alias = nom de la zone if alias in self.zones_direct : - ligne = "@\tIN\tA\t%s\n" % machine.ip() - ligne = ligne.encode('utf-8') - direct[alias] = direct.get(alias, "") + ligne + if machine.ip() != '': + ligne = "@\tIN\tA\t%s\n" % machine.ip() + ligne = ligne.encode('utf-8') + direct[alias] = direct.get(alias, "") + ligne if machine.dnsIpv6(): ligne = "@\tIN\tAAAA\t%s\n" % machine.ipv6() ligne = ligne.encode('utf-8') @@ -441,7 +444,10 @@ zone "%(NOM_zone)s" { # Le reverse ip = machine.ip() - net = AddrInNets(ip, self.zones_reverse) + if ip == '': + net=False + else: + net = AddrInNets(ip, self.zones_reverse) if net: base_ip = ip.split('.') base_ip.reverse() diff --git a/gestion/gen_confs/dhcpd_new.py b/gestion/gen_confs/dhcpd_new.py index 8bb79ec6..bc2327af 100644 --- a/gestion/gen_confs/dhcpd_new.py +++ b/gestion/gen_confs/dhcpd_new.py @@ -145,7 +145,7 @@ class dhcp(gen_config) : for machine in self.machines : self.anim.cycle() for net in self.reseaux.keys() : - if AddrInNet(machine.ip(), net) : + if machine.ip() != '' and AddrInNet(machine.ip(), net) : host_template = self.host_template # variable pour remplir le template #d = { 'nom' : machine.nom().split('.')[0] , 'mac' : machine.mac() , 'ip' : machine.ip() } diff --git a/gestion/gen_confs/firewall4.py b/gestion/gen_confs/firewall4.py index 3e60a20f..4cec028a 100755 --- a/gestion/gen_confs/firewall4.py +++ b/gestion/gen_confs/firewall4.py @@ -480,6 +480,7 @@ class firewall_komaz(firewall_base_routeur): 'filtrage_ports' : self.filtrage_ports, 'limitation_debit' : self.limitation_debit, 'limit_ssh_connexion' : self.limit_ssh_connexion, + 'tunnel_6in4' : self.tunnel_6in4, }) self.use_ipset.extend([self.blacklist_soft, self.blacklist_upload, self.reseaux_non_routable]) @@ -569,7 +570,7 @@ class firewall_komaz(firewall_base_routeur): def tunnel_6in4(self, table=None, apply=False): chain = 'TUNNEL_IPV6' - tunnels_ipv6 = [ ('216.66.84.42', '138.231.136.12') ] + tunnels_ipv6 = [ ('216.66.84.42', '138.231.136.12'), ('216.66.84.42','138.231.136.164') ] if table == 'filter': pretty_print(table, chain) diff --git a/gestion/gen_confs/firewall6.py b/gestion/gen_confs/firewall6.py index d7797888..69d010a8 100755 --- a/gestion/gen_confs/firewall6.py +++ b/gestion/gen_confs/firewall6.py @@ -200,6 +200,40 @@ def main_router(): # On met en place le forwarding enable_forwarding(6) + +def routeur_nat64(): + ''' Firewall pour le nat64 ''' + + dev_crans = iface6('fil') + dev_adm = iface6('adm') + dev_v6only = iface6('v6only') + + # Les blacklistes + # Si on les met après la règle conntrack, une connexion existante ne sera + # pas sevrée et dinc avec un tunnel ssh idoine, la blacklist aurait aucun + # effet. + # Alternative : flusher la table conntrack des entrées concernant cette + # machine. + blacklist(ip6tables) + ip6tables.filter.forward('-i %s -j BLACKLIST_SRC' % dev_v6only) + ip6tables.filter.forward('-i %s -j BLACKLIST_DST' % dev_crans) + + + ip6tables.filter.forward('-m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT') + + # Pour les autres connections + for type_m in [i for i in ['fil', 'adherents-v6', 'wifi', 'wifi-adh-v6'] if not 'v6' in i]: + ip6tables.filter.mac('-s %s -j %s' % (prefix[type_m][0], 'MAC' + + type_m.upper())) + ip6tables.filter.forward('-i %s -j MAC' % dev_crans) + + # Rien ne passe vers adm + # est ce que du local est gêné par le règle ? + ip6tables.filter.forward('-d %s -j REJECT --reject-with icmp6-addr-unreachable' % (prefix['adm'][0])) + + # On met en place le forwarding + enable_forwarding(6) + def wifi_router(): ''' Firewall pour le router du wifi ''' # Le wifi est maintenant routé directement sur komaz. diff --git a/gestion/ipt.py b/gestion/ipt.py index eea46700..919fcd55 100644 --- a/gestion/ipt.py +++ b/gestion/ipt.py @@ -19,7 +19,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - +import sys import os, re, syslog, cPickle, socket from ldap_crans import crans_ldap, hostname @@ -801,10 +801,13 @@ def mac_ip(ipt, machines, types_machines): macips(ipt, machines, types_machines) for type_m in types_machines: if not '-v6' in type_m and not type_m in tab.keys(): - dev = iface6(type_m) - ipt.filter.input('-i %s -s %s -j %s' % (dev, prefix[type_m][0], - 'MAC' + type_m.upper())) - ipt.filter.input('-i %s -j IEUI64' % dev) + try: + dev = iface6(type_m) + ipt.filter.input('-i %s -s %s -j %s' % (dev, prefix[type_m][0], + 'MAC' + type_m.upper())) + ipt.filter.input('-i %s -j IEUI64' % dev) + except NoIface as e: + sys.stderr.write("NoIface: %s" % e) # On active les extensions de vie privée for net in prefix['subnet']: