Date: Tue, 8 May 2001 09:49:47 +0400 (MSD) From: "Vladimir B. Grebenschikov" <vova@express.ru> To: Julian Elischer <julian@elischer.org> Cc: "Vladimir B. Grebenschikov" <vova@express.ru>, freebsd-net@FreeBSD.ORG Subject: Re: netgraph interface names Message-ID: <15095.35067.813462.898426@vbook.express.ru> In-Reply-To: <3AF6E39A.A7447268@elischer.org> References: <15092.6166.422647.927779@vbook.express.ru> <3AF6E39A.A7447268@elischer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Julian Elischer writes:
> I was thinking of doing this..
>
> but slightly differnt....
> renaming the node would change the interface name too.
> but what you have would work as well.
Only problem it is no hook between node renaming code in ng_base.c and
interface allocation code in ng_iface.c
below more extended patch, that supports allocation first free
interface with name "ifname#".
> "Vladimir B. Grebenschikov" wrote:
> >
> > Tring to use netgraph system for some pruposes
> > (frame-relay/tunneling/sync) I found that it is too complicated to
> > follow naming schemes for different clients, and build firewall
> > tables And not very clean witch ngX for what.
> >
> > There two patches:
> >
> > first allow name netgraph network interface.
> >
> > # ngctl msg ng0: setifname \"sync0\"
> >
> > will name interace ng0 as sync0
> >
> > second patch allows rename already named netgraph node (I don't understand why
> > netgraph designers don't allow this)
> >
> > # ngctl name ng0: sync0
> >
> > so small script will easy create interface:
> >
> > mkif() {
> > name="$1"
> > ngname=`( echo "mkpeer iface dummy inet"; echo "msg .:dummy getifname" ) \
> > | ngctl -f - | perl -n -e '/Args:\s+\"(ng\d+)\"/ && print "$1\n";'`
> > if [ "$name" != "" ]; then
> > ngctl msg $ngname: setifname \"$name\"
> > ngctl name $ngname: $name
> > ngname=$name
> > fi
> > }
> >
> > # SYNC interfaces
> > mkif sync0
> > # some other netgraph stuff
> >
> > mkif sync1
> > ...
> > mkif sync2
> > ...
> >
> > # framerelay
> > mkif frm0
> > ...
> > mkif frm1
> > ...
> >
[-- Attachment #2 --]
--- sys/netgraph/ng_iface.h.orig Sat May 5 12:38:33 2001
+++ sys/netgraph/ng_iface.h Sat May 5 14:21:09 2001
@@ -70,6 +70,7 @@
NGM_IFACE_GET_IFNAME = 1, /* returns struct ng_iface_ifname */
NGM_IFACE_POINT2POINT,
NGM_IFACE_BROADCAST,
+ NGM_IFACE_SET_IFNAME, /* set interface name */
};
struct ng_iface_ifname {
--- sys/netgraph/ng_iface.c.orig Sat May 5 12:38:26 2001
+++ sys/netgraph/ng_iface.c Mon May 7 20:58:36 2001
@@ -62,9 +62,11 @@
#include <sys/socket.h>
#include <sys/syslog.h>
#include <sys/libkern.h>
+#include <sys/ctype.h>
#include <net/if.h>
#include <net/if_types.h>
+#include <net/if_dl.h>
#include <net/intrq.h>
#include <net/bpf.h>
@@ -157,6 +159,13 @@
},
{
NGM_IFACE_COOKIE,
+ NGM_IFACE_SET_IFNAME,
+ "setifname",
+ &ng_iface_ifname_type,
+ NULL
+ },
+ {
+ NGM_IFACE_COOKIE,
NGM_IFACE_POINT2POINT,
"point2point",
NULL,
@@ -644,6 +653,68 @@
break;
}
+ case NGM_IFACE_SET_IFNAME:
+ {
+ struct ng_iface_ifname *arg =
+ (struct ng_iface_ifname *)msg->data;
+ char *str;
+ int unit, maxunit = -1;
+ int s;
+ struct ifnet * ifpr = NULL;
+
+ /* Deny request if interface is UP */
+ if ((ifp->if_flags & IFF_UP) != 0) {
+ error = EBUSY;
+ break;
+ }
+
+ str = arg->ngif_name + strlen(arg->ngif_name) - 1;
+ if (*str == '#')
+ unit = -1; /* unit = -1 means first available unit */
+ else
+ for (;(str > arg->ngif_name) && isdigit(*str); str--);
+
+ if (str == arg->ngif_name) {
+ error = EINVAL;
+ break;
+ }
+
+ if (unit != -1)
+ unit = strtoul(++str, NULL, 10);
+
+ *str = '\0';
+
+ /* check for existing interface with same name */
+ s = splimp();
+ TAILQ_FOREACH(ifpr, &ifnet, if_link)
+ if (strcmp(ifpr->if_name, arg->ngif_name) == 0) {
+ if (unit == -1)
+ maxunit = (ifpr->if_unit > maxunit)?ifpr->if_unit:maxunit;
+ else
+ if (ifpr->if_unit == unit) {
+ error = EEXIST;
+ break;
+ }
+ }
+
+ splx(s);
+ if (error) break;
+
+ if (unit == -1)
+ unit = maxunit + 1;
+
+ MALLOC(ifp->if_name, char *, strlen(arg->ngif_name) + 1, M_NETGRAPH, M_NOWAIT);
+ s = splimp();
+ strcpy(ifp->if_name, arg->ngif_name);
+ ifp->if_unit = unit;
+ splx(s);
+
+ if_detach(ifp);
+ if_attach(ifp);
+
+ break;
+ }
+
case NGM_IFACE_POINT2POINT:
case NGM_IFACE_BROADCAST:
{
[-- Attachment #3 --]
> --
> __--_|\ Julian Elischer
> / \ julian@elischer.org
> ( OZ ) World tour 2000-2001
> ---> X_.---._/
--
TSB Russian Express, Moscow
Vladimir B. Grebenschikov, vova@express.ru
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?15095.35067.813462.898426>
