source: rtems/cpukit/libnetworking/net/if_var.h @ 680d0823

4.104.114.84.95
Last change on this file since 680d0823 was 680d0823, checked in by Ralf Corsepius <ralf.corsepius@…>, on Apr 18, 2005 at 3:56:34 PM

2005-04-18 Ralf Corsepius <ralf.corsepius@…>

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