gbproxy: Move peer definitions to gb_proxy_peer.c
This patch moves the peer related definitions from gb_proxy.c to gb_proxy_peer.c and adjusts the prefix of each global symbol to gbproxy_: Peer definitions (prefix adjusted to gbproxy_): peer_ctr_description -> gprs/gb_proxy_peer.c (static) peer_ctrg_desc -> gprs/gb_proxy_peer.c (static) *peer_by_* -> gprs/gb_proxy_peer.c gbproxy_peer_alloc -> gprs/gb_proxy_peer.c gbproxy_peer_free -> gprs/gb_proxy_peer.c gbprox_cleanup_peers -> gprs/gb_proxy_peer.c Sponsored-by: On-Waves ehf
This commit is contained in:
parent
9114bee242
commit
5f1faa3cd2
|
@ -12,6 +12,7 @@
|
|||
|
||||
struct rate_ctr_group;
|
||||
struct gprs_gb_parse_context;
|
||||
struct tlv_parsed;
|
||||
|
||||
enum gbproxy_patch_mode {
|
||||
GBPROX_PATCH_DEFAULT,
|
||||
|
@ -167,13 +168,6 @@ int gbprox_reset_persistent_nsvcs(struct gprs_ns_inst *nsi);
|
|||
|
||||
void gbprox_reset(struct gbproxy_config *cfg);
|
||||
|
||||
int gbprox_cleanup_peers(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci);
|
||||
|
||||
struct gbproxy_peer *gbprox_peer_by_nsei(struct gbproxy_config *cfg, uint16_t nsei);
|
||||
|
||||
struct gbproxy_peer *gbproxy_peer_alloc(struct gbproxy_config *cfg, uint16_t bvci);
|
||||
void gbproxy_peer_free(struct gbproxy_peer *peer);
|
||||
|
||||
/* TLLI state handling */
|
||||
void gbproxy_delete_tllis(struct gbproxy_peer *peer);
|
||||
int gbproxy_check_tlli(struct gbproxy_peer *peer, uint32_t tlli);
|
||||
|
@ -237,4 +231,22 @@ void gbproxy_clear_patch_filter(struct gbproxy_config *cfg);
|
|||
int gbproxy_check_imsi(
|
||||
struct gbproxy_peer *peer, const uint8_t *imsi, size_t imsi_len);
|
||||
|
||||
/* Peer handling */
|
||||
struct gbproxy_peer *gbproxy_peer_by_bvci(
|
||||
struct gbproxy_config *cfg, uint16_t bvci) __attribute__((nonnull));
|
||||
struct gbproxy_peer *gbproxy_peer_by_nsei(
|
||||
struct gbproxy_config *cfg, uint16_t nsei) __attribute__((nonnull));
|
||||
struct gbproxy_peer *gbproxy_peer_by_rai(
|
||||
struct gbproxy_config *cfg, const uint8_t *ra) __attribute__((nonnull));
|
||||
struct gbproxy_peer *gbproxy_peer_by_lai(
|
||||
struct gbproxy_config *cfg, const uint8_t *la) __attribute__((nonnull));
|
||||
struct gbproxy_peer *gbproxy_peer_by_bssgp_tlv(
|
||||
struct gbproxy_config *cfg, struct tlv_parsed *tp)
|
||||
__attribute__((nonnull));
|
||||
struct gbproxy_peer *gbproxy_peer_alloc(struct gbproxy_config *cfg, uint16_t bvci)
|
||||
__attribute__((nonnull));
|
||||
void gbproxy_peer_free(struct gbproxy_peer *peer) __attribute__((nonnull));
|
||||
int gbproxy_cleanup_peers(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci)
|
||||
__attribute__((nonnull));
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,7 +14,7 @@ bin_PROGRAMS = osmo-gbproxy
|
|||
endif
|
||||
|
||||
osmo_gbproxy_SOURCES = gb_proxy.c gb_proxy_main.c gb_proxy_vty.c \
|
||||
gb_proxy_patch.c gb_proxy_tlli.c \
|
||||
gb_proxy_patch.c gb_proxy_tlli.c gb_proxy_peer.c \
|
||||
gprs_gb_parse.c gprs_llc_parse.c crc24.c gprs_utils.c
|
||||
osmo_gbproxy_LDADD = $(top_builddir)/src/libcommon/libcommon.a \
|
||||
$(OSMO_LIBS)
|
||||
|
|
|
@ -72,91 +72,6 @@ static const struct rate_ctr_group_desc global_ctrg_desc = {
|
|||
.ctr_desc = global_ctr_description,
|
||||
};
|
||||
|
||||
static const struct rate_ctr_desc peer_ctr_description[] = {
|
||||
{ "blocked", "BVC Block " },
|
||||
{ "unblocked", "BVC Unblock " },
|
||||
{ "dropped", "BVC blocked, dropped packet " },
|
||||
{ "inv-nsei", "NSEI mismatch " },
|
||||
{ "tx-err", "NS Transmission error " },
|
||||
{ "raid-mod.bss", "RAID patched (BSS )" },
|
||||
{ "raid-mod.sgsn", "RAID patched (SGSN)" },
|
||||
{ "apn-mod.sgsn", "APN patched " },
|
||||
{ "tlli-mod.bss", "TLLI patched (BSS )" },
|
||||
{ "tlli-mod.sgsn", "TLLI patched (SGSN)" },
|
||||
{ "ptmsi-mod.bss", "P-TMSI patched (BSS )" },
|
||||
{ "ptmsi-mod.sgsn","P-TMSI patched (SGSN)" },
|
||||
{ "mod-crypt-err", "Patch error: encrypted " },
|
||||
{ "mod-err", "Patch error: other " },
|
||||
{ "attach-reqs", "Attach Request count " },
|
||||
{ "attach-rejs", "Attach Reject count " },
|
||||
{ "tlli-unknown", "TLLI from SGSN unknown " },
|
||||
{ "tlli-cache", "TLLI cache size " },
|
||||
};
|
||||
|
||||
static const struct rate_ctr_group_desc peer_ctrg_desc = {
|
||||
.group_name_prefix = "gbproxy.peer",
|
||||
.group_description = "GBProxy Peer Statistics",
|
||||
.num_ctr = ARRAY_SIZE(peer_ctr_description),
|
||||
.ctr_desc = peer_ctr_description,
|
||||
};
|
||||
|
||||
|
||||
/* Find the gbprox_peer by its BVCI */
|
||||
static struct gbproxy_peer *peer_by_bvci(struct gbproxy_config *cfg, uint16_t bvci)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
llist_for_each_entry(peer, &cfg->bts_peers, list) {
|
||||
if (peer->bvci == bvci)
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Find the gbprox_peer by its NSEI */
|
||||
struct gbproxy_peer *gbprox_peer_by_nsei(struct gbproxy_config *cfg, uint16_t nsei)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
llist_for_each_entry(peer, &cfg->bts_peers, list) {
|
||||
if (peer->nsei == nsei)
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* look-up a peer by its Routeing Area Identification (RAI) */
|
||||
static struct gbproxy_peer *peer_by_rai(struct gbproxy_config *cfg, const uint8_t *ra)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
llist_for_each_entry(peer, &cfg->bts_peers, list) {
|
||||
if (!memcmp(peer->ra, ra, 6))
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* look-up a peer by its Location Area Identification (LAI) */
|
||||
static struct gbproxy_peer *peer_by_lai(struct gbproxy_config *cfg, const uint8_t *la)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
llist_for_each_entry(peer, &cfg->bts_peers, list) {
|
||||
if (!memcmp(peer->ra, la, 5))
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* look-up a peer by its Location Area Code (LAC) */
|
||||
static struct gbproxy_peer *peer_by_lac(struct gbproxy_config *cfg, const uint8_t *la)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
llist_for_each_entry(peer, &cfg->bts_peers, list) {
|
||||
if (!memcmp(peer->ra + 3, la + 3, 2))
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static int check_peer_nsei(struct gbproxy_peer *peer, uint16_t nsei)
|
||||
{
|
||||
if (peer->nsei != nsei) {
|
||||
|
@ -170,37 +85,6 @@ static int check_peer_nsei(struct gbproxy_peer *peer, uint16_t nsei)
|
|||
return 1;
|
||||
}
|
||||
|
||||
struct gbproxy_peer *gbproxy_peer_alloc(struct gbproxy_config *cfg, uint16_t bvci)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
|
||||
peer = talloc_zero(tall_bsc_ctx, struct gbproxy_peer);
|
||||
if (!peer)
|
||||
return NULL;
|
||||
|
||||
peer->bvci = bvci;
|
||||
peer->ctrg = rate_ctr_group_alloc(peer, &peer_ctrg_desc, bvci);
|
||||
peer->cfg = cfg;
|
||||
|
||||
llist_add(&peer->list, &cfg->bts_peers);
|
||||
|
||||
INIT_LLIST_HEAD(&peer->patch_state.enabled_tllis);
|
||||
|
||||
return peer;
|
||||
}
|
||||
|
||||
void gbproxy_peer_free(struct gbproxy_peer *peer)
|
||||
{
|
||||
llist_del(&peer->list);
|
||||
|
||||
gbproxy_delete_tllis(peer);
|
||||
|
||||
rate_ctr_group_free(peer->ctrg);
|
||||
peer->ctrg = NULL;
|
||||
|
||||
talloc_free(peer);
|
||||
}
|
||||
|
||||
/* strip off the NS header */
|
||||
static void strip_ns_hdr(struct msgb *msg)
|
||||
{
|
||||
|
@ -248,32 +132,6 @@ static void gbprox_update_current_raid(uint8_t *raid_enc,
|
|||
peer->cfg->core_mcc, peer->cfg->core_mnc);
|
||||
}
|
||||
|
||||
struct gbproxy_peer *peer_by_bssgp_tlv(struct gbproxy_config *cfg, struct tlv_parsed *tp)
|
||||
{
|
||||
if (TLVP_PRESENT(tp, BSSGP_IE_BVCI)) {
|
||||
uint16_t bvci;
|
||||
|
||||
bvci = ntohs(tlvp_val16_unal(tp, BSSGP_IE_BVCI));
|
||||
if (bvci >= 2)
|
||||
return peer_by_bvci(cfg, bvci);
|
||||
}
|
||||
|
||||
if (TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) {
|
||||
uint8_t *rai = (uint8_t *)TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA);
|
||||
/* Only compare LAC part, since MCC/MNC are possibly patched.
|
||||
* Since the LAC of different BSS must be different when
|
||||
* MCC/MNC are patched, collisions shouldn't happen. */
|
||||
return peer_by_lac(cfg, rai);
|
||||
}
|
||||
|
||||
if (TLVP_PRESENT(tp, BSSGP_IE_LOCATION_AREA)) {
|
||||
uint8_t *lai = (uint8_t *)TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA);
|
||||
return peer_by_lac(cfg, lai);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t gbproxy_make_bss_ptmsi(struct gbproxy_peer *peer,
|
||||
uint32_t sgsn_ptmsi)
|
||||
{
|
||||
|
@ -348,13 +206,13 @@ static void gbprox_process_bssgp_ul(struct gbproxy_config *cfg,
|
|||
|
||||
/* Get peer */
|
||||
if (!peer && msgb_bvci(msg) >= 2)
|
||||
peer = peer_by_bvci(cfg, msgb_bvci(msg));
|
||||
peer = gbproxy_peer_by_bvci(cfg, msgb_bvci(msg));
|
||||
|
||||
if (!peer)
|
||||
peer = gbprox_peer_by_nsei(cfg, msgb_nsei(msg));
|
||||
peer = gbproxy_peer_by_nsei(cfg, msgb_nsei(msg));
|
||||
|
||||
if (!peer)
|
||||
peer = peer_by_bssgp_tlv(cfg, &parse_ctx.bssgp_tp);
|
||||
peer = gbproxy_peer_by_bssgp_tlv(cfg, &parse_ctx.bssgp_tp);
|
||||
|
||||
if (!peer) {
|
||||
LOGP(DLLC, LOGL_INFO,
|
||||
|
@ -425,10 +283,10 @@ static void gbprox_process_bssgp_dl(struct gbproxy_config *cfg,
|
|||
}
|
||||
|
||||
if (!peer && msgb_bvci(msg) >= 2)
|
||||
peer = peer_by_bvci(cfg, msgb_bvci(msg));
|
||||
peer = gbproxy_peer_by_bvci(cfg, msgb_bvci(msg));
|
||||
|
||||
if (!peer)
|
||||
peer = peer_by_bssgp_tlv(cfg, &parse_ctx.bssgp_tp);
|
||||
peer = gbproxy_peer_by_bssgp_tlv(cfg, &parse_ctx.bssgp_tp);
|
||||
|
||||
if (!peer) {
|
||||
LOGP(DLLC, LOGL_INFO,
|
||||
|
@ -520,7 +378,7 @@ static int block_unblock_peer(struct gbproxy_config *cfg, uint16_t ptp_bvci, uin
|
|||
{
|
||||
struct gbproxy_peer *peer;
|
||||
|
||||
peer = peer_by_bvci(cfg, ptp_bvci);
|
||||
peer = gbproxy_peer_by_bvci(cfg, ptp_bvci);
|
||||
if (!peer) {
|
||||
LOGP(DGPRS, LOGL_ERROR, "BVCI=%u: Cannot find BSS\n",
|
||||
ptp_bvci);
|
||||
|
@ -550,7 +408,7 @@ static int gbprox_relay2bvci(struct gbproxy_config *cfg, struct msgb *msg, uint1
|
|||
{
|
||||
struct gbproxy_peer *peer;
|
||||
|
||||
peer = peer_by_bvci(cfg, ptp_bvci);
|
||||
peer = gbproxy_peer_by_bvci(cfg, ptp_bvci);
|
||||
if (!peer) {
|
||||
LOGP(DGPRS, LOGL_ERROR, "BVCI=%u: Cannot find BSS\n",
|
||||
ptp_bvci);
|
||||
|
@ -605,7 +463,7 @@ static int gbprox_rx_sig_from_bss(struct gbproxy_config *cfg,
|
|||
* BSSGP */
|
||||
if (!TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA))
|
||||
goto err_mand_ie;
|
||||
from_peer = gbprox_peer_by_nsei(cfg, nsei);
|
||||
from_peer = gbproxy_peer_by_nsei(cfg, nsei);
|
||||
if (!from_peer)
|
||||
goto err_no_peer;
|
||||
memcpy(from_peer->ra, TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA),
|
||||
|
@ -632,7 +490,7 @@ static int gbprox_rx_sig_from_bss(struct gbproxy_config *cfg,
|
|||
return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK,
|
||||
nsei, 0, ns_bvci);
|
||||
}
|
||||
from_peer = peer_by_bvci(cfg, bvci);
|
||||
from_peer = gbproxy_peer_by_bvci(cfg, bvci);
|
||||
if (!from_peer) {
|
||||
/* if a PTP-BVC is reset, and we don't know that
|
||||
* PTP-BVCI yet, we should allocate a new peer */
|
||||
|
@ -694,12 +552,12 @@ static int gbprox_rx_paging(struct gbproxy_config *cfg, struct msgb *msg, struct
|
|||
bvci);
|
||||
errctr = GBPROX_GLOB_CTR_OTHER_ERR;
|
||||
} else if (TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) {
|
||||
peer = peer_by_rai(cfg, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA));
|
||||
peer = gbproxy_peer_by_rai(cfg, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA));
|
||||
LOGPC(DGPRS, LOGL_INFO, "routing by RAI to peer BVCI=%u\n",
|
||||
peer ? peer->bvci : -1);
|
||||
errctr = GBPROX_GLOB_CTR_INV_RAI;
|
||||
} else if (TLVP_PRESENT(tp, BSSGP_IE_LOCATION_AREA)) {
|
||||
peer = peer_by_lai(cfg, TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA));
|
||||
peer = gbproxy_peer_by_lai(cfg, TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA));
|
||||
LOGPC(DGPRS, LOGL_INFO, "routing by LAI to peer BVCI=%u\n",
|
||||
peer ? peer->bvci : -1);
|
||||
errctr = GBPROX_GLOB_CTR_INV_LAI;
|
||||
|
@ -734,7 +592,7 @@ static int rx_reset_from_sgsn(struct gbproxy_config *cfg,
|
|||
if (ptp_bvci >= 2) {
|
||||
/* A reset for a PTP BVC was received, forward it to its
|
||||
* respective peer */
|
||||
peer = peer_by_bvci(cfg, ptp_bvci);
|
||||
peer = gbproxy_peer_by_bvci(cfg, ptp_bvci);
|
||||
if (!peer) {
|
||||
LOGP(DGPRS, LOGL_ERROR, "NSEI=%u BVCI=%u: Cannot find BSS\n",
|
||||
nsei, ptp_bvci);
|
||||
|
@ -830,7 +688,7 @@ static int gbprox_rx_sig_from_sgsn(struct gbproxy_config *cfg,
|
|||
/* RAI IE is mandatory */
|
||||
if (!TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA))
|
||||
goto err_mand_ie;
|
||||
peer = peer_by_rai(cfg, TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA));
|
||||
peer = gbproxy_peer_by_rai(cfg, TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA));
|
||||
if (!peer)
|
||||
goto err_no_peer;
|
||||
rc = gbprox_relay2peer(msg, peer, ns_bvci);
|
||||
|
@ -901,7 +759,7 @@ int gbprox_rcvmsg(struct gbproxy_config *cfg, struct msgb *msg, uint16_t nsei,
|
|||
else
|
||||
rc = gbprox_rx_sig_from_bss(cfg, msg, nsei, ns_bvci);
|
||||
} else {
|
||||
peer = peer_by_bvci(cfg, ns_bvci);
|
||||
peer = gbproxy_peer_by_bvci(cfg, ns_bvci);
|
||||
|
||||
/* All other BVCI are PTP and thus can be simply forwarded */
|
||||
if (!remote_end_is_sgsn) {
|
||||
|
@ -976,7 +834,7 @@ int gbprox_signal(unsigned int subsys, unsigned int signal,
|
|||
|
||||
if (!nsvc->remote_end_is_sgsn) {
|
||||
/* from BSS to SGSN */
|
||||
peer = gbprox_peer_by_nsei(cfg, nsvc->nsei);
|
||||
peer = gbproxy_peer_by_nsei(cfg, nsvc->nsei);
|
||||
if (!peer) {
|
||||
LOGP(DGPRS, LOGL_NOTICE, "signal %u for unknown peer "
|
||||
"NSEI=%u/NSVCI=%u\n", signal, nsvc->nsei,
|
||||
|
@ -1033,24 +891,6 @@ void gbprox_reset(struct gbproxy_config *cfg)
|
|||
gbproxy_init_config(cfg);
|
||||
}
|
||||
|
||||
int gbprox_cleanup_peers(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci)
|
||||
{
|
||||
int counter = 0;
|
||||
struct gbproxy_peer *peer, *tmp;
|
||||
|
||||
llist_for_each_entry_safe(peer, tmp, &cfg->bts_peers, list) {
|
||||
if (peer->nsei != nsei)
|
||||
continue;
|
||||
if (bvci && peer->bvci != bvci)
|
||||
continue;
|
||||
|
||||
gbproxy_peer_free(peer);
|
||||
counter += 1;
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
int gbproxy_init_config(struct gbproxy_config *cfg)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
|
|
@ -0,0 +1,200 @@
|
|||
/* Gb proxy peer handling */
|
||||
|
||||
/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
|
||||
* (C) 2010-2013 by On-Waves
|
||||
* (C) 2013 by Holger Hans Peter Freyther
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openbsc/gb_proxy.h>
|
||||
|
||||
#include <openbsc/gsm_data.h>
|
||||
#include <openbsc/gsm_data_shared.h>
|
||||
#include <openbsc/gsm_04_08_gprs.h>
|
||||
#include <openbsc/debug.h>
|
||||
|
||||
#include <osmocom/gprs/protocol/gsm_08_18.h>
|
||||
#include <osmocom/core/rate_ctr.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static const struct rate_ctr_desc peer_ctr_description[] = {
|
||||
{ "blocked", "BVC Block " },
|
||||
{ "unblocked", "BVC Unblock " },
|
||||
{ "dropped", "BVC blocked, dropped packet " },
|
||||
{ "inv-nsei", "NSEI mismatch " },
|
||||
{ "tx-err", "NS Transmission error " },
|
||||
{ "raid-mod.bss", "RAID patched (BSS )" },
|
||||
{ "raid-mod.sgsn", "RAID patched (SGSN)" },
|
||||
{ "apn-mod.sgsn", "APN patched " },
|
||||
{ "tlli-mod.bss", "TLLI patched (BSS )" },
|
||||
{ "tlli-mod.sgsn", "TLLI patched (SGSN)" },
|
||||
{ "ptmsi-mod.bss", "P-TMSI patched (BSS )" },
|
||||
{ "ptmsi-mod.sgsn","P-TMSI patched (SGSN)" },
|
||||
{ "mod-crypt-err", "Patch error: encrypted " },
|
||||
{ "mod-err", "Patch error: other " },
|
||||
{ "attach-reqs", "Attach Request count " },
|
||||
{ "attach-rejs", "Attach Reject count " },
|
||||
{ "tlli-unknown", "TLLI from SGSN unknown " },
|
||||
{ "tlli-cache", "TLLI cache size " },
|
||||
};
|
||||
|
||||
static const struct rate_ctr_group_desc peer_ctrg_desc = {
|
||||
.group_name_prefix = "gbproxy.peer",
|
||||
.group_description = "GBProxy Peer Statistics",
|
||||
.num_ctr = ARRAY_SIZE(peer_ctr_description),
|
||||
.ctr_desc = peer_ctr_description,
|
||||
};
|
||||
|
||||
|
||||
/* Find the gbprox_peer by its BVCI */
|
||||
struct gbproxy_peer *gbproxy_peer_by_bvci(struct gbproxy_config *cfg, uint16_t bvci)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
llist_for_each_entry(peer, &cfg->bts_peers, list) {
|
||||
if (peer->bvci == bvci)
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Find the gbprox_peer by its NSEI */
|
||||
struct gbproxy_peer *gbproxy_peer_by_nsei(struct gbproxy_config *cfg,
|
||||
uint16_t nsei)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
llist_for_each_entry(peer, &cfg->bts_peers, list) {
|
||||
if (peer->nsei == nsei)
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* look-up a peer by its Routeing Area Identification (RAI) */
|
||||
struct gbproxy_peer *gbproxy_peer_by_rai(struct gbproxy_config *cfg,
|
||||
const uint8_t *ra)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
llist_for_each_entry(peer, &cfg->bts_peers, list) {
|
||||
if (!memcmp(peer->ra, ra, 6))
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* look-up a peer by its Location Area Identification (LAI) */
|
||||
struct gbproxy_peer *gbproxy_peer_by_lai(struct gbproxy_config *cfg,
|
||||
const uint8_t *la)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
llist_for_each_entry(peer, &cfg->bts_peers, list) {
|
||||
if (!memcmp(peer->ra, la, 5))
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* look-up a peer by its Location Area Code (LAC) */
|
||||
struct gbproxy_peer *gbproxy_peer_by_lac(struct gbproxy_config *cfg,
|
||||
const uint8_t *la)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
llist_for_each_entry(peer, &cfg->bts_peers, list) {
|
||||
if (!memcmp(peer->ra + 3, la + 3, 2))
|
||||
return peer;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct gbproxy_peer *gbproxy_peer_by_bssgp_tlv(struct gbproxy_config *cfg,
|
||||
struct tlv_parsed *tp)
|
||||
{
|
||||
if (TLVP_PRESENT(tp, BSSGP_IE_BVCI)) {
|
||||
uint16_t bvci;
|
||||
|
||||
bvci = ntohs(tlvp_val16_unal(tp, BSSGP_IE_BVCI));
|
||||
if (bvci >= 2)
|
||||
return gbproxy_peer_by_bvci(cfg, bvci);
|
||||
}
|
||||
|
||||
if (TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) {
|
||||
uint8_t *rai = (uint8_t *)TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA);
|
||||
/* Only compare LAC part, since MCC/MNC are possibly patched.
|
||||
* Since the LAC of different BSS must be different when
|
||||
* MCC/MNC are patched, collisions shouldn't happen. */
|
||||
return gbproxy_peer_by_lac(cfg, rai);
|
||||
}
|
||||
|
||||
if (TLVP_PRESENT(tp, BSSGP_IE_LOCATION_AREA)) {
|
||||
uint8_t *lai = (uint8_t *)TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA);
|
||||
return gbproxy_peer_by_lac(cfg, lai);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
struct gbproxy_peer *gbproxy_peer_alloc(struct gbproxy_config *cfg, uint16_t bvci)
|
||||
{
|
||||
struct gbproxy_peer *peer;
|
||||
|
||||
peer = talloc_zero(tall_bsc_ctx, struct gbproxy_peer);
|
||||
if (!peer)
|
||||
return NULL;
|
||||
|
||||
peer->bvci = bvci;
|
||||
peer->ctrg = rate_ctr_group_alloc(peer, &peer_ctrg_desc, bvci);
|
||||
peer->cfg = cfg;
|
||||
|
||||
llist_add(&peer->list, &cfg->bts_peers);
|
||||
|
||||
INIT_LLIST_HEAD(&peer->patch_state.enabled_tllis);
|
||||
|
||||
return peer;
|
||||
}
|
||||
|
||||
void gbproxy_peer_free(struct gbproxy_peer *peer)
|
||||
{
|
||||
llist_del(&peer->list);
|
||||
|
||||
gbproxy_delete_tllis(peer);
|
||||
|
||||
rate_ctr_group_free(peer->ctrg);
|
||||
peer->ctrg = NULL;
|
||||
|
||||
talloc_free(peer);
|
||||
}
|
||||
|
||||
int gbproxy_cleanup_peers(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci)
|
||||
{
|
||||
int counter = 0;
|
||||
struct gbproxy_peer *peer, *tmp;
|
||||
|
||||
llist_for_each_entry_safe(peer, tmp, &cfg->bts_peers, list) {
|
||||
if (peer->nsei != nsei)
|
||||
continue;
|
||||
if (bvci && peer->bvci != bvci)
|
||||
continue;
|
||||
|
||||
gbproxy_peer_free(peer);
|
||||
counter += 1;
|
||||
}
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
|
@ -422,7 +422,7 @@ DEFUN(delete_gb_bvci, delete_gb_bvci_cmd,
|
|||
const uint16_t bvci = atoi(argv[1]);
|
||||
int counter;
|
||||
|
||||
counter = gbprox_cleanup_peers(g_cfg, nsei, bvci);
|
||||
counter = gbproxy_cleanup_peers(g_cfg, nsei, bvci);
|
||||
|
||||
if (counter == 0) {
|
||||
vty_out(vty, "BVC not found%s", VTY_NEWLINE);
|
||||
|
@ -458,7 +458,7 @@ DEFUN(delete_gb_nsei, delete_gb_nsei_cmd,
|
|||
|
||||
if (delete_bvc) {
|
||||
if (!dry_run)
|
||||
counter = gbprox_cleanup_peers(g_cfg, nsei, 0);
|
||||
counter = gbproxy_cleanup_peers(g_cfg, nsei, 0);
|
||||
else {
|
||||
struct gbproxy_peer *peer;
|
||||
counter = 0;
|
||||
|
@ -541,7 +541,7 @@ DEFUN(delete_gb_tlli, delete_gb_tlli_cmd,
|
|||
break;
|
||||
}
|
||||
|
||||
peer = gbprox_peer_by_nsei(g_cfg, nsei);
|
||||
peer = gbproxy_peer_by_nsei(g_cfg, nsei);
|
||||
if (!peer) {
|
||||
vty_out(vty, "Didn't find peer with NSEI %d%s",
|
||||
nsei, VTY_NEWLINE);
|
||||
|
|
|
@ -10,6 +10,7 @@ gbproxy_test_SOURCES = gbproxy_test.c
|
|||
gbproxy_test_LDADD = \
|
||||
$(top_builddir)/src/gprs/gb_proxy.o \
|
||||
$(top_builddir)/src/gprs/gb_proxy_patch.o \
|
||||
$(top_builddir)/src/gprs/gb_proxy_peer.o \
|
||||
$(top_builddir)/src/gprs/gb_proxy_tlli.o \
|
||||
$(top_builddir)/src/gprs/gprs_gb_parse.o \
|
||||
$(top_builddir)/src/gprs/gprs_llc_parse.o \
|
||||
|
|
|
@ -1203,7 +1203,7 @@ static void test_gbproxy_ra_patching()
|
|||
gprs_dump_nsi(nsi);
|
||||
dump_peers(stdout, 0, 0, &gbcfg);
|
||||
|
||||
peer = gbprox_peer_by_nsei(&gbcfg, 0x1000);
|
||||
peer = gbproxy_peer_by_nsei(&gbcfg, 0x1000);
|
||||
OSMO_ASSERT(peer != NULL);
|
||||
|
||||
send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002);
|
||||
|
@ -1423,7 +1423,7 @@ static void test_gbproxy_ptmsi_patching()
|
|||
setup_ns(nsi, &bss_peer[0], 0x1001, 0x1000);
|
||||
setup_bssgp(nsi, &bss_peer[0], 0x1002);
|
||||
|
||||
peer = gbprox_peer_by_nsei(&gbcfg, 0x1000);
|
||||
peer = gbproxy_peer_by_nsei(&gbcfg, 0x1000);
|
||||
OSMO_ASSERT(peer != NULL);
|
||||
|
||||
send_bssgp_reset_ack(nsi, &sgsn_peer, 0x1002);
|
||||
|
|
Loading…
Reference in New Issue