Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-3]: src/sys/arch/xen/xen Pull up following revision(s) (requested...
details: https://anonhg.NetBSD.org/src/rev/57f6a7f012c0
branches: netbsd-3
changeset: 577805:57f6a7f012c0
user: riz <riz%NetBSD.org@localhost>
date: Sun Feb 05 17:02:11 2006 +0000
description:
Pull up following revision(s) (requested by bouyer in ticket #1155):
sys/arch/xen/xen/if_xennet.c: revision 1.42 via patch
sys/arch/xen/xen/xennetback.c: revision 1.20 via patch
Check the destination ethernet address when not in promiscous mode.
Fix problem where packets would be duplicated, possibly looping, when
a domU is doing IP routing.
Problem reported and fix tested by Mike M. Volokhov on port-xen
While there, add some __predict_false/true in conditionnals where
appropriate, remove a always-true test, and fix handling of
mbuf shortage.
diffstat:
sys/arch/xen/xen/if_xennet.c | 46 ++++++++++++++++++++++++++----------------
sys/arch/xen/xen/xennetback.c | 34 ++++++++++++++++++++++---------
2 files changed, 52 insertions(+), 28 deletions(-)
diffs (184 lines):
diff -r 17d6dc7d3fbe -r 57f6a7f012c0 sys/arch/xen/xen/if_xennet.c
--- a/sys/arch/xen/xen/if_xennet.c Fri Feb 03 05:25:03 2006 +0000
+++ b/sys/arch/xen/xen/if_xennet.c Sun Feb 05 17:02:11 2006 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_xennet.c,v 1.13.2.20 2006/02/01 20:45:34 tron Exp $ */
+/* $NetBSD: if_xennet.c,v 1.13.2.21 2006/02/05 17:02:11 riz Exp $ */
/*
*
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_xennet.c,v 1.13.2.20 2006/02/01 20:45:34 tron Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_xennet.c,v 1.13.2.21 2006/02/05 17:02:11 riz Exp $");
#include "opt_inet.h"
#include "opt_nfs_boot.h"
@@ -638,6 +638,7 @@
mmu_update_t *mmu = rx_mmu;
multicall_entry_t *mcl = rx_mcl;
struct mbuf *m;
+ void *pktp;
network_tx_buf_gc(sc);
ifp->if_flags &= ~IFF_OACTIVE;
@@ -660,7 +661,7 @@
/* XXXcl check rx->status for error */
MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m == NULL) {
+ if (__predict_false(m == NULL)) {
printf("xennet: rx no mbuf\n");
break;
}
@@ -687,14 +688,12 @@
/* Do all the remapping work, and M->P updates, in one
* big hypercall. */
- if ((mcl - rx_mcl) != 0) {
- mcl->op = __HYPERVISOR_mmu_update;
- mcl->args[0] = (unsigned long)rx_mmu;
- mcl->args[1] = mmu - rx_mmu;
- mcl->args[2] = 0;
- mcl++;
- (void)HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl);
- }
+ mcl->op = __HYPERVISOR_mmu_update;
+ mcl->args[0] = (unsigned long)rx_mmu;
+ mcl->args[1] = mmu - rx_mmu;
+ mcl->args[2] = 0;
+ mcl++;
+ (void)HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl);
if (0)
printf("page mapped at va %08lx -> %08x/%08lx\n",
sc->sc_rx_bufa[rx->id].xb_rx.xbrx_va,
@@ -711,11 +710,23 @@
(void *)(PTE_BASE[x86_btop
(sc->sc_rx_bufa[rx->id].xb_rx.xbrx_va)] & PG_FRAME)));
+ pktp = (void *)(sc->sc_rx_bufa[rx->id].xb_rx.xbrx_va +
+ (rx->addr & PAGE_MASK));
+ if ((ifp->if_flags & IFF_PROMISC) == 0) {
+ struct ether_header *eh = pktp;
+ if (ETHER_IS_MULTICAST(eh->ether_dhost) == 0 &&
+ memcmp(LLADDR(ifp->if_sadl), eh->ether_dhost,
+ ETHER_ADDR_LEN) != 0) {
+ xennet_rx_push_buffer(sc, rx->id);
+ m_freem(m);
+ continue; /* packet not for us */
+ }
+ }
m->m_pkthdr.rcvif = ifp;
- if (sc->sc_rx->req_prod != sc->sc_rx->resp_prod) {
+ if (__predict_true(
+ sc->sc_rx->req_prod != sc->sc_rx->resp_prod)) {
m->m_len = m->m_pkthdr.len = rx->status;
- MEXTADD(m, (void *)(sc->sc_rx_bufa[rx->id].xb_rx.
- xbrx_va + (rx->addr & PAGE_MASK)), rx->status,
+ MEXTADD(m, pktp, rx->status,
M_DEVBUF, xennet_rx_mbuf_free,
&sc->sc_rx_bufa[rx->id]);
} else {
@@ -726,14 +737,13 @@
*/
m->m_len = MHLEN;
m->m_pkthdr.len = 0;
- m_copyback(m, 0, rx->status,
- (caddr_t)(sc->sc_rx_bufa[rx->id].xb_rx.xbrx_va +
- (rx->addr & PAGE_MASK)));
+ m_copyback(m, 0, rx->status, pktp);
xennet_rx_push_buffer(sc, rx->id);
if (m->m_pkthdr.len < rx->status) {
+ /* out of memory, just drop packets */
ifp->if_ierrors++;
m_freem(m);
- break;
+ continue;
}
}
diff -r 17d6dc7d3fbe -r 57f6a7f012c0 sys/arch/xen/xen/xennetback.c
--- a/sys/arch/xen/xen/xennetback.c Fri Feb 03 05:25:03 2006 +0000
+++ b/sys/arch/xen/xen/xennetback.c Sun Feb 05 17:02:11 2006 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xennetback.c,v 1.4.2.7 2006/01/20 21:14:47 riz Exp $ */
+/* $NetBSD: xennetback.c,v 1.4.2.8 2006/02/05 17:02:11 riz Exp $ */
/*
* Copyright (c) 2005 Manuel Bouyer.
@@ -496,8 +496,8 @@
do_event = 1;
XENPRINTF(("%s pkg size %d\n", xneti->xni_if.if_xname, txreq->size));
- if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) !=
- (IFF_UP | IFF_RUNNING)) {
+ if (__predict_false((ifp->if_flags & (IFF_UP | IFF_RUNNING)) !=
+ (IFF_UP | IFF_RUNNING))) {
/* interface not up, drop */
txresp->id = txreq->id;
txresp->status = NETIF_RSP_DROPPED;
@@ -506,8 +506,8 @@
/*
* Do some sanity checks, and map the packet's page.
*/
- if (txreq->size < ETHER_HDR_LEN ||
- txreq->size > (ETHER_MAX_LEN - ETHER_CRC_LEN)) {
+ 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);
txresp->id = txreq->id;
@@ -516,7 +516,8 @@
continue;
}
/* don't cross page boundaries */
- if ((txreq->addr & PAGE_MASK) + txreq->size > PAGE_SIZE) {
+ if (__predict_false(
+ (txreq->addr & PAGE_MASK) + txreq->size > PAGE_SIZE)) {
printf("%s: packet cross page boundary\n",
ifp->if_xname);
txresp->id = txreq->id;
@@ -526,7 +527,8 @@
}
ma = txreq->addr & ~PAGE_MASK;
- if (xen_shm_map(&ma, 1, xneti->domid, &pkt, 0) != 0) {
+ if (__predict_false(
+ xen_shm_map(&ma, 1, xneti->domid, &pkt, 0) != 0)) {
printf("%s: can't map packet page\n", ifp->if_xname);
txresp->id = txreq->id;
txresp->status = NETIF_RSP_ERROR;
@@ -534,16 +536,28 @@
continue;
}
pkt |= (txreq->addr & PAGE_MASK);
+ if ((ifp->if_flags & IFF_PROMISC) == 0) {
+ struct ether_header *eh = (void *)pkt;
+ if (ETHER_IS_MULTICAST(eh->ether_dhost) == 0 &&
+ memcmp(LLADDR(ifp->if_sadl), eh->ether_dhost,
+ ETHER_ADDR_LEN) != 0) {
+ /* packet not for us */
+ xen_shm_unmap(pkt, &ma, 1, xneti->domid);
+ txresp->id = txreq->id;
+ txresp->status = NETIF_RSP_OKAY;
+ continue;
+ }
+ }
/* get a mbuf for this packet */
MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m != NULL) {
+ if (__predict_true(m != NULL)) {
MCLGET(m, M_DONTWAIT);
- if ((m->m_flags & M_EXT) == 0) {
+ if (__predict_false((m->m_flags & M_EXT) == 0)) {
m_freem(m);
m = NULL;
}
}
- if (m == NULL) {
+ if (__predict_false(m == NULL)) {
txresp->id = txreq->id;
txresp->status = NETIF_RSP_DROPPED;
xen_shm_unmap(pkt, &ma, 1, xneti->domid);
Home |
Main Index |
Thread Index |
Old Index