-
Notifications
You must be signed in to change notification settings - Fork 107
/
conffile.y
1249 lines (1153 loc) · 30.3 KB
/
conffile.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
%{
/*
* Copyright 2013-2022 Fabian Groffen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "allocator.h"
#include "conffile.h"
#include "conffile.tab.h"
#include "aggregator.h"
#include "receptor.h"
#include "router.h"
#include "config.h"
int router_yylex(ROUTER_YYSTYPE *, ROUTER_YYLTYPE *, void *, router *, allocator *, allocator *);
%}
%code requires {
struct _clust {
enum clusttype t;
int ival;
};
struct _clhost {
char *ip;
unsigned short port;
char *inst;
int proto;
con_type type;
struct _rcptr_trsp_ssl *trnsp;
void *saddr;
void *hint;
struct _clhost *next;
};
struct _maexpr {
route *r;
char drop;
struct _maexpr *next;
};
struct _agcomp {
enum _aggr_compute_type ctype;
unsigned char pctl;
char *metric;
struct _agcomp *next;
};
struct _lsnr {
con_type type;
struct _rcptr_trsp *transport;
struct _rcptr *rcptr;
};
struct _rcptr {
con_proto ctype;
char *ip;
unsigned short port;
void *saddr;
struct _rcptr *next;
};
enum _rcptr_sslprototype {
_rp_PROTOMIN,
_rp_PROTOMAX
};
struct _rcptr_sslprotos {
enum _rcptr_sslprototype prtype;
tlsprotover prver;
struct _rcptr_sslprotos *next;
};
struct _rcptr_trsp_ssl {
con_trnsp mode;
char *mtlspemcert;
char *mtlspemkey;
};
struct _rcptr_trsp {
con_trnsp mode;
char *pemcert;
struct _rcptr_sslprotos *protos;
char *ciphers;
char *suites;
};
}
%define api.prefix {router_yy}
%define api.pure full
%locations
%define parse.error verbose
%define api.value.type union
%param {void *yyscanner} {router *rtr} {allocator *ralloc} {allocator *palloc}
%token crCLUSTER
%token crFORWARD crANY_OF crFAILOVER crCARBON_CH crFNV1A_CH crJUMP_FNV1A_CH
crFILE crIP crREPLICATION crDYNAMIC crPROTO crUSEALL crUDP crTCP
%type <enum clusttype> cluster_useall cluster_ch
%type <struct _clust> cluster_type cluster_file
%type <int> cluster_opt_repl cluster_opt_useall cluster_opt_dynamic
%type <con_proto> cluster_opt_proto
%type <con_type> cluster_opt_type
%type <char *> cluster_opt_instance
%type <cluster *> cluster
%type <struct _clhost *> cluster_host cluster_hosts cluster_opt_host
cluster_path cluster_paths cluster_opt_path
%type <con_trnsp> cluster_transport_trans
%type <struct _rcptr_trsp_ssl *> cluster_opt_transport cluster_transport_opt_ssl
%token crMATCH
%token crVALIDATE crELSE crLOG crDROP crROUTE crUSING
%token crSEND crTO crBLACKHOLE crSTOP
%type <destinations *> match_dst match_opt_dst match_dsts
match_dsts2 match_opt_send_to match_send_to aggregate_opt_send_to
%type <int> match_opt_stop match_log_or_drop
%type <char *> match_opt_route
%type <struct _maexpr *> match_opt_validate match_expr match_opt_expr
match_exprs match_exprs2
%token crREWRITE
%token crINTO
%token crAGGREGATE
%token crEVERY crSECONDS crEXPIRE crAFTER crTIMESTAMP crAT
%token crSTART crMIDDLE crEND crOF crBUCKET
%token crCOMPUTE crSUM crCOUNT crMAX crMIN crAVERAGE crMEDIAN
%token crVARIANCE crSTDDEV
%token <int> crPERCENTILE
%token crWRITE
%type <enum _aggr_timestamp> aggregate_ts_when aggregate_opt_timestamp
%type <struct _agcomp> aggregate_comp_type
%type <struct _agcomp *> aggregate_compute aggregate_computes
aggregate_opt_compute
%token crSTATISTICS
%token crSUBMIT crRESET crCOUNTERS crINTERVAL crPREFIX crWITH
%type <int> statistics_opt_interval
%type <col_mode> statistics_opt_counters
%type <char *> statistics_opt_prefix
%token crLISTEN
%token crTYPE crLINEMODE crSYSLOGMODE crTRANSPORT
%token crPLAIN crGZIP crLZ4 crSNAPPY crSSL crMTLS crUNIX
%token crPROTOMIN crPROTOMAX
%token crSSL3 crTLS1_0 crTLS1_1 crTLS1_2 crTLS1_3
%token crCIPHERS crCIPHERSUITES
%type <con_proto> rcptr_proto
%type <struct _rcptr *> receptor opt_receptor receptors
%type <con_trnsp> transport_ssl_or_mtls
%type <struct _rcptr_trsp *> transport_mode transport_mode_trans
transport_opt_ssl
%type <struct _rcptr_sslprotos *> transport_ssl_proto
transport_opt_ssl_protos
%type <char *> transport_opt_ssl_ciphers transport_opt_ssl_ciphersuites
%type <enum _rcptr_sslprototype> transport_ssl_prototype
%type <tlsprotover> transport_ssl_protover
%type <struct _lsnr *> listener
%token crINCLUDE
%token <char *> crCOMMENT crSTRING crUNEXPECTED
%token <int> crINTVAL
%%
stmts: opt_stmt
;
opt_stmt:
| stmt opt_stmt
;
stmt: command ';'
;
command: cluster
| match
| rewrite
| aggregate
| send
| statistics
| listen
| include
;
/*** {{{ BEGIN cluster ***/
cluster: crCLUSTER crSTRING[name] cluster_type[type] cluster_hosts[servers]
{
struct _clhost *w;
char *err;
int srvcnt;
int replcnt;
/* just to silence clang */
(void)yynerrs;
/* count number of servers for ch_new */
for (srvcnt = 0, w = $servers; w != NULL; w = w->next, srvcnt++)
;
if (($$ = ra_malloc(ralloc, sizeof(cluster))) == NULL) {
logerr("malloc failed for cluster '%s'\n", $name);
YYABORT;
}
$$->name = ra_strdup(ralloc, $name);
$$->next = NULL;
$$->type = $type.t;
switch ($$->type) {
case CARBON_CH:
case FNV1A_CH:
case JUMP_CH:
$$->members.ch = ra_malloc(ralloc, sizeof(chashring));
if ($$->members.ch == NULL) {
logerr("malloc failed for ch in cluster '%s'\n", $name);
YYABORT;
}
replcnt = $type.ival / 10;
$$->isdynamic = $type.ival - (replcnt * 10) == 2;
if (replcnt < 1 || replcnt > 255) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc,
"replication count must be between 1 and 255");
YYERROR;
}
$$->members.ch->repl_factor = (unsigned char)replcnt;
$$->members.ch->ring = ch_new(ralloc,
$$->type == CARBON_CH ? CARBON :
$$->type == FNV1A_CH ? FNV1a :
JUMP_FNV1a, srvcnt);
$$->members.ch->servers = NULL;
$type.ival = 0; /* hack, avoid triggering use_all */
break;
case FORWARD:
$$->members.forward = NULL;
break;
case ANYOF:
case FAILOVER:
$$->members.anyof = NULL;
break;
default:
logerr("unknown cluster type %zd!\n", (ssize_t)$$->type);
YYABORT;
}
for (w = $servers; w != NULL; w = w->next) {
err = router_add_server(rtr, w->ip, w->port, w->inst,
w->type, w->trnsp->mode, w->trnsp->mtlspemcert,
w->trnsp->mtlspemkey, w->proto,
w->saddr, w->hint, (char)$type.ival, $$);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
}
err = router_add_cluster(rtr, $$);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
}
| crCLUSTER crSTRING[name] cluster_file[type] cluster_paths[paths]
{
struct _clhost *w;
char *err;
if (($$ = ra_malloc(ralloc, sizeof(cluster))) == NULL) {
logerr("malloc failed for cluster '%s'\n", $name);
YYABORT;
}
$$->name = ra_strdup(ralloc, $name);
$$->next = NULL;
$$->type = $type.t;
switch ($$->type) {
case FILELOG:
case FILELOGIP:
$$->members.forward = NULL;
break;
default:
logerr("unknown cluster type %zd!\n", (ssize_t)$$->type);
YYABORT;
}
for (w = $paths; w != NULL; w = w->next) {
err = router_add_server(rtr, w->ip, w->port, w->inst,
T_LINEMODE, W_PLAIN, NULL, NULL, w->proto,
w->saddr, w->hint, (char)$type.ival, $$);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
}
err = router_add_cluster(rtr, $$);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
}
;
cluster_type:
cluster_useall[type] cluster_opt_useall[use]
{ $$.t = $type; $$.ival = $use; }
| cluster_ch[type] cluster_opt_repl[repl] cluster_opt_dynamic[dyn]
{ $$.t = $type; $$.ival = ($dyn * 2) + ($repl * 10); }
;
cluster_useall: crFORWARD { $$ = FORWARD; }
| crANY_OF { $$ = ANYOF; }
| crFAILOVER { $$ = FAILOVER; }
;
cluster_opt_useall: { $$ = 0; }
| crUSEALL { $$ = 1; }
;
cluster_ch: crCARBON_CH { $$ = CARBON_CH; }
| crFNV1A_CH { $$ = FNV1A_CH; }
| crJUMP_FNV1A_CH { $$ = JUMP_CH; }
;
cluster_opt_repl: { $$ = 1; }
| crREPLICATION crINTVAL[cnt] { $$ = $cnt; }
;
cluster_opt_dynamic: { $$ = 0; }
| crDYNAMIC { $$ = 1; }
;
cluster_file: crFILE crIP { $$.t = FILELOGIP; $$.ival = 0; }
| crFILE { $$.t = FILELOG; $$.ival = 0; }
;
cluster_paths: cluster_path[l] cluster_opt_path[r] { $l->next = $r; $$ = $l; }
;
cluster_opt_path: { $$ = NULL; }
| cluster_path { $$ = $1; }
;
cluster_path: crSTRING[path]
{
struct _clhost *ret = ra_malloc(palloc, sizeof(struct _clhost));
char *err = router_validate_path(rtr, $path);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc, err);
YYERROR;
}
ret->ip = $path;
ret->port = GRAPHITE_PORT;
ret->saddr = NULL;
ret->hint = NULL;
ret->inst = NULL;
ret->proto = CON_FILE;
ret->next = NULL;
$$ = ret;
}
;
cluster_hosts: cluster_host[l] cluster_opt_host[r] { $l->next = $r; $$ = $l; }
;
cluster_opt_host: { $$ = NULL; }
| cluster_hosts { $$ = $1; }
;
cluster_host: crSTRING[ip] cluster_opt_instance[inst]
cluster_opt_proto[prot] cluster_opt_type[type]
cluster_opt_transport[trnsp]
{
struct _clhost *ret = ra_malloc(palloc, sizeof(struct _clhost));
char *err = router_validate_address(
rtr,
&(ret->ip), &(ret->port), &(ret->saddr), &(ret->hint),
$ip, $prot, 0 /* require explicit host */);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc, err);
YYERROR;
}
ret->inst = $inst;
ret->proto = $prot;
ret->type = $type;
ret->trnsp = $trnsp;
ret->next = NULL;
$$ = ret;
}
;
cluster_opt_instance: { $$ = NULL; }
| '=' crSTRING[inst] { $$ = $inst; }
| '=' crINTVAL[inst]
{
$$ = ra_malloc(palloc, sizeof(char) * 12);
if ($$ == NULL) {
logerr("out of memory\n");
YYABORT;
}
snprintf($$, 12, "%d", $inst);
}
;
cluster_opt_proto: { $$ = CON_TCP; }
| crPROTO crUDP { $$ = CON_UDP; }
| crPROTO crTCP { $$ = CON_TCP; }
;
cluster_opt_type: { $$ = T_LINEMODE; }
| crTYPE crLINEMODE { $$ = T_LINEMODE; }
| crTYPE crSYSLOGMODE { $$ = T_SYSLOGMODE; }
;
cluster_opt_transport:
{
if (($$ = ra_malloc(palloc,
sizeof(struct _rcptr_trsp))) == NULL)
{
logerr("malloc failed\n");
YYABORT;
}
$$->mode = W_PLAIN;
$$->mtlspemcert = NULL;
$$->mtlspemkey = NULL;
}
| cluster_transport_trans[trns]
cluster_transport_opt_ssl[ssl]
{
if ($ssl->mode == W_PLAIN) {
if (($$ = ra_malloc(palloc,
sizeof(struct _rcptr_trsp))) == NULL)
{
logerr("malloc failed\n");
YYABORT;
}
$$->mode = $trns;
$$->mtlspemcert = NULL;
$$->mtlspemkey = NULL;
} else {
$ssl->mode |= $trns;
$$ = $ssl;
}
}
;
cluster_transport_trans: crTRANSPORT crPLAIN { $$ = W_PLAIN; }
| crTRANSPORT crGZIP {
#ifdef HAVE_GZIP
$$ = W_GZIP;
#else
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc,
"feature gzip not compiled in");
YYERROR;
#endif
}
| crTRANSPORT crLZ4 {
#ifdef HAVE_LZ4
$$ = W_LZ4;
#else
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc,
"feature lz4 not compiled in");
YYERROR;
#endif
}
| crTRANSPORT crSNAPPY {
#ifdef HAVE_SNAPPY
$$ = W_SNAPPY;
#else
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc,
"feature snappy not compiled in");
YYERROR;
#endif
}
;
cluster_transport_opt_ssl:
{
if (($$ = ra_malloc(palloc,
sizeof(struct _rcptr_trsp))) == NULL)
{
logerr("malloc failed\n");
YYABORT;
}
$$->mode = W_PLAIN;
$$->mtlspemcert = NULL;
$$->mtlspemkey = NULL;
}
| crSSL
{
#ifdef HAVE_SSL
if (($$ = ra_malloc(palloc,
sizeof(struct _rcptr_trsp))) == NULL)
{
logerr("malloc failed\n");
YYABORT;
}
$$->mode = W_SSL;
$$->mtlspemcert = NULL;
$$->mtlspemkey = NULL;
#else
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc,
"feature ssl not compiled in");
YYERROR;
#endif
}
| crMTLS crSTRING[pemcert] crSTRING[pemkey]
{
#ifdef HAVE_SSL
if (($$ = ra_malloc(palloc,
sizeof(struct _rcptr_trsp))) == NULL)
{
logerr("malloc failed\n");
YYABORT;
}
$$->mode = W_SSL | W_MTLS;
$$->mtlspemcert = $pemcert;
$$->mtlspemkey = $pemkey;
#else
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc,
"feature ssl not compiled in");
YYERROR;
#endif
}
;
/*** }}} END cluster ***/
/*** {{{ BEGIN match ***/
match: crMATCH match_exprs[exprs] match_opt_validate[val]
match_opt_route[masq] match_opt_send_to[dsts] match_opt_stop[stop]
{
/* each expr comes with an allocated route, populate it */
struct _maexpr *we;
destinations *d = NULL;
char *err;
if ($val != NULL) {
/* optional validate clause */
if ((d = ra_malloc(ralloc, sizeof(destinations))) == NULL) {
logerr("out of memory\n");
YYABORT;
}
d->next = NULL;
if ((d->cl = ra_malloc(ralloc, sizeof(cluster))) == NULL) {
logerr("out of memory\n");
YYABORT;
}
d->cl->name = NULL;
d->cl->type = VALIDATION;
d->cl->next = NULL;
d->cl->members.validation = ra_malloc(ralloc, sizeof(validate));
if (d->cl->members.validation == NULL) {
logerr("out of memory\n");
YYABORT;
}
d->cl->members.validation->rule = $val->r;
d->cl->members.validation->action = $val->drop ? VAL_DROP : VAL_LOG;
}
/* add destinations to the chain */
if (d != NULL) {
d->next = $dsts;
} else {
d = $dsts;
}
/* replace with copy on the router allocator */
if ($masq != NULL)
$masq = ra_strdup(ralloc, $masq);
for (we = $exprs; we != NULL; we = we->next) {
we->r->next = NULL;
we->r->dests = d;
we->r->masq = $masq;
we->r->stop = $dsts == NULL ? 0 :
$dsts->cl->type == BLACKHOLE ? 1 : $stop;
err = router_add_route(rtr, we->r);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc, err);
YYERROR;
}
}
}
;
match_exprs: '*'
{
if (($$ = ra_malloc(palloc, sizeof(struct _maexpr))) == NULL) {
logerr("out of memory\n");
YYABORT;
}
$$->r = NULL;
if (router_validate_expression(rtr, &($$->r), "*") != NULL)
YYABORT;
$$->drop = 0;
$$->next = NULL;
}
| match_exprs2 { $$ = $1; }
;
match_exprs2: match_expr[l] match_opt_expr[r] { $l->next = $r; $$ = $l; }
match_opt_expr: { $$ = NULL; }
| match_exprs2 { $$ = $1; }
;
match_expr: crSTRING[expr]
{
char *err;
if (($$ = ra_malloc(palloc, sizeof(struct _maexpr))) == NULL) {
logerr("out of memory\n");
YYABORT;
}
$$->r = NULL;
err = router_validate_expression(rtr, &($$->r), $expr);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc, err);
YYERROR;
}
$$->drop = 0;
$$->next = NULL;
}
;
match_opt_validate: { $$ = NULL; }
| crVALIDATE crSTRING[expr] crELSE match_log_or_drop[drop]
{
char *err;
if (($$ = ra_malloc(palloc, sizeof(struct _maexpr))) == NULL) {
logerr("out of memory\n");
YYABORT;
}
$$->r = NULL;
err = router_validate_expression(rtr, &($$->r), $expr);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc, err);
YYERROR;
}
$$->drop = $drop;
$$->next = NULL;
}
;
match_log_or_drop: crLOG { $$ = 0; }
| crDROP { $$ = 1; }
;
match_opt_route: { $$ = NULL; }
| crROUTE crUSING crSTRING[expr] { $$ = $expr; }
;
match_opt_send_to: { $$ = NULL; }
| match_send_to { $$ = $1; }
;
match_send_to: crSEND crTO match_dsts[dsts] { $$ = $dsts; }
;
match_dsts: crBLACKHOLE
{
if (($$ = ra_malloc(ralloc, sizeof(destinations))) == NULL) {
logerr("out of memory\n");
YYABORT;
}
if (router_validate_cluster(rtr, &($$->cl), "blackhole") != NULL)
YYABORT;
$$->next = NULL;
}
| match_dsts2 { $$ = $1; }
;
match_dsts2: match_dst[l] match_opt_dst[r] { $l->next = $r; $$ = $l; }
match_opt_dst: { $$ = NULL; }
| match_dsts2 { $$ = $1; }
;
match_dst: crSTRING[cluster]
{
char *err;
if (($$ = ra_malloc(ralloc, sizeof(destinations))) == NULL) {
logerr("out of memory\n");
YYABORT;
}
err = router_validate_cluster(rtr, &($$->cl), $1);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
$$->next = NULL;
}
;
match_opt_stop: { $$ = 0; }
| crSTOP { $$ = 1; }
;
/*** }}} END match ***/
/*** {{{ BEGIN rewrite ***/
rewrite: crREWRITE crSTRING[expr] crINTO crSTRING[replacement]
{
char *err;
route *r = NULL;
cluster *cl;
err = router_validate_expression(rtr, &r, $expr);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
cl = ra_malloc(ralloc, sizeof(cluster));
if (cl == NULL) {
logerr("out of memory\n");
YYABORT;
}
cl->type = REWRITE;
cl->name = NULL;
cl->members.replacement = ra_strdup(ralloc, $replacement);
cl->next = NULL;
if (cl->members.replacement == NULL) {
logerr("out of memory\n");
YYABORT;
}
r->dests = ra_malloc(ralloc, sizeof(destinations));
if (r->dests == NULL) {
logerr("out of memory\n");
YYABORT;
}
r->dests->cl = cl;
r->dests->next = NULL;
r->stop = 0;
r->next = NULL;
err = router_add_route(rtr, r);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
}
;
/*** }}} END rewrite ***/
/*** {{{ BEGIN aggregate ***/
aggregate: crAGGREGATE match_exprs2[exprs] crEVERY crINTVAL[intv] crSECONDS
crEXPIRE crAFTER crINTVAL[expire] crSECONDS
aggregate_opt_timestamp[tswhen]
aggregate_computes[computes]
aggregate_opt_send_to[dsts]
match_opt_stop[stop]
{
cluster *w;
aggregator *a;
destinations *d;
struct _agcomp *acw;
struct _maexpr *we;
char *err;
if ($intv <= 0) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc,
"interval must be > 0");
YYERROR;
}
if ($expire <= 0) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc,
"expire must be > 0");
YYERROR;
}
if ($expire <= $intv) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc,
"expire must be greater than interval");
YYERROR;
}
w = ra_malloc(ralloc, sizeof(cluster));
if (w == NULL) {
logerr("malloc failed for aggregate\n");
YYABORT;
}
w->name = NULL;
w->type = AGGREGATION;
w->next = NULL;
a = aggregator_new($intv, $expire, $tswhen);
if (a == NULL) {
logerr("out of memory\n");
YYABORT;
}
if ((err = router_add_aggregator(rtr, a)) != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
w->members.aggregation = a;
for (acw = $computes; acw != NULL; acw = acw->next) {
if (aggregator_add_compute(a,
acw->metric, acw->ctype, acw->pctl) != 0)
{
logerr("out of memory\n");
YYABORT;
}
}
err = router_add_cluster(rtr, w);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
d = ra_malloc(ralloc, sizeof(destinations));
if (d == NULL) {
logerr("out of memory\n");
YYABORT;
}
d->cl = w;
d->next = $dsts;
for (we = $exprs; we != NULL; we = we->next) {
we->r->next = NULL;
we->r->dests = d;
we->r->stop = $stop;
err = router_add_route(rtr, we->r);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc, err);
YYERROR;
}
}
if ($dsts != NULL)
router_add_stubroute(rtr, AGGRSTUB, w, $dsts);
}
;
aggregate_opt_timestamp: { $$ = TS_END; }
| crTIMESTAMP crAT aggregate_ts_when[tswhen] crOF
crBUCKET
{ $$ = $tswhen; }
;
aggregate_ts_when: crSTART { $$ = TS_START; }
| crMIDDLE { $$ = TS_MIDDLE; }
| crEND { $$ = TS_END; }
;
aggregate_computes: aggregate_compute[l] aggregate_opt_compute[r]
{ $l->next = $r; $$ = $l; }
;
aggregate_opt_compute: { $$ = NULL; }
| aggregate_computes { $$ = $1; }
aggregate_compute: crCOMPUTE aggregate_comp_type[type] crWRITE crTO
crSTRING[metric]
{
$$ = ra_malloc(palloc, sizeof(struct _agcomp));
if ($$ == NULL) {
logerr("malloc failed\n");
YYABORT;
}
$$->ctype = $type.ctype;
$$->pctl = $type.pctl;
$$->metric = $metric;
$$->next = NULL;
}
;
aggregate_comp_type: crSUM { $$.ctype = SUM; }
| crCOUNT { $$.ctype = CNT; }
| crMAX { $$.ctype = MAX; }
| crMIN { $$.ctype = MIN; }
| crAVERAGE { $$.ctype = AVG; }
| crMEDIAN { $$.ctype = MEDN; }
| crPERCENTILE
{
if ($1 < 1 || $1 > 99) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc,
"percentile<x>: value x must be between 1 and 99");
YYERROR;
}
$$.ctype = PCTL;
$$.pctl = (unsigned char)$1;
}
| crVARIANCE { $$.ctype = VAR; }
| crSTDDEV { $$.ctype = SDEV; }
;
aggregate_opt_send_to: { $$ = NULL; }
| match_send_to { $$ = $1; }
;
/*** }}} END aggregate ***/
/*** {{{ BEGIN send ***/
send: crSEND crSTATISTICS crTO match_dsts[dsts] match_opt_stop[stop]
{
char *err = router_set_statistics(rtr, $dsts);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
logerr("warning: 'send statistics to ...' is deprecated and will be "
"removed in a future version, use 'statistics send to ...' "
"instead\n");
}
;
/*** }}} END send ***/
/*** {{{ BEGIN statistics ***/
statistics: crSTATISTICS
statistics_opt_interval[interval]
statistics_opt_counters[counters]
statistics_opt_prefix[prefix]
aggregate_opt_send_to[dsts]
match_opt_stop[stop]
{
char *err;
err = router_set_collectorvals(rtr, $interval, $prefix, $counters);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr, ralloc, palloc, err);
YYERROR;
}
if ($dsts != NULL) {
err = router_set_statistics(rtr, $dsts);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc, err);
YYERROR;
}
}
}
;
statistics_opt_interval: { $$ = -1; }
| crSUBMIT crEVERY crINTVAL[intv] crSECONDS
{
if ($intv <= 0) {
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc, "interval must be > 0");
YYERROR;
}
$$ = $intv;
}
;
statistics_opt_counters: { $$ = CUM; }
| crRESET crCOUNTERS crAFTER crINTERVAL { $$ = SUB; }
;
statistics_opt_prefix: { $$ = NULL; }
| crPREFIX crWITH crSTRING[prefix] { $$ = $prefix; }
;
/*** }}} END statistics ***/
/*** {{{ BEGIN listen ***/
listen: crLISTEN listener[lsnr]
{
struct _rcptr *walk;
char *err;
struct _rcptr_sslprotos *prwalk;
int protomin;
int protomax;
for (walk = $lsnr->rcptr; walk != NULL; walk = walk->next) {
protomin = 0;
protomax = 0;
prwalk = $lsnr->transport->protos;
for (; prwalk != NULL; prwalk = prwalk->next) {
if (prwalk->prtype == _rp_PROTOMIN)
protomin = prwalk->prver;
else if (prwalk->prtype == _rp_PROTOMAX)
protomax = prwalk->prver;
}
err = router_add_listener(rtr, $lsnr->type,
$lsnr->transport->mode, $lsnr->transport->pemcert,
protomin, protomax,
$lsnr->transport->ciphers, $lsnr->transport->suites,
walk->ctype, walk->ip, walk->port, walk->saddr);
if (err != NULL) {
router_yyerror(&yylloc, yyscanner, rtr,
ralloc, palloc, err);
YYERROR;
}
}
}
;
listener: crTYPE crLINEMODE transport_mode[mode] receptors[ifaces]
{
if (($$ = ra_malloc(palloc, sizeof(struct _lsnr))) == NULL) {
logerr("malloc failed\n");
YYABORT;
}
$$->type = T_LINEMODE;
$$->transport = $mode;
$$->rcptr = $ifaces;
if ($mode->mode != W_PLAIN) {
struct _rcptr *walk;
for (walk = $ifaces; walk != NULL; walk = walk->next) {
if (walk->ctype == CON_UDP) {