OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [bsd_tcpip/] [v2_0/] [include/] [net/] [if_var.h] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      include/net/if_var.h
4
//
5
//==========================================================================
6
//####BSDCOPYRIGHTBEGIN####
7
//
8
// -------------------------------------------
9
//
10
// Portions of this software may have been derived from OpenBSD, 
11
// FreeBSD or other sources, and are covered by the appropriate
12
// copyright disclaimers included herein.
13
//
14
// Portions created by Red Hat are
15
// Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
16
//
17
// -------------------------------------------
18
//
19
//####BSDCOPYRIGHTEND####
20
//==========================================================================
21
 
22
/*
23
 * Copyright (c) 1982, 1986, 1989, 1993
24
 *      The Regents of the University of California.  All rights reserved.
25
 *
26
 * Redistribution and use in source and binary forms, with or without
27
 * modification, are permitted provided that the following conditions
28
 * are met:
29
 * 1. Redistributions of source code must retain the above copyright
30
 *    notice, this list of conditions and the following disclaimer.
31
 * 2. Redistributions in binary form must reproduce the above copyright
32
 *    notice, this list of conditions and the following disclaimer in the
33
 *    documentation and/or other materials provided with the distribution.
34
 * 3. All advertising materials mentioning features or use of this software
35
 *    must display the following acknowledgement:
36
 *      This product includes software developed by the University of
37
 *      California, Berkeley and its contributors.
38
 * 4. Neither the name of the University nor the names of its contributors
39
 *    may be used to endorse or promote products derived from this software
40
 *    without specific prior written permission.
41
 *
42
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52
 * SUCH DAMAGE.
53
 *
54
 *      From: @(#)if.h  8.1 (Berkeley) 6/10/93
55
 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.7 2001/07/24 19:10:18 brooks Exp $
56
 */
57
 
58
#ifndef _NET_IF_VAR_H_
59
#define _NET_IF_VAR_H_
60
 
61
/*
62
 * Structures defining a network interface, providing a packet
63
 * transport mechanism (ala level 0 of the PUP protocols).
64
 *
65
 * Each interface accepts output datagrams of a specified maximum
66
 * length, and provides higher level routines with input datagrams
67
 * received from its medium.
68
 *
69
 * Output occurs when the routine if_output is called, with three parameters:
70
 *      (*ifp->if_output)(ifp, m, dst, rt)
71
 * Here m is the mbuf chain to be sent and dst is the destination address.
72
 * The output routine encapsulates the supplied datagram if necessary,
73
 * and then transmits it on its medium.
74
 *
75
 * On input, each interface unwraps the data received by it, and either
76
 * places it on the input queue of a internetwork datagram routine
77
 * and posts the associated software interrupt, or passes the datagram to a raw
78
 * packet input routine.
79
 *
80
 * Routines exist for locating interfaces by their addresses
81
 * or for locating a interface on a certain network, as well as more general
82
 * routing and gateway routines maintaining information used to locate
83
 * interfaces.  These routines live in the files if.c and route.c
84
 */
85
 
86
#ifdef __STDC__
87
/*
88
 * Forward structure declarations for function prototypes [sic].
89
 */
90
struct  mbuf;
91
struct  proc;
92
struct  rtentry;
93
struct  socket;
94
struct  ether_header;
95
#endif
96
 
97
#include <sys/queue.h>          /* get TAILQ macros */
98
 
99
TAILQ_HEAD(ifnethead, ifnet);   /* we use TAILQs so that the order of */
100
TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */
101
TAILQ_HEAD(ifprefixhead, ifprefix);
102
LIST_HEAD(ifmultihead, ifmultiaddr);
103
 
104
/*
105
 * Structure defining a queue for a network interface.
106
 */
107
struct  ifqueue {
108
        struct  mbuf *ifq_head;
109
        struct  mbuf *ifq_tail;
110
        int     ifq_len;
111
        int     ifq_maxlen;
112
        int     ifq_drops;
113
};
114
 
115
/*
116
 * Structure defining a network interface.
117
 *
118
 * (Would like to call this struct ``if'', but C isn't PL/1.)
119
 */
