Subject: sysctl function and ROUNDUP kernel bug
To: None <port-alpha@NetBSD.ORG>
From: David Waitzman <djw@bbnplanet.com>
List: port-alpha
Date: 01/24/1996 11:51:11
I am trying to port gated to netbsd/alpha (sys.951220) and am having
problems with reading the interface list using the sysctl function on
variable CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST.  Dereferencing longs
in the middle of the returned data causes bus errors.  It appears that
the longs are embedded in structures that are on 4 byte but not 8 byte
alignment.  

In more detail, there are multiple structures being returned in one
call to sysctl().  The first is 176 bytes, the second 60 bytes,
and the third 176.  So, the third structure is only on a 4 byte
boundary.

Examining the kernel code generating the data, in file
sys/net/rtsock.c, I see that rt_msg2() is called by sysctl_iflist() to
allocate space and copy in some information using a ROUNDUP macro
defined in rtsock.c as:

#define ROUNDUP(a) \
	((a) > 0 ? (1 + (((a) - 1) | (sizeof(int32_t) - 1))) : sizeof(int32_t))

Other files in sys/net/ use 'long' instead of 'int32_t' in ROUNDUP macros.

I don't want to just change the ROUNDUP macro because of other things
that may depend upon the padding.

Can anyone suggest if changing ROUNDUP is the right thing to do?

I also note that the man pages are less than helpful.  sysctl(3) says
to look at route(4) for information on the above variable.  route(4)
doesn't mention the variable.  It does mention the getkerninfo(2)
system call which doesn't exist anymore.  sysctl(3) should also
mention the undocumented system call __sysctl(2).


thanks,
-david  [David Waitzman  (617)873-4323   djw@bbn.com]