chiark / gitweb /
docs: Generate grammar and option summaries from manpage.
[fwd] / fw.1.in
CommitLineData
10a454ad 1.\" -*-nroff-*-
667fb920 2.\"
b69a615b 3.\" $Id$
667fb920 4.\"
5.\" Manual page for fw
6.\"
7.\" (c) 1999 Straylight/Edgeware
8.\"
9.
10.\"----- Licensing notice ---------------------------------------------------
11.\"
12.\" This file is part of the `fw' port forwarder.
13.\"
14.\" `fw' is free software; you can redistribute it and/or modify
15.\" it under the terms of the GNU General Public License as published by
16.\" the Free Software Foundation; either version 2 of the License, or
17.\" (at your option) any later version.
18.\"
19.\" `fw' is distributed in the hope that it will be useful,
20.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
21.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22.\" GNU General Public License for more details.
23.\"
24.\" You should have received a copy of the GNU General Public License
25.\" along with `fw'; if not, write to the Free Software Foundation,
26.\" Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27.
667fb920 28.\"----- Various bits of fancy styling --------------------------------------
29.
30.\" --- Indented paragraphs with right-aligned tags ---
31.
10a454ad 32.de hP
33.IP
34\h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
35..
667fb920 36.
37.\" --- Verbatim-oid typesetting ---
38.de VS
39.sp 1
40.RS
41.nf
42.ft B
43..
44.de VE
45.ft R
46.fi
47.RE
48.sp 1
49..
50.
333c51f4 51.\" --- Grammar markup ---
52.\"
53.\" This is mainly for the benefit of the automatic scripts which
54.\" generate the grammar summary.
55.
56.de GS
57.PP
58..
59.de GE
60.PP
61..
8cf7c7c2
MW
62.de GL
63..
333c51f4 64.
65.de OS
66.PP
67..
68.de OD
69.RS
70..
71.de OE
72.RE
73..
8cf7c7c2
MW
74.de OL
75..
333c51f4 76.
667fb920 77.\" --- Other bits of styling ---
78.
79.ie t \{\
80. ds o \(bu
81. ds ss \s8\u
82. ds se \d\s0
83. if \n(.g \{\
84. fam P
85. \}
86.\}
87.el \{\
88. ds o o
89. ds ss ^
90. ds se
91.\}
92.
93.\"--------------------------------------------------------------------------
94.
d1c182e7 95.TH fw 1 "1 July 1999" "Straylight/Edgeware" "fw port forwarder"
667fb920 96.
97.\"--------------------------------------------------------------------------
10a454ad 98.SH NAME
667fb920 99.
10a454ad 100fw \- port forwarder
667fb920 101.
102.\"--------------------------------------------------------------------------
10a454ad 103.SH SYNOPSIS
667fb920 104.
10a454ad 105.B fw
c42fddf3 106.RB [ \-dlq ]
107.RB [ \-p
faf9726e 108.IR file ]
10a454ad 109.RB [ \-f
110.IR file ]
fc170a33 111.RB [ \-s
112.IR user ]
113.RB [ \-g
114.IR group ]
10a454ad 115.IR config-stmt ...
667fb920 116.
117.\"--------------------------------------------------------------------------
118.SH "DESCRIPTION"
119.
10a454ad 120The
121.B fw
122program is a simple port forwarder. It supports a number of features
123the author hasn't found in similar programs:
124.TP
125.I "Connection logging"
126Each connection attempt to the forwarder is logged, giving the time of
127the connection, the DNS-resolved hostname (if available), and the user
128name resulting from an RFC931 lookup. These lookups are done
129asynchronously to the main forwarder's operation.
130.TP
131.I "Access control"
132Each forwarded port may have an access control list attached to it.
133Only authorized hosts are allowed to connect. Access control checks are
134performed by quick checks on the client's IP address.
135.TP
136.I "Nonblocking single-process design"
137The internal structure of the server is completely nonblocking. The
138connections don't block; the reading and writing don't block; the name
139lookups don't block. This is all done in a single process, with the
140single exception of the DNS resolver.
667fb920 141.TP
142.I "Support for Unix-domain sockets"
143Connections from and to Unix-domain sockets can be handled just as
96bc31ba 144easily as more normal Internet sockets. Access control doesn't work on
667fb920 145Unix domain sockets, though. (Yet.)
10a454ad 146.SS "Command line options"
147The
148.B fw
149program understands a few simple command line options:
150.TP
151.B "\-h, \-\-help"
152Displays a screen of help text on standard output and exits
153successfully.
154.TP
155.B "\-v, \-\-version"
156Writes the version number to standard output and exits successfully.
157.TP
158.B "\-u, \-\-usage"
159Writes a terse usage summary to standard output and exits successfully.
160.TP
fc170a33 161.B "\-G, \-\-grammar"
162Writes a summary of the configuration file grammar to standard output
163and exits successfully.
164.TP
165.B "\-O, \-\-options"
166Writes a summary of the source and target options to standard output and
167exits successfully.
168.TP
10a454ad 169.BI "\-f, \-\-file=" file
170Read configuration information from
171.IR file .
667fb920 172Equivalent to an
173.RB ` include
174.IR file '
175configuration file statement.
10a454ad 176.TP
667fb920 177.B "\-d, \-\-daemon, \-\-fork"
10a454ad 178Forks into the background after reading the configuration and
179initializing properly.
667fb920 180.TP
370e3c14 181.B "\-l, \-\-syslog, \-\-log"
182Emit logging information to the system log, rather than standard error.
183.TP
faf9726e 184.BI "\-p, \-\-pidfile=" file
4166ea7c 185Write
186.BR fw 's
187process-id to
188.I file
189during start-up. If
190.B \-d
191is given too, then the process-id is written after forking (obviously).
192.TP
fc170a33 193.B "\-q, \-\-quiet"
667fb920 194Don't output any logging information. This option is not recommended
195for normal use, although it can make system call traces clearer so I use
196it when debugging.
fc170a33 197.TP
198.BI "\-s, \-\-setuid=" user
199Change uid to that of
200.IR user ,
201which may be either a user name or uid number, after initializing all
202the sources. This will usually require elevated privileges.
203.TP
204.BI "\-g, \-\-setgid=" group
205Change gid to that of
206.IR group ,
207which may be either a group name or gid number, after initializing all
208the sources. If the operating system understands supplementary groups
209then the supplementary groups list is altered to include only
210.IR group .
10a454ad 211.PP
212Any further command line arguments are interpreted as configuration
213lines to be read. Configuration supplied in command line arguments has
214precisely the same syntax as configuration in files. If there are no
96bc31ba 215configuration statements on the command line, and no
10a454ad 216.B \-f
217options were supplied, configuration is read from standard input, if
218stdin is not a terminal.
667fb920 219.
220.\"--------------------------------------------------------------------------
221.SH "CONFIGURATION LANGUAGE"
222.
223The
224.B fw
225program has a fairly sophisticated configuration language to let you
226describe which things should be forwarded where and what special
227features there should be.
228.SS "Lexical structure"
229There are four types of characters.
230.TP
231.I "word constituent characters"
96bc31ba 232Word constituent characters are gathered together into words.
667fb920 233Depending on its surrounding context, a word might act as a keyword or a
234string. All alphanumerics are word constituents, as is the hyphen
235.RB ` \- '.
236Other characters may change their status in future versions.
237.TP
238.I "self-delimiting characters"
239Self-delimiting characters always stand alone. They act as punctuation,
240shaping the sequence of words into more complex grammatical forms. The
241characters
242.RB ` { ',
243.RB ` } ',
244.RB ` [ ',
245.RB ` ] ',
246.RB ` / ',
247.RB ` , ',
248.RB ` = ',
249.RB ` : ',
250.RB ` ; '
251and
252.RB ` . '
253are self-delimiting. Note that while some characters, e.g.,
254.RB ` [ '
255and
256.RB ` ; ',
372a98e2 257require escaping by the shell, they are mostly optional in the grammar
258and can tend to be omitted in quick hacks at the shell prompt.
667fb920 259.TP
260.I "whitespace characters"
261Whitespace characters separate words but are otherwise ignored. All
262`normal' whitespace characters (e.g., space, tab and newline) are
263considered to be whitespace for these purposes.
264.TP
265.I "special characters"
266There are three special characters. The
267.RB ` # '
268character, if it appears at the start of a word, introduces a
269.I comment
270which extends to the end of the current line or command-line argument.
271Within a word, it behaves like a normal word-constituent character. The
272backslash
273.RB ` \e '
274escapes the following character causing it to be interpreted as a word
275constituent regardless of its normal type. The double-quote
276.RB ` """" '
277escapes all characters other than backslashes up to the next
278double-quote and causes them to be regarded as word constituents. Note
279that you don't have to quote a whole word. The backslash can escape a
280quote character allowing you to insert it into a word if really
281necessary.
282.
283.SS "Basic syntax"
284The overall syntax looks a bit like this:
333c51f4 285.GS "Basic syntax"
667fb920 286.I file
10a454ad 287::=
667fb920 288.I empty
289|
290.I file
291.I stmt
292.RB [ ; ]
10a454ad 293.br
294.I stmt
295::=
667fb920 296.I option-stmt
297|
298.I fw-stmt
299.br
300.I fw-stmt
301::=
302.B fw
303.I source
304.I options
305.RB [ to | \-> ]
306.I target
307.I options
308.br
309.I options
310::=
311.B {
312.I option-seq
313.B }
314.br
315.I option-seq
316::=
317.I empty
318|
319.I option-stmt
320.RB [ ; ]
321.I option-seq
333c51f4 322.GE
667fb920 323If you prefer, the keyword
324.RB ` fw '
325may be spelt
326.RB ` forward '
327or
328.RB ` from '.
329All are equivalent.
330.
331.SS "Sources and targets"
332Forwarding is set up by attaching
333.I targets
334to
335.IR sources .
336Sources are things which are capable of
337.I initiating
338one end of a data flow on their own, while targets are things which are
339capable of setting up the other end on demand. In the case of a TCP
340port forwarder, the part which listens for incoming client connections
341is the source, while the part which sets up outgoing connections to the
342destination server is the target.
343.PP
344Essentially, all
345.B fw
346does is set up a collection of sources and targets based on your
347configuration file so that when a source decides to initiate a data
348flow, it tells its target to set its end up, and then squirts data back
349and forth between the two until there's no more.
350.PP
351Some sources are
352.IR persistent :
353they stay around indefinitely setting up multiple attachments to
354targets. Others are
355.IR transient :
356they set up one connection and then disappear. If all the sources
357defined are transient, then
358.B fw
359will quit when no more active sources remain and all connections have
360terminated.
361.PP
362The
363.B fw
364program is fairly versatile. It allows you to attach any supported type
365of source to any supported type of target. This will, I hope, be the
366case in all future versions.
367.PP
368The syntax of a
369.I source
370or
371.I target
372depend on the source or target type, and are therefore described in the
373sections specific to the various types.
374.
375.SS "Options structure"
376Most of the objects that
377.B fw
378knows about (including sources and targets, but also other more specific
379things such as socket address types) can have their behaviour modified
380by
381.IR options .
382The options available at a particular point in the configuration depend
383on the
384.IR context .
385A global option, outside of a
386.I fw-stmt
387has no context unless it is explicitly qualified, and affects global
723210e6 388behaviour. A local option, applied to a source or target in a
389.IR fw-stmt ,
667fb920 390has the context of the type of source or target to which it is applied,
391and affects only that source or target.
392.PP
393Note that it's important to distinguish between an option's context
394(which is affected by its qualification) and its local or global
395status. No matter how qualified, a global option will always control
396default options for objects, and a local option will only affect a
397specific source or target.
398.PP
399The syntax for qualifying options is like this:
333c51f4 400.GS "Option syntax"
667fb920 401.I option-stmt
402::=
403.I q-option
404.br
405.I q-option
406::=
407.I option
408.br
409 |
410.I prefix
23be5eb0 411.B .\&
667fb920 412.I q-option
413.br
414 |
415.I prefix
416.B {
417.I option-seq
418.B }
419.br
420.I prefix
421::=
422.I word
333c51f4 423.GE
667fb920 424Thus, you may qualify either an individual option or a sequence of
425options. The two are equivalent; for example,
426.VS
427exec.rlimit {
428 core = 0;
429 cpu = 60;
430}
431.VE
723210e6 432means the same as
667fb920 433.VS
434exec.rlimit.core = 0;
435exec.rlimit.cpu = 0;
436.VE
437For each option, there is a sequence of prefixes which maximally qualify
438that option. An option prefixed with this sequence is
439.IR "fully qualified" .
440In actual use, some or all of those prefixes may be omitted. However,
441it's possible for the option to become
442.I ambiguous
443if you do this. For example, the option
444.B fattr.owner
445may refer either to
446.B file.fattr.owner
447or to
448.BR socket.unix.fattr.owner .
449In this case, the ambiguity is benign: a local option will have as its
450context an appropriate source or target, and both global options
451actually control the same default. However, the option
452.B logging
453may mean either
454.B socket.logging
455or
456.BR exec.logging ,
457which have separate defaults, and which one you actually get depends on
458the exact implementation of
459.BR fw 's
460option parser. (Currently this would resolve to
461.BR exec.logging ,
462although this may change in a later version.)
463.PP
464In this manual, options are usually shown in their fully-qualified form.
465.
333c51f4 466.SS "File attributes for created files: `fattr'"
467Both the
468.B file
469and
470.B socket
471sources and targets can create new filesystem objects. The
472.B fattr
473options allow control over the attributes of the newly-created objects.
474Both
475.B file
476and
477.B socket
478use the same set of defaults, so a prefix of
479.B fattr
480is good enough for setting global options, and the implicit context
481disambiguates local options.
482.PP
483The following file attribute options are supported:
8cf7c7c2 484.OS "File attributes (`fattr')"
333c51f4 485.IB prefix .fattr.mode
486.RB [ = ]
487.I mode
488.OD
489Sets the permissions mode for a new file. The
490.I mode
491argument may be either an octal number or a
492.BR chmod (1)-style
493string which acts on the default permissions established by the
494prevailing
495.BR umask (2)
496setting. The characters
497.RB ` = '
498and
499.RB ` , '
500do not have to be quoted within the mode string.
501.OE
8cf7c7c2 502.OS "File attributes (`fattr')"
333c51f4 503.IB prefix .fattr.owner
504.RB [ = ]
505.I user
506.OD
507Sets the owner for newly created files. On non-broken systems you will
508need to be the superuser to set the owner on a file. The
509.I user
510may either be a numeric uid or a username. The default is not to change
511the owner of the file once it's created. The synonyms
512.B uid
513and
514.B user
515are accepted in place of
516.BR owner .
517.OE
8cf7c7c2 518.OS "File attributes (`fattr')"
333c51f4 519.IB prefix .fattr.group
520.RB [ = ]
521.I group
522.OD
523Sets the group for newly created files. You will usually need to be a
524member of the group in question order to set the group of a file. The
525.I group
526may either be a numeric gid or a group name. The default is not to
527change the group of the file once it's created. The synonym
528.B gid
529is accepted in place of
530.BR group .
531.OE
532.
667fb920 533.SS "The `file' source and target types"
534The
535.B file
536source and target allow data to move to and from objects other
537than sockets within the Unix filesystem. (Unix-domain sockets are
538handled using the
539.B socket
540source and target.)
541.PP
542If a
543.B file
544is used as a source, it is set up immediately.
545.PP
546The syntax of
547.B file
548sources and targets is like this:
8cf7c7c2 549.GS "File source and target"
667fb920 550.I source
551::=
552.I file
553.br
554.I target
555::=
556.I file
557.br
558.I file
559::=
560.B file
23be5eb0 561.RB [ .\& ]
667fb920 562.I fspec
563.RB [ ,
564.IR fspec ]
565.br
566.I fspec
567::=
568.I fd-spec
569|
570.I name-spec
571|
572.I null-spec
573.br
574.I fd-spec
575::=
576.RB [[ : ] fd [ : ]]
577.IR number \c
578.RB | stdin | stdout
579.br
580.I name-spec
581::=
b69a615b 582.RB [[ : ] name [ : ]]
667fb920 583.I file-name
584.br
585.I file-name
586::=
587.I path-seq
588|
589.B [
590.I path-seq
591.B ]
592.br
593.I path-seq
594::=
595.I path-elt
596|
597.I path-seq
598.I path-elt
599.br
600.I path-elt
601::=
602.B /
603|
604.I word
605.br
606.I null-spec
607::=
e73034b0 608.RB [ : ] null [ : ]
333c51f4 609.GE
667fb920 610The
611.I file
612specification describes two files, the first to be used as input, the
613second to be used as output, each described by an
614.IR fspec .
615.PP
616If none of the keywords
617.RB ` fd ',
618.RB ` name '
619or
620.RB ` null '
621are given, the type of an
622.I fspec
623is deduced from its nature: if it matches one of the strings
624.RB ` stdin '
625or
626.RB ` stdout ',
627or begins with a digit, it's considered to be a file descriptor;
628otherwise it's interpreted as a filename.
629.PP
630A
631.RB ` name '
632spec describes a file by its name within the filesystem. It is opened
633when needed and closed again after use. For output files, the precise
634behaviour is controlled by options described below.
635.PP
636A
637.RB ` null '
638spec attaches the input or output of the source or target to
639.BR /dev/null .
640.PP
641An
642.RB ` fd '
643spec uses an existing open file descriptor, given either by number or a
644symbolic name. The name
645.RB ` stdin '
646refers to standard input (file descriptor 0 on normal systems) and
647.RB ` stdout '
648refers to standard output (file descriptor 1). The names work in
649exactly the same way as the equivalent file descriptor numbers.
650.PP
651If the output
652.I fspec
653is omitted, the input
654.I fspec
655is used for both input and output. Exception: if the input refers to
656standard input then the output will refer to standard output instead.
657.PP
658All
659.B file
660options apply equally to sources and targets. The options are as
661follows:
333c51f4 662.OS "File options"
667fb920 663.B file.create
664.RB [ = ]
665.BR yes | no
333c51f4 666.OD
667fb920 667Whether to create the output file if it doesn't exist. If
668.B no
669(the default), an error is reported if the file doesn't exist. If
670.BR yes ,
671the file is created if it doesn't exist.
333c51f4 672.OE
673.OS "File options"
667fb920 674.B file.open
675.RB [ = ]
676.BR no | truncate | append
333c51f4 677.OD
667fb920 678Controls the behaviour if the output file already exists. If
679.BR no ,
680an error is reported. If
681.B truncate
682(the default), the existing file is replaced by the new data. If
683.BR append ,
684the new data is appended to the file.
333c51f4 685.OE
686.OS "File options"
8cf7c7c2 687.BR file.fattr. *
333c51f4 688.OD
667fb920 689The
690.B file
691source and target also accept
692.B fattr
333c51f4 693options for controlling the attributes of the created file.
694.OE
667fb920 695.PP
333c51f4 696Under no circumstances will
697.B fw
698create a file through a `dangling' symbolic link.
667fb920 699.
700.SS "The `exec' source and target types"
701The
702.B exec
703source and target execute programs and allow access to their standard
704input and output streams. Both source and target have the same syntax,
705which is as follows:
333c51f4 706.GS "Exec source and target"
667fb920 707.I source
708::=
709.I exec
710.br
711.I target
712::=
8cf7c7c2 713.I exec
667fb920 714.br
715.I exec
716::=
717.BR exec
23be5eb0 718.RB [ .\& ]
667fb920 719.I cmd-spec
720.br
721.I cmd-spec
722::=
723.I shell-cmd
10a454ad 724|
667fb920 725.RI [ prog-name ]
726.B [
727.I argv0
728.I arg-seq
729.B ]
730.br
731.I arg-seq
732::=
733.I word
734|
735.I arg-seq
736.I word
737.br
738.I shell-cmd
739::=
740.I word
741.br
742.I argv0
743::=
744.I word
333c51f4 745.GE
667fb920 746If a single word is given, it is a
747.I shell-cmd
748and will be passed to the Bourne shell for execution. If a
749bracket-enclosed sequence of words is given, it is considered to be a
750list of arguments to pass to the program: if a
751.I prog-name
752is also supplied, it names the file containing the program to execute;
753otherwise the file named by the first argument
754.RI ( argv0 )
755is used.
756.PP
49f5947b 757Note that the shell command or program name string must, if present,
758have any delimiter characters (including
759.RB ` / '
760and
761.RB ` . ')
762quoted; this is not required in the
763.RB ` [ '-enclosed
764argument list.
765.PP
667fb920 766The standard input and output of the program are forwarded to the other
767end of the connection. The standard error stream is caught by
768.B fw
769and logged.
770.PP
771The
772.B exec
773source and target both understand the same set of options. The list of
774options supported is as follows:
333c51f4 775.OS "Exec options"
667fb920 776.B exec.logging
777.RB [ = ]
778.BR yes | no
333c51f4 779.OD
667fb920 780Whether to log the start and end of executed programs. If
781.B yes
782(the default), a log message is emitted when the program is started
783listing its process id, and another is emitted when the program finishes
784giving its process id and exit status. If
785.BR no ,
786these messages are not emitted. However the standard error stream is
787still logged. The
788.B log
789abbreviation is accepted as a synonym for
790.BR logging .
333c51f4 791.OE
792.OS "Exec options"
667fb920 793.B exec.dir
794.RB [ = ]
795.I file-name
333c51f4 796.OD
667fb920 797Sets the current directory from which the the program should be run.
798The default is not to change directory. The synonyms
799.BR cd ,
800.B chdir
801and
802.B cwd
803are accepted in place of
804.BR dir .
333c51f4 805.OE
806.OS "Exec options"
667fb920 807.B exec.root
808.RB [ = ]
809.I file-name
333c51f4 810.OD
667fb920 811Sets the root directory for the program, using the
812.BR chroot (2)
813system call. You must be the superuser for this option to work. The
372a98e2 814default is not to set a root directory. The synonym
815.B chroot
816is accepted in place of
817.BR root .
333c51f4 818.OE
819.OS "Exec options"
667fb920 820.B exec.user
821.RB [ = ]
822.I user
333c51f4 823.OD
667fb920 824Sets the user (real and effective uid) to run the program as. This will
825usually require superuser privileges to work. The default is not to
826change uid. The synonym
827.B uid
828is accepted in place of
829.BR user .
333c51f4 830.OE
831.OS "Exec options"
667fb920 832.B exec.group
833.RB [ = ]
834.I group
333c51f4 835.OD
667fb920 836Sets the group (real and effective gid) to run the program as. If
837running with superuser privileges, the supplementary groups list is
838cleared at the same time. The default is not to change gid (or clear
839the supplementary groups list). The synonym
840.B gid
841is accepted in place of
842.BR group .
333c51f4 843.OE
844.OS "Exec options"
667fb920 845.BI exec.rlimit. limit \c
846.RB [ .hard | .soft ]
847.RB [ = ]
848.I value
333c51f4 849.OD
667fb920 850Set resource limits for the program. The
851.I limit
852may be one of the resource limit names described in
853.BR setrlimit (2),
854in lower-case and without the
855.B RLIMIT_
856prefix; for example,
857.B RLIMIT_CORE
858becomes simply
859.BR core .
860The
861.I value
862is a number, followed optionally by
863.B k
864to multiply by 1024 (2\*(ss10\*(se),
865.B m
866to multiply by 1048576 (2\*(ss20\*(se), or
867.B g
868to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
869versions of these if they want. If
870.B .hard
871or
872.B .soft
873was specified, only the hard or soft limit is set; otherwise both are
874set to the same value. Only the superuser can raise the hard limit.
875The soft limit cannot be set above the hard limit.
333c51f4 876.OE
877.OS "Exec options"
667fb920 878.B exec.env.clear
333c51f4 879.OD
667fb920 880Clears the program's environment.
333c51f4 881.OE
8cf7c7c2 882.OS "Exec options"
667fb920 883.B exec.env.unset
884.I var
333c51f4 885.OD
667fb920 886Removes
887.I var
888from the program's environment. It is not an error if no variable named
889.I var
890exists.
333c51f4 891.OE
892.OS "Exec options"
667fb920 893.BR exec.env. [ set ]
894.I var
895.RB [ = ]
896.I value
333c51f4 897.OD
96bc31ba 898Assigns the variable
667fb920 899.I var
900the value
901.I value
902in the program's environment, possibly replacing the existing value.
903The
904.B set
905may be omitted if the
906.B env
907qualifier is present.
333c51f4 908.OE
667fb920 909.PP
910Note that environment variable modifications are performed in order,
911global modifications before local ones.
912.
913.SS "The `socket' source and target types"
914The
915.B socket
916source and target provide access to network services. Support is
917currently provided for TCP/IP and Unix-domain sockets, although other
918address types can be added with reasonable ease.
919.PP
920The syntax for socket sources and targets is:
333c51f4 921.GS "Socket source and target"
667fb920 922.ll +8i
923.I source
924::=
925.I socket-source
10a454ad 926.br
667fb920 927.I target
928::=
929.I socket-target
930.br
931.I socket-source
932::=
23be5eb0 933.RB [ socket [ .\& ]]
667fb920 934.RB [[ : ] \c
935.IR addr-type \c
936.RB [ : ]]
937.I source-addr
938.br
939.I socket-target
940::=
23be5eb0 941.RB [ socket [ .\& ]]
667fb920 942.RB [[ : ] \c
943.IR addr-type \c
944.RB [ : ]]
945.I target-addr
946.ll -8i
333c51f4 947.GE
667fb920 948The syntax of the source and target addresses depend on the address
949types, which are described below. The default address type, if no
950.I addr-type
951is given, is
952.BR inet .
953.PP
954Socket sources support options; socket targets do not. The source
955options provided are:
333c51f4 956.OS "Socket options"
667fb920 957.B socket.conn
958.RB [ = ]
d857515e 959.IR number | \c
960.BR unlimited | one-shot
333c51f4 961.OD
d857515e 962Controls the behaviour of the source when it receives connections. A
667fb920 963.I number
d857515e 964limits the number of simultaneous connections. The value
965.B unlimited
966(or
967.BR infinite )
968removes any limit on the number of connections possible. The value
969.B one-shot
970will remove the socket source after a single successful connection.
971(Connections refused by access control systems don't count here.)
972The default is to apply a limit of 256 concurrent connections. Use of
973the
974.B unlimited
975option is not recommended.
333c51f4 976.OE
977.OS "Socket options"
6f427571 978.B socket.listen
979.RB [ = ]
980.I number
981.OD
982Sets the maximum of the kernel incoming connection queue for this socket
983source. This is the number given to the
984.BR listen (2)
985system call. The default is 5.
986.OE
987.OS "Socket options"
667fb920 988.B socket.logging
989.RB [ = ]
990.BR yes | no
333c51f4 991.OD
667fb920 992Whether to log incoming connections. If
993.B yes
994(the default) incoming connections are logged, together with information
995about the client (where available) and whether the connection was
996accepted or refused. If
997.BR no ,
998log messages are not generated.
333c51f4 999.OE
667fb920 1000.PP
1001Address types also provide their own options.
1002.
1003.SS "The `inet' socket address type"
8cf7c7c2
MW
1004.GL "Socket source and target"
1005.OL "Socket options"
667fb920 1006The
1007.B inet
1008address type provides access to TCP ports. The
1009.B inet
1010source and target addresses have the following syntax:
333c51f4 1011.GS "Socket source and target"
667fb920 1012.I inet-source-addr
10a454ad 1013::=
10a454ad 1014.RB [ port ]
1015.I port
667fb920 1016.br
1017.I inet-target-addr
1018::=
1019.I address
10a454ad 1020.RB [ : ]
1021.I port
10a454ad 1022.br
667fb920 1023.I address
10a454ad 1024::=
667fb920 1025.I addr-elt
1026|
1027.I address
1028.I addr-elt
10a454ad 1029.br
667fb920 1030.I addr-elt
10a454ad 1031::=
23be5eb0 1032.B .\&
10a454ad 1033|
667fb920 1034.I word
333c51f4 1035.GE
667fb920 1036A
1037.I port
1038may be given as a port number or a service name from the
1039.B /etc/services
1040file (or YP map if you do that sort of thing). A
1041.B hostname
1042may be a textual hostname or a numerical IP address.
1043.PP
1044The
1045.B inet
1046source address accepts the following options:
333c51f4 1047.OS "Socket options"
1c2054c7 1048.B socket.inet.source.addr
1049.RB [ = ]
8cf7c7c2 1050.BR any | \c
1c2054c7 1051.I addr
1052.OD
1053Specify the IP address on which to listen for incoming connections. The
1054default is
1055.BR any ,
1056which means to listen on all addresses, though it may be useful to
1057specify this explicitly, if the global setting is different.
1058.OE
1059.OS "Socket options"
1060.BR socket.inet.source. [ allow | deny ]
1061.RB [ host ]
1062.I addr
10a454ad 1063.RB [ /
1c2054c7 1064.IR addr ]
333c51f4 1065.OD
667fb920 1066Adds an entry to the source's access control list. If only one
1067.I address
1068is given, the entry applies only to that address; if two are given, the
1069first is a network address and the second is a netmask either in
1070dotted-quad format or a simple number of bits (e.g.,
1071.B /255.255.255.192
1072and
1073.B /26
1074mean the same), and the entry applies to any address which, when masked
1075by the netmask, is equal to the masked network address.
333c51f4 1076.OE
1c2054c7 1077.OS "Socket options"
1078.BR socket.inet.source. [ allow | deny ]
1079.B priv-port
1080.OD
1081Accept or reject connections from low-numbered `privileged' ports, in
1082the range 0--1023.
1083.OE
1084.OS "Socket options"
1085.B socket.inet.dest.addr
1086.RB [ = ]
8cf7c7c2 1087.BR any | \c
1c2054c7 1088.I addr
1089.OD
1090Specify the IP address to bind the local socket to when making an
1091outbound connection. The default is
1092.BR any ,
1093which means to use whichever address the kernel thinks is most
1094convenient. This option is useful if the destination is doing
1095host-based access control and your server is multi-homed.
1096.OE
ee599f55 1097.OS "Socket options"
1098.B socket.inet.dest.priv-port
1099.RB [=]
1100.BR yes | no
1101.OD
1102Make a privileged connection (i.e., from a low-numbered port) to the
1103target. This only works if
1104.B fw
1105was started with root privileges. However, it still works if
1106.B fw
1107has
1108.I dropped
1109privileges after initialization (the
1110.B \-s
1111option). Before dropping privileges,
1112.B fw
1113forks off a separate process which continues to run with root
1114privileges, and on demand passes sockets bound to privileged ports and
1115connected to the appropriate peer back to the main program. The
1116privileged child only passes back sockets connected to peer addresses
1117named in the configuration; even if the
1118.B fw
1119process is compromised, it can't make privileged connections to other
1120addresses. Note that because of this privilege separation, it's also
1121not possible to reconfigure
1122.B fw
69c8e834 1123to make privileged connections to different peer addresses later by
ee599f55 1124changing configuration files and sending the daemon a
1125.BR SIGHUP .
1126.OE
10a454ad 1127.PP
333c51f4 1128The access control rules are examined in the order: local entries first,
1129then global ones, each in the order given in the configuration file.
1130The first matching entry is used. If no entries match, the behaviour is
1131the
667fb920 1132.I opposite
1133of the last entry tried. If there are no entries defined, the default
1134is to allow all clients.
667fb920 1135.
1136.SS "The `unix' socket address type"
8cf7c7c2
MW
1137.GL "Socket source and target"
1138.OL "Socket options"
10a454ad 1139The
667fb920 1140.B unix
1141address type allows access to Unix-domain sockets. The syntax for
1142.B unix
1143source and target addresses is like this:
333c51f4 1144.GS "Socket source and target"
1145.I unix-source-addr
667fb920 1146::=
333c51f4 1147.I file-name
667fb920 1148.br
333c51f4 1149.I unix-target-addr
667fb920 1150::=
1151.I file-name
333c51f4 1152.GE
1153The following options are supported by the
1154.B unix
1155source address type:
1156.OS "Socket options"
1157.BR socket.unix.fattr. *
1158.OD
667fb920 1159The
1160.B unix
1161source address accepts
1162.B fattr
333c51f4 1163options to control the attributes of the socket file created.
1164.OE
1165.PP
1166Sockets are removed if
10a454ad 1167.B fw
667fb920 1168exits normally (which it will do if it runs out of sources or
372a98e2 1169connections, or if
1170.B fw
1171shuts down in a clean way).
667fb920 1172.SH "EXAMPLES"
1173To forward the local port 25 to a main mail server:
1174.VS
1175from 25 to mailserv:25
1176.VE
1177To attach a fortune server to a Unix-domain socket:
1178.VS
1179from unix:/tmp/fortunes
1180to exec [/usr/games/fortune] { user nobody }
1181.VE
1182To fetch a fortune from the server:
1183.VS
1184from file stdin, stdout to unix:/tmp/fortunes
1185.VE
1186To emulate
1187.BR cat (1):
1188.VS
49f5947b 1189from file stdin, null to file null, stdout
667fb920 1190.VE
69c8e834 1191.sp -1 \" undo final space
667fb920 1192.
1193.\"--------------------------------------------------------------------------
372a98e2 1194.SH "SIGNAL HANDLING"
1195.
1196The
1197.B fw
1198program responds to various signals when it's running. If it receives
1199.B SIGTERM
1200or
1201.BR SIGINT ,
1202.B fw
1203performs a
1204.I graceful
1205shutdown: it removes all of its sources, and will exit when no more
1206connections are running. (Note that if the disposition
1207.B SIGINT
1208was to ignore it,
1209.B fw
1210does not re-enable the signal. You'll have to send
1211.B SIGTERM
1212in that case.) If
1213.B fw
1214receives
1215.BR SIGQUIT ,
1216it performs an
1217.I abrupt
1218shutdown: it removes all sources and extant connections and closes down
1219more-or-less immediately.
1220.PP
1221Finally, if any configuration files (other than standard input) were
1222provided to
1223.B fw
1224on its command line using the
1225.B \-f
1226option, a
1227.B SIGHUP
1228signal may be sent to instruct
1229.B fw
1230to reload its configuration. Any existing connections are allowed to
1231run their course. If no such configuration files are available,
1232.B fw
1233just logs a message about the signal and continues.
372a98e2 1234.
1235.\"--------------------------------------------------------------------------
333c51f4 1236.SH "GRAMMAR SUMMARY"
1237.
8cf7c7c2 1238@@@ grammar
333c51f4 1239.\"--------------------------------------------------------------------------
1240.SH "OPTION SUMMARY"
1241.
8cf7c7c2 1242@@@ option
333c51f4 1243.\"--------------------------------------------------------------------------
10a454ad 1244.SH "BUGS"
667fb920 1245.
cdc917d3 1246The syntax for IP addresses and filenames is nasty.
10a454ad 1247.PP
d857515e 1248IPv6 is not supported yet. Because of
1249.BR fw 's
1250socket address architecture, it's probably not a major piece of work to
667fb920 1251add.
10a454ad 1252.PP
667fb920 1253Please inform me of any security problems you think you've identified in
1254this program. I take security very seriously, and I will fix security
1255holes as a matter of priority when I find out about them. I will be
1256annoyed if I have to read about problems on Bugtraq because they weren't
1257mailed to me first.
723210e6 1258.PP
1259The program is too complicated, and this manual page is too long.
667fb920 1260.
1261.\"--------------------------------------------------------------------------
10a454ad 1262.SH "AUTHOR"
667fb920 1263.
f65809f7 1264Mark Wooding, <mdw@distorted.org.uk>
667fb920 1265.
1266.\"----- That's all, folks --------------------------------------------------