]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #3888 from donaldsharp/ospf_cleanup
authorOlivier Dugeon <olivier.dugeon@orange.com>
Tue, 2 Jul 2019 15:37:23 +0000 (17:37 +0200)
committerGitHub <noreply@github.com>
Tue, 2 Jul 2019 15:37:23 +0000 (17:37 +0200)
ospfd: Cleanup ospf->redist and ospf->external on shutdown

101 files changed:
babeld/babel_interface.c
babeld/babeld.c
bfdd/bfd.c
bfdd/ptm_adapter.c
bgpd/bgp_evpn_vty.c
bgpd/bgp_mplsvpn.c
bgpd/bgp_mplsvpn.h
bgpd/bgp_network.c
bgpd/bgp_route.c
bgpd/bgp_vty.c
bgpd/bgp_zebra.c
bgpd/bgpd.c
bgpd/rfapi/rfapi_import.c
doc/user/pim.rst
doc/user/routemap.rst
eigrpd/eigrp_filter.c
eigrpd/eigrp_routemap.c
eigrpd/eigrp_zebra.c
isisd/isis_cli.c
isisd/isis_northbound.c
isisd/isis_te.c
lib/command_parse.y
lib/if.c
lib/if.h
lib/routemap.c
lib/routemap.h
lib/vrf.c
lib/vrf.h
lib/vty.c
lib/zclient.c
nhrpd/nhrp_interface.c
ospf6d/ospf6_asbr.c
ospf6d/ospf6_interface.c
ospf6d/ospf6_top.c
ospfd/ospf_interface.c
ospfd/ospf_te.c
ospfd/ospf_vty.c
ospfd/ospf_zebra.c
ospfd/ospfd.c
ospfd/ospfd.h
pimd/pim_assert.c
pimd/pim_bsm.c
pimd/pim_cmd.c
pimd/pim_iface.c
pimd/pim_ifchannel.c
pimd/pim_igmp.c
pimd/pim_igmp.h
pimd/pim_mroute.c
pimd/pim_msdp_socket.c
pimd/pim_static.c
pimd/pim_upstream.c
pimd/pim_zebra.c
ripd/rip_interface.c
ripd/rip_routemap.c
ripd/ripd.c
ripngd/ripng_interface.c
ripngd/ripng_routemap.c
ripngd/ripngd.c
sharpd/sharp_zebra.c
staticd/static_nht.c
staticd/static_routes.c
staticd/static_zebra.c
tests/topotests/bgp_instance_del_test/__init__.py [new file with mode: 0644]
tests/topotests/bgp_instance_del_test/ce1 [new symlink]
tests/topotests/bgp_instance_del_test/ce2 [new symlink]
tests/topotests/bgp_instance_del_test/ce3 [new symlink]
tests/topotests/bgp_instance_del_test/ce4 [new symlink]
tests/topotests/bgp_instance_del_test/customize.py [new symlink]
tests/topotests/bgp_instance_del_test/r1 [new symlink]
tests/topotests/bgp_instance_del_test/r2 [new symlink]
tests/topotests/bgp_instance_del_test/r3 [new symlink]
tests/topotests/bgp_instance_del_test/r4 [new symlink]
tests/topotests/bgp_instance_del_test/scripts [new symlink]
tests/topotests/bgp_instance_del_test/test_bgp_instance_del_test.py [new file with mode: 0755]
tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py [new file with mode: 0644]
tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py
tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py
tests/topotests/lib/lutil.py
vrrpd/vrrp_main.c
vtysh/vtysh_user.c
zebra/connected.c
zebra/if_ioctl.c
zebra/if_ioctl_solaris.c
zebra/if_netlink.c
zebra/interface.c
zebra/ioctl.c
zebra/kernel_socket.c
zebra/main.c
zebra/redistribute.c
zebra/router-id.c
zebra/rt_netlink.c
zebra/rtadv.c
zebra/zapi_msg.c
zebra/zebra_dplane.c
zebra/zebra_ptm.c
zebra/zebra_rib.c
zebra/zebra_rnh.c
zebra/zebra_vrf.h
zebra/zebra_vty.c
zebra/zebra_vxlan.c
zebra/zebra_vxlan.h

index 36adf118a409210cc0b171978066a3363e90c466..0eeb9b2bbbfaac3d459ed23831a15e16cfd6cea7 100644 (file)
@@ -242,7 +242,7 @@ babel_enable_if_add (const char *ifname)
 
     vector_set (babel_enable_if, strdup (ifname));
 
-    ifp = if_lookup_by_name(ifname, vrf_lookup_by_id(VRF_DEFAULT));
+    ifp = if_lookup_by_name(ifname, VRF_DEFAULT);
     if (ifp != NULL)
         interface_recalculate(ifp);
 
@@ -265,7 +265,7 @@ babel_enable_if_delete (const char *ifname)
     free (str);
     vector_unset (babel_enable_if, babel_enable_if_index);
 
-    ifp = if_lookup_by_name(ifname, vrf_lookup_by_id(VRF_DEFAULT));
+    ifp = if_lookup_by_name(ifname, VRF_DEFAULT);
     if (ifp != NULL)
         interface_reset(ifp);
 
@@ -908,8 +908,7 @@ DEFUN (show_babel_interface,
       show_babel_interface_sub (vty, ifp);
     return CMD_SUCCESS;
   }
-  if ((ifp = if_lookup_by_name (argv[3]->arg,
-                               vrf_lookup_by_id(VRF_DEFAULT))) == NULL)
+  if ((ifp = if_lookup_by_name (argv[3]->arg, VRF_DEFAULT)) == NULL)
   {
     vty_out (vty, "No such interface name\n");
     return CMD_WARNING;
@@ -951,8 +950,7 @@ DEFUN (show_babel_neighbour,
         }
         return CMD_SUCCESS;
     }
-    if ((ifp = if_lookup_by_name (argv[3]->arg,
-                                 vrf_lookup_by_id(VRF_DEFAULT))) == NULL)
+    if ((ifp = if_lookup_by_name (argv[3]->arg, VRF_DEFAULT)) == NULL)
     {
         vty_out (vty, "No such interface name\n");
         return CMD_WARNING;
index 736dedcf7092e2a36cf59e1c89001b37700c1607..6ad004a4a41a011f738df0b6e70daf2b10999a6d 100644 (file)
@@ -557,7 +557,7 @@ babel_distribute_update (struct distribute_ctx *ctx, struct distribute *dist)
     if (! dist->ifname)
         return;
 
-    ifp = if_lookup_by_name (dist->ifname, vrf_lookup_by_id(VRF_DEFAULT));
+    ifp = if_lookup_by_name (dist->ifname, VRF_DEFAULT);
     if (ifp == NULL)
         return;
 
index efbdc8b4f73c90b89fbafb78b3b4432bdaad3edc..08a70abc1ea29435d94e0b1b4516175382280764 100644 (file)
@@ -142,7 +142,7 @@ int bfd_session_enable(struct bfd_session *bs)
 
        if (bs->key.ifname[0]) {
                if (vrf)
-                       ifp = if_lookup_by_name(bs->key.ifname, vrf);
+                       ifp = if_lookup_by_name(bs->key.ifname, vrf->vrf_id);
                else
                        ifp = if_lookup_by_name_all_vrf(bs->key.ifname);
                if (ifp == NULL) {
@@ -151,7 +151,7 @@ int bfd_session_enable(struct bfd_session *bs)
                        return 0;
                }
                if (bs->key.ifname[0] && !vrf) {
-                       vrf = ifp->vrf;
+                       vrf = vrf_lookup_by_id(ifp->vrf_id);
                        if (vrf == NULL) {
                                log_error(
                                          "session-enable: specified VRF doesn't exists.");
index a634d923d25c9e32f3a2b4e7c6daffa2f5f95785..3e2ace6ea630a95598150799c158be5e185a4730 100644 (file)
@@ -572,10 +572,7 @@ static void bfdd_sessions_enable_interface(struct interface *ifp)
 {
        struct bfd_session_observer *bso;
        struct bfd_session *bs;
-       struct vrf *vrf = ifp->vrf;
-
-       if (!vrf)
-               return;
+       struct vrf *vrf;
 
        TAILQ_FOREACH(bso, &bglobal.bg_obslist, bso_entry) {
                bs = bso->bso_bs;
@@ -584,6 +581,9 @@ static void bfdd_sessions_enable_interface(struct interface *ifp)
                /* Interface name mismatch. */
                if (strcmp(ifp->name, bs->key.ifname))
                        continue;
+               vrf = vrf_lookup_by_id(ifp->vrf_id);
+               if (!vrf)
+                       continue;
                if (bs->key.vrfname[0] &&
                    strcmp(vrf->name, bs->key.vrfname))
                        continue;
@@ -698,14 +698,13 @@ static int bfdd_interface_update(ZAPI_CALLBACK_ARGS)
 static int bfdd_interface_vrf_update(ZAPI_CALLBACK_ARGS)
 {
        struct interface *ifp;
-       struct vrf *nvrf;
        vrf_id_t nvrfid;
 
        ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, &nvrfid);
        if (ifp == NULL)
                return 0;
-       nvrf = vrf_lookup_by_id(nvrfid);
-       if_update_to_new_vrf(ifp, nvrf);
+
+       if_update_to_new_vrf(ifp, nvrfid);
 
        return 0;
 }
index ca6edffab088c6f6956655fdbfc0ba51bc7d9a8d..44e9375dc99c6c04819c8f104d7dd0c57e2121a9 100644 (file)
@@ -2480,6 +2480,8 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type,
                                        bgp_evpn_show_route_header(vty, bgp,
                                                                   tbl_ver,
                                                                   json);
+                                       vty_out(vty, "%19s Extended Community\n"
+                                                       , " ");
                                        header = 0;
                                }
 
index 355bc93320f1e110f1f2df0695f0f729151306ba..1156810510d3c744ba416bd3702032b22412df6a 100644 (file)
@@ -1614,11 +1614,13 @@ void vrf_import_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp,
 {
        const char *export_name;
        vpn_policy_direction_t idir, edir;
-       char *vname;
-       char buf[1000];
+       char *vname, *tmp_name;
+       char buf[RD_ADDRSTRLEN];
        struct ecommunity *ecom;
        bool first_export = false;
        int debug;
+       struct listnode *node;
+       bool is_inst_match = false;
 
        export_name = to_bgp->name ? to_bgp->name : VRF_DEFAULT_NAME;
        idir = BGP_VPN_POLICY_DIR_FROMVPN;
@@ -1634,13 +1636,41 @@ void vrf_import_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp,
        vname = (from_bgp->name ? XSTRDUP(MTYPE_TMP, from_bgp->name)
                               : XSTRDUP(MTYPE_TMP, VRF_DEFAULT_NAME));
 
-       listnode_add(to_bgp->vpn_policy[afi].import_vrf, vname);
+       /* Check the import_vrf list of destination vrf for the source vrf name,
+        * insert otherwise.
+        */
+       for (ALL_LIST_ELEMENTS_RO(to_bgp->vpn_policy[afi].import_vrf,
+                                 node, tmp_name)) {
+               if (strcmp(vname, tmp_name) == 0) {
+                       is_inst_match = true;
+                       break;
+               }
+       }
+       if (!is_inst_match)
+               listnode_add(to_bgp->vpn_policy[afi].import_vrf,
+                                    vname);
 
-       if (!listcount(from_bgp->vpn_policy[afi].export_vrf))
-               first_export = true;
+       /* Check if the source vrf already exports to any vrf,
+        * first time export requires to setup auto derived RD/RT values.
+        * Add the destination vrf name to export vrf list if it is
+        * not present.
+        */
+       is_inst_match = false;
        vname = XSTRDUP(MTYPE_TMP, export_name);
-       listnode_add(from_bgp->vpn_policy[afi].export_vrf, vname);
-
+       if (!listcount(from_bgp->vpn_policy[afi].export_vrf)) {
+               first_export = true;
+       } else {
+               for (ALL_LIST_ELEMENTS_RO(from_bgp->vpn_policy[afi].export_vrf,
+                                         node, tmp_name)) {
+                       if (strcmp(vname, tmp_name) == 0) {
+                               is_inst_match = true;
+                               break;
+                       }
+               }
+       }
+       if (!is_inst_match)
+               listnode_add(from_bgp->vpn_policy[afi].export_vrf,
+                            vname);
        /* Update import RT for current VRF using export RT of the VRF we're
         * importing from. First though, make sure "import_vrf" has that
         * set.
@@ -1702,7 +1732,7 @@ void vrf_unimport_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp,
        const char *export_name, *tmp_name;
        vpn_policy_direction_t idir, edir;
        char *vname;
-       struct ecommunity *ecom;
+       struct ecommunity *ecom = NULL;
        struct listnode *node;
        int debug;
 
@@ -1747,10 +1777,12 @@ void vrf_unimport_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp,
        if (to_bgp->vpn_policy[afi].import_vrf->count == 0) {
                UNSET_FLAG(to_bgp->af_flags[afi][safi],
                           BGP_CONFIG_VRF_TO_VRF_IMPORT);
-               ecommunity_free(&to_bgp->vpn_policy[afi].rtlist[idir]);
+               if (to_bgp->vpn_policy[afi].rtlist[idir])
+                       ecommunity_free(&to_bgp->vpn_policy[afi].rtlist[idir]);
        } else {
                ecom = from_bgp->vpn_policy[afi].rtlist[edir];
-               ecommunity_del_val(to_bgp->vpn_policy[afi].rtlist[idir],
+               if (ecom)
+                       ecommunity_del_val(to_bgp->vpn_policy[afi].rtlist[idir],
                                   (struct ecommunity_val *)ecom->val);
                vpn_leak_postchange(idir, afi, bgp_get_default(), to_bgp);
        }
@@ -1783,8 +1815,11 @@ void vrf_unimport_from_vrf(struct bgp *to_bgp, struct bgp *from_bgp,
         *
         * import_vrf and export_vrf must match in having
         * the in/out names as appropriate.
+        * export_vrf list could have been cleaned up
+        * as part of no router bgp source instnace.
         */
-       assert(vname);
+       if (!vname)
+               return;
 
        listnode_delete(from_bgp->vpn_policy[afi].export_vrf, vname);
        XFREE(MTYPE_TMP, vname);
@@ -2471,3 +2506,167 @@ void vpn_leak_postchange_all(void)
                        bgp);
        }
 }
+
+/* When a bgp vrf instance is unconfigured, remove its routes
+ * from the VPN table and this vrf could be importing routes from other
+ * bgp vrf instnaces, unimport them.
+ * VRF X and VRF Y are exporting routes to each other.
+ * When VRF X is deleted, unimport its routes from all target vrfs,
+ * also VRF Y should unimport its routes from VRF X table.
+ * This will ensure VPN table is cleaned up appropriately.
+ */
+int bgp_vpn_leak_unimport(struct bgp *from_bgp, struct vty *vty)
+{
+       struct bgp *to_bgp;
+       const char *tmp_name;
+       char *vname;
+       struct listnode *node, *next;
+       safi_t safi = SAFI_UNICAST;
+       afi_t afi;
+       bool is_vrf_leak_bind;
+       int debug;
+
+       if (from_bgp->inst_type != BGP_INSTANCE_TYPE_VRF)
+               return 0;
+
+       debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
+                    BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
+
+       tmp_name = from_bgp->name ? from_bgp->name : VRF_DEFAULT_NAME;
+
+       for (afi = 0; afi < AFI_MAX; ++afi) {
+               /* vrf leak is for IPv4 and IPv6 Unicast only */
+               if (afi != AFI_IP && afi != AFI_IP6)
+                       continue;
+
+               for (ALL_LIST_ELEMENTS_RO(bm->bgp, next, to_bgp)) {
+                       if (from_bgp == to_bgp)
+                               continue;
+
+                       /* Unimport and remove source vrf from the
+                        * other vrfs import list.
+                        */
+                       struct vpn_policy *to_vpolicy;
+
+                       is_vrf_leak_bind = false;
+                       to_vpolicy = &(to_bgp->vpn_policy[afi]);
+                       for (ALL_LIST_ELEMENTS_RO(to_vpolicy->import_vrf, node,
+                                                 vname)) {
+                               if (strcmp(vname, tmp_name) == 0) {
+                                       is_vrf_leak_bind = true;
+                                       break;
+                               }
+                       }
+                       /* skip this bgp instance as there is no leak to this
+                        * vrf instance.
+                        */
+                       if (!is_vrf_leak_bind)
+                               continue;
+
+                       if (debug)
+                               zlog_debug("%s: unimport routes from %s to_bgp %s afi %s import vrfs count %u",
+                                          __func__, from_bgp->name_pretty,
+                                          to_bgp->name_pretty, afi2str(afi),
+                                          to_vpolicy->import_vrf->count);
+
+                       vrf_unimport_from_vrf(to_bgp, from_bgp, afi, safi);
+
+                       /* readd vrf name as unimport removes import vrf name
+                        * from the destination vrf's import list where the
+                        * `import vrf` configuration still exist.
+                        */
+                       vname = XSTRDUP(MTYPE_TMP, tmp_name);
+                       listnode_add(to_bgp->vpn_policy[afi].import_vrf,
+                                    vname);
+                       SET_FLAG(to_bgp->af_flags[afi][safi],
+                                BGP_CONFIG_VRF_TO_VRF_IMPORT);
+
+                       /* If to_bgp exports its routes to the bgp vrf
+                        * which is being deleted, un-import the
+                        * to_bgp routes from VPN.
+                        */
+                       for (ALL_LIST_ELEMENTS_RO(to_bgp->vpn_policy[afi]
+                                                 .export_vrf, node,
+                                                 vname)) {
+                               if (strcmp(vname, tmp_name) == 0) {
+                                       vrf_unimport_from_vrf(from_bgp, to_bgp,
+                                                     afi, safi);
+                                       break;
+                               }
+                       }
+               }
+       }
+       return 0;
+}
+
+/* When a router bgp is configured, there could be a bgp vrf
+ * instance importing routes from this newly configured
+ * bgp vrf instance. Export routes from configured
+ * bgp vrf to VPN.
+ * VRF Y has import from bgp vrf x,
+ * when a bgp vrf x instance is created, export its routes
+ * to VRF Y instance.
+ */
+void bgp_vpn_leak_export(struct bgp *from_bgp)
+{
+       afi_t afi;
+       const char *export_name;
+       char *vname;
+       struct listnode *node, *next;
+       struct ecommunity *ecom;
+       vpn_policy_direction_t idir, edir;
+       safi_t safi = SAFI_UNICAST;
+       struct bgp *to_bgp;
+       int debug;
+
+       debug = (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF) |
+                    BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF));
+
+       idir = BGP_VPN_POLICY_DIR_FROMVPN;
+       edir = BGP_VPN_POLICY_DIR_TOVPN;
+
+       export_name = (from_bgp->name ? XSTRDUP(MTYPE_TMP, from_bgp->name)
+                              : XSTRDUP(MTYPE_TMP, VRF_DEFAULT_NAME));
+
+       for (afi = 0; afi < AFI_MAX; ++afi) {
+               /* vrf leak is for IPv4 and IPv6 Unicast only */
+               if (afi != AFI_IP && afi != AFI_IP6)
+                       continue;
+
+               for (ALL_LIST_ELEMENTS_RO(bm->bgp, next, to_bgp)) {
+                       if (from_bgp == to_bgp)
+                               continue;
+
+                       /* bgp instance has import list, check to see if newly
+                        * configured bgp instance is the list.
+                        */
+                       struct vpn_policy *to_vpolicy;
+
+                       to_vpolicy = &(to_bgp->vpn_policy[afi]);
+                       for (ALL_LIST_ELEMENTS_RO(to_vpolicy->import_vrf,
+                                                 node, vname)) {
+                               if (strcmp(vname, export_name) != 0)
+                                       continue;
+
+                               if (debug)
+                                       zlog_debug("%s: found from_bgp %s in to_bgp %s import list, import routes.",
+                                          __func__,
+                                          export_name, to_bgp->name_pretty);
+
+                               ecom = from_bgp->vpn_policy[afi].rtlist[edir];
+                               /* remove import rt, it will be readded
+                                * as part of import from vrf.
+                                */
+                               if (ecom)
+                                       ecommunity_del_val(
+                                               to_vpolicy->rtlist[idir],
+                                               (struct ecommunity_val *)
+                                                       ecom->val);
+                               vrf_import_from_vrf(to_bgp, from_bgp,
+                                                   afi, safi);
+                               break;
+
+                       }
+               }
+       }
+}
index 2a6c0e17088419d3a276024ce62ad530a991a6b7..3234f7fc9db284559016a480c4a6a430200eea86 100644 (file)
@@ -266,5 +266,7 @@ extern vrf_id_t get_first_vrf_for_redirect_with_rt(struct ecommunity *eckey);
 extern void vpn_leak_postchange_all(void);
 extern void vpn_handle_router_id_update(struct bgp *bgp, bool withdraw,
                                        bool is_config);
+extern int bgp_vpn_leak_unimport(struct bgp *from_bgp, struct vty *vty);
+extern void bgp_vpn_leak_export(struct bgp *from_bgp);
 
 #endif /* _QUAGGA_BGP_MPLSVPN_H */
index ca88a38df2f6f2f85702519dfbc935b668d5b21c..8e18ed75295c9a3a0886a113d04bdf8d7bd353ab 100644 (file)
@@ -310,8 +310,7 @@ static int bgp_get_instance_for_inc_conn(int sock, struct bgp **bgp_inst)
                if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW)
                        continue;
 
