]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_pbr.h
zebra: upon zclient breaking, flush PBR entries
[mirror_frr.git] / zebra / zebra_pbr.h
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"
31
32 #include "rt.h"
33 #include "pbr.h"
34
35 struct zebra_pbr_rule {
36 int sock;
37
38 struct pbr_rule rule;
39
40 struct interface *ifp;
41 };
42
43 #define IS_RULE_FILTERING_ON_SRC_IP(r) \
44 (r->rule.filter.filter_bm & PBR_FILTER_SRC_IP)
45 #define IS_RULE_FILTERING_ON_DST_IP(r) \
46 (r->rule.filter.filter_bm & PBR_FILTER_DST_IP)
47 #define IS_RULE_FILTERING_ON_SRC_PORT(r) \
48 (r->rule.filter.filter_bm & PBR_FILTER_SRC_PORT)
49 #define IS_RULE_FILTERING_ON_DST_PORT(r) \
50 (r->rule.filter.filter_bm & PBR_FILTER_DST_PORT)
51
52 /*
53 * An IPSet Entry Filter
54 *
55 * This is a filter mapped on ipset entries
56 */
57 struct zebra_pbr_ipset {
58 /*
59 * Originating zclient sock fd, so we can know who to send
60 * back to.
61 */
62 int sock;
63
64 uint32_t unique;
65
66 /* type is encoded as uint32_t
67 * but value is an enum ipset_type
68 */
69 uint32_t type;
70 char ipset_name[ZEBRA_IPSET_NAME_SIZE];
71 };
72
73 /*
74 * An IPSet Entry Filter
75 *
76 * This is a filter mapped on ipset entries
77 */
78 struct zebra_pbr_ipset_entry {
79 /*
80 * Originating zclient sock fd, so we can know who to send
81 * back to.
82 */
83 int sock;
84
85 uint32_t unique;
86
87 struct prefix src;
88 struct prefix dst;
89
90 uint32_t filter_bm;
91
92 struct zebra_pbr_ipset *backpointer;
93 };
94
95 /*
96 * An IPTables Action
97 *
98 * This is a filter mapped on ipset entries
99 */
100 struct zebra_pbr_iptable {
101 /*
102 * Originating zclient sock fd, so we can know who to send
103 * back to.
104 */
105 int sock;
106
107 uint32_t unique;
108
109 /* include ipset type
110 */
111 uint32_t type;
112
113 /* include which IP is to be filtered
114 */
115 uint32_t filter_bm;
116
117 uint32_t fwmark;
118
119 uint32_t action;
120
121 char ipset_name[ZEBRA_IPSET_NAME_SIZE];
122 };
123
124 void zebra_pbr_add_rule(struct zebra_ns *zns, struct zebra_pbr_rule *rule);
125 void zebra_pbr_del_rule(struct zebra_ns *zns, struct zebra_pbr_rule *rule);
126 void zebra_pbr_create_ipset(struct zebra_ns *zns,
127 struct zebra_pbr_ipset *ipset);
128 void zebra_pbr_destroy_ipset(struct zebra_ns *zns,
129 struct zebra_pbr_ipset *ipset);
130 struct zebra_pbr_ipset *zebra_pbr_lookup_ipset_pername(struct zebra_ns *zns,
131 char *ipsetname);
132 void zebra_pbr_add_ipset_entry(struct zebra_ns *zns,
133 struct zebra_pbr_ipset_entry *ipset);
134 void zebra_pbr_del_ipset_entry(struct zebra_ns *zns,
135 struct zebra_pbr_ipset_entry *ipset);
136
137 void zebra_pbr_add_iptable(struct zebra_ns *zns,
138 struct zebra_pbr_iptable *iptable);
139 void zebra_pbr_del_iptable(struct zebra_ns *zns,
140 struct zebra_pbr_iptable *iptable);
141
142 /*
143 * Install specified rule for a specific interface.
144 * It is possible that the user-defined sequence number and the one in the
145 * forwarding plane may not coincide, hence the API requires a separate
146 * rule priority - maps to preference/FRA_PRIORITY on Linux.
147 */
148 extern void kernel_add_pbr_rule(struct zebra_pbr_rule *rule);
149
150 /*
151 * Uninstall specified rule for a specific interface.
152 */
153 extern void kernel_del_pbr_rule(struct zebra_pbr_rule *rule);
154
155 /*
156 * Get to know existing PBR rules in the kernel - typically called at startup.
157 */
158 extern void kernel_read_pbr_rules(struct zebra_ns *zns);
159
160 enum southbound_results;
161 /*
162 * Handle success or failure of rule (un)install in the kernel.
163 */
164 extern void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule *rule,
165 enum southbound_results res);
166
167 /*
168 * Handle success or failure of ipset kinds (un)install in the kernel.
169 */
170 extern void kernel_pbr_ipset_add_del_status(struct zebra_pbr_ipset *ipset,
171 enum southbound_results res);
172
173 extern void kernel_pbr_ipset_entry_add_del_status(
174 struct zebra_pbr_ipset_entry *ipset,
175 enum southbound_results res);
176
177 extern void kernel_pbr_iptable_add_del_status(struct zebra_pbr_iptable *iptable,
178 enum southbound_results res);
179
180 /*
181 * Handle rule delete notification from kernel.
182 */
183 extern int kernel_pbr_rule_del(struct zebra_pbr_rule *rule);
184
185 extern void zebra_pbr_rules_free(void *arg);
186 extern uint32_t zebra_pbr_rules_hash_key(void *arg);
187 extern int zebra_pbr_rules_hash_equal(const void *arg1, const void *arg2);
188
189 /* has operates on 32bit pointer
190 * and field is a string of 8bit
191 */
192 #define ZEBRA_IPSET_NAME_HASH_SIZE (ZEBRA_IPSET_NAME_SIZE / 4)
193
194 extern void zebra_pbr_ipset_free(void *arg);
195 extern uint32_t zebra_pbr_ipset_hash_key(void *arg);
196 extern int zebra_pbr_ipset_hash_equal(const void *arg1, const void *arg2);
197
198 extern void zebra_pbr_ipset_entry_free(void *arg);
199 extern uint32_t zebra_pbr_ipset_entry_hash_key(void *arg);
200 extern int zebra_pbr_ipset_entry_hash_equal(const void *arg1, const void *arg2);
201
202 extern void zebra_pbr_iptable_free(void *arg);
203 extern uint32_t zebra_pbr_iptable_hash_key(void *arg);
204 extern int zebra_pbr_iptable_hash_equal(const void *arg1, const void *arg2);
205
206 extern void zebra_pbr_init(void);
207 #endif /* _ZEBRA_PBR_H */