FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
ip6_hop_by_hop.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 #ifndef __included_ip6_hop_by_hop_ioam_h__
16 #define __included_ip6_hop_by_hop_ioam_h__
17 
19 #include <vnet/ip/ip.h>
20 
21 
22 #define MAX_IP6_HBH_OPTION 256
23 
24 /* To determine whether a node is decap MS bit is set */
25 #define IOAM_DECAP_BIT 0x80000000
26 
27 #define IOAM_DEAP_ENABLED(opaque_data) (opaque_data & IOAM_DECAP_BIT)
28 
29 #define IOAM_SET_DECAP(opaque_data) \
30  (opaque_data |= IOAM_DECAP_BIT)
31 
32 #define IOAM_MASK_DECAP_BIT(x) (x & ~IOAM_DECAP_BIT)
33 
34 /*
35  * Stores the run time flow data of hbh options
36  */
37 typedef struct
38 {
40  u8 flow_name[64];
41 } flow_data_t;
42 
43 typedef struct
44 {
45  u8 next_index_by_protocol[256];
47 
48 typedef struct
49 {
50  /* The current rewrite we're using */
52 
53  /* Trace data processing callback */
55  /* Configuration data */
56  /* Adjacency */
57  ip6_address_t adj;
58 #define IOAM_HBYH_ADD 0
59 #define IOAM_HBYH_MOD 1
60 #define IOAM_HBYH_POP 2
62  /* time scale transform. Joy. */
65 
66 
67  /* Trace option */
69 
70  /* Pot option */
72 
73  /* Per Packet Counter option */
75 
76  /* Enabling analyis of iOAM data on decap node */
78 
79  /* Array of function pointers to ADD and POP HBH option handling routines */
80  u8 options_size[MAX_IP6_HBH_OPTION];
81  int (*add_options[MAX_IP6_HBH_OPTION]) (u8 * rewrite_string,
82  u8 * rewrite_size);
83  int (*pop_options[MAX_IP6_HBH_OPTION]) (vlib_buffer_t * b,
84  ip6_header_t * ip,
86  int (*get_sizeof_options[MAX_IP6_HBH_OPTION]) (u32 * rewrite_size);
87  int (*config_handler[MAX_IP6_HBH_OPTION]) (void *data, u8 disable);
88 
89  /* Array of function pointers to handle hbh options being used with classifier */
90  u32 (*flow_handler[MAX_IP6_HBH_OPTION]) (u32 flow_ctx, u8 add);
92 
94 
95  /* convenience */
99 
101 
102 extern clib_error_t *ip6_ioam_enable (int has_trace_option,
103  int has_pot_option,
104  int has_seqno_option,
105  int has_analyse_option);
106 
107 extern int ip6_ioam_set_destination (ip6_address_t * addr, u32 mask_width,
108  u32 vrf_id, int is_add, int is_pop,
109  int is_none);
110 
111 extern clib_error_t *clear_ioam_rewrite_fn (void);
112 
113 static inline u8
115 {
116  return (a->as_u32 == 0);
117 }
118 
119 static inline void
120 copy_ip6_address (ip6_address_t * dst, ip6_address_t * src)
121 {
122  dst->as_u64[0] = src->as_u64[0];
123  dst->as_u64[1] = src->as_u64[1];
124 }
125 
126 static inline void
127 set_zero_ip6_address (ip6_address_t * a)
128 {
129  a->as_u64[0] = 0;
130  a->as_u64[1] = 0;
131 }
132 
133 static inline u8
134 cmp_ip6_address (ip6_address_t * a1, ip6_address_t * a2)
135 {
136  return ((a1->as_u64[0] == a2->as_u64[0])
137  && (a1->as_u64[1] == a2->as_u64[1]));
138 }
139 
140 static inline u8
141 is_zero_ip6_address (ip6_address_t * a)
142 {
143  return ((a->as_u64[0] == 0) && (a->as_u64[1] == 0));
144 }
145 
146 int ip6_hbh_add_register_option (u8 option,
147  u8 size,
148  int rewrite_options (u8 * rewrite_string,
149  u8 * size));
150 int ip6_hbh_add_unregister_option (u8 option);
151 
152 int ip6_hbh_pop_register_option (u8 option,
153  int options (vlib_buffer_t * b,
154  ip6_header_t * ip,
155  ip6_hop_by_hop_option_t * opt));
156 int ip6_hbh_pop_unregister_option (u8 option);
157 
158 int
160  int get_sizeof_hdr_options (u32 *
161  rewrite_size));
162 
163 int
164 ip6_ioam_set_rewrite (u8 ** rwp, int has_trace_option,
165  int has_pot_option, int has_seq_no);
166 
167 int
169  int config_handler (void *data, u8 disable));
170 
172 
174  u32 ioam_flow_handler (u32 flow_ctx,
175  u8 add));
176 
178 
180 
181 static inline flow_data_t *
183 {
184  flow_data_t *flow = NULL;
186 
187  if (pool_is_free_index (hm->flows, index))
188  return NULL;
189 
191  return flow;
192 }
193 
194 static inline u32
196 {
197  flow_data_t *flow = NULL;
199  u32 index;
200 
201  index = IOAM_MASK_DECAP_BIT (flow_ctx);
202  //flow = pool_elt_at_index (hm->flows, index);
203  flow = &hm->flows[index];
204  return (flow->ctx[option]);
205 }
206 
207 static inline u8
209 {
211 }
212 
214 
215 static inline u32
216 ioam_flow_add (u8 encap, u8 * flow_name)
217 {
219  flow_data_t *flow = 0;
220  u32 index = 0;
221  u8 i;
222 
223  pool_get (hm->flows, flow);
224  clib_memset (flow, 0, sizeof (flow_data_t));
225 
226  index = flow - hm->flows;
227  strncpy ((char *) flow->flow_name, (char *) flow_name, 31);
228 
229  if (!encap)
231 
232  for (i = 0; i < 255; i++)
233  {
234  if (hm->flow_handler[i])
235  flow->ctx[i] = hm->flow_handler[i] (index, 1);
236  }
237  return (index);
238 }
239 
242 {
243  ip6_hop_by_hop_option_t *opt0, *limit0;
244  u8 type0;
245 
246  if (!hbh0)
247  return NULL;
248 
249  opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
250  limit0 = (ip6_hop_by_hop_option_t *)
251  ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
252 
253  /* Scan the set of h-b-h options, process ones that we understand */
254  while (opt0 < limit0)
255  {
256  type0 = opt0->type;
257  switch (type0)
258  {
259  case 0: /* Pad1 */
260  opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
261  continue;
262  case 1: /* PadN */
263  break;
264  default:
265  if (type0 == option_to_search)
266  return opt0;
267  break;
268  }
269  opt0 =
270  (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
271  sizeof (ip6_hop_by_hop_option_t));
272  }
273  return NULL;
274 }
275 
276 #endif /* __included_ip6_hop_by_hop_ioam_h__ */
277 
278 /*
279  * fd.io coding-style-patch-verification: ON
280  *
281  * Local Variables:
282  * eval: (c-set-style "gnu")
283  * End:
284  */
ip6_hop_by_hop_option_t::length
u8 length
Definition: ip6_hop_by_hop_packet.h:40
ip6_hop_by_hop_ioam_main_t::has_analyse_option
u8 has_analyse_option
Definition: ip6_hop_by_hop.h:77
ip6_hop_by_hop_ioam_main_t::ip6_local_hbh_runtime
ip6_local_hop_by_hop_runtime_t * ip6_local_hbh_runtime
Definition: ip6_hop_by_hop.h:93
ip6_hop_by_hop_option_t::type
u8 type
Definition: ip6_hop_by_hop_packet.h:38
ip6_hop_by_hop_ioam_main_t::has_trace_option
u8 has_trace_option
Definition: ip6_hop_by_hop.h:68
ip6_hbh_pop_unregister_option
int ip6_hbh_pop_unregister_option(u8 option)
Definition: ip6_hop_by_hop.c:500
is_seqno_enabled
static u8 is_seqno_enabled(void)
Definition: ip6_hop_by_hop.h:208
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
is_zero_ip4_address
static u8 is_zero_ip4_address(ip4_address_t *a)
Definition: ip6_hop_by_hop.h:114
ip6_ioam_set_destination
int ip6_ioam_set_destination(ip6_address_t *addr, u32 mask_width, u32 vrf_id, int is_add, int is_pop, int is_none)
MAX_IP6_HBH_OPTION
#define MAX_IP6_HBH_OPTION
Definition: ip6_hop_by_hop.h:22
ip6_hop_by_hop_ioam_main_t::ioam_end_of_path_cb
void * ioam_end_of_path_cb
Definition: ip6_hop_by_hop.h:54
ip6_ioam_set_rewrite
int ip6_ioam_set_rewrite(u8 **rwp, int has_trace_option, int has_pot_option, int has_seq_no)
Definition: ip6_hop_by_hop.c:1138
ip6_hop_by_hop_ioam_main_t
Definition: ip6_hop_by_hop.h:48
ip6_hop_by_hop_ioam_main_t::vlib_main
vlib_main_t * vlib_main
Definition: ip6_hop_by_hop.h:96
ip6_hop_by_hop_packet.h
flow
Definition: flow_types.api:196
ip6_hop_by_hop_ioam_main_t::flow_handler
u32(* flow_handler[MAX_IP6_HBH_OPTION])(u32 flow_ctx, u8 add)
Definition: ip6_hop_by_hop.h:90
ip6_hop_by_hop_option_t
Definition: ip6_hop_by_hop_packet.h:29
set_zero_ip6_address
static void set_zero_ip6_address(ip6_address_t *a)
Definition: ip6_hop_by_hop.h:127
ioam_flow_add
static u32 ioam_flow_add(u8 encap, u8 *flow_name)
Definition: ip6_hop_by_hop.h:216
get_flow
static flow_data_t * get_flow(u32 index)
Definition: ip6_hop_by_hop.h:182
get_flow_data_from_flow_ctx
static u32 get_flow_data_from_flow_ctx(u32 flow_ctx, u8 option)
Definition: ip6_hop_by_hop.h:195
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
ip6_hop_by_hop_header_t
Definition: ip6_hop_by_hop_packet.h:18
ip6_hop_by_hop_ioam_main_t::flows
flow_data_t * flows
Definition: ip6_hop_by_hop.h:91
ip6_trace_profile_setup
int ip6_trace_profile_setup()
Definition: ip6_ioam_trace.c:467
copy_ip6_address
static void copy_ip6_address(ip6_address_t *dst, ip6_address_t *src)
Definition: ip6_hop_by_hop.h:120
mask_width
u8 mask_width
Definition: dhcp.api:204
IOAM_MASK_DECAP_BIT
#define IOAM_MASK_DECAP_BIT(x)
Definition: ip6_hop_by_hop.h:32
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
ip6_hbh_pop_register_option
int ip6_hbh_pop_register_option(u8 option, int options(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt))
Definition: ip6_hop_by_hop.c:481
ip6_hbh_get_sizeof_register_option
int ip6_hbh_get_sizeof_register_option(u8 option, int get_sizeof_hdr_options(u32 *rewrite_size))
ip6_hbh_get_option
static ip6_hop_by_hop_option_t * ip6_hbh_get_option(ip6_hop_by_hop_header_t *hbh0, u8 option_to_search)
Definition: ip6_hop_by_hop.h:241
ip6_hop_by_hop_ioam_main_t::vnet_main
vnet_main_t * vnet_main
Definition: ip6_hop_by_hop.h:97
ip6_hbh_add_register_option
int ip6_hbh_add_register_option(u8 option, u8 size, int rewrite_options(u8 *rewrite_string, u8 *size))
is_zero_ip6_address
static u8 is_zero_ip6_address(ip6_address_t *a)
Definition: ip6_hop_by_hop.h:141
clear_ioam_rewrite_fn
clib_error_t * clear_ioam_rewrite_fn(void)
Definition: ip6_hop_by_hop.c:1224
f64
double f64
Definition: types.h:142
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
src
vl_api_address_t src
Definition: gre.api:54
ip4_address_t
Definition: ip4_packet.h:50
ip6_hop_by_hop_ioam_main_t::rewrite
u8 * rewrite
Definition: ip6_hop_by_hop.h:51
ip6_ioam_enable
clib_error_t * ip6_ioam_enable(int has_trace_option, int has_pot_option, int has_seqno_option, int has_analyse_option)
Definition: ip6_hop_by_hop.c:1276
flow_data_t
Definition: ip6_hop_by_hop.h:37
data
u8 data[128]
Definition: ipsec_types.api:95
vnet_main_t
Definition: vnet.h:76
size
u32 size
Definition: vhost_user.h:125
index
u32 index
Definition: flow_types.api:221
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
ip6_hbh_config_handler_register
int ip6_hbh_config_handler_register(u8 option, int config_handler(void *data, u8 disable))
Definition: ip6_hop_by_hop.c:139
ip.h
u32
unsigned int u32
Definition: types.h:88
options
static struct option options[]
Definition: main.c:52
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
ip6_hop_by_hop_header_t::length
u8 length
Definition: ip6_hop_by_hop_packet.h:26
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
ip6_hop_by_hop_ioam_main_t::ioam_flag
u8 ioam_flag
Definition: ip6_hop_by_hop.h:61
flow
vl_api_flow_t flow
Definition: flow_types.api:240
ip6_hop_by_hop_ioam_main_t::adj
ip6_address_t adj
Definition: ip6_hop_by_hop.h:57
cmp_ip6_address
static u8 cmp_ip6_address(ip6_address_t *a1, ip6_address_t *a2)
Definition: ip6_hop_by_hop.h:134
ip6_hbh_add_unregister_option
int ip6_hbh_add_unregister_option(u8 option)
Definition: ip6_hop_by_hop.c:122
ip6_header_t
Definition: ip6_packet.h:294
ip6_hop_by_hop_ioam_main_t::unix_time_0
u32 unix_time_0
Definition: ip6_hop_by_hop.h:63
ip6_hop_by_hop_ioam_main
ip6_hop_by_hop_ioam_main_t ip6_hop_by_hop_ioam_main
Definition: ip6_hop_by_hop.c:45
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
ip6_local_hop_by_hop_runtime_t
Definition: ip6_hop_by_hop.h:43
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
a
a
Definition: bitmap.h:525
ip
vl_api_address_t ip
Definition: l2.api:558
i
int i
Definition: flowhash_template.h:376
vrf_id
u32 vrf_id
Definition: nat44_ed.api:1053
get_flow_name_from_flow_ctx
u8 * get_flow_name_from_flow_ctx(u32 flow_ctx)
Definition: ip6_hop_by_hop.c:85
ip6_hop_by_hop_ioam_main_t::vlib_time_0
f64 vlib_time_0
Definition: ip6_hop_by_hop.h:64
ip6_hop_by_hop_ioam_main_t::has_pot_option
u8 has_pot_option
Definition: ip6_hop_by_hop.h:71
ip6_hbh_config_handler_unregister
int ip6_hbh_config_handler_unregister(u8 option)
Definition: ip6_hop_by_hop.c:156
ip6_hbh_flow_handler_register
int ip6_hbh_flow_handler_register(u8 option, u32 ioam_flow_handler(u32 flow_ctx, u8 add))
Definition: ip6_hop_by_hop.c:172
ip6_hbh_flow_handler_unregister
int ip6_hbh_flow_handler_unregister(u8 option)
Definition: ip6_hop_by_hop.c:189
ip6_hop_by_hop_ioam_main_t::has_seqno_option
u8 has_seqno_option
Definition: ip6_hop_by_hop.h:74
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
IOAM_SET_DECAP
#define IOAM_SET_DECAP(opaque_data)
Definition: ip6_hop_by_hop.h:29