]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd, lib, nhrpd, zebra: verify return of sockunion2hostprefix
authorDonald Sharp <sharpd@nvidia.com>
Wed, 18 Nov 2020 16:04:27 +0000 (11:04 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Wed, 18 Nov 2020 16:04:27 +0000 (11:04 -0500)
The return from sockunion2hostprefix tells us if the conversion
succeeded or not.  There are places in the code where we
always assume that it just `works`, since it can fail
notice and try to do the right thing.

Please note that failure of this function for most cases
of sockunion2hostprefix is highly highly unlikely as that
the sockunion was already created and tested elsewhere
it's just that this function can fail.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
bgpd/bgp_bmp.c
bgpd/bgp_network.c
bgpd/bgp_route.c
bgpd/bgp_vty.c
bgpd/bgpd.c
lib/vty.c
nhrpd/nhrp_cache.c
nhrpd/nhrp_shortcut.c
zebra/zebra_vty.c

index af88547ca94aa2bc5a63a67ffe8be0e5df795181..f115f18f071609ac1a812caac89f21b7a97b19ab 100644 (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) {
index cae11ae7bdd91f70e4e05e0486ef8adf470e1959..fcbdb2969f2e65e8f3a54d3da139a075a2ef9b53 100644 (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;
 
index 87e8feb3bf7bda029fc1bc6a0e28eea9f694dea3..df30897dc6a5e6dca12f0109b39604447c5d6929 100644 (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);
index 40e97078661da04b478646e954101f14b5a266e3..72d250d2bbf8527ff876a6456bfab348aba8fef2 100644 (file)
@@ -12448,9 +12448,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));
@@ -12467,9 +12467,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,
index fd2c431eac4443cf5221ddc72955eccb5002c372..25f3526a23deca96202d5b4f6a05295df23fbd91 100644 (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);
index fea4c490320db66631601914247da017eab81d1f..1eb4171630e357201ac8e367a8f8870be9f661f3 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -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) {
index 42f6a88f952d86bab2e5fbf7049deb949c836155..f7c71c2218d7e07b6b9b28eaa112ecbc3eb5ecd6 100644 (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);
index 9a6f77334f1868e79e4d774691452468a9035c3a..2359cfa4ac09f84ae678f255df75790cc862a5be 100644 (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;
index ea7baa2565d9c6ec1e55b7e5bc4a96bb6d523f0a..8f73825700fb6d9e985a2fd0696558879c67f3e6 100644 (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;
 }