2 * node.c - vrrp packet handling node definitions
4 * Copyright 2019-2020 Rubicon Communications, LLC (Netgate)
6 * SPDX-License-Identifier: Apache-2.0
10 #include <vlibmemory/api.h>
11 #include <vnet/vnet.h>
12 #include <vnet/ip/ip4_packet.h>
13 #include <vnet/ip/ip6_link.h>
14 #include <vnet/ethernet/arp_packet.h>
15 #include <vnet/fib/fib_sas.h>
16 #include <vppinfra/error.h>
17 #include <vrrp/vrrp.h>
18 #include <vrrp/vrrp_packet.h>
25 u8 addrs[256]; /* print up to 64 IPv4 or 16 IPv6 addresses */
28 /* packet trace format function */
30 format_vrrp_trace (u8 * s, va_list * args)
32 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
33 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
34 vrrp_trace_t *t = va_arg (*args, vrrp_trace_t *);
37 s = format (s, "VRRP: sw_if_index %d IPv%d\n",
38 t->sw_if_index, (t->is_ipv6) ? 6 : 4);
39 s = format (s, " %U\n", format_vrrp_packet_hdr, &t->vrrp);
40 s = format (s, " addresses: ");
42 for (i = 0; i < t->vrrp.n_addrs; i++)
45 s = format (s, "%U ", format_ip6_address,
46 (ip6_address_t *) (t->addrs + i * 16));
48 s = format (s, "%U ", format_ip4_address,
49 (ip4_address_t *) (t->addrs + i * 4));
55 extern vlib_node_registration_t vrrp4_input_node;
56 extern vlib_node_registration_t vrrp6_input_node;
57 extern vlib_node_registration_t vrrp4_arp_input_node;
58 extern vlib_node_registration_t vrrp6_nd_input_node;
60 #define foreach_vrrp_error \
61 _(RECEIVED, "VRRP packets processed") \
62 _(BAD_TTL, "VRRP advertisement TTL is not 255") \
63 _(NOT_VERSION_3, "VRRP version is not 3") \
64 _(INCOMPLETE_PKT, "VRRP packet has wrong size") \
65 _(BAD_CHECKSUM, "VRRP checksum is invalid") \
66 _(UNKNOWN_VR, "VRRP message does not match known VRs") \
67 _(ADDR_MISMATCH, "VR addrs do not match configuration")
71 #define _(sym,str) VRRP_ERROR_##sym,
77 static char *vrrp_error_strings[] = {
78 #define _(sym,string) string,
89 /* Given a VR and a pointer to the VRRP header of an incoming packet,
90 * compare the local src address to the peers. Return < 0 if the local
91 * address < the peer address, 0 if they're equal, > 0 if
92 * the local address > the peer address
95 vrrp_vr_addr_cmp (vrrp_vr_t *vr, ip46_address_t *peer_addr)
97 vrrp_vr_config_t *vrc = &vr->config;
98 void *peer_addr_bytes, *local_addr;
102 clib_memset (&addr, 0, sizeof (addr));
104 if (vrrp_vr_is_ipv6 (vr))
106 peer_addr_bytes = &peer_addr->ip6;
107 local_addr = &addr.ip6;
109 ip6_address_copy (local_addr,
110 ip6_get_link_local_address (vrc->sw_if_index));
114 peer_addr_bytes = &peer_addr->ip4;
115 local_addr = &addr.ip4;
117 fib_sas4_get (vrc->sw_if_index, NULL, local_addr);
120 return memcmp (local_addr, peer_addr_bytes, addr_size);
124 vrrp_input_process_master (vrrp_vr_t *vr, vrrp_input_process_args_t *args)
126 /* received priority 0, another VR is shutting down. send an adv and
127 * remain in the master state
129 if (args->priority == 0)
131 clib_warning ("Received shutdown message from a peer on VR %U",
132 format_vrrp_vr_key, vr);
133 vrrp_adv_send (vr, 0);
134 vrrp_vr_timer_set (vr, VRRP_VR_TIMER_ADV);
139 * - received priority > adjusted priority, or
140 * - received priority == adjusted priority and peer addr > local addr
141 * allow the local VR to be preempted by the peer
143 if ((args->priority > vrrp_vr_priority (vr)) ||
144 ((args->priority == vrrp_vr_priority (vr)) &&
145 (vrrp_vr_addr_cmp (vr, &args->src_addr) < 0)))
147 vrrp_vr_transition (vr, VRRP_VR_STATE_BACKUP, args);
152 /* if we made it this far, eiher received prority < adjusted priority or
153 * received == adjusted and local addr > peer addr. Ignore.
158 /* RFC 5798 section 6.4.2 */
160 vrrp_input_process_backup (vrrp_vr_t *vr, vrrp_input_process_args_t *args)
162 vrrp_vr_config_t *vrc = &vr->config;
163 vrrp_vr_runtime_t *vrt = &vr->runtime;
165 /* master shutting down, ready for election */
166 if (args->priority == 0)
168 clib_warning ("Master for VR %U is shutting down", format_vrrp_vr_key,
170 vrt->master_down_int = vrt->skew;
171 vrrp_vr_timer_set (vr, VRRP_VR_TIMER_MASTER_DOWN);
175 /* no preempt set or adv from a higher priority router, update timers */
176 if (!(vrc->flags & VRRP_VR_PREEMPT) ||
177 (args->priority >= vrrp_vr_priority (vr)))
179 vrt->master_adv_int = args->max_adv_int;
181 vrrp_vr_skew_compute (vr);
182 vrrp_vr_master_down_compute (vr);
183 vrrp_vr_timer_set (vr, VRRP_VR_TIMER_MASTER_DOWN);
187 /* preempt set or our priority > received, continue to wait on master down */
192 vrrp_input_process (vrrp_input_process_args_t * args)
196 vr = vrrp_vr_lookup_index (args->vr_index);
200 clib_warning ("Error retrieving VR with index %u", args->vr_index);
204 switch (vr->runtime.state)
206 case VRRP_VR_STATE_INIT:
208 case VRRP_VR_STATE_BACKUP:
209 /* this is usually the only state an advertisement should be received */
210 vrrp_input_process_backup (vr, args);
212 case VRRP_VR_STATE_MASTER:
213 /* might be getting preempted. or have a misbehaving peer */
214 clib_warning ("Received advertisement for master VR %U",
215 format_vrrp_vr_key, vr);
216 vrrp_input_process_master (vr, args);
219 clib_warning ("Received advertisement for VR %U in unknown state %d",
220 format_vrrp_vr_key, vr, vr->runtime.state);
233 } vrrp_arp_nd_trace_t;
237 format_vrrp_arp_nd_input_trace (u8 * s, va_list * va)
239 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
240 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
241 vrrp_arp_nd_trace_t *t = va_arg (*va, vrrp_arp_nd_trace_t *);
243 s = format (s, "address %U",
244 (t->is_ipv6) ? format_ip6_address : format_ip4_address,
245 (t->is_ipv6) ? (void *) &t->ip.ip6 : (void *) &t->ip.ip4);
247 if (t->vr_index != ~0)
248 s = format (s, ": vr_index %u vr_id %u", t->vr_index, t->vr_id);
255 VRRP_ARP_INPUT_NEXT_DROP,
256 VRRP_ARP_INPUT_NEXT_REPLY_TX,
262 VRRP_ND_INPUT_NEXT_DROP,
263 VRRP_ND_INPUT_NEXT_REPLY_TX,
267 static_always_inline void
268 vrrp_arp_nd_next (vlib_buffer_t * b, u32 * next_index, u32 * vr_index,
271 vnet_main_t *vnm = vnet_get_main ();
272 vlib_main_t *vm = vlib_get_main ();
273 ethernet_header_t *eth, *eth_new;
274 void *lookup_addr = 0;
277 vnet_link_t link_type;
278 u8 *rewrite, rewrite_len;
281 ip6_header_t *ip6 = 0;
282 icmp6_neighbor_solicitation_or_advertisement_header_t *sol_adv = 0;
283 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *lladdr = 0;
285 ethernet_arp_header_t *arp;
286 ip4_address_t ip4_addr;
290 ip6 = vlib_buffer_get_current (b);
292 /* we only care about about ICMP6 neighbor solicitiations */
293 if (ip6->protocol != IP_PROTOCOL_ICMP6)
296 sol_adv = ip6_next_header (ip6);
297 lladdr = (void *) (sol_adv + 1);
299 /* skip anything other than neighbor solicitations */
300 if (sol_adv->icmp.type != ICMP6_neighbor_solicitation)
303 lookup_addr = &sol_adv->target_address;
304 link_type = VNET_LINK_IP6;
308 arp = vlib_buffer_get_current (b);
310 /* skip non-request packets */
311 if (arp->opcode != clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_request))
314 lookup_addr = &arp->ip4_over_ethernet[1].ip4;
315 link_type = VNET_LINK_ARP;
318 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
320 /* Don't bother with a hash lookup if no VRs configured on this interface */
321 if (!vrrp_intf_num_vrs (sw_if_index, is_ipv6))
324 /* skip requests that are not for VRRP addresses */
325 *vr_index = vrrp_vr_lookup_address (sw_if_index, is_ipv6, lookup_addr);
329 vr = vrrp_vr_lookup_index (*vr_index);
330 if (!vr || vr->runtime.state != VRRP_VR_STATE_MASTER)
332 /* RFC 5798 - section 6.4.2 - Backup "MUST NOT respond" to ARP/ND.
333 * So we must drop the request rather than allowing it to continue
334 * on the feature arc.
336 *next_index = VRRP_ARP_INPUT_NEXT_DROP;
340 /* RFC 5798 section 6.4.3: Master "MUST respond" to ARP/ND. */
341 eth = ethernet_buffer_get_header (b);
342 rewrite = ethernet_build_rewrite (vnm, sw_if_index, link_type,
344 rewrite_len = vec_len (rewrite);
345 if (rewrite_len == 0)
348 /* send the reply out the incoming interface */
349 *next_index = VRRP_ARP_INPUT_NEXT_REPLY_TX;
350 vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
352 /* the outbound ethernet & vlan headers may have a different length than
353 * the received header, so get a pointer to the new start of the packet
354 * and write the header there.
356 vlib_buffer_advance (b, -rewrite_len);
357 eth_new = vlib_buffer_get_current (b);
358 clib_memcpy_fast (eth_new, rewrite, rewrite_len);
363 if (ip6_address_is_unspecified (&ip6->src_address))
364 ip6_set_reserved_multicast_address (&ip6->dst_address,
365 IP6_MULTICAST_SCOPE_link_local,
366 IP6_MULTICAST_GROUP_ID_all_hosts);
368 ip6->dst_address = ip6->src_address;
370 ip6->src_address = sol_adv->target_address;
371 ip6->hop_limit = 255;
372 sol_adv->icmp.type = ICMP6_neighbor_advertisement;
373 sol_adv->icmp.checksum = 0;
374 sol_adv->advertisement_flags =
375 clib_host_to_net_u32 (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_ROUTER
376 | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED
377 | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
379 clib_memcpy (lladdr->ethernet_address, vr->runtime.mac.bytes,
380 sizeof (mac_address_t));
381 lladdr->header.type =
382 ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
384 sol_adv->icmp.checksum =
385 ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus_length);
390 ip4_addr = arp->ip4_over_ethernet[1].ip4;
392 arp->opcode = clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply);
393 arp->ip4_over_ethernet[1] = arp->ip4_over_ethernet[0];
395 arp->ip4_over_ethernet[0].mac = vr->runtime.mac;
396 arp->ip4_over_ethernet[0].ip4 = ip4_addr;
400 static_always_inline uword
401 vrrp_arp_nd_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
402 vlib_frame_t * frame, u8 is_ipv6)
404 u32 n_left_from, *from, next_index, *to_next;
406 from = vlib_frame_vector_args (frame);
407 n_left_from = frame->n_vectors;
408 next_index = node->cached_next_index;
410 while (n_left_from > 0)
414 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
416 while (n_left_from > 0 && n_left_to_next > 0)
431 b0 = vlib_get_buffer (vm, bi0);
433 vnet_feature_next (&next0, b0);
434 vrrp_arp_nd_next (b0, &next0, &vr_index, is_ipv6);
436 if (b0->flags & VLIB_BUFFER_IS_TRACED)
438 vrrp_arp_nd_trace_t *t =
439 vlib_add_trace (vm, node, b0, sizeof (*t));
445 icmp6_neighbor_solicitation_or_advertisement_header_t
448 ip0 = vlib_buffer_get_current (b0);
449 sol_adv0 = ip6_next_header (ip0);
450 t->ip.ip6 = sol_adv0->target_address;
454 ethernet_arp_header_t *arp0;
456 arp0 = vlib_buffer_get_current (b0);
457 t->ip.ip4 = arp0->ip4_over_ethernet[0].ip4;
460 vr = vrrp_vr_lookup_index (vr_index);
462 t->vr_id = vr->config.vr_id;
464 t->vr_index = vr_index;
465 t->is_ipv6 = is_ipv6;
468 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
469 n_left_to_next, bi0, next0);
472 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
475 return frame->n_vectors;
478 VLIB_NODE_FN (vrrp4_arp_input_node) (vlib_main_t * vm,
479 vlib_node_runtime_t * node,
480 vlib_frame_t * frame)
482 return vrrp_arp_nd_input_inline (vm, node, frame, 0 /* is_ipv6 */ );
486 VLIB_REGISTER_NODE (vrrp4_arp_input_node) =
488 .name = "vrrp4-arp-input",
489 .vector_size = sizeof (u32),
490 .format_trace = format_vrrp_arp_nd_input_trace,
491 .type = VLIB_NODE_TYPE_INTERNAL,
493 .n_errors = ARRAY_LEN(vrrp_error_strings),
494 .error_strings = vrrp_error_strings,
496 .n_next_nodes = VRRP_ARP_N_NEXT,
499 [VRRP_ARP_INPUT_NEXT_DROP] = "error-drop",
500 [VRRP_ARP_INPUT_NEXT_REPLY_TX] = "interface-output",
504 VNET_FEATURE_INIT (vrrp4_arp_feat_node, static) =
507 .node_name = "vrrp4-arp-input",
508 .runs_before = VNET_FEATURES ("arp-reply"),
511 VLIB_NODE_FN (vrrp6_nd_input_node) (vlib_main_t * vm,
512 vlib_node_runtime_t * node,
513 vlib_frame_t * frame)
515 return vrrp_arp_nd_input_inline (vm, node, frame, 1 /* is_ipv6 */);
519 VLIB_REGISTER_NODE (vrrp6_nd_input_node) =
521 .name = "vrrp6-nd-input",
522 .vector_size = sizeof (u32),
523 .format_trace = format_vrrp_arp_nd_input_trace,
524 .type = VLIB_NODE_TYPE_INTERNAL,
526 .n_errors = ARRAY_LEN(vrrp_error_strings),
527 .error_strings = vrrp_error_strings,
529 .n_next_nodes = VRRP_ND_N_NEXT,
532 [VRRP_ND_INPUT_NEXT_DROP] = "error-drop",
533 [VRRP_ND_INPUT_NEXT_REPLY_TX] = "interface-output",
537 VNET_FEATURE_INIT (vrrp6_nd_feat_node, static) =
539 .arc_name = "ip6-local",
540 .node_name = "vrrp6-nd-input",
541 .runs_before = VNET_FEATURES ("ip6-local-end-of-arc"),
544 static_always_inline uword
545 vrrp_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
546 vlib_frame_t * frame, u8 is_ipv6)
548 u32 n_left_from, *from;
549 vrrp_main_t *vmp = &vrrp_main;
551 from = vlib_frame_vector_args (frame);
552 n_left_from = frame->n_vectors;
554 while (n_left_from > 0)
560 vrrp_header_t *vrrp0;
562 vrrp_input_process_args_t args0;
569 b0 = vlib_get_buffer (vm, bi0);
571 ip0 = vlib_buffer_get_current (b0);
575 ip6_header_t *ip6 = ip0;
577 vrrp0 = (vrrp_header_t *) (ip6 + 1);
578 ttl0 = &ip6->hop_limit;
580 payload_len0 = clib_net_to_host_u16 (ip6->payload_length);
581 vlib_buffer_advance (b0, sizeof (*ip6));
582 clib_memcpy_fast (&args0.src_addr.ip6, &ip6->src_address, addr_len);
586 ip4_header_t *ip4 = ip0;
588 vrrp0 = (vrrp_header_t *) (ip4 + 1);
591 payload_len0 = clib_net_to_host_u16 (ip4->length) - sizeof(*ip4);
592 vlib_buffer_advance (b0, sizeof (*ip4));
593 clib_memcpy_fast (&args0.src_addr.ip4, &ip4->src_address, addr_len);
596 next0 = VRRP_INPUT_NEXT_DROP;
598 error0 = VRRP_ERROR_RECEIVED;
600 /* Validation from RFC 5798 sec 7.1 */
602 /* checksum set to 0 for calculation, save original value */
603 rx_csum0 = vrrp0->checksum;
606 /* Mandatory - TTL/hop limit must be 255 */
609 error0 = VRRP_ERROR_BAD_TTL;
613 /* Mandatory - VRRP version must be 3 */
614 if ((vrrp0->vrrp_version_and_type >> 4) != 3)
616 error0 = VRRP_ERROR_NOT_VERSION_3;
620 /* Mandatory - packet must be complete */
621 if (b0->current_length < sizeof (*vrrp0) +
622 ((u32) vrrp0->n_addrs) * addr_len)
624 error0 = VRRP_ERROR_INCOMPLETE_PKT;
628 /* Mandatory - checksum must be correct */
629 if (rx_csum0 != vrrp_adv_csum (ip0, vrrp0, is_ipv6, payload_len0))
631 error0 = VRRP_ERROR_BAD_CHECKSUM;
635 /* Mandatory - VR must be configured on the interface adv received on */
637 vrrp_vr_lookup (vnet_buffer(b0)->sw_if_index[VLIB_RX],
638 vrrp0->vr_id, is_ipv6)))
640 error0 = VRRP_ERROR_UNKNOWN_VR;
644 /* Optional - count of addresses should match configuration */
645 /* Could also check that addresses match, but likely to be O(n^2) */
646 if (vrrp0->n_addrs != vec_len (vr0->config.vr_addrs))
648 error0 = VRRP_ERROR_ADDR_MISMATCH;
652 /* signal main thread to process contents of packet */
653 args0.vr_index = vr0 - vmp->vrs;
654 args0.priority = vrrp0->priority;
655 args0.max_adv_int = vrrp_adv_int_from_packet (vrrp0);
657 vl_api_rpc_call_main_thread (vrrp_input_process, (u8 *) &args0,
661 vrrp0->checksum = rx_csum0; /* restore csum for correct trace output */
662 b0->error = node->errors[error0];
664 if (b0->flags & VLIB_BUFFER_IS_TRACED)
666 vrrp_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
667 size_t addr_len = (is_ipv6 ? 16 : 4);
669 t->sw_if_index = vnet_buffer(b0)->sw_if_index[VLIB_RX];
670 t->is_ipv6 = is_ipv6;
671 clib_memcpy_fast (&t->vrrp, vrrp0, sizeof (*vrrp0));
672 clib_memcpy_fast (t->addrs, (void *) (vrrp0 + 1),
673 (size_t) vrrp0->n_addrs * addr_len);
676 /* always drop, never forward or reply here */
677 vlib_set_next_frame_buffer (vm, node, next0, bi0);
683 return frame->n_vectors;
686 VLIB_NODE_FN (vrrp4_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
687 vlib_frame_t * frame)
689 return vrrp_input_inline (vm, node, frame, 0);
693 VLIB_REGISTER_NODE (vrrp4_input_node) =
695 .name = "vrrp4-input",
696 .vector_size = sizeof (u32),
697 .format_trace = format_vrrp_trace,
698 .type = VLIB_NODE_TYPE_INTERNAL,
700 .n_errors = ARRAY_LEN(vrrp_error_strings),
701 .error_strings = vrrp_error_strings,
703 .n_next_nodes = VRRP_INPUT_N_NEXT,
706 [VRRP_INPUT_NEXT_DROP] = "error-drop",
710 VLIB_NODE_FN (vrrp6_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
711 vlib_frame_t * frame)
713 return vrrp_input_inline (vm, node, frame, 1);
716 VLIB_REGISTER_NODE (vrrp6_input_node) =
718 .name = "vrrp6-input",
719 .vector_size = sizeof (u32),
720 .format_trace = format_vrrp_trace,
721 .type = VLIB_NODE_TYPE_INTERNAL,
723 .n_errors = ARRAY_LEN(vrrp_error_strings),
724 .error_strings = vrrp_error_strings,
726 .n_next_nodes = VRRP_INPUT_N_NEXT,
729 [VRRP_INPUT_NEXT_DROP] = "error-drop",
737 ip46_address_t src, dst;
738 } vrrp_accept_owner_trace_t;
740 /* packet trace format function */
742 format_vrrp_accept_owner_trace (u8 * s, va_list * args)
744 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
745 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
746 vrrp_accept_owner_trace_t *t = va_arg (*args, vrrp_accept_owner_trace_t *);
747 int ip_ver = 4, ip_type = IP46_TYPE_IP4;
752 ip_type = IP46_TYPE_IP6;
755 s = format (s, "IPv%d sw_if_index %d %U -> %U",
756 ip_ver, t->sw_if_index,
757 format_ip46_address, &t->src, ip_type,
758 format_ip46_address, &t->dst, ip_type);
763 #define foreach_vrrp_accept_owner_error \
764 _(RECEIVED, "VRRP owner accept packets received") \
765 _(PROCESSED, "VRRP owner accept advertisements processed")
769 #define _(sym,str) VRRP_ACCEPT_OWNER_ERROR_##sym,
770 foreach_vrrp_accept_owner_error
772 VRRP_ACCEPT_OWNER_N_ERROR,
773 } vrrp_accept_owner_error_t;
775 static char *vrrp_accept_owner_error_strings[] = {
776 #define _(sym,string) string,
777 foreach_vrrp_accept_owner_error
783 VRRP_ACCEPT_OWNER_NEXT_PROCESS,
784 VRRP_ACCEPT_OWNER_N_NEXT,
785 } vrrp_accept_owner_next_t;
787 static_always_inline void
788 vrrp_accept_owner_next_node (u32 sw_if_index, u8 vr_id, u8 is_ipv6,
789 u32 *next_index, u32 *error)
791 vrrp_vr_t *vr = vrrp_vr_lookup (sw_if_index, vr_id, is_ipv6);
793 if (vr && (vr->runtime.state == VRRP_VR_STATE_MASTER) &&
794 (vr->config.flags & VRRP_VR_ACCEPT))
796 *next_index = VRRP_ACCEPT_OWNER_NEXT_PROCESS;
797 *error = VRRP_ACCEPT_OWNER_ERROR_PROCESSED;
801 static_always_inline uword
802 vrrp_accept_owner_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
803 vlib_frame_t * frame, u8 is_ipv6)
805 u32 n_left_from, *from, *to_next;
806 u32 next_index = node->cached_next_index;
808 from = vlib_frame_vector_args (frame);
809 n_left_from = frame->n_vectors;
811 while (n_left_from > 0)
815 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
817 while (n_left_from >= 2 && n_left_to_next >= 2)
820 vlib_buffer_t *b0, *b1;
823 vrrp_header_t *vrrp0, *vrrp1;
824 ip4_header_t *ip40, *ip41;
825 ip6_header_t *ip60, *ip61;
826 u32 sw_if_index0, sw_if_index1;
834 b0 = vlib_get_buffer (vm, bi0);
835 b1 = vlib_get_buffer (vm, bi1);
837 /* most packets will follow feature arc */
838 vnet_feature_next (&next0, b0);
839 vnet_feature_next (&next1, b1);
841 error0 = error1 = VRRP_ACCEPT_OWNER_ERROR_RECEIVED;
843 sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
844 sw_if_index1 = vnet_buffer(b1)->sw_if_index[VLIB_RX];
846 /* find VRRP advertisements which should be sent to VRRP node */
849 ip60 = vlib_buffer_get_current (b0);
850 ip61 = vlib_buffer_get_current (b1);
852 if (PREDICT_FALSE (ip60->protocol == IP_PROTOCOL_VRRP))
854 vrrp0 = (vrrp_header_t *) (ip60 + 1);
855 vrrp_accept_owner_next_node (sw_if_index0, vrrp0->vr_id,
856 is_ipv6, &next0, &error0);
858 if (PREDICT_FALSE (ip61->protocol == IP_PROTOCOL_VRRP))
860 vrrp1 = (vrrp_header_t *) (ip61 + 1);
861 vrrp_accept_owner_next_node (sw_if_index1, vrrp1->vr_id,
862 is_ipv6, &next1, &error1);
867 ip40 = vlib_buffer_get_current (b0);
868 ip41 = vlib_buffer_get_current (b1);
870 if (PREDICT_FALSE (ip40->protocol == IP_PROTOCOL_VRRP))
872 vrrp0 = (vrrp_header_t *) (ip40 + 1);
873 vrrp_accept_owner_next_node (sw_if_index0, vrrp0->vr_id,
874 is_ipv6, &next0, &error0);
876 if (PREDICT_FALSE (ip41->protocol == IP_PROTOCOL_VRRP))
878 vrrp1 = (vrrp_header_t *) (ip41 + 1);
879 vrrp_accept_owner_next_node (sw_if_index1, vrrp1->vr_id,
880 is_ipv6, &next1, &error1);
884 b0->error = node->errors[error0];
885 b1->error = node->errors[error1];
887 if (b0->flags & VLIB_BUFFER_IS_TRACED)
889 vrrp_accept_owner_trace_t *t =
890 vlib_add_trace (vm, node, b0, sizeof (*t));
892 t->sw_if_index = sw_if_index0;
893 t->is_ipv6 = is_ipv6;
896 ip6_address_copy (&t->src.ip6, &ip60->src_address);
897 ip6_address_copy (&t->dst.ip6, &ip60->dst_address);
901 t->src.ip4.as_u32 = ip40->src_address.as_u32;
902 t->dst.ip4.as_u32 = ip40->dst_address.as_u32;
906 if (b1->flags & VLIB_BUFFER_IS_TRACED)
908 vrrp_accept_owner_trace_t *t =
909 vlib_add_trace (vm, node, b1, sizeof (*t));
911 t->sw_if_index = sw_if_index1;
912 t->is_ipv6 = is_ipv6;
915 ip6_address_copy (&t->src.ip6, &ip61->src_address);
916 ip6_address_copy (&t->dst.ip6, &ip61->dst_address);
920 t->src.ip4.as_u32 = ip41->src_address.as_u32;
921 t->dst.ip4.as_u32 = ip41->dst_address.as_u32;
930 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
931 to_next, n_left_to_next,
932 bi0, bi1, next0, next1);
935 while (n_left_from > 0 && n_left_to_next > 0)
941 vrrp_header_t *vrrp0;
949 b0 = vlib_get_buffer (vm, bi0);
951 /* most packets will follow feature arc */
952 vnet_feature_next (&next0, b0);
954 error0 = VRRP_ACCEPT_OWNER_ERROR_RECEIVED;
956 sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
958 /* find VRRP advertisements which should be sent to VRRP node */
961 ip6 = vlib_buffer_get_current (b0);
963 if (PREDICT_FALSE (ip6->protocol == IP_PROTOCOL_VRRP))
965 vrrp0 = (vrrp_header_t *) (ip6 + 1);
966 vrrp_accept_owner_next_node (sw_if_index0, vrrp0->vr_id,
967 is_ipv6, &next0, &error0);
972 ip4 = vlib_buffer_get_current (b0);
974 if (PREDICT_FALSE (ip4->protocol == IP_PROTOCOL_VRRP))
976 vrrp0 = (vrrp_header_t *) (ip4 + 1);
977 vrrp_accept_owner_next_node (sw_if_index0, vrrp0->vr_id,
978 is_ipv6, &next0, &error0);
982 b0->error = node->errors[error0];
984 if (b0->flags & VLIB_BUFFER_IS_TRACED)
986 vrrp_accept_owner_trace_t *t =
987 vlib_add_trace (vm, node, b0, sizeof (*t));
989 t->sw_if_index = sw_if_index0;
990 t->is_ipv6 = is_ipv6;
993 ip6_address_copy (&t->src.ip6, &ip6->src_address);
994 ip6_address_copy (&t->dst.ip6, &ip6->dst_address);
998 t->src.ip4.as_u32 = ip4->src_address.as_u32;
999 t->dst.ip4.as_u32 = ip4->dst_address.as_u32;
1006 n_left_to_next -= 1;
1008 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1009 to_next, n_left_to_next,
1013 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1016 return frame->n_vectors;
1019 VLIB_NODE_FN (vrrp4_accept_owner_input_node) (vlib_main_t * vm,
1020 vlib_node_runtime_t * node,
1021 vlib_frame_t * frame)
1023 return vrrp_accept_owner_input_inline (vm, node, frame, 0);
1026 VLIB_REGISTER_NODE (vrrp4_accept_owner_input_node) =
1028 .name = "vrrp4-accept-owner-input",
1029 .vector_size = sizeof (u32),
1030 .format_trace = format_vrrp_accept_owner_trace,
1031 .type = VLIB_NODE_TYPE_INTERNAL,
1033 .n_errors = ARRAY_LEN(vrrp_accept_owner_error_strings),
1034 .error_strings = vrrp_accept_owner_error_strings,
1036 .n_next_nodes = VRRP_ACCEPT_OWNER_N_NEXT,
1039 [VRRP_ACCEPT_OWNER_NEXT_PROCESS] = "vrrp4-input",
1043 VNET_FEATURE_INIT (vrrp4_accept_owner_mc, static) =
1045 .arc_name = "ip4-multicast",
1046 .node_name = "vrrp4-accept-owner-input",
1047 .runs_before = VNET_FEATURES ("ip4-mfib-forward-lookup"),
1050 VLIB_NODE_FN (vrrp6_accept_owner_input_node) (vlib_main_t * vm,
1051 vlib_node_runtime_t * node,
1052 vlib_frame_t * frame)
1054 return vrrp_accept_owner_input_inline (vm, node, frame, 1);
1057 VLIB_REGISTER_NODE (vrrp6_accept_owner_input_node) =
1059 .name = "vrrp6-accept-owner-input",
1060 .vector_size = sizeof (u32),
1061 .format_trace = format_vrrp_accept_owner_trace,
1062 .type = VLIB_NODE_TYPE_INTERNAL,
1064 .n_errors = ARRAY_LEN(vrrp_accept_owner_error_strings),
1065 .error_strings = vrrp_accept_owner_error_strings,
1067 .n_next_nodes = VRRP_ACCEPT_OWNER_N_NEXT,
1070 [VRRP_ACCEPT_OWNER_NEXT_PROCESS] = "vrrp6-input",
1074 VNET_FEATURE_INIT (vrrp6_accept_owner_mc, static) =
1076 .arc_name = "ip6-multicast",
1077 .node_name = "vrrp6-accept-owner-input",
1078 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
1081 static clib_error_t *
1082 vrrp_input_init (vlib_main_t *vm)
1084 clib_error_t *error;
1086 if ((error = vlib_call_init_function (vm, vrrp_init)))
1089 ip4_register_protocol (IP_PROTOCOL_VRRP, vrrp4_input_node.index);
1090 ip6_register_protocol (IP_PROTOCOL_VRRP, vrrp6_input_node.index);
1095 VLIB_INIT_FUNCTION (vrrp_input_init);
1100 * fd.io coding-style-patch-verification: ON
1103 * eval: (c-set-style "gnu")