From 5c34a7158dd01da524fff4cea5a006b3ced065d2 Mon Sep 17 00:00:00 2001 From: ozaki-r Date: Fri, 15 Aug 2014 15:03:03 +0000 Subject: [PATCH] Make shmif SIMPLEX Add a sender field to a packet header on a shmif bus to identify and ignore packets sent by itself. This makes shmif work with bridges. ok pooka@ --- sys/rump/net/lib/libshmif/if_shmem.c | 14 ++++++++++---- sys/rump/net/lib/libshmif/shmifvar.h | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sys/rump/net/lib/libshmif/if_shmem.c b/sys/rump/net/lib/libshmif/if_shmem.c index 50ab14c5e7b2..89b8b91a82c2 100644 --- a/sys/rump/net/lib/libshmif/if_shmem.c +++ b/sys/rump/net/lib/libshmif/if_shmem.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_shmem.c,v 1.62 2014/08/09 09:43:49 ozaki-r Exp $ */ +/* $NetBSD: if_shmem.c,v 1.63 2014/08/15 15:03:03 ozaki-r Exp $ */ /* * Copyright (c) 2009, 2010 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.62 2014/08/09 09:43:49 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.63 2014/08/15 15:03:03 ozaki-r Exp $"); #include #include @@ -97,6 +97,8 @@ struct shmif_sc { struct lwp *sc_rcvl; bool sc_dying; + + uint64_t sc_uuid; }; static void shmif_rcv(void *); @@ -167,12 +169,13 @@ allocif(int unit, struct shmif_sc **scp) sc = kmem_zalloc(sizeof(*sc), KM_SLEEP); sc->sc_memfd = -1; sc->sc_unit = unit; + sc->sc_uuid = cprng_fast64(); ifp = &sc->sc_ec.ec_if; snprintf(ifp->if_xname, sizeof(ifp->if_xname), "shmif%d", unit); ifp->if_softc = sc; - ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST; + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_init = shmif_init; ifp->if_ioctl = shmif_ioctl; ifp->if_start = shmif_start; @@ -540,6 +543,7 @@ shmif_start(struct ifnet *ifp) sp.sp_len = pktsize; sp.sp_sec = tv.tv_sec; sp.sp_usec = tv.tv_usec; + sp.sp_sender = sc->sc_uuid; bpf_mtap(ifp, m0); @@ -743,7 +747,9 @@ shmif_rcv(void *arg) * Test if we want to pass the packet upwards */ eth = mtod(m, struct ether_header *); - if (memcmp(eth->ether_dhost, CLLADDR(ifp->if_sadl), + if (sp.sp_sender == sc->sc_uuid) { + passup = false; + } else if (memcmp(eth->ether_dhost, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN) == 0) { passup = true; } else if (ETHER_IS_MULTICAST(eth->ether_dhost)) { diff --git a/sys/rump/net/lib/libshmif/shmifvar.h b/sys/rump/net/lib/libshmif/shmifvar.h index 7e9e509dc887..cb913c576b85 100644 --- a/sys/rump/net/lib/libshmif/shmifvar.h +++ b/sys/rump/net/lib/libshmif/shmifvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: shmifvar.h,v 1.7 2013/12/20 09:06:35 pooka Exp $ */ +/* $NetBSD: shmifvar.h,v 1.8 2014/08/15 15:03:03 ozaki-r Exp $ */ /*- * Copyright (c) 2009, 2010 Antti Kantee. All Rights Reserved. @@ -56,6 +56,8 @@ struct shmif_pkthdr { uint32_t sp_sec; uint32_t sp_usec; + + uint64_t sp_sender; }; #define BUSMEM_SIZE (1024*1024)