vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

netif.h (3078B)


      1 typedef struct Etherpkt	Etherpkt;
      2 typedef struct Netaddr	Netaddr;
      3 typedef struct Netfile	Netfile;
      4 typedef struct Netif	Netif;
      5 
      6 enum
      7 {
      8 	Nmaxaddr=	64,
      9 	Nmhash=		31,
     10 
     11 	Ncloneqid=	1,
     12 	Naddrqid,
     13 	N2ndqid,
     14 	N3rdqid,
     15 	Ndataqid,
     16 	Nctlqid,
     17 	Nstatqid,
     18 	Ntypeqid,
     19 	Nifstatqid,
     20 };
     21 
     22 /*
     23  *  Macros to manage Qid's used for multiplexed devices
     24  */
     25 #define NETTYPE(x)	(((ulong)x)&0x1f)
     26 #define NETID(x)	((((ulong)x))>>5)
     27 #define NETQID(i,t)	((((ulong)i)<<5)|(t))
     28 
     29 /*
     30  *  one per multiplexed connection
     31  */
     32 struct Netfile
     33 {
     34 	QLock	qlock; 
     35 
     36 	int	inuse;
     37 	ulong	mode;
     38 	char	owner[KNAMELEN];
     39 
     40 	int	type;			/* multiplexor type */
     41 	int	prom;			/* promiscuous mode */
     42 	int	scan;			/* base station scanning interval */
     43 	int	bridge;			/* bridge mode */
     44 	int	headersonly;		/* headers only - no data */
     45 	uchar	maddr[8];		/* bitmask of multicast addresses requested */
     46 	int	nmaddr;			/* number of multicast addresses */
     47 
     48 	Queue	*in;			/* input buffer */
     49 };
     50 
     51 /*
     52  *  a network address
     53  */
     54 struct Netaddr
     55 {
     56 	Netaddr	*next;		/* allocation chain */
     57 	Netaddr	*hnext;
     58 	uchar	addr[Nmaxaddr];
     59 	int	ref;
     60 };
     61 
     62 /*
     63  *  a network interface
     64  */
     65 struct Netif
     66 {
     67 	QLock	qlock;
     68 
     69 	/* multiplexing */
     70 	char	name[KNAMELEN];		/* for top level directory */
     71 	int	nfile;			/* max number of Netfiles */
     72 	Netfile	**f;
     73 
     74 	/* about net */
     75 	int	limit;			/* flow control */
     76 	int	alen;			/* address length */
     77 	int	mbps;			/* megabits per sec */
     78 	int	link;			/* link status */
     79 	uchar	addr[Nmaxaddr];
     80 	uchar	bcast[Nmaxaddr];
     81 	Netaddr	*maddr;			/* known multicast addresses */
     82 	int	nmaddr;			/* number of known multicast addresses */
     83 	Netaddr *mhash[Nmhash];		/* hash table of multicast addresses */
     84 	int	prom;			/* number of promiscuous opens */
     85 	int	scan;			/* number of base station scanners */
     86 	int	all;			/* number of -1 multiplexors */
     87 
     88 	/* statistics */
     89 	int	misses;
     90 	uvlong	inpackets;
     91 	uvlong	outpackets;
     92 	int	crcs;		/* input crc errors */
     93 	int	oerrs;		/* output errors */
     94 	int	frames;		/* framing errors */
     95 	int	overflows;	/* packet overflows */
     96 	int	buffs;		/* buffering errors */
     97 	int	soverflows;	/* software overflow */
     98 
     99 	/* routines for touching the hardware */
    100 	void	*arg;
    101 	void	(*promiscuous)(void*, int);
    102 	void	(*multicast)(void*, uchar*, int);
    103 	void	(*scanbs)(void*, uint);	/* scan for base stations */
    104 };
    105 
    106 void	netifinit(Netif*, char*, int, ulong);
    107 Walkqid*	netifwalk(Netif*, Chan*, Chan*, char **, int);
    108 Chan*	netifopen(Netif*, Chan*, int);
    109 void	netifclose(Netif*, Chan*);
    110 long	netifread(Netif*, Chan*, void*, long, ulong);
    111 Block*	netifbread(Netif*, Chan*, long, ulong);
    112 long	netifwrite(Netif*, Chan*, void*, long);
    113 int	netifwstat(Netif*, Chan*, uchar*, int);
    114 int	netifstat(Netif*, Chan*, uchar*, int);
    115 int	activemulti(Netif*, uchar*, int);
    116 
    117 /*
    118  *  Ethernet specific
    119  */
    120 enum
    121 {
    122 	Eaddrlen=	6,
    123 	ETHERMINTU =	60,		/* minimum transmit size */
    124 	ETHERMAXTU =	1514,		/* maximum transmit size */
    125 	ETHERHDRSIZE =	14,		/* size of an ethernet header */
    126 
    127 	/* ethernet packet types */
    128 	ETARP		= 0x0806,
    129 	ETIP4		= 0x0800,
    130 	ETIP6		= 0x86DD,
    131 };
    132 
    133 struct Etherpkt
    134 {
    135 	uchar	d[Eaddrlen];
    136 	uchar	s[Eaddrlen];
    137 	uchar	type[2];
    138 	uchar	data[1500];
    139 };