1
|
diff --git a/sys/netgraph/ng_iface.c b/sys/netgraph/ng_iface.c
|
2
|
index e495f8a..8d80bc3 100644
|
3
|
--- a/sys/netgraph/ng_iface.c
|
4
|
+++ b/sys/netgraph/ng_iface.c
|
5
|
@@ -70,9 +70,11 @@
|
6
|
#include <sys/socket.h>
|
7
|
#include <sys/syslog.h>
|
8
|
#include <sys/libkern.h>
|
9
|
+#include <sys/ctype.h>
|
10
|
|
11
|
#include <net/if.h>
|
12
|
#include <net/if_types.h>
|
13
|
+#include <net/if_dl.h>
|
14
|
#include <net/bpf.h>
|
15
|
#include <net/netisr.h>
|
16
|
#include <net/route.h>
|
17
|
@@ -166,6 +168,13 @@ static const struct ng_cmdlist ng_iface_cmds[] = {
|
18
|
},
|
19
|
{
|
20
|
NGM_IFACE_COOKIE,
|
21
|
+ NGM_IFACE_SET_IFNAME,
|
22
|
+ "setifname",
|
23
|
+ &ng_parse_string_type,
|
24
|
+ NULL
|
25
|
+ },
|
26
|
+ {
|
27
|
+ NGM_IFACE_COOKIE,
|
28
|
NGM_IFACE_POINT2POINT,
|
29
|
"point2point",
|
30
|
NULL,
|
31
|
@@ -608,6 +617,10 @@ ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
32
|
struct ng_mesg *resp = NULL;
|
33
|
int error = 0;
|
34
|
struct ng_mesg *msg;
|
35
|
+ char *new_name;
|
36
|
+ size_t namelen, onamelen;
|
37
|
+ struct sockaddr_dl *sdl = NULL;
|
38
|
+ struct ifaddr *ifa = NULL;
|
39
|
|
40
|
NGI_GET_MSG(item, msg);
|
41
|
switch (msg->header.typecookie) {
|
42
|
@@ -622,6 +635,49 @@ ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
43
|
strlcpy(resp->data, ifp->if_xname, IFNAMSIZ);
|
44
|
break;
|
45
|
|
46
|
+ case NGM_IFACE_SET_IFNAME:
|
47
|
+
|
48
|
+ new_name = (char *)msg->data;
|
49
|
+ /* Announce the departure of the interface. */
|
50
|
+ //new_name[strlen(new_name)] = '\0';
|
51
|
+
|
52
|
+ /* Deny request if interface is UP */
|
53
|
+ if ((ifp->if_flags & IFF_UP) != 0) {
|
54
|
+ error = EBUSY;
|
55
|
+ break;
|
56
|
+ }
|
57
|
+
|
58
|
+ //rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
|
59
|
+ EVENTHANDLER_INVOKE(ifnet_departure_event, ifp);
|
60
|
+
|
61
|
+ strlcpy(ifp->if_xname, new_name, sizeof(ifp->if_xname));
|
62
|
+ ifa = ifp->if_addr;
|
63
|
+ IFA_LOCK(ifa);
|
64
|
+ sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
65
|
+ namelen = strlen(new_name) + 1;
|
66
|
+ onamelen = sdl->sdl_nlen;
|
67
|
+ /*
|
68
|
+ * Move the address if needed. This is safe because we
|
69
|
+ * allocate space for a name of length IFNAMSIZ when we
|
70
|
+ * create this in if_attach().
|
71
|
+ */
|
72
|
+ if (namelen != onamelen) {
|
73
|
+ bcopy(sdl->sdl_data + onamelen,
|
74
|
+ sdl->sdl_data + namelen, sdl->sdl_alen);
|
75
|
+ }
|
76
|
+ bcopy(new_name, sdl->sdl_data, namelen);
|
77
|
+ sdl->sdl_nlen = namelen;
|
78
|
+ sdl = (struct sockaddr_dl *)ifa->ifa_netmask;
|
79
|
+ bzero(sdl->sdl_data, onamelen);
|
80
|
+ while (namelen != 0)
|
81
|
+ sdl->sdl_data[--namelen] = 0xff;
|
82
|
+ IFA_UNLOCK(ifa);
|
83
|
+
|
84
|
+ EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp);
|
85
|
+ /* Announce the return of the interface. */
|
86
|
+ //rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
|
87
|
+ break;
|
88
|
+
|
89
|
case NGM_IFACE_POINT2POINT:
|
90
|
case NGM_IFACE_BROADCAST:
|
91
|
{
|
92
|
@@ -699,9 +755,11 @@ ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
93
|
switch (msg->header.cmd) {
|
94
|
case NGM_LINK_IS_UP:
|
95
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
96
|
+ if_link_state_change(ifp, LINK_STATE_UP);
|
97
|
break;
|
98
|
case NGM_LINK_IS_DOWN:
|
99
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
100
|
+ if_link_state_change(ifp, LINK_STATE_DOWN);
|
101
|
break;
|
102
|
default:
|
103
|
break;
|
104
|
diff --git a/sys/netgraph/ng_iface.h b/sys/netgraph/ng_iface.h
|
105
|
index a78d8cb..fd4b751 100644
|
106
|
--- a/sys/netgraph/ng_iface.h
|
107
|
+++ b/sys/netgraph/ng_iface.h
|
108
|
@@ -70,6 +70,7 @@ enum {
|
109
|
NGM_IFACE_POINT2POINT,
|
110
|
NGM_IFACE_BROADCAST,
|
111
|
NGM_IFACE_GET_IFINDEX,
|
112
|
+ NGM_IFACE_SET_IFNAME,
|
113
|
};
|
114
|
|
115
|
#define MTAG_NGIF NGM_IFACE_COOKIE
|