FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
pppoe.h
Go to the documentation of this file.
1 /*
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:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  *------------------------------------------------------------------
16  */
17 
18 #ifndef _PPPOE_H
19 #define _PPPOE_H
20 
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>
35 
36 
37 typedef struct
38 {
45 
46 #define PPPOE_VER_TYPE 0x11
47 #define PPPOE_PADS 0x65
48 
49 typedef struct
50 {
51  /* Required for pool_get_aligned */
52  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
53 
54  /* pppoe session_id in HOST byte order */
56 
57  /* session client addresses */
58  ip46_address_t client_ip;
59 
60  /* the index of tx interface for pppoe encaped packet */
62 
63  /** FIB indices - inner IP packet lookup here */
65 
66  u8 local_mac[6];
67  u8 client_mac[6];
68 
69  /* vnet intfc index */
72 
74 
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" ) \
80 
81 typedef enum
82 {
83 #define _(s,n) PPPOE_INPUT_NEXT_##s,
85 #undef _
88 
89 typedef enum
90 {
91 #define pppoe_error(n,s) PPPOE_ERROR_##n,
92 #include <pppoe/pppoe_error.def>
93 #undef pppoe_error
96 
97 extern char *pppoe_error_strings[];
98 
99 #define MTU 1500
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
102 
103 /*
104  * The size of pppoe session table
105  */
106 #define PPPOE_NUM_BUCKETS (64 * 1024)
107 #define PPPOE_MEMORY_SIZE (8<<20)
108 
109 /* *INDENT-OFF* */
110 /*
111  * The PPPoE key is the mac address and session ID
112  */
113 typedef struct
114 {
115  union
116  {
117  struct
118  {
120  u8 mac[6];
121  } fields;
122  struct
123  {
126  } words;
128  };
130 /* *INDENT-ON* */
131 
132 /* *INDENT-OFF* */
133 /*
134  * The PPPoE entry results
135  */
136 typedef struct
137 {
138  union
139  {
140  struct
141  {
143 
145 
146  } fields;
148  };
150 /* *INDENT-ON* */
151 
152 typedef struct
153 {
154  /* Vector of encap session instances, */
156 
157  /* For CP: vector of CP path */
158  BVT (clib_bihash) link_table;
159 
160  /* For DP: vector of DP path */
161  BVT (clib_bihash) session_table;
162 
163  /* Free vlib hw_if_indices */
165 
166  /* Mapping from sw_if_index to session index */
168 
169  /* used for pppoe cp path */
171 
172  /* API message ID base */
174 
175  /* convenience */
178 
179 } pppoe_main_t;
180 
181 extern pppoe_main_t pppoe_main;
182 
185 
186 typedef struct
187 {
191  ip46_address_t client_ip;
194  u8 local_mac[6];
195  u8 client_mac[6];
197 
199  (vnet_pppoe_add_del_session_args_t * a, u32 * sw_if_indexp);
200 
201 typedef struct
202 {
207 
208 int pppoe_add_del_cp (u32 cp_if_index, u8 is_add);
209 
212 {
213  u64 temp;
214 
215  /*
216  * The mac address in memory is A:B:C:D:E:F
217  * The session_id in register is H:L
218  */
219 #if CLIB_ARCH_IS_LITTLE_ENDIAN
220  /*
221  * Create the in-register key as F:E:D:C:B:A:H:L
222  * In memory the key is L:H:A:B:C:D:E:F
223  */
224  temp = *((u64 *) (mac_address)) << 16;
225  temp = (temp & ~0xffff) | (u64) (session_id);
226 #else
227  /*
228  * Create the in-register key as H:L:A:B:C:D:E:F
229  * In memory the key is H:L:A:B:C:D:E:F
230  */
231  temp = *((u64 *) (mac_address)) >> 16;
232  temp = temp | (((u64) session_id) << 48);
233 #endif
234 
235  return temp;
236 }
237 
238 /**
239  * Perform learning on one packet based on the mac table lookup result.
240  * */
242 pppoe_learn_process (BVT (clib_bihash) * table,
243  u32 sw_if_index0,
244  pppoe_entry_key_t * key0,
245  pppoe_entry_key_t * cached_key,
246  u32 * bucket0, pppoe_entry_result_t * result0)
247 {
248  /* Check mac table lookup result */
249  if (PREDICT_TRUE (result0->fields.sw_if_index == sw_if_index0))
250  {
251  /*
252  * The entry was in the table, and the sw_if_index matched, the normal case
253  */
254  return;
255  }
256  else if (result0->fields.sw_if_index == ~0)
257  {
258  /* The entry was not in table, so add it */
259  result0->fields.sw_if_index = sw_if_index0;
260  result0->fields.session_index = ~0;
261  cached_key->raw = ~0; /* invalidate the cache */
262  }
263  else
264  {
265  /* The entry was in the table, but with the wrong sw_if_index mapping (mac move) */
266  result0->fields.sw_if_index = sw_if_index0;
267  }
268 
269  /* Update the entry */
270  BVT (clib_bihash_kv) kv;
271  kv.key = key0->raw;
272  kv.value = result0->raw;
273  BV (clib_bihash_add_del) (table, &kv, 1 /* is_add */ );
274 }
275 
277 pppoe_lookup_1 (BVT (clib_bihash) * table,
278  pppoe_entry_key_t * cached_key,
279  pppoe_entry_result_t * cached_result,
280  u8 * mac0,
281  u16 session_id0,
282  pppoe_entry_key_t * key0,
283  u32 * bucket0, pppoe_entry_result_t * result0)
284 {
285  /* set up key */
286  key0->raw = pppoe_make_key (mac0, session_id0);
287  *bucket0 = ~0;
288 
289  if (key0->raw == cached_key->raw)
290  {
291  /* Hit in the one-entry cache */
292  result0->raw = cached_result->raw;
293  }
294  else
295  {
296  /* Do a regular session table lookup */
297  BVT (clib_bihash_kv) kv;
298 
299  kv.key = key0->raw;
300  kv.value = ~0ULL;
301  BV (clib_bihash_search_inline) (table, &kv);
302  result0->raw = kv.value;
303 
304  /* Update one-entry cache */
305  cached_key->raw = key0->raw;
306  cached_result->raw = result0->raw;
307  }
308 }
309 
311 pppoe_update_1 (BVT (clib_bihash) * table,
312  u8 * mac0,
313  u16 session_id0,
314  pppoe_entry_key_t * key0,
315  u32 * bucket0, pppoe_entry_result_t * result0)
316 {
317  /* set up key */
318  key0->raw = pppoe_make_key (mac0, session_id0);
319  *bucket0 = ~0;
320 
321  /* Update the entry */
322  BVT (clib_bihash_kv) kv;
323  kv.key = key0->raw;
324  kv.value = result0->raw;
325  BV (clib_bihash_add_del) (table, &kv, 1 /* is_add */ );
326 
327 }
328 #endif /* _PPPOE_H */
329 
330 /*
331  * fd.io coding-style-patch-verification: ON
332  *
333  * Local Variables:
334  * eval: (c-set-style "gnu")
335  * End:
336  */
vlib.h
pppoe_session_t::decap_fib_index
u32 decap_fib_index
FIB indices - inner IP packet lookup here.
Definition: pppoe.h:64
PPPOE_N_ERROR
@ PPPOE_N_ERROR
Definition: pppoe.h:94
adj_types.h
pppoe_error_strings
char * pppoe_error_strings[]
Definition: pppoe_decap.c:462
mac
vl_api_mac_address_t mac
Definition: l2.api:559
pppoe_header_t::ppp_proto
u16 ppp_proto
Definition: pppoe.h:43
pppoe_session_t::hw_if_index
u32 hw_if_index
Definition: pppoe.h:71
pppoe_main
pppoe_main_t pppoe_main
Definition: pppoe.c:38
bihash_8_8.h
pppoe_header_t::ver_type
u8 ver_type
Definition: pppoe.h:39
pppoe_entry_result_t
Definition: pppoe.h:136
pppoe_entry_result_t::fields
struct pppoe_entry_result_t::@766::@768 fields
CLIB_CACHE_LINE_ALIGN_MARK
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
vnet_pppoe_add_del_session_args_t::decap_fib_index
u32 decap_fib_index
Definition: pppoe.h:193
pppoe_entry_result_t::session_index
u32 session_index
Definition: pppoe.h:144
fib_table.h
pppoe_main_t::vnet_main
vnet_main_t * vnet_main
Definition: pppoe.h:177
u16
unsigned short u16
Definition: types.h:57
pppoe_learn_process
static_always_inline void pppoe_learn_process(BVT(clib_bihash) *table, u32 sw_if_index0, pppoe_entry_key_t *key0, pppoe_entry_key_t *cached_key, u32 *bucket0, pppoe_entry_result_t *result0)
Perform learning on one packet based on the mac table lookup result.
Definition: pppoe.h:242
vnet_pppoe_add_del_tap_args_t
Definition: pppoe.h:201
vnet_pppoe_add_del_session
int vnet_pppoe_add_del_session(vnet_pppoe_add_del_session_args_t *a, u32 *sw_if_indexp)
Definition: pppoe.c:288
ethernet.h
clib_bihash_search_inline
int clib_bihash_search_inline(clib_bihash *h, clib_bihash_kv *in_out_kv)
Search a bi-hash table.
pppoe_input_node
vlib_node_registration_t pppoe_input_node
(constructor) VLIB_REGISTER_NODE (pppoe_input_node)
Definition: pppoe_decap.c:470
vnet_pppoe_add_del_tap_args_t::is_add
u8 is_add
Definition: pppoe.h:203
pppoe_header_t::length
u16 length
Definition: pppoe.h:42
pppoe_session_t::client_ip
ip46_address_t client_ip
Definition: pppoe.h:58
ip6_packet.h
pppoe_main_t::cp_if_index
u32 cp_if_index
Definition: pppoe.h:170
vnet_pppoe_add_del_session_args_t::is_add
u8 is_add
Definition: pppoe.h:188
pppoe_main_t::vlib_main
vlib_main_t * vlib_main
Definition: pppoe.h:176
pppoe_session_t::encap_if_index
u32 encap_if_index
Definition: pppoe.h:61
vnet_pppoe_add_del_session_args_t
Definition: pppoe.h:186
pppoe_main_t
Definition: pppoe.h:152
error.h
dpo.h
lock.h
static_always_inline
#define static_always_inline
Definition: clib.h:112
BVT
BVT(clib_bihash)
The table of adjacencies indexed by the rewrite string.
Definition: l2_fib.c:1069
pppoe_header_t::session_id
u16 session_id
Definition: pppoe.h:41
session_id
u32 session_id
Definition: flow_types.api:131
vnet_pppoe_add_del_session_args_t::encap_if_index
u32 encap_if_index
Definition: pppoe.h:192
pppoe_entry_result_t::raw
u64 raw
Definition: pppoe.h:147
pppoe_entry_key_t::w1
u32 w1
Definition: pppoe.h:125
pppoe_header_t::code
u8 code
Definition: pppoe.h:40
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
pppoe_lookup_1
static_always_inline void pppoe_lookup_1(BVT(clib_bihash) *table, pppoe_entry_key_t *cached_key, pppoe_entry_result_t *cached_result, u8 *mac0, u16 session_id0, pppoe_entry_key_t *key0, u32 *bucket0, pppoe_entry_result_t *result0)
Definition: pppoe.h:277
plugin.h
pppoe_session_t
Definition: pppoe.h:49
ip4_packet.h
pppoe_update_1
static_always_inline void pppoe_update_1(BVT(clib_bihash) *table, u8 *mac0, u16 session_id0, pppoe_entry_key_t *key0, u32 *bucket0, pppoe_entry_result_t *result0)
Definition: pppoe.h:311
vnet_main_t
Definition: vnet.h:76
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
pppoe_session_t::session_id
u16 session_id
Definition: pppoe.h:55
pppoe_entry_key_t::raw
u64 raw
Definition: pppoe.h:127
u64
unsigned long u64
Definition: types.h:89
pppoe_main_t::session_index_by_sw_if_index
u32 * session_index_by_sw_if_index
Definition: pppoe.h:167
pppoe_header_t
Definition: pppoe.h:37
ip.h
u32
unsigned int u32
Definition: types.h:88
pppoe_input_next_t
pppoe_input_next_t
Definition: pppoe.h:81
pppoe_entry_key_t::w0
u32 w0
Definition: pppoe.h:124
PPPOE_INPUT_N_NEXT
@ PPPOE_INPUT_N_NEXT
Definition: pppoe.h:86
pppoe_entry_key_t::session_id
u16 session_id
Definition: pppoe.h:119
clib_bihash_add_del
int clib_bihash_add_del(clib_bihash *h, clib_bihash_kv *add_v, int is_add)
Add or delete a (key,value) pair from a bi-hash table.
vnet_pppoe_add_del_session_args_t::is_ip6
u8 is_ip6
Definition: pppoe.h:189
pppoe_input_error_t
pppoe_input_error_t
Definition: pppoe.h:89
pppoe_entry_result_t::sw_if_index
u32 sw_if_index
Definition: pppoe.h:142
pppoe_error.def
pppoe_make_key
static u64 pppoe_make_key(u8 *mac_address, u16 session_id)
Definition: pppoe.h:211
vnet_pppoe_add_del_tap_args_t::cp_if_index
u32 cp_if_index
Definition: pppoe.h:205
vlib_main_t
Definition: main.h:102
foreach_pppoe_input_next
#define foreach_pppoe_input_next
Definition: pppoe.h:75
hash.h
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:544
pppoe_main_t::free_pppoe_session_hw_if_indices
u32 * free_pppoe_session_hw_if_indices
Definition: pppoe.h:164
pppoe_main_t::msg_id_base
u16 msg_id_base
Definition: pppoe.h:173
vnet.h
vnet_pppoe_add_del_session_args_t::client_ip
ip46_address_t client_ip
Definition: pppoe.h:191
pppoe_add_del_cp
int pppoe_add_del_cp(u32 cp_if_index, u8 is_add)
Definition: pppoe_cp.c:21
pppoe_main_t::sessions
pppoe_session_t * sessions
Definition: pppoe.h:155
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
vnet_pppoe_add_del_tap_args_t::client_if_index
u32 client_if_index
Definition: pppoe.h:204
pppoe_cp_dispatch_node
vlib_node_registration_t pppoe_cp_dispatch_node
(constructor) VLIB_REGISTER_NODE (pppoe_cp_dispatch_node)
Definition: pppoe_cp_node.c:238
vnet_pppoe_add_del_session_args_t::session_id
u16 session_id
Definition: pppoe.h:190
pppoe_entry_key_t
Definition: pppoe.h:113
mac_address
manual_print typedef u8 mac_address[6]
Definition: ethernet_types.api:19
pppoe_session_t::sw_if_index
u32 sw_if_index
Definition: pppoe.h:70