1 /* 2 * INET An implementation of the TCP/IP protocol suite for the LINUX 3 * operating system. INET is implemented using the BSD Socket 4 * interface as the means of communication with the user level. 5 * 6 * Definitions for the Interfaces handler. 7 * 8 * Version: @(#)dev.h 1.0.10 08/12/93 9 * 10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu> 11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 12 * Corey Minyard <wf-rch!minyard@relay.EU.net> 13 * Donald J. Becker, <becker@super.org> 14 * Alan Cox, <A.Cox@swansea.ac.uk> 15 * Bjorn Ekwall. <bj0rn@blox.se> 16 * 17 * This program is free software; you can redistribute it and/or 18 * modify it under the terms of the GNU General Public License 19 * as published by the Free Software Foundation; either version 20 * 2 of the License, or (at your option) any later version. 21 * 22 * Moved to /usr/include/linux for NET3 23 */ 24 #ifndef_LINUX_NETDEVICE_H 25 #define_LINUX_NETDEVICE_H 26
27 #include <linux/config.h>
28 #include <linux/if.h>
29 #include <linux/if_ether.h>
30 #include <linux/skbuff.h>
31
32 /* for future expansion when we will have different priorities. */ 33 #defineDEV_NUMBUFFS 3
34 #defineMAX_ADDR_LEN 7
35 #ifndefCONFIG_AX25 36 #ifndefCONFIG_TR 37 #ifndefCONFIG_NET_IPIP 38 #defineMAX_HEADER 32 /* We really need about 18 worst case .. so 32 is aligned */ 39 #else 40 #defineMAX_HEADER 48 /* We need to allow for having tunnel headers */ 41 #endif/* IPIP */ 42 #else 43 #defineMAX_HEADER 48 /* Token Ring header needs 40 bytes ... 48 is aligned */ 44 #endif/* TR */ 45 #else 46 #defineMAX_HEADER 96 /* AX.25 + NetROM */ 47 #endif/* AX25 */ 48
49 #defineIS_MYADDR 1 /* address is (one of) our own */ 50 #define IS_LOOPBACK 2 /* address is for LOOPBACK */ 51 #defineIS_BROADCAST 3 /* address is a valid broadcast */ 52 #define IS_INVBCAST 4 /* Wrong netmask bcast not for us (unused)*/ 53 #defineIS_MULTICAST 5 /* Multicast IP address */ 54
55 /* 56 * We tag multicasts with these structures. 57 */ 58
59 structdev_mc_list 60 { 61 structdev_mc_list *next;
62 chardmi_addr[MAX_ADDR_LEN];
63 unsignedshortdmi_addrlen;
64 unsignedshortdmi_users;
65 };
66
67 structhh_cache 68 { 69 structhh_cache *hh_next;
70 void *hh_arp; /* Opaque pointer, used by 71 * any address resolution module, 72 * not only ARP. 73 */ 74 unsignedinthh_refcnt; /* number of users */ 75 unsignedshorthh_type; /* protocol identifier, f.e ETH_P_IP */ 76 charhh_uptodate; /* hh_data is valid */ 77 charhh_data[16]; /* cached hardware header */ 78 };
79
80 /* 81 * The DEVICE structure. 82 * Actually, this whole structure is a big mistake. It mixes I/O 83 * data with strictly "high-level" data, and it has to know about 84 * almost every data structure used in the INET module. 85 */ 86 structdevice 87 { 88
89 /* 90 * This is the first field of the "visible" part of this structure 91 * (i.e. as seen by users in the "Space.c" file). It is the name 92 * the interface. 93 */ 94 char *name;
95
96 /* I/O specific fields - FIXME: Merge these and struct ifmap into one */ 97 unsignedlongrmem_end; /* shmem "recv" end */ 98 unsignedlongrmem_start; /* shmem "recv" start */ 99 unsignedlongmem_end; /* shared mem end */ 100 unsignedlongmem_start; /* shared mem start */ 101 unsignedlongbase_addr; /* device I/O address */ 102 unsignedcharirq; /* device IRQ number */ 103
104 /* Low-level status flags. */ 105 volatileunsignedcharstart, /* start an operation */ 106 interrupt; /* interrupt arrived */ 107 unsignedlongtbusy; /* transmitter busy must be long for bitops */ 108
109 structdevice *next;
110
111 /* The device initialization function. Called only once. */ 112 int (*init)(structdevice *dev);
113
114 /* Some hardware also needs these fields, but they are not part of the 115 usual set specified in Space.c. */ 116 unsignedcharif_port; /* Selectable AUI, TP,..*/ 117 unsignedchardma; /* DMA channel */ 118
119 structenet_statistics* (*get_stats)(structdevice *dev);
120
121 /* 122 * This marks the end of the "visible" part of the structure. All 123 * fields hereafter are internal to the system, and may change at 124 * will (read: may be cleaned up at will). 125 */ 126
127 /* These may be needed for future network-power-down code. */ 128 unsignedlongtrans_start; /* Time (in jiffies) of last Tx */ 129 unsignedlonglast_rx; /* Time of last Rx */ 130
131 unsignedshortflags; /* interface flags (a la BSD) */ 132 unsignedshortfamily; /* address family ID (AF_INET) */ 133 unsignedshortmetric; /* routing metric (not used) */ 134 unsignedshortmtu; /* interface MTU value */ 135 unsignedshorttype; /* interface hardware type */ 136 unsignedshorthard_header_len; /* hardware hdr length */ 137 void *priv; /* pointer to private data */ 138
139 /* Interface address info. */ 140 unsignedcharbroadcast[MAX_ADDR_LEN]; /* hw bcast add */ 141 unsignedcharpad; /* make dev_addr aligned to 8 bytes */ 142 unsignedchardev_addr[MAX_ADDR_LEN]; /* hw address */ 143 unsignedcharaddr_len; /* hardware address length */ 144 unsignedlongpa_addr; /* protocol address */ 145 unsignedlongpa_brdaddr; /* protocol broadcast addr */ 146 unsignedlongpa_dstaddr; /* protocol P-P other side addr */ 147 unsignedlongpa_mask; /* protocol netmask */ 148 unsignedshortpa_alen; /* protocol address length */ 149
150 structdev_mc_list *mc_list; /* Multicast mac addresses */ 151 intmc_count; /* Number of installed mcasts */ 152
153 structip_mc_list *ip_mc_list; /* IP multicast filter chain */ 154 __u32tx_queue_len; /* Max frames per queue allowed */ 155
156 /* For load balancing driver pair support */ 157
158 unsignedlong pkt_queue; /* Packets queued */ 159 structdevice *slave; /* Slave device */ 160 structnet_alias_info *alias_info; /* main dev alias info */ 161 structnet_alias *my_alias; /* alias devs */ 162
163 /* Pointer to the interface buffers. */ 164 structsk_buff_headbuffs[DEV_NUMBUFFS];
165
166 /* Pointers to interface service routines. */ 167 int (*open)(structdevice *dev);
168 int (*stop)(structdevice *dev);
169 int (*hard_start_xmit) (structsk_buff *skb,
170 structdevice *dev);
171 int (*hard_header) (structsk_buff *skb,
172 structdevice *dev,
173 unsignedshorttype,
174 void *daddr,
175 void *saddr,
176 unsignedlen);
177 int (*rebuild_header)(void *eth, structdevice *dev,
178 unsignedlongraddr, structsk_buff *skb);
179 #defineHAVE_MULTICAST 180 void (*set_multicast_list)(structdevice *dev);
181 #defineHAVE_SET_MAC_ADDR 182 int (*set_mac_address)(structdevice *dev, void *addr);
183 #define HAVE_PRIVATE_IOCTL
184 int (*do_ioctl)(structdevice *dev, structifreq *ifr, intcmd);
185 #define HAVE_SET_CONFIG
186 int (*set_config)(structdevice *dev, structifmap *map);
187 #define HAVE_HEADER_CACHE
188 void (*header_cache_bind)(structhh_cache **hhp, structdevice *dev, unsignedshorthtype, __u32daddr);
189 void (*header_cache_update)(structhh_cache *hh, structdevice *dev, unsignedchar * haddr);
190 };
191
192
193 structpacket_type{ 194 unsignedshorttype; /* This is really htons(ether_type). */ 195 structdevice * dev;
196 int (*func) (structsk_buff *, structdevice *,
197 structpacket_type *);
198 void *data;
199 structpacket_type *next;
200 };
201
202
203 #ifdef__KERNEL__ 204
205 #include <linux/notifier.h>
206
207 /* Used by dev_rint */ 208 #define IN_SKBUFF 1
209
210 externvolatileunsignedlongin_bh;
211
212 externstructdeviceloopback_dev;
213 externstructdevice *dev_base;
214 externstructpacket_type *ptype_base[16];
215
216
217 externint ip_addr_match(unsignedlong addr1, unsignedlong addr2);
218 externintip_chk_addr(unsignedlongaddr);
219 externstructdevice *ip_dev_check(unsignedlongdaddr);
220 externunsignedlongip_my_addr(void);
221 externunsignedlongip_get_mask(unsignedlongaddr);
222 externstructdevice *ip_dev_find(unsignedlongaddr);
223 externstructdevice *dev_getbytype(unsignedshorttype);
224
225 externvoiddev_add_pack(structpacket_type *pt);
226 externvoiddev_remove_pack(structpacket_type *pt);
227 externstructdevice *dev_get(constchar *name);
228 externintdev_open(structdevice *dev);
229 externintdev_close(structdevice *dev);
230 externvoiddev_queue_xmit(structsk_buff *skb, structdevice *dev,
231 intpri);
232 #define HAVE_NETIF_RX 1
233 externvoidnetif_rx(structsk_buff *skb);
234 externvoiddev_transmit(void);
235 externintin_net_bh(void);
236 externvoidnet_bh(void);
237 externvoiddev_tint(structdevice *dev);
238 externintdev_get_info(char *buffer, char **start, off_toffset, intlength, intdummy);
239 externintdev_ioctl(unsignedintcmd, void *);
240
241 externvoid dev_init(void);
242
243 /* Locking protection for page faults during outputs to devices unloaded during the fault */ 244
245 externintdev_lockct;
246
247 /* 248 * These two dont currently need to be interrupt safe 249 * but they may do soon. Do it properly anyway. 250 */ 251
252 extern__inline__voiddev_lock_list(void)
/* */ 253 { 254 unsignedlongflags;
255 save_flags(flags);
256 cli();
257 dev_lockct++;
258 restore_flags(flags);
259 } 260
261 extern__inline__voiddev_unlock_list(void)
/* */ 262 { 263 unsignedlongflags;
264 save_flags(flags);
265 cli();
266 dev_lockct--;
267 restore_flags(flags);
268 } 269
270 /* 271 * This almost never occurs, isnt in performance critical paths 272 * and we can thus be relaxed about it 273 */ 274
275 extern__inline__voiddev_lock_wait(void)
/* */ 276 { 277 while(dev_lockct)
278 schedule();
279 } 280
281
282 /* These functions live elsewhere (drivers/net/net_init.c, but related) */ 283
284 externvoidether_setup(structdevice *dev);
285 externvoidtr_setup(structdevice *dev);
286 externintether_config(structdevice *dev, structifmap *map);
287 /* Support for loadable net-drivers */ 288 externintregister_netdev(structdevice *dev);
289 externvoidunregister_netdev(structdevice *dev);
290 externintregister_netdevice_notifier(structnotifier_block *nb);
291 externintunregister_netdevice_notifier(structnotifier_block *nb);
292 /* Functions used for multicast support */ 293 externvoiddev_mc_upload(structdevice *dev);
294 externvoiddev_mc_delete(structdevice *dev, void *addr, intalen, intall);
295 externvoiddev_mc_add(structdevice *dev, void *addr, intalen, intnewonly);
296 externvoiddev_mc_discard(structdevice *dev);
297 /* This is the wrong place but it'll do for the moment */ 298 externvoidip_mc_allhost(structdevice *dev);
299 #endif/* __KERNEL__ */ 300
301 #endif/* _LINUX_DEV_H */