--- Net2/net/if_loop.c 2018/04/24 18:04:02 1.1.1.1 +++ Net2/net/if_loop.c 2018/04/24 18:21:40 1.1.1.3 @@ -30,7 +30,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)if_loop.c 7.13 (Berkeley) 4/26/91 + * from: @(#)if_loop.c 7.13 (Berkeley) 4/26/91 + * if_loop.c,v 1.6 1993/06/27 06:02:27 andrew Exp */ /* @@ -43,6 +44,9 @@ #include "socket.h" #include "errno.h" #include "ioctl.h" +#include "protosw.h" + +#include "loop.h" #include "../net/if.h" #include "../net/if_types.h" @@ -68,24 +72,41 @@ #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; +struct ifnet loif[NLOOP]; int looutput(), loioctl(); +void loattach() { - register struct ifnet *ifp = &loif; + register int i; + register struct ifnet *ifp; - ifp->if_name = "lo"; - ifp->if_mtu = LOMTU; - ifp->if_flags = IFF_LOOPBACK; - ifp->if_ioctl = loioctl; - ifp->if_output = looutput; - ifp->if_type = IFT_LOOP; - ifp->if_hdrlen = 0; - ifp->if_addrlen = 0; - if_attach(ifp); + for (i = 0; i < NLOOP; i++) + { + ifp = &loif[i]; + ifp->if_unit = i; + ifp->if_name = "lo"; + ifp->if_mtu = LOMTU; + ifp->if_flags = IFF_LOOPBACK; + ifp->if_ioctl = loioctl; + ifp->if_output = looutput; + ifp->if_type = IFT_LOOP; + 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 +120,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) {