Skip to content

Commit

Permalink
*: Convert numeric 128 into IPV6_MAX_BITLEN for prefixlen
Browse files Browse the repository at this point in the history
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
  • Loading branch information
ton31337 committed Jul 1, 2021
1 parent 936fbae commit 13ccce6
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 37 deletions.
2 changes: 1 addition & 1 deletion bgpd/bgp_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
}

if ((afi == AFI_IP && p.prefixlen > 32)
|| (afi == AFI_IP6 && p.prefixlen > 128))
|| (afi == AFI_IP6 && p.prefixlen > IPV6_MAX_BITLEN))
return BGP_NLRI_PARSE_ERROR_PREFIX_LENGTH;

/* Fetch prefix from NLRI packet */
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
case AF_INET6:
/* save */
nexthop_orig.u.prefix6 = path_vpn->attr->mp_nexthop_global;
nexthop_orig.prefixlen = 128;
nexthop_orig.prefixlen = IPV6_MAX_BITLEN;

if (CHECK_FLAG(bgp_vrf->af_flags[afi][safi],
BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
Expand Down
4 changes: 2 additions & 2 deletions bgpd/rfapi/rfapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ rfapi_query_inner(void *handle, struct rfapi_ip_addr *target,
if (target->addr_family == AF_INET) {
rprefix.length = 32;
} else {
rprefix.length = 128;
rprefix.length = IPV6_MAX_BITLEN;
}

pNHE = rfapiEthRouteTable2NextHopList(
Expand Down Expand Up @@ -1692,7 +1692,7 @@ rfapi_query_inner(void *handle, struct rfapi_ip_addr *target,
if (target->addr_family == AF_INET) {
rprefix.length = 32;
} else {
rprefix.length = 128;
rprefix.length = IPV6_MAX_BITLEN;
}

pNHE = rfapiEthRouteNode2NextHopList(
Expand Down
2 changes: 1 addition & 1 deletion bgpd/rfapi/rfapi_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ struct rfapi {
(((prefix)->family == AF_INET) \
? ((prefix)->prefixlen == 32) \
: (((prefix)->family == AF_INET6) \
? ((prefix)->prefixlen == 128) \
? ((prefix)->prefixlen == IPV6_MAX_BITLEN) \
: 0))

extern int rfapi_find_rfd(struct bgp *bgp, struct rfapi_ip_addr *vn_addr,
Expand Down
4 changes: 2 additions & 2 deletions bgpd/rfapi/rfapi_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int rfapiQprefix2Raddr(struct prefix *qprefix, struct rfapi_ip_addr *raddr)
raddr->addr.v4 = qprefix->u.prefix4;
break;
case AF_INET6:
if (qprefix->prefixlen != 128)
if (qprefix->prefixlen != IPV6_MAX_BITLEN)
return -1;
raddr->addr.v6 = qprefix->u.prefix6;
break;
Expand Down Expand Up @@ -1741,7 +1741,7 @@ int rfapiCliGetPrefixAddr(struct vty *vty, const char *str, struct prefix *p)
}
break;
case AF_INET6:
if (p->prefixlen != 128) {
if (p->prefixlen != IPV6_MAX_BITLEN) {
vty_out(vty, "Not a host address: \"%s\"%s", str,
HVTYNL);
return CMD_WARNING;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/rfapi/vnc_export_bgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ encap_attr_export(struct attr *new, struct attr *orig,
orig_nexthop.prefixlen = 32;
orig_nexthop.u.prefix4 = orig->mp_nexthop_global_in;
} else if (orig_nexthop.family == AF_INET6) {
orig_nexthop.prefixlen = 128;
orig_nexthop.prefixlen = IPV6_MAX_BITLEN;
orig_nexthop.u.prefix6 = orig->mp_nexthop_global;
} else {
return -1; /* FAIL - can't compute nexthop */
Expand Down
6 changes: 3 additions & 3 deletions bgpd/rfapi/vnc_import_bgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static int is_host_prefix(const struct prefix *p)
case AF_INET:
return (p->prefixlen == 32);
case AF_INET6:
return (p->prefixlen == 128);
return (p->prefixlen == IPV6_MAX_BITLEN);
}
return 0;
}
Expand Down Expand Up @@ -1083,7 +1083,7 @@ static void vnc_import_bgp_del_route_mode_plain(struct bgp *bgp,
break;

case AF_INET6:
if (vn_pfx->prefixlen != 128) {
if (vn_pfx->prefixlen != IPV6_MAX_BITLEN) {
vnc_zlog_debug_verbose(
"%s: redist VN plen (%d) != 128, skipping",
__func__, vn_pfx->prefixlen);
Expand Down Expand Up @@ -1157,7 +1157,7 @@ static void vnc_import_bgp_del_route_mode_nvegroup(struct bgp *bgp,
break;

case AF_INET6:
if (vn_pfx->prefixlen != 128) {
if (vn_pfx->prefixlen != IPV6_MAX_BITLEN) {
vnc_zlog_debug_verbose(
"%s: redist VN plen (%d) != 128, skipping",
__func__, vn_pfx->prefixlen);
Expand Down
5 changes: 3 additions & 2 deletions bgpd/rfapi/vnc_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ static void vnc_redistribute_add(struct prefix *p, uint32_t metric,
bgp->rfapi_cfg->rfg_redist->vn_prefix.u.prefix4;
break;
case AF_INET6:
if (bgp->rfapi_cfg->rfg_redist->vn_prefix.prefixlen != 128) {
if (bgp->rfapi_cfg->rfg_redist->vn_prefix.prefixlen
!= IPV6_MAX_BITLEN) {
vnc_zlog_debug_verbose(
"%s: redist nve group VN prefix len (%d) != 128, skipping",
__func__,
Expand Down Expand Up @@ -161,7 +162,7 @@ static void vnc_redistribute_add(struct prefix *p, uint32_t metric,
}
break;
case AF_INET6:
if (pfx_un.length != 128) {
if (pfx_un.length != IPV6_MAX_BITLEN) {
vnc_zlog_debug_verbose(
"%s: redist nve group UN prefix len (%d) != 128, skipping",
__func__, pfx_un.length);
Expand Down
2 changes: 1 addition & 1 deletion isisd/isis_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ isis_route_info_new(struct prefix *prefix, struct prefix_ipv6 *src_p,
adj->router_address = prefix->u.prefix4;
break;
case AF_INET6:
if (depth == 2 && prefix->prefixlen == 128
if (depth == 2 && prefix->prefixlen == IPV6_MAX_BITLEN
&& (!src_p || !src_p->prefixlen)) {
adj->router_address6 = prefix->u.prefix6;
}
Expand Down
4 changes: 2 additions & 2 deletions isisd/isis_tlvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ static int unpack_subtlv_ipv6_source_prefix(enum isis_tlv_context context,
}

p.prefixlen = stream_getc(s);
if (p.prefixlen > 128) {
if (p.prefixlen > IPV6_MAX_BITLEN) {
sbuf_push(log, indent, "Prefixlen %u is implausible for IPv6\n",
p.prefixlen);
return 1;
Expand Down Expand Up @@ -2542,7 +2542,7 @@ static int unpack_item_ipv6_reach(uint16_t mtid, uint8_t len, struct stream *s,

rv->prefix.family = AF_INET6;
rv->prefix.prefixlen = stream_getc(s);
if (rv->prefix.prefixlen > 128) {
if (rv->prefix.prefixlen > IPV6_MAX_BITLEN) {
sbuf_push(log, indent, "Prefixlen %u is implausible for IPv6\n",
rv->prefix.prefixlen);
goto out;
Expand Down
4 changes: 2 additions & 2 deletions ldpd/lde.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,8 @@ lde_update_label(struct fec_node *fn)
return (NO_LABEL);
break;
case FEC_TYPE_IPV6:
if ((ldeconf->ipv6.flags & F_LDPD_AF_ALLOCHOSTONLY) &&
fn->fec.u.ipv6.prefixlen != 128)
if ((ldeconf->ipv6.flags & F_LDPD_AF_ALLOCHOSTONLY)
&& fn->fec.u.ipv6.prefixlen != IPV6_MAX_BITLEN)
return (NO_LABEL);
if (lde_acl_check(ldeconf->ipv6.acl_label_allocate_for,
AF_INET6, (union ldpd_addr *)&fn->fec.u.ipv6.prefix,
Expand Down
2 changes: 1 addition & 1 deletion ldpd/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ ldp_prefixcmp(int af, const union ldpd_addr *a, const union ldpd_addr *b,
case AF_INET6:
if (prefixlen == 0)
return (0);
if (prefixlen > 128)
if (prefixlen > IPV6_MAX_BITLEN)
fatalx("ldp_prefixcmp: bad IPv6 prefixlen");
for (i = 0; i < prefixlen / 8; i++)
if (a->v6.s6_addr[i] != b->v6.s6_addr[i])
Expand Down
2 changes: 1 addition & 1 deletion lib/command_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ static enum match_type match_ipv6_prefix(const char *str, bool prefix)
if (*endptr != '\0')
return no_match;

if (mask < 0 || mask > 128)
if (mask < 0 || mask > IPV6_MAX_BITLEN)
return no_match;

return exact_match;
Expand Down
2 changes: 1 addition & 1 deletion lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ enum zclient_send_status zclient_send_localsid(struct zclient *zclient,
struct nexthop nh = {};

p.family = AF_INET6;
p.prefixlen = 128;
p.prefixlen = IPV6_MAX_BITLEN;
p.prefix = *sid;

api.vrf_id = VRF_DEFAULT;
Expand Down
2 changes: 1 addition & 1 deletion pbrd/pbr_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ void pbr_send_rnh(struct nexthop *nhop, bool reg)
case NEXTHOP_TYPE_IPV6_IFINDEX:
p.family = AF_INET6;
memcpy(&p.u.prefix6, &nhop->gate.ipv6, 16);
p.prefixlen = 128;
p.prefixlen = IPV6_MAX_BITLEN;
if (IN6_IS_ADDR_LINKLOCAL(&nhop->gate.ipv6))
/*
* Don't bother tracking link locals, just track their
Expand Down
2 changes: 1 addition & 1 deletion ripngd/ripngd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ static void ripng_response_process(struct ripng_packet *packet, int size,

/* - is the prefix length valid (i.e., between 0 and 128,
inclusive) */
if (rte->prefixlen > 128) {
if (rte->prefixlen > IPV6_MAX_BITLEN) {
zlog_warn("Invalid prefix length %pI6/%d from %pI6%%%s",
&rte->addr, rte->prefixlen,
&from->sin6_addr, ifp->name);
Expand Down
8 changes: 4 additions & 4 deletions sharpd/sharp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,

if (n) {
type_import = false;
p.prefixlen = 128;
p.prefixlen = IPV6_MAX_BITLEN;
memcpy(&p.u.prefix6, &nhop, 16);
p.family = AF_INET6;
} else {
Expand Down Expand Up @@ -243,7 +243,7 @@ DEFPY (install_routes,
prefix.u.prefix4 = start4;
} else {
prefix.family = AF_INET6;
prefix.prefixlen = 128;
prefix.prefixlen = IPV6_MAX_BITLEN;
prefix.u.prefix6 = start6;
}
sg.r.orig_prefix = prefix;
Expand Down Expand Up @@ -387,7 +387,7 @@ DEFPY (install_seg6_routes,
prefix.u.prefix4 = start4;
} else {
prefix.family = AF_INET6;
prefix.prefixlen = 128;
prefix.prefixlen = IPV6_MAX_BITLEN;
prefix.u.prefix6 = start6;
}
sg.r.orig_prefix = prefix;
Expand Down Expand Up @@ -572,7 +572,7 @@ DEFPY (remove_routes,
prefix.u.prefix4 = start4;
} else {
prefix.family = AF_INET6;
prefix.prefixlen = 128;
prefix.prefixlen = IPV6_MAX_BITLEN;
prefix.u.prefix6 = start6;
}

Expand Down
8 changes: 4 additions & 4 deletions zebra/router-id.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int router_id_get(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
case AFI_IP6:
p->u.prefix6 = in6addr_any;
p->family = AF_INET6;
p->prefixlen = 128;
p->prefixlen = IPV6_MAX_BITLEN;
if (!router_id_v6_is_any(&zvrf->rid6_user_assigned))
addr = &zvrf->rid6_user_assigned.u.prefix6;
else if (!list_isempty(zvrf->rid6_lo_sorted_list)) {
Expand Down Expand Up @@ -313,7 +313,7 @@ DEFUN (ipv6_router_id,
if (!inet_pton(AF_INET6, argv[idx]->arg, &rid.u.prefix6))
return CMD_WARNING_CONFIG_FAILED;

rid.prefixlen = 128;
rid.prefixlen = IPV6_MAX_BITLEN;
rid.family = AF_INET6;

argv_find(argv, argc, "NAME", &idx);
Expand Down Expand Up @@ -372,7 +372,7 @@ DEFUN (ipv6_router_id_in_vrf,
if (!inet_pton(AF_INET6, argv[idx]->arg, &rid.u.prefix6))
return CMD_WARNING_CONFIG_FAILED;

rid.prefixlen = 128;
rid.prefixlen = IPV6_MAX_BITLEN;
rid.family = AF_INET6;

router_id_set(AFI_IP6, &rid, zvrf);
Expand Down Expand Up @@ -601,5 +601,5 @@ void router_id_init(struct zebra_vrf *zvrf)
zvrf->rid_user_assigned.family = AF_INET;
zvrf->rid_user_assigned.prefixlen = 32;
zvrf->rid6_user_assigned.family = AF_INET6;
zvrf->rid6_user_assigned.prefixlen = 128;
zvrf->rid6_user_assigned.prefixlen = IPV6_MAX_BITLEN;
}
14 changes: 8 additions & 6 deletions zebra/zebra_nhg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2048,11 +2048,12 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe,
return 1;
}

if (top &&
((top->family == AF_INET && top->prefixlen == 32
&& nexthop->gate.ipv4.s_addr == top->u.prefix4.s_addr)
|| (top->family == AF_INET6 && top->prefixlen == 128
&& memcmp(&nexthop->gate.ipv6, &top->u.prefix6, 16) == 0))) {
if (top
&& ((top->family == AF_INET && top->prefixlen == 32
&& nexthop->gate.ipv4.s_addr == top->u.prefix4.s_addr)
|| (top->family == AF_INET6 && top->prefixlen == IPV6_MAX_BITLEN
&& memcmp(&nexthop->gate.ipv6, &top->u.prefix6, 16)
== 0))) {
if (IS_ZEBRA_DEBUG_RIB_DETAILED)
zlog_debug(
" :%s: Attempting to install a max prefixlength route through itself",
Expand Down Expand Up @@ -2151,7 +2152,8 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe,
*/
if (prefix_same(&rn->p, top))
if (((afi == AFI_IP) && (rn->p.prefixlen != 32))
|| ((afi == AFI_IP6) && (rn->p.prefixlen != 128))) {
|| ((afi == AFI_IP6)
&& (rn->p.prefixlen != IPV6_MAX_BITLEN))) {
if (IS_ZEBRA_DEBUG_RIB_DETAILED)
zlog_debug(
" %s: Matched against ourself and prefix length is not max bit length",
Expand Down

0 comments on commit 13ccce6

Please sign in to comment.