Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Apr 2007 11:55:08 +0200
From:      Ed Schouten <ed@fxq.nl>
To:        pf@freebsd.org
Subject:   Small kludge in pf.c
Message-ID:  <20070418095508.GB85811@hoeg.nl>

next in thread | raw e-mail | index | archive | help

--eJnRUKwClWJh1Khz
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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
=66rom 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...

--=20
 Ed Schouten <ed@fxq.nl>
 WWW: http://g-rave.nl/

--eJnRUKwClWJh1Khz
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFGJer852SDGA2eCwURAiDOAJsH5CoJMPKayTNt69/Q1QuDSUZm1wCeLfIf
/bhRZ5ESxY74YeUNmcAOeTA=
=rEu/
-----END PGP SIGNATURE-----

--eJnRUKwClWJh1Khz--



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