aboutsummaryrefslogtreecommitdiffstats
path: root/lib/includes/hicn
diff options
context:
space:
mode:
Diffstat (limited to 'lib/includes/hicn')
-rw-r--r--lib/includes/hicn/base.h109
-rw-r--r--lib/includes/hicn/common.h125
-rw-r--r--lib/includes/hicn/compat.h84
-rw-r--r--lib/includes/hicn/error.h29
-rw-r--r--lib/includes/hicn/face.h233
-rw-r--r--lib/includes/hicn/header.h65
-rw-r--r--lib/includes/hicn/hicn.h14
-rw-r--r--lib/includes/hicn/mapme.h70
-rw-r--r--lib/includes/hicn/name.h151
-rw-r--r--lib/includes/hicn/ops.h157
-rw-r--r--lib/includes/hicn/policy.h263
-rw-r--r--lib/includes/hicn/protocol.h4
-rw-r--r--lib/includes/hicn/protocol/ah.h16
-rw-r--r--lib/includes/hicn/protocol/icmp.h12
-rw-r--r--lib/includes/hicn/protocol/icmprd.h6
-rw-r--r--lib/includes/hicn/protocol/ipv4.h41
-rw-r--r--lib/includes/hicn/protocol/ipv6.h32
-rw-r--r--lib/includes/hicn/protocol/new.h88
-rw-r--r--lib/includes/hicn/protocol/tcp.h102
-rw-r--r--lib/includes/hicn/protocol/udp.h4
-rw-r--r--lib/includes/hicn/strategy.h63
-rw-r--r--lib/includes/hicn/util/array.h323
-rw-r--r--lib/includes/hicn/util/ip_address.h167
-rw-r--r--lib/includes/hicn/util/log.h62
-rw-r--r--lib/includes/hicn/util/map.h444
-rw-r--r--lib/includes/hicn/util/set.h370
-rw-r--r--lib/includes/hicn/util/sstrncpy.h68
-rw-r--r--lib/includes/hicn/util/token.h8
-rw-r--r--lib/includes/hicn/util/types.h16
-rw-r--r--lib/includes/hicn/util/win_portability.h88
-rw-r--r--lib/includes/hicn/util/windows/dlfcn.h15
-rw-r--r--[-rwxr-xr-x]lib/includes/hicn/util/windows/windows_utils.h326
-rw-r--r--lib/includes/hicn/validation.h55
33 files changed, 2134 insertions, 1476 deletions
diff --git a/lib/includes/hicn/base.h b/lib/includes/hicn/base.h
index 1061724ce..844814d57 100644
--- a/lib/includes/hicn/base.h
+++ b/lib/includes/hicn/base.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -34,16 +34,17 @@ typedef u32 hicn_faceid_t;
typedef u8 hicn_pathlabel_t;
typedef u32 hicn_lifetime_t;
-#define HICN_MAX_LIFETIME_SCALED 0xFFFF
-#define HICN_MAX_LIFETIME_MULTIPLIER 0x0F /* 4 bits */
-#define HICN_MAX_LIFETIME HICN_MAX_LIFETIME_SCALED << HICN_MAX_LIFETIME_MULTIPLIER
+#define HICN_MAX_LIFETIME_SCALED 0xFFFF
+#define HICN_MAX_LIFETIME_MULTIPLIER 0x0F /* 4 bits */
+#define HICN_MAX_LIFETIME \
+ HICN_MAX_LIFETIME_SCALED << HICN_MAX_LIFETIME_MULTIPLIER
/**
* @brief hICN packet format type
*
- * The hICN type represents the sequence of protocols that we can find in packet
- * headers. They are represented as a quartet of u8 values, correponding to
- * IANA protocol assignment, and read from right to left. This is done to
+ * The hICN type represents the sequence of protocols that we can find in
+ * packet headers. They are represented as a quartet of u8 values, correponding
+ * to IANA protocol assignment, and read from right to left. This is done to
* faciliate decapsulation of packet header by simple shift/mask operations.
*
* For instance, an IPv6/TCP packet will be identified as :
@@ -55,19 +56,19 @@ typedef u32 hicn_lifetime_t;
*/
typedef union
{
- /** protocol layers representation */
+ /** protocol layers representation */
struct
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- u8 l1; /**< First layer */
- u8 l2; /**< Second layer */
- u8 l3; /**< Third layer */
- u8 l4; /**< Fourth layer */
+ u8 l1; /**< First layer */
+ u8 l2; /**< Second layer */
+ u8 l3; /**< Third layer */
+ u8 l4; /**< Fourth layer */
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
- u8 l4; /**< Fourth layer */
- u8 l3; /**< Third layer */
- u8 l2; /**< Second layer */
- u8 l1; /**< First layer */
+ u8 l4; /**< Fourth layer */
+ u8 l3; /**< Third layer */
+ u8 l2; /**< Second layer */
+ u8 l1; /**< First layer */
#elif _WIN32 /* Windows is assumed little-endian */
u8 l1;
u8 l2;
@@ -77,46 +78,73 @@ typedef union
#error "Unsupported endianness"
#endif
};
- /** u32 representation */
+ /** u32 representation */
u32 as_u32;
} hicn_type_t;
/* Common protocol layers */
/* Common protocol layers */
#ifndef _WIN32
-#define HICN_TYPE(x,y,z,t) (hicn_type_t) {{ .l1 = x, .l2 = y, .l3 = z, .l4 = t }}
+#define HICN_TYPE(x, y, z, t) \
+ (hicn_type_t) \
+ { \
+ { \
+ .l1 = x, .l2 = y, .l3 = z, .l4 = t \
+ } \
+ }
#else
inline hicn_type_t
-HICN_TYPE(int x, int y, int z, int t)
+HICN_TYPE (int x, int y, int z, int t)
{
- hicn_type_t type;
- type.l1 = x;
- type.l2 = y;
- type.l3 = z;
- type.l4 = t;
- return type;
+ hicn_type_t type;
+ type.l1 = x;
+ type.l2 = y;
+ type.l3 = z;
+ type.l4 = t;
+ return type;
}
#endif
-#define HICN_TYPE_IPV4_TCP HICN_TYPE(IPPROTO_IP, IPPROTO_TCP, 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_ICMP HICN_TYPE(IPPROTO_IPV6, IPPROTO_ICMPV6, 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_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)
+#define HICN_TYPE_IPV4_TCP \
+ HICN_TYPE (IPPROTO_IP, IPPROTO_TCP, 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_ICMP \
+ HICN_TYPE (IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_NONE, IPPROTO_NONE)
+#define HICN_TYPE_NEW \
+ HICN_TYPE (IPPROTO_ENCAP, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE)
+#define HICN_TYPE_IPV4_UDP \
+ HICN_TYPE (IPPROTO_IP, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_NONE)
+#define HICN_TYPE_IPV6_UDP \
+ HICN_TYPE (IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_ENCAP, 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_ICMP_AH \
+ HICN_TYPE (IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_AH, IPPROTO_NONE)
+#define HICN_TYPE_NEW_AH \
+ HICN_TYPE (IPPROTO_ENCAP, IPPROTO_AH, IPPROTO_NONE, IPPROTO_NONE)
+#define HICN_TYPE_IPV6_UDP_AH \
+ HICN_TYPE (IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_AH)
+#define HICN_TYPE_IPV4_UDP_AH \
+ HICN_TYPE (IPPROTO_IP, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_AH)
+#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)
+static 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);
+ (type.l3 == IPPROTO_NONE) && (type.l4 == IPPROTO_NONE);
}
/**
@@ -151,11 +179,12 @@ typedef enum
* @param [in] face_id The face identifier to combine into the path label
* @param [out] new_label Computed pathlabel
*
- * This function updates the current_label based on the new face_id, and returns
+ * This function updates the current_label based on the new face_id, and
+ * returns
*/
-always_inline void
+static inline void
update_pathlabel (hicn_pathlabel_t current_label, hicn_faceid_t face_id,
- hicn_pathlabel_t * new_label)
+ hicn_pathlabel_t *new_label)
{
hicn_pathlabel_t pl_face_id =
(hicn_pathlabel_t) (face_id & HICN_PATH_LABEL_MASK);
diff --git a/lib/includes/hicn/common.h b/lib/includes/hicn/common.h
index 05f8ad95f..b0898ce1f 100644
--- a/lib/includes/hicn/common.h
+++ b/lib/includes/hicn/common.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -51,13 +51,17 @@ typedef uint8_t u8;
#ifndef HICN_VPP_PLUGIN
-#define PREDICT_FALSE(x) (x)
-#define PREDICT_TRUE(x) (x)
-#define always_inline static inline
-#define static_always_inline static inline
-#define STRUCT_SIZE_OF(type, member) sizeof(((type *)0)->member)
+#define PREDICT_FALSE(x) (x)
+#define PREDICT_TRUE(x) (x)
+#define STRUCT_SIZE_OF(type, member) sizeof (((type *) 0)->member)
#define ASSERT
+#ifndef NDEBUG
+#define _ASSERT(x) assert (x)
+#else
+#define _ASSERT(x) ((void) (x))
+#endif
+
#define STATIC_ASSERT(x)
/* Architecture-dependent uword size */
@@ -82,13 +86,17 @@ typedef u32 uword;
typedef uword ip_csum_t;
+#else
+
+#include <vppinfra/clib.h>
+
#endif /* ! HICN_VPP_PLUGIN */
/*
- * Windows compilers do not support named initilizers when .h files are included
- * inside C++ files. For readability, we either use the following macro, or
- * duplicate some code, with the intent of preserving those safeguards for
- * non-Windows platforms.
+ * Windows compilers do not support named initilizers when .h files are
+ * included inside C++ files. For readability, we either use the following
+ * macro, or duplicate some code, with the intent of preserving those
+ * safeguards for non-Windows platforms.
*/
#ifndef _WIN32
#define ATTR_INIT(key, value) .key = value
@@ -97,12 +105,12 @@ typedef uword ip_csum_t;
#endif
#ifdef _WIN32
- /* Endianness detection for Windows platforms */
+/* Endianness detection for Windows platforms */
#define __ORDER_LITTLE_ENDIAN__ 0x41424344UL
-#define __ORDER_BIG_ENDIAN__ 0x44434241UL
-#define __BYTE_ORDER__ ('ABCD')
+#define __ORDER_BIG_ENDIAN__ 0x44434241UL
+#define __BYTE_ORDER__ ('ABCD')
- /* Windows compatibility headers */
+/* Windows compatibility headers */
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
#define NOMINMAX
@@ -116,10 +124,10 @@ typedef uword ip_csum_t;
#define strdup _strdup
#define __attribute__(A)
-#ifndef IOVEC
+#ifndef IOVEC
#define IOVEC
#define UIO_MAXIOV 16
-#define IOV_MAX UIO_MAXIOV
+#define IOV_MAX UIO_MAXIOV
struct iovec
{
void *iov_base;
@@ -132,66 +140,20 @@ struct iovec
* Portable attribute packed.
*/
#ifndef _WIN32
-#define PACKED( __Declaration__ ) __Declaration__ __attribute__((__packed__))
+#define PACKED(__Declaration__) __Declaration__ __attribute__ ((__packed__))
#else
-#define PACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
+#define PACKED(__Declaration__) \
+ __pragma (pack (push, 1)) __Declaration__ __pragma (pack (pop))
#endif
-
/*
* IP address types
*/
-#ifdef HICN_VPP_PLUGIN
-
-#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
-
-
#ifndef _WIN32
#include <netinet/in.h>
#endif
-typedef union
-{
- u32 as_u32;
- struct in_addr as_inaddr;
-} ip4_address_t;
-
-typedef union
-{
- u64 as_u64[2];
- u32 as_u32[4];
- u8 as_u8[16];
- struct in6_addr as_in6addr;
-} ip6_address_t;
-
-typedef union
-{
- struct
- {
- u32 pad[3];
- ip4_address_t ip4;
- };
- ip6_address_t ip6;
-} ip46_address_t;
-
-#define ip46_address_is_ip4(ip46) (((ip46)->pad[0] | (ip46)->pad[1] | (ip46)->pad[2]) == 0)
-
-#endif /* ! HICN_VPP_PLUGIN */
-
/**
* @brief Returns the family of an IP address
* @param [in] ip_address - IP address in presentation format
@@ -215,7 +177,7 @@ int get_addr_family (const char *ip_address);
* borrow this code here.
*/
-static_always_inline u16
+static inline u16
ip_csum_fold (ip_csum_t c)
{
/* Reduce to 16 bits. */
@@ -227,10 +189,10 @@ ip_csum_fold (ip_csum_t c)
c = (c & 0xffff) + (c >> 16);
c = (c & 0xffff) + (c >> 16);
- return (u16)c;
+ return (u16) c;
}
-static_always_inline ip_csum_t
+static inline ip_csum_t
ip_csum_with_carry (ip_csum_t sum, ip_csum_t x)
{
ip_csum_t t = sum + x;
@@ -238,7 +200,7 @@ ip_csum_with_carry (ip_csum_t sum, ip_csum_t x)
}
/* Update checksum changing field at even byte offset from x -> 0. */
-static_always_inline ip_csum_t
+static inline ip_csum_t
ip_csum_add_even (ip_csum_t c, ip_csum_t x)
{
ip_csum_t d;
@@ -252,19 +214,19 @@ ip_csum_add_even (ip_csum_t c, ip_csum_t x)
}
/* Update checksum changing field at even byte offset from 0 -> x. */
-static_always_inline ip_csum_t
+static inline ip_csum_t
ip_csum_sub_even (ip_csum_t c, ip_csum_t x)
{
return ip_csum_with_carry (c, x);
}
+#endif /* ! HICN_VPP_PLUGIN */
+
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 (const uint8_t * buffer, size_t len);
-
-#endif /* ! HICN_VPP_PLUGIN */
+void hicn_packet_dump (const uint8_t *buffer, size_t len);
/**
* @brief Computes buffer checksum
@@ -273,7 +235,7 @@ void hicn_packet_dump (const uint8_t * buffer, size_t len);
* @param [in] init - Checksum initial value
* @return Checksum of specified buffer
*/
-always_inline u16
+static inline u16
csum (const void *addr, size_t size, u16 init)
{
u32 sum = init;
@@ -291,7 +253,7 @@ csum (const void *addr, size_t size, u16 init)
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
- return (u16) ~ sum;
+ return (u16) ~sum;
}
/*
@@ -305,17 +267,24 @@ csum (const void *addr, size_t size, u16 init)
* Query IP version from packet (either 4 or 6)
* (version is located as same offsets in both protocol headers)
*/
-#define HICN_IP_VERSION(packet) ((hicn_header_t *)packet)->v4.ip.version
+#define HICN_IP_VERSION(packet) \
+ ((hicn_header_t *) packet)->protocol.ipv4.version
/*
* ntohll / htonll allows byte swapping for 64 bits integers
*/
#ifndef htonll
-#define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
+#define htonll(x) \
+ ((1 == htonl (1)) ? \
+ (x) : \
+ ((uint64_t) htonl ((x) &0xFFFFFFFF) << 32) | htonl ((x) >> 32))
#endif
#ifndef ntohll
-#define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
+#define ntohll(x) \
+ ((1 == ntohl (1)) ? \
+ (x) : \
+ ((uint64_t) ntohl ((x) &0xFFFFFFFF) << 32) | ntohl ((x) >> 32))
#endif
#endif /* HICN_COMMON_H */
diff --git a/lib/includes/hicn/compat.h b/lib/includes/hicn/compat.h
index 486c82348..8de3f9d7e 100644
--- a/lib/includes/hicn/compat.h
+++ b/lib/includes/hicn/compat.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -35,14 +35,18 @@
#define HFO_INET 1 << 0
#define HFO_INET6 1 << 1
#define HFO_TCP 1 << 2
-#define HFO_ICMP 1 << 3
-#define HFO_AH 1 << 4
+#define HFO_UDP 1 << 3
+#define HFO_ICMP 1 << 4
+#define HFO_CMPR 1 << 5
+#define HFO_AH 1 << 6
#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_udp(format) ((format & HFO_UDP) >> 3)
+#define _is_icmp(format) ((format & HFO_ICMP) >> 4)
+#define _is_cmpr(format) ((format & HFO_CMPR) >> 5)
+#define _is_ah(format) ((format & HFO_AH) >> 6)
typedef enum
{
@@ -51,13 +55,32 @@ typedef enum
HF_INET6_TCP = HFO_INET6 | HFO_TCP,
HF_INET_ICMP = HFO_INET | HFO_ICMP,
HF_INET6_ICMP = HFO_INET6 | HFO_ICMP,
+ HF_NEW = HFO_CMPR,
+ HF_INET_UDP = HFO_INET | HFO_UDP | HFO_CMPR,
+ HF_INET6_UDP = HFO_INET6 | HFO_UDP | HFO_CMPR,
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_NEW_AH = HFO_CMPR | HFO_AH,
+ HF_INET_UDP_AH = HFO_INET | HFO_UDP | HFO_CMPR | HFO_AH,
+ HF_INET6_UDP_AH = HFO_INET6 | HFO_UDP | HFO_CMPR | HFO_AH,
} hicn_format_t;
/**
+ * @brief Add AH header to current format. E.g. if format is IP + TCP, this
+ * will change it to IP = TCP + AH
+ *
+ * @param [in] format - The input format
+ * @return The format with the AH bit set to 1
+ */
+static inline hicn_format_t
+hicn_get_ah_format (hicn_format_t format)
+{
+ return (hicn_format_t) (format | HFO_AH);
+}
+
+/**
* 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
@@ -351,18 +374,49 @@ int hicn_packet_get_hoplimit (const hicn_header_t *packet, u8 *hops);
*/
int hicn_packet_set_hoplimit (hicn_header_t *packet, u8 hops);
+/**
+ * @brief Check if this packet is interest
+ *
+ * @param format - hICN format
+ * @param packet - Packet header
+ * @return hICN error code
+ */
+int hicn_packet_is_interest (hicn_format_t format, const hicn_header_t *h,
+ int *ret);
+
+/**
+ * @brief Mark this packet as interest
+ *
+ * @param format - hICN format
+ * @param packet - Packet header
+ * @return hICN error code
+ */
+int hicn_packet_set_interest (hicn_format_t format, hicn_header_t *packet);
+
+/**
+ * @brief Mark this packet as data
+ *
+ * @param format - hICN format
+ * @param packet - Packet header
+ * @return hICN error code
+ */
+int hicn_packet_set_data (hicn_format_t format, hicn_header_t *h);
+
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_lifetime (hicn_format_t format,
+ const hicn_header_t *packet, u32 *lifetime);
+int hicn_packet_set_lifetime (hicn_format_t format, 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,
+int hicn_packet_get_payload_type (hicn_format_t format,
+ const hicn_header_t *packet,
hicn_payload_type_t *payload_type);
-int hicn_packet_set_payload_type (hicn_header_t *packet,
+int hicn_packet_set_payload_type (hicn_format_t format, hicn_header_t *packet,
const hicn_payload_type_t payload_type);
int hicn_packet_set_syn (hicn_format_t format, hicn_header_t *packet);
@@ -454,10 +508,14 @@ int hicn_data_get_payload_type (const hicn_header_t *data,
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_packet_get_signature_gap (hicn_format_t format,
- const hicn_header_t *h, uint8_t *bytes);
-int hicn_packet_set_signature_gap (hicn_format_t format, hicn_header_t *h,
- uint8_t bytes);
+int hicn_data_is_last (hicn_format_t format, hicn_header_t *h, int *is_last);
+int hicn_data_set_last (hicn_format_t format, hicn_header_t *h);
+
+int hicn_packet_get_signature_padding (hicn_format_t format,
+ const hicn_header_t *h, size_t *bytes);
+int hicn_packet_set_signature_padding (hicn_format_t format, hicn_header_t *h,
+ size_t bytes);
+
#endif /* HICN_COMPAT_H */
/*
diff --git a/lib/includes/hicn/error.h b/lib/includes/hicn/error.h
index 9303aeb7e..d769ef693 100644
--- a/lib/includes/hicn/error.h
+++ b/lib/includes/hicn/error.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -24,21 +24,22 @@
* 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 ") \
-_(REWRITE_CKSUM_REQUIRED, 223, "Incremental csum calculation error: cksum required.") \
-_(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
{
-#define _(a,b,c) HICN_LIB_ERROR_##a = (-b),
+#define _(a, b, c) HICN_LIB_ERROR_##a = (-b),
foreach_libhicn_error
#undef _
HICN_LIB_N_ERROR,
@@ -46,7 +47,7 @@ typedef enum
extern const char *HICN_LIB_ERROR_STRING[];
-#define hicn_strerror(errno) (char *)(HICN_LIB_ERROR_STRING[-errno])
+#define hicn_strerror(errno) (char *) (HICN_LIB_ERROR_STRING[-errno])
#endif /* HICN_ERROR_H */
diff --git a/lib/includes/hicn/face.h b/lib/includes/hicn/face.h
new file mode 100644
index 000000000..31906afab
--- /dev/null
+++ b/lib/includes/hicn/face.h
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 2021 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 face.h
+ * \brief Face abstraction
+ */
+#ifndef HICN_FACE_H
+#define HICN_FACE_H
+
+#ifndef SPACES
+#define SPACES(x) x
+#endif
+#ifndef SPACE
+#define SPACE 1
+#endif
+#ifndef NULLTERM
+#define NULLTERM 1
+#endif
+
+#include <hicn/policy.h>
+
+#include <hicn/util/ip_address.h>
+
+/* Netdevice type */
+
+#include <net/if.h> // IFNAMSIZ
+
+#define foreach_netdevice_type \
+ _ (UNDEFINED) \
+ _ (LOOPBACK) \
+ _ (WIRED) \
+ _ (WIFI) \
+ _ (CELLULAR) \
+ _ (VPN) \
+ _ (MEMIF) \
+ _ (N)
+
+#define MAXSZ_NETDEVICE_TYPE_ 9
+#define MAXSZ_NETDEVICE_TYPE MAXSZ_NETDEVICE_TYPE_ + NULLTERM
+
+typedef enum
+{
+#define _(x) NETDEVICE_TYPE_##x,
+ foreach_netdevice_type
+#undef _
+} netdevice_type_t;
+
+extern const char *_netdevice_type_str[];
+#define netdevice_type_str(x) _netdevice_type_str[x]
+
+#define NETDEVICE_INVALID_INDEX ~0
+
+/* Netdevice */
+
+/**
+ * \brief Netdevice type
+ *
+ * NOTE
+ * - This struct cannot be made opaque as it is currently part of face_t
+ * - We recommand using the API as to keep redundant attributes consistent
+ */
+
+typedef struct
+{
+ u32 index;
+ char name[IFNAMSIZ];
+} netdevice_t;
+
+#define NETDEVICE_EMPTY \
+ (netdevice_t) \
+ { \
+ .index = 0, .name = { 0 } \
+ }
+
+netdevice_t *netdevice_create_from_index (u32 index);
+netdevice_t *netdevice_create_from_name (const char *name);
+#define netdevice_initialize_from_index netdevice_set_index
+#define netdevice_initialize_from_name netdevice_set_name
+void netdevice_free (netdevice_t *netdevice);
+int netdevice_get_index (const netdevice_t *netdevice, u32 *index);
+int netdevice_set_index (netdevice_t *netdevice, u32 index);
+int netdevice_get_name (const netdevice_t *netdevice, const char **name);
+int netdevice_set_name (netdevice_t *netdevice, const char *name);
+int netdevice_update_index (netdevice_t *netdevice);
+int netdevice_update_name (netdevice_t *netdevice);
+int netdevice_cmp (const netdevice_t *nd1, const netdevice_t *nd2);
+
+#define NETDEVICE_UNDEFINED_INDEX 0
+
+/* Face state */
+
+#define foreach_face_state \
+ _ (UNDEFINED) \
+ _ (DOWN) \
+ _ (UP) \
+ _ (N)
+
+#define MAXSZ_FACE_STATE_ 9
+#define MAXSZ_FACE_STATE MAXSZ_FACE_STATE_ + 1
+
+typedef enum
+{
+#define _(x) FACE_STATE_##x,
+ foreach_face_state
+#undef _
+} face_state_t;
+
+extern const char *_face_state_str[];
+
+#define face_state_str(x) _face_state_str[x]
+
+/* Face type */
+
+#define foreach_face_type \
+ _ (UNDEFINED) \
+ _ (HICN) \
+ _ (HICN_LISTENER) \
+ _ (TCP) \
+ _ (TCP_LISTENER) \
+ _ (UDP) \
+ _ (UDP_LISTENER) \
+ _ (N)
+
+#define MAXSZ_FACE_TYPE_ 13
+#define MAXSZ_FACE_TYPE MAXSZ_FACE_TYPE_ + 1
+
+typedef enum
+{
+#define _(x) FACE_TYPE_##x,
+ foreach_face_type
+#undef _
+} face_type_t;
+
+typedef enum
+{
+ FACE_PROTOCOL_HICN,
+ FACE_PROTOCOL_UDP,
+ FACE_PROTOCOL_TCP,
+ FACE_PROTOCOL_UNKNOWN,
+} face_protocol_t;
+
+#define face_type_is_valid(face_type) \
+ (((face_type) >= FACE_TYPE_UNDEFINED) && (face_type < FACE_TYPE_N))
+#define face_type_is_defined(face_type) \
+ (((face_type) > FACE_TYPE_UNDEFINED) && (face_type < FACE_TYPE_N))
+
+extern const char *_face_type_str[];
+#define face_type_str(x) _face_type_str[x]
+
+face_type_t face_type_from_str (const char *str);
+
+#ifdef WITH_POLICY
+#define MAXSZ_FACE_ \
+ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_URL_ + 2 * MAXSZ_FACE_STATE_ + \
+ MAXSZ_POLICY_TAGS_ + 7
+#else
+#define MAXSZ_FACE_ \
+ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_URL_ + 2 * MAXSZ_FACE_STATE_ + 4
+#endif /* WITH_POLICY */
+#define MAXSZ_FACE MAXSZ_FACE_ + 1
+
+/* Face */
+
+typedef u32 face_id_t;
+
+typedef struct
+{
+ face_type_t type;
+ face_state_t admin_state;
+ face_state_t state;
+#ifdef WITH_POLICY
+ uint32_t priority;
+ policy_tags_t tags; /**< \see policy_tag_t */
+#endif /* WITH_POLICY */
+
+ /*
+ * Depending on the face type, some of the following fields will be unused
+ */
+ netdevice_t netdevice;
+ int family; /* To access family independently of face type */
+ ip_address_t local_addr;
+ ip_address_t remote_addr;
+ u16 local_port;
+ u16 remote_port;
+} face_t;
+
+int face_initialize (face_t *face);
+int face_initialize_udp (face_t *face, const char *interface_name,
+ const ip_address_t *local_addr, u16 local_port,
+ const ip_address_t *remote_addr, u16 remote_port,
+ int family);
+int face_initialize_udp_sa (face_t *face, const char *interface_name,
+ const struct sockaddr *local_addr,
+ const struct sockaddr *remote_addr);
+
+face_t *face_create ();
+face_t *face_create_udp (const char *interface_name,
+ const ip_address_t *local_addr, u16 local_port,
+ const ip_address_t *remote_addr, u16 remote_port,
+ int family);
+face_t *face_create_udp_sa (const char *interface_name,
+ const struct sockaddr *local_addr,
+ const struct sockaddr *remote_addr);
+
+int face_finalize (face_t *face);
+
+void face_free (face_t *face);
+
+typedef int (*face_cmp_t) (const face_t *f1, const face_t *f2);
+
+int face_cmp (const face_t *f1, const face_t *f2);
+
+size_t face_snprintf (char *s, size_t size, const face_t *face);
+
+policy_tags_t face_get_tags (const face_t *face);
+int face_set_tags (face_t *face, policy_tags_t tags);
+
+face_protocol_t get_protocol (face_type_t face_type);
+
+#endif /* HICN_FACE_H */
diff --git a/lib/includes/hicn/header.h b/lib/includes/hicn/header.h
index b21fe5c84..8af9170f8 100644
--- a/lib/includes/hicn/header.h
+++ b/lib/includes/hicn/header.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -20,8 +20,8 @@
* NOTE: These structures are used as convenient facade for accessing
* the encapsulated headers. They are not written taking compiler padding
* into account, then a sizeof() on these struct could not give the expected
- * result. For accessing the size of the hicn headers use the macros at the end of
- * this file.
+ * result. For accessing the size of the hicn headers use the macros at the end
+ * of this file.
*/
#ifndef HICN_HEADER_H
@@ -36,6 +36,11 @@ typedef struct
union
{
_tcp_header_t tcp;
+ struct
+ {
+ _udp_header_t udp;
+ _new_header_t newhdr;
+ };
_icmp_header_t icmp;
_icmp_wldr_header_t wldr;
};
@@ -53,25 +58,36 @@ typedef struct
};
struct
{
+ _udp_header_t udp;
+ _new_header_t newhdr;
+ _ah_header_t udp_ah;
+ };
+ struct
+ {
_icmp_header_t icmp;
_ah_header_t icmp_ah;
};
};
} hicn_v6ah_hdr_t;
-typedef struct
-{
+// For ipv4 we need to use packed structs as fields may be aligned to 64 bits
+// (So for instance tcp header may start at byte #24 instead of byte 20)
+typedef PACKED (struct {
_ipv4_header_t ip;
union
{
_tcp_header_t tcp;
+ struct
+ {
+ _udp_header_t udp;
+ _new_header_t newhdr;
+ };
_icmp_header_t icmp;
_icmp_wldr_header_t wldr;
};
-} hicn_v4_hdr_t;
+}) hicn_v4_hdr_t;
-typedef struct
-{
+typedef PACKED (struct {
_ipv4_header_t ip;
union
{
@@ -82,11 +98,17 @@ typedef struct
};
struct
{
+ _udp_header_t udp;
+ _new_header_t newhdr;
+ _ah_header_t udp_ah;
+ };
+ struct
+ {
_icmp_header_t icmp;
_ah_header_t icmp_ah;
};
};
-} hicn_v4ah_hdr_t;
+}) hicn_v4ah_hdr_t;
typedef union
{
@@ -99,24 +121,19 @@ typedef union
hicn_protocol_t protocol;
} hicn_header_t;
+#define HICN_V6_TCP_HDRLEN (IPV6_HDRLEN + TCP_HDRLEN)
+#define HICN_V6_ICMP_HDRLEN (IPV6_HDRLEN + ICMP_HDRLEN)
+#define HICN_V6_WLDR_HDRLEN (IPV6_HDRLEN + ICMPWLDR_HDRLEN)
-#define HICN_V6_TCP_HDRLEN (IPV6_HDRLEN + TCP_HDRLEN)
-#define HICN_V6_ICMP_HDRLEN (IPV6_HDRLEN + ICMP_HDRLEN)
-#define HICN_V6_WLDR_HDRLEN (IPV6_HDRLEN + ICMPWLDR_HDRLEN)
-
-#define HICN_V6_TCP_AH_HDRLEN (HICN_V6_TCP_HDRLEN + AH_HDRLEN)
-#define HICN_V6_ICMP_AH_HDRLEN (HICN_V6_ICMP_HDRLEN + AH_HDRLEN)
-
-
-#define HICN_V4_TCP_HDRLEN (IPV4_HDRLEN + TCP_HDRLEN)
-#define HICN_V4_ICMP_HDRLEN (IPV4_HDRLEN + ICMP_HDRLEN)
-#define HICN_V4_WLDR_HDRLEN (IPV4_HDRLEN + ICMPWLDR_HDRLEN)
-
-#define HICN_V4_TCP_AH_HDRLEN (HICN_V4_TCP_HDRLEN + AH_HDRLEN)
-#define HICN_V4_ICMP_AH_HDRLEN (HICN_V4_ICMP_HDRLEN + AH_HDRLEN)
-
+#define HICN_V6_TCP_AH_HDRLEN (HICN_V6_TCP_HDRLEN + AH_HDRLEN)
+#define HICN_V6_ICMP_AH_HDRLEN (HICN_V6_ICMP_HDRLEN + AH_HDRLEN)
+#define HICN_V4_TCP_HDRLEN (IPV4_HDRLEN + TCP_HDRLEN)
+#define HICN_V4_ICMP_HDRLEN (IPV4_HDRLEN + ICMP_HDRLEN)
+#define HICN_V4_WLDR_HDRLEN (IPV4_HDRLEN + ICMPWLDR_HDRLEN)
+#define HICN_V4_TCP_AH_HDRLEN (HICN_V4_TCP_HDRLEN + AH_HDRLEN)
+#define HICN_V4_ICMP_AH_HDRLEN (HICN_V4_ICMP_HDRLEN + AH_HDRLEN)
#endif /* HICN_HEADER_H */
diff --git a/lib/includes/hicn/hicn.h b/lib/includes/hicn/hicn.h
index 749fd4247..4a5b4dd56 100644
--- a/lib/includes/hicn/hicn.h
+++ b/lib/includes/hicn/hicn.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -31,15 +31,17 @@
*
* [1] Hybrid Information-Centric Networking
* L. Muscariello, G. Carofiglio, J. Augé, M. Papalini
- * IETF draft (intarea) @ https://tools.ietf.org/html/draft-muscariello-intarea-hicn
+ * IETF draft (intarea) @
+ * https://tools.ietf.org/html/draft-muscariello-intarea-hicn
*
- * [2] Leveraging ICN in-network control for loss detection and recovery in wireless mobile networks
- * G. Carofiglio, L. Muscariello, M. Papalini, N. Rozhnova, X. Zeng
- * In proc. ICN'2016, Kyoto, JP
+ * [2] Leveraging ICN in-network control for loss detection and recovery in
+ * wireless mobile networks G. Carofiglio, L. Muscariello, M. Papalini, N.
+ * Rozhnova, X. Zeng In proc. ICN'2016, Kyoto, JP
*
* [3] Anchorless mobility through hICN
* J. Augé, G. Carofiglio, L. Muscariello, M. Papalini
- * IETF draft (DMM) @ https://tools.ietf.org/html/draft-auge-dmm-hicn-mobility
+ * IETF draft (DMM) @
+ * https://tools.ietf.org/html/draft-auge-dmm-hicn-mobility
*
*
* [4] MAP-Me : Managing Anchorless Mobility in Content Centric Networking
diff --git a/lib/includes/hicn/mapme.h b/lib/includes/hicn/mapme.h
index 8fae44530..63a5cd77e 100644
--- a/lib/includes/hicn/mapme.h
+++ b/lib/includes/hicn/mapme.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -20,7 +20,7 @@
#ifndef HICN_MAPME_H
#define HICN_MAPME_H
-#include <stdint.h> // u32
+#include <stdint.h> // u32
#include <stdbool.h>
#include "common.h"
@@ -32,16 +32,16 @@
*/
typedef struct
{
- /** MAP-Me enabled flag (default: false) */
+ /** MAP-Me enabled flag (default: false) */
bool enabled;
- /** timescale (T_U parameter) in ms (default: 0 for no notifications) */
+ /** timescale (T_U parameter) in ms (default: 0 for no notifications) */
u32 timescale;
- /** retransmission timer in ms (default: 50) */
+ /** retransmission timer in ms (default: 50) */
u32 retx;
- /**
- * Discovery enabled flag (default: true, should be true if mandatory is
- * notifications are enabled)
- */
+ /**
+ * Discovery enabled flag (default: true, should be true if mandatory is
+ * notifications are enabled)
+ */
bool discovery;
} hicn_mapme_conf_t;
@@ -74,37 +74,45 @@ typedef struct
seq_t seq;
} mapme_params_t;
-
/* MAP-Me API */
-size_t hicn_mapme_create_packet (u8 * buf, const hicn_prefix_t * prefix,
- const mapme_params_t * params);
-size_t hicn_mapme_create_ack (u8 * buf, const mapme_params_t * params);
-int hicn_mapme_parse_packet (const u8 * packet, hicn_prefix_t * prefix,
- mapme_params_t * params);
+size_t hicn_mapme_create_packet (u8 *buf, const hicn_prefix_t *prefix,
+ const mapme_params_t *params);
+size_t hicn_mapme_create_ack (u8 *buf, const mapme_params_t *params);
+int hicn_mapme_parse_packet (const u8 *packet, hicn_prefix_t *prefix,
+ mapme_params_t *params);
/* Implementation & parsing : ICMP Redirect */
#define HICN_MAPME_ACK_FLAG (0x20 | 0x60)
-#define HICN_MAPME_ICMP_TYPE_IPV4 5
-#define HICN_MAPME_ICMP_TYPE_IPV6 137
-#define HICN_MAPME_ICMP_TYPE_ACK_IPV4 (HICN_MAPME_ICMP_TYPE_IPV4 | HICN_MAPME_ACK_FLAG)
-#define HICN_MAPME_ICMP_TYPE_ACK_IPV6 (HICN_MAPME_ICMP_TYPE_IPV6 | HICN_MAPME_ACK_FLAG)
-#define HICN_MAPME_ICMP_CODE 0 /* Redirect Datagrams for the Network (or subnet) */
-
-#define HICN_MAPME_TYPE_IS_IU(type) ((type == HICN_MAPME_ICMP_TYPE_IPV4) || (type == HICN_MAPME_ICMP_TYPE_IPV6))
-#define HICN_MAPME_TYPE_IS_IU_ACK(type) ((type == HICN_MAPME_ICMP_TYPE_ACK_IPV4) || (type == HICN_MAPME_ICMP_TYPE_ACK_IPV6))
-
-#define HICN_MAPME_IS_IU(type, code) (HICN_MAPME_TYPE_IS_IU(type) && (code == HICN_MAPME_ICMP_CODE))
-#define HICN_MAPME_IS_ACK(type, code) (HICN_MAPME_TYPE_IS_IU_ACK(type) && (code == HICN_MAPME_ICMP_CODE))
-
-#define HICN_IS_MAPME(type, code) (HICN_MAPME_IS_IU(type, code) || HICN_MAPME_IS_ACK(type, code))
+#define HICN_MAPME_ICMP_TYPE_IPV4 5
+#define HICN_MAPME_ICMP_TYPE_IPV6 137
+#define HICN_MAPME_ICMP_TYPE_ACK_IPV4 \
+ (HICN_MAPME_ICMP_TYPE_IPV4 | HICN_MAPME_ACK_FLAG)
+#define HICN_MAPME_ICMP_TYPE_ACK_IPV6 \
+ (HICN_MAPME_ICMP_TYPE_IPV6 | HICN_MAPME_ACK_FLAG)
+#define HICN_MAPME_ICMP_CODE \
+ 0 /* Redirect Datagrams for the Network (or subnet) */
+
+#define HICN_MAPME_TYPE_IS_IU(type) \
+ ((type == HICN_MAPME_ICMP_TYPE_IPV4) || (type == HICN_MAPME_ICMP_TYPE_IPV6))
+#define HICN_MAPME_TYPE_IS_IU_ACK(type) \
+ ((type == HICN_MAPME_ICMP_TYPE_ACK_IPV4) || \
+ (type == HICN_MAPME_ICMP_TYPE_ACK_IPV6))
+
+#define HICN_MAPME_IS_IU(type, code) \
+ (HICN_MAPME_TYPE_IS_IU (type) && (code == HICN_MAPME_ICMP_CODE))
+#define HICN_MAPME_IS_ACK(type, code) \
+ (HICN_MAPME_TYPE_IS_IU_ACK (type) && (code == HICN_MAPME_ICMP_CODE))
+
+#define HICN_IS_MAPME(type, code) \
+ (HICN_MAPME_IS_IU (type, code) || HICN_MAPME_IS_ACK (type, code))
/* Fast check for ACK flag */
#define HICN_MAPME_IS_ACK_FAST(icmp_type) (icmp_type & HICN_MAPME_ACK_FLAG)
/* Default TTL */
-#define HICN_MAPME_TTL 255 // typical for redirect (ref?)
+#define HICN_MAPME_TTL 255 // typical for redirect (ref?)
/*
* The length of the MAPME4 header struct must be 120 bytes.
@@ -143,8 +151,8 @@ typedef union
hicn_mapme_v6_header_t v6;
} hicn_mapme_header_t;
-#define HICN_MAPME_V4_HDRLEN sizeof(hicn_mapme_v4_header_t)
-#define HICN_MAPME_V6_HDRLEN sizeof(hicn_mapme_v6_header_t)
+#define HICN_MAPME_V4_HDRLEN sizeof (hicn_mapme_v4_header_t)
+#define HICN_MAPME_V6_HDRLEN sizeof (hicn_mapme_v6_header_t)
static_assert (EXPECTED_MAPME_V4_HDRLEN == HICN_MAPME_V4_HDRLEN,
"Size of MAPME_V4 struct does not match its expected size.");
diff --git a/lib/includes/hicn/name.h b/lib/includes/hicn/name.h
index d5202068b..f85b0bc3f 100644
--- a/lib/includes/hicn/name.h
+++ b/lib/includes/hicn/name.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -26,7 +26,7 @@
#include <stdbool.h>
#ifndef _WIN32
-#include <netinet/in.h> // struct sockadd
+#include <netinet/in.h> // struct sockadd
#endif
#include <hicn/util/ip_address.h>
#include "common.h"
@@ -35,12 +35,16 @@
* hICN names
******************************************************************************/
-#define TCP_SEQNO_LEN 4 /* bytes */
+#define TCP_SEQNO_LEN 4 /* bytes */
#define HICN_V4_PREFIX_LEN IPV4_ADDR_LEN
#define HICN_V6_PREFIX_LEN IPV6_ADDR_LEN
-#define HICN_SEGMENT_LEN TCP_SEQNO_LEN
-#define HICN_V6_NAME_LEN (HICN_V6_PREFIX_LEN + HICN_SEGMENT_LEN) /* 20 bytes */
-#define HICN_V4_NAME_LEN (HICN_V4_PREFIX_LEN + HICN_SEGMENT_LEN) /* 8 bytes */
+#define HICN_SEGMENT_LEN TCP_SEQNO_LEN
+#define HICN_V6_NAME_LEN \
+ (HICN_V6_PREFIX_LEN + HICN_SEGMENT_LEN) /* 20 bytes \
+ */
+#define HICN_V4_NAME_LEN \
+ (HICN_V4_PREFIX_LEN + HICN_SEGMENT_LEN) /* 8 bytes \
+ */
/* Prefix */
@@ -48,7 +52,7 @@ typedef u32 hicn_name_suffix_t;
typedef struct
{
- ip46_address_t name;
+ ip_address_t name;
u8 len;
} hicn_prefix_t;
@@ -58,85 +62,17 @@ typedef struct
* A name is a prefix + a segment name (suffix)
*/
-typedef union
-{
- struct
- {
- 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_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
-
-typedef enum
-{
- 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 */
- };
+ ip_address_t prefix;
+ hicn_name_suffix_t suffix;
} 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 */
+#define _is_unspec(name) \
+ (((name)->prefix.pad[0] | (name)->prefix.pad[1] | (name)->prefix.pad[2] | \
+ (name)->prefix.v4.as_u32) == 0)
+#define _is_inet4(name) (ip_address_is_v4 (&name->prefix))
+#define _is_inet6(name) (!_is_inet4 (name))
/**
* @brief Create an hICN name from IP address in presentation format
@@ -145,7 +81,7 @@ typedef struct
* @param [out] Resulting hICN name
* @return hICN error code
*/
-int hicn_name_create (const char *ip_address, u32 id, hicn_name_t * name);
+int hicn_name_create (const char *ip_address, u32 id, hicn_name_t *name);
/**
* @brief Create an hICN name from IP address
@@ -154,28 +90,21 @@ int hicn_name_create (const char *ip_address, u32 id, hicn_name_t * name);
* @param [out] Resulting - hICN name
* @return hICN error code
*/
-int hicn_name_create_from_ip_prefix (const ip_prefix_t * prefix, u32 id,
- hicn_name_t * name);
-
-/**
- * @brief Returns the length of an hICN name
- * @param [in] name - hICN name
- * @return Name length
- */
-u8 hicn_name_get_length (const hicn_name_t * name);
+int hicn_name_create_from_ip_prefix (const ip_prefix_t *prefix, u32 id,
+ hicn_name_t *name);
/**
* @brief Compare two hICN names
* @param [in] name_1 - First name to compare
* @param [in] name_2 - Second name to compare
- * @param [in] consider_segment - Flag indicating whether the segment part has to be
- * considered
+ * @param [in] consider_segment - Flag indicating whether the segment part has
+ * to be considered
* @return An integer less than, equal to, or greater than zero if name_1 is
* found, respectively, to be lest than, to match, or be greater than name_2
* based on numeric order.
*/
-int hicn_name_compare (const hicn_name_t * name_1, const hicn_name_t * name_2,
- bool consider_segment);
+int hicn_name_compare (const hicn_name_t *name_1, const hicn_name_t *name_2,
+ bool consider_segment);
/**
* @brief Provides a 32-bit hash of an hICN name
@@ -184,7 +113,7 @@ int hicn_name_compare (const hicn_name_t * name_1, const hicn_name_t * name_2,
* @param [in] consider_suffix - Consider the suffix in the hash computation
* @return hICN error code
*/
-int hicn_name_hash (const hicn_name_t * name, u32 * hash, bool consider_suffix);
+int hicn_name_hash (const hicn_name_t *name, u32 *hash, bool consider_suffix);
/**
* @brief Test whether an hICN name is empty
@@ -192,7 +121,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)
*/
-int hicn_name_empty (hicn_name_t * name);
+int hicn_name_empty (hicn_name_t *name);
/**
* @brief Copy an hICN name
@@ -200,7 +129,7 @@ int hicn_name_empty (hicn_name_t * name);
* @param [in] src - Source name to copy
* @return hICN error code
*/
-int hicn_name_copy (hicn_name_t * dst, const hicn_name_t * src);
+int hicn_name_copy (hicn_name_t *dst, const hicn_name_t *src);
/**
* @brief Copy an hICN name to a buffer
@@ -209,8 +138,7 @@ int hicn_name_copy (hicn_name_t * dst, const hicn_name_t * src);
* @param [in] copy_suffix - Flag indicating whether the suffix has to be
* considered
*/
-int hicn_name_copy_to_destination (u8 * dst, const hicn_name_t * src,
- bool copy_suffix);
+int hicn_name_copy_prefix_to_destination (u8 *dst, const hicn_name_t *src);
/**
* @brief Sets the segment part of an hICN name
@@ -218,7 +146,7 @@ int hicn_name_copy_to_destination (u8 * dst, const hicn_name_t * src,
* @param [in] seq_number - Segment identifier
* @return hICN error code
*/
-int hicn_name_set_seq_number (hicn_name_t * name, u32 seq_number);
+int hicn_name_set_seq_number (hicn_name_t *name, u32 seq_number);
/**
* @brief Retrieves the segment part of an hICN name
@@ -226,7 +154,7 @@ int hicn_name_set_seq_number (hicn_name_t * name, u32 seq_number);
* @param [in] seq_number - Segment identifier
* @return hICN error code
*/
-int hicn_name_get_seq_number (const hicn_name_t * name, u32 * seq_number);
+int hicn_name_get_seq_number (const hicn_name_t *name, u32 *seq_number);
/**
* @brief Convert an hICN name to a socket address
@@ -234,8 +162,8 @@ int hicn_name_get_seq_number (const hicn_name_t * name, u32 * seq_number);
* @param [out] ip_address - Resulting socket address
* @return hICN error code
*/
-int hicn_name_to_sockaddr_address (const hicn_name_t * name,
- struct sockaddr *ip_address);
+int hicn_name_to_sockaddr_address (const hicn_name_t *name,
+ struct sockaddr *ip_address);
/**
* @brief Convert an hICN name to an IP address
@@ -243,8 +171,7 @@ int hicn_name_to_sockaddr_address (const hicn_name_t * name,
* @param [out] ip_address - Resulting IP address
* @return hICN error code
*/
-int hicn_name_to_ip_prefix (const hicn_name_t * name,
- ip_prefix_t * ip_prefix);
+int hicn_name_to_ip_prefix (const hicn_name_t *name, ip_prefix_t *ip_prefix);
/**
* @brief Convert an hICN name to presentation format
@@ -253,7 +180,7 @@ int hicn_name_to_ip_prefix (const hicn_name_t * name,
* @param [in] len - Number of bytes available in the buffer
* @return hICN error code
*/
-int hicn_name_ntop (const hicn_name_t * src, char *dst, size_t len);
+int hicn_name_ntop (const hicn_name_t *src, char *dst, size_t len);
/**
* @brief Convert an hICN name from presentation format
@@ -261,7 +188,7 @@ int hicn_name_ntop (const hicn_name_t * src, char *dst, size_t len);
* @param [out] dst - Resulting name
* @return hICN error code
*/
-int hicn_name_pton (const char *src, hicn_name_t * dst);
+int hicn_name_pton (const char *src, hicn_name_t *dst);
/**
* @brief Returns the IP address family of an hICN name
@@ -269,7 +196,7 @@ int hicn_name_pton (const char *src, hicn_name_t * dst);
* @param [out] family - Resulting IP address family (AF_INET or AF_INET6)
* @return hICN error code
*/
-int hicn_name_get_family (const hicn_name_t * name, int *family);
+int hicn_name_get_family (const hicn_name_t *name, int *family);
/**
* @brief Creates an hICN prefix from an IP address
@@ -277,8 +204,8 @@ int hicn_name_get_family (const hicn_name_t * name, int *family);
* @param [out] prefix - Resulting prefix
* @return hICN error code
*/
-int hicn_prefix_create_from_ip_prefix (const ip_prefix_t * ip_prefix,
- hicn_prefix_t * prefix);
+int hicn_prefix_create_from_ip_prefix (const ip_prefix_t *ip_prefix,
+ hicn_prefix_t *prefix);
#endif /* HICN_NAME_H */
diff --git a/lib/includes/hicn/ops.h b/lib/includes/hicn/ops.h
index e5b1c088c..e9eebc76c 100644
--- a/lib/includes/hicn/ops.h
+++ b/lib/includes/hicn/ops.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -23,6 +23,7 @@
#include <stdlib.h>
+#include "common.h"
#include "error.h"
#include "header.h"
#include "name.h"
@@ -52,7 +53,7 @@ typedef struct hicn_ops_s
* @return hICN error code
*/
int (*get_interest_locator) (hicn_type_t type, const hicn_protocol_t *h,
- ip46_address_t *ip_address);
+ ip_address_t *ip_address);
/**
* @brief Sets an Interest locator
@@ -62,7 +63,7 @@ typedef struct hicn_ops_s
* @return hICN error code
*/
int (*set_interest_locator) (hicn_type_t type, hicn_protocol_t *h,
- const ip46_address_t *ip_address);
+ const ip_address_t *ip_address);
/**
* @brief Retrieves an Interest name
@@ -105,6 +106,15 @@ typedef struct hicn_ops_s
const hicn_name_suffix_t *suffix);
/**
+ * @brief Check if packet is an interest
+ * @param [in] type - hICN packet type
+ * @param [in] h - Buffer holding the Interest packet
+ * @param [out] h - 1 if interest, 0 otherwise
+ * @return hICN error code
+ */
+ int (*is_interest) (hicn_type_t type, const hicn_protocol_t *h, int *ret);
+
+ /**
* @brief Set flag to mark current packet as interest
* @param [in] type - hICN packet type
* @param [in,out] h - Buffer holding the Interest packet
@@ -136,7 +146,7 @@ typedef struct hicn_ops_s
* @return hICN error code
*/
int (*get_data_locator) (hicn_type_t type, const hicn_protocol_t *h,
- ip46_address_t *ip_address);
+ ip_address_t *ip_address);
/**
* @brief Sets a Data locator
@@ -146,7 +156,7 @@ typedef struct hicn_ops_s
* @return hICN error code
*/
int (*set_data_locator) (hicn_type_t type, hicn_protocol_t *h,
- const ip46_address_t *ip_address);
+ const ip_address_t *ip_address);
/**
* @brief Retrieves a Data name
@@ -282,8 +292,8 @@ typedef struct hicn_ops_s
* @return hICN error code
*/
int (*rewrite_interest) (hicn_type_t type, hicn_protocol_t *h,
- const ip46_address_t *addr_new,
- ip46_address_t *addr_old);
+ const ip_address_t *addr_new,
+ ip_address_t *addr_old);
/**
* @brief Rewrite a Data packet header (locator + pathlabel)
@@ -298,9 +308,8 @@ typedef struct hicn_ops_s
* @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,
- u8 reset_pl);
+ const ip_address_t *addr_new, ip_address_t *addr_old,
+ const hicn_faceid_t face_id, u8 reset_pl);
/**
* @brief Return the packet length
@@ -373,27 +382,27 @@ typedef struct hicn_ops_s
size_t signature_size);
/**
- * @brief Sets an Interest or Data signature gap between maximum size and
+ * @brief Sets an Interest or Data signature padding between maximum size and
* real size
* @param [in] type - hICN packet type
* @param [in,out] h - Buffer holding the Interest or Data packet
* @param [in] signature_size - Signature size to set
* @return hICN error code
*/
- int (*set_signature_gap) (hicn_type_t type, hicn_protocol_t *h,
- uint8_t signature_gap);
+ int (*set_signature_padding) (hicn_type_t type, hicn_protocol_t *h,
+ size_t signature_padding);
/**
- * @brief gets an Interest or Data signature gap between maximum size and
+ * @brief gets an Interest or Data signature padding between maximum size and
* real size
* @param [in] type - hICN packet type
* @param [in,out] h - Buffer holding the Interest or Data packet
- * @param [in] signature_size - retrieve the gap between maximum size and
+ * @param [in] signature_size - retrieve the padding between maximum size and
* real size
* @return hICN error code
*/
- int (*get_signature_gap) (hicn_type_t type, const hicn_protocol_t *h,
- uint8_t *signature_gap);
+ int (*get_signature_padding) (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *signature_padding);
/**
* @brief Gets the signature timestamp
@@ -464,6 +473,44 @@ typedef struct hicn_ops_s
*/
int (*get_signature) (hicn_type_t type, hicn_protocol_t *h,
uint8_t **signature);
+
+ /**
+ * @brief Set payload type of the packet
+ * @param [in] type - hICN packet type
+ * @param [in,out] h - Buffer holding the Interest or Data packet
+ * @param [in] payload_type - The payload type of this packet
+ * @return hICN error code
+ */
+ int (*set_payload_type) (hicn_type_t type, hicn_protocol_t *h,
+ hicn_payload_type_t payload_type);
+
+ /**
+ * @brief Get payload type from the packet
+ * @param [in] type - hICN packet type
+ * @param [in] h - Buffer holding the Interest or Data packet
+ * @param [out] payload_type - The payload type of this packet
+ * @return hICN error code
+ */
+ int (*get_payload_type) (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_payload_type_t *payload_type);
+
+ /**
+ * @brief Check if data packet is last one.
+ * @param [in] type - hICN packet type
+ * @param [in] h - Buffer holding the Interest or Data packet
+ * @param [out] is_last - 1 if last data, 0 otherwise
+ * @return hICN error code
+ */
+ int (*is_last_data) (hicn_type_t type, const hicn_protocol_t *h,
+ int *is_last);
+
+ /**
+ * @brief Mark data packet as last
+ * @param [in] type - hICN packet type
+ * @param [in, out] h - Buffer holding the Interest or Data packet
+ * @return hICN error code
+ */
+ int (*set_last_data) (hicn_type_t type, hicn_protocol_t *h);
} hicn_ops_t;
#define DECLARE_HICN_OPS(protocol) \
@@ -477,6 +524,7 @@ typedef struct hicn_ops_s
protocol##_get_interest_name_suffix), \
ATTR_INIT (set_interest_name_suffix, \
protocol##_set_interest_name_suffix), \
+ ATTR_INIT (is_interest, protocol##_is_interest), \
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), \
@@ -502,6 +550,8 @@ typedef struct hicn_ops_s
ATTR_INIT (get_header_length, protocol##_get_header_length), \
ATTR_INIT (get_payload_length, protocol##_get_payload_length), \
ATTR_INIT (set_payload_length, protocol##_set_payload_length), \
+ ATTR_INIT (get_payload_type, protocol##_get_payload_type), \
+ ATTR_INIT (set_payload_type, protocol##_set_payload_type), \
ATTR_INIT (get_signature_size, protocol##_get_signature_size), \
ATTR_INIT (get_signature_timestamp, protocol##_get_signature_timestamp), \
ATTR_INIT (set_signature_timestamp, protocol##_set_signature_timestamp), \
@@ -512,9 +562,11 @@ typedef struct hicn_ops_s
ATTR_INIT (get_key_id, protocol##_get_key_id), \
ATTR_INIT (set_key_id, protocol##_set_key_id), \
ATTR_INIT (get_signature, protocol##_get_signature), \
- ATTR_INIT (set_signature_gap, protocol##_set_signature_gap), \
+ ATTR_INIT (set_signature_padding, protocol##_set_signature_padding), \
ATTR_INIT (set_signature_size, protocol##_set_signature_size), \
- ATTR_INIT (get_signature_gap, protocol##_get_signature_gap), \
+ ATTR_INIT (get_signature_padding, protocol##_get_signature_padding), \
+ ATTR_INIT (is_last_data, protocol##_is_last_data), \
+ ATTR_INIT (set_last_data, protocol##_set_last_data), \
}
/**
@@ -529,7 +581,7 @@ extern const hicn_ops_t *const hicn_ops_vft[];
* NOTE : we cannot use a shift operation as IPPROTO_NONE != 0 (and 0 is
* IPv4...)
*/
-always_inline hicn_type_t
+static inline hicn_type_t
TYPE_POP (hicn_type_t type)
{
#ifndef _WIN32
@@ -544,7 +596,7 @@ TYPE_POP (hicn_type_t type)
#endif
}
-always_inline hicn_protocol_t *
+static inline hicn_protocol_t *
PAYLOAD (hicn_type_t type, const hicn_protocol_t *h)
{
size_t header_length;
@@ -573,14 +625,14 @@ PAYLOAD (hicn_type_t type, const hicn_protocol_t *h)
#define DECLARE_get_interest_locator(protocol, error) \
int protocol##_get_interest_locator ( \
- hicn_type_t type, const hicn_protocol_t *h, ip46_address_t *ip_address) \
+ hicn_type_t type, const hicn_protocol_t *h, ip_address_t *ip_address) \
{ \
return HICN_LIB_ERROR_##error; \
}
#define DECLARE_set_interest_locator(protocol, error) \
int protocol##_set_interest_locator (hicn_type_t type, hicn_protocol_t *h, \
- const ip46_address_t *ip_address) \
+ const ip_address_t *ip_address) \
{ \
return HICN_LIB_ERROR_##error; \
}
@@ -613,6 +665,13 @@ PAYLOAD (hicn_type_t type, const hicn_protocol_t *h)
return HICN_LIB_ERROR_##error; \
}
+#define DECLARE_is_interest(protocol, error) \
+ int protocol##_is_interest (hicn_type_t type, const hicn_protocol_t *h, \
+ int *ret) \
+ { \
+ 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) \
@@ -635,14 +694,14 @@ PAYLOAD (hicn_type_t type, const hicn_protocol_t *h)
#define DECLARE_get_data_locator(protocol, error) \
int protocol##_get_data_locator ( \
- hicn_type_t type, const hicn_protocol_t *h, ip46_address_t *ip_address) \
+ hicn_type_t type, const hicn_protocol_t *h, ip_address_t *ip_address) \
{ \
return HICN_LIB_ERROR_##error; \
}
#define DECLARE_set_data_locator(protocol, error) \
int protocol##_set_data_locator (hicn_type_t type, hicn_protocol_t *h, \
- const ip46_address_t *ip_address) \
+ const ip_address_t *ip_address) \
{ \
return HICN_LIB_ERROR_##error; \
}
@@ -732,16 +791,16 @@ PAYLOAD (hicn_type_t type, const hicn_protocol_t *h)
#define DECLARE_rewrite_interest(protocol, error) \
int protocol##_rewrite_interest (hicn_type_t type, hicn_protocol_t *h, \
- const ip46_address_t *addr_new, \
- ip46_address_t *addr_old) \
+ const ip_address_t *addr_new, \
+ ip_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, u8 reset_pl) \
+ hicn_type_t type, hicn_protocol_t *h, const ip_address_t *addr_new, \
+ ip_address_t *addr_old, const hicn_faceid_t face_id, u8 reset_pl) \
{ \
return HICN_LIB_ERROR_##error; \
}
@@ -781,6 +840,21 @@ PAYLOAD (hicn_type_t type, const hicn_protocol_t *h)
return HICN_LIB_ERROR_##error; \
}
+#define DECLARE_get_payload_type(protocol, error) \
+ int protocol##_get_payload_type (hicn_type_t type, \
+ const hicn_protocol_t *h, \
+ hicn_payload_type_t *payload_type) \
+ { \
+ return HICN_LIB_ERROR_##error; \
+ }
+
+#define DECLARE_set_payload_type(protocol, error) \
+ int protocol##_set_payload_type (hicn_type_t type, hicn_protocol_t *h, \
+ hicn_payload_type_t payload_type) \
+ { \
+ return HICN_LIB_ERROR_##error; \
+ }
+
#define DECLARE_get_signature_size(protocol, error) \
int protocol##_get_signature_size ( \
hicn_type_t type, const hicn_protocol_t *h, size_t *signature_size) \
@@ -795,16 +869,16 @@ PAYLOAD (hicn_type_t type, const hicn_protocol_t *h)
return HICN_LIB_ERROR_##error; \
}
-#define DECLARE_set_signature_gap(protocol, error) \
- int protocol##_set_signature_gap (hicn_type_t type, hicn_protocol_t *h, \
- uint8_t signature_size) \
+#define DECLARE_set_signature_padding(protocol, error) \
+ int protocol##_set_signature_padding (hicn_type_t type, hicn_protocol_t *h, \
+ size_t padding) \
{ \
return HICN_LIB_ERROR_##error; \
}
-#define DECLARE_get_signature_gap(protocol, error) \
- int protocol##_get_signature_gap ( \
- hicn_type_t type, const hicn_protocol_t *h, uint8_t *signature_size) \
+#define DECLARE_get_signature_padding(protocol, error) \
+ int protocol##_get_signature_padding ( \
+ hicn_type_t type, const hicn_protocol_t *h, size_t *padding) \
{ \
return HICN_LIB_ERROR_##error; \
}
@@ -860,6 +934,19 @@ PAYLOAD (hicn_type_t type, const hicn_protocol_t *h)
return HICN_LIB_ERROR_##error; \
}
+#define DECLARE_is_last_data(protocol, error) \
+ int protocol##_is_last_data (hicn_type_t type, const hicn_protocol_t *h, \
+ int *is_last) \
+ { \
+ return HICN_LIB_ERROR_##error; \
+ }
+
+#define DECLARE_set_last_data(protocol, error) \
+ int protocol##_set_last_data (hicn_type_t type, hicn_protocol_t *h) \
+ { \
+ return HICN_LIB_ERROR_##error; \
+ }
+
#endif /* HICN_OPS_H */
/*
diff --git a/lib/includes/hicn/policy.h b/lib/includes/hicn/policy.h
index e29888bd2..f39fa9272 100644
--- a/lib/includes/hicn/policy.h
+++ b/lib/includes/hicn/policy.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -30,37 +30,44 @@
/* POLICY TAG */
-#define foreach_policy_tag \
- /* Interface type */ \
- _(WIRED, 'E') \
- _(WIFI, 'W') \
- _(CELLULAR, 'C') \
- /* QoS */ \
- _(BEST_EFFORT, 'b') \
- _(REALTIME, 'r') \
- _(MULTIPATH, 'M') \
- /* Security */ \
- _(TRUSTED, 'T')
-
-typedef enum {
-#define _(x, y) POLICY_TAG_ ## x,
-foreach_policy_tag
+#define foreach_policy_tag \
+ /* Interface type */ \
+ _ (WIRED, 'E') \
+ _ (WIFI, 'W') \
+ _ (CELLULAR, 'C') \
+ /* QoS */ \
+ _ (BEST_EFFORT, 'b') \
+ _ (REALTIME, 'r') \
+ _ (MULTIPATH, 'M') \
+ /* Security */ \
+ _ (TRUSTED, 'T')
+
+typedef enum
+{
+#define _(x, y) POLICY_TAG_##x,
+ foreach_policy_tag
#undef _
POLICY_TAG_N
} policy_tag_t;
+#define IS_VALID_POLICY_TAG(x) (x != POLICY_TAG_N)
+
#define MAXSZ_POLICY_TAG_ 11
-#define MAXSZ_POLICY_TAG MAXSZ_POLICY_TAG_ + 1
+#define MAXSZ_POLICY_TAG MAXSZ_POLICY_TAG_ + 1
-extern const char * policy_tag_str[];
+extern const char *policy_tag_str[];
extern const char policy_tag_short_str[];
-static inline
-policy_tag_t
-policy_tag_from_str(const char * str)
+static inline policy_tag_t
+policy_tag_from_str (const char *str)
{
-#define _(x, y) if (strcasecmp(str, policy_tag_str[POLICY_TAG_ ## x] ) == 0) { return POLICY_TAG_ ## x; } else
-foreach_policy_tag
+#define _(x, y) \
+ if (strcasecmp (str, policy_tag_str[POLICY_TAG_##x]) == 0) \
+ { \
+ return POLICY_TAG_##x; \
+ } \
+ else
+ foreach_policy_tag
#undef _
return POLICY_TAG_N;
}
@@ -69,182 +76,188 @@ foreach_policy_tag
typedef int policy_tags_t;
-static inline
-void policy_tags_add(policy_tags_t * tags, policy_tag_t tag)
+static inline void
+policy_tags_add (policy_tags_t *tags, policy_tag_t tag)
{
- *tags |= (1 << tag);
+ *tags |= (1 << tag);
}
-static inline
-void policy_tags_remove(policy_tags_t * tags, policy_tag_t tag)
+static inline void
+policy_tags_remove (policy_tags_t *tags, policy_tag_t tag)
{
- *tags &= ~(1 << tag);
+ *tags &= ~(1 << tag);
}
-static inline
-int policy_tags_has(policy_tags_t tags, policy_tag_t tag)
+static inline int
+policy_tags_has (policy_tags_t tags, policy_tag_t tag)
{
- return tags & (1 << tag);
+ return tags & (1 << tag);
}
-static inline
-void policy_tags_union(policy_tags_t * tags, policy_tags_t * tags_to_union)
+static inline void
+policy_tags_union (policy_tags_t *tags, policy_tags_t *tags_to_union)
{
-#define _(x, y) *tags |= policy_tags_has(*tags_to_union, POLICY_TAG_ ## x) ? (1 << POLICY_TAG_ ## x) : 0;
-foreach_policy_tag
+#define _(x, y) \
+ *tags |= policy_tags_has (*tags_to_union, POLICY_TAG_##x) ? \
+ (1 << POLICY_TAG_##x) : \
+ 0;
+ foreach_policy_tag
#undef _
}
#define POLICY_TAGS_EMPTY 0
-static inline
-int
-policy_tags_snprintf(char * s, size_t size, policy_tags_t tags)
+static inline int
+policy_tags_snprintf (char *s, size_t size, policy_tags_t tags)
{
-#define _(x, y) s[POLICY_TAG_ ## x] = policy_tags_has(tags, POLICY_TAG_ ## x) ? y : '.';
-foreach_policy_tag
+#define _(x, y) \
+ s[POLICY_TAG_##x] = policy_tags_has (tags, POLICY_TAG_##x) ? y : '.';
+ foreach_policy_tag
#undef _
s[POLICY_TAG_N] = '\0';
- return POLICY_TAG_N + 1;
+ return POLICY_TAG_N + 1;
}
#define MAXSZ_POLICY_TAGS_ POLICY_TAG_N + 1
-#define MAXSZ_POLICY_TAGS MAXSZ_POLICY_TAGS_ + 1
+#define MAXSZ_POLICY_TAGS MAXSZ_POLICY_TAGS_ + 1
/* POLICY STATE */
/* TODO vs. weight */
-#define foreach_policy_state \
- _(NEUTRAL) \
- _(REQUIRE) \
- _(PREFER) \
- _(AVOID) \
- _(PROHIBIT) \
- _(N)
-
-typedef enum {
-#define _(x) POLICY_STATE_ ## x,
-foreach_policy_state
+#define foreach_policy_state \
+ _ (NEUTRAL) \
+ _ (REQUIRE) \
+ _ (PREFER) \
+ _ (AVOID) \
+ _ (PROHIBIT) \
+ _ (N)
+
+typedef enum
+{
+#define _(x) POLICY_STATE_##x,
+ foreach_policy_state
#undef _
} policy_state_t;
#define MAXSZ_POLICY_STATE_ 8
-#define MAXSZ_POLICY_STATE MAXSZ_POLICY_STATE_ + 1
+#define MAXSZ_POLICY_STATE MAXSZ_POLICY_STATE_ + 1
+
+extern const char *policy_state_str[];
-extern const char * policy_state_str[];
+#define policy_state_str(x) policy_state_str[x]
+policy_state_t policy_state_from_str (const char *str);
/* POLICY TAG STATE */
-typedef struct {
- policy_state_t state;
- uint8_t disabled;
+typedef struct
+{
+ policy_state_t state;
+ uint8_t disabled;
} policy_tag_state_t;
#define MAXSZ_POLICY_TAG_STATE_ 8
-#define MAXSZ_POLICY_TAG_STATE MAXSZ_POLICY_TAG_STATE_ + 1
-
-int policy_tag_state_snprintf(char * s, size_t size, const policy_tag_state_t * tag_state);
+#define MAXSZ_POLICY_TAG_STATE MAXSZ_POLICY_TAG_STATE_ + 1
+int policy_tag_state_snprintf (char *s, size_t size,
+ const policy_tag_state_t *tag_state);
/* INTERFACE STATS */
-typedef struct {
- float throughput;
- float latency;
- float loss_rate;
+typedef struct
+{
+ float throughput;
+ float latency;
+ float loss_rate;
} interface_stats_t;
-#define INTERFACE_STATS_NONE { \
- .throughput = 0, \
- .latency = 0, \
- .loss_rate = 0, \
-}
-
+#define INTERFACE_STATS_EMPTY \
+ { \
+ .throughput = 0, .latency = 0, .loss_rate = 0, \
+ }
/* POLICY STATS */
-typedef struct {
- interface_stats_t wired;
- interface_stats_t wifi;
- interface_stats_t cellular;
- interface_stats_t all;
+typedef struct
+{
+ interface_stats_t wired;
+ interface_stats_t wifi;
+ interface_stats_t cellular;
+ interface_stats_t all;
} policy_stats_t;
-#define POLICY_STATS_NONE { \
- .wired = INTERFACE_STATS_NONE, \
- .wifi = INTERFACE_STATS_NONE, \
- .cellular = INTERFACE_STATS_NONE, \
- .all = INTERFACE_STATS_NONE, \
-}
+#define POLICY_STATS_EMPTY \
+ (policy_stats_t) \
+ { \
+ .wired = INTERFACE_STATS_EMPTY, .wifi = INTERFACE_STATS_EMPTY, \
+ .cellular = INTERFACE_STATS_EMPTY, .all = INTERFACE_STATS_EMPTY, \
+ }
-typedef struct {
- uint32_t num_packets;
- uint32_t num_bytes;
- uint32_t num_losses;
- uint32_t latency_idle;
+typedef struct
+{
+ uint32_t num_packets;
+ uint32_t num_bytes;
+ uint32_t num_losses;
+ uint32_t latency_idle;
} interface_counters_t;
-#define INTERFACE_COUNTERS_NONE { \
- .num_packets = 0, \
- .num_bytes = 0, \
- .num_losses = 0, \
- .latency_idle = 0, \
-}
+#define INTERFACE_COUNTERS_EMPTY \
+ { \
+ .num_packets = 0, .num_bytes = 0, .num_losses = 0, .latency_idle = 0, \
+ }
-typedef struct {
- interface_counters_t wired;
- interface_counters_t wifi;
- interface_counters_t cellular;
- interface_counters_t all;
- uint64_t last_update;
+typedef struct
+{
+ interface_counters_t wired;
+ interface_counters_t wifi;
+ interface_counters_t cellular;
+ interface_counters_t all;
+ uint64_t last_update;
} policy_counters_t;
-#define POLICY_COUNTERS_NONE (policy_counters_t) { \
- .wired = INTERFACE_COUNTERS_NONE, \
- .wifi = INTERFACE_COUNTERS_NONE, \
- .cellular = INTERFACE_COUNTERS_NONE, \
- .all = INTERFACE_COUNTERS_NONE, \
- .last_update = 0, \
-}
+#define POLICY_COUNTERS_EMPTY \
+ (policy_counters_t) \
+ { \
+ .wired = INTERFACE_COUNTERS_EMPTY, .wifi = INTERFACE_COUNTERS_EMPTY, \
+ .cellular = INTERFACE_COUNTERS_EMPTY, .all = INTERFACE_COUNTERS_EMPTY, \
+ .last_update = 0, \
+ }
/* POLICY */
#define APP_NAME_LEN 128
-typedef struct {
- char app_name[APP_NAME_LEN];
- policy_tag_state_t tags[POLICY_TAG_N];
- policy_stats_t stats;
+typedef struct
+{
+ char app_name[APP_NAME_LEN];
+ policy_tag_state_t tags[POLICY_TAG_N];
+ policy_stats_t stats;
} hicn_policy_t;
-static const hicn_policy_t POLICY_NONE = {
+static const hicn_policy_t POLICY_EMPTY = {
.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 _
},
- .stats = POLICY_STATS_NONE,
+ .stats = POLICY_STATS_EMPTY,
};
-
/* POLICY DESCRIPTION */
#define PFX_STRLEN 4 /* eg. /128 */
-typedef struct {
- int family;
- union {
- char ipv4_prefix[INET_ADDRSTRLEN + PFX_STRLEN];
- char ipv6_prefix[INET6_ADDRSTRLEN + PFX_STRLEN];
- };
- hicn_policy_t policy;
+typedef struct
+{
+ int family;
+ union
+ {
+ char ipv4_prefix[INET_ADDRSTRLEN + PFX_STRLEN];
+ char ipv6_prefix[INET6_ADDRSTRLEN + PFX_STRLEN];
+ };
+ hicn_policy_t policy;
} policy_description_t;
#endif /* HICN_POLICY_H */
diff --git a/lib/includes/hicn/protocol.h b/lib/includes/hicn/protocol.h
index a97cc99cf..fb142e4c3 100644
--- a/lib/includes/hicn/protocol.h
+++ b/lib/includes/hicn/protocol.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -27,9 +27,11 @@
#include "protocol/icmprd.h"
#include "protocol/tcp.h"
#include "protocol/udp.h"
+#include "protocol/new.h"
typedef union
{
+ _new_header_t newhdr;
_ipv4_header_t ipv4;
_ipv6_header_t ipv6;
_tcp_header_t tcp;
diff --git a/lib/includes/hicn/protocol/ah.h b/lib/includes/hicn/protocol/ah.h
index 575da80d7..36fd7d509 100644
--- a/lib/includes/hicn/protocol/ah.h
+++ b/lib/includes/hicn/protocol/ah.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -35,19 +35,19 @@
typedef struct
{
- u8 nh; // (to match with reserved in IPSEC AH)
- u8 payloadlen; // Len of signature/HMAC in 4-bytes words (maximum size)
+ u8 nh; // To match with reserved in IPSEC AH
+ // Length of the signature field. Note that the signature might be smaller
+ // than the field: the actual size is computed from the field size and
+ // signaturePadding.
+ u8 payloadlen;
union
{
u16 reserved;
struct
{
- u8 validationAlgorithm; // As defined in parc_SignerAlgorithm.h
- u8 signatureGap; // used to match IPSEC specification and to
- // have the real size of the signature(without
- // padding). It is the result of Maximum
- // signature size - real size
+ u8 validationAlgorithm;
+ u8 signaturePadding;
};
};
union
diff --git a/lib/includes/hicn/protocol/icmp.h b/lib/includes/hicn/protocol/icmp.h
index 36954bb6d..9315e1e56 100644
--- a/lib/includes/hicn/protocol/icmp.h
+++ b/lib/includes/hicn/protocol/icmp.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -34,7 +34,7 @@ typedef struct
u16 csum;
} _icmp_header_t;
-#define ICMP_HDRLEN sizeof(_icmp_header_t)
+#define ICMP_HDRLEN sizeof (_icmp_header_t)
static_assert (EXPECTED_ICMP_HDRLEN == ICMP_HDRLEN,
"Size of ICMP struct does not match its expected size.");
@@ -54,13 +54,13 @@ typedef struct
{
u16 id;
u16 sequence;
- } echo; /* echo datagram */
- u32 gateway; /* gateway address */
+ } echo; /* echo datagram */
+ u32 gateway; /* gateway address */
struct
{
u16 _unused;
u16 mtu;
- } frag; /* path mtu discovery */
+ } frag; /* path mtu discovery */
struct
{
u16 expected_lbl;
@@ -69,7 +69,7 @@ typedef struct
};
} _icmp_wldr_header_t;
-#define ICMPWLDR_HDRLEN sizeof(_icmp_wldr_header_t)
+#define ICMPWLDR_HDRLEN sizeof (_icmp_wldr_header_t)
static_assert (EXPECTED_ICMPWLDR_HDRLEN == ICMPWLDR_HDRLEN,
"Size of ICMPWLDR struct does not match its expected size.");
diff --git a/lib/includes/hicn/protocol/icmprd.h b/lib/includes/hicn/protocol/icmprd.h
index aa1fa01ae..897e7969e 100644
--- a/lib/includes/hicn/protocol/icmprd.h
+++ b/lib/includes/hicn/protocol/icmprd.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -38,7 +38,7 @@ typedef struct
u8 data[64];
} _icmprd4_header_t;
-#define ICMPRD4_HDRLEN sizeof(_icmprd4_header_t)
+#define ICMPRD4_HDRLEN sizeof (_icmprd4_header_t)
static_assert (EXPECTED_ICMPRD4_HDRLEN == ICMPRD4_HDRLEN,
"Size of ICMPWLDR struct does not match its expected size.");
@@ -57,7 +57,7 @@ typedef struct
ip6_address_t dst;
} _icmprd_header_t;
-#define ICMPRD_HDRLEN sizeof(_icmprd_header_t)
+#define ICMPRD_HDRLEN sizeof (_icmprd_header_t)
static_assert (EXPECTED_ICMPRD_HDRLEN == ICMPRD_HDRLEN,
"Size of ICMPWLDR struct does not match its expected size.");
diff --git a/lib/includes/hicn/protocol/ipv4.h b/lib/includes/hicn/protocol/ipv4.h
index 8a5b6683b..44e95c1e3 100644
--- a/lib/includes/hicn/protocol/ipv4.h
+++ b/lib/includes/hicn/protocol/ipv4.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -16,9 +16,10 @@
#ifndef HICN_PROTOCOL_IPV4
#define HICN_PROTOCOL_IPV4
+#include <hicn/util/ip_address.h>
+
#include "../base.h"
#include "../common.h"
-#include "../protocol.h"
/* Headers were adapted from linux' definitions in netinet/ip.h */
@@ -34,11 +35,11 @@ typedef struct
struct
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
- u8 ihl:4;
- u8 version:4;
+ u8 ihl : 4;
+ u8 version : 4;
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
- u8 version:4;
- u8 ihl:4;
+ u8 version : 4;
+ u8 ihl : 4;
#else
#error "Unsupported endianness"
#endif
@@ -57,9 +58,10 @@ typedef struct
ip4_address_t daddr;
} _ipv4_header_t;
-#define ipv4_header_bytes(ipv4_header) (sizeof(u32) * (ipv4_header->version_ihl & 0xf))
+#define ipv4_header_bytes(ipv4_header) \
+ (sizeof (u32) * (ipv4_header->version_ihl & 0xf))
-#define IPV4_HDRLEN sizeof(_ipv4_header_t)
+#define IPV4_HDRLEN sizeof (_ipv4_header_t)
static_assert (EXPECTED_IPV4_HDRLEN == IPV4_HDRLEN,
"Size of IPV4 struct does not match its expected size.");
@@ -77,22 +79,21 @@ typedef struct
u16 size;
} ipv4_pseudo_header_t;
-#define IPV4_PSHDRLEN sizeof(ipv4_pseudo_header_t)
+#define IPV4_PSHDRLEN sizeof (ipv4_pseudo_header_t)
static_assert (EXPECTED_IPV4_PSHDRLEN == IPV4_PSHDRLEN,
"Size of IPV4_PSHDR struct does not match its expected size.");
/* Default field values */
-#define IPV4_DEFAULT_VERSION 4
-#define IPV4_DEFAULT_IHL 5
-#define IPV4_DEFAULT_TOS 0
-#define IPV4_DEFAULT_PAYLOAD_LENGTH 0
-#define IPV4_DEFAULT_ID 300
-#define IPV4_DEFAULT_FRAG_OFF 0x000
-#define IPV4_DEFAULT_TTL 64
-#define IPV4_DEFAULT_PROTOCOL IPPROTO_TCP
-#define IPV4_DEFAULT_SRC_IP 0, 0, 0, 0
-#define IPV4_DEFAULT_DST_IP 0, 0, 0, 0
-
+#define IPV4_DEFAULT_VERSION 4
+#define IPV4_DEFAULT_IHL 5
+#define IPV4_DEFAULT_TOS 0
+#define IPV4_DEFAULT_PAYLOAD_LENGTH 0
+#define IPV4_DEFAULT_ID 300
+#define IPV4_DEFAULT_FRAG_OFF 0x000
+#define IPV4_DEFAULT_TTL 64
+#define IPV4_DEFAULT_PROTOCOL IPPROTO_TCP
+#define IPV4_DEFAULT_SRC_IP 0, 0, 0, 0
+#define IPV4_DEFAULT_DST_IP 0, 0, 0, 0
#endif /* HICN_PROTOCOL_IPV4 */
diff --git a/lib/includes/hicn/protocol/ipv6.h b/lib/includes/hicn/protocol/ipv6.h
index 5a83abcae..86301e7d1 100644
--- a/lib/includes/hicn/protocol/ipv6.h
+++ b/lib/includes/hicn/protocol/ipv6.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -16,6 +16,8 @@
#ifndef HICN_PROTOCOL_IPV6_H
#define HICN_PROTOCOL_IPV6_H
+#include <hicn/util/ip_address.h>
+
#include "../common.h"
/*
@@ -25,22 +27,26 @@
typedef struct
{
+#if 0 // TEMPORARY FIX
union
{
struct
{
- u32 version_class_flow; /* version, traffic class and 20 bits of flow-ID */
- u16 len; /* payload length */
- u8 nxt; /* next header */
- u8 hlim; /* hop limit */
+#endif
+ u32 version_class_flow; /* version, traffic class and 20 bits of flow-ID */
+ u16 len; /* payload length */
+ u8 nxt; /* next header */
+ u8 hlim; /* hop limit */
+#if 0
};
u8 vfc; /* 4 bits version, top 4 bits class */
};
- ip6_address_t saddr; /* source address */
- ip6_address_t daddr; /* destination address */
+#endif
+ ip6_address_t saddr; /* source address */
+ ip6_address_t daddr; /* destination address */
} _ipv6_header_t;
-#define IPV6_HDRLEN sizeof(_ipv6_header_t)
+#define IPV6_HDRLEN sizeof (_ipv6_header_t)
static_assert (EXPECTED_IPV6_HDRLEN == IPV6_HDRLEN,
"Size of IPV6 struct does not match its expected size.");
@@ -59,15 +65,15 @@ typedef struct
u8 protocol;
} ipv6_pseudo_header_t;
-#define IPV6_PSHDRLEN sizeof(ipv6_pseudo_header_t)
+#define IPV6_PSHDRLEN sizeof (ipv6_pseudo_header_t)
static_assert (EXPECTED_IPV6_PSHDRLEN == IPV6_PSHDRLEN,
"Size of IPV6_PSHDR struct does not match its expected size.");
/* Default field values */
-#define IPV6_DEFAULT_VERSION 6
-#define IPV6_DEFAULT_TRAFFIC_CLASS 0
-#define IPV6_DEFAULT_FLOW_LABEL 0
-#define IPV6_DEFAULT_PAYLOAD_LENGTH 0
+#define IPV6_DEFAULT_VERSION 6
+#define IPV6_DEFAULT_TRAFFIC_CLASS 0
+#define IPV6_DEFAULT_FLOW_LABEL 0
+#define IPV6_DEFAULT_PAYLOAD_LENGTH 0
#endif
diff --git a/lib/includes/hicn/protocol/new.h b/lib/includes/hicn/protocol/new.h
new file mode 100644
index 000000000..47f7758d2
--- /dev/null
+++ b/lib/includes/hicn/protocol/new.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2021 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 protocol/ah.h
+ * @brief AH packet header
+ */
+#ifndef HICN_PROTOCOL_NEW_H
+#define HICN_PROTOCOL_NEW_H
+
+#include "../common.h"
+#include "../name.h"
+
+/*
+ * The length of the new header struct must be 28 bytes.
+ */
+#define EXPECTED_NEW_HDRLEN 32
+
+typedef struct
+{
+ u8 version_reserved;
+ u8 flags;
+ u16 payload_length;
+ u32 lifetime;
+ ip_address_t prefix;
+ u32 suffix;
+ u32 path_label;
+} _new_header_t;
+
+#define NEW_HDRLEN sizeof (_new_header_t)
+static_assert (EXPECTED_NEW_HDRLEN == NEW_HDRLEN,
+ "Size of new_header Struct does not match its expected size.");
+
+/* TCP flags bit 0 first. */
+#define foreach_hicn_new_flag \
+ _ (SIG) /**< Signature header after. */ \
+ _ (MAN) /**< Payload type is manifest. */ \
+ _ (INT) /**< Packet is interest. */ \
+ _ (LST) /**< Last data. */
+
+enum
+{
+#define _(f) HICN_NEW_FLAG_BIT_##f,
+ foreach_hicn_new_flag
+#undef _
+ HICN_NEW_N_FLAG_BITS,
+};
+
+enum
+{
+#define _(f) HICN_NEW_FLAG_##f = 1 << HICN_NEW_FLAG_BIT_##f,
+ foreach_hicn_new_flag
+#undef _
+};
+
+static inline int
+_get_new_header_version (const _new_header_t *new_hdr)
+{
+ return ((new_hdr->version_reserved >> 4) & 0x0F);
+}
+
+static inline void
+_set_new_header_version (_new_header_t *new_hdr)
+{
+ new_hdr->version_reserved = (0x9 << 4) & 0xF0;
+}
+
+#endif /* HICN_PROTOCOL_NEW_H */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/lib/includes/hicn/protocol/tcp.h b/lib/includes/hicn/protocol/tcp.h
index 347682299..1731f0c24 100644
--- a/lib/includes/hicn/protocol/tcp.h
+++ b/lib/includes/hicn/protocol/tcp.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -59,55 +59,55 @@ typedef struct
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
struct
{
- u16 reserved:4;
- u16 doff:4;
- u16 fin:1;
- u16 syn:1;
- u16 rst:1;
- u16 psh:1;
- u16 ack:1;
- u16 urg:1;
- u16 ece:1;
- u16 cwr:1;
+ u16 reserved : 4;
+ u16 doff : 4;
+ u16 fin : 1;
+ u16 syn : 1;
+ u16 rst : 1;
+ u16 psh : 1;
+ u16 ack : 1;
+ u16 urg : 1;
+ u16 ece : 1;
+ u16 cwr : 1;
};
struct
- { /* __ denotes unchanged bitfields */
- u16 timescale:4;
- u16 __doff:4;
- u16 __fin:1;
- u16 __syn:1;
- u16 __rst:1;
- u16 sig:1;
- u16 __ack:1;
- u16 man:1;
- u16 id:1;
- u16 __cwr:1;
+ { /* __ denotes unchanged bitfields */
+ u16 timescale : 4;
+ u16 __doff : 4;
+ u16 __fin : 1;
+ u16 __syn : 1;
+ u16 __rst : 1;
+ u16 sig : 1;
+ u16 __ack : 1;
+ u16 man : 1;
+ u16 id : 1;
+ u16 __cwr : 1;
};
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
struct
{
- u16 doff:4;
- u16 reserved:4;
- u16 cwr:1;
- u16 ece:1;
- u16 urg:1;
- u16 ack:1;
- u16 psh:1;
- u16 rst:1;
- u16 syn:1;
- u16 fin:1;
+ u16 doff : 4;
+ u16 reserved : 4;
+ u16 cwr : 1;
+ u16 ece : 1;
+ u16 urg : 1;
+ u16 ack : 1;
+ u16 psh : 1;
+ u16 rst : 1;
+ u16 syn : 1;
+ u16 fin : 1;
};
struct
{
- u16 __doff:4;
- u16 timescale:4;
- u16 __cwr:1;
- u16 id:1 u16 man:1;
- u16 __ack:1;
- u16 sig:1;
- u16 __rst:1;
- u16 __syn:1;
- u16 __fin:1;
+ u16 __doff : 4;
+ u16 timescale : 4;
+ u16 __cwr : 1;
+ u16 id : 1 u16 man : 1;
+ u16 __ack : 1;
+ u16 sig : 1;
+ u16 __rst : 1;
+ u16 __syn : 1;
+ u16 __fin : 1;
};
#endif
};
@@ -124,20 +124,20 @@ typedef struct
};
} _tcp_header_t;
-#define TCP_HDRLEN sizeof(_tcp_header_t)
+#define TCP_HDRLEN sizeof (_tcp_header_t)
static_assert (EXPECTED_TCP_HDRLEN == TCP_HDRLEN,
"Size of TCP struct does not match its expected size.");
/* TCP flags bit 0 first. */
-#define foreach_tcp_flag \
- _ (FIN) /**< No more data from sender. */ \
- _ (SYN) /**< Synchronize sequence numbers. */ \
- _ (RST) /**< Reset the connection. */ \
- _ (PSH) /**< Push function. */ \
- _ (ACK) /**< Ack field significant. */ \
- _ (URG) /**< Urgent pointer field significant. */ \
- _ (ECE) /**< ECN-echo. Receiver got CE packet */ \
- _ (CWR) /**< Sender reduced congestion window */
+#define foreach_tcp_flag \
+ _ (FIN) /**< No more data from sender. */ \
+ _ (SYN) /**< Synchronize sequence numbers. */ \
+ _ (RST) /**< Reset the connection. */ \
+ _ (PSH) /**< Push function. */ \
+ _ (ACK) /**< Ack field significant. */ \
+ _ (URG) /**< Urgent pointer field significant. */ \
+ _ (ECE) /**< ECN-echo. Receiver got CE packet */ \
+ _ (CWR) /**< Sender reduced congestion window */
enum
{
diff --git a/lib/includes/hicn/protocol/udp.h b/lib/includes/hicn/protocol/udp.h
index 75d1ea98c..0e0dddd2c 100644
--- a/lib/includes/hicn/protocol/udp.h
+++ b/lib/includes/hicn/protocol/udp.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -29,7 +29,7 @@ typedef struct
u16 checksum;
} _udp_header_t;
-#define UDP_HDRLEN sizeof(_udp_header_t)
+#define UDP_HDRLEN sizeof (_udp_header_t)
static_assert (EXPECTED_UDP_HDRLEN == UDP_HDRLEN,
"Size of UDP struct does not match its expected size.");
diff --git a/lib/includes/hicn/strategy.h b/lib/includes/hicn/strategy.h
new file mode 100644
index 000000000..c71db451a
--- /dev/null
+++ b/lib/includes/hicn/strategy.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2021 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
+
+#include <string.h>
+
+#define foreach_strategy_type \
+ _ (UNDEFINED) \
+ _ (LOADBALANCER) \
+ _ (LOW_LATENCY) \
+ _ (RANDOM) \
+ _ (REPLICATION) \
+ _ (BESTPATH) \
+ _ (N)
+
+typedef enum
+{
+#define _(x) STRATEGY_TYPE_##x,
+ foreach_strategy_type
+#undef _
+} strategy_type_t;
+
+extern const char *strategy_str[];
+#define strategy_str(x) strategy_str[x]
+
+#define IS_VALID_STRATEGY_TYPE(x) IS_VALID_ENUM_TYPE (STRATEGY_TYPE, x)
+
+static inline strategy_type_t
+strategy_type_from_str (const char *strategy_str)
+{
+#define _(x) \
+ if (strcasecmp (strategy_str, #x) == 0) \
+ return STRATEGY_TYPE_##x; \
+ else
+ foreach_strategy_type
+#undef _
+ return STRATEGY_TYPE_UNDEFINED;
+}
+
+#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/array.h b/lib/includes/hicn/util/array.h
index 56cfcad8b..46d60976e 100644
--- a/lib/includes/hicn/util/array.h
+++ b/lib/includes/hicn/util/array.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -23,178 +23,169 @@
#include <assert.h>
#include <hicn/util/log.h>
-#include <math.h> // log2
+#include <math.h> // log2
#include <string.h> // memmove
#define BUFSIZE 1024
-typedef int(*cmp_t)(const void * x, const void * y);
-
-#define TYPEDEF_ARRAY_H(NAME, T) \
- \
-typedef struct { \
- size_t size; \
- size_t max_size_log; \
- T * elements; \
-} NAME ## _t; \
- \
-int NAME ## _initialize(NAME ## _t * array); \
- \
-int NAME ## _finalize(NAME ## _t * array); \
- \
-NAME ## _t * NAME ## _create(); \
- \
-void NAME ## _free(NAME ## _t * array); \
- \
-int NAME ## _add(NAME ## _t * array, T element); \
- \
-int NAME ## _remove_index(NAME ## _t * array, int index, T * element); \
- \
-int NAME ## _remove(NAME ## _t * array, const T search, T * element); \
- \
-int NAME ## _get(const NAME ## _t * array, const T search, T * element); \
- \
-int NAME ## _get_index(const NAME ## _t * array, int index, T * element); \
- \
-int NAME ## _get_elements(const NAME ## _t * array, T ** elements); \
- \
-size_t NAME ## _len(const NAME ## _t * array);
+typedef int (*cmp_t) (const void *x, const void *y);
+#define TYPEDEF_ARRAY_H(NAME, T) \
+ \
+ typedef struct \
+ { \
+ size_t size; \
+ size_t max_size_log; \
+ T *elements; \
+ } NAME##_t; \
+ \
+ int NAME##_initialize (NAME##_t *array); \
+ \
+ int NAME##_finalize (NAME##_t *array); \
+ \
+ NAME##_t *NAME##_create (); \
+ \
+ void NAME##_free (NAME##_t *array); \
+ \
+ int NAME##_add (NAME##_t *array, T element); \
+ \
+ int NAME##_remove_index (NAME##_t *array, int index, T *element); \
+ \
+ int NAME##_remove (NAME##_t *array, const T search, T *element); \
+ \
+ int NAME##_get (const NAME##_t *array, const T search, T *element); \
+ \
+ int NAME##_get_index (const NAME##_t *array, int index, T *element); \
+ \
+ int NAME##_get_elements (const NAME##_t *array, T **elements); \
+ \
+ size_t NAME##_len (const NAME##_t *array);
#define ARRAY_MAX_SIZE_LOG_INIT 0
-#define TYPEDEF_ARRAY(NAME, T, CMP, SNPRINTF) \
-int \
-NAME ## _initialize(NAME ## _t * array) \
-{ \
- array->max_size_log = ARRAY_MAX_SIZE_LOG_INIT; \
- array->size = 0; \
- if (array->max_size_log == 0) { \
- array->elements = NULL; \
- return 0; \
- } \
- array->elements = malloc((1 << array->max_size_log) * sizeof(T)); \
- if (!array->elements) \
- return -1; \
- return 0; \
-} \
- \
-int \
-NAME ## _finalize(NAME ## _t * array) \
-{ \
- for (unsigned i = 0; i < array->size; i++) { \
- NAME ## _remove_index(array, i, NULL); \
- } \
- return 0; \
-} \
- \
-NAME ## _t * \
-NAME ## _create() \
-{ \
- NAME ## _t * array = malloc(sizeof(NAME ## _t)); \
- if (!array) \
- goto ERR_MALLOC; \
- \
- if (NAME ## _initialize(array) < 0) \
- goto ERR_INITIALIZE; \
- \
- return array; \
- \
-ERR_INITIALIZE: \
- free(array); \
-ERR_MALLOC: \
- return NULL; \
-} \
- \
-void \
-NAME ## _free(NAME ## _t * array) \
-{ \
- NAME ## _finalize(array); \
- free(array->elements); \
- free(array); \
-} \
- \
-int \
-NAME ## _add(NAME ## _t * array, T element) \
-{ \
- /* Ensure sufficient space for next addition */ \
- size_t new_size_log = (array->size > 0) ? log2(array->size)+1 : 1; \
- if (new_size_log > array->max_size_log) { \
- array->max_size_log = new_size_log; \
- array->elements = realloc(array->elements, \
- (1 << new_size_log) * sizeof(T)); \
- } \
- \
- if (!array->elements) \
- goto ERR_REALLOC; \
- \
- array->elements[array->size++] = element; \
- return 0; \
- \
-ERR_REALLOC: \
- return -1; \
-} \
- \
-int \
-NAME ## _remove_index(NAME ## _t * array, int index, T * element) \
-{ \
- if (index > NAME ## _len(array)) \
- return -1; \
- if (element) \
- *element = array->elements[index]; \
- if (index < array->size) \
- memmove(array->elements + index, array->elements + index + 1, \
- array->size - index); \
- array->size--; \
- return 0; \
-} \
- \
-int \
-NAME ## _remove(NAME ## _t * array, const T search, T * element) \
-{ \
- for (unsigned i = 0; i < array->size; i++) { \
- if (CMP(search, array->elements[i]) == 0) \
- return facelet_array_remove_index(array, i, element); \
- } \
- /* Not found */ \
- if (element) \
- *element = NULL; \
- return 0; \
-} \
- \
-int \
-NAME ## _get(const NAME ## _t * array, const T search, T * element) \
-{ \
- assert(element); \
- for (unsigned i = 0; i < array->size; i++) \
- if (CMP(search, array->elements[i]) == 0) { \
- *element = array->elements[i]; \
- return 0; \
- } \
- /* Not found */ \
- *element = NULL; \
- return 0; \
-} \
- \
-int \
-NAME ## _get_index(const NAME ## _t * array, int index, T * element) \
-{ \
- assert(element); \
- *element = array->elements[index]; \
- return 0; \
-} \
- \
-int \
-NAME ## _get_elements(const NAME ## _t * array, T ** elements) \
-{ \
- *elements = array->elements; \
- return 0; \
-} \
- \
-size_t \
-NAME ## _len(const NAME ## _t * array) \
-{ \
- return array->size; \
-}
+#define TYPEDEF_ARRAY(NAME, T, CMP, SNPRINTF) \
+ int NAME##_initialize (NAME##_t *array) \
+ { \
+ array->max_size_log = ARRAY_MAX_SIZE_LOG_INIT; \
+ array->size = 0; \
+ if (array->max_size_log == 0) \
+ { \
+ array->elements = NULL; \
+ return 0; \
+ } \
+ array->elements = malloc ((1 << array->max_size_log) * sizeof (T)); \
+ if (!array->elements) \
+ return -1; \
+ return 0; \
+ } \
+ \
+ int NAME##_finalize (NAME##_t *array) \
+ { \
+ for (unsigned i = 0; i < array->size; i++) \
+ { \
+ NAME##_remove_index (array, i, NULL); \
+ } \
+ return 0; \
+ } \
+ \
+ NAME##_t *NAME##_create () \
+ { \
+ NAME##_t *array = malloc (sizeof (NAME##_t)); \
+ if (!array) \
+ goto ERR_MALLOC; \
+ \
+ if (NAME##_initialize (array) < 0) \
+ goto ERR_INITIALIZE; \
+ \
+ return array; \
+ \
+ ERR_INITIALIZE: \
+ free (array); \
+ ERR_MALLOC: \
+ return NULL; \
+ } \
+ \
+ void NAME##_free (NAME##_t *array) \
+ { \
+ NAME##_finalize (array); \
+ free (array->elements); \
+ free (array); \
+ } \
+ \
+ int NAME##_add (NAME##_t *array, T element) \
+ { \
+ /* Ensure sufficient space for next addition */ \
+ size_t new_size_log = (array->size > 0) ? log2 (array->size) + 1 : 1; \
+ if (new_size_log > array->max_size_log) \
+ { \
+ array->max_size_log = new_size_log; \
+ array->elements = \
+ realloc (array->elements, (1 << new_size_log) * sizeof (T)); \
+ } \
+ \
+ if (!array->elements) \
+ goto ERR_REALLOC; \
+ \
+ array->elements[array->size++] = element; \
+ return 0; \
+ \
+ ERR_REALLOC: \
+ return -1; \
+ } \
+ \
+ int NAME##_remove_index (NAME##_t *array, int index, T *element) \
+ { \
+ if (index > NAME##_len (array)) \
+ return -1; \
+ if (element) \
+ *element = array->elements[index]; \
+ if (index < array->size) \
+ memmove (array->elements + index, array->elements + index + 1, \
+ array->size - index); \
+ array->size--; \
+ return 0; \
+ } \
+ \
+ int NAME##_remove (NAME##_t *array, const T search, T *element) \
+ { \
+ for (unsigned i = 0; i < array->size; i++) \
+ { \
+ if (CMP (search, array->elements[i]) == 0) \
+ return facelet_array_remove_index (array, i, element); \
+ } \
+ /* Not found */ \
+ if (element) \
+ *element = NULL; \
+ return 0; \
+ } \
+ \
+ int NAME##_get (const NAME##_t *array, const T search, T *element) \
+ { \
+ assert (element); \
+ for (unsigned i = 0; i < array->size; i++) \
+ if (CMP (search, array->elements[i]) == 0) \
+ { \
+ *element = array->elements[i]; \
+ return 0; \
+ } \
+ /* Not found */ \
+ *element = NULL; \
+ return 0; \
+ } \
+ \
+ int NAME##_get_index (const NAME##_t *array, int index, T *element) \
+ { \
+ assert (element); \
+ *element = array->elements[index]; \
+ return 0; \
+ } \
+ \
+ int NAME##_get_elements (const NAME##_t *array, T **elements) \
+ { \
+ *elements = array->elements; \
+ return 0; \
+ } \
+ \
+ size_t NAME##_len (const NAME##_t *array) { return array->size; }
#endif /* UTIL_ARRAY_H */
diff --git a/lib/includes/hicn/util/ip_address.h b/lib/includes/hicn/util/ip_address.h
index 4facd9ad0..89a4c11e0 100644
--- a/lib/includes/hicn/util/ip_address.h
+++ b/lib/includes/hicn/util/ip_address.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -20,10 +20,9 @@
#ifndef UTIL_IP_ADDRESS_H
#define UTIL_IP_ADDRESS_H
-
#ifdef __APPLE__
#include <libkern/OSByteOrder.h>
-#define __bswap_constant_32(x) OSSwapInt32(x)
+#define __bswap_constant_32(x) OSSwapInt32 (x)
#include <machine/endian.h>
#else
#ifdef __ANDROID__
@@ -34,8 +33,8 @@
#include <errno.h>
#ifndef _WIN32
-#include <netinet/in.h> // struct sockadd
-#include <arpa/inet.h> // inet_ntop
+#include <netinet/in.h> // struct sockadd
+#include <arpa/inet.h>
#include <netdb.h> // struct addrinfo
#endif
#include <stdbool.h>
@@ -45,11 +44,12 @@
#include "types.h"
-#define bytes_to_bits(x) (x * 8)
-#define IPV6_ADDR_LEN 16 /* bytes */
-#define IPV4_ADDR_LEN 4 /* bytes */
-#define IPV6_ADDR_LEN_BITS bytes_to_bits(IPV6_ADDR_LEN)
-#define IPV4_ADDR_LEN_BITS bytes_to_bits(IPV4_ADDR_LEN)
+#define bytes_to_bits(x) (x * 8)
+#define IPV6_ADDR_LEN 16 /* bytes */
+#define IPV4_ADDR_LEN 4 /* bytes */
+#define IPV6_ADDR_LEN_BITS bytes_to_bits (IPV6_ADDR_LEN)
+#define IPV4_ADDR_LEN_BITS bytes_to_bits (IPV4_ADDR_LEN)
+#define MAX_IPV6_PREFIX_LEN 128
/* Presentation format */
#ifndef INET_ADDRSTRLEN
@@ -65,25 +65,34 @@
#define DUMMY_PORT 1234
-typedef union {
- struct {
- u32 pad[3];
- union {
- struct in_addr as_inaddr;
- u8 buffer[4];
- u8 as_u8[4];
- u16 as_u16[2];
- u32 as_u32;
- } v4;
- };
- union {
- struct in6_addr as_in6addr;
- u8 buffer[16];
- u8 as_u8[16];
- u16 as_u16[8];
- u32 as_u32[4];
- u64 as_u64[2];
- } v6;
+#ifndef HICN_VPP_PLUGIN
+typedef union
+{
+ struct in_addr as_inaddr;
+ u8 buffer[4];
+ u8 as_u8[4];
+ u16 as_u16[2];
+ u32 as_u32;
+} ip4_address_t;
+
+typedef union
+{
+ struct in6_addr as_in6addr;
+ u8 buffer[16];
+ u8 as_u8[16];
+ u16 as_u16[8];
+ u32 as_u32[4];
+ u64 as_u64[2];
+} ip6_address_t;
+
+typedef union
+{
+ struct
+ {
+ u32 pad[3];
+ ip4_address_t v4;
+ };
+ ip6_address_t v6;
#if 0 /* removed as prone to error due to IPv4 padding */
u8 buffer[IP_MAX_ADDR_LEN];
u8 as_u8[IP_MAX_ADDR_LEN];
@@ -93,77 +102,105 @@ typedef union {
#endif
} ip_address_t;
+#else
+
+#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
+
+typedef ip46_address_t ip_address_t;
+
+#endif /* HICN_VPP_PLUGIN */
+
+#define ip_address_is_v4(ip) \
+ (((ip)->pad[0] | (ip)->pad[1] | (ip)->pad[2]) == 0)
+
#define MAXSZ_IP4_ADDRESS_ INET_ADDRSTRLEN - 1
#define MAXSZ_IP6_ADDRESS_ INET6_ADDRSTRLEN - 1
-#define MAXSZ_IP_ADDRESS_ MAXSZ_IP6_ADDRESS_
-#define MAXSZ_IP4_ADDRESS MAXSZ_IP4_ADDRESS_ + 1
-#define MAXSZ_IP6_ADDRESS MAXSZ_IP6_ADDRESS_ + 1
-#define MAXSZ_IP_ADDRESS MAXSZ_IP_ADDRESS_ + 1
+#define MAXSZ_IP_ADDRESS_ MAXSZ_IP6_ADDRESS_
+#define MAXSZ_IP4_ADDRESS MAXSZ_IP4_ADDRESS_ + 1
+#define MAXSZ_IP6_ADDRESS MAXSZ_IP6_ADDRESS_ + 1
+#define MAXSZ_IP_ADDRESS MAXSZ_IP_ADDRESS_ + 1
-typedef struct {
+typedef struct
+{
int family;
ip_address_t address;
u8 len;
} ip_prefix_t;
-#define MAXSZ_PREFIX_ MAXSZ_IP_ADDRESS_ + 1 + 3
-#define MAXSZ_PREFIX MAXSZ_PREFIX_ + 1
+#define MAXSZ_IP_PREFIX_ MAXSZ_IP_ADDRESS_ + 1 + 3
+#define MAXSZ_IP_PREFIX MAXSZ_IP_PREFIX_ + 1
extern const ip_address_t IPV4_LOOPBACK;
extern const ip_address_t IPV6_LOOPBACK;
extern const ip_address_t IPV4_ANY;
extern const ip_address_t IPV6_ANY;
+
+extern const ip4_address_t IP4_ADDRESS_EMPTY;
+extern const ip6_address_t IP6_ADDRESS_EMPTY;
extern const ip_address_t IP_ADDRESS_EMPTY;
#define IP_ANY(family) (family == AF_INET) ? IPV4_ANY : IPV6_ANY
-
-#define MAX_PORT 1 << (8 * sizeof(u16))
-#define IS_VALID_PORT(x) ((x > 0) && ((int)x < MAX_PORT))
+#define MAX_PORT 1 << (8 * sizeof (u16))
+#define IS_VALID_PORT(x) ((x > 0) && ((int) x < MAX_PORT))
#define MAXSZ_PORT_ 5
-#define MAXSZ_PORT MAXSZ_PORT_ + 1
+#define MAXSZ_PORT MAXSZ_PORT_ + 1
#define IS_VALID_FAMILY(x) ((x == AF_INET) || (x == AF_INET6))
/* IP address */
-int ip_address_get_family (const char * ip_address);
+int ip_address_get_family (const char *ip_address);
int ip_address_len (int family);
-const u8 * ip_address_get_buffer(const ip_address_t * ip_address, int family);
-int ip_address_ntop (const ip_address_t * ip_address, char *dst,
- const size_t len, int family);
-int ip_address_pton (const char *ip_address_str, ip_address_t * ip_address);
-int ip_address_snprintf(char * s, size_t size, const ip_address_t * ip_address,
- int family);
-int ip_address_to_sockaddr(const ip_address_t * ip_address, struct sockaddr *sa,
- int family);
-int ip_address_cmp(const ip_address_t * ip1, const ip_address_t * ip2, int family);
-int ip_address_empty(const ip_address_t * ip);
+const u8 *ip_address_get_buffer (const ip_address_t *ip_address, int family);
+int ip_address_ntop (const ip_address_t *ip_address, char *dst,
+ const size_t len, int family);
+int ip_address_pton (const char *ip_address_str, ip_address_t *ip_address);
+int ip_address_snprintf (char *s, size_t size, const ip_address_t *ip_address,
+ int family);
+int ip_address_to_sockaddr (const ip_address_t *ip_address,
+ struct sockaddr *sa, int family);
+int ip_address_cmp (const ip_address_t *ip1, const ip_address_t *ip2,
+ int family);
+int ip_address_empty (const ip_address_t *ip);
/* Prefix */
-int ip_prefix_pton (const char *ip_address_str, ip_prefix_t * ip_prefix);
-int ip_prefix_ntop_short (const ip_prefix_t * ip_prefix, char *dst, size_t size);
-int ip_prefix_ntop (const ip_prefix_t * ip_prefix, char *dst, size_t size);
-int ip_prefix_len (const ip_prefix_t * prefix);
-bool ip_prefix_empty (const ip_prefix_t * prefix);
-int ip_prefix_to_sockaddr(const ip_prefix_t * prefix, struct sockaddr *sa);
-int ip_prefix_cmp(const ip_prefix_t * prefix1, const ip_prefix_t * prefix2);
+int ip_prefix_pton (const char *ip_address_str, ip_prefix_t *ip_prefix);
+int ip_prefix_ntop_short (const ip_prefix_t *ip_prefix, char *dst,
+ size_t size);
+int ip_prefix_ntop (const ip_prefix_t *ip_prefix, char *dst, size_t size);
+int ip_prefix_snprintf (char *s, size_t size, const ip_prefix_t *prefix);
+int ip_prefix_len (const ip_prefix_t *prefix);
+bool ip_prefix_empty (const ip_prefix_t *prefix);
+int ip_prefix_to_sockaddr (const ip_prefix_t *prefix, struct sockaddr *sa);
+int ip_prefix_cmp (const ip_prefix_t *prefix1, const ip_prefix_t *prefix2);
/* URL */
#define MAXSZ_PROTO_ 8 /* inetX:// */
-#define MAXSZ_PROTO MAXSZ_PROTO_ + NULLTERM
+#define MAXSZ_PROTO MAXSZ_PROTO_ + NULLTERM
#define MAXSZ_URL4_ MAXSZ_PROTO_ + MAXSZ_IP4_ADDRESS_ + MAXSZ_PORT_
#define MAXSZ_URL6_ MAXSZ_PROTO_ + MAXSZ_IP6_ADDRESS_ + MAXSZ_PORT_
-#define MAXSZ_URL_ MAXSZ_URL6_
-#define MAXSZ_URL4 MAXSZ_URL4_ + NULLTERM
-#define MAXSZ_URL6 MAXSZ_URL6_ + NULLTERM
-#define MAXSZ_URL MAXSZ_URL_ + NULLTERM
+#define MAXSZ_URL_ MAXSZ_URL6_
+#define MAXSZ_URL4 MAXSZ_URL4_ + NULLTERM
+#define MAXSZ_URL6 MAXSZ_URL6_ + NULLTERM
+#define MAXSZ_URL MAXSZ_URL_ + NULLTERM
-int url_snprintf(char * s, size_t size, int family,
- const ip_address_t * ip_address, u16 port);
+int url_snprintf (char *s, size_t size, int family,
+ const ip_address_t *ip_address, u16 port);
#endif /* UTIL_IP_ADDRESS_H */
diff --git a/lib/includes/hicn/util/log.h b/lib/includes/hicn/util/log.h
index 6763d464f..6b35d1fef 100644
--- a/lib/includes/hicn/util/log.h
+++ b/lib/includes/hicn/util/log.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -17,8 +17,8 @@
#define UTIL_LOG_H
#include <stdarg.h> // va_*
-#include <stdio.h> // FILE
-#include <time.h> // time, localtime
+#include <stdio.h> // FILE
+#include <time.h> // time, localtime
#define LOG_FATAL 0
#define LOG_ERROR 1
@@ -27,43 +27,59 @@
#define LOG_DEBUG 4
#define LOG_TRACE 5
-typedef struct {
+typedef struct
+{
int log_level;
int debug;
- FILE * log_file;
+ FILE *log_file;
} log_conf_t;
-#define DEFAULT_LOG_CONF { \
- .log_level = LOG_INFO, \
- .debug = 0, \
- .log_file = NULL, \
-};
+#define DEFAULT_LOG_CONF \
+ { \
+ .log_level = LOG_INFO, \
+ .debug = 0, \
+ .log_file = NULL, \
+ };
extern log_conf_t log_conf;
-#define WITH_DEBUG(BLOCK) \
- if (log_conf.log_level >= LOG_DEBUG) \
- BLOCK
+#define WITH_ERROR(BLOCK) \
+ if (log_conf.log_level >= LOG_ERROR) \
+ BLOCK
+#define WITH_WARN(BLOCK) \
+ if (log_conf.log_level >= LOG_WARN) \
+ BLOCK
+#define WITH_INFO(BLOCK) \
+ if (log_conf.log_level >= LOG_INFO) \
+ BLOCK
+#define WITH_DEBUG(BLOCK) \
+ if (log_conf.log_level >= LOG_DEBUG) \
+ BLOCK
+#define WITH_TRACE(BLOCK) \
+ if (log_conf.log_level >= LOG_TRACE) \
+ BLOCK
-#define FATAL(fmt, ...) (_log(LOG_FATAL, fmt, ##__VA_ARGS__ ))
+#define FATAL(fmt, ...) (_log (LOG_FATAL, fmt, ##__VA_ARGS__))
#ifdef ERROR
#undef ERROR
#endif
-#define ERROR(fmt, ...) (_log(LOG_ERROR, fmt, ##__VA_ARGS__ ))
-#define WARN(fmt, ...) (_log(LOG_WARN, fmt, ##__VA_ARGS__ ))
-#define INFO(fmt, ...) (_log(LOG_INFO, fmt, ##__VA_ARGS__ ))
-#define DEBUG(fmt, ...) (_log(LOG_DEBUG, fmt, ##__VA_ARGS__ ))
-#define TRACE(fmt, ...) (_log(LOG_TRACE, fmt, ##__VA_ARGS__ ))
+#define ERROR(fmt, ...) (_log (LOG_ERROR, fmt, ##__VA_ARGS__))
+#define WARN(fmt, ...) (_log (LOG_WARN, fmt, ##__VA_ARGS__))
+#define INFO(fmt, ...) (_log (LOG_INFO, fmt, ##__VA_ARGS__))
+#define DEBUG(fmt, ...) (_log (LOG_DEBUG, fmt, ##__VA_ARGS__))
+#define TRACE(fmt, ...) (_log (LOG_TRACE, fmt, ##__VA_ARGS__))
-void _log_va(int level, const char *fmt, va_list ap);
+void _log_va (int level, const char *fmt, va_list ap);
-void _log(int level, const char *fmt, ...);
+void _log (int level, const char *fmt, ...);
-void fatal(char *fmt, ...);
+void fatal (char *fmt, ...);
+
+int loglevel_from_str (const char *loglevel);
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
-void print_trace(void);
+void print_trace (void);
#endif
#endif // UTIL_LOG_H
diff --git a/lib/includes/hicn/util/map.h b/lib/includes/hicn/util/map.h
index 01195865e..6e23f222f 100644
--- a/lib/includes/hicn/util/map.h
+++ b/lib/includes/hicn/util/map.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -20,231 +20,227 @@
#include "set.h"
-#define ERR_MAP_EXISTS -2
+#define ERR_MAP_EXISTS -2
#define ERR_MAP_NOT_FOUND -3
-#define TYPEDEF_MAP_H(NAME, KEY_T, VAL_T) \
- \
-typedef struct { \
- KEY_T key; \
- VAL_T value; \
-} NAME ## _pair_t; \
- \
-NAME ## _pair_t * NAME ## _pair_create(KEY_T key, VAL_T value); \
- \
-void NAME ## _pair_free(NAME ## _pair_t * pair); \
- \
-int NAME ## _pair_cmp(const NAME ## _pair_t * p1, const NAME ## _pair_t * p2); \
- \
-TYPEDEF_SET_H(NAME ## _pair_set, NAME ## _pair_t *) \
- \
-typedef struct NAME ## _s { \
- NAME ## _pair_set_t pair_set; \
-} NAME ## _t; \
- \
-int NAME ## _initialize(NAME ## _t * map); \
- \
-int NAME ## _finalize(NAME ## _t * map); \
- \
-NAME ## _t * NAME ## _create(); \
- \
-void NAME ## _free(NAME ## _t * map); \
- \
-int NAME ## _add(NAME ## _t * map, KEY_T key, VAL_T value); \
- \
-int NAME ## _remove(NAME ## _t * map, KEY_T key, VAL_T * value); \
- \
-int NAME ## _get(NAME ## _t * map, KEY_T key, VAL_T * value); \
- \
-void NAME ## _dump(NAME ## _t * map);
+#define TYPEDEF_MAP_H(NAME, KEY_T, VAL_T) \
+ \
+ typedef struct \
+ { \
+ KEY_T key; \
+ VAL_T value; \
+ } NAME##_pair_t; \
+ \
+ NAME##_pair_t *NAME##_pair_create (KEY_T key, VAL_T value); \
+ \
+ void NAME##_pair_free (NAME##_pair_t *pair); \
+ \
+ int NAME##_pair_cmp (const NAME##_pair_t *p1, const NAME##_pair_t *p2); \
+ \
+ TYPEDEF_SET_H (NAME##_pair_set, NAME##_pair_t *) \
+ \
+ typedef struct NAME##_s \
+ { \
+ NAME##_pair_set_t pair_set; \
+ } NAME##_t; \
+ \
+ int NAME##_initialize (NAME##_t *map); \
+ \
+ int NAME##_finalize (NAME##_t *map); \
+ \
+ NAME##_t *NAME##_create (); \
+ \
+ void NAME##_free (NAME##_t *map); \
+ \
+ int NAME##_add (NAME##_t *map, KEY_T key, VAL_T value); \
+ \
+ int NAME##_remove (NAME##_t *map, KEY_T key, VAL_T *value); \
+ \
+ int NAME##_get (NAME##_t *map, KEY_T key, VAL_T *value); \
+ \
+ void NAME##_dump (NAME##_t *map); \
+ \
+ int NAME##_get_key_array (NAME##_t *map, KEY_T **array); \
+ \
+ int NAME##_get_value_array (NAME##_t *map, VAL_T **array);
-
-
-
-#define TYPEDEF_MAP(NAME, KEY_T, VAL_T, CMP, KEY_SNPRINTF, VALUE_SNPRINTF) \
- \
-NAME ## _pair_t * NAME ## _pair_create(KEY_T key, VAL_T value) \
-{ \
- /* Create pair */ \
- NAME ## _pair_t * pair = malloc(sizeof(NAME ## _pair_t)); \
- if (!pair) \
- return NULL; \
- \
- pair->key = key; \
- pair->value = value; \
- \
- return pair; \
-} \
- \
-void NAME ## _pair_free(NAME ## _pair_t * pair) \
-{ \
- free(pair); \
-} \
- \
-int \
-NAME ## _pair_cmp(const NAME ## _pair_t * p1, const NAME ## _pair_t * p2) \
-{ \
- return (CMP(p1->key, p2->key)); \
-} \
- \
-int \
-NAME ## _pair_snprintf(char * buf, size_t size, const NAME ## _pair_t * pair) { \
- int rc; \
- rc = KEY_SNPRINTF(buf, BUFSIZE/2, (KEY_T)pair->key); \
- if (rc < 0) \
- return rc; \
- rc = VALUE_SNPRINTF(buf+rc, BUFSIZE/2, (VAL_T)pair->value); \
- return (int)rc; \
-} \
- \
-TYPEDEF_SET(NAME ## _pair_set, NAME ## _pair_t *, NAME ## _pair_cmp, NAME ## _pair_snprintf); \
- \
-int \
-NAME ## _initialize(NAME ## _t * map) \
-{ \
- return NAME ## _pair_set_initialize(&map->pair_set); \
-} \
- \
-int \
-NAME ## _finalize(NAME ## _t * map) \
-{ \
- NAME ## _pair_t ** array; \
- int n = NAME ## _pair_set_get_array(&map->pair_set, &array); \
- if (n < 0) \
- return -1; \
- for (unsigned i = 0; i < n; i++) { \
- NAME ## _pair_t * pair = array[i]; \
- NAME ## _pair_set_remove(&map->pair_set, pair, NULL); \
- NAME ## _pair_free(pair); \
- } \
- free(array); \
- return NAME ## _pair_set_finalize(&map->pair_set); \
-} \
- \
-NAME ## _t * \
-NAME ## _create() \
-{ \
- NAME ## _t * map = malloc(sizeof(NAME ## _t)); \
- if (!map) \
- goto ERR_MALLOC; \
- \
- if (NAME ## _initialize(map) < 0) \
- goto ERR_INITIALIZE; \
- \
- return map; \
- \
-ERR_INITIALIZE: \
- free(map); \
-ERR_MALLOC: \
- return NULL; \
-} \
- \
-void \
-NAME ## _free(NAME ## _t * map) \
-{ \
- NAME ## _finalize(map); \
- free(map); \
-} \
- \
-int \
-NAME ## _add(NAME ## _t * map, KEY_T key, VAL_T value) \
-{ \
- int rc; \
- NAME ## _pair_t * found = NULL; \
- \
- NAME ## _pair_t * pair = NAME ## _pair_create(key, value); \
- if (!pair) \
- return -1; \
- \
- rc = NAME ## _pair_set_get(&map->pair_set, pair, &found); \
- if (rc < 0) \
- return -1; \
- if (found) { \
- NAME ## _pair_free(pair); \
- return ERR_MAP_EXISTS; \
- } \
- \
- rc = NAME ## _pair_set_add(&map->pair_set, pair); \
- if (rc < 0) { \
- NAME ## _pair_free(pair); \
- return -1; \
- } \
- return 0; \
-} \
- \
-int \
-NAME ## _remove(NAME ## _t * map, KEY_T key, VAL_T * value) \
-{ \
- NAME ## _pair_t * found = NULL; \
- NAME ## _pair_t search = { .key = key }; \
- int rc = NAME ## _pair_set_remove(&map->pair_set, &search, &found); \
- if (rc < 0) \
- return ERR_MAP_NOT_FOUND; \
- if (value) \
- *value = found->value; \
- NAME ## _pair_free(found); \
- return 0; \
-} \
- \
-int \
-NAME ## _get(NAME ## _t * map, KEY_T key, VAL_T * value) \
-{ \
- NAME ## _pair_t * found = NULL, search = { .key = key }; \
- int rc = NAME ## _pair_set_get(&map->pair_set, &search, &found); \
- if (rc < 0) \
- return -1; \
- if (found) \
- *value = found->value; \
- return 0; \
-} \
- \
-void \
-NAME ## _dump(NAME ## _t * map) { \
- NAME ## _pair_set_dump(&map->pair_set); \
-} \
- \
-int \
-NAME ## _get_key_array(NAME ## _t * map, KEY_T **array) { \
- NAME ## _pair_t ** pair_array; \
- int n = NAME ## _pair_set_get_array(&map->pair_set, &pair_array); \
- if (n < 0) \
- return -1; \
- if (!array) \
- goto END; \
- /* Allocate result array */ \
- *array = malloc(n * sizeof(KEY_T)); \
- if (!array) { \
- free(pair_array); \
- return -1; \
- } \
- /* Copy keys */ \
- for (int i = 0; i < n; i++) \
- (*array)[i] = pair_array[i]->key; \
- free(pair_array); \
-END: \
- return n; \
-} \
- \
-int \
-NAME ## _get_value_array(NAME ## _t * map, VAL_T **array) { \
- NAME ## _pair_t ** pair_array; \
- int n = NAME ## _pair_set_get_array(&map->pair_set, &pair_array); \
- if (n < 0) \
- return -1; \
- if (!array) \
- goto END; \
- /* Allocate result array */ \
- *array = malloc(n * sizeof(VAL_T)); \
- if (!array) { \
- free(pair_array); \
- return -1; \
- } \
- /* Copy values */ \
- for (int i = 0; i < n; i++) \
- (*array)[i] = pair_array[i]->value; \
- free(pair_array); \
-END: \
- return n; \
-}
+#define TYPEDEF_MAP(NAME, KEY_T, VAL_T, CMP, KEY_SNPRINTF, VALUE_SNPRINTF) \
+ \
+ NAME##_pair_t *NAME##_pair_create (KEY_T key, VAL_T value) \
+ { \
+ /* Create pair */ \
+ NAME##_pair_t *pair = malloc (sizeof (NAME##_pair_t)); \
+ if (!pair) \
+ return NULL; \
+ \
+ pair->key = key; \
+ pair->value = value; \
+ \
+ return pair; \
+ } \
+ \
+ void NAME##_pair_free (NAME##_pair_t *pair) { free (pair); } \
+ \
+ int NAME##_pair_cmp (const NAME##_pair_t *p1, const NAME##_pair_t *p2) \
+ { \
+ return (CMP (p1->key, p2->key)); \
+ } \
+ \
+ int NAME##_pair_snprintf (char *buf, size_t size, \
+ const NAME##_pair_t *pair) \
+ { \
+ int rc; \
+ rc = KEY_SNPRINTF (buf, BUFSIZE / 2, (KEY_T) pair->key); \
+ if (rc < 0) \
+ return rc; \
+ rc = VALUE_SNPRINTF (buf + rc, BUFSIZE / 2, (VAL_T) pair->value); \
+ return (int) rc; \
+ } \
+ \
+ TYPEDEF_SET (NAME##_pair_set, NAME##_pair_t *, NAME##_pair_cmp, \
+ NAME##_pair_snprintf); \
+ \
+ int NAME##_initialize (NAME##_t *map) \
+ { \
+ return NAME##_pair_set_initialize (&map->pair_set); \
+ } \
+ \
+ int NAME##_finalize (NAME##_t *map) \
+ { \
+ NAME##_pair_t **array; \
+ int n = NAME##_pair_set_get_array (&map->pair_set, &array); \
+ if (n < 0) \
+ return -1; \
+ for (unsigned i = 0; i < n; i++) \
+ { \
+ NAME##_pair_t *pair = array[i]; \
+ NAME##_pair_set_remove (&map->pair_set, pair, NULL); \
+ NAME##_pair_free (pair); \
+ } \
+ free (array); \
+ return NAME##_pair_set_finalize (&map->pair_set); \
+ } \
+ \
+ NAME##_t *NAME##_create () \
+ { \
+ NAME##_t *map = malloc (sizeof (NAME##_t)); \
+ if (!map) \
+ goto ERR_MALLOC; \
+ \
+ if (NAME##_initialize (map) < 0) \
+ goto ERR_INITIALIZE; \
+ \
+ return map; \
+ \
+ ERR_INITIALIZE: \
+ free (map); \
+ ERR_MALLOC: \
+ return NULL; \
+ } \
+ \
+ void NAME##_free (NAME##_t *map) \
+ { \
+ NAME##_finalize (map); \
+ free (map); \
+ } \
+ \
+ int NAME##_add (NAME##_t *map, KEY_T key, VAL_T value) \
+ { \
+ int rc; \
+ NAME##_pair_t *found = NULL; \
+ \
+ NAME##_pair_t *pair = NAME##_pair_create (key, value); \
+ if (!pair) \
+ return -1; \
+ \
+ rc = NAME##_pair_set_get (&map->pair_set, pair, &found); \
+ if (rc < 0) \
+ return -1; \
+ if (found) \
+ { \
+ NAME##_pair_free (pair); \
+ return ERR_MAP_EXISTS; \
+ } \
+ \
+ rc = NAME##_pair_set_add (&map->pair_set, pair); \
+ if (rc < 0) \
+ { \
+ NAME##_pair_free (pair); \
+ return -1; \
+ } \
+ return 0; \
+ } \
+ \
+ int NAME##_remove (NAME##_t *map, KEY_T key, VAL_T *value) \
+ { \
+ NAME##_pair_t *found = NULL; \
+ NAME##_pair_t search = { .key = key }; \
+ int rc = NAME##_pair_set_remove (&map->pair_set, &search, &found); \
+ if (rc < 0) \
+ return ERR_MAP_NOT_FOUND; \
+ if (value) \
+ *value = found->value; \
+ NAME##_pair_free (found); \
+ return 0; \
+ } \
+ \
+ int NAME##_get (NAME##_t *map, KEY_T key, VAL_T *value) \
+ { \
+ NAME##_pair_t *found = NULL, search = { .key = key }; \
+ int rc = NAME##_pair_set_get (&map->pair_set, &search, &found); \
+ if (rc < 0) \
+ return -1; \
+ if (found) \
+ *value = found->value; \
+ return 0; \
+ } \
+ \
+ void NAME##_dump (NAME##_t *map) { NAME##_pair_set_dump (&map->pair_set); } \
+ \
+ int NAME##_get_key_array (NAME##_t *map, KEY_T **array) \
+ { \
+ NAME##_pair_t **pair_array; \
+ int n = NAME##_pair_set_get_array (&map->pair_set, &pair_array); \
+ if (n < 0) \
+ return -1; \
+ if (!array) \
+ goto END; \
+ /* Allocate result array */ \
+ *array = malloc (n * sizeof (KEY_T)); \
+ if (!array) \
+ { \
+ free (pair_array); \
+ return -1; \
+ } \
+ /* Copy keys */ \
+ for (int i = 0; i < n; i++) \
+ (*array)[i] = pair_array[i]->key; \
+ free (pair_array); \
+ END: \
+ return n; \
+ } \
+ \
+ int NAME##_get_value_array (NAME##_t *map, VAL_T **array) \
+ { \
+ NAME##_pair_t **pair_array; \
+ int n = NAME##_pair_set_get_array (&map->pair_set, &pair_array); \
+ if (n < 0) \
+ return -1; \
+ if (!array) \
+ goto END; \
+ /* Allocate result array */ \
+ *array = malloc (n * sizeof (VAL_T)); \
+ if (!array) \
+ { \
+ free (pair_array); \
+ return -1; \
+ } \
+ /* Copy values */ \
+ for (int i = 0; i < n; i++) \
+ (*array)[i] = pair_array[i]->value; \
+ free (pair_array); \
+ END: \
+ return n; \
+ }
#endif /* UTIL_MAP_H */
diff --git a/lib/includes/hicn/util/set.h b/lib/includes/hicn/util/set.h
index bc2e3caac..0a5ff6777 100644
--- a/lib/includes/hicn/util/set.h
+++ b/lib/includes/hicn/util/set.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -25,214 +25,196 @@
#define thread_local _Thread_local
//#endif /* ! __ANDROID__ */
-#define ERR_SET_EXISTS -2
+#define ERR_SET_EXISTS -2
#define ERR_SET_NOT_FOUND -3
/* FIXME: buffer overflow when this is too small... investigate */
#define BUFSIZE 1024
-static inline
-int
-int_cmp(const int x, const int y)
+static inline int
+int_cmp (const int x, const int y)
{
- return x - y;
+ return x - y;
}
-static inline
-int
-int_snprintf(char * buf, size_t size, int value) {
- return snprintf(buf, size, "%d", value);
+static inline int
+int_snprintf (char *buf, size_t size, int value)
+{
+ return snprintf (buf, size, "%d", value);
}
-static inline
-int
-string_snprintf(char * buf, size_t size, const char * s) {
- return snprintf(buf, size, "%s", s);
+static inline int
+string_snprintf (char *buf, size_t size, const char *s)
+{
+ return snprintf (buf, size, "%s", s);
}
-static inline
-int
-generic_snprintf(char * buf, size_t size, const void * value) {
- return snprintf(buf, BUFSIZE, "%p", value);
+static inline int
+generic_snprintf (char *buf, size_t size, const void *value)
+{
+ return snprintf (buf, BUFSIZE, "%p", value);
}
-typedef int(*cmp_t)(const void * x, const void * y);
-
-#define TYPEDEF_SET_H(NAME, T) \
- \
-typedef struct { \
- size_t size; \
- void * root; \
-} NAME ## _t; \
- \
-int NAME ## _initialize(NAME ## _t * set); \
- \
-int NAME ## _finalize(NAME ## _t * set); \
- \
-NAME ## _t * NAME ## _create(); \
- \
-void NAME ## _free(NAME ## _t * set); \
- \
-int NAME ## _add(NAME ## _t * set, const T element); \
- \
-int NAME ## _remove(NAME ## _t * set, const T search, T * element); \
- \
-int NAME ## _clear(NAME ## _t * set); \
- \
-int NAME ## _get(const NAME ## _t * set, const T search, T * element); \
- \
-int NAME ## _get_array(const NAME ## _t * set, T ** element); \
- \
-void NAME ## _dump(NAME ## _t * set);
+typedef int (*cmp_t) (const void *x, const void *y);
+#define TYPEDEF_SET_H(NAME, T) \
+ \
+ typedef struct \
+ { \
+ size_t size; \
+ void *root; \
+ } NAME##_t; \
+ \
+ int NAME##_initialize (NAME##_t *set); \
+ \
+ int NAME##_finalize (NAME##_t *set); \
+ \
+ NAME##_t *NAME##_create (); \
+ \
+ void NAME##_free (NAME##_t *set); \
+ \
+ int NAME##_add (NAME##_t *set, const T element); \
+ \
+ int NAME##_remove (NAME##_t *set, const T search, T *element); \
+ \
+ int NAME##_clear (NAME##_t *set); \
+ \
+ int NAME##_get (const NAME##_t *set, const T search, T *element); \
+ \
+ int NAME##_get_array (const NAME##_t *set, T **element); \
+ \
+ void NAME##_dump (NAME##_t *set);
-
-
-#define TYPEDEF_SET(NAME, T, CMP, SNPRINTF) \
-int \
-NAME ## _initialize(NAME ## _t * set) \
-{ \
- set->root = NULL; \
- set->size = 0; \
- return 0; \
-} \
- \
-int \
-NAME ## _finalize(NAME ## _t * set) \
-{ \
- return NAME ## _clear(set); \
-} \
- \
-NAME ## _t * \
-NAME ## _create() \
-{ \
- NAME ## _t * set = malloc(sizeof(NAME ## _t)); \
- if (!set) \
- goto ERR_MALLOC; \
- \
- if (NAME ## _initialize(set) < 0) \
- goto ERR_INITIALIZE; \
- \
- return set; \
- \
-ERR_INITIALIZE: \
- free(set); \
-ERR_MALLOC: \
- return NULL; \
-} \
- \
-void \
-NAME ## _free(NAME ## _t * set) \
-{ \
- NAME ## _finalize(set); \
- free(set); \
-} \
- \
-int \
-NAME ## _add(NAME ## _t * set, const T element) \
-{ \
- T * found = tfind(element, &set->root, (cmp_t)CMP); \
- void * ptr = tsearch(element, &set->root, (cmp_t)CMP); \
- if (!ptr) \
- return -1; \
- if (!found) \
- set->size++; \
- return 0; \
-} \
- \
-int \
-NAME ## _remove(NAME ## _t * set, const T search, T * element) \
-{ \
- T * found = tfind(search, &set->root, (cmp_t)CMP); \
- if (!found) \
- return ERR_SET_NOT_FOUND; \
- if (element) \
- *element = *found; \
- tdelete(search, &set->root, (cmp_t)CMP); \
- set->size--; \
- return 0; \
-} \
- \
-int \
-NAME ## _clear(NAME ## _t * set) \
-{ \
- T * array; \
- int n = NAME ## _get_array(set, &array); \
- if (n < 0) \
- return -1; \
- for (unsigned i = 0; i < n; i++) { \
- T element = array[i]; \
- NAME ## _remove(set, element, NULL); \
- } \
- free(array); \
- return 0; \
-} \
- \
-int \
-NAME ## _get(const NAME ## _t * set, const T search, T * element) \
-{ \
- T * found = tfind(search, &set->root, (cmp_t)CMP); \
- if (element) \
- *element = found ? *found : NULL; \
- return 0; \
-} \
- \
-static void \
-NAME ## _dump_node(const void *nodep, const VISIT which, \
- const int depth) \
-{ \
- char buf[BUFSIZE]; \
- switch (which) { \
- case preorder: \
- case endorder: \
- break; \
- case postorder: \
- case leaf: \
- SNPRINTF(buf, BUFSIZE, *(T*)nodep); \
- INFO("%s", buf); \
- break; \
- } \
-} \
- \
-void \
-NAME ## _dump(NAME ## _t * set) { \
- twalk(set->root, NAME ## _dump_node); \
-} \
- \
-thread_local \
-T * NAME ## _array_pos = NULL; \
- \
-static void \
-NAME ## _add_node_to_array(const void *nodep, const VISIT which, \
- const int depth) \
-{ \
- if (!NAME ## _array_pos) \
- return; \
- switch (which) { \
- case preorder: \
- case endorder: \
- break; \
- case postorder: \
- case leaf: \
- *NAME ## _array_pos = *(T*)nodep; \
- NAME ## _array_pos++; \
- break; \
- } \
-} \
- \
-int \
-NAME ## _get_array(const NAME ## _t * set, T ** element) \
-{ \
- if (!element) \
- goto END; \
- *element = malloc(set->size * sizeof(T)); \
- if (!*element) \
- return -1; \
- NAME ## _array_pos = *element; \
- twalk(set->root, NAME ## _add_node_to_array); \
- NAME ## _array_pos = NULL; \
-END: \
- return (int)(set->size); \
-}
+#define TYPEDEF_SET(NAME, T, CMP, SNPRINTF) \
+ int NAME##_initialize (NAME##_t *set) \
+ { \
+ set->root = NULL; \
+ set->size = 0; \
+ return 0; \
+ } \
+ \
+ int NAME##_finalize (NAME##_t *set) { return NAME##_clear (set); } \
+ \
+ NAME##_t *NAME##_create () \
+ { \
+ NAME##_t *set = malloc (sizeof (NAME##_t)); \
+ if (!set) \
+ goto ERR_MALLOC; \
+ \
+ if (NAME##_initialize (set) < 0) \
+ goto ERR_INITIALIZE; \
+ \
+ return set; \
+ \
+ ERR_INITIALIZE: \
+ free (set); \
+ ERR_MALLOC: \
+ return NULL; \
+ } \
+ \
+ void NAME##_free (NAME##_t *set) \
+ { \
+ NAME##_finalize (set); \
+ free (set); \
+ } \
+ \
+ int NAME##_add (NAME##_t *set, const T element) \
+ { \
+ T *found = tfind (element, &set->root, (cmp_t) CMP); \
+ void *ptr = tsearch (element, &set->root, (cmp_t) CMP); \
+ if (!ptr) \
+ return -1; \
+ if (!found) \
+ set->size++; \
+ return 0; \
+ } \
+ \
+ int NAME##_remove (NAME##_t *set, const T search, T *element) \
+ { \
+ T *found = tfind (search, &set->root, (cmp_t) CMP); \
+ if (!found) \
+ return ERR_SET_NOT_FOUND; \
+ if (element) \
+ *element = *found; \
+ tdelete (search, &set->root, (cmp_t) CMP); \
+ set->size--; \
+ return 0; \
+ } \
+ \
+ int NAME##_clear (NAME##_t *set) \
+ { \
+ T *array; \
+ int n = NAME##_get_array (set, &array); \
+ if (n < 0) \
+ return -1; \
+ for (unsigned i = 0; i < n; i++) \
+ { \
+ T element = array[i]; \
+ NAME##_remove (set, element, NULL); \
+ } \
+ free (array); \
+ return 0; \
+ } \
+ \
+ int NAME##_get (const NAME##_t *set, const T search, T *element) \
+ { \
+ T *found = tfind (search, &set->root, (cmp_t) CMP); \
+ if (element) \
+ *element = found ? *found : NULL; \
+ return 0; \
+ } \
+ \
+ static void NAME##_dump_node (const void *nodep, const VISIT which, \
+ const int depth) \
+ { \
+ char buf[BUFSIZE]; \
+ switch (which) \
+ { \
+ case preorder: \
+ case endorder: \
+ break; \
+ case postorder: \
+ case leaf: \
+ SNPRINTF (buf, BUFSIZE, *(T *) nodep); \
+ INFO ("%s", buf); \
+ break; \
+ } \
+ } \
+ \
+ void NAME##_dump (NAME##_t *set) { twalk (set->root, NAME##_dump_node); } \
+ \
+ thread_local T *NAME##_array_pos = NULL; \
+ \
+ static void NAME##_add_node_to_array (const void *nodep, const VISIT which, \
+ const int depth) \
+ { \
+ if (!NAME##_array_pos) \
+ return; \
+ switch (which) \
+ { \
+ case preorder: \
+ case endorder: \
+ break; \
+ case postorder: \
+ case leaf: \
+ *NAME##_array_pos = *(T *) nodep; \
+ NAME##_array_pos++; \
+ break; \
+ } \
+ } \
+ \
+ int NAME##_get_array (const NAME##_t *set, T **element) \
+ { \
+ if (!element) \
+ goto END; \
+ *element = calloc (set->size, sizeof (T)); \
+ if (!*element) \
+ return -1; \
+ NAME##_array_pos = *element; \
+ twalk (set->root, NAME##_add_node_to_array); \
+ NAME##_array_pos = NULL; \
+ END: \
+ return (int) (set->size); \
+ }
#endif /* UTIL_SET_H */
diff --git a/lib/includes/hicn/util/sstrncpy.h b/lib/includes/hicn/util/sstrncpy.h
new file mode 100644
index 000000000..b316201be
--- /dev/null
+++ b/lib/includes/hicn/util/sstrncpy.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef UTIL_SSTRNCPY_H
+#define UTIL_SSTRNCPY_H
+
+#define __STDC_WANT_LIB_EXT1__ 1
+#include <string.h>
+
+#ifdef __STDC_LIB_EXT1__
+// If safe string functions already available in the system, use them
+#elif ENABLE_SAFEC
+// If safe string functions not available and SafeC is enabled,
+// use SafeC
+#include <safe_string.h>
+#else
+// Use custom safe string functions
+typedef int errno_t;
+#define EOK 0
+
+/**
+ * @brief This function assures a null byte at the end of the buffer.
+ */
+static inline errno_t
+strcpy_s (char *dst, size_t n, const char *src)
+{
+ if (!dst || !src || !n)
+ {
+ fprintf (stderr, "[strncpy] invalid input received");
+ return EINVAL;
+ }
+
+ dst[n - 1] = 0;
+ strncpy (dst, src, n);
+
+ if (dst[n - 1] != 0)
+ {
+ fprintf (stderr, "[strncpy] '%s' has been trucated\n", src);
+ dst[n - 1] = 0;
+ return EINVAL;
+ }
+
+ return EOK;
+}
+
+static inline size_t
+strnlen_s (const char *s, size_t maxlen)
+{
+ if (s == NULL)
+ return 0;
+
+ return strnlen (s, maxlen);
+}
+
+#endif /* __STDC_LIB_EXT1__ */
+#endif /* UTIL_SSTRNCPY_H */
diff --git a/lib/includes/hicn/util/token.h b/lib/includes/hicn/util/token.h
index 43e0a77b2..c62c294bc 100644
--- a/lib/includes/hicn/util/token.h
+++ b/lib/includes/hicn/util/token.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -19,12 +19,12 @@
* Concatenate preprocessor tokens A and B without expanding macro definitions
* (however, if invoked from a macro, macro arguments are expanded).
*/
-#define PPCAT_NX(A, B) A ## B
+#define PPCAT_NX(A, B) A##B
/*
* Concatenate preprocessor tokens A and B after macro-expanding them.
*/
-#define PPCAT(A, B) PPCAT_NX(A, B)
+#define PPCAT(A, B) PPCAT_NX (A, B)
/* Token stringification */
@@ -37,4 +37,4 @@
/*
* Turn A into a string literal after macro-expanding it.
*/
-#define STRINGIZE(A) STRINGIZE_NX(A)
+#define STRINGIZE(A) STRINGIZE_NX (A)
diff --git a/lib/includes/hicn/util/types.h b/lib/includes/hicn/util/types.h
index 017e85b72..50c5362d3 100644
--- a/lib/includes/hicn/util/types.h
+++ b/lib/includes/hicn/util/types.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -25,15 +25,19 @@ typedef uint32_t u32;
typedef uint64_t u64;
/* Helper for avoiding warnings about type-punning */
-#define UNION_CAST(x, destType) \
- (((union {__typeof__(x) a; destType b;})x).b)
+#define UNION_CAST(x, destType) \
+ (((union { \
+ __typeof__ (x) a; \
+ destType b; \
+ }) x) \
+ .b)
-//typedef unsigned int hash_t;
+// typedef unsigned int hash_t;
-typedef int (*cmp_t)(const void *, const void *);
+typedef int (*cmp_t) (const void *, const void *);
/* Enums */
-#define IS_VALID_ENUM_TYPE(NAME, x) ((x > NAME ## _UNDEFINED) && (x < NAME ## _N))
+#define IS_VALID_ENUM_TYPE(NAME, x) ((x > NAME##_UNDEFINED) && (x < NAME##_N))
#endif /* UTIL_TYPES */
diff --git a/lib/includes/hicn/util/win_portability.h b/lib/includes/hicn/util/win_portability.h
index 5f30cfbb2..609203afc 100644
--- a/lib/includes/hicn/util/win_portability.h
+++ b/lib/includes/hicn/util/win_portability.h
@@ -1,45 +1,45 @@
-/*
- * Copyright (c) 2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-#include <hicn/util/windows/windows_Utils.h>
-#include <afunix.h>
-#include <io.h>
-#include <iphlpapi.h>
-#include <process.h>
-#include <stdio.h>
-#pragma comment(lib, "IPHLPAPI.lib")
-
-#ifndef in_port_t
-#define in_port_t uint16_t
-#endif
-
-#ifndef in_addr_t
-#define in_addr_t uint32_t
-#endif
-
-#ifndef strncasecmp
-#define strncasecmp _strnicmp
-#endif
-
-#ifndef strcasecmp
-#define strcasecmp _stricmp
-#endif
-
-#define HAVE_STRUCT_TIMESPEC
-
-#ifndef getline
-int getline(char **lineptr, size_t *n, FILE *stream);
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#pragma once
+#include <hicn/util/windows/windows_Utils.h>
+#include <afunix.h>
+#include <io.h>
+#include <iphlpapi.h>
+#include <process.h>
+#include <stdio.h>
+#pragma comment(lib, "IPHLPAPI.lib")
+
+#ifndef in_port_t
+#define in_port_t uint16_t
+#endif
+
+#ifndef in_addr_t
+#define in_addr_t uint32_t
+#endif
+
+#ifndef strncasecmp
+#define strncasecmp _strnicmp
+#endif
+
+#ifndef strcasecmp
+#define strcasecmp _stricmp
+#endif
+
+#define HAVE_STRUCT_TIMESPEC
+
+#ifndef getline
+int getline (char **lineptr, size_t *n, FILE *stream);
#endif \ No newline at end of file
diff --git a/lib/includes/hicn/util/windows/dlfcn.h b/lib/includes/hicn/util/windows/dlfcn.h
index 7775226cd..f1457964e 100644
--- a/lib/includes/hicn/util/windows/dlfcn.h
+++ b/lib/includes/hicn/util/windows/dlfcn.h
@@ -5,8 +5,8 @@
#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 */
+#define RTLD_LAZY 0x000 /* accept unresolved externs */
+#define RTLD_NOW 0x001 /* abort if module has unresolved externs */
/*
How to call in Windows:
@@ -16,15 +16,16 @@
*/
#ifdef __cplusplus
-extern "C" {
+extern "C"
+{
#endif
- void *dlopen (const char *filename, int flag);
- int dlclose (void *handle);
+ void *dlopen (const char *filename, int flag);
+ int dlclose (void *handle);
- void *dlsym (void *handle, const char *name);
+ void *dlsym (void *handle, const char *name);
-const char *dlerror (void);
+ const char *dlerror (void);
#ifdef __cplusplus
}
diff --git a/lib/includes/hicn/util/windows/windows_utils.h b/lib/includes/hicn/util/windows/windows_utils.h
index d24aaadbf..e15c0d752 100755..100644
--- a/lib/includes/hicn/util/windows/windows_utils.h
+++ b/lib/includes/hicn/util/windows/windows_utils.h
@@ -1,162 +1,166 @@
-/*
- * Copyright (c) 2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef WINDOWS_UTILS_H
-#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
-struct iovec {
- void* iov_base;
- size_t iov_len;
-};
-#endif
-
-typedef uint16_t in_port_t;
-
-#ifndef SLEEP
-#define SLEEP
-#define sleep Sleep
-#endif
-
-#ifndef USLEEP
-#define USLEEP
-void usleep(__int64 usec);
-#endif
-
-#ifndef S_ISDIR
-#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
-#endif
-
-#define PARCLibrary_DISABLE_ATOMICS
-#include <BaseTsd.h>
-typedef SSIZE_T ssize_t;
-
-#ifndef __ATTRIBUTE__
-#define __ATTRIBUTE__
-#define __attribute__(A)
-#endif
-
-#ifndef RESTRICT
-#define RESTRICT
-#define restrict __restrict
-#endif
-
-#ifndef GETTIMEOFDAY
-#define GETTIMEOFDAY
-int gettimeofday(struct timeval * tp, struct timezone * tzp);
-#endif
-
-#ifndef timersub
-#define timersub(a, b, result) \
- do { \
- (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
- (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
- if ((result)->tv_usec < 0) { \
- --(result)->tv_sec; \
- (result)->tv_usec += 1000000; \
- } \
- } while (0)
-#endif // timersub
-
-#ifndef dup
-#define dup _dup
-#endif
-
-#ifndef access
-#define access _access
-#endif
-
-#ifndef __cplusplus
-
-#ifndef read
-#define read _read
-#endif
-
-#ifndef close
-#define close _close
-#endif
-
-#ifndef write
-#define write _write
-#endif
-
-#ifndef open
-#define open _open
-#endif
-
-#endif
-
-#ifndef unlink
-#define unlink _unlink
-#endif
-
-#ifndef strcasecmp
-#define strncasecmp _strnicmp
-#endif
-
-#ifndef strcasecmp
-
-#define strcasecmp _stricmp
-#endif
-
-#ifndef S_ISREG
-#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
-#endif
-#ifndef R_OK
-#define R_OK 4 /* Test for read permission. */
-#endif
-#ifndef W_OK
-#define W_OK 2 /* Test for write permission. */
-#endif
-#ifndef F_OK
-#define F_OK 0
-#endif
-
-#ifndef STDIN_FILENO
-#define STDIN_FILENO _fileno(stdin)
-#endif
-
-#ifndef STDOUT_FILENO
-#define STDOUT_FILENO _fileno(stdout)
-#endif
-
-#ifndef STDERR_FILENO
-#define STDERR_FILENO _fileno(stderr)
-#endif
-
-#endif
-
-#ifndef __bswap_constant_32
-#define __bswap_constant_32(x) \
- ((((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)
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef WINDOWS_UTILS_H
+#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
+struct iovec
+{
+ void *iov_base;
+ size_t iov_len;
+};
+#endif
+
+typedef uint16_t in_port_t;
+
+#ifndef SLEEP
+#define SLEEP
+#define sleep Sleep
+#endif
+
+#ifndef USLEEP
+#define USLEEP
+void usleep (__int64 usec);
+#endif
+
+#ifndef S_ISDIR
+#define S_ISDIR(mode) (((mode) &S_IFMT) == S_IFDIR)
+#endif
+
+#define PARCLibrary_DISABLE_ATOMICS
+#include <BaseTsd.h>
+typedef SSIZE_T ssize_t;
+
+#ifndef __ATTRIBUTE__
+#define __ATTRIBUTE__
+#define __attribute__(A)
+#endif
+
+#ifndef RESTRICT
+#define RESTRICT
+#define restrict __restrict
+#endif
+
+#ifndef GETTIMEOFDAY
+#define GETTIMEOFDAY
+int gettimeofday (struct timeval *tp, struct timezone *tzp);
+#endif
+
+#ifndef timersub
+#define timersub(a, b, result) \
+ do \
+ { \
+ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
+ (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
+ if ((result)->tv_usec < 0) \
+ { \
+ --(result)->tv_sec; \
+ (result)->tv_usec += 1000000; \
+ } \
+ } \
+ while (0)
+#endif // timersub
+
+#ifndef dup
+#define dup _dup
+#endif
+
+#ifndef access
+#define access _access
+#endif
+
+#ifndef __cplusplus
+
+#ifndef read
+#define read _read
+#endif
+
+#ifndef close
+#define close _close
+#endif
+
+#ifndef write
+#define write _write
+#endif
+
+#ifndef open
+#define open _open
+#endif
+
+#endif
+
+#ifndef unlink
+#define unlink _unlink
+#endif
+
+#ifndef strcasecmp
+#define strncasecmp _strnicmp
+#endif
+
+#ifndef strcasecmp
+
+#define strcasecmp _stricmp
+#endif
+
+#ifndef S_ISREG
+#define S_ISREG(mode) (((mode) &S_IFMT) == S_IFREG)
+#endif
+#ifndef R_OK
+#define R_OK 4 /* Test for read permission. */
+#endif
+#ifndef W_OK
+#define W_OK 2 /* Test for write permission. */
+#endif
+#ifndef F_OK
+#define F_OK 0
+#endif
+
+#ifndef STDIN_FILENO
+#define STDIN_FILENO _fileno (stdin)
+#endif
+
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO _fileno (stdout)
+#endif
+
+#ifndef STDERR_FILENO
+#define STDERR_FILENO _fileno (stderr)
+#endif
+
+#endif
+
+#ifndef __bswap_constant_32
+#define __bswap_constant_32(x) \
+ ((((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/includes/hicn/validation.h b/lib/includes/hicn/validation.h
new file mode 100644
index 000000000..05be6d306
--- /dev/null
+++ b/lib/includes/hicn/validation.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2022 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * 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 validation.h
+ * \brief Functions for input validation
+ */
+#include <ctype.h>
+#include <hicn/util/sstrncpy.h>
+
+static inline bool
+is_number (const char *string, size_t maxlen)
+{
+ size_t len = strnlen_s (string, maxlen);
+ for (size_t i = 0; i < len; i++)
+ {
+ if (!isdigit (string[i]))
+ return false;
+ }
+ return len != 0;
+}
+
+/**
+ * A symbolic name must be at least 1 character and must begin with an alpha.
+ * The remainder must be an alphanum.
+ */
+static inline bool
+is_symbolic_name (const char *name, size_t maxlen)
+{
+ size_t len = strnlen_s (name, maxlen);
+ if (len <= 0)
+ return false;
+ if (!isalpha (name[0]))
+ return false;
+
+ for (size_t i = 1; i < len; i++)
+ {
+ if (!isalnum (name[i]) && name[i] != '_' && name[i] != '-')
+ return false;
+ }
+
+ return true;
+}