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