18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __NET_UDP_TUNNEL_H 38c2ecf20Sopenharmony_ci#define __NET_UDP_TUNNEL_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <net/ip_tunnels.h> 68c2ecf20Sopenharmony_ci#include <net/udp.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 98c2ecf20Sopenharmony_ci#include <net/ipv6.h> 108c2ecf20Sopenharmony_ci#include <net/ipv6_stubs.h> 118c2ecf20Sopenharmony_ci#endif 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistruct udp_port_cfg { 148c2ecf20Sopenharmony_ci u8 family; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci /* Used only for kernel-created sockets */ 178c2ecf20Sopenharmony_ci union { 188c2ecf20Sopenharmony_ci struct in_addr local_ip; 198c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 208c2ecf20Sopenharmony_ci struct in6_addr local_ip6; 218c2ecf20Sopenharmony_ci#endif 228c2ecf20Sopenharmony_ci }; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci union { 258c2ecf20Sopenharmony_ci struct in_addr peer_ip; 268c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 278c2ecf20Sopenharmony_ci struct in6_addr peer_ip6; 288c2ecf20Sopenharmony_ci#endif 298c2ecf20Sopenharmony_ci }; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci __be16 local_udp_port; 328c2ecf20Sopenharmony_ci __be16 peer_udp_port; 338c2ecf20Sopenharmony_ci int bind_ifindex; 348c2ecf20Sopenharmony_ci unsigned int use_udp_checksums:1, 358c2ecf20Sopenharmony_ci use_udp6_tx_checksums:1, 368c2ecf20Sopenharmony_ci use_udp6_rx_checksums:1, 378c2ecf20Sopenharmony_ci ipv6_v6only:1; 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciint udp_sock_create4(struct net *net, struct udp_port_cfg *cfg, 418c2ecf20Sopenharmony_ci struct socket **sockp); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 448c2ecf20Sopenharmony_ciint udp_sock_create6(struct net *net, struct udp_port_cfg *cfg, 458c2ecf20Sopenharmony_ci struct socket **sockp); 468c2ecf20Sopenharmony_ci#else 478c2ecf20Sopenharmony_cistatic inline int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg, 488c2ecf20Sopenharmony_ci struct socket **sockp) 498c2ecf20Sopenharmony_ci{ 508c2ecf20Sopenharmony_ci return 0; 518c2ecf20Sopenharmony_ci} 528c2ecf20Sopenharmony_ci#endif 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic inline int udp_sock_create(struct net *net, 558c2ecf20Sopenharmony_ci struct udp_port_cfg *cfg, 568c2ecf20Sopenharmony_ci struct socket **sockp) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci if (cfg->family == AF_INET) 598c2ecf20Sopenharmony_ci return udp_sock_create4(net, cfg, sockp); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci if (cfg->family == AF_INET6) 628c2ecf20Sopenharmony_ci return udp_sock_create6(net, cfg, sockp); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci return -EPFNOSUPPORT; 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_citypedef int (*udp_tunnel_encap_rcv_t)(struct sock *sk, struct sk_buff *skb); 688c2ecf20Sopenharmony_citypedef int (*udp_tunnel_encap_err_lookup_t)(struct sock *sk, 698c2ecf20Sopenharmony_ci struct sk_buff *skb); 708c2ecf20Sopenharmony_citypedef void (*udp_tunnel_encap_destroy_t)(struct sock *sk); 718c2ecf20Sopenharmony_citypedef struct sk_buff *(*udp_tunnel_gro_receive_t)(struct sock *sk, 728c2ecf20Sopenharmony_ci struct list_head *head, 738c2ecf20Sopenharmony_ci struct sk_buff *skb); 748c2ecf20Sopenharmony_citypedef int (*udp_tunnel_gro_complete_t)(struct sock *sk, struct sk_buff *skb, 758c2ecf20Sopenharmony_ci int nhoff); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistruct udp_tunnel_sock_cfg { 788c2ecf20Sopenharmony_ci void *sk_user_data; /* user data used by encap_rcv call back */ 798c2ecf20Sopenharmony_ci /* Used for setting up udp_sock fields, see udp.h for details */ 808c2ecf20Sopenharmony_ci __u8 encap_type; 818c2ecf20Sopenharmony_ci udp_tunnel_encap_rcv_t encap_rcv; 828c2ecf20Sopenharmony_ci udp_tunnel_encap_err_lookup_t encap_err_lookup; 838c2ecf20Sopenharmony_ci udp_tunnel_encap_destroy_t encap_destroy; 848c2ecf20Sopenharmony_ci udp_tunnel_gro_receive_t gro_receive; 858c2ecf20Sopenharmony_ci udp_tunnel_gro_complete_t gro_complete; 868c2ecf20Sopenharmony_ci}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* Setup the given (UDP) sock to receive UDP encapsulated packets */ 898c2ecf20Sopenharmony_civoid setup_udp_tunnel_sock(struct net *net, struct socket *sock, 908c2ecf20Sopenharmony_ci struct udp_tunnel_sock_cfg *sock_cfg); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* -- List of parsable UDP tunnel types -- 938c2ecf20Sopenharmony_ci * 948c2ecf20Sopenharmony_ci * Adding to this list will result in serious debate. The main issue is 958c2ecf20Sopenharmony_ci * that this list is essentially a list of workarounds for either poorly 968c2ecf20Sopenharmony_ci * designed tunnels, or poorly designed device offloads. 978c2ecf20Sopenharmony_ci * 988c2ecf20Sopenharmony_ci * The parsing supported via these types should really be used for Rx 998c2ecf20Sopenharmony_ci * traffic only as the network stack will have already inserted offsets for 1008c2ecf20Sopenharmony_ci * the location of the headers in the skb. In addition any ports that are 1018c2ecf20Sopenharmony_ci * pushed should be kept within the namespace without leaking to other 1028c2ecf20Sopenharmony_ci * devices such as VFs or other ports on the same device. 1038c2ecf20Sopenharmony_ci * 1048c2ecf20Sopenharmony_ci * It is strongly encouraged to use CHECKSUM_COMPLETE for Rx to avoid the 1058c2ecf20Sopenharmony_ci * need to use this for Rx checksum offload. It should not be necessary to 1068c2ecf20Sopenharmony_ci * call this function to perform Tx offloads on outgoing traffic. 1078c2ecf20Sopenharmony_ci */ 1088c2ecf20Sopenharmony_cienum udp_parsable_tunnel_type { 1098c2ecf20Sopenharmony_ci UDP_TUNNEL_TYPE_VXLAN = BIT(0), /* RFC 7348 */ 1108c2ecf20Sopenharmony_ci UDP_TUNNEL_TYPE_GENEVE = BIT(1), /* draft-ietf-nvo3-geneve */ 1118c2ecf20Sopenharmony_ci UDP_TUNNEL_TYPE_VXLAN_GPE = BIT(2), /* draft-ietf-nvo3-vxlan-gpe */ 1128c2ecf20Sopenharmony_ci}; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistruct udp_tunnel_info { 1158c2ecf20Sopenharmony_ci unsigned short type; 1168c2ecf20Sopenharmony_ci sa_family_t sa_family; 1178c2ecf20Sopenharmony_ci __be16 port; 1188c2ecf20Sopenharmony_ci u8 hw_priv; 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* Notify network devices of offloadable types */ 1228c2ecf20Sopenharmony_civoid udp_tunnel_push_rx_port(struct net_device *dev, struct socket *sock, 1238c2ecf20Sopenharmony_ci unsigned short type); 1248c2ecf20Sopenharmony_civoid udp_tunnel_drop_rx_port(struct net_device *dev, struct socket *sock, 1258c2ecf20Sopenharmony_ci unsigned short type); 1268c2ecf20Sopenharmony_civoid udp_tunnel_notify_add_rx_port(struct socket *sock, unsigned short type); 1278c2ecf20Sopenharmony_civoid udp_tunnel_notify_del_rx_port(struct socket *sock, unsigned short type); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic inline void udp_tunnel_get_rx_info(struct net_device *dev) 1308c2ecf20Sopenharmony_ci{ 1318c2ecf20Sopenharmony_ci ASSERT_RTNL(); 1328c2ecf20Sopenharmony_ci call_netdevice_notifiers(NETDEV_UDP_TUNNEL_PUSH_INFO, dev); 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic inline void udp_tunnel_drop_rx_info(struct net_device *dev) 1368c2ecf20Sopenharmony_ci{ 1378c2ecf20Sopenharmony_ci ASSERT_RTNL(); 1388c2ecf20Sopenharmony_ci call_netdevice_notifiers(NETDEV_UDP_TUNNEL_DROP_INFO, dev); 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci/* Transmit the skb using UDP encapsulation. */ 1428c2ecf20Sopenharmony_civoid udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb, 1438c2ecf20Sopenharmony_ci __be32 src, __be32 dst, __u8 tos, __u8 ttl, 1448c2ecf20Sopenharmony_ci __be16 df, __be16 src_port, __be16 dst_port, 1458c2ecf20Sopenharmony_ci bool xnet, bool nocheck); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ciint udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk, 1488c2ecf20Sopenharmony_ci struct sk_buff *skb, 1498c2ecf20Sopenharmony_ci struct net_device *dev, struct in6_addr *saddr, 1508c2ecf20Sopenharmony_ci struct in6_addr *daddr, 1518c2ecf20Sopenharmony_ci __u8 prio, __u8 ttl, __be32 label, 1528c2ecf20Sopenharmony_ci __be16 src_port, __be16 dst_port, bool nocheck); 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_civoid udp_tunnel_sock_release(struct socket *sock); 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cistruct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, 1578c2ecf20Sopenharmony_ci __be16 flags, __be64 tunnel_id, 1588c2ecf20Sopenharmony_ci int md_size); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci#ifdef CONFIG_INET 1618c2ecf20Sopenharmony_cistatic inline int udp_tunnel_handle_offloads(struct sk_buff *skb, bool udp_csum) 1628c2ecf20Sopenharmony_ci{ 1638c2ecf20Sopenharmony_ci int type = udp_csum ? SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci return iptunnel_handle_offloads(skb, type); 1668c2ecf20Sopenharmony_ci} 1678c2ecf20Sopenharmony_ci#endif 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_cistatic inline void udp_tunnel_encap_enable(struct socket *sock) 1708c2ecf20Sopenharmony_ci{ 1718c2ecf20Sopenharmony_ci struct udp_sock *up = udp_sk(sock->sk); 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci if (up->encap_enabled) 1748c2ecf20Sopenharmony_ci return; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci up->encap_enabled = 1; 1778c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_IPV6) 1788c2ecf20Sopenharmony_ci if (sock->sk->sk_family == PF_INET6) 1798c2ecf20Sopenharmony_ci ipv6_stub->udpv6_encap_enable(); 1808c2ecf20Sopenharmony_ci#endif 1818c2ecf20Sopenharmony_ci udp_encap_enable(); 1828c2ecf20Sopenharmony_ci} 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci#define UDP_TUNNEL_NIC_MAX_TABLES 4 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cienum udp_tunnel_nic_info_flags { 1878c2ecf20Sopenharmony_ci /* Device callbacks may sleep */ 1888c2ecf20Sopenharmony_ci UDP_TUNNEL_NIC_INFO_MAY_SLEEP = BIT(0), 1898c2ecf20Sopenharmony_ci /* Device only supports offloads when it's open, all ports 1908c2ecf20Sopenharmony_ci * will be removed before close and re-added after open. 1918c2ecf20Sopenharmony_ci */ 1928c2ecf20Sopenharmony_ci UDP_TUNNEL_NIC_INFO_OPEN_ONLY = BIT(1), 1938c2ecf20Sopenharmony_ci /* Device supports only IPv4 tunnels */ 1948c2ecf20Sopenharmony_ci UDP_TUNNEL_NIC_INFO_IPV4_ONLY = BIT(2), 1958c2ecf20Sopenharmony_ci /* Device has hard-coded the IANA VXLAN port (4789) as VXLAN. 1968c2ecf20Sopenharmony_ci * This port must not be counted towards n_entries of any table. 1978c2ecf20Sopenharmony_ci * Driver will not receive any callback associated with port 4789. 1988c2ecf20Sopenharmony_ci */ 1998c2ecf20Sopenharmony_ci UDP_TUNNEL_NIC_INFO_STATIC_IANA_VXLAN = BIT(3), 2008c2ecf20Sopenharmony_ci}; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_cistruct udp_tunnel_nic; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci#define UDP_TUNNEL_NIC_MAX_SHARING_DEVICES (U16_MAX / 2) 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_cistruct udp_tunnel_nic_shared { 2078c2ecf20Sopenharmony_ci struct udp_tunnel_nic *udp_tunnel_nic_info; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci struct list_head devices; 2108c2ecf20Sopenharmony_ci}; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_cistruct udp_tunnel_nic_shared_node { 2138c2ecf20Sopenharmony_ci struct net_device *dev; 2148c2ecf20Sopenharmony_ci struct list_head list; 2158c2ecf20Sopenharmony_ci}; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci/** 2188c2ecf20Sopenharmony_ci * struct udp_tunnel_nic_info - driver UDP tunnel offload information 2198c2ecf20Sopenharmony_ci * @set_port: callback for adding a new port 2208c2ecf20Sopenharmony_ci * @unset_port: callback for removing a port 2218c2ecf20Sopenharmony_ci * @sync_table: callback for syncing the entire port table at once 2228c2ecf20Sopenharmony_ci * @shared: reference to device global state (optional) 2238c2ecf20Sopenharmony_ci * @flags: device flags from enum udp_tunnel_nic_info_flags 2248c2ecf20Sopenharmony_ci * @tables: UDP port tables this device has 2258c2ecf20Sopenharmony_ci * @tables.n_entries: number of entries in this table 2268c2ecf20Sopenharmony_ci * @tables.tunnel_types: types of tunnels this table accepts 2278c2ecf20Sopenharmony_ci * 2288c2ecf20Sopenharmony_ci * Drivers are expected to provide either @set_port and @unset_port callbacks 2298c2ecf20Sopenharmony_ci * or the @sync_table callback. Callbacks are invoked with rtnl lock held. 2308c2ecf20Sopenharmony_ci * 2318c2ecf20Sopenharmony_ci * Devices which (misguidedly) share the UDP tunnel port table across multiple 2328c2ecf20Sopenharmony_ci * netdevs should allocate an instance of struct udp_tunnel_nic_shared and 2338c2ecf20Sopenharmony_ci * point @shared at it. 2348c2ecf20Sopenharmony_ci * There must never be more than %UDP_TUNNEL_NIC_MAX_SHARING_DEVICES devices 2358c2ecf20Sopenharmony_ci * sharing a table. 2368c2ecf20Sopenharmony_ci * 2378c2ecf20Sopenharmony_ci * Known limitations: 2388c2ecf20Sopenharmony_ci * - UDP tunnel port notifications are fundamentally best-effort - 2398c2ecf20Sopenharmony_ci * it is likely the driver will both see skbs which use a UDP tunnel port, 2408c2ecf20Sopenharmony_ci * while not being a tunneled skb, and tunnel skbs from other ports - 2418c2ecf20Sopenharmony_ci * drivers should only use these ports for non-critical RX-side offloads, 2428c2ecf20Sopenharmony_ci * e.g. the checksum offload; 2438c2ecf20Sopenharmony_ci * - none of the devices care about the socket family at present, so we don't 2448c2ecf20Sopenharmony_ci * track it. Please extend this code if you care. 2458c2ecf20Sopenharmony_ci */ 2468c2ecf20Sopenharmony_cistruct udp_tunnel_nic_info { 2478c2ecf20Sopenharmony_ci /* one-by-one */ 2488c2ecf20Sopenharmony_ci int (*set_port)(struct net_device *dev, 2498c2ecf20Sopenharmony_ci unsigned int table, unsigned int entry, 2508c2ecf20Sopenharmony_ci struct udp_tunnel_info *ti); 2518c2ecf20Sopenharmony_ci int (*unset_port)(struct net_device *dev, 2528c2ecf20Sopenharmony_ci unsigned int table, unsigned int entry, 2538c2ecf20Sopenharmony_ci struct udp_tunnel_info *ti); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci /* all at once */ 2568c2ecf20Sopenharmony_ci int (*sync_table)(struct net_device *dev, unsigned int table); 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci struct udp_tunnel_nic_shared *shared; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci unsigned int flags; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci struct udp_tunnel_nic_table_info { 2638c2ecf20Sopenharmony_ci unsigned int n_entries; 2648c2ecf20Sopenharmony_ci unsigned int tunnel_types; 2658c2ecf20Sopenharmony_ci } tables[UDP_TUNNEL_NIC_MAX_TABLES]; 2668c2ecf20Sopenharmony_ci}; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci/* UDP tunnel module dependencies 2698c2ecf20Sopenharmony_ci * 2708c2ecf20Sopenharmony_ci * Tunnel drivers are expected to have a hard dependency on the udp_tunnel 2718c2ecf20Sopenharmony_ci * module. NIC drivers are not, they just attach their 2728c2ecf20Sopenharmony_ci * struct udp_tunnel_nic_info to the netdev and wait for callbacks to come. 2738c2ecf20Sopenharmony_ci * Loading a tunnel driver will cause the udp_tunnel module to be loaded 2748c2ecf20Sopenharmony_ci * and only then will all the required state structures be allocated. 2758c2ecf20Sopenharmony_ci * Since we want a weak dependency from the drivers and the core to udp_tunnel 2768c2ecf20Sopenharmony_ci * we call things through the following stubs. 2778c2ecf20Sopenharmony_ci */ 2788c2ecf20Sopenharmony_cistruct udp_tunnel_nic_ops { 2798c2ecf20Sopenharmony_ci void (*get_port)(struct net_device *dev, unsigned int table, 2808c2ecf20Sopenharmony_ci unsigned int idx, struct udp_tunnel_info *ti); 2818c2ecf20Sopenharmony_ci void (*set_port_priv)(struct net_device *dev, unsigned int table, 2828c2ecf20Sopenharmony_ci unsigned int idx, u8 priv); 2838c2ecf20Sopenharmony_ci void (*add_port)(struct net_device *dev, struct udp_tunnel_info *ti); 2848c2ecf20Sopenharmony_ci void (*del_port)(struct net_device *dev, struct udp_tunnel_info *ti); 2858c2ecf20Sopenharmony_ci void (*reset_ntf)(struct net_device *dev); 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci size_t (*dump_size)(struct net_device *dev, unsigned int table); 2888c2ecf20Sopenharmony_ci int (*dump_write)(struct net_device *dev, unsigned int table, 2898c2ecf20Sopenharmony_ci struct sk_buff *skb); 2908c2ecf20Sopenharmony_ci}; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci#ifdef CONFIG_INET 2938c2ecf20Sopenharmony_ciextern const struct udp_tunnel_nic_ops *udp_tunnel_nic_ops; 2948c2ecf20Sopenharmony_ci#else 2958c2ecf20Sopenharmony_ci#define udp_tunnel_nic_ops ((struct udp_tunnel_nic_ops *)NULL) 2968c2ecf20Sopenharmony_ci#endif 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_cistatic inline void 2998c2ecf20Sopenharmony_ciudp_tunnel_nic_get_port(struct net_device *dev, unsigned int table, 3008c2ecf20Sopenharmony_ci unsigned int idx, struct udp_tunnel_info *ti) 3018c2ecf20Sopenharmony_ci{ 3028c2ecf20Sopenharmony_ci /* This helper is used from .sync_table, we indicate empty entries 3038c2ecf20Sopenharmony_ci * by zero'ed @ti. Drivers which need to know the details of a port 3048c2ecf20Sopenharmony_ci * when it gets deleted should use the .set_port / .unset_port 3058c2ecf20Sopenharmony_ci * callbacks. 3068c2ecf20Sopenharmony_ci * Zero out here, otherwise !CONFIG_INET causes uninitilized warnings. 3078c2ecf20Sopenharmony_ci */ 3088c2ecf20Sopenharmony_ci memset(ti, 0, sizeof(*ti)); 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci if (udp_tunnel_nic_ops) 3118c2ecf20Sopenharmony_ci udp_tunnel_nic_ops->get_port(dev, table, idx, ti); 3128c2ecf20Sopenharmony_ci} 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_cistatic inline void 3158c2ecf20Sopenharmony_ciudp_tunnel_nic_set_port_priv(struct net_device *dev, unsigned int table, 3168c2ecf20Sopenharmony_ci unsigned int idx, u8 priv) 3178c2ecf20Sopenharmony_ci{ 3188c2ecf20Sopenharmony_ci if (udp_tunnel_nic_ops) 3198c2ecf20Sopenharmony_ci udp_tunnel_nic_ops->set_port_priv(dev, table, idx, priv); 3208c2ecf20Sopenharmony_ci} 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_cistatic inline void 3238c2ecf20Sopenharmony_ciudp_tunnel_nic_add_port(struct net_device *dev, struct udp_tunnel_info *ti) 3248c2ecf20Sopenharmony_ci{ 3258c2ecf20Sopenharmony_ci if (udp_tunnel_nic_ops) 3268c2ecf20Sopenharmony_ci udp_tunnel_nic_ops->add_port(dev, ti); 3278c2ecf20Sopenharmony_ci} 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_cistatic inline void 3308c2ecf20Sopenharmony_ciudp_tunnel_nic_del_port(struct net_device *dev, struct udp_tunnel_info *ti) 3318c2ecf20Sopenharmony_ci{ 3328c2ecf20Sopenharmony_ci if (udp_tunnel_nic_ops) 3338c2ecf20Sopenharmony_ci udp_tunnel_nic_ops->del_port(dev, ti); 3348c2ecf20Sopenharmony_ci} 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci/** 3378c2ecf20Sopenharmony_ci * udp_tunnel_nic_reset_ntf() - device-originating reset notification 3388c2ecf20Sopenharmony_ci * @dev: network interface device structure 3398c2ecf20Sopenharmony_ci * 3408c2ecf20Sopenharmony_ci * Called by the driver to inform the core that the entire UDP tunnel port 3418c2ecf20Sopenharmony_ci * state has been lost, usually due to device reset. Core will assume device 3428c2ecf20Sopenharmony_ci * forgot all the ports and issue .set_port and .sync_table callbacks as 3438c2ecf20Sopenharmony_ci * necessary. 3448c2ecf20Sopenharmony_ci * 3458c2ecf20Sopenharmony_ci * This function must be called with rtnl lock held, and will issue all 3468c2ecf20Sopenharmony_ci * the callbacks before returning. 3478c2ecf20Sopenharmony_ci */ 3488c2ecf20Sopenharmony_cistatic inline void udp_tunnel_nic_reset_ntf(struct net_device *dev) 3498c2ecf20Sopenharmony_ci{ 3508c2ecf20Sopenharmony_ci if (udp_tunnel_nic_ops) 3518c2ecf20Sopenharmony_ci udp_tunnel_nic_ops->reset_ntf(dev); 3528c2ecf20Sopenharmony_ci} 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_cistatic inline size_t 3558c2ecf20Sopenharmony_ciudp_tunnel_nic_dump_size(struct net_device *dev, unsigned int table) 3568c2ecf20Sopenharmony_ci{ 3578c2ecf20Sopenharmony_ci if (!udp_tunnel_nic_ops) 3588c2ecf20Sopenharmony_ci return 0; 3598c2ecf20Sopenharmony_ci return udp_tunnel_nic_ops->dump_size(dev, table); 3608c2ecf20Sopenharmony_ci} 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_cistatic inline int 3638c2ecf20Sopenharmony_ciudp_tunnel_nic_dump_write(struct net_device *dev, unsigned int table, 3648c2ecf20Sopenharmony_ci struct sk_buff *skb) 3658c2ecf20Sopenharmony_ci{ 3668c2ecf20Sopenharmony_ci if (!udp_tunnel_nic_ops) 3678c2ecf20Sopenharmony_ci return 0; 3688c2ecf20Sopenharmony_ci return udp_tunnel_nic_ops->dump_write(dev, table, skb); 3698c2ecf20Sopenharmony_ci} 3708c2ecf20Sopenharmony_ci#endif 371