diff options
| author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2025-09-20 12:37:06 +0200 | 
|---|---|---|
| committer | Sander Vrijders <sander@ouroboros.rocks> | 2025-09-24 08:06:47 +0200 | 
| commit | 181739aa4571b8707160b946f1e1e3a92a3c3e3b (patch) | |
| tree | eef749949d5b72ebe09d79e457870c24f05c80f8 | |
| parent | 20d1f4156394e76c7d9b08013dd04ce6fbc6f949 (diff) | |
| download | ouroboros-testing.tar.gz ouroboros-testing.zip  | |
This fixes a regression in the code path for joining a broadcast
Layer. It deprecates the qos parameter on flow_join, as the QoS is
implied by the broadcast Layer itself.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
| -rw-r--r-- | include/ouroboros/dev.h | 3 | ||||
| -rw-r--r-- | src/ipcpd/broadcast/main.c | 44 | ||||
| -rw-r--r-- | src/ipcpd/ipcp.c | 15 | ||||
| -rw-r--r-- | src/ipcpd/ipcp.h | 7 | ||||
| -rw-r--r-- | src/irmd/main.c | 6 | ||||
| -rw-r--r-- | src/lib/dev.c | 12 | ||||
| -rw-r--r-- | src/tools/obc/obc.c | 4 | 
7 files changed, 56 insertions, 35 deletions
diff --git a/include/ouroboros/dev.h b/include/ouroboros/dev.h index 6e643a2c..61464fbf 100644 --- a/include/ouroboros/dev.h +++ b/include/ouroboros/dev.h @@ -40,9 +40,8 @@ int     flow_alloc(const char *            dst_name,  int     flow_accept(qosspec_t *             qs,                      const struct timespec * timeo); -/* Returns flow descriptor, qs updates to supplied QoS. */ +/* Returns flow descriptor. */  int     flow_join(const char *            bc, -                  qosspec_t *             qs,                    const struct timespec * timeo);  int     flow_dealloc(int fd); diff --git a/src/ipcpd/broadcast/main.c b/src/ipcpd/broadcast/main.c index ebdb182c..151b38c8 100644 --- a/src/ipcpd/broadcast/main.c +++ b/src/ipcpd/broadcast/main.c @@ -36,6 +36,7 @@  #include <ouroboros/ipcp-dev.h>  #include <ouroboros/logs.h>  #include <ouroboros/notifier.h> +#include <ouroboros/np1_flow.h>  #include <ouroboros/random.h>  #include <ouroboros/rib.h>  #include <ouroboros/time.h> @@ -185,39 +186,58 @@ static int name_check(const uint8_t * dst)  {          uint8_t * buf;          size_t    len; -        int       ret; +        int       err; +        char      layer[LAYER_NAME_SIZE + 1];          len = ipcp_dir_hash_len();          buf =  malloc(len); -        if (buf == NULL) -                return -ENOMEM; +        if (buf == NULL) { +                log_err("Failed to malloc buffer."); +                err = -ENOMEM; +                goto fail_buf; +        } -        str_hash(HASH_SHA3_256, buf, ipcp_get_name()); +        err = ipcp_get_layer_name(layer); +        if (err < 0) { +                log_err("Failed to get layer name."); +                goto fail_layer; +        } -        ret = memcmp(buf, dst, len); +        str_hash(HASH_SHA3_256, buf, layer); + +        if (memcmp(buf, dst, len) < 0) { +                log_err("Hash mismatch for layer %s.", layer); +                err = -ENAME; +                goto fail_layer; +        }          free(buf); -        return ret; +        return 0; + + fail_layer: +        free(buf); + fail_buf: +        return err;  }  static int broadcast_ipcp_join(int             fd, -                               const uint8_t * dst, -                               qosspec_t       qs) +                               const uint8_t * dst)  { +        int         err;          struct conn conn;          time_t      mpl = IPCP_BROADCAST_MPL;          buffer_t    data = BUF_INIT; -        (void) qs; -          memset(&conn, 0, sizeof(conn));          conn.flow_info.fd = fd; +        conn.flow_info.qs = qos_np1; -        if (name_check(dst) != 0) { +        err = name_check(dst); +        if (err < 0) {                  log_err("Failed to check name."); -                return -1; +                return err;          }          notifier_event(NOTIFY_DT_CONN_ADD, &conn); diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index 774bfda4..ebb9b1c5 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -159,6 +159,15 @@ size_t ipcp_dir_hash_len(void)          return hash_len(ipcpd.dir_hash_algo);  } +int ipcp_get_layer_name(char * layer) +{ +        if (ipcp_get_state() < IPCP_OPERATIONAL) +                return -EIPCPSTATE; + +        strcpy(layer, ipcpd.layer_name); +        return 0; +} +  uint8_t * ipcp_hash_dup(const uint8_t * hash)  {          uint8_t * dup = malloc(hash_len(ipcpd.dir_hash_algo)); @@ -663,7 +672,6 @@ static void do_flow_alloc(pid_t            pid,  static void do_flow_join(pid_t           pid,                           int             flow_id,                           const uint8_t * dst, -                         qosspec_t       qs,                           ipcp_msg_t *    ret_msg)  {          int fd; @@ -691,7 +699,7 @@ static void do_flow_join(pid_t           pid,                  return;          } -        ret_msg->result = ipcpd.ops->ipcp_flow_join(fd, dst, qs); +        ret_msg->result = ipcpd.ops->ipcp_flow_join(fd, dst);          log_info("Finished joining layer " HASH_FMT32 ".", HASH_VAL32(dst));  } @@ -853,9 +861,8 @@ static void * mainloop(void * o)                          break;                  case IPCP_MSG_CODE__IPCP_FLOW_JOIN:                          assert(msg->hash.len == ipcp_dir_hash_len()); -                        qs = qos_spec_msg_to_s(msg->qosspec);                          do_flow_join(msg->pid, msg->flow_id, -                                     msg->hash.data, qs, &ret_msg); +                                     msg->hash.data, &ret_msg);                          break;                  case IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP:                          assert(msg->pk.len > 0 ? msg->pk.data != NULL diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h index 2c41f5b9..e8c31a32 100644 --- a/src/ipcpd/ipcp.h +++ b/src/ipcpd/ipcp.h @@ -61,8 +61,7 @@ struct ipcp_ops {                                    const buffer_t * data);          int   (* ipcp_flow_join)(int             fd, -                                 const uint8_t * dst, -                                 qosspec_t       qs); +                                 const uint8_t * dst);          int   (* ipcp_flow_alloc_resp)(int              fd,                                         int              response, @@ -95,8 +94,6 @@ void            ipcp_set_state(enum ipcp_state state);  enum ipcp_state ipcp_get_state(void); -int             ipcp_set_layer_info(const struct layer_info * info); -  /* Helper functions to handle races during flow allocation */  int             ipcp_wait_flow_req_arr(const uint8_t *  dst,                                         qosspec_t        qs, @@ -109,6 +106,8 @@ int             ipcp_wait_flow_resp(const int fd);  /* Helper functions for directory entries, could be moved */  size_t          ipcp_dir_hash_len(void); +int             ipcp_get_layer_name(char * layer); +  uint8_t *       ipcp_hash_dup(const uint8_t * hash);  void            ipcp_hash_str(char            buf[], diff --git a/src/irmd/main.c b/src/irmd/main.c index 834a7a8c..daaf4129 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1250,6 +1250,8 @@ static int flow_join(struct flow_info * flow,                  goto fail_ipcp;          } +        flow->n_1_pid = ipcp.pid; +          hash.len = hash_len((enum hash_algo) layer.dir_hash_algo);          hash.data = malloc(hash.len);          if (hash.data == NULL) { @@ -1258,6 +1260,8 @@ static int flow_join(struct flow_info * flow,                  goto fail_ipcp;          } +        str_hash((enum hash_algo) layer.dir_hash_algo, hash.data, dst); +          reg_prepare_flow_alloc(flow);          if (ipcp_flow_join(flow, hash)) { @@ -1889,7 +1893,7 @@ static irm_msg_t * do_command_msg(irm_msg_t * msg)                  abstime = abstime == NULL ? &max : abstime;                  res = flow_join(&flow, msg->dst, abstime);                  if (res == 0) -                        ret_msg->flow_info    = flow_info_s_to_msg(&flow); +                        ret_msg->flow_info = flow_info_s_to_msg(&flow);                  break;          case IRM_MSG_CODE__IRM_FLOW_DEALLOC:                  flow = flow_info_msg_to_s(msg->flow_info); diff --git a/src/lib/dev.c b/src/lib/dev.c index c0cd11a3..cb483aca 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -905,7 +905,6 @@ int flow_alloc(const char *            dst,  }  int flow_join(const char *            dst, -              qosspec_t *             qs,                const struct timespec * timeo)  {          struct flow_info flow; @@ -914,16 +913,12 @@ int flow_join(const char *            dst,          int              fd;          int              err; -#ifdef QOS_DISABLE_CRC -        if (qs != NULL) -                qs->ber = 1; -#endif          memset(&flow, 0, sizeof(flow));          flow.n_pid = getpid(); -        flow.qs    = qs == NULL ? qos_raw : *qs; +        flow.qs    = qos_np1; -        if (flow_alloc__irm_req_ser(&msg, &flow, dst, timeo)) +        if (flow_join__irm_req_ser(&msg, &flow, dst, timeo))                  return -ENOMEM;          err = send_recv_msg(&msg); @@ -936,9 +931,6 @@ int flow_join(const char *            dst,          fd = flow_init(&flow, NULL); -        if (qs != NULL) -                *qs = flow.qs; -          return fd;  } diff --git a/src/tools/obc/obc.c b/src/tools/obc/obc.c index 462cbea9..778eb8a8 100644 --- a/src/tools/obc/obc.c +++ b/src/tools/obc/obc.c @@ -63,7 +63,7 @@ static int reader_main(const char * dst)          printf("Starting a reader.\n"); -        fd = flow_join(dst, NULL, NULL); +        fd = flow_join(dst, NULL);          if (fd < 0) {                  printf("Failed to join broadcast.\n");                  return -1; @@ -91,7 +91,7 @@ static int writer_main(const char * dst,          int     fd  = 0;          size_t  len = strlen(message) + 1; -        fd = flow_join(dst, NULL, NULL); +        fd = flow_join(dst, NULL);          if (fd < 0) {                  printf("Failed to join broadcast.\n");                  return -1;  | 
