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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
|
/*
* Copyright (c) 2002-2012 Balabit
* Copyright (c) 1998-2012 Balázs Scheidler
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
%code top {
#include "afsocket-parser.h"
}
%code {
#include "afsocket.h"
#include "cfg-parser.h"
#include "afunix-source.h"
#include "afunix-dest.h"
#include "afinet-source.h"
#include "afinet-dest.h"
#include "messages.h"
#include "syslog-names.h"
#include "plugin.h"
#include "cfg-grammar-internal.h"
#include "cfg-helpers.h"
#include "socket-options-inet.h"
#include "socket-options-unix.h"
#include "transport-mapper-inet.h"
#include "service-management.h"
#include "systemd-syslog-source.h"
#include "afsocket-systemd-override.h"
#include "transport/tls-context.h"
static SocketOptions *last_sock_options;
static TransportMapper *last_transport_mapper;
TLSContext *last_tls_context;
#if ! SYSLOG_NG_ENABLE_IPV6
#undef AF_INET6
#define AF_INET6 0; g_assert_not_reached()
#endif
static void
afsocket_grammar_set_source_driver(AFSocketSourceDriver *sd)
{
last_driver = &sd->super.super;
last_reader_options = &((AFSocketSourceDriver *) last_driver)->reader_options;
last_sock_options = ((AFSocketSourceDriver *) last_driver)->socket_options;
last_transport_mapper = ((AFSocketSourceDriver *) last_driver)->transport_mapper;
last_proto_server_options = &last_reader_options->proto_options.super;
}
static void
afsocket_grammar_set_dest_driver(AFSocketDestDriver *dd)
{
last_driver = &dd->super.super;
last_writer_options = &((AFSocketDestDriver *) last_driver)->writer_options;
last_sock_options = ((AFSocketDestDriver *) last_driver)->socket_options;
last_transport_mapper = ((AFSocketDestDriver *) last_driver)->transport_mapper;
last_proto_client_options = &last_writer_options->proto_options.super;
}
void
afunix_grammar_set_source_driver(AFUnixSourceDriver *sd)
{
afsocket_grammar_set_source_driver(&sd->super);
last_file_perm_options = &sd->file_perm_options;
}
static void
afinet_grammar_set_source_driver(AFInetSourceDriver *sd)
{
afsocket_grammar_set_source_driver(&sd->super);
}
static void
afunix_grammar_set_dest_driver(AFUnixDestDriver *dd)
{
afsocket_grammar_set_dest_driver(&dd->super);
}
static void
afinet_grammar_set_dest_driver(AFInetDestDriver *dd)
{
afsocket_grammar_set_dest_driver(&dd->super);
}
void
systemd_syslog_grammar_set_source_driver(SystemDSyslogSourceDriver *sd)
{
afsocket_grammar_set_source_driver(&sd->super);
}
}
%define api.prefix {afsocket_}
/* this parameter is needed in order to instruct bison to use a complete
* argument list for yylex/yyerror */
%lex-param {CfgLexer *lexer}
%parse-param {CfgLexer *lexer}
%parse-param {LogDriver **instance}
%parse-param {gpointer arg}
%token KW_UNIX_STREAM 20000
%token KW_UNIX_DGRAM
%token KW_TCP
%token KW_UDP
%token KW_TCP6
%token KW_UDP6
%token KW_NETWORK
%token KW_TRANSPORT
%token KW_IP_PROTOCOL
%token KW_SYSTEMD_SYSLOG
%token KW_IP_TTL
%token KW_SO_BROADCAST
%token KW_IP_TOS
%token KW_IP_FREEBIND
%token KW_SO_SNDBUF
%token KW_SO_RCVBUF
%token KW_SO_KEEPALIVE
%token KW_SO_REUSEPORT
%token KW_TCP_KEEPALIVE_TIME
%token KW_TCP_KEEPALIVE_PROBES
%token KW_TCP_KEEPALIVE_INTVL
%token KW_SO_PASSCRED
%token KW_LISTEN_BACKLOG
%token KW_SPOOF_SOURCE
%token KW_SPOOF_SOURCE_MAX_MSGLEN
%token KW_KEEP_ALIVE
%token KW_MAX_CONNECTIONS
%token KW_CLOSE_ON_INPUT
%token KW_LOCALIP
%token KW_IP
%token KW_INTERFACE
%token KW_LOCALPORT
%token KW_DESTPORT
%token KW_FAILOVER_SERVERS
%token KW_FAILOVER
%token KW_SERVERS
%token KW_FAILBACK
%token KW_TCP_PROBE_INTERVAL
%token KW_SUCCESSFUL_PROBES_REQUIRED
%token KW_DYNAMIC_WINDOW_SIZE
%token KW_DYNAMIC_WINDOW_STATS_FREQ
%token KW_DYNAMIC_WINDOW_REALLOC_TICKS
/* SSL support */
%token KW_TLS
%token KW_PEER_VERIFY
%token KW_KEY_FILE
%token KW_CERT_FILE
%token KW_DHPARAM_FILE
%token KW_PKCS12_FILE
%token KW_CA_DIR
%token KW_CRL_DIR
%token KW_CA_FILE
%token KW_TRUSTED_KEYS
%token KW_TRUSTED_DN
%token KW_CIPHER_SUITE
%token KW_TLS12_AND_OLDER
%token KW_TLS13
%token KW_SIGALGS
%token KW_CLIENT_SIGALGS
%token KW_ECDH_CURVE_LIST
%token KW_SSL_OPTIONS
%token KW_SSL_VERSION
%token KW_SNI
%token KW_ALLOW_COMPRESS
%token KW_KEYLOG_FILE
%token KW_OCSP_STAPLING_VERIFY
%token KW_CONF_CMDS
/* INCLUDE_DECLS */
%type <ptr> driver
%type <ptr> source_afunix
%type <ptr> source_afunix_dgram_params
%type <ptr> source_afunix_stream_params
%type <ptr> source_afinet
%type <ptr> source_afinet_udp_params
%type <ptr> source_afinet_tcp_params
%type <ptr> source_afinet_udp6_params
%type <ptr> source_afinet_tcp6_params
%type <ptr> source_afsyslog
%type <ptr> source_afsyslog_params
%type <ptr> source_afnetwork
%type <ptr> source_afnetwork_params
%type <ptr> source_afsocket_stream_params
%type <ptr> source_systemd_syslog
%type <ptr> source_systemd_syslog_params
%type <ptr> dest_afunix
%type <ptr> dest_afunix_dgram_params
%type <ptr> dest_afunix_stream_params
%type <ptr> dest_afinet
%type <ptr> dest_afinet_udp_params
%type <ptr> dest_afinet_tcp_params
%type <ptr> dest_afinet_udp6_params
%type <ptr> dest_afinet_tcp6_params
%type <ptr> dest_afsyslog
%type <ptr> dest_afsyslog_params
%type <ptr> dest_afnetwork
%type <ptr> dest_afnetwork_params
%type <num> inet_ip_protocol_option
%type <ptr> dest_afinet_option
%type <ptr> dest_failover_options
%type <ptr> dest_failover_modes_options
%type <ptr> tls_conf_cmds
%type <ptr> tls_conf_cmd_list_build
%%
start
: driver
{
*instance = $1;
if (yychar != AFSOCKET_EMPTY)
cfg_lexer_unput_token(lexer, &yylval);
YYACCEPT;
}
;
driver
: LL_CONTEXT_SOURCE source_afunix { $$ = $2; }
| LL_CONTEXT_SOURCE source_afinet { $$ = $2; }
| LL_CONTEXT_SOURCE source_afsyslog { $$ = $2; }
| LL_CONTEXT_SOURCE source_afnetwork { $$ = $2; }
| LL_CONTEXT_SOURCE source_systemd_syslog { $$ = $2; }
| LL_CONTEXT_DESTINATION dest_afunix { $$ = $2; }
| LL_CONTEXT_DESTINATION dest_afinet { $$ = $2; }
| LL_CONTEXT_DESTINATION dest_afsyslog { $$ = $2; }
| LL_CONTEXT_DESTINATION dest_afnetwork { $$ = $2; }
;
source_afunix
: KW_UNIX_DGRAM '(' _inner_src_context_push source_afunix_dgram_params _inner_src_context_pop ')' { $$ = $4; }
| KW_UNIX_STREAM '(' _inner_src_context_push source_afunix_stream_params _inner_src_context_pop ')' { $$ = $4; }
;
source_afunix_dgram_params
: string
{
create_and_set_unix_dgram_or_systemd_syslog_source($1, configuration);
}
source_afunix_options { $$ = last_driver; free($1); }
;
source_afunix_stream_params
: string
{
create_and_set_unix_stream_or_systemd_syslog_source($1, configuration);
}
source_afunix_options { $$ = last_driver; free($1); }
;
/* options are common between dgram & stream */
source_afunix_options
: source_afunix_option source_afunix_options
|
;
source_afunix_option
: file_perm_option
| source_afsocket_stream_params {}
| source_reader_option {}
| source_driver_option
| unix_socket_option {}
| KW_OPTIONAL '(' yesno ')' { last_driver->optional = $3; }
| KW_PASS_UNIX_CREDENTIALS '(' yesno ')'
{
AFUnixSourceDriver *self = (AFUnixSourceDriver*) last_driver;
afunix_sd_set_pass_unix_credentials(self, $3);
}
| KW_CREATE_DIRS '(' yesno ')'
{
AFUnixSourceDriver *self = (AFUnixSourceDriver*) last_driver;
afunix_sd_set_create_dirs(self, $3);
}
;
source_afinet
: KW_UDP '(' _inner_src_context_push source_afinet_udp_params _inner_src_context_pop ')' { $$ = $4; }
| KW_TCP '(' _inner_src_context_push source_afinet_tcp_params _inner_src_context_pop ')' { $$ = $4; }
| KW_UDP6 '(' _inner_src_context_push source_afinet_udp6_params _inner_src_context_pop ')' { $$ = $4; }
| KW_TCP6 '(' _inner_src_context_push source_afinet_tcp6_params _inner_src_context_pop ')' { $$ = $4; }
;
source_afinet_udp_params
:
{
AFInetSourceDriver *d = afinet_sd_new_udp(configuration);
afinet_grammar_set_source_driver(d);
}
source_afinet_udp_options { $$ = last_driver; }
;
source_afinet_udp6_params
:
{
AFInetSourceDriver *d = afinet_sd_new_udp6(configuration);
afinet_grammar_set_source_driver(d);
}
source_afinet_udp_options { $$ = last_driver; }
;
source_afinet_udp_options
: source_afinet_udp_option source_afinet_udp_options
|
;
source_afinet_udp_option
: source_afinet_option
;
source_afinet_option
: KW_LOCALIP '(' string ')' { afinet_sd_set_localip(last_driver, $3); free($3); }
| KW_IP '(' string ')' { afinet_sd_set_localip(last_driver, $3); free($3); }
| KW_LOCALPORT '(' string_or_number ')' { CHECK_ERROR(cfg_check_port($3), @3, "Illegal port number: %s", $3); afinet_sd_set_localport(last_driver, $3); free($3); }
| KW_PORT '(' string_or_number ')' { CHECK_ERROR(cfg_check_port($3), @3, "Illegal port number: %s", $3); afinet_sd_set_localport(last_driver, $3); free($3); }
| source_reader_option
| source_driver_option
| inet_socket_option
;
source_afinet_tcp_params
:
{
AFInetSourceDriver *d = afinet_sd_new_tcp(configuration);
afinet_grammar_set_source_driver(d);
}
source_afinet_tcp_options { $$ = last_driver; }
;
source_afinet_tcp6_params
:
{
AFInetSourceDriver *d = afinet_sd_new_tcp6(configuration);
afinet_grammar_set_source_driver(d);
}
source_afinet_tcp_options { $$ = last_driver; }
;
source_afinet_tcp_options
: source_afinet_tcp_option source_afinet_tcp_options
|
;
source_afinet_tcp_option
: source_afinet_option
| KW_TLS
{
gchar buf[256];
last_tls_context = tls_context_new(TM_SERVER, cfg_lexer_format_location(lexer, &@1, buf, sizeof(buf)));
}
'(' tls_options ')'
{
afinet_sd_set_tls_context(last_driver, last_tls_context);
}
| source_afsocket_stream_params {}
;
source_afsocket_stream_params
: KW_KEEP_ALIVE '(' yesno ')' { afsocket_sd_set_keep_alive(last_driver, $3); }
| KW_MAX_CONNECTIONS '(' positive_integer ')' { afsocket_sd_set_max_connections(last_driver, $3); }
| KW_LISTEN_BACKLOG '(' positive_integer ')' { afsocket_sd_set_listen_backlog(last_driver, $3); }
| KW_DYNAMIC_WINDOW_SIZE '(' nonnegative_integer ')' { afsocket_sd_set_dynamic_window_size(last_driver, $3); }
| KW_DYNAMIC_WINDOW_STATS_FREQ '(' nonnegative_float ')' { afsocket_sd_set_dynamic_window_stats_freq(last_driver, $3); }
| KW_DYNAMIC_WINDOW_REALLOC_TICKS '(' nonnegative_integer ')' { afsocket_sd_set_dynamic_window_realloc_ticks(last_driver, $3); }
;
source_afsyslog
: KW_SYSLOG '(' _inner_src_context_push source_afsyslog_params _inner_src_context_pop ')' { $$ = $4; }
;
source_afsyslog_params
:
{
/* we use transport(tcp) transport by default */
AFInetSourceDriver *d = afinet_sd_new_syslog(configuration);
afinet_grammar_set_source_driver(d);
}
source_afsyslog_options { $$ = last_driver; }
;
source_afsyslog_options
: source_afsyslog_option source_afsyslog_options
|
;
source_afsyslog_option
: source_afinet_option
| source_afsocket_transport
| source_afsocket_stream_params {}
;
source_afnetwork
: KW_NETWORK '(' _inner_src_context_push source_afnetwork_params _inner_src_context_pop ')' { $$ = $4; }
;
source_afnetwork_params
:
{
/* we use transport(tcp) transport by default */
AFInetSourceDriver *d = afinet_sd_new_network(configuration);
afinet_grammar_set_source_driver(d);
}
source_afnetwork_options { $$ = last_driver; }
;
source_afnetwork_options
: source_afnetwork_option source_afnetwork_options
|
;
source_afnetwork_option
: source_afinet_option
| source_afsocket_transport
| source_afsocket_stream_params {}
;
source_afsocket_transport
: afsocket_transport
| KW_TRANSPORT '(' string
{
Plugin *p;
gint context = LL_CONTEXT_SERVER_PROTO;
p = cfg_find_plugin(configuration, context, $3);
if (p)
{
/* for transports with grammar */
if (p->parser)
{
LogProtoServerFactory *sf = cfg_parse_plugin(configuration, p, &@3, last_proto_server_options);
((AFSocketSourceDriver *) last_driver)->proto_factory = sf;
}
}
transport_mapper_set_transport(last_transport_mapper, $3);
}
')' { free($3); }
| KW_TLS
{
gchar buf[256];
last_tls_context = tls_context_new(TM_SERVER, cfg_lexer_format_location(lexer, &@1, buf, sizeof(buf)));
}
'(' tls_options ')'
{
afinet_sd_set_tls_context(last_driver, last_tls_context);
}
;
source_systemd_syslog
: KW_SYSTEMD_SYSLOG '(' _inner_src_context_push source_systemd_syslog_params _inner_src_context_pop ')' { $$ = $4; }
;
source_systemd_syslog_params
: {
#if ! SYSLOG_NG_ENABLE_SYSTEMD
msg_error("systemd-syslog() source cannot be enabled and it is not"
" functioning. Please compile your syslog-ng with --enable-systemd"
" flag", cfg_lexer_format_location_tag(lexer, &@0));
YYERROR;
#else
SystemDSyslogSourceDriver *d = systemd_syslog_sd_new(configuration, FALSE);
systemd_syslog_grammar_set_source_driver(d);
#endif
}
source_systemd_syslog_options { $$ = last_driver; }
;
source_systemd_syslog_options
: source_systemd_syslog_option source_systemd_syslog_options
|
;
source_systemd_syslog_option
: source_reader_option
| socket_option
| source_driver_option
;
dest_afunix
: KW_UNIX_DGRAM '(' _inner_dest_context_push dest_afunix_dgram_params _inner_dest_context_pop ')' { $$ = $4; }
| KW_UNIX_STREAM '(' _inner_dest_context_push dest_afunix_stream_params _inner_dest_context_pop ')' { $$ = $4; }
;
dest_afunix_dgram_params
: string
{
AFUnixDestDriver *d = afunix_dd_new_dgram($1, configuration);
afunix_grammar_set_dest_driver(d);
}
dest_afunix_options { $$ = last_driver; free($1); }
;
dest_afunix_stream_params
: string
{
AFUnixDestDriver *d = afunix_dd_new_stream($1, configuration);
afunix_grammar_set_dest_driver(d);
}
dest_afunix_options { $$ = last_driver; free($1); }
;
dest_afunix_options
: dest_afunix_options dest_afunix_option
|
;
dest_afunix_option
: dest_writer_option
| dest_afsocket_option
| socket_option
| dest_driver_option
;
dest_afinet
: KW_UDP '(' _inner_dest_context_push dest_afinet_udp_params _inner_dest_context_pop ')' { $$ = $4; }
| KW_TCP '(' _inner_dest_context_push dest_afinet_tcp_params _inner_dest_context_pop ')' { $$ = $4; }
| KW_UDP6 '(' _inner_dest_context_push dest_afinet_udp6_params _inner_dest_context_pop ')' { $$ = $4; }
| KW_TCP6 '(' _inner_dest_context_push dest_afinet_tcp6_params _inner_dest_context_pop ')' { $$ = $4; }
;
dest_afinet_udp_params
: string
{
AFInetDestDriver *d = afinet_dd_new_udp($1, configuration);
afinet_grammar_set_dest_driver(d);
}
dest_afinet_udp_options { $$ = last_driver; free($1); }
;
dest_afinet_udp6_params
: string
{
AFInetDestDriver *d = afinet_dd_new_udp6($1, configuration);
afinet_grammar_set_dest_driver(d);
}
dest_afinet_udp_options { $$ = last_driver; free($1); }
;
dest_afinet_udp_options
: dest_afinet_udp_options dest_afinet_udp_option
|
;
dest_afinet_option
: KW_LOCALIP '(' string ')' { afinet_dd_set_localip(last_driver, $3); free($3); }
| KW_LOCALPORT '(' string_or_number ')' { CHECK_ERROR(cfg_check_port($3), @3, "Illegal port number: %s", $3); afinet_dd_set_localport(last_driver, $3); free($3); }
| KW_PORT '(' string_or_number ')' { CHECK_ERROR(cfg_check_port($3), @3, "Illegal port number: %s", $3); afinet_dd_set_destport(last_driver, $3); free($3); }
| KW_DESTPORT '(' string_or_number ')' { CHECK_ERROR(cfg_check_port($3), @3, "Illegal port number: %s", $3); afinet_dd_set_destport(last_driver, $3); free($3); }
| KW_FAILOVER_SERVERS { afinet_dd_enable_failover(last_driver); } '(' string_list ')' { afinet_dd_add_failovers(last_driver, $4); }
| KW_FAILOVER { afinet_dd_enable_failover(last_driver); } '(' dest_failover_options ')' { $$ = $4; }
| inet_socket_option
| dest_writer_option
| dest_afsocket_option
| dest_driver_option
;
dest_failover_options
: KW_SERVERS '(' string_list ')' { afinet_dd_add_failovers(last_driver, $3); } dest_failover_modes_options
;
dest_failover_modes_options
: dest_failback_options
|
;
dest_failback_options
: KW_FAILBACK { afinet_dd_enable_failback(last_driver); } '(' dest_failback_probe_options ')'
;
dest_failback_probe_options
: dest_failback_probe_options dest_failback_probe_option
|
;
dest_failback_probe_option
: KW_TCP_PROBE_INTERVAL '(' positive_integer ')' { afinet_dd_set_failback_tcp_probe_interval(last_driver, $3); }
| KW_SUCCESSFUL_PROBES_REQUIRED '(' positive_integer ')' { afinet_dd_set_failback_successful_probes_required(last_driver, $3); }
;
dest_afinet_dgram_option
: KW_SPOOF_SOURCE '(' yesno ')' { afinet_dd_set_spoof_source(last_driver, $3); }
| KW_SPOOF_SOURCE_MAX_MSGLEN '(' positive_integer ')' { afinet_dd_set_spoof_source_max_msglen(last_driver, $3); }
;
dest_afinet_udp_option
: dest_afinet_option
| dest_afinet_dgram_option
;
dest_afinet_tcp_params
: string
{
AFInetDestDriver *d = afinet_dd_new_tcp($1, configuration);
afinet_grammar_set_dest_driver(d);
}
dest_afinet_tcp_options { $$ = last_driver; free($1); }
;
dest_afinet_tcp6_params
: string
{
AFInetDestDriver *d = afinet_dd_new_tcp6($1, configuration);
afinet_grammar_set_dest_driver(d);
}
dest_afinet_tcp_options { $$ = last_driver; free($1); }
;
dest_afinet_tcp_options
: dest_afinet_tcp_options dest_afinet_tcp_option
|
;
dest_afinet_tcp_option
: dest_afinet_option
| KW_TLS
{
gchar buf[256];
last_tls_context = tls_context_new(TM_CLIENT, cfg_lexer_format_location(lexer, &@1, buf, sizeof(buf)));
}
'(' dest_tls_options ')'
{
afinet_dd_set_tls_context(last_driver, last_tls_context);
}
;
dest_afsocket_option
: KW_KEEP_ALIVE '(' yesno ')' { afsocket_dd_set_keep_alive(last_driver, $3); }
| KW_CLOSE_ON_INPUT '(' yesno ')'
{
afsocket_dd_set_close_on_input(last_driver, $3);
log_proto_client_options_set_drop_input(last_proto_client_options, !$3);
}
;
dest_afsyslog
: KW_SYSLOG '(' _inner_dest_context_push dest_afsyslog_params _inner_dest_context_pop ')' { $$ = $4; }
dest_afsyslog_params
: string
{
AFInetDestDriver *d = afinet_dd_new_syslog($1, configuration);
afinet_grammar_set_dest_driver(d);
}
dest_afsyslog_options { $$ = last_driver; free($1); }
;
dest_afsyslog_options
: dest_afsyslog_options dest_afsyslog_option
|
;
dest_afsyslog_option
: dest_afinet_option
| dest_afsocket_transport
;
dest_afnetwork
: KW_NETWORK '(' _inner_dest_context_push dest_afnetwork_params _inner_dest_context_pop ')' { $$ = $4; }
;
dest_afnetwork_params
: string
{
AFInetDestDriver *d = afinet_dd_new_network($1, configuration);
afinet_grammar_set_dest_driver(d);
}
dest_afnetwork_options { $$ = last_driver; free($1); }
;
dest_afnetwork_options
: dest_afnetwork_options dest_afnetwork_option
|
;
dest_afnetwork_option
: dest_afinet_option
| dest_afsocket_transport
;
dest_afsocket_transport
: afsocket_transport
| KW_TRANSPORT '(' string
{
Plugin *p;
gint context = LL_CONTEXT_CLIENT_PROTO;
p = cfg_find_plugin(configuration, context, $3);
if (p)
{
/* for transports with grammar */
if (p->parser)
{
LogProtoClientFactory *cf = cfg_parse_plugin(configuration, p, &@3, last_proto_client_options);
((AFSocketDestDriver *) last_driver)->proto_factory = cf;
}
}
transport_mapper_set_transport(last_transport_mapper, $3);
}
')' { free($3); }
| dest_afinet_dgram_option
| KW_TLS
{
gchar buf[256];
last_tls_context = tls_context_new(TM_CLIENT, cfg_lexer_format_location(lexer, &@1, buf, sizeof(buf)));
}
'(' dest_tls_options ')'
{
afinet_dd_set_tls_context(last_driver, last_tls_context);
}
;
afsocket_transport
: KW_TRANSPORT '(' KW_TCP ')' { transport_mapper_set_transport(last_transport_mapper, "tcp"); }
| KW_TRANSPORT '(' KW_UDP ')' { transport_mapper_set_transport(last_transport_mapper, "udp"); }
| KW_TRANSPORT '(' KW_TLS ')' { transport_mapper_set_transport(last_transport_mapper, "tls"); }
| KW_IP_PROTOCOL '(' inet_ip_protocol_option ')' { transport_mapper_set_address_family(last_transport_mapper, $3); }
;
dest_tls_options
: dest_tls_option dest_tls_options
|
;
dest_tls_option
: tls_option
| KW_SNI '(' yesno ')'
{
if ($3)
tls_context_set_sni(last_tls_context, ((AFInetDestDriver *)last_driver)->primary);
}
| KW_OCSP_STAPLING_VERIFY '(' yesno ')'
{
tls_context_set_ocsp_stapling_verify(last_tls_context, $3);
}
;
tls_options
: tls_option tls_options
|
;
tls_option
: KW_IFDEF {
}
| KW_PEER_VERIFY '(' yesno ')'
{
gint verify_mode = $3 ? (TVM_REQUIRED | TVM_TRUSTED) : (TVM_OPTIONAL | TVM_UNTRUSTED);
tls_context_set_verify_mode(last_tls_context, verify_mode);
}
| KW_PEER_VERIFY '(' string ')'
{
CHECK_ERROR(tls_context_set_verify_mode_by_name(last_tls_context, $3), @3,
"unknown peer-verify() argument");
free($3);
}
| KW_KEY_FILE '(' path_secret ')'
{
tls_context_set_key_file(last_tls_context, $3);
free($3);
}
| KW_KEYLOG_FILE '(' string ')'
{
GError *error = NULL;
CHECK_ERROR_GERROR(tls_context_set_keylog_file(last_tls_context, $3, &error), @3, error, "Error setting keylog-file()");
free($3);
}
| KW_CERT_FILE '(' path_check ')'
{
tls_context_set_cert_file(last_tls_context, $3);
free($3);
}
| KW_DHPARAM_FILE '(' path_check ')'
{
tls_context_set_dhparam_file(last_tls_context, $3);
free($3);
}
| KW_PKCS12_FILE '(' path_check ')'
{
tls_context_set_pkcs12_file(last_tls_context, $3);
free($3);
}
| KW_CA_DIR '(' string ')'
{
tls_context_set_ca_dir(last_tls_context, $3);
free($3);
}
| KW_CRL_DIR '(' string ')'
{
tls_context_set_crl_dir(last_tls_context, $3);
free($3);
}
| KW_CA_FILE '(' path_check ')'
{
tls_context_set_ca_file(last_tls_context, $3);
free($3);
}
| KW_TRUSTED_KEYS '(' string_list ')'
{
tls_session_set_trusted_fingerprints(last_tls_context, $3);
}
| KW_TRUSTED_DN '(' string_list ')'
{
tls_session_set_trusted_dn(last_tls_context, $3);
}
| KW_CIPHER_SUITE '(' tls_cipher_suites ')'
| KW_CIPHER_SUITE '(' string ')'
{
/* compat for specifying TLS 1.2-or-older ciphers */
tls_context_set_cipher_suite(last_tls_context, $3);
free($3);
}
| KW_SIGALGS '(' string ')'
{
GError *error = NULL;
CHECK_ERROR_GERROR(tls_context_set_sigalgs(last_tls_context, $3, &error), @3, error, "Error setting sigalgs()");
free($3);
}
| KW_CLIENT_SIGALGS '(' string ')'
{
GError *error = NULL;
CHECK_ERROR_GERROR(tls_context_set_client_sigalgs(last_tls_context, $3, &error), @3, error, "Error setting client-sigalgs()");
free($3);
}
| KW_ECDH_CURVE_LIST '(' string ')'
{
tls_context_set_ecdh_curve_list(last_tls_context, $3);
free($3);
}
| KW_SSL_OPTIONS '(' string_list ')'
{
CHECK_ERROR(tls_context_set_ssl_options_by_name(last_tls_context, $3), @3,
"unknown ssl-options() argument");
}
| KW_SSL_VERSION '(' string ')'
{
CHECK_ERROR(tls_context_set_ssl_version_by_name(last_tls_context, $3), @3,
"unknown ssl-version() argument");
free($3);
}
| KW_ALLOW_COMPRESS '(' yesno ')'
{
transport_mapper_inet_set_allow_compress(last_transport_mapper, $3);
}
| KW_CONF_CMDS '(' tls_conf_cmds ')'
{
GError *error = NULL;
CHECK_ERROR_GERROR(tls_context_set_conf_cmds(last_tls_context, $3, &error), @3, error, "Error setting conf-cmds()");
}
| KW_ENDIF {
}
;
tls_conf_cmds
: tls_conf_cmd_list_build
{
$$ = $1;
}
;
tls_conf_cmd_list_build
: string LL_ARROW string tls_conf_cmd_list_build
{
/* Revers order is important here as this is inside of a bison right recursion */
$$ = g_list_prepend($4, g_strdup($3));
$$ = g_list_prepend($$, g_strdup($1));
free($1);
free($3);
}
|
{
$$ = NULL;
}
;
tls_cipher_suites
: tls_cipher_suite tls_cipher_suites
|
;
tls_cipher_suite
: KW_TLS12_AND_OLDER '(' string ')'
{
tls_context_set_cipher_suite(last_tls_context, $3);
free($3);
}
| KW_TLS13 '(' string ')'
{
GError *error = NULL;
CHECK_ERROR_GERROR(tls_context_set_tls13_cipher_suite(last_tls_context, $3, &error), @3, error, "Error setting cipher-suite(tls13())");
free($3);
}
;
socket_option
: KW_SO_SNDBUF '(' nonnegative_integer ')'
{
CHECK_ERROR($3 <= G_MAXINT, @3, "Invalid so_sndbuf, it has to be less than %d", G_MAXINT);
last_sock_options->so_sndbuf = $3;
}
| KW_SO_RCVBUF '(' nonnegative_integer ')'
{
CHECK_ERROR($3 <= G_MAXINT, @3, "Invalid so_rcvbuf, it has to be less than %d", G_MAXINT);
last_sock_options->so_rcvbuf = $3;
}
| KW_SO_BROADCAST '(' yesno ')' { last_sock_options->so_broadcast = $3; }
| KW_SO_KEEPALIVE '(' yesno ')' { last_sock_options->so_keepalive = $3; }
| KW_SO_REUSEPORT '(' yesno ')' { last_sock_options->so_reuseport = $3; }
;
unix_socket_option
: socket_option
| KW_SO_PASSCRED '(' yesno ')' { socket_options_unix_set_so_passcred(last_sock_options, $3); }
;
inet_socket_option
: socket_option
| KW_IP_TTL '(' nonnegative_integer ')' { ((SocketOptionsInet *) last_sock_options)->ip_ttl = $3; }
| KW_IP_TOS '(' nonnegative_integer ')' { ((SocketOptionsInet *) last_sock_options)->ip_tos = $3; }
| KW_IP_FREEBIND '(' yesno ')' { ((SocketOptionsInet *) last_sock_options)->ip_freebind = $3; }
| KW_INTERFACE '(' string ')' { socket_options_inet_set_interface_name((SocketOptionsInet *) last_sock_options, $3); free($3); }
| KW_TCP_KEEPALIVE_TIME '(' nonnegative_integer ')'
{
CHECK_ERROR(socket_options_inet_set_tcp_keepalive_time((SocketOptionsInet *) last_sock_options, $3), @1,
"The tcp-keepalive-time() option is not supported on this platform");
}
| KW_TCP_KEEPALIVE_INTVL '(' nonnegative_integer ')'
{
CHECK_ERROR(socket_options_inet_set_tcp_keepalive_intvl((SocketOptionsInet *) last_sock_options, $3), @1,
"The tcp-keepalive-intvl() option is not supported on this platform");
}
| KW_TCP_KEEPALIVE_PROBES '(' nonnegative_integer ')'
{
CHECK_ERROR(socket_options_inet_set_tcp_keepalive_probes((SocketOptionsInet *) last_sock_options, $3), @1,
"The tcp-keepalive-probes() option is not supported on this platform");
}
;
inet_ip_protocol_option
: LL_NUMBER
{
CHECK_ERROR($1 == 4 || $1 == 6, @1, "ip-protocol option can only be 4 or 6!");
if ($1 == 4)
{
$$ = AF_INET;
}
else
{
$$ = AF_INET6;
}
}
;
/* INCLUDE_RULES */
%%
|