From 0f2d1aa0caf07cedfb6373787fbcaf5d95fd7f6e Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Tue, 11 Jan 2011 19:12:15 +0000 Subject: [PATCH] -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 --- xCAT-server/share/xcat/scripts/genula.sh | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 xCAT-server/share/xcat/scripts/genula.sh diff --git a/xCAT-server/share/xcat/scripts/genula.sh b/xCAT-server/share/xcat/scripts/genula.sh new file mode 100644 index 000000000..74103ab57 --- /dev/null +++ b/xCAT-server/share/xcat/scripts/genula.sh @@ -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