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