forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpim_igmpv3.c
2026 lines (1679 loc) · 55 KB
/
pim_igmpv3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* PIM for Quagga
* Copyright (C) 2008 Everton da Silva Marques
*/
#include <zebra.h>
#include "log.h"
#include "memory.h"
#include "if.h"
#include "lib_errors.h"
#include "pimd.h"
#include "pim_instance.h"
#include "pim_iface.h"
#include "pim_igmp.h"
#include "pim_igmpv3.h"
#include "pim_str.h"
#include "pim_util.h"
#include "pim_time.h"
#include "pim_zebra.h"
#include "pim_oil.h"
#include "pim_ssm.h"
static void group_retransmit_timer_on(struct gm_group *group);
static long igmp_group_timer_remain_msec(struct gm_group *group);
static long igmp_source_timer_remain_msec(struct gm_source *source);
static void group_query_send(struct gm_group *group);
static void source_query_send_by_flag(struct gm_group *group,
int num_sources_tosend);
static void on_trace(const char *label, struct interface *ifp,
struct in_addr from, struct in_addr group_addr,
int num_sources, struct in_addr *sources)
{
if (PIM_DEBUG_GM_TRACE) {
char from_str[INET_ADDRSTRLEN];
char group_str[INET_ADDRSTRLEN];
pim_inet4_dump("<from?>", from, from_str, sizeof(from_str));
pim_inet4_dump("<group?>", group_addr, group_str,
sizeof(group_str));
zlog_debug("%s: from %s on %s: group=%s sources=%d", label,
from_str, ifp->name, group_str, num_sources);
}
}
static inline long igmp_gmi_msec(struct gm_group *group)
{
struct pim_interface *pim_ifp = group->interface->info;
struct gm_sock *igmp;
struct listnode *sock_node;
long qrv = 0, qqi = 0;
for (ALL_LIST_ELEMENTS_RO(pim_ifp->gm_socket_list, sock_node, igmp)) {
qrv = MAX(qrv, igmp->querier_robustness_variable);
qqi = MAX(qqi, igmp->querier_query_interval);
}
return PIM_IGMP_GMI_MSEC(qrv, qqi,
pim_ifp->gm_query_max_response_time_dsec);
}
void igmp_group_reset_gmi(struct gm_group *group)
{
long group_membership_interval_msec;
struct interface *ifp;
ifp = group->interface;
/*
RFC 3376: 8.4. Group Membership Interval
The Group Membership Interval is the amount of time that must pass
before a multicast router decides there are no more members of a
group or a particular source on a network.
This value MUST be ((the Robustness Variable) times (the Query
Interval)) plus (one Query Response Interval).
group_membership_interval_msec = querier_robustness_variable *
(1000 * querier_query_interval) +
100 * query_response_interval_dsec;
*/
group_membership_interval_msec = igmp_gmi_msec(group);
if (PIM_DEBUG_GM_TRACE) {
char group_str[INET_ADDRSTRLEN];
pim_inet4_dump("<group?>", group->group_addr, group_str,
sizeof(group_str));
zlog_debug(
"Resetting group %s timer to GMI=%ld.%03ld sec on %s",
group_str, group_membership_interval_msec / 1000,
group_membership_interval_msec % 1000, ifp->name);
}
/*
RFC 3376: 6.2.2. Definition of Group Timers
The group timer is only used when a group is in EXCLUDE mode and
it represents the time for the *filter-mode* of the group to
expire and switch to INCLUDE mode.
*/
assert(group->group_filtermode_isexcl);
igmp_group_timer_on(group, group_membership_interval_msec, ifp->name);
}
static void igmp_source_timer(struct event *t)
{
struct gm_source *source;
struct gm_group *group;
source = EVENT_ARG(t);
group = source->source_group;
if (PIM_DEBUG_GM_TRACE) {
char group_str[INET_ADDRSTRLEN];
char source_str[INET_ADDRSTRLEN];
pim_inet4_dump("<group?>", group->group_addr, group_str,
sizeof(group_str));
pim_inet4_dump("<source?>", source->source_addr, source_str,
sizeof(source_str));
zlog_debug(
"%s: Source timer expired for group %s source %s on %s",
__func__, group_str, source_str,
group->interface->name);
}
/*
RFC 3376: 6.3. IGMPv3 Source-Specific Forwarding Rules
Group
Filter-Mode Source Timer Value Action
----------- ------------------ ------
INCLUDE TIMER == 0 Suggest to stop forwarding
traffic from source and
remove source record. If
there are no more source
records for the group, delete
group record.
EXCLUDE TIMER == 0 Suggest to not forward
traffic from source
(DO NOT remove record)
Source timer switched from (T > 0) to (T == 0): disable forwarding.
*/
if (group->group_filtermode_isexcl) {
/* EXCLUDE mode */
igmp_source_forward_stop(source);
} else {
/* INCLUDE mode */
/* igmp_source_delete() will stop forwarding source */
igmp_source_delete(source);
/*
If there are no more source records for the group, delete
group
record.
*/
if (!listcount(group->group_source_list)) {
igmp_group_delete_empty_include(group);
}
}
}
static void source_timer_off(struct gm_group *group, struct gm_source *source)
{
if (!source->t_source_timer)
return;
if (PIM_DEBUG_GM_TRACE) {
char group_str[INET_ADDRSTRLEN];
char source_str[INET_ADDRSTRLEN];
pim_inet4_dump("<group?>", group->group_addr, group_str,
sizeof(group_str));
pim_inet4_dump("<source?>", source->source_addr, source_str,
sizeof(source_str));
zlog_debug(
"Cancelling TIMER event for group %s source %s on %s",
group_str, source_str, group->interface->name);
}
EVENT_OFF(source->t_source_timer);
}
static void igmp_source_timer_on(struct gm_group *group,
struct gm_source *source, long interval_msec)
{
source_timer_off(group, source);
struct pim_interface *pim_ifp = group->interface->info;
if (PIM_DEBUG_GM_EVENTS) {
char group_str[INET_ADDRSTRLEN];
char source_str[INET_ADDRSTRLEN];
pim_inet4_dump("<group?>", group->group_addr, group_str,
sizeof(group_str));
pim_inet4_dump("<source?>", source->source_addr, source_str,
sizeof(source_str));
zlog_debug(
"Scheduling %ld.%03ld sec TIMER event for group %s source %s on %s",
interval_msec / 1000, interval_msec % 1000, group_str,
source_str, group->interface->name);
}
event_add_timer_msec(router->master, igmp_source_timer, source,
interval_msec, &source->t_source_timer);
/*
RFC 3376: 6.3. IGMPv3 Source-Specific Forwarding Rules
Source timer switched from (T == 0) to (T > 0): enable forwarding.
*/
igmp_source_forward_start(pim_ifp->pim, source);
}
void igmp_source_reset_gmi(struct gm_group *group, struct gm_source *source)
{
long group_membership_interval_msec;
struct interface *ifp;
ifp = group->interface;
group_membership_interval_msec = igmp_gmi_msec(group);
if (PIM_DEBUG_GM_TRACE) {
char group_str[INET_ADDRSTRLEN];
char source_str[INET_ADDRSTRLEN];
pim_inet4_dump("<group?>", group->group_addr, group_str,
sizeof(group_str));
pim_inet4_dump("<source?>", source->source_addr, source_str,
sizeof(source_str));
zlog_debug(
"Resetting source %s timer to GMI=%ld.%03ld sec for group %s on %s",
source_str, group_membership_interval_msec / 1000,
group_membership_interval_msec % 1000, group_str,
ifp->name);
}
igmp_source_timer_on(group, source, group_membership_interval_msec);
}
static void source_mark_delete_flag(struct gm_group *group)
{
struct listnode *src_node;
struct gm_source *src;
for (ALL_LIST_ELEMENTS_RO(group->group_source_list, src_node, src)) {
IGMP_SOURCE_DO_DELETE(src->source_flags);
}
}
static void source_mark_send_flag(struct gm_group *group)
{
struct listnode *src_node;
struct gm_source *src;
for (ALL_LIST_ELEMENTS_RO(group->group_source_list, src_node, src)) {
IGMP_SOURCE_DO_SEND(src->source_flags);
}
}
static int source_mark_send_flag_by_timer(struct gm_group *group)
{
struct listnode *src_node;
struct gm_source *src;
int num_marked_sources = 0;
for (ALL_LIST_ELEMENTS_RO(group->group_source_list, src_node, src)) {
/* Is source timer running? */
if (src->t_source_timer) {
IGMP_SOURCE_DO_SEND(src->source_flags);
++num_marked_sources;
} else {
IGMP_SOURCE_DONT_SEND(src->source_flags);
}
}
return num_marked_sources;
}
static void source_clear_send_flag(struct list *source_list)
{
struct listnode *src_node;
struct gm_source *src;
for (ALL_LIST_ELEMENTS_RO(source_list, src_node, src)) {
IGMP_SOURCE_DONT_SEND(src->source_flags);
}
}
/*
Any source (*,G) is forwarded only if mode is EXCLUDE {empty}
*/
static void group_exclude_fwd_anysrc_ifempty(struct gm_group *group)
{
struct pim_interface *pim_ifp = group->interface->info;
assert(group->group_filtermode_isexcl);
if (listcount(group->group_source_list) < 1) {
igmp_anysource_forward_start(pim_ifp->pim, group);
}
}
void igmp_source_free(struct gm_source *source)
{
/* make sure there is no source timer running */
assert(!source->t_source_timer);
XFREE(MTYPE_PIM_IGMP_GROUP_SOURCE, source);
}
/*
igmp_source_delete: stop forwarding, and delete the source
igmp_source_forward_stop: stop forwarding, but keep the source
*/
void igmp_source_delete(struct gm_source *source)
{
struct gm_group *group;
struct in_addr src;
group = source->source_group;
if (PIM_DEBUG_GM_TRACE) {
char group_str[INET_ADDRSTRLEN];
char source_str[INET_ADDRSTRLEN];
pim_inet4_dump("<group?>", group->group_addr, group_str,
sizeof(group_str));
pim_inet4_dump("<source?>", source->source_addr, source_str,
sizeof(source_str));
zlog_debug(
"Deleting IGMP source %s for group %s from interface %s c_oil ref_count %d",
source_str, group_str, group->interface->name,
source->source_channel_oil
? source->source_channel_oil->oil_ref_count
: 0);
}
source_timer_off(group, source);
igmp_source_forward_stop(source);
source->source_channel_oil = NULL;
/* sanity check that forwarding has been disabled */
if (IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) {
char group_str[INET_ADDRSTRLEN];
char source_str[INET_ADDRSTRLEN];
pim_inet4_dump("<group?>", group->group_addr, group_str,
sizeof(group_str));
pim_inet4_dump("<source?>", source->source_addr, source_str,
sizeof(source_str));
zlog_warn(
"%s: forwarding=ON(!) IGMP source %s for group %s from interface %s",
__func__, source_str, group_str,
group->interface->name);
/* warning only */
}
/*
notice that listnode_delete() can't be moved
into igmp_source_free() because the later is
called by list_delete_all_node()
*/
listnode_delete(group->group_source_list, source);
src.s_addr = source->source_addr.s_addr;
igmp_source_free(source);
/* Group source list is empty and current source is * then
*,G group going away so do not trigger start */
if (group->group_filtermode_isexcl
&& (listcount(group->group_source_list) != 0)
&& src.s_addr != INADDR_ANY) {
group_exclude_fwd_anysrc_ifempty(group);
}
}
static void source_delete_by_flag(struct list *source_list)
{
struct listnode *src_node;
struct listnode *src_nextnode;
struct gm_source *src;
for (ALL_LIST_ELEMENTS(source_list, src_node, src_nextnode, src))
if (IGMP_SOURCE_TEST_DELETE(src->source_flags))
igmp_source_delete(src);
}
void igmp_source_delete_expired(struct list *source_list)
{
struct listnode *src_node;
struct listnode *src_nextnode;
struct gm_source *src;
for (ALL_LIST_ELEMENTS(source_list, src_node, src_nextnode, src))
if (!src->t_source_timer)
igmp_source_delete(src);
}
struct gm_source *igmp_find_source_by_addr(struct gm_group *group,
struct in_addr src_addr)
{
struct listnode *src_node;
struct gm_source *src;
for (ALL_LIST_ELEMENTS_RO(group->group_source_list, src_node, src))
if (src_addr.s_addr == src->source_addr.s_addr)
return src;
return 0;
}
struct gm_source *igmp_get_source_by_addr(struct gm_group *group,
struct in_addr src_addr, bool *new)
{
struct gm_source *src;
if (new)
*new = false;
src = igmp_find_source_by_addr(group, src_addr);
if (src)
return src;
if (PIM_DEBUG_GM_TRACE) {
char group_str[INET_ADDRSTRLEN];
char source_str[INET_ADDRSTRLEN];
pim_inet4_dump("<group?>", group->group_addr, group_str,
sizeof(group_str));
pim_inet4_dump("<source?>", src_addr, source_str,
sizeof(source_str));
zlog_debug(
"Creating new IGMP source %s for group %s on interface %s",
source_str, group_str, group->interface->name);
}
src = XCALLOC(MTYPE_PIM_IGMP_GROUP_SOURCE, sizeof(*src));
if (new)
*new = true;
src->t_source_timer = NULL;
src->source_group = group; /* back pointer */
src->source_addr = src_addr;
src->source_creation = pim_time_monotonic_sec();
src->source_flags = 0;
src->source_query_retransmit_count = 0;
src->source_channel_oil = NULL;
listnode_add(group->group_source_list, src);
return src;
}
static void allow(struct gm_sock *igmp, struct in_addr from,
struct in_addr group_addr, int num_sources,
struct in_addr *sources)
{
struct gm_source *source;
struct gm_group *group;
int i;
if (num_sources == 0) {
/*
RFC 3376: 3.1. Socket-State
If the requested filter mode is INCLUDE *and* the requested
source list is empty, then the entry corresponding to the
requested interface and multicast address is deleted if
present. If no such entry is present, the request is ignored.
So, deleting the group present.
*/
group = find_group_by_addr(igmp, group_addr);
if (!group) {
return;
}
if (group->group_filtermode_isexcl) {
if (listcount(group->group_source_list) == 1) {
struct in_addr star = {.s_addr = INADDR_ANY};
source = igmp_find_source_by_addr(group, star);
if (source)
igmp_source_reset_gmi(group, source);
}
} else {
igmp_group_delete(group);
}
return;
}
/* non-existent group is created as INCLUDE {empty} */
group = igmp_add_group_by_addr(igmp, group_addr);
if (!group) {
return;
}
/* scan received sources */
for (i = 0; i < num_sources; ++i) {
struct in_addr *src_addr;
src_addr = sources + i;
source = igmp_get_source_by_addr(group, *src_addr, NULL);
if (!source)
continue;
/*
RFC 3376: 6.4.1. Reception of Current-State Records
When receiving IS_IN reports for groups in EXCLUDE mode is
sources should be moved from set with (timers = 0) to set with
(timers > 0).
igmp_source_reset_gmi() below, resetting the source timers to
GMI, accomplishes this.
*/
igmp_source_reset_gmi(group, source);
} /* scan received sources */
}
void igmpv3_report_isin(struct gm_sock *igmp, struct in_addr from,
struct in_addr group_addr, int num_sources,
struct in_addr *sources)
{
on_trace(__func__, igmp->interface, from, group_addr, num_sources,
sources);
allow(igmp, from, group_addr, num_sources, sources);
}
static void isex_excl(struct gm_group *group, int num_sources,
struct in_addr *sources)
{
struct gm_source *source;
int i;
/* EXCLUDE mode */
assert(group->group_filtermode_isexcl);
/* E.1: set deletion flag for known sources (X,Y) */
source_mark_delete_flag(group);
/* scan received sources (A) */
for (i = 0; i < num_sources; ++i) {
struct in_addr *src_addr;
bool new;
src_addr = sources + i;
/* E.2: lookup reported source from (A) in (X,Y) */
source = igmp_get_source_by_addr(group, *src_addr, &new);
if (!source)
continue;
if (!new) {
/* E.3: if found, clear deletion flag: (X*A) or (Y*A) */
IGMP_SOURCE_DONT_DELETE(source->source_flags);
} else {
/* E.4: if not found, create source with timer=GMI:
* (A-X-Y) */
assert(!source->t_source_timer); /* timer == 0 */
igmp_source_reset_gmi(group, source);
assert(source->t_source_timer); /* (A-X-Y) timer > 0 */
}
} /* scan received sources */
/*
* If we are in isexcl mode and num_sources == 0
* than that means we have a *,g entry that
* needs to be handled
*/
if (group->group_filtermode_isexcl && num_sources == 0) {
struct in_addr star = {.s_addr = INADDR_ANY};
source = igmp_find_source_by_addr(group, star);
if (source) {
IGMP_SOURCE_DONT_DELETE(source->source_flags);
igmp_source_reset_gmi(group, source);
}
}
/* E.5: delete all sources marked with deletion flag: (X-A) and (Y-A) */
source_delete_by_flag(group->group_source_list);
}
static void isex_incl(struct gm_group *group, int num_sources,
struct in_addr *sources)
{
int i;
/* INCLUDE mode */
assert(!group->group_filtermode_isexcl);
/* I.1: set deletion flag for known sources (A) */
source_mark_delete_flag(group);
/* scan received sources (B) */
for (i = 0; i < num_sources; ++i) {
struct gm_source *source;
struct in_addr *src_addr;
bool new;
src_addr = sources + i;
/* I.2: lookup reported source (B) */
source = igmp_get_source_by_addr(group, *src_addr, &new);
if (!source)
continue;
if (!new) {
/* I.3: if found, clear deletion flag (A*B) */
IGMP_SOURCE_DONT_DELETE(source->source_flags);
} else {
/* I.4: if not found, create source with timer=0 (B-A)
*/
assert(!source->t_source_timer); /* (B-A) timer=0 */
}
} /* scan received sources */
/* I.5: delete all sources marked with deletion flag (A-B) */
source_delete_by_flag(group->group_source_list);
group->group_filtermode_isexcl = 1; /* boolean=true */
assert(group->group_filtermode_isexcl);
group_exclude_fwd_anysrc_ifempty(group);
}
void igmpv3_report_isex(struct gm_sock *igmp, struct in_addr from,
struct in_addr group_addr, int num_sources,
struct in_addr *sources, int from_igmp_v2_report)
{
struct interface *ifp = igmp->interface;
struct gm_group *group;
on_trace(__func__, ifp, from, group_addr, num_sources, sources);
if (pim_is_group_filtered(ifp->info, &group_addr))
return;
/* non-existent group is created as INCLUDE {empty} */
group = igmp_add_group_by_addr(igmp, group_addr);
if (!group) {
return;
}
/* So we can display how we learned the group in our show command output
*/
if (from_igmp_v2_report)
group->igmp_version = 2;
if (group->group_filtermode_isexcl) {
/* EXCLUDE mode */
isex_excl(group, num_sources, sources);
} else {
/* INCLUDE mode */
isex_incl(group, num_sources, sources);
assert(group->group_filtermode_isexcl);
}
assert(group->group_filtermode_isexcl);
igmp_group_reset_gmi(group);
}
static void toin_incl(struct gm_group *group, int num_sources,
struct in_addr *sources)
{
int num_sources_tosend = listcount(group->group_source_list);
int i;
/* Set SEND flag for all known sources (A) */
source_mark_send_flag(group);
/* Scan received sources (B) */
for (i = 0; i < num_sources; ++i) {
struct gm_source *source;
struct in_addr *src_addr;
bool new;
src_addr = sources + i;
/* Lookup reported source (B) */
source = igmp_get_source_by_addr(group, *src_addr, &new);
if (!source)
continue;
if (!new) {
/* If found, clear SEND flag (A*B) */
IGMP_SOURCE_DONT_SEND(source->source_flags);
--num_sources_tosend;
}
/* (B)=GMI */
igmp_source_reset_gmi(group, source);
}
/* Send sources marked with SEND flag: Q(G,A-B) */
if (num_sources_tosend > 0) {
source_query_send_by_flag(group, num_sources_tosend);
}
}
static void toin_excl(struct gm_group *group, int num_sources,
struct in_addr *sources)
{
int num_sources_tosend;
int i;
/* Set SEND flag for X (sources with timer > 0) */
num_sources_tosend = source_mark_send_flag_by_timer(group);
/* Scan received sources (A) */
for (i = 0; i < num_sources; ++i) {
struct gm_source *source;
struct in_addr *src_addr;
bool new;
src_addr = sources + i;
/* Lookup reported source (A) */
source = igmp_get_source_by_addr(group, *src_addr, &new);
if (!source)
continue;
if (source->t_source_timer) {
/* If found and timer running, clear SEND flag
* (X*A) */
IGMP_SOURCE_DONT_SEND(source->source_flags);
--num_sources_tosend;
}
/* (A)=GMI */
igmp_source_reset_gmi(group, source);
}
/* Send sources marked with SEND flag: Q(G,X-A) */
if (num_sources_tosend > 0) {
source_query_send_by_flag(group, num_sources_tosend);
}
/* Send Q(G) */
group_query_send(group);
}
void igmpv3_report_toin(struct gm_sock *igmp, struct in_addr from,
struct in_addr group_addr, int num_sources,
struct in_addr *sources)
{
struct interface *ifp = igmp->interface;
struct gm_group *group;
on_trace(__func__, ifp, from, group_addr, num_sources, sources);
/*
* If the requested filter mode is INCLUDE *and* the requested source
* list is empty, then the entry corresponding to the requested
* interface and multicast address is deleted if present. If no such
* entry is present, the request is ignored.
*/
if (num_sources) {
/* non-existent group is created as INCLUDE {empty} */
group = igmp_add_group_by_addr(igmp, group_addr);
if (!group) {
return;
}
} else {
group = find_group_by_addr(igmp, group_addr);
if (!group)
return;
}
if (group->group_filtermode_isexcl) {
/* EXCLUDE mode */
toin_excl(group, num_sources, sources);
} else {
/* INCLUDE mode */
toin_incl(group, num_sources, sources);
}
}
static void toex_incl(struct gm_group *group, int num_sources,
struct in_addr *sources)
{
int num_sources_tosend = 0;
int i;
assert(!group->group_filtermode_isexcl);
/* Set DELETE flag for all known sources (A) */
source_mark_delete_flag(group);
/* Clear off SEND flag from all known sources (A) */
source_clear_send_flag(group->group_source_list);
/* Scan received sources (B) */
for (i = 0; i < num_sources; ++i) {
struct gm_source *source;
struct in_addr *src_addr;
bool new;
src_addr = sources + i;
/* Lookup reported source (B) */
source = igmp_get_source_by_addr(group, *src_addr, &new);
if (!new) {
/* If found, clear deletion flag: (A*B) */
IGMP_SOURCE_DONT_DELETE(source->source_flags);
/* and set SEND flag (A*B) */
IGMP_SOURCE_DO_SEND(source->source_flags);
++num_sources_tosend;
}
} /* Scan received sources (B) */
group->group_filtermode_isexcl = 1; /* boolean=true */
/* Delete all sources marked with DELETE flag (A-B) */
source_delete_by_flag(group->group_source_list);
/* Send sources marked with SEND flag: Q(G,A*B) */
if (num_sources_tosend > 0) {
source_query_send_by_flag(group, num_sources_tosend);
}
assert(group->group_filtermode_isexcl);
group_exclude_fwd_anysrc_ifempty(group);
}
static void toex_excl(struct gm_group *group, int num_sources,
struct in_addr *sources)
{
int num_sources_tosend = 0;
int i;
/* set DELETE flag for all known sources (X,Y) */
source_mark_delete_flag(group);
/* clear off SEND flag from all known sources (X,Y) */
source_clear_send_flag(group->group_source_list);
if (num_sources == 0) {
struct gm_source *source;
struct in_addr any = {.s_addr = INADDR_ANY};
source = igmp_find_source_by_addr(group, any);
if (source)
IGMP_SOURCE_DONT_DELETE(source->source_flags);
}
/* scan received sources (A) */
for (i = 0; i < num_sources; ++i) {
struct gm_source *source;
struct in_addr *src_addr;
bool new;
src_addr = sources + i;
/* lookup reported source (A) in known sources (X,Y) */
source = igmp_get_source_by_addr(group, *src_addr, &new);
if (!source)
continue;
if (!new) {
/* if found, clear off DELETE flag from reported source
* (A) */
IGMP_SOURCE_DONT_DELETE(source->source_flags);
} else {
/* if not found, create source with Group Timer:
* (A-X-Y)=Group Timer */
long group_timer_msec;
assert(!source->t_source_timer); /* timer == 0 */
group_timer_msec = igmp_group_timer_remain_msec(group);
igmp_source_timer_on(group, source, group_timer_msec);
assert(source->t_source_timer); /* (A-X-Y) timer > 0 */
/* make sure source is created with DELETE flag unset */
assert(!IGMP_SOURCE_TEST_DELETE(source->source_flags));
}
/* make sure reported source has DELETE flag unset */
assert(!IGMP_SOURCE_TEST_DELETE(source->source_flags));
if (source->t_source_timer) {
/* if source timer>0 mark SEND flag: Q(G,A-Y) */
IGMP_SOURCE_DO_SEND(source->source_flags);
++num_sources_tosend;
}
} /* scan received sources (A) */
/*
delete all sources marked with DELETE flag:
Delete (X-A)
Delete (Y-A)
*/
source_delete_by_flag(group->group_source_list);
/* send sources marked with SEND flag: Q(G,A-Y) */
if (num_sources_tosend > 0) {
source_query_send_by_flag(group, num_sources_tosend);
}
}
void igmpv3_report_toex(struct gm_sock *igmp, struct in_addr from,
struct in_addr group_addr, int num_sources,
struct in_addr *sources)
{
struct interface *ifp = igmp->interface;
struct gm_group *group;
on_trace(__func__, ifp, from, group_addr, num_sources, sources);
/* non-existent group is created as INCLUDE {empty} */
group = igmp_add_group_by_addr(igmp, group_addr);
if (!group) {
return;
}
if (group->group_filtermode_isexcl) {
/* EXCLUDE mode */
toex_excl(group, num_sources, sources);
} else {
/* INCLUDE mode */
toex_incl(group, num_sources, sources);
assert(group->group_filtermode_isexcl);
}
assert(group->group_filtermode_isexcl);
/* Group Timer=GMI */
igmp_group_reset_gmi(group);
}
void igmpv3_report_allow(struct gm_sock *igmp, struct in_addr from,
struct in_addr group_addr, int num_sources,
struct in_addr *sources)
{
on_trace(__func__, igmp->interface, from, group_addr, num_sources,
sources);
allow(igmp, from, group_addr, num_sources, sources);
}
static void igmp_send_query_group(struct gm_group *group, char *query_buf,
size_t query_buf_size, int num_sources,
int s_flag)
{
struct interface *ifp = group->interface;
struct pim_interface *pim_ifp = ifp->info;
struct gm_sock *igmp;
struct listnode *sock_node;
for (ALL_LIST_ELEMENTS_RO(pim_ifp->gm_socket_list, sock_node, igmp)) {
igmp_send_query(
pim_ifp->igmp_version, group, query_buf, query_buf_size,
num_sources, group->group_addr, group->group_addr,
pim_ifp->gm_specific_query_max_response_time_dsec,
s_flag, igmp);
}
}
/*
RFC3376: 6.6.3.1. Building and Sending Group Specific Queries
When transmitting a group specific query, if the group timer is
larger than LMQT, the "Suppress Router-Side Processing" bit is set
in the query message.
*/
static void group_retransmit_group(struct gm_group *group)
{
struct pim_interface *pim_ifp;
long lmqc; /* Last Member Query Count */
long lmqi_msec; /* Last Member Query Interval */
long lmqt_msec; /* Last Member Query Time */
int s_flag;
int query_buf_size;
pim_ifp = group->interface->info;
if (pim_ifp->igmp_version == 3) {
query_buf_size = PIM_IGMP_BUFSIZE_WRITE;
} else {
query_buf_size = IGMP_V12_MSG_SIZE;
}
char query_buf[query_buf_size];