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
;
45 #define IS_RULE_FILTERING_ON_SRC_IP(r) \
46 (r->rule.filter.filter_bm & PBR_FILTER_SRC_IP)
47 #define IS_RULE_FILTERING_ON_DST_IP(r) \
48 (r->rule.filter.filter_bm & PBR_FILTER_DST_IP)
49 #define IS_RULE_FILTERING_ON_SRC_PORT(r) \
50 (r->rule.filter.filter_bm & PBR_FILTER_SRC_PORT)
51 #define IS_RULE_FILTERING_ON_DST_PORT(r) \
52 (r->rule.filter.filter_bm & PBR_FILTER_DST_PORT)
53 #define IS_RULE_FILTERING_ON_FWMARK(r) \
54 (r->rule.filter.filter_bm & PBR_FILTER_FWMARK)
57 * An IPSet Entry Filter
59 * This is a filter mapped on ipset entries
61 struct zebra_pbr_ipset
{
63 * Originating zclient sock fd, so we can know who to send
72 /* type is encoded as uint32_t
73 * but value is an enum ipset_type
76 char ipset_name
[ZEBRA_IPSET_NAME_SIZE
];
80 * An IPSet Entry Filter
82 * This is a filter mapped on ipset entries
84 struct zebra_pbr_ipset_entry
{
86 * Originating zclient sock fd, so we can know who to send
96 /* udp/tcp src port or icmp type */
97 uint16_t src_port_min
;
98 uint16_t src_port_max
;
99 /* udp/tcp dst port or icmp code */
100 uint16_t dst_port_min
;
101 uint16_t dst_port_max
;
107 struct zebra_pbr_ipset
*backpointer
;
113 * This is a filter mapped on ipset entries
115 struct zebra_pbr_iptable
{
117 * Originating zclient sock fd, so we can know who to send
126 /* include ipset type
130 /* include which IP is to be filtered
138 uint16_t pkt_len_min
;
139 uint16_t pkt_len_max
;
141 uint16_t tcp_mask_flags
;
145 uint32_t nb_interface
;
147 struct list
*interface_name_list
;
149 char ipset_name
[ZEBRA_IPSET_NAME_SIZE
];
152 extern const struct message icmp_typecode_str
[];
154 const char *zebra_pbr_ipset_type2str(uint32_t type
);
156 void zebra_pbr_add_rule(struct zebra_pbr_rule
*rule
);
157 void zebra_pbr_del_rule(struct zebra_pbr_rule
*rule
);
158 void zebra_pbr_create_ipset(struct zebra_ns
*zns
,
159 struct zebra_pbr_ipset
*ipset
);
160 void zebra_pbr_destroy_ipset(struct zebra_ns
*zns
,
161 struct zebra_pbr_ipset
*ipset
);
162 struct zebra_pbr_ipset
*zebra_pbr_lookup_ipset_pername(struct zebra_ns
*zns
,
164 void zebra_pbr_add_ipset_entry(struct zebra_ns
*zns
,
165 struct zebra_pbr_ipset_entry
*ipset
);
166 void zebra_pbr_del_ipset_entry(struct zebra_ns
*zns
,
167 struct zebra_pbr_ipset_entry
*ipset
);
169 void zebra_pbr_add_iptable(struct zebra_ns
*zns
,
170 struct zebra_pbr_iptable
*iptable
);
171 void zebra_pbr_del_iptable(struct zebra_ns
*zns
,
172 struct zebra_pbr_iptable
*iptable
);
175 * Install specified rule for a specific interface.
176 * It is possible that the user-defined sequence number and the one in the
177 * forwarding plane may not coincide, hence the API requires a separate
178 * rule priority - maps to preference/FRA_PRIORITY on Linux.
180 extern enum zebra_dplane_result
kernel_add_pbr_rule(struct zebra_pbr_rule
*rule
);
183 * Uninstall specified rule for a specific interface.
185 extern enum zebra_dplane_result
kernel_del_pbr_rule(struct zebra_pbr_rule
*rule
);
188 * Get to know existing PBR rules in the kernel - typically called at startup.
190 extern void kernel_read_pbr_rules(struct zebra_ns
*zns
);
193 * Handle success or failure of rule (un)install in the kernel.
195 extern void kernel_pbr_rule_add_del_status(struct zebra_pbr_rule
*rule
,
196 enum zebra_dplane_status res
);
199 * Handle success or failure of ipset kinds (un)install in the kernel.
201 extern void kernel_pbr_ipset_add_del_status(struct zebra_pbr_ipset
*ipset
,
202 enum zebra_dplane_status res
);
204 extern void kernel_pbr_ipset_entry_add_del_status(
205 struct zebra_pbr_ipset_entry
*ipset
,
206 enum zebra_dplane_status res
);
208 extern void kernel_pbr_iptable_add_del_status(struct zebra_pbr_iptable
*iptable
,
209 enum zebra_dplane_status res
);
212 * Handle rule delete notification from kernel.
214 extern int kernel_pbr_rule_del(struct zebra_pbr_rule
*rule
);
216 extern void zebra_pbr_rules_free(void *arg
);
217 extern uint32_t zebra_pbr_rules_hash_key(void *arg
);
218 extern bool zebra_pbr_rules_hash_equal(const void *arg1
, const void *arg2
);
220 /* has operates on 32bit pointer
221 * and field is a string of 8bit
223 #define ZEBRA_IPSET_NAME_HASH_SIZE (ZEBRA_IPSET_NAME_SIZE / 4)
225 extern void zebra_pbr_ipset_free(void *arg
);
226 extern uint32_t zebra_pbr_ipset_hash_key(void *arg
);
227 extern bool zebra_pbr_ipset_hash_equal(const void *arg1
, const void *arg2
);
229 extern void zebra_pbr_ipset_entry_free(void *arg
);
230 extern uint32_t zebra_pbr_ipset_entry_hash_key(void *arg
);
231 extern bool zebra_pbr_ipset_entry_hash_equal(const void *arg1
,
234 extern void zebra_pbr_iptable_free(void *arg
);
235 extern uint32_t zebra_pbr_iptable_hash_key(void *arg
);
236 extern bool zebra_pbr_iptable_hash_equal(const void *arg1
, const void *arg2
);
238 extern void zebra_pbr_init(void);
239 extern void zebra_pbr_show_ipset_list(struct vty
*vty
, char *ipsetname
);
240 extern void zebra_pbr_show_iptable(struct vty
*vty
, char *iptable
);
241 extern void zebra_pbr_iptable_update_interfacelist(struct stream
*s
,
242 struct zebra_pbr_iptable
*zpi
);
243 size_t zebra_pbr_tcpflags_snprintf(char *buffer
, size_t len
,
246 DECLARE_HOOK(zebra_pbr_ipset_entry_wrap_script_get_stat
, (struct zebra_ns
*zns
,
247 struct zebra_pbr_ipset_entry
*ipset
,
248 uint64_t *pkts
, uint64_t *bytes
),
249 (zns
, ipset
, pkts
, bytes
))
250 DECLARE_HOOK(zebra_pbr_iptable_wrap_script_get_stat
, (struct zebra_ns
*zns
,
251 struct zebra_pbr_iptable
*iptable
,
252 uint64_t *pkts
, uint64_t *bytes
),
253 (zns
, iptable
, pkts
, bytes
))
254 DECLARE_HOOK(zebra_pbr_iptable_wrap_script_update
, (struct zebra_ns
*zns
,
256 struct zebra_pbr_iptable
*iptable
),
257 (zns
, cmd
, iptable
));
259 DECLARE_HOOK(zebra_pbr_ipset_entry_wrap_script_update
, (struct zebra_ns
*zns
,
261 struct zebra_pbr_ipset_entry
*ipset
),
263 DECLARE_HOOK(zebra_pbr_ipset_wrap_script_update
, (struct zebra_ns
*zns
,
265 struct zebra_pbr_ipset
*ipset
),
268 #endif /* _ZEBRA_PBR_H */