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 uint64_t packets; // Count of translated gso (large) packets 43 uint64_t bytes; // Sum of post-translation skb->len 44 } ClatIngress6Value; 45 STRUCT_SIZE(ClatIngress6Value, 4 + 4 + 8 + 8); // 24 46 47 typedef struct { 48 uint32_t iif; // The input interface index 49 struct in_addr local4; // The source IPv4 address 50 } ClatEgress4Key; 51 STRUCT_SIZE(ClatEgress4Key, 4 + 4); // 8 52 53 typedef 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]; 59 uint64_t packets; // Count of translated gso (large) packets 60 uint64_t bytes; // Sum of post-translation skb->len 61 } ClatEgress4Value; 62 STRUCT_SIZE(ClatEgress4Value, 4 + 2 * 16 + 1 + 3 + 8 + 8); // 56 63 64 #undef STRUCT_SIZE 65