epoc32/include/stdapis/net/if_var.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
/*
williamr@2
     2
 * Copyright (c) 1982, 1986, 1989, 1993
williamr@2
     3
 *      The Regents of the University of California.  All rights reserved.
williamr@2
     4
 * Redistribution and use in source and binary forms, with or without
williamr@2
     5
 * modification, are permitted provided that the following conditions
williamr@2
     6
 * are met:
williamr@2
     7
 * 1. Redistributions of source code must retain the above copyright
williamr@2
     8
 *    notice, this list of conditions and the following disclaimer.
williamr@2
     9
 * 2. Redistributions in binary form must reproduce the above copyright
williamr@2
    10
 *    notice, this list of conditions and the following disclaimer in the
williamr@2
    11
 *    documentation and/or other materials provided with the distribution.
williamr@2
    12
 * 4. Neither the name of the University nor the names of its contributors
williamr@2
    13
 *    may be used to endorse or promote products derived from this software
williamr@2
    14
 *    without specific prior written permission.
williamr@2
    15
 *
williamr@2
    16
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
williamr@2
    17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
williamr@2
    18
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
williamr@2
    19
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
williamr@2
    20
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
williamr@2
    21
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
williamr@2
    22
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
williamr@2
    23
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
williamr@2
    24
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
williamr@2
    25
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
williamr@2
    26
 * SUCH DAMAGE.
williamr@2
    27
 *
williamr@4
    28
 * Portions Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
williamr@2
    29
 *      From: @(#)if.h  8.1 (Berkeley) 6/10/93
williamr@2
    30
 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.16 2003/04/15 18:11:19 fjoe Exp $
williamr@2
    31
 * $DragonFly: src/sys/net/if_var.h,v 1.40 2007/09/09 03:51:25 sephe Exp $
williamr@2
    32
 */
williamr@2
    33
williamr@2
    34
#ifndef _NET_IF_VAR_H_
williamr@2
    35
#define _NET_IF_VAR_H_
williamr@2
    36
williamr@2
    37
#ifndef __SYMBIAN32__
williamr@2
    38
#ifndef _SYS_SERIALIZE_H_
williamr@2
    39
#include <sys/serialize.h>
williamr@2
    40
#endif
williamr@2
    41
#endif //__SYMBIAN32__
williamr@2
    42
#ifndef _NET_IF_H_
williamr@4
    43
#include <stdapis/net/if.h>
williamr@2
    44
#endif
williamr@2
    45
 
williamr@2
    46
 /*
williamr@2
    47
  * Structures defining a network interface, providing a packet
williamr@2
    48
  * transport mechanism (ala level 0 of the PUP protocols).
williamr@2
    49
  *
williamr@2
    50
  * Each interface accepts output datagrams of a specified maximum
williamr@2
    51
  * length, and provides higher level routines with input datagrams
williamr@2
    52
  * received from its medium.
williamr@2
    53
  *
williamr@2
    54
  * Output occurs when the routine if_output is called, with four parameters:
williamr@2
    55
  *      ifp->if_output(ifp, m, dst, rt)
williamr@2
    56
  * Here m is the mbuf chain to be sent and dst is the destination address.
williamr@2
    57
  * The output routine encapsulates the supplied datagram if necessary,
williamr@2
    58
  * and then transmits it on its medium.
williamr@2
    59
  *
williamr@2
    60
  * On input, each interface unwraps the data received by it, and either
williamr@2
    61
  * places it on the input queue of a internetwork datagram routine
williamr@2
    62
  * and posts the associated software interrupt, or passes the datagram to
williamr@2
    63
  * the routine if_input. It is called with the mbuf chain as parameter:
williamr@2
    64
  *      ifp->if_input(ifp, m)
williamr@2
    65
  * The input routine removes the protocol dependent header if necessary.
williamr@2
    66
  *
williamr@2
    67
  * Routines exist for locating interfaces by their addresses
williamr@2
    68
  * or for locating a interface on a certain network, as well as more general
williamr@2
    69
  * routing and gateway routines maintaining information used to locate
williamr@2
    70
  * interfaces.  These routines live in the files if.c and route.c
williamr@2
    71
  */
