
gdt at ir
Jan 13, 2004, 6:23 AM
Post #7 of 16
(519 views)
Permalink
|
> Okay, however lib/prefix.c provides calls to manage the data structure > 'struct prefix', and not the semantical object "network prefix" (or > whatever you name it). Clearly, one may use various calls, like > lib/prefix.c/apply_mask(), to enforce various semantics on specific > prefixes, but those aren't assumed to be a prerequisite for other calls > in the library. Good points. > Sure, comments are important, but the code and a couple of usage > examples -- which couldn't be any clearer than in this case -- are an > immediate evidence to the semantics (at least IMO). Perhaps, but are the following new comments accurate? If so, I'll commit them. Index: lib/prefix.h =================================================================== RCS file: /var/cvsroot/quagga/lib/prefix.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 prefix.h --- lib/prefix.h 13 Dec 2002 20:15:29 -0000 1.1.1.1 +++ lib/prefix.h 13 Jan 2004 13:21:04 -0000 @@ -23,6 +23,12 @@ #ifndef _ZEBRA_PREFIX_H #define _ZEBRA_PREFIX_H +/* + * A struct prefix can represent either a true 'network prefix', where + * the 'host bits' of the prefix are 0 (e.g. AF_INET:10.0.0.0/8), or + * an address and netmask (e.g. AF_INET:10.0.0.9/8). + */ + /* IPv4 and IPv6 unified prefix structure. */ struct prefix { Index: lib/prefix.c =================================================================== RCS file: /var/cvsroot/quagga/lib/prefix.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 prefix.c --- lib/prefix.c 13 Dec 2002 20:15:29 -0000 1.1.1.1 +++ lib/prefix.c 13 Jan 2004 13:21:04 -0000 @@ -118,7 +118,13 @@ } } -/* If both prefix structure is same then return 1 else return 0. */ +/* + * Return 1 if the address/netmask contained in the prefix structure + * is the same, and else return 0. For this routine, 'same' requires + * that not only the prefix length and the network part be the same, + * but also the host part. Thus, 10.0.0.1/8 and 10.0.0.2/8 are not + * the same. This routine has the same return value sense as '=='. + */ int prefix_same (struct prefix *p1, struct prefix *p2) { @@ -136,8 +142,16 @@ return 0; } -/* When both prefix structure is not same, but will be same after - applying mask, return 0. otherwise, return 1 */ +/* + * Return 0 if the network prefixes represented by the struct prefix + * arguments are the same prefix, and 1 otherwise. Network prefixes + * are considered the same if the prefix lengths are equal and the + * network parts are the same. Host bits (which are considered masked + * by the prefix length) are not significant. Thus, 10.0.0.1/8 and + * 10.0.0.2/8 are considered equivalent by this routine. Note that + * this routine has the same return sense as strcmp (which is different + * from prefix_same). + */ int prefix_cmp (struct prefix *p1, struct prefix *p2) {
|