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 typedef struct vrrp_input_process_args
93 } vrrp_input_process_args_t;
95 /* Given a VR and a pointer to the VRRP header of an incoming packet,
96 * compare the local src address to the peers. Return < 0 if the local
97 * address < the peer address, 0 if they're equal, > 0 if
98 * the local address > the peer address
101 vrrp_vr_addr_cmp (vrrp_vr_t * vr, vrrp_header_t * pkt)
103 vrrp_vr_config_t *vrc = &vr->config;
104 void *peer_addr, *local_addr;
108 clib_memset (&addr, 0, sizeof (addr));
110 if (vrrp_vr_is_ipv6 (vr))
112 peer_addr = &(((ip6_header_t *) pkt) - 1)->src_address;
113 local_addr = &addr.ip6;
115 ip6_address_copy (local_addr,
116 ip6_get_link_local_address (vrc->sw_if_index));
120 peer_addr = &(((ip4_header_t *) pkt) - 1)->src_address;
121 local_addr = &addr.ip4;
123 fib_sas4_get (vrc->sw_if_index, NULL, local_addr);
126 return memcmp (local_addr, peer_addr, addr_size);
130 vrrp_input_process_master (vrrp_vr_t * vr, vrrp_header_t * pkt)
132 /* received priority 0, another VR is shutting down. send an adv and
133 * remain in the master state
135 if (pkt->priority == 0)
137 clib_warning ("Received shutdown message from a peer on VR %U",
138 format_vrrp_vr_key, vr);
139 vrrp_adv_send (vr, 0);
140 vrrp_vr_timer_set (vr, VRRP_VR_TIMER_ADV);
145 * - received priority > adjusted priority, or
146 * - received priority == adjusted priority and peer addr > local addr
147 * allow the local VR to be preempted by the peer
149 if ((pkt->priority > vrrp_vr_priority (vr)) ||
150 ((pkt->priority == vrrp_vr_priority (vr)) &&
151 (vrrp_vr_addr_cmp (vr, pkt) < 0)))
153 vrrp_vr_transition (vr, VRRP_VR_STATE_BACKUP, pkt);
158 /* if we made it this far, eiher received prority < adjusted priority or
159 * received == adjusted and local addr > peer addr. Ignore.
164 /* RFC 5798 section 6.4.2 */
166 vrrp_input_process_backup (vrrp_vr_t * vr, vrrp_header_t * pkt)
168 vrrp_vr_config_t *vrc = &vr->config;
169 vrrp_vr_runtime_t *vrt = &vr->runtime;
171 /* master shutting down, ready for election */
172 if (pkt->priority == 0)
174 clib_warning ("Master for VR %U is shutting down", format_vrrp_vr_key,
176 vrt->master_down_int = vrt->skew;
177 vrrp_vr_timer_set (vr, VRRP_VR_TIMER_MASTER_DOWN);
181 /* no preempt set or adv from a higher priority router, update timers */
182 if (!(vrc->flags & VRRP_VR_PREEMPT) ||
183 (pkt->priority >= vrrp_vr_priority (vr)))
185 vrt->master_adv_int = clib_net_to_host_u16 (pkt->rsvd_and_max_adv_int);
186 vrt->master_adv_int &= ((u16) 0x0fff); /* ignore rsvd bits */
188 vrrp_vr_skew_compute (vr);
189 vrrp_vr_master_down_compute (vr);
190 vrrp_vr_timer_set (vr, VRRP_VR_TIMER_MASTER_DOWN);
194 /* preempt set or our priority > received, continue to wait on master down */
199 vrrp_input_process (vrrp_input_process_args_t * args)
203 vr = vrrp_vr_lookup_index (args->vr_index);
207 clib_warning ("Error retrieving VR with index %u", args->vr_index);
211 switch (vr->runtime.state)
213 case VRRP_VR_STATE_INIT:
215 case VRRP_VR_STATE_BACKUP:
216 /* this is usually the only state an advertisement should be received */
217 vrrp_input_process_backup (vr, args->pkt);
219 case VRRP_VR_STATE_MASTER:
220 /* might be getting preempted. or have a misbehaving peer */
221 clib_warning ("Received advertisement for master VR %U",
222 format_vrrp_vr_key, vr);
223 vrrp_input_process_master (vr, args->pkt);
226 clib_warning ("Received advertisement for VR %U in unknown state %d",
227 format_vrrp_vr_key, vr, vr->runtime.state);
240 } vrrp_arp_nd_trace_t;
244 format_vrrp_arp_nd_input_trace (u8 * s, va_list * va)
246 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
247 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
248 vrrp_arp_nd_trace_t *t = va_arg (*va, vrrp_arp_nd_trace_t *);
250 s = format (s, "address %U",
251 (t->is_ipv6) ? format_ip6_address : format_ip4_address,
252 (t->is_ipv6) ? (void *) &t->ip.ip6 : (void *) &t->ip.ip4);
254 if (t->vr_index != ~0)
255 s = format (s, ": vr_index %u vr_id %u", t->vr_index, t->vr_id);
262 VRRP_ARP_INPUT_NEXT_DROP,
263 VRRP_ARP_INPUT_NEXT_REPLY_TX,
269 VRRP_ND_INPUT_NEXT_DROP,
270 VRRP_ND_INPUT_NEXT_REPLY_TX,
274 static_always_inline void
275 vrrp_arp_nd_next (vlib_buffer_t * b, u32 * next_index, u32 * vr_index,
278 vnet_main_t *vnm = vnet_get_main ();
279 vlib_main_t *vm = vlib_get_main ();
280 ethernet_header_t *eth, *eth_new;
281 void *lookup_addr = 0;
284 vnet_link_t link_type;
285 u8 *rewrite, rewrite_len;
288 ip6_header_t *ip6 = 0;
289 icmp6_neighbor_solicitation_or_advertisement_header_t *sol_adv = 0;
290 icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *lladdr = 0;
292 ethernet_arp_header_t *arp;
293 ip4_address_t ip4_addr;
297 ip6 = vlib_buffer_get_current (b);
299 /* we only care about about ICMP6 neighbor solicitiations */
300 if (ip6->protocol != IP_PROTOCOL_ICMP6)
303 sol_adv = ip6_next_header (ip6);
304 lladdr = (void *) (sol_adv + 1);
306 /* skip anything other than neighbor solicitations */
307 if (sol_adv->icmp.type != ICMP6_neighbor_solicitation)
310 lookup_addr = &sol_adv->target_address;
311 link_type = VNET_LINK_IP6;
315 arp = vlib_buffer_get_current (b);
317 /* skip non-request packets */
318 if (arp->opcode != clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_request))
321 lookup_addr = &arp->ip4_over_ethernet[1].ip4;
322 link_type = VNET_LINK_ARP;
325 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
327 /* Don't bother with a hash lookup if no VRs configured on this interface */
328 if (!vrrp_intf_num_vrs (sw_if_index, is_ipv6))
331 /* skip requests that are not for VRRP addresses */
332 *vr_index = vrrp_vr_lookup_address (sw_if_index, is_ipv6, lookup_addr);
336 vr = vrrp_vr_lookup_index (*vr_index);
337 if (!vr || vr->runtime.state != VRRP_VR_STATE_MASTER)
339 /* RFC 5798 - section 6.4.2 - Backup "MUST NOT respond" to ARP/ND.
340 * So we must drop the request rather than allowing it to continue
341 * on the feature arc.
343 *next_index = VRRP_ARP_INPUT_NEXT_DROP;
347 /* RFC 5798 section 6.4.3: Master "MUST respond" to ARP/ND. */
348 eth = ethernet_buffer_get_header (b);
349 rewrite = ethernet_build_rewrite (vnm, sw_if_index, link_type,
351 rewrite_len = vec_len (rewrite);
352 if (rewrite_len == 0)
355 /* send the reply out the incoming interface */
356 *next_index = VRRP_ARP_INPUT_NEXT_REPLY_TX;
357 vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index;
359 /* the outbound ethernet & vlan headers may have a different length than
360 * the received header, so get a pointer to the new start of the packet
361 * and write the header there.
363 vlib_buffer_advance (b, -rewrite_len);
364 eth_new = vlib_buffer_get_current (b);
365 clib_memcpy_fast (eth_new, rewrite, rewrite_len);
370 if (ip6_address_is_unspecified (&ip6->src_address))
371 ip6_set_reserved_multicast_address (&ip6->dst_address,
372 IP6_MULTICAST_SCOPE_link_local,
373 IP6_MULTICAST_GROUP_ID_all_hosts);
375 ip6->dst_address = ip6->src_address;
377 ip6->src_address = sol_adv->target_address;
378 ip6->hop_limit = 255;
379 sol_adv->icmp.type = ICMP6_neighbor_advertisement;
380 sol_adv->icmp.checksum = 0;
381 sol_adv->advertisement_flags =
382 clib_host_to_net_u32 (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_ROUTER
383 | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED
384 | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE);
386 clib_memcpy (lladdr->ethernet_address, vr->runtime.mac.bytes,
387 sizeof (mac_address_t));
388 lladdr->header.type =
389 ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
391 sol_adv->icmp.checksum =
392 ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus_length);
397 ip4_addr = arp->ip4_over_ethernet[1].ip4;
399 arp->opcode = clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply);
400 arp->ip4_over_ethernet[1] = arp->ip4_over_ethernet[0];
402 arp->ip4_over_ethernet[0].mac = vr->runtime.mac;
403 arp->ip4_over_ethernet[0].ip4 = ip4_addr;
407 static_always_inline uword
408 vrrp_arp_nd_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
409 vlib_frame_t * frame, u8 is_ipv6)
411 u32 n_left_from, *from, next_index, *to_next;
413 from = vlib_frame_vector_args (frame);
414 n_left_from = frame->n_vectors;
415 next_index = node->cached_next_index;
417 while (n_left_from > 0)
421 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
423 while (n_left_from > 0 && n_left_to_next > 0)
438 b0 = vlib_get_buffer (vm, bi0);
440 vnet_feature_next (&next0, b0);
441 vrrp_arp_nd_next (b0, &next0, &vr_index, is_ipv6);
443 if (b0->flags & VLIB_BUFFER_IS_TRACED)
445 vrrp_arp_nd_trace_t *t =
446 vlib_add_trace (vm, node, b0, sizeof (*t));
452 icmp6_neighbor_solicitation_or_advertisement_header_t
455 ip0 = vlib_buffer_get_current (b0);
456 sol_adv0 = ip6_next_header (ip0);
457 t->ip.ip6 = sol_adv0->target_address;
461 ethernet_arp_header_t *arp0;
463 arp0 = vlib_buffer_get_current (b0);
464 t->ip.ip4 = arp0->ip4_over_ethernet[0].ip4;
467 vr = vrrp_vr_lookup_index (vr_index);
469 t->vr_id = vr->config.vr_id;
471 t->vr_index = vr_index;
472 t->is_ipv6 = is_ipv6;
475 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
476 n_left_to_next, bi0, next0);
479 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
482 return frame->n_vectors;
485 VLIB_NODE_FN (vrrp4_arp_input_node) (vlib_main_t * vm,
486 vlib_node_runtime_t * node,
487 vlib_frame_t * frame)
489 return vrrp_arp_nd_input_inline (vm, node, frame, 0 /* is_ipv6 */ );
493 VLIB_REGISTER_NODE (vrrp4_arp_input_node) =
495 .name = "vrrp4-arp-input",
496 .vector_size = sizeof (u32),
497 .format_trace = format_vrrp_arp_nd_input_trace,
498 .type = VLIB_NODE_TYPE_INTERNAL,
500 .n_errors = ARRAY_LEN(vrrp_error_strings),
501 .error_strings = vrrp_error_strings,
503 .n_next_nodes = VRRP_ARP_N_NEXT,
506 [VRRP_ARP_INPUT_NEXT_DROP] = "error-drop",
507 [VRRP_ARP_INPUT_NEXT_REPLY_TX] = "interface-output",
511 VNET_FEATURE_INIT (vrrp4_arp_feat_node, static) =
514 .node_name = "vrrp4-arp-input",
515 .runs_before = VNET_FEATURES ("arp-reply"),
518 VLIB_NODE_FN (vrrp6_nd_input_node) (vlib_main_t * vm,
519 vlib_node_runtime_t * node,
520 vlib_frame_t * frame)
522 return vrrp_arp_nd_input_inline (vm, node, frame, 1 /* is_ipv6 */);
526 VLIB_REGISTER_NODE (vrrp6_nd_input_node) =
528 .name = "vrrp6-nd-input",
529 .vector_size = sizeof (u32),
530 .format_trace = format_vrrp_arp_nd_input_trace,
531 .type = VLIB_NODE_TYPE_INTERNAL,
533 .n_errors = ARRAY_LEN(vrrp_error_strings),
534 .error_strings = vrrp_error_strings,
536 .n_next_nodes = VRRP_ND_N_NEXT,
539 [VRRP_ND_INPUT_NEXT_DROP] = "error-drop",
540 [VRRP_ND_INPUT_NEXT_REPLY_TX] = "interface-output",
544 VNET_FEATURE_INIT (vrrp6_nd_feat_node, static) =
546 .arc_name = "ip6-local",
547 .node_name = "vrrp6-nd-input",
548 .runs_before = VNET_FEATURES ("ip6-local-end-of-arc"),
551 static_always_inline uword
552 vrrp_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
553 vlib_frame_t * frame, u8 is_ipv6)
555 u32 n_left_from, *from;
556 vrrp_main_t *vmp = &vrrp_main;
558 from = vlib_frame_vector_args (frame);
559 n_left_from = frame->n_vectors;
561 while (n_left_from > 0)
567 vrrp_header_t *vrrp0;
569 vrrp_input_process_args_t args0;
576 b0 = vlib_get_buffer (vm, bi0);
578 ip0 = vlib_buffer_get_current (b0);
582 ip6_header_t *ip6 = ip0;
584 vrrp0 = (vrrp_header_t *) (ip6 + 1);
585 ttl0 = &ip6->hop_limit;
587 payload_len0 = clib_net_to_host_u16 (ip6->payload_length);
588 vlib_buffer_advance (b0, sizeof (*ip6));
592 ip4_header_t *ip4 = ip0;
594 vrrp0 = (vrrp_header_t *) (ip4 + 1);
597 payload_len0 = clib_net_to_host_u16 (ip4->length) - sizeof(*ip4);
598 vlib_buffer_advance (b0, sizeof (*ip4));
601 next0 = VRRP_INPUT_NEXT_DROP;
603 error0 = VRRP_ERROR_RECEIVED;
605 /* Validation from RFC 5798 sec 7.1 */
607 /* checksum set to 0 for calculation, save original value */
608 rx_csum0 = vrrp0->checksum;
611 /* Mandatory - TTL/hop limit must be 255 */
614 error0 = VRRP_ERROR_BAD_TTL;
618 /* Mandatory - VRRP version must be 3 */
619 if ((vrrp0->vrrp_version_and_type >> 4) != 3)
621 error0 = VRRP_ERROR_NOT_VERSION_3;
625 /* Mandatory - packet must be complete */
626 if (b0->current_length < sizeof (*vrrp0) +
627 ((u32) vrrp0->n_addrs) * addr_len)
629 error0 = VRRP_ERROR_INCOMPLETE_PKT;
633 /* Mandatory - checksum must be correct */
634 if (rx_csum0 != vrrp_adv_csum (ip0, vrrp0, is_ipv6, payload_len0))
636 error0 = VRRP_ERROR_BAD_CHECKSUM;
640 /* Mandatory - VR must be configured on the interface adv received on */
642 vrrp_vr_lookup (vnet_buffer(b0)->sw_if_index[VLIB_RX],
643 vrrp0->vr_id, is_ipv6)))
645 error0 = VRRP_ERROR_UNKNOWN_VR;
649 /* Optional - count of addresses should match configuration */
650 /* Could also check that addresses match, but likely to be O(n^2) */
651 if (vrrp0->n_addrs != vec_len (vr0->config.vr_addrs))
653 error0 = VRRP_ERROR_ADDR_MISMATCH;
657 /* signal main thread to process contents of packet */
658 args0.vr_index = vr0 - vmp->vrs;
661 vl_api_rpc_call_main_thread (vrrp_input_process, (u8 *) &args0,
665 vrrp0->checksum = rx_csum0; /* restore csum for correct trace output */
666 b0->error = node->errors[error0];
668 if (b0->flags & VLIB_BUFFER_IS_TRACED)
670 vrrp_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
671 size_t addr_len = (is_ipv6 ? 16 : 4);
673 t->sw_if_index = vnet_buffer(b0)->sw_if_index[VLIB_RX];
674 t->is_ipv6 = is_ipv6;
675 clib_memcpy_fast (&t->vrrp, vrrp0, sizeof (*vrrp0));
676 clib_memcpy_fast (t->addrs, (void *) (vrrp0 + 1),
677 (size_t) vrrp0->n_addrs * addr_len);
680 /* always drop, never forward or reply here */
681 vlib_set_next_frame_buffer (vm, node, next0, bi0);
687 return frame->n_vectors;
690 VLIB_NODE_FN (vrrp4_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
691 vlib_frame_t * frame)
693 return vrrp_input_inline (vm, node, frame, 0);
697 VLIB_REGISTER_NODE (vrrp4_input_node) =
699 .name = "vrrp4-input",
700 .vector_size = sizeof (u32),
701 .format_trace = format_vrrp_trace,
702 .type = VLIB_NODE_TYPE_INTERNAL,
704 .n_errors = ARRAY_LEN(vrrp_error_strings),
705 .error_strings = vrrp_error_strings,
707 .n_next_nodes = VRRP_INPUT_N_NEXT,
710 [VRRP_INPUT_NEXT_DROP] = "error-drop",
714 VLIB_NODE_FN (vrrp6_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
715 vlib_frame_t * frame)
717 return vrrp_input_inline (vm, node, frame, 1);
720 VLIB_REGISTER_NODE (vrrp6_input_node) =
722 .name = "vrrp6-input",
723 .vector_size = sizeof (u32),
724 .format_trace = format_vrrp_trace,
725 .type = VLIB_NODE_TYPE_INTERNAL,
727 .n_errors = ARRAY_LEN(vrrp_error_strings),
728 .error_strings = vrrp_error_strings,
730 .n_next_nodes = VRRP_INPUT_N_NEXT,
733 [VRRP_INPUT_NEXT_DROP] = "error-drop",
741 ip46_address_t src, dst;
742 } vrrp_accept_owner_trace_t;
744 /* packet trace format function */
746 format_vrrp_accept_owner_trace (u8 * s, va_list * args)
748 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
749 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
750 vrrp_accept_owner_trace_t *t = va_arg (*args, vrrp_accept_owner_trace_t *);
751 int ip_ver = 4, ip_type = IP46_TYPE_IP4;
756 ip_type = IP46_TYPE_IP6;
759 s = format (s, "IPv%d sw_if_index %d %U -> %U",
760 ip_ver, t->sw_if_index,
761 format_ip46_address, &t->src, ip_type,
762 format_ip46_address, &t->dst, ip_type);
767 #define foreach_vrrp_accept_owner_error \
768 _(RECEIVED, "VRRP owner accept packets received") \
769 _(PROCESSED, "VRRP owner accept advertisements processed")
773 #define _(sym,str) VRRP_ACCEPT_OWNER_ERROR_##sym,
774 foreach_vrrp_accept_owner_error
776 VRRP_ACCEPT_OWNER_N_ERROR,
777 } vrrp_accept_owner_error_t;
779 static char *vrrp_accept_owner_error_strings[] = {
780 #define _(sym,string) string,
781 foreach_vrrp_accept_owner_error
787 VRRP_ACCEPT_OWNER_NEXT_PROCESS,
788 VRRP_ACCEPT_OWNER_N_NEXT,
789 } vrrp_accept_owner_next_t;
791 static_always_inline void
792 vrrp_accept_owner_next_node (u32 sw_if_index, u8 vr_id, u8 is_ipv6,
793 u32 *next_index, u32 *error)
795 vrrp_vr_t *vr = vrrp_vr_lookup (sw_if_index, vr_id, is_ipv6);
797 if (vr && (vr->runtime.state == VRRP_VR_STATE_MASTER) &&
798 (vr->config.flags & VRRP_VR_ACCEPT))
800 *next_index = VRRP_ACCEPT_OWNER_NEXT_PROCESS;
801 *error = VRRP_ACCEPT_OWNER_ERROR_PROCESSED;
805 static_always_inline uword
806 vrrp_accept_owner_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
807 vlib_frame_t * frame, u8 is_ipv6)
809 u32 n_left_from, *from, *to_next;
810 u32 next_index = node->cached_next_index;
812 from = vlib_frame_vector_args (frame);
813 n_left_from = frame->n_vectors;
815 while (n_left_from > 0)
819 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
821 while (n_left_from >= 2 && n_left_to_next >= 2)
824 vlib_buffer_t *b0, *b1;
827 vrrp_header_t *vrrp0, *vrrp1;
828 ip4_header_t *ip40, *ip41;
829 ip6_header_t *ip60, *ip61;
830 u32 sw_if_index0, sw_if_index1;
838 b0 = vlib_get_buffer (vm, bi0);
839 b1 = vlib_get_buffer (vm, bi1);
841 /* most packets will follow feature arc */
842 vnet_feature_next (&next0, b0);
843 vnet_feature_next (&next1, b1);
845 error0 = error1 = VRRP_ACCEPT_OWNER_ERROR_RECEIVED;
847 sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
848 sw_if_index1 = vnet_buffer(b1)->sw_if_index[VLIB_RX];
850 /* find VRRP advertisements which should be sent to VRRP node */
853 ip60 = vlib_buffer_get_current (b0);
854 ip61 = vlib_buffer_get_current (b1);
856 if (PREDICT_FALSE (ip60->protocol == IP_PROTOCOL_VRRP))
858 vrrp0 = (vrrp_header_t *) (ip60 + 1);
859 vrrp_accept_owner_next_node (sw_if_index0, vrrp0->vr_id,
860 is_ipv6, &next0, &error0);
862 if (PREDICT_FALSE (ip61->protocol == IP_PROTOCOL_VRRP))
864 vrrp1 = (vrrp_header_t *) (ip61 + 1);
865 vrrp_accept_owner_next_node (sw_if_index1, vrrp1->vr_id,
866 is_ipv6, &next1, &error1);
871 ip40 = vlib_buffer_get_current (b0);
872 ip41 = vlib_buffer_get_current (b1);
874 if (PREDICT_FALSE (ip40->protocol == IP_PROTOCOL_VRRP))
876 vrrp0 = (vrrp_header_t *) (ip40 + 1);
877 vrrp_accept_owner_next_node (sw_if_index0, vrrp0->vr_id,
878 is_ipv6, &next0, &error0);
880 if (PREDICT_FALSE (ip41->protocol == IP_PROTOCOL_VRRP))
882 vrrp1 = (vrrp_header_t *) (ip41 + 1);
883 vrrp_accept_owner_next_node (sw_if_index1, vrrp1->vr_id,
884 is_ipv6, &next1, &error1);
888 b0->error = node->errors[error0];
889 b1->error = node->errors[error1];
891 if (b0->flags & VLIB_BUFFER_IS_TRACED)
893 vrrp_accept_owner_trace_t *t =
894 vlib_add_trace (vm, node, b0, sizeof (*t));
896 t->sw_if_index = sw_if_index0;
897 t->is_ipv6 = is_ipv6;
900 ip6_address_copy (&t->src.ip6, &ip60->src_address);
901 ip6_address_copy (&t->dst.ip6, &ip60->dst_address);
905 t->src.ip4.as_u32 = ip40->src_address.as_u32;
906 t->dst.ip4.as_u32 = ip40->dst_address.as_u32;
910 if (b1->flags & VLIB_BUFFER_IS_TRACED)
912 vrrp_accept_owner_trace_t *t =
913 vlib_add_trace (vm, node, b1, sizeof (*t));
915 t->sw_if_index = sw_if_index1;
916 t->is_ipv6 = is_ipv6;
919 ip6_address_copy (&t->src.ip6, &ip61->src_address);
920 ip6_address_copy (&t->dst.ip6, &ip61->dst_address);
924 t->src.ip4.as_u32 = ip41->src_address.as_u32;
925 t->dst.ip4.as_u32 = ip41->dst_address.as_u32;
934 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
935 to_next, n_left_to_next,
936 bi0, bi1, next0, next1);
939 while (n_left_from > 0 && n_left_to_next > 0)
945 vrrp_header_t *vrrp0;
953 b0 = vlib_get_buffer (vm, bi0);
955 /* most packets will follow feature arc */
956 vnet_feature_next (&next0, b0);
958 error0 = VRRP_ACCEPT_OWNER_ERROR_RECEIVED;
960 sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
962 /* find VRRP advertisements which should be sent to VRRP node */
965 ip6 = vlib_buffer_get_current (b0);
967 if (PREDICT_FALSE (ip6->protocol == IP_PROTOCOL_VRRP))
969 vrrp0 = (vrrp_header_t *) (ip6 + 1);
970 vrrp_accept_owner_next_node (sw_if_index0, vrrp0->vr_id,
971 is_ipv6, &next0, &error0);
976 ip4 = vlib_buffer_get_current (b0);
978 if (PREDICT_FALSE (ip4->protocol == IP_PROTOCOL_VRRP))
980 vrrp0 = (vrrp_header_t *) (ip4 + 1);
981 vrrp_accept_owner_next_node (sw_if_index0, vrrp0->vr_id,
982 is_ipv6, &next0, &error0);
986 b0->error = node->errors[error0];
988 if (b0->flags & VLIB_BUFFER_IS_TRACED)
990 vrrp_accept_owner_trace_t *t =
991 vlib_add_trace (vm, node, b0, sizeof (*t));
993 t->sw_if_index = sw_if_index0;
994 t->is_ipv6 = is_ipv6;
997 ip6_address_copy (&t->src.ip6, &ip6->src_address);
998 ip6_address_copy (&t->dst.ip6, &ip6->dst_address);
1002 t->src.ip4.as_u32 = ip4->src_address.as_u32;
1003 t->dst.ip4.as_u32 = ip4->dst_address.as_u32;
1010 n_left_to_next -= 1;
1012 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1013 to_next, n_left_to_next,
1017 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1020 return frame->n_vectors;
1023 VLIB_NODE_FN (vrrp4_accept_owner_input_node) (vlib_main_t * vm,
1024 vlib_node_runtime_t * node,
1025 vlib_frame_t * frame)
1027 return vrrp_accept_owner_input_inline (vm, node, frame, 0);
1030 VLIB_REGISTER_NODE (vrrp4_accept_owner_input_node) =
1032 .name = "vrrp4-accept-owner-input",
1033 .vector_size = sizeof (u32),
1034 .format_trace = format_vrrp_accept_owner_trace,
1035 .type = VLIB_NODE_TYPE_INTERNAL,
1037 .n_errors = ARRAY_LEN(vrrp_accept_owner_error_strings),
1038 .error_strings = vrrp_accept_owner_error_strings,
1040 .n_next_nodes = VRRP_ACCEPT_OWNER_N_NEXT,
1043 [VRRP_ACCEPT_OWNER_NEXT_PROCESS] = "vrrp4-input",
1047 VNET_FEATURE_INIT (vrrp4_accept_owner_mc, static) =
1049 .arc_name = "ip4-multicast",
1050 .node_name = "vrrp4-accept-owner-input",
1051 .runs_before = VNET_FEATURES ("ip4-mfib-forward-lookup"),
1054 VLIB_NODE_FN (vrrp6_accept_owner_input_node) (vlib_main_t * vm,
1055 vlib_node_runtime_t * node,
1056 vlib_frame_t * frame)
1058 return vrrp_accept_owner_input_inline (vm, node, frame, 1);
1061 VLIB_REGISTER_NODE (vrrp6_accept_owner_input_node) =
1063 .name = "vrrp6-accept-owner-input",
1064 .vector_size = sizeof (u32),
1065 .format_trace = format_vrrp_accept_owner_trace,
1066 .type = VLIB_NODE_TYPE_INTERNAL,
1068 .n_errors = ARRAY_LEN(vrrp_accept_owner_error_strings),
1069 .error_strings = vrrp_accept_owner_error_strings,
1071 .n_next_nodes = VRRP_ACCEPT_OWNER_N_NEXT,
1074 [VRRP_ACCEPT_OWNER_NEXT_PROCESS] = "vrrp6-input",
1078 VNET_FEATURE_INIT (vrrp6_accept_owner_mc, static) =
1080 .arc_name = "ip6-multicast",
1081 .node_name = "vrrp6-accept-owner-input",
1082 .runs_before = VNET_FEATURES ("ip6-mfib-forward-lookup"),
1085 static clib_error_t *
1086 vrrp_input_init (vlib_main_t *vm)
1088 clib_error_t *error;
1090 if ((error = vlib_call_init_function (vm, vrrp_init)))
1093 ip4_register_protocol (IP_PROTOCOL_VRRP, vrrp4_input_node.index);
1094 ip6_register_protocol (IP_PROTOCOL_VRRP, vrrp6_input_node.index);
1099 VLIB_INIT_FUNCTION (vrrp_input_init);
1104 * fd.io coding-style-patch-verification: ON
1107 * eval: (c-set-style "gnu")