120
struct ifnet {
121
        void    *if_softc;              /* pointer to driver state */
122
        char    *if_name;               /* name, e.g. ``en'' or ``lo'' */
123
        TAILQ_ENTRY(ifnet) if_link;     /* all struct ifnets are chained */
124
        struct  ifaddrhead if_addrhead; /* linked list of addresses per if */
125
        char    if_xname[IFNAMSIZ];     /* external name (name + unit) */
126
        int     if_pcount;              /* number of promiscuous listeners */
127
        struct  bpf_if *if_bpf;         /* packet filter structure */
128
        u_short if_index;               /* numeric abbreviation for this if  */
129
        short   if_unit;                /* sub-unit for lower level driver */
130
        short   if_timer;               /* time 'til if_watchdog called */
131
        short   if_flags;               /* up/down, broadcast, etc. */
132
        int     if_ipending;            /* interrupts pending */
133
        void    *if_linkmib;            /* link-type-specific MIB data */
134
        size_t  if_linkmiblen;          /* length of above data */
135
        struct  if_data if_data;
136
        struct  ifmultihead if_multiaddrs; /* multicast addresses configured */
137
        int     if_amcount;             /* number of all-multicast requests */
138
/* procedure handles */
139
        int     (*if_output)            /* output routine (enqueue) */
140
                __P((struct ifnet *, struct mbuf *, struct sockaddr *,
141
                     struct rtentry *));
142
        void    (*if_start)             /* initiate output routine */
143
                __P((struct ifnet *));
144
        int     (*if_done)              /* output complete routine */
145
                __P((struct ifnet *));  /* (XXX not used; fake prototype) */
146
        int     (*if_ioctl)             /* ioctl routine */
147
                __P((struct ifnet *, u_long, caddr_t));
148
        void    (*if_watchdog)          /* timer routine */
149
                __P((struct ifnet *));
150
        int     (*if_poll_recv)         /* polled receive routine */
151
                __P((struct ifnet *, int *));
152
        int     (*if_poll_xmit)         /* polled transmit routine */
153
                __P((struct ifnet *, int *));
154
        void    (*if_poll_intren)       /* polled interrupt reenable routine */
155
                __P((struct ifnet *));
156
        void    (*if_poll_slowinput)    /* input routine for slow devices */
157
                __P((struct ifnet *, struct mbuf *));
158
        void    (*if_init)              /* Init routine */
159
                __P((void *));
160
        int     (*if_resolvemulti)      /* validate/resolve multicast */
161
                __P((struct ifnet *, struct sockaddr **, struct sockaddr *));
162
        struct  ifqueue if_snd;         /* output queue */
163
        struct  ifqueue *if_poll_slowq; /* input queue for slow devices */
164
        struct  ifprefixhead if_prefixhead; /* list of prefixes per if */
165
};
166
typedef void if_init_f_t __P((void *));
167
 
168
#define if_mtu          if_data.ifi_mtu
169
#define if_type         if_data.ifi_type
170
#define if_physical     if_data.ifi_physical
171
#define if_addrlen      if_data.ifi_addrlen
172
#define if_hdrlen       if_data.ifi_hdrlen
173
#define if_metric       if_data.ifi_metric
174
#define if_baudrate     if_data.ifi_baudrate
175
#define if_hwassist     if_data.ifi_hwassist
176
#define if_ipackets     if_data.ifi_ipackets
177
#define if_ierrors      if_data.ifi_ierrors
178
#define if_opackets     if_data.ifi_opackets
179
#define if_oerrors      if_data.ifi_oerrors
180
#define if_collisions   if_data.ifi_collisions
181
#define if_ibytes       if_data.ifi_ibytes
182
#define if_obytes       if_data.ifi_obytes
183
#define if_imcasts      if_data.ifi_imcasts
184
#define if_omcasts      if_data.ifi_omcasts
185
#define if_iqdrops      if_data.ifi_iqdrops
186
#define if_noproto      if_data.ifi_noproto
187
#define if_lastchange   if_data.ifi_lastchange
188
#define if_recvquota    if_data.ifi_recvquota
189
#define if_xmitquota    if_data.ifi_xmitquota
190
#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)0)
191
 
