xref: /openbmc/linux/include/net/udp_tunnel.h (revision b97d6790d03b763eca08847a9a5869a4291b9f9a)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
28024e028STom Herbert #ifndef __NET_UDP_TUNNEL_H
38024e028STom Herbert #define __NET_UDP_TUNNEL_H
48024e028STom Herbert 
56a93cc90SAndy Zhou #include <net/ip_tunnels.h>
66a93cc90SAndy Zhou #include <net/udp.h>
76a93cc90SAndy Zhou 
86a93cc90SAndy Zhou #if IS_ENABLED(CONFIG_IPV6)
96a93cc90SAndy Zhou #include <net/ipv6.h>
103616d08bSDavid Ahern #include <net/ipv6_stubs.h>
116a93cc90SAndy Zhou #endif
126a93cc90SAndy Zhou 
138024e028STom Herbert struct udp_port_cfg {
148024e028STom Herbert 	u8			family;
158024e028STom Herbert 
168024e028STom Herbert 	/* Used only for kernel-created sockets */
178024e028STom Herbert 	union {
188024e028STom Herbert 		struct in_addr		local_ip;
198024e028STom Herbert #if IS_ENABLED(CONFIG_IPV6)
208024e028STom Herbert 		struct in6_addr		local_ip6;
218024e028STom Herbert #endif
228024e028STom Herbert 	};
238024e028STom Herbert 
248024e028STom Herbert 	union {
258024e028STom Herbert 		struct in_addr		peer_ip;
268024e028STom Herbert #if IS_ENABLED(CONFIG_IPV6)
278024e028STom Herbert 		struct in6_addr		peer_ip6;
288024e028STom Herbert #endif
298024e028STom Herbert 	};
308024e028STom Herbert 
318024e028STom Herbert 	__be16			local_udp_port;
328024e028STom Herbert 	__be16			peer_udp_port;
33da5095d0SAlexis Bauvin 	int			bind_ifindex;
348024e028STom Herbert 	unsigned int		use_udp_checksums:1,
358024e028STom Herbert 				use_udp6_tx_checksums:1,
36a43a9ef6SJiri Benc 				use_udp6_rx_checksums:1,
37a43a9ef6SJiri Benc 				ipv6_v6only:1;
388024e028STom Herbert };
398024e028STom Herbert 
40fd384412SAndy Zhou int udp_sock_create4(struct net *net, struct udp_port_cfg *cfg,
418024e028STom Herbert 		     struct socket **sockp);
428024e028STom Herbert 
43fd384412SAndy Zhou #if IS_ENABLED(CONFIG_IPV6)
44fd384412SAndy Zhou int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
45fd384412SAndy Zhou 		     struct socket **sockp);
46fd384412SAndy Zhou #else
udp_sock_create6(struct net * net,struct udp_port_cfg * cfg,struct socket ** sockp)47fd384412SAndy Zhou static inline int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
48fd384412SAndy Zhou 				   struct socket **sockp)
49fd384412SAndy Zhou {
50fd384412SAndy Zhou 	return 0;
51fd384412SAndy Zhou }
52fd384412SAndy Zhou #endif
53fd384412SAndy Zhou 
udp_sock_create(struct net * net,struct udp_port_cfg * cfg,struct socket ** sockp)54fd384412SAndy Zhou static inline int udp_sock_create(struct net *net,
55fd384412SAndy Zhou 				  struct udp_port_cfg *cfg,
56fd384412SAndy Zhou 				  struct socket **sockp)
57fd384412SAndy Zhou {
58fd384412SAndy Zhou 	if (cfg->family == AF_INET)
59fd384412SAndy Zhou 		return udp_sock_create4(net, cfg, sockp);
60fd384412SAndy Zhou 
61fd384412SAndy Zhou 	if (cfg->family == AF_INET6)
62fd384412SAndy Zhou 		return udp_sock_create6(net, cfg, sockp);
63fd384412SAndy Zhou 
64fd384412SAndy Zhou 	return -EPFNOSUPPORT;
65fd384412SAndy Zhou }
66fd384412SAndy Zhou 
676a93cc90SAndy Zhou typedef int (*udp_tunnel_encap_rcv_t)(struct sock *sk, struct sk_buff *skb);
68a36e185eSStefano Brivio typedef int (*udp_tunnel_encap_err_lookup_t)(struct sock *sk,
69a36e185eSStefano Brivio 					     struct sk_buff *skb);
70ac56a0b4SDavid Howells typedef void (*udp_tunnel_encap_err_rcv_t)(struct sock *sk,
7142fb06b3SDavid Howells 					   struct sk_buff *skb, int err,
7242fb06b3SDavid Howells 					   __be16 port, u32 info, u8 *payload);
736a93cc90SAndy Zhou typedef void (*udp_tunnel_encap_destroy_t)(struct sock *sk);
74d4546c25SDavid Miller typedef struct sk_buff *(*udp_tunnel_gro_receive_t)(struct sock *sk,
75d4546c25SDavid Miller 						    struct list_head *head,
7638fd2af2STom Herbert 						    struct sk_buff *skb);
7738fd2af2STom Herbert typedef int (*udp_tunnel_gro_complete_t)(struct sock *sk, struct sk_buff *skb,
7838fd2af2STom Herbert 					 int nhoff);
796a93cc90SAndy Zhou 
806a93cc90SAndy Zhou struct udp_tunnel_sock_cfg {
816a93cc90SAndy Zhou 	void *sk_user_data;     /* user data used by encap_rcv call back */
826a93cc90SAndy Zhou 	/* Used for setting up udp_sock fields, see udp.h for details */
836a93cc90SAndy Zhou 	__u8  encap_type;
846a93cc90SAndy Zhou 	udp_tunnel_encap_rcv_t encap_rcv;
85a36e185eSStefano Brivio 	udp_tunnel_encap_err_lookup_t encap_err_lookup;
86ac56a0b4SDavid Howells 	udp_tunnel_encap_err_rcv_t encap_err_rcv;
876a93cc90SAndy Zhou 	udp_tunnel_encap_destroy_t encap_destroy;
8838fd2af2STom Herbert 	udp_tunnel_gro_receive_t gro_receive;
8938fd2af2STom Herbert 	udp_tunnel_gro_complete_t gro_complete;
906a93cc90SAndy Zhou };
916a93cc90SAndy Zhou 
926a93cc90SAndy Zhou /* Setup the given (UDP) sock to receive UDP encapsulated packets */
936a93cc90SAndy Zhou void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
946a93cc90SAndy Zhou 			   struct udp_tunnel_sock_cfg *sock_cfg);
956a93cc90SAndy Zhou 
96e7b3db5eSAlexander Duyck /* -- List of parsable UDP tunnel types --
97e7b3db5eSAlexander Duyck  *
98e7b3db5eSAlexander Duyck  * Adding to this list will result in serious debate.  The main issue is
99e7b3db5eSAlexander Duyck  * that this list is essentially a list of workarounds for either poorly
100e7b3db5eSAlexander Duyck  * designed tunnels, or poorly designed device offloads.
101e7b3db5eSAlexander Duyck  *
102e7b3db5eSAlexander Duyck  * The parsing supported via these types should really be used for Rx
103e7b3db5eSAlexander Duyck  * traffic only as the network stack will have already inserted offsets for
104e7b3db5eSAlexander Duyck  * the location of the headers in the skb.  In addition any ports that are
105e7b3db5eSAlexander Duyck  * pushed should be kept within the namespace without leaking to other
106e7b3db5eSAlexander Duyck  * devices such as VFs or other ports on the same device.
107e7b3db5eSAlexander Duyck  *
108e7b3db5eSAlexander Duyck  * It is strongly encouraged to use CHECKSUM_COMPLETE for Rx to avoid the
109e7b3db5eSAlexander Duyck  * need to use this for Rx checksum offload.  It should not be necessary to
110e7b3db5eSAlexander Duyck  * call this function to perform Tx offloads on outgoing traffic.
111e7b3db5eSAlexander Duyck  */
112e7b3db5eSAlexander Duyck enum udp_parsable_tunnel_type {
11384a4160eSJakub Kicinski 	UDP_TUNNEL_TYPE_VXLAN	  = BIT(0), /* RFC 7348 */
11484a4160eSJakub Kicinski 	UDP_TUNNEL_TYPE_GENEVE	  = BIT(1), /* draft-ietf-nvo3-geneve */
11584a4160eSJakub Kicinski 	UDP_TUNNEL_TYPE_VXLAN_GPE = BIT(2), /* draft-ietf-nvo3-vxlan-gpe */
116e7b3db5eSAlexander Duyck };
117e7b3db5eSAlexander Duyck 
118e7b3db5eSAlexander Duyck struct udp_tunnel_info {
119e7b3db5eSAlexander Duyck 	unsigned short type;
120e7b3db5eSAlexander Duyck 	sa_family_t sa_family;
121e7b3db5eSAlexander Duyck 	__be16 port;
122cc4e3835SJakub Kicinski 	u8 hw_priv;
123e7b3db5eSAlexander Duyck };
124e7b3db5eSAlexander Duyck 
125e7b3db5eSAlexander Duyck /* Notify network devices of offloadable types */
126e7b3db5eSAlexander Duyck void udp_tunnel_push_rx_port(struct net_device *dev, struct socket *sock,
127e7b3db5eSAlexander Duyck 			     unsigned short type);
128296d8ee3SSabrina Dubroca void udp_tunnel_drop_rx_port(struct net_device *dev, struct socket *sock,
129296d8ee3SSabrina Dubroca 			     unsigned short type);
130e7b3db5eSAlexander Duyck void udp_tunnel_notify_add_rx_port(struct socket *sock, unsigned short type);
131e7b3db5eSAlexander Duyck void udp_tunnel_notify_del_rx_port(struct socket *sock, unsigned short type);
132e7b3db5eSAlexander Duyck 
udp_tunnel_get_rx_info(struct net_device * dev)1337c46a640SAlexander Duyck static inline void udp_tunnel_get_rx_info(struct net_device *dev)
1347c46a640SAlexander Duyck {
1357c46a640SAlexander Duyck 	ASSERT_RTNL();
136b9ef3fecSJakub Kicinski 	if (!(dev->features & NETIF_F_RX_UDP_TUNNEL_PORT))
137b9ef3fecSJakub Kicinski 		return;
1387c46a640SAlexander Duyck 	call_netdevice_notifiers(NETDEV_UDP_TUNNEL_PUSH_INFO, dev);
1397c46a640SAlexander Duyck }
1407c46a640SAlexander Duyck 
udp_tunnel_drop_rx_info(struct net_device * dev)141296d8ee3SSabrina Dubroca static inline void udp_tunnel_drop_rx_info(struct net_device *dev)
142296d8ee3SSabrina Dubroca {
143296d8ee3SSabrina Dubroca 	ASSERT_RTNL();
144b9ef3fecSJakub Kicinski 	if (!(dev->features & NETIF_F_RX_UDP_TUNNEL_PORT))
145b9ef3fecSJakub Kicinski 		return;
146296d8ee3SSabrina Dubroca 	call_netdevice_notifiers(NETDEV_UDP_TUNNEL_DROP_INFO, dev);
147296d8ee3SSabrina Dubroca }
148296d8ee3SSabrina Dubroca 
1496a93cc90SAndy Zhou /* Transmit the skb using UDP encapsulation. */
150039f5062SPravin B Shelar void udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
151d998f8efSTom Herbert 			 __be32 src, __be32 dst, __u8 tos, __u8 ttl,
152d998f8efSTom Herbert 			 __be16 df, __be16 src_port, __be16 dst_port,
153d998f8efSTom Herbert 			 bool xnet, bool nocheck);
1546a93cc90SAndy Zhou 
15579b16aadSDavid Miller int udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk,
15679b16aadSDavid Miller 			 struct sk_buff *skb,
157d998f8efSTom Herbert 			 struct net_device *dev, struct in6_addr *saddr,
158d998f8efSTom Herbert 			 struct in6_addr *daddr,
15913461144SDaniel Borkmann 			 __u8 prio, __u8 ttl, __be32 label,
16013461144SDaniel Borkmann 			 __be16 src_port, __be16 dst_port, bool nocheck);
1616a93cc90SAndy Zhou 
1626a93cc90SAndy Zhou void udp_tunnel_sock_release(struct socket *sock);
1636a93cc90SAndy Zhou 
164c29a70d2SPravin B Shelar struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family,
165c29a70d2SPravin B Shelar 				    __be16 flags, __be64 tunnel_id,
166c29a70d2SPravin B Shelar 				    int md_size);
167c29a70d2SPravin B Shelar 
16886a98057SAlexander Duyck #ifdef CONFIG_INET
udp_tunnel_handle_offloads(struct sk_buff * skb,bool udp_csum)169aed069dfSAlexander Duyck static inline int udp_tunnel_handle_offloads(struct sk_buff *skb, bool udp_csum)
1706a93cc90SAndy Zhou {
1716a93cc90SAndy Zhou 	int type = udp_csum ? SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL;
1726a93cc90SAndy Zhou 
1736fa79666SEdward Cree 	return iptunnel_handle_offloads(skb, type);
1746a93cc90SAndy Zhou }
17586a98057SAlexander Duyck #endif
1766a93cc90SAndy Zhou 
udp_tunnel_encap_enable(struct sock * sk)177*f1f1f5ccSEric Dumazet static inline void udp_tunnel_encap_enable(struct sock *sk)
1786a93cc90SAndy Zhou {
179*f1f1f5ccSEric Dumazet 	if (udp_test_and_set_bit(ENCAP_ENABLED, sk))
18060fb9567SPaolo Abeni 		return;
18160fb9567SPaolo Abeni 
1826a93cc90SAndy Zhou #if IS_ENABLED(CONFIG_IPV6)
183*f1f1f5ccSEric Dumazet 	if (READ_ONCE(sk->sk_family) == PF_INET6)
1846a93cc90SAndy Zhou 		ipv6_stub->udpv6_encap_enable();
1856a93cc90SAndy Zhou #endif
1866a93cc90SAndy Zhou 	udp_encap_enable();
1876a93cc90SAndy Zhou }
1886a93cc90SAndy Zhou 
189cc4e3835SJakub Kicinski #define UDP_TUNNEL_NIC_MAX_TABLES	4
190cc4e3835SJakub Kicinski 
191cc4e3835SJakub Kicinski enum udp_tunnel_nic_info_flags {
192cc4e3835SJakub Kicinski 	/* Device callbacks may sleep */
193cc4e3835SJakub Kicinski 	UDP_TUNNEL_NIC_INFO_MAY_SLEEP	= BIT(0),
194cc4e3835SJakub Kicinski 	/* Device only supports offloads when it's open, all ports
195cc4e3835SJakub Kicinski 	 * will be removed before close and re-added after open.
196cc4e3835SJakub Kicinski 	 */
197cc4e3835SJakub Kicinski 	UDP_TUNNEL_NIC_INFO_OPEN_ONLY	= BIT(1),
198cc4e3835SJakub Kicinski 	/* Device supports only IPv4 tunnels */
199cc4e3835SJakub Kicinski 	UDP_TUNNEL_NIC_INFO_IPV4_ONLY	= BIT(2),
200966e5059SJakub Kicinski 	/* Device has hard-coded the IANA VXLAN port (4789) as VXLAN.
201966e5059SJakub Kicinski 	 * This port must not be counted towards n_entries of any table.
202966e5059SJakub Kicinski 	 * Driver will not receive any callback associated with port 4789.
203966e5059SJakub Kicinski 	 */
204966e5059SJakub Kicinski 	UDP_TUNNEL_NIC_INFO_STATIC_IANA_VXLAN	= BIT(3),
205cc4e3835SJakub Kicinski };
206cc4e3835SJakub Kicinski 
20774cc6d18SJakub Kicinski struct udp_tunnel_nic;
20874cc6d18SJakub Kicinski 
20974cc6d18SJakub Kicinski #define UDP_TUNNEL_NIC_MAX_SHARING_DEVICES	(U16_MAX / 2)
21074cc6d18SJakub Kicinski 
21174cc6d18SJakub Kicinski struct udp_tunnel_nic_shared {
21274cc6d18SJakub Kicinski 	struct udp_tunnel_nic *udp_tunnel_nic_info;
21374cc6d18SJakub Kicinski 
21474cc6d18SJakub Kicinski 	struct list_head devices;
21574cc6d18SJakub Kicinski };
21674cc6d18SJakub Kicinski 
21774cc6d18SJakub Kicinski struct udp_tunnel_nic_shared_node {
21874cc6d18SJakub Kicinski 	struct net_device *dev;
21974cc6d18SJakub Kicinski 	struct list_head list;
22074cc6d18SJakub Kicinski };
22174cc6d18SJakub Kicinski 
222cc4e3835SJakub Kicinski /**
223cc4e3835SJakub Kicinski  * struct udp_tunnel_nic_info - driver UDP tunnel offload information
224cc4e3835SJakub Kicinski  * @set_port:	callback for adding a new port
225cc4e3835SJakub Kicinski  * @unset_port:	callback for removing a port
226cc4e3835SJakub Kicinski  * @sync_table:	callback for syncing the entire port table at once
22774cc6d18SJakub Kicinski  * @shared:	reference to device global state (optional)
228cc4e3835SJakub Kicinski  * @flags:	device flags from enum udp_tunnel_nic_info_flags
229cc4e3835SJakub Kicinski  * @tables:	UDP port tables this device has
230cc4e3835SJakub Kicinski  * @tables.n_entries:		number of entries in this table
231cc4e3835SJakub Kicinski  * @tables.tunnel_types:	types of tunnels this table accepts
232cc4e3835SJakub Kicinski  *
233cc4e3835SJakub Kicinski  * Drivers are expected to provide either @set_port and @unset_port callbacks
234cc4e3835SJakub Kicinski  * or the @sync_table callback. Callbacks are invoked with rtnl lock held.
235cc4e3835SJakub Kicinski  *
23674cc6d18SJakub Kicinski  * Devices which (misguidedly) share the UDP tunnel port table across multiple
23774cc6d18SJakub Kicinski  * netdevs should allocate an instance of struct udp_tunnel_nic_shared and
23874cc6d18SJakub Kicinski  * point @shared at it.
23974cc6d18SJakub Kicinski  * There must never be more than %UDP_TUNNEL_NIC_MAX_SHARING_DEVICES devices
24074cc6d18SJakub Kicinski  * sharing a table.
24174cc6d18SJakub Kicinski  *
242cc4e3835SJakub Kicinski  * Known limitations:
243cc4e3835SJakub Kicinski  *  - UDP tunnel port notifications are fundamentally best-effort -
244cc4e3835SJakub Kicinski  *    it is likely the driver will both see skbs which use a UDP tunnel port,
245cc4e3835SJakub Kicinski  *    while not being a tunneled skb, and tunnel skbs from other ports -
246cc4e3835SJakub Kicinski  *    drivers should only use these ports for non-critical RX-side offloads,
247cc4e3835SJakub Kicinski  *    e.g. the checksum offload;
248cc4e3835SJakub Kicinski  *  - none of the devices care about the socket family at present, so we don't
249cc4e3835SJakub Kicinski  *    track it. Please extend this code if you care.
250cc4e3835SJakub Kicinski  */
251cc4e3835SJakub Kicinski struct udp_tunnel_nic_info {
252cc4e3835SJakub Kicinski 	/* one-by-one */
253cc4e3835SJakub Kicinski 	int (*set_port)(struct net_device *dev,
254cc4e3835SJakub Kicinski 			unsigned int table, unsigned int entry,
255cc4e3835SJakub Kicinski 			struct udp_tunnel_info *ti);
256cc4e3835SJakub Kicinski 	int (*unset_port)(struct net_device *dev,
257cc4e3835SJakub Kicinski 			  unsigned int table, unsigned int entry,
258cc4e3835SJakub Kicinski 			  struct udp_tunnel_info *ti);
259cc4e3835SJakub Kicinski 
260cc4e3835SJakub Kicinski 	/* all at once */
261cc4e3835SJakub Kicinski 	int (*sync_table)(struct net_device *dev, unsigned int table);
262cc4e3835SJakub Kicinski 
26374cc6d18SJakub Kicinski 	struct udp_tunnel_nic_shared *shared;
26474cc6d18SJakub Kicinski 
265cc4e3835SJakub Kicinski 	unsigned int flags;
266cc4e3835SJakub Kicinski 
267cc4e3835SJakub Kicinski 	struct udp_tunnel_nic_table_info {
268cc4e3835SJakub Kicinski 		unsigned int n_entries;
269cc4e3835SJakub Kicinski 		unsigned int tunnel_types;
270cc4e3835SJakub Kicinski 	} tables[UDP_TUNNEL_NIC_MAX_TABLES];
271cc4e3835SJakub Kicinski };
272cc4e3835SJakub Kicinski 
273cc4e3835SJakub Kicinski /* UDP tunnel module dependencies
274cc4e3835SJakub Kicinski  *
275cc4e3835SJakub Kicinski  * Tunnel drivers are expected to have a hard dependency on the udp_tunnel
276cc4e3835SJakub Kicinski  * module. NIC drivers are not, they just attach their
277cc4e3835SJakub Kicinski  * struct udp_tunnel_nic_info to the netdev and wait for callbacks to come.
278cc4e3835SJakub Kicinski  * Loading a tunnel driver will cause the udp_tunnel module to be loaded
279cc4e3835SJakub Kicinski  * and only then will all the required state structures be allocated.
280cc4e3835SJakub Kicinski  * Since we want a weak dependency from the drivers and the core to udp_tunnel
281cc4e3835SJakub Kicinski  * we call things through the following stubs.
282cc4e3835SJakub Kicinski  */
283cc4e3835SJakub Kicinski struct udp_tunnel_nic_ops {
284cc4e3835SJakub Kicinski 	void (*get_port)(struct net_device *dev, unsigned int table,
285cc4e3835SJakub Kicinski 			 unsigned int idx, struct udp_tunnel_info *ti);
286cc4e3835SJakub Kicinski 	void (*set_port_priv)(struct net_device *dev, unsigned int table,
287cc4e3835SJakub Kicinski 			      unsigned int idx, u8 priv);
288cc4e3835SJakub Kicinski 	void (*add_port)(struct net_device *dev, struct udp_tunnel_info *ti);
289cc4e3835SJakub Kicinski 	void (*del_port)(struct net_device *dev, struct udp_tunnel_info *ti);
290cc4e3835SJakub Kicinski 	void (*reset_ntf)(struct net_device *dev);
291c7d759ebSJakub Kicinski 
292c7d759ebSJakub Kicinski 	size_t (*dump_size)(struct net_device *dev, unsigned int table);
293c7d759ebSJakub Kicinski 	int (*dump_write)(struct net_device *dev, unsigned int table,
294c7d759ebSJakub Kicinski 			  struct sk_buff *skb);
295cc4e3835SJakub Kicinski };
296cc4e3835SJakub Kicinski 
297cc4e3835SJakub Kicinski #ifdef CONFIG_INET
298cc4e3835SJakub Kicinski extern const struct udp_tunnel_nic_ops *udp_tunnel_nic_ops;
299cc4e3835SJakub Kicinski #else
300cc4e3835SJakub Kicinski #define udp_tunnel_nic_ops	((struct udp_tunnel_nic_ops *)NULL)
301cc4e3835SJakub Kicinski #endif
302cc4e3835SJakub Kicinski 
303cc4e3835SJakub Kicinski static inline void
udp_tunnel_nic_get_port(struct net_device * dev,unsigned int table,unsigned int idx,struct udp_tunnel_info * ti)304cc4e3835SJakub Kicinski udp_tunnel_nic_get_port(struct net_device *dev, unsigned int table,
305cc4e3835SJakub Kicinski 			unsigned int idx, struct udp_tunnel_info *ti)
306cc4e3835SJakub Kicinski {
307cc4e3835SJakub Kicinski 	/* This helper is used from .sync_table, we indicate empty entries
308cc4e3835SJakub Kicinski 	 * by zero'ed @ti. Drivers which need to know the details of a port
309cc4e3835SJakub Kicinski 	 * when it gets deleted should use the .set_port / .unset_port
310cc4e3835SJakub Kicinski 	 * callbacks.
311cc4e3835SJakub Kicinski 	 * Zero out here, otherwise !CONFIG_INET causes uninitilized warnings.
312cc4e3835SJakub Kicinski 	 */
313cc4e3835SJakub Kicinski 	memset(ti, 0, sizeof(*ti));
314cc4e3835SJakub Kicinski 
315cc4e3835SJakub Kicinski 	if (udp_tunnel_nic_ops)
316cc4e3835SJakub Kicinski 		udp_tunnel_nic_ops->get_port(dev, table, idx, ti);
317cc4e3835SJakub Kicinski }
318cc4e3835SJakub Kicinski 
319cc4e3835SJakub Kicinski static inline void
udp_tunnel_nic_set_port_priv(struct net_device * dev,unsigned int table,unsigned int idx,u8 priv)320cc4e3835SJakub Kicinski udp_tunnel_nic_set_port_priv(struct net_device *dev, unsigned int table,
321cc4e3835SJakub Kicinski 			     unsigned int idx, u8 priv)
322cc4e3835SJakub Kicinski {
323cc4e3835SJakub Kicinski 	if (udp_tunnel_nic_ops)
324cc4e3835SJakub Kicinski 		udp_tunnel_nic_ops->set_port_priv(dev, table, idx, priv);
325cc4e3835SJakub Kicinski }
326cc4e3835SJakub Kicinski 
327cc4e3835SJakub Kicinski static inline void
udp_tunnel_nic_add_port(struct net_device * dev,struct udp_tunnel_info * ti)328cc4e3835SJakub Kicinski udp_tunnel_nic_add_port(struct net_device *dev, struct udp_tunnel_info *ti)
329cc4e3835SJakub Kicinski {
330b9ef3fecSJakub Kicinski 	if (!(dev->features & NETIF_F_RX_UDP_TUNNEL_PORT))
331b9ef3fecSJakub Kicinski 		return;
332cc4e3835SJakub Kicinski 	if (udp_tunnel_nic_ops)
333cc4e3835SJakub Kicinski 		udp_tunnel_nic_ops->add_port(dev, ti);
334cc4e3835SJakub Kicinski }
335cc4e3835SJakub Kicinski 
336cc4e3835SJakub Kicinski static inline void
udp_tunnel_nic_del_port(struct net_device * dev,struct udp_tunnel_info * ti)337cc4e3835SJakub Kicinski udp_tunnel_nic_del_port(struct net_device *dev, struct udp_tunnel_info *ti)
338cc4e3835SJakub Kicinski {
339b9ef3fecSJakub Kicinski 	if (!(dev->features & NETIF_F_RX_UDP_TUNNEL_PORT))
340b9ef3fecSJakub Kicinski 		return;
341cc4e3835SJakub Kicinski 	if (udp_tunnel_nic_ops)
342cc4e3835SJakub Kicinski 		udp_tunnel_nic_ops->del_port(dev, ti);
343cc4e3835SJakub Kicinski }
344cc4e3835SJakub Kicinski 
345cc4e3835SJakub Kicinski /**
346cc4e3835SJakub Kicinski  * udp_tunnel_nic_reset_ntf() - device-originating reset notification
347cc4e3835SJakub Kicinski  * @dev: network interface device structure
348cc4e3835SJakub Kicinski  *
349cc4e3835SJakub Kicinski  * Called by the driver to inform the core that the entire UDP tunnel port
350cc4e3835SJakub Kicinski  * state has been lost, usually due to device reset. Core will assume device
351cc4e3835SJakub Kicinski  * forgot all the ports and issue .set_port and .sync_table callbacks as
352cc4e3835SJakub Kicinski  * necessary.
353cc4e3835SJakub Kicinski  *
354cc4e3835SJakub Kicinski  * This function must be called with rtnl lock held, and will issue all
355cc4e3835SJakub Kicinski  * the callbacks before returning.
356cc4e3835SJakub Kicinski  */
udp_tunnel_nic_reset_ntf(struct net_device * dev)357cc4e3835SJakub Kicinski static inline void udp_tunnel_nic_reset_ntf(struct net_device *dev)
358cc4e3835SJakub Kicinski {
359cc4e3835SJakub Kicinski 	if (udp_tunnel_nic_ops)
360cc4e3835SJakub Kicinski 		udp_tunnel_nic_ops->reset_ntf(dev);
361cc4e3835SJakub Kicinski }
362c7d759ebSJakub Kicinski 
363c7d759ebSJakub Kicinski static inline size_t
udp_tunnel_nic_dump_size(struct net_device * dev,unsigned int table)364c7d759ebSJakub Kicinski udp_tunnel_nic_dump_size(struct net_device *dev, unsigned int table)
365c7d759ebSJakub Kicinski {
366c7d759ebSJakub Kicinski 	if (!udp_tunnel_nic_ops)
367c7d759ebSJakub Kicinski 		return 0;
368c7d759ebSJakub Kicinski 	return udp_tunnel_nic_ops->dump_size(dev, table);
369c7d759ebSJakub Kicinski }
370c7d759ebSJakub Kicinski 
371c7d759ebSJakub Kicinski static inline int
udp_tunnel_nic_dump_write(struct net_device * dev,unsigned int table,struct sk_buff * skb)372c7d759ebSJakub Kicinski udp_tunnel_nic_dump_write(struct net_device *dev, unsigned int table,
373c7d759ebSJakub Kicinski 			  struct sk_buff *skb)
374c7d759ebSJakub Kicinski {
375c7d759ebSJakub Kicinski 	if (!udp_tunnel_nic_ops)
376c7d759ebSJakub Kicinski 		return 0;
377c7d759ebSJakub Kicinski 	return udp_tunnel_nic_ops->dump_write(dev, table, skb);
378c7d759ebSJakub Kicinski }
3798024e028STom Herbert #endif
380