add NS protocol stuff
[unix-history] / usr / src / sys / net / if_loop.c
/* if_loop.c 6.4 85/04/27 */
/*
* Loopback interface driver for protocol testing and timing.
*/
#include "param.h"
#include "systm.h"
#include "mbuf.h"
#include "socket.h"
#include "errno.h"
#include "ioctl.h"
#include "../net/if.h"
#include "../net/netisr.h"
#include "../net/route.h"
#include "in.h"
#include "in_systm.h"
#include "ip.h"
#include "ip_var.h"
#ifdef vax
#include "../vax/mtpr.h"
#endif
#ifdef NS
#include "../netns/ns.h"
#include "../netns/ns_if.h"
#endif
#define LONET 127
#define LOHOST 1 /* can't be 0, that's broadcast */
#define LOMTU (1024+512)
struct ifnet loif;
int looutput(), loioctl();
loattach()
{
register struct ifnet *ifp = &loif;
register struct sockaddr_in *sin;
ifp->if_name = "lo";
ifp->if_mtu = LOMTU;
ifp->if_ioctl = loioctl;
ifp->if_output = looutput;
if_attach(ifp);
}
looutput(ifp, m0, dst)
struct ifnet *ifp;
struct mbuf *m0;
struct sockaddr *dst;
{
int s = splimp();
register struct ifqueue *ifq;
ifp->if_opackets++;
switch (dst->sa_family) {
#ifdef INET
case AF_INET:
ifq = &ipintrq;
if (IF_QFULL(ifq)) {
IF_DROP(ifq);
m_freem(m0);
splx(s);
return (ENOBUFS);
}
IF_ENQUEUE(ifq, m0);
schednetisr(NETISR_IP);
break;
#endif
#ifdef NS
case AF_NS:
ifq = &nsintrq;
if (IF_QFULL(ifq)) {
IF_DROP(ifq);
m_freem(m0);
splx(s);
return (ENOBUFS);
}
IF_ENQUEUE(ifq, m0);
schednetisr(NETISR_NS);
break;
#endif
default:
splx(s);
printf("lo%d: can't handle af%d\n", ifp->if_unit,
dst->sa_family);
m_freem(m0);
return (EAFNOSUPPORT);
}
ifp->if_ipackets++;
splx(s);
return (0);
}
/*
* Process an ioctl request.
*/
/* ARGSUSED */
loioctl(ifp, cmd, data)
register struct ifnet *ifp;
int cmd;
caddr_t data;
{
int error = 0;
switch (cmd) {
case SIOCSIFADDR:
ifp->if_flags |= IFF_UP;
/*
* Everything else is done at a higher level.
*/
break;
default:
error = EINVAL;
}
return (error);
}