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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @brief Definitions for punt infrastructure.
20 #ifndef included_punt_h
21 #define included_punt_h
27 #define UNIX_PATH_MAX SUNPATHLEN
28 #endif /* __linux__ */
30 #include <vnet/ip/ip.h>
32 /* Punting reason flags bitfield
33 * (position, length, value, name, string)
35 #define foreach_vnet_punt_reason_flag \
36 _ (0, 1, 0, IP4_PACKET, "ip4-packet") \
37 _ (0, 1, 1, IP6_PACKET, "ip6-packet")
39 typedef enum vnet_punt_reason_flag_t_
41 #define _(pos, len, value, name, str) \
42 VNET_PUNT_REASON_F_##name = ((value) << (pos)),
43 foreach_vnet_punt_reason_flag
45 } __clib_packed vnet_punt_reason_flag_t;
47 enum vnet_punt_reason_flag_mask_t_
49 #define _(pos, len, value, name, str) \
50 VNET_PUNT_REASON_F_MASK_##name = (((1 << (len)) - 1) << (pos)),
51 foreach_vnet_punt_reason_flag
55 /* predicates associated with vlib_punt_reason_flag_t*/
56 #define _(pos, len, value, name, str) \
57 static_always_inline int vnet_punt_reason_flag_is_##name ( \
58 vnet_punt_reason_flag_t f) \
60 return (f & VNET_PUNT_REASON_F_MASK_##name) == VNET_PUNT_REASON_F_##name; \
62 foreach_vnet_punt_reason_flag
65 #define foreach_punt_type \
67 _(EXCEPTION, "exception") \
68 _(IP_PROTO, "ip-proto")
70 typedef enum punt_type_t_ {
71 #define _(v, s) PUNT_TYPE_##v,
76 typedef struct punt_l4_t_
78 ip_address_family_t af;
79 ip_protocol_t protocol;
83 typedef struct punt_ip_proto_t_
85 ip_address_family_t af;
86 ip_protocol_t protocol;
89 typedef struct punt_exception_t_
91 vlib_punt_reason_t reason;
94 typedef struct punt_union_t_
96 punt_exception_t exception;
98 punt_ip_proto_t ip_proto;
101 typedef struct punt_reg_t_
108 clib_error_t *vnet_punt_add_del (vlib_main_t * vm,
109 const punt_reg_t * pr, bool is_add);
110 clib_error_t *vnet_punt_socket_add (vlib_main_t * vm,
112 const punt_reg_t * pr,
113 char *client_pathname);
114 clib_error_t *vnet_punt_socket_del (vlib_main_t * vm, const punt_reg_t * pr);
115 char *vnet_punt_get_server_pathname (void);
125 * Packet descriptor header. Version 1
126 * If this header changes, the version must also change to notify clients.
128 #define PUNT_PACKETDESC_VERSION 1
129 typedef struct __attribute__ ((packed))
131 u32 sw_if_index; /* RX or TX interface */
132 enum punt_action_e action;
136 * Client registration
141 struct sockaddr_un caddr;
144 typedef struct punt_client_db_t_
146 void *clients_by_l4_port;
147 u32 *clients_by_exception;
148 void *clients_by_ip_proto;
151 typedef struct punt_thread_data_t_
153 struct iovec *iovecs;
154 } punt_thread_data_t;
159 char sun_path[sizeof (struct sockaddr_un)];
161 punt_client_t *punt_client_pool;
164 vlib_node_t *interface_output_node;
167 punt_thread_data_t *thread_data;
172 extern punt_main_t punt_main;
174 typedef walk_rc_t (*punt_client_walk_cb_t) (const punt_client_t * pc,
176 extern void punt_client_walk (punt_type_t pt,
177 punt_client_walk_cb_t cb, void *ctx);
179 extern u8 *format_vnet_punt_reason_flags (u8 *s, va_list *args);
182 * inlines for the data-plane
184 static_always_inline u32
185 punt_client_l4_mk_key (ip_address_family_t af, u16 port)
187 return (af << BITS (port) | port);
190 static_always_inline punt_client_t *
191 punt_client_l4_get (ip_address_family_t af, u16 port)
193 punt_main_t *pm = &punt_main;
196 p = hash_get (pm->db.clients_by_l4_port, punt_client_l4_mk_key (af, port));
199 return (pool_elt_at_index (pm->punt_client_pool, p[0]));
204 static_always_inline u32
205 punt_client_ip_proto_mk_key (ip_address_family_t af, ip_protocol_t proto)
207 return (af << 16 | proto);
210 static_always_inline punt_client_t *
211 punt_client_ip_proto_get (ip_address_family_t af, ip_protocol_t proto)
213 punt_main_t *pm = &punt_main;
217 hash_get (pm->db.clients_by_ip_proto,
218 punt_client_ip_proto_mk_key (af, proto));
221 return (pool_elt_at_index (pm->punt_client_pool, p[0]));
226 static_always_inline punt_client_t *
227 punt_client_exception_get (vlib_punt_reason_t reason)
229 punt_main_t *pm = &punt_main;
232 if (reason >= vec_len (pm->db.clients_by_exception))
235 pci = pm->db.clients_by_exception[reason];
238 return (pool_elt_at_index (pm->punt_client_pool, pci));
243 extern vlib_node_registration_t udp4_punt_node;
244 extern vlib_node_registration_t udp6_punt_node;
245 extern vlib_node_registration_t udp4_punt_socket_node;
246 extern vlib_node_registration_t udp6_punt_socket_node;
247 extern vlib_node_registration_t icmp6_punt_socket_node;
248 extern vlib_node_registration_t ip4_proto_punt_socket_node;
249 extern vlib_node_registration_t ip6_proto_punt_socket_node;
250 extern vlib_node_registration_t punt_socket_rx_node;
255 * fd.io coding-style-patch-verification: ON
258 * eval: (c-set-style "gnu")