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
[])
32 fwd_fatal("Need root permissions!");
34 if( !(h
= fwd_alloc_ptr(struct fwd_handle
)) )
35 fwd_fatal("Out of memory");
37 if( !(h
->conf
= fwd_read_config()) )
38 fwd_fatal("Failed to read configuration");
40 if( (h
->rtnl_socket
= socket(AF_NETLINK
, SOCK_RAW
, NETLINK_ROUTE
)) == -1 )
41 fwd_fatal("Failed to create AF_NETLINK socket (%m)");
43 if( !(h
->addrs
= fwd_get_addrs(h
->rtnl_socket
, AF_INET
)) )
44 fwd_fatal("Failed to issue RTM_GETADDR (%m)");
46 fwd_ipt_build_ruleset(h
);
48 fwd_ipt_addif(h
, "lan");
49 fwd_ipt_addif(h
, "wan");
53 fwd_ipt_delif(h
, "wan");
54 fwd_ipt_delif(h
, "lan");
56 fwd_ipt_clear_ruleset(h
);
58 close(h
->rtnl_socket
);
59 fwd_free_config(h
->conf
);
60 fwd_free_addrs(h
->addrs
);