contrib/fwd: renamed struct fwd_{addr,network}_list to struct fwd_{network,addr}
[project/luci.git] / contrib / fwd / src / fwd.h
1 /*
2  * fwd - OpenWrt firewall daemon - data structures
3  *
4  *   Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
5  *
6  * The fwd program is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License version 2
8  * as published by the Free Software Foundation.
9  *
10  * The fwd program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with the fwd program. If not, see http://www.gnu.org/licenses/.
17  */
18
19 #ifndef __FWD_H__
20 #define __FWD_H__
21
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <getopt.h>
28 #include <signal.h>
29 #include <netinet/in.h>
30
31
32 enum fwd_policy {
33         FWD_P_UNSPEC = 0,
34         FWD_P_DROP   = 1,
35         FWD_P_REJECT = 2,
36         FWD_P_ACCEPT = 3
37 };
38
39 enum fwd_stype {
40         FWD_S_DEFAULTS = 0,
41         FWD_S_ZONE     = 1,
42         FWD_S_FORWARD  = 2,
43         FWD_S_REDIRECT = 3,
44         FWD_S_RULE     = 4,
45         FWD_S_INCLUDE  = 5
46 };
47
48 enum fwd_ptype {
49         FWD_PR_CUSTOM  = 0,
50         FWD_PR_TCP     = 1,
51         FWD_PR_UDP     = 2,
52         FWD_PR_TCPUDP  = 3,
53         FWD_PR_ICMP    = 4,
54         FWD_PR_ALL     = 5
55 };
56
57 struct fwd_portrange {
58         unsigned short min;
59         unsigned short max;
60 };
61
62 struct fwd_cidr {
63         struct in_addr addr;
64         int prefix;
65 };
66
67 struct fwd_mac {
68         unsigned char mac[6];
69 };
70
71 struct fwd_proto {
72         enum fwd_ptype type;
73         int proto;
74 };
75
76 struct fwd_icmptype {
77         char name[32];
78         int type;
79         int code;
80 };
81
82 struct fwd_network {
83         char *name;
84         char *ifname;
85         int isalias;
86         struct fwd_cidr *addr;
87         struct fwd_network *next;
88 };
89
90 struct fwd_defaults {
91         enum fwd_policy input;
92         enum fwd_policy forward;
93         enum fwd_policy output;
94         int syn_flood;
95         int syn_rate;
96         int syn_burst;
97         int drop_invalid;       
98 };
99
100 struct fwd_zone {
101         char *name;
102         struct fwd_network *networks;
103         struct fwd_data *forwardings;
104         struct fwd_data *redirects;
105         struct fwd_data *rules;
106         enum fwd_policy input;
107         enum fwd_policy forward;
108         enum fwd_policy output;
109         int masq;
110         int mtu_fix;
111         int conntrack;
112 };
113
114 struct fwd_forwarding {
115         struct fwd_zone *src;
116         struct fwd_zone *dest;
117         int mtu_fix;  /* legacy */
118         int masq;     /* new */
119 };
120
121 struct fwd_redirect {
122         struct fwd_zone      *src;
123         struct fwd_cidr      *src_ip;
124         struct fwd_mac       *src_mac;
125         struct fwd_portrange *src_port;
126         struct fwd_portrange *src_dport;
127         struct fwd_cidr      *dest_ip;
128         struct fwd_portrange *dest_port;
129         struct fwd_proto     *proto;
130         int clone; /* true if rule is cloned (tcpudp -> tcp + udp) */
131 };
132
133 struct fwd_rule {
134         struct fwd_zone      *src;
135         struct fwd_zone      *dest;
136         struct fwd_cidr      *src_ip;
137         struct fwd_mac       *src_mac;
138         struct fwd_portrange *src_port;
139         struct fwd_cidr      *dest_ip;
140         struct fwd_portrange *dest_port;
141         struct fwd_proto     *proto;
142         struct fwd_icmptype  *icmp_type;
143         enum fwd_policy target;
144         int clone; /* true if rule is cloned (tcpudp -> tcp + udp) */
145 };
146
147 struct fwd_include {
148         char *path;
149 };
150
151 struct fwd_data {
152         enum fwd_stype type;
153         struct fwd_data *next;
154         union {
155                 struct fwd_defaults   defaults;
156                 struct fwd_zone       zone;
157                 struct fwd_forwarding forwarding;
158                 struct fwd_redirect   redirect;
159                 struct fwd_rule       rule;
160                 struct fwd_include    include;
161         } section;
162 };
163
164
165 struct fwd_handle {
166         int rtnl_socket;
167         int unix_socket;
168         struct fwd_data *conf;
169 };
170
171
172 /* fwd_fatal(fmt, ...)
173  * Prints message to stderr and termintes program. */
174 #define fwd_fatal(...) do {       \
175         fprintf(stderr, "ERROR: ");   \
176         fprintf(stderr, __VA_ARGS__); \
177         fprintf(stderr, "\n");        \
178         exit(1);                      \
179 } while(0)
180
181
182 #endif