net/tipc/udp_media.c
Source file repositories/reference/linux-study-clean/net/tipc/udp_media.c
File Facts
- System
- Linux kernel
- Corpus path
net/tipc/udp_media.c- Extension
.c- Size
- 22130 bytes
- Lines
- 865
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/socket.hlinux/ip.hlinux/udp.hlinux/inet.hlinux/inetdevice.hlinux/igmp.hlinux/kernel.hlinux/workqueue.hlinux/list.hnet/sock.hnet/ip.hnet/udp_tunnel.hlinux/tipc_netlink.hcore.haddr.hnet.hbearer.hnetlink.hmsg.hudp_media.h
Detected Declarations
struct udp_media_addrstruct udp_replicaststruct udp_bearerfunction tipc_udp_is_mcast_addrfunction tipc_udp_media_addr_setfunction tipc_udp_addr2strfunction tipc_udp_msg2addrfunction tipc_udp_addr2msgfunction tipc_udp_xmitfunction tipc_udp_send_msgfunction tipc_udp_is_known_peerfunction list_for_each_entry_safefunction tipc_udp_rcast_addfunction tipc_udp_rcast_discfunction tipc_udp_recvfunction enable_mcastfunction __tipc_nl_add_udp_addrfunction tipc_udp_nl_dump_remoteipfunction tipc_udp_nl_add_bearer_datafunction tipc_parse_udp_addrfunction tipc_udp_nl_bearer_addfunction tipc_udp_enablefunction cleanup_bearerfunction list_for_each_entry_safefunction tipc_udp_disable
Annotated Snippet
struct udp_media_addr {
__be16 proto;
__be16 port;
union {
struct in_addr ipv4;
struct in6_addr ipv6;
};
};
/* struct udp_replicast - container for UDP remote addresses */
struct udp_replicast {
struct udp_media_addr addr;
struct dst_cache dst_cache;
struct rcu_head rcu;
struct list_head list;
};
/**
* struct udp_bearer - ip/udp bearer data structure
* @bearer: associated generic tipc bearer
* @sk: bearer associated socket
* @ifindex: local address scope
* @work: used to schedule deferred work on a bearer
* @rcast: associated udp_replicast container
*/
struct udp_bearer {
struct tipc_bearer __rcu *bearer;
struct sock *sk;
u32 ifindex;
struct work_struct work;
struct udp_replicast rcast;
};
static int tipc_udp_is_mcast_addr(struct udp_media_addr *addr)
{
if (ntohs(addr->proto) == ETH_P_IP)
return ipv4_is_multicast(addr->ipv4.s_addr);
#if IS_ENABLED(CONFIG_IPV6)
else
return ipv6_addr_is_multicast(&addr->ipv6);
#endif
return 0;
}
/* udp_media_addr_set - convert a ip/udp address to a TIPC media address */
static void tipc_udp_media_addr_set(struct tipc_media_addr *addr,
struct udp_media_addr *ua)
{
memset(addr, 0, sizeof(struct tipc_media_addr));
addr->media_id = TIPC_MEDIA_TYPE_UDP;
memcpy(addr->value, ua, sizeof(struct udp_media_addr));
if (tipc_udp_is_mcast_addr(ua))
addr->broadcast = TIPC_BROADCAST_SUPPORT;
}
/* tipc_udp_addr2str - convert ip/udp address to string */
static int tipc_udp_addr2str(struct tipc_media_addr *a, char *buf, int size)
{
struct udp_media_addr *ua = (struct udp_media_addr *)&a->value;
if (ntohs(ua->proto) == ETH_P_IP)
snprintf(buf, size, "%pI4:%u", &ua->ipv4, ntohs(ua->port));
else if (ntohs(ua->proto) == ETH_P_IPV6)
snprintf(buf, size, "%pI6:%u", &ua->ipv6, ntohs(ua->port));
else {
pr_err("Invalid UDP media address\n");
return 1;
}
return 0;
}
/* tipc_udp_msg2addr - extract an ip/udp address from a TIPC ndisc message */
static int tipc_udp_msg2addr(struct tipc_bearer *b, struct tipc_media_addr *a,
char *msg)
{
struct udp_media_addr *ua;
ua = (struct udp_media_addr *) (msg + TIPC_MEDIA_ADDR_OFFSET);
if (msg[TIPC_MEDIA_TYPE_OFFSET] != TIPC_MEDIA_TYPE_UDP)
return -EINVAL;
tipc_udp_media_addr_set(a, ua);
return 0;
}
/* tipc_udp_addr2msg - write an ip/udp address to a TIPC ndisc message */
static int tipc_udp_addr2msg(char *msg, struct tipc_media_addr *a)
{
memset(msg, 0, TIPC_MEDIA_INFO_SIZE);
Annotation
- Immediate include surface: `linux/socket.h`, `linux/ip.h`, `linux/udp.h`, `linux/inet.h`, `linux/inetdevice.h`, `linux/igmp.h`, `linux/kernel.h`, `linux/workqueue.h`.
- Detected declarations: `struct udp_media_addr`, `struct udp_replicast`, `struct udp_bearer`, `function tipc_udp_is_mcast_addr`, `function tipc_udp_media_addr_set`, `function tipc_udp_addr2str`, `function tipc_udp_msg2addr`, `function tipc_udp_addr2msg`, `function tipc_udp_xmit`, `function tipc_udp_send_msg`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.