]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
openvpnctrl: Update firewall rules when starting a n2n connection.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 25 Jun 2011 08:59:47 +0000 (10:59 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 25 Jun 2011 08:59:47 +0000 (10:59 +0200)
This makes sure, that all rules (esp. for new connections) are up
and running.

src/misc-progs/openvpnctrl.c

index e6a8d3f1a5ec13d3927b14828387ac8b576c68ed..5167d0541b5c8faf77da3d74b164f4f90744e464 100644 (file)
@@ -24,7 +24,7 @@ char enableorange[STRING_SIZE] = "off";
 char OVPNRED[STRING_SIZE] = "OVPN";
 char OVPNBLUE[STRING_SIZE] = "OVPN_BLUE_";
 char OVPNORANGE[STRING_SIZE] = "OVPN_ORANGE_";
 char OVPNRED[STRING_SIZE] = "OVPN";
 char OVPNBLUE[STRING_SIZE] = "OVPN_BLUE_";
 char OVPNORANGE[STRING_SIZE] = "OVPN_ORANGE_";
-char WRAPPERVERSION[STRING_SIZE] = "ipfire-2.1.0";
+char WRAPPERVERSION[STRING_SIZE] = "ipfire-2.1.1";
 
 struct connection_struct {
        char name[STRING_SIZE];
 
 struct connection_struct {
        char name[STRING_SIZE];
@@ -46,9 +46,9 @@ void exithandler(void)
 void usage(void)
 {
 #ifdef ovpndebug
 void usage(void)
 {
 #ifdef ovpndebug
-       printf("Wrapper for OpenVPN v%s-debug\n", WRAPPERVERSION);
+       printf("Wrapper for OpenVPN %s-debug\n", WRAPPERVERSION);
 #else
 #else
-       printf("Wrapper for OpenVPN v%s\n", WRAPPERVERSION);
+       printf("Wrapper for OpenVPN %s\n", WRAPPERVERSION);
 #endif
        printf("openvpnctrl <option>\n");
        printf(" Valid options are:\n");
 #endif
        printf("openvpnctrl <option>\n");
        printf(" Valid options are:\n");
@@ -198,7 +198,7 @@ void executeCommand(char *command) {
 void setChainRules(char *chain, char *interface, char *protocol, char *port)
 {
        char str[STRING_SIZE];
 void setChainRules(char *chain, char *interface, char *protocol, char *port)
 {
        char str[STRING_SIZE];
-       
+
        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);
        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);
@@ -342,6 +342,11 @@ void setFirewallRules(void) {
        // read connection configuration
        connection *conn = getConnections();
 
        // read connection configuration
        connection *conn = getConnections();
 
+       // Flush all chains.
+       flushChain(OVPNRED);
+       flushChain(OVPNBLUE);
+       flushChain(OVPNORANGE);
+
        // set firewall rules
        if (!strcmp(enablered, "on") && strlen(redif))
                setChainRules(OVPNRED, redif, protocol, dport);
        // set firewall rules
        if (!strcmp(enablered, "on") && strlen(redif))
                setChainRules(OVPNRED, redif, protocol, dport);
@@ -351,10 +356,10 @@ void setFirewallRules(void) {
                setChainRules(OVPNORANGE, orangeif, protocol, dport);
 
        // set firewall rules for n2n connections
                setChainRules(OVPNORANGE, orangeif, protocol, dport);
 
        // set firewall rules for n2n connections
-       char port[STRING_SIZE];
+       char *port;
        while (conn) {
                sprintf(port, "%d", conn->port);
        while (conn) {
                sprintf(port, "%d", conn->port);
-               setChainRules(OVPNRED, redif, &conn->proto, &port);
+               setChainRules(OVPNRED, redif, conn->proto, port);
                conn = conn->next;
        }
 }
                conn = conn->next;
        }
 }
@@ -403,6 +408,9 @@ void startNet2Net(char *name) {
                exit(1);
        }
 
                exit(1);
        }
 
+       // Make sure all firewall rules are up to date.
+       setFirewallRules();
+
        char command[STRING_SIZE];
        sprintf(command, "/usr/sbin/openvpn --config " CONFIG_ROOT "/ovpn/n2nconf/%s/%s.conf", conn->name, conn->name);
        executeCommand(command);
        char command[STRING_SIZE];
        sprintf(command, "/usr/sbin/openvpn --config " CONFIG_ROOT "/ovpn/n2nconf/%s/%s.conf", conn->name, conn->name);
        executeCommand(command);