net/openvswitch/conntrack.c
Source file repositories/reference/linux-study-clean/net/openvswitch/conntrack.c
File Facts
- System
- Linux kernel
- Corpus path
net/openvswitch/conntrack.c- Extension
.c- Size
- 53410 bytes
- Lines
- 2029
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- 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/module.hlinux/openvswitch.hlinux/tcp.hlinux/udp.hlinux/sctp.hlinux/static_key.hlinux/string_helpers.hnet/ip.hnet/genetlink.hnet/netfilter/nf_conntrack_core.hnet/netfilter/nf_conntrack_count.hnet/netfilter/nf_conntrack_helper.hnet/netfilter/nf_conntrack_labels.hnet/netfilter/nf_conntrack_seqadj.hnet/netfilter/nf_conntrack_timeout.hnet/netfilter/nf_conntrack_zones.hnet/netfilter/ipv6/nf_defrag_ipv6.hnet/ipv6_frag.hnet/netfilter/nf_nat.hnet/netfilter/nf_conntrack_act_ct.hdatapath.hdrop.hconntrack.hflow.hflow_netlink.h
Detected Declarations
struct ovs_ct_len_tblstruct md_markstruct md_labelsstruct ovs_conntrack_infostruct ovs_ct_limitstruct ovs_ct_limit_infoenum ovs_ct_natfunction key_to_nfprotofunction ovs_ct_get_statefunction ovs_ct_get_markfunction ovs_ct_get_labelsfunction __ovs_ct_update_key_orig_tpfunction __ovs_ct_update_keyfunction nf_ct_l3numfunction ovs_ct_update_keyfunction ovs_ct_fill_keyfunction ovs_ct_put_keyfunction ovs_ct_set_markfunction ovs_ct_init_labelsfunction ovs_ct_set_labelsfunction ovs_ct_handle_fragmentsfunction ovs_ct_get_infofunction ovs_ct_find_existingfunction skb_nfct_cachedfunction ovs_nat_update_keyfunction ovs_ct_natfunction ovs_ct_natfunction verdict_to_errnofunction __ovs_ct_lookupfunction packetfunction afunction attachedfunction ovs_ct_lookupfunction labels_nonzerofunction ct_limit_setfunction ct_limit_delfunction ct_limit_getfunction ovs_ct_check_limitfunction ovs_ct_commitfunction labels_nonzerofunction ovs_ct_executefunction ovs_ct_clearfunction parse_natfunction nla_for_each_nestedfunction parse_ctfunction nla_for_each_nestedfunction ovs_ct_verifyfunction ovs_ct_copy_action
Annotated Snippet
struct ovs_ct_len_tbl {
int maxlen;
int minlen;
};
/* Metadata mark for masked write to conntrack mark */
struct md_mark {
u32 value;
u32 mask;
};
/* Metadata label for masked write to conntrack label. */
struct md_labels {
struct ovs_key_ct_labels value;
struct ovs_key_ct_labels mask;
};
enum ovs_ct_nat {
OVS_CT_NAT = 1 << 0, /* NAT for committed connections only. */
OVS_CT_SRC_NAT = 1 << 1, /* Source NAT for NEW connections. */
OVS_CT_DST_NAT = 1 << 2, /* Destination NAT for NEW connections. */
};
/* Conntrack action context for execution. */
struct ovs_conntrack_info {
struct nf_conntrack_helper *helper;
struct nf_conntrack_zone zone;
struct nf_conn *ct;
u8 commit : 1;
u8 nat : 3; /* enum ovs_ct_nat */
u8 force : 1;
u8 have_eventmask : 1;
u16 family;
u32 eventmask; /* Mask of 1 << IPCT_*. */
struct md_mark mark;
struct md_labels labels;
char timeout[CTNL_TIMEOUT_NAME_MAX];
struct nf_ct_timeout *nf_ct_timeout;
#if IS_ENABLED(CONFIG_NF_NAT)
struct nf_nat_range2 range; /* Only present for SRC NAT and DST NAT. */
#endif
};
#if IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
#define OVS_CT_LIMIT_UNLIMITED 0
#define OVS_CT_LIMIT_DEFAULT OVS_CT_LIMIT_UNLIMITED
#define CT_LIMIT_HASH_BUCKETS 512
static DEFINE_STATIC_KEY_FALSE(ovs_ct_limit_enabled);
struct ovs_ct_limit {
/* Elements in ovs_ct_limit_info->limits hash table */
struct hlist_node hlist_node;
struct rcu_head rcu;
u16 zone;
u32 limit;
};
struct ovs_ct_limit_info {
u32 default_limit;
struct hlist_head *limits;
struct nf_conncount_data *data;
};
static const struct nla_policy ct_limit_policy[OVS_CT_LIMIT_ATTR_MAX + 1] = {
[OVS_CT_LIMIT_ATTR_ZONE_LIMIT] = { .type = NLA_NESTED, },
};
#endif
static bool labels_nonzero(const struct ovs_key_ct_labels *labels);
static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info);
static u16 key_to_nfproto(const struct sw_flow_key *key)
{
switch (ntohs(key->eth.type)) {
case ETH_P_IP:
return NFPROTO_IPV4;
case ETH_P_IPV6:
return NFPROTO_IPV6;
default:
return NFPROTO_UNSPEC;
}
}
/* Map SKB connection state into the values used by flow definition. */
static u8 ovs_ct_get_state(enum ip_conntrack_info ctinfo)
{
u8 ct_state = OVS_CS_F_TRACKED;
switch (ctinfo) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/openvswitch.h`, `linux/tcp.h`, `linux/udp.h`, `linux/sctp.h`, `linux/static_key.h`, `linux/string_helpers.h`, `net/ip.h`.
- Detected declarations: `struct ovs_ct_len_tbl`, `struct md_mark`, `struct md_labels`, `struct ovs_conntrack_info`, `struct ovs_ct_limit`, `struct ovs_ct_limit_info`, `enum ovs_ct_nat`, `function key_to_nfproto`, `function ovs_ct_get_state`, `function ovs_ct_get_mark`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- 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.