Skip to content

Commit

Permalink
Merge pull request FRRouting#17636 from opensourcerouting/msdp-cleanup
Browse files Browse the repository at this point in the history
pimd: clean up MSDP code
  • Loading branch information
donaldsharp authored Dec 12, 2024
2 parents 492750f + d4da631 commit f170e9b
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 115 deletions.
9 changes: 4 additions & 5 deletions pimd/pim_instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ static void pim_instance_terminate(struct pim_instance *pim)

pim_oil_terminate(pim);

#if PIM_IPV == 4
pim_msdp_exit(pim);
#endif /* PIM_IPV == 4 */

close(pim->reg_sock);

Expand Down Expand Up @@ -91,7 +93,9 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf)
pim->spt.switchover = PIM_SPT_IMMEDIATE;
pim->spt.plist = NULL;

#if PIM_IPV == 4
pim_msdp_init(pim, router->master);
#endif /* PIM_IPV == 4 */
pim_vxlan_init(pim);

snprintf(hash_name, sizeof(hash_name), "PIM %s RPF Hash", vrf->name);
Expand Down Expand Up @@ -126,11 +130,6 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf)
if (pim->reg_sock < 0)
assert(0);

/* MSDP global timer defaults. */
pim->msdp.hold_time = PIM_MSDP_PEER_HOLD_TIME;
pim->msdp.keep_alive = PIM_MSDP_PEER_KA_TIME;
pim->msdp.connection_retry = PIM_MSDP_PEER_CONNECT_RETRY_TIME;

#if PIM_IPV == 4
pim_autorp_init(pim);
#endif
Expand Down
5 changes: 2 additions & 3 deletions pimd/pim_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ struct pim_instance {

struct rb_pim_oil_head channel_oil_head;

#if PIM_IPV == 4
struct pim_msdp msdp;
#endif /* PIM_IPV == 4 */
struct pim_vxlan_instance vxlan;

struct pim_autorp *autorp;
Expand Down Expand Up @@ -225,7 +227,4 @@ extern struct pim_router *router;

struct pim_instance *pim_get_pim_instance(vrf_id_t vrf_id);

extern bool pim_msdp_log_neighbor_events(const struct pim_instance *pim);
extern bool pim_msdp_log_sa_events(const struct pim_instance *pim);

#endif
40 changes: 35 additions & 5 deletions pimd/pim_msdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#include "pim_msdp_packet.h"
#include "pim_msdp_socket.h"

// 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);
static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer *mp, bool start);
Expand Down Expand Up @@ -1272,10 +1270,21 @@ int pim_msdp_config_write(struct pim_instance *pim, struct vty *vty)
char src_str[INET_ADDRSTRLEN];
int count = 0;

if (pim->msdp.hold_time != PIM_MSDP_PEER_HOLD_TIME ||
pim->msdp.keep_alive != PIM_MSDP_PEER_KA_TIME ||
pim->msdp.connection_retry != PIM_MSDP_PEER_CONNECT_RETRY_TIME) {
vty_out(vty, " msdp timers %u %u", pim->msdp.hold_time, pim->msdp.keep_alive);
if (pim->msdp.connection_retry != PIM_MSDP_PEER_CONNECT_RETRY_TIME)
vty_out(vty, " %u", pim->msdp.connection_retry);
vty_out(vty, "\n");
}

if (pim_msdp_log_neighbor_events(pim))
vty_out(vty, " msdp log neighbor-events\n");
if (pim_msdp_log_sa_events(pim))
vty_out(vty, " msdp log sa-events\n");
if (pim->msdp.shutdown)
vty_out(vty, " msdp shutdown\n");

if (SLIST_EMPTY(&pim->msdp.mglist))
return count;
Expand Down Expand Up @@ -1331,9 +1340,6 @@ bool pim_msdp_peer_config_write(struct vty *vty, struct pim_instance *pim)
written = true;
}

if (pim->msdp.shutdown)
vty_out(vty, " msdp shutdown\n");

return written;
}

Expand Down Expand Up @@ -1373,6 +1379,11 @@ void pim_msdp_init(struct pim_instance *pim, struct event_loop *master)
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;

/* MSDP global timer defaults. */
pim->msdp.hold_time = PIM_MSDP_PEER_HOLD_TIME;
pim->msdp.keep_alive = PIM_MSDP_PEER_KA_TIME;
pim->msdp.connection_retry = PIM_MSDP_PEER_CONNECT_RETRY_TIME;
}

/* counterpart to MSDP init; XXX: unused currently */
Expand Down Expand Up @@ -1455,6 +1466,25 @@ struct pim_msdp_mg_mbr *pim_msdp_mg_mbr_add(struct pim_instance *pim,
return mbr;
}

