~kris/9p

9hist

ref: d5b7c5eed3d0cf563e4efaef9089fb5db9878f43 9hist/port/netif.h -rw-r--r-- 2.0 KiB
d5b7c5ee — David du Colombier Plan 9 from Bell Labs 1996-06-13 30 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
typedef struct Etherpkt	Etherpkt;
typedef struct Netfile	Netfile;
typedef struct Netif	Netif;

enum
{
	Nmaxaddr=	64,

	Ncloneqid=	1,
	N2ndqid,
	N3rdqid,
	Ndataqid,
	Nctlqid,
	Nstatqid,
	Ntypeqid,
	Nifstatqid,
};

/*
 *  Macros to manage Qid's used for multiplexed devices
 */
#define NETTYPE(x)	((x)&0x1f)
#define NETID(x)	(((x)&~CHDIR)>>5)
#define NETQID(i,t)	(((i)<<5)|(t))

/*
 *  one per multiplexed connection
 */
struct Netfile
{
	QLock;

	int	inuse;
	ulong	mode;
	char	owner[NAMELEN];

	int	type;		/* multiplexor type */
	int	prom;		/* promiscuous mode */

	Queue	*in;		/* input buffer */
};

/*
 *  a network interface
 */
struct Netif
{
	QLock;

	/* multiplexing */
	char	*name;			/* for top level directory */
	int	nfile;			/* max number of Netfiles */
	Netfile	**f;
	Queue	*out;			/* output buffer */

	/* about net */
	int	limit;			/* flow control */
	int	alen;			/* address length */
	uchar	addr[Nmaxaddr];
	uchar	bcast[Nmaxaddr];
	int	prom;			/* number of promiscuous opens */
	int	all;			/* number of -1 multiplexors */

	/* statistics */
	int	misses;
	int	inpackets;
	int	outpackets;
	int	crcs;		/* input crc errors */
	int	oerrs;		/* output errors */
	int	frames;		/* framing errors */
	int	overflows;	/* packet overflows */
	int	buffs;		/* buffering errors */
	int	soverflows;	/* software overflow */

	/* routines for touching the hardware */
	void	*arg;
	void	(*promiscuous)(void*, int);
};

void	netifinit(Netif*, char*, int, ulong);
int	netifwalk(Netif*, Chan*, char*);
Chan*	netifopen(Netif*, Chan*, int);
void	netifclose(Netif*, Chan*);
long	netifread(Netif*, Chan*, void*, long, ulong);
long	netifwrite(Netif*, Chan*, void*, long);
void	netifwstat(Netif*, Chan*, char*);
void	netifstat(Netif*, Chan*, char*);

/*
 *  Ethernet specific
 */
enum
{
	Eaddrlen=	6,
	ETHERMINTU =	60,		/* minimum transmit size */
	ETHERMAXTU =	1514,		/* maximum transmit size */
	ETHERHDRSIZE =	14,		/* size of an ethernet header */
};

struct Etherpkt
{
	uchar	d[Eaddrlen];
	uchar	s[Eaddrlen];
	uchar	type[2];
	uchar	data[1500];
};

extern uchar etherbcast[6];