FD.io VPP  v17.01-9-ge7dcee4
Vector Packet Processing
bfd_udp.c
Go to the documentation of this file.
1 #include <vppinfra/types.h>
2 #include <vlibmemory/api.h>
3 #include <vlib/vlib.h>
4 #include <vlib/buffer.h>
5 #include <vnet/ip/format.h>
6 #include <vnet/ethernet/packet.h>
7 #include <vnet/ip/udp_packet.h>
8 #include <vnet/ip/lookup.h>
10 #include <vnet/ip/ip4.h>
11 #include <vnet/ip/ip6.h>
12 #include <vnet/ip/udp.h>
13 #include <vnet/ip/ip6_packet.h>
14 #include <vnet/adj/adj.h>
15 #include <vnet/adj/adj_nbr.h>
16 #include <vnet/bfd/bfd_debug.h>
17 #include <vnet/bfd/bfd_udp.h>
18 #include <vnet/bfd/bfd_main.h>
19 #include <vnet/bfd/bfd_api.h>
20 
21 typedef struct
22 {
24  /* hashmap - bfd session index by bfd key - used for CLI/API lookup, where
25  * discriminator is unknown */
28 
31 
33 
35  bfd_udp_session_t *bus)
36 {
37  udp_header_t *udp;
38  u16 udp_length, ip_length;
39  bfd_udp_key_t *key = &bus->key;
40 
42  if (ip46_address_is_ip4 (&key->local_addr))
43  {
44  ip4_header_t *ip4;
45  const size_t data_size = sizeof (*ip4) + sizeof (*udp);
46  vlib_buffer_advance (b, -data_size);
47  ip4 = vlib_buffer_get_current (b);
48  udp = (udp_header_t *)(ip4 + 1);
49  memset (ip4, 0, data_size);
50  ip4->ip_version_and_header_length = 0x45;
51  ip4->ttl = 255;
52  ip4->protocol = IP_PROTOCOL_UDP;
53  ip4->src_address.as_u32 = key->local_addr.ip4.as_u32;
54  ip4->dst_address.as_u32 = key->peer_addr.ip4.as_u32;
55 
56  udp->src_port = clib_host_to_net_u16 (50000); /* FIXME */
57  udp->dst_port = clib_host_to_net_u16 (UDP_DST_PORT_bfd4);
58 
59  /* fix ip length, checksum and udp length */
60  ip_length = vlib_buffer_length_in_chain (vm, b);
61 
62  ip4->length = clib_host_to_net_u16 (ip_length);
63  ip4->checksum = ip4_header_checksum (ip4);
64 
65  udp_length = ip_length - (sizeof (*ip4));
66  udp->length = clib_host_to_net_u16 (udp_length);
67  }
68  else
69  {
70  BFD_ERR ("not implemented");
71  abort ();
72  }
73 }
74 
76  bfd_udp_session_t *bus)
77 {
78  vnet_buffer (b)->ip.adj_index[VLIB_RX] = bus->adj_index;
79  vnet_buffer (b)->ip.adj_index[VLIB_TX] = bus->adj_index;
80  bfd_udp_transport_to_buffer (vm, b, bus);
81 }
82 
84  const bfd_udp_key_t *key)
85 {
86  uword *p = mhash_get (&bum->bfd_session_idx_by_bfd_key, key);
87  if (p)
88  {
89  return bfd_find_session_by_idx (bum->bfd_main, *p);
90  }
91  return 0;
92 }
93 
94 static vnet_api_error_t
96  u32 desired_min_tx_us, u32 required_min_rx_us,
97  u8 detect_mult, const ip46_address_t *local_addr,
98  const ip46_address_t *peer_addr)
99 {
100  vnet_sw_interface_t *sw_if =
101  vnet_get_sw_interface (vnet_get_main (), sw_if_index);
102  /* get a pool entry and if we end up not needing it, give it back */
103  bfd_transport_t t = BFD_TRANSPORT_UDP4;
104  if (!ip46_address_is_ip4 (local_addr))
105  {
106  t = BFD_TRANSPORT_UDP6;
107  }
108  bfd_session_t *bs = bfd_get_session (bum->bfd_main, t);
109  bfd_udp_session_t *bus = &bs->udp;
110  memset (bus, 0, sizeof (*bus));
111  bfd_udp_key_t *key = &bus->key;
112  key->sw_if_index = sw_if->sw_if_index;
113  key->local_addr.as_u64[0] = local_addr->as_u64[0];
114  key->local_addr.as_u64[1] = local_addr->as_u64[1];
115  key->peer_addr.as_u64[0] = peer_addr->as_u64[0];
116  key->peer_addr.as_u64[1] = peer_addr->as_u64[1];
117  const bfd_session_t *tmp = bfd_lookup_session (bum, key);
118  if (tmp)
119  {
120  BFD_ERR ("duplicate bfd-udp session, existing bs_idx=%d", tmp->bs_idx);
121  bfd_put_session (bum->bfd_main, bs);
122  return VNET_API_ERROR_BFD_EEXIST;
123  }
124  key->sw_if_index = sw_if->sw_if_index;
125  mhash_set (&bum->bfd_session_idx_by_bfd_key, key, bs->bs_idx, NULL);
126  BFD_DBG ("session created, bs_idx=%u, sw_if_index=%d, local=%U, peer=%U",
127  bs->bs_idx, key->sw_if_index, format_ip46_address, &key->local_addr,
128  IP46_TYPE_ANY, format_ip46_address, &key->peer_addr, IP46_TYPE_ANY);
129  if (BFD_TRANSPORT_UDP4 == t)
130  {
132  &key->peer_addr, key->sw_if_index);
133  BFD_DBG ("adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, VNET_LINK_IP4, %U, %d) "
134  "returns %d",
135  format_ip46_address, &key->peer_addr, IP46_TYPE_ANY,
136  key->sw_if_index, bus->adj_index);
137  }
138  else
139  {
141  &key->peer_addr, key->sw_if_index);
142  BFD_DBG ("adj_nbr_add_or_lock(FIB_PROTOCOL_IP6, VNET_LINK_IP6, %U, %d) "
143  "returns %d",
144  format_ip46_address, &key->peer_addr, IP46_TYPE_ANY,
145  key->sw_if_index, bus->adj_index);
146  }
147  bs->config_desired_min_tx_us = desired_min_tx_us;
148  bs->required_min_rx_us = required_min_rx_us;
149  bs->local_detect_mult = detect_mult;
150  bfd_session_start (bum->bfd_main, bs);
151  return 0;
152 }
153 
154 static vnet_api_error_t
155 bfd_udp_validate_api_input (u32 sw_if_index, const ip46_address_t *local_addr,
156  const ip46_address_t *peer_addr)
157 {
158  vnet_sw_interface_t *sw_if =
159  vnet_get_sw_interface (vnet_get_main (), sw_if_index);
160  u8 local_ip_valid = 0;
162  if (!sw_if)
163  {
164  BFD_ERR ("got NULL sw_if");
165  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
166  }
167  if (ip46_address_is_ip4 (local_addr))
168  {
169  if (!ip46_address_is_ip4 (peer_addr))
170  {
171  BFD_ERR ("IP family mismatch");
172  return VNET_API_ERROR_INVALID_ARGUMENT;
173  }
174  ip4_main_t *im = &ip4_main;
175 
176  /* *INDENT-OFF* */
178  &im->lookup_main, ia, sw_if_index, 0 /* honor unnumbered */, ({
179  ip4_address_t *x =
180  ip_interface_address_get_address (&im->lookup_main, ia);
181  if (x->as_u32 == local_addr->ip4.as_u32)
182  {
183  /* valid address for this interface */
184  local_ip_valid = 1;
185  break;
186  }
187  }));
188  /* *INDENT-ON* */
189  }
190  else
191  {
192  if (ip46_address_is_ip4 (peer_addr))
193  {
194  BFD_ERR ("IP family mismatch");
195  return VNET_API_ERROR_INVALID_ARGUMENT;
196  }
197  ip6_main_t *im = &ip6_main;
198  /* *INDENT-OFF* */
200  &im->lookup_main, ia, sw_if_index, 0 /* honor unnumbered */, ({
201  ip6_address_t *x =
202  ip_interface_address_get_address (&im->lookup_main, ia);
203  if (local_addr->ip6.as_u64[0] == x->as_u64[0] &&
204  local_addr->ip6.as_u64[1] == x->as_u64[1])
205  {
206  /* valid address for this interface */
207  local_ip_valid = 1;
208  break;
209  }
210  }));
211  /* *INDENT-ON* */
212  }
213 
214  if (!local_ip_valid)
215  {
216  BFD_ERR ("address not found on interface");
217  return VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE;
218  }
219 
220  return 0;
221 }
222 
223 vnet_api_error_t bfd_udp_add_session (u32 sw_if_index, u32 desired_min_tx_us,
224  u32 required_min_rx_us, u8 detect_mult,
225  const ip46_address_t *local_addr,
226  const ip46_address_t *peer_addr)
227 {
228  vnet_api_error_t rv =
229  bfd_udp_validate_api_input (sw_if_index, local_addr, peer_addr);
230  if (rv)
231  {
232  return rv;
233  }
234  if (detect_mult < 1)
235  {
236  BFD_ERR ("detect_mult < 1");
237  return VNET_API_ERROR_INVALID_ARGUMENT;
238  }
239  if (desired_min_tx_us < 1)
240  {
241  BFD_ERR ("desired_min_tx_us < 1");
242  return VNET_API_ERROR_INVALID_ARGUMENT;
243  }
244  return bfd_udp_add_session_internal (&bfd_udp_main, sw_if_index,
245  desired_min_tx_us, required_min_rx_us,
246  detect_mult, local_addr, peer_addr);
247 }
248 
250  const ip46_address_t *local_addr,
251  const ip46_address_t *peer_addr)
252 {
253  vnet_api_error_t rv =
254  bfd_udp_validate_api_input (sw_if_index, local_addr, peer_addr);
255  if (rv)
256  {
257  return rv;
258  }
260  vnet_sw_interface_t *sw_if =
261  vnet_get_sw_interface (vnet_get_main (), sw_if_index);
262  bfd_udp_key_t key;
263  memset (&key, 0, sizeof (key));
264  key.sw_if_index = sw_if->sw_if_index;
265  key.local_addr.as_u64[0] = local_addr->as_u64[0];
266  key.local_addr.as_u64[1] = local_addr->as_u64[1];
267  key.peer_addr.as_u64[0] = peer_addr->as_u64[0];
268  key.peer_addr.as_u64[1] = peer_addr->as_u64[1];
269  bfd_session_t *tmp = bfd_lookup_session (bum, &key);
270  if (tmp)
271  {
272  BFD_DBG ("free bfd-udp session, bs_idx=%d", tmp->bs_idx);
274  adj_unlock (tmp->udp.adj_index);
275  bfd_put_session (bum->bfd_main, tmp);
276  }
277  else
278  {
279  BFD_ERR ("no such session");
280  return VNET_API_ERROR_BFD_NOENT;
281  }
282  return 0;
283 }
284 
285 typedef enum {
290 
291 /* Packet counters */
292 #define foreach_bfd_udp_error(F) \
293  F (NONE, "good bfd packets (processed)") \
294  F (BAD, "invalid bfd packets") \
295  F (DISABLED, "bfd packets received on disabled interfaces")
296 
297 #define F(sym, string) static char BFD_UDP_ERR_##sym##_STR[] = string;
299 #undef F
300 
301 static char *bfd_udp_error_strings[] = {
302 #define F(sym, string) BFD_UDP_ERR_##sym##_STR,
304 #undef F
305 };
306 
307 typedef enum {
308 #define F(sym, str) BFD_UDP_ERROR_##sym,
310 #undef F
311  BFD_UDP_N_ERROR,
313 
314 static void bfd_udp4_find_headers (vlib_buffer_t *b, const ip4_header_t **ip4,
315  const udp_header_t **udp)
316 {
317  /* sanity check first */
318  const i32 start = vnet_buffer (b)->ip.start_of_ip_header;
319  if (start < 0 && start < sizeof (b->pre_data))
320  {
321  BFD_ERR ("Start of ip header is before pre_data, ignoring");
322  *ip4 = NULL;
323  *udp = NULL;
324  return;
325  }
326  *ip4 = (ip4_header_t *)(b->data + start);
327  if ((u8 *)*ip4 > (u8 *)vlib_buffer_get_current (b))
328  {
329  BFD_ERR ("Start of ip header is beyond current data, ignoring");
330  *ip4 = NULL;
331  *udp = NULL;
332  return;
333  }
334  *udp = (udp_header_t *)((*ip4) + 1);
335 }
336 
337 static bfd_udp_error_t bfd_udp4_verify_transport (const ip4_header_t *ip4,
338  const udp_header_t *udp,
339  const bfd_session_t *bs)
340 {
341  const bfd_udp_session_t *bus = &bs->udp;
342  const bfd_udp_key_t *key = &bus->key;
343  if (ip4->src_address.as_u32 != key->peer_addr.ip4.as_u32)
344  {
345  BFD_ERR ("IP src addr mismatch, got %U, expected %U", format_ip4_address,
347  key->peer_addr.ip4.as_u32);
348  return BFD_UDP_ERROR_BAD;
349  }
350  if (ip4->dst_address.as_u32 != key->local_addr.ip4.as_u32)
351  {
352  BFD_ERR ("IP dst addr mismatch, got %U, expected %U", format_ip4_address,
354  key->local_addr.ip4.as_u32);
355  return BFD_UDP_ERROR_BAD;
356  }
357  const u8 expected_ttl = 255;
358  if (ip4->ttl != expected_ttl)
359  {
360  BFD_ERR ("IP unexpected TTL value %d, expected %d", ip4->ttl,
361  expected_ttl);
362  return BFD_UDP_ERROR_BAD;
363  }
364  if (clib_net_to_host_u16 (udp->src_port) < 49152 ||
365  clib_net_to_host_u16 (udp->src_port) > 65535)
366  {
367  BFD_ERR ("Invalid UDP src port %d, out of range <49152,65535>",
368  udp->src_port);
369  }
370  return BFD_UDP_ERROR_NONE;
371 }
372 
373 typedef struct
374 {
376  bfd_pkt_t pkt;
378 
380 {
381  bfd_consume_pkt (bfd_udp_main.bfd_main, &a->pkt, a->bs_idx);
382 }
383 
384 static void bfd_rpc_update_session (u32 bs_idx, const bfd_pkt_t *pkt)
385 {
386  /* packet length was already verified to be correct by the caller */
387  const u32 data_size = sizeof (bfd_rpc_update_t) -
389  pkt->head.length;
390  u8 data[data_size];
391  bfd_rpc_update_t *update = (bfd_rpc_update_t *)data;
392  update->bs_idx = bs_idx;
393  clib_memcpy (&update->pkt, pkt, pkt->head.length);
395 }
396 
397 static bfd_udp_error_t bfd_udp4_scan (vlib_main_t *vm, vlib_node_runtime_t *rt,
398  vlib_buffer_t *b, bfd_session_t **bs_out)
399 {
400  const bfd_pkt_t *pkt = vlib_buffer_get_current (b);
401  if (sizeof (*pkt) > b->current_length)
402  {
403  BFD_ERR (
404  "Payload size %d too small to hold bfd packet of minimum size %d",
405  b->current_length, sizeof (*pkt));
406  return BFD_UDP_ERROR_BAD;
407  }
408  const ip4_header_t *ip4;
409  const udp_header_t *udp;
410  bfd_udp4_find_headers (b, &ip4, &udp);
411  if (!ip4 || !udp)
412  {
413  BFD_ERR ("Couldn't find ip4 or udp header");
414  return BFD_UDP_ERROR_BAD;
415  }
416  if (!bfd_verify_pkt_common (pkt))
417  {
418  return BFD_UDP_ERROR_BAD;
419  }
420  bfd_session_t *bs = NULL;
421  if (pkt->your_disc)
422  {
423  BFD_DBG ("Looking up BFD session using discriminator %u",
424  pkt->your_disc);
425  bs = bfd_find_session_by_disc (bfd_udp_main.bfd_main, pkt->your_disc);
426  }
427  else
428  {
429  bfd_udp_key_t key;
430  memset (&key, 0, sizeof (key));
431  key.sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
432  key.local_addr.ip4.as_u32 = ip4->dst_address.as_u32;
433  key.peer_addr.ip4.as_u32 = ip4->src_address.as_u32;
434  BFD_DBG ("Looking up BFD session using key (sw_if_index=%u, local=%U, "
435  "peer=%U)",
436  key.sw_if_index, format_ip4_address, key.local_addr.ip4.as_u8,
437  format_ip4_address, key.peer_addr.ip4.as_u8);
438  bs = bfd_lookup_session (&bfd_udp_main, &key);
439  }
440  if (!bs)
441  {
442  BFD_ERR ("BFD session lookup failed - no session matches BFD pkt");
443  return BFD_UDP_ERROR_BAD;
444  }
445  BFD_DBG ("BFD session found, bs_idx=%u", bs->bs_idx);
446  if (!bfd_verify_pkt_session (pkt, b->current_length, bs))
447  {
448  return BFD_UDP_ERROR_BAD;
449  }
450  bfd_udp_error_t err;
451  if (BFD_UDP_ERROR_NONE != (err = bfd_udp4_verify_transport (ip4, udp, bs)))
452  {
453  return err;
454  }
455  bfd_rpc_update_session (bs->bs_idx, pkt);
456  *bs_out = bs;
457  return BFD_UDP_ERROR_NONE;
458 }
459 
460 static bfd_udp_error_t bfd_udp6_scan (vlib_main_t *vm, vlib_buffer_t *b)
461 {
462  /* TODO */
463  return BFD_UDP_ERROR_BAD;
464 }
465 
466 /*
467  * Process a frame of bfd packets
468  * Expect 1 packet / frame
469  */
471  vlib_frame_t *f, int is_ipv6)
472 {
473  u32 n_left_from, *from;
474  bfd_input_trace_t *t0;
475 
476  from = vlib_frame_vector_args (f); /* array of buffer indices */
477  n_left_from = f->n_vectors; /* number of buffer indices */
478 
479  while (n_left_from > 0)
480  {
481  u32 bi0;
482  vlib_buffer_t *b0;
483  u32 next0, error0;
484 
485  bi0 = from[0];
486  b0 = vlib_get_buffer (vm, bi0);
487 
488  bfd_session_t *bs = NULL;
489 
490  /* If this pkt is traced, snapshot the data */
491  if (b0->flags & VLIB_BUFFER_IS_TRACED)
492  {
493  int len;
494  t0 = vlib_add_trace (vm, rt, b0, sizeof (*t0));
495  len = (b0->current_length < sizeof (t0->data)) ? b0->current_length
496  : sizeof (t0->data);
497  t0->len = len;
498  clib_memcpy (t0->data, vlib_buffer_get_current (b0), len);
499  }
500 
501  /* scan this bfd pkt. error0 is the counter index to bmp */
502  if (is_ipv6)
503  {
504  error0 = bfd_udp6_scan (vm, b0);
505  }
506  else
507  {
508  error0 = bfd_udp4_scan (vm, rt, b0, &bs);
509  }
510  b0->error = rt->errors[error0];
511 
513  if (BFD_UDP_ERROR_NONE == error0)
514  {
515  /* if everything went fine, check for poll bit, if present, re-use
516  the buffer and based on (now updated) session parameters, send the
517  final packet back */
518  const bfd_pkt_t *pkt = vlib_buffer_get_current (b0);
519  if (bfd_pkt_get_poll (pkt))
520  {
521  bfd_send_final (vm, b0, bs);
522  if (is_ipv6)
523  {
525  b0->error, 1);
526  }
527  else
528  {
530  b0->error, 1);
531  }
532  next0 = BFD_UDP_INPUT_NEXT_REPLY;
533  }
534  }
535  vlib_set_next_frame_buffer (vm, rt, next0, bi0);
536 
537  from += 1;
538  n_left_from -= 1;
539  }
540 
541  return f->n_vectors;
542 }
543 
545  vlib_frame_t *f)
546 {
547  return bfd_udp_input (vm, rt, f, 0);
548 }
549 
550 /*
551  * bfd input graph node declaration
552  */
553 /* *INDENT-OFF* */
555  .function = bfd_udp4_input,
556  .name = "bfd-udp4-input",
557  .vector_size = sizeof (u32),
559 
560  .n_errors = BFD_UDP_N_ERROR,
561  .error_strings = bfd_udp_error_strings,
562 
563  .format_trace = bfd_input_format_trace,
564 
565  .n_next_nodes = BFD_UDP_INPUT_N_NEXT,
566  .next_nodes =
567  {
568  [BFD_UDP_INPUT_NEXT_NORMAL] = "error-drop",
569  [BFD_UDP_INPUT_NEXT_REPLY] = "ip4-lookup",
570  },
571 };
572 /* *INDENT-ON* */
573 
575  vlib_frame_t *f)
576 {
577  return bfd_udp_input (vm, rt, f, 1);
578 }
579 
580 /* *INDENT-OFF* */
582  .function = bfd_udp6_input,
583  .name = "bfd-udp6-input",
584  .vector_size = sizeof (u32),
586 
587  .n_errors = BFD_UDP_N_ERROR,
588  .error_strings = bfd_udp_error_strings,
589 
590  .format_trace = bfd_input_format_trace,
591 
592  .n_next_nodes = BFD_UDP_INPUT_N_NEXT,
593  .next_nodes =
594  {
595  [BFD_UDP_INPUT_NEXT_NORMAL] = "error-drop",
596  [BFD_UDP_INPUT_NEXT_REPLY] = "ip6-lookup",
597  },
598 };
599 /* *INDENT-ON* */
600 
602  u32 sw_if_index, u32 flags)
603 {
604  // vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
605  if (!(flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP))
606  {
607  /* TODO */
608  }
609  return 0;
610 }
611 
613 
615  u32 hw_if_index, u32 flags)
616 {
617  if (flags & VNET_HW_INTERFACE_FLAG_LINK_UP)
618  {
619  /* TODO */
620  }
621  return 0;
622 }
623 
625 
626 /*
627  * setup function
628  */
630 {
631  mhash_init (&bfd_udp_main.bfd_session_idx_by_bfd_key, sizeof (uword),
632  sizeof (bfd_udp_key_t));
633  bfd_udp_main.bfd_main = &bfd_main;
634  udp_register_dst_port (vm, UDP_DST_PORT_bfd4, bfd_udp4_input_node.index, 1);
635  udp_register_dst_port (vm, UDP_DST_PORT_bfd6, bfd_udp6_input_node.index, 0);
636  return 0;
637 }
638 
format_function_t format_ip46_address
Definition: format.h:61
static clib_error_t * bfd_udp_init(vlib_main_t *vm)
Definition: bfd_udp.c:629
#define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
Definition: lookup.h:460
static uword bfd_udp_input(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f, int is_ipv6)
Definition: bfd_udp.c:470
Definition: mhash.h:46
vnet_api_error_t
Definition: api_errno.h:97
void bfd_consume_pkt(bfd_main_t *bm, const bfd_pkt_t *pkt, u32 bs_idx)
Definition: bfd_main.c:875
a
Definition: bitmap.h:516
ip4_address_t src_address
Definition: ip4_packet.h:163
bfd_main_t bfd_main
Definition: bfd_main.c:961
static void vlib_set_next_frame_buffer(vlib_main_t *vm, vlib_node_runtime_t *node, u32 next_index, u32 buffer_index)
Definition: node_funcs.h:383
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
#define BFD_ERR(...)
Definition: bfd_debug.h:68
bfd_main_t * bfd_main
Definition: bfd_udp.c:23
bfd_session_t * bfd_find_session_by_disc(bfd_main_t *bm, u32 disc)
Definition: bfd_main.c:774
Definitions for all things IP (v4|v6) unicast and multicast lookup related.
#define NULL
Definition: clib.h:55
uword mhash_unset(mhash_t *h, void *key, uword *old_value)
Definition: mhash.c:353
int bfd_verify_pkt_common(const bfd_pkt_t *pkt)
verify bfd packet - common checks
Definition: bfd_main.c:792
static vlib_node_registration_t bfd_udp4_input_node
(constructor) VLIB_REGISTER_NODE (bfd_udp4_input_node)
Definition: bfd_udp.c:29
struct _vlib_node_registration vlib_node_registration_t
void bfd_put_session(bfd_main_t *bm, bfd_session_t *bs)
Definition: bfd_main.c:757
ip_lookup_main_t lookup_main
Definition: ip4.h:97
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
static vlib_node_registration_t bfd_udp6_input_node
(constructor) VLIB_REGISTER_NODE (bfd_udp6_input_node)
Definition: bfd_udp.c:30
u32 config_desired_min_tx_us
Definition: bfd_main.h:70
#define foreach_bfd_udp_error(F)
Definition: bfd_udp.c:292
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:377
static uword bfd_udp4_input(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: bfd_udp.c:544
vlib_error_t * errors
Definition: node.h:419
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:100
format_function_t format_ip4_address
Definition: format.h:79
static vnet_api_error_t bfd_udp_validate_api_input(u32 sw_if_index, const ip46_address_t *local_addr, const ip46_address_t *peer_addr)
Definition: bfd_udp.c:155
bfd_udp_error_t
Definition: bfd_udp.c:307
mhash_t bfd_session_idx_by_bfd_key
Definition: bfd_udp.c:26
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define VNET_BUFFER_LOCALLY_ORIGINATED
Definition: buffer.h:71
static char * bfd_udp_error_strings[]
Definition: bfd_udp.c:301
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:194
ip4_address_t dst_address
Definition: ip4_packet.h:163
static bfd_session_t * bfd_lookup_session(bfd_udp_main_t *bum, const bfd_udp_key_t *key)
Definition: bfd_udp.c:83
void bfd_send_final(vlib_main_t *vm, vlib_buffer_t *b, bfd_session_t *bs)
Definition: bfd_main.c:534
int i32
Definition: types.h:81
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
Definition: memory_vlib.c:1268
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
Definition: buffer.h:150
static clib_error_t * bfd_hw_interface_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: bfd_udp.c:614
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:209
static void bfd_rpc_update_session_cb(const bfd_rpc_update_t *a)
Definition: bfd_udp.c:379
bfd_session_t * bfd_find_session_by_idx(bfd_main_t *bm, uword bs_idx)
Definition: bfd_main.c:764
bfd_udp_key_t key
Definition: bfd_udp.h:40
bfd_pkt_t pkt
Definition: bfd_udp.c:376
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:82
BFD global declarations.
static clib_error_t * bfd_sw_interface_up_down(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: bfd_udp.c:601
VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION(bfd_hw_interface_up_down)
vnet_api_error_t bfd_udp_add_session(u32 sw_if_index, u32 desired_min_tx_us, u32 required_min_rx_us, u8 detect_mult, const ip46_address_t *local_addr, const ip46_address_t *peer_addr)
Definition: bfd_udp.c:223
static uword mhash_set(mhash_t *h, void *key, uword new_value, uword *old_value)
Definition: mhash.h:117
static bfd_udp_error_t bfd_udp4_scan(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_buffer_t *b, bfd_session_t **bs_out)
Definition: bfd_udp.c:397
static vnet_api_error_t bfd_udp_add_session_internal(bfd_udp_main_t *bum, u32 sw_if_index, u32 desired_min_tx_us, u32 required_min_rx_us, u8 detect_mult, const ip46_address_t *local_addr, const ip46_address_t *peer_addr)
Definition: bfd_udp.c:95
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:121
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1113
void bfd_session_start(bfd_main_t *bm, bfd_session_t *bs)
Definition: bfd_main.c:279
#define ip46_address_is_ip4(ip46)
Definition: ip6_packet.h:76
#define F(sym, string)
Definition: bfd_udp.c:308
void mhash_init(mhash_t *h, uword n_value_bytes, uword n_key_bytes)
Definition: mhash.c:168
u16 n_vectors
Definition: node.h:344
bfd_udp_input_next_t
Definition: bfd_udp.c:285
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(bfd_sw_interface_up_down)
static uword bfd_udp6_input(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: bfd_udp.c:574
#define clib_memcpy(a, b, c)
Definition: string.h:69
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:207
BFD global declarations.
u8 * bfd_input_format_trace(u8 *s, va_list *args)
Definition: bfd_main.c:354
#define BFD_DBG(...)
Definition: bfd_debug.h:67
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:528
void bfd_add_udp_transport(vlib_main_t *vm, vlib_buffer_t *b, bfd_udp_session_t *bus)
Definition: bfd_udp.c:75
unsigned int u32
Definition: types.h:88
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
#define vnet_buffer(b)
Definition: buffer.h:361
ip6_main_t ip6_main
Definition: ip6_forward.c:2828
ip_lookup_main_t lookup_main
Definition: ip6.h:135
void bfd_udp_transport_to_buffer(vlib_main_t *vm, vlib_buffer_t *b, bfd_udp_session_t *bus)
Definition: bfd_udp.c:34
IPv4 main type.
Definition: ip4.h:95
static bfd_udp_error_t bfd_udp4_verify_transport(const ip4_header_t *ip4, const udp_header_t *udp, const bfd_session_t *bs)
Definition: bfd_udp.c:337
adj_index_t adj_index
Definition: bfd_udp.h:42
bfd_udp_main_t bfd_udp_main
Definition: bfd_udp.c:32
bfd_transport_t
Definition: bfd_main.h:31
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:95
u64 uword
Definition: types.h:112
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
u32 required_min_rx_us
Definition: bfd_main.h:79
static void bfd_udp4_find_headers(vlib_buffer_t *b, const ip4_header_t **ip4, const udp_header_t **udp)
Definition: bfd_udp.c:314
Definition: defs.h:47
BFD global declarations.
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
BFD global declarations.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:253
vnet_api_error_t bfd_udp_del_session(u32 sw_if_index, const ip46_address_t *local_addr, const ip46_address_t *peer_addr)
Definition: bfd_udp.c:249
u8 bfd_pkt_get_poll(const bfd_pkt_t *pkt)
Definition: bfd_protocol.c:35
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1099
#define STRUCT_SIZE_OF(t, f)
Definition: clib.h:64
u8 data[0]
Packet data.
Definition: buffer.h:158
adj_index_t adj_nbr_add_or_lock(fib_protocol_t nh_proto, vnet_link_t link_type, const ip46_address_t *nh_addr, u32 sw_if_index)
Neighbour Adjacency sub-type.
Definition: adj_nbr.c:175
u8 local_detect_mult
Definition: bfd_main.h:97
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:495
u8 ip_version_and_header_length
Definition: ip4_packet.h:131
static void bfd_rpc_update_session(u32 bs_idx, const bfd_pkt_t *pkt)
Definition: bfd_udp.c:384
u32 flags
Definition: vhost-user.h:75
bfd_session_t * bfd_get_session(bfd_main_t *bm, bfd_transport_t t)
Definition: bfd_main.c:743
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:85
bfd_udp_session_t udp
Definition: bfd_main.h:122
vlib buffer structure definition and a few select access methods.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
int bfd_verify_pkt_session(const bfd_pkt_t *pkt, u16 pkt_size, const bfd_session_t *bs)
verify bfd packet - authentication
Definition: bfd_main.c:848
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:238
Definition: defs.h:46
static bfd_udp_error_t bfd_udp6_scan(vlib_main_t *vm, vlib_buffer_t *b)
Definition: bfd_udp.c:460