Projet

Général

Profil

Télécharger (3,56 ko) Statistiques
| Branche: | Révision:

univnautes-tools / patches / stable / 10 / ng_eiface.RELENG_10.diff @ 4ab3b90b

1
diff --git a/sys/netgraph/ng_eiface.c b/sys/netgraph/ng_eiface.c
2
index 0f471bb..679eaa0 100644
3
--- a/sys/netgraph/ng_eiface.c
4
+++ b/sys/netgraph/ng_eiface.c
5
@@ -43,6 +43,7 @@
6
 #include <net/if.h>
7
 #include <net/if_media.h>
8
 #include <net/if_types.h>
9
+#include <net/if_dl.h>
10
 #include <net/netisr.h>
11
 #include <net/route.h>
12
 #include <net/vnet.h>
13
@@ -66,6 +67,13 @@ static const struct ng_cmdlist ng_eiface_cmdlist[] = {
14
 	},
15
 	{
16
 	  NGM_EIFACE_COOKIE,
17
+	  NGM_EIFACE_SET_IFNAME,
18
+	  "setifname",
19
+	  &ng_parse_string_type,
20
+	  NULL
21
+	},
22
+	{
23
+	  NGM_EIFACE_COOKIE,
24
 	  NGM_EIFACE_SET,
25
 	  "set",
26
 	  &ng_parse_enaddr_type,
27
@@ -470,6 +478,11 @@ ng_eiface_rcvmsg(node_p node, item_p item, hook_p lasthook)
28
 	struct ng_mesg *resp = NULL;
29
 	int error = 0;
30
 	struct ng_mesg *msg;
31
+	char *new_name;
32
+        size_t namelen, onamelen;
33
+        struct sockaddr_dl *sdl = NULL;
34
+        struct ifaddr *ifa = NULL;
35
+	node_p ethernode;
36
 
37
 	NGI_GET_MSG(item, msg);
38
 	switch (msg->header.typecookie) {
39
@@ -496,6 +509,46 @@ ng_eiface_rcvmsg(node_p node, item_p item, hook_p lasthook)
40
 			}
41
 			strlcpy(resp->data, ifp->if_xname, IFNAMSIZ);
42
 			break;
43
+		case NGM_EIFACE_SET_IFNAME:
44
+			new_name = (char *)msg->data;
45
+                        
46
+                	/* Deny request if interface is UP */
47
+                	if ((ifp->if_flags & IFF_UP) != 0) {
48
+                  		error = EBUSY;
49
+                  		break;
50
+                        }
51
+                        
52
+                	EVENTHANDLER_INVOKE(ifnet_departure_event, ifp);
53
+
54
+			ethernode = ng_name2noderef(node, ifp->if_xname);
55
+                        if (ethernode != NULL)
56
+                                ng_name_node(ethernode, new_name);
57
+
58
+                	strlcpy(ifp->if_xname, new_name, sizeof(ifp->if_xname));
59
+                	ifa = ifp->if_addr;
60
+                	IFA_LOCK(ifa);
61
+                	sdl = (struct sockaddr_dl *)ifa->ifa_addr;
62
+                	namelen = strlen(new_name) + 1;
63
+                	onamelen = sdl->sdl_nlen;
64
+                	/*
65
+                 	* Move the address if needed.  This is safe because we
66
+                 	* allocate space for a name of length IFNAMSIZ when we
67
+                 	* create this in if_attach().
68
+                	 */
69
+        	        if (namelen != onamelen) {
70
+	                        bcopy(sdl->sdl_data + onamelen,
71
+                        	    sdl->sdl_data + namelen, sdl->sdl_alen);
72
+                	}
73
+        	        bcopy(new_name, sdl->sdl_data, namelen);
74
+	                sdl->sdl_nlen = namelen;
75
+                	sdl = (struct sockaddr_dl *)ifa->ifa_netmask;
76
+        	        bzero(sdl->sdl_data, onamelen);
77
+	                while (namelen != 0)
78
+                        	sdl->sdl_data[--namelen] = 0xff;
79
+                	IFA_UNLOCK(ifa);
80
+
81
+                	EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp);
82
+			break;
83
 
84
 		case NGM_EIFACE_GET_IFADDRS:
85
 		    {
86
diff --git a/sys/netgraph/ng_eiface.h b/sys/netgraph/ng_eiface.h
87
index 6fc1c5b..9f1509b 100644
88
--- a/sys/netgraph/ng_eiface.h
89
+++ b/sys/netgraph/ng_eiface.h
90
@@ -54,6 +54,7 @@ enum {
91
 	NGM_EIFACE_GET_IFNAME = 1,	/* get the interface name */
92
 	NGM_EIFACE_GET_IFADDRS,		/* returns list of addresses */
93
 	NGM_EIFACE_SET,			/* set ethernet address */
94
+	NGM_EIFACE_SET_IFNAME,
95
 };
96
 
97
 #endif /* _NETGRAPH_NG_EIFACE_H_ */
98
diff --git a/usr.sbin/ngctl/main.c b/usr.sbin/ngctl/main.c
99
index 3581386..aae67df 100644
100
--- a/usr.sbin/ngctl/main.c
101
+++ b/usr.sbin/ngctl/main.c
102
@@ -218,7 +218,6 @@ ReadFile(FILE *fp)
103
 			continue;
104
 		if ((rtn = DoParseCommand(line)) != 0) {
105
 			warnx("line %d: error in file", num);
106
-			return (rtn);
107
 		}
108
 	}
109
 	return (CMDRTN_OK);
(37-37/67)