-Convenience script for reference on generating IPv6 ULA (v6 equivalent of v4 10/8, 192.168/16 and 172.16/12 addresses)
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@8616 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
9d31ce3f41
commit
0f2d1aa0ca
35
xCAT-server/share/xcat/scripts/genula.sh
Normal file
35
xCAT-server/share/xcat/scripts/genula.sh
Normal file
@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
# This script will generate an IPv6 ULA. In IPv6, you know longer get to pick your favorite private network network and go for it,
|
||||
# you must accept a psuedorandom /48 out of the fd::/8 space. This script will generate a /48 for either deploying an isolated
|
||||
# ipv6 network that will almost certainly not conflict with present and future upstream ipv6 networks or just getting your feet wet
|
||||
# with ipv6
|
||||
|
||||
# Implements RFC5193, section 3.2.2, with precision only down to nanoseconds at best (normalized by date output
|
||||
SECSDOTNANO=$(date +%s.%N|sed -e 's/\.0*/\./')
|
||||
|
||||
NANOSECONDS=${SECSDOTNANO#*.}
|
||||
#Convert from nanoseconds to ntp fractional seconds (I'll call them ticks for convenience)
|
||||
# ns * 2**32 ticks/second * 1/1000000000 ns/s = ticks
|
||||
NTPTICKS=$(( ($NANOSECONDS<<32) /1000000000))
|
||||
|
||||
EPOCHDELTA=2208988800
|
||||
SECONDS=${SECSDOTNANO%.*}
|
||||
SECONDS=$(($SECONDS+$EPOCHDELTA))
|
||||
TIMESTAMP=$(printf "%08X:%08X" $SECONDS $NTPTICKS)
|
||||
|
||||
|
||||
#next, get a mac address and convert to eui64
|
||||
EUIPAD="FF:FE"
|
||||
MAC=$(/sbin/ifconfig|grep HWaddr|grep -v usb|grep -v 00:00:00:00:00:00|head -n 1|awk '{print $NF}')
|
||||
FIRSTBYTE=${MAC%%:*}
|
||||
FIRSTBYTE=$(printf %02X $((0x$FIRSTBYTE|2)))
|
||||
OTHERMANUF=${MAC%%:??:??:??}
|
||||
OTHERMANUF=${OTHERMANUF#??:}
|
||||
LOWMAC=${MAC#??:??:??:}
|
||||
EUI=$FIRSTBYTE:$OTHERMANUF:$EUIPAD:$LOWMAC
|
||||
|
||||
#now, to do the SHA, spec doesn't say much about encoding, so we'll just slap the data together the laziest way
|
||||
|
||||
PREFIX="fd"$(echo $TIMESTAMP:$EUI|sha1sum|awk '{print $1}'|cut -c 31-)
|
||||
PREFIX=$(echo $PREFIX|sed -e 's/\(....\)/\1:/g')
|
||||
echo $PREFIX:/48
|
Loading…
Reference in New Issue
Block a user