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