2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file vpn/gnunet-helper-hijack-dns.c
24 * @author Philipp Tölke
28 #include "gnunet_common.h"
31 fork_and_exec (char *file, char *cmd[])
37 fprintf (stderr, "could not fork: %s\n", strerror (errno));
49 waitpid (pid, &st, 0);
51 return WIFEXITED (st) && (WEXITSTATUS (st) == 0);
55 main (int argc, char **argv)
64 if (strncmp (argv[1], "-d", 2) == 0)
69 port = atoi (argv[2]);
74 port = atoi (argv[1]);
83 if (stat ("/sbin/iptables", &s) < 0)
85 fprintf (stderr, "stat on /sbin/iptables failed: %s\n", strerror (errno));
88 if (stat ("/sbin/ip", &s) < 0)
90 fprintf (stderr, "stat on /sbin/ip failed: %s\n", strerror (errno));
96 snprintf (localport, 7, "%d", port);
103 r = fork_and_exec ("/sbin/ip", (char *[])
105 "ip", "route", "del", "default", "via", virt_dns,
106 "table", "2", NULL});
108 r = fork_and_exec ("/sbin/ip", (char *[])
110 "ip", "rule", "del", "fwmark", "3", "table", "2", NULL});
112 r = fork_and_exec ("/sbin/iptables", (char *[])
114 "iptables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp",
115 "--dport", "53", "-j", "MARK", "--set-mark", "3", NULL});
117 r = fork_and_exec ("/sbin/iptables", (char *[])
119 "iptables", "-t", "mangle", "-D", "OUTPUT", "-p", "udp",
120 "--sport", localport, "--dport", "53", "-j", "ACCEPT",
127 r = fork_and_exec ("/sbin/iptables", (char *[])
129 "iptables", "-t", "mangle", "-I", "OUTPUT", "1", "-p",
130 "udp", "--sport", localport, "--dport", "53", "-j",
134 r = fork_and_exec ("/sbin/iptables", (char *[])
136 "iptables", "-t", "mangle", "-I", "OUTPUT", "2", "-p",
137 "udp", "--dport", "53", "-j", "MARK", "--set-mark", "3",
141 r = fork_and_exec ("/sbin/ip", (char *[])
143 "ip", "rule", "add", "fwmark", "3", "table", "2", NULL});
146 r = fork_and_exec ("/sbin/ip", (char *[])
148 "ip", "route", "add", "default", "via", virt_dns,
149 "table", "2", NULL});
155 return GNUNET_SYSERR;