diff -Nru librtr-0.6.0/CHANGELOG librtr-0.6.3/CHANGELOG --- librtr-0.6.0/CHANGELOG 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/CHANGELOG 2018-12-09 12:13:50.000000000 +0000 @@ -3,6 +3,24 @@ Release History: +* Version 0.6.3 + - Fix IPv4 string conversion to support big endian systems + +* Version 0.6.2 + - Add C++ support by disabling name mangling for RTRlib symbols + - Make pfx_table, pfx_table_init(), pfx_table_add(), + pfx_table_free(), pfx_table_src_remove() public; to use RTRlib + without online connection to an RPKI cache server + - Hide symbols of Tommy hash table without using forward declaration, + to resolve dependency on C11 + - Fix cmake build errors in Debian and OpenBSD + - Add connection timeout in tests/test_dynamic_groups + +* Version 0.6.1 + - Fix for cmake versions >= 2.8 + - Fix rpm build + - Fix Ubuntu 12.04 build + * Version 0.6.0 - Change default symbol visibility: Hide all symbols per default, export public symbols explicitly diff -Nru librtr-0.6.0/CMakeLists.txt librtr-0.6.3/CMakeLists.txt --- librtr-0.6.0/CMakeLists.txt 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/CMakeLists.txt 2018-12-09 12:13:50.000000000 +0000 @@ -1,5 +1,4 @@ -project(rtrlib - LANGUAGES C) +project(rtrlib C) set(PROJECT_DESCRIPTION "Lightweight C library that implements the RPKI/RTR protocol and prefix origin validation.") @@ -24,12 +23,11 @@ find_package(codecov) find_package(Threads REQUIRED) -if(NOT APPLE) +if(NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") find_library(RT_LIB rt) -endif(NOT APPLE) +endif(NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") include(GNUInstallDirs) # for man page install path -include(UseMultiArch) # needed for debian packaging set(RTRLIB_SRC rtrlib/rtr_mgr.c rtrlib/lib/utils.c rtrlib/lib/alloc_utils.c rtrlib/lib/convert_byte_order.c rtrlib/lib/ip.c rtrlib/lib/ipv4.c rtrlib/lib/ipv6.c rtrlib/lib/log.c @@ -95,7 +93,7 @@ #install lib set (RTRLIB_VERSION_MAJOR 0) set (RTRLIB_VERSION_MINOR 6) -set (RTRLIB_VERSION_PATCH 0) +set (RTRLIB_VERSION_PATCH 3) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/rtrlib/rtrlib.h.cmake ${CMAKE_SOURCE_DIR}/rtrlib/rtrlib.h) set(LIBRARY_VERSION ${RTRLIB_VERSION_MAJOR}.${RTRLIB_VERSION_MINOR}.${RTRLIB_VERSION_PATCH}) set(LIBRARY_SOVERSION ${RTRLIB_VERSION_MAJOR}) @@ -124,15 +122,8 @@ set (PKG_CONFIG_REQUIRES "libssh >= 0.5.0") endif(LIBSSH_FOUND) -if(IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR}) - set (PKG_CONFIG_LIBDIR ${CMAKE_INSTALL_LIBDIR}) - set (RTRLIB_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}) -else() - set (PKG_CONFIG_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}") - set (RTRLIB_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") -endif(IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR}) - # '#include ' includes the "rtrlib/" +set (PKG_CONFIG_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}") set (PKG_CONFIG_INCLUDEDIR "\${prefix}/include") set (PKG_CONFIG_LIBS "-L\${libdir} -lrtr") set (PKG_CONFIG_CFLAGS "-I\${includedir}") @@ -143,7 +134,7 @@ ) install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" - DESTINATION "${RTRLIB_INSTALL_LIBDIR}/pkgconfig" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) #add uninstall target configure_file( diff -Nru librtr-0.6.0/debian/changelog librtr-0.6.3/debian/changelog --- librtr-0.6.0/debian/changelog 2018-12-01 21:43:01.000000000 +0000 +++ librtr-0.6.3/debian/changelog 2018-12-09 13:04:06.000000000 +0000 @@ -1,3 +1,12 @@ +librtr (0.6.3-1) unstable; urgency=medium + + * Import new upstream release + - Fixes build issues with big endian architectures + * Mark librtr-doc as Multi-Arch: foreign + * Pass --as-needed to the linker to avoid useless dependencies + + -- Lukas Schwaighofer Sun, 09 Dec 2018 14:04:06 +0100 + librtr (0.6.0-1) unstable; urgency=medium * Initial release (Closes: #728206) diff -Nru librtr-0.6.0/debian/control librtr-0.6.3/debian/control --- librtr-0.6.0/debian/control 2018-12-01 21:43:01.000000000 +0000 +++ librtr-0.6.3/debian/control 2018-12-09 13:04:06.000000000 +0000 @@ -31,6 +31,7 @@ Package: librtr-doc Section: doc Architecture: all +Multi-Arch: foreign Depends: ${misc:Depends} Description: Small extensible RPKI-RTR-Client C library - documentation RTRlib is an open-source C implementation of the RPKI/Router Protocol diff -Nru librtr-0.6.0/debian/librtr0.symbols librtr-0.6.3/debian/librtr0.symbols --- librtr-0.6.0/debian/librtr0.symbols 2018-12-01 21:43:01.000000000 +0000 +++ librtr-0.6.3/debian/librtr0.symbols 2018-12-09 13:04:06.000000000 +0000 @@ -5,8 +5,14 @@ lrtr_ip_str_cmp@Base 0.6.0 lrtr_ip_str_to_addr@Base 0.6.0 lrtr_set_alloc_functions@Base 0.6.0 + pfx_table_add@Base 0.6.2 pfx_table_for_each_ipv4_record@Base 0.6.0 pfx_table_for_each_ipv6_record@Base 0.6.0 + pfx_table_free@Base 0.6.2 + pfx_table_init@Base 0.6.2 + pfx_table_remove@Base 0.6.2 + pfx_table_src_remove@Base 0.6.2 + pfx_table_validate@Base 0.6.2 pfx_table_validate_r@Base 0.6.0 rtr_get_interval_mode@Base 0.6.0 rtr_mgr_add_group@Base 0.6.0 diff -Nru librtr-0.6.0/debian/rules librtr-0.6.3/debian/rules --- librtr-0.6.0/debian/rules 2018-12-01 21:43:01.000000000 +0000 +++ librtr-0.6.3/debian/rules 2018-12-09 13:04:06.000000000 +0000 @@ -1,6 +1,7 @@ #!/usr/bin/make -f export DEB_BUILD_MAINT_OPTIONS = hardening=+all +export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed %: dh $@ diff -Nru librtr-0.6.0/README librtr-0.6.3/README --- librtr-0.6.0/README 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/README 2018-12-09 12:13:50.000000000 +0000 @@ -1,8 +1,7 @@ Introduction ------------ The RTRlib implements the client-side of the RPKI-RTR protocol (RFC -6810) and BGP Prefix Origin Validation (RFC 6811). This release also -supports Internet-Draft draft-ietf-sidr-rpki-rtr-rfc6810-bis, which +6810, RFC 8210) and BGP Prefix Origin Validation (RFC 6811). This also enables the maintenance of router keys. Router keys are required to deploy BGPSEC. diff -Nru librtr-0.6.0/redhat/SPECS/librtr.spec librtr-0.6.3/redhat/SPECS/librtr.spec --- librtr-0.6.0/redhat/SPECS/librtr.spec 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/redhat/SPECS/librtr.spec 2018-12-09 12:13:50.000000000 +0000 @@ -1,12 +1,12 @@ Name: librtr -Version: 0.5.0 +Version: 0.6.3 Release: 1%{?dist} Summary: Small extensible RPKI-RTR-Client C library Group: Development/Libraries License: MIT URL: http://rpki.realmv6.org/ Source0: %{name}-%{version}.tar.gz -BuildRequires: binutils gcc tar chrpath cmake libssh-devel >= 0.5.0 doxygen +BuildRequires: binutils gcc tar cmake libssh-devel >= 0.5.0 doxygen Requires: libssh >= 0.5.0 %description @@ -74,9 +74,7 @@ %install %make_install strip $RPM_BUILD_ROOT/usr/lib64/librtr.so.%{version} -chrpath -d $RPM_BUILD_ROOT/usr/bin/rpki-rov strip $RPM_BUILD_ROOT/usr/bin/rpki-rov -chrpath -d $RPM_BUILD_ROOT/usr/bin/rtrclient strip $RPM_BUILD_ROOT/usr/bin/rtrclient cp %{_topdir}/BUILD/CHANGELOG %{buildroot}/%{_docdir}/rtrlib/ cp %{_topdir}/BUILD/LICENSE %{buildroot}/%{_docdir}/rtrlib/ diff -Nru librtr-0.6.0/rtrlib/lib/ipv4.c librtr-0.6.3/rtrlib/lib/ipv4.c --- librtr-0.6.0/rtrlib/lib/ipv4.c 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/lib/ipv4.c 2018-12-09 12:13:50.000000000 +0000 @@ -27,10 +27,15 @@ int lrtr_ipv4_addr_to_str(const struct lrtr_ipv4_addr *ip, char *str, unsigned int len) { - const uint8_t *t = (uint8_t *)&ip->addr; + uint8_t buff[4]; + + buff[0] = ip->addr >> 24 & 0xff; + buff[1] = ip->addr >> 16 & 0xff; + buff[2] = ip->addr >> 8 & 0xff; + buff[3] = ip->addr & 0xff; if (snprintf(str, len, "%hhu.%hhu.%hhu.%hhu", - t[3], t[2], t[1], t[0]) < 0) + buff[0], buff[1], buff[2], buff[3]) < 0) return -1; return 0; @@ -38,12 +43,14 @@ int lrtr_ipv4_str_to_addr(const char *str, struct lrtr_ipv4_addr *ip) { - unsigned char *t = (unsigned char *)&ip->addr; + uint8_t buff[4]; if (sscanf(str, "%3hhu.%3hhu.%3hhu.%3hhu", - &t[3], &t[2], &t[1], &t[0]) != 4) + &buff[0], &buff[1], &buff[2], &buff[3]) != 4) return -1; + ip->addr = buff[0] << 24 | buff[1] << 16 | buff[2] << 8 | buff[3]; + return 0; } diff -Nru librtr-0.6.0/rtrlib/pfx/pfx.h librtr-0.6.3/rtrlib/pfx/pfx.h --- librtr-0.6.0/rtrlib/pfx/pfx.h 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/pfx/pfx.h 2018-12-09 12:13:50.000000000 +0000 @@ -20,8 +20,7 @@ #include #include "rtrlib/lib/ip.h" - - +#include "rtrlib/pfx/trie/trie-pfx.h" /** @@ -41,8 +40,6 @@ PFX_RECORD_NOT_FOUND = -3 }; -struct pfx_table; - /** * @brief Validation states returned from pfx_validate_origin. */ @@ -59,30 +56,6 @@ /** - * @brief pfx_record. - * @param asn Origin AS number. - * @param prefix IP prefix. - * @param min_len Minimum prefix length. - * @param max_len Maximum prefix length. - * @param socket The rtr_socket that received this record. - */ -struct pfx_record { - uint32_t asn; - struct lrtr_ip_addr prefix; - uint8_t min_len; - uint8_t max_len; - const struct rtr_socket *socket; -}; - -/** - * @brief A function pointer that is called if an record was added to the pfx_table or was removed from the pfx_table. - * @param pfx_table which was updated. - * @param record pfx_record that was modified. - * @param added True if the record was added, false if the record was removed. - */ -typedef void (*pfx_update_fp)(struct pfx_table *pfx_table, const struct pfx_record record, const bool added); - -/** * @brief A function pointer that is called for each record in the pfx_table. * @param pfx_record * @param data forwarded data which the user has passed to pfx_table_for_each_ipv4_record() or @@ -90,6 +63,59 @@ */ typedef void (*pfx_for_each_fp)(const struct pfx_record *pfx_record, void *data); +/** + * @brief Initializes the pfx_table struct. + * @param[in] pfx_table pfx_table that will be initialized. + * @param[in] update_fp Afunction pointers that will be called if a record was added or removed. + */ +void pfx_table_init(struct pfx_table *pfx_table, pfx_update_fp update_fp); + +/** + * @brief Frees all memory associcated with the pfx_table. + * @param[in] pfx_table pfx_table that will be freed. + */ +void pfx_table_free(struct pfx_table *pfx_table); + +/** + * @brief Adds a pfx_record to a pfx_table. + * @param[in] pfx_table pfx_table to use. + * @param[in] pfx_record pfx_record that will be added. + * @return PFX_SUCCESS On success. + * @return PFX_ERROR On error. + * @return PFX_DUPLICATE_RECORD If the pfx_record already exists. + */ +int pfx_table_add(struct pfx_table *pfx_table, const struct pfx_record *pfx_record); + +/** + * @brief Removes a pfx_record from a pfx_table. + * @param[in] pfx_table pfx_table to use. + * @param[in] pfx_record Record that will be removed. + * @return PFX_SUCCESS On success. + * @return PFX_ERROR On error. + * @return PFX_RECORD_NOT_FOUND If pfx_records could'nt be found. + */ +int pfx_table_remove(struct pfx_table *pfx_table, const struct pfx_record *pfx_record); + +/** + * @brief Removes all entries in the pfx_table that match the passed socket_id value from a pfx_table. + * @param[in] pfx_table pfx_table to use. + * @param[in] socket origin socket of the record + * @return PFX_SUCCESS On success. + * @return PFX_ERROR On error. + */ +int pfx_table_src_remove(struct pfx_table *pfx_table, const struct rtr_socket *socket); + +/** + * @brief Validates the origin of a BGP-Route. + * @param[in] pfx_table pfx_table to use. + * @param[in] asn Autonomous system number of the Origin-AS of the route. + * @param[in] prefix Announcend network Prefix. + * @param[in] mask_len Length of the network mask of the announced prefix. + * @param[out] result Result of the validation. + * @return PFX_SUCCESS On success. + * @return PFX_ERROR On error. + */ +int pfx_table_validate(struct pfx_table *pfx_table, const uint32_t asn, const struct lrtr_ip_addr *prefix, const uint8_t mask_len, enum pfxv_state *result); /** * @brief Validates the origin of a BGP-Route and returns a list of pfx_record that decided the result. diff -Nru librtr-0.6.0/rtrlib/pfx/pfx_private.h librtr-0.6.3/rtrlib/pfx/pfx_private.h --- librtr-0.6.0/rtrlib/pfx/pfx_private.h 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/pfx/pfx_private.h 2018-12-09 12:13:50.000000000 +0000 @@ -21,19 +21,6 @@ #include "rtrlib/pfx/pfx.h" #include "rtrlib/lib/ip_private.h" -/** - * @brief Initializes the pfx_table struct. - * @param[in] pfx_table pfx_table that will be initialized. - * @param[in] update_fp Afunction pointers that will be called if a record was added or removed. - */ -void pfx_table_init(struct pfx_table *pfx_table, pfx_update_fp update_fp); - -/** - * @brief Frees all memory associcated with the pfx_table. - * @param[in] pfx_table pfx_table that will be freed. - */ -void pfx_table_free(struct pfx_table *pfx_table); - /** * @brief Frees all memory associcated with the pfx_table without calling the update callback. @@ -42,45 +29,11 @@ void pfx_table_free_without_notify(struct pfx_table *pfx_table); /** - * @brief Adds a pfx_record to a pfx_table. - * @param[in] pfx_table pfx_table to use. - * @param[in] pfx_record pfx_record that will be added. - * @return PFX_SUCCESS On success. - * @return PFX_ERROR On error. - * @return PFX_DUPLICATE_RECORD If the pfx_record already exists. - */ -int pfx_table_add(struct pfx_table *pfx_table, const struct pfx_record *pfx_record); - -/** - * @brief Removes a pfx_record from a pfx_table. - * @param[in] pfx_table pfx_table to use. - * @param[in] pfx_record Record that will be removed. - * @return PFX_SUCCESS On success. - * @return PFX_ERROR On error. - * @return PFX_RECORD_NOT_FOUND If pfx_records could'nt be found. - */ -int pfx_table_remove(struct pfx_table *pfx_table, const struct pfx_record *pfx_record); - -/** - * @brief Removes all entries in the pfx_table that match the passed socket_id value from a pfx_table. - * @param[in] pfx_table pfx_table to use. - * @param[in] socket origin socket of the record - * @return PFX_SUCCESS On success. - * @return PFX_ERROR On error. - */ -int pfx_table_src_remove(struct pfx_table *pfx_table, const struct rtr_socket *socket); - -/** - * @brief Validates the origin of a BGP-Route. - * @param[in] pfx_table pfx_table to use. - * @param[in] asn Autonomous system number of the Origin-AS of the route. - * @param[in] prefix Announcend network Prefix. - * @param[in] mask_len Length of the network mask of the announced prefix. - * @param[out] result Result of the validation. - * @return PFX_SUCCESS On success. - * @return PFX_ERROR On error. + * @brief Swap root nodes of the argument tables + * @param[in,out] a First table + * @param[in,out] b second table */ -int pfx_table_validate(struct pfx_table *pfx_table, const uint32_t asn, const struct lrtr_ip_addr *prefix, const uint8_t mask_len, enum pfxv_state *result); +void pfx_table_swap(struct pfx_table *a, struct pfx_table *b); /** * @brief Copy content of @p src_table into @p dst_table @@ -92,13 +45,6 @@ int pfx_table_copy_except_socket(struct pfx_table *src_table, struct pfx_table *dst_table, const struct rtr_socket *socket); /** - * @brief Swap root nodes of the argument tables - * @param[in,out] a First table - * @param[in,out] b second table - */ -void pfx_table_swap(struct pfx_table *a, struct pfx_table *b); - -/** * @brief Notify client about changes between to pfx tables regarding one specific socket * @details old_table will be modified it should be freed after calling this function * @param[in] new_table diff -Nru librtr-0.6.0/rtrlib/pfx/trie/trie-pfx.c librtr-0.6.3/rtrlib/pfx/trie/trie-pfx.c --- librtr-0.6.0/rtrlib/pfx/trie/trie-pfx.c 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/pfx/trie/trie-pfx.c 2018-12-09 12:13:50.000000000 +0000 @@ -12,8 +12,9 @@ #include #include -#include "rtrlib/pfx/trie/trie-pfx_private.h" +#include "rtrlib/pfx/trie/trie-pfx.h" #include "rtrlib/pfx/trie/trie_private.h" +#include "rtrlib/pfx/pfx_private.h" #include "rtrlib/lib/alloc_utils_private.h" #include "rtrlib/rtrlib_export_private.h" #include "rtrlib/lib/ip_private.h" @@ -61,7 +62,7 @@ pfx_table->update_fp(pfx_table, *record, added); } -void pfx_table_init(struct pfx_table *pfx_table, pfx_update_fp update_fp) +RTRLIB_EXPORT void pfx_table_init(struct pfx_table *pfx_table, pfx_update_fp update_fp) { pfx_table->ipv4 = NULL; pfx_table->ipv6 = NULL; @@ -75,7 +76,7 @@ pfx_table_free(pfx_table); } -void pfx_table_free(struct pfx_table *pfx_table) +RTRLIB_EXPORT void pfx_table_free(struct pfx_table *pfx_table) { for(int i = 0; i < 2; i++) { struct trie_node *root = (i == 0 ? pfx_table->ipv4 : pfx_table->ipv6); @@ -207,7 +208,7 @@ return PFX_SUCCESS; } -int pfx_table_add(struct pfx_table *pfx_table, const struct pfx_record *record) +RTRLIB_EXPORT int pfx_table_add(struct pfx_table *pfx_table, const struct pfx_record *record) { pthread_rwlock_wrlock(&(pfx_table->lock)); @@ -257,7 +258,7 @@ return PFX_SUCCESS; } -int pfx_table_remove(struct pfx_table *pfx_table, const struct pfx_record *record) +RTRLIB_EXPORT int pfx_table_remove(struct pfx_table *pfx_table, const struct pfx_record *record) { pthread_rwlock_wrlock(&(pfx_table->lock)); struct trie_node *root = pfx_table_get_root(pfx_table, record->prefix.ver); @@ -420,12 +421,12 @@ return PFX_SUCCESS; } -int pfx_table_validate(struct pfx_table *pfx_table, const uint32_t asn, const struct lrtr_ip_addr *prefix, const uint8_t prefix_len, enum pfxv_state *result) +RTRLIB_EXPORT int pfx_table_validate(struct pfx_table *pfx_table, const uint32_t asn, const struct lrtr_ip_addr *prefix, const uint8_t prefix_len, enum pfxv_state *result) { return pfx_table_validate_r(pfx_table, NULL, NULL, asn, prefix, prefix_len, result); } -int pfx_table_src_remove(struct pfx_table *pfx_table, const struct rtr_socket *socket) +RTRLIB_EXPORT int pfx_table_src_remove(struct pfx_table *pfx_table, const struct rtr_socket *socket) { for(unsigned int i = 0; i < 2; i++) { struct trie_node **root = (i == 0 ? &(pfx_table->ipv4) : &(pfx_table->ipv6)); diff -Nru librtr-0.6.0/rtrlib/pfx/trie/trie-pfx.h librtr-0.6.3/rtrlib/pfx/trie/trie-pfx.h --- librtr-0.6.0/rtrlib/pfx/trie/trie-pfx.h 1970-01-01 00:00:00.000000000 +0000 +++ librtr-0.6.3/rtrlib/pfx/trie/trie-pfx.h 2018-12-09 12:13:50.000000000 +0000 @@ -0,0 +1,72 @@ +/* + * This file is part of RTRlib. + * + * This file is subject to the terms and conditions of the MIT license. + * See the file LICENSE in the top level directory for more details. + * + * Website: http://rtrlib.realmv6.org/ + */ + +/** + * @defgroup mod_trie_pfx_h Trie + * @ingroup mod_pfx_h + * @brief An implementation of a \ref mod_pfx_h "pfx_table" data structure + * using a shortest prefix first tree (trie) for storing @ref pfx_record "pfx_records". + * @details This implementation uses two separate lpfs-trees, one for IPv4 + * validation records and one for IPv6 records.\n + * See \ref mod_pfx_h "pfx_table" for a list of supported operations of + * this data structure.\n + * + * @{ + */ + +#ifndef RTR_TRIE_PFX +#define RTR_TRIE_PFX +#include +#include +#include + +#include "rtrlib/lib/ip.h" + +struct pfx_table; + +/** + * @brief pfx_record. + * @param asn Origin AS number. + * @param prefix IP prefix. + * @param min_len Minimum prefix length. + * @param max_len Maximum prefix length. + * @param socket The rtr_socket that received this record. + */ +struct pfx_record { + uint32_t asn; + struct lrtr_ip_addr prefix; + uint8_t min_len; + uint8_t max_len; + const struct rtr_socket *socket; +}; + +/** + * @brief A function pointer that is called if an record was added to the pfx_table or was removed from the pfx_table. + * @param pfx_table which was updated. + * @param record pfx_record that was modified. + * @param added True if the record was added, false if the record was removed. + */ +typedef void (*pfx_update_fp)(struct pfx_table *pfx_table, const struct pfx_record record, const bool added); + +/** + * @brief pfx_table. + * @param ipv4 + * @param ipv6 + * @param update_fp + * @param lock + */ +struct pfx_table { + struct trie_node *ipv4; + struct trie_node *ipv6; + pfx_update_fp update_fp; + pthread_rwlock_t lock; +}; + +#endif +/* @} */ diff -Nru librtr-0.6.0/rtrlib/pfx/trie/trie-pfx_private.h librtr-0.6.3/rtrlib/pfx/trie/trie-pfx_private.h --- librtr-0.6.0/rtrlib/pfx/trie/trie-pfx_private.h 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/pfx/trie/trie-pfx_private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -/* - * This file is part of RTRlib. - * - * This file is subject to the terms and conditions of the MIT license. - * See the file LICENSE in the top level directory for more details. - * - * Website: http://rtrlib.realmv6.org/ - */ - -/** - * @defgroup mod_trie_pfx_h Trie - * @ingroup mod_pfx_h - * @brief An implementation of a \ref mod_pfx_h "pfx_table" data structure - * using a shortest prefix first tree (trie) for storing @ref pfx_record "pfx_records". - * @details This implementation uses two separate lpfs-trees, one for IPv4 - * validation records and one for IPv6 records.\n - * See \ref mod_pfx_h "pfx_table" for a list of supported operations of - * this data structure.\n - * - * @{ - */ - -#ifndef RTR_TRIE_PFX_PRIVATE -#define RTR_TRIE_PFX_PRIVATE -#include - -#include "rtrlib/pfx/pfx_private.h" - -/** - * @brief pfx_table. - * @param ipv4 - * @param ipv6 - * @param update_fp - * @param lock - */ -struct pfx_table { - struct trie_node *ipv4; - struct trie_node *ipv6; - pfx_update_fp update_fp; - pthread_rwlock_t lock; -}; - -#endif -/* @} */ diff -Nru librtr-0.6.0/rtrlib/rtr/packets.c librtr-0.6.3/rtrlib/rtr/packets.c --- librtr-0.6.0/rtrlib/rtr/packets.c 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/rtr/packets.c 2018-12-09 12:13:50.000000000 +0000 @@ -17,7 +17,7 @@ #include "rtrlib/lib/convert_byte_order_private.h" #include "rtrlib/lib/log_private.h" #include "rtrlib/lib/utils_private.h" -#include "rtrlib/pfx/trie/trie-pfx_private.h" +#include "rtrlib/pfx/pfx_private.h" #include "rtrlib/rtr/packets_private.h" #include "rtrlib/rtr/rtr_private.h" #include "rtrlib/spki/hashtable/ht-spkitable_private.h" diff -Nru librtr-0.6.0/rtrlib/rtrlib.h.cmake librtr-0.6.3/rtrlib/rtrlib.h.cmake --- librtr-0.6.0/rtrlib/rtrlib.h.cmake 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/rtrlib.h.cmake 2018-12-09 12:13:50.000000000 +0000 @@ -7,6 +7,10 @@ * Website: http://rtrlib.realmv6.org/ */ +#ifdef __cplusplus +extern "C" { +#endif + #ifndef RTRLIB_H #define RTRLIB_H @@ -30,3 +34,8 @@ #endif #endif + + +#ifdef __cplusplus +} +#endif diff -Nru librtr-0.6.0/rtrlib/rtr_mgr.c librtr-0.6.3/rtrlib/rtr_mgr.c --- librtr-0.6.0/rtrlib/rtr_mgr.c 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/rtr_mgr.c 2018-12-09 12:13:50.000000000 +0000 @@ -15,7 +15,7 @@ #include "rtrlib/lib/alloc_utils_private.h" #include "rtrlib/lib/log_private.h" -#include "rtrlib/pfx/trie/trie-pfx_private.h" +#include "rtrlib/pfx/pfx_private.h" #include "rtrlib/rtr/rtr_private.h" #include "rtrlib/rtr_mgr_private.h" #include "rtrlib/rtrlib_export_private.h" @@ -104,7 +104,7 @@ struct rtr_mgr_group *group) { pthread_mutex_lock(&config->mutex); - tommy_node *node = tommy_list_head(&config->groups); + tommy_node *node = tommy_list_head(&config->groups->list); while (node) { struct rtr_mgr_group_node *group_node = node->data; @@ -129,7 +129,7 @@ struct rtr_mgr_group *group) { pthread_mutex_lock(&config->mutex); - tommy_node *node = tommy_list_head(&config->groups); + tommy_node *node = tommy_list_head(&config->groups->list); while (node) { struct rtr_mgr_group_node *group_node = node->data; @@ -148,7 +148,7 @@ static bool is_some_rtr_mgr_group_established(struct rtr_mgr_config *config) { pthread_mutex_lock(&config->mutex); - tommy_node *node = tommy_list_head(&config->groups); + tommy_node *node = tommy_list_head(&config->groups->list); while (node) { struct rtr_mgr_group_node *group_node = node->data; @@ -211,7 +211,7 @@ bool all_error = true; pthread_mutex_lock(&config->mutex); - tommy_node *node = tommy_list_head(&config->groups); + tommy_node *node = tommy_list_head(&config->groups->list); while (node) { struct rtr_mgr_group_node *group_node = node->data; @@ -392,7 +392,10 @@ /* Copy the groups from the array into linked list config->groups */ config->len = groups_len; - config->groups = NULL; + config->groups = lrtr_malloc(sizeof(*config->groups)); + if (!config->groups) + goto err; + config->groups->list = NULL; for (unsigned int i = 0; i < groups_len; i++) { cg = lrtr_malloc(sizeof(struct rtr_mgr_group)); @@ -414,13 +417,13 @@ goto err; group_node->group = cg; - tommy_list_insert_tail(&config->groups, &group_node->node, + tommy_list_insert_tail(&config->groups->list, &group_node->node, group_node); } /* Our linked list should be sorted already, since the groups array was * sorted. However, for safety reasons we sort again. */ - tommy_list_sort(&config->groups, &rtr_mgr_config_cmp_tommy); + tommy_list_sort(&config->groups->list, &rtr_mgr_config_cmp_tommy); config->status_fp_data = status_fp_data; config->status_fp = status_fp; @@ -447,7 +450,7 @@ RTRLIB_EXPORT struct rtr_mgr_group *rtr_mgr_get_first_group( struct rtr_mgr_config *config) { - tommy_node *head = tommy_list_head(&config->groups); + tommy_node *head = tommy_list_head(&config->groups->list); struct rtr_mgr_group_node *group_node = head->data; return group_node->group; @@ -464,7 +467,7 @@ RTRLIB_EXPORT bool rtr_mgr_conf_in_sync(struct rtr_mgr_config *config) { pthread_mutex_lock(&config->mutex); - tommy_node *node = tommy_list_head(&config->groups); + tommy_node *node = tommy_list_head(&config->groups->list); while (node) { bool all_sync = true; @@ -496,7 +499,7 @@ lrtr_free(config->pfx_table); /* Free linked list */ - tommy_node *head = tommy_list_head(&config->groups); + tommy_node *head = tommy_list_head(&config->groups->list); while (head) { tommy_node *tmp = head; @@ -512,6 +515,8 @@ lrtr_free(group_node); } + lrtr_free(config->groups); + pthread_mutex_unlock(&config->mutex); pthread_mutex_destroy(&config->mutex); lrtr_free(config); @@ -542,7 +547,7 @@ RTRLIB_EXPORT void rtr_mgr_stop(struct rtr_mgr_config *config) { pthread_mutex_lock(&config->mutex); - tommy_node *node = tommy_list_head(&config->groups); + tommy_node *node = tommy_list_head(&config->groups->list); MGR_DBG1("rtr_mgr_stop()"); while (node) { @@ -573,7 +578,7 @@ pthread_mutex_lock(&config->mutex); - tommy_node *node = tommy_list_head(&config->groups); + tommy_node *node = tommy_list_head(&config->groups->list); while (node) { gnode = node->data; @@ -612,14 +617,14 @@ goto err; new_group_node->group = new_group; - tommy_list_insert_tail(&config->groups, &new_group_node->node, + tommy_list_insert_tail(&config->groups->list, &new_group_node->node, new_group_node); config->len++; MGR_DBG("Group with preference %d successfully added!", new_group->preference); - tommy_list_sort(&config->groups, &rtr_mgr_config_cmp_tommy); + tommy_list_sort(&config->groups->list, &rtr_mgr_config_cmp_tommy); struct rtr_mgr_group *best_group = rtr_mgr_get_first_group(config); @@ -645,7 +650,7 @@ { pthread_mutex_lock(&config->mutex); tommy_node *remove_node = NULL; - tommy_node *node = tommy_list_head(&config->groups); + tommy_node *node = tommy_list_head(&config->groups->list); struct rtr_mgr_group_node *group_node; struct rtr_mgr_group *remove_group; @@ -671,10 +676,10 @@ group_node = remove_node->data; remove_group = group_node->group; - tommy_list_remove_existing(&config->groups, remove_node); + tommy_list_remove_existing(&config->groups->list, remove_node); config->len--; MGR_DBG("Group with preference %d successfully removed!", preference); - //tommy_list_sort(&config->groups, &rtr_mgr_config_cmp); + //tommy_list_sort(&config->groups->list, &rtr_mgr_config_cmp); pthread_mutex_unlock(&config->mutex); //If group isn't closed, make it so! @@ -699,11 +704,11 @@ // TODO: write test for this function. /* cppcheck-suppress unusedFunction */ RTRLIB_EXPORT int rtr_mgr_for_each_group( - struct rtr_mgr_config *conf, + struct rtr_mgr_config *config, void (fp)(const struct rtr_mgr_group *group, void *data), void *data) { - tommy_node *node = tommy_list_head(&conf->groups); + tommy_node *node = tommy_list_head(&config->groups->list); while (node) { struct rtr_mgr_group_node *group_node = node->data; diff -Nru librtr-0.6.0/rtrlib/rtr_mgr.h librtr-0.6.3/rtrlib/rtr_mgr.h --- librtr-0.6.0/rtrlib/rtr_mgr.h 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/rtr_mgr.h 2018-12-09 12:13:50.000000000 +0000 @@ -37,7 +37,6 @@ #include "rtrlib/pfx/pfx.h" #include "rtrlib/spki/spkitable.h" -#include "rtrlib/spki/hashtable/hashtable_forward.h" /** * @brief Status of a rtr_mgr_group. @@ -75,9 +74,11 @@ const struct rtr_socket *, void *); +struct tommy_list_wrapper; + //TODO Add refresh, expire, and retry intervals to config for easier access. struct rtr_mgr_config { - tommy_list groups; + struct tommy_list_wrapper *groups; unsigned int len; pthread_mutex_t mutex; rtr_mgr_status_fp status_fp; diff -Nru librtr-0.6.0/rtrlib/rtr_mgr_private.h librtr-0.6.3/rtrlib/rtr_mgr_private.h --- librtr-0.6.0/rtrlib/rtr_mgr_private.h 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/rtr_mgr_private.h 2018-12-09 12:13:50.000000000 +0000 @@ -10,7 +10,11 @@ #ifndef RTR_MGR_PRIVATE #define RTR_MGR_PRIVATE #include "rtrlib/rtr_mgr.h" -#include "rtrlib/spki/hashtable/tommyds-1.8/tommytypes.h" +#include "rtrlib/spki/hashtable/tommyds-1.8/tommylist.h" + +struct tommy_list_wrapper { + tommy_list list; +}; //TODO Find a nicer way todo a linked list (without writing our own) struct rtr_mgr_group_node { diff -Nru librtr-0.6.0/rtrlib/spki/hashtable/hashtable_forward.h librtr-0.6.3/rtrlib/spki/hashtable/hashtable_forward.h --- librtr-0.6.0/rtrlib/spki/hashtable/hashtable_forward.h 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/rtrlib/spki/hashtable/hashtable_forward.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,17 +0,0 @@ -/* - * This file is part of RTRlib. - * - * This file is subject to the terms and conditions of the MIT license. - * See the file LICENSE in the top level directory for more details. - * - * Website: http://rtrlib.realmv6.org/ - */ - - -/* - * This File contains forward declarations for some tommy types - * This is to be used in public headers - */ - -typedef struct tommy_node_struct tommy_node; -typedef tommy_node * tommy_list; diff -Nru librtr-0.6.0/tests/test_dynamic_groups.c librtr-0.6.3/tests/test_dynamic_groups.c --- librtr-0.6.0/tests/test_dynamic_groups.c 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/tests/test_dynamic_groups.c 2018-12-09 12:13:50.000000000 +0000 @@ -7,6 +7,17 @@ #include "rtrlib/rtr_mgr_private.h" #include "rtrlib/spki/hashtable/tommyds-1.8/tommylist.h" +const int connection_timeout = 20; +enum rtr_mgr_status connection_status = -1; + +static void connection_status_callback(const struct rtr_mgr_group *group, + enum rtr_mgr_status status, + const struct rtr_socket *socket, + void *data) +{ + connection_status = status; +} + int main(void) { //create a TCP transport socket @@ -46,14 +57,21 @@ struct rtr_mgr_config *conf; - rtr_mgr_init(&conf, groups, 1, 30, 600, 600, NULL, NULL, NULL, NULL); + rtr_mgr_init(&conf, groups, 1, 30, 600, 600, NULL, NULL, &connection_status_callback, NULL); //start the connection manager rtr_mgr_start(conf); - //wait till at least one group is fully synchronized with the server - while (!rtr_mgr_conf_in_sync(conf)) + int sleep_counter = 0; + // wait 20 sec till at least one group is fully synchronized with the server + // otherwise EXIT_FAILURE. + while (!rtr_mgr_conf_in_sync(conf)) { + sleep_counter++; + if (connection_status == RTR_MGR_ERROR || sleep_counter > connection_timeout) + return EXIT_FAILURE; + sleep(1); + } assert(conf->len == 1); @@ -65,7 +83,7 @@ retval = rtr_mgr_add_group(conf, &group2); assert(retval == RTR_INVALID_PARAM); - tommy_node *node = tommy_list_head(&conf->groups); + tommy_node *node = tommy_list_head(&conf->groups->list); struct rtr_mgr_group_node *group_node = node->data; struct rtr_mgr_group_node *group_node2 = node->next->data; @@ -75,7 +93,7 @@ rtr_mgr_remove_group(conf, 1); - node = tommy_list_head(&conf->groups); + node = tommy_list_head(&conf->groups->list); group_node = node->data; assert(group_node->group->preference == 2); assert(conf->len == 1); @@ -111,7 +129,7 @@ // and check whether it will be set as the active group. rtr_mgr_add_group(conf, &group3); - node = tommy_list_head(&conf->groups); + node = tommy_list_head(&conf->groups->list); group_node = node->data; assert(group_node->group->preference == 3); diff -Nru librtr-0.6.0/tests/test_ht_spkitable.c librtr-0.6.3/tests/test_ht_spkitable.c --- librtr-0.6.0/tests/test_ht_spkitable.c 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/tests/test_ht_spkitable.c 2018-12-09 12:13:50.000000000 +0000 @@ -7,6 +7,7 @@ * Website: http://rtrlib.realmv6.org/ */ +#include #include #include #include @@ -61,11 +62,11 @@ memset(record, 0, sizeof(*record)); record->asn = ASN; - for (i = 0; i < sizeof(record->ski) / sizeof(u_int32_t); i++) - ((u_int32_t *)record->ski)[i] = i + ski_offset; + for (i = 0; i < sizeof(record->ski) / sizeof(uint32_t); i++) + ((uint32_t *)record->ski)[i] = i + ski_offset; - for (i = 0; i < sizeof(record->spki) / sizeof(u_int32_t); i++) - ((u_int32_t *)record->spki)[i] = i + spki_offset; + for (i = 0; i < sizeof(record->spki) / sizeof(uint32_t); i++) + ((uint32_t *)record->spki)[i] = i + spki_offset; record->socket = socket; return record; diff -Nru librtr-0.6.0/tests/test_pfx.c librtr-0.6.3/tests/test_pfx.c --- librtr-0.6.0/tests/test_pfx.c 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/tests/test_pfx.c 2018-12-09 12:13:50.000000000 +0000 @@ -17,7 +17,7 @@ #include "rtrlib/lib/ip_private.h" #include "rtrlib/lib/utils_private.h" -#include "rtrlib/pfx/trie/trie-pfx_private.h" +#include "rtrlib/pfx/pfx.h" #include "rtrlib/pfx/trie/trie_private.h" #include "rtrlib/rtr/rtr.h" diff -Nru librtr-0.6.0/tests/test_pfx_locks.c librtr-0.6.3/tests/test_pfx_locks.c --- librtr-0.6.0/tests/test_pfx_locks.c 2018-10-05 15:57:24.000000000 +0000 +++ librtr-0.6.3/tests/test_pfx_locks.c 2018-12-09 12:13:50.000000000 +0000 @@ -17,7 +17,8 @@ #include #include #include "rtrlib/lib/ip.h" -#include "rtrlib/pfx/trie/trie-pfx_private.h" +#include "rtrlib/pfx/trie/trie-pfx.h" +#include "rtrlib/pfx/pfx.h" uint32_t min_i = 0xFF000000; uint32_t max_i = 0xFFFFFFF0;