commit 7eac97781ead6745aa4ca0738cef3bfd318f2b60 Author: Ryota Ozaki Date: Tue Nov 8 16:51:54 2022 +0900 loop: enable to send packets via bpf diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 1c129d65458..f366e68a4e5 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -389,6 +389,13 @@ bpf_movein(struct uio *uio, int linktype, uint64_t mtu, struct mbuf **mp, align = 0; break; + case DLT_LOOP: + printf("DLT_LOOP\n"); + sockp->sa_family = AF_UNSPEC; + hlen = sizeof(uint32_t); + align = 0; + break; + default: return (EIO); } @@ -441,8 +448,15 @@ bpf_movein(struct uio *uio, int linktype, uint64_t mtu, struct mbuf **mp, } if (hlen != 0) { - /* move link level header in the top of mbuf to sa_data */ - memcpy(sockp->sa_data, mtod(m0, void *), hlen); + if (linktype == DLT_LOOP) { + uint32_t af; + /* the link header indicates the address family */ + memcpy(&af, mtod(m0, void *), sizeof(af)); + sockp->sa_family = af; + } else { + /* move link level header in the top of mbuf to sa_data */ + memcpy(sockp->sa_data, mtod(m0, void *), hlen); + } m0->m_data += hlen; m0->m_len -= hlen; } diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index 22db6b45cd5..76be2f8ffa1 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -200,7 +200,7 @@ loop_clone_create(struct if_clone *ifc, int unit) if_initialize(ifp); ifp->if_link_state = LINK_STATE_UP; if_alloc_sadl(ifp); - bpf_attach(ifp, DLT_NULL, sizeof(u_int)); + bpf_attach(ifp, DLT_LOOP, sizeof(u_int)); #ifdef MBUFTRACE ifp->if_mowner = malloc(sizeof(struct mowner), M_DEVBUF, M_WAITOK | M_ZERO);