Bug 31476

Summary: ifconfig's lladdr is ethernet specific
Product: Base System Reporter: tinguely <tinguely>
Component: binAssignee: ru <ru>
Status: Closed FIXED    
Severity: Affects Only Me CC: tinguely
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description tinguely 2001-10-24 16:10:00 UTC
	ifconfig's lladdr feature that allows the setting of the link-level
	address on an interface. lladdr is documented to not be
	ethernet-specific, but the implementation uses ether_aton() which
	requires the link level address to be EXACTLY ETHER_ADDR_LEN in
	length.

	I want to add support for changing a ARCNET link-level address which
	is only one octect long.

Fix: I added a routine to ifconfig called generic_atoi that will
	allow abitraty length link-level addresses. generic_atoi() will
	assume ETHER_ADDR_LEN length if the caller does not include
	an integer to get the count of octets in the specified link-level
	address.

	The patch also adds "arc" as a new address family. My apologies
	for adding two features into one bug-report patch, but they go
	hand-in-hand.

	The SIOCSIFLLADDR ioctl processing in sys/net/if.c will not
	allow a person to set the wrong length link-level address, so
	this will not break anything in the kernel.

How-To-Repeat: 	ifconfig INTERFACE lladdr 88
Comment 1 ru freebsd_committer freebsd_triage 2001-10-24 18:25:17 UTC
On Wed, Oct 24, 2001 at 10:02:50AM -0500, tinguely@web.cs.ndsu.nodak.edu wrote:
> 
> 	ifconfig's lladdr feature that allows the setting of the link-level
> 	address on an interface. lladdr is documented to not be
> 	ethernet-specific, but the implementation uses ether_aton() which
> 	requires the link level address to be EXACTLY ETHER_ADDR_LEN in
> 	length.
> 
[...]
> 	I added a routine to ifconfig called generic_atoi that will
> 	allow abitraty length link-level addresses. generic_atoi() will
> 	assume ETHER_ADDR_LEN length if the caller does not include
> 	an integer to get the count of octets in the specified link-level
> 	address.
> 
Can't we just use link_addr(3) for that?  Here's the patch (lightly
tested) for RELENG_4:

Index: ifconfig.c
===================================================================
RCS file: /home/ncvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.51.2.13
diff -u -p -r1.51.2.13 ifconfig.c
--- ifconfig.c	2001/08/20 18:38:41	1.51.2.13
+++ ifconfig.c	2001/10/24 17:24:09
@@ -1066,17 +1066,24 @@ setiflladdr(val, dummy, s, afp)
 	int s;
 	const struct afswtch *afp;
 {
-	struct ether_addr	*ea;
+	char *newval;
+	struct sockaddr_dl	sdl;
 
-	ea = ether_aton(val);
-	if (ea == NULL) {
+	if ((newval = malloc(strlen(val) + 1)) == NULL)
+		errx(1, "malloc failed");
+	newval[0] = ':';
+	strcpy(newval + 1, val);
+	sdl.sdl_len = sizeof(sdl);
+	link_addr(newval, &sdl);
+	free(newval);
+	if (sdl.sdl_alen > sizeof(ifr.ifr_addr.sa_data)) {
 		warn("malformed link-level address");
 		return;
 	}
 	strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
-	ifr.ifr_addr.sa_len = ETHER_ADDR_LEN;
+	ifr.ifr_addr.sa_len = sdl.sdl_alen;
 	ifr.ifr_addr.sa_family = AF_LINK;
-	bcopy(ea, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN);
+	bcopy(LLADDR(&sdl), ifr.ifr_addr.sa_data, sdl.sdl_alen);
 	if (ioctl(s, SIOCSIFLLADDR, (caddr_t)&ifr) < 0)
 		warn("ioctl (set lladdr)");
 

Cheers,
-- 
Ruslan Ermilov		Oracle Developer/DBA,
ru@sunbay.com		Sunbay Software AG,
ru@FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
Comment 2 tinguely 2001-11-05 14:33:02 UTC
If no one has an objection to Ruslan Ermilov's Oct 24 solution using
link_addr() that replaces ether_aton() to make ifconfig(8)'s lladdr 
option not be ethernet MAC size dependant, could the changes be committed 
and this bug report closed?

thank you,

--mark tinguely
Comment 3 ru freebsd_committer freebsd_triage 2002-03-27 15:36:44 UTC
State Changed
From-To: open->feedback

Fixed in 5.0-CURRENT, in ifconfig.c,v 1.73 and ifconfig.8,v 1.54. 


Comment 4 ru freebsd_committer freebsd_triage 2002-03-27 15:36:44 UTC
Responsible Changed
From-To: freebsd-bugs->ru

MFC in 1 week.
Comment 5 ru freebsd_committer freebsd_triage 2002-04-03 12:45:58 UTC
State Changed
From-To: feedback->closed

Fixed in 4.5-STABLE, in ifconfig.c,v 1.51.2.16 and ifconfig.8,v 1.27.2.18.