From 961b3824bfb82ddb00f85c1a7fbed7f802f48219 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 11 Aug 2025 20:32:23 +0200 Subject: ipcpd: Configure link-state at bootstrap The link-state component had some values defined in the source such as link-state advertisement interval, link timeout period and the PFF recalculation time. These can now be configured from the config file or via "irm ipcp bootstrap" on the command line. Signed-off-by: Dimitri Staessens --- src/lib/pb/ipcp_config.proto | 21 ++++++++-- src/lib/protobuf.c | 98 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 113 insertions(+), 6 deletions(-) (limited to 'src/lib') diff --git a/src/lib/pb/ipcp_config.proto b/src/lib/pb/ipcp_config.proto index aaff599e..becc63c0 100644 --- a/src/lib/pb/ipcp_config.proto +++ b/src/lib/pb/ipcp_config.proto @@ -24,11 +24,24 @@ syntax = "proto2"; import "model.proto"; + +message ls_config_msg { + required uint32 pol = 1; + required uint32 t_recalc = 2; + required uint32 t_update = 3; + required uint32 t_timeo = 4; +} + +message routing_config_msg { + required uint32 pol = 1; + optional ls_config_msg ls = 2; +} + message dt_config_msg { - required uint32 addr_size = 1; - required uint32 eid_size = 2; - required uint32 max_ttl = 3; - required uint32 routing_type = 4; + required uint32 addr_size = 1; + required uint32 eid_size = 2; + required uint32 max_ttl = 3; + required routing_config_msg routing = 4; } message dir_dht_config_msg { diff --git a/src/lib/protobuf.c b/src/lib/protobuf.c index 70c1bc90..43ef6ac6 100644 --- a/src/lib/protobuf.c +++ b/src/lib/protobuf.c @@ -188,6 +188,95 @@ struct ipcp_info ipcp_info_msg_to_s(const ipcp_info_msg_t * msg) return s; } +ls_config_msg_t * ls_config_s_to_msg(const struct ls_config * s) +{ + ls_config_msg_t * msg; + + assert(s != NULL); + + msg = malloc(sizeof(*msg)); + if (msg == NULL) + goto fail_malloc; + + ls_config_msg__init(msg); + + msg->pol = s->pol; + msg->t_recalc = s->t_recalc; + msg->t_update = s->t_update; + msg->t_timeo = s->t_timeo; + + return msg; + + fail_malloc: + return NULL; +} + +struct ls_config ls_config_msg_to_s(const ls_config_msg_t * msg) +{ + struct ls_config s; + + assert(msg != NULL); + + s.pol = msg->pol; + s.t_recalc = msg->t_recalc; + s.t_update = msg->t_update; + s.t_timeo = msg->t_timeo; + + return s; +} + +routing_config_msg_t * routing_config_s_to_msg(const struct routing_config * s) +{ + routing_config_msg_t * msg; + + assert(s != NULL); + + msg = malloc(sizeof(*msg)); + if (msg == NULL) + return NULL; + + routing_config_msg__init(msg); + + switch (s->pol) { + case ROUTING_LINK_STATE: + msg->ls = ls_config_s_to_msg(&s->ls); + if (msg->ls == NULL) + goto fail_ls; + break; + default: + /* No checks here */ + break; + } + + msg->pol = s->pol; + + return msg; + + fail_ls: + routing_config_msg__free_unpacked(msg, NULL); + return NULL; +} + +struct routing_config routing_config_msg_to_s(const routing_config_msg_t * msg) +{ + struct routing_config s; + + assert(msg != NULL); + + switch (msg->pol) { + case ROUTING_LINK_STATE: + s.ls = ls_config_msg_to_s(msg->ls); + break; + default: + /* No checks here */ + break; + } + + s.pol = msg->pol; + + return s; +} + dt_config_msg_t * dt_config_s_to_msg(const struct dt_config * s) { dt_config_msg_t * msg; @@ -203,9 +292,14 @@ dt_config_msg_t * dt_config_s_to_msg(const struct dt_config * s) msg->addr_size = s->addr_size; msg->eid_size = s->eid_size; msg->max_ttl = s->max_ttl; - msg->routing_type = s->routing_type; + msg->routing = routing_config_s_to_msg(&s->routing); + if (msg->routing == NULL) + goto fail_routing; return msg; + fail_routing: + dt_config_msg__free_unpacked(msg, NULL); + return NULL; } struct dt_config dt_config_msg_to_s(const dt_config_msg_t * msg) @@ -217,7 +311,7 @@ struct dt_config dt_config_msg_to_s(const dt_config_msg_t * msg) s.addr_size = msg->addr_size; s.eid_size = msg->eid_size; s.max_ttl = msg->max_ttl; - s.routing_type = msg->routing_type; + s.routing = routing_config_msg_to_s(msg->routing); return s; } -- cgit v1.2.3