filter: Remove bsc_connection from the filter API
Remove the last occurence of NAT datastructures in the filtering module and add the ctx to the filter request structure.
This commit is contained in:
parent
c09f8a3b7f
commit
4e8176d0c9
|
@ -10,9 +10,6 @@
|
|||
struct vty;
|
||||
struct gsm48_hdr;
|
||||
|
||||
/* TODO: remove */
|
||||
struct bsc_connection;
|
||||
|
||||
struct bsc_filter_reject_cause {
|
||||
int lu_reject_cause;
|
||||
int cm_reject_cause;
|
||||
|
@ -61,6 +58,15 @@ struct bsc_filter_state {
|
|||
int imsi_checked;
|
||||
};
|
||||
|
||||
struct bsc_filter_request {
|
||||
void *ctx;
|
||||
struct rb_root *black_list;
|
||||
struct llist_head *access_lists;
|
||||
const char *local_lst_name;
|
||||
const char *global_lst_name;
|
||||
int bsc_nr;
|
||||
};
|
||||
|
||||
|
||||
int bsc_filter_barr_adapt(void *ctx, struct rb_root *rbtree, const struct osmo_config_list *);
|
||||
int bsc_filter_barr_find(struct rb_root *root, const char *imsi, int *cm, int *lu);
|
||||
|
@ -69,11 +75,11 @@ int bsc_filter_barr_find(struct rb_root *root, const char *imsi, int *cm, int *l
|
|||
* Content filtering.
|
||||
*/
|
||||
int bsc_msg_filter_initial(struct gsm48_hdr *hdr, size_t size,
|
||||
struct bsc_connection *bsc,
|
||||
struct bsc_filter_request *req,
|
||||
int *con_type, char **imsi,
|
||||
struct bsc_filter_reject_cause *cause);
|
||||
int bsc_msg_filter_data(struct gsm48_hdr *hdr, size_t size,
|
||||
struct bsc_connection *bsc,
|
||||
struct bsc_filter_request *req,
|
||||
struct bsc_filter_state *state,
|
||||
struct bsc_filter_reject_cause *cause);
|
||||
|
||||
|
|
|
@ -38,14 +38,6 @@
|
|||
|
||||
#include <osmocom/sccp/sccp.h>
|
||||
|
||||
struct filter_request {
|
||||
struct rb_root *black_list;
|
||||
struct llist_head *access_lists;
|
||||
const char *local_lst_name;
|
||||
const char *global_lst_name;
|
||||
int bsc_nr;
|
||||
};
|
||||
|
||||
int bsc_filter_barr_find(struct rb_root *root, const char *imsi, int *cm, int *lu)
|
||||
{
|
||||
struct bsc_filter_barr_entry *n;
|
||||
|
@ -150,7 +142,7 @@ static int lst_check_deny(struct bsc_msg_acc_lst *lst, const char *mi_string,
|
|||
}
|
||||
|
||||
/* apply white/black list */
|
||||
static int auth_imsi(struct filter_request *req,
|
||||
static int auth_imsi(struct bsc_filter_request *req,
|
||||
const char *imsi,
|
||||
struct bsc_filter_reject_cause *cause)
|
||||
{
|
||||
|
@ -306,7 +298,7 @@ static int _cr_check_pag_resp(void *ctx,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int _dt_check_id_resp(void *ctx, struct filter_request *req,
|
||||
static int _dt_check_id_resp(struct bsc_filter_request *req,
|
||||
uint8_t *data, unsigned int length,
|
||||
struct bsc_filter_state *state,
|
||||
struct bsc_filter_reject_cause *cause)
|
||||
|
@ -331,18 +323,17 @@ static int _dt_check_id_resp(void *ctx, struct filter_request *req,
|
|||
return 0;
|
||||
|
||||
state->imsi_checked = 1;
|
||||
state->imsi = talloc_strdup(ctx, mi_string);
|
||||
state->imsi = talloc_strdup(req->ctx, mi_string);
|
||||
return auth_imsi(req, mi_string, cause);
|
||||
}
|
||||
|
||||
|
||||
/* Filter out CR data... */
|
||||
int bsc_msg_filter_initial(struct gsm48_hdr *hdr48, size_t hdr48_len,
|
||||
struct bsc_connection *bsc,
|
||||
struct bsc_filter_request *req,
|
||||
int *con_type,
|
||||
char **imsi, struct bsc_filter_reject_cause *cause)
|
||||
{
|
||||
struct filter_request req;
|
||||
int ret = 0;
|
||||
uint8_t msg_type, proto;
|
||||
|
||||
|
@ -356,18 +347,18 @@ int bsc_msg_filter_initial(struct gsm48_hdr *hdr48, size_t hdr48_len,
|
|||
if (proto == GSM48_PDISC_MM &&
|
||||
msg_type == GSM48_MT_MM_LOC_UPD_REQUEST) {
|
||||
*con_type = NAT_CON_TYPE_LU;
|
||||
ret = _cr_check_loc_upd(bsc, &hdr48->data[0],
|
||||
ret = _cr_check_loc_upd(req->ctx, &hdr48->data[0],
|
||||
hdr48_len - sizeof(*hdr48), imsi);
|
||||
} else if (proto == GSM48_PDISC_MM &&
|
||||
msg_type == GSM48_MT_MM_CM_SERV_REQ) {
|
||||
*con_type = NAT_CON_TYPE_CM_SERV_REQ;
|
||||
ret = _cr_check_cm_serv_req(bsc, &hdr48->data[0],
|
||||
ret = _cr_check_cm_serv_req(req->ctx, &hdr48->data[0],
|
||||
hdr48_len - sizeof(*hdr48),
|
||||
con_type, imsi);
|
||||
} else if (proto == GSM48_PDISC_RR &&
|
||||
msg_type == GSM48_MT_RR_PAG_RESP) {
|
||||
*con_type = NAT_CON_TYPE_PAG_RESP;
|
||||
ret = _cr_check_pag_resp(bsc, &hdr48->data[0],
|
||||
ret = _cr_check_pag_resp(req->ctx, &hdr48->data[0],
|
||||
hdr48_len - sizeof(*hdr48), imsi);
|
||||
} else {
|
||||
/* We only want to filter the above, let other things pass */
|
||||
|
@ -384,20 +375,14 @@ int bsc_msg_filter_initial(struct gsm48_hdr *hdr48, size_t hdr48_len,
|
|||
return -1;
|
||||
|
||||
/* now check the imsi */
|
||||
req.black_list = &bsc->nat->imsi_black_list;
|
||||
req.access_lists = &bsc->nat->access_lists;
|
||||
req.local_lst_name = bsc->cfg->acc_lst_name;
|
||||
req.global_lst_name = bsc->nat->acc_lst_name;
|
||||
req.bsc_nr = bsc->cfg->nr;
|
||||
return auth_imsi(&req, *imsi, cause);
|
||||
return auth_imsi(req, *imsi, cause);
|
||||
}
|
||||
|
||||
int bsc_msg_filter_data(struct gsm48_hdr *hdr48, size_t len,
|
||||
struct bsc_connection *bsc,
|
||||
struct bsc_filter_request *req,
|
||||
struct bsc_filter_state *state,
|
||||
struct bsc_filter_reject_cause *cause)
|
||||
{
|
||||
struct filter_request req;
|
||||
uint8_t msg_type, proto;
|
||||
|
||||
cause->cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED;
|
||||
|
@ -411,11 +396,6 @@ int bsc_msg_filter_data(struct gsm48_hdr *hdr48, size_t len,
|
|||
if (proto != GSM48_PDISC_MM || msg_type != GSM48_MT_MM_ID_RESP)
|
||||
return 0;
|
||||
|
||||
req.black_list = &bsc->nat->imsi_black_list;
|
||||
req.access_lists = &bsc->nat->access_lists;
|
||||
req.local_lst_name = bsc->cfg->acc_lst_name;
|
||||
req.global_lst_name = bsc->nat->acc_lst_name;
|
||||
req.bsc_nr = bsc->cfg->nr;
|
||||
return _dt_check_id_resp(bsc, &req, &hdr48->data[0],
|
||||
return _dt_check_id_resp(req, &hdr48->data[0],
|
||||
len - sizeof(*hdr48), state, cause);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ int bsc_nat_filter_sccp_cr(struct bsc_connection *bsc, struct msgb *msg,
|
|||
struct bsc_nat_parsed *parsed, int *con_type,
|
||||
char **imsi, struct bsc_filter_reject_cause *cause)
|
||||
{
|
||||
struct bsc_filter_request req;
|
||||
struct tlv_parsed tp;
|
||||
struct gsm48_hdr *hdr48;
|
||||
int hdr48_len;
|
||||
|
@ -77,7 +78,13 @@ int bsc_nat_filter_sccp_cr(struct bsc_connection *bsc, struct msgb *msg,
|
|||
}
|
||||
|
||||
hdr48 = (struct gsm48_hdr *) TLVP_VAL(&tp, GSM0808_IE_LAYER_3_INFORMATION);
|
||||
return bsc_msg_filter_initial(hdr48, hdr48_len, bsc, con_type, imsi, cause);
|
||||
req.ctx = bsc;
|
||||
req.black_list = &bsc->nat->imsi_black_list;
|
||||
req.access_lists = &bsc->nat->access_lists;
|
||||
req.local_lst_name = bsc->cfg->acc_lst_name;
|
||||
req.global_lst_name = bsc->nat->acc_lst_name;
|
||||
req.bsc_nr = bsc->cfg->nr;
|
||||
return bsc_msg_filter_initial(hdr48, hdr48_len, &req, con_type, imsi, cause);
|
||||
}
|
||||
|
||||
int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg,
|
||||
|
@ -86,6 +93,7 @@ int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg,
|
|||
{
|
||||
uint32_t len;
|
||||
struct gsm48_hdr *hdr48;
|
||||
struct bsc_filter_request req;
|
||||
|
||||
cause->cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED;
|
||||
cause->lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED;
|
||||
|
@ -101,5 +109,11 @@ int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg,
|
|||
if (!hdr48)
|
||||
return -1;
|
||||
|
||||
return bsc_msg_filter_data(hdr48, len, bsc, &con->filter_state, cause);
|
||||
req.ctx = bsc;
|
||||
req.black_list = &bsc->nat->imsi_black_list;
|
||||
req.access_lists = &bsc->nat->access_lists;
|
||||
req.local_lst_name = bsc->cfg->acc_lst_name;
|
||||
req.global_lst_name = bsc->nat->acc_lst_name;
|
||||
req.bsc_nr = bsc->cfg->nr;
|
||||
return bsc_msg_filter_data(hdr48, len, &req, &con->filter_state, cause);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue