summaryrefslogtreecommitdiffstats
path: root/lib/src/protocol/ipv4.c
diff options
context:
space:
mode:
authorMauro <you@example.com>2021-06-30 07:57:22 +0000
committerMauro Sardara <msardara@cisco.com>2021-07-06 16:16:04 +0000
commit08233d44a6cfde878d7e10bca38ae935ed1c8fd5 (patch)
tree7ecc534d55bdc7e8dd15ecab084720910bcdf4d9 /lib/src/protocol/ipv4.c
parent147ba39bed26887f5eba84757e2463ab8e370a9a (diff)
[HICN-713] Transport Library Major Refactoring 2
Co-authored-by: Luca Muscariello <muscariello@ieee.org> Co-authored-by: Michele Papalini <micpapal@cisco.com> Co-authored-by: Olivier Roques <oroques+fdio@cisco.com> Co-authored-by: Giulio Grassi <gigrassi@cisco.com> Signed-off-by: Mauro Sardara <msardara@cisco.com> Change-Id: I5b2c667bad66feb45abdb5effe22ed0f6c85d1c2
Diffstat (limited to 'lib/src/protocol/ipv4.c')
-rw-r--r--lib/src/protocol/ipv4.c195
1 files changed, 107 insertions, 88 deletions
diff --git a/lib/src/protocol/ipv4.c b/lib/src/protocol/ipv4.c
index 73ce12ee0..cf50f9996 100644
--- a/lib/src/protocol/ipv4.c
+++ b/lib/src/protocol/ipv4.c
@@ -33,12 +33,12 @@
#include <hicn/header.h>
#include <hicn/protocol/ipv4.h>
-
-int ipv4_get_payload_length (hicn_type_t type, const hicn_protocol_t * h,
- size_t * payload_length);
+typedef unsigned short u_short;
+int ipv4_get_payload_length (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *payload_length);
int
-ipv4_init_packet_header (hicn_type_t type, hicn_protocol_t * h)
+ipv4_init_packet_header (hicn_type_t type, hicn_protocol_t *h)
{
size_t total_header_length;
int rc =
@@ -46,37 +46,41 @@ ipv4_init_packet_header (hicn_type_t type, hicn_protocol_t * h)
if (rc < 0)
return rc;
- h->ipv4 = (_ipv4_header_t)
- {
- .version_ihl =
- (IPV4_DEFAULT_VERSION << 4) | (0x0f & IPV4_DEFAULT_IHL),.tos =
- IPV4_DEFAULT_TOS,.len = htons ((u16) total_header_length),.id =
- htons (IPV4_DEFAULT_ID),.frag_off =
- htons (IPV4_DEFAULT_FRAG_OFF),.ttl = HICN_DEFAULT_TTL,.protocol =
- type.l2,.csum = 0,.saddr.as_u32 = 0,.daddr.as_u32 = 0,};
+ h->ipv4 = (_ipv4_header_t){
+ .version_ihl = (IPV4_DEFAULT_VERSION << 4) | (0x0f & IPV4_DEFAULT_IHL),
+ .tos = IPV4_DEFAULT_TOS,
+ .len = htons ((u16) total_header_length),
+ .id = htons (IPV4_DEFAULT_ID),
+ .frag_off = htons (IPV4_DEFAULT_FRAG_OFF),
+ .ttl = HICN_DEFAULT_TTL,
+ .protocol = type.l2,
+ .csum = 0,
+ .saddr.as_u32 = 0,
+ .daddr.as_u32 = 0,
+ };
return CHILD_OPS (init_packet_header, type, h);
}
int
-ipv4_get_interest_locator (hicn_type_t type, const hicn_protocol_t * h,
- ip46_address_t * ip_address)
+ipv4_get_interest_locator (hicn_type_t type, const hicn_protocol_t *h,
+ ip46_address_t *ip_address)
{
ip_address->ip4 = h->ipv4.saddr;
return HICN_LIB_ERROR_NONE;
}
int
-ipv4_set_interest_locator (hicn_type_t type, hicn_protocol_t * h,
- const ip46_address_t * ip_address)
+ipv4_set_interest_locator (hicn_type_t type, hicn_protocol_t *h,
+ const ip46_address_t *ip_address)
{
h->ipv4.saddr = ip_address->ip4;
return HICN_LIB_ERROR_NONE;
}
int
-ipv4_get_interest_name (hicn_type_t type, const hicn_protocol_t * h,
- hicn_name_t * name)
+ipv4_get_interest_name (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_name_t *name)
{
name->ip4.prefix_as_ip4 = h->ipv4.daddr;
#ifndef HICN_VPP_PLUGIN
@@ -87,41 +91,41 @@ ipv4_get_interest_name (hicn_type_t type, const hicn_protocol_t * h,
}
int
-ipv4_set_interest_name (hicn_type_t type, hicn_protocol_t * h,
- const hicn_name_t * name)
+ipv4_set_interest_name (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_name_t *name)
{
h->ipv4.daddr = name->ip4.prefix_as_ip4;
return CHILD_OPS (set_interest_name_suffix, type, h, &(name->ip4.suffix));
}
int
-ipv4_get_interest_name_suffix (hicn_type_t type, const hicn_protocol_t * h,
- hicn_name_suffix_t * suffix)
+ipv4_get_interest_name_suffix (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_name_suffix_t *suffix)
{
return CHILD_OPS (get_interest_name_suffix, type, h, suffix);
}
int
-ipv4_set_interest_name_suffix (hicn_type_t type, hicn_protocol_t * h,
- const hicn_name_suffix_t * suffix)
+ipv4_set_interest_name_suffix (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_name_suffix_t *suffix)
{
return CHILD_OPS (set_interest_name_suffix, type, h, suffix);
}
int
-ipv4_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t * h)
+ipv4_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t *h)
{
return CHILD_OPS (mark_packet_as_interest, type, h);
}
int
-ipv4_mark_packet_as_data (hicn_type_t type, hicn_protocol_t * h)
+ipv4_mark_packet_as_data (hicn_type_t type, hicn_protocol_t *h)
{
return CHILD_OPS (mark_packet_as_data, type, h);
}
int
-ipv4_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t * h)
+ipv4_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t *h)
{
/* Sets everything to 0 up to IP destination address */
memset (&(h->ipv4), 0, 16);
@@ -130,24 +134,24 @@ ipv4_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t * h)
}
int
-ipv4_get_data_locator (hicn_type_t type, const hicn_protocol_t * h,
- ip46_address_t * ip_address)
+ipv4_get_data_locator (hicn_type_t type, const hicn_protocol_t *h,
+ ip46_address_t *ip_address)
{
ip_address->ip4 = h->ipv4.daddr;
return HICN_LIB_ERROR_NONE;
}
int
-ipv4_set_data_locator (hicn_type_t type, hicn_protocol_t * h,
- const ip46_address_t * ip_address)
+ipv4_set_data_locator (hicn_type_t type, hicn_protocol_t *h,
+ const ip46_address_t *ip_address)
{
h->ipv4.daddr = ip_address->ip4;
return HICN_LIB_ERROR_NONE;
}
int
-ipv4_get_data_name (hicn_type_t type, const hicn_protocol_t * h,
- hicn_name_t * name)
+ipv4_get_data_name (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_name_t *name)
{
name->ip4.prefix_as_ip4 = h->ipv4.saddr;
#ifndef HICN_VPP_PLUGIN
@@ -158,50 +162,50 @@ ipv4_get_data_name (hicn_type_t type, const hicn_protocol_t * h,
}
int
-ipv4_set_data_name (hicn_type_t type, hicn_protocol_t * h,
- const hicn_name_t * name)
+ipv4_set_data_name (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_name_t *name)
{
h->ipv4.saddr = name->ip4.prefix_as_ip4;
return CHILD_OPS (set_data_name_suffix, type, h, &(name->ip4.suffix));
}
int
-ipv4_get_data_name_suffix (hicn_type_t type, const hicn_protocol_t * h,
- hicn_name_suffix_t * suffix)
+ipv4_get_data_name_suffix (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_name_suffix_t *suffix)
{
return CHILD_OPS (get_data_name_suffix, type, h, suffix);
}
int
-ipv4_set_data_name_suffix (hicn_type_t type, hicn_protocol_t * h,
- const hicn_name_suffix_t * suffix)
+ipv4_set_data_name_suffix (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_name_suffix_t *suffix)
{
return CHILD_OPS (set_data_name_suffix, type, h, suffix);
}
int
-ipv4_get_data_pathlabel (hicn_type_t type, const hicn_protocol_t * h,
- u32 * pathlabel)
+ipv4_get_data_pathlabel (hicn_type_t type, const hicn_protocol_t *h,
+ u32 *pathlabel)
{
return CHILD_OPS (get_data_pathlabel, type, h, pathlabel);
}
int
-ipv4_set_data_pathlabel (hicn_type_t type, hicn_protocol_t * h,
+ipv4_set_data_pathlabel (hicn_type_t type, hicn_protocol_t *h,
const u32 pathlabel)
{
return CHILD_OPS (set_data_pathlabel, type, h, pathlabel);
}
int
-ipv4_update_data_pathlabel (hicn_type_t type, hicn_protocol_t * h,
+ipv4_update_data_pathlabel (hicn_type_t type, hicn_protocol_t *h,
const hicn_faceid_t face_id)
{
return CHILD_OPS (update_data_pathlabel, type, h, face_id);
}
int
-ipv4_reset_data_for_hash (hicn_type_t type, hicn_protocol_t * h)
+ipv4_reset_data_for_hash (hicn_type_t type, hicn_protocol_t *h)
{
/* Sets everything to 0 up to source address */
memset (&h->ipv4, 0, 12);
@@ -212,22 +216,22 @@ ipv4_reset_data_for_hash (hicn_type_t type, hicn_protocol_t * h)
}
int
-ipv4_get_lifetime (hicn_type_t type, const hicn_protocol_t * h,
- hicn_lifetime_t * lifetime)
+ipv4_get_lifetime (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_lifetime_t *lifetime)
{
return CHILD_OPS (get_lifetime, type, h, lifetime);
}
int
-ipv4_set_lifetime (hicn_type_t type, hicn_protocol_t * h,
+ipv4_set_lifetime (hicn_type_t type, hicn_protocol_t *h,
const hicn_lifetime_t lifetime)
{
return CHILD_OPS (set_lifetime, type, h, lifetime);
}
int
-ipv4_update_checksums (hicn_type_t type, hicn_protocol_t * h,
- u16 partial_csum, size_t payload_length)
+ipv4_update_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
+ size_t payload_length)
{
/*
* Checksum field is not accounted for in lower layers, so we can compute
@@ -254,7 +258,8 @@ ipv4_update_checksums (hicn_type_t type, hicn_protocol_t * h,
ipv4_pseudo_header_t psh;
psh.ip_src = h->ipv4.saddr;
psh.ip_dst = h->ipv4.daddr;
- /* Size is u32 and not u16, we cannot copy and need to care about endianness */
+ /* Size is u32 and not u16, we cannot copy and need to care about endianness
+ */
psh.size = htons (ntohs (h->ipv4.len) - (u16) IPV4_HDRLEN);
psh.zero = 0;
psh.protocol = (u8) h->ipv4.protocol;
@@ -270,8 +275,8 @@ ipv4_update_checksums (hicn_type_t type, hicn_protocol_t * h,
}
int
-ipv4_verify_checksums (hicn_type_t type, hicn_protocol_t * h,
- u16 partial_csum, size_t payload_length)
+ipv4_verify_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
+ size_t payload_length)
{
/*
* Checksum field is not accounted for in lower layers, so we can compute
@@ -292,7 +297,8 @@ ipv4_verify_checksums (hicn_type_t type, hicn_protocol_t * h,
ipv4_pseudo_header_t psh;
psh.ip_src = h->ipv4.saddr;
psh.ip_dst = h->ipv4.daddr;
- /* Size is u32 and not u16, we cannot copy and need to care about endianness */
+ /* Size is u32 and not u16, we cannot copy and need to care about endianness
+ */
psh.size = htons (ntohs (h->ipv4.len) - (u16) IPV4_HDRLEN);
psh.zero = 0;
psh.protocol = (u8) h->ipv4.protocol;
@@ -304,9 +310,9 @@ ipv4_verify_checksums (hicn_type_t type, hicn_protocol_t * h,
}
int
-ipv4_rewrite_interest (hicn_type_t type, hicn_protocol_t * h,
- const ip46_address_t * addr_new,
- ip46_address_t * addr_old)
+ipv4_rewrite_interest (hicn_type_t type, hicn_protocol_t *h,
+ const ip46_address_t *addr_new,
+ ip46_address_t *addr_old)
{
// ASSERT(addr_old == NULL);
addr_old->ip4 = h->ipv4.saddr;
@@ -322,8 +328,8 @@ ipv4_rewrite_interest (hicn_type_t type, hicn_protocol_t * h,
}
int
-ipv4_rewrite_data (hicn_type_t type, hicn_protocol_t * h,
- const ip46_address_t * addr_new, ip46_address_t * addr_old,
+ipv4_rewrite_data (hicn_type_t type, hicn_protocol_t *h,
+ const ip46_address_t *addr_new, ip46_address_t *addr_old,
const hicn_faceid_t face_id, u8 reset_pl)
{
// ASSERT(addr_old == NULL);
@@ -336,36 +342,37 @@ ipv4_rewrite_data (hicn_type_t type, hicn_protocol_t * h,
h->ipv4.csum = 0;
h->ipv4.csum = csum (&h->ipv4, IPV4_HDRLEN, 0);
- return CHILD_OPS (rewrite_data, type, h, addr_new, addr_old, face_id, reset_pl);
+ return CHILD_OPS (rewrite_data, type, h, addr_new, addr_old, face_id,
+ reset_pl);
}
int
-ipv4_get_current_length (hicn_type_t type, const hicn_protocol_t * h,
- size_t * header_length)
+ipv4_get_current_length (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *header_length)
{
*header_length = IPV4_HDRLEN;
return HICN_LIB_ERROR_NONE;
}
int
-ipv4_get_length (hicn_type_t type, const hicn_protocol_t * h,
- size_t * header_length)
+ipv4_get_length (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *header_length)
{
*header_length = h->ipv4.len;
return HICN_LIB_ERROR_NONE;
}
int
-ipv4_get_current_header_length (hicn_type_t type, const hicn_protocol_t * h,
- size_t * header_length)
+ipv4_get_current_header_length (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *header_length)
{
*header_length = IPV4_HDRLEN;
return HICN_LIB_ERROR_NONE;
}
int
-ipv4_get_header_length (hicn_type_t type, const hicn_protocol_t * h,
- size_t * header_length)
+ipv4_get_header_length (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *header_length)
{
size_t child_header_length = 0;
int rc = CHILD_OPS (get_header_length, type, h, &child_header_length);
@@ -376,8 +383,8 @@ ipv4_get_header_length (hicn_type_t type, const hicn_protocol_t * h,
}
int
-ipv4_get_payload_length (hicn_type_t type, const hicn_protocol_t * h,
- size_t * payload_length)
+ipv4_get_payload_length (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *payload_length)
{
size_t child_header_length;
int rc = CHILD_OPS (get_header_length, type, h, &child_header_length);
@@ -388,76 +395,88 @@ ipv4_get_payload_length (hicn_type_t type, const hicn_protocol_t * h,
}
int
-ipv4_set_payload_length (hicn_type_t type, hicn_protocol_t * h,
+ipv4_set_payload_length (hicn_type_t type, hicn_protocol_t *h,
size_t payload_length)
{
size_t child_header_length;
int rc = CHILD_OPS (get_header_length, type, h, &child_header_length);
if (rc < 0)
return rc;
- h->ipv4.len = htons ((u_short) (payload_length + IPV4_HDRLEN + child_header_length));
+ h->ipv4.len =
+ htons ((u_short) (payload_length + IPV4_HDRLEN + child_header_length));
return HICN_LIB_ERROR_NONE;
}
int
-ipv4_get_signature_size (hicn_type_t type, const hicn_protocol_t * h,
- size_t * signature_size)
+ipv4_get_signature_size (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *signature_size)
{
return CHILD_OPS (get_signature_size, type, h, signature_size);
}
int
-ipv4_set_signature_size (hicn_type_t type, hicn_protocol_t * h,
+ipv4_set_signature_size (hicn_type_t type, hicn_protocol_t *h,
size_t signature_size)
{
return CHILD_OPS (set_signature_size, type, h, signature_size);
}
int
-ipv4_set_signature_timestamp(hicn_type_t type, hicn_protocol_t * h,
- uint64_t signature_timestamp)
+ipv4_set_signature_gap (hicn_type_t type, hicn_protocol_t *h, uint8_t gap)
+{
+ return CHILD_OPS (set_signature_gap, type, h, gap);
+}
+
+int
+ipv4_get_signature_gap (hicn_type_t type, const hicn_protocol_t *h,
+ uint8_t *gap)
+{
+ return CHILD_OPS (get_signature_gap, type, h, gap);
+}
+
+int
+ipv4_set_signature_timestamp (hicn_type_t type, hicn_protocol_t *h,
+ uint64_t signature_timestamp)
{
return CHILD_OPS (set_signature_timestamp, type, h, signature_timestamp);
}
int
-ipv4_get_signature_timestamp (hicn_type_t type, const hicn_protocol_t * h,
- uint64_t * signature_timestamp)
+ipv4_get_signature_timestamp (hicn_type_t type, const hicn_protocol_t *h,
+ uint64_t *signature_timestamp)
{
return CHILD_OPS (get_signature_timestamp, type, h, signature_timestamp);
}
int
-ipv4_set_validation_algorithm (hicn_type_t type, hicn_protocol_t * h,
- uint8_t validation_algorithm)
+ipv4_set_validation_algorithm (hicn_type_t type, hicn_protocol_t *h,
+ uint8_t validation_algorithm)
{
return CHILD_OPS (set_validation_algorithm, type, h, validation_algorithm);
}
int
-ipv4_get_validation_algorithm (hicn_type_t type, const hicn_protocol_t * h,
- uint8_t * validation_algorithm)
+ipv4_get_validation_algorithm (hicn_type_t type, const hicn_protocol_t *h,
+ uint8_t *validation_algorithm)
{
return CHILD_OPS (get_validation_algorithm, type, h, validation_algorithm);
}
int
-ipv4_set_key_id (hicn_type_t type, hicn_protocol_t * h,
- uint8_t *key_id)
+ipv4_set_key_id (hicn_type_t type, hicn_protocol_t *h, uint8_t *key_id)
{
return CHILD_OPS (set_key_id, type, h, key_id);
}
int
-ipv4_get_key_id (hicn_type_t type, hicn_protocol_t * h,
- uint8_t **key_id, uint8_t *key_id_size)
+ipv4_get_key_id (hicn_type_t type, hicn_protocol_t *h, uint8_t **key_id,
+ uint8_t *key_id_size)
{
return CHILD_OPS (get_key_id, type, h, key_id, key_id_size);
}
int
-ipv4_get_signature (hicn_type_t type, hicn_protocol_t * h,
- uint8_t ** signature)
+ipv4_get_signature (hicn_type_t type, hicn_protocol_t *h, uint8_t **signature)
{
return CHILD_OPS (get_signature, type, h, signature);
}