diff options
Diffstat (limited to 'ctrl/libhicnctrl/includes')
-rw-r--r--[l---------] | ctrl/libhicnctrl/includes/ctrl.h | 26 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/api.h | 135 | ||||
-rwxr-xr-x | ctrl/libhicnctrl/includes/hicn/ctrl/commands.h | 12 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/face.h | 90 |
4 files changed, 141 insertions, 122 deletions
diff --git a/ctrl/libhicnctrl/includes/ctrl.h b/ctrl/libhicnctrl/includes/ctrl.h index 646630968..e61b7a482 120000..100644 --- a/ctrl/libhicnctrl/includes/ctrl.h +++ b/ctrl/libhicnctrl/includes/ctrl.h @@ -1 +1,25 @@ -hicn/ctrl.h
\ No newline at end of file +/* + * Copyright (c) 2017-2019 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: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * \file ctrl.h + * \brief Main interface for hICN control library + */ +#ifndef HICNCTRL_H +#define HICNCTRL_H + +#include <hicn/ctrl/api.h> + +#endif /* HICNCTRL_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h index 45efb39f9..a0ee828b9 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h @@ -68,42 +68,19 @@ #include <stdbool.h> #include <stdint.h> +#include <hicn/util/ip_address.h> #include "face.h" -#include "util/types.h" + +#define HICN_DEFAULT_PORT 9695 #define LIBHICNCTRL_SUCCESS 0 #define LIBHICNCTRL_FAILURE -1 #define LIBHICNCTRL_NOT_IMPLEMENTED -99 #define LIBHICNCTRL_IS_ERROR(x) (x < 0) - -/** - * This allows to selectively define convenience types to avoid any collision - * when using the library in conjunction with other frameworks including similar - * defines - */ -#ifdef _HICNTRL_NO_DEFS -#define _HICNTRL_NO_DEF_TYPES -#define _HICNTRL_NO_DEF_IPADDR -#define _HICNTRL_NO_DEF_UNIONCAST -#endif - -#ifndef _HICNTRL_NO_DEF_TYPES -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; -#endif /* _HICNTRL_NO_DEF_TYPES */ - -#ifndef _HICNTRL_NO_DEF_IPADDR -#include "util/ip_address.h" -#endif /* _HICNTRL_NO_DEF_IPADDR */ - -#ifndef _HICNTRL_NO_DEF_UNIONCAST /* Helper for avoiding warnings about type-punning */ #define UNION_CAST(x, destType) \ (((union {__typeof__(x) a; destType b;})x).b) -#endif /* _HICNTRL_NO_DEF_UNIONCAST */ /****************************************************************************** * Message helper types and aliases @@ -419,27 +396,13 @@ hc_sock_reset(hc_sock_t * s); #endif #define NAME_LEN 16 /* NULL-terminated right ? */ -#ifdef __linux__ #define INTERFACE_LEN 16 -#endif #define MAXSZ_HC_NAME_ NAME_LEN #define MAXSZ_HC_NAME MAXSZ_HC_NAME_ + NULLTERM #define MAXSZ_HC_ID_ 10 /* Number of digits for MAX_INT */ #define MAXSZ_HC_ID MAXSZ_HC_ID_ + NULLTERM -#define MAXSZ_HC_PROTO_ 8 /* inetX:// */ -#define MAXSZ_HC_PROTO MAXSZ_HC_PROTO_ + NULLTERM - -#define MAXSZ_HC_URL4_ MAXSZ_HC_PROTO_ + MAXSZ_IP4_ADDRESS_ + MAXSZ_PORT_ -#define MAXSZ_HC_URL6_ MAXSZ_HC_PROTO_ + MAXSZ_IP6_ADDRESS_ + MAXSZ_PORT_ -#define MAXSZ_HC_URL_ MAXSZ_HC_URL6_ -#define MAXSZ_HC_URL4 MAXSZ_HC_URL4_ + NULLTERM -#define MAXSZ_HC_URL6 MAXSZ_HC_URL6_ + NULLTERM -#define MAXSZ_HC_URL MAXSZ_HC_URL_ + NULLTERM - -int hc_url_snprintf(char * s, size_t size, int family, - const ip_address_t * ip_address, u16 port); #define foreach_type(TYPE, VAR, data) \ for (TYPE * VAR = (TYPE*)data->buffer; \ @@ -498,9 +461,7 @@ typedef int (*HC_PARSE)(const u8 *, u8 *); // FIXME the listener should not require any port for hICN... typedef struct { char name[NAME_LEN]; /* K.w */ // XXX clarify what used for -#ifdef __linux__ char interface_name[INTERFACE_LEN]; /* Kr. */ -#endif u32 id; hc_connection_type_t type; /* .rw */ int family; /* .rw */ @@ -509,6 +470,7 @@ typedef struct { } hc_listener_t; int hc_listener_create(hc_sock_t * s, hc_listener_t * listener); +/* listener_found might eventually be allocated, and needs to be freed */ int hc_listener_get(hc_sock_t *s, hc_listener_t * listener, hc_listener_t ** listener_found); int hc_listener_delete(hc_sock_t * s, hc_listener_t * listener); @@ -520,7 +482,7 @@ int hc_listener_parse(void * in, hc_listener_t * listener); #define foreach_listener(VAR, data) foreach_type(hc_listener_t, VAR, data) -#define MAXSZ_HC_LISTENER_ MAXSZ_HC_URL_ + SPACE + MAXSZ_HC_CONNECTION_TYPE_ +#define MAXSZ_HC_LISTENER_ INTERFACE_LEN + SPACE + MAXSZ_URL_ + SPACE + MAXSZ_HC_CONNECTION_TYPE_ #define MAXSZ_HC_LISTENER MAXSZ_HC_LISTENER_ + NULLTERM GENERATE_FIND_HEADER(listener); @@ -531,9 +493,15 @@ int hc_listener_snprintf(char * s, size_t size, hc_listener_t * listener); * Connections *----------------------------------------------------------------------------*/ +/* + * NOTE : + * - interface_name is mainly used to derive listeners from connections, but is + * not itself used to create connections. + */ typedef struct { u32 id; /* Kr. */ char name[NAME_LEN]; /* K.w */ + char interface_name[INTERFACE_LEN]; /* Kr. */ hc_connection_type_t type; /* .rw */ int family; /* .rw */ ip_address_t local_addr; /* .rw */ @@ -549,6 +517,7 @@ typedef struct { int hc_connection_create(hc_sock_t * s, hc_connection_t * connection); +/* connection_found will be allocated, and must be freed */ int hc_connection_get(hc_sock_t *s, hc_connection_t * connection, hc_connection_t ** connection_found); int hc_connection_update_by_id(hc_sock_t * s, int hc_connection_id, @@ -567,13 +536,14 @@ int hc_connection_cmp(const hc_connection_t * c1, const hc_connection_t * c2); int hc_connection_parse(void * in, hc_connection_t * connection); #ifdef WITH_POLICY -int hc_connection_set_state(hc_sock_t * s, const char * conn_id_or_name, face_state_t state); +int hc_connection_set_admin_state(hc_sock_t * s, const char * conn_id_or_name, face_state_t state); #endif /* WITH_POLICY */ #define foreach_connection(VAR, data) foreach_type(hc_connection_t, VAR, data) -#define MAXSZ_HC_CONNECTION_ MAXSZ_HC_CONNECTION_STATE_ + \ - 2 * MAXSZ_HC_URL_ + MAXSZ_HC_CONNECTION_TYPE_ + SPACES(3) +#define MAXSZ_HC_CONNECTION_ MAXSZ_HC_CONNECTION_STATE_ + \ + INTERFACE_LEN + SPACE + \ + 2 * MAXSZ_URL_ + MAXSZ_HC_CONNECTION_TYPE_ + SPACES(3) #define MAXSZ_HC_CONNECTION MAXSZ_HC_CONNECTION_ + NULLTERM GENERATE_FIND_HEADER(connection); @@ -581,38 +551,6 @@ GENERATE_FIND_HEADER(connection); int hc_connection_snprintf(char * s, size_t size, const hc_connection_t * connection); /*----------------------------------------------------------------------------* - * Routes - *----------------------------------------------------------------------------*/ - -typedef struct { - u8 face_id; /* Kr. */ - int family; /* Krw */ - ip_address_t remote_addr; /* krw */ - u8 len; /* krw */ - u16 cost; /* .rw */ -} hc_route_t; - -int hc_route_parse(void * in, hc_route_t * route); - -int hc_route_create(hc_sock_t * s, hc_route_t * route); -int hc_route_delete(hc_sock_t * s, hc_route_t * route); -int hc_route_list(hc_sock_t * s, hc_data_t ** pdata); - -#define foreach_route(VAR, data) foreach_type(hc_route_t, VAR, data) - -#define MAX_FACE_ID 255 -#define MAXSZ_FACE_ID 3 -#define MAX_COST 65535 -#define MAXSZ_COST 5 -#define MAX_LEN 255 -#define MAXSZ_LEN 3 - -#define MAXSZ_HC_ROUTE_ MAXSZ_FACE_ID + 1 + MAXSZ_COST + 1 + MAXSZ_IP_ADDRESS + 1 + MAXSZ_LEN -#define MAXSZ_HC_ROUTE MAXSZ_HC_ROUTE_ + NULLTERM - -int hc_route_snprintf(char * s, size_t size, hc_route_t * route); - -/*----------------------------------------------------------------------------* * Faces * * A face is an abstraction introduced by the control library to abstract the @@ -623,7 +561,7 @@ int hc_route_snprintf(char * s, size_t size, hc_route_t * route); *----------------------------------------------------------------------------*/ typedef struct { - u32 id; + u8 id; char name[NAME_LEN]; face_t face; // or embed ? //face_id_t parent; /* Pointer from connection to listener */ @@ -644,12 +582,47 @@ int hc_face_list(hc_sock_t * s, hc_data_t ** pdata); #define foreach_face(VAR, data) foreach_type(hc_face_t, VAR, data) -#define MAXSZ_HC_FACE_ 0 +#define MAX_FACE_ID 255 +#define MAXSZ_FACE_ID_ 3 +#define MAXSZ_FACE_ID MAXSZ_FACE_ID_ + NULLTERM +#define MAXSZ_FACE_NAME_ NAMELEN +#define MAXSZ_FACE_NAME MAXSZ_FACE_NAME_ + NULLTERM + +#define MAXSZ_HC_FACE_ MAXSZ_FACE_ID_ + MAXSZ_FACE_NAME_ + MAXSZ_FACE_ + 5 #define MAXSZ_HC_FACE MAXSZ_HC_FACE_ + NULLTERM int hc_face_snprintf(char * s, size_t size, hc_face_t * face); -/////// XXX XXX XXX XXX missing face api functions, cf punting now... +/*----------------------------------------------------------------------------* + * Routes + *----------------------------------------------------------------------------*/ + +typedef struct { + u8 face_id; /* Kr. */ + int family; /* Krw */ + ip_address_t remote_addr; /* krw */ + u8 len; /* krw */ + u16 cost; /* .rw */ +} hc_route_t; + +int hc_route_parse(void * in, hc_route_t * route); + +int hc_route_create(hc_sock_t * s, hc_route_t * route); +int hc_route_delete(hc_sock_t * s, hc_route_t * route); +int hc_route_list(hc_sock_t * s, hc_data_t ** pdata); + +#define foreach_route(VAR, data) foreach_type(hc_route_t, VAR, data) + +#define MAX_COST 65535 +#define MAXSZ_COST 5 +#define MAX_LEN 255 +#define MAXSZ_LEN 3 + +#define MAXSZ_HC_ROUTE_ MAXSZ_FACE_ID + 1 + MAXSZ_COST + 1 + MAXSZ_IP_ADDRESS + 1 + MAXSZ_LEN +#define MAXSZ_HC_ROUTE MAXSZ_HC_ROUTE_ + NULLTERM + +int hc_route_snprintf(char * s, size_t size, hc_route_t * route); + /*----------------------------------------------------------------------------* * Punting diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h b/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h index 1d07c9b72..4209c6eb6 100755 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h @@ -32,7 +32,7 @@ #include <stdlib.h> #ifdef WITH_POLICY -#include "util/policy.h" +#include <hicn/policy.h> #endif /* WITH_POLICY */ typedef struct in6_addr ipv6_addr_t; @@ -131,6 +131,7 @@ typedef struct { typedef struct { char symbolic[16]; + //char interfaceName[16]; union commandAddr remoteIp; union commandAddr localIp; uint16_t remotePort; @@ -166,9 +167,9 @@ typedef struct { add_connection_command connectionData; uint32_t connid; uint8_t state; -#ifdef WITH_UPDATE + uint8_t admin_state; char connectionName[16]; -#endif /* WITH_UPDATE */ + char interfaceName[16]; } list_connections_command; // SIZE=64 @@ -282,10 +283,8 @@ typedef struct { typedef struct { union commandAddr address; -#ifdef WITH_UPDATE char listenerName[16]; char interfaceName[16]; -#endif /* WITH_UPDATE */ uint32_t connid; uint16_t port; uint8_t addressType; @@ -310,11 +309,10 @@ typedef struct { // SIZE=1 -//========== NEW COMMANDS ========== - typedef struct { char symbolicOrConnid[16]; uint8_t admin_state; + uint8_t pad8[3]; } connection_set_admin_state_command; #ifdef WITH_POLICY diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/face.h b/ctrl/libhicnctrl/includes/hicn/ctrl/face.h index 2856ce89b..5c1fecd55 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/face.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/face.h @@ -30,12 +30,11 @@ #define NULLTERM 1 #endif -#ifndef _HICNTRL_NO_DEF_IPADDR -#include "util/ip_address.h" -#endif /* _HICNTRL_NO_DEF_IPADDR */ -#include "util/policy.h" -#include "util/types.h" +#include <hicn/policy.h> +#include <hicn/util/ip_address.h> + +typedef unsigned int hash_t; /* Netdevice type */ @@ -43,6 +42,7 @@ #define foreach_netdevice_type \ _(UNDEFINED) \ + _(LOOPBACK) \ _(WIRED) \ _(WIFI) \ _(CELLULAR) \ @@ -63,25 +63,48 @@ extern const char * netdevice_type_str[]; /* Netdevice */ +/** + * \brief Netdevice type + * + * NOTE + * - This struct cannot be made opaque as it is currently part of face_t + * - We recommand using the API as to keep redundant attributes consistent + */ typedef struct { u32 index; char name[IFNAMSIZ]; } netdevice_t; +#define NETDEVICE_EMPTY (netdevice_t) { \ + .index = 0, \ + .name = {0}, \ +} + +netdevice_t * netdevice_create_from_index(u32 index); +netdevice_t * netdevice_create_from_name(const char * name); +#define netdevice_initialize_from_index netdevice_set_index +#define netdevice_initialize_from_name netdevice_set_name +void netdevice_free(netdevice_t * netdevice); +int netdevice_get_index(const netdevice_t * netdevice, u32 * index); +int netdevice_set_index(netdevice_t * netdevice, u32 index); +int netdevice_get_name(const netdevice_t * netdevice, const char ** name); +int netdevice_set_name(netdevice_t * netdevice, const char * name); +int netdevice_update_index(netdevice_t * netdevice); +int netdevice_update_name(netdevice_t * netdevice); +int netdevice_cmp(const netdevice_t * nd1, const netdevice_t * nd2); + #define NETDEVICE_UNDEFINED_INDEX 0 /* Face state */ #define foreach_face_state \ _(UNDEFINED) \ - _(PENDING_UP) \ - _(UP) \ - _(PENDING_DOWN) \ _(DOWN) \ - _(ERROR) \ + _(UP) \ _(N) -#define MAXSZ_FACE_STATE_ 12 + +#define MAXSZ_FACE_STATE_ 9 #define MAXSZ_FACE_STATE MAXSZ_FACE_STATE_ + 1 typedef enum { @@ -116,49 +139,49 @@ foreach_face_type extern const char * face_type_str[]; -#define MAXSZ_FACE_ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_IP_ADDRESS + 2 * MAXSZ_PORT + 9 +#ifdef WITH_POLICY +#define MAXSZ_FACE_ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_URL_ + 2 * MAXSZ_FACE_STATE_ + MAXSZ_POLICY_TAGS_ + 7 +#else +#define MAXSZ_FACE_ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_URL_ + 2 * MAXSZ_FACE_STATE_ + 4 +#endif /* WITH_POLICY */ #define MAXSZ_FACE MAXSZ_FACE_ + 1 /* Face */ -typedef union { - int family; /* To access family independently of face type */ - struct { - int family; - netdevice_t netdevice; - ip_address_t local_addr; - ip_address_t remote_addr; - } hicn; - struct { - int family; - ip_address_t local_addr; - u16 local_port; - ip_address_t remote_addr; - u16 remote_port; - } tunnel; -} face_params_t; - typedef struct { face_type_t type; - face_params_t params; face_state_t admin_state; face_state_t state; #ifdef WITH_POLICY policy_tags_t tags; /**< \see policy_tag_t */ #endif /* WITH_POLICY */ + + /* + * Depending on the face type, some of the following fields will be unused + */ + netdevice_t netdevice; + int family; /* To access family independently of face type */ + ip_address_t local_addr; + ip_address_t remote_addr; + u16 local_port; + u16 remote_port; } face_t; int face_initialize(face_t * face); -int face_initialize_udp(face_t * face, const ip_address_t * local_addr, - u16 local_port, const ip_address_t * remote_addr, u16 remote_port, +int face_initialize_udp(face_t * face, const char * interface_name, + const ip_address_t * local_addr, u16 local_port, + const ip_address_t * remote_addr, u16 remote_port, int family); int face_initialize_udp_sa(face_t * face, + const char * interface_name, const struct sockaddr * local_addr, const struct sockaddr * remote_addr); face_t * face_create(); -face_t * face_create_udp(const ip_address_t * local_addr, u16 local_port, +face_t * face_create_udp(const char * interface_name, + const ip_address_t * local_addr, u16 local_port, const ip_address_t * remote_addr, u16 remote_port, int family); -face_t * face_create_udp_sa(const struct sockaddr * local_addr, +face_t * face_create_udp_sa(const char * interface_name, + const struct sockaddr * local_addr, const struct sockaddr * remote_addr); int face_finalize(face_t * face); @@ -173,6 +196,7 @@ hash_t face_hash(const face_t * face); size_t face_snprintf(char * s, size_t size, const face_t * face); +policy_tags_t face_get_tags(const face_t * face); int face_set_tags(face_t * face, policy_tags_t tags); #endif /* HICN_FACE_H */ |