xref: /OK3568_Linux_fs/kernel/include/net/udp_tunnel.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef __NET_UDP_TUNNEL_H
3*4882a593Smuzhiyun #define __NET_UDP_TUNNEL_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <net/ip_tunnels.h>
6*4882a593Smuzhiyun #include <net/udp.h>
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_IPV6)
9*4882a593Smuzhiyun #include <net/ipv6.h>
10*4882a593Smuzhiyun #include <net/ipv6_stubs.h>
11*4882a593Smuzhiyun #endif
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun struct udp_port_cfg {
14*4882a593Smuzhiyun 	u8			family;
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun 	/* Used only for kernel-created sockets */
17*4882a593Smuzhiyun 	union {
18*4882a593Smuzhiyun 		struct in_addr		local_ip;
19*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_IPV6)
20*4882a593Smuzhiyun 		struct in6_addr		local_ip6;
21*4882a593Smuzhiyun #endif
22*4882a593Smuzhiyun 	};
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun 	union {
25*4882a593Smuzhiyun 		struct in_addr		peer_ip;
26*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_IPV6)
27*4882a593Smuzhiyun 		struct in6_addr		peer_ip6;
28*4882a593Smuzhiyun #endif
29*4882a593Smuzhiyun 	};
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun 	__be16			local_udp_port;
32*4882a593Smuzhiyun 	__be16			peer_udp_port;
33*4882a593Smuzhiyun 	int			bind_ifindex;
34*4882a593Smuzhiyun 	unsigned int		use_udp_checksums:1,
35*4882a593Smuzhiyun 				use_udp6_tx_checksums:1,
36*4882a593Smuzhiyun 				use_udp6_rx_checksums:1,
37*4882a593Smuzhiyun 				ipv6_v6only:1;
38*4882a593Smuzhiyun };
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun int udp_sock_create4(struct net *net, struct udp_port_cfg *cfg,
41*4882a593Smuzhiyun 		     struct socket **sockp);
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_IPV6)
44*4882a593Smuzhiyun int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
45*4882a593Smuzhiyun 		     struct socket **sockp);
46*4882a593Smuzhiyun #else
udp_sock_create6(struct net * net,struct udp_port_cfg * cfg,struct socket ** sockp)47*4882a593Smuzhiyun static inline int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
48*4882a593Smuzhiyun 				   struct socket **sockp)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun 	return 0;
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun #endif
53*4882a593Smuzhiyun 
udp_sock_create(struct net * net,struct udp_port_cfg * cfg,struct socket ** sockp)54*4882a593Smuzhiyun static inline int udp_sock_create(struct net *net,
55*4882a593Smuzhiyun 				  struct udp_port_cfg *cfg,
56*4882a593Smuzhiyun 				  struct socket **sockp)
57*4882a593Smuzhiyun {
58*4882a593Smuzhiyun 	if (cfg->family == AF_INET)
59*4882a593Smuzhiyun 		return udp_sock_create4(net, cfg, sockp);
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	if (cfg->family == AF_INET6)
62*4882a593Smuzhiyun 		return udp_sock_create6(net, cfg, sockp);
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	return -EPFNOSUPPORT;
65*4882a593Smuzhiyun }
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun typedef int (*udp_tunnel_encap_rcv_t)(struct sock *sk, struct sk_buff *skb);
68*4882a593Smuzhiyun typedef int (*udp_tunnel_encap_err_lookup_t)(struct sock *sk,
69*4882a593Smuzhiyun 					     struct sk_buff *skb);
70*4882a593Smuzhiyun typedef void (*udp_tunnel_encap_destroy_t)(struct sock *sk);
71*4882a593Smuzhiyun typedef struct sk_buff *(*udp_tunnel_gro_receive_t)(struct sock *sk,
72*4882a593Smuzhiyun 						    struct list_head *head,
73*4882a593Smuzhiyun 						    struct sk_buff *skb);
74*4882a593Smuzhiyun typedef int (*udp_tunnel_gro_complete_t)(struct sock *sk, struct sk_buff *skb,
75*4882a593Smuzhiyun 					 int nhoff);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun struct udp_tunnel_sock_cfg {
78*4882a593Smuzhiyun 	void *sk_user_data;     /* user data used by encap_rcv call back */
79*4882a593Smuzhiyun 	/* Used for setting up udp_sock fields, see udp.h for details */
80*4882a593Smuzhiyun 	__u8  encap_type;
81*4882a593Smuzhiyun 	udp_tunnel_encap_rcv_t encap_rcv;
82*4882a593Smuzhiyun 	udp_tunnel_encap_err_lookup_t encap_err_lookup;
83*4882a593Smuzhiyun 	udp_tunnel_encap_destroy_t encap_destroy;
84*4882a593Smuzhiyun 	udp_tunnel_gro_receive_t gro_receive;
85*4882a593Smuzhiyun 	udp_tunnel_gro_complete_t gro_complete;
86*4882a593Smuzhiyun };
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun /* Setup the given (UDP) sock to receive UDP encapsulated packets */
89*4882a593Smuzhiyun void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
90*4882a593Smuzhiyun 			   struct udp_tunnel_sock_cfg *sock_cfg);
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun /* -- List of parsable UDP tunnel types --
93*4882a593Smuzhiyun  *
94*4882a593Smuzhiyun  * Adding to this list will result in serious debate.  The main issue is
95*4882a593Smuzhiyun  * that this list is essentially a list of workarounds for either poorly
96*4882a593Smuzhiyun  * designed tunnels, or poorly designed device offloads.
97*4882a593Smuzhiyun  *
98*4882a593Smuzhiyun  * The parsing supported via these types should really be used for Rx
99*4882a593Smuzhiyun  * traffic only as the network stack will have already inserted offsets for
100*4882a593Smuzhiyun  * the location of the headers in the skb.  In addition any ports that are
101*4882a593Smuzhiyun  * pushed should be kept within the namespace without leaking to other
102*4882a593Smuzhiyun  * devices such as VFs or other ports on the same device.
103*4882a593Smuzhiyun  *
104*4882a593Smuzhiyun  * It is strongly encouraged to use CHECKSUM_COMPLETE for Rx to avoid the
105*4882a593Smuzhiyun  * need to use this for Rx checksum offload.  It should not be necessary to
106*4882a593Smuzhiyun  * call this function to perform Tx offloads on outgoing traffic.
107*4882a593Smuzhiyun  */
108*4882a593Smuzhiyun enum udp_parsable_tunnel_type {
109*4882a593Smuzhiyun 	UDP_TUNNEL_TYPE_VXLAN	  = BIT(0), /* RFC 7348 */
110*4882a593Smuzhiyun 	UDP_TUNNEL_TYPE_GENEVE	  = BIT(1), /* draft-ietf-nvo3-geneve */
111*4882a593Smuzhiyun 	UDP_TUNNEL_TYPE_VXLAN_GPE = BIT(2), /* draft-ietf-nvo3-vxlan-gpe */
112*4882a593Smuzhiyun };
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun struct udp_tunnel_info {
115*4882a593Smuzhiyun 	unsigned short type;
116*4882a593Smuzhiyun 	sa_family_t sa_family;
117*4882a593Smuzhiyun 	__be16 port;
118*4882a593Smuzhiyun 	u8 hw_priv;
119*4882a593Smuzhiyun };
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun /* Notify network devices of offloadable types */
122*4882a593Smuzhiyun void udp_tunnel_push_rx_port(struct net_device *dev, struct socket *sock,
123*4882a593Smuzhiyun 			     unsigned short type);
124*4882a593Smuzhiyun void udp_tunnel_drop_rx_port(struct net_device *dev, struct socket *sock,
125*4882a593Smuzhiyun 			     unsigned short type);
126*4882a593Smuzhiyun void udp_tunnel_notify_add_rx_port(struct socket *sock, unsigned short type);
127*4882a593Smuzhiyun void udp_tunnel_notify_del_rx_port(struct socket *sock, unsigned short type);
128*4882a593Smuzhiyun 
udp_tunnel_get_rx_info(struct net_device * dev)129*4882a593Smuzhiyun static inline void udp_tunnel_get_rx_info(struct net_device *dev)
130*4882a593Smuzhiyun {
131*4882a593Smuzhiyun 	ASSERT_RTNL();
132*4882a593Smuzhiyun 	call_netdevice_notifiers(NETDEV_UDP_TUNNEL_PUSH_INFO, dev);
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun 
udp_tunnel_drop_rx_info(struct net_device * dev)135*4882a593Smuzhiyun static inline void udp_tunnel_drop_rx_info(struct net_device *dev)
136*4882a593Smuzhiyun {
137*4882a593Smuzhiyun 	ASSERT_RTNL();
138*4882a593Smuzhiyun 	call_netdevice_notifiers(NETDEV_UDP_TUNNEL_DROP_INFO, dev);
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun /* Transmit the skb using UDP encapsulation. */
142*4882a593Smuzhiyun void udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
143*4882a593Smuzhiyun 			 __be32 src, __be32 dst, __u8 tos, __u8 ttl,
144*4882a593Smuzhiyun 			 __be16 df, __be16 src_port, __be16 dst_port,
145*4882a593Smuzhiyun 			 bool xnet, bool nocheck);
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun int udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk,
148*4882a593Smuzhiyun 			 struct sk_buff *skb,
149*4882a593Smuzhiyun 			 struct net_device *dev, struct in6_addr *saddr,
150*4882a593Smuzhiyun 			 struct in6_addr *daddr,
151*4882a593Smuzhiyun 			 __u8 prio, __u8 ttl, __be32 label,
152*4882a593Smuzhiyun 			 __be16 src_port, __be16 dst_port, bool nocheck);
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun void udp_tunnel_sock_release(struct socket *sock);
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family,
157*4882a593Smuzhiyun 				    __be16 flags, __be64 tunnel_id,
158*4882a593Smuzhiyun 				    int md_size);
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun #ifdef CONFIG_INET
udp_tunnel_handle_offloads(struct sk_buff * skb,bool udp_csum)161*4882a593Smuzhiyun static inline int udp_tunnel_handle_offloads(struct sk_buff *skb, bool udp_csum)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun 	int type = udp_csum ? SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL;
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun 	return iptunnel_handle_offloads(skb, type);
166*4882a593Smuzhiyun }
167*4882a593Smuzhiyun #endif
168*4882a593Smuzhiyun 
udp_tunnel_encap_enable(struct socket * sock)169*4882a593Smuzhiyun static inline void udp_tunnel_encap_enable(struct socket *sock)
170*4882a593Smuzhiyun {
171*4882a593Smuzhiyun 	struct udp_sock *up = udp_sk(sock->sk);
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	if (up->encap_enabled)
174*4882a593Smuzhiyun 		return;
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	up->encap_enabled = 1;
177*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_IPV6)
178*4882a593Smuzhiyun 	if (sock->sk->sk_family == PF_INET6)
179*4882a593Smuzhiyun 		ipv6_stub->udpv6_encap_enable();
180*4882a593Smuzhiyun #endif
181*4882a593Smuzhiyun 	udp_encap_enable();
182*4882a593Smuzhiyun }
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun #define UDP_TUNNEL_NIC_MAX_TABLES	4
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun enum udp_tunnel_nic_info_flags {
187*4882a593Smuzhiyun 	/* Device callbacks may sleep */
188*4882a593Smuzhiyun 	UDP_TUNNEL_NIC_INFO_MAY_SLEEP	= BIT(0),
189*4882a593Smuzhiyun 	/* Device only supports offloads when it's open, all ports
190*4882a593Smuzhiyun 	 * will be removed before close and re-added after open.
191*4882a593Smuzhiyun 	 */
192*4882a593Smuzhiyun 	UDP_TUNNEL_NIC_INFO_OPEN_ONLY	= BIT(1),
193*4882a593Smuzhiyun 	/* Device supports only IPv4 tunnels */
194*4882a593Smuzhiyun 	UDP_TUNNEL_NIC_INFO_IPV4_ONLY	= BIT(2),
195*4882a593Smuzhiyun 	/* Device has hard-coded the IANA VXLAN port (4789) as VXLAN.
196*4882a593Smuzhiyun 	 * This port must not be counted towards n_entries of any table.
197*4882a593Smuzhiyun 	 * Driver will not receive any callback associated with port 4789.
198*4882a593Smuzhiyun 	 */
199*4882a593Smuzhiyun 	UDP_TUNNEL_NIC_INFO_STATIC_IANA_VXLAN	= BIT(3),
200*4882a593Smuzhiyun };
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun struct udp_tunnel_nic;
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun #define UDP_TUNNEL_NIC_MAX_SHARING_DEVICES	(U16_MAX / 2)
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun struct udp_tunnel_nic_shared {
207*4882a593Smuzhiyun 	struct udp_tunnel_nic *udp_tunnel_nic_info;
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	struct list_head devices;
210*4882a593Smuzhiyun };
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun struct udp_tunnel_nic_shared_node {
213*4882a593Smuzhiyun 	struct net_device *dev;
214*4882a593Smuzhiyun 	struct list_head list;
215*4882a593Smuzhiyun };
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun /**
218*4882a593Smuzhiyun  * struct udp_tunnel_nic_info - driver UDP tunnel offload information
219*4882a593Smuzhiyun  * @set_port:	callback for adding a new port
220*4882a593Smuzhiyun  * @unset_port:	callback for removing a port
221*4882a593Smuzhiyun  * @sync_table:	callback for syncing the entire port table at once
222*4882a593Smuzhiyun  * @shared:	reference to device global state (optional)
223*4882a593Smuzhiyun  * @flags:	device flags from enum udp_tunnel_nic_info_flags
224*4882a593Smuzhiyun  * @tables:	UDP port tables this device has
225*4882a593Smuzhiyun  * @tables.n_entries:		number of entries in this table
226*4882a593Smuzhiyun  * @tables.tunnel_types:	types of tunnels this table accepts
227*4882a593Smuzhiyun  *
228*4882a593Smuzhiyun  * Drivers are expected to provide either @set_port and @unset_port callbacks
229*4882a593Smuzhiyun  * or the @sync_table callback. Callbacks are invoked with rtnl lock held.
230*4882a593Smuzhiyun  *
231*4882a593Smuzhiyun  * Devices which (misguidedly) share the UDP tunnel port table across multiple
232*4882a593Smuzhiyun  * netdevs should allocate an instance of struct udp_tunnel_nic_shared and
233*4882a593Smuzhiyun  * point @shared at it.
234*4882a593Smuzhiyun  * There must never be more than %UDP_TUNNEL_NIC_MAX_SHARING_DEVICES devices
235*4882a593Smuzhiyun  * sharing a table.
236*4882a593Smuzhiyun  *
237*4882a593Smuzhiyun  * Known limitations:
238*4882a593Smuzhiyun  *  - UDP tunnel port notifications are fundamentally best-effort -
239*4882a593Smuzhiyun  *    it is likely the driver will both see skbs which use a UDP tunnel port,
240*4882a593Smuzhiyun  *    while not being a tunneled skb, and tunnel skbs from other ports -
241*4882a593Smuzhiyun  *    drivers should only use these ports for non-critical RX-side offloads,
242*4882a593Smuzhiyun  *    e.g. the checksum offload;
243*4882a593Smuzhiyun  *  - none of the devices care about the socket family at present, so we don't
244*4882a593Smuzhiyun  *    track it. Please extend this code if you care.
245*4882a593Smuzhiyun  */
246*4882a593Smuzhiyun struct udp_tunnel_nic_info {
247*4882a593Smuzhiyun 	/* one-by-one */
248*4882a593Smuzhiyun 	int (*set_port)(struct net_device *dev,
249*4882a593Smuzhiyun 			unsigned int table, unsigned int entry,
250*4882a593Smuzhiyun 			struct udp_tunnel_info *ti);
251*4882a593Smuzhiyun 	int (*unset_port)(struct net_device *dev,
252*4882a593Smuzhiyun 			  unsigned int table, unsigned int entry,
253*4882a593Smuzhiyun 			  struct udp_tunnel_info *ti);
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun 	/* all at once */
256*4882a593Smuzhiyun 	int (*sync_table)(struct net_device *dev, unsigned int table);
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun 	struct udp_tunnel_nic_shared *shared;
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun 	unsigned int flags;
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun 	struct udp_tunnel_nic_table_info {
263*4882a593Smuzhiyun 		unsigned int n_entries;
264*4882a593Smuzhiyun 		unsigned int tunnel_types;
265*4882a593Smuzhiyun 	} tables[UDP_TUNNEL_NIC_MAX_TABLES];
266*4882a593Smuzhiyun };
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun /* UDP tunnel module dependencies
269*4882a593Smuzhiyun  *
270*4882a593Smuzhiyun  * Tunnel drivers are expected to have a hard dependency on the udp_tunnel
271*4882a593Smuzhiyun  * module. NIC drivers are not, they just attach their
272*4882a593Smuzhiyun  * struct udp_tunnel_nic_info to the netdev and wait for callbacks to come.
273*4882a593Smuzhiyun  * Loading a tunnel driver will cause the udp_tunnel module to be loaded
274*4882a593Smuzhiyun  * and only then will all the required state structures be allocated.
275*4882a593Smuzhiyun  * Since we want a weak dependency from the drivers and the core to udp_tunnel
276*4882a593Smuzhiyun  * we call things through the following stubs.
277*4882a593Smuzhiyun  */
278*4882a593Smuzhiyun struct udp_tunnel_nic_ops {
279*4882a593Smuzhiyun 	void (*get_port)(struct net_device *dev, unsigned int table,
280*4882a593Smuzhiyun 			 unsigned int idx, struct udp_tunnel_info *ti);
281*4882a593Smuzhiyun 	void (*set_port_priv)(struct net_device *dev, unsigned int table,
282*4882a593Smuzhiyun 			      unsigned int idx, u8 priv);
283*4882a593Smuzhiyun 	void (*add_port)(struct net_device *dev, struct udp_tunnel_info *ti);
284*4882a593Smuzhiyun 	void (*del_port)(struct net_device *dev, struct udp_tunnel_info *ti);
285*4882a593Smuzhiyun 	void (*reset_ntf)(struct net_device *dev);
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun 	size_t (*dump_size)(struct net_device *dev, unsigned int table);
288*4882a593Smuzhiyun 	int (*dump_write)(struct net_device *dev, unsigned int table,
289*4882a593Smuzhiyun 			  struct sk_buff *skb);
290*4882a593Smuzhiyun };
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun #ifdef CONFIG_INET
293*4882a593Smuzhiyun extern const struct udp_tunnel_nic_ops *udp_tunnel_nic_ops;
294*4882a593Smuzhiyun #else
295*4882a593Smuzhiyun #define udp_tunnel_nic_ops	((struct udp_tunnel_nic_ops *)NULL)
296*4882a593Smuzhiyun #endif
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun static inline void
udp_tunnel_nic_get_port(struct net_device * dev,unsigned int table,unsigned int idx,struct udp_tunnel_info * ti)299*4882a593Smuzhiyun udp_tunnel_nic_get_port(struct net_device *dev, unsigned int table,
300*4882a593Smuzhiyun 			unsigned int idx, struct udp_tunnel_info *ti)
301*4882a593Smuzhiyun {
302*4882a593Smuzhiyun 	/* This helper is used from .sync_table, we indicate empty entries
303*4882a593Smuzhiyun 	 * by zero'ed @ti. Drivers which need to know the details of a port
304*4882a593Smuzhiyun 	 * when it gets deleted should use the .set_port / .unset_port
305*4882a593Smuzhiyun 	 * callbacks.
306*4882a593Smuzhiyun 	 * Zero out here, otherwise !CONFIG_INET causes uninitilized warnings.
307*4882a593Smuzhiyun 	 */
308*4882a593Smuzhiyun 	memset(ti, 0, sizeof(*ti));
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun 	if (udp_tunnel_nic_ops)
311*4882a593Smuzhiyun 		udp_tunnel_nic_ops->get_port(dev, table, idx, ti);
312*4882a593Smuzhiyun }
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun static inline void
udp_tunnel_nic_set_port_priv(struct net_device * dev,unsigned int table,unsigned int idx,u8 priv)315*4882a593Smuzhiyun udp_tunnel_nic_set_port_priv(struct net_device *dev, unsigned int table,
316*4882a593Smuzhiyun 			     unsigned int idx, u8 priv)
317*4882a593Smuzhiyun {
318*4882a593Smuzhiyun 	if (udp_tunnel_nic_ops)
319*4882a593Smuzhiyun 		udp_tunnel_nic_ops->set_port_priv(dev, table, idx, priv);
320*4882a593Smuzhiyun }
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun static inline void
udp_tunnel_nic_add_port(struct net_device * dev,struct udp_tunnel_info * ti)323*4882a593Smuzhiyun udp_tunnel_nic_add_port(struct net_device *dev, struct udp_tunnel_info *ti)
324*4882a593Smuzhiyun {
325*4882a593Smuzhiyun 	if (udp_tunnel_nic_ops)
326*4882a593Smuzhiyun 		udp_tunnel_nic_ops->add_port(dev, ti);
327*4882a593Smuzhiyun }
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun static inline void
udp_tunnel_nic_del_port(struct net_device * dev,struct udp_tunnel_info * ti)330*4882a593Smuzhiyun udp_tunnel_nic_del_port(struct net_device *dev, struct udp_tunnel_info *ti)
331*4882a593Smuzhiyun {
332*4882a593Smuzhiyun 	if (udp_tunnel_nic_ops)
333*4882a593Smuzhiyun 		udp_tunnel_nic_ops->del_port(dev, ti);
334*4882a593Smuzhiyun }
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun /**
337*4882a593Smuzhiyun  * udp_tunnel_nic_reset_ntf() - device-originating reset notification
338*4882a593Smuzhiyun  * @dev: network interface device structure
339*4882a593Smuzhiyun  *
340*4882a593Smuzhiyun  * Called by the driver to inform the core that the entire UDP tunnel port
341*4882a593Smuzhiyun  * state has been lost, usually due to device reset. Core will assume device
342*4882a593Smuzhiyun  * forgot all the ports and issue .set_port and .sync_table callbacks as
343*4882a593Smuzhiyun  * necessary.
344*4882a593Smuzhiyun  *
345*4882a593Smuzhiyun  * This function must be called with rtnl lock held, and will issue all
346*4882a593Smuzhiyun  * the callbacks before returning.
347*4882a593Smuzhiyun  */
udp_tunnel_nic_reset_ntf(struct net_device * dev)348*4882a593Smuzhiyun static inline void udp_tunnel_nic_reset_ntf(struct net_device *dev)
349*4882a593Smuzhiyun {
350*4882a593Smuzhiyun 	if (udp_tunnel_nic_ops)
351*4882a593Smuzhiyun 		udp_tunnel_nic_ops->reset_ntf(dev);
352*4882a593Smuzhiyun }
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun static inline size_t
udp_tunnel_nic_dump_size(struct net_device * dev,unsigned int table)355*4882a593Smuzhiyun udp_tunnel_nic_dump_size(struct net_device *dev, unsigned int table)
356*4882a593Smuzhiyun {
357*4882a593Smuzhiyun 	if (!udp_tunnel_nic_ops)
358*4882a593Smuzhiyun 		return 0;
359*4882a593Smuzhiyun 	return udp_tunnel_nic_ops->dump_size(dev, table);
360*4882a593Smuzhiyun }
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun static inline int
udp_tunnel_nic_dump_write(struct net_device * dev,unsigned int table,struct sk_buff * skb)363*4882a593Smuzhiyun udp_tunnel_nic_dump_write(struct net_device *dev, unsigned int table,
364*4882a593Smuzhiyun 			  struct sk_buff *skb)
365*4882a593Smuzhiyun {
366*4882a593Smuzhiyun 	if (!udp_tunnel_nic_ops)
367*4882a593Smuzhiyun 		return 0;
368*4882a593Smuzhiyun 	return udp_tunnel_nic_ops->dump_write(dev, table, skb);
369*4882a593Smuzhiyun }
370*4882a593Smuzhiyun #endif
371