Merge pull request #11107 from opensourcerouting/prefix-more-unionizing

lib: `struct prefix` spring cleaning
This commit is contained in:
Donald Sharp 2022-04-28 08:25:30 -04:00 committed by GitHub
commit 8bb5f1db16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 27 deletions

View File

@ -158,7 +158,6 @@ Networking data types
- :c:struct:`prefix_ls` - :c:struct:`prefix_ls`
- :c:struct:`prefix_rd` - :c:struct:`prefix_rd`
- :c:struct:`prefix_ptr`
- :c:struct:`prefix_sg` (use :frrfmt:`%pPSG4`) - :c:struct:`prefix_sg` (use :frrfmt:`%pPSG4`)
- :c:union:`prefixptr` (dereference to get :c:struct:`prefix`) - :c:union:`prefixptr` (dereference to get :c:struct:`prefix`)
- :c:union:`prefixconstptr` (dereference to get :c:struct:`prefix`) - :c:union:`prefixconstptr` (dereference to get :c:struct:`prefix`)

View File

@ -177,8 +177,10 @@ const char *safi2str(safi_t safi)
} }
/* If n includes p prefix then return 1 else return 0. */ /* If n includes p prefix then return 1 else return 0. */
int prefix_match(const struct prefix *n, const struct prefix *p) int prefix_match(union prefixconstptr unet, union prefixconstptr upfx)
{ {
const struct prefix *n = unet.p;
const struct prefix *p = upfx.p;
int offset; int offset;
int shift; int shift;
const uint8_t *np, *pp; const uint8_t *np, *pp;
@ -274,9 +276,11 @@ int evpn_type5_prefix_match(const struct prefix *n, const struct prefix *p)
} }
/* If n includes p then return 1 else return 0. Prefix mask is not considered */ /* If n includes p then return 1 else return 0. Prefix mask is not considered */
int prefix_match_network_statement(const struct prefix *n, int prefix_match_network_statement(union prefixconstptr unet,
const struct prefix *p) union prefixconstptr upfx)
{ {
const struct prefix *n = unet.p;
const struct prefix *p = upfx.p;
int offset; int offset;
int shift; int shift;
const uint8_t *np, *pp; const uint8_t *np, *pp;
@ -472,8 +476,10 @@ int prefix_cmp(union prefixconstptr up1, union prefixconstptr up2)
* address families don't match, return -1; otherwise the return value is * address families don't match, return -1; otherwise the return value is
* in range 0 ... maximum prefix length for the address family. * in range 0 ... maximum prefix length for the address family.
*/ */
int prefix_common_bits(const struct prefix *p1, const struct prefix *p2) int prefix_common_bits(union prefixconstptr ua, union prefixconstptr ub)
{ {
const struct prefix *p1 = ua.p;
const struct prefix *p2 = ub.p;
int pos, bit; int pos, bit;
int length = 0; int length = 0;
uint8_t xor ; uint8_t xor ;
@ -509,8 +515,10 @@ int prefix_common_bits(const struct prefix *p1, const struct prefix *p2)
} }
/* Return prefix family type string. */ /* Return prefix family type string. */
const char *prefix_family_str(const struct prefix *p) const char *prefix_family_str(union prefixconstptr pu)
{ {
const struct prefix *p = pu.p;
if (p->family == AF_INET) if (p->family == AF_INET)
return "inet"; return "inet";
if (p->family == AF_INET6) if (p->family == AF_INET6)
@ -815,14 +823,16 @@ void apply_mask_ipv6(struct prefix_ipv6 *p)
} }
} }
void apply_mask(struct prefix *p) void apply_mask(union prefixptr pu)
{ {
struct prefix *p = pu.p;
switch (p->family) { switch (p->family) {
case AF_INET: case AF_INET:
apply_mask_ipv4((struct prefix_ipv4 *)p); apply_mask_ipv4(pu.p4);
break; break;
case AF_INET6: case AF_INET6:
apply_mask_ipv6((struct prefix_ipv6 *)p); apply_mask_ipv6(pu.p6);
break; break;
default: default:
break; break;
@ -868,8 +878,10 @@ void prefix2sockunion(const struct prefix *p, union sockunion *su)
sizeof(struct in6_addr)); sizeof(struct in6_addr));
} }
int prefix_blen(const struct prefix *p) int prefix_blen(union prefixconstptr pu)
{ {
const struct prefix *p = pu.p;
switch (p->family) { switch (p->family) {
case AF_INET: case AF_INET:
return IPV4_MAX_BYTELEN; return IPV4_MAX_BYTELEN;

View File

@ -287,13 +287,6 @@ static inline int is_evpn_prefix_ipaddr_v6(const struct prefix_evpn *evp)
return 0; return 0;
} }
/* Prefix for a generic pointer */
struct prefix_ptr {
uint8_t family;
uint16_t prefixlen;
uintptr_t prefix __attribute__((aligned(8)));
};
/* Prefix for a Flowspec entry */ /* Prefix for a Flowspec entry */
struct prefix_fs { struct prefix_fs {
uint8_t family; uint8_t family;
@ -442,8 +435,8 @@ extern void prefix_free(struct prefix **p);
* Function to handle prefix_free being used as a del function. * Function to handle prefix_free being used as a del function.
*/ */
extern void prefix_free_lists(void *arg); extern void prefix_free_lists(void *arg);
extern const char *prefix_family_str(const struct prefix *); extern const char *prefix_family_str(union prefixconstptr pu);
extern int prefix_blen(const struct prefix *); extern int prefix_blen(union prefixconstptr pu);
extern int str2prefix(const char *, struct prefix *); extern int str2prefix(const char *, struct prefix *);
#define PREFIX2STR_BUFFER PREFIX_STRLEN #define PREFIX2STR_BUFFER PREFIX_STRLEN
@ -454,14 +447,14 @@ extern const char *prefix_sg2str(const struct prefix_sg *sg, char *str);
extern const char *prefix2str(union prefixconstptr, char *, int); extern const char *prefix2str(union prefixconstptr, char *, int);
extern int evpn_type5_prefix_match(const struct prefix *evpn_pfx, extern int evpn_type5_prefix_match(const struct prefix *evpn_pfx,
const struct prefix *match_pfx); const struct prefix *match_pfx);
extern int prefix_match(const struct prefix *, const struct prefix *); extern int prefix_match(union prefixconstptr unet, union prefixconstptr upfx);
extern int prefix_match_network_statement(const struct prefix *, extern int prefix_match_network_statement(union prefixconstptr unet,
const struct prefix *); union prefixconstptr upfx);
extern int prefix_same(union prefixconstptr, union prefixconstptr); extern int prefix_same(union prefixconstptr ua, union prefixconstptr ub);
extern int prefix_cmp(union prefixconstptr, union prefixconstptr); extern int prefix_cmp(union prefixconstptr ua, union prefixconstptr ub);
extern int prefix_common_bits(const struct prefix *, const struct prefix *); extern int prefix_common_bits(union prefixconstptr ua, union prefixconstptr ub);
extern void prefix_copy(union prefixptr, union prefixconstptr); extern void prefix_copy(union prefixptr udst, union prefixconstptr usrc);
extern void apply_mask(struct prefix *); extern void apply_mask(union prefixptr pu);
#ifdef __clang_analyzer__ #ifdef __clang_analyzer__
/* clang-SA doesn't understand transparent unions, making it think that the /* clang-SA doesn't understand transparent unions, making it think that the