Fix BPf to generate a header mbuf for writes.

Fix loopback and discard interfaces to understand BPF writes.
(These two from Bill Fenner to fix PR 512.)

Move ifpromisc() from bpf.c to if.c as suggested by comment in BPF.
Send a notice to the log when promiscuous mode is enabled.
This commit is contained in:
Garrett Wollman 1995-09-22 17:57:48 +00:00
parent f001bbb882
commit 963e4c2a50
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=10957
4 changed files with 59 additions and 42 deletions

View File

@ -37,7 +37,7 @@
*
* @(#)bpf.c 8.2 (Berkeley) 3/28/94
*
* $Id: bpf.c,v 1.11 1995/09/08 11:08:52 bde Exp $
* $Id: bpf.c,v 1.12 1995/09/20 20:48:29 wollman Exp $
*/
#include "bpfilter.h"
@ -192,10 +192,10 @@ bpf_movein(uio, linktype, mp, sockp, datlen)
if ((unsigned)len > MCLBYTES)
return (EIO);
MGET(m, M_WAIT, MT_DATA);
MGETHDR(m, M_WAIT, MT_DATA);
if (m == 0)
return (ENOBUFS);
if (len > MLEN) {
if (len > MHLEN) {
#if BSD >= 199103
MCLGET(m, M_WAIT);
if ((m->m_flags & M_EXT) == 0) {
@ -207,7 +207,8 @@ bpf_movein(uio, linktype, mp, sockp, datlen)
goto bad;
}
}
m->m_len = len;
m->m_pkthdr.len = m->m_len = len;
m->m_pkthdr.rcvif = NULL;
*mp = m;
/*
* Make room for link header.
@ -1308,39 +1309,4 @@ bpfattach(driverp, ifp, dlt, hdrlen)
if (bootverbose)
printf("bpf: %s%d attached\n", ifp->if_name, ifp->if_unit);
}
#if BSD >= 199103
/* XXX This routine belongs in net/if.c. */
/*
* Set/clear promiscuous mode on interface ifp based on the truth value
* of pswitch. The calls are reference counted so that only the first
* "on" request actually has an effect, as does the final "off" request.
* Results are undefined if the "off" and "on" requests are not matched.
*/
int
ifpromisc(ifp, pswitch)
struct ifnet *ifp;
int pswitch;
{
struct ifreq ifr;
if (pswitch) {
/*
* If the device is not configured up, we cannot put it in
* promiscuous mode.
*/
if ((ifp->if_flags & IFF_UP) == 0)
return (ENETDOWN);
if (ifp->if_pcount++ != 0)
return (0);
ifp->if_flags |= IFF_PROMISC;
} else {
if (--ifp->if_pcount > 0)
return (0);
ifp->if_flags &= ~IFF_PROMISC;
}
ifr.ifr_flags = ifp->if_flags;
return ((*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr));
}
#endif
#endif

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)if.c 8.3 (Berkeley) 1/4/94
* $Id: if.c,v 1.18 1995/08/28 09:19:00 julian Exp $
* $Id: if.c,v 1.19 1995/09/09 18:10:20 davidg Exp $
*/
#include <sys/param.h>
@ -44,6 +44,7 @@
#include <sys/kernel.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/syslog.h>
#include <net/if.h>
#include <net/if_dl.h>
@ -645,6 +646,40 @@ ifioctl(so, cmd, data, p)
return (0);
}
/*
* Set/clear promiscuous mode on interface ifp based on the truth value
* of pswitch. The calls are reference counted so that only the first
* "on" request actually has an effect, as does the final "off" request.
* Results are undefined if the "off" and "on" requests are not matched.
*/
int
ifpromisc(ifp, pswitch)
struct ifnet *ifp;
int pswitch;
{
struct ifreq ifr;
if (pswitch) {
/*
* If the device is not configured up, we cannot put it in
* promiscuous mode.
*/
if ((ifp->if_flags & IFF_UP) == 0)
return (ENETDOWN);
if (ifp->if_pcount++ != 0)
return (0);
ifp->if_flags |= IFF_PROMISC;
log(LOG_NOTICE, "%s%d: promiscuous mode enabled",
ifp->if_name, ifp->if_unit);
} else {
if (--ifp->if_pcount > 0)
return (0);
ifp->if_flags &= ~IFF_PROMISC;
}
ifr.ifr_flags = ifp->if_flags;
return ((*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr));
}
/*
* Return interface configuration
* of system. List may be used

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* From: @(#)if_loop.c 8.1 (Berkeley) 6/10/93
* $Id: if_disc.c,v 1.5 1995/08/30 00:33:17 bde Exp $
* $Id: if_disc.c,v 1.6 1995/09/09 18:10:21 davidg Exp $
*/
/*
@ -123,6 +123,14 @@ dsoutput(ifp, m, dst, rt)
panic("dsoutput no HDR");
ifp->if_lastchange = time;
#if NBPFILTER > 0
/* BPF write needs to be handled specially */
if (dst->sa_family == AF_UNSPEC) {
dst->sa_family = *(mtod(m, int *));
m->m_len -= sizeof(int);
m->m_pkthdr.len -= sizeof(int);
m->m_data += sizeof(int);
}
if (dsif.if_bpf) {
/*
* We need to prepend the address family as

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)if_loop.c 8.1 (Berkeley) 6/10/93
* $Id: if_loop.c,v 1.11 1995/08/30 00:33:18 bde Exp $
* $Id: if_loop.c,v 1.12 1995/09/09 18:10:22 davidg Exp $
*/
/*
@ -126,6 +126,14 @@ looutput(ifp, m, dst, rt)
panic("looutput no HDR");
ifp->if_lastchange = time;
#if NBPFILTER > 0
/* BPF write needs to be handled specially */
if (dst->sa_family == AF_UNSPEC) {
dst->sa_family = *(mtod(m, int *));
m->m_len -= sizeof(int);
m->m_pkthdr.len -= sizeof(int);
m->m_data += sizeof(int);
}
if (ifp->if_bpf) {
/*
* We need to prepend the address family as