]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #2362 from donaldsharp/vrf_debug_5.0
authorLou Berger <lberger@labn.net>
Mon, 4 Jun 2018 13:53:59 +0000 (09:53 -0400)
committerGitHub <noreply@github.com>
Mon, 4 Jun 2018 13:53:59 +0000 (09:53 -0400)
Couple of cherry-picks of code

bgpd/bgp_network.c
bgpd/bgpd.c
lib/vrf.c
zebra/redistribute.c

index 37d06c1e53ad9373a07a692ca7b7b715cfedbed1..84a959d0e8cb0fb0100f74eb0aef5e7ef9789682 100644 (file)
@@ -723,7 +723,9 @@ int bgp_socket(struct bgp *bgp, unsigned short port, const char *address)
                if (bgpd_privs.change(ZPRIVS_RAISE))
                        zlog_err("Can't raise privileges");
                sock = vrf_socket(ainfo->ai_family, ainfo->ai_socktype,
-                                 ainfo->ai_protocol, bgp->vrf_id, NULL);
+                                 ainfo->ai_protocol, bgp->vrf_id,
+                                 (bgp->inst_type == BGP_INSTANCE_TYPE_VRF ?
+                                  bgp->name : NULL));
                if (bgpd_privs.change(ZPRIVS_LOWER))
                        zlog_err("Can't lower privileges");
                if (sock < 0) {
index cfb759d124caf15afe74fe67dcd67b3610c84571..41f85f4a6fb74fccab253384a76c8b81d825b69e 100644 (file)
@@ -109,12 +109,7 @@ extern struct zclient *zclient;
 static int bgp_check_main_socket(bool create, struct bgp *bgp)
 {
        static int bgp_server_main_created;
-       struct listnode *bgpnode, *nbgpnode;
-       struct bgp *bgp_temp;
 
-       if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF &&
-           vrf_is_mapped_on_netns(bgp->vrf_id))
-               return 0;
        if (create == true) {
                if (bgp_server_main_created)
                        return 0;
@@ -125,18 +120,6 @@ static int bgp_check_main_socket(bool create, struct bgp *bgp)
        }
        if (!bgp_server_main_created)
                return 0;
-       /* only delete socket on some cases */
-       for (ALL_LIST_ELEMENTS(bm->bgp, bgpnode, nbgpnode, bgp_temp)) {
-               /* do not count with current bgp */
-               if (bgp_temp == bgp)
-                       continue;
-               /* if other instance non VRF, do not delete socket */
-               if (bgp_temp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
-                       return 0;
-               /* vrf lite, do not delete socket */
-               if (!vrf_is_mapped_on_netns(bgp_temp->vrf_id))
-                       return 0;
-       }
        bgp_close();
        bgp_server_main_created = 0;
        return 0;
@@ -3074,17 +3057,16 @@ int bgp_handle_socket(struct bgp *bgp, struct vrf *vrf, vrf_id_t old_vrf_id,
        /* Create BGP server socket, if listen mode not disabled */
        if (!bgp || bgp_option_check(BGP_OPT_NO_LISTEN))
                return 0;
-       if (bgp->name && bgp->inst_type == BGP_INSTANCE_TYPE_VRF && vrf) {
+       if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF) {
                /*
                 * suppress vrf socket
                 */
                if (create == FALSE) {
-                       if (vrf_is_mapped_on_netns(vrf->vrf_id))
-                               bgp_close_vrf_socket(bgp);
-                       else
-                               ret = bgp_check_main_socket(create, bgp);
-                       return ret;
+                       bgp_close_vrf_socket(bgp);
+                       return 0;
                }
+               if (vrf == NULL)
+                       return BGP_ERR_INVALID_VALUE;
                /* do nothing
                 * if vrf_id did not change
                 */
@@ -3099,21 +3081,12 @@ int bgp_handle_socket(struct bgp *bgp, struct vrf *vrf, vrf_id_t old_vrf_id,
                 */
                if (vrf->vrf_id == VRF_UNKNOWN)
                        return 0;
-               /* if BGP VRF instance requested
-                * if backend is NETNS, create BGP server socket in the NETNS
-                */
-               if (vrf_is_mapped_on_netns(bgp->vrf_id)) {
-                       ret = bgp_socket(bgp, bm->port, bm->address);
-                       if (ret < 0)
-                               return BGP_ERR_INVALID_VALUE;
-                       return 0;
-               }
-       }
-       /* if BGP VRF instance requested or VRF lite backend
-        * if BGP non VRF instance, create it
-        *  if not already done
-        */
-       return bgp_check_main_socket(create, bgp);
+               ret = bgp_socket(bgp, bm->port, bm->address);
+               if (ret < 0)
+                       return BGP_ERR_INVALID_VALUE;
+               return 0;
+       } else
+               return bgp_check_main_socket(create, bgp);
 }
 
 /* Called from VTY commands. */
@@ -3490,16 +3463,7 @@ struct peer *peer_lookup(struct bgp *bgp, union sockunion *su)
                struct listnode *bgpnode, *nbgpnode;
 
                for (ALL_LIST_ELEMENTS(bm->bgp, bgpnode, nbgpnode, bgp)) {
-                       /* Skip VRFs Lite only, this function will not be
-                        * invoked without an instance
-                        * when examining VRFs.
-                        */
-                       if ((bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
-                           && !vrf_is_mapped_on_netns(bgp->vrf_id))
-                               continue;
-
                        peer = hash_lookup(bgp->peerhash, &tmp_peer);
-
                        if (peer)
                                break;
                }
index db539d375dda73bb015363528af9ec10116c0565..e1176d152603a742cd80260daf227583e127caed 100644 (file)
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -856,7 +856,7 @@ int vrf_bind(vrf_id_t vrf_id, int fd, char *name)
        if (vrf_is_mapped_on_netns(vrf_id))
                return fd;
 #ifdef SO_BINDTODEVICE
-       ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, name, strlen(name));
+       ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, name, strlen(name)+1);
        if (ret < 0)
                zlog_debug("bind to interface %s failed, errno=%d", name,
                           errno);
index 810ee33839a71bfe4af5631e3f6932aaae0fe0af..c7acd73988deb8190c3919e37cf1251241625a0e 100644 (file)
@@ -120,7 +120,7 @@ static void zebra_redistribute(struct zserv *client, int type,
 
                        if (IS_ZEBRA_DEBUG_EVENT)
                                zlog_debug(
-                                       "%s: client %s %s(%d) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d",
+                                       "%s: client %s %s(%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d",
                                        __func__,
                                        zebra_route_string(client->proto),
                                        prefix2str(dst_p, buf, sizeof(buf)),
@@ -192,7 +192,7 @@ void redistribute_update(struct prefix *p, struct prefix *src_p,
                if (send_redistribute) {
                        if (IS_ZEBRA_DEBUG_EVENT) {
                                zlog_debug(
-                                          "%s: client %s %s(%d), type=%d, distance=%d, metric=%d",
+                                          "%s: client %s %s(%u), type=%d, distance=%d, metric=%d",
                                           __func__,
                                           zebra_route_string(client->proto),
                                           prefix2str(p, buf, sizeof(buf)),
@@ -270,7 +270,7 @@ void zebra_redistribute_add(ZAPI_HANDLER_ARGS)
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug(
-                       "%s: client proto %s afi=%d, wants %s, vrf %d, instance=%d",
+                       "%s: client proto %s afi=%d, wants %s, vrf %u, instance=%d",
                        __func__, zebra_route_string(client->proto), afi,
                        zebra_route_string(type), zvrf_id(zvrf), instance);
 
@@ -298,7 +298,7 @@ void zebra_redistribute_add(ZAPI_HANDLER_ARGS)
                if (!vrf_bitmap_check(client->redist[afi][type],
                                      zvrf_id(zvrf))) {
                        if (IS_ZEBRA_DEBUG_EVENT)
-                               zlog_debug("%s: setting vrf %d redist bitmap",
+                               zlog_debug("%s: setting vrf %u redist bitmap",
                                           __func__, zvrf_id(zvrf));
                        vrf_bitmap_set(client->redist[afi][type],
                                       zvrf_id(zvrf));
@@ -365,7 +365,8 @@ void zebra_interface_up_update(struct interface *ifp)
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s", ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s(%u)",
+                          ifp->name, ifp->vrf_id);
 
        if (ifp->ptm_status || !ifp->ptm_enable) {
                for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
@@ -384,7 +385,8 @@ void zebra_interface_down_update(struct interface *ifp)
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s", ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)",
+                          ifp->name, ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) {
                zsend_interface_update(ZEBRA_INTERFACE_DOWN, client, ifp);
@@ -398,7 +400,7 @@ void zebra_interface_add_update(struct interface *ifp)
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s[%d]", ifp->name,
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s(%u)", ifp->name,
                           ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
@@ -415,7 +417,8 @@ void zebra_interface_delete_update(struct interface *ifp)
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s", ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s(%u)",
+                          ifp->name, ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) {
                client->ifdel_cnt++;
@@ -435,8 +438,9 @@ void zebra_interface_address_add_update(struct interface *ifp,
                char buf[PREFIX_STRLEN];
 
                p = ifc->address;
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s",
-                          prefix2str(p, buf, sizeof(buf)), ifc->ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s(%u)",
+                          prefix2str(p, buf, sizeof(buf)), ifp->name,
+                          ifp->vrf_id);
        }
 
        if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
@@ -467,8 +471,9 @@ void zebra_interface_address_delete_update(struct interface *ifp,
                char buf[PREFIX_STRLEN];
 
                p = ifc->address;
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s",
-                          prefix2str(p, buf, sizeof(buf)), ifc->ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s(%u)",
+                          prefix2str(p, buf, sizeof(buf)),
+                          ifp->name, ifp->vrf_id);
        }
 
        zebra_vxlan_add_del_gw_macip(ifp, ifc->address, 0);
@@ -768,8 +773,8 @@ void zebra_interface_parameters_update(struct interface *ifp)
        struct zserv *client;
 
        if (IS_ZEBRA_DEBUG_EVENT)
-               zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s",
-                          ifp->name);
+               zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)",
+                          ifp->name, ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
                if (client->ifinfo)