Enable the VLAN mtu capability and check for the adjusted packet size

(Jean-Jacques.Puig at espci.fr).
Factor out the packet-size checking function for clarity.
This commit is contained in:
christos 2015-11-19 17:01:40 +00:00
parent 88b3ee5eb5
commit 2b793cea0d
2 changed files with 30 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_xennet_xenbus.c,v 1.64 2015/04/13 21:18:40 riastradh Exp $ */
/* $NetBSD: if_xennet_xenbus.c,v 1.65 2015/11/19 17:01:40 christos Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@ -85,7 +85,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.64 2015/04/13 21:18:40 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_xennet_xenbus.c,v 1.65 2015/11/19 17:01:40 christos Exp $");
#include "opt_xen.h"
#include "opt_nfs_boot.h"
@ -362,6 +362,7 @@ xennet_xenbus_attach(device_t parent, device_t self, void *aux)
ether_sprintf(sc->sc_enaddr));
/* Initialize ifnet structure and attach interface */
strlcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
ifp->if_softc = sc;
ifp->if_start = xennet_start;
ifp->if_ioctl = xennet_ioctl;

View File

@ -1,4 +1,4 @@
/* $NetBSD: xennetback_xenbus.c,v 1.52 2013/10/20 11:37:53 bouyer Exp $ */
/* $NetBSD: xennetback_xenbus.c,v 1.53 2015/11/19 17:01:40 christos Exp $ */
/*
* Copyright (c) 2006 Manuel Bouyer.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.52 2013/10/20 11:37:53 bouyer Exp $");
__KERNEL_RCSID(0, "$NetBSD: xennetback_xenbus.c,v 1.53 2015/11/19 17:01:40 christos Exp $");
#include "opt_xen.h"
@ -301,6 +301,7 @@ xennetback_xenbus_create(struct xenbus_device *xbusd)
/* create pseudo-interface */
aprint_verbose_ifnet(ifp, "Ethernet address %s\n",
ether_sprintf(xneti->xni_enaddr));
xneti->xni_ec.ec_capabilities |= ETHERCAP_VLAN_MTU;
ifp->if_flags =
IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST;
ifp->if_snd.ifq_maxlen =
@ -710,6 +711,23 @@ xennetback_tx_response(struct xnetback_instance *xneti, int id, int status)
}
}
static inline const char *
xennetback_tx_check_packet(const netif_tx_request_t *txreq, int vlan)
{
if (__predict_false(txreq->size < ETHER_HDR_LEN))
return "too small";
if (__predict_false(txreq->offset + txreq->size > PAGE_SIZE))
return "crossing a page boundary";
const int maxlen =
vlan ? (ETHER_VLAN_ENCAP_LEN + ETHER_MAX_LEN) : ETHER_MAX_LEN;
if (__predict_false(txreq->size > maxlen))
return "too big";
return NULL;
}
static int
xennetback_evthandler(void *arg)
{
@ -745,28 +763,21 @@ xennetback_evthandler(void *arg)
NETIF_RSP_DROPPED);
continue;
}
/*
* Do some sanity checks, and map the packet's page.
*/
if (__predict_false(txreq->size < ETHER_HDR_LEN ||
txreq->size > (ETHER_MAX_LEN - ETHER_CRC_LEN))) {
printf("%s: packet size %d too big\n",
ifp->if_xname, txreq->size);
xennetback_tx_response(xneti, txreq->id,
NETIF_RSP_ERROR);
ifp->if_ierrors++;
continue;
}
/* don't cross page boundaries */
if (__predict_false(
txreq->offset + txreq->size > PAGE_SIZE)) {
printf("%s: packet cross page boundary\n",
ifp->if_xname);
const char *msg = xennetback_tx_check_packet(txreq,
xneti->xni_ec.ec_capenable & ETHERCAP_VLAN_MTU);
if (msg) {
printf("%s: packet with size %d is %s\n",
ifp->if_xname, txreq->size, msg);
xennetback_tx_response(xneti, txreq->id,
NETIF_RSP_ERROR);
ifp->if_ierrors++;
continue;
}
/* get a mbuf for this packet */
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (__predict_false(m == NULL)) {