From 6d22a0db96aa7f8e3102ae44d00c09e36a2e9c57 Mon Sep 17 00:00:00 2001 From: Luca Muscariello Date: Thu, 4 Aug 2022 16:06:34 +0200 Subject: feat: Due to the deep modifications related to names and packet format, this task cover a large part of the codebase and involves several changes: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - the library provides a name data structure (hicn_name_t ), which is composed of a name prefix (hicn_name_prefix_t) and a name suffix (hicn_name_suffix_t), and it has been extended to provide all support functions required for name manipulation, including common prefix computation, as required for the Longest Prefix Match (LPM)in the forwarder, in addition to Exact Prefix Match (EPM). - all code has been rewritten to use this data structure instead of having for instance the forwarder define its own name class (used to be Name and NameBitVector) the code has been refactored to minimize name allocations and copies, one remaining aspect is the difference of name storage between PIT and CS entries (respectively in the PIT entry, and in the message buffer), which causes the packet cache index to be updated when a PIT entry is converted into a CS entry. By storing the name in the PIT/CS entry everytime, we might save on this operation). - hicn-light FIB has been rewritten : code has been refactored and should now be shorter and documented; unit tests have been drafted but more would be required to cover all cases and match the algorithms to add/remove nodes, as specified in the doc. all protocol details and hICN header formats are now abstracted by the library for the forwarder (and thus header.h and  protocols/*.h have been removed from public includes, and replaced by packet.h providing protocol agnostic packet level functions, completely replacing the compat.h header that used to provide similar functions. - this works by exposing a opaque buffer to the application (a kind of socket buffer) which is used by the lib to cache the packet format and offsets of the different layers in the buffer and provider efficient operations (the packet format is either defined for packet construction, or guessed at ingress, and this structure is updated accordingly only once). Co-authored-by: Jordan Augé Signed-off-by: Luca Muscariello Change-Id: I31e321897f85f0267fe8ba4720363c180564492f --- ctrl/facemgr/includes/hicn/facemgr/api.h | 2 +- ctrl/facemgr/includes/hicn/facemgr/cfg.h | 20 +- ctrl/facemgr/includes/hicn/facemgr/facelet.h | 18 +- ctrl/facemgr/src/api.c | 32 +- ctrl/facemgr/src/cfg.c | 45 +- ctrl/facemgr/src/cfg_file.c | 56 +- ctrl/facemgr/src/common.h | 4 +- ctrl/facemgr/src/facelet.c | 33 +- ctrl/facemgr/src/interfaces/android/android.c | 4 +- ctrl/facemgr/src/interfaces/bonjour/bonjour.c | 17 +- .../facemgr/src/interfaces/hicn_light/hicn_light.c | 85 ++- ctrl/facemgr/src/interfaces/netlink/netlink.c | 6 +- .../network_framework/network_framework.c | 814 ++++++++++----------- 13 files changed, 555 insertions(+), 581 deletions(-) (limited to 'ctrl/facemgr') diff --git a/ctrl/facemgr/includes/hicn/facemgr/api.h b/ctrl/facemgr/includes/hicn/facemgr/api.h index 3fe049c06..582be0e78 100644 --- a/ctrl/facemgr/includes/hicn/facemgr/api.h +++ b/ctrl/facemgr/includes/hicn/facemgr/api.h @@ -44,7 +44,7 @@ typedef int (*facemgr_cb_t)(void *loop, facemgr_cb_type_t type, void *data); typedef struct { uint16_t local_port; - ip_address_t remote_addr; + hicn_ip_address_t remote_addr; uint16_t remote_port; } facemgr_overlay_setting_t; diff --git a/ctrl/facemgr/includes/hicn/facemgr/cfg.h b/ctrl/facemgr/includes/hicn/facemgr/cfg.h index bbbe81825..57d8f35bc 100644 --- a/ctrl/facemgr/includes/hicn/facemgr/cfg.h +++ b/ctrl/facemgr/includes/hicn/facemgr/cfg.h @@ -76,8 +76,9 @@ int facemgr_cfg_rule_set_ipv6(facemgr_cfg_rule_t* cfg_rule, bool status); int facemgr_cfg_rule_unset_ipv6(facemgr_cfg_rule_t* cfg_rule); int facemgr_cfg_rule_set_overlay(facemgr_cfg_rule_t* rule, int family, - ip_address_t* local_addr, uint16_t local_port, - ip_address_t* remote_addr, + hicn_ip_address_t* local_addr, + uint16_t local_port, + hicn_ip_address_t* remote_addr, uint16_t remote_port); int facemgr_rule_unset_overlay(facemgr_cfg_rule_t* rule, int family); @@ -93,8 +94,9 @@ int facemgr_cfg_set_ipv6(facemgr_cfg_t* cfg, bool status); int facemgr_cfg_unset_ipv6(facemgr_cfg_t* cfg); int facemgr_cfg_set_overlay(facemgr_cfg_t* cfg, int family, - ip_address_t* local_addr, uint16_t local_port, - ip_address_t* remote_addr, uint16_t remote_port); + hicn_ip_address_t* local_addr, uint16_t local_port, + hicn_ip_address_t* remote_addr, + uint16_t remote_port); int facemgr_cfg_unset_overlay(facemgr_cfg_t* cfg, int family); int facemgr_cfg_add_rule(facemgr_cfg_t* cfg, facemgr_cfg_rule_t* rule); @@ -128,7 +130,7 @@ int facemgr_cfg_get_ipv6(const facemgr_cfg_t* cfg, const netdevice_t* netdevice, int facemgr_cfg_get_overlay_local_addr(const facemgr_cfg_t* cfg, const netdevice_t* netdevice, netdevice_type_t netdevice_type, - int family, ip_address_t* addr); + int family, hicn_ip_address_t* addr); int facemgr_cfg_get_overlay_local_port(const facemgr_cfg_t* cfg, const netdevice_t* netdevice, netdevice_type_t netdevice_type, @@ -136,7 +138,7 @@ int facemgr_cfg_get_overlay_local_port(const facemgr_cfg_t* cfg, int facemgr_cfg_get_overlay_remote_addr(const facemgr_cfg_t* cfg, const netdevice_t* netdevice, netdevice_type_t netdevice_type, - int family, ip_address_t* addr); + int family, hicn_ip_address_t* addr); int facemgr_cfg_get_overlay_remote_port(const facemgr_cfg_t* cfg, const netdevice_t* netdevice, netdevice_type_t netdevice_type, @@ -154,11 +156,13 @@ int facemgr_cfg_rule_get_ignore(const facemgr_cfg_rule_t* cfg_rule, int facemgr_cfg_rule_get_ipv4(const facemgr_cfg_rule_t* cfg_rule, bool* status); int facemgr_cfg_rule_get_ipv6(const facemgr_cfg_rule_t* cfg_rule, bool* status); int facemgr_cfg_rule_get_overlay_local_addr(const facemgr_cfg_rule_t* rule, - int family, ip_address_t* addr); + int family, + hicn_ip_address_t* addr); int facemgr_cfg_rule_get_overlay_local_port(const facemgr_cfg_rule_t* rule, int family, uint16_t* port); int facemgr_cfg_rule_get_overlay_remote_addr(const facemgr_cfg_rule_t* rule, - int family, ip_address_t* addr); + int family, + hicn_ip_address_t* addr); int facemgr_cfg_rule_get_overlay_remote_port(const facemgr_cfg_rule_t* rule, int family, uint16_t* port); diff --git a/ctrl/facemgr/includes/hicn/facemgr/facelet.h b/ctrl/facemgr/includes/hicn/facemgr/facelet.h index d9c986731..9b04832b3 100644 --- a/ctrl/facemgr/includes/hicn/facemgr/facelet.h +++ b/ctrl/facemgr/includes/hicn/facemgr/facelet.h @@ -168,32 +168,18 @@ extern const char* facelet_attr_status_str_short[]; /* Facelet attribute */ -#ifdef WITH_POLICY #define foreach_facelet_attr \ _(netdevice_type_t, netdevice_type) \ _(netdevice_t, netdevice) \ _(int, family) \ - _(ip_address_t, local_addr) \ + _(hicn_ip_address_t, local_addr) \ _(u16, local_port) \ - _(ip_address_t, remote_addr) \ + _(hicn_ip_address_t, remote_addr) \ _(u16, remote_port) \ _(face_state_t, admin_state) \ _(face_state_t, state) \ _(u32, priority) \ _(facemgr_face_type_t, face_type) -#else -#define foreach_facelet_attr \ - _(netdevice_type_t, netdevice_type) \ - _(netdevice_t, netdevice) \ - _(int, family) \ - _(ip_address_t, local_addr) \ - _(u16, local_port) \ - _(ip_address_t, remote_addr) \ - _(u16, remote_port) \ - _(face_state_t, admin_state) \ - _(face_state_t, state) \ - _(facemgr_face_type_t, face_type) -#endif /* WITH_POLICY */ #define foreach_facelet_event \ _(UNDEFINED) \ diff --git a/ctrl/facemgr/src/api.c b/ctrl/facemgr/src/api.c index d030abd1f..f271b24c7 100644 --- a/ctrl/facemgr/src/api.c +++ b/ctrl/facemgr/src/api.c @@ -28,7 +28,7 @@ /* * Dump facelets (debug) */ -//#define WITH_DUMP +#define WITH_DUMP 1 /* * Allow priority setting before interface is actually created @@ -291,7 +291,10 @@ int facemgr_finalize(facemgr_t *facemgr) { facelet_set_free(facemgr->facelet_cache); /* Free all facelets from static array */ - for (unsigned i = 0; i < facelet_array_len(facemgr->static_facelets); i++) { + n = (int)facelet_array_len(facemgr->static_facelets); + + INFO("Removing %d facelets from static array", n); + for (unsigned i = 0; i < n; i++) { facelet_t *facelet; if (facelet_array_get_index(facemgr->static_facelets, i, &facelet) < 0) { ERROR("[facemgr_cfg_finalize] Error getting facelet in array"); @@ -817,7 +820,7 @@ int facemgr_complement_facelet_manual(facemgr_t *facemgr, facelet_t *facelet) { * We never override a result we have obtained through bonjour */ if (!facelet_has_remote_addr(facelet)) { - ip_address_t remote_addr; + hicn_ip_address_t remote_addr; if (facemgr_cfg_get_overlay_remote_addr(facemgr->cfg, &netdevice, netdevice_type, family, &remote_addr) < 0) { @@ -826,7 +829,7 @@ int facemgr_complement_facelet_manual(facemgr_t *facemgr, facelet_t *facelet) { "information from cfg"); return -1; } - if (ip_address_empty(&remote_addr)) { + if (hicn_ip_address_empty(&remote_addr)) { ERROR( "[facemgr_complement_facelet_manual] Got empty remote addr " "information from cfg"); @@ -859,7 +862,7 @@ int facemgr_complement_facelet_manual(facemgr_t *facemgr, facelet_t *facelet) { * whether this is an address that belong to us... it might be used * to arbitrate amongst several IP addresses instead... */ - ip_address_t local_addr; + hicn_ip_address_t local_addr; if (facemgr_cfg_get_overlay_local_addr( facemgr->cfg, &netdevice, netdevice_type, family, &local_addr) < 0) { ERROR( @@ -867,7 +870,7 @@ int facemgr_complement_facelet_manual(facemgr_t *facemgr, facelet_t *facelet) { "information from cfg"); return -1; } - if (ip_address_empty(&local_addr)) { + if (hicn_ip_address_empty(&local_addr)) { ERROR( "[facemgr_complement_facelet_manual] Got empty local addr information " "from cfg"); @@ -1435,7 +1438,7 @@ int facemgr_process_facelet_get(facemgr_t *facemgr, facelet_t *facelet) { if (facelet_get_netdevice_type(facelet, &netdevice_type) < 0) { /* Inspect local address */ int family; - ip_address_t local; + hicn_ip_address_t local; if (facelet_get_family(facelet, &family) < 0) { ERROR("[facemgr_process_facelet_get] Error getting facelet family"); return -1; @@ -1448,14 +1451,14 @@ int facemgr_process_facelet_get(facemgr_t *facemgr, facelet_t *facelet) { } switch (family) { case AF_INET: - if (ip_address_cmp(&local, &IPV4_LOOPBACK, family) == 0) { + if (hicn_ip_address_cmp(&local, &IPV4_LOOPBACK) == 0) { facelet_set_netdevice_type(facelet, NETDEVICE_TYPE_LOOPBACK); } else { return -2; } break; case AF_INET6: - if (ip_address_cmp(&local, &IPV6_LOOPBACK, family) == 0) { + if (hicn_ip_address_cmp(&local, &IPV6_LOOPBACK) == 0) { facelet_set_netdevice_type(facelet, NETDEVICE_TYPE_LOOPBACK); } else { return -2; @@ -1673,7 +1676,8 @@ ERR_PRIORITY: * routes managed by the face manager. */ DEBUG("[facemgr_process_facelet_create_no_family] Loop static"); - for (unsigned i = 0; i < facelet_array_len(facemgr->static_facelets); i++) { + int n = (int)facelet_array_len(facemgr->static_facelets); + for (unsigned i = 0; i < n; i++) { facelet_t *static_facelet; if (facelet_array_get_index(facemgr->static_facelets, i, &static_facelet) < 0) { @@ -1733,7 +1737,7 @@ ERR_PRIORITY: */ int facemgr_on_event(facemgr_t *facemgr, facelet_t *facelet_in) { bool remove_facelet = true; -#if WITH_DUMP +#ifdef WITH_DUMP bool dump = true; #endif /* WITH_DUMP */ int ret = 0; @@ -1826,7 +1830,7 @@ int facemgr_on_event(facemgr_t *facemgr, facelet_t *facelet_in) { // DEBUG("[facemgr_on_event] GET NEW %s", facelet_s); rc = facemgr_process_facelet_get(facemgr, facelet_in); if (rc == 0) remove_facelet = false; -#if WITH_DUMP +#ifdef WITH_DUMP dump = false; #endif if (rc == -1) { @@ -1943,7 +1947,7 @@ int facemgr_on_event(facemgr_t *facemgr, facelet_t *facelet_in) { // ERROR("[facemgr_on_event] GET event for a face that already // exists..."); #ifdef WITH_DUMP - dump = false; + // dump = false; #endif /* WITH_DUMP */ continue; @@ -2025,7 +2029,7 @@ ERR: ret = -1; DUMP_CACHE: -#if WITH_DUMP +#ifdef WITH_DUMP if (dump) { DEBUG(" "); facelet_set_dump(facemgr->facelet_cache); diff --git a/ctrl/facemgr/src/cfg.c b/ctrl/facemgr/src/cfg.c index 76e1f5e72..87a6279ca 100644 --- a/ctrl/facemgr/src/cfg.c +++ b/ctrl/facemgr/src/cfg.c @@ -17,11 +17,11 @@ typedef struct { bool is_local_port; uint16_t local_port; bool is_local_addr; - ip_address_t local_addr; + hicn_ip_address_t local_addr; bool is_remote_port; uint16_t remote_port; bool is_remote_addr; - ip_address_t remote_addr; + hicn_ip_address_t remote_addr; } facemgr_cfg_overlay_t; int facemgr_cfg_overlay_initialize(facemgr_cfg_overlay_t *overlay) { @@ -185,8 +185,8 @@ void facemgr_cfg_rule_dump(facemgr_cfg_rule_t *rule) { DEBUG(" "); if (rule->override.overlays.v4->is_local_addr) { char buf[MAXSZ_IP_ADDRESS]; - ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, - &rule->override.overlays.v4->local_addr, AF_INET); + hicn_ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, + &rule->override.overlays.v4->local_addr); DEBUG(" %s", buf); } if (rule->override.overlays.v4->is_local_port) { @@ -195,8 +195,8 @@ void facemgr_cfg_rule_dump(facemgr_cfg_rule_t *rule) { } if (rule->override.overlays.v4->is_remote_addr) { char buf[MAXSZ_IP_ADDRESS]; - ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, - &rule->override.overlays.v4->remote_addr, AF_INET); + hicn_ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, + &rule->override.overlays.v4->remote_addr); DEBUG(" %s", buf); } if (rule->override.overlays.v4->is_remote_port) { @@ -209,8 +209,8 @@ void facemgr_cfg_rule_dump(facemgr_cfg_rule_t *rule) { DEBUG(" "); if (rule->override.overlays.v6->is_local_addr) { char buf[MAXSZ_IP_ADDRESS]; - ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, - &rule->override.overlays.v6->local_addr, AF_INET6); + hicn_ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, + &rule->override.overlays.v6->local_addr); DEBUG(" %s", buf); } if (rule->override.overlays.v6->is_local_port) { @@ -219,8 +219,8 @@ void facemgr_cfg_rule_dump(facemgr_cfg_rule_t *rule) { } if (rule->override.overlays.v6->is_remote_addr) { char buf[MAXSZ_IP_ADDRESS]; - ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, - &rule->override.overlays.v6->remote_addr, AF_INET6); + hicn_ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, + &rule->override.overlays.v6->remote_addr); DEBUG(" %s", buf); } if (rule->override.overlays.v6->is_remote_port) { @@ -300,8 +300,9 @@ int facemgr_cfg_rule_unset_ipv6(facemgr_cfg_rule_t *rule) { } int facemgr_cfg_rule_set_overlay(facemgr_cfg_rule_t *rule, int family, - ip_address_t *local_addr, uint16_t local_port, - ip_address_t *remote_addr, + hicn_ip_address_t *local_addr, + uint16_t local_port, + hicn_ip_address_t *remote_addr, uint16_t remote_port) { if ((family != AF_INET) && (family != AF_INET6)) return -1; @@ -546,8 +547,9 @@ int facemgr_cfg_unset_ipv6(facemgr_cfg_t *cfg) { } int facemgr_cfg_set_overlay(facemgr_cfg_t *cfg, int family, - ip_address_t *local_addr, uint16_t local_port, - ip_address_t *remote_addr, uint16_t remote_port) { + hicn_ip_address_t *local_addr, uint16_t local_port, + hicn_ip_address_t *remote_addr, + uint16_t remote_port) { if ((family != AF_INET) && (family != AF_INET6)) return -1; facemgr_cfg_overlay_t *overlay = facemgr_cfg_overlay_create(); @@ -589,7 +591,7 @@ int facemgr_cfg_set_overlay(facemgr_cfg_t *cfg, int family, DEBUG(" "); if (overlay->is_local_addr) { char buf[MAXSZ_IP_ADDRESS]; - ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, &overlay->local_addr, AF_INET); + hicn_ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, &overlay->local_addr); DEBUG(" %s", buf); } if (overlay->is_local_port) { @@ -597,8 +599,7 @@ int facemgr_cfg_set_overlay(facemgr_cfg_t *cfg, int family, } if (overlay->is_remote_addr) { char buf[MAXSZ_IP_ADDRESS]; - ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, &overlay->remote_addr, - AF_INET); + hicn_ip_address_snprintf(buf, MAXSZ_IP_ADDRESS, &overlay->remote_addr); DEBUG(" %s", buf); } if (overlay->is_remote_port) { @@ -803,7 +804,7 @@ int facemgr_cfg_get_ignore(const facemgr_cfg_t *cfg, int facemgr_cfg_get_overlay_local_addr(const facemgr_cfg_t *cfg, const netdevice_t *netdevice, netdevice_type_t netdevice_type, - int family, ip_address_t *addr) { + int family, hicn_ip_address_t *addr) { facemgr_cfg_override_t *override; int rc = facemgr_cfg_get_override(cfg, netdevice, netdevice_type, &override); if (rc < 0) return rc; @@ -889,7 +890,7 @@ int facemgr_cfg_get_overlay_local_port(const facemgr_cfg_t *cfg, int facemgr_cfg_get_overlay_remote_addr(const facemgr_cfg_t *cfg, const netdevice_t *netdevice, netdevice_type_t netdevice_type, - int family, ip_address_t *addr) { + int family, hicn_ip_address_t *addr) { facemgr_cfg_override_t *override; int rc = facemgr_cfg_get_override(cfg, netdevice, netdevice_type, &override); if (rc < 0) return rc; @@ -1042,7 +1043,8 @@ int facemgr_cfg_rule_get_ipv6(const facemgr_cfg_rule_t *rule, bool *ipv6) { } int facemgr_cfg_rule_get_overlay_local_addr(const facemgr_cfg_rule_t *rule, - int family, ip_address_t *addr) { + int family, + hicn_ip_address_t *addr) { facemgr_cfg_overlay_t *overlay = NULL; switch (family) { case AF_INET: @@ -1078,7 +1080,8 @@ int facemgr_cfg_rule_get_overlay_local_port(const facemgr_cfg_rule_t *rule, } int facemgr_cfg_rule_get_overlay_remote_addr(const facemgr_cfg_rule_t *rule, - int family, ip_address_t *addr) { + int family, + hicn_ip_address_t *addr) { facemgr_cfg_overlay_t *overlay = NULL; switch (family) { case AF_INET: diff --git a/ctrl/facemgr/src/cfg_file.c b/ctrl/facemgr/src/cfg_file.c index 966e35816..9b5f592dd 100644 --- a/ctrl/facemgr/src/cfg_file.c +++ b/ctrl/facemgr/src/cfg_file.c @@ -99,16 +99,16 @@ int parse_config_global(facemgr_cfg_t *cfg, config_setting_t *setting) { config_setting_t *overlay_v4 = config_setting_get_member(overlay, "ipv4"); if (overlay_v4) { const char *local_addr_str, *remote_addr_str; - ip_address_t local_addr = IP_ADDRESS_EMPTY; - ip_address_t remote_addr = IP_ADDRESS_EMPTY; - ip_address_t *local_addr_p = NULL; - ip_address_t *remote_addr_p = NULL; + hicn_ip_address_t local_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t remote_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t *local_addr_p = NULL; + hicn_ip_address_t *remote_addr_p = NULL; int local_port = 0; int remote_port = 0; if (config_setting_lookup_string(overlay_v4, "local_addr", &local_addr_str)) { - if (ip_address_pton(local_addr_str, &local_addr) < 0) { + if (hicn_ip_address_pton(local_addr_str, &local_addr) < 0) { ERROR("Error parsing v4 local addr"); goto ERR; } @@ -121,7 +121,7 @@ int parse_config_global(facemgr_cfg_t *cfg, config_setting_t *setting) { if (config_setting_lookup_string(overlay_v4, "remote_addr", &remote_addr_str)) { - if (ip_address_pton(remote_addr_str, &remote_addr) < 0) { + if (hicn_ip_address_pton(remote_addr_str, &remote_addr) < 0) { ERROR("Error parsing v4 remote addr"); goto ERR; } @@ -140,16 +140,16 @@ int parse_config_global(facemgr_cfg_t *cfg, config_setting_t *setting) { config_setting_t *overlay_v6 = config_setting_get_member(overlay, "ipv6"); if (overlay_v6) { const char *local_addr_str, *remote_addr_str; - ip_address_t local_addr = IP_ADDRESS_EMPTY; - ip_address_t remote_addr = IP_ADDRESS_EMPTY; - ip_address_t *local_addr_p = NULL; - ip_address_t *remote_addr_p = NULL; + hicn_ip_address_t local_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t remote_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t *local_addr_p = NULL; + hicn_ip_address_t *remote_addr_p = NULL; int local_port = 0; int remote_port = 0; if (config_setting_lookup_string(overlay_v6, "local_addr", &local_addr_str)) { - if (ip_address_pton(local_addr_str, &local_addr) < 0) { + if (hicn_ip_address_pton(local_addr_str, &local_addr) < 0) { ERROR("Error parsing v6 local addr"); goto ERR; } @@ -162,7 +162,7 @@ int parse_config_global(facemgr_cfg_t *cfg, config_setting_t *setting) { if (config_setting_lookup_string(overlay_v6, "remote_addr", &remote_addr_str)) { - if (ip_address_pton(remote_addr_str, &remote_addr) < 0) { + if (hicn_ip_address_pton(remote_addr_str, &remote_addr) < 0) { ERROR("Error parsing v6 remote addr"); goto ERR; } @@ -353,16 +353,16 @@ int parse_config_rules(facemgr_cfg_t *cfg, config_setting_t *setting) { config_setting_t *overlay_v4 = config_setting_get_member(overlay, "ipv4"); if (overlay_v4) { const char *local_addr_str, *remote_addr_str; - ip_address_t local_addr = IP_ADDRESS_EMPTY; - ip_address_t remote_addr = IP_ADDRESS_EMPTY; - ip_address_t *local_addr_p = NULL; - ip_address_t *remote_addr_p = NULL; + hicn_ip_address_t local_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t remote_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t *local_addr_p = NULL; + hicn_ip_address_t *remote_addr_p = NULL; int local_port = 0; int remote_port = 0; if (config_setting_lookup_string(overlay_v4, "local_addr", &local_addr_str)) { - ip_address_pton(local_addr_str, &local_addr); + hicn_ip_address_pton(local_addr_str, &local_addr); local_addr_p = &local_addr; } @@ -372,7 +372,7 @@ int parse_config_rules(facemgr_cfg_t *cfg, config_setting_t *setting) { if (config_setting_lookup_string(overlay_v4, "remote_addr", &remote_addr_str)) { - ip_address_pton(remote_addr_str, &remote_addr); + hicn_ip_address_pton(remote_addr_str, &remote_addr); remote_addr_p = &remote_addr; } @@ -390,16 +390,16 @@ int parse_config_rules(facemgr_cfg_t *cfg, config_setting_t *setting) { config_setting_t *overlay_v6 = config_setting_get_member(overlay, "ipv6"); if (overlay_v6) { const char *local_addr_str, *remote_addr_str; - ip_address_t local_addr = IP_ADDRESS_EMPTY; - ip_address_t remote_addr = IP_ADDRESS_EMPTY; - ip_address_t *local_addr_p = NULL; - ip_address_t *remote_addr_p = NULL; + hicn_ip_address_t local_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t remote_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t *local_addr_p = NULL; + hicn_ip_address_t *remote_addr_p = NULL; int local_port = 0; int remote_port = 0; if (config_setting_lookup_string(overlay_v6, "local_addr", &local_addr_str)) { - ip_address_pton(local_addr_str, &local_addr); + hicn_ip_address_pton(local_addr_str, &local_addr); local_addr_p = &local_addr; } @@ -409,7 +409,7 @@ int parse_config_rules(facemgr_cfg_t *cfg, config_setting_t *setting) { if (config_setting_lookup_string(overlay_v6, "remote_addr", &remote_addr_str)) { - ip_address_pton(remote_addr_str, &remote_addr); + hicn_ip_address_pton(remote_addr_str, &remote_addr); remote_addr_p = &remote_addr; } @@ -450,7 +450,7 @@ int parse_config_static_facelets(facemgr_cfg_t *cfg, const char *family_str; int family; const char *remote_addr_str; - ip_address_t remote_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t remote_addr = IP_ADDRESS_EMPTY; int remote_port = 0; const char *interface_name; const char *interface_type_str; @@ -496,7 +496,7 @@ int parse_config_static_facelets(facemgr_cfg_t *cfg, /* Remote address */ if (config_setting_lookup_string(static_setting, "remote_addr", &remote_addr_str)) { - if (ip_address_pton(remote_addr_str, &remote_addr) < 0) { + if (hicn_ip_address_pton(remote_addr_str, &remote_addr) < 0) { ERROR("Error parsing v4 remote addr"); goto ERR_FACELET; } @@ -554,12 +554,12 @@ int parse_config_static_facelets(facemgr_cfg_t *cfg, config_setting_get_elem(routes_static_setting, j); const char *prefix_str; - ip_prefix_t prefix; + hicn_ip_prefix_t prefix; int cost = 0; /* default */ if (config_setting_lookup_string(route_static_setting, "prefix", &prefix_str)) { - if (ip_prefix_pton(prefix_str, &prefix) < 0) { + if (hicn_ip_prefix_pton(prefix_str, &prefix) < 0) { ERROR("Error parsing prefix in route #%d, rule #%d", j, i); goto ERR_FACELET; } diff --git a/ctrl/facemgr/src/common.h b/ctrl/facemgr/src/common.h index 2fda668c8..2adbc9a23 100644 --- a/ctrl/facemgr/src/common.h +++ b/ctrl/facemgr/src/common.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -34,8 +34,6 @@ #define INDENT(n, fmt) "%*s" fmt, n, "" #define printfi(n, fmt, ...) printf(INDENT(n * 4, fmt), ##__VA_ARGS__) -#define _unused(x) ((void)(x)) - /* Random strings */ static inline void rand_str(char *dest, size_t length) { diff --git a/ctrl/facemgr/src/facelet.c b/ctrl/facemgr/src/facelet.c index 609950f75..a299cc5ac 100644 --- a/ctrl/facemgr/src/facelet.c +++ b/ctrl/facemgr/src/facelet.c @@ -114,9 +114,7 @@ facelet_t *facelet_create() { facelet->remote_port_status = FACELET_ATTR_STATUS_UNSET; facelet->admin_state_status = FACELET_ATTR_STATUS_UNSET; facelet->state_status = FACELET_ATTR_STATUS_UNSET; -#ifdef WITH_POLICY facelet->priority_status = FACELET_ATTR_STATUS_UNSET; -#endif /* WITH_POLICY */ facelet->face_type_status = FACELET_ATTR_STATUS_UNSET; facelet->status = FACELET_STATUS_UNDEFINED; @@ -187,7 +185,6 @@ int facelet_validate_face(const facelet_t *facelet) { } netdevice_type_t netdevice_type_from_face_tags(const face_t *face) { -#ifdef WITH_POLICY policy_tags_t tags = face->tags; if (policy_tags_has(tags, POLICY_TAG_WIRED)) return NETDEVICE_TYPE_WIRED; @@ -195,7 +192,6 @@ netdevice_type_t netdevice_type_from_face_tags(const face_t *face) { return NETDEVICE_TYPE_WIFI; else if (policy_tags_has(tags, POLICY_TAG_CELLULAR)) return NETDEVICE_TYPE_CELLULAR; -#endif /* WITH_POLICY */ return NETDEVICE_TYPE_UNDEFINED; } @@ -232,8 +228,7 @@ facelet_t *facelet_create_from_face(face_t *face) { facelet->family_status = FACELET_ATTR_STATUS_CLEAN; /* Attribute : local_addr */ - if (ip_address_cmp(&face->local_addr, &IP_ADDRESS_EMPTY, face->family) != - 0) { + if (hicn_ip_address_cmp(&face->local_addr, &IP_ADDRESS_EMPTY) != 0) { facelet->local_addr = face->local_addr; facelet->local_addr_status = FACELET_ATTR_STATUS_CLEAN; } else { @@ -249,8 +244,7 @@ facelet_t *facelet_create_from_face(face_t *face) { } /* Attribute : remote_addr */ - if (ip_address_cmp(&face->remote_addr, &IP_ADDRESS_EMPTY, face->family) != - 0) { + if (hicn_ip_address_cmp(&face->remote_addr, &IP_ADDRESS_EMPTY) != 0) { facelet->remote_addr = face->remote_addr; facelet->remote_addr_status = FACELET_ATTR_STATUS_CLEAN; } else { @@ -290,7 +284,6 @@ facelet_t *facelet_create_from_face(face_t *face) { facelet->state_status = FACELET_ATTR_STATUS_UNSET; } -#ifdef WITH_POLICY /* Attribute : priority */ if (face->priority > 0) { facelet->priority = face->priority; @@ -298,7 +291,6 @@ facelet_t *facelet_create_from_face(face_t *face) { } else { facelet->priority_status = FACELET_ATTR_STATUS_UNSET; } -#endif /* WITH_POLICY */ /* Attribute : face_type */ if ((face->type != FACE_TYPE_UNDEFINED) && (face->type != FACE_TYPE_N)) { @@ -382,7 +374,8 @@ facelet_t *facelet_dup(const facelet_t *current_facelet) { hicn_route_t **route_array; int n = route_set_get_array(current_facelet->routes, &route_array); if (n < 0) { - ERROR("[facelet_free] Error getting route set associated to facelet"); + ERROR("[facelet_free] Error getting route set associated to facelet %p", + current_facelet); } else { for (unsigned i = 0; i < n; i++) { hicn_route_t *route = route_array[i]; @@ -775,7 +768,6 @@ int facelet_get_face(const facelet_t *facelet, face_t **pface) { face->state = FACE_STATE_UP; } -#ifdef WITH_POLICY /* Priority */ if (facelet_has_priority(facelet)) { if (facelet_get_priority(facelet, &face->priority) < 0) { @@ -815,7 +807,6 @@ int facelet_get_face(const facelet_t *facelet, face_t **pface) { } } face->tags = tags; -#endif /* WITH_POLICY */ *pface = face; @@ -956,8 +947,7 @@ int facelet_snprintf(char *s, size_t size, const facelet_t *facelet) { cur += rc; if (cur >= s + size) return (int)(cur - s); - rc = ip_address_snprintf(cur, s + size - cur, &facelet->local_addr, - facelet->family); + rc = hicn_ip_address_snprintf(cur, s + size - cur, &facelet->local_addr); if (rc < 0) return rc; cur += rc; if (cur >= s + size) return (int)(cur - s); @@ -978,8 +968,7 @@ int facelet_snprintf(char *s, size_t size, const facelet_t *facelet) { cur += rc; if (cur >= s + size) return (int)(cur - s); - rc = ip_address_snprintf(cur, s + size - cur, &facelet->remote_addr, - facelet->family); + rc = hicn_ip_address_snprintf(cur, s + size - cur, &facelet->remote_addr); if (rc < 0) return rc; cur += rc; if (cur >= s + size) return (int)(cur - s); @@ -1011,7 +1000,6 @@ int facelet_snprintf(char *s, size_t size, const facelet_t *facelet) { if (cur >= s + size) return (int)(cur - s); } -#ifdef WITH_POLICY /* Priority */ if (facelet_has_priority(facelet)) { rc = snprintf(cur, s + size - cur, " priority=%d", facelet->priority); @@ -1019,7 +1007,6 @@ int facelet_snprintf(char *s, size_t size, const facelet_t *facelet) { cur += rc; if (cur >= s + size) return (int)(cur - s); } -#endif /* WITH_POLICY */ /* Face type */ if (facelet_has_face_type(facelet)) { @@ -1138,8 +1125,7 @@ int facelet_snprintf_json(char *s, size_t size, const facelet_t *facelet, cur += rc; if (cur >= s + size) return (int)(cur - s); - rc = ip_address_snprintf(cur, s + size - cur, &facelet->local_addr, - facelet->family); + rc = hicn_ip_address_snprintf(cur, s + size - cur, &facelet->local_addr); if (rc < 0) return rc; cur += rc; if (cur >= s + size) return (int)(cur - s); @@ -1167,8 +1153,7 @@ int facelet_snprintf_json(char *s, size_t size, const facelet_t *facelet, cur += rc; if (cur >= s + size) return (int)(cur - s); - rc = ip_address_snprintf(cur, s + size - cur, &facelet->remote_addr, - facelet->family); + rc = hicn_ip_address_snprintf(cur, s + size - cur, &facelet->remote_addr); if (rc < 0) return rc; cur += rc; if (cur >= s + size) return (int)(cur - s); @@ -1206,7 +1191,6 @@ int facelet_snprintf_json(char *s, size_t size, const facelet_t *facelet, if (cur >= s + size) return (int)(cur - s); } -#ifdef WITH_POLICY /* Priority */ if (facelet_has_priority(facelet)) { rc = snprintf(cur, s + size - cur, "%*s%s: %d,\n", 4 * (indent + 1), "", @@ -1215,7 +1199,6 @@ int facelet_snprintf_json(char *s, size_t size, const facelet_t *facelet, cur += rc; if (cur >= s + size) return (int)(cur - s); } -#endif /* WITH_POLICY */ if (facelet_has_face_type(facelet)) { rc = snprintf(cur, s + size - cur, "%*s%s: \"LAYER%s/%s\",\n", diff --git a/ctrl/facemgr/src/interfaces/android/android.c b/ctrl/facemgr/src/interfaces/android/android.c index 4e084d76d..578e7472a 100644 --- a/ctrl/facemgr/src/interfaces/android/android.c +++ b/ctrl/facemgr/src/interfaces/android/android.c @@ -74,9 +74,9 @@ int android_on_network_event(interface_t *interface, const char *interface_name, goto ERR_ND; } - ip_address_t local_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t local_addr = IP_ADDRESS_EMPTY; if (ip_address) { - if (ip_address_pton(ip_address, &local_addr) < 0) { + if (hicn_ip_address_pton(ip_address, &local_addr) < 0) { ERROR("[android_on_network_event] error processing IP address"); goto ERR_IP_ADDRESS; } diff --git a/ctrl/facemgr/src/interfaces/bonjour/bonjour.c b/ctrl/facemgr/src/interfaces/bonjour/bonjour.c index 90f18c299..e7de5d648 100644 --- a/ctrl/facemgr/src/interfaces/bonjour/bonjour.c +++ b/ctrl/facemgr/src/interfaces/bonjour/bonjour.c @@ -211,8 +211,8 @@ static mdns_string_t ipv6_address_to_string(char* buffer, size_t capacity, return str; } -static mdns_string_t ip_address_to_string(char* buffer, size_t capacity, - const struct sockaddr* addr) { +static mdns_string_t hicn_ip_address_to_string(char* buffer, size_t capacity, + const struct sockaddr* addr) { if (addr->sa_family == AF_INET6) return ipv6_address_to_string(buffer, capacity, (const struct sockaddr_in6*)addr); @@ -220,7 +220,8 @@ static mdns_string_t ip_address_to_string(char* buffer, size_t capacity, (const struct sockaddr_in*)addr); } -int ip_address_set_sockaddr(ip_address_t* ip_address, struct sockaddr* sa) { +int hicn_ip_address_set_sockaddr(hicn_ip_address_t* ip_address, + struct sockaddr* sa) { switch (sa->sa_family) { case AF_INET: ip_address->v4.as_inaddr = ((struct sockaddr_in*)sa)->sin_addr; @@ -245,7 +246,7 @@ static int callback(const struct sockaddr* from, mdns_entry_type_t entry, struct sockaddr_storage addr; mdns_string_t fromaddrstr = - ip_address_to_string(addrbuffer, sizeof(addrbuffer), from); + hicn_ip_address_to_string(addrbuffer, sizeof(addrbuffer), from); const char* entrytype = (entry == MDNS_ENTRYTYPE_ANSWER) ? "answer" @@ -253,10 +254,10 @@ static int callback(const struct sockaddr* from, mdns_entry_type_t entry, switch (type) { case MDNS_RECORDTYPE_A: { - ip_address_t ip_address; + hicn_ip_address_t ip_address; mdns_record_parse_a(data, size, offset, length, (struct sockaddr_in*)&addr); - ip_address_set_sockaddr(&ip_address, (struct sockaddr*)&addr); + hicn_ip_address_set_sockaddr(&ip_address, (struct sockaddr*)&addr); mdns_string_t addrstr = ipv4_address_to_string( namebuffer, sizeof(namebuffer), (struct sockaddr_in*)&addr); @@ -276,10 +277,10 @@ static int callback(const struct sockaddr* from, mdns_entry_type_t entry, } case MDNS_RECORDTYPE_AAAA: { - ip_address_t ip_address; + hicn_ip_address_t ip_address; mdns_record_parse_aaaa(data, size, offset, length, (struct sockaddr_in6*)&addr); - ip_address_set_sockaddr(&ip_address, (struct sockaddr*)&addr); + hicn_ip_address_set_sockaddr(&ip_address, (struct sockaddr*)&addr); mdns_string_t addrstr = ipv6_address_to_string( namebuffer, sizeof(namebuffer), (struct sockaddr_in6*)&addr); diff --git a/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c b/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c index b396782f5..2275d1cff 100644 --- a/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c +++ b/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -23,6 +23,7 @@ #include // time #include +#include #include #include #include @@ -110,7 +111,7 @@ int hl_process_state(interface_t *interface) assert(!data->polled_routes); stop_poll_timer(interface); - // DEBUG("[hl_process_state] Querying route list"); + DEBUG("[hl_process_state] Querying route list"); if (hc_route_list_async(data->sp) < 0) { DEBUG("[hl_process_state] Error querying route list"); return -1; @@ -119,7 +120,8 @@ int hl_process_state(interface_t *interface) break; case HL_STATE_ROUTES_RECEIVED: - // DEBUG("[hl_process_state] Querying face list"); + DEBUG("[hl_process_state] Got route list"); + DEBUG("[hl_process_state] Querying face list"); if (hc_face_list_async(data->sp) < 0) { DEBUG("[hl_process_state] Error querying face list"); return -1; @@ -128,6 +130,7 @@ int hl_process_state(interface_t *interface) break; case HL_STATE_FACES_RECEIVED: + DEBUG("[hl_process_state] Got face list"); data->state = HL_STATE_IDLE; start_poll_timer(interface); break; @@ -215,11 +218,12 @@ int hl_connect_timeout(interface_t *interface, int fd, void *unused) { * connected to succeed. */ int _hl_connect(interface_t *interface) { + ERROR("[MACCHA] CONNECT"); hl_data_t *data = interface->data; assert(!data->s); assert(!data->sp); - data->s = hc_sock_create(); + data->s = hc_sock_create(FORWARDER_TYPE_HICNLIGHT, NULL); if (data->s <= 0) { ERROR("[hc_connect] Could not create control socket"); goto ERR_SOCK; @@ -230,7 +234,7 @@ int _hl_connect(interface_t *interface) { goto ERR_CONNECT; } - data->sp = hc_sock_create(); + data->sp = hc_sock_create(FORWARDER_TYPE_HICNLIGHT, NULL); if (data->sp <= 0) { ERROR("[hc_connect] Could not create polling socket"); goto ERR_SOCK_POLL; @@ -339,16 +343,12 @@ int hl_finalize(interface_t *interface) { } int hl_on_event(interface_t *interface, facelet_t *facelet) { - hc_face_t hc_face; hc_route_t route; int rc; int ret = 0; hl_data_t *data = (hl_data_t *)interface->data; face_t *face = NULL; - hc_face.id = 0; - memset(hc_face.name, 0, sizeof(hc_face.name)); - /* NOTE * - One example where this fails (and it is normal) is when we delete a * face that was not completely created, because for instance bonjour did @@ -373,14 +373,13 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { facelet_snprintf(buf, MAXSZ_FACELET, facelet); DEBUG("Create facelet %s", buf); - hc_face.face = *face; - rc = hc_face_create(data->s, &hc_face); + rc = hc_face_create(data->s, face); if (rc < 0) { ERROR("Failed to create face\n"); ret = -FACELET_ERROR_REASON_UNSPECIFIED_ERROR; goto ERR; } - INFO("Created face id=%d - %s", hc_face.id, buf); + INFO("Created face id=%d - %s", face->id, buf); } hicn_route_t **route_array; @@ -393,7 +392,7 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { if (n == 0) { /* Adding default routes */ route = (hc_route_t){ - .face_id = hc_face.id, + .face_id = face->id, .family = AF_INET, .remote_addr = IPV4_ANY, .len = 0, @@ -406,7 +405,7 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { } route = (hc_route_t){ - .face_id = hc_face.id, + .face_id = face->id, .family = AF_INET6, .remote_addr = IPV6_ANY, .len = 0, @@ -421,7 +420,7 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { } else { for (unsigned i = 0; i < n; i++) { hicn_route_t *hicn_route = route_array[i]; - ip_prefix_t prefix; + hicn_ip_prefix_t prefix; int cost; if (hicn_route_get_prefix(hicn_route, &prefix) < 0) { ERROR("Failed to get route prefix"); @@ -434,8 +433,8 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { continue; } route = (hc_route_t){ - .face_id = hc_face.id, - .name = "", /* take face_id into account */ + .face_id = face->id, + .face_name = "", /* take face_id into account */ .family = prefix.family, .remote_addr = prefix.address, .len = prefix.len, @@ -454,8 +453,7 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { case FACELET_EVENT_DELETE: /* Removing a face should also remove associated routes */ - hc_face.face = *face; - rc = hc_face_delete(data->s, &hc_face, 1); + rc = hc_face_delete(data->s, face); // delete_listener= */ 1); if (rc < 0) { ERROR("Failed to delete face\n"); ret = -FACELET_ERROR_REASON_UNSPECIFIED_ERROR; @@ -464,7 +462,7 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { char buf[MAXSZ_FACELET]; facelet_snprintf(buf, MAXSZ_FACELET, facelet); - INFO("Deleted face id=%d", hc_face.id); + INFO("Deleted face id=%d", face->id); break; @@ -472,10 +470,9 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { /* Currently, only admin_state & priority are supported */ if (facelet_get_admin_state_status(facelet) == FACELET_ATTR_STATUS_DIRTY) { - hc_face.face = *face; - hc_face_t *face_found; + hc_data_t *face_found; - rc = hc_face_get(data->s, &hc_face, &face_found); + rc = hc_face_get(data->s, face, &face_found); if (rc < 0) { ERROR("Failed to find face\n"); ret = -FACELET_ERROR_REASON_INTERNAL_ERROR; @@ -487,8 +484,10 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { goto ERR; } char conn_id_or_name[SYMBOLIC_NAME_LEN]; - snprintf(conn_id_or_name, SYMBOLIC_NAME_LEN, "%d", face_found->id); - free(face_found); + + const hc_object_t *object = hc_data_get_object(face_found, 0); + snprintf(conn_id_or_name, SYMBOLIC_NAME_LEN, "%d", object->face.id); + hc_data_free(face_found); face_state_t admin_state; if (facelet_get_admin_state(facelet, &admin_state) < 0) { @@ -504,16 +503,14 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { goto ERR; } facelet_set_admin_state_status(facelet, FACELET_ATTR_STATUS_CLEAN); - INFO("Updated face id=%d - admin_state=%s", hc_face.id, + INFO("Updated face id=%d - admin_state=%s", face->id, face_state_str(admin_state)); } -#ifdef WITH_POLICY if (facelet_get_netdevice_type_status(facelet) == FACELET_ATTR_STATUS_DIRTY) { - hc_face.face = *face; - hc_face_t *face_found; + hc_data_t *face_found; - rc = hc_face_get(data->s, &hc_face, &face_found); + rc = hc_face_get(data->s, face, &face_found); if (rc < 0) { ERROR("Failed to find face\n"); goto ERR; @@ -523,8 +520,9 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { goto ERR; } char conn_id_or_name[SYMBOLIC_NAME_LEN]; - snprintf(conn_id_or_name, SYMBOLIC_NAME_LEN, "%d", face_found->id); - free(face_found); + const hc_object_t *object = hc_data_get_object(face_found, 0); + snprintf(conn_id_or_name, SYMBOLIC_NAME_LEN, "%d", object->face.id); + hc_data_free(face_found); netdevice_type_t netdevice_type; if (facelet_get_netdevice_type(facelet, &netdevice_type) < 0) { @@ -565,15 +563,14 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { goto ERR; } facelet_set_netdevice_type_status(facelet, FACELET_ATTR_STATUS_CLEAN); - INFO("Updated face id=%d - netdevice_type=%s", hc_face.id, + INFO("Updated face id=%d - netdevice_type=%s", face->id, netdevice_type_str(netdevice_type)); } if (facelet_get_priority_status(facelet) == FACELET_ATTR_STATUS_DIRTY) { INFO("Updating priority..."); - hc_face.face = *face; - hc_face_t *face_found; + hc_data_t *face_found; - rc = hc_face_get(data->s, &hc_face, &face_found); + rc = hc_face_get(data->s, face, &face_found); if (rc < 0) { ERROR("Failed to find face\n"); goto ERR; @@ -583,8 +580,9 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { goto ERR; } char conn_id_or_name[SYMBOLIC_NAME_LEN]; - snprintf(conn_id_or_name, SYMBOLIC_NAME_LEN, "%d", face_found->id); - free(face_found); + const hc_object_t *object = hc_data_get_object(face_found, 0); + snprintf(conn_id_or_name, SYMBOLIC_NAME_LEN, "%d", object->face.id); + hc_data_free(face_found); uint32_t priority; if (facelet_get_priority(facelet, &priority) < 0) { @@ -601,9 +599,8 @@ int hl_on_event(interface_t *interface, facelet_t *facelet) { } facelet_set_priority_status(facelet, FACELET_ATTR_STATUS_CLEAN); - INFO("Updated face id=%d - priority=%d", hc_face.id, priority); + INFO("Updated face id=%d - priority=%d", face->id, priority); } -#endif /* WITH_POLICY */ break; default: @@ -637,7 +634,7 @@ int hl_callback(interface_t *interface, int fd, void *unused) { } /* In case of error, reconnect to forwarder */ - if (hc_sock_callback(data->sp, &results) < 0) { + if (hc_sock_receive_all(data->sp, &results) < 0) { INFO("Closing socket... reconnecting..."); if (interface_unregister_fd(interface, hc_sock_get_fd(data->sp)) < 0) { ERROR("[hl_callback] Error unregistering fd"); @@ -657,7 +654,7 @@ int hl_callback(interface_t *interface, int fd, void *unused) { } /* Shall we wait for more data ? */ - if (!results->complete) { + if (!hc_data_is_complete(results)) { INFO("[hl_callback] results incomplete"); return ret; } @@ -704,7 +701,7 @@ int hl_callback(interface_t *interface, int fd, void *unused) { /* We can ignore faces on localhost */ - facelet_t *facelet = facelet_create_from_face(&f->face); + facelet_t *facelet = facelet_create_from_face(f); if (!facelet) { ERROR("[hl_callback] Could not create facelet... skipping"); continue; @@ -725,7 +722,7 @@ int hl_callback(interface_t *interface, int fd, void *unused) { if (r->len == 0) continue; - ip_prefix_t prefix = { + hicn_ip_prefix_t prefix = { .family = r->family, .address = r->remote_addr, .len = r->len, diff --git a/ctrl/facemgr/src/interfaces/netlink/netlink.c b/ctrl/facemgr/src/interfaces/netlink/netlink.c index 11738d7ac..3c99dc5cc 100644 --- a/ctrl/facemgr/src/interfaces/netlink/netlink.c +++ b/ctrl/facemgr/src/interfaces/netlink/netlink.c @@ -257,7 +257,7 @@ ERR_ND: int parse_addr(struct nlmsghdr *h, facelet_t **facelet, char *interface_name, size_t interface_name_size, char *interface_address, size_t interface_address_size) { - ip_address_t local_addr = IP_ADDRESS_EMPTY; + hicn_ip_address_t local_addr = IP_ADDRESS_EMPTY; struct ifaddrmsg *ifa; // structure for network interface data struct rtattr *tba[IFA_MAX + 1]; @@ -298,8 +298,8 @@ int parse_addr(struct nlmsghdr *h, facelet_t **facelet, char *interface_name, /* See comment in parse_link */ if (interface_address) { assert(tba[IFA_ADDRESS]); - ip_address_snprintf(interface_address, interface_address_size, &local_addr, - ifa->ifa_family); + hicn_ip_address_snprintf(interface_address, interface_address_size, + &local_addr); } netdevice_t *netdevice = netdevice_create_from_index(ifa->ifa_index); diff --git a/ctrl/facemgr/src/interfaces/network_framework/network_framework.c b/ctrl/facemgr/src/interfaces/network_framework/network_framework.c index e1f5575d3..7f4a26c56 100644 --- a/ctrl/facemgr/src/interfaces/network_framework/network_framework.c +++ b/ctrl/facemgr/src/interfaces/network_framework/network_framework.c @@ -173,501 +173,499 @@ void dump_endpoint(nw_endpoint_t endpoint, int indent) { } } - void dump_path(nw_path_t path, int indent) { - /* nw_path_enumerate_interfaces : not interesting */ - nw_path_status_t path_status = nw_path_get_status(path); - printfi(indent, "Status: %s\n", path_status_str[path_status]); - printfi(indent, "Expensive: %s\n", - nw_path_is_expensive(path) ? "true" : "false"); - printfi(indent, "IPv4 enabled: %s\n", - nw_path_has_ipv4(path) ? "true" : "false"); - printfi(indent, "IPv6 enabled: %s\n", - nw_path_has_ipv6(path) ? "true" : "false"); - printfi(indent, "DNS: %s\n", nw_path_has_dns(path) ? "true" : "false"); - printfi(indent, "Interfaces:\n"); - nw_path_enumerate_interfaces( - path, - (nw_path_enumerate_interfaces_block_t) ^ (nw_interface_t interface) { - dump_interface(interface, indent + 1); - return true; - }); - - nw_endpoint_t local = nw_path_copy_effective_local_endpoint(path); - printfi(indent, "Effective local endpoint:\n"); - dump_endpoint(local, indent + 1); - nw_release(local); - - nw_endpoint_t remote = nw_path_copy_effective_remote_endpoint(path); - printfi(indent, "Effective remote endpoint:\n"); - dump_endpoint(remote, indent + 1); - nw_release(remote); - } +void dump_path(nw_path_t path, int indent) { + /* nw_path_enumerate_interfaces : not interesting */ + nw_path_status_t path_status = nw_path_get_status(path); + printfi(indent, "Status: %s\n", path_status_str[path_status]); + printfi(indent, "Expensive: %s\n", + nw_path_is_expensive(path) ? "true" : "false"); + printfi(indent, "IPv4 enabled: %s\n", + nw_path_has_ipv4(path) ? "true" : "false"); + printfi(indent, "IPv6 enabled: %s\n", + nw_path_has_ipv6(path) ? "true" : "false"); + printfi(indent, "DNS: %s\n", nw_path_has_dns(path) ? "true" : "false"); + printfi(indent, "Interfaces:\n"); + nw_path_enumerate_interfaces( + path, + (nw_path_enumerate_interfaces_block_t) ^ (nw_interface_t interface) { + dump_interface(interface, indent + 1); + return true; + }); - void dump_connection(nw_connection_t connection, int indent) { - nw_endpoint_t remote = nw_connection_copy_endpoint(connection); - nw_path_t path = nw_connection_copy_current_path(connection); + nw_endpoint_t local = nw_path_copy_effective_local_endpoint(path); + printfi(indent, "Effective local endpoint:\n"); + dump_endpoint(local, indent + 1); + nw_release(local); - printfi(indent, "Remote endpoint:\n"); - dump_endpoint(remote, indent + 1); - printfi(indent, "Path:\n"); - dump_path(path, indent + 1); + nw_endpoint_t remote = nw_path_copy_effective_remote_endpoint(path); + printfi(indent, "Effective remote endpoint:\n"); + dump_endpoint(remote, indent + 1); + nw_release(remote); +} - /* - nw_connection_copy_protocol_metadata(); - nw_connection_get_maximum_datagram_size(); - */ +void dump_connection(nw_connection_t connection, int indent) { + nw_endpoint_t remote = nw_connection_copy_endpoint(connection); + nw_path_t path = nw_connection_copy_current_path(connection); - nw_release(remote); - nw_release(path); - } + printfi(indent, "Remote endpoint:\n"); + dump_endpoint(remote, indent + 1); + printfi(indent, "Path:\n"); + dump_path(path, indent + 1); + + /* + nw_connection_copy_protocol_metadata(); + nw_connection_get_maximum_datagram_size(); + */ + + nw_release(remote); + nw_release(path); +} #if defined(MAC_OS_X_VERSION_10_15) - void dump_browse_result(nw_browse_result_t result, int indent) { - /* Endpoint */ - nw_endpoint_t browse_endpoint = nw_browse_result_copy_endpoint(result); - if (!browse_endpoint) { - ERROR( - "[network_framework.dump_result] Failed to retrieve endpoint from " - "Bonjour browse result"); - return; - } - printfi(indent + 1, "Endpoint:"); - dump_endpoint(browse_endpoint, indent + 2); - - /* Interfaces */ - printfi(indent + 1, "Interfaces:"); - nw_browse_result_enumerate_interfaces( - result, - (nw_browse_result_enumerate_interface_t) ^ (nw_interface_t interface) { - dump_interface(interface, indent + 2); - return true; - }); +void dump_browse_result(nw_browse_result_t result, int indent) { + /* Endpoint */ + nw_endpoint_t browse_endpoint = nw_browse_result_copy_endpoint(result); + if (!browse_endpoint) { + ERROR( + "[network_framework.dump_result] Failed to retrieve endpoint from " + "Bonjour browse result"); + return; } + printfi(indent + 1, "Endpoint:"); + dump_endpoint(browse_endpoint, indent + 2); + + /* Interfaces */ + printfi(indent + 1, "Interfaces:"); + nw_browse_result_enumerate_interfaces( + result, + (nw_browse_result_enumerate_interface_t) ^ (nw_interface_t interface) { + dump_interface(interface, indent + 2); + return true; + }); +} #endif /* defined(MAC_OS_X_VERSION_10_15) */ - facelet_t *facelet_create_from_connection(nw_connection_t connection) { - facelet_t *facelet; - ip_address_t local_addr, remote_addr; - uint16_t remote_port; - - nw_path_t path = nw_connection_copy_current_path(connection); - nw_endpoint_t local = nw_path_copy_effective_local_endpoint(path); - nw_endpoint_t remote = nw_path_copy_effective_remote_endpoint(path); - __block nw_interface_t interface; - - const struct sockaddr *local_sa = nw_endpoint_get_address(local); - const struct sockaddr *remote_sa = nw_endpoint_get_address(remote); - - assert(local_sa->sa_family == remote_sa->sa_family); - switch (local_sa->sa_family) { - case AF_INET: - local_addr.v4.as_inaddr = ((struct sockaddr_in *)local_sa)->sin_addr; - remote_addr.v4.as_inaddr = ((struct sockaddr_in *)remote_sa)->sin_addr; - remote_port = ((struct sockaddr_in *)remote_sa)->sin_port; - break; - case AF_INET6: - local_addr.v6.as_in6addr = ((struct sockaddr_in6 *)local_sa)->sin6_addr; - remote_addr.v6.as_in6addr = - ((struct sockaddr_in6 *)remote_sa)->sin6_addr; - remote_port = ((struct sockaddr_in6 *)remote_sa)->sin6_port; - break; - default: - ERROR("Unsupported address family: %d\n", local_sa->sa_family); - return NULL; - } - - /* Retrieving path interface type (a single one expected */ - nw_path_enumerate_interfaces( - path, (nw_path_enumerate_interfaces_block_t) ^ - (nw_interface_t path_interface) { - interface = path_interface; - return false; - }); - - const char *name = nw_interface_get_name(interface); - netdevice_t netdevice; - snprintf(netdevice.name, IFNAMSIZ, "%s", name); - netdevice_update_index(&netdevice); - - netdevice_type_t netdevice_type; - nw_interface_type_t type = nw_interface_get_type(interface); - - switch (type) { - case INTERFACE_TYPE_OTHER: - netdevice_type = NETDEVICE_TYPE_UNDEFINED; - break; - case INTERFACE_TYPE_WIFI: - netdevice_type = NETDEVICE_TYPE_WIFI; - break; - case INTERFACE_TYPE_CELLULAR: - netdevice_type = NETDEVICE_TYPE_CELLULAR; - break; - case INTERFACE_TYPE_WIRED: - netdevice_type = NETDEVICE_TYPE_WIRED; - break; - case INTERFACE_TYPE_LOOPBACK: - netdevice_type = NETDEVICE_TYPE_LOOPBACK; - break; - default: - break; - } +facelet_t *facelet_create_from_connection(nw_connection_t connection) { + facelet_t *facelet; + hicn_ip_address_t local_addr, remote_addr; + uint16_t remote_port; + + nw_path_t path = nw_connection_copy_current_path(connection); + nw_endpoint_t local = nw_path_copy_effective_local_endpoint(path); + nw_endpoint_t remote = nw_path_copy_effective_remote_endpoint(path); + __block nw_interface_t interface; + + const struct sockaddr *local_sa = nw_endpoint_get_address(local); + const struct sockaddr *remote_sa = nw_endpoint_get_address(remote); + + assert(local_sa->sa_family == remote_sa->sa_family); + switch (local_sa->sa_family) { + case AF_INET: + local_addr.v4.as_inaddr = ((struct sockaddr_in *)local_sa)->sin_addr; + remote_addr.v4.as_inaddr = ((struct sockaddr_in *)remote_sa)->sin_addr; + remote_port = ((struct sockaddr_in *)remote_sa)->sin_port; + break; + case AF_INET6: + local_addr.v6.as_in6addr = ((struct sockaddr_in6 *)local_sa)->sin6_addr; + remote_addr.v6.as_in6addr = ((struct sockaddr_in6 *)remote_sa)->sin6_addr; + remote_port = ((struct sockaddr_in6 *)remote_sa)->sin6_port; + break; + default: + ERROR("Unsupported address family: %d\n", local_sa->sa_family); + return NULL; + } - nw_release(local); - nw_release(remote); - nw_release(path); + /* Retrieving path interface type (a single one expected */ + nw_path_enumerate_interfaces( + path, + (nw_path_enumerate_interfaces_block_t) ^ (nw_interface_t path_interface) { + interface = path_interface; + return false; + }); - facelet = facelet_create(); - if (!facelet) return NULL; + const char *name = nw_interface_get_name(interface); + netdevice_t netdevice; + snprintf(netdevice.name, IFNAMSIZ, "%s", name); + netdevice_update_index(&netdevice); - facelet_set_netdevice(facelet, netdevice); - facelet_set_netdevice_type(facelet, netdevice_type); - facelet_set_family(facelet, local_sa->sa_family); - facelet_set_local_addr(facelet, local_addr); - facelet_set_remote_addr(facelet, remote_addr); - facelet_set_remote_port(facelet, remote_port); + netdevice_type_t netdevice_type; + nw_interface_type_t type = nw_interface_get_type(interface); - return facelet; + switch (type) { + case INTERFACE_TYPE_OTHER: + netdevice_type = NETDEVICE_TYPE_UNDEFINED; + break; + case INTERFACE_TYPE_WIFI: + netdevice_type = NETDEVICE_TYPE_WIFI; + break; + case INTERFACE_TYPE_CELLULAR: + netdevice_type = NETDEVICE_TYPE_CELLULAR; + break; + case INTERFACE_TYPE_WIRED: + netdevice_type = NETDEVICE_TYPE_WIRED; + break; + case INTERFACE_TYPE_LOOPBACK: + netdevice_type = NETDEVICE_TYPE_LOOPBACK; + break; + default: + break; } - void on_connection_state_event( - interface_t * interface, nw_interface_t iface, nw_connection_t cnx, - nw_connection_state_t state, nw_error_t error) { + nw_release(local); + nw_release(remote); + nw_release(path); + + facelet = facelet_create(); + if (!facelet) return NULL; + + facelet_set_netdevice(facelet, netdevice); + facelet_set_netdevice_type(facelet, netdevice_type); + facelet_set_family(facelet, local_sa->sa_family); + facelet_set_local_addr(facelet, local_addr); + facelet_set_remote_addr(facelet, remote_addr); + facelet_set_remote_port(facelet, remote_port); + + return facelet; +} + +void on_connection_state_event(interface_t *interface, nw_interface_t iface, + nw_connection_t cnx, nw_connection_state_t state, + nw_error_t error) { #if 1 - DEBUG("Connection [new state = %s]:\n", connection_state_str[state]); - nw_path_t path = nw_connection_copy_current_path(cnx); - nw_path_enumerate_interfaces( - path, - (nw_path_enumerate_interfaces_block_t) ^ (nw_interface_t interface) { - const char *name = nw_interface_get_name(interface); - printf("NAME=%s\n", name); - return true; - }); + DEBUG("Connection [new state = %s]:\n", connection_state_str[state]); + nw_path_t path = nw_connection_copy_current_path(cnx); + nw_path_enumerate_interfaces( + path, + (nw_path_enumerate_interfaces_block_t) ^ (nw_interface_t interface) { + const char *name = nw_interface_get_name(interface); + printf("NAME=%s\n", name); + return true; + }); #endif - /* We should get enough information to create the face and set if up - * asap */ + /* We should get enough information to create the face and set if up + * asap */ - nw_endpoint_t remote = nw_connection_copy_endpoint(cnx); - errno = error ? nw_error_get_error_code(error) : 0; + nw_endpoint_t remote = nw_connection_copy_endpoint(cnx); + errno = error ? nw_error_get_error_code(error) : 0; - switch (state) { - case nw_connection_state_waiting: - warn("connect to %s port %u (%s) failed, is waiting", - nw_endpoint_get_hostname(remote), nw_endpoint_get_port(remote), - BONJOUR_PROTOCOL_NAME); - break; + switch (state) { + case nw_connection_state_waiting: + warn("connect to %s port %u (%s) failed, is waiting", + nw_endpoint_get_hostname(remote), nw_endpoint_get_port(remote), + BONJOUR_PROTOCOL_NAME); + break; - case nw_connection_state_preparing: - break; + case nw_connection_state_preparing: + break; - case nw_connection_state_ready: { - printf("info:\n"); - warn("connection ready"); + case nw_connection_state_ready: { + printf("info:\n"); + warn("connection ready"); #if 1 - WITH_DEBUG({ dump_connection(cnx, 1); }); + WITH_DEBUG({ dump_connection(cnx, 1); }); #endif - facelet_t *facelet = facelet_create_from_connection(cnx); - if (!facelet) return; - facelet_set_event(facelet, FACELET_EVENT_CREATE); - interface_raise_event(interface, facelet); - break; - } - case nw_connection_state_failed: - /* Can we fail with bonjour, or are we always waiting ? */ - warn("connect to %s port %u (%s) failed", - nw_endpoint_get_hostname(remote), nw_endpoint_get_port(remote), - BONJOUR_PROTOCOL_NAME); - break; - - case nw_connection_state_cancelled: - // Release the primary reference on the connection - // that was taken at creation time - nw_release(cnx); - break; - - default: /* nw_connection_state_invalid */ - /* Should never be called */ - break; + facelet_t *facelet = facelet_create_from_connection(cnx); + if (!facelet) return; + facelet_set_event(facelet, FACELET_EVENT_CREATE); + interface_raise_event(interface, facelet); + break; } - - nw_release(remote); + case nw_connection_state_failed: + /* Can we fail with bonjour, or are we always waiting ? */ + warn("connect to %s port %u (%s) failed", + nw_endpoint_get_hostname(remote), nw_endpoint_get_port(remote), + BONJOUR_PROTOCOL_NAME); + break; + + case nw_connection_state_cancelled: + // Release the primary reference on the connection + // that was taken at creation time + nw_release(cnx); + break; + + default: /* nw_connection_state_invalid */ + /* Should never be called */ + break; } - void on_connection_path_event(interface_t * interface, nw_interface_t iface, - nw_connection_t cnx, nw_path_t path) { + nw_release(remote); +} + +void on_connection_path_event(interface_t *interface, nw_interface_t iface, + nw_connection_t cnx, nw_path_t path) { #if 1 - DEBUG("Connection [path changed]:\n"); - WITH_DEBUG({ dump_connection(cnx, 1); }); + DEBUG("Connection [path changed]:\n"); + WITH_DEBUG({ dump_connection(cnx, 1); }); #endif - /* redundant */ /* - DEBUG(1, "Path:\n"); - dump_path(path, 2); - */ - } + /* redundant */ /* + DEBUG(1, "Path:\n"); + dump_path(path, 2); + */ +} - /** - * Enumerate main path interfaces +/** + * Enumerate main path interfaces + * + * We need to create specific dummy connections for each newly discovered + * interface + * + * Currently we only use Bonjour/TCP for remote hICN discovery and connection + * path monitoring. + */ +void on_interface_event(interface_t *interface, nw_interface_t iface) { + /* We can create an hICN face on this interface that will be down until + * connected + * It is however possible to have two default gateways on the same + * interface, or more, or even zero. Somehow we need a strategy, timers, etc + * to properly do the job. * - * We need to create specific dummy connections for each newly discovered - * interface + * We have to determine: + * - how many faces to build + * - the face type : hICN, tunnel (TCP/UDP) + * - the underlying protocol : v4, v6 * - * Currently we only use Bonjour/TCP for remote hICN discovery and connection - * path monitoring. + * This depends on the configuration, end host and network capabilities. + * + * We can rely on several types of discovery: + * - DHCP + * - Bonjour + * - ... + * + * So far: + * - bonjour discovery attempt, we expect to discover one hICN interface + * (how bonjour works with more than one is unclear), after a certain + * time, if none is discovered, we cannot do any tunnel face. */ - void on_interface_event(interface_t * interface, nw_interface_t iface) { - /* We can create an hICN face on this interface that will be down until - * connected - * It is however possible to have two default gateways on the same - * interface, or more, or even zero. Somehow we need a strategy, timers, etc - * to properly do the job. - * - * We have to determine: - * - how many faces to build - * - the face type : hICN, tunnel (TCP/UDP) - * - the underlying protocol : v4, v6 - * - * This depends on the configuration, end host and network capabilities. - * - * We can rely on several types of discovery: - * - DHCP - * - Bonjour - * - ... - * - * So far: - * - bonjour discovery attempt, we expect to discover one hICN interface - * (how bonjour works with more than one is unclear), after a certain - * time, if none is discovered, we cannot do any tunnel face. - */ - // OLD CODE + // OLD CODE - /* nw_parameters_create_secure_{udp,tcp} */ - nw_parameters_t parameters = nw_parameters_create_fn( - NW_PARAMETERS_DISABLE_PROTOCOL, /* no (d)tls */ - NW_PARAMETERS_DEFAULT_CONFIGURATION /* default udp/tcp */); + /* nw_parameters_create_secure_{udp,tcp} */ + nw_parameters_t parameters = nw_parameters_create_fn( + NW_PARAMETERS_DISABLE_PROTOCOL, /* no (d)tls */ + NW_PARAMETERS_DEFAULT_CONFIGURATION /* default udp/tcp */); - if (!parameters) goto ERR_PARAMETERS; + if (!parameters) goto ERR_PARAMETERS; - nw_parameters_require_interface(parameters, iface); - nw_parameters_set_reuse_local_address(parameters, true); + nw_parameters_require_interface(parameters, iface); + nw_parameters_set_reuse_local_address(parameters, true); #if defined(MAC_OS_X_VERSION_10_15) - /* - * Before being able to create a bonjour endpoint, we need to browse for - * available services on the local network using the parameters specified - * before. - */ - nw_browse_descriptor_t descriptor = - nw_browse_descriptor_create_bonjour_service(BONJOUR_SERVICE_TYPE, - BONJOUR_SERVICE_DOMAIN); - if (!descriptor) { - ERROR( - "[network_framework.on_interface_event] Failed to create a bonjour " - "browse descriptor"); - goto ERR_DESCRIPTOR; - } + /* + * Before being able to create a bonjour endpoint, we need to browse for + * available services on the local network using the parameters specified + * before. + */ + nw_browse_descriptor_t descriptor = + nw_browse_descriptor_create_bonjour_service(BONJOUR_SERVICE_TYPE, + BONJOUR_SERVICE_DOMAIN); + if (!descriptor) { + ERROR( + "[network_framework.on_interface_event] Failed to create a bonjour " + "browse descriptor"); + goto ERR_DESCRIPTOR; + } - nw_browser_t browser = nw_browser_create(descriptor, parameters); - nw_browser_set_queue(browser, dispatch_get_main_queue()); - nw_browser_set_browse_results_changed_handler(browser, ^( - nw_browse_result_t result, - nw_browse_result_t - result2, - bool flag) { - /* Dump result */ - printfi(0, "NEW BROWSE RESULT"); - printfi(1, "Result:"); - dump_browse_result(result, 2); - printfi(1, "Result2:"); - dump_browse_result(result2, 2); - printfi(1, "Flag: %s\n", (flag ? "ON" : "OFF")); - - /* Changes */ - nw_browse_result_change_t change = - nw_browse_result_get_changes(result, result2); - switch (change) { - case nw_browse_result_change_identical: - printfi(2, "The compared services are identical."); - break; - case nw_browse_result_change_result_added: - printfi(2, "A new service was discovered."); - break; + nw_browser_t browser = nw_browser_create(descriptor, parameters); + nw_browser_set_queue(browser, dispatch_get_main_queue()); + nw_browser_set_browse_results_changed_handler(browser, ^( + nw_browse_result_t result, + nw_browse_result_t result2, + bool flag) { + /* Dump result */ + printfi(0, "NEW BROWSE RESULT"); + printfi(1, "Result:"); + dump_browse_result(result, 2); + printfi(1, "Result2:"); + dump_browse_result(result2, 2); + printfi(1, "Flag: %s\n", (flag ? "ON" : "OFF")); + + /* Changes */ + nw_browse_result_change_t change = + nw_browse_result_get_changes(result, result2); + switch (change) { + case nw_browse_result_change_identical: + printfi(2, "The compared services are identical."); + break; + case nw_browse_result_change_result_added: + printfi(2, "A new service was discovered."); + break; - case nw_browse_result_change_result_removed: - printfi(2, "A previously discovered service was removed."); - break; + case nw_browse_result_change_result_removed: + printfi(2, "A previously discovered service was removed."); + break; - case nw_browse_result_change_txt_record_changed: - printfi(2, "The service's associated TXT record changed."); - break; + case nw_browse_result_change_txt_record_changed: + printfi(2, "The service's associated TXT record changed."); + break; - case nw_browse_result_change_interface_added: - printfi(2, "The service was discovered over a new interface."); - break; + case nw_browse_result_change_interface_added: + printfi(2, "The service was discovered over a new interface."); + break; - case nw_browse_result_change_interface_removed: - printfi( - 2, - "The service was no longer discovered over a certain interface."); - break; - } - }); + case nw_browse_result_change_interface_removed: + printfi( + 2, + "The service was no longer discovered over a certain interface."); + break; + } + }); - nw_browser_start(browser); + nw_browser_start(browser); //#else //#warning "Bonjour discovery only available in MacOS 10.15+" #endif /* defined(MAC_OS_X_VERSION_10_15) */ - /* - * Now that we have resolve the name of a bonjour remote, we can create a - * connection to the corresponding endpoint identified by its name. - */ - nw_endpoint_t endpoint; + /* + * Now that we have resolve the name of a bonjour remote, we can create a + * connection to the corresponding endpoint identified by its name. + */ + nw_endpoint_t endpoint; - DEBUG("Creating bonjour service towards NAME=%s TYPE=%s DOMAIN=%s", - BONJOUR_SERVICE_NAME, BONJOUR_SERVICE_TYPE, BONJOUR_SERVICE_DOMAIN); - endpoint = nw_endpoint_create_bonjour_service( + DEBUG("Creating bonjour service towards NAME=%s TYPE=%s DOMAIN=%s", BONJOUR_SERVICE_NAME, BONJOUR_SERVICE_TYPE, BONJOUR_SERVICE_DOMAIN); + endpoint = nw_endpoint_create_bonjour_service( + BONJOUR_SERVICE_NAME, BONJOUR_SERVICE_TYPE, BONJOUR_SERVICE_DOMAIN); - if (!endpoint) { - ERROR( - "[network_framework.on_interface_event] Failed to create bound " - "Bonjour " - "connection"); - goto ERR_ENDPOINT; - } + if (!endpoint) { + ERROR( + "[network_framework.on_interface_event] Failed to create bound " + "Bonjour " + "connection"); + goto ERR_ENDPOINT; + } - nw_connection_t connection = nw_connection_create(endpoint, parameters); - if (!connection) goto ERR_CONNECTION; + nw_connection_t connection = nw_connection_create(endpoint, parameters); + if (!connection) goto ERR_CONNECTION; - nw_release(endpoint); - nw_release(parameters); + nw_release(endpoint); + nw_release(parameters); - /* Remember not to recreate connection */ - // XXX TODO + /* Remember not to recreate connection */ + // XXX TODO - /* Setup connection handlers */ + /* Setup connection handlers */ - nw_connection_set_state_changed_handler( - connection, ^(nw_connection_state_t state, nw_error_t error) { - on_connection_state_event(interface, iface, connection, state, error); - }); + nw_connection_set_state_changed_handler( + connection, ^(nw_connection_state_t state, nw_error_t error) { + on_connection_state_event(interface, iface, connection, state, error); + }); - nw_connection_set_path_changed_handler(connection, ^(nw_path_t path) { - on_connection_path_event(interface, iface, connection, path); - }); + nw_connection_set_path_changed_handler(connection, ^(nw_path_t path) { + on_connection_path_event(interface, iface, connection, path); + }); - nw_connection_set_better_path_available_handler(connection, ^(bool value) { + nw_connection_set_better_path_available_handler(connection, ^(bool value) { #if 1 - DEBUG("Connection [better path = %s]\n", (value ? "true" : "false")); - WITH_DEBUG({ dump_connection(connection, 1); }); + DEBUG("Connection [better path = %s]\n", (value ? "true" : "false")); + WITH_DEBUG({ dump_connection(connection, 1); }); #endif - }); + }); - nw_connection_set_viability_changed_handler(connection, ^(bool value) { + nw_connection_set_viability_changed_handler(connection, ^(bool value) { #if 1 - DEBUG("Connection [viable = %s]\n", (value ? "true" : "false")); - WITH_DEBUG({ - // dump_connection(connection, 1); - }); + DEBUG("Connection [viable = %s]\n", (value ? "true" : "false")); + WITH_DEBUG({ + // dump_connection(connection, 1); + }); #endif - /* - * This is the first time we have a connection with address and port - * and thus the full identification of an hICN face - */ - facelet_t *facelet = facelet_create_from_connection(connection); - if (!facelet) return; - facelet_set_event(facelet, - value ? FACELET_EVENT_CREATE : FACELET_EVENT_DELETE); - interface_raise_event(interface, facelet); - }); + /* + * This is the first time we have a connection with address and port + * and thus the full identification of an hICN face + */ + facelet_t *facelet = facelet_create_from_connection(connection); + if (!facelet) return; + facelet_set_event(facelet, + value ? FACELET_EVENT_CREATE : FACELET_EVENT_DELETE); + interface_raise_event(interface, facelet); + }); - nw_connection_start(connection); + nw_connection_start(connection); - nw_connection_set_queue(connection, dispatch_get_main_queue()); - nw_retain(connection); // Hold a reference until cancelled + nw_connection_set_queue(connection, dispatch_get_main_queue()); + nw_retain(connection); // Hold a reference until cancelled #if 1 - DEBUG("Created Bonjour cnx on interface:"); - WITH_DEBUG({ dump_interface(iface, 1); }); + DEBUG("Created Bonjour cnx on interface:"); + WITH_DEBUG({ dump_interface(iface, 1); }); #endif - return; + return; - nw_release(connection); - ERR_CONNECTION: - nw_release(endpoint); - ERR_ENDPOINT: + nw_release(connection); +ERR_CONNECTION: + nw_release(endpoint); +ERR_ENDPOINT: #if defined(MAC_OS_X_VERSION_10_15) - nw_release(descriptor); - ERR_DESCRIPTOR: + nw_release(descriptor); +ERR_DESCRIPTOR: #endif /* defined(MAC_OS_X_VERSION_10_15) */ - nw_release(parameters); + nw_release(parameters); - ERR_PARAMETERS: - return; - } +ERR_PARAMETERS: + return; +} - void on_path_event(interface_t * interface, nw_path_t path) { - /* Simplification: we handle path event only once. - * Ideally, test whether we discover new interfaces or not - */ +void on_path_event(interface_t *interface, nw_path_t path) { + /* Simplification: we handle path event only once. + * Ideally, test whether we discover new interfaces or not + */ #if 1 - DEBUG("Path [event]:\n"); - WITH_DEBUG({ dump_path(path, 1); }); + DEBUG("Path [event]:\n"); + WITH_DEBUG({ dump_path(path, 1); }); #endif - nw_path_enumerate_interfaces( - path, (nw_path_enumerate_interfaces_block_t) ^ (nw_interface_t iface) { - on_interface_event(interface, iface); - return true; - }); - } + nw_path_enumerate_interfaces( + path, (nw_path_enumerate_interfaces_block_t) ^ (nw_interface_t iface) { + on_interface_event(interface, iface); + return true; + }); +} - int nf_initialize(interface_t * interface, void *cfg) { - nf_data_t *data = malloc(sizeof(nf_data_t)); - if (!data) goto ERR_MALLOC; +int nf_initialize(interface_t *interface, void *cfg) { + nf_data_t *data = malloc(sizeof(nf_data_t)); + if (!data) goto ERR_MALLOC; - if (cfg) data->cfg = *(network_framework_cfg_t *)cfg; + if (cfg) data->cfg = *(network_framework_cfg_t *)cfg; - data->pm = nw_path_monitor_create(); - if (!data->pm) goto ERR_PM; + data->pm = nw_path_monitor_create(); + if (!data->pm) goto ERR_PM; - nw_path_monitor_set_queue(data->pm, dispatch_get_main_queue()); - nw_path_monitor_set_cancel_handler(data->pm, ^(){ - }); - nw_path_monitor_set_update_handler(data->pm, ^(nw_path_t path) { - on_path_event(interface, path); - }); + nw_path_monitor_set_queue(data->pm, dispatch_get_main_queue()); + nw_path_monitor_set_cancel_handler(data->pm, ^(){ + }); + nw_path_monitor_set_update_handler(data->pm, ^(nw_path_t path) { + on_path_event(interface, path); + }); - // XXX NEEDED ? - nw_retain(data->pm); + // XXX NEEDED ? + nw_retain(data->pm); - DEBUG("Starting network path monitor"); - nw_path_monitor_start(data->pm); + DEBUG("Starting network path monitor"); + nw_path_monitor_start(data->pm); - interface->data = data; - return 0; + interface->data = data; + return 0; - ERR_PM: - free(data); - ERR_MALLOC: - return -1; - } +ERR_PM: + free(data); +ERR_MALLOC: + return -1; +} - int nf_finalize(interface_t * interface) { - nf_data_t *data = (nf_data_t *)interface->data; - if (data->pm) { - nw_path_monitor_cancel(data->pm); - data->pm = NULL; - } - return 0; +int nf_finalize(interface_t *interface) { + nf_data_t *data = (nf_data_t *)interface->data; + if (data->pm) { + nw_path_monitor_cancel(data->pm); + data->pm = NULL; } + return 0; +} - const interface_ops_t network_framework_ops = { - .type = "network_framework", - .initialize = nf_initialize, - .finalize = nf_finalize, - .on_event = NULL, - }; +const interface_ops_t network_framework_ops = { + .type = "network_framework", + .initialize = nf_initialize, + .finalize = nf_finalize, + .on_event = NULL, +}; -- cgit 1.2.3-korg