FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
punt.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @file
18  * @brief Definitions for punt infrastructure.
19  */
20 #ifndef included_punt_h
21 #define included_punt_h
22 
23 #include <linux/un.h>
24 #include <stdbool.h>
25 #include <vnet/ip/ip.h>
26 
27 #define foreach_punt_type \
28  _(L4, "l4") \
29  _(EXCEPTION, "exception") \
30  _(IP_PROTO, "ip-proto")
31 
32 typedef enum punt_type_t_
33 {
34 #define _(v, s) PUNT_TYPE_##v,
36 #undef _
37 } punt_type_t;
38 
39 typedef struct punt_l4_t_
40 {
44 } punt_l4_t;
45 
46 typedef struct punt_ip_proto_t_
47 {
51 
52 typedef struct punt_exception_t_
53 {
56 
57 typedef struct punt_union_t_
58 {
62 } punt_union_t;
63 
64 typedef struct punt_reg_t_
65 {
68 } punt_reg_t;
69 
70 
72  const punt_reg_t * pr, bool is_add);
74  u32 header_version,
75  const punt_reg_t * pr,
76  char *client_pathname);
79 
81 {
82  PUNT_L2 = 0,
85 };
86 
87 /*
88  * Packet descriptor header. Version 1
89  * If this header changes, the version must also change to notify clients.
90  */
91 #define PUNT_PACKETDESC_VERSION 1
92 typedef struct __attribute__ ((packed))
93 {
94  u32 sw_if_index; /* RX or TX interface */
97 
98 /*
99  * Client registration
100  */
101 typedef struct
102 {
104  struct sockaddr_un caddr;
105 } punt_client_t;
106 
107 typedef struct punt_client_db_t_
108 {
113 
114 typedef struct punt_thread_data_t_
115 {
116  struct iovec *iovecs;
118 
119 typedef struct
120 {
122  char sun_path[sizeof (struct sockaddr_un)];
132 } punt_main_t;
133 
134 extern punt_main_t punt_main;
135 
137  void *ctx);
138 extern void punt_client_walk (punt_type_t pt,
139  punt_client_walk_cb_t cb, void *ctx);
140 
141 /*
142  * inlines for the data-plane
143  */
146 {
147  return (af << BITS (port) | port);
148 }
149 
152 {
153  punt_main_t *pm = &punt_main;
154  uword *p;
155 
156  p = hash_get (pm->db.clients_by_l4_port, punt_client_l4_mk_key (af, port));
157 
158  if (p)
159  return (pool_elt_at_index (pm->punt_client_pool, p[0]));
160 
161  return (NULL);
162 }
163 
166 {
167  return (af << 16 | proto);
168 }
169 
172 {
173  punt_main_t *pm = &punt_main;
174  uword *p;
175 
176  p =
178  punt_client_ip_proto_mk_key (af, proto));
179 
180  if (p)
181  return (pool_elt_at_index (pm->punt_client_pool, p[0]));
182 
183  return (NULL);
184 }
185 
188 {
189  punt_main_t *pm = &punt_main;
190  u32 pci;
191 
192  if (reason >= vec_len (pm->db.clients_by_exception))
193  return (NULL);
194 
195  pci = pm->db.clients_by_exception[reason];
196 
197  if (~0 != pci)
198  return (pool_elt_at_index (pm->punt_client_pool, pci));
199 
200  return (NULL);
201 }
202 
210 
211 #endif
212 
213 /*
214  * fd.io coding-style-patch-verification: ON
215  *
216  * Local Variables:
217  * eval: (c-set-style "gnu")
218  * End:
219  */
vlib_node_t * interface_output_node
Definition: punt.h:127
enum punt_type_t_ punt_type_t
A registration, by a client, to direct punted traffic to a given node.
Definition: punt.h:64
vlib_node_registration_t udp6_punt_node
(constructor) VLIB_REGISTER_NODE (udp6_punt_node)
Definition: punt_node.c:205
ip_protocol_t protocol
Definition: punt.h:49
Definition: punt.h:82
punt_type_t_
Definition: punt.h:32
void punt_client_walk(punt_type_t pt, punt_client_walk_cb_t cb, void *ctx)
Definition: punt.c:640
static_always_inline u32 punt_client_l4_mk_key(ip_address_family_t af, u16 port)
Definition: punt.h:145
vlib_node_registration_t ip4_proto_punt_socket_node
(constructor) VLIB_REGISTER_NODE (ip4_proto_punt_socket_node)
Definition: punt_node.c:461
#define foreach_punt_type
Definition: punt.h:27
clib_error_t * vnet_punt_socket_del(vlib_main_t *vm, const punt_reg_t *pr)
Definition: punt.c:330
u32 * ready_fds
Definition: punt.h:128
u32 clib_file_index
Definition: punt.h:125
punt_reg_t reg
Definition: punt.h:103
punt_type_t type
Definition: punt.h:66
static_always_inline punt_client_t * punt_client_l4_get(ip_address_family_t af, u16 port)
Definition: punt.h:151
int vlib_punt_hdl_t
Typedef for a client handle.
Definition: punt.h:47
vlib_node_registration_t udp4_punt_socket_node
(constructor) VLIB_REGISTER_NODE (udp4_punt_socket_node)
Definition: punt_node.c:442
int socket_fd
Definition: punt.h:121
static_always_inline punt_client_t * punt_client_ip_proto_get(ip_address_family_t af, ip_protocol_t proto)
Definition: punt.h:171
punt_thread_data_t * thread_data
Definition: punt.h:130
enum walk_rc_t_ walk_rc_t
Walk return code.
#define static_always_inline
Definition: clib.h:106
punt_client_t * punt_client_pool
Definition: punt.h:124
clib_error_t * vnet_punt_add_del(vlib_main_t *vm, const punt_reg_t *pr, bool is_add)
Definition: punt.c:410
static_always_inline punt_client_t * punt_client_exception_get(vlib_punt_reason_t reason)
Definition: punt.h:187
unsigned int u32
Definition: types.h:88
struct iovec * iovecs
Definition: punt.h:116
struct punt_client_db_t_ punt_client_db_t
vlib_punt_hdl_t hdl
Definition: punt.h:131
static_always_inline u32 punt_client_ip_proto_mk_key(ip_address_family_t af, ip_protocol_t proto)
Definition: punt.h:165
enum ip_protocol ip_protocol_t
#define hash_get(h, key)
Definition: hash.h:249
struct punt_thread_data_t_ punt_thread_data_t
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
struct punt_reg_t_ punt_reg_t
punt_ip_proto_t ip_proto
Definition: punt.h:61
vl_api_ip_proto_t proto
Definition: acl_types.api:50
long ctx[MAX_CONNS]
Definition: main.c:144
unsigned short u16
Definition: types.h:57
ip_address_family_t af
Definition: punt.h:41
vlib_node_registration_t punt_socket_rx_node
(constructor) VLIB_REGISTER_NODE (punt_socket_rx_node)
Definition: punt_node.c:621
vlib_main_t * vm
Definition: in2out_ed.c:1599
punt_exception_t exception
Definition: punt.h:59
vlib_node_registration_t udp6_punt_socket_node
(constructor) VLIB_REGISTER_NODE (udp6_punt_socket_node)
Definition: punt_node.c:452
punt_main_t punt_main
Definition: punt.c:39
struct punt_ip_proto_t_ punt_ip_proto_t
u32 sw_if_index
Definition: punt.h:94
u32 * rx_buffers
Definition: punt.h:129
ip_address_family_t af
Definition: punt.h:48
walk_rc_t(* punt_client_walk_cb_t)(const punt_client_t *pc, void *ctx)
Definition: punt.h:136
ip_protocol_t protocol
Definition: punt.h:42
punt_l4_t l4
Definition: punt.h:60
struct punt_client_t_ punt_client_t
A client using the punt serivce and its registrations.
punt_action_e
Definition: punt.h:80
struct punt_union_t_ punt_union_t
u32 * clients_by_exception
Definition: punt.h:110
enum ip_address_family_t_ ip_address_family_t
struct _vlib_node_registration vlib_node_registration_t
struct punt_exception_t_ punt_exception_t
struct punt_l4_t_ punt_l4_t
void * clients_by_ip_proto
Definition: punt.h:111
bool is_configured
Definition: punt.h:126
vl_api_mac_event_action_t action
Definition: l2.api:181
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
char * vnet_punt_get_server_pathname(void)
Definition: punt.c:42
punt_union_t punt
Definition: punt.h:67
u64 uword
Definition: types.h:112
vlib_node_registration_t ip6_proto_punt_socket_node
(constructor) VLIB_REGISTER_NODE (ip6_proto_punt_socket_node)
Definition: punt_node.c:471
punt_client_db_t db
Definition: punt.h:123
clib_error_t * vnet_punt_socket_add(vlib_main_t *vm, u32 header_version, const punt_reg_t *pr, char *client_pathname)
Definition: punt.c:290
#define BITS(x)
Definition: clib.h:65
vlib_punt_reason_t reason
Definition: punt.h:54
enum vlib_punt_reason_t_ vlib_punt_reason_t
The &#39;syatem&#39; defined punt reasons.
void * clients_by_l4_port
Definition: punt.h:109
vlib_node_registration_t udp4_punt_node
(constructor) VLIB_REGISTER_NODE (udp4_punt_node)
Definition: punt_node.c:189
u16 port
Definition: punt.h:43