summaryrefslogtreecommitdiffstats
path: root/lib/src/protocol
diff options
context:
space:
mode:
authorLuca Muscariello <lumuscar@cisco.com>2022-03-30 22:29:28 +0200
committerMauro Sardara <msardara@cisco.com>2022-03-31 19:51:47 +0200
commitc46e5df56b67bb8ea7a068d39324c640084ead2b (patch)
treeeddeb17785938e09bc42eec98ee09b8a28846de6 /lib/src/protocol
parent18fa668f25d3cc5463417ce7df6637e31578e898 (diff)
feat: boostrap hicn 22.02
The current patch provides several new features, improvements, bug fixes and also complete rewrite of entire components. - lib The hicn packet parser has been improved with a new packet format fully based on UDP. The TCP header is still temporarily supported but the UDP header will replace completely the new hicn packet format. Improvements have been made to make sure every packet parsing operation is made via this library. The current new header can be used as header between the payload and the UDP header or as trailer in the UDP surplus area to be tested when UDP options will start to be used. - hicn-light The portable packet forwarder has been completely rewritten from scratch with the twofold objective to improve performance and code size but also to drop dependencies such as libparc which is now removed by the current implementation. - hicn control the control library is the agent that is used to program the packet forwarders via their binary API. This component has benefited from significant improvements in terms of interaction model which is now event driven and more robust to failures. - VPP plugin has been updated to support VPP 22.02 - transport Major improvement have been made to the RTC protocol, to the support of IO modules and to the security sub system. Signed manifests are the default data authenticity and integrity framework. Confidentiality can be enabled by sharing the encryption key to the prod/cons layer. The library has been tested with group key based applications such as broadcast/multicast and real-time on-line meetings with trusted server keys or MLS. - testing Unit testing has been introduced using GoogleTest. One third of the code base is covered by unit testing with priority on critical features. Functional testing has also been introduce using Docker, linux bridging and Robot Framework to define test with Less Code techniques to facilitate the extension of the coverage. Co-authored-by: Mauro Sardara <msardara@cisco.com> Co-authored-by: Jordan Augé <jordan.auge+fdio@cisco.com> Co-authored-by: Michele Papalini <micpapal@cisco.com> Co-authored-by: Angelo Mantellini <manangel@cisco.com> Co-authored-by: Jacques Samain <jsamain@cisco.com> Co-authored-by: Olivier Roques <oroques+fdio@cisco.com> Co-authored-by: Enrico Loparco <eloparco@cisco.com> Co-authored-by: Giulio Grassi <gigrassi@cisco.com> Change-Id: I75d0ef70f86d921e3ef503c99271216ff583c215 Signed-off-by: Luca Muscariello <muscariello@ieee.org> Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'lib/src/protocol')
-rw-r--r--lib/src/protocol/ah.c24
-rw-r--r--lib/src/protocol/icmp.c23
-rw-r--r--lib/src/protocol/ipv4.c98
-rw-r--r--lib/src/protocol/ipv6.c102
-rw-r--r--lib/src/protocol/new.c441
-rw-r--r--lib/src/protocol/tcp.c114
-rw-r--r--lib/src/protocol/udp.c312
7 files changed, 995 insertions, 119 deletions
diff --git a/lib/src/protocol/ah.c b/lib/src/protocol/ah.c
index 13340eae1..b3d24161d 100644
--- a/lib/src/protocol/ah.c
+++ b/lib/src/protocol/ah.c
@@ -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,6 +31,7 @@ DECLARE_get_interest_name (ah, UNEXPECTED);
DECLARE_set_interest_name (ah, UNEXPECTED);
DECLARE_get_interest_name_suffix (ah, UNEXPECTED);
DECLARE_set_interest_name_suffix (ah, UNEXPECTED);
+DECLARE_is_interest (ah, UNEXPECTED);
DECLARE_mark_packet_as_interest (ah, UNEXPECTED);
DECLARE_mark_packet_as_data (ah, UNEXPECTED);
DECLARE_get_data_locator (ah, UNEXPECTED);
@@ -46,6 +47,10 @@ DECLARE_get_lifetime (ah, UNEXPECTED);
DECLARE_set_lifetime (ah, UNEXPECTED);
DECLARE_get_payload_length (ah, UNEXPECTED);
DECLARE_set_payload_length (ah, UNEXPECTED);
+DECLARE_get_payload_type (ah, UNEXPECTED);
+DECLARE_set_payload_type (ah, UNEXPECTED);
+DECLARE_is_last_data (ah, UNEXPECTED);
+DECLARE_set_last_data (ah, UNEXPECTED);
int
ah_init_packet_header (hicn_type_t type, hicn_protocol_t *h)
@@ -69,6 +74,7 @@ ah_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t *h)
if (rc < 0)
return rc;
memset (&(h->ah.validationPayload), 0, signature_size);
+ h->ah.signaturePadding = 0;
return CHILD_OPS (reset_interest_for_hash, type, h);
}
@@ -81,6 +87,7 @@ ah_reset_data_for_hash (hicn_type_t type, hicn_protocol_t *h)
if (rc < 0)
return rc;
memset (&(h->ah.validationPayload), 0, signature_size);
+ h->ah.signaturePadding = 0;
return CHILD_OPS (reset_interest_for_hash, type, h);
}
@@ -102,7 +109,7 @@ ah_verify_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
int
ah_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)
{
/* Nothing to do on signature */
return HICN_LIB_ERROR_NONE;
@@ -110,7 +117,7 @@ ah_rewrite_interest (hicn_type_t type, hicn_protocol_t *h,
int
ah_rewrite_data (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,
const hicn_faceid_t face_id, u8 reset_pl)
{
/* Nothing to do on signature */
@@ -162,7 +169,7 @@ int
ah_set_signature_size (hicn_type_t type, hicn_protocol_t *h,
const size_t signature_size)
{
- h->ah.payloadlen = (u8) (signature_size >> 2);
+ h->ah.payloadlen = signature_size >> 2;
return HICN_LIB_ERROR_NONE;
}
@@ -201,16 +208,17 @@ ah_get_validation_algorithm (hicn_type_t type, const hicn_protocol_t *h,
}
int
-ah_set_signature_gap (hicn_type_t type, hicn_protocol_t *h, uint8_t gap)
+ah_set_signature_padding (hicn_type_t type, hicn_protocol_t *h, size_t padding)
{
- h->ah.signatureGap = gap;
+ h->ah.signaturePadding = padding;
return HICN_LIB_ERROR_NONE;
}
int
-ah_get_signature_gap (hicn_type_t type, const hicn_protocol_t *h, uint8_t *gap)
+ah_get_signature_padding (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *padding)
{
- *gap = h->ah.signatureGap;
+ *padding = h->ah.signaturePadding;
return HICN_LIB_ERROR_NONE;
}
diff --git a/lib/src/protocol/icmp.c b/lib/src/protocol/icmp.c
index 5783cf52c..0452e4fbb 100644
--- a/lib/src/protocol/icmp.c
+++ b/lib/src/protocol/icmp.c
@@ -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,6 +24,7 @@ DECLARE_get_interest_name (icmp, UNEXPECTED);
DECLARE_set_interest_name (icmp, UNEXPECTED);
DECLARE_get_interest_name_suffix (icmp, UNEXPECTED);
DECLARE_set_interest_name_suffix (icmp, UNEXPECTED);
+DECLARE_is_interest (icmp, UNEXPECTED);
DECLARE_mark_packet_as_interest (icmp, UNEXPECTED);
DECLARE_mark_packet_as_data (icmp, UNEXPECTED);
DECLARE_get_data_locator (icmp, UNEXPECTED);
@@ -40,7 +41,11 @@ DECLARE_set_lifetime (icmp, UNEXPECTED);
DECLARE_get_length (icmp, UNEXPECTED);
DECLARE_get_payload_length (icmp, UNEXPECTED);
DECLARE_set_payload_length (icmp, UNEXPECTED);
+DECLARE_get_payload_type (icmp, UNEXPECTED);
+DECLARE_set_payload_type (icmp, UNEXPECTED);
DECLARE_get_signature (icmp, UNEXPECTED);
+DECLARE_is_last_data (icmp, UNEXPECTED);
+DECLARE_set_last_data (icmp, UNEXPECTED);
int
icmp_init_packet_header (hicn_type_t type, hicn_protocol_t *h)
@@ -94,8 +99,7 @@ icmp_verify_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
int
icmp_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_NOT_IMPLEMENTED;
// u16 *icmp_checksum = &(h->icmp.csum);
@@ -120,7 +124,7 @@ icmp_rewrite_interest (hicn_type_t type, hicn_protocol_t *h,
int
icmp_rewrite_data (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,
const hicn_faceid_t face_id, u8 reset_pl)
{
return HICN_LIB_ERROR_NOT_IMPLEMENTED;
@@ -184,16 +188,17 @@ icmp_set_signature_size (hicn_type_t type, hicn_protocol_t *h,
}
int
-icmp_set_signature_gap (hicn_type_t type, hicn_protocol_t *h, uint8_t gap)
+icmp_set_signature_padding (hicn_type_t type, hicn_protocol_t *h,
+ size_t padding)
{
- return CHILD_OPS (set_signature_gap, type, h, gap);
+ return CHILD_OPS (set_signature_padding, type, h, padding);
}
int
-icmp_get_signature_gap (hicn_type_t type, const hicn_protocol_t *h,
- uint8_t *gap)
+icmp_get_signature_padding (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *padding)
{
- return CHILD_OPS (get_signature_gap, type, h, gap);
+ return CHILD_OPS (get_signature_padding, type, h, padding);
}
int
diff --git a/lib/src/protocol/ipv4.c b/lib/src/protocol/ipv4.c
index cf50f9996..5d445f018 100644
--- a/lib/src/protocol/ipv4.c
+++ b/lib/src/protocol/ipv4.c
@@ -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:
@@ -64,17 +64,17 @@ ipv4_init_packet_header (hicn_type_t type, hicn_protocol_t *h)
int
ipv4_get_interest_locator (hicn_type_t type, const hicn_protocol_t *h,
- ip46_address_t *ip_address)
+ ip_address_t *ip_address)
{
- ip_address->ip4 = h->ipv4.saddr;
+ ip_address->v4 = 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)
+ const ip_address_t *ip_address)
{
- h->ipv4.saddr = ip_address->ip4;
+ h->ipv4.saddr = ip_address->v4;
return HICN_LIB_ERROR_NONE;
}
@@ -82,20 +82,16 @@ int
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
- name->type = HNT_CONTIGUOUS_V4;
- name->len = HICN_V4_NAME_LEN;
-#endif /* HICN_VPP_PLUGIN */
- return CHILD_OPS (get_interest_name_suffix, type, h, &(name->ip4.suffix));
+ name->prefix.v4 = h->ipv4.daddr;
+ return CHILD_OPS (get_interest_name_suffix, type, h, &(name->suffix));
}
int
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));
+ h->ipv4.daddr = name->prefix.v4;
+ return CHILD_OPS (set_interest_name_suffix, type, h, &(name->suffix));
}
int
@@ -113,6 +109,12 @@ ipv4_set_interest_name_suffix (hicn_type_t type, hicn_protocol_t *h,
}
int
+ipv4_is_interest (hicn_type_t type, const hicn_protocol_t *h, int *is_interest)
+{
+ return CHILD_OPS (is_interest, type, h, is_interest);
+}
+
+int
ipv4_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t *h)
{
return CHILD_OPS (mark_packet_as_interest, type, h);
@@ -135,17 +137,17 @@ 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)
+ ip_address_t *ip_address)
{
- ip_address->ip4 = h->ipv4.daddr;
+ ip_address->v4 = 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)
+ const ip_address_t *ip_address)
{
- h->ipv4.daddr = ip_address->ip4;
+ h->ipv4.daddr = ip_address->v4;
return HICN_LIB_ERROR_NONE;
}
@@ -153,20 +155,16 @@ int
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
- name->type = HNT_CONTIGUOUS_V4;
- name->len = HICN_V4_NAME_LEN;
-#endif /* HICN_VPP_PLUGIN */
- return CHILD_OPS (get_data_name_suffix, type, h, &(name->ip4.suffix));
+ name->prefix.v4 = h->ipv4.saddr;
+ return CHILD_OPS (get_data_name_suffix, type, h, &(name->suffix));
}
int
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));
+ h->ipv4.saddr = name->prefix.v4;
+ return CHILD_OPS (set_data_name_suffix, type, h, &(name->suffix));
}
int
@@ -311,16 +309,15 @@ ipv4_verify_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
int
ipv4_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)
{
// ASSERT(addr_old == NULL);
- addr_old->ip4 = h->ipv4.saddr;
+ addr_old->v4 = h->ipv4.saddr;
addr_old->pad[0] = 0;
addr_old->pad[1] = 0;
addr_old->pad[2] = 0;
- h->ipv4.saddr = addr_new->ip4;
+ h->ipv4.saddr = addr_new->v4;
h->ipv4.csum = 0;
h->ipv4.csum = csum (&h->ipv4, IPV4_HDRLEN, 0);
@@ -329,16 +326,16 @@ 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,
+ const ip_address_t *addr_new, ip_address_t *addr_old,
const hicn_faceid_t face_id, u8 reset_pl)
{
// ASSERT(addr_old == NULL);
- addr_old->ip4 = h->ipv4.daddr;
+ addr_old->v4 = h->ipv4.daddr;
addr_old->pad[0] = 0;
addr_old->pad[1] = 0;
addr_old->pad[2] = 0;
- h->ipv4.daddr = addr_new->ip4;
+ h->ipv4.daddr = addr_new->v4;
h->ipv4.csum = 0;
h->ipv4.csum = csum (&h->ipv4, IPV4_HDRLEN, 0);
@@ -408,6 +405,20 @@ ipv4_set_payload_length (hicn_type_t type, hicn_protocol_t *h,
}
int
+ipv4_get_payload_type (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_payload_type_t *payload_type)
+{
+ return CHILD_OPS (get_payload_type, type, h, payload_type);
+}
+
+int
+ipv4_set_payload_type (hicn_type_t type, hicn_protocol_t *h,
+ hicn_payload_type_t payload_type)
+{
+ return CHILD_OPS (set_payload_type, type, h, payload_type);
+}
+
+int
ipv4_get_signature_size (hicn_type_t type, const hicn_protocol_t *h,
size_t *signature_size)
{
@@ -422,16 +433,17 @@ ipv4_set_signature_size (hicn_type_t type, hicn_protocol_t *h,
}
int
-ipv4_set_signature_gap (hicn_type_t type, hicn_protocol_t *h, uint8_t gap)
+ipv4_set_signature_padding (hicn_type_t type, hicn_protocol_t *h,
+ size_t padding)
{
- return CHILD_OPS (set_signature_gap, type, h, gap);
+ return CHILD_OPS (set_signature_padding, type, h, padding);
}
int
-ipv4_get_signature_gap (hicn_type_t type, const hicn_protocol_t *h,
- uint8_t *gap)
+ipv4_get_signature_padding (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *padding)
{
- return CHILD_OPS (get_signature_gap, type, h, gap);
+ return CHILD_OPS (get_signature_padding, type, h, padding);
}
int
@@ -481,6 +493,18 @@ ipv4_get_signature (hicn_type_t type, hicn_protocol_t *h, uint8_t **signature)
return CHILD_OPS (get_signature, type, h, signature);
}
+int
+ipv4_is_last_data (hicn_type_t type, const hicn_protocol_t *h, int *is_last)
+{
+ return CHILD_OPS (is_last_data, type, h, is_last);
+}
+
+int
+ipv4_set_last_data (hicn_type_t type, hicn_protocol_t *h)
+{
+ return CHILD_OPS (set_last_data, type, h);
+}
+
DECLARE_HICN_OPS (ipv4);
/*
diff --git a/lib/src/protocol/ipv6.c b/lib/src/protocol/ipv6.c
index 7ac55b2be..b3a107a13 100644
--- a/lib/src/protocol/ipv6.c
+++ b/lib/src/protocol/ipv6.c
@@ -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:
@@ -33,8 +33,8 @@ ipv6_init_packet_header (hicn_type_t type, hicn_protocol_t *h)
/* *INDENT-OFF* */
h->ipv6 = (_ipv6_header_t){
- .saddr = { { 0 } },
- .daddr = { { 0 } },
+ .saddr = IP6_ADDRESS_EMPTY,
+ .daddr = IP6_ADDRESS_EMPTY,
.version_class_flow = htonl ((IPV6_DEFAULT_VERSION << 28) |
(IPV6_DEFAULT_TRAFFIC_CLASS << 20) |
(IPV6_DEFAULT_FLOW_LABEL & 0xfffff)),
@@ -48,17 +48,17 @@ 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)
+ ip_address_t *ip_address)
{
- ip_address->ip6 = h->ipv6.saddr;
+ ip_address->v6 = 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)
+ const ip_address_t *ip_address)
{
- h->ipv6.saddr = ip_address->ip6;
+ h->ipv6.saddr = ip_address->v6;
return HICN_LIB_ERROR_NONE;
}
@@ -66,20 +66,16 @@ int
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
- name->type = HNT_CONTIGUOUS_V6;
- name->len = HICN_V6_NAME_LEN;
-#endif /* HICN_VPP_PLUGIN */
- return CHILD_OPS (get_interest_name_suffix, type, h, &(name->ip6.suffix));
+ name->prefix.v6 = h->ipv6.daddr;
+ return CHILD_OPS (get_interest_name_suffix, type, h, &(name->suffix));
}
int
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));
+ h->ipv6.daddr = name->prefix.v6;
+ return CHILD_OPS (set_interest_name_suffix, type, h, &(name->suffix));
}
int
@@ -97,6 +93,12 @@ ipv6_set_interest_name_suffix (hicn_type_t type, hicn_protocol_t *h,
}
int
+ipv6_is_interest (hicn_type_t type, const hicn_protocol_t *h, int *is_interest)
+{
+ return CHILD_OPS (is_interest, type, h, is_interest);
+}
+
+int
ipv6_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t *h)
{
return CHILD_OPS (mark_packet_as_interest, type, h);
@@ -119,17 +121,17 @@ 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)
+ ip_address_t *ip_address)
{
- ip_address->ip6 = h->ipv6.daddr;
+ ip_address->v6 = 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)
+ const ip_address_t *ip_address)
{
- h->ipv6.daddr = ip_address->ip6;
+ h->ipv6.daddr = ip_address->v6;
return HICN_LIB_ERROR_NONE;
}
@@ -137,20 +139,16 @@ int
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
- name->type = HNT_CONTIGUOUS_V6;
- name->len = HICN_V6_NAME_LEN;
-#endif /* HICN_VPP_PLUGIN */
- return CHILD_OPS (get_data_name_suffix, type, h, &(name->ip6.suffix));
+ name->prefix.v6 = h->ipv6.saddr;
+ return CHILD_OPS (get_data_name_suffix, type, h, &(name->suffix));
}
int
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));
+ h->ipv6.saddr = name->prefix.v6;
+ return CHILD_OPS (set_data_name_suffix, type, h, &(name->suffix));
}
int
@@ -281,24 +279,23 @@ ipv6_verify_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
int
ipv6_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)
{
// ASSERT(addr_old == NULL);
- addr_old->ip6 = h->ipv6.saddr;
- h->ipv6.saddr = addr_new->ip6;
+ addr_old->v6 = h->ipv6.saddr;
+ h->ipv6.saddr = addr_new->v6;
return CHILD_OPS (rewrite_interest, type, h, addr_new, addr_old);
}
int
ipv6_rewrite_data (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,
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;
+ addr_old->v6 = h->ipv6.daddr;
+ h->ipv6.daddr = addr_new->v6;
return CHILD_OPS (rewrite_data, type, h, addr_new, addr_old, face_id,
reset_pl);
@@ -357,6 +354,20 @@ ipv6_set_payload_length (hicn_type_t type, hicn_protocol_t *h,
}
int
+ipv6_get_payload_type (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_payload_type_t *payload_type)
+{
+ return CHILD_OPS (get_payload_type, type, h, payload_type);
+}
+
+int
+ipv6_set_payload_type (hicn_type_t type, hicn_protocol_t *h,
+ hicn_payload_type_t payload_type)
+{
+ return CHILD_OPS (set_payload_type, type, h, payload_type);
+}
+
+int
ipv6_get_signature_size (hicn_type_t type, const hicn_protocol_t *h,
size_t *signature_size)
{
@@ -371,16 +382,17 @@ ipv6_set_signature_size (hicn_type_t type, hicn_protocol_t *h,
}
int
-ipv6_set_signature_gap (hicn_type_t type, hicn_protocol_t *h, uint8_t gap)
+ipv6_set_signature_padding (hicn_type_t type, hicn_protocol_t *h,
+ size_t padding)
{
- return CHILD_OPS (set_signature_gap, type, h, gap);
+ return CHILD_OPS (set_signature_padding, type, h, padding);
}
int
-ipv6_get_signature_gap (hicn_type_t type, const hicn_protocol_t *h,
- uint8_t *gap)
+ipv6_get_signature_padding (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *padding)
{
- return CHILD_OPS (get_signature_gap, type, h, gap);
+ return CHILD_OPS (get_signature_padding, type, h, padding);
}
int
@@ -430,6 +442,18 @@ ipv6_get_signature (hicn_type_t type, hicn_protocol_t *h, uint8_t **signature)
return CHILD_OPS (get_signature, type, h, signature);
}
+int
+ipv6_is_last_data (hicn_type_t type, const hicn_protocol_t *h, int *is_last)
+{
+ return CHILD_OPS (is_last_data, type, h, is_last);
+}
+
+int
+ipv6_set_last_data (hicn_type_t type, hicn_protocol_t *h)
+{
+ return CHILD_OPS (set_last_data, type, h);
+}
+
DECLARE_HICN_OPS (ipv6);
/*
diff --git a/lib/src/protocol/new.c b/lib/src/protocol/new.c
new file mode 100644
index 000000000..8c79963ad
--- /dev/null
+++ b/lib/src/protocol/new.c
@@ -0,0 +1,441 @@
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <hicn/common.h>
+#include <hicn/error.h>
+#include <hicn/ops.h>
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+
+static int
+is_interest (u8 flags)
+{
+ return flags & HICN_NEW_FLAG_INT;
+}
+
+int
+new_init_packet_header (hicn_type_t type, hicn_protocol_t *h)
+{
+ memset (&h->newhdr, 0, sizeof (h->newhdr));
+ _set_new_header_version (&h->newhdr);
+ uint8_t ah_flag = type.l2 == IPPROTO_AH ? HICN_NEW_FLAG_SIG : 0;
+ h->newhdr.flags |= ah_flag;
+
+ return CHILD_OPS (init_packet_header, type, h);
+}
+
+int
+new_is_interest (hicn_type_t type, const hicn_protocol_t *h, int *is_interest)
+{
+ *is_interest = (h->newhdr.flags & HICN_NEW_FLAG_INT) != 0;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t *h)
+{
+ h->newhdr.flags |= HICN_NEW_FLAG_INT;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_mark_packet_as_data (hicn_type_t type, hicn_protocol_t *h)
+{
+ h->newhdr.flags &= ~HICN_NEW_FLAG_INT;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_get_interest_locator (hicn_type_t type, const hicn_protocol_t *h,
+ ip_address_t *ip_address)
+{
+ assert (is_interest (h->newhdr.flags));
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_interest_locator (hicn_type_t type, hicn_protocol_t *h,
+ const ip_address_t *ip_address)
+{
+ assert (is_interest (h->newhdr.flags));
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_get_interest_name (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_name_t *name)
+{
+ assert (is_interest (h->newhdr.flags));
+ name->prefix = h->newhdr.prefix;
+ name->suffix = ntohl (h->newhdr.suffix);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_interest_name (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_name_t *name)
+{
+ int rc = new_mark_packet_as_interest (type, h);
+ if (rc)
+ return rc;
+
+ assert (is_interest (h->newhdr.flags));
+ h->newhdr.prefix = name->prefix;
+ h->newhdr.suffix = htonl (name->suffix);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_get_interest_name_suffix (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_name_suffix_t *suffix)
+{
+ assert (is_interest (h->newhdr.flags));
+ *suffix = ntohl (h->newhdr.suffix);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_interest_name_suffix (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_name_suffix_t *suffix)
+{
+ assert (is_interest (h->newhdr.flags));
+ h->newhdr.suffix = htonl (*suffix);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t *h)
+{
+ assert (is_interest (h->newhdr.flags));
+ return CHILD_OPS (init_packet_header, type, h);
+}
+
+int
+new_get_data_locator (hicn_type_t type, const hicn_protocol_t *h,
+ ip_address_t *ip_address)
+{
+ assert (!is_interest (h->newhdr.flags));
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_data_locator (hicn_type_t type, hicn_protocol_t *h,
+ const ip_address_t *ip_address)
+{
+ assert (!is_interest (h->newhdr.flags));
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_get_data_name (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_name_t *name)
+{
+ assert (!is_interest (h->newhdr.flags));
+ name->prefix = h->newhdr.prefix;
+ name->suffix = ntohl (h->newhdr.suffix);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_data_name (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_name_t *name)
+{
+ new_mark_packet_as_data (type, h);
+ assert (!is_interest (h->newhdr.flags));
+ h->newhdr.prefix = name->prefix;
+ h->newhdr.suffix = htonl (name->suffix);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_get_data_name_suffix (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_name_suffix_t *suffix)
+{
+ assert (!is_interest (h->newhdr.flags));
+ *suffix = ntohl (h->newhdr.suffix);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_data_name_suffix (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_name_suffix_t *suffix)
+{
+ assert (!is_interest (h->newhdr.flags));
+ h->newhdr.suffix = htonl (*suffix);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_get_data_pathlabel (hicn_type_t type, const hicn_protocol_t *h,
+ u32 *pathlabel)
+{
+ assert (!is_interest (h->newhdr.flags));
+ *pathlabel = h->newhdr.path_label;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_data_pathlabel (hicn_type_t type, hicn_protocol_t *h,
+ const u32 pathlabel)
+{
+ assert (!is_interest (h->newhdr.flags));
+ h->newhdr.path_label = pathlabel;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_update_data_pathlabel (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_faceid_t face_id)
+{
+ hicn_pathlabel_t new_pl;
+ update_pathlabel (h->newhdr.path_label, face_id, &new_pl);
+ h->newhdr.path_label = new_pl;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_reset_data_for_hash (hicn_type_t type, hicn_protocol_t *h)
+{
+ return CHILD_OPS (reset_data_for_hash, type, h);
+}
+
+int
+new_get_lifetime (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_lifetime_t *lifetime)
+{
+ *lifetime = ntohl (h->newhdr.lifetime);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_lifetime (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_lifetime_t lifetime)
+{
+ h->newhdr.lifetime = htonl (lifetime);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_update_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
+ size_t payload_length)
+{
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_verify_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
+ size_t payload_length)
+{
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_rewrite_interest (hicn_type_t type, hicn_protocol_t *h,
+ const ip_address_t *addr_new, ip_address_t *addr_old)
+{
+ assert (is_interest (h->newhdr.flags));
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_rewrite_data (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)
+{
+ assert (!is_interest (h->newhdr.flags));
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_get_length (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *header_length)
+{
+ *header_length = NEW_HDRLEN + ntohs (h->newhdr.payload_length);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_get_current_header_length (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *header_length)
+{
+ *header_length = NEW_HDRLEN;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_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);
+ if (rc < 0)
+ return rc;
+ *header_length = NEW_HDRLEN + child_header_length;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_get_payload_length (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *payload_length)
+{
+ size_t child_header_length = 0;
+ int rc = CHILD_OPS (get_header_length, type, h, &child_header_length);
+ if (rc < 0)
+ return rc;
+ *payload_length = ntohs (h->newhdr.payload_length) - child_header_length;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_payload_length (hicn_type_t type, hicn_protocol_t *h,
+ size_t payload_length)
+{
+ size_t child_header_length = 0;
+ int rc = CHILD_OPS (get_header_length, type, h, &child_header_length);
+ if (rc < 0)
+ return rc;
+ h->newhdr.payload_length =
+ htons ((u_short) (payload_length + child_header_length));
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_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
+new_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
+new_set_signature_padding (hicn_type_t type, hicn_protocol_t *h,
+ size_t padding)
+{
+ return CHILD_OPS (set_signature_padding, type, h, padding);
+}
+
+int
+new_get_signature_padding (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *padding)
+{
+ return CHILD_OPS (get_signature_padding, type, h, padding);
+}
+
+int
+new_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
+new_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
+new_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
+new_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
+new_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
+new_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
+new_get_signature (hicn_type_t type, hicn_protocol_t *h, uint8_t **signature)
+{
+ return CHILD_OPS (get_signature, type, h, signature);
+}
+
+int
+new_get_payload_type (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_payload_type_t *payload_type)
+{
+ *payload_type = ((h->newhdr.flags & HICN_NEW_FLAG_MAN) == HICN_NEW_FLAG_MAN);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_payload_type (hicn_type_t type, hicn_protocol_t *h,
+ hicn_payload_type_t payload_type)
+{
+ if (payload_type != HPT_DATA && payload_type != HPT_MANIFEST)
+ return HICN_LIB_ERROR_INVALID_PARAMETER;
+
+ if (payload_type)
+ h->newhdr.flags |= HICN_NEW_FLAG_MAN;
+ else
+ h->newhdr.flags &= ~HICN_NEW_FLAG_MAN;
+
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_is_last_data (hicn_type_t type, const hicn_protocol_t *h, int *is_last)
+{
+ assert (!is_interest (h->newhdr.flags));
+ *is_last = h->newhdr.flags & HICN_NEW_FLAG_LST;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+new_set_last_data (hicn_type_t type, hicn_protocol_t *h)
+{
+ assert (!is_interest (h->newhdr.flags));
+ h->newhdr.flags |= HICN_NEW_FLAG_LST;
+ return HICN_LIB_ERROR_NONE;
+}
+
+DECLARE_HICN_OPS (new);
+
+#pragma GCC diagnostic pop
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/lib/src/protocol/tcp.c b/lib/src/protocol/tcp.c
index cfeac1907..8097cfd12 100644
--- a/lib/src/protocol/tcp.c
+++ b/lib/src/protocol/tcp.c
@@ -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:
@@ -44,7 +44,20 @@ DECLARE_get_length (tcp, UNEXPECTED);
DECLARE_get_payload_length (tcp, UNEXPECTED);
DECLARE_set_payload_length (tcp, UNEXPECTED);
-always_inline int
+static inline void
+reset_for_hash (hicn_protocol_t *h)
+{
+ h->tcp.sport = 0;
+ h->tcp.dport = 0;
+ h->tcp.seq_ack = 0;
+ h->tcp.data_offset_and_reserved = 0;
+ h->tcp.flags = 0;
+ h->tcp.window = 0;
+ h->tcp.csum = 0;
+ h->tcp.urg_ptr = 0;
+}
+
+static inline int
check_tcp_checksum (u16 csum)
{
/* As per RFC1624
@@ -92,6 +105,20 @@ tcp_init_packet_header (hicn_type_t type, hicn_protocol_t *h)
}
int
+tcp_is_interest (hicn_type_t type, const hicn_protocol_t *h, int *is_interest)
+{
+ *is_interest = (h->tcp.flags & HICN_TCP_FLAG_ECE) == 0;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+tcp_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t *h)
+{
+ h->tcp.flags &= ~HICN_TCP_FLAG_ECE;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
tcp_get_interest_name_suffix (hicn_type_t type, const hicn_protocol_t *h,
hicn_name_suffix_t *suffix)
{
@@ -103,15 +130,12 @@ int
tcp_set_interest_name_suffix (hicn_type_t type, hicn_protocol_t *h,
const hicn_name_suffix_t *suffix)
{
- h->tcp.name_suffix = htonl (*suffix);
+ int rc = tcp_mark_packet_as_interest (type, h);
+ if (rc)
+ return rc;
- return HICN_LIB_ERROR_NONE;
-}
+ h->tcp.name_suffix = htonl (*suffix);
-int
-tcp_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t *h)
-{
- h->tcp.flags &= ~HICN_TCP_FLAG_ECE;
return HICN_LIB_ERROR_NONE;
}
@@ -125,9 +149,7 @@ tcp_mark_packet_as_data (hicn_type_t type, hicn_protocol_t *h)
int
tcp_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t *h)
{
- memset (&(h->tcp), 0, 4);
- memset (&(h->tcp.seq_ack), 0, 12);
-
+ reset_for_hash (h);
return CHILD_OPS (reset_interest_for_hash, type, h);
}
@@ -143,6 +165,10 @@ int
tcp_set_data_name_suffix (hicn_type_t type, hicn_protocol_t *h,
const hicn_name_suffix_t *suffix)
{
+ int rc = tcp_mark_packet_as_data (type, h);
+ if (rc)
+ return rc;
+
h->tcp.name_suffix = htonl (*suffix);
return HICN_LIB_ERROR_NONE;
}
@@ -181,9 +207,7 @@ tcp_update_data_pathlabel (hicn_type_t type, hicn_protocol_t *h,
int
tcp_reset_data_for_hash (hicn_type_t type, hicn_protocol_t *h)
{
- memset (&(h->tcp), 0, 4);
- memset (&(h->tcp.seq_ack), 0, 12);
-
+ reset_for_hash (h);
return CHILD_OPS (reset_data_for_hash, type, h);
}
@@ -279,7 +303,7 @@ tcp_verify_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
int
tcp_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)
{
u16 *tcp_checksum = &(h->tcp.csum);
int ret = check_tcp_checksum (*tcp_checksum);
@@ -310,7 +334,7 @@ tcp_rewrite_interest (hicn_type_t type, hicn_protocol_t *h,
int
tcp_rewrite_data (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,
const hicn_faceid_t face_id, u8 reset_pl)
{
@@ -339,11 +363,11 @@ tcp_rewrite_data (hicn_type_t type, hicn_protocol_t *h,
* csum = ip_csum_add_even (csum, h->ipv4.saddr.as_u32);
*/
ip_csum_t csum =
- ip_csum_sub_even (*tcp_checksum, (ip_csum_t) (addr_old->ip6.as_u64[0]));
+ ip_csum_sub_even (*tcp_checksum, (ip_csum_t) (addr_old->v6.as_u64[0]));
csum =
- ip_csum_sub_even (*tcp_checksum, (ip_csum_t) (addr_old->ip6.as_u64[1]));
- csum = ip_csum_add_even (csum, (ip_csum_t) (addr_new->ip6.as_u64[0]));
- csum = ip_csum_add_even (csum, (ip_csum_t) (addr_new->ip6.as_u64[1]));
+ ip_csum_sub_even (*tcp_checksum, (ip_csum_t) (addr_old->v6.as_u64[1]));
+ csum = ip_csum_add_even (csum, (ip_csum_t) (addr_new->v6.as_u64[0]));
+ csum = ip_csum_add_even (csum, (ip_csum_t) (addr_new->v6.as_u64[1]));
csum = ip_csum_sub_even (csum, old_pl);
csum = ip_csum_add_even (csum, h->tcp.seq_ack);
@@ -389,16 +413,17 @@ tcp_set_signature_size (hicn_type_t type, hicn_protocol_t *h,
}
int
-tcp_set_signature_gap (hicn_type_t type, hicn_protocol_t *h, uint8_t gap)
+tcp_set_signature_padding (hicn_type_t type, hicn_protocol_t *h,
+ size_t padding)
{
- return CHILD_OPS (set_signature_gap, type, h, gap);
+ return CHILD_OPS (set_signature_padding, type, h, padding);
}
int
-tcp_get_signature_gap (hicn_type_t type, const hicn_protocol_t *h,
- uint8_t *gap)
+tcp_get_signature_padding (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *padding)
{
- return CHILD_OPS (get_signature_gap, type, h, gap);
+ return CHILD_OPS (get_signature_padding, type, h, padding);
}
int
@@ -448,6 +473,43 @@ tcp_get_signature (hicn_type_t type, hicn_protocol_t *h, uint8_t **signature)
return CHILD_OPS (get_signature, type, h, signature);
}
+int
+tcp_get_payload_type (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_payload_type_t *payload_type)
+{
+ *payload_type = ((h->tcp.flags & HICN_TCP_FLAG_URG) == HICN_TCP_FLAG_URG);
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+tcp_set_payload_type (hicn_type_t type, hicn_protocol_t *h,
+ hicn_payload_type_t payload_type)
+{
+ if (payload_type != HPT_DATA && payload_type != HPT_MANIFEST)
+ return HICN_LIB_ERROR_INVALID_PARAMETER;
+
+ if (payload_type)
+ h->tcp.flags |= HICN_TCP_FLAG_URG;
+ else
+ h->tcp.flags &= ~HICN_TCP_FLAG_URG;
+
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+tcp_is_last_data (hicn_type_t type, const hicn_protocol_t *h, int *is_last)
+{
+ *is_last = (h->tcp.flags & HICN_TCP_FLAG_RST) == HICN_TCP_FLAG_RST;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+tcp_set_last_data (hicn_type_t type, hicn_protocol_t *h)
+{
+ h->tcp.flags |= HICN_TCP_FLAG_RST;
+ return HICN_LIB_ERROR_NONE;
+}
+
DECLARE_HICN_OPS (tcp);
/*
diff --git a/lib/src/protocol/udp.c b/lib/src/protocol/udp.c
new file mode 100644
index 000000000..ee46b8e9d
--- /dev/null
+++ b/lib/src/protocol/udp.c
@@ -0,0 +1,312 @@
+/*
+ * 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.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <hicn/common.h>
+#include <hicn/error.h>
+#include <hicn/ops.h>
+
+#include <hicn/protocol/udp.h>
+
+DECLARE_get_interest_locator (udp, UNEXPECTED);
+DECLARE_set_interest_locator (udp, UNEXPECTED);
+DECLARE_get_interest_name (udp, UNEXPECTED);
+DECLARE_set_interest_name (udp, UNEXPECTED);
+DECLARE_get_data_locator (udp, UNEXPECTED);
+DECLARE_set_data_locator (udp, UNEXPECTED);
+DECLARE_get_data_name (udp, UNEXPECTED);
+DECLARE_set_data_name (udp, UNEXPECTED);
+DECLARE_get_payload_length (udp, UNEXPECTED);
+DECLARE_set_payload_length (udp, UNEXPECTED);
+
+int
+udp_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);
+ if (rc < 0)
+ return rc;
+
+ /* *INDENT-OFF* */
+ h->udp = (_udp_header_t){ .src_port = 0,
+ .dst_port = 0,
+ .length = htons ((u16) total_header_length),
+ .checksum = 0 };
+ /* *INDENT-ON* */
+ return CHILD_OPS (init_packet_header, type, h);
+}
+
+int
+udp_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
+udp_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
+udp_is_interest (hicn_type_t type, const hicn_protocol_t *h, int *is_interest)
+{
+ return CHILD_OPS (is_interest, type, h, is_interest);
+}
+
+int
+udp_mark_packet_as_interest (hicn_type_t type, hicn_protocol_t *h)
+{
+ return CHILD_OPS (mark_packet_as_interest, type, h);
+}
+
+int
+udp_mark_packet_as_data (hicn_type_t type, hicn_protocol_t *h)
+{
+ return CHILD_OPS (mark_packet_as_data, type, h);
+}
+
+int
+udp_reset_interest_for_hash (hicn_type_t type, hicn_protocol_t *h)
+{
+ return CHILD_OPS (reset_interest_for_hash, type, h);
+}
+
+int
+udp_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
+udp_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
+udp_get_data_pathlabel (hicn_type_t type, const hicn_protocol_t *h,
+ u32 *pathlabel)
+{
+ return CHILD_OPS (get_data_pathlabel, type, h, pathlabel);
+}
+
+int
+udp_set_data_pathlabel (hicn_type_t type, hicn_protocol_t *h,
+ const u32 pathlabel)
+{
+ return CHILD_OPS (set_data_pathlabel, type, h, pathlabel);
+}
+
+int
+udp_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
+udp_reset_data_for_hash (hicn_type_t type, hicn_protocol_t *h)
+{
+ return CHILD_OPS (reset_data_for_hash, type, h);
+}
+
+int
+udp_get_lifetime (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_lifetime_t *lifetime)
+{
+ return CHILD_OPS (get_lifetime, type, h, lifetime);
+}
+
+int
+udp_set_lifetime (hicn_type_t type, hicn_protocol_t *h,
+ const hicn_lifetime_t lifetime)
+{
+ return CHILD_OPS (set_lifetime, type, h, lifetime);
+}
+
+int
+udp_update_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
+ size_t payload_length)
+{
+ return CHILD_OPS (update_checksums, type, h, partial_csum, payload_length);
+}
+
+int
+udp_verify_checksums (hicn_type_t type, hicn_protocol_t *h, u16 partial_csum,
+ size_t payload_length)
+{
+ return CHILD_OPS (verify_checksums, type, h, partial_csum, payload_length);
+}
+
+int
+udp_rewrite_interest (hicn_type_t type, hicn_protocol_t *h,
+ const ip_address_t *addr_new, ip_address_t *addr_old)
+{
+ return CHILD_OPS (rewrite_interest, type, h, addr_new, addr_old);
+}
+
+int
+udp_rewrite_data (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 CHILD_OPS (rewrite_data, type, h, addr_new, addr_old, face_id,
+ reset_pl);
+}
+
+int
+udp_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
+udp_get_current_header_length (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *header_length)
+{
+ *header_length = UDP_HDRLEN;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+udp_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);
+ if (rc < 0)
+ return rc;
+ *header_length = UDP_HDRLEN + child_header_length;
+ return HICN_LIB_ERROR_NONE;
+}
+
+int
+udp_get_payload_type (hicn_type_t type, const hicn_protocol_t *h,
+ hicn_payload_type_t *payload_type)
+{
+ return CHILD_OPS (get_payload_type, type, h, payload_type);
+}
+
+int
+udp_set_payload_type (hicn_type_t type, hicn_protocol_t *h,
+ hicn_payload_type_t payload_type)
+{
+ return CHILD_OPS (set_payload_type, type, h, payload_type);
+}
+
+int
+udp_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
+udp_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
+udp_set_signature_padding (hicn_type_t type, hicn_protocol_t *h,
+ size_t padding)
+{
+ return CHILD_OPS (set_signature_padding, type, h, padding);
+}
+
+int
+udp_get_signature_padding (hicn_type_t type, const hicn_protocol_t *h,
+ size_t *padding)
+{
+ return CHILD_OPS (get_signature_padding, type, h, padding);
+}
+
+int
+udp_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
+udp_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
+udp_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
+udp_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
+udp_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
+udp_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
+udp_get_signature (hicn_type_t type, hicn_protocol_t *h, uint8_t **signature)
+{
+ return CHILD_OPS (get_signature, type, h, signature);
+}
+
+int
+udp_is_last_data (hicn_type_t type, const hicn_protocol_t *h, int *is_last)
+{
+ return CHILD_OPS (is_last_data, type, h, is_last);
+}
+
+int
+udp_set_last_data (hicn_type_t type, hicn_protocol_t *h)
+{
+ return CHILD_OPS (set_last_data, type, h);
+}
+
+DECLARE_HICN_OPS (udp);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */