1 .\" Copyright (c) 2001-2003 International Computer Science Institute
3 .\" Permission is hereby granted, free of charge, to any person obtaining a
4 .\" copy of this software and associated documentation files (the "Software"),
5 .\" to deal in the Software without restriction, including without limitation
6 .\" the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 .\" and/or sell copies of the Software, and to permit persons to whom the
8 .\" Software is furnished to do so, subject to the following conditions:
10 .\" The above copyright notice and this permission notice shall be included in
11 .\" all copies or substantial portions of the Software.
13 .\" The names and trademarks of copyright holders may not be used in
14 .\" advertising or publicity pertaining to the software without specific
15 .\" prior permission. Title to copyright in this software and any associated
16 .\" documentation will at all times remain with the copyright holders.
18 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 .\" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 .\" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 .\" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 .\" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 .\" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 .\" DEALINGS IN THE SOFTWARE.
26 .\" $FreeBSD: src/share/man/man4/multicast.4,v 1.4 2004/07/09 09:22:36 ru Exp $
27 .\" $NetBSD: multicast.4,v 1.2 2004/09/12 13:06:14 wiz Exp $
38 .Cd "options MROUTING"
43 .In netinet/ip_mroute.h
44 .In netinet6/ip6_mroute.h
46 .Fn getsockopt "int s" IPPROTO_IP MRT_INIT "void *optval" "socklen_t *optlen"
48 .Fn setsockopt "int s" IPPROTO_IP MRT_INIT "const void *optval" "socklen_t optlen"
50 .Fn getsockopt "int s" IPPROTO_IPV6 MRT6_INIT "void *optval" "socklen_t *optlen"
52 .Fn setsockopt "int s" IPPROTO_IPV6 MRT6_INIT "const void *optval" "socklen_t optlen"
54 .Tn "Multicast routing"
55 is used to efficiently propagate data
56 packets to a set of multicast listeners in multipoint networks.
57 If unicast is used to replicate the data to all listeners,
58 then some of the network links may carry multiple copies of the same
60 With multicast routing, the overhead is reduced to one copy
61 (at most) per network link.
63 All multicast-capable routers must run a common multicast routing
65 The Distance Vector Multicast Routing Protocol (DVMRP)
66 was the first developed multicast routing protocol.
67 Later, other protocols such as Multicast Extensions to OSPF (MOSPF),
68 Core Based Trees (CBT),
69 Protocol Independent Multicast - Sparse Mode (PIM-SM),
70 and Protocol Independent Multicast - Dense Mode (PIM-DM)
71 were developed as well.
73 To start multicast routing,
74 the user must enable multicast forwarding in the kernel
77 about the kernel configuration options),
78 and must run a multicast routing capable user-level process.
79 From developer's point of view,
80 the programming guide described in the
81 .Sx "Programming Guide"
82 section should be used to control the multicast forwarding in the kernel.
85 This section provides information about the basic multicast routing API.
87 .Dq advanced multicast API
89 .Sx "Advanced Multicast API Programming Guide"
92 First, a multicast routing socket must be open.
93 That socket would be used
94 to control the multicast forwarding in the kernel.
95 Note that most operations below require certain privilege
96 (i.e., root privilege):
100 mrouter_s4 = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP);
104 mrouter_s6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
107 Note that if the router needs to open an IGMP or ICMPv6 socket
108 (in case of IPv4 and IPv6 respectively)
109 for sending or receiving of IGMP or MLD multicast group membership messages,
114 sockets should be used
115 for sending and receiving respectively IGMP or MLD messages.
118 -derived kernel, it may be possible to open separate sockets
119 for IGMP or MLD messages only.
120 However, some other kernels (e.g.,
122 require that the multicast
123 routing socket must be used for sending and receiving of IGMP or MLD
125 Therefore, for portability reason the multicast
126 routing socket should be reused for IGMP and MLD messages as well.
128 After the multicast routing socket is open, it can be used to enable
129 or disable multicast forwarding in the kernel:
132 int v = 1; /* 1 to enable, or 0 to disable */
133 setsockopt(mrouter_s4, IPPROTO_IP, MRT_INIT, (void *)\*[Am]v, sizeof(v));
137 int v = 1; /* 1 to enable, or 0 to disable */
138 setsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_INIT, (void *)\*[Am]v, sizeof(v));
140 /* If necessary, filter all ICMPv6 messages */
141 struct icmp6_filter filter;
142 ICMP6_FILTER_SETBLOCKALL(\*[Am]filter);
143 setsockopt(mrouter_s6, IPPROTO_ICMPV6, ICMP6_FILTER, (void *)\*[Am]filter,
147 After multicast forwarding is enabled, the multicast routing socket
148 can be used to enable PIM processing in the kernel if we are running PIM-SM or
153 For each network interface (e.g., physical or a virtual tunnel)
154 that would be used for multicast forwarding, a corresponding
155 multicast interface must be added to the kernel:
159 memset(\*[Am]vc, 0, sizeof(vc));
160 /* Assign all vifctl fields as appropriate */
161 vc.vifc_vifi = vif_index;
162 vc.vifc_flags = vif_flags;
163 vc.vifc_threshold = min_ttl_threshold;
164 vc.vifc_rate_limit = max_rate_limit;
165 memcpy(\*[Am]vc.vifc_lcl_addr, \*[Am]vif_local_address, sizeof(vc.vifc_lcl_addr));
166 if (vc.vifc_flags \*[Am] VIFF_TUNNEL)
167 memcpy(\*[Am]vc.vifc_rmt_addr, \*[Am]vif_remote_address,
168 sizeof(vc.vifc_rmt_addr));
169 setsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_VIF, (void *)\*[Am]vc,
175 must be unique per vif.
181 .Aq Pa netinet/ip_mroute.h .
183 .Va min_ttl_threshold
184 contains the minimum TTL a multicast data packet must have to be
185 forwarded on that vif.
186 Typically, it would have value of 1.
189 contains the maximum rate (in bits/s) of the multicast data packets forwarded
191 Value of 0 means no limit.
193 .Va vif_local_address
194 contains the local IP address of the corresponding local interface.
196 .Va vif_remote_address
197 contains the remote IP address in case of DVMRP multicast tunnels.
201 memset(\*[Am]mc, 0, sizeof(mc));
202 /* Assign all mif6ctl fields as appropriate */
203 mc.mif6c_mifi = mif_index;
204 mc.mif6c_flags = mif_flags;
205 mc.mif6c_pifi = pif_index;
206 setsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_ADD_MIF, (void *)\*[Am]mc,
212 must be unique per vif.
218 .Aq Pa netinet6/ip6_mroute.h .
221 is the physical interface index of the corresponding local interface.
223 A multicast interface is deleted by:
226 vifi_t vifi = vif_index;
227 setsockopt(mrouter_s4, IPPROTO_IP, MRT_DEL_VIF, (void *)\*[Am]vifi,
232 mifi_t mifi = mif_index;
233 setsockopt(mrouter_s6, IPPROTO_IPV6, MRT6_DEL_MIF, (void *)\*[Am]mifi,
237 After the multicast forwarding is enabled, and the multicast virtual
239 added, the kernel may deliver upcall messages (also called signals
240 later in this text) on the multicast routing socket that was open
245 The IPv4 upcalls have
248 .Aq Pa netinet/ip_mroute.h )
252 Note that this header follows the structure of
254 with the protocol field
257 The IPv6 upcalls have
260 .Aq Pa netinet6/ip6_mroute.h )
264 Note that this header follows the structure of
266 with the next header field
270 The upcall header contains field
274 with the type of the upcall
278 for IPv4 and IPv6 respectively.
279 The values of the rest of the upcall header fields
280 and the body of the upcall message depend on the particular upcall type.
282 If the upcall message type is
285 .Dv MRT6MSG_NOCACHE ,
286 this is an indication that a multicast packet has reached the multicast
287 router, but the router has no forwarding state for that packet.
288 Typically, the upcall would be a signal for the multicast routing
289 user-level process to install the appropriate Multicast Forwarding
290 Cache (MFC) entry in the kernel.
292 An MFC entry is added by:
296 memset(\*[Am]mc, 0, sizeof(mc));
297 memcpy(\*[Am]mc.mfcc_origin, \*[Am]source_addr, sizeof(mc.mfcc_origin));
298 memcpy(\*[Am]mc.mfcc_mcastgrp, \*[Am]group_addr, sizeof(mc.mfcc_mcastgrp));
299 mc.mfcc_parent = iif_index;
300 for (i = 0; i \*[Lt] maxvifs; i++)
301 mc.mfcc_ttls[i] = oifs_ttl[i];
302 setsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_MFC,
303 (void *)\*[Am]mc, sizeof(mc));
308 memset(\*[Am]mc, 0, sizeof(mc));
309 memcpy(\*[Am]mc.mf6cc_origin, \*[Am]source_addr, sizeof(mc.mf6cc_origin));
310 memcpy(\*[Am]mc.mf6cc_mcastgrp, \*[Am]group_addr, sizeof(mf6cc_mcastgrp));
311 mc.mf6cc_parent = iif_index;
312 for (i = 0; i \*[Lt] maxvifs; i++)
313 if (oifs_ttl[i] \*[Gt] 0)
314 IF_SET(i, \*[Am]mc.mf6cc_ifset);
315 setsockopt(mrouter_s4, IPPROTO_IPV6, MRT6_ADD_MFC,
316 (void *)\*[Am]mc, sizeof(mc));
323 are the source and group address of the multicast packet (as set
324 in the upcall message).
327 is the virtual interface index of the multicast interface the multicast
328 packets for this specific source and group address should be received on.
331 array contains the minimum TTL (per interface) a multicast packet
332 should have to be forwarded on an outgoing interface.
333 If the TTL value is zero, the corresponding interface is not included
334 in the set of outgoing interfaces.
335 Note that in case of IPv6 only the set of outgoing interfaces can
338 An MFC entry is deleted by:
342 memset(\*[Am]mc, 0, sizeof(mc));
343 memcpy(\*[Am]mc.mfcc_origin, \*[Am]source_addr, sizeof(mc.mfcc_origin));
344 memcpy(\*[Am]mc.mfcc_mcastgrp, \*[Am]group_addr, sizeof(mc.mfcc_mcastgrp));
345 setsockopt(mrouter_s4, IPPROTO_IP, MRT_DEL_MFC,
346 (void *)\*[Am]mc, sizeof(mc));
351 memset(\*[Am]mc, 0, sizeof(mc));
352 memcpy(\*[Am]mc.mf6cc_origin, \*[Am]source_addr, sizeof(mc.mf6cc_origin));
353 memcpy(\*[Am]mc.mf6cc_mcastgrp, \*[Am]group_addr, sizeof(mf6cc_mcastgrp));
354 setsockopt(mrouter_s4, IPPROTO_IPV6, MRT6_DEL_MFC,
355 (void *)\*[Am]mc, sizeof(mc));
358 The following method can be used to get various statistics per
359 installed MFC entry in the kernel (e.g., the number of forwarded
360 packets per source and group address):
363 struct sioc_sg_req sgreq;
364 memset(\*[Am]sgreq, 0, sizeof(sgreq));
365 memcpy(\*[Am]sgreq.src, \*[Am]source_addr, sizeof(sgreq.src));
366 memcpy(\*[Am]sgreq.grp, \*[Am]group_addr, sizeof(sgreq.grp));
367 ioctl(mrouter_s4, SIOCGETSGCNT, \*[Am]sgreq);
371 struct sioc_sg_req6 sgreq;
372 memset(\*[Am]sgreq, 0, sizeof(sgreq));
373 memcpy(\*[Am]sgreq.src, \*[Am]source_addr, sizeof(sgreq.src));
374 memcpy(\*[Am]sgreq.grp, \*[Am]group_addr, sizeof(sgreq.grp));
375 ioctl(mrouter_s6, SIOCGETSGCNT_IN6, \*[Am]sgreq);
378 The following method can be used to get various statistics per
379 multicast virtual interface in the kernel (e.g., the number of forwarded
380 packets per interface):
383 struct sioc_vif_req vreq;
384 memset(\*[Am]vreq, 0, sizeof(vreq));
385 vreq.vifi = vif_index;
386 ioctl(mrouter_s4, SIOCGETVIFCNT, \*[Am]vreq);
390 struct sioc_mif_req6 mreq;
391 memset(\*[Am]mreq, 0, sizeof(mreq));
392 mreq.mifi = vif_index;
393 ioctl(mrouter_s6, SIOCGETMIFCNT_IN6, \*[Am]mreq);
395 .Ss Advanced Multicast API Programming Guide
396 If we want to add new features in the kernel, it becomes difficult
397 to preserve backward compatibility (binary and API),
398 and at the same time to allow user-level processes to take advantage of
399 the new features (if the kernel supports them).
401 One of the mechanisms that allows us to preserve the backward
402 compatibility is a sort of negotiation
403 between the user-level process and the kernel:
406 The user-level process tries to enable in the kernel the set of new
407 features (and the corresponding API) it would like to use.
409 The kernel returns the (sub)set of features it knows about
410 and is willing to be enabled.
412 The user-level process uses only that set of features
413 the kernel has agreed on.
417 To support backward compatibility, if the user-level process does not
418 ask for any new features, the kernel defaults to the basic
419 multicast API (see the
420 .Sx "Programming Guide"
422 .\" XXX: edit as appropriate after the advanced multicast API is
423 .\" supported under IPv6
424 Currently, the advanced multicast API exists only for IPv4;
425 in the future there will be IPv6 support as well.
427 Below is a summary of the expandable API solution.
428 Note that all new options and structures are defined
430 .Aq Pa netinet/ip_mroute.h
432 .Aq Pa netinet6/ip6_mroute.h ,
433 unless stated otherwise.
435 The user-level process uses new
436 .Fn getsockopt Ns / Ns Fn setsockopt
438 perform the API features negotiation with the kernel.
439 This negotiation must be performed right after the multicast routing
441 The set of desired/allowed features is stored in a bitset
444 i.e., maximum of 32 new features).
446 .Fn getsockopt Ns / Ns Fn setsockopt
454 getsockopt(sock, IPPROTO_IP, MRT_API_SUPPORT, (void *)\*[Am]v, sizeof(v));
459 the pre-defined bits that the kernel API supports.
460 The eight least significant bits in
467 as part of the new definition of
469 (see below about those flags), which leaves 24 flags for other new features.
470 The value returned by
471 .Fn getsockopt MRT_API_SUPPORT
472 is read-only; in other words,
473 .Fn setsockopt MRT_API_SUPPORT
476 To modify the API, and to set some specific feature in the kernel, then:
478 uint32_t v = MRT_MFC_FLAGS_DISABLE_WRONGVIF;
479 if (setsockopt(sock, IPPROTO_IP, MRT_API_CONFIG, (void *)\*[Am]v, sizeof(v))
483 if (v \*[Am] MRT_MFC_FLAGS_DISABLE_WRONGVIF)
484 return (OK); /* Success */
490 .Fn setsockopt MRT_API_CONFIG
492 argument to it specifies the desired set of features to
493 be enabled in the API and the kernel.
496 is the actual (sub)set of features that were enabled in the kernel.
497 To obtain later the same set of features that were enabled, then:
499 getsockopt(sock, IPPROTO_IP, MRT_API_CONFIG, (void *)\*[Am]v, sizeof(v));
502 The set of enabled features is global.
504 .Fn setsockopt MRT_API_CONFIG
505 should be called right after
506 .Fn setsockopt MRT_INIT .
508 Currently, the following set of new features is defined:
510 #define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 \*[Lt]\*[Lt] 0) /* disable WRONGVIF signals */
511 #define MRT_MFC_FLAGS_BORDER_VIF (1 \*[Lt]\*[Lt] 1) /* border vif */
512 #define MRT_MFC_RP (1 \*[Lt]\*[Lt] 8) /* enable RP address */
513 #define MRT_MFC_BW_UPCALL (1 \*[Lt]\*[Lt] 9) /* enable bw upcalls */
516 .\" In the future there might be:
518 .\" #define MRT_MFC_GROUP_SPECIFIC (1 \*[Lt]\*[Lt] 10) /* allow (*,G) MFC entries */
521 .\" to allow (*,G) MFC entries (i.e., group-specific entries) in the kernel.
522 .\" For now this is left-out until it is clear whether
523 .\" (*,G) MFC support is the preferred solution instead of something more generic
524 .\" solution for example.
526 .\" 2. The newly defined struct mfcctl2.
529 The advanced multicast API uses a newly defined
531 instead of the traditional
532 .Vt "struct mfcctl" .
541 * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays
542 * and extends the old struct mfcctl.
545 /* the mfcctl fields */
546 struct in_addr mfcc_origin; /* ip origin of mcasts */
547 struct in_addr mfcc_mcastgrp; /* multicast group associated*/
548 vifi_t mfcc_parent; /* incoming vif */
549 u_char mfcc_ttls[MAXVIFS];/* forwarding ttls on vifs */
551 /* extension fields */
552 uint8_t mfcc_flags[MAXVIFS];/* the MRT_MFC_FLAGS_* flags*/
553 struct in_addr mfcc_rp; /* the RP address */
558 .Va mfcc_flags[MAXVIFS]
561 Note that for compatibility reasons they are added at the end.
564 .Va mfcc_flags[MAXVIFS]
565 field is used to set various flags per
566 interface per (S,G) entry.
567 Currently, the defined flags are:
569 #define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 \*[Lt]\*[Lt] 0) /* disable WRONGVIF signals */
570 #define MRT_MFC_FLAGS_BORDER_VIF (1 \*[Lt]\*[Lt] 1) /* border vif */
574 .Dv MRT_MFC_FLAGS_DISABLE_WRONGVIF
575 flag is used to explicitly disable the
577 kernel signal at the (S,G) granularity if a multicast data packet
578 arrives on the wrong interface.
579 Usually, this signal is used to
580 complete the shortest-path switch in case of PIM-SM multicast routing,
581 or to trigger a PIM assert message.
582 However, it should not be delivered for interfaces that are not in
583 the outgoing interface set, and that are not expecting to
584 become an incoming interface.
586 .Dv MRT_MFC_FLAGS_DISABLE_WRONGVIF
587 flag is set for some of the
588 interfaces, then a data packet that arrives on that interface for
589 that MFC entry will NOT trigger a WRONGVIF signal.
590 If that flag is not set, then a signal is triggered (the default action).
593 .Dv MRT_MFC_FLAGS_BORDER_VIF
594 flag is used to specify whether the Border-bit in PIM
595 Register messages should be set (in case when the Register encapsulation
596 is performed inside the kernel).
597 If it is set for the special PIM Register kernel virtual interface
600 the Border-bit in the Register messages sent to the RP will be set.
602 The remaining six bits are reserved for future usage.
606 field is used to specify the RP address (in case of PIM-SM multicast routing)
608 group G if we want to perform kernel-level PIM Register encapsulation.
611 field is used only if the
613 advanced API flag/capability has been successfully set by
614 .Fn setsockopt MRT_API_CONFIG .
617 .\" 3. Kernel-level PIM Register encapsulation
621 flag was successfully set by
622 .Fn setsockopt MRT_API_CONFIG ,
623 then the kernel will attempt to perform
624 the PIM Register encapsulation itself instead of sending the
625 multicast data packets to user level (inside
627 upcalls) for user-level encapsulation.
628 The RP address would be taken from the
632 .Vt "struct mfcctl2" .
635 flag was successfully set, if the
640 kernel will still deliver an
643 multicast data packet to the user-level process.
645 In addition, if the multicast data packet is too large to fit within
646 a single IP packet after the PIM Register encapsulation (e.g., if
647 its size was on the order of 65500 bytes), the data packet will be
648 fragmented, and then each of the fragments will be encapsulated
650 Note that typically a multicast data packet can be that
651 large only if it was originated locally from the same hosts that
652 performs the encapsulation; otherwise the transmission of the
653 multicast data packet over Ethernet for example would have
654 fragmented it into much smaller pieces.
656 .\" Note that if this code is ported to IPv6, we may need the kernel to
657 .\" perform MTU discovery to the RP, and keep those discoveries inside
658 .\" the kernel so the encapsulating router may send back ICMP
659 .\" Fragmentation Required if the size of the multicast data packet is
660 .\" too large (see "Encapsulating data packets in the Register Tunnel"
661 .\" in Section 4.4.1 in the PIM-SM spec
662 .\" draft-ietf-pim-sm-v2-new-05.{txt,ps}).
663 .\" For IPv4 we may be able to get away without it, but for IPv6 we need
666 .\" 4. Mechanism for "multicast bandwidth monitoring and upcalls".
669 Typically, a multicast routing user-level process would need to know the
670 forwarding bandwidth for some data flow.
671 For example, the multicast routing process may want to timeout idle MFC
672 entries, or in case of PIM-SM it can initiate (S,G) shortest-path switch if
673 the bandwidth rate is above a threshold for example.
675 The original solution for measuring the bandwidth of a dataflow was
676 that a user-level process would periodically
677 query the kernel about the number of forwarded packets/bytes per
678 (S,G), and then based on those numbers it would estimate whether a source
679 has been idle, or whether the source's transmission bandwidth is above a
681 That solution is far from being scalable, hence the need for a new
682 mechanism for bandwidth monitoring.
684 Below is a description of the bandwidth monitoring mechanism.
687 If the bandwidth of a data flow satisfies some pre-defined filter,
688 the kernel delivers an upcall on the multicast routing socket
689 to the multicast routing process that has installed that filter.
691 The bandwidth-upcall filters are installed per (S,G).
693 more than one filter per (S,G).
695 Instead of supporting all possible comparison operations
696 (i.e., \*[Lt] \*[Lt]= == != \*[Gt] \*[Gt]= ), there is support only for the
697 \*[Lt]= and \*[Gt]= operations,
698 because this makes the kernel-level implementation simpler,
699 and because practically we need only those two.
700 Further, the missing operations can be simulated by secondary
701 user-level filtering of those \*[Lt]= and \*[Gt]= filters.
702 For example, to simulate !=, then we need to install filter
703 .Dq bw \*[Lt]= 0xffffffff ,
705 upcall is received, we need to check whether
706 .Dq measured_bw != expected_bw .
708 The bandwidth-upcall mechanism is enabled by
709 .Fn setsockopt MRT_API_CONFIG
711 .Dv MRT_MFC_BW_UPCALL
714 The bandwidth-upcall filters are added/deleted by the new
715 .Fn setsockopt MRT_ADD_BW_UPCALL
717 .Fn setsockopt MRT_DEL_BW_UPCALL
718 respectively (with the appropriate
719 .Vt "struct bw_upcall"
723 From application point of view, a developer needs to know about
727 * Structure for installing or delivering an upcall if the
728 * measured bandwidth is above or below a threshold.
730 * User programs (e.g. daemons) may have a need to know when the
731 * bandwidth used by some data flow is above or below some threshold.
732 * This interface allows the userland to specify the threshold (in
733 * bytes and/or packets) and the measurement interval. Flows are
734 * all packet with the same source and destination IP address.
735 * At the moment the code is only used for multicast destinations
736 * but there is nothing that prevents its use for unicast.
738 * The measurement interval cannot be shorter than some Tmin (currently, 3s).
739 * The threshold is set in packets and/or bytes per_interval.
741 * Measurement works as follows:
743 * For \*[Gt]= measurements:
744 * The first packet marks the start of a measurement interval.
745 * During an interval we count packets and bytes, and when we
746 * pass the threshold we deliver an upcall and we are done.
747 * The first packet after the end of the interval resets the
748 * count and restarts the measurement.
750 * For \*[Lt]= measurement:
751 * We start a timer to fire at the end of the interval, and
752 * then for each incoming packet we count packets and bytes.
753 * When the timer fires, we compare the value with the threshold,
754 * schedule an upcall if we are below, and restart the measurement
755 * (reschedule timer and zero counters).
759 struct timeval b_time;
765 struct in_addr bu_src; /* source address */
766 struct in_addr bu_dst; /* destination address */
767 uint32_t bu_flags; /* misc flags (see below) */
768 #define BW_UPCALL_UNIT_PACKETS (1 \*[Lt]\*[Lt] 0) /* threshold (in packets) */
769 #define BW_UPCALL_UNIT_BYTES (1 \*[Lt]\*[Lt] 1) /* threshold (in bytes) */
770 #define BW_UPCALL_GEQ (1 \*[Lt]\*[Lt] 2) /* upcall if bw \*[Gt]= threshold */
771 #define BW_UPCALL_LEQ (1 \*[Lt]\*[Lt] 3) /* upcall if bw \*[Lt]= threshold */
772 #define BW_UPCALL_DELETE_ALL (1 \*[Lt]\*[Lt] 4) /* delete all upcalls for s,d*/
773 struct bw_data bu_threshold; /* the bw threshold */
774 struct bw_data bu_measured; /* the measured bw */
777 /* max. number of upcalls to deliver together */
778 #define BW_UPCALLS_MAX 128
779 /* min. threshold time interval for bandwidth measurement */
780 #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC 3
781 #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC 0
786 structure is used as an argument to
787 .Fn setsockopt MRT_ADD_BW_UPCALL
789 .Fn setsockopt MRT_DEL_BW_UPCALL .
791 .Fn setsockopt MRT_ADD_BW_UPCALL
792 installs a filter in the kernel
793 for the source and destination address in the
796 and that filter will trigger an upcall according to the following
799 if (bw_upcall_oper IS "\*[Gt]=") {
800 if (((bw_upcall_unit \*[Am] PACKETS == PACKETS) \*[Am]\*[Am]
801 (measured_packets \*[Gt]= threshold_packets)) ||
802 ((bw_upcall_unit \*[Am] BYTES == BYTES) \*[Am]\*[Am]
803 (measured_bytes \*[Gt]= threshold_bytes)))
804 SEND_UPCALL("measured bandwidth is \*[Gt]= threshold");
806 if (bw_upcall_oper IS "\*[Lt]=" \*[Am]\*[Am] measured_interval \*[Gt]= threshold_interval) {
807 if (((bw_upcall_unit \*[Am] PACKETS == PACKETS) \*[Am]\*[Am]
808 (measured_packets \*[Lt]= threshold_packets)) ||
809 ((bw_upcall_unit \*[Am] BYTES == BYTES) \*[Am]\*[Am]
810 (measured_bytes \*[Lt]= threshold_bytes)))
811 SEND_UPCALL("measured bandwidth is \*[Lt]= threshold");
817 the unit can be specified in both BYTES and PACKETS.
818 However, the GEQ and LEQ flags are mutually exclusive.
820 Basically, an upcall is delivered if the measured bandwidth is \*[Gt]= or
821 \*[Lt]= the threshold bandwidth (within the specified measurement
823 For practical reasons, the smallest value for the measurement
824 interval is 3 seconds.
825 If smaller values are allowed, then the bandwidth
826 estimation may be less accurate, or the potentially very high frequency
827 of the generated upcalls may introduce too much overhead.
828 For the \*[Gt]= operation, the answer may be known before the end of
829 .Va threshold_interval ,
830 therefore the upcall may be delivered earlier.
831 For the \*[Lt]= operation however, we must wait
832 until the threshold interval has expired to know the answer.
836 struct bw_upcall bw_upcall;
837 /* Assign all bw_upcall fields as appropriate */
838 memset(\*[Am]bw_upcall, 0, sizeof(bw_upcall));
839 memcpy(\*[Am]bw_upcall.bu_src, \*[Am]source, sizeof(bw_upcall.bu_src));
840 memcpy(\*[Am]bw_upcall.bu_dst, \*[Am]group, sizeof(bw_upcall.bu_dst));
841 bw_upcall.bu_threshold.b_data = threshold_interval;
842 bw_upcall.bu_threshold.b_packets = threshold_packets;
843 bw_upcall.bu_threshold.b_bytes = threshold_bytes;
844 if (is_threshold_in_packets)
845 bw_upcall.bu_flags |= BW_UPCALL_UNIT_PACKETS;
846 if (is_threshold_in_bytes)
847 bw_upcall.bu_flags |= BW_UPCALL_UNIT_BYTES;
850 bw_upcall.bu_flags |= BW_UPCALL_GEQ;
854 bw_upcall.bu_flags |= BW_UPCALL_LEQ;
859 setsockopt(mrouter_s4, IPPROTO_IP, MRT_ADD_BW_UPCALL,
860 (void *)\*[Am]bw_upcall, sizeof(bw_upcall));
863 To delete a single filter, then use
864 .Dv MRT_DEL_BW_UPCALL ,
865 and the fields of bw_upcall must be set
867 .Dv MRT_ADD_BW_UPCALL
870 To delete all bandwidth filters for a given (S,G), then
876 .Vt "struct bw_upcall"
877 need to be set, and then just set only the
878 .Dv BW_UPCALL_DELETE_ALL
880 .Va bw_upcall.bu_flags .
882 The bandwidth upcalls are received by aggregating them in the new upcall
885 #define IGMPMSG_BW_UPCALL 4 /* BW monitoring upcall */
888 This message is an array of
889 .Vt "struct bw_upcall"
894 delivered when there are 128 pending upcalls, or when 1 second has
895 expired since the previous upcall (whichever comes first).
900 field is filled-in to
901 indicate the particular measured values.
902 However, because of the way
903 the particular intervals are measured, the user should be careful how
904 .Va bu_measured.b_time
907 filter is installed to trigger an upcall if the number of packets
910 may have a value of zero in the upcalls after the
911 first one, because the measured interval for \*[Gt]= filters is
913 by the forwarded packets.
914 Hence, this upcall mechanism should not be used for measuring
915 the exact value of the bandwidth of the forwarded data.
916 To measure the exact bandwidth, the user would need to
917 get the forwarded packets statistics with the
918 .Fn ioctl SIOCGETSGCNT
921 .Sx Programming Guide
924 Note that the upcalls for a filter are delivered until the specific
925 filter is deleted, but no more frequently than once per
926 .Va bu_threshold.b_time .
927 For example, if the filter is specified to
928 deliver a signal if bw \*[Gt]= 1 packet, the first packet will trigger a
929 signal, but the next upcall will be triggered no earlier than
930 .Va bu_threshold.b_time
931 after the previous upcall.
949 The original multicast code was written by
952 and later modified by the following individuals:
955 .An Mark J. Steiglitz
963 The IPv6 multicast support was implemented by the KAME project
964 .Pq Pa http://www.kame.net ,
965 and was based on the IPv4 multicast code.
966 The advanced multicast API and the multicast bandwidth
967 monitoring were implemented by
968 .An Pavlin Radoslavov
970 in collaboration with
974 This manual page was written by
975 .An Pavlin Radoslavov