diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/ouroboros/crypt.h | 92 | ||||
-rw-r--r-- | include/ouroboros/endian.h | 2 | ||||
-rw-r--r-- | include/ouroboros/errno.h | 7 | ||||
-rw-r--r-- | include/ouroboros/flow.h | 4 | ||||
-rw-r--r-- | include/ouroboros/hash.h | 7 | ||||
-rw-r--r-- | include/ouroboros/ipcp-dev.h | 10 | ||||
-rw-r--r-- | include/ouroboros/ipcp.h | 251 | ||||
-rw-r--r-- | include/ouroboros/irm.h | 3 | ||||
-rw-r--r-- | include/ouroboros/logs.h | 8 | ||||
-rw-r--r-- | include/ouroboros/name.h | 10 | ||||
-rw-r--r-- | include/ouroboros/np1_flow.h | 4 | ||||
-rw-r--r-- | include/ouroboros/protobuf.h | 51 | ||||
-rw-r--r-- | include/ouroboros/qos.h | 67 | ||||
-rw-r--r-- | include/ouroboros/rib.h | 2 | ||||
-rw-r--r-- | include/ouroboros/serdes-oep.h | 9 | ||||
-rw-r--r-- | include/ouroboros/sockets.h.in | 12 | ||||
-rw-r--r-- | include/ouroboros/test.h | 23 | ||||
-rw-r--r-- | include/ouroboros/time.h | 20 | ||||
-rw-r--r-- | include/ouroboros/tpm.h | 6 | ||||
-rw-r--r-- | include/ouroboros/utils.h | 26 |
20 files changed, 435 insertions, 179 deletions
diff --git a/include/ouroboros/crypt.h b/include/ouroboros/crypt.h index 28fe63b2..2d7cda6d 100644 --- a/include/ouroboros/crypt.h +++ b/include/ouroboros/crypt.h @@ -26,31 +26,89 @@ #include <ouroboros/shm_du_buff.h> #include <ouroboros/utils.h> +#define IVSZ 16 #define SYMMKEYSZ 32 +#define MSGBUFSZ 2048 -struct crypt_info { - uint16_t flags; - void * ctx; - uint8_t key[SYMMKEYSZ]; -}; +struct auth_ctx; +struct crypt_ctx; -int crypt_dh_pkp_create(void ** pkp, - uint8_t * pk); +struct crypt_ctx * crypt_create_ctx(const uint8_t * key); -void crypt_dh_pkp_destroy(void * pkp); +void crypt_destroy_ctx(struct crypt_ctx * ctx); -int crypt_dh_derive(void * pkp, - buffer_t pk, - uint8_t * s); +int crypt_dh_pkp_create(void ** pkp, + uint8_t * pk); -int crypt_encrypt(struct crypt_info * info, - struct shm_du_buff * sdb); +void crypt_dh_pkp_destroy(void * pkp); -int crypt_decrypt(struct crypt_info * info, - struct shm_du_buff * sdb); +int crypt_dh_derive(void * pkp, + buffer_t pk, + uint8_t * s); -int crypt_init(struct crypt_info * info); +int crypt_encrypt(struct crypt_ctx * ctx, + buffer_t in, + buffer_t * out); -void crypt_fini(struct crypt_info * info); +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/endian.h b/include/ouroboros/endian.h index addb2ed3..6c3493d9 100644 --- a/include/ouroboros/endian.h +++ b/include/ouroboros/endian.h @@ -66,8 +66,8 @@ #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) diff --git a/include/ouroboros/errno.h b/include/ouroboros/errno.h index 25e776df..6b808241 100644 --- a/include/ouroboros/errno.h +++ b/include/ouroboros/errno.h @@ -32,7 +32,10 @@ #define EIPCPSTATE 1004 /* Target in wrong state */ #define EFLOWDOWN 1005 /* Flow is down */ #define EFLOWPEER 1006 /* Flow is down (peer timed out) */ -#define ECRYPT 1007 /* Encryption error */ -#define ENAME 1008 /* Naming error */ +#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/flow.h b/include/ouroboros/flow.h index e6bf8886..77b7737e 100644 --- a/include/ouroboros/flow.h +++ b/include/ouroboros/flow.h @@ -27,14 +27,14 @@ #include <sys/types.h> - enum flow_state { /* DO NOT CHANGE ORDER! */ + 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_DESTROY, /* TODO: REMOVE! */ FLOW_NULL }; diff --git a/include/ouroboros/hash.h b/include/ouroboros/hash.h index 6b0087ce..c44c2c8a 100644 --- a/include/ouroboros/hash.h +++ b/include/ouroboros/hash.h @@ -42,7 +42,8 @@ enum hash_algo { #define HASH_FMT32 "%02x%02x%02x%02x" #define HASH_VAL32(hash) \ - (hash)[0], (hash)[1], (hash)[2], (hash)[3] + ((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) \ @@ -52,6 +53,10 @@ enum hash_algo { #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), \ diff --git a/include/ouroboros/ipcp-dev.h b/include/ouroboros/ipcp-dev.h index 378d724a..35e07414 100644 --- a/include/ouroboros/ipcp-dev.h +++ b/include/ouroboros/ipcp-dev.h @@ -28,12 +28,12 @@ #include <ouroboros/shm_rdrbuff.h> #include <ouroboros/utils.h> -int ipcp_create_r(const struct ipcp_info * info); +int ipcp_create_r(const struct ipcp_info * info); -int ipcp_flow_req_arr(const buffer_t * dst, - qosspec_t qs, - time_t mpl, - const buffer_t * data); +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, diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index 42c4dfa4..c397f250 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -26,20 +26,22 @@ #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 +/* TODO: Move state to ipcpd/ipcp.h, requires small change to reg/ipcp.c */ enum ipcp_state { - IPCP_INIT = 0, + IPCP_NULL = 0, + IPCP_INIT, IPCP_BOOT, - IPCP_OPERATIONAL, IPCP_BOOTSTRAPPED, IPCP_ENROLLED, - IPCP_SHUTDOWN, - IPCP_NULL + IPCP_OPERATIONAL, + IPCP_SHUTDOWN }; enum ipcp_type { /* IRMd uses order to select an IPCP for flow allocation. */ @@ -48,7 +50,8 @@ enum ipcp_type { /* IRMd uses order to select an IPCP for flow allocation. */ IPCP_BROADCAST, IPCP_ETH_LLC, IPCP_ETH_DIX, - IPCP_UDP, + IPCP_UDP4, + IPCP_UDP6, IPCP_INVALID }; @@ -56,7 +59,7 @@ struct ipcp_info { enum ipcp_type type; pid_t pid; char name[IPCP_NAME_SIZE + 1]; - enum ipcp_state state; + enum ipcp_state state; /* TODO: remove. */ }; /* Unicast IPCP components. */ @@ -69,13 +72,50 @@ enum pol_addr_auth { 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, @@ -83,41 +123,158 @@ enum pol_cong_avoid { }; struct dt_config { - uint8_t addr_size; - uint8_t eid_size; - uint8_t max_ttl; - enum pol_routing routing_type; + 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, + DIR_HASH_SHA3_256, + DIR_HASH_SHA3_384, + 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, +}; + +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 udp_config { - uint32_t ip_addr; - uint32_t dns_addr; - uint16_t port; +struct udp4_config { + struct in_addr ip_addr; + struct in_addr dns_addr; + uint16_t port; }; -/* Layers */ -enum pol_dir_hash { - DIR_HASH_SHA3_224, - DIR_HASH_SHA3_256, - DIR_HASH_SHA3_384, - DIR_HASH_SHA3_512, - DIR_HASH_INVALID +struct udp6_config { + struct in6_addr ip_addr; + struct in6_addr dns_addr; + uint16_t port; }; +/* Layers */ struct layer_info { char name[LAYER_NAME_SIZE + 1]; + /* TODO: Move this to directory info ? */ enum pol_dir_hash dir_hash_algo; }; @@ -127,9 +284,10 @@ struct ipcp_config { enum ipcp_type type; union { - struct uni_config unicast; - struct udp_config udp; - struct eth_config eth; + struct uni_config unicast; + struct udp4_config udp4; + struct udp6_config udp6; + struct eth_config eth; }; }; @@ -158,9 +316,16 @@ static const struct ipcp_config eth_llc_default_conf = { } }; -static const struct ipcp_config udp_default_conf = { - .type = IPCP_UDP, - .udp = { +static const struct ipcp_config udp4_default_conf = { + .type = IPCP_UDP4, + .udp4 = { + .port = 3435 + } +}; + +static const struct ipcp_config udp6_default_conf = { + .type = IPCP_UDP6, + .udp6 = { .port = 3435 } }; @@ -172,10 +337,30 @@ static const struct ipcp_config uni_default_conf = { }, .unicast = { .dt = { - .addr_size = 4, - .eid_size = 8, - .max_ttl = 60, - .routing_type = ROUTING_LINK_STATE + .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 diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h index 0105f88e..70a21ed7 100644 --- a/include/ouroboros/irm.h +++ b/include/ouroboros/irm.h @@ -76,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/logs.h b/include/ouroboros/logs.h index db49ae32..f1c401fa 100644 --- a/include/ouroboros/logs.h +++ b/include/ouroboros/logs.h @@ -37,12 +37,14 @@ #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; @@ -98,9 +100,15 @@ void log_fini(void); #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_LIB_LOGS_H */ diff --git a/include/ouroboros/name.h b/include/ouroboros/name.h index 9d77a90b..14fdd504 100644 --- a/include/ouroboros/name.h +++ b/include/ouroboros/name.h @@ -24,6 +24,7 @@ #define OUROBOROS_NAME_H #define NAME_SIZE 255 +#define NAME_PATH_SIZE (NAME_SIZE + 256) #define BIND_AUTO 0x01 enum pol_balance { @@ -32,9 +33,18 @@ enum pol_balance { 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/np1_flow.h b/include/ouroboros/np1_flow.h index 31720eea..4110ab6a 100644 --- a/include/ouroboros/np1_flow.h +++ b/include/ouroboros/np1_flow.h @@ -30,7 +30,8 @@ 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, time_t timeo); @@ -43,7 +44,6 @@ static const qosspec_t qos_np1 = { .ber = UINT32_MAX, .in_order = 0, .max_gap = UINT32_MAX, - .cypher_s = 0, .timeout = 0 }; diff --git a/include/ouroboros/protobuf.h b/include/ouroboros/protobuf.h index 9d38afb1..780d58dc 100644 --- a/include/ouroboros/protobuf.h +++ b/include/ouroboros/protobuf.h @@ -31,31 +31,36 @@ #include <ouroboros/serdes-oep.h> #include "ipcp_config.pb-c.h" -typedef IpcpConfigMsg ipcp_config_msg_t; -typedef DtConfigMsg dt_config_msg_t; -typedef EthConfigMsg eth_config_msg_t; -typedef UdpConfigMsg udp_config_msg_t; -typedef UniConfigMsg uni_config_msg_t; +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; +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; +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 LayerInfoMsg layer_info_msg_t; -typedef NameInfoMsg name_info_msg_t; -typedef QosspecMsg qosspec_msg_t; +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; +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); @@ -66,6 +71,10 @@ 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); @@ -86,9 +95,13 @@ 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); -udp_config_msg_t * udp_config_s_to_msg(const struct udp_config * s); +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 udp_config udp_config_msg_to_s(const udp_config_msg_t * msg); +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); diff --git a/include/ouroboros/qos.h b/include/ouroboros/qos.h index a45e8135..2be31305 100644 --- a/include/ouroboros/qos.h +++ b/include/ouroboros/qos.h @@ -36,7 +36,6 @@ typedef struct qos_spec { 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 (bits), 0 = no encryption. */ uint32_t timeout; /* Peer timeout time, in ms, 0 = no timeout. */ } qosspec_t; @@ -48,7 +47,6 @@ static const qosspec_t qos_raw = { .ber = 1, .in_order = 0, .max_gap = UINT32_MAX, - .cypher_s = 0, .timeout = DEFAULT_PEER_TIMEOUT }; @@ -60,19 +58,6 @@ static const qosspec_t qos_raw_no_errors = { .ber = 0, .in_order = 0, .max_gap = UINT32_MAX, - .cypher_s = 0, - .timeout = DEFAULT_PEER_TIMEOUT -}; - -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 }; @@ -84,19 +69,6 @@ static const qosspec_t qos_best_effort = { .ber = 0, .in_order = 1, .max_gap = UINT32_MAX, - .cypher_s = 0, - .timeout = DEFAULT_PEER_TIMEOUT -}; - -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 }; @@ -108,19 +80,6 @@ static const qosspec_t qos_video = { .ber = 0, .in_order = 1, .max_gap = 100, - .cypher_s = 0, - .timeout = DEFAULT_PEER_TIMEOUT -}; - -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 }; @@ -132,19 +91,6 @@ static const qosspec_t qos_voice = { .ber = 0, .in_order = 1, .max_gap = 50, - .cypher_s = 0, - .timeout = DEFAULT_PEER_TIMEOUT -}; - -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 }; @@ -156,19 +102,6 @@ static const qosspec_t qos_data = { .ber = 0, .in_order = 1, .max_gap = 2000, - .cypher_s = 0, - .timeout = DEFAULT_PEER_TIMEOUT -}; - -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 }; diff --git a/include/ouroboros/rib.h b/include/ouroboros/rib.h index 6aabe8f7..cdc5a9d5 100644 --- a/include/ouroboros/rib.h +++ b/include/ouroboros/rib.h @@ -25,6 +25,8 @@ #define RIB_PATH_LEN 300 #define RIB_SEPARATOR "/" +#define RIB_TM_STRLEN 26 +#define RIB_TM_FORMAT "%F %T (UTC)" #include <sys/types.h> diff --git a/include/ouroboros/serdes-oep.h b/include/ouroboros/serdes-oep.h index 69ba71a4..af4446c1 100644 --- a/include/ouroboros/serdes-oep.h +++ b/include/ouroboros/serdes-oep.h @@ -33,7 +33,6 @@ #define ENROLL_ID_LEN 8 struct enroll_req { - /* TODO: Authentication */ uint8_t id[ENROLL_ID_LEN]; }; @@ -67,4 +66,12 @@ ssize_t enroll_ack_ser(const struct enroll_ack * ack, 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/sockets.h.in b/include/ouroboros/sockets.h.in index 095674a9..1a6974ac 100644 --- a/include/ouroboros/sockets.h.in +++ b/include/ouroboros/sockets.h.in @@ -27,16 +27,20 @@ #include <sys/types.h> -#define SOCK_PATH "/var/run/ouroboros/" +#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 IPCP_SOCK_PATH_PREFIX SOCK_PATH "ipcp." #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); diff --git a/include/ouroboros/test.h b/include/ouroboros/test.h index 096e145c..bccf9ccd 100644 --- a/include/ouroboros/test.h +++ b/include/ouroboros/test.h @@ -28,6 +28,11 @@ #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 { \ @@ -36,13 +41,19 @@ } while (0) #define TEST_SUCCESS() \ do { \ - printf("%s succeeded.\n", __func__); \ + 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("%s failed.\n", __func__); \ + printf("\x1b[31m%s failed.\x1b[0m\n", __func__); \ fflush(stdout); \ } while (0) @@ -57,7 +68,7 @@ static int __attribute__((unused)) test_assert_fail(int(* testfunc)(void)) pid = fork(); if (pid == -1) { printf("Failed to fork: %s.\n", strerror(errno)); - return -1; + return TEST_RC_FAIL; } if (pid == 0) @@ -66,17 +77,17 @@ static int __attribute__((unused)) test_assert_fail(int(* testfunc)(void)) waitpid(pid, &wstatus, 0); #ifdef CONFIG_OUROBOROS_DEBUG if (WIFSIGNALED(wstatus) && (wstatus == 134 || wstatus == 6)) - return 0; + return TEST_RC_SUCCESS; printf("Process did not abort, status: %d.\n", wstatus); #else if (WIFEXITED(wstatus) && wstatus == 0) - return 0; + return TEST_RC_SUCCESS; printf("Process did not exit, status: %d.\n", wstatus); #endif - return -1; + return TEST_RC_FAIL; } #endif /* OUROBOROS_LIB_TEST_H */ diff --git a/include/ouroboros/time.h b/include/ouroboros/time.h index b274c35b..3bd6a257 100644 --- a/include/ouroboros/time.h +++ b/include/ouroboros/time.h @@ -31,34 +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 */ diff --git a/include/ouroboros/tpm.h b/include/ouroboros/tpm.h index 445f9306..3fb49b88 100644 --- a/include/ouroboros/tpm.h +++ b/include/ouroboros/tpm.h @@ -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 93fbf402..b93b345d 100644 --- a/include/ouroboros/utils.h +++ b/include/ouroboros/utils.h @@ -24,20 +24,26 @@ #define OUROBOROS_LIB_UTILS_H #include <stdint.h> -#include <unistd.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 @@ -57,11 +63,17 @@ 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_LIB_UTILS_H */ |