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


Change subject: Implement ASP adm state shutdown
......................................................................

Implement ASP adm state shutdown

These commands are used to tweak administrative use of a given ASP,
tearing down the existing SCTP/TCP connection in the process of needed,
plus:
* In the case of SCTP client: avoid reconnecting until administratively
  enabled again.
* In the case of SCTP server: Immediately close incoming connections for
  that ASP until administratively enabled again.

Related: OS#6752
Change-Id: I7e4eedb65c4f2952f8b39ca4c539ca2f40e9946c
---
M include/osmocom/sigtran/osmo_ss7.h
M src/osmo_ss7_asp.c
M src/osmo_ss7_vty.c
M src/osmo_ss7_xua_srv.c
M src/ss7_asp.h
M tests/vty/osmo_stp_route_prio.vty
M tests/vty/osmo_stp_test.vty
7 files changed, 121 insertions(+), 9 deletions(-)



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

diff --git a/include/osmocom/sigtran/osmo_ss7.h 
b/include/osmocom/sigtran/osmo_ss7.h
index 0bde3d9..dc9aada 100644
--- a/include/osmocom/sigtran/osmo_ss7.h
+++ b/include/osmocom/sigtran/osmo_ss7.h
@@ -248,6 +248,7 @@
        /*! in normal operation */
        OSMO_SS7_ASP_ADM_S_ENABLED,
 };
+extern const struct value_string osmo_ss7_asp_admin_state_names[];

 enum osmo_ss7_asp_role {
        OSMO_SS7_ASP_ROLE_ASP,
diff --git a/src/osmo_ss7_asp.c b/src/osmo_ss7_asp.c
index f2d511a..56767e9 100644
--- a/src/osmo_ss7_asp.c
+++ b/src/osmo_ss7_asp.c
@@ -124,6 +124,13 @@
        { 0, NULL }
 };

+const struct value_string osmo_ss7_asp_admin_state_names[] = {
+       { OSMO_SS7_ASP_ADM_S_SHUTDOWN,  "SHUTDOWN" },
+       { OSMO_SS7_ASP_ADM_S_BLOCKED,   "BLOCKED" },
+       { OSMO_SS7_ASP_ADM_S_ENABLED,   "ENABLED" },
+       { 0, NULL }
+};
+
 const struct value_string osmo_ss7_asp_role_names[] = {
        { OSMO_SS7_ASP_ROLE_ASP,        "ASP" },
        { OSMO_SS7_ASP_ROLE_SG,         "SG" },
@@ -553,6 +560,8 @@
        }
        rate_ctr_group_set_name(asp->ctrg, name);
        asp->inst = inst;
+       /* ASP in "no shutdown" state by default: */
+       asp->cfg.adm_state = OSMO_SS7_ASP_ADM_S_ENABLED;
        ss7_asp_peer_init(&asp->cfg.remote);
        asp->cfg.remote.port = remote_port;
        ss7_asp_peer_init(&asp->cfg.local);
@@ -746,6 +755,12 @@
                return rc;
        OSMO_ASSERT(asp->fi);

+       if (asp->cfg.adm_state == OSMO_SS7_ASP_ADM_S_SHUTDOWN) {
+               LOGPASP(asp, DLSS7, LOGL_NOTICE, "Skipping start for ASP in 
administrative state %s\n",
+                       get_value_string(osmo_ss7_asp_admin_state_names, 
OSMO_SS7_ASP_ADM_S_SHUTDOWN));
+               return 0;
+       }
+
        /* Now start the new stream: */

        if (asp->cfg.is_server) {
@@ -1014,8 +1029,11 @@

 static int xua_cli_close_and_reconnect(struct osmo_stream_cli *cli)
 {
+       struct osmo_ss7_asp *asp = osmo_stream_cli_get_data(cli);
+       LOGPASP(asp, DLSS7, LOGL_NOTICE, "Closing and reconnecting ASP\n");
        xua_cli_close(cli);
-       osmo_stream_cli_reconnect(cli);
+       if (asp->cfg.adm_state != OSMO_SS7_ASP_ADM_S_SHUTDOWN)
+               osmo_stream_cli_reconnect(cli);
        return 0;
 }

diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index bf3bec2..41872fe 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -1113,6 +1113,9 @@
                asp->cfg.role = OSMO_SS7_ASP_ROLE_SG;
        }

