1addeef82SBruce A. Mah.\" Copyright (c) 2001-2003 International Computer Science Institute 2addeef82SBruce A. Mah.\" 3addeef82SBruce A. Mah.\" Permission is hereby granted, free of charge, to any person obtaining a 4addeef82SBruce A. Mah.\" copy of this software and associated documentation files (the "Software"), 5addeef82SBruce A. Mah.\" to deal in the Software without restriction, including without limitation 6addeef82SBruce A. Mah.\" the rights to use, copy, modify, merge, publish, distribute, sublicense, 7addeef82SBruce A. Mah.\" and/or sell copies of the Software, and to permit persons to whom the 8addeef82SBruce A. Mah.\" Software is furnished to do so, subject to the following conditions: 9addeef82SBruce A. Mah.\" 10addeef82SBruce A. Mah.\" The above copyright notice and this permission notice shall be included in 11addeef82SBruce A. Mah.\" all copies or substantial portions of the Software. 12addeef82SBruce A. Mah.\" 13addeef82SBruce A. Mah.\" The names and trademarks of copyright holders may not be used in 14addeef82SBruce A. Mah.\" advertising or publicity pertaining to the software without specific 15addeef82SBruce A. Mah.\" prior permission. Title to copyright in this software and any associated 16addeef82SBruce A. Mah.\" documentation will at all times remain with the copyright holders. 17addeef82SBruce A. Mah.\" 18addeef82SBruce A. Mah.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19addeef82SBruce A. Mah.\" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20addeef82SBruce A. Mah.\" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21addeef82SBruce A. Mah.\" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22addeef82SBruce A. Mah.\" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23addeef82SBruce A. Mah.\" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24addeef82SBruce A. Mah.\" DEALINGS IN THE SOFTWARE. 25addeef82SBruce A. Mah.\" 26addeef82SBruce A. Mah.\" $FreeBSD$ 27addeef82SBruce A. Mah.\" 28addeef82SBruce A. Mah.Dd September 4, 2003 29addeef82SBruce A. Mah.Dt MULTICAST 4 30addeef82SBruce A. Mah.Os 31addeef82SBruce A. Mah.\" 32addeef82SBruce A. Mah.Sh NAME 33addeef82SBruce A. Mah.Nm multicast 34addeef82SBruce A. Mah.Nd Multicast Routing 35addeef82SBruce A. Mah.\" 36addeef82SBruce A. Mah.Sh SYNOPSIS 37addeef82SBruce A. Mah.Cd "options MROUTING" 38addeef82SBruce A. Mah.Pp 39addeef82SBruce A. Mah.In sys/types.h 40addeef82SBruce A. Mah.In sys/socket.h 41addeef82SBruce A. Mah.In netinet/in.h 42addeef82SBruce A. Mah.In netinet/ip_mroute.h 43addeef82SBruce A. Mah.In netinet6/ip6_mroute.h 44addeef82SBruce A. Mah.Ft int 45addeef82SBruce A. Mah.Fn getsockopt "int s" IPPROTO_IP MRT_INIT "void *optval" "socklen_t *optlen" 46addeef82SBruce A. Mah.Ft int 47addeef82SBruce A. Mah.Fn setsockopt "int s" IPPROTO_IP MRT_INIT "const void *optval" "socklen_t optlen" 48addeef82SBruce A. Mah.Ft int 49addeef82SBruce A. Mah.Fn getsockopt "int s" IPPROTO_IPV6 MRT6_INIT "void *optval" "socklen_t *optlen" 50addeef82SBruce A. Mah.Ft int 51addeef82SBruce A. Mah.Fn setsockopt "int s" IPPROTO_IPV6 MRT6_INIT "const void *optval" "socklen_t optlen" 52addeef82SBruce A. Mah.Sh DESCRIPTION 53addeef82SBruce A. Mah.Tn "Multicast routing" 54addeef82SBruce A. Mahis used to efficiently propagate data 55addeef82SBruce A. Mahpackets to a set of multicast listeners in multipoint networks. 56addeef82SBruce A. MahIf unicast is used to replicate the data to all listeners, 57addeef82SBruce A. Mahthen some of the network links may carry multiple copies of the same 58addeef82SBruce A. Mahdata packets. 59addeef82SBruce A. MahWith multicast routing, the overhead is reduced to one copy 60addeef82SBruce A. Mah(at most) per network link. 61addeef82SBruce A. Mah.Pp 62addeef82SBruce A. MahAll multicast-capable routers must run a common multicast routing 63addeef82SBruce A. Mahprotocol. 64addeef82SBruce A. MahThe Distance Vector Multicast Routing Protocol (DVMRP) 65addeef82SBruce A. Mahwas the first developed multicast routing protocol. 66addeef82SBruce A. MahLater, other protocols such as Multicast Extensions to OSPF (MOSPF), 67addeef82SBruce A. MahCore Based Trees (CBT), 68addeef82SBruce A. MahProtocol Independent Multicast - Sparse Mode (PIM-SM), 69addeef82SBruce A. Mahand Protocol Independent Multicast - Dense Mode (PIM-DM) 70addeef82SBruce A. Mahwere developed as well. 71addeef82SBruce A. Mah.Pp 72addeef82SBruce A. MahTo start multicast routing, 73addeef82SBruce A. Mahthe user must enable multicast forwarding in the kernel 74addeef82SBruce A. Mah(see 75addeef82SBruce A. Mah.Sx SYNOPSIS 76addeef82SBruce A. Mahabout the kernel configuration options), 77addeef82SBruce A. Mahand must run a multicast routing capable user-level process. 78addeef82SBruce A. MahFrom developer's point of view, 79addeef82SBruce A. Mahthe programming guide described in the 80addeef82SBruce A. Mah.Sx "Programming Guide" 81addeef82SBruce A. Mahsection should be used to control the multicast forwarding in the kernel. 82addeef82SBruce A. Mah.\" 83addeef82SBruce A. Mah.Ss Programming Guide 84addeef82SBruce A. MahThis section provides information about the basic multicast routing API. 85addeef82SBruce A. MahThe so-called 86addeef82SBruce A. Mah.Dq advanced multicast API 87addeef82SBruce A. Mahis described in the 88addeef82SBruce A. Mah.Sx "Advanced Multicast API Programming Guide" 89addeef82SBruce A. Mahsection. 90addeef82SBruce A. Mah.Pp 91addeef82SBruce A. MahFirst, a multicast routing socket must be open. 92addeef82SBruce A. MahThat socket would be used 93addeef82SBruce A. Mahto control the multicast forwarding in the kernel. 94addeef82SBruce A. MahNote that most operations below require certain privilege 95addeef82SBruce A. Mah(i.e., root privilege): 96addeef82SBruce A. Mah.Bd -literal 97addeef82SBruce A. Mah/* IPv4 */ 98addeef82SBruce A. Mahint mrouter_s4; 99addeef82SBruce A. Mahmrouter_s4 = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP); 100addeef82SBruce A. Mah.Ed 101addeef82SBruce A. Mah.Bd -literal 102addeef82SBruce A. Mahint mrouter_s6; 103addeef82SBruce A. Mahmrouter_s6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); 104addeef82SBruce A. Mah.Ed 105addeef82SBruce A. Mah.Pp 106addeef82SBruce A. MahNote that if the router needs to open an IGMP or ICMPv6 socket 107addeef82SBruce A. Mah(in case of IPv4 and IPv6 respectively) 108addeef82SBruce A. Mahfor sending or receiving of IGMP or MLD multicast group membership messages, 109ef151d78SRuslan Ermilovthen the same 110ef151d78SRuslan Ermilov.Va mrouter_s4 111ef151d78SRuslan Ermilovor 112ef151d78SRuslan Ermilov.Va mrouter_s6 113ef151d78SRuslan Ermilovsockets should be used 114addeef82SBruce A. Mahfor sending and receiving respectively IGMP or MLD messages. 115ef151d78SRuslan ErmilovIn case of 116ef151d78SRuslan Ermilov.Bx Ns 117ef151d78SRuslan Ermilov-derived kernel, it may be possible to open separate sockets 118addeef82SBruce A. Mahfor IGMP or MLD messages only. 119ef151d78SRuslan ErmilovHowever, some other kernels (e.g., 120ef151d78SRuslan Ermilov.Tn Linux ) 121ef151d78SRuslan Ermilovrequire that the multicast 122addeef82SBruce A. Mahrouting socket must be used for sending and receiving of IGMP or MLD 123addeef82SBruce A. Mahmessages. 124addeef82SBruce A. MahTherefore, for portability reason the multicast 125addeef82SBruce A. Mahrouting socket should be reused for IGMP and MLD messages as well. 126addeef82SBruce A. Mah.Pp 127addeef82SBruce A. MahAfter the multicast routing socket is open, it can be used to enable 128addeef82SBruce A. Mahor disable multicast forwarding in the kernel: 129addeef82SBruce A. Mah.Bd -literal 130addeef82SBruce A. Mah/* IPv4 */ 131addeef82SBruce A. Mahint v = 1; /* 1 to enable, or 0 to disable */ 132addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_INIT, (void *)&v, sizeof(v)); 133addeef82SBruce A. Mah.Ed 134addeef82SBruce A. Mah.Bd -literal 135addeef82SBruce A. Mah/* IPv6 */ 136addeef82SBruce A. Mahint v = 1; /* 1 to enable, or 0 to disable */ 137addeef82SBruce A. Mahsetsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_INIT, (void *)&v, sizeof(v)); 138addeef82SBruce A. Mah\&... 139addeef82SBruce A. Mah/* If necessary, filter all ICMPv6 messages */ 140addeef82SBruce A. Mahstruct icmp6_filter filter; 141addeef82SBruce A. MahICMP6_FILTER_SETBLOCKALL(&filter); 142addeef82SBruce A. Mahsetsockopt(mrouter_s6, IPPROTO_ICMPV6, ICMP6_FILTER, (void *)&filter, 143addeef82SBruce A. Mah sizeof(filter)); 144addeef82SBruce A. Mah.Ed 145addeef82SBruce A. Mah.Pp 146addeef82SBruce A. MahAfter multicast forwarding is enabled, the multicast routing socket 147addeef82SBruce A. Mahcan be used to enable PIM processing in the kernel if we are running PIM-SM or 148addeef82SBruce A. MahPIM-DM 149addeef82SBruce A. Mah(see 150addeef82SBruce A. Mah.Xr pim 4 ) . 151addeef82SBruce A. Mah.Pp 152addeef82SBruce A. MahFor each network interface (e.g., physical or a virtual tunnel) 153addeef82SBruce A. Mahthat would be used for multicast forwarding, a corresponding 154addeef82SBruce A. Mahmulticast interface must be added to the kernel: 155addeef82SBruce A. Mah.Bd -literal 156addeef82SBruce A. Mah/* IPv4 */ 157addeef82SBruce A. Mahstruct vifctl vc; 158addeef82SBruce A. Mahmemset(&vc, 0, sizeof(vc)); 159addeef82SBruce A. Mah/* Assign all vifctl fields as appropriate */ 160addeef82SBruce A. Mahvc.vifc_vifi = vif_index; 161addeef82SBruce A. Mahvc.vifc_flags = vif_flags; 162addeef82SBruce A. Mahvc.vifc_threshold = min_ttl_threshold; 163addeef82SBruce A. Mahvc.vifc_rate_limit = max_rate_limit; 164addeef82SBruce A. Mahmemcpy(&vc.vifc_lcl_addr, &vif_local_address, sizeof(vc.vifc_lcl_addr)); 165addeef82SBruce A. Mahif (vc.vifc_flags & VIFF_TUNNEL) 166addeef82SBruce A. Mah memcpy(&vc.vifc_rmt_addr, &vif_remote_address, 167addeef82SBruce A. Mah sizeof(vc.vifc_rmt_addr)); 168addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_VIF, (void *)&vc, 169addeef82SBruce A. Mah sizeof(vc)); 170addeef82SBruce A. Mah.Ed 171addeef82SBruce A. Mah.Pp 172addeef82SBruce A. MahThe 173ef151d78SRuslan Ermilov.Va vif_index 174addeef82SBruce A. Mahmust be unique per vif. 175addeef82SBruce A. MahThe 176ef151d78SRuslan Ermilov.Va vif_flags 177addeef82SBruce A. Mahcontains the 178ef151d78SRuslan Ermilov.Dv VIFF_* 179ef151d78SRuslan Ermilovflags as defined in 180ef151d78SRuslan Ermilov.In netinet/ip_mroute.h . 181addeef82SBruce A. MahThe 182ef151d78SRuslan Ermilov.Va min_ttl_threshold 183addeef82SBruce A. Mahcontains the minimum TTL a multicast data packet must have to be 184addeef82SBruce A. Mahforwarded on that vif. 185addeef82SBruce A. MahTypically, it would have value of 1. 186addeef82SBruce A. MahThe 187ef151d78SRuslan Ermilov.Va max_rate_limit 188addeef82SBruce A. Mahcontains the maximum rate (in bits/s) of the multicast data packets forwarded 189addeef82SBruce A. Mahon that vif. 190addeef82SBruce A. MahValue of 0 means no limit. 191addeef82SBruce A. MahThe 192ef151d78SRuslan Ermilov.Va vif_local_address 193addeef82SBruce A. Mahcontains the local IP address of the corresponding local interface. 194addeef82SBruce A. MahThe 195ef151d78SRuslan Ermilov.Va vif_remote_address 196addeef82SBruce A. Mahcontains the remote IP address in case of DVMRP multicast tunnels. 197addeef82SBruce A. Mah.Bd -literal 198addeef82SBruce A. Mah/* IPv6 */ 199addeef82SBruce A. Mahstruct mif6ctl mc; 200addeef82SBruce A. Mahmemset(&mc, 0, sizeof(mc)); 201addeef82SBruce A. Mah/* Assign all mif6ctl fields as appropriate */ 202addeef82SBruce A. Mahmc.mif6c_mifi = mif_index; 203addeef82SBruce A. Mahmc.mif6c_flags = mif_flags; 204addeef82SBruce A. Mahmc.mif6c_pifi = pif_index; 205addeef82SBruce A. Mahsetsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_ADD_MIF, (void *)&mc, 206addeef82SBruce A. Mah sizeof(mc)); 207addeef82SBruce A. Mah.Ed 208addeef82SBruce A. Mah.Pp 209addeef82SBruce A. MahThe 210ef151d78SRuslan Ermilov.Va mif_index 211addeef82SBruce A. Mahmust be unique per vif. 212addeef82SBruce A. MahThe 213ef151d78SRuslan Ermilov.Va mif_flags 214addeef82SBruce A. Mahcontains the 215ef151d78SRuslan Ermilov.Dv MIFF_* 216ef151d78SRuslan Ermilovflags as defined in 217ef151d78SRuslan Ermilov.In netinet6/ip6_mroute.h . 218addeef82SBruce A. MahThe 219ef151d78SRuslan Ermilov.Va pif_index 220addeef82SBruce A. Mahis the physical interface index of the corresponding local interface. 221addeef82SBruce A. Mah.Pp 222addeef82SBruce A. MahA multicast interface is deleted by: 223addeef82SBruce A. Mah.Bd -literal 224addeef82SBruce A. Mah/* IPv4 */ 225addeef82SBruce A. Mahvifi_t vifi = vif_index; 226addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_DEL_VIF, (void *)&vifi, 227addeef82SBruce A. Mah sizeof(vifi)); 228addeef82SBruce A. Mah.Ed 229addeef82SBruce A. Mah.Bd -literal 230addeef82SBruce A. Mah/* IPv6 */ 231addeef82SBruce A. Mahmifi_t mifi = mif_index; 232addeef82SBruce A. Mahsetsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_DEL_MIF, (void *)&mifi, 233addeef82SBruce A. Mah sizeof(mifi)); 234addeef82SBruce A. Mah.Ed 235addeef82SBruce A. Mah.Pp 236addeef82SBruce A. MahAfter the multicast forwarding is enabled, and the multicast virtual 237addeef82SBruce A. Mahinterfaces are 238addeef82SBruce A. Mahadded, the kernel may deliver upcall messages (also called signals 239addeef82SBruce A. Mahlater in this text) on the multicast routing socket that was open 240addeef82SBruce A. Mahearlier with 241ef151d78SRuslan Ermilov.Dv MRT_INIT 242addeef82SBruce A. Mahor 243ef151d78SRuslan Ermilov.Dv MRT6_INIT . 244addeef82SBruce A. MahThe IPv4 upcalls have 245ef151d78SRuslan Ermilov.Vt "struct igmpmsg" 246ef151d78SRuslan Ermilovheader (see 247ef151d78SRuslan Ermilov.In netinet/ip_mroute.h ) 248ef151d78SRuslan Ermilovwith field 249ef151d78SRuslan Ermilov.Va im_mbz 250addeef82SBruce A. Mahset to zero. 251addeef82SBruce A. MahNote that this header follows the structure of 252ef151d78SRuslan Ermilov.Vt "struct ip" 253addeef82SBruce A. Mahwith the protocol field 254ef151d78SRuslan Ermilov.Va ip_p 255addeef82SBruce A. Mahset to zero. 256addeef82SBruce A. MahThe IPv6 upcalls have 257ef151d78SRuslan Ermilov.Vt "struct mrt6msg" 258ef151d78SRuslan Ermilovheader (see 259ef151d78SRuslan Ermilov.In netinet6/ip6_mroute.h ) 260ef151d78SRuslan Ermilovwith field 261ef151d78SRuslan Ermilov.Va im6_mbz 262addeef82SBruce A. Mahset to zero. 263addeef82SBruce A. MahNote that this header follows the structure of 264ef151d78SRuslan Ermilov.Vt "struct ip6_hdr" 265addeef82SBruce A. Mahwith the next header field 266ef151d78SRuslan Ermilov.Va ip6_nxt 267addeef82SBruce A. Mahset to zero. 268addeef82SBruce A. Mah.Pp 269addeef82SBruce A. MahThe upcall header contains field 270ef151d78SRuslan Ermilov.Va im_msgtype 271addeef82SBruce A. Mahand 272ef151d78SRuslan Ermilov.Va im6_msgtype 273addeef82SBruce A. Mahwith the type of the upcall 274ef151d78SRuslan Ermilov.Dv IGMPMSG_* 275addeef82SBruce A. Mahand 276ef151d78SRuslan Ermilov.Dv MRT6MSG_* 277addeef82SBruce A. Mahfor IPv4 and IPv6 respectively. 278addeef82SBruce A. MahThe values of the rest of the upcall header fields 279addeef82SBruce A. Mahand the body of the upcall message depend on the particular upcall type. 280addeef82SBruce A. Mah.Pp 281addeef82SBruce A. MahIf the upcall message type is 282ef151d78SRuslan Ermilov.Dv IGMPMSG_NOCACHE 283addeef82SBruce A. Mahor 284ef151d78SRuslan Ermilov.Dv MRT6MSG_NOCACHE , 285addeef82SBruce A. Mahthis is an indication that a multicast packet has reached the multicast 286addeef82SBruce A. Mahrouter, but the router has no forwarding state for that packet. 287addeef82SBruce A. MahTypically, the upcall would be a signal for the multicast routing 288addeef82SBruce A. Mahuser-level process to install the appropriate Multicast Forwarding 289addeef82SBruce A. MahCache (MFC) entry in the kernel. 290addeef82SBruce A. Mah.Pp 291ef151d78SRuslan ErmilovAn MFC entry is added by: 292addeef82SBruce A. Mah.Bd -literal 293addeef82SBruce A. Mah/* IPv4 */ 294addeef82SBruce A. Mahstruct mfcctl mc; 295addeef82SBruce A. Mahmemset(&mc, 0, sizeof(mc)); 296addeef82SBruce A. Mahmemcpy(&mc.mfcc_origin, &source_addr, sizeof(mc.mfcc_origin)); 297addeef82SBruce A. Mahmemcpy(&mc.mfcc_mcastgrp, &group_addr, sizeof(mc.mfcc_mcastgrp)); 298addeef82SBruce A. Mahmc.mfcc_parent = iif_index; 299addeef82SBruce A. Mahfor (i = 0; i < maxvifs; i++) 300addeef82SBruce A. Mah mc.mfcc_ttls[i] = oifs_ttl[i]; 301addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_MFC, 302addeef82SBruce A. Mah (void *)&mc, sizeof(mc)); 303addeef82SBruce A. Mah.Ed 304addeef82SBruce A. Mah.Bd -literal 305addeef82SBruce A. Mah/* IPv6 */ 306addeef82SBruce A. Mahstruct mf6cctl mc; 307addeef82SBruce A. Mahmemset(&mc, 0, sizeof(mc)); 308addeef82SBruce A. Mahmemcpy(&mc.mf6cc_origin, &source_addr, sizeof(mc.mf6cc_origin)); 309addeef82SBruce A. Mahmemcpy(&mc.mf6cc_mcastgrp, &group_addr, sizeof(mf6cc_mcastgrp)); 310addeef82SBruce A. Mahmc.mf6cc_parent = iif_index; 311addeef82SBruce A. Mahfor (i = 0; i < maxvifs; i++) 312addeef82SBruce A. Mah if (oifs_ttl[i] > 0) 313addeef82SBruce A. Mah IF_SET(i, &mc.mf6cc_ifset); 314addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IPV6, MRT6_ADD_MFC, 315addeef82SBruce A. Mah (void *)&mc, sizeof(mc)); 316addeef82SBruce A. Mah.Ed 317addeef82SBruce A. Mah.Pp 318addeef82SBruce A. MahThe 319ef151d78SRuslan Ermilov.Va source_addr 320addeef82SBruce A. Mahand 321ef151d78SRuslan Ermilov.Va group_addr 322addeef82SBruce A. Mahare the source and group address of the multicast packet (as set 323addeef82SBruce A. Mahin the upcall message). 324addeef82SBruce A. MahThe 325ef151d78SRuslan Ermilov.Va iif_index 326addeef82SBruce A. Mahis the virtual interface index of the multicast interface the multicast 327addeef82SBruce A. Mahpackets for this specific source and group address should be received on. 328addeef82SBruce A. MahThe 329ef151d78SRuslan Ermilov.Va oifs_ttl[] 330addeef82SBruce A. Maharray contains the minimum TTL (per interface) a multicast packet 331addeef82SBruce A. Mahshould have to be forwarded on an outgoing interface. 332addeef82SBruce A. MahIf the TTL value is zero, the corresponding interface is not included 333addeef82SBruce A. Mahin the set of outgoing interfaces. 334addeef82SBruce A. MahNote that in case of IPv6 only the set of outgoing interfaces can 335addeef82SBruce A. Mahbe specified. 336addeef82SBruce A. Mah.Pp 337ef151d78SRuslan ErmilovAn MFC entry is deleted by: 338addeef82SBruce A. Mah.Bd -literal 339addeef82SBruce A. Mah/* IPv4 */ 340addeef82SBruce A. Mahstruct mfcctl mc; 341addeef82SBruce A. Mahmemset(&mc, 0, sizeof(mc)); 342addeef82SBruce A. Mahmemcpy(&mc.mfcc_origin, &source_addr, sizeof(mc.mfcc_origin)); 343addeef82SBruce A. Mahmemcpy(&mc.mfcc_mcastgrp, &group_addr, sizeof(mc.mfcc_mcastgrp)); 344addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_DEL_MFC, 345addeef82SBruce A. Mah (void *)&mc, sizeof(mc)); 346addeef82SBruce A. Mah.Ed 347addeef82SBruce A. Mah.Bd -literal 348addeef82SBruce A. Mah/* IPv6 */ 349addeef82SBruce A. Mahstruct mf6cctl mc; 350addeef82SBruce A. Mahmemset(&mc, 0, sizeof(mc)); 351addeef82SBruce A. Mahmemcpy(&mc.mf6cc_origin, &source_addr, sizeof(mc.mf6cc_origin)); 352addeef82SBruce A. Mahmemcpy(&mc.mf6cc_mcastgrp, &group_addr, sizeof(mf6cc_mcastgrp)); 353addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IPV6, MRT6_DEL_MFC, 354addeef82SBruce A. Mah (void *)&mc, sizeof(mc)); 355addeef82SBruce A. Mah.Ed 356addeef82SBruce A. Mah.Pp 357addeef82SBruce A. MahThe following method can be used to get various statistics per 358addeef82SBruce A. Mahinstalled MFC entry in the kernel (e.g., the number of forwarded 359addeef82SBruce A. Mahpackets per source and group address): 360addeef82SBruce A. Mah.Bd -literal 361addeef82SBruce A. Mah/* IPv4 */ 362addeef82SBruce A. Mahstruct sioc_sg_req sgreq; 363addeef82SBruce A. Mahmemset(&sgreq, 0, sizeof(sgreq)); 364addeef82SBruce A. Mahmemcpy(&sgreq.src, &source_addr, sizeof(sgreq.src)); 365addeef82SBruce A. Mahmemcpy(&sgreq.grp, &group_addr, sizeof(sgreq.grp)); 366addeef82SBruce A. Mahioctl(mrouter_s4, SIOCGETSGCNT, &sgreq); 367addeef82SBruce A. Mah.Ed 368addeef82SBruce A. Mah.Bd -literal 369addeef82SBruce A. Mah/* IPv6 */ 370addeef82SBruce A. Mahstruct sioc_sg_req6 sgreq; 371addeef82SBruce A. Mahmemset(&sgreq, 0, sizeof(sgreq)); 372addeef82SBruce A. Mahmemcpy(&sgreq.src, &source_addr, sizeof(sgreq.src)); 373addeef82SBruce A. Mahmemcpy(&sgreq.grp, &group_addr, sizeof(sgreq.grp)); 374addeef82SBruce A. Mahioctl(mrouter_s6, SIOCGETSGCNT_IN6, &sgreq); 375addeef82SBruce A. Mah.Ed 376addeef82SBruce A. Mah.Pp 377addeef82SBruce A. MahThe following method can be used to get various statistics per 378addeef82SBruce A. Mahmulticast virtual interface in the kernel (e.g., the number of forwarded 379addeef82SBruce A. Mahpackets per interface): 380addeef82SBruce A. Mah.Bd -literal 381addeef82SBruce A. Mah/* IPv4 */ 382addeef82SBruce A. Mahstruct sioc_vif_req vreq; 383addeef82SBruce A. Mahmemset(&vreq, 0, sizeof(vreq)); 384addeef82SBruce A. Mahvreq.vifi = vif_index; 385addeef82SBruce A. Mahioctl(mrouter_s4, SIOCGETVIFCNT, &vreq); 386addeef82SBruce A. Mah.Ed 387addeef82SBruce A. Mah.Bd -literal 388addeef82SBruce A. Mah/* IPv6 */ 389addeef82SBruce A. Mahstruct sioc_mif_req6 mreq; 390addeef82SBruce A. Mahmemset(&mreq, 0, sizeof(mreq)); 391addeef82SBruce A. Mahmreq.mifi = vif_index; 392addeef82SBruce A. Mahioctl(mrouter_s6, SIOCGETMIFCNT_IN6, &mreq); 393addeef82SBruce A. Mah.Ed 394addeef82SBruce A. Mah.Ss Advanced Multicast API Programming Guide 395addeef82SBruce A. MahIf we want to add new features in the kernel, it becomes difficult 396addeef82SBruce A. Mahto preserve backward compatibility (binary and API), 397addeef82SBruce A. Mahand at the same time to allow user-level processes to take advantage of 398addeef82SBruce A. Mahthe new features (if the kernel supports them). 399addeef82SBruce A. Mah.Pp 400addeef82SBruce A. MahOne of the mechanisms that allows us to preserve the backward 401addeef82SBruce A. Mahcompatibility is a sort of negotiation 402addeef82SBruce A. Mahbetween the user-level process and the kernel: 403addeef82SBruce A. Mah.Bl -enum 404addeef82SBruce A. Mah.It 405addeef82SBruce A. MahThe user-level process tries to enable in the kernel the set of new 406addeef82SBruce A. Mahfeatures (and the corresponding API) it would like to use. 407addeef82SBruce A. Mah.It 408addeef82SBruce A. MahThe kernel returns the (sub)set of features it knows about 409addeef82SBruce A. Mahand is willing to be enabled. 410addeef82SBruce A. Mah.It 411addeef82SBruce A. MahThe user-level process uses only that set of features 412addeef82SBruce A. Mahthe kernel has agreed on. 413addeef82SBruce A. Mah.El 414addeef82SBruce A. Mah.\" 415addeef82SBruce A. Mah.Pp 416ef151d78SRuslan ErmilovTo support backward compatibility, if the user-level process does not 417addeef82SBruce A. Mahask for any new features, the kernel defaults to the basic 418addeef82SBruce A. Mahmulticast API (see the 419addeef82SBruce A. Mah.Sx "Programming Guide" 420addeef82SBruce A. Mahsection). 421addeef82SBruce A. Mah.\" XXX: edit as appropriate after the advanced multicast API is 422addeef82SBruce A. Mah.\" supported under IPv6 423addeef82SBruce A. MahCurrently, the advanced multicast API exists only for IPv4; 424addeef82SBruce A. Mahin the future there will be IPv6 support as well. 425addeef82SBruce A. Mah.Pp 426addeef82SBruce A. MahBelow is a summary of the expandable API solution. 427addeef82SBruce A. MahNote that all new options and structures are defined 428ef151d78SRuslan Ermilovin 429ef151d78SRuslan Ermilov.In netinet/ip_mroute.h 430ef151d78SRuslan Ermilovand 431ef151d78SRuslan Ermilov.In netinet6/ip6_mroute.h , 432addeef82SBruce A. Mahunless stated otherwise. 433addeef82SBruce A. Mah.Pp 434ef151d78SRuslan ErmilovThe user-level process uses new 435ef151d78SRuslan Ermilov.Fn getsockopt Ns / Ns Fn setsockopt 436ef151d78SRuslan Ermilovoptions to 437addeef82SBruce A. Mahperform the API features negotiation with the kernel. 438addeef82SBruce A. MahThis negotiation must be performed right after the multicast routing 439addeef82SBruce A. Mahsocket is open. 440addeef82SBruce A. MahThe set of desired/allowed features is stored in a bitset 441ef151d78SRuslan Ermilov(currently, in 442ef151d78SRuslan Ermilov.Vt uint32_t ; 443ef151d78SRuslan Ermilovi.e., maximum of 32 new features). 444ef151d78SRuslan ErmilovThe new 445ef151d78SRuslan Ermilov.Fn getsockopt Ns / Ns Fn setsockopt 446ef151d78SRuslan Ermilovoptions are 447ef151d78SRuslan Ermilov.Dv MRT_API_SUPPORT 448addeef82SBruce A. Mahand 449ef151d78SRuslan Ermilov.Dv MRT_API_CONFIG . 450addeef82SBruce A. MahExample: 451addeef82SBruce A. Mah.Bd -literal 452addeef82SBruce A. Mahuint32_t v; 453addeef82SBruce A. Mahgetsockopt(sock, IPPROTO_IP, MRT_API_SUPPORT, (void *)&v, sizeof(v)); 454addeef82SBruce A. Mah.Ed 455addeef82SBruce A. Mah.Pp 456addeef82SBruce A. Mahwould set in 457ef151d78SRuslan Ermilov.Va v 458addeef82SBruce A. Mahthe pre-defined bits that the kernel API supports. 459ef151d78SRuslan ErmilovThe eight least significant bits in 460ef151d78SRuslan Ermilov.Vt uint32_t 461ef151d78SRuslan Ermilovare same as the 462addeef82SBruce A. Maheight possible flags 463ef151d78SRuslan Ermilov.Dv MRT_MFC_FLAGS_* 464addeef82SBruce A. Mahthat can be used in 465ef151d78SRuslan Ermilov.Va mfcc_flags 466addeef82SBruce A. Mahas part of the new definition of 467ef151d78SRuslan Ermilov.Vt "struct mfcctl" 468addeef82SBruce A. Mah(see below about those flags), which leaves 24 flags for other new features. 469ef151d78SRuslan ErmilovThe value returned by 470ef151d78SRuslan Ermilov.Fn getsockopt MRT_API_SUPPORT 471ef151d78SRuslan Ermilovis read-only; in other words, 472ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_SUPPORT 473ef151d78SRuslan Ermilovwould fail. 474addeef82SBruce A. Mah.Pp 475addeef82SBruce A. MahTo modify the API, and to set some specific feature in the kernel, then: 476addeef82SBruce A. Mah.Bd -literal 477addeef82SBruce A. Mahuint32_t v = MRT_MFC_FLAGS_DISABLE_WRONGVIF; 478addeef82SBruce A. Mahif (setsockopt(sock, IPPROTO_IP, MRT_API_CONFIG, (void *)&v, sizeof(v)) 479addeef82SBruce A. Mah != 0) { 480addeef82SBruce A. Mah return (ERROR); 481addeef82SBruce A. Mah} 482addeef82SBruce A. Mahif (v & MRT_MFC_FLAGS_DISABLE_WRONGVIF) 483addeef82SBruce A. Mah return (OK); /* Success */ 484addeef82SBruce A. Mahelse 485addeef82SBruce A. Mah return (ERROR); 486addeef82SBruce A. Mah.Ed 487addeef82SBruce A. Mah.Pp 488ef151d78SRuslan ErmilovIn other words, when 489ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_CONFIG 490ef151d78SRuslan Ermilovis called, the 491addeef82SBruce A. Mahargument to it specifies the desired set of features to 492addeef82SBruce A. Mahbe enabled in the API and the kernel. 493addeef82SBruce A. MahThe return value in 494ef151d78SRuslan Ermilov.Va v 495addeef82SBruce A. Mahis the actual (sub)set of features that were enabled in the kernel. 496addeef82SBruce A. MahTo obtain later the same set of features that were enabled, then: 497addeef82SBruce A. Mah.Bd -literal 498addeef82SBruce A. Mahgetsockopt(sock, IPPROTO_IP, MRT_API_CONFIG, (void *)&v, sizeof(v)); 499addeef82SBruce A. Mah.Ed 500addeef82SBruce A. Mah.Pp 501addeef82SBruce A. MahThe set of enabled features is global. 502ef151d78SRuslan ErmilovIn other words, 503ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_CONFIG 504ef151d78SRuslan Ermilovshould be called right after 505ef151d78SRuslan Ermilov.Fn setsockopt MRT_INIT . 506addeef82SBruce A. Mah.Pp 507addeef82SBruce A. MahCurrently, the following set of new features is defined: 508addeef82SBruce A. Mah.Bd -literal 509addeef82SBruce A. Mah#define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */ 510addeef82SBruce A. Mah#define MRT_MFC_FLAGS_BORDER_VIF (1 << 1) /* border vif */ 511addeef82SBruce A. Mah#define MRT_MFC_RP (1 << 8) /* enable RP address */ 512addeef82SBruce A. Mah#define MRT_MFC_BW_UPCALL (1 << 9) /* enable bw upcalls */ 513addeef82SBruce A. Mah.Ed 514addeef82SBruce A. Mah.\" .Pp 515addeef82SBruce A. Mah.\" In the future there might be: 516addeef82SBruce A. Mah.\" .Bd -literal 517addeef82SBruce A. Mah.\" #define MRT_MFC_GROUP_SPECIFIC (1 << 10) /* allow (*,G) MFC entries */ 518addeef82SBruce A. Mah.\" .Ed 519addeef82SBruce A. Mah.\" .Pp 520addeef82SBruce A. Mah.\" to allow (*,G) MFC entries (i.e., group-specific entries) in the kernel. 521addeef82SBruce A. Mah.\" For now this is left-out until it is clear whether 522addeef82SBruce A. Mah.\" (*,G) MFC support is the preferred solution instead of something more generic 523addeef82SBruce A. Mah.\" solution for example. 524addeef82SBruce A. Mah.\" 525addeef82SBruce A. Mah.\" 2. The newly defined struct mfcctl2. 526addeef82SBruce A. Mah.\" 527addeef82SBruce A. Mah.Pp 528addeef82SBruce A. MahThe advanced multicast API uses a newly defined 529ef151d78SRuslan Ermilov.Vt "struct mfcctl2" 530addeef82SBruce A. Mahinstead of the traditional 531ef151d78SRuslan Ermilov.Vt "struct mfcctl" . 532addeef82SBruce A. MahThe original 533ef151d78SRuslan Ermilov.Vt "struct mfcctl" 534addeef82SBruce A. Mahis kept as is. 535addeef82SBruce A. MahThe new 536ef151d78SRuslan Ermilov.Vt "struct mfcctl2" 537addeef82SBruce A. Mahis: 538addeef82SBruce A. Mah.Bd -literal 539addeef82SBruce A. Mah/* 540addeef82SBruce A. Mah * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays 541addeef82SBruce A. Mah * and extends the old struct mfcctl. 542addeef82SBruce A. Mah */ 543addeef82SBruce A. Mahstruct mfcctl2 { 544addeef82SBruce A. Mah /* the mfcctl fields */ 545addeef82SBruce A. Mah struct in_addr mfcc_origin; /* ip origin of mcasts */ 546addeef82SBruce A. Mah struct in_addr mfcc_mcastgrp; /* multicast group associated*/ 547addeef82SBruce A. Mah vifi_t mfcc_parent; /* incoming vif */ 548addeef82SBruce A. Mah u_char mfcc_ttls[MAXVIFS];/* forwarding ttls on vifs */ 549addeef82SBruce A. Mah 550addeef82SBruce A. Mah /* extension fields */ 551addeef82SBruce A. Mah uint8_t mfcc_flags[MAXVIFS];/* the MRT_MFC_FLAGS_* flags*/ 552addeef82SBruce A. Mah struct in_addr mfcc_rp; /* the RP address */ 553addeef82SBruce A. Mah}; 554addeef82SBruce A. Mah.Ed 555addeef82SBruce A. Mah.Pp 556addeef82SBruce A. MahThe new fields are 557ef151d78SRuslan Ermilov.Va mfcc_flags[MAXVIFS] 558addeef82SBruce A. Mahand 559ef151d78SRuslan Ermilov.Va mfcc_rp . 560addeef82SBruce A. MahNote that for compatibility reasons they are added at the end. 561addeef82SBruce A. Mah.Pp 562addeef82SBruce A. MahThe 563ef151d78SRuslan Ermilov.Va mfcc_flags[MAXVIFS] 564addeef82SBruce A. Mahfield is used to set various flags per 565addeef82SBruce A. Mahinterface per (S,G) entry. 566addeef82SBruce A. MahCurrently, the defined flags are: 567addeef82SBruce A. Mah.Bd -literal 568addeef82SBruce A. Mah#define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */ 569addeef82SBruce A. Mah#define MRT_MFC_FLAGS_BORDER_VIF (1 << 1) /* border vif */ 570addeef82SBruce A. Mah.Ed 571addeef82SBruce A. Mah.Pp 572addeef82SBruce A. MahThe 573ef151d78SRuslan Ermilov.Dv MRT_MFC_FLAGS_DISABLE_WRONGVIF 574addeef82SBruce A. Mahflag is used to explicitly disable the 575ef151d78SRuslan Ermilov.Dv IGMPMSG_WRONGVIF 576addeef82SBruce A. Mahkernel signal at the (S,G) granularity if a multicast data packet 577addeef82SBruce A. Maharrives on the wrong interface. 578addeef82SBruce A. MahUsually, this signal is used to 579addeef82SBruce A. Mahcomplete the shortest-path switch in case of PIM-SM multicast routing, 580addeef82SBruce A. Mahor to trigger a PIM assert message. 581addeef82SBruce A. MahHowever, it should not be delivered for interfaces that are not in 582addeef82SBruce A. Mahthe outgoing interface set, and that are not expecting to 583addeef82SBruce A. Mahbecome an incoming interface. 584addeef82SBruce A. MahHence, if the 585ef151d78SRuslan Ermilov.Dv MRT_MFC_FLAGS_DISABLE_WRONGVIF 586addeef82SBruce A. Mahflag is set for some of the 587addeef82SBruce A. Mahinterfaces, then a data packet that arrives on that interface for 588addeef82SBruce A. Mahthat MFC entry will NOT trigger a WRONGVIF signal. 589addeef82SBruce A. MahIf that flag is not set, then a signal is triggered (the default action). 590addeef82SBruce A. Mah.Pp 591addeef82SBruce A. MahThe 592ef151d78SRuslan Ermilov.Dv MRT_MFC_FLAGS_BORDER_VIF 593addeef82SBruce A. Mahflag is used to specify whether the Border-bit in PIM 594addeef82SBruce A. MahRegister messages should be set (in case when the Register encapsulation 595addeef82SBruce A. Mahis performed inside the kernel). 596addeef82SBruce A. MahIf it is set for the special PIM Register kernel virtual interface 597addeef82SBruce A. Mah(see 598addeef82SBruce A. Mah.Xr pim 4 ) , 599addeef82SBruce A. Mahthe Border-bit in the Register messages sent to the RP will be set. 600addeef82SBruce A. Mah.Pp 601addeef82SBruce A. MahThe remaining six bits are reserved for future usage. 602addeef82SBruce A. Mah.Pp 603addeef82SBruce A. MahThe 604ef151d78SRuslan Ermilov.Va mfcc_rp 605addeef82SBruce A. Mahfield is used to specify the RP address (in case of PIM-SM multicast routing) 606addeef82SBruce A. Mahfor a multicast 607addeef82SBruce A. Mahgroup G if we want to perform kernel-level PIM Register encapsulation. 608addeef82SBruce A. MahThe 609ef151d78SRuslan Ermilov.Va mfcc_rp 610addeef82SBruce A. Mahfield is used only if the 611ef151d78SRuslan Ermilov.Dv MRT_MFC_RP 612addeef82SBruce A. Mahadvanced API flag/capability has been successfully set by 613ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_CONFIG . 614addeef82SBruce A. Mah.Pp 615addeef82SBruce A. Mah.\" 616addeef82SBruce A. Mah.\" 3. Kernel-level PIM Register encapsulation 617addeef82SBruce A. Mah.\" 618addeef82SBruce A. MahIf the 619ef151d78SRuslan Ermilov.Dv MRT_MFC_RP 620addeef82SBruce A. Mahflag was successfully set by 621ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_CONFIG , 622ef151d78SRuslan Ermilovthen the kernel will attempt to perform 623addeef82SBruce A. Mahthe PIM Register encapsulation itself instead of sending the 624ef151d78SRuslan Ermilovmulticast data packets to user level (inside 625ef151d78SRuslan Ermilov.Dv IGMPMSG_WHOLEPKT 626addeef82SBruce A. Mahupcalls) for user-level encapsulation. 627addeef82SBruce A. MahThe RP address would be taken from the 628ef151d78SRuslan Ermilov.Va mfcc_rp 629addeef82SBruce A. Mahfield 630addeef82SBruce A. Mahinside the new 631ef151d78SRuslan Ermilov.Vt "struct mfcctl2" . 632addeef82SBruce A. MahHowever, even if the 633ef151d78SRuslan Ermilov.Dv MRT_MFC_RP 634addeef82SBruce A. Mahflag was successfully set, if the 635ef151d78SRuslan Ermilov.Va mfcc_rp 636addeef82SBruce A. Mahfield was set to 637ef151d78SRuslan Ermilov.Dv INADDR_ANY , 638addeef82SBruce A. Mahthen the 639ef151d78SRuslan Ermilovkernel will still deliver an 640ef151d78SRuslan Ermilov.Dv IGMPMSG_WHOLEPKT 641ef151d78SRuslan Ermilovupcall with the 642addeef82SBruce A. Mahmulticast data packet to the user-level process. 643addeef82SBruce A. Mah.Pp 644addeef82SBruce A. MahIn addition, if the multicast data packet is too large to fit within 645addeef82SBruce A. Maha single IP packet after the PIM Register encapsulation (e.g., if 646addeef82SBruce A. Mahits size was on the order of 65500 bytes), the data packet will be 647addeef82SBruce A. Mahfragmented, and then each of the fragments will be encapsulated 648addeef82SBruce A. Mahseparately. 649addeef82SBruce A. MahNote that typically a multicast data packet can be that 650addeef82SBruce A. Mahlarge only if it was originated locally from the same hosts that 651addeef82SBruce A. Mahperforms the encapsulation; otherwise the transmission of the 652addeef82SBruce A. Mahmulticast data packet over Ethernet for example would have 653addeef82SBruce A. Mahfragmented it into much smaller pieces. 654addeef82SBruce A. Mah.\" 655addeef82SBruce A. Mah.\" Note that if this code is ported to IPv6, we may need the kernel to 656addeef82SBruce A. Mah.\" perform MTU discovery to the RP, and keep those discoveries inside 657addeef82SBruce A. Mah.\" the kernel so the encapsulating router may send back ICMP 658addeef82SBruce A. Mah.\" Fragmentation Required if the size of the multicast data packet is 659addeef82SBruce A. Mah.\" too large (see "Encapsulating data packets in the Register Tunnel" 660addeef82SBruce A. Mah.\" in Section 4.4.1 in the PIM-SM spec 661addeef82SBruce A. Mah.\" draft-ietf-pim-sm-v2-new-05.{txt,ps}). 662addeef82SBruce A. Mah.\" For IPv4 we may be able to get away without it, but for IPv6 we need 663addeef82SBruce A. Mah.\" that. 664addeef82SBruce A. Mah.\" 665addeef82SBruce A. Mah.\" 4. Mechanism for "multicast bandwidth monitoring and upcalls". 666addeef82SBruce A. Mah.\" 667addeef82SBruce A. Mah.Pp 668addeef82SBruce A. MahTypically, a multicast routing user-level process would need to know the 669addeef82SBruce A. Mahforwarding bandwidth for some data flow. 670addeef82SBruce A. MahFor example, the multicast routing process may want to timeout idle MFC 671addeef82SBruce A. Mahentries, or in case of PIM-SM it can initiate (S,G) shortest-path switch if 672addeef82SBruce A. Mahthe bandwidth rate is above a threshold for example. 673addeef82SBruce A. Mah.Pp 674addeef82SBruce A. MahThe original solution for measuring the bandwidth of a dataflow was 675addeef82SBruce A. Mahthat a user-level process would periodically 676addeef82SBruce A. Mahquery the kernel about the number of forwarded packets/bytes per 677addeef82SBruce A. Mah(S,G), and then based on those numbers it would estimate whether a source 678addeef82SBruce A. Mahhas been idle, or whether the source's transmission bandwidth is above a 679addeef82SBruce A. Mahthreshold. 680addeef82SBruce A. MahThat solution is far from being scalable, hence the need for a new 681addeef82SBruce A. Mahmechanism for bandwidth monitoring. 682addeef82SBruce A. Mah.Pp 683addeef82SBruce A. MahBelow is a description of the bandwidth monitoring mechanism. 684addeef82SBruce A. Mah.Bl -bullet 685addeef82SBruce A. Mah.It 686addeef82SBruce A. MahIf the bandwidth of a data flow satisfies some pre-defined filter, 687addeef82SBruce A. Mahthe kernel delivers an upcall on the multicast routing socket 688addeef82SBruce A. Mahto the multicast routing process that has installed that filter. 689addeef82SBruce A. Mah.It 6905203edcdSRuslan ErmilovThe bandwidth-upcall filters are installed per (S,G). 6915203edcdSRuslan ErmilovThere can be 692addeef82SBruce A. Mahmore than one filter per (S,G). 693addeef82SBruce A. Mah.It 694addeef82SBruce A. MahInstead of supporting all possible comparison operations 695addeef82SBruce A. Mah(i.e., < <= == != > >= ), there is support only for the 696addeef82SBruce A. Mah<= and >= operations, 697addeef82SBruce A. Mahbecause this makes the kernel-level implementation simpler, 698addeef82SBruce A. Mahand because practically we need only those two. 699addeef82SBruce A. MahFurther, the missing operations can be simulated by secondary 700addeef82SBruce A. Mahuser-level filtering of those <= and >= filters. 701addeef82SBruce A. MahFor example, to simulate !=, then we need to install filter 702addeef82SBruce A. Mah.Dq bw <= 0xffffffff , 703addeef82SBruce A. Mahand after an 704addeef82SBruce A. Mahupcall is received, we need to check whether 705addeef82SBruce A. Mah.Dq measured_bw != expected_bw . 706addeef82SBruce A. Mah.It 707addeef82SBruce A. MahThe bandwidth-upcall mechanism is enabled by 708ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_CONFIG 709ef151d78SRuslan Ermilovfor the 710ef151d78SRuslan Ermilov.Dv MRT_MFC_BW_UPCALL 711ef151d78SRuslan Ermilovflag. 712addeef82SBruce A. Mah.It 713addeef82SBruce A. MahThe bandwidth-upcall filters are added/deleted by the new 714ef151d78SRuslan Ermilov.Fn setsockopt MRT_ADD_BW_UPCALL 715ef151d78SRuslan Ermilovand 716ef151d78SRuslan Ermilov.Fn setsockopt MRT_DEL_BW_UPCALL 717addeef82SBruce A. Mahrespectively (with the appropriate 718ef151d78SRuslan Ermilov.Vt "struct bw_upcall" 719addeef82SBruce A. Mahargument of course). 720addeef82SBruce A. Mah.El 721addeef82SBruce A. Mah.Pp 722addeef82SBruce A. MahFrom application point of view, a developer needs to know about 723addeef82SBruce A. Mahthe following: 724addeef82SBruce A. Mah.Bd -literal 725addeef82SBruce A. Mah/* 726addeef82SBruce A. Mah * Structure for installing or delivering an upcall if the 727addeef82SBruce A. Mah * measured bandwidth is above or below a threshold. 728addeef82SBruce A. Mah * 729addeef82SBruce A. Mah * User programs (e.g. daemons) may have a need to know when the 730addeef82SBruce A. Mah * bandwidth used by some data flow is above or below some threshold. 731addeef82SBruce A. Mah * This interface allows the userland to specify the threshold (in 732addeef82SBruce A. Mah * bytes and/or packets) and the measurement interval. Flows are 733addeef82SBruce A. Mah * all packet with the same source and destination IP address. 734addeef82SBruce A. Mah * At the moment the code is only used for multicast destinations 735addeef82SBruce A. Mah * but there is nothing that prevents its use for unicast. 736addeef82SBruce A. Mah * 737addeef82SBruce A. Mah * The measurement interval cannot be shorter than some Tmin (currently, 3s). 738addeef82SBruce A. Mah * The threshold is set in packets and/or bytes per_interval. 739addeef82SBruce A. Mah * 740addeef82SBruce A. Mah * Measurement works as follows: 741addeef82SBruce A. Mah * 742addeef82SBruce A. Mah * For >= measurements: 743addeef82SBruce A. Mah * The first packet marks the start of a measurement interval. 744addeef82SBruce A. Mah * During an interval we count packets and bytes, and when we 745addeef82SBruce A. Mah * pass the threshold we deliver an upcall and we are done. 746addeef82SBruce A. Mah * The first packet after the end of the interval resets the 747addeef82SBruce A. Mah * count and restarts the measurement. 748addeef82SBruce A. Mah * 749addeef82SBruce A. Mah * For <= measurement: 750addeef82SBruce A. Mah * We start a timer to fire at the end of the interval, and 751addeef82SBruce A. Mah * then for each incoming packet we count packets and bytes. 752addeef82SBruce A. Mah * When the timer fires, we compare the value with the threshold, 753addeef82SBruce A. Mah * schedule an upcall if we are below, and restart the measurement 754addeef82SBruce A. Mah * (reschedule timer and zero counters). 755addeef82SBruce A. Mah */ 756addeef82SBruce A. Mah 757addeef82SBruce A. Mahstruct bw_data { 758addeef82SBruce A. Mah struct timeval b_time; 759addeef82SBruce A. Mah uint64_t b_packets; 760addeef82SBruce A. Mah uint64_t b_bytes; 761addeef82SBruce A. Mah}; 762addeef82SBruce A. Mah 763addeef82SBruce A. Mahstruct bw_upcall { 764addeef82SBruce A. Mah struct in_addr bu_src; /* source address */ 765addeef82SBruce A. Mah struct in_addr bu_dst; /* destination address */ 766addeef82SBruce A. Mah uint32_t bu_flags; /* misc flags (see below) */ 767addeef82SBruce A. Mah#define BW_UPCALL_UNIT_PACKETS (1 << 0) /* threshold (in packets) */ 768addeef82SBruce A. Mah#define BW_UPCALL_UNIT_BYTES (1 << 1) /* threshold (in bytes) */ 769addeef82SBruce A. Mah#define BW_UPCALL_GEQ (1 << 2) /* upcall if bw >= threshold */ 770addeef82SBruce A. Mah#define BW_UPCALL_LEQ (1 << 3) /* upcall if bw <= threshold */ 771addeef82SBruce A. Mah#define BW_UPCALL_DELETE_ALL (1 << 4) /* delete all upcalls for s,d*/ 772addeef82SBruce A. Mah struct bw_data bu_threshold; /* the bw threshold */ 773addeef82SBruce A. Mah struct bw_data bu_measured; /* the measured bw */ 774addeef82SBruce A. Mah}; 775addeef82SBruce A. Mah 776addeef82SBruce A. Mah/* max. number of upcalls to deliver together */ 777addeef82SBruce A. Mah#define BW_UPCALLS_MAX 128 778addeef82SBruce A. Mah/* min. threshold time interval for bandwidth measurement */ 779addeef82SBruce A. Mah#define BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC 3 780addeef82SBruce A. Mah#define BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC 0 781addeef82SBruce A. Mah.Ed 782addeef82SBruce A. Mah.Pp 783addeef82SBruce A. MahThe 784ef151d78SRuslan Ermilov.Vt bw_upcall 785addeef82SBruce A. Mahstructure is used as an argument to 786ef151d78SRuslan Ermilov.Fn setsockopt MRT_ADD_BW_UPCALL 787ef151d78SRuslan Ermilovand 788ef151d78SRuslan Ermilov.Fn setsockopt MRT_DEL_BW_UPCALL . 789ef151d78SRuslan ErmilovEach 790ef151d78SRuslan Ermilov.Fn setsockopt MRT_ADD_BW_UPCALL 791ef151d78SRuslan Ermilovinstalls a filter in the kernel 792addeef82SBruce A. Mahfor the source and destination address in the 793ef151d78SRuslan Ermilov.Vt bw_upcall 794addeef82SBruce A. Mahargument, 795addeef82SBruce A. Mahand that filter will trigger an upcall according to the following 796addeef82SBruce A. Mahpseudo-algorithm: 797addeef82SBruce A. Mah.Bd -literal 798addeef82SBruce A. Mah if (bw_upcall_oper IS ">=") { 799addeef82SBruce A. Mah if (((bw_upcall_unit & PACKETS == PACKETS) && 800addeef82SBruce A. Mah (measured_packets >= threshold_packets)) || 801addeef82SBruce A. Mah ((bw_upcall_unit & BYTES == BYTES) && 802addeef82SBruce A. Mah (measured_bytes >= threshold_bytes))) 803addeef82SBruce A. Mah SEND_UPCALL("measured bandwidth is >= threshold"); 804addeef82SBruce A. Mah } 805addeef82SBruce A. Mah if (bw_upcall_oper IS "<=" && measured_interval >= threshold_interval) { 806addeef82SBruce A. Mah if (((bw_upcall_unit & PACKETS == PACKETS) && 807addeef82SBruce A. Mah (measured_packets <= threshold_packets)) || 808addeef82SBruce A. Mah ((bw_upcall_unit & BYTES == BYTES) && 809addeef82SBruce A. Mah (measured_bytes <= threshold_bytes))) 810addeef82SBruce A. Mah SEND_UPCALL("measured bandwidth is <= threshold"); 811addeef82SBruce A. Mah } 812addeef82SBruce A. Mah.Ed 813addeef82SBruce A. Mah.Pp 814addeef82SBruce A. MahIn the same 815ef151d78SRuslan Ermilov.Vt bw_upcall 816addeef82SBruce A. Mahthe unit can be specified in both BYTES and PACKETS. 817addeef82SBruce A. MahHowever, the GEQ and LEQ flags are mutually exclusive. 818addeef82SBruce A. Mah.Pp 819addeef82SBruce A. MahBasically, an upcall is delivered if the measured bandwidth is >= or 820addeef82SBruce A. Mah<= the threshold bandwidth (within the specified measurement 821addeef82SBruce A. Mahinterval). 822addeef82SBruce A. MahFor practical reasons, the smallest value for the measurement 823addeef82SBruce A. Mahinterval is 3 seconds. 824addeef82SBruce A. MahIf smaller values are allowed, then the bandwidth 825addeef82SBruce A. Mahestimation may be less accurate, or the potentially very high frequency 826addeef82SBruce A. Mahof the generated upcalls may introduce too much overhead. 827addeef82SBruce A. MahFor the >= operation, the answer may be known before the end of 828ef151d78SRuslan Ermilov.Va threshold_interval , 829addeef82SBruce A. Mahtherefore the upcall may be delivered earlier. 830addeef82SBruce A. MahFor the <= operation however, we must wait 831addeef82SBruce A. Mahuntil the threshold interval has expired to know the answer. 832addeef82SBruce A. Mah.Pp 833addeef82SBruce A. MahExample of usage: 834addeef82SBruce A. Mah.Bd -literal 835addeef82SBruce A. Mahstruct bw_upcall bw_upcall; 836addeef82SBruce A. Mah/* Assign all bw_upcall fields as appropriate */ 837addeef82SBruce A. Mahmemset(&bw_upcall, 0, sizeof(bw_upcall)); 838addeef82SBruce A. Mahmemcpy(&bw_upcall.bu_src, &source, sizeof(bw_upcall.bu_src)); 839addeef82SBruce A. Mahmemcpy(&bw_upcall.bu_dst, &group, sizeof(bw_upcall.bu_dst)); 840addeef82SBruce A. Mahbw_upcall.bu_threshold.b_data = threshold_interval; 841addeef82SBruce A. Mahbw_upcall.bu_threshold.b_packets = threshold_packets; 842addeef82SBruce A. Mahbw_upcall.bu_threshold.b_bytes = threshold_bytes; 843addeef82SBruce A. Mahif (is_threshold_in_packets) 844addeef82SBruce A. Mah bw_upcall.bu_flags |= BW_UPCALL_UNIT_PACKETS; 845addeef82SBruce A. Mahif (is_threshold_in_bytes) 846addeef82SBruce A. Mah bw_upcall.bu_flags |= BW_UPCALL_UNIT_BYTES; 847addeef82SBruce A. Mahdo { 848addeef82SBruce A. Mah if (is_geq_upcall) { 849addeef82SBruce A. Mah bw_upcall.bu_flags |= BW_UPCALL_GEQ; 850addeef82SBruce A. Mah break; 851addeef82SBruce A. Mah } 852addeef82SBruce A. Mah if (is_leq_upcall) { 853addeef82SBruce A. Mah bw_upcall.bu_flags |= BW_UPCALL_LEQ; 854addeef82SBruce A. Mah break; 855addeef82SBruce A. Mah } 856addeef82SBruce A. Mah return (ERROR); 857addeef82SBruce A. Mah} while (0); 858addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_BW_UPCALL, 859addeef82SBruce A. Mah (void *)&bw_upcall, sizeof(bw_upcall)); 860addeef82SBruce A. Mah.Ed 861addeef82SBruce A. Mah.Pp 862ef151d78SRuslan ErmilovTo delete a single filter, then use 863ef151d78SRuslan Ermilov.Dv MRT_DEL_BW_UPCALL , 864addeef82SBruce A. Mahand the fields of bw_upcall must be set 865ef151d78SRuslan Ermilovexactly same as when 866ef151d78SRuslan Ermilov.Dv MRT_ADD_BW_UPCALL 867ef151d78SRuslan Ermilovwas called. 868addeef82SBruce A. Mah.Pp 869addeef82SBruce A. MahTo delete all bandwidth filters for a given (S,G), then 870addeef82SBruce A. Mahonly the 871ef151d78SRuslan Ermilov.Va bu_src 872addeef82SBruce A. Mahand 873ef151d78SRuslan Ermilov.Va bu_dst 874addeef82SBruce A. Mahfields in 875ef151d78SRuslan Ermilov.Vt "struct bw_upcall" 876addeef82SBruce A. Mahneed to be set, and then just set only the 877ef151d78SRuslan Ermilov.Dv BW_UPCALL_DELETE_ALL 878addeef82SBruce A. Mahflag inside field 879ef151d78SRuslan Ermilov.Va bw_upcall.bu_flags . 880addeef82SBruce A. Mah.Pp 881addeef82SBruce A. MahThe bandwidth upcalls are received by aggregating them in the new upcall 882addeef82SBruce A. Mahmessage: 883addeef82SBruce A. Mah.Bd -literal 884addeef82SBruce A. Mah#define IGMPMSG_BW_UPCALL 4 /* BW monitoring upcall */ 885addeef82SBruce A. Mah.Ed 886addeef82SBruce A. Mah.Pp 887addeef82SBruce A. MahThis message is an array of 888ef151d78SRuslan Ermilov.Vt "struct bw_upcall" 889ef151d78SRuslan Ermilovelements (up to 890ef151d78SRuslan Ermilov.Dv BW_UPCALLS_MAX 891ef151d78SRuslan Ermilov= 128). 892addeef82SBruce A. MahThe upcalls are 893addeef82SBruce A. Mahdelivered when there are 128 pending upcalls, or when 1 second has 894addeef82SBruce A. Mahexpired since the previous upcall (whichever comes first). 895addeef82SBruce A. MahIn an 896ef151d78SRuslan Ermilov.Vt "struct upcall" 897addeef82SBruce A. Mahelement, the 898ef151d78SRuslan Ermilov.Va bu_measured 899addeef82SBruce A. Mahfield is filled-in to 900addeef82SBruce A. Mahindicate the particular measured values. 901addeef82SBruce A. MahHowever, because of the way 902addeef82SBruce A. Mahthe particular intervals are measured, the user should be careful how 903ef151d78SRuslan Ermilov.Va bu_measured.b_time 904ef151d78SRuslan Ermilovis used. 905addeef82SBruce A. MahFor example, if the 906addeef82SBruce A. Mahfilter is installed to trigger an upcall if the number of packets 907addeef82SBruce A. Mahis >= 1, then 908ef151d78SRuslan Ermilov.Va bu_measured 909addeef82SBruce A. Mahmay have a value of zero in the upcalls after the 910addeef82SBruce A. Mahfirst one, because the measured interval for >= filters is 911addeef82SBruce A. Mah.Dq clocked 912addeef82SBruce A. Mahby the forwarded packets. 913addeef82SBruce A. MahHence, this upcall mechanism should not be used for measuring 914addeef82SBruce A. Mahthe exact value of the bandwidth of the forwarded data. 915addeef82SBruce A. MahTo measure the exact bandwidth, the user would need to 916ef151d78SRuslan Ermilovget the forwarded packets statistics with the 917ef151d78SRuslan Ermilov.Fn ioctl SIOCGETSGCNT 918addeef82SBruce A. Mahmechanism 919addeef82SBruce A. Mah(see the 920addeef82SBruce A. Mah.Sx Programming Guide 921addeef82SBruce A. Mahsection) . 922addeef82SBruce A. Mah.Pp 923addeef82SBruce A. MahNote that the upcalls for a filter are delivered until the specific 924addeef82SBruce A. Mahfilter is deleted, but no more frequently than once per 925ef151d78SRuslan Ermilov.Va bu_threshold.b_time . 926addeef82SBruce A. MahFor example, if the filter is specified to 927addeef82SBruce A. Mahdeliver a signal if bw >= 1 packet, the first packet will trigger a 928addeef82SBruce A. Mahsignal, but the next upcall will be triggered no earlier than 929ef151d78SRuslan Ermilov.Va bu_threshold.b_time 930addeef82SBruce A. Mahafter the previous upcall. 931addeef82SBruce A. Mah.\" 932addeef82SBruce A. Mah.Sh SEE ALSO 933addeef82SBruce A. Mah.Xr getsockopt 2 , 934addeef82SBruce A. Mah.Xr recvfrom 2 , 935addeef82SBruce A. Mah.Xr recvmsg 2 , 936addeef82SBruce A. Mah.Xr setsockopt 2 , 937addeef82SBruce A. Mah.Xr socket 2 , 938addeef82SBruce A. Mah.Xr icmp6 4 , 939addeef82SBruce A. Mah.Xr inet 4 , 940addeef82SBruce A. Mah.Xr inet6 4 , 941addeef82SBruce A. Mah.Xr intro 4 , 942addeef82SBruce A. Mah.Xr ip 4 , 943addeef82SBruce A. Mah.Xr ip6 4 , 944addeef82SBruce A. Mah.Xr pim 4 945addeef82SBruce A. Mah.\" 946addeef82SBruce A. Mah.Sh AUTHORS 9475203edcdSRuslan Ermilov.An -nosplit 9485203edcdSRuslan ErmilovThe original multicast code was written by 9495203edcdSRuslan Ermilov.An David Waitzman 9505203edcdSRuslan Ermilov(BBN Labs), 951addeef82SBruce A. Mahand later modified by the following individuals: 9525203edcdSRuslan Ermilov.An Steve Deering 9535203edcdSRuslan Ermilov(Stanford), 9545203edcdSRuslan Ermilov.An Mark J. Steiglitz 9555203edcdSRuslan Ermilov(Stanford), 9565203edcdSRuslan Ermilov.An Van Jacobson 9575203edcdSRuslan Ermilov(LBL), 9585203edcdSRuslan Ermilov.An Ajit Thyagarajan 9595203edcdSRuslan Ermilov(PARC), 9605203edcdSRuslan Ermilov.An Bill Fenner 9615203edcdSRuslan Ermilov(PARC). 962addeef82SBruce A. MahThe IPv6 multicast support was implemented by the KAME project 963ef151d78SRuslan Ermilov.Pq Pa http://www.kame.net , 964ef151d78SRuslan Ermilovand was based on the IPv4 multicast code. 965addeef82SBruce A. MahThe advanced multicast API and the multicast bandwidth 9665203edcdSRuslan Ermilovmonitoring were implemented by 9675203edcdSRuslan Ermilov.An Pavlin Radoslavov 9685203edcdSRuslan Ermilov(ICSI) 9695203edcdSRuslan Ermilovin collaboration with 9705203edcdSRuslan Ermilov.An Chris Brown 9715203edcdSRuslan Ermilov(NextHop). 972addeef82SBruce A. Mah.Pp 9735203edcdSRuslan ErmilovThis manual page was written by 9745203edcdSRuslan Ermilov.An Pavlin Radoslavov 9755203edcdSRuslan Ermilov(ICSI). 976