aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/src/common.h30
-rw-r--r--lib/src/compat.h33
-rw-r--r--lib/src/header.h28
-rw-r--r--lib/src/mapme.c32
-rw-r--r--lib/src/mapme.h29
-rw-r--r--lib/src/protocol/ah.h11
-rw-r--r--lib/src/protocol/icmp.h18
-rw-r--r--lib/src/protocol/icmprd.h29
-rw-r--r--lib/src/protocol/ipv4.h14
-rw-r--r--lib/src/protocol/ipv6.h15
-rw-r--r--lib/src/protocol/tcp.h9
-rw-r--r--lib/src/protocol/udp.h7
12 files changed, 198 insertions, 57 deletions
diff --git a/lib/src/common.h b/lib/src/common.h
index e67762301..1d4b1e6bf 100644
--- a/lib/src/common.h
+++ b/lib/src/common.h
@@ -80,7 +80,7 @@ typedef uint8_t u8;
#define __ORDER_BIG_ENDIAN__ 0x44434241UL
#define __BYTE_ORDER__ ('ABCD')
- /* Windows compatibility headers*/
+ /* Windows compatibility headers */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
@@ -95,14 +95,22 @@ typedef uint8_t u8;
#define IOVEC
#define UIO_MAXIOV 16
#define IOV_MAX UIO_MAXIOV
-struct iovec {
- void* iov_base;
- size_t iov_len;
+struct iovec
+{
+ void *iov_base;
+ size_t iov_len;
};
#endif
-
#endif
+/*
+ * Portable attribute packed.
+ */
+#ifndef _WIN32
+#define PACKED( __Declaration__ ) __Declaration__ __attribute__((__packed__))
+#else
+#define PACKED( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
+#endif
/*
@@ -120,6 +128,7 @@ struct iovec {
#ifndef _WIN32
#include <netinet/in.h>
#endif
+
typedef union
{
u32 as_u32;
@@ -265,6 +274,17 @@ csum (const void *addr, size_t size, u16 init)
*/
#define HICN_IP_VERSION(packet) ((hicn_header_t *)packet)->v4.ip.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))
+#endif
+
+#ifndef ntohll
+#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/src/compat.h b/lib/src/compat.h
index 52dd41f1e..e174414a4 100644
--- a/lib/src/compat.h
+++ b/lib/src/compat.h
@@ -58,12 +58,6 @@ typedef enum
} hicn_format_t;
/**
- * Maximum Size of the hICN header (the effective size will depend on the
- * underlying IP version)
- */
-#define HICN_HDR_LEN sizeof(hicn_header_t)
-
-/**
* Minimum required header length to determine the type and length of a supposed
* hICN packet.
* This should be equal to the maximum value over all possible hICN packet
@@ -283,8 +277,9 @@ int hicn_packet_set_signature_size (hicn_format_t format,
* @param [in] signature_timestamp - Signature timestamp to set
* @return hICN error code
*/
-int hicn_packet_set_signature_timestamp (hicn_format_t format, hicn_header_t * h,
- uint64_t signature_timestamp);
+int hicn_packet_set_signature_timestamp (hicn_format_t format,
+ hicn_header_t * h,
+ uint64_t signature_timestamp);
/**
* @brief Sets the signature size
@@ -293,8 +288,9 @@ int hicn_packet_set_signature_timestamp (hicn_format_t format, hicn_header_t * h
* @param [out] signature_timestamp - Retrieved signature timestamp
* @return hICN error code
*/
-int hicn_packet_get_signature_timestamp (hicn_format_t format, const hicn_header_t * h,
- uint64_t *signature_timestamp);
+int hicn_packet_get_signature_timestamp (hicn_format_t format,
+ const hicn_header_t * h,
+ uint64_t * signature_timestamp);
/**
* @brief Sets the signature size
@@ -303,8 +299,9 @@ int hicn_packet_get_signature_timestamp (hicn_format_t format, const hicn_header
* @param [in] validation_algorithm - Validation algorithm to set
* @return hICN error code
*/
-int hicn_packet_set_validation_algorithm (hicn_format_t format, hicn_header_t * h,
- uint8_t validation_algorithm);
+int hicn_packet_set_validation_algorithm (hicn_format_t format,
+ hicn_header_t * h,
+ uint8_t validation_algorithm);
/**
* @brief Sets the signature size
@@ -313,8 +310,9 @@ int hicn_packet_set_validation_algorithm (hicn_format_t format, hicn_header_t *
* @param [out] validation_algorithm - Retrieved validation algorithm
* @return hICN error code
*/
-int hicn_packet_get_validation_algorithm (hicn_format_t format, const hicn_header_t * h,
- uint8_t * validation_algorithm);
+int hicn_packet_get_validation_algorithm (hicn_format_t format,
+ const hicn_header_t * h,
+ uint8_t * validation_algorithm);
/**
* @brief Sets the signature size
@@ -324,7 +322,7 @@ int hicn_packet_get_validation_algorithm (hicn_format_t format, const hicn_heade
* @return hICN error code
*/
int hicn_packet_set_key_id (hicn_format_t format, hicn_header_t * h,
- uint8_t *key_id);
+ uint8_t * key_id);
/**
* @brief Sets the signature size
@@ -334,7 +332,7 @@ int hicn_packet_set_key_id (hicn_format_t format, hicn_header_t * h,
* @return hICN error code
*/
int hicn_packet_get_key_id (hicn_format_t format, hicn_header_t * h,
- uint8_t ** key_id, uint8_t *key_id_length);
+ uint8_t ** key_id, uint8_t * key_id_length);
/**
* @brief Retrieves the packet hop limit
@@ -387,7 +385,8 @@ int hicn_packet_set_src_port (hicn_header_t * packet, u16 src_port);
int hicn_packet_get_src_port (const hicn_header_t * packet, u16 * src_port);
int hicn_packet_set_dst_port (hicn_header_t * packet, u16 dst_port);
int hicn_packet_get_dst_port (const hicn_header_t * packet, u16 * dst_port);
-int hicn_packet_get_signature(hicn_format_t format, hicn_header_t * packet, uint8_t ** sign_buf);
+int hicn_packet_get_signature (hicn_format_t format, hicn_header_t * packet,
+ uint8_t ** sign_buf);
/* Interest */
int hicn_interest_get_name (hicn_format_t format,
diff --git a/lib/src/header.h b/lib/src/header.h
index 3864064f2..b21fe5c84 100644
--- a/lib/src/header.h
+++ b/lib/src/header.h
@@ -16,15 +16,20 @@
/**
* @file header.h
* @brief hICN header data structures.
- * details.
+ *
+ * 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.
*/
+
#ifndef HICN_HEADER_H
#define HICN_HEADER_H
#include "common.h"
#include "protocol.h"
-
typedef struct
{
_ipv6_header_t ip;
@@ -94,6 +99,25 @@ 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_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/src/mapme.c b/lib/src/mapme.c
index 746336205..ccd384b21 100644
--- a/lib/src/mapme.c
+++ b/lib/src/mapme.c
@@ -44,14 +44,10 @@ hicn_mapme_v4_create_packet (u8 * buf, const hicn_prefix_t * prefix,
.saddr.as_u32 = 0,
.daddr = prefix->name.ip4,
},
- .icmp = {
- .type = ((params->type == UPDATE) || (params->type == NOTIFICATION))
- ? HICN_MAPME_ICMP_TYPE_IPV4
- : HICN_MAPME_ICMP_TYPE_ACK_IPV4,
+ .icmp_rd = {
+ .type = ((params->type == UPDATE) || (params->type == NOTIFICATION)) ? HICN_MAPME_ICMP_TYPE_IPV4 : HICN_MAPME_ICMP_TYPE_ACK_IPV4,
.code = HICN_MAPME_ICMP_CODE,
.csum = 0,
- },
- .icmp_rd = {
.ip = prefix->name.ip4,
},
.seq = htonl(params->seq),
@@ -80,14 +76,10 @@ hicn_mapme_v6_create_packet (u8 * buf, const hicn_prefix_t * prefix,
.nxt = IPPROTO_ICMPV6,
.hlim = HICN_MAPME_TTL,
},
- .icmp = {
- .type = ((params->type == UPDATE) || (params->type == NOTIFICATION))
- ? HICN_MAPME_ICMP_TYPE_IPV6
- : HICN_MAPME_ICMP_TYPE_ACK_IPV6,
+ .icmp_rd = {
+ .type = ((params->type == UPDATE) || (params->type == NOTIFICATION)) ? HICN_MAPME_ICMP_TYPE_IPV6 : HICN_MAPME_ICMP_TYPE_ACK_IPV6,
.code = HICN_MAPME_ICMP_CODE,
.csum = 0,
- },
- .icmp_rd = {
.res = 0,
.tgt = prefix->name.ip6,
.dst = prefix->name.ip6,
@@ -120,8 +112,8 @@ hicn_mapme_v4_create_ack (u8 * buf, const mapme_params_t * params)
mh->ip.daddr = mh->ip.saddr;
mh->ip.saddr = tmp;
mh->ip.ttl = HICN_MAPME_TTL;
- mh->icmp.type = HICN_MAPME_ICMP_TYPE_ACK_IPV4;
- mh->icmp.csum = 0;
+ mh->icmp_rd.type = HICN_MAPME_ICMP_TYPE_ACK_IPV4;
+ mh->icmp_rd.csum = 0;
return HICN_MAPME_V4_HDRLEN;
}
@@ -136,8 +128,8 @@ hicn_mapme_v6_create_ack (u8 * buf, const mapme_params_t * params)
mh->ip.daddr = mh->ip.saddr;
mh->ip.saddr = tmp;
mh->ip.hlim = HICN_MAPME_TTL;
- mh->icmp.type = HICN_MAPME_ICMP_TYPE_ACK_IPV6;
- mh->icmp.csum = 0;
+ mh->icmp_rd.type = HICN_MAPME_ICMP_TYPE_ACK_IPV6;
+ mh->icmp_rd.csum = 0;
return HICN_MAPME_V6_HDRLEN;
}
@@ -161,14 +153,14 @@ hicn_mapme_v4_parse_packet (const u8 * packet, hicn_prefix_t * prefix,
/* *INDENT-OFF* */
*prefix = (hicn_prefix_t) {
.name = {
- .ip4 = HICN_MAPME_TYPE_IS_IU (mh->icmp.type) ? mh->ip.daddr : mh->ip.saddr,
+ .ip4 = HICN_MAPME_TYPE_IS_IU (mh->icmp_rd.type) ? mh->ip.daddr : mh->ip.saddr,
},
.len = mh->len,
};
*params = (mapme_params_t) {
.protocol = IPPROTO_IP,
- .type = (mh->icmp.type == HICN_MAPME_ICMP_TYPE_IPV4) ? UPDATE : UPDATE_ACK,
+ .type = (mh->icmp_rd.type == HICN_MAPME_ICMP_TYPE_IPV4) ? UPDATE : UPDATE_ACK,
.seq = ntohl (mh->seq),
};
/* *INDENT-ON* */
@@ -185,14 +177,14 @@ hicn_mapme_v6_parse_packet (const u8 * packet, hicn_prefix_t * prefix,
/* *INDENT-OFF* */
*prefix = (hicn_prefix_t) {
.name = {
- .ip6 = HICN_MAPME_TYPE_IS_IU (mh->icmp.type) ? mh->ip.daddr : mh->ip.saddr,
+ .ip6 = HICN_MAPME_TYPE_IS_IU (mh->icmp_rd.type) ? mh->ip.daddr : mh->ip.saddr,
},
.len = mh->len,
};
*params = (mapme_params_t) {
.protocol = IPPROTO_IPV6,
- .type = (mh->icmp.type == HICN_MAPME_ICMP_TYPE_IPV6) ? UPDATE : UPDATE_ACK,
+ .type = (mh->icmp_rd.type == HICN_MAPME_ICMP_TYPE_IPV6) ? UPDATE : UPDATE_ACK,
.seq = ntohl (mh->seq),
};
/* *INDENT-ON* */
diff --git a/lib/src/mapme.h b/lib/src/mapme.h
index 00c7ca798..8fae44530 100644
--- a/lib/src/mapme.h
+++ b/lib/src/mapme.h
@@ -47,10 +47,10 @@ typedef struct
/** @brief Default MAP-Me configuration */
static const hicn_mapme_conf_t hicn_mapme_conf = {
- ATTR_INIT(enabled, false),
- ATTR_INIT(timescale, 0),
- ATTR_INIT(retx, 50),
- ATTR_INIT(discovery, true),
+ ATTR_INIT (enabled, false),
+ ATTR_INIT (timescale, 0),
+ ATTR_INIT (retx, 50),
+ ATTR_INIT (discovery, true),
};
/** @brief MAP-Me update sequence number */
@@ -106,22 +106,30 @@ int hicn_mapme_parse_packet (const u8 * packet, hicn_prefix_t * prefix,
/* Default TTL */
#define HICN_MAPME_TTL 255 // typical for redirect (ref?)
+/*
+ * The length of the MAPME4 header struct must be 120 bytes.
+ */
+#define EXPECTED_MAPME_V4_HDRLEN 120
+
/** @brief MAP-Me packet header for IPv4 */
-typedef struct __attribute__ ((packed))
+typedef struct
{
_ipv4_header_t ip;
- _icmp_header_t icmp;
_icmprd4_header_t icmp_rd;
seq_t seq;
u8 len;
u8 _pad[3];
} hicn_mapme_v4_header_t;
+/*
+ * The length of the MAPME4 header struct must be bytes.
+ */
+#define EXPECTED_MAPME_V6_HDRLEN 88
+
/** @brief MAP-Me packet header for IPv6 */
-typedef struct __attribute__ ((packed))
+typedef struct
{
_ipv6_header_t ip;
- _icmp_header_t icmp;
_icmprd_header_t icmp_rd;
seq_t seq;
u8 len;
@@ -138,6 +146,11 @@ typedef union
#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.");
+static_assert (EXPECTED_MAPME_V6_HDRLEN == HICN_MAPME_V6_HDRLEN,
+ "Size of MAPME_V6 struct does not match its expected size.");
+
#endif /* HICN_MAPME_H */
/*
diff --git a/lib/src/protocol/ah.h b/lib/src/protocol/ah.h
index f8a05bf38..a59a5051a 100644
--- a/lib/src/protocol/ah.h
+++ b/lib/src/protocol/ah.h
@@ -20,12 +20,19 @@
#ifndef HICN_PROTOCOL_AH_H
#define HICN_PROTOCOL_AH_H
+#include "../common.h"
+
/*
* The TCP PSH flag is set to indicate TCP payload in fact contains a AH header
* with signature information for the packet
*/
#define AH_FLAG 0x10
+/*
+ * The length of the AH struct must be 44 bytes.
+ */
+#define EXPECTED_AH_HDRLEN 44
+
typedef struct
{
u8 nh; // (to match with reserved in IPSEC AH)
@@ -49,6 +56,8 @@ typedef struct
};
// Unix timestamp indicating when the signature has been calculated
u8 timestamp_as_u8[8];
+ u16 timestamp_as_u16[4];
+ u32 timestamp_as_u32[2];
};
// ICV would follow
u8 keyId[32]; // Hash of the pub key
@@ -57,6 +66,8 @@ typedef struct
} _ah_header_t;
#define AH_HDRLEN sizeof(_ah_header_t)
+static_assert (EXPECTED_AH_HDRLEN == AH_HDRLEN,
+ "Size of AH Struct does not match its expected size.");
#endif /* HICN_PROTOCOL_AH_H */
diff --git a/lib/src/protocol/icmp.h b/lib/src/protocol/icmp.h
index 5a84995b6..36954bb6d 100644
--- a/lib/src/protocol/icmp.h
+++ b/lib/src/protocol/icmp.h
@@ -22,6 +22,11 @@
#include "../common.h"
+/*
+ * The length of the ICMP header struct must be 4 bytes.
+ */
+#define EXPECTED_ICMP_HDRLEN 4
+
typedef struct
{
u8 type;
@@ -29,6 +34,15 @@ typedef struct
u16 csum;
} _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.");
+
+/*
+ * The length of the ICMPWLDR header struct must be 4 bytes.
+ */
+#define EXPECTED_ICMPWLDR_HDRLEN 8
+
typedef struct
{
u8 type;
@@ -55,7 +69,9 @@ typedef struct
};
} _icmp_wldr_header_t;
-#define ICMP_HDRLEN sizeof(_icmp_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.");
#endif /* HICN_PROTOCOL_ICMP_H */
diff --git a/lib/src/protocol/icmprd.h b/lib/src/protocol/icmprd.h
index c2f27d673..aa1fa01ae 100644
--- a/lib/src/protocol/icmprd.h
+++ b/lib/src/protocol/icmprd.h
@@ -21,21 +21,46 @@
#define HICN_PROTOCOL_ICMPRD_H
#include "../common.h"
+#include "ipv4.h"
-typedef struct __attribute__ ((__packed__))
+/*
+ * The length of the ICMPRD4 header struct must be 92 bytes.
+ */
+#define EXPECTED_ICMPRD4_HDRLEN 92
+
+typedef struct
{
+ u8 type;
+ u8 code;
+ u16 csum;
ip4_address_t ip;
_ipv4_header_t iph;
u8 data[64];
} _icmprd4_header_t;
-typedef struct __attribute__ ((__packed__))
+#define ICMPRD4_HDRLEN sizeof(_icmprd4_header_t)
+static_assert (EXPECTED_ICMPRD4_HDRLEN == ICMPRD4_HDRLEN,
+ "Size of ICMPWLDR struct does not match its expected size.");
+
+/*
+ * The length of the ICMPRD header struct must be 40 bytes.
+ */
+#define EXPECTED_ICMPRD_HDRLEN 40
+
+typedef struct
{
+ u8 type;
+ u8 code;
+ u16 csum;
u32 res;
ip6_address_t tgt;
ip6_address_t dst;
} _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.");
+
#endif /* HICN_PROTOCOL_ICMPRD_H */
/*
diff --git a/lib/src/protocol/ipv4.h b/lib/src/protocol/ipv4.h
index c57485b6c..8a5b6683b 100644
--- a/lib/src/protocol/ipv4.h
+++ b/lib/src/protocol/ipv4.h
@@ -22,6 +22,11 @@
/* Headers were adapted from linux' definitions in netinet/ip.h */
+/*
+ * The length of the IPV4 header struct must be 20 bytes.
+ */
+#define EXPECTED_IPV4_HDRLEN 20
+
typedef struct
{
union
@@ -55,6 +60,13 @@ typedef struct
#define ipv4_header_bytes(ipv4_header) (sizeof(u32) * (ipv4_header->version_ihl & 0xf))
#define IPV4_HDRLEN sizeof(_ipv4_header_t)
+static_assert (EXPECTED_IPV4_HDRLEN == IPV4_HDRLEN,
+ "Size of IPV4 struct does not match its expected size.");
+
+/*
+ * The length of the IPV4 pseudo header struct must be 12 bytes.
+ */
+#define EXPECTED_IPV4_PSHDRLEN 12
typedef struct
{
@@ -66,6 +78,8 @@ typedef struct
} 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
diff --git a/lib/src/protocol/ipv6.h b/lib/src/protocol/ipv6.h
index 28a1aa47f..5a83abcae 100644
--- a/lib/src/protocol/ipv6.h
+++ b/lib/src/protocol/ipv6.h
@@ -18,6 +18,11 @@
#include "../common.h"
+/*
+ * The length of the IPV6 header struct must be 40 bytes.
+ */
+#define EXPECTED_IPV6_HDRLEN 40
+
typedef struct
{
union
@@ -35,8 +40,14 @@ typedef struct
ip6_address_t daddr; /* destination address */
} _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.");
+
+/*
+ * The length of the IPV6 pseudo header struct must be 40 bytes.
+ */
+#define EXPECTED_IPV6_PSHDRLEN 40
typedef struct
{
@@ -49,6 +60,8 @@ typedef struct
} 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
diff --git a/lib/src/protocol/tcp.h b/lib/src/protocol/tcp.h
index 68f4bf8f9..3a15a93b3 100644
--- a/lib/src/protocol/tcp.h
+++ b/lib/src/protocol/tcp.h
@@ -21,11 +21,16 @@
#include "../name.h"
/*
+ * The length of the TCP header struct must be 20 bytes.
+ */
+#define EXPECTED_TCP_HDRLEN 20
+
+/*
* NOTE: bitfields are problematic for portability reasons. There are provided
* here for reference and documentation purposes, we might just provide a macro
* to disable and use it instead of __BYTE_ORDER__.
*/
-typedef struct __attribute__ ((packed))
+typedef struct
{
u16 sport;
u16 dport;
@@ -120,6 +125,8 @@ typedef struct __attribute__ ((packed))
} _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.");
#ifndef HICN_VPP_PLUGIN
diff --git a/lib/src/protocol/udp.h b/lib/src/protocol/udp.h
index 58cd65095..75d1ea98c 100644
--- a/lib/src/protocol/udp.h
+++ b/lib/src/protocol/udp.h
@@ -16,6 +16,11 @@
#ifndef HICN_PROTOCOL_UDP_H
#define HICN_PROTOCOL_UDP_H
+/*
+ * The length of the UDP header struct must be 8 bytes.
+ */
+#define EXPECTED_UDP_HDRLEN 8
+
typedef struct
{
u16 src_port;
@@ -25,6 +30,8 @@ typedef struct
} _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.");
#endif /* HICN_PROTOCOL_UDP_H */