williamr@2
    72
 
williamr@2
    73
 /*
williamr@2
    74
  * Forward structure declarations for function prototypes [sic].
williamr@2
    75
  */
williamr@2
    76
 struct  mbuf;
williamr@2
    77
 struct  proc;
williamr@2
    78
 struct  rtentry;
williamr@2
    79
 struct  rt_addrinfo;
williamr@2
    80
 struct  socket;
williamr@2
    81
 struct  ether_header;
williamr@2
    82
 struct  carp_if;
williamr@2
    83
 struct  ucred;
williamr@2
    84
 struct  lwkt_serialize;
williamr@2
    85
williamr@2
    86
 #include <sys/queue.h>          /* get TAILQ macros */
williamr@2
    87
 
williamr@2
    88
 #ifndef __SYMBIAN32__
williamr@2
    89
 #include <net/altq/if_altq.h>
williamr@2
    90
 #endif //__SYMBIAN32__
williamr@2
    91
 #ifdef _KERNEL
williamr@2
    92
 #include <sys/eventhandler.h>
williamr@2
    93
 #include <sys/mbuf.h>
williamr@2
    94
 #include <sys/systm.h>          /* XXX */
williamr@2
    95
 #include <sys/thread2.h>
williamr@2
    96
 #endif /* _KERNEL */
williamr@2
    97
  
williamr@2
    98
 #define IF_DUNIT_NONE   -1
williamr@2
    99
williamr@2
   100
 TAILQ_HEAD(ifnethead, ifnet);   /* we use TAILQs so that the order of */
williamr@2
   101
 TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */
williamr@2
   102
 TAILQ_HEAD(ifprefixhead, ifprefix);
williamr@2
   103
 LIST_HEAD(ifmultihead, ifmultiaddr);
williamr@2
   104
 
williamr@2
   105
 /*
williamr@2
   106
  * Structure defining a queue for a network interface.
williamr@2
   107
  */
williamr@2
   108
 struct  ifqueue {
williamr@2
   109
         struct  mbuf *ifq_head;
williamr@2
   110
         struct  mbuf *ifq_tail;
williamr@2
   111
         int     ifq_len;
williamr@2
   112
         int     ifq_maxlen;
williamr@2
   113
         int     ifq_drops;
williamr@2
   114
 };
williamr@2
   115
 
williamr@2
   116
 /*
williamr@2
   117
  * Note of DEVICE_POLLING
williamr@2
   118
  * 1) Any file(*.c) that depends on DEVICE_POLLING supports in this
williamr@2
   119
  *    file should include opt_polling.h at its beginning.
williamr@2
   120
  * 2) When struct changes, which are conditioned by DEVICE_POLLING,
williamr@2
   121
  *    are to be introduced, please keep the struct's size and layout
williamr@2
   122
  *    same, no matter whether DEVICE_POLLING is defined or not.
williamr@2
   123
  *    See ifnet.if_poll and ifnet.if_poll_unused for example.
williamr@2
   124
  */
williamr@2
   125
 
williamr@2
   126
 #ifdef DEVICE_POLLING
williamr@2
   127
 enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS, POLL_DEREGISTER,
williamr@2
   128
                 POLL_REGISTER };
williamr@2
   129
 #endif
williamr@2
   130
 
williamr@2
   131
 /*
williamr@2
   132
  * Structure defining a network interface.
williamr@2
   133
  *
williamr@2
   134
  * (Would like to call this struct ``if'', but C isn't PL/1.)
williamr@2
   135
  */
williamr@2
   136
 
