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 #define MAX_POLICIES 16 18 19 #define STRUCT_SIZE(name, size) _Static_assert(sizeof(name) == (size), "Incorrect struct size.") 20 21 // Retrieve the first (ie. high) 64 bits of an IPv6 address (in network order) 22 #define v6_hi_be64(v) (*(uint64_t*)&((v).s6_addr32[0])) 23 24 // Retrieve the last (ie. low) 64 bits of an IPv6 address (in network order) 25 #define v6_lo_be64(v) (*(uint64_t*)&((v).s6_addr32[2])) 26 27 // This returns a non-zero u64 iff a != b 28 #define v6_not_equal(a, b) ((v6_hi_be64(a) ^ v6_hi_be64(b)) \ 29 | (v6_lo_be64(a) ^ v6_lo_be64(b))) 30 31 typedef struct { 32 struct in6_addr src_ip; 33 struct in6_addr dst_ip; 34 uint32_t ifindex; 35 __be16 src_port; 36 uint16_t dst_port_start; 37 uint16_t dst_port_end; 38 uint8_t proto; 39 int8_t dscp_val; // -1 none, or 0..63 DSCP value 40 bool match_src_ip; 41 bool match_dst_ip; 42 bool match_src_port; 43 bool match_proto; 44 } DscpPolicy; 45 STRUCT_SIZE(DscpPolicy, 2 * 16 + 4 + 3 * 2 + 6 * 1); // 48 46 47 typedef struct { 48 struct in6_addr src_ip; 49 struct in6_addr dst_ip; 50 uint32_t ifindex; 51 __be16 src_port; 52 uint16_t dst_port; 53 uint8_t proto; 54 int8_t dscp_val; // -1 none, or 0..63 DSCP value 55 uint8_t pad[2]; 56 } RuleEntry; 57 STRUCT_SIZE(RuleEntry, 2 * 16 + 4 + 2 * 2 + 4 * 1); // 44 58