File: iflib.h

package info (click to toggle)
tcng 10b-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,644 kB
  • sloc: ansic: 19,040; pascal: 4,640; yacc: 2,619; sh: 1,914; perl: 1,546; lex: 772; makefile: 751
file content (152 lines) | stat: -rw-r--r-- 3,898 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * iflib.h - Functions for processing if expressions
 *
 * Written 2001,2002 by Werner Almesberger
 * Copyright 2001 EPFL-ICA, Network Robots
 * Copyright 2002 Network Robots, Werner Almesberger
 */


#ifndef IFLIB_H
#define IFLIB_H

#include <stdio.h>

#include "location.h"
#include "data.h"
#include "tree.h"


void complement_decisions(DATA *d,CLASS *class);
void iflib_comb_iterate(const QDISC *qdisc,
  void (*fn)(const ELEMENT *e,void *user),void *user);
DATA iflib_combine(const QDISC *qdisc);

/* Generate if expression from all filters on that qdisc */

void iflib_normalize(DATA *d);

/* Normalize && and || */

void iflib_reduce(DATA *d);

/* General optimizations */

void iflib_offset(DATA *d,int for_u32);

/*
 * Add and reduce explicit offset operators. If "for_u32" is non-zero,
 * iflib_offset also tries to combine offsets across sub-expressions, and it
 * ignores the meta field root.
 */

void iflib_actions(LOCATION loc,DATA *d);

/*
 * Convert actions to canonical format by moving policing and such pastall
 * matches.
 */

void iflib_arith(DATA *d);

/*
 * Perform various simple arithmetic optimizations.
 */

void iflib_not(DATA *d);

/*
 * Replace negations in logical expressions by re-arranging the expression
 * around || and &&.
 */

int expr_equal(DATA a,DATA b);

/*
 * Actually, this is a test for whether the expressions are _identical_, not
 * only equal. Returns non-zero if they are.
 */

int action_tree(DATA d);

/*
 * Returns non-zero if the sub-tree rooted at d consists exclusively of
 * policing operators, class selections, and logical operators combining
 * such things. I.e. any such sub-tree goes into the "actions" group at
 * the external interface, while all or part of a sub-tree for which
 * action_tree returns zero has to go into the "rules" group.
 */

typedef enum {
    sc_no,		/* not self_contained */
    sc_no_false,	/* not self-contained, expression is false */
    sc_no_true,		/* not self-contained, expression is true */
    sc_yes		/* is self-contained */
} SELF_CONTAINED;

SELF_CONTAINED self_contained(DATA d);

/*
 * A sub-tree is self_contained if it selects a class, or if any failed
 * conformance decisions lead to a self_contained subtree.
 *
 * Note: self_contained may incorrectly return 0 if the subtree is not an
 * action_tree.
 */

int side_effect(DATA d);

void prune_shortcuts(DATA *d);

/*
 * Used by iflib_act.c to clean out shortcuts uncovered by re-arranging
 * actions.
 */

void iflib_cheap_actions(LOCATION loc,DATA d);
void iflib_cheap_ops(LOCATION loc,DATA d);

/*
 * Refuse all operations that appear to be "expensive"
 */

void iflib_bit(FILE *file,QDISC *qdisc,DATA d);
void iflib_newbit(FILE *file,DATA d);
void iflib_fastbit(FILE *file,DATA d);


/* New action database handling from iflib_actdb.c: */

enum action_type { at_conform,at_count,at_class,at_drop,at_unspec };

struct action {
    enum action_type type;
    union {
	const POLICE *conform;	/* pointer to bucket */
	const POLICE *count;	/* pointer to bucket */
	const CLASS *decision;	/* use CLASS_TO_DECISION to convert to number */
    } u;
    struct action *parent;	/* parent in tree being constructed */
    struct action *c[2];	/* child if 0/1 */
    int number;			/* action number; -1 if none assigned */
    int dumped;			/* non-zero if entry has been dumped */
    struct action *next;	/* next action in list of entry points */
    struct action_referer *referers; /* referers in inverted tree */
};

struct action_referer {
    struct action *action;
    struct action_referer *next;
};

void register_actions(DATA d);
void write_actions(FILE *file,QDISC *qdisc);
const struct action *get_action(DATA d);
int action_number(DATA d);
void free_actions(void);


#define dump_failed(d,reason) __dump_failed(d,reason,__FILE__,__LINE__)
void __dump_failed(DATA d,const char *reason,const char *file,int line);

#endif /* IFLIB_H */