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 | |
Maciej Żenczykowski | f75b7e1 | 2022-07-27 12:56:01 +0000 | [diff] [blame] | 17 | #define CACHE_MAP_SIZE 1024 |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 18 | #define MAX_POLICIES 16 |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 19 | |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 20 | #define STRUCT_SIZE(name, size) _Static_assert(sizeof(name) == (size), "Incorrect struct size.") |
| 21 | |
Maciej Żenczykowski | 1feaa43 | 2022-07-29 21:17:07 +0000 | [diff] [blame] | 22 | // Retrieve the first (ie. high) 64 bits of an IPv6 address (in network order) |
| 23 | #define v6_hi_be64(v) (*(uint64_t*)&((v).s6_addr32[0])) |
| 24 | |
| 25 | // Retrieve the last (ie. low) 64 bits of an IPv6 address (in network order) |
| 26 | #define v6_lo_be64(v) (*(uint64_t*)&((v).s6_addr32[2])) |
| 27 | |
| 28 | // This returns a non-zero u64 iff a != b |
| 29 | #define v6_not_equal(a, b) ((v6_hi_be64(a) ^ v6_hi_be64(b)) \ |
| 30 | | (v6_lo_be64(a) ^ v6_lo_be64(b))) |
| 31 | |
| 32 | // Returns 'a == b' as boolean |
| 33 | #define v6_equal(a, b) (!v6_not_equal((a), (b))) |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 34 | |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 35 | typedef struct { |
Tyler Wear | 9228105 | 2022-06-22 15:32:14 -0700 | [diff] [blame] | 36 | struct in6_addr src_ip; |
| 37 | struct in6_addr dst_ip; |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 38 | uint32_t ifindex; |
Tyler Wear | 9228105 | 2022-06-22 15:32:14 -0700 | [diff] [blame] | 39 | __be16 src_port; |
Maciej Żenczykowski | a44510b | 2022-08-09 14:59:25 +0000 | [diff] [blame] | 40 | uint16_t dst_port_start; |
| 41 | uint16_t dst_port_end; |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 42 | uint8_t proto; |
Maciej Żenczykowski | d7b92c0 | 2022-07-27 19:57:15 +0000 | [diff] [blame] | 43 | int8_t dscp_val; // -1 none, or 0..63 DSCP value |
Maciej Żenczykowski | d6c0db3 | 2024-08-22 18:11:30 +0000 | [diff] [blame^] | 44 | bool match_src_ip; |
| 45 | bool match_dst_ip; |
| 46 | bool match_src_port; |
| 47 | bool match_proto; |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 48 | } DscpPolicy; |
Maciej Żenczykowski | d6c0db3 | 2024-08-22 18:11:30 +0000 | [diff] [blame^] | 49 | STRUCT_SIZE(DscpPolicy, 2 * 16 + 4 + 3 * 2 + 6 * 1); // 48 |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 50 | |
| 51 | typedef struct { |
Tyler Wear | 9228105 | 2022-06-22 15:32:14 -0700 | [diff] [blame] | 52 | struct in6_addr src_ip; |
| 53 | struct in6_addr dst_ip; |
Maciej Żenczykowski | 640752b | 2022-08-09 23:02:57 +0000 | [diff] [blame] | 54 | uint32_t ifindex; |
Tyler Wear | 9228105 | 2022-06-22 15:32:14 -0700 | [diff] [blame] | 55 | __be16 src_port; |
Maciej Żenczykowski | 640752b | 2022-08-09 23:02:57 +0000 | [diff] [blame] | 56 | uint16_t dst_port; |
| 57 | uint8_t proto; |
| 58 | int8_t dscp_val; // -1 none, or 0..63 DSCP value |
| 59 | uint8_t pad[2]; |
Tyler Wear | 3ad8089 | 2022-02-03 15:14:44 -0800 | [diff] [blame] | 60 | } RuleEntry; |
Maciej Żenczykowski | d6c0db3 | 2024-08-22 18:11:30 +0000 | [diff] [blame^] | 61 | STRUCT_SIZE(RuleEntry, 2 * 16 + 4 + 2 * 2 + 4 * 1); // 44 |