]>
Commit | Line | Data |
---|---|---|
942bf97b | 1 | /* |
2 | * Zebra Policy Based Routing (PBR) Data structures and definitions | |
3 | * These are public definitions referenced by multiple files. | |
4 | * Copyright (C) 2018 Cumulus Networks, Inc. | |
5 | * | |
6 | * This file is part of FRR. | |
7 | * | |
8 | * FRR is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * FRR is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with FRR; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
21 | * 02111-1307, USA. | |
22 | */ | |
23 | ||
24 | #ifndef _ZEBRA_PBR_H | |
25 | #define _ZEBRA_PBR_H | |
26 | ||
27 | #include <zebra.h> | |
28 | ||
29 | #include "prefix.h" | |
30 | #include "if.h" | |
b6c5d343 | 31 | |
942bf97b | 32 | #include "rt.h" |
5dd0722d | 33 | #include "pbr.h" |
942bf97b | 34 | |
51e94aa7 EDP |
35 | #ifdef __cplusplus |
36 | extern "C" { | |
37 | #endif | |
38 | ||
5dd0722d PG |
39 | struct zebra_pbr_rule { |
40 | int sock; | |
7661461a | 41 | |
5dd0722d | 42 | struct pbr_rule rule; |
1907e4b8 | 43 | |
b19d55d0 | 44 | char ifname[INTERFACE_NAMSIZ]; |
7f0ea8a4 DS |
45 | |
46 | vrf_id_t vrf_id; | |
942bf97b | 47 | }; |
48 | ||
49 | #define IS_RULE_FILTERING_ON_SRC_IP(r) \ | |
5dd0722d | 50 | (r->rule.filter.filter_bm & PBR_FILTER_SRC_IP) |
942bf97b | 51 | #define IS_RULE_FILTERING_ON_DST_IP(r) \ |
5dd0722d | 52 | (r->rule.filter.filter_bm & PBR_FILTER_DST_IP) |
942bf97b | 53 | #define IS_RULE_FILTERING_ON_SRC_PORT(r) \ |
5dd0722d | 54 | (r->rule.filter.filter_bm & PBR_FILTER_SRC_PORT) |
942bf97b | 55 | #define IS_RULE_FILTERING_ON_DST_PORT(r) \ |
5dd0722d | 56 | (r->rule.filter.filter_bm & PBR_FILTER_DST_PORT) |
01f23aff WC |
57 | #define IS_RULE_FILTERING_ON_DSFIELD(r) \ |
58 | (r->rule.filter.filter_bm & PBR_FILTER_DSFIELD) | |
2bee7aae PG |
59 | #define IS_RULE_FILTERING_ON_FWMARK(r) \ |
60 | (r->rule.filter.filter_bm & PBR_FILTER_FWMARK) | |
7661461a PG |
61 | |
62 | /* | |
63 | * An IPSet Entry Filter | |
64 | * | |
65 | * This is a filter mapped on ipset entries | |
66 | */ | |
67 | struct zebra_pbr_ipset { | |
68 | /* | |
69 | * Originating zclient sock fd, so we can know who to send | |
70 | * back to. | |
71 | */ | |
72 | int sock; | |
73 | ||
be2028d1 PG |
74 | vrf_id_t vrf_id; |
75 | ||
7661461a PG |
76 | uint32_t unique; |
77 | ||
78 | /* type is encoded as uint32_t | |
79 | * but value is an enum ipset_type | |
80 | */ | |
81 | uint32_t type; | |
a60b7031 PG |
82 | |
83 | uint8_t family; | |
84 | ||
7661461a PG |
85 | char ipset_name[ZEBRA_IPSET_NAME_SIZE]; |
86 | }; | |
87 | ||
88 | /* | |
89 | * An IPSet Entry Filter | |
90 | * | |
91 | * This is a filter mapped on ipset entries | |
92 | */ | |
93 | struct zebra_pbr_ipset_entry { | |
94 | /* | |
95 | * Originating zclient sock fd, so we can know who to send | |
96 | * back to. | |
97 | */ | |
98 | int sock; | |
99 | ||
100 | uint32_t unique; | |
101 | ||
102 | struct prefix src; | |
103 | struct prefix dst; | |
104 | ||
3b0c3697 | 105 | /* udp/tcp src port or icmp type */ |
25d760c5 PG |
106 | uint16_t src_port_min; |
107 | uint16_t src_port_max; | |
3b0c3697 | 108 | /* udp/tcp dst port or icmp code */ |
25d760c5 PG |
109 | uint16_t dst_port_min; |
110 | uint16_t dst_port_max; | |
111 | ||
112 | uint8_t proto; | |
113 | ||
7661461a PG |
114 | uint32_t filter_bm; |
115 | ||
116 | struct zebra_pbr_ipset *backpointer; | |
117 | }; | |
118 | ||
7abd6c4f PG |
119 | /* |
120 | * An IPTables Action | |
121 | * | |
122 | * This is a filter mapped on ipset entries | |
123 | */ | |
124 | struct zebra_pbr_iptable { | |
125 | /* | |
126 | * Originating zclient sock fd, so we can know who to send | |
127 | * back to. | |
128 | */ | |
129 | int sock; | |
130 | ||
be2028d1 PG |
131 | vrf_id_t vrf_id; |
132 | ||
7abd6c4f PG |
133 | uint32_t unique; |
134 | ||
135 | /* include ipset type | |
136 | */ | |
137 | uint32_t type; | |
138 | ||
139 | /* include which IP is to be filtered | |
140 | */ | |
141 | uint32_t filter_bm; | |
142 | ||
143 | uint32_t fwmark; | |
144 | ||
145 | uint32_t action; | |
146 | ||
e7f7dad4 PG |
147 | uint16_t pkt_len_min; |
148 | uint16_t pkt_len_max; | |
dc993e76 PG |
149 | uint16_t tcp_flags; |
150 | uint16_t tcp_mask_flags; | |
4977bd6c | 151 | uint8_t dscp_value; |
5ac5b7cc | 152 | uint8_t fragment; |
f449d223 | 153 | uint8_t protocol; |
e7f7dad4 | 154 | |
f80ec7e3 | 155 | uint32_t nb_interface; |
a60b7031 PG |
156 | uint16_t flow_label; |
157 | ||
158 | uint8_t family; | |
f80ec7e3 PG |
159 | |
160 | struct list *interface_name_list; | |
161 | ||
7abd6c4f PG |
162 | char ipset_name[ZEBRA_IPSET_NAME_SIZE]; |
163 | }; | |
164 | ||
be729dd7 PG |
165 | extern const struct message icmp_typecode_str[]; |
166 | ||
5b0d92b8 PG |
167 | const char *zebra_pbr_ipset_type2str(uint32_t type); |
168 | ||
7f0ea8a4 DS |
169 | void zebra_pbr_add_rule(struct zebra_pbr_rule *rule); |
170 | void zebra_pbr_del_rule(struct zebra_pbr_rule *rule); | |
62f20a52 DS |
171 | void zebra_pbr_create_ipset(struct zebra_pbr_ipset *ipset); |
172 | void zebra_pbr_destroy_ipset(struct zebra_pbr_ipset *ipset); | |
173 | struct zebra_pbr_ipset *zebra_pbr_lookup_ipset_pername(char *ipsetname); | |
174 | void zebra_pbr_add_ipset_entry(struct zebra_pbr_ipset_entry *ipset); | |
175 | void zebra_pbr_del_ipset_entry(struct zebra_pbr_ipset_entry *ipset); | |
176 | ||
177 | void zebra_pbr_add_iptable(struct zebra_pbr_iptable *iptable); | |
178 | void zebra_pbr_del_iptable(struct zebra_pbr_iptable *iptable); | |
7abd6c4f | 179 | |
942bf97b | 180 | /* |
181 | * Get to know existing PBR rules in the kernel - typically called at startup. | |
182 | */ | |
183 | extern void kernel_read_pbr_rules(struct zebra_ns *zns); | |
184 | ||
185 | /* | |
186 | * Handle success or failure of rule (un)install in the kernel. | |
187 | */ | |
f62e5480 | 188 | extern void zebra_pbr_dplane_result(struct zebra_dplane_ctx *ctx); |
942bf97b | 189 | |
425bdd6b PG |
190 | /* |
191 | * Handle success or failure of ipset kinds (un)install in the kernel. | |
192 | */ | |
193 | extern void kernel_pbr_ipset_add_del_status(struct zebra_pbr_ipset *ipset, | |
ea1c14f6 | 194 | enum zebra_dplane_status res); |
425bdd6b PG |
195 | |
196 | extern void kernel_pbr_ipset_entry_add_del_status( | |
197 | struct zebra_pbr_ipset_entry *ipset, | |
ea1c14f6 | 198 | enum zebra_dplane_status res); |
425bdd6b | 199 | |
7abd6c4f | 200 | extern void kernel_pbr_iptable_add_del_status(struct zebra_pbr_iptable *iptable, |
ea1c14f6 | 201 | enum zebra_dplane_status res); |
7abd6c4f | 202 | |
942bf97b | 203 | /* |
204 | * Handle rule delete notification from kernel. | |
205 | */ | |
a0321978 | 206 | extern int kernel_pbr_rule_del(struct zebra_pbr_rule *rule); |
942bf97b | 207 | |
43fe6a2a | 208 | extern void zebra_pbr_rules_free(void *arg); |
d8b87afe | 209 | extern uint32_t zebra_pbr_rules_hash_key(const void *arg); |
74df8d6d | 210 | extern bool zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2); |
e69aa084 | 211 | |
425bdd6b PG |
212 | /* has operates on 32bit pointer |
213 | * and field is a string of 8bit | |
214 | */ | |
215 | #define ZEBRA_IPSET_NAME_HASH_SIZE (ZEBRA_IPSET_NAME_SIZE / 4) | |
216 | ||
7661461a | 217 | extern void zebra_pbr_ipset_free(void *arg); |
d8b87afe | 218 | extern uint32_t zebra_pbr_ipset_hash_key(const void *arg); |
74df8d6d | 219 | extern bool zebra_pbr_ipset_hash_equal(const void *arg1, const void *arg2); |
7661461a PG |
220 | |
221 | extern void zebra_pbr_ipset_entry_free(void *arg); | |
d8b87afe | 222 | extern uint32_t zebra_pbr_ipset_entry_hash_key(const void *arg); |
74df8d6d DS |
223 | extern bool zebra_pbr_ipset_entry_hash_equal(const void *arg1, |
224 | const void *arg2); | |
7661461a | 225 | |
7abd6c4f | 226 | extern void zebra_pbr_iptable_free(void *arg); |
d8b87afe | 227 | extern uint32_t zebra_pbr_iptable_hash_key(const void *arg); |
74df8d6d | 228 | extern bool zebra_pbr_iptable_hash_equal(const void *arg1, const void *arg2); |
7abd6c4f | 229 | |
4c0ec639 | 230 | extern void zebra_pbr_init(void); |
586f4ccf | 231 | extern void zebra_pbr_show_ipset_list(struct vty *vty, char *ipsetname); |
7929821a | 232 | extern void zebra_pbr_show_iptable(struct vty *vty, char *iptable); |
f80ec7e3 PG |
233 | extern void zebra_pbr_iptable_update_interfacelist(struct stream *s, |
234 | struct zebra_pbr_iptable *zpi); | |
dc993e76 PG |
235 | size_t zebra_pbr_tcpflags_snprintf(char *buffer, size_t len, |
236 | uint16_t tcp_val); | |
586f4ccf | 237 | |
1c6fca1f | 238 | DECLARE_HOOK(zebra_pbr_ipset_entry_get_stat, |
62f20a52 DS |
239 | (struct zebra_pbr_ipset_entry *ipset, uint64_t *pkts, |
240 | uint64_t *bytes), | |
241 | (ipset, pkts, bytes)) | |
1c6fca1f | 242 | DECLARE_HOOK(zebra_pbr_iptable_get_stat, |
62f20a52 DS |
243 | (struct zebra_pbr_iptable *iptable, uint64_t *pkts, |
244 | uint64_t *bytes), | |
245 | (iptable, pkts, bytes)) | |
1c6fca1f | 246 | DECLARE_HOOK(zebra_pbr_iptable_update, |
62f20a52 DS |
247 | (int cmd, struct zebra_pbr_iptable *iptable), (cmd, iptable)); |
248 | ||
1c6fca1f | 249 | DECLARE_HOOK(zebra_pbr_ipset_entry_update, |
62f20a52 | 250 | (int cmd, struct zebra_pbr_ipset_entry *ipset), (cmd, ipset)); |
1c6fca1f | 251 | DECLARE_HOOK(zebra_pbr_ipset_update, |
62f20a52 | 252 | (int cmd, struct zebra_pbr_ipset *ipset), (cmd, ipset)); |
73a829f7 | 253 | |
51e94aa7 EDP |
254 | #ifdef __cplusplus |
255 | } | |
256 | #endif | |
257 | ||
942bf97b | 258 | #endif /* _ZEBRA_PBR_H */ |