net/ipv4/udp_tunnel_nic.c
Source file repositories/reference/linux-study-clean/net/ipv4/udp_tunnel_nic.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/udp_tunnel_nic.c- Extension
.c- Size
- 25397 bytes
- Lines
- 1011
- 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/ethtool_netlink.hlinux/netdevice.hlinux/slab.hlinux/types.hlinux/workqueue.hnet/udp_tunnel.hnet/vxlan.h
Detected Declarations
struct udp_tunnel_nic_table_entrystruct udp_tunnel_nicenum udp_tunnel_nic_table_entry_flagsfunction udp_tunnel_nic_entry_is_freefunction udp_tunnel_nic_entry_is_presentfunction udp_tunnel_nic_entry_is_frozenfunction udp_tunnel_nic_entry_freeze_usedfunction udp_tunnel_nic_entry_unfreezefunction udp_tunnel_nic_entry_is_queuedfunction udp_tunnel_nic_entry_queuefunction udp_tunnel_nic_ti_from_entryfunction udp_tunnel_nic_is_emptyfunction udp_tunnel_nic_should_replayfunction __udp_tunnel_nic_get_portfunction __udp_tunnel_nic_set_port_privfunction udp_tunnel_nic_entry_update_donefunction udp_tunnel_nic_device_sync_onefunction udp_tunnel_nic_device_sync_by_portfunction udp_tunnel_nic_device_sync_by_tablefunction __udp_tunnel_nic_device_syncfunction udp_tunnel_nic_device_syncfunction udp_tunnel_nic_table_is_capablefunction udp_tunnel_nic_is_capablefunction udp_tunnel_nic_has_collisionfunction udp_tunnel_nic_entry_adjfunction udp_tunnel_nic_entry_try_adjfunction udp_tunnel_nic_try_existingfunction udp_tunnel_nic_add_existingfunction udp_tunnel_nic_del_existingfunction udp_tunnel_nic_add_newfunction __udp_tunnel_nic_add_portfunction __udp_tunnel_nic_del_portfunction __udp_tunnel_nic_reset_ntffunction __udp_tunnel_nic_dump_sizefunction __udp_tunnel_nic_dump_writefunction __udp_tunnel_nic_assert_lockedfunction __udp_tunnel_nic_lockfunction __udp_tunnel_nic_unlockfunction udp_tunnel_nic_flushfunction udp_tunnel_nic_replayfunction udp_tunnel_nic_device_sync_workfunction udp_tunnel_nic_allocfunction udp_tunnel_nic_freefunction udp_tunnel_nic_registerfunction udp_tunnel_nic_unregisterfunction udp_tunnel_nic_netdevice_eventfunction udp_tunnel_nic_init_modulefunction udp_tunnel_nic_cleanup_module
Annotated Snippet
struct udp_tunnel_nic_table_entry {
__be16 port;
u8 type;
u8 flags;
u16 use_cnt;
#define UDP_TUNNEL_NIC_USE_CNT_MAX U16_MAX
u8 hw_priv;
};
/**
* struct udp_tunnel_nic - UDP tunnel port offload state
* @work: async work for talking to hardware from process context
* @dev: netdev pointer
* @lock: protects all fields
* @need_sync: at least one port start changed
* @need_replay: space was freed, we need a replay of all ports
* @work_pending: @work is currently scheduled
* @n_tables: number of tables under @entries
* @missed: bitmap of tables which overflown
* @entries: table of tables of ports currently offloaded
*/
struct udp_tunnel_nic {
struct work_struct work;
struct net_device *dev;
struct mutex lock;
u8 need_sync:1;
u8 need_replay:1;
u8 work_pending:1;
unsigned int n_tables;
unsigned long missed;
struct udp_tunnel_nic_table_entry *entries[] __counted_by(n_tables);
};
/* We ensure all work structs are done using driver state, but not the code.
* We need a workqueue we can flush before module gets removed.
*/
static struct workqueue_struct *udp_tunnel_nic_workqueue;
static const char *udp_tunnel_nic_tunnel_type_name(unsigned int type)
{
switch (type) {
case UDP_TUNNEL_TYPE_VXLAN:
return "vxlan";
case UDP_TUNNEL_TYPE_GENEVE:
return "geneve";
case UDP_TUNNEL_TYPE_VXLAN_GPE:
return "vxlan-gpe";
default:
return "unknown";
}
}
static bool
udp_tunnel_nic_entry_is_free(struct udp_tunnel_nic_table_entry *entry)
{
return entry->use_cnt == 0 && !entry->flags;
}
static bool
udp_tunnel_nic_entry_is_present(struct udp_tunnel_nic_table_entry *entry)
{
return entry->use_cnt && !(entry->flags & ~UDP_TUNNEL_NIC_ENTRY_FROZEN);
}
static bool
udp_tunnel_nic_entry_is_frozen(struct udp_tunnel_nic_table_entry *entry)
{
return entry->flags & UDP_TUNNEL_NIC_ENTRY_FROZEN;
}
static void
udp_tunnel_nic_entry_freeze_used(struct udp_tunnel_nic_table_entry *entry)
{
if (!udp_tunnel_nic_entry_is_free(entry))
entry->flags |= UDP_TUNNEL_NIC_ENTRY_FROZEN;
}
static void
udp_tunnel_nic_entry_unfreeze(struct udp_tunnel_nic_table_entry *entry)
{
entry->flags &= ~UDP_TUNNEL_NIC_ENTRY_FROZEN;
}
static bool
udp_tunnel_nic_entry_is_queued(struct udp_tunnel_nic_table_entry *entry)
{
Annotation
- Immediate include surface: `linux/ethtool_netlink.h`, `linux/netdevice.h`, `linux/slab.h`, `linux/types.h`, `linux/workqueue.h`, `net/udp_tunnel.h`, `net/vxlan.h`.
- Detected declarations: `struct udp_tunnel_nic_table_entry`, `struct udp_tunnel_nic`, `enum udp_tunnel_nic_table_entry_flags`, `function udp_tunnel_nic_entry_is_free`, `function udp_tunnel_nic_entry_is_present`, `function udp_tunnel_nic_entry_is_frozen`, `function udp_tunnel_nic_entry_freeze_used`, `function udp_tunnel_nic_entry_unfreeze`, `function udp_tunnel_nic_entry_is_queued`, `function udp_tunnel_nic_entry_queue`.
- 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.