kern/66225: Extend ng_eiface(4) control messages

Robin Breathe robin at isometry.net
Mon May 3 14:00:39 PDT 2004


>Number:         66225
>Category:       kern
>Synopsis:       Extend ng_eiface(4) control messages
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 03 14:00:38 PDT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Robin Breathe
>Release:        FreeBSD 5.2-CURRENT i386
>Organization:
isometry.net
>Environment:
System: FreeBSD twiddle 5.2-CURRENT FreeBSD 5.2-CURRENT #0: Thu Apr 29 23:20:35 UTC 2004 root at twiddle:/home/data/work/usr/src/sys/TWIDDLE i386

>Description:
- Extend the ng_eiface(4) control message set with getifaddr, getifindex, getenaddr and setenaddr, c.f. ng_ether(4).
  Allows code to get a handle on the associated ngeth# interface, and change its properties without knowing the unit number.
- Renamed NGM_EIFACE_SET (set) to NGM_EIFACE_SET_ENADDR (setenaddr) for clarity, and to match ng_ether(4).
- Clean up some extraneous code.
- Increased max MTU to 9000.
- Document the new interfaces in ng_eiface.4.
>How-To-Repeat:
>Fix:
Apply the following patch in /usr/src of -CURRENT.

--- ng_eiface.diff begins here ---
diff -ruN share/man/man4/ng_eiface.4 share/man/man4/ng_eiface.4.ori
--- share/man/man4/ng_eiface.4.ori	Mon May  3 20:23:57 2004
+++ share/man/man4/ng_eiface.4	Mon May  3 20:35:27 2004
@@ -65,25 +65,21 @@
 .Sh CONTROL MESSAGES
 This node type supports the generic control messages, plus the following:
 .Bl -tag -width indent
-.It Dv NGM_EIFACE_SET
-Set link-level address of the interface.
-Requires
-.Vt "struct ether_addr"
-as an argument.
-This message also has an
-.Tn ASCII
-version, called
-.Dq Li set ,
-which requires as an argument an
-.Tn ASCII
-string consisting of 6 colon-separated hex digits.
-.It Dv NGM_EIFACE_GET_IFNAME
-Return the name of the associated interface as a
+.It Dv NGM_EIFACE_GET_IFNAME Pq Li getifname
+Returns the name of the associated interface as a
 .Dv NUL Ns -terminated
 .Tn ASCII
 string.
-.It Dv NGM_EIFACE_GET_IFADDRS
-Return the list of link-level addresses associated with the node.
+.It DV NGM_EIFACE_GET_IFINDEX Pq Li getifindex
+Returns the global index of the associated inteface as a 32-bit integer.
+.It DV NGM_EIFACE_GET_ENADDR Pq Li getenaddr
+Returns the associated interface's unique six-byte Ethernet address.
+.It Dv NGM_EIFACE_SET_ENADDR Pq Li setenaddr
+Sets the associated interface's unique six-byte Ethernet address.
+This control message is equivalent to using the
+.Dv SIOCIFLLADDR
+.Xr ioctl 2
+system call.
 .El
 .Sh SHUTDOWN
 This node shuts down upon receipt of a
