kern/66225: Extend ng_eiface(4) control messages

Gleb Smirnoff glebius at cell.sick.ru
Tue May 4 01:20:17 PDT 2004


The following reply was made to PR kern/66225; it has been noted by GNATS.

From: Gleb Smirnoff <glebius at cell.sick.ru>
To: Robin Breathe <robin at isometry.net>
Cc: FreeBSD-gnats-submit at freebsd.org
Subject: Re: kern/66225: Extend ng_eiface(4) control messages
Date: Tue, 4 May 2004 12:12:42 +0400

   Robin,
 
   can you take a look at these threads:
 http://groups.google.com/groups?threadm=c2l47t%2413rc%241%40FreeBSD.csie.NCTU.edu.tw
 http://groups.google.com/groups?threadm=c3etc5%2422b3%241%40FreeBSD.csie.NCTU.edu.tw
 
   May be you have some ideas/comments on this. And note, that now
 we have one more interface node ng_sppp and we are going to have
 fifth - ng_atm.
   I think this more general solution is better. I haven't started writing it,
 since I can't yet understand which approach described in above links, 
 is prefered by developers.
 
 P.S. You have forgot to bump NGM_EIFACE_COOKIE in your patch.
 
 On Mon, May 03, 2004 at 08:59:19PM +0000, Robin Breathe wrote:
 R> 
 R> >Number:         66225
 R> >Category:       kern
 R> >Synopsis:       Extend ng_eiface(4) control messages
 R> >Confidential:   no
 R> >Severity:       non-critical
 R> >Priority:       low
 R> >Responsible:    freebsd-bugs
 R> >State:          open
 R> >Quarter:        
 R> >Keywords:       
 R> >Date-Required:
 R> >Class:          change-request
 R> >Submitter-Id:   current-users
 R> >Arrival-Date:   Mon May 03 14:00:38 PDT 2004
 R> >Closed-Date:
 R> >Last-Modified:
 R> >Originator:     Robin Breathe
 R> >Release:        FreeBSD 5.2-CURRENT i386
 R> >Organization:
 R> isometry.net
 R> >Environment:
 R> 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
 R> 
 R> >Description:
 R> - Extend the ng_eiface(4) control message set with getifaddr, getifindex, getenaddr and setenaddr, c.f. ng_ether(4).
 R>   Allows code to get a handle on the associated ngeth# interface, and change its properties without knowing the unit number.
 R> - Renamed NGM_EIFACE_SET (set) to NGM_EIFACE_SET_ENADDR (setenaddr) for clarity, and to match ng_ether(4).
 R> - Clean up some extraneous code.
 R> - Increased max MTU to 9000.
 R> - Document the new interfaces in ng_eiface.4.
 R> >How-To-Repeat:
 R> >Fix:
 R> Apply the following patch in /usr/src of -CURRENT.
 R> 
 R> --- ng_eiface.diff begins here ---
 R> diff -ruN share/man/man4/ng_eiface.4 share/man/man4/ng_eiface.4.ori
 R> --- share/man/man4/ng_eiface.4.ori	Mon May  3 20:23:57 2004
 R> +++ share/man/man4/ng_eiface.4	Mon May  3 20:35:27 2004
 R> @@ -65,25 +65,21 @@
 R>  .Sh CONTROL MESSAGES
 R>  This node type supports the generic control messages, plus the following:
 R>  .Bl -tag -width indent
 R> -.It Dv NGM_EIFACE_SET
 R> -Set link-level address of the interface.
 R> -Requires
 R> -.Vt "struct ether_addr"
 R> -as an argument.
 R> -This message also has an
 R> -.Tn ASCII
 R> -version, called
 R> -.Dq Li set ,
 R> -which requires as an argument an
 R> -.Tn ASCII
 R> -string consisting of 6 colon-separated hex digits.
 R> -.It Dv NGM_EIFACE_GET_IFNAME
 R> -Return the name of the associated interface as a
 R> +.It Dv NGM_EIFACE_GET_IFNAME Pq Li getifname
 R> +Returns the name of the associated interface as a
 R>  .Dv NUL Ns -terminated
 R>  .Tn ASCII
 R>  string.
 R> -.It Dv NGM_EIFACE_GET_IFADDRS
 R> -Return the list of link-level addresses associated with the node.
 R> +.It DV NGM_EIFACE_GET_IFINDEX Pq Li getifindex
 R> +Returns the global index of the associated inteface as a 32-bit integer.
 R> +.It DV NGM_EIFACE_GET_ENADDR Pq Li getenaddr
 R> +Returns the associated interface's unique six-byte Ethernet address.
 R> +.It Dv NGM_EIFACE_SET_ENADDR Pq Li setenaddr
 R> +Sets the associated interface's unique six-byte Ethernet address.
 R> +This control message is equivalent to using the
 R> +.Dv SIOCIFLLADDR
 R> +.Xr ioctl 2
 R> +system call.
 R>  .El
 R>  .Sh SHUTDOWN
 R>  This node shuts down upon receipt of a
 R> diff -ruN sys/netgraph/ng_eiface.c sys/netgraph/ng_eiface.c.ori
 R> --- sys/netgraph/ng_eiface.c.ori	Thu Apr 22 19:11:57 2004
 R> +++ sys/netgraph/ng_eiface.c	Mon May  3 20:16:06 2004
 R> @@ -60,8 +60,29 @@
 R>  static const struct ng_cmdlist ng_eiface_cmdlist[] = {
 R>  	{
 R>  	  NGM_EIFACE_COOKIE,
 R> -	  NGM_EIFACE_SET,
 R> -	  "set",
 R> +	  NGM_EIFACE_GET_IFNAME,
 R> +	  "getifname",
 R> +	  NULL,
 R> +	  &ng_parse_string_type
 R> +	},
 R> +	{
 R> +	  NGM_EIFACE_COOKIE,
 R> +	  NGM_EIFACE_GET_IFINDEX,
 R> +	  "getifindex",
 R> +	  NULL,
 R> +	  &ng_parse_int32_type
 R> +	},
 R> +	{
 R> +	  NGM_EIFACE_COOKIE,
 R> +	  NGM_EIFACE_GET_ENADDR,
 R> +	  "getenaddr",
 R> +	  NULL,
 R> +	  &ng_parse_enaddr_type
 R> +	},
 R> +	{
 R> +	  NGM_EIFACE_COOKIE,
 R> +	  NGM_EIFACE_SET_ENADDR,
 R> +	  "setenaddr",
 R>  	  &ng_parse_enaddr_type,
 R>  	  NULL
 R>  	},
 R> @@ -486,80 +507,42 @@
 R>  	switch		(msg->header.typecookie) {
 R>  	case NGM_EIFACE_COOKIE:
 R>  		switch (msg->header.cmd) {
 R> -		case NGM_EIFACE_SET:
 R> -		{
 R> -			struct ether_addr *eaddr;
 R> -			struct ifaddr *ifa;
 R> -			struct sockaddr_dl *sdl;
 R> -
 R> -			if (msg->header.arglen != sizeof(struct ether_addr)){
 R> -				error = EINVAL;
 R> +		case NGM_EIFACE_GET_IFNAME:
 R> +			NG_MKRESPONSE(resp, msg, IFNAMSIZ + 1, M_NOWAIT);
 R> +			if (resp == NULL) {
 R> +				error = ENOMEM;
 R>  				break;
 R>  			}
 R> -			eaddr = (struct ether_addr *)(msg->data);
 R> -			bcopy(eaddr, priv->arpcom.ac_enaddr, ETHER_ADDR_LEN);
 R> -
 R> -			/* And put it in the ifaddr list */
 R> -			TAILQ_FOREACH(ifa, &(ifp->if_addrhead), ifa_link) {
 R> -				sdl = (struct sockaddr_dl *)ifa->ifa_addr;
 R> -				if (sdl->sdl_type == IFT_ETHER) {
 R> -					bcopy((IFP2AC(ifp))->ac_enaddr,
 R> -						LLADDR(sdl), ifp->if_addrlen);
 R> -					break;
 R> -				}
 R> -			}
 R> +			strlcpy(resp->data, ifp->if_xname, IFNAMSIZ + 1);
 R>  			break;
 R> -		}
 R>  
 R> -		case NGM_EIFACE_GET_IFNAME:
 R> -		{
 R> -			struct ng_eiface_ifname *arg;
 R> -
 R> -			NG_MKRESPONSE(resp, msg, sizeof(*arg), M_NOWAIT);
 R> +		case NGM_EIFACE_GET_IFINDEX:
 R> +			NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT);
 R>  			if (resp == NULL) {
 R>  				error = ENOMEM;
 R>  				break;
 R>  			}
 R> -			arg = (struct ng_eiface_ifname *)resp->data;
 R> -			strlcpy(arg->ngif_name, ifp->if_xname,
 R> -			    sizeof(arg->ngif_name));
 R> +			*((u_int32_t *)resp->data) = ifp->if_index;
 R>  			break;
 R> -		}
 R>  
 R> -		case NGM_EIFACE_GET_IFADDRS:
 R> -		{
 R> -			struct ifaddr  *ifa;
 R> -			caddr_t		ptr;
 R> -			int		buflen;
 R> -
 R> -#define SA_SIZE(s)	((s)->sa_len<sizeof(*(s))? sizeof(*(s)):(s)->sa_len)
 R> -
 R> -			/* Determine size of response and allocate it */
 R> -			buflen = 0;
 R> -			TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
 R> -			buflen += SA_SIZE(ifa->ifa_addr);
 R> -			NG_MKRESPONSE(resp, msg, buflen, M_NOWAIT);
 R> +		case NGM_EIFACE_GET_ENADDR:
 R> +			NG_MKRESPONSE(resp, msg, ETHER_ADDR_LEN, M_NOWAIT);
 R>  			if (resp == NULL) {
 R>  				error = ENOMEM;
 R>  				break;
 R>  			}
 R> -			/* Add addresses */
 R> -			ptr = resp->data;
 R> -			TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
 R> -				const int       len = SA_SIZE(ifa->ifa_addr);
 R> -
 R> -				if (buflen < len) {
 R> -					log(LOG_ERR, "%s: len changed?\n",
 R> -					ifp->if_xname);
 R> -					break;
 R> -				}
 R> -				bcopy(ifa->ifa_addr, ptr, len);
 R> -				ptr += len;
 R> -				buflen -= len;
 R> +			bcopy((IFP2AC(ifp))->ac_enaddr,
 R> +				resp->data, ETHER_ADDR_LEN);
 R> +			break;
 R> +
 R> +		case NGM_EIFACE_SET_ENADDR:
 R> +			if (msg->header.arglen != ETHER_ADDR_LEN){
 R> +				error = EINVAL;
 R> +				break;
 R>  			}
 R> +			error = if_setlladdr(ifp,
 R> +				(u_char *)msg->data, ETHER_ADDR_LEN);
 R>  			break;
 R> -#undef SA_SIZE
 R> -		}
 R>  
 R>  		default:
 R>  			error = EINVAL;
 R> diff -ruN sys/netgraph/ng_eiface.h sys/netgraph/ng_eiface.h.ori
 R> --- sys/netgraph/ng_eiface.h.ori	Wed Dec 17 13:03:32 2003
 R> +++ sys/netgraph/ng_eiface.h	Mon May  3 20:16:06 2004
 R> @@ -38,25 +38,21 @@
 R>  
 R>  /* Interface base name */
 R>  #define NG_EIFACE_EIFACE_NAME		"ngeth"
 R> -#define NG_EIFACE_EIFACE_NAME_MAX	15
 R>  
 R>  /* My hook names */
 R>  #define NG_EIFACE_HOOK_ETHER		"ether"
 R>  
 R>  /* MTU bounds */
 R>  #define NG_EIFACE_MTU_MIN		72
 R> -#define NG_EIFACE_MTU_MAX		2312
 R> +#define NG_EIFACE_MTU_MAX		9000
 R>  #define NG_EIFACE_MTU_DEFAULT		1500
 R>  
 R>  /* Netgraph commands */
 R>  enum {
 R> -	NGM_EIFACE_GET_IFNAME = 1,	/* returns struct ng_eiface_ifname */
 R> -	NGM_EIFACE_GET_IFADDRS,		/* returns list of addresses */
 R> -	NGM_EIFACE_SET,			/* set ethernet address */
 R> -};
 R> -
 R> -struct ng_eiface_ifname {
 R> -	char    ngif_name[NG_EIFACE_EIFACE_NAME_MAX + 1];
 R> +	NGM_EIFACE_GET_IFNAME = 1,	/* get the interface name */
 R> +	NGM_EIFACE_GET_IFINDEX,		/* get the interface global index # */
 R> +	NGM_EIFACE_GET_ENADDR,		/* get Ethernet address */
 R> +	NGM_EIFACE_SET_ENADDR,		/* set Ethernet address */
 R>  };
 R>  
 R>  #endif /* _NETGRAPH_NG_EIFACE_H_ */
 R> --- ng_eiface.diff ends here ---
 R> 
 R> 
 R> >Release-Note:
 R> >Audit-Trail:
 R> >Unformatted:
 R> _______________________________________________
 R> freebsd-bugs at freebsd.org mailing list
 R> http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
 R> To unsubscribe, send any mail to "freebsd-bugs-unsubscribe at freebsd.org"
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE


More information about the freebsd-bugs mailing list