filter: Move the con_type into the filter_state
diff --git a/openbsc/include/openbsc/bsc_msg_filter.h b/openbsc/include/openbsc/bsc_msg_filter.h
index b09cd8a..a9dedf4 100644
--- a/openbsc/include/openbsc/bsc_msg_filter.h
+++ b/openbsc/include/openbsc/bsc_msg_filter.h
@@ -53,9 +53,21 @@
 	int lu_reject_cause;
 };
 
+enum {
+	FLT_CON_TYPE_NONE,
+	FLT_CON_TYPE_LU,
+	FLT_CON_TYPE_CM_SERV_REQ,
+	FLT_CON_TYPE_PAG_RESP,
+	FLT_CON_TYPE_SSA,
+	FLT_CON_TYPE_LOCAL_REJECT,
+	FLT_CON_TYPE_OTHER,
+};
+
+
 struct bsc_filter_state {
 	char *imsi;
 	int imsi_checked;
+	int con_type;
 };
 
 struct bsc_filter_request {
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 10f11a6..ae940b3 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -48,16 +48,6 @@
 struct bsc_nat_ussd_con;
 struct nat_rewrite_rule;
 
-enum {
-	NAT_CON_TYPE_NONE,
-	NAT_CON_TYPE_LU,
-	NAT_CON_TYPE_CM_SERV_REQ,
-	NAT_CON_TYPE_PAG_RESP,
-	NAT_CON_TYPE_SSA,
-	NAT_CON_TYPE_LOCAL_REJECT,
-	NAT_CON_TYPE_OTHER,
-};
-
 /*
  * Is this terminated to the MSC, to the local machine (release
  * handling for IMSI filtering) or to a USSD provider?
diff --git a/openbsc/include/openbsc/bsc_nat_sccp.h b/openbsc/include/openbsc/bsc_nat_sccp.h
index d2490ca..0824664 100644
--- a/openbsc/include/openbsc/bsc_nat_sccp.h
+++ b/openbsc/include/openbsc/bsc_nat_sccp.h
@@ -79,7 +79,6 @@
 	int has_remote_ref;
 
 	/* status */
-	int con_type;
 	int con_local;
 	int authorized;
 
diff --git a/openbsc/src/libfilter/bsc_msg_filter.c b/openbsc/src/libfilter/bsc_msg_filter.c
index c3d1bed..2bbfa07 100644
--- a/openbsc/src/libfilter/bsc_msg_filter.c
+++ b/openbsc/src/libfilter/bsc_msg_filter.c
@@ -256,7 +256,7 @@
 
 	req = (struct gsm48_service_request *) data;
 	if (req->cm_service_type == 0x8)
-		*con_type = NAT_CON_TYPE_SSA;
+		*con_type = FLT_CON_TYPE_SSA;
 	rc = gsm48_extract_mi((uint8_t *) &req->classmark,
 			      length - classmark_offset, mi_string, &mi_type);
 	if (rc < 0) {
@@ -337,7 +337,7 @@
 	int ret = 0;
 	uint8_t msg_type, proto;
 
-	*con_type = NAT_CON_TYPE_NONE;
+	*con_type = FLT_CON_TYPE_NONE;
 	cause->cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED;
 	cause->lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED;
 	*imsi = NULL;
@@ -346,23 +346,23 @@
 	msg_type = hdr48->msg_type & 0xbf;
 	if (proto == GSM48_PDISC_MM &&
 	    msg_type == GSM48_MT_MM_LOC_UPD_REQUEST) {
-		*con_type = NAT_CON_TYPE_LU;
+		*con_type = FLT_CON_TYPE_LU;
 		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;
+		*con_type = FLT_CON_TYPE_CM_SERV_REQ;
 		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;
+		*con_type = FLT_CON_TYPE_PAG_RESP;
 		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 */
-		*con_type = NAT_CON_TYPE_OTHER;
+		*con_type = FLT_CON_TYPE_OTHER;
 		return 0;
 	}
 
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_api.c b/openbsc/src/osmo-bsc/osmo_bsc_api.c
index 18b9607..a90ad16 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_api.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_api.c
@@ -210,6 +210,7 @@
 	ci = get_ci_for_msc(conn->sccp_con->msc, conn->bts);
 
 	bsc_scan_bts_msg(conn, msg);
+
 	resp = gsm0808_create_layer3(msg, network_code, country_code, lac, ci);
 	if (!resp) {
 		LOGP(DMSC, LOGL_DEBUG, "Failed to create layer3 message.\n");
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c
index 3ec43b1..4357485 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c
@@ -442,7 +442,7 @@
 	con->msc_con = NULL;
 
 	/* 2. release the BSC side */
-	if (con->con_type == NAT_CON_TYPE_LU) {
+	if (con->filter_state.con_type == FLT_CON_TYPE_LU) {
 		struct msgb *payload, *udt;
 		payload = gsm48_create_loc_upd_rej(cause->lu_reject_cause);
 
@@ -470,7 +470,7 @@
 		return;
 	}
 
-	con->con_type = NAT_CON_TYPE_LOCAL_REJECT;
+	con->filter_state.con_type = FLT_CON_TYPE_LOCAL_REJECT;
 	bsc_write(bsc, rlsd, IPAC_PROTO_SCCP);
 }
 
@@ -481,9 +481,9 @@
 	struct msgb *payload;
 	struct msgb *refuse;
 
-	if (con_type == NAT_CON_TYPE_LU)
+	if (con_type == FLT_CON_TYPE_LU)
 		payload = gsm48_create_loc_upd_rej(cause->lu_reject_cause);
-	else if (con_type == NAT_CON_TYPE_CM_SERV_REQ || con_type == NAT_CON_TYPE_SSA)
+	else if (con_type == FLT_CON_TYPE_CM_SERV_REQ || con_type == FLT_CON_TYPE_SSA)
 		payload = gsm48_create_mm_serv_rej(cause->cm_reject_cause);
 	else {
 		LOGP(DNAT, LOGL_ERROR, "Unknown connection type: %d\n", con_type);
@@ -504,7 +504,7 @@
 			goto send_refuse;
 
 		/* declare it local and assign a unique remote_ref */
-		con->con_type = NAT_CON_TYPE_LOCAL_REJECT;
+		con->filter_state.con_type = FLT_CON_TYPE_LOCAL_REJECT;
 		con->con_local = NAT_CON_END_LOCAL;
 		con->has_remote_ref = 1;
 		con->remote_ref = con->patched_ref;
@@ -1072,7 +1072,7 @@
 			con = patch_sccp_src_ref_to_msc(msg, parsed, bsc);
 			con->msc_con = bsc->nat->msc_con;
 			con_msc = con->msc_con;
-			con->con_type = con_type;
+			con->filter_state.con_type = con_type;
 			con->filter_state.imsi_checked = filter;
 			bsc_nat_extract_lac(bsc, con, parsed, msg);
 			if (imsi)
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_filter.c b/openbsc/src/osmo-bsc_nat/bsc_nat_filter.c
index 6883d66..393aea3 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_filter.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_filter.c
@@ -41,7 +41,7 @@
 	int hdr48_len;
 	int len;
 
-	*con_type = NAT_CON_TYPE_NONE;
+	*con_type = FLT_CON_TYPE_NONE;
 	cause->cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED;
 	cause->lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED;
 	*imsi = NULL;
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
index 8921208..d95227d 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
@@ -403,13 +403,13 @@
 }
 
 static const char *con_types [] = {
-	[NAT_CON_TYPE_NONE] = "n/a",
-	[NAT_CON_TYPE_LU] = "Location Update",
-	[NAT_CON_TYPE_CM_SERV_REQ] = "CM Serv Req",
-	[NAT_CON_TYPE_PAG_RESP] = "Paging Response",
-	[NAT_CON_TYPE_SSA] = "Supplementar Service Activation",
-	[NAT_CON_TYPE_LOCAL_REJECT] = "Local Reject",
-	[NAT_CON_TYPE_OTHER] = "Other",
+	[FLT_CON_TYPE_NONE] = "n/a",
+	[FLT_CON_TYPE_LU] = "Location Update",
+	[FLT_CON_TYPE_CM_SERV_REQ] = "CM Serv Req",
+	[FLT_CON_TYPE_PAG_RESP] = "Paging Response",
+	[FLT_CON_TYPE_SSA] = "Supplementar Service Activation",
+	[FLT_CON_TYPE_LOCAL_REJECT] = "Local Reject",
+	[FLT_CON_TYPE_OTHER] = "Other",
 };
 
 const char *bsc_con_type_to_string(int type)
@@ -423,18 +423,18 @@
 }
 
 static const int con_to_ctr[] = {
-	[NAT_CON_TYPE_NONE]		= -1,
-	[NAT_CON_TYPE_LU]		= BCFG_CTR_CON_TYPE_LU,
-	[NAT_CON_TYPE_CM_SERV_REQ]	= BCFG_CTR_CON_CMSERV_RQ,
-	[NAT_CON_TYPE_PAG_RESP]		= BCFG_CTR_CON_PAG_RESP,
-	[NAT_CON_TYPE_SSA]		= BCFG_CTR_CON_SSA,
-	[NAT_CON_TYPE_LOCAL_REJECT]	= -1,
-	[NAT_CON_TYPE_OTHER]		= BCFG_CTR_CON_OTHER,
+	[FLT_CON_TYPE_NONE]		= -1,
+	[FLT_CON_TYPE_LU]		= BCFG_CTR_CON_TYPE_LU,
+	[FLT_CON_TYPE_CM_SERV_REQ]	= BCFG_CTR_CON_CMSERV_RQ,
+	[FLT_CON_TYPE_PAG_RESP]		= BCFG_CTR_CON_PAG_RESP,
+	[FLT_CON_TYPE_SSA]		= BCFG_CTR_CON_SSA,
+	[FLT_CON_TYPE_LOCAL_REJECT]	= -1,
+	[FLT_CON_TYPE_OTHER]		= BCFG_CTR_CON_OTHER,
 };
 
 int bsc_conn_type_to_ctr(struct nat_sccp_connection *conn)
 {
-	return con_to_ctr[conn->con_type];
+	return con_to_ctr[conn->filter_state.con_type];
 }
 
 int bsc_write_cb(struct osmo_fd *bfd, struct msgb *msg)
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
index 596ecae..821e522 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
@@ -189,7 +189,7 @@
 			con->has_remote_ref,
 			sccp_src_ref_to_int(&con->remote_ref),
 			con->msc_endp, con->bsc_endp,
-			bsc_con_type_to_string(con->con_type),
+			bsc_con_type_to_string(con->filter_state.con_type),
 			VTY_NEWLINE);
 	}
 
