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