Merge pull request #7554 from donaldsharp/sockunion2hostprefix_watch_returns

bgpd, lib, nhrpd, zebra: verify return of sockunion2hostprefix
This commit is contained in:
Donatas Abraitis 2020-11-19 11:26:02 +02:00 committed by GitHub
commit 53a85efa51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 34 additions and 16 deletions

View File

@ -1351,7 +1351,10 @@ static struct bmp *bmp_open(struct bmp_targets *bt, int bmp_sock)
set_cloexec(bmp_sock);
shutdown(bmp_sock, SHUT_RD);
sockunion2hostprefix(&su, &p);
if (!sockunion2hostprefix(&su, &p)) {
close(bmp_sock);
return NULL;
}
acl = NULL;
switch (p.family) {

View File

@ -639,7 +639,9 @@ static int bgp_update_address(struct interface *ifp, const union sockunion *dst,
struct listnode *node;
int common;
sockunion2hostprefix(dst, &d);
if (!sockunion2hostprefix(dst, &d))
return 1;
sel = NULL;
common = -1;

View File

@ -13699,7 +13699,9 @@ uint8_t bgp_distance_apply(const struct prefix *p, struct bgp_path_info *pinfo,
return pinfo->attr->distance;
/* Check source address. */
sockunion2hostprefix(&peer->su, &q);
if (!sockunion2hostprefix(&peer->su, &q))
return 0;
dest = bgp_node_match(bgp_distance_table[afi][safi], &q);
if (dest) {
bdistance = bgp_dest_get_bgp_distance_info(dest);

View File

@ -12442,9 +12442,9 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
if (dn_flag[0]) {
struct prefix prefix, *range = NULL;
sockunion2hostprefix(&(p->su), &prefix);
range = peer_group_lookup_dynamic_neighbor_range(
p->group, &prefix);
if (sockunion2hostprefix(&(p->su), &prefix))
range = peer_group_lookup_dynamic_neighbor_range(
p->group, &prefix);
if (range) {
prefix2str(range, buf1, sizeof(buf1));
@ -12461,9 +12461,9 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
if (dn_flag[0]) {
struct prefix prefix, *range = NULL;
sockunion2hostprefix(&(p->su), &prefix);
range = peer_group_lookup_dynamic_neighbor_range(
p->group, &prefix);
if (sockunion2hostprefix(&(p->su), &prefix))
range = peer_group_lookup_dynamic_neighbor_range(
p->group, &prefix);
if (range) {
vty_out(vty,

View File

@ -2802,8 +2802,8 @@ int peer_group_listen_range_del(struct peer_group *group, struct prefix *range)
if (!peer_dynamic_neighbor(peer))
continue;
sockunion2hostprefix(&peer->su, &prefix2);
if (prefix_match(prefix, &prefix2)) {
if (sockunion2hostprefix(&peer->su, &prefix2)
&& prefix_match(prefix, &prefix2)) {
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"Deleting dynamic neighbor %s group %s upon delete of listen range %pFX",
@ -3834,7 +3834,8 @@ struct peer *peer_lookup_dynamic_neighbor(struct bgp *bgp, union sockunion *su)
int dncount;
char buf[PREFIX2STR_BUFFER];
sockunion2hostprefix(su, &prefix);
if (!sockunion2hostprefix(su, &prefix))
return NULL;
/* See if incoming connection matches a configured listen range. */
group = peer_group_lookup_dynamic_neighbor(bgp, &prefix, &listen_range);

View File

@ -1810,7 +1810,11 @@ static int vty_accept(struct thread *thread)
set_nonblocking(vty_sock);
set_cloexec(vty_sock);
sockunion2hostprefix(&su, &p);
if (!sockunion2hostprefix(&su, &p)) {
zlog_info("Vty unable to convert prefix from sockunion %s",
sockunion2str(&su, buf, SU_ADDRSTRLEN));
return -1;
}
/* VTY's accesslist apply. */
if (p.family == AF_INET && vty_accesslist_name) {

View File

@ -122,7 +122,8 @@ static void nhrp_cache_update_route(struct nhrp_cache *c)
char buf[3][SU_ADDRSTRLEN];
struct nhrp_interface *nifp;
sockunion2hostprefix(&c->remote_addr, &pfx);
if (!sockunion2hostprefix(&c->remote_addr, &pfx))
return;
if (p && nhrp_peer_check(p, 1)) {
if (sockunion_family(&c->cur.remote_nbma_natoa) != AF_UNSPEC) {
@ -186,7 +187,7 @@ static void nhrp_cache_update_route(struct nhrp_cache *c)
c->nhrp_route_installed = 0;
}
if (c->route_installed) {
sockunion2hostprefix(&c->remote_addr, &pfx);
assert(sockunion2hostprefix(&c->remote_addr, &pfx));
notifier_call(&c->notifier_list, NOTIFY_CACHE_DOWN);
nhrp_route_announce(0, c->cur.type, &pfx, NULL, NULL,
0);

View File

@ -397,7 +397,9 @@ void nhrp_shortcut_initiate(union sockunion *addr)
struct prefix p;
struct nhrp_shortcut *s;
sockunion2hostprefix(addr, &p);
if (!sockunion2hostprefix(addr, &p))
return;
s = nhrp_shortcut_get(&p);
if (s && s->type != NHRP_CACHE_INCOMPLETE) {
s->addr = *addr;

View File

@ -1277,6 +1277,9 @@ DEFPY (show_ip_nht,
if (addr)
p = sockunion2hostprefix(addr, &prefix);
if (!p)
return CMD_WARNING;
zebra_print_rnh_table(vrf_id, afi, vty, rtype, p);
return CMD_SUCCESS;
}