blob: a75798f137dea66bdc9ab952d41c2c26806fb1e5 [file] [log] [blame]
Maciej Żenczykowski7b452a12022-12-08 13:10:29 +00001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <linux/in.h>
20#include <linux/in6.h>
21
22#include <stdbool.h>
23#include <stdint.h>
24
25// This header file is shared by eBPF kernel programs (C) and netd (C++) and
26// some of the maps are also accessed directly from Java mainline module code.
27//
28// Hence: explicitly pad all relevant structures and assert that their size
29// is the sum of the sizes of their fields.
30#define STRUCT_SIZE(name, size) _Static_assert(sizeof(name) == (size), "Incorrect struct size.")
31
32typedef struct {
33 uint32_t iif; // The input interface index
34 struct in6_addr pfx96; // The source /96 nat64 prefix, bottom 32 bits must be 0
35 struct in6_addr local6; // The full 128-bits of the destination IPv6 address
36} ClatIngress6Key;
37STRUCT_SIZE(ClatIngress6Key, 4 + 2 * 16); // 36
38
39typedef struct {
40 uint32_t oif; // The output interface to redirect to (0 means don't redirect)
41 struct in_addr local4; // The destination IPv4 address
Maciej Żenczykowski8b3f9d92024-03-13 03:39:36 +000042 uint64_t packets; // Count of translated gso (large) packets
43 uint64_t bytes; // Sum of post-translation skb->len
Maciej Żenczykowski7b452a12022-12-08 13:10:29 +000044} ClatIngress6Value;
Maciej Żenczykowski8b3f9d92024-03-13 03:39:36 +000045STRUCT_SIZE(ClatIngress6Value, 4 + 4 + 8 + 8); // 24
Maciej Żenczykowski7b452a12022-12-08 13:10:29 +000046
47typedef struct {
48 uint32_t iif; // The input interface index
49 struct in_addr local4; // The source IPv4 address
50} ClatEgress4Key;
51STRUCT_SIZE(ClatEgress4Key, 4 + 4); // 8
52
53typedef struct {
54 uint32_t oif; // The output interface to redirect to
55 struct in6_addr local6; // The full 128-bits of the source IPv6 address
56 struct in6_addr pfx96; // The destination /96 nat64 prefix, bottom 32 bits must be 0
57 bool oifIsEthernet; // Whether the output interface requires ethernet header
58 uint8_t pad[3];
Maciej Żenczykowski8b3f9d92024-03-13 03:39:36 +000059 uint64_t packets; // Count of translated gso (large) packets
60 uint64_t bytes; // Sum of post-translation skb->len
Maciej Żenczykowski7b452a12022-12-08 13:10:29 +000061} ClatEgress4Value;
Maciej Żenczykowski8b3f9d92024-03-13 03:39:36 +000062STRUCT_SIZE(ClatEgress4Value, 4 + 2 * 16 + 1 + 3 + 8 + 8); // 56
Maciej Żenczykowski7b452a12022-12-08 13:10:29 +000063
64#undef STRUCT_SIZE