1 /* $FreeBSD: src/sys/netinet6/ip6_mroute.h,v 1.2.2.3 2002/04/28 05:40:27 suz Exp $ */ 2 /* $DragonFly: src/sys/netinet6/ip6_mroute.h,v 1.4 2006/05/20 02:42:12 dillon Exp $ */ 3 /* $KAME: ip6_mroute.h,v 1.19 2001/06/14 06:12:55 suz Exp $ */ 4 5 /* 6 * Copyright (C) 1998 WIDE Project. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the project nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 /* BSDI ip_mroute.h,v 2.5 1996/10/11 16:01:48 pjd Exp */ 35 36 /* 37 * Definitions for IP multicast forwarding. 38 * 39 * Written by David Waitzman, BBN Labs, August 1988. 40 * Modified by Steve Deering, Stanford, February 1989. 41 * Modified by Ajit Thyagarajan, PARC, August 1993. 42 * Modified by Ajit Thyagarajan, PARC, August 1994. 43 * Modified by Ahmed Helmy, USC, September 1996. 44 * 45 * MROUTING Revision: 1.2 46 */ 47 48 #ifndef _NETINET6_IP6_MROUTE_H_ 49 #define _NETINET6_IP6_MROUTE_H_ 50 51 #ifndef _SYS_TYPES_H_ 52 #include <sys/types.h> 53 #endif 54 #ifndef _SYS_TIME_H_ 55 #include <sys/time.h> 56 #endif 57 #ifndef _SYS_SOCKET_H_ 58 #include <sys/socket.h> 59 #endif 60 #ifndef _NETINET_IN_H_ 61 #include <netinet/in.h> 62 #endif 63 64 /* 65 * Multicast Routing set/getsockopt commands. 66 */ 67 #ifdef _KERNEL 68 #define MRT6_OINIT 100 /* initialize forwarder (omrt6msg) */ 69 #endif 70 #define MRT6_DONE 101 /* shut down forwarder */ 71 #define MRT6_ADD_MIF 102 /* add multicast interface */ 72 #define MRT6_DEL_MIF 103 /* delete multicast interface */ 73 #define MRT6_ADD_MFC 104 /* insert forwarding cache entry */ 74 #define MRT6_DEL_MFC 105 /* delete forwarding cache entry */ 75 #define MRT6_PIM 107 /* enable pim code */ 76 #define MRT6_INIT 108 /* initialize forwarder (mrt6msg) */ 77 78 #if BSD >= 199103 79 #define GET_TIME(t) microtime(&t) 80 #elif defined(sun) 81 #define GET_TIME(t) uniqtime(&t) 82 #else 83 #define GET_TIME(t) ((t) = time) 84 #endif 85 86 /* 87 * Types and macros for handling bitmaps with one bit per multicast interface. 88 */ 89 typedef u_short mifi_t; /* type of a mif index */ 90 #define MAXMIFS 64 91 92 #ifndef IF_SETSIZE 93 #define IF_SETSIZE 256 94 #endif 95 96 typedef u_int32_t if_mask; 97 #define NIFBITS (sizeof(if_mask) * NBBY) /* bits per mask */ 98 99 #ifndef howmany 100 #define howmany(x, y) (((x) + ((y) - 1)) / (y)) 101 #endif 102 103 typedef struct if_set { 104 if_mask ifs_bits[howmany(IF_SETSIZE, NIFBITS)]; 105 } if_set; 106 107 #define IF_SET(n, p) ((p)->ifs_bits[(n)/NIFBITS] |= (1 << ((n) % NIFBITS))) 108 #define IF_CLR(n, p) ((p)->ifs_bits[(n)/NIFBITS] &= ~(1 << ((n) % NIFBITS))) 109 #define IF_ISSET(n, p) ((p)->ifs_bits[(n)/NIFBITS] & (1 << ((n) % NIFBITS))) 110 #define IF_COPY(f, t) bcopy(f, t, sizeof(*(f))) 111 #define IF_ZERO(p) bzero(p, sizeof(*(p))) 112 113 /* 114 * Argument structure for MRT6_ADD_IF. 115 */ 116 struct mif6ctl { 117 mifi_t mif6c_mifi; /* the index of the mif to be added */ 118 u_char mif6c_flags; /* MIFF_ flags defined below */ 119 u_short mif6c_pifi; /* the index of the physical IF */ 120 #ifdef notyet 121 u_int mif6c_rate_limit; /* max rate */ 122 #endif 123 }; 124 125 #define MIFF_REGISTER 0x1 /* mif represents a register end-point */ 126 127 /* 128 * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC 129 */ 130 struct mf6cctl { 131 struct sockaddr_in6 mf6cc_origin; /* IPv6 origin of mcasts */ 132 struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */ 133 mifi_t mf6cc_parent; /* incoming ifindex */ 134 struct if_set mf6cc_ifset; /* set of forwarding ifs */ 135 }; 136 137 /* 138 * The kernel's multicast routing statistics. 139 */ 140 struct mrt6stat { 141 u_quad_t mrt6s_mfc_lookups; /* # forw. cache hash table hits */ 142 u_quad_t mrt6s_mfc_misses; /* # forw. cache hash table misses */ 143 u_quad_t mrt6s_upcalls; /* # calls to mrouted */ 144 u_quad_t mrt6s_no_route; /* no route for packet's origin */ 145 u_quad_t mrt6s_bad_tunnel; /* malformed tunnel options */ 146 u_quad_t mrt6s_cant_tunnel; /* no room for tunnel options */ 147 u_quad_t mrt6s_wrong_if; /* arrived on wrong interface */ 148 u_quad_t mrt6s_upq_ovflw; /* upcall Q overflow */ 149 u_quad_t mrt6s_cache_cleanups; /* # entries with no upcalls */ 150 u_quad_t mrt6s_drop_sel; /* pkts dropped selectively */ 151 u_quad_t mrt6s_q_overflow; /* pkts dropped - Q overflow */ 152 u_quad_t mrt6s_pkt2large; /* pkts dropped - size > BKT SIZE */ 153 u_quad_t mrt6s_upq_sockfull; /* upcalls dropped - socket full */ 154 }; 155 156 #ifdef MRT6_OINIT 157 /* 158 * Struct used to communicate from kernel to multicast router 159 * note the convenient similarity to an IPv6 header. 160 * XXX old version, superseded by mrt6msg. 161 */ 162 struct omrt6msg { 163 u_long unused1; 164 u_char im6_msgtype; /* what type of message */ 165 #if 0 166 #define MRT6MSG_NOCACHE 1 167 #define MRT6MSG_WRONGMIF 2 168 #define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/ 169 #endif 170 u_char im6_mbz; /* must be zero */ 171 u_char im6_mif; /* mif rec'd on */ 172 u_char unused2; 173 struct in6_addr im6_src, im6_dst; 174 }; 175 #endif 176 177 /* 178 * Structure used to communicate from kernel to multicast router. 179 * We'll overlay the structure onto an MLD header (not an IPv6 header 180 * like igmpmsg{} used for IPv4 implementation). This is because this 181 * structure will be passed via an IPv6 raw socket, on which an application 182 * will only receive the payload i.e. the data after the IPv6 header and all 183 * the extension headers. (see Section 3 of draft-ietf-ipngwg-2292bis-01) 184 */ 185 struct mrt6msg { 186 #define MRT6MSG_NOCACHE 1 187 #define MRT6MSG_WRONGMIF 2 188 #define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/ 189 u_char im6_mbz; /* must be zero */ 190 u_char im6_msgtype; /* what type of message */ 191 u_int16_t im6_mif; /* mif rec'd on */ 192 u_int32_t im6_pad; /* padding for 64bit arch */ 193 struct in6_addr im6_src, im6_dst; 194 }; 195 196 /* 197 * Argument structure used by multicast routing daemon to get src-grp 198 * packet counts 199 */ 200 struct sioc_sg_req6 { 201 struct sockaddr_in6 src; 202 struct sockaddr_in6 grp; 203 u_quad_t pktcnt; 204 u_quad_t bytecnt; 205 u_quad_t wrong_if; 206 }; 207 208 /* 209 * Argument structure used by mrouted to get mif pkt counts 210 */ 211 struct sioc_mif_req6 { 212 mifi_t mifi; /* mif number */ 213 u_quad_t icount; /* Input packet count on mif */ 214 u_quad_t ocount; /* Output packet count on mif */ 215 u_quad_t ibytes; /* Input byte count on mif */ 216 u_quad_t obytes; /* Output byte count on mif */ 217 }; 218 219 #if defined(_KERNEL) || defined(KERNEL) 220 /* 221 * The kernel's multicast-interface structure. 222 */ 223 struct mif6 { 224 u_char m6_flags; /* MIFF_ flags defined above */ 225 u_int m6_rate_limit; /* max rate */ 226 #ifdef notyet 227 struct tbf *m6_tbf; /* token bucket structure at intf. */ 228 #endif 229 struct in6_addr m6_lcl_addr; /* local interface address */ 230 struct ifnet *m6_ifp; /* pointer to interface */ 231 u_quad_t m6_pkt_in; /* # pkts in on interface */ 232 u_quad_t m6_pkt_out; /* # pkts out on interface */ 233 u_quad_t m6_bytes_in; /* # bytes in on interface */ 234 u_quad_t m6_bytes_out; /* # bytes out on interface */ 235 struct route_in6 m6_route;/* cached route if this is a tunnel */ 236 #ifdef notyet 237 u_int m6_rsvp_on; /* RSVP listening on this vif */ 238 struct socket *m6_rsvpd; /* RSVP daemon socket */ 239 #endif 240 }; 241 242 /* 243 * The kernel's multicast forwarding cache entry structure 244 */ 245 struct mf6c { 246 struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */ 247 struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/ 248 mifi_t mf6c_parent; /* incoming IF */ 249 struct if_set mf6c_ifset; /* set of outgoing IFs */ 250 251 u_quad_t mf6c_pkt_cnt; /* pkt count for src-grp */ 252 u_quad_t mf6c_byte_cnt; /* byte count for src-grp */ 253 u_quad_t mf6c_wrong_if; /* wrong if for src-grp */ 254 int mf6c_expire; /* time to clean entry up */ 255 struct timeval mf6c_last_assert; /* last time I sent an assert*/ 256 struct rtdetq *mf6c_stall; /* pkts waiting for route */ 257 struct mf6c *mf6c_next; /* hash table linkage */ 258 }; 259 260 #define MF6C_INCOMPLETE_PARENT ((mifi_t)-1) 261 262 /* 263 * Argument structure used for pkt info. while upcall is made 264 */ 265 #ifndef _NETINET_IP_MROUTE_H_ 266 struct rtdetq { /* XXX: rtdetq is also defined in ip_mroute.h */ 267 struct mbuf *m; /* A copy of the packet */ 268 struct ifnet *ifp; /* Interface pkt came in on */ 269 #ifdef UPCALL_TIMING 270 struct timeval t; /* Timestamp */ 271 #endif /* UPCALL_TIMING */ 272 struct rtdetq *next; 273 }; 274 #endif /* _NETINET_IP_MROUTE_H_ */ 275 276 #define MF6CTBLSIZ 256 277 #if (MF6CTBLSIZ & (MF6CTBLSIZ - 1)) == 0 /* from sys:route.h */ 278 #define MF6CHASHMOD(h) ((h) & (MF6CTBLSIZ - 1)) 279 #else 280 #define MF6CHASHMOD(h) ((h) % MF6CTBLSIZ) 281 #endif 282 283 #define MAX_UPQ6 4 /* max. no of pkts in upcall Q */ 284 285 struct sockopt; 286 struct socket; 287 288 int ip6_mrouter_set (struct socket *so, struct sockopt *sopt); 289 int ip6_mrouter_get (struct socket *so, struct sockopt *sopt); 290 int ip6_mrouter_done (void); 291 int mrt6_ioctl (int, caddr_t); 292 #endif /* _KERNEL */ 293 294 #endif /* !_NETINET6_IP6_MROUTE_H_ */ 295