tools/testing/selftests/bpf/prog_tests/vrf_socket_lookup.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/vrf_socket_lookup.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/vrf_socket_lookup.c- Extension
.c- Size
- 8913 bytes
- Lines
- 313
- 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
net/if.htest_progs.hnetwork_helpers.hvrf_socket_lookup.skel.h
Detected Declarations
function serverfunction make_serverfunction attach_progsfunction cleanupfunction setupfunction test_lookupfunction _test_vrf_socket_lookupfunction test_vrf_socket_lookup
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/*
* Topology:
* ---------
* NS0 namespace | NS1 namespace
* |
* +--------------+ | +--------------+
* | veth01 |----------| veth10 |
* | 172.16.1.100 | | | 172.16.1.200 |
* | bpf | | +--------------+
* +--------------+ |
* server(UDP/TCP) |
* +-------------------+ |
* | vrf1 | |
* | +--------------+ | | +--------------+
* | | veth02 |----------| veth20 |
* | | 172.16.2.100 | | | | 172.16.2.200 |
* | | bpf | | | +--------------+
* | +--------------+ | |
* | server(UDP/TCP) | |
* +-------------------+ |
*
* Test flow
* -----------
* The tests verifies that socket lookup via TC is VRF aware:
* 1) Creates two veth pairs between NS0 and NS1:
* a) veth01 <-> veth10 outside the VRF
* b) veth02 <-> veth20 in the VRF
* 2) Attaches to veth01 and veth02 a program that calls:
* a) bpf_skc_lookup_tcp() with TCP and tcp_skc is true
* b) bpf_sk_lookup_tcp() with TCP and tcp_skc is false
* c) bpf_sk_lookup_udp() with UDP
* The program stores the lookup result in bss->lookup_status.
* 3) Creates a socket TCP/UDP server in/outside the VRF.
* 4) The test expects lookup_status to be:
* a) 0 from device in VRF to server outside VRF
* b) 0 from device outside VRF to server in VRF
* c) 1 from device in VRF to server in VRF
* d) 1 from device outside VRF to server outside VRF
*/
#include <net/if.h>
#include "test_progs.h"
#include "network_helpers.h"
#include "vrf_socket_lookup.skel.h"
#define NS0 "vrf_socket_lookup_0"
#define NS1 "vrf_socket_lookup_1"
#define IP4_ADDR_VETH01 "172.16.1.100"
#define IP4_ADDR_VETH10 "172.16.1.200"
#define IP4_ADDR_VETH02 "172.16.2.100"
#define IP4_ADDR_VETH20 "172.16.2.200"
#define NON_VRF_PORT 5000
#define IN_VRF_PORT 5001
#define TIMEOUT_MS 3000
static int make_socket(int sotype, const char *ip, int port,
struct sockaddr_storage *addr)
{
int err, fd;
err = make_sockaddr(AF_INET, ip, port, addr, NULL);
if (!ASSERT_OK(err, "make_address"))
return -1;
fd = socket(AF_INET, sotype, 0);
if (!ASSERT_GE(fd, 0, "socket"))
return -1;
if (!ASSERT_OK(settimeo(fd, TIMEOUT_MS), "settimeo"))
goto fail;
return fd;
fail:
close(fd);
return -1;
}
static int make_server(int sotype, const char *ip, int port, const char *ifname)
{
int err, fd = -1;
fd = start_server(AF_INET, sotype, ip, port, TIMEOUT_MS);
if (!ASSERT_GE(fd, 0, "start_server"))
return -1;
Annotation
- Immediate include surface: `net/if.h`, `test_progs.h`, `network_helpers.h`, `vrf_socket_lookup.skel.h`.
- Detected declarations: `function server`, `function make_server`, `function attach_progs`, `function cleanup`, `function setup`, `function test_lookup`, `function _test_vrf_socket_lookup`, `function test_vrf_socket_lookup`.
- 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.