pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmo-sigtran/+/40535?usp=email )


Change subject: asp: Support setting TCP_USER_TIMEOUT over VTY
......................................................................

asp: Support setting TCP_USER_TIMEOUT over VTY

Change-Id: If3cbc05a304857be7030c684ffd94d929bc8dc23
---
M src/ss7_asp.c
M src/ss7_asp.h
M src/ss7_asp_vty.c
M src/ss7_xua_srv.c
M tests/vty/osmo_stp_test.vty
5 files changed, 74 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran 
refs/changes/35/40535/1

diff --git a/src/ss7_asp.c b/src/ss7_asp.c
index ca4a4c6..0fea556 100644
--- a/src/ss7_asp.c
+++ b/src/ss7_asp.c
@@ -227,7 +227,7 @@
 };
 static unsigned int g_ss7_asp_rcg_idx;

-int ss7_asp_apply_tcp_keepalive(const struct osmo_ss7_asp *asp)
+static int ss7_asp_apply_tcp_keepalive(const struct osmo_ss7_asp *asp)
 {
        uint8_t byte = 1;
        int val;
@@ -301,6 +301,38 @@
        return 0;
 }

+static int ss7_asp_apply_tcp_user_timeout(const struct osmo_ss7_asp *asp)
+{
+       int rc = 0;
+       unsigned int val;
+
+       if (!asp->cfg.tcp.user_timeout_present)
+               return 0;
+
+       LOGPASP(asp, DLSS7, LOGL_DEBUG, "Setting TCP user-timeout %u ms\n",
+               asp->cfg.tcp.user_timeout_value);
+
+       val = asp->cfg.tcp.user_timeout_value;
+       if (asp->server) {
+               rc = osmo_stream_srv_set_param(asp->server, 
OSMO_STREAM_SRV_PAR_TCP_SOCKOPT_USER_TIMEOUT,
+                                              &val, sizeof(val));
+       } else if (asp->client) {
+               rc = osmo_stream_cli_set_param(asp->client, 
OSMO_STREAM_CLI_PAR_TCP_SOCKOPT_USER_TIMEOUT,
+                                              &val, sizeof(val));
+       }
+
+       return rc;
+}
+
+int ss7_asp_apply_tcp_pars(const struct osmo_ss7_asp *asp)
+{
+       int rc;
+       rc = ss7_asp_apply_tcp_keepalive(asp);
+       if (rc < 0)
+               return rc;
+       return ss7_asp_apply_tcp_user_timeout(asp);
+}
+
 int ss7_asp_apply_new_local_address(const struct osmo_ss7_asp *asp, unsigned 
int loc_idx)
 {
        const char *new_loc_addr;
@@ -797,7 +829,7 @@

        switch (asp->cfg.trans_proto) {
        case IPPROTO_TCP:
-               (void)ss7_asp_apply_tcp_keepalive(asp);
+               (void)ss7_asp_apply_tcp_pars(asp);
                break;
        case IPPROTO_SCTP:
                (void)asp_client_apply_sctp_init_pars(asp);
diff --git a/src/ss7_asp.h b/src/ss7_asp.h
index 00c6825..6bc0201 100644
--- a/src/ss7_asp.h
+++ b/src/ss7_asp.h
@@ -135,9 +135,11 @@
                        bool keepalive_time_present;
                        bool keepalive_intvl_present;
                        bool keepalive_probes_present;
+                       bool user_timeout_present;
                        int keepalive_time_value; /* seconds */
                        int keepalive_intvl_value; /* seconds */
                        int keepalive_probes_value;
+                       unsigned int user_timeout_value; /* milliseconds */
                } tcp;

                /*! The underlaying transport protocol (one of IPPROTO_*) */
@@ -153,7 +155,7 @@
 int ss7_asp_get_fd(const struct osmo_ss7_asp *asp);
 int ss7_asp_disconnect_stream(struct osmo_ss7_asp *asp);

-int ss7_asp_apply_tcp_keepalive(const struct osmo_ss7_asp *asp);
+int ss7_asp_apply_tcp_pars(const struct osmo_ss7_asp *asp);
 int ss7_asp_apply_peer_primary_address(const struct osmo_ss7_asp *asp);
 int ss7_asp_apply_primary_address(const struct osmo_ss7_asp *asp);
 int ss7_asp_apply_new_local_address(const struct osmo_ss7_asp *asp, unsigned 
int loc_idx);
diff --git a/src/ss7_asp_vty.c b/src/ss7_asp_vty.c
index 534c1d9..0c79b0f 100644
--- a/src/ss7_asp_vty.c
+++ b/src/ss7_asp_vty.c
@@ -445,9 +445,10 @@
        return CMD_SUCCESS;
 }

+#define ASP_TCP_PARAM_DESC "Configure TCP parameters\n"
 #define ASP_TCP_PARAM_KEEPALIVE_DESC \