williamr@2
   137
 /*
williamr@2
   138
  * NB: For FreeBSD, it is assumed that each NIC driver's softc starts with  
williamr@2
   139
  * one of these structures, typically held within an arpcom structure.   
williamr@2
   140
  * 
williamr@2
   141
  *      struct <foo>_softc {
williamr@2
   142
  *              struct arpcom {
williamr@2
   143
  *                      struct  ifnet ac_if;
williamr@2
   144
  *                      ...
williamr@2
   145
  *              } <arpcom> ;
williamr@2
   146
  *              ...   
williamr@2
   147
  *      };
williamr@2
   148
  *
williamr@2
   149
  * The assumption is used in a number of places, including many
williamr@2
   150
  * files in sys/net, device drivers, and sys/dev/mii.c:miibus_attach().
williamr@2
   151
  * 
williamr@2
   152
  * Unfortunately devices' softc are opaque, so we depend on this layout
williamr@2
   153
  * to locate the struct ifnet from the softc in the generic code.
williamr@2
   154
  *
williamr@2
   155
  * MPSAFE NOTES: 
williamr@2
   156
  *
williamr@2
   157
  * ifnet and its related packet queues are protected by if_serializer.
williamr@2
   158
  * Callers of if_output, if_ioctl, if_start, if_watchdog, if_init, 
williamr@2
   159
  * if_resolvemulti, and if_poll hold if_serializer.  Device drivers usually
williamr@2
   160
  * use the same serializer for their interrupt but this is not required.
williamr@2
   161
  * However, the device driver must be holding if_serializer when it 
williamr@2
   162
  * calls if_input.  Note that the serializer may be temporarily released
williamr@2
   163
  * within if_input to avoid a deadlock (e.g. when fast-forwarding or
williamr@2
   164
  * bridging packets between interfaces).
williamr@2
   165
  *
williamr@2
   166
  * If a device driver installs the same serializer for its interrupt
williamr@2
   167
  * as for ifnet, then the driver only really needs to worry about further
williamr@2
   168
  * serialization in timeout based entry points.  All other entry points
williamr@2
   169
  * will already be serialized.  Older ISA drivers still using the old
williamr@2
   170
  * interrupt infrastructure will have to obtain and release the serializer
williamr@2
   171
  * in their interrupt routine themselves.
williamr@2
   172
  */
williamr@2
   173
 struct ifnet {
williamr@2
   174
         void    *if_softc;              /* pointer to driver state */
williamr@2
   175
         TAILQ_ENTRY(ifnet) if_link;     /* all struct ifnets are chained */
williamr@2
   176
         char    if_xname[IFNAMSIZ];     /* external name (name + unit) */
williamr@2
   177
         const char *if_dname;           /* driver name */
williamr@2
   178
         int     if_dunit;               /* unit or IF_DUNIT_NONE */
williamr@2
   179
         struct  ifaddrhead if_addrhead; /* linked list of addresses per if */
williamr@2
   180
         int     if_pcount;              /* number of promiscuous listeners */
williamr@2
   181
         struct  carp_if *if_carp;       /* carp interface structure */
williamr@2
   182
         struct  bpf_if *if_bpf;         /* packet filter structure */
williamr@2
   183
         u_short if_index;               /* numeric abbreviation for this if  */
williamr@2
   184
         short   if_timer;               /* time 'til if_watchdog called */
williamr@2
   185
         int     if_flags;               /* up/down, broadcast, etc. */
williamr@2
   186
         int     if_capabilities;        /* interface capabilities */
williamr@2
   187
         int     if_capenable;           /* enabled features */
williamr@2
   188
         void    *if_linkmib;            /* link-type-specific MIB data */
williamr@2
   189
         size_t  if_linkmiblen;          /* length of above data */
williamr@2
   190
         struct  if_data if_data;
williamr@2
   191
         struct  ifmultihead if_multiaddrs; /* multicast addresses configured */
williamr@2
   192
         int     if_amcount;             /* number of all-multicast requests */
williamr@2
   193
 /* procedure handles */
williamr@2
   194
         int     (*if_output)            /* output routine (enqueue) */
williamr@2
   195
                 (struct ifnet *, struct mbuf *, struct sockaddr *,
williamr@2
   196
                      struct rtentry *);
williamr@2
   197
         void    (*if_input)             /* input routine from hardware driver */
williamr@2
   198
                 (struct ifnet *, struct mbuf *);
williamr@2
   199
         void    (*if_start)             /* initiate output routine */
williamr@2
   200
                 (struct ifnet *);
williamr@2
   201
         int     (*if_ioctl)             /* ioctl routine */
williamr@2
   202
                 (struct ifnet *, u_long, caddr_t, struct ucred *);
williamr@2
   203
         void    (*if_watchdog)          /* timer routine */
williamr@2
   204
                 (struct ifnet *);
williamr@2
   205
         void    (*if_init)              /* Init routine */
williamr@2
   206
                 (void *);
williamr@2
   207
         int     (*if_resolvemulti)      /* validate/resolve multicast */
williamr@2
   208
                 (struct ifnet *, struct sockaddr **, struct sockaddr *);
williamr@2
   209
 #ifdef DEVICE_POLLING
williamr@2
   210
         void    (*if_poll)              /* IFF_POLLING support */
williamr@2
   211
                 (struct ifnet *, enum poll_cmd, int);
williamr@2
   212
 #else
williamr@2
   213
         void    (*if_poll_unused)(void); /* placeholder */
williamr@2
   214
 #endif
williamr@2
   215
 #ifndef __SYMBIAN32__
williamr@2
   216
         struct  ifaltq if_snd;          /* output queue (includes altq) */
williamr@2
   217
 #endif         
williamr@2
   218
         struct  ifprefixhead if_prefixhead; /* list of prefixes per if */
williamr@2
   219
         const uint8_t   *if_broadcastaddr;
williamr@2
   220
         void    *if_bridge;             /* bridge glue */
williamr@2
   221
         void    *if_afdata[AF_MAX];
williamr@2
   222
         struct ifaddr   *if_lladdr;
williamr@2
   223
         struct lwkt_serialize *if_serializer;   /* serializer or MP lock */
williamr@2
   224
 #ifndef __SYMBIAN32__        
williamr@2
   225
         struct lwkt_serialize if_default_serializer; /* if not supplied */
williamr@2
   226
 #endif         
williamr@2
   227
 };
