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