License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2014-07-14 10:49:37 +08:00
|
|
|
#ifndef __NET_UDP_TUNNEL_H
|
|
|
|
#define __NET_UDP_TUNNEL_H
|
|
|
|
|
2014-09-17 08:31:17 +08:00
|
|
|
#include <net/ip_tunnels.h>
|
|
|
|
#include <net/udp.h>
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
#include <net/ipv6.h>
|
2019-03-22 21:06:09 +08:00
|
|
|
#include <net/ipv6_stubs.h>
|
2014-09-17 08:31:17 +08:00
|
|
|
#endif
|
|
|
|
|
2014-07-14 10:49:37 +08:00
|
|
|
struct udp_port_cfg {
|
|
|
|
u8 family;
|
|
|
|
|
|
|
|
/* Used only for kernel-created sockets */
|
|
|
|
union {
|
|
|
|
struct in_addr local_ip;
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
struct in6_addr local_ip6;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct in_addr peer_ip;
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
struct in6_addr peer_ip6;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
__be16 local_udp_port;
|
|
|
|
__be16 peer_udp_port;
|
2018-12-03 17:54:38 +08:00
|
|
|
int bind_ifindex;
|
2014-07-14 10:49:37 +08:00
|
|
|
unsigned int use_udp_checksums:1,
|
|
|
|
use_udp6_tx_checksums:1,
|
2015-08-29 02:48:22 +08:00
|
|
|
use_udp6_rx_checksums:1,
|
|
|
|
ipv6_v6only:1;
|
2014-07-14 10:49:37 +08:00
|
|
|
};
|
|
|
|
|
2014-09-17 08:31:16 +08:00
|
|
|
int udp_sock_create4(struct net *net, struct udp_port_cfg *cfg,
|
|
|
|
struct socket **sockp);
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
|
|
|
|
struct socket **sockp);
|
|
|
|
#else
|
|
|
|
static inline int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg,
|
|
|
|
struct socket **sockp)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline int udp_sock_create(struct net *net,
|
|
|
|
struct udp_port_cfg *cfg,
|
|
|
|
struct socket **sockp)
|
|
|
|
{
|
|
|
|
if (cfg->family == AF_INET)
|
|
|
|
return udp_sock_create4(net, cfg, sockp);
|
|
|
|
|
|
|
|
if (cfg->family == AF_INET6)
|
|
|
|
return udp_sock_create6(net, cfg, sockp);
|
|
|
|
|
|
|
|
return -EPFNOSUPPORT;
|
|
|
|
}
|
2014-07-14 10:49:37 +08:00
|
|
|
|
2014-09-17 08:31:17 +08:00
|
|
|
typedef int (*udp_tunnel_encap_rcv_t)(struct sock *sk, struct sk_buff *skb);
|
udp: Handle ICMP errors for tunnels with same destination port on both endpoints
For both IPv4 and IPv6, if we can't match errors to a socket, try
tunnels before ignoring them. Look up a socket with the original source
and destination ports as found in the UDP packet inside the ICMP payload,
this will work for tunnels that force the same destination port for both
endpoints, i.e. VXLAN and GENEVE.
Actually, lwtunnels could break this assumption if they are configured by
an external control plane to have different destination ports on the
endpoints: in this case, we won't be able to trace ICMP messages back to
them.
For IPv6 redirect messages, call ip6_redirect() directly with the output
interface argument set to the interface we received the packet from (as
it's the very interface we should build the exception on), otherwise the
new nexthop will be rejected. There's no such need for IPv4.
Tunnels can now export an encap_err_lookup() operation that indicates a
match. Pass the packet to the lookup function, and if the tunnel driver
reports a matching association, continue with regular ICMP error handling.
v2:
- Added newline between network and transport header sets in
__udp{4,6}_lib_err_encap() (David Miller)
- Removed redundant skb_reset_network_header(skb); in
__udp4_lib_err_encap()
- Removed redundant reassignment of iph in __udp4_lib_err_encap()
(Sabrina Dubroca)
- Edited comment to __udp{4,6}_lib_err_encap() to reflect the fact this
won't work with lwtunnels configured to use asymmetric ports. By the way,
it's VXLAN, not VxLAN (Jiri Benc)
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-11-08 19:19:14 +08:00
|
|
|
typedef int (*udp_tunnel_encap_err_lookup_t)(struct sock *sk,
|
|
|
|
struct sk_buff *skb);
|
2014-09-17 08:31:17 +08:00
|
|
|
typedef void (*udp_tunnel_encap_destroy_t)(struct sock *sk);
|
2018-06-24 13:13:49 +08:00
|
|
|
typedef struct sk_buff *(*udp_tunnel_gro_receive_t)(struct sock *sk,
|
|
|
|
struct list_head *head,
|
|
|
|
struct sk_buff *skb);
|
2016-04-05 23:22:52 +08:00
|
|
|
typedef int (*udp_tunnel_gro_complete_t)(struct sock *sk, struct sk_buff *skb,
|
|
|
|
int nhoff);
|
2014-09-17 08:31:17 +08:00
|
|
|
|
|
|
|
struct udp_tunnel_sock_cfg {
|
|
|
|
void *sk_user_data; /* user data used by encap_rcv call back */
|
|
|
|
/* Used for setting up udp_sock fields, see udp.h for details */
|
|
|
|
__u8 encap_type;
|
|
|
|
udp_tunnel_encap_rcv_t encap_rcv;
|
udp: Handle ICMP errors for tunnels with same destination port on both endpoints
For both IPv4 and IPv6, if we can't match errors to a socket, try
tunnels before ignoring them. Look up a socket with the original source
and destination ports as found in the UDP packet inside the ICMP payload,
this will work for tunnels that force the same destination port for both
endpoints, i.e. VXLAN and GENEVE.
Actually, lwtunnels could break this assumption if they are configured by
an external control plane to have different destination ports on the
endpoints: in this case, we won't be able to trace ICMP messages back to
them.
For IPv6 redirect messages, call ip6_redirect() directly with the output
interface argument set to the interface we received the packet from (as
it's the very interface we should build the exception on), otherwise the
new nexthop will be rejected. There's no such need for IPv4.
Tunnels can now export an encap_err_lookup() operation that indicates a
match. Pass the packet to the lookup function, and if the tunnel driver
reports a matching association, continue with regular ICMP error handling.
v2:
- Added newline between network and transport header sets in
__udp{4,6}_lib_err_encap() (David Miller)
- Removed redundant skb_reset_network_header(skb); in
__udp4_lib_err_encap()
- Removed redundant reassignment of iph in __udp4_lib_err_encap()
(Sabrina Dubroca)
- Edited comment to __udp{4,6}_lib_err_encap() to reflect the fact this
won't work with lwtunnels configured to use asymmetric ports. By the way,
it's VXLAN, not VxLAN (Jiri Benc)
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-11-08 19:19:14 +08:00
|
|
|
udp_tunnel_encap_err_lookup_t encap_err_lookup;
|
2014-09-17 08:31:17 +08:00
|
|
|
udp_tunnel_encap_destroy_t encap_destroy;
|
2016-04-05 23:22:52 +08:00
|
|
|
udp_tunnel_gro_receive_t gro_receive;
|
|
|
|
udp_tunnel_gro_complete_t gro_complete;
|
2014-09-17 08:31:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup the given (UDP) sock to receive UDP encapsulated packets */
|
|
|
|
void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
|
|
|
|
struct udp_tunnel_sock_cfg *sock_cfg);
|
|
|
|
|
2016-06-17 03:20:52 +08:00
|
|
|
/* -- List of parsable UDP tunnel types --
|
|
|
|
*
|
|
|
|
* Adding to this list will result in serious debate. The main issue is
|
|
|
|
* that this list is essentially a list of workarounds for either poorly
|
|
|
|
* designed tunnels, or poorly designed device offloads.
|
|
|
|
*
|
|
|
|
* The parsing supported via these types should really be used for Rx
|
|
|
|
* traffic only as the network stack will have already inserted offsets for
|
|
|
|
* the location of the headers in the skb. In addition any ports that are
|
|
|
|
* pushed should be kept within the namespace without leaking to other
|
|
|
|
* devices such as VFs or other ports on the same device.
|
|
|
|
*
|
|
|
|
* It is strongly encouraged to use CHECKSUM_COMPLETE for Rx to avoid the
|
|
|
|
* need to use this for Rx checksum offload. It should not be necessary to
|
|
|
|
* call this function to perform Tx offloads on outgoing traffic.
|
|
|
|
*/
|
|
|
|
enum udp_parsable_tunnel_type {
|
2020-07-10 08:42:45 +08:00
|
|
|
UDP_TUNNEL_TYPE_VXLAN = BIT(0), /* RFC 7348 */
|
|
|
|
UDP_TUNNEL_TYPE_GENEVE = BIT(1), /* draft-ietf-nvo3-geneve */
|
|
|
|
UDP_TUNNEL_TYPE_VXLAN_GPE = BIT(2), /* draft-ietf-nvo3-vxlan-gpe */
|
2016-06-17 03:20:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct udp_tunnel_info {
|
|
|
|
unsigned short type;
|
|
|
|
sa_family_t sa_family;
|
|
|
|
__be16 port;
|
2020-07-10 08:42:46 +08:00
|
|
|
u8 hw_priv;
|
2016-06-17 03:20:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Notify network devices of offloadable types */
|
|
|
|
void udp_tunnel_push_rx_port(struct net_device *dev, struct socket *sock,
|
|
|
|
unsigned short type);
|
2017-07-21 18:49:30 +08:00
|
|
|
void udp_tunnel_drop_rx_port(struct net_device *dev, struct socket *sock,
|
|
|
|
unsigned short type);
|
2016-06-17 03:20:52 +08:00
|
|
|
void udp_tunnel_notify_add_rx_port(struct socket *sock, unsigned short type);
|
|
|
|
void udp_tunnel_notify_del_rx_port(struct socket *sock, unsigned short type);
|
|
|
|
|
2016-06-17 03:21:00 +08:00
|
|
|
static inline void udp_tunnel_get_rx_info(struct net_device *dev)
|
|
|
|
{
|
|
|
|
ASSERT_RTNL();
|
2021-01-07 05:06:37 +08:00
|
|
|
if (!(dev->features & NETIF_F_RX_UDP_TUNNEL_PORT))
|
|
|
|
return;
|
2016-06-17 03:21:00 +08:00
|
|
|
call_netdevice_notifiers(NETDEV_UDP_TUNNEL_PUSH_INFO, dev);
|
|
|
|
}
|
|
|
|
|
2017-07-21 18:49:30 +08:00
|
|
|
static inline void udp_tunnel_drop_rx_info(struct net_device *dev)
|
|
|
|
{
|
|
|
|
ASSERT_RTNL();
|
2021-01-07 05:06:37 +08:00
|
|
|
if (!(dev->features & NETIF_F_RX_UDP_TUNNEL_PORT))
|
|
|
|
return;
|
2017-07-21 18:49:30 +08:00
|
|
|
call_netdevice_notifiers(NETDEV_UDP_TUNNEL_DROP_INFO, dev);
|
|
|
|
}
|
|
|
|
|
2014-09-17 08:31:17 +08:00
|
|
|
/* Transmit the skb using UDP encapsulation. */
|
2015-12-25 06:34:54 +08:00
|
|
|
void udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
|
|
|
|
__be32 src, __be32 dst, __u8 tos, __u8 ttl,
|
|
|
|
__be16 df, __be16 src_port, __be16 dst_port,
|
|
|
|
bool xnet, bool nocheck);
|
2014-09-17 08:31:17 +08:00
|
|
|
|
2015-04-06 10:19:09 +08:00
|
|
|
int udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk,
|
|
|
|
struct sk_buff *skb,
|
2015-01-21 03:23:04 +08:00
|
|
|
struct net_device *dev, struct in6_addr *saddr,
|
|
|
|
struct in6_addr *daddr,
|
2016-03-09 10:00:02 +08:00
|
|
|
__u8 prio, __u8 ttl, __be32 label,
|
|
|
|
__be16 src_port, __be16 dst_port, bool nocheck);
|
2014-09-17 08:31:17 +08:00
|
|
|
|
|
|
|
void udp_tunnel_sock_release(struct socket *sock);
|
|
|
|
|
2015-08-27 14:46:50 +08:00
|
|
|
struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family,
|
|
|
|
__be16 flags, __be64 tunnel_id,
|
|
|
|
int md_size);
|
|
|
|
|
2016-06-17 03:20:44 +08:00
|
|
|
#ifdef CONFIG_INET
|
2016-04-15 03:33:37 +08:00
|
|
|
static inline int udp_tunnel_handle_offloads(struct sk_buff *skb, bool udp_csum)
|
2014-09-17 08:31:17 +08:00
|
|
|
{
|
|
|
|
int type = udp_csum ? SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL;
|
|
|
|
|
2016-02-12 05:02:31 +08:00
|
|
|
return iptunnel_handle_offloads(skb, type);
|
2014-09-17 08:31:17 +08:00
|
|
|
}
|
2016-06-17 03:20:44 +08:00
|
|
|
#endif
|
2014-09-17 08:31:17 +08:00
|
|
|
|
|
|
|
static inline void udp_tunnel_encap_enable(struct socket *sock)
|
|
|
|
{
|
2018-11-07 19:38:28 +08:00
|
|
|
struct udp_sock *up = udp_sk(sock->sk);
|
|
|
|
|
|
|
|
if (up->encap_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
up->encap_enabled = 1;
|
2014-09-17 08:31:17 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
if (sock->sk->sk_family == PF_INET6)
|
|
|
|
ipv6_stub->udpv6_encap_enable();
|
|
|
|
#endif
|
2021-02-03 16:54:22 +08:00
|
|
|
udp_encap_enable();
|
2014-09-17 08:31:17 +08:00
|
|
|
}
|
|
|
|
|
2020-07-10 08:42:46 +08:00
|
|
|
#define UDP_TUNNEL_NIC_MAX_TABLES 4
|
|
|
|
|
|
|
|
enum udp_tunnel_nic_info_flags {
|
|
|
|
/* Device callbacks may sleep */
|
|
|
|
UDP_TUNNEL_NIC_INFO_MAY_SLEEP = BIT(0),
|
|
|
|
/* Device only supports offloads when it's open, all ports
|
|
|
|
* will be removed before close and re-added after open.
|
|
|
|
*/
|
|
|
|
UDP_TUNNEL_NIC_INFO_OPEN_ONLY = BIT(1),
|
|
|
|
/* Device supports only IPv4 tunnels */
|
|
|
|
UDP_TUNNEL_NIC_INFO_IPV4_ONLY = BIT(2),
|
2020-07-29 05:47:58 +08:00
|
|
|
/* Device has hard-coded the IANA VXLAN port (4789) as VXLAN.
|
|
|
|
* This port must not be counted towards n_entries of any table.
|
|
|
|
* Driver will not receive any callback associated with port 4789.
|
|
|
|
*/
|
|
|
|
UDP_TUNNEL_NIC_INFO_STATIC_IANA_VXLAN = BIT(3),
|
2020-07-10 08:42:46 +08:00
|
|
|
};
|
|
|
|
|
2020-09-26 08:56:40 +08:00
|
|
|
struct udp_tunnel_nic;
|
|
|
|
|
|
|
|
#define UDP_TUNNEL_NIC_MAX_SHARING_DEVICES (U16_MAX / 2)
|
|
|
|
|
|
|
|
struct udp_tunnel_nic_shared {
|
|
|
|
struct udp_tunnel_nic *udp_tunnel_nic_info;
|
|
|
|
|
|
|
|
struct list_head devices;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct udp_tunnel_nic_shared_node {
|
|
|
|
struct net_device *dev;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2020-07-10 08:42:46 +08:00
|
|
|
/**
|
|
|
|
* struct udp_tunnel_nic_info - driver UDP tunnel offload information
|
|
|
|
* @set_port: callback for adding a new port
|
|
|
|
* @unset_port: callback for removing a port
|
|
|
|
* @sync_table: callback for syncing the entire port table at once
|
2020-09-26 08:56:40 +08:00
|
|
|
* @shared: reference to device global state (optional)
|
2020-07-10 08:42:46 +08:00
|
|
|
* @flags: device flags from enum udp_tunnel_nic_info_flags
|
|
|
|
* @tables: UDP port tables this device has
|
|
|
|
* @tables.n_entries: number of entries in this table
|
|
|
|
* @tables.tunnel_types: types of tunnels this table accepts
|
|
|
|
*
|
|
|
|
* Drivers are expected to provide either @set_port and @unset_port callbacks
|
|
|
|
* or the @sync_table callback. Callbacks are invoked with rtnl lock held.
|
|
|
|
*
|
2020-09-26 08:56:40 +08:00
|
|
|
* Devices which (misguidedly) share the UDP tunnel port table across multiple
|
|
|
|
* netdevs should allocate an instance of struct udp_tunnel_nic_shared and
|
|
|
|
* point @shared at it.
|
|
|
|
* There must never be more than %UDP_TUNNEL_NIC_MAX_SHARING_DEVICES devices
|
|
|
|
* sharing a table.
|
|
|
|
*
|
2020-07-10 08:42:46 +08:00
|
|
|
* Known limitations:
|
|
|
|
* - UDP tunnel port notifications are fundamentally best-effort -
|
|
|
|
* it is likely the driver will both see skbs which use a UDP tunnel port,
|
|
|
|
* while not being a tunneled skb, and tunnel skbs from other ports -
|
|
|
|
* drivers should only use these ports for non-critical RX-side offloads,
|
|
|
|
* e.g. the checksum offload;
|
|
|
|
* - none of the devices care about the socket family at present, so we don't
|
|
|
|
* track it. Please extend this code if you care.
|
|
|
|
*/
|
|
|
|
struct udp_tunnel_nic_info {
|
|
|
|
/* one-by-one */
|
|
|
|
int (*set_port)(struct net_device *dev,
|
|
|
|
unsigned int table, unsigned int entry,
|
|
|
|
struct udp_tunnel_info *ti);
|
|
|
|
int (*unset_port)(struct net_device *dev,
|
|
|
|
unsigned int table, unsigned int entry,
|
|
|
|
struct udp_tunnel_info *ti);
|
|
|
|
|
|
|
|
/* all at once */
|
|
|
|
int (*sync_table)(struct net_device *dev, unsigned int table);
|
|
|
|
|
2020-09-26 08:56:40 +08:00
|
|
|
struct udp_tunnel_nic_shared *shared;
|
|
|
|
|
2020-07-10 08:42:46 +08:00
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
struct udp_tunnel_nic_table_info {
|
|
|
|
unsigned int n_entries;
|
|
|
|
unsigned int tunnel_types;
|
|
|
|
} tables[UDP_TUNNEL_NIC_MAX_TABLES];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* UDP tunnel module dependencies
|
|
|
|
*
|
|
|
|
* Tunnel drivers are expected to have a hard dependency on the udp_tunnel
|
|
|
|
* module. NIC drivers are not, they just attach their
|
|
|
|
* struct udp_tunnel_nic_info to the netdev and wait for callbacks to come.
|
|
|
|
* Loading a tunnel driver will cause the udp_tunnel module to be loaded
|
|
|
|
* and only then will all the required state structures be allocated.
|
|
|
|
* Since we want a weak dependency from the drivers and the core to udp_tunnel
|
|
|
|
* we call things through the following stubs.
|
|
|
|
*/
|
|
|
|
struct udp_tunnel_nic_ops {
|
|
|
|
void (*get_port)(struct net_device *dev, unsigned int table,
|
|
|
|
unsigned int idx, struct udp_tunnel_info *ti);
|
|
|
|
void (*set_port_priv)(struct net_device *dev, unsigned int table,
|
|
|
|
unsigned int idx, u8 priv);
|
|
|
|
void (*add_port)(struct net_device *dev, struct udp_tunnel_info *ti);
|
|
|
|
void (*del_port)(struct net_device *dev, struct udp_tunnel_info *ti);
|
|
|
|
void (*reset_ntf)(struct net_device *dev);
|
2020-07-10 08:42:47 +08:00
|
|
|
|
|
|
|
size_t (*dump_size)(struct net_device *dev, unsigned int table);
|
|
|
|
int (*dump_write)(struct net_device *dev, unsigned int table,
|
|
|
|
struct sk_buff *skb);
|
2020-07-10 08:42:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_INET
|
|
|
|
extern const struct udp_tunnel_nic_ops *udp_tunnel_nic_ops;
|
|
|
|
#else
|
|
|
|
#define udp_tunnel_nic_ops ((struct udp_tunnel_nic_ops *)NULL)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
udp_tunnel_nic_get_port(struct net_device *dev, unsigned int table,
|
|
|
|
unsigned int idx, struct udp_tunnel_info *ti)
|
|
|
|
{
|
|
|
|
/* This helper is used from .sync_table, we indicate empty entries
|
|
|
|
* by zero'ed @ti. Drivers which need to know the details of a port
|
|
|
|
* when it gets deleted should use the .set_port / .unset_port
|
|
|
|
* callbacks.
|
|
|
|
* Zero out here, otherwise !CONFIG_INET causes uninitilized warnings.
|
|
|
|
*/
|
|
|
|
memset(ti, 0, sizeof(*ti));
|
|
|
|
|
|
|
|
if (udp_tunnel_nic_ops)
|
|
|
|
udp_tunnel_nic_ops->get_port(dev, table, idx, ti);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
udp_tunnel_nic_set_port_priv(struct net_device *dev, unsigned int table,
|
|
|
|
unsigned int idx, u8 priv)
|
|
|
|
{
|
|
|
|
if (udp_tunnel_nic_ops)
|
|
|
|
udp_tunnel_nic_ops->set_port_priv(dev, table, idx, priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
udp_tunnel_nic_add_port(struct net_device *dev, struct udp_tunnel_info *ti)
|
|
|
|
{
|
2021-01-07 05:06:37 +08:00
|
|
|
if (!(dev->features & NETIF_F_RX_UDP_TUNNEL_PORT))
|
|
|
|
return;
|
2020-07-10 08:42:46 +08:00
|
|
|
if (udp_tunnel_nic_ops)
|
|
|
|
udp_tunnel_nic_ops->add_port(dev, ti);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
udp_tunnel_nic_del_port(struct net_device *dev, struct udp_tunnel_info *ti)
|
|
|
|
{
|
2021-01-07 05:06:37 +08:00
|
|
|
if (!(dev->features & NETIF_F_RX_UDP_TUNNEL_PORT))
|
|
|
|
return;
|
2020-07-10 08:42:46 +08:00
|
|
|
if (udp_tunnel_nic_ops)
|
|
|
|
udp_tunnel_nic_ops->del_port(dev, ti);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* udp_tunnel_nic_reset_ntf() - device-originating reset notification
|
|
|
|
* @dev: network interface device structure
|
|
|
|
*
|
|
|
|
* Called by the driver to inform the core that the entire UDP tunnel port
|
|
|
|
* state has been lost, usually due to device reset. Core will assume device
|
|
|
|
* forgot all the ports and issue .set_port and .sync_table callbacks as
|
|
|
|
* necessary.
|
|
|
|
*
|
|
|
|
* This function must be called with rtnl lock held, and will issue all
|
|
|
|
* the callbacks before returning.
|
|
|
|
*/
|
|
|
|
static inline void udp_tunnel_nic_reset_ntf(struct net_device *dev)
|
|
|
|
{
|
|
|
|
if (udp_tunnel_nic_ops)
|
|
|
|
udp_tunnel_nic_ops->reset_ntf(dev);
|
|
|
|
}
|
2020-07-10 08:42:47 +08:00
|
|
|
|
|
|
|
static inline size_t
|
|
|
|
udp_tunnel_nic_dump_size(struct net_device *dev, unsigned int table)
|
|
|
|
{
|
|
|
|
if (!udp_tunnel_nic_ops)
|
|
|
|
return 0;
|
|
|
|
return udp_tunnel_nic_ops->dump_size(dev, table);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
udp_tunnel_nic_dump_write(struct net_device *dev, unsigned int table,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
if (!udp_tunnel_nic_ops)
|
|
|
|
return 0;
|
|
|
|
return udp_tunnel_nic_ops->dump_write(dev, table, skb);
|
|
|
|
}
|
2014-07-14 10:49:37 +08:00
|
|
|
#endif
|