]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/net/if_var.h
xnu-1228.9.59.tar.gz
[apple/xnu.git] / bsd / net / if_var.h
index c58305470211e6e901a31f25dbafdccee0144eda..02735e846b6a9d236240bb7258a5e6f61e433c51 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -91,7 +91,7 @@
 #define APPLE_IF_FAM_STF       12
 #define APPLE_IF_FAM_FIREWIRE  13
 #define APPLE_IF_FAM_BOND      14
-#endif __APPLE__
+#endif /* __APPLE__ */
 
 /*
  * 72 was chosen below because it is the size of a TCP/IP
  */
 
 struct net_event_data {
-     unsigned long     if_family;
-     unsigned long     if_unit;
-     char              if_name[IFNAMSIZ];
+       u_int32_t       if_family;
+       u_int32_t       if_unit;
+       char            if_name[IFNAMSIZ];
 };
 
+#if defined(__LP64__)
+#define __need_struct_timeval32
+#include <sys/_structs.h>
+#define IF_DATA_TIMEVAL timeval32
+#else
+#define IF_DATA_TIMEVAL timeval
+#endif
+
+#pragma pack(4)
+
 /*
  * Structure describing information about an interface
  * which may be of interest to management entities.
  */
 struct if_data {
        /* generic interface information */
-       unsigned char   ifi_type;       /* ethernet, tokenring, etc */
-#ifdef __APPLE__
-       unsigned char   ifi_typelen;    /* Length of frame type id */
-#endif
-       unsigned char   ifi_physical;   /* e.g., AUI, Thinnet, 10base-T, etc */
-       unsigned char   ifi_addrlen;    /* media address length */
-       unsigned char   ifi_hdrlen;     /* media header length */
-       unsigned char   ifi_recvquota;  /* polling quota for receive intrs */
-       unsigned char   ifi_xmitquota;  /* polling quota for xmit intrs */
-       unsigned char   ifi_unused1;    /* for future use */
-       unsigned long   ifi_mtu;        /* maximum transmission unit */
-       unsigned long   ifi_metric;     /* routing metric (external only) */
-       unsigned long   ifi_baudrate;   /* linespeed */
+       u_char          ifi_type;       /* ethernet, tokenring, etc */
+       u_char          ifi_typelen;    /* Length of frame type id */
+       u_char          ifi_physical;   /* e.g., AUI, Thinnet, 10base-T, etc */
+       u_char          ifi_addrlen;    /* media address length */
+       u_char          ifi_hdrlen;     /* media header length */
+       u_char          ifi_recvquota;  /* polling quota for receive intrs */
+       u_char          ifi_xmitquota;  /* polling quota for xmit intrs */
+       u_char          ifi_unused1;    /* for future use */
+       u_int32_t       ifi_mtu;        /* maximum transmission unit */
+       u_int32_t       ifi_metric;     /* routing metric (external only) */
+       u_int32_t       ifi_baudrate;   /* linespeed */
        /* volatile statistics */
-       unsigned long   ifi_ipackets;   /* packets received on interface */
-       unsigned long   ifi_ierrors;    /* input errors on interface */
-       unsigned long   ifi_opackets;   /* packets sent on interface */
-       unsigned long   ifi_oerrors;    /* output errors on interface */
-       unsigned long   ifi_collisions; /* collisions on csma interfaces */
-       unsigned long   ifi_ibytes;     /* total number of octets received */
-       unsigned long   ifi_obytes;     /* total number of octets sent */
-       unsigned long   ifi_imcasts;    /* packets received via multicast */
-       unsigned long   ifi_omcasts;    /* packets sent via multicast */
-       unsigned long   ifi_iqdrops;    /* dropped on input, this interface */
-       unsigned long   ifi_noproto;    /* destined for unsupported protocol */
-       unsigned long   ifi_recvtiming; /* usec spent receiving when timing */
-       unsigned long   ifi_xmittiming; /* usec spent xmitting when timing */
-       struct  timeval ifi_lastchange; /* time of last administrative change */
-       unsigned long   ifi_unused2;    /* used to be the default_proto */
-       unsigned long   ifi_hwassist;   /* HW offload capabilities */
-       unsigned long   ifi_reserved1;  /* for future use */
-       unsigned long   ifi_reserved2;  /* for future use */
+       u_int32_t       ifi_ipackets;   /* packets received on interface */
+       u_int32_t       ifi_ierrors;    /* input errors on interface */
+       u_int32_t       ifi_opackets;   /* packets sent on interface */
+       u_int32_t       ifi_oerrors;    /* output errors on interface */
+       u_int32_t       ifi_collisions; /* collisions on csma interfaces */
+       u_int32_t       ifi_ibytes;     /* total number of octets received */
+       u_int32_t       ifi_obytes;     /* total number of octets sent */
+       u_int32_t       ifi_imcasts;    /* packets received via multicast */
+       u_int32_t       ifi_omcasts;    /* packets sent via multicast */
+       u_int32_t       ifi_iqdrops;    /* dropped on input, this interface */
+       u_int32_t       ifi_noproto;    /* destined for unsupported protocol */
+       u_int32_t       ifi_recvtiming; /* usec spent receiving when timing */
+       u_int32_t       ifi_xmittiming; /* usec spent xmitting when timing */
+       struct IF_DATA_TIMEVAL ifi_lastchange;  /* time of last administrative change */
+       u_int32_t       ifi_unused2;    /* used to be the default_proto */
+       u_int32_t       ifi_hwassist;   /* HW offload capabilities */
+       u_int32_t       ifi_reserved1;  /* for future use */
+       u_int32_t       ifi_reserved2;  /* for future use */
 };
 
 /*
@@ -183,18 +191,16 @@ struct if_data {
  */
 struct if_data64 {
        /* generic interface information */
-       u_char  ifi_type;               /* ethernet, tokenring, etc */
-#ifdef __APPLE__
-       u_char  ifi_typelen;            /* Length of frame type id */
-#endif
+       u_char          ifi_type;               /* ethernet, tokenring, etc */
+       u_char          ifi_typelen;            /* Length of frame type id */
        u_char          ifi_physical;           /* e.g., AUI, Thinnet, 10base-T, etc */
        u_char          ifi_addrlen;            /* media address length */
        u_char          ifi_hdrlen;             /* media header length */
        u_char          ifi_recvquota;          /* polling quota for receive intrs */
        u_char          ifi_xmitquota;          /* polling quota for xmit intrs */
        u_char          ifi_unused1;            /* for future use */
-       u_long          ifi_mtu;                /* maximum transmission unit */
-       u_long          ifi_metric;             /* routing metric (external only) */
+       u_int32_t       ifi_mtu;                /* maximum transmission unit */
+       u_int32_t       ifi_metric;             /* routing metric (external only) */
        u_int64_t       ifi_baudrate;           /* linespeed */
        /* volatile statistics */
        u_int64_t       ifi_ipackets;           /* packets received on interface */
@@ -208,11 +214,13 @@ struct if_data64 {
        u_int64_t       ifi_omcasts;            /* packets sent via multicast */
        u_int64_t       ifi_iqdrops;            /* dropped on input, this interface */
        u_int64_t       ifi_noproto;            /* destined for unsupported protocol */
-       u_long          ifi_recvtiming;         /* usec spent receiving when timing */
-       u_long          ifi_xmittiming;         /* usec spent xmitting when timing */
-       struct  timeval ifi_lastchange; /* time of last administrative change */
+       u_int32_t       ifi_recvtiming;         /* usec spent receiving when timing */
+       u_int32_t       ifi_xmittiming;         /* usec spent xmitting when timing */
+       struct IF_DATA_TIMEVAL ifi_lastchange;  /* time of last administrative change */
 };
 
+#pragma pack()
+
 #ifdef PRIVATE
 /*
  * Internal storage of if_data. This is bound to change. Various places in the
@@ -221,34 +229,34 @@ struct if_data64 {
  */
 struct if_data_internal {
        /* generic interface information */
-       u_char  ifi_type;               /* ethernet, tokenring, etc */
-       u_char  ifi_typelen;    /* Length of frame type id */
-       u_char  ifi_physical;   /* e.g., AUI, Thinnet, 10base-T, etc */
-       u_char  ifi_addrlen;    /* media address length */
-       u_char  ifi_hdrlen;             /* media header length */
-       u_char  ifi_recvquota;  /* polling quota for receive intrs */
-       u_char  ifi_xmitquota;  /* polling quota for xmit intrs */
-    u_char     ifi_unused1;    /* for future use */
-       u_long  ifi_mtu;                /* maximum transmission unit */
-       u_long  ifi_metric;             /* routing metric (external only) */
-       u_long  ifi_baudrate;   /* linespeed */
+       u_char          ifi_type;       /* ethernet, tokenring, etc */
+       u_char          ifi_typelen;    /* Length of frame type id */
+       u_char          ifi_physical;   /* e.g., AUI, Thinnet, 10base-T, etc */
+       u_char          ifi_addrlen;    /* media address length */
+       u_char          ifi_hdrlen;     /* media header length */
+       u_char          ifi_recvquota;  /* polling quota for receive intrs */
+       u_char          ifi_xmitquota;  /* polling quota for xmit intrs */
+       u_char          ifi_unused1;    /* for future use */
+       u_int32_t       ifi_mtu;        /* maximum transmission unit */
+       u_int32_t       ifi_metric;     /* routing metric (external only) */
+       u_int32_t       ifi_baudrate;   /* linespeed */
        /* volatile statistics */
        u_int64_t       ifi_ipackets;   /* packets received on interface */
        u_int64_t       ifi_ierrors;    /* input errors on interface */
        u_int64_t       ifi_opackets;   /* packets sent on interface */
        u_int64_t       ifi_oerrors;    /* output errors on interface */
        u_int64_t       ifi_collisions; /* collisions on csma interfaces */
-       u_int64_t       ifi_ibytes;             /* total number of octets received */
-       u_int64_t       ifi_obytes;             /* total number of octets sent */
+       u_int64_t       ifi_ibytes;     /* total number of octets received */
+       u_int64_t       ifi_obytes;     /* total number of octets sent */
        u_int64_t       ifi_imcasts;    /* packets received via multicast */
        u_int64_t       ifi_omcasts;    /* packets sent via multicast */
        u_int64_t       ifi_iqdrops;    /* dropped on input, this interface */
        u_int64_t       ifi_noproto;    /* destined for unsupported protocol */
-       u_long  ifi_recvtiming;         /* usec spent receiving when timing */
-       u_long  ifi_xmittiming;         /* usec spent xmitting when timing */
+       u_int32_t       ifi_recvtiming; /* usec spent receiving when timing */
+       u_int32_t       ifi_xmittiming; /* usec spent xmitting when timing */
 #define IF_LASTCHANGEUPTIME    1       /* lastchange: 1-uptime 0-calendar time */
        struct  timeval ifi_lastchange; /* time of last administrative change */
-       u_long  ifi_hwassist;           /* HW offload capabilities */
+       u_int32_t       ifi_hwassist;   /* HW offload capabilities */
 };
 
 #define        if_mtu          if_data.ifi_mtu
@@ -314,6 +322,7 @@ TAILQ_HEAD(ddesc_head_name, dlil_demux_desc);
 
 #define IFNET_RW_LOCK 1
 
+#endif /* PRIVATE */
 /*
  * Structure defining a queue for a network interface.
  */
@@ -325,9 +334,12 @@ struct     ifqueue {
        int     ifq_drops;
 };
 
+#ifdef PRIVATE
+
 struct ddesc_head_str;
 struct proto_hash_entry;
 struct kev_msg;
+struct dlil_threading_info;
 
 /*
  * Structure defining a network interface.
@@ -362,7 +374,6 @@ struct ifnet {
 #else
        int     refcnt;
 #endif
-       int     offercnt;
 #ifdef __KPI_INTERFACE__
        ifnet_output_func       if_output;
        ifnet_ioctl_func        if_ioctl;
@@ -395,11 +406,7 @@ struct ifnet {
        int     if_amcount;             /* number of all-multicast requests */
 /* procedure handles */
 #ifdef __KPI_INTERFACE__
-       union {
-               int     (*original)(struct ifnet *ifp, u_long protocol_family,
-                       struct ddesc_head_str *demux_desc_head);
-               ifnet_add_proto_func    kpi;
-       } if_add_proto_u;
+       ifnet_add_proto_func    if_add_proto;
        ifnet_del_proto_func    if_del_proto;
 #else __KPI_INTERFACE__
        void*   if_add_proto;
@@ -407,8 +414,11 @@ struct ifnet {
 #endif __KPI_INTERFACE__
        struct proto_hash_entry *if_proto_hash;
        void                                    *if_kpi_storage;
-       
+#if 0  
        void    *unused_was_init;
+#else
+       struct dlil_threading_info *if_input_thread;
+#endif
        void    *unused_was_resolvemulti;
        
        struct ifqueue  if_snd;
@@ -437,10 +447,11 @@ struct ifnet {
                        u_char  *ptr;
                } u;
        } if_broadcast;
+#if CONFIG_MACF_NET
+       struct  label *if_label;        /* interface MAC label */
+#endif
 };
 
