2 * fwd - OpenWrt firewall daemon - data structures
4 * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
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.
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.
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/.
28 #include <netinet/in.h>
32 #include "fwd_rules.h"
33 #include "fwd_config.h"
61 struct fwd_portrange {
86 struct fwd_network_list {
90 struct fwd_cidr *addr;
91 struct fwd_network_list *next;
95 enum fwd_policy input;
96 enum fwd_policy forward;
97 enum fwd_policy output;
106 struct fwd_network_list *networks;
107 struct fwd_data *forwardings;
108 struct fwd_data *redirects;
109 struct fwd_data *rules;
110 enum fwd_policy input;
111 enum fwd_policy forward;
112 enum fwd_policy output;
118 struct fwd_forwarding {
119 struct fwd_zone *src;
120 struct fwd_zone *dest;
121 int mtu_fix; /* legacy */
125 struct fwd_redirect {
126 struct fwd_zone *src;
127 struct fwd_cidr *src_ip;
128 struct fwd_mac *src_mac;
129 struct fwd_portrange *src_port;
130 struct fwd_portrange *src_dport;
131 struct fwd_cidr *dest_ip;
132 struct fwd_portrange *dest_port;
133 struct fwd_proto *proto;
134 int clone; /* true if rule is cloned (tcpudp -> tcp + udp) */
138 struct fwd_zone *src;
139 struct fwd_zone *dest;
140 struct fwd_cidr *src_ip;
141 struct fwd_mac *src_mac;
142 struct fwd_portrange *src_port;
143 struct fwd_cidr *dest_ip;
144 struct fwd_portrange *dest_port;
145 struct fwd_proto *proto;
146 struct fwd_icmptype *icmp_type;
147 enum fwd_policy target;
148 int clone; /* true if rule is cloned (tcpudp -> tcp + udp) */
157 struct fwd_data *next;
159 struct fwd_defaults defaults;
160 struct fwd_zone zone;
161 struct fwd_forwarding forwarding;
162 struct fwd_redirect redirect;
163 struct fwd_rule rule;
164 struct fwd_include include;
171 struct fwd_data *conf;
172 struct fwd_addr_list *addrs;
176 /* fwd_zmalloc(size_t)
177 * Allocates a zeroed buffer of the given size. */
178 static void * fwd_zmalloc(size_t s)
188 /* fwd_fatal(fmt, ...)
189 * Prints message to stderr and termintes program. */
190 #define fwd_fatal(...) do { \
191 fprintf(stderr, "ERROR: "); \
192 fprintf(stderr, __VA_ARGS__); \
193 fprintf(stderr, "\n"); \
197 /* fwd_alloc_ptr(type)
198 * Allocates a buffer with the size of the given datatype
199 * and returns a pointer to it. */
200 #define fwd_alloc_ptr(t) (t *) fwd_zmalloc(sizeof(t))
202 /* fwd_free_ptr(void *)
203 * Frees the given pointer and sets it to NULL.
204 * Safe for NULL values. */
205 #define fwd_free_ptr(x) do { if(x != NULL) free(x); x = NULL; } while(0)