pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sigtran/+/38730?usp=email )
Change subject: Move code to delete routes by as/linkset to helper functions ......................................................................
Move code to delete routes by as/linkset to helper functions
This really fits into a helper function, allowig for further reuse in the future and removing complexity from other code functions. It also makes the logic independent on the implementation of the routing table.
Change-Id: Ic36fd6a0466cc0338132f2e34eb7c916115c9d4a --- M src/osmo_ss7_as.c M src/osmo_ss7_linkset.c M src/osmo_ss7_route_table.c M src/ss7_route_table.h 4 files changed, 28 insertions(+), 12 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/30/38730/1
diff --git a/src/osmo_ss7_as.c b/src/osmo_ss7_as.c index 3540fde..eb655ca 100644 --- a/src/osmo_ss7_as.c +++ b/src/osmo_ss7_as.c @@ -167,8 +167,6 @@ * \param[in] as Application Server to destroy */ void osmo_ss7_as_destroy(struct osmo_ss7_as *as) { - struct osmo_ss7_route *rt, *rt2; - OSMO_ASSERT(ss7_initialized); LOGPAS(as, DLSS7, LOGL_INFO, "Destroying AS\n");
@@ -176,10 +174,7 @@ osmo_fsm_inst_term(as->fi, OSMO_FSM_TERM_REQUEST, NULL);
/* find any routes pointing to this AS and remove them */ - llist_for_each_entry_safe(rt, rt2, &as->inst->rtable_system->routes, list) { - if (rt->dest.as == as) - ss7_route_destroy(rt); - } + ss7_route_table_del_routes_by_as(as->inst->rtable_system, as);
as->inst = NULL; llist_del(&as->list); diff --git a/src/osmo_ss7_linkset.c b/src/osmo_ss7_linkset.c index 9e0b17b..146ec92 100644 --- a/src/osmo_ss7_linkset.c +++ b/src/osmo_ss7_linkset.c @@ -39,18 +39,14 @@ * \param[in] lset Linkset to be destroyed */ void ss7_linkset_destroy(struct osmo_ss7_linkset *lset) { - struct osmo_ss7_route *rt, *rt2; unsigned int i;
OSMO_ASSERT(ss7_initialized); LOGSS7(lset->inst, LOGL_INFO, "Destroying Linkset %s\n", lset->cfg.name);
- /* find any routes pointing to this AS and remove them */ - llist_for_each_entry_safe(rt, rt2, &lset->inst->rtable_system->routes, list) { - if (rt->dest.linkset == lset) - ss7_route_destroy(rt); - } + /* find any routes pointing to this linkset and remove them */ + ss7_route_table_del_routes_by_linkset(lset->inst->rtable_system, lset);
for (i = 0; i < ARRAY_SIZE(lset->links); i++) { struct osmo_ss7_link *link = lset->links[i]; diff --git a/src/osmo_ss7_route_table.c b/src/osmo_ss7_route_table.c index 910633b..03596d0 100644 --- a/src/osmo_ss7_route_table.c +++ b/src/osmo_ss7_route_table.c @@ -122,3 +122,25 @@ } return NULL; } + +/* find any routes pointing to this linkset and remove them */ +void ss7_route_table_del_routes_by_linkset(struct osmo_ss7_route_table *rtbl, struct osmo_ss7_linkset *lset) +{ + struct osmo_ss7_route *rt, *rt2; + + llist_for_each_entry_safe(rt, rt2, &rtbl->routes, list) { + if (rt->dest.linkset == lset) + ss7_route_destroy(rt); + } +} + +/* find any routes pointing to this AS and remove them */ +void ss7_route_table_del_routes_by_as(struct osmo_ss7_route_table *rtbl, struct osmo_ss7_as *as) +{ + struct osmo_ss7_route *rt, *rt2; + + llist_for_each_entry_safe(rt, rt2, &rtbl->routes, list) { + if (rt->dest.as == as) + ss7_route_destroy(rt); + } +} diff --git a/src/ss7_route_table.h b/src/ss7_route_table.h index 5c70c4c..38cff31 100644 --- a/src/ss7_route_table.h +++ b/src/ss7_route_table.h @@ -34,3 +34,6 @@ struct osmo_ss7_route * ss7_route_table_find_route_by_dpc_mask(struct osmo_ss7_route_table *rtbl, uint32_t dpc, uint32_t mask); + +void ss7_route_table_del_routes_by_as(struct osmo_ss7_route_table *rtbl, struct osmo_ss7_as *as); +void ss7_route_table_del_routes_by_linkset(struct osmo_ss7_route_table *rtbl, struct osmo_ss7_linkset *lset);