diff options
Diffstat (limited to 'include')
46 files changed, 1320 insertions, 356 deletions
diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt index 8f248710..4e90bc59 100644 --- a/include/ouroboros/CMakeLists.txt +++ b/include/ouroboros/CMakeLists.txt @@ -8,7 +8,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sockets.h.in" "${CMAKE_CURRENT_BINARY_DIR}/sockets.h" @ONLY) set(HEADER_FILES - cacep.h + cep.h cdefs.h dev.h errno.h @@ -16,6 +16,7 @@ set(HEADER_FILES fqueue.h ipcp.h irm.h + name.h proto.h qos.h ${CMAKE_CURRENT_BINARY_DIR}/version.h diff --git a/include/ouroboros/bitmap.h b/include/ouroboros/bitmap.h index b557b3d1..04467a8a 100644 --- a/include/ouroboros/bitmap.h +++ b/include/ouroboros/bitmap.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Bitmap implementation * @@ -20,8 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_BITMAP_H -#define OUROBOROS_BITMAP_H +#ifndef OUROBOROS_LIB_BITMAP_H +#define OUROBOROS_LIB_BITMAP_H #include <stddef.h> #include <unistd.h> @@ -45,4 +45,4 @@ bool bmp_is_id_valid(struct bmp * bmp, bool bmp_is_id_used(struct bmp * bmp, ssize_t id); -#endif /* OUROBOROS_BITMAP_H */ +#endif /* OUROBOROS_LIB_BITMAP_H */ diff --git a/include/ouroboros/btree.h b/include/ouroboros/btree.h index c692ae9e..cf982856 100644 --- a/include/ouroboros/btree.h +++ b/include/ouroboros/btree.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * B-trees * diff --git a/include/ouroboros/cdefs.h b/include/ouroboros/cdefs.h index 5764fb41..f4a5dc65 100644 --- a/include/ouroboros/cdefs.h +++ b/include/ouroboros/cdefs.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * C Definitions * diff --git a/include/ouroboros/cacep.h b/include/ouroboros/cep.h index 6c11b701..4c1737f0 100644 --- a/include/ouroboros/cacep.h +++ b/include/ouroboros/cep.h @@ -1,7 +1,7 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * - * The Common Application Connection Establishment Protocol + * The Ouroboros Connection Establishment Protocol * * Dimitri Staessens <dimitri@ouroboros.rocks> * Sander Vrijders <sander@ouroboros.rocks> @@ -20,20 +20,19 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_CACEP_H -#define OUROBOROS_CACEP_H +#ifndef OUROBOROS_CEP_H +#define OUROBOROS_CEP_H #include <ouroboros/cdefs.h> #include <ouroboros/proto.h> #include <stdint.h> -#include <sys/types.h> -#define CACEP_BUF_STRLEN 64 +#define OCEP_BUF_STRLEN 128 struct conn_info { - char comp_name[CACEP_BUF_STRLEN + 1]; - char protocol[CACEP_BUF_STRLEN + 1]; + char comp_name[OCEP_BUF_STRLEN + 1]; + char protocol[OCEP_BUF_STRLEN + 1]; uint32_t pref_version; enum proto_concrete_syntax pref_syntax; struct proto_field fixed_conc_syntax[PROTO_MAX_FIELDS]; @@ -43,12 +42,12 @@ struct conn_info { __BEGIN_DECLS -int cacep_snd(int fd, - const struct conn_info * in); +int cep_snd(int fd, + const struct conn_info * in); -int cacep_rcv(int fd, - struct conn_info * out); +int cep_rcv(int fd, + struct conn_info * out); __END_DECLS -#endif /* OUROBOROS_CACEP_H */ +#endif /* OUROBOROS_CEP_H */ diff --git a/include/ouroboros/crc32.h b/include/ouroboros/crc32.h index 4a2abafa..eb610797 100644 --- a/include/ouroboros/crc32.h +++ b/include/ouroboros/crc32.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * 32-bit Cyclic Redundancy Check * @@ -20,8 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_CRC32_H -#define OUROBOROS_CRC32_H +#ifndef OUROBOROS_LIB_CRC32_H +#define OUROBOROS_LIB_CRC32_H #include <stdint.h> #include <stddef.h> @@ -32,4 +32,4 @@ void crc32(uint32_t * crc, const void * buf, size_t len); -#endif /* OUROBOROS_CRC32_H */ +#endif /* OUROBOROS_LIB_CRC32_H */ diff --git a/include/ouroboros/crypt.h b/include/ouroboros/crypt.h new file mode 100644 index 00000000..2d7cda6d --- /dev/null +++ b/include/ouroboros/crypt.h @@ -0,0 +1,114 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Cryptography + * + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_LIB_CRYPT_H +#define OUROBOROS_LIB_CRYPT_H + +#include <ouroboros/shm_du_buff.h> +#include <ouroboros/utils.h> + +#define IVSZ 16 +#define SYMMKEYSZ 32 +#define MSGBUFSZ 2048 + +struct auth_ctx; +struct crypt_ctx; + +struct crypt_ctx * crypt_create_ctx(const uint8_t * key); + +void crypt_destroy_ctx(struct crypt_ctx * ctx); + +int crypt_dh_pkp_create(void ** pkp, + uint8_t * pk); + +void crypt_dh_pkp_destroy(void * pkp); + +int crypt_dh_derive(void * pkp, + buffer_t pk, + uint8_t * s); + +int crypt_encrypt(struct crypt_ctx * ctx, + buffer_t in, + buffer_t * out); + +int crypt_decrypt(struct crypt_ctx * ctx, + buffer_t in, + buffer_t * out); + +int crypt_load_crt_file(const char * path, + void ** crt); + +int crypt_load_crt_str(const char * str, + void ** crt); + +int crypt_load_crt_der(buffer_t buf, + void ** crt); + +int crypt_get_pubkey_crt(void * crt, + void ** pk); + +void crypt_free_crt(void * crt); + +int crypt_load_privkey_file(const char * path, + void ** key); + +int crypt_load_privkey_str(const char * str, + void ** key); + +int crypt_load_pubkey_str(const char * str, + void ** key); + +int crypt_cmp_key(const void * key1, + const void * key2); + +void crypt_free_key(void * key); + +int crypt_crt_str(const void * crt, + char * buf); + +int crypt_crt_der(const void * crt, + buffer_t * buf); + +int crypt_check_crt_name(void * crt, + const char * name); + +struct auth_ctx * auth_create_ctx(void); + +void auth_destroy_ctx(struct auth_ctx * ctx); + +int auth_add_crt_to_store(struct auth_ctx * ctx, + void * crt); + +void auth_destroy_ctx(struct auth_ctx * ctx); + +int auth_verify_crt(struct auth_ctx * ctx, + void * crt); + +int auth_sign(void * pkp, + buffer_t msg, + buffer_t * sig); + +int auth_verify_sig(void * pk, + buffer_t msg, + buffer_t sig); + +#endif /* OUROBOROS_LIB_CRYPT_H */ diff --git a/include/ouroboros/dev.h b/include/ouroboros/dev.h index c402abd6..6e643a2c 100644 --- a/include/ouroboros/dev.h +++ b/include/ouroboros/dev.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * API for applications * diff --git a/include/ouroboros/endian.h b/include/ouroboros/endian.h index 530f66ba..6c3493d9 100644 --- a/include/ouroboros/endian.h +++ b/include/ouroboros/endian.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Endianness * @@ -20,9 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_ENDIAN_H -#define OUROBOROS_ENDIAN_H - +#ifndef OUROBOROS_LIB_ENDIAN_H +#define OUROBOROS_LIB_ENDIAN_H #if defined(__linux__) || defined(__CYGWIN__) || \ (defined(__MACH__) && !defined(__APPLE__)) @@ -67,10 +66,10 @@ #endif #define hton64(x) htobe64(x) -#define hton32(x) htobe32(x) #define ntoh64(x) betoh64(x) +#define hton32(x) htobe32(x) #define ntoh32(x) betoh32(x) #define hton16(x) htobe16(x) #define ntoh16(x) betoh16(x) -#endif /* OUROBOROS_ENDIAN_H */ +#endif /* OUROBOROS_LIB_ENDIAN_H */ diff --git a/include/ouroboros/errno.h b/include/ouroboros/errno.h index 06f33bef..6b808241 100644 --- a/include/ouroboros/errno.h +++ b/include/ouroboros/errno.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ouroboros specific error numbers * @@ -31,7 +31,11 @@ #define EIPCP 1003 /* Failed to communicate with IPCP */ #define EIPCPSTATE 1004 /* Target in wrong state */ #define EFLOWDOWN 1005 /* Flow is down */ -#define ECRYPT 1006 /* Encryption error */ +#define EFLOWPEER 1006 /* Flow is down (peer timed out) */ #define ENAME 1007 /* Naming error */ +#define ECRYPT 1008 /* Encryption error */ +#ifndef EAUTH /* Exists on BSD */ +#define EAUTH 1009 /* Authentication error */ +#endif #endif /* OUROBOROS_ERRNO_H */ diff --git a/include/ouroboros/fccntl.h b/include/ouroboros/fccntl.h index e9f979f3..aa2b0d14 100644 --- a/include/ouroboros/fccntl.h +++ b/include/ouroboros/fccntl.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Flow and FRCT connection control * diff --git a/include/ouroboros/flow.h b/include/ouroboros/flow.h new file mode 100644 index 00000000..77b7737e --- /dev/null +++ b/include/ouroboros/flow.h @@ -0,0 +1,54 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Flows + * + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_LIB_FLOW_H +#define OUROBOROS_LIB_FLOW_H + +#include <ouroboros/qos.h> + +#include <sys/types.h> + + enum flow_state { /* DO NOT CHANGE ORDER! */ + FLOW_INIT = 0, + FLOW_ALLOC_PENDING, + FLOW_ACCEPT_PENDING, + FLOW_ALLOCATED, + FLOW_DEALLOC_PENDING, + FLOW_DEALLOCATED, + FLOW_DESTROY, /* TODO: REMOVE! */ + FLOW_NULL +}; + +struct flow_info { + int id; + + pid_t n_pid; + pid_t n_1_pid; + + time_t mpl; + + struct qos_spec qs; + + enum flow_state state; +}; + +#endif /* OUROBOROS_LIB_FLOW_H */ diff --git a/include/ouroboros/fqueue.h b/include/ouroboros/fqueue.h index f6828a4d..8eb2ff50 100644 --- a/include/ouroboros/fqueue.h +++ b/include/ouroboros/fqueue.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Flow queues * @@ -33,7 +33,8 @@ enum fqtype { FLOW_DOWN = (1 << 1), FLOW_UP = (1 << 2), FLOW_ALLOC = (1 << 3), - FLOW_DEALLOC = (1 << 4) + FLOW_DEALLOC = (1 << 4), + FLOW_PEER = (1 << 5) }; struct flow_set; diff --git a/include/ouroboros/hash.h b/include/ouroboros/hash.h index 917856a1..c44c2c8a 100644 --- a/include/ouroboros/hash.h +++ b/include/ouroboros/hash.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Hashing functions * @@ -25,49 +25,65 @@ #include "config.h" -#include <ouroboros/endian.h> +#include <ouroboros/ipcp.h> -#ifdef HAVE_LIBGCRYPT -#include <gcrypt.h> -#endif #include <stdint.h> #include <stddef.h> /* Hash algorithms */ enum hash_algo { -#ifdef HAVE_LIBGCRYPT - HASH_CRC32 = GCRY_MD_CRC32, - HASH_MD5 = GCRY_MD_MD5, - HASH_SHA3_224 = GCRY_MD_SHA3_224, - HASH_SHA3_256 = GCRY_MD_SHA3_256, - HASH_SHA3_384 = GCRY_MD_SHA3_384, - HASH_SHA3_512 = GCRY_MD_SHA3_512 -#else - HASH_CRC32 = 0, + HASH_SHA3_224 = DIR_HASH_SHA3_224, + HASH_SHA3_256 = DIR_HASH_SHA3_256, + HASH_SHA3_384 = DIR_HASH_SHA3_384, + HASH_SHA3_512 = DIR_HASH_SHA3_512, + HASH_CRC32, HASH_MD5, - HASH_SHA3_224, - HASH_SHA3_256, - HASH_SHA3_384, - HASH_SHA3_512 -#endif }; -#define HASH_FMT "%02x%02x%02x%02x" -#define HASH_VAL(hash) \ - (betoh32(*(uint32_t *) hash) & 0xFF000000) >> 24, \ - (betoh32(*(uint32_t *) hash) & 0x00FF0000) >> 16, \ - (betoh32(*(uint32_t *) hash) & 0x0000FF00) >> 8, \ - (betoh32(*(uint32_t *) hash) & 0x000000FF) +#define HASH_FMT32 "%02x%02x%02x%02x" +#define HASH_VAL32(hash) \ + ((uint8_t *) hash)[0], ((uint8_t *) hash)[1], \ + ((uint8_t *) hash)[2], ((uint8_t *) hash)[3] + +#define HASH_FMT64 HASH_FMT32 HASH_FMT32 +#define HASH_VAL64(hash64) \ + HASH_VAL32(hash64), HASH_VAL32(hash64 + 4) + +#define HASH_FMT128 HASH_FMT64 HASH_FMT64 +#define HASH_VAL128(hash128) \ + HASH_VAL64(hash128), HASH_VAL64(hash128 + 8) + +#define HASH_FMT192 HASH_FMT128 HASH_FMT64 +#define HASH_VAL192(hash192) \ + HASH_VAL128(hash192), HASH_VAL64(hash192 + 16) + +#define HASH_FMT224 HASH_FMT128 HASH_FMT64 HASH_FMT32 +#define HASH_VAL224(hash224) \ + HASH_VAL128(hash224), HASH_VAL64(hash224 + 16), \ + HASH_VAL32(hash224 + 24) + +#define HASH_FMT256 HASH_FMT128 HASH_FMT128 +#define HASH_VAL256(hash256) \ + HASH_VAL128(hash256), HASH_VAL128(hash256 + 16) + +#define HASH_FMT384 HASH_FMT256 HASH_FMT128 +#define HASH_VAL384(hash384) \ + HASH_VAL256(hash384), HASH_VAL128(hash384 + 32) + +#define HASH_FMT512 HASH_FMT256 HASH_FMT256 +#define HASH_VAL512(hash512) \ + HASH_VAL256(hash512), HASH_VAL256(hash512 + 32) + uint16_t hash_len(enum hash_algo algo); -void mem_hash(enum hash_algo algo, - void * dst, - const uint8_t * buf, - size_t len); +void mem_hash(enum hash_algo algo, + void * dst, + const uint8_t * buf, + size_t len); -void str_hash(enum hash_algo algo, - void * dst, - const char * str); +void str_hash(enum hash_algo algo, + void * dst, + const char * str); #endif /* OUROBOROS_LIB_HASH_H */ diff --git a/include/ouroboros/ipcp-dev.h b/include/ouroboros/ipcp-dev.h index 3cd40771..35e07414 100644 --- a/include/ouroboros/ipcp-dev.h +++ b/include/ouroboros/ipcp-dev.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Additional API for IPCPs * @@ -20,24 +20,25 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#include <ouroboros/shm_rdrbuff.h> -#include <ouroboros/qoscube.h> +#ifndef OUROBOROS_LIB_IPCP_DEV_H +#define OUROBOROS_LIB_IPCP_DEV_H -#ifndef OUROBOROS_IPCP_DEV_H -#define OUROBOROS_IPCP_DEV_H +#include <ouroboros/ipcp.h> +#include <ouroboros/qoscube.h> +#include <ouroboros/shm_rdrbuff.h> +#include <ouroboros/utils.h> -int ipcp_create_r(int result); +int ipcp_create_r(const struct ipcp_info * info); -int ipcp_flow_req_arr(const uint8_t * dst, - size_t len, - qosspec_t qs, - const void * data, - size_t dlen); +int ipcp_flow_req_arr(const buffer_t * dst, + qosspec_t qs, + time_t mpl, + const buffer_t * data); -int ipcp_flow_alloc_reply(int fd, - int response, - const void * data, - size_t len); +int ipcp_flow_alloc_reply(int fd, + int response, + time_t mpl, + const buffer_t * data); int ipcp_flow_read(int fd, struct shm_du_buff ** sdb); @@ -45,6 +46,14 @@ int ipcp_flow_read(int fd, int ipcp_flow_write(int fd, struct shm_du_buff * sdb); +int np1_flow_read(int fd, + struct shm_du_buff ** sdb); + +int np1_flow_write(int fd, + struct shm_du_buff * sdb); + +int ipcp_flow_dealloc(int fd); + int ipcp_flow_fini(int fd); int ipcp_flow_get_qoscube(int fd, @@ -57,4 +66,4 @@ int ipcp_sdb_reserve(struct shm_du_buff ** sdb, void ipcp_sdb_release(struct shm_du_buff * sdb); -#endif /* OUROBOROS_IPCP_DEV_H */ +#endif /* OUROBOROS_LIB_IPCP_DEV_H */ diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index a1bdae70..c397f250 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * IPCP definitions and policies * @@ -26,77 +26,349 @@ #include <stdint.h> #include <unistd.h> #include <stdbool.h> +#include <netinet/in.h> +#include <sys/types.h> +#define IPCP_NAME_SIZE 255 #define LAYER_NAME_SIZE 255 +#define DEV_NAME_SIZE 255 -/* - * NOTE: the IRMd uses this order to select an IPCP - * for flow allocation. - */ -enum ipcp_type { +/* TODO: Move state to ipcpd/ipcp.h, requires small change to reg/ipcp.c */ +enum ipcp_state { + IPCP_NULL = 0, + IPCP_INIT, + IPCP_BOOT, + IPCP_BOOTSTRAPPED, + IPCP_ENROLLED, + IPCP_OPERATIONAL, + IPCP_SHUTDOWN +}; + +enum ipcp_type { /* IRMd uses order to select an IPCP for flow allocation. */ IPCP_LOCAL = 0, IPCP_UNICAST, IPCP_BROADCAST, IPCP_ETH_LLC, IPCP_ETH_DIX, - IPCP_UDP, + IPCP_UDP4, + IPCP_UDP6, IPCP_INVALID }; +struct ipcp_info { + enum ipcp_type type; + pid_t pid; + char name[IPCP_NAME_SIZE + 1]; + enum ipcp_state state; /* TODO: remove. */ +}; + +/* Unicast IPCP components. */ +#define DT_COMP "Data Transfer" +#define MGMT_COMP "Management" + /* Unicast IPCP policies */ enum pol_addr_auth { - ADDR_AUTH_FLAT_RANDOM = 0 + ADDR_AUTH_FLAT_RANDOM = 0, + ADDR_AUTH_INVALID +}; + +enum pol_link_state { + LS_SIMPLE = 0, + LS_LFA, + LS_ECMP, + LS_INVALID +}; + +struct ls_config { + enum pol_link_state pol; /* Link state policy */ + time_t t_recalc; /* Time to recalculate PFF (s) */ + time_t t_update; /* Time between updates (s) */ + time_t t_timeo; /* Link timeout (s) */ +}; + +static const struct ls_config default_ls_config = { + .pol = LS_SIMPLE, + .t_recalc = 4, + .t_update = 15, + .t_timeo = 60 }; enum pol_routing { ROUTING_LINK_STATE = 0, - ROUTING_LINK_STATE_LFA, - ROUTING_LINK_STATE_ECMP + ROUTING_INVALID +}; + +struct routing_config { + enum pol_routing pol; /* Routing policy */ + union { + struct ls_config ls; /* Link state config */ + /* struct pv_config pv */ /* Path vector config */ + }; +}; + +static const struct routing_config default_routing_config = { + .pol = ROUTING_LINK_STATE, + .ls = { + .pol = LS_SIMPLE, + .t_recalc = 4, + .t_update = 15, + .t_timeo = 60 + } }; enum pol_cong_avoid { CA_NONE = 0, - CA_MB_ECN + CA_MB_ECN, + CA_INVALID +}; + +struct dt_config { + struct { + uint8_t addr_size; + uint8_t eid_size; + uint8_t max_ttl; + }; + struct routing_config routing; /* Routing policy */ +}; + +static const struct dt_config default_dt_config = { + .addr_size = 4, + .eid_size = 8, + .max_ttl = 60, + .routing = { + .pol = ROUTING_LINK_STATE, + .ls = { + .pol = LS_SIMPLE, + .t_recalc = 4, + .t_update = 15, + .t_timeo = 60 + } + } +}; + +enum pol_dir { + DIR_DHT = 0, + DIR_INVALID }; enum pol_dir_hash { - DIR_HASH_SHA3_224 = 0, + DIR_HASH_SHA3_224, DIR_HASH_SHA3_256, DIR_HASH_SHA3_384, - DIR_HASH_SHA3_512 + DIR_HASH_SHA3_512, + DIR_HASH_INVALID +}; + +enum dir_dht_config_limits { + DHT_ALPHA_MIN = 1, + DHT_K_MIN = 1, + DHT_T_EXPIRE_MIN = 10, + DHT_T_REFRESH_MIN = 3, + DHT_T_REPLICATE_MIN = 3, + + DHT_ALPHA_MAX = 10, + DHT_K_MAX = 20, + DHT_T_EXPIRE_MAX = 86400, + DHT_T_REFRESH_MAX = 3600, + DHT_T_REPLICATE_MAX = 3600, }; -/* Info reported back to the IRMd about the layer on enrollment */ +struct dir_dht_config { + struct { + uint32_t alpha; /* Parallel search factor */ + uint32_t k; /* Replication factor */ + uint32_t t_expire; /* Expire time (s) */ + uint32_t t_refresh; /* Refresh time (s) */ + uint32_t t_replicate; /* Replication time (s) */ + } params; + uint64_t peer; /* Initial peer address */ +}; + +static const struct dir_dht_config default_dht_config = { + .params = { + .alpha = 3, /* Proven optimal value */ + .k = 8, /* MDHT value */ + .t_expire = 86400, /* Expire after 1 day */ + .t_refresh = 900, /* MDHT value. */ + .t_replicate = 900 /* MDHT value. */ + } +}; + +/* TODO: Move hash algorithm in directory config */ +struct dir_config { + enum pol_dir pol; + union { + struct dir_dht_config dht; + }; +}; + +static const struct dir_config default_dir_config = { + .pol = DIR_DHT, + .dht = { + .params = { + .alpha = 3, + .k = 8, + .t_expire = 86400, + .t_refresh = 900, + .t_replicate = 900 + } + } +}; + +/* IPCP configuration */ +struct uni_config { + struct dt_config dt; + struct dir_config dir; + enum pol_addr_auth addr_auth_type; + enum pol_cong_avoid cong_avoid; +}; + +static const struct uni_config default_uni_config = { + .dt = { + .addr_size = 4, + .eid_size = 8, + .max_ttl = 60, + .routing = { + .pol = ROUTING_LINK_STATE, + .ls = { + .pol = LS_SIMPLE, + .t_recalc = 4, + .t_update = 15, + .t_timeo = 60 + } + } + }, + .dir = { + .pol = DIR_DHT, + .dht = { + .params = { + .alpha = 3, + .k = 8, + .t_expire = 86400, + .t_refresh = 900, + .t_replicate = 900 + } + } + }, + .addr_auth_type = ADDR_AUTH_FLAT_RANDOM, + .cong_avoid = CA_MB_ECN +}; + +struct eth_config { + char dev[DEV_NAME_SIZE + 1]; + uint16_t ethertype; /* DIX only*/ +}; + +struct udp4_config { + struct in_addr ip_addr; + struct in_addr dns_addr; + uint16_t port; +}; + +struct udp6_config { + struct in6_addr ip_addr; + struct in6_addr dns_addr; + uint16_t port; +}; + +/* Layers */ struct layer_info { - char layer_name[LAYER_NAME_SIZE + 1]; - int dir_hash_algo; + char name[LAYER_NAME_SIZE + 1]; + /* TODO: Move this to directory info ? */ + enum pol_dir_hash dir_hash_algo; }; /* Structure to configure the first IPCP */ struct ipcp_config { - struct layer_info layer_info; + struct layer_info layer_info; + enum ipcp_type type; - enum ipcp_type type; + union { + struct uni_config unicast; + struct udp4_config udp4; + struct udp6_config udp6; + struct eth_config eth; + }; +}; - /* Unicast */ - uint8_t addr_size; - uint8_t eid_size; - uint8_t max_ttl; +/* default configurations */ +static const struct ipcp_config local_default_conf = { + .type = IPCP_LOCAL, + .layer_info = { + .dir_hash_algo = DIR_HASH_SHA3_256 + } +}; - enum pol_addr_auth addr_auth_type; - enum pol_routing routing_type; - enum pol_cong_avoid cong_avoid; +static const struct ipcp_config eth_dix_default_conf = { + .type = IPCP_ETH_DIX, + .layer_info = { + .dir_hash_algo = DIR_HASH_SHA3_256 + }, + .eth = { + .ethertype=0xA000, + } +}; + +static const struct ipcp_config eth_llc_default_conf = { + .type = IPCP_ETH_LLC, + .layer_info = { + .dir_hash_algo = DIR_HASH_SHA3_256 + } +}; - /* UDP */ - uint32_t ip_addr; - uint32_t dns_addr; - uint16_t port; +static const struct ipcp_config udp4_default_conf = { + .type = IPCP_UDP4, + .udp4 = { + .port = 3435 + } +}; - /* Ethernet */ - char * dev; +static const struct ipcp_config udp6_default_conf = { + .type = IPCP_UDP6, + .udp6 = { + .port = 3435 + } +}; + +static const struct ipcp_config uni_default_conf = { + .type = IPCP_UNICAST, + .layer_info = { + .dir_hash_algo = DIR_HASH_SHA3_256 + }, + .unicast = { + .dt = { + .addr_size = 4, + .eid_size = 8, + .max_ttl = 60, + .routing = { + .pol = ROUTING_LINK_STATE, + .ls = { + .pol = LS_SIMPLE, + .t_recalc = 4, + .t_update = 15, + .t_timeo = 60 + } + } + }, + .dir = { + .pol = DIR_DHT, + .dht = { + .params = { + .alpha = 3, + .k = 8, + .t_expire = 86400, + .t_refresh = 900, + .t_replicate = 900 + } + } + }, + .addr_auth_type = ADDR_AUTH_FLAT_RANDOM, + .cong_avoid = CA_MB_ECN + } +}; - /* Ethernet DIX */ - uint16_t ethertype; +static const struct ipcp_config bc_default_conf = { + .type = IPCP_BROADCAST }; #endif /* OUROBOROS_IPCP_H */ diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h index d2a4c263..70a21ed7 100644 --- a/include/ouroboros/irm.h +++ b/include/ouroboros/irm.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * The API to instruct the IPC Resource Manager * @@ -25,36 +25,16 @@ #include <ouroboros/cdefs.h> #include <ouroboros/ipcp.h> +#include <ouroboros/name.h> #include <ouroboros/qos.h> #include <sys/types.h> -/* Unicast IPCP components. */ -#define DT_COMP "Data Transfer" -#define MGMT_COMP "Management" - -/* Name binding options. */ -#define BIND_AUTO 0x01 - -#define NAME_SIZE 256 -#define LAYER_SIZE LAYER_NAME_SIZE - -/* Load balancing policy for incoming flows. */ -enum pol_balance { - LB_RR = 0, - LB_SPILL -}; - -struct ipcp_info { +struct ipcp_list_info { pid_t pid; enum ipcp_type type; char name[NAME_SIZE]; - char layer[LAYER_SIZE]; -}; - -struct name_info { - char name[NAME_SIZE]; - enum pol_balance pol_lb; + char layer[LAYER_NAME_SIZE]; }; __BEGIN_DECLS @@ -64,7 +44,7 @@ pid_t irm_create_ipcp(const char * name, int irm_destroy_ipcp(pid_t pid); -ssize_t irm_list_ipcps(struct ipcp_info ** ipcps); +ssize_t irm_list_ipcps(struct ipcp_list_info ** ipcps); int irm_enroll_ipcp(pid_t pid, const char * dst); @@ -96,8 +76,7 @@ int irm_bind_process(pid_t pid, int irm_unbind_process(pid_t pid, const char * name); -int irm_create_name(const char * name, - enum pol_balance pol); +int irm_create_name(struct name_info * info); int irm_destroy_name(const char * name); diff --git a/include/ouroboros/list.h b/include/ouroboros/list.h index 408aa64e..f3ea0e46 100644 --- a/include/ouroboros/list.h +++ b/include/ouroboros/list.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Simple doubly linked list implementation. * @@ -61,6 +61,6 @@ void list_del(struct list_head * e); void list_move(struct list_head * dst, struct list_head * src); -bool list_is_empty(struct list_head * h); +bool list_is_empty(const struct list_head * h); #endif /* OUROBOROS_LIB_LIST_H */ diff --git a/include/ouroboros/local-dev.h b/include/ouroboros/local-dev.h index 103fe37b..da62e31c 100644 --- a/include/ouroboros/local-dev.h +++ b/include/ouroboros/local-dev.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Optimized calls for the local IPCPs * @@ -20,12 +20,12 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_LOCAL_DEV_H -#define OUROBOROS_LOCAL_DEV_H +#ifndef OUROBOROS_LIB_LOCAL_DEV_H +#define OUROBOROS_LIB_LOCAL_DEV_H ssize_t local_flow_read(int fd); int local_flow_write(int fd, size_t idx); -#endif /* OUROBOROS_LOCAL_DEV_H */ +#endif /* OUROBOROS_LIB_LOCAL_DEV_H */ diff --git a/include/ouroboros/lockfile.h b/include/ouroboros/lockfile.h index b188d2b4..85a57313 100644 --- a/include/ouroboros/lockfile.h +++ b/include/ouroboros/lockfile.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Lockfile for Ouroboros * @@ -20,8 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_LOCKFILE_H -#define OUROBOROS_LOCKFILE_H +#ifndef OUROBOROS_LIB_LOCKFILE_H +#define OUROBOROS_LIB_LOCKFILE_H #include <sys/types.h> @@ -37,4 +37,4 @@ void lockfile_destroy(struct lockfile * lf); pid_t lockfile_owner(struct lockfile * lf); -#endif +#endif /* OUROBOROS_LIB_LOCKFILE_H */ diff --git a/include/ouroboros/logs.h b/include/ouroboros/logs.h index bffba477..f1c401fa 100644 --- a/include/ouroboros/logs.h +++ b/include/ouroboros/logs.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Logging facilities * @@ -20,56 +20,95 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_LOGS_H -#define OUROBOROS_LOGS_H - -#include <unistd.h> -#include <stdio.h> -#include <stdbool.h> -#include <syslog.h> +#ifndef OUROBOROS_LIB_LOGS_H +#define OUROBOROS_LIB_LOGS_H #ifndef OUROBOROS_PREFIX #error You must define OUROBOROS_PREFIX before including this file #endif -void log_init(bool sysout); +#include <ouroboros/hash.h> -void log_fini(void); +#include <unistd.h> +#include <stdio.h> +#include <stdbool.h> +#include <syslog.h> #define CLR_RED "\x1b[31m" #define CLR_GREEN "\x1b[32m" #define CLR_YELLOW "\x1b[33m" +#define CLR_BLUE "\x1b[34m" #define CLR_RESET "\x1b[0m" #define DEBUG_CODE "DB" #define ERROR_CODE "EE" #define WARN_CODE "WW" #define INFO_CODE "II" +#define PROTO_CODE "PP" extern bool log_syslog; -#define __olog(CLR, LVL, SYSLVL, ...) \ - do { \ - if (log_syslog) { \ - syslog(SYSLVL, OUROBOROS_PREFIX ": " \ - __VA_ARGS__); \ - } else { \ - printf(CLR "==%05d== " OUROBOROS_PREFIX \ - "(" LVL "): ", getpid()); \ - printf(__VA_ARGS__); \ - printf(CLR_RESET "\n"); \ - fflush(stdout); \ - } \ +void log_init(bool sysout); + +void log_fini(void); + + +#define __olog(CLR, LVL, SYSLVL, ...) \ + do { \ + if (log_syslog) { \ + syslog(SYSLVL, __VA_ARGS__); \ + } else { \ + printf(CLR "==%05d== " OUROBOROS_PREFIX \ + "(" LVL "): ", getpid()); \ + printf(__VA_ARGS__); \ + printf(CLR_RESET "\n"); \ + fflush(stdout); \ + } \ } while (0) -#define log_err(...) __olog(CLR_RED, ERROR_CODE, LOG_ERR, __VA_ARGS__) -#define log_warn(...) __olog(CLR_YELLOW, WARN_CODE, LOG_WARNING, __VA_ARGS__) -#define log_info(...) __olog(CLR_GREEN, INFO_CODE, LOG_INFO, __VA_ARGS__) +#define __olog_id(CLR, LVL, SYSLVL, id, fmt, ...) \ + do { \ + if (log_syslog) { \ + syslog(SYSLVL, "[" HASH_FMT64 "] " fmt, \ + HASH_VAL64(id), ## __VA_ARGS__); \ + } else { \ + printf(CLR "==%05d== " OUROBOROS_PREFIX \ + "(" LVL "): ", getpid()); \ + printf("[" HASH_FMT64 "] " fmt, \ + HASH_VAL64(id), ## __VA_ARGS__); \ + printf(CLR_RESET "\n"); \ + fflush(stdout); \ + } \ + } while (0) + +#define log_err(...) \ + __olog(CLR_RED, ERROR_CODE, LOG_ERR, __VA_ARGS__) +#define log_warn(...) \ + __olog(CLR_YELLOW, WARN_CODE, LOG_WARNING, __VA_ARGS__) +#define log_info(...) \ + __olog(CLR_GREEN, INFO_CODE, LOG_INFO, __VA_ARGS__) + + +#define log_err_id(id, fmt, ...) \ + __olog_id(CLR_RED, ERROR_CODE, LOG_ERR, id, fmt, ## __VA_ARGS__) +#define log_warn_id(id, fmt, ...) \ + __olog_id(CLR_YELLOW, WARN_CODE, LOG_WARNING, id, fmt, ## __VA_ARGS__) +#define log_info_id(id, fmt, ...) \ + __olog_id(CLR_GREEN, INFO_CODE, LOG_INFO, id, fmt, ## __VA_ARGS__) #ifdef CONFIG_OUROBOROS_DEBUG #define log_dbg(...) __olog("", DEBUG_CODE, LOG_DEBUG, __VA_ARGS__) +#define log_dbg_id(id, fmt, ...) \ + __olog_id("", DEBUG_CODE, LOG_DEBUG, id, fmt, ## __VA_ARGS__) +#define log_proto(...) __olog(CLR_BLUE, PROTO_CODE, LOG_DEBUG, __VA_ARGS__) +#define log_proto_id(id, fmt, ...) \ + __olog_id(CLR_BLUE, INFO_CODE, LOG_INFO, id, fmt, ## __VA_ARGS__) + #else #define log_dbg(...) do { } while (0) +#define log_dbg_id(...) do { } while (0) +#define log_proto(...) do { } while (0) +#define log_proto_id(...) do { } while (0) #endif -#endif /* OUROBOROS_LOGS_H */ +#endif /* OUROBOROS_LIB_LOGS_H */ diff --git a/include/ouroboros/md5.h b/include/ouroboros/md5.h index ab01996d..85a22544 100644 --- a/include/ouroboros/md5.h +++ b/include/ouroboros/md5.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * MD5 algorithm * diff --git a/include/ouroboros/name.h b/include/ouroboros/name.h new file mode 100644 index 00000000..14fdd504 --- /dev/null +++ b/include/ouroboros/name.h @@ -0,0 +1,50 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Names + * + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_NAME_H +#define OUROBOROS_NAME_H + +#define NAME_SIZE 255 +#define NAME_PATH_SIZE (NAME_SIZE + 256) +#define BIND_AUTO 0x01 + +enum pol_balance { + LB_RR = 0, + LB_SPILL, + LB_INVALID +}; + +struct name_sec_paths { + char enc[NAME_PATH_SIZE + 1]; /* path to crypt for this name */ + char key[NAME_PATH_SIZE + 1]; /* path to key for this name */ + char crt[NAME_PATH_SIZE + 1]; /* path to crt for this name */ +}; + +struct name_info { + char name[NAME_SIZE + 1]; + enum pol_balance pol_lb; + + struct name_sec_paths s; /* server */ + struct name_sec_paths c; /* client */ +}; + +#endif /* OUROBOROS_NAME_H */ diff --git a/include/ouroboros/notifier.h b/include/ouroboros/notifier.h index 429a8d97..db945f1e 100644 --- a/include/ouroboros/notifier.h +++ b/include/ouroboros/notifier.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Notifier event system using callbacks * diff --git a/include/ouroboros/np1_flow.h b/include/ouroboros/np1_flow.h index b764de91..4110ab6a 100644 --- a/include/ouroboros/np1_flow.h +++ b/include/ouroboros/np1_flow.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Adapter functions for N + 1 flow descriptors * @@ -20,20 +20,31 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_NP1_FLOW_H -#define OUROBOROS_NP1_FLOW_H +#ifndef OUROBOROS_LIB_NP1_FLOW_H +#define OUROBOROS_LIB_NP1_FLOW_H #include <ouroboros/qos.h> #include <unistd.h> -int np1_flow_alloc(pid_t n_pid, - int flow_id, - qosspec_t qs); +int np1_flow_alloc(pid_t n_pid, + int flow_id); -int np1_flow_resp(int flow_id); +int np1_flow_resp(int flow_id, + int resp); -int np1_flow_dealloc(int flow_id, +int np1_flow_dealloc(int flow_id, time_t timeo); -#endif /* OUROBOROS_NP1_FLOW_H */ +static const qosspec_t qos_np1 = { + .delay = UINT32_MAX, + .bandwidth = 0, + .availability = 0, + .loss = UINT32_MAX, + .ber = UINT32_MAX, + .in_order = 0, + .max_gap = UINT32_MAX, + .timeout = 0 +}; + +#endif /* OUROBOROS_LIB_NP1_FLOW_H */ diff --git a/include/ouroboros/proc.h b/include/ouroboros/proc.h new file mode 100644 index 00000000..80c67227 --- /dev/null +++ b/include/ouroboros/proc.h @@ -0,0 +1,44 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Processes and Programs + * + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_LIB_PROC_H +#define OUROBOROS_LIB_PROC_H + +#include <sys/types.h> + +#define PROG_NAME_SIZE 255 +#define PROG_PATH_SIZE 255 + +/* Processes */ +struct proc_info { + pid_t pid; + char prog[PROG_NAME_SIZE + 1]; /* program instantiated */ + +}; + +/* Programs */ +struct prog_info { + char name[PROG_NAME_SIZE + 1]; + char path[PROG_PATH_SIZE + 1]; +}; + +#endif /* OUROBOROS_LIB_PROC_H */ diff --git a/include/ouroboros/proto.h b/include/ouroboros/proto.h index f289e761..5c863c8b 100644 --- a/include/ouroboros/proto.h +++ b/include/ouroboros/proto.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Protocol syntax definitions * diff --git a/include/ouroboros/protobuf.h b/include/ouroboros/protobuf.h new file mode 100644 index 00000000..780d58dc --- /dev/null +++ b/include/ouroboros/protobuf.h @@ -0,0 +1,130 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Protobuf syntax conversion + * + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_LIB_PROTOBUF_H +#define OUROBOROS_LIB_PROTOBUF_H + +#include <ouroboros/flow.h> +#include <ouroboros/qos.h> +#include <ouroboros/ipcp.h> +#include <ouroboros/irm.h> +#include <ouroboros/serdes-irm.h> +#include <ouroboros/serdes-oep.h> + +#include "ipcp_config.pb-c.h" +typedef IpcpConfigMsg ipcp_config_msg_t; +typedef LsConfigMsg ls_config_msg_t; +typedef RoutingConfigMsg routing_config_msg_t; +typedef DtConfigMsg dt_config_msg_t; +typedef DirConfigMsg dir_config_msg_t; +typedef DirDhtConfigMsg dir_dht_config_msg_t; +typedef EthConfigMsg eth_config_msg_t; +typedef Udp4ConfigMsg udp4_config_msg_t; +typedef Udp6ConfigMsg udp6_config_msg_t; +typedef UniConfigMsg uni_config_msg_t; + +#include "ipcp.pb-c.h" +typedef IpcpMsg ipcp_msg_t; + +#include "irm.pb-c.h" +typedef IrmMsg irm_msg_t; +typedef TimespecMsg timespec_msg_t; +typedef IpcpInfoMsg ipcp_info_msg_t; +typedef IpcpListMsg ipcp_list_msg_t; + +#include "model.pb-c.h" +typedef FlowInfoMsg flow_info_msg_t; +typedef NameInfoMsg name_info_msg_t; +typedef LayerInfoMsg layer_info_msg_t; +typedef QosspecMsg qosspec_msg_t; + +#include "enroll.pb-c.h" +typedef EnrollReqMsg enroll_req_msg_t; +typedef EnrollRespMsg enroll_resp_msg_t; +typedef EnrollAckMsg enroll_ack_msg_t; + +/* IPCP configuration */ +timespec_msg_t * timespec_s_to_msg(const struct timespec * s); + +struct timespec timespec_msg_to_s(timespec_msg_t * msg); + +flow_info_msg_t * flow_info_s_to_msg(const struct flow_info * s); + +struct flow_info flow_info_msg_to_s(const flow_info_msg_t * msg); + +name_info_msg_t * name_info_s_to_msg(const struct name_info * s); + +struct name_info name_info_msg_to_s(const name_info_msg_t * msg); + +layer_info_msg_t * layer_info_s_to_msg(const struct layer_info * s); + +struct layer_info layer_info_msg_to_s(const layer_info_msg_t * msg); + +ipcp_info_msg_t * ipcp_info_s_to_msg(const struct ipcp_info * s); + +struct ipcp_info ipcp_info_msg_to_s(const ipcp_info_msg_t * msg); + +dt_config_msg_t * dt_config_s_to_msg(const struct dt_config * s); + +struct dt_config dt_config_msg_to_s(const dt_config_msg_t * msg); + +uni_config_msg_t * uni_config_s_to_msg(const struct uni_config * s); + +struct uni_config uni_config_msg_to_s(const uni_config_msg_t * msg); + +eth_config_msg_t * eth_config_s_to_msg(const struct eth_config * s); + +struct eth_config eth_config_msg_to_s(const eth_config_msg_t * msg); + +udp4_config_msg_t * udp4_config_s_to_msg(const struct udp4_config * s); + +struct udp4_config udp4_config_msg_to_s(const udp4_config_msg_t * msg); + +udp6_config_msg_t * udp6_config_s_to_msg(const struct udp6_config * s); + +struct udp6_config udp6_config_msg_to_s(const udp6_config_msg_t * msg); + +ipcp_config_msg_t * ipcp_config_s_to_msg(const struct ipcp_config * s); + +struct ipcp_config ipcp_config_msg_to_s(const ipcp_config_msg_t * msg); + +/* QoS */ + +qosspec_msg_t * qos_spec_s_to_msg(const struct qos_spec * s); + +struct qos_spec qos_spec_msg_to_s(const qosspec_msg_t * msg); + +/* Enrollment */ + +enroll_req_msg_t * enroll_req_s_to_msg(const struct enroll_req * s); + +struct enroll_req enroll_req_msg_to_s(const enroll_req_msg_t * msg); + +enroll_resp_msg_t * enroll_resp_s_to_msg(const struct enroll_resp * s); + +struct enroll_resp enroll_resp_msg_to_s(const enroll_resp_msg_t * msg); + +enroll_ack_msg_t * enroll_ack_s_to_msg(const struct enroll_ack * s); + +struct enroll_ack enroll_ack_msg_to_s(const enroll_ack_msg_t * msg); + +#endif /* OUROBOROS_LIB_PROTOBUF_H */ diff --git a/include/ouroboros/pthread.h b/include/ouroboros/pthread.h index 735557d2..7044cb5e 100644 --- a/include/ouroboros/pthread.h +++ b/include/ouroboros/pthread.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Useful cleanup functions for pthreads * @@ -20,20 +20,32 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_PTHREAD_H -#define OUROBOROS_PTHREAD_H +#ifndef OUROBOROS_LIB_PTHREAD_H +#define OUROBOROS_LIB_PTHREAD_H #include <pthread.h> +static int __attribute__((unused)) __timedwait(pthread_cond_t * cond, + pthread_mutex_t * mtx, + const struct timespec * abstime) +{ + if (abstime == NULL) + return pthread_cond_wait(cond, mtx); + + return pthread_cond_timedwait(cond, mtx, abstime); +} + +#if defined (_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L /* various cleanup functions for pthread_cleanup_push */ static void __attribute__((unused)) __cleanup_rwlock_unlock(void * rwlock) { pthread_rwlock_unlock((pthread_rwlock_t *) rwlock); } +#endif static void __attribute__((unused)) __cleanup_mutex_unlock(void * mutex) { pthread_mutex_unlock((pthread_mutex_t *) mutex); } -#endif /* OUROBOROS_PTHREAD_H */ +#endif /* OUROBOROS_LIB_PTHREAD_H */ diff --git a/include/ouroboros/qos.h b/include/ouroboros/qos.h index 6391347a..2be31305 100644 --- a/include/ouroboros/qos.h +++ b/include/ouroboros/qos.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Quality of Service specification * @@ -26,15 +26,17 @@ #include <stdint.h> #include <stdbool.h> +#define DEFAULT_PEER_TIMEOUT 120000 + typedef struct qos_spec { - uint32_t delay; /* In ms */ - uint64_t bandwidth; /* In bits/s */ - uint8_t availability; /* Class of 9s */ - uint32_t loss; /* Packet loss */ - uint32_t ber; /* Bit error rate, errors per billion bits */ - uint8_t in_order; /* In-order delivery, enables FRCT */ - uint32_t max_gap; /* In ms */ - uint16_t cypher_s; /* Cypher strength, 0 = no encryption */ + uint32_t delay; /* In ms. */ + uint64_t bandwidth; /* In bits/s. */ + uint8_t availability; /* Class of 9s. */ + uint32_t loss; /* Packet loss. */ + uint32_t ber; /* Bit error rate, errors per billion bits. */ + uint8_t in_order; /* In-order delivery, enables FRCT. */ + uint32_t max_gap; /* In ms. */ + uint32_t timeout; /* Peer timeout time, in ms, 0 = no timeout. */ } qosspec_t; static const qosspec_t qos_raw = { @@ -45,7 +47,7 @@ static const qosspec_t qos_raw = { .ber = 1, .in_order = 0, .max_gap = UINT32_MAX, - .cypher_s = 0 + .timeout = DEFAULT_PEER_TIMEOUT }; static const qosspec_t qos_raw_no_errors = { @@ -56,18 +58,7 @@ static const qosspec_t qos_raw_no_errors = { .ber = 0, .in_order = 0, .max_gap = UINT32_MAX, - .cypher_s = 0 -}; - -static const qosspec_t qos_raw_crypt = { - .delay = UINT32_MAX, - .bandwidth = 0, - .availability = 0, - .loss = 1, - .ber = 0, - .in_order = 0, - .max_gap = UINT32_MAX, - .cypher_s = 256 + .timeout = DEFAULT_PEER_TIMEOUT }; static const qosspec_t qos_best_effort = { @@ -78,18 +69,7 @@ static const qosspec_t qos_best_effort = { .ber = 0, .in_order = 1, .max_gap = UINT32_MAX, - .cypher_s = 0 -}; - -static const qosspec_t qos_best_effort_crypt = { - .delay = UINT32_MAX, - .bandwidth = 0, - .availability = 0, - .loss = 1, - .ber = 0, - .in_order = 1, - .max_gap = UINT32_MAX, - .cypher_s = 256 + .timeout = DEFAULT_PEER_TIMEOUT }; static const qosspec_t qos_video = { @@ -100,18 +80,7 @@ static const qosspec_t qos_video = { .ber = 0, .in_order = 1, .max_gap = 100, - .cypher_s = 0 -}; - -static const qosspec_t qos_video_crypt = { - .delay = 100, - .bandwidth = UINT64_MAX, - .availability = 3, - .loss = 1, - .ber = 0, - .in_order = 1, - .max_gap = 100, - .cypher_s = 256 + .timeout = DEFAULT_PEER_TIMEOUT }; static const qosspec_t qos_voice = { @@ -122,18 +91,7 @@ static const qosspec_t qos_voice = { .ber = 0, .in_order = 1, .max_gap = 50, - .cypher_s = 0 -}; - -static const qosspec_t qos_voice_crypt = { - .delay = 50, - .bandwidth = 100000, - .availability = 5, - .loss = 1, - .ber = 0, - .in_order = 1, - .max_gap = 50, - .cypher_s = 256 + .timeout = DEFAULT_PEER_TIMEOUT }; static const qosspec_t qos_data = { @@ -144,18 +102,7 @@ static const qosspec_t qos_data = { .ber = 0, .in_order = 1, .max_gap = 2000, - .cypher_s = 0 -}; - -static const qosspec_t qos_data_crypt = { - .delay = 1000, - .bandwidth = 0, - .availability = 0, - .loss = 0, - .ber = 0, - .in_order = 1, - .max_gap = 2000, - .cypher_s = 256 + .timeout = DEFAULT_PEER_TIMEOUT }; #endif /* OUROBOROS_QOS_H */ diff --git a/include/ouroboros/qoscube.h b/include/ouroboros/qoscube.h index 48705ffc..ed20484c 100644 --- a/include/ouroboros/qoscube.h +++ b/include/ouroboros/qoscube.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Quality of Service cubes * @@ -20,8 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_QOSCUBE_H -#define OUROBOROS_QOSCUBE_H +#ifndef OUROBOROS_LIB_QOSCUBE_H +#define OUROBOROS_LIB_QOSCUBE_H #include <ouroboros/qos.h> @@ -35,4 +35,4 @@ typedef enum qos_cube { qoscube_t qos_spec_to_cube(qosspec_t qs); qosspec_t qos_cube_to_spec(qoscube_t qc); -#endif +#endif /* OUROBOROS_LIB_QOSCUBE_H */ diff --git a/include/ouroboros/random.h b/include/ouroboros/random.h index 1f1ab057..e1b25e5d 100644 --- a/include/ouroboros/random.h +++ b/include/ouroboros/random.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Pseudo random generator * @@ -20,12 +20,12 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_RANDOM_H -#define OUROBOROS_RANDOM_H +#ifndef OUROBOROS_LIB_RANDOM_H +#define OUROBOROS_LIB_RANDOM_H #include <sys/types.h> int random_buffer(void * buf, size_t len); -#endif /* OUROBOROS_RANDOM_H */ +#endif /* OUROBOROS_LIB_RANDOM_H */ diff --git a/include/ouroboros/rib.h b/include/ouroboros/rib.h index 9eab6334..cdc5a9d5 100644 --- a/include/ouroboros/rib.h +++ b/include/ouroboros/rib.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * RIB export using FUSE * @@ -23,8 +23,10 @@ #ifndef OUROBOROS_LIB_RIB_H #define OUROBOROS_LIB_RIB_H -#define RIB_PATH_LEN 128 +#define RIB_PATH_LEN 300 #define RIB_SEPARATOR "/" +#define RIB_TM_STRLEN 26 +#define RIB_TM_FORMAT "%F %T (UTC)" #include <sys/types.h> @@ -53,4 +55,6 @@ int rib_reg(const char * path, void rib_unreg(const char * path); +void rib_cleanup(const char * mnt); + #endif /* OUROBOROS_LIB_RIB_H */ diff --git a/include/ouroboros/serdes-irm.h b/include/ouroboros/serdes-irm.h new file mode 100644 index 00000000..1d041541 --- /dev/null +++ b/include/ouroboros/serdes-irm.h @@ -0,0 +1,79 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Ouroboros IRM Protocol - serialization/deserialization + * + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_LIB_SERDES_IRM_H +#define OUROBOROS_LIB_SERDES_IRM_H + +#include <ouroboros/flow.h> +#include <ouroboros/ipcp.h> +#include <ouroboros/time.h> +#include <ouroboros/utils.h> + +#include <inttypes.h> + +int flow_alloc__irm_req_ser(buffer_t * buf, + const struct flow_info * flow, + const char * dst, + const struct timespec * timeo); + +int flow_join__irm_req_ser(buffer_t * buf, + const struct flow_info * flow, + const char * dst, + const struct timespec * timeo); + +int flow_accept__irm_req_ser(buffer_t * buf, + const struct flow_info * flow, + const struct timespec * timeo); + +int ipcp_flow_req_arr__irm_req_ser(buffer_t * buf, + const buffer_t * dst, + const struct flow_info * flow, + const buffer_t * data); + +int ipcp_flow_alloc_reply__irm_msg_ser(buffer_t * buf, + const struct flow_info * flow, + int response, + const buffer_t * data); + +/* response to alloc / join / accept / flow_req_arr */ +int flow__irm_result_des(buffer_t * buf, + struct flow_info * flow, + buffer_t * sk); + +int flow_dealloc__irm_req_ser(buffer_t * buf, + const struct flow_info * flow, + const struct timespec * timeo); + +int ipcp_flow_dealloc__irm_req_ser(buffer_t * buf, + const struct flow_info * info); + +int ipcp_create_r__irm_req_ser(buffer_t * buf, + const struct ipcp_info * ipcp); + +int proc_announce__irm_req_ser(buffer_t * buf, + const char * prog); + +int proc_exit__irm_req_ser(buffer_t * buf); + +int irm__irm_result_des(buffer_t * buf); + +#endif /* OUROBOROS_LIB_SERDES_IRM_H*/ diff --git a/include/ouroboros/serdes-oep.h b/include/ouroboros/serdes-oep.h new file mode 100644 index 00000000..af4446c1 --- /dev/null +++ b/include/ouroboros/serdes-oep.h @@ -0,0 +1,77 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Ouroboros Enrollment Protocol - serialization/deserialization + * + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_LIB_SERDES_OEP_H +#define OUROBOROS_LIB_SERDES_OEP_H + +#include <ouroboros/ipcp.h> +#include <ouroboros/utils.h> + +#include <sys/time.h> + +/* Enrollment */ + +#define ENROLL_ID_LEN 8 + +struct enroll_req { + uint8_t id[ENROLL_ID_LEN]; +}; + +struct enroll_resp { + uint8_t id[ENROLL_ID_LEN]; + struct timespec t; + int response; + struct ipcp_config conf; +}; + +struct enroll_ack { + uint8_t id[ENROLL_ID_LEN]; + int result; +}; + +ssize_t enroll_req_ser(const struct enroll_req * req, + buffer_t buf); + +int enroll_req_des(struct enroll_req * req, + const buffer_t buf); + +ssize_t enroll_resp_ser(const struct enroll_resp * resp, + buffer_t buf); + +int enroll_resp_des(struct enroll_resp * resp, + buffer_t buf); + +ssize_t enroll_ack_ser(const struct enroll_ack * ack, + buffer_t buf); + +int enroll_ack_des(struct enroll_ack * ack, + const buffer_t buf); + +#ifdef DEBUG_PROTO_OEP +void debug_enroll_req(const struct enroll_req * req); + +void debug_enroll_resp(const struct enroll_resp * resp); + +void debug_enroll_ack(const struct enroll_ack * ack); +#endif /* DEBUG_PROTO_OEP */ + +#endif /* OUROBOROS_LIB_SERDES_OEP_H*/ diff --git a/include/ouroboros/sha3.h b/include/ouroboros/sha3.h index 41967599..04871f3b 100644 --- a/include/ouroboros/sha3.h +++ b/include/ouroboros/sha3.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * SHA3 algorithm * diff --git a/include/ouroboros/shm_du_buff.h b/include/ouroboros/shm_du_buff.h index da350055..c25d4b95 100644 --- a/include/ouroboros/shm_du_buff.h +++ b/include/ouroboros/shm_du_buff.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Data Buffer element in Random Deletion Ring Buffer * @@ -20,8 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_SHM_DU_BUFF_H -#define OUROBOROS_SHM_DU_BUFF_H +#ifndef OUROBOROS_LIB_SHM_DU_BUFF_H +#define OUROBOROS_LIB_SHM_DU_BUFF_H #include <sys/types.h> #include <stdint.h> @@ -34,6 +34,8 @@ uint8_t * shm_du_buff_head(struct shm_du_buff * sdb); uint8_t * shm_du_buff_tail(struct shm_du_buff * sdb); +size_t shm_du_buff_len(struct shm_du_buff * sdb); + uint8_t * shm_du_buff_head_alloc(struct shm_du_buff * sdb, size_t size); @@ -53,4 +55,4 @@ int shm_du_buff_wait_ack(struct shm_du_buff * sdb); int shm_du_buff_ack(struct shm_du_buff * sdb); -#endif /* OUROBOROS_SHM_DU_BUFF_H */ +#endif /* OUROBOROS_LIB_SHM_DU_BUFF_H */ diff --git a/include/ouroboros/shm_flow_set.h b/include/ouroboros/shm_flow_set.h index ba085aef..09e37649 100644 --- a/include/ouroboros/shm_flow_set.h +++ b/include/ouroboros/shm_flow_set.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Management of flow_sets for fqueue * @@ -20,13 +20,18 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_SHM_FLOW_SET_H -#define OUROBOROS_SHM_FLOW_SET_H +#ifndef OUROBOROS_LIB_SHM_FLOW_SET_H +#define OUROBOROS_LIB_SHM_FLOW_SET_H #include <ouroboros/fqueue.h> #include <sys/time.h> +struct flowevent { + int flow_id; + int event; +}; + struct shm_flow_set; struct shm_flow_set * shm_flow_set_create(pid_t pid); @@ -58,7 +63,7 @@ void shm_flow_set_notify(struct shm_flow_set * set, ssize_t shm_flow_set_wait(const struct shm_flow_set * shm_set, size_t idx, - int * fqueue, + struct flowevent * fqueue, const struct timespec * abstime); -#endif /* OUROBOROS_SHM_FLOW_SET_H */ +#endif /* OUROBOROS_LIB_SHM_FLOW_SET_H */ diff --git a/include/ouroboros/shm_rbuff.h b/include/ouroboros/shm_rbuff.h index e853e487..4323d4e1 100644 --- a/include/ouroboros/shm_rbuff.h +++ b/include/ouroboros/shm_rbuff.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ring buffer for incoming packets * @@ -20,8 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_SHM_RBUFF_H -#define OUROBOROS_SHM_RBUFF_H +#ifndef OUROBOROS_LIB_SHM_RBUFF_H +#define OUROBOROS_LIB_SHM_RBUFF_H #include <sys/types.h> #include <sys/time.h> @@ -31,6 +31,7 @@ #define ACL_RDWR 0000 #define ACL_RDONLY 0001 #define ACL_FLOWDOWN 0002 +#define ACL_FLOWPEER 0004 struct shm_rbuff; @@ -65,4 +66,4 @@ ssize_t shm_rbuff_read_b(struct shm_rbuff * rb, size_t shm_rbuff_queued(struct shm_rbuff * rb); -#endif /* OUROBOROS_SHM_RBUFF_H */ +#endif /* OUROBOROS_LIB_SHM_RBUFF_H */ diff --git a/include/ouroboros/shm_rdrbuff.h b/include/ouroboros/shm_rdrbuff.h index 0bce681b..4f9a215a 100644 --- a/include/ouroboros/shm_rdrbuff.h +++ b/include/ouroboros/shm_rdrbuff.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Random Deletion Ring Buffer for Data Units * @@ -20,14 +20,14 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_SHM_RDRBUFF_H -#define OUROBOROS_SHM_RDRBUFF_H +#ifndef OUROBOROS_LIB_SHM_RDRBUFF_H +#define OUROBOROS_LIB_SHM_RDRBUFF_H #include <ouroboros/shm_du_buff.h> -#include <ouroboros/time_utils.h> +#include <ouroboros/time.h> -#include <stdint.h> #include <pthread.h> +#include <stdint.h> #include <sys/types.h> struct shm_rdrbuff; @@ -64,4 +64,4 @@ struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, size_t idx); -#endif /* OUROBOROS_SHM_RDRBUFF_H */ +#endif /* OUROBOROS_LIB_SHM_RDRBUFF_H */ diff --git a/include/ouroboros/sockets.h.in b/include/ouroboros/sockets.h.in index f1162163..1a6974ac 100644 --- a/include/ouroboros/sockets.h.in +++ b/include/ouroboros/sockets.h.in @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * The sockets layer to communicate between daemons * @@ -20,52 +20,37 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_SOCKETS_H -#define OUROBOROS_SOCKETS_H +#ifndef OUROBOROS_LIB_SOCKETS_H +#define OUROBOROS_LIB_SOCKETS_H -#include <ouroboros/qos.h> +#include <ouroboros/protobuf.h> #include <sys/types.h> -#include "ipcp_config.pb-c.h" -typedef IpcpConfigMsg ipcp_config_msg_t; -typedef LayerInfoMsg layer_info_msg_t; - -#include "irmd_messages.pb-c.h" -typedef IrmMsg irm_msg_t; -typedef IpcpInfoMsg ipcp_info_msg_t; -typedef NameInfoMsg name_info_msg_t; - -#include "ipcpd_messages.pb-c.h" -typedef IpcpMsg ipcp_msg_t; - -#include "qosspec.pb-c.h" -typedef QosspecMsg qosspec_msg_t; - -#define SOCK_PATH "/var/run/ouroboros/" -#define SOCK_PATH_SUFFIX ".sock" +#ifndef OUROBOROS_TEST + #define SOCK_PATH "/var/run/ouroboros/" +#else + #define SOCK_PATH "/tmp/" +#endif +#define SOCK_PATH_SUFFIX ".sock" -#define IRM_SOCK_PATH SOCK_PATH "irm" SOCK_PATH_SUFFIX -#define IPCP_SOCK_PATH_PREFIX SOCK_PATH "ipcp" +#define IRM_SOCK_PATH SOCK_PATH "irm" SOCK_PATH_SUFFIX +#define IPCP_SOCK_PATH_PREFIX SOCK_PATH "ipcp." -#define SOCK_BUF_SIZE @SOCK_BUF_SIZE@ +#define SOCK_BUF_SIZE @SOCK_BUF_SIZE@ -/* Returns the full socket path of an IPCP */ -char * ipcp_sock_path(pid_t pid); +char * sock_path(pid_t pid, + const char * path); int server_socket_open(char * file_name); int client_socket_open(char * file_name); -irm_msg_t * send_recv_irm_msg(irm_msg_t * msg); - - -/* qos message conversion needed in different components */ -qosspec_msg_t spec_to_msg(const qosspec_t * qs); +int send_recv_msg(buffer_t * buf); -qosspec_t msg_to_spec(const qosspec_msg_t * msg); +irm_msg_t * send_recv_irm_msg(irm_msg_t * msg); /* cleanup socket when cancelling thread */ void __cleanup_close_ptr(void * o); -#endif +#endif /* OUROBOROS_LIB_SOCKETS_H */ diff --git a/include/ouroboros/test.h b/include/ouroboros/test.h new file mode 100644 index 00000000..bccf9ccd --- /dev/null +++ b/include/ouroboros/test.h @@ -0,0 +1,93 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Test macros + * + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., http://www.fsf.org/about/contact/. + */ + +#ifndef OUROBOROS_LIB_TEST_H +#define OUROBOROS_LIB_TEST_H + +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/wait.h> +#include <sys/types.h> + +#define TEST_RC_SUCCESS 0 +#define TEST_RC_SKIP 1 +#define TEST_RC_FAIL -1 + +#define TEST_START() \ + do { \ + printf("%s started.\n", __func__); \ + fflush(stdout); \ + } while (0) +#define TEST_SUCCESS() \ + do { \ + printf("\x1b[32m%s succeeded.\x1b[0m\n", __func__); \ + fflush(stdout); \ + } while (0) + +#define TEST_SKIPPED() \ + do { \ + printf("\x1b[33m%s skipped.\x1b[0m\n", __func__); \ + fflush(stdout); \ + } while (0) + +#define TEST_FAIL() \ + do { \ + printf("\x1b[31m%s failed.\x1b[0m\n", __func__); \ + fflush(stdout); \ + } while (0) + +#define TEST_END(result) \ + do { if (result == 0) TEST_SUCCESS(); else TEST_FAIL(); } while (0) + +static int __attribute__((unused)) test_assert_fail(int(* testfunc)(void)) +{ + pid_t pid; + int wstatus; + + pid = fork(); + if (pid == -1) { + printf("Failed to fork: %s.\n", strerror(errno)); + return TEST_RC_FAIL; + } + + if (pid == 0) + return testfunc(); /* should abort */ + + waitpid(pid, &wstatus, 0); +#ifdef CONFIG_OUROBOROS_DEBUG + if (WIFSIGNALED(wstatus) && (wstatus == 134 || wstatus == 6)) + return TEST_RC_SUCCESS; + + printf("Process did not abort, status: %d.\n", wstatus); +#else + if (WIFEXITED(wstatus) && wstatus == 0) + return TEST_RC_SUCCESS; + + printf("Process did not exit, status: %d.\n", wstatus); +#endif + + return TEST_RC_FAIL; +} + +#endif /* OUROBOROS_LIB_TEST_H */ diff --git a/include/ouroboros/time_utils.h b/include/ouroboros/time.h index 6e51f305..3bd6a257 100644 --- a/include/ouroboros/time_utils.h +++ b/include/ouroboros/time.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Time utilities * @@ -20,8 +20,8 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_TIME_UTILS_H -#define OUROBOROS_TIME_UTILS_H +#ifndef OUROBOROS_LIB_TIME_H +#define OUROBOROS_LIB_TIME_H #ifdef MILLION #undef MILLION @@ -31,25 +31,38 @@ #undef BILLION #endif -#define MILLION 1000000L -#define BILLION 1000000000L +#define MILLION 1000000LL +#define BILLION 1000000000LL #include <time.h> #include <sys/time.h> +#include <sys/types.h> + +#define TIMESPEC_INIT_S(s) {(s), 0} +#define TIMESPEC_INIT_MS(ms) {(ms) / 1000, ((ms) % 1000) * MILLION} +#define TIMESPEC_INIT_US(us) {(us) / MILLION, ((us) % MILLION) * 1000} +#define TIMESPEC_INIT_NS(ns) {(ns) / BILLION, ((ns) % BILLION)} + +#define TS_TO_UINT64(ts) \ + ((uint64_t)(ts).tv_sec * BILLION + (uint64_t)(ts).tv_nsec) + +#define TIMEVAL_INIT_S(s) {(s), 0} +#define TIMEVAL_INIT_MS(ms) {(ms) / 1000, ((ms) % 1000) * 1000} +#define TIMEVAL_INIT_US(us) {(us) / MILLION, ((us) % MILLION)} /* functions for timespecs */ -#define ts_diff_ns(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * BILLION \ +#define ts_diff_ns(tx, t0) (((tx)->tv_sec - (t0)->tv_sec) * BILLION \ + ((tx)->tv_nsec - (t0)->tv_nsec)) -#define ts_diff_us(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * MILLION \ +#define ts_diff_us(tx, t0) (((tx)->tv_sec - (t0)->tv_sec) * MILLION \ + ((tx)->tv_nsec - (t0)->tv_nsec) / 1000L) -#define ts_diff_ms(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * 1000L \ +#define ts_diff_ms(tx, t0) (((tx)->tv_sec - (t0)->tv_sec) * 1000L \ + ((tx)->tv_nsec - (t0)->tv_nsec) / MILLION) /* functions for timevals are the same */ -#define tv_diff_us(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * MILLION \ +#define tv_diff_us(tx, t0) (((tx)->tv_sec - (t0)->tv_sec) * MILLION \ + + ((tx)->tv_usec - (t0)->tv_usec)) +#define tv_diff_ms(tx, t0) (((tx)->tv_sec - (t0)->tv_sec) * 1000L \ + ((tx)->tv_usec - (t0)->tv_usec) / 1000L) -#define tv_diff_ms(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * 1000L \ - + ((tx)->tv_usec - (t0)->tv_usec) / MILLION) /* functions for timespecs */ @@ -118,4 +131,4 @@ (tv)->tv_usec = (ts)->tv_nsec / 1000L; \ } while (0); -#endif /* OUROBOROS_TIME_UTILS_H */ +#endif /* OUROBOROS_LIB_TIME_H */ diff --git a/include/ouroboros/tpm.h b/include/ouroboros/tpm.h index a69549d2..3fb49b88 100644 --- a/include/ouroboros/tpm.h +++ b/include/ouroboros/tpm.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Threadpool management * @@ -38,8 +38,10 @@ int tpm_start(struct tpm * tpm); void tpm_stop(struct tpm * tpm); -void tpm_dec(struct tpm * tpm); +void tpm_begin_work(struct tpm * tpm); -void tpm_inc(struct tpm * tpm); +void tpm_wait_work(struct tpm * tpm); + +void tpm_end_work(struct tpm * tpm); #endif /* OUROBOROS_LIB_TPM_H */ diff --git a/include/ouroboros/utils.h b/include/ouroboros/utils.h index 426a143c..b93b345d 100644 --- a/include/ouroboros/utils.h +++ b/include/ouroboros/utils.h @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Handy utilities * @@ -20,21 +20,30 @@ * Foundation, Inc., http://www.fsf.org/about/contact/. */ -#ifndef OUROBOROS_UTILS_H -#define OUROBOROS_UTILS_H +#ifndef OUROBOROS_LIB_UTILS_H +#define OUROBOROS_LIB_UTILS_H #include <stdint.h> +#include <stdlib.h> +#include <string.h> #include <unistd.h> #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #define ABS(a) ((a) > 0 ? (a) : -(a)) +#define clrbuf(buf) do { memset(&(buf), 0, sizeof(buf)); } while (0); +#define freebuf(buf) do { free((buf).data); clrbuf(buf); } while (0); +#define BUF_INIT { 0, NULL } +#define BUF_IS_EMPTY(buf) ((buf)->data == NULL && (buf)->len == 0) typedef struct { - uint8_t * data; size_t len; + uint8_t * data; } buffer_t; +int bufcmp(const buffer_t * a, + const buffer_t * b); + /* * Returns the number of characters a uint would * need when represented as a string @@ -42,16 +51,29 @@ typedef struct { int n_digits(unsigned i); /* gets the application name */ -char * path_strip(char * src); +char * path_strip(const char * src); + +/* functions for copying and destroying arguments list */ +size_t argvlen(const char ** argv); + +char ** argvdup(char ** argv); + +void argvfree(char ** argv); /* destroy a ** */ #define freepp(type, ptr, len) \ do { \ - if (len == 0) \ - break; \ - while (len > 0) \ - free(((type **) ptr)[--len]); \ + while (len-- > 0) \ + free(((type **) ptr)[len]); \ + free(ptr); \ + } while (0) + +/* destroys an array of buffers */ +#define freebufs(ptr, len) \ + do { \ + while ((len)-- > 0) \ + freebuf((ptr)[len]); \ free(ptr); \ - } while (0); + } while (0) -#endif /* OUROBOROS_UTILS_H */ +#endif /* OUROBOROS_LIB_UTILS_H */ diff --git a/include/ouroboros/version.h.in b/include/ouroboros/version.h.in index 4306b239..c006a095 100644 --- a/include/ouroboros/version.h.in +++ b/include/ouroboros/version.h.in @@ -1,5 +1,5 @@ /* - * Ouroboros - Copyright (C) 2016 - 2021 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ouroboros version * |