diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-05-22 15:12:08 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-07-24 19:51:37 +0200 |
commit | 2ad78035cc824f747e64274020140dcd0b95e3fd (patch) | |
tree | fec2b9db86a4148e97cfd72d296febe633b073c7 | |
parent | pimd: Get the default pim code ready to write into vrf's or not (diff) | |
download | frr-2ad78035cc824f747e64274020140dcd0b95e3fd.tar.xz frr-2ad78035cc824f747e64274020140dcd0b95e3fd.zip |
pimd: Make pim MSDP pim instance aware to some extent
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
-rw-r--r-- | pimd/pim_cmd.c | 14 | ||||
-rw-r--r-- | pimd/pim_instance.c | 4 | ||||
-rw-r--r-- | pimd/pim_instance.h | 5 | ||||
-rw-r--r-- | pimd/pim_main.c | 1 | ||||
-rw-r--r-- | pimd/pim_msdp.c | 139 | ||||
-rw-r--r-- | pimd/pim_msdp.h | 15 | ||||
-rw-r--r-- | pimd/pim_msdp_packet.c | 29 | ||||
-rw-r--r-- | pimd/pim_msdp_socket.c | 10 |
8 files changed, 115 insertions, 102 deletions
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 06186a241..c25907c81 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -6803,7 +6803,7 @@ static void ip_msdp_show_mesh_group(struct vty *vty, u_char uj) { struct listnode *mbrnode; struct pim_msdp_mg_mbr *mbr; - struct pim_msdp_mg *mg = msdp->mg; + struct pim_msdp_mg *mg = pimg->msdp.mg; char mbr_str[INET_ADDRSTRLEN]; char src_str[INET_ADDRSTRLEN]; char state_str[PIM_MSDP_STATE_STRLEN]; @@ -6901,7 +6901,7 @@ static void ip_msdp_show_peers(struct vty *vty, u_char uj) "Peer Local State Uptime SaCnt\n"); } - for (ALL_LIST_ELEMENTS_RO(msdp->peer_list, mpnode, mp)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.peer_list, mpnode, mp)) { if (mp->state == PIM_MSDP_ESTABLISHED) { now = pim_time_monotonic_sec(); pim_time_uptime(timebuf, sizeof(timebuf), @@ -6954,7 +6954,7 @@ static void ip_msdp_show_peers_detail(struct vty *vty, const char *peer, json = json_object_new_object(); } - for (ALL_LIST_ELEMENTS_RO(msdp->peer_list, mpnode, mp)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.peer_list, mpnode, mp)) { pim_inet4_dump("<peer?>", mp->peer, peer_str, sizeof(peer_str)); if (strcmp(peer, "detail") && strcmp(peer, peer_str)) continue; @@ -7084,7 +7084,7 @@ static void ip_msdp_show_sa(struct vty *vty, u_char uj) "Source Group RP Local SPT Uptime\n"); } - for (ALL_LIST_ELEMENTS_RO(msdp->sa_list, sanode, sa)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.sa_list, sanode, sa)) { now = pim_time_monotonic_sec(); pim_time_uptime(timebuf, sizeof(timebuf), now - sa->uptime); pim_inet4_dump("<src?>", sa->sg.src, src_str, sizeof(src_str)); @@ -7215,7 +7215,7 @@ static void ip_msdp_show_sa_detail(struct vty *vty, u_char uj) json = json_object_new_object(); } - for (ALL_LIST_ELEMENTS_RO(msdp->sa_list, sanode, sa)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.sa_list, sanode, sa)) { pim_inet4_dump("<src?>", sa->sg.src, src_str, sizeof(src_str)); pim_inet4_dump("<grp?>", sa->sg.grp, grp_str, sizeof(grp_str)); ip_msdp_show_sa_entry_detail(sa, src_str, grp_str, vty, uj, @@ -7257,7 +7257,7 @@ static void ip_msdp_show_sa_addr(struct vty *vty, const char *addr, u_char uj) json = json_object_new_object(); } - for (ALL_LIST_ELEMENTS_RO(msdp->sa_list, sanode, sa)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.sa_list, sanode, sa)) { pim_inet4_dump("<src?>", sa->sg.src, src_str, sizeof(src_str)); pim_inet4_dump("<grp?>", sa->sg.grp, grp_str, sizeof(grp_str)); if (!strcmp(addr, src_str) || !strcmp(addr, grp_str)) { @@ -7286,7 +7286,7 @@ static void ip_msdp_show_sa_sg(struct vty *vty, const char *src, json = json_object_new_object(); } - for (ALL_LIST_ELEMENTS_RO(msdp->sa_list, sanode, sa)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.sa_list, sanode, sa)) { pim_inet4_dump("<src?>", sa->sg.src, src_str, sizeof(src_str)); pim_inet4_dump("<grp?>", sa->sg.grp, grp_str, sizeof(grp_str)); if (!strcmp(src, src_str) && !strcmp(grp, grp_str)) { diff --git a/pimd/pim_instance.c b/pimd/pim_instance.c index 3d13ee7a5..6b10f14d9 100644 --- a/pimd/pim_instance.c +++ b/pimd/pim_instance.c @@ -56,6 +56,8 @@ static void pim_instance_terminate(struct pim_instance *pim) pim_if_terminate(pim); + pim_msdp_exit(pim); + XFREE(MTYPE_PIM_PIM_INSTANCE, pimg); } @@ -75,6 +77,8 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf) pim->spt.switchover = PIM_SPT_IMMEDIATE; pim->spt.plist = NULL; + pim_msdp_init(master, pim); + pim->rpf_hash = hash_create_size(256, pim_rpf_hash_key, pim_rpf_equal, NULL); diff --git a/pimd/pim_instance.h b/pimd/pim_instance.h index e931e7a9f..b33ae537c 100644 --- a/pimd/pim_instance.h +++ b/pimd/pim_instance.h @@ -21,6 +21,9 @@ #ifndef __PIM_INSTANCE_H__ #define __PIM_INSTANCE_H__ +#include "pim_str.h" +#include "pim_msdp.h" + #if defined(HAVE_LINUX_MROUTE_H) #include <linux/mroute.h> #else @@ -80,6 +83,8 @@ struct pim_instance { struct list *channel_oil_list; struct hash *channel_oil_hash; + + struct pim_msdp msdp; }; void pim_vrf_init(void); diff --git a/pimd/pim_main.c b/pimd/pim_main.c index a62406546..c4cab25ae 100644 --- a/pimd/pim_main.c +++ b/pimd/pim_main.c @@ -116,7 +116,6 @@ int main(int argc, char **argv, char **envp) pim_route_map_init(); pim_init(); - pim_msdp_init(master); /* * Initialize zclient "update" and "lookup" sockets diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c index 8e118ae3a..07b8e04ab 100644 --- a/pimd/pim_msdp.c +++ b/pimd/pim_msdp.c @@ -42,7 +42,7 @@ #include "pim_msdp_packet.h" #include "pim_msdp_socket.h" -struct pim_msdp pim_msdp, *msdp = &pim_msdp; +// struct pim_msdp pim_msdp, *msdp = &pim_msdp; static void pim_msdp_peer_listen(struct pim_msdp_peer *mp); static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer *mp, bool start); @@ -79,11 +79,11 @@ static int pim_msdp_sa_adv_timer_cb(struct thread *t) } static void pim_msdp_sa_adv_timer_setup(bool start) { - THREAD_OFF(msdp->sa_adv_timer); + THREAD_OFF(pimg->msdp.sa_adv_timer); if (start) { - thread_add_timer(msdp->master, pim_msdp_sa_adv_timer_cb, NULL, - PIM_MSDP_SA_ADVERTISMENT_TIME, - &msdp->sa_adv_timer); + thread_add_timer(pimg->msdp.master, pim_msdp_sa_adv_timer_cb, + NULL, PIM_MSDP_SA_ADVERTISMENT_TIME, + &pimg->msdp.sa_adv_timer); } } @@ -105,8 +105,9 @@ static void pim_msdp_sa_state_timer_setup(struct pim_msdp_sa *sa, bool start) { THREAD_OFF(sa->sa_state_timer); if (start) { - thread_add_timer(msdp->master, pim_msdp_sa_state_timer_cb, sa, - PIM_MSDP_SA_HOLD_TIME, &sa->sa_state_timer); + thread_add_timer(pimg->msdp.master, pim_msdp_sa_state_timer_cb, + sa, PIM_MSDP_SA_HOLD_TIME, + &sa->sa_state_timer); } } @@ -245,13 +246,13 @@ static struct pim_msdp_sa *pim_msdp_sa_new(struct prefix_sg *sg, sa->uptime = pim_time_monotonic_sec(); /* insert into misc tables for easy access */ - sa = hash_get(msdp->sa_hash, sa, hash_alloc_intern); + sa = hash_get(pimg->msdp.sa_hash, sa, hash_alloc_intern); if (!sa) { zlog_err("%s: PIM hash get failure", __PRETTY_FUNCTION__); pim_msdp_sa_free(sa); return NULL; } - listnode_add_sort(msdp->sa_list, sa); + listnode_add_sort(pimg->msdp.sa_list, sa); if (PIM_DEBUG_MSDP_EVENTS) { zlog_debug("MSDP SA %s created", sa->sg_str); @@ -265,7 +266,7 @@ static struct pim_msdp_sa *pim_msdp_sa_find(struct prefix_sg *sg) struct pim_msdp_sa lookup; lookup.sg = *sg; - return hash_lookup(msdp->sa_hash, &lookup); + return hash_lookup(pimg->msdp.sa_hash, &lookup); } static struct pim_msdp_sa *pim_msdp_sa_add(struct prefix_sg *sg, @@ -291,8 +292,8 @@ static void pim_msdp_sa_del(struct pim_msdp_sa *sa) pim_msdp_sa_state_timer_setup(sa, false /* start */); /* remove the entry from various tables */ - listnode_delete(msdp->sa_list, sa); - hash_release(msdp->sa_hash, sa); + listnode_delete(pimg->msdp.sa_list, sa); + hash_release(pimg->msdp.sa_hash, sa); if (PIM_DEBUG_MSDP_EVENTS) { zlog_debug("MSDP SA %s deleted", sa->sg_str); @@ -349,8 +350,8 @@ static void pim_msdp_sa_deref(struct pim_msdp_sa *sa, zlog_debug("MSDP SA %s local reference removed", sa->sg_str); } - if (msdp->local_cnt) - --msdp->local_cnt; + if (pimg->msdp.local_cnt) + --pimg->msdp.local_cnt; } } @@ -412,7 +413,7 @@ void pim_msdp_sa_ref(struct pim_msdp_peer *mp, struct prefix_sg *sg, } else { if (!(sa->flags & PIM_MSDP_SAF_LOCAL)) { sa->flags |= PIM_MSDP_SAF_LOCAL; - ++msdp->local_cnt; + ++pimg->msdp.local_cnt; if (PIM_DEBUG_MSDP_EVENTS) { zlog_debug("MSDP SA %s added locally", sa->sg_str); @@ -438,7 +439,7 @@ void pim_msdp_sa_ref(struct pim_msdp_peer *mp, struct prefix_sg *sg, */ static bool pim_msdp_sa_local_add_ok(struct pim_upstream *up) { - if (!(msdp->flags & PIM_MSDPF_ENABLE)) { + if (!(pimg->msdp.flags & PIM_MSDPF_ENABLE)) { return false; } @@ -568,7 +569,7 @@ void pim_msdp_i_am_rp_changed(void) struct listnode *nextnode; struct pim_msdp_sa *sa; - if (!(msdp->flags & PIM_MSDPF_ENABLE)) { + if (!(pimg->msdp.flags & PIM_MSDPF_ENABLE)) { /* if the feature is not enabled do nothing */ return; } @@ -578,7 +579,7 @@ void pim_msdp_i_am_rp_changed(void) } /* mark all local entries as stale */ - for (ALL_LIST_ELEMENTS_RO(msdp->sa_list, sanode, sa)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.sa_list, sanode, sa)) { if (sa->flags & PIM_MSDP_SAF_LOCAL) { sa->flags |= PIM_MSDP_SAF_STALE; } @@ -587,7 +588,7 @@ void pim_msdp_i_am_rp_changed(void) /* re-setup local SA entries */ pim_msdp_sa_local_setup(); - for (ALL_LIST_ELEMENTS(msdp->sa_list, sanode, nextnode, sa)) { + for (ALL_LIST_ELEMENTS(pimg->msdp.sa_list, sanode, nextnode, sa)) { /* purge stale SA entries */ if (sa->flags & PIM_MSDP_SAF_STALE) { /* clear the stale flag; the entry may be kept even @@ -626,7 +627,7 @@ void pim_msdp_up_join_state_changed(struct pim_upstream *xg_up) /* XXX: Need to maintain SAs per-group to avoid all this unnecessary * walking */ - for (ALL_LIST_ELEMENTS_RO(msdp->sa_list, sanode, sa)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.sa_list, sanode, sa)) { if (sa->sg.grp.s_addr != xg_up->sg.grp.s_addr) { continue; } @@ -650,7 +651,7 @@ static void pim_msdp_up_xg_del(struct prefix_sg *sg) /* XXX: Need to maintain SAs per-group to avoid all this unnecessary * walking */ - for (ALL_LIST_ELEMENTS_RO(msdp->sa_list, sanode, sa)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.sa_list, sanode, sa)) { if (sa->sg.grp.s_addr != sg->grp.s_addr) { continue; } @@ -917,8 +918,8 @@ static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer *mp, bool start) { THREAD_OFF(mp->hold_timer); if (start) { - thread_add_timer(msdp->master, pim_msdp_peer_hold_timer_cb, mp, - PIM_MSDP_PEER_HOLD_TIME, &mp->hold_timer); + thread_add_timer(pimg->msdp.master, pim_msdp_peer_hold_timer_cb, + mp, PIM_MSDP_PEER_HOLD_TIME, &mp->hold_timer); } } @@ -942,8 +943,8 @@ static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer *mp, bool start) { THREAD_OFF(mp->ka_timer); if (start) { - thread_add_timer(msdp->master, pim_msdp_peer_ka_timer_cb, mp, - PIM_MSDP_PEER_KA_TIME, &mp->ka_timer); + thread_add_timer(pimg->msdp.master, pim_msdp_peer_ka_timer_cb, + mp, PIM_MSDP_PEER_KA_TIME, &mp->ka_timer); } } @@ -1005,8 +1006,8 @@ static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer *mp, bool start) { THREAD_OFF(mp->cr_timer); if (start) { - thread_add_timer(msdp->master, pim_msdp_peer_cr_timer_cb, mp, - PIM_MSDP_PEER_CONNECT_RETRY_TIME, + thread_add_timer(pimg->msdp.master, pim_msdp_peer_cr_timer_cb, + mp, PIM_MSDP_PEER_CONNECT_RETRY_TIME, &mp->cr_timer); } } @@ -1064,7 +1065,7 @@ static enum pim_msdp_err pim_msdp_peer_new(struct in_addr peer_addr, pim_msdp_addr2su(&mp->su_peer, mp->peer); mp->local = local_addr; /* XXX: originator_id setting needs to move to the mesh group */ - msdp->originator_id = local_addr; + pimg->msdp.originator_id = local_addr; pim_msdp_addr2su(&mp->su_local, mp->local); mp->mesh_group_name = XSTRDUP(MTYPE_PIM_MSDP_MG_NAME, mesh_group_name); mp->state = PIM_MSDP_INACTIVE; @@ -1080,8 +1081,8 @@ static enum pim_msdp_err pim_msdp_peer_new(struct in_addr peer_addr, mp->obuf = stream_fifo_new(); /* insert into misc tables for easy access */ - mp = hash_get(msdp->peer_hash, mp, hash_alloc_intern); - listnode_add_sort(msdp->peer_list, mp); + mp = hash_get(pimg->msdp.peer_hash, mp, hash_alloc_intern); + listnode_add_sort(pimg->msdp.peer_list, mp); if (PIM_DEBUG_MSDP_EVENTS) { zlog_debug("MSDP peer %s created", mp->key_str); @@ -1106,7 +1107,7 @@ struct pim_msdp_peer *pim_msdp_peer_find(struct in_addr peer_addr) struct pim_msdp_peer lookup; lookup.peer = peer_addr; - return hash_lookup(msdp->peer_hash, &lookup); + return hash_lookup(pimg->msdp.peer_hash, &lookup); } /* add peer configuration if it doesn't already exist */ @@ -1168,8 +1169,8 @@ static enum pim_msdp_err pim_msdp_peer_do_del(struct pim_msdp_peer *mp) pim_msdp_peer_stop_tcp_conn(mp, true /* chg_state */); /* remove the session from various tables */ - listnode_delete(msdp->peer_list, mp); - hash_release(msdp->peer_hash, mp); + listnode_delete(pimg->msdp.peer_list, mp); + hash_release(pimg->msdp.peer_hash, mp); if (PIM_DEBUG_MSDP_EVENTS) { zlog_debug("MSDP peer %s deleted", mp->key_str); @@ -1240,7 +1241,7 @@ static void pim_msdp_mg_free(struct pim_msdp_mg *mg) list_free(mg->mbr_list); XFREE(MTYPE_PIM_MSDP_MG, mg); - msdp->mg = NULL; + pimg->msdp.mg = NULL; } static struct pim_msdp_mg *pim_msdp_mg_new(const char *mesh_group_name) @@ -1267,7 +1268,7 @@ static struct pim_msdp_mg *pim_msdp_mg_new(const char *mesh_group_name) enum pim_msdp_err pim_msdp_mg_del(const char *mesh_group_name) { - struct pim_msdp_mg *mg = msdp->mg; + struct pim_msdp_mg *mg = pimg->msdp.mg; struct pim_msdp_mg_mbr *mbr; if (!mg || strcmp(mg->mesh_group_name, mesh_group_name)) { @@ -1290,16 +1291,16 @@ enum pim_msdp_err pim_msdp_mg_del(const char *mesh_group_name) static enum pim_msdp_err pim_msdp_mg_add(const char *mesh_group_name) { - if (msdp->mg) { - if (!strcmp(msdp->mg->mesh_group_name, mesh_group_name)) { + if (pimg->msdp.mg) { + if (!strcmp(pimg->msdp.mg->mesh_group_name, mesh_group_name)) { return PIM_MSDP_ERR_NONE; } /* currently only one mesh-group can exist at a time */ return PIM_MSDP_ERR_MAX_MESH_GROUPS; } - msdp->mg = pim_msdp_mg_new(mesh_group_name); - if (!msdp->mg) { + pimg->msdp.mg = pim_msdp_mg_new(mesh_group_name); + if (!pimg->msdp.mg) { return PIM_MSDP_ERR_OOM; } @@ -1330,12 +1331,12 @@ static struct pim_msdp_mg_mbr *pim_msdp_mg_mbr_find(struct in_addr mbr_ip) struct pim_msdp_mg_mbr *mbr; struct listnode *mbr_node; - if (!msdp->mg) { + if (!pimg->msdp.mg) { return NULL; } /* we can move this to a hash but considering that number of peers in * a mesh-group that seems like bit of an overkill */ - for (ALL_LIST_ELEMENTS_RO(msdp->mg->mbr_list, mbr_node, mbr)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.mg->mbr_list, mbr_node, mbr)) { if (mbr->mbr_ip.s_addr == mbr_ip.s_addr) { return mbr; } @@ -1355,7 +1356,7 @@ enum pim_msdp_err pim_msdp_mg_mbr_add(const char *mesh_group_name, return rc; } - mg = msdp->mg; + mg = pimg->msdp.mg; mbr = pim_msdp_mg_mbr_find(mbr_ip); if (mbr) { return PIM_MSDP_ERR_MG_MBR_EXISTS; @@ -1413,7 +1414,7 @@ enum pim_msdp_err pim_msdp_mg_mbr_del(const char *mesh_group_name, struct in_addr mbr_ip) { struct pim_msdp_mg_mbr *mbr; - struct pim_msdp_mg *mg = msdp->mg; + struct pim_msdp_mg *mg = pimg->msdp.mg; if (!mg || strcmp(mg->mesh_group_name, mesh_group_name)) { return PIM_MSDP_ERR_NO_MG; @@ -1435,7 +1436,7 @@ static void pim_msdp_mg_src_do_del(void) { struct pim_msdp_mg_mbr *mbr; struct listnode *mbr_node; - struct pim_msdp_mg *mg = msdp->mg; + struct pim_msdp_mg *mg = pimg->msdp.mg; /* SIP is being removed - tear down all active peer sessions */ for (ALL_LIST_ELEMENTS_RO(mg->mbr_list, mbr_node, mbr)) { @@ -1452,7 +1453,7 @@ static void pim_msdp_mg_src_do_del(void) enum pim_msdp_err pim_msdp_mg_src_del(const char *mesh_group_name) { - struct pim_msdp_mg *mg = msdp->mg; + struct pim_msdp_mg *mg = pimg->msdp.mg; if (!mg || strcmp(mg->mesh_group_name, mesh_group_name)) { return PIM_MSDP_ERR_NO_MG; @@ -1485,7 +1486,7 @@ enum pim_msdp_err pim_msdp_mg_src_add(const char *mesh_group_name, return rc; } - mg = msdp->mg; + mg = pimg->msdp.mg; if (mg->src_ip.s_addr != INADDR_ANY) { pim_msdp_mg_src_do_del(); } @@ -1510,7 +1511,7 @@ int pim_msdp_config_write(struct vty *vty) { struct listnode *mbrnode; struct pim_msdp_mg_mbr *mbr; - struct pim_msdp_mg *mg = msdp->mg; + struct pim_msdp_mg *mg = pimg->msdp.mg; char mbr_str[INET_ADDRSTRLEN]; char src_str[INET_ADDRSTRLEN]; int count = 0; @@ -1539,47 +1540,47 @@ int pim_msdp_config_write(struct vty *vty) * config. Till then MSDP should just stay quiet. */ static void pim_msdp_enable(void) { - if (msdp->flags & PIM_MSDPF_ENABLE) { + if (pimg->msdp.flags & PIM_MSDPF_ENABLE) { /* feature is already enabled */ return; } - msdp->flags |= PIM_MSDPF_ENABLE; - msdp->work_obuf = stream_new(PIM_MSDP_MAX_PACKET_SIZE); + pimg->msdp.flags |= PIM_MSDPF_ENABLE; + pimg->msdp.work_obuf = stream_new(PIM_MSDP_MAX_PACKET_SIZE); pim_msdp_sa_adv_timer_setup(true /* start */); /* setup sa cache based on local sources */ pim_msdp_sa_local_setup(); } /* MSDP init */ -void pim_msdp_init(struct thread_master *master) +void pim_msdp_init(struct thread_master *master, struct pim_instance *pim) { - msdp->master = master; + pimg->msdp.master = master; - msdp->peer_hash = hash_create(pim_msdp_peer_hash_key_make, - pim_msdp_peer_hash_eq, NULL); - msdp->peer_list = list_new(); - msdp->peer_list->del = (void (*)(void *))pim_msdp_peer_free; - msdp->peer_list->cmp = (int (*)(void *, void *))pim_msdp_peer_comp; + pim->msdp.peer_hash = hash_create(pim_msdp_peer_hash_key_make, + pim_msdp_peer_hash_eq, NULL); + pim->msdp.peer_list = list_new(); + pim->msdp.peer_list->del = (void (*)(void *))pim_msdp_peer_free; + pim->msdp.peer_list->cmp = (int (*)(void *, void *))pim_msdp_peer_comp; - msdp->sa_hash = hash_create(pim_msdp_sa_hash_key_make, - pim_msdp_sa_hash_eq, NULL); - msdp->sa_list = list_new(); - msdp->sa_list->del = (void (*)(void *))pim_msdp_sa_free; - msdp->sa_list->cmp = (int (*)(void *, void *))pim_msdp_sa_comp; + pim->msdp.sa_hash = hash_create(pim_msdp_sa_hash_key_make, + pim_msdp_sa_hash_eq, NULL); + pim->msdp.sa_list = list_new(); + pim->msdp.sa_list->del = (void (*)(void *))pim_msdp_sa_free; + pim->msdp.sa_list->cmp = (int (*)(void *, void *))pim_msdp_sa_comp; } /* counterpart to MSDP init; XXX: unused currently */ -void pim_msdp_exit(void) +void pim_msdp_exit(struct pim_instance *pim) { /* XXX: stop listener and delete all peer sessions */ - if (msdp->peer_hash) { - hash_free(msdp->peer_hash); - msdp->peer_hash = NULL; + if (pim->msdp.peer_hash) { + hash_free(pim->msdp.peer_hash); + pim->msdp.peer_hash = NULL; } - if (msdp->peer_list) { - list_free(msdp->peer_list); - msdp->peer_list = NULL; + if (pim->msdp.peer_list) { + list_free(pim->msdp.peer_list); + pim->msdp.peer_list = NULL; } } diff --git a/pimd/pim_msdp.h b/pimd/pim_msdp.h index 66e5457df..88bef4bc7 100644 --- a/pimd/pim_msdp.h +++ b/pimd/pim_msdp.h @@ -69,7 +69,7 @@ enum pim_msdp_sa_flags { PIM_MSDP_SAF_PEER = (1 << 1), PIM_MSDP_SAF_REF = (PIM_MSDP_SAF_LOCAL | PIM_MSDP_SAF_PEER), PIM_MSDP_SAF_STALE = (1 << 2), /* local entries can get kicked out on - * misc pim events such as RP change */ + * misc pim events such as RP change */ PIM_MSDP_SAF_UP_DEL_IN_PROG = (1 << 3) }; @@ -203,17 +203,20 @@ struct pim_msdp { }; #define PIM_MSDP_PEER_READ_ON(mp) \ - thread_add_read(msdp->master, pim_msdp_read, mp, mp->fd, &mp->t_read) + thread_add_read(pimg->msdp.master, pim_msdp_read, mp, mp->fd, \ + &mp->t_read) #define PIM_MSDP_PEER_WRITE_ON(mp) \ - thread_add_write(msdp->master, pim_msdp_write, mp, mp->fd, &mp->t_write) + thread_add_write(pimg->msdp.master, pim_msdp_write, mp, mp->fd, \ + &mp->t_write) #define PIM_MSDP_PEER_READ_OFF(mp) THREAD_READ_OFF(mp->t_read) #define PIM_MSDP_PEER_WRITE_OFF(mp) THREAD_WRITE_OFF(mp->t_write) -extern struct pim_msdp *msdp; -void pim_msdp_init(struct thread_master *master); -void pim_msdp_exit(void); +// struct pim_msdp *msdp; +struct pim_instance; +void pim_msdp_init(struct thread_master *master, struct pim_instance *pim); +void pim_msdp_exit(struct pim_instance *pim); enum pim_msdp_err pim_msdp_peer_add(struct in_addr peer, struct in_addr local, const char *mesh_group_name, struct pim_msdp_peer **mp_p); diff --git a/pimd/pim_msdp_packet.c b/pimd/pim_msdp_packet.c index 01ce293e3..7860a6ac2 100644 --- a/pimd/pim_msdp_packet.c +++ b/pimd/pim_msdp_packet.c @@ -318,7 +318,7 @@ static void pim_msdp_pkt_sa_push_to_one_peer(struct pim_msdp_peer *mp) /* don't tx anything unless a session is established */ return; } - s = stream_dup(msdp->work_obuf); + s = stream_dup(pimg->msdp.work_obuf); if (s) { pim_msdp_pkt_send(mp, s); mp->flags |= PIM_MSDP_PEERF_SA_JUST_SENT; @@ -333,7 +333,7 @@ static void pim_msdp_pkt_sa_push(struct pim_msdp_peer *mp) if (mp) { pim_msdp_pkt_sa_push_to_one_peer(mp); } else { - for (ALL_LIST_ELEMENTS_RO(msdp->peer_list, mpnode, mp)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.peer_list, mpnode, mp)) { if (PIM_DEBUG_MSDP_INTERNAL) { zlog_debug("MSDP peer %s pim_msdp_pkt_sa_push", mp->key_str); @@ -347,25 +347,26 @@ static int pim_msdp_pkt_sa_fill_hdr(int local_cnt) { int curr_tlv_ecnt; - stream_reset(msdp->work_obuf); + stream_reset(pimg->msdp.work_obuf); curr_tlv_ecnt = local_cnt > PIM_MSDP_SA_MAX_ENTRY_CNT ? PIM_MSDP_SA_MAX_ENTRY_CNT : local_cnt; local_cnt -= curr_tlv_ecnt; - stream_putc(msdp->work_obuf, PIM_MSDP_V4_SOURCE_ACTIVE); - stream_putw(msdp->work_obuf, PIM_MSDP_SA_ENTRY_CNT2SIZE(curr_tlv_ecnt)); - stream_putc(msdp->work_obuf, curr_tlv_ecnt); - stream_put_ipv4(msdp->work_obuf, msdp->originator_id.s_addr); + stream_putc(pimg->msdp.work_obuf, PIM_MSDP_V4_SOURCE_ACTIVE); + stream_putw(pimg->msdp.work_obuf, + PIM_MSDP_SA_ENTRY_CNT2SIZE(curr_tlv_ecnt)); + stream_putc(pimg->msdp.work_obuf, curr_tlv_ecnt); + stream_put_ipv4(pimg->msdp.work_obuf, pimg->msdp.originator_id.s_addr); return local_cnt; } static void pim_msdp_pkt_sa_fill_one(struct pim_msdp_sa *sa) { - stream_put3(msdp->work_obuf, 0 /* reserved */); - stream_putc(msdp->work_obuf, 32 /* sprefix len */); - stream_put_ipv4(msdp->work_obuf, sa->sg.grp.s_addr); - stream_put_ipv4(msdp->work_obuf, sa->sg.src.s_addr); + stream_put3(pimg->msdp.work_obuf, 0 /* reserved */); + stream_putc(pimg->msdp.work_obuf, 32 /* sprefix len */); + stream_put_ipv4(pimg->msdp.work_obuf, sa->sg.grp.s_addr); + stream_put_ipv4(pimg->msdp.work_obuf, sa->sg.src.s_addr); } static void pim_msdp_pkt_sa_gen(struct pim_msdp_peer *mp) @@ -373,7 +374,7 @@ static void pim_msdp_pkt_sa_gen(struct pim_msdp_peer *mp) struct listnode *sanode; struct pim_msdp_sa *sa; int sa_count; - int local_cnt = msdp->local_cnt; + int local_cnt = pimg->msdp.local_cnt; sa_count = 0; if (PIM_DEBUG_MSDP_INTERNAL) { @@ -382,7 +383,7 @@ static void pim_msdp_pkt_sa_gen(struct pim_msdp_peer *mp) local_cnt = pim_msdp_pkt_sa_fill_hdr(local_cnt); - for (ALL_LIST_ELEMENTS_RO(msdp->sa_list, sanode, sa)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.sa_list, sanode, sa)) { if (!(sa->flags & PIM_MSDP_SAF_LOCAL)) { /* current implementation of MSDP is for anycast i.e. * full mesh. so @@ -418,7 +419,7 @@ static void pim_msdp_pkt_sa_tx_done(void) /* if SA were sent to the peers we restart ka timer and avoid * unnecessary ka noise */ - for (ALL_LIST_ELEMENTS_RO(msdp->peer_list, mpnode, mp)) { + for (ALL_LIST_ELEMENTS_RO(pimg->msdp.peer_list, mpnode, mp)) { if (mp->flags & PIM_MSDP_PEERF_SA_JUST_SENT) { mp->flags &= ~PIM_MSDP_PEERF_SA_JUST_SENT; pim_msdp_peer_pkt_txed(mp); diff --git a/pimd/pim_msdp_socket.c b/pimd/pim_msdp_socket.c index 0ce097101..9b955d47c 100644 --- a/pimd/pim_msdp_socket.c +++ b/pimd/pim_msdp_socket.c @@ -85,7 +85,7 @@ static int pim_msdp_sock_accept(struct thread *thread) /* see if have peer config for this */ mp = pim_msdp_peer_find(su.sin.sin_addr); if (!mp || !PIM_MSDP_PEER_IS_LISTENER(mp)) { - ++msdp->rejected_accepts; + ++pimg->msdp.rejected_accepts; if (PIM_DEBUG_MSDP_EVENTS) { zlog_err("msdp peer connection refused from %s", sockunion2str(&su, buf, SU_ADDRSTRLEN)); @@ -123,9 +123,9 @@ int pim_msdp_sock_listen(void) int socklen; struct sockaddr_in sin; int rc; - struct pim_msdp_listener *listener = &msdp->listener; + struct pim_msdp_listener *listener = &pimg->msdp.listener; - if (msdp->flags & PIM_MSDPF_LISTENER) { + if (pimg->msdp.flags & PIM_MSDPF_LISTENER) { /* listener already setup */ return 0; } @@ -178,10 +178,10 @@ int pim_msdp_sock_listen(void) listener->fd = sock; memcpy(&listener->su, &sin, socklen); listener->thread = NULL; - thread_add_read(msdp->master, pim_msdp_sock_accept, listener, sock, + thread_add_read(pimg->msdp.master, pim_msdp_sock_accept, listener, sock, &listener->thread); - msdp->flags |= PIM_MSDPF_LISTENER; + pimg->msdp.flags |= PIM_MSDPF_LISTENER; return 0; } |