summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-01-26 09:36:50 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-01-26 09:36:50 +0100
commitda31c063de92d725bf706bb8ed7a79f9e03f8755 (patch)
tree18cf0a06872f7a746c9290296d3dad94489bf8d2 /src
parent534ae7240bc5cad6edb9fd160cdb0ff0eb4778de (diff)
downloadfastd-da31c063de92d725bf706bb8ed7a79f9e03f8755.tar
fastd-da31c063de92d725bf706bb8ed7a79f9e03f8755.zip
Nicer log message on failed link-local binds
Diffstat (limited to 'src')
-rw-r--r--src/log.c21
-rw-r--r--src/socket.c5
2 files changed, 16 insertions, 10 deletions
diff --git a/src/log.c b/src/log.c
index fb3a8af..3e9199a 100644
--- a/src/log.c
+++ b/src/log.c
@@ -44,7 +44,7 @@ static inline size_t snprintf_safe(char *buffer, size_t size, const char *format
return min_size_t(ret, size);
}
-static size_t snprint_peer_address(const fastd_context_t *ctx, char *buffer, size_t size, const fastd_peer_address_t *address, bool bind_address) {
+static size_t snprint_peer_address(const fastd_context_t *ctx, char *buffer, size_t size, const fastd_peer_address_t *address, const char *iface, bool bind_address) {
char addr_buf[INET6_ADDRSTRLEN] = "";
switch (address->sa.sa_family) {
@@ -66,13 +66,14 @@ static size_t snprint_peer_address(const fastd_context_t *ctx, char *buffer, siz
if (!bind_address && ctx->conf->hide_ip_addresses)
return snprintf_safe(buffer, size, "[hidden]:%u", ntohs(address->in.sin_port));
if (inet_ntop(AF_INET6, &address->in6.sin6_addr, addr_buf, sizeof(addr_buf))) {
- if (IN6_IS_ADDR_LINKLOCAL(&address->in6.sin6_addr)) {
- char ifname_buf[IF_NAMESIZE];
- if (if_indextoname(address->in6.sin6_scope_id, ifname_buf))
- return snprintf_safe(buffer, size, "[%s%%%s]:%u", addr_buf, if_indextoname(address->in6.sin6_scope_id, ifname_buf), ntohs(address->in6.sin6_port));
- }
+ char ifname_buf[IF_NAMESIZE];
+ if (!iface && IN6_IS_ADDR_LINKLOCAL(&address->in6.sin6_addr))
+ iface = if_indextoname(address->in6.sin6_scope_id, ifname_buf);
- return snprintf_safe(buffer, size, "[%s]:%u", addr_buf, ntohs(address->in6.sin6_port));
+ if (iface)
+ return snprintf_safe(buffer, size, "[%s%%%s]:%u", addr_buf, iface, ntohs(address->in6.sin6_port));
+ else
+ return snprintf_safe(buffer, size, "[%s]:%u", addr_buf, ntohs(address->in6.sin6_port));
}
else
return 0;
@@ -103,6 +104,7 @@ static int fastd_vsnprintf(const fastd_context_t *ctx, char *buffer, size_t size
for (; *format; format++) {
const void *p;
+ const char *iface;
const fastd_eth_addr_t *eth_addr;
if (buffer >= buffer_end)
@@ -164,10 +166,13 @@ static int fastd_vsnprintf(const fastd_context_t *ctx, char *buffer, size_t size
case 'I':
case 'B':
+ case 'L':
p = va_arg(ap, const fastd_peer_address_t*);
+ iface = (*format == 'L') ? va_arg(ap, const char*) : NULL;
+
if (p)
- buffer += snprint_peer_address(ctx, buffer, buffer_end-buffer, (const fastd_peer_address_t*)p, *format == 'B');
+ buffer += snprint_peer_address(ctx, buffer, buffer_end-buffer, (const fastd_peer_address_t*)p, iface, *format != 'I');
else
buffer += snprintf_safe(buffer, buffer_end-buffer, "(null)");
break;
diff --git a/src/socket.c b/src/socket.c
index 25f50e7..a9e6f33 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -114,7 +114,8 @@ static int bind_socket(fastd_context_t *ctx, const fastd_bind_address_t *addr, b
bind_address.in6.sin6_scope_id = if_nametoindex(addr->bindtodev);
if (!bind_address.in6.sin6_scope_id) {
- pr_warn_errno(ctx, "if_nametoindex");
+ if (warn)
+ pr_warn_errno(ctx, "if_nametoindex");
goto error;
}
}
@@ -145,7 +146,7 @@ static int bind_socket(fastd_context_t *ctx, const fastd_bind_address_t *addr, b
if (warn) {
if (addr->bindtodev)
- pr_warn(ctx, "unable to bind to %B on `%s'", &addr->addr, addr->bindtodev);
+ pr_warn(ctx, fastd_peer_address_is_v6_ll(&addr->addr) ? "unable to bind to %L" : "unable to bind to %B on `%s'", &addr->addr, addr->bindtodev);
else
pr_warn(ctx, "unable to bind to %B", &addr->addr);
}