From 08233d44a6cfde878d7e10bca38ae935ed1c8fd5 Mon Sep 17 00:00:00 2001 From: Mauro Date: Wed, 30 Jun 2021 07:57:22 +0000 Subject: [HICN-713] Transport Library Major Refactoring 2 Co-authored-by: Luca Muscariello Co-authored-by: Michele Papalini Co-authored-by: Olivier Roques Co-authored-by: Giulio Grassi Signed-off-by: Mauro Sardara Change-Id: I5b2c667bad66feb45abdb5effe22ed0f6c85d1c2 --- lib/src/protocol/ipv6.c | 184 ++++++++++++++++++++++++++---------------------- 1 file changed, 98 insertions(+), 86 deletions(-) (limited to 'lib/src/protocol/ipv6.c') diff --git a/lib/src/protocol/ipv6.c b/lib/src/protocol/ipv6.c index bf8123497..7ac55b2be 100644 --- a/lib/src/protocol/ipv6.c +++ b/lib/src/protocol/ipv6.c @@ -15,17 +15,16 @@ #include #include - #include #include #include -int -ipv6_get_payload_length (hicn_type_t type, const hicn_protocol_t * h, - size_t * payload_length); +typedef unsigned short u_short; +int ipv6_get_payload_length (hicn_type_t type, const hicn_protocol_t *h, + size_t *payload_length); int -ipv6_init_packet_header (hicn_type_t type, hicn_protocol_t * h) +ipv6_init_packet_header (hicn_type_t type, hicn_protocol_t *h) { size_t total_header_length; int rc = CHILD_OPS (get_header_length, type, h, &total_header_length); @@ -33,13 +32,12 @@ ipv6_init_packet_header (hicn_type_t type, hicn_protocol_t * h) return rc; /* *INDENT-OFF* */ - h->ipv6 = (_ipv6_header_t) - { - .saddr = {{ 0 }} - ,.daddr = {{ 0 }} - ,.version_class_flow = htonl ((IPV6_DEFAULT_VERSION << 28) | - (IPV6_DEFAULT_TRAFFIC_CLASS << 20) | - (IPV6_DEFAULT_FLOW_LABEL & 0xfffff)), + h->ipv6 = (_ipv6_header_t){ + .saddr = { { 0 } }, + .daddr = { { 0 } }, + .version_class_flow = htonl ((IPV6_DEFAULT_VERSION << 28) | + (IPV6_DEFAULT_TRAFFIC_CLASS << 20) | + (IPV6_DEFAULT_FLOW_LABEL & 0xfffff)), .len = htons ((u16) total_header_length), .nxt = type.l2, .hlim = HICN_DEFAULT_TTL, @@ -49,24 +47,24 @@ ipv6_init_packet_header (hicn_type_t type, hicn_protocol_t * h) } int -ipv6_get_interest_locator (hicn_type_t type, const hicn_protocol_t * h, - ip46_address_t * ip_address) +ipv6_get_interest_locator (hicn_type_t type, const hicn_protocol_t *h, + ip46_address_t *ip_address) { ip_address->ip6 = h->ipv6.saddr; return HICN_LIB_ERROR_NONE; } int -ipv6_set_interest_locator (hicn_type_t type, hicn_protocol_t * h, - const ip46_address_t * ip_address) +ipv6_set_interest_locator (hicn_type_t type, hicn_protocol_t *h, + const ip46_address_t *ip_address) { h->ipv6.saddr = ip_address->ip6; return HICN_LIB_ERROR_NONE; } int -ipv6_get_interest_name (hicn_type_t type, const hicn_protocol_t * h, - hicn_name_t * name) +ipv6_get_interest_name (hicn_type_t type, const hicn_protocol_t *h, + hicn_name_t *name) { name->ip6.prefix_as_ip6 = h->ipv6.daddr; #ifndef HICN_VPP_PLUGIN @@ -77,41 +75,41 @@ ipv6_get_interest_name (hicn_type_t type, const hicn_protocol_t * h, } int -ipv6_set_interest_name (hicn_type_t type, hicn_protocol_t * h, - const hicn_name_t * name) +ipv6_set_interest_name (hicn_type_t type, hicn_protocol_t *h, + const hicn_name_t *name) { h->ipv6.daddr = name->ip6.prefix_as_ip6; return CHILD_OPS (set_interest_name_suffix, type, h, &(name->ip6.suffix)); } int -ipv6_get_interest_name_suffix (hicn_type_t type, const hicn_protocol_t * h, - hicn_name_suffix_t * suffix) +ipv6_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 -ipv6_set_interest_name_suffix (hicn_type_t type, hicn_protocol_t * h, - const hicn_name_suffix_t * suffix) +ipv6_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 -ipv6_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t * h) +ipv6_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t *h) { return CHILD_OPS (mark_packet_as_interest, type, h); } int -ipv6_mark_packet_as_data (hicn_type_t type, hicn_protocol_t * h) +ipv6_mark_packet_as_data (hicn_type_t type, hicn_protocol_t *h) { return CHILD_OPS (mark_packet_as_data, type, h); } int -ipv6_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t * h) +ipv6_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t *h) { /* Sets everything to 0 up to IP destination address */ memset (&(h->ipv6), 0, 24); @@ -120,24 +118,24 @@ ipv6_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t * h) } int -ipv6_get_data_locator (hicn_type_t type, const hicn_protocol_t * h, - ip46_address_t * ip_address) +ipv6_get_data_locator (hicn_type_t type, const hicn_protocol_t *h, + ip46_address_t *ip_address) { ip_address->ip6 = h->ipv6.daddr; return HICN_LIB_ERROR_NONE; } int -ipv6_set_data_locator (hicn_type_t type, hicn_protocol_t * h, - const ip46_address_t * ip_address) +ipv6_set_data_locator (hicn_type_t type, hicn_protocol_t *h, + const ip46_address_t *ip_address) { h->ipv6.daddr = ip_address->ip6; return HICN_LIB_ERROR_NONE; } int -ipv6_get_data_name (hicn_type_t type, const hicn_protocol_t * h, - hicn_name_t * name) +ipv6_get_data_name (hicn_type_t type, const hicn_protocol_t *h, + hicn_name_t *name) { name->ip6.prefix_as_ip6 = h->ipv6.saddr; #ifndef HICN_VPP_PLUGIN @@ -148,50 +146,50 @@ ipv6_get_data_name (hicn_type_t type, const hicn_protocol_t * h, } int -ipv6_set_data_name (hicn_type_t type, hicn_protocol_t * h, - const hicn_name_t * name) +ipv6_set_data_name (hicn_type_t type, hicn_protocol_t *h, + const hicn_name_t *name) { h->ipv6.saddr = name->ip6.prefix_as_ip6; return CHILD_OPS (set_data_name_suffix, type, h, &(name->ip6.suffix)); } int -ipv6_get_data_name_suffix (hicn_type_t type, const hicn_protocol_t * h, - hicn_name_suffix_t * suffix) +ipv6_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 -ipv6_set_data_name_suffix (hicn_type_t type, hicn_protocol_t * h, - const hicn_name_suffix_t * suffix) +ipv6_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 -ipv6_get_data_pathlabel (hicn_type_t type, const hicn_protocol_t * h, - u32 * pathlabel) +ipv6_get_data_pathlabel (hicn_type_t type, const hicn_protocol_t *h, + u32 *pathlabel) { return CHILD_OPS (get_data_pathlabel, type, h, pathlabel); } int -ipv6_set_data_pathlabel (hicn_type_t type, hicn_protocol_t * h, +ipv6_set_data_pathlabel (hicn_type_t type, hicn_protocol_t *h, const u32 pathlabel) { return CHILD_OPS (set_data_pathlabel, type, h, pathlabel); } int -ipv6_update_data_pathlabel (hicn_type_t type, hicn_protocol_t * h, +ipv6_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 -ipv6_reset_data_for_hash (hicn_type_t type, hicn_protocol_t * h) +ipv6_reset_data_for_hash (hicn_type_t type, hicn_protocol_t *h) { /* IP: Set everithing to 0 up to destination address */ memset (&h->ipv6, 0, 8); @@ -202,22 +200,22 @@ ipv6_reset_data_for_hash (hicn_type_t type, hicn_protocol_t * h) } int -ipv6_get_lifetime (hicn_type_t type, const hicn_protocol_t * h, - hicn_lifetime_t * lifetime) +ipv6_get_lifetime (hicn_type_t type, const hicn_protocol_t *h, + hicn_lifetime_t *lifetime) { return CHILD_OPS (get_lifetime, type, h, lifetime); } int -ipv6_set_lifetime (hicn_type_t type, hicn_protocol_t * h, +ipv6_set_lifetime (hicn_type_t type, hicn_protocol_t *h, const hicn_lifetime_t lifetime) { return CHILD_OPS (set_lifetime, type, h, lifetime); } int -ipv6_update_checksums (hicn_type_t type, hicn_protocol_t * h, - u16 partial_csum, size_t payload_length) +ipv6_update_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum, + size_t payload_length) { /* Retrieve payload length if not specified */ if (payload_length == ~0) @@ -231,7 +229,8 @@ ipv6_update_checksums (hicn_type_t type, hicn_protocol_t * h, ipv6_pseudo_header_t psh; psh.ip_src = h->ipv6.saddr; psh.ip_dst = h->ipv6.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 = htonl (ntohs (h->ipv6.len)); psh.zeros = 0; psh.zero = 0; @@ -248,8 +247,8 @@ ipv6_update_checksums (hicn_type_t type, hicn_protocol_t * h, } int -ipv6_verify_checksums (hicn_type_t type, hicn_protocol_t * h, - u16 partial_csum, size_t payload_length) +ipv6_verify_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum, + size_t payload_length) { /* Retrieve payload length if not specified */ if (payload_length == ~0) @@ -263,7 +262,8 @@ ipv6_verify_checksums (hicn_type_t type, hicn_protocol_t * h, ipv6_pseudo_header_t pseudo; pseudo.ip_src = h->ipv6.saddr; pseudo.ip_dst = h->ipv6.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 + */ pseudo.size = htonl (ntohs (h->ipv6.len)); pseudo.zeros = 0; pseudo.zero = 0; @@ -280,9 +280,9 @@ ipv6_verify_checksums (hicn_type_t type, hicn_protocol_t * h, } int -ipv6_rewrite_interest (hicn_type_t type, hicn_protocol_t * h, - const ip46_address_t * addr_new, - ip46_address_t * addr_old) +ipv6_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->ip6 = h->ipv6.saddr; @@ -292,36 +292,37 @@ ipv6_rewrite_interest (hicn_type_t type, hicn_protocol_t * h, } int -ipv6_rewrite_data (hicn_type_t type, hicn_protocol_t * h, - const ip46_address_t * addr_new, ip46_address_t * addr_old, +ipv6_rewrite_data (hicn_type_t type, hicn_protocol_t *h, + const ip46_address_t *addr_new, ip46_address_t *addr_old, const hicn_faceid_t face_id, u8 reset_pl) { // ASSERT(addr_old == NULL); addr_old->ip6 = h->ipv6.daddr; h->ipv6.daddr = addr_new->ip6; - return CHILD_OPS (rewrite_data, type, h, addr_new, addr_old, face_id, reset_pl); + return CHILD_OPS (rewrite_data, type, h, addr_new, addr_old, face_id, + reset_pl); } int -ipv6_get_length (hicn_type_t type, const hicn_protocol_t * h, - size_t * header_length) +ipv6_get_length (hicn_type_t type, const hicn_protocol_t *h, + size_t *header_length) { *header_length = IPV6_HDRLEN + ntohs (h->ipv6.len); return HICN_LIB_ERROR_NONE; } int -ipv6_get_current_header_length (hicn_type_t type, const hicn_protocol_t * h, - size_t * header_length) +ipv6_get_current_header_length (hicn_type_t type, const hicn_protocol_t *h, + size_t *header_length) { *header_length = IPV6_HDRLEN; return HICN_LIB_ERROR_NONE; } int -ipv6_get_header_length (hicn_type_t type, const hicn_protocol_t * h, - size_t * header_length) +ipv6_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); @@ -332,8 +333,8 @@ ipv6_get_header_length (hicn_type_t type, const hicn_protocol_t * h, } int -ipv6_get_payload_length (hicn_type_t type, const hicn_protocol_t * h, - size_t * payload_length) +ipv6_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); @@ -344,76 +345,87 @@ ipv6_get_payload_length (hicn_type_t type, const hicn_protocol_t * h, } int -ipv6_set_payload_length (hicn_type_t type, hicn_protocol_t * h, +ipv6_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->ipv6.len = htons ( (u_short) (payload_length + child_header_length)); + h->ipv6.len = htons ((u_short) (payload_length + child_header_length)); return HICN_LIB_ERROR_NONE; } int -ipv6_get_signature_size (hicn_type_t type, const hicn_protocol_t * h, - size_t * signature_size) +ipv6_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 -ipv6_set_signature_size (hicn_type_t type, hicn_protocol_t * h, +ipv6_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 -ipv6_set_signature_timestamp(hicn_type_t type, hicn_protocol_t * h, - uint64_t signature_timestamp) +ipv6_set_signature_gap (hicn_type_t type, hicn_protocol_t *h, uint8_t gap) +{ + return CHILD_OPS (set_signature_gap, type, h, gap); +} + +int +ipv6_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 +ipv6_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 -ipv6_get_signature_timestamp (hicn_type_t type, const hicn_protocol_t * h, - uint64_t * signature_timestamp) +ipv6_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 -ipv6_set_validation_algorithm (hicn_type_t type, hicn_protocol_t * h, - uint8_t validation_algorithm) +ipv6_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 -ipv6_get_validation_algorithm (hicn_type_t type, const hicn_protocol_t * h, - uint8_t * validation_algorithm) +ipv6_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 -ipv6_set_key_id (hicn_type_t type, hicn_protocol_t * h, - uint8_t *key_id) +ipv6_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 -ipv6_get_key_id (hicn_type_t type, hicn_protocol_t * h, - uint8_t **key_id, uint8_t *key_id_size) +ipv6_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 -ipv6_get_signature (hicn_type_t type, hicn_protocol_t * h, - uint8_t ** signature) +ipv6_get_signature (hicn_type_t type, hicn_protocol_t *h, uint8_t **signature) { return CHILD_OPS (get_signature, type, h, signature); } -- cgit 1.2.3-korg