* Copyright (c) 1982, 1986 Regents of the University of California.
* %sccs.include.redist.c%
* @(#)if_loop.c 7.17 (Berkeley) %G%
* Loopback interface driver for protocol testing and timing.
#include "netinet/in_systm.h"
#include "netinet/in_var.h"
#include "netiso/iso_var.h"
int looutput(), loioctl();
register struct ifnet
*ifp
= &loif
;
ifp
->if_flags
= IFF_LOOPBACK
| IFF_MULTICAST
;
ifp
->if_flags
= IFF_LOOPBACK
;
ifp
->if_output
= looutput
;
bpfattach(&ifp
->if_bpf
, ifp
, DLT_NULL
, sizeof(u_int
));
looutput(ifp
, m
, dst
, rt
)
register struct rtentry
*rt
;
register struct ifqueue
*ifq
= 0;
if ((m
->m_flags
& M_PKTHDR
) == 0)
panic("looutput no HDR");
ifp
->if_lastchange
= time
;
* We need to prepend the address family as
* a four byte field. Cons up a dummy header
* to pacify bpf. This is safe because bpf
* will only read from the mbuf (i.e., it won't
* try to free it or keep a pointer a to it).
u_int af
= dst
->sa_family
;
bpf_mtap(loif
.if_bpf
, &m0
);
if (rt
&& rt
->rt_flags
& RTF_REJECT
) {
return (rt
->rt_flags
& RTF_HOST
? EHOSTUNREACH
: ENETUNREACH
);
ifp
->if_obytes
+= m
->m_pkthdr
.len
;
switch (dst
->sa_family
) {
printf("lo%d: can't handle af%d\n", ifp
->if_unit
,
ifp
->if_ibytes
+= m
->m_pkthdr
.len
;
rt
->rt_rmx
.rmx_mtu
= LOMTU
;
* Process an ioctl request.
register struct ifnet
*ifp
;
register struct ifaddr
*ifa
;
register struct ifreq
*ifr
;
ifa
= (struct ifaddr
*)data
;
if (ifa
!= 0 && ifa
->ifa_addr
->sa_family
== AF_ISO
)
ifa
->ifa_rtrequest
= lortrequest
;
* Everything else is done at a higher level.
ifr
= (struct ifreq
*)data
;
error
= EAFNOSUPPORT
; /* XXX */
switch (ifr
->ifr_addr
.sa_family
) {