Skip to content

Commit

Permalink
*: Replace IPV4_MAX_PREFIXLEN to IPV4_MAX_BITLEN
Browse files Browse the repository at this point in the history
Just drop IPV4_MAX_PREFIXLEN at all, no need keeping both.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
  • Loading branch information
ton31337 committed Jul 1, 2021
1 parent f4d81e5 commit 936fbae
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 53 deletions.
6 changes: 3 additions & 3 deletions bgpd/bgp_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static int bgp_md5_set_socket(int socket, union sockunion *su,
su2.sin6.sin6_port = 0;

/* For addresses, use the non-extended signature functionality */
if ((su2.sa.sa_family == AF_INET && prefixlen == IPV4_MAX_PREFIXLEN)
if ((su2.sa.sa_family == AF_INET && prefixlen == IPV4_MAX_BITLEN)
|| (su2.sa.sa_family == AF_INET6 && prefixlen == IPV6_MAX_BITLEN))
ret = sockopt_tcp_signature(socket, &su2, password);
else
Expand Down Expand Up @@ -163,7 +163,7 @@ static int bgp_md5_set_password(struct peer *peer, const char *password)
peer->su.sa.sa_family) {
uint16_t prefixlen =
peer->su.sa.sa_family == AF_INET
? IPV4_MAX_PREFIXLEN
? IPV4_MAX_BITLEN
: IPV6_MAX_BITLEN;

/*
Expand Down Expand Up @@ -744,7 +744,7 @@ int bgp_connect(struct peer *peer)

if (peer->password) {
uint16_t prefixlen = peer->su.sa.sa_family == AF_INET
? IPV4_MAX_PREFIXLEN
? IPV4_MAX_BITLEN
: IPV6_MAX_BITLEN;

bgp_md5_set_connect(peer->fd, &peer->su, prefixlen,
Expand Down
2 changes: 1 addition & 1 deletion ldpd/labelmapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *msg, char *buf,
map->fec.prefix.prefixlen = buf[off];
off += sizeof(uint8_t);
if ((map->fec.prefix.af == AF_IPV4
&& map->fec.prefix.prefixlen > IPV4_MAX_PREFIXLEN)
&& map->fec.prefix.prefixlen > IPV4_MAX_BITLEN)
|| (map->fec.prefix.af == AF_IPV6
&& map->fec.prefix.prefixlen > IPV6_MAX_BITLEN)) {
session_shutdown(nbr, S_BAD_TLV_VAL, msg->id,
Expand Down
17 changes: 9 additions & 8 deletions lib/prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ int str2prefix_ipv4(const char *str, struct prefix_ipv4 *p)

/* Get prefix length. */
plen = (uint8_t)atoi(++pnt);
if (plen > IPV4_MAX_PREFIXLEN)
if (plen > IPV4_MAX_BITLEN)
return 0;

p->family = AF_INET;
Expand Down Expand Up @@ -1128,7 +1128,7 @@ void apply_classful_mask_ipv4(struct prefix_ipv4 *p)

destination = ntohl(p->prefix.s_addr);

if (p->prefixlen == IPV4_MAX_PREFIXLEN)
if (p->prefixlen == IPV4_MAX_BITLEN)
;
/* do nothing for host routes */
else if (IN_CLASSC(destination)) {
Expand All @@ -1148,12 +1148,13 @@ in_addr_t ipv4_broadcast_addr(in_addr_t hostaddr, int masklen)
struct in_addr mask;

masklen2ip(masklen, &mask);
return (masklen != IPV4_MAX_PREFIXLEN - 1) ?
/* normal case */
(hostaddr | ~mask.s_addr)
:
/* For prefix 31 return 255.255.255.255 (RFC3021) */
htonl(0xFFFFFFFF);
return (masklen != IPV4_MAX_BITLEN - 1)
?
/* normal case */
(hostaddr | ~mask.s_addr)
:
/* For prefix 31 return 255.255.255.255 (RFC3021) */
htonl(0xFFFFFFFF);
}

/* Utility function to convert ipv4 netmask to prefixes
Expand Down
1 change: 0 additions & 1 deletion lib/prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ union prefixconstptr {
/* Max bit/byte length of IPv4 address. */
#define IPV4_MAX_BYTELEN 4
#define IPV4_MAX_BITLEN 32
#define IPV4_MAX_PREFIXLEN 32
#define IPV4_ADDR_CMP(D,S) memcmp ((D), (S), IPV4_MAX_BYTELEN)

static inline bool ipv4_addr_same(const struct in_addr *a,
Expand Down
2 changes: 1 addition & 1 deletion lib/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ struct route_node *route_node_match_ipv4(struct route_table *table,

memset(&p, 0, sizeof(struct prefix_ipv4));
p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
p.prefix = *addr;

return route_node_match(table, (struct prefix *)&p);
Expand Down
2 changes: 1 addition & 1 deletion lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api)
STREAM_GETC(s, api->prefix.prefixlen);
switch (api->prefix.family) {
case AF_INET:
if (api->prefix.prefixlen > IPV4_MAX_PREFIXLEN) {
if (api->prefix.prefixlen > IPV4_MAX_BITLEN) {
flog_err(
EC_LIB_ZAPI_ENCODE,
"%s: V4 prefixlen is %d which should not be more than 32",
Expand Down
2 changes: 1 addition & 1 deletion ospfd/ospf_asbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ bool is_valid_summary_addr(struct prefix_ipv4 *p)
return false;

/*Host route shouldn't be configured as summary addres*/
if (p->prefixlen == IPV4_MAX_PREFIXLEN)
if (p->prefixlen == IPV4_MAX_BITLEN)
return false;

return true;
Expand Down
12 changes: 6 additions & 6 deletions ospfd/ospf_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ struct ospf_interface *ospf_if_table_lookup(struct interface *ifp,
struct ospf_interface *rninfo = NULL;

p = *prefix;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;

/* route_node_get implicitely locks */
if ((rn = route_node_lookup(IF_OIFS(ifp), &p))) {
Expand All @@ -205,7 +205,7 @@ static void ospf_add_to_if(struct interface *ifp, struct ospf_interface *oi)
struct prefix p;

p = *oi->address;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
apply_mask(&p);

rn = route_node_get(IF_OIFS(ifp), &p);
Expand All @@ -223,7 +223,7 @@ static void ospf_delete_from_if(struct interface *ifp,
struct prefix p;

p = *oi->address;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;

rn = route_node_lookup(IF_OIFS(oi->ifp), &p);
assert(rn);
Expand Down Expand Up @@ -566,7 +566,7 @@ void ospf_free_if_params(struct interface *ifp, struct in_addr addr)
struct route_node *rn;

p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
p.prefix = addr;
rn = route_node_lookup(IF_OIFS_PARAMS(ifp), (struct prefix *)&p);
if (!rn || !rn->info)
Expand Down Expand Up @@ -601,7 +601,7 @@ struct ospf_if_params *ospf_lookup_if_params(struct interface *ifp,
struct route_node *rn;

p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
p.prefix = addr;

rn = route_node_lookup(IF_OIFS_PARAMS(ifp), (struct prefix *)&p);
Expand All @@ -621,7 +621,7 @@ struct ospf_if_params *ospf_get_if_params(struct interface *ifp,
struct route_node *rn;

p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
p.prefix = addr;
apply_mask_ipv4(&p);

Expand Down
12 changes: 6 additions & 6 deletions ospfd/ospf_te.c
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,7 @@ static void ospf_te_update_subnet(struct ls_ted *ted, struct ls_vertex *vertex,

/**
* Delete Subnet that correspond to the given IPv4 address and export deletion
* information before removal. Prefix length is fixed to IPV4_MAX_PREFIXLEN.
* information before removal. Prefix length is fixed to IPV4_MAX_BITLEN.
*
* @param ted Links State Database
* @param addr IPv4 address
Expand All @@ -1852,7 +1852,7 @@ static void ospf_te_delete_subnet(struct ls_ted *ted, struct in_addr addr)

/* Search subnet that correspond to the address/32 as prefix */
p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = addr;
subnet = ls_find_subnet(ted, p);

Expand Down Expand Up @@ -1944,15 +1944,15 @@ static int ospf_te_parse_router_lsa(struct ls_ted *ted, struct ospf_lsa *lsa)
ntohs(rl->link[i].metric));
/* Add corresponding subnet */
p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = rl->link[i].link_data;
metric = ntohs(rl->link[i].metric);
ospf_te_update_subnet(ted, vertex, p, metric);
break;
case LSA_LINK_TYPE_STUB:
/* Keep only /32 prefix */
p.prefixlen = ip_masklen(rl->link[i].link_data);
if (p.prefixlen == IPV4_MAX_PREFIXLEN) {
if (p.prefixlen == IPV4_MAX_BITLEN) {
p.family = AF_INET;
p.u.prefix4 = rl->link[i].link_id;
metric = ntohs(rl->link[i].metric);
Expand Down Expand Up @@ -2086,12 +2086,12 @@ static void ospf_te_update_remote_asbr(struct ls_ted *ted, struct ls_edge *edge)

/* Update corresponding Subnets */
p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = attr->standard.local;
ospf_te_update_subnet(ted, edge->source, p, attr->standard.te_metric);

p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = attr->standard.remote_addr;
ospf_te_update_subnet(ted, vertex, p, attr->standard.te_metric);

Expand Down
2 changes: 1 addition & 1 deletion ospfd/ospf_ti_lfa.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ void ospf_ti_lfa_generate_p_spaces(struct ospf_area *area,

stub_prefix.family = AF_INET;
child_prefix.family = AF_INET;
child_prefix.prefixlen = IPV4_MAX_PREFIXLEN;
child_prefix.prefixlen = IPV4_MAX_BITLEN;

p = ((uint8_t *)root->lsa) + OSPF_LSA_HEADER_SIZE + 4;
lim = ((uint8_t *)root->lsa) + ntohs(root->lsa->length);
Expand Down
2 changes: 1 addition & 1 deletion ospfd/ospf_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static int ospf_interface_address_delete(ZAPI_CALLBACK_ARGS)

ifp = c->ifp;
p = *c->address;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;

rn = route_node_lookup(IF_OIFS(ifp), &p);
if (!rn) {
Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp,

p.family = AF_INET;
p.u.prefix4 = addr;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;

for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode,
neigh)) {
Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_ifchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ int pim_ifchannel_local_membership_add(struct interface *ifp,
AFI_IP, pim->spt.plist);
struct prefix g;
g.family = AF_INET;
g.prefixlen = IPV4_MAX_PREFIXLEN;
g.prefixlen = IPV4_MAX_BITLEN;
g.u.prefix4 = up->sg.grp;

if (prefix_list_apply(plist, &g)
Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ int pim_register_recv(struct interface *ifp, struct in_addr dest_addr,
plist = prefix_list_lookup(AFI_IP, pim->register_plist);

src.family = AF_INET;
src.prefixlen = IPV4_MAX_PREFIXLEN;
src.prefixlen = IPV4_MAX_BITLEN;
src.u.prefix4 = sg.src;

if (prefix_list_apply(plist, &src) == PREFIX_DENY) {
Expand Down
4 changes: 2 additions & 2 deletions pimd/pim_rp.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void pim_rp_init(struct pim_instance *pim)
}
rp_info->group.family = AF_INET;
rp_info->rp.rpf_addr.family = AF_INET;
rp_info->rp.rpf_addr.prefixlen = IPV4_MAX_PREFIXLEN;
rp_info->rp.rpf_addr.prefixlen = IPV4_MAX_BITLEN;
rp_info->rp.rpf_addr.u.prefix4.s_addr = INADDR_NONE;

listnode_add(pim->rp_list, rp_info);
Expand Down Expand Up @@ -417,7 +417,7 @@ int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr,
rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info));

rp_info->rp.rpf_addr.family = AF_INET;
rp_info->rp.rpf_addr.prefixlen = IPV4_MAX_PREFIXLEN;
rp_info->rp.rpf_addr.prefixlen = IPV4_MAX_BITLEN;
rp_info->rp.rpf_addr.u.prefix4 = rp_addr;
prefix_copy(&rp_info->group, &group);
rp_info->rp_src = rp_src_flag;
Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ int pim_parse_addr_ucast(struct prefix *p, const uint8_t *buf, int buf_size)
p->family = AF_INET; /* notice: AF_INET !=
PIM_MSG_ADDRESS_FAMILY_IPV4 */
memcpy(&p->u.prefix4, addr, sizeof(struct in_addr));
p->prefixlen = IPV4_MAX_PREFIXLEN;
p->prefixlen = IPV4_MAX_BITLEN;
addr += sizeof(struct in_addr);

break;
Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@ void pim_upstream_remove_lhr_star_pimreg(struct pim_instance *pim,
np = prefix_list_lookup(AFI_IP, nlist);

g.family = AF_INET;
g.prefixlen = IPV4_MAX_PREFIXLEN;
g.prefixlen = IPV4_MAX_BITLEN;

frr_each (rb_pim_upstream, &pim->upstream_head, up) {
if (up->sg.src.s_addr != INADDR_ANY)
Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int pim_is_group_224_0_0_0_24(struct in_addr group_addr)

group.family = AF_INET;
group.u.prefix4 = group_addr;
group.prefixlen = IPV4_MAX_PREFIXLEN;
group.prefixlen = IPV4_MAX_BITLEN;

return prefix_match(&group_224, &group);
}
Expand Down
2 changes: 1 addition & 1 deletion ripd/rip_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static void rip_request_interface_send(struct interface *ifp, uint8_t version)
* destination addr */
to.sin_addr = connected->destination->u.prefix4;
else if (connected->address->prefixlen
< IPV4_MAX_PREFIXLEN)
< IPV4_MAX_BITLEN)
/* calculate the appropriate broadcast
* address */
to.sin_addr.s_addr = ipv4_broadcast_addr(
Expand Down
2 changes: 1 addition & 1 deletion ripd/ripd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,7 @@ static void rip_update_interface(struct connected *ifc, uint8_t version,
/* use specified broadcast or peer destination
* addr */
to.sin_addr = ifc->destination->u.prefix4;
else if (ifc->address->prefixlen < IPV4_MAX_PREFIXLEN)
else if (ifc->address->prefixlen < IPV4_MAX_BITLEN)
/* calculate the appropriate broadcast address
*/
to.sin_addr.s_addr = ipv4_broadcast_addr(
Expand Down
11 changes: 5 additions & 6 deletions zebra/connected.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ void connected_add_ipv4(struct interface *ifp, int flags, struct in_addr *addr,
p = prefix_ipv4_new();
p->family = AF_INET;
p->prefix = *addr;
p->prefixlen = CHECK_FLAG(flags, ZEBRA_IFA_PEER) ? IPV4_MAX_PREFIXLEN
: prefixlen;
p->prefixlen =
CHECK_FLAG(flags, ZEBRA_IFA_PEER) ? IPV4_MAX_BITLEN : prefixlen;
ifc->address = (struct prefix *)p;

/* If there is a peer address. */
Expand All @@ -358,8 +358,7 @@ void connected_add_ipv4(struct interface *ifp, int flags, struct in_addr *addr,
}

/* no destination address was supplied */
if (!dest && (prefixlen == IPV4_MAX_PREFIXLEN)
&& if_is_pointopoint(ifp))
if (!dest && (prefixlen == IPV4_MAX_BITLEN) && if_is_pointopoint(ifp))
zlog_debug(
"PtP interface %s with addr %pI4/%d needs a peer address",
ifp->name, addr, prefixlen);
Expand Down Expand Up @@ -512,8 +511,8 @@ void connected_delete_ipv4(struct interface *ifp, int flags,
memset(&p, 0, sizeof(struct prefix));
p.family = AF_INET;
p.u.prefix4 = *addr;
p.prefixlen = CHECK_FLAG(flags, ZEBRA_IFA_PEER) ? IPV4_MAX_PREFIXLEN
: prefixlen;
p.prefixlen =
CHECK_FLAG(flags, ZEBRA_IFA_PEER) ? IPV4_MAX_BITLEN : prefixlen;

if (dest) {
memset(&d, 0, sizeof(struct prefix));
Expand Down
2 changes: 1 addition & 1 deletion zebra/kernel_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ void rtm_read(struct rt_msghdr *rtm)
p.family = AF_INET;
p.u.prefix4 = dest.sin.sin_addr;
if (flags & RTF_HOST)
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
else
p.prefixlen = ip_masklen(mask.sin.sin_addr);

Expand Down
3 changes: 1 addition & 2 deletions zebra/zebra_dplane.c
Original file line number Diff line number Diff line change
Expand Up @@ -2537,8 +2537,7 @@ static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx,
*/
memcpy(&p.u, &pw->nexthop, sizeof(pw->nexthop));
p.family = pw->af;
p.prefixlen =
((pw->af == AF_INET) ? IPV4_MAX_PREFIXLEN : IPV6_MAX_BITLEN);
p.prefixlen = ((pw->af == AF_INET) ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN);

afi = (pw->af == AF_INET) ? AFI_IP : AFI_IP6;
table = zebra_vrf_table(afi, SAFI_UNICAST, pw->vrf_id);
Expand Down
2 changes: 1 addition & 1 deletion zebra/zebra_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ static int nhlfe_nexthop_active_ipv4(zebra_nhlfe_t *nhlfe,
/* Lookup nexthop in IPv4 routing table. */
memset(&p, 0, sizeof(struct prefix_ipv4));
p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
p.prefix = nexthop->gate.ipv4;

rn = route_node_match(table, (struct prefix *)&p);
Expand Down
2 changes: 1 addition & 1 deletion zebra/zebra_nhg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe,
switch (afi) {
case AFI_IP:
p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefixlen = IPV4_MAX_BITLEN;
p.u.prefix4 = *ipv4;
break;
case AFI_IP6:
Expand Down
2 changes: 1 addition & 1 deletion zebra/zebra_pbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ static const char *zebra_pbr_prefix2str(union prefixconstptr pu,
const struct prefix *p = pu.p;
char buf[PREFIX2STR_BUFFER];

if ((p->family == AF_INET && p->prefixlen == IPV4_MAX_PREFIXLEN)
if ((p->family == AF_INET && p->prefixlen == IPV4_MAX_BITLEN)
|| (p->family == AF_INET6 && p->prefixlen == IPV6_MAX_BITLEN)) {
snprintf(str, size, "%s", inet_ntop(p->family, &p->u.prefix,
buf, PREFIX2STR_BUFFER));
Expand Down
Loading

0 comments on commit 936fbae

Please sign in to comment.