aboutsummaryrefslogtreecommitdiffstats
path: root/lib/src/compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/src/compat.c')
-rw-r--r--lib/src/compat.c472
1 files changed, 284 insertions, 188 deletions
diff --git a/lib/src/compat.c b/lib/src/compat.c
index 615175e3b..779a47315 100644
--- a/lib/src/compat.c
+++ b/lib/src/compat.c
@@ -20,8 +20,8 @@
#ifndef _WIN32
#include <netinet/in.h>
#endif
-#include <string.h> // memset
-#include <stddef.h> // offsetof
+#include <string.h> // memset
+#include <stddef.h> // offsetof
#include <hicn/common.h>
#include <hicn/compat.h>
@@ -30,13 +30,13 @@
#include <hicn/name.h>
#include <hicn/ops.h>
-#define member_size(type, member) sizeof(((type *)0)->member)
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
+#define member_size(type, member) sizeof (((type *) 0)->member)
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof (*(a)))
#define HICN_NAME_COMPONENT_SIZE 2
int
-hicn_packet_get_format (const hicn_header_t * h, hicn_format_t * format)
+hicn_packet_get_format (const hicn_header_t *h, hicn_format_t *format)
{
*format = HF_UNSPEC;
@@ -122,7 +122,7 @@ hicn_format_to_type (hicn_format_t format)
* This function is used to wrap old API calls to new ones
*/
hicn_type_t
-hicn_header_to_type (const hicn_header_t * h)
+hicn_header_to_type (const hicn_header_t *h)
{
hicn_format_t format;
hicn_packet_get_format (h, &format);
@@ -130,39 +130,47 @@ hicn_header_to_type (const hicn_header_t * h)
}
int
-hicn_packet_init_header (hicn_format_t format, hicn_header_t * packet)
+hicn_packet_init_header (hicn_format_t format, hicn_header_t *packet)
{
hicn_type_t type = hicn_format_to_type (format);
+
+ if (hicn_type_is_none (type))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
return hicn_ops_vft[type.l1]->init_packet_header (type, &packet->protocol);
}
int
-hicn_packet_compute_checksum (hicn_format_t format, hicn_header_t * h)
+hicn_packet_compute_checksum (hicn_format_t format, hicn_header_t *h)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->update_checksums (type, &h->protocol, 0, 0);
+ return hicn_ops_vft[type.l1]->update_checksums (type, &h->protocol, 0, ~0);
}
int
-hicn_packet_compute_header_checksum (hicn_format_t format, hicn_header_t * h,
+hicn_packet_compute_header_checksum (hicn_format_t format, hicn_header_t *h,
u16 init_sum)
{
hicn_type_t type = hicn_format_to_type (format);
- /* payload_length == ~0: ignore payload */
- return hicn_ops_vft[type.l1]->update_checksums (type, &h->protocol,
- init_sum, ~0);
+ /* payload_length == 0: ignore payload */
+ return hicn_ops_vft[type.l1]->update_checksums (type, &h->protocol, init_sum,
+ 0);
}
int
-hicn_packet_check_integrity (hicn_format_t format, hicn_header_t * h)
+hicn_packet_check_integrity_no_payload (hicn_format_t format, hicn_header_t *h,
+ u16 init_sum)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->verify_checksums (type, &h->protocol, 0, 0);
+ return hicn_ops_vft[type.l1]->verify_checksums (type, &h->protocol, init_sum,
+ 0);
}
int
hicn_packet_get_header_length_from_format (hicn_format_t format,
- size_t * header_length)
+ size_t *header_length)
{
*header_length = _is_ipv4 (format) * IPV4_HDRLEN;
*header_length += _is_ipv6 (format) * IPV6_HDRLEN;
@@ -174,8 +182,8 @@ hicn_packet_get_header_length_from_format (hicn_format_t format,
}
int
-hicn_packet_get_header_length (hicn_format_t format, const hicn_header_t * h,
- size_t * header_length)
+hicn_packet_get_header_length (hicn_format_t format, const hicn_header_t *h,
+ size_t *header_length)
{
hicn_packet_get_header_length_from_format (format, header_length);
int is_ah = _is_ah (format);
@@ -184,15 +192,15 @@ hicn_packet_get_header_length (hicn_format_t format, const hicn_header_t * h,
// The signature payload is expressed as number of 32 bits words
if (is_ah && is_ipv4)
*header_length += (h->v4ah.ah.payloadlen) << 2;
- else if(is_ah && is_ipv6)
+ else if (is_ah && is_ipv6)
*header_length += (h->v6ah.ah.payloadlen) << 2;
return HICN_LIB_ERROR_NONE;
}
int
-hicn_packet_get_payload_length (hicn_format_t format, const hicn_header_t * h,
- size_t * payload_length)
+hicn_packet_get_payload_length (hicn_format_t format, const hicn_header_t *h,
+ size_t *payload_length)
{
hicn_type_t type = hicn_format_to_type (format);
return hicn_ops_vft[type.l1]->get_payload_length (type, &h->protocol,
@@ -200,7 +208,7 @@ hicn_packet_get_payload_length (hicn_format_t format, const hicn_header_t * h,
}
int
-hicn_packet_set_payload_length (hicn_format_t format, hicn_header_t * h,
+hicn_packet_set_payload_length (hicn_format_t format, hicn_header_t *h,
const size_t payload_length)
{
hicn_type_t type = hicn_format_to_type (format);
@@ -209,8 +217,8 @@ hicn_packet_set_payload_length (hicn_format_t format, hicn_header_t * h,
}
int
-hicn_packet_compare (const hicn_header_t * packet1,
- const hicn_header_t * packet2)
+hicn_packet_compare (const hicn_header_t *packet1,
+ const hicn_header_t *packet2)
{
hicn_type_t type1 = hicn_header_to_type (packet1);
hicn_type_t type2 = hicn_header_to_type (packet2);
@@ -233,25 +241,23 @@ hicn_packet_compare (const hicn_header_t * packet1,
return HICN_LIB_ERROR_UNEXPECTED;
return memcmp ((u8 *) packet1, (u8 *) packet2, len1);
-
}
int
-hicn_packet_get_name (hicn_format_t format, const hicn_header_t * h,
- hicn_name_t * name, u8 is_interest)
+hicn_packet_get_name (hicn_format_t format, const hicn_header_t *h,
+ hicn_name_t *name, u8 is_interest)
{
hicn_type_t type = hicn_format_to_type (format);
if (is_interest)
- return hicn_ops_vft[type.l1]->get_interest_name (type, &h->protocol,
- name);
+ return hicn_ops_vft[type.l1]->get_interest_name (type, &h->protocol, name);
else
return hicn_ops_vft[type.l1]->get_data_name (type, &h->protocol, name);
}
int
-hicn_packet_set_name (hicn_format_t format, hicn_header_t * h,
- const hicn_name_t * name, u8 is_interest)
+hicn_packet_set_name (hicn_format_t format, hicn_header_t *h,
+ const hicn_name_t *name, u8 is_interest)
{
hicn_type_t type = hicn_format_to_type (format);
@@ -261,23 +267,21 @@ hicn_packet_set_name (hicn_format_t format, hicn_header_t * h,
#endif /* HICN_VPP_PLUGIN */
if (is_interest)
- return hicn_ops_vft[type.l1]->set_interest_name (type, &h->protocol,
- name);
+ return hicn_ops_vft[type.l1]->set_interest_name (type, &h->protocol, name);
else
return hicn_ops_vft[type.l1]->set_data_name (type, &h->protocol, name);
}
int
-hicn_packet_set_payload (hicn_format_t format, hicn_header_t * h,
- const u8 * payload, u16 payload_length)
+hicn_packet_set_payload (hicn_format_t format, hicn_header_t *h,
+ const u8 *payload, u16 payload_length)
{
hicn_type_t type = hicn_format_to_type (format);
size_t header_length;
int rc;
- rc =
- hicn_ops_vft[type.l1]->get_header_length (type, &h->protocol,
- &header_length);
+ rc = hicn_ops_vft[type.l1]->get_header_length (type, &h->protocol,
+ &header_length);
if (rc < 0)
return rc;
@@ -288,22 +292,20 @@ hicn_packet_set_payload (hicn_format_t format, hicn_header_t * h,
}
int
-hicn_packet_get_payload (hicn_format_t format, const hicn_header_t * h,
- u8 ** payload, size_t * payload_size, bool hard_copy)
+hicn_packet_get_payload (hicn_format_t format, const hicn_header_t *h,
+ u8 **payload, size_t *payload_size, bool hard_copy)
{
size_t header_length, payload_length;
int rc;
hicn_type_t type = hicn_format_to_type (format);
- rc =
- hicn_ops_vft[type.l1]->get_header_length (type, &h->protocol,
- &header_length);
+ rc = hicn_ops_vft[type.l1]->get_header_length (type, &h->protocol,
+ &header_length);
if (rc < 0)
return rc;
- rc =
- hicn_ops_vft[type.l1]->get_payload_length (type, &h->protocol,
- &payload_length);
+ rc = hicn_ops_vft[type.l1]->get_payload_length (type, &h->protocol,
+ &payload_length);
if (rc < 0)
return rc;
@@ -320,23 +322,21 @@ hicn_packet_get_payload (hicn_format_t format, const hicn_header_t * h,
}
int
-hicn_packet_get_locator (hicn_format_t format, const hicn_header_t * h,
- ip_address_t * address, bool is_interest)
+hicn_packet_get_locator (hicn_format_t format, const hicn_header_t *h,
+ ip_address_t *address, bool is_interest)
{
int is_ipv4 = (format & HFO_INET);
int is_ipv6 = (format & HFO_INET6) >> 1;
if (is_ipv4)
{
- address->v4.as_inaddr = is_interest
- ? h->v4.ip.saddr.as_inaddr
- : h->v4.ip.daddr.as_inaddr;
+ address->v4.as_inaddr =
+ is_interest ? h->v4.ip.saddr.as_inaddr : h->v4.ip.daddr.as_inaddr;
}
else if (is_ipv6)
{
- address->v6.as_in6addr = is_interest
- ? h->v6.ip.saddr.as_in6addr
- : h->v6.ip.daddr.as_in6addr;
+ address->v6.as_in6addr =
+ is_interest ? h->v6.ip.saddr.as_in6addr : h->v6.ip.daddr.as_in6addr;
}
else
{
@@ -347,25 +347,25 @@ hicn_packet_get_locator (hicn_format_t format, const hicn_header_t * h,
}
int
-hicn_packet_set_locator (hicn_format_t format, hicn_header_t * h,
- const ip_address_t * address, bool is_interest)
+hicn_packet_set_locator (hicn_format_t format, hicn_header_t *h,
+ const ip_address_t *address, bool is_interest)
{
int is_ipv4 = (format & HFO_INET);
int is_ipv6 = (format & HFO_INET6) >> 1;
if (is_ipv6)
{
- if (is_interest)
- h->v6.ip.saddr.as_in6addr = address->v6.as_in6addr;
- else
- h->v6.ip.daddr.as_in6addr = address->v6.as_in6addr;
+ if (is_interest)
+ h->v6.ip.saddr.as_in6addr = address->v6.as_in6addr;
+ else
+ h->v6.ip.daddr.as_in6addr = address->v6.as_in6addr;
}
else if (is_ipv4)
{
- if (is_interest)
- h->v4.ip.saddr.as_inaddr = address->v4.as_inaddr;
- else
- h->v4.ip.daddr.as_inaddr = address->v4.as_inaddr;
+ if (is_interest)
+ h->v4.ip.saddr.as_inaddr = address->v4.as_inaddr;
+ else
+ h->v4.ip.daddr.as_inaddr = address->v4.as_inaddr;
}
else
{
@@ -376,79 +376,78 @@ hicn_packet_set_locator (hicn_format_t format, hicn_header_t * h,
}
int
-hicn_packet_get_signature_size (hicn_format_t format, const hicn_header_t * h,
- size_t * bytes)
+hicn_packet_get_signature_size (hicn_format_t format, const hicn_header_t *h,
+ size_t *bytes)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->get_signature_size (type, &h->protocol,
- bytes);
+ return hicn_ops_vft[type.l1]->get_signature_size (type, &h->protocol, bytes);
}
int
-hicn_packet_set_signature_size (hicn_format_t format, hicn_header_t * h,
+hicn_packet_set_signature_size (hicn_format_t format, hicn_header_t *h,
size_t bytes)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->set_signature_size (type, &h->protocol,
- bytes);
+ return hicn_ops_vft[type.l1]->set_signature_size (type, &h->protocol, bytes);
}
int
-hicn_packet_set_signature_timestamp (hicn_format_t format, hicn_header_t * h,
- uint64_t signature_timestamp)
+hicn_packet_set_signature_timestamp (hicn_format_t format, hicn_header_t *h,
+ uint64_t signature_timestamp)
{
hicn_type_t type = hicn_format_to_type (format);
return hicn_ops_vft[type.l1]->set_signature_timestamp (type, &h->protocol,
- signature_timestamp);
+ signature_timestamp);
}
int
-hicn_packet_get_signature_timestamp (hicn_format_t format, const hicn_header_t * h,
- uint64_t *signature_timestamp)
+hicn_packet_get_signature_timestamp (hicn_format_t format,
+ const hicn_header_t *h,
+ uint64_t *signature_timestamp)
{
hicn_type_t type = hicn_format_to_type (format);
return hicn_ops_vft[type.l1]->get_signature_timestamp (type, &h->protocol,
- signature_timestamp);
+ signature_timestamp);
}
int
-hicn_packet_set_validation_algorithm (hicn_format_t format, hicn_header_t * h,
- uint8_t validation_algorithm)
+hicn_packet_set_validation_algorithm (hicn_format_t format, hicn_header_t *h,
+ uint8_t validation_algorithm)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->set_validation_algorithm (type, &h->protocol,
- validation_algorithm);
+ return hicn_ops_vft[type.l1]->set_validation_algorithm (
+ type, &h->protocol, validation_algorithm);
}
int
-hicn_packet_get_validation_algorithm (hicn_format_t format, const hicn_header_t * h,
- uint8_t * validation_algorithm)
+hicn_packet_get_validation_algorithm (hicn_format_t format,
+ const hicn_header_t *h,
+ uint8_t *validation_algorithm)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->get_validation_algorithm (type, &h->protocol,
- validation_algorithm);
+ return hicn_ops_vft[type.l1]->get_validation_algorithm (
+ type, &h->protocol, validation_algorithm);
}
int
-hicn_packet_set_key_id (hicn_format_t format, hicn_header_t * h,
- uint8_t *key_id)
+hicn_packet_set_key_id (hicn_format_t format, hicn_header_t *h,
+ uint8_t *key_id)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->set_key_id (type, &h->protocol,
- key_id);
+ return hicn_ops_vft[type.l1]->set_key_id (type, &h->protocol, key_id);
}
int
-hicn_packet_get_key_id (hicn_format_t format, hicn_header_t * h,
- uint8_t ** key_id, uint8_t *key_id_length)
+hicn_packet_get_key_id (hicn_format_t format, hicn_header_t *h,
+ uint8_t **key_id, uint8_t *key_id_length)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->get_key_id (type, &h->protocol,
- key_id, key_id_length);
+ return hicn_ops_vft[type.l1]->get_key_id (type, &h->protocol, key_id,
+ key_id_length);
}
int
-hicn_packet_get_hoplimit (const hicn_header_t * h, u8 * hops)
+hicn_packet_get_hoplimit (const hicn_header_t *h, u8 *hops)
{
switch (HICN_IP_VERSION (h))
{
@@ -466,7 +465,7 @@ hicn_packet_get_hoplimit (const hicn_header_t * h, u8 * hops)
}
int
-hicn_packet_set_hoplimit (hicn_header_t * h, u8 hops)
+hicn_packet_set_hoplimit (hicn_header_t *h, u8 hops)
{
switch (HICN_IP_VERSION (h))
{
@@ -483,9 +482,8 @@ hicn_packet_set_hoplimit (hicn_header_t * h, u8 hops)
return HICN_LIB_ERROR_NONE;
}
-
int
-hicn_packet_get_lifetime (const hicn_header_t * h, u32 * lifetime)
+hicn_packet_get_lifetime (const hicn_header_t *h, u32 *lifetime)
{
hicn_type_t type = hicn_header_to_type (h);
return hicn_ops_vft[type.l1]->get_lifetime (type, &h->protocol,
@@ -493,7 +491,7 @@ hicn_packet_get_lifetime (const hicn_header_t * h, u32 * lifetime)
}
int
-hicn_packet_set_lifetime (hicn_header_t * h, u32 lifetime)
+hicn_packet_set_lifetime (hicn_header_t *h, u32 lifetime)
{
hicn_type_t type = hicn_header_to_type (h);
return hicn_ops_vft[type.l1]->set_lifetime (type, &h->protocol,
@@ -501,15 +499,15 @@ hicn_packet_set_lifetime (hicn_header_t * h, u32 lifetime)
}
int
-hicn_packet_get_reserved_bits (const hicn_header_t * h, u8 * reserved_bits)
+hicn_packet_get_reserved_bits (const hicn_header_t *h, u8 *reserved_bits)
{
switch (HICN_IP_VERSION (h))
{
case 6:
- *reserved_bits = (u8)(h->v6.tcp.reserved);
+ *reserved_bits = (u8) (h->v6.tcp.reserved);
break;
case 4:
- *reserved_bits = (u8)(h->v4.tcp.reserved);
+ *reserved_bits = (u8) (h->v4.tcp.reserved);
break;
default:
return HICN_LIB_ERROR_UNEXPECTED;
@@ -519,7 +517,7 @@ hicn_packet_get_reserved_bits (const hicn_header_t * h, u8 * reserved_bits)
}
int
-hicn_packet_set_reserved_bits (hicn_header_t * h, const u8 reserved_bits)
+hicn_packet_set_reserved_bits (hicn_header_t *h, const u8 reserved_bits)
{
switch (HICN_IP_VERSION (h))
{
@@ -537,16 +535,18 @@ hicn_packet_set_reserved_bits (hicn_header_t * h, const u8 reserved_bits)
}
int
-hicn_packet_get_payload_type (const hicn_header_t * h,
- hicn_payload_type_t * payload_type)
+hicn_packet_get_payload_type (const hicn_header_t *h,
+ hicn_payload_type_t *payload_type)
{
switch (HICN_IP_VERSION (h))
{
case 6:
- *payload_type = ((h->v6.tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG);
+ *payload_type =
+ ((h->v6.tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG);
break;
case 4:
- *payload_type = ((h->v4.tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG);
+ *payload_type =
+ ((h->v4.tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG);
break;
default:
return HICN_LIB_ERROR_UNEXPECTED;
@@ -561,7 +561,7 @@ hicn_packet_get_payload_type (const hicn_header_t * h,
}
int
-hicn_packet_set_payload_type (hicn_header_t * h,
+hicn_packet_set_payload_type (hicn_header_t *h,
hicn_payload_type_t payload_type)
{
if (payload_type != HPT_DATA && payload_type != HPT_MANIFEST)
@@ -591,8 +591,13 @@ hicn_packet_set_payload_type (hicn_header_t * h,
}
int
-hicn_packet_set_syn (hicn_header_t * h)
+hicn_packet_set_syn (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -608,8 +613,13 @@ hicn_packet_set_syn (hicn_header_t * h)
}
int
-hicn_packet_reset_syn (hicn_header_t * h)
+hicn_packet_reset_syn (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -625,8 +635,13 @@ hicn_packet_reset_syn (hicn_header_t * h)
}
int
-hicn_packet_test_syn (const hicn_header_t * h, bool * flag)
+hicn_packet_test_syn (hicn_format_t format, const hicn_header_t *h, bool *flag)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -642,8 +657,13 @@ hicn_packet_test_syn (const hicn_header_t * h, bool * flag)
}
int
-hicn_packet_set_ack (hicn_header_t * h)
+hicn_packet_set_ack (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -659,8 +679,13 @@ hicn_packet_set_ack (hicn_header_t * h)
}
int
-hicn_packet_reset_ack (hicn_header_t * h)
+hicn_packet_reset_ack (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -676,8 +701,13 @@ hicn_packet_reset_ack (hicn_header_t * h)
}
int
-hicn_packet_test_ack (const hicn_header_t * h, bool * flag)
+hicn_packet_test_ack (hicn_format_t format, const hicn_header_t *h, bool *flag)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -693,8 +723,13 @@ hicn_packet_test_ack (const hicn_header_t * h, bool * flag)
}
int
-hicn_packet_set_rst (hicn_header_t * h)
+hicn_packet_set_rst (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -710,8 +745,13 @@ hicn_packet_set_rst (hicn_header_t * h)
}
int
-hicn_packet_reset_rst (hicn_header_t * h)
+hicn_packet_reset_rst (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -727,8 +767,13 @@ hicn_packet_reset_rst (hicn_header_t * h)
}
int
-hicn_packet_test_rst (const hicn_header_t * h, bool * flag)
+hicn_packet_test_rst (hicn_format_t format, const hicn_header_t *h, bool *flag)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -744,8 +789,13 @@ hicn_packet_test_rst (const hicn_header_t * h, bool * flag)
}
int
-hicn_packet_set_fin (hicn_header_t * h)
+hicn_packet_set_fin (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -761,8 +811,13 @@ hicn_packet_set_fin (hicn_header_t * h)
}
int
-hicn_packet_reset_fin (hicn_header_t * h)
+hicn_packet_reset_fin (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -778,8 +833,13 @@ hicn_packet_reset_fin (hicn_header_t * h)
}
int
-hicn_packet_test_fin (const hicn_header_t * h, bool * flag)
+hicn_packet_test_fin (hicn_format_t format, const hicn_header_t *h, bool *flag)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -795,8 +855,13 @@ hicn_packet_test_fin (const hicn_header_t * h, bool * flag)
}
int
-hicn_packet_set_ece (hicn_header_t * h)
+hicn_packet_set_ece (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -812,8 +877,13 @@ hicn_packet_set_ece (hicn_header_t * h)
}
int
-hicn_packet_reset_ece (hicn_header_t * h)
+hicn_packet_reset_ece (hicn_format_t format, hicn_header_t *h)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -829,8 +899,13 @@ hicn_packet_reset_ece (hicn_header_t * h)
}
int
-hicn_packet_test_ece (const hicn_header_t * h, bool * flag)
+hicn_packet_test_ece (hicn_format_t format, const hicn_header_t *h, bool *flag)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -846,8 +921,13 @@ hicn_packet_test_ece (const hicn_header_t * h, bool * flag)
}
int
-hicn_packet_set_src_port (hicn_header_t * h, u16 src_port)
+hicn_packet_set_src_port (hicn_format_t format, hicn_header_t *h, u16 src_port)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -863,8 +943,14 @@ hicn_packet_set_src_port (hicn_header_t * h, u16 src_port)
}
int
-hicn_packet_get_src_port (const hicn_header_t * h, u16 * src_port)
+hicn_packet_get_src_port (hicn_format_t format, const hicn_header_t *h,
+ u16 *src_port)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -880,8 +966,13 @@ hicn_packet_get_src_port (const hicn_header_t * h, u16 * src_port)
}
int
-hicn_packet_set_dst_port (hicn_header_t * h, u16 dst_port)
+hicn_packet_set_dst_port (hicn_format_t format, hicn_header_t *h, u16 dst_port)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -897,8 +988,14 @@ hicn_packet_set_dst_port (hicn_header_t * h, u16 dst_port)
}
int
-hicn_packet_get_dst_port (const hicn_header_t * h, u16 * dst_port)
+hicn_packet_get_dst_port (hicn_format_t format, const hicn_header_t *h,
+ u16 *dst_port)
{
+ if (!_is_tcp (format))
+ {
+ return HICN_LIB_ERROR_UNEXPECTED;
+ }
+
switch (HICN_IP_VERSION (h))
{
case 6:
@@ -914,8 +1011,8 @@ hicn_packet_get_dst_port (const hicn_header_t * h, u16 * dst_port)
}
int
-hicn_packet_copy_header (hicn_format_t format, const hicn_header_t * packet,
- hicn_header_t * destination, bool copy_ah)
+hicn_packet_copy_header (hicn_format_t format, const hicn_header_t *packet,
+ hicn_header_t *destination, bool copy_ah)
{
size_t header_length = _is_ipv4 (format) * IPV4_HDRLEN;
header_length += _is_ipv6 (format) * IPV6_HDRLEN;
@@ -929,95 +1026,95 @@ hicn_packet_copy_header (hicn_format_t format, const hicn_header_t * packet,
}
#define _INTEREST 1
-#define _DATA 0
+#define _DATA 0
/* Interest */
int
-hicn_interest_get_name (hicn_format_t format, const hicn_header_t * interest,
- hicn_name_t * name)
+hicn_interest_get_name (hicn_format_t format, const hicn_header_t *interest,
+ hicn_name_t *name)
{
return hicn_packet_get_name (format, interest, name, _INTEREST);
}
int
-hicn_interest_set_name (hicn_format_t format, hicn_header_t * interest,
- const hicn_name_t * name)
+hicn_interest_set_name (hicn_format_t format, hicn_header_t *interest,
+ const hicn_name_t *name)
{
- int ret_err = hicn_packet_reset_ece (interest); //interest packet -> ece flag unset
+ int ret_err =
+ hicn_packet_reset_ece (format, interest); // interest packet -> ece flag unset
if (ret_err < 0)
return HICN_LIB_ERROR_UNEXPECTED;
return hicn_packet_set_name (format, interest, name, _INTEREST);
}
int
-hicn_interest_get_locator (hicn_format_t format,
- const hicn_header_t * interest,
- ip_address_t * address)
+hicn_interest_get_locator (hicn_format_t format, const hicn_header_t *interest,
+ ip_address_t *address)
{
return hicn_packet_get_locator (format, interest, address, _INTEREST);
}
int
-hicn_interest_set_locator (hicn_format_t format, hicn_header_t * interest,
- const ip_address_t * address)
+hicn_interest_set_locator (hicn_format_t format, hicn_header_t *interest,
+ const ip_address_t *address)
{
return hicn_packet_set_locator (format, interest, address, _INTEREST);
}
int
-hicn_interest_compare (const hicn_header_t * interest_1,
- const hicn_header_t * interest_2)
+hicn_interest_compare (const hicn_header_t *interest_1,
+ const hicn_header_t *interest_2)
{
return hicn_packet_compare (interest_1, interest_2);
}
int
-hicn_interest_get_lifetime (const hicn_header_t * interest, u32 * lifetime)
+hicn_interest_get_lifetime (const hicn_header_t *interest, u32 *lifetime)
{
return hicn_packet_get_lifetime (interest, lifetime);
}
int
-hicn_interest_set_lifetime (hicn_header_t * interest, u32 lifetime)
+hicn_interest_set_lifetime (hicn_header_t *interest, u32 lifetime)
{
return hicn_packet_set_lifetime (interest, lifetime);
}
int
hicn_interest_get_header_length (hicn_format_t format,
- const hicn_header_t * interest,
- size_t * header_length)
+ const hicn_header_t *interest,
+ size_t *header_length)
{
return hicn_packet_get_header_length (format, interest, header_length);
}
int
hicn_interest_get_payload_length (hicn_format_t format,
- const hicn_header_t * interest,
- size_t * payload_length)
+ const hicn_header_t *interest,
+ size_t *payload_length)
{
return hicn_packet_get_payload_length (format, interest, payload_length);
}
int
-hicn_interest_get_payload (hicn_format_t format,
- const hicn_header_t * interest, u8 ** payload,
- size_t * payload_size, bool hard_copy)
+hicn_interest_get_payload (hicn_format_t format, const hicn_header_t *interest,
+ u8 **payload, size_t *payload_size, bool hard_copy)
{
return hicn_packet_get_payload (format, interest, payload, payload_size,
hard_copy);
}
int
-hicn_interest_set_payload (hicn_format_t format, hicn_header_t * interest,
- const u8 * payload, size_t payload_length)
+hicn_interest_set_payload (hicn_format_t format, hicn_header_t *interest,
+ const u8 *payload, size_t payload_length)
{
- return hicn_packet_set_payload (format, interest, payload, (u16)payload_length);
+ return hicn_packet_set_payload (format, interest, payload,
+ (u16) payload_length);
}
int
-hicn_interest_reset_for_hash (hicn_format_t format, hicn_header_t * packet)
+hicn_interest_reset_for_hash (hicn_format_t format, hicn_header_t *packet)
{
hicn_type_t type = hicn_format_to_type (format);
return hicn_ops_vft[type.l1]->reset_interest_for_hash (type,
@@ -1027,85 +1124,84 @@ hicn_interest_reset_for_hash (hicn_format_t format, hicn_header_t * packet)
/* Data */
int
-hicn_data_get_name (hicn_format_t format, const hicn_header_t * data,
- hicn_name_t * name)
+hicn_data_get_name (hicn_format_t format, const hicn_header_t *data,
+ hicn_name_t *name)
{
return hicn_packet_get_name (format, data, name, _DATA);
}
int
-hicn_data_set_name (hicn_format_t format, hicn_header_t * data,
- const hicn_name_t * name)
+hicn_data_set_name (hicn_format_t format, hicn_header_t *data,
+ const hicn_name_t *name)
{
- int ret_err = hicn_packet_set_ece (data); //data packet -> ece flag set
+ int ret_err = hicn_packet_set_ece (format, data); // data packet -> ece flag set
if (ret_err < 0)
return HICN_LIB_ERROR_UNEXPECTED;
return hicn_packet_set_name (format, data, name, _DATA);
}
int
-hicn_data_get_locator (hicn_format_t format, const hicn_header_t * data,
- ip_address_t * address)
+hicn_data_get_locator (hicn_format_t format, const hicn_header_t *data,
+ ip_address_t *address)
{
return hicn_packet_get_locator (format, data, address, _DATA);
}
int
-hicn_data_set_locator (hicn_format_t format, hicn_header_t * data,
- const ip_address_t * address)
+hicn_data_set_locator (hicn_format_t format, hicn_header_t *data,
+ const ip_address_t *address)
{
return hicn_packet_set_locator (format, data, address, _DATA);
}
int
-hicn_data_compare (const hicn_header_t * data_1, const hicn_header_t * data_2)
+hicn_data_compare (const hicn_header_t *data_1, const hicn_header_t *data_2)
{
return hicn_packet_compare (data_1, data_2);
}
int
-hicn_data_get_expiry_time (const hicn_header_t * data, u32 * expiry_time)
+hicn_data_get_expiry_time (const hicn_header_t *data, u32 *expiry_time)
{
return hicn_packet_get_lifetime (data, expiry_time);
}
int
-hicn_data_set_expiry_time (hicn_header_t * data, u32 expiry_time)
+hicn_data_set_expiry_time (hicn_header_t *data, u32 expiry_time)
{
return hicn_packet_set_lifetime (data, (hicn_lifetime_t) expiry_time);
}
int
-hicn_data_get_header_length (hicn_format_t format, hicn_header_t * data,
- size_t * header_length)
+hicn_data_get_header_length (hicn_format_t format, hicn_header_t *data,
+ size_t *header_length)
{
return hicn_packet_get_header_length (format, data, header_length);
}
int
-hicn_data_get_payload_length (hicn_format_t format,
- const hicn_header_t * data,
- size_t * payload_length)
+hicn_data_get_payload_length (hicn_format_t format, const hicn_header_t *data,
+ size_t *payload_length)
{
return hicn_packet_get_payload_length (format, data, payload_length);
}
int
-hicn_data_set_payload_type (hicn_header_t * data,
+hicn_data_set_payload_type (hicn_header_t *data,
hicn_payload_type_t payload_type)
{
return hicn_packet_set_payload_type (data, payload_type);
}
int
-hicn_data_get_payload_type (const hicn_header_t * data,
- hicn_payload_type_t * payload_type)
+hicn_data_get_payload_type (const hicn_header_t *data,
+ hicn_payload_type_t *payload_type)
{
return hicn_packet_get_payload_type (data, payload_type);
}
int
-hicn_data_get_path_label (const hicn_header_t * data, u32 * path_label)
+hicn_data_get_path_label (const hicn_header_t *data, u32 *path_label)
{
hicn_type_t type = hicn_header_to_type (data);
return hicn_ops_vft[type.l1]->get_data_pathlabel (type, &data->protocol,
@@ -1113,7 +1209,7 @@ hicn_data_get_path_label (const hicn_header_t * data, u32 * path_label)
}
int
-hicn_data_set_path_label (hicn_header_t * data, u32 path_label)
+hicn_data_set_path_label (hicn_header_t *data, u32 path_label)
{
hicn_type_t type = hicn_header_to_type (data);
return hicn_ops_vft[type.l1]->set_data_pathlabel (type, &data->protocol,
@@ -1121,34 +1217,34 @@ hicn_data_set_path_label (hicn_header_t * data, u32 path_label)
}
int
-hicn_data_set_payload (hicn_format_t format, hicn_header_t * data,
- const u8 * payload, size_t payload_length)
+hicn_data_set_payload (hicn_format_t format, hicn_header_t *data,
+ const u8 *payload, size_t payload_length)
{
- return hicn_packet_set_payload (format, data, payload, (u16)payload_length);
+ return hicn_packet_set_payload (format, data, payload, (u16) payload_length);
}
int
-hicn_data_get_payload (hicn_format_t format, const hicn_header_t * data,
- u8 ** payload, size_t * payload_size, bool hard_copy)
+hicn_data_get_payload (hicn_format_t format, const hicn_header_t *data,
+ u8 **payload, size_t *payload_size, bool hard_copy)
{
return hicn_packet_get_payload (format, data, payload, payload_size,
hard_copy);
}
int
-hicn_data_reset_for_hash (hicn_format_t format, hicn_header_t * packet)
+hicn_data_reset_for_hash (hicn_format_t format, hicn_header_t *packet)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->reset_data_for_hash (type,
- &packet->protocol);
-
+ return hicn_ops_vft[type.l1]->reset_data_for_hash (type, &packet->protocol);
}
-int hicn_packet_get_signature(hicn_format_t format, hicn_header_t * packet, uint8_t ** sign_buf)
+int
+hicn_packet_get_signature (hicn_format_t format, hicn_header_t *packet,
+ uint8_t **sign_buf)
{
hicn_type_t type = hicn_format_to_type (format);
- return hicn_ops_vft[type.l1]->get_signature (type,
- &packet->protocol, sign_buf);
+ return hicn_ops_vft[type.l1]->get_signature (type, &packet->protocol,
+ sign_buf);
}
/*