NS_Emulation: Dynamically compute list of v4/v6 endpoints in SNS-CONFIG

Don't hard-code the assumption that we only have a single IP[v4] endpoint.

Related: OS#4953
Change-Id: I43fe5810b95ebbc9f848856803ac2c71f80d74f3
This commit is contained in:
Harald Welte 2021-01-18 18:37:34 +01:00
parent 86be7ed803
commit 0b38da55c7
1 changed files with 40 additions and 3 deletions

View File

@ -491,6 +491,42 @@ module NS_Emulation {
}
}
/* generate a list of v4 + v6 endpoints based on the NSVConfigurations. This is not strictly
* accurate, as we should create a list of _endpoints_, while we actually create a list of
* NSVCs. Those are only identical as long as our peer only implements one endpoint */
private function gen_sns_ip_elems(out template (omit) IP4_Elements v4_out,
out template (omit) IP6_Elements v6_out) runs on NSVC_CT {
var integer i;
var IP4_Elements v4 := {};
var IP6_Elements v6 := {};
for (i := 0; i < lengthof(g_config.nsvc); i := i + 1) {
var NSVCConfiguration nsvc_cfg := g_config.nsvc[i];
if (not ischosen(nsvc_cfg.provider.ip)) {
continue;
}
if (nsvc_cfg.provider.ip.address_family == AF_INET) {
v4 := v4 & { valueof(ts_SNS_IPv4(nsvc_cfg.provider.ip.local_ip,
nsvc_cfg.provider.ip.local_udp_port)) };
} else if (nsvc_cfg.provider.ip.address_family == AF_INET6) {
v6 := v6 & { valueof(ts_SNS_IPv6(nsvc_cfg.provider.ip.local_ip,
nsvc_cfg.provider.ip.local_udp_port)) };
}
}
/* we must not return empty lists, but 'omit' as otherwise we get wrong SNS IEs */
if (lengthof(v4) == 0) {
v4_out := omit;
} else {
v4_out := v4;
}
if (lengthof(v6) == 0) {
v6_out := omit;
} else {
v6_out := v6;
}
}
/* simple IP Sub-Network Service responder for the SGSN side. This is not a full implementation
* of the protocol, merely sufficient to make the PCU/BSS side happy to proceed */
private altstep as_sns_sgsn() runs on NSVC_CT {
@ -513,9 +549,10 @@ module NS_Emulation {
/* blindly acknowledge whatever the PCU sends */
NSCP.send(ts_SNS_CONFIG_ACK(g_config.nsei, omit));
/* send a SNS-CONFIG in response and expect a SNS-CONFIG-ACK */
var IP4_Elements v4 := { valueof(ts_SNS_IPv4(g_nsvc_config.provider.ip.local_ip,
g_nsvc_config.provider.ip.local_udp_port)) };
NSCP.send(ts_SNS_CONFIG(g_config.nsei, true, v4));
var template (omit) IP4_Elements v4;
var template (omit) IP6_Elements v6;
gen_sns_ip_elems(v4, v6);
NSCP.send(ts_SNS_CONFIG(g_config.nsei, true, v4, v6));
alt {
[] NSCP.receive(tr_SNS_CONFIG_ACK(g_config.nsei, omit)) {
/* success */