192
/* for compatibility with other BSDs */
193
#define if_addrlist     if_addrhead
194
#define if_list         if_link
195
 
196
static __inline__ char *
197
if_name(struct ifnet *ifp)
198
{
199
    return ifp->if_xname;
200
}
201
 
202
/*
203
 * Bit values in if_ipending
204
 */
205
#define IFI_RECV        1       /* I want to receive */
206
#define IFI_XMIT        2       /* I want to transmit */
207
 
208
/*
209
 * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq)
210
 * are queues of messages stored on ifqueue structures
211
 * (defined above).  Entries are added to and deleted from these structures
212
 * by these macros, which should be called with ipl raised to splimp().
213
 */
214
#define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
215
#define IF_DROP(ifq)            ((ifq)->ifq_drops++)
216
#define IF_ENQUEUE(ifq, m) { \
217
        (m)->m_nextpkt = 0; \
218
        if ((ifq)->ifq_tail == 0) \
219
                (ifq)->ifq_head = m; \
220
        else \
221
                (ifq)->ifq_tail->m_nextpkt = m; \
222
        (ifq)->ifq_tail = m; \
223
        (ifq)->ifq_len++; \
224
}
225
#define IF_PREPEND(ifq, m) { \
226
        (m)->m_nextpkt = (ifq)->ifq_head; \
227
        if ((ifq)->ifq_tail == 0) \
228
                (ifq)->ifq_tail = (m); \
229
        (ifq)->ifq_head = (m); \
230
        (ifq)->ifq_len++; \
231
}
232
#define IF_DEQUEUE(ifq, m) { \
233
        (m) = (ifq)->ifq_head; \
234
        if (m) { \
235
                if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
236
                        (ifq)->ifq_tail = 0; \
237
                (m)->m_nextpkt = 0; \
238
                (ifq)->ifq_len--; \
239
        } \
240
}
241
#define IF_POLL(ifq, m)         ((m) = (ifq)->ifq_head)
242
#define IF_PURGE(ifq)                                                   \
243
while (1) {                                                             \
244
        struct mbuf *m0;                                                \
245
        IF_DEQUEUE((ifq), m0);                                          \
246
        if (m0 == NULL)                                                 \
247
                break;                                                  \
248
        else                                                            \
249
                m_freem(m0);                                            \
250
}
251
#define IF_IS_EMPTY(ifq)        ((ifq)->ifq_len == 0)
252
 
253
#ifdef _KERNEL
254
#define IF_ENQ_DROP(ifq, m)     if_enq_drop(ifq, m)
255
 
256
#if defined(__GNUC__) && defined(MT_HEADER)
257
static __inline int
258
if_queue_drop(struct ifqueue *ifq, struct mbuf *m)
259
{
260
        IF_DROP(ifq);
261
        return 0;
262
}
263
 
264
static __inline int
265
if_enq_drop(struct ifqueue *ifq, struct mbuf *m)
266
{
267
        if (IF_QFULL(ifq) &&
268
            !if_queue_drop(ifq, m))
269
                return 0;
270
        IF_ENQUEUE(ifq, m);
271
        return 1;
272
}
273
#else
274
 
275
#ifdef MT_HEADER
276
int     if_enq_drop __P((struct ifqueue *, struct mbuf *));
277
#endif
278
 
279
#endif
280
 
281
/*
282
 * 72 was chosen below because it is the size of a TCP/IP
283
 * header (40) + the minimum mss (32).
284
 */
285
#define IF_MINMTU       72
286
#define IF_MAXMTU       65535
287
 
288
#endif /* _KERNEL */
289
 
290
#ifdef _KERNEL
291
#define IFQ_ENQUEUE(ifq, m, err)                                        \
292
do {                                                                    \
293
        if (IF_QFULL((ifq))) {                                          \
294
                m_freem((m));                                           \
295
                (err) = ENOBUFS;                                        \
296
        } else {                                                        \
297
                IF_ENQUEUE((ifq), (m));                                 \
298
                (err) = 0;                                               \
299
        }                                                               \
300
        if ((err))                                                      \
301
                (ifq)->ifq_drops++;                                     \
302
} while (0)
303
 
