From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/openrc:master commit in: net/
Date: Thu, 9 Feb 2012 09:40:07 +0000 (UTC) [thread overview]
Message-ID: <659f7c2bc82c43088fd4a479d8fee849fe89141e.robbat2@gentoo> (raw)
commit: 659f7c2bc82c43088fd4a479d8fee849fe89141e
Author: Salah Coronya <salah.coronya <AT> gmail <DOT> com>
AuthorDate: Thu Feb 9 09:39:40 2012 +0000
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Thu Feb 9 09:39:40 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=659f7c2b
oldnet: ip6rd support
X-Gentoo-Bug: 392223
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=392223
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
---
net/ip6rd.sh | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 168 insertions(+), 0 deletions(-)
diff --git a/net/ip6rd.sh b/net/ip6rd.sh
new file mode 100644
index 0000000..9da0576
--- /dev/null
+++ b/net/ip6rd.sh
@@ -0,0 +1,168 @@
+# Copyright (c) 2011 by Gentoo Foundation
+# Released under the 2-clause BSD license.
+
+_config_vars="$_config_vars link prefix suffix ipv4mask relay"
+
+ip6rd_depend()
+{
+ program ip
+ after interface
+}
+
+ip6rd_pre_start()
+{
+ # ALL interfaces run pre_start blocks, not just those with something
+ # assigned, so we must check if we need to run on this interface before we
+ # do so.
+ local config
+ eval config=\$config_${IFVAR}
+ [ "$config" = "ip6rd" ] || return 0
+
+ case "${MODULES}" in
+ *" ifconfig "*)
+ eerror "ifconfig is not supported for 6rd"
+ eerror "Please emerge sys-apps/iproute2"
+ return 1
+ ;;
+ esac
+
+ local host= suffix= relay= addr= iface=${IFACE} config_ip6rd= localip= ipv4mask=
+ eval host=\$link_${IFVAR}
+ if [ -z "${host}" ]; then
+ eerror "link_${IFVAR} not set"
+ return 1
+ fi
+
+ eval host=\${link_${IFVAR}}
+ eval ipv4mask=\${ipv4mask_${IFVAR}:-0}
+ eval suffix=\${suffix_${IFVAR}:-1}
+ eval relay=\${relay_${IFVAR}}
+ eval prefix=\${prefix_${IFVAR}}
+
+ IFACE=${host}
+ addrs=$(_get_inet_addresses)
+ IFACE=${iface}
+ if [ -z "${addrs}" ]; then
+ eerror "${host} is not configured with an IPv4 address"
+ return 1
+ fi
+ # TODO: Get this settings from DHCP (Option 212)
+ if [ -z "${prefix}" ]; then
+ eerror "prefix_${IFVAR} not set"
+ return 1
+ fi
+ if [ -z "${relay}" ]; then
+ eerror "relay_${IFVAR} not set"
+ return 1
+ fi
+ for addr in ${addrs}; do
+ # Strip the subnet
+ local ip="${addr%/*}" subnet="${addr#*/}"
+ # We don't work on private IPv4 addresses
+ if _ip6rd_inet_is_private_network "${ip}"
+ then
+ continue
+ fi
+
+ local ip6= ip6_prefix="${prefix%::/*}" ip6_subnet="${prefix#*/}"
+ ip6_subnet=$((ip6_subnet + (32-ipv4mask)))
+ eval ip6="$(printf "${ip6_prefix}:%s::%s" \
+ $(_ip6rd_prefix_shave_bits ${ip} ${ipv4mask}) ${suffix})"
+ veinfo "Derived IPv6 address: ${ip6}"
+
+ # Now apply our IPv6 address to our config
+ config_ip6rd="${config_ip6rd}${config_ip6rd:+ }${ip6}/${ip6_subnet}"
+
+ if [ -n "${localip}" ]; then
+ localip="any"
+ else
+ localip="${ip}"
+ fi
+ done
+
+ if [ -z "${config_ip6rd}" ]; then
+ eerror "No global IPv4 addresses found on interface ${host}"
+ return 1
+ fi
+
+ ebegin "Creating 6rd tunnel ${IFACE}"
+ if [ "${IFACE}" != "sit0" ]; then
+ _tunnel add "${IFACE}" mode sit ttl 255 remote any local "${localip}"
+ fi
+ _tunnel 6rd dev "${IFACE}" 6rd-prefix "${prefix}"
+ eend $? || return 1
+ _up
+
+ routes_ip6rd="2003::/3 via ::${relay} metric 2147483647"
+ service_set_value "config_ip6rd_$IFVAR" "$config_ip6rd"
+ service_set_value "routes_ip6rd_$IFVAR" "$routes_ip6rd"
+}
+
+ip6rd_start()
+{
+ local config_ip6rd=$(service_get_value "config_ip6rd_$IFVAR")
+ local routes_ip6rd=$(service_get_value "routes_ip6rd_$IFVAR")
+
+ # Now apply our config
+ eval config_${config_index}=\'"${config_ip6rd}"\'
+ : $(( config_index -= 1 ))
+
+ # Add a route for us, ensuring we don't delete anything else
+ local routes="$(_get_array "routes_${IFVAR}")
+$routes_ip6rd"
+ eval routes_${IFVAR}=\$routes
+}
+
+_ip6rd_inet_atoi()
+{
+ local IFS="${IFS}." ipi=0 j=3
+ for i in $1 ; do
+ ipi=$(( ipi | i << 8*j-- ))
+ done
+ echo ${ipi}
+}
+
+_ip6rd_inet_itoa()
+{
+ local ipi=$1
+ for i in 0 1 2 3; do
+ if [ $i != 3 ] ; then
+ printf "%d." $(( (ipi & ~((1<<24)-1)) >> 24 ))
+ ipi=$(( (ipi & ((1<<24)-1)) << 8))
+ else
+ printf "%d\n" $(( (ipi & ~((1<<24)-1)) >> 24 ))
+ fi
+ done
+}
+
+_ip6rd_inet_get_network()
+{
+ echo $(_ip6rd_inet_itoa $(( ($(_ip6rd_inet_atoi $1) & ((1<<$2)-1) << (32-$2) ) )) )
+}
+
+_ip6rd_inet_is_private_network()
+{
+ if [ "$(_ip6rd_inet_get_network $1 16)" = "192.168.0.0" ]\
+ || [ "$(_ip6rd_inet_get_network $1 8)" = "10.0.0.0" ]\
+ || [ "$(_ip6rd_inet_get_network $1 12)" = "172.16.0.0" ]\
+ || [ "$(_ip6rd_inet_get_network $1 16)" = "169.254.0.0" ]
+ then
+ return 0;
+ fi
+ return 1;
+}
+
+_ip6rd_prefix_shave_bits()
+{
+ local ipi=
+ ipi=$(( ($(_ip6rd_inet_atoi $1) & (1<<(32-$2))-1) << $2))
+ if [ $2 -le 16 ]
+ then
+ printf "%04x:%0$(( (16-$2>>2)+(($2%4)?1:0) ))x" \
+ $((ipi >> 16)) $((ipi & (1<<(16-$2))-1))
+ elif [ $2 -lt 32 ]
+ then
+ printf "%0$(( (32-$2>>2)+(($2%4)?1:0) ))x" \
+ $((ipi >> 16))
+ fi
+}
next reply other threads:[~2012-02-09 9:40 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-09 9:40 Robin H. Johnson [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-02-17 21:39 [gentoo-commits] proj/openrc:master commit in: net/ William Hubbs
2012-12-21 22:45 William Hubbs
2012-12-20 21:28 Robin H. Johnson
2012-11-10 20:58 William Hubbs
2012-11-07 1:45 Robin H. Johnson
2012-11-07 1:45 Robin H. Johnson
2012-11-06 23:23 Robin H. Johnson
2012-11-06 23:19 Robin H. Johnson
2012-11-06 23:19 Robin H. Johnson
2012-10-17 18:51 William Hubbs
2012-10-11 3:57 Robin H. Johnson
2012-10-11 3:57 Robin H. Johnson
2012-10-10 0:11 Robin H. Johnson
2012-09-07 19:57 William Hubbs
2012-07-04 14:20 William Hubbs
2012-06-07 5:36 William Hubbs
2012-05-03 20:43 Robin H. Johnson
2012-04-24 3:32 Christian Ruppert
2012-04-03 21:31 Robin H. Johnson
2012-04-02 4:28 William Hubbs
2012-03-11 19:55 Robin H. Johnson
2012-03-02 19:55 Robin H. Johnson
2012-02-09 9:43 Robin H. Johnson
2012-01-25 18:47 Robin H. Johnson
2012-01-16 17:33 Robin H. Johnson
2012-01-13 4:39 Robin H. Johnson
2012-01-07 21:56 William Hubbs
2012-01-07 21:56 William Hubbs
2012-01-06 21:08 William Hubbs
2012-01-04 21:38 Mike Frysinger
2011-12-30 1:22 William Hubbs
2011-12-30 0:11 William Hubbs
2011-12-28 20:32 Robin H. Johnson
2011-12-27 2:01 Robin H. Johnson
2011-12-27 1:51 Robin H. Johnson
2011-12-27 1:24 Robin H. Johnson
2011-12-27 1:09 Robin H. Johnson
2011-12-21 8:11 Robin H. Johnson
2011-12-21 8:11 Robin H. Johnson
2011-12-21 8:11 Robin H. Johnson
2011-12-13 8:43 Robin H. Johnson
2011-12-13 6:53 Robin H. Johnson
2011-12-13 6:38 William Hubbs
2011-12-13 3:20 Robin H. Johnson
2011-12-13 3:20 Robin H. Johnson
2011-12-10 4:12 William Hubbs
2011-12-10 2:59 William Hubbs
2011-11-23 14:26 William Hubbs
2011-11-22 15:14 William Hubbs
2011-10-07 21:47 Robin H. Johnson
2011-09-21 11:29 Christian Ruppert
2011-09-21 1:58 Christian Ruppert
2011-09-18 22:04 Christian Ruppert
2011-09-18 12:45 Christian Ruppert
2011-09-16 23:14 Christian Ruppert
2011-09-16 22:18 Christian Ruppert
2011-09-16 21:48 Christian Ruppert
2011-07-18 23:57 Robin H. Johnson
2011-06-28 4:08 Mike Frysinger
2011-05-16 19:58 William Hubbs
2011-05-16 13:23 Anthony G. Basile
2011-05-16 5:22 Mike Frysinger
2011-04-07 12:51 William Hubbs
2011-03-27 20:46 William Hubbs
2011-03-18 18:25 Mike Frysinger
2011-02-21 9:56 Robin H. Johnson
2011-02-12 19:37 William Hubbs
2011-02-05 13:28 William Hubbs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=659f7c2bc82c43088fd4a479d8fee849fe89141e.robbat2@gentoo \
--to=robbat2@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox