blob: 413fb0f5fad6b08eb90cee87c97fcb13b62ddb95 [file] [log] [blame]
Tyler Wear3ad80892022-02-03 15:14:44 -08001/*
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 Wear3ad80892022-02-03 15:14:44 -080018
Tyler Wear3ad80892022-02-03 15:14:44 -080019#define STRUCT_SIZE(name, size) _Static_assert(sizeof(name) == (size), "Incorrect struct size.")
20
Maciej Żenczykowski1feaa432022-07-29 21:17:07 +000021// 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 Wear3ad80892022-02-03 15:14:44 -080031typedef struct {
Tyler Wear92281052022-06-22 15:32:14 -070032 struct in6_addr src_ip;
33 struct in6_addr dst_ip;
Tyler Wear3ad80892022-02-03 15:14:44 -080034 uint32_t ifindex;
Tyler Wear92281052022-06-22 15:32:14 -070035 __be16 src_port;
Maciej Żenczykowskia44510b2022-08-09 14:59:25 +000036 uint16_t dst_port_start;
37 uint16_t dst_port_end;
Tyler Wear3ad80892022-02-03 15:14:44 -080038 uint8_t proto;
Maciej Żenczykowskid7b92c02022-07-27 19:57:15 +000039 int8_t dscp_val; // -1 none, or 0..63 DSCP value
Maciej Żenczykowskid6c0db32024-08-22 18:11:30 +000040 bool match_src_ip;
41 bool match_dst_ip;
42 bool match_src_port;
43 bool match_proto;
Tyler Wear3ad80892022-02-03 15:14:44 -080044} DscpPolicy;
Maciej Żenczykowskid6c0db32024-08-22 18:11:30 +000045STRUCT_SIZE(DscpPolicy, 2 * 16 + 4 + 3 * 2 + 6 * 1); // 48
Tyler Wear3ad80892022-02-03 15:14:44 -080046
47typedef struct {
Tyler Wear92281052022-06-22 15:32:14 -070048 struct in6_addr src_ip;
49 struct in6_addr dst_ip;
Maciej Żenczykowski640752b2022-08-09 23:02:57 +000050 uint32_t ifindex;
Tyler Wear92281052022-06-22 15:32:14 -070051 __be16 src_port;
Maciej Żenczykowski640752b2022-08-09 23:02:57 +000052 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 Wear3ad80892022-02-03 15:14:44 -080056} RuleEntry;
Maciej Żenczykowskid6c0db32024-08-22 18:11:30 +000057STRUCT_SIZE(RuleEntry, 2 * 16 + 4 + 2 * 2 + 4 * 1); // 44