Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ethernet/arp.c: IP v4 ARP node |
| 3 | * |
| 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: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 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. |
| 16 | */ |
| 17 | |
| 18 | #ifndef included_ethernet_arp_packet_h |
| 19 | #define included_ethernet_arp_packet_h |
| 20 | |
| 21 | #define foreach_ethernet_arp_hardware_type \ |
| 22 | _ (0, reserved) \ |
| 23 | _ (1, ethernet) \ |
| 24 | _ (2, experimental_ethernet) \ |
| 25 | _ (3, ax_25) \ |
| 26 | _ (4, proteon_pronet_token_ring) \ |
| 27 | _ (5, chaos) \ |
| 28 | _ (6, ieee_802) \ |
| 29 | _ (7, arcnet) \ |
| 30 | _ (8, hyperchannel) \ |
| 31 | _ (9, lanstar) \ |
| 32 | _ (10, autonet) \ |
| 33 | _ (11, localtalk) \ |
| 34 | _ (12, localnet) \ |
| 35 | _ (13, ultra_link) \ |
| 36 | _ (14, smds) \ |
| 37 | _ (15, frame_relay) \ |
| 38 | _ (16, atm) \ |
| 39 | _ (17, hdlc) \ |
| 40 | _ (18, fibre_channel) \ |
| 41 | _ (19, atm19) \ |
| 42 | _ (20, serial_line) \ |
| 43 | _ (21, atm21) \ |
| 44 | _ (22, mil_std_188_220) \ |
| 45 | _ (23, metricom) \ |
| 46 | _ (24, ieee_1394) \ |
| 47 | _ (25, mapos) \ |
| 48 | _ (26, twinaxial) \ |
| 49 | _ (27, eui_64) \ |
| 50 | _ (28, hiparp) \ |
| 51 | _ (29, iso_7816_3) \ |
| 52 | _ (30, arpsec) \ |
| 53 | _ (31, ipsec_tunnel) \ |
| 54 | _ (32, infiniband) \ |
| 55 | _ (33, cai) \ |
| 56 | _ (34, wiegand) \ |
| 57 | _ (35, pure_ip) \ |
| 58 | _ (36, hw_exp1) \ |
| 59 | _ (256, hw_exp2) |
| 60 | |
| 61 | #define foreach_ethernet_arp_opcode \ |
| 62 | _ (reserved) \ |
| 63 | _ (request) \ |
| 64 | _ (reply) \ |
| 65 | _ (reverse_request) \ |
| 66 | _ (reverse_reply) \ |
| 67 | _ (drarp_request) \ |
| 68 | _ (drarp_reply) \ |
| 69 | _ (drarp_error) \ |
| 70 | _ (inarp_request) \ |
| 71 | _ (inarp_reply) \ |
| 72 | _ (arp_nak) \ |
| 73 | _ (mars_request) \ |
| 74 | _ (mars_multi) \ |
| 75 | _ (mars_mserv) \ |
| 76 | _ (mars_join) \ |
| 77 | _ (mars_leave) \ |
| 78 | _ (mars_nak) \ |
| 79 | _ (mars_unserv) \ |
| 80 | _ (mars_sjoin) \ |
| 81 | _ (mars_sleave) \ |
| 82 | _ (mars_grouplist_request) \ |
| 83 | _ (mars_grouplist_reply) \ |
| 84 | _ (mars_redirect_map) \ |
| 85 | _ (mapos_unarp) \ |
| 86 | _ (exp1) \ |
| 87 | _ (exp2) |
| 88 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 89 | typedef enum |
| 90 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | #define _(n,f) ETHERNET_ARP_HARDWARE_TYPE_##f = (n), |
| 92 | foreach_ethernet_arp_hardware_type |
| 93 | #undef _ |
| 94 | } ethernet_arp_hardware_type_t; |
| 95 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 96 | typedef enum |
| 97 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 98 | #define _(f) ETHERNET_ARP_OPCODE_##f, |
| 99 | foreach_ethernet_arp_opcode |
| 100 | #undef _ |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 101 | ETHERNET_ARP_N_OPCODE, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | } ethernet_arp_opcode_t; |
| 103 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 104 | typedef enum |
| 105 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 106 | IP4_ARP_NEXT_DROP, |
| 107 | IP4_ARP_N_NEXT, |
| 108 | } ip4_arp_next_t; |
| 109 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 110 | typedef enum |
| 111 | { |
Eyal Bari | bf9f02c | 2018-10-31 13:19:11 +0200 | [diff] [blame] | 112 | IP4_ARP_ERROR_THROTTLED, |
| 113 | IP4_ARP_ERROR_RESOLVED, |
| 114 | IP4_ARP_ERROR_NO_BUFFERS, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 115 | IP4_ARP_ERROR_REQUEST_SENT, |
| 116 | IP4_ARP_ERROR_NON_ARP_ADJ, |
Pierre Pfister | d076f19 | 2016-06-22 12:58:30 +0100 | [diff] [blame] | 117 | IP4_ARP_ERROR_NO_SOURCE_ADDRESS, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 118 | } ip4_arp_error_t; |
| 119 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 120 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | typedef CLIB_PACKED (struct { |
| 122 | u8 ethernet[6]; |
| 123 | ip4_address_t ip4; |
| 124 | }) ethernet_arp_ip4_over_ethernet_address_t; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 125 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 127 | typedef struct |
| 128 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 129 | u16 l2_type; |
| 130 | u16 l3_type; |
| 131 | u8 n_l2_address_bytes; |
| 132 | u8 n_l3_address_bytes; |
| 133 | u16 opcode; |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 134 | union |
| 135 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 136 | ethernet_arp_ip4_over_ethernet_address_t ip4_over_ethernet[2]; |
| 137 | |
| 138 | /* Others... */ |
| 139 | u8 data[0]; |
| 140 | }; |
| 141 | } ethernet_arp_header_t; |
| 142 | |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 143 | typedef enum ethernet_arp_entry_flags_t_ |
| 144 | { |
| 145 | ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC = (1 << 0), |
| 146 | ETHERNET_ARP_IP4_ENTRY_FLAG_DYNAMIC = (1 << 1), |
| 147 | ETHERNET_ARP_IP4_ENTRY_FLAG_NO_FIB_ENTRY = (1 << 2), |
| 148 | } __attribute__ ((packed)) ethernet_arp_entry_flags_t; |
| 149 | |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 150 | typedef struct |
| 151 | { |
| 152 | u32 sw_if_index; |
| 153 | ip4_address_t ip4_address; |
| 154 | |
| 155 | u8 ethernet_address[6]; |
| 156 | |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 157 | ethernet_arp_entry_flags_t flags; |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 158 | |
John Lo | 7f358b3 | 2018-04-28 01:19:24 -0400 | [diff] [blame] | 159 | f64 time_last_updated; |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * The index of the adj-fib entry created |
| 163 | */ |
| 164 | fib_node_index_t fib_entry_index; |
| 165 | } ethernet_arp_ip4_entry_t; |
| 166 | |
John Lo | 7f358b3 | 2018-04-28 01:19:24 -0400 | [diff] [blame] | 167 | ethernet_arp_ip4_entry_t *ip4_neighbors_pool (void); |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 168 | ethernet_arp_ip4_entry_t *ip4_neighbor_entries (u32 sw_if_index); |
| 169 | u8 *format_ethernet_arp_ip4_entry (u8 * s, va_list * va); |
| 170 | |
Steven | 9f781d8 | 2018-06-05 11:09:32 -0700 | [diff] [blame] | 171 | void send_ip4_garp (vlib_main_t * vm, u32 sw_if_index); |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 172 | void send_ip4_garp_w_addr (vlib_main_t * vm, |
Steven | 9f781d8 | 2018-06-05 11:09:32 -0700 | [diff] [blame] | 173 | const ip4_address_t * ip4_addr, u32 sw_if_index); |
John Lo | 8b81cb4 | 2017-06-26 01:40:20 -0400 | [diff] [blame] | 174 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | #endif /* included_ethernet_arp_packet_h */ |
Keith Burns (alagalah) | e70dcc8 | 2016-08-15 18:33:19 -0700 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * fd.io coding-style-patch-verification: ON |
| 179 | * |
| 180 | * Local Variables: |
| 181 | * eval: (c-set-style "gnu") |
| 182 | * End: |
| 183 | */ |