Skip to content

Commit

Permalink
*: Replace s_addr 0 => INADDR_ANY
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 Feb 6, 2020
1 parent 85c58de commit 975a328
Show file tree
Hide file tree
Showing 44 changed files with 182 additions and 157 deletions.
2 changes: 1 addition & 1 deletion bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,7 @@ int bgp_mp_reach_parse(struct bgp_attr_parser_args *args,
case BGP_ATTR_NHLEN_IPV4:
stream_get(&attr->mp_nexthop_global_in, s, IPV4_MAX_BYTELEN);
/* Probably needed for RFC 2283 */
if (attr->nexthop.s_addr == 0)
if (attr->nexthop.s_addr == INADDR_ANY)
memcpy(&attr->nexthop.s_addr,
&attr->mp_nexthop_global_in, IPV4_MAX_BYTELEN);
break;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_evpn_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ static void show_vni_routes(struct bgp *bgp, struct bgpevpn *vpn, int type,
for (; pi; pi = pi->next) {
json_object *json_path = NULL;

if (vtep_ip.s_addr
if (vtep_ip.s_addr != INADDR_ANY
&& !IPV4_ADDR_SAME(&(vtep_ip),
&(pi->attr->nexthop)))
continue;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_flowspec_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ int bgp_flowspec_match_rules_fill(uint8_t *nlri_content, int len,
* ignore that rule
*/
if (prefix->family == AF_INET
&& prefix->u.prefix4.s_addr == 0)
&& prefix->u.prefix4.s_addr == INADDR_ANY)
bpem->match_bitmask_iprule |= bitmask;
else
bpem->match_bitmask |= bitmask;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ int bgp_start(struct peer *peer)
}

/* Clear remote router-id. */
peer->remote_id.s_addr = 0;
peer->remote_id.s_addr = INADDR_ANY;

/* Clear peer capability flag. */
peer->cap = 0;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_mpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best,
}

/* Zap multipath attr nexthop so we set nexthop to self */
attr.nexthop.s_addr = 0;
attr.nexthop.s_addr = INADDR_ANY;
memset(&attr.mp_nexthop_global, 0, sizeof(struct in6_addr));

/* TODO: should we set ATOMIC_AGGREGATE and AGGREGATOR? */
Expand Down
5 changes: 3 additions & 2 deletions bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size)
}

