tools/testing/selftests/net/tcp_ao/key-management.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/tcp_ao/key-management.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/tcp_ao/key-management.c- Extension
.c- Size
- 34253 bytes
- Lines
- 1164
- 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
inttypes.h../../../../include/linux/kernel.haolib.h
Detected Declarations
struct test_keystruct key_collectionfunction setup_vrfsfunction prepare_skfunction prepare_lskfunction test_del_keyfunction try_delete_keyfunction test_set_keyfunction test_add_current_rnext_keyfunction __try_add_current_rnext_keyfunction try_add_current_rnext_keyfunction check_closed_socketfunction assert_no_current_rnextfunction assert_no_tcp_repairfunction check_listen_socketfunction make_maskfunction init_key_in_collectionfunction init_default_key_collectionfunction test_key_errorfunction test_add_key_crfunction verify_current_rnextfunction key_collection_socketfunction verify_countersfunction verify_keysfunction start_serverfunction end_serverfunction try_server_runfunction server_rotationsfunction run_clientfunction start_clientfunction end_clientfunction try_unmatched_keysfunction client_non_matchingfunction check_current_backfunction roll_over_keysfunction try_client_runfunction try_client_matchfunction check_established_socketfunction main
Annotated Snippet
struct test_key {
char password[TCP_AO_MAXKEYLEN];
const char *alg;
unsigned int len;
uint8_t client_keyid;
uint8_t server_keyid;
uint8_t maclen;
uint8_t matches_client : 1,
matches_server : 1,
matches_vrf : 1,
is_current : 1,
is_rnext : 1,
used_on_server_tx : 1,
used_on_client_tx : 1,
skip_counters_checks : 1;
};
struct key_collection {
unsigned int nr_keys;
struct test_key *keys;
};
static struct key_collection collection;
#define TEST_MAX_MACLEN 16
const char *test_algos[] = { "cmac(aes128)", "hmac(sha1)", "hmac(sha256)" };
const unsigned int test_maclens[] = { 1, 4, 12, 16 };
#define MACLEN_SHIFT 2
#define ALGOS_SHIFT 4
static unsigned int make_mask(unsigned int shift, unsigned int prev_shift)
{
unsigned int ret = BIT(shift) - 1;
return ret << prev_shift;
}
static void init_key_in_collection(unsigned int index, bool randomized)
{
struct test_key *key = &collection.keys[index];
unsigned int algos_index;
/* Same for randomized and non-randomized test flows */
key->client_keyid = index;
key->server_keyid = 127 + index;
key->matches_client = 1;
key->matches_server = 1;
key->matches_vrf = 1;
/* not really even random, but good enough for a test */
key->len = rand() % (TCP_AO_MAXKEYLEN - TEST_TCP_AO_MINKEYLEN);
key->len += TEST_TCP_AO_MINKEYLEN;
randomize_buffer(key->password, key->len);
if (randomized) {
key->maclen = (rand() % TEST_MAX_MACLEN) + 1;
algos_index = rand();
} else {
unsigned int shift = MACLEN_SHIFT;
key->maclen = test_maclens[index & make_mask(shift, 0)];
algos_index = index & make_mask(ALGOS_SHIFT, shift);
}
key->alg = test_algos[algos_index % ARRAY_SIZE(test_algos)];
}
static int init_default_key_collection(unsigned int nr_keys, bool randomized)
{
size_t key_sz = sizeof(collection.keys[0]);
if (!nr_keys) {
free(collection.keys);
collection.keys = NULL;
return 0;
}
/*
* All keys have uniq sndid/rcvid and sndid != rcvid in order to
* check for any bugs/issues for different keyids, visible to both
* peers. Keyid == 254 is unused.
*/
if (nr_keys > 127)
test_error("Test requires too many keys, correct the source");
collection.keys = reallocarray(collection.keys, nr_keys, key_sz);
if (!collection.keys)
return -ENOMEM;
memset(collection.keys, 0, nr_keys * key_sz);
collection.nr_keys = nr_keys;
while (nr_keys--)
Annotation
- Immediate include surface: `inttypes.h`, `../../../../include/linux/kernel.h`, `aolib.h`.
- Detected declarations: `struct test_key`, `struct key_collection`, `function setup_vrfs`, `function prepare_sk`, `function prepare_lsk`, `function test_del_key`, `function try_delete_key`, `function test_set_key`, `function test_add_current_rnext_key`, `function __try_add_current_rnext_key`.
- 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.