qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH for-3.2 31/41] slirp: add a callback to log guest er


From: Marc-André Lureau
Subject: [Qemu-devel] [PATCH for-3.2 31/41] slirp: add a callback to log guest errors
Date: Wed, 14 Nov 2018 16:36:33 +0400

Signed-off-by: Marc-André Lureau <address@hidden>
---
 slirp/libslirp.h | 1 +
 net/slirp.c      | 7 +++++++
 slirp/dhcpv6.c   | 6 +++---
 slirp/ip6_icmp.c | 7 +++----
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index f2e7f94ebb..c7582e6516 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -21,6 +21,7 @@ typedef struct SlirpCb {
     void (*timer_free)(void *timer);
     void (*timer_mod)(void *timer, int64_t expire_timer);
     void (*set_nonblock)(int fd);
+    void (*guest_error)(const char *msg);
 } SlirpCb;
 
 
diff --git a/net/slirp.c b/net/slirp.c
index 5ea8c255f6..b36092c948 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/log.h"
 #include "net/slirp.h"
 
 
@@ -183,6 +184,11 @@ static void net_slirp_timer_mod(void *timer, int64_t 
expire_timer)
     timer_mod(timer, expire_timer);
 }
 
+static void net_slirp_guest_error(const char *msg)
+{
+    qemu_log_mask(LOG_GUEST_ERROR, "%s", msg);
+}
+
 static SlirpCb slirp_cb = {
     .output = net_slirp_output,
     .chr_write_all = net_slirp_chr_write_all,
@@ -191,6 +197,7 @@ static SlirpCb slirp_cb = {
     .timer_free = net_slirp_timer_free,
     .timer_mod = net_slirp_timer_mod,
     .set_nonblock = qemu_set_nonblock,
+    .guest_error = net_slirp_guest_error,
 };
 
 static int net_slirp_init(NetClientState *peer, const char *model,
diff --git a/slirp/dhcpv6.c b/slirp/dhcpv6.c
index 943a13bca8..5d703e8ae6 100644
--- a/slirp/dhcpv6.c
+++ b/slirp/dhcpv6.c
@@ -50,7 +50,7 @@ struct requested_infos {
  * the odata region, thus the caller must keep odata valid as long as it
  * needs to access the requested_infos struct.
  */
-static int dhcpv6_parse_info_request(uint8_t *odata, int olen,
+static int dhcpv6_parse_info_request(Slirp *slirp, uint8_t *odata, int olen,
                                      struct requested_infos *ri)
 {
     int i, req_opt;
@@ -61,7 +61,7 @@ static int dhcpv6_parse_info_request(uint8_t *odata, int olen,
         int len = odata[2] << 8 | odata[3];
 
         if (len + 4 > olen) {
-            qemu_log_mask(LOG_GUEST_ERROR, "Guest sent bad DHCPv6 packet!\n");
+            slirp->cb->guest_error("Guest sent bad DHCPv6 packet!");
             return -E2BIG;
         }
 
@@ -121,7 +121,7 @@ static void dhcpv6_info_request(Slirp *slirp, struct 
sockaddr_in6 *srcsas,
     struct mbuf *m;
     uint8_t *resp;
 
-    if (dhcpv6_parse_info_request(odata, olen, &ri) < 0) {
+    if (dhcpv6_parse_info_request(slirp, odata, olen, &ri) < 0) {
         return;
     }
 
diff --git a/slirp/ip6_icmp.c b/slirp/ip6_icmp.c
index 6f20190a0a..d523852a1f 100644
--- a/slirp/ip6_icmp.c
+++ b/slirp/ip6_icmp.c
@@ -343,8 +343,7 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, struct 
ip6 *ip,
 
     case ICMP6_NDP_RA:
         DEBUG_CALL(" type = Router Advertisement");
-        qemu_log_mask(LOG_GUEST_ERROR,
-                "Warning: guest sent NDP RA, but shouldn't");
+        slirp->cb->guest_error("Warning: guest sent NDP RA, but shouldn't");
         break;
 
     case ICMP6_NDP_NS:
@@ -377,8 +376,8 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, struct 
ip6 *ip,
 
     case ICMP6_NDP_REDIRECT:
         DEBUG_CALL(" type = Redirect");
-        qemu_log_mask(LOG_GUEST_ERROR,
-                "Warning: guest sent NDP REDIRECT, but shouldn't");
+        slirp->cb->guest_error(
+            "Warning: guest sent NDP REDIRECT, but shouldn't");
         break;
     }
 }
-- 
2.19.1.708.g4ede3d42df




reply via email to

[Prev in Thread] Current Thread [Next in Thread]