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 000000 which results in 000-000, while 00f000 would
result in 000-00. IOW this is expected.

Change-Id: I7437dfaa586689e2bef0d4be6537e5577a8f6c26
This commit is contained in:
Neels Hofmeyr 2018-02-21 00:39:36 +01:00
parent f1474f5fc8
commit 6179f0ca36
3 changed files with 19 additions and 29 deletions

View File

@ -3,6 +3,7 @@
#include <osmocom/core/msgb.h>
#include <osmocom/gsm/gsm23003.h>
#include <osmocom/gprs/gprs_ns.h>
#include <osmocom/vty/command.h>
@ -101,8 +102,7 @@ struct gbproxy_config {
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_config {
};
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;

View File

@ -131,12 +131,11 @@ static int dump_peers(FILE *stream, int indent, time_t now,
struct gbproxy_patch_state *state = &peer->patch_state;
gsm48_parse_ra(&raid, peer->ra);
rc = fprintf(stream, "%*s NSEI %u, BVCI %u, %sblocked, "
"RAI %u-%u-%u-%u\n",
rc = fprintf(stream, "%*s NSEI %u, BVCI %u, %sblocked, RAI %s\n",
indent, "",
peer->nsei, peer->bvci,
peer->blocked ? "" : "not ",
raid.mcc, raid.mnc, raid.lac, raid.rac);
osmo_rai_name(&raid));
if (rc < 0)
return rc;
@ -1657,8 +1656,7 @@ static void test_gbproxy_ra_patching()
bssgp_nsi = nsi;
gbcfg.nsi = bssgp_nsi;
gbcfg.nsip_sgsn_nsei = SGSN_NSEI;
gbcfg.core_mcc = 123;
gbcfg.core_mnc = 456;
gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 };
gbcfg.core_apn = talloc_zero_size(NULL, 100);
gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
gbcfg.patch_ptmsi = 0;
@ -1998,8 +1996,7 @@ static void test_gbproxy_ptmsi_assignment()
bssgp_nsi = nsi;
gbcfg.nsi = bssgp_nsi;
gbcfg.nsip_sgsn_nsei = SGSN_NSEI;
gbcfg.core_mcc = 0;
gbcfg.core_mnc = 0;
gbcfg.core_plmn = (struct osmo_plmn_id){};
gbcfg.core_apn = talloc_zero_size(NULL, 100);
gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
gbcfg.patch_ptmsi = 0;
@ -2232,8 +2229,7 @@ static void test_gbproxy_ptmsi_patching()
bssgp_nsi = nsi;
gbcfg.nsi = bssgp_nsi;
gbcfg.nsip_sgsn_nsei = SGSN_NSEI;
gbcfg.core_mcc = 123;
gbcfg.core_mnc = 456;
gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 };
gbcfg.core_apn = talloc_zero_size(NULL, 100);
gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
gbcfg.patch_ptmsi = 1;
@ -2551,8 +2547,7 @@ static void test_gbproxy_ptmsi_patching_bad_cases()
bssgp_nsi = nsi;
gbcfg.nsi = bssgp_nsi;
gbcfg.nsip_sgsn_nsei = SGSN_NSEI;
gbcfg.core_mcc = 123;
gbcfg.core_mnc = 456;
gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 };
gbcfg.core_apn = talloc_zero_size(NULL, 100);
gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
gbcfg.patch_ptmsi = 1;
@ -2735,8 +2730,7 @@ static void test_gbproxy_imsi_acquisition()
bssgp_nsi = nsi;
gbcfg.nsi = bssgp_nsi;
gbcfg.nsip_sgsn_nsei = SGSN_NSEI;
gbcfg.core_mcc = 123;
gbcfg.core_mnc = 456;
gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 };
gbcfg.core_apn = talloc_zero_size(NULL, 100);
gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
gbcfg.patch_ptmsi = 1;
@ -3061,8 +3055,7 @@ static void test_gbproxy_secondary_sgsn()
bssgp_nsi = nsi;
gbcfg.nsi = bssgp_nsi;
gbcfg.nsip_sgsn_nsei = SGSN_NSEI;
gbcfg.core_mcc = 123;
gbcfg.core_mnc = 456;
gbcfg.core_plmn = (struct osmo_plmn_id){ .mcc = 123, .mnc = 456 };
gbcfg.core_apn = talloc_zero_size(NULL, 100);
gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
gbcfg.patch_ptmsi = 1;
@ -3540,8 +3533,7 @@ static void test_gbproxy_keep_info()
gbcfg.nsip_sgsn_nsei = SGSN_NSEI;
gbcfg.patch_ptmsi = 0;
gbcfg.acquire_imsi = 1;
gbcfg.core_mcc = 0;
gbcfg.core_mnc = 0;
gbcfg.core_plmn = (struct osmo_plmn_id){};
gbcfg.core_apn = NULL;
gbcfg.core_apn_size = 0;
gbcfg.route_to_sgsn2 = 0;
@ -4841,8 +4833,7 @@ static void test_gbproxy_stored_messages()
bssgp_nsi = nsi;
gbcfg.nsi = bssgp_nsi;
gbcfg.nsip_sgsn_nsei = SGSN_NSEI;
gbcfg.core_mcc = 0;
gbcfg.core_mnc = 0;
gbcfg.core_plmn = (struct osmo_plmn_id){};
gbcfg.core_apn = talloc_zero_size(NULL, 100);
gbcfg.core_apn_size = gprs_str_to_apn(gbcfg.core_apn, 100, "foo.bar");
gbcfg.patch_ptmsi = 0;