williamr@2
   228
 typedef void if_init_f_t (void *);
williamr@2
   229
 
williamr@2
   230
 #define if_mtu          if_data.ifi_mtu
williamr@2
   231
 #define if_type         if_data.ifi_type
williamr@2
   232
 #define if_physical     if_data.ifi_physical
williamr@2
   233
 #define if_addrlen      if_data.ifi_addrlen
williamr@2
   234
 #define if_hdrlen       if_data.ifi_hdrlen
williamr@2
   235
 #define if_metric       if_data.ifi_metric
williamr@2
   236
 #define if_link_state   if_data.ifi_link_state
williamr@2
   237
 #define if_baudrate     if_data.ifi_baudrate
williamr@2
   238
 #define if_hwassist     if_data.ifi_hwassist
williamr@2
   239
 #define if_ipackets     if_data.ifi_ipackets
williamr@2
   240
 #define if_ierrors      if_data.ifi_ierrors
williamr@2
   241
 #define if_opackets     if_data.ifi_opackets
williamr@2
   242
 #define if_oerrors      if_data.ifi_oerrors
williamr@2
   243
 #define if_collisions   if_data.ifi_collisions
williamr@2
   244
 #define if_ibytes       if_data.ifi_ibytes
williamr@2
   245
 #define if_obytes       if_data.ifi_obytes
williamr@2
   246
 #define if_imcasts      if_data.ifi_imcasts
williamr@2
   247
 #define if_omcasts      if_data.ifi_omcasts
williamr@2
   248
 #define if_iqdrops      if_data.ifi_iqdrops
williamr@2
   249
 #define if_noproto      if_data.ifi_noproto
williamr@2
   250
 #define if_lastchange   if_data.ifi_lastchange
williamr@2
   251
 #define if_recvquota    if_data.ifi_recvquota
williamr@2
   252
 #define if_xmitquota    if_data.ifi_xmitquota
williamr@2
   253
 #define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)0)
williamr@2
   254
 
williamr@2
   255
 /* for compatibility with other BSDs */
williamr@2
   256
 #define if_addrlist     if_addrhead
williamr@2
   257
 #define if_list         if_link
williamr@2
   258
 
williamr@2
   259
 /*
williamr@2
   260
  * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq)
williamr@2
   261
  * are queues of messages stored on ifqueue structures
williamr@2
   262
  * (defined above).  Entries are added to and deleted from these structures
williamr@2
   263
  * by these macros, which should be called with ipl raised to splimp().
williamr@2
   264
  */