304
#define IFQ_DEQUEUE(ifq, m)     IF_DEQUEUE((ifq), (m))
305
 
306
#define IFQ_POLL(ifq, m)        IF_POLL((ifq), (m))
307
 
308
#define IFQ_PURGE(ifq)                                                  \
309
while (1) {                                                             \
310
        struct mbuf *m0;                                                \
311
        IF_DEQUEUE((ifq), m0);                                          \
312
        if (m0 == NULL)                                                 \
313
                break;                                                  \
314
        else                                                            \
315
                m_freem(m0);                                            \
316
}
317
 
318
#define IFQ_SET_READY(ifq)              ((void)0)
319
#define IFQ_CLASSIFY(ifq, m, af, pa)    ((void)0)
320
 
321
#define IFQ_IS_EMPTY(ifq)               ((ifq)->ifq_len == 0)
322
#define IFQ_INC_LEN(ifq)                ((ifq)->ifq_len++)
323
#define IFQ_DEC_LEN(ifq)                (--(ifq)->ifq_len)
324
#define IFQ_INC_DROPS(ifq)              ((ifq)->ifq_drops++)
325
#define IFQ_SET_MAXLEN(ifq, len)        ((ifq)->ifq_maxlen = (len))
326
 
327
#endif /* _KERNEL */
328
 
329
/*
330
 * The ifaddr structure contains information about one address
331
 * of an interface.  They are maintained by the different address families,
332
 * are allocated and attached when an address is set, and are linked
333
 * together so all addresses for an interface can be located.
334
 */
335
struct ifaddr {
336
        struct  sockaddr *ifa_addr;     /* address of interface */
337
        struct  sockaddr *ifa_dstaddr;  /* other end of p-to-p link */
338
#define ifa_broadaddr   ifa_dstaddr     /* broadcast address interface */
339
        struct  sockaddr *ifa_netmask;  /* used to determine subnet */
340
        struct  if_data if_data;        /* not all members are meaningful */
341
        struct  ifnet *ifa_ifp;         /* back-pointer to interface */
342
        TAILQ_ENTRY(ifaddr) ifa_link;   /* queue macro glue */
343
        void    (*ifa_rtrequest)        /* check or clean routes (+ or -)'d */
344
                __P((int, struct rtentry *, struct sockaddr *));
345
        u_short ifa_flags;              /* mostly rt_flags for cloning */
346
        u_int   ifa_refcnt;             /* references to this structure */
347
        int     ifa_metric;             /* cost of going out this interface */
348
#ifdef notdef
349
        struct  rtentry *ifa_rt;        /* XXXX for ROUTETOIF ????? */
350
#endif
351
        int (*ifa_claim_addr)           /* check if an addr goes to this if */
352
                __P((struct ifaddr *, struct sockaddr *));
353
 
354
};
355
#define IFA_ROUTE       RTF_UP          /* route installed */
356
#define IFAREF(ifa)     do { ++(ifa)->ifa_refcnt; } while (0)
357
 
358
/* for compatibility with other BSDs */
359
#define ifa_list        ifa_link
360
 
361
/*
362
 * The prefix structure contains information about one prefix
363
 * of an interface.  They are maintained by the different address families,
364
 * are allocated and attached when an prefix or an address is set,
365
 * and are linked together so all prefixes for an interface can be located.
366
 */
367
struct ifprefix {
368
        struct  sockaddr *ifpr_prefix;  /* prefix of interface */
369
        struct  ifnet *ifpr_ifp;        /* back-pointer to interface */
370
        TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */
371
        u_char  ifpr_plen;              /* prefix length in bits */
372
        u_char  ifpr_type;              /* protocol dependent prefix type */
373
};
374
 
375
/*
376
 * Multicast address structure.  This is analogous to the ifaddr
377
 * structure except that it keeps track of multicast addresses.
378
 * Also, the reference count here is a count of requests for this
379
 * address, not a count of pointers to this structure.
380
 */
