1 /* $OpenBSD: ip_mroute.h,v 1.32 2024/10/13 02:27:44 jsg Exp $ */ 2 /* $NetBSD: ip_mroute.h,v 1.23 2004/04/21 17:49:46 itojun Exp $ */ 3 4 #ifndef _NETINET_IP_MROUTE_H_ 5 #define _NETINET_IP_MROUTE_H_ 6 7 /* 8 * Definitions for IP multicast forwarding. 9 * 10 * Written by David Waitzman, BBN Labs, August 1988. 11 * Modified by Steve Deering, Stanford, February 1989. 12 * Modified by Ajit Thyagarajan, PARC, August 1993. 13 * Modified by Ajit Thyagarajan, PARC, August 1994. 14 * Modified by Ahmed Helmy, SGI, June 1996. 15 * Modified by Pavlin Radoslavov, ICSI, October 2002. 16 * 17 * MROUTING Revision: 1.2 18 * advanced API support, bandwidth metering and signaling. 19 */ 20 21 /* 22 * Multicast Routing set/getsockopt commands. 23 */ 24 #define MRT_INIT 100 /* initialize forwarder */ 25 #define MRT_DONE 101 /* shut down forwarder */ 26 #define MRT_ADD_VIF 102 /* create virtual interface */ 27 #define MRT_DEL_VIF 103 /* delete virtual interface */ 28 #define MRT_ADD_MFC 104 /* insert forwarding cache entry */ 29 #define MRT_DEL_MFC 105 /* delete forwarding cache entry */ 30 #define MRT_VERSION 106 /* get kernel version number */ 31 #define MRT_ASSERT 107 /* enable assert processing */ 32 #define MRT_API_SUPPORT 109 /* supported MRT API */ 33 #define MRT_API_CONFIG 110 /* config MRT API */ 34 35 /* 36 * Types and macros for handling bitmaps with one bit per virtual interface. 37 */ 38 #define MAXVIFS 32 39 typedef u_int32_t vifbitmap_t; 40 typedef u_int16_t vifi_t; /* type of a vif index */ 41 42 #define VIFM_SET(n, m) ((m) |= (1 << (n))) 43 #define VIFM_CLR(n, m) ((m) &= ~(1 << (n))) 44 #define VIFM_ISSET(n, m) ((m) & (1 << (n))) 45 #define VIFM_CLRALL(m) ((m) = 0x00000000) 46 #define VIFM_COPY(mfrom, mto) ((mto) = (mfrom)) 47 #define VIFM_SAME(m1, m2) ((m1) == (m2)) 48 49 #define VIFF_TUNNEL 0x1 /* vif represents a tunnel end-point */ 50 #define VIFF_SRCRT 0x2 /* tunnel uses IP src routing */ 51 52 /* 53 * Argument structure for MRT_ADD_VIF. 54 * (MRT_DEL_VIF takes a single vifi_t argument.) 55 */ 56 struct vifctl { 57 vifi_t vifc_vifi; /* the index of the vif to be added */ 58 u_int8_t vifc_flags; /* VIFF_ flags defined above */ 59 u_int8_t vifc_threshold; /* min ttl required to forward on vif */ 60 u_int32_t vifc_rate_limit; /* ignored */ 61 struct in_addr vifc_lcl_addr;/* local interface address */ 62 struct in_addr vifc_rmt_addr;/* remote address (tunnels only) */ 63 }; 64 65 /* 66 * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC. 67 * XXX if you change this, make sure to change struct mfcctl2 as well. 68 */ 69 struct mfcctl { 70 struct in_addr mfcc_origin; /* ip origin of mcasts */ 71 struct in_addr mfcc_mcastgrp; /* multicast group associated */ 72 vifi_t mfcc_parent; /* incoming vif */ 73 u_int8_t mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */ 74 }; 75 76 /* 77 * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays 78 * and extends the old struct mfcctl. 79 */ 80 struct mfcctl2 { 81 /* the mfcctl fields */ 82 struct in_addr mfcc_origin; /* ip origin of mcasts */ 83 struct in_addr mfcc_mcastgrp; /* multicast group associated*/ 84 vifi_t mfcc_parent; /* incoming vif */ 85 u_int8_t mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */ 86 87 /* extension fields */ 88 u_int8_t mfcc_flags[MAXVIFS]; /* the MRT_MFC_FLAGS_* flags */ 89 struct in_addr mfcc_rp; /* the RP address */ 90 }; 91 /* 92 * The advanced-API flags. 93 * 94 * The MRT_MFC_FLAGS_XXX API flags are also used as flags 95 * for the mfcc_flags field. 96 */ 97 #define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */ 98 #define MRT_MFC_RP (1 << 8) /* enable RP address */ 99 #define MRT_MFC_BW_UPCALL (1 << 9) /* enable bw upcalls */ 100 #define MRT_MFC_FLAGS_ALL (MRT_MFC_FLAGS_DISABLE_WRONGVIF) 101 #define MRT_API_FLAGS_ALL (MRT_MFC_FLAGS_ALL | \ 102 MRT_MFC_RP | \ 103 MRT_MFC_BW_UPCALL) 104 105 /* structure used to get all the mfc entries */ 106 struct mfcinfo { 107 struct in_addr mfc_origin; /* ip origin of mcasts */ 108 struct in_addr mfc_mcastgrp; /* multicast group associated */ 109 vifi_t mfc_parent; /* incoming vif */ 110 u_long mfc_pkt_cnt; /* pkt count for src-grp */ 111 u_long mfc_byte_cnt; /* byte count for src-grp */ 112 u_int8_t mfc_ttls[MAXVIFS]; /* forwarding ttls on vifs */ 113 }; 114 115 /* structure used to get all the vif entries */ 116 struct vifinfo { 117 vifi_t v_vifi; /* the index of the vif to be added */ 118 u_int8_t v_flags; /* VIFF_ flags defined above */ 119 u_int8_t v_threshold; /* min ttl required to forward on vif */ 120 struct in_addr v_lcl_addr; /* local interface address */ 121 struct in_addr v_rmt_addr; /* remote address (tunnels only) */ 122 u_long v_pkt_in; /* # pkts in on interface */ 123 u_long v_pkt_out; /* # pkts out on interface */ 124 u_long v_bytes_in; /* # bytes in on interface */ 125 u_long v_bytes_out; /* # bytes out on interface */ 126 }; 127 128 /* 129 * Argument structure used by mrouted to get src-grp pkt counts. 130 */ 131 struct sioc_sg_req { 132 struct in_addr src; 133 struct in_addr grp; 134 u_long pktcnt; 135 u_long bytecnt; 136 u_long wrong_if; 137 }; 138 139 /* 140 * Argument structure used by mrouted to get vif pkt counts. 141 */ 142 struct sioc_vif_req { 143 vifi_t vifi; /* vif number */ 144 u_long icount; /* input packet count on vif */ 145 u_long ocount; /* output packet count on vif */ 146 u_long ibytes; /* input byte count on vif */ 147 u_long obytes; /* output byte count on vif */ 148 }; 149 150 151 /* 152 * The kernel's multicast routing statistics. 153 */ 154 struct mrtstat { 155 u_long mrts_mfc_lookups; /* # forw. cache hash table hits */ 156 u_long mrts_mfc_misses; /* # forw. cache hash table misses */ 157 u_long mrts_upcalls; /* # calls to mrouted */ 158 u_long mrts_no_route; /* no route for packet's origin */ 159 u_long mrts_bad_tunnel; /* malformed tunnel options */ 160 u_long mrts_cant_tunnel; /* no room for tunnel options */ 161 u_long mrts_wrong_if; /* arrived on wrong interface */ 162 u_long mrts_upq_ovflw; /* upcall Q overflow */ 163 u_long mrts_cache_cleanups; /* # entries with no upcalls */ 164 u_long mrts_drop_sel; /* pkts dropped selectively */ 165 u_long mrts_q_overflow; /* pkts dropped - Q overflow */ 166 u_long mrts_pkt2large; /* pkts dropped - size > BKT SIZE */ 167 u_long mrts_upq_sockfull; /* upcalls dropped - socket full */ 168 }; 169 170 171 #ifdef _KERNEL 172 173 /* How frequent should we look for expired entries (in seconds). */ 174 #define MCAST_EXPIRE_FREQUENCY 30 175 176 extern struct rttimer_queue ip_mrouterq; 177 void mfc_expire_route(struct rtentry *, u_int); 178 179 extern int ip_mrtproto; 180 181 /* 182 * The kernel's virtual-interface structure. 183 */ 184 struct vif { 185 vifi_t v_id; /* Virtual interface index */ 186 u_int8_t v_flags; /* VIFF_ flags defined above */ 187 u_int8_t v_threshold; /* min ttl required to forward on vif */ 188 struct in_addr v_lcl_addr; /* local interface address */ 189 struct in_addr v_rmt_addr; /* remote address (tunnels only) */ 190 u_long v_pkt_in; /* # pkts in on interface */ 191 u_long v_pkt_out; /* # pkts out on interface */ 192 u_long v_bytes_in; /* # bytes in on interface */ 193 u_long v_bytes_out; /* # bytes out on interface */ 194 }; 195 196 /* 197 * The kernel's multicast forwarding cache entry structure. 198 * (A field for the type of service (mfc_tos) is to be added 199 * at a future point.) 200 */ 201 struct mfc { 202 vifi_t mfc_parent; /* incoming vif */ 203 u_long mfc_pkt_cnt; /* pkt count for src-grp */ 204 u_long mfc_byte_cnt; /* byte count for src-grp */ 205 u_long mfc_wrong_if; /* wrong if for src-grp */ 206 uint8_t mfc_ttl; /* route interface ttl */ 207 uint8_t mfc_flags; /* MRT_MFC_FLAGS_* flags */ 208 struct in_addr mfc_rp; /* the RP address */ 209 u_long mfc_expire; /* expire timer */ 210 }; 211 212 /* 213 * Structure used to communicate from kernel to multicast router. 214 * (Note the convenient similarity to an IP packet.) 215 */ 216 struct igmpmsg { 217 u_int32_t unused1; 218 u_int32_t unused2; 219 u_int8_t im_msgtype; /* what type of message */ 220 #define IGMPMSG_NOCACHE 1 /* no MFC in the kernel */ 221 #define IGMPMSG_WRONGVIF 2 /* packet came from wrong interface */ 222 #define IGMPMSG_BW_UPCALL 4 /* BW monitoring upcall */ 223 u_int8_t im_mbz; /* must be zero */ 224 u_int8_t im_vif; /* vif rec'd on */ 225 u_int8_t unused3; 226 struct in_addr im_src, im_dst; 227 }; 228 229 int ip_mrouter_set(struct socket *, int, struct mbuf *); 230 int ip_mrouter_get(struct socket *, int, struct mbuf *); 231 int mrt_ioctl(struct socket *, u_long, caddr_t); 232 int mrt_sysctl_vif(void *, size_t *); 233 int mrt_sysctl_mfc(void *, size_t *); 234 int ip_mrouter_done(struct socket *); 235 void vif_delete(struct ifnet *); 236 237 #endif /* _KERNEL */ 238 #endif /* _NETINET_IP_MROUTE_H_ */ 239