Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Feature: make log contain source address of unknown site
So far, log would contain just the (reasonably unique) identifier
of the astray originator, but it's hard or downright impossible
to unambiguously recover the original address just with this piece
of knowledge.  Hence to allow for convenient tracking such cases
down, log also the source address if possible.

Technically, we are abusing the fact that said identifiers are supposed
to be non-negative (most significant bit set to zero) while the proper
OK state is indicated with zero and proper error condition mostly with
negative integers.  So these identifiers fit nicely into the positive
integer area, except for:
- zero identifier <-- we flip all the bits but MSB to 1 in this case
- malformed identifiers with MSB=1 <-- we flip MSB to 0

Also, we make sure that remaining error conditions not following the
rule and being indicated with positive integers are now indicated
with negative ones.

This convention is also mentioned in the function declaration's comment.
  • Loading branch information
jnpkrn committed Jun 16, 2016
commit 3b0bc3ae5939b021b69579c009e03f9a5fee23cd
2 changes: 1 addition & 1 deletion src/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ int attr_recv(void *buf, struct booth_site *source)
log_warn("got invalid ticket name %s from %s",
msg->attr.tkt_id, site_string(source));
source->invalid_cnt++;
return 1;
return -1;
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/raft.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,13 @@ static int process_REVOKE (
tk_log_error("%s wants to revoke ticket, "
"but it is not granted there (ignoring)",
site_string(sender));
return 1;
return -1;
} else if (tk->state != ST_FOLLOWER) {
tk_log_error("unexpected ticket revoke from %s "
"(in state %s) (ignoring)",
site_string(sender),
state_to_string(tk->state));
return 1;
return -1;
} else {
tk_log_info("%s revokes ticket",
site_string(tk->leader));
Expand Down
27 changes: 22 additions & 5 deletions src/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h> /* getnameinfo */
#include <poll.h>
#include <arpa/inet.h>
#include <asm/types.h>
#include <linux/rtnetlink.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h> /* getnameinfo */
#include "b_config.h"
#include "attr.h"
#include "auth.h"
Expand All @@ -50,7 +52,12 @@

struct booth_site *local = NULL;


/* function to be called when handling booth-group-internal messages;
* it's expected to return 0 to indicate success, negative integer
* to indicate silent (or possibly already complained about) error,
* or positive integer to indicate sender's ID that will then be
* emitted in the error log message together with the real source
* address if this is available */
static int (*deliver_fn) (void *msg, int msglen);


Expand Down Expand Up @@ -779,7 +786,15 @@ static void process_recv(int ci)
if (rv == -1)
return;

deliver_fn((void*)msg, rv);
rv = deliver_fn((void*)msg, rv);
if (rv > 0) {
if (getnameinfo((struct sockaddr *)&sa, sa_len,
buffer, sizeof(buffer), NULL, 0,
NI_NUMERICHOST) == 0)
log_error("unknown sender: %08x (real: %s)", rv, buffer);
else
log_error("unknown sender: %08x", rv);
}
}

static int booth_udp_init(void *f)
Expand Down Expand Up @@ -1051,7 +1066,7 @@ int send_header_plus(int fd, struct boothc_hdr_msg *msg, void *data, int len)
return rv;
}

/* UDP message receiver. */
/* UDP message receiver (see also deliver_fn declaration's comment) */
int message_recv(void *msg, int msglen)
{
uint32_t from;
Expand All @@ -1062,8 +1077,10 @@ int message_recv(void *msg, int msglen)

from = ntohl(header->from);
if (!find_site_by_id(from, &source)) {
log_error("unknown sender: %08x", from);
return -1;
/* caller knows the actual source address, pass
the (assuredly) positive number and let it report */
from = from ? from : ~from; /* avoid 0 (success) */
return from & (~0U >> 1); /* avoid negative (error code} */
}

time(&source->last_recv);
Expand Down