slirp: improve a bit the debug macros

Let them accept multiple arguments. Simplify the inner argument
handling of DEBUG_ARGS/DEBUG_MISC_DEBUG_ERROR.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
master
Marc-André Lureau 2018-11-14 16:36:31 +04:00 committed by Samuel Thibault
parent 90dfa27841
commit 2afbb788ff
16 changed files with 109 additions and 85 deletions

View File

@ -34,9 +34,9 @@ void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN])
DEBUG_CALL("arp_table_add");
DEBUG_ARG("ip = %s", inet_ntoa((struct in_addr){.s_addr = ip_addr}));
DEBUG_ARGS((dfd, " hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
ethaddr[0], ethaddr[1], ethaddr[2],
ethaddr[3], ethaddr[4], ethaddr[5]));
DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
ethaddr[0], ethaddr[1], ethaddr[2],
ethaddr[3], ethaddr[4], ethaddr[5]);
if (ip_addr == 0 || ip_addr == 0xffffffff || ip_addr == broadcast_addr) {
/* Do not register broadcast addresses */
@ -79,9 +79,9 @@ bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
for (i = 0; i < ARP_TABLE_SIZE; i++) {
if (arptbl->table[i].ar_sip == ip_addr) {
memcpy(out_ethaddr, arptbl->table[i].ar_sha, ETH_ALEN);
DEBUG_ARGS((dfd, " found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
DEBUG_ARGS(" found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
return 1;
}
}

View File

@ -37,8 +37,7 @@
static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE };
#ifdef DEBUG
#define DPRINTF(fmt, ...) \
do if (slirp_debug & DBG_CALL) { fprintf(dfd, fmt, ## __VA_ARGS__); fflush(dfd); } while (0)
#define DPRINTF(fmt, ...) DEBUG_CALL(fmt, ##__VA_ARGS__)
#else
#define DPRINTF(fmt, ...) do{}while(0)
#endif

View File

@ -124,8 +124,8 @@ int cksum(struct mbuf *m, int len)
cont:
#ifdef DEBUG
if (len) {
DEBUG_ERROR((dfd, "cksum: out of data\n"));
DEBUG_ERROR((dfd, " len = %d\n", len));
DEBUG_ERROR("cksum: out of data\n");
DEBUG_ERROR(" len = %d\n", len);
}
#endif
if (mlen == -1) {

View File

@ -17,18 +17,45 @@
extern int slirp_debug;
#define DEBUG_CALL(x) if (slirp_debug & DBG_CALL) { fprintf(dfd, "%s...\n", x); fflush(dfd); }
#define DEBUG_ARG(x, y) if (slirp_debug & DBG_CALL) { fputc(' ', dfd); fprintf(dfd, x, y); fputc('\n', dfd); fflush(dfd); }
#define DEBUG_ARGS(x) if (slirp_debug & DBG_CALL) { fprintf x ; fflush(dfd); }
#define DEBUG_MISC(x) if (slirp_debug & DBG_MISC) { fprintf x ; fflush(dfd); }
#define DEBUG_ERROR(x) if (slirp_debug & DBG_ERROR) {fprintf x ; fflush(dfd); }
#define DEBUG_CALL(fmt, ...) do { \
if (slirp_debug & DBG_CALL) { \
fprintf(dfd, fmt, ##__VA_ARGS__); \
fprintf(dfd, "...\n"); \
fflush(dfd); \
} \
} while (0)
#define DEBUG_ARG(fmt, ...) do { \
if (slirp_debug & DBG_CALL) { \
fputc(' ', dfd); \
fprintf(dfd, fmt, ##__VA_ARGS__); \
fputc('\n', dfd); \
fflush(dfd); \
} \
} while (0)
#define DEBUG_ARGS(fmt, ...) DEBUG_ARG(fmt, ##__VA_ARGS__)
#define DEBUG_MISC(fmt, ...) do { \
if (slirp_debug & DBG_MISC) { \
fprintf(dfd, fmt, ##__VA_ARGS__); \
fflush(dfd); \
} \
} while (0)
#define DEBUG_ERROR(fmt, ...) do { \
if (slirp_debug & DBG_ERROR) { \
fprintf(dfd, fmt, ##__VA_ARGS__); \
fflush(dfd); \
} \
} while (0)
#else
#define DEBUG_CALL(x)
#define DEBUG_ARG(x, y)
#define DEBUG_ARGS(x)
#define DEBUG_MISC(x)
#define DEBUG_ERROR(x)
#define DEBUG_CALL(fmt, ...)
#define DEBUG_ARG(fmt, ...)
#define DEBUG_ARGS(fmt, ...)
#define DEBUG_MISC(fmt, ...)
#define DEBUG_ERROR(fmt, ...)
#endif

View File

@ -92,14 +92,14 @@ static int dhcpv6_parse_info_request(uint8_t *odata, int olen,
ri->want_boot_url = true;
break;
default:
DEBUG_MISC((dfd, "dhcpv6: Unsupported option request %d\n",
req_opt));
DEBUG_MISC("dhcpv6: Unsupported option request %d\n",
req_opt);
}
}
break;
default:
DEBUG_MISC((dfd, "dhcpv6 info req: Unsupported option %d, len=%d\n",
option, len));
DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d\n",
option, len);
}
odata += len + 4;
@ -203,7 +203,6 @@ void dhcpv6_input(struct sockaddr_in6 *srcsas, struct mbuf *m)
dhcpv6_info_request(m->slirp, srcsas, xid, &data[4], data_len - 4);
break;
default:
DEBUG_MISC((dfd, "dhcpv6_input: Unsupported message type 0x%x\n",
data[0]));
DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x\n", data[0]);
}
}

View File

@ -76,7 +76,7 @@ void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code)
struct ip6 *ip = mtod(m, struct ip6 *);
DEBUG_CALL("icmp6_send_error");
DEBUG_ARGS((dfd, " type = %d, code = %d\n", type, code));
DEBUG_ARGS(" type = %d, code = %d\n", type, code);
if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) ||
in6_zero(&ip->ip_src)) {

View File

@ -99,8 +99,8 @@ static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0,
(struct sockaddr *)&addr, sizeof(addr)) == -1) {
DEBUG_MISC((dfd, "icmp_input icmp sendto tx errno = %d-%s\n",
errno, strerror(errno)));
DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s\n",
errno, strerror(errno));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
icmp_detach(so);
}
@ -165,8 +165,8 @@ icmp_input(struct mbuf *m, int hlen)
return;
}
if (udp_attach(so, AF_INET) == -1) {
DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n",
errno,strerror(errno)));
DEBUG_MISC("icmp_input udp_attach errno = %d-%s\n",
errno,strerror(errno));
sofree(so);
m_free(m);
goto end_error;
@ -188,8 +188,8 @@ icmp_input(struct mbuf *m, int hlen)
if(sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0,
(struct sockaddr *)&addr, sockaddr_size(&addr)) == -1) {
DEBUG_MISC((dfd,"icmp_input udp sendto tx errno = %d-%s\n",
errno,strerror(errno)));
DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s\n",
errno,strerror(errno));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
udp_detach(so);
}
@ -257,7 +257,7 @@ icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
{ char bufa[20], bufb[20];
strcpy(bufa, inet_ntoa(ip->ip_src));
strcpy(bufb, inet_ntoa(ip->ip_dst));
DEBUG_MISC((dfd, " %.16s to %.16s\n", bufa, bufb));
DEBUG_MISC(" %.16s to %.16s\n", bufa, bufb);
}
#endif
if(ip->ip_off & IP_OFFMASK) goto end_error; /* Only reply to fragment 0 */
@ -457,8 +457,8 @@ void icmp_receive(struct socket *so)
} else {
error_code = ICMP_UNREACH_HOST;
}
DEBUG_MISC((dfd, " udp icmp rx errno = %d-%s\n", errno,
strerror(errno)));
DEBUG_MISC(" udp icmp rx errno = %d-%s\n", errno,
strerror(errno));
icmp_send_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno));
} else {
icmp_reflect(so->so_m);

View File

@ -232,7 +232,7 @@ dtom(Slirp *slirp, void *dat)
}
}
DEBUG_ERROR((dfd, "dtom failed"));
DEBUG_ERROR("dtom failed");
return (struct mbuf *)0;
}

View File

@ -19,9 +19,9 @@ void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr,
inet_ntop(AF_INET6, &(ip_addr), addrstr, INET6_ADDRSTRLEN);
DEBUG_ARG("ip = %s", addrstr);
#endif
DEBUG_ARGS((dfd, " hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
ethaddr[0], ethaddr[1], ethaddr[2],
ethaddr[3], ethaddr[4], ethaddr[5]));
DEBUG_ARGS(" hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
ethaddr[0], ethaddr[1], ethaddr[2],
ethaddr[3], ethaddr[4], ethaddr[5]);
if (IN6_IS_ADDR_MULTICAST(&ip_addr) || in6_zero(&ip_addr)) {
/* Do not register multicast or unspecified addresses */
@ -69,18 +69,18 @@ bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
out_ethaddr[3] = ip_addr.s6_addr[13];
out_ethaddr[4] = ip_addr.s6_addr[14];
out_ethaddr[5] = ip_addr.s6_addr[15];
DEBUG_ARGS((dfd, " multicast addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
DEBUG_ARGS(" multicast addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
return 1;
}
for (i = 0; i < NDP_TABLE_SIZE; i++) {
if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) {
memcpy(out_ethaddr, ndp_table->table[i].eth_addr, ETH_ALEN);
DEBUG_ARGS((dfd, " found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]));
DEBUG_ARGS(" found hw addr = %02x:%02x:%02x:%02x:%02x:%02x\n",
out_ethaddr[0], out_ethaddr[1], out_ethaddr[2],
out_ethaddr[3], out_ethaddr[4], out_ethaddr[5]);
return 1;
}
}

View File

@ -984,12 +984,12 @@ int if_encap(Slirp *slirp, struct mbuf *ifm)
}
memcpy(eh->h_dest, ethaddr, ETH_ALEN);
DEBUG_ARGS((dfd, " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
eh->h_source[0], eh->h_source[1], eh->h_source[2],
eh->h_source[3], eh->h_source[4], eh->h_source[5]));
DEBUG_ARGS((dfd, " dst = %02x:%02x:%02x:%02x:%02x:%02x\n",
eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]));
DEBUG_ARGS(" src = %02x:%02x:%02x:%02x:%02x:%02x\n",
eh->h_source[0], eh->h_source[1], eh->h_source[2],
eh->h_source[3], eh->h_source[4], eh->h_source[5]);
DEBUG_ARGS(" dst = %02x:%02x:%02x:%02x:%02x:%02x\n",
eh->h_dest[0], eh->h_dest[1], eh->h_dest[2],
eh->h_dest[3], eh->h_dest[4], eh->h_dest[5]);
memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len);
slirp->cb->output(slirp->opaque, buf, ifm->m_len + ETH_HLEN);
return 1;

View File

@ -208,7 +208,7 @@ soread(struct socket *so)
}
}
DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));
DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno));
sofcantrcvmore(so);
if (err == ECONNRESET || err == ECONNREFUSED
@ -237,7 +237,7 @@ soread(struct socket *so)
nn += ret;
}
DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
DEBUG_MISC(" ... read nn = %d bytes\n", nn);
/* Update fields */
sb->sb_cc += nn;
@ -370,7 +370,7 @@ sosendoob(struct socket *so)
n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */
#ifdef DEBUG
if (n != len) {
DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
DEBUG_ERROR("Didn't send all data urgently XXXXX\n");
}
#endif
}
@ -379,7 +379,7 @@ sosendoob(struct socket *so)
return n;
}
so->so_urgc -= n;
DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc);
sb->sb_cc -= n;
sb->sb_rptr += n;
@ -460,7 +460,7 @@ sowrite(struct socket *so)
if (ret > 0)
nn += ret;
}
DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn));
DEBUG_MISC(" ... wrote nn = %d bytes\n", nn);
/* Update sbuf */
sb->sb_cc -= nn;
@ -478,8 +478,8 @@ sowrite(struct socket *so)
return nn;
err_disconnected:
DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",
so->so_state, errno));
DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d\n",
so->so_state, errno);
sofcantsendmore(so);
tcp_sockclosed(sototcpcb(so));
return -1;
@ -512,8 +512,8 @@ sorecvfrom(struct socket *so)
if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET;
DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n",
errno,strerror(errno)));
DEBUG_MISC(" udp icmp rx errno = %d-%s\n",
errno,strerror(errno));
icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno));
} else {
icmp_reflect(so->so_m);
@ -564,8 +564,8 @@ sorecvfrom(struct socket *so)
m->m_len = recvfrom(so->s, m->m_data, len, 0,
(struct sockaddr *)&addr, &addrlen);
DEBUG_MISC((dfd, " did recvfrom %d, errno = %d-%s\n",
m->m_len, errno,strerror(errno)));
DEBUG_MISC(" did recvfrom %d, errno = %d-%s\n",
m->m_len, errno,strerror(errno));
if(m->m_len<0) {
/* Report error as ICMP */
switch (so->so_lfamily) {
@ -579,7 +579,7 @@ sorecvfrom(struct socket *so)
code = ICMP_UNREACH_NET;
}
DEBUG_MISC((dfd, " rx error, tx icmp ICMP_UNREACH:%i\n", code));
DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i\n", code);
icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno));
break;
case AF_INET6:
@ -591,7 +591,7 @@ sorecvfrom(struct socket *so)
code = ICMP6_UNREACH_NO_ROUTE;
}
DEBUG_MISC((dfd, " rx error, tx icmp6 ICMP_UNREACH:%i\n", code));
DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i\n", code);
icmp6_send_error(so->so_m, ICMP6_UNREACH, code);
break;
default:
@ -839,9 +839,9 @@ void sotranslate_out(struct socket *so, struct sockaddr_storage *addr)
}
}
DEBUG_MISC((dfd, " addr.sin_port=%d, "
"addr.sin_addr.s_addr=%.16s\n",
ntohs(sin->sin_port), inet_ntoa(sin->sin_addr)));
DEBUG_MISC(" addr.sin_port=%d, "
"addr.sin_addr.s_addr=%.16s\n",
ntohs(sin->sin_port), inet_ntoa(sin->sin_addr));
break;
case AF_INET6:

