Skip to content

Commit

Permalink
lib: use some more transparent unions for prefixes
Browse files Browse the repository at this point in the history
... so we can pass prefix_ipv4/prefix_ipv6 in.

Signed-off-by: David Lamparter <[email protected]>
  • Loading branch information
eqvinox committed Jul 28, 2019
1 parent 1315d74 commit 9c3a217
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 11 additions & 3 deletions lib/prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,11 @@ int prefix_match_network_statement(const struct prefix *n,
return 1;
}

void prefix_copy(struct prefix *dest, const struct prefix *src)
void prefix_copy(union prefixptr udest, union prefixconstptr usrc)
{
struct prefix *dest = udest.p;
const struct prefix *src = usrc.p;

dest->family = src->family;
dest->prefixlen = src->prefixlen;

Expand Down Expand Up @@ -674,8 +677,11 @@ void prefix_copy(struct prefix *dest, const struct prefix *src)
* the same. Note that this routine has the same return value sense
* as '==' (which is different from prefix_cmp).
*/
int prefix_same(const struct prefix *p1, const struct prefix *p2)
int prefix_same(union prefixconstptr up1, union prefixconstptr up2)
{
const struct prefix *p1 = up1.p;
const struct prefix *p2 = up2.p;

if ((p1 && !p2) || (!p1 && p2))
return 0;

Expand Down Expand Up @@ -722,8 +728,10 @@ int prefix_same(const struct prefix *p1, const struct prefix *p2)
* this routine has the same return sense as strcmp (which is different
* from prefix_same).
*/
int prefix_cmp(const struct prefix *p1, const struct prefix *p2)
int prefix_cmp(union prefixconstptr up1, union prefixconstptr up2)
{
const struct prefix *p1 = up1.p;
const struct prefix *p2 = up2.p;
int offset;
int shift;
int i;
Expand Down
6 changes: 3 additions & 3 deletions lib/prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ extern const char *prefix2str(union prefixconstptr, char *, int);
extern int prefix_match(const struct prefix *, const struct prefix *);
extern int prefix_match_network_statement(const struct prefix *,
const struct prefix *);
extern int prefix_same(const struct prefix *, const struct prefix *);
extern int prefix_cmp(const struct prefix *, const struct prefix *);
extern int prefix_same(union prefixconstptr, union prefixconstptr);
extern int prefix_cmp(union prefixconstptr, union prefixconstptr);
extern int prefix_common_bits(const struct prefix *, const struct prefix *);
extern void prefix_copy(struct prefix *dest, const struct prefix *src);
extern void prefix_copy(union prefixptr, union prefixconstptr);
extern void apply_mask(struct prefix *);

extern struct prefix *sockunion2prefix(const union sockunion *dest,
Expand Down

0 comments on commit 9c3a217

Please sign in to comment.