if_faith.c revision 54263
154263Sshin/*
254263Sshin * Copyright (c) 1982, 1986, 1993
354263Sshin *	The Regents of the University of California.  All rights reserved.
454263Sshin *
554263Sshin * Redistribution and use in source and binary forms, with or without
654263Sshin * modification, are permitted provided that the following conditions
754263Sshin * are met:
854263Sshin * 1. Redistributions of source code must retain the above copyright
954263Sshin *    notice, this list of conditions and the following disclaimer.
1054263Sshin * 2. Redistributions in binary form must reproduce the above copyright
1154263Sshin *    notice, this list of conditions and the following disclaimer in the
1254263Sshin *    documentation and/or other materials provided with the distribution.
1354263Sshin * 3. All advertising materials mentioning features or use of this software
1454263Sshin *    must display the following acknowledgement:
1554263Sshin *	This product includes software developed by the University of
1654263Sshin *	California, Berkeley and its contributors.
1754263Sshin * 4. Neither the name of the University nor the names of its contributors
1854263Sshin *    may be used to endorse or promote products derived from this software
1954263Sshin *    without specific prior written permission.
2054263Sshin *
2154263Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2254263Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2354263Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2454263Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2554263Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2654263Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2754263Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2854263Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2954263Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3054263Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3154263Sshin * SUCH DAMAGE.
3254263Sshin *
3354263Sshin * $FreeBSD: head/sys/net/if_faith.c 54263 1999-12-07 17:39:16Z shin $
3454263Sshin */
3554263Sshin/*
3654263Sshin * derived from
3754263Sshin *	@(#)if_loop.c	8.1 (Berkeley) 6/10/93
3854263Sshin * Id: if_loop.c,v 1.22 1996/06/19 16:24:10 wollman Exp
3954263Sshin */
4054263Sshin
4154263Sshin/*
4254263Sshin * Loopback interface driver for protocol testing and timing.
4354263Sshin */
4454263Sshin
4554263Sshin#include "faith.h"
4654263Sshin#if NFAITH > 0
4754263Sshin
4854263Sshin#include <sys/param.h>
4954263Sshin#include <sys/systm.h>
5054263Sshin#include <sys/kernel.h>
5154263Sshin#include <sys/mbuf.h>
5254263Sshin#include <sys/socket.h>
5354263Sshin#include <sys/sockio.h>
5454263Sshin
5554263Sshin#include <net/if.h>
5654263Sshin#include <net/if_types.h>
5754263Sshin#include <net/netisr.h>
5854263Sshin#include <net/route.h>
5954263Sshin#include <net/bpf.h>
6054263Sshin
6154263Sshinextern int loioctl __P((struct ifnet *, u_long, caddr_t));
6254263Sshinextern int looutput __P((struct ifnet *ifp,
6354263Sshin		struct mbuf *m, struct sockaddr *dst, struct rtentry *rt));
6454263Sshin
6554263Sshinvoid faithattach __P((void *));
6654263SshinPSEUDO_SET(faithattach, if_faith);
6754263Sshinstatic struct ifnet faithif[NFAITH];
6854263Sshin
6954263Sshin#define	FAITHMTU	1500
7054263Sshin
7154263Sshin/* ARGSUSED */
7254263Sshinvoid
7354263Sshinfaithattach(faith)
7454263Sshin	void *faith;
7554263Sshin{
7654263Sshin	register struct ifnet *ifp;
7754263Sshin	register int i;
7854263Sshin
7954263Sshin	for (i = 0; i < NFAITH; i++) {
8054263Sshin		ifp = &faithif[i];
8154263Sshin		bzero(ifp, sizeof(faithif[i]));
8254263Sshin		ifp->if_name = "faith";
8354263Sshin		ifp->if_unit = i;
8454263Sshin		ifp->if_mtu = FAITHMTU;
8554263Sshin		/* Change to BROADCAST experimentaly to announce its prefix. */
8654263Sshin		ifp->if_flags = /* IFF_LOOPBACK */ IFF_BROADCAST | IFF_MULTICAST;
8754263Sshin		ifp->if_ioctl = loioctl;
8854263Sshin		ifp->if_output = looutput;
8954263Sshin		ifp->if_type = IFT_FAITH;
9054263Sshin		ifp->if_snd.ifq_maxlen = ifqmaxlen;
9154263Sshin		ifp->if_hdrlen = 0;
9254263Sshin		ifp->if_addrlen = 0;
9354263Sshin		if_attach(ifp);
9454263Sshin		bpfattach(ifp, DLT_NULL, sizeof(u_int));
9554263Sshin	}
9654263Sshin}
9754263Sshin#endif /* NFAITH > 0 */
98