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/.
27 #include <netinet/in.h>
31 #include "fwd_rules.h"
32 #include "fwd_config.h"
60 struct fwd_portrange {
85 struct fwd_network_list {
89 struct fwd_cidr *addr;
90 struct fwd_network_list *next;
94 enum fwd_policy input;
95 enum fwd_policy forward;
96 enum fwd_policy output;
105 struct fwd_network_list *networks;
106 enum fwd_policy input;
107 enum fwd_policy forward;
108 enum fwd_policy output;
114 struct fwd_forwarding {
115 struct fwd_zone *src;
116 struct fwd_zone *dest;
117 int mtu_fix; /* legacy */
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;
133 struct fwd_zone *src;
134 struct fwd_zone *dest;
135 struct fwd_cidr *src_ip;
136 struct fwd_mac *src_mac;
137 struct fwd_portrange *src_port;
138 struct fwd_cidr *dest_ip;
139 struct fwd_portrange *dest_port;
140 struct fwd_proto *proto;
141 struct fwd_icmptype *icmp_type;
142 enum fwd_policy target;
151 struct fwd_data *next;
153 struct fwd_defaults defaults;
154 struct fwd_zone zone;
155 struct fwd_forwarding forwarding;
156 struct fwd_redirect redirect;
157 struct fwd_rule rule;
158 struct fwd_include include;
165 struct fwd_data *conf;
166 struct fwd_addr_list *addrs;
170 /* fwd_zmalloc(size_t)
171 * Allocates a zeroed buffer of the given size. */
172 static void * fwd_zmalloc(size_t s)
182 /* fwd_fatal(fmt, ...)
183 * Prints message to stderr and termintes program. */
184 #define fwd_fatal(...) do { \
185 fprintf(stderr, "ERROR: "); \
186 fprintf(stderr, __VA_ARGS__); \
187 fprintf(stderr, "\n"); \
191 /* fwd_alloc_ptr(type)
192 * Allocates a buffer with the size of the given datatype
193 * and returns a pointer to it. */
194 #define fwd_alloc_ptr(t) (t *) fwd_zmalloc(sizeof(t))
196 /* fwd_free_ptr(void *)
197 * Frees the given pointer and sets it to NULL.
198 * Safe for NULL values. */
199 #define fwd_free_ptr(x) do { if(x != NULL) free(x); x = NULL; } while(0)