]> git.ipfire.org Git - thirdparty/bird.git/blame - filter/filter.h
Cross-protocol issues solved better
[thirdparty/bird.git] / filter / filter.h
CommitLineData
b9d70dc8 1/*
e0f2e42f 2 * BIRD Internet Routing Daemon -- Filters
b9d70dc8 3 *
e0f2e42f 4 * (c) 1999 Pavel Machek <pavel@ucw.cz>
b9d70dc8
PM
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9#ifndef _BIRD_FILT_H_
10#define _BIRD_FILT_H_
11
12#include "lib/resource.h"
23b1539b 13#include "lib/ip.h"
b9d70dc8 14
b7005824
PM
15struct f_inst { /* Instruction */
16 struct f_inst *next; /* Structure is 16 bytes, anyway */
c7b43f33
PM
17 u16 code;
18 u16 aux;
2db3b288
PM
19 union {
20 int i;
21 void *p;
22 } a1;
23 union {
24 int i;
25 void *p;
26 } a2;
b9d70dc8
PM
27};
28
2db3b288
PM
29#define arg1 a1.p
30#define arg2 a2.p
31
23b1539b
PM
32struct prefix {
33 ip_addr ip;
34 int len;
d3dd620b 35#define LEN_MASK 0xff
6dc7a0cb
PM
36#define LEN_PLUS 0x1000000
37#define LEN_MINUS 0x2000000
38#define LEN_RANGE 0x4000000
39 /* If range then prefix must be in range (len >> 16 & 0xff, len >> 8 & 0xff) */
23b1539b
PM
40};
41
b7005824
PM
42struct f_val {
43 int type;
44 union {
45 int i;
6dc7a0cb 46 /* ip_addr ip; Folded into prefix */
2db3b288 47 struct prefix px;
23b1539b 48 char *s;
38506f71 49 struct f_tree *t;
b7005824
PM
50 } val;
51};
52
e0f2e42f
MM
53struct filter {
54 char *name;
55 struct f_inst *root;
56};
57
ca3d562b 58void filters_postconfig(void);
b7005824 59struct f_inst *f_new_inst(void);
62ab789d 60struct f_inst *f_new_dynamic_attr(int type, int code);
38506f71
PM
61struct f_tree *f_new_tree(void);
62
63struct f_tree *build_tree(struct f_tree *);
64struct f_tree *find_tree(struct f_tree *t, struct f_val val);
9a4037d4 65int same_tree(struct f_tree *t1, struct f_tree *t2);
84c7e194 66
9a706f32
MM
67struct ea_list;
68struct rte;
69
63a381db
MM
70int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool);
71char *filter_name(struct filter *filter);
30a6108c 72int filter_same(struct filter *new, struct filter *old);
e0f2e42f 73
9a4037d4
PM
74int i_same(struct f_inst *f1, struct f_inst *f2);
75
38506f71
PM
76int val_compare(struct f_val v1, struct f_val v2);
77void val_print(struct f_val v);
23b1539b
PM
78
79#define F_NOP 0
d3dd620b
PM
80#define F_NONL 1
81#define F_ACCEPT 2 /* Need to preserve ordering: accepts < rejects! */
d46ffc97
MM
82#define F_REJECT 3
83#define F_ERROR 4
84#define F_QUITBIRD 5
ca3d562b 85
63a381db
MM
86#define FILTER_ACCEPT NULL
87#define FILTER_REJECT ((void *) 1)
88
ba921648
PM
89/* Type numbers must be in 0..0xff range */
90#define T_MASK 0xff
91
92/* Internal types */
c7b43f33
PM
93/* Do not use type of zero, that way we'll see errors easier. */
94#define T_VOID 1
ba921648
PM
95
96/* User visible types, which fit in int */
97#define T_INT 0x10
98#define T_BOOL 0x11
99#define T_PAIR 0x12
f4536657 100
2d496d20 101/* Put enumerational types in 0x30..0x3f range */
f4536657 102#define T_ENUM_LO 0x30
2d496d20 103#define T_ENUM_HI 0x3f
f4536657 104
cb8034f4
PM
105#define T_ENUM_RTS 0x30
106
f4536657 107#define T_ENUM T_ENUM_LO ... T_ENUM_HI
ba921648
PM
108
109/* Bigger ones */
110#define T_IP 0x20
111#define T_PREFIX 0x21
112#define T_STRING 0x22
113
2d496d20 114#define T_RETURN 0x40
ba921648 115#define T_SET 0x80
d36d838d 116
38506f71
PM
117struct f_tree {
118 struct f_tree *left, *right;
119 struct f_val from, to;
120 void *data;
121};
122
d3dd620b
PM
123#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val));
124
b9d70dc8 125#endif