summaryrefslogtreecommitdiffstats
path: root/sys/netgraph
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2015-08-17 13:52:59 -0300
committerRenato Botelho <renato@netgate.com>2015-08-17 13:52:59 -0300
commit161cf1089185cf4625d774bd21e18f0ef3e64a5e (patch)
treec9eed05ee226ab96ac1fd82158e8c6bafa5a9847 /sys/netgraph
parent35a2f523fc6fe145b5bf688338c41904f7d13a4b (diff)
downloadFreeBSD-src-161cf1089185cf4625d774bd21e18f0ef3e64a5e.zip
FreeBSD-src-161cf1089185cf4625d774bd21e18f0ef3e64a5e.tar.gz
Importing pfSense patch ng_iface.RELENG_10.diff
Diffstat (limited to 'sys/netgraph')
-rw-r--r--sys/netgraph/ng_iface.c58
-rw-r--r--sys/netgraph/ng_iface.h1
2 files changed, 59 insertions, 0 deletions
diff --git a/sys/netgraph/ng_iface.c b/sys/netgraph/ng_iface.c
index 6c18d2a..94c8c05c 100644
--- a/sys/netgraph/ng_iface.c
+++ b/sys/netgraph/ng_iface.c
@@ -70,9 +70,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/bpf.h>
#include <net/netisr.h>
#include <net/route.h>
@@ -166,6 +168,13 @@ static const struct ng_cmdlist ng_iface_cmds[] = {
},
{
NGM_IFACE_COOKIE,
+ NGM_IFACE_SET_IFNAME,
+ "setifname",
+ &ng_parse_string_type,
+ NULL
+ },
+ {
+ NGM_IFACE_COOKIE,
NGM_IFACE_POINT2POINT,
"point2point",
NULL,
@@ -608,6 +617,10 @@ ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook)
struct ng_mesg *resp = NULL;
int error = 0;
struct ng_mesg *msg;
+ char *new_name;
+ size_t namelen, onamelen;
+ struct sockaddr_dl *sdl = NULL;
+ struct ifaddr *ifa = NULL;
NGI_GET_MSG(item, msg);
switch (msg->header.typecookie) {
@@ -622,6 +635,49 @@ ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook)
strlcpy(resp->data, ifp->if_xname, IFNAMSIZ);
break;
+ case NGM_IFACE_SET_IFNAME:
+
+ new_name = (char *)msg->data;
+ /* Announce the departure of the interface. */
+ //new_name[strlen(new_name)] = '\0';
+
+ /* Deny request if interface is UP */
+ if ((ifp->if_flags & IFF_UP) != 0) {
+ error = EBUSY;
+ break;
+ }
+
+ //rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
+ EVENTHANDLER_INVOKE(ifnet_departure_event, ifp);
+
+ strlcpy(ifp->if_xname, new_name, sizeof(ifp->if_xname));
+ ifa = ifp->if_addr;
+ IFA_LOCK(ifa);
+ sdl = (struct sockaddr_dl *)ifa->ifa_addr;
+ namelen = strlen(new_name) + 1;
+ onamelen = sdl->sdl_nlen;
+ /*
+ * Move the address if needed. This is safe because we
+ * allocate space for a name of length IFNAMSIZ when we
+ * create this in if_attach().
+ */
+ if (namelen != onamelen) {
+ bcopy(sdl->sdl_data + onamelen,
+ sdl->sdl_data + namelen, sdl->sdl_alen);
+ }
+ bcopy(new_name, sdl->sdl_data, namelen);
+ sdl->sdl_nlen = namelen;
+ sdl = (struct sockaddr_dl *)ifa->ifa_netmask;
+ bzero(sdl->sdl_data, onamelen);
+ while (namelen != 0)
+ sdl->sdl_data[--namelen] = 0xff;
+ IFA_UNLOCK(ifa);
+
+ EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp);
+ /* Announce the return of the interface. */
+ //rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
+ break;
+
case NGM_IFACE_POINT2POINT:
case NGM_IFACE_BROADCAST:
{
@@ -699,9 +755,11 @@ ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook)
switch (msg->header.cmd) {
case NGM_LINK_IS_UP:
ifp->if_drv_flags |= IFF_DRV_RUNNING;
+ //if_link_state_change(ifp, LINK_STATE_UP);
break;
case NGM_LINK_IS_DOWN:
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+ //if_link_state_change(ifp, LINK_STATE_DOWN);
break;
default:
break;
diff --git a/sys/netgraph/ng_iface.h b/sys/netgraph/ng_iface.h
index 58fb442..3c843c4 100644
--- a/sys/netgraph/ng_iface.h
+++ b/sys/netgraph/ng_iface.h
@@ -70,6 +70,7 @@ enum {
NGM_IFACE_POINT2POINT,
NGM_IFACE_BROADCAST,
NGM_IFACE_GET_IFINDEX,
+ NGM_IFACE_SET_IFNAME,
};
#define MTAG_NGIF NGM_IFACE_COOKIE
OpenPOWER on IntegriCloud