icmp: Flow based error reporting
Use flow_dbg() and flow_err() helpers to generate flow-linked error messages in most places. Make a few small improvements to the messages while we're at it. This allows us to avoid the awkward 'pname' variables since whether we're dealing with ICMP or ICMPv6 is already built into the flow type which these helpers include. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> [sbrivio: Coding style fix in icmp_tap_handler()] Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
3af5e9fdba
commit
02cbdb0b86
1 changed files with 12 additions and 14 deletions
26
icmp.c
26
icmp.c
|
@ -62,7 +62,6 @@ void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref)
|
||||||
{
|
{
|
||||||
struct icmp_ping_flow *pingf = af == AF_INET
|
struct icmp_ping_flow *pingf = af == AF_INET
|
||||||
? icmp_id_map[V4][ref.icmp.id] : icmp_id_map[V6][ref.icmp.id];
|
? icmp_id_map[V4][ref.icmp.id] : icmp_id_map[V6][ref.icmp.id];
|
||||||
const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6";
|
|
||||||
union sockaddr_inany sr;
|
union sockaddr_inany sr;
|
||||||
socklen_t sl = sizeof(sr);
|
socklen_t sl = sizeof(sr);
|
||||||
char buf[USHRT_MAX];
|
char buf[USHRT_MAX];
|
||||||
|
@ -76,8 +75,7 @@ void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref)
|
||||||
|
|
||||||
n = recvfrom(ref.fd, buf, sizeof(buf), 0, &sr.sa, &sl);
|
n = recvfrom(ref.fd, buf, sizeof(buf), 0, &sr.sa, &sl);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
warn("%s: recvfrom() error on ping socket: %s",
|
flow_err(pingf, "recvfrom() error: %s", strerror(errno));
|
||||||
pname, strerror(errno));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sr.sa_family != af)
|
if (sr.sa_family != af)
|
||||||
|
@ -114,8 +112,9 @@ void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref)
|
||||||
pingf->seq = seq;
|
pingf->seq = seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("%s: echo reply to tap, ID: %"PRIu16", seq: %"PRIu16, pname,
|
flow_dbg(pingf, "echo reply to tap, ID: %"PRIu16", seq: %"PRIu16,
|
||||||
ref.icmp.id, seq);
|
ref.icmp.id, seq);
|
||||||
|
|
||||||
if (af == AF_INET)
|
if (af == AF_INET)
|
||||||
tap_icmp4_send(c, sr.sa4.sin_addr, tap_ip4_daddr(c), buf, n);
|
tap_icmp4_send(c, sr.sa4.sin_addr, tap_ip4_daddr(c), buf, n);
|
||||||
else if (af == AF_INET6)
|
else if (af == AF_INET6)
|
||||||
|
@ -124,7 +123,7 @@ void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
unexpected:
|
unexpected:
|
||||||
warn("%s: Unexpected packet on ping socket", pname);
|
flow_err(pingf, "Unexpected packet on ping socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,7 +158,6 @@ static struct icmp_ping_flow *icmp_ping_new(const struct ctx *c,
|
||||||
struct icmp_ping_flow **id_sock,
|
struct icmp_ping_flow **id_sock,
|
||||||
sa_family_t af, uint16_t id)
|
sa_family_t af, uint16_t id)
|
||||||
{
|
{
|
||||||
const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6";
|
|
||||||
uint8_t flowtype = af == AF_INET ? FLOW_PING4 : FLOW_PING6;
|
uint8_t flowtype = af == AF_INET ? FLOW_PING4 : FLOW_PING6;
|
||||||
union icmp_epoll_ref iref = { .id = id };
|
union icmp_epoll_ref iref = { .id = id };
|
||||||
union flow *flow = flow_alloc();
|
union flow *flow = flow_alloc();
|
||||||
|
@ -196,9 +194,9 @@ static struct icmp_ping_flow *icmp_ping_new(const struct ctx *c,
|
||||||
if (pingf->sock > FD_REF_MAX)
|
if (pingf->sock > FD_REF_MAX)
|
||||||
goto cancel;
|
goto cancel;
|
||||||
|
|
||||||
*id_sock = pingf;
|
flow_dbg(pingf, "new socket %i for echo ID %"PRIu16, pingf->sock, id);
|
||||||
|
|
||||||
debug("%s: new socket %i for echo ID %"PRIu16, pname, pingf->sock, id);
|
*id_sock = pingf;
|
||||||
|
|
||||||
return pingf;
|
return pingf;
|
||||||
|
|
||||||
|
@ -223,7 +221,6 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
|
||||||
const void *saddr, const void *daddr,
|
const void *saddr, const void *daddr,
|
||||||
const struct pool *p, const struct timespec *now)
|
const struct pool *p, const struct timespec *now)
|
||||||
{
|
{
|
||||||
const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6";
|
|
||||||
union sockaddr_inany sa = { .sa_family = af };
|
union sockaddr_inany sa = { .sa_family = af };
|
||||||
const socklen_t sl = af == AF_INET ? sizeof(sa.sa4) : sizeof(sa.sa6);
|
const socklen_t sl = af == AF_INET ? sizeof(sa.sa4) : sizeof(sa.sa6);
|
||||||
struct icmp_ping_flow *pingf, **id_sock;
|
struct icmp_ping_flow *pingf, **id_sock;
|
||||||
|
@ -278,11 +275,12 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
|
||||||
pingf->ts = now->tv_sec;
|
pingf->ts = now->tv_sec;
|
||||||
|
|
||||||
if (sendto(pingf->sock, pkt, plen, MSG_NOSIGNAL, &sa.sa, sl) < 0) {
|
if (sendto(pingf->sock, pkt, plen, MSG_NOSIGNAL, &sa.sa, sl) < 0) {
|
||||||
debug("%s: failed to relay request to socket: %s",
|
flow_dbg(pingf, "failed to relay request to socket: %s",
|
||||||
pname, strerror(errno));
|
strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
debug("%s: echo request to socket, ID: %"PRIu16", seq: %"PRIu16,
|
flow_dbg(pingf,
|
||||||
pname, id, seq);
|
"echo request to socket, ID: %"PRIu16", seq: %"PRIu16,
|
||||||
|
id, seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue