]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/net/tcpip/v2_0/include/net/if.h
Initial revision
[karo-tx-redboot.git] / packages / net / tcpip / v2_0 / include / net / if.h
1 //==========================================================================
2 //
3 //      include/net/if.h
4 //
5 //      
6 //
7 //==========================================================================
8 //####BSDCOPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 //
12 // Portions of this software may have been derived from OpenBSD or other sources,
13 // and are covered by the appropriate copyright disclaimers included herein.
14 //
15 // -------------------------------------------
16 //
17 //####BSDCOPYRIGHTEND####
18 //==========================================================================
19 //#####DESCRIPTIONBEGIN####
20 //
21 // Author(s):    gthomas
22 // Contributors: gthomas
23 // Date:         2000-01-10
24 // Purpose:      
25 // Description:  
26 //              
27 //
28 //####DESCRIPTIONEND####
29 //
30 //==========================================================================
31
32
33 /*      $OpenBSD: if.h,v 1.14 1999/12/08 06:50:17 itojun Exp $  */
34 /*      $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $  */
35
36 /*
37  * Copyright (c) 1982, 1986, 1989, 1993
38  *      The Regents of the University of California.  All rights reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  * 1. Redistributions of source code must retain the above copyright
44  *    notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  *    notice, this list of conditions and the following disclaimer in the
47  *    documentation and/or other materials provided with the distribution.
48  * 3. All advertising materials mentioning features or use of this software
49  *    must display the following acknowledgement:
50  *      This product includes software developed by the University of
51  *      California, Berkeley and its contributors.
52  * 4. Neither the name of the University nor the names of its contributors
53  *    may be used to endorse or promote products derived from this software
54  *    without specific prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66  * SUCH DAMAGE.
67  *
68  *      @(#)if.h        8.1 (Berkeley) 6/10/93
69  */
70
71 #ifndef _NET_IF_H_
72 #define _NET_IF_H_
73
74 #include <sys/queue.h>
75
76 /*
77  * Structures defining a network interface, providing a packet
78  * transport mechanism (ala level 0 of the PUP protocols).
79  *
80  * Each interface accepts output datagrams of a specified maximum
81  * length, and provides higher level routines with input datagrams
82  * received from its medium.
83  *
84  * Output occurs when the routine if_output is called, with four parameters:
85  *      (*ifp->if_output)(ifp, m, dst, rt)
86  * Here m is the mbuf chain to be sent and dst is the destination address.
87  * The output routine encapsulates the supplied datagram if necessary,
88  * and then transmits it on its medium.
89  *
90  * On input, each interface unwraps the data received by it, and either
91  * places it on the input queue of a internetwork datagram routine
92  * and posts the associated software interrupt, or passes the datagram to a raw
93  * packet input routine.
94  *
95  * Routines exist for locating interfaces by their addresses
96  * or for locating a interface on a certain network, as well as more general
97  * routing and gateway routines maintaining information used to locate
98  * interfaces.  These routines live in the files if.c and route.c
99  */
100 #include <sys/time.h>
101
102 struct mbuf;
103 struct proc;
104 struct rtentry;
105 struct socket;
106 struct ether_header;
107 struct arpcom;
108
109 /*
110  * Structure defining statistics and other data kept regarding a network
111  * interface.
112  */
113 struct  if_data {
114         /* generic interface information */
115         u_char  ifi_type;               /* ethernet, tokenring, etc. */
116         u_char  ifi_addrlen;            /* media address length */
117         u_char  ifi_hdrlen;             /* media header length */
118         u_long  ifi_mtu;                /* maximum transmission unit */
119         u_long  ifi_metric;             /* routing metric (external only) */
120         u_long  ifi_baudrate;           /* linespeed */
121         /* volatile statistics */
122         u_long  ifi_ipackets;           /* packets received on interface */
123         u_long  ifi_ierrors;            /* input errors on interface */
124         u_long  ifi_opackets;           /* packets sent on interface */
125         u_long  ifi_oerrors;            /* output errors on interface */
126         u_long  ifi_collisions;         /* collisions on csma interfaces */
127         u_long  ifi_ibytes;             /* total number of octets received */
128         u_long  ifi_obytes;             /* total number of octets sent */
129         u_long  ifi_imcasts;            /* packets received via multicast */
130         u_long  ifi_omcasts;            /* packets sent via multicast */
131         u_long  ifi_iqdrops;            /* dropped on input, this interface */
132         u_long  ifi_noproto;            /* destined for unsupported protocol */
133         struct  timeval ifi_lastchange; /* last updated */
134 };
135
136 /*
137  * Structure defining a queue for a network interface.
138  *
139  * (Would like to call this struct ``if'', but C isn't PL/1.)
140  */
141 TAILQ_HEAD(ifnet_head, ifnet);          /* the actual queue head */
142
143 /*
144  * Length of interface external name, including terminating '\0'.
145  * Note: this is the same size as a generic device's external name.
146  */
147 #define IFNAMSIZ        16
148 #define IF_NAMESIZE     IFNAMSIZ
149
150 struct ifnet {                          /* and the entries */
151         void    *if_softc;              /* lower-level data for this if */
152         TAILQ_ENTRY(ifnet) if_list;     /* all struct ifnets are chained */
153         TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */
154         char    if_xname[IFNAMSIZ];     /* external name (name + unit) */
155         int     if_pcount;              /* number of promiscuous listeners */
156         caddr_t if_bpf;                 /* packet filter structure */
157         caddr_t if_bridge;              /* bridge structure */
158         u_short if_index;               /* numeric abbreviation for this if */
159         short   if_timer;               /* time 'til if_watchdog called */
160         short   if_flags;               /* up/down, broadcast, etc. */
161         struct  if_data if_data;        /* statistics and other data about if */
162 /* procedure handles */
163         int     (*if_output)            /* output routine (enqueue) */
164                 __P((struct ifnet *, struct mbuf *, struct sockaddr *,
165                      struct rtentry *));
166         void    (*if_start)             /* initiate output routine */
167                 __P((struct ifnet *));
168         int     (*if_ioctl)             /* ioctl routine */
169                 __P((struct ifnet *, u_long, caddr_t));
170         int     (*if_reset)             /* XXX bus reset routine */
171                 __P((struct ifnet *));
172         void    (*if_watchdog)          /* timer routine */
173                 __P((struct ifnet *));
174         struct  ifqueue {
175                 struct  mbuf *ifq_head;
176                 struct  mbuf *ifq_tail;
177                 int     ifq_len;
178                 int     ifq_maxlen;
179                 int     ifq_drops;
180         } if_snd;                       /* output queue */
181         struct ifprefix *if_prefixlist; /* linked list of prefixes per if */
182 };
183 #define if_mtu          if_data.ifi_mtu
184 #define if_type         if_data.ifi_type
185 #define if_addrlen      if_data.ifi_addrlen
186 #define if_hdrlen       if_data.ifi_hdrlen
187 #define if_metric       if_data.ifi_metric
188 #define if_baudrate     if_data.ifi_baudrate
189 #define if_ipackets     if_data.ifi_ipackets
190 #define if_ierrors      if_data.ifi_ierrors
191 #define if_opackets     if_data.ifi_opackets
192 #define if_oerrors      if_data.ifi_oerrors
193 #define if_collisions   if_data.ifi_collisions
194 #define if_ibytes       if_data.ifi_ibytes
195 #define if_obytes       if_data.ifi_obytes
196 #define if_imcasts      if_data.ifi_imcasts
197 #define if_omcasts      if_data.ifi_omcasts
198 #define if_iqdrops      if_data.ifi_iqdrops
199 #define if_noproto      if_data.ifi_noproto
200 #define if_lastchange   if_data.ifi_lastchange
201
202 #define IFF_UP          0x1             /* interface is up */
203 #define IFF_BROADCAST   0x2             /* broadcast address valid */
204 #define IFF_DEBUG       0x4             /* turn on debugging */
205 #define IFF_LOOPBACK    0x8             /* is a loopback net */
206 #define IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
207 #define IFF_NOTRAILERS  0x20            /* avoid use of trailers */
208 #define IFF_RUNNING     0x40            /* resources allocated */
209 #define IFF_NOARP       0x80            /* no address resolution protocol */
210 #define IFF_PROMISC     0x100           /* receive all packets */
211 #define IFF_ALLMULTI    0x200           /* receive all multicast packets */
212 #define IFF_OACTIVE     0x400           /* transmission in progress */
213 #define IFF_SIMPLEX     0x800           /* can't hear own transmissions */
214 #define IFF_LINK0       0x1000          /* per link layer defined bit */
215 #define IFF_LINK1       0x2000          /* per link layer defined bit */
216 #define IFF_LINK2       0x4000          /* per link layer defined bit */
217 #define IFF_MULTICAST   0x8000          /* supports multicast */
218
219 /* flags set internally only: */
220 #define IFF_CANTCHANGE \
221         (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
222             IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
223
224 /*
225  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
226  * input routines have queues of messages stored on ifqueue structures
227  * (defined above).  Entries are added to and deleted from these structures
228  * by these macros, which should be called with ipl raised to splimp().
229  */
230 #define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
231 #define IF_DROP(ifq)            ((ifq)->ifq_drops++)
232 #define IF_ENQUEUE(ifq, m) { \
233         (m)->m_nextpkt = 0; \
234         if ((ifq)->ifq_tail == 0) \
235                 (ifq)->ifq_head = m; \
236         else \
237                 (ifq)->ifq_tail->m_nextpkt = m; \
238         (ifq)->ifq_tail = m; \
239         (ifq)->ifq_len++; \
240 }
241 #define IF_PREPEND(ifq, m) { \
242         (m)->m_nextpkt = (ifq)->ifq_head; \
243         if ((ifq)->ifq_tail == 0) \
244                 (ifq)->ifq_tail = (m); \
245         (ifq)->ifq_head = (m); \
246         (ifq)->ifq_len++; \
247 }
248 #define IF_DEQUEUE(ifq, m) { \
249         (m) = (ifq)->ifq_head; \
250         if (m) { \
251                 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
252                         (ifq)->ifq_tail = 0; \
253                 (m)->m_nextpkt = 0; \
254                 (ifq)->ifq_len--; \
255         } \
256 }
257 #define IF_IS_EMPTY(ifq)        ((ifq)->ifq_len == 0)
258
259 #define IFQ_ENQUEUE(ifq, m, pattr, err)                                 \
260 do {                                                                    \
261         if (IF_QFULL((ifq))) {                                          \
262                 m_freem((m));                                           \
263                 (err) = ENOBUFS;                                        \
264         } else {                                                        \
265                 IF_ENQUEUE((ifq), (m));                                 \
266                 (err) = 0;                                              \
267         }                                                               \
268         if ((err))                                                      \
269                 (ifq)->ifq_drops++;                                     \
270 } while (0)
271
272 #define IFQ_MAXLEN      50
273 #define IFNET_SLOWHZ    1               /* granularity is 1 second */
274
275 /*
276  * The ifaddr structure contains information about one address
277  * of an interface.  They are maintained by the different address families,
278  * are allocated and attached when an address is set, and are linked
279  * together so all addresses for an interface can be located.
280  */
281 struct ifaddr {
282         struct  sockaddr *ifa_addr;     /* address of interface */
283         struct  sockaddr *ifa_dstaddr;  /* other end of p-to-p link */
284 #define ifa_broadaddr   ifa_dstaddr     /* broadcast address interface */
285         struct  sockaddr *ifa_netmask;  /* used to determine subnet */
286         struct  ifnet *ifa_ifp;         /* back-pointer to interface */
287         TAILQ_ENTRY(ifaddr) ifa_list;   /* list of addresses for interface */
288         void    (*ifa_rtrequest)        /* check or clean routes (+ or -)'d */
289                     __P((int, struct rtentry *, struct sockaddr *));
290         u_short ifa_flags;              /* mostly rt_flags for cloning */
291         u_int   ifa_refcnt;             /* count of references */
292         int     ifa_metric;             /* cost of going out this interface */
293 };
294 #define IFA_ROUTE       RTF_UP          /* route installed */
295
296 /*
297  * The prefix structure contains information about one prefix
298  * of an interface.  They are maintained by the different address families,
299  * are allocated and attached when an prefix or an address is set,
300  * and are linked together so all prfefixes for an interface can be located.
301  */
302 struct ifprefix {
303         struct  sockaddr *ifpr_prefix;  /* prefix of interface */
304         struct  ifnet *ifpr_ifp;        /* back-pointer to interface */
305         struct ifprefix *ifpr_next;
306         u_char  ifpr_plen;              /* prefix length in bits */
307         u_char  ifpr_type;              /* protocol dependent prefix type */
308 };
309
310 /*
311  * Message format for use in obtaining information about interfaces
312  * from sysctl and the routing socket.
313  */
314 struct if_msghdr {
315         u_short ifm_msglen;     /* to skip over non-understood messages */
316         u_char  ifm_version;    /* future binary compatability */
317         u_char  ifm_type;       /* message type */
318         int     ifm_addrs;      /* like rtm_addrs */
319         int     ifm_flags;      /* value of if_flags */
320         u_short ifm_index;      /* index for associated ifp */
321         struct  if_data ifm_data;/* statistics and other data about if */
322 };
323
324 /*
325  * Message format for use in obtaining information about interface addresses
326  * from sysctl and the routing socket.
327  */
328 struct ifa_msghdr {
329         u_short ifam_msglen;    /* to skip over non-understood messages */
330         u_char  ifam_version;   /* future binary compatability */
331         u_char  ifam_type;      /* message type */
332         int     ifam_addrs;     /* like rtm_addrs */
333         int     ifam_flags;     /* value of ifa_flags */
334         u_short ifam_index;     /* index for associated ifp */
335         int     ifam_metric;    /* value of ifa_metric */
336 };
337
338 /*
339  * Interface request structure used for socket
340  * ioctl's.  All interface ioctl's must have parameter
341  * definitions which begin with ifr_name.  The
342  * remainder may be interface specific.
343  */
344 struct  ifreq {
345 #define IFHWADDRLEN  6
346         char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
347         union {
348                 struct  sockaddr ifru_addr;
349                 struct  sockaddr ifru_dstaddr;
350                 struct  sockaddr ifru_broadaddr;
351                 struct  sockaddr ifru_hwaddr;
352                 short   ifru_flags;
353                 int     ifru_metric;
354                 caddr_t ifru_data;
355         } ifr_ifru;
356 #define ifr_addr        ifr_ifru.ifru_addr      /* address */
357 #define ifr_hwaddr      ifr_ifru.ifru_hwaddr    /* MAC address */
358 #define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
359 #define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
360 #define ifr_flags       ifr_ifru.ifru_flags     /* flags */
361 #define ifr_metric      ifr_ifru.ifru_metric    /* metric */
362 #define ifr_media       ifr_ifru.ifru_metric    /* media options (overload) */
363 #define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
364 };
365
366 struct ifaliasreq {
367         char    ifra_name[IFNAMSIZ];            /* if name, e.g. "en0" */
368         struct  sockaddr ifra_addr;
369         struct  sockaddr ifra_dstaddr;
370 #define ifra_broadaddr  ifra_dstaddr
371         struct  sockaddr ifra_mask;
372 };
373
374 struct ifmediareq {
375         char    ifm_name[IFNAMSIZ];             /* if name, e.g. "en0" */
376         int     ifm_current;                    /* current media options */
377         int     ifm_mask;                       /* don't care mask */
378         int     ifm_status;                     /* media status */
379         int     ifm_active;                     /* active options */ 
380         int     ifm_count;                      /* # entries in ifm_ulist
381                                                         array */
382         int     *ifm_ulist;                     /* media words */
383 };
384
385 /*
386  * Structure used in SIOCGIFCONF request.
387  * Used to retrieve interface configuration
388  * for machine (useful for programs which
389  * must know all networks accessible).
390  */
391 struct  ifconf {
392         int     ifc_len;                /* size of associated buffer */
393         union {
394                 caddr_t ifcu_buf;
395                 struct  ifreq *ifcu_req;
396         } ifc_ifcu;
397 #define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
398 #define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
399 };
400
401 /*
402  * Structure for SIOC[AGD]LIFADDR
403  */
404 struct if_laddrreq {
405         char iflr_name[IFNAMSIZ];
406         unsigned int flags;
407 #define IFLR_PREFIX     0x8000  /* in: prefix given  out: kernel fills id */
408         unsigned int prefixlen;         /* in/out */
409         struct sockaddr_storage addr;   /* in/out */
410         struct sockaddr_storage dstaddr; /* out */
411 };
412
413 struct if_nameindex {
414         unsigned int    if_index;
415         char            *if_name;
416 };
417
418 #ifndef _KERNEL
419 __BEGIN_DECLS
420 unsigned int if_nametoindex __P((const char *));
421 char    *if_indextoname __P((unsigned int, char *));
422 struct  if_nameindex *if_nameindex __P((void));
423 __END_DECLS
424 #define if_freenameindex(x)     free(x)
425 #endif
426
427 #include <net/if_arp.h>
428
429 #ifdef _KERNEL
430 #define IFAFREE(ifa) { \
431         if ((ifa)->ifa_refcnt <= 0) \
432                 ifafree(ifa); \
433         else \
434                 (ifa)->ifa_refcnt--; \
435         }
436
437 struct ifnet_head ifnet;
438 struct ifnet **ifindex2ifnet;
439 #if 0
440 struct ifnet loif[];
441 #endif
442 int if_index;
443
444 void    ether_ifattach __P((struct ifnet *));
445 void    ether_ifdetach __P((struct ifnet *));
446 int     ether_ioctl __P((struct ifnet *, struct arpcom *, u_long, caddr_t));
447 void    ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *));
448 int     ether_output __P((struct ifnet *,
449            struct mbuf *, struct sockaddr *, struct rtentry *));
450 char    *ether_sprintf __P((u_char *));
451
452 void    if_attach __P((struct ifnet *));
453 void    if_attachtail __P((struct ifnet *));
454 void    if_attachhead __P((struct ifnet *));
455 void    if_detach __P((struct ifnet *));
456 void    if_down __P((struct ifnet *));
457 void    if_qflush __P((struct ifqueue *));
458 void    if_slowtimo __P((void *));
459 void    if_up __P((struct ifnet *));
460 int     ifconf __P((u_long, caddr_t));
461 void    ifinit __P((void));
462 int     ifioctl __P((struct socket *, u_long, caddr_t, struct proc *));
463 int     ifpromisc __P((struct ifnet *, int));
464 struct  ifnet *ifunit __P((char *));
465 struct  ifnet *if_withname __P((struct sockaddr *));
466
467 struct  ifaddr *ifa_ifwithaddr __P((struct sockaddr *));
468 struct  ifaddr *ifa_ifwithaf __P((int));
469 struct  ifaddr *ifa_ifwithdstaddr __P((struct sockaddr *));
470 struct  ifaddr *ifa_ifwithnet __P((struct sockaddr *));
471 struct  ifaddr *ifa_ifwithroute __P((int, struct sockaddr *,
472                                         struct sockaddr *));
473 struct  ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *));
474 void    ifafree __P((struct ifaddr *));
475 void    link_rtrequest __P((int, struct rtentry *, struct sockaddr *));
476
477 int     loioctl __P((struct ifnet *, u_long, caddr_t));
478 void    loopattach __P((int));
479 int     looutput __P((struct ifnet *,
480            struct mbuf *, struct sockaddr *, struct rtentry *));
481 void    lortrequest __P((int, struct rtentry *, struct sockaddr *));
482 #endif /* _KERNEL */
483
484 #endif // _NET_IF_H_