tools/testing/selftests/net/tuntap_helpers.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/tuntap_helpers.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/tuntap_helpers.h- Extension
.h- Size
- 9881 bytes
- Lines
- 391
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hlinux/if_packet.hlinux/ipv6.hlinux/virtio_net.hnetinet/in.hnetinet/if_ether.hnetinet/udp.hstdio.hstdlib.hstring.hunistd.hynl.hrt-route-user.hrt-addr-user.hrt-neigh-user.hrt-link-user.h
Detected Declarations
function ip_addr_lenfunction fill_ifaddr_msgfunction ip_addr_addfunction fill_neigh_req_headerfunction ip_neigh_addfunction fill_route_req_headerfunction ip_route_getfunction ip_link_addfunction ip_link_delfunction build_ethfunction add_csumfunction finish_ip_csumfunction build_ip_csumfunction build_ipv4_headerfunction ipv6_set_dsfieldfunction build_ipv6_headerfunction build_geneve_headerfunction build_udp_headerfunction build_udp_packet_csumfunction build_udp_packetfunction build_virtio_net_hdr_v1_hash_tunnel
Annotated Snippet
#ifndef _TUNTAP_HELPERS_H
#define _TUNTAP_HELPERS_H
#include <errno.h>
#include <linux/if_packet.h>
#include <linux/ipv6.h>
#include <linux/virtio_net.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netinet/udp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ynl.h>
#include "rt-route-user.h"
#include "rt-addr-user.h"
#include "rt-neigh-user.h"
#include "rt-link-user.h"
#define GENEVE_HLEN 8
#define PKT_DATA 0xCB
#define TUNTAP_DEFAULT_TTL 8
#define TUNTAP_DEFAULT_IPID 1337
unsigned int if_nametoindex(const char *ifname);
static inline int ip_addr_len(int family)
{
return (family == AF_INET) ? sizeof(struct in_addr) :
sizeof(struct in6_addr);
}
static inline void fill_ifaddr_msg(struct ifaddrmsg *ifam, int family,
int prefix, int flags, const char *dev)
{
ifam->ifa_family = family;
ifam->ifa_prefixlen = prefix;
ifam->ifa_index = if_nametoindex(dev);
ifam->ifa_flags = flags;
ifam->ifa_scope = RT_SCOPE_UNIVERSE;
}
static inline int ip_addr_add(const char *dev, int family, void *addr,
uint8_t prefix)
{
int nl_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
int ifa_flags = IFA_F_PERMANENT | IFA_F_NODAD;
int ret = -1, ipalen = ip_addr_len(family);
struct rt_addr_newaddr_req *req;
struct ynl_sock *ys;
ys = ynl_sock_create(&ynl_rt_addr_family, NULL);
if (!ys)
return -1;
req = rt_addr_newaddr_req_alloc();
if (!req)
goto err_req_alloc;
fill_ifaddr_msg(&req->_hdr, family, prefix, ifa_flags, dev);
rt_addr_newaddr_req_set_nlflags(req, nl_flags);
rt_addr_newaddr_req_set_local(req, addr, ipalen);
ret = rt_addr_newaddr(ys, req);
rt_addr_newaddr_req_free(req);
err_req_alloc:
ynl_sock_destroy(ys);
return ret;
}
static inline void fill_neigh_req_header(struct ndmsg *ndm, int family,
int state, const char *dev)
{
ndm->ndm_family = family;
ndm->ndm_ifindex = if_nametoindex(dev);
ndm->ndm_state = state;
ndm->ndm_flags = 0;
ndm->ndm_type = RTN_UNICAST;
}
static inline int ip_neigh_add(const char *dev, int family, void *addr,
unsigned char *lladdr)
{
int nl_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;
int ret = -1, ipalen = ip_addr_len(family);
struct rt_neigh_newneigh_req *req;
struct ynl_sock *ys;
Annotation
- Immediate include surface: `errno.h`, `linux/if_packet.h`, `linux/ipv6.h`, `linux/virtio_net.h`, `netinet/in.h`, `netinet/if_ether.h`, `netinet/udp.h`, `stdio.h`.
- Detected declarations: `function ip_addr_len`, `function fill_ifaddr_msg`, `function ip_addr_add`, `function fill_neigh_req_header`, `function ip_neigh_add`, `function fill_route_req_header`, `function ip_route_get`, `function ip_link_add`, `function ip_link_del`, `function build_eth`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.