williamr@2
   265
 #define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
williamr@2
   266
 #define IF_DROP(ifq)            ((ifq)->ifq_drops++)
williamr@2
   267
 #define IF_QLEN(ifq)            ((ifq)->ifq_len)
williamr@2
   268
 #define IF_QEMPTY(ifq)          (IF_QLEN(ifq) == 0)
williamr@2
   269
 #define IF_ENQUEUE(ifq, m) { \
williamr@2
   270
         (m)->m_nextpkt = 0; \
williamr@2
   271
         if ((ifq)->ifq_tail == 0) \
williamr@2
   272
                (ifq)->ifq_head = m; \
williamr@2
   273
         else \
williamr@2
   274
                 (ifq)->ifq_tail->m_nextpkt = m; \
williamr@2
   275
         (ifq)->ifq_tail = m; \
williamr@2
   276
         (ifq)->ifq_len++; \
williamr@2
   277
 }
williamr@2
   278
 #define IF_PREPEND(ifq, m) { \
williamr@2
   279
         (m)->m_nextpkt = (ifq)->ifq_head; \
williamr@2
   280
         if ((ifq)->ifq_tail == 0) \
williamr@2
   281
                 (ifq)->ifq_tail = (m); \
williamr@2
   282
         (ifq)->ifq_head = (m); \
williamr@2
   283
         (ifq)->ifq_len++; \
williamr@2
   284
 }
williamr@2
   285
 #define IF_DEQUEUE(ifq, m) { \
williamr@2
   286
         (m) = (ifq)->ifq_head; \
williamr@2
   287
         if (m) { \
williamr@2
   288
                 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
williamr@2
   289
                         (ifq)->ifq_tail = 0; \
williamr@2
   290
                 (m)->m_nextpkt = 0; \
williamr@2
   291
                 (ifq)->ifq_len--; \
williamr@2
   292
         } \
williamr@2
   293
 }
williamr@2
   294
 
williamr@2
   295
 #define IF_POLL(ifq, m)         ((m) = (ifq)->ifq_head)
williamr@2
   296
 
williamr@2
   297
 #define IF_DRAIN(ifq) do {                                              \
williamr@2
   298
         struct mbuf *m;                                                 \
williamr@2
   299
         while (1) {                                                     \
williamr@2
   300
                 IF_DEQUEUE(ifq, m);                                     \
williamr@2
   301
                 if (m == NULL)                                          \
williamr@2
   302
                         break;                                          \
williamr@2
   303
                 m_freem(m);                                             \
williamr@2
   304
         }                                                               \
williamr@2
   305
 } while (0)
williamr@2
   306
 
williamr@2
   307
 #ifdef _KERNEL
williamr@2
   308
 
williamr@2
   309
 /*
williamr@2
   310
  * DEPRECATED - should not be used by any new driver.  This code uses the
williamr@2
   311
  * old queueing interface and if_start ABI and does not use the ifp's
williamr@2
   312
  * serializer.
williamr@2
   313
  */
williamr@2
   314
 #define IF_HANDOFF(ifq, m, ifp)                 if_handoff(ifq, m, ifp, 0)
williamr@2
   315
 #define IF_HANDOFF_ADJ(ifq, m, ifp, adj)        if_handoff(ifq, m, ifp, adj)
williamr@2
   316
 
williamr@2
   317
 static __inline int
williamr@2
   318
 if_handoff(struct ifqueue *_ifq, struct mbuf *_m, struct ifnet *_ifp,
williamr@2
   319
            int _adjust)