+       /* Reset value, will be checked at osmo_ss7_vty_go_parent() */
+       asp->cfg.explicit_shutdown_state_by_vty_since_node_enter = false;
+
        vty->node = L_CS7_ASP_NODE;
        vty->index = asp;
        vty->index_sub = &asp->cfg.description;
@@ -1424,9 +1427,33 @@
           "Terminates SCTP association; New associations will be rejected\n",
           CMD_ATTR_NODE_EXIT)
 {
-       /* TODO */
-       vty_out(vty, "Not supported yet%s", VTY_NEWLINE);
-       return CMD_WARNING;
+       struct osmo_ss7_asp *asp = vty->index;
+
+       LOGPASP(asp, DLSS7, LOGL_NOTICE, "Applying Adm State change: %s -> 
%s\n",
+               get_value_string(osmo_ss7_asp_admin_state_names, 
asp->cfg.adm_state),
+               get_value_string(osmo_ss7_asp_admin_state_names, 
OSMO_SS7_ASP_ADM_S_SHUTDOWN));
+
+       asp->cfg.explicit_shutdown_state_by_vty_since_node_enter = true;
+       asp->cfg.adm_state = OSMO_SS7_ASP_ADM_S_SHUTDOWN;
+       ss7_asp_restart_after_reconfigure(asp);
+       return CMD_SUCCESS;
+}
+
+DEFUN_ATTR(asp_no_shutdown, asp_no_shutdown_cmd,
+       "no shutdown",
+       NO_STR "Terminates SCTP association; New associations will be 
rejected\n",
+       CMD_ATTR_NODE_EXIT)
+{
+       struct osmo_ss7_asp *asp = vty->index;
+
+       LOGPASP(asp, DLSS7, LOGL_NOTICE, "Applying Adm State change: %s -> 
%s\n",
+               get_value_string(osmo_ss7_asp_admin_state_names, 
asp->cfg.adm_state),
+               get_value_string(osmo_ss7_asp_admin_state_names, 
OSMO_SS7_ASP_ADM_S_ENABLED));
+
+       asp->cfg.explicit_shutdown_state_by_vty_since_node_enter = true;
+       asp->cfg.adm_state = OSMO_SS7_ASP_ADM_S_ENABLED;
+       ss7_asp_restart_after_reconfigure(asp);
+       return CMD_SUCCESS;
 }

 DEFUN_ATTR(asp_quirk, asp_quirk_cmd,
@@ -2015,6 +2042,19 @@
                vty_out(vty, "  quirk %s%s", get_value_string(asp_quirk_names, 
(1 << i)), VTY_NEWLINE);
        }
        write_asp_timers(vty, "  ", asp);
+
+       switch (asp->cfg.adm_state) {
+       case OSMO_SS7_ASP_ADM_S_SHUTDOWN:
+               vty_out(vty, "  shutdown%s", VTY_NEWLINE);
+               break;
+       case OSMO_SS7_ASP_ADM_S_BLOCKED:
+               vty_out(vty, "  blocked%s", VTY_NEWLINE);
+               break;
+       case OSMO_SS7_ASP_ADM_S_ENABLED:
+               /* Default, no need to print: */
+               vty_out(vty, "  no shutdown%s", VTY_NEWLINE);
+               break;
+       }
 }


