net/l3mdev/l3mdev.c
Source file repositories/reference/linux-study-clean/net/l3mdev/l3mdev.c
File Facts
- System
- Linux kernel
- Corpus path
net/l3mdev/l3mdev.c- Extension
.c- Size
- 6796 bytes
- Lines
- 304
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/netdevice.hnet/fib_rules.hnet/l3mdev.h
Detected Declarations
struct l3mdev_handlerfunction l3mdev_check_typefunction l3mdev_table_lookup_registerfunction l3mdev_table_lookup_unregisterfunction l3mdev_ifindex_lookup_by_table_idfunction l3mdev_master_ifindex_rcufunction l3mdev_master_upper_ifindex_by_index_rcufunction l3mdev_fib_table_rcufunction l3mdev_fib_table_by_indexfunction rcu_read_lockfunction l3mdev_fib_rule_matchfunction l3mdev_update_flowexport l3mdev_table_lookup_registerexport l3mdev_table_lookup_unregisterexport l3mdev_ifindex_lookup_by_table_idexport l3mdev_master_ifindex_rcuexport l3mdev_master_upper_ifindex_by_index_rcuexport l3mdev_fib_table_rcuexport l3mdev_fib_table_by_indexexport l3mdev_link_scope_lookupexport l3mdev_update_flow
Annotated Snippet
struct l3mdev_handler {
lookup_by_table_id_t dev_lookup;
};
static struct l3mdev_handler l3mdev_handlers[L3MDEV_TYPE_MAX + 1];
static int l3mdev_check_type(enum l3mdev_type l3type)
{
if (l3type <= L3MDEV_TYPE_UNSPEC || l3type > L3MDEV_TYPE_MAX)
return -EINVAL;
return 0;
}
int l3mdev_table_lookup_register(enum l3mdev_type l3type,
lookup_by_table_id_t fn)
{
struct l3mdev_handler *hdlr;
int res;
res = l3mdev_check_type(l3type);
if (res)
return res;
hdlr = &l3mdev_handlers[l3type];
spin_lock(&l3mdev_lock);
if (hdlr->dev_lookup) {
res = -EBUSY;
goto unlock;
}
hdlr->dev_lookup = fn;
res = 0;
unlock:
spin_unlock(&l3mdev_lock);
return res;
}
EXPORT_SYMBOL_GPL(l3mdev_table_lookup_register);
void l3mdev_table_lookup_unregister(enum l3mdev_type l3type,
lookup_by_table_id_t fn)
{
struct l3mdev_handler *hdlr;
if (l3mdev_check_type(l3type))
return;
hdlr = &l3mdev_handlers[l3type];
spin_lock(&l3mdev_lock);
if (hdlr->dev_lookup == fn)
hdlr->dev_lookup = NULL;
spin_unlock(&l3mdev_lock);
}
EXPORT_SYMBOL_GPL(l3mdev_table_lookup_unregister);
int l3mdev_ifindex_lookup_by_table_id(enum l3mdev_type l3type,
struct net *net, u32 table_id)
{
lookup_by_table_id_t lookup;
struct l3mdev_handler *hdlr;
int ifindex = -EINVAL;
int res;
res = l3mdev_check_type(l3type);
if (res)
return res;
hdlr = &l3mdev_handlers[l3type];
spin_lock(&l3mdev_lock);
lookup = hdlr->dev_lookup;
if (!lookup)
goto unlock;
ifindex = lookup(net, table_id);
unlock:
spin_unlock(&l3mdev_lock);
return ifindex;
}
EXPORT_SYMBOL_GPL(l3mdev_ifindex_lookup_by_table_id);
Annotation
- Immediate include surface: `linux/netdevice.h`, `net/fib_rules.h`, `net/l3mdev.h`.
- Detected declarations: `struct l3mdev_handler`, `function l3mdev_check_type`, `function l3mdev_table_lookup_register`, `function l3mdev_table_lookup_unregister`, `function l3mdev_ifindex_lookup_by_table_id`, `function l3mdev_master_ifindex_rcu`, `function l3mdev_master_upper_ifindex_by_index_rcu`, `function l3mdev_fib_table_rcu`, `function l3mdev_fib_table_by_index`, `function rcu_read_lock`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration 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.