Subject: in-kernel workaround for PR 14746
To: None <port-sparc64@netbsd.org, tech-net@netbsd.org>
From: Jed Davis <jldavis+netbsdlist@cs.oberlin.edu>
List: tech-net
Date: 12/02/2001 03:34:59
Quick context: the implementation of SIOCGIFCONF can, on 64-bit archs
copy out data the compiler expects to be word-aligned to non-aligned
addresses; on at least sparc64 this causes some network daemons to die
on a bus error.

The recommended solution seems to be to modify the userland programs
to call getifaddrs() instead of that benighted ioctl; using bcopy()
instead of struct assignment to extract data from the ioctl buffer
also works.

However, for those of us who are too lazy to retrofit and recompile
every affected program, I have the following patch to sys/net/if.c
which rounds up to the next word size multiple the lengths of the
sockaddrs that ifconf() copies out .  This is almost certainly not the
best solution, but it seems to work and hasn't broken anything for me
yet:

--- sys/net/if.c.orig	Sun Dec  2 00:35:59 2001
+++ sys/net/if.c	Tue Nov 27 21:50:53 2001
@@ -1536,6 +1536,8 @@
 					ifrp++;
 				}
 			} else {
+			  sa->sa_len=((sa->sa_len+sizeof(caddr_t)-1)
+				      /sizeof(caddr_t))*sizeof(caddr_t);
 				space -= sa->sa_len - sizeof(*sa);
 				if (space >= (int)sizeof (ifr)) {
 					error = copyout((caddr_t)&ifr,

Note that I'm specifically avoiding calling this a "fix", mainly
because it's IMHO a rather inelegant hack, and hasn't been anything
like properly tested; the bad indentation was left in to reinforce
this point. (-:

--Jed

-- 
#!/usr/bin/perl -- ## "But life wasn't yes-no, on-off.  Life was shades of gray,
sub f{(($n,$d,@_)=@_)?(substr(## and rainbows not in the order of the spectrum."
" ExhortJavelinBus",$n&&$d/$n,1),$n?f($d##   -- L. E. Modesitt, Jr., _Adiamante_
%$n,$n,@_):&f):("\n")}print f 1461,10324,55001,444162,1208,1341,5660480,79715997