pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-upf/+/44074?usp=email )


Change subject: vty: Support configuring local PFCP Node ID
......................................................................

vty: Support configuring local PFCP Node ID

Related: SYS#7719
Depends: libosmo-pfcp.git Change-Id Ibfb53fddb618a4480d873ceb783e56c0a0e5fead
Change-Id: Iaba51a7f3d6b357ab6d484e073653422178adac7
---
M TODO-RELEASE
M include/osmocom/upf/up_endpoint.h
M include/osmocom/upf/upf.h
M src/osmo-upf/up_endpoint.c
M src/osmo-upf/upf.c
M src/osmo-upf/upf_vty.c
6 files changed, 41 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/74/44074/1

diff --git a/TODO-RELEASE b/TODO-RELEASE
index 0ed7189..e6caf0f 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,4 @@
 # If any interfaces have been added since the last public release: c:r:a + 1.
 # If any interfaces have been removed or changed since the last public 
release: c:r:0.
 #library       what                    description / commit summary line
+libosmo-pfcp    >0.7.0                  osmo_pfcp_ie_node_id_from_str()
diff --git a/include/osmocom/upf/up_endpoint.h 
b/include/osmocom/upf/up_endpoint.h
index 03fd23d..d96495f 100644
--- a/include/osmocom/upf/up_endpoint.h
+++ b/include/osmocom/upf/up_endpoint.h
@@ -28,6 +28,7 @@

 struct osmo_pfcp_msg;
 struct osmo_pfcp_endpoint;
+struct osmo_pfcp_ie_node_id;
 struct osmo_sockaddr;

 struct pfcp_node_peer;
@@ -48,7 +49,9 @@
        uint64_t next_up_seid_state;
 };

-struct up_endpoint *up_endpoint_alloc(void *ctx, const struct osmo_sockaddr 
*local_addr);
+struct up_endpoint *up_endpoint_alloc(void *ctx,
+                                     const struct osmo_sockaddr *local_addr,
+                                     const struct osmo_pfcp_ie_node_id 
*node_id);
 int up_endpoint_bind(struct up_endpoint *up_ep);
 void up_endpoint_free(struct up_endpoint **ep);

diff --git a/include/osmocom/upf/upf.h b/include/osmocom/upf/upf.h
index 2f25c99..c2f5bcf 100644
--- a/include/osmocom/upf/upf.h
+++ b/include/osmocom/upf/upf.h
@@ -50,6 +50,7 @@
 struct pfcp_vty_cfg {
        char *local_addr;
        uint16_t local_port;
+       char *node_id;
 };

 struct tunend_vty_cfg_dev {
diff --git a/src/osmo-upf/up_endpoint.c b/src/osmo-upf/up_endpoint.c
index e1e845f..5a1fd36 100644
--- a/src/osmo-upf/up_endpoint.c
+++ b/src/osmo-upf/up_endpoint.c
@@ -351,7 +351,9 @@
        }
 }

