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