Importing all of DRL, including ulogd and all of its files.
[distributedratelimiting.git] / include / ulogd / ulogd.h
1 #ifndef _ULOGD_H
2 #define _ULOGD_H
3 /* ulogd, Version $Revision: 5369 $
4  *
5  * userspace logging daemon for netfilter ULOG target
6  * of the linux 2.4 netfilter subsystem.
7  *
8  * (C) 2000 by Harald Welte <laforge@gnumonks.org>
9  *
10  * this code is released under the terms of GNU GPL
11  *
12  * $Id: ulogd.h 5369 2005-05-04 01:16:57Z laforge $
13  */
14
15 #include <libipulog/libipulog.h>
16 #include <stdio.h>
17 #include <signal.h>     /* need this because of extension-sighandler */
18
19 /* All types with MSB = 1 make use of value.ptr
20  * other types use one of the union's member */
21
22 /* types without length */
23 #define ULOGD_RET_NONE          0x0000
24
25 #define ULOGD_RET_INT8          0x0001
26 #define ULOGD_RET_INT16         0x0002
27 #define ULOGD_RET_INT32         0x0003
28 #define ULOGD_RET_INT64         0x0004
29
30 #define ULOGD_RET_UINT8         0x0011
31 #define ULOGD_RET_UINT16        0x0012
32 #define ULOGD_RET_UINT32        0x0013
33 #define ULOGD_RET_UINT64        0x0014
34
35 #define ULOGD_RET_BOOL          0x0050
36
37 #define ULOGD_RET_IPADDR        0x0100
38
39 /* types with length field */
40 #define ULOGD_RET_STRING        0x8020
41 #define ULOGD_RET_RAW           0x8030
42
43
44 /* FLAGS */
45 #define ULOGD_RETF_NONE         0x0000
46 #define ULOGD_RETF_VALID        0x0001  /* contains a valid result */
47 #define ULOGD_RETF_FREE         0x0002  /* ptr needs to be free()d */
48
49
50 /* maximum length of ulogd key */
51 #define ULOGD_MAX_KEYLEN 32
52
53 #define ULOGD_DEBUG     1       /* debugging information */
54 #define ULOGD_INFO      3
55 #define ULOGD_NOTICE    5       /* abnormal/unexpected condition */
56 #define ULOGD_ERROR     7       /* error condition, requires user action */
57 #define ULOGD_FATAL     8       /* fatal, program aborted */
58
59 typedef struct ulog_iret {
60         /* next interpreter return (key) in the global list */
61         struct ulog_iret *next;
62         /* next interpreter in linked list for current result */
63         struct ulog_iret *cur_next;
64         /* length of the returned value (only for lengthed types */
65         u_int32_t len;
66         /* type of the returned value (ULOGD_IRET_...) */
67         u_int16_t type;
68         /* flags (i.e. free, ...) */
69         u_int16_t flags;
70         /* name of this key */
71         char key[ULOGD_MAX_KEYLEN];
72         /* and finally the returned value */
73         union {
74                 u_int8_t        b;
75                 u_int8_t        ui8;
76                 u_int16_t       ui16;
77                 u_int32_t       ui32;
78                 u_int64_t       ui64;
79                 int8_t          i8;
80                 int16_t         i16;
81                 int32_t         i32;
82                 int64_t         i64;
83                 void            *ptr;
84         } value;
85 } ulog_iret_t;
86
87 typedef struct ulog_interpreter {
88         /* next interpreter in old-style linked list */
89         struct ulog_interpreter *next;
90         /* name of this interpreter (predefined by plugin) */
91         char name[ULOGD_MAX_KEYLEN];
92         /* ID for this interpreter (dynamically assigned) */
93         unsigned int id;
94         /* function to call for each packet */
95         ulog_iret_t* (*interp)(struct ulog_interpreter *ip, 
96                                 ulog_packet_msg_t *pkt);
97         /* number of keys this interpreter has */
98         unsigned int key_num;
99         /* keys of this particular interpreter */
100         ulog_iret_t *result;
101 } ulog_interpreter_t;
102
103 typedef struct ulog_output {
104         /* next output in the linked list */
105         struct ulog_output *next;
106         /* name of this ouput plugin */
107         char name[ULOGD_MAX_KEYLEN];
108         /* callback for initialization */
109         int (*init)(void);
110         /* callback for de-initialization */
111         void (*fini)(void);
112         /* callback function */
113         int (*output)(ulog_iret_t *ret);
114         /* callback function for signals (SIGHUP, ..) */
115         void (*signal)(int signal);
116 } ulog_output_t;
117
118 /* entries of the key hash */
119 struct ulogd_keyh_entry {
120         ulog_interpreter_t *interp;     /* interpreter for this key */
121         unsigned int offset;            /* offset within interpreter */
122         const char *name;               /* name of this particular key */
123 };
124
125 /***********************************************************************
126  * PUBLIC INTERFACE 
127  ***********************************************************************/
128
129 /* register a new interpreter plugin */
130 void register_interpreter(ulog_interpreter_t *me);
131
132 /* register a new output target */
133 void register_output(ulog_output_t *me);
134
135 /* allocate a new ulog_iret_t */
136 ulog_iret_t *alloc_ret(const u_int16_t type, const char*);
137
138 /* write a message to the daemons' logfile */
139 void __ulogd_log(int level, char *file, int line, const char *message, ...);
140 /* macro for logging including filename and line number */
141 #define ulogd_log(level, format, args...) \
142         __ulogd_log(level, __FILE__, __LINE__, format, ## args)
143 /* backwards compatibility */
144 #define ulogd_error(format, args...) ulogd_log(ULOGD_ERROR, format, ## args)
145
146 /* get an interpreter hash id by name */
147 unsigned int interh_getid(const char *name);
148
149 /* get a key id if you have the name */
150 unsigned int keyh_getid(const char *name);
151
152 /* get a result for a given key id */
153 ulog_iret_t *keyh_getres(unsigned int id);
154
155 /* the key hash itself */
156 extern struct ulogd_keyh_entry *ulogd_keyh;
157
158 #define IS_VALID(x)     (x.flags & ULOGD_RETF_VALID)
159
160 #define SET_VALID(x)    (x.flags |= ULOGD_RETF_VALID)
161
162 #endif /* _ULOGD_H */