diff options
Diffstat (limited to 'lib/includes/hicn/base.h')
-rw-r--r-- | lib/includes/hicn/base.h | 109 |
1 files changed, 69 insertions, 40 deletions
diff --git a/lib/includes/hicn/base.h b/lib/includes/hicn/base.h index 1061724ce..844814d57 100644 --- a/lib/includes/hicn/base.h +++ b/lib/includes/hicn/base.h @@ -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: @@ -34,16 +34,17 @@ typedef u32 hicn_faceid_t; typedef u8 hicn_pathlabel_t; typedef u32 hicn_lifetime_t; -#define HICN_MAX_LIFETIME_SCALED 0xFFFF -#define HICN_MAX_LIFETIME_MULTIPLIER 0x0F /* 4 bits */ -#define HICN_MAX_LIFETIME HICN_MAX_LIFETIME_SCALED << HICN_MAX_LIFETIME_MULTIPLIER +#define HICN_MAX_LIFETIME_SCALED 0xFFFF +#define HICN_MAX_LIFETIME_MULTIPLIER 0x0F /* 4 bits */ +#define HICN_MAX_LIFETIME \ + HICN_MAX_LIFETIME_SCALED << HICN_MAX_LIFETIME_MULTIPLIER /** * @brief hICN packet format type * - * The hICN type represents the sequence of protocols that we can find in packet - * headers. They are represented as a quartet of u8 values, correponding to - * IANA protocol assignment, and read from right to left. This is done to + * The hICN type represents the sequence of protocols that we can find in + * packet headers. They are represented as a quartet of u8 values, correponding + * to IANA protocol assignment, and read from right to left. This is done to * faciliate decapsulation of packet header by simple shift/mask operations. * * For instance, an IPv6/TCP packet will be identified as : @@ -55,19 +56,19 @@ typedef u32 hicn_lifetime_t; */ typedef union { - /** protocol layers representation */ + /** protocol layers representation */ struct { #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - u8 l1; /**< First layer */ - u8 l2; /**< Second layer */ - u8 l3; /**< Third layer */ - u8 l4; /**< Fourth layer */ + u8 l1; /**< First layer */ + u8 l2; /**< Second layer */ + u8 l3; /**< Third layer */ + u8 l4; /**< Fourth layer */ #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - u8 l4; /**< Fourth layer */ - u8 l3; /**< Third layer */ - u8 l2; /**< Second layer */ - u8 l1; /**< First layer */ + u8 l4; /**< Fourth layer */ + u8 l3; /**< Third layer */ + u8 l2; /**< Second layer */ + u8 l1; /**< First layer */ #elif _WIN32 /* Windows is assumed little-endian */ u8 l1; u8 l2; @@ -77,46 +78,73 @@ typedef union #error "Unsupported endianness" #endif }; - /** u32 representation */ + /** u32 representation */ u32 as_u32; } hicn_type_t; /* Common protocol layers */ /* Common protocol layers */ #ifndef _WIN32 -#define HICN_TYPE(x,y,z,t) (hicn_type_t) {{ .l1 = x, .l2 = y, .l3 = z, .l4 = t }} +#define HICN_TYPE(x, y, z, t) \ + (hicn_type_t) \ + { \ + { \ + .l1 = x, .l2 = y, .l3 = z, .l4 = t \ + } \ + } #else inline hicn_type_t -HICN_TYPE(int x, int y, int z, int t) +HICN_TYPE (int x, int y, int z, int t) { - hicn_type_t type; - type.l1 = x; - type.l2 = y; - type.l3 = z; - type.l4 = t; - return type; + hicn_type_t type; + type.l1 = x; + type.l2 = y; + type.l3 = z; + type.l4 = t; + return type; } #endif -#define HICN_TYPE_IPV4_TCP HICN_TYPE(IPPROTO_IP, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE) -#define HICN_TYPE_IPV4_ICMP HICN_TYPE(IPPROTO_IP, IPPROTO_ICMP, IPPROTO_NONE, IPPROTO_NONE) -#define HICN_TYPE_IPV6_TCP HICN_TYPE(IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE) -#define HICN_TYPE_IPV6_ICMP HICN_TYPE(IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_NONE, IPPROTO_NONE) -#define HICN_TYPE_IPV4_TCP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE) -#define HICN_TYPE_IPV4_ICMP_AH HICN_TYPE(IPPROTO_IP, IPPROTO_ICMP, IPPROTO_AH, IPPROTO_NONE) -#define HICN_TYPE_IPV6_TCP_AH HICN_TYPE(IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE) -#define HICN_TYPE_IPV6_ICMP_AH HICN_TYPE(IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_AH, IPPROTO_NONE) -#define HICN_TYPE_NONE HICN_TYPE(IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_TYPE_IPV4_TCP \ + HICN_TYPE (IPPROTO_IP, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_TYPE_IPV4_ICMP \ + HICN_TYPE (IPPROTO_IP, IPPROTO_ICMP, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_TYPE_IPV6_TCP \ + HICN_TYPE (IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_TYPE_IPV6_ICMP \ + HICN_TYPE (IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_TYPE_NEW \ + HICN_TYPE (IPPROTO_ENCAP, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_TYPE_IPV4_UDP \ + HICN_TYPE (IPPROTO_IP, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_NONE) +#define HICN_TYPE_IPV6_UDP \ + HICN_TYPE (IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_NONE) +#define HICN_TYPE_IPV4_TCP_AH \ + HICN_TYPE (IPPROTO_IP, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE) +#define HICN_TYPE_IPV4_ICMP_AH \ + HICN_TYPE (IPPROTO_IP, IPPROTO_ICMP, IPPROTO_AH, IPPROTO_NONE) +#define HICN_TYPE_IPV6_TCP_AH \ + HICN_TYPE (IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE) +#define HICN_TYPE_IPV6_ICMP_AH \ + HICN_TYPE (IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_AH, IPPROTO_NONE) +#define HICN_TYPE_NEW_AH \ + HICN_TYPE (IPPROTO_ENCAP, IPPROTO_AH, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_TYPE_IPV6_UDP_AH \ + HICN_TYPE (IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_AH) +#define HICN_TYPE_IPV4_UDP_AH \ + HICN_TYPE (IPPROTO_IP, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_AH) +#define HICN_TYPE_NONE \ + HICN_TYPE (IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE) /** * @brief Check if type is none. * @return 1 if none, 0 otherwise */ -always_inline int -hicn_type_is_none(hicn_type_t type) +static inline int +hicn_type_is_none (hicn_type_t type) { return (type.l1 == IPPROTO_NONE) && (type.l2 == IPPROTO_NONE) && - (type.l3 == IPPROTO_NONE) && (type.l4 == IPPROTO_NONE); + (type.l3 == IPPROTO_NONE) && (type.l4 == IPPROTO_NONE); } /** @@ -151,11 +179,12 @@ typedef enum * @param [in] face_id The face identifier to combine into the path label * @param [out] new_label Computed pathlabel * - * This function updates the current_label based on the new face_id, and returns + * This function updates the current_label based on the new face_id, and + * returns */ -always_inline void +static inline void update_pathlabel (hicn_pathlabel_t current_label, hicn_faceid_t face_id, - hicn_pathlabel_t * new_label) + hicn_pathlabel_t *new_label) { hicn_pathlabel_t pl_face_id = (hicn_pathlabel_t) (face_id & HICN_PATH_LABEL_MASK); |