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"
24 #include "fwd_xtables.h"
27 int main(int argc, const char *argv[])
30 struct iptc_handle *ipt;
33 fwd_fatal("Need root permissions!");
35 if( !(h = fwd_alloc_ptr(struct fwd_handle)) )
36 fwd_fatal("Out of memory");
38 if( !(h->conf = fwd_read_config()) )
39 fwd_fatal("Failed to read configuration");
41 if( (h->rtnl_socket = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1 )
42 fwd_fatal("Failed to create AF_NETLINK socket (%m)");
44 if( !(h->addrs = fwd_get_addrs(h->rtnl_socket, AF_INET)) )
45 fwd_fatal("Failed to issue RTM_GETADDR (%m)");
47 fwd_ipt_build_ruleset(h);
49 fwd_ipt_addif(h, "lan");
50 fwd_ipt_addif(h, "wan");
52 close(h->rtnl_socket);
53 fwd_free_config(h->conf);
54 fwd_free_addrs(h->addrs);