-
Notifications
You must be signed in to change notification settings - Fork 101
/
peervpn.c
115 lines (103 loc) · 3.33 KB
/
peervpn.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/***************************************************************************
* Copyright (C) 2016 by Tobias Volk *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include <signal.h>
#include <stdio.h>
#include <openssl/engine.h>
#include "ethernet/switch.c"
#include "ethernet/ndp6.c"
#include "ethernet/virtserv.c"
#include "libp2psec/p2psec.c"
#include "platform/io.c"
#include "platform/ifconfig.c"
#include "platform/seccomp.c"
#include "globals.ic"
#include "console.ic"
#include "mainloop.ic"
#include "config.ic"
#include "pwd.ic"
#include "init.ic"
// commandline parser
int main(int argc, char **argv) {
int confok;
int conffd;
int arglen;
int i;
struct s_initconfig config;
// default configuration
strcpy(config.tapname,"");
strcpy(config.ifconfig4,"");
strcpy(config.ifconfig6,"");
strcpy(config.upcmd,"");
strcpy(config.sourceip,"");
strcpy(config.sourceport,"");
strcpy(config.userstr,"");
strcpy(config.groupstr,"");
strcpy(config.chrootstr,"");
strcpy(config.networkname,"PEERVPN");
strcpy(config.initpeers,"");
strcpy(config.engines,"");
config.password_len = 0;
config.enableeth = 1;
config.enablendpcache = 0;
config.enablevirtserv = 0;
config.enablerelay = 0;
config.enableindirect = 0;
config.enableconsole = 0;
config.enableseccomp = 0;
config.forceseccomp = 0;
config.enableprivdrop = 1;
config.enableipv4 = 1;
config.enableipv6 = 1;
config.enablenat64clat = 0;
config.sockmark = 0;
setbuf(stdout,NULL);
printf("PeerVPN v%d.%03d\n", PEERVPN_VERSION_MAJOR, PEERVPN_VERSION_MINOR);
printf("(c)2016 Tobias Volk <[email protected]>\n");
printf("\n");
confok = 0;
if(argc == 2) {
arglen = 0;
for(i=0; i<3; i++) {
if(argv[1][i] == '\0') break;
arglen++;
}
if(arglen > 0) {
if(argv[1][0] == '-') {
if(!((arglen > 1) && (argv[1][1] >= '!') && (argv[1][1] <= '~'))) {
conffd = STDIN_FILENO;
parseConfigFile(conffd,&config);
confok = 1;
}
}
else {
if((conffd = (open(argv[1],O_RDONLY))) < 0) throwError("could not open config file!");
parseConfigFile(conffd,&config);
close(conffd);
confok = 1;
}
}
}
if(confok > 0) {
// start vpn node
init(&config);
}
else {
printf("usage: %s <configfile>\n", argv[0]);
}
return 0;
}