/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (C) 1998 WIDE Project.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the project nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*30* $KAME: ip6_mroute.h,v 1.19 2001/06/14 06:12:55 suz Exp $31*/3233/* BSDI ip_mroute.h,v 2.5 1996/10/11 16:01:48 pjd Exp */3435/*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.245*/4647#ifndef _NETINET6_IP6_MROUTE_H_48#define _NETINET6_IP6_MROUTE_H_4950/*51* Multicast Routing set/getsockopt commands.52*/53#ifdef _KERNEL54#define MRT6_OINIT 100 /* initialize forwarder (omrt6msg) */55#endif56#define MRT6_DONE 101 /* shut down forwarder */57#define MRT6_ADD_MIF 102 /* add multicast interface */58#define MRT6_DEL_MIF 103 /* delete multicast interface */59#define MRT6_ADD_MFC 104 /* insert forwarding cache entry */60#define MRT6_DEL_MFC 105 /* delete forwarding cache entry */61#define MRT6_PIM 107 /* enable pim code */62#define MRT6_INIT 108 /* initialize forwarder (mrt6msg) */6364#if BSD >= 19910365#define GET_TIME(t) microtime(&t)66#elif defined(sun)67#define GET_TIME(t) uniqtime(&t)68#else69#define GET_TIME(t) ((t) = time)70#endif7172/*73* Types and macros for handling bitmaps with one bit per multicast interface.74*/75typedef u_short mifi_t; /* type of a mif index */76#define MAXMIFS 647778#ifndef IF_SETSIZE79#define IF_SETSIZE 25680#endif8182typedef u_int32_t if_mask;83#define NIFBITS (sizeof(if_mask) * NBBY) /* bits per mask */8485#ifndef howmany86#define howmany(x, y) (((x) + ((y) - 1)) / (y))87#endif8889typedef struct if_set {90if_mask ifs_bits[howmany(IF_SETSIZE, NIFBITS)];91} if_set;9293#define IF_SET(n, p) ((p)->ifs_bits[(n)/NIFBITS] |= (1 << ((n) % NIFBITS)))94#define IF_CLR(n, p) ((p)->ifs_bits[(n)/NIFBITS] &= ~(1 << ((n) % NIFBITS)))95#define IF_ISSET(n, p) ((p)->ifs_bits[(n)/NIFBITS] & (1 << ((n) % NIFBITS)))96#define IF_COPY(f, t) bcopy(f, t, sizeof(*(f)))97#define IF_ZERO(p) bzero(p, sizeof(*(p)))9899/*100* Argument structure for MRT6_ADD_IF.101*/102struct mif6ctl {103mifi_t mif6c_mifi; /* the index of the mif to be added */104u_char mif6c_flags; /* MIFF_ flags defined below */105u_short mif6c_pifi; /* the index of the physical IF */106};107108#define MIFF_REGISTER 0x1 /* mif represents a register end-point */109110/*111* Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC112*/113struct mf6cctl {114struct sockaddr_in6 mf6cc_origin; /* IPv6 origin of mcasts */115struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */116mifi_t mf6cc_parent; /* incoming ifindex */117struct if_set mf6cc_ifset; /* set of forwarding ifs */118};119120/*121* The kernel's multicast routing statistics.122*/123struct mrt6stat {124uint64_t mrt6s_mfc_lookups; /* # forw. cache hash table hits */125uint64_t mrt6s_mfc_misses; /* # forw. cache hash table misses */126uint64_t mrt6s_upcalls; /* # calls to multicast routing daemon */127uint64_t mrt6s_no_route; /* no route for packet's origin */128uint64_t mrt6s_bad_tunnel; /* malformed tunnel options */129uint64_t mrt6s_cant_tunnel; /* no room for tunnel options */130uint64_t mrt6s_wrong_if; /* arrived on wrong interface */131uint64_t mrt6s_upq_ovflw; /* upcall Q overflow */132uint64_t mrt6s_cache_cleanups; /* # entries with no upcalls */133uint64_t mrt6s_drop_sel; /* pkts dropped selectively */134uint64_t mrt6s_q_overflow; /* pkts dropped - Q overflow */135uint64_t mrt6s_pkt2large; /* pkts dropped - size > BKT SIZE */136uint64_t mrt6s_upq_sockfull; /* upcalls dropped - socket full */137};138139#ifdef MRT6_OINIT140/*141* Struct used to communicate from kernel to multicast router142* note the convenient similarity to an IPv6 header.143* XXX old version, superseded by mrt6msg.144*/145struct omrt6msg {146u_long unused1;147u_char im6_msgtype; /* what type of message */148u_char im6_mbz; /* must be zero */149u_char im6_mif; /* mif rec'd on */150u_char unused2;151struct in6_addr im6_src, im6_dst;152};153#endif154155/*156* Structure used to communicate from kernel to multicast router.157* We'll overlay the structure onto an MLD header (not an IPv6 header158* like igmpmsg{} used for IPv4 implementation). This is because this159* structure will be passed via an IPv6 raw socket, on which an application160* will only receive the payload i.e. the data after the IPv6 header and all161* the extension headers. (see Section 3 of RFC3542)162*/163struct mrt6msg {164#define MRT6MSG_NOCACHE 1165#define MRT6MSG_WRONGMIF 2166#define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/167u_char im6_mbz; /* must be zero */168u_char im6_msgtype; /* what type of message */169u_int16_t im6_mif; /* mif rec'd on */170u_int32_t im6_pad; /* padding for 64bit arch */171struct in6_addr im6_src, im6_dst;172};173174/*175* Argument structure used by multicast routing daemon to get src-grp176* packet counts177*/178struct sioc_sg_req6 {179struct sockaddr_in6 src;180struct sockaddr_in6 grp;181u_quad_t pktcnt;182u_quad_t bytecnt;183u_quad_t wrong_if;184};185186/*187* Argument structure used by mrouted to get mif pkt counts188*/189struct sioc_mif_req6 {190mifi_t mifi; /* mif number */191u_quad_t icount; /* Input packet count on mif */192u_quad_t ocount; /* Output packet count on mif */193u_quad_t ibytes; /* Input byte count on mif */194u_quad_t obytes; /* Output byte count on mif */195};196197/*198* Structure to export 'struct mif6' to userland via sysctl.199*/200struct mif6_sctl {201u_char m6_flags; /* MIFF_ flags defined above */202u_int m6_rate_limit; /* max rate */203struct in6_addr m6_lcl_addr; /* local interface address */204uint32_t m6_ifp; /* interface index */205u_quad_t m6_pkt_in; /* # pkts in on interface */206u_quad_t m6_pkt_out; /* # pkts out on interface */207u_quad_t m6_bytes_in; /* # bytes in on interface */208u_quad_t m6_bytes_out; /* # bytes out on interface */209};210211#if defined(_KERNEL) || defined(KERNEL)212/*213* The kernel's multicast-interface structure.214*/215struct mif6 {216u_char m6_flags; /* MIFF_ flags defined above */217u_int m6_rate_limit; /* max rate */218struct in6_addr m6_lcl_addr; /* local interface address */219struct ifnet *m6_ifp; /* pointer to interface */220u_quad_t m6_pkt_in; /* # pkts in on interface */221u_quad_t m6_pkt_out; /* # pkts out on interface */222u_quad_t m6_bytes_in; /* # bytes in on interface */223u_quad_t m6_bytes_out; /* # bytes out on interface */224#ifdef notyet225u_int m6_rsvp_on; /* RSVP listening on this vif */226struct socket *m6_rsvpd; /* RSVP daemon socket */227#endif228};229230/*231* The kernel's multicast forwarding cache entry structure232*/233struct mf6c {234struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */235struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/236mifi_t mf6c_parent; /* incoming IF */237struct if_set mf6c_ifset; /* set of outgoing IFs */238239u_quad_t mf6c_pkt_cnt; /* pkt count for src-grp */240u_quad_t mf6c_byte_cnt; /* byte count for src-grp */241u_quad_t mf6c_wrong_if; /* wrong if for src-grp */242int mf6c_expire; /* time to clean entry up */243struct timeval mf6c_last_assert; /* last time I sent an assert*/244struct rtdetq *mf6c_stall; /* pkts waiting for route */245struct mf6c *mf6c_next; /* hash table linkage */246};247248#define MF6C_INCOMPLETE_PARENT ((mifi_t)-1)249250/*251* Argument structure used for pkt info. while upcall is made252*/253#ifndef _NETINET_IP_MROUTE_H_254struct rtdetq { /* XXX: rtdetq is also defined in ip_mroute.h */255struct mbuf *m; /* A copy of the packet */256struct ifnet *ifp; /* Interface pkt came in on */257#ifdef UPCALL_TIMING258struct timeval t; /* Timestamp */259#endif /* UPCALL_TIMING */260struct rtdetq *next;261};262#endif /* _NETINET_IP_MROUTE_H_ */263264#define MF6CTBLSIZ 256265#if (MF6CTBLSIZ & (MF6CTBLSIZ - 1)) == 0 /* from sys:route.h */266#define MF6CHASHMOD(h) ((h) & (MF6CTBLSIZ - 1))267#else268#define MF6CHASHMOD(h) ((h) % MF6CTBLSIZ)269#endif270271#define MAX_UPQ6 4 /* max. no of pkts in upcall Q */272273extern int (*ip6_mrouter_set)(struct socket *so, struct sockopt *sopt);274extern int (*ip6_mrouter_get)(struct socket *so, struct sockopt *sopt);275extern int (*ip6_mrouter_done)(void);276extern int (*mrt6_ioctl)(u_long, caddr_t);277#endif /* _KERNEL */278279#endif /* !_NETINET6_IP6_MROUTE_H_ */280281282