| Maciej Żenczykowski | 7b452a1 | 2022-12-08 13:10:29 +0000 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 32 | typedef 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; | 
|  | 37 | STRUCT_SIZE(ClatIngress6Key, 4 + 2 * 16);  // 36 | 
|  | 38 |  | 
|  | 39 | typedef 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 | 
|  | 42 | } ClatIngress6Value; | 
|  | 43 | STRUCT_SIZE(ClatIngress6Value, 4 + 4);  // 8 | 
|  | 44 |  | 
|  | 45 | typedef struct { | 
|  | 46 | uint32_t iif;           // The input interface index | 
|  | 47 | struct in_addr local4;  // The source IPv4 address | 
|  | 48 | } ClatEgress4Key; | 
|  | 49 | STRUCT_SIZE(ClatEgress4Key, 4 + 4);  // 8 | 
|  | 50 |  | 
|  | 51 | typedef struct { | 
|  | 52 | uint32_t oif;            // The output interface to redirect to | 
|  | 53 | struct in6_addr local6;  // The full 128-bits of the source IPv6 address | 
|  | 54 | struct in6_addr pfx96;   // The destination /96 nat64 prefix, bottom 32 bits must be 0 | 
|  | 55 | bool oifIsEthernet;      // Whether the output interface requires ethernet header | 
|  | 56 | uint8_t pad[3]; | 
|  | 57 | } ClatEgress4Value; | 
|  | 58 | STRUCT_SIZE(ClatEgress4Value, 4 + 2 * 16 + 1 + 3);  // 40 | 
|  | 59 |  | 
|  | 60 | #undef STRUCT_SIZE |