2 * fwd - OpenWrt firewall daemon - main part
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/.
22 #include "fwd_rules.h"
23 #include "fwd_config.h"
25 #define IPT "iptables"
28 int main(int argc, const char *argv[])
32 if( !(h = fwd_alloc_ptr(struct fwd_handle)) )
33 fwd_fatal("Out of memory");
35 if( !(h->conf = fwd_read_config()) )
36 fwd_fatal("Failed to read configuration");
38 if( (h->rtnl_socket = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1 )
39 fwd_fatal("Failed to create AF_NETLINK socket (%m)");
41 if( !(h->addrs = fwd_get_addrs(h->rtnl_socket, AF_INET)) )
42 fwd_fatal("Failed to issue RTM_GETADDR (%m)");
45 fwd_ipt_build_ruleset(h);
47 fwd_ipt_addif(h, "lan");
48 fwd_ipt_addif(h, "wan");
51 close(h->rtnl_socket);
52 fwd_free_config(h->conf);
53 fwd_free_addrs(h->addrs);