1 /* 2 * Copyright (C) 1998 WIDE Project. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the project nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD$ 30 */ 31 32 /* BSDI ip_mroute.h,v 2.5 1996/10/11 16:01:48 pjd Exp */ 33 34 /* 35 * Definitions for IP multicast forwarding. 36 * 37 * Written by David Waitzman, BBN Labs, August 1988. 38 * Modified by Steve Deering, Stanford, February 1989. 39 * Modified by Ajit Thyagarajan, PARC, August 1993. 40 * Modified by Ajit Thyagarajan, PARC, August 1994. 41 * Modified by Ahmed Helmy, USC, September 1996. 42 * 43 * MROUTING Revision: 1.2 44 */ 45 46 #ifndef _NETINET6_IP6_MROUTE_H_ 47 #define _NETINET6_IP6_MROUTE_H_ 48 49 /* 50 * Multicast Routing set/getsockopt commands. 51 */ 52 #define MRT6_INIT 100 /* initialize forwarder */ 53 #define MRT6_DONE 101 /* shut down forwarder */ 54 #define MRT6_ADD_MIF 102 /* add multicast interface */ 55 #define MRT6_DEL_MIF 103 /* delete multicast interface */ 56 #define MRT6_ADD_MFC 104 /* insert forwarding cache entry */ 57 #define MRT6_DEL_MFC 105 /* delete forwarding cache entry */ 58 #define MRT6_PIM 107 /* enable pim code */ 59 60 #define GET_TIME(t) microtime(&t) 61 62 /* 63 * Types and macros for handling bitmaps with one bit per multicast interface. 64 */ 65 typedef u_short mifi_t; /* type of a mif index */ 66 #define MAXMIFS 64 67 68 #ifndef IF_SETSIZE 69 #define IF_SETSIZE 256 70 #endif 71 72 typedef long if_mask; 73 #define NIFBITS (sizeof(if_mask) * NBBY) /* bits per mask */ 74 75 #ifndef howmany 76 #define howmany(x, y) (((x) + ((y) - 1)) / (y)) 77 #endif 78 79 typedef struct if_set { 80 fd_mask ifs_bits[howmany(IF_SETSIZE, NIFBITS)]; 81 } if_set; 82 83 #define IF_SET(n, p) ((p)->ifs_bits[(n)/NIFBITS] |= (1 << ((n) % NIFBITS))) 84 #define IF_CLR(n, p) ((p)->ifs_bits[(n)/NIFBITS] &= ~(1 << ((n) % NIFBITS))) 85 #define IF_ISSET(n, p) ((p)->ifs_bits[(n)/NIFBITS] & (1 << ((n) % NIFBITS))) 86 #define IF_COPY(f, t) bcopy(f, t, sizeof(*(f))) 87 #define IF_ZERO(p) bzero(p, sizeof(*(p))) 88 89 /* 90 * Argument structure for MRT6_ADD_IF. 91 */ 92 struct mif6ctl { 93 mifi_t mif6c_mifi; /* the index of the mif to be added */ 94 u_char mif6c_flags; /* MIFF_ flags defined below */ 95 u_short mif6c_pifi; /* the index of the physical IF */ 96 }; 97 98 #define MIFF_REGISTER 0x1 /* mif represents a register end-point */ 99 100 /* 101 * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC 102 */ 103 struct mf6cctl { 104 struct sockaddr_in6 mf6cc_origin; /* IPv6 origin of mcasts */ 105 struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */ 106 mifi_t mf6cc_parent; /* incoming ifindex */ 107 struct if_set mf6cc_ifset; /* set of forwarding ifs */ 108 }; 109 110 /* 111 * The kernel's multicast routing statistics. 112 */ 113 struct mrt6stat { 114 u_quad_t mrt6s_mfc_lookups; /* # forw. cache hash table hits */ 115 u_quad_t mrt6s_mfc_misses; /* # forw. cache hash table misses */ 116 u_quad_t mrt6s_upcalls; /* # calls to mrouted */ 117 u_quad_t mrt6s_no_route; /* no route for packet's origin */ 118 u_quad_t mrt6s_bad_tunnel; /* malformed tunnel options */ 119 u_quad_t mrt6s_cant_tunnel; /* no room for tunnel options */ 120 u_quad_t mrt6s_wrong_if; /* arrived on wrong interface */ 121 u_quad_t mrt6s_upq_ovflw; /* upcall Q overflow */ 122 u_quad_t mrt6s_cache_cleanups; /* # entries with no upcalls */ 123 u_quad_t mrt6s_drop_sel; /* pkts dropped selectively */ 124 u_quad_t mrt6s_q_overflow; /* pkts dropped - Q overflow */ 125 u_quad_t mrt6s_pkt2large; /* pkts dropped - size > BKT SIZE */ 126 u_quad_t mrt6s_upq_sockfull; /* upcalls dropped - socket full */ 127 }; 128 129 /* 130 * Struct used to communicate from kernel to multicast router 131 * note the convenient similarity to an IPv6 header. 132 */ 133 struct mrt6msg { 134 u_long unused1; 135 u_char im6_msgtype; /* what type of message */ 136 #define MRT6MSG_NOCACHE 1 137 #define MRT6MSG_WRONGMIF 2 138 #define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/ 139 u_char im6_mbz; /* must be zero */ 140 u_char im6_mif; /* mif rec'd on */ 141 u_char unused2; 142 struct in6_addr im6_src, im6_dst; 143 }; 144 145 /* 146 * Argument structure used by multicast routing daemon to get src-grp 147 * packet counts 148 */ 149 struct sioc_sg_req6 { 150 struct sockaddr_in6 src; 151 struct sockaddr_in6 grp; 152 u_quad_t pktcnt; 153 u_quad_t bytecnt; 154 u_quad_t wrong_if; 155 }; 156 157 /* 158 * Argument structure used by mrouted to get mif pkt counts 159 */ 160 struct sioc_mif_req6 { 161 mifi_t mifi; /* mif number */ 162 u_quad_t icount; /* Input packet count on mif */ 163 u_quad_t ocount; /* Output packet count on mif */ 164 u_quad_t ibytes; /* Input byte count on mif */ 165 u_quad_t obytes; /* Output byte count on mif */ 166 }; 167 168 #if defined(_KERNEL) || defined(KERNEL) 169 /* 170 * The kernel's multicast-interface structure. 171 */ 172 struct mif6 { 173 u_char m6_flags; /* MIFF_ flags defined above */ 174 u_int m6_rate_limit; /* max rate */ 175 struct in6_addr m6_lcl_addr; /* local interface address */ 176 struct ifnet *m6_ifp; /* pointer to interface */ 177 u_quad_t m6_pkt_in; /* # pkts in on interface */ 178 u_quad_t m6_pkt_out; /* # pkts out on interface */ 179 u_quad_t m6_bytes_in; /* # bytes in on interface */ 180 u_quad_t m6_bytes_out; /* # bytes out on interface */ 181 struct route_in6 m6_route;/* cached route if this is a tunnel */ 182 }; 183 184 /* 185 * The kernel's multicast forwarding cache entry structure 186 */ 187 struct mf6c { 188 struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */ 189 struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/ 190 mifi_t mf6c_parent; /* incoming IF */ 191 struct if_set mf6c_ifset; /* set of outgoing IFs */ 192 u_quad_t mf6c_pkt_cnt; /* pkt count for src-grp */ 193 u_quad_t mf6c_byte_cnt; /* byte count for src-grp */ 194 u_quad_t mf6c_wrong_if; /* wrong if for src-grp */ 195 int mf6c_expire; /* time to clean entry up */ 196 struct timeval mf6c_last_assert; /* last time I sent an assert*/ 197 struct rtdetq *mf6c_stall; /* pkts waiting for route */ 198 struct mf6c *mf6c_next; /* hash table linkage */ 199 }; 200 201 #define MF6C_INCOMPLETE_PARENT ((mifi_t)-1) 202 203 /* 204 * Argument structure used for pkt info. while upcall is made 205 */ 206 #ifndef _NETINET_IP_MROUTE_H_ 207 struct rtdetq { /* XXX: rtdetq is also defined in ip_mroute.h */ 208 struct mbuf *m; /* A copy of the packet */ 209 struct ifnet *ifp; /* Interface pkt came in on */ 210 #ifdef UPCALL_TIMING 211 struct timeval t; /* Timestamp */ 212 #endif /* UPCALL_TIMING */ 213 struct rtdetq *next; 214 }; 215 #endif /* _NETINET_IP_MROUTE_H_ */ 216 217 #define MF6CTBLSIZ 256 218 #if (MF6CTBLSIZ & (MF6CTBLSIZ - 1)) == 0 /* from sys:route.h */ 219 #define MF6CHASHMOD(h) ((h) & (MF6CTBLSIZ - 1)) 220 #else 221 #define MF6CHASHMOD(h) ((h) % MF6CTBLSIZ) 222 #endif 223 224 #define MAX_UPQ6 4 /* max. no of pkts in upcall Q */ 225 226 int ip6_mrouter_set __P((struct socket *so, struct sockopt *sopt)); 227 int ip6_mrouter_get __P((struct socket *so, struct sockopt *sopt)); 228 int ip6_mrouter_done __P((void)); 229 int mrt6_ioctl __P((int, caddr_t)); 230 #endif /* _KERNEL */ 231 232 #endif /* !_NETINET6_IP6_MROUTE_H_ */ 233 /* 234 * Copyright (C) 1998 WIDE Project. 235 * All rights reserved. 236 * 237 * Redistribution and use in source and binary forms, with or without 238 * modification, are permitted provided that the following conditions 239 * are met: 240 * 1. Redistributions of source code must retain the above copyright 241 * notice, this list of conditions and the following disclaimer. 242 * 2. Redistributions in binary form must reproduce the above copyright 243 * notice, this list of conditions and the following disclaimer in the 244 * documentation and/or other materials provided with the distribution. 245 * 3. Neither the name of the project nor the names of its contributors 246 * may be used to endorse or promote products derived from this software 247 * without specific prior written permission. 248 * 249 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 250 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 252 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 253 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 255 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 256 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 257 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 258 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 259 * SUCH DAMAGE. 260 */ 261 262 /* BSDI ip_mroute.h,v 2.5 1996/10/11 16:01:48 pjd Exp */ 263 264 /* 265 * Definitions for IP multicast forwarding. 266 * 267 * Written by David Waitzman, BBN Labs, August 1988. 268 * Modified by Steve Deering, Stanford, February 1989. 269 * Modified by Ajit Thyagarajan, PARC, August 1993. 270 * Modified by Ajit Thyagarajan, PARC, August 1994. 271 * Modified by Ahmed Helmy, USC, September 1996. 272 * 273 * MROUTING Revision: 1.2 274 */ 275 276 #ifndef _NETINET6_IP6_MROUTE_H_ 277 #define _NETINET6_IP6_MROUTE_H_ 278 279 /* 280 * Multicast Routing set/getsockopt commands. 281 */ 282 #define MRT6_INIT 100 /* initialize forwarder */ 283 #define MRT6_DONE 101 /* shut down forwarder */ 284 #define MRT6_ADD_MIF 102 /* add multicast interface */ 285 #define MRT6_DEL_MIF 103 /* delete multicast interface */ 286 #define MRT6_ADD_MFC 104 /* insert forwarding cache entry */ 287 #define MRT6_DEL_MFC 105 /* delete forwarding cache entry */ 288 #define MRT6_PIM 107 /* enable pim code */ 289 290 #if BSD >= 199103 291 #define GET_TIME(t) microtime(&t) 292 #elif defined(sun) 293 #define GET_TIME(t) uniqtime(&t) 294 #else 295 #define GET_TIME(t) ((t) = time) 296 #endif 297 298 /* 299 * Types and macros for handling bitmaps with one bit per multicast interface. 300 */ 301 typedef u_short mifi_t; /* type of a mif index */ 302 #define MAXMIFS 64 303 304 #ifndef IF_SETSIZE 305 #define IF_SETSIZE 256 306 #endif 307 308 typedef long if_mask; 309 #define NIFBITS (sizeof(if_mask) * NBBY) /* bits per mask */ 310 311 #ifndef howmany 312 #define howmany(x, y) (((x) + ((y) - 1)) / (y)) 313 #endif 314 315 typedef struct if_set { 316 fd_mask ifs_bits[howmany(IF_SETSIZE, NIFBITS)]; 317 } if_set; 318 319 #define IF_SET(n, p) ((p)->ifs_bits[(n)/NIFBITS] |= (1 << ((n) % NIFBITS))) 320 #define IF_CLR(n, p) ((p)->ifs_bits[(n)/NIFBITS] &= ~(1 << ((n) % NIFBITS))) 321 #define IF_ISSET(n, p) ((p)->ifs_bits[(n)/NIFBITS] & (1 << ((n) % NIFBITS))) 322 #define IF_COPY(f, t) bcopy(f, t, sizeof(*(f))) 323 #define IF_ZERO(p) bzero(p, sizeof(*(p))) 324 325 /* 326 * Argument structure for MRT6_ADD_IF. 327 */ 328 struct mif6ctl { 329 mifi_t mif6c_mifi; /* the index of the mif to be added */ 330 u_char mif6c_flags; /* MIFF_ flags defined below */ 331 u_short mif6c_pifi; /* the index of the physical IF */ 332 #ifdef notyet 333 u_int mif6c_rate_limit; /* max rate */ 334 #endif 335 }; 336 337 #define MIFF_REGISTER 0x1 /* mif represents a register end-point */ 338 339 /* 340 * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC 341 */ 342 struct mf6cctl { 343 struct sockaddr_in6 mf6cc_origin; /* IPv6 origin of mcasts */ 344 struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */ 345 mifi_t mf6cc_parent; /* incoming ifindex */ 346 struct if_set mf6cc_ifset; /* set of forwarding ifs */ 347 }; 348 349 /* 350 * The kernel's multicast routing statistics. 351 */ 352 struct mrt6stat { 353 u_quad_t mrt6s_mfc_lookups; /* # forw. cache hash table hits */ 354 u_quad_t mrt6s_mfc_misses; /* # forw. cache hash table misses */ 355 u_quad_t mrt6s_upcalls; /* # calls to mrouted */ 356 u_quad_t mrt6s_no_route; /* no route for packet's origin */ 357 u_quad_t mrt6s_bad_tunnel; /* malformed tunnel options */ 358 u_quad_t mrt6s_cant_tunnel; /* no room for tunnel options */ 359 u_quad_t mrt6s_wrong_if; /* arrived on wrong interface */ 360 u_quad_t mrt6s_upq_ovflw; /* upcall Q overflow */ 361 u_quad_t mrt6s_cache_cleanups; /* # entries with no upcalls */ 362 u_quad_t mrt6s_drop_sel; /* pkts dropped selectively */ 363 u_quad_t mrt6s_q_overflow; /* pkts dropped - Q overflow */ 364 u_quad_t mrt6s_pkt2large; /* pkts dropped - size > BKT SIZE */ 365 u_quad_t mrt6s_upq_sockfull; /* upcalls dropped - socket full */ 366 }; 367 368 /* 369 * Struct used to communicate from kernel to multicast router 370 * note the convenient similarity to an IPv6 header. 371 */ 372 struct mrt6msg { 373 u_long unused1; 374 u_char im6_msgtype; /* what type of message */ 375 #define MRT6MSG_NOCACHE 1 376 #define MRT6MSG_WRONGMIF 2 377 #define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/ 378 u_char im6_mbz; /* must be zero */ 379 u_char im6_mif; /* mif rec'd on */ 380 u_char unused2; 381 struct in6_addr im6_src, im6_dst; 382 }; 383 384 /* 385 * Argument structure used by multicast routing daemon to get src-grp 386 * packet counts 387 */ 388 struct sioc_sg_req6 { 389 struct sockaddr_in6 src; 390 struct sockaddr_in6 grp; 391 u_quad_t pktcnt; 392 u_quad_t bytecnt; 393 u_quad_t wrong_if; 394 }; 395 396 /* 397 * Argument structure used by mrouted to get mif pkt counts 398 */ 399 struct sioc_mif_req6 { 400 mifi_t mifi; /* mif number */ 401 u_quad_t icount; /* Input packet count on mif */ 402 u_quad_t ocount; /* Output packet count on mif */ 403 u_quad_t ibytes; /* Input byte count on mif */ 404 u_quad_t obytes; /* Output byte count on mif */ 405 }; 406 407 #if defined(_KERNEL) || defined(KERNEL) 408 /* 409 * The kernel's multicast-interface structure. 410 */ 411 struct mif6 { 412 u_char m6_flags; /* MIFF_ flags defined above */ 413 u_int m6_rate_limit; /* max rate */ 414 #ifdef notyet 415 struct tbf *m6_tbf; /* token bucket structure at intf. */ 416 #endif 417 struct in6_addr m6_lcl_addr; /* local interface address */ 418 struct ifnet *m6_ifp; /* pointer to interface */ 419 u_quad_t m6_pkt_in; /* # pkts in on interface */ 420 u_quad_t m6_pkt_out; /* # pkts out on interface */ 421 u_quad_t m6_bytes_in; /* # bytes in on interface */ 422 u_quad_t m6_bytes_out; /* # bytes out on interface */ 423 struct route_in6 m6_route;/* cached route if this is a tunnel */ 424 #ifdef notyet 425 u_int m6_rsvp_on; /* RSVP listening on this vif */ 426 struct socket *m6_rsvpd; /* RSVP daemon socket */ 427 #endif 428 }; 429 430 /* 431 * The kernel's multicast forwarding cache entry structure 432 */ 433 struct mf6c { 434 struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */ 435 struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/ 436 mifi_t mf6c_parent; /* incoming IF */ 437 struct if_set mf6c_ifset; /* set of outgoing IFs */ 438 439 u_quad_t mf6c_pkt_cnt; /* pkt count for src-grp */ 440 u_quad_t mf6c_byte_cnt; /* byte count for src-grp */ 441 u_quad_t mf6c_wrong_if; /* wrong if for src-grp */ 442 int mf6c_expire; /* time to clean entry up */ 443 struct timeval mf6c_last_assert; /* last time I sent an assert*/ 444 struct rtdetq *mf6c_stall; /* pkts waiting for route */ 445 struct mf6c *mf6c_next; /* hash table linkage */ 446 }; 447 448 #define MF6C_INCOMPLETE_PARENT ((mifi_t)-1) 449 450 /* 451 * Argument structure used for pkt info. while upcall is made 452 */ 453 #ifndef _NETINET_IP_MROUTE_H_ 454 struct rtdetq { /* XXX: rtdetq is also defined in ip_mroute.h */ 455 struct mbuf *m; /* A copy of the packet */ 456 struct ifnet *ifp; /* Interface pkt came in on */ 457 #ifdef UPCALL_TIMING 458 struct timeval t; /* Timestamp */ 459 #endif /* UPCALL_TIMING */ 460 struct rtdetq *next; 461 }; 462 #endif /* _NETINET_IP_MROUTE_H_ */ 463 464 #define MF6CTBLSIZ 256 465 #if (MF6CTBLSIZ & (MF6CTBLSIZ - 1)) == 0 /* from sys:route.h */ 466 #define MF6CHASHMOD(h) ((h) & (MF6CTBLSIZ - 1)) 467 #else 468 #define MF6CHASHMOD(h) ((h) % MF6CTBLSIZ) 469 #endif 470 471 #define MAX_UPQ6 4 /* max. no of pkts in upcall Q */ 472 473 #if defined(__FreeBSD__) && __FreeBSD__ >= 3 474 int ip6_mrouter_set __P((struct socket *so, struct sockopt *sopt)); 475 int ip6_mrouter_get __P((struct socket *so, struct sockopt *sopt)); 476 #else 477 int ip6_mrouter_set __P((int, struct socket *, struct mbuf *)); 478 int ip6_mrouter_get __P((int, struct socket *, struct mbuf **)); 479 #endif 480 int ip6_mrouter_done __P((void)); 481 int mrt6_ioctl __P((int, caddr_t)); 482 #endif /* _KERNEL */ 483 484 #endif /* !_NETINET6_IP6_MROUTE_H_ */ 485