Various bpf(4) related fixes to catch places up to the new bpf(4)

semantics.
- Stop testing bpf pointers for NULL.  In some cases use
  bpf_peers_present() and then call the function directly inside the
  conditional block instead of the macro.
- For places where the entire conditional block is the macro, remove the
  test and make the macro unconditional.
- Use BPF_MTAP() in if_pfsync on FreeBSD instead of an expanded version of
  the old semantics.

Reviewed by:	csjp (older version)
This commit is contained in:
John Baldwin 2006-12-29 13:59:50 +00:00
parent 240589a9fe
commit 0dea849ae9
13 changed files with 33 additions and 37 deletions

View File

@ -1793,8 +1793,12 @@ pfsync_sendout(sc)
KASSERT(m != NULL, ("pfsync_sendout: null mbuf"));
#endif
#if NBPFILTER > 0
#ifdef __FreeBSD__
BPF_MTAP(ifp, m);
#else
if (ifp->if_bpf)
bpf_mtap(ifp->if_bpf, m);
#endif
#endif
if (sc->sc_mbuf_net) {

View File

@ -980,7 +980,7 @@ arl_read(sc, buf, len)
* Check if there's a bpf filter listening on this interface.
* If so, hand off the raw packet to bpf.
*/
if (ifp->if_bpf) {
if (bpf_peers_present(ifp->if_bpf)) {
/*
* Note that the interface cannot be in promiscuous mode if
* there are no bpf listeners. And if el are in promiscuous

View File

@ -1070,10 +1070,10 @@ static void ce_send (drv_t *d)
if (! m)
return;
#ifndef NETGRAPH
if (d->ifp->if_bpf)
#if __FreeBSD_version >= 500000
BPF_MTAP (d->ifp, m);
BPF_MTAP (d->ifp, m);
#else
if (d->ifp->if_bpf)
bpf_mtap (d->ifp, m);
#endif
#endif
@ -1192,10 +1192,10 @@ static void ce_receive (ce_chan_t *c, unsigned char *data, int len)
m->m_pkthdr.rcvif = d->ifp;
/* Check if there's a BPF listener on this interface.
* If so, hand off the raw packet to bpf. */
if (d->ifp->if_bpf)
#if __FreeBSD_version >= 500000
BPF_TAP (d->ifp, data, len);
BPF_TAP (d->ifp, data, len);
#else
if (d->ifp->if_bpf)
bpf_tap (d->ifp, data, len);
#endif
IF_ENQUEUE(&d->rqueue, m);

View File

@ -833,8 +833,7 @@ static void cp_send (drv_t *d)
if (! m)
return;
#ifndef NETGRAPH
if (d->ifp->if_bpf)
BPF_MTAP (d->ifp, m);
BPF_MTAP (d->ifp, m);
#endif
len = m_length (m, NULL);
if (len >= BUFSZ)
@ -943,8 +942,7 @@ static void cp_receive (cp_chan_t *c, unsigned char *data, int len)
m->m_pkthdr.rcvif = d->ifp;
/* Check if there's a BPF listener on this interface.
* If so, hand off the raw packet to bpf. */
if (d->ifp->if_bpf)
BPF_TAP (d->ifp, data, len);
BPF_TAP (d->ifp, data, len);
IF_ENQUEUE (&d->queue, m);
#endif
}

View File

@ -1040,8 +1040,7 @@ static void ct_send (drv_t *d)
if (! m)
return;
#ifndef NETGRAPH
if (d->ifp->if_bpf)
BPF_MTAP (d->ifp, m);
BPF_MTAP (d->ifp, m);
#endif
len = m_length (m, NULL);
if (! m->m_next)
@ -1161,8 +1160,7 @@ static void ct_receive (ct_chan_t *c, char *data, int len)
m->m_pkthdr.rcvif = d->ifp;
/* Check if there's a BPF listener on this interface.
* If so, hand off the raw packet to bpf. */
if (d->ifp->if_bpf)
BPF_TAP (d->ifp, data, len);
BPF_TAP (d->ifp, data, len);
IF_ENQUEUE (&d->queue, m);
#endif
}

View File

@ -1195,8 +1195,7 @@ static void cx_send (drv_t *d)
if (! m)
return;
#ifndef NETGRAPH
if (d->ifp->if_bpf)
BPF_MTAP (d->ifp, m);
BPF_MTAP (d->ifp, m);
#endif
len = m_length (m, NULL);
if (! m->m_next)
@ -1352,8 +1351,7 @@ static void cx_receive (cx_chan_t *c, char *data, int len)
m->m_pkthdr.rcvif = d->ifp;
/* Check if there's a BPF listener on this interface.
* If so, hand off the raw packet to bpf. */
if (d->ifp->if_bpf)
BPF_TAP (d->ifp, data, len);
BPF_TAP (d->ifp, data, len);
IF_ENQUEUE (&d->queue, m);
#endif
}

View File

