FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
pg.c
Go to the documentation of this file.
1 /*
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 
22 typedef struct
23 {
27 
28 static inline void
30 {
31  pg_edit_init (&e->flags_and_version, gre_header_t, flags_and_version);
33 }
34 
35 uword
36 unformat_pg_gre_header (unformat_input_t * input, va_list * args)
37 {
38  pg_stream_t *s = va_arg (*args, pg_stream_t *);
40  u32 group_index, error;
41 
42  h = pg_create_edit_group (s, sizeof (h[0]), sizeof (gre_header_t),
43  &group_index);
45 
46  pg_edit_set_fixed (&h->flags_and_version, 0);
47 
48  error = 1;
49  if (!unformat (input, "%U",
52  goto done;
53 
54  {
55  gre_main_t *pm = &gre_main;
56  gre_protocol_info_t *pi = 0;
57  pg_node_t *pg_node = 0;
58 
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;
73 done:
74  if (error)
76  return error == 0;
77 }
78 
79 
80 /*
81  * fd.io coding-style-patch-verification: ON
82  *
83  * Local Variables:
84  * eval: (c-set-style "gnu")
85  * End:
86  */
vlib.h
PG_EDIT_FIXED
@ PG_EDIT_FIXED
Definition: edit.h:52
pg_edit_set_fixed
static void pg_edit_set_fixed(pg_edit_t *e, u64 value)
Definition: edit.h:153
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
gre_main
gre_main_t gre_main
Definition: gre.c:26
pg.h
gre_main_t
GRE related global data.
Definition: gre.h:242
gre_protocol_info_t
A GRE payload protocol registration.
Definition: gre.h:69
u16
unsigned short u16
Definition: types.h:57
unformat_input_t
struct _unformat_input_t unformat_input_t
pg_gre_header_t
Definition: pg.c:22
h
h
Definition: flowhash_template.h:372
error
Definition: cJSON.c:88
pg_node_t
Definition: pg.h:324
pg_gre_header_init
static void pg_gre_header_init(pg_gre_header_t *e)
Definition: pg.c:29
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
pg_node_t::unformat_edit
unformat_function_t * unformat_edit
Definition: pg.h:327
unformat_gre_protocol_net_byte_order
unformat_function_t unformat_gre_protocol_net_byte_order
Definition: gre.h:351
PG_EDIT_LO
#define PG_EDIT_LO
Definition: edit.h:83
uword
u64 uword
Definition: types.h:112
pg_get_node
static pg_node_t * pg_get_node(uword node_index)
Definition: pg.h:381
unformat_pg_gre_header
uword unformat_pg_gre_header(unformat_input_t *input, va_list *args)
Definition: pg.c:36
gre_protocol_info_t::node_index
u32 node_index
Node which handles this type.
Definition: gre.h:81
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_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
protocol
vl_api_ip_proto_t protocol
Definition: lb_types.api:72
pg_edit_init
#define pg_edit_init(e, type, field)
Definition: edit.h:116
pg_gre_header_t::flags_and_version
pg_edit_t flags_and_version
Definition: pg.c:24
gre_get_protocol_info
static gre_protocol_info_t * gre_get_protocol_info(gre_main_t *em, gre_protocol_t protocol)
Definition: gre.h:314
gre_header_t
Definition: packet.h:37
pg_edit_t
Definition: edit.h:64
pg_stream_t
Definition: pg.h:96
pg_gre_header_t::protocol
pg_edit_t protocol
Definition: pg.c:25
gre.h