diff options
Diffstat (limited to 'ffi')
| -rw-r--r-- | ffi/fccntl_wrap.h | 58 | ||||
| -rw-r--r-- | ffi/irm_wrap.h | 47 | ||||
| -rw-r--r-- | ffi/pyouroboros_build_dev.py (renamed from ffi/pyouroboros_build.py) | 100 | ||||
| -rw-r--r-- | ffi/pyouroboros_build_irm.py | 291 |
4 files changed, 455 insertions, 41 deletions
diff --git a/ffi/fccntl_wrap.h b/ffi/fccntl_wrap.h index ab227ea..7cfc902 100644 --- a/ffi/fccntl_wrap.h +++ b/ffi/fccntl_wrap.h @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2026 * * An fccntl wrapper * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * 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 @@ -57,6 +57,11 @@ int flow_get_tx_qlen(int fd, size_t * sz) return fccntl(fd, FLOWGTXQLEN, sz); } +int flow_get_mtu(int fd, size_t * mtu) +{ + return fccntl(fd, FLOWGMTU, mtu); +} + int flow_set_flags(int fd, uint32_t flags) { return fccntl(fd, FLOWSFLAGS, flags); @@ -66,8 +71,53 @@ int flow_get_flags(int fd) { uint32_t flags; - if (fccntl(fd, FLOWGFLAGS, &flags)) + if (fccntl(fd, FLOWGFLAGS, &flags) < 0) + return -EPERM; + + return (int) flags; +} + +int flow_set_frct_flags(int fd, uint16_t flags) +{ + return fccntl(fd, FRCTSFLAGS, flags); +} + +int flow_get_frct_flags(int fd) +{ + uint16_t flags; + + if (fccntl(fd, FRCTGFLAGS, &flags) < 0) return -EPERM; return (int) flags; } + +int flow_set_frct_max_sdu(int fd, size_t max) +{ + return fccntl(fd, FRCTSMAXSDU, max); +} + +int flow_get_frct_max_sdu(int fd, size_t * max) +{ + return fccntl(fd, FRCTGMAXSDU, max); +} + +int flow_set_frct_rcv_ring_sz(int fd, size_t sz) +{ + return fccntl(fd, FRCTSRRINGSZ, sz); +} + +int flow_get_frct_rcv_ring_sz(int fd, size_t * sz) +{ + return fccntl(fd, FRCTGRRINGSZ, sz); +} + +int flow_set_frct_rto_min(int fd, time_t rto_ns) +{ + return fccntl(fd, FRCTSRTOMIN, rto_ns); +} + +int flow_get_frct_rto_min(int fd, time_t * rto_ns) +{ + return fccntl(fd, FRCTGRTOMIN, rto_ns); +} diff --git a/ffi/irm_wrap.h b/ffi/irm_wrap.h new file mode 100644 index 0000000..9e5ff91 --- /dev/null +++ b/ffi/irm_wrap.h @@ -0,0 +1,47 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2026 + * + * An IRM wrapper for Python bindings + * + * Dimitri Staessens <dimitri@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/. + */ + +#include <ouroboros/irm.h> +#include <arpa/inet.h> + +static int ipcp_config_udp4_set_ip(struct ipcp_config * conf, + const char * ip_str) +{ + return inet_pton(AF_INET, ip_str, &conf->udp4.ip_addr) == 1 ? 0 : -1; +} + +static int ipcp_config_udp4_set_dns(struct ipcp_config * conf, + const char * dns_str) +{ + return inet_pton(AF_INET, dns_str, &conf->udp4.dns_addr) == 1 ? 0 : -1; +} + +static int ipcp_config_udp6_set_ip(struct ipcp_config * conf, + const char * ip_str) +{ + return inet_pton(AF_INET6, ip_str, &conf->udp6.ip_addr) == 1 ? 0 : -1; +} + +static int ipcp_config_udp6_set_dns(struct ipcp_config * conf, + const char * dns_str) +{ + return inet_pton(AF_INET6, dns_str, &conf->udp6.dns_addr) == 1 ? 0 : -1; +} diff --git a/ffi/pyouroboros_build.py b/ffi/pyouroboros_build_dev.py index d216895..fc7a05a 100644 --- a/ffi/pyouroboros_build.py +++ b/ffi/pyouroboros_build_dev.py @@ -1,39 +1,46 @@ # -# Ouroboros - Copyright (C) 2016 - 2020 -# -# Python API for applications -# -# Dimitri Staessens <dimitri@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/. +# SPDX-FileCopyrightText: 2016 - 2026 Dimitri Staessens +# SPDX-License-Identifier: LGPL-2.1-only # +""" +CFFI build script for the ouroboros-dev library. +""" + +# qosspec_t / timespec cdef is duplicated in the irm builder, one copy +# per CFFI module. +# pylint: disable=duplicate-code + +from __future__ import annotations + from cffi import FFI ffibuilder: FFI = FFI() ffibuilder.cdef(""" +/* System types */ +typedef long... time_t; + +struct timespec { + time_t tv_sec; + long tv_nsec; + ...; +}; + +/* OUROBOROS VERSION.H */ +#define OUROBOROS_VERSION_MAJOR ... +#define OUROBOROS_VERSION_MINOR ... +#define OUROBOROS_VERSION_PATCH ... + /* OUROBOROS QOS.H */ 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 */ + uint8_t service; + uint32_t delay; + uint64_t bandwidth; + uint8_t availability; + uint32_t loss; + uint32_t ber; + uint32_t max_gap; uint32_t timeout; /* Timeout in ms */ } qosspec_t; @@ -47,9 +54,8 @@ int flow_alloc(const char * dst_name, int flow_accept(qosspec_t * qs, const struct timespec * timeo); -/* Returns flow descriptor, qs updates to supplied QoS. */ +/* Returns flow descriptor. */ int flow_join(const char * bc, - qosspec_t * qs, const struct timespec * timeo); int flow_dealloc(int fd); @@ -62,7 +68,7 @@ ssize_t flow_read(int fd, void * buf, size_t count); -/*OUROBOROS FCCNTL.H, VIA WRAPPER */ +/* OUROBOROS FCCNTL.H, VIA WRAPPER */ int flow_set_snd_timeout(int fd, struct timespec * ts); int flow_set_rcv_timeout(int fd, struct timespec * ts); @@ -77,17 +83,36 @@ int flow_get_rx_qlen(int fd, size_t * sz); int flow_get_tx_qlen(int fd, size_t * sz); +int flow_get_mtu(int fd, size_t * mtu); + int flow_set_flags(int fd, uint32_t flags); int flow_get_flags(int fd); -/*OUROBOROS FQUEUE.H */ +int flow_set_frct_flags(int fd, uint16_t flags); + +int flow_get_frct_flags(int fd); + +int flow_set_frct_max_sdu(int fd, size_t max); + +int flow_get_frct_max_sdu(int fd, size_t * max); + +int flow_set_frct_rcv_ring_sz(int fd, size_t sz); + +int flow_get_frct_rcv_ring_sz(int fd, size_t * sz); + +int flow_set_frct_rto_min(int fd, time_t rto_ns); + +int flow_get_frct_rto_min(int fd, time_t * rto_ns); + +/* OUROBOROS FQUEUE.H */ enum fqtype { - FLOW_PKT = (1 << 0), - FLOW_DOWN = (1 << 1), - FLOW_UP = (1 << 2), - FLOW_ALLOC = (1 << 3), - FLOW_DEALLOC = (1 << 4) + FLOW_PKT = ..., + FLOW_DOWN = ..., + FLOW_UP = ..., + FLOW_ALLOC = ..., + FLOW_DEALLOC = ..., + FLOW_PEER = ... }; struct flow_set; @@ -118,15 +143,16 @@ void fset_del(fset_t * set, int fqueue_next(fqueue_t * fq); -int fqueue_type(fqueue_t * fq); +enum fqtype fqueue_type(fqueue_t * fq); ssize_t fevent(fset_t * set, fqueue_t * fq, const struct timespec * timeo); """) -ffibuilder.set_source("_ouroboros_cffi", +ffibuilder.set_source("_ouroboros_dev_cffi", """ +#include "ouroboros/version.h" #include "ouroboros/qos.h" #include "ouroboros/dev.h" #include "fccntl_wrap.h" diff --git a/ffi/pyouroboros_build_irm.py b/ffi/pyouroboros_build_irm.py new file mode 100644 index 0000000..a9f4bc9 --- /dev/null +++ b/ffi/pyouroboros_build_irm.py @@ -0,0 +1,291 @@ +# +# SPDX-FileCopyrightText: 2016 - 2026 Dimitri Staessens +# SPDX-License-Identifier: LGPL-2.1-only +# + +""" +CFFI build script for the ouroboros-irm library. +""" + +# qosspec_t / timespec cdef is duplicated in the dev builder, one copy +# per CFFI module. +# pylint: disable=duplicate-code + +from __future__ import annotations + +from cffi import FFI + +ffibuilder: FFI = FFI() + +ffibuilder.cdef(""" +/* System types */ +typedef int... pid_t; +typedef long... time_t; + +struct timespec { + time_t tv_sec; + long tv_nsec; + ...; +}; + +/* OUROBOROS VERSION.H */ +#define OUROBOROS_VERSION_MAJOR ... +#define OUROBOROS_VERSION_MINOR ... +#define OUROBOROS_VERSION_PATCH ... + +/* Network types */ +struct in_addr { ...; }; +struct in6_addr { ...; }; + +/* OUROBOROS QOS.H */ +typedef struct qos_spec { + uint8_t service; + uint32_t delay; + uint64_t bandwidth; + uint8_t availability; + uint32_t loss; + uint32_t ber; + uint32_t max_gap; + uint32_t timeout; /* Timeout in ms */ +} qosspec_t; + +/* OUROBOROS IPCP.H */ +enum ipcp_type { + IPCP_LOCAL = ..., + IPCP_UNICAST = ..., + IPCP_BROADCAST = ..., + IPCP_ETH_LLC = ..., + IPCP_ETH_DIX = ..., + IPCP_UDP4 = ..., + IPCP_UDP6 = ..., + IPCP_INVALID = ... +}; + +/* Unicast IPCP policies */ +enum pol_addr_auth { + ADDR_AUTH_FLAT_RANDOM = ..., + ADDR_AUTH_INVALID = ... +}; + +enum pol_link_state { + LS_SIMPLE = ..., + LS_LFA = ..., + LS_ECMP = ..., + LS_INVALID = ... +}; + +struct ls_config { + enum pol_link_state pol; + time_t t_recalc; + time_t t_update; + time_t t_timeo; +}; + +enum pol_routing { + ROUTING_LINK_STATE = ..., + ROUTING_INVALID = ... +}; + +struct routing_config { + enum pol_routing pol; + union { + struct ls_config ls; + }; +}; + +enum pol_cong_avoid { + CA_NONE = ..., + 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; +}; + +enum pol_dir { + DIR_DHT = ..., + 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 = ... +}; + +struct dir_dht_config { + struct { + uint32_t alpha; + uint32_t k; + uint32_t t_expire; + uint32_t t_refresh; + uint32_t t_replicate; + } params; + uint64_t peer; +}; + +struct dir_config { + enum pol_dir pol; + union { + struct dir_dht_config dht; + }; +}; + +struct uni_config { + struct dt_config dt; + struct dir_config dir; + enum pol_addr_auth addr_auth_type; + enum pol_cong_avoid cong_avoid; +}; + +struct eth_config { + char dev[256]; /* DEV_NAME_SIZE + 1 */ + uint16_t ethertype; +}; + +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; +}; + +struct layer_info { + char name[256]; /* LAYER_NAME_SIZE + 1 */ + enum pol_dir_hash dir_hash_algo; +}; + +struct ipcp_config { + struct layer_info layer_info; + enum ipcp_type type; + + union { + struct uni_config unicast; + struct udp4_config udp4; + struct udp6_config udp6; + struct eth_config eth; + }; +}; + +/* OUROBOROS NAME.H */ +#define BIND_AUTO ... + +enum pol_balance { + LB_RR = ..., + LB_SPILL = ..., + LB_INVALID = ... +}; + +struct name_sec_paths { + char sec[512]; /* NAME_PATH_SIZE + 1 */ + char key[512]; /* NAME_PATH_SIZE + 1 */ + char crt[512]; /* NAME_PATH_SIZE + 1 */ +}; + +struct name_info { + char name[256]; /* NAME_SIZE + 1 */ + enum pol_balance pol_lb; + + struct name_sec_paths s; + struct name_sec_paths c; +}; + +/* OUROBOROS IRM.H */ + +struct ipcp_list_info { + pid_t pid; + enum ipcp_type type; + char name[255]; /* NAME_SIZE */ + char layer[255]; /* LAYER_NAME_SIZE */ +}; + +pid_t irm_create_ipcp(const char * name, + enum ipcp_type type); + +int irm_destroy_ipcp(pid_t pid); + +ssize_t irm_list_ipcps(struct ipcp_list_info ** ipcps); + +int irm_enroll_ipcp(pid_t pid, + const char * dst); + +int irm_bootstrap_ipcp(pid_t pid, + const struct ipcp_config * conf); + +int irm_connect_ipcp(pid_t pid, + const char * dst, + const char * component, + qosspec_t qs); + +int irm_disconnect_ipcp(pid_t pid, + const char * dst, + const char * component); + +int irm_bind_program(const char * prog, + const char * name, + uint16_t opts, + int argc, + char ** argv); + +int irm_unbind_program(const char * progr, + const char * name); + +int irm_bind_process(pid_t pid, + const char * name); + +int irm_unbind_process(pid_t pid, + const char * name); + +int irm_create_name(struct name_info * info); + +int irm_destroy_name(const char * name); + +ssize_t irm_list_names(struct name_info ** names); + +int irm_reg_name(const char * name, + pid_t pid); + +int irm_unreg_name(const char * name, + pid_t pid); + +/* IRM WRAPPER HELPERS */ +int ipcp_config_udp4_set_ip(struct ipcp_config * conf, + const char * ip_str); + +int ipcp_config_udp4_set_dns(struct ipcp_config * conf, + const char * dns_str); + +int ipcp_config_udp6_set_ip(struct ipcp_config * conf, + const char * ip_str); + +int ipcp_config_udp6_set_dns(struct ipcp_config * conf, + const char * dns_str); + +/* libc */ +void free(void *ptr); +""") + +ffibuilder.set_source("_ouroboros_irm_cffi", + """ +#include "ouroboros/version.h" +#include "ouroboros/qos.h" +#include "irm_wrap.h" + """, + libraries=['ouroboros-irm'], + extra_compile_args=["-I./ffi/"]) + +if __name__ == "__main__": + ffibuilder.compile(verbose=True) |
