aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Couzens <lynxis@fe80.eu>2021-06-05 20:04:04 +0200
committerlaforge <laforge@osmocom.org>2021-06-07 12:39:47 +0000
commit31d52e156f5e8c17074559e60767ffb11b8bd268 (patch)
treece5b6f27100ed206c3f1a354c10dcc656f8b12d2
parent6608ce9525d0447e1159f66bf2a0cf6278993c12 (diff)
gprs_ns2_sns: bss: improve validation of configuration
Some combination of IPv4 and IPv6 result in incomplete combination. E.g. IPv6 binds, but only IPv4 endpoints and vice versa. Related: OS#5036 Change-Id: I2fcf67bc2431ddac23c4ae23cebbb29771e573f1
-rw-r--r--src/gb/gprs_ns2_sns.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index 5d85ec08..9865acd2 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -1519,6 +1519,54 @@ static void ns2_sns_st_all_action(struct osmo_fsm_inst *fi, uint32_t event, void
}
}
+/* validate the bss configuration (sns endpoint and binds)
+ * - no endpoints -> invalid
+ * - no binds -> invalid
+ * - only v4 sns endpoints, only v6 binds -> invalid
+ * - only v4 sns endpoints, but v4 sig weights == 0 -> invalid ...
+ */
+static int ns2_sns_bss_valid_configuration(struct ns2_sns_state *gss)
+{
+ struct ns2_sns_bind *sbind;
+ struct sns_endpoint *endpoint;
+ const struct osmo_sockaddr *addr;
+ int v4_sig = 0, v4_data = 0, v6_sig = 0, v6_data = 0;
+ bool v4_endpoints = false;
+ bool v6_endpoints = false;
+
+ if (llist_empty(&gss->sns_endpoints) || llist_empty(&gss->binds))
+ return 0;
+
+ llist_for_each_entry(sbind, &gss->binds, list) {
+ addr = gprs_ns2_ip_bind_sockaddr(sbind->bind);
+ if (!addr)
+ continue;
+ switch (addr->u.sa.sa_family) {
+ case AF_INET:
+ v4_sig += sbind->bind->sns_sig_weight;
+ v4_data += sbind->bind->sns_data_weight;
+ break;
+ case AF_INET6:
+ v6_sig += sbind->bind->sns_sig_weight;
+ v6_data += sbind->bind->sns_data_weight;
+ break;
+ }
+ }
+
+ llist_for_each_entry(endpoint, &gss->sns_endpoints, list) {
+ switch (endpoint->saddr.u.sa.sa_family) {
+ case AF_INET:
+ v4_endpoints = true;
+ break;
+ case AF_INET6:
+ v6_endpoints = true;
+ break;
+ }
+ }
+
+ return (v4_endpoints && v4_sig && v4_data) || (v6_endpoints && v6_sig && v6_data);
+}
+
/* allstate-action for BSS role */
static void ns2_sns_st_all_action_bss(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
@@ -1544,7 +1592,7 @@ static void ns2_sns_st_all_action_bss(struct osmo_fsm_inst *fi, uint32_t event,
ns2_clear_ipv46_entries_remote(gss);
/* Choose the next sns endpoint. */
- if (llist_empty(&gss->sns_endpoints) || llist_empty(&gss->binds)) {
+ if (!ns2_sns_bss_valid_configuration(gss)) {
gss->initial = NULL;
ns2_prim_status_ind(gss->nse, NULL, 0, GPRS_NS2_AFF_CAUSE_SNS_NO_ENDPOINTS);
osmo_fsm_inst_state_chg(fi, GPRS_SNS_ST_UNCONFIGURED, 0, 3);