home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / include / netinet / ip_mroute.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-30  |  10.5 KB  |  289 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) 1989 Stephen Deering.
  24.  * Copyright (c) 1992, 1993
  25.  *    The Regents of the University of California.  All rights reserved.
  26.  *
  27.  * This code is derived from software contributed to Berkeley by
  28.  * Stephen Deering of Stanford University.
  29.  *
  30.  * Redistribution and use in source and binary forms, with or without
  31.  * modification, are permitted provided that the following conditions
  32.  * are met:
  33.  * 1. Redistributions of source code must retain the above copyright
  34.  *    notice, this list of conditions and the following disclaimer.
  35.  * 2. Redistributions in binary form must reproduce the above copyright
  36.  *    notice, this list of conditions and the following disclaimer in the
  37.  *    documentation and/or other materials provided with the distribution.
  38.  * 3. All advertising materials mentioning features or use of this software
  39.  *    must display the following acknowledgement:
  40.  *    This product includes software developed by the University of
  41.  *    California, Berkeley and its contributors.
  42.  * 4. Neither the name of the University nor the names of its contributors
  43.  *    may be used to endorse or promote products derived from this software
  44.  *    without specific prior written permission.
  45.  *
  46.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  47.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  48.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  49.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  50.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  51.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  52.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  53.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  54.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  56.  * SUCH DAMAGE.
  57.  *
  58.  *    @(#)ip_mroute.h    8.1 (Berkeley) 6/10/93
  59.  */
  60.  
  61. #ifndef _NETINET_IP_MROUTE_H_
  62. #define _NETINET_IP_MROUTE_H_
  63.  
  64. /*
  65.  * Definitions for IP multicast forwarding.
  66.  *
  67.  * Written by David Waitzman, BBN Labs, August 1988.
  68.  * Modified by Steve Deering, Stanford, February 1989.
  69.  * Modified by Ajit Thyagarajan, PARC, August 1993.
  70.  * Modified by Ajit Thyagarajan, PARC, August 1994.
  71.  *
  72.  * MROUTING Revision: 3.3.1.3
  73.  */
  74.  
  75.  
  76. /*
  77.  * Multicast Routing set/getsockopt commands.
  78.  */
  79. #define    MRT_INIT    100    /* initialize forwarder */
  80. #define    MRT_DONE    101    /* shut down forwarder */
  81. #define    MRT_ADD_VIF    102    /* create virtual interface */
  82. #define    MRT_DEL_VIF    103    /* delete virtual interface */
  83. #define MRT_ADD_MFC    104    /* insert forwarding cache entry */
  84. #define MRT_DEL_MFC    105    /* delete forwarding cache entry */
  85. #define MRT_VERSION    106    /* get kernel version number */
  86. #define MRT_ASSERT      107     /* enable PIM assert processing */
  87.  
  88.  
  89. #define GET_TIME(t)    microtime(&t)
  90.  
  91. /*
  92.  * Types and macros for handling bitmaps with one bit per virtual interface.
  93.  */
  94. #define    MAXVIFS 32
  95. typedef u_long vifbitmap_t;
  96. typedef u_short vifi_t;        /* type of a vif index */
  97. #define ALL_VIFS (vifi_t)-1
  98.  
  99. #define    VIFM_SET(n, m)        ((m) |= (1 << (n)))
  100. #define    VIFM_CLR(n, m)        ((m) &= ~(1 << (n)))
  101. #define    VIFM_ISSET(n, m)    ((m) & (1 << (n)))
  102. #define    VIFM_CLRALL(m)        ((m) = 0x00000000)
  103. #define    VIFM_COPY(mfrom, mto)    ((mto) = (mfrom))
  104. #define    VIFM_SAME(m1, m2)    ((m1) == (m2))
  105.  
  106.  
  107. /*
  108.  * Argument structure for MRT_ADD_VIF.
  109.  * (MRT_DEL_VIF takes a single vifi_t argument.)
  110.  */
  111. struct vifctl {
  112.     vifi_t    vifc_vifi;            /* the index of the vif to be added */
  113.     u_char    vifc_flags;         /* VIFF_ flags defined below */
  114.     u_char    vifc_threshold;     /* min ttl required to forward on vif */
  115.     u_int    vifc_rate_limit;    /* max rate */
  116.     struct    in_addr vifc_lcl_addr;    /* local interface address */
  117.     struct    in_addr vifc_rmt_addr;    /* remote address (tunnels only) */
  118. };
  119.  
  120. #define    VIFF_TUNNEL    0x1        /* vif represents a tunnel end-point */
  121. #define VIFF_SRCRT    0x2        /* tunnel uses IP source routing */
  122.  
  123. /*
  124.  * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC
  125.  * (mfcc_tos to be added at a future point)
  126.  */
  127. struct mfcctl {
  128.     struct in_addr  mfcc_origin;        /* ip origin of mcasts       */
  129.     struct in_addr  mfcc_mcastgrp;         /* multicast group associated*/
  130.     vifi_t        mfcc_parent;           /* incoming vif              */
  131.     u_char        mfcc_ttls[MAXVIFS];     /* forwarding ttls on vifs   */
  132. };
  133.  
  134. /*
  135.  * The kernel's multicast routing statistics.
  136.  */
  137. struct mrtstat {
  138.     u_long    mrts_mfc_lookups;    /* # forw. cache hash table hits   */
  139.     u_long    mrts_mfc_misses;    /* # forw. cache hash table misses */
  140.     u_long    mrts_upcalls;        /* # calls to mrouted              */
  141.     u_long    mrts_no_route;        /* no route for packet's origin    */
  142.     u_long    mrts_bad_tunnel;    /* malformed tunnel options        */
  143.     u_long    mrts_cant_tunnel;    /* no room for tunnel options      */
  144.     u_long    mrts_wrong_if;        /* arrived on wrong interface       */
  145.     u_long    mrts_upq_ovflw;        /* upcall Q overflow           */
  146.     u_long    mrts_cache_cleanups;    /* # entries with no upcalls        */
  147.     u_long      mrts_drop_sel;         /* pkts dropped selectively        */
  148.     u_long      mrts_q_overflow;        /* pkts dropped - Q overflow       */
  149.     u_long      mrts_pkt2large;         /* pkts dropped - size > BKT SIZE  */
  150.     u_long    mrts_upq_sockfull;    /* upcalls dropped - socket full */
  151. };
  152.  
  153. /*
  154.  * Argument structure used by mrouted to get src-grp pkt counts
  155.  */
  156. struct sioc_sg_req {
  157.     struct in_addr src;
  158.     struct in_addr grp;
  159.     u_long pktcnt;
  160.     u_long bytecnt;
  161.     u_long wrong_if;
  162. };
  163.  
  164. /*
  165.  * Argument structure used by mrouted to get vif pkt counts
  166.  */
  167. struct sioc_vif_req {
  168.     vifi_t vifi;        /* vif number                */
  169.     u_long icount;        /* Input packet count on vif        */
  170.     u_long ocount;        /* Output packet count on vif        */
  171.     u_long ibytes;        /* Input byte count on vif        */
  172.     u_long obytes;        /* Output byte count on vif        */
  173. };
  174.     
  175.  
  176. /*
  177.  * The kernel's virtual-interface structure.
  178.  */
  179. struct vif {
  180.     u_char           v_flags;         /* VIFF_ flags defined above         */
  181.     u_char           v_threshold;    /* min ttl required to forward on vif*/
  182.     u_int              v_rate_limit;     /* max rate                 */
  183.     struct tbf            *v_tbf;           /* token bucket structure at intf.   */
  184.     struct in_addr     v_lcl_addr;       /* local interface address           */
  185.     struct in_addr     v_rmt_addr;       /* remote address (tunnels only)     */
  186.     struct ifnet       *v_ifp;             /* pointer to interface              */
  187.     u_long        v_pkt_in;    /* # pkts in on interface            */
  188.     u_long        v_pkt_out;    /* # pkts out on interface           */
  189.     u_long        v_bytes_in;    /* # bytes in on interface         */
  190.     u_long        v_bytes_out;    /* # bytes out on interface         */
  191.     struct route    v_route;    /* cached route if this is a tunnel */
  192.     u_int        v_rsvp_on;    /* RSVP listening on this vif */
  193.     struct socket      *v_rsvpd;    /* RSVP daemon socket */
  194. };
  195.  
  196. /*
  197.  * The kernel's multicast forwarding cache entry structure 
  198.  * (A field for the type of service (mfc_tos) is to be added 
  199.  * at a future point)
  200.  */
  201. struct mfc {
  202.     struct in_addr  mfc_origin;             /* IP origin of mcasts   */
  203.     struct in_addr  mfc_mcastgrp;          /* multicast group associated*/
  204.     vifi_t        mfc_parent;         /* incoming vif              */
  205.     u_char        mfc_ttls[MAXVIFS];         /* forwarding ttls on vifs   */
  206.     u_long        mfc_pkt_cnt;        /* pkt count for src-grp     */
  207.     u_long        mfc_byte_cnt;        /* byte count for src-grp    */
  208.     u_long        mfc_wrong_if;        /* wrong if for src-grp         */
  209.     int            mfc_expire;            /* time to clean entry up    */
  210.     struct timeval  mfc_last_assert;        /* last time I sent an assert*/
  211.     struct rtdetq  *mfc_stall;            /* q of packets awaiting mfc */
  212.     struct mfc     *mfc_next;            /* next mfc entry            */
  213. };
  214.  
  215. /*
  216.  * Struct used to communicate from kernel to multicast router
  217.  * note the convenient similarity to an IP packet
  218.  */
  219. struct igmpmsg {
  220.     u_long        unused1;
  221.     u_long        unused2;
  222.     u_char        im_msgtype;            /* what type of message        */
  223. #define IGMPMSG_NOCACHE        1
  224. #define IGMPMSG_WRONGVIF    2
  225.     u_char        im_mbz;            /* must be zero            */
  226.     u_char        im_vif;            /* vif rec'd on            */
  227.     u_char        unused3;
  228.     struct in_addr  im_src, im_dst;
  229. };
  230.  
  231. /*
  232.  * Argument structure used for pkt info. while upcall is made
  233.  */
  234. struct rtdetq {
  235.     struct mbuf     *m;        /* A copy of the packet            */
  236.     struct ifnet    *ifp;        /* Interface pkt came in on        */
  237.     vifi_t        xmt_vif;    /* Saved copy of imo_multicast_vif  */
  238. #if UPCALL_TIMING
  239.     struct timeval    t;        /* Timestamp */
  240. #endif /* UPCALL_TIMING */
  241.     struct rtdetq    *next;        /* Next in list of packets          */
  242. };
  243.  
  244. #define MFCTBLSIZ    256
  245. #if (MFCTBLSIZ & (MFCTBLSIZ - 1)) == 0      /* from sys:route.h */
  246. #define MFCHASHMOD(h)    ((h) & (MFCTBLSIZ - 1))
  247. #else
  248. #define MFCHASHMOD(h)    ((h) % MFCTBLSIZ)
  249. #endif
  250.  
  251. #define MAX_UPQ    4        /* max. no of pkts in upcall Q */
  252.  
  253. /*
  254.  * Token Bucket filter code 
  255.  */
  256. #define MAX_BKT_SIZE    10000             /* 10K bytes size         */
  257. #define MAXQSIZE        10                /* max # of pkts in queue     */
  258.  
  259. /*
  260.  * the token bucket filter at each vif
  261.  */
  262. struct tbf
  263. {
  264.     struct timeval tbf_last_pkt_t; /* arr. time of last pkt     */
  265.     u_long tbf_n_tok;          /* no of tokens in bucket     */
  266.     u_long tbf_q_len;        /* length of queue at this vif    */
  267.     u_long tbf_max_q_len;    /* max. queue length        */
  268.     struct mbuf *tbf_q;        /* Packet queue            */
  269.     struct mbuf *tbf_t;        /* tail-insertion pointer    */
  270. };
  271.  
  272. #ifdef KERNEL
  273.  
  274. struct sockopt;
  275.  
  276. extern int    (*ip_mrouter_set) __P((struct socket *, struct sockopt *));
  277. extern int    (*ip_mrouter_get) __P((struct socket *, struct sockopt *));
  278. extern int    (*ip_mrouter_done) __P((void));
  279.  
  280. #if MROUTING
  281. extern int    (*mrt_ioctl) __P((int, caddr_t));
  282. #else
  283. extern int    (*mrt_ioctl) __P((int, caddr_t, struct proc *));
  284. #endif
  285.  
  286. #endif /* KERNEL */
  287.  
  288. #endif /* _NETINET_IP_MROUTE_H_ */
  289.