include/net/checksum.h
Source file repositories/reference/linux-study-clean/include/net/checksum.h
File Facts
- System
- Linux kernel
- Corpus path
include/net/checksum.h- Extension
.h- Size
- 4961 bytes
- Lines
- 192
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/errno.hasm/types.hasm/byteorder.hasm/checksum.hlinux/uaccess.h
Detected Declarations
struct sk_bufffunction csum_and_copy_from_userfunction csum_and_copy_to_userfunction csum_partial_copy_nocheckfunction csum_addfunction csum_subfunction csum16_addfunction csum16_subfunction csum_shiftfunction csum_block_addfunction csum_block_subfunction csum_unfoldfunction csum_replace_by_difffunction csum_replace4function csum_replace2function csum_replacefunction csum_from32to16function inet_proto_csum_replace2function remcsum_adjustfunction remcsum_unadjustfunction wsum_negate
Annotated Snippet
#ifndef _CHECKSUM_H
#define _CHECKSUM_H
#include <linux/errno.h>
#include <asm/types.h>
#include <asm/byteorder.h>
#include <asm/checksum.h>
#if !defined(_HAVE_ARCH_COPY_AND_CSUM_FROM_USER) || !defined(HAVE_CSUM_COPY_USER)
#include <linux/uaccess.h>
#endif
#ifndef _HAVE_ARCH_COPY_AND_CSUM_FROM_USER
static __always_inline
__wsum csum_and_copy_from_user (const void __user *src, void *dst,
int len)
{
if (copy_from_user(dst, src, len))
return 0;
return csum_partial(dst, len, ~0U);
}
#endif
#ifndef HAVE_CSUM_COPY_USER
static __always_inline __wsum csum_and_copy_to_user
(const void *src, void __user *dst, int len)
{
__wsum sum = csum_partial(src, len, ~0U);
if (copy_to_user(dst, src, len) == 0)
return sum;
return 0;
}
#endif
#ifndef _HAVE_ARCH_CSUM_AND_COPY
static __always_inline __wsum
csum_partial_copy_nocheck(const void *src, void *dst, int len)
{
memcpy(dst, src, len);
return csum_partial(dst, len, 0);
}
#endif
#ifndef HAVE_ARCH_CSUM_ADD
static __always_inline __wsum csum_add(__wsum csum, __wsum addend)
{
u32 res = (__force u32)csum;
res += (__force u32)addend;
return (__force __wsum)(res + (res < (__force u32)addend));
}
#endif
static __always_inline __wsum csum_sub(__wsum csum, __wsum addend)
{
return csum_add(csum, ~addend);
}
static __always_inline __sum16 csum16_add(__sum16 csum, __be16 addend)
{
u16 res = (__force u16)csum;
res += (__force u16)addend;
return (__force __sum16)(res + (res < (__force u16)addend));
}
static __always_inline __sum16 csum16_sub(__sum16 csum, __be16 addend)
{
return csum16_add(csum, ~addend);
}
#ifndef HAVE_ARCH_CSUM_SHIFT
static __always_inline __wsum csum_shift(__wsum sum, int offset)
{
/* rotate sum to align it with a 16b boundary */
if (offset & 1)
return (__force __wsum)ror32((__force u32)sum, 8);
return sum;
}
#endif
static __always_inline __wsum
csum_block_add(__wsum csum, __wsum csum2, int offset)
{
return csum_add(csum, csum_shift(csum2, offset));
}
static __always_inline __wsum
csum_block_sub(__wsum csum, __wsum csum2, int offset)
{
return csum_block_add(csum, ~csum2, offset);
Annotation
- Immediate include surface: `linux/errno.h`, `asm/types.h`, `asm/byteorder.h`, `asm/checksum.h`, `linux/uaccess.h`.
- Detected declarations: `struct sk_buff`, `function csum_and_copy_from_user`, `function csum_and_copy_to_user`, `function csum_partial_copy_nocheck`, `function csum_add`, `function csum_sub`, `function csum16_add`, `function csum16_sub`, `function csum_shift`, `function csum_block_add`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.