net/ipv4/fib_rules.c
Source file repositories/reference/linux-study-clean/net/ipv4/fib_rules.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv4/fib_rules.c- Extension
.c- Size
- 12378 bytes
- Lines
- 523
- 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/types.hlinux/kernel.hlinux/netdevice.hlinux/netlink.hlinux/inetdevice.hlinux/init.hlinux/list.hlinux/rcupdate.hlinux/export.hnet/flow.hnet/inet_dscp.hnet/ip.hnet/route.hnet/tcp.hnet/ip_fib.hnet/nexthop.hnet/fib_rules.hlinux/indirect_call_wrapper.h
Detected Declarations
struct fib4_rulefunction fib4_rule_matchallfunction fib4_rule_defaultfunction fib4_rules_dumpfunction fib4_rules_seq_readfunction __fib_lookupfunction fib4_rule_actionfunction fib4_rule_suppressfunction fib4_rule_matchfunction fib4_nl2rule_dscpfunction fib4_nl2rule_dscp_maskfunction fib4_rule_configurefunction fib4_rule_deletefunction fib4_rule_comparefunction fib4_rule_fillfunction fib4_rule_nlmsg_payloadfunction fib4_rule_flush_cachefunction fib_default_rules_initfunction fib4_rules_initfunction fib4_rules_exitexport fib4_rule_defaultexport __fib_lookup
Annotated Snippet
struct fib4_rule {
struct fib_rule common;
u8 dst_len;
u8 src_len;
dscp_t dscp;
dscp_t dscp_mask;
u8 dscp_full:1; /* DSCP or TOS selector */
__be32 src;
__be32 srcmask;
__be32 dst;
__be32 dstmask;
#ifdef CONFIG_IP_ROUTE_CLASSID
u32 tclassid;
#endif
};
static bool fib4_rule_matchall(const struct fib_rule *rule)
{
struct fib4_rule *r = container_of(rule, struct fib4_rule, common);
if (r->dst_len || r->src_len || r->dscp)
return false;
return fib_rule_matchall(rule);
}
bool fib4_rule_default(const struct fib_rule *rule)
{
if (!fib4_rule_matchall(rule) || rule->action != FR_ACT_TO_TBL ||
rule->l3mdev)
return false;
if (rule->table != RT_TABLE_LOCAL && rule->table != RT_TABLE_MAIN &&
rule->table != RT_TABLE_DEFAULT)
return false;
return true;
}
EXPORT_SYMBOL_GPL(fib4_rule_default);
int fib4_rules_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
return fib_rules_dump(net, nb, AF_INET, extack);
}
unsigned int fib4_rules_seq_read(const struct net *net)
{
return fib_rules_seq_read(net, AF_INET);
}
int __fib_lookup(struct net *net, struct flowi4 *flp,
struct fib_result *res, unsigned int flags)
{
struct fib_lookup_arg arg = {
.result = res,
.flags = flags,
};
int err;
/* update flow if oif or iif point to device enslaved to l3mdev */
l3mdev_update_flow(net, flowi4_to_flowi(flp));
err = fib_rules_lookup(net->ipv4.rules_ops, flowi4_to_flowi(flp), 0, &arg);
#ifdef CONFIG_IP_ROUTE_CLASSID
if (arg.rule)
res->tclassid = ((struct fib4_rule *)arg.rule)->tclassid;
else
res->tclassid = 0;
#endif
if (err == -ESRCH)
err = -ENETUNREACH;
return err;
}
EXPORT_SYMBOL_GPL(__fib_lookup);
INDIRECT_CALLABLE_SCOPE int fib4_rule_action(struct fib_rule *rule,
struct flowi *flp, int flags,
struct fib_lookup_arg *arg)
{
int err = -EAGAIN;
struct fib_table *tbl;
u32 tb_id;
switch (rule->action) {
case FR_ACT_TO_TBL:
break;
case FR_ACT_UNREACHABLE:
return -ENETUNREACH;
Annotation
- Immediate include surface: `linux/types.h`, `linux/kernel.h`, `linux/netdevice.h`, `linux/netlink.h`, `linux/inetdevice.h`, `linux/init.h`, `linux/list.h`, `linux/rcupdate.h`.
- Detected declarations: `struct fib4_rule`, `function fib4_rule_matchall`, `function fib4_rule_default`, `function fib4_rules_dump`, `function fib4_rules_seq_read`, `function __fib_lookup`, `function fib4_rule_action`, `function fib4_rule_suppress`, `function fib4_rule_match`, `function fib4_nl2rule_dscp`.
- 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.