⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 if_ulip.c

📁 Tornado 2.0.2 source code!vxworks的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* if_ulip.c - network interface driver for User Level IP (VxSim) *//* Copyright 1984-1997 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02s,03apr99,jdi  doc: updated SEE ALSO cross-reference for T2.02r,09feb99,wsl  added comments documenting ERRNO codes02q,19Aug97,cth  Changed ULIP_MTU and if_mtu registered with IP for 		 simsolaris (SPR 8460)01p,01may97,spm  replaced ether_output() and do_protocol() in BSD 4.4 version 02p,19Aug97,cth  Changed ULIP_MTU and if_mtu registered with IP for 		 simsolaris (SPR 8460)02o,21mar97,cth  added FIOSETUSED ioctl (SPR 8221), added ulipDebugSet 		 function and FIOSETD definition (SPR 8240).02n,24feb97,jank corrected if CPU check L:12002m,06sep96,ism  added hack to generate extra SIGPOLL after init on solaris.02l,23jul96,ism  cleanup sim/solaris version.02m,07apr97,spm  code cleanup, corrected statistics, and upgraded to BSD 4.402m,06dec96,cdp  fixed #ifdef which should have been #if (sim/solaris).02k,10apr96,ism  added simsolaris ReadUlip call replacing read()02j,08apr96,ism  added simsolaris WriteUlip call replacing write()02i,26jan95,jdi  doc tweaks.02h,02jun94,ms   locked interrupts in ulconnect() for HPPA.02g,26jan94,gae  fixed warnings.02f,04jan94,gae  added pseudo-SIOCGIFADDR IP address check.02e,24aug93,gae  documentation tweaks.02d,30jul93,gae  added ether header to MTU in temp buffers.02c,05jul93,gae  added test for procnum equal to last ip octet.02b,12may93,rrr  fixed intLock's in ulread().02a,28jan93,gae  5.1 update; reworked interrupts.01d,05aug92,gae  free'd and detach'd i/f that doesn't connect properly.01c,29jul92,gae  IP address not user settable - fixed /dev's; debug mode ioctl.01b,22apr92,gae  fixed arpcom structure; merged with ulipunix.c;		 used if_subr routines; put packets in SOFTC; other cleanup.01a,22feb92,smeg derived from SLIP.*//*DESCRIPTIONThis module implements the VxWorks User Level IP (ULIP) network driver.The ULIP driver allows VxWorks under UNIX to talk to other machinesby handing off IP packets to the UNIX host for processing.The ULIP driver is automatically included and initialized by the VxSimBSPs; normally there is no need for applications to use these routinesdirectly.USER CALLABLE ROUTINESWhen initializing the device, it is necessary to specifythe Internet address for both sides of the ULIP point-to-pointlink (local side and the remote side of the connection) using ulipInit()..CS    STATUS ulipInit	(	int unit,	/@ ULIP unit number (0 - NULIP-1) @/	char *myAddr,   /@ IP address of the interface @/	char *peerAddr, /@ IP address of the remote peer interface @/	int procnum     /@ processor number to map to ULIP interface @/	).CEFor example, the following initializes a ULIP device whoseInternet address is 127.0.1.1:.CS    ulipInit (0, "127.0.1.1", "147.11.1.132", 1);.CEThe standard network interface call is:.CS    STATUS ulattach	(	int unit  /@ unit number @/	).CEHowever, it should not be called.  The following call will deletethe first ULIP interface from the list of network interfaces:.CS    ulipDelete (0);	/@ unit number @/.CEUp to NULIP(2) units may be created.SEE ALSO.pG "VxSim"*/#include "vxWorks.h"#include "net/mbuf.h"#include "socket.h"#include "ioctl.h"#include "errno.h"#include "ioLib.h"#include "tickLib.h"#include "net/if.h"#include "net/route.h"#include "in.h"#include "ifLib.h"#include "inetLib.h"#include "routeLib.h"#include "netLib.h"#include "netinet/if_ether.h"#include "netinet/in_systm.h"#include "netinet/in_var.h"#include "netinet/ip.h"#include "systime.h"#include "stdlib.h"#include "stdio.h"#include "net/if_subr.h"#include "net/unixLib.h"#include "drv/netif/if_ul.h"#include "iv.h"#include "intLib.h"#include "u_Lib.h"#include "simLib.h"#if (CPU==SIMSPARCSOLARIS)#include "arch/simsolaris/ulipSimsolaris.h"#endif /* (CPU==SIMSPARCSOLARIS) */extern int u_printf ();extern void if_down ();extern void if_dettach ();/*+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=*/#define	ULIP_VERSION	"ulip 2.1"	/* version 1.0 is BNR original */#define MAX_ULIPS 16#if CPU==SIMSPARCSOLARIS#define ULIP_MTU 		1020#else /* CPU==SIMSPARCSOLARIS */#define ULIP_MTU 		1536#endif /* CPU==SIMSPARCSOLARIS */#ifdef	__STDC__#define FIOSETR		_IO('f', 66)		/* set r */#if CPU==SIMSPARCSOLARIS#define FIOSETD		(('l'<<8)|2)		/* turn on/off unix debugging */#define FIOSETUSED	(('l'<<8)|4)		/* turn on/off unix used flag */#else#define FIOSETD		_IOWR('f', 65, int)	/* set debug */#endif /* SIMSPARCSOLARIS */#define	SIOCSIFADDR	_IOW('i', 12, struct ifreq)	/* set ifnet address */#else#define FIOSETR		_IO(f, 66)		/* set r */#if CPU==SIMSPARCSOLARIS#define FIOSETD		((l<<8)|2)		/* turn on/off unix debugging */#define FIOSETUSED	((l<<8)|4)		/* turn on/off unix used flag */#else#define FIOSETD		_IOWR(f, 65, int)	/* set debug */#endif /* SIMSPARCSOLARIS */#define	SIOCSIFADDR	_IOW(i, 12, struct ifreq)	/* set ifnet address */#define	SIOCGIFADDR	_IOWR(i,13, struct ifreq)	/* get ifnet address */#endif	/* __STDC__ */#define	ULIP_LOG_INFO	TRUE/* ulipDebug is used to indicate the amount of debug messages * desired (they are printf'd from the kernel).  the FIOSETD * ioctl allows users to change this value. */#define ULIP_DEBUG_TRACE_ALL	0#define ULIP_DEBUG_ERRNO	5#define ULIP_DEBUG_NONE		100int uldebug = 0;extern int ulDebug; /* debug switch for UNIX driver: 0=all, 5=errno, 100=none *//*+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=*/typedef	struct		/* UL_SOFTC */	{	struct	arpcom sc_ac;		/* Ethernet common part */#define sc_if	sc_ac.ac_if		/* network-visible interface */	char devUlip [30];		/* usually "/dev/ulipNN" */	int ulipFd;			/* UNIX file descriptor */	long ipaddr;			/* UNIX's associated IP address */	volatile int ulReadLoop;	/* in readloop (don't add netjobs) */	} UL_SOFTC;#define NULIP	2	/* max. number of ULIP interfaces (only 1 tested) */LOCAL UL_SOFTC *ul_softc [NULIP];/* forward declarations */STATUS		ulattach ();STATUS		ulipDelete ();LOCAL STATUS 	uloutput ();#ifdef BSD43_DRIVERLOCAL STATUS ulStartOutput (int unit);#elseLOCAL STATUS ulStartOutput (UL_SOFTC *sc);#endifLOCAL int 	ulinit ();LOCAL int 	ulioctl (); LOCAL int	ulconnect ();/********************************************************************************* ulipInit - initialize the ULIP interface (VxSim)** This routine initializes the ULIP interface and sets the Internet* address as a function of the processor number.** RETURNS: OK, or ERROR if the device cannot be opened or there is* insufficient memory.** ERRNO: S_if_ul_INVALID_UNIT_NUMBER** SEE ALSO* .I "VxSim User's Guide"*/STATUS ulipInit    (    int 	unit,		/* ULIP unit number (0 - NULIP-1) */    char	*myAddr,	/* IP address of the interface */    char        *peerAddr,	/* IP address of the remote peer interface */    int         procnum		/* processor number to map to ULIP interface */    )    {    UL_SOFTC	*sc;    char	ulipName [10];    if (unit < 0 || unit >= NULIP)	{	errno = S_if_ul_INVALID_UNIT_NUMBER;	return (ERROR);	}    if (ulattach (unit) == ERROR)	return (ERROR);    sc = ul_softc [unit];    if (procnum != (inet_addr (myAddr) & 0x000000ff))	{	u_printf ("ulipInit: bad procnum/addr x.x.x.%d != %s\n",		    procnum, myAddr);	}    sprintf (sc->devUlip, "/dev/ulip%d", procnum);    if (ulconnect (unit) < 0)	{	if_dettach (&sc->sc_if);	free ((char *) sc);	ul_softc [unit] = (UL_SOFTC *) NULL;	/* undo ulattach */	return (ERROR);	}    if (sc->ipaddr != -1 && inet_addr (myAddr) != sc->ipaddr)	{	u_printf ("ulipInit: IP's don't match %#x != %#x\n",	    inet_addr(myAddr), sc->ipaddr);	}    sprintf (ulipName, "ul%d", sc->sc_if.if_unit);    /* Set own and peer's Internet address.     * Add a routing table entry to tell how to loopback over ULIP.     * Point to point loopback routing table entry is required to     * properly talk to myself using the ULIP interface address.     */    if (ifAddrSet (ulipName, myAddr) == ERROR	   ||	ifDstAddrSet (ulipName, peerAddr) == ERROR ||	routeAdd (myAddr, myAddr) == ERROR)	{	return (ERROR);	}#if (CPU == SIMSPARCSOLARIS)    /*     * When vxWorks comes up, there might still be messages stuck in the ULIP     * driver from the last session (vxWorks cannot close the driver if it     * crashes).  Those messages will not be retrieved until a SIGPOLL is     * received, and Solaris will not send another SIGPOLL until the     * messages are received.  So the easy hack is to generate an extra     * SIGPOLL here, now that the ULIP driver is all set up.     */    u_kill (u_getpid(), 22 /* SIGPOLL */);#endif    return (OK);    }/********************************************************************************* ulattach - attach a ULIP interface to a list of network interfaces (VxSim)** This routine is called by ulipInit().  It inserts a pointer* to the ULIP interface data structure into a linked list of available* network interfaces.** RETURNS: OK or ERROR.** ERRNO: S_if_ul_UNIT_ALREADY_INITIALIZED** SEE ALSO* .I "VxSim User's Guide"*/STATUS ulattach    (    int unit		/* ULIP unit number */    )    {    UL_SOFTC		*sc;    struct ifnet	*ifp;    if (ul_softc [unit] != NULL)	{	errno = S_if_ul_UNIT_ALREADY_INITIALIZED;	return (ERROR);	}    if ((sc = (UL_SOFTC *) calloc (1, sizeof (UL_SOFTC))) == NULL)	return (ERROR);    ul_softc [unit] = sc;    ifp = &sc->sc_if;	/* get a pointer to ifnet structure */    ether_attach (ifp, unit, "ul", ulinit, ulioctl, uloutput, ulipDelete);    /*     * The MTUs for VxSim Solaris should be set as described below.  VxSim     * SunOS does not use STREAMS devices, and therefore does not have      * these limitations.  All of the conditions described below were found      * empiracally.       *     * The ULIP STREAMS devices can transfer a maximum of 1024 bytes, and     * so the Solaris ULIP driver should have an MTU of 1024 to allow it to     * read and write the maximum allowable data over the channel.     * VxSim's IP stack, however adds two (2) bytes to packets it sends     * to Solaris.  The stack determines the size of packets based on the     * if_mtu variable (set equal to ULIP_MTU + 2), and so it should     * be at most 1022.  Also, when packets arrive from Solaris, they      * have four (4) bytes of extra space at the end.  This means a max     * sized packet has size 1024, but has a 1020-byte message in it.  For     * this reason the VxSim IP stack should expect messages of at most     * 1020 bytes.  By registering if_mtu as 1020+2, however, IP will     * not throw away packets for being too large; and the remaining four     * (4) bytes (in this case garbage) of all arriving packets normally      * contains trailer-packet information which will never be used by ULIP.     *     * For the reasons above the MTU's of host and target side should be:     *       Solaris-host ULIP driver MTU = 1024,     *       VxSim-target ULIP driver MTU = 1020,     *       VxSim-target if_mtu (for IP) = 1022 or (1020 + 2).     */#if (CPU==SIMSPARCSOLARIS)    ifp->if_mtu	= ULIP_MTU + 2;#else /* CPU==SIMSPARCSOLARIS */    ifp->if_mtu	= ULIP_MTU;#endif /* CPU==SIMSPARCSOLARIS */#ifndef BSD43_DRIVER    ifp->if_start = (FUNCPTR)ulStartOutput;#endif    ifp->if_flags = IFF_POINTOPOINT | IFF_NOTRAILERS | IFF_NOARP;    return (OK);    }/********************************************************************************* ulipDelete - delete a ULIP interface (VxSim)** This routine detaches the ULIP unit and frees up system resources taken up* by this ULIP interface.** RETURNS: OK, or ERROR if the unit number is invalid or the interface* is uninitialized.** ERRNO: S_if_ul_INVALID_UNIT_NUMBER, S_if_ul_UNIT_UNINITIALIZED** SEE ALSO* .I "VxSim User's Guide"*/STATUS ulipDelete    (    int unit		/* ULIP unit number */    )    {    UL_SOFTC *sc;    int s;#if    CPU==SIMSPARCSOLARIS    int isUsed;#endif /* SIMSPARCSOLARIS */    if (unit < 0 || unit >= NULIP)	{	errno = S_if_ul_INVALID_UNIT_NUMBER;	return (ERROR);	}    sc = ul_softc [unit];    if (sc == NULL)	{	errno = S_if_ul_UNIT_UNINITIALIZED;	return (ERROR);	}    s = splimp ();    if_down (&sc->sc_if);		/* mark it down */    splx (s);    /*     * Delete all routes associated with this ULIP interface.     * This will effectively delete the point-to-point routes for this ULIP.     */    ifRouteDelete ("ul", unit);    /*     * Take the pointer to this ULIP interface out of the linked list     * of all available network interfaces.  The if_dettach () will un-do     * the action taken by if_attach ().     */    if_dettach (&sc->sc_if);#if    CPU==SIMSPARCSOLARIS    /* Send ioctl to UNIX ulip driver to mark this processor number unused.     * This is marked as used in ulipconnect. s_ulipIoctl is called because     * the FIOSETUSED ioctl requires special bundling of its user data.     */    isUsed = 0;    s_ulipIoctl (sc->ulipFd, FIOSETUSED, (char *)&isUsed, sizeof (isUsed));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -