2020-02-23 22:27:50 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/* Bareudp: UDP tunnel encasulation for different Payload types like
|
|
|
|
* MPLS, NSH, IP, etc.
|
|
|
|
* Copyright (c) 2019 Nokia, Inc.
|
|
|
|
* Authors: Martin Varghese, <martin.varghese@nokia.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/hash.h>
|
|
|
|
#include <net/dst_metadata.h>
|
|
|
|
#include <net/gro_cells.h>
|
|
|
|
#include <net/rtnetlink.h>
|
|
|
|
#include <net/protocol.h>
|
|
|
|
#include <net/ip6_tunnel.h>
|
|
|
|
#include <net/ip_tunnels.h>
|
|
|
|
#include <net/udp_tunnel.h>
|
|
|
|
#include <net/bareudp.h>
|
|
|
|
|
|
|
|
#define BAREUDP_BASE_HLEN sizeof(struct udphdr)
|
|
|
|
#define BAREUDP_IPV4_HLEN (sizeof(struct iphdr) + \
|
|
|
|
sizeof(struct udphdr))
|
|
|
|
#define BAREUDP_IPV6_HLEN (sizeof(struct ipv6hdr) + \
|
|
|
|
sizeof(struct udphdr))
|
|
|
|
|
|
|
|
static bool log_ecn_error = true;
|
|
|
|
module_param(log_ecn_error, bool, 0644);
|
|
|
|
MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
|
|
|
|
|
|
|
|
/* per-network namespace private data for this module */
|
|
|
|
|
|
|
|
static unsigned int bareudp_net_id;
|
|
|
|
|
|
|
|
struct bareudp_net {
|
|
|
|
struct list_head bareudp_list;
|
|
|
|
};
|
|
|
|
|
2021-12-10 12:56:39 -07:00
|
|
|
struct bareudp_conf {
|
|
|
|
__be16 ethertype;
|
|
|
|
__be16 port;
|
|
|
|
u16 sport_min;
|
|
|
|
bool multi_proto_mode;
|
|
|
|
};
|
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
/* Pseudo network device */
|
|
|
|
struct bareudp_dev {
|
|
|
|
struct net *net; /* netns for packet i/o */
|
|
|
|
struct net_device *dev; /* netdev for bareudp tunnel */
|
|
|
|
__be16 ethertype;
|
|
|
|
__be16 port;
|
|
|
|
u16 sport_min;
|
2020-02-23 22:28:35 -07:00
|
|
|
bool multi_proto_mode;
|
2020-02-23 22:27:50 -07:00
|
|
|
struct socket __rcu *sock;
|
|
|
|
struct list_head next; /* bareudp node on namespace list */
|
|
|
|
struct gro_cells gro_cells;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct metadata_dst *tun_dst = NULL;
|
ip_tunnel: convert __be16 tunnel flags to bitmaps
Historically, tunnel flags like TUNNEL_CSUM or TUNNEL_ERSPAN_OPT
have been defined as __be16. Now all of those 16 bits are occupied
and there's no more free space for new flags.
It can't be simply switched to a bigger container with no
adjustments to the values, since it's an explicit Endian storage,
and on LE systems (__be16)0x0001 equals to
(__be64)0x0001000000000000.
We could probably define new 64-bit flags depending on the
Endianness, i.e. (__be64)0x0001 on BE and (__be64)0x00010000... on
LE, but that would introduce an Endianness dependency and spawn a
ton of Sparse warnings. To mitigate them, all of those places which
were adjusted with this change would be touched anyway, so why not
define stuff properly if there's no choice.
Define IP_TUNNEL_*_BIT counterparts as a bit number instead of the
value already coded and a fistful of <16 <-> bitmap> converters and
helpers. The two flags which have a different bit position are
SIT_ISATAP_BIT and VTI_ISVTI_BIT, as they were defined not as
__cpu_to_be16(), but as (__force __be16), i.e. had different
positions on LE and BE. Now they both have strongly defined places.
Change all __be16 fields which were used to store those flags, to
IP_TUNNEL_DECLARE_FLAGS() -> DECLARE_BITMAP(__IP_TUNNEL_FLAG_NUM) ->
unsigned long[1] for now, and replace all TUNNEL_* occurrences to
their bitmap counterparts. Use the converters in the places which talk
to the userspace, hardware (NFP) or other hosts (GRE header). The rest
must explicitly use the new flags only. This must be done at once,
otherwise there will be too many conversions throughout the code in
the intermediate commits.
Finally, disable the old __be16 flags for use in the kernel code
(except for the two 'irregular' flags mentioned above), to prevent
any accidental (mis)use of them. For the userspace, nothing is
changed, only additions were made.
Most noticeable bloat-o-meter difference (.text):
vmlinux: 307/-1 (306)
gre.ko: 62/0 (62)
ip_gre.ko: 941/-217 (724) [*]
ip_tunnel.ko: 390/-900 (-510) [**]
ip_vti.ko: 138/0 (138)
ip6_gre.ko: 534/-18 (516) [*]
ip6_tunnel.ko: 118/-10 (108)
[*] gre_flags_to_tnl_flags() grew, but still is inlined
[**] ip_tunnel_find() got uninlined, hence such decrease
The average code size increase in non-extreme case is 100-200 bytes
per module, mostly due to sizeof(long) > sizeof(__be16), as
%__IP_TUNNEL_FLAG_NUM is less than %BITS_PER_LONG and the compilers
are able to expand the majority of bitmap_*() calls here into direct
operations on scalars.
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-03-27 08:23:53 -07:00
|
|
|
IP_TUNNEL_DECLARE_FLAGS(key) = { };
|
2020-02-23 22:27:50 -07:00
|
|
|
struct bareudp_dev *bareudp;
|
|
|
|
unsigned short family;
|
|
|
|
unsigned int len;
|
|
|
|
__be16 proto;
|
|
|
|
void *oiph;
|
|
|
|
int err;
|
2024-09-11 02:20:58 -07:00
|
|
|
int nh;
|
2020-02-23 22:27:50 -07:00
|
|
|
|
|
|
|
bareudp = rcu_dereference_sk_user_data(sk);
|
|
|
|
if (!bareudp)
|
|
|
|
goto drop;
|
|
|
|
|
|
|
|
if (skb->protocol == htons(ETH_P_IP))
|
|
|
|
family = AF_INET;
|
|
|
|
else
|
|
|
|
family = AF_INET6;
|
|
|
|
|
2020-02-23 22:28:35 -07:00
|
|
|
if (bareudp->ethertype == htons(ETH_P_IP)) {
|
2021-08-06 08:52:06 -07:00
|
|
|
__u8 ipversion;
|
2020-02-23 22:28:35 -07:00
|
|
|
|
2021-08-06 08:52:06 -07:00
|
|
|
if (skb_copy_bits(skb, BAREUDP_BASE_HLEN, &ipversion,
|
|
|
|
sizeof(ipversion))) {
|
2024-08-30 08:31:07 -07:00
|
|
|
DEV_STATS_INC(bareudp->dev, rx_dropped);
|
2021-08-06 08:52:06 -07:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
ipversion >>= 4;
|
|
|
|
|
|
|
|
if (ipversion == 4) {
|
|
|
|
proto = htons(ETH_P_IP);
|
|
|
|
} else if (ipversion == 6 && bareudp->multi_proto_mode) {
|
2020-02-23 22:28:35 -07:00
|
|
|
proto = htons(ETH_P_IPV6);
|
|
|
|
} else {
|
2024-08-30 08:31:07 -07:00
|
|
|
DEV_STATS_INC(bareudp->dev, rx_dropped);
|
2020-02-23 22:28:35 -07:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
} else if (bareudp->ethertype == htons(ETH_P_MPLS_UC)) {
|
|
|
|
struct iphdr *tunnel_hdr;
|
|
|
|
|
|
|
|
tunnel_hdr = (struct iphdr *)skb_network_header(skb);
|
|
|
|
if (tunnel_hdr->version == 4) {
|
|
|
|
if (!ipv4_is_multicast(tunnel_hdr->daddr)) {
|
|
|
|
proto = bareudp->ethertype;
|
|
|
|
} else if (bareudp->multi_proto_mode &&
|
|
|
|
ipv4_is_multicast(tunnel_hdr->daddr)) {
|
|
|
|
proto = htons(ETH_P_MPLS_MC);
|
|
|
|
} else {
|
2024-08-30 08:31:07 -07:00
|
|
|
DEV_STATS_INC(bareudp->dev, rx_dropped);
|
2020-02-23 22:28:35 -07:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int addr_type;
|
|
|
|
struct ipv6hdr *tunnel_hdr_v6;
|
|
|
|
|
|
|
|
tunnel_hdr_v6 = (struct ipv6hdr *)skb_network_header(skb);
|
|
|
|
addr_type =
|
|
|
|
ipv6_addr_type((struct in6_addr *)&tunnel_hdr_v6->daddr);
|
|
|
|
if (!(addr_type & IPV6_ADDR_MULTICAST)) {
|
|
|
|
proto = bareudp->ethertype;
|
|
|
|
} else if (bareudp->multi_proto_mode &&
|
|
|
|
(addr_type & IPV6_ADDR_MULTICAST)) {
|
|
|
|
proto = htons(ETH_P_MPLS_MC);
|
|
|
|
} else {
|
2024-08-30 08:31:07 -07:00
|
|
|
DEV_STATS_INC(bareudp->dev, rx_dropped);
|
2020-02-23 22:28:35 -07:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
proto = bareudp->ethertype;
|
|
|
|
}
|
2020-02-23 22:27:50 -07:00
|
|
|
|
|
|
|
if (iptunnel_pull_header(skb, BAREUDP_BASE_HLEN,
|
|
|
|
proto,
|
|
|
|
!net_eq(bareudp->net,
|
|
|
|
dev_net(bareudp->dev)))) {
|
2024-08-30 08:31:07 -07:00
|
|
|
DEV_STATS_INC(bareudp->dev, rx_dropped);
|
2020-02-23 22:27:50 -07:00
|
|
|
goto drop;
|
|
|
|
}
|
ip_tunnel: convert __be16 tunnel flags to bitmaps
Historically, tunnel flags like TUNNEL_CSUM or TUNNEL_ERSPAN_OPT
have been defined as __be16. Now all of those 16 bits are occupied
and there's no more free space for new flags.
It can't be simply switched to a bigger container with no
adjustments to the values, since it's an explicit Endian storage,
and on LE systems (__be16)0x0001 equals to
(__be64)0x0001000000000000.
We could probably define new 64-bit flags depending on the
Endianness, i.e. (__be64)0x0001 on BE and (__be64)0x00010000... on
LE, but that would introduce an Endianness dependency and spawn a
ton of Sparse warnings. To mitigate them, all of those places which
were adjusted with this change would be touched anyway, so why not
define stuff properly if there's no choice.
Define IP_TUNNEL_*_BIT counterparts as a bit number instead of the
value already coded and a fistful of <16 <-> bitmap> converters and
helpers. The two flags which have a different bit position are
SIT_ISATAP_BIT and VTI_ISVTI_BIT, as they were defined not as
__cpu_to_be16(), but as (__force __be16), i.e. had different
positions on LE and BE. Now they both have strongly defined places.
Change all __be16 fields which were used to store those flags, to
IP_TUNNEL_DECLARE_FLAGS() -> DECLARE_BITMAP(__IP_TUNNEL_FLAG_NUM) ->
unsigned long[1] for now, and replace all TUNNEL_* occurrences to
their bitmap counterparts. Use the converters in the places which talk
to the userspace, hardware (NFP) or other hosts (GRE header). The rest
must explicitly use the new flags only. This must be done at once,
otherwise there will be too many conversions throughout the code in
the intermediate commits.
Finally, disable the old __be16 flags for use in the kernel code
(except for the two 'irregular' flags mentioned above), to prevent
any accidental (mis)use of them. For the userspace, nothing is
changed, only additions were made.
Most noticeable bloat-o-meter difference (.text):
vmlinux: 307/-1 (306)
gre.ko: 62/0 (62)
ip_gre.ko: 941/-217 (724) [*]
ip_tunnel.ko: 390/-900 (-510) [**]
ip_vti.ko: 138/0 (138)
ip6_gre.ko: 534/-18 (516) [*]
ip6_tunnel.ko: 118/-10 (108)
[*] gre_flags_to_tnl_flags() grew, but still is inlined
[**] ip_tunnel_find() got uninlined, hence such decrease
The average code size increase in non-extreme case is 100-200 bytes
per module, mostly due to sizeof(long) > sizeof(__be16), as
%__IP_TUNNEL_FLAG_NUM is less than %BITS_PER_LONG and the compilers
are able to expand the majority of bitmap_*() calls here into direct
operations on scalars.
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-03-27 08:23:53 -07:00
|
|
|
|
|
|
|
__set_bit(IP_TUNNEL_KEY_BIT, key);
|
|
|
|
|
|
|
|
tun_dst = udp_tun_rx_dst(skb, family, key, 0, 0);
|
2020-07-16 19:35:12 -07:00
|
|
|
if (!tun_dst) {
|
2024-08-30 08:31:07 -07:00
|
|
|
DEV_STATS_INC(bareudp->dev, rx_dropped);
|
2020-07-16 19:35:12 -07:00
|
|
|
goto drop;
|
2020-02-23 22:27:50 -07:00
|
|
|
}
|
2020-07-16 19:35:12 -07:00
|
|
|
skb_dst_set(skb, &tun_dst->dst);
|
2020-02-23 22:27:50 -07:00
|
|
|
skb->dev = bareudp->dev;
|
2021-06-25 06:33:01 -07:00
|
|
|
skb_reset_mac_header(skb);
|
2020-02-23 22:27:50 -07:00
|
|
|
|
2024-09-11 02:20:58 -07:00
|
|
|
/* Save offset of outer header relative to skb->head,
|
|
|
|
* because we are going to reset the network header to the inner header
|
|
|
|
* and might change skb->head.
|
|
|
|
*/
|
|
|
|
nh = skb_network_header(skb) - skb->head;
|
|
|
|
|
|
|
|
skb_reset_network_header(skb);
|
|
|
|
|
|
|
|
if (!pskb_inet_may_pull(skb)) {
|
|
|
|
DEV_STATS_INC(bareudp->dev, rx_length_errors);
|
|
|
|
DEV_STATS_INC(bareudp->dev, rx_errors);
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the outer header. */
|
|
|
|
oiph = skb->head + nh;
|
|
|
|
|
2022-03-14 23:26:18 -07:00
|
|
|
if (!ipv6_mod_enabled() || family == AF_INET)
|
2020-02-23 22:27:50 -07:00
|
|
|
err = IP_ECN_decapsulate(oiph, skb);
|
|
|
|
else
|
|
|
|
err = IP6_ECN_decapsulate(oiph, skb);
|
|
|
|
|
|
|
|
if (unlikely(err)) {
|
|
|
|
if (log_ecn_error) {
|
2022-03-14 23:26:18 -07:00
|
|
|
if (!ipv6_mod_enabled() || family == AF_INET)
|
2020-02-23 22:27:50 -07:00
|
|
|
net_info_ratelimited("non-ECT from %pI4 "
|
|
|
|
"with TOS=%#x\n",
|
|
|
|
&((struct iphdr *)oiph)->saddr,
|
|
|
|
((struct iphdr *)oiph)->tos);
|
|
|
|
else
|
|
|
|
net_info_ratelimited("non-ECT from %pI6\n",
|
|
|
|
&((struct ipv6hdr *)oiph)->saddr);
|
|
|
|
}
|
|
|
|
if (err > 1) {
|
2024-08-30 08:31:07 -07:00
|
|
|
DEV_STATS_INC(bareudp->dev, rx_frame_errors);
|
|
|
|
DEV_STATS_INC(bareudp->dev, rx_errors);
|
2020-02-23 22:27:50 -07:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len = skb->len;
|
|
|
|
err = gro_cells_receive(&bareudp->gro_cells, skb);
|
2020-10-05 13:35:15 -07:00
|
|
|
if (likely(err == NET_RX_SUCCESS))
|
|
|
|
dev_sw_netstats_rx_add(bareudp->dev, len);
|
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
return 0;
|
|
|
|
drop:
|
|
|
|
/* Consume bad packet */
|
|
|
|
kfree_skb(skb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp_err_lookup(struct sock *sk, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp_init(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct bareudp_dev *bareudp = netdev_priv(dev);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = gro_cells_init(&bareudp->gro_cells, dev);
|
2024-02-29 10:04:23 -07:00
|
|
|
if (err)
|
2020-02-23 22:27:50 -07:00
|
|
|
return err;
|
2024-02-29 10:04:23 -07:00
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bareudp_uninit(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct bareudp_dev *bareudp = netdev_priv(dev);
|
|
|
|
|
|
|
|
gro_cells_destroy(&bareudp->gro_cells);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct socket *bareudp_create_sock(struct net *net, __be16 port)
|
|
|
|
{
|
|
|
|
struct udp_port_cfg udp_conf;
|
|
|
|
struct socket *sock;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
memset(&udp_conf, 0, sizeof(udp_conf));
|
2022-03-14 23:26:18 -07:00
|
|
|
|
|
|
|
if (ipv6_mod_enabled())
|
|
|
|
udp_conf.family = AF_INET6;
|
|
|
|
else
|
|
|
|
udp_conf.family = AF_INET;
|
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
udp_conf.local_udp_port = port;
|
|
|
|
/* Open UDP socket */
|
|
|
|
err = udp_sock_create(net, &udp_conf, &sock);
|
|
|
|
if (err < 0)
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
2021-03-30 03:28:55 -07:00
|
|
|
udp_allow_gso(sock->sk);
|
2020-02-23 22:27:50 -07:00
|
|
|
return sock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create new listen socket if needed */
|
|
|
|
static int bareudp_socket_create(struct bareudp_dev *bareudp, __be16 port)
|
|
|
|
{
|
|
|
|
struct udp_tunnel_sock_cfg tunnel_cfg;
|
|
|
|
struct socket *sock;
|
|
|
|
|
|
|
|
sock = bareudp_create_sock(bareudp->net, port);
|
|
|
|
if (IS_ERR(sock))
|
|
|
|
return PTR_ERR(sock);
|
|
|
|
|
|
|
|
/* Mark socket as an encapsulation socket */
|
|
|
|
memset(&tunnel_cfg, 0, sizeof(tunnel_cfg));
|
|
|
|
tunnel_cfg.sk_user_data = bareudp;
|
|
|
|
tunnel_cfg.encap_type = 1;
|
|
|
|
tunnel_cfg.encap_rcv = bareudp_udp_encap_recv;
|
|
|
|
tunnel_cfg.encap_err_lookup = bareudp_err_lookup;
|
|
|
|
tunnel_cfg.encap_destroy = NULL;
|
|
|
|
setup_udp_tunnel_sock(bareudp->net, sock, &tunnel_cfg);
|
|
|
|
|
|
|
|
rcu_assign_pointer(bareudp->sock, sock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct bareudp_dev *bareudp = netdev_priv(dev);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = bareudp_socket_create(bareudp, bareudp->port);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bareudp_sock_release(struct bareudp_dev *bareudp)
|
|
|
|
{
|
|
|
|
struct socket *sock;
|
|
|
|
|
|
|
|
sock = bareudp->sock;
|
|
|
|
rcu_assign_pointer(bareudp->sock, NULL);
|
|
|
|
synchronize_net();
|
|
|
|
udp_tunnel_sock_release(sock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp_stop(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct bareudp_dev *bareudp = netdev_priv(dev);
|
|
|
|
|
|
|
|
bareudp_sock_release(bareudp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,
|
|
|
|
struct bareudp_dev *bareudp,
|
|
|
|
const struct ip_tunnel_info *info)
|
|
|
|
{
|
ip_tunnel: convert __be16 tunnel flags to bitmaps
Historically, tunnel flags like TUNNEL_CSUM or TUNNEL_ERSPAN_OPT
have been defined as __be16. Now all of those 16 bits are occupied
and there's no more free space for new flags.
It can't be simply switched to a bigger container with no
adjustments to the values, since it's an explicit Endian storage,
and on LE systems (__be16)0x0001 equals to
(__be64)0x0001000000000000.
We could probably define new 64-bit flags depending on the
Endianness, i.e. (__be64)0x0001 on BE and (__be64)0x00010000... on
LE, but that would introduce an Endianness dependency and spawn a
ton of Sparse warnings. To mitigate them, all of those places which
were adjusted with this change would be touched anyway, so why not
define stuff properly if there's no choice.
Define IP_TUNNEL_*_BIT counterparts as a bit number instead of the
value already coded and a fistful of <16 <-> bitmap> converters and
helpers. The two flags which have a different bit position are
SIT_ISATAP_BIT and VTI_ISVTI_BIT, as they were defined not as
__cpu_to_be16(), but as (__force __be16), i.e. had different
positions on LE and BE. Now they both have strongly defined places.
Change all __be16 fields which were used to store those flags, to
IP_TUNNEL_DECLARE_FLAGS() -> DECLARE_BITMAP(__IP_TUNNEL_FLAG_NUM) ->
unsigned long[1] for now, and replace all TUNNEL_* occurrences to
their bitmap counterparts. Use the converters in the places which talk
to the userspace, hardware (NFP) or other hosts (GRE header). The rest
must explicitly use the new flags only. This must be done at once,
otherwise there will be too many conversions throughout the code in
the intermediate commits.
Finally, disable the old __be16 flags for use in the kernel code
(except for the two 'irregular' flags mentioned above), to prevent
any accidental (mis)use of them. For the userspace, nothing is
changed, only additions were made.
Most noticeable bloat-o-meter difference (.text):
vmlinux: 307/-1 (306)
gre.ko: 62/0 (62)
ip_gre.ko: 941/-217 (724) [*]
ip_tunnel.ko: 390/-900 (-510) [**]
ip_vti.ko: 138/0 (138)
ip6_gre.ko: 534/-18 (516) [*]
ip6_tunnel.ko: 118/-10 (108)
[*] gre_flags_to_tnl_flags() grew, but still is inlined
[**] ip_tunnel_find() got uninlined, hence such decrease
The average code size increase in non-extreme case is 100-200 bytes
per module, mostly due to sizeof(long) > sizeof(__be16), as
%__IP_TUNNEL_FLAG_NUM is less than %BITS_PER_LONG and the compilers
are able to expand the majority of bitmap_*() calls here into direct
operations on scalars.
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-03-27 08:23:53 -07:00
|
|
|
bool udp_sum = test_bit(IP_TUNNEL_CSUM_BIT, info->key.tun_flags);
|
2020-02-23 22:27:50 -07:00
|
|
|
bool xnet = !net_eq(bareudp->net, dev_net(bareudp->dev));
|
|
|
|
bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
|
|
|
|
struct socket *sock = rcu_dereference(bareudp->sock);
|
|
|
|
const struct ip_tunnel_key *key = &info->key;
|
|
|
|
struct rtable *rt;
|
|
|
|
__be16 sport, df;
|
|
|
|
int min_headroom;
|
|
|
|
__u8 tos, ttl;
|
|
|
|
__be32 saddr;
|
|
|
|
int err;
|
|
|
|
|
2024-09-11 02:21:05 -07:00
|
|
|
if (!skb_vlan_inet_prepare(skb, skb->protocol != htons(ETH_P_TEB)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
if (!sock)
|
|
|
|
return -ESHUTDOWN;
|
|
|
|
|
2023-10-25 02:44:41 -07:00
|
|
|
sport = udp_flow_src_port(bareudp->net, skb,
|
|
|
|
bareudp->sport_min, USHRT_MAX,
|
|
|
|
true);
|
2023-10-16 00:15:22 -07:00
|
|
|
rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, 0, &saddr, &info->key,
|
2023-10-25 02:44:41 -07:00
|
|
|
sport, bareudp->port, key->tos,
|
2023-10-16 00:15:22 -07:00
|
|
|
use_cache ?
|
|
|
|
(struct dst_cache *)&info->dst_cache : NULL);
|
2020-02-23 22:27:50 -07:00
|
|
|
|
|
|
|
if (IS_ERR(rt))
|
|
|
|
return PTR_ERR(rt);
|
|
|
|
|
|
|
|
skb_tunnel_check_pmtu(skb, &rt->dst,
|
tunnels: PMTU discovery support for directly bridged IP packets
It's currently possible to bridge Ethernet tunnels carrying IP
packets directly to external interfaces without assigning them
addresses and routes on the bridged network itself: this is the case
for UDP tunnels bridged with a standard bridge or by Open vSwitch.
PMTU discovery is currently broken with those configurations, because
the encapsulation effectively decreases the MTU of the link, and
while we are able to account for this using PMTU discovery on the
lower layer, we don't have a way to relay ICMP or ICMPv6 messages
needed by the sender, because we don't have valid routes to it.
On the other hand, as a tunnel endpoint, we can't fragment packets
as a general approach: this is for instance clearly forbidden for
VXLAN by RFC 7348, section 4.3:
VTEPs MUST NOT fragment VXLAN packets. Intermediate routers may
fragment encapsulated VXLAN packets due to the larger frame size.
The destination VTEP MAY silently discard such VXLAN fragments.
The same paragraph recommends that the MTU over the physical network
accomodates for encapsulations, but this isn't a practical option for
complex topologies, especially for typical Open vSwitch use cases.
Further, it states that:
Other techniques like Path MTU discovery (see [RFC1191] and
[RFC1981]) MAY be used to address this requirement as well.
Now, PMTU discovery already works for routed interfaces, we get
route exceptions created by the encapsulation device as they receive
ICMP Fragmentation Needed and ICMPv6 Packet Too Big messages, and
we already rebuild those messages with the appropriate MTU and route
them back to the sender.
Add the missing bits for bridged cases:
- checks in skb_tunnel_check_pmtu() to understand if it's appropriate
to trigger a reply according to RFC 1122 section 3.2.2 for ICMP and
RFC 4443 section 2.4 for ICMPv6. This function is already called by
UDP tunnels
- a new function generating those ICMP or ICMPv6 replies. We can't
reuse icmp_send() and icmp6_send() as we don't see the sender as a
valid destination. This doesn't need to be generic, as we don't
cover any other type of ICMP errors given that we only provide an
encapsulation function to the sender
While at it, make the MTU check in skb_tunnel_check_pmtu() accurate:
we might receive GSO buffers here, and the passed headroom already
includes the inner MAC length, so we don't have to account for it
a second time (that would imply three MAC headers on the wire, but
there are just two).
This issue became visible while bridging IPv6 packets with 4500 bytes
of payload over GENEVE using IPv4 with a PMTU of 4000. Given the 50
bytes of encapsulation headroom, we would advertise MTU as 3950, and
we would reject fragmented IPv6 datagrams of 3958 bytes size on the
wire. We're exclusively dealing with network MTU here, though, so we
could get Ethernet frames up to 3964 octets in that case.
v2:
- moved skb_tunnel_check_pmtu() to ip_tunnel_core.c (David Ahern)
- split IPv4/IPv6 functions (David Ahern)
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-03 22:53:43 -07:00
|
|
|
BAREUDP_IPV4_HLEN + info->options_len, false);
|
2020-02-23 22:27:50 -07:00
|
|
|
|
|
|
|
tos = ip_tunnel_ecn_encap(key->tos, ip_hdr(skb), skb);
|
|
|
|
ttl = key->ttl;
|
ip_tunnel: convert __be16 tunnel flags to bitmaps
Historically, tunnel flags like TUNNEL_CSUM or TUNNEL_ERSPAN_OPT
have been defined as __be16. Now all of those 16 bits are occupied
and there's no more free space for new flags.
It can't be simply switched to a bigger container with no
adjustments to the values, since it's an explicit Endian storage,
and on LE systems (__be16)0x0001 equals to
(__be64)0x0001000000000000.
We could probably define new 64-bit flags depending on the
Endianness, i.e. (__be64)0x0001 on BE and (__be64)0x00010000... on
LE, but that would introduce an Endianness dependency and spawn a
ton of Sparse warnings. To mitigate them, all of those places which
were adjusted with this change would be touched anyway, so why not
define stuff properly if there's no choice.
Define IP_TUNNEL_*_BIT counterparts as a bit number instead of the
value already coded and a fistful of <16 <-> bitmap> converters and
helpers. The two flags which have a different bit position are
SIT_ISATAP_BIT and VTI_ISVTI_BIT, as they were defined not as
__cpu_to_be16(), but as (__force __be16), i.e. had different
positions on LE and BE. Now they both have strongly defined places.
Change all __be16 fields which were used to store those flags, to
IP_TUNNEL_DECLARE_FLAGS() -> DECLARE_BITMAP(__IP_TUNNEL_FLAG_NUM) ->
unsigned long[1] for now, and replace all TUNNEL_* occurrences to
their bitmap counterparts. Use the converters in the places which talk
to the userspace, hardware (NFP) or other hosts (GRE header). The rest
must explicitly use the new flags only. This must be done at once,
otherwise there will be too many conversions throughout the code in
the intermediate commits.
Finally, disable the old __be16 flags for use in the kernel code
(except for the two 'irregular' flags mentioned above), to prevent
any accidental (mis)use of them. For the userspace, nothing is
changed, only additions were made.
Most noticeable bloat-o-meter difference (.text):
vmlinux: 307/-1 (306)
gre.ko: 62/0 (62)
ip_gre.ko: 941/-217 (724) [*]
ip_tunnel.ko: 390/-900 (-510) [**]
ip_vti.ko: 138/0 (138)
ip6_gre.ko: 534/-18 (516) [*]
ip6_tunnel.ko: 118/-10 (108)
[*] gre_flags_to_tnl_flags() grew, but still is inlined
[**] ip_tunnel_find() got uninlined, hence such decrease
The average code size increase in non-extreme case is 100-200 bytes
per module, mostly due to sizeof(long) > sizeof(__be16), as
%__IP_TUNNEL_FLAG_NUM is less than %BITS_PER_LONG and the compilers
are able to expand the majority of bitmap_*() calls here into direct
operations on scalars.
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-03-27 08:23:53 -07:00
|
|
|
df = test_bit(IP_TUNNEL_DONT_FRAGMENT_BIT, key->tun_flags) ?
|
|
|
|
htons(IP_DF) : 0;
|
2020-02-23 22:27:50 -07:00
|
|
|
skb_scrub_packet(skb, xnet);
|
|
|
|
|
2020-02-24 15:40:54 -07:00
|
|
|
err = -ENOSPC;
|
2020-02-23 22:27:50 -07:00
|
|
|
if (!skb_pull(skb, skb_network_offset(skb)))
|
|
|
|
goto free_dst;
|
|
|
|
|
|
|
|
min_headroom = LL_RESERVED_SPACE(rt->dst.dev) + rt->dst.header_len +
|
|
|
|
BAREUDP_BASE_HLEN + info->options_len + sizeof(struct iphdr);
|
|
|
|
|
|
|
|
err = skb_cow_head(skb, min_headroom);
|
|
|
|
if (unlikely(err))
|
|
|
|
goto free_dst;
|
|
|
|
|
|
|
|
err = udp_tunnel_handle_offloads(skb, udp_sum);
|
|
|
|
if (err)
|
|
|
|
goto free_dst;
|
|
|
|
|
|
|
|
skb_set_inner_protocol(skb, bareudp->ethertype);
|
|
|
|
udp_tunnel_xmit_skb(rt, sock->sk, skb, saddr, info->key.u.ipv4.dst,
|
|
|
|
tos, ttl, df, sport, bareudp->port,
|
|
|
|
!net_eq(bareudp->net, dev_net(bareudp->dev)),
|
ip_tunnel: convert __be16 tunnel flags to bitmaps
Historically, tunnel flags like TUNNEL_CSUM or TUNNEL_ERSPAN_OPT
have been defined as __be16. Now all of those 16 bits are occupied
and there's no more free space for new flags.
It can't be simply switched to a bigger container with no
adjustments to the values, since it's an explicit Endian storage,
and on LE systems (__be16)0x0001 equals to
(__be64)0x0001000000000000.
We could probably define new 64-bit flags depending on the
Endianness, i.e. (__be64)0x0001 on BE and (__be64)0x00010000... on
LE, but that would introduce an Endianness dependency and spawn a
ton of Sparse warnings. To mitigate them, all of those places which
were adjusted with this change would be touched anyway, so why not
define stuff properly if there's no choice.
Define IP_TUNNEL_*_BIT counterparts as a bit number instead of the
value already coded and a fistful of <16 <-> bitmap> converters and
helpers. The two flags which have a different bit position are
SIT_ISATAP_BIT and VTI_ISVTI_BIT, as they were defined not as
__cpu_to_be16(), but as (__force __be16), i.e. had different
positions on LE and BE. Now they both have strongly defined places.
Change all __be16 fields which were used to store those flags, to
IP_TUNNEL_DECLARE_FLAGS() -> DECLARE_BITMAP(__IP_TUNNEL_FLAG_NUM) ->
unsigned long[1] for now, and replace all TUNNEL_* occurrences to
their bitmap counterparts. Use the converters in the places which talk
to the userspace, hardware (NFP) or other hosts (GRE header). The rest
must explicitly use the new flags only. This must be done at once,
otherwise there will be too many conversions throughout the code in
the intermediate commits.
Finally, disable the old __be16 flags for use in the kernel code
(except for the two 'irregular' flags mentioned above), to prevent
any accidental (mis)use of them. For the userspace, nothing is
changed, only additions were made.
Most noticeable bloat-o-meter difference (.text):
vmlinux: 307/-1 (306)
gre.ko: 62/0 (62)
ip_gre.ko: 941/-217 (724) [*]
ip_tunnel.ko: 390/-900 (-510) [**]
ip_vti.ko: 138/0 (138)
ip6_gre.ko: 534/-18 (516) [*]
ip6_tunnel.ko: 118/-10 (108)
[*] gre_flags_to_tnl_flags() grew, but still is inlined
[**] ip_tunnel_find() got uninlined, hence such decrease
The average code size increase in non-extreme case is 100-200 bytes
per module, mostly due to sizeof(long) > sizeof(__be16), as
%__IP_TUNNEL_FLAG_NUM is less than %BITS_PER_LONG and the compilers
are able to expand the majority of bitmap_*() calls here into direct
operations on scalars.
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-03-27 08:23:53 -07:00
|
|
|
!test_bit(IP_TUNNEL_CSUM_BIT,
|
|
|
|
info->key.tun_flags));
|
2020-02-23 22:27:50 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
free_dst:
|
|
|
|
dst_release(&rt->dst);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
|
|
|
|
struct bareudp_dev *bareudp,
|
|
|
|
const struct ip_tunnel_info *info)
|
|
|
|
{
|
ip_tunnel: convert __be16 tunnel flags to bitmaps
Historically, tunnel flags like TUNNEL_CSUM or TUNNEL_ERSPAN_OPT
have been defined as __be16. Now all of those 16 bits are occupied
and there's no more free space for new flags.
It can't be simply switched to a bigger container with no
adjustments to the values, since it's an explicit Endian storage,
and on LE systems (__be16)0x0001 equals to
(__be64)0x0001000000000000.
We could probably define new 64-bit flags depending on the
Endianness, i.e. (__be64)0x0001 on BE and (__be64)0x00010000... on
LE, but that would introduce an Endianness dependency and spawn a
ton of Sparse warnings. To mitigate them, all of those places which
were adjusted with this change would be touched anyway, so why not
define stuff properly if there's no choice.
Define IP_TUNNEL_*_BIT counterparts as a bit number instead of the
value already coded and a fistful of <16 <-> bitmap> converters and
helpers. The two flags which have a different bit position are
SIT_ISATAP_BIT and VTI_ISVTI_BIT, as they were defined not as
__cpu_to_be16(), but as (__force __be16), i.e. had different
positions on LE and BE. Now they both have strongly defined places.
Change all __be16 fields which were used to store those flags, to
IP_TUNNEL_DECLARE_FLAGS() -> DECLARE_BITMAP(__IP_TUNNEL_FLAG_NUM) ->
unsigned long[1] for now, and replace all TUNNEL_* occurrences to
their bitmap counterparts. Use the converters in the places which talk
to the userspace, hardware (NFP) or other hosts (GRE header). The rest
must explicitly use the new flags only. This must be done at once,
otherwise there will be too many conversions throughout the code in
the intermediate commits.
Finally, disable the old __be16 flags for use in the kernel code
(except for the two 'irregular' flags mentioned above), to prevent
any accidental (mis)use of them. For the userspace, nothing is
changed, only additions were made.
Most noticeable bloat-o-meter difference (.text):
vmlinux: 307/-1 (306)
gre.ko: 62/0 (62)
ip_gre.ko: 941/-217 (724) [*]
ip_tunnel.ko: 390/-900 (-510) [**]
ip_vti.ko: 138/0 (138)
ip6_gre.ko: 534/-18 (516) [*]
ip6_tunnel.ko: 118/-10 (108)
[*] gre_flags_to_tnl_flags() grew, but still is inlined
[**] ip_tunnel_find() got uninlined, hence such decrease
The average code size increase in non-extreme case is 100-200 bytes
per module, mostly due to sizeof(long) > sizeof(__be16), as
%__IP_TUNNEL_FLAG_NUM is less than %BITS_PER_LONG and the compilers
are able to expand the majority of bitmap_*() calls here into direct
operations on scalars.
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-03-27 08:23:53 -07:00
|
|
|
bool udp_sum = test_bit(IP_TUNNEL_CSUM_BIT, info->key.tun_flags);
|
2020-02-23 22:27:50 -07:00
|
|
|
bool xnet = !net_eq(bareudp->net, dev_net(bareudp->dev));
|
|
|
|
bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
|
|
|
|
struct socket *sock = rcu_dereference(bareudp->sock);
|
|
|
|
const struct ip_tunnel_key *key = &info->key;
|
|
|
|
struct dst_entry *dst = NULL;
|
|
|
|
struct in6_addr saddr, daddr;
|
|
|
|
int min_headroom;
|
|
|
|
__u8 prio, ttl;
|
|
|
|
__be16 sport;
|
|
|
|
int err;
|
|
|
|
|
2024-09-11 02:21:05 -07:00
|
|
|
if (!skb_vlan_inet_prepare(skb, skb->protocol != htons(ETH_P_TEB)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
if (!sock)
|
|
|
|
return -ESHUTDOWN;
|
|
|
|
|
2023-10-25 02:44:41 -07:00
|
|
|
sport = udp_flow_src_port(bareudp->net, skb,
|
|
|
|
bareudp->sport_min, USHRT_MAX,
|
|
|
|
true);
|
2023-10-20 04:55:27 -07:00
|
|
|
dst = udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, 0, &saddr,
|
2023-10-25 02:44:41 -07:00
|
|
|
key, sport, bareudp->port, key->tos,
|
2023-10-20 04:55:27 -07:00
|
|
|
use_cache ?
|
|
|
|
(struct dst_cache *) &info->dst_cache : NULL);
|
2020-02-23 22:27:50 -07:00
|
|
|
if (IS_ERR(dst))
|
|
|
|
return PTR_ERR(dst);
|
|
|
|
|
tunnels: PMTU discovery support for directly bridged IP packets
It's currently possible to bridge Ethernet tunnels carrying IP
packets directly to external interfaces without assigning them
addresses and routes on the bridged network itself: this is the case
for UDP tunnels bridged with a standard bridge or by Open vSwitch.
PMTU discovery is currently broken with those configurations, because
the encapsulation effectively decreases the MTU of the link, and
while we are able to account for this using PMTU discovery on the
lower layer, we don't have a way to relay ICMP or ICMPv6 messages
needed by the sender, because we don't have valid routes to it.
On the other hand, as a tunnel endpoint, we can't fragment packets
as a general approach: this is for instance clearly forbidden for
VXLAN by RFC 7348, section 4.3:
VTEPs MUST NOT fragment VXLAN packets. Intermediate routers may
fragment encapsulated VXLAN packets due to the larger frame size.
The destination VTEP MAY silently discard such VXLAN fragments.
The same paragraph recommends that the MTU over the physical network
accomodates for encapsulations, but this isn't a practical option for
complex topologies, especially for typical Open vSwitch use cases.
Further, it states that:
Other techniques like Path MTU discovery (see [RFC1191] and
[RFC1981]) MAY be used to address this requirement as well.
Now, PMTU discovery already works for routed interfaces, we get
route exceptions created by the encapsulation device as they receive
ICMP Fragmentation Needed and ICMPv6 Packet Too Big messages, and
we already rebuild those messages with the appropriate MTU and route
them back to the sender.
Add the missing bits for bridged cases:
- checks in skb_tunnel_check_pmtu() to understand if it's appropriate
to trigger a reply according to RFC 1122 section 3.2.2 for ICMP and
RFC 4443 section 2.4 for ICMPv6. This function is already called by
UDP tunnels
- a new function generating those ICMP or ICMPv6 replies. We can't
reuse icmp_send() and icmp6_send() as we don't see the sender as a
valid destination. This doesn't need to be generic, as we don't
cover any other type of ICMP errors given that we only provide an
encapsulation function to the sender
While at it, make the MTU check in skb_tunnel_check_pmtu() accurate:
we might receive GSO buffers here, and the passed headroom already
includes the inner MAC length, so we don't have to account for it
a second time (that would imply three MAC headers on the wire, but
there are just two).
This issue became visible while bridging IPv6 packets with 4500 bytes
of payload over GENEVE using IPv4 with a PMTU of 4000. Given the 50
bytes of encapsulation headroom, we would advertise MTU as 3950, and
we would reject fragmented IPv6 datagrams of 3958 bytes size on the
wire. We're exclusively dealing with network MTU here, though, so we
could get Ethernet frames up to 3964 octets in that case.
v2:
- moved skb_tunnel_check_pmtu() to ip_tunnel_core.c (David Ahern)
- split IPv4/IPv6 functions (David Ahern)
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-08-03 22:53:43 -07:00
|
|
|
skb_tunnel_check_pmtu(skb, dst, BAREUDP_IPV6_HLEN + info->options_len,
|
|
|
|
false);
|
2020-02-23 22:27:50 -07:00
|
|
|
|
|
|
|
prio = ip_tunnel_ecn_encap(key->tos, ip_hdr(skb), skb);
|
|
|
|
ttl = key->ttl;
|
|
|
|
|
|
|
|
skb_scrub_packet(skb, xnet);
|
|
|
|
|
2020-02-24 15:40:54 -07:00
|
|
|
err = -ENOSPC;
|
2020-02-23 22:27:50 -07:00
|
|
|
if (!skb_pull(skb, skb_network_offset(skb)))
|
|
|
|
goto free_dst;
|
|
|
|
|
|
|
|
min_headroom = LL_RESERVED_SPACE(dst->dev) + dst->header_len +
|
2020-12-28 08:21:46 -07:00
|
|
|
BAREUDP_BASE_HLEN + info->options_len + sizeof(struct ipv6hdr);
|
2020-02-23 22:27:50 -07:00
|
|
|
|
|
|
|
err = skb_cow_head(skb, min_headroom);
|
|
|
|
if (unlikely(err))
|
|
|
|
goto free_dst;
|
|
|
|
|
|
|
|
err = udp_tunnel_handle_offloads(skb, udp_sum);
|
|
|
|
if (err)
|
|
|
|
goto free_dst;
|
|
|
|
|
|
|
|
daddr = info->key.u.ipv6.dst;
|
|
|
|
udp_tunnel6_xmit_skb(dst, sock->sk, skb, dev,
|
|
|
|
&saddr, &daddr, prio, ttl,
|
|
|
|
info->key.label, sport, bareudp->port,
|
ip_tunnel: convert __be16 tunnel flags to bitmaps
Historically, tunnel flags like TUNNEL_CSUM or TUNNEL_ERSPAN_OPT
have been defined as __be16. Now all of those 16 bits are occupied
and there's no more free space for new flags.
It can't be simply switched to a bigger container with no
adjustments to the values, since it's an explicit Endian storage,
and on LE systems (__be16)0x0001 equals to
(__be64)0x0001000000000000.
We could probably define new 64-bit flags depending on the
Endianness, i.e. (__be64)0x0001 on BE and (__be64)0x00010000... on
LE, but that would introduce an Endianness dependency and spawn a
ton of Sparse warnings. To mitigate them, all of those places which
were adjusted with this change would be touched anyway, so why not
define stuff properly if there's no choice.
Define IP_TUNNEL_*_BIT counterparts as a bit number instead of the
value already coded and a fistful of <16 <-> bitmap> converters and
helpers. The two flags which have a different bit position are
SIT_ISATAP_BIT and VTI_ISVTI_BIT, as they were defined not as
__cpu_to_be16(), but as (__force __be16), i.e. had different
positions on LE and BE. Now they both have strongly defined places.
Change all __be16 fields which were used to store those flags, to
IP_TUNNEL_DECLARE_FLAGS() -> DECLARE_BITMAP(__IP_TUNNEL_FLAG_NUM) ->
unsigned long[1] for now, and replace all TUNNEL_* occurrences to
their bitmap counterparts. Use the converters in the places which talk
to the userspace, hardware (NFP) or other hosts (GRE header). The rest
must explicitly use the new flags only. This must be done at once,
otherwise there will be too many conversions throughout the code in
the intermediate commits.
Finally, disable the old __be16 flags for use in the kernel code
(except for the two 'irregular' flags mentioned above), to prevent
any accidental (mis)use of them. For the userspace, nothing is
changed, only additions were made.
Most noticeable bloat-o-meter difference (.text):
vmlinux: 307/-1 (306)
gre.ko: 62/0 (62)
ip_gre.ko: 941/-217 (724) [*]
ip_tunnel.ko: 390/-900 (-510) [**]
ip_vti.ko: 138/0 (138)
ip6_gre.ko: 534/-18 (516) [*]
ip6_tunnel.ko: 118/-10 (108)
[*] gre_flags_to_tnl_flags() grew, but still is inlined
[**] ip_tunnel_find() got uninlined, hence such decrease
The average code size increase in non-extreme case is 100-200 bytes
per module, mostly due to sizeof(long) > sizeof(__be16), as
%__IP_TUNNEL_FLAG_NUM is less than %BITS_PER_LONG and the compilers
are able to expand the majority of bitmap_*() calls here into direct
operations on scalars.
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2024-03-27 08:23:53 -07:00
|
|
|
!test_bit(IP_TUNNEL_CSUM_BIT,
|
|
|
|
info->key.tun_flags));
|
2020-02-23 22:27:50 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
free_dst:
|
|
|
|
dst_release(dst);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-07-25 06:06:47 -07:00
|
|
|
static bool bareudp_proto_valid(struct bareudp_dev *bareudp, __be16 proto)
|
|
|
|
{
|
|
|
|
if (bareudp->ethertype == proto)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!bareudp->multi_proto_mode)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (bareudp->ethertype == htons(ETH_P_MPLS_UC) &&
|
|
|
|
proto == htons(ETH_P_MPLS_MC))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (bareudp->ethertype == htons(ETH_P_IP) &&
|
|
|
|
proto == htons(ETH_P_IPV6))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
static netdev_tx_t bareudp_xmit(struct sk_buff *skb, struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct bareudp_dev *bareudp = netdev_priv(dev);
|
|
|
|
struct ip_tunnel_info *info = NULL;
|
|
|
|
int err;
|
|
|
|
|
2020-07-25 06:06:47 -07:00
|
|
|
if (!bareudp_proto_valid(bareudp, skb->protocol)) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto tx_error;
|
2020-02-23 22:27:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
info = skb_tunnel_info(skb);
|
|
|
|
if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX))) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto tx_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2022-03-14 23:26:18 -07:00
|
|
|
if (ipv6_mod_enabled() && info->mode & IP_TUNNEL_INFO_IPV6)
|
2020-02-23 22:27:50 -07:00
|
|
|
err = bareudp6_xmit_skb(skb, dev, bareudp, info);
|
|
|
|
else
|
|
|
|
err = bareudp_xmit_skb(skb, dev, bareudp, info);
|
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (likely(!err))
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
tx_error:
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
|
|
|
|
if (err == -ELOOP)
|
2024-08-30 08:31:07 -07:00
|
|
|
DEV_STATS_INC(dev, collisions);
|
2020-02-23 22:27:50 -07:00
|
|
|
else if (err == -ENETUNREACH)
|
2024-08-30 08:31:07 -07:00
|
|
|
DEV_STATS_INC(dev, tx_carrier_errors);
|
2020-02-23 22:27:50 -07:00
|
|
|
|
2024-08-30 08:31:07 -07:00
|
|
|
DEV_STATS_INC(dev, tx_errors);
|
2020-02-23 22:27:50 -07:00
|
|
|
return NETDEV_TX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp_fill_metadata_dst(struct net_device *dev,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct ip_tunnel_info *info = skb_tunnel_info(skb);
|
|
|
|
struct bareudp_dev *bareudp = netdev_priv(dev);
|
|
|
|
bool use_cache;
|
2023-10-25 02:44:41 -07:00
|
|
|
__be16 sport;
|
2020-02-23 22:27:50 -07:00
|
|
|
|
|
|
|
use_cache = ip_tunnel_dst_cache_usable(skb, info);
|
2023-10-25 02:44:41 -07:00
|
|
|
sport = udp_flow_src_port(bareudp->net, skb,
|
|
|
|
bareudp->sport_min, USHRT_MAX,
|
|
|
|
true);
|
2020-02-23 22:27:50 -07:00
|
|
|
|
2022-03-14 23:26:18 -07:00
|
|
|
if (!ipv6_mod_enabled() || ip_tunnel_info_af(info) == AF_INET) {
|
2020-02-23 22:27:50 -07:00
|
|
|
struct rtable *rt;
|
|
|
|
__be32 saddr;
|
|
|
|
|
2023-10-16 00:15:22 -07:00
|
|
|
rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, 0, &saddr,
|
2023-10-25 02:44:41 -07:00
|
|
|
&info->key, sport, bareudp->port,
|
|
|
|
info->key.tos,
|
2023-10-16 00:15:22 -07:00
|
|
|
use_cache ? &info->dst_cache : NULL);
|
2020-02-23 22:27:50 -07:00
|
|
|
if (IS_ERR(rt))
|
|
|
|
return PTR_ERR(rt);
|
|
|
|
|
|
|
|
ip_rt_put(rt);
|
|
|
|
info->key.u.ipv4.src = saddr;
|
|
|
|
} else if (ip_tunnel_info_af(info) == AF_INET6) {
|
|
|
|
struct dst_entry *dst;
|
|
|
|
struct in6_addr saddr;
|
|
|
|
struct socket *sock = rcu_dereference(bareudp->sock);
|
|
|
|
|
2023-10-20 04:55:25 -07:00
|
|
|
dst = udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock,
|
2023-10-20 04:55:27 -07:00
|
|
|
0, &saddr, &info->key,
|
2023-10-25 02:44:41 -07:00
|
|
|
sport, bareudp->port, info->key.tos,
|
2023-10-20 04:55:27 -07:00
|
|
|
use_cache ? &info->dst_cache : NULL);
|
2020-02-23 22:27:50 -07:00
|
|
|
if (IS_ERR(dst))
|
|
|
|
return PTR_ERR(dst);
|
|
|
|
|
|
|
|
dst_release(dst);
|
|
|
|
info->key.u.ipv6.src = saddr;
|
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2023-10-25 02:44:41 -07:00
|
|
|
info->key.tp_src = sport;
|
2020-02-23 22:27:50 -07:00
|
|
|
info->key.tp_dst = bareudp->port;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct net_device_ops bareudp_netdev_ops = {
|
|
|
|
.ndo_init = bareudp_init,
|
|
|
|
.ndo_uninit = bareudp_uninit,
|
|
|
|
.ndo_open = bareudp_open,
|
|
|
|
.ndo_stop = bareudp_stop,
|
|
|
|
.ndo_start_xmit = bareudp_xmit,
|
|
|
|
.ndo_fill_metadata_dst = bareudp_fill_metadata_dst,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct nla_policy bareudp_policy[IFLA_BAREUDP_MAX + 1] = {
|
|
|
|
[IFLA_BAREUDP_PORT] = { .type = NLA_U16 },
|
|
|
|
[IFLA_BAREUDP_ETHERTYPE] = { .type = NLA_U16 },
|
|
|
|
[IFLA_BAREUDP_SRCPORT_MIN] = { .type = NLA_U16 },
|
2020-02-23 22:28:35 -07:00
|
|
|
[IFLA_BAREUDP_MULTIPROTO_MODE] = { .type = NLA_FLAG },
|
2020-02-23 22:27:50 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Info for udev, that this is a virtual tunnel endpoint */
|
2020-12-02 05:23:24 -07:00
|
|
|
static const struct device_type bareudp_type = {
|
2020-02-23 22:27:50 -07:00
|
|
|
.name = "bareudp",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialize the device structure. */
|
|
|
|
static void bareudp_setup(struct net_device *dev)
|
|
|
|
{
|
|
|
|
dev->netdev_ops = &bareudp_netdev_ops;
|
|
|
|
dev->needs_free_netdev = true;
|
|
|
|
SET_NETDEV_DEVTYPE(dev, &bareudp_type);
|
2021-01-15 02:47:47 -07:00
|
|
|
dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_FRAGLIST;
|
2020-02-23 22:27:50 -07:00
|
|
|
dev->features |= NETIF_F_RXCSUM;
|
|
|
|
dev->features |= NETIF_F_GSO_SOFTWARE;
|
2021-01-15 02:47:47 -07:00
|
|
|
dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_FRAGLIST;
|
|
|
|
dev->hw_features |= NETIF_F_RXCSUM;
|
2020-02-23 22:27:50 -07:00
|
|
|
dev->hw_features |= NETIF_F_GSO_SOFTWARE;
|
|
|
|
dev->hard_header_len = 0;
|
|
|
|
dev->addr_len = 0;
|
|
|
|
dev->mtu = ETH_DATA_LEN;
|
|
|
|
dev->min_mtu = IPV4_MIN_MTU;
|
|
|
|
dev->max_mtu = IP_MAX_MTU - BAREUDP_BASE_HLEN;
|
|
|
|
dev->type = ARPHRD_NONE;
|
|
|
|
netif_keep_dst(dev);
|
|
|
|
dev->priv_flags |= IFF_NO_QUEUE;
|
2024-08-29 05:33:37 -07:00
|
|
|
dev->lltx = true;
|
2020-02-23 22:27:50 -07:00
|
|
|
dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
|
2024-02-29 10:04:23 -07:00
|
|
|
dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS;
|
2020-02-23 22:27:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp_validate(struct nlattr *tb[], struct nlattr *data[],
|
|
|
|
struct netlink_ext_ack *extack)
|
|
|
|
{
|
|
|
|
if (!data) {
|
|
|
|
NL_SET_ERR_MSG(extack,
|
|
|
|
"Not enough attributes provided to perform the operation");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-07 18:19:17 -07:00
|
|
|
static int bareudp2info(struct nlattr *data[], struct bareudp_conf *conf,
|
|
|
|
struct netlink_ext_ack *extack)
|
2020-02-23 22:27:50 -07:00
|
|
|
{
|
2020-06-15 22:48:58 -07:00
|
|
|
memset(conf, 0, sizeof(*conf));
|
|
|
|
|
2020-03-07 18:19:17 -07:00
|
|
|
if (!data[IFLA_BAREUDP_PORT]) {
|
|
|
|
NL_SET_ERR_MSG(extack, "port not specified");
|
2020-02-23 22:27:50 -07:00
|
|
|
return -EINVAL;
|
2020-03-07 18:19:17 -07:00
|
|
|
}
|
|
|
|
if (!data[IFLA_BAREUDP_ETHERTYPE]) {
|
|
|
|
NL_SET_ERR_MSG(extack, "ethertype not specified");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2020-02-23 22:27:50 -07:00
|
|
|
|
2021-10-28 11:24:53 -07:00
|
|
|
conf->port = nla_get_u16(data[IFLA_BAREUDP_PORT]);
|
|
|
|
conf->ethertype = nla_get_u16(data[IFLA_BAREUDP_ETHERTYPE]);
|
2020-02-23 22:27:50 -07:00
|
|
|
|
|
|
|
if (data[IFLA_BAREUDP_SRCPORT_MIN])
|
|
|
|
conf->sport_min = nla_get_u16(data[IFLA_BAREUDP_SRCPORT_MIN]);
|
|
|
|
|
2020-06-17 10:00:23 -07:00
|
|
|
if (data[IFLA_BAREUDP_MULTIPROTO_MODE])
|
|
|
|
conf->multi_proto_mode = true;
|
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bareudp_dev *bareudp_find_dev(struct bareudp_net *bn,
|
|
|
|
const struct bareudp_conf *conf)
|
|
|
|
{
|
|
|
|
struct bareudp_dev *bareudp, *t = NULL;
|
|
|
|
|
|
|
|
list_for_each_entry(bareudp, &bn->bareudp_list, next) {
|
|
|
|
if (conf->port == bareudp->port)
|
|
|
|
t = bareudp;
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp_configure(struct net *net, struct net_device *dev,
|
2021-12-13 11:17:17 -07:00
|
|
|
struct bareudp_conf *conf,
|
|
|
|
struct netlink_ext_ack *extack)
|
2020-02-23 22:27:50 -07:00
|
|
|
{
|
|
|
|
struct bareudp_net *bn = net_generic(net, bareudp_net_id);
|
|
|
|
struct bareudp_dev *t, *bareudp = netdev_priv(dev);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
bareudp->net = net;
|
|
|
|
bareudp->dev = dev;
|
|
|
|
t = bareudp_find_dev(bn, conf);
|
2021-12-13 11:17:17 -07:00
|
|
|
if (t) {
|
|
|
|
NL_SET_ERR_MSG(extack, "Another bareudp device using the same port already exists");
|
2020-02-23 22:27:50 -07:00
|
|
|
return -EBUSY;
|
2021-12-13 11:17:17 -07:00
|
|
|
}
|
2020-02-23 22:27:50 -07:00
|
|
|
|
2020-02-23 22:28:35 -07:00
|
|
|
if (conf->multi_proto_mode &&
|
|
|
|
(conf->ethertype != htons(ETH_P_MPLS_UC) &&
|
2021-12-13 11:17:17 -07:00
|
|
|
conf->ethertype != htons(ETH_P_IP))) {
|
|
|
|
NL_SET_ERR_MSG(extack, "Cannot set multiproto mode for this ethertype (only IPv4 and unicast MPLS are supported)");
|
2020-02-23 22:28:35 -07:00
|
|
|
return -EINVAL;
|
2021-12-13 11:17:17 -07:00
|
|
|
}
|
2020-02-23 22:28:35 -07:00
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
bareudp->port = conf->port;
|
|
|
|
bareudp->ethertype = conf->ethertype;
|
|
|
|
bareudp->sport_min = conf->sport_min;
|
2020-02-23 22:28:35 -07:00
|
|
|
bareudp->multi_proto_mode = conf->multi_proto_mode;
|
2020-06-28 10:48:23 -07:00
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
err = register_netdevice(dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
list_add(&bareudp->next, &bn->bareudp_list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp_link_config(struct net_device *dev,
|
|
|
|
struct nlattr *tb[])
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (tb[IFLA_MTU]) {
|
|
|
|
err = dev_set_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-05 12:07:25 -07:00
|
|
|
static void bareudp_dellink(struct net_device *dev, struct list_head *head)
|
|
|
|
{
|
|
|
|
struct bareudp_dev *bareudp = netdev_priv(dev);
|
|
|
|
|
|
|
|
list_del(&bareudp->next);
|
|
|
|
unregister_netdevice_queue(dev, head);
|
|
|
|
}
|
|
|
|
|
2020-02-23 22:27:50 -07:00
|
|
|
static int bareudp_newlink(struct net *net, struct net_device *dev,
|
|
|
|
struct nlattr *tb[], struct nlattr *data[],
|
|
|
|
struct netlink_ext_ack *extack)
|
|
|
|
{
|
|
|
|
struct bareudp_conf conf;
|
|
|
|
int err;
|
|
|
|
|
2020-03-07 18:19:17 -07:00
|
|
|
err = bareudp2info(data, &conf, extack);
|
2020-02-23 22:27:50 -07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2021-12-13 11:17:17 -07:00
|
|
|
err = bareudp_configure(net, dev, &conf, extack);
|
2020-02-23 22:27:50 -07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = bareudp_link_config(dev, tb);
|
|
|
|
if (err)
|
2021-01-05 12:07:25 -07:00
|
|
|
goto err_unconfig;
|
2020-02-23 22:27:50 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2021-01-05 12:07:25 -07:00
|
|
|
err_unconfig:
|
2021-01-10 22:29:22 -07:00
|
|
|
bareudp_dellink(dev, NULL);
|
2021-01-05 12:07:25 -07:00
|
|
|
return err;
|
2020-02-23 22:27:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t bareudp_get_size(const struct net_device *dev)
|
|
|
|
{
|
|
|
|
return nla_total_size(sizeof(__be16)) + /* IFLA_BAREUDP_PORT */
|
|
|
|
nla_total_size(sizeof(__be16)) + /* IFLA_BAREUDP_ETHERTYPE */
|
|
|
|
nla_total_size(sizeof(__u16)) + /* IFLA_BAREUDP_SRCPORT_MIN */
|
2020-02-23 22:28:35 -07:00
|
|
|
nla_total_size(0) + /* IFLA_BAREUDP_MULTIPROTO_MODE */
|
2020-02-23 22:27:50 -07:00
|
|
|
0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bareudp_fill_info(struct sk_buff *skb, const struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct bareudp_dev *bareudp = netdev_priv(dev);
|
|
|
|
|
|
|
|
if (nla_put_be16(skb, IFLA_BAREUDP_PORT, bareudp->port))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put_be16(skb, IFLA_BAREUDP_ETHERTYPE, bareudp->ethertype))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put_u16(skb, IFLA_BAREUDP_SRCPORT_MIN, bareudp->sport_min))
|
|
|
|
goto nla_put_failure;
|
2020-02-23 22:28:35 -07:00
|
|
|
if (bareudp->multi_proto_mode &&
|
|
|
|
nla_put_flag(skb, IFLA_BAREUDP_MULTIPROTO_MODE))
|
|
|
|
goto nla_put_failure;
|
2020-02-23 22:27:50 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct rtnl_link_ops bareudp_link_ops __read_mostly = {
|
|
|
|
.kind = "bareudp",
|
|
|
|
.maxtype = IFLA_BAREUDP_MAX,
|
|
|
|
.policy = bareudp_policy,
|
|
|
|
.priv_size = sizeof(struct bareudp_dev),
|
|
|
|
.setup = bareudp_setup,
|
|
|
|
.validate = bareudp_validate,
|
|
|
|
.newlink = bareudp_newlink,
|
|
|
|
.dellink = bareudp_dellink,
|
|
|
|
.get_size = bareudp_get_size,
|
|
|
|
.fill_info = bareudp_fill_info,
|
|
|
|
};
|
|
|
|
|
|
|
|
static __net_init int bareudp_init_net(struct net *net)
|
|
|
|
{
|
|
|
|
struct bareudp_net *bn = net_generic(net, bareudp_net_id);
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&bn->bareudp_list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bareudp_destroy_tunnels(struct net *net, struct list_head *head)
|
|
|
|
{
|
|
|
|
struct bareudp_net *bn = net_generic(net, bareudp_net_id);
|
|
|
|
struct bareudp_dev *bareudp, *next;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(bareudp, next, &bn->bareudp_list, next)
|
|
|
|
unregister_netdevice_queue(bareudp->dev, head);
|
|
|
|
}
|
|
|
|
|
2024-02-06 07:43:00 -07:00
|
|
|
static void __net_exit bareudp_exit_batch_rtnl(struct list_head *net_list,
|
|
|
|
struct list_head *dev_kill_list)
|
2020-02-23 22:27:50 -07:00
|
|
|
{
|
|
|
|
struct net *net;
|
|
|
|
|
|
|
|
list_for_each_entry(net, net_list, exit_list)
|
2024-02-06 07:43:00 -07:00
|
|
|
bareudp_destroy_tunnels(net, dev_kill_list);
|
2020-02-23 22:27:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pernet_operations bareudp_net_ops = {
|
|
|
|
.init = bareudp_init_net,
|
2024-02-06 07:43:00 -07:00
|
|
|
.exit_batch_rtnl = bareudp_exit_batch_rtnl,
|
2020-02-23 22:27:50 -07:00
|
|
|
.id = &bareudp_net_id,
|
|
|
|
.size = sizeof(struct bareudp_net),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init bareudp_init_module(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = register_pernet_subsys(&bareudp_net_ops);
|
|
|
|
if (rc)
|
|
|
|
goto out1;
|
|
|
|
|
|
|
|
rc = rtnl_link_register(&bareudp_link_ops);
|
|
|
|
if (rc)
|
|
|
|
goto out2;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out2:
|
|
|
|
unregister_pernet_subsys(&bareudp_net_ops);
|
|
|
|
out1:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
late_initcall(bareudp_init_module);
|
|
|
|
|
|
|
|
static void __exit bareudp_cleanup_module(void)
|
|
|
|
{
|
|
|
|
rtnl_link_unregister(&bareudp_link_ops);
|
|
|
|
unregister_pernet_subsys(&bareudp_net_ops);
|
|
|
|
}
|
|
|
|
module_exit(bareudp_cleanup_module);
|
|
|
|
|
2020-03-07 18:19:07 -07:00
|
|
|
MODULE_ALIAS_RTNL_LINK("bareudp");
|
2020-02-23 22:27:50 -07:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Martin Varghese <martin.varghese@nokia.com>");
|
|
|
|
MODULE_DESCRIPTION("Interface driver for UDP encapsulated traffic");
|