xref: /freebsd/share/man/man4/multicast.4 (revision 0770db8953f4c2fda2e9eaa117b627da1b8e141f)
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.\"
280770db89SBruce M Simpson.Dd February 25, 2007
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;
1630770db89SBruce M Simpsonvc.vifc_rate_limit = 0;
164addeef82SBruce A. Mahmemcpy(&vc.vifc_lcl_addr, &vif_local_address, sizeof(vc.vifc_lcl_addr));
165addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_VIF, (void *)&vc,
166addeef82SBruce A. Mah           sizeof(vc));
167addeef82SBruce A. Mah.Ed
168addeef82SBruce A. Mah.Pp
169addeef82SBruce A. MahThe
170ef151d78SRuslan Ermilov.Va vif_index
171addeef82SBruce A. Mahmust be unique per vif.
172addeef82SBruce A. MahThe
173ef151d78SRuslan Ermilov.Va vif_flags
174addeef82SBruce A. Mahcontains the
175ef151d78SRuslan Ermilov.Dv VIFF_*
176ef151d78SRuslan Ermilovflags as defined in
177ef151d78SRuslan Ermilov.In netinet/ip_mroute.h .
178addeef82SBruce A. MahThe
1790770db89SBruce M Simpson.Dv VIFF_TUNNEL
1800770db89SBruce M Simpsonflag is no longer supported by
1810770db89SBruce M Simpson.Fx .
1820770db89SBruce M SimpsonUsers who wish to forward multicast datagrams over a tunnel should consider
1830770db89SBruce M Simpsonconfiguring a
1840770db89SBruce M Simpson.Xr gif 4
1850770db89SBruce M Simpsonor
1860770db89SBruce M Simpson.Xr gre 4
1870770db89SBruce M Simpsontunnel and using it as a physical interface.
1880770db89SBruce M Simpson.Pp
1890770db89SBruce M SimpsonThe
190ef151d78SRuslan Ermilov.Va min_ttl_threshold
191addeef82SBruce A. Mahcontains the minimum TTL a multicast data packet must have to be
192addeef82SBruce A. Mahforwarded on that vif.
193addeef82SBruce A. MahTypically, it would have value of 1.
1940770db89SBruce M Simpson.Pp
195addeef82SBruce A. MahThe
196ef151d78SRuslan Ermilov.Va max_rate_limit
1970770db89SBruce M Simpsonargument is no longer supported in
1980770db89SBruce M Simpson.Fx
1990770db89SBruce M Simpsonand should be set to 0.
2000770db89SBruce M SimpsonUsers who wish to rate-limit multicast datagrams should consider the use of
2010770db89SBruce M Simpson.Xr dummynet 4
2020770db89SBruce M Simpsonor
2030770db89SBruce M Simpson.Xr altq 4 .
2040770db89SBruce M Simpson.Pp
205addeef82SBruce A. MahThe
206ef151d78SRuslan Ermilov.Va vif_local_address
207addeef82SBruce A. Mahcontains the local IP address of the corresponding local interface.
208addeef82SBruce A. MahThe
209ef151d78SRuslan Ermilov.Va vif_remote_address
210addeef82SBruce A. Mahcontains the remote IP address in case of DVMRP multicast tunnels.
211addeef82SBruce A. Mah.Bd -literal
212addeef82SBruce A. Mah/* IPv6 */
213addeef82SBruce A. Mahstruct mif6ctl mc;
214addeef82SBruce A. Mahmemset(&mc, 0, sizeof(mc));
215addeef82SBruce A. Mah/* Assign all mif6ctl fields as appropriate */
216addeef82SBruce A. Mahmc.mif6c_mifi = mif_index;
217addeef82SBruce A. Mahmc.mif6c_flags = mif_flags;
218addeef82SBruce A. Mahmc.mif6c_pifi = pif_index;
219addeef82SBruce A. Mahsetsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_ADD_MIF, (void *)&mc,
220addeef82SBruce A. Mah           sizeof(mc));
221addeef82SBruce A. Mah.Ed
222addeef82SBruce A. Mah.Pp
223addeef82SBruce A. MahThe
224ef151d78SRuslan Ermilov.Va mif_index
225addeef82SBruce A. Mahmust be unique per vif.
226addeef82SBruce A. MahThe
227ef151d78SRuslan Ermilov.Va mif_flags
228addeef82SBruce A. Mahcontains the
229ef151d78SRuslan Ermilov.Dv MIFF_*
230ef151d78SRuslan Ermilovflags as defined in
231ef151d78SRuslan Ermilov.In netinet6/ip6_mroute.h .
232addeef82SBruce A. MahThe
233ef151d78SRuslan Ermilov.Va pif_index
234addeef82SBruce A. Mahis the physical interface index of the corresponding local interface.
235addeef82SBruce A. Mah.Pp
236addeef82SBruce A. MahA multicast interface is deleted by:
237addeef82SBruce A. Mah.Bd -literal
238addeef82SBruce A. Mah/* IPv4 */
239addeef82SBruce A. Mahvifi_t vifi = vif_index;
240addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_DEL_VIF, (void *)&vifi,
241addeef82SBruce A. Mah           sizeof(vifi));
242addeef82SBruce A. Mah.Ed
243addeef82SBruce A. Mah.Bd -literal
244addeef82SBruce A. Mah/* IPv6 */
245addeef82SBruce A. Mahmifi_t mifi = mif_index;
246addeef82SBruce A. Mahsetsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_DEL_MIF, (void *)&mifi,
247addeef82SBruce A. Mah           sizeof(mifi));
248addeef82SBruce A. Mah.Ed
249addeef82SBruce A. Mah.Pp
250addeef82SBruce A. MahAfter the multicast forwarding is enabled, and the multicast virtual
251addeef82SBruce A. Mahinterfaces are
252addeef82SBruce A. Mahadded, the kernel may deliver upcall messages (also called signals
253addeef82SBruce A. Mahlater in this text) on the multicast routing socket that was open
254addeef82SBruce A. Mahearlier with
255ef151d78SRuslan Ermilov.Dv MRT_INIT
256addeef82SBruce A. Mahor
257ef151d78SRuslan Ermilov.Dv MRT6_INIT .
258addeef82SBruce A. MahThe IPv4 upcalls have
259ef151d78SRuslan Ermilov.Vt "struct igmpmsg"
260ef151d78SRuslan Ermilovheader (see
261ef151d78SRuslan Ermilov.In netinet/ip_mroute.h )
262ef151d78SRuslan Ermilovwith field
263ef151d78SRuslan Ermilov.Va im_mbz
264addeef82SBruce A. Mahset to zero.
265addeef82SBruce A. MahNote that this header follows the structure of
266ef151d78SRuslan Ermilov.Vt "struct ip"
267addeef82SBruce A. Mahwith the protocol field
268ef151d78SRuslan Ermilov.Va ip_p
269addeef82SBruce A. Mahset to zero.
270addeef82SBruce A. MahThe IPv6 upcalls have
271ef151d78SRuslan Ermilov.Vt "struct mrt6msg"
272ef151d78SRuslan Ermilovheader (see
273ef151d78SRuslan Ermilov.In netinet6/ip6_mroute.h )
274ef151d78SRuslan Ermilovwith field
275ef151d78SRuslan Ermilov.Va im6_mbz
276addeef82SBruce A. Mahset to zero.
277addeef82SBruce A. MahNote that this header follows the structure of
278ef151d78SRuslan Ermilov.Vt "struct ip6_hdr"
279addeef82SBruce A. Mahwith the next header field
280ef151d78SRuslan Ermilov.Va ip6_nxt
281addeef82SBruce A. Mahset to zero.
282addeef82SBruce A. Mah.Pp
283addeef82SBruce A. MahThe upcall header contains field
284ef151d78SRuslan Ermilov.Va im_msgtype
285addeef82SBruce A. Mahand
286ef151d78SRuslan Ermilov.Va im6_msgtype
287addeef82SBruce A. Mahwith the type of the upcall
288ef151d78SRuslan Ermilov.Dv IGMPMSG_*
289addeef82SBruce A. Mahand
290ef151d78SRuslan Ermilov.Dv MRT6MSG_*
291addeef82SBruce A. Mahfor IPv4 and IPv6 respectively.
292addeef82SBruce A. MahThe values of the rest of the upcall header fields
293addeef82SBruce A. Mahand the body of the upcall message depend on the particular upcall type.
294addeef82SBruce A. Mah.Pp
295addeef82SBruce A. MahIf the upcall message type is
296ef151d78SRuslan Ermilov.Dv IGMPMSG_NOCACHE
297addeef82SBruce A. Mahor
298ef151d78SRuslan Ermilov.Dv MRT6MSG_NOCACHE ,
299addeef82SBruce A. Mahthis is an indication that a multicast packet has reached the multicast
300addeef82SBruce A. Mahrouter, but the router has no forwarding state for that packet.
301addeef82SBruce A. MahTypically, the upcall would be a signal for the multicast routing
302addeef82SBruce A. Mahuser-level process to install the appropriate Multicast Forwarding
303addeef82SBruce A. MahCache (MFC) entry in the kernel.
304addeef82SBruce A. Mah.Pp
305ef151d78SRuslan ErmilovAn MFC entry is added by:
306addeef82SBruce A. Mah.Bd -literal
307addeef82SBruce A. Mah/* IPv4 */
308addeef82SBruce A. Mahstruct mfcctl mc;
309addeef82SBruce A. Mahmemset(&mc, 0, sizeof(mc));
310addeef82SBruce A. Mahmemcpy(&mc.mfcc_origin, &source_addr, sizeof(mc.mfcc_origin));
311addeef82SBruce A. Mahmemcpy(&mc.mfcc_mcastgrp, &group_addr, sizeof(mc.mfcc_mcastgrp));
312addeef82SBruce A. Mahmc.mfcc_parent = iif_index;
313addeef82SBruce A. Mahfor (i = 0; i < maxvifs; i++)
314addeef82SBruce A. Mah    mc.mfcc_ttls[i] = oifs_ttl[i];
315addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_MFC,
316addeef82SBruce A. Mah           (void *)&mc, sizeof(mc));
317addeef82SBruce A. Mah.Ed
318addeef82SBruce A. Mah.Bd -literal
319addeef82SBruce A. Mah/* IPv6 */
320addeef82SBruce A. Mahstruct mf6cctl mc;
321addeef82SBruce A. Mahmemset(&mc, 0, sizeof(mc));
322addeef82SBruce A. Mahmemcpy(&mc.mf6cc_origin, &source_addr, sizeof(mc.mf6cc_origin));
323addeef82SBruce A. Mahmemcpy(&mc.mf6cc_mcastgrp, &group_addr, sizeof(mf6cc_mcastgrp));
324addeef82SBruce A. Mahmc.mf6cc_parent = iif_index;
325addeef82SBruce A. Mahfor (i = 0; i < maxvifs; i++)
326addeef82SBruce A. Mah    if (oifs_ttl[i] > 0)
327addeef82SBruce A. Mah        IF_SET(i, &mc.mf6cc_ifset);
328addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IPV6, MRT6_ADD_MFC,
329addeef82SBruce A. Mah           (void *)&mc, sizeof(mc));
330addeef82SBruce A. Mah.Ed
331addeef82SBruce A. Mah.Pp
332addeef82SBruce A. MahThe
333ef151d78SRuslan Ermilov.Va source_addr
334addeef82SBruce A. Mahand
335ef151d78SRuslan Ermilov.Va group_addr
336addeef82SBruce A. Mahare the source and group address of the multicast packet (as set
337addeef82SBruce A. Mahin the upcall message).
338addeef82SBruce A. MahThe
339ef151d78SRuslan Ermilov.Va iif_index
340addeef82SBruce A. Mahis the virtual interface index of the multicast interface the multicast
341addeef82SBruce A. Mahpackets for this specific source and group address should be received on.
342addeef82SBruce A. MahThe
343ef151d78SRuslan Ermilov.Va oifs_ttl[]
344addeef82SBruce A. Maharray contains the minimum TTL (per interface) a multicast packet
345addeef82SBruce A. Mahshould have to be forwarded on an outgoing interface.
346addeef82SBruce A. MahIf the TTL value is zero, the corresponding interface is not included
347addeef82SBruce A. Mahin the set of outgoing interfaces.
348addeef82SBruce A. MahNote that in case of IPv6 only the set of outgoing interfaces can
349addeef82SBruce A. Mahbe specified.
350addeef82SBruce A. Mah.Pp
351ef151d78SRuslan ErmilovAn MFC entry is deleted by:
352addeef82SBruce A. Mah.Bd -literal
353addeef82SBruce A. Mah/* IPv4 */
354addeef82SBruce A. Mahstruct mfcctl mc;
355addeef82SBruce A. Mahmemset(&mc, 0, sizeof(mc));
356addeef82SBruce A. Mahmemcpy(&mc.mfcc_origin, &source_addr, sizeof(mc.mfcc_origin));
357addeef82SBruce A. Mahmemcpy(&mc.mfcc_mcastgrp, &group_addr, sizeof(mc.mfcc_mcastgrp));
358addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_DEL_MFC,
359addeef82SBruce A. Mah           (void *)&mc, sizeof(mc));
360addeef82SBruce A. Mah.Ed
361addeef82SBruce A. Mah.Bd -literal
362addeef82SBruce A. Mah/* IPv6 */
363addeef82SBruce A. Mahstruct mf6cctl mc;
364addeef82SBruce A. Mahmemset(&mc, 0, sizeof(mc));
365addeef82SBruce A. Mahmemcpy(&mc.mf6cc_origin, &source_addr, sizeof(mc.mf6cc_origin));
366addeef82SBruce A. Mahmemcpy(&mc.mf6cc_mcastgrp, &group_addr, sizeof(mf6cc_mcastgrp));
367addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IPV6, MRT6_DEL_MFC,
368addeef82SBruce A. Mah           (void *)&mc, sizeof(mc));
369addeef82SBruce A. Mah.Ed
370addeef82SBruce A. Mah.Pp
371addeef82SBruce A. MahThe following method can be used to get various statistics per
372addeef82SBruce A. Mahinstalled MFC entry in the kernel (e.g., the number of forwarded
373addeef82SBruce A. Mahpackets per source and group address):
374addeef82SBruce A. Mah.Bd -literal
375addeef82SBruce A. Mah/* IPv4 */
376addeef82SBruce A. Mahstruct sioc_sg_req sgreq;
377addeef82SBruce A. Mahmemset(&sgreq, 0, sizeof(sgreq));
378addeef82SBruce A. Mahmemcpy(&sgreq.src, &source_addr, sizeof(sgreq.src));
379addeef82SBruce A. Mahmemcpy(&sgreq.grp, &group_addr, sizeof(sgreq.grp));
380addeef82SBruce A. Mahioctl(mrouter_s4, SIOCGETSGCNT, &sgreq);
381addeef82SBruce A. Mah.Ed
382addeef82SBruce A. Mah.Bd -literal
383addeef82SBruce A. Mah/* IPv6 */
384addeef82SBruce A. Mahstruct sioc_sg_req6 sgreq;
385addeef82SBruce A. Mahmemset(&sgreq, 0, sizeof(sgreq));
386addeef82SBruce A. Mahmemcpy(&sgreq.src, &source_addr, sizeof(sgreq.src));
387addeef82SBruce A. Mahmemcpy(&sgreq.grp, &group_addr, sizeof(sgreq.grp));
388addeef82SBruce A. Mahioctl(mrouter_s6, SIOCGETSGCNT_IN6, &sgreq);
389addeef82SBruce A. Mah.Ed
390addeef82SBruce A. Mah.Pp
391addeef82SBruce A. MahThe following method can be used to get various statistics per
392addeef82SBruce A. Mahmulticast virtual interface in the kernel (e.g., the number of forwarded
393addeef82SBruce A. Mahpackets per interface):
394addeef82SBruce A. Mah.Bd -literal
395addeef82SBruce A. Mah/* IPv4 */
396addeef82SBruce A. Mahstruct sioc_vif_req vreq;
397addeef82SBruce A. Mahmemset(&vreq, 0, sizeof(vreq));
398addeef82SBruce A. Mahvreq.vifi = vif_index;
399addeef82SBruce A. Mahioctl(mrouter_s4, SIOCGETVIFCNT, &vreq);
400addeef82SBruce A. Mah.Ed
401addeef82SBruce A. Mah.Bd -literal
402addeef82SBruce A. Mah/* IPv6 */
403addeef82SBruce A. Mahstruct sioc_mif_req6 mreq;
404addeef82SBruce A. Mahmemset(&mreq, 0, sizeof(mreq));
405addeef82SBruce A. Mahmreq.mifi = vif_index;
406addeef82SBruce A. Mahioctl(mrouter_s6, SIOCGETMIFCNT_IN6, &mreq);
407addeef82SBruce A. Mah.Ed
408addeef82SBruce A. Mah.Ss Advanced Multicast API Programming Guide
409addeef82SBruce A. MahIf we want to add new features in the kernel, it becomes difficult
410addeef82SBruce A. Mahto preserve backward compatibility (binary and API),
411addeef82SBruce A. Mahand at the same time to allow user-level processes to take advantage of
412addeef82SBruce A. Mahthe new features (if the kernel supports them).
413addeef82SBruce A. Mah.Pp
414addeef82SBruce A. MahOne of the mechanisms that allows us to preserve the backward
415addeef82SBruce A. Mahcompatibility is a sort of negotiation
416addeef82SBruce A. Mahbetween the user-level process and the kernel:
417addeef82SBruce A. Mah.Bl -enum
418addeef82SBruce A. Mah.It
419addeef82SBruce A. MahThe user-level process tries to enable in the kernel the set of new
420addeef82SBruce A. Mahfeatures (and the corresponding API) it would like to use.
421addeef82SBruce A. Mah.It
422addeef82SBruce A. MahThe kernel returns the (sub)set of features it knows about
423addeef82SBruce A. Mahand is willing to be enabled.
424addeef82SBruce A. Mah.It
425addeef82SBruce A. MahThe user-level process uses only that set of features
426addeef82SBruce A. Mahthe kernel has agreed on.
427addeef82SBruce A. Mah.El
428addeef82SBruce A. Mah.\"
429addeef82SBruce A. Mah.Pp
430ef151d78SRuslan ErmilovTo support backward compatibility, if the user-level process does not
431addeef82SBruce A. Mahask for any new features, the kernel defaults to the basic
432addeef82SBruce A. Mahmulticast API (see the
433addeef82SBruce A. Mah.Sx "Programming Guide"
434addeef82SBruce A. Mahsection).
435addeef82SBruce A. Mah.\" XXX: edit as appropriate after the advanced multicast API is
436addeef82SBruce A. Mah.\" supported under IPv6
437addeef82SBruce A. MahCurrently, the advanced multicast API exists only for IPv4;
438addeef82SBruce A. Mahin the future there will be IPv6 support as well.
439addeef82SBruce A. Mah.Pp
440addeef82SBruce A. MahBelow is a summary of the expandable API solution.
441addeef82SBruce A. MahNote that all new options and structures are defined
442ef151d78SRuslan Ermilovin
443ef151d78SRuslan Ermilov.In netinet/ip_mroute.h
444ef151d78SRuslan Ermilovand
445ef151d78SRuslan Ermilov.In netinet6/ip6_mroute.h ,
446addeef82SBruce A. Mahunless stated otherwise.
447addeef82SBruce A. Mah.Pp
448ef151d78SRuslan ErmilovThe user-level process uses new
449ef151d78SRuslan Ermilov.Fn getsockopt Ns / Ns Fn setsockopt
450ef151d78SRuslan Ermilovoptions to
451addeef82SBruce A. Mahperform the API features negotiation with the kernel.
452addeef82SBruce A. MahThis negotiation must be performed right after the multicast routing
453addeef82SBruce A. Mahsocket is open.
454addeef82SBruce A. MahThe set of desired/allowed features is stored in a bitset
455ef151d78SRuslan Ermilov(currently, in
456ef151d78SRuslan Ermilov.Vt uint32_t ;
457ef151d78SRuslan Ermilovi.e., maximum of 32 new features).
458ef151d78SRuslan ErmilovThe new
459ef151d78SRuslan Ermilov.Fn getsockopt Ns / Ns Fn setsockopt
460ef151d78SRuslan Ermilovoptions are
461ef151d78SRuslan Ermilov.Dv MRT_API_SUPPORT
462addeef82SBruce A. Mahand
463ef151d78SRuslan Ermilov.Dv MRT_API_CONFIG .
464addeef82SBruce A. MahExample:
465addeef82SBruce A. Mah.Bd -literal
466addeef82SBruce A. Mahuint32_t v;
467addeef82SBruce A. Mahgetsockopt(sock, IPPROTO_IP, MRT_API_SUPPORT, (void *)&v, sizeof(v));
468addeef82SBruce A. Mah.Ed
469addeef82SBruce A. Mah.Pp
470addeef82SBruce A. Mahwould set in
471ef151d78SRuslan Ermilov.Va v
472addeef82SBruce A. Mahthe pre-defined bits that the kernel API supports.
473ef151d78SRuslan ErmilovThe eight least significant bits in
474ef151d78SRuslan Ermilov.Vt uint32_t
475ef151d78SRuslan Ermilovare same as the
476addeef82SBruce A. Maheight possible flags
477ef151d78SRuslan Ermilov.Dv MRT_MFC_FLAGS_*
478addeef82SBruce A. Mahthat can be used in
479ef151d78SRuslan Ermilov.Va mfcc_flags
480addeef82SBruce A. Mahas part of the new definition of
481ef151d78SRuslan Ermilov.Vt "struct mfcctl"
482addeef82SBruce A. Mah(see below about those flags), which leaves 24 flags for other new features.
483ef151d78SRuslan ErmilovThe value returned by
484ef151d78SRuslan Ermilov.Fn getsockopt MRT_API_SUPPORT
485ef151d78SRuslan Ermilovis read-only; in other words,
486ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_SUPPORT
487ef151d78SRuslan Ermilovwould fail.
488addeef82SBruce A. Mah.Pp
489addeef82SBruce A. MahTo modify the API, and to set some specific feature in the kernel, then:
490addeef82SBruce A. Mah.Bd -literal
491addeef82SBruce A. Mahuint32_t v = MRT_MFC_FLAGS_DISABLE_WRONGVIF;
492addeef82SBruce A. Mahif (setsockopt(sock, IPPROTO_IP, MRT_API_CONFIG, (void *)&v, sizeof(v))
493addeef82SBruce A. Mah    != 0) {
494addeef82SBruce A. Mah    return (ERROR);
495addeef82SBruce A. Mah}
496addeef82SBruce A. Mahif (v & MRT_MFC_FLAGS_DISABLE_WRONGVIF)
497addeef82SBruce A. Mah    return (OK);	/* Success */
498addeef82SBruce A. Mahelse
499addeef82SBruce A. Mah    return (ERROR);
500addeef82SBruce A. Mah.Ed
501addeef82SBruce A. Mah.Pp
502ef151d78SRuslan ErmilovIn other words, when
503ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_CONFIG
504ef151d78SRuslan Ermilovis called, the
505addeef82SBruce A. Mahargument to it specifies the desired set of features to
506addeef82SBruce A. Mahbe enabled in the API and the kernel.
507addeef82SBruce A. MahThe return value in
508ef151d78SRuslan Ermilov.Va v
509addeef82SBruce A. Mahis the actual (sub)set of features that were enabled in the kernel.
510addeef82SBruce A. MahTo obtain later the same set of features that were enabled, then:
511addeef82SBruce A. Mah.Bd -literal
512addeef82SBruce A. Mahgetsockopt(sock, IPPROTO_IP, MRT_API_CONFIG, (void *)&v, sizeof(v));
513addeef82SBruce A. Mah.Ed
514addeef82SBruce A. Mah.Pp
515addeef82SBruce A. MahThe set of enabled features is global.
516ef151d78SRuslan ErmilovIn other words,
517ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_CONFIG
518ef151d78SRuslan Ermilovshould be called right after
519ef151d78SRuslan Ermilov.Fn setsockopt MRT_INIT .
520addeef82SBruce A. Mah.Pp
521addeef82SBruce A. MahCurrently, the following set of new features is defined:
522addeef82SBruce A. Mah.Bd -literal
523addeef82SBruce A. Mah#define	MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */
524addeef82SBruce A. Mah#define	MRT_MFC_FLAGS_BORDER_VIF   (1 << 1)  /* border vif              */
525addeef82SBruce A. Mah#define MRT_MFC_RP                 (1 << 8)  /* enable RP address	*/
526addeef82SBruce A. Mah#define MRT_MFC_BW_UPCALL          (1 << 9)  /* enable bw upcalls	*/
527addeef82SBruce A. Mah.Ed
528addeef82SBruce A. Mah.\" .Pp
529addeef82SBruce A. Mah.\" In the future there might be:
530addeef82SBruce A. Mah.\" .Bd -literal
531addeef82SBruce A. Mah.\" #define MRT_MFC_GROUP_SPECIFIC     (1 << 10) /* allow (*,G) MFC entries */
532addeef82SBruce A. Mah.\" .Ed
533addeef82SBruce A. Mah.\" .Pp
534addeef82SBruce A. Mah.\" to allow (*,G) MFC entries (i.e., group-specific entries) in the kernel.
535addeef82SBruce A. Mah.\" For now this is left-out until it is clear whether
536addeef82SBruce A. Mah.\" (*,G) MFC support is the preferred solution instead of something more generic
537addeef82SBruce A. Mah.\" solution for example.
538addeef82SBruce A. Mah.\"
539addeef82SBruce A. Mah.\" 2. The newly defined struct mfcctl2.
540addeef82SBruce A. Mah.\"
541addeef82SBruce A. Mah.Pp
542addeef82SBruce A. MahThe advanced multicast API uses a newly defined
543ef151d78SRuslan Ermilov.Vt "struct mfcctl2"
544addeef82SBruce A. Mahinstead of the traditional
545ef151d78SRuslan Ermilov.Vt "struct mfcctl" .
546addeef82SBruce A. MahThe original
547ef151d78SRuslan Ermilov.Vt "struct mfcctl"
548addeef82SBruce A. Mahis kept as is.
549addeef82SBruce A. MahThe new
550ef151d78SRuslan Ermilov.Vt "struct mfcctl2"
551addeef82SBruce A. Mahis:
552addeef82SBruce A. Mah.Bd -literal
553addeef82SBruce A. Mah/*
554addeef82SBruce A. Mah * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays
555addeef82SBruce A. Mah * and extends the old struct mfcctl.
556addeef82SBruce A. Mah */
557addeef82SBruce A. Mahstruct mfcctl2 {
558addeef82SBruce A. Mah        /* the mfcctl fields */
559addeef82SBruce A. Mah        struct in_addr  mfcc_origin;       /* ip origin of mcasts       */
560addeef82SBruce A. Mah        struct in_addr  mfcc_mcastgrp;     /* multicast group associated*/
561addeef82SBruce A. Mah        vifi_t          mfcc_parent;       /* incoming vif              */
562addeef82SBruce A. Mah        u_char          mfcc_ttls[MAXVIFS];/* forwarding ttls on vifs   */
563addeef82SBruce A. Mah
564addeef82SBruce A. Mah        /* extension fields */
565addeef82SBruce A. Mah        uint8_t         mfcc_flags[MAXVIFS];/* the MRT_MFC_FLAGS_* flags*/
566addeef82SBruce A. Mah        struct in_addr  mfcc_rp;            /* the RP address           */
567addeef82SBruce A. Mah};
568addeef82SBruce A. Mah.Ed
569addeef82SBruce A. Mah.Pp
570addeef82SBruce A. MahThe new fields are
571ef151d78SRuslan Ermilov.Va mfcc_flags[MAXVIFS]
572addeef82SBruce A. Mahand
573ef151d78SRuslan Ermilov.Va mfcc_rp .
574addeef82SBruce A. MahNote that for compatibility reasons they are added at the end.
575addeef82SBruce A. Mah.Pp
576addeef82SBruce A. MahThe
577ef151d78SRuslan Ermilov.Va mfcc_flags[MAXVIFS]
578addeef82SBruce A. Mahfield is used to set various flags per
579addeef82SBruce A. Mahinterface per (S,G) entry.
580addeef82SBruce A. MahCurrently, the defined flags are:
581addeef82SBruce A. Mah.Bd -literal
582addeef82SBruce A. Mah#define	MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */
583addeef82SBruce A. Mah#define	MRT_MFC_FLAGS_BORDER_VIF       (1 << 1) /* border vif          */
584addeef82SBruce A. Mah.Ed
585addeef82SBruce A. Mah.Pp
586addeef82SBruce A. MahThe
587ef151d78SRuslan Ermilov.Dv MRT_MFC_FLAGS_DISABLE_WRONGVIF
588addeef82SBruce A. Mahflag is used to explicitly disable the
589ef151d78SRuslan Ermilov.Dv IGMPMSG_WRONGVIF
590addeef82SBruce A. Mahkernel signal at the (S,G) granularity if a multicast data packet
591addeef82SBruce A. Maharrives on the wrong interface.
592addeef82SBruce A. MahUsually, this signal is used to
593addeef82SBruce A. Mahcomplete the shortest-path switch in case of PIM-SM multicast routing,
594addeef82SBruce A. Mahor to trigger a PIM assert message.
595addeef82SBruce A. MahHowever, it should not be delivered for interfaces that are not in
596addeef82SBruce A. Mahthe outgoing interface set, and that are not expecting to
597addeef82SBruce A. Mahbecome an incoming interface.
598addeef82SBruce A. MahHence, if the
599ef151d78SRuslan Ermilov.Dv MRT_MFC_FLAGS_DISABLE_WRONGVIF
600addeef82SBruce A. Mahflag is set for some of the
601addeef82SBruce A. Mahinterfaces, then a data packet that arrives on that interface for
602addeef82SBruce A. Mahthat MFC entry will NOT trigger a WRONGVIF signal.
603addeef82SBruce A. MahIf that flag is not set, then a signal is triggered (the default action).
604addeef82SBruce A. Mah.Pp
605addeef82SBruce A. MahThe
606ef151d78SRuslan Ermilov.Dv MRT_MFC_FLAGS_BORDER_VIF
607addeef82SBruce A. Mahflag is used to specify whether the Border-bit in PIM
608addeef82SBruce A. MahRegister messages should be set (in case when the Register encapsulation
609addeef82SBruce A. Mahis performed inside the kernel).
610addeef82SBruce A. MahIf it is set for the special PIM Register kernel virtual interface
611addeef82SBruce A. Mah(see
612addeef82SBruce A. Mah.Xr pim 4 ) ,
613addeef82SBruce A. Mahthe Border-bit in the Register messages sent to the RP will be set.
614addeef82SBruce A. Mah.Pp
615addeef82SBruce A. MahThe remaining six bits are reserved for future usage.
616addeef82SBruce A. Mah.Pp
617addeef82SBruce A. MahThe
618ef151d78SRuslan Ermilov.Va mfcc_rp
619addeef82SBruce A. Mahfield is used to specify the RP address (in case of PIM-SM multicast routing)
620addeef82SBruce A. Mahfor a multicast
621addeef82SBruce A. Mahgroup G if we want to perform kernel-level PIM Register encapsulation.
622addeef82SBruce A. MahThe
623ef151d78SRuslan Ermilov.Va mfcc_rp
624addeef82SBruce A. Mahfield is used only if the
625ef151d78SRuslan Ermilov.Dv MRT_MFC_RP
626addeef82SBruce A. Mahadvanced API flag/capability has been successfully set by
627ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_CONFIG .
628addeef82SBruce A. Mah.Pp
629addeef82SBruce A. Mah.\"
630addeef82SBruce A. Mah.\" 3. Kernel-level PIM Register encapsulation
631addeef82SBruce A. Mah.\"
632addeef82SBruce A. MahIf the
633ef151d78SRuslan Ermilov.Dv MRT_MFC_RP
634addeef82SBruce A. Mahflag was successfully set by
635ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_CONFIG ,
636ef151d78SRuslan Ermilovthen the kernel will attempt to perform
637addeef82SBruce A. Mahthe PIM Register encapsulation itself instead of sending the
638ef151d78SRuslan Ermilovmulticast data packets to user level (inside
639ef151d78SRuslan Ermilov.Dv IGMPMSG_WHOLEPKT
640addeef82SBruce A. Mahupcalls) for user-level encapsulation.
641addeef82SBruce A. MahThe RP address would be taken from the
642ef151d78SRuslan Ermilov.Va mfcc_rp
643addeef82SBruce A. Mahfield
644addeef82SBruce A. Mahinside the new
645ef151d78SRuslan Ermilov.Vt "struct mfcctl2" .
646addeef82SBruce A. MahHowever, even if the
647ef151d78SRuslan Ermilov.Dv MRT_MFC_RP
648addeef82SBruce A. Mahflag was successfully set, if the
649ef151d78SRuslan Ermilov.Va mfcc_rp
650addeef82SBruce A. Mahfield was set to
651ef151d78SRuslan Ermilov.Dv INADDR_ANY ,
652addeef82SBruce A. Mahthen the
653ef151d78SRuslan Ermilovkernel will still deliver an
654ef151d78SRuslan Ermilov.Dv IGMPMSG_WHOLEPKT
655ef151d78SRuslan Ermilovupcall with the
656addeef82SBruce A. Mahmulticast data packet to the user-level process.
657addeef82SBruce A. Mah.Pp
658addeef82SBruce A. MahIn addition, if the multicast data packet is too large to fit within
659addeef82SBruce A. Maha single IP packet after the PIM Register encapsulation (e.g., if
660addeef82SBruce A. Mahits size was on the order of 65500 bytes), the data packet will be
661addeef82SBruce A. Mahfragmented, and then each of the fragments will be encapsulated
662addeef82SBruce A. Mahseparately.
663addeef82SBruce A. MahNote that typically a multicast data packet can be that
664addeef82SBruce A. Mahlarge only if it was originated locally from the same hosts that
665addeef82SBruce A. Mahperforms the encapsulation; otherwise the transmission of the
666addeef82SBruce A. Mahmulticast data packet over Ethernet for example would have
667addeef82SBruce A. Mahfragmented it into much smaller pieces.
668addeef82SBruce A. Mah.\"
669addeef82SBruce A. Mah.\" Note that if this code is ported to IPv6, we may need the kernel to
670addeef82SBruce A. Mah.\" perform MTU discovery to the RP, and keep those discoveries inside
671addeef82SBruce A. Mah.\" the kernel so the encapsulating router may send back ICMP
672addeef82SBruce A. Mah.\" Fragmentation Required if the size of the multicast data packet is
673addeef82SBruce A. Mah.\" too large (see "Encapsulating data packets in the Register Tunnel"
674addeef82SBruce A. Mah.\" in Section 4.4.1 in the PIM-SM spec
675addeef82SBruce A. Mah.\" draft-ietf-pim-sm-v2-new-05.{txt,ps}).
676addeef82SBruce A. Mah.\" For IPv4 we may be able to get away without it, but for IPv6 we need
677addeef82SBruce A. Mah.\" that.
678addeef82SBruce A. Mah.\"
679addeef82SBruce A. Mah.\" 4. Mechanism for "multicast bandwidth monitoring and upcalls".
680addeef82SBruce A. Mah.\"
681addeef82SBruce A. Mah.Pp
682addeef82SBruce A. MahTypically, a multicast routing user-level process would need to know the
683addeef82SBruce A. Mahforwarding bandwidth for some data flow.
684addeef82SBruce A. MahFor example, the multicast routing process may want to timeout idle MFC
685addeef82SBruce A. Mahentries, or in case of PIM-SM it can initiate (S,G) shortest-path switch if
686addeef82SBruce A. Mahthe bandwidth rate is above a threshold for example.
687addeef82SBruce A. Mah.Pp
688addeef82SBruce A. MahThe original solution for measuring the bandwidth of a dataflow was
689addeef82SBruce A. Mahthat a user-level process would periodically
690addeef82SBruce A. Mahquery the kernel about the number of forwarded packets/bytes per
691addeef82SBruce A. Mah(S,G), and then based on those numbers it would estimate whether a source
692addeef82SBruce A. Mahhas been idle, or whether the source's transmission bandwidth is above a
693addeef82SBruce A. Mahthreshold.
694addeef82SBruce A. MahThat solution is far from being scalable, hence the need for a new
695addeef82SBruce A. Mahmechanism for bandwidth monitoring.
696addeef82SBruce A. Mah.Pp
697addeef82SBruce A. MahBelow is a description of the bandwidth monitoring mechanism.
698addeef82SBruce A. Mah.Bl -bullet
699addeef82SBruce A. Mah.It
700addeef82SBruce A. MahIf the bandwidth of a data flow satisfies some pre-defined filter,
701addeef82SBruce A. Mahthe kernel delivers an upcall on the multicast routing socket
702addeef82SBruce A. Mahto the multicast routing process that has installed that filter.
703addeef82SBruce A. Mah.It
7045203edcdSRuslan ErmilovThe bandwidth-upcall filters are installed per (S,G).
7055203edcdSRuslan ErmilovThere can be
706addeef82SBruce A. Mahmore than one filter per (S,G).
707addeef82SBruce A. Mah.It
708addeef82SBruce A. MahInstead of supporting all possible comparison operations
709addeef82SBruce A. Mah(i.e., < <= == != > >= ), there is support only for the
710addeef82SBruce A. Mah<= and >= operations,
711addeef82SBruce A. Mahbecause this makes the kernel-level implementation simpler,
712addeef82SBruce A. Mahand because practically we need only those two.
713addeef82SBruce A. MahFurther, the missing operations can be simulated by secondary
714addeef82SBruce A. Mahuser-level filtering of those <= and >= filters.
715addeef82SBruce A. MahFor example, to simulate !=, then we need to install filter
716addeef82SBruce A. Mah.Dq bw <= 0xffffffff ,
717addeef82SBruce A. Mahand after an
718addeef82SBruce A. Mahupcall is received, we need to check whether
719addeef82SBruce A. Mah.Dq measured_bw != expected_bw .
720addeef82SBruce A. Mah.It
721addeef82SBruce A. MahThe bandwidth-upcall mechanism is enabled by
722ef151d78SRuslan Ermilov.Fn setsockopt MRT_API_CONFIG
723ef151d78SRuslan Ermilovfor the
724ef151d78SRuslan Ermilov.Dv MRT_MFC_BW_UPCALL
725ef151d78SRuslan Ermilovflag.
726addeef82SBruce A. Mah.It
727addeef82SBruce A. MahThe bandwidth-upcall filters are added/deleted by the new
728ef151d78SRuslan Ermilov.Fn setsockopt MRT_ADD_BW_UPCALL
729ef151d78SRuslan Ermilovand
730ef151d78SRuslan Ermilov.Fn setsockopt MRT_DEL_BW_UPCALL
731addeef82SBruce A. Mahrespectively (with the appropriate
732ef151d78SRuslan Ermilov.Vt "struct bw_upcall"
733addeef82SBruce A. Mahargument of course).
734addeef82SBruce A. Mah.El
735addeef82SBruce A. Mah.Pp
736addeef82SBruce A. MahFrom application point of view, a developer needs to know about
737addeef82SBruce A. Mahthe following:
738addeef82SBruce A. Mah.Bd -literal
739addeef82SBruce A. Mah/*
740addeef82SBruce A. Mah * Structure for installing or delivering an upcall if the
741addeef82SBruce A. Mah * measured bandwidth is above or below a threshold.
742addeef82SBruce A. Mah *
743addeef82SBruce A. Mah * User programs (e.g. daemons) may have a need to know when the
744addeef82SBruce A. Mah * bandwidth used by some data flow is above or below some threshold.
745addeef82SBruce A. Mah * This interface allows the userland to specify the threshold (in
746addeef82SBruce A. Mah * bytes and/or packets) and the measurement interval. Flows are
747addeef82SBruce A. Mah * all packet with the same source and destination IP address.
748addeef82SBruce A. Mah * At the moment the code is only used for multicast destinations
749addeef82SBruce A. Mah * but there is nothing that prevents its use for unicast.
750addeef82SBruce A. Mah *
751addeef82SBruce A. Mah * The measurement interval cannot be shorter than some Tmin (currently, 3s).
752addeef82SBruce A. Mah * The threshold is set in packets and/or bytes per_interval.
753addeef82SBruce A. Mah *
754addeef82SBruce A. Mah * Measurement works as follows:
755addeef82SBruce A. Mah *
756addeef82SBruce A. Mah * For >= measurements:
757addeef82SBruce A. Mah * The first packet marks the start of a measurement interval.
758addeef82SBruce A. Mah * During an interval we count packets and bytes, and when we
759addeef82SBruce A. Mah * pass the threshold we deliver an upcall and we are done.
760addeef82SBruce A. Mah * The first packet after the end of the interval resets the
761addeef82SBruce A. Mah * count and restarts the measurement.
762addeef82SBruce A. Mah *
763addeef82SBruce A. Mah * For <= measurement:
764addeef82SBruce A. Mah * We start a timer to fire at the end of the interval, and
765addeef82SBruce A. Mah * then for each incoming packet we count packets and bytes.
766addeef82SBruce A. Mah * When the timer fires, we compare the value with the threshold,
767addeef82SBruce A. Mah * schedule an upcall if we are below, and restart the measurement
768addeef82SBruce A. Mah * (reschedule timer and zero counters).
769addeef82SBruce A. Mah */
770addeef82SBruce A. Mah
771addeef82SBruce A. Mahstruct bw_data {
772addeef82SBruce A. Mah        struct timeval  b_time;
773addeef82SBruce A. Mah        uint64_t        b_packets;
774addeef82SBruce A. Mah        uint64_t        b_bytes;
775addeef82SBruce A. Mah};
776addeef82SBruce A. Mah
777addeef82SBruce A. Mahstruct bw_upcall {
778addeef82SBruce A. Mah        struct in_addr  bu_src;         /* source address            */
779addeef82SBruce A. Mah        struct in_addr  bu_dst;         /* destination address       */
780addeef82SBruce A. Mah        uint32_t        bu_flags;       /* misc flags (see below)    */
781addeef82SBruce A. Mah#define BW_UPCALL_UNIT_PACKETS (1 << 0) /* threshold (in packets)    */
782addeef82SBruce A. Mah#define BW_UPCALL_UNIT_BYTES   (1 << 1) /* threshold (in bytes)      */
783addeef82SBruce A. Mah#define BW_UPCALL_GEQ          (1 << 2) /* upcall if bw >= threshold */
784addeef82SBruce A. Mah#define BW_UPCALL_LEQ          (1 << 3) /* upcall if bw <= threshold */
785addeef82SBruce A. Mah#define BW_UPCALL_DELETE_ALL   (1 << 4) /* delete all upcalls for s,d*/
786addeef82SBruce A. Mah        struct bw_data  bu_threshold;   /* the bw threshold          */
787addeef82SBruce A. Mah        struct bw_data  bu_measured;    /* the measured bw           */
788addeef82SBruce A. Mah};
789addeef82SBruce A. Mah
790addeef82SBruce A. Mah/* max. number of upcalls to deliver together */
791addeef82SBruce A. Mah#define BW_UPCALLS_MAX				128
792addeef82SBruce A. Mah/* min. threshold time interval for bandwidth measurement */
793addeef82SBruce A. Mah#define BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC	3
794addeef82SBruce A. Mah#define BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC	0
795addeef82SBruce A. Mah.Ed
796addeef82SBruce A. Mah.Pp
797addeef82SBruce A. MahThe
798ef151d78SRuslan Ermilov.Vt bw_upcall
799addeef82SBruce A. Mahstructure is used as an argument to
800ef151d78SRuslan Ermilov.Fn setsockopt MRT_ADD_BW_UPCALL
801ef151d78SRuslan Ermilovand
802ef151d78SRuslan Ermilov.Fn setsockopt MRT_DEL_BW_UPCALL .
803ef151d78SRuslan ErmilovEach
804ef151d78SRuslan Ermilov.Fn setsockopt MRT_ADD_BW_UPCALL
805ef151d78SRuslan Ermilovinstalls a filter in the kernel
806addeef82SBruce A. Mahfor the source and destination address in the
807ef151d78SRuslan Ermilov.Vt bw_upcall
808addeef82SBruce A. Mahargument,
809addeef82SBruce A. Mahand that filter will trigger an upcall according to the following
810addeef82SBruce A. Mahpseudo-algorithm:
811addeef82SBruce A. Mah.Bd -literal
812addeef82SBruce A. Mah if (bw_upcall_oper IS ">=") {
813addeef82SBruce A. Mah    if (((bw_upcall_unit & PACKETS == PACKETS) &&
814addeef82SBruce A. Mah         (measured_packets >= threshold_packets)) ||
815addeef82SBruce A. Mah        ((bw_upcall_unit & BYTES == BYTES) &&
816addeef82SBruce A. Mah         (measured_bytes >= threshold_bytes)))
817addeef82SBruce A. Mah       SEND_UPCALL("measured bandwidth is >= threshold");
818addeef82SBruce A. Mah  }
819addeef82SBruce A. Mah  if (bw_upcall_oper IS "<=" && measured_interval >= threshold_interval) {
820addeef82SBruce A. Mah    if (((bw_upcall_unit & PACKETS == PACKETS) &&
821addeef82SBruce A. Mah         (measured_packets <= threshold_packets)) ||
822addeef82SBruce A. Mah        ((bw_upcall_unit & BYTES == BYTES) &&
823addeef82SBruce A. Mah         (measured_bytes <= threshold_bytes)))
824addeef82SBruce A. Mah       SEND_UPCALL("measured bandwidth is <= threshold");
825addeef82SBruce A. Mah  }
826addeef82SBruce A. Mah.Ed
827addeef82SBruce A. Mah.Pp
828addeef82SBruce A. MahIn the same
829ef151d78SRuslan Ermilov.Vt bw_upcall
830addeef82SBruce A. Mahthe unit can be specified in both BYTES and PACKETS.
831addeef82SBruce A. MahHowever, the GEQ and LEQ flags are mutually exclusive.
832addeef82SBruce A. Mah.Pp
833addeef82SBruce A. MahBasically, an upcall is delivered if the measured bandwidth is >= or
834addeef82SBruce A. Mah<= the threshold bandwidth (within the specified measurement
835addeef82SBruce A. Mahinterval).
836addeef82SBruce A. MahFor practical reasons, the smallest value for the measurement
837addeef82SBruce A. Mahinterval is 3 seconds.
838addeef82SBruce A. MahIf smaller values are allowed, then the bandwidth
839addeef82SBruce A. Mahestimation may be less accurate, or the potentially very high frequency
840addeef82SBruce A. Mahof the generated upcalls may introduce too much overhead.
841addeef82SBruce A. MahFor the >= operation, the answer may be known before the end of
842ef151d78SRuslan Ermilov.Va threshold_interval ,
843addeef82SBruce A. Mahtherefore the upcall may be delivered earlier.
844addeef82SBruce A. MahFor the <= operation however, we must wait
845addeef82SBruce A. Mahuntil the threshold interval has expired to know the answer.
846addeef82SBruce A. Mah.Pp
847addeef82SBruce A. MahExample of usage:
848addeef82SBruce A. Mah.Bd -literal
849addeef82SBruce A. Mahstruct bw_upcall bw_upcall;
850addeef82SBruce A. Mah/* Assign all bw_upcall fields as appropriate */
851addeef82SBruce A. Mahmemset(&bw_upcall, 0, sizeof(bw_upcall));
852addeef82SBruce A. Mahmemcpy(&bw_upcall.bu_src, &source, sizeof(bw_upcall.bu_src));
853addeef82SBruce A. Mahmemcpy(&bw_upcall.bu_dst, &group, sizeof(bw_upcall.bu_dst));
854addeef82SBruce A. Mahbw_upcall.bu_threshold.b_data = threshold_interval;
855addeef82SBruce A. Mahbw_upcall.bu_threshold.b_packets = threshold_packets;
856addeef82SBruce A. Mahbw_upcall.bu_threshold.b_bytes = threshold_bytes;
857addeef82SBruce A. Mahif (is_threshold_in_packets)
858addeef82SBruce A. Mah    bw_upcall.bu_flags |= BW_UPCALL_UNIT_PACKETS;
859addeef82SBruce A. Mahif (is_threshold_in_bytes)
860addeef82SBruce A. Mah    bw_upcall.bu_flags |= BW_UPCALL_UNIT_BYTES;
861addeef82SBruce A. Mahdo {
862addeef82SBruce A. Mah    if (is_geq_upcall) {
863addeef82SBruce A. Mah        bw_upcall.bu_flags |= BW_UPCALL_GEQ;
864addeef82SBruce A. Mah        break;
865addeef82SBruce A. Mah    }
866addeef82SBruce A. Mah    if (is_leq_upcall) {
867addeef82SBruce A. Mah        bw_upcall.bu_flags |= BW_UPCALL_LEQ;
868addeef82SBruce A. Mah        break;
869addeef82SBruce A. Mah    }
870addeef82SBruce A. Mah    return (ERROR);
871addeef82SBruce A. Mah} while (0);
872addeef82SBruce A. Mahsetsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_BW_UPCALL,
873addeef82SBruce A. Mah          (void *)&bw_upcall, sizeof(bw_upcall));
874addeef82SBruce A. Mah.Ed
875addeef82SBruce A. Mah.Pp
876ef151d78SRuslan ErmilovTo delete a single filter, then use
877ef151d78SRuslan Ermilov.Dv MRT_DEL_BW_UPCALL ,
878addeef82SBruce A. Mahand the fields of bw_upcall must be set
879ef151d78SRuslan Ermilovexactly same as when
880ef151d78SRuslan Ermilov.Dv MRT_ADD_BW_UPCALL
881ef151d78SRuslan Ermilovwas called.
882addeef82SBruce A. Mah.Pp
883addeef82SBruce A. MahTo delete all bandwidth filters for a given (S,G), then
884addeef82SBruce A. Mahonly the
885ef151d78SRuslan Ermilov.Va bu_src
886addeef82SBruce A. Mahand
887ef151d78SRuslan Ermilov.Va bu_dst
888addeef82SBruce A. Mahfields in
889ef151d78SRuslan Ermilov.Vt "struct bw_upcall"
890addeef82SBruce A. Mahneed to be set, and then just set only the
891ef151d78SRuslan Ermilov.Dv BW_UPCALL_DELETE_ALL
892addeef82SBruce A. Mahflag inside field
893ef151d78SRuslan Ermilov.Va bw_upcall.bu_flags .
894addeef82SBruce A. Mah.Pp
895addeef82SBruce A. MahThe bandwidth upcalls are received by aggregating them in the new upcall
896addeef82SBruce A. Mahmessage:
897addeef82SBruce A. Mah.Bd -literal
898addeef82SBruce A. Mah#define IGMPMSG_BW_UPCALL  4  /* BW monitoring upcall */
899addeef82SBruce A. Mah.Ed
900addeef82SBruce A. Mah.Pp
901addeef82SBruce A. MahThis message is an array of
902ef151d78SRuslan Ermilov.Vt "struct bw_upcall"
903ef151d78SRuslan Ermilovelements (up to
904ef151d78SRuslan Ermilov.Dv BW_UPCALLS_MAX
905ef151d78SRuslan Ermilov= 128).
906addeef82SBruce A. MahThe upcalls are
907addeef82SBruce A. Mahdelivered when there are 128 pending upcalls, or when 1 second has
908addeef82SBruce A. Mahexpired since the previous upcall (whichever comes first).
909addeef82SBruce A. MahIn an
910ef151d78SRuslan Ermilov.Vt "struct upcall"
911addeef82SBruce A. Mahelement, the
912ef151d78SRuslan Ermilov.Va bu_measured
913addeef82SBruce A. Mahfield is filled-in to
914addeef82SBruce A. Mahindicate the particular measured values.
915addeef82SBruce A. MahHowever, because of the way
916addeef82SBruce A. Mahthe particular intervals are measured, the user should be careful how
917ef151d78SRuslan Ermilov.Va bu_measured.b_time
918ef151d78SRuslan Ermilovis used.
919addeef82SBruce A. MahFor example, if the
920addeef82SBruce A. Mahfilter is installed to trigger an upcall if the number of packets
921addeef82SBruce A. Mahis >= 1, then
922ef151d78SRuslan Ermilov.Va bu_measured
923addeef82SBruce A. Mahmay have a value of zero in the upcalls after the
924addeef82SBruce A. Mahfirst one, because the measured interval for >= filters is
925addeef82SBruce A. Mah.Dq clocked
926addeef82SBruce A. Mahby the forwarded packets.
927addeef82SBruce A. MahHence, this upcall mechanism should not be used for measuring
928addeef82SBruce A. Mahthe exact value of the bandwidth of the forwarded data.
929addeef82SBruce A. MahTo measure the exact bandwidth, the user would need to
930ef151d78SRuslan Ermilovget the forwarded packets statistics with the
931ef151d78SRuslan Ermilov.Fn ioctl SIOCGETSGCNT
932addeef82SBruce A. Mahmechanism
933addeef82SBruce A. Mah(see the
934addeef82SBruce A. Mah.Sx Programming Guide
935addeef82SBruce A. Mahsection) .
936addeef82SBruce A. Mah.Pp
937addeef82SBruce A. MahNote that the upcalls for a filter are delivered until the specific
938addeef82SBruce A. Mahfilter is deleted, but no more frequently than once per
939ef151d78SRuslan Ermilov.Va bu_threshold.b_time .
940addeef82SBruce A. MahFor example, if the filter is specified to
941addeef82SBruce A. Mahdeliver a signal if bw >= 1 packet, the first packet will trigger a
942addeef82SBruce A. Mahsignal, but the next upcall will be triggered no earlier than
943ef151d78SRuslan Ermilov.Va bu_threshold.b_time
944addeef82SBruce A. Mahafter the previous upcall.
945addeef82SBruce A. Mah.\"
946addeef82SBruce A. Mah.Sh SEE ALSO
9470770db89SBruce M Simpson.Xr altq 4 ,
9480770db89SBruce M Simpson.Xr dummynet 4 ,
949addeef82SBruce A. Mah.Xr getsockopt 2 ,
9500770db89SBruce M Simpson.Xr gif 4 ,
9510770db89SBruce M Simpson.Xr gre 4 ,
952addeef82SBruce A. Mah.Xr recvfrom 2 ,
953addeef82SBruce A. Mah.Xr recvmsg 2 ,
954addeef82SBruce A. Mah.Xr setsockopt 2 ,
955addeef82SBruce A. Mah.Xr socket 2 ,
956addeef82SBruce A. Mah.Xr icmp6 4 ,
957addeef82SBruce A. Mah.Xr inet 4 ,
958addeef82SBruce A. Mah.Xr inet6 4 ,
959addeef82SBruce A. Mah.Xr intro 4 ,
960addeef82SBruce A. Mah.Xr ip 4 ,
961addeef82SBruce A. Mah.Xr ip6 4 ,
962addeef82SBruce A. Mah.Xr pim 4
963addeef82SBruce A. Mah.\"
964addeef82SBruce A. Mah.Sh AUTHORS
9655203edcdSRuslan Ermilov.An -nosplit
9665203edcdSRuslan ErmilovThe original multicast code was written by
9675203edcdSRuslan Ermilov.An David Waitzman
9685203edcdSRuslan Ermilov(BBN Labs),
969addeef82SBruce A. Mahand later modified by the following individuals:
9705203edcdSRuslan Ermilov.An Steve Deering
9715203edcdSRuslan Ermilov(Stanford),
9725203edcdSRuslan Ermilov.An Mark J. Steiglitz
9735203edcdSRuslan Ermilov(Stanford),
9745203edcdSRuslan Ermilov.An Van Jacobson
9755203edcdSRuslan Ermilov(LBL),
9765203edcdSRuslan Ermilov.An Ajit Thyagarajan
9775203edcdSRuslan Ermilov(PARC),
9785203edcdSRuslan Ermilov.An Bill Fenner
9795203edcdSRuslan Ermilov(PARC).
980addeef82SBruce A. MahThe IPv6 multicast support was implemented by the KAME project
981ef151d78SRuslan Ermilov.Pq Pa http://www.kame.net ,
982ef151d78SRuslan Ermilovand was based on the IPv4 multicast code.
983addeef82SBruce A. MahThe advanced multicast API and the multicast bandwidth
9845203edcdSRuslan Ermilovmonitoring were implemented by
9855203edcdSRuslan Ermilov.An Pavlin Radoslavov
9865203edcdSRuslan Ermilov(ICSI)
9875203edcdSRuslan Ermilovin collaboration with
9885203edcdSRuslan Ermilov.An Chris Brown
9895203edcdSRuslan Ermilov(NextHop).
990addeef82SBruce A. Mah.Pp
9915203edcdSRuslan ErmilovThis manual page was written by
9925203edcdSRuslan Ermilov.An Pavlin Radoslavov
9935203edcdSRuslan Ermilov(ICSI).
994