Change in libosmocore[master]: gprs_ns2_sns: bss: improve validation of configuration

2021-06-07 Thread laforge
laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/24581 )

Change subject: gprs_ns2_sns: bss: improve validation of configuration
..

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
---
M src/gb/gprs_ns2_sns.c
1 file changed, 49 insertions(+), 1 deletion(-)

Approvals:
  laforge: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index 5d85ec0..9865acd 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -1519,6 +1519,54 @@
}
 }

+/* 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(>sns_endpoints) || llist_empty(>binds))
+   return 0;
+
+   llist_for_each_entry(sbind, >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, >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 @@
ns2_clear_ipv46_entries_remote(gss);
 
/* Choose the next sns endpoint. */
-   if (llist_empty(>sns_endpoints) || 
llist_empty(>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);

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24581
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I2fcf67bc2431ddac23c4ae23cebbb29771e573f1
Gerrit-Change-Number: 24581
Gerrit-PatchSet: 2
Gerrit-Owner: lynxis lazus 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-MessageType: merged


Change in libosmocore[master]: gprs_ns2_sns: bss: improve validation of configuration

2021-06-07 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/24581 )

Change subject: gprs_ns2_sns: bss: improve validation of configuration
..


Patch Set 1: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24581
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I2fcf67bc2431ddac23c4ae23cebbb29771e573f1
Gerrit-Change-Number: 24581
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Mon, 07 Jun 2021 12:36:23 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in libosmocore[master]: gprs_ns2_sns: bss: improve validation of configuration

2021-06-07 Thread pespin
pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/24581 )

Change subject: gprs_ns2_sns: bss: improve validation of configuration
..


Patch Set 1: Code-Review+1


--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24581
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I2fcf67bc2431ddac23c4ae23cebbb29771e573f1
Gerrit-Change-Number: 24581
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin 
Gerrit-Comment-Date: Mon, 07 Jun 2021 09:12:10 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in libosmocore[master]: gprs_ns2_sns: bss: improve validation of configuration

2021-06-06 Thread lynxis lazus
lynxis lazus has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/24581 )


Change subject: gprs_ns2_sns: bss: improve validation of configuration
..

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
---
M src/gb/gprs_ns2_sns.c
1 file changed, 49 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/81/24581/1

diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index 5d85ec0..9865acd 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -1519,6 +1519,54 @@
}
 }

+/* 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(>sns_endpoints) || llist_empty(>binds))
+   return 0;
+
+   llist_for_each_entry(sbind, >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, >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 @@
ns2_clear_ipv46_entries_remote(gss);

/* Choose the next sns endpoint. */
-   if (llist_empty(>sns_endpoints) || 
llist_empty(>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);

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24581
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I2fcf67bc2431ddac23c4ae23cebbb29771e573f1
Gerrit-Change-Number: 24581
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus 
Gerrit-MessageType: newchange