diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-05-18 18:51:31 -0400 |
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-07-24 13:51:35 -0400 |
| commit | c2cf4b0230faec3e0c478cb7ab14030a6ffe0593 (patch) | |
| tree | ecd191d414d3ad8101f3537af7d88d835c417f02 /pimd/pimd.c | |
| parent | 72ec4672899d4042c9f7dc2203b2e1771c90ac89 (diff) | |
pimd: Refactor code to be in better spots
1) Create pim_instance.[ch] to allow us to handle the instance information there
2) Refactor some pim_rpf_ and some pim_rp commands into appropriate files and
appropriate includes.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'pimd/pimd.c')
| -rw-r--r-- | pimd/pimd.c | 156 |
1 files changed, 1 insertions, 155 deletions
diff --git a/pimd/pimd.c b/pimd/pimd.c index b687a943a8..164dafe5f7 100644 --- a/pimd/pimd.c +++ b/pimd/pimd.c @@ -31,19 +31,15 @@ #include "pimd.h" #include "pim_cmd.h" -#include "pim_iface.h" -#include "pim_zebra.h" #include "pim_str.h" #include "pim_oil.h" #include "pim_pim.h" -#include "pim_upstream.h" -#include "pim_rpf.h" #include "pim_ssmpingd.h" #include "pim_static.h" #include "pim_rp.h" #include "pim_ssm.h" #include "pim_zlookup.h" -#include "pim_nht.h" +#include "pim_zebra.h" const char *const PIM_ALL_SYSTEMS = MCAST_ALL_SYSTEMS; const char *const PIM_ALL_ROUTERS = MCAST_ALL_ROUTERS; @@ -76,93 +72,6 @@ struct pim_instance *pimg = NULL; int32_t qpim_register_suppress_time = PIM_REGISTER_SUPPRESSION_TIME_DEFAULT; int32_t qpim_register_probe_time = PIM_REGISTER_PROBE_TIME_DEFAULT; -static struct pim_instance *pim_instance_init(struct vrf *vrf); -static void pim_instance_terminate(struct pim_instance *pim); - -static int pim_vrf_new(struct vrf *vrf) -{ - zlog_debug("VRF Created: %s(%d)", vrf->name, vrf->vrf_id); - return 0; -} - -static int pim_vrf_delete(struct vrf *vrf) -{ - zlog_debug("VRF Deletion: %s(%d)", vrf->name, vrf->vrf_id); - return 0; -} - -static int pim_vrf_enable(struct vrf *vrf) -{ - struct pim_instance *pim; - - zlog_debug("%s: for %s", __PRETTY_FUNCTION__, vrf->name); - pim = pim_instance_init(vrf); - if (pim == NULL) { - zlog_err("%s %s: pim class init failure ", __FILE__, - __PRETTY_FUNCTION__); - /* - * We will crash and burn otherwise - */ - exit(1); - } - - vrf->info = (void *)pim; - - if (vrf->vrf_id == VRF_DEFAULT) - pimg = pim; - - return 0; -} - -static int pim_vrf_disable(struct vrf *vrf) -{ - pim_instance_terminate((struct pim_instance *)vrf->info); - - /* Note: This is a callback, the VRF will be deleted by the caller. */ - return 0; -} - -void pim_vrf_init(void) -{ - vrf_init(pim_vrf_new, pim_vrf_enable, pim_vrf_disable, pim_vrf_delete); -} - -static void pim_vrf_terminate(void) -{ - vrf_terminate(); -} - -/* Key generate for pim->rpf_hash */ -static unsigned int pim_rpf_hash_key(void *arg) -{ - struct pim_nexthop_cache *r = (struct pim_nexthop_cache *)arg; - - return jhash_1word(r->rpf.rpf_addr.u.prefix4.s_addr, 0); -} - -/* Compare pim->rpf_hash node data */ -static int pim_rpf_equal(const void *arg1, const void *arg2) -{ - const struct pim_nexthop_cache *r1 = - (const struct pim_nexthop_cache *)arg1; - const struct pim_nexthop_cache *r2 = - (const struct pim_nexthop_cache *)arg2; - - return prefix_same(&r1->rpf.rpf_addr, &r2->rpf.rpf_addr); -} - -/* Cleanup pim->rpf_hash each node data */ -static void pim_rp_list_hash_clean(void *data) -{ - struct pim_nexthop_cache *pnc; - - pnc = (struct pim_nexthop_cache *)data; - if (pnc->rp_list->count) - list_delete_all_node(pnc->rp_list); - if (pnc->upstream_list->count) - list_delete_all_node(pnc->upstream_list); -} - void pim_prefix_list_update(struct prefix_list *plist) { pim_rp_prefix_list_update(plist); @@ -170,33 +79,6 @@ void pim_prefix_list_update(struct prefix_list *plist) pim_upstream_spt_prefix_list_update(plist); } -struct pim_instance *pim_get_pim_instance(vrf_id_t vrf_id) -{ - struct vrf *vrf = vrf_lookup_by_id(vrf_id); - - if (vrf) - return vrf->info; - - return NULL; -} - -static void pim_instance_terminate(struct pim_instance *pim) -{ - /* Traverse and cleanup rpf_hash */ - if (pim->rpf_hash) { - hash_clean(pim->rpf_hash, (void *)pim_rp_list_hash_clean); - hash_free(pim->rpf_hash); - pim->rpf_hash = NULL; - } - - if (pim->ssm_info) { - pim_ssm_terminate(pim->ssm_info); - pim->ssm_info = NULL; - } - - XFREE(MTYPE_PIM_PIM_INSTANCE, pimg); -} - static void pim_free() { pim_ssmpingd_destroy(); @@ -218,42 +100,6 @@ static void pim_free() zprivs_terminate(&pimd_privs); } -static struct pim_instance *pim_instance_init(struct vrf *vrf) -{ - struct pim_instance *pim; - - pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance)); - if (!pim) - return NULL; - - pim->vrf_id = vrf->vrf_id; - pim->vrf = vrf; - - pim->spt.switchover = PIM_SPT_IMMEDIATE; - pim->spt.plist = NULL; - - pim->rpf_hash = - hash_create_size(256, pim_rpf_hash_key, pim_rpf_equal, NULL); - - if (PIM_DEBUG_ZEBRA) - zlog_debug("%s: NHT rpf hash init ", __PRETTY_FUNCTION__); - - pim->ssm_info = pim_ssm_init(); - if (!pim->ssm_info) { - pim_instance_terminate(pim); - return NULL; - } - - pim->send_v6_secondary = 1; - - if (vrf->vrf_id == VRF_DEFAULT) - pimg = pim; - - pim_mroute_socket_enable(pim); - - return pim; -} - void pim_init() { qpim_rp_keep_alive_time = PIM_RP_KEEPALIVE_PERIOD; |
