drivers/net/ethernet/sfc/tc_conntrack.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/sfc/tc_conntrack.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/sfc/tc_conntrack.c- Extension
.c- Size
- 17334 bytes
- Lines
- 626
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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
tc_conntrack.htc.hmae.h
Detected Declarations
struct efx_tc_ct_mangler_statefunction efx_tc_ct_zone_freefunction efx_tc_ct_freefunction efx_tc_init_conntrackfunction efx_tc_destroy_conntrackfunction efx_tc_fini_conntrackfunction efx_tc_ct_parse_matchfunction LHSfunction efx_tc_ct_manglefunction efx_tc_ct_replacefunction efx_tc_ct_removefunction efx_tc_ct_remove_finishfunction efx_tc_ct_destroyfunction efx_tc_ct_statsfunction efx_tc_flow_blockfunction efx_tc_ct_unregister_zone
Annotated Snippet
struct efx_tc_ct_mangler_state {
u8 ipv4:1;
u8 tcpudp:1;
};
static int efx_tc_ct_mangle(struct efx_nic *efx, struct efx_tc_ct_entry *conn,
const struct flow_action_entry *fa,
struct efx_tc_ct_mangler_state *mung)
{
/* Is this the first mangle we've processed for this rule? */
bool first = !(mung->ipv4 || mung->tcpudp);
bool dnat = false;
switch (fa->mangle.htype) {
case FLOW_ACT_MANGLE_HDR_TYPE_IP4:
switch (fa->mangle.offset) {
case offsetof(struct iphdr, daddr):
dnat = true;
fallthrough;
case offsetof(struct iphdr, saddr):
if (fa->mangle.mask)
return -EOPNOTSUPP;
conn->nat_ip = htonl(fa->mangle.val);
mung->ipv4 = 1;
break;
default:
return -EOPNOTSUPP;
}
break;
case FLOW_ACT_MANGLE_HDR_TYPE_TCP:
case FLOW_ACT_MANGLE_HDR_TYPE_UDP:
/* Both struct tcphdr and struct udphdr start with
* __be16 source;
* __be16 dest;
* so we can use the same code for both.
*/
switch (fa->mangle.offset) {
case offsetof(struct tcphdr, dest):
BUILD_BUG_ON(offsetof(struct tcphdr, dest) !=
offsetof(struct udphdr, dest));
dnat = true;
fallthrough;
case offsetof(struct tcphdr, source):
BUILD_BUG_ON(offsetof(struct tcphdr, source) !=
offsetof(struct udphdr, source));
if (~fa->mangle.mask != 0xffff)
return -EOPNOTSUPP;
conn->l4_natport = htons(fa->mangle.val);
mung->tcpudp = 1;
break;
default:
return -EOPNOTSUPP;
}
break;
default:
return -EOPNOTSUPP;
}
/* first mangle tells us whether this is SNAT or DNAT;
* subsequent mangles must match that
*/
if (first)
conn->dnat = dnat;
else if (conn->dnat != dnat)
return -EOPNOTSUPP;
return 0;
}
static int efx_tc_ct_replace(struct efx_tc_ct_zone *ct_zone,
struct flow_cls_offload *tc)
{
struct flow_rule *fr = flow_cls_offload_flow_rule(tc);
struct efx_tc_ct_mangler_state mung = {};
struct efx_tc_ct_entry *conn, *old;
struct efx_nic *efx = ct_zone->efx;
const struct flow_action_entry *fa;
struct efx_tc_counter *cnt;
int rc, i;
if (WARN_ON(!efx->tc))
return -ENETDOWN;
if (WARN_ON(!efx->tc->up))
return -ENETDOWN;
conn = kzalloc_obj(*conn, GFP_USER);
if (!conn)
return -ENOMEM;
conn->cookie = tc->cookie;
old = rhashtable_lookup_get_insert_fast(&efx->tc->ct_ht,
&conn->linkage,
efx_tc_ct_ht_params);
Annotation
- Immediate include surface: `tc_conntrack.h`, `tc.h`, `mae.h`.
- Detected declarations: `struct efx_tc_ct_mangler_state`, `function efx_tc_ct_zone_free`, `function efx_tc_ct_free`, `function efx_tc_init_conntrack`, `function efx_tc_destroy_conntrack`, `function efx_tc_fini_conntrack`, `function efx_tc_ct_parse_match`, `function LHS`, `function efx_tc_ct_mangle`, `function efx_tc_ct_replace`.
- Atlas domain: Driver Families / drivers/net.
- 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.