bpf writes on tun device

Matthew Luckie mjl at luckie.org.nz
Mon Jun 6 20:41:20 GMT 2005


> > If I was to pursue this, would someone on this list consider committing the
> > work to current?
> ...
> > +	case DLT_NULL:
> > +		sockp->sa_family = AF_UNSPEC;
> > +		if(strcmp(ifp->if_name, "tun") == 0)
> > +			hlen = sizeof(int);
> > +		else
> > +			hlen = 0;
> > +		break;
> 
> Maybe this won't work if an instance of tun is renamed? I'd compare "tun"
> with ifp->if_dname (driver name) to be on the safe side.

right.  although the patch was against 4.11 which does not have if_dname.
does 4.11 support renaming interfaces?  it doesn't appear to.

i wasn't really suggesting that we'd add a series of strcmp to see
which driver corresponds to the DLT_NULL, just that if if_tun was
handled specially then bpf writes would work correctly on it.

> Another way of dealing with this would be to ask the tcpdump.org guys to
> define a DLT type for tun interfaces, rather than special-casing it for
> DLT_NULL.

is there a good reason why _all_ DLT_NULL bpf devices could not simply
have writes supported?  the user space application would pass the
address family in the first 4 bytes of the packet; this is currently
done anyway for if_disc, if_loop, if_tun, if_faith, and ng_iface.
ip_carp could get bpf writes for free with AF_UNSPEC added to the
carp_looutput() switch statement.

[mjl at mylar sys]$ egrep -r 'bpfattach.+DLT_NULL' *
dev/iicbus/if_ic.c:   bpfattach(ifp, DLT_NULL, ICHDRLEN);
dev/ppbus/if_plip.c:  bpfattach(ifp, DLT_NULL, sizeof(u_int32_t));
i4b/driver/i4b_ipr.c: bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int));
net/if_disc.c:        bpfattach(ifp, DLT_NULL, sizeof(u_int));
net/if_faith.c:       bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int));
net/if_gif.c:         bpfattach(&sc->gif_if, DLT_NULL, sizeof(u_int));
net/if_gre.c:         bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int32_t));
net/if_loop.c:        bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int));
net/if_stf.c:         bpfattach(ifp, DLT_NULL, sizeof(u_int));
net/if_tun.c:         bpfattach(ifp, DLT_NULL, sizeof(u_int));
netgraph/ng_iface.c:  bpfattach(ifp, DLT_NULL, sizeof(u_int));
netgraph/ng_sppp.c:   bpfattach (&pp->pp_if, DLT_NULL, sizeof(u_int));
netinet/ip_carp.c:    bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int32_t));

Matthew


More information about the freebsd-net mailing list