net/ipv4/udp_tunnel_core.c
Source file repositories/reference/linux-study-clean/net/ipv4/udp_tunnel_core.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/udp_tunnel_core.c- Extension
.c- Size
- 6867 bytes
- Lines
- 276
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/errno.hlinux/socket.hlinux/kernel.hnet/dst_metadata.hnet/flow.hnet/udp.hnet/udp_tunnel.hnet/inet_dscp.h
Detected Declarations
function udp_sock_create4function sk_saddr_anyfunction setup_udp_tunnel_sockfunction udp_tunnel_push_rx_portfunction udp_tunnel_drop_rx_portfunction udp_tunnel_notify_add_rx_portfunction for_each_netdevfunction udp_tunnel_notify_del_rx_portfunction for_each_netdevfunction udp_tunnel_xmit_skbfunction udp_tunnel_sock_releaseexport udp_sock_create4export setup_udp_tunnel_sockexport udp_tunnel_push_rx_portexport udp_tunnel_drop_rx_portexport udp_tunnel_notify_add_rx_portexport udp_tunnel_notify_del_rx_portexport udp_tunnel_xmit_skbexport udp_tunnel_sock_releaseexport udp_tun_rx_dstexport udp_tunnel_dst_lookup
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/socket.h>
#include <linux/kernel.h>
#include <net/dst_metadata.h>
#include <net/flow.h>
#include <net/udp.h>
#include <net/udp_tunnel.h>
#include <net/inet_dscp.h>
int udp_sock_create4(struct net *net, struct udp_port_cfg *cfg,
struct socket **sockp)
{
int err;
struct socket *sock = NULL;
struct sockaddr_in udp_addr;
err = sock_create_kern(net, AF_INET, SOCK_DGRAM, 0, &sock);
if (err < 0)
goto error;
if (cfg->bind_ifindex) {
err = sock_bindtoindex(sock->sk, cfg->bind_ifindex, true);
if (err < 0)
goto error;
}
udp_addr.sin_family = AF_INET;
udp_addr.sin_addr = cfg->local_ip;
udp_addr.sin_port = cfg->local_udp_port;
err = kernel_bind(sock, (struct sockaddr_unsized *)&udp_addr,
sizeof(udp_addr));
if (err < 0)
goto error;
if (cfg->peer_udp_port) {
udp_addr.sin_family = AF_INET;
udp_addr.sin_addr = cfg->peer_ip;
udp_addr.sin_port = cfg->peer_udp_port;
err = kernel_connect(sock, (struct sockaddr_unsized *)&udp_addr,
sizeof(udp_addr), 0);
if (err < 0)
goto error;
}
sock->sk->sk_no_check_tx = !cfg->use_udp_checksums;
*sockp = sock;
return 0;
error:
if (sock) {
kernel_sock_shutdown(sock, SHUT_RDWR);
sock_release(sock);
}
*sockp = NULL;
return err;
}
EXPORT_SYMBOL(udp_sock_create4);
static bool sk_saddr_any(struct sock *sk)
{
#if IS_ENABLED(CONFIG_IPV6)
return ipv6_addr_any(&sk->sk_v6_rcv_saddr);
#else
return !sk->sk_rcv_saddr;
#endif
}
void setup_udp_tunnel_sock(struct net *net, struct sock *sk,
struct udp_tunnel_sock_cfg *cfg)
{
/* Disable multicast loopback */
inet_clear_bit(MC_LOOP, sk);
/* Enable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */
inet_inc_convert_csum(sk);
rcu_assign_sk_user_data(sk, cfg->sk_user_data);
udp_sk(sk)->encap_type = cfg->encap_type;
udp_sk(sk)->encap_rcv = cfg->encap_rcv;
udp_sk(sk)->encap_err_rcv = cfg->encap_err_rcv;
udp_sk(sk)->encap_err_lookup = cfg->encap_err_lookup;
udp_sk(sk)->encap_destroy = cfg->encap_destroy;
udp_sk(sk)->gro_receive = cfg->gro_receive;
udp_sk(sk)->gro_complete = cfg->gro_complete;
udp_tunnel_encap_enable(sk);
Annotation
- Immediate include surface: `linux/module.h`, `linux/errno.h`, `linux/socket.h`, `linux/kernel.h`, `net/dst_metadata.h`, `net/flow.h`, `net/udp.h`, `net/udp_tunnel.h`.
- Detected declarations: `function udp_sock_create4`, `function sk_saddr_any`, `function setup_udp_tunnel_sock`, `function udp_tunnel_push_rx_port`, `function udp_tunnel_drop_rx_port`, `function udp_tunnel_notify_add_rx_port`, `function for_each_netdev`, `function udp_tunnel_notify_del_rx_port`, `function for_each_netdev`, `function udp_tunnel_xmit_skb`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.