--- Net2/net/if_loop.c 2018/04/24 18:04:02 1.1 +++ Net2/net/if_loop.c 2018/04/24 18:13:15 1.1.1.2 @@ -43,6 +43,7 @@ #include "socket.h" #include "errno.h" #include "ioctl.h" +#include "protosw.h" #include "../net/if.h" #include "../net/if_types.h" @@ -68,6 +69,13 @@ #include "../netiso/iso_var.h" #endif +#include "bpfilter.h" +#if NBPFILTER > 0 +#include +#include +static caddr_t lo_bpf; +#endif + #define LOMTU (1024+512) struct ifnet loif; @@ -86,6 +94,9 @@ loattach() ifp->if_hdrlen = 0; ifp->if_addrlen = 0; if_attach(ifp); +#if NBPFILTER > 0 + bpfattach(&lo_bpf, ifp, DLT_NULL, sizeof(u_int)); +#endif } looutput(ifp, m, dst, rt) @@ -99,6 +110,25 @@ looutput(ifp, m, dst, rt) if ((m->m_flags & M_PKTHDR) == 0) panic("looutput no HDR"); +#if NBPFILTER > 0 + if (lo_bpf) { + /* + * We need to prepend the address family as + * a four byte field. Cons up a dummy header + * to pacify bpf. This is safe because bpf + * will only read from the mbuf (i.e., it won't + * try to free it or keep a pointer to it). + */ + struct mbuf m0; + u_int af = dst->sa_family; + + m0.m_next = m; + m0.m_len = 4; + m0.m_data = (char *)⁡ + + bpf_mtap(lo_bpf, &m0); + } +#endif m->m_pkthdr.rcvif = ifp; if (rt && rt->rt_flags & RTF_REJECT) {