Bonjour à tous,
Je vous partage les scripts que j'utilisais quand j'avais un EdgeRouter 4. Normalement ils doivent continuer à bien fonctionner.
L'ONT était connecté sur eth1, utilisant l'interface eth1.832.
Script /config/scripts/generate_dhcpv6_configfile.sh
Ce script va lire la configuration dans /config/config.boot et va reutiliser les mêmes informations d'authentification pour IPv6 (adresse MAC et chaine d'authentification).
#!/bin/bash
target_file="/var/run/dhclient6_eth1_832.conf"
interface="eth1"
vif="832"
auth_string=$(/bin/cli-shell-api showCfg interfaces ethernet $interface vif $vif dhcp-options client-option | grep "send rfc3118-auth" | awk '{ print $4 }' | awk -F ";" '{print $1}')
mac_livebox=$(/bin/cli-shell-api showCfg interfaces ethernet $interface vif $vif dhcp-options client-option | grep "dhcp-client-identifier" | awk '{ print $4 }' | awk -F ";" '{print $1}')
read -r -d '' conffile <<EOF
# $target_file\n
option dhcp6.auth code 11 = string;\n
option dhcp6.vendorclass code 16 = string;\n
option dhcp6.userclass code 15 = string;\n
option dhcp6.vendor-specific-info code 17 = string;\n
\n
#External interface (VLAN must be 832 for Orange)\n
interface "$interface.$vif" {\n
\t#Orange France specific options\n
\tsend dhcp6.vendor-specific-info 00:16:00:00:05:58:00:06:00:0e:49:50:56:36:5f:52:45:51:55:45:53:54:45:44;\n
\tsend dhcp6.vendorclass 00:00:04:0e:00:05:73:61:67:65:6d;\n
\tsend dhcp6.userclass 00:2b:46:53:56:44:53:4c:5f:6c:69:76:65:62:6f:78:2e:49:6e:74:65:72:6e:65:74:2e:73:6f:66:74:61:74:68:6f:6d:65:2e:6c:69:76:65:62:6f:78:34;\n
\tsend dhcp6.vendor-opts 00:00:05:58:00:06:00:0e:49:50:56:36:5f:52:45:51:55:45:53:54:45:44;\n
\n
\t#Authentication for Orange France DHCP server (same value as for DHCPv4)\n
\tsend dhcp6.auth $auth_string;\n
\n
\tsend dhcp6.client-id 00:03:00:$mac_livebox;\n
\n
\trequest dhcp6.name-servers, dhcp6.vendorclass, dhcp6.userclass, dhcp6.auth;\n
}\n
EOF
echo -e $conffile > $target_file
Script /config/scripts/install_extra_config_files.sh
Ce script va créer les fichiers de configuration nécessaires pour avoir IPv6 avec le dhclient par défaut. Il faut l'executer après chaque reinstallation de l'OS.
J'avais quelques VLAN avec des clients qui utilisent IPv6 (eth0.120, eth0.200, eth0.180, eth2.150). Il faut modifier la ligne "IPV6_INTERFACES=(eth0.120 eth0.200 eth0.180 eth2.150)" en conséquence.
#!/bin/bash
# DHCPv6
target_dhcphook="/etc/dhcp3/dhclient-exit-hooks.d/dhclient-ipv6-exit-hook"
target_servicefile="/etc/systemd/system/dhclient6.service"
cat >$target_dhcphook << 'EOF'
# /etc/dhcp3/dhclient-exit-hooks.d/dhclient-ipv6-exit-hook 
# Interfaces that should obtain a /64 prefix
IPV6_INTERFACES=(eth0.120 eth0.200 eth0.180 eth2.150)
INT_ADDRESS="::cafe"
###
ipv6_prefix_setup() {
	# $1 is the ethernet interface
	# $2 is the suffix to use
	ethiface=$1
	suffix=$2
	
	current_ip=$(ip -6 addr show dev $ethiface scope global | awk '/inet6/ {print $2}' | grep -v '^fd' )
	current_prefix=$(echo $current_ip | sed -e 's@::.*/64@::/64@')
  
	# To generate new IP, need to take new prefix, add 8 bits
	new_ip=$( echo $new_ip6_prefix | sed -e 's/00::\/.*//g' )
	new_ip="$new_ip$suffix"
	if [ "$new_ip" != "$current_ip" ]
	then
		if [ "$current_ip" != "" ]
		then
			/sbin/ip -6 addr delete "$current_ip" dev $ethiface
		fi
	/sbin/ip -6 addr add "$new_ip" dev $ethiface
  
	fi
}
case "$reason" in
  BOUND6|REBIND6)
    # We will get called twice here - once for the temp address
    # and once for the prefix. We only care about the prefix.
	if [ ! -z "$new_ip6_prefix" ] ; then
		offset=$(( $RANDOM % (255 - ${#IPV6_INTERFACES[@]}) ))		
		for interface in "${IPV6_INTERFACES[@]}"
		do
			index=1
			for i in "${!IPV6_INTERFACES[@]}"
			do
				if [[ "${IPV6_INTERFACES[i]}" = "${interface}" ]]
				then
					index="${i}"
					break
				fi
			done
			
			index=$(( $index + $offset ))
			suffix=$(printf "%0*x" 2 $index )				
			suffix="$suffix$INT_ADDRESS/64"
	                
			ipv6_prefix_setup ${interface} $suffix
		done
	
	/bin/systemctl restart radvd.service >/dev/null 2>&1
	fi
	;;
esac
EOF
cat >$target_servicefile << 'EOF'
#/etc/systemd/system/dhclient6.service
[Unit]
Description=dhclient for sending IPv6 DUID
After=network.target auditd.service vyatta-router.service netplug.service
[Service]
Type=forking
ExecStartPre=/config/scripts/generate_dhcpv6_configfile.sh
ExecStart=/sbin/dhclient -6 -P -nw -cf /var/run/dhclient6_eth1_832.conf -pf /var/run/dhclient6_eth1_832.pid -lf /var/run/dhclient6_eth1_832.leases eth1.832
NonBlocking=yes                               
Restart=always
RestartSec=60
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd configuration files and start dhclient6
/bin/systemctl daemon-reload
/bin/systemctl enable dhclient6
Enfin, la configuration de eth1.832 (extrait de /config/config.boot) :
    ethernet eth1 {
        description "WAN (Internet)"
        duplex auto
        speed auto
        vif 832 {
            address dhcp
            description "VLAN Internet"
            dhcp-options {
                client-option "send vendor-class-identifier "sagem";"
                client-option "send user-class "\053FSVDSL_livebox.Internet.softathome.Livebox4";"
                client-option "send dhcp-client-identifier 01:XX:XX:XX:XX:XX:XX;"
                client-option "request subnet-mask, routers, domain-name-servers, domain-name, broadcast-address, dhcp-lease-time, dhcp-renewal-time, dhcp-rebinding-time, rfc3118-authentication, domain-search, Vendor-Specific-Information;"
                client-option "send rfc3118-authentication 00:00:00:00:00:00:00:00:00:00:00:1a:09:00:00:05:58:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX;"
                default-route update
                default-route-distance 210
                global-option "option rfc3118-authentication code 90 = string;"
                global-option "option Vendor-Specific-Information code 125 = string;"
                name-server no-update
            }
            egress-qos "0:0 1:0 2:0 3:0 4:0 5:0 6:6 7:0"
            ipv6 {
                address {
                    autoconf
                }
                dup-addr-detect-transmits 1
            }
        }
    }