View File

@ -236,8 +236,8 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso, unsigned short af)
Slirp *slirp;
DEBUG_CALL("tcp_input");
DEBUG_ARGS((dfd, " m = %p iphlen = %2d inso = %p\n",
m, iphlen, inso));
DEBUG_ARGS(" m = %p iphlen = %2d inso = %p\n",
m, iphlen, inso);
/*
* If called with m == 0, then we're continuing the connect
@ -662,8 +662,8 @@ findso:
(errno != EINPROGRESS) && (errno != EWOULDBLOCK)
) {
uint8_t code;
DEBUG_MISC((dfd, " tcp fconnect errno = %d-%s\n",
errno,strerror(errno)));
DEBUG_MISC(" tcp fconnect errno = %d-%s\n",
errno,strerror(errno));
if(errno == ECONNREFUSED) {
/* ACK the SYN, send RST to refuse the connection */
tcp_respond(tp, ti, m, ti->ti_seq + 1, (tcp_seq) 0,
@ -1032,8 +1032,7 @@ trimthenstep6:
if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) {
if (ti->ti_len == 0 && tiwin == tp->snd_wnd) {
DEBUG_MISC((dfd, " dup ack m = %p so = %p\n",
m, so));
DEBUG_MISC(" dup ack m = %p so = %p\n", m, so);
/*
* If we have outstanding data (other than
* a window probe), this is a completely
@ -1411,7 +1410,7 @@ tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti)
int opt, optlen;
DEBUG_CALL("tcp_dooptions");
DEBUG_ARGS((dfd, " tp = %p cnt=%i\n", tp, cnt));
DEBUG_ARGS(" tp = %p cnt=%i\n", tp, cnt);
for (; cnt > 0; cnt -= optlen, cp += optlen) {
opt = cp[0];
@ -1611,7 +1610,7 @@ tcp_mss(struct tcpcb *tp, u_int offer)
(mss - (TCP_RCVSPACE % mss)) :
0));
DEBUG_MISC((dfd, " returning mss = %d\n", mss));
DEBUG_MISC(" returning mss = %d\n", mss);
return mss;
}

View File

@ -92,7 +92,7 @@ again:
flags = tcp_outflags[tp->t_state];
DEBUG_MISC((dfd, " --- tcp_output flags = 0x%x\n",flags));
DEBUG_MISC(" --- tcp_output flags = 0x%x\n", flags);
/*
* If in persist timeout with window of 0, send 1 byte.

View File

@ -420,7 +420,7 @@ int tcp_fconnect(struct socket *so, unsigned short af)
qemu_setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
addr = so->fhost.ss;
DEBUG_CALL(" connect()ing")
DEBUG_CALL(" connect()ing");
sotranslate_out(so, &addr);
/* We don't care what port we get */
@ -964,7 +964,7 @@ int tcp_ctl(struct socket *so)
so->chardev = ex_ptr->ex_chardev;
return 1;
}
DEBUG_MISC((dfd, " executing %s\n", ex_ptr->ex_exec));
DEBUG_MISC(" executing %s\n", ex_ptr->ex_exec);
return fork_exec(so, ex_ptr->ex_exec);
}
}

