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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [net/] [tcpip/] [v2_0/] [include/] [net/] [if.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1254 phoenix
//==========================================================================
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
 
258
#define IFQ_MAXLEN      50
259
#define IFNET_SLOWHZ    1               /* granularity is 1 second */
260
 
261
/*
262
 * The ifaddr structure contains information about one address
263
 * of an interface.  They are maintained by the different address families,
264
 * are allocated and attached when an address is set, and are linked
265
 * together so all addresses for an interface can be located.
266
 */
267
struct ifaddr {
268
        struct  sockaddr *ifa_addr;     /* address of interface */
269
        struct  sockaddr *ifa_dstaddr;  /* other end of p-to-p link */
270
#define ifa_broadaddr   ifa_dstaddr     /* broadcast address interface */
271
        struct  sockaddr *ifa_netmask;  /* used to determine subnet */
272
        struct  ifnet *ifa_ifp;         /* back-pointer to interface */
273
        TAILQ_ENTRY(ifaddr) ifa_list;   /* list of addresses for interface */
274
        void    (*ifa_rtrequest)        /* check or clean routes (+ or -)'d */
275
                    __P((int, struct rtentry *, struct sockaddr *));
276
        u_short ifa_flags;              /* mostly rt_flags for cloning */
277
        u_int   ifa_refcnt;             /* count of references */
278
        int     ifa_metric;             /* cost of going out this interface */
279
};
280
#define IFA_ROUTE       RTF_UP          /* route installed */
281
 
282
/*
283
 * The prefix structure contains information about one prefix
284
 * of an interface.  They are maintained by the different address families,
285
 * are allocated and attached when an prefix or an address is set,
286
 * and are linked together so all prfefixes for an interface can be located.
287
 */
288
struct ifprefix {
289
        struct  sockaddr *ifpr_prefix;  /* prefix of interface */
290
        struct  ifnet *ifpr_ifp;        /* back-pointer to interface */
291
        struct ifprefix *ifpr_next;
292
        u_char  ifpr_plen;              /* prefix length in bits */
293
        u_char  ifpr_type;              /* protocol dependent prefix type */
294
};
295
 
296
/*
297
 * Message format for use in obtaining information about interfaces
298
 * from sysctl and the routing socket.
299
 */
300
struct if_msghdr {
301
        u_short ifm_msglen;     /* to skip over non-understood messages */
302
        u_char  ifm_version;    /* future binary compatability */
303
        u_char  ifm_type;       /* message type */
304
        int     ifm_addrs;      /* like rtm_addrs */
305
        int     ifm_flags;      /* value of if_flags */
306
        u_short ifm_index;      /* index for associated ifp */
307
        struct  if_data ifm_data;/* statistics and other data about if */
308
};
309
 
310
/*
311
 * Message format for use in obtaining information about interface addresses
312
 * from sysctl and the routing socket.
313
 */
314
struct ifa_msghdr {
315
        u_short ifam_msglen;    /* to skip over non-understood messages */
316
        u_char  ifam_version;   /* future binary compatability */
317
        u_char  ifam_type;      /* message type */
318
        int     ifam_addrs;     /* like rtm_addrs */
319
        int     ifam_flags;     /* value of ifa_flags */
320
        u_short ifam_index;     /* index for associated ifp */
321
        int     ifam_metric;    /* value of ifa_metric */
322
};
323
 
324
/*
325
 * Interface request structure used for socket
326
 * ioctl's.  All interface ioctl's must have parameter
327
 * definitions which begin with ifr_name.  The
328
 * remainder may be interface specific.
329
 */
330
struct  ifreq {
331
#define IFHWADDRLEN  6
332
        char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
333
        union {
334
                struct  sockaddr ifru_addr;
335
                struct  sockaddr ifru_dstaddr;
336
                struct  sockaddr ifru_broadaddr;
337
                struct  sockaddr ifru_hwaddr;
338
                short   ifru_flags;
339
                int     ifru_metric;
340
                caddr_t ifru_data;
341
        } ifr_ifru;
342
#define ifr_addr        ifr_ifru.ifru_addr      /* address */
343
#define ifr_hwaddr      ifr_ifru.ifru_hwaddr    /* MAC address */
344
#define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
345
#define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
346
#define ifr_flags       ifr_ifru.ifru_flags     /* flags */
347
#define ifr_metric      ifr_ifru.ifru_metric    /* metric */
348
#define ifr_media       ifr_ifru.ifru_metric    /* media options (overload) */
349
#define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
350
};
351
 
352
struct ifaliasreq {
353
        char    ifra_name[IFNAMSIZ];            /* if name, e.g. "en0" */
354
        struct  sockaddr ifra_addr;
355
        struct  sockaddr ifra_dstaddr;
356
#define ifra_broadaddr  ifra_dstaddr
357
        struct  sockaddr ifra_mask;
358
};
359
 
360
struct ifmediareq {
361
        char    ifm_name[IFNAMSIZ];             /* if name, e.g. "en0" */
362
        int     ifm_current;                    /* current media options */
363
        int     ifm_mask;                       /* don't care mask */
364
        int     ifm_status;                     /* media status */
365
        int     ifm_active;                     /* active options */
366
        int     ifm_count;                      /* # entries in ifm_ulist
367
                                                        array */
368
        int     *ifm_ulist;                     /* media words */
369
};
370
 
371
/*
372
 * Structure used in SIOCGIFCONF request.
373
 * Used to retrieve interface configuration
374
 * for machine (useful for programs which
375
 * must know all networks accessible).
376
 */
377
struct  ifconf {
378
        int     ifc_len;                /* size of associated buffer */
379
        union {
380
                caddr_t ifcu_buf;
381
                struct  ifreq *ifcu_req;
382
        } ifc_ifcu;
383
#define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
384
#define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
385
};
386
 
387
/*
388
 * Structure for SIOC[AGD]LIFADDR
389
 */
390
struct if_laddrreq {
391
        char iflr_name[IFNAMSIZ];
392
        unsigned int flags;
393
#define IFLR_PREFIX     0x8000  /* in: prefix given  out: kernel fills id */
394
        unsigned int prefixlen;         /* in/out */
395
        struct sockaddr_storage addr;   /* in/out */
396
        struct sockaddr_storage dstaddr; /* out */
397
};
398
 
399
struct if_nameindex {
400
        unsigned int    if_index;
401
        char            *if_name;
402
};
403
 
404
#ifndef _KERNEL
405
__BEGIN_DECLS
406
unsigned int if_nametoindex __P((const char *));
407
char    *if_indextoname __P((unsigned int, char *));
408
struct  if_nameindex *if_nameindex __P((void));
409
__END_DECLS
410
#define if_freenameindex(x)     free(x)
411
#endif
412
 
413
#include <net/if_arp.h>
414
 
415
#ifdef _KERNEL
416
#define IFAFREE(ifa) { \
417
        if ((ifa)->ifa_refcnt <= 0) \
418
                ifafree(ifa); \
419
        else \
420
                (ifa)->ifa_refcnt--; \
421
        }
