forked from troglobit/pimd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.c.orig
1276 lines (1168 loc) · 43.5 KB
/
config.c.orig
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
/*
* Copyright (c) 1998-2001
* University of Southern California/Information Sciences Institute.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* $Id: config.c,v 1.27 2002/12/06 06:47:15 pavlin Exp $
*/
/*
* Part of this program has been derived from mrouted.
* The mrouted program is covered by the license in the accompanying file
* named "LICENSE.mrouted".
*
* The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
* Leland Stanford Junior University.
*
*/
#include "defs.h"
#define LINE_BUFSIZ 1024 /* Max. line length of the config file */
/*
* Forward declarations.
*/
static char *next_word (char **);
static int parse_phyint (char *s);
static u_int32 ifname2addr (char *s);
extern struct rp_hold *g_rp_hold;
/*
* Query the kernel to find network interfaces that are multicast-capable
* and install them in the uvifs array.
*/
void
config_vifs_from_kernel()
{
struct ifreq *ifrp, *ifend;
register struct uvif *v;
register vifi_t vifi;
int n;
u_int32 addr, mask, subnet;
short flags;
int num_ifreq = 64;
struct ifconf ifc;
char *newbuf;
total_interfaces = 0; /* The total number of physical interfaces */
ifc.ifc_len = num_ifreq * sizeof(struct ifreq);
ifc.ifc_buf = calloc(ifc.ifc_len, sizeof(char));
while (ifc.ifc_buf) {
if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0)
logit(LOG_ERR, errno, "ioctl SIOCGIFCONF");
/*
* If the buffer was large enough to hold all the addresses
* then break out, otherwise increase the buffer size and
* try again.
*
* The only way to know that we definitely had enough space
* is to know that there was enough space for at least one
* more struct ifreq. ???
*/
if ((num_ifreq * sizeof(struct ifreq)) >=
ifc.ifc_len + sizeof(struct ifreq))
break;
num_ifreq *= 2;
ifc.ifc_len = num_ifreq * sizeof(struct ifreq);
newbuf = realloc(ifc.ifc_buf, ifc.ifc_len);
if (newbuf == NULL)
free(ifc.ifc_buf);
ifc.ifc_buf = newbuf;
}
if (ifc.ifc_buf == NULL)
logit(LOG_ERR, 0, "config_vifs_from_kernel: ran out of memory");
ifrp = (struct ifreq *)ifc.ifc_buf;
ifend = (struct ifreq *)(ifc.ifc_buf + ifc.ifc_len);
/*
* Loop through all of the interfaces.
*/
for (; ifrp < ifend; ifrp = (struct ifreq *)((char *)ifrp + n)) {
struct ifreq ifr;
#ifdef HAVE_SA_LEN
n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
if (n < sizeof(*ifrp))
n = sizeof(*ifrp);
#else
n = sizeof(*ifrp);
#endif /* HAVE_SA_LEN */
/*
* Ignore any interface for an address family other than IP.
*/
if (ifrp->ifr_addr.sa_family != AF_INET) {
total_interfaces++; /* Eventually may have IP address later */
continue;
}
addr = ((struct sockaddr_in *)&ifrp->ifr_addr)->sin_addr.s_addr;
/*
* Need a template to preserve address info that is
* used below to locate the next entry. (Otherwise,
* SIOCGIFFLAGS stomps over it because the requests
* are returned in a union.)
*/
bcopy(ifrp->ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name));
/*
* Ignore loopback interfaces and interfaces that do not
* support multicast.
*/
if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ifr) < 0)
logit(LOG_ERR, errno, "ioctl SIOCGIFFLAGS for %s", ifr.ifr_name);
flags = ifr.ifr_flags;
if ((flags & (IFF_LOOPBACK | IFF_MULTICAST)) != IFF_MULTICAST)
continue;
/*
* Everyone below is a potential vif interface.
* We don't care if it has wrong configuration or not configured
* at all.
*/
total_interfaces++;
/*
* Ignore any interface whose address and mask do not define a
* valid subnet number, or whose address is of the form
* {subnet,0} or {subnet,-1}.
*/
if (ioctl(udp_socket, SIOCGIFNETMASK, (char *)&ifr) < 0) {
if (!(flags & IFF_POINTOPOINT)) {
logit(LOG_ERR, errno, "ioctl SIOCGIFNETMASK for %s",
ifr.ifr_name);
} else {
mask = 0xffffffff;
}
} else {
mask = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
}
subnet = addr & mask;
if ((!inet_valid_subnet(subnet, mask))
|| (addr == subnet) || addr == (subnet | ~mask)) {
if (!(inet_valid_host(addr) && (flags & IFF_POINTOPOINT))) {
logit(LOG_WARNING, 0,
"ignoring %s, has invalid address (%s) and/or mask (%s)",
ifr.ifr_name, inet_fmt(addr, s1, sizeof(s1)), inet_fmt(mask, s2, sizeof(s2)));
continue;
}
}
/*
* Ignore any interface that is connected to the same subnet as
* one already installed in the uvifs array.
*/
/*
* TODO: XXX: bug or "feature" is to allow only one interface per
* subnet?
*/
for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
if (strcmp(v->uv_name, ifr.ifr_name) == 0) {
logit(LOG_DEBUG, 0,
"skipping %s (%s on subnet %s) (alias for vif#%u?)",
v->uv_name, inet_fmt(addr, s1, sizeof(s1)),
netname(subnet, mask), vifi);
break;
}
/* we don't care about point-to-point links in same subnet */
if (flags & IFF_POINTOPOINT)
continue;
if (v->uv_flags & VIFF_POINT_TO_POINT)
continue;
#if 0
/*
* TODO: to allow different interfaces belong to
* overlapping subnet addresses, use this version instead
*/
if (((addr & mask ) == v->uv_subnet) &&
(v->uv_subnetmask == mask)) {
logit(LOG_WARNING, 0, "ignoring %s, same subnet as %s",
ifr.ifr_name, v->uv_name);
break;
}
#else
if ((addr & v->uv_subnetmask) == v->uv_subnet ||
(v->uv_subnet & mask) == subnet) {
logit(LOG_WARNING, 0, "ignoring %s, same subnet as %s",
ifr.ifr_name, v->uv_name);
break;
}
#endif /* 0 */
}
if (vifi != numvifs)
continue;
/*
* If there is room in the uvifs array, install this interface.
*/
if (numvifs == MAXVIFS) {
logit(LOG_WARNING, 0, "too many vifs, ignoring %s", ifr.ifr_name);
continue;
}
v = &uvifs[numvifs];
zero_vif(v, FALSE);
v->uv_lcl_addr = addr;
v->uv_subnet = subnet;
v->uv_subnetmask = mask;
v->uv_subnetbcast = subnet | ~mask;
strlcpy(v->uv_name, ifr.ifr_name, IFNAMSIZ);
if (flags & IFF_POINTOPOINT) {
v->uv_flags |= (VIFF_REXMIT_PRUNES | VIFF_POINT_TO_POINT);
if (ioctl(udp_socket, SIOCGIFDSTADDR, (char *)&ifr) < 0) {
logit(LOG_ERR, errno, "ioctl SIOCGIFDSTADDR for %s", v->uv_name);
} else {
v->uv_rmt_addr
= ((struct sockaddr_in *)(&ifr.ifr_dstaddr))->sin_addr.s_addr;
}
}
#ifdef Linux
{
struct ifreq ifridx;
memset(&ifridx, 0, sizeof(ifridx));
strlcpy(ifridx.ifr_name,v->uv_name, IFNAMSIZ);
if (ioctl(udp_socket, SIOGIFINDEX, (char *) &ifridx) < 0) {
logit(LOG_ERR, errno, "ioctl SIOGIFINDEX for %s",
ifridx.ifr_name);
/* Not reached */
return;
}
v->uv_ifindex = ifridx.ifr_ifindex;
}
if (flags & IFF_POINTOPOINT) {
logit(LOG_INFO, 0,
"installing %s (%s -> %s) as vif #%u-%d - rate=%d",
v->uv_name, inet_fmt(addr, s1, sizeof(s1)), inet_fmt(v->uv_rmt_addr, s2, sizeof(s2)),
numvifs, v->uv_ifindex, v->uv_rate_limit);
} else {
logit(LOG_INFO, 0,
"installing %s (%s on subnet %s) as vif #%u-%d - rate=%d",
v->uv_name, inet_fmt(addr, s1, sizeof(s1)), netname(subnet, mask),
numvifs, v->uv_ifindex, v->uv_rate_limit);
}
#else /* !Linux */
if (flags & IFF_POINTOPOINT) {
logit(LOG_INFO, 0,
"installing %s (%s -> %s) as vif #%u - rate=%d",
v->uv_name, inet_fmt(addr, s1, sizeof(s1)), inet_fmt(v->uv_rmt_addr, s2, sizeof(s2)),
numvifs, v->uv_rate_limit);
} else {
logit(LOG_INFO, 0,
"installing %s (%s on subnet %s) as vif #%u - rate=%d",
v->uv_name, inet_fmt(addr, s1, sizeof(s1)), netname(subnet, mask),
numvifs, v->uv_rate_limit);
}
#endif /* Linux */
++numvifs;
/*
* If the interface is not yet up, set the vifs_down flag to
* remind us to check again later.
*/
if (!(flags & IFF_UP)) {
v->uv_flags |= VIFF_DOWN;
vifs_down = TRUE;
}
}
}
#define UNKNOWN -1
#define EMPTY 1
#define PHYINT 2
#define CANDIDATE_RP 3
#define RP_ADDRESS 64
#define GROUP_PREFIX 4
#define BOOTSTRAP_RP 5
#define REG_THRESHOLD 6
#define DATA_THRESHOLD 7
#define DEFAULT_SOURCE_METRIC 8
#define DEFAULT_SOURCE_PREFERENCE 9
#define ALTNET 10
#define MASKLEN 11
#define SCOPED 12
/*
* function name: wordToOption
* input: char *word, a pointer to the word
* output: int; a number corresponding to the code of the word
* operation: converts the result of the string comparisons into numerics.
* comments: called by config_vifs_from_file()
*/
int
wordToOption(word)
char *word;
{
if (EQUAL(word, ""))
return EMPTY;
if (EQUAL(word, "phyint"))
return PHYINT;
if (EQUAL(word, "cand_rp"))
return CANDIDATE_RP;
if (EQUAL(word, "rp_address"))
return RP_ADDRESS;
if (EQUAL(word, "group_prefix"))
return GROUP_PREFIX;
if (EQUAL(word, "cand_bootstrap_router"))
return BOOTSTRAP_RP;
if (EQUAL(word, "switch_register_threshold"))
return REG_THRESHOLD;
if (EQUAL(word, "switch_data_threshold"))
return DATA_THRESHOLD;
if (EQUAL(word, "default_source_metric"))
return DEFAULT_SOURCE_METRIC;
if (EQUAL(word, "default_source_preference"))
return DEFAULT_SOURCE_PREFERENCE;
if (EQUAL(word, "altnet"))
return ALTNET;
if (EQUAL(word, "masklen"))
return MASKLEN;
if (EQUAL(word, "scoped"))
return SCOPED;
return UNKNOWN;
}
/**
* parse_phyint - parses the physical interface file configurations, if any.
* @s: pointing to the parsing point of the file
*
* Syntax:
* phyint <local-addr | ifname> [disable|enable]
* [threshold <t>] [preference <p>] [metric <m>]
* [altnet <net-addr> masklen <masklen>]
* [scoped <net-addr> masklen <masklen>]
*
* Returns:
* %TRUE if the parsing was successful, o.w. %FALSE
*/
static int parse_phyint(char *s)
{
char *w, c;
u_int32 local, altnet_addr, scoped_addr;
vifi_t vifi;
struct uvif *v;
u_int n, altnet_masklen, scoped_masklen;
struct phaddr *ph;
struct vif_acl *v_acl;
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0, "Missing phyint address in %s", configfilename);
return(FALSE);
} /* if empty */
local = ifname2addr(w);
if (!local) {
local = inet_parse(w, 4);
if (!inet_valid_host(local)) {
logit(LOG_WARNING, 0, "Invalid phyint address '%s' in %s", w,
configfilename);
return(FALSE);
} /* invalid address */
}
for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) {
if (vifi == numvifs) {
logit(LOG_WARNING, 0,
"phyint %s in %s is not a configured interface",
inet_fmt(local, s1, sizeof(s1)), configfilename);
return(FALSE);
} /* if vifi == numvifs */
if (local != v->uv_lcl_addr)
continue;
while (!EQUAL((w = next_word(&s)), "")) {
if (EQUAL(w, "disable")) {
v->uv_flags |= VIFF_DISABLED;
continue;
}
if (EQUAL(w, "enable")) {
v->uv_flags &= ~VIFF_DISABLED;
continue;
}
if (EQUAL(w, "altnet")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0, "Missing ALTNET for phyint %s in %s",
inet_fmt(local, s1, sizeof(s1)), configfilename);
continue;
}
altnet_addr = ifname2addr(w);
if (!altnet_addr) {
altnet_addr = inet_parse(w, 4);
if (!inet_valid_host(altnet_addr)) {
logit(LOG_WARNING, 0,
"Invalid altnet address '%s' in %s", w,
configfilename);
return(FALSE);
} /* invalid address */
}
if (EQUAL((w = next_word(&s)), "masklen")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing ALTNET masklen for phyint %s in %s",
inet_fmt(local, s1, sizeof (s1)), configfilename);
continue;
}
if (sscanf(w, "%u", &altnet_masklen) != 1) {
logit(LOG_WARNING, 0,
"Invalid altnet masklen '%s' for phyint %s in %s",
w, inet_fmt(local, s1, sizeof(s1)), configfilename);
continue;
}
}
ph = (struct phaddr *)malloc(sizeof(struct phaddr));
if (ph == NULL)
return(FALSE);
if (altnet_masklen) {
VAL_TO_MASK(ph->pa_subnetmask, altnet_masklen);
} else {
ph->pa_subnetmask = v->uv_subnetmask;
}
ph->pa_subnet = altnet_addr & ph->pa_subnetmask;
ph->pa_subnetbcast = ph->pa_subnet | ~ph->pa_subnetmask;
if (altnet_addr & ~ph->pa_subnetmask)
logit(LOG_WARNING,0, "Extra subnet %s/%d has host bits set",
inet_fmt(altnet_addr, s1, sizeof(s1)), altnet_masklen);
ph->pa_next = v->uv_addrs;
v->uv_addrs = ph;
logit(LOG_DEBUG, 0, "ALTNET: %s/%d", inet_fmt(altnet_addr, s1, sizeof(s1)),
altnet_masklen);
} /* altnet */
/* scoped mcast groups/masklen */
if (EQUAL(w, "scoped")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0, "Missing SCOPED for phyint %s in %s",
inet_fmt(local, s1, sizeof(s1)), configfilename);
continue;
}
scoped_addr = ifname2addr(w);
if (!scoped_addr) {
scoped_addr = inet_parse(w, 4);
if (!IN_MULTICAST(ntohl(scoped_addr))) {
logit(LOG_WARNING, 0,
"Invalid scoped address '%s' in %s", w,
configfilename);
return(FALSE);
} /* invalid address */
}
if (EQUAL((w = next_word(&s)), "masklen")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing SCOPED masklen for phyint %s in %s",
inet_fmt(local, s1, sizeof(s1)), configfilename);
continue;
}
if (sscanf(w, "%u", &scoped_masklen) != 1) {
logit(LOG_WARNING, 0,
"Invalid scoped masklen '%s' for phyint %s in %s",
w, inet_fmt(local, s1, sizeof(s1)), configfilename);
continue;
}
}
v_acl = (struct vif_acl *)malloc(sizeof(struct vif_acl));
if (v_acl == NULL)
return(FALSE);
VAL_TO_MASK(v_acl->acl_mask, scoped_masklen);
v_acl->acl_addr = scoped_addr & v_acl->acl_mask;
if (scoped_addr & ~v_acl->acl_mask)
logit(LOG_WARNING, 0,
"Boundary spec %s/%d has host bits set",
inet_fmt(scoped_addr, s1, sizeof(s1)),scoped_masklen);
v_acl->acl_next = v->uv_acl;
v->uv_acl = v_acl;
logit(LOG_DEBUG, 0, "SCOPED %s/%x",
inet_fmt(v_acl->acl_addr, s1, sizeof(s1)), v_acl->acl_mask);
} /* scoped */
if (EQUAL(w, "threshold")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing threshold for phyint %s in %s",
inet_fmt(local, s1, sizeof(s1)), configfilename);
continue;
}
if (sscanf(w, "%u%c", &n, &c) != 1 || n < 1 || n > 255 ) {
logit(LOG_WARNING, 0,
"Invalid threshold '%s' for phyint %s in %s",
w, inet_fmt(local, s1, sizeof(s1)), configfilename);
continue;
}
v->uv_threshold = n;
continue;
} /* threshold */
if (EQUAL(w, "preference")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing preference for phyint %s in %s",
inet_fmt(local, s1, sizeof(s1)), configfilename);
continue;
}
if (sscanf(w, "%u%c", &n, &c) != 1 || n < 1 || n > 255 ) {
logit(LOG_WARNING, 0,
"Invalid preference '%s' for phyint %s in %s",
w, inet_fmt(local, s1, sizeof(s1)),
configfilename);
continue;
}
IF_DEBUG(DEBUG_ASSERT)
logit(LOG_DEBUG, 0,
"Config setting default local preference on %s to %d.",
inet_fmt(local, s1, sizeof(s1)), n);
v->uv_local_pref = n;
continue;
}
if (EQUAL(w, "metric")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing metric for phyint %s in %s",
inet_fmt(local, s1, sizeof(s1)), configfilename);
continue;
}
if (sscanf(w, "%u%c", &n, &c) != 1 || n < 1 || n > 1024 ) {
logit(LOG_WARNING, 0,
"Invalid metric '%s' for phyint %s in %s",
w, inet_fmt(local, s1, sizeof(s1)),
configfilename);
continue;
}
IF_DEBUG(DEBUG_ASSERT)
logit(LOG_DEBUG, 0,
"Config setting default local metric on %s to %d.",
inet_fmt(local, s1, sizeof(s1)), n);
v->uv_local_metric = n;
continue;
}
} /* if not empty */
break;
}
return(TRUE);
}
/*
* function name: parse_candidateRP
* input: char *s
* output: int (TRUE if the parsing was successful, o.w. FALSE)
* operation: parses the candidate RP information.
* The general form is:
* 'cand_rp <local-addr> [priority <number>] [time <number>]'.
*/
int
parse_candidateRP(s)
char *s;
{
u_int time = PIM_DEFAULT_CAND_RP_ADV_PERIOD;
u_int priority = PIM_DEFAULT_CAND_RP_PRIORITY;
char *w;
u_int32 local = INADDR_ANY_N;
cand_rp_flag = FALSE;
my_cand_rp_adv_period = PIM_DEFAULT_CAND_RP_ADV_PERIOD;
while (!EQUAL((w = next_word(&s)), "")) {
if (EQUAL(w, "priority")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing priority; set to default %u (0 is highest)",
PIM_DEFAULT_CAND_RP_PRIORITY);
priority = PIM_DEFAULT_CAND_RP_PRIORITY;
continue;
}
if (sscanf(w, "%u", &priority) != 1) {
logit(LOG_WARNING, 0,
"invalid priority %s; set to default %u (0 is highest)",
PIM_DEFAULT_CAND_RP_PRIORITY);
priority = PIM_DEFAULT_CAND_RP_PRIORITY;
}
continue;
}
if (EQUAL(w, "time")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing cand_rp_adv_period value; set to default %u",
PIM_DEFAULT_CAND_RP_ADV_PERIOD);
time = PIM_DEFAULT_CAND_RP_ADV_PERIOD;
continue;
}
if (sscanf(w, "%u", &time) != 1) {
logit(LOG_WARNING, 0,
"Invalid cand_rp_adv_period value; set to default %u",
PIM_DEFAULT_CAND_RP_ADV_PERIOD);
time = PIM_DEFAULT_CAND_RP_ADV_PERIOD;
continue;
}
if (time > (my_cand_rp_adv_period = ~0))
time = my_cand_rp_adv_period;
/* TODO: XXX: cannot be shorter than 10 seconds (not in the spec)*/
if (time < 10)
time = 10;
#if 0
if (time > PIM_DEFAULT_CAND_RP_ADV_PERIOD)
time = PIM_DEFAULT_CAND_RP_ADV_PERIOD;
#endif /* 0 */
my_cand_rp_adv_period = time;
continue;
}
/* Cand-RP address */
local = inet_parse(w, 4);
if (!inet_valid_host(local)) {
local = max_local_address();
logit(LOG_WARNING, 0,
"Invalid Cand-RP address provided '%s' in %s. Will use the largest enabled local address.",
w, configfilename);
} else if (local_address(local) == NO_VIF) {
local = max_local_address();
logit(LOG_WARNING, 0, "Cand-RP address is not local '%s' in %s. Will use the largest enabled local address.",
w, configfilename);
}
} /* while not empty */
if (local == INADDR_ANY_N)
/* If address not provided, use the max. local */
local = max_local_address();
my_cand_rp_address = local;
my_cand_rp_priority = priority;
my_cand_rp_adv_period = time;
cand_rp_flag = TRUE;
logit(LOG_INFO, 0, "Local Cand-RP address is %s", inet_fmt(local, s1, sizeof(s1)));
logit(LOG_INFO, 0, "Local Cand-RP priority is %u", priority);
logit(LOG_INFO, 0, "Local Cand-RP advertisement period is %u sec.", time);
return(TRUE);
}
/*
* function name: parse_group_prefix
* input: char *s
* output: int
* operation: parse group_prefix configured information.
* General form: 'group_prefix <group-addr> [masklen <masklen>]'.
*/
int
parse_group_prefix(s)
char *s;
{
char *w;
u_int32 group_addr;
u_int32 masklen;
w = next_word(&s);
if (EQUAL(w, "")) {
logit(LOG_WARNING, 0,
"Configuration error for 'group_prefix' in %s: no group_addr. Ignoring...", configfilename);
return(FALSE);
}
group_addr = inet_parse(w, 4);
if (!IN_MULTICAST(ntohl(group_addr))) {
logit(LOG_WARNING, 0,
"Config error for 'group_prefix' in %s: %s is not a mcast addr. Ignoring...", configfilename, inet_fmt(group_addr, s1, sizeof(s1)));
return(FALSE);
}
/* Was if (!(~(*cand_rp_adv_message.prefix_cnt_ptr))) which Arm GCC 4.4.2 dislikes:
* --> "config.c:693: warning: promoted ~unsigned is always non-zero"
* The prefix_cnt_ptr is a u_int8 so it seems this check was to prevent overruns.
* I've changed the check to see if we've already read 255 entries, if so the cnt
* is maximized and we need to tell the user. --Joachim Nilsson 2010-01-16 */
if (*cand_rp_adv_message.prefix_cnt_ptr == 255) {
logit(LOG_WARNING, 0,
"Too many group_prefix configured. Truncating...");
return(FALSE);
}
if (EQUAL((w = next_word(&s)), "masklen")) {
w = next_word(&s);
if (sscanf(w, "%u", &masklen) == 1) {
if (masklen > (sizeof(group_addr)*8))
masklen = (sizeof(group_addr)*8);
else
if (masklen < 4)
masklen = 4;
}
else
masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN;
}
else
masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN;
PUT_EGADDR(group_addr, (u_int8)masklen, 0,
cand_rp_adv_message.insert_data_ptr);
(*cand_rp_adv_message.prefix_cnt_ptr)++;
logit(LOG_INFO, 0, "Adding prefix %s/%d", inet_fmt(group_addr, s1, sizeof(s1)), masklen);
return(TRUE);
}
/*
* function name: parseBSR
* input: char *s
* output: int
* operation: parse the candidate BSR configured information.
* General form:
* 'cand_bootstrap_router <local-addr> [priority <number>]'.
*/
int
parseBSR(s)
char *s;
{
char *w;
u_int32 local = INADDR_ANY_N;
u_int32 priority = PIM_DEFAULT_BSR_PRIORITY;
cand_bsr_flag = FALSE;
while (!EQUAL((w = next_word(&s)), "")) {
if (EQUAL(w, "priority")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing priority; set to default %u (0 is lowest)\n",
PIM_DEFAULT_BSR_PRIORITY);
priority = PIM_DEFAULT_BSR_PRIORITY;
continue;
}
if (sscanf(w, "%u", &priority) != 1) {
logit(LOG_WARNING, 0,
"invalid priority %s; set to default %u (0 is lowest)",
PIM_DEFAULT_BSR_PRIORITY);
priority = PIM_DEFAULT_BSR_PRIORITY;
continue;
}
if (priority > (my_bsr_priority = ~0))
priority = my_bsr_priority;
my_bsr_priority = (u_int8)priority;
continue;
}
/* BSR address */
local = inet_parse(w, 4);
if (!inet_valid_host(local)) {
local = max_local_address();
logit(LOG_WARNING, 0, "Invalid BSR address provided '%s' in %s. Will use the largest enabled local address.",
w, configfilename);
continue;
}
if (local_address(local) == NO_VIF) {
local = max_local_address();
logit(LOG_WARNING, 0,
"Cand-BSR address is not local '%s' in %s. Will use the largest enabled local address.",
w, configfilename);
}
} /* while not empty */
if (local == INADDR_ANY_N)
/* If address not provided, use the max. local */
local = max_local_address();
my_bsr_address = local;
my_bsr_priority = priority;
MASKLEN_TO_MASK(RP_DEFAULT_IPV4_HASHMASKLEN, my_bsr_hash_mask);
cand_bsr_flag = TRUE;
logit(LOG_INFO, 0, "Local Cand-BSR address is %s", inet_fmt(local, s1, sizeof(s1)));
logit(LOG_INFO, 0, "Local Cand-BSR priority is %u", priority);
return(TRUE);
}
/**
* parse_rp_address - Parse rp_address config option.
* @s: String token.
*
* This is an extension to the original pimd to add pimd.conf support for static
* Rendez-Vous Point addresses.
*
* The function has been extended by pjf@asn.pl, of Lintrack, to allow specifying
* multicast group addresses as well.
*
* Format:
* rp_address <rp-address>
*
* Returns:
* When parsing @s is successful this function returns %TRUE, otherwise %FALSE.
*/
int parse_rp_address(char *s)
{
char *w;
u_int32 local = 0xffffff;
u_int32 group_addr;
u_int32 masklen;
struct rp_hold * rph;
w = next_word(&s);
if (EQUAL(w, "")) {
logit(LOG_WARNING, 0, "'rp_address' in %s: no <rp-addr> - ignoring", configfilename);
return FALSE;
}
local = inet_parse(w, 4);
if (local == 0xffffff) {
logit(LOG_WARNING, 0, "'rp_address' in %s: invalid <rp-addr> provided: '%s'", configfilename, w);
return FALSE;
}
w = next_word(&s);
if (!EQUAL(w, "")) {
group_addr = inet_parse(w, 4);
if (!IN_MULTICAST(ntohl(group_addr))) {
logit(LOG_WARNING, 0, "'rp_address' in %s: %s is not a multicast addr", configfilename, inet_fmt(group_addr, s1, sizeof(s1)));
return FALSE;
}
if (EQUAL((w = next_word(&s)), "masklen")) {
w = next_word(&s);
if (sscanf(w, "%u", &masklen) == 1) {
if (masklen > (sizeof(group_addr) * 8))
masklen = (sizeof(group_addr) * 8);
else if (masklen < 4)
masklen = 4;
}
else
masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN;
}
else
masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN;
}
else {
group_addr = htonl(224 << 24);
masklen = 4;
}
/* save */
rph = malloc(sizeof(*rph));
rph->address = local;
rph->group = group_addr;
VAL_TO_MASK(rph->mask, masklen);
/* attach at the beginning */
rph->next = g_rp_hold;
g_rp_hold = rph;
logit(LOG_INFO, 0, "Added static RP: %s, group %s/%d", inet_fmt(local, s1, sizeof(s1)), inet_fmt(group_addr, s2, sizeof(s2)), masklen);
return TRUE;
}
/*
* function name: parse_reg_threshold
* input: char *s
* output: int (TRUE if successful, FALSE o.w.)
* operation: reads and assigns the switch to the spt threshold
* due to registers for the router, if used as RP.
* Maybe extended to support different thresholds
* for different groups(prefixes).
* General form:
* 'switch_register_threshold [rate <number> interval <number>]'.
* comments: called by config_vifs_from_file()
*/
int parse_reg_threshold(char *s)
{
char *w;
u_int rate;
u_int interval;
rate = PIM_DEFAULT_REG_RATE;
interval = PIM_DEFAULT_REG_RATE_INTERVAL;
pim_reg_rate_bytes = (rate * interval) / 10;
pim_reg_rate_check_interval = interval;
while (!EQUAL((w = next_word(&s)), "")) {
if (EQUAL(w, "rate")) {
/* rate */
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing reg_rate value; set to default %u (bits/s)\n",
PIM_DEFAULT_REG_RATE);
rate = PIM_DEFAULT_REG_RATE;
continue;
}
if (sscanf(w, "%u", &rate) != 1) {
logit(LOG_WARNING, 0,
"Invalid reg_rate value %s; set to default %u (bits/s)",
w, PIM_DEFAULT_REG_RATE);
rate = PIM_DEFAULT_REG_RATE;
}
continue;
} /* if rate */
if (EQUAL(w, "interval")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing reg_rate interval; set to default %u seconds",
PIM_DEFAULT_REG_RATE_INTERVAL);
interval = PIM_DEFAULT_REG_RATE_INTERVAL;
continue;
}
if (sscanf(w, "%u", &interval) != 1) {
logit(LOG_WARNING, 0,
"Invalid reg_rate interval %s; set to default %u seconds",
w, PIM_DEFAULT_REG_RATE_INTERVAL);
interval = PIM_DEFAULT_REG_RATE_INTERVAL;
}
continue;
} /* if interval */
logit(LOG_WARNING, 0, "Invalid parameter %s; setting rate and interval to default", w);
rate = PIM_DEFAULT_REG_RATE;
interval = PIM_DEFAULT_REG_RATE_INTERVAL;
break;
} /* while not empty */
if (interval < TIMER_INTERVAL) {
logit(LOG_WARNING, 0,
"reg_rate interval too short; set to default %u seconds",
PIM_DEFAULT_REG_RATE_INTERVAL);
interval = PIM_DEFAULT_REG_RATE_INTERVAL;
}
logit(LOG_INFO, 0, "reg_rate_limit is %u (bits/s)", rate);
logit(LOG_INFO, 0, "reg_rate_interval is %u (seconds)", interval);
pim_reg_rate_bytes = (rate * interval) / 10;
pim_reg_rate_check_interval = interval;
return(TRUE);
}
/*
* function name: parse_data_threshold
* input: char *s
* output: int
* operation: reads and assigns the switch to the spt threshold
* due to data packets, if used as DR.
* General form:
* 'switch_data_threshold [rate <number> interval <number>]'.
*/
int parse_data_threshold(char *s)
{
char *w;
u_int rate;
u_int interval;
rate = PIM_DEFAULT_DATA_RATE;
interval = PIM_DEFAULT_DATA_RATE_INTERVAL;
pim_data_rate_bytes = (rate * interval) / 10;
pim_data_rate_check_interval = interval;
while (!EQUAL((w = next_word(&s)), "")) {
if (EQUAL(w, "rate")) {
if (EQUAL((w = next_word(&s)), "")) {
logit(LOG_WARNING, 0,
"Missing data_rate value; set to default %u (bits/s)\n",
PIM_DEFAULT_DATA_RATE);
rate = PIM_DEFAULT_DATA_RATE;
continue;
}
if (sscanf(w, "%u", &rate) != 1) {
logit(LOG_WARNING, 0,
"Invalid data_rate value %s; set to default %u (bits/s)",
w, PIM_DEFAULT_DATA_RATE);
rate = PIM_DEFAULT_DATA_RATE;
}
continue;
} /* if rate */
if (EQUAL(w, "interval")) {
if (EQUAL((w = next_word(&s)), "")) {