diff --git a/openbsc/src/osmo-bsc_nat/bsc_ussd.c b/openbsc/src/osmo-bsc_nat/bsc_ussd.c
index 2241896..1082414 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_ussd.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_ussd.c
@@ -382,7 +382,7 @@
 	 * decode if the connection was created for USSD, we do have a USSD access
 	 * list, a query, a IMSI and such...
 	 */
-	if (con->con_type != NAT_CON_TYPE_SSA)
+	if (con->filter_state.con_type != FLT_CON_TYPE_SSA)
 		return 0;
 
 	if (!con->filter_state.imsi)
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index e883ddd..b830eb0 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -711,7 +711,7 @@
 		.data = bssmap_cr,
 		.length = sizeof(bssmap_cr),
 		.result = 1,
-		.contype = NAT_CON_TYPE_CM_SERV_REQ,
+		.contype = FLT_CON_TYPE_CM_SERV_REQ,
 		.nat_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.nat_lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.bsc_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
@@ -723,7 +723,7 @@
 		.data = bss_lu,
 		.length = sizeof(bss_lu),
 		.result = 1,
-		.contype = NAT_CON_TYPE_LU,
+		.contype = FLT_CON_TYPE_LU,
 		.nat_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.nat_lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.bsc_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
@@ -735,7 +735,7 @@
 		.data = pag_resp,
 		.length = sizeof(pag_resp),
 		.result = 1,
