char OVPNRED[STRING_SIZE] = "OVPN";
char OVPNBLUE[STRING_SIZE] = "OVPN_BLUE_";
char OVPNORANGE[STRING_SIZE] = "OVPN_ORANGE_";
+char OVPNBLOCK[STRING_SIZE] = "OVPNBLOCK";
char OVPNNAT[STRING_SIZE] = "OVPNNAT";
char WRAPPERVERSION[STRING_SIZE] = "ipfire-2.2.3";
sprintf(str, "/sbin/iptables -A %sINPUT -i %s -p %s --dport %s -j ACCEPT", chain, interface, protocol, port);
executeCommand(str);
- sprintf(str, "/sbin/iptables -A %sINPUT -i tun+ -j ACCEPT", chain);
- executeCommand(str);
- sprintf(str, "/sbin/iptables -A %sFORWARD -i tun+ -j ACCEPT", chain);
- executeCommand(str);
}
void flushChain(char *chain) {
sprintf(str, "/sbin/iptables -F %sINPUT", chain);
executeCommand(str);
- sprintf(str, "/sbin/iptables -F %sFORWARD", chain);
- executeCommand(str);
- safe_system(str);
}
void flushChainNAT(char *chain) {
sprintf(str, "/sbin/iptables -D INPUT -j %sINPUT", chain);
executeCommand(str);
- safe_system(str);
- sprintf(str, "/sbin/iptables -D FORWARD -j %sFORWARD", chain);
- executeCommand(str);
- safe_system(str);
}
void deleteChain(char *chain) {
sprintf(str, "/sbin/iptables -X %sINPUT", chain);
executeCommand(str);
- sprintf(str, "/sbin/iptables -X %sFORWARD", chain);
- executeCommand(str);
}
void deleteAllChains(void) {
deleteChain(OVPNRED);
deleteChain(OVPNBLUE);
deleteChain(OVPNORANGE);
+
+ // Only flush chains that are created by the firewall
+ flushChain(OVPNBLOCK);
+ flushChainNAT(OVPNNAT);
}
void createChainReference(char *chain) {
char str[STRING_SIZE];
sprintf(str, "/sbin/iptables -I INPUT %s -j %sINPUT", "14", chain);
executeCommand(str);
- sprintf(str, "/sbin/iptables -I FORWARD %s -j %sFORWARD", "12", chain);
- executeCommand(str);
}
void createChain(char *chain) {
char str[STRING_SIZE];
sprintf(str, "/sbin/iptables -N %sINPUT", chain);
executeCommand(str);
- sprintf(str, "/sbin/iptables -N %sFORWARD", chain);
- executeCommand(str);
}
void createAllChains(void) {
char *subnetmask = strdup(conn->transfer_subnet);
char *address = strsep(&subnetmask, "/");
+ if ((address == NULL) || (subnetmask == NULL)) {
+ goto ERROR;
+ }
+
in_addr_t _address = inet_addr(address);
in_addr_t _subnetmask = inet_addr(subnetmask);
_address &= _subnetmask;
flushChain(OVPNRED);
flushChain(OVPNBLUE);
flushChain(OVPNORANGE);
+ flushChain(OVPNBLOCK);
flushChainNAT(OVPNNAT);
// set firewall rules
OVPNRED, redif, conn->proto, conn->port);
executeCommand(command);
+ /* Block all communication from the transfer nets. */
+ snprintf(command, STRING_SIZE, "/sbin/iptables -A %s -s %s -j DROP",
+ OVPNBLOCK, conn->transfer_subnet);
+ executeCommand(command);
+
local_subnet_address = getLocalSubnetAddress(conn);
transfer_subnet_address = calcTransferNetAddress(conn);
- if ((!local_subnet_address) || (!transfer_subnet_address))
- continue;
-
- snprintf(command, STRING_SIZE, "/sbin/iptables -t nat -A %s -s %s -j SNAT --to-source %s",
- OVPNNAT, transfer_subnet_address, local_subnet_address);
- executeCommand(command);
+ if ((local_subnet_address) && (transfer_subnet_address)) {
+ snprintf(command, STRING_SIZE, "/sbin/iptables -t nat -A %s -s %s -j SNAT --to-source %s",
+ OVPNNAT, transfer_subnet_address, local_subnet_address);
+ executeCommand(command);
+ }
}
conn = conn->next;