Statistics
| Branch: | Revision:

iof-bird-daemon / filter / filter.h @ 4847a894

History | View | Annotate | Download (3.32 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/route.h"
15
#include "nest/attrs.h"
16

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

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

    
35
struct f_prefix {
36
  ip_addr ip;
37
  int len;
38
#define LEN_MASK 0xff
39
#define LEN_PLUS  0x1000000
40
#define LEN_MINUS 0x2000000
41
#define LEN_RANGE 0x4000000
42
  /* If range then prefix must be in range (len >> 16 & 0xff, len >> 8 & 0xff) */
43
};
44

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

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

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

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

    
72
struct ea_list;
73
struct rte;
74

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

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

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

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

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

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

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

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

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

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

    
119
#define T_ENUM T_ENUM_LO ... T_ENUM_HI
120

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

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

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

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

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

    
142
#endif