-#define if_add_proto   if_add_proto_u.original
-
 #ifndef __APPLE__
 /* for compatibility with other BSDs */
 #define        if_addrlist     if_addrhead
@@ -468,7 +479,7 @@ struct if_clone {
 };
 
 #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit)   \
-    { { 0, 0 }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy }
+    { { NULL, NULL }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy }
 
 /*
  * Bit values in if_ipending
@@ -621,10 +632,9 @@ struct ifmultiaddr {
 extern struct ifnethead ifnet_head;
 extern struct  ifnet   **ifindex2ifnet;
 extern int ifqmaxlen;
-extern struct ifnet loif[];
+extern ifnet_t  lo_ifp;
 extern int if_index;
 extern struct ifaddr **ifnet_addrs;
-extern struct ifnet *lo_ifp;
 
 int    if_addmulti(struct ifnet *, const struct sockaddr *, struct ifmultiaddr **);
 int    if_allmulti(struct ifnet *, int);
@@ -632,6 +642,7 @@ void        if_attach(struct ifnet *);
 int    if_delmultiaddr(struct ifmultiaddr *ifma, int locked);
 int    if_delmulti(struct ifnet *, const struct sockaddr *);
 void   if_down(struct ifnet *);
+int    if_down_all(void);
 void   if_route(struct ifnet *, int flag, int fam);
 void   if_unroute(struct ifnet *, int flag, int fam);
 void   if_up(struct ifnet *);
@@ -664,16 +675,29 @@ struct    ifaddr *ifa_ifwithaddr(const struct sockaddr *);
 struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
 struct ifaddr *ifa_ifwithnet(const struct sockaddr *);
 struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, const struct sockaddr *);
+struct ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *, const struct sockaddr *);
 struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
+struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int);
 void   ifafree(struct ifaddr *);
 void   ifaref(struct ifaddr *);
 
 struct ifmultiaddr *ifmaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
 
+int    ifa_foraddr(unsigned int addr);
+
 #ifdef BSD_KERNEL_PRIVATE
-void   if_data_internal_to_if_data(const struct if_data_internal *if_data_int,
-                                                          struct if_data *if_data);
-void   if_data_internal_to_if_data64(const struct if_data_internal *if_data_int,
+enum {
+       kIfNetUseCount_MayBeZero = 0,
+       kIfNetUseCount_MustNotBeZero = 1
+};
+
+int ifp_use(struct ifnet *ifp, int handle_zero);
+int ifp_unuse(struct ifnet *ifp);
+void ifp_use_reached_zero(struct ifnet *ifp);
+
+void   if_data_internal_to_if_data(struct ifnet *ifp, const struct if_data_internal *if_data_int,
+                          struct if_data *if_data);
+void   if_data_internal_to_if_data64(struct ifnet *ifp, const struct if_data_internal *if_data_int,
                                                           struct if_data64 *if_data64);
 #endif /* BSD_KERNEL_PRIVATE */
 #endif /* KERNEL_PRIVATE */