5 .\" (c) 1999 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the `fw' port forwarder.
12 .\" `fw' 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.
17 .\" `fw' 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.
22 .\" You should have received a copy of the GNU General Public License
23 .\" along with `fw'; if not, write to the Free Software Foundation,
24 .\" Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 .\"----- Various bits of fancy styling --------------------------------------
28 .\" --- Indented paragraphs with right-aligned tags ---
32 \h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
35 .\" --- Verbatim-oid typesetting ---
49 .\" --- Grammar markup ---
51 .\" This is mainly for the benefit of the automatic scripts which
52 .\" generate the grammar summary.
75 .\" --- Other bits of styling ---
91 .\"--------------------------------------------------------------------------
93 .TH fw 1 "1 July 1999" "Straylight/Edgeware" "fw port forwarder"
95 .\"--------------------------------------------------------------------------
100 .\"--------------------------------------------------------------------------
115 .\"--------------------------------------------------------------------------
120 program is a simple port forwarder. It supports a number of features
121 the author hasn't found in similar programs:
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.
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.
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.
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"
147 program understands a few simple command line options:
150 Displays a screen of help text on standard output and exits
153 .B "\-v, \-\-version"
154 Writes the version number to standard output and exits successfully.
157 Writes a terse usage summary to standard output and exits successfully.
159 .B "\-G, \-\-grammar"
160 Writes a summary of the configuration file grammar to standard output
161 and exits successfully.
163 .B "\-O, \-\-options"
164 Writes a summary of the source and target options to standard output and
167 .BI "\-f, \-\-file=" file
168 Read configuration information from
173 configuration file statement.
175 .B "\-d, \-\-daemon, \-\-fork"
176 Forks into the background after reading the configuration and
177 initializing properly.
179 .B "\-l, \-\-syslog, \-\-log"
180 Emit logging information to the system log, rather than standard error.
182 .BI "\-p, \-\-pidfile=" file
189 is given too, then the process-id is written after forking (obviously).
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
196 .BI "\-s, \-\-setuid=" user
197 Change uid to that of
199 which may be either a user name or uid number, after initializing all
200 the sources. This will usually require elevated privileges.
202 .BI "\-g, \-\-setgid=" group
203 Change gid to that of
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
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
215 options were supplied, configuration is read from standard input, if
216 stdin is not a terminal.
218 .\"--------------------------------------------------------------------------
219 .SH "CONFIGURATION LANGUAGE"
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.
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
234 Other characters may change their status in future versions.
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
251 are self-delimiting. Note that while some characters, e.g.,
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.
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.
263 .I "special characters"
264 There are three special characters. The
266 character, if it appears at the start of a word, introduces a
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
272 escapes the following character causing it to be interpreted as a word
273 constituent regardless of its normal type. The double-quote
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
282 The overall syntax looks a bit like this:
321 If you prefer, the keyword
329 .SS "Sources and targets"
330 Forwarding is set up by attaching
334 Sources are things which are capable of
336 one end of a data flow on their own, while targets are things which are
337 capable of setting up the other end on demand. In the case of a TCP
338 port forwarder, the part which listens for incoming client connections
339 is the source, while the part which sets up outgoing connections to the
340 destination server is the target.
344 does is set up a collection of sources and targets based on your
345 configuration file so that when a source decides to initiate a data
346 flow, it tells its target to set its end up, and then squirts data back
347 and forth between the two until there's no more.
351 they stay around indefinitely setting up multiple attachments to
354 they set up one connection and then disappear. If all the sources
355 defined are transient, then
357 will quit when no more active sources remain and all connections have
362 program is fairly versatile. It allows you to attach any supported type
363 of source to any supported type of target. This will, I hope, be the
364 case in all future versions.
370 depend on the source or target type, and are therefore described in the
371 sections specific to the various types.
373 .SS "Options structure"
374 Most of the objects that
376 knows about (including sources and targets, but also other more specific
377 things such as socket address types) can have their behaviour modified
380 The options available at a particular point in the configuration depend
383 A global option, outside of a
385 has no context unless it is explicitly qualified, and affects global
386 behaviour. A local option, applied to a source or target in a
388 has the context of the type of source or target to which it is applied,
389 and affects only that source or target.
391 Note that it's important to distinguish between an option's context
392 (which is affected by its qualification) and its local or global
393 status. No matter how qualified, a global option will always control
394 default options for objects, and a local option will only affect a
395 specific source or target.
397 The syntax for qualifying options is like this:
422 Thus, you may qualify either an individual option or a sequence of
423 options. The two are equivalent; for example,
432 exec.rlimit.core = 0;
435 For each option, there is a sequence of prefixes which maximally qualify
436 that option. An option prefixed with this sequence is
437 .IR "fully qualified" .
438 In actual use, some or all of those prefixes may be omitted. However,
439 it's possible for the option to become
441 if you do this. For example, the option
446 .BR socket.unix.fattr.owner .
447 In this case, the ambiguity is benign: a local option will have as its
448 context an appropriate source or target, and both global options
449 actually control the same default. However, the option
455 which have separate defaults, and which one you actually get depends on
456 the exact implementation of
458 option parser. (Currently this would resolve to
460 although this may change in a later version.)
462 In this manual, options are usually shown in their fully-qualified form.
464 .SS "File attributes for created files: `fattr'"
469 sources and targets can create new filesystem objects. The
471 options allow control over the attributes of the newly-created objects.
476 use the same set of defaults, so a prefix of
478 is good enough for setting global options, and the implicit context
479 disambiguates local options.
481 The following file attribute options are supported:
482 .OS "File attributes (`fattr')"
483 .IB prefix .fattr.mode
487 Sets the permissions mode for a new file. The
489 argument may be either an octal number or a
491 string which acts on the default permissions established by the
494 setting. The characters
498 do not have to be quoted within the mode string.
500 .OS "File attributes (`fattr')"
501 .IB prefix .fattr.owner
505 Sets the owner for newly created files. On non-broken systems you will
506 need to be the superuser to set the owner on a file. The
508 may either be a numeric uid or a username. The default is not to change
509 the owner of the file once it's created. The synonyms
513 are accepted in place of
516 .OS "File attributes (`fattr')"
517 .IB prefix .fattr.group
521 Sets the group for newly created files. You will usually need to be a
522 member of the group in question order to set the group of a file. The
524 may either be a numeric gid or a group name. The default is not to
525 change the group of the file once it's created. The synonym
527 is accepted in place of
531 .SS "The `file' source and target types"
534 source and target allow data to move to and from objects other
535 than sockets within the Unix filesystem. (Unix-domain sockets are
542 is used as a source, it is set up immediately.
546 sources and targets is like this:
547 .GS "File source and target"
580 .RB [[ : ] name [ : ]]
610 specification describes two files, the first to be used as input, the
611 second to be used as output, each described by an
614 If none of the keywords
619 are given, the type of an
621 is deduced from its nature: if it matches one of the strings
625 or begins with a digit, it's considered to be a file descriptor;
626 otherwise it's interpreted as a filename.
630 spec describes a file by its name within the filesystem. It is opened
631 when needed and closed again after use. For output files, the precise
632 behaviour is controlled by options described below.
636 spec attaches the input or output of the source or target to
641 spec uses an existing open file descriptor, given either by number or a
642 symbolic name. The name
644 refers to standard input (file descriptor 0 on normal systems) and
646 refers to standard output (file descriptor 1). The names work in
647 exactly the same way as the equivalent file descriptor numbers.
651 is omitted, the input
653 is used for both input and output. Exception: if the input refers to
654 standard input then the output will refer to standard output instead.
658 options apply equally to sources and targets. The options are as
665 Whether to create the output file if it doesn't exist. If
667 (the default), an error is reported if the file doesn't exist. If
669 the file is created if it doesn't exist.
674 .BR no | truncate | append
676 Controls the behaviour if the output file already exists. If
678 an error is reported. If
680 (the default), the existing file is replaced by the new data. If
682 the new data is appended to the file.
689 source and target also accept
691 options for controlling the attributes of the created file.
694 Under no circumstances will
696 create a file through a `dangling' symbolic link.
698 .SS "The `exec' source and target types"
701 source and target execute programs and allow access to their standard
702 input and output streams. Both source and target have the same syntax,
704 .GS "Exec source and target"
744 If a single word is given, it is a
746 and will be passed to the Bourne shell for execution. If a
747 bracket-enclosed sequence of words is given, it is considered to be a
748 list of arguments to pass to the program: if a
750 is also supplied, it names the file containing the program to execute;
751 otherwise the file named by the first argument
755 Note that the shell command or program name string must, if present,
756 have any delimiter characters (including
760 quoted; this is not required in the
764 The standard input and output of the program are forwarded to the other
765 end of the connection. The standard error stream is caught by
771 source and target both understand the same set of options. The list of
772 options supported is as follows:
778 Whether to log the start and end of executed programs. If
780 (the default), a log message is emitted when the program is started
781 listing its process id, and another is emitted when the program finishes
782 giving its process id and exit status. If
784 these messages are not emitted. However the standard error stream is
787 abbreviation is accepted as a synonym for
795 Sets the current directory from which the the program should be run.
796 The default is not to change directory. The synonyms
801 are accepted in place of
809 Sets the root directory for the program, using the
811 system call. You must be the superuser for this option to work. The
812 default is not to set a root directory. The synonym
814 is accepted in place of
822 Sets the user (real and effective uid) to run the program as. This will
823 usually require superuser privileges to work. The default is not to
824 change uid. The synonym
826 is accepted in place of
834 Sets the group (real and effective gid) to run the program as. If
835 running with superuser privileges, the supplementary groups list is
836 cleared at the same time. The default is not to change gid (or clear
837 the supplementary groups list). The synonym
839 is accepted in place of
843 .BI exec.rlimit. limit \c
844 .RB [ .hard | .soft ]
848 Set resource limits for the program. The
850 may be one of the resource limit names described in
852 in lower-case and without the
860 is a number, followed optionally by
862 to multiply by 1024 (2\*(ss10\*(se),
864 to multiply by 1048576 (2\*(ss20\*(se), or
866 to multiply by 1073741824 (2\*(ss30\*(se); purists can use upper-case
867 versions of these if they want. If
871 was specified, only the hard or soft limit is set; otherwise both are
872 set to the same value. Only the superuser can raise the hard limit.
873 The soft limit cannot be set above the hard limit.
878 Clears the program's environment.
886 from the program's environment. It is not an error if no variable named
891 .BR exec.env. [ set ]
900 in the program's environment, possibly replacing the existing value.
903 may be omitted if the
905 qualifier is present.
908 Note that environment variable modifications are performed in order,
909 global modifications before local ones.
911 .SS "The `socket' source and target types"
914 source and target provide access to network services. Support is
915 currently provided for TCP/IP and Unix-domain sockets, although other
916 address types can be added with reasonable ease.
918 The syntax for socket sources and targets is:
919 .GS "Socket source and target"
931 .RB [ socket [ .\& ]]
939 .RB [ socket [ .\& ]]
946 The syntax of the source and target addresses depend on the address
947 types, which are described below. The default address type, if no
952 Socket sources support options; socket targets do not. The source
953 options provided are:
955 .BR socket. [ accept | accept-count ]
960 Controls the number of connections that
962 accepts at a time on a particular socket. This parameter affects how
964 prioritizes between keeping up with connection turnover and processing
965 existing connections. The default is 1, which strongly favours existing
966 connections. The special value
970 removes any limit, and therefore favours connection turnover.
976 .BR unlimited | one-shot
978 Controls the behaviour of the source when it receives connections. A
980 limits the number of simultaneous connections. The value
984 removes any limit on the number of connections possible. The value
986 will remove the socket source after a single successful connection.
987 (Connections refused by access control systems don't count here.)
988 The default is to apply a limit of 256 concurrent connections. Use of
991 option is not recommended.
998 Sets the maximum of the kernel incoming connection queue for this socket
999 source. This is the number given to the
1001 system call. The default is 5.
1003 .OS "Socket options"
1008 Whether to log incoming connections. If
1010 (the default) incoming connections are logged, together with information
1011 about the client (where available) and whether the connection was
1012 accepted or refused. If
1014 log messages are not generated.
1017 Address types also provide their own options.
1019 .SS "The `inet' socket address type"
1020 .GL "Socket source and target"
1021 .OL "Socket options"
1024 address type provides access to TCP ports. The
1026 source and target addresses have the following syntax:
1027 .GS "Socket source and target"
1054 may be given as a port number or a service name from the
1056 file (or YP map if you do that sort of thing). A
1058 may be a textual hostname or a numerical IP address.
1062 source address accepts the following options:
1063 .OS "Socket options"
1064 .B socket.inet.source.addr
1069 Specify the IP address on which to listen for incoming connections. The
1072 which means to listen on all addresses, though it may be useful to
1073 specify this explicitly, if the global setting is different.
1075 .OS "Socket options"
1076 .BR socket.inet.source. [ allow | deny ]
1082 Adds an entry to the source's access control list. If only one
1084 is given, the entry applies only to that address; if two are given, the
1085 first is a network address and the second is a netmask either in
1086 dotted-quad format or a simple number of bits (e.g.,
1090 mean the same), and the entry applies to any address which, when masked
1091 by the netmask, is equal to the masked network address.
1093 .OS "Socket options"
1094 .BR socket.inet.source. [ allow | deny ]
1097 Accept or reject connections from low-numbered `privileged' ports, in
1100 .OS "Socket options"
1101 .B socket.inet.dest.addr
1106 Specify the IP address to bind the local socket to when making an
1107 outbound connection. The default is
1109 which means to use whichever address the kernel thinks is most
1110 convenient. This option is useful if the destination is doing
1111 host-based access control and your server is multi-homed.
1113 .OS "Socket options"
1114 .B socket.inet.dest.priv-port
1118 Make a privileged connection (i.e., from a low-numbered port) to the
1119 target. This only works if
1121 was started with root privileges. However, it still works if
1125 privileges after initialization (the
1127 option). Before dropping privileges,
1129 forks off a separate process which continues to run with root
1130 privileges, and on demand passes sockets bound to privileged ports and
1131 connected to the appropriate peer back to the main program. The
1132 privileged child only passes back sockets connected to peer addresses
1133 named in the configuration; even if the
1135 process is compromised, it can't make privileged connections to other
1136 addresses. Note that because of this privilege separation, it's also
1137 not possible to reconfigure
1139 to make privileged connections to different peer addresses later by
1140 changing configuration files and sending the daemon a
1144 The access control rules are examined in the order: local entries first,
1145 then global ones, each in the order given in the configuration file.
1146 The first matching entry is used. If no entries match, the behaviour is
1149 of the last entry tried. If there are no entries defined, the default
1150 is to allow all clients.
1152 .SS "The `unix' socket address type"
1153 .GL "Socket source and target"
1154 .OL "Socket options"
1157 address type allows access to Unix-domain sockets. The syntax for
1159 source and target addresses is like this:
1160 .GS "Socket source and target"
1169 The following options are supported by the
1171 source address type:
1172 .OS "Socket options"
1173 .BR socket.unix.fattr. *
1177 source address accepts
1179 options to control the attributes of the socket file created.
1182 Sockets are removed if
1184 exits normally (which it will do if it runs out of sources or
1187 shuts down in a clean way).
1189 To forward the local port 25 to a main mail server:
1191 from 25 to mailserv:25
1193 To attach a fortune server to a Unix-domain socket:
1195 from unix:/tmp/fortunes
1196 to exec [/usr/games/fortune] { user nobody }
1198 To fetch a fortune from the server:
1200 from file stdin, stdout to unix:/tmp/fortunes
1205 from file stdin, null to file null, stdout
1207 .sp -1 \" undo final space
1209 .\"--------------------------------------------------------------------------
1210 .SH "SIGNAL HANDLING"
1214 program responds to various signals when it's running. If it receives
1221 shutdown: it removes all of its sources, and will exit when no more
1222 connections are running. (Note that if the disposition
1226 does not re-enable the signal. You'll have to send
1234 shutdown: it removes all sources and extant connections and closes down
1235 more-or-less immediately.
1237 Finally, if any configuration files (other than standard input) were
1240 on its command line using the
1244 signal may be sent to instruct
1246 to reload its configuration. Any existing connections are allowed to
1247 run their course. If no such configuration files are available,
1249 just logs a message about the signal and continues.
1251 .\"--------------------------------------------------------------------------
1252 .SH "GRAMMAR SUMMARY"
1255 .\"--------------------------------------------------------------------------
1256 .SH "OPTION SUMMARY"
1259 .\"--------------------------------------------------------------------------
1262 The syntax for IP addresses and filenames is nasty.
1264 IPv6 is not supported yet. Because of
1266 socket address architecture, it's probably not a major piece of work to
1269 Please inform me of any security problems you think you've identified in
1270 this program. I take security very seriously, and I will fix security
1271 holes as a matter of priority when I find out about them. I will be
1272 annoyed if I have to read about problems on Bugtraq because they weren't
1275 The program is too complicated, and this manual page is too long.
1277 .\"--------------------------------------------------------------------------
1280 Mark Wooding, <mdw@distorted.org.uk>
1282 .\"----- That's all, folks --------------------------------------------------