Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (3.3 KB)

1
/*
2
 *        BIRD Internet Routing Daemon -- Filters
3
 *
4
 *        (c) 1999 Pavel Machek <pavel@ucw.cz>
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"
13
#include "lib/ip.h"
14
#include "nest/attrs.h"
15

    
16
struct f_inst {                /* Instruction */
17
  struct f_inst *next;        /* Structure is 16 bytes, anyway */
18
  u16 code;
19
  u16 aux;
20
  union {
21
    int i;
22
    void *p;
23
  } a1;
24
  union {
25
    int i;
26
    void *p;
27
  } a2;
28
  int lineno;
29
};
30

    
31
#define arg1 a1.p
32
#define arg2 a2.p
33

    
34
struct f_prefix {
35
  ip_addr ip;
36
  int len;
37
#define LEN_MASK 0xff
38
#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
};
43

    
44
struct f_val {
45
  int type;
46
  union {
47
    int i;
48
    /*    ip_addr ip; Folded into prefix */        
49
    struct f_prefix px;
50
    char *s;
51
    struct f_tree *t;
52
    struct adata *ad;
53
    struct f_path_mask *path_mask;
54
  } val;
55
};
56

    
57
struct filter {
58
  char *name;
59
  struct f_inst *root;
60
};
61

    
62
struct f_inst *f_new_inst(void);
63
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
struct f_tree *f_new_tree(void);
65
struct f_inst *f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument);
66

    
67
struct f_tree *build_tree(struct f_tree *);
68
struct f_tree *find_tree(struct f_tree *t, struct f_val val);
69
int same_tree(struct f_tree *t1, struct f_tree *t2);
70

    
71
struct ea_list;
72
struct rte;
73

    
74
int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags);
75
int f_eval_int(struct f_inst *expr);
76
char *filter_name(struct filter *filter);
77
int filter_same(struct filter *new, struct filter *old);
78

    
79
int i_same(struct f_inst *f1, struct f_inst *f2);
80

    
81
int val_compare(struct f_val v1, struct f_val v2);
82
void val_print(struct f_val v);
83

    
84
#define F_NOP 0
85
#define F_NONL 1
86
#define F_ACCEPT 2        /* Need to preserve ordering: accepts < rejects! */
87
#define F_REJECT 3
88
#define F_ERROR 4
89
#define F_QUITBIRD 5
90

    
91
#define FILTER_ACCEPT NULL
92
#define FILTER_REJECT ((void *) 1)
93

    
94
/* Type numbers must be in 0..0xff range */
95
#define T_MASK 0xff
96

    
97
/* Internal types */
98
/* Do not use type of zero, that way we'll see errors easier. */
99
#define T_VOID 1
100

    
101
/* User visible types, which fit in int */
102
#define T_INT 0x10
103
#define T_BOOL 0x11
104
#define T_PAIR 0x12  /*        Notice that pair is stored as integer: first << 16 | second */
105

    
106
/* Put enumerational types in 0x30..0x3f range */
107
#define T_ENUM_LO 0x30
108
#define T_ENUM_HI 0x3f
109

    
110
#define T_ENUM_RTS 0x30
111
#define T_ENUM_BGP_ORIGIN 0x31
112
#define T_ENUM_SCOPE 0x32
113
#define T_ENUM_RTC 0x33
114
#define T_ENUM_RTD 0x34
115
/* new enums go here */
116
#define T_ENUM_EMPTY 0x3f        /* Special hack for atomic_aggr */
117

    
118
#define T_ENUM T_ENUM_LO ... T_ENUM_HI
119

    
120
/* Bigger ones */
121
#define T_IP 0x20
122
#define T_PREFIX 0x21
123
#define T_STRING 0x22
124
#define T_PATH_MASK 0x23        /* mask for BGP path */
125
#define T_PATH 0x24                /* BGP path */
126
#define T_CLIST 0x25                /* Community list */
127

    
128
#define T_RETURN 0x40
129
#define T_SET 0x80
130

    
131
struct f_tree {
132
  struct f_tree *left, *right;
133
  struct f_val from, to;
134
  void *data;
135
};
136

    
137
#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val));
138

    
139
#define FF_FORCE_TMPATTR 1                /* Force all attributes to be temporary */
140

    
141
#endif