2 *------------------------------------------------------------------
3 * Copyright (c) 2017 Intel and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
21 #include <vnet/plugin/plugin.h>
22 #include <vppinfra/lock.h>
23 #include <vppinfra/error.h>
24 #include <vppinfra/hash.h>
25 #include <vnet/vnet.h>
26 #include <vnet/ip/ip.h>
27 #include <vnet/ethernet/ethernet.h>
28 #include <vnet/ip/ip4_packet.h>
29 #include <vnet/ip/ip6_packet.h>
30 #include <vnet/dpo/dpo.h>
31 #include <vnet/adj/adj_types.h>
32 #include <vnet/fib/fib_table.h>
33 #include <vlib/vlib.h>
34 #include <vppinfra/bihash_8_8.h>
46 #define PPPOE_VER_TYPE 0x11
47 #define PPPOE_PADS 0x65
51 /* Required for pool_get_aligned */
52 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
54 /* pppoe session_id in HOST byte order */
57 /* session client addresses */
58 ip46_address_t client_ip;
60 /* the index of tx interface for pppoe encaped packet */
63 /** FIB indices - inner IP packet lookup here */
69 /* vnet intfc index */
75 #define foreach_pppoe_input_next \
76 _(DROP, "error-drop") \
77 _(IP4_INPUT, "ip4-input") \
78 _(IP6_INPUT, "ip6-input" ) \
79 _(CP_INPUT, "pppoe-cp-dispatch" ) \
83 #define _(s,n) PPPOE_INPUT_NEXT_##s,
84 foreach_pppoe_input_next
91 #define pppoe_error(n,s) PPPOE_ERROR_##n,
92 #include <pppoe/pppoe_error.def>
95 } pppoe_input_error_t;
97 extern char *pppoe_error_strings[];
100 #define MTU_BUFFERS ((MTU + vlib_buffer_get_default_data_size(vm) - 1) / vlib_buffer_get_default_data_size(vm))
101 #define NUM_BUFFERS_TO_ALLOC 32
104 * The size of pppoe session table
106 #define PPPOE_NUM_BUCKETS (64 * 1024)
107 #define PPPOE_MEMORY_SIZE (8<<20)
110 * The PPPoE key is the mac address and session ID
131 * The PPPoE entry results
146 } pppoe_entry_result_t;
150 /* Vector of encap session instances, */
151 pppoe_session_t *sessions;
153 /* For CP: vector of CP path */
154 BVT (clib_bihash) link_table;
156 /* For DP: vector of DP path */
157 BVT (clib_bihash) session_table;
159 /* Free vlib hw_if_indices */
160 u32 *free_pppoe_session_hw_if_indices;
162 /* Mapping from sw_if_index to session index */
163 u32 *session_index_by_sw_if_index;
165 /* used for pppoe cp path */
168 /* API message ID base */
172 vlib_main_t *vlib_main;
173 vnet_main_t *vnet_main;
177 extern pppoe_main_t pppoe_main;
179 extern vlib_node_registration_t pppoe_input_node;
180 extern vlib_node_registration_t pppoe_cp_dispatch_node;
187 ip46_address_t client_ip;
192 } vnet_pppoe_add_del_session_args_t;
194 int vnet_pppoe_add_del_session
195 (vnet_pppoe_add_del_session_args_t * a, u32 * sw_if_indexp);
202 } vnet_pppoe_add_del_tap_args_t;
204 int pppoe_add_del_cp (u32 cp_if_index, u8 is_add);
207 pppoe_make_key (u8 * mac_address, u16 session_id)
212 * The mac address in memory is A:B:C:D:E:F
213 * The session_id in register is H:L
215 #if CLIB_ARCH_IS_LITTLE_ENDIAN
217 * Create the in-register key as F:E:D:C:B:A:H:L
218 * In memory the key is L:H:A:B:C:D:E:F
220 temp = *((u64 *) (mac_address)) << 16;
221 temp = (temp & ~0xffff) | (u64) (session_id);
224 * Create the in-register key as H:L:A:B:C:D:E:F
225 * In memory the key is H:L:A:B:C:D:E:F
227 temp = *((u64 *) (mac_address)) >> 16;
228 temp = temp | (((u64) session_id) << 48);
235 * Perform learning on one packet based on the mac table lookup result.
237 static_always_inline void
238 pppoe_learn_process (BVT (clib_bihash) * table,
240 pppoe_entry_key_t * key0,
241 pppoe_entry_key_t * cached_key,
242 u32 * bucket0, pppoe_entry_result_t * result0)
244 /* Check mac table lookup result */
245 if (PREDICT_TRUE (result0->fields.sw_if_index == sw_if_index0))
248 * The entry was in the table, and the sw_if_index matched, the normal case
252 else if (result0->fields.sw_if_index == ~0)
254 /* The entry was not in table, so add it */
255 result0->fields.sw_if_index = sw_if_index0;
256 result0->fields.session_index = ~0;
257 cached_key->raw = ~0; /* invalidate the cache */
261 /* The entry was in the table, but with the wrong sw_if_index mapping (mac move) */
262 result0->fields.sw_if_index = sw_if_index0;
265 /* Update the entry */
266 BVT (clib_bihash_kv) kv;
268 kv.value = result0->raw;
269 BV (clib_bihash_add_del) (table, &kv, 1 /* is_add */ );
272 static_always_inline void
273 pppoe_lookup_1 (BVT (clib_bihash) * table,
274 pppoe_entry_key_t * cached_key,
275 pppoe_entry_result_t * cached_result,
278 pppoe_entry_key_t * key0,
279 u32 * bucket0, pppoe_entry_result_t * result0)
282 key0->raw = pppoe_make_key (mac0, session_id0);
285 if (key0->raw == cached_key->raw)
287 /* Hit in the one-entry cache */
288 result0->raw = cached_result->raw;
292 /* Do a regular session table lookup */
293 BVT (clib_bihash_kv) kv;
297 BV (clib_bihash_search_inline) (table, &kv);
298 result0->raw = kv.value;
300 /* Update one-entry cache */
301 cached_key->raw = key0->raw;
302 cached_result->raw = result0->raw;
306 static_always_inline void
307 pppoe_update_1 (BVT (clib_bihash) * table,
310 pppoe_entry_key_t * key0,
311 u32 * bucket0, pppoe_entry_result_t * result0)
314 key0->raw = pppoe_make_key (mac0, session_id0);
317 /* Update the entry */
318 BVT (clib_bihash_kv) kv;
320 kv.value = result0->raw;
321 BV (clib_bihash_add_del) (table, &kv, 1 /* is_add */ );
324 #endif /* _PPPOE_H */
327 * fd.io coding-style-patch-verification: ON
330 * eval: (c-set-style "gnu")