Statistics
| Branch: | Revision:

iof-bird-daemon / filter / filter.h @ 26c09e1d

History | View | Annotate | Download (3.3 KB)

1 b9d70dc8 Pavel Machek
/*
2 e0f2e42f Martin Mares
 *        BIRD Internet Routing Daemon -- Filters
3 b9d70dc8 Pavel Machek
 *
4 e0f2e42f Martin Mares
 *        (c) 1999 Pavel Machek <pavel@ucw.cz>
5 b9d70dc8 Pavel Machek
 *
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"
13 23b1539b Pavel Machek
#include "lib/ip.h"
14 159fa4ce Pavel Machek
#include "nest/attrs.h"
15 b9d70dc8 Pavel Machek
16 b7005824 Pavel Machek
struct f_inst {                /* Instruction */
17
  struct f_inst *next;        /* Structure is 16 bytes, anyway */
18 c7b43f33 Pavel Machek
  u16 code;
19
  u16 aux;
20 2db3b288 Pavel Machek
  union {
21
    int i;
22
    void *p;
23
  } a1;
24
  union {
25
    int i;
26
    void *p;
27
  } a2;
28 a96a979d Pavel Machek
  int lineno;
29 b9d70dc8 Pavel Machek
};
30
31 2db3b288 Pavel Machek
#define arg1 a1.p
32
#define arg2 a2.p
33
34 b1c9d871 Martin Mares
struct f_prefix {
35 23b1539b Pavel Machek
  ip_addr ip;
36
  int len;
37 d3dd620b Pavel Machek
#define LEN_MASK 0xff
38 6dc7a0cb Pavel Machek
#define LEN_PLUS  0x1000000
39
#define LEN_MINUS 0x2000000
40
#define LEN_RANGE 0x4000000
41
  /* If range then prefix must be in range (len >> 16 & 0xff, len >> 8 & 0xff) */
42 23b1539b Pavel Machek
};
43
44 b7005824 Pavel Machek
struct f_val {
45
  int type;
46
  union {
47
    int i;
48 6dc7a0cb Pavel Machek
    /*    ip_addr ip; Folded into prefix */        
49 b1c9d871 Martin Mares
    struct f_prefix px;
50 23b1539b Pavel Machek
    char *s;
51 38506f71 Pavel Machek
    struct f_tree *t;
52 10a53608 Pavel Machek
    struct adata *ad;
53
    struct f_path_mask *path_mask;
54 b7005824 Pavel Machek
  } val;
55
};
56
57 e0f2e42f Martin Mares
struct filter {
58
  char *name;
59
  struct f_inst *root;
60
};
61
62 b7005824 Pavel Machek
struct f_inst *f_new_inst(void);
63 a2d15746 Pavel Machek
struct f_inst *f_new_dynamic_attr(int type, int f_type, int code);        /* Type as core knows it, type as filters know it, and code of dynamic attribute */
64 38506f71 Pavel Machek
struct f_tree *f_new_tree(void);
65 ad9074e9 Pavel Machek
struct f_inst *f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument);
66 38506f71 Pavel Machek
67
struct f_tree *build_tree(struct f_tree *);
68
struct f_tree *find_tree(struct f_tree *t, struct f_val val);
69 9a4037d4 Pavel Machek
int same_tree(struct f_tree *t1, struct f_tree *t2);
70 84c7e194 Pavel Machek
71 9a706f32 Martin Mares
struct ea_list;
72
struct rte;
73
74 0a06a9b8 Pavel Machek
int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags);
75 b1c9d871 Martin Mares
int f_eval_int(struct f_inst *expr);
76 63a381db Martin Mares
char *filter_name(struct filter *filter);
77 30a6108c Martin Mares
int filter_same(struct filter *new, struct filter *old);
78 e0f2e42f Martin Mares
79 9a4037d4 Pavel Machek
int i_same(struct f_inst *f1, struct f_inst *f2);
80
81 38506f71 Pavel Machek
int val_compare(struct f_val v1, struct f_val v2);
82
void val_print(struct f_val v);
83 23b1539b Pavel Machek
84
#define F_NOP 0
85 d3dd620b Pavel Machek
#define F_NONL 1
86
#define F_ACCEPT 2        /* Need to preserve ordering: accepts < rejects! */
87 d46ffc97 Martin Mares
#define F_REJECT 3
88
#define F_ERROR 4
89
#define F_QUITBIRD 5
90 ca3d562b Pavel Machek
91 63a381db Martin Mares
#define FILTER_ACCEPT NULL
92
#define FILTER_REJECT ((void *) 1)
93
94 ba921648 Pavel Machek
/* Type numbers must be in 0..0xff range */
95
#define T_MASK 0xff
96
97
/* Internal types */
98 c7b43f33 Pavel Machek
/* Do not use type of zero, that way we'll see errors easier. */
99
#define T_VOID 1
100 ba921648 Pavel Machek
101
/* User visible types, which fit in int */
102
#define T_INT 0x10
103
#define T_BOOL 0x11
104 7a86a8b0 Pavel Machek
#define T_PAIR 0x12  /*        Notice that pair is stored as integer: first << 16 | second */
105 f4536657 Pavel Machek
106 2d496d20 Pavel Machek
/* Put enumerational types in 0x30..0x3f range */
107 f4536657 Pavel Machek
#define T_ENUM_LO 0x30
108 2d496d20 Pavel Machek
#define T_ENUM_HI 0x3f
109 f4536657 Pavel Machek
110 cb8034f4 Pavel Machek
#define T_ENUM_RTS 0x30
111 471bd6c3 Pavel Machek
#define T_ENUM_BGP_ORIGIN 0x31
112 26c09e1d Pavel Machek
#define T_ENUM_SCOPE 0x32
113
#define T_ENUM_RTC 0x33
114
#define T_ENUM_RTD 0x34
115 471bd6c3 Pavel Machek
/* new enums go here */
116 3bbc4ad6 Pavel Machek
#define T_ENUM_EMPTY 0x3f        /* Special hack for atomic_aggr */
117 cb8034f4 Pavel Machek
118 f4536657 Pavel Machek
#define T_ENUM T_ENUM_LO ... T_ENUM_HI
119 ba921648 Pavel Machek
120
/* Bigger ones */
121
#define T_IP 0x20
122
#define T_PREFIX 0x21
123
#define T_STRING 0x22
124 dcab7890 Pavel Machek
#define T_PATH_MASK 0x23        /* mask for BGP path */
125 10a53608 Pavel Machek
#define T_PATH 0x24                /* BGP path */
126
#define T_CLIST 0x25                /* Community list */
127 ba921648 Pavel Machek
128 2d496d20 Pavel Machek
#define T_RETURN 0x40
129 ba921648 Pavel Machek
#define T_SET 0x80
130 d36d838d Pavel Machek
131 38506f71 Pavel Machek
struct f_tree {
132
  struct f_tree *left, *right;
133
  struct f_val from, to;
134
  void *data;
135
};
136
137 d3dd620b Pavel Machek
#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val));
138
139 3076b5ae Martin Mares
#define FF_FORCE_TMPATTR 1                /* Force all attributes to be temporary */
140 0a06a9b8 Pavel Machek
141 b9d70dc8 Pavel Machek
#endif