File: data.h

package info (click to toggle)
tcng 10b-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 3,636 kB
  • ctags: 2,515
  • sloc: ansic: 19,040; pascal: 4,640; yacc: 2,619; sh: 1,914; perl: 1,546; lex: 772; makefile: 756
file content (151 lines) | stat: -rw-r--r-- 4,024 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
/*
 * data.h - Typed data containers
 *
 * Written 2001,2002 by Werner Almesberger
 * Copyright 2001 EPFL-ICA, Network Robots
 * Copyright 2002 Bivio Networks, Network Robots, Werner Almesberger
 */


#ifndef DATA_H
#define DATA_H


#include <stdint.h>
#include <stdio.h>

#include <u128.h>


/* including tree.h would cause circular dependency via param.h:PARAM */
struct _qdisc;
struct _class;
struct _filter;
struct _police;
/* ditto for op.h */
struct _op;
/* ditto for field.h */
struct _field;
struct _field_root;


typedef enum {
    dt_none,	/* no data */
    dt_unum,	/* unsigned integer (don't trust double to preserve a u32) */
    dt_ipv4,	/* like dt_unum, but we know this is an IPv4 address */
    dt_ipv6,	/* 128 bit integer representing an IPv6 address */
    dt_fnum,	/* floating-point number */
    dt_string,	/* string (malloc'ed) */
    dt_rate,	/* rate (bits per second) */
    dt_size,	/* size (Bytes) */
    dt_prate,	/* rate (packets per second) */
    dt_psize,	/* size (packets) */
    dt_time,	/* time (seconds) */
    dt_device,	/* device (internal use only) */
    dt_qdisc,	/* queuing discipline */
    dt_class,	/* class */
    dt_filter,	/* filter */
    dt_tunnel,	/* tunnel (internal use only) */
    dt_police,	/* policer */
    dt_bucket,	/* bucket */
    dt_list,	/* list of data elements */
    dt_field,	/* field */
    dt_field_root,
		/* field root */
    dt_decision,/* generalized policing decision */
    dt_assoc,	/* associative array (structure) */
} DATA_TYPE;


struct _data;


typedef enum {
    dr_continue,	/* continue/unspec */
    dr_class,		/* pass/ok */
    dr_drop,		/* drop/shot */
    dr_reclassify,	/* reclassify */
} DECISION_RESULT;

typedef struct _data_list {
    struct _data *ref;		/* pointer to actual data */
    struct _data_list *next;	/* next list element */
} DATA_LIST;

typedef struct _data {
    DATA_TYPE type;
    struct _op *op;
	/* if non-NULL, u is invalid and the expression is variable */
    union {
	uint32_t unum;		/* dt_unum, dt_ipv4 */
	U128 u128;		/* dt_ipv6 */
	double fnum;		/* dt_fnum, dt_p?rate, dt_p?size, dt_time */
	char *string;		/* dt_string */
	struct _device *device;	/* dt_device */
	struct _qdisc *qdisc;	/* dt_qdisc */
	struct _class *class;	/* dt_class */
	struct _filter *filter;	/* dt_filter */
	struct _tunnel *tunnel;	/* dt_tunnel */
	struct _police *police;	/* dt_police, dt_bucket */
	DATA_LIST *list;	/* dt_list */
	struct _field *field;	/* dt_field */
	struct _field_root *field_root;
				/* dt_field_root */
	struct {
	    DECISION_RESULT result;
	    const struct _class *class;
	} decision;		/* dt_decision */
	struct _data_assoc *assoc;
				/* dt_assoc */
    } u;
} DATA;

typedef struct _data_assoc {
    const char *name;		/* malloc'ed name */
    DATA data;
    const struct _data_assoc *parent; /* for reverse tree traversal */
    struct _data_assoc *next;
} DATA_ASSOC;


DATA data_none(void);
DATA data_unum(uint32_t in);
DATA data_ipv4(uint32_t in);
DATA data_ipv6(U128 in);
DATA data_fnum(double in);
DATA data_typed_fnum(double in,DATA_TYPE type);
DATA data_string(const char *in);
DATA data_device(struct _device *in);
DATA data_qdisc(struct _qdisc *in);
DATA data_class(struct _class *in);
DATA data_decision(DECISION_RESULT result,struct _class *class);
DATA data_filter(struct _filter *in);
DATA data_tunnel(struct _tunnel *in);
DATA data_police(struct _police *in);
DATA data_bucket(struct _police *in);
DATA data_list(DATA_LIST *list);
DATA_LIST *data_list_element(DATA *ref);
DATA data_field(struct _field *field);
DATA data_field_root(struct _field_root *field_root);
DATA data_assoc(void);

const char *type_name(DATA_TYPE type);

DATA data_convert(DATA in,DATA_TYPE type);
int type_is_u32(DATA_TYPE type);

/*
 * unit.type must be dt_none, dt_p?rate, dt_p?size, or dt_time
 */

DATA data_add_unit(DATA in,DATA unit);

DATA data_clone(DATA d);
int data_equal(DATA a,DATA b);

void data_destroy_1(DATA d);
void data_destroy(DATA d);

void print_data(FILE *file,DATA d);

#endif /* DATA_H */