]>
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 | ||
4cf4fad1 AK |
39 | struct zebra_pbr_action { |
40 | afi_t afi; | |
41 | ||
42 | /* currently only one nexthop is supported */ | |
43 | union g_addr gate; | |
44 | ||
45 | /* dest-interface */ | |
46 | ifindex_t ifindex; | |
47 | ||
9898473f AK |
48 | /* dataplane info */ |
49 | intptr_t dp_flow_ptr; | |
50 | ||
4cf4fad1 AK |
51 | /* neigh */ |
52 | struct zebra_neigh_ent *neigh; | |
59f47eb0 | 53 | /* zebra_pbr_rule is linked to neigh via neigh_listnode */ |
4cf4fad1 AK |
54 | struct listnode neigh_listnode; |
55 | }; | |
56 | ||
5dd0722d PG |
57 | struct zebra_pbr_rule { |
58 | int sock; | |
7661461a | 59 | |
5dd0722d | 60 | struct pbr_rule rule; |
1907e4b8 | 61 | |
b19d55d0 | 62 | char ifname[INTERFACE_NAMSIZ]; |
7f0ea8a4 | 63 | |
4cf4fad1 AK |
64 | struct zebra_pbr_action action; |
65 | ||
7f0ea8a4 | 66 | vrf_id_t vrf_id; |
942bf97b | 67 | }; |
68 | ||
69 | #define IS_RULE_FILTERING_ON_SRC_IP(r) \ | |
5dd0722d | 70 | (r->rule.filter.filter_bm & PBR_FILTER_SRC_IP) |
942bf97b | 71 | #define IS_RULE_FILTERING_ON_DST_IP(r) \ |
5dd0722d | 72 | (r->rule.filter.filter_bm & PBR_FILTER_DST_IP) |
942bf97b | 73 | #define IS_RULE_FILTERING_ON_SRC_PORT(r) \ |
5dd0722d | 74 | (r->rule.filter.filter_bm & PBR_FILTER_SRC_PORT) |
942bf97b | 75 | #define IS_RULE_FILTERING_ON_DST_PORT(r) \ |
5dd0722d | 76 | (r->rule.filter.filter_bm & PBR_FILTER_DST_PORT) |
01f23aff WC |
77 | #define IS_RULE_FILTERING_ON_DSFIELD(r) \ |
78 | (r->rule.filter.filter_bm & PBR_FILTER_DSFIELD) | |
2bee7aae PG |
79 | #define IS_RULE_FILTERING_ON_FWMARK(r) \ |
80 | (r->rule.filter.filter_bm & PBR_FILTER_FWMARK) | |
7661461a PG |
81 | |
82 | /* | |
83 | * An IPSet Entry Filter | |
84 | * | |
85 | * This is a filter mapped on ipset entries | |
86 | */ | |
ef524230 PG |
87 | struct zebra_pbr_ipset_info { |
88 | /* type is encoded as uint32_t | |
89 | * but value is an enum ipset_type | |
90 | */ | |
91 | uint32_t type; | |
92 | ||
85b02353 PG |
93 | uint8_t family; |
94 | ||
ef524230 PG |
95 | char ipset_name[ZEBRA_IPSET_NAME_SIZE]; |
96 | }; | |
97 | ||
7661461a PG |
98 | struct zebra_pbr_ipset { |
99 | /* | |
100 | * Originating zclient sock fd, so we can know who to send | |
101 | * back to. | |
102 | */ | |
103 | int sock; | |
104 | ||
be2028d1 PG |
105 | vrf_id_t vrf_id; |
106 | ||
7661461a PG |
107 | uint32_t unique; |
108 | ||
109 | /* type is encoded as uint32_t | |
110 | * but value is an enum ipset_type | |
111 | */ | |
112 | uint32_t type; | |
a60b7031 PG |
113 | |
114 | uint8_t family; | |
115 | ||
7661461a PG |
116 | char ipset_name[ZEBRA_IPSET_NAME_SIZE]; |
117 | }; | |
118 | ||
ef524230 | 119 | |
7661461a PG |
120 | /* |
121 | * An IPSet Entry Filter | |
122 | * | |
123 | * This is a filter mapped on ipset entries | |
124 | */ | |
125 | struct zebra_pbr_ipset_entry { | |
126 | /* | |
127 | * Originating zclient sock fd, so we can know who to send | |
128 | * back to. | |
129 | */ | |
130 | int sock; | |
131 | ||
132 | uint32_t unique; | |
133 | ||
134 | struct prefix src; | |
135 | struct prefix dst; | |
136 | ||
3b0c3697 | 137 | /* udp/tcp src port or icmp type */ |
25d760c5 PG |
138 | uint16_t src_port_min; |
139 | uint16_t src_port_max; | |
3b0c3697 | 140 | /* udp/tcp dst port or icmp code */ |
25d760c5 PG |
141 | uint16_t dst_port_min; |
142 | uint16_t dst_port_max; | |
143 | ||
144 | uint8_t proto; | |
145 | ||
7661461a PG |
146 | uint32_t filter_bm; |
147 | ||
148 | struct zebra_pbr_ipset *backpointer; | |
149 | }; | |
150 | ||
7abd6c4f PG |
151 | /* |
152 | * An IPTables Action | |
153 | * | |
154 | * This is a filter mapped on ipset entries | |
155 | */ | |
156 | struct zebra_pbr_iptable { | |
157 | /* | |
158 | * Originating zclient sock fd, so we can know who to send | |
159 | * back to. | |
160 | */ | |
161 | int sock; | |
162 | ||
be2028d1 PG |
163 | vrf_id_t vrf_id; |
164 | ||
7abd6c4f PG |
165 | uint32_t unique; |
166 | ||
167 | /* include ipset type | |
168 | */ | |
169 | uint32_t type; | |
170 | ||
171 | /* include which IP is to be filtered | |
172 | */ | |
173 | uint32_t filter_bm; | |
174 | ||
175 | uint32_t fwmark; | |
176 | ||
177 | uint32_t action; | |
178 | ||
e7f7dad4 PG |
179 | uint16_t pkt_len_min; |
180 | uint16_t pkt_len_max; | |
dc993e76 PG |
181 | uint16_t tcp_flags; |
182 | uint16_t tcp_mask_flags; | |
4977bd6c | 183 | uint8_t dscp_value; |
5ac5b7cc | 184 | uint8_t fragment; |
f449d223 | 185 | uint8_t protocol; |
e7f7dad4 | 186 | |
f80ec7e3 | 187 | uint32_t nb_interface; |
a60b7031 PG |
188 | uint16_t flow_label; |
189 | ||
190 | uint8_t family; | |
f80ec7e3 PG |
191 | |
192 | struct list *interface_name_list; | |
193 | ||
c9250e28 PG |
194 | #define IPTABLE_INSTALL_QUEUED 1 << 1 |
195 | #define IPTABLE_UNINSTALL_QUEUED 1 << 2 | |
196 | uint8_t internal_flags; | |
7abd6c4f PG |
197 | char ipset_name[ZEBRA_IPSET_NAME_SIZE]; |
198 | }; | |
199 | ||
be729dd7 | 200 | extern const struct message icmp_typecode_str[]; |
c9b1139a | 201 | extern const struct message icmpv6_typecode_str[]; |
be729dd7 | 202 | |
5b0d92b8 PG |
203 | const char *zebra_pbr_ipset_type2str(uint32_t type); |
204 | ||
7f0ea8a4 DS |
205 | void zebra_pbr_add_rule(struct zebra_pbr_rule *rule); |
206 | void zebra_pbr_del_rule(struct zebra_pbr_rule *rule); | |
62f20a52 DS |
207 | void zebra_pbr_create_ipset(struct zebra_pbr_ipset *ipset); |
208 | void zebra_pbr_destroy_ipset(struct zebra_pbr_ipset *ipset); | |
209 | struct zebra_pbr_ipset *zebra_pbr_lookup_ipset_pername(char *ipsetname); | |
210 | void zebra_pbr_add_ipset_entry(struct zebra_pbr_ipset_entry *ipset); | |
211 | void zebra_pbr_del_ipset_entry(struct zebra_pbr_ipset_entry *ipset); | |
212 | ||
213 | void zebra_pbr_add_iptable(struct zebra_pbr_iptable *iptable); | |
214 | void zebra_pbr_del_iptable(struct zebra_pbr_iptable *iptable); | |
5162e000 | 215 | void zebra_pbr_process_iptable(struct zebra_dplane_ctx *ctx); |
ef524230 PG |
216 | void zebra_pbr_process_ipset(struct zebra_dplane_ctx *ctx); |
217 | void zebra_pbr_process_ipset_entry(struct zebra_dplane_ctx *ctx); | |
7abd6c4f | 218 | |
942bf97b | 219 | /* |
220 | * Get to know existing PBR rules in the kernel - typically called at startup. | |
221 | */ | |
222 | extern void kernel_read_pbr_rules(struct zebra_ns *zns); | |
223 | ||
224 | /* | |
225 | * Handle success or failure of rule (un)install in the kernel. | |
226 | */ | |
f62e5480 | 227 | extern void zebra_pbr_dplane_result(struct zebra_dplane_ctx *ctx); |
942bf97b | 228 | |
425bdd6b PG |
229 | /* |
230 | * Handle success or failure of ipset kinds (un)install in the kernel. | |
231 | */ | |
232 | extern void kernel_pbr_ipset_add_del_status(struct zebra_pbr_ipset *ipset, | |
ea1c14f6 | 233 | enum zebra_dplane_status res); |
425bdd6b PG |
234 | |
235 | extern void kernel_pbr_ipset_entry_add_del_status( | |
236 | struct zebra_pbr_ipset_entry *ipset, | |
ea1c14f6 | 237 | enum zebra_dplane_status res); |
425bdd6b | 238 | |
942bf97b | 239 | /* |
240 | * Handle rule delete notification from kernel. | |
241 | */ | |
a0321978 | 242 | extern int kernel_pbr_rule_del(struct zebra_pbr_rule *rule); |
942bf97b | 243 | |
43fe6a2a | 244 | extern void zebra_pbr_rules_free(void *arg); |
d8b87afe | 245 | extern uint32_t zebra_pbr_rules_hash_key(const void *arg); |
74df8d6d | 246 | extern bool zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2); |
e69aa084 | 247 | |
425bdd6b PG |
248 | /* has operates on 32bit pointer |
249 | * and field is a string of 8bit | |
250 | */ | |
251 | #define ZEBRA_IPSET_NAME_HASH_SIZE (ZEBRA_IPSET_NAME_SIZE / 4) | |
252 | ||
7661461a | 253 | extern void zebra_pbr_ipset_free(void *arg); |
d8b87afe | 254 | extern uint32_t zebra_pbr_ipset_hash_key(const void *arg); |
74df8d6d | 255 | extern bool zebra_pbr_ipset_hash_equal(const void *arg1, const void *arg2); |
7661461a PG |
256 | |
257 | extern void zebra_pbr_ipset_entry_free(void *arg); | |
d8b87afe | 258 | extern uint32_t zebra_pbr_ipset_entry_hash_key(const void *arg); |
74df8d6d DS |
259 | extern bool zebra_pbr_ipset_entry_hash_equal(const void *arg1, |
260 | const void *arg2); | |
7661461a | 261 | |
7abd6c4f | 262 | extern void zebra_pbr_iptable_free(void *arg); |
d8b87afe | 263 | extern uint32_t zebra_pbr_iptable_hash_key(const void *arg); |
74df8d6d | 264 | extern bool zebra_pbr_iptable_hash_equal(const void *arg1, const void *arg2); |
7abd6c4f | 265 | |
59f47eb0 AK |
266 | extern void zebra_pbr_config_write(struct vty *vty); |
267 | extern void zebra_pbr_expand_action_update(bool enable); | |
4c0ec639 | 268 | extern void zebra_pbr_init(void); |
586f4ccf | 269 | extern void zebra_pbr_show_ipset_list(struct vty *vty, char *ipsetname); |
7929821a | 270 | extern void zebra_pbr_show_iptable(struct vty *vty, char *iptable); |
f80ec7e3 PG |
271 | extern void zebra_pbr_iptable_update_interfacelist(struct stream *s, |
272 | struct zebra_pbr_iptable *zpi); | |
dc993e76 PG |
273 | size_t zebra_pbr_tcpflags_snprintf(char *buffer, size_t len, |
274 | uint16_t tcp_val); | |
59f47eb0 AK |
275 | extern void zebra_pbr_show_rule(struct vty *vty); |
276 | extern void zebra_pbr_show_rule_unit(struct zebra_pbr_rule *rule, | |
277 | struct vty *vty); | |
586f4ccf | 278 | |
1c6fca1f | 279 | DECLARE_HOOK(zebra_pbr_ipset_entry_get_stat, |
62f20a52 DS |
280 | (struct zebra_pbr_ipset_entry *ipset, uint64_t *pkts, |
281 | uint64_t *bytes), | |
8451921b | 282 | (ipset, pkts, bytes)); |
1c6fca1f | 283 | DECLARE_HOOK(zebra_pbr_iptable_get_stat, |
62f20a52 DS |
284 | (struct zebra_pbr_iptable *iptable, uint64_t *pkts, |
285 | uint64_t *bytes), | |
8451921b | 286 | (iptable, pkts, bytes)); |
1c6fca1f | 287 | DECLARE_HOOK(zebra_pbr_iptable_update, |
62f20a52 DS |
288 | (int cmd, struct zebra_pbr_iptable *iptable), (cmd, iptable)); |
289 | ||
1c6fca1f | 290 | DECLARE_HOOK(zebra_pbr_ipset_entry_update, |
62f20a52 | 291 | (int cmd, struct zebra_pbr_ipset_entry *ipset), (cmd, ipset)); |
1c6fca1f | 292 | DECLARE_HOOK(zebra_pbr_ipset_update, |
62f20a52 | 293 | (int cmd, struct zebra_pbr_ipset *ipset), (cmd, ipset)); |
73a829f7 | 294 | |
51e94aa7 EDP |
295 | #ifdef __cplusplus |
296 | } | |
297 | #endif | |
298 | ||
942bf97b | 299 | #endif /* _ZEBRA_PBR_H */ |