-		.contype = NAT_CON_TYPE_PAG_RESP,
+		.contype = FLT_CON_TYPE_PAG_RESP,
 		.nat_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.nat_lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.bsc_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
@@ -749,7 +749,7 @@
 		.length = sizeof(bss_lu),
 		.result = -3,
 		.nat_imsi_deny = "[0-9]*",
-		.contype = NAT_CON_TYPE_LU,
+		.contype = FLT_CON_TYPE_LU,
 		.nat_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.nat_lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.bsc_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
@@ -764,7 +764,7 @@
 		.result = 1,
 		.nat_imsi_deny = "[0-9]*",
 		.bsc_imsi_allow = "2440[0-9]*",
-		.contype = NAT_CON_TYPE_LU,
+		.contype = FLT_CON_TYPE_LU,
 		.nat_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.nat_lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.bsc_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
@@ -779,7 +779,7 @@
 		.result = 1,
 		.bsc_imsi_allow = "[0-9]*",
 		.nat_imsi_deny = "[0-9]*",
-		.contype = NAT_CON_TYPE_LU,
+		.contype = FLT_CON_TYPE_LU,
 		.nat_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.nat_lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.bsc_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
@@ -795,7 +795,7 @@
 		.bsc_imsi_deny = "[0-9]*",
 		.bsc_imsi_allow = "[0-9]*",
 		.nat_imsi_deny = "[0-9]*",
-		.contype = NAT_CON_TYPE_LU,
+		.contype = FLT_CON_TYPE_LU,
 		.nat_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.nat_lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.bsc_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
@@ -810,7 +810,7 @@
 		.result = -3,
 		.bsc_imsi_deny = "000[0-9]*",
 		.nat_imsi_deny = "[0-9]*",
-		.contype = NAT_CON_TYPE_LU,
+		.contype = FLT_CON_TYPE_LU,
 		.nat_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.nat_lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.bsc_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
@@ -825,7 +825,7 @@
 		.result = -3,
 		.bsc_imsi_deny = "000[0-9]*",
 		.nat_imsi_deny = "[0-9]*",
-		.contype = NAT_CON_TYPE_LU,
+		.contype = FLT_CON_TYPE_LU,
 		.nat_cm_reject_cause = 0x23,
 		.nat_lu_reject_cause = 0x42,
 		.bsc_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
@@ -839,7 +839,7 @@
 		.length = sizeof(bss_lu),
 		.result = -2,
 		.bsc_imsi_deny = "[0-9]*",
-		.contype = NAT_CON_TYPE_LU,
+		.contype = FLT_CON_TYPE_LU,
 		.nat_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.nat_lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.bsc_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
@@ -853,7 +853,7 @@
 		.length = sizeof(bss_lu),
 		.result = -2,
 		.bsc_imsi_deny = "[0-9]*",
-		.contype = NAT_CON_TYPE_LU,
+		.contype = FLT_CON_TYPE_LU,
 		.nat_cm_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.nat_lu_reject_cause = GSM48_REJECT_PLMN_NOT_ALLOWED,
 		.bsc_cm_reject_cause = 0x42,