blob: dc431a768e4f61f688393cad974d3adcc4bd307d [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
Maciej Żenczykowskif75b7e12022-07-27 12:56:01 +000017#define CACHE_MAP_SIZE 1024
Tyler Wear3ad80892022-02-03 15:14:44 -080018#define MAX_POLICIES 16
Tyler Wear3ad80892022-02-03 15:14:44 -080019
Tyler Wear3ad80892022-02-03 15:14:44 -080020#define STRUCT_SIZE(name, size) _Static_assert(sizeof(name) == (size), "Incorrect struct size.")
21
Maciej Żenczykowski1feaa432022-07-29 21:17:07 +000022// 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 Wear3ad80892022-02-03 15:14:44 -080034
Tyler Wear3ad80892022-02-03 15:14:44 -080035typedef struct {
Tyler Wear92281052022-06-22 15:32:14 -070036 struct in6_addr src_ip;
37 struct in6_addr dst_ip;
Tyler Wear3ad80892022-02-03 15:14:44 -080038 uint32_t ifindex;
Tyler Wear92281052022-06-22 15:32:14 -070039 __be16 src_port;
Maciej Żenczykowskia44510b2022-08-09 14:59:25 +000040 uint16_t dst_port_start;
41 uint16_t dst_port_end;
Tyler Wear3ad80892022-02-03 15:14:44 -080042 uint8_t proto;
Maciej Żenczykowskid7b92c02022-07-27 19:57:15 +000043 int8_t dscp_val; // -1 none, or 0..63 DSCP value
Maciej Żenczykowskid6c0db32024-08-22 18:11:30 +000044 bool match_src_ip;
45 bool match_dst_ip;
46 bool match_src_port;
47 bool match_proto;
Tyler Wear3ad80892022-02-03 15:14:44 -080048} DscpPolicy;
Maciej Żenczykowskid6c0db32024-08-22 18:11:30 +000049STRUCT_SIZE(DscpPolicy, 2 * 16 + 4 + 3 * 2 + 6 * 1); // 48
Tyler Wear3ad80892022-02-03 15:14:44 -080050
51typedef struct {
Tyler Wear92281052022-06-22 15:32:14 -070052 struct in6_addr src_ip;
53 struct in6_addr dst_ip;
Maciej Żenczykowski640752b2022-08-09 23:02:57 +000054 uint32_t ifindex;
Tyler Wear92281052022-06-22 15:32:14 -070055 __be16 src_port;
Maciej Żenczykowski640752b2022-08-09 23:02:57 +000056 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 Wear3ad80892022-02-03 15:14:44 -080060} RuleEntry;
Maciej Żenczykowskid6c0db32024-08-22 18:11:30 +000061STRUCT_SIZE(RuleEntry, 2 * 16 + 4 + 2 * 2 + 4 * 1); // 44