net/sched/sch_api.c
Source file repositories/reference/linux-study-clean/net/sched/sch_api.c
File Facts
- System
- Linux kernel
- Corpus path
net/sched/sch_api.c- Extension
.c- Size
- 62209 bytes
- Lines
- 2537
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/module.hlinux/types.hlinux/kernel.hlinux/string.hlinux/errno.hlinux/skbuff.hlinux/init.hlinux/proc_fs.hlinux/seq_file.hlinux/kmod.hlinux/list.hlinux/hrtimer.hlinux/slab.hlinux/hashtable.hlinux/bpf.hnet/netdev_lock.hnet/net_namespace.hnet/sock.hnet/netlink.hnet/pkt_sched.hnet/pkt_cls.hnet/tc_wrapper.htrace/events/qdisc.h
Detected Declarations
struct check_loop_argstruct tcf_bind_argsstruct tc_bind_class_argsstruct qdisc_dump_argsfunction register_qdiscfunction unregister_qdiscfunction qdisc_get_defaultfunction qdisc_set_defaultfunction sch_default_qdiscfunction hash_for_each_possible_rcufunction qdisc_hash_addfunction qdisc_hash_delfunction mpufunction qdisc_put_rtabfunction list_for_each_entryfunction qdisc_put_stabfunction qdisc_dump_stabfunction __qdisc_calculate_pkt_lenfunction qdisc_watchdogfunction qdisc_watchdog_init_clockidfunction qdisc_watchdog_initfunction qdisc_watchdog_schedule_range_nsfunction qdisc_watchdog_cancelfunction qdisc_class_hash_growfunction hlist_for_each_entry_safefunction qdisc_class_hash_initfunction qdisc_class_hash_destroyfunction qdisc_class_hash_insertfunction qdisc_class_hash_removefunction qdisc_alloc_handlefunction qdisc_tree_reduce_backlogfunction qdisc_offload_dump_helperfunction qdisc_offload_graft_helperfunction qdisc_offload_query_capsfunction qdisc_offload_graft_rootfunction tc_fill_qdiscfunction tc_qdisc_dump_ignorefunction qdisc_get_notifyfunction qdisc_notifyfunction notify_and_destroyfunction qdisc_clear_nolockfunction qdisc_graftfunction __tcf_qdisc_findfunction qdisc_block_indexes_setfunction qdisc_changefunction check_loopfunction check_loop_fnfunction __tc_get_qdisc
Annotated Snippet
const struct net_device_ops *ops = dev->netdev_ops;
struct tc_query_caps_base base = {
.type = type,
.caps = caps,
};
memset(caps, 0, caps_len);
if (ops->ndo_setup_tc)
ops->ndo_setup_tc(dev, TC_QUERY_CAPS, &base);
}
EXPORT_SYMBOL(qdisc_offload_query_caps);
static void qdisc_offload_graft_root(struct net_device *dev,
struct Qdisc *new, struct Qdisc *old,
struct netlink_ext_ack *extack)
{
struct tc_root_qopt_offload graft_offload = {
.command = TC_ROOT_GRAFT,
.handle = new ? new->handle : 0,
.ingress = (new && new->flags & TCQ_F_INGRESS) ||
(old && old->flags & TCQ_F_INGRESS),
};
qdisc_offload_graft_helper(dev, NULL, new, old,
TC_SETUP_ROOT_QDISC, &graft_offload, extack);
}
static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid,
u32 portid, u32 seq, u16 flags, int event,
struct netlink_ext_ack *extack)
{
struct gnet_stats_basic_sync __percpu *cpu_bstats = NULL;
struct gnet_stats_queue __percpu *cpu_qstats = NULL;
struct tcmsg *tcm;
struct nlmsghdr *nlh;
unsigned char *b = skb_tail_pointer(skb);
struct gnet_dump d;
struct qdisc_size_table *stab;
u32 block_index;
__u32 qlen;
cond_resched();
nlh = nlmsg_put(skb, portid, seq, event, sizeof(*tcm), flags);
if (!nlh)
goto out_nlmsg_trim;
tcm = nlmsg_data(nlh);
tcm->tcm_family = AF_UNSPEC;
tcm->tcm__pad1 = 0;
tcm->tcm__pad2 = 0;
tcm->tcm_ifindex = qdisc_dev(q)->ifindex;
tcm->tcm_parent = clid;
tcm->tcm_handle = q->handle;
tcm->tcm_info = refcount_read(&q->refcnt);
if (nla_put_string(skb, TCA_KIND, q->ops->id))
goto nla_put_failure;
if (q->ops->ingress_block_get) {
block_index = q->ops->ingress_block_get(q);
if (block_index &&
nla_put_u32(skb, TCA_INGRESS_BLOCK, block_index))
goto nla_put_failure;
}
if (q->ops->egress_block_get) {
block_index = q->ops->egress_block_get(q);
if (block_index &&
nla_put_u32(skb, TCA_EGRESS_BLOCK, block_index))
goto nla_put_failure;
}
if (q->ops->dump && q->ops->dump(q, skb) < 0)
goto nla_put_failure;
if (nla_put_u8(skb, TCA_HW_OFFLOAD, !!(q->flags & TCQ_F_OFFLOADED)))
goto nla_put_failure;
qlen = qdisc_qlen_sum(q);
stab = rtnl_dereference(q->stab);
if (stab && qdisc_dump_stab(skb, stab) < 0)
goto nla_put_failure;
if (gnet_stats_start_copy_compat(skb, TCA_STATS2, TCA_STATS, TCA_XSTATS,
NULL, &d, TCA_PAD) < 0)
goto nla_put_failure;
if (q->ops->dump_stats && q->ops->dump_stats(q, &d) < 0)
goto nla_put_failure;
if (qdisc_is_percpu_stats(q)) {
cpu_bstats = q->cpu_bstats;
cpu_qstats = q->cpu_qstats;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/kernel.h`, `linux/string.h`, `linux/errno.h`, `linux/skbuff.h`, `linux/init.h`, `linux/proc_fs.h`.
- Detected declarations: `struct check_loop_arg`, `struct tcf_bind_args`, `struct tc_bind_class_args`, `struct qdisc_dump_args`, `function register_qdisc`, `function unregister_qdisc`, `function qdisc_get_default`, `function qdisc_set_default`, `function sch_default_qdisc`, `function hash_for_each_possible_rcu`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.