-               ifp = if_lookup_by_name(name,
-                                       vrf_lookup_by_id(bgp->vrf_id));
+               ifp = if_lookup_by_name(name, bgp->vrf_id);
                if (ifp) {
                        *bgp_inst = bgp;
                        return 0;
@@ -571,8 +570,7 @@ static int bgp_update_source(struct peer *peer)
 
        /* Source is specified with interface name.  */
        if (peer->update_if) {
-               ifp = if_lookup_by_name(peer->update_if,
-                                       vrf_lookup_by_id(peer->bgp->vrf_id));
+               ifp = if_lookup_by_name(peer->update_if, peer->bgp->vrf_id);
                if (!ifp)
                        return -1;
 
index b90097a4f25cdc2cc84e03e177f8a3f43922b1a4..a3aba447b5e5d2c78cccab57a9e6411ba66e8212 100644 (file)
@@ -2311,6 +2311,17 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_node *rn,
        char pfx_buf[PREFIX2STR_BUFFER];
        int debug = 0;
 
+       if (bgp_flag_check(bgp, BGP_FLAG_DELETE_IN_PROGRESS)) {
+               if (rn)
+                       debug = bgp_debug_bestpath(&rn->p);
+               if (debug) {
+                       prefix2str(&rn->p, pfx_buf, sizeof(pfx_buf));
+                       zlog_debug(
+                            "%s: bgp delete in progress, ignoring event, p=%s",
+                            __func__, pfx_buf);
+               }
+               return;
+       }
        /* Is it end of initial update? (after startup) */
        if (!rn) {
                quagga_timestamp(3, bgp->update_delay_zebra_resume_time,
@@ -6965,6 +6976,7 @@ void route_vty_out(struct vty *vty, struct prefix *p,
        json_object *json_nexthops = NULL;
        json_object *json_nexthop_global = NULL;
        json_object *json_nexthop_ll = NULL;
+       json_object *json_ext_community = NULL;
        char vrf_id_str[VRF_NAMSIZ] = {0};
        bool nexthop_self =
                CHECK_FLAG(path->flags, BGP_PATH_ANNC_NH_SELF) ? true : false;
@@ -7330,6 +7342,17 @@ void route_vty_out(struct vty *vty, struct prefix *p,
                vty_out(vty, "%s", bgp_origin_str[attr->origin]);
 
        if (json_paths) {
+               if (safi == SAFI_EVPN &&
+                   attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
+                       json_ext_community = json_object_new_object();
+                       json_object_string_add(json_ext_community,
+                                              "string",
+                                              attr->ecommunity->str);
+                       json_object_object_add(json_path,
+                                              "extendedCommunity",
+                                              json_ext_community);
+               }
+
                if (nexthop_self)
                        json_object_boolean_true_add(json_path,
                                "announceNexthopSelf");
@@ -7363,6 +7386,13 @@ void route_vty_out(struct vty *vty, struct prefix *p,
                json_object_array_add(json_paths, json_path);
        } else {
                vty_out(vty, "\n");
+
+               if (safi == SAFI_EVPN &&
+                   attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
+                       vty_out(vty, "%*s", 20, " ");
+                       vty_out(vty, "%s\n", attr->ecommunity->str);
+               }
+
 #if ENABLE_BGP_VNC
                /* prints an additional line, indented, with VNC info, if
                 * present */
index 091d8f0317bbdceae91b2ddf1dec2d463f362eb8..6e0e079cd8a31ffaeeed0362c565b1c95bef0ade 100644 (file)
@@ -999,6 +999,8 @@ DEFUN_NOSH (router_bgp,
                if (is_new_bgp && inst_type == BGP_INSTANCE_TYPE_DEFAULT)
                        vpn_leak_postchange_all();
 
+               if (inst_type == BGP_INSTANCE_TYPE_VRF)
+                       bgp_vpn_leak_export(bgp);
                /* Pending: handle when user tries to change a view to vrf n vv.
                 */
        }
@@ -1081,6 +1083,9 @@ DEFUN (no_router_bgp,
                }
        }
 
+       if (bgp_vpn_leak_unimport(bgp, vty))
+               return CMD_WARNING_CONFIG_FAILED;
+
        bgp_delete(bgp);
 
        return CMD_SUCCESS;
@@ -11313,15 +11318,19 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
                                json_object_array_add(json_import_vrfs,
                                                json_object_new_string(vname));
 
+                       json_object_object_add(json, "importFromVrfs",
+                                                      json_import_vrfs);
                        dir = BGP_VPN_POLICY_DIR_FROMVPN;
-                       ecom_str = ecommunity_ecom2str(
+                       if (bgp->vpn_policy[afi].rtlist[dir]) {
+                               ecom_str = ecommunity_ecom2str(
                                        bgp->vpn_policy[afi].rtlist[dir],
                                        ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
-                       json_object_object_add(json, "importFromVrfs",
-                                              json_import_vrfs);
-                       json_object_string_add(json, "importRts", ecom_str);
-
-                       XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
+                               json_object_string_add(json, "importRts",
+                                                      ecom_str);
+                               XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
+                       } else
+                               json_object_string_add(json, "importRts",
+                                                      "none");
                }
 
                if (!CHECK_FLAG(bgp->af_flags[afi][safi],
@@ -11345,12 +11354,16 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
                                                 buf1, RD_ADDRSTRLEN));
 
                        dir = BGP_VPN_POLICY_DIR_TOVPN;
-                       ecom_str = ecommunity_ecom2str(
+                       if (bgp->vpn_policy[afi].rtlist[dir]) {
+                               ecom_str = ecommunity_ecom2str(
                                               bgp->vpn_policy[afi].rtlist[dir],
                                               ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
-                       json_object_string_add(json, "exportRts", ecom_str);
-
-                       XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
+                               json_object_string_add(json, "exportRts",
+                                                      ecom_str);
+                               XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
+                       } else
+                               json_object_string_add(json, "exportRts",
+                                                      "none");
                }
 
                if (use_json) {
@@ -11383,12 +11396,16 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
                                vty_out(vty, "  %s\n", vname);
 
                        dir = BGP_VPN_POLICY_DIR_FROMVPN;
-                       ecom_str = ecommunity_ecom2str(
+                       ecom_str = NULL;
+                       if (bgp->vpn_policy[afi].rtlist[dir]) {
+                               ecom_str = ecommunity_ecom2str(
                                               bgp->vpn_policy[afi].rtlist[dir],
                                               ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
-                       vty_out(vty, "Import RT(s): %s\n", ecom_str);
+                               vty_out(vty, "Import RT(s): %s\n", ecom_str);
 
-                       XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
+                               XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
+                       } else
+                               vty_out(vty, "Import RT(s):\n");
                }
 
                if (!CHECK_FLAG(bgp->af_flags[afi][safi],
@@ -11411,11 +11428,14 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
                                              buf1, RD_ADDRSTRLEN));
 
                        dir = BGP_VPN_POLICY_DIR_TOVPN;
-                       ecom_str = ecommunity_ecom2str(
+                       if (bgp->vpn_policy[afi].rtlist[dir]) {
+                               ecom_str = ecommunity_ecom2str(
                                        bgp->vpn_policy[afi].rtlist[dir],
                                        ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
-                       vty_out(vty, "Export RT: %s\n", ecom_str);
-                       XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
+                               vty_out(vty, "Export RT: %s\n", ecom_str);
+                               XFREE(MTYPE_ECOMMUNITY_STR, ecom_str);
+                       } else
+                               vty_out(vty, "Import RT(s):\n");
                }
        }
 
@@ -12298,7 +12318,7 @@ ALIAS_HIDDEN(
 
 DEFUN (no_bgp_redistribute_ipv4_ospf,
        no_bgp_redistribute_ipv4_ospf_cmd,
-       "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
+       "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
        NO_STR
        "Redistribute information from another routing protocol\n"
        "Open Shortest Path First (OSPFv2)\n"
@@ -12326,7 +12346,7 @@ DEFUN (no_bgp_redistribute_ipv4_ospf,
 
 ALIAS_HIDDEN(
        no_bgp_redistribute_ipv4_ospf, no_bgp_redistribute_ipv4_ospf_hidden_cmd,
-       "no redistribute <ospf|table> (1-65535) [metric (0-4294967295)] [route-map WORD]",
+       "no redistribute <ospf|table> (1-65535) [{metric (0-4294967295)|route-map WORD}]",
        NO_STR
        "Redistribute information from another routing protocol\n"
        "Open Shortest Path First (OSPFv2)\n"
@@ -12339,7 +12359,7 @@ ALIAS_HIDDEN(
 
 DEFUN (no_bgp_redistribute_ipv4,
        no_bgp_redistribute_ipv4_cmd,
-       "no redistribute " FRR_IP_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
+       "no redistribute " FRR_IP_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
        NO_STR
        "Redistribute information from another routing protocol\n"
        FRR_IP_REDIST_HELP_STR_BGPD
@@ -12363,7 +12383,7 @@ DEFUN (no_bgp_redistribute_ipv4,
 ALIAS_HIDDEN(
        no_bgp_redistribute_ipv4, no_bgp_redistribute_ipv4_hidden_cmd,
        "no redistribute " FRR_IP_REDIST_STR_BGPD
-       " [metric (0-4294967295)] [route-map WORD]",
+       " [{metric (0-4294967295)|route-map WORD}]",
        NO_STR
        "Redistribute information from another routing protocol\n" FRR_IP_REDIST_HELP_STR_BGPD
        "Metric for redistributed routes\n"
@@ -12522,7 +12542,7 @@ DEFUN (bgp_redistribute_ipv6_metric_rmap,
 
 DEFUN (no_bgp_redistribute_ipv6,
        no_bgp_redistribute_ipv6_cmd,
-       "no redistribute " FRR_IP6_REDIST_STR_BGPD " [metric (0-4294967295)] [route-map WORD]",
+       "no redistribute " FRR_IP6_REDIST_STR_BGPD " [{metric (0-4294967295)|route-map WORD}]",
        NO_STR
        "Redistribute information from another routing protocol\n"
        FRR_IP6_REDIST_HELP_STR_BGPD
index 5d1d430e9d8b7efc9474f0c5fadf9475bc4d4451..c0f2dfca176c709cb020e70e4957459719c7d679 100644 (file)
@@ -503,7 +503,7 @@ static int bgp_interface_vrf_update(ZAPI_CALLBACK_ARGS)
                }
        }
 
-       if_update_to_new_vrf(ifp, vrf_lookup_by_id(new_vrf_id));
+       if_update_to_new_vrf(ifp, new_vrf_id);
 
        bgp = bgp_lookup_by_vrf_id(new_vrf_id);
        if (!bgp)
@@ -787,7 +787,7 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote,
                nexthop->v4 = local->sin.sin_addr;
                if (peer->update_if)
                        ifp = if_lookup_by_name(peer->update_if,
-                                               vrf_lookup_by_id(peer->bgp->vrf_id));
+                                               peer->bgp->vrf_id);
                else
                        ifp = if_lookup_by_ipv4_exact(&local->sin.sin_addr,
                                                      peer->bgp->vrf_id);
@@ -799,11 +799,10 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote,
                                ifp = if_lookup_by_name(peer->conf_if
                                                                ? peer->conf_if
                                                                : peer->ifname,
-                                                       vrf_lookup_by_id(
-                                                                peer->bgp->vrf_id));
+                                                       peer->bgp->vrf_id);
                } else if (peer->update_if)
                        ifp = if_lookup_by_name(peer->update_if,
-                                       vrf_lookup_by_id(peer->bgp->vrf_id));
+                                               peer->bgp->vrf_id);
                else
                        ifp = if_lookup_by_ipv6_exact(&local->sin6.sin6_addr,
                                                      local->sin6.sin6_scope_id,
@@ -2884,8 +2883,7 @@ static void bgp_encode_pbr_interface_list(struct bgp *bgp, struct stream *s)
        head = &(bgp_pbr_cfg->ifaces_by_name_ipv4);
 
        RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) {
-               ifp = if_lookup_by_name(pbr_if->name,
-                                       vrf_lookup_by_id(bgp->vrf_id));
+               ifp = if_lookup_by_name(pbr_if->name, bgp->vrf_id);
                if (ifp)
                        stream_putl(s, ifp->ifindex);
        }
@@ -2903,8 +2901,7 @@ static int bgp_pbr_get_ifnumber(struct bgp *bgp)
        head = &(bgp_pbr_cfg->ifaces_by_name_ipv4);
 
        RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) {
-               if (if_lookup_by_name(pbr_if->name,
-                                     vrf_lookup_by_id(bgp->vrf_id)))
+               if (if_lookup_by_name(pbr_if->name, bgp->vrf_id))
                        cnt++;
        }
        return cnt;
index 8a96d46cd6c909c832b814c08824505c6d7d68a9..3ca209676f276e170e2513801dd0d45f97ec6e39 100644 (file)
@@ -1440,8 +1440,7 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer)
        hash_release(peer->bgp->peerhash, peer);
 
        prev_family = peer->su.sa.sa_family;
-       if ((ifp = if_lookup_by_name(peer->conf_if,
-                                    vrf_lookup_by_id(peer->bgp->vrf_id)))) {
+       if ((ifp = if_lookup_by_name(peer->conf_if, peer->bgp->vrf_id))) {
                peer->ifp = ifp;
                /* If BGP unnumbered is not "v6only", we first see if we can
                 * derive the
index 583adcda77cc17bf98b4ff3b68e78d588f5c8c46..87a05a4f8c12da32980638b13c4ffed218c03b14 100644 (file)
@@ -2402,6 +2402,18 @@ static int rfapiWithdrawTimerVPN(struct thread *t)
        struct rfapi_monitor_vpn *moved;
        afi_t afi;
 
+       if (bgp == NULL) {
+               vnc_zlog_debug_verbose(
+                   "%s: NULL BGP pointer, assume shutdown race condition!!!",
+                   __func__);
+               return 0;
+       }
+       if (bgp_flag_check(bgp, BGP_FLAG_DELETE_IN_PROGRESS)) {
+               vnc_zlog_debug_verbose(
+                   "%s: BGP delete in progress, assume shutdown race condition!!!",
+                   __func__);
+               return 0;
+       }
        assert(wcb->node);
        assert(bpi);
        assert(wcb->import_table);
index e8c74f7b87d4416cab22514694c57fc5309ff931..805d6264a87291f943c8d869267a44bc24de98c3 100644 (file)
@@ -151,6 +151,12 @@ Certain signals have special meanings to *pimd*.
    urib-only
       Lookup in the Unicast Rib only.
 
+.. index:: ip igmp generate-query-once [version (2-3)]
+.. clicmd:: ip igmp generate-query-once [version (2-3)]
+
+   Generate IGMP query (v2/v3) on user requirement. This will not depend on
+   the existing IGMP general query timer.If no version is provided in the cli,
+   it will be considered as default v2 query.This is a hidden command.
 
 .. _pim-interface-configuration:
 
index ef9ebe8ddc3d4caba1e0c132a18d50f4a2612738..bac61cbc58e435dc6e2fcba62777be48e3aedbe1 100644 (file)
@@ -85,6 +85,23 @@ deny
 cont
    goto next route-map entry
 
+.. _route-map-show-command:
+
+.. index:: show route-map [WORD]
+.. clicmd:: show route-map [WORD]
+
+   Display data about each daemons knowledge of individual route-maps.
+   If WORD is supplied narrow choice to that particular route-map.
+
+.. _route-map-clear-counter-command:
+
+.. index:: clear route-map counter [WORD]
+.. clicmd:: clear route-map counter [WORD]
+
+   Clear counters that are being stored about the route-map utilization
+   so that subsuquent show commands will indicate since the last clear.
+   If WORD is specified clear just that particular route-map's counters.
+
 .. _route-map-command:
 
 Route Map Command
@@ -315,6 +332,7 @@ Route Map Exit Action Command
 
    Proceed processing the route-map at the first entry whose order is >= N
 
+
 Route Map Examples
 ==================
 
index 7727fd96c8ab4c8ae24bf2da9269530ca1ef40e5..93eed9452ccbb6ab4ad9174b45f4f4f2b90a0908 100644 (file)
@@ -174,8 +174,7 @@ void eigrp_distribute_update(struct distribute_ctx *ctx,
                return;
        }
 
-       ifp = if_lookup_by_name(dist->ifname,
-                               vrf_lookup_by_id(VRF_DEFAULT));
+       ifp = if_lookup_by_name(dist->ifname, VRF_DEFAULT);
        if (ifp == NULL)
                return;
 
index 10f8df6f1d1906be0faf87335afe1b63d6c9b8d0..f080ba48769f78c369431e57e5c1f283da3c5b99 100644 (file)
@@ -62,7 +62,7 @@ void eigrp_if_rmap_update(struct if_rmap *if_rmap)
        struct route_map *rmap;
        struct eigrp *e;
 
-       ifp = if_lookup_by_name(if_rmap->ifname, vrf_lookup_by_id(VRF_DEFAULT));
+       ifp = if_lookup_by_name(if_rmap->ifname);
        if (ifp == NULL)
                return;
 
index 5040386e886f8e2a0f581bbe6a1222635bf5e190..0a74e86263a320f1b65ec76a23cef07e9e186409 100644 (file)
@@ -336,8 +336,7 @@ static struct interface *zebra_interface_if_lookup(struct stream *s)
        stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
 
        /* And look it up. */
-       return if_lookup_by_name(ifname_tmp,
-                                vrf_lookup_by_id(VRF_DEFAULT));
+       return if_lookup_by_name(ifname_tmp, VRF_DEFAULT);
 }
 
 void eigrp_zebra_route_add(struct prefix *p, struct list *successors,
index d2733ebaff58424512da7720bdf2ea9ed284d212..0334b98a122fb71c54a0704b8d97cf068a266457 100644 (file)
@@ -97,7 +97,8 @@ DEFPY(no_router_isis, no_router_isis_cmd, "no router isis WORD$tag",
                        /* add callbacks to delete each of the circuits listed
                         */
                        const char *vrf_name =
-                               circuit->interface->vrf->name;
+                               vrf_lookup_by_id(circuit->interface->vrf_id)
+                                       ->name;
                        snprintf(
                                temp_xpath, XPATH_MAXLEN,
                                "/frr-interface:lib/interface[name='%s'][vrf='%s']/frr-isisd:isis",
index fa3c5398b078210e226419e8ed219b4d289eb12e..ffc6ee0464b69f27b27746d80ac870c9bb83d2af 100644 (file)
@@ -1597,7 +1597,7 @@ static int lib_interface_isis_area_tag_modify(enum nb_event event,
                vrfname = yang_dnode_get_string(dnode->parent->parent, "./vrf");
                vrf = vrf_lookup_by_name(vrfname);
                assert(vrf);
-               ifp = if_lookup_by_name(ifname, vrf);
+               ifp = if_lookup_by_name(ifname, vrf->vrf_id);
                if (!ifp)
                        return NB_OK;
                circuit = circuit_lookup_by_ifp(ifp, isis->init_circ_list);
@@ -1635,7 +1635,7 @@ static int lib_interface_isis_circuit_type_modify(enum nb_event event,
                vrfname = yang_dnode_get_string(dnode->parent->parent, "./vrf");
                vrf = vrf_lookup_by_name(vrfname);
                assert(vrf);
-               ifp = if_lookup_by_name(ifname, vrf);
+               ifp = if_lookup_by_name(ifname, vrf->vrf_id);
                if (!ifp)
                        break;
                circuit = circuit_lookup_by_ifp(ifp, isis->init_circ_list);
index a56c2836d0fda385cc57b45215a2622cdf4d7f66..4ea6c2c60d657901cb6c8f9a8ea1252348ea1baa 100644 (file)
@@ -1175,8 +1175,7 @@ DEFUN (show_isis_mpls_te_interface,
                }
        } else {
                /* Interface name is specified. */
-               ifp = if_lookup_by_name(argv[idx_interface]->arg,
-                                       vrf_lookup_by_id(VRF_DEFAULT));
+               ifp = if_lookup_by_name(argv[idx_interface]->arg, VRF_DEFAULT);
                if (ifp == NULL)
                        vty_out(vty, "No such interface name\n");
                else {
index 1b304a98b2b151dcaa51084d98383b7c340a31cc..062a4bb30c0395c3e02fbd72866c46d86cf1fc5a 100644 (file)
@@ -46,6 +46,7 @@
 %code requires {
   #include "config.h"
 
+  #include <stdbool.h>
   #include <stdlib.h>
   #include <string.h>
   #include <ctype.h>
   static void
   cleanup (struct parser_ctx *ctx);
 
+  static void loopcheck(struct parser_ctx *ctx, struct subgraph *sg);
+
   #define scanner ctx->scanner
 }
 
@@ -335,6 +338,7 @@ selector: '{' selector_seq_seq '}' varname_token
    * just use [{a|b}] if neccessary, that will work perfectly fine, and reason
    * #1 is good enough to keep it this way. */
 
+  loopcheck(ctx, &$$);
   cmd_token_varname_set ($2.end->data, $4);
   XFREE (MTYPE_LEX, $4);
 };
@@ -396,6 +400,38 @@ cmd_graph_parse (struct graph *graph, struct cmd_element *cmd)
 
 /* parser helper functions */
 
+static bool loopcheck_inner(struct graph_node *start, struct graph_node *node,
+                           struct graph_node *end, size_t depth)
+{
+       size_t i;
+       bool ret;
+
+       /* safety check */
+       if (depth++ == 64)
+               return true;
+
+       for (i = 0; i < vector_active(node->to); i++) {
+               struct graph_node *next = vector_slot(node->to, i);
+               struct cmd_token *tok = next->data;
+
+               if (next == end || next == start)
+                       return true;
+               if (tok->type < SPECIAL_TKN)
+                       continue;
+               ret = loopcheck_inner(start, next, end, depth);
+               if (ret)
+                       return true;
+       }
+       return false;
+}
+
+static void loopcheck(struct parser_ctx *ctx, struct subgraph *sg)
+{
+       if (loopcheck_inner(sg->start, sg->start, sg->end, 0))
+               zlog_err("FATAL: '%s': {} contains an empty path! Use [{...}]",
+                        ctx->el->string);
+}
+
 void
 yyerror (CMD_YYLTYPE *loc, struct parser_ctx *ctx, char const *msg)
 {
index 8885fb11a3af4c6e8c458e442baf54bb37412691..f7a167f251b95d2e524933ca708e5041d86dfcc7 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -132,8 +132,9 @@ static int if_cmp_index_func(const struct interface *ifp1,
 }
 
 /* Create new interface structure. */
-struct interface *if_create(const char *name, struct vrf *vrf)
+struct interface *if_create(const char *name, vrf_id_t vrf_id)
 {
+       struct vrf *vrf = vrf_get(vrf_id, NULL);
        struct interface *ifp;
 
        ifp = XCALLOC(MTYPE_IF, sizeof(struct interface));
@@ -141,7 +142,7 @@ struct interface *if_create(const char *name, struct vrf *vrf)
 
        assert(name);
        strlcpy(ifp->name, name, sizeof(ifp->name));
-       ifp->vrf = vrf;
+       ifp->vrf_id = vrf_id;
        IFNAME_RB_INSERT(vrf, ifp);
        ifp->connected = list_new();
        ifp->connected->del = (void (*)(void *))connected_free;
@@ -157,34 +158,26 @@ struct interface *if_create(const char *name, struct vrf *vrf)
        return ifp;
 }
 
-/* Create new interface structure.
- * vrf must be created outside of this routing
- */
-void if_update_to_new_vrf(struct interface *ifp, struct vrf *vrf)
+/* Create new interface structure. */
+void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id)
 {
-       struct vrf *old_vrf;
+       struct vrf *old_vrf, *vrf;
 
-       if (!vrf) {
-               flog_err(EC_LIB_INTERFACE, "interface %s. Unknown VRF",
-                        ifp->name);
-               return;
-       }
        /* remove interface from old master vrf list */
-       old_vrf = ifp->vrf;
+       old_vrf = vrf_lookup_by_id(ifp->vrf_id);
        if (old_vrf) {
                IFNAME_RB_REMOVE(old_vrf, ifp);
                if (ifp->ifindex != IFINDEX_INTERNAL)
                        IFINDEX_RB_REMOVE(old_vrf, ifp);
        }
 
-       ifp->vrf = vrf;
+       ifp->vrf_id = vrf_id;
+       vrf = vrf_get(ifp->vrf_id, NULL);
 
        IFNAME_RB_INSERT(vrf, ifp);
        if (ifp->ifindex != IFINDEX_INTERNAL)
                IFINDEX_RB_INSERT(vrf, ifp);
 
-       if (!old_vrf->name)
-               return;
        /*
         * HACK: Change the interface VRF in the running configuration directly,
         * bypassing the northbound layer. This is necessary to avoid deleting
@@ -225,8 +218,9 @@ void if_delete_retain(struct interface *ifp)
 /* Delete and free interface structure. */
 void if_delete(struct interface *ifp)
 {
-       struct vrf *vrf = ifp->vrf;
+       struct vrf *vrf;
 
+       vrf = vrf_lookup_by_id(ifp->vrf_id);
        assert(vrf);
 
        IFNAME_RB_REMOVE(vrf, ifp);
@@ -271,16 +265,16 @@ const char *ifindex2ifname(ifindex_t ifindex, vrf_id_t vrf_id)
 ifindex_t ifname2ifindex(const char *name, vrf_id_t vrf_id)
 {
        struct interface *ifp;
-       struct vrf *vrf = vrf_lookup_by_id(vrf_id);
 
-       return ((ifp = if_lookup_by_name(name, vrf)) != NULL)
+       return ((ifp = if_lookup_by_name(name, vrf_id)) != NULL)
                       ? ifp->ifindex
                       : IFINDEX_INTERNAL;
 }
 
 /* Interface existance check by interface name. */
-struct interface *if_lookup_by_name(const char *name, struct vrf *vrf)
+struct interface *if_lookup_by_name(const char *name, vrf_id_t vrf_id)
 {
+       struct vrf *vrf = vrf_lookup_by_id(vrf_id);
        struct interface if_tmp;
 
        if (!vrf || !name
@@ -300,7 +294,7 @@ struct interface *if_lookup_by_name_all_vrf(const char *name)
                return NULL;
 
        RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
-               ifp = if_lookup_by_name(name, vrf);
+               ifp = if_lookup_by_name(name, vrf->vrf_id);
                if (ifp)
                        return ifp;
        }
@@ -425,29 +419,29 @@ size_t if_lookup_by_hwaddr(const uint8_t *hw_addr, size_t addrsz,
 
 /* Get interface by name if given name interface doesn't exist create
    one. */
-struct interface *if_get_by_name(const char *name, struct vrf *vrf)
+struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id)
 {
        struct interface *ifp;
 
        switch (vrf_get_backend()) {
        case VRF_BACKEND_UNKNOWN:
        case VRF_BACKEND_NETNS:
-               ifp = if_lookup_by_name(name, vrf);
+               ifp = if_lookup_by_name(name, vrf_id);
                if (ifp)
                        return ifp;
-               return if_create(name, vrf);
+               return if_create(name, vrf_id);
        case VRF_BACKEND_VRF_LITE:
                ifp = if_lookup_by_name_all_vrf(name);
                if (ifp) {
-                       if (ifp->vrf == vrf)
+                       if (ifp->vrf_id == vrf_id)
                                return ifp;
                        /* If it came from the kernel or by way of zclient,
                         * believe it and update the ifp accordingly.
                         */
-                       if_update_to_new_vrf(ifp, vrf);
+                       if_update_to_new_vrf(ifp, vrf_id);
                        return ifp;
                }
-               return if_create(name, vrf);
+               return if_create(name, vrf_id);
        }
 
        return NULL;
@@ -457,7 +451,7 @@ void if_set_index(struct interface *ifp, ifindex_t ifindex)
 {
        struct vrf *vrf;
 
-       vrf = ifp->vrf;
+       vrf = vrf_lookup_by_id(ifp->vrf_id);
        assert(vrf);
 
        if (ifp->ifindex == ifindex)
@@ -601,8 +595,7 @@ static void if_dump(const struct interface *ifp)
                zlog_info(
                        "Interface %s vrf %u index %d metric %d mtu %d "
                        "mtu6 %d %s",
-                       ifp->name, vrf_to_id(ifp->vrf),
-                       ifp->ifindex, ifp->metric,
+                       ifp->name, ifp->vrf_id, ifp->ifindex, ifp->metric,
                        ifp->mtu, ifp->mtu6, if_flag_dump(ifp->flags));
 }
 
@@ -638,12 +631,12 @@ void if_dump_all(void)
  *     if not:
  *     - no idea, just get the name in its entirety.
  */
-static struct interface *if_sunwzebra_get(const char *name, struct vrf *vrf)
+static struct interface *if_sunwzebra_get(const char *name, vrf_id_t vrf_id)
 {
        struct interface *ifp;
        char *cp;
 
-       if ((ifp = if_lookup_by_name(name, vrf)) != NULL)
+       if ((ifp = if_lookup_by_name(name, vrf_id)) != NULL)
                return ifp;
 
        /* hunt the primary interface name... */
@@ -651,7 +644,7 @@ static struct interface *if_sunwzebra_get(const char *name, struct vrf *vrf)
        if (cp)
                *cp = '\0';
 
-       return if_get_by_name(name, vrf);
+       return if_get_by_name(name, vrf_id);
 }
 #endif /* SUNOS_5 */
 
@@ -784,8 +777,7 @@ connected_log(struct connected *connected, char *str)
        p = connected->address;
 
        snprintf(logbuf, BUFSIZ, "%s interface %s vrf %u %s %s/%d ", str,
-                ifp->name, vrf_to_id(ifp->vrf),
-                prefix_family_str(p),
+                ifp->name, ifp->vrf_id, prefix_family_str(p),
                 inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
 
        p = connected->destination;
@@ -1134,9 +1126,9 @@ DEFPY_NOSH (interface,
        VRF_CMD_HELP_STR)
 {
        char xpath_list[XPATH_MAXLEN];
-       struct interface *ifp = NULL;
+       vrf_id_t vrf_id;
+       struct interface *ifp;
        int ret;
-       struct vrf *vrf;
 
        if (!vrfname)
                vrfname = VRF_DEFAULT_NAME;
@@ -1148,24 +1140,16 @@ DEFPY_NOSH (interface,
         * interface is found, then a new one should be created on the default
         * VRF.
         */
-       VRF_GET_INSTANCE(vrf, vrfname, false, true);
-       /*
-        * within vrf context, vrf_id may be unknown
-        * this happens on daemons relying on zebra
-        * on this specific case, interface creation may
-        * be forced
-        */
-       if (vrf && (vrf->vrf_id == VRF_UNKNOWN ||
-                   vrf_get_backend() == VRF_BACKEND_UNKNOWN))
-               ifp = if_lookup_by_name(ifname, vrf);
-       else
-               ifp = if_lookup_by_name_all_vrf(ifname);
-       if (ifp && ifp->vrf != vrf) {
+       VRF_GET_ID(vrf_id, vrfname, false);
+       ifp = if_lookup_by_name_all_vrf(ifname);
+       if (ifp && ifp->vrf_id != vrf_id) {
+               struct vrf *vrf;
+
                /*
                 * Special case 1: a VRF name was specified, but the found
                 * interface is associated to different VRF. Reject the command.
                 */
-               if (vrf->vrf_id != VRF_DEFAULT) {
+               if (vrf_id != VRF_DEFAULT) {
                        vty_out(vty, "%% interface %s not in %s vrf\n", ifname,
                                vrfname);
                        return CMD_WARNING_CONFIG_FAILED;
@@ -1176,8 +1160,9 @@ DEFPY_NOSH (interface,
                 * interface is associated to a VRF other than the default one.
                 * Update vrf_id and vrfname to account for that.
                 */
-               vrf = ifp->vrf;
+               vrf = vrf_lookup_by_id(ifp->vrf_id);
                assert(vrf);
+               vrf_id = ifp->vrf_id;
                vrfname = vrf->name;
        }
 
@@ -1196,7 +1181,7 @@ DEFPY_NOSH (interface,
                 * all interface-level commands are converted to the new
                 * northbound model.
                 */
-               ifp = if_lookup_by_name(ifname, vrf);
+               ifp = if_lookup_by_name(ifname, vrf_id);
                if (ifp)
                        VTY_PUSH_CONTEXT(INTERFACE_NODE, ifp);
        }
@@ -1318,7 +1303,7 @@ static int lib_interface_create(enum nb_event event,
        const char *ifname;
        const char *vrfname;
        struct vrf *vrf;
-       struct interface *ifp = NULL;
+       struct interface *ifp;
 
        ifname = yang_dnode_get_string(dnode, "./name");
        vrfname = yang_dnode_get_string(dnode, "./vrf");
@@ -1331,9 +1316,11 @@ static int lib_interface_create(enum nb_event event,
                                  vrfname);
                        return NB_ERR_VALIDATION;
                }
-               if (vrf->vrf_id == VRF_UNKNOWN)
-                       zlog_warn("%s: VRF %s is not active. Using interface however.",
-                                 __func__, vrf->name);
+               if (vrf->vrf_id == VRF_UNKNOWN) {
+                       zlog_warn("%s: VRF %s is not active", __func__,
+                                 vrf->name);
+                       return NB_ERR_VALIDATION;
+               }
 
                /* if VRF is netns or not yet known - init for instance
                 * then assumption is that passed config is exact
@@ -1341,7 +1328,7 @@ static int lib_interface_create(enum nb_event event,
                 */
                if (vrf_get_backend() == VRF_BACKEND_VRF_LITE) {
                        ifp = if_lookup_by_name_all_vrf(ifname);
-                       if (ifp && ifp->vrf != vrf) {
+                       if (ifp && ifp->vrf_id != vrf->vrf_id) {
                                zlog_warn(
                                        "%s: interface %s already exists in another VRF",
                                        __func__, ifp->name);
@@ -1356,9 +1343,9 @@ static int lib_interface_create(enum nb_event event,
                vrf = vrf_lookup_by_name(vrfname);
                assert(vrf);
 #ifdef SUNOS_5
-               ifp = if_sunwzebra_get(ifname, vrf);
+               ifp = if_sunwzebra_get(ifname, vrf->vrf_id);
 #else
-               ifp = if_get_by_name(ifname, vrf);
+               ifp = if_get_by_name(ifname, vrf->vrf_id);
 #endif /* SUNOS_5 */
                nb_running_set_entry(dnode, ifp);
                break;
index 3237cab1d6c2380be36603d738eeac83c7435fee..603c9c3780cfd2beed09e9ec20d18b9cce21a619 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -33,8 +33,6 @@ extern "C" {
 
 DECLARE_MTYPE(CONNECTED_LABEL)
 
-struct vrf;
-
 /* Interface link-layer type, if known. Derived from:
  *
  * net/if_arp.h on various platforms - Linux especially.
@@ -293,7 +291,7 @@ struct interface {
 #endif /* HAVE_NET_RT_IFLIST */
 
        struct route_node *node;
-       struct vrf *vrf;
+       vrf_id_t vrf_id;
 
        QOBJ_FIELDS
 };
@@ -304,37 +302,33 @@ RB_HEAD(if_index_head, interface);
 RB_PROTOTYPE(if_index_head, interface, index_entry, if_cmp_func)
 DECLARE_QOBJ_TYPE(interface)
 
-#define IFNAME_RB_INSERT(_vrf, _ifp)                                           \
-       if (RB_INSERT(if_name_head, &(_vrf)->ifaces_by_name, (_ifp)))          \
+#define IFNAME_RB_INSERT(vrf, ifp)                                             \
+       if (RB_INSERT(if_name_head, &vrf->ifaces_by_name, (ifp)))              \
                flog_err(EC_LIB_INTERFACE,                                     \
                         "%s(%s): corruption detected -- interface with this " \
                         "name exists already in VRF %u!",                     \
-                        __func__, (_ifp)->name, (_ifp)->vrf ?                 \
-                        (_ifp)->vrf->vrf_id : VRF_UNKNOWN);
+                        __func__, (ifp)->name, (ifp)->vrf_id);
 
-#define IFNAME_RB_REMOVE(_vrf, _ifp)                                           \
-       if (RB_REMOVE(if_name_head, &(_vrf)->ifaces_by_name, (_ifp)) == NULL)  \
+#define IFNAME_RB_REMOVE(vrf, ifp)                                             \
+       if (RB_REMOVE(if_name_head, &vrf->ifaces_by_name, (ifp)) == NULL)      \
                flog_err(EC_LIB_INTERFACE,                                     \
                         "%s(%s): corruption detected -- interface with this " \
                         "name doesn't exist in VRF %u!",                      \
-                        __func__, (_ifp)->name, (_ifp)->vrf ?                 \
-                        (_ifp)->vrf->vrf_id : VRF_UNKNOWN);
+                        __func__, (ifp)->name, (ifp)->vrf_id);
 
-#define IFINDEX_RB_INSERT(_vrf, _ifp)                                          \
-       if (RB_INSERT(if_index_head, &(_vrf)->ifaces_by_index, (_ifp)))        \
+#define IFINDEX_RB_INSERT(vrf, ifp)                                            \
+       if (RB_INSERT(if_index_head, &vrf->ifaces_by_index, (ifp)))            \
                flog_err(EC_LIB_INTERFACE,                                     \
                         "%s(%u): corruption detected -- interface with this " \
                         "ifindex exists already in VRF %u!",                  \
-                        __func__, (_ifp)->ifindex, (_ifp)->vrf ?              \
-                        (_ifp)->vrf->vrf_id : VRF_UNKNOWN);
+                        __func__, (ifp)->ifindex, (ifp)->vrf_id);
 
-#define IFINDEX_RB_REMOVE(_vrf, _ifp)                                          \
-       if (RB_REMOVE(if_index_head, &(_vrf)->ifaces_by_index, (_ifp)) == NULL)\
+#define IFINDEX_RB_REMOVE(vrf, ifp)                                            \
+       if (RB_REMOVE(if_index_head, &vrf->ifaces_by_index, (ifp)) == NULL)    \
                flog_err(EC_LIB_INTERFACE,                                     \
                         "%s(%u): corruption detected -- interface with this " \
                         "ifindex doesn't exist in VRF %u!",                   \
-                        __func__, (_ifp)->ifindex, (_ifp)->vrf ?              \
-                        (_ifp)->vrf->vrf_id : VRF_UNKNOWN);
+                        __func__, (ifp)->ifindex, (ifp)->vrf_id);
 
 #define FOR_ALL_INTERFACES(vrf, ifp)                                           \
        if (vrf)                                                               \
@@ -482,8 +476,8 @@ extern int if_cmp_name_func(const char *p1, const char *p2);
  * This is useful for vrf route-leaking.  So more than anything
  * else think before you use VRF_UNKNOWN
  */
-extern void if_update_to_new_vrf(struct interface *, struct vrf *vrf);
-extern struct interface *if_create(const char *name, struct vrf *vrf);
+extern void if_update_to_new_vrf(struct interface *, vrf_id_t vrf_id);
+extern struct interface *if_create(const char *name, vrf_id_t vrf_id);
 extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id);
 extern struct interface *if_lookup_exact_address(void *matchaddr, int family,
                                                 vrf_id_t vrf_id);
@@ -497,8 +491,8 @@ size_t if_lookup_by_hwaddr(const uint8_t *hw_addr, size_t addrsz,
 /* These 3 functions are to be used when the ifname argument is terminated
    by a '\0' character: */
 extern struct interface *if_lookup_by_name_all_vrf(const char *ifname);
-extern struct interface *if_lookup_by_name(const char *ifname, struct vrf *vrf);
-extern struct interface *if_get_by_name(const char *ifname, struct vrf *vrf);
+extern struct interface *if_lookup_by_name(const char *ifname, vrf_id_t vrf_id);
+extern struct interface *if_get_by_name(const char *ifname, vrf_id_t vrf_id);
 extern void if_set_index(struct interface *ifp, ifindex_t ifindex);
 
 /* Delete the interface, but do not free the structure, and leave it in the
index 6e6a1d99e01e814c642a52c4b45e75425322a68f..2fee3a479efe110cf8cc896d309c18cbe817c887 100644 (file)
@@ -960,12 +960,12 @@ static void vty_show_route_map_entry(struct vty *vty, struct route_map *map)
        struct route_map_rule *rule;
 
        vty_out(vty, "route-map: %s Invoked: %" PRIu64 "\n",
-               map->name, map->applied);
+               map->name, map->applied - map->applied_clear);
 
        for (index = map->head; index; index = index->next) {
                vty_out(vty, " %s, sequence %d Invoked %" PRIu64 "\n",
                        route_map_type_str(index->type), index->pref,
-                       index->applied);
+                       index->applied - index->applied_clear);
 
                /* Description */
                if (index->description)
@@ -2956,6 +2956,46 @@ DEFUN (no_rmap_continue,
        return no_rmap_onmatch_goto(self, vty, argc, argv);
 }
 
+static void clear_route_map_helper(struct route_map *map)
+{
+       struct route_map_index *index;
+
+       map->applied_clear = map->applied;
+       for (index = map->head; index; index = index->next)
+               index->applied_clear = index->applied;
+}
+
+DEFUN (rmap_clear_counters,
+       rmap_clear_counters_cmd,
+       "clear route-map counters [WORD]",
+       CLEAR_STR
+       "route-map information\n"
+       "counters associated with the specified route-map\n"
+       "route-map name\n")
+{
+       int idx_word = 2;
+       struct route_map *map;
+
+       const char *name = (argc == 3 ) ? argv[idx_word]->arg : NULL;
+
+       if (name) {
+               map = route_map_lookup_by_name(name);
+
+               if (map)
+                       clear_route_map_helper(map);
+               else {
+                       vty_out(vty, "%s: 'route-map %s' not found\n",
+                               frr_protonameinst, name);
+                       return CMD_SUCCESS;
+               }
+       } else {
+               for (map = route_map_master.head; map; map = map->next)
+                       clear_route_map_helper(map);
+       }
+
+       return CMD_SUCCESS;
+
+}
 
 DEFUN (rmap_show_name,
        rmap_show_name_cmd,
@@ -3093,8 +3133,15 @@ static int route_map_config_write(struct vty *vty)
        struct route_map_rule *rule;
        int first = 1;
        int write = 0;
+       struct listnode *ln;
+       struct list *maplist = list_new();
 
        for (map = route_map_master.head; map; map = map->next)
+               listnode_add(maplist, map);
+
+       list_sort(maplist, sort_route_map);
+
+       for (ALL_LIST_ELEMENTS_RO(maplist, ln, map))
                for (index = map->head; index; index = index->next) {
                        if (!first)
                                vty_out(vty, "!\n");
@@ -3127,6 +3174,8 @@ static int route_map_config_write(struct vty *vty)
 
                        write++;
                }
+
+       list_delete(&maplist);
        return write;
 }
 
@@ -3291,6 +3340,8 @@ void route_map_init(void)
        install_element(RMAP_NODE, &no_rmap_description_cmd);
 
        /* Install show command */
+       install_element(ENABLE_NODE, &rmap_clear_counters_cmd);
+
        install_element(ENABLE_NODE, &rmap_show_name_cmd);
        install_element(ENABLE_NODE, &rmap_show_unused_cmd);
 
index 3781d227df8ae45e2557edfb712ec17dd9c46792..90df1048ed4b7e5780a20e0b1468dad77bcb498e 100644 (file)
@@ -153,6 +153,7 @@ struct route_map_index {
 
        /* Keep track how many times we've try to apply */
        uint64_t applied;
+       uint64_t applied_clear;
 
        QOBJ_FIELDS
 };
@@ -177,6 +178,7 @@ struct route_map {
 
        /* How many times have we applied this route-map */
        uint64_t applied;
+       uint64_t applied_clear;
 
        /* Counter to track active usage of this route-map */
        uint16_t use_count;
index 2efc64b090f3193de351a40451731b7df0c60569..229f19f29ae877a2f2b02ae7c9b65c27e36ae634 100644 (file)
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -176,24 +176,6 @@ struct vrf *vrf_get(vrf_id_t vrf_id, const char *name)
                           name, vrf_id, vrf->vrf_id);
                return NULL;
        }
-       /* look for duplicates. case is followine one:
-        * - a vrf is configured per name -> vrfA
-        * - netlink discovery creates a vrf with vrf_id ->vrfB
-        * - then, netlink discovers vrf, and associated vrf_id and name
-        * -> so vrfA and vrfB must be merged
-        */
-       if (vrf && vrf_id != VRF_UNKNOWN
-           && vrf->vrf_id == VRF_UNKNOWN) {
-               struct vrf *vrf2 = vrf_lookup_by_id(vrf_id);
-               struct interface *ifp;
-
-               if (vrf2 && !vrf2->name && vrf2 != vrf) {
-                       /* move vrf2 context to vrf */
-                       FOR_ALL_INTERFACES (vrf2, ifp)
-                               if_update_to_new_vrf(ifp, vrf);
-                       vrf_delete(vrf2);
-               }
-       }
        /* Try to find VRF both by ID and name */
        if (!vrf && vrf_id != VRF_UNKNOWN)
                vrf = vrf_lookup_by_id(vrf_id);
@@ -923,15 +905,14 @@ int vrf_bind(vrf_id_t vrf_id, int fd, const char *name)
 {
        int ret = 0;
        struct interface *ifp;
-       struct vrf *vrf = vrf_lookup_by_id(vrf_id);
 
-       if (fd < 0 || name == NULL || !vrf)
+       if (fd < 0 || name == NULL)
                return fd;
        /* the device should exist
         * otherwise we should return
         * case ifname = vrf in netns mode => return
         */
-       ifp = if_lookup_by_name(name, vrf);
+       ifp = if_lookup_by_name(name, vrf_id);
        if (!ifp)
                return fd;
 #ifdef SO_BINDTODEVICE
@@ -1018,13 +999,3 @@ vrf_id_t vrf_generate_id(void)
 
        return ++vrf_id_local;
 }
-
-vrf_id_t vrf_to_id(struct vrf *vrf)
-{
-       return vrf ? vrf->vrf_id : VRF_UNKNOWN;
-}
-
-const char *vrf_to_name(struct vrf *vrf)
-{
-       return vrf ? vrf->name : "NIL";
-}
index 169feb6f52aa951e85b6748747f4d219c1b104d9..ca253e58a3618c2c83cee703d7ba26649998a9f7 100644 (file)
--- a/lib/vrf.h
+++ b/lib/vrf.h
@@ -113,36 +113,6 @@ extern struct vrf *vrf_lookup_by_name(const char *);
 extern struct vrf *vrf_get(vrf_id_t, const char *);
 extern const char *vrf_id_to_name(vrf_id_t vrf_id);
 extern vrf_id_t vrf_name_to_id(const char *);
-extern vrf_id_t vrf_to_id(struct vrf *vrf);
-extern const char *vrf_to_name(struct vrf *vrf);
-
-/* vrf context is searched and created
- */
-#define VRF_GET_INSTANCE(V, NAME, USE_JSON, FORCE_CREATION)                   \
-       do {                                                                   \
-               struct vrf *_vrf;                                              \
-                                                                              \
-               if (!(_vrf = vrf_lookup_by_name(NAME))) {                      \
-                       if (!FORCE_CREATION) {                                 \
-                               if (USE_JSON) {                                \
-                                       vty_out(vty, "{}\n");                  \
-                               } else {                                       \
-                                       vty_out(vty, "%% VRF %s not found\n",  \
-                                               NAME);                         \
-                               }                                              \
-                               return CMD_WARNING;                            \
-                       }                                                      \
-                       _vrf = vrf_get(VRF_UNKNOWN, NAME);                     \
-               }                                                              \
-               if (_vrf->vrf_id == VRF_UNKNOWN) {                             \
-                       if (USE_JSON) {                                        \
-                               vty_out(vty, "{}\n");                          \
-                       } else {                                               \
-                               vty_out(vty, "%% VRF %s not active\n", NAME);  \
-                       }                                                      \
-               }                                                              \
-               (V) = _vrf;                                                    \
-       } while (0)
 
 #define VRF_GET_ID(V, NAME, USE_JSON)                                          \
        do {                                                                   \
index 0db3dc36f2249c6b61b6b18d21e9b2c4888039c9..18a449f647ad017a3c3292067d5876b43dde95df 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -1335,7 +1335,6 @@ static int vty_read(struct thread *thread)
 
        int vty_sock = THREAD_FD(thread);
        struct vty *vty = THREAD_ARG(thread);
-       vty->t_read = NULL;
 
        /* Read raw data from socket */
        if ((nbytes = read(vty->fd, buf, VTY_READ_BUFSIZ)) <= 0) {
@@ -1529,13 +1528,9 @@ static int vty_flush(struct thread *thread)
        int vty_sock = THREAD_FD(thread);
        struct vty *vty = THREAD_ARG(thread);
 
-       vty->t_write = NULL;
-
        /* Tempolary disable read thread. */
-       if ((vty->lines == 0) && vty->t_read) {
-               thread_cancel(vty->t_read);
-               vty->t_read = NULL;
-       }
+       if (vty->lines == 0)
+               THREAD_OFF(vty->t_read);
 
        /* Function execution continue. */
        erase = ((vty->status == VTY_MORE || vty->status == VTY_MORELINE));
@@ -1713,12 +1708,9 @@ void vty_stdio_suspend(void)
        if (!stdio_vty)
                return;
 
-       if (stdio_vty->t_write)
-               thread_cancel(stdio_vty->t_write);
-       if (stdio_vty->t_read)
-               thread_cancel(stdio_vty->t_read);
-       if (stdio_vty->t_timeout)
-               thread_cancel(stdio_vty->t_timeout);
+       THREAD_OFF(stdio_vty->t_write);
+       THREAD_OFF(stdio_vty->t_read);
+       THREAD_OFF(stdio_vty->t_timeout);
 
        if (stdio_termios)
                tcsetattr(0, TCSANOW, &stdio_orig_termios);
@@ -2077,7 +2069,6 @@ static int vtysh_read(struct thread *thread)
 
        sock = THREAD_FD(thread);
        vty = THREAD_ARG(thread);
-       vty->t_read = NULL;
 
        if ((nbytes = read(sock, buf, VTY_READ_BUFSIZ)) <= 0) {
                if (nbytes < 0) {
@@ -2157,7 +2148,6 @@ static int vtysh_write(struct thread *thread)
 {
        struct vty *vty = THREAD_ARG(thread);
 
-       vty->t_write = NULL;
        vtysh_flush(vty);
        return 0;
 }
@@ -2193,12 +2183,9 @@ void vty_close(struct vty *vty)
        bool was_stdio = false;
 
        /* Cancel threads.*/
-       if (vty->t_read)
-               thread_cancel(vty->t_read);
-       if (vty->t_write)
-               thread_cancel(vty->t_write);
-       if (vty->t_timeout)
-               thread_cancel(vty->t_timeout);
+       THREAD_OFF(vty->t_read);
+       THREAD_OFF(vty->t_write);
+       THREAD_OFF(vty->t_timeout);
 
        /* Flush buffer. */
        buffer_flush_all(vty->obuf, vty->wfd);
@@ -2254,7 +2241,6 @@ static int vty_timeout(struct thread *thread)
        struct vty *vty;
 
        vty = THREAD_ARG(thread);
-       vty->t_timeout = NULL;
        vty->v_timeout = 0;
 
        /* Clear buffer*/
@@ -2651,25 +2637,20 @@ static void vty_event(enum event event, int sock, struct vty *vty)
                vector_set_index(Vvty_serv_thread, sock, vty_serv_thread);
                break;
        case VTYSH_READ:
-               vty->t_read = NULL;
                thread_add_read(vty_master, vtysh_read, vty, sock,
                                &vty->t_read);
                break;
        case VTYSH_WRITE:
-               vty->t_write = NULL;
                thread_add_write(vty_master, vtysh_write, vty, sock,
                                 &vty->t_write);
                break;
 #endif /* VTYSH */
        case VTY_READ:
-               vty->t_read = NULL;
                thread_add_read(vty_master, vty_read, vty, sock, &vty->t_read);
 
                /* Time out treatment. */
                if (vty->v_timeout) {
-                       if (vty->t_timeout)
-                               thread_cancel(vty->t_timeout);
-                       vty->t_timeout = NULL;
+                       THREAD_OFF(vty->t_timeout);
                        thread_add_timer(vty_master, vty_timeout, vty,
                                         vty->v_timeout, &vty->t_timeout);
                }
@@ -2679,15 +2660,10 @@ static void vty_event(enum event event, int sock, struct vty *vty)
                                 &vty->t_write);
                break;
        case VTY_TIMEOUT_RESET:
-               if (vty->t_timeout) {
-                       thread_cancel(vty->t_timeout);
-                       vty->t_timeout = NULL;
-               }
-               if (vty->v_timeout) {
-                       vty->t_timeout = NULL;
+               THREAD_OFF(vty->t_timeout);
+               if (vty->v_timeout)
                        thread_add_timer(vty_master, vty_timeout, vty,
                                         vty->v_timeout, &vty->t_timeout);
-               }
                break;
        }
 }
@@ -3024,7 +3000,7 @@ void vty_reset(void)
        for (i = 0; i < vector_active(Vvty_serv_thread); i++)
                if ((vty_serv_thread = vector_slot(Vvty_serv_thread, i))
                    != NULL) {
-                       thread_cancel(vty_serv_thread);
+                       THREAD_OFF(vty_serv_thread);
                        vector_slot(Vvty_serv_thread, i) = NULL;
                        close(i);
                }
index 94d92f67e774f01cb2d459a3ade0e3dd4574e806..e9b4f5a58b1797473f6b6f368ff3746a086f105c 100644 (file)
@@ -1461,18 +1461,12 @@ struct interface *zebra_interface_add_read(struct stream *s, vrf_id_t vrf_id)
 {
        struct interface *ifp;
        char ifname_tmp[INTERFACE_NAMSIZ];
-       struct vrf *vrf = vrf_lookup_by_id(vrf_id);
 
        /* Read interface name. */
        stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
 
        /* Lookup/create interface by name. */
-       ifp = if_get_by_name(ifname_tmp, vrf);
-
-       /* update vrf_id of interface */
-       if (ifp->vrf->vrf_id == VRF_UNKNOWN &&
-           vrf->vrf_id != VRF_UNKNOWN)
-               ifp->vrf = vrf;
+       ifp = if_get_by_name(ifname_tmp, vrf_id);
 
        zebra_interface_if_set_value(s, ifp);
 
@@ -1495,8 +1489,7 @@ struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id)
        stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
 
        /* Lookup this by interface index. */
-       ifp = if_lookup_by_name(ifname_tmp,
-                               vrf_lookup_by_id(vrf_id));
+       ifp = if_lookup_by_name(ifname_tmp, vrf_id);
        if (ifp == NULL) {
                flog_err(EC_LIB_ZAPI_ENCODE,
                         "INTERFACE_STATE: Cannot find IF %s in VRF %d",
@@ -1556,8 +1549,7 @@ struct interface *zebra_interface_link_params_read(struct stream *s,
 
        ifindex = stream_getl(s);
 
-       struct interface *ifp = if_lookup_by_index(ifindex,
-                                                  vrf_id);
+       struct interface *ifp = if_lookup_by_index(ifindex, vrf_id);
 
        if (ifp == NULL) {
                flog_err(EC_LIB_ZAPI_ENCODE,
@@ -1853,8 +1845,7 @@ struct interface *zebra_interface_vrf_update_read(struct stream *s,
        stream_get(ifname, s, INTERFACE_NAMSIZ);
 
        /* Lookup interface. */
-       ifp = if_lookup_by_name(ifname,
-                               vrf_lookup_by_id(vrf_id));
+       ifp = if_lookup_by_name(ifname, vrf_id);
        if (ifp == NULL) {
                flog_err(EC_LIB_ZAPI_ENCODE,
                         "INTERFACE_VRF_UPDATE: Cannot find IF %s in VRF %d",
@@ -2849,12 +2840,11 @@ void zclient_interface_set_master(struct zclient *client,
        s = client->obuf;
        stream_reset(s);
 
-       zclient_create_header(s, ZEBRA_INTERFACE_SET_MASTER,
-                             vrf_to_id(master->vrf));
+       zclient_create_header(s, ZEBRA_INTERFACE_SET_MASTER, master->vrf_id);
 
-       stream_putl(s, vrf_to_id(master->vrf));
+       stream_putl(s, master->vrf_id);
        stream_putl(s, master->ifindex);
-       stream_putl(s, vrf_to_id(slave->vrf));
+       stream_putl(s, slave->vrf_id);
        stream_putl(s, slave->ifindex);
 
        stream_putw_at(s, 0, stream_get_endp(s));
index a01911ca4b8dd1ea5e929781aa64cc8343da4356..8f1ba14fe4f200636ae85fcb9eedc505bf94539a 100644 (file)
@@ -126,8 +126,7 @@ static void nhrp_interface_update_nbma(struct interface *ifp)
        sockunion_family(&nbma) = AF_UNSPEC;
 
        if (nifp->source)
-               nbmaifp = if_lookup_by_name(nifp->source,
-                                           vrf_lookup_by_id(VRF_DEFAULT));
+               nbmaifp = if_lookup_by_name(nifp->source, VRF_DEFAULT);
 
        switch (ifp->ll_type) {
        case ZEBRA_LLT_IPGRE: {
index 91a28eaa4f489c9bf5df0dbf615dca0d2ca7b802..946bbf8cc9423f8fb9a5309f2c79203b4f3f6a16 100644 (file)
@@ -1404,8 +1404,7 @@ ospf6_routemap_rule_match_interface(void *rule, const struct prefix *prefix,
 
        if (type == RMAP_OSPF6) {
                ei = ((struct ospf6_route *)object)->route_option;
-               ifp = if_lookup_by_name((char *)rule,
-                                       vrf_lookup_by_id(VRF_DEFAULT));
+               ifp = if_lookup_by_name((char *)rule, VRF_DEFAULT);
 
                if (ifp != NULL && ei->ifindex == ifp->ifindex)
                        return RMAP_MATCH;
index 114a56c952b7933f239f17ceda3f9c79334014e2..692c84ad08e7f7f82c144f4a4f3ce631fe222782 100644 (file)
@@ -996,8 +996,7 @@ DEFUN (show_ipv6_ospf6_interface,
        struct interface *ifp;
 
        if (argc == 5) {
-               ifp = if_lookup_by_name(argv[idx_ifname]->arg,
-                                       vrf_lookup_by_id(VRF_DEFAULT));
+               ifp = if_lookup_by_name(argv[idx_ifname]->arg, VRF_DEFAULT);
                if (ifp == NULL) {
                        vty_out(vty, "No such Interface: %s\n",
                                argv[idx_ifname]->arg);
@@ -1082,8 +1081,7 @@ DEFUN (show_ipv6_ospf6_interface_traffic,
 
        if (argv_find(argv, argc, "IFNAME", &idx_ifname)) {
                intf_name = argv[idx_ifname]->arg;
-               ifp = if_lookup_by_name(intf_name,
-                                       vrf_lookup_by_id(VRF_DEFAULT));
+               ifp = if_lookup_by_name(intf_name, VRF_DEFAULT);
                if (ifp == NULL) {
                        vty_out(vty, "No such Interface: %s\n", intf_name);
                        return CMD_WARNING;
@@ -1127,8 +1125,7 @@ DEFUN (show_ipv6_ospf6_interface_ifname_prefix,
        struct interface *ifp;
        struct ospf6_interface *oi;
 
-       ifp = if_lookup_by_name(argv[idx_ifname]->arg,
-                               vrf_lookup_by_id(VRF_DEFAULT));
+       ifp = if_lookup_by_name(argv[idx_ifname]->arg, VRF_DEFAULT);
        if (ifp == NULL) {
                vty_out(vty, "No such Interface: %s\n", argv[idx_ifname]->arg);
                return CMD_WARNING;
@@ -2029,7 +2026,7 @@ DEFUN (clear_ipv6_ospf6_interface,
        } else /* Interface name is specified. */
        {
                if ((ifp = if_lookup_by_name(argv[idx_ifname]->arg,
-                                            vrf_lookup_by_id(VRF_DEFAULT)))
+                                            VRF_DEFAULT))
                    == NULL) {
                        vty_out(vty, "No such Interface: %s\n",
                                argv[idx_ifname]->arg);
index bbc9247b07627bba88119e319c5b0b1005d1cc77..40c612381090658defacd51993bbcf288d57192c 100644 (file)
@@ -654,10 +654,9 @@ DEFUN (ospf6_interface_area,
        struct ospf6_interface *oi;
        struct interface *ifp;
        uint32_t area_id;
-       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
 
        /* find/create ospf6 interface */
-       ifp = if_get_by_name(argv[idx_ifname]->arg, vrf);
+       ifp = if_get_by_name(argv[idx_ifname]->arg, VRF_DEFAULT);
        oi = (struct ospf6_interface *)ifp->info;
        if (oi == NULL)
                oi = ospf6_interface_create(ifp);
@@ -715,8 +714,7 @@ DEFUN (no_ospf6_interface_area,
        struct interface *ifp;
        uint32_t area_id;
 
-       ifp = if_lookup_by_name(argv[idx_ifname]->arg,
-                               vrf_lookup_by_id(VRF_DEFAULT));
+       ifp = if_lookup_by_name(argv[idx_ifname]->arg, VRF_DEFAULT);
        if (ifp == NULL) {
                vty_out(vty, "No such interface %s\n", argv[idx_ifname]->arg);
                return CMD_SUCCESS;
index 6516129c5db18d59f969f738c99d193e2b2ed8b5..ce1604a5b1c5a667058f549739f54dd7a39c3c4b 100644 (file)
@@ -349,8 +349,8 @@ void ospf_if_free(struct ospf_interface *oi)
        if (IS_DEBUG_OSPF_EVENT)
                zlog_debug("%s: ospf interface %s vrf %s id %u deleted",
                           __PRETTY_FUNCTION__, oi->ifp->name,
-                          vrf_to_name(oi->ifp->vrf),
-                          vrf_to_id(oi->ifp->vrf));
+                          ospf_vrf_id_to_name(oi->ifp->vrf_id),
+                          oi->ifp->vrf_id);
 
        ospf_delete_from_if(oi->ifp, oi);
 
@@ -838,7 +838,6 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf,
        struct in_addr area_id;
        struct connected *co;
        struct prefix_ipv4 *p;
-       struct vrf *vrf;
 
        if (IS_DEBUG_OSPF_EVENT)
                zlog_debug("ospf_vl_new(): Start");
@@ -856,8 +855,7 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf,
                        ospf->vrf_id);
 
        snprintf(ifname, sizeof(ifname), "VLINK%u", vlink_count);
-       vrf = vrf_lookup_by_id(ospf->vrf_id);
-       vi = if_create(ifname, vrf);
+       vi = if_create(ifname, ospf->vrf_id);
        /*
         * if_create sets ZEBRA_INTERFACE_LINKDETECTION
         * virtual links don't need this.
index 52ec97e345f812ce65ef1e3c4cd570c78327af6c..e68363663949b8d7c34965fcd2afc11b59d629cf 100644 (file)
@@ -2569,7 +2569,7 @@ DEFUN (show_ip_ospf_mpls_te_link,
        if (idx_interface) {
                ifp = if_lookup_by_name(
                                        argv[idx_interface]->arg,
-                                       vrf_lookup_by_id(ospf->vrf_id));
+                                       ospf->vrf_id);
                if (ifp == NULL) {
                        vty_out(vty, "No such interface name in vrf %s\n",
                                vrf->name);
index 6fee49d12294a1ea54728487837b3dfe2ccf0fcb..631465fb2067f9c522d65235580c853b49d007dd 100644 (file)
@@ -457,14 +457,13 @@ DEFUN (ospf_passive_interface,
        int ret;
        struct ospf_if_params *params;
        struct route_node *rn;
-       struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
 
        if (strmatch(argv[1]->text, "default")) {
                ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE);
                return CMD_SUCCESS;
        }
        if (ospf->vrf_id != VRF_UNKNOWN)
-               ifp = if_get_by_name(argv[1]->arg, vrf);
+               ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id);
 
        if (ifp == NULL) {
                vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg);
@@ -530,7 +529,6 @@ DEFUN (no_ospf_passive_interface,
        struct ospf_if_params *params;
        int ret;
        struct route_node *rn;
-       struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
 
        if (strmatch(argv[2]->text, "default")) {
                ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE);
@@ -538,7 +536,7 @@ DEFUN (no_ospf_passive_interface,
        }
 
        if (ospf->vrf_id != VRF_UNKNOWN)
-               ifp = if_get_by_name(argv[2]->arg, vrf);
+               ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id);
 
        if (ifp == NULL) {
                vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg);
@@ -3741,8 +3739,7 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
                                               json_interface);
        } else {
                /* Interface name is specified. */
-               ifp = if_lookup_by_name(intf_name,
-                                       vrf_lookup_by_id(ospf->vrf_id));
+               ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
                if (ifp == NULL) {
                        if (use_json)
                                json_object_boolean_true_add(json_vrf,
@@ -3882,8 +3879,7 @@ static int show_ip_ospf_interface_traffic_common(
                }
        } else {
                /* Interface name is specified. */
-               ifp = if_lookup_by_name(intf_name,
-                                       vrf_lookup_by_id(ospf->vrf_id));
+               ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
                if (ifp != NULL) {
                        struct route_node *rn;
                        struct ospf_interface *oi;
@@ -4693,8 +4689,7 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
 
        ospf_show_vrf_name(ospf, vty, json, use_vrf);
 
-       ifp = if_lookup_by_name(argv[arg_base]->arg,
-                               vrf_lookup_by_id(ospf->vrf_id));
+       ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);
        if (!ifp) {
                if (use_json)
                        json_object_boolean_true_add(json, "noSuchIface");
@@ -4762,8 +4757,7 @@ DEFUN (show_ip_ospf_neighbor_int,
 
        argv_find(argv, argc, "IFNAME", &idx_ifname);
 
-       ifp = if_lookup_by_name(argv[idx_ifname]->arg,
-                               vrf_lookup_by_id(vrf_id));
+       ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
        if (!ifp)
                return ret;
 
@@ -5580,8 +5574,7 @@ static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
                        vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
        }
 
-       ifp = if_lookup_by_name(argv[arg_base]->arg,
-                               vrf_lookup_by_id(ospf->vrf_id));
+       ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);
        if (!ifp) {
                if (!use_json)
                        vty_out(vty, "No such interface.\n");
@@ -7279,7 +7272,7 @@ static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
        if (nbr_str) {
                struct ospf *ospf = NULL;
 
-               ospf = ospf_lookup_by_vrf(ifp->vrf);
+               ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
                if (ospf) {
                        oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
                        if (oi)
@@ -7396,7 +7389,7 @@ DEFUN (no_ip_ospf_dead_interval,
        if (argc == 1) {
                struct ospf *ospf = NULL;
 
-               ospf = ospf_lookup_by_vrf(ifp->vrf);
+               ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
                if (ospf) {
                        oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
                        if (oi)
@@ -7995,8 +7988,8 @@ DEFUN (ip_ospf_area,
        argv_find(argv, argc, "area", &idx);
        areaid = argv[idx + 1]->arg;
 
-       if (ifp->vrf && ifp->vrf->vrf_id && !instance)
-               ospf = ospf_lookup_by_vrf(ifp->vrf);
+       if (ifp->vrf_id && !instance)
+               ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
        else
                ospf = ospf_lookup_instance(instance);
 
@@ -8093,8 +8086,8 @@ DEFUN (no_ip_ospf_area,
        if (argv_find(argv, argc, "(1-65535)", &idx))
                instance = strtol(argv[idx]->arg, NULL, 10);
 
-       if (ifp->vrf && ifp->vrf->vrf_id && !instance)
-               ospf = ospf_lookup_by_vrf(ifp->vrf);
+       if (ifp->vrf_id && !instance)
+               ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
        else
                ospf = ospf_lookup_instance(instance);
 
@@ -9720,7 +9713,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
                        continue;
 
                vty_frame(vty, "!\n");
-               if (ifp->vrf->vrf_id == VRF_DEFAULT)
+               if (ifp->vrf_id == VRF_DEFAULT)
                        vty_frame(vty, "interface %s\n", ifp->name);
                else
                        vty_frame(vty, "interface %s vrf %s\n", ifp->name,
@@ -10689,8 +10682,7 @@ DEFUN (clear_ip_ospf_interface,
                }
        } else {
                /* Interface name is specified. */
-               ifp = if_lookup_by_name(argv[idx_ifname]->arg,
-                                       vrf_lookup_by_id(vrf_id));
+               ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
                if (ifp == NULL)
                        vty_out(vty, "No such interface name\n");
                else
index 33d2c82d03c94d5aab7367cd28f8e40583061ec3..c178e367d390a032fcc37df14163950328d8ce69 100644 (file)
@@ -110,8 +110,8 @@ static int ospf_interface_add(ZAPI_CALLBACK_ARGS)
        if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
                zlog_debug(
                        "Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d speed %u",
-                       ifp->name, vrf_to_name(ifp->vrf),
-                       vrf_to_id(ifp->vrf), ifp->ifindex,
+                       ifp->name, ospf_vrf_id_to_name(ifp->vrf_id),
+                       ifp->vrf_id, ifp->ifindex,
                        (unsigned long long)ifp->flags, ifp->metric, ifp->mtu,
                        ifp->speed);
 
@@ -152,8 +152,8 @@ static int ospf_interface_delete(ZAPI_CALLBACK_ARGS)
        if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
                zlog_debug(
                        "Zebra: interface delete %s vrf %s[%u] index %d flags %llx metric %d mtu %d",
-                       ifp->name, vrf_to_name(ifp->vrf),
-                       vrf_to_id(ifp->vrf), ifp->ifindex,
+                       ifp->name, ospf_vrf_id_to_name(ifp->vrf_id),
+                       ifp->vrf_id, ifp->ifindex,
                        (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
 
        hook_call(ospf_if_delete, ifp);
@@ -175,8 +175,7 @@ static struct interface *zebra_interface_if_lookup(struct stream *s,
        stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
 
        /* And look it up. */
-       return if_lookup_by_name(ifname_tmp,
-                                vrf_lookup_by_id(vrf_id));
+       return if_lookup_by_name(ifname_tmp, vrf_id);
 }
 
 static int ospf_interface_state_up(ZAPI_CALLBACK_ARGS)
@@ -366,7 +365,7 @@ static int ospf_interface_vrf_update(ZAPI_CALLBACK_ARGS)
                        ospf_vrf_id_to_name(new_vrf_id), new_vrf_id);
 
        /*if_update(ifp, ifp->name, strlen(ifp->name), new_vrf_id);*/
-       if_update_to_new_vrf(ifp, vrf_lookup_by_id(new_vrf_id));
+       if_update_to_new_vrf(ifp, new_vrf_id);
 
        return 0;
 }
index 1b52682d9b7267868d7f5199965d5be66d5deb07..35c313e55543d3fa8aeeced8e73f665ffd5a1cb9 100644 (file)
@@ -452,11 +452,6 @@ struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id)
        vrf = vrf_lookup_by_id(vrf_id);
        if (!vrf)
                return NULL;
-       return ospf_lookup_by_vrf(vrf);
-}
-
-struct ospf *ospf_lookup_by_vrf(struct vrf *vrf)
-{
        return (vrf->info) ? (struct ospf *)vrf->info : NULL;
 }
 
@@ -1356,8 +1351,8 @@ void ospf_if_update(struct ospf *ospf, struct interface *ifp)
 
        if (IS_DEBUG_OSPF_EVENT)
                zlog_debug(
-                       "%s: interface %s ifp->vrf->vrf_id %u ospf vrf %s vrf_id %u router_id %s",
-                       __PRETTY_FUNCTION__, ifp->name, vrf_to_id(ifp->vrf),
+                       "%s: interface %s ifp->vrf_id %u ospf vrf %s vrf_id %u router_id %s",
+                       __PRETTY_FUNCTION__, ifp->name, ifp->vrf_id,
                        ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id,
                        inet_ntoa(ospf->router_id));
 
index a46febaecaf9e5df893d8373c1fca05ebf70b2ba..cbea033b7357a9ba0e9efa3fac3bac3a68318ee7 100644 (file)
@@ -507,7 +507,6 @@ extern struct ospf *ospf_get_instance(unsigned short);
 extern struct ospf *ospf_lookup_by_inst_name(unsigned short instance,
                                             const char *name);
 extern struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id);
-extern struct ospf *ospf_lookup_by_vrf(struct vrf *vrf);
 extern void ospf_finish(struct ospf *);
 extern void ospf_router_id_update(struct ospf *ospf);
 extern int ospf_network_set(struct ospf *, struct prefix_ipv4 *, struct in_addr,
index 438a0c9b64dba825bc817f2fb0eebf6c2d9af0e8..228218e3a31879dfd29e332bc9f74c617d944e0c 100644 (file)
@@ -148,12 +148,6 @@ static int dispatch_assert(struct interface *ifp, struct in_addr source_addr,
        sg.src = source_addr;
        sg.grp = group_addr;
        ch = pim_ifchannel_add(ifp, &sg, 0, 0);
-       if (!ch) {
-               zlog_warn(
-                       "%s: (S,G)=%s failure creating channel on interface %s",
-                       __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), ifp->name);
-               return -1;
-       }
 
        switch (ch->ifassert_state) {
        case PIM_IFASSERT_NOINFO:
index 266d3ffcf521824ce13f4721a6fc55af6fdc162f..9995b5e31f0afae70f28ac9e820d6b46a2bfd259 100644 (file)
@@ -152,14 +152,6 @@ static struct bsgrp_node *pim_bsm_new_bsgrp_node(struct route_table *rt,
        }
        bsgrp = XCALLOC(MTYPE_PIM_BSGRP_NODE, sizeof(struct bsgrp_node));
 
-       if (!bsgrp) {
-               if (PIM_DEBUG_BSM)
-                       zlog_debug("%s: bsgrp alloc failed",
-                                  __PRETTY_FUNCTION__);
-               route_unlock_node(rn);
-               return NULL;
-       }
-
        rn->info = bsgrp;
        bsgrp->bsrp_list = pim_alloc_bsrp_list();
        bsgrp->partial_bsrp_list = pim_alloc_bsrp_list();
@@ -730,12 +722,6 @@ static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp,
 
        pak_start = XCALLOC(MTYPE_PIM_BSM_PKT_VAR_MEM, pim_mtu);
 
-       if (!pak_start) {
-               if (PIM_DEBUG_BSM)
-                       zlog_debug("%s: malloc failed", __PRETTY_FUNCTION__);
-               return false;
-       }
-
        pkt = pak_start;
 
        /* Fill PIM header later before sending packet to calc checksum */
@@ -1057,13 +1043,6 @@ static bool pim_install_bsm_grp_rp(struct pim_instance *pim,
        /*memory allocation for bsm_rpinfo */
        bsm_rpinfo = XCALLOC(MTYPE_PIM_BSRP_NODE, sizeof(*bsm_rpinfo));
 
-       if (!bsm_rpinfo) {
-               if (PIM_DEBUG_BSM)
-                       zlog_debug("%s, Memory allocation failed.\r\n",
-                                  __PRETTY_FUNCTION__);
-               return false;
-       }
-
        bsm_rpinfo->rp_prio = rp->rp_pri;
        bsm_rpinfo->rp_holdtime = rp->rp_holdtime;
        memcpy(&bsm_rpinfo->rp_address, &rp->rpaddr.addr,
@@ -1387,18 +1366,8 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf,
        if (!no_fwd) {
                pim_bsm_fwd_whole_sz(pim_ifp->pim, buf, buf_size, sz);
                bsminfo = XCALLOC(MTYPE_PIM_BSM_INFO, sizeof(struct bsm_info));
-               if (!bsminfo) {
-                       zlog_warn("%s: bsminfo alloc failed",
-                                 __PRETTY_FUNCTION__);
-                       return 0;
-               }
 
                bsminfo->bsm = XCALLOC(MTYPE_PIM_BSM_PKT_VAR_MEM, buf_size);
-               if (!bsminfo->bsm) {
-                       zlog_warn("%s: bsm alloc failed", __PRETTY_FUNCTION__);
-                       XFREE(MTYPE_PIM_BSM_INFO, bsminfo);
-                       return 0;
-               }
 
                bsminfo->size = buf_size;
                memcpy(bsminfo->bsm, buf, buf_size);
index d71b4bf640d0b0023557a18f756aff52844b5767..72d7916b20ee416e3a8adf69ef0dfb86f81d2039 100644 (file)
@@ -6653,13 +6653,7 @@ static int pim_cmd_igmp_start(struct vty *vty, struct interface *ifp)
        pim_ifp = ifp->info;
 
        if (!pim_ifp) {
-               pim_ifp = pim_if_new(ifp, true, false, false,
-                       false /*vxlan_term*/);
-               if (!pim_ifp) {
-                       vty_out(vty, "Could not enable IGMP on interface %s\n",
-                               ifp->name);
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
+               (void)pim_if_new(ifp, true, false, false, false);
                need_startup = 1;
        } else {
                if (!PIM_IF_TEST_IGMP(pim_ifp->options)) {
@@ -7360,19 +7354,40 @@ DEFUN (interface_no_ip_pim_drprio,
        return CMD_SUCCESS;
 }
 
+DEFPY_HIDDEN (interface_ip_igmp_query_generate,
+       interface_ip_igmp_query_generate_cmd,
+       "ip igmp generate-query-once [version (2-3)]",
+       IP_STR
+       IFACE_IGMP_STR
+       "Generate igmp general query once\n"
+       "IGMP version\n"
+       "IGMP version number\n")
+{
+       VTY_DECLVAR_CONTEXT(interface, ifp);
+       int igmp_version = 2;
+
+       if (!ifp->info) {
+               vty_out(vty, "IGMP/PIM is not enabled on the interface %s\n",
+                       ifp->name);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
+       if (argc > 3)
+               igmp_version = atoi(argv[4]->arg);
+
+       igmp_send_query_on_intf(ifp, igmp_version);
+
+       return CMD_SUCCESS;
+}
+
 static int pim_cmd_interface_add(struct interface *ifp)
 {
        struct pim_interface *pim_ifp = ifp->info;
 
-       if (!pim_ifp) {
-               pim_ifp = pim_if_new(ifp, false, true, false,
-                       false /*vxlan_term*/);
-               if (!pim_ifp) {
-                       return 0;
-               }
-       } else {
+       if (!pim_ifp)
+               (void)pim_if_new(ifp, false, true, false, false);
+       else
                PIM_IF_DO_PIM(pim_ifp->options);
-       }
 
        pim_if_addr_add_all(ifp);
        pim_if_membership_refresh(ifp);
@@ -7655,7 +7670,7 @@ DEFUN (interface_ip_mroute,
        pim = pim_ifp->pim;
 
        oifname = argv[idx_interface]->arg;
-       oif = if_lookup_by_name(oifname, pim->vrf);
+       oif = if_lookup_by_name(oifname, pim->vrf_id);
        if (!oif) {
                vty_out(vty, "No such interface name %s\n", oifname);
                return CMD_WARNING;
@@ -7706,7 +7721,7 @@ DEFUN (interface_ip_mroute_source,
        pim = pim_ifp->pim;
 
        oifname = argv[idx_interface]->arg;
-       oif = if_lookup_by_name(oifname, pim->vrf);
+       oif = if_lookup_by_name(oifname, pim->vrf_id);
        if (!oif) {
                vty_out(vty, "No such interface name %s\n", oifname);
                return CMD_WARNING;
@@ -7761,7 +7776,7 @@ DEFUN (interface_no_ip_mroute,
        pim = pim_ifp->pim;
 
        oifname = argv[idx_interface]->arg;
-       oif = if_lookup_by_name(oifname, pim->vrf);
+       oif = if_lookup_by_name(oifname, pim->vrf_id);
        if (!oif) {
                vty_out(vty, "No such interface name %s\n", oifname);
                return CMD_WARNING;
@@ -7813,7 +7828,7 @@ DEFUN (interface_no_ip_mroute_source,
        pim = pim_ifp->pim;
 
        oifname = argv[idx_interface]->arg;
-       oif = if_lookup_by_name(oifname, pim->vrf);
+       oif = if_lookup_by_name(oifname, pim->vrf_id);
        if (!oif) {
                vty_out(vty, "No such interface name %s\n", oifname);
                return CMD_WARNING;
@@ -10136,7 +10151,7 @@ DEFUN_HIDDEN (ip_pim_mlag,
 
        idx = 3;
        peerlink = argv[idx]->arg;
-       ifp = if_lookup_by_name(peerlink, vrf_lookup_by_id(VRF_DEFAULT));
+       ifp = if_lookup_by_name(peerlink, VRF_DEFAULT);
        if (!ifp) {
                vty_out(vty, "No such interface name %s\n", peerlink);
                return CMD_WARNING;
@@ -10289,6 +10304,7 @@ void pim_cmd_init(void)
        install_element(INTERFACE_NODE, &interface_no_ip_pim_hello_cmd);
        install_element(INTERFACE_NODE, &interface_ip_pim_boundary_oil_cmd);
        install_element(INTERFACE_NODE, &interface_no_ip_pim_boundary_oil_cmd);
+       install_element(INTERFACE_NODE, &interface_ip_igmp_query_generate_cmd);
 
        // Static mroutes NEB
        install_element(INTERFACE_NODE, &interface_ip_mroute_cmd);
index 6ccc6ed19606863a8cd60d1df99da94779e6e567..0511a1a157cb539d9f7f08d548ba2223d61b5c6d 100644 (file)
@@ -120,7 +120,7 @@ struct pim_interface *pim_if_new(struct interface *ifp, bool igmp, bool pim,
        pim_ifp = XCALLOC(MTYPE_PIM_INTERFACE, sizeof(*pim_ifp));
 
        pim_ifp->options = 0;
-       pim_ifp->pim = pim_get_pim_instance(vrf_to_id(ifp->vrf));
+       pim_ifp->pim = pim_get_pim_instance(ifp->vrf_id);
        pim_ifp->mroute_vif_index = -1;
 
        pim_ifp->igmp_version = IGMP_DEFAULT_VERSION;
@@ -781,7 +781,7 @@ void pim_if_addr_del_all(struct interface *ifp)
        struct connected *ifc;
        struct listnode *node;
        struct listnode *nextnode;
-       struct vrf *vrf = ifp->vrf;
+       struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id);
        struct pim_instance *pim;
 
        if (!vrf)
@@ -853,7 +853,7 @@ struct in_addr pim_find_primary_addr(struct interface *ifp)
        int v4_addrs = 0;
        int v6_addrs = 0;
        struct pim_interface *pim_ifp = ifp->info;
-       struct vrf *vrf = ifp->vrf;
+       struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id);
 
        if (!vrf)
                return addr;
@@ -894,10 +894,10 @@ struct in_addr pim_find_primary_addr(struct interface *ifp)
        if (!v4_addrs && v6_addrs && !if_is_loopback(ifp)) {
                struct interface *lo_ifp;
                // DBS - Come back and check here
-               if (!ifp->vrf || ifp->vrf->vrf_id == VRF_DEFAULT)
-                       lo_ifp = if_lookup_by_name("lo", vrf);
+               if (ifp->vrf_id == VRF_DEFAULT)
+                       lo_ifp = if_lookup_by_name("lo", vrf->vrf_id);
                else
-                       lo_ifp = if_lookup_by_name(vrf->name, vrf);
+                       lo_ifp = if_lookup_by_name(vrf->name, vrf->vrf_id);
 
                if (lo_ifp)
                        return pim_find_primary_addr(lo_ifp);
@@ -1293,11 +1293,7 @@ ferr_r pim_if_igmp_join_add(struct interface *ifp, struct in_addr group_addr,
                return ferr_ok();
        }
 
-       ij = igmp_join_new(ifp, group_addr, source_addr);
-       if (!ij) {
-               return ferr_cfg_invalid(
-                       "Failure to create new join data structure, see log file for more information");
-       }
+       (void)igmp_join_new(ifp, group_addr, source_addr);
 
        if (PIM_DEBUG_IGMP_EVENTS) {
                char group_str[INET_ADDRSTRLEN];
@@ -1480,7 +1476,7 @@ void pim_if_create_pimreg(struct pim_instance *pim)
                        snprintf(pimreg_name, sizeof(pimreg_name), "pimreg%u",
                                 pim->vrf->data.l.table_id);
 
-               pim->regiface = if_create(pimreg_name, pim->vrf);
+               pim->regiface = if_create(pimreg_name, pim->vrf_id);
                pim->regiface->ifindex = PIM_OIF_PIM_REGISTER_VIF;
 
                pim_if_new(pim->regiface, false, false, true,
index 3fb3da8f4450a274ebe9ddcc760e6da5d1238c67..96c7e8052ceda38c08f16a24ad0038bf697e328b 100644 (file)
@@ -133,7 +133,7 @@ void pim_ifchannel_delete(struct pim_ifchannel *ch)
        if (ch->upstream->channel_oil) {
                uint32_t mask = PIM_OIF_FLAG_PROTO_PIM;
                if (ch->upstream->flags & PIM_UPSTREAM_FLAG_MASK_SRC_IGMP)
-                       mask = PIM_OIF_FLAG_PROTO_IGMP;
+                       mask |= PIM_OIF_FLAG_PROTO_IGMP;
 
                /*
                 * A S,G RPT channel can have an empty oil, we also
@@ -142,13 +142,15 @@ void pim_ifchannel_delete(struct pim_ifchannel *ch)
                 * being inherited.  So let's figure out what
                 * needs to be done here
                 */
-               if (pim_upstream_evaluate_join_desired_interface(
-                           ch->upstream, ch, ch->parent))
+               if ((ch->sg.src.s_addr != INADDR_ANY) &&
+                               pim_upstream_evaluate_join_desired_interface(
+                                       ch->upstream, ch, ch->parent))
                        pim_channel_add_oif(ch->upstream->channel_oil,
-                                           ch->interface, mask);
-               else
-                       pim_channel_del_oif(ch->upstream->channel_oil,
-                                           ch->interface, mask);
+                                       ch->interface,
+                                       PIM_OIF_FLAG_PROTO_STAR);
+
+               pim_channel_del_oif(ch->upstream->channel_oil,
+                                       ch->interface, mask);
                /*
                 * Do we have any S,G's that are inheriting?
                 * Nuke from on high too.
@@ -227,6 +229,8 @@ void pim_ifchannel_delete_all(struct interface *ifp)
        while (!RB_EMPTY(pim_ifchannel_rb, &pim_ifp->ifchannel_rb)) {
                ch = RB_ROOT(pim_ifchannel_rb, &pim_ifp->ifchannel_rb);
 
+               pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__,
+                               ch, PIM_IFJOIN_NOINFO);
                pim_ifchannel_delete(ch);
        }
 }
@@ -791,8 +795,6 @@ void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr,
 
        ch = pim_ifchannel_add(ifp, sg, source_flags,
                               PIM_UPSTREAM_FLAG_MASK_SRC_PIM);
-       if (!ch)
-               return;
 
        /*
          RFC 4601: 4.6.1.  (S,G) Assert Message State Machine
@@ -953,8 +955,6 @@ void pim_ifchannel_prune(struct interface *ifp, struct in_addr upstream,
 
        ch = pim_ifchannel_add(ifp, sg, source_flags,
                               PIM_UPSTREAM_FLAG_MASK_SRC_PIM);
-       if (!ch)
-               return;
 
        pim_ifp = ifp->info;
 
@@ -1082,13 +1082,6 @@ int pim_ifchannel_local_membership_add(struct interface *ifp,
        }
 
        ch = pim_ifchannel_add(ifp, sg, 0, PIM_UPSTREAM_FLAG_MASK_SRC_IGMP);
-       if (!ch) {
-               if (PIM_DEBUG_EVENTS)
-                       zlog_debug("%s:%s Unable to add ifchannel",
-                                  __PRETTY_FUNCTION__,
-                                  pim_str_sg_dump(sg));
-               return 0;
-       }
 
        ifmembership_set(ch, PIM_IFMEMBERSHIP_INCLUDE);
 
index 4ae6f69d3eee39dd92f408b71b9dbf738b647a96..7dfd26ea655d9c67662c5510ebf0313c15876223 100644 (file)
@@ -305,6 +305,13 @@ static int igmp_recv_query(struct igmp_sock *igmp, int query_version,
                return -1;
        }
 
+       if (!pim_if_connected_to_source(ifp, from)) {
+               if (PIM_DEBUG_IGMP_PACKETS)
+                       zlog_debug("Recv IGMP query on interface: %s from a non-connected source: %s",
+                                  ifp->name, from_str);
+               return 0;
+       }
+
        /* Collecting IGMP Rx stats */
        switch (query_version) {
        case 1:
@@ -1180,3 +1187,42 @@ void igmp_send_query(int igmp_version, struct igmp_group *group, int fd,
                                   group_addr, query_max_response_time_dsec);
        }
 }
+
+void igmp_send_query_on_intf(struct interface *ifp, int igmp_ver)
+{
+       struct pim_interface *pim_ifp = ifp->info;
+       struct listnode *sock_node = NULL;
+       struct igmp_sock *igmp = NULL;
+       struct in_addr dst_addr;
+       struct in_addr group_addr;
+       int query_buf_size;
+
+       if (!igmp_ver)
+               igmp_ver = 2;
+
+       if (igmp_ver == 3)
+               query_buf_size = PIM_IGMP_BUFSIZE_WRITE;
+       else
+               query_buf_size = IGMP_V12_MSG_SIZE;
+
+       dst_addr.s_addr = htonl(INADDR_ALLHOSTS_GROUP);
+       group_addr.s_addr = PIM_NET_INADDR_ANY;
+
+       if (PIM_DEBUG_IGMP_TRACE)
+               zlog_debug("Issuing general query on request on %s",
+                               ifp->name);
+
+       for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+
+               char query_buf[query_buf_size];
+
+               igmp_send_query(igmp_ver, 0 /* igmp_group */, igmp->fd,
+                               igmp->interface->name, query_buf,
+                               sizeof(query_buf), 0 /* num_sources */,
+                               dst_addr, group_addr,
+                               pim_ifp->igmp_query_max_response_time_dsec,
+                               1 /* s_flag: always set for general queries */,
+                               igmp->querier_robustness_variable,
+                               igmp->querier_query_interval);
+       }
+}
index 7db568dcfe21597b36766edcbb761c555b6f51d8..9231b0b41fb0128120122eb1c46bc8a8ca55e22b 100644 (file)
@@ -198,4 +198,6 @@ void igmp_send_query(int igmp_version, struct igmp_group *group, int fd,
                     uint8_t querier_robustness_variable,
                     uint16_t querier_query_interval);
 void igmp_group_delete(struct igmp_group *group);
+
+void igmp_send_query_on_intf(struct interface *ifp, int igmp_ver);
 #endif /* PIM_IGMP_H */
index 2bdec12cd1a8f26e84efe823a0ba065e512d2ba7..b1c55c1f43438e9c54005dbf1c9a3e7c1d8d79fd 100644 (file)
@@ -201,6 +201,10 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp,
                 * Let's blackhole those packets for the moment
                 * As that they will be coming up to the cpu
                 * and causing us to consider them.
+                *
+                * This *will* create a dangling channel_oil
+                * that I see no way to get rid of.  Just noting
+                * this for future reference.
                 */
                c_oil = pim_channel_oil_add(pim_ifp->pim, &sg,
                                            pim_ifp->mroute_vif_index,
@@ -212,14 +216,6 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp,
 
        up = pim_upstream_find_or_add(&sg, ifp, PIM_UPSTREAM_FLAG_MASK_FHR,
                                      __PRETTY_FUNCTION__);
-       if (!up) {
-               if (PIM_DEBUG_MROUTE) {
-                       zlog_debug(
-                               "%s: Failure to add upstream information for %s",
-                               __PRETTY_FUNCTION__, pim_str_sg_dump(&sg));
-               }
-               return 0;
-       }
 
        /*
         * I moved this debug till after the actual add because
index 954b5dee7e8d8d2400d00be51afefe42e88ff919..b1f7cfd2c66b57b05e170b2f06735138308c2e40 100644 (file)
@@ -158,7 +158,7 @@ int pim_msdp_sock_listen(struct pim_instance *pim)
 
        if (pim->vrf_id != VRF_DEFAULT) {
                struct interface *ifp =
-                       if_lookup_by_name(pim->vrf->name, pim->vrf);
+                       if_lookup_by_name(pim->vrf->name, pim->vrf_id);
                if (!ifp) {
                        flog_err(EC_LIB_INTERFACE,
                                 "%s: Unable to lookup vrf interface: %s",
@@ -239,7 +239,7 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp)
 
        if (mp->pim->vrf_id != VRF_DEFAULT) {
                struct interface *ifp =
-                       if_lookup_by_name(mp->pim->vrf->name, mp->pim->vrf);
+                       if_lookup_by_name(mp->pim->vrf->name, mp->pim->vrf_id);
                if (!ifp) {
                        flog_err(EC_LIB_INTERFACE,
                                 "%s: Unable to lookup vrf interface: %s",
index 4ddf21951b005deb82a44c085573624ecfb9d3ec..62c3216e864946756f22c4a189ac0689b3a6610e 100644 (file)
@@ -92,7 +92,7 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif,
                return -4;
        }
 #endif
-       if (iif->vrf != oif->vrf) {
+       if (iif->vrf_id != oif->vrf_id) {
                return -3;
        }
 
@@ -124,9 +124,6 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif,
                         * back if it fails.
                         */
                        original_s_route = static_route_alloc();
-                       if (!original_s_route) {
-                               return -5;
-                       }
                        memcpy(original_s_route, s_route,
                               sizeof(struct static_route));
 
index 2e6c5c7803501e333b7b6ab34bbf63eb8df53733..194fb2cffdd02af5dc053d73b09b14784726e177 100644 (file)
@@ -770,6 +770,18 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim,
                                up->channel_oil = pim_channel_oil_add(
                                        pim, &up->sg, pim_ifp->mroute_vif_index,
                                        __PRETTY_FUNCTION__);
+                       else {
+                               /*
+                                * Yeah this should not happen
+                                * but let's be sure that we are not
+                                * doing something stupid, all paths
+                                * through upstream creation will
+                                * create a channel oil
+                                */
+                               up->channel_oil = pim_channel_oil_add(
+                                       pim, &up->sg, MAXVIFS,
+                                       __PRETTY_FUNCTION__);
+                       }
                }
        }
 
index eef36288d92ac27ec1a6e2c228ce7aa9ab9afdc4..2c814d0fdcb09f6bbeab7ed48db856b598fecbdb 100644 (file)
@@ -211,12 +211,11 @@ static int pim_zebra_if_state_up(ZAPI_CALLBACK_ARGS)
         */
        if (sscanf(ifp->name, "pimreg%" SCNu32, &table_id) == 1) {
                struct vrf *vrf;
-
                RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
                        if ((table_id == vrf->data.l.table_id)
-                           && (ifp->vrf != vrf)) {
+                           && (ifp->vrf_id != vrf->vrf_id)) {
                                struct interface *master = if_lookup_by_name(
-                                                            vrf->name, vrf);
+                                       vrf->name, vrf->vrf_id);
 
                                if (!master) {
                                        zlog_debug(
@@ -291,7 +290,7 @@ static int pim_zebra_interface_vrf_update(ZAPI_CALLBACK_ARGS)
                           __PRETTY_FUNCTION__,
                           ifp->name, vrf_id, new_vrf_id);
 
-       if_update_to_new_vrf(ifp, vrf_lookup_by_id(new_vrf_id));
+       if_update_to_new_vrf(ifp, new_vrf_id);
 
        return 0;
 }
@@ -977,16 +976,6 @@ void igmp_source_forward_start(struct pim_instance *pim,
                        /*Create a dummy channel oil */
                        source->source_channel_oil = pim_channel_oil_add(
                                pim, &sg, MAXVIFS, __PRETTY_FUNCTION__);
-
-                       if (!source->source_channel_oil) {
-                               if (PIM_DEBUG_IGMP_TRACE) {
-                                       zlog_debug(
-                                       "%s %s: could not create OIL for channel (S,G)=%s",
-                                       __FILE__, __PRETTY_FUNCTION__,
-                                       pim_str_sg_dump(&sg));
-                               }
-                               return;
-                       }
                }
 
                else {
@@ -1251,19 +1240,10 @@ void pim_forward_start(struct pim_ifchannel *ch)
                                pim, &up->sg, MAXVIFS, __PRETTY_FUNCTION__);
                }
 
-               else {
+               else
                        up->channel_oil = pim_channel_oil_add(
                                pim, &up->sg, input_iface_vif_index,
                                __PRETTY_FUNCTION__);
-                       if (!up->channel_oil) {
-                               if (PIM_DEBUG_PIM_TRACE)
-                                       zlog_debug(
-                                           "%s %s: could not create OIL for channel (S,G)=%s",
-                                           __FILE__, __PRETTY_FUNCTION__,
-                                           up->sg_str);
-                               return;
-                       }
-               }
 
                if (PIM_DEBUG_TRACE) {
                        struct interface *in_intf = pim_if_find_by_vif_index(
@@ -1278,14 +1258,6 @@ void pim_forward_start(struct pim_ifchannel *ch)
                up->channel_oil =
                        pim_channel_oil_add(pim, &up->sg, input_iface_vif_index,
                                            __PRETTY_FUNCTION__);
-               if (!up->channel_oil) {
-                       if (PIM_DEBUG_PIM_TRACE)
-                               zlog_debug(
-                                       "%s %s: could not create OIL for channel (S,G)=%s",
-                                       __FILE__, __PRETTY_FUNCTION__,
-                                       up->sg_str);
-                       return;
-               }
        }
 
        if (up->flags & PIM_UPSTREAM_FLAG_MASK_SRC_IGMP)
index 3a892f33b28f04fad9844089017c6822bfe8ebaa..80561f350ba2abcf901d1873c5447f2477e80387 100644 (file)
@@ -366,7 +366,7 @@ int rip_interface_down(ZAPI_CALLBACK_ARGS)
        if (IS_RIP_DEBUG_ZEBRA)
                zlog_debug(
                        "interface %s vrf %u index %d flags %llx metric %d mtu %d is down",
-                       ifp->name, ifp->vrf->vrf_id, ifp->ifindex,
+                       ifp->name, ifp->vrf_id, ifp->ifindex,
                        (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
 
        return 0;
@@ -387,7 +387,7 @@ int rip_interface_up(ZAPI_CALLBACK_ARGS)
        if (IS_RIP_DEBUG_ZEBRA)
                zlog_debug(
                        "interface %s vrf %u index %d flags %#llx metric %d mtu %d is up",
-                       ifp->name, ifp->vrf->vrf_id, ifp->ifindex,
+                       ifp->name, ifp->vrf_id, ifp->ifindex,
                        (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
 
        rip_interface_sync(ifp);
@@ -415,7 +415,7 @@ int rip_interface_add(ZAPI_CALLBACK_ARGS)
        if (IS_RIP_DEBUG_ZEBRA)
                zlog_debug(
                        "interface add %s vrf %u index %d flags %#llx metric %d mtu %d",
-                       ifp->name, ifp->vrf->vrf_id, ifp->ifindex,
+                       ifp->name, ifp->vrf_id, ifp->ifindex,
                        (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
 
        /* Check if this interface is RIP enabled or not.*/
@@ -455,7 +455,7 @@ int rip_interface_delete(ZAPI_CALLBACK_ARGS)
 
        zlog_info(
                "interface delete %s vrf %u index %d flags %#llx metric %d mtu %d",
-               ifp->name, ifp->vrf->vrf_id, ifp->ifindex,
+               ifp->name, ifp->vrf_id, ifp->ifindex,
                (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
 
        /* To support pseudo interface do not free interface structure.  */
@@ -470,21 +470,17 @@ int rip_interface_vrf_update(ZAPI_CALLBACK_ARGS)
 {
        struct interface *ifp;
        vrf_id_t new_vrf_id;
-       struct vrf *new_vrf;
 
        ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id,
                                              &new_vrf_id);
        if (!ifp)
                return 0;
 
-       new_vrf = vrf_lookup_by_id(new_vrf_id);
-
        if (IS_RIP_DEBUG_ZEBRA)
                zlog_debug("interface %s VRF change vrf_id %u new vrf id %u",
                           ifp->name, vrf_id, new_vrf_id);
 
-       if_update_to_new_vrf(ifp, new_vrf);
-
+       if_update_to_new_vrf(ifp, new_vrf_id);
        rip_interface_sync(ifp);
 
        return 0;
@@ -1229,7 +1225,7 @@ void rip_interface_sync(struct interface *ifp)
 {
        struct vrf *vrf;
 
-       vrf = ifp->vrf;
+       vrf = vrf_lookup_by_id(ifp->vrf_id);
        if (vrf) {
                struct rip_interface *ri;
 
index b09af7e086d8babecbc673ff703b6ad5a2bc1965..85d83c61dc3ca00efea00b85f522ee721dd11bf8 100644 (file)
@@ -106,8 +106,7 @@ static route_map_result_t route_match_interface(void *rule,
 
        if (type == RMAP_RIP) {
                ifname = rule;
-               ifp = if_lookup_by_name(ifname,
-                                       vrf_lookup_by_id(VRF_DEFAULT));
+               ifp = if_lookup_by_name(ifname, VRF_DEFAULT);
 
                if (!ifp)
                        return RMAP_NOMATCH;
index a859bcc43efd44e0b929c14d17de36ab192146b8..e0ff0430f81a4728cbe5524754975a60bdd0ed45 100644 (file)
@@ -3305,7 +3305,7 @@ static void rip_distribute_update(struct distribute_ctx *ctx,
        if (!ctx->vrf || !dist->ifname)
                return;
 
-       ifp = if_lookup_by_name(dist->ifname, ctx->vrf);
+       ifp = if_lookup_by_name(dist->ifname, ctx->vrf->vrf_id);
        if (ifp == NULL)
                return;
 
@@ -3424,7 +3424,7 @@ static void rip_if_rmap_update(struct if_rmap_ctx *ctx,
        if (ctx->name)
                vrf = vrf_lookup_by_name(ctx->name);
        if (vrf)
-               ifp = if_lookup_by_name(if_rmap->ifname, vrf);
+               ifp = if_lookup_by_name(if_rmap->ifname, vrf->vrf_id);
        if (ifp == NULL)
                return;
 
@@ -3457,8 +3457,6 @@ void rip_if_rmap_update_interface(struct interface *ifp)
 
        if (!rip)
                return;
-       if (ifp->vrf && ifp->vrf->vrf_id == VRF_UNKNOWN)
-               return;
        ctx = rip->if_rmap_ctx;
        if (!ctx)
                return;
index 520e19a71076965ad71dac2a829722f8d2e38715..49ed13a2c29b416d67275f3f86704f8b6473baa5 100644 (file)
@@ -212,7 +212,7 @@ int ripng_interface_up(ZAPI_CALLBACK_ARGS)
        if (IS_RIPNG_DEBUG_ZEBRA)
                zlog_debug(
                        "interface up %s vrf %u index %d flags %llx metric %d mtu %d",
-                       ifp->name, ifp->vrf->vrf_id, ifp->ifindex,
+                       ifp->name, ifp->vrf_id, ifp->ifindex,
                        (unsigned long long)ifp->flags, ifp->metric, ifp->mtu6);
 
        ripng_interface_sync(ifp);
@@ -249,7 +249,7 @@ int ripng_interface_down(ZAPI_CALLBACK_ARGS)
        if (IS_RIPNG_DEBUG_ZEBRA)
                zlog_debug(
                        "interface down %s vrf %u index %d flags %#llx metric %d mtu %d",
-                       ifp->name, ifp->vrf->vrf_id, ifp->ifindex,
+                       ifp->name, ifp->vrf_id, ifp->ifindex,
                        (unsigned long long)ifp->flags, ifp->metric, ifp->mtu6);
 
        return 0;
@@ -266,7 +266,7 @@ int ripng_interface_add(ZAPI_CALLBACK_ARGS)
        if (IS_RIPNG_DEBUG_ZEBRA)
                zlog_debug(
                        "RIPng interface add %s vrf %u index %d flags %#llx metric %d mtu %d",
-                       ifp->name, ifp->vrf->vrf_id, ifp->ifindex,
+                       ifp->name, ifp->vrf_id, ifp->ifindex,
                        (unsigned long long)ifp->flags, ifp->metric, ifp->mtu6);
 
        /* Check is this interface is RIP enabled or not.*/
@@ -301,7 +301,7 @@ int ripng_interface_delete(ZAPI_CALLBACK_ARGS)
 
        zlog_info(
                "interface delete %s vrf %u index %d flags %#llx metric %d mtu %d",
-               ifp->name, ifp->vrf->vrf_id, ifp->ifindex,
+               ifp->name, ifp->vrf_id, ifp->ifindex,
                (unsigned long long)ifp->flags, ifp->metric, ifp->mtu6);
 
        /* To support pseudo interface do not free interface structure.  */
@@ -316,21 +316,17 @@ int ripng_interface_vrf_update(ZAPI_CALLBACK_ARGS)
 {
        struct interface *ifp;
        vrf_id_t new_vrf_id;
-       struct vrf *new_vrf;
 
        ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id,
                                              &new_vrf_id);
        if (!ifp)
                return 0;
 
-       new_vrf = vrf_lookup_by_id(new_vrf_id);
-
        if (IS_RIPNG_DEBUG_ZEBRA)
                zlog_debug("interface %s VRF change vrf_id %u new vrf id %u",
                           ifp->name, vrf_id, new_vrf_id);
 
-       if_update_to_new_vrf(ifp, new_vrf);
-
+       if_update_to_new_vrf(ifp, new_vrf_id);
        ripng_interface_sync(ifp);
 
        return 0;
@@ -935,7 +931,7 @@ void ripng_interface_sync(struct interface *ifp)
 {
        struct vrf *vrf;
 
-       vrf = ifp->vrf;
+       vrf = vrf_lookup_by_id(ifp->vrf_id);
        if (vrf) {
                struct ripng_interface *ri;
 
index 874d815167c84fc3057d41de0021b371d850df32..0604e272cdfd6800b6318f3746841616de5c6c61 100644 (file)
@@ -97,8 +97,7 @@ static route_map_result_t route_match_interface(void *rule,
 
        if (type == RMAP_RIPNG) {
                ifname = rule;
-               ifp = if_lookup_by_name(ifname,
-                                       vrf_lookup_by_id(VRF_DEFAULT));
+               ifp = if_lookup_by_name(ifname, VRF_DEFAULT);
 
                if (!ifp)
                        return RMAP_NOMATCH;
index 34d8b3121ea9c42ec632e9300ca7490ca6779410..3314892e74afded39219148b8c4c4cf1823152e5 100644 (file)
@@ -2459,7 +2459,7 @@ static void ripng_distribute_update(struct distribute_ctx *ctx,
        if (!ctx->vrf || !dist->ifname)
                return;
 
-       ifp = if_lookup_by_name(dist->ifname, ctx->vrf);
+       ifp = if_lookup_by_name(dist->ifname, ctx->vrf->vrf_id);
        if (ifp == NULL)
                return;
 
@@ -2576,7 +2576,7 @@ static void ripng_if_rmap_update(struct if_rmap_ctx *ctx,
        if (ctx->name)
                vrf = vrf_lookup_by_name(ctx->name);
        if (vrf)
-               ifp = if_lookup_by_name(if_rmap->ifname, vrf);
+               ifp = if_lookup_by_name(if_rmap->ifname, vrf->vrf_id);
        if (ifp == NULL)
                return;
 
@@ -2608,8 +2608,6 @@ void ripng_if_rmap_update_interface(struct interface *ifp)
        struct if_rmap *if_rmap;
        struct if_rmap_ctx *ctx;
 
-       if (ifp->vrf && ifp->vrf->vrf_id == VRF_UNKNOWN)
-               return;
        if (!ripng)
                return;
        ctx = ripng->if_rmap_ctx;
index 01d6db07842badf4f31aca951157ac83aa00f91e..cd6f9565802dca1f2e19fcdafbc4c99e90ffebd1 100644 (file)
@@ -46,7 +46,7 @@ struct zclient *zclient = NULL;
 /* For registering threads. */
 extern struct thread_master *master;
 
-static struct interface *zebra_interface_if_lookup(struct stream *s, vrf_id_t vrf_id)
+static struct interface *zebra_interface_if_lookup(struct stream *s)
 {
        char ifname_tmp[INTERFACE_NAMSIZ];
 
@@ -54,8 +54,7 @@ static struct interface *zebra_interface_if_lookup(struct stream *s, vrf_id_t vr
        stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
 
        /* And look it up. */
-       return if_lookup_by_name(ifname_tmp,
-                                vrf_lookup_by_id(vrf_id));
+       return if_lookup_by_name(ifname_tmp, VRF_DEFAULT);
 }
 
 /* Inteface addition message from zebra. */
@@ -113,7 +112,7 @@ static int interface_address_delete(ZAPI_CALLBACK_ARGS)
 static int interface_state_up(ZAPI_CALLBACK_ARGS)
 {
 
-       zebra_interface_if_lookup(zclient->ibuf, vrf_id);
+       zebra_interface_if_lookup(zclient->ibuf);
 
        return 0;
 }
index 9af30a587a4a17b4d63baeec80cd6cb89c83dd65..2aa0db59f11c4a7d201758ea9396733374609f13 100644 (file)
@@ -37,8 +37,6 @@ static void static_nht_update_safi(struct prefix *p, uint32_t nh_num,
        struct static_route *si;
        struct static_vrf *svrf;
        struct route_node *rn;
-       bool orig;
-       bool reinstall;
 
        svrf = vrf->info;
        if (!svrf)
@@ -49,7 +47,6 @@ static void static_nht_update_safi(struct prefix *p, uint32_t nh_num,
                return;
 
        for (rn = route_top(stable); rn; rn = route_next(rn)) {
-               reinstall = false;
                for (si = rn->info; si; si = si->next) {
                        if (si->nh_vrf_id != nh_vrf_id)
                                continue;
@@ -60,7 +57,6 @@ static void static_nht_update_safi(struct prefix *p, uint32_t nh_num,
                            && si->type != STATIC_IPV6_GATEWAY_IFNAME)
                                continue;
 
-                       orig = si->nh_valid;
                        if (p->family == AF_INET
                            && p->u.prefix4.s_addr == si->addr.ipv4.s_addr)
                                si->nh_valid = !!nh_num;
@@ -69,14 +65,7 @@ static void static_nht_update_safi(struct prefix *p, uint32_t nh_num,
                            && memcmp(&p->u.prefix6, &si->addr.ipv6, 16) == 0)
                                si->nh_valid = !!nh_num;
 
-                       if (orig != si->nh_valid)
-                               reinstall = true;
-
-                       if (reinstall) {
-                               static_zebra_route_add(rn, si, vrf->vrf_id,
-                                                      safi, true);
-                               reinstall = false;
-                       }
+                       static_zebra_route_add(rn, si, vrf->vrf_id, safi, true);
                }
        }
 }
index e9fdad6bacc890f20e5dc809fefcf3b98068c3ee..5f9ecad6946229f8c3db99da2def2165552f7163 100644 (file)
@@ -187,7 +187,7 @@ int static_add_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p,
        else {
                struct interface *ifp;
 
-               ifp = if_lookup_by_name(ifname, nh_svrf->vrf);
+               ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
                if (ifp && ifp->ifindex != IFINDEX_INTERNAL) {
                        si->ifindex = ifp->ifindex;
                        static_install_route(rn, si, safi);
@@ -331,7 +331,8 @@ static void static_fixup_vrf(struct static_vrf *svrf,
                        si->nh_vrf_id = svrf->vrf->vrf_id;
                        si->nh_registered = false;
                        if (si->ifindex) {
-                               ifp = if_lookup_by_name(si->ifname, svrf->vrf);
+                               ifp = if_lookup_by_name(si->ifname,
+                                                       si->nh_vrf_id);
                                if (ifp)
                                        si->ifindex = ifp->ifindex;
                                else
@@ -366,8 +367,7 @@ static void static_enable_vrf(struct static_vrf *svrf,
                        si->vrf_id = vrf->vrf_id;
                        if (si->ifindex) {
                                ifp = if_lookup_by_name(si->ifname,
-                                                       vrf_lookup_by_id(
-                                                        si->nh_vrf_id));
+                                                       si->nh_vrf_id);
                                if (ifp)
                                        si->ifindex = ifp->ifindex;
                                else
@@ -516,7 +516,7 @@ static void static_fixup_intf_nh(struct route_table *stable,
 
        for (rn = route_top(stable); rn; rn = route_next(rn)) {
                for (si = rn->info; si; si = si->next) {
-                       if (si->nh_vrf_id != vrf_to_id(ifp->vrf))
+                       if (si->nh_vrf_id != ifp->vrf_id)
                                continue;
 
                        if (si->ifindex != ifp->ifindex)
@@ -542,7 +542,7 @@ void static_install_intf_nh(struct interface *ifp)
                struct static_vrf *svrf = vrf->info;
 
                /* Not needed if same vrf since happens naturally */
-               if (vrf == ifp->vrf)
+               if (vrf->vrf_id == ifp->vrf_id)
                        continue;
 
                /* Install any static routes configured for this interface. */
index 6ffeb2ca4bea033c92db60ac8840757224ddd295..c6da00418b4ab9408b056c07c17871ac6560f76b 100644 (file)
@@ -47,7 +47,7 @@
 struct zclient *zclient;
 static struct hash *static_nht_hash;
 
-static struct interface *zebra_interface_if_lookup(struct stream *s, vrf_id_t vrf_id)
+static struct interface *zebra_interface_if_lookup(struct stream *s)
 {
        char ifname_tmp[INTERFACE_NAMSIZ];
 
@@ -55,8 +55,7 @@ static struct interface *zebra_interface_if_lookup(struct stream *s, vrf_id_t vr
        stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
 
        /* And look it up. */
-       return if_lookup_by_name(ifname_tmp,
-                                vrf_lookup_by_id(vrf_id));
+       return if_lookup_by_name(ifname_tmp, VRF_DEFAULT);
 }
 
 /* Inteface addition message from zebra. */
@@ -116,7 +115,7 @@ static int interface_state_up(ZAPI_CALLBACK_ARGS)
 {
        struct interface *ifp;
 
-       ifp = zebra_interface_if_lookup(zclient->ibuf, vrf_id);
+       ifp = zebra_interface_if_lookup(zclient->ibuf);
 
        if (ifp) {
                if (if_is_vrf(ifp)) {
diff --git a/tests/topotests/bgp_instance_del_test/__init__.py b/tests/topotests/bgp_instance_del_test/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/topotests/bgp_instance_del_test/ce1 b/tests/topotests/bgp_instance_del_test/ce1
new file mode 120000 (symlink)
index 0000000..0924eb5
--- /dev/null
@@ -0,0 +1 @@
+../bgp_l3vpn_to_bgp_vrf/ce1
\ No newline at end of file
diff --git a/tests/topotests/bgp_instance_del_test/ce2 b/tests/topotests/bgp_instance_del_test/ce2
new file mode 120000 (symlink)
index 0000000..8c7a677
--- /dev/null
@@ -0,0 +1 @@
+../bgp_l3vpn_to_bgp_vrf/ce2
\ No newline at end of file
diff --git a/tests/topotests/bgp_instance_del_test/ce3 b/tests/topotests/bgp_instance_del_test/ce3
new file mode 120000 (symlink)
index 0000000..0abb8e5
--- /dev/null
@@ -0,0 +1 @@
+../bgp_l3vpn_to_bgp_vrf/ce3
\ No newline at end of file
diff --git a/tests/topotests/bgp_instance_del_test/ce4 b/tests/topotests/bgp_instance_del_test/ce4
new file mode 120000 (symlink)
index 0000000..ddee1ef
--- /dev/null
@@ -0,0 +1 @@
+../bgp_l3vpn_to_bgp_vrf/ce4
\ No newline at end of file
diff --git a/tests/topotests/bgp_instance_del_test/customize.py b/tests/topotests/bgp_instance_del_test/customize.py
new file mode 120000 (symlink)
index 0000000..99fcf39
--- /dev/null
@@ -0,0 +1 @@
+../bgp_l3vpn_to_bgp_vrf/customize.py
\ No newline at end of file
diff --git a/tests/topotests/bgp_instance_del_test/r1 b/tests/topotests/bgp_instance_del_test/r1
new file mode 120000 (symlink)
index 0000000..16babfa
--- /dev/null
@@ -0,0 +1 @@
+../bgp_l3vpn_to_bgp_vrf/r1
\ No newline at end of file
diff --git a/tests/topotests/bgp_instance_del_test/r2 b/tests/topotests/bgp_instance_del_test/r2
new file mode 120000 (symlink)
index 0000000..e25b932
--- /dev/null
@@ -0,0 +1 @@
+../bgp_l3vpn_to_bgp_vrf/r2
\ No newline at end of file
diff --git a/tests/topotests/bgp_instance_del_test/r3 b/tests/topotests/bgp_instance_del_test/r3
new file mode 120000 (symlink)
index 0000000..0d7c189
--- /dev/null
@@ -0,0 +1 @@
+../bgp_l3vpn_to_bgp_vrf/r3
\ No newline at end of file
diff --git a/tests/topotests/bgp_instance_del_test/r4 b/tests/topotests/bgp_instance_del_test/r4
new file mode 120000 (symlink)
index 0000000..2d667d3
--- /dev/null
@@ -0,0 +1 @@
+../bgp_l3vpn_to_bgp_vrf/r4
\ No newline at end of file
diff --git a/tests/topotests/bgp_instance_del_test/scripts b/tests/topotests/bgp_instance_del_test/scripts
new file mode 120000 (symlink)
index 0000000..c46bf1f
--- /dev/null
@@ -0,0 +1 @@
+../bgp_l3vpn_to_bgp_vrf/scripts
\ No newline at end of file
diff --git a/tests/topotests/bgp_instance_del_test/test_bgp_instance_del_test.py b/tests/topotests/bgp_instance_del_test/test_bgp_instance_del_test.py
new file mode 100755 (executable)
index 0000000..115c779
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+#
+# Part of NetDEF Topology Tests
+#
+# Copyright (c) 2018, LabN Consulting, L.L.C.
+# Authored by Lou Berger <lberger@labn.net>
+#
+# Permission to use, copy, modify, and/or distribute this software
+# for any purpose with or without fee is hereby granted, provided
+# that the above copyright notice and this permission notice appear
+# in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
+# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+# OF THIS SOFTWARE.
+#
+
+import os
+import sys
+import pytest
+
+sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../'))
+
+from lib.ltemplate import *
+
+def test_check_linux_vrf():
+    CliOnFail = None
+    # For debugging, uncomment the next line
+    #CliOnFail = 'tgen.mininet_cli'
+    CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')'
+    #uncomment next line to start cli *before* script is run
+    #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')'
+    ltemplateTest('scripts/check_linux_vrf.py', False, CliOnFail, CheckFunc)
+
+def test_adjacencies():
+    CliOnFail = None
+    # For debugging, uncomment the next line
+    #CliOnFail = 'tgen.mininet_cli'
+    CheckFunc = 'ltemplateVersionCheck(\'4.1\')'
+    #uncomment next line to start cli *before* script is run
+    #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)'
+    ltemplateTest('scripts/adjacencies.py', False, CliOnFail, CheckFunc)
+
+def SKIP_test_add_routes():
+    CliOnFail = None
+    # For debugging, uncomment the next line
+    #CliOnFail = 'tgen.mininet_cli'
+    CheckFunc = 'ltemplateVersionCheck(\'4.1\')'
+    #uncomment next line to start cli *before* script is run
+    #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)'
+    ltemplateTest('scripts/add_routes.py', False, CliOnFail, CheckFunc)
+
+def test_check_routes():
+    CliOnFail = None
+    # For debugging, uncomment the next line
+    #CliOnFail = 'tgen.mininet_cli'
+    CheckFunc = 'ltemplateVersionCheck(\'4.1\')'
+    #uncomment next line to start cli *before* script is run
+    #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)'
+    ltemplateTest('scripts/check_routes.py', False, CliOnFail, CheckFunc)
+
+#manual data path setup test - remove once have bgp/zebra vrf path working
+def test_check_linux_mpls():
+    CliOnFail = None
+    # For debugging, uncomment the next line
+    #CliOnFail = 'tgen.mininet_cli'
+    CheckFunc = 'ltemplateVersionCheck(\'4.1\', iproute2=\'4.9\')'
+    #uncomment next line to start cli *before* script is run
+    #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True, iproute2=\'4.9\')'
+    ltemplateTest('scripts/check_linux_mpls.py', False, CliOnFail, CheckFunc)
+
+def test_del_bgp_instances():
+    CliOnFail = None
+    # For debugging, uncomment the next line
+    #CliOnFail = 'tgen.mininet_cli'
+    CheckFunc = 'ltemplateVersionCheck(\'4.1\')'
+    #uncomment next line to start cli *before* script is run
+    #CheckFunc = 'ltemplateVersionCheck(\'4.1\', cli=True)'
+    ltemplateTest('scripts/del_bgp_instances.py', False, CliOnFail, CheckFunc)
+
+if __name__ == '__main__':
+    retval = pytest.main(["-s"])
+    sys.exit(retval)
diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py
new file mode 100644 (file)
index 0000000..c25c2d9
--- /dev/null
@@ -0,0 +1,7 @@
+from lutil import luCommand
+
+luCommand('r1','/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5227 vrf r1-cust1" -c "no router bgp 5226"','.','none','Cleared bgp instances')
+luCommand('r2','/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5226"','.','none','Cleared bgp instances')
+luCommand('r3','/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5227 vrf r3-cust1" -c "no router bgp 5226"','.','none','Cleared bgp instances')
+luCommand('r4','/usr/lib/frr/vtysh -c "conf ter" -c "no router bgp 5228 vrf r4-cust2" -c "no router bgp 5227 vrf r4-cust1"  -c "no router bgp 5226"','.','none','Cleared bgp instances')
+
index c17bf1168c763430b23d2b983626e5c235f4b3e6..db53c1aacde84a06b873b36fe90c14ad2db1b290 100644 (file)
@@ -6,14 +6,19 @@ if ret != False and found != None:
     luCommand('ce3', 'vtysh -c "show bgp sum"',
              '.', 'pass', 'See %s sharp routes' % num)
     if num > 0:
+        rtrs = ['ce1', 'ce2', 'ce3']
+        for rtr in rtrs:
+            luCommand(rtr, 'vtysh -c "show bgp ipv4 uni" | grep Display','.', 'none', 'BGP routes pre remove')
+            luCommand(rtr, 'ip route show | cat -n | tail','.', 'none', 'Linux routes pre remove')
         wait = 2*num/500
         luCommand('ce1', 'vtysh -c "sharp remove routes 10.0.0.0 {}"'.format(num),'.','none','Removing {} routes'.format(num))
         luCommand('ce2', 'vtysh -c "sharp remove routes 10.0.0.0 {}"'.format(num),'.','none','Removing {} routes'.format(num))
-        rtrs = ['ce1', 'ce2', 'ce3']
         for rtr in rtrs:
-            luCommand(rtr, 'vtysh -c "show bgp ipv4 uni" | grep -c 10\\.\\*/32','^0$', 'wait', 'BGP routes removed', wait)
+            luCommand(rtr, 'vtysh -c "show bgp ipv4 uni" | grep Display',' 10 route', 'wait', 'BGP routes removed', wait)
+            luCommand(rtr, 'vtysh -c "show bgp ipv4 uni"','.', 'none', 'BGP routes post remove')
         for rtr in rtrs:
             luCommand(rtr, 'ip route show | grep -c \\^10\\.','^0$', 'wait', 'Linux routes removed', wait)
+            luCommand(rtr, 'ip route show','.', 'none', 'Linux routes post remove')
         rtrs = ['r1', 'r3', 'r4']
         for rtr in rtrs:
             luCommand(rtr, 'ip route show vrf {}-cust1 | grep -c \\^10\\.'.format(rtr),'^0$','wait','VRF route removed',wait)
index 7f114d10df78ebd0d91ba2ee323caa7b3963ef2b..3619cdf84fe7422f03c7369afd80ca822dc46090 100644 (file)
@@ -11,14 +11,17 @@ if c > 0:
 else:
     d = r
 wait = 2*num/1000
-mem = {}
+mem_z = {}
+mem_b = {}
 rtrs = ['ce1', 'ce2', 'ce3', 'r1', 'r2', 'r3', 'r4']
 for rtr in rtrs:
-    mem[rtr] = {'value': 0, 'units': 'unknown'}
-    ret = luCommand(rtr, 'vtysh -c "show memory"', 'bgpd: System allocator statistics:   Total heap allocated: *(\d*) ([A-Za-z]*)', 'none', 'collect bgpd memory stats')
+    mem_z[rtr] = {'value': 0, 'units': 'unknown'}
+    mem_b[rtr] = {'value': 0, 'units': 'unknown'}
+    ret = luCommand(rtr, 'vtysh -c "show memory"', 'zebra: System allocator statistics:   Total heap allocated: *(\d*) ([A-Za-z]*) .*bgpd: System allocator statistics:   Total heap allocated: *(\d*) ([A-Za-z]*)', 'none', 'collect bgpd memory stats')
     found = luLast()
     if ret != False and found != None:
-        mem[rtr] = {'value': int(found.group(1)), 'units': found.group(2)}
+        mem_z[rtr] = {'value': int(found.group(1)), 'units': found.group(2)}
+        mem_b[rtr] = {'value': int(found.group(3)), 'units': found.group(4)}
 
 luCommand('ce1', 'vtysh -c "sharp data nexthop"', 'sharpd is not running', 'none','check if sharpd running')
 doSharp = True
@@ -54,13 +57,20 @@ if doSharp == True:
         luCommand(rtr, 'ip route show vrf {}-cust1 | grep -c \\^10\\.'.format(rtr), str(num), 'wait','See {} linux routes'.format(num), wait)
     rtrs = ['ce1', 'ce2', 'ce3', 'r1', 'r2', 'r3', 'r4']
     for rtr in rtrs:
-        ret = luCommand(rtr, 'vtysh -c "show memory"', 'bgpd: System allocator statistics:   Total heap allocated: *(\d*) ([A-Za-z]*)', 'none', 'collect bgpd memory stats')
+        ret = luCommand(rtr, 'vtysh -c "show memory"', 'zebra: System allocator statistics:   Total heap allocated: *(\d*) ([A-Za-z]*) .*bgpd: System allocator statistics:   Total heap allocated: *(\d*) ([A-Za-z]*)', 'none', 'collect bgpd memory stats')
         found = luLast()
         if ret != False and found != None:
-            val = int(found.group(1))
-            if mem[rtr]['units'] != found.group(2):
-                val *= 1000
-            delta = val - int(mem[rtr]['value'])
-            ave = float(delta)/float(num)
-            luCommand(rtr, 'vtysh -c "show thread cpu"', '.', 'pass', 'BGPd heap: {0} {1} --> {2} {3} ({4} {1}/route)'.format(mem[rtr]['value'], mem[rtr]['units'], found.group(1), found.group(2), round(ave,4)))
+            val_z = int(found.group(1))
+            if mem_z[rtr]['units'] != found.group(2):
+                val_z *= 1000
+            delta_z = val_z - int(mem_z[rtr]['value'])
+            ave_z = float(delta_z)/float(num)
+
+            val_b = int(found.group(3))
+            if mem_b[rtr]['units'] != found.group(4):
+                val_b *= 1000
+            delta_b = val_b - int(mem_b[rtr]['value'])
+            ave_b = float(delta_b)/float(num)
+            luCommand(rtr, 'vtysh -c "show thread cpu"', '.', 'pass', 'BGPd heap: {0} {1} --> {2} {3} ({4} {1}/vpn route)'.format(mem_b[rtr]['value'], mem_b[rtr]['units'], found.group(3), found.group(4), round(ave_b,4)))
+            luCommand(rtr, 'vtysh -c "show thread cpu"', '.', 'pass', 'Zebra heap: {0} {1} --> {2} {3} ({4} {1}/vpn route)'.format(mem_z[rtr]['value'], mem_z[rtr]['units'], found.group(1), found.group(2), round(ave_z,4)))
 #done
index 3ae18018bfdd84a10ff54ce82334ddc367458306..e58b4725eb6756b3425ee4570bdfd3ae037848cc 100755 (executable)
@@ -37,7 +37,7 @@ class lUtil:
     base_log_dir = '.'
     fout_name = 'output.log'
     fsum_name = 'summary.txt'
-    l_level = 9
+    l_level = 6
     CallOnFail = False
 
     l_total = 0
@@ -53,12 +53,12 @@ class lUtil:
     fsum = ''
     net  = ''
 
-    def log(self, str):
+    def log(self, str, level=6):
         if self.l_level > 0:
             if self.fout == '':
                 self.fout = open(self.fout_name, 'w', 0)
             self.fout.write(str+'\n')
-        if self.l_level > 5:
+        if level <= self.l_level:
             print(str)
 
     def summary(self, str):
@@ -226,14 +226,16 @@ Total %-4d                                                           %-4d %d\n\
             ret = success
         else:
             ret = search.group()
-            self.log('found:%s:' % ret)
             if op != 'fail':
                 success = True
+                level = 7
             else:
                 success = False
+                level = 5
+            self.log('found:%s:' % ret, level)
            # Experiment: compare matched strings obtained each way
            if self.l_dotall_experiment and (group_nl_converted != ret):
-               self.log('DOTALL experiment: strings differ dotall=[%s] orig=[%s]' % (group_nl_converted, ret))
+               self.log('DOTALL experiment: strings differ dotall=[%s] orig=[%s]' % (group_nl_converted, ret), 9)
         if op == 'pass' or op == 'fail':
             self.result(target, success, result)
         if js != None:
@@ -265,7 +267,7 @@ LUtil=None
 
 #entry calls
 def luStart(baseScriptDir='.', baseLogDir='.', net='',
-            fout='output.log', fsum='summary.txt', level=9):
+            fout='output.log', fsum='summary.txt', level=None):
     global LUtil
     #init class
     LUtil=lUtil()
@@ -276,7 +278,8 @@ def luStart(baseScriptDir='.', baseLogDir='.', net='',
         LUtil.fout_name = baseLogDir + '/' + fout
     if fsum != None:
         LUtil.fsum_name = baseLogDir + '/' + fsum
-    LUtil.l_level = level
+    if level != None:
+        LUtil.l_level = level
     LUtil.l_dotall_experiment = False
     LUtil.l_dotall_experiment = True
 
@@ -289,11 +292,11 @@ def luCommand(target, command, regexp='.', op='none', result='', time=10, return
 def luLast(usenl=False):
     if usenl:
        if LUtil.l_last_nl != None:
-           LUtil.log('luLast:%s:' %  LUtil.l_last_nl.group())
+           LUtil.log('luLast:%s:' %  LUtil.l_last_nl.group(), 7)
        return LUtil.l_last_nl
     else:
        if LUtil.l_last != None:
-           LUtil.log('luLast:%s:' %  LUtil.l_last.group())
+           LUtil.log('luLast:%s:' %  LUtil.l_last.group(), 7)
        return LUtil.l_last
 
 def luInclude(filename, CallOnFail=None):
index 6c6a06064de84f5b7d96e2835e5e23d91bc9b8ee..6afb418ad0890351d589111e3e3320f97dcff81e 100644 (file)
@@ -144,6 +144,7 @@ int main(int argc, char **argv, char **envp)
 
        master = frr_init();
 
+       access_list_init();
        vrrp_debug_init();
        vrrp_zebra_init();
        vrrp_vty_init();
index aaf70ab08b1d9917854b5cfb5c0da197979cbb97..17e5a7331c26c71fe4a85db1d645790d13f5154d 100644 (file)
@@ -62,35 +62,20 @@ static int vtysh_pam(const char *user)
 
        /* Start PAM. */
        ret = pam_start(FRR_PAM_NAME, user, &conv, &pamh);
-       /* printf ("ret %d\n", ret); */
 
        /* Is user really user? */
        if (ret == PAM_SUCCESS)
                ret = pam_authenticate(pamh, 0);
-/* printf ("ret %d\n", ret); */
 
-#if 0
-  /* Permitted access? */
-  if (ret == PAM_SUCCESS)
-    ret = pam_acct_mgmt (pamh, 0);
-  printf ("ret %d\n", ret);
-
-  if (ret == PAM_AUTHINFO_UNAVAIL)
-    ret = PAM_SUCCESS;
-#endif /* 0 */
-
-/* This is where we have been authorized or not. */
-#ifdef DEBUG
-       if (ret == PAM_SUCCESS)
-               printf("Authenticated\n");
-       else
-               printf("Not Authenticated\n");
-#endif /* DEBUG */
+       if (ret != PAM_SUCCESS)
+               fprintf(stderr, "vtysh_pam: Failure to initialize pam: %s(%d)",
+                       pam_strerror(pamh, ret), ret);
 
        /* close Linux-PAM */
        if (pam_end(pamh, ret) != PAM_SUCCESS) {
                pamh = NULL;
-               fprintf(stderr, "vtysh_pam: failed to release authenticator\n");
+               fprintf(stderr, "vtysh_pam: failed to release authenticator: %s(%d)\n",
+                       pam_strerror(pamh, ret), ret);
                exit(1);
        }
 
index bd4f9b66a937610364873a23ad5e7cf4978a3219..bba221c2cf13dbc0204ba06dbc09d280efb8e8f0 100644 (file)
@@ -207,16 +207,16 @@ void connected_up(struct interface *ifp, struct connected *ifc)
        struct nexthop nh = {
                .type = NEXTHOP_TYPE_IFINDEX,
                .ifindex = ifp->ifindex,
-               .vrf_id = vrf_to_id(ifp->vrf),
+               .vrf_id = ifp->vrf_id,
        };
        struct zebra_vrf *zvrf;
        uint32_t metric;
 
-       zvrf = zebra_vrf_lookup_by_id(ifp->vrf->vrf_id);
+       zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
        if (!zvrf) {
                flog_err(EC_ZEBRA_VRF_NOT_FOUND,
                         "%s: Received Up for interface but no associated zvrf: %d",
-                        __PRETTY_FUNCTION__, ifp->vrf->vrf_id);
+                        __PRETTY_FUNCTION__, ifp->vrf_id);
                return;
        }
        if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
@@ -265,7 +265,7 @@ void connected_up(struct interface *ifp, struct connected *ifc)
 
                zlog_debug(
                        "%u: IF %s address %s add/up, scheduling RIB processing",
-                       vrf_to_id(ifp->vrf), ifp->name,
+                       ifp->vrf_id, ifp->name,
                        prefix2str(&p, buf, sizeof(buf)));
        }
        rib_update(zvrf->vrf->vrf_id, RIB_UPDATE_IF_CHANGE);
@@ -383,15 +383,15 @@ void connected_down(struct interface *ifp, struct connected *ifc)
        struct nexthop nh = {
                .type = NEXTHOP_TYPE_IFINDEX,
                .ifindex = ifp->ifindex,
-               .vrf_id = vrf_to_id(ifp->vrf),
+               .vrf_id = ifp->vrf_id,
        };
        struct zebra_vrf *zvrf;
 
-       zvrf = zebra_vrf_lookup_by_id(ifp->vrf->vrf_id);
+       zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
        if (!zvrf) {
                flog_err(EC_ZEBRA_VRF_NOT_FOUND,
                         "%s: Received Up for interface but no associated zvrf: %d",
-                        __PRETTY_FUNCTION__, ifp->vrf->vrf_id);
+                        __PRETTY_FUNCTION__, ifp->vrf_id);
                return;
        }
 
@@ -473,22 +473,22 @@ static void connected_delete_helper(struct connected *ifc, struct prefix *p)
 
                zlog_debug(
                        "%u: IF %s IP %s address del, scheduling RIB processing",
-                       vrf_to_id(ifp->vrf), ifp->name,
+                       ifp->vrf_id, ifp->name,
                        prefix2str(p, buf, sizeof(buf)));
        }
-       rib_update(vrf_to_id(ifp->vrf), RIB_UPDATE_IF_CHANGE);
+       rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
 
        /* Schedule LSP forwarding entries for processing, if appropriate. */
-       if (vrf_to_id(ifp->vrf) == VRF_DEFAULT) {
+       if (ifp->vrf_id == VRF_DEFAULT) {
                if (IS_ZEBRA_DEBUG_MPLS) {
                        char buf[PREFIX_STRLEN];
 
                        zlog_debug(
                                "%u: IF %s IP %s address delete, scheduling MPLS processing",
-                               vrf_to_id(ifp->vrf), ifp->name,
+                               ifp->vrf_id, ifp->name,
                                prefix2str(p, buf, sizeof(buf)));
                }
-               mpls_mark_lsps_for_processing(zvrf_info_lookup(ifp->vrf), p);
+               mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id), p);
        }
 }
 
index 6ce566262d1c9586d198d158d486b4ee0795fffc..8bec2563553252db71cb11385471b5321e63fe2e 100644 (file)
@@ -54,7 +54,6 @@ static int interface_list_ioctl(void)
        struct interface *ifp;
        int n;
        int lastlen;
-       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
 
        /* Normally SIOCGIFCONF works with AF_INET socket. */
        sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -111,7 +110,7 @@ static int interface_list_ioctl(void)
                unsigned int size;
 
                ifreq = (struct ifreq *)((caddr_t)ifconf.ifc_req + n);
-               ifp = if_get_by_name(ifreq->ifr_name, vrf);
+               ifp = if_get_by_name(ifreq->ifr_name, VRF_DEFAULT);
                if_add_update(ifp);
                size = ifreq->ifr_addr.sa_len;
                if (size < sizeof(ifreq->ifr_addr))
@@ -121,7 +120,7 @@ static int interface_list_ioctl(void)
        }
 #else
        for (n = 0; n < ifconf.ifc_len; n += sizeof(struct ifreq)) {
-               ifp = if_get_by_name(ifreq->ifr_name, vrf);
+               ifp = if_get_by_name(ifreq->ifr_name, VRF_DEFAULT);
                if_add_update(ifp);
                ifreq++;
        }
@@ -152,8 +151,7 @@ static int if_get_hwaddr(struct interface *ifp)
        ifreq.ifr_addr.sa_family = AF_INET;
 
        /* Fetch Hardware address if available. */
-       ret = vrf_if_ioctl(SIOCGIFHWADDR, (caddr_t)&ifreq,
-                          vrf_to_id(ifp->vrf));
+       ret = vrf_if_ioctl(SIOCGIFHWADDR, (caddr_t)&ifreq, ifp->vrf_id);
        if (ret < 0)
                ifp->hw_addr_len = 0;
        else {
@@ -197,8 +195,7 @@ static int if_getaddrs(void)
                        continue;
                }
 
-               ifp = if_lookup_by_name(ifap->ifa_name,
-                                       vrf_lookup_by_id(VRF_DEFAULT));
+               ifp = if_lookup_by_name(ifap->ifa_name, VRF_DEFAULT);
                if (ifp == NULL) {
                        flog_err(EC_LIB_INTERFACE,
                                 "if_getaddrs(): Can't lookup interface %s\n",
index 1ed75bfa5575269b7ac124fa1eb6435a3bd24b3a..8b539a90499532be23337701a1d198098a7160c2 100644 (file)
@@ -59,7 +59,6 @@ static int interface_list_ioctl(int af)
        int n;
        size_t needed, lastneeded = 0;
        char *buf = NULL;
-       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
 
        frr_elevate_privs(&zserv_privs) {
                sock = socket(af, SOCK_DGRAM, 0);
@@ -157,7 +156,7 @@ calculate_lifc_len:
                       && (*(lifreq->lifr_name + normallen) != ':'))
                        normallen++;
 
-               ifp = if_get_by_name(lifreq->lifr_name, vrf);
+               ifp = if_get_by_name(lifreq->lifr_name, VRF_DEFAULT);
 
                if (lifreq->lifr_addr.ss_family == AF_INET)
                        ifp->flags |= IFF_IPV4;
index 4b6000c94b8e244bb9b5b770fb6170811352c5c2..df8d4bfe1541b1bd0a7e57da9be79ecb31983ac6 100644 (file)
@@ -387,7 +387,7 @@ static int get_iflink_speed(struct interface *interface)
        /* use ioctl to get IP address of an interface */
        frr_elevate_privs(&zserv_privs) {
                sd = vrf_socket(PF_INET, SOCK_DGRAM, IPPROTO_IP,
-                               vrf_to_id(interface->vrf),
+                               interface->vrf_id,
                                NULL);
                if (sd < 0) {
                        if (IS_ZEBRA_DEBUG_KERNEL)
@@ -396,7 +396,7 @@ static int get_iflink_speed(struct interface *interface)
                        return 0;
                }
        /* Get the current link state for the interface */
-               rc = vrf_ioctl(vrf_to_id(interface->vrf), sd, SIOCETHTOOL,
+               rc = vrf_ioctl(interface->vrf_id, sd, SIOCETHTOOL,
                               (char *)&ifdata);
        }
        if (rc < 0) {
@@ -598,7 +598,6 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
        ifindex_t link_ifindex = IFINDEX_INTERNAL;
        ifindex_t bond_ifindex = IFINDEX_INTERNAL;
        struct zebra_if *zif;
-       struct vrf *vrf;
 
        zns = zebra_ns_lookup(ns_id);
        ifi = NLMSG_DATA(h);
@@ -665,8 +664,6 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                    && !vrf_is_backend_netns()) {
                        zif_slave_type = ZEBRA_IF_SLAVE_VRF;
                        vrf_id = *(uint32_t *)RTA_DATA(tb[IFLA_MASTER]);
-                       /* vrf can be needed before vrf netlink discovery */
-                       vrf_get(vrf_id, NULL);
                } else if (slave_kind && (strcmp(slave_kind, "bridge") == 0)) {
                        zif_slave_type = ZEBRA_IF_SLAVE_BRIDGE;
                        bridge_ifindex =
@@ -679,13 +676,13 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
        }
        if (vrf_is_backend_netns())
                vrf_id = (vrf_id_t)ns_id;
-       vrf = vrf_lookup_by_id(vrf_id);
+
        /* If linking to another interface, note it. */
        if (tb[IFLA_LINK])
                link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
 
        /* Add interface. */
-       ifp = if_get_by_name(name, vrf);
+       ifp = if_get_by_name(name, vrf_id);
        set_ifindex(ifp, ifi->ifi_index, zns);
        ifp->flags = ifi->ifi_flags & 0x0000fffff;
        ifp->mtu6 = ifp->mtu = *(uint32_t *)RTA_DATA(tb[IFLA_MTU]);
@@ -1112,7 +1109,6 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
        ifindex_t link_ifindex = IFINDEX_INTERNAL;
        uint8_t old_hw_addr[INTERFACE_HWADDR_MAX];
        struct zebra_if *zif;
-       struct vrf *vrf;
 
        zns = zebra_ns_lookup(ns_id);
        ifi = NLMSG_DATA(h);
@@ -1213,9 +1209,6 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                }
                if (vrf_is_backend_netns())
                        vrf_id = (vrf_id_t)ns_id;
-
-               vrf = vrf_lookup_by_id(vrf_id);
-
                if (ifp == NULL
                    || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
                        /* Add interface notification from kernel */
@@ -1229,11 +1222,11 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
 
                        if (ifp == NULL) {
                                /* unknown interface */
-                               ifp = if_get_by_name(name, vrf);
+                               ifp = if_get_by_name(name, vrf_id);
                        } else {
                                /* pre-configured interface, learnt now */
-                               if (ifp->vrf != vrf)
-                                       if_update_to_new_vrf(ifp, vrf);
+                               if (ifp->vrf_id != vrf_id)
+                                       if_update_to_new_vrf(ifp, vrf_id);
                        }
 
                        /* Update interface information. */
@@ -1272,16 +1265,16 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                                                               bridge_ifindex);
                        else if (IS_ZEBRA_IF_BOND_SLAVE(ifp))
                                zebra_l2if_update_bond_slave(ifp, bond_ifindex);
-               } else if (ifp->vrf != vrf) {
+               } else if (ifp->vrf_id != vrf_id) {
                        /* VRF change for an interface. */
                        if (IS_ZEBRA_DEBUG_KERNEL)
                                zlog_debug(
                                        "RTM_NEWLINK vrf-change for %s(%u) "
                                        "vrf_id %u -> %u flags 0x%x",
-                                       name, ifp->ifindex, vrf_to_id(ifp->vrf),
-                                       vrf_id, ifi->ifi_flags);
+                                       name, ifp->ifindex, ifp->vrf_id, vrf_id,
+                                       ifi->ifi_flags);
 
-                       if_handle_vrf_change(ifp, vrf->vrf_id);
+                       if_handle_vrf_change(ifp, vrf_id);
                } else {
                        bool was_bridge_slave, was_bond_slave;
 
index 34bdd54b8b88c80e22b3049785fc61983ab77b6e..719cf05db1d1f5a07b8c3b892e9ddce82847ae3f 100644 (file)
@@ -530,7 +530,7 @@ void if_add_update(struct interface *ifp)
 {
        struct zebra_if *if_data;
        struct zebra_ns *zns;
-       struct zebra_vrf *zvrf = zvrf_info_lookup(ifp->vrf);
+       struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
 
        /* case interface populate before vrf enabled */
        if (zvrf->zns)
@@ -558,8 +558,7 @@ void if_add_update(struct interface *ifp)
                                zlog_debug(
                                        "interface %s vrf %u index %d is shutdown. "
                                        "Won't wake it up.",
-                                       ifp->name, vrf_to_id(ifp->vrf),
-                                       ifp->ifindex);
+                                       ifp->name, ifp->vrf_id, ifp->ifindex);
                        return;
                }
 
@@ -568,13 +567,12 @@ void if_add_update(struct interface *ifp)
                if (IS_ZEBRA_DEBUG_KERNEL)
                        zlog_debug(
                                "interface %s vrf %u index %d becomes active.",
-                               ifp->name, vrf_to_id(ifp->vrf), ifp->ifindex);
+                               ifp->name, ifp->vrf_id, ifp->ifindex);
 
        } else {
                if (IS_ZEBRA_DEBUG_KERNEL)
                        zlog_debug("interface %s vrf %u index %d is added.",
-                                  ifp->name, vrf_to_id(ifp->vrf),
-                                  ifp->ifindex);
+                                  ifp->name, ifp->vrf_id, ifp->ifindex);
        }
 }
 
@@ -716,7 +714,7 @@ void if_delete_update(struct interface *ifp)
                flog_err(
                        EC_LIB_INTERFACE,
                        "interface %s vrf %u index %d is still up while being deleted.",
-                       ifp->name, vrf_to_id(ifp->vrf), ifp->ifindex);
+                       ifp->name, ifp->vrf_id, ifp->ifindex);
                return;
        }
 
@@ -728,7 +726,7 @@ void if_delete_update(struct interface *ifp)
 
        if (IS_ZEBRA_DEBUG_KERNEL)
                zlog_debug("interface %s vrf %u index %d is now inactive.",
-                          ifp->name, vrf_to_id(ifp->vrf), ifp->ifindex);
+                          ifp->name, ifp->vrf_id, ifp->ifindex);
 
        /* Delete connected routes from the kernel. */
        if_delete_connected(ifp);
@@ -752,7 +750,7 @@ void if_delete_update(struct interface *ifp)
         * occur with this implementation whereas it is not possible with
         * vrf-lite).
         */
-       if (ifp->vrf->vrf_id && !vrf_is_backend_netns())
+       if (ifp->vrf_id && !vrf_is_backend_netns())
                if_handle_vrf_change(ifp, VRF_DEFAULT);
 
        /* Reset some zebra interface params to default values. */
@@ -770,9 +768,8 @@ void if_delete_update(struct interface *ifp)
 void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id)
 {
        vrf_id_t old_vrf_id;
-       struct vrf *vrf = vrf_lookup_by_id(vrf_id);
 
-       old_vrf_id = vrf_to_id(ifp->vrf);
+       old_vrf_id = ifp->vrf_id;
 
        /* Uninstall connected routes. */
        if_uninstall_connected(ifp);
@@ -788,7 +785,7 @@ void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id)
        zebra_interface_vrf_update_del(ifp, vrf_id);
 
        /* update VRF */
-       if_update_to_new_vrf(ifp, vrf);
+       if_update_to_new_vrf(ifp, vrf_id);
 
        /* Send out notification on interface VRF change. */
        /* This is to issue an ADD, if needed. */
@@ -803,9 +800,9 @@ void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id)
         */
        if (IS_ZEBRA_DEBUG_RIB_DETAILED)
                zlog_debug("%u: IF %s VRF change, scheduling RIB processing",
-                          vrf_to_id(ifp->vrf), ifp->name);
+                          ifp->vrf_id, ifp->name);
        rib_update(old_vrf_id, RIB_UPDATE_IF_CHANGE);
-       rib_update(vrf_to_id(ifp->vrf), RIB_UPDATE_IF_CHANGE);
+       rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
 }
 
 static void ipv6_ll_address_to_mac(struct in6_addr *address, uint8_t *mac)
@@ -823,7 +820,7 @@ void if_nbr_mac_to_ipv4ll_neigh_update(struct interface *ifp,
                                       struct in6_addr *address,
                                       int add)
 {
-       struct zebra_vrf *zvrf = zvrf_info_lookup(ifp->vrf);
+       struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
        struct zebra_if *zif = ifp->info;
        char buf[16] = "169.254.0.1";
        struct in_addr ipv4_ll;
@@ -919,7 +916,7 @@ void if_up(struct interface *ifp)
 {
        struct zebra_if *zif;
        struct interface *link_if;
-       struct zebra_vrf *zvrf = zvrf_info_lookup(ifp->vrf);
+       struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
 
        zif = ifp->info;
        zif->up_count++;
@@ -950,8 +947,8 @@ void if_up(struct interface *ifp)
 
        if (IS_ZEBRA_DEBUG_RIB_DETAILED)
                zlog_debug("%u: IF %s up, scheduling RIB processing",
-                          vrf_to_id(ifp->vrf), ifp->name);
-       rib_update(vrf_to_id(ifp->vrf), RIB_UPDATE_IF_CHANGE);
+                          ifp->vrf_id, ifp->name);
+       rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
 
        /* Handle interface up for specific types for EVPN. Non-VxLAN interfaces
         * are checked to see if (remote) neighbor entries need to be installed
@@ -976,7 +973,7 @@ void if_down(struct interface *ifp)
 {
        struct zebra_if *zif;
        struct interface *link_if;
-       struct zebra_vrf *zvrf = zvrf_info_lookup(ifp->vrf);
+       struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
 
        zif = ifp->info;
        zif->down_count++;
@@ -1008,8 +1005,8 @@ void if_down(struct interface *ifp)
 
        if (IS_ZEBRA_DEBUG_RIB_DETAILED)
                zlog_debug("%u: IF %s down, scheduling RIB processing",
-                          vrf_to_id(ifp->vrf), ifp->name);
-       rib_update(vrf_to_id(ifp->vrf), RIB_UPDATE_IF_CHANGE);
+                          ifp->vrf_id, ifp->name);
+       rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
 
        if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp);
 
@@ -1310,7 +1307,7 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp)
 
        zebra_ptm_show_status(vty, ifp);
 
-       vrf = ifp->vrf;
+       vrf = vrf_lookup_by_id(ifp->vrf_id);
        vty_out(vty, "  vrf: %s\n", vrf->name);
 
        if (ifp->desc)
@@ -1572,15 +1569,17 @@ DEFPY(show_interface, show_interface_cmd,
       VRF_CMD_HELP_STR
       "Interface status and configuration summary\n")
 {
-       struct vrf *vrf = NULL;
+       struct vrf *vrf;
        struct interface *ifp;
+       vrf_id_t vrf_id = VRF_DEFAULT;
 
        interface_update_stats();
 
        if (name)
-               VRF_GET_INSTANCE(vrf, name, false, false);
+               VRF_GET_ID(vrf_id, name, false);
 
        /* All interface print. */
+       vrf = vrf_lookup_by_id(vrf_id);
        if (brief) {
                ifs_dump_brief_vty(vty, vrf);
        } else {
@@ -1633,14 +1632,14 @@ DEFUN (show_interface_name_vrf,
        int idx_ifname = 2;
        int idx_name = 4;
        struct interface *ifp;
-       struct vrf *vrf;
+       vrf_id_t vrf_id;
 
        interface_update_stats();
 
-       VRF_GET_INSTANCE(vrf, argv[idx_name]->arg, false, false);
+       VRF_GET_ID(vrf_id, argv[idx_name]->arg, false);
 
        /* Specified interface print. */
-       ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf);
+       ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
        if (ifp == NULL) {
                vty_out(vty, "%% Can't find interface %s\n",
                        argv[idx_ifname]->arg);
@@ -1670,7 +1669,7 @@ DEFUN (show_interface_name_vrf_all,
        /* All interface print. */
        RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
                /* Specified interface print. */
-               ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf);
+               ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf->vrf_id);
                if (ifp) {
                        if_dump_vty(vty, ifp);
                        found++;
@@ -1687,8 +1686,9 @@ DEFUN (show_interface_name_vrf_all,
 }
 
 
-static void if_show_description(struct vty *vty, struct vrf *vrf)
+static void if_show_description(struct vty *vty, vrf_id_t vrf_id)
 {
+       struct vrf *vrf = vrf_lookup_by_id(vrf_id);
        struct interface *ifp;
 
        vty_out(vty, "Interface       Status  Protocol  Description\n");
@@ -1742,14 +1742,12 @@ DEFUN (show_interface_desc,
        "Interface description\n"
        VRF_CMD_HELP_STR)
 {
-       struct vrf *vrf;
+       vrf_id_t vrf_id = VRF_DEFAULT;
 
        if (argc > 3)
-               VRF_GET_INSTANCE(vrf, argv[4]->arg, false, false);
-       else
-               vrf = vrf_lookup_by_id(VRF_DEFAULT);
+               VRF_GET_ID(vrf_id, argv[4]->arg, false);
 
-       if_show_description(vty, vrf);
+       if_show_description(vty, vrf_id);
 
        return CMD_SUCCESS;
 }
@@ -1768,7 +1766,7 @@ DEFUN (show_interface_desc_vrf_all,
        RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
                if (!RB_EMPTY(if_name_head, &vrf->ifaces_by_name)) {
                        vty_out(vty, "\n\tVRF %u\n\n", vrf->vrf_id);
-                       if_show_description(vty, vrf);
+                       if_show_description(vty, vrf->vrf_id);
                }
 
        return CMD_SUCCESS;
@@ -3122,9 +3120,9 @@ static int if_config_write(struct vty *vty)
                        struct vrf *vrf;
 
                        if_data = ifp->info;
-                       vrf = ifp->vrf;
+                       vrf = vrf_lookup_by_id(ifp->vrf_id);
 
-                       if (vrf->vrf_id == VRF_DEFAULT)
+                       if (ifp->vrf_id == VRF_DEFAULT)
                                vty_frame(vty, "interface %s\n", ifp->name);
                        else
                                vty_frame(vty, "interface %s vrf %s\n",
index 628be6563af9927d8c5b7287349682b40ff383a7..8202e076afb49cf387408d95d38b12f077b3036b 100644 (file)
@@ -142,8 +142,7 @@ void if_get_metric(struct interface *ifp)
 
        ifreq_set_name(&ifreq, ifp);
 
-       if (vrf_if_ioctl(SIOCGIFMETRIC, (caddr_t)&ifreq,
-                        vrf_to_id(ifp->vrf)) < 0)
+       if (vrf_if_ioctl(SIOCGIFMETRIC, (caddr_t)&ifreq, ifp->vrf_id) < 0)
                return;
        ifp->metric = ifreq.ifr_metric;
        if (ifp->metric == 0)
@@ -161,8 +160,7 @@ void if_get_mtu(struct interface *ifp)
        ifreq_set_name(&ifreq, ifp);
 
 #if defined(SIOCGIFMTU)
-       if (vrf_if_ioctl(SIOCGIFMTU, (caddr_t)&ifreq,
-                        vrf_to_id(ifp->vrf)) < 0) {
+       if (vrf_if_ioctl(SIOCGIFMTU, (caddr_t)&ifreq, ifp->vrf_id) < 0) {
                zlog_info("Can't lookup mtu by ioctl(SIOCGIFMTU)");
                ifp->mtu6 = ifp->mtu = -1;
                return;
@@ -429,7 +427,7 @@ void if_get_flags(struct interface *ifp)
 
        ifreq_set_name(&ifreq, ifp);
 
-       ret = vrf_if_ioctl(SIOCGIFFLAGS, (caddr_t)&ifreq, vrf_to_id(ifp->vrf));
+       ret = vrf_if_ioctl(SIOCGIFFLAGS, (caddr_t)&ifreq, ifp->vrf_id);
        if (ret < 0) {
                flog_err_sys(EC_LIB_SYSTEM_CALL,
                             "vrf_if_ioctl(SIOCGIFFLAGS) failed: %s",
@@ -479,7 +477,7 @@ int if_set_flags(struct interface *ifp, uint64_t flags)
        ifreq.ifr_flags = ifp->flags;
        ifreq.ifr_flags |= flags;
 
-       ret = vrf_if_ioctl(SIOCSIFFLAGS, (caddr_t)&ifreq, vrf_to_id(ifp->vrf));
+       ret = vrf_if_ioctl(SIOCSIFFLAGS, (caddr_t)&ifreq, ifp->vrf_id);
 
        if (ret < 0) {
                zlog_info("can't set interface flags");
@@ -500,7 +498,7 @@ int if_unset_flags(struct interface *ifp, uint64_t flags)
        ifreq.ifr_flags = ifp->flags;
        ifreq.ifr_flags &= ~flags;
 
-       ret = vrf_if_ioctl(SIOCSIFFLAGS, (caddr_t)&ifreq, vrf_to_id(ifp->vrf));
+       ret = vrf_if_ioctl(SIOCSIFFLAGS, (caddr_t)&ifreq, ifp->vrf_id);
 
        if (ret < 0) {
                zlog_info("can't unset interface flags");
index be1191bac11b82630728206df435a0e643f194d1..156ce50725ec758d6e99f5594006a9f38912bf1c 100644 (file)
@@ -435,7 +435,6 @@ static void rtm_flag_dump(int flag)
 static int ifan_read(struct if_announcemsghdr *ifan)
 {
        struct interface *ifp;
-       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
 
        ifp = if_lookup_by_index(ifan->ifan_index, VRF_DEFAULT);
 
@@ -451,7 +450,7 @@ static int ifan_read(struct if_announcemsghdr *ifan)
                                __func__, ifan->ifan_index, ifan->ifan_name);
 
                /* Create Interface */
-               ifp = if_get_by_name(ifan->ifan_name, vrf);
+               ifp = if_get_by_name(ifan->ifan_name, VRF_DEFAULT);
                if_set_index(ifp, ifan->ifan_index);
 
                if_get_metric(ifp);
@@ -530,7 +529,6 @@ int ifm_read(struct if_msghdr *ifm)
        int maskbit;
        caddr_t cp;
        char fbuf[64];
-       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
 
        /* terminate ifname at head (for strnlen) and tail (for safety) */
        ifname[IFNAMSIZ - 1] = '\0';
@@ -616,7 +614,7 @@ int ifm_read(struct if_msghdr *ifm)
         * be filled in.
         */
        if ((ifp == NULL) && ifnlen)
-               ifp = if_lookup_by_name(ifname, vrf);
+               ifp = if_lookup_by_name(ifname, VRF_DEFAULT);
 
        /*
         * If ifp still does not exist or has an invalid index
@@ -645,7 +643,7 @@ int ifm_read(struct if_msghdr *ifm)
                if (ifp == NULL) {
                        /* Interface that zebra was not previously aware of, so
                         * create. */
-                       ifp = if_create(ifname, vrf);
+                       ifp = if_create(ifname, VRF_DEFAULT);
                        if (IS_ZEBRA_DEBUG_KERNEL)
                                zlog_debug("%s: creating ifp for ifindex %d",
                                           __func__, ifm->ifm_index);
index 5797a5846aa8ef6f398a4148636cc7aa0e030cc6..19471067509ea9cea815ec88751d2f0c415e268b 100644 (file)
@@ -55,6 +55,7 @@
 #include "zebra/zebra_netns_notify.h"
 #include "zebra/zebra_rnh.h"
 #include "zebra/zebra_pbr.h"
+#include "zebra/zebra_vxlan.h"
 
 #if defined(HANDLE_NETLINK_FUZZING)
 #include "zebra/kernel_netlink.h"
@@ -455,6 +456,9 @@ int main(int argc, char **argv)
        /* RNH init */
        zebra_rnh_init();
 
+       /* Config handler Init */
+       zebra_evpn_init();
+
        /* Error init */
        zebra_error_init();
 
index 7b3332e58284062b8c615972e7f97d9c61278351..b13f1170cd5defa3dc53c1d32b0b3d327b81961b 100644 (file)
@@ -402,7 +402,7 @@ void zebra_interface_up_update(struct interface *ifp)
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s(%u)",
-                          ifp->name, vrf_to_id(ifp->vrf));
+                          ifp->name, ifp->vrf_id);
 
        if (ifp->ptm_status || !ifp->ptm_enable) {
                for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode,
@@ -422,7 +422,7 @@ void zebra_interface_down_update(struct interface *ifp)
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)",
-                          ifp->name, vrf_to_id(ifp->vrf));
+                          ifp->name, ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
                zsend_interface_update(ZEBRA_INTERFACE_DOWN, client, ifp);
@@ -437,7 +437,7 @@ void zebra_interface_add_update(struct interface *ifp)
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s(%u)", ifp->name,
-                          vrf_to_id(ifp->vrf));
+                          ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
                client->ifadd_cnt++;
@@ -453,7 +453,7 @@ void zebra_interface_delete_update(struct interface *ifp)
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s(%u)",
-                          ifp->name, vrf_to_id(ifp->vrf));
+                          ifp->name, ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
                client->ifdel_cnt++;
@@ -475,7 +475,7 @@ void zebra_interface_address_add_update(struct interface *ifp,
                p = ifc->address;
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s(%u)",
                           prefix2str(p, buf, sizeof(buf)), ifp->name,
-                          vrf_to_id(ifp->vrf));
+                          ifp->vrf_id);
        }
 
        if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
@@ -509,7 +509,7 @@ void zebra_interface_address_delete_update(struct interface *ifp,
                p = ifc->address;
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s(%u)",
                           prefix2str(p, buf, sizeof(buf)),
-                          ifp->name, vrf_to_id(ifp->vrf));
+                          ifp->name, ifp->vrf_id);
        }
 
        zebra_vxlan_add_del_gw_macip(ifp, ifc->address, 0);
@@ -535,7 +535,7 @@ void zebra_interface_vrf_update_del(struct interface *ifp, vrf_id_t new_vrf_id)
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug(
                        "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u",
-                       ifp->name, vrf_to_id(ifp->vrf), new_vrf_id);
+                       ifp->name, ifp->vrf_id, new_vrf_id);
 
        for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
                /* Need to delete if the client is not interested in the new
@@ -558,7 +558,7 @@ void zebra_interface_vrf_update_add(struct interface *ifp, vrf_id_t old_vrf_id)
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug(
                        "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u",
-                       ifp->name, old_vrf_id, vrf_to_id(ifp->vrf));
+                       ifp->name, old_vrf_id, ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) {
                /* Need to add if the client is interested in the new VRF. */
@@ -816,7 +816,7 @@ void zebra_interface_parameters_update(struct interface *ifp)
 
        if (IS_ZEBRA_DEBUG_EVENT)
                zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)",
-                          ifp->name, vrf_to_id(ifp->vrf));
+                          ifp->name, ifp->vrf_id);
 
        for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client))
                zsend_interface_link_params(client, ifp);
index b5a8860c43daf08ab67123f11356fd17b64017e8..569ffbab411f80fd0bcf0ace9680a09e63993d87 100644 (file)
@@ -122,7 +122,7 @@ void router_id_add_address(struct connected *ifc)
        struct prefix before;
        struct prefix after;
        struct zserv *client;
-       struct zebra_vrf *zvrf = vrf_info_get(vrf_to_id(ifc->ifp->vrf));
+       struct zebra_vrf *zvrf = vrf_info_get(ifc->ifp->vrf_id);
 
        if (router_id_bad_address(ifc))
                return;
@@ -154,7 +154,7 @@ void router_id_del_address(struct connected *ifc)
        struct prefix before;
        struct listnode *node;
        struct zserv *client;
-       struct zebra_vrf *zvrf = vrf_info_get(vrf_to_id(ifc->ifp->vrf));
+       struct zebra_vrf *zvrf = vrf_info_get(ifc->ifp->vrf_id);
 
        if (router_id_bad_address(ifc))
                return;
index c4654510bef96115a08036a79e9ccacdde76df02..b05d037f960640d574524476d12c864fe2d3a62e 100644 (file)
@@ -549,7 +549,7 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
                                                zebra_ns_lookup(ns_id),
                                                index);
                                if (ifp)
-                                       nh_vrf_id = vrf_to_id(ifp->vrf);
+                                       nh_vrf_id = ifp->vrf_id;
                        }
                        nh.vrf_id = nh_vrf_id;
 
@@ -609,7 +609,7 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
                                                        zebra_ns_lookup(ns_id),
                                                        index);
                                        if (ifp)
-                                               nh_vrf_id = vrf_to_id(ifp->vrf);
+                                               nh_vrf_id = ifp->vrf_id;
                                        else {
                                                flog_warn(
                                                        EC_ZEBRA_UNKNOWN_INTERFACE,
@@ -1893,7 +1893,7 @@ static int netlink_vxlan_flood_list_update(struct interface *ifp,
                char buf[256];
        } req;
        uint8_t dst_mac[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
-       struct zebra_vrf *zvrf = zvrf_info_lookup(ifp->vrf);
+       struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
 
        zns = zvrf->zns;
        memset(&req, 0, sizeof(req));
@@ -2291,7 +2291,7 @@ static int netlink_macfdb_update(struct interface *ifp, vlanid_t vid,
        int vid_present = 0;
        char vid_buf[20];
        char dst_buf[30];
-       struct zebra_vrf *zvrf = zvrf_info_lookup(ifp->vrf);
+       struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
 
        zns = zvrf->zns;
        zif = ifp->info;
@@ -2348,7 +2348,8 @@ static int netlink_macfdb_update(struct interface *ifp, vlanid_t vid,
  * 5549 support, re-install them.
  */
 static void netlink_handle_5549(struct ndmsg *ndm, struct zebra_if *zif,
-                               struct interface *ifp, struct ipaddr *ip)
+                               struct interface *ifp, struct ipaddr *ip,
+                               bool handle_failed)
 {
        if (ndm->ndm_family != AF_INET)
                return;
@@ -2359,6 +2360,12 @@ static void netlink_handle_5549(struct ndmsg *ndm, struct zebra_if *zif,
        if (ipv4_ll.s_addr != ip->ip._v4_addr.s_addr)
                return;
 
+       if (handle_failed && ndm->ndm_state & NUD_FAILED) {
+               zlog_info("Neighbor Entry for %s has entered a failed state, not reinstalling",
+                         ifp->name);
+               return;
+       }
+
        if_nbr_ipv6ll_to_ipv4ll_neigh_update(ifp, &zif->v6_2_v4_ll_addr6, true);
 }
 
@@ -2409,7 +2416,7 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
 
        /* if kernel deletes our rfc5549 neighbor entry, re-install it */
        if (h->nlmsg_type == RTM_DELNEIGH && (ndm->ndm_state & NUD_PERMANENT)) {
-               netlink_handle_5549(ndm, zif, ifp, &ip);
+               netlink_handle_5549(ndm, zif, ifp, &ip, false);
                if (IS_ZEBRA_DEBUG_KERNEL)
                        zlog_debug(
                                "\tNeighbor Entry Received is a 5549 entry, finished");
@@ -2417,13 +2424,8 @@ static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
        }
 
        /* if kernel marks our rfc5549 neighbor entry invalid, re-install it */
-       if (h->nlmsg_type == RTM_NEWNEIGH && !(ndm->ndm_state & NUD_VALID)) {
-               if (!(ndm->ndm_state & NUD_FAILED))
-                       netlink_handle_5549(ndm, zif, ifp, &ip);
-               else
-                       zlog_info("Neighbor Entry for %s has entered a failed state, not reinstalling",
-                               ifp->name);
-       }
+       if (h->nlmsg_type == RTM_NEWNEIGH && !(ndm->ndm_state & NUD_VALID))
+               netlink_handle_5549(ndm, zif, ifp, &ip, true);
 
        /* The neighbor is present on an SVI. From this, we locate the
         * underlying
@@ -2640,7 +2642,7 @@ int netlink_neigh_read_specific_ip(struct ipaddr *ip,
 {
        int ret = 0;
        struct zebra_ns *zns;
-       struct zebra_vrf *zvrf = zvrf_info_lookup(vlan_if->vrf);
+       struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(vlan_if->vrf_id);
        char buf[INET6_ADDRSTRLEN];
        struct zebra_dplane_info dp_info;
 
@@ -2653,7 +2655,7 @@ int netlink_neigh_read_specific_ip(struct ipaddr *ip,
                           __PRETTY_FUNCTION__, vlan_if->name,
                           vlan_if->ifindex,
                           ipaddr2str(ip, buf, sizeof(buf)),
-                          vrf_to_id(vlan_if->vrf));
+                          vlan_if->vrf_id);
 
        ret = netlink_request_specific_neigh_in_vlan(zns, RTM_GETNEIGH, ip,
                                            vlan_if->ifindex);
@@ -2718,7 +2720,7 @@ static int netlink_neigh_update2(struct interface *ifp, struct ipaddr *ip,
        struct zebra_ns *zns;
        char buf[INET6_ADDRSTRLEN];
        char buf2[ETHER_ADDR_STRLEN];
-       struct zebra_vrf *zvrf =  zvrf_info_lookup(ifp->vrf);
+       struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
 
        zns = zvrf->zns;
        memset(&req, 0, sizeof(req));
index 33d0022a9d9baefc7c726a413196d82820e66f05..5841c44b0334fa152735397c2b956cf933478802 100644 (file)
@@ -534,7 +534,7 @@ static int rtadv_timer(struct thread *thread)
 
 static void rtadv_process_solicit(struct interface *ifp)
 {
-       struct zebra_vrf *zvrf = zvrf_info_lookup(ifp->vrf);
+       struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id);
 
        assert(zvrf);
        rtadv_send_packet(rtadv_get_socket(zvrf), ifp);
@@ -884,7 +884,7 @@ static void ipv6_nd_suppress_ra_set(struct interface *ifp,
        struct zebra_vrf *zvrf;
 
        zif = ifp->info;
-       zvrf = zvrf_info_lookup(ifp->vrf);
+       zvrf = vrf_info_lookup(ifp->vrf_id);
 
        if (status == RA_SUPPRESS) {
                /* RA is currently enabled */
@@ -957,11 +957,11 @@ static void zebra_interface_radv_set(ZAPI_HANDLER_ARGS, int enable)
                          zebra_route_string(client->proto));
                return;
        }
-       if (ifp->vrf != zvrf->vrf) {
+       if (ifp->vrf_id != zvrf_id(zvrf)) {
                zlog_debug(
                        "%u: IF %u RA %s client %s - VRF mismatch, IF VRF %u",
                        zvrf_id(zvrf), ifindex, enable ? "enable" : "disable",
-                       zebra_route_string(client->proto), vrf_to_id(ifp->vrf));
+                       zebra_route_string(client->proto), ifp->vrf_id);
                return;
        }
 
@@ -1058,7 +1058,7 @@ DEFUN (ipv6_nd_ra_interval_msec,
        struct zebra_if *zif = ifp->info;
        struct zebra_vrf *zvrf;
 
-       zvrf = zvrf_info_lookup(ifp->vrf);
+       zvrf = vrf_info_lookup(ifp->vrf_id);
 
        interval = strtoul(argv[idx_number]->arg, NULL, 10);
        if ((zif->rtadv.AdvDefaultLifetime != -1
@@ -1096,7 +1096,7 @@ DEFUN (ipv6_nd_ra_interval,
        struct zebra_if *zif = ifp->info;
        struct zebra_vrf *zvrf;
 
-       zvrf = zvrf_info_lookup(ifp->vrf);
+       zvrf = vrf_info_lookup(ifp->vrf_id);
 
        interval = strtoul(argv[idx_number]->arg, NULL, 10);
        if ((zif->rtadv.AdvDefaultLifetime != -1
@@ -1135,7 +1135,7 @@ DEFUN (no_ipv6_nd_ra_interval,
        struct zebra_if *zif = ifp->info;
        struct zebra_vrf *zvrf = NULL;
 
-       zvrf = zvrf_info_lookup(ifp->vrf);
+       zvrf = vrf_info_lookup(ifp->vrf_id);
 
        if (zif->rtadv.MaxRtrAdvInterval % 1000)
                zvrf->rtadv.adv_msec_if_count--;
index 2f41f7133d8383280c8f863ca29d2207a7fe0f33..61200806ba84ca81b9077771dd0be3963b51b25e 100644 (file)
@@ -165,7 +165,7 @@ int zsend_interface_add(struct zserv *client, struct interface *ifp)
 {
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       zclient_create_header(s, ZEBRA_INTERFACE_ADD, vrf_to_id(ifp->vrf));
+       zclient_create_header(s, ZEBRA_INTERFACE_ADD, ifp->vrf_id);
        zserv_encode_interface(s, ifp);
 
        client->ifadd_cnt++;
@@ -177,7 +177,7 @@ int zsend_interface_delete(struct zserv *client, struct interface *ifp)
 {
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       zclient_create_header(s, ZEBRA_INTERFACE_DELETE, vrf_to_id(ifp->vrf));
+       zclient_create_header(s, ZEBRA_INTERFACE_DELETE, ifp->vrf_id);
        zserv_encode_interface(s, ifp);
 
        client->ifdel_cnt++;
@@ -217,8 +217,7 @@ int zsend_interface_link_params(struct zserv *client, struct interface *ifp)
                return 0;
        }
 
-       zclient_create_header(s, ZEBRA_INTERFACE_LINK_PARAMS,
-                             vrf_to_id(ifp->vrf));
+       zclient_create_header(s, ZEBRA_INTERFACE_LINK_PARAMS, ifp->vrf_id);
 
        /* Add Interface Index */
        stream_putl(s, ifp->ifindex);
@@ -280,7 +279,7 @@ int zsend_interface_address(int cmd, struct zserv *client,
        struct prefix *p;
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       zclient_create_header(s, cmd, vrf_to_id(ifp->vrf));
+       zclient_create_header(s, cmd, ifp->vrf_id);
        stream_putl(s, ifp->ifindex);
 
        /* Interface address flag. */
@@ -322,7 +321,7 @@ static int zsend_interface_nbr_address(int cmd, struct zserv *client,
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
        struct prefix *p;
 
-       zclient_create_header(s, cmd, vrf_to_id(ifp->vrf));
+       zclient_create_header(s, cmd, ifp->vrf_id);
        stream_putl(s, ifp->ifindex);
 
        /* Prefix information. */
@@ -430,8 +429,7 @@ int zsend_interface_vrf_update(struct zserv *client, struct interface *ifp,
 {
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       zclient_create_header(s, ZEBRA_INTERFACE_VRF_UPDATE,
-                             vrf_to_id(ifp->vrf));
+       zclient_create_header(s, ZEBRA_INTERFACE_VRF_UPDATE, ifp->vrf_id);
 
        /* Fill in the name of the interface and its new VRF (id) */
        stream_put(s, ifp->name, INTERFACE_NAMSIZ);
@@ -506,7 +504,7 @@ int zsend_interface_update(int cmd, struct zserv *client, struct interface *ifp)
 {
        struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
 
-       zclient_create_header(s, cmd, vrf_to_id(ifp->vrf));
+       zclient_create_header(s, cmd, ifp->vrf_id);
        zserv_encode_interface(s, ifp);
 
        if (cmd == ZEBRA_INTERFACE_UP)
@@ -2209,9 +2207,9 @@ static void zread_vrf_label(ZAPI_HANDLER_ARGS)
        STREAM_GETC(s, ltype);
 
        if (zvrf->vrf->vrf_id != VRF_DEFAULT)
-               ifp = if_lookup_by_name(zvrf->vrf->name, zvrf->vrf);
+               ifp = if_lookup_by_name(zvrf->vrf->name, zvrf->vrf->vrf_id);
        else
-               ifp = if_lookup_by_name("lo", vrf_lookup_by_id(VRF_DEFAULT));
+               ifp = if_lookup_by_name("lo", VRF_DEFAULT);
 
        if (!ifp) {
                zlog_debug("Unable to find specified Interface for %s",
index e2128b1c8995ba94db8b2e4bc011d6bb49464635..f93562b31b53a2263dc11d05b2455dc073b7efb5 100644 (file)
@@ -1920,7 +1920,7 @@ enum zebra_dplane_result dplane_intf_addr_set(const struct interface *ifp,
                struct prefix_ipv4 *p;
 
                p = (struct prefix_ipv4 *)ifc->address;
-               rib_lookup_and_pushup(p, ifp->vrf->vrf_id);
+               rib_lookup_and_pushup(p, ifp->vrf_id);
        }
 #endif
 
@@ -1951,7 +1951,7 @@ static enum zebra_dplane_result intf_addr_update_internal(
                prefix2str(ifc->address, addr_str, sizeof(addr_str));
 
                zlog_debug("init intf ctx %s: idx %d, addr %u:%s",
-                          dplane_op2str(op), ifp->ifindex, ifp->vrf->vrf_id,
+                          dplane_op2str(op), ifp->ifindex, ifp->vrf_id,
                           addr_str);
        }
 
@@ -1959,9 +1959,9 @@ static enum zebra_dplane_result intf_addr_update_internal(
 
        ctx->zd_op = op;
        ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS;
-       ctx->zd_vrf_id = ifp->vrf->vrf_id;
+       ctx->zd_vrf_id = ifp->vrf_id;
 
-       zns = zebra_ns_lookup(ifp->vrf->vrf_id);
+       zns = zebra_ns_lookup(ifp->vrf_id);
        dplane_ctx_ns_init(ctx, zns, false);
 
        /* Init the interface-addr-specific area */
index 636bceb9804e568148c625f786df33c6ec24b156..46f138552059f6f9edfc03287cc3bc991c2ec22f 100644 (file)
@@ -522,7 +522,7 @@ static int zebra_ptm_handle_bfd_msg(void *arg, void *in_ctxt,
        }
 
        if (!strcmp(ZEBRA_PTM_INVALID_VRF, vrf_str) && ifp) {
-               vrf_id = vrf_to_id(ifp->vrf);
+               vrf_id = ifp->vrf_id;
        } else {
                vrf_id = vrf_name_to_id(vrf_str);
        }
index 555bec95937bfa5716037b181e8af59606a7539f..2df24f75c5e1ed1b1d6a85c68218aeee94e2106e 100644 (file)
@@ -2444,6 +2444,7 @@ void _route_entry_dump(const char *func, union prefixconstptr pp,
        bool is_srcdst = src_p && src_p->prefixlen;
        char straddr[PREFIX_STRLEN];
        char srcaddr[PREFIX_STRLEN];
+       char nhname[PREFIX_STRLEN];
        struct nexthop *nexthop;
 
        zlog_debug("%s: dumping RE entry %p for %s%s%s vrf %u", func,
@@ -2453,12 +2454,12 @@ void _route_entry_dump(const char *func, union prefixconstptr pp,
                             : "",
                   re->vrf_id);
        zlog_debug("%s: uptime == %lu, type == %u, instance == %d, table == %d",
-                  func, (unsigned long)re->uptime, re->type, re->instance,
+                  straddr, (unsigned long)re->uptime, re->type, re->instance,
                   re->table);
        zlog_debug(
                "%s: metric == %u, mtu == %u, distance == %u, flags == %u, status == %u",
-               func, re->metric, re->mtu, re->distance, re->flags, re->status);
-       zlog_debug("%s: nexthop_num == %u, nexthop_active_num == %u", func,
+               straddr, re->metric, re->mtu, re->distance, re->flags, re->status);
+       zlog_debug("%s: nexthop_num == %u, nexthop_active_num == %u", straddr,
                   re->nexthop_num, re->nexthop_active_num);
 
        for (ALL_NEXTHOPS(re->ng, nexthop)) {
@@ -2467,27 +2468,27 @@ void _route_entry_dump(const char *func, union prefixconstptr pp,
 
                switch (nexthop->type) {
                case NEXTHOP_TYPE_BLACKHOLE:
-                       sprintf(straddr, "Blackhole");
+                       sprintf(nhname, "Blackhole");
                        break;
                case NEXTHOP_TYPE_IFINDEX:
                        ifp = if_lookup_by_index(nexthop->ifindex,
                                                 nexthop->vrf_id);
-                       sprintf(straddr, "%s", ifp ? ifp->name : "Unknown");
+                       sprintf(nhname, "%s", ifp ? ifp->name : "Unknown");
                        break;
                case NEXTHOP_TYPE_IPV4:
                        /* fallthrough */
                case NEXTHOP_TYPE_IPV4_IFINDEX:
-                       inet_ntop(AF_INET, &nexthop->gate, straddr,
+                       inet_ntop(AF_INET, &nexthop->gate, nhname,
                                  INET6_ADDRSTRLEN);
                        break;
                case NEXTHOP_TYPE_IPV6:
                case NEXTHOP_TYPE_IPV6_IFINDEX:
-                       inet_ntop(AF_INET6, &nexthop->gate, straddr,
+                       inet_ntop(AF_INET6, &nexthop->gate, nhname,
                                  INET6_ADDRSTRLEN);
                        break;
                }
                zlog_debug("%s: %s %s[%u] vrf %s(%u) with flags %s%s%s%s%s%s",
-                          func, (nexthop->rparent ? "  NH" : "NH"), straddr,
+                          straddr, (nexthop->rparent ? "  NH" : "NH"), nhname,
                           nexthop->ifindex, vrf ? vrf->name : "Unknown",
                           nexthop->vrf_id,
                           (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)
@@ -2509,7 +2510,7 @@ void _route_entry_dump(const char *func, union prefixconstptr pp,
                                    ? "DUPLICATE "
                                    : ""));
        }
-       zlog_debug("%s: dump complete", func);
+       zlog_debug("%s: dump complete", straddr);
 }
 
 /* This is an exported helper to rtm_read() to dump the strange
index 5f397eb8c29f29a3fd5e28b465cce6a5e868987b..6f65f8ab7a1d917b3b24a4fd2d72c5631d5fb8ad 100644 (file)
@@ -759,7 +759,7 @@ static void zebra_rnh_eval_nexthop_entry(struct zebra_vrf *zvrf, afi_t afi,
         * change.
         */
        zebra_rnh_remove_from_routing_table(rnh);
-       if (!prefix_same(&rnh->resolved_route, prn ? NULL : &prn->p)) {
+       if (!prefix_same(&rnh->resolved_route, prn ? &prn->p : NULL)) {
                if (prn)
                        prefix_copy(&rnh->resolved_route, &prn->p);
                else {
@@ -965,7 +965,6 @@ static void copy_state(struct rnh *rnh, struct route_entry *re,
 
 static int compare_state(struct route_entry *r1, struct route_entry *r2)
 {
-
        if (!r1 && !r2)
                return 0;
 
@@ -981,8 +980,7 @@ static int compare_state(struct route_entry *r1, struct route_entry *r2)
        if (r1->nexthop_num != r2->nexthop_num)
                return 1;
 
-       if (CHECK_FLAG(r1->status, ROUTE_ENTRY_NEXTHOPS_CHANGED)
-           || CHECK_FLAG(r1->status, ROUTE_ENTRY_LABELS_CHANGED))
+       if (nexthop_group_hash(&r1->ng) != nexthop_group_hash(&r2->ng))
                return 1;
 
        return 0;
index 1b87669505b44863dbc74ef55c71a05d27181a90..972fe381cc1fbb89aa105d23cfa1559ec8cdbbba 100644 (file)
@@ -193,15 +193,6 @@ static inline vrf_id_t zvrf_id(struct zebra_vrf *zvrf)
        return zvrf->vrf->vrf_id;
 }
 
-static inline struct zebra_vrf *zvrf_info_lookup(struct vrf *vrf)
-{
-       struct zebra_vrf *zvrf = NULL;
-
-       if (vrf)
-               zvrf = (struct zebra_vrf *)vrf->info;
-       return zvrf;
-}
-
 static inline const char *zvrf_ns_name(struct zebra_vrf *zvrf)
 {
        if (!zvrf->vrf || !zvrf->vrf->ns_ctxt)
index a38d060bd1de3ff0681edccea8c995747608536b..1f8eec9cad1491c2cc901239eda85cadf6bb6c1c 100644 (file)
@@ -970,9 +970,10 @@ DEFPY (show_route_table_vrf,
        afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
        struct zebra_vrf *zvrf;
        struct route_table *t;
-       vrf_id_t vrf_id;
+       vrf_id_t vrf_id = VRF_DEFAULT;
 
-       VRF_GET_ID(vrf_id, vrf_name, !!json);
+       if (vrf_name)
+               VRF_GET_ID(vrf_id, vrf_name, !!json);
        zvrf = zebra_vrf_lookup_by_id(vrf_id);
 
        t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST);
index c058fdce6c0cd3387d782ac74558f3b24b5ba198..a3a630d53e53697956c9cd1e9e9a5995ce518cd3 100644 (file)
@@ -225,6 +225,9 @@ static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip,
                                struct in_addr mcast_grp);
 static void zebra_vxlan_sg_cleanup(struct hash_backet *backet, void *arg);
 
+static void zvni_send_mac_to_client(zebra_vni_t *zvn);
+static void zvni_send_neigh_to_client(zebra_vni_t *zvni);
+
 /* Private functions */
 static int host_rb_entry_compare(const struct host_rb_entry *hle1,
                                 const struct host_rb_entry *hle2)
@@ -872,10 +875,10 @@ static void zvni_print_neigh_hash(struct hash_bucket *bucket, void *ctxt)
                if (json_vni == NULL) {
                        if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP) &&
                            (wctx->count == 0))
-                               vty_out(vty,
-                                       "%*s %-6s %-8s %-17s %-21s\n",
+                               vty_out(vty, "%*s %-6s %-8s %-17s %-21s %s\n",
                                        -wctx->addr_width, "Neighbor", "Type",
-                                       "State", "MAC", "Remote VTEP");
+                                       "State", "MAC", "Remote VTEP",
+                                       "Seq #'s");
                        vty_out(vty, "%*s %-6s %-8s %-17s %-21s %u/%u\n",
                                -wctx->addr_width, buf2, "remote", state_str,
                                buf1, inet_ntoa(n->r_vtep_ip), n->loc_seq, n->rem_seq);
@@ -1388,9 +1391,10 @@ static void zvni_print_mac_hash(struct hash_bucket *bucket, void *ctxt)
                        else
                                json_object_int_add(json_mac, "vlan", vid);
                } else /* No vid? fill out the space */
-                       vty_out(vty, " %-5s", "");
-               vty_out(vty, " %u/%u", mac->loc_seq, mac->rem_seq);
+                       if (json_mac_hdr == NULL)
+                               vty_out(vty, " %-5s", "");
                if (json_mac_hdr == NULL) {
+                       vty_out(vty, " %u/%u", mac->loc_seq, mac->rem_seq);
                        vty_out(vty, "\n");
                } else {
                        json_object_int_add(json_mac, "localSequence",
@@ -2358,7 +2362,7 @@ static void zvni_process_neigh_on_local_mac_change(zebra_vni_t *zvni,
        struct zebra_vrf *zvrf = NULL;
        char buf[ETHER_ADDR_STRLEN];
 
-       zvrf = zvrf_info_lookup(zvni->vxlan_if->vrf);
+       zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id);
 
        if (IS_ZEBRA_DEBUG_VXLAN)
                zlog_debug("Processing neighbors on local MAC %s %s, VNI %u",
@@ -2617,7 +2621,7 @@ struct interface *zebra_get_vrr_intf_for_svi(struct interface *ifp)
        struct interface *tmp_if = NULL;
        struct zebra_if *zif = NULL;
 
-       zvrf = zvrf_info_lookup(ifp->vrf);
+       zvrf = vrf_info_lookup(ifp->vrf_id);
        assert(zvrf);
 
        FOR_ALL_INTERFACES (zvrf->vrf, tmp_if) {
@@ -2721,10 +2725,10 @@ static int zvni_advertise_subnet(zebra_vni_t *zvni, struct interface *ifp,
 
                apply_mask(&p);
                if (advertise)
-                       ip_prefix_send_to_client(vrf_to_id(ifp->vrf), &p,
+                       ip_prefix_send_to_client(ifp->vrf_id, &p,
                                                 ZEBRA_IP_PREFIX_ROUTE_ADD);
                else
-                       ip_prefix_send_to_client(vrf_to_id(ifp->vrf), &p,
+                       ip_prefix_send_to_client(ifp->vrf_id, &p,
                                                 ZEBRA_IP_PREFIX_ROUTE_DEL);
        }
        return 0;
@@ -2843,7 +2847,7 @@ static int zvni_gw_macip_del(struct interface *ifp, zebra_vni_t *zvni,
        if (IS_ZEBRA_DEBUG_VXLAN)
                zlog_debug(
                        "%u:SVI %s(%u) VNI %u, sending GW MAC %s IP %s del to BGP",
-                       vrf_to_id(ifp->vrf), ifp->name, ifp->ifindex, zvni->vni,
+                       ifp->vrf_id, ifp->name, ifp->ifindex, zvni->vni,
                        prefix_mac2str(&(n->emac), buf1, sizeof(buf1)),
                        ipaddr2str(ip, buf2, sizeof(buf2)));
 
@@ -2874,6 +2878,16 @@ static void zvni_gw_macip_del_for_vni_hash(struct hash_bucket *bucket,
        /* Add primary SVI MAC*/
        zvni = (zebra_vni_t *)bucket->data;
 
+       /* Global (Zvrf) advertise-default-gw is disabled,
+        * but zvni advertise-default-gw is enabled
+        */
+       if (zvni->advertise_gw_macip) {
+               if (IS_ZEBRA_DEBUG_VXLAN)
+                       zlog_debug("VNI: %u GW-MACIP enabled, retain gw-macip",
+                                  zvni->vni);
+               return;
+       }
+
        ifp = zvni->vxlan_if;
        if (!ifp)
                return;
@@ -2955,6 +2969,16 @@ static void zvni_svi_macip_del_for_vni_hash(struct hash_bucket *bucket,
        if (!zvni)
                return;
 
+       /* Global(vrf) advertise-svi-ip disabled, but zvni advertise-svi-ip
+        * enabled
+        */
+       if (zvni->advertise_svi_macip) {
+               if (IS_ZEBRA_DEBUG_VXLAN)
+                       zlog_debug("VNI: %u SVI-MACIP enabled, retain svi-macip",
+                                  zvni->vni);
+               return;
+       }
+
        ifp = zvni->vxlan_if;
        if (!ifp)
                return;
@@ -3030,11 +3054,11 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni,
                }
        }
 
-       zvrf = zvrf_info_lookup(zvni->vxlan_if->vrf);
+       zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id);
        if (!zvrf) {
                if (IS_ZEBRA_DEBUG_VXLAN)
-                       zlog_debug("\tUnable to find vrf for: %s",
-                                  zvni->vxlan_if->vrf->name);
+                       zlog_debug("\tUnable to find vrf for: %d",
+                                  zvni->vxlan_if->vrf_id);
                return -1;
        }
 
@@ -4061,47 +4085,67 @@ static void zvni_build_hash_table(void)
                                        ifp->name, ifp->ifindex, vni,
                                        inet_ntoa(vxl->vtep_ip));
 
-                       /* VNI hash entry is not expected to exist. */
+                       /* VNI hash entry is expected to exist, if the BGP process is killed */
                        zvni = zvni_lookup(vni);
                        if (zvni) {
                                zlog_debug(
                                        "VNI hash already present for IF %s(%u) L2-VNI %u",
                                        ifp->name, ifp->ifindex, vni);
-                               continue;
-                       }
 
-                       zvni = zvni_add(vni);
-                       if (!zvni) {
-                               zlog_debug(
-                                       "Failed to add VNI hash, IF %s(%u) L2-VNI %u",
-                                       ifp->name, ifp->ifindex, vni);
-                               return;
-                       }
+                               /*
+                                * Inform BGP if intf is up and mapped to
+                                * bridge.
+                                */
+                               if (if_is_operative(ifp) &&
+                                       zif->brslave_info.br_if)
+                                       zvni_send_add_to_client(zvni);
 
-                       if (zvni->local_vtep_ip.s_addr != vxl->vtep_ip.s_addr ||
-                               zvni->mcast_grp.s_addr != vxl->mcast_grp.s_addr) {
-                               zebra_vxlan_sg_deref(zvni->local_vtep_ip,
-                                       zvni->mcast_grp);
-                               zebra_vxlan_sg_ref(vxl->vtep_ip,
-                                       vxl->mcast_grp);
-                               zvni->local_vtep_ip = vxl->vtep_ip;
-                               zvni->mcast_grp = vxl->mcast_grp;
-                       }
-                       zvni->vxlan_if = ifp;
-                       vlan_if = zvni_map_to_svi(vxl->access_vlan,
-                                                 zif->brslave_info.br_if);
-                       if (vlan_if) {
-                               zvni->vrf_id = vrf_to_id(vlan_if->vrf);
-                               zl3vni = zl3vni_from_vrf(
-                                               vrf_to_id(vlan_if->vrf));
-                               if (zl3vni)
-                                       listnode_add_sort(zl3vni->l2vnis, zvni);
-                       }
+                               /* Send Local MAC-entries to client */
+                               zvni_send_mac_to_client(zvni);
 
+                               /* Send Loval Neighbor entries to client */
+                               zvni_send_neigh_to_client(zvni);
+                       } else {
+                               zvni = zvni_add(vni);
+                               if (!zvni) {
+                                       zlog_debug(
+                                               "Failed to add VNI hash, IF %s(%u) L2-VNI %u",
+                                               ifp->name, ifp->ifindex, vni);
+                                       return;
+                               }
+
+                               if (zvni->local_vtep_ip.s_addr !=
+                                       vxl->vtep_ip.s_addr ||
+                                       zvni->mcast_grp.s_addr !=
+                                       vxl->mcast_grp.s_addr) {
+                                       zebra_vxlan_sg_deref(
+                                               zvni->local_vtep_ip,
+                                               zvni->mcast_grp);
+                                       zebra_vxlan_sg_ref(vxl->vtep_ip,
+                                               vxl->mcast_grp);
+                                       zvni->local_vtep_ip = vxl->vtep_ip;
+                                       zvni->mcast_grp = vxl->mcast_grp;
+                               }
+                               zvni->vxlan_if = ifp;
+                               vlan_if = zvni_map_to_svi(vxl->access_vlan,
+                                               zif->brslave_info.br_if);
+                               if (vlan_if) {
+                                       zvni->vrf_id = vlan_if->vrf_id;
+                                       zl3vni = zl3vni_from_vrf(
+                                                       vlan_if->vrf_id);
+                                       if (zl3vni)
+                                               listnode_add_sort(
+                                                       zl3vni->l2vnis, zvni);
+                               }
 
-                       /* Inform BGP if intf is up and mapped to bridge. */
-                       if (if_is_operative(ifp) && zif->brslave_info.br_if)
-                               zvni_send_add_to_client(zvni);
+                               /*
+                                * Inform BGP if intf is up and mapped to
+                                * bridge.
+                                */
+                               if (if_is_operative(ifp) &&
+                                       zif->brslave_info.br_if)
+                                       zvni_send_add_to_client(zvni);
+                       }
                }
        }
 }
@@ -5258,7 +5302,7 @@ static void process_remote_macip_add(vni_t vni,
                return;
        }
 
-       zvrf = zvrf_info_lookup(zvni->vxlan_if->vrf);
+       zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id);
        if (!zvrf)
                return;
 
@@ -5586,7 +5630,7 @@ static void process_remote_macip_del(vni_t vni,
        if (!mac && !n)
                return;
 
-       zvrf = zvrf_info_lookup(zvni->vxlan_if->vrf);
+       zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id);
 
        /* Ignore the delete if this mac is a gateway mac-ip */
        if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)
@@ -6107,9 +6151,8 @@ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf,
                vty_out(vty,
                        "Number of ARPs (local and remote) known for this VNI: %u\n",
                        num_neigh);
-               vty_out(vty, "%*s %-6s %-8s %-17s %-21s\n",
-                       -wctx.addr_width, "IP", "Type",
-                       "State", "MAC", "Remote VTEP");
+               vty_out(vty, "%*s %-6s %-8s %-17s %-21s %s\n", -wctx.addr_width,
+                       "IP", "Type", "State", "MAC", "Remote VTEP", "Seq #'s");
        } else
                json_object_int_add(json, "numArpNd", num_neigh);
 
@@ -6371,8 +6414,8 @@ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf,
                vty_out(vty,
                        "Number of MACs (local and remote) known for this VNI: %u\n",
                        num_macs);
-               vty_out(vty, "%-17s %-6s %-21s %-5s\n", "MAC", "Type",
-                       "Intf/Remote VTEP", "VLAN");
+               vty_out(vty, "%-17s %-6s %-21s %-5s %s\n", "MAC", "Type",
+                       "Intf/Remote VTEP", "VLAN", "Seq #'s");
        } else
                json_object_int_add(json, "numMacs", num_macs);
 
@@ -7273,7 +7316,7 @@ int zebra_vxlan_handle_kernel_neigh_del(struct interface *ifp,
                return 0;
        }
 
-       zvrf = zvrf_info_lookup(zvni->vxlan_if->vrf);
+       zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id);
        if (!zvrf) {
                zlog_debug("%s: VNI %u vrf lookup failed.",
                                   __PRETTY_FUNCTION__, zvni->vni);
@@ -7696,11 +7739,11 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp,
                return -1;
        }
 
-       zvrf = zvrf_info_lookup(zvni->vxlan_if->vrf);
+       zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id);
        if (!zvrf) {
                if (IS_ZEBRA_DEBUG_VXLAN)
-                       zlog_debug("\tNo Vrf found for vrf_id: %s",
-                                  zvni->vxlan_if->vrf->name);
+                       zlog_debug("\tNo Vrf found for vrf_id: %d",
+                                  zvni->vxlan_if->vrf_id);
                return -1;
        }
 
@@ -8232,10 +8275,10 @@ int zebra_vxlan_svi_up(struct interface *ifp, struct interface *link_if)
                        zlog_debug(
                                "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors",
                                ifp->name, ifp->ifindex, zvni->vni,
-                               vrf_to_name(ifp->vrf));
+                               vrf_id_to_name(ifp->vrf_id));
 
                /* update the vrf information for l2-vni and inform bgp */
-               zvni->vrf_id = vrf_to_id(ifp->vrf);
+               zvni->vrf_id = ifp->vrf_id;
                zvni_send_add_to_client(zvni);
 
                /* Install any remote neighbors for this VNI. */
@@ -8361,8 +8404,8 @@ int zebra_vxlan_if_up(struct interface *ifp)
                vlan_if = zvni_map_to_svi(vxl->access_vlan,
                                          zif->brslave_info.br_if);
                if (vlan_if) {
-                       zvni->vrf_id = vrf_to_id(vlan_if->vrf);
-                       zl3vni = zl3vni_from_vrf(vrf_to_id(vlan_if->vrf));
+                       zvni->vrf_id = vlan_if->vrf_id;
+                       zl3vni = zl3vni_from_vrf(vlan_if->vrf_id);
                        if (zl3vni)
                                listnode_add_sort(zl3vni->l2vnis, zvni);
                }
@@ -8690,8 +8733,8 @@ int zebra_vxlan_if_add(struct interface *ifp)
                vlan_if = zvni_map_to_svi(vxl->access_vlan,
                                          zif->brslave_info.br_if);
                if (vlan_if) {
-                       zvni->vrf_id = vrf_to_id(vlan_if->vrf);
-                       zl3vni = zl3vni_from_vrf(vrf_to_id(vlan_if->vrf));
+                       zvni->vrf_id = vlan_if->vrf_id;
+                       zl3vni = zl3vni_from_vrf(vlan_if->vrf_id);
                        if (zl3vni)
                                listnode_add_sort(zl3vni->l2vnis, zvni);
                }
@@ -8708,7 +8751,7 @@ int zebra_vxlan_if_add(struct interface *ifp)
                        zlog_debug(
                                "Add L2-VNI %u VRF %s intf %s(%u) VLAN %u local IP %s mcast_grp %s master %u",
                                vni,
-                               vlan_if ? vrf_to_name(vlan_if->vrf)
+                               vlan_if ? vrf_id_to_name(vlan_if->vrf_id)
                                        : VRF_DEFAULT_NAME,
                                ifp->name, ifp->ifindex, vxl->access_vlan,
                                addr_buf1, addr_buf2,
@@ -8934,7 +8977,7 @@ void zebra_vxlan_advertise_svi_macip(ZAPI_HANDLER_ARGS)
        struct interface *ifp = NULL;
 
        if (!EVPN_ENABLED(zvrf)) {
-               zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u",
+               zlog_debug("EVPN SVI-MACIP Adv for non-EVPN VRF %u",
                          zvrf_id(zvrf));
                return;
        }
@@ -8945,7 +8988,7 @@ void zebra_vxlan_advertise_svi_macip(ZAPI_HANDLER_ARGS)
 
        if (!vni) {
                if (IS_ZEBRA_DEBUG_VXLAN)
-                       zlog_debug("EVPN gateway macip Adv %s, currently %s",
+                       zlog_debug("EVPN SVI-MACIP Adv %s, currently %s",
                                   advertise ? "enabled" : "disabled",
                                   advertise_gw_macip_enabled(NULL)
                                           ? "enabled"
@@ -9655,3 +9698,120 @@ static void zebra_vxlan_sg_cleanup(struct hash_backet *backet, void *arg)
 
        zebra_vxlan_sg_del(vxlan_sg);
 }
+
+/************************** EVPN BGP config management ************************/
+/* Notify Local MACs to the clienti, skips GW MAC */
+static void zvni_send_mac_hash_entry_to_client(struct hash_bucket *bucket,
+                                              void *arg)
+{
+       struct mac_walk_ctx *wctx = arg;
+       zebra_mac_t *zmac = bucket->data;
+
+       if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_DEF_GW))
+               return;
+
+       if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL))
+               zvni_mac_send_add_to_client(wctx->zvni->vni, &zmac->macaddr,
+                                               zmac->flags, zmac->loc_seq);
+}
+
+/* Iterator to Notify Local MACs of a L2VNI */
+static void zvni_send_mac_to_client(zebra_vni_t *zvni)
+{
+       struct mac_walk_ctx wctx;
+
+       if (!zvni->mac_table)
+               return;
+
+       memset(&wctx, 0, sizeof(struct mac_walk_ctx));
+       wctx.zvni = zvni;
+
+       hash_iterate(zvni->mac_table, zvni_send_mac_hash_entry_to_client,
+                       &wctx);
+}
+
+/* Notify Neighbor entries to the Client, skips the GW entry */
+static void zvni_send_neigh_hash_entry_to_client(struct hash_bucket *bucket,
+                                                void *arg)
+{
+       struct mac_walk_ctx *wctx = arg;
+       zebra_neigh_t *zn = bucket->data;
+       zebra_mac_t *zmac = NULL;
+
+       if (CHECK_FLAG(zn->flags, ZEBRA_NEIGH_DEF_GW))
+               return;
+
+       if (CHECK_FLAG(zn->flags, ZEBRA_NEIGH_LOCAL) &&
+               IS_ZEBRA_NEIGH_ACTIVE(zn)) {
+               zmac = zvni_mac_lookup(wctx->zvni, &zn->emac);
+               if (!zmac)
+                       return;
+
+               zvni_neigh_send_add_to_client(wctx->zvni->vni, &zn->ip,
+                                               &zn->emac, zn->flags,
+                                               zn->loc_seq);
+       }
+}
+
+/* Iterator of a specific L2VNI */
+static void zvni_send_neigh_to_client(zebra_vni_t *zvni)
+{
+       struct neigh_walk_ctx wctx;
+
+       memset(&wctx, 0, sizeof(struct neigh_walk_ctx));
+       wctx.zvni = zvni;
+
+       hash_iterate(zvni->neigh_table, zvni_send_neigh_hash_entry_to_client,
+                       &wctx);
+}
+
+static void zvni_evpn_cfg_cleanup(struct hash_bucket *bucket, void *ctxt)
+{
+       zebra_vni_t *zvni = NULL;
+
+       zvni = (zebra_vni_t *)bucket->data;
+       zvni->advertise_gw_macip = 0;
+       zvni->advertise_svi_macip = 0;
+       zvni->advertise_subnet = 0;
+
+       zvni_neigh_del_all(zvni, 0, 0,
+                          DEL_REMOTE_NEIGH | DEL_REMOTE_NEIGH_FROM_VTEP);
+       zvni_mac_del_all(zvni, 0, 0,
+                        DEL_REMOTE_MAC | DEL_REMOTE_MAC_FROM_VTEP);
+       zvni_vtep_del_all(zvni, 0);
+}
+
+/* Cleanup EVPN configuration of a specific VRF */
+static void zebra_evpn_vrf_cfg_cleanup(struct zebra_vrf *zvrf)
+{
+       zvrf->advertise_all_vni = 0;
+       zvrf->advertise_gw_macip = 0;
+       zvrf->advertise_svi_macip = 0;
+       zvrf->vxlan_flood_ctrl = VXLAN_FLOOD_HEAD_END_REPL;
+
+       hash_iterate(zvrf->vni_table, zvni_evpn_cfg_cleanup, NULL);
+}
+
+/* Cleanup BGP EVPN configuration upon client disconnect */
+static int zebra_evpn_cfg_clean_up(struct zserv *client)
+{
+       struct vrf *vrf;
+       struct zebra_vrf *zvrf;
+
+       if (client->proto != ZEBRA_ROUTE_BGP)
+               return 0;
+
+       RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
+               zvrf = vrf->info;
+               if (zvrf)
+                       zebra_evpn_vrf_cfg_cleanup(zvrf);
+       }
+
+       return 0;
+}
+
+/* Cleanup BGP EVPN configuration upon client disconnect */
+extern void zebra_evpn_init(void)
+{
+       hook_register(zserv_client_close, zebra_evpn_cfg_clean_up);
+}
index f752bdd690d27995d23f375e787899a357180596..6117567bc165e7ad4c9a820ac62aac9e6d9f0a60 100644 (file)
@@ -212,6 +212,7 @@ extern int zebra_vxlan_clear_dup_detect_vni_all(struct vty *vty,
 extern int zebra_vxlan_clear_dup_detect_vni(struct vty *vty,
                                            struct zebra_vrf *zvrf,
                                            vni_t vni);
+extern void zebra_evpn_init(void);
 
 #ifdef __cplusplus
 }