--- 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:
 		    {
