net/core/selftests.c
Source file repositories/reference/linux-study-clean/net/core/selftests.c
File Facts
- System
- Linux kernel
- Corpus path
net/core/selftests.c- Extension
.c- Size
- 10874 bytes
- Lines
- 449
- 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.
- 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/phy.hnet/selftests.hnet/tcp.hnet/udp.h
Detected Declarations
function net_test_loopback_validatefunction __net_test_loopbackfunction net_test_netif_carrierfunction net_test_phy_phydevfunction net_test_phy_loopback_enablefunction net_test_phy_loopback_disablefunction net_test_phy_loopback_udpfunction net_test_phy_loopback_udp_mtufunction net_test_phy_loopback_tcpfunction net_test_phy_loopback_tcp_bad_csumfunction net_selftestfunction net_selftest_get_countfunction net_selftest_get_stringsexport net_test_get_skbexport net_selftestexport net_selftest_get_countexport net_selftest_get_strings
Annotated Snippet
if (attr->bad_csum) {
/* Force mangled checksum */
if (skb_checksum_help(skb)) {
kfree_skb(skb);
return NULL;
}
if (thdr->check != CSUM_MANGLED_0)
thdr->check = CSUM_MANGLED_0;
else
thdr->check = csum16_sub(thdr->check,
cpu_to_be16(1));
}
} else {
udp4_hwcsum(skb, ihdr->saddr, ihdr->daddr);
}
skb->protocol = htons(ETH_P_IP);
skb->pkt_type = PACKET_HOST;
skb->dev = ndev;
return skb;
}
EXPORT_SYMBOL_GPL(net_test_get_skb);
static int net_test_loopback_validate(struct sk_buff *skb,
struct net_device *ndev,
struct packet_type *pt,
struct net_device *orig_ndev)
{
struct net_test_priv *tpriv = pt->af_packet_priv;
const unsigned char *src = tpriv->packet->src;
const unsigned char *dst = tpriv->packet->dst;
struct netsfhdr *shdr;
struct ethhdr *ehdr;
struct udphdr *uhdr;
struct tcphdr *thdr;
struct iphdr *ihdr;
skb = skb_unshare(skb, GFP_ATOMIC);
if (!skb)
goto out;
if (skb_linearize(skb))
goto out;
if (skb_headlen(skb) < (NET_TEST_PKT_SIZE - ETH_HLEN))
goto out;
ehdr = (struct ethhdr *)skb_mac_header(skb);
if (dst) {
if (!ether_addr_equal_unaligned(ehdr->h_dest, dst))
goto out;
}
if (src) {
if (!ether_addr_equal_unaligned(ehdr->h_source, src))
goto out;
}
ihdr = ip_hdr(skb);
if (tpriv->double_vlan)
ihdr = (struct iphdr *)(skb_network_header(skb) + 4);
if (tpriv->packet->tcp) {
if (ihdr->protocol != IPPROTO_TCP)
goto out;
thdr = (struct tcphdr *)((u8 *)ihdr + 4 * ihdr->ihl);
if (thdr->dest != htons(tpriv->packet->dport))
goto out;
shdr = (struct netsfhdr *)((u8 *)thdr + sizeof(*thdr));
} else {
if (ihdr->protocol != IPPROTO_UDP)
goto out;
uhdr = (struct udphdr *)((u8 *)ihdr + 4 * ihdr->ihl);
if (uhdr->dest != htons(tpriv->packet->dport))
goto out;
shdr = (struct netsfhdr *)((u8 *)uhdr + sizeof(*uhdr));
}
if (shdr->magic != cpu_to_be64(NET_TEST_PKT_MAGIC))
goto out;
if (tpriv->packet->id != shdr->id)
goto out;
if (tpriv->packet->bad_csum && skb->ip_summed == CHECKSUM_UNNECESSARY)
tpriv->ok = -EIO;
Annotation
- Immediate include surface: `linux/phy.h`, `net/selftests.h`, `net/tcp.h`, `net/udp.h`.
- Detected declarations: `function net_test_loopback_validate`, `function __net_test_loopback`, `function net_test_netif_carrier`, `function net_test_phy_phydev`, `function net_test_phy_loopback_enable`, `function net_test_phy_loopback_disable`, `function net_test_phy_loopback_udp`, `function net_test_phy_loopback_udp_mtu`, `function net_test_phy_loopback_tcp`, `function net_test_phy_loopback_tcp_bad_csum`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
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.