slirp: add a callback to log guest errors
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
This commit is contained in:
parent
2afbb788ff
commit
2addc8fb6d
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
|
#include "qemu/log.h"
|
||||||
#include "net/slirp.h"
|
#include "net/slirp.h"
|
||||||
|
|
||||||
|
|
||||||
@ -140,8 +141,14 @@ static NetClientInfo net_slirp_info = {
|
|||||||
.cleanup = net_slirp_cleanup,
|
.cleanup = net_slirp_cleanup,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void net_slirp_guest_error(const char *msg)
|
||||||
|
{
|
||||||
|
qemu_log_mask(LOG_GUEST_ERROR, "%s", msg);
|
||||||
|
}
|
||||||
|
|
||||||
static const SlirpCb slirp_cb = {
|
static const SlirpCb slirp_cb = {
|
||||||
.output = net_slirp_output,
|
.output = net_slirp_output,
|
||||||
|
.guest_error = net_slirp_guest_error,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int net_slirp_init(NetClientState *peer, const char *model,
|
static int net_slirp_init(NetClientState *peer, const char *model,
|
||||||
|
@ -50,7 +50,7 @@ struct requested_infos {
|
|||||||
* the odata region, thus the caller must keep odata valid as long as it
|
* the odata region, thus the caller must keep odata valid as long as it
|
||||||
* needs to access the requested_infos struct.
|
* 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)
|
struct requested_infos *ri)
|
||||||
{
|
{
|
||||||
int i, req_opt;
|
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];
|
int len = odata[2] << 8 | odata[3];
|
||||||
|
|
||||||
if (len + 4 > olen) {
|
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;
|
return -E2BIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ static void dhcpv6_info_request(Slirp *slirp, struct sockaddr_in6 *srcsas,
|
|||||||
struct mbuf *m;
|
struct mbuf *m;
|
||||||
uint8_t *resp;
|
uint8_t *resp;
|
||||||
|
|
||||||
if (dhcpv6_parse_info_request(odata, olen, &ri) < 0) {
|
if (dhcpv6_parse_info_request(slirp, odata, olen, &ri) < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,8 +342,7 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
|
|||||||
|
|
||||||
case ICMP6_NDP_RA:
|
case ICMP6_NDP_RA:
|
||||||
DEBUG_CALL(" type = Router Advertisement");
|
DEBUG_CALL(" type = Router Advertisement");
|
||||||
qemu_log_mask(LOG_GUEST_ERROR,
|
slirp->cb->guest_error("Warning: guest sent NDP RA, but shouldn't");
|
||||||
"Warning: guest sent NDP RA, but shouldn't");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ICMP6_NDP_NS:
|
case ICMP6_NDP_NS:
|
||||||
@ -376,7 +375,7 @@ static void ndp_input(struct mbuf *m, Slirp *slirp, struct ip6 *ip,
|
|||||||
|
|
||||||
case ICMP6_NDP_REDIRECT:
|
case ICMP6_NDP_REDIRECT:
|
||||||
DEBUG_CALL(" type = Redirect");
|
DEBUG_CALL(" type = Redirect");
|
||||||
qemu_log_mask(LOG_GUEST_ERROR,
|
slirp->cb->guest_error(
|
||||||
"Warning: guest sent NDP REDIRECT, but shouldn't");
|
"Warning: guest sent NDP REDIRECT, but shouldn't");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ typedef struct Slirp Slirp;
|
|||||||
typedef struct SlirpCb {
|
typedef struct SlirpCb {
|
||||||
/* Send an ethernet frame to the guest network. */
|
/* Send an ethernet frame to the guest network. */
|
||||||
void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
|
void (*output)(void *opaque, const uint8_t *pkt, int pkt_len);
|
||||||
|
/* Print a message for an error due to guest misbehavior. */
|
||||||
|
void (*guest_error)(const char *msg);
|
||||||
} SlirpCb;
|
} SlirpCb;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user