Hybrid ICN (hICN)  v20.01-105-g43d0ecb
mapme.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 
20 #ifndef HICN_MAPME_H
21 #define HICN_MAPME_H
22 
23 #include <stdint.h> // u32
24 #include <stdbool.h>
25 
26 #include "common.h"
27 #include "protocol.h"
28 #include "ops.h"
29 
33 typedef struct
34 {
36  bool enabled;
38  u32 timescale;
40  u32 retx;
45  bool discovery;
47 
49 static const hicn_mapme_conf_t hicn_mapme_conf = {
50  ATTR_INIT (enabled, false),
51  ATTR_INIT (timescale, 0),
52  ATTR_INIT (retx, 50),
53  ATTR_INIT (discovery, true),
54 };
55 
57 typedef u32 seq_t;
58 
60 typedef enum
61 {
62  UNKNOWN,
63  UPDATE,
64  UPDATE_ACK,
65  NOTIFICATION,
66  NOTIFICATION_ACK,
68 
70 typedef struct
71 {
72  int protocol;
73  hicn_mapme_type_t type;
74  seq_t seq;
76 
77 
78 /* MAP-Me API */
79 size_t hicn_mapme_create_packet (u8 * buf, const hicn_prefix_t * prefix,
80  const mapme_params_t * params);
81 size_t hicn_mapme_create_ack (u8 * buf, const mapme_params_t * params);
82 int hicn_mapme_parse_packet (const u8 * packet, hicn_prefix_t * prefix,
83  mapme_params_t * params);
84 
85 /* Implementation & parsing : ICMP Redirect */
86 
87 #define HICN_MAPME_ACK_FLAG (0x20 | 0x60)
88 
89 #define HICN_MAPME_ICMP_TYPE_IPV4 5
90 #define HICN_MAPME_ICMP_TYPE_IPV6 137
91 #define HICN_MAPME_ICMP_TYPE_ACK_IPV4 (HICN_MAPME_ICMP_TYPE_IPV4 | HICN_MAPME_ACK_FLAG)
92 #define HICN_MAPME_ICMP_TYPE_ACK_IPV6 (HICN_MAPME_ICMP_TYPE_IPV6 | HICN_MAPME_ACK_FLAG)
93 #define HICN_MAPME_ICMP_CODE 0 /* Redirect Datagrams for the Network (or subnet) */
94 
95 #define HICN_MAPME_TYPE_IS_IU(type) ((type == HICN_MAPME_ICMP_TYPE_IPV4) || (type == HICN_MAPME_ICMP_TYPE_IPV6))
96 #define HICN_MAPME_TYPE_IS_IU_ACK(type) ((type == HICN_MAPME_ICMP_TYPE_ACK_IPV4) || (type == HICN_MAPME_ICMP_TYPE_ACK_IPV6))
97 
98 #define HICN_MAPME_IS_IU(type, code) (HICN_MAPME_TYPE_IS_IU(type) && (code == HICN_MAPME_ICMP_CODE))
99 #define HICN_MAPME_IS_ACK(type, code) (HICN_MAPME_TYPE_IS_IU_ACK(type) && (code == HICN_MAPME_ICMP_CODE))
100 
101 #define HICN_IS_MAPME(type, code) (HICN_MAPME_IS_IU(type, code) || HICN_MAPME_IS_ACK(type, code))
102 
103 /* Fast check for ACK flag */
104 #define HICN_MAPME_IS_ACK_FAST(icmp_type) (icmp_type & HICN_MAPME_ACK_FLAG)
105 
106 /* Default TTL */
107 #define HICN_MAPME_TTL 255 // typical for redirect (ref?)
108 
109 /*
110  * The length of the MAPME4 header struct must be 120 bytes.
111  */
112 #define EXPECTED_MAPME_V4_HDRLEN 120
113 
115 typedef struct
116 {
117  _ipv4_header_t ip;
118  _icmprd4_header_t icmp_rd;
119  seq_t seq;
120  u8 len;
121  u8 _pad[3];
123 
124 /*
125  * The length of the MAPME4 header struct must be bytes.
126  */
127 #define EXPECTED_MAPME_V6_HDRLEN 88
128 
130 typedef struct
131 {
132  _ipv6_header_t ip;
133  _icmprd_header_t icmp_rd;
134  seq_t seq;
135  u8 len;
136  u8 _pad[3];
138 
140 typedef union
141 {
145 
146 #define HICN_MAPME_V4_HDRLEN sizeof(hicn_mapme_v4_header_t)
147 #define HICN_MAPME_V6_HDRLEN sizeof(hicn_mapme_v6_header_t)
148 
149 static_assert (EXPECTED_MAPME_V4_HDRLEN == HICN_MAPME_V4_HDRLEN,
150  "Size of MAPME_V4 struct does not match its expected size.");
151 static_assert (EXPECTED_MAPME_V6_HDRLEN == HICN_MAPME_V6_HDRLEN,
152  "Size of MAPME_V6 struct does not match its expected size.");
153 
154 #endif /* HICN_MAPME_H */
155 
156 /*
157  * fd.io coding-style-patch-verification: ON
158  *
159  * Local Variables:
160  * eval: (c-set-style "gnu")
161  * End:
162  */
bool enabled
Definition: mapme.h:36
bool discovery
Definition: mapme.h:45
hicn_mapme_type_t
MAP-Me packet types.
Definition: mapme.h:60
Definition: ipv4.h:30
Definition: ipv6.h:26
Protocol header definitions.
MAP-Me configuration options.
Definition: mapme.h:33
Definition: icmprd.h:31
MAP-Me packet header for IPv6.
Definition: mapme.h:130
u32 seq_t
MAP-Me update sequence number.
Definition: mapme.h:57
u32 timescale
Definition: mapme.h:38
MAP-Me packet header for IPv4.
Definition: mapme.h:115
u32 retx
Definition: mapme.h:40
Definition: name.h:49
Definition: icmprd.h:50
MAP-Me parameters (excluding those contained in * hicn_prefix_t)
Definition: mapme.h:70
MAP-Me packet header (IP version agnostic)
Definition: mapme.h:140