From 346b054ee32a9f7b8491f842709f72cc8d1f3f2e Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 27 Nov 2023 14:43:11 +0100 Subject: include: Store IPCP name and type in info struct The information for an IPCP is now stored in an ipcp_info struct, containing name and type. The IRM public API is not changed. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/lib/irm.c | 18 ++++++++++-------- src/lib/pb/irm.proto | 49 +++++++++++++++++++++++++++---------------------- src/lib/protobuf.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 30 deletions(-) (limited to 'src/lib') diff --git a/src/lib/irm.c b/src/lib/irm.c index 4c744e8a..ce646ae7 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -41,17 +41,19 @@ pid_t irm_create_ipcp(const char * name, enum ipcp_type type) { - irm_msg_t msg = IRM_MSG__INIT; - irm_msg_t * recv_msg = NULL; - int ret = -1; + irm_msg_t msg = IRM_MSG__INIT; + irm_msg_t * recv_msg; + int ret; + struct ipcp_info info; - if (name == NULL) + if (name == NULL || strlen(name) > IPCP_NAME_SIZE) return -EINVAL; - msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP; - msg.name = (char *) name; - msg.has_ipcp_type = true; - msg.ipcp_type = type; + info.type = type; + strcpy(info.name, name); + + msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP; + msg.ipcp_info = ipcp_info_s_to_msg(&info); recv_msg = send_recv_irm_msg(&msg); if (recv_msg == NULL) diff --git a/src/lib/pb/irm.proto b/src/lib/pb/irm.proto index f910baeb..94db28a4 100644 --- a/src/lib/pb/irm.proto +++ b/src/lib/pb/irm.proto @@ -53,6 +53,11 @@ enum irm_msg_code { IRM_REPLY = 25; } +message ipcp_info_msg { + required uint32 type = 1; + required string name = 2; +} + message ipcp_list_msg { required uint32 pid = 1; required uint32 type = 2; @@ -66,26 +71,26 @@ message name_info_msg { } message irm_msg { - required irm_msg_code code = 1; - optional string prog = 2; - optional sint32 pid = 3; - optional string name = 4; - optional uint32 ipcp_type = 5; - optional string layer = 6; - repeated string args = 7; - optional sint32 response = 8; - optional string dst = 9; - optional bytes hash = 10; - optional sint32 flow_id = 11; - optional qosspec_msg qosspec = 12; - optional ipcp_config_msg conf = 13; - optional uint32 opts = 14; - repeated ipcp_list_msg ipcps = 15; - repeated name_info_msg names = 16; - optional uint32 timeo_sec = 17; - optional uint32 timeo_nsec = 18; - optional sint32 mpl = 19; - optional string comp = 20; - optional bytes pk = 21; /* piggyback */ - optional sint32 result = 22; + required irm_msg_code code = 1; + optional string prog = 2; + optional sint32 pid = 3; + optional string name = 4; + optional ipcp_info_msg ipcp_info = 5; + optional string layer = 6; + repeated string args = 7; + optional sint32 response = 8; + optional string dst = 9; + optional bytes hash = 10; + optional sint32 flow_id = 11; + optional qosspec_msg qosspec = 12; + optional ipcp_config_msg conf = 13; + optional uint32 opts = 14; + repeated ipcp_list_msg ipcps = 15; + repeated name_info_msg names = 16; + optional uint32 timeo_sec = 17; + optional uint32 timeo_nsec = 18; + optional sint32 mpl = 19; + optional string comp = 20; + optional bytes pk = 21; /* piggyback */ + optional sint32 result = 22; } diff --git a/src/lib/protobuf.c b/src/lib/protobuf.c index 7fbcef8c..d4e02549 100644 --- a/src/lib/protobuf.c +++ b/src/lib/protobuf.c @@ -67,6 +67,45 @@ struct layer_info layer_info_msg_to_s(const layer_info_msg_t * msg) return s; } +ipcp_info_msg_t * ipcp_info_s_to_msg(const struct ipcp_info * s) +{ + ipcp_info_msg_t * msg; + + assert(s != NULL); + + msg = malloc(sizeof(*msg)); + if (msg == NULL) + goto fail_malloc; + + ipcp_info_msg__init(msg); + + msg->name = strdup(s->name); + if (msg->name == NULL) + goto fail_msg; + + msg->type = s->type; + + return msg; + fail_msg: + ipcp_info_msg__free_unpacked(msg, NULL); + fail_malloc: + return NULL; +} + +struct ipcp_info ipcp_info_msg_to_s(const ipcp_info_msg_t * msg) +{ + struct ipcp_info s; + + assert(msg != NULL); + assert(msg->name != NULL); + assert(strlen(msg->name) <= NAME_SIZE); + + s.type = msg->type; + strcpy(s.name, msg->name); + + return s; +} + dt_config_msg_t * dt_config_s_to_msg(const struct dt_config * s) { dt_config_msg_t * msg; -- cgit v1.2.3