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 /* pppoe session_id in HOST byte order */
54 /* session client addresses */
55 ip46_address_t client_ip;
57 /* the index of tx interface for pppoe encaped packet */
60 /** FIB indices - inner IP packet lookup here */
66 /* vnet intfc index */
72 #define foreach_pppoe_input_next \
73 _(DROP, "error-drop") \
74 _(IP4_INPUT, "ip4-input") \
75 _(IP6_INPUT, "ip6-input" ) \
76 _(CP_INPUT, "pppoe-tap-dispatch" ) \
80 #define _(s,n) PPPOE_INPUT_NEXT_##s,
81 foreach_pppoe_input_next
88 #define pppoe_error(n,s) PPPOE_ERROR_##n,
89 #include <pppoe/pppoe_error.def>
92 } pppoe_input_error_t;
96 #define MTU_BUFFERS ((MTU + VLIB_BUFFER_DATA_SIZE - 1) / VLIB_BUFFER_DATA_SIZE)
97 #define NUM_BUFFERS_TO_ALLOC 32
100 * The size of pppoe session table
102 #define PPPOE_NUM_BUCKETS (128 * 1024)
103 #define PPPOE_MEMORY_SIZE (16<<20)
107 * The PPPoE key is the mac address and session ID
130 * The PPPoE entry results
145 } pppoe_entry_result_t;
150 /* For DP: vector of encap session instances, */
151 pppoe_session_t *sessions;
153 /* For CP: vector of CP path */
154 BVT (clib_bihash) session_table;
156 /* Free vlib hw_if_indices */
157 u32 *free_pppoe_session_hw_if_indices;
159 /* Mapping from sw_if_index to session index */
160 u32 *session_index_by_sw_if_index;
162 /* used for pppoe cp path */
165 /* API message ID base */
169 vlib_main_t *vlib_main;
170 vnet_main_t *vnet_main;
174 extern pppoe_main_t pppoe_main;
176 extern vlib_node_registration_t pppoe_input_node;
177 extern vlib_node_registration_t pppoe_tap_dispatch_node;
184 ip46_address_t client_ip;
189 } vnet_pppoe_add_del_session_args_t;
191 int vnet_pppoe_add_del_session
192 (vnet_pppoe_add_del_session_args_t * a, u32 * sw_if_indexp);
199 } vnet_pppoe_add_del_tap_args_t;
202 pppoe_make_key (u8 * mac_address, u16 session_id)
207 * The mac address in memory is A:B:C:D:E:F
208 * The session_id in register is H:L
210 #if CLIB_ARCH_IS_LITTLE_ENDIAN
212 * Create the in-register key as F:E:D:C:B:A:H:L
213 * In memory the key is L:H:A:B:C:D:E:F
215 temp = *((u64 *) (mac_address)) << 16;
216 temp = (temp & ~0xffff) | (u64) (session_id);
219 * Create the in-register key as H:L:A:B:C:D:E:F
220 * In memory the key is H:L:A:B:C:D:E:F
222 temp = *((u64 *) (mac_address)) >> 16;
223 temp = temp | (((u64) session_id) << 48);
229 static_always_inline void
230 pppoe_lookup_1 (BVT (clib_bihash) * session_table,
231 pppoe_entry_key_t * cached_key,
232 pppoe_entry_result_t * cached_result,
235 pppoe_entry_key_t * key0,
236 u32 * bucket0, pppoe_entry_result_t * result0)
239 key0->raw = pppoe_make_key (mac0, session_id0);
242 if (key0->raw == cached_key->raw)
244 /* Hit in the one-entry cache */
245 result0->raw = cached_result->raw;
249 /* Do a regular session table lookup */
250 BVT (clib_bihash_kv) kv;
254 BV (clib_bihash_search_inline) (session_table, &kv);
255 result0->raw = kv.value;
257 /* Update one-entry cache */
258 cached_key->raw = key0->raw;
259 cached_result->raw = result0->raw;
263 static_always_inline void
264 pppoe_update_1 (BVT (clib_bihash) * session_table,
267 pppoe_entry_key_t * key0,
268 u32 * bucket0, pppoe_entry_result_t * result0)
271 key0->raw = pppoe_make_key (mac0, session_id0);
274 /* Update the entry */
275 BVT (clib_bihash_kv) kv;
277 kv.value = result0->raw;
278 BV (clib_bihash_add_del) (session_table, &kv, 1 /* is_add */ );
281 #endif /* _PPPOE_H */
284 * fd.io coding-style-patch-verification: ON
287 * eval: (c-set-style "gnu")