Mise en place des fonctions de calcul d'ip en fonction des mid, et macs, pour l'ipv6
This commit is contained in:
parent
c805146ab5
commit
c955638859
2 changed files with 39 additions and 2 deletions
|
@ -34,7 +34,7 @@ sys.path.append('/usr/scripts/gestion')
|
|||
import config
|
||||
from unicodedata import normalize
|
||||
|
||||
def ip_of_mid(mid):
|
||||
def ip4_of_mid(mid):
|
||||
"""Convertit un mid en son IP associée"""
|
||||
for net, plage in config.mid.items():
|
||||
if mid >= plage[0] and mid <= plage[1]:
|
||||
|
@ -50,6 +50,43 @@ def ip_of_mid(mid):
|
|||
|
||||
return netaddr.IPAddress(netaddr.IPNetwork(config.NETs[net][0]).first + mid - plage[0])
|
||||
|
||||
def prefixev6_of_mid(mid):
|
||||
"""
|
||||
L'ip de sous-réseau privé d'une machine. L'adhérent en fait ce qu'il veut, mais c'est la machine
|
||||
associée au mid qui est responsable du traffic.
|
||||
|
||||
Cette fonction retourne l'ip de début de ce sous-réseau.
|
||||
"""
|
||||
for net, plage in config.mid.items():
|
||||
if mid >= plage[0] and mid <= plage[1]:
|
||||
break
|
||||
else:
|
||||
raise ValueError("Mid dans aucune plage: %d" % mid)
|
||||
|
||||
# fil-v6 ou wifi-v6, we don't care
|
||||
return netaddr.IPAddress(netaddr.IPNetwork(config.prefix['fil-v6'][0]).first + 2**64*mid)
|
||||
|
||||
def ip6_of_mac(mac, mid):
|
||||
"""
|
||||
Retourne la bonne ipv6 de la machine en fonction de sa mac et de son mid.
|
||||
"""
|
||||
|
||||
for net, plage in config.mid.items():
|
||||
if mid >= plage[0] and mid <= plage[1]:
|
||||
break
|
||||
else:
|
||||
raise ValueError("Mid dans aucune plage: %d" % mid)
|
||||
|
||||
# En théorie, format_mac est inutile, car on ne devrait avoir
|
||||
# que des mac formatées.
|
||||
mac = format_mac(mac).replace(':', '')
|
||||
|
||||
# hex retourne un str, donc on concatène, suivant la RFC
|
||||
euid64v6 = hex(int(mac[:2], 16)^0b00000010) + mac[2:6] + 'fffe' + mac[6:12]
|
||||
|
||||
# fil-v6 ou wifi-v6, we don't care
|
||||
return netaddr.IPAddress(netaddr.IPNetwork(config.prefix[net][0]).first + int(euid64v6, 16))
|
||||
|
||||
def strip_accents(a):
|
||||
""" Supression des accents de la chaîne fournie"""
|
||||
res = normalize('NFKD', a).encode('ASCII', 'ignore')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue