/* Copyright 1984 by the Massachusetts Institute of Technology */

/* Network structure. This is the heart of the rapid reconfigurability
 * of the gateway code. Each network interface that is connected to
 * the machine has a line in the table. It comes in two parts so it's
 * easy to set the initialized data in the configuration file (netcnf.c);
 * the initialized stuff is all at the front.
 *
 * There is additional per protocol information that gives things like
 * the interface addresses in a protocol specific form; this information
 * is kept in per protocol configuration files.
 *
 * The current network interface was designed to be highly flexible; it
 * provides a minimal interface for networks with very non-standard
 * software interface architectures, and a library of default routines
 * that work well with simple local networks. A network can use as many or
 * as few of these as it wants; there is no single set interface. In the
 * minimal case, a network must provide an initialization routine, which
 * is called once at startup, and is responsible for seeing that packet
 * input from the network is handled (input packets are generally handled
 * in the driver, for network support functions, or passed on to a higher
 * level protocol for forwarding), and a send routine (which is generally
 * called from a protocol packet forwarder which is called from the input
 * handler of some other net). For networks which use the library, these
 * entry points are subsumed by others, and in many cases, when using the
 * library, if no local handler is supplied (the entry is NULL) a default
 * handler is used. See gate.c for more details  on the general structure,
 * and net.c for details of the library routines.
 * 
 * Entry points and variables which must be provided  by networks which
 * use the standard library are marked with a $, and by # for those which
 * have default handler if the entry is NULL.
 * Note that any of these entries may be used by custom handlers (i.e. ones
 * which only use the simplest interface) for whatever they chose.
 *
 * Most of the entries are simple; the complicated ones are the action
 * routines, which are described in detail below.
 *
 * n_init	Responsible for activating the network in all details.
 *		This is called only once per system activation, but
 *		should be coded so that it can be called again if the
 *		entire system is restarted. If this field is NULL, the
 *		netinit library routine is used instead.
 *	args:	netp
 *	rets:	-
 *
 * n_prinit	Does per protocol initialization. If this field is
 *		NULL no per protocol initialization is done, but
 *		things like checking the interface address, etc. are
 *		strongly recommended.
 *	args:	netp, protocol, per-protocol-datum
 *	rets:	-
 *
 * n_send	Prepends all the local network headers and arranges
 *		for the packet to be sent. host is a pointer to the
 *		address of the immediate destination in a protocol
 *		specific form. There are two special defined addresses,
 *		for broadcast and packets for no host.
 *		For networks using the network library, you can use the
 *		routine netsend to handle all the queueing, etc. Just
 *		prepend all the local network headers and in general
 *		prepare the packet to be sent, and call netsend. You need
 *		to return the completioncode that netsend returns. In
 *		networks that use netsend and the supplied n_get routine
 * 		this should put in i_usr3 either a pointer to the local
 *		address that this packet is being sent to or up to one word
 *		of arbitrary data which will be used instead in a direct
 *		compare.
 *
 *	args:	iob, netp, prot, per-protocol-datum (usually next host)
 *	rets:	completion code
 *
 * The routine below here are only needed by nets which expect to
 * use the network library support code.
 *
 * n_start	Prepare a buffer for the read queue. Does necessary
 *		prelim work such as getting the header aligned correctly.
 *		if this is NULL, a header/trailer of the size listed in
 *		n_hsiz/n_tsiz is allowed for and no other processing is done.
 *	args:	iob
 *	rets:	-
 *
 * n_in		Given an input packet, it must grok the header and
 *		call the right forwarder routine.
 *	args:	iob
 *	rets:	-
 *
 * n_get	Looks through the waiting output queue and gets
 *		the next packet to be sent. It is able to thus
 *		completely control the output flow. If a delay is
 *		desired, it can call for a dally after which it will be
 *		called again. If this field is NULL, a supplied system
 *		one is used.
 *	args:	netp
 *	rets:	iob, or NULL if none
 *
 * n_cmp	Compares the two local addresses pointed at by the two
 *		arguments. Return true is they are different, otherwise
 *		false. Needed only if your driver returns pointers, not
 *		16 bit objects in i_usr3.
 *	args:	addr1, addr2
 *	rets:	true or false
 */


#define	net	struct	netstr

net	{	void	(*n_init)();	/* 00   Start ball rolling */
		void	(*n_prinit)();	/* 04   Per protocol initialization */
		word	(*n_send)();	/* 08   Complete output processor */
		void	(*n_start)();	/* 0c # Queue a read */
		void	(*n_in)();	/* 10 $ Read local hdr and dispatch */
		iorb	*(*n_get)();	/* 14 # Choose next pkt to send */
		word	(*n_cmp)();	/* 18 # Compare two addresses  */
		unsb	n_maxip;	/* 1c $ Max pkts to keep on sys */
		unsb	n_maxop;	/* 1d $ queues for i/p and o/p */
		unsb	n_maxr;		/* 1e $ Max no of retrys */
		byte	n_unus;		/* 1f   Unused */
		unsw	n_msiz;		/* 20 $ Max packet size for hrdwr */
		unsb	n_hsiz;		/* 24 $ Size of header */
		unsb	n_tsiz;		/* 25 $ Size of trailer (if any) */
		dct	*n_bdevp;	/* 28   Base device within group */
		dct	*n_idevp;	/* 2c $ Input device */
		dct	*n_odevp;	/* 30 $ Output device */
		byte	n_type;		/* 34 $ Network type code */
		bitb	n_cap;		/* 35 $ Network capability codes */

		unsb	n_int;		/* 36 Interface number */
		unsb	n_net;		/* 37 Network index number */
		bitb	n_flg;		/* 38 Status flags */
		unsb	n_siz;		/* 39 Total local overhead */
		unsw	n_max;		/* 3c Max pkt size without lcl hdr */
		void	(*n_irtn)();	/* 40 Input routine */
		void	(*n_ortn)();	/* 44 Output routine */
		unsb	n_ipc;		/* 48 No of packets in sys Q's */
		unsb	n_opc;		/* 49 for i/p and o/p */
		iorbq	n_ipq;		/* 4c Unprocessed packet queue */
		iorbq	n_opq;		/* 58 Output hold queue */
		word	n_lsthst;	/* 64 Last host packet sent to */
		word	n_pernet;	/* 68 Per network data */
		unsl	n_pkti;		/* 6c Statistics */
		unsl	n_byti;		/* 70 */
		unsl	n_pkto;		/* 74 */
		unsl	n_byto;		/* 78 */
		unsw	n_ioin;		/* 7c I/O errors */
		unsw	n_ioout;	/* 80 */
		unsw	n_ovfin;	/* 84 Overflow discards */
		unsw	n_ovfout;	/* 88 */
		unsw	n_disc;		/* 8c Random errors */
		};

#define	mknet(x)	((net *) (x))