381
struct ifmultiaddr {
382
        LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
383
        struct  sockaddr *ifma_addr;    /* address this membership is for */
384
        struct  sockaddr *ifma_lladdr;  /* link-layer translation, if any */
385
        struct  ifnet *ifma_ifp;        /* back-pointer to interface */
386
        u_int   ifma_refcount;          /* reference count */
387
        void    *ifma_protospec;        /* protocol-specific state, if any */
388
};
389
 
390
#ifdef _KERNEL
391
#define IFAFREE(ifa) \
392
        do { \
393
                if ((ifa)->ifa_refcnt <= 0) \
394
                        ifafree(ifa); \
395
                else \
396
                        (ifa)->ifa_refcnt--; \
397
        } while (0)
398
 
399
extern  struct ifnethead ifnet;
400
extern  struct ifnet    **ifindex2ifnet;
401
extern  int ifqmaxlen;
402
extern  struct ifnet loif[];
403
extern  int if_index;
404
extern  struct ifaddr **ifnet_addrs;
405
 
406
void    ether_ifattach __P((struct ifnet *, int));
407
void    ether_ifdetach __P((struct ifnet *, int));
408
void    ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *));
409
void    ether_demux __P((struct ifnet *, struct ether_header *, struct mbuf *));
410
int     ether_output __P((struct ifnet *,
411
           struct mbuf *, struct sockaddr *, struct rtentry *));
412
int     ether_output_frame __P((struct ifnet *, struct mbuf *));
413
int     ether_ioctl __P((struct ifnet *, int, caddr_t));
414
 
415
int     if_addmulti __P((struct ifnet *, struct sockaddr *,
416
                         struct ifmultiaddr **));
417
int     if_allmulti __P((struct ifnet *, int));
418
void    if_attach __P((struct ifnet *));
419
int     if_delmulti __P((struct ifnet *, struct sockaddr *));
420
void    if_detach __P((struct ifnet *));
421
void    if_down __P((struct ifnet *));
422
void    if_route __P((struct ifnet *, int flag, int fam));
423
int     if_setlladdr __P((struct ifnet *, const u_char *, int));
424
void    if_unroute __P((struct ifnet *, int flag, int fam));
425
void    if_up __P((struct ifnet *));
426
/*void  ifinit __P((void));*/ /* declared in systm.h for main() */
427
int     ifioctl __P((struct socket *, u_long, caddr_t, struct proc *));
428
int     ifpromisc __P((struct ifnet *, int));
429
struct  ifnet *ifunit __P((const char *));
430
struct  ifnet *if_withname __P((struct sockaddr *));
431
 
432
int     if_poll_recv_slow __P((struct ifnet *ifp, int *quotap));
433
void    if_poll_xmit_slow __P((struct ifnet *ifp, int *quotap));
434
void    if_poll_throttle __P((void));
435
void    if_poll_unthrottle __P((void *));
436
void    if_poll_init __P((void));
437
void    if_poll __P((void));
438
 
439
struct  ifaddr *ifa_ifwithaddr __P((struct sockaddr *));
440
struct  ifaddr *ifa_ifwithdstaddr __P((struct sockaddr *));
441
struct  ifaddr *ifa_ifwithnet __P((struct sockaddr *));
442
struct  ifaddr *ifa_ifwithroute __P((int, struct sockaddr *,
443
                                        struct sockaddr *));
444
struct  ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *));
445
void    ifafree __P((struct ifaddr *));
446
 
447
struct  ifmultiaddr *ifmaof_ifpforaddr __P((struct sockaddr *,
448
                                            struct ifnet *));
449
int     if_simloop __P((struct ifnet *ifp, struct mbuf *m, int af, int hlen));
450
 
451
void    if_clone_attach __P((struct if_clone *));
452
void    if_clone_detach __P((struct if_clone *));
453
 
454
int     if_clone_create __P((char *, int));
455
int     if_clone_destroy __P((const char *));
456
 
457
#endif /* _KERNEL */
458
 
459
 
460
#endif /* !_NET_IF_VAR_H_ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.