Date: Sat, 5 May 2001 19:11:18 +0400 (MSD) From: "Vladimir B. Grebenschikov" <vova@express.ru> To: freebsd-net@freebsd.org Subject: netgraph interface names Message-ID: <15092.6166.422647.927779@vbook.express.ru>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
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.c.orig Sat May 5 12:38:26 2001
+++ sys/netgraph/ng_iface.c Sat May 5 17:31:26 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,
@@ -641,6 +650,57 @@
arg = (struct ng_iface_ifname *)resp->data;
snprintf(arg->ngif_name, sizeof(arg->ngif_name),
"%s%d", ifp->if_name, ifp->if_unit);
+ break;
+ }
+
+ case NGM_IFACE_SET_IFNAME:
+ {
+ struct ng_iface_ifname *arg =
+ (struct ng_iface_ifname *)msg->data;
+ char *str;
+ int unit;
+ int s;
+ struct ifnet * ifpr = NULL;
+
+ /* Deny request if interface is UP */
+ if ((ifp->if_flags & IFF_UP) != 0) {
+ error = EBUSY;
+ break;
+ }
+
+
+ for (str = arg->ngif_name + strlen(arg->ngif_name) - 1;
+ (str > arg->ngif_name) && isdigit(*str); str--);
+
+ if (str == arg->ngif_name) {
+ error = EINVAL;
+ break;
+ }
+
+ str++;
+ 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) && (ifpr->if_unit == unit)) {
+ error = EEXIST;
+ break;
+ }
+
+ splx(s);
+ if (error) break;
+
+ 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;
}
--- 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 {
[-- Attachment #3 --]
--- sys/netgraph/ng_base.c.orig Sat May 5 18:00:19 2001
+++ sys/netgraph/ng_base.c Sat May 5 18:04:14 2001
@@ -541,10 +541,10 @@
return (EINVAL);
}
- /* Check the node isn't already named */
+ /* Check the node isn't already named, free memory */
if (node->name != NULL) {
- TRAP_ERROR;
- return (EISCONN);
+ FREE(node->name, M_NETGRAPH);
+ node->name = NULL;
}
/* Check the name isn't already being used */
[-- Attachment #4 --]
--
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?15092.6166.422647.927779>
