diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2021-08-12 15:42:43 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2021-09-01 17:00:27 +0200 |
commit | 1e49d194d01788afbc4b8216e27c794651a4facf (patch) | |
tree | 3397d4b687a74fe9552e057138c3a795917a5afa /util.c | |
parent | 1b1b27c06a27067a7d7a380f1df545e72268c411 (diff) | |
download | passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar.gz passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar.bz2 passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar.lz passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar.xz passt-1e49d194d01788afbc4b8216e27c794651a4facf.tar.zst passt-1e49d194d01788afbc4b8216e27c794651a4facf.zip |
passt, pasta: Introduce command-line options and port re-mapping
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 47 |
1 files changed, 23 insertions, 24 deletions
@@ -36,7 +36,6 @@ #include "util.h" #include "passt.h" -#ifdef DEBUG #define logfn(name, level) \ void name(const char *format, ...) { \ char ts[sizeof("Mmm dd hh:mm:ss.")]; \ @@ -44,37 +43,33 @@ void name(const char *format, ...) { \ struct tm *tm; \ va_list args; \ \ - clock_gettime(CLOCK_REALTIME, &tp); \ - tm = gmtime(&tp.tv_sec); \ - strftime(ts, sizeof(ts), "%b %d %T.", tm); \ + if (setlogmask(0) & LOG_MASK(LOG_DEBUG)) { \ + clock_gettime(CLOCK_REALTIME, &tp); \ + tm = gmtime(&tp.tv_sec); \ + strftime(ts, sizeof(ts), "%b %d %T.", tm); \ \ - fprintf(stderr, "%s%04lu: ", ts, tp.tv_nsec / (100 * 1000)); \ - va_start(args, format); \ - vsyslog(level, format, args); \ - va_end(args); \ - va_start(args, format); \ - vfprintf(stderr, format, args); \ - va_end(args); \ - if (format[strlen(format)] != '\n') \ - fprintf(stderr, "\n"); \ -} -#else -#define logfn(name, level) \ -void name(const char *format, ...) { \ - va_list args; \ + fprintf(stderr, "%s%04lu: ", ts, \ + tp.tv_nsec / (100 * 1000)); \ + } \ \ va_start(args, format); \ vsyslog(level, format, args); \ va_end(args); \ + \ + if (setlogmask(0) & LOG_MASK(LOG_DEBUG) || \ + setlogmask(0) == LOG_MASK(LOG_EMERG)) { \ + va_start(args, format); \ + vfprintf(stderr, format, args); \ + va_end(args); \ + if (format[strlen(format)] != '\n') \ + fprintf(stderr, "\n"); \ + } \ } -#endif logfn(err, LOG_ERR) logfn(warn, LOG_WARNING) logfn(info, LOG_INFO) -#ifdef DEBUG logfn(debug, LOG_DEBUG) -#endif /** * ipv6_l4hdr() - Find pointer to L4 header in IPv6 packet and extract protocol @@ -171,12 +166,16 @@ int sock_l4(struct ctx *c, int af, uint8_t proto, uint16_t port, sa = (const struct sockaddr *)&addr4; sl = sizeof(addr4); } else { - if (bind_addr == BIND_LOOPBACK) + if (bind_addr == BIND_LOOPBACK) { addr6.sin6_addr = in6addr_loopback; - else if (bind_addr == BIND_EXT) + } else if (bind_addr == BIND_EXT) { addr6.sin6_addr = c->addr6; - else + } else if (bind_addr == BIND_LL) { + addr6.sin6_addr = c->addr6_ll; + addr6.sin6_scope_id = if_nametoindex(c->ifn); + } else { addr6.sin6_addr = in6addr_any; + } sa = (const struct sockaddr *)&addr6; sl = sizeof(addr6); |