Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 7b7195ca544de00c65ea0a36d76a2162810e7e9b @danielrobbins danielrobbins committed Apr 8, 2010
Showing with 400 additions and 0 deletions.
  1. +15 −0 conf.d/netif.eth0
  2. +56 −0 future/dualie.py
  3. +25 −0 future/interface
  4. +14 −0 future/netif.eth0
  5. +17 −0 init.d/netif.lo.in
  6. +68 −0 init.d/netif.tmpl.in
  7. +28 −0 netif.d/bond
  8. +38 −0 netif.d/bridge
  9. +29 −0 netif.d/bridge-noip
  10. +51 −0 netif.d/common.sh
  11. +21 −0 netif.d/interface
  12. +15 −0 netif.d/interface-noip
  13. +23 −0 netif.d/simple.sh
@@ -0,0 +1,15 @@
+template="interface"
+description="my public interface"
+
+# lower-case better name support:
+# multiple ip address support:
+# should we change this var to "ipaddrs"?
+
+ipaddr="207.66.127.100/24 207.66.127.101/24"
+
+# gateway can be "default" or a specified gw for this interface:
+gateway=default
+
+# "nameservers" variable:
+domain=funtoo.org
+nameservers="129.120.200.1 129.120.200.2"
@@ -0,0 +1,56 @@
+#!/usr/bin/python2.6
+
+import re
+
+class StopCommand(object):
+ def __init__(self,start_pat, stop_pat, stop_pos):
+ self.start_pat = start_pat
+ self.stop_pat = stop_pat
+ self.stop_pos = stop_pos
+
+ def expand(self,groups):
+ mygroups = []
+ for pos in self.stop_pos:
+ mygroups.append(groups[pos])
+ return self.stop_pat % tuple(mygroups)
+
+
+class Application(object):
+
+ def __init__(self,handlers):
+ self.handlers = []
+ self.add_handlers(handlers)
+ self.negate = []
+
+ def add_handlers(self,handlers):
+ for regex, handler, stop in handlers:
+ stopcmd, stoppos = stop
+ if regex[-1] != "$":
+ regex += "$"
+ self.handlers.append((re.compile(regex),handler(regex, stopcmd, stoppos)))
+
+ def process(self,lines):
+ for line in lines:
+ for regex, handler in self.handlers:
+ match = regex.match(line)
+ if match:
+ self.negate = [ handler.expand(match.groups()) ] + self.negate
+ break
+
+app = Application([
+ (r"brctl addbr (.*)", StopCommand, ("brctl delbr %s",[0]) ),
+ (r"ip link set (.*) up", StopCommand, ("ip link set %s down",[0])),
+ (r"ip route add (.*)", StopCommand, ("ip route del %s",[0])),
+ (r"resolvconf -a (.*)", StopCommand, ("resolvconf -d %s",[0])),
+ (r"echo 1 > (/proc/sys/net.*)", StopCommand, ("echo 0 > %s",[0])),
+ (r"echo 0 > (/proc/sys/net.*)", StopCommand, ("echo 1 > %s",[0])),
+ (r"iptables -N (.*)", StopCommand, ("iptables -F %s",[0])), # need to add -X
+ (r"iptables -P (.*) DROP", StopCommand, ("iptables -P %s ACCEPT",[0])),
+ (r"ifconfig (.*) (.*) netmask (.*) up", StopCommand, ("ifconfig %s down",[0])),
+])
+
+
+app.process(["hi", "ifconfig eth0 207.66.127.100 netmask 255.255.255.0 up", "ip link set eth0 up", "resolvconf -a eth0", "ip route add default foo bar", "echo 1 > /proc/sys/net/ipv4/ip_forward"])
+print
+for line in app.negate:
+ print line
@@ -0,0 +1,25 @@
+int {
+ : eth0
+ ipaddr 207.66.127.100/24
+ domain funtoo.org
+ nameservers 129.121.254.1 129.121.254.2
+ gateway default
+}
+
+start [
+ ip link set $[int] up
+ {% for ipaddr in int.ipaddr %}
+ ip addr add $[int.ipaddr] dev $[int]
+ {% end %}
+ {% if int.gateway == "default" %}
+ ip route add default dev $[int]
+ {% end %}
+ resolvconf -a $[<<resolvconf.expand()]
+]
+
+resolvconf [
+ domain $[int.domain?]
+ {% for ns in int.nameservers %}
+ nameserver $[ns]
+ {% end %}
+]
@@ -0,0 +1,14 @@
+info {
+ template: interface
+ description: LAN
+}
+
+interface {
+ ipaddr: 166.3.244.231/24
+ nameservers: 166.3.68.1
+ domain: fs.fed.us
+}
+
+route {
+ default: 166.244.254
+}
@@ -0,0 +1,17 @@
+#!/sbin/runscript
+# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
+# All rights reserved. Released under the 2-clause BSD license.
+
+start() {
+ ebegin "Bringing up network interface lo"
+ ifconfig lo 127.0.0.1 netmask 255.0.0.0 up && \
+ route add -net 127.0.0.0 netmask 255.0.0.0 dev lo
+ eend $?
+}
+
+stop() {
+ ebegin "Shutting down network interface lo"
+ route del -net 127.0.0.0 netmask 255.0.0.0 dev lo &&
+ ifconfig lo down
+ eend $?
+}
@@ -0,0 +1,68 @@
+#!/sbin/runscript
+# Copyright (c) 2007-2009 Funtoo Technologies
+# All rights reserved. Released under the 2-clause BSD license.
+
+# TODO - generate cached templates for /etc/init.d/foo, use them for starting and stopping
+# rather than running "live" commands. This way "stop" will work correctly.
+
+INT=${RC_SVCNAME##*.}
+interface=${interface:-INT}
+
+[ "$interface" = "tmpl" ] && exit 0
+
+[ -z "$template" ] && \\
+ eerror "Please specify a template (template=) for $RC_SVCNAME in /etc/conf.d/$interface" && \\
+ exit 1
+
+BLUE=""
+CYAN=""
+CYANN=""
+GREEN=""
+RED=""
+PURP=""
+YEL=""
+BOLD=""
+OFF=""
+
+cachedir="/var/cache/netif.d/$interface/"
+install -d -m0755 "$cachedir"
+
+CONFD="/etc/conf.d/$RC_SVCNAME"
+
+if [ -n "$description" ]
+then
+ DESC1="$interface${OFF}"
+ DESC2="${CYAN}${description}${OFF}"
+else
+ DESC1="$interface${OFF}"
+ DESC2="${CYANN}${template}${OFF}"
+fi
+STARTD="Interface $DESC1 ${GREEN}up${OFF} - $DESC2"
+STOPD="Interface $DESC1 ${RED}down${OFF} - $DESC2"
+TPATH="/etc/netif.d/$template"
+
+require() {
+ local missing=""
+ for envname in $*
+ do
+ [ -z "${!envname}" ] && missing="$missing $envname"
+ done
+ if [ -n "$missing" ]
+ then
+ echo
+ eerror "ERROR: Required variable(s) are missing from ${CYAN}$CONFD${OFF}:"
+ eerror ""
+ for miss in $missing
+ do
+ eerror " ${CYAN}$miss${OFF}"
+ done
+ eerror ""
+ eerror "Please correct ${CYAN}$CONFD${OFF} to address this issue."
+ echo
+ exit 1
+ fi
+}
+
+. /etc/netif.d/common.sh
+. $TPATH
+
@@ -0,0 +1,28 @@
+
+depend() {
+ config "$CONFD"
+ need $SLAVES
+}
+
+start() {
+ ebegin "$STARTD"
+ require SLAVES
+ ifconfig $INT 0.0.0.0 up
+ if [ -n "$MTU" ]
+ then
+ ifconfig $INT mtu $MTU
+ for SLAVE in ${SLAVES//netif./}
+ do
+ ifconfig $SLAVE mtu $MTU || eend $?
+ done
+ fi
+ ifenslave $INT ${SLAVES//netif./}
+ eend $?
+}
+
+stop() {
+ ebegin "$STOPD"
+ ifenslave -d $INT ${SLAVES//netif./} &&
+ ifconfig $INT down
+ eend $?
+}
@@ -0,0 +1,38 @@
+#!/sbin/runscript
+
+depend() {
+ config "$CONFD"
+ [ -n "$slaves" ] && need $slaves
+}
+
+start() {
+ local SLAVE
+ ebegin "$STARTD"
+
+ # 1. CREATE BRIDGE, ADD SLAVE DEVICES, set FORWARDING DELAY TO 0
+ brctl addbr $interface || die "Couldn't create bridge $interface"
+ if [ -n "$slaves" ]
+ then
+ for slave in ${slaves//netif./}
+ do
+ brctl addif $interface $slave || die "Couldn't add slave $slave to bridge $interface"
+ done
+ fi
+ brctl setfd $interface 0 || die "Couldn't set forwarding delay to zero on bridge $interface"
+
+ # 2. CONFIGURE INTERFACE
+ ip link set $interface up || die "Couldn't bring $interface up"
+ [ -n "$mtu" ] && { ip link set dev $interface mtu $mtu || die "Couldn't set MTU on $interface to $mtu"; }
+ ezroute add
+ ezresolv add
+ eend 0
+}
+
+stop() {
+ ebegin "$STOPD"
+ ezresolv del
+ ezroute del
+ ip link set $interface down || die "Couldn't bring $interface down"
+ brctl delbr $interface
+ eend 0
+}
@@ -0,0 +1,29 @@
+#!/sbin/runscript
+
+depend() {
+ config "$CONFD"
+ [ -n "$SLAVES" ] && need $SLAVES
+}
+
+start() {
+ local SLAVE
+ ebegin "$STARTD"
+ brctl addbr $INT
+ if [ -n "$SLAVES" ]
+ then
+ for SLAVE in ${SLAVES//netif./}
+ do
+ brctl addif $INT ${SLAVE}
+ done
+ fi
+ brctl setfd $INT 0 && \
+ ifconfig $INT up && \
+ eend $?
+}
+
+stop() {
+ ebegin "$STOPD"
+ ifconfig $INT down && \
+ brctl delbr $INT
+ eend $?
+}
@@ -0,0 +1,51 @@
+#!/sbin/runscript
+
+domain=${domain:-DOM}
+nameservers=${nameservers}
+ipaddrs=${ipaddrs:-IP}
+netmask=${netmask:-NM}
+slaves=${slaves:-SLAVES}
+mtu=${mtu:-MTU}
+
+depend() {
+ config "$CONFD"
+}
+
+die() {
+ eend 1 "$*"; exit 1
+}
+
+ezdns() {
+ # This function generates a resolv.conf entry, which ezresolv() passes to resolvconf
+ [ -n "$domain" ] && echo "domain $domain"
+ for ns in $nameservers
+ do
+ echo "nameserver $ns"
+ done
+}
+
+ezresolv() {
+ # This function calls resolvconf (openresolv) with the correct resolv.conf passed as a here-file
+ [ -z "`ezdns`" ] && return
+ if [ "$1" = "add" ]; then
+ resolvconf -a $interface << EOF || die "Problem adding DNS info for $interface"
+`ezdns`
+EOF
+ else
+ resolvconf -d $interface
+ fi
+}
+
+ezroute() {
+ if [ "$gateway" = "default" ]
+ then
+ qipr $1 default dev $interface
+ elif [ -n "$gateway" ]
+ qipr $1 $gateway dev $interface
+ fi
+}
+
+qipr() {
+ ip route $*
+ [ "$1" = "add" ] && [ $? -ne 0 ] && die "Couldn't set route: $*"
+}
@@ -0,0 +1,21 @@
+#!/sbin/runscript
+
+start() {
+ ebegin "$STARTD"
+ ip link set $interface up || die "Couldn't bring $interface up"
+ for ipnm in $ipaddrs
+ do
+ ip addr add $ipnm dev $interface || die "Couldn't add $ipnm to $interface"
+ done
+ ezroute add; ezresolv add
+ eend $?
+}
+
+stop() {
+ ebegin "$STOPD"
+ ezresolv del
+ ezroute del
+ ip link set $interface down || die "Couldn't bring $INT down"
+ brctl delbr $interface
+ eend 0
+}
@@ -0,0 +1,15 @@
+depend() {
+ config "$CONFD"
+}
+
+start() {
+ ebegin "$STARTD"
+ ifconfig $INT 0.0.0.0 up
+ eend $?
+}
+
+stop() {
+ ebegin "$STOPD"
+ ifconfig $INT down
+ eend $?
+}
Oops, something went wrong.

0 comments on commit 7b7195c

Please sign in to comment.