2 * ethernet/arp.c: IP v4 ARP node
4 * Copyright (c) 2010 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vnet/arp/arp.h>
19 #include <vnet/arp/arp_packet.h>
21 #include <vnet/fib/ip4_fib.h>
22 #include <vnet/fib/fib_entry_src.h>
23 #include <vnet/adj/adj_nbr.h>
24 #include <vnet/adj/adj_mcast.h>
25 #include <vnet/pg/pg.h>
27 #include <vnet/ip-neighbor/ip_neighbor.h>
28 #include <vnet/ip-neighbor/ip4_neighbor.h>
29 #include <vnet/ip-neighbor/ip_neighbor_dp.h>
31 #include <vlibmemory/api.h>
37 * This file contains code to manage the IPv4 ARP tables (IP Address
38 * to MAC Address lookup).
42 * @brief Per-interface ARP configuration and state
44 typedef struct ethernet_arp_interface_t_
47 * Is ARP enabled on this interface
50 } ethernet_arp_interface_t;
54 /* Hash tables mapping name to opcode. */
55 uword *opcode_by_name;
57 /** Per interface state */
58 ethernet_arp_interface_t *ethernet_arp_by_sw_if_index;
60 /* ARP feature arc index */
62 } ethernet_arp_main_t;
64 static ethernet_arp_main_t ethernet_arp_main;
66 static const u8 vrrp_prefix[] = { 0x00, 0x00, 0x5E, 0x00, 0x01 };
69 unformat_ethernet_arp_opcode_host_byte_order (unformat_input_t * input,
72 int *result = va_arg (*args, int *);
73 ethernet_arp_main_t *am = ðernet_arp_main;
77 if (unformat (input, "0x%x", &x) || unformat (input, "%d", &x))
86 if (unformat_user (input, unformat_vlib_number_by_name,
87 am->opcode_by_name, &i))
97 unformat_ethernet_arp_opcode_net_byte_order (unformat_input_t * input,
100 int *result = va_arg (*args, int *);
102 (input, unformat_ethernet_arp_opcode_host_byte_order, result))
105 *result = clib_host_to_net_u16 ((u16) * result);
112 } ethernet_arp_input_trace_t;
115 format_ethernet_arp_input_trace (u8 * s, va_list * va)
117 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
118 CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
119 ethernet_arp_input_trace_t *t = va_arg (*va, ethernet_arp_input_trace_t *);
122 format_ethernet_arp_header,
123 t->packet_data, sizeof (t->packet_data));
129 arp_is_enabled (ethernet_arp_main_t * am, u32 sw_if_index)
131 if (vec_len (am->ethernet_arp_by_sw_if_index) <= sw_if_index)
134 return (am->ethernet_arp_by_sw_if_index[sw_if_index].enabled);
138 arp_enable (ethernet_arp_main_t * am, u32 sw_if_index)
140 if (arp_is_enabled (am, sw_if_index))
143 vec_validate (am->ethernet_arp_by_sw_if_index, sw_if_index);
145 am->ethernet_arp_by_sw_if_index[sw_if_index].enabled = 1;
147 vnet_feature_enable_disable ("arp", "arp-reply", sw_if_index, 1, NULL, 0);
148 vnet_feature_enable_disable ("arp", "arp-disabled", sw_if_index, 0, NULL,
153 arp_disable (ethernet_arp_main_t * am, u32 sw_if_index)
155 if (!arp_is_enabled (am, sw_if_index))
158 vnet_feature_enable_disable ("arp", "arp-disabled", sw_if_index, 1, NULL,
160 vnet_feature_enable_disable ("arp", "arp-reply", sw_if_index, 0, NULL, 0);
162 am->ethernet_arp_by_sw_if_index[sw_if_index].enabled = 0;
166 arp_unnumbered (vlib_buffer_t * p0,
167 u32 input_sw_if_index, u32 conn_sw_if_index)
169 vnet_main_t *vnm = vnet_get_main ();
170 vnet_interface_main_t *vim = &vnm->interface_main;
171 vnet_sw_interface_t *si;
173 /* verify that the input interface is unnumbered to the connected.
174 * the connected interface is the interface on which the subnet is
176 si = &vim->sw_interfaces[input_sw_if_index];
178 if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED &&
179 (si->unnumbered_sw_if_index == conn_sw_if_index)))
181 /* the input interface is not unnumbered to the interface on which
182 * the sub-net is configured that covers the ARP request.
183 * So this is not the case for unnumbered.. */
191 arp_learn (u32 sw_if_index,
192 const ethernet_arp_ip4_over_ethernet_address_t * addr)
194 ip_neighbor_learn_t l = {
200 .sw_if_index = sw_if_index,
203 ip_neighbor_learn_dp (&l);
205 return (ARP_ERROR_L3_SRC_ADDRESS_LEARNED);
208 typedef enum arp_input_next_t_
211 ARP_INPUT_NEXT_DISABLED,
216 arp_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
218 u32 n_left_from, next_index, *from, *to_next, n_left_to_next;
219 ethernet_arp_main_t *am = ðernet_arp_main;
221 from = vlib_frame_vector_args (frame);
222 n_left_from = frame->n_vectors;
223 next_index = node->cached_next_index;
225 if (node->flags & VLIB_NODE_FLAG_TRACE)
226 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
228 sizeof (ethernet_arp_input_trace_t));
230 while (n_left_from > 0)
232 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
234 while (n_left_from > 0 && n_left_to_next > 0)
236 const ethernet_arp_header_t *arp0;
237 arp_input_next_t next0;
241 pi0 = to_next[0] = from[0];
247 p0 = vlib_get_buffer (vm, pi0);
248 arp0 = vlib_buffer_get_current (p0);
250 error0 = ARP_ERROR_REPLIES_SENT;
251 next0 = ARP_INPUT_NEXT_DROP;
253 error0 = (arp0->l2_type != clib_net_to_host_u16 (
254 ETHERNET_ARP_HARDWARE_TYPE_ethernet) ?
255 ARP_ERROR_L2_TYPE_NOT_ETHERNET :
257 error0 = (arp0->l3_type != clib_net_to_host_u16 (ETHERNET_TYPE_IP4) ?
258 ARP_ERROR_L3_TYPE_NOT_IP4 :
260 error0 = (0 == arp0->ip4_over_ethernet[0].ip4.as_u32 ?
261 ARP_ERROR_L3_DST_ADDRESS_UNSET :
264 if (ARP_ERROR_REPLIES_SENT == error0)
266 next0 = ARP_INPUT_NEXT_DISABLED;
267 vnet_feature_arc_start (am->feature_arc_index,
268 vnet_buffer (p0)->sw_if_index[VLIB_RX],
272 p0->error = node->errors[error0];
274 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
275 n_left_to_next, pi0, next0);
278 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
281 return frame->n_vectors;
284 typedef enum arp_disabled_next_t_
286 ARP_DISABLED_NEXT_DROP,
288 } arp_disabled_next_t;
291 arp_disabled (vlib_main_t * vm,
292 vlib_node_runtime_t * node, vlib_frame_t * frame)
294 u32 n_left_from, next_index, *from, *to_next, n_left_to_next;
296 from = vlib_frame_vector_args (frame);
297 n_left_from = frame->n_vectors;
298 next_index = node->cached_next_index;
300 if (node->flags & VLIB_NODE_FLAG_TRACE)
301 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
303 sizeof (ethernet_arp_input_trace_t));
305 while (n_left_from > 0)
307 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
309 while (n_left_from > 0 && n_left_to_next > 0)
311 arp_disabled_next_t next0 = ARP_DISABLED_NEXT_DROP;
315 next0 = ARP_DISABLED_NEXT_DROP;
316 error0 = ARP_ERROR_DISABLED;
318 pi0 = to_next[0] = from[0];
324 p0 = vlib_get_buffer (vm, pi0);
325 p0->error = node->errors[error0];
327 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
328 n_left_to_next, pi0, next0);
331 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
334 return frame->n_vectors;
337 enum arp_dst_fib_type
345 * we're looking for FIB sources that indicate the destination
346 * is attached. There may be interposed DPO prior to the one
349 static enum arp_dst_fib_type
350 arp_dst_fib_check (const fib_node_index_t fei, fib_entry_flag_t * flags)
352 const fib_entry_t *entry = fib_entry_get (fei);
353 const fib_entry_src_t *entry_src;
355 FOR_EACH_SRC_ADDED(entry, entry_src, src,
357 *flags = fib_entry_get_flags_for_source (fei, src);
358 if (fib_entry_is_sourced (fei, FIB_SOURCE_ADJ))
359 return ARP_DST_FIB_ADJ;
360 else if (FIB_ENTRY_FLAG_CONNECTED & *flags)
361 return ARP_DST_FIB_CONN;
364 return ARP_DST_FIB_NONE;
368 arp_reply (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
370 vnet_main_t *vnm = vnet_get_main ();
371 u32 n_left_from, next_index, *from, *to_next;
372 u32 n_replies_sent = 0;
374 from = vlib_frame_vector_args (frame);
375 n_left_from = frame->n_vectors;
376 next_index = node->cached_next_index;
378 if (node->flags & VLIB_NODE_FLAG_TRACE)
379 vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors,
381 sizeof (ethernet_arp_input_trace_t));
383 while (n_left_from > 0)
387 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
389 while (n_left_from > 0 && n_left_to_next > 0)
392 ethernet_arp_header_t *arp0;
393 ethernet_header_t *eth_rx;
394 const ip4_address_t *if_addr0;
395 u32 pi0, error0, next0, sw_if_index0, conn_sw_if_index0, fib_index0;
396 u8 dst_is_local0, is_vrrp_reply0;
397 fib_node_index_t dst_fei, src_fei;
398 const fib_prefix_t *pfx0;
399 fib_entry_flag_t src_flags, dst_flags;
408 p0 = vlib_get_buffer (vm, pi0);
409 arp0 = vlib_buffer_get_current (p0);
410 /* Fill in ethernet header. */
411 eth_rx = ethernet_buffer_get_header (p0);
413 next0 = ARP_REPLY_NEXT_DROP;
414 error0 = ARP_ERROR_REPLIES_SENT;
415 sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX];
417 /* Check that IP address is local and matches incoming interface. */
418 fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
419 if (~0 == fib_index0)
421 error0 = ARP_ERROR_INTERFACE_NO_TABLE;
426 dst_fei = ip4_fib_table_lookup (ip4_fib_get (fib_index0),
427 &arp0->ip4_over_ethernet[1].ip4, 32);
428 conn_sw_if_index0 = fib_entry_get_any_resolving_interface (dst_fei);
432 * we're looking for FIB entries that indicate the source
433 * is attached. There may be more specific non-attached
434 * routes that match the source, but these do not influence
435 * whether we respond to an ARP request, i.e. they do not
436 * influence whether we are the correct way for the sender
437 * to reach us, they only affect how we reach the sender.
439 fib_entry_t *src_fib_entry;
440 const fib_prefix_t *pfx;
441 fib_entry_src_t *src;
451 src_fei = ip4_fib_table_lookup (ip4_fib_get (fib_index0),
453 ip4_over_ethernet[0].ip4,
455 src_fib_entry = fib_entry_get (src_fei);
458 * It's possible that the source that provides the
459 * flags we need, or the flags we must not have,
460 * is not the best source, so check then all.
462 FOR_EACH_SRC_ADDED(src_fib_entry, src, source,
464 src_flags = fib_entry_get_flags_for_source (src_fei, source);
466 /* Reject requests/replies with our local interface
468 if (FIB_ENTRY_FLAG_LOCAL & src_flags)
470 error0 = ARP_ERROR_L3_SRC_ADDRESS_IS_LOCAL;
472 * When VPP has an interface whose address is also
473 * applied to a TAP interface on the host, then VPP's
474 * TAP interface will be unnumbered to the 'real'
475 * interface and do proxy ARP from the host.
476 * The curious aspect of this setup is that ARP requests
477 * from the host will come from the VPP's own address.
478 * So don't drop immediately here, instead go see if this
479 * is a proxy ARP case.
483 /* A Source must also be local to subnet of matching
484 * interface address. */
485 if ((FIB_ENTRY_FLAG_ATTACHED & src_flags) ||
486 (FIB_ENTRY_FLAG_CONNECTED & src_flags))
493 * The packet was sent from an address that is not
494 * connected nor attached i.e. it is not from an
495 * address that is covered by a link's sub-net,
496 * nor is it a already learned host resp.
501 * shorter mask lookup for the next iteration.
503 pfx = fib_entry_get_prefix (src_fei);
504 mask = pfx->fp_len - 1;
507 * continue until we hit the default route or we find
508 * the attached we are looking for. The most likely
509 * outcome is we find the attached with the first source
510 * on the first lookup.
514 !fib_entry_is_sourced (src_fei, FIB_SOURCE_DEFAULT_ROUTE));
517 !arp_unnumbered (p0, sw_if_index0, conn_sw_if_index0))
520 * the matching route is a not attached and not unnumbered,
521 * i.e. it was added as a result of routing, rather than
522 * interface/ARP configuration. If the matching route is not
523 * a host route (i.e. a /32)
525 error0 = ARP_ERROR_L3_SRC_ADDRESS_NOT_LOCAL;
530 switch (arp_dst_fib_check (dst_fei, &dst_flags))
532 case ARP_DST_FIB_ADJ:
534 * We matched an adj-fib on ths source subnet (a /32 previously
535 * added as a result of ARP). If this request is a gratuitous
536 * ARP, then learn from it.
537 * The check for matching an adj-fib, is to prevent hosts
538 * from spamming us with gratuitous ARPS that might otherwise
541 if (conn_sw_if_index0 != sw_if_index0)
542 error0 = ARP_ERROR_L3_DST_ADDRESS_NOT_LOCAL;
543 else if (arp0->ip4_over_ethernet[0].ip4.as_u32 ==
544 arp0->ip4_over_ethernet[1].ip4.as_u32)
546 vlib_increment_simple_counter (
547 &ip_neighbor_counters[AF_IP4]
548 .ipnc[VLIB_RX][IP_NEIGHBOR_CTR_GRAT],
549 vm->thread_index, sw_if_index0, 1);
551 arp_learn (sw_if_index0, &arp0->ip4_over_ethernet[0]);
554 case ARP_DST_FIB_CONN:
555 /* destination is connected, continue to process */
557 case ARP_DST_FIB_NONE:
558 /* destination is not connected, stop here */
559 error0 = ARP_ERROR_L3_DST_ADDRESS_NOT_LOCAL;
563 dst_is_local0 = (FIB_ENTRY_FLAG_LOCAL & dst_flags);
564 pfx0 = fib_entry_get_prefix (dst_fei);
565 if_addr0 = &pfx0->fp_addr.ip4;
569 clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply))
572 (arp0->ip4_over_ethernet[0].mac.bytes, vrrp_prefix,
573 sizeof (vrrp_prefix))));
575 /* Trash ARP packets whose ARP-level source addresses do not
576 match their L2-frame-level source addresses, unless it's
577 a reply from a VRRP virtual router */
578 if (!ethernet_mac_address_equal
579 (eth_rx->src_address,
580 arp0->ip4_over_ethernet[0].mac.bytes) && !is_vrrp_reply0)
582 error0 = ARP_ERROR_L2_ADDRESS_MISMATCH;
586 vlib_increment_simple_counter (
587 &ip_neighbor_counters[AF_IP4]
588 .ipnc[VLIB_RX][arp0->opcode == clib_host_to_net_u16 (
589 ETHERNET_ARP_OPCODE_reply) ?
590 IP_NEIGHBOR_CTR_REPLY :
591 IP_NEIGHBOR_CTR_REQUEST],
592 vm->thread_index, sw_if_index0, 1);
594 /* Learn or update sender's mapping only for replies to addresses
595 * that are local to the subnet */
597 clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply))
601 arp_learn (sw_if_index0, &arp0->ip4_over_ethernet[0]);
603 /* a reply for a non-local destination could be a GARP.
604 * GARPs for hosts we know were handled above, so this one
606 error0 = ARP_ERROR_L3_DST_ADDRESS_NOT_LOCAL;
610 else if (arp0->opcode ==
611 clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_request) &&
612 (dst_is_local0 == 0))
617 /* Honor unnumbered interface, if any */
618 if (sw_if_index0 != conn_sw_if_index0 ||
619 sw_if_index0 != fib_entry_get_resolving_interface (src_fei))
622 * The interface the ARP is sent to or was received on is
623 * not the interface on which the covering prefix is
624 * configured. Maybe this is a case for unnumbered.
626 if (!arp_unnumbered (p0, sw_if_index0, conn_sw_if_index0))
628 error0 = ARP_ERROR_UNNUMBERED_MISMATCH;
632 if (arp0->ip4_over_ethernet[0].ip4.as_u32 ==
633 arp0->ip4_over_ethernet[1].ip4.as_u32)
635 error0 = ARP_ERROR_GRATUITOUS_ARP;
639 next0 = arp_mk_reply (vnm, p0, sw_if_index0, if_addr0, arp0, eth_rx);
641 /* We are going to reply to this request, so, in the absence of
642 errors, learn the sender */
644 error0 = arp_learn (sw_if_index0, &arp0->ip4_over_ethernet[1]);
646 vlib_increment_simple_counter (
647 &ip_neighbor_counters[AF_IP4].ipnc[VLIB_TX][IP_NEIGHBOR_CTR_REPLY],
648 vm->thread_index, sw_if_index0, 1);
653 vnet_feature_next (&next0, p0);
656 p0->error = node->errors[error0];
659 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
660 n_left_to_next, pi0, next0);
663 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
666 vlib_error_count (vm, node->node_index, ARP_ERROR_REPLIES_SENT,
669 return frame->n_vectors;
674 VLIB_REGISTER_NODE (arp_input_node, static) =
676 .function = arp_input,
678 .vector_size = sizeof (u32),
679 .n_errors = ARP_N_ERROR,
680 .error_counters = arp_error_counters,
681 .n_next_nodes = ARP_INPUT_N_NEXT,
683 [ARP_INPUT_NEXT_DROP] = "error-drop",
684 [ARP_INPUT_NEXT_DISABLED] = "arp-disabled",
686 .format_buffer = format_ethernet_arp_header,
687 .format_trace = format_ethernet_arp_input_trace,
690 VLIB_REGISTER_NODE (arp_disabled_node, static) =
692 .function = arp_disabled,
693 .name = "arp-disabled",
694 .vector_size = sizeof (u32),
695 .n_errors = ARP_N_ERROR,
696 .error_counters = arp_error_counters,
697 .n_next_nodes = ARP_DISABLED_N_NEXT,
699 [ARP_INPUT_NEXT_DROP] = "error-drop",
701 .format_buffer = format_ethernet_arp_header,
702 .format_trace = format_ethernet_arp_input_trace,
705 VLIB_REGISTER_NODE (arp_reply_node, static) =
707 .function = arp_reply,
709 .vector_size = sizeof (u32),
710 .n_errors = ARP_N_ERROR,
711 .error_counters = arp_error_counters,
712 .n_next_nodes = ARP_REPLY_N_NEXT,
714 [ARP_REPLY_NEXT_DROP] = "error-drop",
715 [ARP_REPLY_NEXT_REPLY_TX] = "interface-output",
717 .format_buffer = format_ethernet_arp_header,
718 .format_trace = format_ethernet_arp_input_trace,
721 /* Built-in ARP rx feature path definition */
722 VNET_FEATURE_ARC_INIT (arp_feat, static) =
725 .start_nodes = VNET_FEATURES ("arp-input"),
726 .last_in_arc = "error-drop",
727 .arc_index_ptr = ðernet_arp_main.feature_arc_index,
730 VNET_FEATURE_INIT (arp_reply_feat_node, static) =
733 .node_name = "arp-reply",
734 .runs_before = VNET_FEATURES ("arp-disabled"),
737 VNET_FEATURE_INIT (arp_proxy_feat_node, static) =
740 .node_name = "arp-proxy",
741 .runs_after = VNET_FEATURES ("arp-reply"),
742 .runs_before = VNET_FEATURES ("arp-disabled"),
745 VNET_FEATURE_INIT (arp_disabled_feat_node, static) =
748 .node_name = "arp-disabled",
749 .runs_before = VNET_FEATURES ("error-drop"),
752 VNET_FEATURE_INIT (arp_drop_feat_node, static) =
755 .node_name = "error-drop",
756 .runs_before = 0, /* last feature */
762 pg_edit_t l2_type, l3_type;
763 pg_edit_t n_l2_address_bytes, n_l3_address_bytes;
769 } ip4_over_ethernet[2];
770 } pg_ethernet_arp_header_t;
773 pg_ethernet_arp_header_init (pg_ethernet_arp_header_t * p)
775 /* Initialize fields that are not bit fields in the IP header. */
776 #define _(f) pg_edit_init (&p->f, ethernet_arp_header_t, f);
779 _(n_l2_address_bytes);
780 _(n_l3_address_bytes);
782 _(ip4_over_ethernet[0].mac);
783 _(ip4_over_ethernet[0].ip4);
784 _(ip4_over_ethernet[1].mac);
785 _(ip4_over_ethernet[1].ip4);
790 unformat_pg_arp_header (unformat_input_t * input, va_list * args)
792 pg_stream_t *s = va_arg (*args, pg_stream_t *);
793 pg_ethernet_arp_header_t *p;
796 p = pg_create_edit_group (s, sizeof (p[0]), sizeof (ethernet_arp_header_t),
798 pg_ethernet_arp_header_init (p);
801 pg_edit_set_fixed (&p->l2_type, ETHERNET_ARP_HARDWARE_TYPE_ethernet);
802 pg_edit_set_fixed (&p->l3_type, ETHERNET_TYPE_IP4);
803 pg_edit_set_fixed (&p->n_l2_address_bytes, 6);
804 pg_edit_set_fixed (&p->n_l3_address_bytes, 4);
806 if (!unformat (input, "%U: %U/%U -> %U/%U",
808 unformat_ethernet_arp_opcode_net_byte_order, &p->opcode,
810 unformat_mac_address_t, &p->ip4_over_ethernet[0].mac,
812 unformat_ip4_address, &p->ip4_over_ethernet[0].ip4,
814 unformat_mac_address_t, &p->ip4_over_ethernet[1].mac,
816 unformat_ip4_address, &p->ip4_over_ethernet[1].ip4))
818 /* Free up any edits we may have added. */
819 pg_free_edit_group (s);
826 * callback when an interface address is added or deleted
829 arp_enable_disable_interface (ip4_main_t * im,
830 uword opaque, u32 sw_if_index, u32 is_enable)
832 ethernet_arp_main_t *am = ðernet_arp_main;
835 arp_enable (am, sw_if_index);
837 arp_disable (am, sw_if_index);
841 * Remove any arp entries associated with the specified interface
843 static clib_error_t *
844 vnet_arp_add_del_sw_interface (vnet_main_t * vnm, u32 sw_if_index, u32 is_add)
846 ethernet_arp_main_t *am = ðernet_arp_main;
848 arp_disable (am, sw_if_index);
852 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (vnet_arp_add_del_sw_interface);
854 const static ip_neighbor_vft_t arp_vft = {
855 .inv_proxy4_add = arp_proxy_add,
856 .inv_proxy4_del = arp_proxy_del,
857 .inv_proxy4_enable = arp_proxy_enable,
858 .inv_proxy4_disable = arp_proxy_disable,
861 static clib_error_t *
862 ethernet_arp_init (vlib_main_t * vm)
864 ethernet_arp_main_t *am = ðernet_arp_main;
865 ip4_main_t *im = &ip4_main;
868 ethernet_register_input_type (vm, ETHERNET_TYPE_ARP, arp_input_node.index);
870 pn = pg_get_node (arp_input_node.index);
871 pn->unformat_edit = unformat_pg_arp_header;
873 am->opcode_by_name = hash_create_string (0, sizeof (uword));
874 #define _(o) hash_set_mem (am->opcode_by_name, #o, ETHERNET_ARP_OPCODE_##o);
875 foreach_ethernet_arp_opcode;
878 /* don't trace ARP error packets */
880 vlib_node_runtime_t *rt =
881 vlib_node_get_runtime (vm, arp_input_node.index);
883 vnet_pcap_drop_trace_filter_add_del (rt->errors[ARP_ERROR_REPLIES_SENT],
885 vnet_pcap_drop_trace_filter_add_del (rt->errors[ARP_ERROR_DISABLED], 1);
886 vnet_pcap_drop_trace_filter_add_del (
887 rt->errors[ARP_ERROR_L2_TYPE_NOT_ETHERNET], 1);
888 vnet_pcap_drop_trace_filter_add_del (rt->errors[ARP_ERROR_L3_TYPE_NOT_IP4],
890 vnet_pcap_drop_trace_filter_add_del (
891 rt->errors[ARP_ERROR_L3_SRC_ADDRESS_NOT_LOCAL], 1);
892 vnet_pcap_drop_trace_filter_add_del (
893 rt->errors[ARP_ERROR_L3_DST_ADDRESS_NOT_LOCAL], 1);
894 vnet_pcap_drop_trace_filter_add_del (
895 rt->errors[ARP_ERROR_L3_DST_ADDRESS_UNSET], 1);
896 vnet_pcap_drop_trace_filter_add_del (
897 rt->errors[ARP_ERROR_L3_SRC_ADDRESS_IS_LOCAL], 1);
898 vnet_pcap_drop_trace_filter_add_del (
899 rt->errors[ARP_ERROR_L3_SRC_ADDRESS_LEARNED], 1);
900 vnet_pcap_drop_trace_filter_add_del (
901 rt->errors[ARP_ERROR_REPLIES_RECEIVED], 1);
902 vnet_pcap_drop_trace_filter_add_del (
903 rt->errors[ARP_ERROR_OPCODE_NOT_REQUEST], 1);
904 vnet_pcap_drop_trace_filter_add_del (
905 rt->errors[ARP_ERROR_PROXY_ARP_REPLIES_SENT], 1);
906 vnet_pcap_drop_trace_filter_add_del (
907 rt->errors[ARP_ERROR_L2_ADDRESS_MISMATCH], 1);
908 vnet_pcap_drop_trace_filter_add_del (rt->errors[ARP_ERROR_GRATUITOUS_ARP],
910 vnet_pcap_drop_trace_filter_add_del (
911 rt->errors[ARP_ERROR_INTERFACE_NO_TABLE], 1);
912 vnet_pcap_drop_trace_filter_add_del (
913 rt->errors[ARP_ERROR_INTERFACE_NOT_IP_ENABLED], 1);
914 vnet_pcap_drop_trace_filter_add_del (
915 rt->errors[ARP_ERROR_UNNUMBERED_MISMATCH], 1);
919 ip4_enable_disable_interface_callback_t cb = {
920 .function = arp_enable_disable_interface,
922 vec_add1 (im->enable_disable_interface_callbacks, cb);
925 ip_neighbor_register (AF_IP4, &arp_vft);
930 VLIB_INIT_FUNCTION (ethernet_arp_init) =
932 .runs_after = VLIB_INITS("ethernet_init",
937 * fd.io coding-style-patch-verification: ON
940 * eval: (c-set-style "gnu")