Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [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 | #define MAX_POLICIES 16 |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 18 | |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 19 | #define STRUCT_SIZE(name, size) _Static_assert(sizeof(name) == (size), "Incorrect struct size.") |
| 20 | |
Maciej Żenczykowski | 1feaa43 | 2022-07-29 21:17:07 +0000 | [diff] [blame] | 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 | |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 31 | typedef struct { |
Tyler Wear | 9228105 | 2022-06-22 15:32:14 -0700 | [diff] [blame] | 32 | struct in6_addr src_ip; |
| 33 | struct in6_addr dst_ip; |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 34 | uint32_t ifindex; |
Tyler Wear | 9228105 | 2022-06-22 15:32:14 -0700 | [diff] [blame] | 35 | __be16 src_port; |
Maciej Żenczykowski | a44510b | 2022-08-09 14:59:25 +0000 | [diff] [blame] | 36 | uint16_t dst_port_start; |
| 37 | uint16_t dst_port_end; |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 38 | uint8_t proto; |
Maciej Żenczykowski | d7b92c0 | 2022-07-27 19:57:15 +0000 | [diff] [blame] | 39 | int8_t dscp_val; // -1 none, or 0..63 DSCP value |
Maciej Żenczykowski | d6c0db3 | 2024-08-22 18:11:30 +0000 | [diff] [blame] | 40 | bool match_src_ip; |
| 41 | bool match_dst_ip; |
| 42 | bool match_src_port; |
| 43 | bool match_proto; |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 44 | } DscpPolicy; |
Maciej Żenczykowski | d6c0db3 | 2024-08-22 18:11:30 +0000 | [diff] [blame] | 45 | STRUCT_SIZE(DscpPolicy, 2 * 16 + 4 + 3 * 2 + 6 * 1); // 48 |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 46 | |
| 47 | typedef struct { |
Tyler Wear | 9228105 | 2022-06-22 15:32:14 -0700 | [diff] [blame] | 48 | struct in6_addr src_ip; |
| 49 | struct in6_addr dst_ip; |
Maciej Żenczykowski | 640752b | 2022-08-09 23:02:57 +0000 | [diff] [blame] | 50 | uint32_t ifindex; |
Tyler Wear | 9228105 | 2022-06-22 15:32:14 -0700 | [diff] [blame] | 51 | __be16 src_port; |
Maciej Żenczykowski | 640752b | 2022-08-09 23:02:57 +0000 | [diff] [blame] | 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]; |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 56 | } RuleEntry; |
Maciej Żenczykowski | d6c0db3 | 2024-08-22 18:11:30 +0000 | [diff] [blame] | 57 | STRUCT_SIZE(RuleEntry, 2 * 16 + 4 + 2 * 2 + 4 * 1); // 44 |