-       "Configure TCP parameters\n" \
-       "Configure TCP keep-alive related parameters\n" \
+       ASP_TCP_PARAM_DESC \
+       "Configure TCP keep-alive related parameters\n"

 DEFUN_ATTR(asp_tcp_param_keepalive_enabled, 
asp_tcp_param_keepalive_enabled_cmd,
           "tcp-param keepalive enabled",
@@ -520,6 +521,33 @@
        return CMD_SUCCESS;
 }

+#define ASP_TCP_PARAM_USER_TIMEOUT_DESC \
+       ASP_TCP_PARAM_DESC \
+       "Configure TCP User Timeout socket option (TCP_USER_TIMEOUT)\n"
+DEFUN_ATTR(asp_tcp_param_user_timeout, asp_tcp_param_user_timeout_cmd,
+          "tcp-param user-timeout <0-65535>",
+          ASP_TCP_PARAM_USER_TIMEOUT_DESC
+          "Value of the parameter\n",
+          CMD_ATTR_NODE_EXIT)
+{
+       struct osmo_ss7_asp *asp = vty->index;
+
+       asp->cfg.tcp.user_timeout_present = true;
+       asp->cfg.tcp.user_timeout_value = atoi(argv[0]);
+       return CMD_SUCCESS;
+}
+
+DEFUN_ATTR(asp_no_tcp_param_user_timeout, asp_no_tcp_param_user_timeout_cmd,
+          "no tcp-param user-timeout",
+          NO_STR ASP_TCP_PARAM_USER_TIMEOUT_DESC,
+          CMD_ATTR_NODE_EXIT)
+{
+       struct osmo_ss7_asp *asp = vty->index;
+       asp->cfg.tcp.user_timeout_present = false;
+       asp->cfg.tcp.user_timeout_value = 0;
+       return CMD_SUCCESS;
+}
+
 DEFUN_ATTR(asp_block, asp_block_cmd,
           "block",
           "Allows a SCTP Association with ASP, but doesn't let it become 
active\n",
@@ -1228,6 +1256,8 @@
        } else if (asp->cfg.trans_proto == IPPROTO_TCP) {
                vty_out(vty, "  no tcp-param keepalive%s", VTY_NEWLINE);
        }
+       if (asp->cfg.tcp.user_timeout_present)
+               vty_out(vty, "  tcp-param user-timeout %u%s", 
asp->cfg.tcp.user_timeout_value, VTY_NEWLINE);

        for (i = 0; i < sizeof(uint32_t) * 8; i++) {
                if (!(asp->cfg.quirks & ((uint32_t) 1 << i)))
@@ -1318,6 +1348,8 @@
        install_lib_element(L_CS7_ASP_NODE, &asp_tcp_param_keepalive_cfg_cmd);
        install_lib_element(L_CS7_ASP_NODE, &asp_no_tcp_param_keepalive_cmd);
        install_lib_element(L_CS7_ASP_NODE, 
&asp_no_tcp_param_keepalive_cfg_cmd);
+       install_lib_element(L_CS7_ASP_NODE, &asp_tcp_param_user_timeout_cmd);
+       install_lib_element(L_CS7_ASP_NODE, &asp_no_tcp_param_user_timeout_cmd);
        install_lib_element(L_CS7_ASP_NODE, &asp_quirk_cmd);
        install_lib_element(L_CS7_ASP_NODE, &asp_no_quirk_cmd);
        gen_asp_timer_xua_cmd_strs(&asp_timer_xua_cmd);
diff --git a/src/ss7_xua_srv.c b/src/ss7_xua_srv.c
index b60acf6..077eea0 100644
--- a/src/ss7_xua_srv.c
+++ b/src/ss7_xua_srv.c
@@ -193,7 +193,7 @@

        switch (asp->cfg.trans_proto) {
        case IPPROTO_TCP:
-               rc = ss7_asp_apply_tcp_keepalive(asp);
+               rc = ss7_asp_apply_tcp_pars(asp);
                break;
        case IPPROTO_SCTP:
                rc = ss7_asp_apply_peer_primary_address(asp);
diff --git a/tests/vty/osmo_stp_test.vty b/tests/vty/osmo_stp_test.vty
index b89bb30..2c5b5d8 100644
--- a/tests/vty/osmo_stp_test.vty
+++ b/tests/vty/osmo_stp_test.vty
@@ -287,6 +287,8 @@
   tcp-param keepalive (time|intvl|probes) <0-65535>
   no tcp-param keepalive
   no tcp-param keepalive (time|intvl|probes)
+  tcp-param user-timeout <0-65535>
+  no tcp-param user-timeout
   quirk (no_notify|daud_in_asp|snm_inactive)
   no quirk (no_notify|daud_in_asp|snm_inactive)
   timer xua (ack|beat) <1-999999>

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

Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: If3cbc05a304857be7030c684ffd94d929bc8dc23
Gerrit-Change-Number: 40535
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>

Reply via email to