1 /* $OpenBSD: ip_mroute.h,v 1.19 2015/02/09 12:18:19 claudio 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 * and PIM-SMv2 and PIM-DM support, advanced API support, 19 * bandwidth metering and signaling. 20 */ 21 22 #include <sys/queue.h> 23 #include <sys/timeout.h> 24 25 /* 26 * Multicast Routing set/getsockopt commands. 27 */ 28 #define MRT_INIT 100 /* initialize forwarder */ 29 #define MRT_DONE 101 /* shut down forwarder */ 30 #define MRT_ADD_VIF 102 /* create virtual interface */ 31 #define MRT_DEL_VIF 103 /* delete virtual interface */ 32 #define MRT_ADD_MFC 104 /* insert forwarding cache entry */ 33 #define MRT_DEL_MFC 105 /* delete forwarding cache entry */ 34 #define MRT_VERSION 106 /* get kernel version number */ 35 #define MRT_ASSERT 107 /* enable assert processing */ 36 #define MRT_PIM MRT_ASSERT /* enable PIM processing */ 37 #define MRT_API_SUPPORT 109 /* supported MRT API */ 38 #define MRT_API_CONFIG 110 /* config MRT API */ 39 40 41 /* 42 * Types and macros for handling bitmaps with one bit per virtual interface. 43 */ 44 #define MAXVIFS 32 45 typedef u_int32_t vifbitmap_t; 46 typedef u_int16_t vifi_t; /* type of a vif index */ 47 48 #define VIFM_SET(n, m) ((m) |= (1 << (n))) 49 #define VIFM_CLR(n, m) ((m) &= ~(1 << (n))) 50 #define VIFM_ISSET(n, m) ((m) & (1 << (n))) 51 #define VIFM_SETALL(m) ((m) = 0xffffffff) 52 #define VIFM_CLRALL(m) ((m) = 0x00000000) 53 #define VIFM_COPY(mfrom, mto) ((mto) = (mfrom)) 54 #define VIFM_SAME(m1, m2) ((m1) == (m2)) 55 56 #define VIFF_TUNNEL 0x1 /* vif represents a tunnel end-point */ 57 #define VIFF_SRCRT 0x2 /* tunnel uses IP src routing */ 58 #define VIFF_REGISTER 0x4 /* used for PIM Register encap/decap */ 59 60 /* 61 * Argument structure for MRT_ADD_VIF. 62 * (MRT_DEL_VIF takes a single vifi_t argument.) 63 */ 64 struct vifctl { 65 vifi_t vifc_vifi; /* the index of the vif to be added */ 66 u_int8_t vifc_flags; /* VIFF_ flags defined above */ 67 u_int8_t vifc_threshold; /* min ttl required to forward on vif */ 68 u_int32_t vifc_rate_limit; /* ignored */ 69 struct in_addr vifc_lcl_addr;/* local interface address */ 70 struct in_addr vifc_rmt_addr;/* remote address (tunnels only) */ 71 }; 72 73 /* 74 * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC. 75 * XXX if you change this, make sure to change struct mfcctl2 as well. 76 */ 77 struct mfcctl { 78 struct in_addr mfcc_origin; /* ip origin of mcasts */ 79 struct in_addr mfcc_mcastgrp; /* multicast group associated */ 80 vifi_t mfcc_parent; /* incoming vif */ 81 u_int8_t mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */ 82 }; 83 84 /* 85 * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays 86 * and extends the old struct mfcctl. 87 */ 88 struct mfcctl2 { 89 /* the mfcctl fields */ 90 struct in_addr mfcc_origin; /* ip origin of mcasts */ 91 struct in_addr mfcc_mcastgrp; /* multicast group associated*/ 92 vifi_t mfcc_parent; /* incoming vif */ 93 u_int8_t mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */ 94 95 /* extension fields */ 96 u_int8_t mfcc_flags[MAXVIFS]; /* the MRT_MFC_FLAGS_* flags */ 97 struct in_addr mfcc_rp; /* the RP address */ 98 }; 99 /* 100 * The advanced-API flags. 101 * 102 * The MRT_MFC_FLAGS_XXX API flags are also used as flags 103 * for the mfcc_flags field. 104 */ 105 #define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */ 106 #define MRT_MFC_FLAGS_BORDER_VIF (1 << 1) /* border vif */ 107 #define MRT_MFC_RP (1 << 8) /* enable RP address */ 108 #define MRT_MFC_BW_UPCALL (1 << 9) /* enable bw upcalls */ 109 #define MRT_MFC_FLAGS_ALL (MRT_MFC_FLAGS_DISABLE_WRONGVIF | \ 110 MRT_MFC_FLAGS_BORDER_VIF) 111 #define MRT_API_FLAGS_ALL (MRT_MFC_FLAGS_ALL | \ 112 MRT_MFC_RP | \ 113 MRT_MFC_BW_UPCALL) 114 115 /* structure used to get all the mfc entries */ 116 struct mfcinfo { 117 struct in_addr mfc_origin; /* ip origin of mcasts */ 118 struct in_addr mfc_mcastgrp; /* multicast group associated */ 119 vifi_t mfc_parent; /* incoming vif */ 120 u_long mfc_pkt_cnt; /* pkt count for src-grp */ 121 u_long mfc_byte_cnt; /* byte count for src-grp */ 122 u_int8_t mfc_ttls[MAXVIFS]; /* forwarding ttls on vifs */ 123 }; 124 125 /* structure used to get all the vif entries */ 126 struct vifinfo { 127 vifi_t v_vifi; /* the index of the vif to be added */ 128 u_int8_t v_flags; /* VIFF_ flags defined above */ 129 u_int8_t v_threshold; /* min ttl required to forward on vif */ 130 struct in_addr v_lcl_addr; /* local interface address */ 131 struct in_addr v_rmt_addr; /* remote address (tunnels only) */ 132 u_long v_pkt_in; /* # pkts in on interface */ 133 u_long v_pkt_out; /* # pkts out on interface */ 134 u_long v_bytes_in; /* # bytes in on interface */ 135 u_long v_bytes_out; /* # bytes out on interface */ 136 }; 137 138 /* 139 * Structure for installing or delivering an upcall if the 140 * measured bandwidth is above or below a threshold. 141 * 142 * User programs (e.g. daemons) may have a need to know when the 143 * bandwidth used by some data flow is above or below some threshold. 144 * This interface allows the userland to specify the threshold (in 145 * bytes and/or packets) and the measurement interval. Flows are 146 * all packet with the same source and destination IP address. 147 * At the moment the code is only used for multicast destinations 148 * but there is nothing that prevents its use for unicast. 149 * 150 * The measurement interval cannot be shorter than some Tmin (currently, 3s). 151 * The threshold is set in packets and/or bytes per_interval. 152 * 153 * Measurement works as follows: 154 * 155 * For >= measurements: 156 * The first packet marks the start of a measurement interval. 157 * During an interval we count packets and bytes, and when we 158 * pass the threshold we deliver an upcall and we are done. 159 * The first packet after the end of the interval resets the 160 * count and restarts the measurement. 161 * 162 * For <= measurement: 163 * We start a timer to fire at the end of the interval, and 164 * then for each incoming packet we count packets and bytes. 165 * When the timer fires, we compare the value with the threshold, 166 * schedule an upcall if we are below, and restart the measurement 167 * (reschedule timer and zero counters). 168 */ 169 170 struct bw_data { 171 struct timeval b_time; 172 u_int64_t b_packets; 173 u_int64_t b_bytes; 174 }; 175 176 struct bw_upcall { 177 struct in_addr bu_src; /* source address */ 178 struct in_addr bu_dst; /* destination address */ 179 u_int32_t bu_flags; /* misc flags (see below) */ 180 #define BW_UPCALL_UNIT_PACKETS (1 << 0) /* threshold (in packets) */ 181 #define BW_UPCALL_UNIT_BYTES (1 << 1) /* threshold (in bytes) */ 182 #define BW_UPCALL_GEQ (1 << 2) /* upcall if bw >= threshold */ 183 #define BW_UPCALL_LEQ (1 << 3) /* upcall if bw <= threshold */ 184 #define BW_UPCALL_DELETE_ALL (1 << 4) /* delete all upcalls for s,d*/ 185 struct bw_data bu_threshold; /* the bw threshold */ 186 struct bw_data bu_measured; /* the measured bw */ 187 }; 188 189 /* max. number of upcalls to deliver together */ 190 #define BW_UPCALLS_MAX 128 191 /* min. threshold time interval for bandwidth measurement */ 192 #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC 3 193 #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC 0 194 195 /* 196 * Argument structure used by mrouted to get src-grp pkt counts. 197 */ 198 struct sioc_sg_req { 199 struct in_addr src; 200 struct in_addr grp; 201 u_long pktcnt; 202 u_long bytecnt; 203 u_long wrong_if; 204 }; 205 206 /* 207 * Argument structure used by mrouted to get vif pkt counts. 208 */ 209 struct sioc_vif_req { 210 vifi_t vifi; /* vif number */ 211 u_long icount; /* input packet count on vif */ 212 u_long ocount; /* output packet count on vif */ 213 u_long ibytes; /* input byte count on vif */ 214 u_long obytes; /* output byte count on vif */ 215 }; 216 217 218 /* 219 * The kernel's multicast routing statistics. 220 */ 221 struct mrtstat { 222 u_long mrts_mfc_lookups; /* # forw. cache hash table hits */ 223 u_long mrts_mfc_misses; /* # forw. cache hash table misses */ 224 u_long mrts_upcalls; /* # calls to mrouted */ 225 u_long mrts_no_route; /* no route for packet's origin */ 226 u_long mrts_bad_tunnel; /* malformed tunnel options */ 227 u_long mrts_cant_tunnel; /* no room for tunnel options */ 228 u_long mrts_wrong_if; /* arrived on wrong interface */ 229 u_long mrts_upq_ovflw; /* upcall Q overflow */ 230 u_long mrts_cache_cleanups; /* # entries with no upcalls */ 231 u_long mrts_drop_sel; /* pkts dropped selectively */ 232 u_long mrts_q_overflow; /* pkts dropped - Q overflow */ 233 u_long mrts_pkt2large; /* pkts dropped - size > BKT SIZE */ 234 u_long mrts_upq_sockfull; /* upcalls dropped - socket full */ 235 }; 236 237 238 #ifdef _KERNEL 239 240 /* 241 * The kernel's virtual-interface structure. 242 */ 243 struct vif { 244 u_int8_t v_flags; /* VIFF_ flags defined above */ 245 u_int8_t v_threshold; /* min ttl required to forward on vif */ 246 struct in_addr v_lcl_addr; /* local interface address */ 247 struct in_addr v_rmt_addr; /* remote address (tunnels only) */ 248 struct ifnet *v_ifp; /* pointer to interface */ 249 u_long v_pkt_in; /* # pkts in on interface */ 250 u_long v_pkt_out; /* # pkts out on interface */ 251 u_long v_bytes_in; /* # bytes in on interface */ 252 u_long v_bytes_out; /* # bytes out on interface */ 253 struct route v_route; /* cached route if this is a tunnel */ 254 struct timeout v_repq_ch; /* for tbf_reprocess_q() */ 255 }; 256 257 /* 258 * The kernel's multicast forwarding cache entry structure. 259 * (A field for the type of service (mfc_tos) is to be added 260 * at a future point.) 261 */ 262 struct mfc { 263 LIST_ENTRY(mfc) mfc_hash; 264 struct in_addr mfc_origin; /* ip origin of mcasts */ 265 struct in_addr mfc_mcastgrp; /* multicast group associated */ 266 vifi_t mfc_parent; /* incoming vif */ 267 u_int8_t mfc_ttls[MAXVIFS]; /* forwarding ttls on vifs */ 268 u_long mfc_pkt_cnt; /* pkt count for src-grp */ 269 u_long mfc_byte_cnt; /* byte count for src-grp */ 270 u_long mfc_wrong_if; /* wrong if for src-grp */ 271 int mfc_expire; /* time to clean entry up */ 272 struct timeval mfc_last_assert; /* last time I sent an assert */ 273 struct rtdetq *mfc_stall; /* pkts waiting for route */ 274 u_int8_t mfc_flags[MAXVIFS]; /* the MRT_MFC_FLAGS_* flags */ 275 struct in_addr mfc_rp; /* the RP address */ 276 }; 277 278 /* 279 * Structure used to communicate from kernel to multicast router. 280 * (Note the convenient similarity to an IP packet.) 281 */ 282 struct igmpmsg { 283 u_int32_t unused1; 284 u_int32_t unused2; 285 u_int8_t im_msgtype; /* what type of message */ 286 #define IGMPMSG_NOCACHE 1 /* no MFC in the kernel */ 287 #define IGMPMSG_WRONGVIF 2 /* packet came from wrong interface */ 288 #define IGMPMSG_WHOLEPKT 3 /* PIM pkt for user level encap. */ 289 #define IGMPMSG_BW_UPCALL 4 /* BW monitoring upcall */ 290 u_int8_t im_mbz; /* must be zero */ 291 u_int8_t im_vif; /* vif rec'd on */ 292 u_int8_t unused3; 293 struct in_addr im_src, im_dst; 294 }; 295 296 /* 297 * Argument structure used for pkt info. while upcall is made. 298 */ 299 struct rtdetq { 300 struct mbuf *m; /* a copy of the packet */ 301 struct ifnet *ifp; /* interface pkt came in on */ 302 struct rtdetq *next; 303 }; 304 305 #define MFCTBLSIZ 256 306 #define MAX_UPQ 4 /* max. no of pkts in upcall Q */ 307 308 int ip_mrouter_set(struct socket *, int, struct mbuf **); 309 int ip_mrouter_get(struct socket *, int, struct mbuf **); 310 int mrt_ioctl(struct socket *, u_long, caddr_t); 311 int mrt_sysctl_vif(void *, size_t *); 312 int mrt_sysctl_mfc(void *, size_t *); 313 int ip_mrouter_done(void); 314 void ip_mrouter_detach(struct ifnet *); 315 void reset_vif(struct vif *); 316 void vif_delete(struct ifnet *); 317 318 #endif /* _KERNEL */ 319 #endif /* _NETINET_IP_MROUTE_H_ */ 320