This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
lynxis lazus gerrit-no-reply at lists.osmocom.orglynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/22872 ) Change subject: gprs_ns2: rework IP-SNS binds ...................................................................... gprs_ns2: rework IP-SNS binds Introduce a `ip-sns-bind BINDID` vty command within a `nse` vty object. The ip-sns-bind defines the binds which will be used by the dynamic configuration with IP-SNS. This is only the first part which only use the binds when doing a new SNS configuration. The outgoing add procedure will be supported in a later patch when the SNS fsm support outgoing procedures. Change-Id: I9ab8092bf286e7d90e92f5702a5404425e959c84 --- M src/gb/gprs_ns2.c M src/gb/gprs_ns2_internal.h M src/gb/gprs_ns2_sns.c M src/gb/gprs_ns2_vty.c 4 files changed, 420 insertions(+), 25 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/72/22872/1 diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c index 39bbbef..f63c0ad 100644 --- a/src/gb/gprs_ns2.c +++ b/src/gb/gprs_ns2.c @@ -1267,6 +1267,7 @@ void gprs_ns2_free_bind(struct gprs_ns2_vc_bind *bind) { struct gprs_ns2_vc *nsvc, *tmp; + struct gprs_ns2_nse *nse; if (!bind) return; @@ -1274,6 +1275,12 @@ gprs_ns2_free_nsvc(nsvc); } + if (gprs_ns2_is_ip_bind(bind)) { + llist_for_each_entry(nse, &bind->nsi->nse, list) { + ns2_sns_remove_bind(nse, bind); + } + } + if (bind->driver->free_bind) bind->driver->free_bind(bind); diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h index 9dd9421..7da4a7c 100644 --- a/src/gb/gprs_ns2_internal.h +++ b/src/gb/gprs_ns2_internal.h @@ -365,6 +365,10 @@ void ns2_sns_replace_nsvc(struct gprs_ns2_vc *nsvc); void ns2_sns_notify_alive(struct gprs_ns2_nse *nse, struct gprs_ns2_vc *nsvc, bool alive); void ns2_update_weights(struct gprs_ns2_vc_bind *bind); +int ns2_sns_add_bind(struct gprs_ns2_nse *nse, + struct gprs_ns2_vc_bind *bind); +int ns2_sns_remove_bind(struct gprs_ns2_nse *nse, + struct gprs_ns2_vc_bind *bind); /* vc */ struct osmo_fsm_inst *ns2_vc_fsm_alloc(struct gprs_ns2_vc *nsvc, diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c index 9e77f2a..7e0d5d9 100644 --- a/src/gb/gprs_ns2_sns.c +++ b/src/gb/gprs_ns2_sns.c @@ -103,6 +103,11 @@ struct osmo_sockaddr saddr; }; +struct ns2_sns_bind { + struct llist_head list; + struct gprs_ns2_vc_bind *bind; +}; + struct ns2_sns_state { struct gprs_ns2_nse *nse; @@ -110,6 +115,10 @@ /* holds the list of initial SNS endpoints */ struct llist_head sns_endpoints; + /* list of used struct ns2_sns_bind */ + struct llist_head binds; + /* pointer to the bind which was used to initiate the SNS connection */ + struct ns2_sns_bind *current_bind; /* prevent recursive reselection */ bool reselection_running; @@ -120,8 +129,6 @@ struct sns_endpoint *initial; /* all SNS PDU will be sent over this nsvc */ struct gprs_ns2_vc *sns_nsvc; - /* iterate over the binds after all remote has been tested */ - int bind_offset; /* timer N */ int N; /* true if at least one nsvc is alive */ @@ -741,23 +748,25 @@ remote = &gss->initial->saddr; /* count how many bindings are available (only UDP binds) */ - count = ns2_ip_count_bind(nsi, remote); + count = llist_count(&gss->binds); if (count == 0) { /* TODO: logging */ return; } - bind = ns2_ip_get_bind_by_index(nsi, remote, gss->bind_offset); - if (!bind) { - if (gss->bind_offset) { - gss->bind_offset = 0; - bind = ns2_ip_get_bind_by_index(nsi, remote, gss->bind_offset); + /* take the first bind or take the next bind */ + if (!gss->current_bind) { + gss->current_bind = llist_first_entry(&gss->binds, struct ns2_sns_bind, list); + } else { + if (gss->current_bind->list.next != &gss->binds) { + gss->current_bind = llist_entry(gss->current_bind->list.next, struct ns2_sns_bind, list); + } else { + gss->current_bind = llist_first_entry(&gss->binds, struct ns2_sns_bind, list); } - - if (!bind) - return; } + bind = gss->current_bind->bind; + /* setup the NSVC */ if (!gss->sns_nsvc) { gss->sns_nsvc = ns2_ip_bind_connect(bind, gss->nse, remote); @@ -1435,12 +1444,9 @@ return; } else if (!gss->initial) { gss->initial = llist_first_entry(&gss->sns_endpoints, struct sns_endpoint, list); - gss->bind_offset = 0; } else if (gss->initial->list.next == &gss->sns_endpoints) { /* last entry, continue with first */ gss->initial = llist_first_entry(&gss->sns_endpoints, struct sns_endpoint, list); - gss->bind_offset++; - gss->bind_offset %= ns2_ip_count_bind(nse->nsi, &gss->initial->saddr); } else { /* next element is an entry */ gss->initial = llist_entry(gss->initial->list.next, struct sns_endpoint, list); @@ -1488,6 +1494,7 @@ fi->priv = gss; gss->nse = nse; INIT_LLIST_HEAD(&gss->sns_endpoints); + INIT_LLIST_HEAD(&gss->binds); return fi; err: @@ -1810,6 +1817,88 @@ } } +int ns2_sns_add_bind(struct gprs_ns2_nse *nse, + struct gprs_ns2_vc_bind *bind) +{ + struct ns2_sns_state *gss; + struct ns2_sns_bind *tmp; + bool trigger_reselection = false; + + OSMO_ASSERT(nse->bss_sns_fi); + gss = nse->bss_sns_fi->priv; + + if (!gprs_ns2_is_ip_bind(bind)) { + return -EINVAL; + } + + if (!llist_empty(&gss->binds)) { + llist_for_each_entry(tmp, &gss->binds, list) { + if (tmp->bind == bind) + return -EALREADY; + } + } else { + trigger_reselection = true; + } + + tmp = talloc_zero(gss, struct ns2_sns_bind); + if (!tmp) + return -ENOMEM; + tmp->bind = bind; + llist_add_tail(&tmp->list, &gss->binds); + + if (trigger_reselection) { + osmo_fsm_inst_dispatch(nse->bss_sns_fi, GPRS_SNS_EV_SELECT_ENDPOINT, NULL); + } else { + /* TODO: do a add SNS-IP procedure & add nsvc() */ + } + + return 0; +} + +/* Remove a bind from the SNS. All assosiated NSVC must be removed. */ +int ns2_sns_remove_bind(struct gprs_ns2_nse *nse, + struct gprs_ns2_vc_bind *bind) +{ + struct ns2_sns_state *gss; + struct ns2_sns_bind *tmp, *tmp2; + struct gprs_ns2_vc *nsvc, *nsvc2; + bool found = false; + + if (!nse->bss_sns_fi) + return 0; + + gss = nse->bss_sns_fi->priv; + if (gss->current_bind && gss->current_bind->bind == bind) { + if (gss->current_bind->list.prev == &gss->binds) + gss->current_bind = NULL; + else + gss->current_bind = llist_entry(gss->current_bind->list.prev, struct ns2_sns_bind, list); + } + + llist_for_each_entry_safe(tmp, tmp2, &gss->binds, list) { + if (tmp->bind == bind) { + llist_del(&tmp->list); + found = true; + talloc_free(tmp); + } + } + + if (!found) + return -ENOENT; + + llist_for_each_entry_safe(nsvc, nsvc2, &nse->nsvc, list) { + if (nsvc->bind == bind) { + gprs_ns2_free_nsvc(nsvc); + } + } + + if (llist_count(&gss->binds)) { + /* TODO: do a remove SNS-IP procedure */ + } + + return 0; +} + /* Update SNS weights * \param[in] nsvc the NSVC which should be updated */ diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c index 53e5572..881761b 100644 --- a/src/gb/gprs_ns2_vty.c +++ b/src/gb/gprs_ns2_vty.c @@ -58,6 +58,7 @@ static struct gprs_ns2_inst *vty_nsi = NULL; static struct osmo_fr_network *vty_fr_network = NULL; static struct llist_head binds; +static struct llist_head nses; struct vty_bind { struct llist_head list; @@ -70,6 +71,21 @@ uint8_t ip_sns_data_weight; }; +struct vty_nse { + struct llist_head list; + uint16_t nsei; + /* list of binds which are valid for this nse. Only IP-SNS uses this + * to allow `no listen ..` in the bind context. So "half" created binds are valid for + * IP-SNS. This allows changing the bind ip without modifying all NSEs afterwards */ + struct llist_head binds; +}; + +/* used by IP-SNS to connect multiple vty_nse_bind to a vty_nse */ +struct vty_nse_bind { + struct llist_head list; + struct vty_bind *vbind; +}; + /* TODO: this should into osmo timer */ static const struct value_string gprs_ns_timer_strs[] = { { 0, "tns-block" }, @@ -135,6 +151,93 @@ talloc_free(vbind); } +static struct vty_nse *vty_nse_by_nsei(uint16_t nsei) +{ + struct vty_nse *vnse; + llist_for_each_entry(vnse, &nses, list) { + if (vnse->nsei == nsei) + return vnse; + } + return NULL; +} + +static struct vty_nse *vty_nse_alloc(uint16_t nsei) +{ + struct vty_nse *vnse = talloc_zero(vty_nsi, struct vty_nse); + if (!vnse) + return NULL; + + vnse->nsei = nsei; + INIT_LLIST_HEAD(&vnse->binds); + llist_add(&vnse->list, &nses); + return vnse; +} + +static void vty_nse_free(struct vty_nse *vnse) +{ + if (!vnse) + return; + + llist_del(&vnse->list); + talloc_free(vnse); +} + +static int vty_nse_add_vbind(struct vty_nse *vnse, struct vty_bind *vbind) +{ + struct vty_nse_bind *vnse_bind; + + if (vbind->ll != GPRS_NS2_LL_UDP) + return -EINVAL; + + llist_for_each_entry(vnse_bind, &vnse->binds, list) { + if (vnse_bind->vbind == vbind) + return -EALREADY; + } + + vnse_bind = talloc(vnse, struct vty_nse_bind); + if (!vnse_bind) + return -ENOMEM; + vnse_bind->vbind = vbind; + + llist_add_tail(&vnse->list, &vnse->binds); + return 0; +} + +static int vty_nse_remove_vbind(struct vty_nse *vnse, struct vty_bind *vbind) +{ + struct vty_nse_bind *vnse_bind, *tmp; + if (vbind->ll != GPRS_NS2_LL_UDP) + return -EINVAL; + + llist_for_each_entry_safe(vnse_bind, tmp, &vnse->binds, list) { + if (vnse_bind->vbind == vbind) { + llist_del(&vnse_bind->list); + talloc_free(vnse_bind); + } + } + + return -ENOENT; +} + +/* check if the NSE still has SNS configuration */ +static bool vty_nse_check_sns(struct gprs_ns2_nse *nse) { + struct vty_nse *vnse = vty_nse_by_nsei(nse->nsei); + + int count = gprs_ns2_sns_count(nse); + if (count > 0) { + /* there are other sns endpoints */ + return true; + } + + if (!vnse) + return false; + + if (llist_empty(&vnse->binds)) + return false; + + return true; +} + static struct cmd_node ns_node = { L_NS_NODE, "%s(config-ns)# ", @@ -172,14 +275,26 @@ ) { struct gprs_ns2_nse *nse; + struct vty_nse *vnse; uint16_t nsei = atoi(argv[0]); + bool free_vnse = false; + + vnse = vty_nse_by_nsei(nsei); + if (!vnse) { + vnse = vty_nse_alloc(nsei); + if (!vnse) { + vty_out(vty, "Failed to create vty NSE!%s", VTY_NEWLINE); + return CMD_ERR_INCOMPLETE; + } + free_vnse = true; + } nse = gprs_ns2_nse_by_nsei(vty_nsi, nsei); if (!nse) { nse = gprs_ns2_create_nse(vty_nsi, nsei, GPRS_NS2_LL_UNDEF, GPRS_NS2_DIALECT_UNDEF); if (!nse) { vty_out(vty, "Failed to create NSE!%s", VTY_NEWLINE); - return CMD_ERR_INCOMPLETE; + goto err; } nse->persistent = true; } @@ -187,13 +302,19 @@ if (!nse->persistent) { /* TODO: should the dynamic NSE removed? */ vty_out(vty, "A dynamic NSE with the specified NSEI already exists%s", VTY_NEWLINE); - return CMD_ERR_INCOMPLETE; + goto err; } vty->node = L_NS_NSE_NODE; vty->index = nse; return CMD_SUCCESS; + +err: + if (free_vnse) + talloc_free(vnse); + + return CMD_ERR_INCOMPLETE; } DEFUN(cfg_no_ns_nsei, cfg_no_ns_nsei_cmd, @@ -204,6 +325,7 @@ ) { struct gprs_ns2_nse *nse; + struct vty_nse *vnse; uint16_t nsei = atoi(argv[0]); nse = gprs_ns2_nse_by_nsei(vty_nsi, nsei); @@ -219,6 +341,10 @@ vty_out(vty, "Deleting NS Entity %u%s", nse->nsei, VTY_NEWLINE); gprs_ns2_free_nse(nse); + + vnse = vty_nse_by_nsei(nsei); + vty_nse_free(vnse); + return CMD_SUCCESS; } @@ -472,7 +598,7 @@ { struct vty_bind *vbind = vty->index; struct gprs_ns2_vc_bind *bind; - + int rc; const char *addr_str = argv[0]; unsigned int port = atoi(argv[1]); struct osmo_sockaddr_str sockaddr_str; @@ -494,8 +620,9 @@ return CMD_WARNING; } - if (gprs_ns2_ip_bind(vty_nsi, vbind->name, &sockaddr, vbind->dscp, &bind) != 0) { - vty_out(vty, "Failed to create the bind!%s", VTY_NEWLINE); + rc = gprs_ns2_ip_bind(vty_nsi, vbind->name, &sockaddr, vbind->dscp, &bind); + if (rc != 0) { + vty_out(vty, "Failed to create the bind (rc %d)!%s", rc, VTY_NEWLINE); return CMD_WARNING; } @@ -1320,7 +1447,6 @@ struct osmo_sockaddr_str remote_str; /* argv[0] */ struct osmo_sockaddr remote; uint16_t port = atoi(argv[1]); - int count; if (nse->ll != GPRS_NS2_LL_UDP) { vty_out(vty, "This NSE doesn't support UDP.%s", VTY_NEWLINE); @@ -1347,12 +1473,9 @@ return CMD_WARNING; } - count = gprs_ns2_sns_count(nse); - if (count > 0) { - /* there are other sns endpoints */ + if (vty_nse_check_sns(nse)) { + /* there is still sns configuration valid */ return CMD_SUCCESS; - } else if (count < 0) { - OSMO_ASSERT(0); } else { /* clean up nse to allow other nsvc commands */ osmo_fsm_inst_term(nse->bss_sns_fi, OSMO_FSM_TERM_REQUEST, NULL); @@ -1364,6 +1487,175 @@ return CMD_SUCCESS; } +DEFUN(cfg_ns_nse_ip_sns_bind, cfg_ns_nse_ip_sns_bind_cmd, + "ip-sns-bind BINDID", + "IP SNS binds\n" + "A udp bind which this SNS will be used. The bind must be already exists. Can be given multiple times.\n") +{ + struct gprs_ns2_nse *nse = vty->index; + struct gprs_ns2_vc_bind *bind; + struct vty_bind *vbind; + struct vty_nse *vnse; + const char *name = argv[0]; + bool ll_modified = false; + bool dialect_modified = false; + int rc; + + if (nse->ll == GPRS_NS2_LL_UNDEF) { + nse->ll = GPRS_NS2_LL_UDP; + ll_modified = true; + } + + if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) { + char sns[16]; + snprintf(sns, sizeof(sns), "NSE%05u-SNS", nse->nsei); + nse->bss_sns_fi = ns2_sns_bss_fsm_alloc(nse, sns); + if (!nse->bss_sns_fi) + goto err; + nse->dialect = GPRS_NS2_DIALECT_SNS; + dialect_modified = true; + } + + if (nse->ll != GPRS_NS2_LL_UDP) { + vty_out(vty, "Can not mix NS-VC with different link layer%s", VTY_NEWLINE); + goto err; + } + + if (nse->dialect != GPRS_NS2_DIALECT_SNS) { + vty_out(vty, "Can not mix NS-VC with different dialects%s", VTY_NEWLINE); + goto err; + } + + vbind = vty_bind_by_name(name); + if (!vbind) { + vty_out(vty, "Can not find the given bind '%s'%s", name, VTY_NEWLINE); + goto err; + } + + if (vbind->ll != GPRS_NS2_LL_UDP) { + vty_out(vty, "ip-sns-bind can only be used with UDP bind%s", + VTY_NEWLINE); + goto err; + } + + /* the vnse has been created together when creating the nse node. The parent node should check this already! */ + vnse = vty_nse_by_nsei(nse->nsei); + OSMO_ASSERT(vnse); + + rc = vty_nse_add_vbind(vnse, vbind); + switch (rc) { + case 0: + break; + case -EALREADY: + vty_out(vty, "Failed to add ip-sns-bind %s already present%s", name, VTY_NEWLINE); + goto err; + case -ENOMEM: + vty_out(vty, "Failed to add ip-sns-bind %s out of memory%s", name, VTY_NEWLINE); + goto err; + default: + vty_out(vty, "Failed to add ip-sns-bind %s! %d%s", name, rc, VTY_NEWLINE); + goto err; + } + + /* the bind might not yet created because "listen" is missing. */ + bind = gprs_ns2_bind_by_name(vty_nsi, name); + if (!bind) + return CMD_SUCCESS; + + rc = ns2_sns_add_bind(nse, bind); + switch (rc) { + case 0: + break; + case -EALREADY: + vty_out(vty, "Failed to add ip-sns-bind %s already present%s", name, VTY_NEWLINE); + goto err; + case -ENOMEM: + vty_out(vty, "Failed to add ip-sns-bind %s out of memory%s", name, VTY_NEWLINE); + goto err; + default: + vty_out(vty, "Failed to add ip-sns-bind %s! %d%s", name, rc, VTY_NEWLINE); + goto err; + } + + return CMD_SUCCESS; +err: + if (ll_modified) + nse->ll = GPRS_NS2_LL_UNDEF; + if (dialect_modified) + nse->dialect = GPRS_NS2_DIALECT_UNDEF; + + return CMD_WARNING; +} + +DEFUN(cfg_no_ns_nse_ip_sns_bind, cfg_no_ns_nse_ip_sns_bind_cmd, + "no ip-sns-bind BINDID", + NO_STR + "IP SNS binds\n" + "A udp bind which this SNS will be used.\n") +{ + struct gprs_ns2_nse *nse = vty->index; + struct gprs_ns2_vc_bind *bind; + struct vty_bind *vbind; + struct vty_nse *vnse; + const char *name = argv[0]; + int rc; + + if (nse->ll != GPRS_NS2_LL_UDP) { + vty_out(vty, "This NSE doesn't support UDP.%s", VTY_NEWLINE); + return CMD_WARNING; + } + + if (nse->dialect != GPRS_NS2_DIALECT_SNS) { + vty_out(vty, "This NSE doesn't support UDP with dialect ip-sns.%s", VTY_NEWLINE); + return CMD_WARNING; + } + + vbind = vty_bind_by_name(name); + if (!vbind) { + vty_out(vty, "Can not find the given bind '%s'%s", name, VTY_NEWLINE); + return CMD_WARNING; + } + + if (vbind->ll != GPRS_NS2_LL_UDP) { + vty_out(vty, "no ip-sns-bind can only be used with UDP bind%s", + VTY_NEWLINE); + return CMD_WARNING; + } + + /* the vnse has been created together when creating the nse node. The parent node should check this already! */ + vnse = vty_nse_by_nsei(nse->nsei); + OSMO_ASSERT(vnse); + + rc = vty_nse_remove_vbind(vnse, vbind); + switch(rc) { + case 0: + break; + case -ENOENT: + vty_out(vty, "Bind %s is not part of this NSE%s", name, VTY_NEWLINE); + return CMD_WARNING; + case -EINVAL: + vty_out(vty, "no ip-sns-bind can only be used with UDP bind%s", + VTY_NEWLINE); + return CMD_WARNING; + default: + return CMD_WARNING; + } + + /* the bind might not exists yet */ + bind = gprs_ns2_bind_by_name(vty_nsi, name); + if (bind) + ns2_sns_remove_bind(nse, bind); + + if (!vty_nse_check_sns(nse)) { + /* clean up nse to allow other nsvc commands */ + osmo_fsm_inst_term(nse->bss_sns_fi, OSMO_FSM_TERM_REQUEST, NULL); + nse->bss_sns_fi = NULL; + nse->ll = GPRS_NS2_LL_UNDEF; + nse->dialect = GPRS_NS2_DIALECT_UNDEF; + } + + return CMD_SUCCESS; +} /* non-config commands */ static void dump_nsvc(struct vty *vty, struct gprs_ns2_vc *nsvc, bool stats) @@ -1676,6 +1968,7 @@ { vty_nsi = nsi; INIT_LLIST_HEAD(&binds); + INIT_LLIST_HEAD(&nses); vty_fr_network = osmo_fr_network_alloc(nsi); if (!vty_fr_network) @@ -1737,6 +2030,8 @@ install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_nsvc_ipa_cmd); install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_ip_sns_remote_cmd); install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_ip_sns_remote_cmd); + install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_ip_sns_bind_cmd); + install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_ip_sns_bind_cmd); return 0; } -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22872 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I9ab8092bf286e7d90e92f5702a5404425e959c84 Gerrit-Change-Number: 22872 Gerrit-PatchSet: 1 Gerrit-Owner: lynxis lazus <lynxis at fe80.eu> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210212/4b7f27fd/attachment.htm>