summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2014-09-15 14:38:37 +0200
committerJacob Erlbeck <jerlbeck@sysmocom.de>2014-09-18 13:46:09 +0200
commitcba4c0cc600da7b9548e9267cb0486806820a9ef (patch)
tree924528cef215b3f5c3827ad055e869b5d0dda225
parent772a22b529807b1fb60c5d146d9d1a9b4fa7f6b0 (diff)
gbproxy: Only patch what has been configured
Currently when patching is basically enabled P-TMSI and TLLI gets patched even when P-TMSI patching is not enabled. Albeit the result is correct in this case (the same value is re-written), the counter shows unexpected results. This patch adds configuration checks for P-TMSI and TLLI patching. It also reorders the code of gbproxy_patch_raid to return early if there is nothing to patch. Sponsored-by: On-Waves ehf
-rw-r--r--openbsc/src/gprs/gb_proxy_patch.c42
-rw-r--r--openbsc/tests/gbproxy/gbproxy_test.ok5
2 files changed, 22 insertions, 25 deletions
diff --git a/openbsc/src/gprs/gb_proxy_patch.c b/openbsc/src/gprs/gb_proxy_patch.c
index caedf8965..bf0f22e08 100644
--- a/openbsc/src/gprs/gb_proxy_patch.c
+++ b/openbsc/src/gprs/gb_proxy_patch.c
@@ -37,6 +37,13 @@ static void gbproxy_patch_raid(uint8_t *raid_enc, struct gbproxy_peer *peer,
int old_mcc;
int old_mnc;
struct gprs_ra_id raid;
+ enum gbproxy_peer_ctr counter =
+ to_bss ?
+ GBPROX_PEER_CTR_RAID_PATCHED_SGSN :
+ GBPROX_PEER_CTR_RAID_PATCHED_BSS;
+
+ if (!state->local_mcc || !state->local_mnc)
+ return;
gsm48_parse_ra(&raid, raid_enc);
@@ -59,23 +66,16 @@ static void gbproxy_patch_raid(uint8_t *raid_enc, struct gbproxy_peer *peer,
raid.mnc = state->local_mnc;
}
- if (state->local_mcc || state->local_mnc) {
- enum gbproxy_peer_ctr counter =
- to_bss ?
- GBPROX_PEER_CTR_RAID_PATCHED_SGSN :
- GBPROX_PEER_CTR_RAID_PATCHED_BSS;
-
- LOGP(DGPRS, LOGL_DEBUG,
- "Patching %s to %s: "
- "%d-%d-%d-%d -> %d-%d-%d-%d\n",
- log_text,
- to_bss ? "BSS" : "SGSN",
- old_mcc, old_mnc, raid.lac, raid.rac,
- raid.mcc, raid.mnc, raid.lac, raid.rac);
-
- gsm48_construct_ra(raid_enc, &raid);
- rate_ctr_inc(&peer->ctrg->ctr[counter]);
- }
+ LOGP(DGPRS, LOGL_DEBUG,
+ "Patching %s to %s: "
+ "%d-%d-%d-%d -> %d-%d-%d-%d\n",
+ log_text,
+ to_bss ? "BSS" : "SGSN",
+ old_mcc, old_mnc, raid.lac, raid.rac,
+ raid.mcc, raid.mnc, raid.lac, raid.rac);
+
+ gsm48_construct_ra(raid_enc, &raid);
+ rate_ctr_inc(&peer->ctrg->ctr[counter]);
}
static void gbproxy_patch_apn_ie(struct msgb *msg,
@@ -200,7 +200,7 @@ int gbproxy_patch_llc(struct msgb *msg, uint8_t *llc, size_t llc_len,
int fcs;
if (parse_ctx->ptmsi_enc && tlli_info &&
- !parse_ctx->old_raid_is_foreign) {
+ !parse_ctx->old_raid_is_foreign && peer->cfg->patch_ptmsi) {
uint32_t ptmsi;
if (parse_ctx->to_bss)
ptmsi = tlli_info->tlli.ptmsi;
@@ -216,7 +216,7 @@ int gbproxy_patch_llc(struct msgb *msg, uint8_t *llc, size_t llc_len,
}
}
- if (parse_ctx->new_ptmsi_enc && tlli_info) {
+ if (parse_ctx->new_ptmsi_enc && tlli_info && peer->cfg->patch_ptmsi) {
uint32_t ptmsi;
if (parse_ctx->to_bss)
ptmsi = tlli_info->tlli.ptmsi;
@@ -245,7 +245,7 @@ int gbproxy_patch_llc(struct msgb *msg, uint8_t *llc, size_t llc_len,
if (parse_ctx->apn_ie &&
peer->cfg->core_apn &&
!parse_ctx->to_bss &&
- gbproxy_check_tlli(peer, tlli_info)) {
+ gbproxy_check_tlli(peer, tlli_info) && peer->cfg->core_apn) {
size_t new_len;
gbproxy_patch_apn_ie(msg,
parse_ctx->apn_ie, parse_ctx->apn_ie_len,
@@ -308,7 +308,7 @@ void gbproxy_patch_bssgp(struct msgb *msg, uint8_t *bssgp, size_t bssgp_len,
if (!tlli_info)
return;
- if (parse_ctx->tlli_enc) {
+ if (parse_ctx->tlli_enc && peer->cfg->patch_ptmsi) {
uint32_t tlli = gbproxy_map_tlli(parse_ctx->tlli,
tlli_info, parse_ctx->to_bss);
diff --git a/openbsc/tests/gbproxy/gbproxy_test.ok b/openbsc/tests/gbproxy/gbproxy_test.ok
index ffa6b57f0..80a691e93 100644
--- a/openbsc/tests/gbproxy/gbproxy_test.ok
+++ b/openbsc/tests/gbproxy/gbproxy_test.ok
@@ -4663,7 +4663,7 @@ CALLBACK, event 0, msg length 31, bvci 0x1002
NS UNITDATA MESSAGE to SGSN, BVCI 0x1002, msg length 75 (gprs_ns_sendmsg)
MESSAGE to SGSN at 0x05060708:32000, msg length 79
-00 00 10 02 01 af e2 b7 00 00 00 04 08 88 11 22 33 40 50 60 12 34 00 80 0e 00 34 01 c0 39 08 01 02 f5 e0 21 08 02 05 f4 ef e2 b7 00 11 22 33 40 50 60 19 18 b3 43 2b 25 96 62 00 60 80 9a c2 c6 62 00 60 80 ba c8 c6 62 00 60 80 00 e4 85 12
+00 00 10 02 01 af e2 b7 00 00 00 04 08 88 11 22 33 40 50 60 12 34 00 80 0e 00 34 01 c0 39 08 01 02 f5 e0 21 08 02 05 f4 fb c5 46 79 11 22 33 40 50 60 19 18 b3 43 2b 25 96 62 00 60 80 9a c2 c6 62 00 60 80 ba c8 c6 62 00 60 80 00 e4 e8 65
NS UNITDATA MESSAGE to SGSN, BVCI 0x1002, msg length 31 (gprs_ns_sendmsg)
MESSAGE to SGSN at 0x05060708:32000, msg length 35
@@ -4673,7 +4673,6 @@ result (ATTACH COMPLETE) = 35
Peers:
NSEI 4096, BVCI 4098, not blocked, RAI 112-332-16464-96
- P-TMSI patched (BSS ): 1
Attach Request count : 5
TLLI cache size : 2
TLLI-Cache: 2
@@ -4693,7 +4692,6 @@ result (DETACH REQ) = 73
Peers:
NSEI 4096, BVCI 4098, not blocked, RAI 112-332-16464-96
- P-TMSI patched (BSS ): 1
Attach Request count : 5
TLLI cache size : 2
TLLI-Cache: 2
@@ -4713,7 +4711,6 @@ result (DETACH ACC) = 35
Peers:
NSEI 4096, BVCI 4098, not blocked, RAI 112-332-16464-96
- P-TMSI patched (BSS ): 1
Attach Request count : 5
TLLI cache size : 1
TLLI-Cache: 1