net: Allow snooping on ethermedium
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 7 Dec 2016 22:49:41 +0000 (14:49 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 12 Dec 2016 19:21:07 +0000 (14:21 -0500)
Normally, snoopy snoops on /net/ether0.  It does this by default.  You
can also pass it an ipifc, such as /net/ipifc/{0,1,2} and it'll tap at
the medium layer.

Previously, we only supported snooping on the loopback medium.  This
commit snoops on the ethernet medium.  If you do this, you won't see
ARP or stuff like that.  It's still nice.

We need this, since the mlx4 currently can't set promiscuous mode, and
without that, we couldn't see any outbound traffic.  Outbound traffic
with /net/ether0 only gets snooped if promiscuous is on.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/src/net/ethermedium.c

index d1393f0..c7f5fd7 100644 (file)
@@ -370,6 +370,7 @@ etherbwrite(struct Ipifc *ifc, struct block *bp, int version, uint8_t * ip)
        uint8_t mac[6];
        Etherrock *er = ifc->arg;
 
+       ipifc_trace_block(ifc, bp);
        /* get mac address of destination.
         *
         * Locking is tricky here.  If we get arpent 'a' back, the f->arp is
@@ -452,10 +453,12 @@ static void etherread4(void *a)
                }
                ifc->in++;
                bp->rp += ifc->m->hsize;
-               if (ifc->lifc == NULL)
+               if (ifc->lifc == NULL) {
                        freeb(bp);
-               else
+               } else {
+                       ipifc_trace_block(ifc, bp);
                        ipiput4(er->f, ifc, bp);
+               }
                runlock(&ifc->rwlock);
                poperror();
        }
@@ -493,10 +496,12 @@ static void etherread6(void *a)
                }
                ifc->in++;
                bp->rp += ifc->m->hsize;
-               if (ifc->lifc == NULL)
+               if (ifc->lifc == NULL) {
                        freeb(bp);
-               else
+               } else {
+                       ipifc_trace_block(ifc, bp);
                        ipiput6(er->f, ifc, bp);
+               }
                runlock(&ifc->rwlock);
                poperror();
        }