@@ -3282,7 +3322,26 @@
        switch (vty->node) {
        case L_CS7_ASP_NODE:
                asp = vty->index;
-               ss7_asp_restart_after_reconfigure(asp);
+               if (asp->cfg.explicit_shutdown_state_by_vty_since_node_enter) {
+                       /* Interactive VTY, inform of new behavior upon use of 
new '[no] shutdown' commands: */
+                       if (vty->type != VTY_FILE)
+                               vty_out(vty, "%% NOTE: Skipping automatic 
restart of ASP since an explicit '[no] shutdown' command was entered%s", 
VTY_NEWLINE);
+                       
asp->cfg.explicit_shutdown_state_by_vty_since_node_enter = false;
+               } else if (vty->type == VTY_FILE) {
+                       /* Make sure config reading is backward compatible by 
starting the ASP if no explicit 'no shutdown' is read: */
+                       vty_out(vty,
+                               "%% VTY node 'asp' without a '[no] shutdown' 
command at the end is deprecated, "
+                               "please make sure you update your cfg file for 
future compatibility.%s",
+                               VTY_NEWLINE);
+                       ss7_asp_restart_after_reconfigure(asp);
+               } else {
+                       /* Interactive VTY without '[no] shutdown' explicit 
cmd, remind the user that we are no
+                        * longer automatically restarting the ASP when going 
out of the "asp" node: */
+                       vty_out(vty,
+                               "%% NOTE: Make sure to use '[no] shutdown' 
command in 'asp' node "
+                               "in order to restart the ASP for new configs to 
be applied.%s",
+                               VTY_NEWLINE);
+               }
                vty->node = L_CS7_NODE;
                vty->index = asp->inst;
                break;
@@ -3431,12 +3490,13 @@
        install_lib_element(L_CS7_ASP_NODE, &asp_sctp_role_cmd);
        install_lib_element(L_CS7_ASP_NODE, &asp_sctp_param_init_cmd);
        install_lib_element(L_CS7_ASP_NODE, &asp_no_sctp_param_init_cmd);
-       install_lib_element(L_CS7_ASP_NODE, &asp_block_cmd);
-       install_lib_element(L_CS7_ASP_NODE, &asp_shutdown_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_cmd_strs(&asp_timer_cmd);
        install_lib_element(L_CS7_ASP_NODE, &asp_timer_cmd);
+       install_lib_element(L_CS7_ASP_NODE, &asp_block_cmd);
+       install_lib_element(L_CS7_ASP_NODE, &asp_shutdown_cmd);
+       install_lib_element(L_CS7_ASP_NODE, &asp_no_shutdown_cmd);

        install_node(&as_node, NULL);
        install_lib_element_ve(&show_cs7_as_cmd);
diff --git a/src/osmo_ss7_xua_srv.c b/src/osmo_ss7_xua_srv.c
index 5483aae..893797a 100644
--- a/src/osmo_ss7_xua_srv.c
+++ b/src/osmo_ss7_xua_srv.c
@@ -74,6 +74,16 @@

        LOGP(DLSS7, LOGL_INFO, "%s: New %s connection accepted\n", sock_name, 
proto_name);

+       asp = ss7_asp_find_by_socket_addr(fd, oxs->cfg.trans_proto);
+       if (asp && asp->cfg.adm_state == OSMO_SS7_ASP_ADM_S_SHUTDOWN) {
+               LOGPASP(asp, DLSS7, LOGL_NOTICE,
+                       "Reject incoming new connection from %s for ASP in adm 
state %s\n",
+                       sock_name, 
get_value_string(osmo_ss7_asp_admin_state_names, asp->cfg.adm_state));
+               close(fd);
+               talloc_free(sock_name);
+               return 0;
+       }
+
        srv = osmo_stream_srv_create2(oxs, link, fd, NULL);
        if (!srv) {
                LOGP(DLSS7, LOGL_ERROR, "%s: Unable to create stream server "
@@ -107,7 +117,6 @@
        }
        osmo_stream_srv_set_closed_cb(srv, ss7_asp_xua_srv_conn_closed_cb);

-       asp = ss7_asp_find_by_socket_addr(fd, oxs->cfg.trans_proto);
        if (asp) {
                LOGP(DLSS7, LOGL_INFO, "%s: matched connection to ASP %s\n",
                        sock_name, asp->cfg.name);
diff --git a/src/ss7_asp.h b/src/ss7_asp.h
index 5dee90a..2e25f97 100644
--- a/src/ss7_asp.h
+++ b/src/ss7_asp.h
@@ -87,6 +87,12 @@
                enum osmo_ss7_asp_role role;
                bool role_set_by_vty;
                bool trans_role_set_by_vty;
+               /* Used internally by "asp" node to figure out if "no shutdown"
+                * was done explicitly, in order to avoid automatic asp
+                * reconfiguring/restart at go_parent().
+                * Can be dropped in the future once we make sure everybody uses
+                * "[no] shutdown" explicitly in cfg files. */
+               bool explicit_shutdown_state_by_vty_since_node_enter;

                struct osmo_ss7_asp_peer local;
                struct osmo_ss7_asp_peer remote;
diff --git a/tests/vty/osmo_stp_route_prio.vty 
b/tests/vty/osmo_stp_route_prio.vty
index b993cbb..1a3b516 100644
--- a/tests/vty/osmo_stp_route_prio.vty
+++ b/tests/vty/osmo_stp_route_prio.vty
@@ -6,15 +6,21 @@
 OsmoSTP(config-cs7)# asp asp1 2905 54321 m3ua
 OsmoSTP(config-cs7-asp)# remote-ip 127.0.0.110
 OsmoSTP(config-cs7-asp)# local-ip 27.0.0.1
+OsmoSTP(config-cs7-asp)# no shutdown
 OsmoSTP(config-cs7-asp)# exit
+% NOTE: Skipping automatic restart of ASP since an explicit '[no] shutdown' 
command was entered
 OsmoSTP(config-cs7)# asp asp2 2905 54321 m3ua
 OsmoSTP(config-cs7-asp)# remote-ip 127.0.0.120
 OsmoSTP(config-cs7-asp)# local-ip 27.0.0.1
+OsmoSTP(config-cs7-asp)# no shutdown
 OsmoSTP(config-cs7-asp)# exit
+% NOTE: Skipping automatic restart of ASP since an explicit '[no] shutdown' 
command was entered
 OsmoSTP(config-cs7)# asp asp3 2905 54321 m3ua
 OsmoSTP(config-cs7-asp)# remote-ip 127.0.0.130
 OsmoSTP(config-cs7-asp)# local-ip 27.0.0.1
+OsmoSTP(config-cs7-asp)# no shutdown
 OsmoSTP(config-cs7-asp)# exit
+% NOTE: Skipping automatic restart of ASP since an explicit '[no] shutdown' 
command was entered
 OsmoSTP(config-cs7)# as as1 m3ua
 OsmoSTP(config-cs7-as)# asp asp1
 OsmoSTP(config-cs7-as)# routing-key 56 0.1.2
@@ -36,16 +42,19 @@
   remote-ip 127.0.0.110
   role sg
   sctp-role server
+  no shutdown
  asp asp2 2905 54321 m3ua
   local-ip 27.0.0.1
   remote-ip 127.0.0.120
   role sg
   sctp-role server
+  no shutdown
  asp asp3 2905 54321 m3ua
   local-ip 27.0.0.1
   remote-ip 127.0.0.130
   role sg
   sctp-role server
+  no shutdown
  as as1 m3ua
   asp asp1
   routing-key 56 0.1.2
diff --git a/tests/vty/osmo_stp_test.vty b/tests/vty/osmo_stp_test.vty
index e56e0ff..de852e1 100644
--- a/tests/vty/osmo_stp_test.vty
+++ b/tests/vty/osmo_stp_test.vty
@@ -283,8 +283,12 @@
   transport-role (client|server)
   sctp-param init (num-ostreams|max-instreams|max-attempts|timeout) <0-65535>
   no sctp-param init (num-ostreams|max-instreams|max-attempts|timeout)
+  quirk (no_notify|daud_in_asp|snm_inactive)
+  no quirk (no_notify|daud_in_asp|snm_inactive)
+  timer lm (wait_asp_up|wait_notify|wait_notify_rkm|wait_rk_reg_resp) 
<1-999999>
   block
   shutdown
+  no shutdown
 ...

 OsmoSTP(config-cs7-asp)# ?
@@ -297,6 +301,8 @@
   role            Specify the xUA role for this ASP
   transport-role  Specify the transport layer role for this ASP
   sctp-param      Configure SCTP parameters
+  quirk           Enable quirk to work around interop issues
+  timer           Configure ASP default timer values
   block           Allows a SCTP Association with ASP, but doesn't let it 
become active
   shutdown        Terminates SCTP association; New associations will be 
rejected
 ...
@@ -305,6 +311,7 @@
 ...
   sctp-param  Configure SCTP parameters
   quirk       Disable quirk to work around interop issues
+  shutdown    Terminates SCTP association; New associations will be rejected
 ...

 OsmoSTP(config-cs7-asp)# remote-ip 127.0.0.200
@@ -351,8 +358,9 @@
   remote-ip 127.0.0.201
 ...
 end
+OsmoSTP(config-cs7-asp)# no shutdown
 OsmoSTP(config-cs7-asp)# exit
-
+% NOTE: Skipping automatic restart of ASP since an explicit '[no] shutdown' 
command was entered
 OsmoSTP(config-cs7)# as my-ass m3ua
 OsmoSTP(config-cs7-as)# list
 ...
@@ -594,6 +602,7 @@
   remote-ip 127.0.0.201
   role sg
   sctp-role server
+  no shutdown
  as my-ass m3ua
   asp my-asp
   routing-key 0 3.2.1

--
To view, visit https://gerrit.osmocom.org/c/libosmo-sigtran/+/40197?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: I7e4eedb65c4f2952f8b39ca4c539ca2f40e9946c
Gerrit-Change-Number: 40197
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pes...@sysmocom.de>

Reply via email to