williamr@2
   320
 {
williamr@2
   321
         int _need_if_start = 0;
williamr@2
   322
 
williamr@2
   323
         crit_enter(); 
williamr@2
   324
 
williamr@2
   325
         if (IF_QFULL(_ifq)) {
williamr@2
   326
                 IF_DROP(_ifq);
williamr@2
   327
                 crit_exit();
williamr@2
   328
                 m_freem(_m);
williamr@2
   329
                 return (0);
williamr@2
   330
         }
williamr@2
   331
         if (_ifp != NULL) {
williamr@2
   332
                 _ifp->if_obytes += _m->m_pkthdr.len + _adjust;
williamr@2
   333
                 if (_m->m_flags & M_MCAST)
williamr@2
   334
                         _ifp->if_omcasts++;
williamr@2
   335
                 _need_if_start = !(_ifp->if_flags & IFF_OACTIVE);
williamr@2
   336
         }
williamr@2
   337
         IF_ENQUEUE(_ifq, _m);
williamr@2
   338
         if (_need_if_start) {
williamr@2
   339
                 (*_ifp->if_start)(_ifp);
williamr@2
   340
         }
williamr@2
   341
         crit_exit();
williamr@2
   342
         return (1);
williamr@2
   343
 }
williamr@2
   344
 
williamr@2
   345
 /*
williamr@2
   346
  * 72 was chosen below because it is the size of a TCP/IP
williamr@2
   347
  * header (40) + the minimum mss (32).
williamr@2
   348
  */
williamr@2
   349
 #define IF_MINMTU       72
williamr@2
   350
 #define IF_MAXMTU       65535
williamr@2
   351
 
williamr@2
   352
 #endif /* _KERNEL */
williamr@2
   353
 
williamr@2
   354
 /*
williamr@2
   355
  * The ifaddr structure contains information about one address
williamr@2
   356
  * of an interface.  They are maintained by the different address families,
williamr@2
   357
  * are allocated and attached when an address is set, and are linked
williamr@2
   358
  * together so all addresses for an interface can be located.
williamr@2
   359
  */
williamr@2
   360
 struct ifaddr {
williamr@2
   361
         struct  sockaddr *ifa_addr;     /* address of interface */
williamr@2
   362
         struct  sockaddr *ifa_dstaddr;  /* other end of p-to-p link */
williamr@2
   363
 #define ifa_broadaddr   ifa_dstaddr     /* broadcast address interface */
williamr@2
   364
         struct  sockaddr *ifa_netmask;  /* used to determine subnet */
williamr@2
   365
         struct  if_data if_data;        /* not all members are meaningful */
williamr@2
   366
         struct  ifnet *ifa_ifp;         /* back-pointer to interface */
williamr@2
   367
         TAILQ_ENTRY(ifaddr) ifa_link;   /* queue macro glue */
williamr@2
   368
         void    (*ifa_rtrequest)        /* check or clean routes (+ or -)'d */
williamr@2
   369
                 (int, struct rtentry *, struct rt_addrinfo *);
williamr@2
   370
         u_short ifa_flags;              /* mostly rt_flags for cloning */
williamr@2
   371
         u_int   ifa_refcnt;             /* references to this structure */
williamr@2
   372
         int     ifa_metric;             /* cost of going out this interface */
williamr@2
   373
 #ifdef notdef
williamr@2
   374
         struct  rtentry *ifa_rt;        /* XXXX for ROUTETOIF ????? */
williamr@2
   375
 #endif
williamr@2
   376
         int (*ifa_claim_addr)           /* check if an addr goes to this if */
williamr@2
   377
                 (struct ifaddr *, struct sockaddr *);
williamr@2
   378
 
williamr@2
   379
 };
williamr@2
   380
 #define IFA_ROUTE       RTF_UP          /* route installed */
williamr@2
   381
 
williamr@2
   382
 /* for compatibility with other BSDs */
williamr@2
   383
 #define ifa_list        ifa_link
williamr@2
   384
 
williamr@2
   385
 /*
williamr@2
   386
  * The prefix structure contains information about one prefix
williamr@2
   387
  * of an interface.  They are maintained by the different address families,
williamr@2
   388
  * are allocated and attached when an prefix or an address is set,
williamr@2
   389
  * and are linked together so all prefixes for an interface can be located.
williamr@2
   390
  */
williamr@2
   391
 struct ifprefix {
williamr@2
   392
         struct  sockaddr *ifpr_prefix;  /* prefix of interface */
williamr@2
   393
         struct  ifnet *ifpr_ifp;        /* back-pointer to interface */
williamr@2
   394
         TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */
williamr@2
   395
         u_char  ifpr_plen;              /* prefix length in bits */
williamr@2
   396
         u_char  ifpr_type;              /* protocol dependent prefix type */
williamr@2
   397
 };