diff -ruN sys/netgraph/ng_eiface.c sys/netgraph/ng_eiface.c.ori
--- sys/netgraph/ng_eiface.c.ori	Thu Apr 22 19:11:57 2004
+++ sys/netgraph/ng_eiface.c	Mon May  3 20:16:06 2004
@@ -60,8 +60,29 @@
 static const struct ng_cmdlist ng_eiface_cmdlist[] = {
 	{
 	  NGM_EIFACE_COOKIE,
-	  NGM_EIFACE_SET,
-	  "set",
+	  NGM_EIFACE_GET_IFNAME,
+	  "getifname",
+	  NULL,
+	  &ng_parse_string_type
+	},
+	{
+	  NGM_EIFACE_COOKIE,
+	  NGM_EIFACE_GET_IFINDEX,
+	  "getifindex",
+	  NULL,
+	  &ng_parse_int32_type
+	},
+	{
+	  NGM_EIFACE_COOKIE,
+	  NGM_EIFACE_GET_ENADDR,
+	  "getenaddr",
+	  NULL,
+	  &ng_parse_enaddr_type
+	},
+	{
+	  NGM_EIFACE_COOKIE,
+	  NGM_EIFACE_SET_ENADDR,
+	  "setenaddr",
 	  &ng_parse_enaddr_type,
 	  NULL
 	},
@@ -486,80 +507,42 @@
 	switch		(msg->header.typecookie) {
 	case NGM_EIFACE_COOKIE:
 		switch (msg->header.cmd) {
-		case NGM_EIFACE_SET:
-		{
-			struct ether_addr *eaddr;
-			struct ifaddr *ifa;
-			struct sockaddr_dl *sdl;
-
-			if (msg->header.arglen != sizeof(struct ether_addr)){
-				error = EINVAL;
+		case NGM_EIFACE_GET_IFNAME:
+			NG_MKRESPONSE(resp, msg, IFNAMSIZ + 1, M_NOWAIT);
+			if (resp == NULL) {
+				error = ENOMEM;
 				break;
 			}
-			eaddr = (struct ether_addr *)(msg->data);
-			bcopy(eaddr, priv->arpcom.ac_enaddr, ETHER_ADDR_LEN);
-
-			/* And put it in the ifaddr list */
-			TAILQ_FOREACH(ifa, &(ifp->if_addrhead), ifa_link) {
-				sdl = (struct sockaddr_dl *)ifa->ifa_addr;
-				if (sdl->sdl_type == IFT_ETHER) {
-					bcopy((IFP2AC(ifp))->ac_enaddr,
-						LLADDR(sdl), ifp->if_addrlen);
-					break;
-				}
-			}
+			strlcpy(resp->data, ifp->if_xname, IFNAMSIZ + 1);
 			break;
-		}
 
-		case NGM_EIFACE_GET_IFNAME:
-		{
-			struct ng_eiface_ifname *arg;
-
-			NG_MKRESPONSE(resp, msg, sizeof(*arg), M_NOWAIT);
+		case NGM_EIFACE_GET_IFINDEX:
+			NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT);
 			if (resp == NULL) {
 				error = ENOMEM;
 				break;
 			}
-			arg = (struct ng_eiface_ifname *)resp->data;
-			strlcpy(arg->ngif_name, ifp->if_xname,
-			    sizeof(arg->ngif_name));
+			*((u_int32_t *)resp->data) = ifp->if_index;
 			break;
-		}
 
-		case NGM_EIFACE_GET_IFADDRS:
-		{
-			struct ifaddr  *ifa;
-			caddr_t		ptr;
-			int		buflen;
-
-#define SA_SIZE(s)	((s)->sa_len<sizeof(*(s))? sizeof(*(s)):(s)->sa_len)
-
-			/* Determine size of response and allocate it */
-			buflen = 0;
-			TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
-			buflen += SA_SIZE(ifa->ifa_addr);
-			NG_MKRESPONSE(resp, msg, buflen, M_NOWAIT);
+		case NGM_EIFACE_GET_ENADDR:
+			NG_MKRESPONSE(resp, msg, ETHER_ADDR_LEN, M_NOWAIT);
 			if (resp == NULL) {
 				error = ENOMEM;
 				break;
 			}
-			/* Add addresses */
-			ptr = resp->data;
-			TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
-				const int       len = SA_SIZE(ifa->ifa_addr);
-
-				if (buflen < len) {
-					log(LOG_ERR, "%s: len changed?\n",
-					ifp->if_xname);
-					break;
-				}
-				bcopy(ifa->ifa_addr, ptr, len);
-				ptr += len;
-				buflen -= len;
+			bcopy((IFP2AC(ifp))->ac_enaddr,
+				resp->data, ETHER_ADDR_LEN);
+			break;
+
+		case NGM_EIFACE_SET_ENADDR:
+			if (msg->header.arglen != ETHER_ADDR_LEN){
+				error = EINVAL;
+				break;
 			}
+			error = if_setlladdr(ifp,
+				(u_char *)msg->data, ETHER_ADDR_LEN);
 			break;
-#undef SA_SIZE
-		}
 
 		default:
 			error = EINVAL;
diff -ruN sys/netgraph/ng_eiface.h sys/netgraph/ng_eiface.h.ori
--- sys/netgraph/ng_eiface.h.ori	Wed Dec 17 13:03:32 2003
+++ sys/netgraph/ng_eiface.h	Mon May  3 20:16:06 2004
@@ -38,25 +38,21 @@
 
 /* Interface base name */
 #define NG_EIFACE_EIFACE_NAME		"ngeth"
-#define NG_EIFACE_EIFACE_NAME_MAX	15
 
 /* My hook names */
 #define NG_EIFACE_HOOK_ETHER		"ether"
 
 /* MTU bounds */
 #define NG_EIFACE_MTU_MIN		72
-#define NG_EIFACE_MTU_MAX		2312
+#define NG_EIFACE_MTU_MAX		9000
 #define NG_EIFACE_MTU_DEFAULT		1500
 
 /* Netgraph commands */
 enum {
-	NGM_EIFACE_GET_IFNAME = 1,	/* returns struct ng_eiface_ifname */
-	NGM_EIFACE_GET_IFADDRS,		/* returns list of addresses */
-	NGM_EIFACE_SET,			/* set ethernet address */
-};
-
-struct ng_eiface_ifname {
-	char    ngif_name[NG_EIFACE_EIFACE_NAME_MAX + 1];
+	NGM_EIFACE_GET_IFNAME = 1,	/* get the interface name */
+	NGM_EIFACE_GET_IFINDEX,		/* get the interface global index # */
+	NGM_EIFACE_GET_ENADDR,		/* get Ethernet address */
+	NGM_EIFACE_SET_ENADDR,		/* set Ethernet address */
 };
 
 #endif /* _NETGRAPH_NG_EIFACE_H_ */
--- ng_eiface.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list