View File

@ -172,8 +172,8 @@ udp_input(register struct mbuf *m, int iphlen)
*/
so = socreate(slirp);
if (udp_attach(so, AF_INET) == -1) {
DEBUG_MISC((dfd," udp_attach errno = %d-%s\n",
errno,strerror(errno)));
DEBUG_MISC(" udp_attach errno = %d-%s\n",
errno, strerror(errno));
sofree(so);
goto bad;
}
@ -209,7 +209,7 @@ udp_input(register struct mbuf *m, int iphlen)
m->m_len += iphlen;
m->m_data -= iphlen;
*ip=save_ip;
DEBUG_MISC((dfd,"udp tx errno = %d-%s\n",errno,strerror(errno)));
DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno));
icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0,
strerror(errno));
goto bad;

View File

@ -92,8 +92,8 @@ void udp6_input(struct mbuf *m)
/* If there's no socket for this packet, create one. */
so = socreate(slirp);
if (udp_attach(so, AF_INET6) == -1) {
DEBUG_MISC((dfd, " udp6_attach errno = %d-%s\n",
errno, strerror(errno)));
DEBUG_MISC(" udp6_attach errno = %d-%s\n",
errno, strerror(errno));
sofree(so);
goto bad;
}
@ -119,7 +119,7 @@ void udp6_input(struct mbuf *m)
m->m_len += iphlen;
m->m_data -= iphlen;
*ip = save_ip;
DEBUG_MISC((dfd, "udp tx errno = %d-%s\n", errno, strerror(errno)));
DEBUG_MISC("udp tx errno = %d-%s\n", errno, strerror(errno));
icmp6_send_error(m, ICMP6_UNREACH, ICMP6_UNREACH_NO_ROUTE);
goto bad;
}