home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / include / netinet / in_var.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-30  |  9.8 KB  |  294 lines

  1. /*
  2.  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  * 
  6.  * The contents of this file constitute Original Code as defined in and
  7.  * are subject to the Apple Public Source License Version 1.1 (the
  8.  * "License").  You may not use this file except in compliance with the
  9.  * License.  Please obtain a copy of the License at
  10.  * http://www.apple.com/publicsource and read it before using this file.
  11.  * 
  12.  * This Original Code and all software distributed under the License are
  13.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17.  * License for the specific language governing rights and limitations
  18.  * under the License.
  19.  * 
  20.  * @APPLE_LICENSE_HEADER_END@
  21.  */
  22. /*
  23.  * Copyright (c) 1985, 1986, 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.  *    @(#)in_var.h    8.2 (Berkeley) 1/9/95
  55.  */
  56.  
  57. #ifndef _NETINET_IN_VAR_H_
  58. #define _NETINET_IN_VAR_H_
  59.  
  60. #include <sys/queue.h>
  61. #include <sys/kern_event.h>
  62.  
  63. /*
  64.  * Interface address, Internet version.  One of these structures
  65.  * is allocated for each Internet address on an interface.
  66.  * The ifaddr structure contains the protocol-independent part
  67.  * of the structure and is assumed to be first.
  68.  */
  69. struct in_ifaddr {
  70.     struct    ifaddr ia_ifa;        /* protocol-independent info */
  71. #define    ia_ifp        ia_ifa.ifa_ifp
  72. #define ia_flags    ia_ifa.ifa_flags
  73.                     /* ia_{,sub}net{,mask} in host order */
  74.     u_long    ia_net;            /* network number of interface */
  75.     u_long    ia_netmask;        /* mask of net part */
  76.     u_long    ia_subnet;        /* subnet number, including net */
  77.     u_long    ia_subnetmask;        /* mask of subnet part */
  78.     struct    in_addr ia_netbroadcast; /* to recognize net broadcasts */
  79.     TAILQ_ENTRY(in_ifaddr) ia_link;    /* tailq macro glue */
  80.     struct    sockaddr_in ia_addr;    /* reserve space for interface name */
  81.     struct    sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
  82. #define    ia_broadaddr    ia_dstaddr
  83.     struct    sockaddr_in ia_sockmask; /* reserve space for general netmask */
  84. };
  85.  
  86. struct    in_aliasreq {
  87.     char    ifra_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  88.     struct    sockaddr_in ifra_addr;
  89.     struct    sockaddr_in ifra_broadaddr;
  90. #define ifra_dstaddr ifra_broadaddr
  91.     struct    sockaddr_in ifra_mask;
  92.         u_long              dlt;
  93. };
  94.  
  95.  
  96. /*
  97.  * Event data, internet style.
  98.  */
  99.  
  100. struct kev_in_data {
  101.         struct net_event_data   link_data;
  102.     struct in_addr  ia_addr;
  103.     u_long    ia_net;            /* network number of interface */
  104.     u_long    ia_netmask;        /* mask of net part */
  105.     u_long    ia_subnet;        /* subnet number, including net */
  106.     u_long    ia_subnetmask;        /* mask of subnet part */
  107.     struct    in_addr ia_netbroadcast; /* to recognize net broadcasts */
  108.     struct  in_addr ia_dstaddr;
  109. };
  110.  
  111.  
  112.  
  113. /*
  114.  * Define inet event subclass and specific inet events.
  115.  */
  116.  
  117. #define KEV_INET_SUBCLASS 1
  118.  
  119. #define KEV_INET_NEW_ADDR     1
  120. #define KEV_INET_CHANGED_ADDR 2
  121. #define KEV_INET_ADDR_DELETED 3
  122. #define KEV_INET_SIFDSTADDR   4
  123. #define KEV_INET_SIFBRDADDR   5
  124. #define KEV_INET_SIFNETMASK   6
  125.  
  126. /*
  127.  * Given a pointer to an in_ifaddr (ifaddr),
  128.  * return a pointer to the addr as a sockaddr_in.
  129.  */
  130. #define IA_SIN(ia)    (&(((struct in_ifaddr *)(ia))->ia_addr))
  131. #define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr))
  132.  
  133. #define IN_LNAOF(in, ifa) \
  134.     ((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
  135.  
  136.  
  137. #ifdef    KERNEL
  138. extern    TAILQ_HEAD(in_ifaddrhead, in_ifaddr) in_ifaddrhead;
  139. extern    struct    ifqueue    ipintrq;        /* ip packet input queue */
  140. extern    struct    in_addr zeroin_addr;
  141. extern    u_char    inetctlerrmap[];
  142.  
  143. /*
  144.  * Macro for finding the interface (ifnet structure) corresponding to one
  145.  * of our IP addresses.
  146.  */
  147. #define INADDR_TO_IFP(addr, ifp) \
  148.     /* struct in_addr addr; */ \
  149.     /* struct ifnet *ifp; */ \
  150. { \
  151.     register struct in_ifaddr *ia; \
  152. \
  153.     for (ia = in_ifaddrhead.tqh_first; \
  154.         ia != NULL && ((ia->ia_ifp->if_flags & IFF_POINTOPOINT)? \
  155.         IA_DSTSIN(ia):IA_SIN(ia))->sin_addr.s_addr != (addr).s_addr; \
  156.         ia = ia->ia_link.tqe_next) \
  157.          continue; \
  158.     if (ia == NULL) \
  159.         for (ia = in_ifaddrhead.tqh_first; \
  160.         ia != NULL; \
  161.         ia = ia->ia_link.tqe_next) \
  162.             if (ia->ia_ifp->if_flags & IFF_POINTOPOINT && \
  163.             IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \
  164.                 break; \
  165.     (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
  166. }
  167.  
  168. /*
  169.  * Macro for finding the internet address structure (in_ifaddr) corresponding
  170.  * to a given interface (ifnet structure).
  171.  */
  172. #define IFP_TO_IA(ifp, ia) \
  173.     /* struct ifnet *ifp; */ \
  174.     /* struct in_ifaddr *ia; */ \
  175. { \
  176.     for ((ia) = in_ifaddrhead.tqh_first; \
  177.         (ia) != NULL && (ia)->ia_ifp != (ifp); \
  178.         (ia) = (ia)->ia_link.tqe_next) \
  179.         continue; \
  180. }
  181. #endif
  182.  
  183. /*
  184.  * This information should be part of the ifnet structure but we don't wish
  185.  * to change that - as it might break a number of things
  186.  */
  187.  
  188. struct router_info {
  189.     struct ifnet *rti_ifp;
  190.     int    rti_type; /* type of router which is querier on this interface */
  191.     int    rti_time; /* # of slow timeouts since last old query */
  192.     struct router_info *rti_next;
  193. };
  194.  
  195. /*
  196.  * Internet multicast address structure.  There is one of these for each IP
  197.  * multicast group to which this host belongs on a given network interface.
  198.  * For every entry on the interface's if_multiaddrs list which represents
  199.  * an IP multicast group, there is one of these structures.  They are also
  200.  * kept on a system-wide list to make it easier to keep our legacy IGMP code
  201.  * compatible with the rest of the world (see IN_FIRST_MULTI et al, below).
  202.  */
  203. struct in_multi {
  204.     LIST_ENTRY(in_multi) inm_link;    /* queue macro glue */
  205.     struct    in_addr inm_addr;    /* IP multicast address, convenience */
  206.     struct    ifnet *inm_ifp;        /* back pointer to ifnet */
  207.     struct    ifmultiaddr *inm_ifma;    /* back pointer to ifmultiaddr */
  208.     u_int    inm_timer;        /* IGMP membership report timer */
  209.     u_int    inm_state;        /*  state of the membership */
  210.     struct    router_info *inm_rti;    /* router info*/
  211. };
  212.  
  213. #ifdef KERNEL
  214.  
  215. #ifdef SYSCTL_DECL
  216. SYSCTL_DECL(_net_inet_ip);
  217. SYSCTL_DECL(_net_inet_raw);
  218. #endif
  219.  
  220. extern LIST_HEAD(in_multihead, in_multi) in_multihead;
  221.  
  222. /*
  223.  * Structure used by macros below to remember position when stepping through
  224.  * all of the in_multi records.
  225.  */
  226. struct in_multistep {
  227.     struct in_multi *i_inm;
  228. };
  229.  
  230. /*
  231.  * Macro for looking up the in_multi record for a given IP multicast address
  232.  * on a given interface.  If no matching record is found, "inm" is set null.
  233.  */
  234. #define IN_LOOKUP_MULTI(addr, ifp, inm) \
  235.     /* struct in_addr addr; */ \
  236.     /* struct ifnet *ifp; */ \
  237.     /* struct in_multi *inm; */ \
  238. do { \
  239.     register struct ifmultiaddr *ifma; \
  240. \
  241.     for (ifma = (ifp)->if_multiaddrs.lh_first; ifma; \
  242.          ifma = ifma->ifma_link.le_next) { \
  243.         if (ifma->ifma_addr->sa_family == AF_INET \
  244.             && ((struct sockaddr_in *)ifma->ifma_addr)->sin_addr.s_addr == \
  245.             (addr).s_addr) \
  246.             break; \
  247.     } \
  248.     (inm) = ifma ? ifma->ifma_protospec : 0; \
  249. } while(0)
  250.  
  251. /*
  252.  * Macro to step through all of the in_multi records, one at a time.
  253.  * The current position is remembered in "step", which the caller must
  254.  * provide.  IN_FIRST_MULTI(), below, must be called to initialize "step"
  255.  * and get the first record.  Both macros return a NULL "inm" when there
  256.  * are no remaining records.
  257.  */
  258. #define IN_NEXT_MULTI(step, inm) \
  259.     /* struct in_multistep  step; */ \
  260.     /* struct in_multi *inm; */ \
  261. do { \
  262.     if (((inm) = (step).i_inm) != NULL) \
  263.         (step).i_inm = (step).i_inm->inm_link.le_next; \
  264. } while(0)
  265.  
  266. #define IN_FIRST_MULTI(step, inm) \
  267.     /* struct in_multistep step; */ \
  268.     /* struct in_multi *inm; */ \
  269. do { \
  270.     (step).i_inm = in_multihead.lh_first; \
  271.     IN_NEXT_MULTI((step), (inm)); \
  272. } while(0)
  273.  
  274. struct    route;
  275. struct    in_multi *in_addmulti __P((struct in_addr *, struct ifnet *));
  276. void    in_delmulti __P((struct in_multi *));
  277. int    in_control __P((struct socket *, u_long, caddr_t, struct ifnet *,
  278.             struct proc *));
  279. void    in_rtqdrain __P((void));
  280. void    ip_input __P((struct mbuf *));
  281. int    in_ifadown __P((struct ifaddr *ifa));
  282. void    in_ifscrub __P((struct ifnet *, struct in_ifaddr *));
  283. int    ipflow_fastforward __P((struct mbuf *));
  284. void    ipflow_create __P((const struct route *, struct mbuf *));
  285. void    ipflow_slowtimo __P((void));
  286.  
  287. #endif /* KERNEL */
  288. #if INET6
  289. /* INET6 stuff */
  290. #include <netinet6/in6_var.h>
  291. #endif
  292.  
  293. #endif /* _NETINET_IN_VAR_H_ */
  294.