source: rtems/cpukit/libnetworking/net/if.h @ 7a845a9e

4.104.114.84.9
Last change on this file since 7a845a9e was 7a845a9e, checked in by Ralf Corsepius <ralf.corsepius@…>, on Oct 22, 2004 at 11:54:09 AM

2004-10-22 Ralf Corsepius <ralf_corsepius@…>

  • libnetworking/opt_atalk.h, libnetworking/opt_bdg.h, libnetworking/opt_inet.h, libnetworking/opt_inet6.h, libnetworking/opt_ipx.h, libnetworking/opt_mac.h, libnetworking/opt_netgraph.h: New (Stubs).
  • libnetworking/net/if_loop.c: Cosmetical update from FreeBSD.
  • libnetworking/net/if_ethersubr.c: Update from FreeBSD.
  • libnetworking/net/if.h: Update from FreeBSD.
  • Property mode set to 100644
File size: 17.7 KB
Line 
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 *      The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 *      @(#)if.h        8.1 (Berkeley) 6/10/93
30 * $FreeBSD: src/sys/net/if.h,v 1.92 2004/09/08 04:50:55 brooks Exp $
31 */
32
33/*
34 * $Id$
35 */
36 
37#ifndef _NET_IF_H_
38#define _NET_IF_H_
39
40/*
41 * Structures defining a network interface, providing a packet
42 * transport mechanism (ala level 0 of the PUP protocols).
43 *
44 * Each interface accepts output datagrams of a specified maximum
45 * length, and provides higher level routines with input datagrams
46 * received from its medium.
47 *
48 * Output occurs when the routine if_output is called, with three parameters:
49 *      (*ifp->if_output)(ifp, m, dst, rt)
50 * Here m is the mbuf chain to be sent and dst is the destination address.
51 * The output routine encapsulates the supplied datagram if necessary,
52 * and then transmits it on its medium.
53 *
54 * On input, each interface unwraps the data received by it, and either
55 * places it on the input queue of a internetwork datagram routine
56 * and posts the associated software interrupt, or passes the datagram to a raw
57 * packet input routine.
58 *
59 * Routines exist for locating interfaces by their addresses
60 * or for locating a interface on a certain network, as well as more general
61 * routing and gateway routines maintaining information used to locate
62 * interfaces.  These routines live in the files if.c and route.c
63 */
64
65#include <sys/cdefs.h>
66
67#if defined(__rtems__)
68/*
69 * FIXME - HACK: BSD defines __BSD_VISIBLE in sys/cdefs.h
70 * RTEMS sys/cdefs.h doesn't, so we enforce it here.
71 */
72#ifndef __BSD_VISIBLE
73#define __BSD_VISIBLE 1
74#endif
75#endif
76
77#ifdef _KERNEL
78#include <sys/queue.h>
79#endif
80
81#if __BSD_VISIBLE
82/*
83 * <net/if.h> does not depend on <sys/time.h> on most other systems.  This
84 * helps userland compatibility.  (struct timeval ifi_lastchange)
85 */
86#ifndef _KERNEL
87#include <sys/time.h>
88#endif
89
90struct ifnet;
91
92/*
93 * Forward structure declarations for function prototypes [sic].
94 */
95struct  mbuf;
96struct  proc;
97struct  rtentry;
98struct  socket;
99struct  ether_header;
100#endif
101
102/*
103 * Length of interface external name, including terminating '\0'.
104 * Note: this is the same size as a generic device's external name.
105 */
106#define         IF_NAMESIZE     16
107#if __BSD_VISIBLE
108#define         IFNAMSIZ        IF_NAMESIZE
109#define         IF_MAXUNIT      0x7fff  /* historical value */
110#endif
111#if __BSD_VISIBLE
112
113/*
114 * Structure used to query names of interface cloners.
115 */
116
117struct if_clonereq {
118        int     ifcr_total;             /* total cloners (out) */
119        int     ifcr_count;             /* room for this many in user buffer */
120        char    *ifcr_buffer;           /* buffer for cloner names */
121};
122
123/*
124 * Structure describing information about an interface
125 * which may be of interest to management entities.
126 */
127struct if_data {
128        /* generic interface information */
129        u_char  ifi_type;               /* ethernet, tokenring, etc */
130        u_char  ifi_physical;           /* e.g., AUI, Thinnet, 10base-T, etc */
131        u_char  ifi_addrlen;            /* media address length */
132        u_char  ifi_hdrlen;             /* media header length */
133        u_char  ifi_recvquota;          /* polling quota for receive intrs */
134        u_char  ifi_xmitquota;          /* polling quota for xmit intrs */
135        u_long  ifi_mtu;                /* maximum transmission unit */
136        u_long  ifi_metric;             /* routing metric (external only) */
137        u_long  ifi_baudrate;           /* linespeed */
138        /* volatile statistics */
139        u_long  ifi_ipackets;           /* packets received on interface */
140        u_long  ifi_ierrors;            /* input errors on interface */
141        u_long  ifi_opackets;           /* packets sent on interface */
142        u_long  ifi_oerrors;            /* output errors on interface */
143        u_long  ifi_collisions;         /* collisions on csma interfaces */
144        u_long  ifi_ibytes;             /* total number of octets received */
145        u_long  ifi_obytes;             /* total number of octets sent */
146        u_long  ifi_imcasts;            /* packets received via multicast */
147        u_long  ifi_omcasts;            /* packets sent via multicast */
148        u_long  ifi_iqdrops;            /* dropped on input, this interface */
149        u_long  ifi_noproto;            /* destined for unsupported protocol */
150        u_long  ifi_recvtiming;         /* usec spent receiving when timing */
151        u_long  ifi_xmittiming;         /* usec spent xmitting when timing */
152        struct  timeval ifi_lastchange; /* time of last administrative change */
153};
154
155/*
156 * Structure defining a queue for a network interface.
157 */
158struct  ifqueue {
159        struct  mbuf *ifq_head;
160        struct  mbuf *ifq_tail;
161        int     ifq_len;
162        int     ifq_maxlen;
163        int     ifq_drops;
164};
165
166/*
167 * Structure defining a network interface.
168 *
169 * (Would like to call this struct ``if'', but C isn't PL/1.)
170 */
171struct ifnet {
172        void    *if_softc;              /* pointer to driver state */
173        char    *if_name;               /* name, e.g. ``en'' or ``lo'' */
174        struct  ifnet *if_next;         /* all struct ifnets are chained */
175        struct  ifaddr *if_addrlist;    /* linked list of addresses per if */
176        int     if_pcount;              /* number of promiscuous listeners */
177        struct  bpf_if *if_bpf;         /* packet filter structure */
178        u_short if_index;               /* numeric abbreviation for this if  */
179        short   if_unit;                /* sub-unit for lower level driver */
180        short   if_timer;               /* time 'til if_watchdog called */
181        short   if_flags;               /* up/down, broadcast, etc. */
182        int     if_ipending;            /* interrupts pending */
183        void    *if_linkmib;            /* link-type-specific MIB data */
184        size_t  if_linkmiblen;          /* length of above data */
185        struct  if_data if_data;
186/* procedure handles */
187        int     (*if_output)            /* output routine (enqueue) */
188                __P((struct ifnet *, struct mbuf *, struct sockaddr *,
189                     struct rtentry *));
190        void    (*if_start)             /* initiate output routine */
191                __P((struct ifnet *));
192        int     (*if_done)              /* output complete routine */
193                __P((struct ifnet *));  /* (XXX not used; fake prototype) */
194        int     (*if_ioctl)             /* ioctl routine */
195                __P((struct ifnet *, int, caddr_t));
196        void    (*if_watchdog)          /* timer routine */
197                __P((struct ifnet *));
198        int     (*if_poll_recv)         /* polled receive routine */
199                __P((struct ifnet *, int *));
200        int     (*if_poll_xmit)         /* polled transmit routine */
201                __P((struct ifnet *, int *));
202        void    (*if_poll_intren)       /* polled interrupt reenable routine */
203                __P((struct ifnet *));
204        void    (*if_poll_slowinput)    /* input routine for slow devices */
205                __P((struct ifnet *, struct mbuf *));
206        void    (*if_init)              /* Init routine */
207                __P((void *));
208        int     (*if_tap)               /* Packet filter routine */
209                (struct ifnet *, struct ether_header *, struct mbuf *);
210        struct  ifqueue if_snd;         /* output queue */
211        struct  ifqueue *if_poll_slowq; /* input queue for slow devices */
212};
213typedef void if_init_f_t __P((void *));       
214
215#define if_mtu          if_data.ifi_mtu
216#define if_type         if_data.ifi_type
217#define if_physical     if_data.ifi_physical
218#define if_addrlen      if_data.ifi_addrlen
219#define if_hdrlen       if_data.ifi_hdrlen
220#define if_metric       if_data.ifi_metric
221#define if_baudrate     if_data.ifi_baudrate
222#define if_ipackets     if_data.ifi_ipackets
223#define if_ierrors      if_data.ifi_ierrors
224#define if_opackets     if_data.ifi_opackets
225#define if_oerrors      if_data.ifi_oerrors
226#define if_collisions   if_data.ifi_collisions
227#define if_ibytes       if_data.ifi_ibytes
228#define if_obytes       if_data.ifi_obytes
229#define if_imcasts      if_data.ifi_imcasts
230#define if_omcasts      if_data.ifi_omcasts
231#define if_iqdrops      if_data.ifi_iqdrops
232#define if_noproto      if_data.ifi_noproto
233#define if_lastchange   if_data.ifi_lastchange
234#define if_recvquota    if_data.ifi_recvquota
235#define if_xmitquota    if_data.ifi_xmitquota
236#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)0)
237
238#define IFF_UP          0x1             /* interface is up */
239#define IFF_BROADCAST   0x2             /* broadcast address valid */
240#define IFF_DEBUG       0x4             /* turn on debugging */
241#define IFF_LOOPBACK    0x8             /* is a loopback net */
242#define IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
243#define IFF_SMART       0x20            /* interface manages own routes */
244#define IFF_RUNNING     0x40            /* resources allocated */
245#define IFF_NOARP       0x80            /* no address resolution protocol */
246#define IFF_PROMISC     0x100           /* receive all packets */
247#define IFF_ALLMULTI    0x200           /* receive all multicast packets */
248#define IFF_OACTIVE     0x400           /* transmission in progress */
249#define IFF_SIMPLEX     0x800           /* can't hear own transmissions */
250#define IFF_LINK0       0x1000          /* per link layer defined bit */
251#define IFF_LINK1       0x2000          /* per link layer defined bit */
252#define IFF_LINK2       0x4000          /* per link layer defined bit */
253#define IFF_ALTPHYS     IFF_LINK2       /* use alternate physical connection */
254#define IFF_MULTICAST   0x8000          /* supports multicast */
255#define IFF_POLLING     0x10000         /* Interface is in polling mode. */
256#define IFF_PPROMISC    0x20000         /* user-requested promisc mode */
257#define IFF_MONITOR     0x40000         /* user-requested monitor mode */
258#define IFF_STATICARP   0x80000         /* static ARP */
259#define IFF_NEEDSGIANT  0x100000        /* hold Giant over if_start calls */
260
261/* flags set internally only: */
262#define IFF_CANTCHANGE \
263        (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
264            IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_SMART|IFF_PROMISC|\
265            IFF_POLLING)
266
267
268/*
269 * These really don't belong here, but there's no other obviously appropriate
270 * location.
271 */
272#define IFP_AUI         0
273#define IFP_10BASE2     1
274#define IFP_10BASET     2
275/* etc. */
276
277/*
278 * Bit values in if_ipending
279 */
280#define IFI_RECV        1       /* I want to receive */
281#define IFI_XMIT        2       /* I want to transmit */
282
283/*
284 * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq)
285 * are queues of messages stored on ifqueue structures
286 * (defined above).  Entries are added to and deleted from these structures
287 * by these macros, which should be called with ipl raised to splimp().
288 */
289#define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
290#define IF_DROP(ifq)            ((ifq)->ifq_drops++)
291#define IF_ENQUEUE(ifq, m) { \
292/* printf(" IF_ENQUEUE: %p %p\n", ifq, m ); */ \
293        (m)->m_nextpkt = 0; \
294        if ((ifq)->ifq_tail == 0) \
295                (ifq)->ifq_head = m; \
296        else \
297                (ifq)->ifq_tail->m_nextpkt = m; \
298        (ifq)->ifq_tail = m; \
299        (ifq)->ifq_len++; \
300}
301#define IF_PREPEND(ifq, m) { \
302/* printf(" IF_PREPEND: %p %p\n", ifq, m ); */ \
303        (m)->m_nextpkt = (ifq)->ifq_head; \
304        if ((ifq)->ifq_tail == 0) \
305                (ifq)->ifq_tail = (m); \
306        (ifq)->ifq_head = (m); \
307        (ifq)->ifq_len++; \
308}
309#define IF_DEQUEUE(ifq, m) { \
310        (m) = (ifq)->ifq_head; \
311        if (m) { \
312/* printf(" IF_DEQUEUE: %p %p\n", ifq, m ); */ \
313                if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
314                        (ifq)->ifq_tail = 0; \
315                (m)->m_nextpkt = 0; \
316                (ifq)->ifq_len--; \
317        } \
318}
319
320#ifdef _KERNEL
321#define IF_ENQ_DROP(ifq, m)     if_enq_drop(ifq, m)
322
323#if defined(__GNUC__) && defined(MT_HEADER)
324static inline int
325if_queue_drop(struct ifqueue *ifq, struct mbuf *m)
326{
327        IF_DROP(ifq);
328        return 0;
329}
330
331static inline int
332if_enq_drop(struct ifqueue *ifq, struct mbuf *m)
333{
334        if (IF_QFULL(ifq) &&
335            !if_queue_drop(ifq, m))
336                return 0;
337        IF_ENQUEUE(ifq, m);
338        return 1;
339}
340#else
341
342#ifdef MT_HEADER
343int     if_enq_drop __P((struct ifqueue *, struct mbuf *));
344#endif
345
346#endif
347#endif /* _KERNEL */
348
349#define IFQ_MAXLEN      50
350#define IFNET_SLOWHZ    1               /* granularity is 1 second */
351
352/*
353 * The ifaddr structure contains information about one address
354 * of an interface.  They are maintained by the different address families,
355 * are allocated and attached when an address is set, and are linked
356 * together so all addresses for an interface can be located.
357 */
358struct ifaddr {
359        struct  sockaddr *ifa_addr;     /* address of interface */
360        struct  sockaddr *ifa_dstaddr;  /* other end of p-to-p link */
361#define ifa_broadaddr   ifa_dstaddr     /* broadcast address interface */
362        struct  sockaddr *ifa_netmask;  /* used to determine subnet */
363        struct  ifnet *ifa_ifp;         /* back-pointer to interface */
364        struct  ifaddr *ifa_next;       /* next address for interface */
365        void    (*ifa_rtrequest)        /* check or clean routes (+ or -)'d */
366                __P((int, struct rtentry *, struct sockaddr *));
367        u_short ifa_flags;              /* mostly rt_flags for cloning */
368        short   ifa_refcnt;             /* references to this structure */
369        int     ifa_metric;             /* cost of going out this interface */
370#ifdef notdef
371        struct  rtentry *ifa_rt;        /* XXXX for ROUTETOIF ????? */
372#endif
373        int (*ifa_claim_addr)           /* check if an addr goes to this if */
374                __P((struct ifaddr *, struct sockaddr *));
375
376};
377#define IFA_ROUTE       RTF_UP          /* route installed */
378
379/*
380 * Message format for use in obtaining information about interfaces
381 * from getkerninfo and the routing socket
382 */
383struct if_msghdr {
384        u_short ifm_msglen;     /* to skip over non-understood messages */
385        u_char  ifm_version;    /* future binary compatibility */
386        u_char  ifm_type;       /* message type */
387        int     ifm_addrs;      /* like rtm_addrs */
388        int     ifm_flags;      /* value of if_flags */
389        u_short ifm_index;      /* index for associated ifp */
390        struct  if_data ifm_data;/* statistics and other data about if */
391};
392
393/*
394 * Message format for use in obtaining information about interface addresses
395 * from getkerninfo and the routing socket
396 */
397struct ifa_msghdr {
398        u_short ifam_msglen;    /* to skip over non-understood messages */
399        u_char  ifam_version;   /* future binary compatibility */
400        u_char  ifam_type;      /* message type */
401        int     ifam_addrs;     /* like rtm_addrs */
402        int     ifam_flags;     /* value of ifa_flags */
403        u_short ifam_index;     /* index for associated ifp */
404        int     ifam_metric;    /* value of ifa_metric */
405};
406
407/*
408 * Interface request structure used for socket
409 * ioctl's.  All interface ioctl's must have parameter
410 * definitions which begin with ifr_name.  The
411 * remainder may be interface specific.
412 */
413struct  ifreq {
414        char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
415        union {
416                struct  sockaddr ifru_addr;
417                struct  sockaddr ifru_dstaddr;
418                struct  sockaddr ifru_broadaddr;
419                short   ifru_flags;
420                int     ifru_metric;
421                int     ifru_mtu;
422                int     ifru_phys;
423                int     ifru_media;
424                caddr_t ifru_data;
425                int     (*ifru_tap)(struct ifnet *, struct ether_header *, struct mbuf *);
426        } ifr_ifru;
427#define ifr_addr        ifr_ifru.ifru_addr      /* address */
428#define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
429#define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
430#define ifr_flags       ifr_ifru.ifru_flags     /* flags */
431#define ifr_metric      ifr_ifru.ifru_metric    /* metric */
432#define ifr_mtu         ifr_ifru.ifru_mtu       /* mtu */
433#define ifr_phys        ifr_ifru.ifru_phys      /* physical wire */
434#define ifr_media       ifr_ifru.ifru_media     /* physical media */
435#define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
436#define ifr_tap         ifr_ifru.ifru_tap       /* tap function */
437};
438
439struct ifaliasreq {
440        char    ifra_name[IFNAMSIZ];            /* if name, e.g. "en0" */
441        struct  sockaddr ifra_addr;
442        struct  sockaddr ifra_broadaddr;
443        struct  sockaddr ifra_mask;
444};
445
446struct ifmediareq {
447        char    ifm_name[IFNAMSIZ];     /* if name, e.g. "en0" */
448        int     ifm_current;            /* current media options */
449        int     ifm_mask;               /* don't care mask */
450        int     ifm_status;             /* media status */
451        int     ifm_active;             /* active options */
452        int     ifm_count;              /* # entries in ifm_ulist array */
453        int     *ifm_ulist;             /* media words */
454};
455
456/*
457 * Structure used to retrieve aux status data from interfaces.
458 * Kernel suppliers to this interface should respect the formatting
459 * needed by ifconfig(8): each line starts with a TAB and ends with
460 * a newline.  The canonical example to copy and paste is in if_tun.c.
461 */
462
463#define IFSTATMAX       800             /* 10 lines of text */
464struct ifstat {
465        char    ifs_name[IFNAMSIZ];     /* if name, e.g. "en0" */
466        char    ascii[IFSTATMAX + 1];
467};
468
469/*
470 * Structure used in SIOCGIFCONF request.
471 * Used to retrieve interface configuration
472 * for machine (useful for programs which
473 * must know all networks accessible).
474 */
475struct  ifconf {
476        int     ifc_len;                /* size of associated buffer */
477        union {
478                caddr_t ifcu_buf;
479                struct  ifreq *ifcu_req;
480        } ifc_ifcu;
481#define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
482#define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
483};
484#endif /* __BSD_VISIBLE */
485
486#include <net/if_arp.h>
487
488#ifdef _KERNEL
489#define IFAFREE(ifa) \
490        if ((ifa)->ifa_refcnt <= 0) \
491                ifafree(ifa); \
492        else \
493                (ifa)->ifa_refcnt--;
494
495extern struct   ifnet   *ifnet;
496extern int      ifqmaxlen;
497extern struct   ifnet   loif[];
498extern int      if_index;
499extern struct   ifaddr  **ifnet_addrs;
500
501void    ether_ifattach __P((struct ifnet *));
502void    ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *));
503int     ether_output __P((struct ifnet *,
504           struct mbuf *, struct sockaddr *, struct rtentry *));
505int     ether_ioctl __P((struct ifnet *, int , caddr_t ));
506
507void    if_attach(struct ifnet *);
508void    if_down(struct ifnet *);
509void    if_up(struct ifnet *);
510
511/*void  ifinit __P((void));*/ /* declared in systm.h for main() */
512int     ifioctl(struct socket *, int, caddr_t, struct proc *);
513int     ifpromisc(struct ifnet *, int);
514struct  ifnet *ifunit(char *);
515
516struct  ifaddr *ifa_ifwithaddr(struct sockaddr *);
517struct  ifaddr *ifa_ifwithdstaddr(struct sockaddr *);
518struct  ifaddr *ifa_ifwithnet(struct sockaddr *);
519struct  ifaddr *ifa_ifwithroute(int, struct sockaddr *,
520                                        struct sockaddr *);
521struct  ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *));
522void    ifafree __P((struct ifaddr *));
523
524int     looutput __P((struct ifnet *,
525           struct mbuf *, struct sockaddr *, struct rtentry *));
526#endif /* _KERNEL */
527
528#endif /* !_NET_IF_H_ */
Note: See TracBrowser for help on using the repository browser.