mirror of
https://github.com/ntop/n2n.git
synced 2024-09-20 00:51:10 +02:00
Compilation fixes
This commit is contained in:
parent
ed5b793379
commit
0825bfb16b
|
@ -1232,14 +1232,14 @@ static void readFromMgmtSocket(n2n_edge_t * eee, int * keep_running) {
|
|||
traceEvent(TRACE_DEBUG, "mgmt status rq");
|
||||
|
||||
msg_len=0;
|
||||
msg_len += snprintf((char *)(udp_buf+msg_len), (N2N_PKT_BUF_SIZE-msg_len),
|
||||
msg_len += snprintf((char*)&udp_buf[msg_len], (N2N_PKT_BUF_SIZE-msg_len),
|
||||
"STATISTICS FOR EDGE\n");
|
||||
msg_len += snprintf(udp_buf + msg_len, N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
msg_len += snprintf((char*)&udp_buf[msg_len], N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
"community: %s\n", eee->conf.community_name);
|
||||
|
||||
msg_len += snprintf(udp_buf + msg_len, N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
msg_len += snprintf((char*)&udp_buf[msg_len], N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
"\tid tun_tap MAC edge last_seen\n");
|
||||
msg_len += snprintf(udp_buf + msg_len, N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
msg_len += snprintf((char*)&udp_buf[msg_len], N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
"--- pending peers -------------------------------------------------------------------\n");
|
||||
|
||||
sendto(eee->udp_mgmt_sock, udp_buf, msg_len, 0/*flags*/,
|
||||
|
@ -1247,7 +1247,7 @@ static void readFromMgmtSocket(n2n_edge_t * eee, int * keep_running) {
|
|||
msg_len = 0;
|
||||
|
||||
HASH_ITER(hh, eee->pending_peers, peer, tmpPeer) {
|
||||
msg_len += snprintf(udp_buf + msg_len, N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
msg_len += snprintf((char*)&udp_buf[msg_len], N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
"\t%-4u %-18s %-17s %-21s %lu\n",
|
||||
++num, ip_subnet_to_str(ip_bit_str, &peer->dev_addr),
|
||||
macaddr_str(mac_buf, peer->mac_addr),
|
||||
|
@ -1258,11 +1258,11 @@ static void readFromMgmtSocket(n2n_edge_t * eee, int * keep_running) {
|
|||
msg_len = 0;
|
||||
}
|
||||
|
||||
msg_len += snprintf(udp_buf + msg_len, N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
msg_len += snprintf((char*)&udp_buf[msg_len], N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
"--- known peers ---------------------------------------------------------------------\n");
|
||||
|
||||
HASH_ITER(hh, eee->known_peers, peer, tmpPeer) {
|
||||
msg_len += snprintf(udp_buf + msg_len, N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
msg_len += snprintf((char*)&udp_buf[msg_len], N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
"\t%-4u %-18s %-17s %-21s %lu\n",
|
||||
++num, ip_subnet_to_str(ip_bit_str, &peer->dev_addr),
|
||||
macaddr_str(mac_buf, peer->mac_addr),
|
||||
|
@ -1273,7 +1273,7 @@ static void readFromMgmtSocket(n2n_edge_t * eee, int * keep_running) {
|
|||
msg_len = 0;
|
||||
}
|
||||
|
||||
msg_len += snprintf(udp_buf + msg_len, N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
msg_len += snprintf((char*)&udp_buf[msg_len], N2N_SN_PKTBUF_SIZE - msg_len,
|
||||
"-------------------------------------------------------------------------------------\n");
|
||||
|
||||
msg_len += snprintf((char *)(udp_buf+msg_len), (N2N_PKT_BUF_SIZE-msg_len),
|
||||
|
|
195
src/sn.c
195
src/sn.c
|
@ -101,10 +101,10 @@ static int load_allowed_sn_community(n2n_sn_t *sss, char *path) {
|
|||
fclose(fd);
|
||||
|
||||
if ((num_regex + num_communities) == 0)
|
||||
{
|
||||
traceEvent(TRACE_WARNING, "File %s does not contain any valid community names or regular expressions", path);
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
traceEvent(TRACE_WARNING, "File %s does not contain any valid community names or regular expressions", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
traceEvent(TRACE_NORMAL, "Loaded %u fixed-name communities from %s",
|
||||
num_communities, path);
|
||||
|
@ -123,137 +123,136 @@ static int load_allowed_sn_community(n2n_sn_t *sss, char *path) {
|
|||
|
||||
/** Help message to print if the command line arguments are not valid. */
|
||||
static void help() {
|
||||
print_n2n_version();
|
||||
print_n2n_version();
|
||||
|
||||
printf("supernode <config file> (see supernode.conf)\n"
|
||||
"or\n"
|
||||
);
|
||||
printf("supernode ");
|
||||
printf("-l <local port> ");
|
||||
printf("-c <path> ");
|
||||
printf("supernode <config file> (see supernode.conf)\n"
|
||||
"or\n"
|
||||
);
|
||||
printf("supernode ");
|
||||
printf("-l <local port> ");
|
||||
printf("-c <path> ");
|
||||
#if defined(N2N_HAVE_DAEMON)
|
||||
printf("[-f] ");
|
||||
printf("[-f] ");
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
printf("[-u <uid> -g <gid>] ");
|
||||
printf("[-u <uid> -g <gid>] ");
|
||||
#endif /* ifndef WIN32 */
|
||||
printf("[-t <mgmt port>] ");
|
||||
printf("[-d <net/bit>] ");
|
||||
printf("[-v] ");
|
||||
printf("\n\n");
|
||||
printf("[-t <mgmt port>] ");
|
||||
printf("[-d <net/bit>] ");
|
||||
printf("[-v] ");
|
||||
printf("\n\n");
|
||||
|
||||
printf("-l <port> | Set UDP main listen port to <port>\n");
|
||||
printf("-c <path> | File containing the allowed communities.\n");
|
||||
printf("-l <port> | Set UDP main listen port to <port>\n");
|
||||
printf("-c <path> | File containing the allowed communities.\n");
|
||||
#if defined(N2N_HAVE_DAEMON)
|
||||
printf("-f | Run in foreground.\n");
|
||||
printf("-f | Run in foreground.\n");
|
||||
#endif /* #if defined(N2N_HAVE_DAEMON) */
|
||||
#ifndef WIN32
|
||||
printf("-u <UID> | User ID (numeric) to use when privileges are dropped.\n");
|
||||
printf("-g <GID> | Group ID (numeric) to use when privileges are dropped.\n");
|
||||
printf("-u <UID> | User ID (numeric) to use when privileges are dropped.\n");
|
||||
printf("-g <GID> | Group ID (numeric) to use when privileges are dropped.\n");
|
||||
#endif /* ifndef WIN32 */
|
||||
printf("-t <port> | Management UDP Port (for multiple supernodes on a machine).\n");
|
||||
printf("-d <net/bit> | Subnet that provides dhcp service for edge. eg. -d 172.17.12.0/24\n");
|
||||
printf("-v | Increase verbosity. Can be used multiple times.\n");
|
||||
printf("-h | This help message.\n");
|
||||
printf("\n");
|
||||
printf("-t <port> | Management UDP Port (for multiple supernodes on a machine).\n");
|
||||
printf("-d <net/bit> | Subnet that provides dhcp service for edge. eg. -d 172.17.12.0/24\n");
|
||||
printf("-v | Increase verbosity. Can be used multiple times.\n");
|
||||
printf("-h | This help message.\n");
|
||||
printf("\n");
|
||||
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
static int setOption(int optkey, char *_optarg, n2n_sn_t *sss) {
|
||||
//traceEvent(TRACE_NORMAL, "Option %c = %s", optkey, _optarg ? _optarg : "");
|
||||
//traceEvent(TRACE_NORMAL, "Option %c = %s", optkey, _optarg ? _optarg : "");
|
||||
|
||||
switch (optkey) {
|
||||
case 'l': /* local-port */
|
||||
sss->lport = atoi(_optarg);
|
||||
break;
|
||||
switch (optkey) {
|
||||
case 'l': /* local-port */
|
||||
sss->lport = atoi(_optarg);
|
||||
break;
|
||||
|
||||
case 't': /* mgmt-port */
|
||||
sss->mport = atoi(_optarg);
|
||||
break;
|
||||
case 't': /* mgmt-port */
|
||||
sss->mport = atoi(_optarg);
|
||||
break;
|
||||
|
||||
case 'd': {
|
||||
dec_ip_str_t ip_str = {'\0'};
|
||||
in_addr_t net;
|
||||
uint8_t bitlen;
|
||||
case 'd': {
|
||||
dec_ip_str_t ip_str = {'\0'};
|
||||
in_addr_t net;
|
||||
uint8_t bitlen;
|
||||
|
||||
if (sscanf(_optarg, "%15[^/]/%hhu", ip_str, &bitlen) != 2) {
|
||||
traceEvent(TRACE_WARNING, "Bad net/bit format '%s'. See -h.", _optarg);
|
||||
break;
|
||||
}
|
||||
if (sscanf(_optarg, "%15[^/]/%hhu", ip_str, &bitlen) != 2) {
|
||||
traceEvent(TRACE_WARNING, "Bad net/bit format '%s'. See -h.", _optarg);
|
||||
break;
|
||||
}
|
||||
|
||||
net = inet_addr(ip_str);
|
||||
if ((net < 0) || (net == INADDR_NONE) || (net == INADDR_ANY)) {
|
||||
traceEvent(TRACE_WARNING, "Bad network '%s' in '%s', Use default: '%s/%d'",
|
||||
ip_str, _optarg,
|
||||
N2N_SN_DHCP_NET_ADDR_DEFAULT, N2N_SN_DHCP_NET_BIT_DEFAULT);
|
||||
break;
|
||||
}
|
||||
net = inet_addr(ip_str);
|
||||
if ((net == (in_addr_t)(-1)) || (net == INADDR_NONE) || (net == INADDR_ANY)) {
|
||||
traceEvent(TRACE_WARNING, "Bad network '%s' in '%s', Use default: '%s/%d'",
|
||||
ip_str, _optarg,
|
||||
N2N_SN_DHCP_NET_ADDR_DEFAULT, N2N_SN_DHCP_NET_BIT_DEFAULT);
|
||||
break;
|
||||
}
|
||||
|
||||
if (bitlen > 32) {
|
||||
traceEvent(TRACE_WARNING, "Bad prefix '%hhu' in '%s', Use default: '%s/%d'",
|
||||
bitlen, _optarg,
|
||||
N2N_SN_DHCP_NET_ADDR_DEFAULT, N2N_SN_DHCP_NET_BIT_DEFAULT);
|
||||
break;
|
||||
}
|
||||
if (bitlen > 32) {
|
||||
traceEvent(TRACE_WARNING, "Bad prefix '%hhu' in '%s', Use default: '%s/%d'",
|
||||
bitlen, _optarg,
|
||||
N2N_SN_DHCP_NET_ADDR_DEFAULT, N2N_SN_DHCP_NET_BIT_DEFAULT);
|
||||
break;
|
||||
}
|
||||
|
||||
traceEvent(TRACE_NORMAL, "The subnet of DHCP service is: '%s/%hhu'.", ip_str, bitlen);
|
||||
traceEvent(TRACE_NORMAL, "The subnet of DHCP service is: '%s/%hhu'.", ip_str, bitlen);
|
||||
|
||||
sss->dhcp_addr.net_addr = ntohl(net);
|
||||
sss->dhcp_addr.net_bitlen = bitlen;
|
||||
sss->dhcp_addr.net_addr = ntohl(net);
|
||||
sss->dhcp_addr.net_bitlen = bitlen;
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
case 'u': /* unprivileged uid */
|
||||
sss->userid = atoi(_optarg);
|
||||
break;
|
||||
case 'u': /* unprivileged uid */
|
||||
sss->userid = atoi(_optarg);
|
||||
break;
|
||||
|
||||
case 'g': /* unprivileged uid */
|
||||
sss->groupid = atoi(_optarg);
|
||||
break;
|
||||
case 'g': /* unprivileged uid */
|
||||
sss->groupid = atoi(_optarg);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case 'c': /* community file */
|
||||
load_allowed_sn_community(sss, _optarg);
|
||||
break;
|
||||
case 'c': /* community file */
|
||||
load_allowed_sn_community(sss, _optarg);
|
||||
break;
|
||||
|
||||
case 'f': /* foreground */
|
||||
sss->daemon = 0;
|
||||
break;
|
||||
case 'f': /* foreground */
|
||||
sss->daemon = 0;
|
||||
break;
|
||||
|
||||
case 'h': /* help */
|
||||
help();
|
||||
break;
|
||||
case 'h': /* help */
|
||||
help();
|
||||
break;
|
||||
|
||||
case 'v': /* verbose */
|
||||
setTraceLevel(getTraceLevel() + 1);
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
setTraceLevel(getTraceLevel() + 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
traceEvent(TRACE_WARNING, "Unknown option -%c: Ignored.", (char) optkey);
|
||||
return (-1);
|
||||
}
|
||||
default:
|
||||
traceEvent(TRACE_WARNING, "Unknown option -%c: Ignored.", (char) optkey);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* *********************************************** */
|
||||
|
||||
static const struct option long_options[] = {
|
||||
{"communities", required_argument, NULL, 'c'},
|
||||
{"foreground", no_argument, NULL, 'f'},
|
||||
{"local-port", required_argument, NULL, 'l'},
|
||||
{"mgmt-port", required_argument, NULL, 't'},
|
||||
{"dhcp", required_argument, NULL, 'd'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0}
|
||||
{"communities", required_argument, NULL, 'c'},
|
||||
{"foreground", no_argument, NULL, 'f'},
|
||||
{"local-port", required_argument, NULL, 'l'},
|
||||
{"mgmt-port", required_argument, NULL, 't'},
|
||||
{"dhcp", required_argument, NULL, 'd'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
/* *************************************************** */
|
||||
|
@ -395,7 +394,7 @@ static int keep_running;
|
|||
#ifdef WIN32
|
||||
BOOL WINAPI term_handler(DWORD sig)
|
||||
#else
|
||||
static void term_handler(int sig)
|
||||
static void term_handler(int sig)
|
||||
#endif
|
||||
{
|
||||
static int called = 0;
|
||||
|
@ -424,7 +423,7 @@ int main(int argc, char * const argv[]) {
|
|||
struct passwd *pw = NULL;
|
||||
#endif
|
||||
|
||||
sn_init(&sss_node);
|
||||
sn_init(&sss_node);
|
||||
|
||||
if((argc >= 2) && (argv[1][0] != '-')) {
|
||||
rc = loadFromFile(argv[1], &sss_node);
|
||||
|
@ -437,7 +436,7 @@ int main(int argc, char * const argv[]) {
|
|||
/* Load from current directory */
|
||||
rc = loadFromFile("supernode.conf", &sss_node);
|
||||
#else
|
||||
rc = -1;
|
||||
rc = -1;
|
||||
#endif
|
||||
|
||||
if(rc < 0)
|
||||
|
@ -478,7 +477,7 @@ int main(int argc, char * const argv[]) {
|
|||
}
|
||||
if((sss_node.userid != 0) || (sss_node.groupid != 0)) {
|
||||
traceEvent(TRACE_NORMAL, "Dropping privileges to uid=%d, gid=%d",
|
||||
(signed int)sss_node.userid, (signed int)sss_node.groupid);
|
||||
(signed int)sss_node.userid, (signed int)sss_node.groupid);
|
||||
|
||||
/* Finished with the need for root privileges. Drop to unprivileged user. */
|
||||
if((setgid(sss_node.groupid) != 0)
|
||||
|
|
|
@ -874,10 +874,10 @@ static int process_udp(n2n_sn_t * sss,
|
|||
|
||||
if(!comm && sss->lock_communities) {
|
||||
HASH_ITER(hh, sss->rules, re, tmp_re) {
|
||||
allowed_match = re_matchp(re->rule, cmn.community, &match_length);
|
||||
allowed_match = re_matchp(re->rule, (const char *)cmn.community, &match_length);
|
||||
|
||||
if( (allowed_match != -1)
|
||||
&& (match_length == strlen(cmn.community)) // --- only full matches allowed (remove, if also partial matches wanted)
|
||||
&& (match_length == strlen((const char *)cmn.community)) // --- only full matches allowed (remove, if also partial matches wanted)
|
||||
&& (allowed_match == 0)) { // --- only full matches allowed (remove, if also partial matches wanted)
|
||||
match = 1;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user