-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdat.h
132 lines (112 loc) · 2.67 KB
/
dat.h
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
/*
* This file is part of the UCB release of Plan 9. It is subject to the license
* terms in the LICENSE file found in the top-level directory of this
* distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
* part of the UCB release of Plan 9, including this file, may be copied,
* modified, propagated, or distributed except according to the terms contained
* in the LICENSE file.
*/
#pragma once
#include <parlib/timing.h>
#include <iplib/iplib.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#define ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
typedef struct Field Field;
typedef struct Filter Filter;
typedef struct Msg Msg;
typedef struct Mux Mux;
typedef struct Proto Proto;
#define NetS(x) ((((uint8_t*)x)[0]<<8) | ((uint8_t*)x)[1])
#define Net3(x) ((((uint8_t*)x)[0]<<16) | (((uint8_t*)x)[1]<<8) | ((uint8_t*)x)[2])
#define NetL(x) ((((uint8_t*)x)[0]<<24) | (((uint8_t*)x)[1]<<16) | (((uint8_t*)x)[2]<<8) | ((uint8_t*)x)[3])
/*
* one per protocol module
*/
struct Proto
{
char* name;
void (*compile)(Filter*);
int (*filter)(Filter*, Msg*);
int (*seprint)(Msg*);
Mux* mux;
char* valfmt;
Field* field;
int (*framer)(int, uint8_t*, int);
};
extern Proto *protos[];
/*
* one per protocol module, pointed to by Proto.mux
*/
struct Mux
{
char* name;
uint32_t val;
Proto* pr;
};
/*
* a field defining a comparison filter
*/
struct Field
{
char* name;
int ftype;
int subop;
char* help;
};
/*
* the status of the current message walk
*/
struct Msg
{
uint8_t *ps; /* packet ptr */
uint8_t *pe; /* packet end */
char *p; /* buffer start */
char *e; /* buffer end */
int needroot; /* pr is root, need to see in expression */
Proto *pr; /* current/next protocol */
};
enum
{
Fnum, /* just a number */
Fether, /* ethernet address */
Fv4ip, /* v4 ip address */
Fv6ip, /* v6 ip address */
Fba, /* byte array */
};
/*
* a node in the filter tree
*/
struct Filter {
int op; /* token type */
char *s; /* string */
Filter *l;
Filter *r;
Proto *pr; /* next protocol;*/
/* protocol specific */
int subop;
uint32_t param;
union {
uint32_t ulv;
int64_t vlv;
uint8_t a[32];
};
};
extern void yyinit(char*);
extern int yyparse(void);
extern Filter* newfilter(void);
extern void compile_cmp(char*, Filter*, Field*);
extern void demux(Mux*, uint32_t, uint32_t, Msg*, Proto*);
extern int defaultframer(int, uint8_t*, int);
extern int Mflag;
extern int Nflag;
extern int dflag;
extern int Cflag;
typedef Filter *Filterptr;
#define YYSTYPE Filterptr
extern Filter *filter;
char *seprint(char *buf, char *end, const char *fmt, ...);
void sysfatal(const char *fmt, ...);
int readn(int fd, uint8_t *buf, int len);