source: rtems/cpukit/libnetworking/net/if_var.h @ 6d7d5b4

4.104.114.84.95
Last change on this file since 6d7d5b4 was f2fe8c9b, checked in by Ralf Corsepius <ralf.corsepius@…>, on 05/07/05 at 13:21:51

More partial updates from FreeBSD.

  • Property mode set to 100644
File size: 9.0 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 *      From: @(#)if.h  8.1 (Berkeley) 6/10/93
30 * $FreeBSD: src/sys/net/if_var.h,v 1.94 2005/03/01 10:59:14 glebius Exp $
31 */
32 
33/*
34 * $Id$
35 */
36
37#ifndef _NET_IF_VAR_H_
38#define _NET_IF_VAR_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 an 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 an 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/*
66 * Forward structure declarations for function prototypes [sic].
67 */
68struct  mbuf;
69#ifndef __rtems__
70struct  thread;
71#endif
72struct  rtentry;
73struct  rt_addrinfo;
74struct  socket;
75struct  ether_header;
76#ifndef __rtems__
77struct  carp_if;
78#endif
79
80/*
81 * Structure defining a queue for a network interface.
82 */
83struct  ifqueue {
84        struct  mbuf *ifq_head;
85        struct  mbuf *ifq_tail;
86        int     ifq_len;
87        int     ifq_maxlen;
88        int     ifq_drops;
89};
90
91/*
92 * Structure defining a network interface.
93 *
94 * (Would like to call this struct ``if'', but C isn't PL/1.)
95 */
96struct ifnet {
97        void    *if_softc;              /* pointer to driver state */
98        char    *if_name;               /* name, e.g. ``en'' or ``lo'' */
99        struct  ifnet *if_next;         /* all struct ifnets are chained */
100        struct  ifaddr *if_addrlist;    /* linked list of addresses per if */
101        int     if_pcount;              /* number of promiscuous listeners */
102        struct  bpf_if *if_bpf;         /* packet filter structure */
103        u_short if_index;               /* numeric abbreviation for this if  */
104        short   if_unit;                /* sub-unit for lower level driver */
105        short   if_timer;               /* time 'til if_watchdog called */
106        int     if_flags;               /* up/down, broadcast, etc. */
107        int     if_ipending;            /* interrupts pending */
108        void    *if_linkmib;            /* link-type-specific MIB data */
109        size_t  if_linkmiblen;          /* length of above data */
110        struct  if_data if_data;
111/* procedure handles */
112        int     (*if_output)            /* output routine (enqueue) */
113                (struct ifnet *, struct mbuf *, struct sockaddr *,
114                     struct rtentry *);
115        void    (*if_start)             /* initiate output routine */
116                (struct ifnet *);
117        int     (*if_ioctl)             /* ioctl routine */
118                (struct ifnet *, u_long, caddr_t);
119        void    (*if_watchdog)          /* timer routine */
120                (struct ifnet *);
121        int     (*if_poll_recv)         /* polled receive routine */
122                (struct ifnet *, int *);
123        int     (*if_poll_xmit)         /* polled transmit routine */
124                (struct ifnet *, int *);
125        void    (*if_poll_intren)       /* polled interrupt reenable routine */
126                (struct ifnet *);
127        void    (*if_poll_slowinput)    /* input routine for slow devices */
128                (struct ifnet *, struct mbuf *);
129        void    (*if_init)              /* Init routine */
130                (void *);
131        int     (*if_tap)               /* Packet filter routine */
132                (struct ifnet *, struct ether_header *, struct mbuf *);
133        struct  ifqueue if_snd;         /* output queue */
134        struct  ifqueue *if_poll_slowq; /* input queue for slow devices */
135};
136
137typedef void if_init_f_t(void *);       
138
139/*
140 * XXX These aliases are terribly dangerous because they could apply
141 * to anything.
142 */
143#define if_mtu          if_data.ifi_mtu
144#define if_type         if_data.ifi_type
145#define if_physical     if_data.ifi_physical
146#define if_addrlen      if_data.ifi_addrlen
147#define if_hdrlen       if_data.ifi_hdrlen
148#define if_metric       if_data.ifi_metric
149#define if_baudrate     if_data.ifi_baudrate
150#define if_ipackets     if_data.ifi_ipackets
151#define if_ierrors      if_data.ifi_ierrors
152#define if_opackets     if_data.ifi_opackets
153#define if_oerrors      if_data.ifi_oerrors
154#define if_collisions   if_data.ifi_collisions
155#define if_ibytes       if_data.ifi_ibytes
156#define if_obytes       if_data.ifi_obytes
157#define if_imcasts      if_data.ifi_imcasts
158#define if_omcasts      if_data.ifi_omcasts
159#define if_iqdrops      if_data.ifi_iqdrops
160#define if_noproto      if_data.ifi_noproto
161#define if_lastchange   if_data.ifi_lastchange
162#define if_recvquota    if_data.ifi_recvquota
163#define if_xmitquota    if_data.ifi_xmitquota
164#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)NULL)
165
166/*
167 * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq)
168 * are queues of messages stored on ifqueue structures
169 * (defined above).  Entries are added to and deleted from these structures
170 * by these macros, which should be called with ipl raised to splimp().
171 */
172#define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
173#define IF_DROP(ifq)            ((ifq)->ifq_drops++)
174
175#define IF_ENQUEUE(ifq, m) do {                                 \
176        (m)->m_nextpkt = NULL; \
177        if ((ifq)->ifq_tail == NULL) \
178                (ifq)->ifq_head = m; \
179        else \
180                (ifq)->ifq_tail->m_nextpkt = m; \
181        (ifq)->ifq_tail = m; \
182        (ifq)->ifq_len++; \
183} while (0)
184
185#define IF_PREPEND(ifq, m) do {                                 \
186        (m)->m_nextpkt = (ifq)->ifq_head; \
187        if ((ifq)->ifq_tail == NULL) \
188                (ifq)->ifq_tail = (m); \
189        (ifq)->ifq_head = (m); \
190        (ifq)->ifq_len++; \
191} while (0)
192
193#define IF_DEQUEUE(ifq, m) do {                                 \
194        (m) = (ifq)->ifq_head; \
195        if (m) { \
196                if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \
197                        (ifq)->ifq_tail = NULL; \
198                (m)->m_nextpkt = NULL; \
199                (ifq)->ifq_len--; \
200        } \
201} while (0)
202
203/*
204 * The ifaddr structure contains information about one address
205 * of an interface.  They are maintained by the different address families,
206 * are allocated and attached when an address is set, and are linked
207 * together so all addresses for an interface can be located.
208 */
209struct ifaddr {
210        struct  sockaddr *ifa_addr;     /* address of interface */
211        struct  sockaddr *ifa_dstaddr;  /* other end of p-to-p link */
212#define ifa_broadaddr   ifa_dstaddr     /* broadcast address interface */
213        struct  sockaddr *ifa_netmask;  /* used to determine subnet */
214        struct  ifnet *ifa_ifp;         /* back-pointer to interface */
215        struct  ifaddr *ifa_next;       /* next address for interface */
216        void    (*ifa_rtrequest)        /* check or clean routes (+ or -)'d */
217                (int, struct rtentry *, struct sockaddr *);
218        u_short ifa_flags;              /* mostly rt_flags for cloning */
219        u_int   ifa_refcnt;             /* references to this structure */
220        int     ifa_metric;             /* cost of going out this interface */
221        int (*ifa_claim_addr)           /* check if an addr goes to this if */
222                (struct ifaddr *, struct sockaddr *);
223
224};
225#define IFA_ROUTE       RTF_UP          /* route installed */
226
227#ifdef _KERNEL
228#define IFAFREE(ifa) \
229        if ((ifa)->ifa_refcnt <= 0) \
230                ifafree(ifa); \
231        else \
232                (ifa)->ifa_refcnt--;
233
234extern struct   ifnet   *ifnet;
235extern int      ifqmaxlen;
236extern struct   ifnet   loif[];
237extern int      if_index;
238extern struct   ifaddr  **ifnet_addrs;
239
240void    if_attach(struct ifnet *);
241void    if_down(struct ifnet *);
242void    if_up(struct ifnet *);
243/*void  ifinit(void);*/ /* declared in systm.h for main() */
244int     ifioctl(struct socket *, u_long, caddr_t, struct proc *);
245int     ifpromisc(struct ifnet *, int);
246
247struct  ifaddr *ifa_ifwithaddr(struct sockaddr *);
248struct  ifaddr *ifa_ifwithdstaddr(struct sockaddr *);
249struct  ifaddr *ifa_ifwithnet(struct sockaddr *);
250struct  ifaddr *ifa_ifwithroute(int, struct sockaddr *, struct sockaddr *);
251struct  ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *);
252
253#endif /* _KERNEL */
254
255#endif /* !_NET_IF_VAR_H_ */
Note: See TracBrowser for help on using the repository browser.