interfaces(ipv6): début de facto + wifi
This commit is contained in:
parent
10421ec7d5
commit
28cb84804e
1 changed files with 57 additions and 9 deletions
|
@ -167,29 +167,77 @@ def admip6(If):
|
|||
else: alt = ''
|
||||
return "2a01:240:fe3d:c804:" + alt + If_Mac[If]
|
||||
|
||||
def wifiip6(If):
|
||||
if len(If_Mac[If].split(':'))<4: alt = ':'
|
||||
else: alt = ''
|
||||
return "2a01:240:fe3d:c04:" + alt + If_Mac[If]
|
||||
|
||||
def radinip6(If):
|
||||
if len(If_Mac[If].split(':'))<4: alt = ':'
|
||||
else: alt = ''
|
||||
return "2001:470:c8b9:a4:" + alt + If_Mac[If]
|
||||
|
||||
def pub6(interface, mode = 'serveur'):
|
||||
def eui64(If):
|
||||
if len(If_Mac[If].split(':'))<4: alt = ':'
|
||||
else: alt = ''
|
||||
return alt + If_Mac[If]
|
||||
|
||||
def str64(name):
|
||||
"""Construit un suffixe 64 bits à partir d'une chaine"""
|
||||
name = name[:8]
|
||||
name = '\x00'*(8-len(name)) + name
|
||||
attr = ''
|
||||
for x in range(4):
|
||||
block = (ord(name[2*x])<<8) + ord(name[2*x+1])
|
||||
attr += ':%x' % block
|
||||
|
||||
skip = False
|
||||
while attr.startswith(':0:'):
|
||||
skip = True
|
||||
attr = attr[2:]
|
||||
if not skip:
|
||||
attr = attr[1:]
|
||||
return attr
|
||||
|
||||
def interface6(interface, list_ip, mode = 'serveur'):
|
||||
""" fonction permettant d'ajouter une adressse ipv6 a l'interface donnee en argument.
|
||||
Le mode permet de faire la distinction entre les simples serveurs et les routeurs.
|
||||
"""
|
||||
main_ip = list_ip[0]
|
||||
list_ip = list_ip[1:]
|
||||
print """iface %(interface)s inet6 static
|
||||
address %(ip6)s
|
||||
netmask 64""" % { 'interface': interface, 'ip6': pubip6(interface) }
|
||||
if mode == 'serveur':
|
||||
netmask %(netmask)s""" % {
|
||||
'interface': interface,
|
||||
'ip6': main_ip.split('/')[0],
|
||||
'netmask': main_ip.split('/')[1],
|
||||
}
|
||||
# Avoid loops
|
||||
if mode != 'routeur':
|
||||
print ' gateway fe80::1'
|
||||
elif mode == 'routeur':
|
||||
# Le routeur est le ::1 du réseau
|
||||
add_ip = ['2a01:240:fe3d:4::1/64', 'fe80::1/64']
|
||||
for ip in add_ip:
|
||||
print ' up ip a add %s dev $IFACE' % ip
|
||||
print ' down ip a delete %s dev $IFACE' % ip
|
||||
for ip in list_ip:
|
||||
print ' up ip a add %s dev $IFACE' % ip
|
||||
print ' down ip a delete %s dev $IFACE' % ip
|
||||
print ' up /sbin/sysctl net/ipv6/conf/$IFACE/autoconf=0'
|
||||
print
|
||||
|
||||
def pub6(interface, mode='serveur', list_ip=[]):
|
||||
list_ip = [pubip6(interface) + '/64'] + list_ip
|
||||
if mode == 'routeur':
|
||||
# Le routeur est le ::1 du réseau
|
||||
list_ip += ['2a01:240:fe3d:4::1/64', 'fe80::1/64']
|
||||
interface6(interface, list_ip, mode=mode)
|
||||
|
||||
def wifi6(interface, list_ip=[], name=None):
|
||||
conf_prefix = "fda8:5d34:a228:c04:%s/64"
|
||||
list_ip = [ "2a01:240:fe3d:c04:%s/64" % eui64(interface),
|
||||
conf_prefix % eui64(interface),
|
||||
] + list_ip
|
||||
if name is not None:
|
||||
list_ip.append(conf_prefix % str64(name))
|
||||
|
||||
interface6(interface, list_ip)
|
||||
|
||||
def adm6(interface):
|
||||
print """iface %(interface)s inet6 static
|
||||
address %(ip6)s
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue