1# The syslogd listens on 127.0.0.1 TCP socket.
2# The client writes octet counting message that is too long.
3# The syslogd writes it into a file and through a pipe.
4# The syslogd passes it via UDP to the loghost.
5# The server receives the message on its UDP socket.
6# Find the message in client, file, syslogd, server log.
7# Check that the file log contains the truncated message.
8
9use strict;
10use warnings;
11use Socket qw(AF_INET IPPROTO_TCP TCP_NOPUSH);
12use constant MAXLINE => 8192;
13use constant MAX_UDPMSG => 1180;
14
15our %args = (
16    client => {
17	connect => { domain => AF_INET, proto => "tcp", addr => "127.0.0.1",
18	    port => 514 },
19	func => sub {
20	    my $self = shift;
21	    local $| = 1;
22	    my $msg = generate_chars(MAXLINE+1);
23	    printf "%05d %s", MAXLINE+1, $msg;
24	    print STDERR "<<< $msg\n";
25	    ${$self->{syslogd}}->loggrep(qr/tcp logger .* use \d+ bytes/, 5)
26		or die ref($self), " syslogd did not use bytes";
27	    setsockopt(\*STDOUT, IPPROTO_TCP, TCP_NOPUSH, pack('i', 1))
28		or die ref($self), " set TCP_NOPUSH failed: $!";
29	    $msg = generate_chars(MAXLINE);
30	    printf "%05d %s", MAXLINE+1, $msg;
31	    print STDERR "<<< $msg\n";
32	    setsockopt(\*STDOUT, IPPROTO_TCP, TCP_NOPUSH, pack('i', 0))
33		or die ref($self), " clear TCP_NOPUSH failed: $!";
34	    ${$self->{syslogd}}->loggrep("tcp logger .* incomplete", 5)
35		or die ref($self), " syslogd did not receive incomplete";
36	    print "\n";
37	    print STDERR "<<< \n";
38	    write_shutdown($self);
39	},
40	loggrep => {
41	    qr/<<< 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ/ => 2,
42	},
43    },
44    syslogd => {
45	options => ["-T", "127.0.0.1:514"],
46	loggrep => {
47	    qr/octet counting /.(MAXLINE+1).qr/, incomplete frame, /.
48		qr/buffer \d+ bytes/ => 2,
49	    qr/octet counting /.(MAXLINE+1).
50		qr/, use /.(MAXLINE+1).qr/ bytes/ => 2,
51	},
52    },
53    server => {
54	# >>> <13>Jul  6 22:33:32 0123456789ABC...fgh
55	loggrep => {
56	    qr/>>> .{19} /.generate_chars(MAX_UDPMSG-20).qr/$/ => 2,
57	}
58    },
59    file => {
60	loggrep => {
61	    generate_chars(MAXLINE).qr/$/ => 2,
62	},
63    },
64    pipe => { nocheck => 1 },  # XXX syslogd ignore short writes to pipe
65    tty => { nocheck => 1 },  # XXX syslogd ignore short writes to pipe
66);
67
681;
69