mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
bpf: Add IfAPI analogue for bpf_peers_present()
An interface's bpf could feasibly not exist, in which case bpf_peers_present() would panic from a NULL pointer dereference. Solve this by adding a new IfAPI that could deal with a NULL bpf, if such could occur in the network stack. Reviewed by: zlei Sponsored by: Juniper Networks, Inc. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42082
This commit is contained in:
parent
5e444deec0
commit
8f31b879ec
|
@ -780,7 +780,7 @@ fwip_stream_input(struct fw_xferq *xferq)
|
|||
* Record the sender ID for possible BPF usage.
|
||||
*/
|
||||
src = ntohl(p[1]) >> 16;
|
||||
if (bpf_peers_present(if_getbpf(ifp))) {
|
||||
if (bpf_peers_present_if(ifp)) {
|
||||
mtag = m_tag_alloc(MTAG_FIREWIRE,
|
||||
MTAG_FIREWIRE_SENDER_EUID,
|
||||
2*sizeof(uint32_t), M_NOWAIT);
|
||||
|
@ -880,7 +880,7 @@ fwip_unicast_input(struct fw_xfer *xfer)
|
|||
goto done;
|
||||
}
|
||||
|
||||
if (bpf_peers_present(if_getbpf(ifp))) {
|
||||
if (bpf_peers_present_if(ifp)) {
|
||||
/*
|
||||
* Record the sender ID for possible BPF usage.
|
||||
*/
|
||||
|
|
|
@ -3262,7 +3262,7 @@ hn_txpkt(if_t ifp, struct hn_tx_ring *txr, struct hn_txdesc *txd)
|
|||
int error, send_failed = 0, has_bpf;
|
||||
|
||||
again:
|
||||
has_bpf = bpf_peers_present(if_getbpf(ifp));
|
||||
has_bpf = bpf_peers_present_if(ifp);
|
||||
if (has_bpf) {
|
||||
/*
|
||||
* Make sure that this txd and any aggregated txds are not
|
||||
|
@ -5972,7 +5972,7 @@ hn_transmit(if_t ifp, struct mbuf *m)
|
|||
omcast = (m->m_flags & M_MCAST) != 0;
|
||||
|
||||
if (sc->hn_xvf_flags & HN_XVFFLAG_ACCBPF) {
|
||||
if (bpf_peers_present(if_getbpf(ifp))) {
|
||||
if (bpf_peers_present_if(ifp)) {
|
||||
m_bpf = m_copypacket(m, M_NOWAIT);
|
||||
if (m_bpf == NULL) {
|
||||
/*
|
||||
|
|
|
@ -1152,7 +1152,7 @@ my_rxeof(struct my_softc * sc)
|
|||
* broadcast packet, multicast packet, matches our ethernet
|
||||
* address or the interface is in promiscuous mode.
|
||||
*/
|
||||
if (bpf_peers_present(if_getbpf(ifp))) {
|
||||
if (bpf_peers_present_if(ifp)) {
|
||||
bpf_mtap_if(ifp, m);
|
||||
if (if_getflags(ifp) & IFF_PROMISC &&
|
||||
(bcmp(eh->ether_dhost, if_getlladdr(sc->my_ifp),
|
||||
|
|
|
@ -408,9 +408,7 @@ usbpf_xfertap(struct usb_xfer *xfer, int type)
|
|||
bus = xfer->xroot->bus;
|
||||
|
||||
/* sanity checks */
|
||||
if (bus->ifp == NULL || if_getbpf(bus->ifp) == NULL)
|
||||
return;
|
||||
if (!bpf_peers_present(if_getbpf(bus->ifp)))
|
||||
if (bus->ifp == NULL || !bpf_peers_present_if(bus->ifp))
|
||||
return;
|
||||
|
||||
totlen = usbpf_xfer_precompute_size(xfer, type);
|
||||
|
|
|
@ -2879,6 +2879,14 @@ bpfdetach(struct ifnet *ifp)
|
|||
BPF_UNLOCK();
|
||||
}
|
||||
|
||||
bool
|
||||
bpf_peers_present_if(struct ifnet *ifp)
|
||||
{
|
||||
struct bpf_if *bp = ifp->if_bpf;
|
||||
|
||||
return (bpf_peers_present(bp) > 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a list of available data link type of the interface.
|
||||
*/
|
||||
|
@ -3162,6 +3170,12 @@ bpfdetach(struct ifnet *ifp)
|
|||
{
|
||||
}
|
||||
|
||||
bool
|
||||
bpf_peers_present_if(struct ifnet *ifp)
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
|
||||
u_int
|
||||
bpf_filter(const struct bpf_insn *pc, u_char *p, u_int wirelen, u_int buflen)
|
||||
{
|
||||
|
|
|
@ -428,6 +428,7 @@ void bpf_mtap2_if(struct ifnet *, void *, u_int, struct mbuf *);
|
|||
void bpfattach(struct ifnet *, u_int, u_int);
|
||||
void bpfattach2(struct ifnet *, u_int, u_int, struct bpf_if **);
|
||||
void bpfdetach(struct ifnet *);
|
||||
bool bpf_peers_present_if(struct ifnet *);
|
||||
#ifdef VIMAGE
|
||||
int bpf_get_bp_params(struct bpf_if *, u_int *, u_int *);
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue