forked from billm/pfsense-tools-centipede-slbd
/
patch-fbsd
1531 lines (1371 loc) · 54.4 KB
/
patch-fbsd
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
diff -ur ../src_old/Makefile ./Makefile
--- ../src_old/Makefile 2009-12-14 11:10:51.000000000 +0000
+++ ./Makefile 2009-12-14 11:10:54.000000000 +0000
@@ -1,12 +1,12 @@
#BINDIR=../bin
BINDIR=/usr/local/bin
-ETCDIR=/etc
-MANDIR=/usr/share/man
+ETCDIR=/usr/local/etc
+MANDIR=/usr/local/man
# CFLAGS=-g
-CFLAGS=-O
+CFLAGS+=-O2 -Wall -Wextra -fno-builtin-log
default : build.h igmpproxy
@@ -21,8 +21,11 @@
cp ../doc/igmpproxy.conf.5 ${MANDIR}/man5
if [ ! -e ${ETCDIR}/igmpproxy.conf ]; then cp igmpproxy.conf ${ETCDIR}; fi
-igmpproxy : igmpproxy.o config.o confread.o request.o udpsock.o mcgroup.o rttable.o \
- igmp.o ifvc.o callout.o kern.o syslog.o lib.o mroute-api.o
+SRC = igmpproxy.c config.c confread.c request.c mcgroup.c rttable.c \
+ igmp.c ifvc.c callout.c kern.c syslog.c lib.c mroute-api.c
+OBJS = ${SRC:.c=.o}
+igmpproxy: build.h ${OBJS}
+ cc ${CFLAGS} ${OBJS} -o igmpproxy
build.h :
echo '#define BUILD "' `date +%y%m%d` '"' >build.h
Only in .: Makefile.orig
diff -ur ../src_old/config.c ./config.c
--- ../src_old/config.c 2009-12-14 11:10:51.000000000 +0000
+++ ./config.c 2009-12-14 11:10:54.000000000 +0000
@@ -177,7 +177,7 @@
}
// Loop through all VIFs...
- for ( Ix = 0; Dp = getIfByIx( Ix ); Ix++ ) {
+ for ( Ix = 0; (Dp = getIfByIx( Ix )); Ix++ ) {
if ( Dp->InAdr.s_addr && ! (Dp->Flags & IFF_LOOPBACK) ) {
// Now try to find a matching config...
@@ -241,7 +241,8 @@
tmpPtr->allowednets = NULL;
// Make a copy of the token to store the IF name
- tmpPtr->name = (char *)malloc( sizeof(char) * strlen(token) );
+ //One more byte since strlen does not include the terminating NULL char.
+ tmpPtr->name = (char *)malloc( (sizeof(char) * strlen(token)) + 1 );
if(tmpPtr->name == NULL) {
log(LOG_ERR, 0, "Out of memory.");
}
@@ -255,7 +256,7 @@
while(token != NULL) {
if(strcmp("altnet", token)==0) {
// Altnet...
- struct in_addr networkAddr;
+ //struct in_addr networkAddr;
token = nextConfigToken();
IF_DEBUG log(LOG_DEBUG, 0, "Config: IF: Got altnet token %s.",token);
@@ -347,7 +348,7 @@
mask <<= (32 - bitcnt);
}
- if(addr == -1 || addr == 0) {
+ if(addr == (uint32) -1 || addr == 0) {
log(LOG_WARNING, 0, "Unable to parse address token '%s'.", addrstr);
return NULL;
}
Only in .: config.c.orig
diff -ur ../src_old/defs.h ./defs.h
--- ../src_old/defs.h 2009-12-14 11:10:51.000000000 +0000
+++ ./defs.h 2009-12-14 11:10:54.000000000 +0000
@@ -40,10 +40,18 @@
#include <stdlib.h>
#include <syslog.h>
#include <signal.h>
-
#include <sys/socket.h>
+
+#ifdef __FreeBSD__
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#else
#include <sys/un.h>
#include <sys/time.h>
+#endif
#include <net/if.h>
@@ -52,7 +60,15 @@
#include <linux/in.h>
#include <linux/mroute.h>
#else
+#ifdef __FreeBSD__
+ #include <alias.h>
+ #include <net/route.h>
#include <netinet/in.h>
+ #include <netinet/ip_mroute.h>
+ #include <netinet/igmp.h>
+#endif
+ #include <netinet/in.h>
+ #include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/igmp.h>
#include <arpa/inet.h>
@@ -60,7 +76,11 @@
// The default path for the config file...
+#ifdef __FreeBSD__
+#define IGMPPROXY_CONFIG_FILEPATH "/usr/local/etc/igmpproxy.conf"
+#else
#define IGMPPROXY_CONFIG_FILEPATH "/etc/igmpproxy.conf"
+#endif
#define ENABLE_DEBUG 1
/*
@@ -69,12 +89,46 @@
#define MAX_IP_PACKET_LEN 576
#define MIN_IP_HEADER_LEN 20
#define MAX_IP_HEADER_LEN 60
+#define HAVE_SA_LEN 1
+#define IP_HEADER_RAOPT_LEN 24
#define MAX_MC_VIFS 32 // !!! check this const in the specific includes
+#ifndef IGMP_MEMBERSHIP_QUERY
+#define IGMP_MEMBERSHIP_QUERY IGMP_HOST_MEMBERSHIP_QUERY
+#endif
+
+#define IGMP_V3_MEMBERSHIP_QUERY 0x111 /* it's fake but we have to differentiate between V2 and V3 queries */
+#define IGMP_V3_QUERY_HDRLEN 4
+
+#ifndef IGMP_V1_MEMBERSHIP_REPORT
+#define IGMP_V1_MEMBERSHIP_REPORT IGMP_v1_HOST_MEMBERSHIP_REPORT
+#endif
+#ifndef IGMP_V2_MEMBERSHIP_REPORT
+#define IGMP_V2_MEMBERSHIP_REPORT IGMP_v2_HOST_MEMBERSHIP_REPORT
+#endif
+#ifndef IGMP_V3_MEMBERSHIP_REPORT
+#define IGMP_V3_MEMBERSHIP_REPORT IGMP_v3_HOST_MEMBERSHIP_REPORT
+#endif
+#ifndef IGMP_V2_LEAVE_GROUP
+#define IGMP_V2_LEAVE_GROUP IGMP_HOST_LEAVE_MESSAGE
+#endif
+
+
+#ifndef INADDR_ALLRTRS_GROUP
+/* address for multicast mtrace msg */
+#define INADDR_ALLRTRS_GROUP (u_int32_t)0xe0000002 /* 224.0.0.2 */
+#endif
+#define INADDR_ALLRTRS_GROUP_V3 (u_int32_t)0xe0000016 /* 224.0.0.22 */
+#define INADDR_V3_GENQRY_GROUP (u_int32_t)0x00000000 /* 0.0.0.0 */
+
// Useful macros..
+#ifndef MIN
#define MIN( a, b ) ((a) < (b) ? (a) : (b))
+#endif
+#ifndef MAX
#define MAX( a, b ) ((a) < (b) ? (b) : (a))
+#endif
#define VCMC( Vc ) (sizeof( Vc ) / sizeof( (Vc)[ 0 ] ))
#define VCEP( Vc ) (&(Vc)[ VCMC( Vc ) ])
@@ -126,7 +180,12 @@
#define IF_DEBUG if(Log2Stderr & LOG_DEBUG)
-void log( int Serverity, int Errno, const char *FmtSt, ... );
+#ifdef DEVEL_LOGGING
+#define log(Severity, Errno, Fmt, args...) _log((Severity), (Errno), __FUNCTION__, __LINE__, (Fmt), ##args)
+void _log( int Serverity, int Errno, const char *func, int line, const char *FmtSt, ...);
+#else
+void log( int Serverity, int Errno, const char *FmtSt, ...);
+#endif
/* ifvc.c
*/
@@ -196,6 +255,7 @@
struct IfDesc *getIfByName( const char *IfName );
struct IfDesc *getIfByIx( unsigned Ix );
struct IfDesc *getIfByAddress( uint32 Ix );
+int isAdressValidForIf( struct IfDesc* intrface, uint32 ipaddr );
/* mroute-api.c
*/
@@ -226,6 +286,9 @@
*/
extern uint32 allhosts_group;
extern uint32 allrouters_group;
+extern uint32 allrouters_group_v3;
+extern uint32 v3_genqry_allsystems;
+extern uint32 v3_genqry_group;
void initIgmp(void);
void acceptIgmp(int);
void sendIgmp (uint32, uint32, int, int, uint32,int);
@@ -235,7 +298,7 @@
char *fmtInAdr( char *St, struct in_addr InAdr );
char *inetFmt(uint32 addr, char *s);
char *inetFmts(uint32 addr, uint32 mask, char *s);
-int inetCksum(u_short *addr, u_int len);
+int inetChksum(u_short *addr, u_int len);
/* kern.c
*/
@@ -255,7 +318,7 @@
/* mcgroup.c
*/
-int joinMcGroup( int UdpSock, struct IfDesc *IfDp, uint32 mcastaddr );
+int joinMcGroup( int UdpSock, struct IfDesc *IfDp, uint32 mcastaddr);
int leaveMcGroup( int UdpSock, struct IfDesc *IfDp, uint32 mcastaddr );
@@ -264,14 +327,14 @@
void initRouteTable();
void clearAllRoutes();
int insertRoute(uint32 group, int ifx);
-int activateRoute(uint32 group, uint32 originAddr);
+int activateRoute(uint32 group, uint32 originAddr, int downIf);
void ageActiveRoutes();
void setRouteLastMemberMode(uint32 group);
int lastMemberGroupAge(uint32 group);
/* request.c
*/
-void acceptGroupReport(uint32 src, uint32 group, uint8 type);
+void acceptGroupReport(uint32 src, uint32 group);
void acceptLeaveMessage(uint32 src, uint32 group);
void sendGeneralMembershipQuery();
Only in .: defs.h.orig
diff -ur ../src_old/ifvc.c ./ifvc.c
--- ../src_old/ifvc.c 2009-12-14 11:10:51.000000000 +0000
+++ ./ifvc.c 2009-12-14 11:10:54.000000000 +0000
@@ -32,7 +32,11 @@
*/
#include "defs.h"
+#ifdef __FreeBSD__
+#include <ifaddrs.h>
+#else
#include <linux/sockios.h>
+#endif
struct IfDesc IfDescVc[ MAX_IF ], *IfDescEp = IfDescVc;
@@ -42,76 +46,44 @@
**
*/
void buildIfVc() {
- struct ifreq IfVc[ sizeof( IfDescVc ) / sizeof( IfDescVc[ 0 ] ) ];
- struct ifreq *IfEp;
+ struct ifaddrs *ifap, *ifa;
+ struct IfDesc *ifp;
+ struct SubnetList *net;
- int Sock;
-
- if ( (Sock = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 )
- log( LOG_ERR, errno, "RAW socket open" );
-
- /* get If vector
- */
- {
- struct ifconf IoCtlReq;
-
- IoCtlReq.ifc_buf = (void *)IfVc;
- IoCtlReq.ifc_len = sizeof( IfVc );
-
- if ( ioctl( Sock, SIOCGIFCONF, &IoCtlReq ) < 0 )
- log( LOG_ERR, errno, "ioctl SIOCGIFCONF" );
-
- IfEp = (void *)((char *)IfVc + IoCtlReq.ifc_len);
- }
+ if (getifaddrs(&ifap) < 0)
+ log( LOG_ERR, errno, "getifaddrs" );
/* loop over interfaces and copy interface info to IfDescVc
*/
{
- struct ifreq *IfPt;
- struct IfDesc *IfDp;
-
// Temp keepers of interface params...
uint32 addr, subnet, mask;
- for ( IfPt = IfVc; IfPt < IfEp; IfPt++ ) {
- struct ifreq IfReq;
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
char FmtBu[ 32 ];
- strncpy( IfDescEp->Name, IfPt->ifr_name, sizeof( IfDescEp->Name ) );
-
- // Currently don't set any allowed nets...
- //IfDescEp->allowednets = NULL;
-
- // Set the index to -1 by default.
- IfDescEp->index = -1;
+ if (IfDescEp >= &IfDescVc[ MAX_IF ]) {
+ log(LOG_WARNING, 0, "Too many interfaces, skipping %d", ifa->ifa_name);
+ continue;
+ }
- /* don't retrieve more info for non-IP interfaces
+ /* ignore non-IP interfaces
*/
- if ( IfPt->ifr_addr.sa_family != AF_INET ) {
- IfDescEp->InAdr.s_addr = 0; /* mark as non-IP interface */
- IfDescEp++;
+ if ( ifa->ifa_addr->sa_family != AF_INET )
continue;
- }
- // Get the interface adress...
- IfDescEp->InAdr = ((struct sockaddr_in *)&IfPt->ifr_addr)->sin_addr;
- addr = IfDescEp->InAdr.s_addr;
-
- memcpy( IfReq.ifr_name, IfDescEp->Name, sizeof( IfReq.ifr_name ) );
-
- // Get the subnet mask...
- if (ioctl(Sock, SIOCGIFNETMASK, &IfReq ) < 0)
- log(LOG_ERR, errno, "ioctl SIOCGIFNETMASK for %s", IfReq.ifr_name);
- mask = ((struct sockaddr_in *)&IfReq.ifr_addr)->sin_addr.s_addr;
- subnet = addr & mask;
+ if ((ifp = getIfByName(ifa->ifa_name)) == NULL) {
- // Get the physical index of the Interface
- if (ioctl(Sock, SIOCGIFINDEX, &IfReq ) < 0)
- log(LOG_ERR, errno, "ioctl SIOCGIFINDEX for %s", IfReq.ifr_name);
+ strlcpy( IfDescEp->Name, ifa->ifa_name, sizeof( IfDescEp->Name ) );
+
+ log(LOG_DEBUG, 0, "Adding Physical Index value of IF '%s' is %d",
+ IfDescEp->Name, if_nametoindex(IfDescEp->Name));
- log(LOG_DEBUG, 0, "Physical Index value of IF '%s' is %d",
- IfDescEp->Name, IfReq.ifr_ifindex);
+ // Set the index to -1 by default.
+ IfDescEp->index = -1;
+ // Get the interface adress...
+ IfDescEp->InAdr = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
/* get if flags
**
@@ -122,39 +94,43 @@
** grex 0x00C1 -> NoArp, Running, Up
** ipipx 0x00C1 -> NoArp, Running, Up
*/
- if ( ioctl( Sock, SIOCGIFFLAGS, &IfReq ) < 0 )
- log( LOG_ERR, errno, "ioctl SIOCGIFFLAGS" );
-
- IfDescEp->Flags = IfReq.ifr_flags;
- // Insert the verified subnet as an allowed net...
- IfDescEp->allowednets = (struct SubnetList *)malloc(sizeof(struct SubnetList));
- if(IfDescEp->allowednets == NULL) log(LOG_ERR, 0, "Out of memory !");
-
- // Create the network address for the IF..
- IfDescEp->allowednets->next = NULL;
- IfDescEp->allowednets->subnet_mask = mask;
- IfDescEp->allowednets->subnet_addr = subnet;
+ IfDescEp->Flags = ifa->ifa_flags;
// Set the default params for the IF...
IfDescEp->state = IF_STATE_DOWNSTREAM;
IfDescEp->robustness = DEFAULT_ROBUSTNESS;
IfDescEp->threshold = DEFAULT_THRESHOLD; /* ttl limit */
IfDescEp->ratelimit = DEFAULT_RATELIMIT;
+ IfDescEp->allowednets = NULL;
+ ifp = IfDescEp++;
+ }
+
+ // Insert the verified subnet as an allowed net...
+ addr = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
+ mask = ((struct sockaddr_in *)ifa->ifa_netmask)->sin_addr.s_addr;
+ subnet = addr & mask;
+ net = (struct SubnetList *)malloc(sizeof(struct SubnetList));
+ if(net == NULL) log(LOG_ERR, 0, "Out of memory !");
+
+ // Create the network address for the IF..
+ net->next = ifp->allowednets;
+ net->subnet_mask = mask;
+ net->subnet_addr = subnet;
+ ifp->allowednets = net;
// Debug log the result...
IF_DEBUG log( LOG_DEBUG, 0, "buildIfVc: Interface %s Addr: %s, Flags: 0x%04x, Network: %s",
- IfDescEp->Name,
- fmtInAdr( FmtBu, IfDescEp->InAdr ),
- IfDescEp->Flags,
+ ifp->Name,
+ fmtInAdr( FmtBu, ifp->InAdr ),
+ ifp->Flags,
inetFmts(subnet,mask, s1));
- IfDescEp++;
- }
}
- close( Sock );
+ }
+ freeifaddrs(ifap);
}
/*
Only in .: ifvc.c.orig
diff -ur ../src_old/igmp.c ./igmp.c
--- ../src_old/igmp.c 2009-12-14 11:10:51.000000000 +0000
+++ ./igmp.c 2009-12-14 11:11:51.000000000 +0000
@@ -35,11 +35,15 @@
* appropriately...
*/
+#include <sys/param.h>
+
#include "defs.h"
// Globals
uint32 allhosts_group; /* All hosts addr in net order */
-uint32 allrouters_group; /* All hosts addr in net order */
+uint32 allrouters_group; /* All hosts addr in net order */
+uint32 allrouters_group_v3;
+uint32 v3_genqry_group;
extern int MRouterFD;
@@ -67,13 +71,15 @@
* - Checksum (let the kernel fill it in)
*/
ip->ip_v = IPVERSION;
- ip->ip_hl = sizeof(struct ip) >> 2;
+ ip->ip_hl = (sizeof(struct ip) + 4) >> 2; /* +4 for Router Alert option */
ip->ip_tos = 0xc0; /* Internet Control */
ip->ip_ttl = MAXTTL; /* applies to unicasts only */
ip->ip_p = IPPROTO_IGMP;
allhosts_group = htonl(INADDR_ALLHOSTS_GROUP);
allrouters_group = htonl(INADDR_ALLRTRS_GROUP);
+ allrouters_group_v3 = htonl(INADDR_ALLRTRS_GROUP_V3);
+ v3_genqry_group = htonl(INADDR_V3_GENQRY_GROUP);
}
/**
@@ -87,6 +93,8 @@
case IGMP_V1_MEMBERSHIP_REPORT: return "V1 member report ";
case IGMP_V2_MEMBERSHIP_REPORT: return "V2 member report ";
case IGMP_V2_LEAVE_GROUP: return "Leave message ";
+ case IGMP_V3_MEMBERSHIP_REPORT: return "V3 member report ";
+ case IGMP_V3_MEMBERSHIP_QUERY: return "V3 membership query ";
default:
sprintf(unknown, "unk: 0x%02x/0x%02x ", type, code);
@@ -103,9 +111,12 @@
register uint32 src, dst, group;
struct ip *ip;
struct igmp *igmp;
+ struct igmpv3 *igmp_v3;
+ struct igmp_grouprec* igmp_gr;
+
int ipdatalen, iphdrlen, igmpdatalen;
- if (recvlen < sizeof(struct ip)) {
+ if (recvlen < (int) sizeof(struct ip)) {
log(LOG_WARNING, 0,
"received packet too short (%u bytes) for IP header", recvlen);
return;
@@ -115,7 +126,7 @@
src = ip->ip_src.s_addr;
dst = ip->ip_dst.s_addr;
- //IF_DEBUG log(LOG_DEBUG, 0, "Got a IGMP request to process...");
+ IF_DEBUG log(LOG_DEBUG, 0, "Got a IGMP request to process...");
/*
* this is most likely a message from the kernel indicating that
@@ -128,6 +139,7 @@
}
else {
struct IfDesc *checkVIF;
+ int downIf = -1;
// Check if the source address matches a valid address on upstream vif.
checkVIF = getIfByIx( upStreamVif );
@@ -141,23 +153,44 @@
return;
}
else if(!isAdressValidForIf(checkVIF, src)) {
+ unsigned Ix;
+ struct IfDesc *Dp;
+ for ( Ix = 0; (Dp = getIfByIx( Ix )); Ix++ ) {
+ if ((Dp->state == IF_STATE_DOWNSTREAM) &&isAdressValidForIf(Dp, src)) {
+ downIf = Ix;
+ break;
+ }
+ }
+
+ if (downIf == -1) {
log(LOG_WARNING, 0, "The source address %s for group %s, is not in any valid net for upstream VIF.",
inetFmt(src, s1), inetFmt(dst, s2));
return;
+ } else {
+ log(LOG_NOTICE, 0, "The source address %s for group %s, is valid DOWNSTREAM VIF #%d.",
+ inetFmt(src, s1), inetFmt(dst, s2), downIf);
+ }
}
// Activate the route.
- IF_DEBUG log(LOG_DEBUG, 0, "Route activate request from %s to %s",
- inetFmt(src,s1), inetFmt(dst,s2));
- activateRoute(dst, src);
+ IF_DEBUG log(LOG_DEBUG, 0, "Route activate request from %s to %s, downIf %d",
+ inetFmt(src,s1), inetFmt(dst,s2), downIf);
+ activateRoute(dst, src, downIf);
}
return;
}
+ log(LOG_DEBUG, 0, "Packet from %s: proto: %d hdrlen: %d iplen: %d or %d",
+ inetFmt(src, s1), ip->ip_p, ip->ip_hl << 2, ip->ip_len, ntohs(ip->ip_len));
+
iphdrlen = ip->ip_hl << 2;
+#ifdef RAW_INPUT_IS_RAW
ipdatalen = ntohs(ip->ip_len) - iphdrlen;
+#else
+ ipdatalen = ip->ip_len;
+#endif
if (iphdrlen + ipdatalen != recvlen) {
log(LOG_WARNING, 0,
@@ -167,7 +200,14 @@
}
igmp = (struct igmp *)(recv_buf + iphdrlen);
- group = igmp->igmp_group.s_addr;
+ igmp_v3 = (struct igmpv3 *)(recv_buf + iphdrlen);
+
+ if (igmp->igmp_type == IGMP_V3_MEMBERSHIP_REPORT){
+ igmp_gr = (struct igmp_grouprec*)((char*)igmp_v3+8); /* Start of group record */
+ group = igmp_gr->ig_group.s_addr;
+ }else
+ group = igmp->igmp_group.s_addr;
+
igmpdatalen = ipdatalen - IGMP_MINLEN;
if (igmpdatalen < 0) {
log(LOG_WARNING, 0,
@@ -176,27 +216,32 @@
return;
}
- log(LOG_NOTICE, 0, "RECV %s from %-15s to %s",
+ log(LOG_NOTICE, 0, "RECV %s from %-15s to %s (ip_hl %d, data %d)",
igmpPacketKind(igmp->igmp_type, igmp->igmp_code),
- inetFmt(src, s1), inetFmt(dst, s2) );
+ inetFmt(src, s1), inetFmt(dst, s2), iphdrlen, ipdatalen);
- switch (igmp->igmp_type) {
+ switch (igmp->igmp_type) {
case IGMP_V1_MEMBERSHIP_REPORT:
case IGMP_V2_MEMBERSHIP_REPORT:
- acceptGroupReport(src, group, igmp->igmp_type);
+ acceptGroupReport(src, group);
+ return;
+ case IGMP_V3_MEMBERSHIP_REPORT:
+ if ( ((u_char*)igmp_v3)[8] == (u_char)4 ){ /* Change To Exclude Mode - join */
+ acceptGroupReport(src, group);
+ }else if ( ((u_char*)igmp_v3)[8] == (u_char)3 ) /* Change To Include Mode - leave */
+ acceptLeaveMessage(src, group);
+ else
+ log(LOG_WARNING, 0, "unknown Mode in V3 report (%u)", (u_char*)igmp_v3+8);
return;
case IGMP_V2_LEAVE_GROUP:
acceptLeaveMessage(src, group);
return;
- /*
case IGMP_MEMBERSHIP_QUERY:
- //accept_membership_query(src, dst, group, igmp->igmp_code);
+ log(LOG_INFO, 0, "ignoring membership query");
return;
- */
-
default:
log(LOG_INFO, 0,
"ignoring unknown IGMP message type %x from %s to %s",
@@ -214,27 +259,70 @@
void buildIgmp(uint32 src, uint32 dst, int type, int code, uint32 group, int datalen) {
struct ip *ip;
struct igmp *igmp;
+ struct igmpv3 *igmp_v3;
+ struct igmp_report *igmp_rep;
extern int curttl;
ip = (struct ip *)send_buf;
ip->ip_src.s_addr = src;
ip->ip_dst.s_addr = dst;
- ip->ip_len = MIN_IP_HEADER_LEN + IGMP_MINLEN + datalen;
+ ip->ip_len = IP_HEADER_RAOPT_LEN + IGMP_MINLEN + datalen;
+#ifdef RAW_OUTPUT_IS_RAW
ip->ip_len = htons(ip->ip_len);
-
+#endif
if (IN_MULTICAST(ntohl(dst))) {
ip->ip_ttl = curttl;
} else {
ip->ip_ttl = MAXTTL;
}
- igmp = (struct igmp *)(send_buf + MIN_IP_HEADER_LEN);
- igmp->igmp_type = type;
- igmp->igmp_code = code;
- igmp->igmp_group.s_addr = group;
- igmp->igmp_cksum = 0;
- igmp->igmp_cksum = inetChksum((u_short *)igmp,
- IGMP_MINLEN + datalen);
+ // Add Router Alert option
+ ((char*)send_buf+MIN_IP_HEADER_LEN)[0] = IPOPT_RA;
+ ((char*)send_buf+MIN_IP_HEADER_LEN)[1] = 0x04;
+ ((char*)send_buf+MIN_IP_HEADER_LEN)[2] = 0x00;
+ ((char*)send_buf+MIN_IP_HEADER_LEN)[3] = 0x00;
+
+ if (type == IGMP_V3_MEMBERSHIP_REPORT){
+ ip->ip_dst.s_addr = allrouters_group_v3;
+ ip->ip_len = IP_HEADER_RAOPT_LEN + IGMP_MINLEN + IGMP_GRPREC_HDRLEN + datalen;
+ igmp_rep = (struct igmp_report *)(send_buf + IP_HEADER_RAOPT_LEN);
+ igmp_rep->ir_type = type;
+ igmp_rep->ir_rsv1 = 0;
+ igmp_rep->ir_cksum = 0;
+ igmp_rep->ir_rsv2 = 0;
+ igmp_rep->ir_numgrps = 0x0100;
+
+#if __FreeBSD_version < 800000
+ igmp_rep->ir_groups[0].ig_type = (u_char)4; /* Change To Exclude Mode */
+ igmp_rep->ir_groups[0].ig_datalen = (u_char)0; /* length of auxiliary data */
+ igmp_rep->ir_groups[0].ig_numsrc = (u_short)0; /* number of sources */
+ igmp_rep->ir_groups[0].ig_group.s_addr = group; /* group address being reported */
+#endif
+
+ igmp_rep->ir_cksum = inetChksum((u_short *)igmp_rep,
+ IGMP_MINLEN + IGMP_GRPREC_HDRLEN + datalen);
+ }else if (type == IGMP_V3_MEMBERSHIP_QUERY){
+ ip->ip_dst.s_addr = allhosts_group;
+ ip->ip_len = IP_HEADER_RAOPT_LEN + IGMP_MINLEN + IGMP_V3_QUERY_HDRLEN + datalen;
+ igmp_v3 = (struct igmpv3 *)(send_buf + IP_HEADER_RAOPT_LEN);
+ igmp_v3->igmp_type = IGMP_MEMBERSHIP_QUERY;
+ igmp_v3->igmp_code = code;
+ igmp_v3->igmp_cksum = 0;
+ igmp_v3->igmp_group.s_addr = group;
+ igmp_v3->igmp_misc = 0x2; /* S-flag=0 - Do not suppress router side processing */
+ /* QRV =2 - Querier's Robustness Variable */
+ igmp_v3->igmp_cksum = inetChksum((u_short *)igmp_v3,
+ IGMP_MINLEN + IGMP_V3_QUERY_HDRLEN + datalen);
+
+ }else{
+ igmp = (struct igmp *)(send_buf + IP_HEADER_RAOPT_LEN);
+ igmp->igmp_type = type;
+ igmp->igmp_code = code;
+ igmp->igmp_group.s_addr = group;
+ igmp->igmp_cksum = 0;
+ igmp->igmp_cksum = inetChksum((u_short *)igmp,
+ IGMP_MINLEN + datalen);
+ }
}
/*
@@ -244,9 +332,11 @@
*/
void sendIgmp(uint32 src, uint32 dst, int type, int code, uint32 group, int datalen) {
struct sockaddr_in sdst;
+ struct igmp_report *igmp_rep;
int setloop = 0, setigmpsource = 0;
- buildIgmp(src, dst, type, code, group, datalen);
+ if (type != IGMP_V2_LEAVE_GROUP) /* for leave buld later */
+ buildIgmp(src, dst, type, code, group, datalen);
if (IN_MULTICAST(ntohl(dst))) {
k_set_if(src);
@@ -262,16 +352,83 @@
#ifdef HAVE_SA_LEN
sdst.sin_len = sizeof(sdst);
#endif
- sdst.sin_addr.s_addr = dst;
- if (sendto(MRouterFD, send_buf,
- MIN_IP_HEADER_LEN + IGMP_MINLEN + datalen, 0,
- (struct sockaddr *)&sdst, sizeof(sdst)) < 0) {
- if (errno == ENETDOWN)
+ if ( type == IGMP_V3_MEMBERSHIP_REPORT ){
+ sdst.sin_addr.s_addr = allrouters_group_v3;
+ if (sendto(MRouterFD, send_buf,
+ IP_HEADER_RAOPT_LEN + IGMP_MINLEN + IGMP_GRPREC_HDRLEN + datalen, 0,
+ (struct sockaddr *)&sdst, sizeof(sdst)) < 0) {
+ if (errno == ENETDOWN)
+ log(LOG_ERR, errno, "Sender VIF was down.");
+ else
+ log(LOG_INFO, errno,
+ "sendto to %s on %s",
+ inetFmt(allrouters_group_v3, s1), inetFmt(src, s2));
+ }
+ else{
+ IF_DEBUG log(LOG_DEBUG, 0, "SENT %s from %-15s to %s",
+ igmpPacketKind(type, code), src == INADDR_ANY ? "INADDR_ANY" :
+ inetFmt(src, s1), inetFmt(allrouters_group_v3, s2));
+ }
+ }else if ( type == IGMP_V3_MEMBERSHIP_QUERY ){
+ sdst.sin_addr.s_addr = allhosts_group;
+ if (sendto(MRouterFD, send_buf,
+ IP_HEADER_RAOPT_LEN + IGMP_MINLEN + IGMP_V3_QUERY_HDRLEN + datalen, 0,
+ (struct sockaddr *)&sdst, sizeof(sdst)) < 0) {
+ if (errno == ENETDOWN)
+ log(LOG_ERR, errno, "Sender VIF was down.");
+ else
+ log(LOG_INFO, errno,
+ "sendto to %s on %s",
+ inetFmt(allhosts_group, s1), inetFmt(src, s2));
+ }
+ else{
+ IF_DEBUG log(LOG_DEBUG, 0, "SENT %s from %-15s to %s",
+ igmpPacketKind(type, code), src == INADDR_ANY ? "INADDR_ANY" :
+ inetFmt(src, s1), inetFmt(allhosts_group, s2));
+ }
+ }else if (type == IGMP_V2_LEAVE_GROUP){
+ /* we have to send V3 leave as well */
+ buildIgmp(src, allrouters_group_v3, IGMP_V3_MEMBERSHIP_REPORT, code, group, datalen);
+ sdst.sin_addr.s_addr = allrouters_group_v3;
+ igmp_rep = (struct igmp_report *)(send_buf + IP_HEADER_RAOPT_LEN);
+#if __FreeBSD_version < 750000
+ igmp_rep->ir_groups[0].ig_type = (u_char)3; /* Change To Include Mode - leave */
+#endif
+ igmp_rep->ir_cksum = inetChksum((u_short *)igmp_rep, /* recalculate checksum */
+ IGMP_MINLEN + IGMP_GRPREC_HDRLEN + datalen);
+
+ if (sendto(MRouterFD, send_buf,
+ IP_HEADER_RAOPT_LEN + IGMP_MINLEN + IGMP_GRPREC_HDRLEN + datalen, 0,
+ (struct sockaddr *)&sdst, sizeof(sdst)) < 0) {
+ if (errno == ENETDOWN)
log(LOG_ERR, errno, "Sender VIF was down.");
- else
+ else
log(LOG_INFO, errno,
"sendto to %s on %s",
- inetFmt(dst, s1), inetFmt(src, s2));
+ inetFmt(allrouters_group_v3, s1), inetFmt(src, s2));
+ }
+ else{
+ IF_DEBUG log(LOG_DEBUG, 0, "SENT %s from %-15s to %s",
+ "V3 report with leave", src == INADDR_ANY ? "INADDR_ANY" :
+ inetFmt(src, s1), inetFmt(allrouters_group_v3, s2));
+ }
+ }else{
+ sdst.sin_addr.s_addr = dst;
+ if (sendto(MRouterFD, send_buf,
+ IP_HEADER_RAOPT_LEN + IGMP_MINLEN + datalen, 0,
+ (struct sockaddr *)&sdst, sizeof(sdst)) < 0) {
+ if (errno == ENETDOWN)
+ log(LOG_ERR, errno, "Sender VIF was down.");
+ else
+ log(LOG_INFO, errno,
+ "sendto to %s on %s",
+ inetFmt(dst, s1), inetFmt(src, s2));
+ }
+ else{
+ IF_DEBUG log(LOG_DEBUG, 0, "SENT %s from %-15s to %s",
+ igmpPacketKind(type, code), src == INADDR_ANY ? "INADDR_ANY" :
+ inetFmt(src, s1), inetFmt(dst, s2));
+ }
}
if(setigmpsource) {
@@ -282,8 +439,5 @@
k_set_if(INADDR_ANY);
}
- IF_DEBUG log(LOG_DEBUG, 0, "SENT %s from %-15s to %s",
- igmpPacketKind(type, code), src == INADDR_ANY ? "INADDR_ANY" :
- inetFmt(src, s1), inetFmt(dst, s2));
}
Only in .: igmp.c.orig
diff -ur ../src_old/igmpproxy.c ./igmpproxy.c
--- ../src_old/igmpproxy.c 2009-12-14 11:10:51.000000000 +0000
+++ ./igmpproxy.c 2009-12-14 11:10:54.000000000 +0000
@@ -80,7 +80,7 @@
* on commandline. The number of commandline arguments, and a
* pointer to the arguments are recieved on the line...
*/
-int main( int ArgCn, const char *ArgVc[] ) {
+int main( int ArgCn, char *ArgVc[] ) {
int debugMode = 0;
@@ -155,18 +155,9 @@
if ( ! debugMode ) {
IF_DEBUG log( LOG_DEBUG, 0, "Starting daemon mode.");
-
- // Only daemon goes past this line...
- if (fork()) exit(0);
-
- // Detach deamon from terminal
- if ( close( 0 ) < 0 || close( 1 ) < 0 || close( 2 ) < 0
- || open( "/dev/null", 0 ) != 0 || dup2( 0, 1 ) < 0 || dup2( 0, 2 ) < 0
- || setpgrp() < 0
- ) {
+ if (daemon(1, 0) != 0)
log( LOG_ERR, errno, "failed to detach deamon" );
}
- }
// Go to the main loop.
igmpProxyRun();
@@ -218,7 +209,7 @@
int vifcount = 0;
upStreamVif = -1;
- for ( Ix = 0; Dp = getIfByIx( Ix ); Ix++ ) {
+ for ( Ix = 0; (Dp = getIfByIx( Ix )); Ix++ ) {
if ( Dp->InAdr.s_addr && ! (Dp->Flags & IFF_LOOPBACK) ) {
if(Dp->state == IF_STATE_UPSTREAM) {
@@ -237,7 +228,7 @@
// If there is only one VIF, or no defined upstream VIF, we send an error.
if(vifcount < 2 || upStreamVif < 0) {
- log(LOG_ERR, 0, "There must be at least 2 Vif's where one is upstream.");
+ log(LOG_ERR, 0, "There must be at least 2 Vif's where one is upstream. (vifcount %d, upStreamVif %d)", vifcount, upStreamVif);
}
}
@@ -275,7 +266,7 @@
register int recvlen;
int MaxFD, Rt, secs;
fd_set ReadFDS;
- int dummy = 0;
+ socklen_t dummy = 0;
struct timeval curtime, lasttime, difftime, tv;
// The timeout is a pointer in order to set it to NULL if nessecary.
struct timeval *timeout = &tv;
@@ -324,12 +315,12 @@
continue;
}
else if( Rt > 0 ) {
-
// Read IGMP request, and handle it...
if( FD_ISSET( MRouterFD, &ReadFDS ) ) {
recvlen = recvfrom(MRouterFD, recv_buf, RECV_BUF_SIZE,
0, NULL, &dummy);
+
if (recvlen < 0) {
if (errno != EINTR) log(LOG_ERR, errno, "recvfrom");
continue;
Only in .: igmpproxy.c.orig
diff -ur ../src_old/igmpproxy.conf ./igmpproxy.conf
--- ../src_old/igmpproxy.conf 2009-12-14 11:10:51.000000000 +0000
+++ ./igmpproxy.conf 2009-12-14 11:10:54.000000000 +0000
@@ -25,22 +25,22 @@
##------------------------------------------------------
-## Configuration for eth0 (Upstream Interface)
+## Configuration for em0 (Upstream Interface)
##------------------------------------------------------
-phyint eth0 upstream ratelimit 0 threshold 1
+phyint em0 upstream ratelimit 0 threshold 1
altnet 10.0.0.0/8
altnet 192.168.0.0/24
##------------------------------------------------------
-## Configuration for eth1 (Downstream Interface)
+## Configuration for em1 (Downstream Interface)
##------------------------------------------------------
-phyint eth1 downstream ratelimit 0 threshold 1
+phyint em1 downstream ratelimit 0 threshold 1
##------------------------------------------------------
-## Configuration for eth2 (Disabled Interface)
+## Configuration for xl0 (Disabled Interface)
##------------------------------------------------------
-phyint eth2 disabled
+phyint xl0 disabled
Only in .: igmpproxy.conf.orig
diff -ur ../src_old/mcgroup.c ./mcgroup.c
--- ../src_old/mcgroup.c 2009-12-14 11:10:51.000000000 +0000
+++ ./mcgroup.c 2009-12-14 11:10:54.000000000 +0000
@@ -44,16 +44,15 @@
static int joinleave( int Cmd, int UdpSock, struct IfDesc *IfDp, uint32 mcastaddr ) {
struct ip_mreq CtlReq;
const char *CmdSt = Cmd == 'j' ? "join" : "leave";
-
+
CtlReq.imr_multiaddr.s_addr = mcastaddr;
CtlReq.imr_interface.s_addr = IfDp->InAdr.s_addr;
{
- char FmtBu[ 32 ];
log( LOG_NOTICE, 0, "%sMcGroup: %s on %s", CmdSt,
inetFmt( mcastaddr, s1 ), IfDp ? IfDp->Name : "<any>" );
}
-
+#if __FreeBSD_version < 800000
if( setsockopt( UdpSock, IPPROTO_IP,
Cmd == 'j' ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP,
(void *)&CtlReq, sizeof( CtlReq ) ) )
@@ -61,6 +60,23 @@
log( LOG_WARNING, errno, "MRT_%s_MEMBERSHIP failed", Cmd == 'j' ? "ADD" : "DROP" );
return 1;
}
+#else
+ if( setsockopt( UdpSock, IPPROTO_IP,
+ Cmd == 'j' ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP,
+ (void *)&CtlReq, sizeof( CtlReq ) ) )
+ {
+ log( LOG_WARNING, errno, "MRT_%s_MEMBERSHIP failed", Cmd == 'j' ? "ADD" : "DROP" );
+ return 1;
+ }
+#endif
+ /* setsockopt() causes IGMP_V2_MEMBERSHIPT_REPORT sent out of Upstream interface */
+ /* Send IGMP packet on upstream interface */
+ if( Cmd == 'j' ){
+ sendIgmp(IfDp->InAdr.s_addr, mcastaddr, IGMP_V3_MEMBERSHIP_REPORT, 0, mcastaddr, 0);
+ }
+ else
+ sendIgmp(IfDp->InAdr.s_addr, mcastaddr, IGMP_V2_LEAVE_GROUP, 0, mcastaddr, 0);
+ /* V3 leave will be sent inside sendIgmp() */
return 0;
}
Only in .: mcgroup.c.orig
diff -ur ../src_old/mroute-api.c ./mroute-api.c
--- ../src_old/mroute-api.c 2009-12-14 11:10:51.000000000 +0000
+++ ./mroute-api.c 2009-12-14 11:10:54.000000000 +0000
@@ -37,7 +37,9 @@
*/
+#ifndef __FreeBSD__
#define USE_LINUX_IN_H
+#endif
#include "defs.h"
// MAX_MC_VIFS from mclab.h must have same value as MAXVIFS from mroute.h
@@ -47,7 +49,7 @@
// need an IGMP socket as interface for the mrouted API
// - receives the IGMP messages
-int MRouterFD; /* socket for all network I/O */
+int MRouterFD = -1; /* socket for all network I/O */
char *recv_buf; /* input packet buffer */
char *send_buf; /* output packet buffer */
@@ -177,13 +179,15 @@
log( LOG_NOTICE, 0, "Adding MFC: %s -> %s, InpVIf: %d",
fmtInAdr( FmtBuO, CtlReq.mfcc_origin ),
fmtInAdr( FmtBuM, CtlReq.mfcc_mcastgrp ),
- CtlReq.mfcc_parent == ALL_VIFS ? -1 : CtlReq.mfcc_parent
+ CtlReq.mfcc_parent
);
}
if ( setsockopt( MRouterFD, IPPROTO_IP, MRT_ADD_MFC,
(void *)&CtlReq, sizeof( CtlReq ) ) )
log( LOG_WARNING, errno, "MRT_ADD_MFC" );
+
+ return 0;
}
/*
@@ -210,13 +214,15 @@
log( LOG_NOTICE, 0, "Removing MFC: %s -> %s, InpVIf: %d",
fmtInAdr( FmtBuO, CtlReq.mfcc_origin ),
fmtInAdr( FmtBuM, CtlReq.mfcc_mcastgrp ),
- CtlReq.mfcc_parent == ALL_VIFS ? -1 : CtlReq.mfcc_parent
+ CtlReq.mfcc_parent
);
}
if ( setsockopt( MRouterFD, IPPROTO_IP, MRT_DEL_MFC,
(void *)&CtlReq, sizeof( CtlReq ) ) )
log( LOG_WARNING, errno, "MRT_DEL_MFC" );
+
+ return 0;