/* remote router-id check. */
if (remote_id.s_addr == 0 || IPV4_CLASS_DE(ntohl(remote_id.s_addr))
if (remote_id.s_addr == INADDR_ANY
|| IPV4_CLASS_DE(ntohl(remote_id.s_addr))
|| ntohl(peer->local_id.s_addr) == ntohl(remote_id.s_addr)) {
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s bad OPEN, wrong router identifier %s",
Expand Down Expand Up @@ -1354,7 +1355,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size)
|| peer->afc_nego[AFI_IP][SAFI_MULTICAST]
|| peer->afc_nego[AFI_IP][SAFI_MPLS_VPN]
|| peer->afc_nego[AFI_IP][SAFI_ENCAP]) {
if (!peer->nexthop.v4.s_addr) {
if (peer->nexthop.v4.s_addr == INADDR_ANY) {
#if defined(HAVE_CUMULUS)
flog_err(
EC_BGP_SND_FAIL,
Expand Down
12 changes: 7 additions & 5 deletions bgpd/bgp_pbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,15 @@ int bgp_pbr_build_and_validate_entry(struct prefix *p,
* draft-ietf-idr-flowspec-redirect
*/
if (api_action_redirect_ip) {
if (api_action_redirect_ip->u
.zr.redirect_ip_v4.s_addr)
if (api_action_redirect_ip->u.zr
.redirect_ip_v4.s_addr
!= INADDR_ANY)
continue;
if (!path->attr->nexthop.s_addr)
if (path->attr->nexthop.s_addr
== INADDR_ANY)
continue;
api_action_redirect_ip->u
.zr.redirect_ip_v4.s_addr =
api_action_redirect_ip->u.zr
.redirect_ip_v4.s_addr =
path->attr->nexthop.s_addr;
api_action_redirect_ip->u.zr.duplicate
= ecom_eval->val[7];
Expand Down
25 changes: 12 additions & 13 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -1535,8 +1535,8 @@ void bgp_attr_add_gshut_community(struct attr *attr)
static void subgroup_announce_reset_nhop(uint8_t family, struct attr *attr)
{
if (family == AF_INET) {
attr->nexthop.s_addr = 0;
attr->mp_nexthop_global_in.s_addr = 0;
attr->nexthop.s_addr = INADDR_ANY;
attr->mp_nexthop_global_in.s_addr = INADDR_ANY;
}
if (family == AF_INET6)
memset(&attr->mp_nexthop_global, 0, IPV6_MAX_BYTELEN);
Expand Down Expand Up @@ -3200,10 +3200,9 @@ static int bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi,

/* If NEXT_HOP is present, validate it. */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) {
if (attr->nexthop.s_addr == 0
if (attr->nexthop.s_addr == INADDR_ANY
|| IPV4_CLASS_DE(ntohl(attr->nexthop.s_addr))
|| bgp_nexthop_self(bgp, afi, type, stype,
attr, rn))
|| bgp_nexthop_self(bgp, afi, type, stype, attr, rn))
return 1;
}

Expand All @@ -3216,11 +3215,11 @@ static int bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi,
switch (attr->mp_nexthop_len) {
case BGP_ATTR_NHLEN_IPV4:
case BGP_ATTR_NHLEN_VPNV4:
ret = (attr->mp_nexthop_global_in.s_addr == 0
|| IPV4_CLASS_DE(ntohl(
attr->mp_nexthop_global_in.s_addr))
|| bgp_nexthop_self(bgp, afi, type, stype,
attr, rn));
ret = (attr->mp_nexthop_global_in.s_addr == INADDR_ANY
|| IPV4_CLASS_DE(
ntohl(attr->mp_nexthop_global_in.s_addr))
|| bgp_nexthop_self(bgp, afi, type, stype, attr,
rn));
break;

case BGP_ATTR_NHLEN_IPV6_GLOBAL:
Expand Down Expand Up @@ -5475,7 +5474,7 @@ static int bgp_static_set(struct vty *vty, const char *negate,
bgp_static->backdoor = backdoor;
bgp_static->valid = 0;
bgp_static->igpmetric = 0;
bgp_static->igpnexthop.s_addr = 0;
bgp_static->igpnexthop.s_addr = INADDR_ANY;
bgp_static->label_index = label_index;

if (rmap) {
Expand Down Expand Up @@ -5766,7 +5765,7 @@ int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty,
bgp_static->backdoor = 0;
bgp_static->valid = 0;
bgp_static->igpmetric = 0;
bgp_static->igpnexthop.s_addr = 0;
bgp_static->igpnexthop.s_addr = INADDR_ANY;
bgp_static->label = label;
bgp_static->prd = prd;

Expand Down Expand Up @@ -7540,7 +7539,7 @@ void route_vty_out(struct vty *vty, struct prefix *p,
: inet_ntoa(attr->nexthop),
vrf_id_str);
} else if (safi == SAFI_FLOWSPEC) {
if (attr->nexthop.s_addr != 0) {
if (attr->nexthop.s_addr != INADDR_ANY) {
if (json_paths) {
json_nexthop_global = json_object_new_object();

Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_routemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,7 @@ route_set_ip_nexthop(void *rule, const struct prefix *prefix,
*/
SET_FLAG(path->attr->rmap_change_flags,
BATTR_RMAP_NEXTHOP_PEER_ADDRESS);
path->attr->nexthop.s_addr = 0;
path->attr->nexthop.s_addr = INADDR_ANY;
}
} else {
/* Set next hop value. */
Expand Down
4 changes: 2 additions & 2 deletions bgpd/bgp_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[],

oid2in_addr(offset, len, &paddr);
} else
paddr.s_addr = 0;
paddr.s_addr = INADDR_ANY;

if (!rn)
return NULL;
Expand Down Expand Up @@ -804,7 +804,7 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[],
return min;
}

paddr.s_addr = 0;
paddr.s_addr = INADDR_ANY;
} while ((rn = bgp_route_next(rn)) != NULL);
}
return NULL;
Expand Down
14 changes: 7 additions & 7 deletions bgpd/bgp_updgrp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,16 +467,16 @@ struct stream *bpacket_reformat_for_peer(struct bpacket *pkt,
mod_v4nh = &peer->nexthop.v4;
nh_modified = 1;
}
} else if (!v4nh.s_addr) {
} else if (v4nh.s_addr == INADDR_ANY) {
mod_v4nh = &peer->nexthop.v4;
nh_modified = 1;
} else if (
peer->sort == BGP_PEER_EBGP
&& (bgp_multiaccess_check_v4(v4nh, peer) == 0)
&& !CHECK_FLAG(
} else if (peer->sort == BGP_PEER_EBGP
&& (bgp_multiaccess_check_v4(v4nh, peer)
== 0)
&& !CHECK_FLAG(
vec->flags,
BPKT_ATTRVEC_FLAGS_RMAP_NH_UNCHANGED)
&& !peer_af_flag_check(
&& !peer_af_flag_check(
peer, paf->afi, paf->safi,
PEER_FLAG_NEXTHOP_UNCHANGED)) {
/* NOTE: not handling case where NH has new AFI
Expand Down Expand Up @@ -628,7 +628,7 @@ struct stream *bpacket_reformat_for_peer(struct bpacket *pkt,
mod_v4nh = &v4nh;

/* No route-map changes allowed for EVPN nexthops. */
if (!v4nh.s_addr) {
if (v4nh.s_addr == INADDR_ANY) {
mod_v4nh = &peer->nexthop.v4;
nh_modified = 1;
}
Expand Down
7 changes: 4 additions & 3 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote,

/* IPv4 nexthop. */
ret = if_get_ipv4_address(ifp, &nexthop->v4);
if (!ret && peer->local_id.s_addr)
if (!ret && peer->local_id.s_addr != INADDR_ANY)
nexthop->v4 = peer->local_id;

/* Global address*/
Expand Down Expand Up @@ -2548,7 +2548,8 @@ static int bgp_zebra_process_local_vni(ZAPI_CALLBACK_ARGS)

if (cmd == ZEBRA_VNI_ADD)
return bgp_evpn_local_vni_add(
bgp, vni, vtep_ip.s_addr ? vtep_ip : bgp->router_id,
bgp, vni,
vtep_ip.s_addr != INADDR_ANY ? vtep_ip : bgp->router_id,
tenant_vrf_id, mcast_grp);
else
return bgp_evpn_local_vni_del(bgp, vni);
Expand Down Expand Up @@ -2975,7 +2976,7 @@ void bgp_zebra_announce_default(struct bgp *bgp, struct nexthop *nh,
SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);

/* redirect IP */
if (nh->gate.ipv4.s_addr) {
if (nh->gate.ipv4.s_addr != INADDR_ANY) {
char buff[PREFIX_STRLEN];

api_nh->vrf_id = nh->vrf_id;
Expand Down
3 changes: 2 additions & 1 deletion bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ void bgp_router_id_zebra_bump(vrf_id_t vrf_id, const struct prefix *router_id)
int bgp_router_id_static_set(struct bgp *bgp, struct in_addr id)
{
bgp->router_id_static = id;
bgp_router_id_set(bgp, id.s_addr ? &id : &bgp->router_id_zebra,
bgp_router_id_set(bgp,
id.s_addr != INADDR_ANY ? &id : &bgp->router_id_zebra,
true /* is config */);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion eigrpd/eigrp_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ int eigrp_network_set(struct eigrp *eigrp, struct prefix *p)
rn->info = (void *)pref;

/* Schedule Router ID Update. */
if (eigrp->router_id.s_addr == 0)
if (eigrp->router_id.s_addr == INADDR_ANY)
eigrp_router_id_update(eigrp);
/* Run network config now. */
/* Get target interface. */
Expand Down
2 changes: 1 addition & 1 deletion eigrpd/eigrp_northbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static int eigrpd_instance_router_id_destroy(enum nb_event event,
break;
case NB_EV_APPLY:
eigrp = nb_running_get_entry(dnode, NULL, true);
eigrp->router_id_static.s_addr = 0;
eigrp->router_id_static.s_addr = INADDR_ANY;
break;
}

Expand Down
8 changes: 4 additions & 4 deletions eigrpd/eigrpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ void eigrp_router_id_update(struct eigrp *eigrp)

router_id_old = eigrp->router_id;

if (eigrp->router_id_static.s_addr != 0)
if (eigrp->router_id_static.s_addr != INADDR_ANY)
router_id = eigrp->router_id_static;

else if (eigrp->router_id.s_addr != 0)
else if (eigrp->router_id.s_addr != INADDR_ANY)
router_id = eigrp->router_id;

else
Expand Down Expand Up @@ -142,8 +142,8 @@ static struct eigrp *eigrp_new(uint16_t as, vrf_id_t vrf_id)
eigrp->vrf_id = vrf_id;
eigrp->vrid = 0;
eigrp->AS = as;
eigrp->router_id.s_addr = 0;
eigrp->router_id_static.s_addr = 0;
eigrp->router_id.s_addr = INADDR_ANY;
eigrp->router_id_static.s_addr = INADDR_ANY;
eigrp->sequence_number = 1;

/*Configure default K Values for EIGRP Process*/
Expand Down
5 changes: 2 additions & 3 deletions ldpd/ldp_vty_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,8 @@ ldp_config_write(struct vty *vty)

vty_out (vty, "mpls ldp\n");

if (ldpd_conf->rtr_id.s_addr != 0)
vty_out (vty, " router-id %s\n",
inet_ntoa(ldpd_conf->rtr_id));
if (ldpd_conf->rtr_id.s_addr != INADDR_ANY)
vty_out(vty, " router-id %s\n", inet_ntoa(ldpd_conf->rtr_id));

if (ldpd_conf->lhello_holdtime != LINK_DFLT_HOLDTIME &&
ldpd_conf->lhello_holdtime != 0)
Expand Down
12 changes: 7 additions & 5 deletions lib/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2551,7 +2551,8 @@ static int filter_show(struct vty *vty, const char *name, afi_t afi)
else {
vty_out(vty, " %s",
inet_ntoa(filter->addr));
if (filter->addr_mask.s_addr != 0)
if (filter->addr_mask.s_addr
!= INADDR_ANY)
vty_out(vty,
", wildcard bits %s",
inet_ntoa(
Expand Down Expand Up @@ -2599,7 +2600,8 @@ static int filter_show(struct vty *vty, const char *name, afi_t afi)
else {
vty_out(vty, " %s",
inet_ntoa(filter->addr));
if (filter->addr_mask.s_addr != 0)
if (filter->addr_mask.s_addr
!= INADDR_ANY)
vty_out(vty,
", wildcard bits %s",
inet_ntoa(
Expand Down Expand Up @@ -2692,7 +2694,7 @@ static void config_write_access_cisco(struct vty *vty, struct filter *mfilter)
vty_out(vty, " ip");
if (filter->addr_mask.s_addr == 0xffffffff)
vty_out(vty, " any");
else if (filter->addr_mask.s_addr == 0)
else if (filter->addr_mask.s_addr == INADDR_ANY)
vty_out(vty, " host %s", inet_ntoa(filter->addr));
else {
vty_out(vty, " %s", inet_ntoa(filter->addr));
Expand All @@ -2701,7 +2703,7 @@ static void config_write_access_cisco(struct vty *vty, struct filter *mfilter)

if (filter->mask_mask.s_addr == 0xffffffff)
vty_out(vty, " any");
else if (filter->mask_mask.s_addr == 0)
else if (filter->mask_mask.s_addr == INADDR_ANY)
vty_out(vty, " host %s", inet_ntoa(filter->mask));
else {
vty_out(vty, " %s", inet_ntoa(filter->mask));
Expand All @@ -2713,7 +2715,7 @@ static void config_write_access_cisco(struct vty *vty, struct filter *mfilter)
vty_out(vty, " any\n");
else {
vty_out(vty, " %s", inet_ntoa(filter->addr));
if (filter->addr_mask.s_addr != 0)
if (filter->addr_mask.s_addr != INADDR_ANY)
vty_out(vty, " %s",
inet_ntoa(filter->addr_mask));
vty_out(vty, "\n");
Expand Down
4 changes: 2 additions & 2 deletions lib/prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ void apply_mask_ipv4(struct prefix_ipv4 *p)
/* If prefix is 0.0.0.0/0 then return 1 else return 0. */
int prefix_ipv4_any(const struct prefix_ipv4 *p)
{
return (p->prefix.s_addr == 0 && p->prefixlen == 0);
return (p->prefix.s_addr == INADDR_ANY && p->prefixlen == 0);
}

/* Allocate a new ip version 6 route */
Expand Down Expand Up @@ -1144,7 +1144,7 @@ int netmask_str2prefix_str(const char *net_str, const char *mask_str,
} else {
destination = ntohl(network.s_addr);

if (network.s_addr == 0)
if (network.s_addr == INADDR_ANY)
prefixlen = 0;
else if (IN_CLASSC(destination))
prefixlen = 24;
Expand Down
2 changes: 1 addition & 1 deletion lib/routemap_northbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ lib_route_map_entry_set_action_ipv4_address_modify(enum nb_event event,
* only implemented action.
*/
yang_dnode_get_ipv4(&ia, dnode, NULL);
if (ia.s_addr == 0 || IPV4_CLASS_DE(ntohl(ia.s_addr)))
if (ia.s_addr == INADDR_ANY || IPV4_CLASS_DE(ntohl(ia.s_addr)))
return NB_ERR_VALIDATION;
/* FALLTHROUGH */
case NB_EV_PREPARE:
Expand Down
2 changes: 1 addition & 1 deletion nhrpd/nhrp_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static void nhrp_interface_update_nbma(struct interface *ifp)
&nifp->linkidx, &saddr);
debugf(NHRP_DEBUG_IF, "%s: GRE: %x %x %x", ifp->name,
nifp->grekey, nifp->linkidx, saddr.s_addr);
if (saddr.s_addr)
if (saddr.s_addr != INADDR_ANY)
sockunion_set(&nbma, AF_INET, (uint8_t *)&saddr.s_addr,
sizeof(saddr.s_addr));
else if (!nbmaifp && nifp->linkidx != IFINDEX_INTERNAL)
Expand Down
2 changes: 1 addition & 1 deletion ospfclient/ospf_apiclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ int ospf_apiclient_lsa_originate(struct ospf_apiclient *oclient,

tmp = SET_OPAQUE_LSID(opaque_type, opaque_id);
lsah->id.s_addr = htonl(tmp);
lsah->adv_router.s_addr = 0;
lsah->adv_router.s_addr = INADDR_ANY;
lsah->ls_seqnum = 0;
lsah->checksum = 0;
lsah->length = htons(sizeof(struct lsa_header) + opaquelen);
Expand Down
Loading

0 comments on commit 975a328

Please sign in to comment.