| 54 | | char s_tag[16]; |
| 55 | | char script[MAX_BUF]; |
| 56 | | struct stat st; |
| 57 | | char *command[] = {script, "allow", ip, mac, s_tag, NULL}; |
| 58 | | |
| 59 | | sprintf(s_tag, "%-10d", tag); |
| 60 | | sprintf(script, "%s/%s/%s", config.fwscripts_path, config.fwtype, |
| 61 | | SCRIPT_FWACCESS); |
| 62 | | |
| 63 | | debug(LOG_DEBUG, "Allowing ip %s mac %s with MARK %s", ip, mac, s_tag); |
| 64 | | |
| 65 | | if (-1 == (stat(script, &st))) { |
| 66 | | debug(LOG_ERR, "Could not find %s: %s", script, |
| 67 | | strerror(errno)); |
| 68 | | return (1); |
| 69 | | } |
| 70 | | return (execute(command)); |
| | 54 | iptables_do_command("-t mangle -A wifidog_mark -s %s -m mac --mac-source %s -j MARK --set-mark %d", ip, mac, tag); |
| | 55 | |
| | 56 | return 1; |
| 87 | | char s_tag[16]; |
| 88 | | char script[MAX_BUF]; |
| 89 | | struct stat st; |
| 90 | | char *command[] = {script, "deny", ip, mac, s_tag, NULL}; |
| 91 | | |
| 92 | | sprintf(s_tag, "%-10d", tag); |
| 93 | | sprintf(script, "%s/%s/%s", config.fwscripts_path, config.fwtype, |
| 94 | | SCRIPT_FWACCESS); |
| 95 | | |
| 96 | | debug(LOG_DEBUG, "Denying ip %s mac %s with MARK %s", ip, mac, s_tag); |
| 97 | | |
| 98 | | if (-1 == (stat(script, &st))) { |
| 99 | | debug(LOG_ERR, "Could not find %s: %s", script, |
| 100 | | strerror(errno)); |
| 101 | | return (1); |
| 102 | | } |
| 103 | | return (execute(command)); |
| | 73 | iptables_do_command("-t mangle -D wifidog_mark -s %s -m mac --mac-source %s -j MARK --set-mark %d", ip, mac, tag); |
| | 74 | |
| | 75 | return 1; |
| 179 | | char port[16]; |
| 180 | | char script[MAX_BUF]; |
| 181 | | int rc; |
| 182 | | struct stat st; |
| 183 | | char *command[] = {script, config.gw_interface, config.gw_address, |
| 184 | | port, config.authserv_hostname, NULL}; |
| 185 | | |
| 186 | | sprintf(port, "%-5d", config.gw_port); |
| 187 | | sprintf(script, "%s/%s/%s", config.fwscripts_path, config.fwtype, |
| 188 | | SCRIPT_FWINIT); |
| 189 | | |
| 190 | | if (-1 == (stat(script, &st))) { |
| 191 | | debug(LOG_ERR, "Could not find %s: %s", script, |
| 192 | | strerror(errno)); |
| 193 | | debug(LOG_ERR, "Exiting..."); |
| 194 | | exit(1); |
| 195 | | } |
| 196 | | debug(LOG_NOTICE, "Setting firewall rules"); |
| 197 | | |
| 198 | | if ((rc = execute(command)) != 0) { |
| 199 | | debug(LOG_ERR, "Could not setup firewall, exiting..."); |
| 200 | | exit(1); |
| 201 | | } |
| 202 | | return (rc); |
| | 159 | debug(LOG_INFO, "Initializing Firewall"); |
| | 160 | |
| | 161 | iptables_do_command("-t nat -N wifidog_validate"); |
| | 162 | iptables_do_command("-t nat -A wifidog_validate -d %s -j ACCEPT", config.gw_address); |
| | 163 | iptables_do_command("-t nat -A wifidog_validate -d %s -j ACCEPT", config.authserv_hostname); |
| | 164 | iptables_do_command("-t nat -A wifidog_validate -p udp --dport 67 -j ACCEPT"); |
| | 165 | iptables_do_command("-t nat -A wifidog_validate -p tcp --dport 67 -j ACCEPT"); |
| | 166 | iptables_do_command("-t nat -A wifidog_validate -p udp --dport 53 -j ACCEPT"); |
| | 167 | iptables_do_command("-t nat -A wifidog_validate -p tcp --dport 80 -j ACCEPT"); |
| | 168 | iptables_do_command("-t nat -A wifidog_validate -p tcp --dport 443 -j ACCEPT"); |
| | 169 | iptables_do_command("-t nat -A wifidog_validate -j DROP"); |
| | 170 | |
| | 171 | iptables_do_command("-t nat -N wifidog_unknown"); |
| | 172 | iptables_do_command("-t nat -A wifidog_unknown -d %s -j ACCEPT", config.gw_address); |
| | 173 | iptables_do_command("-t nat -A wifidog_unknown -d %s -j ACCEPT", config.authserv_hostname); |
| | 174 | iptables_do_command("-t nat -A wifidog_unknown -p udp --dport 67 -j ACCEPT"); |
| | 175 | iptables_do_command("-t nat -A wifidog_unknown -p tcp --dport 67 -j ACCEPT"); |
| | 176 | iptables_do_command("-t nat -A wifidog_unknown -p udp --dport 53 -j ACCEPT"); |
| | 177 | iptables_do_command("-t nat -A wifidog_unknown -p tcp --dport 80 -j REDIRECT --to-ports %d", config.gw_port); |
| | 178 | iptables_do_command("-t nat -A wifidog_unknown -j DROP"); |
| | 179 | |
| | 180 | iptables_do_command("-t nat -N wifidog_known"); |
| | 181 | iptables_do_command("-t nat -A wifidog_known -j ACCEPT"); |
| | 182 | |
| | 183 | iptables_do_command("-t nat -N wifidog_locked"); |
| | 184 | iptables_do_command("-t nat -A wifidog_locked -j DROP"); |
| | 185 | |
| | 186 | iptables_do_command("-t nat -N wifidog_class"); |
| | 187 | iptables_do_command("-t nat -A wifidog_class -i %s -m mark --mark 0x1 -j wifidog_validate", config.gw_interface); |
| | 188 | iptables_do_command("-t nat -A wifidog_class -i %s -m mark --mark 0x2 -j wifidog_known", config.gw_interface); |
| | 189 | iptables_do_command("-t nat -A wifidog_class -i %s -m mark --mark 0x254 -j wifidog_locked", config.gw_interface); |
| | 190 | iptables_do_command("-t nat -A wifidog_class -i %s -j wifidog_unknown", config.gw_interface); |
| | 191 | |
| | 192 | iptables_do_command("-t mangle -N wifidog_mark"); |
| | 193 | |
| | 194 | iptables_do_command("-t mangle -I PREROUTING 1 -i %s -j wifidog_mark", config.gw_interface); |
| | 195 | |
| | 196 | iptables_do_command("-t nat -I PREROUTING 1 -i %s -j wifidog_class", config.gw_interface); |
| | 197 | |
| | 198 | return 1; |
| 215 | | char script[MAX_BUF]; |
| 216 | | struct stat st; |
| 217 | | char *command[] = {script, config.gw_interface, NULL}; |
| 218 | | |
| 219 | | sprintf(script, "%s/%s/%s", config.fwscripts_path, config.fwtype, |
| 220 | | SCRIPT_FWDESTROY); |
| 221 | | |
| 222 | | if (-1 == (stat(script, &st))) { |
| 223 | | debug(LOG_ERR, "Could not find %s: %s", script, |
| 224 | | strerror(errno)); |
| 225 | | return (1); |
| 226 | | } |
| 227 | | debug(LOG_NOTICE, "Flushing firewall rules"); |
| 228 | | |
| 229 | | return (execute(command)); |
| | 211 | int rc, tries, fd; |
| | 212 | |
| | 213 | debug(LOG_INFO, "Removing Firewall rules"); |
| | 214 | |
| | 215 | iptables_do_command("-t nat -F wifidog_class"); |
| | 216 | iptables_do_command("-t mangle -F wifidog_mark"); |
| | 217 | |
| | 218 | iptables_do_command("-t nat -F wifidog_validate"); |
| | 219 | iptables_do_command("-t nat -F wifidog_unknown"); |
| | 220 | iptables_do_command("-t nat -F wifidog_known"); |
| | 221 | iptables_do_command("-t nat -F wifidog_locked"); |
| | 222 | iptables_do_command("-t nat -X wifidog_validate"); |
| | 223 | iptables_do_command("-t nat -X wifidog_unknown"); |
| | 224 | iptables_do_command("-t nat -X wifidog_known"); |
| | 225 | iptables_do_command("-t nat -X wifidog_locked"); |
| | 226 | |
| | 227 | /* We loop in case wifidog has crashed and left some unwanted rules, |
| | 228 | * maybe we shouldn't loop forever, we'll give it 10 tries |
| | 229 | */ |
| | 230 | rc = 0; |
| | 231 | for (tries = 0; tries < 10 && rc == 0; tries++) { |
| | 232 | rc = iptables_do_command("-t nat -D PREROUTING -i %s -j wifidog_class", config.gw_interface); |
| | 233 | } |
| | 234 | iptables_do_command("-t nat -X wifidog_class"); |
| | 235 | |
| | 236 | rc = 0; |
| | 237 | for (tries = 0; tries < 10 && rc == 0; tries++) { |
| | 238 | rc = iptables_do_command("-t mangle -D PREROUTING -i %s -j wifidog_mark", config.gw_interface); |
| | 239 | } |
| | 240 | iptables_do_command("-t mangle -X wifidog_mark"); |
| | 241 | |
| | 242 | return 1; |