/* MSDP on RP needs to know if a source is registerable to this RP */
static void pim_upstream_msdp_reg_timer(struct event *t)
{
struct pim_upstream *up = EVENT_ARG(t);
struct pim_instance *pim = up->channel_oil->pim;

/* source is no longer active - pull the SA from MSDP's cache */
pim_msdp_sa_local_del(pim, &up->sg);
}

void pim_upstream_msdp_reg_timer_start(struct pim_upstream *up)
{
EVENT_OFF(up->t_msdp_reg_timer);
event_add_timer(router->master, pim_upstream_msdp_reg_timer, up, PIM_MSDP_REG_RXED_PERIOD,
&up->t_msdp_reg_timer);

pim_msdp_sa_local_update(up);
}

void pim_msdp_shutdown(struct pim_instance *pim, bool state)
{
struct pim_msdp_peer *peer;
Expand Down
54 changes: 4 additions & 50 deletions pimd/pim_msdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ struct pim_msdp {
#define PIM_MSDP_PEER_READ_OFF(mp) event_cancel(&mp->t_read)
#define PIM_MSDP_PEER_WRITE_OFF(mp) event_cancel(&mp->t_write)

#if PIM_IPV != 6
// struct pim_msdp *msdp;
struct pim_instance;
void pim_msdp_init(struct pim_instance *pim, struct event_loop *master);
void pim_msdp_exit(struct pim_instance *pim);
Expand All @@ -263,6 +261,8 @@ void pim_msdp_up_del(struct pim_instance *pim, pim_sgaddr *sg);
enum pim_msdp_err pim_msdp_mg_del(struct pim_instance *pim,
const char *mesh_group_name);

extern void pim_upstream_msdp_reg_timer_start(struct pim_upstream *up);

/**
* Allocates a new mesh group data structure under PIM instance.
*/
Expand Down Expand Up @@ -341,53 +341,7 @@ void pim_msdp_peer_restart(struct pim_msdp_peer *mp);
*/
void pim_msdp_shutdown(struct pim_instance *pim, bool state);

#else /* PIM_IPV == 6 */
static inline void pim_msdp_init(struct pim_instance *pim,
struct event_loop *master)
{
}

static inline void pim_msdp_exit(struct pim_instance *pim)
{
}

static inline void pim_msdp_i_am_rp_changed(struct pim_instance *pim)
{
}

static inline void pim_msdp_up_join_state_changed(struct pim_instance *pim,
struct pim_upstream *xg_up)
{
}

static inline void pim_msdp_up_del(struct pim_instance *pim, pim_sgaddr *sg)
{
}

static inline void pim_msdp_sa_local_update(struct pim_upstream *up)
{
}

static inline void pim_msdp_sa_local_del(struct pim_instance *pim,
pim_sgaddr *sg)
{
}

static inline int pim_msdp_config_write(struct pim_instance *pim,
struct vty *vty)
{
return 0;
}

static inline bool pim_msdp_peer_config_write(struct vty *vty,
struct pim_instance *pim)
{
return false;
}

static inline void pim_msdp_shutdown(struct pim_instance *pim, bool state)
{
}
#endif /* PIM_IPV == 6 */
extern bool pim_msdp_log_neighbor_events(const struct pim_instance *pim);
extern bool pim_msdp_log_sa_events(const struct pim_instance *pim);

#endif
54 changes: 33 additions & 21 deletions pimd/pim_nb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,38 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_ss
return NB_OK;
}

pim6_msdp_err(pim_msdp_hold_time_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_keep_alive_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_connection_retry_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_mesh_group_destroy, nb_cb_destroy_args);
pim6_msdp_err(pim_msdp_mesh_group_create, nb_cb_create_args);
pim6_msdp_err(pim_msdp_mesh_group_source_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_mesh_group_source_destroy, nb_cb_destroy_args);
pim6_msdp_err(pim_msdp_mesh_group_members_create, nb_cb_create_args);
pim6_msdp_err(pim_msdp_mesh_group_members_destroy, nb_cb_destroy_args);
pim6_msdp_err(pim_msdp_peer_sa_filter_in_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_peer_sa_filter_in_destroy, nb_cb_destroy_args);
pim6_msdp_err(pim_msdp_peer_sa_filter_out_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_peer_sa_filter_out_destroy, nb_cb_destroy_args);
pim6_msdp_err(pim_msdp_peer_sa_limit_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_peer_sa_limit_destroy, nb_cb_destroy_args);
pim6_msdp_err(
routing_control_plane_protocols_control_plane_protocol_pim_address_family_msdp_peer_source_ip_modify,
nb_cb_modify_args);
pim6_msdp_err(
routing_control_plane_protocols_control_plane_protocol_pim_address_family_msdp_peer_destroy,
nb_cb_destroy_args);
pim6_msdp_err(
routing_control_plane_protocols_control_plane_protocol_pim_address_family_msdp_peer_create,
nb_cb_create_args);
pim6_msdp_err(pim_msdp_peer_authentication_type_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_peer_authentication_key_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_peer_authentication_key_destroy, nb_cb_destroy_args);
pim6_msdp_err(pim_msdp_log_neighbor_events_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_log_sa_events_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_shutdown_modify, nb_cb_modify_args);

#if PIM_IPV != 6
/*
* XPath:
* /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/msdp/hold-time
Expand Down Expand Up @@ -1081,26 +1113,6 @@ int pim_msdp_connection_retry_modify(struct nb_cb_modify_args *args)
return NB_OK;
}

pim6_msdp_err(pim_msdp_mesh_group_destroy, nb_cb_destroy_args);
pim6_msdp_err(pim_msdp_mesh_group_create, nb_cb_create_args);
pim6_msdp_err(pim_msdp_mesh_group_source_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_mesh_group_source_destroy, nb_cb_destroy_args);
pim6_msdp_err(pim_msdp_mesh_group_members_create, nb_cb_create_args);
pim6_msdp_err(pim_msdp_mesh_group_members_destroy, nb_cb_destroy_args);
pim6_msdp_err(routing_control_plane_protocols_control_plane_protocol_pim_address_family_msdp_peer_source_ip_modify,
nb_cb_modify_args);
pim6_msdp_err(routing_control_plane_protocols_control_plane_protocol_pim_address_family_msdp_peer_destroy,
nb_cb_destroy_args);
pim6_msdp_err(routing_control_plane_protocols_control_plane_protocol_pim_address_family_msdp_peer_create,
nb_cb_create_args);
pim6_msdp_err(pim_msdp_peer_authentication_type_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_peer_authentication_key_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_peer_authentication_key_destroy, nb_cb_destroy_args);
pim6_msdp_err(pim_msdp_log_neighbor_events_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_log_sa_events_modify, nb_cb_modify_args);
pim6_msdp_err(pim_msdp_shutdown_modify, nb_cb_modify_args);

#if PIM_IPV != 6
/*
* XPath:
* /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/msdp/log-neighbor-events
Expand Down Expand Up @@ -1489,7 +1501,6 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_ms

return NB_OK;
}
#endif /* PIM_IPV != 6 */

/*
* XPath:
Expand Down Expand Up @@ -1620,6 +1631,7 @@ int pim_msdp_peer_sa_limit_destroy(struct nb_cb_destroy_args *args)

return NB_OK;
}
#endif /* PIM_IPV != 6 */

/*
* XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/mlag
Expand Down
3 changes: 3 additions & 0 deletions pimd/pim_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,10 @@ int pim_register_recv(struct interface *ifp, pim_addr dest_addr,
// inherited_olist(S,G,rpt)
// This is taken care of by the kernel for us
}

#if PIM_IPV == 4
pim_upstream_msdp_reg_timer_start(upstream);
#endif /* PIM_IPV == 4 */
} else {
if (PIM_DEBUG_PIM_REG) {
if (!i_am_rp)
Expand Down
6 changes: 6 additions & 0 deletions pimd/pim_rp.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ struct rp_info *pim_rp_find_match_group(struct pim_instance *pim,
*/
void pim_rp_refresh_group_to_rp_mapping(struct pim_instance *pim)
{
#if PIM_IPV == 4
pim_msdp_i_am_rp_changed(pim);
#endif /* PIM_IPV == 4 */
pim_upstream_reeval_use_rpt(pim);
}

Expand Down Expand Up @@ -1030,7 +1032,9 @@ void pim_rp_check_on_if_add(struct pim_interface *pim_ifp)
}

if (i_am_rp_changed) {
#if PIM_IPV == 4
pim_msdp_i_am_rp_changed(pim);
#endif /* PIM_IPV == 4 */
pim_upstream_reeval_use_rpt(pim);
}
}
Expand Down Expand Up @@ -1072,7 +1076,9 @@ void pim_i_am_rp_re_evaluate(struct pim_instance *pim)
}

if (i_am_rp_changed) {
#if PIM_IPV == 4
pim_msdp_i_am_rp_changed(pim);
#endif /* PIM_IPV == 4 */
pim_upstream_reeval_use_rpt(pim);
}
}
Expand Down
Loading

0 comments on commit f170e9b

Please sign in to comment.