-
Notifications
You must be signed in to change notification settings - Fork 107
/
gram.y
1185 lines (1023 loc) · 23.9 KB
/
gram.y
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
/*
*
* Authors:
* Pedro Roque <[email protected]>
* Lars Fenneberg <[email protected]>
*
* This software is Copyright 1996-2000 by the above mentioned author(s),
* All Rights Reserved.
*
* The license which is distributed with this software in the file COPYRIGHT
* applies to this software. If your distribution is missing this file, you
* may request it from <[email protected]>.
*
*/
%{
#include "config.h"
#include "includes.h"
#include "radvd.h"
#include "defaults.h"
#define YYERROR_VERBOSE 1
int yylex (void);
void yyset_in (FILE * _in_str);
int yylex_destroy (void);
#if 0 /* no longer necessary? */
#ifndef HAVE_IN6_ADDR_S6_ADDR
# ifdef __FreeBSD__
# define s6_addr32 __u6_addr.__u6_addr32
# define s6_addr16 __u6_addr.__u6_addr16
# endif
#endif
#endif
#define ADD_TO_LL(type, list, value) \
do { \
if (iface->list == NULL) \
iface->list = value; \
else { \
type *current = iface->list; \
while (current->next != NULL) \
current = current->next; \
current->next = value; \
} \
} while (0)
%}
%token T_INTERFACE
%token T_PREFIX
%token T_ROUTE
%token T_RDNSS
%token T_DNSSL
%token T_CLIENTS
%token T_LOWPANCO
%token T_ABRO
%token T_RASRCADDRESS
%token T_NAT64PREFIX
%token T_AUTOIGNOREPREFIX
%token <str> STRING
%token <num> NUMBER
%token <snum> SIGNEDNUMBER
%token <dec> DECIMAL
%token <num> SWITCH
%token <addr> IPV6ADDR
%token <addr> NOT_IPV6ADDR
%token INFINITY
%token T_IgnoreIfMissing
%token T_AdvSendAdvert
%token T_MaxRtrAdvInterval
%token T_MinRtrAdvInterval
%token T_MinDelayBetweenRAs
%token T_AdvManagedFlag
%token T_AdvOtherConfigFlag
%token T_AdvLinkMTU
%token T_AdvRAMTU
%token T_AdvReachableTime
%token T_AdvRetransTimer
%token T_AdvCurHopLimit
%token T_AdvDefaultLifetime
%token T_AdvDefaultPreference
%token T_AdvSourceLLAddress
%token T_RemoveAdvOnExit
%token T_AdvOnLink
%token T_AdvAutonomous
%token T_AdvValidLifetime
%token T_AdvPreferredLifetime
%token T_DeprecatePrefix
%token T_DecrementLifetimes
%token T_AdvRouterAddr
%token T_AdvHomeAgentFlag
%token T_AdvIntervalOpt
%token T_AdvHomeAgentInfo
%token T_Base6Interface
%token T_Base6to4Interface
%token T_UnicastOnly
%token T_UnrestrictedUnicast
%token T_AdvRASolicitedUnicast
%token T_AdvCaptivePortalAPI
%token T_HomeAgentPreference
%token T_HomeAgentLifetime
%token T_AdvRoutePreference
%token T_AdvRouteLifetime
%token T_RemoveRoute
%token T_AdvRDNSSPreference
%token T_AdvRDNSSOpenFlag
%token T_AdvRDNSSLifetime
%token T_FlushRDNSS
%token T_AdvDNSSLLifetime
%token T_FlushDNSSL
%token T_AdvMobRtrSupportFlag
%token T_AdvContextLength
%token T_AdvContextCompressionFlag
%token T_AdvContextID
%token T_AdvLifeTime
%token T_AdvContextPrefix
%token T_AdvVersionLow
%token T_AdvVersionHigh
%token T_Adv6LBRaddress
%token T_BAD_TOKEN
%type <str> name
%type <pinfo> prefixdef
%type <ainfo> clientslist v6addrlist_clients
%type <rinfo> routedef
%type <rdnssinfo> rdnssdef
%type <dnsslinfo> dnssldef
%type <lowpancoinfo> lowpancodef
%type <abroinfo> abrodef
%type <num> number_or_infinity
%type <rasrcaddressinfo> rasrcaddresslist v6addrlist_rasrcaddress
%type <nat64pinfo> nat64prefixdef
%type <igpinfo> ignoreprefixlist ignoreprefixes
%union {
unsigned int num;
int snum;
double dec;
struct in6_addr *addr;
char *str;
struct AdvPrefix *pinfo;
struct AdvRoute *rinfo;
struct AdvRDNSS *rdnssinfo;
struct AdvDNSSL *dnsslinfo;
struct Clients *ainfo;
struct AdvLowpanCo *lowpancoinfo;
struct AdvAbro *abroinfo;
struct AdvRASrcAddress *rasrcaddressinfo;
struct NAT64Prefix *nat64pinfo;
struct AutogenIgnorePrefix *igpinfo;
};
%{
extern int num_lines;
static char const * filename;
static struct Interface *iface;
static struct Interface *IfaceList;
static struct AdvPrefix *prefix;
static struct AdvRoute *route;
static struct AdvRDNSS *rdnss;
static struct AdvDNSSL *dnssl;
static struct AdvLowpanCo *lowpanco;
static struct AdvAbro *abro;
static struct NAT64Prefix *nat64prefix;
static void cleanup(void);
#define ABORT do { cleanup(); YYABORT; } while (0);
static void yyerror(char const * msg);
%}
%%
grammar : grammar ifacedef
| ifacedef
;
ifacedef : ifacehead '{' ifaceparams '}' ';'
{
dlog(LOG_DEBUG, 4, "%s interface definition ok", iface->props.name);
iface->next = IfaceList;
IfaceList = iface;
iface = NULL;
};
ifacehead : T_INTERFACE name
{
iface = IfaceList;
while (iface)
{
if (!strcmp($2, iface->props.name))
{
flog(LOG_ERR, "duplicate interface "
"definition for %s", $2);
ABORT;
}
iface = iface->next;
}
iface = malloc(sizeof(struct Interface));
if (iface == NULL) {
flog(LOG_CRIT, "malloc failed: %s", strerror(errno));
ABORT;
}
iface_init_defaults(iface);
memset(&iface->props.name, 0, sizeof(iface->props.name));
strlcpy(iface->props.name, $2, sizeof(iface->props.name));
iface->lineno = num_lines;
}
;
name : STRING
{
/* check vality */
$$ = $1;
}
;
ifaceparams : ifaceparams ifaceparam /* This is left recursion and won't overrun the stack. */
| /* empty */
;
ifaceparam : ifaceval
| prefixdef { ADD_TO_LL(struct AdvPrefix, AdvPrefixList, $1); }
| clientslist { ADD_TO_LL(struct Clients, ClientList, $1); }
| routedef { ADD_TO_LL(struct AdvRoute, AdvRouteList, $1); }
| rdnssdef { ADD_TO_LL(struct AdvRDNSS, AdvRDNSSList, $1); }
| dnssldef { ADD_TO_LL(struct AdvDNSSL, AdvDNSSLList, $1); }
| lowpancodef { ADD_TO_LL(struct AdvLowpanCo, AdvLowpanCoList, $1); }
| abrodef { ADD_TO_LL(struct AdvAbro, AdvAbroList, $1); }
| rasrcaddresslist { ADD_TO_LL(struct AdvRASrcAddress, AdvRASrcAddressList, $1); }
| nat64prefixdef { ADD_TO_LL(struct NAT64Prefix, NAT64PrefixList, $1); }
| ignoreprefixlist { ADD_TO_LL(struct AutogenIgnorePrefix, IgnorePrefixList, $1); }
;
ifaceval : T_MinRtrAdvInterval NUMBER ';'
{
iface->MinRtrAdvInterval = $2;
}
| T_MaxRtrAdvInterval NUMBER ';'
{
iface->MaxRtrAdvInterval = $2;
}
| T_MinDelayBetweenRAs NUMBER ';'
{
iface->MinDelayBetweenRAs = $2;
}
| T_MinRtrAdvInterval DECIMAL ';'
{
iface->MinRtrAdvInterval = $2;
}
| T_MaxRtrAdvInterval DECIMAL ';'
{
iface->MaxRtrAdvInterval = $2;
}
| T_MinDelayBetweenRAs DECIMAL ';'
{
iface->MinDelayBetweenRAs = $2;
}
| T_IgnoreIfMissing SWITCH ';'
{
iface->IgnoreIfMissing = $2;
}
| T_AdvSendAdvert SWITCH ';'
{
iface->AdvSendAdvert = $2;
}
| T_AdvManagedFlag SWITCH ';'
{
iface->ra_header_info.AdvManagedFlag = $2;
}
| T_AdvOtherConfigFlag SWITCH ';'
{
iface->ra_header_info.AdvOtherConfigFlag = $2;
}
| T_AdvLinkMTU NUMBER ';'
{
iface->AdvLinkMTU = $2;
}
| T_AdvRAMTU NUMBER ';'
{
iface->AdvRAMTU = $2;
iface->AdvRAMTU = MAX(MIN_AdvLinkMTU, iface->AdvRAMTU);
iface->AdvRAMTU = MIN(MAX_AdvLinkMTU, iface->AdvRAMTU);
}
| T_AdvReachableTime NUMBER ';'
{
iface->ra_header_info.AdvReachableTime = $2;
}
| T_AdvRetransTimer NUMBER ';'
{
iface->ra_header_info.AdvRetransTimer = $2;
}
| T_AdvDefaultLifetime NUMBER ';'
{
iface->ra_header_info.AdvDefaultLifetime = $2;
}
| T_AdvDefaultPreference SIGNEDNUMBER ';'
{
iface->ra_header_info.AdvDefaultPreference = $2;
}
| T_AdvCurHopLimit NUMBER ';'
{
iface->ra_header_info.AdvCurHopLimit = $2;
}
| T_RemoveAdvOnExit SWITCH ';'
{
iface->RemoveAdvOnExit = $2;
}
| T_AdvSourceLLAddress SWITCH ';'
{
iface->AdvSourceLLAddress = $2;
}
| T_AdvIntervalOpt SWITCH ';'
{
iface->mipv6.AdvIntervalOpt = $2;
}
| T_AdvHomeAgentInfo SWITCH ';'
{
iface->mipv6.AdvHomeAgentInfo = $2;
}
| T_AdvHomeAgentFlag SWITCH ';'
{
iface->ra_header_info.AdvHomeAgentFlag = $2;
}
| T_HomeAgentPreference NUMBER ';'
{
iface->mipv6.HomeAgentPreference = $2;
}
| T_HomeAgentLifetime NUMBER ';'
{
iface->mipv6.HomeAgentLifetime = $2;
}
| T_UnicastOnly SWITCH ';'
{
iface->UnicastOnly = $2;
}
| T_UnrestrictedUnicast SWITCH ';'
{
iface->UnrestrictedUnicast = $2;
}
| T_AdvRASolicitedUnicast SWITCH ';'
{
iface->AdvRASolicitedUnicast = $2;
}
| T_AdvCaptivePortalAPI STRING ';'
{
const char *source = $2;
size_t len = strlen(source);
if (iface->AdvCaptivePortalAPI) {
flog(LOG_WARNING, "warning: AdvCaptivePortalAPI specified twice for interface "
"%s in %s, line %d", iface->props.name, filename, num_lines);
free(iface->AdvCaptivePortalAPI);
iface->AdvCaptivePortalAPI = NULL;
}
/* trim double-quotes from start and end of string */
if ((len > 0) && (source[0] == '"')) {
source++;
len--;
}
if ((len > 0) && (source[len-1] == '"')) {
len--;
}
if (len <= 0) {
flog(LOG_ERR, "AdvCaptivePortalAPI empty URL specified for interface %s.", iface->props.name);
ABORT;
}
iface->AdvCaptivePortalAPI = strndup(source, len);
if (!iface->AdvCaptivePortalAPI) {
flog(LOG_CRIT, "malloc failed: %s", strerror(errno));
ABORT;
}
}
| T_AdvMobRtrSupportFlag SWITCH ';'
{
iface->mipv6.AdvMobRtrSupportFlag = $2;
}
;
clientslist : T_CLIENTS '{' v6addrlist_clients '}' ';'
{
$$ = $3;
}
;
v6addrlist_clients : IPV6ADDR ';'
{
struct Clients *new = calloc(1, sizeof(struct Clients));
if (new == NULL) {
flog(LOG_CRIT, "calloc failed: %s", strerror(errno));
ABORT;
}
memcpy(&(new->Address), $1, sizeof(struct in6_addr));
new->ignored = 0;
$$ = new;
}
| NOT_IPV6ADDR ';'
{
struct Clients *new = calloc(1, sizeof(struct Clients));
if (new == NULL) {
flog(LOG_CRIT, "calloc failed: %s", strerror(errno));
ABORT;
}
memcpy(&(new->Address), $1, sizeof(struct in6_addr));
new->ignored = 1;
$$ = new;
}
| v6addrlist_clients IPV6ADDR ';'
{
struct Clients *new = calloc(1, sizeof(struct Clients));
if (new == NULL) {
flog(LOG_CRIT, "calloc failed: %s", strerror(errno));
ABORT;
}
memcpy(&(new->Address), $2, sizeof(struct in6_addr));
new->ignored = 0;
new->next = $1;
$$ = new;
}
| v6addrlist_clients NOT_IPV6ADDR ';'
{
struct Clients *new = calloc(1, sizeof(struct Clients));
if (new == NULL) {
flog(LOG_CRIT, "calloc failed: %s", strerror(errno));
ABORT;
}
memcpy(&(new->Address), $2, sizeof(struct in6_addr));
new->ignored = 1;
new->next = $1;
$$ = new;
}
;
rasrcaddresslist : T_RASRCADDRESS '{' v6addrlist_rasrcaddress '}' ';'
{
$$ = $3;
}
;
v6addrlist_rasrcaddress : IPV6ADDR ';'
{
struct AdvRASrcAddress *new = calloc(1, sizeof(struct AdvRASrcAddress));
if (new == NULL) {
flog(LOG_CRIT, "calloc failed: %s", strerror(errno));
ABORT;
}
memcpy(&(new->address), $1, sizeof(struct in6_addr));
$$ = new;
}
| v6addrlist_rasrcaddress IPV6ADDR ';'
{
struct AdvRASrcAddress *new = calloc(1, sizeof(struct AdvRASrcAddress));
if (new == NULL) {
flog(LOG_CRIT, "calloc failed: %s", strerror(errno));
ABORT;
}
memcpy(&(new->address), $2, sizeof(struct in6_addr));
new->next = $1;
$$ = new;
}
;
nat64prefixdef : nat64prefixhead optional_nat64prefixplist ';'
{
if (nat64prefix) {
if (nat64prefix->AdvValidLifetime > DFLT_NAT64MaxValidLifetime)
{
flog(LOG_ERR, "AdvValidLifetime must be "
"smaller or equal to %d in %s, line %d",
DFLT_NAT64MaxValidLifetime, filename, num_lines);
ABORT;
}
nat64prefix->curr_validlft = nat64prefix->AdvValidLifetime;
}
$$ = nat64prefix;
nat64prefix = NULL;
}
;
nat64prefixhead : T_NAT64PREFIX IPV6ADDR '/' NUMBER
{
struct in6_addr zeroaddr;
memset(&zeroaddr, 0, sizeof(zeroaddr));
if (!memcmp($2, &zeroaddr, sizeof(struct in6_addr))) {
flog(LOG_ERR, "invalid all-zeros nat64prefix in %s, line %d", filename, num_lines);
ABORT;
}
nat64prefix = malloc(sizeof(struct NAT64Prefix));
if (nat64prefix == NULL) {
flog(LOG_CRIT, "malloc failed: %s", strerror(errno));
ABORT;
}
nat64prefix_init_defaults(nat64prefix, iface);
if ($4 > MAX_PrefixLen)
{
flog(LOG_ERR, "invalid prefix length in %s, line %d", filename, num_lines);
ABORT;
}
/* RFC8781, section 4: only prefix lengths of 96, 64, 56, 48, 40, and 32 bits are valid */
switch ($4) {
case 32:
case 40:
case 48:
case 56:
case 64:
case 96:
break;
default:
flog(LOG_ERR, "only /96, /64, /56, /48, /40 and /32 are allowed for "
"nat64prefix in %s:%d", filename, num_lines);
ABORT;
}
nat64prefix->PrefixLen = $4;
memcpy(&nat64prefix->Prefix, $2, sizeof(struct in6_addr));
}
;
optional_nat64prefixplist: /* empty */
| '{' /* somewhat empty */ '}'
| '{' nat64prefixplist '}'
;
nat64prefixplist : nat64prefixplist nat64prefixparms
| nat64prefixparms
;
nat64prefixparms : T_AdvValidLifetime NUMBER ';'
{
if ($2 > DFLT_NAT64MaxValidLifetime)
{
flog(LOG_ERR, "maximum for NAT64 AdvValidLifetime is %d (in %s, line %d)",
DFLT_NAT64MaxValidLifetime, filename, num_lines);
ABORT;
}
if (nat64prefix) {
nat64prefix->AdvValidLifetime = $2;
}
}
;
ignoreprefixlist : T_AUTOIGNOREPREFIX '{' ignoreprefixes '}' ';'
{
$$ = $3;
}
;
ignoreprefixes : IPV6ADDR '/' NUMBER ';'
{
struct AutogenIgnorePrefix *new = calloc(1, sizeof(struct AutogenIgnorePrefix));
if (new == NULL) {
flog(LOG_CRIT, "calloc failed: %s", strerror(errno));
ABORT;
}
memcpy(&(new->Prefix), $1, sizeof(struct in6_addr));
// Create subnet mask from CIDR notation
int fullOctets = $3 / 8;
for (int i = 0; i < fullOctets; ++i) {
new->Mask.s6_addr[i] = 0xff;
}
if (fullOctets != 16) {
new->Mask.s6_addr[fullOctets] = ~(1 << (8 - $3 % 8)) + 1;
}
$$ = new;
}
| ignoreprefixes IPV6ADDR '/' NUMBER ';'
{
struct AutogenIgnorePrefix *new = calloc(1, sizeof(struct AutogenIgnorePrefix));
if (new == NULL) {
flog(LOG_CRIT, "calloc failed: %s", strerror(errno));
ABORT;
}
memcpy(&(new->Prefix), $2, sizeof(struct in6_addr));
// Create subnet mask from CIDR notation
int fullOctets = $4 / 8;
for (int i = 0; i < fullOctets; ++i) {
new->Mask.s6_addr[i] = 0xff;
}
if (fullOctets != 16) {
new->Mask.s6_addr[fullOctets] = ~(1 << (8 - $4 % 8)) + 1;
}
new->next = $1;
$$ = new;
}
;
prefixdef : prefixhead optional_prefixplist ';'
{
if (prefix) {
if (prefix->AdvPreferredLifetime > prefix->AdvValidLifetime)
{
flog(LOG_ERR, "AdvValidLifetime must be "
"greater than or equal to AdvPreferredLifetime in %s, line %d",
filename, num_lines);
ABORT;
}
if ( prefix->if6[0] )
{
if (prefix->PrefixLen != 64) {
flog(LOG_ERR, "only /64 is allowed with Base6Interface. %s:%d", filename, num_lines);
ABORT;
}
}
}
$$ = prefix;
prefix = NULL;
}
;
prefixhead : T_PREFIX IPV6ADDR '/' NUMBER
{
struct in6_addr zeroaddr;
memset(&zeroaddr, 0, sizeof(zeroaddr));
#ifndef HAVE_IFADDRS_H // all-zeros prefix is a way to tell us to get the prefix from the interface config
if (!memcmp($2, &zeroaddr, sizeof(struct in6_addr))) {
flog(LOG_WARNING, "invalid all-zeros prefix in %s, line %d", filename, num_lines);
}
#endif
prefix = malloc(sizeof(struct AdvPrefix));
if (prefix == NULL) {
flog(LOG_CRIT, "malloc failed: %s", strerror(errno));
ABORT;
}
prefix_init_defaults(prefix);
if ($4 > MAX_PrefixLen)
{
flog(LOG_ERR, "invalid prefix length in %s, line %d", filename, num_lines);
ABORT;
}
prefix->PrefixLen = $4;
memcpy(&prefix->Prefix, $2, sizeof(struct in6_addr));
}
;
optional_prefixplist: /* empty */
| '{' /* somewhat empty */ '}'
| '{' prefixplist '}'
;
prefixplist : prefixplist prefixparms
| prefixparms
;
prefixparms : T_AdvOnLink SWITCH ';'
{
if (prefix) {
prefix->AdvOnLinkFlag = $2;
}
}
| T_AdvAutonomous SWITCH ';'
{
if (prefix) {
prefix->AdvAutonomousFlag = $2;
}
}
| T_AdvRouterAddr SWITCH ';'
{
if (prefix) {
prefix->AdvRouterAddr = $2;
}
}
| T_AdvValidLifetime number_or_infinity ';'
{
if (prefix) {
prefix->AdvValidLifetime = $2;
prefix->curr_validlft = $2;
}
}
| T_AdvPreferredLifetime number_or_infinity ';'
{
if (prefix) {
prefix->AdvPreferredLifetime = $2;
prefix->curr_preferredlft = $2;
}
}
| T_DeprecatePrefix SWITCH ';'
{
if (prefix) {
prefix->DeprecatePrefixFlag = $2;
}
}
| T_DecrementLifetimes SWITCH ';'
{
if (prefix) {
prefix->DecrementLifetimesFlag = $2;
}
}
| T_Base6Interface name ';'
{
#ifndef HAVE_IFADDRS_H
flog(LOG_ERR, "Base6Interface not supported in %s, line %d", filename, num_lines);
ABORT;
#else
if (prefix) {
dlog(LOG_DEBUG, 4, "using prefixes on interface %s for prefixes on interface %s", $2, iface->props.name);
memset(&prefix->if6, 0, sizeof(prefix->if6));
strlcpy(prefix->if6, $2, sizeof(prefix->if6));
}
#endif
}
| T_Base6to4Interface name ';'
{
#ifndef HAVE_IFADDRS_H
flog(LOG_ERR, "Base6to4Interface not supported in %s, line %d", filename, num_lines);
ABORT;
#else
if (prefix) {
dlog(LOG_DEBUG, 4, "using interface %s for 6to4 prefixes on interface %s", $2, iface->props.name);
memset(&prefix->if6to4, 0, sizeof(prefix->if6to4));
strlcpy(prefix->if6to4, $2, sizeof(prefix->if6to4));
}
#endif
}
;
routedef : routehead '{' optional_routeplist '}' ';'
{
$$ = route;
route = NULL;
}
;
routehead : T_ROUTE IPV6ADDR '/' NUMBER
{
route = malloc(sizeof(struct AdvRoute));
if (route == NULL) {
flog(LOG_CRIT, "malloc failed: %s", strerror(errno));
ABORT;
}
route_init_defaults(route, iface);
if ($4 > MAX_PrefixLen)
{
flog(LOG_ERR, "invalid route prefix length in %s, line %d", filename, num_lines);
ABORT;
}
route->PrefixLen = $4;
memcpy(&route->Prefix, $2, sizeof(struct in6_addr));
}
;
optional_routeplist: /* empty */
| routeplist
;
routeplist : routeplist routeparms
| routeparms
;
routeparms : T_AdvRoutePreference SIGNEDNUMBER ';'
{
route->AdvRoutePreference = $2;
}
| T_AdvRouteLifetime number_or_infinity ';'
{
route->AdvRouteLifetime = $2;
}
| T_RemoveRoute SWITCH ';'
{
route->RemoveRouteFlag = $2;
}
;
rdnssdef : rdnsshead '{' optional_rdnssplist '}' ';'
{
$$ = rdnss;
rdnss = NULL;
}
;
rdnssaddrs : rdnssaddrs rdnssaddr
| rdnssaddr
;
rdnssaddr : IPV6ADDR
{
if (!rdnss) {
/* first IP found */
rdnss = malloc(sizeof(struct AdvRDNSS));
if (rdnss == NULL) {
flog(LOG_CRIT, "malloc failed: %s", strerror(errno));
ABORT;
}
rdnss_init_defaults(rdnss, iface);
}
switch (rdnss->AdvRDNSSNumber) {
case 0:
memcpy(&rdnss->AdvRDNSSAddr1, $1, sizeof(struct in6_addr));
rdnss->AdvRDNSSNumber++;
break;
case 1:
memcpy(&rdnss->AdvRDNSSAddr2, $1, sizeof(struct in6_addr));
rdnss->AdvRDNSSNumber++;
break;
case 2:
memcpy(&rdnss->AdvRDNSSAddr3, $1, sizeof(struct in6_addr));
rdnss->AdvRDNSSNumber++;
break;
default:
flog(LOG_CRIT, "too many addresses in RDNSS section");
ABORT;
}
}
;
rdnsshead : T_RDNSS rdnssaddrs
{
if (!rdnss) {
flog(LOG_CRIT, "no address specified in RDNSS section");
ABORT;
}
}
;
optional_rdnssplist: /* empty */
| rdnssplist
;
rdnssplist : rdnssplist rdnssparms
| rdnssparms
;
rdnssparms : T_AdvRDNSSPreference NUMBER ';'
{
flog(LOG_WARNING, "ignoring deprecated RDNSS preference");
}
| T_AdvRDNSSOpenFlag SWITCH ';'
{
flog(LOG_WARNING, "ignoring deprecated RDNSS open flag");
}
| T_AdvRDNSSLifetime number_or_infinity ';'
{
rdnss->AdvRDNSSLifetime = $2;
}
| T_FlushRDNSS SWITCH ';'
{
rdnss->FlushRDNSSFlag = $2;
}
;
dnssldef : dnsslhead '{' optional_dnsslplist '}' ';'
{
$$ = dnssl;
dnssl = NULL;
}
;
dnsslsuffixes : dnsslsuffixes dnsslsuffix
| dnsslsuffix
;
dnsslsuffix : STRING
{
char *ch;
for (ch = $1;*ch != '\0';ch++) {
if (*ch >= 'A' && *ch <= 'Z')
continue;
if (*ch >= 'a' && *ch <= 'z')
continue;
if (*ch >= '0' && *ch <= '9')
continue;
if (*ch == '-' || *ch == '.')
continue;
flog(LOG_CRIT, "invalid domain suffix specified");
ABORT;
}
if (!dnssl) {
/* first domain found */
dnssl = malloc(sizeof(struct AdvDNSSL));
if (dnssl == NULL) {
flog(LOG_CRIT, "malloc failed: %s", strerror(errno));
ABORT;
}
dnssl_init_defaults(dnssl, iface);
}
dnssl->AdvDNSSLNumber++;
dnssl->AdvDNSSLSuffixes =
realloc(dnssl->AdvDNSSLSuffixes,
dnssl->AdvDNSSLNumber * sizeof(char*));
if (dnssl->AdvDNSSLSuffixes == NULL) {
flog(LOG_CRIT, "realloc failed: %s", strerror(errno));
ABORT;
}
dnssl->AdvDNSSLSuffixes[dnssl->AdvDNSSLNumber - 1] = strdup($1);
}
;
dnsslhead : T_DNSSL dnsslsuffixes
{
if (!dnssl) {
flog(LOG_CRIT, "no domain specified in DNSSL section");
ABORT;
}
}
;
optional_dnsslplist: /* empty */
| dnsslplist
;
dnsslplist : dnsslplist dnsslparms
| dnsslparms
;
dnsslparms : T_AdvDNSSLLifetime number_or_infinity ';'
{
dnssl->AdvDNSSLLifetime = $2;
}
| T_FlushDNSSL SWITCH ';'
{
dnssl->FlushDNSSLFlag = $2;
}
;
lowpancodef : lowpancohead '{' optional_lowpancoplist '}' ';'
{
$$ = lowpanco;
lowpanco = NULL;
}
;
lowpancohead : T_LOWPANCO
{
lowpanco = malloc(sizeof(struct AdvLowpanCo));
if (lowpanco == NULL) {