1139826Simp/*- 256723Sshin * Copyright (C) 1998 WIDE Project. 356723Sshin * All rights reserved. 456723Sshin * 556723Sshin * Redistribution and use in source and binary forms, with or without 656723Sshin * modification, are permitted provided that the following conditions 756723Sshin * are met: 856723Sshin * 1. Redistributions of source code must retain the above copyright 956723Sshin * notice, this list of conditions and the following disclaimer. 1056723Sshin * 2. Redistributions in binary form must reproduce the above copyright 1156723Sshin * notice, this list of conditions and the following disclaimer in the 1256723Sshin * documentation and/or other materials provided with the distribution. 1356723Sshin * 3. Neither the name of the project nor the names of its contributors 1456723Sshin * may be used to endorse or promote products derived from this software 1556723Sshin * without specific prior written permission. 1656723Sshin * 1756723Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 1856723Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1956723Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2056723Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2156723Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2256723Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2356723Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2456723Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2556723Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2656723Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2756723Sshin * SUCH DAMAGE. 28174510Sobrien * 29174510Sobrien * $KAME: ip6_mroute.h,v 1.19 2001/06/14 06:12:55 suz Exp $ 30174510Sobrien * $FreeBSD$ 3156723Sshin */ 3256723Sshin 3356723Sshin/* BSDI ip_mroute.h,v 2.5 1996/10/11 16:01:48 pjd Exp */ 3456723Sshin 3556723Sshin/* 3656723Sshin * Definitions for IP multicast forwarding. 3756723Sshin * 3856723Sshin * Written by David Waitzman, BBN Labs, August 1988. 3956723Sshin * Modified by Steve Deering, Stanford, February 1989. 4056723Sshin * Modified by Ajit Thyagarajan, PARC, August 1993. 4156723Sshin * Modified by Ajit Thyagarajan, PARC, August 1994. 4256723Sshin * Modified by Ahmed Helmy, USC, September 1996. 4356723Sshin * 4456723Sshin * MROUTING Revision: 1.2 4556723Sshin */ 4656723Sshin 4756723Sshin#ifndef _NETINET6_IP6_MROUTE_H_ 4862587Sitojun#define _NETINET6_IP6_MROUTE_H_ 4956723Sshin 5056723Sshin/* 5156723Sshin * Multicast Routing set/getsockopt commands. 5256723Sshin */ 5362587Sitojun#ifdef _KERNEL 5462587Sitojun#define MRT6_OINIT 100 /* initialize forwarder (omrt6msg) */ 5556723Sshin#endif 5656723Sshin#define MRT6_DONE 101 /* shut down forwarder */ 5756723Sshin#define MRT6_ADD_MIF 102 /* add multicast interface */ 5856723Sshin#define MRT6_DEL_MIF 103 /* delete multicast interface */ 5956723Sshin#define MRT6_ADD_MFC 104 /* insert forwarding cache entry */ 6056723Sshin#define MRT6_DEL_MFC 105 /* delete forwarding cache entry */ 6156723Sshin#define MRT6_PIM 107 /* enable pim code */ 6262587Sitojun#define MRT6_INIT 108 /* initialize forwarder (mrt6msg) */ 6356723Sshin 6462587Sitojun#if BSD >= 199103 6556723Sshin#define GET_TIME(t) microtime(&t) 6656723Sshin#elif defined(sun) 6756723Sshin#define GET_TIME(t) uniqtime(&t) 6856723Sshin#else 6956723Sshin#define GET_TIME(t) ((t) = time) 7056723Sshin#endif 7156723Sshin 7256723Sshin/* 7356723Sshin * Types and macros for handling bitmaps with one bit per multicast interface. 7456723Sshin */ 7556723Sshintypedef u_short mifi_t; /* type of a mif index */ 7656723Sshin#define MAXMIFS 64 7756723Sshin 7856723Sshin#ifndef IF_SETSIZE 7956723Sshin#define IF_SETSIZE 256 8056723Sshin#endif 8156723Sshin 8278064Sumetypedef u_int32_t if_mask; 8356723Sshin#define NIFBITS (sizeof(if_mask) * NBBY) /* bits per mask */ 8456723Sshin 8556723Sshin#ifndef howmany 8656723Sshin#define howmany(x, y) (((x) + ((y) - 1)) / (y)) 8756723Sshin#endif 8856723Sshin 8956723Sshintypedef struct if_set { 9078064Sume if_mask ifs_bits[howmany(IF_SETSIZE, NIFBITS)]; 9156723Sshin} if_set; 9256723Sshin 9356723Sshin#define IF_SET(n, p) ((p)->ifs_bits[(n)/NIFBITS] |= (1 << ((n) % NIFBITS))) 9456723Sshin#define IF_CLR(n, p) ((p)->ifs_bits[(n)/NIFBITS] &= ~(1 << ((n) % NIFBITS))) 9556723Sshin#define IF_ISSET(n, p) ((p)->ifs_bits[(n)/NIFBITS] & (1 << ((n) % NIFBITS))) 9656723Sshin#define IF_COPY(f, t) bcopy(f, t, sizeof(*(f))) 9756723Sshin#define IF_ZERO(p) bzero(p, sizeof(*(p))) 9856723Sshin 9956723Sshin/* 10056723Sshin * Argument structure for MRT6_ADD_IF. 10156723Sshin */ 10256723Sshinstruct mif6ctl { 103171260Sdelphij mifi_t mif6c_mifi; /* the index of the mif to be added */ 104171260Sdelphij u_char mif6c_flags; /* MIFF_ flags defined below */ 10556723Sshin u_short mif6c_pifi; /* the index of the physical IF */ 10656723Sshin}; 10756723Sshin 10856723Sshin#define MIFF_REGISTER 0x1 /* mif represents a register end-point */ 10956723Sshin 11056723Sshin/* 11156723Sshin * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC 11256723Sshin */ 11356723Sshinstruct mf6cctl { 11456723Sshin struct sockaddr_in6 mf6cc_origin; /* IPv6 origin of mcasts */ 11556723Sshin struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */ 11656723Sshin mifi_t mf6cc_parent; /* incoming ifindex */ 11756723Sshin struct if_set mf6cc_ifset; /* set of forwarding ifs */ 11856723Sshin}; 11956723Sshin 12056723Sshin/* 12156723Sshin * The kernel's multicast routing statistics. 12256723Sshin */ 12356723Sshinstruct mrt6stat { 124253081Sae uint64_t mrt6s_mfc_lookups; /* # forw. cache hash table hits */ 125253081Sae uint64_t mrt6s_mfc_misses; /* # forw. cache hash table misses */ 126253081Sae uint64_t mrt6s_upcalls; /* # calls to multicast routing daemon */ 127253081Sae uint64_t mrt6s_no_route; /* no route for packet's origin */ 128253081Sae uint64_t mrt6s_bad_tunnel; /* malformed tunnel options */ 129253081Sae uint64_t mrt6s_cant_tunnel; /* no room for tunnel options */ 130253081Sae uint64_t mrt6s_wrong_if; /* arrived on wrong interface */ 131253081Sae uint64_t mrt6s_upq_ovflw; /* upcall Q overflow */ 132253081Sae uint64_t mrt6s_cache_cleanups; /* # entries with no upcalls */ 133253081Sae uint64_t mrt6s_drop_sel; /* pkts dropped selectively */ 134253081Sae uint64_t mrt6s_q_overflow; /* pkts dropped - Q overflow */ 135253081Sae uint64_t mrt6s_pkt2large; /* pkts dropped - size > BKT SIZE */ 136253081Sae uint64_t mrt6s_upq_sockfull; /* upcalls dropped - socket full */ 13756723Sshin}; 13856723Sshin 13962587Sitojun#ifdef MRT6_OINIT 14056723Sshin/* 14156723Sshin * Struct used to communicate from kernel to multicast router 14256723Sshin * note the convenient similarity to an IPv6 header. 14362587Sitojun * XXX old version, superseded by mrt6msg. 14456723Sshin */ 14562587Sitojunstruct omrt6msg { 14656723Sshin u_long unused1; 14756723Sshin u_char im6_msgtype; /* what type of message */ 14856723Sshin u_char im6_mbz; /* must be zero */ 14956723Sshin u_char im6_mif; /* mif rec'd on */ 15056723Sshin u_char unused2; 15156723Sshin struct in6_addr im6_src, im6_dst; 15256723Sshin}; 15362587Sitojun#endif 15456723Sshin 15556723Sshin/* 15662587Sitojun * Structure used to communicate from kernel to multicast router. 15762587Sitojun * We'll overlay the structure onto an MLD header (not an IPv6 header 15862587Sitojun * like igmpmsg{} used for IPv4 implementation). This is because this 15962587Sitojun * structure will be passed via an IPv6 raw socket, on which an application 16062587Sitojun * will only receive the payload i.e. the data after the IPv6 header and all 161148169Sume * the extension headers. (see Section 3 of RFC3542) 16262587Sitojun */ 16362587Sitojunstruct mrt6msg { 16462587Sitojun#define MRT6MSG_NOCACHE 1 16562587Sitojun#define MRT6MSG_WRONGMIF 2 16662587Sitojun#define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/ 16762587Sitojun u_char im6_mbz; /* must be zero */ 16862587Sitojun u_char im6_msgtype; /* what type of message */ 16962587Sitojun u_int16_t im6_mif; /* mif rec'd on */ 17062587Sitojun u_int32_t im6_pad; /* padding for 64bit arch */ 17162587Sitojun struct in6_addr im6_src, im6_dst; 17262587Sitojun}; 17362587Sitojun 17462587Sitojun/* 17556723Sshin * Argument structure used by multicast routing daemon to get src-grp 17656723Sshin * packet counts 17756723Sshin */ 17856723Sshinstruct sioc_sg_req6 { 17956723Sshin struct sockaddr_in6 src; 18056723Sshin struct sockaddr_in6 grp; 18156723Sshin u_quad_t pktcnt; 18256723Sshin u_quad_t bytecnt; 18356723Sshin u_quad_t wrong_if; 18456723Sshin}; 18556723Sshin 18656723Sshin/* 18756723Sshin * Argument structure used by mrouted to get mif pkt counts 18856723Sshin */ 18956723Sshinstruct sioc_mif_req6 { 19056723Sshin mifi_t mifi; /* mif number */ 19156723Sshin u_quad_t icount; /* Input packet count on mif */ 19256723Sshin u_quad_t ocount; /* Output packet count on mif */ 19356723Sshin u_quad_t ibytes; /* Input byte count on mif */ 19456723Sshin u_quad_t obytes; /* Output byte count on mif */ 19556723Sshin}; 19656723Sshin 197281172Sglebius/* 198281172Sglebius * Structure to export 'struct mif6' to userland via sysctl. 199281172Sglebius */ 200281172Sglebiusstruct mif6_sctl { 201281172Sglebius u_char m6_flags; /* MIFF_ flags defined above */ 202281172Sglebius u_int m6_rate_limit; /* max rate */ 203281172Sglebius struct in6_addr m6_lcl_addr; /* local interface address */ 204281172Sglebius uint32_t m6_ifp; /* interface index */ 205281172Sglebius u_quad_t m6_pkt_in; /* # pkts in on interface */ 206281172Sglebius u_quad_t m6_pkt_out; /* # pkts out on interface */ 207281172Sglebius u_quad_t m6_bytes_in; /* # bytes in on interface */ 208281172Sglebius u_quad_t m6_bytes_out; /* # bytes out on interface */ 209281172Sglebius}; 210281172Sglebius 211260496Sjmg#if defined(_KERNEL) || defined(KERNEL) 21256723Sshin/* 21356723Sshin * The kernel's multicast-interface structure. 21456723Sshin */ 21556723Sshinstruct mif6 { 216171260Sdelphij u_char m6_flags; /* MIFF_ flags defined above */ 217171260Sdelphij u_int m6_rate_limit; /* max rate */ 218171260Sdelphij struct in6_addr m6_lcl_addr; /* local interface address */ 219171260Sdelphij struct ifnet *m6_ifp; /* pointer to interface */ 22056723Sshin u_quad_t m6_pkt_in; /* # pkts in on interface */ 22156723Sshin u_quad_t m6_pkt_out; /* # pkts out on interface */ 22256723Sshin u_quad_t m6_bytes_in; /* # bytes in on interface */ 22356723Sshin u_quad_t m6_bytes_out; /* # bytes out on interface */ 22456723Sshin#ifdef notyet 22556723Sshin u_int m6_rsvp_on; /* RSVP listening on this vif */ 22656723Sshin struct socket *m6_rsvpd; /* RSVP daemon socket */ 22762587Sitojun#endif 22856723Sshin}; 22956723Sshin 23056723Sshin/* 23162587Sitojun * The kernel's multicast forwarding cache entry structure 23256723Sshin */ 23356723Sshinstruct mf6c { 23456723Sshin struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */ 23556723Sshin struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/ 236171260Sdelphij mifi_t mf6c_parent; /* incoming IF */ 23756723Sshin struct if_set mf6c_ifset; /* set of outgoing IFs */ 23856723Sshin 239171260Sdelphij u_quad_t mf6c_pkt_cnt; /* pkt count for src-grp */ 240171260Sdelphij u_quad_t mf6c_byte_cnt; /* byte count for src-grp */ 241171260Sdelphij u_quad_t mf6c_wrong_if; /* wrong if for src-grp */ 242171260Sdelphij int mf6c_expire; /* time to clean entry up */ 24356723Sshin struct timeval mf6c_last_assert; /* last time I sent an assert*/ 24456723Sshin struct rtdetq *mf6c_stall; /* pkts waiting for route */ 24556723Sshin struct mf6c *mf6c_next; /* hash table linkage */ 24656723Sshin}; 24756723Sshin 24856723Sshin#define MF6C_INCOMPLETE_PARENT ((mifi_t)-1) 24956723Sshin 25056723Sshin/* 25156723Sshin * Argument structure used for pkt info. while upcall is made 25256723Sshin */ 25356723Sshin#ifndef _NETINET_IP_MROUTE_H_ 25456723Sshinstruct rtdetq { /* XXX: rtdetq is also defined in ip_mroute.h */ 255171260Sdelphij struct mbuf *m; /* A copy of the packet */ 256171260Sdelphij struct ifnet *ifp; /* Interface pkt came in on */ 25756723Sshin#ifdef UPCALL_TIMING 25856723Sshin struct timeval t; /* Timestamp */ 25956723Sshin#endif /* UPCALL_TIMING */ 26056723Sshin struct rtdetq *next; 26156723Sshin}; 26256723Sshin#endif /* _NETINET_IP_MROUTE_H_ */ 26356723Sshin 26456723Sshin#define MF6CTBLSIZ 256 26556723Sshin#if (MF6CTBLSIZ & (MF6CTBLSIZ - 1)) == 0 /* from sys:route.h */ 26656723Sshin#define MF6CHASHMOD(h) ((h) & (MF6CTBLSIZ - 1)) 26756723Sshin#else 26856723Sshin#define MF6CHASHMOD(h) ((h) % MF6CTBLSIZ) 26956723Sshin#endif 27056723Sshin 27156723Sshin#define MAX_UPQ6 4 /* max. no of pkts in upcall Q */ 27256723Sshin 273166938Sbmsextern int (*ip6_mrouter_set)(struct socket *so, struct sockopt *sopt); 274166938Sbmsextern int (*ip6_mrouter_get)(struct socket *so, struct sockopt *sopt); 275166938Sbmsextern int (*ip6_mrouter_done)(void); 276194581Srdivackyextern int (*mrt6_ioctl)(u_long, caddr_t); 27756723Sshin#endif /* _KERNEL */ 27856723Sshin 27956723Sshin#endif /* !_NETINET6_IP6_MROUTE_H_ */ 280