multiple definitions of ROUNDUP macro

Ruslan Ermilov ru at freebsd.org
Tue Apr 13 03:29:39 PDT 2004


On Tue, Apr 13, 2004 at 01:47:20AM -0700, Luigi Rizzo wrote:
> The ROUNDUP macro, used to account for the space occupied by a sockaddr   
> when passed through a routing socket, is defined in a zillion places:
> 
> src/usr.sbin/IPXrouted/startup.c:#define ROUNDUP(a) \
> src/usr.sbin/arp/arp.c:#define ROUNDUP(a) \
> src/usr.sbin/ndp/ndp.c:#define ROUNDUP(a) \
> src/usr.sbin/ppp/defs.h:#define ROUNDUP(x) ((x) ? (1 + (((x) - 1) | (sizeof(longsrc/usr.sbin/route6d/route6d.c:#define ROUNDUP(a) \
> src/usr.sbin/rwhod/rwhod.c:#define ROUNDUP(a) \
> src/sys/net/route.c.orig:#define ROUNDUP(a) (a>0 ? (1 + (((a) - 1) | (sizeof(lonsrc/sys/net/rtsock.c:#define ROUNDUP(a) \
> 
You forgot ifconfig(8) and route(8), my favourite reference utils,
when it comes to routing.  ;)

> A similar macro, ADVANCE, has similar problems.
> This is confusing at best, and a likely source of trouble.
> 
> If there are no objections I would like to replace it with a
> centralised macro (possibly with a suitable name) which takes
> a sockaddr * as argument and returns the rounded-up size of the
> object as a result.
> 
Yes, please!  I wanted to do it long ago, but couldn't come up
with good names for them.

> BTW, i notice that the rounding is to multiples of "sizeof(long)",
> and i wonder if this is intentional, especially on 64-bit
> architectures.
> 
It would probably be OK to round-up to an int, but it's too late
to change it now -- many off-tree tools that work with routing
sockets would break on machines with sizeof(int) != sizeof(long).


Cheers,
-- 
Ruslan Ermilov
ru at FreeBSD.org
FreeBSD committer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-net/attachments/20040413/fb941093/attachment.bin


More information about the freebsd-net mailing list