422
 
423
struct ifnet_head ifnet;
424
struct ifnet **ifindex2ifnet;
425
#if 0
426
struct ifnet loif[];
427
#endif
428
int if_index;
429
 
430
void    ether_ifattach __P((struct ifnet *));
431
void    ether_ifdetach __P((struct ifnet *));
432
int     ether_ioctl __P((struct ifnet *, struct arpcom *, u_long, caddr_t));
433
void    ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *));
434
int     ether_output __P((struct ifnet *,
435
           struct mbuf *, struct sockaddr *, struct rtentry *));
436
char    *ether_sprintf __P((u_char *));
437
 
438
void    if_attach __P((struct ifnet *));
439
void    if_attachtail __P((struct ifnet *));
440
void    if_attachhead __P((struct ifnet *));
441
void    if_detach __P((struct ifnet *));
442
void    if_down __P((struct ifnet *));
443
void    if_qflush __P((struct ifqueue *));
444
void    if_slowtimo __P((void *));
445
void    if_up __P((struct ifnet *));
446
int     ifconf __P((u_long, caddr_t));
447
void    ifinit __P((void));
448
int     ifioctl __P((struct socket *, u_long, caddr_t, struct proc *));
449
int     ifpromisc __P((struct ifnet *, int));
450
struct  ifnet *ifunit __P((char *));
451
struct  ifnet *if_withname __P((struct sockaddr *));
452
 
453
struct  ifaddr *ifa_ifwithaddr __P((struct sockaddr *));
454
struct  ifaddr *ifa_ifwithaf __P((int));
455
struct  ifaddr *ifa_ifwithdstaddr __P((struct sockaddr *));
456
struct  ifaddr *ifa_ifwithnet __P((struct sockaddr *));
457
struct  ifaddr *ifa_ifwithroute __P((int, struct sockaddr *,
458
                                        struct sockaddr *));
459
struct  ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *));
460
void    ifafree __P((struct ifaddr *));
461
void    link_rtrequest __P((int, struct rtentry *, struct sockaddr *));
462
 
463
int     loioctl __P((struct ifnet *, u_long, caddr_t));
464
void    loopattach __P((int));
465
int     looutput __P((struct ifnet *,
466
           struct mbuf *, struct sockaddr *, struct rtentry *));
467
void    lortrequest __P((int, struct rtentry *, struct sockaddr *));
468
#endif /* _KERNEL */
469
 
470
#endif // _NET_IF_H_

powered by: WebSVN 2.1.0

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