]> git.proxmox.com Git - mirror_frr.git/blame - lib/filter.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / filter.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/*
3 * Route filtering function.
4 * Copyright (C) 1998 Kunihiro Ishiguro
718e3744 5 */
6
7#ifndef _ZEBRA_FILTER_H
8#define _ZEBRA_FILTER_H
9
10#include "if.h"
4cf24501 11#include "prefix.h"
718e3744 12
5e244469
RW
13#ifdef __cplusplus
14extern "C" {
15#endif
16
45a8eba9
RW
17/* Maximum ACL name length */
18#define ACL_NAMSIZ 128
19
0ed507dd
RZ
20/** Cisco host wildcard mask. */
21#define CISCO_HOST_WILDCARD_MASK "0.0.0.0"
22/** Cisco host wildcard binary mask. */
23#define CISCO_BIN_HOST_WILDCARD_MASK INADDR_ANY
24
25/** Cisco any wildcard mask. */
26#define CISCO_ANY_WILDCARD_MASK "255.255.255.255"
27/** Cisco binary any wildcard mask. */
28#define CISCO_BIN_ANY_WILDCARD_MASK INADDR_NONE
29
039f3a34
DS
30/* Filter direction. */
31#define FILTER_IN 0
32#define FILTER_OUT 1
33#define FILTER_MAX 2
34
718e3744 35/* Filter type is made by `permit', `deny' and `dynamic'. */
d62a17ae 36enum filter_type { FILTER_DENY, FILTER_PERMIT, FILTER_DYNAMIC };
718e3744 37
4cf24501
RZ
38struct filter_cisco {
39 /* Cisco access-list */
40 int extended;
41 struct in_addr addr;
42 struct in_addr addr_mask;
43 struct in_addr mask;
44 struct in_addr mask_mask;
45};
46
47struct filter_zebra {
48 /* If this filter is "exact" match then this flag is set. */
49 int exact;
50
51 /* Prefix information. */
52 struct prefix prefix;
53};
54
55/* Forward declaration of access-list struct. */
56struct access_list;
57
58/* Filter element of access list */
59struct filter {
60 /* For doubly linked list. */
61 struct filter *next;
62 struct filter *prev;
63
64 /* Parent access-list pointer. */
65 struct access_list *acl;
66
67 /* Filter type information. */
68 enum filter_type type;
69
70 /* Sequence number */
71 int64_t seq;
72
73 /* Cisco access-list */
74 int cisco;
75
76 union {
77 struct filter_cisco cfilter;
78 struct filter_zebra zfilter;
79 } u;
80};
81
718e3744 82/* Access list */
d62a17ae 83struct access_list {
84 char *name;
85 char *remark;
718e3744 86
d62a17ae 87 struct access_master *master;
718e3744 88
d62a17ae 89 struct access_list *next;
90 struct access_list *prev;
718e3744 91
d62a17ae 92 struct filter *head;
93 struct filter *tail;
718e3744 94};
95
4cf24501
RZ
96/* List of access_list. */
97struct access_list_list {
98 struct access_list *head;
99 struct access_list *tail;
100};
101
102/* Master structure of access_list. */
103struct access_master {
4cf24501
RZ
104 /* List of access_list which name is string. */
105 struct access_list_list str;
106
107 /* Hook function which is executed when new access_list is added. */
108 void (*add_hook)(struct access_list *);
109
110 /* Hook function which is executed when access_list is deleted. */
111 void (*delete_hook)(struct access_list *);
112};
113
114
718e3744 115/* Prototypes for access-list. */
d62a17ae 116extern void access_list_init(void);
117extern void access_list_reset(void);
118extern void access_list_add_hook(void (*func)(struct access_list *));
119extern void access_list_delete_hook(void (*func)(struct access_list *));
120extern struct access_list *access_list_lookup(afi_t, const char *);
123214ef
MS
121extern enum filter_type access_list_apply(struct access_list *access,
122 const void *object);
718e3744 123
4cf24501
RZ
124struct access_list *access_list_get(afi_t afi, const char *name);
125void access_list_delete(struct access_list *access);
126struct filter *filter_new(void);
127void access_list_filter_add(struct access_list *access,
128 struct filter *filter);
129void access_list_filter_delete(struct access_list *access,
130 struct filter *filter);
131int64_t filter_new_seq_get(struct access_list *access);
4cf24501 132
c2aab693
RZ
133extern const struct frr_yang_module_info frr_filter_info;
134
be96651c
RZ
135
136/* filter_nb.c */
137enum yang_access_list_type {
138 YALT_IPV4 = 0,
139 YALT_IPV6 = 1,
140 YALT_MAC = 2,
141};
142
143enum yang_prefix_list_type {
144 YPLT_IPV4 = 0,
145 YPLT_IPV6 = 1,
146};
147
148enum yang_prefix_list_action {
149 YPLA_DENY = 0,
150 YPLA_PERMIT = 1,
151};
152
f414129b
RZ
153struct acl_dup_args {
154 /** Access list type ("ipv4", "ipv6" or "mac"). */
155 const char *ada_type;
156 /** Access list name. */
157 const char *ada_name;
158
18abe2b9
IR
159 /** Entry action. */
160 const char *ada_action;
161
f414129b
RZ
162#define ADA_MAX_VALUES 4
163 /** Entry XPath for value. */
164 const char *ada_xpath[ADA_MAX_VALUES];
165 /** Entry value to match. */
166 const char *ada_value[ADA_MAX_VALUES];
167
168 /** Duplicated entry found in list? */
169 bool ada_found;
170
a0145975
IR
171 /** Sequence number of the found entry */
172 int64_t ada_seq;
173
f414129b
RZ
174 /** (Optional) Already existing `dnode`. */
175 const struct lyd_node *ada_entry_dnode;
176};
177
178/**
179 * Check for duplicated entries using the candidate configuration.
180 *
181 * \param vty so we can get the candidate config.
182 * \param ada the arguments to check.
183 */
184bool acl_is_dup(const struct lyd_node *dnode, struct acl_dup_args *ada);
185
54d153f7
RZ
186struct plist_dup_args {
187 /** Access list type ("ipv4" or "ipv6"). */
188 const char *pda_type;
189 /** Access list name. */
190 const char *pda_name;
191
4179f151
IR
192 /** Entry action. */
193 const char *pda_action;
194
667dcc27
IR
195 bool any;
196 struct prefix prefix;
197 int ge;
198 int le;
54d153f7
RZ
199
200 /** Duplicated entry found in list? */
201 bool pda_found;
202
a0145975
IR
203 /** Sequence number of the found entry */
204 int64_t pda_seq;
205
54d153f7
RZ
206 /** (Optional) Already existing `dnode`. */
207 const struct lyd_node *pda_entry_dnode;
208};
209
210/**
211 * Check for duplicated entries using the candidate configuration.
212 *
213 * \param vty so we can get the candidate config.
214 * \param pda the arguments to check.
215 */
216bool plist_is_dup(const struct lyd_node *dnode, struct plist_dup_args *pda);
217
1d3c4b66
RZ
218/* filter_cli.c */
219struct lyd_node;
220struct vty;
221
25605051
IR
222extern int access_list_cmp(const struct lyd_node *dnode1,
223 const struct lyd_node *dnode2);
224extern void access_list_show(struct vty *vty, const struct lyd_node *dnode,
1d3c4b66 225 bool show_defaults);
25605051
IR
226extern void access_list_remark_show(struct vty *vty,
227 const struct lyd_node *dnode,
1d3c4b66 228 bool show_defaults);
25605051
IR
229extern int prefix_list_cmp(const struct lyd_node *dnode1,
230 const struct lyd_node *dnode2);
231extern void prefix_list_show(struct vty *vty, const struct lyd_node *dnode,
1d3c4b66 232 bool show_defaults);
25605051
IR
233extern void prefix_list_remark_show(struct vty *vty,
234 const struct lyd_node *dnode,
1d3c4b66
RZ
235 bool show_defaults);
236
b62578bd
RZ
237void filter_cli_init(void);
238
5e244469
RW
239#ifdef __cplusplus
240}
241#endif
242
718e3744 243#endif /* _ZEBRA_FILTER_H */