drivers/net/netdevsim/fib.c
Source file repositories/reference/linux-study-clean/drivers/net/netdevsim/fib.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/netdevsim/fib.c- Extension
.c- Size
- 41514 bytes
- Lines
- 1672
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/bitmap.hlinux/in6.hlinux/kernel.hlinux/list.hlinux/rhashtable.hlinux/spinlock_types.hlinux/types.hnet/fib_notifier.hnet/inet_dscp.hnet/ip_fib.hnet/ip6_fib.hnet/fib_rules.hnet/net_namespace.hnet/nexthop.hlinux/debugfs.hnetdevsim.h
Detected Declarations
struct nsim_fib_entrystruct nsim_per_fib_datastruct nsim_fib_datastruct nsim_fib_rt_keystruct nsim_fib_rtstruct nsim_fib4_rtstruct nsim_fib6_rtstruct nsim_fib6_rt_nhstruct nsim_fib6_eventstruct nsim_fib_eventstruct nsim_nexthopfunction nsim_fib_get_valfunction nsim_fib_set_maxfunction nsim_fib_rule_accountfunction nsim_fib_rule_eventfunction nsim_fib_accountfunction nsim_fib_rt_initfunction nsim_fib_rt_finifunction nsim_fib4_rt_createfunction nsim_fib4_rt_destroyfunction nsim_fib4_rt_lookupfunction nsim_fib4_rt_offload_failed_flag_setfunction nsim_fib4_rt_hw_flags_setfunction nsim_fib4_rt_addfunction nsim_fib4_rt_replacefunction nsim_fib4_rt_insertfunction nsim_fib4_rt_removefunction nsim_fib4_eventfunction nsim_fib6_rt_nh_findfunction list_for_each_entryfunction nsim_fib6_rt_nh_addfunction nsim_rt6_releasefunction nsim_rt6_releasefunction nsim_fib6_rt_createfunction nsim_fib6_rt_destroyfunction nsim_fib6_rt_lookupfunction nsim_fib6_rt_appendfunction nsim_fib6_rt_offload_failed_flag_setfunction nsim_fib6_rt_offload_failed_flag_setfunction nsim_fib6_rt_hw_flags_setfunction nsim_fib6_rt_replacefunction nsim_fib6_rt_insertfunction nsim_fib6_rt_removefunction nsim_fib6_event_initfunction list_for_each_entryfunction nsim_fib6_event_finifunction nsim_fib6_eventfunction nsim_fib_event
Annotated Snippet
static const struct file_operations nsim_nexthop_bucket_activity_fops = {
.open = simple_open,
.write = nsim_nexthop_bucket_activity_write,
.owner = THIS_MODULE,
};
static u64 nsim_fib_ipv4_resource_occ_get(void *priv)
{
struct nsim_fib_data *data = priv;
return nsim_fib_get_val(data, NSIM_RESOURCE_IPV4_FIB, false);
}
static u64 nsim_fib_ipv4_rules_res_occ_get(void *priv)
{
struct nsim_fib_data *data = priv;
return nsim_fib_get_val(data, NSIM_RESOURCE_IPV4_FIB_RULES, false);
}
static u64 nsim_fib_ipv6_resource_occ_get(void *priv)
{
struct nsim_fib_data *data = priv;
return nsim_fib_get_val(data, NSIM_RESOURCE_IPV6_FIB, false);
}
static u64 nsim_fib_ipv6_rules_res_occ_get(void *priv)
{
struct nsim_fib_data *data = priv;
return nsim_fib_get_val(data, NSIM_RESOURCE_IPV6_FIB_RULES, false);
}
static u64 nsim_fib_nexthops_res_occ_get(void *priv)
{
struct nsim_fib_data *data = priv;
return nsim_fib_get_val(data, NSIM_RESOURCE_NEXTHOPS, false);
}
static void nsim_fib_set_max_all(struct nsim_fib_data *data,
struct devlink *devlink)
{
static const enum nsim_resource_id res_ids[] = {
NSIM_RESOURCE_IPV4_FIB, NSIM_RESOURCE_IPV4_FIB_RULES,
NSIM_RESOURCE_IPV6_FIB, NSIM_RESOURCE_IPV6_FIB_RULES,
NSIM_RESOURCE_NEXTHOPS,
};
int i;
for (i = 0; i < ARRAY_SIZE(res_ids); i++) {
int err;
u64 val;
err = devl_resource_size_get(devlink, res_ids[i], &val);
if (err)
val = (u64) -1;
nsim_fib_set_max(data, res_ids[i], val);
}
}
static void nsim_fib_event_work(struct work_struct *work)
{
struct nsim_fib_data *data = container_of(work, struct nsim_fib_data,
fib_event_work);
struct nsim_fib_event *fib_event, *next_fib_event;
LIST_HEAD(fib_event_queue);
spin_lock_bh(&data->fib_event_queue_lock);
list_splice_init(&data->fib_event_queue, &fib_event_queue);
spin_unlock_bh(&data->fib_event_queue_lock);
mutex_lock(&data->fib_lock);
list_for_each_entry_safe(fib_event, next_fib_event, &fib_event_queue,
list) {
nsim_fib_event(fib_event);
list_del(&fib_event->list);
kfree(fib_event);
cond_resched();
}
mutex_unlock(&data->fib_lock);
}
static void nsim_fib_flush_work(struct work_struct *work)
{
struct nsim_fib_data *data = container_of(work, struct nsim_fib_data,
fib_flush_work);
struct nsim_fib_rt *fib_rt, *fib_rt_tmp;
Annotation
- Immediate include surface: `linux/bitmap.h`, `linux/in6.h`, `linux/kernel.h`, `linux/list.h`, `linux/rhashtable.h`, `linux/spinlock_types.h`, `linux/types.h`, `net/fib_notifier.h`.
- Detected declarations: `struct nsim_fib_entry`, `struct nsim_per_fib_data`, `struct nsim_fib_data`, `struct nsim_fib_rt_key`, `struct nsim_fib_rt`, `struct nsim_fib4_rt`, `struct nsim_fib6_rt`, `struct nsim_fib6_rt_nh`, `struct nsim_fib6_event`, `struct nsim_fib_event`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.