aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-03-05 10:20:11 +0100
committerlaforge <laforge@osmocom.org>2021-03-10 12:23:09 +0000
commit06d9bf910b450b1176b3d78b163fb2022c68c554 (patch)
tree2253baa3afe52a9823df72211399aa7c17f271be /src
parentc1c7e4a8304d3dcecd1b220cbc453db0510841b5 (diff)
gprs_ns2: Encapsulate setting NSE dialect
Setting the NSE dialect possibly involves the creating (or destruction) of a IP-SNS FSM. Encapsulate that, rather than having every caller re-implement that. Change-Id: I24fdc26fbcfda039bd58ea166f4d5c2fd1801da1
Diffstat (limited to 'src')
-rw-r--r--src/gb/gprs_ns2.c45
-rw-r--r--src/gb/gprs_ns2_internal.h1
-rw-r--r--src/gb/gprs_ns2_vty.c44
3 files changed, 53 insertions, 37 deletions
diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index e19ae780..93b7c3a0 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -781,7 +781,6 @@ struct gprs_ns2_nse *gprs_ns2_create_nse(struct gprs_ns2_inst *nsi, uint16_t nse
enum gprs_ns2_ll linklayer, enum gprs_ns2_dialect dialect)
{
struct gprs_ns2_nse *nse;
- char sns[16];
nse = gprs_ns2_nse_by_nsei(nsi, nsei);
if (nse) {
@@ -792,17 +791,13 @@ struct gprs_ns2_nse *gprs_ns2_create_nse(struct gprs_ns2_inst *nsi, uint16_t nse
nse = talloc_zero(nsi, struct gprs_ns2_nse);
if (!nse)
return NULL;
+ nse->dialect = GPRS_NS2_DIALECT_UNDEF;
- if (dialect == GPRS_NS2_DIALECT_SNS) {
- snprintf(sns, sizeof(sns), "NSE%05u-SNS", nsei);
- nse->bss_sns_fi = ns2_sns_bss_fsm_alloc(nse, sns);
- if (!nse->bss_sns_fi) {
- talloc_free(nse);
- return NULL;
- }
+ if (ns2_nse_set_dialect(nse, dialect) < 0) {
+ talloc_free(nse);
+ return NULL;
}
- nse->dialect = dialect;
nse->ll = linklayer;
nse->nsei = nsei;
nse->nsi = nsi;
@@ -814,6 +809,38 @@ struct gprs_ns2_nse *gprs_ns2_create_nse(struct gprs_ns2_inst *nsi, uint16_t nse
return nse;
}
+int ns2_nse_set_dialect(struct gprs_ns2_nse *nse, enum gprs_ns2_dialect dialect)
+{
+ char sns[16];
+
+ if (nse->dialect == dialect)
+ return 0;
+
+ switch (nse->dialect) {
+ case GPRS_NS2_DIALECT_UNDEF:
+ if (dialect == GPRS_NS2_DIALECT_SNS) {
+ snprintf(sns, sizeof(sns), "NSE%05u-SNS", nse->nsei);
+ nse->bss_sns_fi = ns2_sns_bss_fsm_alloc(nse, sns);
+ if (!nse->bss_sns_fi)
+ return -1;
+ }
+ nse->dialect = dialect;
+ break;
+ default:
+ if (dialect == GPRS_NS2_DIALECT_UNDEF) {
+ if (nse->bss_sns_fi)
+ osmo_fsm_inst_term(nse->bss_sns_fi, OSMO_FSM_TERM_REQUEST, NULL);
+ nse->bss_sns_fi = NULL;
+ nse->dialect = GPRS_NS2_DIALECT_UNDEF;
+ } else {
+ /* we don't support arbitrary changes without going through UNDEF first */
+ return -EPERM;
+ }
+ }
+
+ return 0;
+}
+
/*! Return the NSEI
* \param[in] nse NS Entity
* \return the nsei.
diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h
index 80e664c3..688a5874 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -306,6 +306,7 @@ void ns2_prim_status_ind(struct gprs_ns2_nse *nse,
enum gprs_ns2_affecting_cause cause);
void ns2_nse_notify_alive(struct gprs_ns2_vc *nsvc, bool alive);
void ns2_nse_update_mtu(struct gprs_ns2_nse *nse);
+int ns2_nse_set_dialect(struct gprs_ns2_nse *nse, enum gprs_ns2_dialect dialect);
/* message */
int ns2_validate(struct gprs_ns2_vc *nsvc,
diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c
index 76e44345..a769ad1b 100644
--- a/src/gb/gprs_ns2_vty.c
+++ b/src/gb/gprs_ns2_vty.c
@@ -900,7 +900,7 @@ DEFUN(cfg_ns_nse_nsvc_fr, cfg_ns_nse_nsvc_fr_cmd,
}
if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) {
- nse->dialect = GPRS_NS2_DIALECT_STATIC_RESETBLOCK;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_STATIC_RESETBLOCK);
dialect_modified = true;
}
@@ -935,7 +935,7 @@ err:
if (ll_modified)
nse->ll = GPRS_NS2_LL_UNDEF;
if (dialect_modified)
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
return CMD_WARNING;
}
@@ -986,7 +986,7 @@ DEFUN(cfg_no_ns_nse_nsvc_fr_dlci, cfg_no_ns_nse_nsvc_fr_dlci_cmd,
gprs_ns2_free_nsvc(nsvc);
if (llist_empty(&nse->nsvc)) {
nse->ll = GPRS_NS2_LL_UNDEF;
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
}
return CMD_SUCCESS;
@@ -1032,7 +1032,7 @@ DEFUN(cfg_no_ns_nse_nsvci, cfg_no_ns_nse_nsvci_cmd,
gprs_ns2_free_nsvc(nsvc);
if (llist_empty(&nse->nsvc)) {
nse->ll = GPRS_NS2_LL_UNDEF;
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
}
return CMD_SUCCESS;
@@ -1056,7 +1056,7 @@ static int ns_nse_nsvc_udp_cmds(struct vty *vty, const char *bind_name, const ch
}
if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) {
- nse->dialect = GPRS_NS2_DIALECT_STATIC_ALIVE;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_STATIC_ALIVE);
dialect_modified = true;
}
@@ -1117,7 +1117,7 @@ err:
if (ll_modified)
nse->ll = GPRS_NS2_LL_UNDEF;
if (dialect_modified)
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
return CMD_WARNING;
}
@@ -1232,7 +1232,7 @@ DEFUN(cfg_no_ns_nse_nsvc_udp, cfg_no_ns_nse_nsvc_udp_cmd,
gprs_ns2_free_nsvc(nsvc);
if (llist_empty(&nse->nsvc)) {
nse->ll = GPRS_NS2_LL_UNDEF;
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
}
return CMD_SUCCESS;
@@ -1267,7 +1267,7 @@ DEFUN(cfg_ns_nse_nsvc_ipa, cfg_ns_nse_nsvc_ipa_cmd,
}
if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) {
- nse->dialect = GPRS_NS2_DIALECT_IPACCESS;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_IPACCESS);
dialect_modified = true;
}
@@ -1317,7 +1317,7 @@ err:
if (ll_modified)
nse->ll = GPRS_NS2_LL_UNDEF;
if (dialect_modified)
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
return CMD_WARNING;
}
@@ -1407,7 +1407,7 @@ DEFUN(cfg_no_ns_nse_nsvc_ipa, cfg_no_ns_nse_nsvc_ipa_cmd,
gprs_ns2_free_nsvc(nsvc);
if (llist_empty(&nse->nsvc)) {
nse->ll = GPRS_NS2_LL_UNDEF;
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
}
return CMD_SUCCESS;
@@ -1436,12 +1436,8 @@ DEFUN(cfg_ns_nse_ip_sns_remote, cfg_ns_nse_ip_sns_remote_cmd,
}
if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) {
- char sns[16];
- snprintf(sns, sizeof(sns), "NSE%05u-SNS", nse->nsei);
- nse->bss_sns_fi = ns2_sns_bss_fsm_alloc(nse, sns);
- if (!nse->bss_sns_fi)
+ if (ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_SNS) < 0)
goto err;
- nse->dialect = GPRS_NS2_DIALECT_SNS;
dialect_modified = true;
}
@@ -1481,7 +1477,7 @@ err:
if (ll_modified)
nse->ll = GPRS_NS2_LL_UNDEF;
if (dialect_modified)
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
return CMD_WARNING;
}
@@ -1528,10 +1524,8 @@ DEFUN(cfg_no_ns_nse_ip_sns_remote, cfg_no_ns_nse_ip_sns_remote_cmd,
return CMD_SUCCESS;
} else {
/* clean up nse to allow other nsvc commands */
- osmo_fsm_inst_term(nse->bss_sns_fi, OSMO_FSM_TERM_REQUEST, NULL);
- nse->bss_sns_fi = NULL;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
nse->ll = GPRS_NS2_LL_UNDEF;
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
}
return CMD_SUCCESS;
@@ -1557,12 +1551,8 @@ DEFUN(cfg_ns_nse_ip_sns_bind, cfg_ns_nse_ip_sns_bind_cmd,
}
if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) {
- char sns[16];
- snprintf(sns, sizeof(sns), "NSE%05u-SNS", nse->nsei);
- nse->bss_sns_fi = ns2_sns_bss_fsm_alloc(nse, sns);
- if (!nse->bss_sns_fi)
+ if (ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_SNS) < 0)
goto err;
- nse->dialect = GPRS_NS2_DIALECT_SNS;
dialect_modified = true;
}
@@ -1632,7 +1622,7 @@ err:
if (ll_modified)
nse->ll = GPRS_NS2_LL_UNDEF;
if (dialect_modified)
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
return CMD_WARNING;
}
@@ -1698,10 +1688,8 @@ DEFUN(cfg_no_ns_nse_ip_sns_bind, cfg_no_ns_nse_ip_sns_bind_cmd,
if (!vty_nse_check_sns(nse)) {
/* clean up nse to allow other nsvc commands */
- osmo_fsm_inst_term(nse->bss_sns_fi, OSMO_FSM_TERM_REQUEST, NULL);
- nse->bss_sns_fi = NULL;
+ ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF);
nse->ll = GPRS_NS2_LL_UNDEF;
- nse->dialect = GPRS_NS2_DIALECT_UNDEF;
}
return CMD_SUCCESS;