FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
pg.c
Go to the documentation of this file.
1 /*
2  * pg.c: packet generator for L2TPv3 header
3  *
4  * Copyright (c) 2013 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 #include <vlib/vlib.h>
19 #include <vnet/pg/pg.h>
20 #include <l2tp/l2tp.h>
21 
22 typedef struct
23 {
27 
28 typedef struct
29 {
32 
33 static inline void
35 {
36  pg_edit_init (&e->session_id, l2tpv3_header_t, session_id);
37  pg_edit_init (&e->cookie, l2tpv3_header_t, cookie);
38 }
39 
40 uword
41 unformat_pg_l2tp_header (unformat_input_t * input, va_list * args)
42 {
43  pg_stream_t *s = va_arg (*args, pg_stream_t *);
45  u32 group_index, error;
47 
48  h = pg_create_edit_group (s, sizeof (h[0]),
49  sizeof (l2tpv3_header_t) - sizeof (u32),
50  &group_index);
52 
53  error = 1;
54 
55  /* session id and cookie are required */
56  if (!unformat (input, "L2TP: session_id %U cookie %U",
57  unformat_pg_edit, unformat_pg_number, &h->session_id,
59  {
60  goto done;
61  }
62 
63  /* "l2_sublayer <value>" is optional */
64  if (unformat (input, "l2_sublayer"))
65  {
67 
68  h2 = pg_add_edits (s, sizeof (h2[0]), sizeof (u32), group_index);
69  pg_edit_init (&h2->l2_sublayer, l2tpv3_header_t, l2_specific_sublayer);
70  if (!unformat_user (input, unformat_pg_edit,
72  {
73  goto done;
74  }
75  }
76 
77  /* Parse an ethernet header if it is present */
78  {
79  pg_node_t *pg_node = 0;
80  vlib_node_t *eth_lookup_node;
81 
82  eth_lookup_node = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
83  ASSERT (eth_lookup_node);
84 
85  pg_node = pg_get_node (eth_lookup_node->index);
86 
87  if (pg_node && pg_node->unformat_edit
88  && unformat_user (input, pg_node->unformat_edit, s))
89  ;
90  }
91 
92  error = 0;
93 
94 done:
95  if (error)
97  return error == 0;
98 }
99 
100 /*
101  * fd.io coding-style-patch-verification: ON
102  *
103  * Local Variables:
104  * eval: (c-set-style "gnu")
105  * End:
106  */
vlib.h
pg_l2tp_header_t::session_id
pg_edit_t session_id
Definition: pg.c:24
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
pg.h
pg_l2tp_header_init
static void pg_l2tp_header_init(pg_l2tp_header_t *e)
Definition: pg.c:34
pg_l2tp_header_l2_sublayer_t::l2_sublayer
pg_edit_t l2_sublayer
Definition: pg.c:30
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
unformat_pg_number
uword unformat_pg_number(unformat_input_t *input, va_list *args)
Definition: edit.c:85
unformat_input_t
struct _unformat_input_t unformat_input_t
h
h
Definition: flowhash_template.h:372
error
Definition: cJSON.c:88
pg_node_t
Definition: pg.h:324
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vlib_node_t::index
u32 index
Definition: node.h:269
pg_node_t::unformat_edit
unformat_function_t * unformat_edit
Definition: pg.h:327
uword
u64 uword
Definition: types.h:112
pg_get_node
static pg_node_t * pg_get_node(uword node_index)
Definition: pg.h:381
session_id
u32 session_id
Definition: flow_types.api:131
pg_l2tp_header_t::cookie
pg_edit_t cookie
Definition: pg.c:25
pg_free_edit_group
static void pg_free_edit_group(pg_stream_t *s)
Definition: pg.h:292
unformat_pg_edit
uword unformat_pg_edit(unformat_input_t *input, va_list *args)
Definition: edit.c:106
pg_l2tp_header_l2_sublayer_t
Definition: pg.c:28
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
pg_create_edit_group
static void * pg_create_edit_group(pg_stream_t *s, int n_edit_bytes, int n_packet_bytes, u32 *group_index)
Definition: pg.h:239
u32
unsigned int u32
Definition: types.h:88
pg_edit_init
#define pg_edit_init(e, type, field)
Definition: edit.h:116
pg_l2tp_header_t
Definition: pg.c:22
pg_add_edits
static void * pg_add_edits(pg_stream_t *s, int n_edit_bytes, int n_packet_bytes, u32 group_index)
Definition: pg.h:259
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
u8
unsigned char u8
Definition: types.h:56
pg_edit_t
Definition: edit.h:64
l2tp.h
pg_stream_t
Definition: pg.h:96
unformat_pg_l2tp_header
uword unformat_pg_l2tp_header(unformat_input_t *input, va_list *args)
Definition: pg.c:41