FD.io VPP  v21.06-3-gbb25fbf28
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 /* Punting reason flags bitfield
28  * (position, length, value, name, string)
29  */
30 #define foreach_vnet_punt_reason_flag \
31  _ (0, 1, 0, IP4_PACKET, "ip4-packet") \
32  _ (0, 1, 1, IP6_PACKET, "ip6-packet")
33 
35 {
36 #define _(pos, len, value, name, str) \
37  VNET_PUNT_REASON_F_##name = ((value) << (pos)),
39 #undef _
40 } __clib_packed vnet_punt_reason_flag_t;
41 
43 {
44 #define _(pos, len, value, name, str) \
45  VNET_PUNT_REASON_F_MASK_##name = (((1 << (len)) - 1) << (pos)),
47 #undef _
48 };
49 
50 /* predicates associated with vlib_punt_reason_flag_t*/
51 #define _(pos, len, value, name, str) \
52  static_always_inline int vnet_punt_reason_flag_is_##name ( \
53  vnet_punt_reason_flag_t f) \
54  { \
55  return (f & VNET_PUNT_REASON_F_MASK_##name) == VNET_PUNT_REASON_F_##name; \
56  }
58 #undef _
59 
60 #define foreach_punt_type \
61  _(L4, "l4") \
62  _(EXCEPTION, "exception") \
63  _(IP_PROTO, "ip-proto")
64 
65  typedef enum punt_type_t_ {
66 #define _(v, s) PUNT_TYPE_##v,
68 #undef _
69  } punt_type_t;
70 
71 typedef struct punt_l4_t_
72 {
76 } punt_l4_t;
77 
78 typedef struct punt_ip_proto_t_
79 {
83 
84 typedef struct punt_exception_t_
85 {
88 
89 typedef struct punt_union_t_
90 {
94 } punt_union_t;
95 
96 typedef struct punt_reg_t_
97 {
100 } punt_reg_t;
101 
102 
104  const punt_reg_t * pr, bool is_add);
106  u32 header_version,
107  const punt_reg_t * pr,
108  char *client_pathname);
110 char *vnet_punt_get_server_pathname (void);
111 
113 {
114  PUNT_L2 = 0,
117 };
118 
119 /*
120  * Packet descriptor header. Version 1
121  * If this header changes, the version must also change to notify clients.
122  */
123 #define PUNT_PACKETDESC_VERSION 1
124 typedef struct __attribute__ ((packed))
125 {
126  u32 sw_if_index; /* RX or TX interface */
129 
130 /*
131  * Client registration
132  */
133 typedef struct
134 {
136  struct sockaddr_un caddr;
137 } punt_client_t;
138 
139 typedef struct punt_client_db_t_
140 {
145 
146 typedef struct punt_thread_data_t_
147 {
148  struct iovec *iovecs;
150 
151 typedef struct
152 {
154  char sun_path[sizeof (struct sockaddr_un)];
164 } punt_main_t;
165 
166 extern punt_main_t punt_main;
167 
169  void *ctx);
170 extern void punt_client_walk (punt_type_t pt,
171  punt_client_walk_cb_t cb, void *ctx);
172 
173 extern u8 *format_vnet_punt_reason_flags (u8 *s, va_list *args);
174 
175 /*
176  * inlines for the data-plane
177  */
180 {
181  return (af << BITS (port) | port);
182 }
183 
186 {
187  punt_main_t *pm = &punt_main;
188  uword *p;
189 
191 
192  if (p)
193  return (pool_elt_at_index (pm->punt_client_pool, p[0]));
194 
195  return (NULL);
196 }
197 
200 {
201  return (af << 16 | proto);
202 }
203 
206 {
207  punt_main_t *pm = &punt_main;
208  uword *p;
209 
210  p =
213 
214  if (p)
215  return (pool_elt_at_index (pm->punt_client_pool, p[0]));
216 
217  return (NULL);
218 }
219 
222 {
223  punt_main_t *pm = &punt_main;
224  u32 pci;
225 
226  if (reason >= vec_len (pm->db.clients_by_exception))
227  return (NULL);
228 
229  pci = pm->db.clients_by_exception[reason];
230 
231  if (~0 != pci)
232  return (pool_elt_at_index (pm->punt_client_pool, pci));
233 
234  return (NULL);
235 }
236 
244 
245 #endif
246 
247 /*
248  * fd.io coding-style-patch-verification: ON
249  *
250  * Local Variables:
251  * eval: (c-set-style "gnu")
252  * End:
253  */
vlib_punt_reason_t
enum vlib_punt_reason_t_ vlib_punt_reason_t
The 'syatem' defined punt reasons.
punt_union_t_
Definition: punt.h:89
punt_client_t
Definition: punt.h:133
udp4_punt_node
vlib_node_registration_t udp4_punt_node
(constructor) VLIB_REGISTER_NODE (udp4_punt_node)
Definition: punt_node.c:186
punt_client_walk
void punt_client_walk(punt_type_t pt, punt_client_walk_cb_t cb, void *ctx)
Definition: punt.c:691
punt_union_t
struct punt_union_t_ punt_union_t
punt_reg_t_
A registration, by a client, to direct punted traffic to a given node.
Definition: punt.h:96
punt_main_t::punt_client_pool
punt_client_t * punt_client_pool
Definition: punt.h:156
foreach_punt_type
#define foreach_punt_type
Definition: punt.h:60
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
punt_main_t::interface_output_node
vlib_node_t * interface_output_node
Definition: punt.h:159
punt_exception_t
struct punt_exception_t_ punt_exception_t
punt_client_t
struct punt_client_t_ punt_client_t
A client using the punt serivce and its registrations.
punt_l4_t_::af
ip_address_family_t af
Definition: punt.h:73
vnet_punt_reason_flag_mask_t_
vnet_punt_reason_flag_mask_t_
Definition: punt.h:42
punt_ip_proto_t_::protocol
ip_protocol_t protocol
Definition: punt.h:81
punt_main_t::clib_file_index
u32 clib_file_index
Definition: punt.h:157
vnet_punt_socket_add
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:289
u16
unsigned short u16
Definition: types.h:57
punt_client_exception_get
static_always_inline punt_client_t * punt_client_exception_get(vlib_punt_reason_t reason)
Definition: punt.h:221
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
port
u16 port
Definition: lb_types.api:73
vnet_punt_add_del
clib_error_t * vnet_punt_add_del(vlib_main_t *vm, const punt_reg_t *pr, bool is_add)
Definition: punt.c:435
punt_client_db_t_::clients_by_ip_proto
void * clients_by_ip_proto
Definition: punt.h:143
punt_client_l4_mk_key
static_always_inline u32 punt_client_l4_mk_key(ip_address_family_t af, u16 port)
Definition: punt.h:179
punt_packetdesc_t
Definition: punt.h:124
punt_client_db_t
struct punt_client_db_t_ punt_client_db_t
punt_client_ip_proto_get
static_always_inline punt_client_t * punt_client_ip_proto_get(ip_address_family_t af, ip_protocol_t proto)
Definition: punt.h:205
vnet_punt_socket_del
clib_error_t * vnet_punt_socket_del(vlib_main_t *vm, const punt_reg_t *pr)
Definition: punt.c:329
punt_client_db_t_::clients_by_exception
u32 * clients_by_exception
Definition: punt.h:142
punt_main_t
Definition: punt.h:151
format_vnet_punt_reason_flags
u8 * format_vnet_punt_reason_flags(u8 *s, va_list *args)
Definition: punt.c:849
punt_client_l4_get
static_always_inline punt_client_t * punt_client_l4_get(ip_address_family_t af, u16 port)
Definition: punt.h:185
punt_ip_proto_t_
Definition: punt.h:78
punt_main
punt_main_t punt_main
Definition: punt.c:38
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
punt_union_t_::ip_proto
punt_ip_proto_t ip_proto
Definition: punt.h:93
punt_union_t_::exception
punt_exception_t exception
Definition: punt.h:91
punt_client_db_t_::clients_by_l4_port
void * clients_by_l4_port
Definition: punt.h:141
udp4_punt_socket_node
vlib_node_registration_t udp4_punt_socket_node
(constructor) VLIB_REGISTER_NODE (udp4_punt_socket_node)
Definition: punt_node.c:439
punt_thread_data_t_
Definition: punt.h:146
punt_client_t::reg
punt_reg_t reg
Definition: punt.h:135
BITS
#define BITS(x)
Definition: clib.h:69
punt_ip_proto_t_::af
ip_address_family_t af
Definition: punt.h:80
static_always_inline
#define static_always_inline
Definition: clib.h:112
punt_client_walk_cb_t
walk_rc_t(* punt_client_walk_cb_t)(const punt_client_t *pc, void *ctx)
Definition: punt.h:168
foreach_vnet_punt_reason_flag
#define foreach_vnet_punt_reason_flag
Definition: punt.h:30
uword
u64 uword
Definition: types.h:112
hash_get
#define hash_get(h, key)
Definition: hash.h:249
punt_main_t::rx_buffers
u32 * rx_buffers
Definition: punt.h:161
punt_client_db_t_
Definition: punt.h:139
punt_main_t::db
punt_client_db_t db
Definition: punt.h:155
punt_exception_t_
Definition: punt.h:84
punt_l4_t_::port
u16 port
Definition: punt.h:75
punt_main_t::ready_fds
u32 * ready_fds
Definition: punt.h:160
PUNT_L2
@ PUNT_L2
Definition: punt.h:114
punt_reg_t_::punt
punt_union_t punt
Definition: punt.h:99
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
punt_socket_rx_node
vlib_node_registration_t punt_socket_rx_node
(constructor) VLIB_REGISTER_NODE (punt_socket_rx_node)
Definition: punt_node.c:618
punt_client_ip_proto_mk_key
static_always_inline u32 punt_client_ip_proto_mk_key(ip_address_family_t af, ip_protocol_t proto)
Definition: punt.h:199
punt_action_e
punt_action_e
Definition: punt.h:112
punt_l4_t_
Definition: punt.h:71
PUNT_IP4_ROUTED
@ PUNT_IP4_ROUTED
Definition: punt.h:115
PUNT_IP6_ROUTED
@ PUNT_IP6_ROUTED
Definition: punt.h:116
punt_ip_proto_t
struct punt_ip_proto_t_ punt_ip_proto_t
punt_reg_t
struct punt_reg_t_ punt_reg_t
punt_thread_data_t_::iovecs
struct iovec * iovecs
Definition: punt.h:148
vnet_punt_get_server_pathname
char * vnet_punt_get_server_pathname(void)
Definition: punt.c:41
ip.h
punt_l4_t_::protocol
ip_protocol_t protocol
Definition: punt.h:74
u32
unsigned int u32
Definition: types.h:88
vnet_punt_reason_flag_t_
vnet_punt_reason_flag_t_
Definition: punt.h:34
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
ip6_proto_punt_socket_node
vlib_node_registration_t ip6_proto_punt_socket_node
(constructor) VLIB_REGISTER_NODE (ip6_proto_punt_socket_node)
Definition: punt_node.c:468
punt_type_t_
punt_type_t_
Definition: punt.h:65
udp6_punt_socket_node
vlib_node_registration_t udp6_punt_socket_node
(constructor) VLIB_REGISTER_NODE (udp6_punt_socket_node)
Definition: punt_node.c:449
punt_exception_t_::reason
vlib_punt_reason_t reason
Definition: punt.h:86
vlib_punt_hdl_t
int vlib_punt_hdl_t
Typedef for a client handle.
Definition: punt.h:52
punt_type_t
enum punt_type_t_ punt_type_t
ip_protocol_t
enum ip_protocol ip_protocol_t
vlib_main_t
Definition: main.h:102
punt_main_t::socket_fd
int socket_fd
Definition: punt.h:153
vlib_node_t
Definition: node.h:247
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
punt_packetdesc_t::sw_if_index
u32 sw_if_index
Definition: punt.h:126
punt_union_t_::l4
punt_l4_t l4
Definition: punt.h:92
punt_main_t::thread_data
punt_thread_data_t * thread_data
Definition: punt.h:162
punt_thread_data_t
struct punt_thread_data_t_ punt_thread_data_t
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
vnet_punt_reason_flag_t
enum vnet_punt_reason_flag_t_ vnet_punt_reason_flag_t
punt_reg_t_::type
punt_type_t type
Definition: punt.h:98
action
vl_api_mac_event_action_t action
Definition: l2.api:211
punt_main_t::is_configured
bool is_configured
Definition: punt.h:158
punt_main_t::hdl
vlib_punt_hdl_t hdl
Definition: punt.h:163
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
ip4_proto_punt_socket_node
vlib_node_registration_t ip4_proto_punt_socket_node
(constructor) VLIB_REGISTER_NODE (ip4_proto_punt_socket_node)
Definition: punt_node.c:458
udp6_punt_node
vlib_node_registration_t udp6_punt_node
(constructor) VLIB_REGISTER_NODE (udp6_punt_node)
Definition: punt_node.c:202
ip_address_family_t
enum ip_address_family_t_ ip_address_family_t
punt_l4_t
struct punt_l4_t_ punt_l4_t