williamr@2
   398
 
williamr@2
   399
 /*
williamr@2
   400
  * Multicast address structure.  This is analogous to the ifaddr
williamr@2
   401
  * structure except that it keeps track of multicast addresses.
williamr@2
   402
  * Also, the reference count here is a count of requests for this
williamr@2
   403
  * address, not a count of pointers to this structure.
williamr@2
   404
  */
williamr@2
   405
 struct ifmultiaddr {
williamr@2
   406
         LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
williamr@2
   407
         struct  sockaddr *ifma_addr;    /* address this membership is for */
williamr@2
   408
         struct  sockaddr *ifma_lladdr;  /* link-layer translation, if any */
williamr@2
   409
         struct  ifnet *ifma_ifp;        /* back-pointer to interface */
williamr@2
   410
         u_int   ifma_refcount;          /* reference count */
williamr@2
   411
         void    *ifma_protospec;        /* protocol-specific state, if any */
williamr@2
   412
 };
williamr@2
   413
 
williamr@2
   414
 #ifdef _KERNEL
williamr@2
   415
 /* interface address change event */
williamr@2
   416
 typedef void (*ifaddr_event_handler_t)(void *, struct ifnet *);
williamr@2
   417
 EVENTHANDLER_DECLARE(ifaddr_event, ifaddr_event_handler_t);
williamr@2
   418
 /* new interface attach event */
williamr@2
   419
 typedef void (*ifnet_attach_event_handler_t)(void *, struct ifnet *);
williamr@2
   420
 EVENTHANDLER_DECLARE(ifnet_attach_event, ifnet_attach_event_handler_t);
williamr@2
   421
 /* interface detach event */
williamr@2
   422
 typedef void (*ifnet_detach_event_handler_t)(void *, struct ifnet *);
williamr@2
   423
 EVENTHANDLER_DECLARE(ifnet_detach_event, ifnet_detach_event_handler_t);
williamr@2
   424
 /* interface clone event */
williamr@2
   425
 typedef void (*if_clone_event_handler_t)(void *, struct if_clone *);
williamr@2
   426
 EVENTHANDLER_DECLARE(if_clone_event, if_clone_event_handler_t);
williamr@2
   427
 
williamr@2
   428
 static __inline void
williamr@2
   429
 IFAREF(struct ifaddr *_ifa)
williamr@2
   430
 {
williamr@2
   431
         ++_ifa->ifa_refcnt;
williamr@2
   432
 }
williamr@2
   433
 
williamr@2
   434
 #include <sys/malloc.h>
williamr@2
   435
 
williamr@2
   436
 MALLOC_DECLARE(M_IFADDR);
williamr@2
   437
 MALLOC_DECLARE(M_IFMADDR);
williamr@2
   438
 
williamr@2
   439
 static __inline void
williamr@2
   440
 IFAFREE(struct ifaddr *_ifa)
williamr@2
   441
 {
williamr@2
   442
         if (_ifa->ifa_refcnt <= 0)
williamr@2
   443
                 kfree(_ifa, M_IFADDR);
williamr@2
   444
         else
williamr@2
   445
                 _ifa->ifa_refcnt--;
williamr@2
   446
 }
williamr@2
   447
 
williamr@2
   448
 extern  struct ifnethead ifnet;
williamr@2
   449
 extern struct   ifnet   **ifindex2ifnet;
williamr@2
   450
 extern  int ifqmaxlen;
williamr@2
   451
 extern  struct ifnet loif[];
williamr@2
   452
 extern  int if_index;
williamr@2
   453
 
williamr@2
   454
 void    ether_ifattach(struct ifnet *, uint8_t *, struct lwkt_serialize *);
williamr@2
   455
 void    ether_ifattach_bpf(struct ifnet *, uint8_t *, u_int, u_int,
williamr@2
   456
                         struct lwkt_serialize *);
williamr@2
   457
 void    ether_ifdetach(struct ifnet *);
williamr@2
   458
 void    ether_input(struct ifnet *, struct ether_header *, struct mbuf *);
williamr@2
   459
 void    ether_demux(struct ifnet *, struct ether_header *, struct mbuf *);