View File

@ -7249,7 +7249,7 @@ Test TLLI replacement:
Add TLLI 1, IMSI 1
Add TLLI 2, IMSI 1 (should replace TLLI 1)
Peers:
NSEI 0, BVCI 20, not blocked, RAI 0-0-0-0
NSEI 0, BVCI 20, not blocked, RAI 000-000-0-0
TLLI cache size : 1
TLLI-Cache: 1
TLLI c000162e, IMSI 03242526, AGE 0, IMSI matches
@ -7258,7 +7258,7 @@ Test IMSI replacement:
Add TLLI 1, IMSI 1
Add TLLI 1, IMSI 2 (should replace IMSI 1)
Peers:
NSEI 0, BVCI 20, not blocked, RAI 0-0-0-0
NSEI 0, BVCI 20, not blocked, RAI 000-000-0-0
TLLI cache size : 1
TLLI-Cache: 1
TLLI c00004d2, IMSI 06272829, AGE 0, IMSI matches
@ -7267,7 +7267,7 @@ Test TLLI expiry, max_len == 1:
Add TLLI 1, IMSI 1
Add TLLI 2, IMSI 2 (should replace IMSI 1)
Peers:
NSEI 0, BVCI 20, not blocked, RAI 0-0-0-0
NSEI 0, BVCI 20, not blocked, RAI 000-000-0-0
TLLI cache size : 1
TLLI-Cache: 1
TLLI c000162e, IMSI 06272829, AGE 0, IMSI matches
@ -7276,7 +7276,7 @@ Test TLLI expiry, max_age == 1:
Add TLLI 1, IMSI 1 (should expire after timeout)
Add TLLI 2, IMSI 2 (should not expire after timeout)
Peers:
NSEI 0, BVCI 20, not blocked, RAI 0-0-0-0
NSEI 0, BVCI 20, not blocked, RAI 000-000-0-0
TLLI cache size : 1
TLLI-Cache: 1
TLLI c000162e, IMSI 06272829, AGE 1, IMSI matches
@ -7286,7 +7286,7 @@ Test TLLI expiry, max_len == 2, max_age == 1:
Add TLLI 2, IMSI 2 (should expire after timeout)
Add TLLI 3, IMSI 3 (should not expire after timeout)
Peers:
NSEI 0, BVCI 20, not blocked, RAI 0-0-0-0
NSEI 0, BVCI 20, not blocked, RAI 000-000-0-0
TLLI cache size : 3
TLLI-Cache: 3
TLLI c0000d80, IMSI 12345678, AGE 0, IMSI matches
@ -7294,7 +7294,7 @@ Test TLLI expiry, max_len == 2, max_age == 1:
TLLI c00004d2, IMSI 03242526, AGE 2, IMSI matches
Remove stale TLLIs
Peers:
NSEI 0, BVCI 20, not blocked, RAI 0-0-0-0
NSEI 0, BVCI 20, not blocked, RAI 000-000-0-0
TLLI cache size : 1
TLLI-Cache: 1
TLLI c0000d80, IMSI 12345678, AGE 0, IMSI matches