blob: 1e523d3bbb0398f76516a3ed571d1db4c06a8377 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 <vnet/l2tp/l2tp.h>
21
Calvinee275a72016-08-10 11:01:41 -040022typedef struct
23{
Ed Warnickecb9cada2015-12-08 15:45:58 -070024 pg_edit_t session_id;
25 pg_edit_t cookie;
26} pg_l2tp_header_t;
27
Calvinee275a72016-08-10 11:01:41 -040028typedef struct
29{
Ed Warnickecb9cada2015-12-08 15:45:58 -070030 pg_edit_t l2_sublayer;
31} pg_l2tp_header_l2_sublayer_t;
32
33static inline void
34pg_l2tp_header_init (pg_l2tp_header_t * e)
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
40uword
41unformat_pg_l2tp_header (unformat_input_t * input, va_list * args)
42{
Calvinee275a72016-08-10 11:01:41 -040043 pg_stream_t *s = va_arg (*args, pg_stream_t *);
44 pg_l2tp_header_t *h;
Ed Warnickecb9cada2015-12-08 15:45:58 -070045 u32 group_index, error;
Calvinee275a72016-08-10 11:01:41 -040046 vlib_main_t *vm = vlib_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -070047
Calvinee275a72016-08-10 11:01:41 -040048 h = pg_create_edit_group (s, sizeof (h[0]),
49 sizeof (l2tpv3_header_t) - sizeof (u32),
Ed Warnickecb9cada2015-12-08 15:45:58 -070050 &group_index);
51 pg_l2tp_header_init (h);
52
53 error = 1;
54
Calvinee275a72016-08-10 11:01:41 -040055 /* 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,
58 unformat_pg_edit, unformat_pg_number, &h->cookie))
59 {
Ed Warnickecb9cada2015-12-08 15:45:58 -070060 goto done;
Calvinee275a72016-08-10 11:01:41 -040061 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070062
Calvinee275a72016-08-10 11:01:41 -040063 /* "l2_sublayer <value>" is optional */
64 if (unformat (input, "l2_sublayer"))
65 {
66 pg_l2tp_header_l2_sublayer_t *h2;
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,
71 unformat_pg_number, &h2->l2_sublayer))
72 {
73 goto done;
74 }
75 }
76
77 /* Parse an ethernet header if it is present */
Ed Warnickecb9cada2015-12-08 15:45:58 -070078 {
Calvinee275a72016-08-10 11:01:41 -040079 pg_node_t *pg_node = 0;
80 vlib_node_t *eth_lookup_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -070081
Calvinee275a72016-08-10 11:01:41 -040082 eth_lookup_node = vlib_get_node_by_name (vm, (u8 *) "ethernet-input");
Ed Warnickecb9cada2015-12-08 15:45:58 -070083 ASSERT (eth_lookup_node);
84
85 pg_node = pg_get_node (eth_lookup_node->index);
86
87 if (pg_node && pg_node->unformat_edit
Calvinee275a72016-08-10 11:01:41 -040088 && unformat_user (input, pg_node->unformat_edit, s))
Ed Warnickecb9cada2015-12-08 15:45:58 -070089 ;
90 }
91
92 error = 0;
93
94done:
95 if (error)
96 pg_free_edit_group (s);
97 return error == 0;
98}
99
Calvinee275a72016-08-10 11:01:41 -0400100/*
101 * fd.io coding-style-patch-verification: ON
102 *
103 * Local Variables:
104 * eval: (c-set-style "gnu")
105 * End:
106 */