]>
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) |
2bee7aae PG |
57 | #define IS_RULE_FILTERING_ON_FWMARK(r) \ |
58 | (r->rule.filter.filter_bm & PBR_FILTER_FWMARK) | |
7661461a PG |
59 | |
60 | /* | |
61 | * An IPSet Entry Filter | |
62 | * | |
63 | * This is a filter mapped on ipset entries | |
64 | */ | |
65 | struct zebra_pbr_ipset { | |
66 | /* | |
67 | * Originating zclient sock fd, so we can know who to send | |
68 | * back to. | |
69 | */ | |
70 | int sock; | |
71 | ||
be2028d1 PG |
72 | vrf_id_t vrf_id; |
73 | ||
7661461a PG |
74 | uint32_t unique; |
75 | ||
76 | /* type is encoded as uint32_t | |
77 | * but value is an enum ipset_type | |
78 | */ | |
79 | uint32_t type; | |
80 | char ipset_name[ZEBRA_IPSET_NAME_SIZE]; | |
81 | }; | |
82 | ||
83 | /* | |
84 | * An IPSet Entry Filter | |
85 | * | |
86 | * This is a filter mapped on ipset entries | |
87 | */ | |
88 | struct zebra_pbr_ipset_entry { | |
89 | /* | |
90 | * Originating zclient sock fd, so we can know who to send | |
91 | * back to. | |
92 | */ | |
93 | int sock; | |
94 | ||
95 | uint32_t unique; | |
96 | ||
97 | struct prefix src; | |
98 | struct prefix dst; | |
99 | ||
3b0c3697 | 100 | /* udp/tcp src port or icmp type */ |
25d760c5 PG |
101 | uint16_t src_port_min; |
102 | uint16_t src_port_max; | |
3b0c3697 | 103 | /* udp/tcp dst port or icmp code */ |
25d760c5 PG |
104 | uint16_t dst_port_min; |
105 | uint16_t dst_port_max; | |
106 | ||
107 | uint8_t proto; | |
108 | ||
7661461a PG |
109 | uint32_t filter_bm; |
110 | ||
111 | struct zebra_pbr_ipset *backpointer; | |
112 | }; | |
113 | ||
7abd6c4f PG |
114 | /* |
115 | * An IPTables Action | |
116 | * | |
117 | * This is a filter mapped on ipset entries | |
118 | */ | |
119 | struct zebra_pbr_iptable { | |
120 | /* | |
121 | * Originating zclient sock fd, so we can know who to send | |
122 | * back to. | |
123 | */ | |
124 | int sock; | |
125 | ||
be2028d1 PG |
126 | vrf_id_t vrf_id; |
127 | ||
7abd6c4f PG |
128 | uint32_t unique; |
129 | ||
130 | /* include ipset type | |
131 | */ | |
132 | uint32_t type; | |
133 | ||
134 | /* include which IP is to be filtered | |
135 | */ | |
136 | uint32_t filter_bm; | |
137 | ||
138 | uint32_t fwmark; | |
139 | ||
140 | uint32_t action; | |
141 | ||
e7f7dad4 PG |
142 | uint16_t pkt_len_min; |
143 | uint16_t pkt_len_max; | |
dc993e76 PG |
144 | uint16_t tcp_flags; |
145 | uint16_t tcp_mask_flags; | |
4977bd6c | 146 | uint8_t dscp_value; |
5ac5b7cc | 147 | uint8_t fragment; |
f449d223 | 148 | uint8_t protocol; |
e7f7dad4 | 149 | |
f80ec7e3 PG |
150 | uint32_t nb_interface; |
151 | ||
152 | struct list *interface_name_list; | |
153 | ||
7abd6c4f PG |
154 | char ipset_name[ZEBRA_IPSET_NAME_SIZE]; |
155 | }; | |
156 | ||
be729dd7 PG |
157 | extern const struct message icmp_typecode_str[]; |
158 | ||
5b0d92b8 PG |
159 | const char *zebra_pbr_ipset_type2str(uint32_t type); |
160 | ||
7f0ea8a4 DS |
161 | void zebra_pbr_add_rule(struct zebra_pbr_rule *rule); |
162 | void zebra_pbr_del_rule(struct zebra_pbr_rule *rule); | |
62f20a52 DS |
163 | void zebra_pbr_create_ipset(struct zebra_pbr_ipset *ipset); |
164 | void zebra_pbr_destroy_ipset(struct zebra_pbr_ipset *ipset); | |
165 | struct zebra_pbr_ipset *zebra_pbr_lookup_ipset_pername(char *ipsetname); | |
166 | void zebra_pbr_add_ipset_entry(struct zebra_pbr_ipset_entry *ipset); | |
167 | void zebra_pbr_del_ipset_entry(struct zebra_pbr_ipset_entry *ipset); | |
168 | ||
169 | void zebra_pbr_add_iptable(struct zebra_pbr_iptable *iptable); | |
170 | void zebra_pbr_del_iptable(struct zebra_pbr_iptable *iptable); | |
7abd6c4f | 171 | |
942bf97b | 172 | /* |
173 | * Install specified rule for a specific interface. | |
174 | * It is possible that the user-defined sequence number and the one in the | |
175 | * forwarding plane may not coincide, hence the API requires a separate | |
176 | * rule priority - maps to preference/FRA_PRIORITY on Linux. | |
177 | */ | |
ea1c14f6 | 178 | extern enum zebra_dplane_result kernel_add_pbr_rule(struct zebra_pbr_rule *rule); |
942bf97b | 179 | |
180 | /* | |
181 | * Uninstall specified rule for a specific interface. | |
182 | */ | |
ea1c14f6 | 183 | extern enum zebra_dplane_result kernel_del_pbr_rule(struct zebra_pbr_rule *rule); |
942bf97b | 184 | |
185 | /* | |
186 | * Get to know existing PBR rules in the kernel - typically called at startup. | |
187 | */ | |
188 | extern void kernel_read_pbr_rules(struct zebra_ns *zns); | |
189 | ||
190 | /* | |
191 | * Handle success or failure of rule (un)install in the kernel. | |
192 | */ | |
193 | extern void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule *rule, | |
ea1c14f6 | 194 | enum zebra_dplane_status res); |
942bf97b | 195 | |
425bdd6b PG |
196 | /* |
197 | * Handle success or failure of ipset kinds (un)install in the kernel. | |
198 | */ | |
199 | extern void kernel_pbr_ipset_add_del_status(struct zebra_pbr_ipset *ipset, | |
ea1c14f6 | 200 | enum zebra_dplane_status res); |
425bdd6b PG |
201 | |
202 | extern void kernel_pbr_ipset_entry_add_del_status( | |
203 | struct zebra_pbr_ipset_entry *ipset, | |
ea1c14f6 | 204 | enum zebra_dplane_status res); |
425bdd6b | 205 | |
7abd6c4f | 206 | extern void kernel_pbr_iptable_add_del_status(struct zebra_pbr_iptable *iptable, |
ea1c14f6 | 207 | enum zebra_dplane_status res); |
7abd6c4f | 208 | |
942bf97b | 209 | /* |
210 | * Handle rule delete notification from kernel. | |
211 | */ | |
a0321978 | 212 | extern int kernel_pbr_rule_del(struct zebra_pbr_rule *rule); |
942bf97b | 213 | |
43fe6a2a | 214 | extern void zebra_pbr_rules_free(void *arg); |
d8b87afe | 215 | extern uint32_t zebra_pbr_rules_hash_key(const void *arg); |
74df8d6d | 216 | extern bool zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2); |
e69aa084 | 217 | |
425bdd6b PG |
218 | /* has operates on 32bit pointer |
219 | * and field is a string of 8bit | |
220 | */ | |
221 | #define ZEBRA_IPSET_NAME_HASH_SIZE (ZEBRA_IPSET_NAME_SIZE / 4) | |
222 | ||
7661461a | 223 | extern void zebra_pbr_ipset_free(void *arg); |
d8b87afe | 224 | extern uint32_t zebra_pbr_ipset_hash_key(const void *arg); |
74df8d6d | 225 | extern bool zebra_pbr_ipset_hash_equal(const void *arg1, const void *arg2); |
7661461a PG |
226 | |
227 | extern void zebra_pbr_ipset_entry_free(void *arg); | |
d8b87afe | 228 | extern uint32_t zebra_pbr_ipset_entry_hash_key(const void *arg); |
74df8d6d DS |
229 | extern bool zebra_pbr_ipset_entry_hash_equal(const void *arg1, |
230 | const void *arg2); | |
7661461a | 231 | |
7abd6c4f | 232 | extern void zebra_pbr_iptable_free(void *arg); |
d8b87afe | 233 | extern uint32_t zebra_pbr_iptable_hash_key(const void *arg); |
74df8d6d | 234 | extern bool zebra_pbr_iptable_hash_equal(const void *arg1, const void *arg2); |
7abd6c4f | 235 | |
4c0ec639 | 236 | extern void zebra_pbr_init(void); |
586f4ccf | 237 | extern void zebra_pbr_show_ipset_list(struct vty *vty, char *ipsetname); |
7929821a | 238 | extern void zebra_pbr_show_iptable(struct vty *vty, char *iptable); |
f80ec7e3 PG |
239 | extern void zebra_pbr_iptable_update_interfacelist(struct stream *s, |
240 | struct zebra_pbr_iptable *zpi); | |
dc993e76 PG |
241 | size_t zebra_pbr_tcpflags_snprintf(char *buffer, size_t len, |
242 | uint16_t tcp_val); | |
586f4ccf | 243 | |
1c6fca1f | 244 | DECLARE_HOOK(zebra_pbr_ipset_entry_get_stat, |
62f20a52 DS |
245 | (struct zebra_pbr_ipset_entry *ipset, uint64_t *pkts, |
246 | uint64_t *bytes), | |
247 | (ipset, pkts, bytes)) | |
1c6fca1f | 248 | DECLARE_HOOK(zebra_pbr_iptable_get_stat, |
62f20a52 DS |
249 | (struct zebra_pbr_iptable *iptable, uint64_t *pkts, |
250 | uint64_t *bytes), | |
251 | (iptable, pkts, bytes)) | |
1c6fca1f | 252 | DECLARE_HOOK(zebra_pbr_iptable_update, |
62f20a52 DS |
253 | (int cmd, struct zebra_pbr_iptable *iptable), (cmd, iptable)); |
254 | ||
1c6fca1f | 255 | DECLARE_HOOK(zebra_pbr_ipset_entry_update, |
62f20a52 | 256 | (int cmd, struct zebra_pbr_ipset_entry *ipset), (cmd, ipset)); |
1c6fca1f | 257 | DECLARE_HOOK(zebra_pbr_ipset_update, |
62f20a52 | 258 | (int cmd, struct zebra_pbr_ipset *ipset), (cmd, ipset)); |
73a829f7 | 259 | |
51e94aa7 EDP |
260 | #ifdef __cplusplus |
261 | } | |
262 | #endif | |
263 | ||
942bf97b | 264 | #endif /* _ZEBRA_PBR_H */ |