7 .\" (c) 1999 Straylight/Edgeware
10 .\"----- Licensing notice ---------------------------------------------------
12 .\" This file is part of the `fw' port forwarder.
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.
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.
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.
28 .\"----- Various bits of fancy styling --------------------------------------
30 .\" --- Indented paragraphs with right-aligned tags ---
34 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
37 .\" --- Verbatim-oid typesetting ---
51 .\" --- Grammar markup ---
53 .\" This is mainly for the benefit of the automatic scripts which
54 .\" generate the grammar summary.
77 .\" --- Other bits of styling ---
93 .\"--------------------------------------------------------------------------
95 .TH fw 1 "1 July 1999" "Straylight/Edgeware" "fw port forwarder"
97 .\"--------------------------------------------------------------------------
102 .\"--------------------------------------------------------------------------
117 .\"--------------------------------------------------------------------------
122 program is a simple port forwarder. It supports a number of features
123 the author hasn't found in similar programs:
125 .I "Connection logging"
126 Each connection attempt to the forwarder is logged, giving the time of
127 the connection, the DNS-resolved hostname (if available), and the user
128 name resulting from an RFC931 lookup. These lookups are done
129 asynchronously to the main forwarder's operation.
132 Each forwarded port may have an access control list attached to it.
133 Only authorized hosts are allowed to connect. Access control checks are
134 performed by quick checks on the client's IP address.
136 .I "Nonblocking single-process design"
137 The internal structure of the server is completely nonblocking. The
138 connections don't block; the reading and writing don't block; the name
139 lookups don't block. This is all done in a single process, with the
140 single exception of the DNS resolver.
142 .I "Support for Unix-domain sockets"
143 Connections from and to Unix-domain sockets can be handled just as
144 easily as more normal Internet sockets. Access control doesn't work on
145 Unix domain sockets, though. (Yet.)
146 .SS "Command line options"
149 program understands a few simple command line options:
152 Displays a screen of help text on standard output and exits
155 .B "\-v, \-\-version"
156 Writes the version number to standard output and exits successfully.
159 Writes a terse usage summary to standard output and exits successfully.
161 .B "\-G, \-\-grammar"
162 Writes a summary of the configuration file grammar to standard output
163 and exits successfully.
165 .B "\-O, \-\-options"
166 Writes a summary of the source and target options to standard output and
169 .BI "\-f, \-\-file=" file
170 Read configuration information from
175 configuration file statement.
177 .B "\-d, \-\-daemon, \-\-fork"
178 Forks into the background after reading the configuration and
179 initializing properly.
181 .B "\-l, \-\-syslog, \-\-log"
182 Emit logging information to the system log, rather than standard error.
184 .BI "\-p, \-\-pidfile=" file
191 is given too, then the process-id is written after forking (obviously).
194 Don't output any logging information. This option is not recommended
195 for normal use, although it can make system call traces clearer so I use
198 .BI "\-s, \-\-setuid=" user
199 Change uid to that of
201 which may be either a user name or uid number, after initializing all
202 the sources. This will usually require elevated privileges.
204 .BI "\-g, \-\-setgid=" group
205 Change gid to that of
207 which may be either a group name or gid number, after initializing all
208 the sources. If the operating system understands supplementary groups
209 then the supplementary groups list is altered to include only
212 Any further command line arguments are interpreted as configuration
213 lines to be read. Configuration supplied in command line arguments has
214 precisely the same syntax as configuration in files. If there are no
215 configuration statements on the command line, and no
217 options were supplied, configuration is read from standard input, if
218 stdin is not a terminal.
220 .\"--------------------------------------------------------------------------
221 .SH "CONFIGURATION LANGUAGE"
225 program has a fairly sophisticated configuration language to let you
226 describe which things should be forwarded where and what special
227 features there should be.
228 .SS "Lexical structure"
229 There are four types of characters.
231 .I "word constituent characters"
232 Word constituent characters are gathered together into words.
233 Depending on its surrounding context, a word might act as a keyword or a
234 string. All alphanumerics are word constituents, as is the hyphen
236 Other characters may change their status in future versions.
238 .I "self-delimiting characters"
239 Self-delimiting characters always stand alone. They act as punctuation,
240 shaping the sequence of words into more complex grammatical forms. The
253 are self-delimiting. Note that while some characters, e.g.,
257 require escaping by the shell, they are mostly optional in the grammar
258 and can tend to be omitted in quick hacks at the shell prompt.
260 .I "whitespace characters"
261 Whitespace characters separate words but are otherwise ignored. All
262 `normal' whitespace characters (e.g., space, tab and newline) are
263 considered to be whitespace for these purposes.
265 .I "special characters"
266 There are three special characters. The
268 character, if it appears at the start of a word, introduces a
270 which extends to the end of the current line or command-line argument.
271 Within a word, it behaves like a normal word-constituent character. The
274 escapes the following character causing it to be interpreted as a word
275 constituent regardless of its normal type. The double-quote
277 escapes all characters other than backslashes up to the next
278 double-quote and causes them to be regarded as word constituents. Note
279 that you don't have to quote a whole word. The backslash can escape a
280 quote character allowing you to insert it into a word if really
284 The overall syntax looks a bit like this:
323 If you prefer, the keyword
331 .SS "Sources and targets"
332 Forwarding is set up by attaching
336 Sources are things which are capable of
338 one end of a data flow on their own, while targets are things which are
339 capable of setting up the other end on demand. In the case of a TCP
340 port forwarder, the part which listens for incoming client connections
341 is the source, while the part which sets up outgoing connections to the
342 destination server is the target.
346 does is set up a collection of sources and targets based on your
347 configuration file so that when a source decides to initiate a data
348 flow, it tells its target to set its end up, and then squirts data back
349 and forth between the two until there's no more.
353 they stay around indefinitely setting up multiple attachments to
356 they set up one connection and then disappear. If all the sources
357 defined are transient, then
359 will quit when no more active sources remain and all connections have
364 program is fairly versatile. It allows you to attach any supported type
365 of source to any supported type of target. This will, I hope, be the
366 case in all future versions.
372 depend on the source or target type, and are therefore described in the
373 sections specific to the various types.
375 .SS "Options structure"
376 Most of the objects that
378 knows about (including sources and targets, but also other more specific
379 things such as socket address types) can have their behaviour modified
382 The options available at a particular point in the configuration depend
385 A global option, outside of a
387 has no context unless it is explicitly qualified, and affects global
388 behaviour. A local option, applied to a source or target in a
390 has the context of the type of source or target to which it is applied,
391 and affects only that source or target.
393 Note that it's important to distinguish between an option's context
394 (which is affected by its qualification) and its local or global
395 status. No matter how qualified, a global option will always control
396 default options for objects, and a local option will only affect a
397 specific source or target.
399 The syntax for qualifying options is like this:
424 Thus, you may qualify either an individual option or a sequence of
425 options. The two are equivalent; for example,
434 exec.rlimit.core = 0;
437 For each option, there is a sequence of prefixes which maximally qualify
438 that option. An option prefixed with this sequence is
439 .IR "fully qualified" .
440 In actual use, some or all of those prefixes may be omitted. However,
441 it's possible for the option to become
443 if you do this. For example, the option
448 .BR socket.unix.fattr.owner .
449 In this case, the ambiguity is benign: a local option will have as its
450 context an appropriate source or target, and both global options
451 actually control the same default. However, the option
457 which have separate defaults, and which one you actually get depends on
458 the exact implementation of
460 option parser. (Currently this would resolve to
462 although this may change in a later version.)
464 In this manual, options are usually shown in their fully-qualified form.
466 .SS "File attributes for created files: `fattr'"
471 sources and targets can create new filesystem objects. The
473 options allow control over the attributes of the newly-created objects.
478 use the same set of defaults, so a prefix of
480 is good enough for setting global options, and the implicit context
481 disambiguates local options.
483 The following file attribute options are supported:
484 .OS "File attributes (`fattr')"
485 .IB prefix .fattr.mode
489 Sets the permissions mode for a new file. The
491 argument may be either an octal number or a
493 string which acts on the default permissions established by the
496 setting. The characters
500 do not have to be quoted within the mode string.
502 .OS "File attributes (`fattr')"
503 .IB prefix .fattr.owner
507 Sets the owner for newly created files. On non-broken systems you will
508 need to be the superuser to set the owner on a file. The
510 may either be a numeric uid or a username. The default is not to change
511 the owner of the file once it's created. The synonyms
515 are accepted in place of
518 .OS "File attributes (`fattr')"
519 .IB prefix .fattr.group
523 Sets the group for newly created files. You will usually need to be a
524 member of the group in question order to set the group of a file. The
526 may either be a numeric gid or a group name. The default is not to
527 change the group of the file once it's created. The synonym
529 is accepted in place of
533 .SS "The `file' source and target types"
536 source and target allow data to move to and from objects other
537 than sockets within the Unix filesystem. (Unix-domain sockets are
544 is used as a source, it is set up immediately.
548 sources and targets is like this:
549 .GS "File source and target"
582 .RB [[ : ] name [ : ]]
612 specification describes two files, the first to be used as input, the
613 second to be used as output, each described by an
616 If none of the keywords
621 are given, the type of an
623 is deduced from its nature: if it matches one of the strings
627 or begins with a digit, it's considered to be a file descriptor;
628 otherwise it's interpreted as a filename.
632 spec describes a file by its name within the filesystem. It is opened
633 when needed and closed again after use. For output files, the precise
634 behaviour is controlled by options described below.
638 spec attaches the input or output of the source or target to
643 spec uses an existing open file descriptor, given either by number or a
644 symbolic name. The name
646 refers to standard input (file descriptor 0 on normal systems) and
648 refers to standard output (file descriptor 1). The names work in
649 exactly the same way as the equivalent file descriptor numbers.
653 is omitted, the input
655 is used for both input and output. Exception: if the input refers to
656 standard input then the output will refer to standard output instead.
660 options apply equally to sources and targets. The options are as
667 Whether to create the output file if it doesn't exist. If
669 (the default), an error is reported if the file doesn't exist. If
671 the file is created if it doesn't exist.
676 .BR no | truncate | append
678 Controls the behaviour if the output file already exists. If
680 an error is reported. If
682 (the default), the existing file is replaced by the new data. If
684 the new data is appended to the file.
691 source and target also accept
693 options for controlling the attributes of the created file.
696 Under no circumstances will
698 create a file through a `dangling' symbolic link.
700 .SS "The `exec' source and target types"
703 source and target execute programs and allow access to their standard
704 input and output streams. Both source and target have the same syntax,
706 .GS "Exec source and target"
746 If a single word is given, it is a
748 and will be passed to the Bourne shell for execution. If a
749 bracket-enclosed sequence of words is given, it is considered to be a
750 list of arguments to pass to the program: if a
752 is also supplied, it names the file containing the program to execute;
753 otherwise the file named by the first argument
757 Note that the shell command or program name string must, if present,
758 have any delimiter characters (including
762 quoted; this is not required in the
766 The standard input and output of the program are forwarded to the other
767 end of the connection. The standard error stream is caught by
773 source and target both understand the same set of options. The list of
774 options supported is as follows:
780 Whether to log the start and end of executed programs. If
782 (the default), a log message is emitted when the program is started
783 listing its process id, and another is emitted when the program finishes
784 giving its process id and exit status. If
786 these messages are not emitted. However the standard error stream is
789 abbreviation is accepted as a synonym for
797 Sets the current directory from which the the program should be run.
798 The default is not to change directory. The synonyms
803 are accepted in place of
811 Sets the root directory for the program, using the
813 system call. You must be the superuser for this option to work. The
814 default is not to set a root directory. The synonym
816 is accepted in place of
824 Sets the user (real and effective uid) to run the program as. This will
825 usually require superuser privileges to work. The default is not to
826 change uid. The synonym
828 is accepted in place of
836 Sets the group (real and effective gid) to run the program as. If
837 running with superuser privileges, the supplementary groups list is
838 cleared at the same time. The default is not to change gid (or clear
839 the supplementary groups list). The synonym
841 is accepted in place of
845 .BI exec.rlimit. limit \c
846 .RB [ .hard | .soft ]
850 Set resource limits for the program. The
852 may be one of the resource limit names described in
854 in lower-case and without the
862 is a number, followed optionally by
864 to multiply by 1024 (2\*(ss10\*(se),
866 to multiply by 1048576 (2\*(ss20\*(se), or
868 to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
869 versions of these if they want. If
873 was specified, only the hard or soft limit is set; otherwise both are
874 set to the same value. Only the superuser can raise the hard limit.
875 The soft limit cannot be set above the hard limit.
880 Clears the program's environment.
888 from the program's environment. It is not an error if no variable named
893 .BR exec.env. [ set ]
902 in the program's environment, possibly replacing the existing value.
905 may be omitted if the
907 qualifier is present.
910 Note that environment variable modifications are performed in order,
911 global modifications before local ones.
913 .SS "The `socket' source and target types"
916 source and target provide access to network services. Support is
917 currently provided for TCP/IP and Unix-domain sockets, although other
918 address types can be added with reasonable ease.
920 The syntax for socket sources and targets is:
921 .GS "Socket source and target"
933 .RB [ socket [ .\& ]]
941 .RB [ socket [ .\& ]]
948 The syntax of the source and target addresses depend on the address
949 types, which are described below. The default address type, if no
954 Socket sources support options; socket targets do not. The source
955 options provided are:
960 .BR unlimited | one-shot
962 Controls the behaviour of the source when it receives connections. A
964 limits the number of simultaneous connections. The value
968 removes any limit on the number of connections possible. The value
970 will remove the socket source after a single successful connection.
971 (Connections refused by access control systems don't count here.)
972 The default is to apply a limit of 256 concurrent connections. Use of
975 option is not recommended.
982 Sets the maximum of the kernel incoming connection queue for this socket
983 source. This is the number given to the
985 system call. The default is 5.
992 Whether to log incoming connections. If
994 (the default) incoming connections are logged, together with information
995 about the client (where available) and whether the connection was
996 accepted or refused. If
998 log messages are not generated.
1001 Address types also provide their own options.
1003 .SS "The `inet' socket address type"
1004 .GL "Socket source and target"
1005 .OL "Socket options"
1008 address type provides access to TCP ports. The
1010 source and target addresses have the following syntax:
1011 .GS "Socket source and target"
1038 may be given as a port number or a service name from the
1040 file (or YP map if you do that sort of thing). A
1042 may be a textual hostname or a numerical IP address.
1046 source address accepts the following options:
1047 .OS "Socket options"
1048 .B socket.inet.source.addr
1053 Specify the IP address on which to listen for incoming connections. The
1056 which means to listen on all addresses, though it may be useful to
1057 specify this explicitly, if the global setting is different.
1059 .OS "Socket options"
1060 .BR socket.inet.source. [ allow | deny ]
1066 Adds an entry to the source's access control list. If only one
1068 is given, the entry applies only to that address; if two are given, the
1069 first is a network address and the second is a netmask either in
1070 dotted-quad format or a simple number of bits (e.g.,
1074 mean the same), and the entry applies to any address which, when masked
1075 by the netmask, is equal to the masked network address.
1077 .OS "Socket options"
1078 .BR socket.inet.source. [ allow | deny ]
1081 Accept or reject connections from low-numbered `privileged' ports, in
1084 .OS "Socket options"
1085 .B socket.inet.dest.addr
1090 Specify the IP address to bind the local socket to when making an
1091 outbound connection. The default is
1093 which means to use whichever address the kernel thinks is most
1094 convenient. This option is useful if the destination is doing
1095 host-based access control and your server is multi-homed.
1097 .OS "Socket options"
1098 .B socket.inet.dest.priv-port
1102 Make a privileged connection (i.e., from a low-numbered port) to the
1103 target. This only works if
1105 was started with root privileges. However, it still works if
1109 privileges after initialization (the
1111 option). Before dropping privileges,
1113 forks off a separate process which continues to run with root
1114 privileges, and on demand passes sockets bound to privileged ports and
1115 connected to the appropriate peer back to the main program. The
1116 privileged child only passes back sockets connected to peer addresses
1117 named in the configuration; even if the
1119 process is compromised, it can't make privileged connections to other
1120 addresses. Note that because of this privilege separation, it's also
1121 not possible to reconfigure
1123 to make privileged connections to different peer addresses later by
1124 changing configuration files and sending the daemon a
1128 The access control rules are examined in the order: local entries first,
1129 then global ones, each in the order given in the configuration file.
1130 The first matching entry is used. If no entries match, the behaviour is
1133 of the last entry tried. If there are no entries defined, the default
1134 is to allow all clients.
1136 .SS "The `unix' socket address type"
1137 .GL "Socket source and target"
1138 .OL "Socket options"
1141 address type allows access to Unix-domain sockets. The syntax for
1143 source and target addresses is like this:
1144 .GS "Socket source and target"
1153 The following options are supported by the
1155 source address type:
1156 .OS "Socket options"
1157 .BR socket.unix.fattr. *
1161 source address accepts
1163 options to control the attributes of the socket file created.
1166 Sockets are removed if
1168 exits normally (which it will do if it runs out of sources or
1171 shuts down in a clean way).
1173 To forward the local port 25 to a main mail server:
1175 from 25 to mailserv:25
1177 To attach a fortune server to a Unix-domain socket:
1179 from unix:/tmp/fortunes
1180 to exec [/usr/games/fortune] { user nobody }
1182 To fetch a fortune from the server:
1184 from file stdin, stdout to unix:/tmp/fortunes
1189 from file stdin, null to file null, stdout
1191 .sp -1 \" undo final space
1193 .\"--------------------------------------------------------------------------
1194 .SH "SIGNAL HANDLING"
1198 program responds to various signals when it's running. If it receives
1205 shutdown: it removes all of its sources, and will exit when no more
1206 connections are running. (Note that if the disposition
1210 does not re-enable the signal. You'll have to send
1218 shutdown: it removes all sources and extant connections and closes down
1219 more-or-less immediately.
1221 Finally, if any configuration files (other than standard input) were
1224 on its command line using the
1228 signal may be sent to instruct
1230 to reload its configuration. Any existing connections are allowed to
1231 run their course. If no such configuration files are available,
1233 just logs a message about the signal and continues.
1235 .\"--------------------------------------------------------------------------
1236 .SH "GRAMMAR SUMMARY"
1239 .\"--------------------------------------------------------------------------
1240 .SH "OPTION SUMMARY"
1243 .\"--------------------------------------------------------------------------
1246 The syntax for IP addresses and filenames is nasty.
1248 IPv6 is not supported yet. Because of
1250 socket address architecture, it's probably not a major piece of work to
1253 Please inform me of any security problems you think you've identified in
1254 this program. I take security very seriously, and I will fix security
1255 holes as a matter of priority when I find out about them. I will be
1256 annoyed if I have to read about problems on Bugtraq because they weren't
1259 The program is too complicated, and this manual page is too long.
1261 .\"--------------------------------------------------------------------------
1264 Mark Wooding, <mdw@distorted.org.uk>
1266 .\"----- That's all, folks --------------------------------------------------