net/ipv6/seg6_hmac.c
Source file repositories/reference/linux-study-clean/net/ipv6/seg6_hmac.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv6/seg6_hmac.c- Extension
.c- Size
- 7414 bytes
- Lines
- 322
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/errno.hlinux/kernel.hlinux/types.hlinux/socket.hlinux/sockios.hlinux/net.hlinux/netdevice.hlinux/in6.hlinux/icmpv6.hlinux/mroute6.hlinux/rhashtable.hlinux/netfilter.hlinux/netfilter_ipv6.hnet/sock.hnet/snmp.hnet/ipv6.hnet/protocol.hnet/transp_v6.hnet/rawv6.hnet/ndisc.hnet/ip6_route.hnet/addrconf.hnet/xfrm.hcrypto/sha1.hcrypto/sha2.hcrypto/utils.hnet/seg6.hnet/genetlink.hnet/seg6_hmac.hlinux/random.h
Detected Declarations
struct hmac_storagefunction seg6_hmac_cmpfnfunction seg6_hinfo_releasefunction seg6_free_hifunction seg6_hmac_computefunction rcu_read_lockfunction seg6_hmac_info_addfunction seg6_hmac_info_delfunction seg6_push_hmacfunction seg6_hmac_net_initfunction seg6_hmac_net_exitexport seg6_hmac_computeexport seg6_hmac_validate_skbexport seg6_hmac_info_lookupexport seg6_hmac_info_addexport seg6_hmac_info_delexport seg6_push_hmacexport seg6_hmac_net_exit
Annotated Snippet
struct hmac_storage {
local_lock_t bh_lock;
char hmac_ring[SEG6_HMAC_RING_SIZE];
};
static DEFINE_PER_CPU(struct hmac_storage, hmac_storage) = {
.bh_lock = INIT_LOCAL_LOCK(bh_lock),
};
static int seg6_hmac_cmpfn(struct rhashtable_compare_arg *arg, const void *obj)
{
const struct seg6_hmac_info *hinfo = obj;
return (hinfo->hmackeyid != *(__u32 *)arg->key);
}
static inline void seg6_hinfo_release(struct seg6_hmac_info *hinfo)
{
kfree_rcu(hinfo, rcu);
}
static void seg6_free_hi(void *ptr, void *arg)
{
struct seg6_hmac_info *hinfo = (struct seg6_hmac_info *)ptr;
if (hinfo)
seg6_hinfo_release(hinfo);
}
static const struct rhashtable_params rht_params = {
.head_offset = offsetof(struct seg6_hmac_info, node),
.key_offset = offsetof(struct seg6_hmac_info, hmackeyid),
.key_len = sizeof(u32),
.automatic_shrinking = true,
.obj_cmpfn = seg6_hmac_cmpfn,
};
static struct sr6_tlv_hmac *seg6_get_tlv_hmac(struct ipv6_sr_hdr *srh)
{
struct sr6_tlv_hmac *tlv;
if (srh->hdrlen < (srh->first_segment + 1) * 2 + 5)
return NULL;
if (!sr_has_hmac(srh))
return NULL;
tlv = (struct sr6_tlv_hmac *)
((char *)srh + ((srh->hdrlen + 1) << 3) - 40);
if (tlv->tlvhdr.type != SR6_TLV_HMAC || tlv->tlvhdr.len != 38)
return NULL;
return tlv;
}
int seg6_hmac_compute(struct seg6_hmac_info *hinfo, struct ipv6_sr_hdr *hdr,
struct in6_addr *saddr, u8 *output)
{
__be32 hmackeyid = cpu_to_be32(hinfo->hmackeyid);
int plen, i, ret = 0;
char *ring, *off;
/* saddr(16) + first_seg(1) + flags(1) + keyid(4) + seglist(16n) */
plen = 16 + 1 + 1 + 4 + (hdr->first_segment + 1) * 16;
/* this limit allows for 14 segments */
if (plen >= SEG6_HMAC_RING_SIZE)
return -EMSGSIZE;
/* Let's build the HMAC text on the ring buffer. The text is composed
* as follows, in order:
*
* 1. Source IPv6 address (128 bits)
* 2. first_segment value (8 bits)
* 3. Flags (8 bits)
* 4. HMAC Key ID (32 bits)
* 5. All segments in the segments list (n * 128 bits)
*/
local_bh_disable();
local_lock_nested_bh(&hmac_storage.bh_lock);
ring = this_cpu_ptr(hmac_storage.hmac_ring);
off = ring;
/* source address */
memcpy(off, saddr, 16);
off += 16;
/* first_segment value */
Annotation
- Immediate include surface: `linux/errno.h`, `linux/kernel.h`, `linux/types.h`, `linux/socket.h`, `linux/sockios.h`, `linux/net.h`, `linux/netdevice.h`, `linux/in6.h`.
- Detected declarations: `struct hmac_storage`, `function seg6_hmac_cmpfn`, `function seg6_hinfo_release`, `function seg6_free_hi`, `function seg6_hmac_compute`, `function rcu_read_lock`, `function seg6_hmac_info_add`, `function seg6_hmac_info_del`, `function seg6_push_hmac`, `function seg6_hmac_net_init`.
- 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.