summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2020-09-18 17:39:03 +0200
committerMauro Sardara <msardara@cisco.com>2020-09-18 17:41:14 +0200
commit20a773677230374ffa2d5d140f7d46032fb7bc9d (patch)
tree972ba743c7b1cfbbabd38024215af670d4dc2e3c /lib
parent22738e6177e9e1348e5a9c23c5a71e1d1ef7246f (diff)
Revert to [HICN-638] Check if systemd is running before enabling hicn-light service
Signed-off-by: Mauro Sardara <msardara@cisco.com> Change-Id: I1810d96e001a4e6e097e1efa331b682af750925d
Diffstat (limited to 'lib')
-rw-r--r--lib/includes/hicn/common.h1
-rw-r--r--lib/includes/hicn/name.h82
-rw-r--r--lib/includes/hicn/ops.h14
-rw-r--r--lib/src/CMakeLists.txt4
-rw-r--r--lib/src/compat.c5
-rw-r--r--lib/src/name.c435
-rw-r--r--lib/src/ops.c1
-rw-r--r--lib/src/protocol/ah.c3
-rw-r--r--lib/src/protocol/icmp.c1
-rw-r--r--lib/src/protocol/ipv4.c30
-rw-r--r--lib/src/protocol/ipv6.c30
-rw-r--r--lib/src/protocol/tcp.c7
12 files changed, 487 insertions, 126 deletions
diff --git a/lib/includes/hicn/common.h b/lib/includes/hicn/common.h
index 3385b4d19..30f370241 100644
--- a/lib/includes/hicn/common.h
+++ b/lib/includes/hicn/common.h
@@ -154,7 +154,6 @@ struct iovec
typedef union
{
- u8 as_u8[4];
u32 as_u32;
struct in_addr as_inaddr;
} ip4_address_t;
diff --git a/lib/includes/hicn/name.h b/lib/includes/hicn/name.h
index 9cee0bc1d..d5202068b 100644
--- a/lib/includes/hicn/name.h
+++ b/lib/includes/hicn/name.h
@@ -62,18 +62,81 @@ typedef union
{
struct
{
- ip46_address_t prefix;
+ union
+ {
+ u32 prefix;
+ u8 prefix_as_u8[4];
+ ip4_address_t prefix_as_ip4;
+ };
+ hicn_name_suffix_t suffix;
+ };
+ u8 buffer[HICN_V4_NAME_LEN];
+} hicn_v4_name_t;
+
+typedef union
+{
+ struct
+ {
+ union
+ {
+ u64 prefix[2];
+ u8 prefix_as_u8[16];
+ ip6_address_t prefix_as_ip6;
+ };
hicn_name_suffix_t suffix;
};
u8 buffer[HICN_V6_NAME_LEN];
-} hicn_name_t;
+} hicn_v6_name_t;
+
+#ifndef HICN_VPP_PLUGIN
+#define HICN_NAME_COMPONENT_SIZE 2
+
+typedef struct
+{
+ struct iovec buffers[HICN_NAME_COMPONENT_SIZE];
+} hicn_iov_name_t;
+
+#define UNSPEC 1 << 0
+#define HNT_CONTIGUOUS 1 << 1
+#define HNT_IOV 1 << 2
+#define HNT_INET 1 << 3
+#define HNT_INET6 1 << 4
-always_inline
-int hicn_name_is_ip4 (const hicn_name_t * name)
+typedef enum
{
- const ip46_address_t *ip46 = &name->prefix;
- return (((ip46)->pad[0] | (ip46)->pad[1] | (ip46)->pad[2]) == 0);
-}
+ HNT_UNSPEC = UNSPEC,
+ HNT_CONTIGUOUS_V4 = HNT_CONTIGUOUS | HNT_INET,
+ HNT_CONTIGUOUS_V6 = HNT_CONTIGUOUS | HNT_INET6,
+ HNT_IOV_V4 = HNT_IOV | HNT_INET,
+ HNT_IOV_V6 = HNT_IOV | HNT_INET6,
+} hicn_name_type_t;
+#endif /* HICN_VPP_PLUGIN */
+
+typedef struct
+{
+#ifndef HICN_VPP_PLUGIN
+ hicn_name_type_t type;
+ u8 len;
+#endif /* HICN_VPP_PLUGIN */
+ union
+ {
+ hicn_v4_name_t ip4;
+ hicn_v6_name_t ip6;
+ ip46_address_t ip46;
+#ifndef HICN_VPP_PLUGIN
+ hicn_iov_name_t iov;
+ u8 buffer[HICN_V6_NAME_LEN];
+#endif /* HICN_VPP_PLUGIN */
+ };
+} hicn_name_t;
+
+#ifndef HICN_VPP_PLUGIN
+#define _is_unspec(name) ((name->type & UNSPEC))
+#define _is_contiguous(name) ((name->type & HNT_CONTIGUOUS) >> 1)
+#define _is_iov(name) ((name->type & HNT_IOV) >> 2)
+#define _is_inet4(name) ((name->type & HNT_INET) >> 3)
+#define _is_inet6(name) ((name->type & HNT_INET6) >> 4)
+#endif /* HICN_VPP_PLUGIN */
/**
* @brief Create an hICN name from IP address in presentation format
@@ -129,10 +192,7 @@ 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)
-{
- return ((name->prefix.ip6.as_u64[0] | name->prefix.ip6.as_u64[1] | (u64)name->suffix) == 0);
-}
+int hicn_name_empty (hicn_name_t * name);
/**
* @brief Copy an hICN name
diff --git a/lib/includes/hicn/ops.h b/lib/includes/hicn/ops.h
index bcb73171e..e8feff92d 100644
--- a/lib/includes/hicn/ops.h
+++ b/lib/includes/hicn/ops.h
@@ -122,16 +122,6 @@ typedef struct hicn_ops_s
int (*mark_packet_as_data) (hicn_type_t type, hicn_protocol_t * h);
/**
- * @brief Check if currentpacket is interest
- * @param [in] type - hICN packet type
- * @param [in,out] h - Buffer holding the Interest packet
- * @param [out] ret - Return 1 if interest
- * @return hICN error code
- */
- int (*test_packet_is_interest) (hicn_type_t type, hicn_protocol_t * h,
- u8 *ret);
-
- /**
* @brief Clear the necessary Interest fields in order to hash it
* @param [in] type - hICN packet type
* @param [in,out] h - Buffer holding the Interest packet
@@ -466,7 +456,6 @@ typedef struct hicn_ops_s
ATTR_INIT(set_interest_name_suffix, protocol ## _set_interest_name_suffix), \
ATTR_INIT(mark_packet_as_interest, protocol ## _mark_packet_as_interest), \
ATTR_INIT(mark_packet_as_data, protocol ## _mark_packet_as_data), \
- ATTR_INIT(test_packet_is_interest, protocol ## _test_packet_is_interest), \
ATTR_INIT(reset_interest_for_hash, protocol ## _reset_interest_for_hash), \
ATTR_INIT(get_data_locator, protocol ## _get_data_locator), \
ATTR_INIT(set_data_locator, protocol ## _set_data_locator), \
@@ -572,9 +561,6 @@ PAYLOAD (hicn_type_t type, const hicn_protocol_t * h)
#define DECLARE_mark_packet_as_data(protocol, error) \
int protocol ## _mark_packet_as_data(hicn_type_t type, hicn_protocol_t * h) { return HICN_LIB_ERROR_ ## error ; }
-#define DECLARE_test_packet_is_interest(protocol, error) \
- int protocol ## _test_packet_is_interest(hicn_type_t type, hicn_protocol_t * h, u8 *ret) { return HICN_LIB_ERROR_ ## error ; }
-
#define DECLARE_reset_interest_for_hash(protocol, error) \
int protocol ## _reset_interest_for_hash(hicn_type_t type, hicn_protocol_t * h) { return HICN_LIB_ERROR_ ## error ; }
diff --git a/lib/src/CMakeLists.txt b/lib/src/CMakeLists.txt
index 49b735f51..7eecaf775 100644
--- a/lib/src/CMakeLists.txt
+++ b/lib/src/CMakeLists.txt
@@ -42,7 +42,7 @@ if (DISABLE_SHARED_LIBRARIES)
COMPONENT lib${LIBHICN}
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../includes
DEFINITIONS ${COMPILER_DEFINITIONS}
- HEADER_ROOT_DIR hicn
+ INSTALL_ROOT_DIR hicn
INSTALL_HEADERS ${LIBHICN_HEADER_FILES} ${LIBHICN_HEADER_FILES_PROTOCOL} ${LIBHICN_HEADER_FILES_UTIL}
LINK_LIBRARIES ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
)
@@ -53,7 +53,7 @@ else ()
COMPONENT lib${LIBHICN}
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../includes
DEFINITIONS ${COMPILER_DEFINITIONS}
- HEADER_ROOT_DIR hicn
+ INSTALL_ROOT_DIR hicn
INSTALL_HEADERS ${LIBHICN_HEADER_FILES} ${LIBHICN_HEADER_FILES_PROTOCOL} ${LIBHICN_HEADER_FILES_UTIL}
LINK_LIBRARIES ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
)
diff --git a/lib/src/compat.c b/lib/src/compat.c
index db2f40e37..615175e3b 100644
--- a/lib/src/compat.c
+++ b/lib/src/compat.c
@@ -255,6 +255,11 @@ hicn_packet_set_name (hicn_format_t format, hicn_header_t * h,
{
hicn_type_t type = hicn_format_to_type (format);
+#ifndef HICN_VPP_PLUGIN
+ if (name->type & HNT_IOV)
+ return HICN_LIB_ERROR_NOT_IMPLEMENTED;
+#endif /* HICN_VPP_PLUGIN */
+
if (is_interest)
return hicn_ops_vft[type.l1]->set_interest_name (type, &h->protocol,
name);
diff --git a/lib/src/name.c b/lib/src/name.c
index 1aa54ad40..9388c35e7 100644
--- a/lib/src/name.c
+++ b/lib/src/name.c
@@ -30,32 +30,72 @@
#include <hicn/error.h>
#include <hicn/name.h>
+#if ! HICN_VPP_PLUGIN
int
hicn_name_create (const char *ip_address, u32 id, hicn_name_t * name)
{
int af, rc;
- u8 *dst;
af = get_addr_family (ip_address);
switch (af)
{
case AF_INET:
- dst = (u8*)(&name->prefix.ip4);
+ if (name->type == HNT_UNSPEC)
+ {
+ name->type = HNT_CONTIGUOUS_V4;
+ }
+ name->len = IPV4_ADDR_LEN;
break;
case AF_INET6:
- dst = (u8*)(&name->prefix.ip6.as_u8);
+ if (name->type == HNT_UNSPEC)
+ {
+ name->type = HNT_CONTIGUOUS_V6;
+ }
+ name->len = IPV6_ADDR_LEN;
break;
default:
return HICN_LIB_ERROR_INVALID_IP_ADDRESS;
}
- rc = inet_pton (af, ip_address, dst);
+ if ((name->type != HNT_CONTIGUOUS_V4) && (name->type != HNT_CONTIGUOUS_V6))
+ {
+ return HICN_LIB_ERROR_NOT_IMPLEMENTED;
+ }
+
+ rc = inet_pton (af, ip_address, name->buffer);
if (rc <= 0)
{
return HICN_LIB_ERROR_UNKNOWN_ADDRESS;
}
- name->suffix = id;
+ *(u32 *) (name->buffer + name->len) = id;
+
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+hicn_name_create_from_ip_prefix (const ip_prefix_t * prefix, u32 id,
+ hicn_name_t * name)
+{
+ switch (prefix->family)
+ {
+ case AF_INET:
+ name->type = HNT_CONTIGUOUS_V4;
+ memcpy (name->buffer, prefix->address.v4.buffer,
+ ip_address_len(prefix->family));
+ name->len = IPV4_ADDR_LEN;
+ break;
+ case AF_INET6:
+ name->type = HNT_CONTIGUOUS_V6;
+ memcpy (name->buffer, prefix->address.v6.buffer,
+ ip_address_len(prefix->family));
+ name->len = IPV6_ADDR_LEN;
+ break;
+ default:
+ return HICN_LIB_ERROR_INVALID_IP_ADDRESS;
+ }
+
+ *(u32 *) (name->buffer + name->len) = id;
return HICN_LIB_ERROR_NONE;
}
@@ -63,25 +103,170 @@ hicn_name_create (const char *ip_address, u32 id, hicn_name_t * name)
u8
hicn_name_get_length (const hicn_name_t * name)
{
- return hicn_name_is_ip4(name) ? HICN_V4_NAME_LEN : HICN_V4_NAME_LEN;
+ return name->len;
}
-#if ! HICN_VPP_PLUGIN
+int
+hicn_name_compare (const hicn_name_t * name_1, const hicn_name_t * name_2,
+ bool consider_segment)
+{
+ hicn_name_t *name1 = (hicn_name_t *) name_1;
+ hicn_name_t *name2 = (hicn_name_t *) name_2;
+
+ if ((name1->type == HNT_CONTIGUOUS_V4 && name2->type == HNT_CONTIGUOUS_V6)
+ || (name1->type == HNT_CONTIGUOUS_V6
+ && name2->type == HNT_CONTIGUOUS_V4))
+ {
+ return -1;
+ }
+
+ if ((name1->type == HNT_IOV_V4 && name2->type == HNT_IOV_V6) ||
+ (name1->type == HNT_IOV_V6 && name2->type == HNT_IOV_V4))
+ {
+ return -1;
+ }
+
+ if ((name1->type == HNT_IOV_V4 && name2->type == HNT_CONTIGUOUS_V6) ||
+ (name1->type == HNT_IOV_V6 && name2->type == HNT_CONTIGUOUS_V4))
+ {
+ return -1;
+ }
+
+ if (name1->type == HNT_UNSPEC || name2->type == HNT_UNSPEC)
+ {
+ return -1;
+ }
+
+ size_t len1 = 0, len2 = 0;
+
+ u8 *buffer11, *buffer12, *buffer21, *buffer22;
+
+ switch (name1->type)
+ {
+ case HNT_CONTIGUOUS_V4:
+ buffer11 = name1->buffer;
+ buffer12 = name1->buffer + IPV4_ADDR_LEN;
+ len1 = IPV4_ADDR_LEN;
+ break;
+ case HNT_CONTIGUOUS_V6:
+ buffer11 = name1->buffer;
+ buffer12 = name1->buffer + IPV6_ADDR_LEN;
+ len1 = IPV6_ADDR_LEN;
+ break;
+ case HNT_IOV_V4:
+ buffer11 = name1->iov.buffers[0].iov_base;
+ buffer12 = name1->iov.buffers[1].iov_base;
+ len1 = IPV4_ADDR_LEN;
+ break;
+ case HNT_IOV_V6:
+ buffer11 = name1->iov.buffers[0].iov_base;
+ buffer12 = name1->iov.buffers[1].iov_base;
+ len1 = IPV6_ADDR_LEN;
+ break;
+ default:
+ return HICN_LIB_ERROR_NOT_IMPLEMENTED;
+ }
+
+ switch (name2->type)
+ {
+ case HNT_CONTIGUOUS_V4:
+ buffer21 = name2->buffer;
+ buffer22 = name2->buffer + IPV4_ADDR_LEN;
+ len2 = IPV4_ADDR_LEN;
+ break;
+ case HNT_CONTIGUOUS_V6:
+ buffer21 = name2->buffer;
+ buffer22 = name2->buffer + IPV6_ADDR_LEN;
+ len2 = IPV6_ADDR_LEN;
+ break;
+ case HNT_IOV_V4:
+ buffer21 = name2->iov.buffers[0].iov_base;
+ buffer22 = name2->iov.buffers[1].iov_base;
+ len2 = IPV4_ADDR_LEN;
+ break;
+ case HNT_IOV_V6:
+ buffer21 = name2->iov.buffers[0].iov_base;
+ buffer22 = name2->iov.buffers[1].iov_base;
+ len2 = IPV6_ADDR_LEN;
+ break;
+ default:
+ return HICN_LIB_ERROR_NOT_IMPLEMENTED;
+ }
+
+ // Sanity check
+ if (len1 != len2)
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
+ int ret1 = memcmp ((u8 *) buffer11, (u8 *) buffer21, len1);
+
+ if (!consider_segment)
+ {
+ return ret1;
+ }
+
+ int ret2 = memcmp ((u8 *) buffer12, (u8 *) buffer22, HICN_SEGMENT_LEN);
+
+ return ret1 || ret2;
+}
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);
+ switch (name->type)
+ {
+ case HNT_CONTIGUOUS_V4:
+ *hash = hash32 (name->buffer, consider_suffix ? HICN_V4_NAME_LEN : HICN_V4_PREFIX_LEN);
+ break;
+ case HNT_CONTIGUOUS_V6:
+ *hash = hash32 (name->buffer, consider_suffix ? HICN_V6_NAME_LEN : HICN_V6_PREFIX_LEN);
+ break;
+ case HNT_IOV_V4:
+ case HNT_IOV_V6:
+ *hash =
+ hash32 (name->iov.buffers[0].iov_base, name->iov.buffers[0].iov_len);
+ if (consider_suffix)
+ {
+ *hash = cumulative_hash32 (name->iov.buffers[1].iov_base,
+ name->iov.buffers[1].iov_len, *hash);
+ }
+ break;
+ default:
+ return HICN_LIB_ERROR_NOT_IMPLEMENTED;
+ }
+
return HICN_LIB_ERROR_NONE;
}
-#endif /* ! HICN_VPP_PLUGIN */
+int
+hicn_name_empty (hicn_name_t * name)
+{
+ return name->type == HNT_UNSPEC ? HICN_LIB_ERROR_NONE : 1;
+}
int
hicn_name_copy (hicn_name_t * dst, const hicn_name_t * src)
{
- memcpy (dst, src, sizeof(*dst));
+ switch (src->type)
+ {
+ case HNT_CONTIGUOUS_V4:
+ case HNT_CONTIGUOUS_V6:
+ *dst = *src;
+ break;
+ case HNT_IOV_V4:
+ case HNT_IOV_V6:
+ dst->type =
+ src->type == HNT_IOV_V4 ? HNT_CONTIGUOUS_V4 : HNT_CONTIGUOUS_V6;
+ memcpy (dst->buffer, src->iov.buffers[0].iov_base,
+ src->iov.buffers[0].iov_len);
+ memcpy (dst->buffer + src->iov.buffers[0].iov_len,
+ src->iov.buffers[1].iov_base, src->iov.buffers[1].iov_len);
+ break;
+ default:
+ return HICN_LIB_ERROR_NOT_IMPLEMENTED;
+ }
+
return HICN_LIB_ERROR_NONE;
}
@@ -89,18 +274,78 @@ int
hicn_name_copy_to_destination (u8 * dst, const hicn_name_t * src,
bool copy_suffix)
{
- u8 is_ip4 = hicn_name_is_ip4(src);
- size_t size = is_ip4 * IPV4_ADDR_LEN + (1 - is_ip4) * IPV6_ADDR_LEN;
- size += (u8)copy_suffix * sizeof (hicn_name_suffix_t);
- void *_src = (void *)(is_ip4 * (u64)(&src->prefix.ip4) + (1 - is_ip4) * (u64)(&src->prefix.ip6));
- memcpy (dst, _src, size);
+ size_t length;
+
+ switch (src->type)
+ {
+ case HNT_CONTIGUOUS_V4:
+ if (copy_suffix)
+ {
+ length = HICN_V4_NAME_LEN;
+ }
+ else
+ {
+ length = IPV4_ADDR_LEN;
+ }
+ memcpy (dst, src->buffer, length);
+ break;
+ case HNT_CONTIGUOUS_V6:
+ if (copy_suffix)
+ {
+ length = HICN_V6_NAME_LEN;
+ }
+ else
+ {
+ length = IPV6_ADDR_LEN;
+ }
+ memcpy (dst, src->buffer, length);
+ break;
+ case HNT_IOV_V4:
+ case HNT_IOV_V6:
+ memcpy (dst, src->iov.buffers[0].iov_base, src->iov.buffers[0].iov_len);
+ if (copy_suffix)
+ {
+ memcpy (dst + src->iov.buffers[0].iov_len,
+ src->iov.buffers[1].iov_base, src->iov.buffers[1].iov_len);
+ }
+ break;
+ default:
+ return HICN_LIB_ERROR_NOT_IMPLEMENTED;
+ }
+
return HICN_LIB_ERROR_NONE;
}
int
hicn_name_set_seq_number (hicn_name_t * name, u32 seq_number)
{
- name->suffix = seq_number;
+ u8 *sequence_number = NULL;
+
+ switch (name->type)
+ {
+ case HNT_CONTIGUOUS_V6:
+ sequence_number = name->buffer + IPV6_ADDR_LEN;
+ break;
+ case HNT_CONTIGUOUS_V4:
+ sequence_number = name->buffer + IPV4_ADDR_LEN;
+ break;
+ case HNT_IOV_V6:
+ case HNT_IOV_V4:
+ sequence_number = name->iov.buffers[1].iov_base;
+ break;
+ case HNT_UNSPEC:
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
+ if (sequence_number)
+ {
+ *(u32 *) sequence_number = seq_number;
+ }
+ else
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
return HICN_LIB_ERROR_NONE;
}
@@ -111,20 +356,34 @@ hicn_name_to_sockaddr_address (const hicn_name_t * name,
struct sockaddr_in6 *tmp6 = (struct sockaddr_in6 *) ip_address;
struct sockaddr_in *tmp4 = (struct sockaddr_in *) ip_address;
- u8 is_ip4 = hicn_name_is_ip4 (name);
- ip_address->sa_family = AF_INET * is_ip4 + AF_INET6 * (1 - is_ip4);
-
- if (is_ip4)
- {
- tmp4->sin_family = AF_INET;
- tmp4->sin_port = DUMMY_PORT;
- memcpy (&tmp4->sin_addr, name->prefix.ip4.as_u8, IPV4_ADDR_LEN);
- }
- else
+ switch (name->type)
{
+ case HNT_CONTIGUOUS_V6:
+ tmp6->sin6_family = AF_INET6;
+ tmp6->sin6_scope_id = 0;
+ tmp6->sin6_port = DUMMY_PORT;
+ memcpy (&tmp6->sin6_addr, name->buffer, IPV6_ADDR_LEN);
+ break;
+ case HNT_IOV_V6:
tmp6->sin6_family = AF_INET6;
+ tmp6->sin6_scope_id = 0;
tmp6->sin6_port = DUMMY_PORT;
- memcpy (&tmp6->sin6_addr, name->prefix.ip6.as_u8, IPV6_ADDR_LEN);
+ memcpy (&tmp6->sin6_addr, name->iov.buffers[0].iov_base,
+ name->iov.buffers[0].iov_len);
+ break;
+ case HNT_CONTIGUOUS_V4:
+ tmp4->sin_family = AF_INET;
+ tmp4->sin_port = DUMMY_PORT;
+ memcpy (&tmp4->sin_addr, name->buffer, IPV4_ADDR_LEN);
+ break;
+ case HNT_IOV_V4:
+ tmp4->sin_family = AF_INET;
+ tmp4->sin_port = DUMMY_PORT;
+ memcpy (&tmp4->sin_addr, name->iov.buffers[0].iov_base,
+ name->iov.buffers[0].iov_len);
+ break;
+ default:
+ return HICN_LIB_ERROR_UNEXPECTED;
}
return HICN_LIB_ERROR_NONE;
@@ -133,14 +392,63 @@ hicn_name_to_sockaddr_address (const hicn_name_t * name,
int
hicn_name_to_ip_prefix (const hicn_name_t * name, ip_prefix_t * prefix)
{
- memcpy (prefix, &name->prefix, sizeof(*prefix));
+ switch (name->type)
+ {
+ case HNT_CONTIGUOUS_V6:
+ memcpy (&prefix->address.v6.buffer, name->buffer, IPV6_ADDR_LEN);
+ prefix->family = AF_INET6;
+ break;
+ case HNT_IOV_V6:
+ memcpy (&prefix->address.v6.buffer, name->iov.buffers[0].iov_base,
+ name->iov.buffers[0].iov_len);
+ prefix->family = AF_INET6;
+ break;
+ case HNT_CONTIGUOUS_V4:
+ memcpy (&prefix->address.v4.buffer, name->buffer, IPV4_ADDR_LEN);
+ prefix->family = AF_INET;
+ break;
+ case HNT_IOV_V4:
+ memcpy (&prefix->address.v4.buffer, name->iov.buffers[0].iov_base,
+ name->iov.buffers[0].iov_len);
+ prefix->family = AF_INET;
+ break;
+ default:
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
return HICN_LIB_ERROR_NONE;
}
int
hicn_name_get_seq_number (const hicn_name_t * name, u32 * seq_number)
{
- *seq_number = name->suffix;
+ const u8 *sequence_number = NULL;
+
+ switch (name->type)
+ {
+ case HNT_CONTIGUOUS_V6:
+ sequence_number = name->buffer + IPV6_ADDR_LEN;
+ break;
+ case HNT_CONTIGUOUS_V4:
+ sequence_number = name->buffer + IPV4_ADDR_LEN;
+ break;
+ case HNT_IOV_V6:
+ case HNT_IOV_V4:
+ sequence_number = name->iov.buffers[1].iov_base;
+ break;
+ default:
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
+ if (sequence_number)
+ {
+ *seq_number = *(u32 *) sequence_number;
+ }
+ else
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
return HICN_LIB_ERROR_NONE;
}
@@ -149,12 +457,29 @@ hicn_name_ntop (const hicn_name_t * src, char *dst, size_t len)
{
int offset;
const char *rc;
- u8 is_ip4 = hicn_name_is_ip4 (src);
+ void *seg_number = NULL;
- if (is_ip4)
- rc = inet_ntop (AF_INET, (struct in_addr*)(src->prefix.ip4.as_u8), dst, (socklen_t)len);
- else
- rc = inet_ntop (AF_INET6, (struct in6_addr*)(src->prefix.ip6.as_u8), dst, (socklen_t)len);
+ switch (src->type)
+ {
+ case HNT_CONTIGUOUS_V6:
+ rc = inet_ntop (AF_INET6, src->buffer, dst, (socklen_t)len);
+ seg_number = (u8 *) src->buffer + IPV6_ADDR_LEN;
+ break;
+ case HNT_CONTIGUOUS_V4:
+ rc = inet_ntop (AF_INET, src->buffer, dst, (socklen_t)len);
+ seg_number = (u8 *) src->buffer + IPV4_ADDR_LEN;
+ break;
+ case HNT_IOV_V6:
+ rc = inet_ntop (AF_INET6, src->iov.buffers[0].iov_base, dst, (socklen_t)len);
+ seg_number = src->iov.buffers[1].iov_base;
+ break;
+ case HNT_IOV_V4:
+ rc = inet_ntop (AF_INET, src->iov.buffers[0].iov_base, dst, (socklen_t)len);
+ seg_number = src->iov.buffers[1].iov_base;
+ break;
+ default:
+ return HICN_LIB_ERROR_NOT_IMPLEMENTED;
+ }
if (!rc)
{
@@ -164,7 +489,8 @@ hicn_name_ntop (const hicn_name_t * src, char *dst, size_t len)
offset = (int) strlen (dst);
dst[offset] = '|';
- sprintf (dst + offset + 1, "%lu", (unsigned long) src->suffix);
+ sprintf (dst + offset + 1, "%lu", (unsigned long) (*(u32 *) seg_number));
+
return HICN_LIB_ERROR_NONE;
ERR:
@@ -180,8 +506,19 @@ hicn_name_pton (const char *src, hicn_name_t * dst)
int
hicn_name_get_family (const hicn_name_t * name, int *family)
{
- u8 is_ip4 = hicn_name_is_ip4 (name);
- *family = AF_INET * is_ip4 + (1 - is_ip4) * AF_INET6;
+ switch (name->type)
+ {
+ case HNT_CONTIGUOUS_V6:
+ case HNT_IOV_V6:
+ *family = AF_INET6;
+ break;
+ case HNT_CONTIGUOUS_V4:
+ case HNT_IOV_V4:
+ *family = AF_INET;
+ break;
+ default:
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
return HICN_LIB_ERROR_NONE;
}
@@ -202,32 +539,12 @@ hicn_prefix_create_from_ip_prefix (const ip_prefix_t * ip_prefix,
default:
return HICN_LIB_ERROR_INVALID_IP_ADDRESS;
}
-
prefix->len = (u8) (ip_prefix->len);
return HICN_LIB_ERROR_NONE;
}
-int
-hicn_name_create_from_ip_prefix (const ip_prefix_t * prefix, u32 id,
- hicn_name_t * name)
-{
- int i;
-
- for (i = 0; i < 2; i++)
- name->prefix.ip6.as_u64[i] = prefix->address.v6.as_u64[i];
- name->suffix = id;
-
- return HICN_LIB_ERROR_NONE;
-}
-
-int
-hicn_name_compare (const hicn_name_t * name_1, const hicn_name_t * name_2,
- bool consider_segment)
-{
- size_t size = (u8)consider_segment * sizeof(hicn_name_suffix_t) + IPV6_ADDR_LEN;
- return memcmp (name_1, name_2, size);
-}
+#endif /* ! HICN_VPP_PLUGIN */
/*
diff --git a/lib/src/ops.c b/lib/src/ops.c
index 919567721..d49138398 100644
--- a/lib/src/ops.c
+++ b/lib/src/ops.c
@@ -42,7 +42,6 @@ DECLARE_get_interest_name_suffix (none, NONE);
DECLARE_set_interest_name_suffix (none, NONE);
DECLARE_mark_packet_as_interest (none, NONE);
DECLARE_mark_packet_as_data (none, NONE);
-DECLARE_test_packet_is_interest (none, NONE);
DECLARE_reset_interest_for_hash (none, NONE);
DECLARE_get_data_locator (none, NONE);
DECLARE_set_data_locator (none, NONE);
diff --git a/lib/src/protocol/ah.c b/lib/src/protocol/ah.c
index 6f143238a..da08d1ee8 100644
--- a/lib/src/protocol/ah.c
+++ b/lib/src/protocol/ah.c
@@ -32,8 +32,7 @@ DECLARE_set_interest_name (ah, UNEXPECTED);
DECLARE_get_interest_name_suffix (ah, UNEXPECTED);
DECLARE_set_interest_name_suffix (ah, UNEXPECTED);
DECLARE_mark_packet_as_interest (ah, UNEXPECTED)
-DECLARE_mark_packet_as_data (ah, UNEXPECTED);
-DECLARE_test_packet_is_interest (ah, UNEXPECTED);
+DECLARE_mark_packet_as_data (ah, UNEXPECTED)
DECLARE_get_data_locator (ah, UNEXPECTED);
DECLARE_set_data_locator (ah, UNEXPECTED);
DECLARE_get_data_name (ah, UNEXPECTED);
diff --git a/lib/src/protocol/icmp.c b/lib/src/protocol/icmp.c
index 40a93b099..b24c0f11e 100644
--- a/lib/src/protocol/icmp.c
+++ b/lib/src/protocol/icmp.c
@@ -27,7 +27,6 @@ DECLARE_get_interest_name_suffix (icmp, UNEXPECTED)
DECLARE_set_interest_name_suffix (icmp, UNEXPECTED)
DECLARE_mark_packet_as_interest (icmp, UNEXPECTED)
DECLARE_mark_packet_as_data (icmp, UNEXPECTED)
-DECLARE_test_packet_is_interest (icmp, UNEXPECTED)
DECLARE_get_data_locator (icmp, UNEXPECTED)
DECLARE_set_data_locator (icmp, UNEXPECTED)
DECLARE_get_data_name (icmp, UNEXPECTED)
diff --git a/lib/src/protocol/ipv4.c b/lib/src/protocol/ipv4.c
index 4bab9980b..781907231 100644
--- a/lib/src/protocol/ipv4.c
+++ b/lib/src/protocol/ipv4.c
@@ -78,16 +78,20 @@ int
ipv4_get_interest_name (hicn_type_t type, const hicn_protocol_t * h,
hicn_name_t * name)
{
- name->prefix.ip4.as_u32 = h->ipv4.daddr.as_u32;
- return CHILD_OPS (get_interest_name_suffix, type, h, &(name->suffix));
+ name->ip4.prefix_as_ip4 = h->ipv4.daddr;
+#ifndef HICN_VPP_PLUGIN
+ name->type = HNT_CONTIGUOUS_V4;
+ name->len = HICN_V4_NAME_LEN;
+#endif /* HICN_VPP_PLUGIN */
+ return CHILD_OPS (get_interest_name_suffix, type, h, &(name->ip4.suffix));
}
int
ipv4_set_interest_name (hicn_type_t type, hicn_protocol_t * h,
const hicn_name_t * name)
{
- h->ipv4.daddr.as_u32 = name->prefix.ip4.as_u32;
- return CHILD_OPS (set_interest_name_suffix, type, h, &(name->suffix));
+ h->ipv4.daddr = name->ip4.prefix_as_ip4;
+ return CHILD_OPS (set_interest_name_suffix, type, h, &(name->ip4.suffix));
}
int
@@ -117,12 +121,6 @@ ipv4_mark_packet_as_data (hicn_type_t type, hicn_protocol_t * h)
}
int
-ipv4_test_packet_is_interest (hicn_type_t type, hicn_protocol_t * h, u8 *ret)
-{
- return CHILD_OPS (test_packet_is_interest, type, h, ret);
-}
-
-int
ipv4_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t * h)
{
/* Sets everything to 0 up to IP destination address */
@@ -151,16 +149,20 @@ int
ipv4_get_data_name (hicn_type_t type, const hicn_protocol_t * h,
hicn_name_t * name)
{
- name->prefix.ip4.as_u32 = h->ipv4.saddr.as_u32;
- return CHILD_OPS (get_data_name_suffix, type, h, &(name->suffix));
+ name->ip4.prefix_as_ip4 = h->ipv4.saddr;
+#ifndef HICN_VPP_PLUGIN
+ name->type = HNT_CONTIGUOUS_V4;
+ name->len = HICN_V4_NAME_LEN;
+#endif /* HICN_VPP_PLUGIN */
+ return CHILD_OPS (get_data_name_suffix, type, h, &(name->ip4.suffix));
}
int
ipv4_set_data_name (hicn_type_t type, hicn_protocol_t * h,
const hicn_name_t * name)
{
- h->ipv4.saddr.as_u32 = name->prefix.ip4.as_u32;
- return CHILD_OPS (set_data_name_suffix, type, h, &(name->suffix));
+ h->ipv4.saddr = name->ip4.prefix_as_ip4;
+ return CHILD_OPS (set_data_name_suffix, type, h, &(name->ip4.suffix));
}
int
diff --git a/lib/src/protocol/ipv6.c b/lib/src/protocol/ipv6.c
index b0ba3117d..f23b01cd8 100644
--- a/lib/src/protocol/ipv6.c
+++ b/lib/src/protocol/ipv6.c
@@ -68,16 +68,20 @@ int
ipv6_get_interest_name (hicn_type_t type, const hicn_protocol_t * h,
hicn_name_t * name)
{
- name->prefix.ip6 = h->ipv6.daddr;
- return CHILD_OPS (get_interest_name_suffix, type, h, &(name->suffix));
+ name->ip6.prefix_as_ip6 = h->ipv6.daddr;
+#ifndef HICN_VPP_PLUGIN
+ name->type = HNT_CONTIGUOUS_V6;
+ name->len = HICN_V6_NAME_LEN;
+#endif /* HICN_VPP_PLUGIN */
+ return CHILD_OPS (get_interest_name_suffix, type, h, &(name->ip6.suffix));
}
int
ipv6_set_interest_name (hicn_type_t type, hicn_protocol_t * h,
const hicn_name_t * name)
{
- h->ipv6.daddr = name->prefix.ip6;
- return CHILD_OPS (set_interest_name_suffix, type, h, &(name->suffix));
+ h->ipv6.daddr = name->ip6.prefix_as_ip6;
+ return CHILD_OPS (set_interest_name_suffix, type, h, &(name->ip6.suffix));
}
int
@@ -107,12 +111,6 @@ ipv6_mark_packet_as_data (hicn_type_t type, hicn_protocol_t * h)
}
int
-ipv6_test_packet_is_interest (hicn_type_t type, hicn_protocol_t * h, u8 *ret)
-{
- return CHILD_OPS (test_packet_is_interest, type, h, ret);
-}
-
-int
ipv6_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t * h)
{
/* Sets everything to 0 up to IP destination address */
@@ -141,16 +139,20 @@ int
ipv6_get_data_name (hicn_type_t type, const hicn_protocol_t * h,
hicn_name_t * name)
{
- name->prefix.ip6 = h->ipv6.saddr;
- return CHILD_OPS (get_data_name_suffix, type, h, &(name->suffix));
+ name->ip6.prefix_as_ip6 = h->ipv6.saddr;
+#ifndef HICN_VPP_PLUGIN
+ name->type = HNT_CONTIGUOUS_V6;
+ name->len = HICN_V6_NAME_LEN;
+#endif /* HICN_VPP_PLUGIN */
+ return CHILD_OPS (get_data_name_suffix, type, h, &(name->ip6.suffix));
}
int
ipv6_set_data_name (hicn_type_t type, hicn_protocol_t * h,
const hicn_name_t * name)
{
- h->ipv6.saddr = name->prefix.ip6;
- return CHILD_OPS (set_data_name_suffix, type, h, &(name->suffix));
+ h->ipv6.saddr = name->ip6.prefix_as_ip6;
+ return CHILD_OPS (set_data_name_suffix, type, h, &(name->ip6.suffix));
}
int
diff --git a/lib/src/protocol/tcp.c b/lib/src/protocol/tcp.c
index ec1eb27dc..31c495ff4 100644
--- a/lib/src/protocol/tcp.c
+++ b/lib/src/protocol/tcp.c
@@ -97,13 +97,6 @@ tcp_mark_packet_as_data (hicn_type_t type, hicn_protocol_t * h)
}
int
-tcp_test_packet_is_interest (hicn_type_t type, hicn_protocol_t * h, u8 *ret)
-{
- *ret = !(h->tcp.flags & HICN_TCP_FLAG_ECE);
- return HICN_LIB_ERROR_NONE;
-}
-
-int
tcp_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t * h)
{
memset (&(h->tcp), 0, 4);