Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Sep 1998 17:06:30 +0200 (MET DST)
From:      Luigi Rizzo <luigi@labinfo.iet.unipi.it>
To:        hackers@FreeBSD.ORG
Subject:   bcmp abuse in networking code ?
Message-ID:  <199809021506.RAA10910@labinfo.iet.unipi.it>

next in thread | raw e-mail | index | archive | help
poking around in /sys/net and /sys/netinet, i frequently see bcmp() being
used to compare ethernet addresses (but not only those). In some cases,
even against the ethernet broadcast address.

In my revised bridge code i have the following macros

#define ETH_MATCH(a,b) ( \
    ((unsigned short *)(a))[2] == ((unsigned short *)(b))[2] && \
    *((unsigned int *)(a)) == *((unsigned int *)(b)) )
#define IS_ETHER_BROADCAST(a) ( \
        *((unsigned int *)(a)) == 0xffffffff && \
        ((unsigned short *)(a))[2] == 0xffff )

which seem to do a decent job in terms of performance. On a Pentium90,
they save about 40-50 ticks per call, which is not bad considering how
frequently they are used on a bridge or on a multicast router.

I suppose the macros as above might have some alignment problems
on the Alpha, but one could always make them conditionals and resort
to the old method for the Alpha. How about putting something similar
in, say, sys/net/ethernet.h (and BTW eliminate the useless
etherbroadcastaddr[] variable from /sys/net/if_ethersubr.c, whose
prototype is in /sys/netinet/if_ether.h where i am not really sure
it belongs to!)

	cheers
	luigi

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809021506.RAA10910>