mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Revive config_test.c
Move config-dependent code (recvwithttl) from net.c to mdp_net.c (new) Move log-implementation-independent code from log.c to log_util.c (new) Build config_test binary in Makefile
This commit is contained in:
parent
513aa15968
commit
92253ca97d
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,6 +21,7 @@ serval.c
|
||||
/directory_service
|
||||
/tfw_createfile
|
||||
/fakeradio
|
||||
/config_test
|
||||
*.so
|
||||
test.*.log
|
||||
testlog
|
||||
|
@ -23,6 +23,7 @@ MONITORCLIENTSRCS=conf.c \
|
||||
conf_schema.c \
|
||||
dataformats.c \
|
||||
log.c \
|
||||
log_util.c \
|
||||
xprintf.c \
|
||||
os.c \
|
||||
mem.c \
|
||||
@ -43,10 +44,12 @@ MDPCLIENTSRCS=conf.c \
|
||||
os.c \
|
||||
mem.c \
|
||||
log.c \
|
||||
log_util.c \
|
||||
xprintf.c \
|
||||
mdp_client.c \
|
||||
instance.c \
|
||||
net.c \
|
||||
mdp_net.c \
|
||||
socket.c \
|
||||
str.c \
|
||||
strbuf.c \
|
||||
@ -76,7 +79,7 @@ DEFS= @DEFS@
|
||||
|
||||
all: servald libmonitorclient.so libmonitorclient.a test
|
||||
|
||||
test: tfw_createfile directory_service fakeradio
|
||||
test: tfw_createfile directory_service fakeradio config_test
|
||||
|
||||
sqlite-amalgamation-3070900/sqlite3.o: sqlite-amalgamation-3070900/sqlite3.c
|
||||
@echo CC $<
|
||||
@ -111,6 +114,10 @@ fakeradio: fakeradio.o
|
||||
@echo LINK $@
|
||||
@$(CC) $(CFLAGS) -Wall -o $@ fakeradio.o
|
||||
|
||||
config_test: config_test.o conf_om.o conf_schema.o conf_parse.o str.o strbuf.o strbuf_helpers.o mem.o dataformats.o net.o log_util.o
|
||||
@echo LINK $@
|
||||
@$(CC) $(CFLAGS) -Wall -o $@ config_test.o conf_om.o conf_schema.o conf_parse.o str.o strbuf.o strbuf_helpers.o mem.o dataformats.o net.o log_util.o
|
||||
|
||||
# This does not build on 64 bit elf platforms as NaCL isn't built with -fPIC
|
||||
# DOC 20120615
|
||||
libservald.so: $(OBJS) version.o
|
||||
|
6
conf.h
6
conf.h
@ -222,8 +222,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
|
||||
#ifndef __SERVALDNA_CONFIG_H
|
||||
#define __SERVALDNA_CONFIG_H
|
||||
#ifndef __SERVALDNA_CONF_H
|
||||
#define __SERVALDNA_CONF_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <arpa/inet.h>
|
||||
@ -701,4 +701,4 @@ int cf_reload();
|
||||
int cf_reload_strict();
|
||||
int cf_reload_permissive();
|
||||
|
||||
#endif //__SERVALDNA_CONFIG_H
|
||||
#endif //__SERVALDNA_CONF_H
|
||||
|
@ -632,11 +632,7 @@ int cf_cmp_sid(const sid_t *a, const sid_t *b)
|
||||
|
||||
int cf_opt_rhizome_bk(rhizome_bk_t *bkp, const char *text)
|
||||
{
|
||||
if (!rhizome_str_is_bundle_key(text))
|
||||
return CFINVALID;
|
||||
size_t n = fromhex(bkp->binary, text, RHIZOME_BUNDLE_KEY_BYTES);
|
||||
assert(n == RHIZOME_BUNDLE_KEY_BYTES);
|
||||
return CFOK;
|
||||
return str_to_rhizome_bk_t(bkp, text) ? CFOK : CFINVALID;
|
||||
}
|
||||
|
||||
int cf_fmt_rhizome_bk(const char **textp, const rhizome_bk_t *bkp)
|
||||
|
@ -1,8 +1,28 @@
|
||||
/*
|
||||
Serval DNA configuration stand-alone configuration check utility
|
||||
Copyright 2013 Serval Project, Inc.
|
||||
|
||||
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 2
|
||||
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, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "str.h"
|
||||
@ -30,7 +50,7 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
struct cf_om_node *root = NULL;
|
||||
int ret = cf_parse_to_om(argv[i], buf, st.st_size, &root);
|
||||
int ret = cf_om_parse(argv[i], buf, st.st_size, &root);
|
||||
close(fd);
|
||||
DEBUGF("ret = %s", strbuf_str(strbuf_cf_flags(strbuf_alloca(128), ret)));
|
||||
//cf_dump_node(root, 0);
|
||||
@ -38,17 +58,17 @@ int main(int argc, char **argv)
|
||||
memset(&config, 0, sizeof config);
|
||||
cf_dfl_config_main(&config);
|
||||
int result = root ? cf_opt_config_main(&config, root) : CFEMPTY;
|
||||
cf_free_node(&root);
|
||||
cf_om_free_node(&root);
|
||||
free(buf);
|
||||
DEBUGF("result = %s", strbuf_str(strbuf_cf_flags(strbuf_alloca(128), result)));
|
||||
DEBUGF("config.log.file = %s", alloca_str_toprint(config.log.file));
|
||||
DEBUGF("config.log.show_pid = %d", config.log.show_pid);
|
||||
DEBUGF("config.log.show_time = %d", config.log.show_time);
|
||||
DEBUGF("config.log.file.path = %s", alloca_str_toprint(config.log.file.path));
|
||||
DEBUGF("config.log.file.show_pid = %d", config.log.file.show_pid);
|
||||
DEBUGF("config.log.file.show_time = %d", config.log.file.show_time);
|
||||
DEBUGF("config.server.chdir = %s", alloca_str_toprint(config.server.chdir));
|
||||
DEBUGF("config.debug = %"PRIx64, (uint64_t) config.debug);
|
||||
DEBUGF("config.debug.verbose = %d", config.debug.verbose);
|
||||
DEBUGF("config.directory.service = %s", alloca_tohex_sid_t(config.directory.service));
|
||||
DEBUGF("config.rhizome.api.addfile.allow_host = %s", inet_ntoa(config.rhizome.api.addfile.allow_host));
|
||||
int j;
|
||||
unsigned j;
|
||||
for (j = 0; j < config.mdp.iftype.ac; ++j) {
|
||||
DEBUGF("config.mdp.iftype.%u", config.mdp.iftype.av[j].key);
|
||||
DEBUGF(" .tick_ms = %u", config.mdp.iftype.av[j].value.tick_ms);
|
||||
@ -63,7 +83,7 @@ int main(int argc, char **argv)
|
||||
DEBUGF(" .port = %u", config.rhizome.direct.peer.av[j].value.port);
|
||||
}
|
||||
for (j = 0; j < config.interfaces.ac; ++j) {
|
||||
DEBUGF("config.interfaces.%s", config.interfaces.av[j].key);
|
||||
DEBUGF("config.interfaces.%u", config.interfaces.av[j].key);
|
||||
DEBUGF(" .exclude = %d", config.interfaces.av[j].value.exclude);
|
||||
DEBUGF(" .match = [");
|
||||
int k;
|
||||
@ -72,7 +92,9 @@ int main(int argc, char **argv)
|
||||
DEBUGF(" ]");
|
||||
DEBUGF(" .type = %d", config.interfaces.av[j].value.type);
|
||||
DEBUGF(" .port = %u", config.interfaces.av[j].value.port);
|
||||
DEBUGF(" .speed = %llu", (unsigned long long) config.interfaces.av[j].value.speed);
|
||||
DEBUGF(" .drop_broadcasts = %llu", (unsigned long long) config.interfaces.av[j].value.drop_broadcasts);
|
||||
DEBUGF(" .drop_unicasts = %llu", (unsigned long long) config.interfaces.av[j].value.drop_unicasts);
|
||||
DEBUGF(" .drop_packets = %llu", (unsigned long long) config.interfaces.av[j].value.drop_packets);
|
||||
}
|
||||
for (j = 0; j < config.hosts.ac; ++j) {
|
||||
char sidhex[SID_STRLEN + 1];
|
||||
@ -129,37 +151,3 @@ void logMessage(int level, struct __sourceloc whence, const char *fmt, ...)
|
||||
va_end(ap);
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
|
||||
debugflags_t debugFlagMask(const char *flagname)
|
||||
{
|
||||
if (!strcasecmp(flagname,"all")) return ~0;
|
||||
else if (!strcasecmp(flagname,"interfaces")) return 1 << 0;
|
||||
else if (!strcasecmp(flagname,"rx")) return 1 << 1;
|
||||
else if (!strcasecmp(flagname,"tx")) return 1 << 2;
|
||||
else if (!strcasecmp(flagname,"verbose")) return 1 << 3;
|
||||
else if (!strcasecmp(flagname,"verbio")) return 1 << 4;
|
||||
else if (!strcasecmp(flagname,"peers")) return 1 << 5;
|
||||
else if (!strcasecmp(flagname,"dnaresponses")) return 1 << 6;
|
||||
else if (!strcasecmp(flagname,"dnahelper")) return 1 << 7;
|
||||
else if (!strcasecmp(flagname,"vomp")) return 1 << 8;
|
||||
else if (!strcasecmp(flagname,"packetformats")) return 1 << 9;
|
||||
else if (!strcasecmp(flagname,"packetconstruction")) return 1 << 10;
|
||||
else if (!strcasecmp(flagname,"gateway")) return 1 << 11;
|
||||
else if (!strcasecmp(flagname,"keyring")) return 1 << 12;
|
||||
else if (!strcasecmp(flagname,"sockio")) return 1 << 13;
|
||||
else if (!strcasecmp(flagname,"frames")) return 1 << 14;
|
||||
else if (!strcasecmp(flagname,"abbreviations")) return 1 << 15;
|
||||
else if (!strcasecmp(flagname,"routing")) return 1 << 16;
|
||||
else if (!strcasecmp(flagname,"security")) return 1 << 17;
|
||||
else if (!strcasecmp(flagname,"rhizome")) return 1 << 18;
|
||||
else if (!strcasecmp(flagname,"rhizometx")) return 1 << 19;
|
||||
else if (!strcasecmp(flagname,"rhizomerx")) return 1 << 20;
|
||||
else if (!strcasecmp(flagname,"rhizomeads")) return 1 << 21;
|
||||
else if (!strcasecmp(flagname,"monitorroutes")) return 1 << 22;
|
||||
else if (!strcasecmp(flagname,"queues")) return 1 << 23;
|
||||
else if (!strcasecmp(flagname,"broadcasts")) return 1 << 24;
|
||||
else if (!strcasecmp(flagname,"manifests")) return 1 << 25;
|
||||
else if (!strcasecmp(flagname,"mdprequests")) return 1 << 26;
|
||||
else if (!strcasecmp(flagname,"timing")) return 1 << 27;
|
||||
return 0;
|
||||
}
|
||||
|
54
log.c
54
log.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Serval DNA logging.
|
||||
Serval DNA logging
|
||||
Copyright 2013 Serval Project Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
@ -717,30 +717,6 @@ void logConfigChanged()
|
||||
logFlush();
|
||||
}
|
||||
|
||||
int logDump(int level, struct __sourceloc whence, char *name, const unsigned char *addr, size_t len)
|
||||
{
|
||||
if (level != LOG_LEVEL_SILENT) {
|
||||
char buf[100];
|
||||
size_t i;
|
||||
if (name)
|
||||
logMessage(level, whence, "Dump of %s", name);
|
||||
for(i = 0; i < len; i += 16) {
|
||||
strbuf b = strbuf_local(buf, sizeof buf);
|
||||
strbuf_sprintf(b, " %04zx :", i);
|
||||
int j;
|
||||
for (j = 0; j < 16 && i + j < len; j++)
|
||||
strbuf_sprintf(b, " %02x", addr[i + j]);
|
||||
for (; j < 16; j++)
|
||||
strbuf_puts(b, " ");
|
||||
strbuf_puts(b, " ");
|
||||
for (j = 0; j < 16 && i + j < len; j++)
|
||||
strbuf_sprintf(b, "%c", addr[i+j] >= ' ' && addr[i+j] < 0x7f ? addr[i+j] : '.');
|
||||
logMessage(level, whence, "%s", strbuf_str(b));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t get_self_executable_path(char *buf, size_t len)
|
||||
{
|
||||
#if defined(linux)
|
||||
@ -860,31 +836,3 @@ int log_backtrace(int level, struct __sourceloc whence)
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *log_level_as_string(int level)
|
||||
{
|
||||
switch (level) {
|
||||
case LOG_LEVEL_SILENT: return "silent";
|
||||
case LOG_LEVEL_DEBUG: return "debug";
|
||||
case LOG_LEVEL_INFO: return "info";
|
||||
case LOG_LEVEL_HINT: return "hint";
|
||||
case LOG_LEVEL_WARN: return "warn";
|
||||
case LOG_LEVEL_ERROR: return "error";
|
||||
case LOG_LEVEL_FATAL: return "fatal";
|
||||
case LOG_LEVEL_NONE: return "none";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int string_to_log_level(const char *text)
|
||||
{
|
||||
if (strcasecmp(text, "none") == 0) return LOG_LEVEL_NONE;
|
||||
if (strcasecmp(text, "fatal") == 0) return LOG_LEVEL_FATAL;
|
||||
if (strcasecmp(text, "error") == 0) return LOG_LEVEL_ERROR;
|
||||
if (strcasecmp(text, "warn") == 0) return LOG_LEVEL_WARN;
|
||||
if (strcasecmp(text, "hint") == 0) return LOG_LEVEL_HINT;
|
||||
if (strcasecmp(text, "info") == 0) return LOG_LEVEL_INFO;
|
||||
if (strcasecmp(text, "debug") == 0) return LOG_LEVEL_DEBUG;
|
||||
if (strcasecmp(text, "silent") == 0) return LOG_LEVEL_SILENT;
|
||||
return LOG_LEVEL_INVALID;
|
||||
}
|
||||
|
73
log_util.c
Normal file
73
log_util.c
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
Serval DNA logging utility functions
|
||||
Copyright 2013 Serval Project Inc.
|
||||
|
||||
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 2
|
||||
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, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
int logDump(int level, struct __sourceloc whence, char *name, const unsigned char *addr, size_t len)
|
||||
{
|
||||
if (level != LOG_LEVEL_SILENT) {
|
||||
char buf[100];
|
||||
size_t i;
|
||||
if (name)
|
||||
logMessage(level, whence, "Dump of %s", name);
|
||||
for(i = 0; i < len; i += 16) {
|
||||
strbuf b = strbuf_local(buf, sizeof buf);
|
||||
strbuf_sprintf(b, " %04zx :", i);
|
||||
int j;
|
||||
for (j = 0; j < 16 && i + j < len; j++)
|
||||
strbuf_sprintf(b, " %02x", addr[i + j]);
|
||||
for (; j < 16; j++)
|
||||
strbuf_puts(b, " ");
|
||||
strbuf_puts(b, " ");
|
||||
for (j = 0; j < 16 && i + j < len; j++)
|
||||
strbuf_sprintf(b, "%c", addr[i+j] >= ' ' && addr[i+j] < 0x7f ? addr[i+j] : '.');
|
||||
logMessage(level, whence, "%s", strbuf_str(b));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *log_level_as_string(int level)
|
||||
{
|
||||
switch (level) {
|
||||
case LOG_LEVEL_SILENT: return "silent";
|
||||
case LOG_LEVEL_DEBUG: return "debug";
|
||||
case LOG_LEVEL_INFO: return "info";
|
||||
case LOG_LEVEL_HINT: return "hint";
|
||||
case LOG_LEVEL_WARN: return "warn";
|
||||
case LOG_LEVEL_ERROR: return "error";
|
||||
case LOG_LEVEL_FATAL: return "fatal";
|
||||
case LOG_LEVEL_NONE: return "none";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int string_to_log_level(const char *text)
|
||||
{
|
||||
if (strcasecmp(text, "none") == 0) return LOG_LEVEL_NONE;
|
||||
if (strcasecmp(text, "fatal") == 0) return LOG_LEVEL_FATAL;
|
||||
if (strcasecmp(text, "error") == 0) return LOG_LEVEL_ERROR;
|
||||
if (strcasecmp(text, "warn") == 0) return LOG_LEVEL_WARN;
|
||||
if (strcasecmp(text, "hint") == 0) return LOG_LEVEL_HINT;
|
||||
if (strcasecmp(text, "info") == 0) return LOG_LEVEL_INFO;
|
||||
if (strcasecmp(text, "debug") == 0) return LOG_LEVEL_DEBUG;
|
||||
if (strcasecmp(text, "silent") == 0) return LOG_LEVEL_SILENT;
|
||||
return LOG_LEVEL_INVALID;
|
||||
}
|
80
mdp_net.c
Normal file
80
mdp_net.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright (C) 2013 Serval Project, Inc.
|
||||
|
||||
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 2
|
||||
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, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "serval.h"
|
||||
#include "conf.h"
|
||||
#include "log.h"
|
||||
|
||||
ssize_t recvwithttl(int sock,unsigned char *buffer, size_t bufferlen,int *ttl,
|
||||
struct sockaddr *recvaddr, socklen_t *recvaddrlen)
|
||||
{
|
||||
struct msghdr msg;
|
||||
struct iovec iov[1];
|
||||
|
||||
iov[0].iov_base=buffer;
|
||||
iov[0].iov_len=bufferlen;
|
||||
bzero(&msg,sizeof(msg));
|
||||
msg.msg_name = recvaddr;
|
||||
msg.msg_namelen = *recvaddrlen;
|
||||
msg.msg_iov = &iov[0];
|
||||
msg.msg_iovlen = 1;
|
||||
// setting the following makes the data end up in the wrong place
|
||||
// msg.msg_iov->iov_base=iov_buffer;
|
||||
// msg.msg_iov->iov_len=sizeof(iov_buffer);
|
||||
|
||||
struct cmsghdr cmsgcmsg[16];
|
||||
msg.msg_control = &cmsgcmsg[0];
|
||||
msg.msg_controllen = sizeof(struct cmsghdr)*16;
|
||||
msg.msg_flags = 0;
|
||||
|
||||
ssize_t len = recvmsg(sock,&msg,0);
|
||||
if (len == -1 && errno != EAGAIN && errno != EWOULDBLOCK)
|
||||
return WHY_perror("recvmsg");
|
||||
|
||||
#if 0
|
||||
if (config.debug.packetrx) {
|
||||
DEBUGF("recvmsg returned %d (flags=%d, msg_controllen=%d)", (int) len, msg.msg_flags, (int)msg.msg_controllen);
|
||||
dump("received data", buffer, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (len > 0) {
|
||||
struct cmsghdr *cmsg;
|
||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||
if ( cmsg->cmsg_level == IPPROTO_IP
|
||||
&& ((cmsg->cmsg_type == IP_RECVTTL) || (cmsg->cmsg_type == IP_TTL))
|
||||
&& cmsg->cmsg_len
|
||||
) {
|
||||
if (config.debug.packetrx)
|
||||
DEBUGF(" TTL (%p) data location resolves to %p", ttl,CMSG_DATA(cmsg));
|
||||
if (CMSG_DATA(cmsg)) {
|
||||
*ttl = *(unsigned char *) CMSG_DATA(cmsg);
|
||||
if (config.debug.packetrx)
|
||||
DEBUGF(" TTL of packet is %d", *ttl);
|
||||
}
|
||||
} else {
|
||||
if (config.debug.packetrx)
|
||||
DEBUGF("I didn't expect to see level=%02x, type=%02x",
|
||||
cmsg->cmsg_level,cmsg->cmsg_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
*recvaddrlen=msg.msg_namelen;
|
||||
|
||||
return len;
|
||||
}
|
59
net.c
59
net.c
@ -137,62 +137,3 @@ ssize_t _write_str_nonblock(int fd, const char *str, struct __sourceloc __whence
|
||||
{
|
||||
return _write_all_nonblock(fd, str, strlen(str), __whence);
|
||||
}
|
||||
|
||||
ssize_t recvwithttl(int sock,unsigned char *buffer, size_t bufferlen,int *ttl,
|
||||
struct sockaddr *recvaddr, socklen_t *recvaddrlen)
|
||||
{
|
||||
struct msghdr msg;
|
||||
struct iovec iov[1];
|
||||
|
||||
iov[0].iov_base=buffer;
|
||||
iov[0].iov_len=bufferlen;
|
||||
bzero(&msg,sizeof(msg));
|
||||
msg.msg_name = recvaddr;
|
||||
msg.msg_namelen = *recvaddrlen;
|
||||
msg.msg_iov = &iov[0];
|
||||
msg.msg_iovlen = 1;
|
||||
// setting the following makes the data end up in the wrong place
|
||||
// msg.msg_iov->iov_base=iov_buffer;
|
||||
// msg.msg_iov->iov_len=sizeof(iov_buffer);
|
||||
|
||||
struct cmsghdr cmsgcmsg[16];
|
||||
msg.msg_control = &cmsgcmsg[0];
|
||||
msg.msg_controllen = sizeof(struct cmsghdr)*16;
|
||||
msg.msg_flags = 0;
|
||||
|
||||
ssize_t len = recvmsg(sock,&msg,0);
|
||||
if (len == -1 && errno != EAGAIN && errno != EWOULDBLOCK)
|
||||
return WHY_perror("recvmsg");
|
||||
|
||||
#if 0
|
||||
if (config.debug.packetrx) {
|
||||
DEBUGF("recvmsg returned %d (flags=%d, msg_controllen=%d)", (int) len, msg.msg_flags, (int)msg.msg_controllen);
|
||||
dump("received data", buffer, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (len > 0) {
|
||||
struct cmsghdr *cmsg;
|
||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||
if ( cmsg->cmsg_level == IPPROTO_IP
|
||||
&& ((cmsg->cmsg_type == IP_RECVTTL) || (cmsg->cmsg_type == IP_TTL))
|
||||
&& cmsg->cmsg_len
|
||||
) {
|
||||
if (config.debug.packetrx)
|
||||
DEBUGF(" TTL (%p) data location resolves to %p", ttl,CMSG_DATA(cmsg));
|
||||
if (CMSG_DATA(cmsg)) {
|
||||
*ttl = *(unsigned char *) CMSG_DATA(cmsg);
|
||||
if (config.debug.packetrx)
|
||||
DEBUGF(" TTL of packet is %d", *ttl);
|
||||
}
|
||||
} else {
|
||||
if (config.debug.packetrx)
|
||||
DEBUGF("I didn't expect to see level=%02x, type=%02x",
|
||||
cmsg->cmsg_level,cmsg->cmsg_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
*recvaddrlen=msg.msg_namelen;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
1
net.h
1
net.h
@ -52,6 +52,5 @@ ssize_t _write_all_nonblock(int fd, const void *buf, size_t len, struct __source
|
||||
ssize_t _writev_all(int fd, const struct iovec *iov, int iovcnt, struct __sourceloc __whence);
|
||||
ssize_t _write_str(int fd, const char *str, struct __sourceloc __whence);
|
||||
ssize_t _write_str_nonblock(int fd, const char *str, struct __sourceloc __whence);
|
||||
ssize_t recvwithttl(int sock, unsigned char *buffer, size_t bufferlen, int *ttl, struct sockaddr *recvaddr, socklen_t *recvaddrlen);
|
||||
|
||||
#endif // __SERVALD_NET_H
|
||||
|
2
serval.h
2
serval.h
@ -217,6 +217,8 @@ int _socket_set_rcvbufsize(struct __sourceloc, int sock, unsigned buffer_size);
|
||||
int real_sockaddr(const struct sockaddr_un *src_addr, socklen_t src_addrlen, struct sockaddr_un *dst_addr, socklen_t *dst_addrlen);
|
||||
int cmp_sockaddr(const struct sockaddr *, socklen_t, const struct sockaddr *, socklen_t);
|
||||
|
||||
ssize_t recvwithttl(int sock, unsigned char *buffer, size_t bufferlen, int *ttl, struct sockaddr *recvaddr, socklen_t *recvaddrlen);
|
||||
|
||||
#define SERVER_CONFIG_RELOAD_INTERVAL_MS 1000
|
||||
|
||||
struct cli_parsed;
|
||||
|
@ -17,11 +17,13 @@ SERVAL_SOURCES = \
|
||||
$(SERVAL_BASE)http_server.c \
|
||||
$(SERVAL_BASE)keyring.c \
|
||||
$(SERVAL_BASE)log.c \
|
||||
$(SERVAL_BASE)log_util.c \
|
||||
$(SERVAL_BASE)lsif.c \
|
||||
$(SERVAL_BASE)main.c \
|
||||
$(SERVAL_BASE)mavlink.c \
|
||||
$(SERVAL_BASE)meshms.c \
|
||||
$(SERVAL_BASE)mdp_client.c \
|
||||
$(SERVAL_BASE)mdp_net.c \
|
||||
$(SERVAL_BASE)os.c \
|
||||
$(SERVAL_BASE)mem.c \
|
||||
$(SERVAL_BASE)instance.c \
|
||||
|
Loading…
x
Reference in New Issue
Block a user