add SET_INTERFACE command to stroke
authorDenis Vinogradov <denis.vinogradov@samsung.com>
Thu, 16 Jul 2020 01:34:24 +0000 (10:34 +0900)
committerYoojung Heo <yoojung.heo@samsung.com>
Wed, 26 Aug 2020 07:56:03 +0000 (16:56 +0900)
Change-Id: Ie3b34f88a4c4ed38a4a4ec139047cb60e0cfa5f5
Signed-off-by: Denis Vinogradov <denis.vinogradov@samsung.com>
src/libcharon/comm/comm_msg.h
src/libcharon/plugins/stroke/stroke_socket.c
src/stroke/stroke_msg.h

index 9b3716f2d192c1b56ac61fc1954b9a4401e5db30..ecf3bf731fe03d809e5e7ae9f41fa4003a1ec7bd 100755 (executable)
@@ -43,6 +43,9 @@ typedef enum {
 
        /* DELETE ROUTE */
        RES_DEL_ROUTE,
+
+       /* set interface response */
+       RES_SET_INTERFACE,
 } charon_response_type_t;
 
 #define AKA_RAND_LEN   16
index c2065bf4b050a24209e2cec8e1e354f1e2b22d43..420d0df71c5adec74ab41ed6120b6575bbde7471 100755 (executable)
@@ -674,6 +674,36 @@ static void stroke_del_route(private_stroke_socket_t *this, stroke_msg_t *msg, F
 
        charon_send_route_response(RES_DEL_ROUTE, msg);
 }
+
+static void stroke_set_interface(private_stroke_socket_t *this, stroke_msg_t *msg, FILE *out)
+{
+       enumerator_t *enumerator;
+       ike_sa_t *ike_sa;
+
+       pop_string(msg, &msg->set_interface.name);
+       pop_string(msg, &msg->set_interface.interface);
+       DBG1(DBG_CFG,"received stroke: set new interface for %s to %s\n", msg->set_interface.name, msg->set_interface.interface);
+
+       enumerator = charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager, TRUE);
+       while (enumerator->enumerate(enumerator, &ike_sa))
+       {
+               if (streq(msg->set_interface.name, ike_sa->get_name(ike_sa)))
+               {
+                       peer_cfg_t *peer_cfg = ike_sa->get_peer_cfg(ike_sa);
+                       if (peer_cfg)
+                       {
+                               /* first, update interface */
+                               peer_cfg->set_interface(peer_cfg, msg->set_interface.interface);
+
+                               /* start roaming scenario */
+                               ike_sa->roam(ike_sa, FALSE);
+                       }
+               }
+       }
+       enumerator->destroy(enumerator);
+
+       charon_send_conn_response(RES_SET_INTERFACE, msg);
+}
 #endif
 
 /**
@@ -817,6 +847,9 @@ static bool on_accept(private_stroke_socket_t *this, stream_t *stream)
                case STR_DEL_ROUTE:
                        stroke_del_route(this, msg, out);
                        break;
+               case STR_SET_INTERFACE:
+                       stroke_set_interface(this, msg, out);
+                       break;
 #endif
                default:
                        DBG1(DBG_CFG, "received unknown stroke");
index 51a34a56113a23de11f22b17ee459ac3e74408c6..a84599fee0b765bd49a4aa55fdb9b30fd8830854 100755 (executable)
@@ -29,7 +29,7 @@
 /**
  * Number of bytes by which the buffer is increased as needed
  */
-#define STROKE_BUF_LEN_INC     1024
+#define STROKE_BUF_LEN_INC        1024
 
 #ifdef VOWIFI_CFG
 typedef enum {
@@ -236,10 +236,12 @@ struct stroke_msg_t {
                /* print/reset counters */
                STR_COUNTERS,
 #ifdef VOWIFI_CFG
-               /* ADD route */
-                STR_ADD_ROUTE,
-               /* DELETE route */
-                STR_DEL_ROUTE,
+               /* ADD route */
+               STR_ADD_ROUTE,
+               /* DELETE route */
+               STR_DEL_ROUTE,
+               /* set new interface */
+               STR_SET_INTERFACE,
 #endif
                /* more to come */
        } type;
@@ -400,12 +402,18 @@ struct stroke_msg_t {
                } counters;
 
 #ifdef VOWIFI_CFG
-               /* data for STR_ADD_ROUTE, STR_DEL_ROUTE */
-               struct {
-                       char *src;
-                       char *dst;
-                       char *interface;
-               } add_route, del_route;
+               /* data for STR_ADD_ROUTE, STR_DEL_ROUTE */
+               struct {
+                       char *src;
+                       char *dst;
+                       char *interface;
+               } add_route, del_route;
+
+               /* data for STR_SET_INTERFACE */
+               struct {
+                       char *name;
+                       char *interface;
+               } set_interface;
 #endif
        };
 #ifdef VOWIFI_CFG