pespin has uploaded this change for review.

View Change

xua: Split traffic mode readonly validation from internal state update

First validate the whole message, then once evyerthing is fine, act on
the message updating internal state.

Change-Id: I05ba891e774ebe341229b968c92e0383b6899bd6
---
M src/xua_asp_fsm.c
M src/xua_rkm.c
2 files changed, 31 insertions(+), 16 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/29/42529/1
diff --git a/src/xua_asp_fsm.c b/src/xua_asp_fsm.c
index 913f0e8..5cb28fc 100644
--- a/src/xua_asp_fsm.c
+++ b/src/xua_asp_fsm.c
@@ -641,6 +641,7 @@
struct xua_asp_fsm_priv *xafp = fi->priv;
struct osmo_ss7_asp *asp = xafp->asp;
struct osmo_ss7_as *as;
+ struct ss7_as_asp_assoc *assoc;
struct xua_msg_part *asp_id_ie;
struct xua_msg *xua_in;
uint32_t traf_mode = 0;
@@ -715,8 +716,16 @@
}

if (traf_mode) { /* if the peer has specified a traffic mode at all */
+ /* First validate peer not trying to establish an incompatible traffic mode: */
+ llist_for_each_entry(assoc, &asp->assoc_as_list, asp_entry) {
+ if (!osmo_ss7_as_tmode_compatible_xua(assoc->as, traf_mode)) {
+ peer_send_error(fi, M3UA_ERR_UNSUPP_TRAF_MOD_TYP);
+ return;
+ }
+ }
+
+ /* Update traffic mode in all AS associated with the ASP: */
enum osmo_ss7_as_traffic_mode tmode = osmo_ss7_tmode_from_xua(traf_mode);
- struct ss7_as_asp_assoc *assoc;
llist_for_each_entry(assoc, &asp->assoc_as_list, asp_entry) {
as = assoc->as;
if (!as->cfg.mode_set_by_peer && !as->cfg.mode_set_by_vty) {
@@ -724,9 +733,6 @@
LOGPAS(as, DLSS7, LOGL_INFO,
"ASPAC: Traffic mode set dynamically by peer to %s\n",
osmo_ss7_as_traffic_mode_name(as->cfg.mode));
- } else if (!osmo_ss7_as_tmode_compatible_xua(as, traf_mode)) {
- peer_send_error(fi, M3UA_ERR_UNSUPP_TRAF_MOD_TYP);
- return;
}
as->cfg.mode_set_by_peer = true;
}
diff --git a/src/xua_rkm.c b/src/xua_rkm.c
index 22bcafe..d6dfa51 100644
--- a/src/xua_rkm.c
+++ b/src/xua_rkm.c
@@ -172,6 +172,7 @@
uint32_t rk_id, rctx, _tmode, dpc;
enum osmo_ss7_as_traffic_mode tmode;
struct osmo_ss7_as *as;
+ struct ss7_as_asp_assoc *assoc;
struct osmo_ss7_route *rt;
char namebuf[32];
bool as_already_in_array;
@@ -264,19 +265,27 @@
}
if (_tmode) { /* if the peer has specified a traffic mode at all */
tmode = osmo_ss7_tmode_from_xua(_tmode);
- if (!as->cfg.mode_set_by_peer && !as->cfg.mode_set_by_vty) {
- as->cfg.mode = tmode;
- LOGPAS(as, DLSS7, LOGL_INFO,
- "RKM: Traffic mode set dynamically by peer to %s\n",
- osmo_ss7_as_traffic_mode_name(as->cfg.mode));
- /* verify if existing AS has same traffic-mode as new request (if any) */
- } else if (!osmo_ss7_as_tmode_compatible_xua(as, _tmode)) {
- LOGPASP(asp, DLSS7, LOGL_NOTICE, "RKM: Non-matching Traffic Mode %s\n",
- osmo_ss7_as_traffic_mode_name(tmode));
- msgb_append_reg_res(resp, rk_id, M3UA_RKM_REG_ERR_UNSUPP_TRAF_MODE, 0);
- return -1;
+ /* First validate peer not trying to establish an incompatible traffic mode: */
+ llist_for_each_entry(assoc, &asp->assoc_as_list, asp_entry) {
+ if (!osmo_ss7_as_tmode_compatible_xua(assoc->as, _tmode)) {
+ LOGPASP(asp, DLSS7, LOGL_NOTICE, "RKM: Non-matching Traffic Mode %s\n",
+ osmo_ss7_as_traffic_mode_name(tmode));
+ msgb_append_reg_res(resp, rk_id, M3UA_RKM_REG_ERR_UNSUPP_TRAF_MODE, 0);
+ return -1;
+ }
}
- as->cfg.mode_set_by_peer = true;
+
+ /* Update traffic mode in all AS associated with the ASP: */
+ llist_for_each_entry(assoc, &asp->assoc_as_list, asp_entry) {
+ as = assoc->as;
+ if (!as->cfg.mode_set_by_peer && !as->cfg.mode_set_by_vty) {
+ as->cfg.mode = tmode;
+ LOGPAS(as, DLSS7, LOGL_INFO,
+ "RKM: Traffic mode set dynamically by peer to %s\n",
+ osmo_ss7_as_traffic_mode_name(as->cfg.mode));
+ }
+ as->cfg.mode_set_by_peer = true;
+ }
}
} else {
/* Create an AS for this routing key */

To view, visit change 42529. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: I05ba891e774ebe341229b968c92e0383b6899bd6
Gerrit-Change-Number: 42529
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>