williamr@2
   460
 int     ether_output_frame(struct ifnet *, struct mbuf *);
williamr@2
   461
 int     ether_ioctl(struct ifnet *, int, caddr_t);
williamr@2
   462
 uint32_t        ether_crc32_le(const uint8_t *, size_t);
williamr@2
   463
 uint32_t        ether_crc32_be(const uint8_t *, size_t);
williamr@2
   464
 
williamr@2
   465
 int     if_addmulti(struct ifnet *, struct sockaddr *, struct ifmultiaddr **);
williamr@2
   466
 int     if_allmulti(struct ifnet *, int);
williamr@2
   467
 void    if_attach(struct ifnet *, struct lwkt_serialize *);
williamr@2
   468
 int     if_delmulti(struct ifnet *, struct sockaddr *);
williamr@2
   469
 void    if_detach(struct ifnet *);
williamr@2
   470
 void    if_down(struct ifnet *);
williamr@2
   471
 void    if_link_state_change(struct ifnet *);
williamr@2
   472
 void    if_initname(struct ifnet *, const char *, int);
williamr@2
   473
 int     if_getanyethermac(uint16_t *, int);
williamr@2
   474
 int     if_printf(struct ifnet *, const char *, ...) __printflike(2, 3);
williamr@2
   475
 void    if_route(struct ifnet *, int flag, int fam);
williamr@2
   476
 int     if_setlladdr(struct ifnet *, const u_char *, int);
williamr@2
   477
 void    if_unroute(struct ifnet *, int flag, int fam);
williamr@2
   478
 void    if_up(struct ifnet *);
williamr@2
   479
 /*void  ifinit(void);*/ /* declared in systm.h for main() */
williamr@2
   480
 int     ifioctl(struct socket *, u_long, caddr_t, struct ucred *);
williamr@2
   481
 int     ifpromisc(struct ifnet *, int);
williamr@2
   482
 struct  ifnet *ifunit(const char *);
williamr@2
   483
 struct  ifnet *if_withname(struct sockaddr *);
williamr@2
   484
 
williamr@2
   485
 struct  ifaddr *ifa_ifwithaddr(struct sockaddr *);
williamr@2
   486
 struct  ifaddr *ifa_ifwithdstaddr(struct sockaddr *);
williamr@2
   487
 struct  ifaddr *ifa_ifwithnet(struct sockaddr *);
williamr@2
   488
 struct  ifaddr *ifa_ifwithroute(int, struct sockaddr *, struct sockaddr *);
williamr@2
   489
 struct  ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *);
williamr@2
   490
 
williamr@2
   491
 struct  ifmultiaddr *ifmaof_ifpforaddr(struct sockaddr *, struct ifnet *);
williamr@2
   492
 int     if_simloop(struct ifnet *ifp, struct mbuf *m, int af, int hlen);
williamr@2
   493
 
williamr@2
   494
 void    if_clone_attach(struct if_clone *);
williamr@2
   495
 void    if_clone_detach(struct if_clone *);
williamr@2
   496
 
williamr@2
   497
 int     if_clone_create(char *, int);
williamr@2
   498
 int     if_clone_destroy(const char *);
williamr@2
   499
 
williamr@2
   500
 #define IF_LLSOCKADDR(ifp)                                              \
williamr@2
   501
     ((struct sockaddr_dl *)(ifp)->if_lladdr->ifa_addr)
williamr@2
   502
 #define IF_LLADDR(ifp)  LLADDR(IF_LLSOCKADDR(ifp))
williamr@2
   503
 
williamr@2
   504
 #ifdef DEVICE_POLLING
williamr@2
   505
 typedef void poll_handler_t (struct ifnet *ifp, enum poll_cmd cmd, int count);
williamr@2
   506
 int     ether_poll_register(struct ifnet *);
williamr@2
   507
 int     ether_poll_deregister(struct ifnet *);
williamr@2
   508
 #endif /* DEVICE_POLLING */
williamr@2
   509
 #endif /* _KERNEL */
williamr@2
   510
 
williamr@2
   511
 #endif /* !_NET_IF_VAR_H_ */