-struct up_endpoint *up_endpoint_alloc(void *ctx, const struct osmo_sockaddr 
*local_addr)
+struct up_endpoint *up_endpoint_alloc(void *ctx,
+                                     const struct osmo_sockaddr *local_addr,
+                                     const struct osmo_pfcp_ie_node_id 
*node_id)
 {
        struct osmo_pfcp_endpoint_cfg cfg;
        struct up_endpoint *up_ep;
@@ -361,11 +363,11 @@

        cfg = (struct osmo_pfcp_endpoint_cfg){
                .local_addr = *local_addr,
+               .local_node_id = *node_id,
                .set_msg_ctx_cb = up_endpoint_set_msg_ctx,
                .rx_msg_cb = up_endpoint_rx_cb,
                .priv = up_ep,
        };
-       osmo_pfcp_ie_node_id_from_osmo_sockaddr(&cfg.local_node_id, local_addr);

        up_ep->pfcp_ep = osmo_pfcp_endpoint_create(up_ep, &cfg);
        OSMO_ASSERT(up_ep->pfcp_ep);
diff --git a/src/osmo-upf/upf.c b/src/osmo-upf/upf.c
index 0c3a364..0dcc114 100644
--- a/src/osmo-upf/upf.c
+++ b/src/osmo-upf/upf.c
@@ -85,6 +85,8 @@
 {
        struct osmo_sockaddr_str local_addr_str;
        struct osmo_sockaddr local_addr;
+       struct osmo_pfcp_ie_node_id local_node_id;
+       int rc;

        OSMO_ASSERT(g_upf);
        OSMO_ASSERT(g_upf->pfcp.ep == NULL);
@@ -94,9 +96,24 @@
        osmo_sockaddr_str_from_str(&local_addr_str, 
g_upf->pfcp.vty_cfg.local_addr, g_upf->pfcp.vty_cfg.local_port);
        osmo_sockaddr_str_to_sockaddr(&local_addr_str, &local_addr.u.sas);

-       g_upf->pfcp.ep = up_endpoint_alloc(g_upf, &local_addr);
+       if (g_upf->pfcp.vty_cfg.node_id) {
+               rc = osmo_pfcp_ie_node_id_from_str(&local_node_id, 
g_upf->pfcp.vty_cfg.node_id);
+               if (rc < 0) {
+                       LOGP(DLPFCP, LOGL_ERROR, "PFCP: failed to parse local 
Node ID %s\n",
+                       g_upf->pfcp.vty_cfg.node_id);
+                       return rc;
+               }
+       } else { /* Pick Node ID from local PFCP address: */
+               rc = osmo_pfcp_ie_node_id_from_osmo_sockaddr(&local_node_id, 
&local_addr);
+               if (rc < 0) {
+                       LOGP(DLPFCP, LOGL_ERROR, "PFCP: failed to parse local 
Node ID from local address\n");
+                       return rc;
+               }
+       }
+
+       g_upf->pfcp.ep = up_endpoint_alloc(g_upf, &local_addr, &local_node_id);
        if (!g_upf->pfcp.ep) {
-               fprintf(stderr, "Failed to allocate PFCP endpoint.\n");
+               LOGP(DLPFCP, LOGL_ERROR, "Failed to allocate PFCP endpoint.\n");
                return -1;
        }
        return 0;
diff --git a/src/osmo-upf/upf_vty.c b/src/osmo-upf/upf_vty.c
index cc446b3..a394452 100644
--- a/src/osmo-upf/upf_vty.c
+++ b/src/osmo-upf/upf_vty.c
@@ -70,6 +70,8 @@
        vty_out(vty, "pfcp%s", VTY_NEWLINE);
        if (strcmp(UPF_PFCP_LISTEN_DEFAULT, pfcp_vty.local_addr))
                vty_out(vty, " local-addr %s%s", pfcp_vty.local_addr, 
VTY_NEWLINE);
+       if (pfcp_vty.node_id)
+               vty_out(vty, " node-id %s%s", pfcp_vty.node_id, VTY_NEWLINE);
        return CMD_SUCCESS;
 }

@@ -82,6 +84,15 @@
        return CMD_SUCCESS;
 }

+DEFUN(cfg_pfcp_node_id, cfg_pfcp_node_id_cmd,
+      "node-id (IP_ADDR|FQDN)",
+      "Set the local IP address to bind on for PFCP\n"
+      "IP address\n")
+{
+       osmo_talloc_replace_string(g_upf, &pfcp_vty.node_id, argv[0]);
+       return CMD_SUCCESS;
+}
+
 static struct cmd_node cfg_tunend_node = {
        TUNEND_NODE,
        "%s(config-tunend)# ",
@@ -614,6 +625,7 @@
        install_element(CONFIG_NODE, &cfg_pfcp_cmd);

        install_element(PFCP_NODE, &cfg_pfcp_local_addr_cmd);
+       install_element(PFCP_NODE, &cfg_pfcp_node_id_cmd);

        install_node(&cfg_tunend_node, config_write_tunend);
        install_element(CONFIG_NODE, &cfg_tunend_cmd);

--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/44074?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: Iaba51a7f3d6b357ab6d484e073653422178adac7
Gerrit-Change-Number: 44074
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>

Reply via email to