pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-sgsn/+/40973?usp=email )
Change subject: iu_rnc: Split iu_rnc_register API into 2 steps ......................................................................
iu_rnc: Split iu_rnc_register API into 2 steps
Split lookup+allocation from RAI updating. This will be needed once we start creating iu_rnc objects upon SCCP rx RANAP RESET messages, which hold Global RNC-ID but no RAI information.
Change-Id: I3761cc539c63a7ed680b04bb8136a43d397c10aa --- M include/osmocom/sgsn/iu_rnc.h M src/sgsn/gprs_ranap.c M src/sgsn/iu_rnc.c 3 files changed, 41 insertions(+), 35 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/73/40973/1
diff --git a/include/osmocom/sgsn/iu_rnc.h b/include/osmocom/sgsn/iu_rnc.h index 895e922..344337d 100644 --- a/include/osmocom/sgsn/iu_rnc.h +++ b/include/osmocom/sgsn/iu_rnc.h @@ -30,6 +30,6 @@ struct llist_head lac_rac_list; };
-struct ranap_iu_rnc *iu_rnc_register(struct osmo_rnc_id *rnc_id, - const struct osmo_routing_area_id *rai, - const struct osmo_sccp_addr *addr); +struct ranap_iu_rnc *iu_rnc_find_or_create(const struct osmo_rnc_id *rnc_id, + const struct osmo_sccp_addr *addr); +void iu_rnc_update_rai_seen(struct ranap_iu_rnc *rnc, const struct osmo_routing_area_id *rai); diff --git a/src/sgsn/gprs_ranap.c b/src/sgsn/gprs_ranap.c index 0ddb959..7ddeea8 100644 --- a/src/sgsn/gprs_ranap.c +++ b/src/sgsn/gprs_ranap.c @@ -374,6 +374,7 @@ struct msgb *msg = msgb_alloc(256, "RANAP->NAS"); struct ranap_iu_rnc *rnc;
+ if (ranap_parse_lai(&ra_id, &ies->lai) != 0) { LOGP(DRANAP, LOGL_ERROR, "Failed to parse RANAP LAI IE\n"); return -1; @@ -404,7 +405,9 @@ gprs_rai_to_osmo(&ra_id2, &ra_id);
/* Make sure we know the RNC Id and LAC+RAC coming in on this connection. */ - rnc = iu_rnc_register(&rnc_id, &ra_id2, rem_sccp_addr); + rnc = iu_rnc_find_or_create(&rnc_id, rem_sccp_addr); + OSMO_ASSERT(rnc); + iu_rnc_update_rai_seen(rnc, &ra_id2);
ue = ue_conn_ctx_alloc(rnc, scu_iups, conn_id); OSMO_ASSERT(ue); diff --git a/src/sgsn/iu_rnc.c b/src/sgsn/iu_rnc.c index b1af9ba..8bb5bc1 100644 --- a/src/sgsn/iu_rnc.c +++ b/src/sgsn/iu_rnc.c @@ -60,6 +60,35 @@ return rnc; }
+static struct ranap_iu_rnc *iu_rnc_find_by_id(const struct osmo_rnc_id *rnc_id) +{ + struct ranap_iu_rnc *rnc; + llist_for_each_entry(rnc, &sgsn->rnc_list, entry) { + if (!osmo_rnc_id_cmp(&rnc->rnc_id, rnc_id)) + return rnc; + } + return NULL; +} + +struct ranap_iu_rnc *iu_rnc_find_or_create(const struct osmo_rnc_id *rnc_id, + const struct osmo_sccp_addr *addr) +{ + struct ranap_iu_rnc *rnc; + + /* Make sure we know this rnc_id and that this SCCP address is in our records */ + rnc = iu_rnc_find_by_id(rnc_id); + if (rnc) { + if (!osmo_sccp_addr_ri_cmp(&rnc->sccp_addr, addr)) { + LOGP(DRANAP, LOGL_NOTICE, "RNC %s changed its SCCP addr to %s\n", + osmo_rnc_id_name(&rnc->rnc_id), osmo_sccp_addr_dump(addr)); + rnc->sccp_addr = *addr; + } + } else { + rnc = iu_rnc_alloc(rnc_id, addr); + } + return rnc; +} + /* Find a match for the given LAC (and RAC). For CS, pass rac as 0. * If rnc and lre pointers are not NULL, *rnc / *lre are set to NULL if no match is found, or to the * match if a match is found. Return true if a match is found. */ @@ -88,16 +117,6 @@ return false; }
-static struct ranap_iu_rnc *iu_rnc_id_find(struct osmo_rnc_id *rnc_id) -{ - struct ranap_iu_rnc *rnc; - llist_for_each_entry(rnc, &sgsn->rnc_list, entry) { - if (!osmo_rnc_id_cmp(&rnc->rnc_id, rnc_id)) - return rnc; - } - return NULL; -} - static void global_iu_event_new_area(const struct osmo_rnc_id *rnc_id, const struct osmo_routing_area_id *rai) { struct ranap_iu_event_new_area new_area = (struct ranap_iu_event_new_area) { @@ -116,26 +135,12 @@ global_iu_event(NULL, RANAP_IU_EVENT_NEW_AREA, &new_area); }
-struct ranap_iu_rnc *iu_rnc_register(struct osmo_rnc_id *rnc_id, - const struct osmo_routing_area_id *rai, - const struct osmo_sccp_addr *addr) + +void iu_rnc_update_rai_seen(struct ranap_iu_rnc *rnc, const struct osmo_routing_area_id *rai) { - struct ranap_iu_rnc *rnc; struct ranap_iu_rnc *old_rnc; struct iu_lac_rac_entry *lre;
- /* Make sure we know this rnc_id and that this SCCP address is in our records */ - rnc = iu_rnc_id_find(rnc_id); - - if (rnc) { - if (!osmo_sccp_addr_ri_cmp(&rnc->sccp_addr, addr)) { - LOGP(DRANAP, LOGL_NOTICE, "RNC %s changed its SCCP addr to %s (LAC/RAC %s)\n", - osmo_rnc_id_name(rnc_id), osmo_sccp_addr_dump(addr), osmo_rai_name2(rai)); - rnc->sccp_addr = *addr; - } - } else - rnc = iu_rnc_alloc(rnc_id, addr); - /* Detect whether the LAC,RAC is already recorded in another RNC */ iu_rnc_lac_rac_find(&old_rnc, &lre, rai);
@@ -149,17 +154,15 @@
llist_del(&lre->entry); llist_add(&lre->entry, &rnc->lac_rac_list); - global_iu_event_new_area(rnc_id, rai); + global_iu_event_new_area(&rnc->rnc_id, rai); } else if (!old_rnc) { /* LAC, RAC not recorded yet */ LOGP(DRANAP, LOGL_NOTICE, "RNC %s: new LAC/RAC %s\n", - osmo_rnc_id_name(rnc_id), osmo_rai_name2(rai)); + osmo_rnc_id_name(&rnc->rnc_id), osmo_rai_name2(rai)); lre = talloc_zero(rnc, struct iu_lac_rac_entry); lre->rai = *rai; llist_add(&lre->entry, &rnc->lac_rac_list); - global_iu_event_new_area(rnc_id, rai); + global_iu_event_new_area(&rnc->rnc_id, rai); } /* else, LAC,RAC already recorded with the current RNC. */ - - return rnc; }