Hybrid ICN (hICN) plugin  v21.06-rc0-4-g18fa668
compat.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
27 #ifndef HICN_COMPAT_H
28 #define HICN_COMPAT_H
29 
30 #include "common.h"
31 #include "header.h"
32 #include "name.h"
33 
34 /* HICN format options */
35 #define HFO_INET 1 << 0
36 #define HFO_INET6 1 << 1
37 #define HFO_TCP 1 << 2
38 #define HFO_ICMP 1 << 3
39 #define HFO_AH 1 << 4
40 
41 #define _is_ipv4(format) ((format & HFO_INET))
42 #define _is_ipv6(format) ((format & HFO_INET6) >> 1)
43 #define _is_tcp(format) ((format & HFO_TCP) >> 2)
44 #define _is_icmp(format) ((format & HFO_ICMP) >> 3)
45 #define _is_ah(format) ((format & HFO_AH) >> 4)
46 
47 typedef enum
48 {
49  HF_UNSPEC = 0,
50  HF_INET_TCP = HFO_INET | HFO_TCP,
51  HF_INET6_TCP = HFO_INET6 | HFO_TCP,
52  HF_INET_ICMP = HFO_INET | HFO_ICMP,
53  HF_INET6_ICMP = HFO_INET6 | HFO_ICMP,
54  HF_INET_TCP_AH = HFO_INET | HFO_TCP | HFO_AH,
55  HF_INET6_TCP_AH = HFO_INET6 | HFO_TCP | HFO_AH,
56  HF_INET_ICMP_AH = HFO_INET | HFO_ICMP | HFO_AH,
57  HF_INET6_ICMP_AH = HFO_INET6 | HFO_ICMP | HFO_AH,
58 } hicn_format_t;
59 
66 #define HICN_V6_MIN_HDR_LEN 6 /* bytes */
67 #define HICN_V4_MIN_HDR_LEN 4 /* bytes */
68 
69 // #define HICN_MIN_HDR_LEN ((HICN_V6_MIN_HDR_LEN > HICN_V4_MIN_HDR_LEN) ?
70 // HICN_V6_MIN_HDR_LEN : HICN_V4_MIN_HDR_LEN)
71 #define HICN_MIN_HDR_LEN HICN_V6_MIN_HDR_LEN
72 
80 int hicn_packet_init_header (hicn_format_t format, hicn_header_t *packet);
81 
88 int hicn_packet_get_format (const hicn_header_t *packet,
89  hicn_format_t *format);
90 
97 int hicn_packet_compute_checksum (hicn_format_t format, hicn_header_t *packet);
98 
107 int hicn_packet_compute_header_checksum (hicn_format_t format,
108  hicn_header_t *packet, u16 init_sum);
109 
116 int hicn_packet_check_integrity_no_payload (hicn_format_t format,
117  hicn_header_t *packet,
118  u16 init_sum);
119 
120 // this is not accounted here
127 int hicn_packet_get_header_length_from_format (hicn_format_t format,
128  size_t *header_length);
129 
137 int hicn_packet_get_header_length (hicn_format_t format,
138  const hicn_header_t *packet,
139  size_t *header_length);
140 
148 int hicn_packet_get_payload_length (hicn_format_t format,
149  const hicn_header_t *packet,
150  size_t *payload_length);
151 
159 int hicn_packet_set_payload_length (hicn_format_t format,
160  hicn_header_t *packet,
161  const size_t payload_length);
162 
169 int hicn_packet_compare (const hicn_header_t *packet1,
170  const hicn_header_t *packet2);
171 
181 int hicn_packet_get_name (hicn_format_t format, const hicn_header_t *packet,
182  hicn_name_t *name, u8 is_interest);
183 
193 int hicn_packet_set_name (hicn_format_t format, hicn_header_t *packet,
194  const hicn_name_t *name, u8 is_interest);
195 
208 int hicn_packet_set_payload (hicn_format_t format, hicn_header_t *packet,
209  const u8 *payload, u16 payload_length);
210 
225 int hicn_packet_get_payload (hicn_format_t format, const hicn_header_t *packet,
226  u8 **payload, size_t *payload_size,
227  bool hard_copy);
228 
238 int hicn_packet_get_locator (hicn_format_t format, const hicn_header_t *packet,
239  ip_address_t *prefix, bool is_interest);
240 
250 int hicn_packet_set_locator (hicn_format_t format, hicn_header_t *packet,
251  const ip_address_t *prefix, bool is_interest);
252 
260 int hicn_packet_get_signature_size (hicn_format_t format,
261  const hicn_header_t *packet,
262  size_t *bytes);
263 
271 int hicn_packet_set_signature_size (hicn_format_t format,
272  hicn_header_t *packet, size_t bytes);
273 
281 int hicn_packet_set_signature_timestamp (hicn_format_t format,
282  hicn_header_t *h,
283  uint64_t signature_timestamp);
284 
292 int hicn_packet_get_signature_timestamp (hicn_format_t format,
293  const hicn_header_t *h,
294  uint64_t *signature_timestamp);
295 
303 int hicn_packet_set_validation_algorithm (hicn_format_t format,
304  hicn_header_t *h,
305  uint8_t validation_algorithm);
306 
314 int hicn_packet_get_validation_algorithm (hicn_format_t format,
315  const hicn_header_t *h,
316  uint8_t *validation_algorithm);
317 
325 int hicn_packet_set_key_id (hicn_format_t format, hicn_header_t *h,
326  uint8_t *key_id);
327 
335 int hicn_packet_get_key_id (hicn_format_t format, hicn_header_t *h,
336  uint8_t **key_id, uint8_t *key_id_length);
337 
344 int hicn_packet_get_hoplimit (const hicn_header_t *packet, u8 *hops);
345 
352 int hicn_packet_set_hoplimit (hicn_header_t *packet, u8 hops);
353 
354 int hicn_packet_copy_header (hicn_format_t format, const hicn_header_t *packet,
355  hicn_header_t *destination, bool copy_ah);
356 
357 int hicn_packet_get_lifetime (const hicn_header_t *packet, u32 *lifetime);
358 int hicn_packet_set_lifetime (hicn_header_t *packet, u32 lifetime);
359 int hicn_packet_get_reserved_bits (const hicn_header_t *packet,
360  u8 *reserved_bits);
361 int hicn_packet_set_reserved_bits (hicn_header_t *packet,
362  const u8 reserved_bits);
363 int hicn_packet_get_payload_type (const hicn_header_t *packet,
364  hicn_payload_type_t *payload_type);
365 int hicn_packet_set_payload_type (hicn_header_t *packet,
366  const hicn_payload_type_t payload_type);
367 
368 int hicn_packet_set_syn (hicn_format_t format, hicn_header_t *packet);
369 int hicn_packet_reset_syn (hicn_format_t format, hicn_header_t *packet);
370 int hicn_packet_test_syn (hicn_format_t format, const hicn_header_t *packet,
371  bool *flag);
372 int hicn_packet_set_ack (hicn_format_t format, hicn_header_t *packet);
373 int hicn_packet_reset_ack (hicn_format_t format, hicn_header_t *packet);
374 int hicn_packet_test_ack (hicn_format_t format, const hicn_header_t *packet,
375  bool *flag);
376 int hicn_packet_set_rst (hicn_format_t format, hicn_header_t *packet);
377 int hicn_packet_reset_rst (hicn_format_t format, hicn_header_t *packet);
378 int hicn_packet_test_rst (hicn_format_t format, const hicn_header_t *packet,
379  bool *flag);
380 int hicn_packet_set_fin (hicn_format_t format, hicn_header_t *packet);
381 int hicn_packet_reset_fin (hicn_format_t format, hicn_header_t *packet);
382 int hicn_packet_test_fin (hicn_format_t format, const hicn_header_t *packet,
383  bool *flag);
384 int hicn_packet_set_ece (hicn_format_t format, hicn_header_t *packet);
385 int hicn_packet_reset_ece (hicn_format_t format, hicn_header_t *packet);
386 int hicn_packet_test_ece (hicn_format_t format, const hicn_header_t *packet,
387  bool *flag);
388 
389 int hicn_packet_set_src_port (hicn_format_t format, hicn_header_t *packet,
390  u16 src_port);
391 int hicn_packet_get_src_port (hicn_format_t format,
392  const hicn_header_t *packet, u16 *src_port);
393 int hicn_packet_set_dst_port (hicn_format_t format, hicn_header_t *packet,
394  u16 dst_port);
395 int hicn_packet_get_dst_port (hicn_format_t format,
396  const hicn_header_t *packet, u16 *dst_port);
397 int hicn_packet_get_signature (hicn_format_t format, hicn_header_t *packet,
398  uint8_t **sign_buf);
399 
400 /* Interest */
401 int hicn_interest_get_name (hicn_format_t format,
402  const hicn_header_t *interest, hicn_name_t *name);
403 int hicn_interest_set_name (hicn_format_t format, hicn_header_t *interest,
404  const hicn_name_t *name);
405 int hicn_interest_get_locator (hicn_format_t format,
406  const hicn_header_t *interest,
407  ip_address_t *prefix);
408 int hicn_interest_set_locator (hicn_format_t format, hicn_header_t *interest,
409  const ip_address_t *prefix);
410 int hicn_interest_compare (const hicn_header_t *interest_1,
411  const hicn_header_t *interest_2);
412 int hicn_interest_set_lifetime (hicn_header_t *interest, u32 lifetime);
413 int hicn_interest_get_lifetime (const hicn_header_t *interest, u32 *lifetime);
414 int hicn_interest_get_header_length (hicn_format_t format,
415  const hicn_header_t *interest,
416  size_t *header_length);
417 int hicn_interest_get_payload_length (hicn_format_t format,
418  const hicn_header_t *interest,
419  size_t *payload_length);
420 int hicn_interest_set_payload (hicn_format_t format, hicn_header_t *interest,
421  const u8 *payload, size_t payload_length);
422 int hicn_interest_get_payload (hicn_format_t format,
423  const hicn_header_t *interest, u8 **payload,
424  size_t *payload_size, bool hard_copy);
425 int hicn_interest_reset_for_hash (hicn_format_t format, hicn_header_t *packet);
426 
427 /* Data */
428 
429 int hicn_data_get_name (hicn_format_t format, const hicn_header_t *data,
430  hicn_name_t *name);
431 int hicn_data_set_name (hicn_format_t format, hicn_header_t *data,
432  const hicn_name_t *name);
433 int hicn_data_get_locator (hicn_format_t format, const hicn_header_t *data,
434  ip_address_t *prefix);
435 int hicn_data_set_locator (hicn_format_t format, hicn_header_t *data,
436  const ip_address_t *prefix);
437 int hicn_data_compare (const hicn_header_t *data_1,
438  const hicn_header_t *data_2);
439 int hicn_data_get_expiry_time (const hicn_header_t *data, u32 *expiry_time);
440 int hicn_data_set_expiry_time (hicn_header_t *data, u32 expiry_time);
441 int hicn_data_get_header_length (hicn_format_t format, hicn_header_t *data,
442  size_t *header_length);
443 int hicn_data_get_payload_length (hicn_format_t format,
444  const hicn_header_t *data,
445  size_t *payload_length);
446 int hicn_data_get_path_label (const hicn_header_t *data, u32 *path_label);
447 int hicn_data_set_path_label (hicn_header_t *data, u32 path_label);
448 int hicn_data_get_payload (hicn_format_t format, const hicn_header_t *data,
449  u8 **payload, size_t *payload_size, bool hard_copy);
450 int hicn_data_set_payload (hicn_format_t format, hicn_header_t *data,
451  const u8 *payload, size_t payload_length);
452 int hicn_data_get_payload_type (const hicn_header_t *data,
453  hicn_payload_type_t *payload_type);
454 int hicn_data_set_payload_type (hicn_header_t *data,
455  hicn_payload_type_t payload_type);
456 int hicn_data_reset_for_hash (hicn_format_t format, hicn_header_t *packet);
457 int hicn_packet_get_signature_gap (hicn_format_t format,
458  const hicn_header_t *h, uint8_t *bytes);
459 int hicn_packet_set_signature_gap (hicn_format_t format, hicn_header_t *h,
460  uint8_t bytes);
461 #endif /* HICN_COMPAT_H */
462 
463 /*
464  * fd.io coding-style-patch-verification: ON
465  *
466  * Local Variables:
467  * eval: (c-set-style "gnu")
468  * End:
469  */
hicn_packet_get_validation_algorithm
int hicn_packet_get_validation_algorithm(hicn_format_t format, const hicn_header_t *h, uint8_t *validation_algorithm)
Sets the signature size.
hicn_packet_get_payload_length
int hicn_packet_get_payload_length(hicn_format_t format, const hicn_header_t *packet, size_t *payload_length)
Return payload length.
hicn_packet_set_hoplimit
int hicn_packet_set_hoplimit(hicn_header_t *packet, u8 hops)
Sets the packet hop limit.
hicn_packet_check_integrity_no_payload
int hicn_packet_check_integrity_no_payload(hicn_format_t format, hicn_header_t *packet, u16 init_sum)
Verify checksums in packet headers.
hicn_header_t
Definition: header.h:91
hicn_packet_compute_header_checksum
int hicn_packet_compute_header_checksum(hicn_format_t format, hicn_header_t *packet, u16 init_sum)
compute the checksum of the packet header, adding init_sum to the final value
hicn_packet_get_signature_size
int hicn_packet_get_signature_size(hicn_format_t format, const hicn_header_t *packet, size_t *bytes)
Retrieves the signature size.
ip_address_t
Definition: ip_address.h:68
hicn_packet_set_payload_length
int hicn_packet_set_payload_length(hicn_format_t format, hicn_header_t *packet, const size_t payload_length)
Sets payload length.
hicn_packet_get_payload
int hicn_packet_get_payload(hicn_format_t format, const hicn_header_t *packet, u8 **payload, size_t *payload_size, bool hard_copy)
Retrieves the payload of a packet.
hicn_packet_compute_checksum
int hicn_packet_compute_checksum(hicn_format_t format, hicn_header_t *packet)
Update checksums in packet headers.
hicn_packet_compare
int hicn_packet_compare(const hicn_header_t *packet1, const hicn_header_t *packet2)
Compare two hICN packets.
hicn_packet_set_validation_algorithm
int hicn_packet_set_validation_algorithm(hicn_format_t format, hicn_header_t *h, uint8_t validation_algorithm)
Sets the signature size.
hicn_packet_get_format
int hicn_packet_get_format(const hicn_header_t *packet, hicn_format_t *format)
Parse packet headers and return hICN format.
hicn_packet_get_header_length
int hicn_packet_get_header_length(hicn_format_t format, const hicn_header_t *packet, size_t *header_length)
Return total length of hicn headers (before payload)
hicn_packet_get_hoplimit
int hicn_packet_get_hoplimit(const hicn_header_t *packet, u8 *hops)
Retrieves the packet hop limit.
header.h
hICN header data structures.
hicn_packet_set_payload
int hicn_packet_set_payload(hicn_format_t format, hicn_header_t *packet, const u8 *payload, u16 payload_length)
Sets the payload of a packet.
hicn_packet_set_signature_size
int hicn_packet_set_signature_size(hicn_format_t format, hicn_header_t *packet, size_t bytes)
Sets the signature size.
hicn_packet_get_locator
int hicn_packet_get_locator(hicn_format_t format, const hicn_header_t *packet, ip_address_t *prefix, bool is_interest)
Retrieve the locator of an interest / data packet.
hicn_packet_get_key_id
int hicn_packet_get_key_id(hicn_format_t format, hicn_header_t *h, uint8_t **key_id, uint8_t *key_id_length)
Sets the signature size.
hicn_payload_type_t
hicn_payload_type_t
hICN Payload type
Definition: base.h:128
hicn_name_t
Definition: name.h:115
hicn_packet_get_header_length_from_format
int hicn_packet_get_header_length_from_format(hicn_format_t format, size_t *header_length)
Return total length of hicn headers (but signature payload)
hicn_packet_init_header
int hicn_packet_init_header(hicn_format_t format, hicn_header_t *packet)
Parse packet headers and return hICN format.
hicn_packet_set_signature_timestamp
int hicn_packet_set_signature_timestamp(hicn_format_t format, hicn_header_t *h, uint64_t signature_timestamp)
Sets the signature size.
hicn_packet_get_name
int hicn_packet_get_name(hicn_format_t format, const hicn_header_t *packet, hicn_name_t *name, u8 is_interest)
Retrieve the name of an interest/data packet.
hicn_packet_set_name
int hicn_packet_set_name(hicn_format_t format, hicn_header_t *packet, const hicn_name_t *name, u8 is_interest)
Sets the name of an interest/data packet.
hicn_packet_set_locator
int hicn_packet_set_locator(hicn_format_t format, hicn_header_t *packet, const ip_address_t *prefix, bool is_interest)
Sets the locator of an interest / data packet.
hicn_packet_get_signature_timestamp
int hicn_packet_get_signature_timestamp(hicn_format_t format, const hicn_header_t *h, uint64_t *signature_timestamp)
Sets the signature size.
hicn_packet_set_key_id
int hicn_packet_set_key_id(hicn_format_t format, hicn_header_t *h, uint8_t *key_id)
Sets the signature size.