net/ipv6/rpl.c
Source file repositories/reference/linux-study-clean/net/ipv6/rpl.c
File Facts
- System
- Linux kernel
- Corpus path
net/ipv6/rpl.c- Extension
.c- Size
- 3112 bytes
- Lines
- 119
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
net/ipv6.hnet/rpl.h
Detected Declarations
function ipv6_rpl_addr_decompressfunction ipv6_rpl_addr_compressfunction ipv6_rpl_srh_decompressfunction ipv6_rpl_srh_calc_cmprifunction ipv6_rpl_srh_calc_cmprefunction ipv6_rpl_srh_compress
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Authors:
* (C) 2020 Alexander Aring <alex.aring@gmail.com>
*/
#include <net/ipv6.h>
#include <net/rpl.h>
#define IPV6_PFXTAIL_LEN(x) (sizeof(struct in6_addr) - (x))
#define IPV6_RPL_BEST_ADDR_COMPRESSION 15
static void ipv6_rpl_addr_decompress(struct in6_addr *dst,
const struct in6_addr *daddr,
const void *post, unsigned char pfx)
{
memcpy(dst, daddr, pfx);
memcpy(&dst->s6_addr[pfx], post, IPV6_PFXTAIL_LEN(pfx));
}
static void ipv6_rpl_addr_compress(void *dst, const struct in6_addr *addr,
unsigned char pfx)
{
memcpy(dst, &addr->s6_addr[pfx], IPV6_PFXTAIL_LEN(pfx));
}
static void *ipv6_rpl_segdata_pos(const struct ipv6_rpl_sr_hdr *hdr, int i)
{
return (void *)&hdr->rpl_segdata[i * IPV6_PFXTAIL_LEN(hdr->cmpri)];
}
void ipv6_rpl_srh_decompress(struct ipv6_rpl_sr_hdr *outhdr,
const struct ipv6_rpl_sr_hdr *inhdr,
const struct in6_addr *daddr, unsigned char n)
{
int i;
outhdr->nexthdr = inhdr->nexthdr;
outhdr->hdrlen = (((n + 1) * sizeof(struct in6_addr)) >> 3);
outhdr->pad = 0;
outhdr->type = inhdr->type;
outhdr->segments_left = inhdr->segments_left;
outhdr->cmpri = 0;
outhdr->cmpre = 0;
for (i = 0; i < n; i++)
ipv6_rpl_addr_decompress(&outhdr->rpl_segaddr[i], daddr,
ipv6_rpl_segdata_pos(inhdr, i),
inhdr->cmpri);
ipv6_rpl_addr_decompress(&outhdr->rpl_segaddr[n], daddr,
ipv6_rpl_segdata_pos(inhdr, n),
inhdr->cmpre);
}
static unsigned char ipv6_rpl_srh_calc_cmpri(const struct ipv6_rpl_sr_hdr *inhdr,
const struct in6_addr *daddr,
unsigned char n)
{
unsigned char plen;
int i;
for (plen = 0; plen < sizeof(*daddr); plen++) {
for (i = 0; i < n; i++) {
if (daddr->s6_addr[plen] !=
inhdr->rpl_segaddr[i].s6_addr[plen])
return plen;
}
}
return IPV6_RPL_BEST_ADDR_COMPRESSION;
}
static unsigned char ipv6_rpl_srh_calc_cmpre(const struct in6_addr *daddr,
const struct in6_addr *last_segment)
{
unsigned int plen;
for (plen = 0; plen < sizeof(*daddr); plen++) {
if (daddr->s6_addr[plen] != last_segment->s6_addr[plen])
return plen;
}
return IPV6_RPL_BEST_ADDR_COMPRESSION;
}
void ipv6_rpl_srh_compress(struct ipv6_rpl_sr_hdr *outhdr,
const struct ipv6_rpl_sr_hdr *inhdr,
const struct in6_addr *daddr, unsigned char n)
{
Annotation
- Immediate include surface: `net/ipv6.h`, `net/rpl.h`.
- Detected declarations: `function ipv6_rpl_addr_decompress`, `function ipv6_rpl_addr_compress`, `function ipv6_rpl_srh_decompress`, `function ipv6_rpl_srh_calc_cmpri`, `function ipv6_rpl_srh_calc_cmpre`, `function ipv6_rpl_srh_compress`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.