blob: 38a3a07ebad9a76849ecb6e951d7e060bb43b7f5 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * hdlc_pg.c: packet generator gre interface
3 *
4 * Copyright (c) 2012 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/gre/gre.h>
21
Swarup Nayak9ff647a2017-11-27 10:27:43 +053022typedef struct
23{
Ed Warnickecb9cada2015-12-08 15:45:58 -070024 pg_edit_t flags_and_version;
25 pg_edit_t protocol;
26} pg_gre_header_t;
27
28static inline void
29pg_gre_header_init (pg_gre_header_t * e)
30{
31 pg_edit_init (&e->flags_and_version, gre_header_t, flags_and_version);
32 pg_edit_init (&e->protocol, gre_header_t, protocol);
33}
34
35uword
36unformat_pg_gre_header (unformat_input_t * input, va_list * args)
37{
Swarup Nayak9ff647a2017-11-27 10:27:43 +053038 pg_stream_t *s = va_arg (*args, pg_stream_t *);
39 pg_gre_header_t *h;
Ed Warnickecb9cada2015-12-08 15:45:58 -070040 u32 group_index, error;
Swarup Nayak9ff647a2017-11-27 10:27:43 +053041
Ed Warnickecb9cada2015-12-08 15:45:58 -070042 h = pg_create_edit_group (s, sizeof (h[0]), sizeof (gre_header_t),
43 &group_index);
44 pg_gre_header_init (h);
45
46 pg_edit_set_fixed (&h->flags_and_version, 0);
47
48 error = 1;
Swarup Nayak9ff647a2017-11-27 10:27:43 +053049 if (!unformat (input, "%U",
50 unformat_pg_edit,
51 unformat_gre_protocol_net_byte_order, &h->protocol))
Ed Warnickecb9cada2015-12-08 15:45:58 -070052 goto done;
53
54 {
Swarup Nayak9ff647a2017-11-27 10:27:43 +053055 gre_main_t *pm = &gre_main;
56 gre_protocol_info_t *pi = 0;
57 pg_node_t *pg_node = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070058
59 if (h->protocol.type == PG_EDIT_FIXED)
60 {
61 u16 t = *(u16 *) h->protocol.values[PG_EDIT_LO];
62 pi = gre_get_protocol_info (pm, clib_net_to_host_u16 (t));
63 if (pi && pi->node_index != ~0)
64 pg_node = pg_get_node (pi->node_index);
65 }
66
67 if (pg_node && pg_node->unformat_edit
68 && unformat_user (input, pg_node->unformat_edit, s))
69 ;
70 }
71
72 error = 0;
Swarup Nayak9ff647a2017-11-27 10:27:43 +053073done:
Ed Warnickecb9cada2015-12-08 15:45:58 -070074 if (error)
75 pg_free_edit_group (s);
76 return error == 0;
77}
78
Swarup Nayak9ff647a2017-11-27 10:27:43 +053079
80/*
81 * fd.io coding-style-patch-verification: ON
82 *
83 * Local Variables:
84 * eval: (c-set-style "gnu")
85 * End:
86 */