Skip to content

Commit

Permalink
Improve babel_send() error handling
Browse files Browse the repository at this point in the history
- Print EDESTADDREQ only once per interface down/up cycle
- Include destination address in error message
  • Loading branch information
DanielG committed Jul 21, 2023
1 parent ef3eb65 commit d88c465
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ interface_updown(struct interface *ifp, int up)
ifp->numll = 0;
}

ifp->flags &= ~IF_EDESTADDRREQ_SEEN;

local_notify_interface(ifp, LOCAL_CHANGE);

return 1;
Expand Down
2 changes: 2 additions & 0 deletions interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ struct interface_conf {
#define IF_DTLS (1 << 9)
/* Announce v4-via-v6 routes through this interface. */
#define IF_V4VIAV6 (1 << 10)
/* Whether we've printed an error for EDESTADDRREQ already */
#define IF_EDESTADDRREQ_SEEN (1 << 11)

/* Only INTERFERING can appear on the wire. */
#define IF_CHANNEL_UNKNOWN 0
Expand Down
20 changes: 18 additions & 2 deletions message.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ THE SOFTWARE.
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <errno.h>
#include <inttypes.h>

#include "babeld.h"
#include "util.h"
Expand Down Expand Up @@ -1153,8 +1155,22 @@ flushbuf(struct buffered *buf, struct interface *ifp)
buf->buf, end,
(struct sockaddr*)&buf->sin6,
sizeof(buf->sin6));
if(rc < 0)
perror("send");
if(rc < 0) {
char *suppressed = "";
if (errno == EDESTADDRREQ) {
if (ifp->flags & IF_EDESTADDRREQ_SEEN)
goto suppress_send_error;
ifp->flags |= IF_EDESTADDRREQ_SEEN;
suppressed = " (suppressed)";
}

fprintf(stderr, "send(%s%%%" PRIu32 "): %s%s\n",
format_address((unsigned char*)&buf->sin6.sin6_addr),
buf->sin6.sin6_scope_id,
strerror(errno),
suppressed);
}
suppress_send_error:
}
VALGRIND_MAKE_MEM_UNDEFINED(buf->buf, buf->size);
buf->len = 0;
Expand Down

0 comments on commit d88c465

Please sign in to comment.