aboutsummaryrefslogtreecommitdiffstats
path: root/lib/includes/hicn/name.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/includes/hicn/name.h')
-rw-r--r--lib/includes/hicn/name.h68
1 files changed, 39 insertions, 29 deletions
diff --git a/lib/includes/hicn/name.h b/lib/includes/hicn/name.h
index 9cee0bc1d..942c0f9db 100644
--- a/lib/includes/hicn/name.h
+++ b/lib/includes/hicn/name.h
@@ -26,21 +26,22 @@
#include <stdbool.h>
#ifndef _WIN32
-#include <netinet/in.h> // struct sockadd
+#include <netinet/in.h> // struct sockadd
#endif
#include <hicn/util/ip_address.h>
#include "common.h"
+#include "error.h"
/******************************************************************************
* hICN names
******************************************************************************/
-#define TCP_SEQNO_LEN 4 /* bytes */
+#define TCP_SEQNO_LEN 4 /* bytes */
#define HICN_V4_PREFIX_LEN IPV4_ADDR_LEN
#define HICN_V6_PREFIX_LEN IPV6_ADDR_LEN
#define HICN_SEGMENT_LEN TCP_SEQNO_LEN
-#define HICN_V6_NAME_LEN (HICN_V6_PREFIX_LEN + HICN_SEGMENT_LEN) /* 20 bytes */
-#define HICN_V4_NAME_LEN (HICN_V4_PREFIX_LEN + HICN_SEGMENT_LEN) /* 8 bytes */
+#define HICN_V6_NAME_LEN (HICN_V6_PREFIX_LEN + HICN_SEGMENT_LEN) /* 20 bytes */
+#define HICN_V4_NAME_LEN (HICN_V4_PREFIX_LEN + HICN_SEGMENT_LEN) /* 8 bytes */
/* Prefix */
@@ -68,8 +69,7 @@ typedef union
u8 buffer[HICN_V6_NAME_LEN];
} hicn_name_t;
-always_inline
-int hicn_name_is_ip4 (const hicn_name_t * name)
+always_inline int hicn_name_is_ip4(const hicn_name_t *name)
{
const ip46_address_t *ip46 = &name->prefix;
return (((ip46)->pad[0] | (ip46)->pad[1] | (ip46)->pad[2]) == 0);
@@ -82,7 +82,7 @@ int hicn_name_is_ip4 (const hicn_name_t * name)
* @param [out] Resulting hICN name
* @return hICN error code
*/
-int hicn_name_create (const char *ip_address, u32 id, hicn_name_t * name);
+int hicn_name_create(const char *ip_address, u32 id, hicn_name_t *name);
/**
* @brief Create an hICN name from IP address
@@ -91,15 +91,15 @@ int hicn_name_create (const char *ip_address, u32 id, hicn_name_t * name);
* @param [out] Resulting - hICN name
* @return hICN error code
*/
-int hicn_name_create_from_ip_prefix (const ip_prefix_t * prefix, u32 id,
- hicn_name_t * name);
+int hicn_name_create_from_ip_prefix(const ip_prefix_t *prefix, u32 id,
+ hicn_name_t *name);
/**
* @brief Returns the length of an hICN name
* @param [in] name - hICN name
* @return Name length
*/
-u8 hicn_name_get_length (const hicn_name_t * name);
+u8 hicn_name_get_length(const hicn_name_t *name);
/**
* @brief Compare two hICN names
@@ -111,8 +111,8 @@ u8 hicn_name_get_length (const hicn_name_t * name);
* found, respectively, to be lest than, to match, or be greater than name_2
* based on numeric order.
*/
-int hicn_name_compare (const hicn_name_t * name_1, const hicn_name_t * name_2,
- bool consider_segment);
+int hicn_name_compare(const hicn_name_t *name_1, const hicn_name_t *name_2,
+ bool consider_segment);
/**
* @brief Provides a 32-bit hash of an hICN name
@@ -121,7 +121,17 @@ int hicn_name_compare (const hicn_name_t * name_1, const hicn_name_t * name_2,
* @param [in] consider_suffix - Consider the suffix in the hash computation
* @return hICN error code
*/
-int hicn_name_hash (const hicn_name_t * name, u32 * hash, bool consider_suffix);
+
+#if !HICN_VPP_PLUGIN
+
+always_inline int hicn_name_hash(const hicn_name_t *name, u32 *hash, bool consider_suffix)
+{
+ size_t size = (u8)consider_suffix * sizeof(hicn_name_suffix_t) + IPV6_ADDR_LEN;
+ *hash = hash32(name->buffer, size);
+ return HICN_LIB_ERROR_NONE;
+}
+
+#endif /* ! HICN_VPP_PLUGIN */
/**
* @brief Test whether an hICN name is empty
@@ -129,9 +139,9 @@ int hicn_name_hash (const hicn_name_t * name, u32 * hash, bool consider_suffix);
* @return 0 if the name is empty, any other value otherwise (implementation
* returns 1)
*/
-always_inline int hicn_name_empty (hicn_name_t * name)
+always_inline int hicn_name_empty(hicn_name_t *name)
{
- return ((name->prefix.ip6.as_u64[0] | name->prefix.ip6.as_u64[1] | (u64)name->suffix) == 0);
+ return ((name->prefix.ip6.as_u64[0] | name->prefix.ip6.as_u64[1] | (u64)name->suffix) != 0);
}
/**
@@ -140,7 +150,7 @@ always_inline int hicn_name_empty (hicn_name_t * name)
* @param [in] src - Source name to copy
* @return hICN error code
*/
-int hicn_name_copy (hicn_name_t * dst, const hicn_name_t * src);
+int hicn_name_copy(hicn_name_t *dst, const hicn_name_t *src);
/**
* @brief Copy an hICN name to a buffer
@@ -149,8 +159,8 @@ int hicn_name_copy (hicn_name_t * dst, const hicn_name_t * src);
* @param [in] copy_suffix - Flag indicating whether the suffix has to be
* considered
*/
-int hicn_name_copy_to_destination (u8 * dst, const hicn_name_t * src,
- bool copy_suffix);
+int hicn_name_copy_to_destination(u8 *dst, const hicn_name_t *src,
+ bool copy_suffix);
/**
* @brief Sets the segment part of an hICN name
@@ -158,7 +168,7 @@ int hicn_name_copy_to_destination (u8 * dst, const hicn_name_t * src,
* @param [in] seq_number - Segment identifier
* @return hICN error code
*/
-int hicn_name_set_seq_number (hicn_name_t * name, u32 seq_number);
+int hicn_name_set_seq_number(hicn_name_t *name, u32 seq_number);
/**
* @brief Retrieves the segment part of an hICN name
@@ -166,7 +176,7 @@ int hicn_name_set_seq_number (hicn_name_t * name, u32 seq_number);
* @param [in] seq_number - Segment identifier
* @return hICN error code
*/
-int hicn_name_get_seq_number (const hicn_name_t * name, u32 * seq_number);
+int hicn_name_get_seq_number(const hicn_name_t *name, u32 *seq_number);
/**
* @brief Convert an hICN name to a socket address
@@ -174,8 +184,8 @@ int hicn_name_get_seq_number (const hicn_name_t * name, u32 * seq_number);
* @param [out] ip_address - Resulting socket address
* @return hICN error code
*/
-int hicn_name_to_sockaddr_address (const hicn_name_t * name,
- struct sockaddr *ip_address);
+int hicn_name_to_sockaddr_address(const hicn_name_t *name,
+ struct sockaddr *ip_address);
/**
* @brief Convert an hICN name to an IP address
@@ -183,8 +193,8 @@ int hicn_name_to_sockaddr_address (const hicn_name_t * name,
* @param [out] ip_address - Resulting IP address
* @return hICN error code
*/
-int hicn_name_to_ip_prefix (const hicn_name_t * name,
- ip_prefix_t * ip_prefix);
+int hicn_name_to_ip_prefix(const hicn_name_t *name,
+ ip_prefix_t *ip_prefix);
/**
* @brief Convert an hICN name to presentation format
@@ -193,7 +203,7 @@ int hicn_name_to_ip_prefix (const hicn_name_t * name,
* @param [in] len - Number of bytes available in the buffer
* @return hICN error code
*/
-int hicn_name_ntop (const hicn_name_t * src, char *dst, size_t len);
+int hicn_name_ntop(const hicn_name_t *src, char *dst, size_t len);
/**
* @brief Convert an hICN name from presentation format
@@ -201,7 +211,7 @@ int hicn_name_ntop (const hicn_name_t * src, char *dst, size_t len);
* @param [out] dst - Resulting name
* @return hICN error code
*/
-int hicn_name_pton (const char *src, hicn_name_t * dst);
+int hicn_name_pton(const char *src, hicn_name_t *dst);
/**
* @brief Returns the IP address family of an hICN name
@@ -209,7 +219,7 @@ int hicn_name_pton (const char *src, hicn_name_t * dst);
* @param [out] family - Resulting IP address family (AF_INET or AF_INET6)
* @return hICN error code
*/
-int hicn_name_get_family (const hicn_name_t * name, int *family);
+int hicn_name_get_family(const hicn_name_t *name, int *family);
/**
* @brief Creates an hICN prefix from an IP address
@@ -217,8 +227,8 @@ int hicn_name_get_family (const hicn_name_t * name, int *family);
* @param [out] prefix - Resulting prefix
* @return hICN error code
*/
-int hicn_prefix_create_from_ip_prefix (const ip_prefix_t * ip_prefix,
- hicn_prefix_t * prefix);
+int hicn_prefix_create_from_ip_prefix(const ip_prefix_t *ip_prefix,
+ hicn_prefix_t *prefix);
#endif /* HICN_NAME_H */