diff options
author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2023-08-16 18:15:14 +0200 |
---|---|---|
committer | Sander Vrijders <sander@ouroboros.rocks> | 2023-08-23 13:09:11 +0200 |
commit | ab8ee0b24335790e49127b1330f9d7bcca7f6bfa (patch) | |
tree | b58fa560f7bf52d951547522f9b6d87244af3e06 /src/ipcpd | |
parent | de9674f090c2ae71cacd5f8bd6dcf5e8657ad686 (diff) | |
download | ouroboros-ab8ee0b24335790e49127b1330f9d7bcca7f6bfa.tar.gz ouroboros-ab8ee0b24335790e49127b1330f9d7bcca7f6bfa.zip |
include: Revise printing hashes
The code was a bit convoluted to print hashes as hex strings. Renamed
to HASH_FMT32 and HASH_VAL32 to make clear we are printing the first
32 bits only, and added options to print 64 up to 512 bits as well.
This doesn't depend on endianness anymore. Adds a small test for the
hash (printing) functions.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/ipcpd')
-rw-r--r-- | src/ipcpd/eth/eth.c | 11 | ||||
-rw-r--r-- | src/ipcpd/local/main.c | 11 | ||||
-rw-r--r-- | src/ipcpd/shim-data.c | 4 | ||||
-rw-r--r-- | src/ipcpd/udp/main.c | 11 | ||||
-rw-r--r-- | src/ipcpd/unicast/dir/dht.c | 1 | ||||
-rw-r--r-- | src/ipcpd/unicast/fa.c | 1 |
6 files changed, 22 insertions, 17 deletions
diff --git a/src/ipcpd/eth/eth.c b/src/ipcpd/eth/eth.c index 15082ee3..a429c0a0 100644 --- a/src/ipcpd/eth/eth.c +++ b/src/ipcpd/eth/eth.c @@ -37,6 +37,7 @@ #include "config.h" +#include <ouroboros/endian.h> #include <ouroboros/hash.h> #include <ouroboros/errno.h> #include <ouroboros/list.h> @@ -1470,7 +1471,7 @@ static int eth_ipcp_bootstrap(const struct ipcp_config * conf) #endif if (bind(eth_data.s_fd, (struct sockaddr *) ð_data.device, - sizeof(eth_data.device))) { + sizeof(eth_data.device))) { log_err("Failed to bind socket to interface."); goto fail_device; } @@ -1560,12 +1561,12 @@ static int eth_ipcp_bootstrap(const struct ipcp_config * conf) static int eth_ipcp_reg(const uint8_t * hash) { if (shim_data_reg_add_entry(eth_data.shim_data, hash)) { - log_err("Failed to add " HASH_FMT " to local registry.", - HASH_VAL(hash)); + log_err("Failed to add " HASH_FMT32 " to local registry.", + HASH_VAL32(hash)); return -1; } - log_dbg("Registered " HASH_FMT ".", HASH_VAL(hash)); + log_dbg("Registered " HASH_FMT32 ".", HASH_VAL32(hash)); return 0; } @@ -1645,7 +1646,7 @@ static int eth_ipcp_flow_alloc(int fd, uint8_t r_addr[MAC_SIZE]; uint64_t addr = 0; - log_dbg("Allocating flow to " HASH_FMT ".", HASH_VAL(hash)); + log_dbg("Allocating flow to " HASH_FMT32 ".", HASH_VAL32(hash)); assert(hash); diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 2fae01fd..e0ba04be 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -164,12 +164,12 @@ static int local_ipcp_bootstrap(const struct ipcp_config * conf) static int local_ipcp_reg(const uint8_t * hash) { if (shim_data_reg_add_entry(local_data.shim_data, hash)) { - log_dbg("Failed to add " HASH_FMT " to local registry.", - HASH_VAL(hash)); + log_dbg("Failed to add " HASH_FMT32 " to local registry.", + HASH_VAL32(hash)); return -1; } - log_info("Registered " HASH_FMT ".", HASH_VAL(hash)); + log_info("Registered " HASH_FMT32 ".", HASH_VAL32(hash)); return 0; } @@ -178,7 +178,7 @@ static int local_ipcp_unreg(const uint8_t * hash) { shim_data_reg_del_entry(local_data.shim_data, hash); - log_info("Unregistered " HASH_FMT ".", HASH_VAL(hash)); + log_info("Unregistered " HASH_FMT32 ".", HASH_VAL32(hash)); return 0; } @@ -203,7 +203,8 @@ static int local_ipcp_flow_alloc(int fd, int out_fd = -1; time_t mpl = IPCP_LOCAL_MPL; - log_dbg("Allocating flow to " HASH_FMT " on fd %d.", HASH_VAL(dst), fd); + log_dbg("Allocating flow to " HASH_FMT32 " on fd %d.", + HASH_VAL32(dst), fd); assert(dst); clock_gettime(PTHREAD_COND_CLOCK, &abstime); diff --git a/src/ipcpd/shim-data.c b/src/ipcpd/shim-data.c index 9f720e32..840b8224 100644 --- a/src/ipcpd/shim-data.c +++ b/src/ipcpd/shim-data.c @@ -297,8 +297,8 @@ int shim_data_reg_add_entry(struct shim_data * data, if (find_reg_entry_by_hash(data, hash)) { pthread_rwlock_unlock(&data->reg_lock); - log_dbg(HASH_FMT " was already in the directory.", - HASH_VAL(hash)); + log_dbg(HASH_FMT32 " was already in the directory.", + HASH_VAL32(hash)); return 0; } diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c index ee7e2f8f..62cd3181 100644 --- a/src/ipcpd/udp/main.c +++ b/src/ipcpd/udp/main.c @@ -31,6 +31,7 @@ #define OUROBOROS_PREFIX "ipcpd/udp" #include <ouroboros/bitmap.h> +#include <ouroboros/endian.h> #include <ouroboros/hash.h> #include <ouroboros/list.h> #include <ouroboros/utils.h> @@ -858,8 +859,8 @@ static int udp_ipcp_reg(const uint8_t * hash) ipcp_hash_str(hashstr, hash); if (shim_data_reg_add_entry(udp_data.shim_data, hash)) { - log_err("Failed to add " HASH_FMT " to local registry.", - HASH_VAL(hash)); + log_err("Failed to add " HASH_FMT32 " to local registry.", + HASH_VAL32(hash)); free(hashstr); return -1; } @@ -892,7 +893,7 @@ static int udp_ipcp_reg(const uint8_t * hash) } } #endif - log_dbg("Registered " HASH_FMT ".", HASH_VAL(hash)); + log_dbg("Registered " HASH_FMT32 ".", HASH_VAL32(hash)); free(hashstr); @@ -936,7 +937,7 @@ static int udp_ipcp_unreg(const uint8_t * hash) shim_data_reg_del_entry(udp_data.shim_data, hash); - log_dbg("Unregistered " HASH_FMT ".", HASH_VAL(hash)); + log_dbg("Unregistered " HASH_FMT32 ".", HASH_VAL32(hash)); free(hashstr); @@ -1009,7 +1010,7 @@ static int udp_ipcp_flow_alloc(int fd, uint32_t ip_addr = 0; char ipstr[INET_ADDRSTRLEN]; - log_dbg("Allocating flow to " HASH_FMT ".", HASH_VAL(dst)); + log_dbg("Allocating flow to " HASH_FMT32 ".", HASH_VAL32(dst)); (void) qs; diff --git a/src/ipcpd/unicast/dir/dht.c b/src/ipcpd/unicast/dir/dht.c index e97d5c5f..adc6feb2 100644 --- a/src/ipcpd/unicast/dir/dht.c +++ b/src/ipcpd/unicast/dir/dht.c @@ -31,6 +31,7 @@ #define DHT "dht" #define OUROBOROS_PREFIX DHT +#include <ouroboros/endian.h> #include <ouroboros/hash.h> #include <ouroboros/ipcp-dev.h> #include <ouroboros/bitmap.h> diff --git a/src/ipcpd/unicast/fa.c b/src/ipcpd/unicast/fa.c index 90550ebc..2591a162 100644 --- a/src/ipcpd/unicast/fa.c +++ b/src/ipcpd/unicast/fa.c @@ -31,6 +31,7 @@ #define FA "flow-allocator" #define OUROBOROS_PREFIX FA +#include <ouroboros/endian.h> #include <ouroboros/logs.h> #include <ouroboros/fqueue.h> #include <ouroboros/errno.h> |