@@ -115,6 +115,7 @@ struct udp_tunnel_info {
115115 unsigned short type ;
116116 sa_family_t sa_family ;
117117 __be16 port ;
118+ u8 hw_priv ;
118119};
119120
120121/* Notify network devices of offloadable types */
@@ -181,4 +182,140 @@ static inline void udp_tunnel_encap_enable(struct socket *sock)
181182 udp_encap_enable ();
182183}
183184
185+ #define UDP_TUNNEL_NIC_MAX_TABLES 4
186+
187+ enum udp_tunnel_nic_info_flags {
188+ /* Device callbacks may sleep */
189+ UDP_TUNNEL_NIC_INFO_MAY_SLEEP = BIT (0 ),
190+ /* Device only supports offloads when it's open, all ports
191+ * will be removed before close and re-added after open.
192+ */
193+ UDP_TUNNEL_NIC_INFO_OPEN_ONLY = BIT (1 ),
194+ /* Device supports only IPv4 tunnels */
195+ UDP_TUNNEL_NIC_INFO_IPV4_ONLY = BIT (2 ),
196+ };
197+
198+ /**
199+ * struct udp_tunnel_nic_info - driver UDP tunnel offload information
200+ * @set_port: callback for adding a new port
201+ * @unset_port: callback for removing a port
202+ * @sync_table: callback for syncing the entire port table at once
203+ * @flags: device flags from enum udp_tunnel_nic_info_flags
204+ * @tables: UDP port tables this device has
205+ * @tables.n_entries: number of entries in this table
206+ * @tables.tunnel_types: types of tunnels this table accepts
207+ *
208+ * Drivers are expected to provide either @set_port and @unset_port callbacks
209+ * or the @sync_table callback. Callbacks are invoked with rtnl lock held.
210+ *
211+ * Known limitations:
212+ * - UDP tunnel port notifications are fundamentally best-effort -
213+ * it is likely the driver will both see skbs which use a UDP tunnel port,
214+ * while not being a tunneled skb, and tunnel skbs from other ports -
215+ * drivers should only use these ports for non-critical RX-side offloads,
216+ * e.g. the checksum offload;
217+ * - none of the devices care about the socket family at present, so we don't
218+ * track it. Please extend this code if you care.
219+ */
220+ struct udp_tunnel_nic_info {
221+ /* one-by-one */
222+ int (* set_port )(struct net_device * dev ,
223+ unsigned int table , unsigned int entry ,
224+ struct udp_tunnel_info * ti );
225+ int (* unset_port )(struct net_device * dev ,
226+ unsigned int table , unsigned int entry ,
227+ struct udp_tunnel_info * ti );
228+
229+ /* all at once */
230+ int (* sync_table )(struct net_device * dev , unsigned int table );
231+
232+ unsigned int flags ;
233+
234+ struct udp_tunnel_nic_table_info {
235+ unsigned int n_entries ;
236+ unsigned int tunnel_types ;
237+ } tables [UDP_TUNNEL_NIC_MAX_TABLES ];
238+ };
239+
240+ /* UDP tunnel module dependencies
241+ *
242+ * Tunnel drivers are expected to have a hard dependency on the udp_tunnel
243+ * module. NIC drivers are not, they just attach their
244+ * struct udp_tunnel_nic_info to the netdev and wait for callbacks to come.
245+ * Loading a tunnel driver will cause the udp_tunnel module to be loaded
246+ * and only then will all the required state structures be allocated.
247+ * Since we want a weak dependency from the drivers and the core to udp_tunnel
248+ * we call things through the following stubs.
249+ */
250+ struct udp_tunnel_nic_ops {
251+ void (* get_port )(struct net_device * dev , unsigned int table ,
252+ unsigned int idx , struct udp_tunnel_info * ti );
253+ void (* set_port_priv )(struct net_device * dev , unsigned int table ,
254+ unsigned int idx , u8 priv );
255+ void (* add_port )(struct net_device * dev , struct udp_tunnel_info * ti );
256+ void (* del_port )(struct net_device * dev , struct udp_tunnel_info * ti );
257+ void (* reset_ntf )(struct net_device * dev );
258+ };
259+
260+ #ifdef CONFIG_INET
261+ extern const struct udp_tunnel_nic_ops * udp_tunnel_nic_ops ;
262+ #else
263+ #define udp_tunnel_nic_ops ((struct udp_tunnel_nic_ops *)NULL)
264+ #endif
265+
266+ static inline void
267+ udp_tunnel_nic_get_port (struct net_device * dev , unsigned int table ,
268+ unsigned int idx , struct udp_tunnel_info * ti )
269+ {
270+ /* This helper is used from .sync_table, we indicate empty entries
271+ * by zero'ed @ti. Drivers which need to know the details of a port
272+ * when it gets deleted should use the .set_port / .unset_port
273+ * callbacks.
274+ * Zero out here, otherwise !CONFIG_INET causes uninitilized warnings.
275+ */
276+ memset (ti , 0 , sizeof (* ti ));
277+
278+ if (udp_tunnel_nic_ops )
279+ udp_tunnel_nic_ops -> get_port (dev , table , idx , ti );
280+ }
281+
282+ static inline void
283+ udp_tunnel_nic_set_port_priv (struct net_device * dev , unsigned int table ,
284+ unsigned int idx , u8 priv )
285+ {
286+ if (udp_tunnel_nic_ops )
287+ udp_tunnel_nic_ops -> set_port_priv (dev , table , idx , priv );
288+ }
289+
290+ static inline void
291+ udp_tunnel_nic_add_port (struct net_device * dev , struct udp_tunnel_info * ti )
292+ {
293+ if (udp_tunnel_nic_ops )
294+ udp_tunnel_nic_ops -> add_port (dev , ti );
295+ }
296+
297+ static inline void
298+ udp_tunnel_nic_del_port (struct net_device * dev , struct udp_tunnel_info * ti )
299+ {
300+ if (udp_tunnel_nic_ops )
301+ udp_tunnel_nic_ops -> del_port (dev , ti );
302+ }
303+
304+ /**
305+ * udp_tunnel_nic_reset_ntf() - device-originating reset notification
306+ * @dev: network interface device structure
307+ *
308+ * Called by the driver to inform the core that the entire UDP tunnel port
309+ * state has been lost, usually due to device reset. Core will assume device
310+ * forgot all the ports and issue .set_port and .sync_table callbacks as
311+ * necessary.
312+ *
313+ * This function must be called with rtnl lock held, and will issue all
314+ * the callbacks before returning.
315+ */
316+ static inline void udp_tunnel_nic_reset_ntf (struct net_device * dev )
317+ {
318+ if (udp_tunnel_nic_ops )
319+ udp_tunnel_nic_ops -> reset_ntf (dev );
320+ }
184321#endif
0 commit comments