Small kludge in pf.c

Ed Schouten ed at fxq.nl
Wed Apr 18 10:14:51 UTC 2007


Hello,

Some time ago I looked through the PF source code and I saw something
that isn't really a bug, but is (in my opinion) something that isn't
really nice when it comes to coding style. The following snippets are
from pf.c. Please refer to the file itself if you want to take a closer
look.

| void			 pf_hash(struct pf_addr *, struct pf_addr *,
| 			    struct pf_poolhashkey *, sa_family_t);
| ...
| int
| pf_map_addr(sa_family_t af, struct pf_rule *r, struct pf_addr *saddr,
|     struct pf_addr *naddr, struct pf_addr *init_addr, struct pf_src_node **sn)
| {
| 	unsigned char		 hash[16];
| ...
| 	case PF_POOL_SRCHASH:
| 		pf_hash(saddr, (struct pf_addr *)&hash, &rpool->key, af);
| 		PF_POOLMASK(naddr, raddr, rmask, (struct pf_addr *)&hash, af);
| 		break;

In `pf_map_addr()' the `hash' variable is referred to only twice, only
in the PF_POOL_SRCHASH case. For some reason, the author of the code
picked an `unsigned char[16]' as its type, while a `struct pf_addr'
would suffice as well. This makes it possible to use it without all the
evil castings that are used and should keep the code portable. Think
about what would happen when PF would suddenly gain support for a
networking protocol that uses 17 or more bytes for addressing...

-- 
 Ed Schouten <ed at fxq.nl>
 WWW: http://g-rave.nl/
-------------- 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-pf/attachments/20070418/51b0d3da/attachment.pgp


More information about the freebsd-pf mailing list