ip6_mroute.h revision 78064
162587Sitojun/* $FreeBSD: head/sys/netinet6/ip6_mroute.h 78064 2001-06-11 12:39:29Z ume $ */ 278064Sume/* $KAME: ip6_mroute.h,v 1.17 2001/02/10 02:05:52 itojun Exp $ */ 362587Sitojun 456723Sshin/* 556723Sshin * Copyright (C) 1998 WIDE Project. 656723Sshin * All rights reserved. 756723Sshin * 856723Sshin * Redistribution and use in source and binary forms, with or without 956723Sshin * modification, are permitted provided that the following conditions 1056723Sshin * are met: 1156723Sshin * 1. Redistributions of source code must retain the above copyright 1256723Sshin * notice, this list of conditions and the following disclaimer. 1356723Sshin * 2. Redistributions in binary form must reproduce the above copyright 1456723Sshin * notice, this list of conditions and the following disclaimer in the 1556723Sshin * documentation and/or other materials provided with the distribution. 1656723Sshin * 3. Neither the name of the project nor the names of its contributors 1756723Sshin * may be used to endorse or promote products derived from this software 1856723Sshin * without specific prior written permission. 1956723Sshin * 2056723Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2156723Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2256723Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2356723Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2456723Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2556723Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2656723Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2756723Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2856723Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2956723Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3056723Sshin * SUCH DAMAGE. 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 { 10356723Sshin mifi_t mif6c_mifi; /* the index of the mif to be added */ 10456723Sshin u_char mif6c_flags; /* MIFF_ flags defined below */ 10556723Sshin u_short mif6c_pifi; /* the index of the physical IF */ 10656723Sshin#ifdef notyet 10756723Sshin u_int mif6c_rate_limit; /* max rate */ 10856723Sshin#endif 10956723Sshin}; 11056723Sshin 11156723Sshin#define MIFF_REGISTER 0x1 /* mif represents a register end-point */ 11256723Sshin 11356723Sshin/* 11456723Sshin * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC 11556723Sshin */ 11656723Sshinstruct mf6cctl { 11756723Sshin struct sockaddr_in6 mf6cc_origin; /* IPv6 origin of mcasts */ 11856723Sshin struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */ 11956723Sshin mifi_t mf6cc_parent; /* incoming ifindex */ 12056723Sshin struct if_set mf6cc_ifset; /* set of forwarding ifs */ 12156723Sshin}; 12256723Sshin 12356723Sshin/* 12456723Sshin * The kernel's multicast routing statistics. 12556723Sshin */ 12656723Sshinstruct mrt6stat { 12756723Sshin u_quad_t mrt6s_mfc_lookups; /* # forw. cache hash table hits */ 12856723Sshin u_quad_t mrt6s_mfc_misses; /* # forw. cache hash table misses */ 12956723Sshin u_quad_t mrt6s_upcalls; /* # calls to mrouted */ 13056723Sshin u_quad_t mrt6s_no_route; /* no route for packet's origin */ 13156723Sshin u_quad_t mrt6s_bad_tunnel; /* malformed tunnel options */ 13256723Sshin u_quad_t mrt6s_cant_tunnel; /* no room for tunnel options */ 13356723Sshin u_quad_t mrt6s_wrong_if; /* arrived on wrong interface */ 13456723Sshin u_quad_t mrt6s_upq_ovflw; /* upcall Q overflow */ 13556723Sshin u_quad_t mrt6s_cache_cleanups; /* # entries with no upcalls */ 13656723Sshin u_quad_t mrt6s_drop_sel; /* pkts dropped selectively */ 13756723Sshin u_quad_t mrt6s_q_overflow; /* pkts dropped - Q overflow */ 13856723Sshin u_quad_t mrt6s_pkt2large; /* pkts dropped - size > BKT SIZE */ 13956723Sshin u_quad_t mrt6s_upq_sockfull; /* upcalls dropped - socket full */ 14056723Sshin}; 14156723Sshin 14262587Sitojun#ifdef MRT6_OINIT 14356723Sshin/* 14456723Sshin * Struct used to communicate from kernel to multicast router 14556723Sshin * note the convenient similarity to an IPv6 header. 14662587Sitojun * XXX old version, superseded by mrt6msg. 14756723Sshin */ 14862587Sitojunstruct omrt6msg { 14956723Sshin u_long unused1; 15056723Sshin u_char im6_msgtype; /* what type of message */ 15162587Sitojun#if 0 15262587Sitojun#define MRT6MSG_NOCACHE 1 15356723Sshin#define MRT6MSG_WRONGMIF 2 15456723Sshin#define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/ 15562587Sitojun#endif 15656723Sshin u_char im6_mbz; /* must be zero */ 15756723Sshin u_char im6_mif; /* mif rec'd on */ 15856723Sshin u_char unused2; 15956723Sshin struct in6_addr im6_src, im6_dst; 16056723Sshin}; 16162587Sitojun#endif 16256723Sshin 16356723Sshin/* 16462587Sitojun * Structure used to communicate from kernel to multicast router. 16562587Sitojun * We'll overlay the structure onto an MLD header (not an IPv6 header 16662587Sitojun * like igmpmsg{} used for IPv4 implementation). This is because this 16762587Sitojun * structure will be passed via an IPv6 raw socket, on which an application 16862587Sitojun * will only receive the payload i.e. the data after the IPv6 header and all 16962587Sitojun * the extension headers. (see Section 3 of draft-ietf-ipngwg-2292bis-01) 17062587Sitojun */ 17162587Sitojunstruct mrt6msg { 17262587Sitojun#define MRT6MSG_NOCACHE 1 17362587Sitojun#define MRT6MSG_WRONGMIF 2 17462587Sitojun#define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/ 17562587Sitojun u_char im6_mbz; /* must be zero */ 17662587Sitojun u_char im6_msgtype; /* what type of message */ 17762587Sitojun u_int16_t im6_mif; /* mif rec'd on */ 17862587Sitojun u_int32_t im6_pad; /* padding for 64bit arch */ 17962587Sitojun struct in6_addr im6_src, im6_dst; 18062587Sitojun}; 18162587Sitojun 18262587Sitojun/* 18356723Sshin * Argument structure used by multicast routing daemon to get src-grp 18456723Sshin * packet counts 18556723Sshin */ 18656723Sshinstruct sioc_sg_req6 { 18756723Sshin struct sockaddr_in6 src; 18856723Sshin struct sockaddr_in6 grp; 18956723Sshin u_quad_t pktcnt; 19056723Sshin u_quad_t bytecnt; 19156723Sshin u_quad_t wrong_if; 19256723Sshin}; 19356723Sshin 19456723Sshin/* 19556723Sshin * Argument structure used by mrouted to get mif pkt counts 19656723Sshin */ 19756723Sshinstruct sioc_mif_req6 { 19856723Sshin mifi_t mifi; /* mif number */ 19956723Sshin u_quad_t icount; /* Input packet count on mif */ 20056723Sshin u_quad_t ocount; /* Output packet count on mif */ 20156723Sshin u_quad_t ibytes; /* Input byte count on mif */ 20256723Sshin u_quad_t obytes; /* Output byte count on mif */ 20356723Sshin}; 20456723Sshin 20556723Sshin#if defined(_KERNEL) || defined(KERNEL) 20656723Sshin/* 20756723Sshin * The kernel's multicast-interface structure. 20856723Sshin */ 20956723Sshinstruct mif6 { 21056723Sshin u_char m6_flags; /* MIFF_ flags defined above */ 21156723Sshin u_int m6_rate_limit; /* max rate */ 21256723Sshin#ifdef notyet 21356723Sshin struct tbf *m6_tbf; /* token bucket structure at intf. */ 21462587Sitojun#endif 21556723Sshin struct in6_addr m6_lcl_addr; /* local interface address */ 21656723Sshin struct ifnet *m6_ifp; /* pointer to interface */ 21756723Sshin u_quad_t m6_pkt_in; /* # pkts in on interface */ 21856723Sshin u_quad_t m6_pkt_out; /* # pkts out on interface */ 21956723Sshin u_quad_t m6_bytes_in; /* # bytes in on interface */ 22056723Sshin u_quad_t m6_bytes_out; /* # bytes out on interface */ 22156723Sshin struct route_in6 m6_route;/* cached route if this is a tunnel */ 22256723Sshin#ifdef notyet 22356723Sshin u_int m6_rsvp_on; /* RSVP listening on this vif */ 22456723Sshin struct socket *m6_rsvpd; /* RSVP daemon socket */ 22562587Sitojun#endif 22656723Sshin}; 22756723Sshin 22856723Sshin/* 22962587Sitojun * The kernel's multicast forwarding cache entry structure 23056723Sshin */ 23156723Sshinstruct mf6c { 23256723Sshin struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */ 23356723Sshin struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/ 23456723Sshin mifi_t mf6c_parent; /* incoming IF */ 23556723Sshin struct if_set mf6c_ifset; /* set of outgoing IFs */ 23656723Sshin 23756723Sshin u_quad_t mf6c_pkt_cnt; /* pkt count for src-grp */ 23856723Sshin u_quad_t mf6c_byte_cnt; /* byte count for src-grp */ 23956723Sshin u_quad_t mf6c_wrong_if; /* wrong if for src-grp */ 24056723Sshin int mf6c_expire; /* time to clean entry up */ 24156723Sshin struct timeval mf6c_last_assert; /* last time I sent an assert*/ 24256723Sshin struct rtdetq *mf6c_stall; /* pkts waiting for route */ 24356723Sshin struct mf6c *mf6c_next; /* hash table linkage */ 24456723Sshin}; 24556723Sshin 24656723Sshin#define MF6C_INCOMPLETE_PARENT ((mifi_t)-1) 24756723Sshin 24856723Sshin/* 24956723Sshin * Argument structure used for pkt info. while upcall is made 25056723Sshin */ 25156723Sshin#ifndef _NETINET_IP_MROUTE_H_ 25256723Sshinstruct rtdetq { /* XXX: rtdetq is also defined in ip_mroute.h */ 25356723Sshin struct mbuf *m; /* A copy of the packet */ 25456723Sshin struct ifnet *ifp; /* Interface pkt came in on */ 25556723Sshin#ifdef UPCALL_TIMING 25656723Sshin struct timeval t; /* Timestamp */ 25756723Sshin#endif /* UPCALL_TIMING */ 25856723Sshin struct rtdetq *next; 25956723Sshin}; 26056723Sshin#endif /* _NETINET_IP_MROUTE_H_ */ 26156723Sshin 26256723Sshin#define MF6CTBLSIZ 256 26356723Sshin#if (MF6CTBLSIZ & (MF6CTBLSIZ - 1)) == 0 /* from sys:route.h */ 26456723Sshin#define MF6CHASHMOD(h) ((h) & (MF6CTBLSIZ - 1)) 26556723Sshin#else 26656723Sshin#define MF6CHASHMOD(h) ((h) % MF6CTBLSIZ) 26756723Sshin#endif 26856723Sshin 26956723Sshin#define MAX_UPQ6 4 /* max. no of pkts in upcall Q */ 27056723Sshin 27156723Sshinint ip6_mrouter_set __P((struct socket *so, struct sockopt *sopt)); 27256723Sshinint ip6_mrouter_get __P((struct socket *so, struct sockopt *sopt)); 27356723Sshinint ip6_mrouter_done __P((void)); 27456723Sshinint mrt6_ioctl __P((int, caddr_t)); 27556723Sshin#endif /* _KERNEL */ 27656723Sshin 27756723Sshin#endif /* !_NETINET6_IP6_MROUTE_H_ */ 278