[PATCH] osmo-sgsn[master]: implement support for 3-digit MNC with leading zeros

2018-02-27 Thread Neels Hofmeyr
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/6672

to look at the new patch set (#2).

implement support for 3-digit MNC with leading zeros

Add 3-digit flags and use the new RAI and LAI API from libosmocore throughout
the code base to be able to handle an MNC < 100 that has three digits (leading
zeros).

Note that in gbproxy_test.ok, 0-0 changes to 000-000 instead of 000-00, because
the parsed ra buffer is 00 which results in 000-000, while 00f000 would
result in 000-00. IOW this is expected.

Change-Id: I7437dfaa586689e2bef0d4be6537e5577a8f6c26
---
M include/osmocom/sgsn/gb_proxy.h
M src/gprs/gb_proxy.c
M src/gprs/gb_proxy_patch.c
M src/gprs/gb_proxy_vty.c
M src/gprs/gprs_gb_parse.c
M src/gprs/gprs_gmm.c
M src/gprs/gprs_utils.c
M src/gprs/sgsn_auth.c
M src/gprs/sgsn_vty.c
M tests/gbproxy/gbproxy_test.c
M tests/gbproxy/gbproxy_test.ok
11 files changed, 103 insertions(+), 105 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/72/6672/2

diff --git a/include/osmocom/sgsn/gb_proxy.h b/include/osmocom/sgsn/gb_proxy.h
index e10894f..2540a7e 100644
--- a/include/osmocom/sgsn/gb_proxy.h
+++ b/include/osmocom/sgsn/gb_proxy.h
@@ -3,6 +3,7 @@
 
 
 #include 
+#include 
 
 #include 
 #include 
@@ -101,8 +102,7 @@
struct rate_ctr_group *ctrg;
 
/* force mcc/mnc */
-   int core_mnc;
-   int core_mcc;
+   struct osmo_plmn_id core_plmn;
uint8_t* core_apn;
size_t core_apn_size;
int tlli_max_age;
@@ -120,8 +120,7 @@
 };
 
 struct gbproxy_patch_state {
-   int local_mnc;
-   int local_mcc;
+   struct osmo_plmn_id local_plmn;
 
/* List of TLLIs for which patching is enabled */
struct llist_head logical_links;
diff --git a/src/gprs/gb_proxy.c b/src/gprs/gb_proxy.c
index 63c3a61..7d21518 100644
--- a/src/gprs/gb_proxy.c
+++ b/src/gprs/gb_proxy.c
@@ -192,8 +192,7 @@
   const char *log_text)
 {
struct gbproxy_patch_state *state = >patch_state;
-   const int old_local_mcc = state->local_mcc;
-   const int old_local_mnc = state->local_mnc;
+   const struct osmo_plmn_id old_plmn = state->local_plmn;
struct gprs_ra_id raid;
 
if (!raid_enc)
@@ -202,28 +201,31 @@
gsm48_parse_ra(, raid_enc);
 
/* save source side MCC/MNC */
-   if (!peer->cfg->core_mcc || raid.mcc == peer->cfg->core_mcc) {
-   state->local_mcc = 0;
+   if (!peer->cfg->core_plmn.mcc || raid.mcc == peer->cfg->core_plmn.mcc) {
+   state->local_plmn.mcc = 0;
} else {
-   state->local_mcc = raid.mcc;
+   state->local_plmn.mcc = raid.mcc;
}
 
-   if (!peer->cfg->core_mnc || raid.mnc == peer->cfg->core_mnc) {
-   state->local_mnc = 0;
+   if (!peer->cfg->core_plmn.mnc
+   || !osmo_mnc_cmp(raid.mnc, raid.mnc_3_digits,
+peer->cfg->core_plmn.mnc, 
peer->cfg->core_plmn.mnc_3_digits)) {
+   state->local_plmn.mnc = 0;
+   state->local_plmn.mnc_3_digits = false;
} else {
-   state->local_mnc = raid.mnc;
+   state->local_plmn.mnc = raid.mnc;
+   state->local_plmn.mnc_3_digits = raid.mnc_3_digits;
}
 
-   if (old_local_mcc != state->local_mcc ||
-   old_local_mnc != state->local_mnc)
+   if (osmo_plmn_cmp(_plmn, >local_plmn))
LOGP(DGPRS, LOGL_NOTICE,
 "Patching RAID %sactivated, msg: %s, "
-"local: %d-%d, core: %d-%d\n",
-state->local_mcc || state->local_mnc ?
+"local: %s, core: %s\n",
+state->local_plmn.mcc || state->local_plmn.mnc ?
 "" : "de",
 log_text,
-state->local_mcc, state->local_mnc,
-peer->cfg->core_mcc, peer->cfg->core_mnc);
+osmo_plmn_name(>local_plmn),
+osmo_plmn_name2(>cfg->core_plmn));
 }
 
 uint32_t gbproxy_make_bss_ptmsi(struct gbproxy_peer *peer,
@@ -559,7 +561,7 @@
struct gbproxy_link_info *link_info = NULL;
uint32_t sgsn_nsei = cfg->nsip_sgsn_nsei;
 
-   if (!cfg->core_mcc && !cfg->core_mnc && !cfg->core_apn &&
+   if (!cfg->core_plmn.mcc && !cfg->core_plmn.mnc && !cfg->core_apn &&
!cfg->acquire_imsi && !cfg->patch_ptmsi && !cfg->route_to_sgsn2)
return 1;
 
@@ -665,7 +667,7 @@
return 1;
 }
 
-/* patch BSSGP message to use core_mcc/mnc on the SGSN side */
+/* patch BSSGP message to use core_plmn.mcc/mnc on the SGSN side */
 static void gbprox_process_bssgp_dl(struct gbproxy_config *cfg,
struct msgb *msg,
struct gbproxy_peer *peer)
@@ -677,7 +679,7 @@
struct timespec ts = {0,};
struct gbproxy_link_info *link_info = 

[PATCH] osmo-sgsn[master]: implement support for 3-digit MNC with leading zeros

2018-02-21 Thread Neels Hofmeyr

Review at  https://gerrit.osmocom.org/6672

implement support for 3-digit MNC with leading zeros

Add 3-digit flags and use the new RAI and LAI API from libosmocore throughout
the code base to be able to handle an MNC < 100 that has three digits (leading
zeros).

Note that in gbproxy_test.ok, 0-0 changes to 000-000 instead of 000-00, because
the parsed ra buffer is 00 which results in 000-000, while 00f000 would
result in 000-00. IOW this is expected.

Change-Id: I7437dfaa586689e2bef0d4be6537e5577a8f6c26
---
M include/osmocom/sgsn/gb_proxy.h
M src/gprs/gb_proxy.c
M src/gprs/gb_proxy_patch.c
M src/gprs/gb_proxy_vty.c
M src/gprs/gprs_gb_parse.c
M src/gprs/gprs_gmm.c
M src/gprs/gprs_utils.c
M src/gprs/sgsn_auth.c
M src/gprs/sgsn_vty.c
M tests/gbproxy/gbproxy_test.c
M tests/gbproxy/gbproxy_test.ok
11 files changed, 70 insertions(+), 56 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/72/6672/1

diff --git a/include/osmocom/sgsn/gb_proxy.h b/include/osmocom/sgsn/gb_proxy.h
index e10894f..f4d82a0 100644
--- a/include/osmocom/sgsn/gb_proxy.h
+++ b/include/osmocom/sgsn/gb_proxy.h
@@ -102,6 +102,7 @@
 
/* force mcc/mnc */
int core_mnc;
+   bool core_mnc_3_digits;
int core_mcc;
uint8_t* core_apn;
size_t core_apn_size;
@@ -121,6 +122,7 @@
 
 struct gbproxy_patch_state {
int local_mnc;
+   bool local_mnc_3_digits;
int local_mcc;
 
/* List of TLLIs for which patching is enabled */
diff --git a/src/gprs/gb_proxy.c b/src/gprs/gb_proxy.c
index 63c3a61..68d9b15 100644
--- a/src/gprs/gb_proxy.c
+++ b/src/gprs/gb_proxy.c
@@ -194,6 +194,7 @@
struct gbproxy_patch_state *state = >patch_state;
const int old_local_mcc = state->local_mcc;
const int old_local_mnc = state->local_mnc;
+   const bool old_local_mnc_3_digits = state->local_mnc_3_digits;
struct gprs_ra_id raid;
 
if (!raid_enc)
@@ -208,22 +209,28 @@
state->local_mcc = raid.mcc;
}
 
-   if (!peer->cfg->core_mnc || raid.mnc == peer->cfg->core_mnc) {
+   if (!peer->cfg->core_mnc
+   || !gsm48_mnc_cmp(raid.mnc, raid.mnc_3_digits,
+ peer->cfg->core_mnc, 
peer->cfg->core_mnc_3_digits)) {
state->local_mnc = 0;
+   state->local_mnc_3_digits = false;
} else {
state->local_mnc = raid.mnc;
+   state->local_mnc_3_digits = raid.mnc_3_digits;
}
 
-   if (old_local_mcc != state->local_mcc ||
-   old_local_mnc != state->local_mnc)
+   if (old_local_mcc != state->local_mcc
+   || gsm48_mnc_cmp(old_local_mnc, old_local_mnc_3_digits,
+state->local_mnc, state->local_mnc_3_digits))
LOGP(DGPRS, LOGL_NOTICE,
 "Patching RAID %sactivated, msg: %s, "
-"local: %d-%d, core: %d-%d\n",
+"local: %s, core: %s\n",
 state->local_mcc || state->local_mnc ?
 "" : "de",
 log_text,
-state->local_mcc, state->local_mnc,
-peer->cfg->core_mcc, peer->cfg->core_mnc);
+osmo_mcc_mnc_name(state->local_mcc, state->local_mnc, 
state->local_mnc_3_digits),
+osmo_mcc_mnc_name2(peer->cfg->core_mcc, 
peer->cfg->core_mnc,
+   peer->cfg->core_mnc_3_digits));
 }
 
 uint32_t gbproxy_make_bss_ptmsi(struct gbproxy_peer *peer,
@@ -994,9 +1001,8 @@
sizeof(from_peer->ra));
gsm48_parse_ra(, from_peer->ra);
LOGP(DGPRS, LOGL_INFO, "NSEI=%u BSSGP SUSPEND/RESUME "
-   "RAI snooping: RAI %u-%u-%u-%u behind BVCI=%u\n",
-   nsei, raid.mcc, raid.mnc, raid.lac,
-   raid.rac , from_peer->bvci);
+   "RAI snooping: RAI %s behind BVCI=%u\n",
+   nsei, osmo_rai_name(), from_peer->bvci);
/* FIXME: This only supports one BSS per RA */
break;
case BSSGP_PDUT_BVC_RESET:
@@ -1037,10 +1043,8 @@
TLVP_VAL(, BSSGP_IE_CELL_ID),
sizeof(from_peer->ra));
gsm48_parse_ra(, from_peer->ra);
-   LOGP(DGPRS, LOGL_INFO, "NSEI=%u/BVCI=%u "
-"Cell ID %u-%u-%u-%u\n", nsei,
-bvci, raid.mcc, raid.mnc, raid.lac,
-raid.rac);
+   LOGP(DGPRS, LOGL_INFO, "NSEI=%u/BVCI=%u Cell ID 
%s\n",
+nsei, bvci, osmo_rai_name());
}
if (cfg->route_to_sgsn2)
copy_to_sgsn2 = 1;
diff --git a/src/gprs/gb_proxy_patch.c