Browse Source

Packaging and parameter parsing fixes

pull/35/head
Luca Deri 6 years ago
parent
commit
d299d558ac
  1. 93
      edge.c
  2. 0
      packages/debian/Makefile.in
  3. 3
      packages/debian/configure
  4. 1
      packages/debian/configure.in
  5. 12
      packages/etc/n2n/edge.conf
  6. 2
      packages/etc/n2n/supernode.conf
  7. 813
      sn.c

93
edge.c

@ -110,6 +110,9 @@ static int scan_address(char * ip_addr, size_t addr_size,
static void help() {
print_n2n_version();
printf("edge <config file> (see edge.conf)\n"
"or\n"
);
printf("edge "
#if defined(N2N_CAN_NAME_IFACE)
"-d <tun device> "
@ -173,7 +176,7 @@ static int setOption(int optkey, char *optarg, edge_conf_t *ec, n2n_edge_t *eee)
//traceEvent(TRACE_NORMAL, "Option %c = %s", optkey, optarg ? optarg : "");
switch(optkey) {
case'K':
case'K':
{
if(ec->encrypt_key) {
fprintf(stderr, "Error: -K and -k options are mutually exclusive.\n");
@ -189,7 +192,7 @@ static int setOption(int optkey, char *optarg, edge_conf_t *ec, n2n_edge_t *eee)
break;
}
case 'a': /* IP address and mode of TUNTAP interface */
case 'a': /* IP address and mode of TUNTAP interface */
{
scan_address(ec->ip_addr, N2N_NETMASK_STR_SIZE,
ec->ip_mode, N2N_IF_MODE_SIZE,
@ -197,14 +200,14 @@ static int setOption(int optkey, char *optarg, edge_conf_t *ec, n2n_edge_t *eee)
break;
}
case 'c': /* community as a string */
case 'c': /* community as a string */
{
memset(eee->community_name, 0, N2N_COMMUNITY_SIZE);
strncpy((char *)eee->community_name, optarg, N2N_COMMUNITY_SIZE);
break;
}
case 'E': /* multicast ethernet addresses accepted. */
case 'E': /* multicast ethernet addresses accepted. */
{
eee->drop_multicast=0;
traceEvent(TRACE_DEBUG, "Enabling ethernet multicast traffic\n");
@ -212,13 +215,13 @@ static int setOption(int optkey, char *optarg, edge_conf_t *ec, n2n_edge_t *eee)
}
#ifndef WIN32
case 'u': /* unprivileged uid */
case 'u': /* unprivileged uid */
{
ec->userid = atoi(optarg);
break;
}
case 'g': /* unprivileged uid */
case 'g': /* unprivileged uid */
{
ec->groupid = atoi(optarg);
break;
@ -226,26 +229,26 @@ static int setOption(int optkey, char *optarg, edge_conf_t *ec, n2n_edge_t *eee)
#endif
#ifndef WIN32
case 'f' : /* do not fork as daemon */
case 'f' : /* do not fork as daemon */
{
eee->daemon=0;
break;
}
#endif /* #ifndef WIN32 */
case 'm' : /* TUNTAP MAC address */
case 'm' : /* TUNTAP MAC address */
{
strncpy(ec->device_mac,optarg,N2N_MACNAMSIZ);
break;
}
case 'M' : /* TUNTAP MTU */
case 'M' : /* TUNTAP MTU */
{
ec->mtu = atoi(optarg);
break;
}
case 'k': /* encrypt key */
case 'k': /* encrypt key */
{
if(strlen(eee->keyschedule) > 0) {
fprintf(stderr, "Error: -K and -k options are mutually exclusive.\n");
@ -257,13 +260,13 @@ static int setOption(int optkey, char *optarg, edge_conf_t *ec, n2n_edge_t *eee)
break;
}
case 'r': /* enable packet routing across n2n endpoints */
case 'r': /* enable packet routing across n2n endpoints */
{
eee->allow_routing = 1;
break;
}
case 'l': /* supernode-list */
case 'l': /* supernode-list */
{
if(eee->sn_num < N2N_EDGE_NUM_SUPERNODES) {
strncpy((eee->sn_ip_array[eee->sn_num]), optarg, N2N_EDGE_SN_HOST_SIZE);
@ -277,32 +280,32 @@ static int setOption(int optkey, char *optarg, edge_conf_t *ec, n2n_edge_t *eee)
}
#if defined(N2N_CAN_NAME_IFACE)
case 'd': /* TUNTAP name */
case 'd': /* TUNTAP name */
{
strncpy(ec->tuntap_dev_name, optarg, N2N_IFNAMSIZ);
break;
}
#endif
case 'b':
case 'b':
{
eee->re_resolve_supernode_ip = 1;
break;
}
case 'p':
case 'p':
{
ec->local_port = atoi(optarg);
break;
}
case 't':
case 't':
{
ec->mgmt_port = atoi(optarg);
break;
}
case 's': /* Subnet Mask */
case 's': /* Subnet Mask */
{
if(0 != ec->got_s) {
traceEvent(TRACE_WARNING, "Multiple subnet masks supplied.");
@ -312,19 +315,19 @@ static int setOption(int optkey, char *optarg, edge_conf_t *ec, n2n_edge_t *eee)
break;
}
case 'h': /* help */
case 'h': /* help */
{
help();
break;
}
case 'v': /* verbose */
case 'v': /* verbose */
{
++traceLevel; /* do 2 -v flags to increase verbosity to DEBUG level*/
break;
}
default:
default:
{
traceEvent(TRACE_WARNING, "Unknown option -%c: Ignored.", (char)optkey);
return(-1);
@ -551,10 +554,12 @@ int main(int argc, char* argv[]) {
int keep_on_running = 1;
int rc;
int i;
n2n_edge_t eee; /* single instance for this program */
edge_conf_t ec;
if(argc == 1)
help();
ec.local_port = 0 /* any port */;
ec.mgmt_port = N2N_EDGE_MGMT_PORT; /* 5644 by default */
snprintf(ec.tuntap_dev_name, sizeof(ec.tuntap_dev_name), "edge0");
@ -570,17 +575,15 @@ int main(int argc, char* argv[]) {
ec.groupid = 0; /* root is the only guaranteed ID */
#endif
if(-1 == edge_init(&eee))
{
traceEvent(TRACE_ERROR, "Failed in edge_init");
exit(1);
}
if(getenv("N2N_KEY"))
{
ec.encrypt_key = strdup(getenv("N2N_KEY"));
}
if(-1 == edge_init(&eee)) {
traceEvent(TRACE_ERROR, "Failed in edge_init");
exit(1);
}
if(getenv("N2N_KEY")) {
ec.encrypt_key = strdup(getenv("N2N_KEY"));
}
#ifdef WIN32
ec.tuntap_dev_name[0] = '\0';
#endif
@ -596,19 +599,12 @@ int main(int argc, char* argv[]) {
#endif
rc = loadFromCLI(argc, argv, &ec, &eee);
if(rc < 0)
return(-1);
#ifndef WIN32
if(eee.daemon) {
useSyslog = 1; /* traceEvent output now goes to syslog. */
daemonize();
}
#endif /* #ifndef WIN32 */
if((rc < 0) || (eee.sn_num == 0))
help();
traceEvent(TRACE_NORMAL, "Starting n2n edge %s %s", n2n_sw_version, n2n_sw_buildDate);
for (i=0; i< N2N_EDGE_NUM_SUPERNODES; ++i)
for (i=0; i<eee.sn_num; ++i)
traceEvent(TRACE_NORMAL, "supernode %u => %s\n", i, (eee.sn_ip_array[i]));
supernode2addr(&(eee.supernode), eee.sn_ip_array[eee.sn_idx]);
@ -624,13 +620,20 @@ int main(int argc, char* argv[]) {
help();
}
#ifndef WIN32
if(eee.daemon) {
useSyslog = 1; /* traceEvent output now goes to syslog. */
daemonize();
}
#endif /* #ifndef WIN32 */
if((NULL == ec.encrypt_key) && (0 == strlen(eee.keyschedule)))
{
traceEvent(TRACE_WARNING, "Encryption is disabled in edge.");
eee.null_transop = 1;
}
#ifndef WIN32
/* If running suid root then we need to setuid before using the force. */
setuid(0);

0
packages/debian/Makefile → packages/debian/Makefile.in

3
packages/debian/configure

@ -1728,6 +1728,8 @@ ac_config_files="$ac_config_files ../etc/systemd/system/edge.service"
ac_config_files="$ac_config_files ../etc/systemd/system/supernode.service"
ac_config_files="$ac_config_files Makefile"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
# tests run on this system so they can be shared between configure
@ -2439,6 +2441,7 @@ do
"debian/rules") CONFIG_FILES="$CONFIG_FILES debian/rules" ;;
"../etc/systemd/system/edge.service") CONFIG_FILES="$CONFIG_FILES ../etc/systemd/system/edge.service" ;;
"../etc/systemd/system/supernode.service") CONFIG_FILES="$CONFIG_FILES ../etc/systemd/system/supernode.service" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
esac

1
packages/debian/configure.in

@ -41,4 +41,5 @@ AC_CONFIG_FILES(debian/control)
AC_CONFIG_FILES(debian/rules)
AC_CONFIG_FILES(../etc/systemd/system/edge.service)
AC_CONFIG_FILES(../etc/systemd/system/supernode.service)
AC_CONFIG_FILES(Makefile)
AC_OUTPUT

12
packages/etc/n2n/edge.conf

@ -7,17 +7,17 @@
# -d|--tun-device
# Specifies the name of the TUN interface.
#
# -d=n2n0
-d=n2n0
#
# -c|--community
# Specifies the n2n community name the edge belongs to.
#
# -c=mynetwork
-c=mynetwork
#
# -k
# Sets the encryption key (ASCII). The environment variable N2N_KEY=<key> can also be used.
#
# -k=mypassword
-k=mypassword
#
# -m
# Specified the MAC address for the TAP interface (random otherwise).
@ -27,15 +27,15 @@
# -a
# Sets the interface address. For DHCP use '-r -a dhcp:0.0.0.0'.
#
# -a=1.2.3.4
-a=1.2.3.4
#
# -p
# Sets the local UDP port to a fixed port.
#
# -p=50001
-p=50001
#
# -l|--supernode-list
# Specifies the supernode IP and port.
#
# -l=7.8.9.0:7777
-l=7.8.9.0:7777
#

2
packages/etc/n2n/supernode.conf

@ -1,5 +1,5 @@
#
# The configuration file is similar to the command line, with one option per line. An equal
# The configuration file is similar to the command line, with one option per line. An equal
# sign '=' should be used between key and value. Example: -l=7777 or --local-port=7777
# This file contains a basic configuration example, please refer to the help (-h) for the full
# list of available options.

813
sn.c

File diff suppressed because it is too large
Loading…
Cancel
Save