aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEnrico Loparco (eloparco) <eloparco@cisco.com>2021-06-24 09:15:41 +0200
committerEnrico Loparco (eloparco) <eloparco@cisco.com>2021-06-24 09:15:41 +0200
commit229385955109b866a23c4ac2aa03d4d11044c39d (patch)
tree0591f9c2fc4144d62330337cc2b94c63dfeded54 /lib
parent6ffbb5ed61733b8dbef39b1a9d437e899e9359d7 (diff)
[HICN-708] Rebase with master
Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com> Change-Id: I2122e1d61dd3b2e039972624ffbdbcb3c5610159
Diffstat (limited to 'lib')
-rw-r--r--lib/.clang-format21
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/doc/CMakeLists.txt35
-rw-r--r--lib/doc/Doxyfile.in12
-rw-r--r--lib/includes/CMakeLists.txt5
-rw-r--r--lib/includes/hicn/base.h36
-rw-r--r--lib/includes/hicn/common.h14
-rw-r--r--lib/includes/hicn/compat.h299
-rw-r--r--lib/includes/hicn/error.h21
-rw-r--r--lib/includes/hicn/face.h1
-rw-r--r--lib/includes/hicn/ops.h38
-rw-r--r--lib/includes/hicn/policy.h10
-rw-r--r--lib/includes/hicn/protocol/tcp.h14
-rw-r--r--lib/includes/hicn/strategy.h36
-rw-r--r--lib/includes/hicn/util/log.h2
-rw-r--r--lib/includes/hicn/util/windows/dlfcn.h33
-rwxr-xr-xlib/includes/hicn/util/windows/windows_utils.h8
-rw-r--r--lib/src/CMakeLists.txt9
-rw-r--r--lib/src/common.c3
-rw-r--r--lib/src/compat.c472
-rw-r--r--lib/src/name.c2
-rw-r--r--lib/src/ops.c2
-rw-r--r--lib/src/protocol/ah.c4
-rw-r--r--lib/src/protocol/icmp.c4
-rw-r--r--lib/src/protocol/ipv4.c16
-rw-r--r--lib/src/protocol/ipv6.c32
-rw-r--r--lib/src/protocol/tcp.c95
-rw-r--r--lib/src/strategy.c39
-rw-r--r--lib/src/util/ip_address.c5
-rw-r--r--lib/src/util/windows/dlfcn.c65
30 files changed, 871 insertions, 463 deletions
diff --git a/lib/.clang-format b/lib/.clang-format
new file mode 100644
index 000000000..8b5c955ce
--- /dev/null
+++ b/lib/.clang-format
@@ -0,0 +1,21 @@
+# Minimal clang-format version is 8
+
+BasedOnStyle: GNU
+UseTab: Always
+SpaceAfterCStyleCast: true
+SortIncludes: false
+AlignConsecutiveMacros: true
+BreakBeforeTernaryOperators: false
+BreakBeforeBinaryOperators: None
+ContinuationIndentWidth: 2
+
+ForEachMacros:
+ - 'clib_bitmap_foreach'
+ - 'pool_foreach'
+ - 'pool_foreach_index'
+ - 'vec_foreach'
+ - 'vec_foreach_backwards'
+ - 'vec_foreach_index'
+ - 'vec_foreach_index_backwards'
+ - 'vlib_foreach_rx_tx'
+
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 3cc40bb7f..0512b7c64 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -48,5 +48,4 @@ endif ()
add_subdirectory(includes)
add_subdirectory (src)
-add_subdirectory (doc)
diff --git a/lib/doc/CMakeLists.txt b/lib/doc/CMakeLists.txt
deleted file mode 100644
index 135addc09..000000000
--- a/lib/doc/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-# add a target to generate API documentation with Doxygen
-find_package(Doxygen)
-option(BUILD_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND})
-
-if(BUILD_DOCUMENTATION)
- if(NOT DOXYGEN_FOUND)
- message(FATAL_ERROR "Doxygen is needed to build the documentation.")
- endif()
-
- set(doxy_main_page ${CMAKE_CURRENT_SOURCE_DIR}/../README.md)
- set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
- set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
-
- # extract version from git
- execute_process(
- COMMAND git describe --long --match v*
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- OUTPUT_VARIABLE VERSION
- OUTPUT_STRIP_TRAILING_WHITESPACE
- )
-
- if (NOT VERSION)
- set(VERSION "v1.0-1-gcafe")
- endif()
-
- configure_file(${doxyfile_in} ${doxyfile} @ONLY)
-
- add_custom_target(doc
- COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- COMMENT "Generating API documentation with Doxygen"
- VERBATIM)
-
- install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc OPTIONAL)
-endif()
diff --git a/lib/doc/Doxyfile.in b/lib/doc/Doxyfile.in
deleted file mode 100644
index a28fb3a1a..000000000
--- a/lib/doc/Doxyfile.in
+++ /dev/null
@@ -1,12 +0,0 @@
-PROJECT_NAME = "Hybrid ICN (hICN)"
-PROJECT_NUMBER = @VERSION@
-STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ \
- @PROJECT_BINARY_DIR@
-INPUT = @doxy_main_page@ \
- @PROJECT_SOURCE_DIR@ \
- @PROJECT_BINARY_DIR@
-FILE_PATTERNS = *.md \
- *.h \
- *.cc
-RECURSIVE = YES
-USE_MDFILE_AS_MAINPAGE = @doxy_main_page@
diff --git a/lib/includes/CMakeLists.txt b/lib/includes/CMakeLists.txt
index 6184f4708..0f1bf80d3 100644
--- a/lib/includes/CMakeLists.txt
+++ b/lib/includes/CMakeLists.txt
@@ -27,9 +27,10 @@ set(LIBHICN_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/hicn/header.h
${CMAKE_CURRENT_SOURCE_DIR}/hicn/mapme.h
${CMAKE_CURRENT_SOURCE_DIR}/hicn/name.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ops.h
${CMAKE_CURRENT_SOURCE_DIR}/hicn/policy.h
${CMAKE_CURRENT_SOURCE_DIR}/hicn/protocol.h
- ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ops.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn/strategy.h
PARENT_SCOPE
)
@@ -55,3 +56,5 @@ set(LIBHICN_HEADER_FILES_UTIL
PARENT_SCOPE
)
+set_property(GLOBAL PROPERTY LIBHICN_HEADER_FILES_UTIL_PROPERTY "${LIBHICN_HEADER_FILES_UTIL}")
+
diff --git a/lib/includes/hicn/base.h b/lib/includes/hicn/base.h
index 3112d1140..1061724ce 100644
--- a/lib/includes/hicn/base.h
+++ b/lib/includes/hicn/base.h
@@ -22,12 +22,16 @@
#define HICN_BASE_H
#include "common.h"
-
+#ifdef _WIN32
+#include <Winsock2.h>
+#else
+#include <netinet/in.h>
+#endif
/* Default header fields */
#define HICN_DEFAULT_TTL 254
typedef u32 hicn_faceid_t;
-typedef u32 hicn_pathlabel_t;
+typedef u8 hicn_pathlabel_t;
typedef u32 hicn_lifetime_t;
#define HICN_MAX_LIFETIME_SCALED 0xFFFF
@@ -95,20 +99,27 @@ HICN_TYPE(int x, int y, int z, int t)
#endif
#define HICN_TYPE_IPV4_TCP HICN_TYPE(IPPROTO_IP, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE)
-#define HICN_TYPE_IPV4_UDP HICN_TYPE(IPPROTO_IP, IPPROTO_UDP, IPPROTO_NONE, IPPROTO_NONE)
#define HICN_TYPE_IPV4_ICMP HICN_TYPE(IPPROTO_IP, IPPROTO_ICMP, IPPROTO_NONE, IPPROTO_NONE)
#define HICN_TYPE_IPV6_TCP HICN_TYPE(IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE)
-#define HICN_TYPE_IPV6_UDP HICN_TYPE(IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_NONE, IPPROTO_NONE)
#define HICN_TYPE_IPV6_ICMP HICN_TYPE(IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_NONE, IPPROTO_NONE)
-#define HICN_TYPE_IPV4_TCP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE)
-#define HICN_TYPE_IPV4_UDP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_UDP, IPPROTO_NONE, IPPROTO_NONE)
-#define HICN_TYPE_IPV4_ICMP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_ICMP, IPPROTO_NONE, IPPROTO_NONE)
+#define HICN_TYPE_IPV4_TCP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE)
+#define HICN_TYPE_IPV4_ICMP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_ICMP, IPPROTO_AH, IPPROTO_NONE)
#define HICN_TYPE_IPV6_TCP_AH HICN_TYPE(IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE)
-#define HICN_TYPE_IPV6_UDP_AH HICN_TYPE(IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_AH, IPPROTO_NONE)
#define HICN_TYPE_IPV6_ICMP_AH HICN_TYPE(IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_AH, IPPROTO_NONE)
#define HICN_TYPE_NONE HICN_TYPE(IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE)
/**
+ * @brief Check if type is none.
+ * @return 1 if none, 0 otherwise
+ */
+always_inline int
+hicn_type_is_none(hicn_type_t type)
+{
+ return (type.l1 == IPPROTO_NONE) && (type.l2 == IPPROTO_NONE) &&
+ (type.l3 == IPPROTO_NONE) && (type.l4 == IPPROTO_NONE);
+}
+
+/**
* @brief hICN Payload type
*
* This type distinguishes several types of data packet, which can either carry
@@ -131,9 +142,8 @@ typedef enum
* NOTE: this computation is not (yet) part of the hICN specification.
*/
-// XXX TODO deprecate TODO XXX
-#define HICN_PATH_LABEL_MASK 0xF000 /* 1000 0000 0000 0000 */
-#define HICN_PATH_LABEL_SIZE 8 /* XXX in bits ? */
+#define HICN_PATH_LABEL_MASK 0x000000ff
+#define HICN_PATH_LABEL_SIZE 8
/**
* @brief Path label update
@@ -148,8 +158,8 @@ update_pathlabel (hicn_pathlabel_t current_label, hicn_faceid_t face_id,
hicn_pathlabel_t * new_label)
{
hicn_pathlabel_t pl_face_id =
- (hicn_pathlabel_t) ((face_id & HICN_PATH_LABEL_MASK) >>
- (16 - HICN_PATH_LABEL_SIZE));
+ (hicn_pathlabel_t) (face_id & HICN_PATH_LABEL_MASK);
+
*new_label =
((current_label << 1) | (current_label >> (HICN_PATH_LABEL_SIZE - 1))) ^
pl_face_id;
diff --git a/lib/includes/hicn/common.h b/lib/includes/hicn/common.h
index 30f370241..05f8ad95f 100644
--- a/lib/includes/hicn/common.h
+++ b/lib/includes/hicn/common.h
@@ -104,6 +104,9 @@ typedef uword ip_csum_t;
/* Windows compatibility headers */
#define WIN32_LEAN_AND_MEAN
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
#include <windows.h>
#include <winsock2.h>
#include <ws2ipdef.h>
@@ -143,8 +146,17 @@ struct iovec
#include <vnet/ip/ip4_packet.h> // ip4_address_t
#include <vnet/ip/ip6_packet.h> // ip6_address_t
+
+#if __GNUC__ >= 9
+#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
+#endif
+
#include <vnet/ip/ip46_address.h>
+#if __GNUC__ >= 9
+#pragma GCC diagnostic pop
+#endif
+
#else
@@ -250,7 +262,7 @@ u32 cumulative_hash32 (const void *data, size_t len, u32 lastValue);
u32 hash32 (const void *data, size_t len);
u64 cumulative_hash64 (const void *data, size_t len, u64 lastValue);
u64 hash64 (const void *data, size_t len);
-void hicn_packet_dump (uint8_t * buffer, size_t len);
+void hicn_packet_dump (const uint8_t * buffer, size_t len);
#endif /* ! HICN_VPP_PLUGIN */
diff --git a/lib/includes/hicn/compat.h b/lib/includes/hicn/compat.h
index 2796983c6..35b6e6fc5 100644
--- a/lib/includes/hicn/compat.h
+++ b/lib/includes/hicn/compat.h
@@ -34,15 +34,15 @@
/* HICN format options */
#define HFO_INET 1 << 0
#define HFO_INET6 1 << 1
-#define HFO_TCP 1 << 2
+#define HFO_TCP 1 << 2
#define HFO_ICMP 1 << 3
-#define HFO_AH 1 << 4
+#define HFO_AH 1 << 4
#define _is_ipv4(format) ((format & HFO_INET))
#define _is_ipv6(format) ((format & HFO_INET6) >> 1)
-#define _is_tcp(format) ((format & HFO_TCP) >> 2)
-#define _is_icmp(format) ((format & HFO_ICMP) >> 3)
-#define _is_ah(format) ((format & HFO_AH) >> 4)
+#define _is_tcp(format) ((format & HFO_TCP) >> 2)
+#define _is_icmp(format) ((format & HFO_ICMP) >> 3)
+#define _is_ah(format) ((format & HFO_AH) >> 4)
typedef enum
{
@@ -54,28 +54,30 @@ typedef enum
HF_INET_TCP_AH = HFO_INET | HFO_TCP | HFO_AH,
HF_INET6_TCP_AH = HFO_INET6 | HFO_TCP | HFO_AH,
HF_INET_ICMP_AH = HFO_INET | HFO_ICMP | HFO_AH,
- HF_INET6_ICMP_AH = HFO_INET6 | HFO_ICMP | HFO_AH
+ HF_INET6_ICMP_AH = HFO_INET6 | HFO_ICMP | HFO_AH,
} hicn_format_t;
/**
- * Minimum required header length to determine the type and length of a supposed
- * hICN packet.
- * This should be equal to the maximum value over all possible hICN packet
- * formats, and less than the minimum possible IP packet size.
+ * Minimum required header length to determine the type and length of a
+ * supposed hICN packet. This should be equal to the maximum value over all
+ * possible hICN packet formats, and less than the minimum possible IP packet
+ * size.
*/
-#define HICN_V6_MIN_HDR_LEN 6 /* bytes */
-#define HICN_V4_MIN_HDR_LEN 4 /* bytes */
+#define HICN_V6_MIN_HDR_LEN 6 /* bytes */
+#define HICN_V4_MIN_HDR_LEN 4 /* bytes */
-// #define HICN_MIN_HDR_LEN ((HICN_V6_MIN_HDR_LEN > HICN_V4_MIN_HDR_LEN) ? HICN_V6_MIN_HDR_LEN : HICN_V4_MIN_HDR_LEN)
+// #define HICN_MIN_HDR_LEN ((HICN_V6_MIN_HDR_LEN > HICN_V4_MIN_HDR_LEN) ?
+// HICN_V6_MIN_HDR_LEN : HICN_V4_MIN_HDR_LEN)
#define HICN_MIN_HDR_LEN HICN_V6_MIN_HDR_LEN
/**
* @brief Parse packet headers and return hICN format
* @param [in] format - hICN Format
- * @param [in, out] packet - Buffer containing the hICN header to be initialized
+ * @param [in, out] packet - Buffer containing the hICN header to be
+ * initialized
* @return hICN error code
*/
-int hicn_packet_init_header (hicn_format_t format, hicn_header_t * packet);
+int hicn_packet_init_header (hicn_format_t format, hicn_header_t *packet);
/**
* @brief Parse packet headers and return hICN format
@@ -83,8 +85,8 @@ int hicn_packet_init_header (hicn_format_t format, hicn_header_t * packet);
* @param [out] format - hICN format
* @return hICN error code
*/
-int hicn_packet_get_format (const hicn_header_t * packet,
- hicn_format_t * format);
+int hicn_packet_get_format (const hicn_header_t *packet,
+ hicn_format_t *format);
/**
* @brief Update checksums in packet headers
@@ -92,19 +94,18 @@ int hicn_packet_get_format (const hicn_header_t * packet,
* @param [in,out] packet - packet header
* @return hICN error code
*/
-int hicn_packet_compute_checksum (hicn_format_t format,
- hicn_header_t * packet);
+int hicn_packet_compute_checksum (hicn_format_t format, hicn_header_t *packet);
/**
- * @brief compute the checksum of the packet header, adding init_sum to the final value
+ * @brief compute the checksum of the packet header, adding init_sum to the
+ * final value
* @param [in] format - hICN format
* @param [in,out] packet - packet header
* @param [in] init_sum - value to add to the final checksum
* @return hICN error code
*/
int hicn_packet_compute_header_checksum (hicn_format_t format,
- hicn_header_t * packet,
- u16 init_sum);
+ hicn_header_t *packet, u16 init_sum);
/**
* @brief Verify checksums in packet headers
@@ -112,8 +113,9 @@ int hicn_packet_compute_header_checksum (hicn_format_t format,
* @param [in,out] packet - packet header
* @return hICN error code
*/
-int hicn_packet_check_integrity (hicn_format_t format,
- hicn_header_t * packet);
+int hicn_packet_check_integrity_no_payload (hicn_format_t format,
+ hicn_header_t *packet,
+ u16 init_sum);
// this is not accounted here
/**
@@ -123,7 +125,7 @@ int hicn_packet_check_integrity (hicn_format_t format,
* @return hICN error code
*/
int hicn_packet_get_header_length_from_format (hicn_format_t format,
- size_t * header_length);
+ size_t *header_length);
/**
* @brief Return total length of hicn headers (before payload)
@@ -133,8 +135,8 @@ int hicn_packet_get_header_length_from_format (hicn_format_t format,
* @return hICN error code
*/
int hicn_packet_get_header_length (hicn_format_t format,
- const hicn_header_t * packet,
- size_t * header_length);
+ const hicn_header_t *packet,
+ size_t *header_length);
/**
* @brief Return payload length
@@ -144,8 +146,8 @@ int hicn_packet_get_header_length (hicn_format_t format,
* @return hICN error code
*/
int hicn_packet_get_payload_length (hicn_format_t format,
- const hicn_header_t * packet,
- size_t * payload_length);
+ const hicn_header_t *packet,
+ size_t *payload_length);
/**
* @brief Sets payload length
@@ -155,7 +157,7 @@ int hicn_packet_get_payload_length (hicn_format_t format,
* @return hICN error code
*/
int hicn_packet_set_payload_length (hicn_format_t format,
- hicn_header_t * packet,
+ hicn_header_t *packet,
const size_t payload_length);
/**
@@ -164,8 +166,8 @@ int hicn_packet_set_payload_length (hicn_format_t format,
* @param [in] packet_2 - Second packet
* @return 0 if both packets are considered equal, any other value otherwise.
*/
-int hicn_packet_compare (const hicn_header_t * packet1,
- const hicn_header_t * packet2);
+int hicn_packet_compare (const hicn_header_t *packet1,
+ const hicn_header_t *packet2);
/**
* @brief Retrieve the name of an interest/data packet
@@ -176,8 +178,8 @@ int hicn_packet_compare (const hicn_header_t * packet1,
* data packet (0)
* @return hICN error code
*/
-int hicn_packet_get_name (hicn_format_t format, const hicn_header_t * packet,
- hicn_name_t * name, u8 is_interest);
+int hicn_packet_get_name (hicn_format_t format, const hicn_header_t *packet,
+ hicn_name_t *name, u8 is_interest);
/**
* @brief Sets the name of an interest/data packet
@@ -188,8 +190,8 @@ int hicn_packet_get_name (hicn_format_t format, const hicn_header_t * packet,
* data packet (0)
* @return hICN error code
*/
-int hicn_packet_set_name (hicn_format_t format, hicn_header_t * packet,
- const hicn_name_t * name, u8 is_interest);
+int hicn_packet_set_name (hicn_format_t format, hicn_header_t *packet,
+ const hicn_name_t *name, u8 is_interest);
/**
* @brief Sets the payload of a packet
@@ -203,8 +205,8 @@ int hicn_packet_set_name (hicn_format_t format, hicn_header_t * packet,
* - The buffer holding payload is assumed sufficiently large
* - This function updates header fields with the new length, but no checksum.
*/
-int hicn_packet_set_payload (hicn_format_t format, hicn_header_t * packet,
- const u8 * payload, u16 payload_length);
+int hicn_packet_set_payload (hicn_format_t format, hicn_header_t *packet,
+ const u8 *payload, u16 payload_length);
/**
* @brief Retrieves the payload of a packet
@@ -212,16 +214,17 @@ int hicn_packet_set_payload (hicn_format_t format, hicn_header_t * packet,
* @param [in] packet - packet header
* @param [out] payload - pointer to buffer for storing the result
* @param [out] payload_length - size of the retreived payload
- * @param [in] hard_copy - Flag : if true (eg. 1), a copy of the payload is made
- * into the payload buffer, otherwise (0) the pointer is changed to point to the payload offset in the packet.
+ * @param [in] hard_copy - Flag : if true (eg. 1), a copy of the payload is
+ * made into the payload buffer, otherwise (0) the pointer is changed to point
+ * to the payload offset in the packet.
* @return hICN error code
*
* NOTE:
* - The buffer holding payload is assumed sufficiently large
*/
-int hicn_packet_get_payload (hicn_format_t format,
- const hicn_header_t * packet, u8 ** payload,
- size_t * payload_size, bool hard_copy);
+int hicn_packet_get_payload (hicn_format_t format, const hicn_header_t *packet,
+ u8 **payload, size_t *payload_size,
+ bool hard_copy);
/**
* @brief Retrieve the locator of an interest / data packet
@@ -232,9 +235,8 @@ int hicn_packet_get_payload (hicn_format_t format,
* data packet (0)
* @return hICN error code
*/
-int hicn_packet_get_locator (hicn_format_t format,
- const hicn_header_t * packet,
- ip_address_t * prefix, bool is_interest);
+int hicn_packet_get_locator (hicn_format_t format, const hicn_header_t *packet,
+ ip_address_t *prefix, bool is_interest);
/**
* @brief Sets the locator of an interest / data packet
@@ -245,9 +247,8 @@ int hicn_packet_get_locator (hicn_format_t format,
* data packet (0)
* @return hICN error code
*/
-int hicn_packet_set_locator (hicn_format_t format, hicn_header_t * packet,
- const ip_address_t * prefix,
- bool is_interest);
+int hicn_packet_set_locator (hicn_format_t format, hicn_header_t *packet,
+ const ip_address_t *prefix, bool is_interest);
/**
* @brief Retrieves the signature size
@@ -257,8 +258,8 @@ int hicn_packet_set_locator (hicn_format_t format, hicn_header_t * packet,
* @return hICN error code
*/
int hicn_packet_get_signature_size (hicn_format_t format,
- const hicn_header_t * packet,
- size_t * bytes);
+ const hicn_header_t *packet,
+ size_t *bytes);
/**
* @brief Sets the signature size
@@ -268,7 +269,7 @@ int hicn_packet_get_signature_size (hicn_format_t format,
* @return hICN error code
*/
int hicn_packet_set_signature_size (hicn_format_t format,
- hicn_header_t * packet, size_t bytes);
+ hicn_header_t *packet, size_t bytes);
/**
* @brief Sets the signature size
@@ -278,7 +279,7 @@ int hicn_packet_set_signature_size (hicn_format_t format,
* @return hICN error code
*/
int hicn_packet_set_signature_timestamp (hicn_format_t format,
- hicn_header_t * h,
+ hicn_header_t *h,
uint64_t signature_timestamp);
/**
@@ -289,8 +290,8 @@ int hicn_packet_set_signature_timestamp (hicn_format_t format,
* @return hICN error code
*/
int hicn_packet_get_signature_timestamp (hicn_format_t format,
- const hicn_header_t * h,
- uint64_t * signature_timestamp);
+ const hicn_header_t *h,
+ uint64_t *signature_timestamp);
/**
* @brief Sets the signature size
@@ -300,7 +301,7 @@ int hicn_packet_get_signature_timestamp (hicn_format_t format,
* @return hICN error code
*/
int hicn_packet_set_validation_algorithm (hicn_format_t format,
- hicn_header_t * h,
+ hicn_header_t *h,
uint8_t validation_algorithm);
/**
@@ -311,8 +312,8 @@ int hicn_packet_set_validation_algorithm (hicn_format_t format,
* @return hICN error code
*/
int hicn_packet_get_validation_algorithm (hicn_format_t format,
- const hicn_header_t * h,
- uint8_t * validation_algorithm);
+ const hicn_header_t *h,
+ uint8_t *validation_algorithm);
/**
* @brief Sets the signature size
@@ -321,8 +322,8 @@ int hicn_packet_get_validation_algorithm (hicn_format_t format,
* @param [in] key_id - Key id to set
* @return hICN error code
*/
-int hicn_packet_set_key_id (hicn_format_t format, hicn_header_t * h,
- uint8_t * key_id);
+int hicn_packet_set_key_id (hicn_format_t format, hicn_header_t *h,
+ uint8_t *key_id);
/**
* @brief Sets the signature size
@@ -331,8 +332,8 @@ int hicn_packet_set_key_id (hicn_format_t format, hicn_header_t * h,
* @param [out] key_id - Retrieved key id
* @return hICN error code
*/
-int hicn_packet_get_key_id (hicn_format_t format, hicn_header_t * h,
- uint8_t ** key_id, uint8_t * key_id_length);
+int hicn_packet_get_key_id (hicn_format_t format, hicn_header_t *h,
+ uint8_t **key_id, uint8_t *key_id_length);
/**
* @brief Retrieves the packet hop limit
@@ -340,7 +341,7 @@ int hicn_packet_get_key_id (hicn_format_t format, hicn_header_t * h,
* @param [out] hops - Retrieved hop limit
* @return hICN error code
*/
-int hicn_packet_get_hoplimit (const hicn_header_t * packet, u8 * hops);
+int hicn_packet_get_hoplimit (const hicn_header_t *packet, u8 *hops);
/**
* @brief Sets the packet hop limit
@@ -348,107 +349,111 @@ int hicn_packet_get_hoplimit (const hicn_header_t * packet, u8 * hops);
* @param [in] hops - Hop limit to set
* @return hICN error code
*/
-int hicn_packet_set_hoplimit (hicn_header_t * packet, u8 hops);
+int hicn_packet_set_hoplimit (hicn_header_t *packet, u8 hops);
-int hicn_packet_copy_header (hicn_format_t format,
- const hicn_header_t * packet,
- hicn_header_t * destination, bool copy_ah);
+int hicn_packet_copy_header (hicn_format_t format, const hicn_header_t *packet,
+ hicn_header_t *destination, bool copy_ah);
-int hicn_packet_get_lifetime (const hicn_header_t * packet, u32 * lifetime);
-int hicn_packet_set_lifetime (hicn_header_t * packet, u32 lifetime);
-int hicn_packet_get_reserved_bits (const hicn_header_t * packet,
- u8 * reserved_bits);
-int hicn_packet_set_reserved_bits (hicn_header_t * packet,
+int hicn_packet_get_lifetime (const hicn_header_t *packet, u32 *lifetime);
+int hicn_packet_set_lifetime (hicn_header_t *packet, u32 lifetime);
+int hicn_packet_get_reserved_bits (const hicn_header_t *packet,
+ u8 *reserved_bits);
+int hicn_packet_set_reserved_bits (hicn_header_t *packet,
const u8 reserved_bits);
-int hicn_packet_get_payload_type (const hicn_header_t * packet,
- hicn_payload_type_t * payload_type);
-int hicn_packet_set_payload_type (hicn_header_t * packet,
+int hicn_packet_get_payload_type (const hicn_header_t *packet,
+ hicn_payload_type_t *payload_type);
+int hicn_packet_set_payload_type (hicn_header_t *packet,
const hicn_payload_type_t payload_type);
-int hicn_packet_set_syn (hicn_header_t * packet);
-int hicn_packet_reset_syn (hicn_header_t * packet);
-int hicn_packet_test_syn (const hicn_header_t * packet, bool * flag);
-int hicn_packet_set_ack (hicn_header_t * packet);
-int hicn_packet_reset_ack (hicn_header_t * packet);
-int hicn_packet_test_ack (const hicn_header_t * packet, bool * flag);
-int hicn_packet_set_rst (hicn_header_t * packet);
-int hicn_packet_reset_rst (hicn_header_t * packet);
-int hicn_packet_test_rst (const hicn_header_t * packet, bool * flag);
-int hicn_packet_set_fin (hicn_header_t * packet);
-int hicn_packet_reset_fin (hicn_header_t * packet);
-int hicn_packet_test_fin (const hicn_header_t * packet, bool * flag);
-int hicn_packet_set_ece (hicn_header_t * packet);
-int hicn_packet_reset_ece (hicn_header_t * packet);
-int hicn_packet_test_ece (const hicn_header_t * packet, bool * flag);
-
-int hicn_packet_set_src_port (hicn_header_t * packet, u16 src_port);
-int hicn_packet_get_src_port (const hicn_header_t * packet, u16 * src_port);
-int hicn_packet_set_dst_port (hicn_header_t * packet, u16 dst_port);
-int hicn_packet_get_dst_port (const hicn_header_t * packet, u16 * dst_port);
-int hicn_packet_get_signature (hicn_format_t format, hicn_header_t * packet,
- uint8_t ** sign_buf);
+int hicn_packet_set_syn (hicn_format_t format, hicn_header_t *packet);
+int hicn_packet_reset_syn (hicn_format_t format, hicn_header_t *packet);
+int hicn_packet_test_syn (hicn_format_t format, const hicn_header_t *packet,
+ bool *flag);
+int hicn_packet_set_ack (hicn_format_t format, hicn_header_t *packet);
+int hicn_packet_reset_ack (hicn_format_t format, hicn_header_t *packet);
+int hicn_packet_test_ack (hicn_format_t format, const hicn_header_t *packet,
+ bool *flag);
+int hicn_packet_set_rst (hicn_format_t format, hicn_header_t *packet);
+int hicn_packet_reset_rst (hicn_format_t format, hicn_header_t *packet);
+int hicn_packet_test_rst (hicn_format_t format, const hicn_header_t *packet,
+ bool *flag);
+int hicn_packet_set_fin (hicn_format_t format, hicn_header_t *packet);
+int hicn_packet_reset_fin (hicn_format_t format, hicn_header_t *packet);
+int hicn_packet_test_fin (hicn_format_t format, const hicn_header_t *packet,
+ bool *flag);
+int hicn_packet_set_ece (hicn_format_t format, hicn_header_t *packet);
+int hicn_packet_reset_ece (hicn_format_t format, hicn_header_t *packet);
+int hicn_packet_test_ece (hicn_format_t format, const hicn_header_t *packet,
+ bool *flag);
+
+int hicn_packet_set_src_port (hicn_format_t format, hicn_header_t *packet,
+ u16 src_port);
+int hicn_packet_get_src_port (hicn_format_t format,
+ const hicn_header_t *packet, u16 *src_port);
+int hicn_packet_set_dst_port (hicn_format_t format, hicn_header_t *packet,
+ u16 dst_port);
+int hicn_packet_get_dst_port (hicn_format_t format,
+ const hicn_header_t *packet, u16 *dst_port);
+int hicn_packet_get_signature (hicn_format_t format, hicn_header_t *packet,
+ uint8_t **sign_buf);
/* Interest */
int hicn_interest_get_name (hicn_format_t format,
- const hicn_header_t * interest,
- hicn_name_t * name);
-int hicn_interest_set_name (hicn_format_t format, hicn_header_t * interest,
- const hicn_name_t * name);
+ const hicn_header_t *interest, hicn_name_t *name);
+int hicn_interest_set_name (hicn_format_t format, hicn_header_t *interest,
+ const hicn_name_t *name);
int hicn_interest_get_locator (hicn_format_t format,
- const hicn_header_t * interest,
- ip_address_t * prefix);
-int hicn_interest_set_locator (hicn_format_t format, hicn_header_t * interest,
- const ip_address_t * prefix);
-int hicn_interest_compare (const hicn_header_t * interest_1,
- const hicn_header_t * interest_2);
-int hicn_interest_set_lifetime (hicn_header_t * interest, u32 lifetime);
-int hicn_interest_get_lifetime (const hicn_header_t * interest,
- u32 * lifetime);
+ const hicn_header_t *interest,
+ ip_address_t *prefix);
+int hicn_interest_set_locator (hicn_format_t format, hicn_header_t *interest,
+ const ip_address_t *prefix);
+int hicn_interest_compare (const hicn_header_t *interest_1,
+ const hicn_header_t *interest_2);
+int hicn_interest_set_lifetime (hicn_header_t *interest, u32 lifetime);
+int hicn_interest_get_lifetime (const hicn_header_t *interest, u32 *lifetime);
int hicn_interest_get_header_length (hicn_format_t format,
- const hicn_header_t * interest,
- size_t * header_length);
+ const hicn_header_t *interest,
+ size_t *header_length);
int hicn_interest_get_payload_length (hicn_format_t format,
- const hicn_header_t * interest,
- size_t * payload_length);
-int hicn_interest_set_payload (hicn_format_t format, hicn_header_t * interest,
- const u8 * payload, size_t payload_length);
+ const hicn_header_t *interest,
+ size_t *payload_length);
+int hicn_interest_set_payload (hicn_format_t format, hicn_header_t *interest,
+ const u8 *payload, size_t payload_length);
int hicn_interest_get_payload (hicn_format_t format,
- const hicn_header_t * interest, u8 ** payload,
- size_t * payload_size, bool hard_copy);
-int hicn_interest_reset_for_hash (hicn_format_t format,
- hicn_header_t * packet);
+ const hicn_header_t *interest, u8 **payload,
+ size_t *payload_size, bool hard_copy);
+int hicn_interest_reset_for_hash (hicn_format_t format, hicn_header_t *packet);
/* Data */
-int hicn_data_get_name (hicn_format_t format, const hicn_header_t * data,
- hicn_name_t * name);
-int hicn_data_set_name (hicn_format_t format, hicn_header_t * data,
- const hicn_name_t * name);
-int hicn_data_get_locator (hicn_format_t format, const hicn_header_t * data,
- ip_address_t * prefix);
-int hicn_data_set_locator (hicn_format_t format, hicn_header_t * data,
- const ip_address_t * prefix);
-int hicn_data_compare (const hicn_header_t * data_1,
- const hicn_header_t * data_2);
-int hicn_data_get_expiry_time (const hicn_header_t * data, u32 * expiry_time);
-int hicn_data_set_expiry_time (hicn_header_t * data, u32 expiry_time);
-int hicn_data_get_header_length (hicn_format_t format, hicn_header_t * data,
- size_t * header_length);
+int hicn_data_get_name (hicn_format_t format, const hicn_header_t *data,
+ hicn_name_t *name);
+int hicn_data_set_name (hicn_format_t format, hicn_header_t *data,
+ const hicn_name_t *name);
+int hicn_data_get_locator (hicn_format_t format, const hicn_header_t *data,
+ ip_address_t *prefix);
+int hicn_data_set_locator (hicn_format_t format, hicn_header_t *data,
+ const ip_address_t *prefix);
+int hicn_data_compare (const hicn_header_t *data_1,
+ const hicn_header_t *data_2);
+int hicn_data_get_expiry_time (const hicn_header_t *data, u32 *expiry_time);
+int hicn_data_set_expiry_time (hicn_header_t *data, u32 expiry_time);
+int hicn_data_get_header_length (hicn_format_t format, hicn_header_t *data,
+ size_t *header_length);
int hicn_data_get_payload_length (hicn_format_t format,
- const hicn_header_t * data,
- size_t * payload_length);
-int hicn_data_get_path_label (const hicn_header_t * data, u32 * path_label);
-int hicn_data_set_path_label (hicn_header_t * data, u32 path_label);
-int hicn_data_get_payload (hicn_format_t format, const hicn_header_t * data,
- u8 ** payload, size_t * payload_size,
- bool hard_copy);
-int hicn_data_set_payload (hicn_format_t format, hicn_header_t * data,
- const u8 * payload, size_t payload_length);
-int hicn_data_get_payload_type (const hicn_header_t * data,
- hicn_payload_type_t * payload_type);
-int hicn_data_set_payload_type (hicn_header_t * data,
+ const hicn_header_t *data,
+ size_t *payload_length);
+int hicn_data_get_path_label (const hicn_header_t *data, u32 *path_label);
+int hicn_data_set_path_label (hicn_header_t *data, u32 path_label);
+int hicn_data_get_payload (hicn_format_t format, const hicn_header_t *data,
+ u8 **payload, size_t *payload_size, bool hard_copy);
+int hicn_data_set_payload (hicn_format_t format, hicn_header_t *data,
+ const u8 *payload, size_t payload_length);
+int hicn_data_get_payload_type (const hicn_header_t *data,
+ hicn_payload_type_t *payload_type);
+int hicn_data_set_payload_type (hicn_header_t *data,
hicn_payload_type_t payload_type);
-int hicn_data_reset_for_hash (hicn_format_t format, hicn_header_t * packet);
+int hicn_data_reset_for_hash (hicn_format_t format, hicn_header_t *packet);
#endif /* HICN_COMPAT_H */
diff --git a/lib/includes/hicn/error.h b/lib/includes/hicn/error.h
index 3e027c4e5..9303aeb7e 100644
--- a/lib/includes/hicn/error.h
+++ b/lib/includes/hicn/error.h
@@ -24,16 +24,17 @@
* Error definitions
******************************************************************************/
-#define foreach_libhicn_error \
-_(NONE, 0, "OK") \
-_(UNSPECIFIED, 128, "Unspecified Error") \
-_(NOT_IMPLEMENTED, 180, "Function not yet implemented") \
-_(NOT_HICN, 202, "Non hICN packet") \
-_(UNKNOWN_ADDRESS, 210, "Unknown address") \
-_(INVALID_PARAMETER, 220, "Invalid parameter") \
-_(INVALID_IP_ADDRESS, 221, "Invalid IP address") \
-_(CORRUPTED_PACKET, 222, "Corrupted packet ") \
-_(UNEXPECTED, 298, "Unexpected error")
+#define foreach_libhicn_error \
+_(NONE, 0, "OK") \
+_(UNSPECIFIED, 128, "Unspecified Error") \
+_(NOT_IMPLEMENTED, 180, "Function not yet implemented") \
+_(NOT_HICN, 202, "Non hICN packet") \
+_(UNKNOWN_ADDRESS, 210, "Unknown address") \
+_(INVALID_PARAMETER, 220, "Invalid parameter") \
+_(INVALID_IP_ADDRESS, 221, "Invalid IP address") \
+_(CORRUPTED_PACKET, 222, "Corrupted packet ") \
+_(REWRITE_CKSUM_REQUIRED, 223, "Incremental csum calculation error: cksum required.") \
+_(UNEXPECTED, 298, "Unexpected error")
typedef enum
{
diff --git a/lib/includes/hicn/face.h b/lib/includes/hicn/face.h
index 0d116b64b..3438552ff 100644
--- a/lib/includes/hicn/face.h
+++ b/lib/includes/hicn/face.h
@@ -219,4 +219,3 @@ int face_set_tags(face_t * face, policy_tags_t tags);
face_protocol_t get_protocol(face_type_t face_type);
#endif /* HICN_FACE_H */
-
diff --git a/lib/includes/hicn/ops.h b/lib/includes/hicn/ops.h
index 47795efd5..7d4ae86d8 100644
--- a/lib/includes/hicn/ops.h
+++ b/lib/includes/hicn/ops.h
@@ -106,6 +106,22 @@ typedef struct hicn_ops_s
const hicn_name_suffix_t * suffix);
/**
+ * @brief Set flag to mark current packet as interest
+ * @param [in] type - hICN packet type
+ * @param [in,out] h - Buffer holding the Interest packet
+ * @return hICN error code
+ */
+ int (*mark_packet_as_interest) (hicn_type_t type, hicn_protocol_t * h);
+
+ /**
+ * @brief Set flag to mark current packet as data
+ * @param [in] type - hICN packet type
+ * @param [in,out] h - Buffer holding the Interest packet
+ * @return hICN error code
+ */
+ int (*mark_packet_as_data) (hicn_type_t type, hicn_protocol_t * h);
+
+ /**
* @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
@@ -237,7 +253,7 @@ typedef struct hicn_ops_s
* @param [in,out] h - Buffer holding the packet
* @param [in] partial_csum - Partial checksum (set to 0, used internally to
* carry intermediate values from IP pseudo-header)
- * @param [in] payload_length - Payload length (can be set to 0, retrieved
+ * @param [in] payload_length - Payload length (can be set to ~0, retrieved
* and used internally to carry payload length across protocol headers)
* @return hICN error code
*/
@@ -248,9 +264,8 @@ typedef struct hicn_ops_s
* @brief Validate all checksums in packet headers
* @param [in] type - hICN packet type
* @param [in] h - Buffer holding the packet
- * @param [in] partial_csum - Partial checksum (set to 0, used internally to
- * carry intermediate values from IP pseudo-header)
- * @param [in] payload_length - Payload length (can be set to 0, retrieved
+ * @param [in] partial_csum - Partial checksum, or zero if no partial checksum available
+ * @param [in] payload_length - Payload length (can be set to ~0, retrieved
* and used internally to carry payload length across protocol headers)
* @return hICN error code
*/
@@ -278,12 +293,15 @@ typedef struct hicn_ops_s
* @param [in] addr_old - Old locator (set to NULL, used internally to
* compute incremental checksums)
* @param [in] face_id - Face identifier used to update pathlabel
+ * @param [in] reset_pl - If not zero, reset the current pathlabel
+ * before update it
* @return hICN error code
*/
int (*rewrite_data) (hicn_type_t type, hicn_protocol_t * h,
const ip46_address_t * addr_new,
ip46_address_t * addr_old,
- const hicn_faceid_t face_id);
+ const hicn_faceid_t face_id,
+ u8 reset_pl);
/**
* @brief Return the packet length
@@ -438,6 +456,8 @@ typedef struct hicn_ops_s
ATTR_INIT(set_interest_name, protocol ## _set_interest_name), \
ATTR_INIT(get_interest_name_suffix, protocol ## _get_interest_name_suffix), \
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(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), \
@@ -537,6 +557,12 @@ PAYLOAD (hicn_type_t type, const hicn_protocol_t * h)
#define DECLARE_set_interest_name_suffix(protocol, error) \
int protocol ## _set_interest_name_suffix(hicn_type_t type, hicn_protocol_t * h, const hicn_name_suffix_t * suffix) { return HICN_LIB_ERROR_ ## error ; }
+#define DECLARE_mark_packet_as_interest(protocol, error) \
+ int protocol ## _mark_packet_as_interest(hicn_type_t type, hicn_protocol_t * h) { return HICN_LIB_ERROR_ ## error ; }
+
+#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_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 ; }
@@ -586,7 +612,7 @@ PAYLOAD (hicn_type_t type, const hicn_protocol_t * h)
int protocol ## _rewrite_interest(hicn_type_t type, hicn_protocol_t * h, const ip46_address_t * addr_new, ip46_address_t * addr_old) { return HICN_LIB_ERROR_ ## error ; }
#define DECLARE_rewrite_data(protocol, error) \
- int protocol ## _rewrite_data(hicn_type_t type, hicn_protocol_t * h, const ip46_address_t * addr_new, ip46_address_t * addr_old, const hicn_faceid_t face_id) { return HICN_LIB_ERROR_ ## error ; }
+ int protocol ## _rewrite_data(hicn_type_t type, hicn_protocol_t * h, const ip46_address_t * addr_new, ip46_address_t * addr_old, const hicn_faceid_t face_id, u8 reset_pl) { return HICN_LIB_ERROR_ ## error ; }
#define DECLARE_get_length(protocol, error) \
int protocol ## _get_length(hicn_type_t type, const hicn_protocol_t * h, size_t * length) { return HICN_LIB_ERROR_ ## error ; }
diff --git a/lib/includes/hicn/policy.h b/lib/includes/hicn/policy.h
index 5a9a44467..d649630bd 100644
--- a/lib/includes/hicn/policy.h
+++ b/lib/includes/hicn/policy.h
@@ -159,12 +159,16 @@ int policy_tag_state_snprintf(char * s, size_t size, const policy_tag_state_t *
typedef struct {
char app_name[APP_NAME_LEN];
policy_tag_state_t tags[POLICY_TAG_N];
-} policy_t;
+} hicn_policy_t;
-static const policy_t POLICY_NONE = {
+static const hicn_policy_t POLICY_NONE = {
.app_name = { 0 },
.tags = {
+#ifdef __ANDROID__
+#define _(x, y) { POLICY_STATE_NEUTRAL, 0 },
+#else
#define _(x, y) [POLICY_TAG_ ## x] = { POLICY_STATE_NEUTRAL, 0 },
+#endif
foreach_policy_tag
#undef _
},
@@ -181,7 +185,7 @@ typedef struct {
char ipv4_prefix[INET_ADDRSTRLEN + PFX_STRLEN];
char ipv6_prefix[INET6_ADDRSTRLEN + PFX_STRLEN];
};
- policy_t policy;
+ hicn_policy_t policy;
} policy_description_t;
#endif /* HICN_POLICY_H */
diff --git a/lib/includes/hicn/protocol/tcp.h b/lib/includes/hicn/protocol/tcp.h
index 5cf1a3625..347682299 100644
--- a/lib/includes/hicn/protocol/tcp.h
+++ b/lib/includes/hicn/protocol/tcp.h
@@ -42,7 +42,11 @@ typedef struct
union
{
u32 seq_ack;
- hicn_pathlabel_t pathlabel;
+ struct
+ {
+ hicn_pathlabel_t pathlabel;
+ u8 pad[3];
+ };
};
union
@@ -124,8 +128,6 @@ typedef struct
static_assert (EXPECTED_TCP_HDRLEN == TCP_HDRLEN,
"Size of TCP struct does not match its expected size.");
-#ifndef HICN_VPP_PLUGIN
-
/* TCP flags bit 0 first. */
#define foreach_tcp_flag \
_ (FIN) /**< No more data from sender. */ \
@@ -152,12 +154,6 @@ enum
#undef _
};
-#endif /* HICN_VPP_PLUGIN */
-
-// get_data_name_suffix
-// name->ip4.suffix = h->v4.tcp.seq;
-
-
#endif /* HICN_PROTOCOL_TCP_H */
/*
diff --git a/lib/includes/hicn/strategy.h b/lib/includes/hicn/strategy.h
new file mode 100644
index 000000000..fe47ce547
--- /dev/null
+++ b/lib/includes/hicn/strategy.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2020 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 strategy.h
+ * \brief hICN forwarding strategy
+ */
+#ifndef HICN_STRATEGY_H
+#define HICN_STRATEGY_H
+
+typedef enum {
+ STRATEGY_TYPE_UNDEFINED,
+ STRATEGY_TYPE_LOADBALANCER,
+ STRATEGY_TYPE_LOW_LATENCY,
+ STRATEGY_TYPE_RANDOM,
+ STRATEGY_TYPE_N
+} strategy_type_t;
+
+#define STRATEGY_TYPE_VALID(type) \
+ ((type != STRATEGY_TYPE_UNDEFINED) && (type != STRATEGY_TYPE_N))
+
+#define MAX_FWD_STRATEGY_RELATED_PREFIXES 10
+
+#endif /* HICN_STRATEGY_H */
diff --git a/lib/includes/hicn/util/log.h b/lib/includes/hicn/util/log.h
index 6763d464f..5650a164e 100644
--- a/lib/includes/hicn/util/log.h
+++ b/lib/includes/hicn/util/log.h
@@ -34,7 +34,7 @@ typedef struct {
} log_conf_t;
#define DEFAULT_LOG_CONF { \
- .log_level = LOG_INFO, \
+ .log_level = LOG_TRACE, \
.debug = 0, \
.log_file = NULL, \
};
diff --git a/lib/includes/hicn/util/windows/dlfcn.h b/lib/includes/hicn/util/windows/dlfcn.h
new file mode 100644
index 000000000..7775226cd
--- /dev/null
+++ b/lib/includes/hicn/util/windows/dlfcn.h
@@ -0,0 +1,33 @@
+/* dlfcn.h */
+
+#ifndef DLFCN_H
+#define DLFCN_H
+#define RTLD_GLOBAL 0x100 /* do not hide entries in this module */
+#define RTLD_LOCAL 0x000 /* hide entries in this module */
+
+#define RTLD_LAZY 0x000 /* accept unresolved externs */
+#define RTLD_NOW 0x001 /* abort if module has unresolved externs */
+
+/*
+ How to call in Windows:
+
+ void *h = dlopen ("path\\library.dll", flags)
+ void (*fun)() = dlsym (h, "entry")
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ void *dlopen (const char *filename, int flag);
+ int dlclose (void *handle);
+
+ void *dlsym (void *handle, const char *name);
+
+const char *dlerror (void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif \ No newline at end of file
diff --git a/lib/includes/hicn/util/windows/windows_utils.h b/lib/includes/hicn/util/windows/windows_utils.h
index c4662af5e..d24aaadbf 100755
--- a/lib/includes/hicn/util/windows/windows_utils.h
+++ b/lib/includes/hicn/util/windows/windows_utils.h
@@ -17,12 +17,16 @@
#define WINDOWS_UTILS_H
#define WIN32_LEAN_AND_MEAN
#define HAVE_STRUCT_TIMESPEC
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
#include <Windows.h>
#include <stdint.h>
#include <io.h>
#include <stdlib.h>
#include <winsock2.h>
#include <WS2tcpip.h>
+#include "dlfcn.h"
#ifndef IOVEC
#define IOVEC
@@ -152,3 +156,7 @@ int gettimeofday(struct timeval * tp, struct timezone * tzp);
((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) \
| (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
#endif
+
+#ifndef bzero
+#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
+#endif \ No newline at end of file
diff --git a/lib/src/CMakeLists.txt b/lib/src/CMakeLists.txt
index 6eb4c9554..b8cfc3f6c 100644
--- a/lib/src/CMakeLists.txt
+++ b/lib/src/CMakeLists.txt
@@ -31,6 +31,11 @@ list(APPEND LIBHICN_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/util/log.c
)
+if (WIN32)
+ list(APPEND LIBHICN_SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/util/windows/dlfcn.c
+ )
+endif ()
set (COMPILER_DEFINITIONS
"-DWITH_MAPME"
"-DWITH_POLICY"
@@ -46,7 +51,7 @@ if (DISABLE_SHARED_LIBRARIES)
COMPONENT lib${LIBHICN}
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../includes
DEFINITIONS ${COMPILER_DEFINITIONS}
- INSTALL_ROOT_DIR hicn
+ HEADER_ROOT_DIR hicn
INSTALL_HEADERS ${LIBHICN_HEADER_FILES} ${LIBHICN_HEADER_FILES_PROTOCOL} ${LIBHICN_HEADER_FILES_UTIL}
LINK_LIBRARIES ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
)
@@ -57,7 +62,7 @@ else ()
COMPONENT lib${LIBHICN}
INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../includes
DEFINITIONS ${COMPILER_DEFINITIONS}
- INSTALL_ROOT_DIR hicn
+ HEADER_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/common.c b/lib/src/common.c
index 78d25b770..562771e09 100644
--- a/lib/src/common.c
+++ b/lib/src/common.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <hicn/common.h>
+#include <hicn/util/log.h>
@@ -109,7 +110,7 @@ hash64 (const void *data, size_t len)
}
void
-hicn_packet_dump (uint8_t * buffer, size_t len)
+hicn_packet_dump (const uint8_t * buffer, size_t len)
{
int i;
unsigned char buff[17];
diff --git a/lib/src/compat.c b/lib/src/compat.c
index 615175e3b..779a47315 100644
--- a/lib/src/compat.c
+++ b/lib/src/compat.c
@@ -20,8 +20,8 @@
#ifndef _WIN32
#include <netinet/in.h>
#endif
-#include <string.h> // memset
-#include <stddef.h> // offsetof
+#include <string.h> // memset
+#include <stddef.h> // offsetof
#include <hicn/common.h>
#include <hicn/compat.h>
@@ -30,13 +30,13 @@
#include <hicn/name.h>
#include <hicn/ops.h>
-#define member_size(type, member) sizeof(((type *)0)->member)
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
+#define member_size(type, member) sizeof (((type *) 0)->member)
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof (*(a)))
#define HICN_NAME_COMPONENT_SIZE 2
int
-hicn_packet_get_format (const hicn_header_t * h, hicn_format_t * format)
+hicn_packet_get_format (const hicn_header_t *h, hicn_format_t *format)
{
*format = HF_UNSPEC;
@@ -122,7 +122,7 @@ hicn_format_to_type (hicn_format_t format)
* This function is used to wrap old API calls to new ones
*/
hicn_type_t
-hicn_header_to_type (const hicn_header_t * h)
+hicn_header_to_type (const hicn_header_t *h)
{
hicn_format_t format;
hicn_packet_get_format (h, &format);
@@ -130,39 +130,47 @@ hicn_header_to_type (const hicn_header_t * h)
}
int
-hicn_packet_init_header (hicn_format_t format, hicn_header_t * packet)
+hicn_packet_init_header (hicn_format_t format, hicn_header_t *packet)
{
hicn_type_t type = hicn_format_to_type (format);
+
+ if (hicn_type_is_none (type))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
return hicn_ops_vft[type.l1]->init_packet_header (type, &packet->protocol);
}
int
-hicn_packet_compute_checksum (hicn_format_t format, hicn_header_t * h)
+hicn_packet_compute_checksum (hicn_format_t format, hicn_header_t *h)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->update_checksums (type, &h->protocol, 0, 0);
+ return hicn_ops_vft[type.l1]->update_checksums (type, &h->protocol, 0, ~0);
}
int
-hicn_packet_compute_header_checksum (hicn_format_t format, hicn_header_t * h,
+hicn_packet_compute_header_checksum (hicn_format_t format, hicn_header_t *h,
u16 init_sum)
{
hicn_type_t type = hicn_format_to_type (format);
- /* payload_length == ~0: ignore payload */
- return hicn_ops_vft[type.l1]->update_checksums (type, &h->protocol,
- init_sum, ~0);
+ /* payload_length == 0: ignore payload */
+ return hicn_ops_vft[type.l1]->update_checksums (type, &h->protocol, init_sum,
+ 0);
}
int
-hicn_packet_check_integrity (hicn_format_t format, hicn_header_t * h)
+hicn_packet_check_integrity_no_payload (hicn_format_t format, hicn_header_t *h,
+ u16 init_sum)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->verify_checksums (type, &h->protocol, 0, 0);
+ return hicn_ops_vft[type.l1]->verify_checksums (type, &h->protocol, init_sum,
+ 0);
}
int
hicn_packet_get_header_length_from_format (hicn_format_t format,
- size_t * header_length)
+ size_t *header_length)
{
*header_length = _is_ipv4 (format) * IPV4_HDRLEN;
*header_length += _is_ipv6 (format) * IPV6_HDRLEN;
@@ -174,8 +182,8 @@ hicn_packet_get_header_length_from_format (hicn_format_t format,
}
int
-hicn_packet_get_header_length (hicn_format_t format, const hicn_header_t * h,
- size_t * header_length)
+hicn_packet_get_header_length (hicn_format_t format, const hicn_header_t *h,
+ size_t *header_length)
{
hicn_packet_get_header_length_from_format (format, header_length);
int is_ah = _is_ah (format);
@@ -184,15 +192,15 @@ hicn_packet_get_header_length (hicn_format_t format, const hicn_header_t * h,
// The signature payload is expressed as number of 32 bits words
if (is_ah && is_ipv4)
*header_length += (h->v4ah.ah.payloadlen) << 2;
- else if(is_ah && is_ipv6)
+ else if (is_ah && is_ipv6)
*header_length += (h->v6ah.ah.payloadlen) << 2;
return HICN_LIB_ERROR_NONE;
}
int
-hicn_packet_get_payload_length (hicn_format_t format, const hicn_header_t * h,
- size_t * payload_length)
+hicn_packet_get_payload_length (hicn_format_t format, const hicn_header_t *h,
+ size_t *payload_length)
{
hicn_type_t type = hicn_format_to_type (format);
return hicn_ops_vft[type.l1]->get_payload_length (type, &h->protocol,
@@ -200,7 +208,7 @@ hicn_packet_get_payload_length (hicn_format_t format, const hicn_header_t * h,
}
int
-hicn_packet_set_payload_length (hicn_format_t format, hicn_header_t * h,
+hicn_packet_set_payload_length (hicn_format_t format, hicn_header_t *h,
const size_t payload_length)
{
hicn_type_t type = hicn_format_to_type (format);
@@ -209,8 +217,8 @@ hicn_packet_set_payload_length (hicn_format_t format, hicn_header_t * h,
}
int
-hicn_packet_compare (const hicn_header_t * packet1,
- const hicn_header_t * packet2)
+hicn_packet_compare (const hicn_header_t *packet1,
+ const hicn_header_t *packet2)
{
hicn_type_t type1 = hicn_header_to_type (packet1);
hicn_type_t type2 = hicn_header_to_type (packet2);
@@ -233,25 +241,23 @@ hicn_packet_compare (const hicn_header_t * packet1,
return HICN_LIB_ERROR_UNEXPECTED;
return memcmp ((u8 *) packet1, (u8 *) packet2, len1);
-
}
int
-hicn_packet_get_name (hicn_format_t format, const hicn_header_t * h,
- hicn_name_t * name, u8 is_interest)
+hicn_packet_get_name (hicn_format_t format, const hicn_header_t *h,
+ hicn_name_t *name, u8 is_interest)
{
hicn_type_t type = hicn_format_to_type (format);
if (is_interest)
- return hicn_ops_vft[type.l1]->get_interest_name (type, &h->protocol,
- name);
+ return hicn_ops_vft[type.l1]->get_interest_name (type, &h->protocol, name);
else
return hicn_ops_vft[type.l1]->get_data_name (type, &h->protocol, name);
}
int
-hicn_packet_set_name (hicn_format_t format, hicn_header_t * h,
- const hicn_name_t * name, u8 is_interest)
+hicn_packet_set_name (hicn_format_t format, hicn_header_t *h,
+ const hicn_name_t *name, u8 is_interest)
{
hicn_type_t type = hicn_format_to_type (format);
@@ -261,23 +267,21 @@ hicn_packet_set_name (hicn_format_t format, hicn_header_t * h,
#endif /* HICN_VPP_PLUGIN */
if (is_interest)
- return hicn_ops_vft[type.l1]->set_interest_name (type, &h->protocol,
- name);
+ return hicn_ops_vft[type.l1]->set_interest_name (type, &h->protocol, name);
else
return hicn_ops_vft[type.l1]->set_data_name (type, &h->protocol, name);
}
int
-hicn_packet_set_payload (hicn_format_t format, hicn_header_t * h,
- const u8 * payload, u16 payload_length)
+hicn_packet_set_payload (hicn_format_t format, hicn_header_t *h,
+ const u8 *payload, u16 payload_length)
{
hicn_type_t type = hicn_format_to_type (format);
size_t header_length;
int rc;
- rc =
- hicn_ops_vft[type.l1]->get_header_length (type, &h->protocol,
- &header_length);
+ rc = hicn_ops_vft[type.l1]->get_header_length (type, &h->protocol,
+ &header_length);
if (rc < 0)
return rc;
@@ -288,22 +292,20 @@ hicn_packet_set_payload (hicn_format_t format, hicn_header_t * h,
}
int
-hicn_packet_get_payload (hicn_format_t format, const hicn_header_t * h,
- u8 ** payload, size_t * payload_size, bool hard_copy)
+hicn_packet_get_payload (hicn_format_t format, const hicn_header_t *h,
+ u8 **payload, size_t *payload_size, bool hard_copy)
{
size_t header_length, payload_length;
int rc;
hicn_type_t type = hicn_format_to_type (format);
- rc =
- hicn_ops_vft[type.l1]->get_header_length (type, &h->protocol,
- &header_length);
+ rc = hicn_ops_vft[type.l1]->get_header_length (type, &h->protocol,
+ &header_length);
if (rc < 0)
return rc;
- rc =
- hicn_ops_vft[type.l1]->get_payload_length (type, &h->protocol,
- &payload_length);
+ rc = hicn_ops_vft[type.l1]->get_payload_length (type, &h->protocol,
+ &payload_length);
if (rc < 0)
return rc;
@@ -320,23 +322,21 @@ hicn_packet_get_payload (hicn_format_t format, const hicn_header_t * h,
}
int
-hicn_packet_get_locator (hicn_format_t format, const hicn_header_t * h,
- ip_address_t * address, bool is_interest)
+hicn_packet_get_locator (hicn_format_t format, const hicn_header_t *h,
+ ip_address_t *address, bool is_interest)
{
int is_ipv4 = (format & HFO_INET);
int is_ipv6 = (format & HFO_INET6) >> 1;
if (is_ipv4)
{
- address->v4.as_inaddr = is_interest
- ? h->v4.ip.saddr.as_inaddr
- : h->v4.ip.daddr.as_inaddr;
+ address->v4.as_inaddr =
+ is_interest ? h->v4.ip.saddr.as_inaddr : h->v4.ip.daddr.as_inaddr;
}
else if (is_ipv6)
{
- address->v6.as_in6addr = is_interest
- ? h->v6.ip.saddr.as_in6addr
- : h->v6.ip.daddr.as_in6addr;
+ address->v6.as_in6addr =
+ is_interest ? h->v6.ip.saddr.as_in6addr : h->v6.ip.daddr.as_in6addr;
}
else
{
@@ -347,25 +347,25 @@ hicn_packet_get_locator (hicn_format_t format, const hicn_header_t * h,
}
int
-hicn_packet_set_locator (hicn_format_t format, hicn_header_t * h,
- const ip_address_t * address, bool is_interest)
+hicn_packet_set_locator (hicn_format_t format, hicn_header_t *h,
+ const ip_address_t *address, bool is_interest)
{
int is_ipv4 = (format & HFO_INET);
int is_ipv6 = (format & HFO_INET6) >> 1;
if (is_ipv6)
{
- if (is_interest)
- h->v6.ip.saddr.as_in6addr = address->v6.as_in6addr;
- else
- h->v6.ip.daddr.as_in6addr = address->v6.as_in6addr;
+ if (is_interest)
+ h->v6.ip.saddr.as_in6addr = address->v6.as_in6addr;
+ else
+ h->v6.ip.daddr.as_in6addr = address->v6.as_in6addr;
}
else if (is_ipv4)
{
- if (is_interest)
- h->v4.ip.saddr.as_inaddr = address->v4.as_inaddr;
- else
- h->v4.ip.daddr.as_inaddr = address->v4.as_inaddr;
+ if (is_interest)
+ h->v4.ip.saddr.as_inaddr = address->v4.as_inaddr;
+ else
+ h->v4.ip.daddr.as_inaddr = address->v4.as_inaddr;
}
else
{
@@ -376,79 +376,78 @@ hicn_packet_set_locator (hicn_format_t format, hicn_header_t * h,
}
int
-hicn_packet_get_signature_size (hicn_format_t format, const hicn_header_t * h,
- size_t * bytes)
+hicn_packet_get_signature_size (hicn_format_t format, const hicn_header_t *h,
+ size_t *bytes)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->get_signature_size (type, &h->protocol,
- bytes);
+ return hicn_ops_vft[type.l1]->get_signature_size (type, &h->protocol, bytes);
}
int
-hicn_packet_set_signature_size (hicn_format_t format, hicn_header_t * h,
+hicn_packet_set_signature_size (hicn_format_t format, hicn_header_t *h,
size_t bytes)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->set_signature_size (type, &h->protocol,
- bytes);
+ return hicn_ops_vft[type.l1]->set_signature_size (type, &h->protocol, bytes);
}
int
-hicn_packet_set_signature_timestamp (hicn_format_t format, hicn_header_t * h,
- uint64_t signature_timestamp)
+hicn_packet_set_signature_timestamp (hicn_format_t format, hicn_header_t *h,
+ uint64_t signature_timestamp)
{
hicn_type_t type = hicn_format_to_type (format);
return hicn_ops_vft[type.l1]->set_signature_timestamp (type, &h->protocol,
- signature_timestamp);
+ signature_timestamp);
}
int
-hicn_packet_get_signature_timestamp (hicn_format_t format, const hicn_header_t * h,
- uint64_t *signature_timestamp)
+hicn_packet_get_signature_timestamp (hicn_format_t format,
+ const hicn_header_t *h,
+ uint64_t *signature_timestamp)
{
hicn_type_t type = hicn_format_to_type (format);
return hicn_ops_vft[type.l1]->get_signature_timestamp (type, &h->protocol,
- signature_timestamp);
+ signature_timestamp);
}
int
-hicn_packet_set_validation_algorithm (hicn_format_t format, hicn_header_t * h,
- uint8_t validation_algorithm)
+hicn_packet_set_validation_algorithm (hicn_format_t format, hicn_header_t *h,
+ uint8_t validation_algorithm)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->set_validation_algorithm (type, &h->protocol,
- validation_algorithm);
+ return hicn_ops_vft[type.l1]->set_validation_algorithm (
+ type, &h->protocol, validation_algorithm);
}
int
-hicn_packet_get_validation_algorithm (hicn_format_t format, const hicn_header_t * h,
- uint8_t * validation_algorithm)
+hicn_packet_get_validation_algorithm (hicn_format_t format,
+ const hicn_header_t *h,
+ uint8_t *validation_algorithm)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->get_validation_algorithm (type, &h->protocol,
- validation_algorithm);
+ return hicn_ops_vft[type.l1]->get_validation_algorithm (
+ type, &h->protocol, validation_algorithm);
}
int
-hicn_packet_set_key_id (hicn_format_t format, hicn_header_t * h,
- uint8_t *key_id)
+hicn_packet_set_key_id (hicn_format_t format, hicn_header_t *h,
+ uint8_t *key_id)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->set_key_id (type, &h->protocol,
- key_id);
+ return hicn_ops_vft[type.l1]->set_key_id (type, &h->protocol, key_id);
}
int
-hicn_packet_get_key_id (hicn_format_t format, hicn_header_t * h,
- uint8_t ** key_id, uint8_t *key_id_length)
+hicn_packet_get_key_id (hicn_format_t format, hicn_header_t *h,
+ uint8_t **key_id, uint8_t *key_id_length)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->get_key_id (type, &h->protocol,
- key_id, key_id_length);
+ return hicn_ops_vft[type.l1]->get_key_id (type, &h->protocol, key_id,
+ key_id_length);
}
int
-hicn_packet_get_hoplimit (const hicn_header_t * h, u8 * hops)
+hicn_packet_get_hoplimit (const hicn_header_t *h, u8 *hops)
{
switch (HICN_IP_VERSION (h))
{
@@ -466,7 +465,7 @@ hicn_packet_get_hoplimit (const hicn_header_t * h, u8 * hops)
}
int
-hicn_packet_set_hoplimit (hicn_header_t * h, u8 hops)
+hicn_packet_set_hoplimit (hicn_header_t *h, u8 hops)
{
switch (HICN_IP_VERSION (h))
{
@@ -483,9 +482,8 @@ hicn_packet_set_hoplimit (hicn_header_t * h, u8 hops)
return HICN_LIB_ERROR_NONE;
}
-
int
-hicn_packet_get_lifetime (const hicn_header_t * h, u32 * lifetime)
+hicn_packet_get_lifetime (const hicn_header_t *h, u32 *lifetime)
{
hicn_type_t type = hicn_header_to_type (h);
return hicn_ops_vft[type.l1]->get_lifetime (type, &h->protocol,
@@ -493,7 +491,7 @@ hicn_packet_get_lifetime (const hicn_header_t * h, u32 * lifetime)
}
int
-hicn_packet_set_lifetime (hicn_header_t * h, u32 lifetime)
+hicn_packet_set_lifetime (hicn_header_t *h, u32 lifetime)
{
hicn_type_t type = hicn_header_to_type (h);
return hicn_ops_vft[type.l1]->set_lifetime (type, &h->protocol,
@@ -501,15 +499,15 @@ hicn_packet_set_lifetime (hicn_header_t * h, u32 lifetime)
}
int
-hicn_packet_get_reserved_bits (const hicn_header_t * h, u8 * reserved_bits)
+hicn_packet_get_reserved_bits (const hicn_header_t *h, u8 *reserved_bits)
{
switch (HICN_IP_VERSION (h))
{
case 6:
- *reserved_bits = (u8)(h->v6.tcp.reserved);
+ *reserved_bits = (u8) (h->v6.tcp.reserved);
break;
case 4:
- *reserved_bits = (u8)(h->v4.tcp.reserved);
+ *reserved_bits = (u8) (h->v4.tcp.reserved);
break;
default:
return HICN_LIB_ERROR_UNEXPECTED;
@@ -519,7 +517,7 @@ hicn_packet_get_reserved_bits (const hicn_header_t * h, u8 * reserved_bits)
}
int
-hicn_packet_set_reserved_bits (hicn_header_t * h, const u8 reserved_bits)
+hicn_packet_set_reserved_bits (hicn_header_t *h, const u8 reserved_bits)
{
switch (HICN_IP_VERSION (h))
{
@@ -537,16 +535,18 @@ hicn_packet_set_reserved_bits (hicn_header_t * h, const u8 reserved_bits)
}
int
-hicn_packet_get_payload_type (const hicn_header_t * h,
- hicn_payload_type_t * payload_type)
+hicn_packet_get_payload_type (const hicn_header_t *h,
+ hicn_payload_type_t *payload_type)
{
switch (HICN_IP_VERSION (h))
{
case 6:
- *payload_type = ((h->v6.tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG);
+ *payload_type =
+ ((h->v6.tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG);
break;
case 4:
- *payload_type = ((h->v4.tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG);
+ *payload_type =
+ ((h->v4.tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG);
break;
default:
return HICN_LIB_ERROR_UNEXPECTED;
@@ -561,7 +561,7 @@ hicn_packet_get_payload_type (const hicn_header_t * h,
}
int
-hicn_packet_set_payload_type (hicn_header_t * h,
+hicn_packet_set_payload_type (hicn_header_t *h,
hicn_payload_type_t payload_type)
{
if (payload_type != HPT_DATA && payload_type != HPT_MANIFEST)
@@ -591,8 +591,13 @@ hicn_packet_set_payload_type (hicn_header_t * h,
}
int
-hicn_packet_set_syn (hicn_header_t * h)
+hicn_packet_set_syn (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -608,8 +613,13 @@ hicn_packet_set_syn (hicn_header_t * h)
}
int
-hicn_packet_reset_syn (hicn_header_t * h)
+hicn_packet_reset_syn (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -625,8 +635,13 @@ hicn_packet_reset_syn (hicn_header_t * h)
}
int
-hicn_packet_test_syn (const hicn_header_t * h, bool * flag)
+hicn_packet_test_syn (hicn_format_t format, const hicn_header_t *h, bool *flag)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -642,8 +657,13 @@ hicn_packet_test_syn (const hicn_header_t * h, bool * flag)
}
int
-hicn_packet_set_ack (hicn_header_t * h)
+hicn_packet_set_ack (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -659,8 +679,13 @@ hicn_packet_set_ack (hicn_header_t * h)
}
int
-hicn_packet_reset_ack (hicn_header_t * h)
+hicn_packet_reset_ack (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -676,8 +701,13 @@ hicn_packet_reset_ack (hicn_header_t * h)
}
int
-hicn_packet_test_ack (const hicn_header_t * h, bool * flag)
+hicn_packet_test_ack (hicn_format_t format, const hicn_header_t *h, bool *flag)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -693,8 +723,13 @@ hicn_packet_test_ack (const hicn_header_t * h, bool * flag)
}
int
-hicn_packet_set_rst (hicn_header_t * h)
+hicn_packet_set_rst (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -710,8 +745,13 @@ hicn_packet_set_rst (hicn_header_t * h)
}
int
-hicn_packet_reset_rst (hicn_header_t * h)
+hicn_packet_reset_rst (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -727,8 +767,13 @@ hicn_packet_reset_rst (hicn_header_t * h)
}
int
-hicn_packet_test_rst (const hicn_header_t * h, bool * flag)
+hicn_packet_test_rst (hicn_format_t format, const hicn_header_t *h, bool *flag)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -744,8 +789,13 @@ hicn_packet_test_rst (const hicn_header_t * h, bool * flag)
}
int
-hicn_packet_set_fin (hicn_header_t * h)
+hicn_packet_set_fin (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -761,8 +811,13 @@ hicn_packet_set_fin (hicn_header_t * h)
}
int
-hicn_packet_reset_fin (hicn_header_t * h)
+hicn_packet_reset_fin (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -778,8 +833,13 @@ hicn_packet_reset_fin (hicn_header_t * h)
}
int
-hicn_packet_test_fin (const hicn_header_t * h, bool * flag)
+hicn_packet_test_fin (hicn_format_t format, const hicn_header_t *h, bool *flag)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -795,8 +855,13 @@ hicn_packet_test_fin (const hicn_header_t * h, bool * flag)
}
int
-hicn_packet_set_ece (hicn_header_t * h)
+hicn_packet_set_ece (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -812,8 +877,13 @@ hicn_packet_set_ece (hicn_header_t * h)
}
int
-hicn_packet_reset_ece (hicn_header_t * h)
+hicn_packet_reset_ece (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -829,8 +899,13 @@ hicn_packet_reset_ece (hicn_header_t * h)
}
int
-hicn_packet_test_ece (const hicn_header_t * h, bool * flag)
+hicn_packet_test_ece (hicn_format_t format, const hicn_header_t *h, bool *flag)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -846,8 +921,13 @@ hicn_packet_test_ece (const hicn_header_t * h, bool * flag)
}
int
-hicn_packet_set_src_port (hicn_header_t * h, u16 src_port)
+hicn_packet_set_src_port (hicn_format_t format, hicn_header_t *h, u16 src_port)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -863,8 +943,14 @@ hicn_packet_set_src_port (hicn_header_t * h, u16 src_port)
}
int
-hicn_packet_get_src_port (const hicn_header_t * h, u16 * src_port)
+hicn_packet_get_src_port (hicn_format_t format, const hicn_header_t *h,
+ u16 *src_port)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -880,8 +966,13 @@ hicn_packet_get_src_port (const hicn_header_t * h, u16 * src_port)
}
int
-hicn_packet_set_dst_port (hicn_header_t * h, u16 dst_port)
+hicn_packet_set_dst_port (hicn_format_t format, hicn_header_t *h, u16 dst_port)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -897,8 +988,14 @@ hicn_packet_set_dst_port (hicn_header_t * h, u16 dst_port)
}
int
-hicn_packet_get_dst_port (const hicn_header_t * h, u16 * dst_port)
+hicn_packet_get_dst_port (hicn_format_t format, const hicn_header_t *h,
+ u16 *dst_port)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -914,8 +1011,8 @@ hicn_packet_get_dst_port (const hicn_header_t * h, u16 * dst_port)
}
int
-hicn_packet_copy_header (hicn_format_t format, const hicn_header_t * packet,
- hicn_header_t * destination, bool copy_ah)
+hicn_packet_copy_header (hicn_format_t format, const hicn_header_t *packet,
+ hicn_header_t *destination, bool copy_ah)
{
size_t header_length = _is_ipv4 (format) * IPV4_HDRLEN;
header_length += _is_ipv6 (format) * IPV6_HDRLEN;
@@ -929,95 +1026,95 @@ hicn_packet_copy_header (hicn_format_t format, const hicn_header_t * packet,
}
#define _INTEREST 1
-#define _DATA 0
+#define _DATA 0
/* Interest */
int
-hicn_interest_get_name (hicn_format_t format, const hicn_header_t * interest,
- hicn_name_t * name)
+hicn_interest_get_name (hicn_format_t format, const hicn_header_t *interest,
+ hicn_name_t *name)
{
return hicn_packet_get_name (format, interest, name, _INTEREST);
}
int
-hicn_interest_set_name (hicn_format_t format, hicn_header_t * interest,
- const hicn_name_t * name)
+hicn_interest_set_name (hicn_format_t format, hicn_header_t *interest,
+ const hicn_name_t *name)
{
- int ret_err = hicn_packet_reset_ece (interest); //interest packet -> ece flag unset
+ int ret_err =
+ hicn_packet_reset_ece (format, interest); // interest packet -> ece flag unset
if (ret_err < 0)
return HICN_LIB_ERROR_UNEXPECTED;
return hicn_packet_set_name (format, interest, name, _INTEREST);
}
int
-hicn_interest_get_locator (hicn_format_t format,
- const hicn_header_t * interest,
- ip_address_t * address)
+hicn_interest_get_locator (hicn_format_t format, const hicn_header_t *interest,
+ ip_address_t *address)
{
return hicn_packet_get_locator (format, interest, address, _INTEREST);
}
int
-hicn_interest_set_locator (hicn_format_t format, hicn_header_t * interest,
- const ip_address_t * address)
+hicn_interest_set_locator (hicn_format_t format, hicn_header_t *interest,
+ const ip_address_t *address)
{
return hicn_packet_set_locator (format, interest, address, _INTEREST);
}
int
-hicn_interest_compare (const hicn_header_t * interest_1,
- const hicn_header_t * interest_2)
+hicn_interest_compare (const hicn_header_t *interest_1,
+ const hicn_header_t *interest_2)
{
return hicn_packet_compare (interest_1, interest_2);
}
int
-hicn_interest_get_lifetime (const hicn_header_t * interest, u32 * lifetime)
+hicn_interest_get_lifetime (const hicn_header_t *interest, u32 *lifetime)
{
return hicn_packet_get_lifetime (interest, lifetime);
}
int
-hicn_interest_set_lifetime (hicn_header_t * interest, u32 lifetime)
+hicn_interest_set_lifetime (hicn_header_t *interest, u32 lifetime)
{
return hicn_packet_set_lifetime (interest, lifetime);
}
int
hicn_interest_get_header_length (hicn_format_t format,
- const hicn_header_t * interest,
- size_t * header_length)
+ const hicn_header_t *interest,
+ size_t *header_length)
{
return hicn_packet_get_header_length (format, interest, header_length);
}
int
hicn_interest_get_payload_length (hicn_format_t format,
- const hicn_header_t * interest,
- size_t * payload_length)
+ const hicn_header_t *interest,
+ size_t *payload_length)
{
return hicn_packet_get_payload_length (format, interest, payload_length);
}
int
-hicn_interest_get_payload (hicn_format_t format,
- const hicn_header_t * interest, u8 ** payload,
- size_t * payload_size, bool hard_copy)
+hicn_interest_get_payload (hicn_format_t format, const hicn_header_t *interest,
+ u8 **payload, size_t *payload_size, bool hard_copy)
{
return hicn_packet_get_payload (format, interest, payload, payload_size,
hard_copy);
}
int
-hicn_interest_set_payload (hicn_format_t format, hicn_header_t * interest,
- const u8 * payload, size_t payload_length)
+hicn_interest_set_payload (hicn_format_t format, hicn_header_t *interest,
+ const u8 *payload, size_t payload_length)
{
- return hicn_packet_set_payload (format, interest, payload, (u16)payload_length);
+ return hicn_packet_set_payload (format, interest, payload,
+ (u16) payload_length);
}
int
-hicn_interest_reset_for_hash (hicn_format_t format, hicn_header_t * packet)
+hicn_interest_reset_for_hash (hicn_format_t format, hicn_header_t *packet)
{
hicn_type_t type = hicn_format_to_type (format);
return hicn_ops_vft[type.l1]->reset_interest_for_hash (type,
@@ -1027,85 +1124,84 @@ hicn_interest_reset_for_hash (hicn_format_t format, hicn_header_t * packet)
/* Data */
int
-hicn_data_get_name (hicn_format_t format, const hicn_header_t * data,
- hicn_name_t * name)
+hicn_data_get_name (hicn_format_t format, const hicn_header_t *data,
+ hicn_name_t *name)
{
return hicn_packet_get_name (format, data, name, _DATA);
}
int
-hicn_data_set_name (hicn_format_t format, hicn_header_t * data,
- const hicn_name_t * name)
+hicn_data_set_name (hicn_format_t format, hicn_header_t *data,
+ const hicn_name_t *name)
{
- int ret_err = hicn_packet_set_ece (data); //data packet -> ece flag set
+ int ret_err = hicn_packet_set_ece (format, data); // data packet -> ece flag set
if (ret_err < 0)
return HICN_LIB_ERROR_UNEXPECTED;
return hicn_packet_set_name (format, data, name, _DATA);
}
int
-hicn_data_get_locator (hicn_format_t format, const hicn_header_t * data,
- ip_address_t * address)
+hicn_data_get_locator (hicn_format_t format, const hicn_header_t *data,
+ ip_address_t *address)
{
return hicn_packet_get_locator (format, data, address, _DATA);
}
int
-hicn_data_set_locator (hicn_format_t format, hicn_header_t * data,
- const ip_address_t * address)
+hicn_data_set_locator (hicn_format_t format, hicn_header_t *data,
+ const ip_address_t *address)
{
return hicn_packet_set_locator (format, data, address, _DATA);
}
int
-hicn_data_compare (const hicn_header_t * data_1, const hicn_header_t * data_2)
+hicn_data_compare (const hicn_header_t *data_1, const hicn_header_t *data_2)
{
return hicn_packet_compare (data_1, data_2);
}
int
-hicn_data_get_expiry_time (const hicn_header_t * data, u32 * expiry_time)
+hicn_data_get_expiry_time (const hicn_header_t *data, u32 *expiry_time)
{
return hicn_packet_get_lifetime (data, expiry_time);
}
int
-hicn_data_set_expiry_time (hicn_header_t * data, u32 expiry_time)
+hicn_data_set_expiry_time (hicn_header_t *data, u32 expiry_time)
{
return hicn_packet_set_lifetime (data, (hicn_lifetime_t) expiry_time);
}
int
-hicn_data_get_header_length (hicn_format_t format, hicn_header_t * data,
- size_t * header_length)
+hicn_data_get_header_length (hicn_format_t format, hicn_header_t *data,
+ size_t *header_length)
{
return hicn_packet_get_header_length (format, data, header_length);
}
int
-hicn_data_get_payload_length (hicn_format_t format,
- const hicn_header_t * data,
- size_t * payload_length)
+hicn_data_get_payload_length (hicn_format_t format, const hicn_header_t *data,
+ size_t *payload_length)
{
return hicn_packet_get_payload_length (format, data, payload_length);
}
int
-hicn_data_set_payload_type (hicn_header_t * data,
+hicn_data_set_payload_type (hicn_header_t *data,
hicn_payload_type_t payload_type)
{
return hicn_packet_set_payload_type (data, payload_type);
}
int
-hicn_data_get_payload_type (const hicn_header_t * data,
- hicn_payload_type_t * payload_type)
+hicn_data_get_payload_type (const hicn_header_t *data,
+ hicn_payload_type_t *payload_type)
{
return hicn_packet_get_payload_type (data, payload_type);
}
int
-hicn_data_get_path_label (const hicn_header_t * data, u32 * path_label)
+hicn_data_get_path_label (const hicn_header_t *data, u32 *path_label)
{
hicn_type_t type = hicn_header_to_type (data);
return hicn_ops_vft[type.l1]->get_data_pathlabel (type, &data->protocol,
@@ -1113,7 +1209,7 @@ hicn_data_get_path_label (const hicn_header_t * data, u32 * path_label)
}
int
-hicn_data_set_path_label (hicn_header_t * data, u32 path_label)
+hicn_data_set_path_label (hicn_header_t *data, u32 path_label)
{
hicn_type_t type = hicn_header_to_type (data);
return hicn_ops_vft[type.l1]->set_data_pathlabel (type, &data->protocol,
@@ -1121,34 +1217,34 @@ hicn_data_set_path_label (hicn_header_t * data, u32 path_label)
}
int
-hicn_data_set_payload (hicn_format_t format, hicn_header_t * data,
- const u8 * payload, size_t payload_length)
+hicn_data_set_payload (hicn_format_t format, hicn_header_t *data,
+ const u8 *payload, size_t payload_length)
{
- return hicn_packet_set_payload (format, data, payload, (u16)payload_length);
+ return hicn_packet_set_payload (format, data, payload, (u16) payload_length);
}
int
-hicn_data_get_payload (hicn_format_t format, const hicn_header_t * data,
- u8 ** payload, size_t * payload_size, bool hard_copy)
+hicn_data_get_payload (hicn_format_t format, const hicn_header_t *data,
+ u8 **payload, size_t *payload_size, bool hard_copy)
{
return hicn_packet_get_payload (format, data, payload, payload_size,
hard_copy);
}
int
-hicn_data_reset_for_hash (hicn_format_t format, hicn_header_t * packet)
+hicn_data_reset_for_hash (hicn_format_t format, hicn_header_t *packet)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->reset_data_for_hash (type,
- &packet->protocol);
-
+ return hicn_ops_vft[type.l1]->reset_data_for_hash (type, &packet->protocol);
}
-int hicn_packet_get_signature(hicn_format_t format, hicn_header_t * packet, uint8_t ** sign_buf)
+int
+hicn_packet_get_signature (hicn_format_t format, hicn_header_t *packet,
+ uint8_t **sign_buf)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->get_signature (type,
- &packet->protocol, sign_buf);
+ return hicn_ops_vft[type.l1]->get_signature (type, &packet->protocol,
+ sign_buf);
}
/*
diff --git a/lib/src/name.c b/lib/src/name.c
index 9388c35e7..54b2a76aa 100644
--- a/lib/src/name.c
+++ b/lib/src/name.c
@@ -242,7 +242,7 @@ hicn_name_hash (const hicn_name_t * name, u32 * hash, bool consider_suffix)
int
hicn_name_empty (hicn_name_t * name)
{
- return name->type == HNT_UNSPEC ? HICN_LIB_ERROR_NONE : 1;
+ return name->type == HNT_UNSPEC ? 1 : 0;
}
int
diff --git a/lib/src/ops.c b/lib/src/ops.c
index 9bb78be65..d49138398 100644
--- a/lib/src/ops.c
+++ b/lib/src/ops.c
@@ -40,6 +40,8 @@ DECLARE_get_interest_name (none, NONE);
DECLARE_set_interest_name (none, NONE);
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_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 c2f3f552a..03f3af04a 100644
--- a/lib/src/protocol/ah.c
+++ b/lib/src/protocol/ah.c
@@ -31,6 +31,8 @@ DECLARE_get_interest_name (ah, UNEXPECTED);
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_get_data_locator (ah, UNEXPECTED);
DECLARE_set_data_locator (ah, UNEXPECTED);
DECLARE_get_data_name (ah, UNEXPECTED);
@@ -111,7 +113,7 @@ ah_rewrite_interest (hicn_type_t type, hicn_protocol_t * h,
int
ah_rewrite_data (hicn_type_t type, hicn_protocol_t * h,
const ip46_address_t * addr_new, ip46_address_t * addr_old,
- const hicn_faceid_t face_id)
+ const hicn_faceid_t face_id, u8 reset_pl)
{
/* Nothing to do on signature */
return HICN_LIB_ERROR_NONE;
diff --git a/lib/src/protocol/icmp.c b/lib/src/protocol/icmp.c
index 85605a2c3..a16353427 100644
--- a/lib/src/protocol/icmp.c
+++ b/lib/src/protocol/icmp.c
@@ -25,6 +25,8 @@ DECLARE_get_interest_name (icmp, UNEXPECTED)
DECLARE_set_interest_name (icmp, UNEXPECTED)
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_get_data_locator (icmp, UNEXPECTED)
DECLARE_set_data_locator (icmp, UNEXPECTED)
DECLARE_get_data_name (icmp, UNEXPECTED)
@@ -116,7 +118,7 @@ icmp_rewrite_interest (hicn_type_t type, hicn_protocol_t * h,
int
icmp_rewrite_data (hicn_type_t type, hicn_protocol_t * h,
const ip46_address_t * addr_new, ip46_address_t * addr_old,
- const hicn_faceid_t face_id)
+ const hicn_faceid_t face_id, u8 reset_pl)
{
return HICN_LIB_ERROR_NOT_IMPLEMENTED;
// u16 *icmp_checksum = &(h->icmp.csum);
diff --git a/lib/src/protocol/ipv4.c b/lib/src/protocol/ipv4.c
index d8d958350..73ce12ee0 100644
--- a/lib/src/protocol/ipv4.c
+++ b/lib/src/protocol/ipv4.c
@@ -109,6 +109,18 @@ ipv4_set_interest_name_suffix (hicn_type_t type, hicn_protocol_t * h,
}
int
+ipv4_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t * h)
+{
+ return CHILD_OPS (mark_packet_as_interest, type, h);
+}
+
+int
+ipv4_mark_packet_as_data (hicn_type_t type, hicn_protocol_t * h)
+{
+ return CHILD_OPS (mark_packet_as_data, type, h);
+}
+
+int
ipv4_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t * h)
{
/* Sets everything to 0 up to IP destination address */
@@ -312,7 +324,7 @@ ipv4_rewrite_interest (hicn_type_t type, hicn_protocol_t * h,
int
ipv4_rewrite_data (hicn_type_t type, hicn_protocol_t * h,
const ip46_address_t * addr_new, ip46_address_t * addr_old,
- const hicn_faceid_t face_id)
+ const hicn_faceid_t face_id, u8 reset_pl)
{
// ASSERT(addr_old == NULL);
addr_old->ip4 = h->ipv4.daddr;
@@ -324,7 +336,7 @@ ipv4_rewrite_data (hicn_type_t type, hicn_protocol_t * h,
h->ipv4.csum = 0;
h->ipv4.csum = csum (&h->ipv4, IPV4_HDRLEN, 0);
- return CHILD_OPS (rewrite_data, type, h, addr_new, addr_old, face_id);
+ return CHILD_OPS (rewrite_data, type, h, addr_new, addr_old, face_id, reset_pl);
}
int
diff --git a/lib/src/protocol/ipv6.c b/lib/src/protocol/ipv6.c
index 622355294..bf8123497 100644
--- a/lib/src/protocol/ipv6.c
+++ b/lib/src/protocol/ipv6.c
@@ -99,6 +99,18 @@ ipv6_set_interest_name_suffix (hicn_type_t type, hicn_protocol_t * h,
}
int
+ipv6_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t * h)
+{
+ return CHILD_OPS (mark_packet_as_interest, type, h);
+}
+
+int
+ipv6_mark_packet_as_data (hicn_type_t type, hicn_protocol_t * h)
+{
+ return CHILD_OPS (mark_packet_as_data, type, h);
+}
+
+int
ipv6_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t * h)
{
/* Sets everything to 0 up to IP destination address */
@@ -208,19 +220,13 @@ ipv6_update_checksums (hicn_type_t type, hicn_protocol_t * h,
u16 partial_csum, size_t payload_length)
{
/* Retrieve payload length if not specified */
- if (payload_length == 0)
+ if (payload_length == ~0)
{
int rc = ipv6_get_payload_length (type, h, &payload_length);
if (rc < 0)
return rc;
}
- /* Ignore the payload if payload_length = ~0 */
- if (payload_length == ~0)
- {
- payload_length = 0;
- }
-
/* Build pseudo-header */
ipv6_pseudo_header_t psh;
psh.ip_src = h->ipv6.saddr;
@@ -246,7 +252,7 @@ ipv6_verify_checksums (hicn_type_t type, hicn_protocol_t * h,
u16 partial_csum, size_t payload_length)
{
/* Retrieve payload length if not specified */
- if (payload_length == 0)
+ if (payload_length == ~0)
{
int rc = ipv6_get_payload_length (type, h, &payload_length);
if (rc < 0)
@@ -264,7 +270,11 @@ ipv6_verify_checksums (hicn_type_t type, hicn_protocol_t * h,
pseudo.protocol = h->ipv6.nxt;
/* Compute partial checksum based on pseudo-header */
- partial_csum = csum (&pseudo, IPV6_PSHDRLEN, 0);
+ if (partial_csum != 0)
+ {
+ partial_csum = ~partial_csum;
+ }
+ partial_csum = csum (&pseudo, IPV6_PSHDRLEN, partial_csum);
return CHILD_OPS (verify_checksums, type, h, partial_csum, payload_length);
}
@@ -284,13 +294,13 @@ ipv6_rewrite_interest (hicn_type_t type, hicn_protocol_t * h,
int
ipv6_rewrite_data (hicn_type_t type, hicn_protocol_t * h,
const ip46_address_t * addr_new, ip46_address_t * addr_old,
- const hicn_faceid_t face_id)
+ const hicn_faceid_t face_id, u8 reset_pl)
{
// ASSERT(addr_old == NULL);
addr_old->ip6 = h->ipv6.daddr;
h->ipv6.daddr = addr_new->ip6;
- return CHILD_OPS (rewrite_data, type, h, addr_new, addr_old, face_id);
+ return CHILD_OPS (rewrite_data, type, h, addr_new, addr_old, face_id, reset_pl);
}
int
diff --git a/lib/src/protocol/tcp.c b/lib/src/protocol/tcp.c
index 0e3155020..95f93c6af 100644
--- a/lib/src/protocol/tcp.c
+++ b/lib/src/protocol/tcp.c
@@ -45,18 +45,45 @@ DECLARE_get_length (tcp, UNEXPECTED);
DECLARE_get_payload_length (tcp, UNEXPECTED);
DECLARE_set_payload_length (tcp, UNEXPECTED);
+always_inline int
+check_tcp_checksum(u16 csum)
+{
+ /* As per RFC1624
+ * In one's complement, there are two representations of zero: the all
+ * zero and the all one bit values, often referred to as +0 and -0.
+ * One's complement addition of non-zero inputs can produce -0 as a
+ * result, but never +0. Since there is guaranteed to be at least one
+ * non-zero field in the IP header, and the checksum field in the
+ * protocol header is the complement of the sum, the checksum field can
+ * never contain ~(+0), which is -0 (0xFFFF). It can, however, contain
+ * ~(-0), which is +0 (0x0000).
+ */
+ if (csum == 0xffff)
+ {
+ /* Invalid checksum, no need to compute incremental update */
+ return HICN_LIB_ERROR_REWRITE_CKSUM_REQUIRED;
+ }
+
+ return HICN_LIB_ERROR_NONE;
+}
+
int
tcp_init_packet_header (hicn_type_t type, hicn_protocol_t * h)
{
- h->tcp = (_tcp_header_t)
- {
- .sport = htons (TCP_DEFAULT_SRC_PORT),.dport =
- htons (TCP_DEFAULT_DST_PORT),.seq = 0,.seq_ack =
- 0,.data_offset_and_reserved = TCP_DEFAULT_DATA_OFFSET_RES,.flags =
+ h->tcp = (_tcp_header_t) {
+ .sport = htons (TCP_DEFAULT_SRC_PORT),
+ .dport = htons (TCP_DEFAULT_DST_PORT),
+ .seq = 0,
+ .seq_ack = 0,
+ .data_offset_and_reserved = TCP_DEFAULT_DATA_OFFSET_RES,
+ .flags =
TCP_DEFAULT_CWR << 7 | TCP_DEFAULT_ECE << 6 | TCP_DEFAULT_URG << 5 |
TCP_DEFAULT_ACK << 4 | TCP_DEFAULT_PSH << 3 | TCP_DEFAULT_RST << 2 |
- TCP_DEFAULT_SYN << 1 | TCP_DEFAULT_FIN << 0,.window =
- htons (TCP_DEFAULT_WINDOW_SIZE),.csum = 0,.urg_ptr = 65000,};
+ TCP_DEFAULT_SYN << 1 | TCP_DEFAULT_FIN << 0,
+ .window = htons (TCP_DEFAULT_WINDOW_SIZE),
+ .csum = 0xffff,
+ .urg_ptr = 65000,
+ };
uint8_t ah_flag = type.l2 == IPPROTO_AH ? AH_FLAG : 0;
@@ -83,6 +110,20 @@ tcp_set_interest_name_suffix (hicn_type_t type, hicn_protocol_t * h,
}
int
+tcp_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t * h)
+{
+ h->tcp.flags &= ~HICN_TCP_FLAG_ECE;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+tcp_mark_packet_as_data (hicn_type_t type, hicn_protocol_t * h)
+{
+ 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);
@@ -129,12 +170,12 @@ tcp_update_data_pathlabel (hicn_type_t type, hicn_protocol_t * h,
const hicn_faceid_t face_id)
{
hicn_pathlabel_t pl =
- (hicn_pathlabel_t) ((h->tcp.pathlabel & HICN_PATH_LABEL_MASK) >> (32 -
- HICN_PATH_LABEL_SIZE));
+ (hicn_pathlabel_t) (h->tcp.seq_ack >> (32 - HICN_PATH_LABEL_SIZE));
+
hicn_pathlabel_t new_pl;
update_pathlabel (pl, face_id, &new_pl);
- h->tcp.pathlabel = new_pl;
+ h->tcp.seq_ack = (new_pl << (32 - HICN_PATH_LABEL_SIZE));
return HICN_LIB_ERROR_NONE;
}
@@ -208,7 +249,12 @@ int
tcp_verify_checksums (hicn_type_t type, hicn_protocol_t * h, u16 partial_csum,
size_t payload_length)
{
- if (csum (h, TCP_HDRLEN + payload_length, ~partial_csum) != 0)
+ if (PREDICT_TRUE (partial_csum != 0))
+ {
+ partial_csum = ~partial_csum;
+ }
+
+ if (csum (h, TCP_HDRLEN + payload_length, partial_csum) != 0)
return HICN_LIB_ERROR_CORRUPTED_PACKET;
return CHILD_OPS (verify_checksums, type, h, 0, payload_length);
}
@@ -238,6 +284,12 @@ tcp_rewrite_interest (hicn_type_t type, hicn_protocol_t * h,
ip46_address_t * addr_old)
{
u16 *tcp_checksum = &(h->tcp.csum);
+ int ret = check_tcp_checksum(*tcp_checksum);
+
+ if (ret)
+ {
+ return ret;
+ }
/*
* Padding fields are set to zero so we can apply checksum on the
@@ -260,9 +312,23 @@ tcp_rewrite_interest (hicn_type_t type, hicn_protocol_t * h,
int
tcp_rewrite_data (hicn_type_t type, hicn_protocol_t * h,
const ip46_address_t * addr_new, ip46_address_t * addr_old,
- const hicn_faceid_t face_id)
+ const hicn_faceid_t face_id, u8 reset_pl)
{
+
u16 *tcp_checksum = &(h->tcp.csum);
+ int ret = check_tcp_checksum(*tcp_checksum);
+
+ /*
+ * update path label
+ */
+ u16 old_pl = h->tcp.seq_ack;
+ if(reset_pl) h->tcp.seq_ack = 0;
+ tcp_update_data_pathlabel (type, h, face_id);
+
+ if (ret)
+ {
+ return ret;
+ }
/*
* Padding fields are set to zero so we can apply checksum on the
@@ -277,9 +343,8 @@ tcp_rewrite_data (hicn_type_t type, hicn_protocol_t * h,
csum = ip_csum_add_even (csum, (ip_csum_t) (addr_new->ip6.as_u64[0]));
csum = ip_csum_add_even (csum, (ip_csum_t) (addr_new->ip6.as_u64[1]));
- csum = ip_csum_sub_even (csum, h->tcp.pathlabel);
- tcp_update_data_pathlabel (type, h, face_id);
- csum = ip_csum_add_even (csum, h->tcp.pathlabel);
+ csum = ip_csum_sub_even (csum, old_pl);
+ csum = ip_csum_add_even (csum, h->tcp.seq_ack);
*tcp_checksum = ip_csum_fold (csum);
diff --git a/lib/src/strategy.c b/lib/src/strategy.c
new file mode 100644
index 000000000..66ab232b5
--- /dev/null
+++ b/lib/src/strategy.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2020 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 strategy.c
+ * \brief Implementation of hICN forwarding strategy
+ */
+
+#include <hicn/core/strategy_vft.h>
+
+#include <hicn/strategies/load_balancer.h>
+#include <hicn/strategies/random.h>
+#include <hicn/strategies/low_latency.h>
+
+extern const strategy_ops_t strategy_load_balancer;
+extern const strategy_ops_t strategy_random;
+extern const strategy_ops_t strategy_low_latency;
+
+const strategy_ops_t * const strategy_vft[] = {
+ [STRATEGY_TYPE_LOADBALANCER] = &strategy_load_balancer,
+ [STRATEGY_TYPE_RANDOM] = &strategy_random,
+#if 0
+ [STRATEGY_TYPE_LOW_LATENCY] = &strategy_low_latency,
+#endif
+};
+
+
diff --git a/lib/src/util/ip_address.c b/lib/src/util/ip_address.c
index d4b34dc0b..1d123d8cd 100644
--- a/lib/src/util/ip_address.c
+++ b/lib/src/util/ip_address.c
@@ -302,7 +302,10 @@ ip_prefix_ntop(const ip_prefix_t * ip_prefix, char *dst, size_t size)
}
if (!s)
return -1;
- return snprintf(dst, size, "%s/%d", ip_s, ip_prefix->len);
+ int rc = snprintf(dst, size, "%s/%d", ip_s, ip_prefix->len);
+ if (rc >= size)
+ return (int)size;
+ return rc;
}
int
diff --git a/lib/src/util/windows/dlfcn.c b/lib/src/util/windows/dlfcn.c
new file mode 100644
index 000000000..c8173cdb0
--- /dev/null
+++ b/lib/src/util/windows/dlfcn.c
@@ -0,0 +1,65 @@
+/* dlfcn.c */
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+
+static struct {
+ long lasterror;
+ const char *err_rutin;
+} var = {
+ 0,
+ NULL
+};
+
+void *dlopen (const char *filename, int flags)
+{
+ HINSTANCE hInst;
+
+ hInst= LoadLibrary (filename);
+ if (hInst==NULL) {
+ var.lasterror = GetLastError ();
+ var.err_rutin = "dlopen";
+ }
+ return hInst;
+}
+
+int dlclose (void *handle)
+{
+ BOOL ok;
+ int rc= 0;
+
+ ok= FreeLibrary ((HINSTANCE)handle);
+ if (! ok) {
+ var.lasterror = GetLastError ();
+ var.err_rutin = "dlclose";
+ rc= -1;
+ }
+ return rc;
+}
+
+void *dlsym (void *handle, const char *name)
+{
+ FARPROC fp;
+
+ fp= GetProcAddress ((HINSTANCE)handle, name);
+ if (!fp) {
+ var.lasterror = GetLastError ();
+ var.err_rutin = "dlsym";
+ }
+ return (void *)(intptr_t)fp;
+}
+
+const char *dlerror (void)
+{
+static char errstr [88];
+
+ if (var.lasterror) {
+ sprintf (errstr, "%s error #%ld", var.err_rutin, var.lasterror);
+ return errstr;
+ } else {
+ return NULL;
+ }
+} \ No newline at end of file