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.
6 * This file is part of FRR.
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
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.
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
35 struct zebra_pbr_rule
{
40 struct interface
*ifp
;
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 #define IS_RULE_FILTERING_ON_FWMARK(r) \
52 (r->rule.filter.filter_bm & PBR_FILTER_FWMARK)
55 * An IPSet Entry Filter
57 * This is a filter mapped on ipset entries
59 struct zebra_pbr_ipset
{
61 * Originating zclient sock fd, so we can know who to send
70 /* type is encoded as uint32_t
71 * but value is an enum ipset_type
74 char ipset_name
[ZEBRA_IPSET_NAME_SIZE
];
78 * An IPSet Entry Filter
80 * This is a filter mapped on ipset entries
82 struct zebra_pbr_ipset_entry
{
84 * Originating zclient sock fd, so we can know who to send
94 uint16_t src_port_min
;
95 uint16_t src_port_max
;
96 uint16_t dst_port_min
;
97 uint16_t dst_port_max
;
103 struct zebra_pbr_ipset
*backpointer
;
109 * This is a filter mapped on ipset entries
111 struct zebra_pbr_iptable
{
113 * Originating zclient sock fd, so we can know who to send
122 /* include ipset type
126 /* include which IP is to be filtered
134 uint32_t nb_interface
;
136 struct list
*interface_name_list
;
138 char ipset_name
[ZEBRA_IPSET_NAME_SIZE
];
141 void zebra_pbr_add_rule(struct zebra_ns
*zns
, struct zebra_pbr_rule
*rule
);
142 void zebra_pbr_del_rule(struct zebra_ns
*zns
, struct zebra_pbr_rule
*rule
);
143 void zebra_pbr_create_ipset(struct zebra_ns
*zns
,
144 struct zebra_pbr_ipset
*ipset
);
145 void zebra_pbr_destroy_ipset(struct zebra_ns
*zns
,
146 struct zebra_pbr_ipset
*ipset
);
147 struct zebra_pbr_ipset
*zebra_pbr_lookup_ipset_pername(struct zebra_ns
*zns
,
149 void zebra_pbr_add_ipset_entry(struct zebra_ns
*zns
,
150 struct zebra_pbr_ipset_entry
*ipset
);
151 void zebra_pbr_del_ipset_entry(struct zebra_ns
*zns
,
152 struct zebra_pbr_ipset_entry
*ipset
);
154 void zebra_pbr_add_iptable(struct zebra_ns
*zns
,
155 struct zebra_pbr_iptable
*iptable
);
156 void zebra_pbr_del_iptable(struct zebra_ns
*zns
,
157 struct zebra_pbr_iptable
*iptable
);
160 * Install specified rule for a specific interface.
161 * It is possible that the user-defined sequence number and the one in the
162 * forwarding plane may not coincide, hence the API requires a separate
163 * rule priority - maps to preference/FRA_PRIORITY on Linux.
165 extern void kernel_add_pbr_rule(struct zebra_pbr_rule
*rule
);
168 * Uninstall specified rule for a specific interface.
170 extern void kernel_del_pbr_rule(struct zebra_pbr_rule
*rule
);
173 * Get to know existing PBR rules in the kernel - typically called at startup.
175 extern void kernel_read_pbr_rules(struct zebra_ns
*zns
);
177 enum southbound_results
;
179 * Handle success or failure of rule (un)install in the kernel.
181 extern void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule
*rule
,
182 enum southbound_results res
);
185 * Handle success or failure of ipset kinds (un)install in the kernel.
187 extern void kernel_pbr_ipset_add_del_status(struct zebra_pbr_ipset
*ipset
,
188 enum southbound_results res
);
190 extern void kernel_pbr_ipset_entry_add_del_status(
191 struct zebra_pbr_ipset_entry
*ipset
,
192 enum southbound_results res
);
194 extern void kernel_pbr_iptable_add_del_status(struct zebra_pbr_iptable
*iptable
,
195 enum southbound_results res
);
198 * Handle rule delete notification from kernel.
200 extern int kernel_pbr_rule_del(struct zebra_pbr_rule
*rule
);
202 extern void zebra_pbr_rules_free(void *arg
);
203 extern uint32_t zebra_pbr_rules_hash_key(void *arg
);
204 extern int zebra_pbr_rules_hash_equal(const void *arg1
, const void *arg2
);
206 /* has operates on 32bit pointer
207 * and field is a string of 8bit
209 #define ZEBRA_IPSET_NAME_HASH_SIZE (ZEBRA_IPSET_NAME_SIZE / 4)
211 extern void zebra_pbr_ipset_free(void *arg
);
212 extern uint32_t zebra_pbr_ipset_hash_key(void *arg
);
213 extern int zebra_pbr_ipset_hash_equal(const void *arg1
, const void *arg2
);
215 extern void zebra_pbr_ipset_entry_free(void *arg
);
216 extern uint32_t zebra_pbr_ipset_entry_hash_key(void *arg
);
217 extern int zebra_pbr_ipset_entry_hash_equal(const void *arg1
, const void *arg2
);
219 extern void zebra_pbr_iptable_free(void *arg
);
220 extern uint32_t zebra_pbr_iptable_hash_key(void *arg
);
221 extern int zebra_pbr_iptable_hash_equal(const void *arg1
, const void *arg2
);
223 extern void zebra_pbr_init(void);
224 extern void zebra_pbr_show_ipset_list(struct vty
*vty
, char *ipsetname
);
225 extern void zebra_pbr_show_iptable(struct vty
*vty
);
226 extern void zebra_pbr_iptable_update_interfacelist(struct stream
*s
,
227 struct zebra_pbr_iptable
*zpi
);
229 DECLARE_HOOK(zebra_pbr_ipset_entry_wrap_script_get_stat
, (struct zebra_ns
*zns
,
230 struct zebra_pbr_ipset_entry
*ipset
,
231 uint64_t *pkts
, uint64_t *bytes
),
232 (zns
, ipset
, pkts
, bytes
))
233 DECLARE_HOOK(zebra_pbr_iptable_wrap_script_get_stat
, (struct zebra_ns
*zns
,
234 struct zebra_pbr_iptable
*iptable
,
235 uint64_t *pkts
, uint64_t *bytes
),
236 (zns
, iptable
, pkts
, bytes
))
237 DECLARE_HOOK(zebra_pbr_iptable_wrap_script_update
, (struct zebra_ns
*zns
,
239 struct zebra_pbr_iptable
*iptable
),
240 (zns
, cmd
, iptable
));
242 DECLARE_HOOK(zebra_pbr_ipset_entry_wrap_script_update
, (struct zebra_ns
*zns
,
244 struct zebra_pbr_ipset_entry
*ipset
),
246 DECLARE_HOOK(zebra_pbr_ipset_wrap_script_update
, (struct zebra_ns
*zns
,
248 struct zebra_pbr_ipset
*ipset
),
251 #endif /* _ZEBRA_PBR_H */