FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
vrrp.c
Go to the documentation of this file.
1 /*
2  * vrrp.c - vrrp plugin action functions
3  *
4  * Copyright 2019-2020 Rubicon Communications, LLC (Netgate)
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  *
8  */
9 
10 #include <vnet/vnet.h>
11 #include <vnet/plugin/plugin.h>
12 #include <vnet/mfib/mfib_entry.h>
13 #include <vnet/mfib/mfib_table.h>
14 #include <vnet/adj/adj.h>
15 #include <vnet/adj/adj_mcast.h>
16 #include <vnet/fib/fib_table.h>
17 #include <vnet/ip/igmp_packet.h>
18 #include <vnet/ip/ip6_link.h>
19 
20 #include <vrrp/vrrp.h>
21 #include <vrrp/vrrp_packet.h>
22 
23 #include <vpp/app/version.h>
24 
26 
27 static const mac_address_t ipv4_vmac = {
28  .bytes = {0x00, 0x00, 0x5e, 0x00, 0x01, 0x00}
29 };
30 
31 static const mac_address_t ipv6_vmac = {
32  .bytes = {0x00, 0x00, 0x5e, 0x00, 0x02, 0x00}
33 };
34 
35 typedef struct
36 {
40 
41 typedef enum
42 {
47 
48 typedef struct
49 {
53  int intf_up;
55 
57  vrrp_intf_update_t * pending);
58 
59 static walk_rc_t
61 {
62  vrrp_hwif_vr_count_t *vr_count = arg;
63  vrrp_vr_t *vr;
64 
65  vr = vrrp_vr_lookup (sw_if_index, vr_count->key.vr_id,
66  vr_count->key.is_ipv6);
67 
68  if (vr && (vr->runtime.state == VRRP_VR_STATE_MASTER))
69  vr_count->count++;
70 
71  return WALK_CONTINUE;
72 }
73 
74 /*
75  * Get a count of VRs in master state on a given hardware interface with
76  * the provided VR ID and AF.
77  */
78 static u32
80 {
81  vnet_main_t *vnm = vnet_get_main ();
82  vrrp_hwif_vr_count_t vr_count;
83 
84  clib_memset (&vr_count, 0, sizeof (vr_count));
85 
86  vr_count.key.vr_id = vr_id;
87  vr_count.key.is_ipv6 = is_ipv6;
88 
89  vnet_hw_interface_walk_sw (vnm, hw_if_index,
90  vrrp_hwif_master_count_walk, &vr_count);
91 
92  return vr_count.count;
93 }
94 
95 /*
96  * Add or delete the VR virtual MAC address on the hardware interface
97  * when a VR enters or leaves the master state.
98  *
99  * Multiple subinterfaces may host the same VR ID. We should only add or
100  * delete the virtual MAC if this is the first VR being enabled on the
101  * hardware interface or the last one being disabled, respectively.
102  */
103 void
105 {
106  vnet_main_t *vnm = vnet_get_main ();
107  clib_error_t *error = 0;
109  u8 enable = (new_state == VRRP_VR_STATE_MASTER);
110  u32 n_master_vrs;
111 
113  n_master_vrs =
115  vrrp_vr_is_ipv6 (vr));
116 
117  /* enable only if current master vrs is 0, disable only if 0 or 1 */
118  if ((enable && !n_master_vrs) || (!enable && (n_master_vrs < 2)))
119  {
120  clib_warning ("%s virtual MAC address %U on hardware interface %u",
121  (enable) ? "Adding" : "Deleting",
123  hw->hw_if_index);
124 
126  (vnm, hw->hw_if_index, vr->runtime.mac.bytes, enable);
127  }
128 
129  if (error)
130  clib_error_report (error);
131 }
132 
133 /*
134  * Manage VR interface data on transition to/from master:
135  * - enable or disable ARP/ND input feature if appropriate
136  * - update count of VRs in master state
137  */
138 static void
140 {
141  vrrp_intf_t *intf;
142  const char *arc_name = 0, *node_name = 0;
143  u8 is_ipv6 = vrrp_vr_is_ipv6 (vr);
144 
145  /* only need to do something if entering or leaving master state */
146  if ((vr->runtime.state != VRRP_VR_STATE_MASTER) &&
147  (new_state != VRRP_VR_STATE_MASTER))
148  return;
149 
150  if (is_ipv6)
151  {
152  arc_name = "ip6-local";
153  node_name = "vrrp6-nd-input";
154  }
155  else
156  {
157  arc_name = "arp";
158  node_name = "vrrp4-arp-input";
159  }
160 
161  intf = vrrp_intf_get (vr->config.sw_if_index);
162  if (new_state == VRRP_VR_STATE_MASTER)
163  {
164  intf->n_master_vrs[is_ipv6]++;
165  if (intf->n_master_vrs[is_ipv6] == 1)
166  vnet_feature_enable_disable (arc_name, node_name,
167  vr->config.sw_if_index, 1, NULL, 0);
168  }
169  else
170  {
171  if (intf->n_master_vrs[is_ipv6] == 1)
172  vnet_feature_enable_disable (arc_name, node_name,
173  vr->config.sw_if_index, 0, NULL, 0);
174  /* If the count were already 0, leave it at 0 */
175  if (intf->n_master_vrs[is_ipv6])
176  intf->n_master_vrs[is_ipv6]--;
177  }
178 }
179 
180 /* If accept mode enabled, add/remove VR addresses from interface */
181 static void
183 {
185  u8 is_del;
186  ip46_address_t *vr_addr;
187 
188  if (!vrrp_vr_accept_mode_enabled (vr))
189  return;
190 
191  /* owner always has VR addresses configured, should never remove them */
192  if (vrrp_vr_is_owner (vr))
193  return;
194 
195  if (vrrp_vr_is_unicast (vr))
196  return;
197 
198  /* only need to do something if entering or leaving master state */
199  if ((vr->runtime.state != VRRP_VR_STATE_MASTER) &&
200  (new_state != VRRP_VR_STATE_MASTER))
201  return;
202 
203  is_del = (new_state != VRRP_VR_STATE_MASTER);
204 
205  clib_warning ("%s VR addresses on sw_if_index %u",
206  (is_del) ? "Deleting" : "Adding", vr->config.sw_if_index);
207 
208  vec_foreach (vr_addr, vr->config.vr_addrs)
209  {
210  ip_interface_address_t *ia = NULL;
211 
212  /* We need to know the address length to use, find it from another
213  * address on the interface. Or use a default (/24, /64).
214  */
215  if (!vrrp_vr_is_ipv6 (vr))
216  {
217  ip4_main_t *im = &ip4_main;
218  ip4_address_t *intf4;
219 
220  intf4 =
222  (im, &vr_addr->ip4, vr->config.sw_if_index, &ia);
223 
225  &vr_addr->ip4,
226  (intf4 ? ia->address_length : 24),
227  is_del);
228  }
229  else
230  {
231  ip6_main_t *im = &ip6_main;
232  ip6_address_t *intf6;
233 
234  intf6 =
236  (im, &vr_addr->ip6, vr->config.sw_if_index, &ia);
237 
239  &vr_addr->ip6,
240  (intf6 ? ia->address_length : 64),
241  is_del);
242  }
243  }
244 }
245 
246 void
248 {
249 
250  clib_warning ("VR %U transitioning to %U", format_vrrp_vr_key, vr,
251  format_vrrp_vr_state, new_state);
252 
253  /* Don't do anything if transitioning to the state VR is already in.
254  * This should never happen, just covering our bases.
255  */
256  if (new_state == vr->runtime.state)
257  return;
258 
259  if (new_state == VRRP_VR_STATE_MASTER)
260  {
261  /* RFC 5798 sec 6.4.1 (105) - startup event for VR with priority 255
262  * sec 6.4.2 (365) - master down timer fires on backup VR
263  */
264 
266  vrrp_adv_send (vr, 0);
268 
270  }
271  else if (new_state == VRRP_VR_STATE_BACKUP)
272  {
273  /* RFC 5798 sec 6.4.1 (150) - startup event for VR with priority < 255
274  * sec 6.4.3 (735) - master preempted by higher priority VR
275  */
276 
278 
279  if (vr->runtime.state == VRRP_VR_STATE_MASTER)
280  {
281  vrrp_header_t *pkt = data;
283 
284  }
285  else /* INIT, INTF_DOWN */
287 
291 
292  }
293  else if (new_state == VRRP_VR_STATE_INIT)
294  {
295  /* RFC 5798 sec 6.4.2 (345) - shutdown event for backup VR
296  * sec 6.4.3 (655) - shutdown event for master VR
297  */
298 
300  if (vr->runtime.state == VRRP_VR_STATE_MASTER)
301  vrrp_adv_send (vr, 1);
302  }
303  else if (new_state == VRRP_VR_STATE_INTF_DOWN)
304  /* State is not specified by RFC. This is to avoid attempting to
305  * send packets on an interface that's down and to avoid having a
306  * VR believe it is already the master when an interface is brought up
307  */
309 
310  /* add/delete virtual IP addrs if accept_mode is true */
311  vrrp_vr_transition_addrs (vr, new_state);
312 
313  /* enable/disable arp/ND input features if necessary */
314  vrrp_vr_transition_intf (vr, new_state);
315 
316  /* add/delete virtual MAC address on NIC if necessary */
317  vrrp_vr_transition_vmac (vr, new_state);
318 
319  vr->runtime.state = new_state;
320 }
321 
322 #define VRRP4_MCAST_ADDR_AS_U8 { 224, 0, 0, 18 }
323 #define VRRP6_MCAST_ADDR_AS_U8 \
324 { 0xff, 0x2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x12 }
325 
326 static const mfib_prefix_t all_vrrp4_routers = {
328  .fp_len = 32,
329  .fp_grp_addr = {
330  .ip4 = {
331  .as_u8 = VRRP4_MCAST_ADDR_AS_U8,
332  },
333  },
334 };
335 
336 static const mfib_prefix_t all_vrrp6_routers = {
338  .fp_len = 128,
339  .fp_grp_addr = {
340  .ip6 = {
341  .as_u8 = VRRP6_MCAST_ADDR_AS_U8,
342  },
343  },
344 };
345 
346 static int
348 {
349  vrrp_main_t *vrm = &vrrp_main;
350  vrrp_intf_t *intf;
351  u32 fib_index;
352  const mfib_prefix_t *vrrp_prefix;
354  vnet_link_t link_type;
355  fib_route_path_t for_us = {
356  .frp_sw_if_index = 0xffffffff,
357  .frp_weight = 1,
358  .frp_flags = FIB_ROUTE_PATH_LOCAL,
359  .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
360  };
361  fib_route_path_t via_itf = {
363  .frp_weight = 1,
364  .frp_mitf_flags = MFIB_ITF_FLAG_ACCEPT,
365  };
366 
367  intf = vrrp_intf_get (sw_if_index);
368 
369  if (is_ipv6)
370  {
371  proto = FIB_PROTOCOL_IP6;
372  link_type = VNET_LINK_IP6;
373  vrrp_prefix = &all_vrrp6_routers;
374  }
375  else
376  {
377  proto = FIB_PROTOCOL_IP4;
378  link_type = VNET_LINK_IP4;
379  vrrp_prefix = &all_vrrp4_routers;
380  }
381 
382  for_us.frp_proto = fib_proto_to_dpo (proto);
383  via_itf.frp_proto = fib_proto_to_dpo (proto);
384  fib_index = mfib_table_get_index_for_sw_if_index (proto, sw_if_index);
385 
386  if (enable)
387  {
388  if (pool_elts (vrm->vrs) == 1)
389  mfib_table_entry_path_update (fib_index, vrrp_prefix, MFIB_SOURCE_API,
390  &for_us);
391 
392  mfib_table_entry_path_update (fib_index, vrrp_prefix, MFIB_SOURCE_API,
393  &via_itf);
394  intf->mcast_adj_index[! !is_ipv6] =
395  adj_mcast_add_or_lock (proto, link_type, sw_if_index);
396  }
397  else
398  {
399  if (pool_elts (vrm->vrs) == 0)
400  mfib_table_entry_path_remove (fib_index, vrrp_prefix, MFIB_SOURCE_API,
401  &for_us);
402 
403  mfib_table_entry_path_remove (fib_index, vrrp_prefix, MFIB_SOURCE_API,
404  &via_itf);
405  }
406 
407  return 0;
408 }
409 
410 static int
412 {
413  vrrp_intf_t *vr_intf;
414 
415  vr_intf = vrrp_intf_get (sw_if_index);
416  if (!vr_intf)
417  return -1;
418 
419  if (is_add)
420  {
421  if (!vec_len (vr_intf->vr_indices[is_ipv6]))
422  vrrp_intf_enable_disable_mcast (1, sw_if_index, is_ipv6);
423 
424  vec_add1 (vr_intf->vr_indices[is_ipv6], vr_index);
425  }
426  else
427  {
428  u32 per_intf_index =
429  vec_search (vr_intf->vr_indices[is_ipv6], vr_index);
430 
431  if (per_intf_index != ~0)
432  vec_del1 (vr_intf->vr_indices[is_ipv6], per_intf_index);
433 
434  /* no more VRs on this interface, disable multicast */
435  if (!vec_len (vr_intf->vr_indices[is_ipv6]))
436  vrrp_intf_enable_disable_mcast (0, sw_if_index, is_ipv6);
437  }
438 
439  return 0;
440 }
441 
442 /* RFC 5798 section 8.3.2 says to take care not to configure more than
443  * one VRRP router as the "IPvX address owner" of a VRID. Make sure that
444  * all of the addresses configured for this VR are configured on the
445  * interface.
446  */
447 static int
449 {
450  ip46_address_t *addr;
451  u8 is_ipv6 = (vr_conf->flags & VRRP_VR_IPV6) != 0;
452 
453  vec_foreach (addr, vr_conf->vr_addrs)
454  {
455  if (!ip_interface_has_address (vr_conf->sw_if_index, addr, !is_ipv6))
456  return VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE;
457  }
458 
459  return 0;
460 }
461 
462 static int
464 {
465  ip46_address_t *vr_addr;
466  u8 is_ipv6 = (vr_conf->flags & VRRP_VR_IPV6) != 0;
467 
468  vec_foreach (vr_addr, vr_conf->vr_addrs)
469  {
470  u32 vr_index;
471  void *addr;
472 
473  addr = (is_ipv6) ? (void *) &vr_addr->ip6 : (void *) &vr_addr->ip4;
474  vr_index = vrrp_vr_lookup_address (vr_conf->sw_if_index, is_ipv6, addr);
475  if (vr_index != ~0)
476  return VNET_API_ERROR_ADDRESS_IN_USE;
477  }
478 
479  return 0;
480 }
481 
482 static int
484 {
485  int ret = 0;
486 
487  /* If the VR owns the addresses, make sure they are configured */
488  if (vr_conf->priority == 255 &&
489  (ret = vrrp_vr_valid_addrs_owner (vr_conf)) < 0)
490  return ret;
491 
492  /* make sure no other VR has already configured any of the VR addresses */
493  ret = vrrp_vr_valid_addrs_unused (vr_conf);
494 
495  return ret;
496 }
497 
498 int
499 vrrp_vr_addr_add_del (vrrp_vr_t * vr, u8 is_add, ip46_address_t * vr_addr)
500 {
501  vrrp_main_t *vmp = &vrrp_main;
502  u32 vr_index;
503  vrrp4_arp_key_t key4;
504  vrrp6_nd_key_t key6;
505  ip46_address_t *addr;
506 
507  if (!vr || !vr_addr)
508  return VNET_API_ERROR_INVALID_ARGUMENT;
509 
510  vr_index = vr - vmp->vrs;
511 
512  if (vrrp_vr_is_ipv6 (vr))
513  {
514  key6.sw_if_index = vr->config.sw_if_index;
515  key6.addr = vr_addr->ip6;
516  if (is_add)
517  {
518  hash_set_mem_alloc (&vmp->vrrp6_nd_lookup, &key6, vr_index);
519  vec_add1 (vr->config.vr_addrs, vr_addr[0]);
520  }
521  else
522  {
523  hash_unset_mem_free (&vmp->vrrp6_nd_lookup, &key6);
524  vec_foreach (addr, vr->config.vr_addrs)
525  {
526  if (!ip46_address_cmp (addr, vr_addr))
527  {
528  vec_del1 (vr->config.vr_addrs, vr->config.vr_addrs - addr);
529  break;
530  }
531  }
532  }
533  }
534  else
535  {
536  key4.sw_if_index = vr->config.sw_if_index;
537  key4.addr = vr_addr->ip4;
538  if (is_add)
539  {
540  hash_set (vmp->vrrp4_arp_lookup, key4.as_u64, vr_index);
541  vec_add1 (vr->config.vr_addrs, vr_addr[0]);
542  }
543  else
544  {
545  hash_unset (vmp->vrrp4_arp_lookup, key4.as_u64);
546  vec_foreach (addr, vr->config.vr_addrs)
547  {
548  if (!ip46_address_cmp (addr, vr_addr))
549  {
550  vec_del1 (vr->config.vr_addrs, vr->config.vr_addrs - addr);
551  break;
552  }
553  }
554  }
555  }
556 
557  return 0;
558 }
559 
560 static void
561 vrrp_vr_addrs_add_del (vrrp_vr_t * vr, u8 is_add, ip46_address_t * vr_addrs)
562 {
563  ip46_address_t *vr_addr;
564 
565  vec_foreach (vr_addr, vr_addrs)
566  {
567  vrrp_vr_addr_add_del (vr, is_add, vr_addr);
568  }
569 }
570 
571 /* Action function shared between message handler and debug CLI */
572 int
574 {
575  vrrp_main_t *vrm = &vrrp_main;
576  vnet_main_t *vnm = vnet_get_main ();
578  uword *p;
579  u32 vr_index;
580  vrrp_vr_t *vr = 0;
581  int ret;
582 
583  if (vr_conf->sw_if_index == ~0 ||
584  !vnet_sw_interface_is_valid (vnm, vr_conf->sw_if_index))
585  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
586 
587  clib_memset (&key, 0, sizeof (key));
588 
589  key.sw_if_index = vr_conf->sw_if_index;
590  key.vr_id = vr_conf->vr_id;
591  key.is_ipv6 = ((vr_conf->flags & VRRP_VR_IPV6) != 0);
592 
593  p = mhash_get (&vrm->vr_index_by_key, &key);
594 
595  if (is_add)
596  {
597  /* does a VR matching this key already exist ? */
598  if (p)
599  {
600  clib_warning ("VR %u for IPv%d already exists on sw_if_index %u",
601  key.vr_id, (key.is_ipv6) ? 6 : 4, key.sw_if_index);
602  return VNET_API_ERROR_ENTRY_ALREADY_EXISTS;
603  }
604 
605  /* were IPvX addresses included ? */
606  if (!vec_len (vr_conf->vr_addrs))
607  {
608  clib_warning ("Conf of VR %u for IPv%d on sw_if_index %u "
609  " does not contain IP addresses",
610  key.vr_id, (key.is_ipv6) ? 6 : 4, key.sw_if_index);
611  return VNET_API_ERROR_INVALID_SRC_ADDRESS;
612  }
613 
614  /* Make sure the addresses are ok to use */
615  if ((ret = vrrp_vr_valid_addrs (vr_conf)) < 0)
616  return ret;
617 
618  pool_get_zero (vrm->vrs, vr);
619  vr_index = vr - vrm->vrs;
620 
621  clib_memcpy (&vr->config, vr_conf, sizeof (vrrp_vr_config_t));
622 
623  vr->config.vr_addrs = 0; /* allocate our own memory */
624  vrrp_vr_addrs_add_del (vr, is_add, vr_conf->vr_addrs);
625 
626  vr->runtime.state = VRRP_VR_STATE_INIT;
627  vr->runtime.timer_index = ~0;
628 
629  /* set virtual MAC based on IP version and VR ID */
630  vr->runtime.mac = (key.is_ipv6) ? ipv6_vmac : ipv4_vmac;
631  vr->runtime.mac.bytes[5] = vr_conf->vr_id;
632 
633  mhash_set (&vrm->vr_index_by_key, &key, vr_index, 0);
634  }
635  else
636  {
637  if (!p)
638  {
639  clib_warning ("No VR %u for IPv%d exists on sw_if_index %u",
640  key.vr_id, (key.is_ipv6) ? 6 : 4, key.sw_if_index);
641  return VNET_API_ERROR_NO_SUCH_ENTRY;
642  }
643 
644  vr_index = p[0];
645  vr = pool_elt_at_index (vrm->vrs, vr_index);
646 
648  vrrp_vr_addrs_add_del (vr, is_add, vr->config.vr_addrs);
649  mhash_unset (&vrm->vr_index_by_key, &key, 0);
650  vec_free (vr->config.vr_addrs);
652  pool_put (vrm->vrs, vr);
653  }
654 
655  vrrp_intf_vr_add_del (is_add, vr_conf->sw_if_index, vr_index, key.is_ipv6);
656 
657  return 0;
658 }
659 
660 int
661 vrrp_vr_start_stop (u8 is_start, vrrp_vr_key_t * vr_key)
662 {
663  vrrp_main_t *vmp = &vrrp_main;
664  uword *p;
665  vrrp_vr_t *vr = 0;
666 
667  p = mhash_get (&vmp->vr_index_by_key, vr_key);
668  if (!p)
669  return VNET_API_ERROR_NO_SUCH_ENTRY;
670 
671  vr = pool_elt_at_index (vmp->vrs, p[0]);
672 
673  /* return success if already in the desired state */
674  switch (vr->runtime.state)
675  {
676  case VRRP_VR_STATE_INIT:
677  if (!is_start)
678  {
679  clib_warning ("Attempting to stop already stopped VR (%U)",
680  format_vrrp_vr_key, vr);
681  return 0;
682  }
683  break;
684  default:
685  if (is_start)
686  {
687  clib_warning ("Attempting to start already started VR (%U)",
688  format_vrrp_vr_key, vr);
689  return 0;
690  }
691  break;
692  }
693 
694  if (is_start)
695  {
696  if (vrrp_vr_is_unicast (vr) && vec_len (vr->config.peer_addrs) == 0)
697  {
698  clib_warning ("Cannot start unicast VR without peers");
699  return VNET_API_ERROR_INIT_FAILED;
700  }
701 
702  vmp->n_vrs_started++;
703 
705  NULL))
706  {
707  clib_warning ("VRRP VR started on down interface (%U)",
708  format_vrrp_vr_key, vr);
709  vrrp_vr_transition (vr, VRRP_VR_STATE_INTF_DOWN, NULL);
710  }
711  else if (vrrp_vr_is_owner (vr))
712  vrrp_vr_transition (vr, VRRP_VR_STATE_MASTER, NULL);
713  else
714  vrrp_vr_transition (vr, VRRP_VR_STATE_BACKUP, NULL);
715  }
716  else
717  {
718  vmp->n_vrs_started--;
719 
720  vrrp_vr_transition (vr, VRRP_VR_STATE_INIT, NULL);
721  }
722 
723  clib_warning ("%d VRs configured, %d VRs running",
724  pool_elts (vmp->vrs), vmp->n_vrs_started);
725 
726  return 0;
727 }
728 
729 static int
730 vrrp_vr_set_peers_validate (vrrp_vr_t * vr, ip46_address_t * peers)
731 {
732  if (!vrrp_vr_is_unicast (vr))
733  {
734  clib_warning ("Peers can only be set on a unicast VR");
735  return VNET_API_ERROR_INVALID_ARGUMENT;
736  }
737 
738  if (vr->runtime.state != VRRP_VR_STATE_INIT)
739  {
740  clib_warning ("Cannot set peers on a running VR");
741  return VNET_API_ERROR_RSRC_IN_USE;
742  }
743 
744  if (vec_len (peers) == 0)
745  {
746  clib_warning ("No peer addresses provided");
747  return VNET_API_ERROR_INVALID_DST_ADDRESS;
748  }
749 
750  return 0;
751 }
752 
753 int
754 vrrp_vr_set_peers (vrrp_vr_key_t * vr_key, ip46_address_t * peers)
755 {
756  vrrp_main_t *vmp = &vrrp_main;
757  uword *p;
758  vrrp_vr_t *vr = 0;
759  int ret = 0;
760 
761  p = mhash_get (&vmp->vr_index_by_key, vr_key);
762  if (!p)
763  return VNET_API_ERROR_NO_SUCH_ENTRY;
764 
765  vr = pool_elt_at_index (vmp->vrs, p[0]);
766 
767  ret = vrrp_vr_set_peers_validate (vr, peers);
768  if (ret < 0)
769  return ret;
770 
771  if (vr->config.peer_addrs)
772  vec_free (vr->config.peer_addrs);
773 
774  vr->config.peer_addrs = vec_dup (peers);
775 
776  return 0;
777 }
778 
779 /* Manage reference on the interface to the VRs which track that interface */
780 static void
782 {
783  vrrp_intf_t *intf;
784  u32 vr_index;
785  u8 is_ipv6 = vrrp_vr_is_ipv6 (vr);
786  int i;
787 
788  intf = vrrp_intf_get (sw_if_index);
789  vr_index = vrrp_vr_index (vr);
790 
791  /* Try to find the VR index in the list of tracking VRs */
792  vec_foreach_index (i, intf->tracking_vrs[is_ipv6])
793  {
794  if (vec_elt (intf->tracking_vrs[is_ipv6], i) != vr_index)
795  continue;
796 
797  /* Current index matches VR index */
798  if (!is_add)
799  vec_delete (intf->tracking_vrs[is_ipv6], 1, i);
800 
801  /* If deleting, the job is done. If adding, it's already here */
802  return;
803  }
804 
805  /* vr index was not found. */
806  if (is_add)
807  vec_add1 (intf->tracking_vrs[is_ipv6], vr_index);
808 }
809 
810 /* Check if sw intf admin state is up or in the process of coming up */
811 static int
813 {
814  vnet_main_t *vnm = vnet_get_main ();
815  int admin_up;
816 
817  if (pending && (pending->type == VRRP_IF_UPDATE_SW_ADMIN))
818  admin_up = pending->intf_up;
819  else
820  admin_up = vnet_sw_interface_is_admin_up (vnm, sw_if_index);
821 
822  return admin_up;
823 }
824 
825 /* Check if hw intf link state is up or int the process of coming up */
826 static int
828 {
829  vnet_main_t *vnm = vnet_get_main ();
830  vnet_sw_interface_t *sup_sw;
831  int link_up;
832 
833  sup_sw = vnet_get_sup_sw_interface (vnm, sw_if_index);
834 
835  if (pending && (pending->type == VRRP_IF_UPDATE_HW_LINK) &&
836  (pending->hw_if_index == sup_sw->hw_if_index))
837  link_up = pending->intf_up;
838  else
839  link_up = vnet_hw_interface_is_link_up (vnm, sup_sw->hw_if_index);
840 
841  return link_up;
842 }
843 
844 /* Check if interface has ability to send IP packets. */
845 static int
847 {
848  int ip_up;
849 
850  if (pending && pending->type == VRRP_IF_UPDATE_IP)
851  ip_up = pending->intf_up;
852  else
853  /* Either a unicast address has to be explicitly assigned, or
854  * for IPv6 only, a link local assigned and multicast/ND enabled
855  */
856  ip_up =
857  ((ip_interface_get_first_ip (sw_if_index, !is_ipv6) != 0) ||
858  (is_ipv6 && ip6_link_is_enabled (sw_if_index)));
859 
860  return ip_up;
861 }
862 
863 static int
865 {
866  int admin_up, link_up, ip_up;
867 
868  admin_up = vrrp_intf_sw_admin_up (sw_if_index, pending);
869  link_up = vrrp_intf_hw_link_up (sw_if_index, pending);
870  ip_up = vrrp_intf_ip_up (sw_if_index, is_ipv6, pending);
871 
872  return (admin_up && link_up && ip_up);
873 }
874 
875 /* Examine the state of interfaces tracked by a VR and compute the priority
876  * adjustment that should be applied to the VR. If this is being called
877  * by the hw_link_up_down callback, the pending new flags on the sup hw
878  * interface have not been updated yet, so accept those as an optional
879  * argument.
880  */
881 void
883 {
884  vrrp_vr_tracking_if_t *intf;
885  u32 total_priority = 0;
886 
887  vec_foreach (intf, vr->tracking.interfaces)
888  {
889  if (vrrp_intf_is_up (intf->sw_if_index, vrrp_vr_is_ipv6 (vr), pending))
890  continue;
891 
892  total_priority += intf->priority;
893  }
894 
895  if (total_priority != vr->tracking.interfaces_dec)
896  {
897  clib_warning ("VR %U interface track adjustment change from %u to %u",
899  total_priority);
900  vr->tracking.interfaces_dec = total_priority;
901  }
902 }
903 
904 /* Manage tracked interfaces on a VR */
905 int
907  u8 is_add)
908 {
909  vnet_main_t *vnm = vnet_get_main ();
910  vrrp_vr_tracking_if_t *track_intf;
911 
912  /* VR can't track non-existent interface */
913  if (!vnet_sw_interface_is_valid (vnm, sw_if_index))
914  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
915 
916  /* VR can't track it's own interface */
917  if (sw_if_index == vr->config.sw_if_index)
918  return VNET_API_ERROR_INVALID_SW_IF_INDEX_2;
919 
920  /* update intf vector of tracking VRs */
921  vrrp_intf_tracking_vr_add_del (sw_if_index, vr, is_add);
922 
923  /* update VR vector of tracked interfaces */
924  vec_foreach (track_intf, vr->tracking.interfaces)
925  {
926  if (track_intf->sw_if_index != sw_if_index)
927  continue;
928 
929  /* found it */
930  if (!is_add)
931  vec_delete
932  (vr->tracking.interfaces, 1, track_intf - vr->tracking.interfaces);
933 
934  return 0;
935  }
936 
937  if (is_add)
938  {
939  vec_add2 (vr->tracking.interfaces, track_intf, 1);
940 
941  track_intf->sw_if_index = sw_if_index;
942  track_intf->priority = prio;
943  }
944 
945  return 0;
946 }
947 
948 int
950  vrrp_vr_tracking_if_t * track_ifs, u8 is_add)
951 {
952  vrrp_vr_tracking_if_t *track_if, *ifs_copy;
953  int rv = 0;
954 
955  /* if deleting & track_ifs points to the VR list of tracked intfs, the
956  * vector could be modified as we iterate it. make a copy instead */
957  ifs_copy = vec_dup (track_ifs);
958 
959  /* add each tracked interface in the vector */
960  vec_foreach (track_if, ifs_copy)
961  {
962  rv = vrrp_vr_tracking_if_add_del (vr, track_if->sw_if_index,
963  track_if->priority, (is_add != 0));
964 
965  /* if operation failed, undo the previous changes */
966  if (rv)
967  {
968  vrrp_vr_tracking_if_t *rb_if;
969 
970  for (rb_if = track_if - 1; rb_if >= track_ifs; rb_if -= 1)
972  rb_if->priority, !(is_add != 0));
973  break;
974  }
975  }
976 
977  vec_free (ifs_copy);
978 
980 
981  return rv;
982 }
983 
984 /* Compute priority to advertise on all VRs which track the given interface
985  * and address family. The flags on an HW interface are not updated until
986  * after link up/down callbacks are invoked, so if this function is called
987  * by the link up/down callback, the flags about to be set will be passed
988  * via the 'pending' argument. Otherwise, pending will be NULL.
989  */
990 static void
992  vrrp_intf_update_t * pending, u8 is_ipv6)
993 {
994  u32 *vr_index;
995  vrrp_vr_t *vr;
996  vrrp_intf_t *intf = vrrp_intf_get (sw_if_index);
997 
998  vec_foreach (vr_index, intf->tracking_vrs[is_ipv6])
999  {
1000  vr = vrrp_vr_lookup_index (*vr_index);
1001  if (vr)
1002  vrrp_vr_tracking_ifs_compute (vr, pending);
1003  }
1004 }
1005 
1006 /* Interface being brought up/down is a quasi-{startup/shutdown} event.
1007  * Execute an appropriate state transition for all VRs on the interface.
1008  * This function may be invoked by:
1009  * sw interface admin up/down event
1010  * hw interface link up/down event
1011  */
1012 clib_error_t *
1014 {
1015  vrrp_intf_t *intf;
1016  int i;
1017  u32 *vr_index;
1018  vrrp_vr_t *vr;
1019 
1020  intf = vrrp_intf_get (pending->sw_if_index);
1021  if (!intf)
1022  return 0;
1023 
1024  /* adjust state of VR's configured on this interface */
1025  for (i = 0; i < 2; i++)
1026  {
1027  int is_up;
1028 
1029  if (!intf->vr_indices[i])
1030  continue;
1031 
1032  is_up = vrrp_intf_is_up (pending->sw_if_index, i, pending);
1033 
1034  vec_foreach (vr_index, intf->vr_indices[i])
1035  {
1036  vrrp_vr_state_t vr_state;
1037 
1038  vr = vrrp_vr_lookup_index (*vr_index);
1039  if (!vr)
1040  continue;
1041 
1042  if (vr->runtime.state == VRRP_VR_STATE_INIT)
1043  continue; /* VR not started yet, no transition */
1044 
1045  if (!is_up)
1046  vr_state = VRRP_VR_STATE_INTF_DOWN;
1047  else
1048  {
1049  if (vr->runtime.state != VRRP_VR_STATE_INTF_DOWN)
1050  continue; /* shouldn't happen */
1051 
1052  vr_state = (vrrp_vr_is_owner (vr)) ?
1053  VRRP_VR_STATE_MASTER : VRRP_VR_STATE_BACKUP;
1054  }
1055 
1056  vrrp_vr_transition (vr, vr_state, NULL);
1057  }
1058  }
1059 
1060  /* compute adjustments on any VR's tracking this interface */
1061  vrrp_intf_tracking_vrs_compute (pending->sw_if_index, pending,
1062  0 /* is_ipv6 */ );
1063  vrrp_intf_tracking_vrs_compute (pending->sw_if_index, pending,
1064  1 /* is_ipv6 */ );
1065 
1066  return 0;
1067 }
1068 
1069 /* Process change in admin status on an interface */
1070 clib_error_t *
1072  u32 flags)
1073 {
1074  vrrp_intf_update_t pending = {
1076  .sw_if_index = sw_if_index,
1077  .intf_up = ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0),
1078  };
1079 
1080  return vrrp_sw_interface_up_down (&pending);
1081 }
1082 
1084 
1085 static walk_rc_t
1087  u32 sw_if_index, void *arg)
1088 {
1089  vrrp_intf_update_t *pending = arg;
1090 
1091  pending->sw_if_index = sw_if_index;
1092  vrrp_sw_interface_up_down (pending);
1093 
1094  return WALK_CONTINUE;
1095 }
1096 
1097 static clib_error_t *
1099 {
1100  vrrp_intf_update_t pending = {
1102  .hw_if_index = hw_if_index,
1103  .intf_up = ((flags & VNET_HW_INTERFACE_FLAG_LINK_UP) != 0),
1104  };
1105 
1106  /* walk the sw interface and sub interfaces to adjust interface tracking */
1107  vnet_hw_interface_walk_sw (vnm, hw_if_index,
1109 
1110  return 0;
1111 }
1112 
1114 
1115 static void
1117  uword opaque,
1118  u32 sw_if_index,
1120  u32 address_length,
1121  u32 if_address_index, u32 is_del)
1122 {
1123  vrrp_intf_tracking_vrs_compute (sw_if_index, NULL, 0 /* is_ipv6 */ );
1124 }
1125 
1127 
1128 static u8 *
1129 format_vrrp_ip6_link (u8 * s, va_list * args)
1130 {
1131  index_t indi = va_arg (*args, index_t);
1132  u32 indent = va_arg (*args, u32);
1133  vrrp_intf_t *intf;
1134  u32 *vr_index;
1135 
1136  intf = vrrp_intf_get ((u32) indi);
1137 
1138  s = format (s, "%UVRRP VRs monitoring this link:\n",
1139  format_white_space, indent);
1140 
1141  vec_foreach (vr_index, intf->tracking_vrs[1])
1142  {
1143  vrrp_vr_t *vr = vrrp_vr_lookup_index (*vr_index);
1144 
1145  s = format (s, "%U%U\n", format_white_space, indent + 2,
1146  format_vrrp_vr_key, vr);
1147  }
1148 
1149  return s;
1150 }
1151 
1152 static void
1154 {
1155  vrrp_intf_update_t pending = {
1157  .sw_if_index = sw_if_index,
1158  .intf_up = enable,
1159  };
1160 
1161  vrrp_intf_tracking_vrs_compute (sw_if_index, &pending, 1 /* is_ipv6 */ );
1162 }
1163 
1164 static void
1166 {
1167  vrrp_intf_ip6_enable_disable (sw_if_index, 1 /* enable */ );
1168  ip6_link_delegate_update (sw_if_index, vrrp_ip6_delegate_id, sw_if_index);
1169 }
1170 
1171 static void
1173 {
1174  vrrp_intf_ip6_enable_disable (indi, 0 /* enable */ );
1175 }
1176 
1177 const static ip6_link_delegate_vft_t vrrp_ip6_delegate_vft = {
1179  .ildv_disable = vrrp_intf_ip6_disable,
1180  .ildv_format = format_vrrp_ip6_link,
1181 };
1182 
1183 static clib_error_t *
1185 {
1186  vrrp_main_t *vmp = &vrrp_main;
1187  clib_error_t *error = 0;
1188  ip4_main_t *im4 = &ip4_main;
1190  vlib_node_t *intf_output_node;
1191 
1192  clib_memset (vmp, 0, sizeof (*vmp));
1193 
1194  if ((error = vlib_call_init_function (vm, ip4_lookup_init)) ||
1195  (error = vlib_call_init_function (vm, ip6_lookup_init)))
1196  return error;
1197 
1198  vmp->vlib_main = vm;
1199  vmp->vnet_main = vnet_get_main ();
1200 
1201  intf_output_node = vlib_get_node_by_name (vm, (u8 *) "interface-output");
1202  vmp->intf_output_node_idx = intf_output_node->index;
1203 
1204  error = vrrp_plugin_api_hookup (vm);
1205 
1206  if (error)
1207  return error;
1208 
1209  mhash_init (&vmp->vr_index_by_key, sizeof (u32), sizeof (vrrp_vr_key_t));
1210  vmp->vrrp4_arp_lookup = hash_create (0, sizeof (uword));
1211  vmp->vrrp6_nd_lookup = hash_create_mem (0, sizeof (vrrp6_nd_key_t),
1212  sizeof (uword));
1213 
1215  cb4.function_opaque = 0;
1217 
1218  vrrp_ip6_delegate_id = ip6_link_delegate_register (&vrrp_ip6_delegate_vft);
1219 
1220  return error;
1221 }
1222 
1224 
1225 
1226 /* *INDENT-OFF* */
1228 {
1229  .version = VPP_BUILD_VER,
1230  .description = "VRRP v3 (RFC 5798)",
1231 };
1232 /* *INDENT-ON* */
1233 
1234 /*
1235  * fd.io coding-style-patch-verification: ON
1236  *
1237  * Local Variables:
1238  * eval: (c-set-style "gnu")
1239  * End:
1240  */
static u8 * format_vrrp_ip6_link(u8 *s, va_list *args)
Definition: vrrp.c:1129
u8 ip_interface_has_address(u32 sw_if_index, ip46_address_t *ip, u8 is_ip4)
Definition: ip_interface.c:140
u32 timer_index
Definition: vrrp.h:102
static int vrrp_vr_valid_addrs(vrrp_vr_config_t *vr_conf)
Definition: vrrp.c:483
u8 n_master_vrs[2]
Definition: vrrp.h:141
u8 * format_vrrp_vr_state(u8 *s, va_list *args)
Definition: vrrp_format.c:47
#define vec_foreach_index(var, v)
Iterate over vector indices.
u8 vr_id
Definition: vrrp.h:32
static u8 vrrp_vr_is_unicast(vrrp_vr_t *vr)
Definition: vrrp.h:315
clib_error_t * vrrp_sw_interface_up_down(vrrp_intf_update_t *pending)
Definition: vrrp.c:1013
#define hash_set(h, key, value)
Definition: hash.h:255
static void vrrp_vr_transition_addrs(vrrp_vr_t *vr, vrrp_vr_state_t new_state)
Definition: vrrp.c:182
u32 sw_if_index
Definition: vrrp.h:71
static u32 vrrp_vr_index(vrrp_vr_t *vr)
Definition: vrrp.h:345
ip4_add_del_interface_address_callback_t * add_del_interface_address_callbacks
Functions to call when interface address changes.
Definition: ip4.h:140
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(vrrp_sw_interface_admin_up_down)
vrrp_vr_tracking_t tracking
Definition: vrrp.h:110
#define hash_unset(h, key)
Definition: hash.h:261
int vrrp_vr_start_stop(u8 is_start, vrrp_vr_key_t *vr_key)
Definition: vrrp.c:661
A representation of a path as described by a route producer.
Definition: fib_types.h:490
static clib_error_t * vrrp_init(vlib_main_t *vm)
Definition: vrrp.c:1184
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
static clib_error_t * ip4_lookup_init(vlib_main_t *vm)
Definition: ip4_forward.c:1148
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:255
#define VRRP4_MCAST_ADDR_AS_U8
Definition: vrrp.c:322
Definition: vrrp.h:106
adj_index_t mcast_adj_index[2]
Definition: vrrp.h:138
VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION(vrrp_hw_interface_link_up_down)
fib_node_index_t mfib_table_entry_path_update(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, const fib_route_path_t *rpath)
Add n paths to an entry (aka route) in the FIB.
Definition: mfib_table.c:325
static const mfib_prefix_t all_vrrp6_routers
Definition: vrrp.c:336
void * ip_interface_get_first_ip(u32 sw_if_index, u8 is_ip4)
Definition: ip_interface.c:174
void vrrp_vr_transition_vmac(vrrp_vr_t *vr, vrrp_vr_state_t new_state)
Definition: vrrp.c:104
void vnet_hw_interface_walk_sw(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_sw_interface_walk_t fn, void *ctx)
Walk the SW interfaces on a HW interface - this is the super interface and any sub-interfaces.
Definition: interface.c:1049
uword mhash_unset(mhash_t *h, void *key, uword *old_value)
Definition: mhash.c:346
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:282
u8 vr_id
Definition: vrrp.api:17
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:590
vrrp_vr_t * vrs
Definition: vrrp.h:151
static int vrrp_intf_sw_admin_up(u32 sw_if_index, vrrp_intf_update_t *pending)
Definition: vrrp.c:812
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:628
int vrrp_vr_set_peers(vrrp_vr_key_t *vr_key, ip46_address_t *peers)
Definition: vrrp.c:754
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
dpo_proto_t frp_proto
The protocol of the address below.
Definition: fib_types.h:495
vrrp_vr_state_t state
Definition: vrrp.h:96
void vrrp_vr_tracking_ifs_compute(vrrp_vr_t *vr, vrrp_intf_update_t *pending)
Definition: vrrp.c:882
static int vrrp_intf_is_up(u32 sw_if_index, u8 is_ipv6, vrrp_intf_update_t *pending)
Definition: vrrp.c:864
static int vrrp_intf_hw_link_up(u32 sw_if_index, vrrp_intf_update_t *pending)
Definition: vrrp.c:827
vhost_vring_addr_t addr
Definition: vhost_user.h:254
static u16 vrrp_adv_int_from_packet(vrrp_header_t *pkt)
Definition: vrrp_packet.h:45
unsigned char u8
Definition: types.h:56
static vrrp_vr_t * vrrp_vr_lookup_index(u32 vr_index)
Definition: vrrp.h:248
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
u32 * tracking_vrs[2]
Definition: vrrp.h:135
#define clib_memcpy(d, s, n)
Definition: string.h:180
enum walk_rc_t_ walk_rc_t
Walk return code.
u32 hw_if_index
Definition: vrrp.c:52
static const u8 vrrp_prefix[]
Definition: arp.c:64
uword * vrrp6_nd_lookup
Definition: vrrp.h:165
u16 master_adv_int
Definition: vrrp.h:97
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
u32 frp_sw_if_index
The interface.
Definition: fib_types.h:530
vl_api_interface_index_t sw_if_index
Definition: gre.api:53
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
u32 mfib_table_get_index_for_sw_if_index(fib_protocol_t proto, u32 sw_if_index)
Get the index of the FIB bound to the interface.
Definition: mfib_table.c:527
static int ip46_address_cmp(const ip46_address_t *ip46_1, const ip46_address_t *ip46_2)
Definition: ip46_address.h:80
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
vrrp_vr_config_t config
Definition: vrrp.h:108
static void vrrp_intf_ip6_enable_disable(u32 sw_if_index, int enable)
Definition: vrrp.c:1153
static void vrrp_vr_transition_intf(vrrp_vr_t *vr, vrrp_vr_state_t new_state)
Definition: vrrp.c:139
static vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
static int vrrp_intf_vr_add_del(u8 is_add, u32 sw_if_index, u32 vr_index, u8 is_ipv6)
Definition: vrrp.c:411
static u8 vrrp_vr_is_owner(vrrp_vr_t *vr)
Definition: vrrp.h:321
unsigned int u32
Definition: types.h:88
#define vec_search(v, E)
Search a vector for the index of the entry that matches.
Definition: vec.h:1010
#define vlib_call_init_function(vm, x)
Definition: init.h:270
static uword vnet_sw_interface_is_valid(vnet_main_t *vnm, u32 sw_if_index)
static u8 vrrp_vr_accept_mode_enabled(vrrp_vr_t *vr)
Definition: vrrp.h:339
mac_address_t mac
Definition: vrrp.h:100
mhash_t vr_index_by_key
Definition: vrrp.h:161
u16 n_vrs_started
Definition: vrrp.h:158
clib_error_t * ip4_add_del_interface_address(vlib_main_t *vm, u32 sw_if_index, ip4_address_t *address, u32 address_length, u32 is_del)
Definition: ip4_forward.c:872
static void vrrp_intf_tracking_vrs_compute(u32 sw_if_index, vrrp_intf_update_t *pending, u8 is_ipv6)
Definition: vrrp.c:991
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:661
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
u8 * format_vrrp_vr_key(u8 *s, va_list *args)
Definition: vrrp_format.c:65
u8 priority
Definition: vrrp.h:73
vl_api_ip_proto_t proto
Definition: acl_types.api:50
u32 sw_if_index
Definition: vrrp.h:31
vrrp_vr_flags_t flags
Definition: vrrp.h:75
VLIB_PLUGIN_REGISTER()
static walk_rc_t vrrp_hwif_master_count_walk(vnet_main_t *vnm, u32 sw_if_index, void *arg)
Definition: vrrp.c:60
int vrrp_garp_or_na_send(vrrp_vr_t *vr)
Definition: vrrp_packet.c:459
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:302
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:427
u8 vr_id
Definition: vrrp.h:72
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:873
vrrp_vr_runtime_t runtime
Definition: vrrp.h:109
ip6_main_t ip6_main
Definition: ip6_forward.c:2784
static void vrrp_vr_master_down_compute(vrrp_vr_t *vr)
Definition: vrrp.h:222
vrrp_intf_update_type_t
Definition: vrrp.c:41
static uword mhash_set(mhash_t *h, void *key, uword new_value, uword *old_value)
Definition: mhash.h:117
vlib_main_t * vm
Definition: in2out_ed.c:1599
static u8 vrrp_vr_is_ipv6(vrrp_vr_t *vr)
Definition: vrrp.h:309
int vrrp_vr_multicast_group_join(vrrp_vr_t *vr)
Definition: vrrp_packet.c:682
int vrrp_vr_tracking_if_add_del(vrrp_vr_t *vr, u32 sw_if_index, u8 prio, u8 is_add)
Definition: vrrp.c:906
static const mfib_prefix_t all_vrrp4_routers
Definition: vrrp.c:326
static void vrrp_intf_tracking_vr_add_del(u32 sw_if_index, vrrp_vr_t *vr, u8 is_add)
Definition: vrrp.c:781
void mhash_init(mhash_t *h, uword n_value_bytes, uword n_key_bytes)
Definition: mhash.c:168
u32 flags
Definition: vhost_user.h:248
u8 is_ipv6
Definition: vrrp.h:33
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
ip4_add_del_interface_address_function_t * function
Definition: ip4.h:74
static void vrrp_vr_addrs_add_del(vrrp_vr_t *vr, u8 is_add, ip46_address_t *vr_addrs)
Definition: vrrp.c:561
static ip4_address_t * ip4_interface_address_matching_destination(ip4_main_t *im, const ip4_address_t *dst, u32 sw_if_index, ip_interface_address_t **result_ia)
Definition: ip4.h:235
#define clib_warning(format, args...)
Definition: error.h:59
static int vrrp_vr_valid_addrs_owner(vrrp_vr_config_t *vr_conf)
Definition: vrrp.c:448
static int vrrp_intf_ip_up(u32 sw_if_index, u8 is_ipv6, vrrp_intf_update_t *pending)
Definition: vrrp.c:846
vrrp_intf_update_type_t type
Definition: vrrp.c:50
Aggregate type for a prefix.
Definition: mfib_types.h:24
u32 * vr_indices[2]
Definition: vrrp.h:131
vrrp_main_t vrrp_main
Definition: vrrp.c:25
#define hash_create(elts, value_bytes)
Definition: hash.h:696
static walk_rc_t vrrp_hw_interface_link_up_down_walk(vnet_main_t *vnm, u32 sw_if_index, void *arg)
Definition: vrrp.c:1086
manual_print typedef address
Definition: ip_types.api:85
u32 intf_output_node_idx
Definition: vrrp.h:175
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
#define vec_delete(V, N, M)
Delete N elements starting at element M.
Definition: vec.h:852
u8 data[128]
Definition: ipsec_types.api:89
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
int vrrp_adv_send(vrrp_vr_t *vr, int shutdown)
Definition: vrrp_packet.c:272
IPv4 main type.
Definition: ip4.h:106
vrrp_vr_tracking_if_t * interfaces
Definition: vrrp.h:65
void vrrp_vr_timer_set(vrrp_vr_t *vr, vrrp_vr_timer_type_t type)
Definition: vrrp_periodic.c:89
static int vrrp_vr_valid_addrs_unused(vrrp_vr_config_t *vr_conf)
Definition: vrrp.c:463
int vrrp_vr_add_del(u8 is_add, vrrp_vr_config_t *vr_conf)
Definition: vrrp.c:573
#define clib_error_report(e)
Definition: error.h:113
static void hash_unset_mem_free(uword **h, const void *key)
Definition: hash.h:295
enum vrrp_vr_state vrrp_vr_state_t
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:324
static ip6_link_delegate_id_t vrrp_ip6_delegate_id
Definition: vrrp.c:1126
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
vrrp_vr_key_t key
Definition: vrrp.c:37
static uword vnet_sw_interface_is_admin_up(vnet_main_t *vnm, u32 sw_if_index)
#define vec_elt(v, i)
Get vector value at index i.
typedef key
Definition: ipsec_types.api:85
fib_protocol_t fp_proto
protocol type
Definition: mfib_types.h:33
static void vrrp_ip4_add_del_interface_addr(ip4_main_t *im, uword opaque, u32 sw_if_index, ip4_address_t *address, u32 address_length, u32 if_address_index, u32 is_del)
Definition: vrrp.c:1116
static vrrp_intf_t * vrrp_intf_get(u32 sw_if_index)
Definition: vrrp.h:286
void vrrp_vr_timer_cancel(vrrp_vr_t *vr)
Definition: vrrp_periodic.c:58
u32 interfaces_dec
Definition: vrrp.h:66
A for-us/local path.
Definition: fib_types.h:338
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static u32 vrrp_vr_hwif_master_vrs_by_vrid(u32 hw_if_index, u8 vr_id, u8 is_ipv6)
Definition: vrrp.c:79
static int vrrp_vr_set_peers_validate(vrrp_vr_t *vr, ip46_address_t *peers)
Definition: vrrp.c:730
u64 uword
Definition: types.h:112
static int vrrp_intf_enable_disable_mcast(u8 enable, u32 sw_if_index, u8 is_ipv6)
Definition: vrrp.c:347
clib_error_t * vrrp_plugin_api_hookup(vlib_main_t *vm)
Definition: vrrp_api.c:492
static vrrp_vr_t * vrrp_vr_lookup(u32 sw_if_index, u8 vr_id, u8 is_ipv6)
Definition: vrrp.h:230
u32 sw_if_index
Definition: vrrp.c:51
vnet_main_t * vnet_main
Definition: vrrp.h:172
static void vrrp_intf_ip6_disable(index_t indi)
Definition: vrrp.c:1172
static clib_error_t * vrrp_hw_interface_link_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: vrrp.c:1098
uword * vrrp4_arp_lookup
Definition: vrrp.h:164
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1144
adj_index_t adj_mcast_add_or_lock(fib_protocol_t proto, vnet_link_t link_type, u32 sw_if_index)
Mcast Adjacency.
Definition: adj_mcast.c:51
#define vec_foreach(var, vec)
Vector iterator.
ip46_address_t * vr_addrs
Definition: vrrp.h:76
clib_error_t * ip6_add_del_interface_address(vlib_main_t *vm, u32 sw_if_index, ip6_address_t *address, u32 address_length, u32 is_del)
Definition: ip6_forward.c:297
static void hash_set_mem_alloc(uword **h, const void *key, uword v)
Definition: hash.h:279
bool is_ipv6
Definition: dhcp.api:202
clib_error_t * vnet_hw_interface_add_del_mac_address(vnet_main_t *vnm, u32 hw_if_index, const u8 *mac_address, u8 is_add)
Definition: interface.c:1456
static void vrrp_intf_ip6_enable(u32 sw_if_index)
Definition: vrrp.c:1165
static ip6_address_t * ip6_interface_address_matching_destination(ip6_main_t *im, const ip6_address_t *dst, u32 sw_if_index, ip_interface_address_t **result_ia)
Definition: ip6.h:307
u16 adv_interval
Definition: vrrp.h:74
static clib_error_t * ip6_lookup_init(vlib_main_t *vm)
Definition: ip6_forward.c:2788
ip46_address_t * peer_addrs
Definition: vrrp.h:77
void mfib_table_entry_path_remove(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, const fib_route_path_t *rpath)
Remove n paths to an entry (aka route) in the FIB.
Definition: mfib_table.c:407
int vrrp_vr_tracking_ifs_add_del(vrrp_vr_t *vr, vrrp_vr_tracking_if_t *track_ifs, u8 is_add)
Definition: vrrp.c:949
static void vrrp_vr_skew_compute(vrrp_vr_t *vr)
Definition: vrrp.h:213
static uword vnet_hw_interface_is_link_up(vnet_main_t *vnm, u32 hw_if_index)
int vrrp_vr_addr_add_del(vrrp_vr_t *vr, u8 is_add, ip46_address_t *vr_addr)
Definition: vrrp.c:499
clib_error_t * vrrp_sw_interface_admin_up_down(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: vrrp.c:1071
vlib_main_t * vlib_main
Definition: vrrp.h:171
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: feature.c:304
static u32 vrrp_vr_lookup_address(u32 sw_if_index, u8 is_ipv6, void *addr)
Definition: vrrp.h:259
#define VRRP6_MCAST_ADDR_AS_U8
Definition: vrrp.c:323
void vrrp_vr_transition(vrrp_vr_t *vr, vrrp_vr_state_t new_state, void *data)
Definition: vrrp.c:247
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128