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
39 struct zebra_pbr_rule
{
44 char ifname
[INTERFACE_NAMSIZ
];
49 #define IS_RULE_FILTERING_ON_SRC_IP(r) \
50 (r->rule.filter.filter_bm & PBR_FILTER_SRC_IP)
51 #define IS_RULE_FILTERING_ON_DST_IP(r) \
52 (r->rule.filter.filter_bm & PBR_FILTER_DST_IP)
53 #define IS_RULE_FILTERING_ON_SRC_PORT(r) \
54 (r->rule.filter.filter_bm & PBR_FILTER_SRC_PORT)
55 #define IS_RULE_FILTERING_ON_DST_PORT(r) \
56 (r->rule.filter.filter_bm & PBR_FILTER_DST_PORT)
57 #define IS_RULE_FILTERING_ON_DSFIELD(r) \
58 (r->rule.filter.filter_bm & PBR_FILTER_DSFIELD)
59 #define IS_RULE_FILTERING_ON_FWMARK(r) \
60 (r->rule.filter.filter_bm & PBR_FILTER_FWMARK)
63 * An IPSet Entry Filter
65 * This is a filter mapped on ipset entries
67 struct zebra_pbr_ipset_info
{
68 /* type is encoded as uint32_t
69 * but value is an enum ipset_type
73 char ipset_name
[ZEBRA_IPSET_NAME_SIZE
];
76 struct zebra_pbr_ipset
{
78 * Originating zclient sock fd, so we can know who to send
87 /* type is encoded as uint32_t
88 * but value is an enum ipset_type
94 char ipset_name
[ZEBRA_IPSET_NAME_SIZE
];
99 * An IPSet Entry Filter
101 * This is a filter mapped on ipset entries
103 struct zebra_pbr_ipset_entry
{
105 * Originating zclient sock fd, so we can know who to send
115 /* udp/tcp src port or icmp type */
116 uint16_t src_port_min
;
117 uint16_t src_port_max
;
118 /* udp/tcp dst port or icmp code */
119 uint16_t dst_port_min
;
120 uint16_t dst_port_max
;
126 struct zebra_pbr_ipset
*backpointer
;
132 * This is a filter mapped on ipset entries
134 struct zebra_pbr_iptable
{
136 * Originating zclient sock fd, so we can know who to send
145 /* include ipset type
149 /* include which IP is to be filtered
157 uint16_t pkt_len_min
;
158 uint16_t pkt_len_max
;
160 uint16_t tcp_mask_flags
;
165 uint32_t nb_interface
;
170 struct list
*interface_name_list
;
172 char ipset_name
[ZEBRA_IPSET_NAME_SIZE
];
175 extern const struct message icmp_typecode_str
[];
176 extern const struct message icmpv6_typecode_str
[];
178 const char *zebra_pbr_ipset_type2str(uint32_t type
);
180 void zebra_pbr_add_rule(struct zebra_pbr_rule
*rule
);
181 void zebra_pbr_del_rule(struct zebra_pbr_rule
*rule
);
182 void zebra_pbr_create_ipset(struct zebra_pbr_ipset
*ipset
);
183 void zebra_pbr_destroy_ipset(struct zebra_pbr_ipset
*ipset
);
184 struct zebra_pbr_ipset
*zebra_pbr_lookup_ipset_pername(char *ipsetname
);
185 void zebra_pbr_add_ipset_entry(struct zebra_pbr_ipset_entry
*ipset
);
186 void zebra_pbr_del_ipset_entry(struct zebra_pbr_ipset_entry
*ipset
);
188 void zebra_pbr_add_iptable(struct zebra_pbr_iptable
*iptable
);
189 void zebra_pbr_del_iptable(struct zebra_pbr_iptable
*iptable
);
190 void zebra_pbr_process_iptable(struct zebra_dplane_ctx
*ctx
);
191 void zebra_pbr_process_ipset(struct zebra_dplane_ctx
*ctx
);
192 void zebra_pbr_process_ipset_entry(struct zebra_dplane_ctx
*ctx
);
195 * Get to know existing PBR rules in the kernel - typically called at startup.
197 extern void kernel_read_pbr_rules(struct zebra_ns
*zns
);
200 * Handle success or failure of rule (un)install in the kernel.
202 extern void zebra_pbr_dplane_result(struct zebra_dplane_ctx
*ctx
);
205 * Handle success or failure of ipset kinds (un)install in the kernel.
207 extern void kernel_pbr_ipset_add_del_status(struct zebra_pbr_ipset
*ipset
,
208 enum zebra_dplane_status res
);
210 extern void kernel_pbr_ipset_entry_add_del_status(
211 struct zebra_pbr_ipset_entry
*ipset
,
212 enum zebra_dplane_status res
);
215 * Handle rule delete notification from kernel.
217 extern int kernel_pbr_rule_del(struct zebra_pbr_rule
*rule
);
219 extern void zebra_pbr_rules_free(void *arg
);
220 extern uint32_t zebra_pbr_rules_hash_key(const void *arg
);
221 extern bool zebra_pbr_rules_hash_equal(const void *arg1
, const void *arg2
);
223 /* has operates on 32bit pointer
224 * and field is a string of 8bit
226 #define ZEBRA_IPSET_NAME_HASH_SIZE (ZEBRA_IPSET_NAME_SIZE / 4)
228 extern void zebra_pbr_ipset_free(void *arg
);
229 extern uint32_t zebra_pbr_ipset_hash_key(const void *arg
);
230 extern bool zebra_pbr_ipset_hash_equal(const void *arg1
, const void *arg2
);
232 extern void zebra_pbr_ipset_entry_free(void *arg
);
233 extern uint32_t zebra_pbr_ipset_entry_hash_key(const void *arg
);
234 extern bool zebra_pbr_ipset_entry_hash_equal(const void *arg1
,
237 extern void zebra_pbr_iptable_free(void *arg
);
238 extern uint32_t zebra_pbr_iptable_hash_key(const void *arg
);
239 extern bool zebra_pbr_iptable_hash_equal(const void *arg1
, const void *arg2
);
241 extern void zebra_pbr_init(void);
242 extern void zebra_pbr_show_ipset_list(struct vty
*vty
, char *ipsetname
);
243 extern void zebra_pbr_show_iptable(struct vty
*vty
, char *iptable
);
244 extern void zebra_pbr_iptable_update_interfacelist(struct stream
*s
,
245 struct zebra_pbr_iptable
*zpi
);
246 size_t zebra_pbr_tcpflags_snprintf(char *buffer
, size_t len
,
249 DECLARE_HOOK(zebra_pbr_ipset_entry_get_stat
,
250 (struct zebra_pbr_ipset_entry
*ipset
, uint64_t *pkts
,
252 (ipset
, pkts
, bytes
))
253 DECLARE_HOOK(zebra_pbr_iptable_get_stat
,
254 (struct zebra_pbr_iptable
*iptable
, uint64_t *pkts
,
256 (iptable
, pkts
, bytes
))
257 DECLARE_HOOK(zebra_pbr_iptable_update
,
258 (int cmd
, struct zebra_pbr_iptable
*iptable
), (cmd
, iptable
));
260 DECLARE_HOOK(zebra_pbr_ipset_entry_update
,
261 (int cmd
, struct zebra_pbr_ipset_entry
*ipset
), (cmd
, ipset
));
262 DECLARE_HOOK(zebra_pbr_ipset_update
,
263 (int cmd
, struct zebra_pbr_ipset
*ipset
), (cmd
, ipset
));
269 #endif /* _ZEBRA_PBR_H */