@ -776,7 +776,7 @@ en_txdma(struct en_softc *sc, struct en_txslot *slot)
sc->vccs[tx.vci]->obytes += tx.datalen;
#ifdef ENABLE_BPF
if (sc->ifp->if_bpf != NULL) {
if (bpf_peers_present(sc->ifp->if_bpf)) {
/*
* adjust the top of the mbuf to skip the TBD if present
* before passing the packet to bpf.
@ -794,7 +794,7 @@ en_txdma(struct en_softc *sc, struct en_txslot *slot)
tx.m->m_pkthdr.len = tx.datalen;
}
BPF_MTAP(sc->ifp, tx.m);
bpf_mtap(sc->ifp, tx.m);
}
#endif

View File

@ -838,7 +838,7 @@ fwip_stream_input(struct fw_xferq *xferq)
* Record the sender ID for possible BPF usage.
*/
src = ntohl(p[1]) >> 16;
if (ifp->if_bpf) {
if (bpf_peers_present(ifp->if_bpf)) {
mtag = m_tag_alloc(MTAG_FIREWIRE,
MTAG_FIREWIRE_SENDER_EUID,
2*sizeof(uint32_t), M_NOWAIT);
@ -939,7 +939,7 @@ fwip_unicast_input(struct fw_xfer *xfer)
return;
}
if (ifp->if_bpf) {
if (bpf_peers_present(ifp->if_bpf)) {
/*
* Record the sender ID for possible BPF usage.
*/

View File

@ -1161,8 +1161,8 @@ my_rxeof(struct my_softc * sc)
* broadcast packet, multicast packet, matches our ethernet
* address or the interface is in promiscuous mode.
*/
if (ifp->if_bpf) {
BPF_MTAP(ifp, m);
if (bpf_peers_present(ifp->if_bpf)) {
bpf_mtap(ifp, m);
if (ifp->if_flags & IFF_PROMISC &&
(bcmp(eh->ether_dhost, IF_LLADDR(sc->my_ifp),
ETHER_ADDR_LEN) &&

View File

@ -455,7 +455,7 @@ static void
lptap(struct ifnet *ifp, struct mbuf *m)
{
u_int32_t af = AF_INET;
BPF_MTAP2(ifp, &af, sizeof(af), m);
bpf_mtap2(ifp, &af, sizeof(af), m);
}
static void
@ -514,7 +514,7 @@ lp_intr (void *arg)
sc->sc_ifp->if_ibytes += len;
top = m_devget(sc->sc_ifbuf + CLPIPHDRLEN, len, 0, sc->sc_ifp, 0);
if (top) {
if (sc->sc_ifp->if_bpf)
if (bpf_peers_present(sc->sc_ifp->if_bpf))
lptap(sc->sc_ifp, top);
netisr_queue(NETISR_IP, top); /* mbuf is free'd on failure. */
}
@ -559,7 +559,7 @@ lp_intr (void *arg)
sc->sc_ifp->if_ibytes += len;
top = m_devget(sc->sc_ifbuf + LPIPHDRLEN, len, 0, sc->sc_ifp, 0);
if (top) {
if (sc->sc_ifp->if_bpf)
if (bpf_peers_present(sc->sc_ifp->if_bpf))
lptap(sc->sc_ifp, top);
netisr_queue(NETISR_IP, top); /* mbuf is free'd on failure. */
}
@ -694,7 +694,7 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
} else {
ifp->if_opackets++;
ifp->if_obytes += m->m_pkthdr.len;
if (ifp->if_bpf)
if (bpf_peers_present(ifp->if_bpf))
lptap(ifp, m);
}
@ -739,7 +739,7 @@ lpoutput (struct ifnet *ifp, struct mbuf *m,
} else {
ifp->if_opackets++;
ifp->if_obytes += m->m_pkthdr.len;
if (ifp->if_bpf)
if (bpf_peers_present(ifp->if_bpf))
lptap(ifp, m);
}

View File

@ -883,7 +883,7 @@ ipr_rx_data_rdy(int unit)
}
#endif
if(sc->sc_ifp->if_bpf)
if(bpf_peers_present(sc->sc_ifp->if_bpf))
{
/* prepend the address family as a four byte field */
struct mbuf mm;
@ -891,7 +891,7 @@ ipr_rx_data_rdy(int unit)
mm.m_next = m;
mm.m_len = 4;
mm.m_data = (char *)⁡
BPF_MTAP(sc->sc_ifp, &mm);
bpf_mtap(sc->sc_ifp, &mm);
}
if(netisr_queue(NETISR_IP, m)) /* (0) on success. */
@ -936,7 +936,7 @@ ipr_tx_queue_empty(int unit)
microtime(&sc->sc_ifp->if_lastchange);
if(sc->sc_ifp->if_bpf)
if(bpf_peers_present(sc->sc_ifp->if_bpf))
{
/* prepend the address family as a four byte field */
@ -945,7 +945,7 @@ ipr_tx_queue_empty(int unit)
mm.m_next = m;
mm.m_len = 4;
mm.m_data = (char *)⁡
BPF_MTAP(sc->sc_ifp, &mm);
bpf_mtap(sc->sc_ifp, &mm);
}
#if I4BIPRACCT

View File

@ -280,7 +280,7 @@ ipsec_bpf(struct mbuf *m, struct secasvar *sav, int af)
if ((encif->if_drv_flags & IFF_DRV_RUNNING) == 0)
return;
if (encif->if_bpf) {
if (bpf_peers_present(encif->if_bpf)) {
flags = 0;
if (sav->alg_enc != SADB_EALG_NONE)
flags |= M_CONF;

View File

@ -219,8 +219,7 @@ ng_sppp_start (struct ifnet *ifp)
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
while ((m = sppp_dequeue (ifp)) != NULL) {
if (ifp->if_bpf)
BPF_MTAP (ifp, m);
BPF_MTAP (ifp, m);
len = m->m_pkthdr.len;
NG_SEND_DATA_ONLY (error, priv->hook, m);
@ -382,8 +381,7 @@ ng_sppp_rcvdata (hook_p hook, item_p item)
m->m_pkthdr.rcvif = SP2IFP(pp);
/* Berkeley packet filter */
if (SP2IFP(pp)->if_bpf)
BPF_MTAP (SP2IFP(pp), m);
BPF_MTAP (SP2IFP(pp), m);
/* Send packet */
sppp_input (SP2IFP(pp), m);