summaryrefslogtreecommitdiffhomepage
path: root/contrib/fwd/src/fwd.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-12-09 02:15:59 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-12-09 02:15:59 +0000
commit2e9ac3b3420350737aa37d01c0418bede10ab401 (patch)
tree352ff51ea0379c7709deb28dc8a18318ba47f806 /contrib/fwd/src/fwd.c
parente8220d96a52be888db8611e2908cb3ba97dfe2f8 (diff)
contrib: fwd - initial C implementation of the uci firewall
Diffstat (limited to 'contrib/fwd/src/fwd.c')
-rw-r--r--contrib/fwd/src/fwd.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/contrib/fwd/src/fwd.c b/contrib/fwd/src/fwd.c
new file mode 100644
index 0000000000..44b7f5a126
--- /dev/null
+++ b/contrib/fwd/src/fwd.c
@@ -0,0 +1,57 @@
+/*
+ * 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"
+
+#define IPT "iptables"
+
+
+int main(int argc, const char *argv[])
+{
+ struct fwd_handle *h;
+
+ 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");
+
+
+ close(h->rtnl_socket);
+ fwd_free_config(h->conf);
+ fwd_free_addrs(h->addrs);
+ fwd_free_ptr(h);
+
+ return 0;
+}