]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/misc-progs/wirelessctrl.c
1 /* IPCop helper program - wirelessctrl
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Alan Hourihane, 2003
8 * $Id: wirelessctrl.c,v 1.2.2.5 2005/07/11 10:56:47 franck78 Exp $
12 #include "libsmooth.h"
18 #include <sys/types.h>
25 char blue_dev
[STRING_SIZE
] = "";
26 char command
[STRING_SIZE
];
30 char green_dev
[STRING_SIZE
] = "";
31 char buffer
[STRING_SIZE
];
32 char *index
, *ipaddress
, *macaddress
, *enabled
;
33 struct keyvalue
*kv
= NULL
;
38 /* flush wireless iptables */
39 safe_system("/sbin/iptables -F WIRELESSINPUT > /dev/null 2> /dev/null");
40 safe_system("/sbin/iptables -F WIRELESSFORWARD > /dev/null 2> /dev/null");
42 memset(buffer
, 0, STRING_SIZE
);
44 /* Init the keyvalue structure */
47 /* Read in the current values */
48 if (!readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings"))
50 fprintf(stderr
, "Cannot read ethernet settings\n");
54 /* Read in the firewall values */
55 if (!readkeyvalues(kv
, CONFIG_ROOT
"/optionsfw/settings"))
57 fprintf(stderr
, "Cannot read optionsfw settings\n");
61 /* Get the GREEN interface details */
62 if(!findkey(kv
, "GREEN_DEV", green_dev
))
64 fprintf(stderr
, "Cannot read GREEN_DEV\n");
67 if (!VALID_DEVICE(green_dev
))
69 fprintf(stderr
, "Bad GREEN_DEV: %s\n", green_dev
);
72 /* Get the BLUE interface details */
73 if(!findkey(kv
, "BLUE_DEV", blue_dev
))
75 fprintf(stderr
, "Cannot read BLUE_DEV\n");
78 if (strlen(blue_dev
) && !VALID_DEVICE(blue_dev
))
80 fprintf(stderr
, "Bad BLUE_DEV: %s\n", blue_dev
);
83 if(! strlen(blue_dev
) > 0)
85 fprintf(stderr
, "No BLUE interface\n");
91 if(findkey(kv
, "DROPWIRELESSINPUT", buffer
) && !strcmp(buffer
,"on")){
92 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSINPUT -i %s -j LOG --log-prefix 'DROP_Wirelessinput'", blue_dev
);
95 if(findkey(kv
, "DROPWIRELESSFORWARD", buffer
) && !strcmp(buffer
,"on")){
96 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSFORWARD -i %s -j LOG --log-prefix 'DROP_Wirelessforward'", blue_dev
);
99 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSINPUT -i %s -j DROP -m comment --comment 'DROP_Wirelessinput'", blue_dev
);
100 safe_system(command
);
101 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSFORWARD -i %s -j DROP -m comment --comment 'DROP_Wirelessforward'", blue_dev
);
102 safe_system(command
);
108 if (!(fd
= fopen(CONFIG_ROOT
"/wireless/config", "r")))
112 while (fgets(buffer
, STRING_SIZE
, fd
))
114 buffer
[strlen(buffer
) - 1] = 0;
116 index
= strtok(buffer
, ",");
117 ipaddress
= strtok(NULL
, ",");
118 macaddress
= strtok(NULL
, ",");
119 enabled
= strtok(NULL
, ",");
121 if (!strncmp(enabled
, "on", 2)) {
123 /* both specified, added security */
124 if ((strlen(macaddress
) == 17) &&
125 (VALID_IP(ipaddress
))) {
126 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSINPUT -m mac --mac-source %s -s %s -i %s -j ACCEPT", macaddress
, ipaddress
, blue_dev
);
127 safe_system(command
);
128 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSFORWARD -m mac --mac-source %s -s %s -i %s -o ! %s -j ACCEPT", macaddress
, ipaddress
, blue_dev
, green_dev
);
129 safe_system(command
);
130 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSFORWARD -m mac --mac-source %s -s %s -i %s -j DMZHOLES", macaddress
, ipaddress
, blue_dev
);
131 safe_system(command
);
134 /* correctly formed mac address is 17 chars */
135 if (strlen(macaddress
) == 17) {
136 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSINPUT -m mac --mac-source %s -i %s -j ACCEPT", macaddress
, blue_dev
);
137 safe_system(command
);
138 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSFORWARD -m mac --mac-source %s -i %s -o ! %s -j ACCEPT", macaddress
, blue_dev
, green_dev
);
139 safe_system(command
);
140 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSFORWARD -m mac --mac-source %s -i %s -j DMZHOLES", macaddress
, blue_dev
);
141 safe_system(command
);
144 if (VALID_IP(ipaddress
)) {
145 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSINPUT -s %s -i %s -j ACCEPT", ipaddress
, blue_dev
);
146 safe_system(command
);
147 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSFORWARD -s %s -i %s -o ! %s -j ACCEPT", ipaddress
, blue_dev
, green_dev
);
148 safe_system(command
);
149 snprintf(command
, STRING_SIZE
-1, "/sbin/iptables -A WIRELESSFORWARD -s %s -i %s -j DMZHOLES", ipaddress
, blue_dev
);
150 safe_system(command
);