blob: 903834b10470111caab8334a613c81b8a277c753 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/*
* fwd - OpenWrt firewall daemon - main part
*
* Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
*
* The fwd program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* The fwd program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with the fwd program. If not, see http://www.gnu.org/licenses/.
*/
#include "fwd.h"
#include "fwd_addr.h"
#include "fwd_rules.h"
#include "fwd_config.h"
#include "fwd_xtables.h"
int main(int argc, const char *argv[])
{
struct fwd_handle *h;
if( getuid() > 0 )
fwd_fatal("Need root permissions!");
if( !(h = fwd_alloc_ptr(struct fwd_handle)) )
fwd_fatal("Out of memory");
if( !(h->conf = fwd_read_config()) )
fwd_fatal("Failed to read configuration");
if( (h->rtnl_socket = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1 )
fwd_fatal("Failed to create AF_NETLINK socket (%m)");
if( !(h->addrs = fwd_get_addrs(h->rtnl_socket, AF_INET)) )
fwd_fatal("Failed to issue RTM_GETADDR (%m)");
fwd_ipt_build_ruleset(h);
fwd_ipt_addif(h, "lan");
fwd_ipt_addif(h, "wan");
sleep(1);
fwd_ipt_delif(h, "wan");
fwd_ipt_delif(h, "lan");
fwd_ipt_clear_ruleset(h);
close(h->rtnl_socket);
fwd_free_config(h->conf);
fwd_free_addrs(h->addrs);
fwd_free_ptr(h);
return 0;
}
|