Commit 226ea7a9 authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Samuel Thibault
Browse files

slirp: call into g_debug() for DEBUG macros



Make slirp use GLib logging, instead of fprintf(), so that
applications can filter log, process it etc.

With recent versions of glib, G_MESSAGES_DEBUG must be set to "all" or
"Slirp" to see slirp debug messages.

Reformat DEBUG_MISC & DEBUG_ERROR calls to not need \n ending.

Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: default avatarSamuel Thibault <samuel.thibault@ens-lyon.org>
parent 2a2d3e4a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -121,8 +121,8 @@ int cksum(struct mbuf *m, int len)

cont:
	if (len) {
		DEBUG_ERROR("cksum: out of data\n");
		DEBUG_ERROR(" len = %d\n", len);
		DEBUG_ERROR("cksum: out of data");
		DEBUG_ERROR(" len = %d", len);
	}
	if (mlen == -1) {
		/* The last mbuf has odd # of bytes. Follow the
+4 −13
Original line number Diff line number Diff line
@@ -12,38 +12,29 @@
#define DBG_MISC 0x2
#define DBG_ERROR 0x4

#define dfd stderr

extern int slirp_debug;

#define DEBUG_CALL(fmt, ...) do {               \
    if (slirp_debug & DBG_CALL) {               \
        fprintf(dfd, fmt, ##__VA_ARGS__);       \
        fprintf(dfd, "...\n");                  \
        fflush(dfd);                            \
        g_debug(fmt "...", ##__VA_ARGS__);      \
    }                                           \
} while (0)

#define DEBUG_ARG(fmt, ...) do {                \
    if (slirp_debug & DBG_CALL) {               \
        fputc(' ', dfd);                        \
        fprintf(dfd, fmt, ##__VA_ARGS__);       \
        fputc('\n', dfd);                       \
        fflush(dfd);                            \
        g_debug(" " fmt, ##__VA_ARGS__);        \
    }                                           \
} while (0)

#define DEBUG_MISC(fmt, ...) do {               \
    if (slirp_debug & DBG_MISC) {               \
        fprintf(dfd, fmt, ##__VA_ARGS__);       \
        fflush(dfd);                            \
        g_debug(fmt, ##__VA_ARGS__);            \
    }                                           \
} while (0)

#define DEBUG_ERROR(fmt, ...) do {              \
    if (slirp_debug & DBG_ERROR) {              \
        fprintf(dfd, fmt, ##__VA_ARGS__);       \
        fflush(dfd);                            \
        g_debug(fmt, ##__VA_ARGS__);            \
    }                                           \
} while (0)

+3 −3
Original line number Diff line number Diff line
@@ -92,13 +92,13 @@ static int dhcpv6_parse_info_request(Slirp *slirp, uint8_t *odata, int olen,
                    ri->want_boot_url = true;
                    break;
                default:
                    DEBUG_MISC("dhcpv6: Unsupported option request %d\n",
                    DEBUG_MISC("dhcpv6: Unsupported option request %d",
                               req_opt);
                }
            }
            break;
        default:
            DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d\n",
            DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d",
                       option, len);
        }

@@ -203,6 +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("dhcpv6_input: Unsupported message type 0x%x\n", data[0]);
        DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x", data[0]);
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ 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("icmp_input icmp sendto tx errno = %d-%s\n",
        DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s",
                   errno, strerror(errno));
        icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
        icmp_detach(so);
@@ -169,7 +169,7 @@ icmp_input(struct mbuf *m, int hlen)
        return;
      }
      if (udp_attach(so, AF_INET) == -1) {
	DEBUG_MISC("icmp_input udp_attach errno = %d-%s\n",
	DEBUG_MISC("icmp_input udp_attach errno = %d-%s",
               errno,strerror(errno));
	sofree(so);
	m_free(m);
@@ -192,7 +192,7 @@ 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("icmp_input udp sendto tx errno = %d-%s\n",
	DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s",
               errno,strerror(errno));
	icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
	udp_detach(so);
@@ -261,7 +261,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(" %.16s to %.16s\n", bufa, bufb);
    DEBUG_MISC(" %.16s to %.16s", bufa, bufb);
  }
  if(ip->ip_off & IP_OFFMASK) goto end_error;    /* Only reply to fragment 0 */

@@ -458,7 +458,7 @@ void icmp_receive(struct socket *so)
        } else {
            error_code = ICMP_UNREACH_HOST;
        }
        DEBUG_MISC(" udp icmp rx errno = %d-%s\n", errno,
        DEBUG_MISC(" udp icmp rx errno = %d-%s", errno,
                   strerror(errno));
        icmp_send_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno));
    } else {
+4 −6
Original line number Diff line number Diff line
@@ -188,8 +188,6 @@ static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr,
                    *scope_id = if_index;
                }
                *cached_time = curtime;
            } else {
                DEBUG_MISC(", ");
            }

            if (++found > 3) {
Loading