]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/misc-progs/openvpnctrl.c
Merge branch 'next' into temp-c171-development
[people/pmueller/ipfire-2.x.git] / src / misc-progs / openvpnctrl.c
1 #define _XOPEN_SOURCE 500
2 #include <signal.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <arpa/inet.h>
9 #include <netinet/in.h>
10 #include <fcntl.h>
11 #include <ftw.h>
12 #include "setuid.h"
13 #include "netutil.h"
14 #include "libsmooth.h"
15
16 #define noovpndebug
17
18 // global vars
19 struct keyvalue *kv = NULL;
20 FILE *ifacefile = NULL;
21
22 char redif[STRING_SIZE];
23 char blueif[STRING_SIZE];
24 char orangeif[STRING_SIZE];
25 char enablered[STRING_SIZE] = "off";
26 char enableblue[STRING_SIZE] = "off";
27 char enableorange[STRING_SIZE] = "off";
28
29 // consts
30 char OVPNINPUT[STRING_SIZE] = "OVPNINPUT";
31 char OVPNBLOCK[STRING_SIZE] = "OVPNBLOCK";
32 char OVPNNAT[STRING_SIZE] = "OVPNNAT";
33 char WRAPPERVERSION[STRING_SIZE] = "ipfire-2.2.4";
34
35 struct connection_struct {
36 char name[STRING_SIZE];
37 char type[STRING_SIZE];
38 char proto[STRING_SIZE];
39 char status[STRING_SIZE];
40 char local_subnet[STRING_SIZE];
41 char transfer_subnet[STRING_SIZE];
42 char role[STRING_SIZE];
43 char port[STRING_SIZE];
44 struct connection_struct *next;
45 };
46
47 typedef struct connection_struct connection;
48
49 static int recursive_remove_callback(const char* fpath, const struct stat* sb, int typeflag, struct FTW* ftwbuf) {
50 int rv = remove(fpath);
51 if (rv)
52 perror(fpath);
53
54 return rv;
55 }
56
57 static int recursive_remove(const char* path) {
58 return nftw(path, recursive_remove_callback, 64, FTW_DEPTH | FTW_PHYS);
59 }
60
61 void exithandler(void)
62 {
63 if(kv)
64 freekeyvalues(kv);
65 if (ifacefile)
66 fclose(ifacefile);
67 }
68
69 void usage(void)
70 {
71 #ifdef ovpndebug
72 printf("Wrapper for OpenVPN %s-debug\n", WRAPPERVERSION);
73 #else
74 printf("Wrapper for OpenVPN %s\n", WRAPPERVERSION);
75 #endif
76 printf("openvpnctrl <option>\n");
77 printf(" Valid options are:\n");
78 printf(" -s --start\n");
79 printf(" starts OpenVPN (implicitly creates chains and firewall rules)\n");
80 printf(" -k --kill\n");
81 printf(" kills/stops OpenVPN\n");
82 printf(" -r --restart\n");
83 printf(" restarts OpenVPN (implicitly creates chains and firewall rules)\n");
84 printf(" -sn2n --start-net-2-net\n");
85 printf(" starts all net2net connections\n");
86 printf(" you may pass a connection name to the switch to only start a specific one\n");
87 printf(" -kn2n --kill-net-2-net\n");
88 printf(" kills all net2net connections\n");
89 printf(" you may pass a connection name to the switch to only start a specific one\n");
90 printf(" -drrd --delete-rrd\n");
91 printf(" Deletes the RRD data for a specific client\n");
92 printf(" you need to pass a connection name (RW) to the switch to delete the directory (case sensitive)\n");
93 printf(" -d --display\n");
94 printf(" displays OpenVPN status to syslog\n");
95 printf(" -fwr --firewall-rules\n");
96 printf(" removes current OpenVPN chains and rules and resets them according to the config\n");
97 printf(" -sdo --start-daemon-only\n");
98 printf(" starts OpenVPN daemon only\n");
99 exit(1);
100 }
101
102 connection *getConnections() {
103 FILE *fp = NULL;
104
105 if (!(fp = fopen(CONFIG_ROOT "/ovpn/ovpnconfig", "r"))) {
106 fprintf(stderr, "Could not open openvpn n2n configuration file.\n");
107 exit(1);
108 }
109
110 char line[STRING_SIZE] = "";
111 char result[STRING_SIZE] = "";
112 char *resultptr;
113 int count;
114 connection *conn_first = NULL;
115 connection *conn_last = NULL;
116 connection *conn_curr;
117
118 while ((fgets(line, STRING_SIZE, fp) != NULL)) {
119 if (line[strlen(line) - 1] == '\n')
120 line[strlen(line) - 1] = '\0';
121
122 conn_curr = (connection *)malloc(sizeof(connection));
123 memset(conn_curr, 0, sizeof(connection));
124
125 if (conn_first == NULL) {
126 conn_first = conn_curr;
127 } else {
128 conn_last->next = conn_curr;
129 }
130 conn_last = conn_curr;
131
132 count = 0;
133 char *lineptr = &line;
134 while (1) {
135 if (*lineptr == NULL)
136 break;
137
138 resultptr = result;
139 while (*lineptr != NULL) {
140 if (*lineptr == ',') {
141 lineptr++;
142 break;
143 }
144 *resultptr++ = *lineptr++;
145 }
146 *resultptr = '\0';
147
148 if (count == 1) {
149 strcpy(conn_curr->status, result);
150 } else if (count == 2) {
151 strcpy(conn_curr->name, result);
152 } else if (count == 4) {
153 strcpy(conn_curr->type, result);
154 } else if (count == 7) {
155 strcpy(conn_curr->role, result);
156 } else if (count == 9) {
157 strcpy(conn_curr->local_subnet, result);
158 } else if (count == 28) {
159 strcpy(conn_curr->transfer_subnet, result);
160 } else if (count == 29) {
161 strcpy(conn_curr->proto, result);
162 } else if (count == 30) {
163 strcpy(conn_curr->port, result);
164 }
165
166 count++;
167 }
168 }
169
170 fclose(fp);
171
172 return conn_first;
173 }
174
175 int readPidFile(const char *pidfile) {
176 FILE *fp = fopen(pidfile, "r");
177 if (fp == NULL) {
178 exit(1);
179 }
180
181 int pid = 0;
182 fscanf(fp, "%d", &pid);
183 fclose(fp);
184
185 return pid;
186 }
187
188 int readExternalAddress(char* address) {
189 FILE *fp = fopen("/var/ipfire/red/local-ipaddress", "r");
190 if (!fp)
191 goto ERROR;
192
193 int r = fscanf(fp, "%s", address);
194 fclose(fp);
195
196 if (r < 0)
197 goto ERROR;
198
199 /* In case the read IP address is not valid, we empty
200 * the content of address and return non-zero. */
201 if (!VALID_IP(address))
202 goto ERROR;
203
204 return 0;
205
206 ERROR:
207 address = NULL;
208 return 1;
209 }
210
211 void ovpnInit(void) {
212 // Read OpenVPN configuration
213 kv = initkeyvalues();
214 if (!readkeyvalues(kv, CONFIG_ROOT "/ovpn/settings")) {
215 fprintf(stderr, "Cannot read ovpn settings\n");
216 exit(1);
217 }
218
219 if (!findkey(kv, "ENABLED", enablered)) {
220 exit(1);
221 }
222
223 if (!findkey(kv, "ENABLED_BLUE", enableblue)){
224 exit(1);
225 }
226
227 if (!findkey(kv, "ENABLED_ORANGE", enableorange)){
228 exit(1);
229 }
230 freekeyvalues(kv);
231
232 // read interface settings
233
234 // details for the red int
235 memset(redif, 0, STRING_SIZE);
236 if ((ifacefile = fopen(CONFIG_ROOT "/red/iface", "r")))
237 {
238 if (fgets(redif, STRING_SIZE, ifacefile))
239 {
240 if (redif[strlen(redif) - 1] == '\n')
241 redif[strlen(redif) - 1] = '\0';
242 }
243 fclose (ifacefile);
244 ifacefile = NULL;
245
246 if (!VALID_DEVICE(redif))
247 {
248 memset(redif, 0, STRING_SIZE);
249 }
250 }
251
252 kv=initkeyvalues();
253 if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")) {
254 fprintf(stderr, "Cannot read ethernet settings\n");
255 exit(1);
256 }
257
258 if (strcmp(enableblue, "on") == 0) {
259 if (!findkey(kv, "BLUE_DEV", blueif)) {
260 exit(1);
261 }
262 }
263
264 if (strcmp(enableorange, "on") == 0) {
265 if (!findkey(kv, "ORANGE_DEV", orangeif)) {
266 exit(1);
267 }
268 }
269 freekeyvalues(kv);
270 }
271
272 void executeCommand(char *command) {
273 #ifdef ovpndebug
274 printf(strncat(command, "\n", 2));
275 #endif
276 safe_system(strncat(command, " >/dev/null 2>&1", 17));
277 }
278
279 void addRule(const char *chain, const char *interface, const char *protocol, const char *port) {
280 char command[STRING_SIZE];
281
282 snprintf(command, STRING_SIZE - 1, "/sbin/iptables -A %s -i %s -p %s --dport %s -j ACCEPT",
283 chain, interface, protocol, port);
284 executeCommand(command);
285 }
286
287 void flushChain(char *chain) {
288 char str[STRING_SIZE];
289
290 snprintf(str, STRING_SIZE - 1, "/sbin/iptables -F %s", chain);
291 executeCommand(str);
292 }
293
294 void flushChainNAT(char *chain) {
295 char str[STRING_SIZE];
296
297 snprintf(str, STRING_SIZE - 1, "/sbin/iptables -t nat -F %s", chain);
298 executeCommand(str);
299 }
300
301 char* calcTransferNetAddress(const connection* conn) {
302 char *subnetmask = strdup(conn->transfer_subnet);
303 char *address = strsep(&subnetmask, "/");
304
305 if ((address == NULL) || (subnetmask == NULL)) {
306 goto ERROR;
307 }
308
309 in_addr_t _address = inet_addr(address);
310 in_addr_t _subnetmask = inet_addr(subnetmask);
311 _address &= _subnetmask;
312
313 if (strcmp(conn->role, "server") == 0) {
314 _address += 1 << 24;
315 } else if (strcmp(conn->role, "client") == 0) {
316 _address += 2 << 24;
317 } else {
318 goto ERROR;
319 }
320
321 struct in_addr address_info;
322 address_info.s_addr = _address;
323
324 return inet_ntoa(address_info);
325
326 ERROR:
327 fprintf(stderr, "Could not determine transfer net address: %s\n", conn->name);
328
329 free(address);
330 return NULL;
331 }
332
333 char* getLocalSubnetAddress(const connection* conn) {
334 kv = initkeyvalues();
335 if (!readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")) {
336 fprintf(stderr, "Cannot read ethernet settings\n");
337 exit(1);
338 }
339
340 const char *zones[] = {"GREEN", "BLUE", "ORANGE", NULL};
341 char *zone = NULL;
342
343 // Get net address of the local openvpn subnet.
344 char *subnetmask = strdup(conn->local_subnet);
345 char *address = strsep(&subnetmask, "/");
346
347 if ((address == NULL) || (subnetmask == NULL)) {
348 goto ERROR;
349 }
350
351 in_addr_t _address = inet_addr(address);
352 in_addr_t _subnetmask = inet_addr(subnetmask);
353
354 in_addr_t _netaddr = (_address & _subnetmask);
355 in_addr_t _broadcast = (_address | ~_subnetmask);
356
357 char zone_address_key[STRING_SIZE];
358 char zone_address[STRING_SIZE];
359 in_addr_t zone_addr;
360
361 int i = 0;
362 while (zones[i]) {
363 zone = zones[i++];
364 snprintf(zone_address_key, STRING_SIZE, "%s_ADDRESS", zone);
365
366 if (!findkey(kv, zone_address_key, zone_address))
367 continue;
368
369 zone_addr = inet_addr(zone_address);
370 if ((zone_addr > _netaddr) && (zone_addr < _broadcast)) {
371 freekeyvalues(kv);
372
373 return strdup(zone_address);
374 }
375 }
376
377 ERROR:
378 fprintf(stderr, "Could not determine local subnet address: %s\n", conn->name);
379
380 freekeyvalues(kv);
381 return NULL;
382 }
383
384 void setFirewallRules(void) {
385 char command[STRING_SIZE];
386 char protocol[STRING_SIZE] = "";
387 char dport[STRING_SIZE] = "";
388 char dovpnip[STRING_SIZE] = "";
389
390 kv = initkeyvalues();
391 if (!readkeyvalues(kv, CONFIG_ROOT "/ovpn/settings"))
392 {
393 fprintf(stderr, "Cannot read ovpn settings\n");
394 exit(1);
395 }
396
397 /* we got one device, so lets proceed further */
398 if (!findkey(kv, "DDEST_PORT", dport)){
399 fprintf(stderr, "Cannot read DDEST_PORT\n");
400 exit(1);
401 }
402
403 if (!findkey(kv, "DPROTOCOL", protocol)){
404 fprintf(stderr, "Cannot read DPROTOCOL\n");
405 exit(1);
406 }
407
408 if (!findkey(kv, "VPN_IP", dovpnip)){
409 fprintf(stderr, "Cannot read VPN_IP\n");
410 }
411 freekeyvalues(kv);
412
413 // Flush all chains.
414 flushChain(OVPNINPUT);
415 flushChain(OVPNBLOCK);
416 flushChainNAT(OVPNNAT);
417
418 // set firewall rules
419 if (!strcmp(enablered, "on") && strlen(redif))
420 addRule(OVPNINPUT, redif, protocol, dport);
421 if (!strcmp(enableblue, "on") && strlen(blueif))
422 addRule(OVPNINPUT, blueif, protocol, dport);
423 if (!strcmp(enableorange, "on") && strlen(orangeif))
424 addRule(OVPNINPUT, orangeif, protocol, dport);
425
426 /* Allow ICMP error messages to pass. */
427 snprintf(command, STRING_SIZE - 1, "/sbin/iptables -A %s -p icmp"
428 " -m conntrack --ctstate RELATED -j RETURN", OVPNBLOCK);
429 executeCommand(command);
430
431 // read connection configuration
432 connection *conn = getConnections();
433
434 // set firewall rules for n2n connections
435 char *local_subnet_address = NULL;
436 char *transfer_subnet_address = NULL;
437 while (conn != NULL) {
438 if (strcmp(conn->type, "net") == 0) {
439 addRule(OVPNINPUT, redif, conn->proto, conn->port);
440
441 /* Block all communication from the transfer nets. */
442 snprintf(command, STRING_SIZE - 1, "/sbin/iptables -A %s -s %s -j DROP",
443 OVPNBLOCK, conn->transfer_subnet);
444 executeCommand(command);
445
446 local_subnet_address = getLocalSubnetAddress(conn);
447 transfer_subnet_address = calcTransferNetAddress(conn);
448
449 if ((local_subnet_address) && (transfer_subnet_address)) {
450 snprintf(command, STRING_SIZE - 1, "/sbin/iptables -t nat -A %s -s %s -j SNAT --to-source %s",
451 OVPNNAT, transfer_subnet_address, local_subnet_address);
452 executeCommand(command);
453 }
454 }
455
456 conn = conn->next;
457 }
458 }
459
460 static void stopAuthenticator() {
461 const char* argv[] = {
462 "/usr/sbin/openvpn-authenticator",
463 NULL,
464 };
465
466 run("/sbin/killall", argv);
467 }
468
469 void stopDaemon(void) {
470 char command[STRING_SIZE];
471
472 int pid = readPidFile("/var/run/openvpn.pid");
473 if (!pid > 0) {
474 exit(1);
475 }
476
477 fprintf(stderr, "Killing PID %d.\n", pid);
478 kill(pid, SIGTERM);
479
480 snprintf(command, STRING_SIZE - 1, "/bin/rm -f /var/run/openvpn.pid");
481 executeCommand(command);
482
483 // Stop OpenVPN authenticator
484 stopAuthenticator();
485 }
486
487 static int startAuthenticator(void) {
488 const char* argv[] = { "-d", NULL };
489
490 return run("/usr/sbin/openvpn-authenticator", argv);
491 }
492
493 void startDaemon(void) {
494 char command[STRING_SIZE];
495
496 if (!((strcmp(enablered, "on") == 0) || (strcmp(enableblue, "on") == 0) || (strcmp(enableorange, "on") == 0))) {
497 fprintf(stderr, "OpenVPN is not enabled on any interface\n");
498 exit(1);
499 } else {
500 snprintf(command, STRING_SIZE-1, "/sbin/modprobe tun");
501 executeCommand(command);
502 snprintf(command, STRING_SIZE-1, "/usr/sbin/openvpn --config /var/ipfire/ovpn/server.conf");
503 executeCommand(command);
504 snprintf(command, STRING_SIZE-1, "/bin/chown root.nobody /var/run/ovpnserver.log");
505 executeCommand(command);
506 snprintf(command, STRING_SIZE-1, "/bin/chmod 644 /var/run/ovpnserver.log");
507 executeCommand(command);
508
509 // Start OpenVPN Authenticator
510 startAuthenticator();
511 }
512 }
513
514 int startNet2Net(char *name) {
515 connection *conn = NULL;
516 connection *conn_iter;
517
518 conn_iter = getConnections();
519
520 while (conn_iter) {
521 if ((strcmp(conn_iter->type, "net") == 0) && (strcmp(conn_iter->name, name) == 0)) {
522 conn = conn_iter;
523 break;
524 }
525 conn_iter = conn_iter->next;
526 }
527
528 if (conn == NULL) {
529 fprintf(stderr, "Connection not found.\n");
530 return 1;
531 }
532
533 if (strcmp(conn->status, "on") != 0) {
534 fprintf(stderr, "Connection '%s' is not enabled.\n", conn->name);
535 return 1;
536 }
537
538 fprintf(stderr, "Starting connection %s...\n", conn->name);
539
540 char configfile[STRING_SIZE];
541 snprintf(configfile, STRING_SIZE - 1, CONFIG_ROOT "/ovpn/n2nconf/%s/%s.conf",
542 conn->name, conn->name);
543
544 FILE *fp = fopen(configfile, "r");
545 if (fp == NULL) {
546 fprintf(stderr, "Could not find configuration file for connection '%s' at '%s'.\n",
547 conn->name, configfile);
548 return 2;
549 }
550 fclose(fp);
551
552 // Make sure all firewall rules are up to date.
553 setFirewallRules();
554
555 // Get the external IP address.
556 char address[STRING_SIZE] = "";
557 int r = readExternalAddress(address);
558 if (r) {
559 fprintf(stderr, "Could not read the external address\n");
560 exit(1);
561 }
562
563 char command[STRING_SIZE];
564 snprintf(command, STRING_SIZE-1, "/sbin/modprobe tun");
565 executeCommand(command);
566 snprintf(command, STRING_SIZE-1, "/usr/sbin/openvpn --local %s --config %s", address, configfile);
567 executeCommand(command);
568
569 return 0;
570 }
571
572 int killNet2Net(char *name) {
573 connection *conn = NULL;
574 connection *conn_iter;
575 int rc = 0;
576
577 conn_iter = getConnections();
578
579 while (conn_iter) {
580 if (strcmp(conn_iter->name, name) == 0) {
581 conn = conn_iter;
582 break;
583 }
584 conn_iter = conn_iter->next;
585 }
586
587 if (conn == NULL) {
588 fprintf(stderr, "Connection not found.\n");
589 return 1;
590 }
591
592 char pidfile[STRING_SIZE];
593 snprintf(pidfile, STRING_SIZE - 1, "/var/run/%sn2n.pid", conn->name);
594
595 int pid = readPidFile(pidfile);
596 if (!pid > 0) {
597 fprintf(stderr, "Could not read pid file of connection %s.", conn->name);
598 return 1;
599 }
600
601 fprintf(stderr, "Killing connection %s (PID %d)...\n", conn->name, pid);
602 kill(pid, SIGTERM);
603
604 char command[STRING_SIZE];
605 snprintf(command, STRING_SIZE - 1, "/bin/rm -f %s", pidfile);
606 executeCommand(command);
607
608 char runfile[STRING_SIZE];
609 snprintf(runfile, STRING_SIZE - 1, "/var/run/openvpn/%s-n2n", conn->name);
610 rc = recursive_remove(runfile);
611 if (rc)
612 perror(runfile);
613
614 return 0;
615 }
616
617 int deleterrd(char *name) {
618 char rrd_dir[STRING_SIZE];
619
620 connection *conn = getConnections();
621 while(conn) {
622 if (strcmp(conn->name, name) != 0) {
623 conn = conn->next;
624 continue;
625 }
626
627 // Handle RW connections
628 if (strcmp(conn->type, "host") == 0) {
629 snprintf(rrd_dir, STRING_SIZE - 1, "/var/log/rrd/collectd/localhost/openvpn-%s/", name);
630
631 // Handle N2N connections
632 } else if (strcmp(conn->type, "net") == 0) {
633 snprintf(rrd_dir, STRING_SIZE - 1, "/var/log/rrd/collectd/localhost/openvpn-%s-n2n/", name);
634
635 // Unhandled connection type
636 } else {
637 conn = conn->next;
638 continue;
639 }
640
641 return recursive_remove(rrd_dir);
642 }
643
644 return 1;
645 }
646
647 void startAllNet2Net() {
648 int exitcode = 0, _exitcode = 0;
649
650 connection *conn = getConnections();
651
652 while(conn) {
653 /* Skip all connections that are not of type "net" or disabled. */
654 if ((strcmp(conn->type, "net") != 0) || (strcmp(conn->status, "on") != 0)) {
655 conn = conn->next;
656 continue;
657 }
658
659 _exitcode = startNet2Net(conn->name);
660 conn = conn->next;
661
662 if (_exitcode > exitcode) {
663 exitcode = _exitcode;
664 }
665 }
666
667 exit(exitcode);
668 }
669
670 void killAllNet2Net() {
671 int exitcode = 0, _exitcode = 0;
672
673 connection *conn = getConnections();
674
675 while(conn) {
676 /* Skip all connections that are not of type "net". */
677 if (strcmp(conn->type, "net") != 0) {
678 conn = conn->next;
679 continue;
680 }
681
682 _exitcode = killNet2Net(conn->name);
683 conn = conn->next;
684
685 if (_exitcode > exitcode) {
686 exitcode = _exitcode;
687 }
688 }
689
690 exit(exitcode);
691 }
692
693 void displayopenvpn(void) {
694 char command[STRING_SIZE];
695
696 snprintf(command, STRING_SIZE - 1, "/bin/killall -sSIGUSR2 openvpn");
697 executeCommand(command);
698 }
699
700 int main(int argc, char *argv[]) {
701 if (!(initsetuid()))
702 exit(1);
703 if(argc < 2)
704 usage();
705
706 if(argc == 3) {
707 ovpnInit();
708
709 if( (strcmp(argv[1], "-sn2n") == 0) || (strcmp(argv[1], "--start-net-2-net") == 0) ) {
710 startNet2Net(argv[2]);
711 return 0;
712 }
713 else if( (strcmp(argv[1], "-kn2n") == 0) || (strcmp(argv[1], "--kill-net-2-net") == 0) ) {
714 killNet2Net(argv[2]);
715 return 0;
716 }
717 else if( (strcmp(argv[1], "-drrd") == 0) || (strcmp(argv[1], "--delete-rrd") == 0) ) {
718 deleterrd(argv[2]);
719 return 0;
720 } else {
721 usage();
722 return 1;
723 }
724 }
725 else if(argc == 2) {
726 if( (strcmp(argv[1], "-k") == 0) || (strcmp(argv[1], "--kill") == 0) ) {
727 stopDaemon();
728 return 0;
729 }
730 else if( (strcmp(argv[1], "-d") == 0) || (strcmp(argv[1], "--display") == 0) ) {
731 displayopenvpn();
732 return 0;
733 }
734 else {
735 ovpnInit();
736
737 if( (strcmp(argv[1], "-s") == 0) || (strcmp(argv[1], "--start") == 0) ) {
738 setFirewallRules();
739 startDaemon();
740 return 0;
741 }
742 else if( (strcmp(argv[1], "-sn2n") == 0) || (strcmp(argv[1], "--start-net-2-net") == 0) ) {
743 startAllNet2Net();
744 return 0;
745 }
746 else if( (strcmp(argv[1], "-kn2n") == 0) || (strcmp(argv[1], "--kill-net-2-net") == 0) ) {
747 killAllNet2Net();
748 return 0;
749 }
750 else if( (strcmp(argv[1], "-sdo") == 0) || (strcmp(argv[1], "--start-daemon-only") == 0) ) {
751 startDaemon();
752 return 0;
753 }
754 else if( (strcmp(argv[1], "-r") == 0) || (strcmp(argv[1], "--restart") == 0) ) {
755 stopDaemon();
756 setFirewallRules();
757 startDaemon();
758 return 0;
759 }
760 else if( (strcmp(argv[1], "-fwr") == 0) || (strcmp(argv[1], "--firewall-rules") == 0) ) {
761 setFirewallRules();
762 return 0;
763 }
764 else {
765 usage();
766 return 0;
767 }
768 }
769 }
770 else {
771 usage();
772 return 0;
773 }
774 return 0;
775 }
776