Module Name: src Committed By: gutteridge Date: Wed Feb 8 01:37:53 UTC 2023
Modified Files: src/sys/net: bpf.c Log Message: bpf.c: support loopback writes when BIOCSHDRCMPLT is set Following changes in r. 1.249 "bpf: support sending packets on loopback interfaces", also allow for this to succeed when the "header complete" flag is set, which is the practice of some tools, e.g., tcpreplay and Scapy. With this change, both of those example tools now work, e.g., Scapy passes "L3bpfSocket - send and sniff on loopback" in its test suite. There are several ways of addressing this issue; this commit is intended to be the most conservative and consistent with the previous changes. (E.g., FreeBSD instead has special handling of this condition in its if_loop.c.) To generate a diff of this commit: cvs rdiff -u -r1.250 -r1.251 src/sys/net/bpf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/bpf.c diff -u src/sys/net/bpf.c:1.250 src/sys/net/bpf.c:1.251 --- src/sys/net/bpf.c:1.250 Tue Feb 7 01:46:37 2023 +++ src/sys/net/bpf.c Wed Feb 8 01:37:53 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: bpf.c,v 1.250 2023/02/07 01:46:37 gutteridge Exp $ */ +/* $NetBSD: bpf.c,v 1.251 2023/02/08 01:37:53 gutteridge Exp $ */ /* * Copyright (c) 1990, 1991, 1993 @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.250 2023/02/07 01:46:37 gutteridge Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.251 2023/02/08 01:37:53 gutteridge Exp $"); #if defined(_KERNEL_OPT) #include "opt_bpf.h" @@ -876,7 +876,12 @@ bpf_write(struct file *fp, off_t *offp, goto out; } - if (d->bd_hdrcmplt) + /* + * If writing to a loopback interface, the address family has + * already been specially computed in bpf_movein(), so don't + * clobber it, or the loopback will reject it in looutput(). + */ + if (d->bd_hdrcmplt && ifp->if_type != IFT_LOOP) dst.ss_family = pseudo_AF_HDRCMPLT; if (d->bd_feedback) {