xref: /plan9-contrib/sys/src/9k/port/netif.h (revision 277b6efdcc262cd4d08d05822b6e10d78be9f0bc)
1 typedef struct Netaddr	Netaddr;
2 typedef struct Netfile	Netfile;
3 typedef struct Netif	Netif;
4 
5 enum
6 {
7 	Nmaxaddr=	64,
8 	Nmhash=		31,
9 
10 	Ncloneqid=	1,
11 	Naddrqid,
12 	N2ndqid,
13 	N3rdqid,
14 	Ndataqid,
15 	Nctlqid,
16 	Nstatqid,
17 	Ntypeqid,
18 	Nifstatqid,
19 	Nmtuqid,
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;
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*	iq;			/* input */
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;
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 	int	minmtu;
80 	int 	maxmtu;
81 	int	mtu;
82 	uchar	addr[Nmaxaddr];
83 	uchar	bcast[Nmaxaddr];
84 	Netaddr	*maddr;			/* known multicast addresses */
85 	int	nmaddr;			/* number of known multicast addresses */
86 	Netaddr *mhash[Nmhash];		/* hash table of multicast addresses */
87 	int	prom;			/* number of promiscuous opens */
88 	int	scan;			/* number of base station scanners */
89 	int	all;			/* number of -1 multiplexors */
90 
91 	Queue*	oq;			/* output */
92 
93 	/* statistics */
94 	int	misses;
95 	uvlong	inpackets;
96 	uvlong	outpackets;
97 	int	crcs;			/* input crc errors */
98 	int	oerrs;			/* output errors */
99 	int	frames;			/* framing errors */
100 	int	overflows;		/* packet overflows */
101 	int	buffs;			/* buffering errors */
102 	int	soverflows;		/* software overflow */
103 
104 	/* routines for touching the hardware */
105 	void	*arg;
106 	void	(*promiscuous)(void*, int);
107 	void	(*multicast)(void*, uchar*, int);
108 	int	(*hwmtu)(void*, int);	/* get/set mtu */
109 	void	(*scanbs)(void*, uint);	/* scan for base stations */
110 };
111 
112 void	netifinit(Netif*, char*, int, ulong);
113 Walkqid*	netifwalk(Netif*, Chan*, Chan*, char **, int);
114 Chan*	netifopen(Netif*, Chan*, int);
115 void	netifclose(Netif*, Chan*);
116 long	netifread(Netif*, Chan*, void*, long, vlong);
117 Block*	netifbread(Netif*, Chan*, long, vlong);
118 long	netifwrite(Netif*, Chan*, void*, long);
119 long	netifwstat(Netif*, Chan*, uchar*, long);
120 long	netifstat(Netif*, Chan*, uchar*, long);
121 int	activemulti(Netif*, uchar*, int);
122