net/core/lwtunnel.c
Source file repositories/reference/linux-study-clean/net/core/lwtunnel.c
File Facts
- System
- Linux kernel
- Corpus path
net/core/lwtunnel.c- Extension
.c- Size
- 10134 bytes
- Lines
- 475
- 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.
- 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/capability.hlinux/module.hlinux/types.hlinux/kernel.hlinux/slab.hlinux/uaccess.hlinux/skbuff.hlinux/netdevice.hlinux/lwtunnel.hlinux/in.hlinux/init.hlinux/err.hnet/lwtunnel.hnet/rtnetlink.hnet/ip6_fib.hnet/rtnh.hdev.h
Detected Declarations
function lwtunnel_encap_add_opsfunction lwtunnel_encap_del_opsfunction lwtunnel_build_statefunction lwtunnel_valid_encap_typefunction lwtunnel_valid_encap_type_attrfunction lwtstate_freefunction lwtunnel_fill_encapfunction lwtunnel_get_encap_sizefunction lwtunnel_cmp_encapfunction lwtunnel_outputfunction lwtunnel_xmitfunction lwtunnel_inputexport nf_hooks_lwtunnel_enabledexport lwtunnel_state_allocexport lwtunnel_encap_add_opsexport lwtunnel_encap_del_opsexport lwtunnel_build_stateexport lwtunnel_valid_encap_typeexport lwtunnel_valid_encap_type_attrexport lwtstate_freeexport lwtunnel_fill_encapexport lwtunnel_get_encap_sizeexport lwtunnel_cmp_encapexport lwtunnel_outputexport lwtunnel_xmitexport lwtunnel_input
Annotated Snippet
if (encap_type_str) {
request_module("rtnl-lwt-%s", encap_type_str);
ops = rcu_access_pointer(lwtun_encaps[encap_type]);
}
}
#endif
ret = ops ? 0 : -EOPNOTSUPP;
if (ret < 0)
NL_SET_ERR_MSG(extack, "lwt encapsulation type not supported");
return ret;
}
EXPORT_SYMBOL_GPL(lwtunnel_valid_encap_type);
int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int remaining,
struct netlink_ext_ack *extack)
{
struct rtnexthop *rtnh = (struct rtnexthop *)attr;
struct nlattr *nla_entype;
struct nlattr *attrs;
u16 encap_type;
int attrlen;
while (rtnh_ok(rtnh, remaining)) {
attrlen = rtnh_attrlen(rtnh);
if (attrlen > 0) {
attrs = rtnh_attrs(rtnh);
nla_entype = nla_find(attrs, attrlen, RTA_ENCAP_TYPE);
if (nla_entype) {
if (nla_len(nla_entype) < sizeof(u16)) {
NL_SET_ERR_MSG(extack, "Invalid RTA_ENCAP_TYPE");
return -EINVAL;
}
encap_type = nla_get_u16(nla_entype);
if (lwtunnel_valid_encap_type(encap_type, extack))
return -EOPNOTSUPP;
}
}
rtnh = rtnh_next(rtnh, &remaining);
}
return 0;
}
EXPORT_SYMBOL_GPL(lwtunnel_valid_encap_type_attr);
void lwtstate_free(struct lwtunnel_state *lws)
{
const struct lwtunnel_encap_ops *ops = lwtun_encaps[lws->type];
if (ops->destroy_state) {
ops->destroy_state(lws);
kfree_rcu(lws, rcu);
} else {
kfree(lws);
}
module_put(ops->owner);
}
EXPORT_SYMBOL_GPL(lwtstate_free);
int lwtunnel_fill_encap(struct sk_buff *skb, struct lwtunnel_state *lwtstate,
int encap_attr, int encap_type_attr)
{
const struct lwtunnel_encap_ops *ops;
struct nlattr *nest;
int ret;
if (!lwtstate)
return 0;
if (lwtstate->type == LWTUNNEL_ENCAP_NONE ||
lwtstate->type > LWTUNNEL_ENCAP_MAX)
return 0;
nest = nla_nest_start_noflag(skb, encap_attr);
if (!nest)
return -EMSGSIZE;
ret = -EOPNOTSUPP;
rcu_read_lock();
ops = rcu_dereference(lwtun_encaps[lwtstate->type]);
if (likely(ops && ops->fill_encap))
ret = ops->fill_encap(skb, lwtstate);
rcu_read_unlock();
if (ret)
goto nla_put_failure;
nla_nest_end(skb, nest);
ret = nla_put_u16(skb, encap_type_attr, lwtstate->type);
Annotation
- Immediate include surface: `linux/capability.h`, `linux/module.h`, `linux/types.h`, `linux/kernel.h`, `linux/slab.h`, `linux/uaccess.h`, `linux/skbuff.h`, `linux/netdevice.h`.
- Detected declarations: `function lwtunnel_encap_add_ops`, `function lwtunnel_encap_del_ops`, `function lwtunnel_build_state`, `function lwtunnel_valid_encap_type`, `function lwtunnel_valid_encap_type_attr`, `function lwtstate_free`, `function lwtunnel_fill_encap`, `function lwtunnel_get_encap_size`, `function lwtunnel_cmp_encap`, `function lwtunnel_output`.
- 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.