xref: /plan9/sys/src/cmd/unix/drawterm/kern/netif.h (revision 8ccd4a6360d974db7bd7bbd4f37e7018419ea908)
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 lk;
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 lk;
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 	uchar	addr[Nmaxaddr];
79 	uchar	bcast[Nmaxaddr];
80 	Netaddr	*maddr;			/* known multicast addresses */
81 	int	nmaddr;			/* number of known multicast addresses */
82 	Netaddr *mhash[Nmhash];		/* hash table of multicast addresses */
83 	int	prom;			/* number of promiscuous opens */
84 	int	scan;			/* number of base station scanners */
85 	int	all;			/* number of -1 multiplexors */
86 
87 	/* statistics */
88 	int	misses;
89 	int	inpackets;
90 	int	outpackets;
91 	int	crcs;		/* input crc errors */
92 	int	oerrs;		/* output errors */
93 	int	frames;		/* framing errors */
94 	int	overflows;	/* packet overflows */
95 	int	buffs;		/* buffering errors */
96 	int	soverflows;	/* software overflow */
97 
98 	/* routines for touching the hardware */
99 	void	*arg;
100 	void	(*promiscuous)(void*, int);
101 	void	(*multicast)(void*, uchar*, int);
102 	void	(*scanbs)(void*, uint);	/* scan for base stations */
103 };
104 
105 void	netifinit(Netif*, char*, int, ulong);
106 Walkqid*	netifwalk(Netif*, Chan*, Chan*, char **, int);
107 Chan*	netifopen(Netif*, Chan*, int);
108 void	netifclose(Netif*, Chan*);
109 long	netifread(Netif*, Chan*, void*, long, ulong);
110 Block*	netifbread(Netif*, Chan*, long, ulong);
111 long	netifwrite(Netif*, Chan*, void*, long);
112 int	netifwstat(Netif*, Chan*, uchar*, int);
113 int	netifstat(Netif*, Chan*, uchar*, int);
114 int	activemulti(Netif*, uchar*, int);
115 
116 /*
117  *  Ethernet specific
118  */
119 enum
120 {
121 	Eaddrlen=	6,
122 	ETHERMINTU =	60,		/* minimum transmit size */
123 	ETHERMAXTU =	1514,		/* maximum transmit size */
124 	ETHERHDRSIZE =	14,		/* size of an ethernet header */
125 };
126 
127 struct Etherpkt
128 {
129 	uchar	d[Eaddrlen];
130 	uchar	s[Eaddrlen];
131 	uchar	type[2];
132 	uchar	data[1500];
133 };
134