2 .\" Copyright (c) 2001 Charles Mott <cm@linktel.net>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" $FreeBSD: src/lib/libalias/libalias.3,v 1.23.2.11 2001/12/17 10:08:22 ru Exp $
33 .Nd packet aliasing library for masquerading and network address translation
41 Function prototypes are given in the main body of the text.
45 library is a collection of functions for aliasing and de-aliasing of IP
46 packets, intended for masquerading and network address translation (NAT).
48 This library is a moderately portable set of functions designed to assist
49 in the process of IP masquerading and network address translation.
50 Outgoing packets from a local network with unregistered IP addresses can
51 be aliased to appear as if they came from an accessible IP address.
52 Incoming packets are then de-aliased so that they are sent to the correct
53 machine on the local network.
55 A certain amount of flexibility is built into the packet aliasing engine.
56 In the simplest mode of operation, a many-to-one address mapping takes
57 place between local network and the packet aliasing host.
58 This is known as IP masquerading.
59 In addition, one-to-one mappings between local and public addresses can
60 also be implemented, which is known as static NAT.
61 In between these extremes, different groups of private addresses can be
62 linked to different public addresses, comprising several distinct
64 Also, a given public address and port can be statically redirected to a
67 The packet aliasing engine was designed to operate in user space outside
68 of the kernel, without any access to private kernel data structure, but
69 the source code can also be ported to a kernel environment.
70 .Sh INITIALIZATION AND CONTROL
71 Two special functions,
74 .Fn PacketAliasSetAddress ,
75 must always be called before any packet handling may be performed.
76 In addition, the operating mode of the packet aliasing engine can be
78 .Fn PacketAliasSetMode .
81 .Fn PacketAliasInit void
82 .Bd -ragged -offset indent
83 This function has no arguments or return value and is used to initialize
84 internal data structures.
85 The following mode bits are always set after calling
87 See the description of
88 .Fn PacketAliasSetMode
89 below for the meaning of these mode bits.
91 .Bl -item -offset indent -compact
93 .Dv PKT_ALIAS_SAME_PORTS
95 .Dv PKT_ALIAS_USE_SOCKETS
97 .Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
100 This function will always return the packet aliasing engine to the same
102 .Fn PacketAliasSetAddress
103 must be called afterwards, and any desired changes from the default mode
104 bits listed above require a call to
105 .Fn PacketAliasSetMode .
107 It is mandatory that this function be called at the beginning of a program
108 prior to any packet handling.
112 .Fn PacketAliasUninit void
113 .Bd -ragged -offset indent
114 This function has no arguments or return value and is used to clear any
115 resources attached to internal data structures.
117 This functions should be called when a program stops using the aliasing
118 engine; it does, amongst other things, clear out any firewall holes.
119 To provide backwards compatibility and extra security, it is added to
123 .Fn PacketAliasInit .
124 Calling it multiple times is harmless.
128 .Fn PacketAliasSetAddress "struct in_addr addr"
129 .Bd -ragged -offset indent
130 This function sets the source address to which outgoing packets from the
131 local area network are aliased.
132 All outgoing packets are re-mapped to this address unless overridden by a
133 static address mapping established by
134 .Fn PacketAliasRedirectAddr .
137 .Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
138 mode bit is set (the default mode of operation), then the internal aliasing
139 link tables will be reset any time the aliasing address changes.
140 This is useful for interfaces such as
143 address may or may not change on successive dial-up attempts.
146 .Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
147 mode bit is set to zero, this function can also be used to dynamically change
148 the aliasing address on a packet to packet basis (it is a low overhead call).
150 It is mandatory that this function be called prior to any packet handling.
154 .Fn PacketAliasSetMode "unsigned int flags" "unsigned int mask"
155 .Bd -ragged -offset indent
156 This function sets or clears mode bits
157 according to the value of
162 The following mode bits are defined in
164 .Bl -tag -width indent
167 .Pa /var/log/alias.log .
168 Each time an aliasing link is created or deleted, the log file is appended
169 with the current number of ICMP, TCP and UDP links.
170 Mainly useful for debugging when the log file is viewed continuously with
172 .It Dv PKT_ALIAS_DENY_INCOMING
173 If this mode bit is set, all incoming packets associated with new TCP
174 connections or new UDP transactions will be marked for being ignored
177 .Dv PKT_ALIAS_IGNORED
179 by the calling program.
180 Response packets to connections or transactions initiated from the packet
181 aliasing host or local network will be unaffected.
182 This mode bit is useful for implementing a one-way firewall.
183 .It Dv PKT_ALIAS_SAME_PORTS
184 If this mode bit is set, the packet aliasing engine will attempt to leave
185 the alias port numbers unchanged from the actual local port numbers.
186 This can be done as long as the quintuple (proto, alias addr, alias port,
187 remote addr, remote port) is unique.
188 If a conflict exists, a new aliasing port number is chosen even if this
190 .It Dv PKT_ALIAS_USE_SOCKETS
191 This bit should be set when the packet aliasing host originates network
192 traffic as well as forwards it.
193 When the packet aliasing host is waiting for a connection from an unknown
194 host address or unknown port number (e.g. an FTP data connection), this
195 mode bit specifies that a socket be allocated as a place holder to prevent
197 Once a connection is established, usually within a minute or so, the socket
199 .It Dv PKT_ALIAS_UNREGISTERED_ONLY
200 If this mode bit is set, traffic on the local network which does not
201 originate from unregistered address spaces will be ignored.
202 Standard Class A, B and C unregistered addresses are:
203 .Bd -literal -offset indent
204 10.0.0.0 -> 10.255.255.255 (Class A subnet)
205 172.16.0.0 -> 172.31.255.255 (Class B subnets)
206 192.168.0.0 -> 192.168.255.255 (Class C subnets)
209 This option is useful in the case that packet aliasing host has both
210 registered and unregistered subnets on different interfaces.
211 The registered subnet is fully accessible to the outside world, so traffic
212 from it does not need to be passed through the packet aliasing engine.
213 .It Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
214 When this mode bit is set and
215 .Fn PacketAliasSetAddress
216 is called to change the aliasing address, the internal link table of the
217 packet aliasing engine will be cleared.
218 This operating mode is useful for
220 links where the interface address can sometimes change or remain the same
221 between dial-up attempts.
222 If this mode bit is not set, the link table will never be reset in the event
223 of an address change.
224 .It Dv PKT_ALIAS_PUNCH_FW
229 based firewall for FTP/IRC DCC connections.
230 The holes punched are bound by from/to IP address and port; it will not be
231 possible to use a hole for another connection.
232 A hole is removed when the connection that uses it dies.
233 To cater to unexpected death of a program using
236 changing the state of the flag will clear the entire firewall range
238 This will also happen on the initial call to
239 .Fn PacketAliasSetFWBase .
240 This call must happen prior to setting this flag.
241 .It Dv PKT_ALIAS_REVERSE
244 reverse the way it handles incoming and outgoing packets, allowing it
245 to be fed with data that passes through the internal interface rather
246 than the external one.
247 .It Dv PKT_ALIAS_PROXY_ONLY
250 to obey transparent proxy rules only.
251 Normal packet aliasing is not performed.
253 .Fn PacketAliasProxyRule
259 .Fn PacketAliasSetFWBase "unsigned int base" "unsigned int num"
260 .Bd -ragged -offset indent
261 Set firewall range allocated for punching firewall holes (with the
262 .Dv PKT_ALIAS_PUNCH_FW
264 The range will be cleared for all rules on initialization.
267 The packet handling functions are used to modify incoming (remote to local)
268 and outgoing (local to remote) packets.
269 The calling program is responsible for receiving and sending packets via
275 .Fn PacketAliasSetAddress ,
276 the two packet handling functions,
280 comprise minimal set of functions needed for a basic IP masquerading
284 .Fn PacketAliasIn "char *buffer" "int maxpacketsize"
285 .Bd -ragged -offset indent
286 An incoming packet coming from a remote machine to the local network is
287 de-aliased by this function.
288 The IP packet is pointed to by
292 indicates the size of the data structure containing the packet and should
293 be at least as large as the actual packet size.
296 .Bl -tag -width indent
298 The packet aliasing process was successful.
299 .It Dv PKT_ALIAS_IGNORED
300 The packet was ignored and not de-aliased.
301 This can happen if the protocol is unrecognized, possibly an ICMP message
302 type is not handled or if incoming packets for new connections are being
304 .Dv PKT_ALIAS_DENY_INCOMING
306 .Fn PacketAliasSetMode ) .
307 .It Dv PKT_ALIAS_UNRESOLVED_FRAGMENT
308 This is returned when a fragment cannot be resolved because the header
309 fragment has not been sent yet.
310 In this situation, fragments must be saved with
311 .Fn PacketAliasSaveFragment
312 until a header fragment is found.
313 .It Dv PKT_ALIAS_FOUND_HEADER_FRAGMENT
314 The packet aliasing process was successful, and a header fragment was found.
315 This is a signal to retrieve any unresolved fragments with
316 .Fn PacketAliasGetFragment
317 and de-alias them with
318 .Fn PacketAliasFragmentIn .
319 .It Dv PKT_ALIAS_ERROR
320 An internal error within the packet aliasing engine occurred.
325 .Fn PacketAliasOut "char *buffer" "int maxpacketsize"
326 .Bd -ragged -offset indent
327 An outgoing packet coming from the local network to a remote machine is
328 aliased by this function.
329 The IP packet is pointed to by
333 indicates the maximum packet size permissible should the packet length be
335 IP encoding protocols place address and port information in the encapsulated
336 data stream which has to be modified and can account for changes in packet
338 Well known examples of such protocols are FTP and IRC DCC.
341 .Bl -tag -width indent
343 The packet aliasing process was successful.
344 .It Dv PKT_ALIAS_IGNORED
345 The packet was ignored and not aliased.
346 This can happen if the protocol is unrecognized, or possibly an ICMP message
348 .It Dv PKT_ALIAS_ERROR
349 An internal error within the packet aliasing engine occurred.
352 .Sh PORT AND ADDRESS REDIRECTION
353 The functions described in this section allow machines on the local network
354 to be accessible in some degree to new incoming connections from the external
356 Individual ports can be re-mapped or static network address translations can
359 .Ft struct alias_link *
360 .Fo PacketAliasRedirectPort
361 .Fa "struct in_addr local_addr"
362 .Fa "u_short local_port"
363 .Fa "struct in_addr remote_addr"
364 .Fa "u_short remote_port"
365 .Fa "struct in_addr alias_addr"
366 .Fa "u_short alias_port"
369 .Bd -ragged -offset indent
370 This function specifies that traffic from a given remote address/port to
371 an alias address/port be redirected to a specified local address/port.
385 is zero, this indicates that the packet aliasing address as established
387 .Fn PacketAliasSetAddress
390 .Fn PacketAliasSetAddress
391 is called to change the address after
392 .Fn PacketAliasRedirectPort
393 is called, a zero reference will track this change.
395 If the link is further set up to operate for a load sharing, then
399 are ignored, and are selected dynamically from the server pool, as described in
400 .Fn PacketAliasAddServer
405 is zero, this indicates to redirect packets from any remote address.
408 is zero, this indicates to redirect packets originating from any remote
410 Almost always, the remote port specification will be zero, but non-zero
411 remote addresses can sometimes be useful for firewalling.
413 .Fn PacketAliasRedirectPort
414 overlap in their address/port specifications, then the most recent call
415 will have precedence.
417 This function returns a pointer which can subsequently be used by
418 .Fn PacketAliasRedirectDelete .
421 is returned, then the function call did not complete successfully.
423 All port numbers should be in network address byte order, so it is necessary
426 to convert these parameters from internally readable numbers to network byte
428 Addresses are also in network byte order, which is implicit in the use of the
433 .Ft struct alias_link *
434 .Fo PacketAliasRedirectAddr
435 .Fa "struct in_addr local_addr"
436 .Fa "struct in_addr alias_addr"
438 .Bd -ragged -offset indent
439 This function designates that all incoming traffic to
443 Similarly, all outgoing traffic from
452 is zero, this indicates that the packet aliasing address as established by
453 .Fn PacketAliasSetAddress
456 .Fn PacketAliasSetAddress
457 is called to change the address after
458 .Fn PacketAliasRedirectAddr
459 is called, a zero reference will track this change.
461 If the link is further set up to operate for a load sharing, then
463 is ignored, and is selected dynamically from the server pool, as described in
464 .Fn PacketAliasAddServer
467 If subsequent calls to
468 .Fn PacketAliasRedirectAddr
469 use the same aliasing address, all new incoming traffic to this aliasing
470 address will be redirected to the local address made in the last function
472 New traffic generated by any of the local machines, designated in the
473 several function calls, will be aliased to the same address.
474 Consider the following example:
475 .Bd -literal -offset indent
476 PacketAliasRedirectAddr(inet_aton("192.168.0.2"),
477 inet_aton("141.221.254.101"));
478 PacketAliasRedirectAddr(inet_aton("192.168.0.3"),
479 inet_aton("141.221.254.101"));
480 PacketAliasRedirectAddr(inet_aton("192.168.0.4"),
481 inet_aton("141.221.254.101"));
484 Any outgoing connections such as
488 from 192.168.0.2, 192.168.0.3 and 192.168.0.4 will appear to come from
490 Any incoming connections to 141.221.254.101 will be directed to 192.168.0.4.
493 .Fn PacketAliasRedirectPort
494 will have precedence over address mappings designated by
495 .Fn PacketAliasRedirectAddr .
497 This function returns a pointer which can subsequently be used by
498 .Fn PacketAliasRedirectDelete .
501 is returned, then the function call did not complete successfully.
505 .Fo PacketAliasAddServer
506 .Fa "struct alias_link *link"
507 .Fa "struct in_addr addr"
510 .Bd -ragged -offset indent
511 This function sets the
513 up for Load Sharing using IP Network Address Translation (RFC 2391, LSNAT).
514 LSNAT operates as follows.
515 A client attempts to access a server by using the server virtual address.
516 The LSNAT router transparently redirects the request to one of the hosts
517 in server pool, selected using a real-time load sharing algorithm.
518 Multiple sessions may be initiated from the same client, and each session
519 could be directed to a different host based on load balance across server
520 pool hosts at the time.
521 If load share is desired for just a few specific services, the configuration
522 on LSNAT could be defined to restrict load share for just the services
525 Currently, only the simplest selection algorithm is implemented, where a
526 host is selected on a round-robin basis only, without regard to load on
532 .Fn PacketAliasRedirectPort
534 .Fn PacketAliasRedirectAddr .
536 .Fn PacketAliasAddServer
537 is called multiple times to add entries to the
541 For links created with
542 .Fn PacketAliasRedirectAddr ,
545 argument is ignored and could have any value, e.g. htons(~0).
547 This function returns 0 on success, -1 otherwise.
551 .Fn PacketAliasRedirectDelete "struct alias_link *link"
552 .Bd -ragged -offset indent
553 This function will delete a specific static redirect rule entered by
554 .Fn PacketAliasRedirectPort
556 .Fn PacketAliasRedirectAddr .
559 is the pointer returned by either of the redirection functions.
560 If an invalid pointer is passed to
561 .Fn PacketAliasRedirectDelete ,
562 then a program crash or unpredictable operation could result, so it is
563 necessary to be careful using this function.
567 .Fn PacketAliasProxyRule "const char *cmd"
568 .Bd -ragged -offset indent
571 string consists of one or more pairs of words.
572 The first word in each pair is a token and the second is the value that
573 should be applied for that token.
574 Tokens and their argument types are as follows:
575 .Bl -tag -width indent
576 .It Cm type encode_ip_hdr | encode_tcp_stream | no_encode
577 In order to support transparent proxying, it is necessary to somehow
578 pass the original address and port information into the new destination
582 is specified, the original address and port is passed as an extra IP
585 .Cm encode_tcp_stream
586 is specified, the original address and port is passed as the first
587 piece of data in the TCP stream in the format
588 .Dq DEST Ar IP port .
589 .It Cm port Ar portnum
590 Only packets with the destination port
593 .It Cm server Ar host Ns Xo
600 that the data is to be redirected to.
602 must be an IP address rather than a DNS host name.
605 is not specified, the destination port number is not changed.
609 specification is mandatory unless the
611 command is being used.
613 Normally, each call to
614 .Fn PacketAliasProxyRule
615 inserts the next rule at the start of a linear list of rules.
618 is specified, the new rule will be checked after all rules with lower
621 .Fn PacketAliasProxyRule
622 that do not specify a rule are assigned rule 0.
623 .It Cm delete Ar index
624 This token and its argument MUST NOT be used with any other tokens.
625 When used, all existing rules with the given
628 .It Cm proto tcp | udp
629 If specified, only packets of the given protocol type are matched.
630 .It Cm src Ar IP Ns Xo
633 If specified, only packets with a source address matching the given
638 is also specified, then the first
642 are taken as a network specification, and all IP addresses from that
643 network will be matched.
644 .It Cm dst Ar IP Ns Xo
647 If specified, only packets with a destination address matching the given
652 is also specified, then the first
656 are taken as a network specification, and all IP addresses from that
657 network will be matched.
660 This function is usually used to redirect outgoing connections for
661 internal machines that are not permitted certain types of internet
662 access, or to restrict access to certain external machines.
665 .Ft struct alias_link *
666 .Fo PacketAliasRedirectProto
667 .Fa "struct in_addr local_addr"
668 .Fa "struct in_addr remote_addr"
669 .Fa "struct in_addr alias_addr"
672 .Bd -ragged -offset indent
673 This function specifies that any IP packet with protocol number of
675 from a given remote address to an alias address be
676 redirected to a specified local address.
682 is zero, this indicates that the packet aliasing address as established
684 .Fn PacketAliasSetAddress
687 .Fn PacketAliasSetAddress
688 is called to change the address after
689 .Fn PacketAliasRedirectProto
690 is called, a zero reference will track this change.
694 is zero, this indicates to redirect packets from any remote address.
695 Non-zero remote addresses can sometimes be useful for firewalling.
698 .Fn PacketAliasRedirectProto
699 overlap in their address specifications, then the most recent call
700 will have precedence.
702 This function returns a pointer which can subsequently be used by
703 .Fn PacketAliasRedirectDelete .
706 is returned, then the function call did not complete successfully.
708 .Sh FRAGMENT HANDLING
709 The functions in this section are used to deal with incoming fragments.
711 Outgoing fragments are handled within
713 by changing the address according to any applicable mapping set by
714 .Fn PacketAliasRedirectAddr ,
715 or the default aliasing address set by
716 .Fn PacketAliasSetAddress .
718 Incoming fragments are handled in one of two ways.
719 If the header of a fragmented IP packet has already been seen, then all
720 subsequent fragments will be re-mapped in the same manner the header
722 Fragments which arrive before the header are saved and then retrieved
723 once the header fragment has been resolved.
726 .Fn PacketAliasSaveFragment "char *ptr"
727 .Bd -ragged -offset indent
731 .Dv PKT_ALIAS_UNRESOLVED_FRAGMENT ,
732 this function can be used to save the pointer to the unresolved fragment.
734 It is implicitly assumed that
736 points to a block of memory allocated by
738 If the fragment is never resolved, the packet aliasing engine will
739 automatically free the memory after a timeout period.
740 [Eventually this function should be modified so that a callback function
741 for freeing memory is passed as an argument.]
743 This function returns
745 if it was successful and
747 if there was an error.
751 .Fn PacketAliasGetFragment "char *buffer"
752 .Bd -ragged -offset indent
753 This function can be used to retrieve fragment pointers saved by
754 .Fn PacketAliasSaveFragment .
755 The IP header fragment pointed to by
757 is the header fragment indicated when
760 .Dv PKT_ALIAS_FOUND_HEADER_FRAGMENT .
761 Once a fragment pointer is retrieved, it becomes the calling program's
762 responsibility to free the dynamically allocated memory for the fragment.
764 .Fn PacketAliasGetFragment
765 can be called sequentially until there are no more fragments available,
766 at which time it returns
771 .Fn PacketAliasFragmentIn "char *header" "char *fragment"
772 .Bd -ragged -offset indent
773 When a fragment is retrieved with
774 .Fn PacketAliasGetFragment ,
775 it can then be de-aliased with a call to
776 .Fn PacketAliasFragmentIn .
779 argument is the pointer to a header fragment used as a template, and
781 is the pointer to the packet to be de-aliased.
783 .Sh MISCELLANEOUS FUNCTIONS
785 .Fn PacketAliasSetTarget "struct in_addr addr"
786 .Bd -ragged -offset indent
787 When an incoming packet not associated with any pre-existing aliasing link
788 arrives at the host machine, it will be sent to the address indicated by a
790 .Fn PacketAliasSetTarget .
792 If this function is called with an
794 address argument, then all new incoming packets go to the address set by
795 .Fn PacketAliasSetAddress .
797 If this function is not called, or is called with an
799 address argument, then all new incoming packets go to the address specified
801 This allows external machines to talk directly to internal machines if they
802 can route packets to the machine in question.
806 .Fn PacketAliasCheckNewLink void
807 .Bd -ragged -offset indent
808 This function returns a non-zero value when a new aliasing link is created.
809 In circumstances where incoming traffic is being sequentially sent to
810 different local servers, this function can be used to trigger when
811 .Fn PacketAliasSetTarget
812 is called to change the default target address.
816 .Fn PacketAliasInternetChecksum "u_short *buffer" "int nbytes"
817 .Bd -ragged -offset indent
818 This is a utility function that does not seem to be available elsewhere and
819 is included as a convenience.
820 It computes the internet checksum, which is used in both IP and
821 protocol-specific headers (TCP, UDP, ICMP).
825 argument points to the data block to be checksummed, and
827 is the number of bytes.
828 The 16-bit checksum field should be zeroed before computing the checksum.
830 Checksums can also be verified by operating on a block of data including
832 If the checksum is valid,
833 .Fn PacketAliasInternetChecksum
838 .Fn PacketUnaliasOut "char *buffer" "int maxpacketsize"
839 .Bd -ragged -offset indent
840 An outgoing packet, which has already been aliased,
841 has its private address/port information restored by this function.
842 The IP packet is pointed to by
846 is provided for error checking purposes.
847 This function can be used if an already-aliased packet needs to have its
848 original IP header restored for further processing (eg. logging).
851 .An Charles Mott Aq Mt cm@linktel.net ,
852 versions 1.0 - 1.8, 2.0 - 2.4.
853 .An Eivind Eklund Aq Mt eivind@FreeBSD.org ,
854 versions 1.8b, 1.9 and 2.5.
855 Added IRC DCC support as well as contributing a number of architectural
856 improvements; added the firewall bypass for FTP/IRC DCC.
857 .An Erik Salander Aq Mt erik@whistle.com
858 added support for PPTP and RTSP.
859 .An Junichi Satoh Aq Mt junichi@junichi.org
860 added support for RTSP/PNA.
862 Listed below, in approximate chronological order, are individuals who
863 have provided valuable comments and/or debugging assistance.
864 .Bd -ragged -offset indent
878 .Sh CONCEPTUAL BACKGROUND
879 This section is intended for those who are planning to modify the source
880 code or want to create somewhat esoteric applications using the packet
883 The conceptual framework under which the packet aliasing engine operates
885 Central to the discussion is the idea of an
887 which describes the relationship for a given packet transaction between
888 the local machine, aliased identity and remote machine.
889 It is discussed how such links come into existence and are destroyed.
891 There is a notion of an
893 which is a 7-tuple describing a specific translation:
894 .Bd -literal -offset indent
895 (local addr, local port, alias addr, alias port,
896 remote addr, remote port, protocol)
899 Outgoing packets have the local address and port number replaced with the
900 alias address and port number.
901 Incoming packets undergo the reverse process.
902 The packet aliasing engine attempts to match packets against an internal
903 table of aliasing links to determine how to modify a given IP packet.
904 Both the IP header and protocol dependent headers are modified as necessary.
905 Aliasing links are created and deleted as necessary according to network
908 Protocols can be TCP, UDP or even ICMP in certain circumstances.
909 (Some types of ICMP packets can be aliased according to sequence or ID
910 number which acts as an equivalent port number for identifying how
911 individual packets should be handled.)
913 Each aliasing link must have a unique combination of the following five
914 quantities: alias address/port, remote address/port and protocol.
915 This ensures that several machines on a local network can share the
916 same aliasing IP address.
917 In cases where conflicts might arise, the aliasing port is chosen so that
918 uniqueness is maintained.
919 .Ss STATIC AND DYNAMIC LINKS
920 Aliasing links can either be static or dynamic.
921 Static links persist indefinitely and represent fixed rules for translating
923 Dynamic links come into existence for a specific TCP connection or UDP
924 transaction or ICMP ECHO sequence.
925 For the case of TCP, the connection can be monitored to see when the
926 associated aliasing link should be deleted.
927 Aliasing links for UDP transactions (and ICMP ECHO and TIMESTAMP requests)
928 work on a simple timeout rule.
929 When no activity is observed on a dynamic link for a certain amount of time
930 it is automatically deleted.
931 Timeout rules also apply to TCP connections which do not open or close
933 .Ss PARTIALLY SPECIFIED ALIASING LINKS
934 Aliasing links can be partially specified, meaning that the remote address
935 and/or remote port are unknown.
936 In this case, when a packet matching the incomplete specification is found,
937 a fully specified dynamic link is created.
938 If the original partially specified link is dynamic, it will be deleted
939 after the fully specified link is created, otherwise it will persist.
941 For instance, a partially specified link might be
942 .Bd -literal -offset indent
943 (192.168.0.4, 23, 204.228.203.215, 8066, 0, 0, tcp)
946 The zeros denote unspecified components for the remote address and port.
947 If this link were static it would have the effect of redirecting all
948 incoming traffic from port 8066 of 204.228.203.215 to port 23 (telnet)
949 of machine 192.168.0.4 on the local network.
950 Each individual telnet connection would initiate the creation of a distinct
952 .Ss DYNAMIC LINK CREATION
953 In addition to aliasing links, there are also address mappings that can be
954 stored within the internal data table of the packet aliasing mechanism.
955 .Bd -literal -offset indent
956 (local addr, alias addr)
959 Address mappings are searched when creating new dynamic links.
961 All outgoing packets from the local network automatically create a dynamic
962 link if they do not match an already existing fully specified link.
963 If an address mapping exists for the outgoing packet, this determines
964 the alias address to be used.
965 If no mapping exists, then a default address, usually the address of the
966 packet aliasing host, is used.
967 If necessary, this default address can be changed as often as each individual
970 The aliasing port number is determined such that the new dynamic link does
971 not conflict with any existing links.
972 In the default operating mode, the packet aliasing engine attempts to set
973 the aliasing port equal to the local port number.
974 If this results in a conflict, then port numbers are randomly chosen until
975 a unique aliasing link can be established.
976 In an alternate operating mode, the first choice of an aliasing port is also
977 random and unrelated to the local port number.
979 PPTP aliasing does not work when more than one internal client
980 connects to the same external server at the same time, because
981 PPTP requires a single TCP control connection to be established
982 between any two IP addresses.