From 02bda770bdb5218cc6ae43cada7574fd49eef761 Mon Sep 17 00:00:00 2001 From: Denis Vinogradov Date: Thu, 16 Jul 2020 10:34:24 +0900 Subject: [PATCH] add SET_INTERFACE command to stroke Change-Id: Ie3b34f88a4c4ed38a4a4ec139047cb60e0cfa5f5 Signed-off-by: Denis Vinogradov --- src/libcharon/comm/comm_msg.h | 3 ++ src/libcharon/plugins/stroke/stroke_socket.c | 33 ++++++++++++++++++++ src/stroke/stroke_msg.h | 30 +++++++++++------- 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/libcharon/comm/comm_msg.h b/src/libcharon/comm/comm_msg.h index 9b3716f..ecf3bf7 100755 --- a/src/libcharon/comm/comm_msg.h +++ b/src/libcharon/comm/comm_msg.h @@ -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 diff --git a/src/libcharon/plugins/stroke/stroke_socket.c b/src/libcharon/plugins/stroke/stroke_socket.c index c2065bf..420d0df 100755 --- a/src/libcharon/plugins/stroke/stroke_socket.c +++ b/src/libcharon/plugins/stroke/stroke_socket.c @@ -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"); diff --git a/src/stroke/stroke_msg.h b/src/stroke/stroke_msg.h index 51a34a5..a84599f 100755 --- a/src/stroke/stroke_msg.h +++ b/src/stroke/stroke_msg.h @@ -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 -- 2.20.1