FD.io VPP  v17.10-9-gd594711
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  /* pppoe session_id in HOST byte order */
53 
54  /* session client addresses */
55  ip46_address_t client_ip;
56 
57  /* the index of tx interface for pppoe encaped packet */
59 
60  /** FIB indices - inner IP packet lookup here */
62 
63  u8 local_mac[6];
64  u8 client_mac[6];
65 
66  /* vnet intfc index */
69 
71 
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" ) \
77 
78 typedef enum
79 {
80 #define _(s,n) PPPOE_INPUT_NEXT_##s,
82 #undef _
85 
86 typedef enum
87 {
88 #define pppoe_error(n,s) PPPOE_ERROR_##n,
89 #include <pppoe/pppoe_error.def>
90 #undef pppoe_error
93 
94 
95 #define MTU 1500
96 #define MTU_BUFFERS ((MTU + VLIB_BUFFER_DATA_SIZE - 1) / VLIB_BUFFER_DATA_SIZE)
97 #define NUM_BUFFERS_TO_ALLOC 32
98 
99 /*
100  * The size of pppoe session table
101  */
102 #define PPPOE_NUM_BUCKETS (128 * 1024)
103 #define PPPOE_MEMORY_SIZE (16<<20)
104 
105 /* *INDENT-OFF* */
106 /*
107  * The PPPoE key is the mac address and session ID
108  */
109 typedef struct
110 {
111  union
112  {
113  struct
114  {
116  u8 mac[6];
117  } fields;
118  struct
119  {
122  } words;
124  };
126 /* *INDENT-ON* */
127 
128 /* *INDENT-OFF* */
129 /*
130  * The PPPoE entry results
131  */
132 typedef struct
133 {
134  union
135  {
136  struct
137  {
139 
141 
142  } fields;
144  };
146 /* *INDENT-ON* */
147 
148 typedef struct
149 {
150  /* For DP: vector of encap session instances, */
152 
153  /* For CP: vector of CP path */
154  BVT (clib_bihash) session_table;
155 
156  /* Free vlib hw_if_indices */
157  u32 *free_pppoe_session_hw_if_indices;
158 
159  /* Mapping from sw_if_index to session index */
160  u32 *session_index_by_sw_if_index;
161 
162  /* used for pppoe cp path */
163  u32 tap_if_index;
164 
165  /* API message ID base */
166  u16 msg_id_base;
167 
168  /* convenience */
171 
172 } pppoe_main_t;
173 
174 extern pppoe_main_t pppoe_main;
175 
178 
179 typedef struct
180 {
184  ip46_address_t client_ip;
187  u8 local_mac[6];
188  u8 client_mac[6];
190 
192  (vnet_pppoe_add_del_session_args_t * a, u32 * sw_if_indexp);
193 
194 typedef struct
195 {
200 
202 pppoe_make_key (u8 * mac_address, u16 session_id)
203 {
204  u64 temp;
205 
206  /*
207  * The mac address in memory is A:B:C:D:E:F
208  * The session_id in register is H:L
209  */
210 #if CLIB_ARCH_IS_LITTLE_ENDIAN
211  /*
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
214  */
215  temp = *((u64 *) (mac_address)) << 16;
216  temp = (temp & ~0xffff) | (u64) (session_id);
217 #else
218  /*
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
221  */
222  temp = *((u64 *) (mac_address)) >> 16;
223  temp = temp | (((u64) session_id) << 48);
224 #endif
225 
226  return temp;
227 }
228 
230 pppoe_lookup_1 (BVT (clib_bihash) * session_table,
231  pppoe_entry_key_t * cached_key,
232  pppoe_entry_result_t * cached_result,
233  u8 * mac0,
234  u16 session_id0,
235  pppoe_entry_key_t * key0,
236  u32 * bucket0, pppoe_entry_result_t * result0)
237 {
238  /* set up key */
239  key0->raw = pppoe_make_key (mac0, session_id0);
240  *bucket0 = ~0;
241 
242  if (key0->raw == cached_key->raw)
243  {
244  /* Hit in the one-entry cache */
245  result0->raw = cached_result->raw;
246  }
247  else
248  {
249  /* Do a regular session table lookup */
250  BVT (clib_bihash_kv) kv;
251 
252  kv.key = key0->raw;
253  kv.value = ~0ULL;
254  BV (clib_bihash_search_inline) (session_table, &kv);
255  result0->raw = kv.value;
256 
257  /* Update one-entry cache */
258  cached_key->raw = key0->raw;
259  cached_result->raw = result0->raw;
260  }
261 }
262 
264 pppoe_update_1 (BVT (clib_bihash) * session_table,
265  u8 * mac0,
266  u16 session_id0,
267  pppoe_entry_key_t * key0,
268  u32 * bucket0, pppoe_entry_result_t * result0)
269 {
270  /* set up key */
271  key0->raw = pppoe_make_key (mac0, session_id0);
272  *bucket0 = ~0;
273 
274  /* Update the entry */
275  BVT (clib_bihash_kv) kv;
276  kv.key = key0->raw;
277  kv.value = result0->raw;
278  BV (clib_bihash_add_del) (session_table, &kv, 1 /* is_add */ );
279 
280 }
281 #endif /* _PPPOE_H */
282 
283 /*
284  * fd.io coding-style-patch-verification: ON
285  *
286  * Local Variables:
287  * eval: (c-set-style "gnu")
288  * End:
289  */
static_always_inline void pppoe_update_1(BVT(clib_bihash)*session_table, u8 *mac0, u16 session_id0, pppoe_entry_key_t *key0, u32 *bucket0, pppoe_entry_result_t *result0)
Definition: pppoe.h:264
u16 ppp_proto
Definition: pppoe.h:43
Definition: pppoe.h:109
a
Definition: bitmap.h:516
u32 encap_if_index
Definition: pppoe.h:58
u16 session_id
Definition: pppoe.h:52
u64 raw
Definition: pppoe.h:143
#define foreach_pppoe_input_next
Definition: pppoe.h:72
struct _vlib_node_registration vlib_node_registration_t
static_always_inline void pppoe_lookup_1(BVT(clib_bihash)*session_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:230
#define static_always_inline
Definition: clib.h:85
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.
#define always_inline
Definition: clib.h:84
static BVT(clib_bihash)
Definition: adj_nbr.c:26
unsigned long u64
Definition: types.h:89
u64 raw
Definition: pppoe.h:123
u32 sw_if_index
Definition: pppoe.h:138
u16 session_id
Definition: pppoe.h:41
u16 length
Definition: pppoe.h:42
u32 hw_if_index
Definition: pppoe.h:68
ip46_address_t client_ip
Definition: pppoe.h:55
vlib_node_registration_t pppoe_tap_dispatch_node
(constructor) VLIB_REGISTER_NODE (pppoe_tap_dispatch_node)
vnet_main_t vnet_main
Definition: misc.c:43
u32 w0
Definition: pppoe.h:120
pppoe_input_next_t
Definition: pppoe.h:78
u32 w1
Definition: pppoe.h:121
vlib_node_registration_t pppoe_input_node
(constructor) VLIB_REGISTER_NODE (pppoe_input_node)
Definition: pppoe_decap.c:401
u32 session_index
Definition: pppoe.h:140
static u64 pppoe_make_key(u8 *mac_address, u16 session_id)
Definition: pppoe.h:202
pppoe_input_error_t
Definition: pppoe.h:86
pppoe_session_t * sessions
Definition: pppoe.h:151
pppoe_main_t pppoe_main
Definition: jvpp_pppoe.h:39
unsigned int u32
Definition: types.h:88
Definition: pppoe.h:132
u32 sw_if_index
Definition: pppoe.h:67
u16 session_id
Definition: pppoe.h:115
int vlib_main(vlib_main_t *volatile vm, unformat_input_t *input)
Definition: main.c:1689
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
u32 decap_fib_index
FIB indices - inner IP packet lookup here.
Definition: pppoe.h:61
int vnet_pppoe_add_del_session(vnet_pppoe_add_del_session_args_t *a, u32 *sw_if_indexp)
Definition: pppoe.c:248
u8 ver_type
Definition: pppoe.h:39