From owner-freebsd-rc@FreeBSD.ORG Wed Jan 11 19:18:23 2006 Return-Path: X-Original-To: freebsd-rc@freebsd.org Delivered-To: freebsd-rc@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A44C916A41F for ; Wed, 11 Jan 2006 19:18:23 +0000 (GMT) (envelope-from thompsa@freebsd.org) Received: from dbmail-mx2.orcon.net.nz (loadbalancer1.orcon.net.nz [219.88.242.3]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9A0C843D5C for ; Wed, 11 Jan 2006 19:18:16 +0000 (GMT) (envelope-from thompsa@freebsd.org) Received: from heff.fud.org.nz (60-234-149-201.bitstream.orcon.net.nz [60.234.149.201]) by dbmail-mx2.orcon.net.nz (8.13.2/8.13.2/Debian-1) with ESMTP id k0BJMxgN017917 for ; Thu, 12 Jan 2006 08:22:59 +1300 Received: by heff.fud.org.nz (Postfix, from userid 1001) id 273722843C; Thu, 12 Jan 2006 08:18:25 +1300 (NZDT) Date: Thu, 12 Jan 2006 08:18:25 +1300 From: Andrew Thompson To: freebsd-rc@freebsd.org Message-ID: <20060111191825.GA2332@heff.fud.org.nz> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="cWoXeonUoKmBZSoM" Content-Disposition: inline User-Agent: Mutt/1.5.11 X-Virus-Scanned: ClamAV version 0.87.1, clamav-milter version 0.87 on dbmail-mx2.orcon.net.nz X-Virus-Status: Clean Subject: review of rc.d/autobridge X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Jan 2006 19:18:23 -0000 --cWoXeonUoKmBZSoM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, I have a patch here that adds rc.d/autobridge. This is aimed towards apps like qemu or vmware that open a tap interface and need it bridged with the network adapter, the user can set up a glob for interfaces to be automatically added (eg tap*). Can I get the etc/* and rc.conf.5 changes reviewed for scripting style and general faux pas. regards, Andrew --cWoXeonUoKmBZSoM Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=autobridge Index: etc/devd.conf =================================================================== RCS file: /home/ncvs/src/etc/devd.conf,v retrieving revision 1.30 diff -u -p -r1.30 devd.conf --- etc/devd.conf 11 Dec 2005 00:18:28 -0000 1.30 +++ etc/devd.conf 11 Jan 2006 19:02:53 -0000 @@ -55,6 +55,16 @@ notify 0 { }; # +# Notify the autobridge script that a cloned interface has been created, +# physical interfaces are already handled by rc.d/netif. +# +notify 0 { + match "system" "IFNET"; + match "type" "CLONE_CREATE"; + action "/etc/rc.d/autobridge start $subsystem"; +}; + +# # Like Ethernet devices, but separate because # they have a different media type. We may want # to exploit this later. Index: etc/defaults/rc.conf =================================================================== RCS file: /home/ncvs/src/etc/defaults/rc.conf,v retrieving revision 1.269 diff -u -p -r1.269 rc.conf --- etc/defaults/rc.conf 20 Dec 2005 20:36:48 -0000 1.269 +++ etc/defaults/rc.conf 11 Jan 2006 18:45:58 -0000 @@ -163,6 +163,9 @@ ifconfig_lo0="inet 127.0.0.1" # default #ifconfig_fxp0_name="net0" # Change interface name from fxp0 to net0. #ipv4_addrs_fxp0="192.168.0.1/24 192.168.1.1-5/28" # example IPv4 address entry. # +#autobridge_interfaces="bridge0" # List of bridges to check +#autobridge_bridge0="tap* vlan0" # Interface glob to automatically add to the bridge +# # If you have any sppp(4) interfaces above, you might also want to set # the following parameters. Refer to spppcontrol(8) for their meaning. sppp_interfaces="" # List of sppp interfaces. Index: etc/rc.d/autobridge =================================================================== RCS file: etc/rc.d/autobridge diff -N etc/rc.d/autobridge --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ etc/rc.d/autobridge 11 Jan 2006 18:35:32 -0000 @@ -0,0 +1,70 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: autobridge +# REQUIRE: netif +# KEYWORD: nojail + +. /etc/rc.subr +. /etc/network.subr + +name="autobridge" +start_cmd="autobridge_start" +stop_cmd="autobridge_stop" +_cmd="" + +glob_int () { + case "$1" in + $2 ) true ;; + * ) false ;; + esac +} + +test_bridge () { + bridge=$1 + iface=$2 + + eval interfaces=\$autobridge_${bridge} + if [ -n "${interfaces}" ]; then + for i in ${interfaces}; do + if glob_int $iface $i ; then + ifconfig $bridge $_cmd $iface + fi + done + fi +} + +autobridge() +{ + if [ -n "${autobridge_interfaces}" ]; then + if [ -z "$_iflist" ]; then + # We're operating as a general network start routine. + _iflist="`list_net_interfaces`" + fi + + for br in ${autobridge_interfaces}; do + for i in $_iflist; do + test_bridge $br $i + done + done + fi +} + +autobridge_start() +{ + _cmd="addm" + autobridge +} + +autobridge_stop() +{ + _cmd="deletem" + autobridge +} + +_iflist=$2 + +load_rc_config $name +run_rc_command "$1" Index: etc/rc.d/netif =================================================================== RCS file: /home/ncvs/src/etc/rc.d/netif,v retrieving revision 1.18 diff -u -p -r1.18 netif --- etc/rc.d/netif 14 Nov 2005 23:34:50 -0000 1.18 +++ etc/rc.d/netif 6 Jan 2006 02:03:23 -0000 @@ -71,6 +71,9 @@ network_start() # Resync ipfilter /etc/rc.d/ipfilter resync fi + if [ -f /etc/rc.d/autobridge -a -n "$_cmdifn" ] ; then + /etc/rc.d/autobridge start $_cmdifn + fi } network_stop() Index: share/man/man5/rc.conf.5 =================================================================== RCS file: /home/ncvs/src/share/man/man5/rc.conf.5,v retrieving revision 1.278 diff -u -p -r1.278 rc.conf.5 --- share/man/man5/rc.conf.5 8 Jan 2006 13:20:57 -0000 1.278 +++ share/man/man5/rc.conf.5 11 Jan 2006 18:58:11 -0000 @@ -3395,6 +3395,23 @@ has been mounted. Both the .Xr md 4 device and the mount point will be changed. +.It Va autobridge_interfaces +.Pq Vt str +Set to the list of bridge interfaces that will have newly arriving interfaces +checked against to be automatically added. +If not set to +.Dq Li NO +then for each whitespace separated +.Ar element +in the value, a +.Va autobridge_ Ns Aq Ar element +variable is assumed to exist which has a whitespace separated list of interface +names to match, these names can use wildcards. +For example: +.Bd -literal +autobridge_interfaces="bridge0" +autobridge_bridge0="tap* dc0 dc[345]" +.Ed .El .Sh FILES .Bl -tag -width ".Pa /etc/defaults/rc.conf" -compact @@ -3411,6 +3428,7 @@ device and the mount point will be chang .Xr makewhatis 1 , .Xr vi 1 , .Xr vidcontrol 1 , +.Xr bridge 4 , .Xr ip 4 , .Xr ipf 4 , .Xr ipfw 4 , Index: sys/net/if_clone.c =================================================================== RCS file: /home/ncvs/src/sys/net/if_clone.c,v retrieving revision 1.9 diff -u -p -r1.9 if_clone.c --- sys/net/if_clone.c 24 Nov 2005 18:56:14 -0000 1.9 +++ sys/net/if_clone.c 11 Jan 2006 18:38:37 -0000 @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -161,6 +162,8 @@ if_clone_createif(struct if_clone *ifc, IF_CLONE_LOCK(ifc); IFC_IFLIST_INSERT(ifc, ifp); IF_CLONE_UNLOCK(ifc); + + devctl_notify("IFNET", ifp->if_xname, "CLONE_CREATE", NULL); } return (err); @@ -216,6 +219,8 @@ if_clone_destroyif(struct if_clone *ifc, IF_CLONE_LOCK(ifc); IFC_IFLIST_INSERT(ifc, ifp); IF_CLONE_UNLOCK(ifc); + + devctl_notify("IFNET", ifp->if_xname, "CLONE_DESTROY", NULL); } done: Index: sys/net/if_tap.c =================================================================== RCS file: /home/ncvs/src/sys/net/if_tap.c,v retrieving revision 1.58 diff -u -p -r1.58 if_tap.c --- sys/net/if_tap.c 11 Nov 2005 16:04:48 -0000 1.58 +++ sys/net/if_tap.c 11 Jan 2006 18:40:40 -0000 @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -398,6 +399,7 @@ tapopen(dev, flag, mode, td) splx(s); TAPDEBUG("%s is open. minor = %#x\n", ifp->if_xname, minor(dev)); + devctl_notify("IFNET", ifp->if_xname, "CLONE_CREATE", NULL); return (0); } /* tapopen */ @@ -454,6 +456,7 @@ tapclose(dev, foo, bar, td) TAPDEBUG("%s is closed. minor = %#x\n", ifp->if_xname, minor(dev)); + devctl_notify("IFNET", ifp->if_xname, "CLONE_DESTROY", NULL); return (0); } /* tapclose */ Index: sys/net/if_tun.c =================================================================== RCS file: /home/ncvs/src/sys/net/if_tun.c,v retrieving revision 1.154 diff -u -p -r1.154 if_tun.c --- sys/net/if_tun.c 9 Aug 2005 10:19:58 -0000 1.154 +++ sys/net/if_tun.c 11 Jan 2006 18:41:30 -0000 @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -324,6 +325,7 @@ tunopen(struct cdev *dev, int flag, int mtx_unlock(&tp->tun_mtx); ifp = TUN2IFP(tp); TUNDEBUG(ifp, "open\n"); + devctl_notify("IFNET", ifp->if_xname, "CLONE_CREATE", NULL); return (0); } @@ -377,6 +379,7 @@ tunclose(struct cdev *dev, int foo, int funsetown(&tp->tun_sigio); selwakeuppri(&tp->tun_rsel, PZERO + 1); TUNDEBUG (ifp, "closed\n"); + devctl_notify("IFNET", ifp->if_xname, "CLONE_DESTROY", NULL); return (0); } --cWoXeonUoKmBZSoM--