#if BSD310
#include "opt_inet.h"
#endif
#include "dummy.h"
#if NDUMMY > 0
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <net/if.h>
#include <net/if_types.h>
#include <net/netisr.h>
#include <net/route.h>
#include <net/bpf.h>
#if INET
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#endif
#if IPX
#include <netipx/ipx.h>
#include <netipx/ipx_if.h>
#endif
#if INET6
#ifndef INET
#include <netinet/in.h>
#endif
#include <netinet6/in6_var.h>
#include <netinet6/ip6.h>
#endif
#if NS
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif
#if ISO
#include <netiso/iso.h>
#include <netiso/iso_var.h>
#endif
#if NETATALK
#include <netinet/if_ether.h>
#include <netatalk/at.h>
#include <netatalk/at_var.h>
#endif NETATALK
#include "bpfilter.h"
static int dummyioctl __P((struct ifnet *, u_long, caddr_t));
int dummyoutput __P((struct ifnet *, register struct mbuf *, struct sockaddr *,
register struct rtentry *));
static void dummyrtrequest __P((int, struct rtentry *, struct sockaddr *));
static void dummyattach __P((void *));
PSEUDO_SET(dummyattach, if_dummy);
#if TINY_DUMMYMTU
#define DUMMYMTU (1024+512)
#else
#define DUMMYMTU 16384
#endif
#define HAVE_OLD_BPF 1
static struct ifnet dummyif[NDUMMY];
static void
dummyattach(dummy)
void *dummy;
{
register struct ifnet *ifp;
register int i = 0;
for (i = 0; i < NDUMMY; i++) {
ifp = &dummyif[i];
#if defined(__NetBSD__) || defined(__OpenBSD__)
sprintf(ifp->if_xname, "dummy%d", i);
#else
ifp->if_name = "dummy";
ifp->if_unit = i;
#endif
#ifndef __bsdi__
ifp->if_softc = NULL;
#endif
ifp->if_mtu = DUMMYMTU;
ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST;
ifp->if_ioctl = dummyioctl;
ifp->if_output = dummyoutput;
ifp->if_type = IFT_DUMMY;
ifp->if_hdrlen = 0;
ifp->if_addrlen = 0;
if_attach(ifp);
#if NBPFILTER > 0
#ifdef HAVE_OLD_BPF
bpfattach(ifp, DLT_NULL, sizeof(u_int));
#else
bpfattach(&ifp->if_bpf, ifp, DLT_NULL, sizeof(u_int));
#endif
#endif
}
}
int
dummyoutput(ifp, m, dst, rt)
struct ifnet *ifp;
register struct mbuf *m;
struct sockaddr *dst;
register struct rtentry *rt;
{
int s, isr;
register struct ifqueue *ifq = 0;
if ((m->m_flags & M_PKTHDR) == 0)
panic("dummyoutput no HDR");
#if NBPFILTER > 0
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) {
struct mbuf m0;
u_int af = dst->sa_family;
m0.m_next = m;
m0.m_len = 4;
m0.m_data = (char *)⁡
#ifdef HAVE_OLD_BPF
bpf_mtap(ifp, &m0);
#else
bpf_mtap(ifp->if_bpf, &m0);
#endif
}
#endif
m->m_pkthdr.rcvif = ifp;
if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) {
m_freem(m);
return (rt->rt_flags & RTF_BLACKHOLE ? 0 :
rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH);
}
ifp->if_opackets++;
ifp->if_obytes += m->m_pkthdr.len;
switch (dst->sa_family) {
#if INET
case AF_INET:
ifq = &ipintrq;
isr = NETISR_IP;
break;
#endif
#if IPX
case AF_IPX:
ifq = &ipxintrq;
isr = NETISR_IPX;
break;
#endif
#if INET6
case AF_INET6:
ifq = &ip6intrq;
isr = NETISR_IPV6;
break;
#endif
#if NS
case AF_NS:
ifq = &nsintrq;
isr = NETISR_NS;
break;
#endif
#if ISO
case AF_ISO:
ifq = &clnlintrq;
isr = NETISR_ISO;
break;
#endif
#if NETATALK
case AF_APPLETALK:
ifq = &atintrq2;
isr = NETISR_ATALK;
break;
#endif NETATALK
default:
printf("%s: can't handle af%d\n",
if_name(ifp), dst->sa_family);
m_freem(m);
return (EAFNOSUPPORT);
}
s = splimp();
if (IF_QFULL(ifq)) {
IF_DROP(ifq);
m_freem(m);
splx(s);
return (ENOBUFS);
}
IF_ENQUEUE(ifq, m);
schednetisr(isr);
ifp->if_ipackets++;
ifp->if_ibytes += m->m_pkthdr.len;
splx(s);
return (0);
}
static void
dummyrtrequest(cmd, rt, sa)
int cmd;
struct rtentry *rt;
struct sockaddr *sa;
{
if (rt) {
rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu;
rt->rt_rmx.rmx_recvpipe =
rt->rt_rmx.rmx_sendpipe = 3 * DUMMYMTU;
}
}
static int
dummyioctl(ifp, cmd, data)
register struct ifnet *ifp;
u_long cmd;
caddr_t data;
{
register struct ifaddr *ifa;
register struct ifreq *ifr = (struct ifreq *)data;
register int error = 0;
switch (cmd) {
case SIOCSIFADDR:
ifp->if_flags |= IFF_UP | IFF_RUNNING;
ifa = (struct ifaddr *)data;
ifa->ifa_rtrequest = dummyrtrequest;
break;
case SIOCADDMULTI:
case SIOCDELMULTI:
if (ifr == 0) {
error = EAFNOSUPPORT;
break;
}
switch (ifr->ifr_addr.sa_family) {
#if INET
case AF_INET:
break;
#endif
#if INET6
case AF_INET6:
break;
#endif
default:
error = EAFNOSUPPORT;
break;
}
break;
case SIOCSIFMTU:
ifp->if_mtu = ifr->ifr_mtu;
break;
case SIOCSIFFLAGS:
break;
default:
error = EINVAL;
}
return (error);
}
#endif