xref: /freebsd/sys/netinet/libalias/libalias.3 (revision 812f1d32e7cce15029a7444cb70a46e464b14496)
1.\"-
2.\" Copyright (c) 2001 Charles Mott <cm@linktel.net>
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
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.
13.\"
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
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd June 22, 2011
29.Dt LIBALIAS 3
30.Os
31.Sh NAME
32.Nm libalias
33.Nd packet aliasing library for masquerading and network address translation
34.Sh SYNOPSIS
35.In sys/types.h
36.In netinet/in.h
37.In alias.h
38.Pp
39Function prototypes are given in the main body of the text.
40.Sh DESCRIPTION
41The
42.Nm
43library is a collection of functions for aliasing and de-aliasing of IP
44packets, intended for masquerading and network address translation (NAT).
45.Sh INTRODUCTION
46This library is a moderately portable set of functions designed to assist
47in the process of IP masquerading and network address translation.
48Outgoing packets from a local network with unregistered IP addresses can
49be aliased to appear as if they came from an accessible IP address.
50Incoming packets are then de-aliased so that they are sent to the correct
51machine on the local network.
52.Pp
53A certain amount of flexibility is built into the packet aliasing engine.
54In the simplest mode of operation, a many-to-one address mapping takes
55place between local network and the packet aliasing host.
56This is known as IP masquerading.
57In addition, one-to-one mappings between local and public addresses can
58also be implemented, which is known as static NAT.
59In between these extremes, different groups of private addresses can be
60linked to different public addresses, comprising several distinct
61many-to-one mappings.
62Also, a given public address and port can be statically redirected to a
63private address/port.
64.Pp
65The packet aliasing engine was designed to operate in user space outside
66of the kernel, without any access to private kernel data structure, but
67the source code can also be ported to a kernel environment.
68.Sh INITIALIZATION AND CONTROL
69One special function,
70.Fn LibAliasInit ,
71must always be called before any packet handling may be performed and
72the returned instance pointer passed to all the other functions.
73Normally, the
74.Fn LibAliasSetAddress
75function is called afterwards, to set the default aliasing address.
76In addition, the operating mode of the packet aliasing engine can be
77customized by calling
78.Fn LibAliasSetMode .
79.Pp
80.Ft "struct libalias *"
81.Fn LibAliasInit "struct libalias *"
82.Bd -ragged -offset indent
83This function is used to initialize
84internal data structures.
85When called the first time, a
86.Dv NULL
87pointer should be passed as an argument.
88The following mode bits are always set after calling
89.Fn LibAliasInit .
90See the description of
91.Fn LibAliasSetMode
92below for the meaning of these mode bits.
93.Pp
94.Bl -item -offset indent -compact
95.It
96.Dv PKT_ALIAS_SAME_PORTS
97.It
98.Dv PKT_ALIAS_USE_SOCKETS
99.It
100.Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
101.El
102.Pp
103This function will always return the packet aliasing engine to the same
104initial state.
105The
106.Fn LibAliasSetAddress
107function is normally called afterwards, and any desired changes from the
108default mode bits listed above require a call to
109.Fn LibAliasSetMode .
110.Pp
111It is mandatory that this function be called at the beginning of a program
112prior to any packet handling.
113.Ed
114.Pp
115.Ft void
116.Fn LibAliasUninit "struct libalias *"
117.Bd -ragged -offset indent
118This function has no return value and is used to clear any
119resources attached to internal data structures.
120.Pp
121This functions should be called when a program stops using the aliasing
122engine; it does, amongst other things, clear out any firewall holes.
123To provide backwards compatibility and extra security, it is added to
124the
125.Xr atexit 3
126chain by
127.Fn LibAliasInit .
128.Ed
129.Pp
130.Ft void
131.Fn LibAliasSetAddress "struct libalias *" "struct in_addr addr"
132.Bd -ragged -offset indent
133This function sets the source address to which outgoing packets from the
134local area network are aliased.
135All outgoing packets are re-mapped to this address unless overridden by a
136static address mapping established by
137.Fn LibAliasRedirectAddr .
138If this function is not called, and no static rules match, an outgoing
139packet retains its source address.
140.Pp
141If the
142.Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
143mode bit is set (the default mode of operation), then the internal aliasing
144link tables will be reset any time the aliasing address changes.
145This is useful for interfaces such as
146.Xr ppp 8 ,
147where the IP
148address may or may not change on successive dial-up attempts.
149.Pp
150If the
151.Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
152mode bit is set to zero, this function can also be used to dynamically change
153the aliasing address on a packet to packet basis (it is a low overhead call).
154.Pp
155It is mandatory that this function be called prior to any packet handling.
156.Ed
157.Pp
158.Ft unsigned int
159.Fn LibAliasSetMode "struct libalias *" "unsigned int flags" "unsigned int mask"
160.Bd -ragged -offset indent
161This function sets or clears mode bits
162according to the value of
163.Fa flags .
164Only bits marked in
165.Fa mask
166are affected.
167The following mode bits are defined in
168.In alias.h :
169.Bl -tag -width indent
170.It Dv PKT_ALIAS_LOG
171Enables logging into
172.Pa /var/log/alias.log .
173Each time an aliasing link is created or deleted, the log file is appended
174with the current number of ICMP, TCP and UDP links.
175Mainly useful for debugging when the log file is viewed continuously with
176.Xr tail 1 .
177.It Dv PKT_ALIAS_DENY_INCOMING
178If this mode bit is set, all incoming packets associated with new TCP
179connections or new UDP transactions will be marked for being ignored
180.Fn ( LibAliasIn
181returns
182.Dv PKT_ALIAS_IGNORED
183code)
184by the calling program.
185Response packets to connections or transactions initiated from the packet
186aliasing host or local network will be unaffected.
187This mode bit is useful for implementing a one-way firewall.
188.It Dv PKT_ALIAS_SAME_PORTS
189If this mode bit is set, the packet aliasing engine will attempt to leave
190the alias port numbers unchanged from the actual local port numbers.
191This can be done as long as the quintuple (proto, alias addr, alias port,
192remote addr, remote port) is unique.
193If a conflict exists, a new aliasing port number is chosen even if this
194mode bit is set.
195.It Dv PKT_ALIAS_USE_SOCKETS
196This bit should be set when the packet aliasing host originates network
197traffic as well as forwards it.
198When the packet aliasing host is waiting for a connection from an unknown
199host address or unknown port number (e.g.\& an FTP data connection), this
200mode bit specifies that a socket be allocated as a place holder to prevent
201port conflicts.
202Once a connection is established, usually within a minute or so, the socket
203is closed.
204.It Dv PKT_ALIAS_UNREGISTERED_ONLY
205If this mode bit is set, traffic on the local network which does not
206originate from unregistered address spaces will be ignored.
207Standard Class A, B and C unregistered addresses are:
208.Bd -literal -offset indent
20910.0.0.0     ->  10.255.255.255   (Class A subnet)
210172.16.0.0   ->  172.31.255.255   (Class B subnets)
211192.168.0.0  ->  192.168.255.255  (Class C subnets)
212.Ed
213.Pp
214This option is useful in the case that packet aliasing host has both
215registered and unregistered subnets on different interfaces.
216The registered subnet is fully accessible to the outside world, so traffic
217from it does not need to be passed through the packet aliasing engine.
218.It Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE
219When this mode bit is set and
220.Fn LibAliasSetAddress
221is called to change the aliasing address, the internal link table of the
222packet aliasing engine will be cleared.
223This operating mode is useful for
224.Xr ppp 8
225links where the interface address can sometimes change or remain the same
226between dial-up attempts.
227If this mode bit is not set, the link table will never be reset in the event
228of an address change.
229.It Dv PKT_ALIAS_PUNCH_FW
230This option makes
231.Nm
232`punch holes' in an
233.Xr ipfirewall 4
234based firewall for FTP/IRC DCC connections.
235The holes punched are bound by from/to IP address and port; it will not be
236possible to use a hole for another connection.
237A hole is removed when the connection that uses it dies.
238To cater to unexpected death of a program using
239.Nm
240(e.g.\& kill -9),
241changing the state of the flag will clear the entire firewall range
242allocated for holes.
243This will also happen on the initial call to
244.Fn LibAliasSetFWBase .
245This call must happen prior to setting this flag.
246.It Dv PKT_ALIAS_REVERSE
247This option makes
248.Nm
249reverse the way it handles incoming and outgoing packets, allowing it
250to be fed with data that passes through the internal interface rather
251than the external one.
252.It Dv PKT_ALIAS_PROXY_ONLY
253This option tells
254.Nm
255to obey transparent proxy rules only.
256Normal packet aliasing is not performed.
257See
258.Fn LibAliasProxyRule
259below for details.
260.It Dv PKT_ALIAS_SKIP_GLOBAL
261This option is used by
262.Pa ipfw_nat
263only. Specifying it as a flag to
264.Fn LibAliasSetMode
265has no effect. See section
266.Sx NETWORK ADDRESS TRANSLATION
267in
268.Xr ipfw 8
269for more details.
270.El
271.Ed
272.Pp
273.Ft void
274.Fn LibAliasSetFWBase "struct libalias *" "unsigned int base" "unsigned int num"
275.Bd -ragged -offset indent
276Set firewall range allocated for punching firewall holes (with the
277.Dv PKT_ALIAS_PUNCH_FW
278flag).
279The range will be cleared for all rules on initialization.
280.Ed
281.Pp
282.Ft void
283.Fn LibAliasSkinnyPort "struct libalias *" "unsigned int port"
284.Bd -ragged -offset indent
285Set the TCP port used by the Skinny Station protocol.
286Skinny is used by Cisco IP phones to communicate with
287Cisco Call Managers to set up voice over IP calls.
288If this is not set, Skinny aliasing will not be done.
289The typical port used by Skinny is 2000.
290.Ed
291.Sh PACKET HANDLING
292The packet handling functions are used to modify incoming (remote to local)
293and outgoing (local to remote) packets.
294The calling program is responsible for receiving and sending packets via
295network interfaces.
296.Pp
297Along with
298.Fn LibAliasInit
299and
300.Fn LibAliasSetAddress ,
301the two packet handling functions,
302.Fn LibAliasIn
303and
304.Fn LibAliasOut ,
305comprise minimal set of functions needed for a basic IP masquerading
306implementation.
307.Pp
308.Ft int
309.Fn LibAliasIn "struct libalias *" "char *buffer" "int maxpacketsize"
310.Bd -ragged -offset indent
311An incoming packet coming from a remote machine to the local network is
312de-aliased by this function.
313The IP packet is pointed to by
314.Fa buffer ,
315and
316.Fa maxpacketsize
317indicates the size of the data structure containing the packet and should
318be at least as large as the actual packet size.
319.Pp
320Return codes:
321.Bl -tag -width indent
322.It Dv PKT_ALIAS_OK
323The packet aliasing process was successful.
324.It Dv PKT_ALIAS_IGNORED
325The packet was ignored and not de-aliased.
326This can happen if the protocol is unrecognized, possibly an ICMP message
327type is not handled or if incoming packets for new connections are being
328ignored (if
329.Dv PKT_ALIAS_DENY_INCOMING
330mode bit was set by
331.Fn LibAliasSetMode ) .
332.It Dv PKT_ALIAS_UNRESOLVED_FRAGMENT
333This is returned when a fragment cannot be resolved because the header
334fragment has not been sent yet.
335In this situation, fragments must be saved with
336.Fn LibAliasSaveFragment
337until a header fragment is found.
338.It Dv PKT_ALIAS_FOUND_HEADER_FRAGMENT
339The packet aliasing process was successful, and a header fragment was found.
340This is a signal to retrieve any unresolved fragments with
341.Fn LibAliasGetFragment
342and de-alias them with
343.Fn LibAliasFragmentIn .
344.It Dv PKT_ALIAS_ERROR
345An internal error within the packet aliasing engine occurred.
346.El
347.Ed
348.Pp
349.Ft int
350.Fn LibAliasOut "struct libalias *" "char *buffer" "int maxpacketsize"
351.Bd -ragged -offset indent
352An outgoing packet coming from the local network to a remote machine is
353aliased by this function.
354The IP packet is pointed to by
355.Fa buffer ,
356and
357.Fa maxpacketsize
358indicates the maximum packet size permissible should the packet length be
359changed.
360IP encoding protocols place address and port information in the encapsulated
361data stream which has to be modified and can account for changes in packet
362length.
363Well known examples of such protocols are FTP and IRC DCC.
364.Pp
365Return codes:
366.Bl -tag -width indent
367.It Dv PKT_ALIAS_OK
368The packet aliasing process was successful.
369.It Dv PKT_ALIAS_IGNORED
370The packet was ignored and not aliased.
371This can happen if the protocol is unrecognized, or possibly an ICMP message
372type is not handled.
373.It Dv PKT_ALIAS_ERROR
374An internal error within the packet aliasing engine occurred.
375.El
376.Ed
377.Sh PORT AND ADDRESS REDIRECTION
378The functions described in this section allow machines on the local network
379to be accessible in some degree to new incoming connections from the external
380network.
381Individual ports can be re-mapped or static network address translations can
382be designated.
383.Pp
384.Ft struct alias_link *
385.Fo LibAliasRedirectPort
386.Fa "struct libalias *"
387.Fa "struct in_addr local_addr"
388.Fa "u_short local_port"
389.Fa "struct in_addr remote_addr"
390.Fa "u_short remote_port"
391.Fa "struct in_addr alias_addr"
392.Fa "u_short alias_port"
393.Fa "u_char proto"
394.Fc
395.Bd -ragged -offset indent
396This function specifies that traffic from a given remote address/port to
397an alias address/port be redirected to a specified local address/port.
398The parameter
399.Fa proto
400can be either
401.Dv IPPROTO_TCP
402or
403.Dv IPPROTO_UDP ,
404as defined in
405.In netinet/in.h .
406.Pp
407If
408.Fa local_addr
409or
410.Fa alias_addr
411is zero, this indicates that the packet aliasing address as established
412by
413.Fn LibAliasSetAddress
414is to be used.
415Even if
416.Fn LibAliasSetAddress
417is called to change the address after
418.Fn LibAliasRedirectPort
419is called, a zero reference will track this change.
420.Pp
421If the link is further set up to operate for a load sharing, then
422.Fa local_addr
423and
424.Fa local_port
425are ignored, and are selected dynamically from the server pool, as described in
426.Fn LibAliasAddServer
427below.
428.Pp
429If
430.Fa remote_addr
431is zero, this indicates to redirect packets from any remote address.
432Likewise, if
433.Fa remote_port
434is zero, this indicates to redirect packets originating from any remote
435port number.
436Almost always, the remote port specification will be zero, but non-zero
437remote addresses can sometimes be useful for firewalling.
438If two calls to
439.Fn LibAliasRedirectPort
440overlap in their address/port specifications, then the most recent call
441will have precedence.
442.Pp
443This function returns a pointer which can subsequently be used by
444.Fn LibAliasRedirectDelete .
445If
446.Dv NULL
447is returned, then the function call did not complete successfully.
448.Pp
449All port numbers should be in network address byte order, so it is necessary
450to use
451.Xr htons 3
452to convert these parameters from internally readable numbers to network byte
453order.
454Addresses are also in network byte order, which is implicit in the use of the
455.Fa struct in_addr
456data type.
457.Ed
458.Pp
459.Ft struct alias_link *
460.Fo LibAliasRedirectAddr
461.Fa "struct libalias *"
462.Fa "struct in_addr local_addr"
463.Fa "struct in_addr alias_addr"
464.Fc
465.Bd -ragged -offset indent
466This function designates that all incoming traffic to
467.Fa alias_addr
468be redirected to
469.Fa local_addr .
470Similarly, all outgoing traffic from
471.Fa local_addr
472is aliased to
473.Fa alias_addr .
474.Pp
475If
476.Fa local_addr
477or
478.Fa alias_addr
479is zero, this indicates that the packet aliasing address as established by
480.Fn LibAliasSetAddress
481is to be used.
482Even if
483.Fn LibAliasSetAddress
484is called to change the address after
485.Fn LibAliasRedirectAddr
486is called, a zero reference will track this change.
487.Pp
488If the link is further set up to operate for a load sharing, then
489.Fa local_addr
490is ignored, and is selected dynamically from the server pool, as described in
491.Fn LibAliasAddServer
492below.
493.Pp
494If subsequent calls to
495.Fn LibAliasRedirectAddr
496use the same aliasing address, all new incoming traffic to this aliasing
497address will be redirected to the local address made in the last function
498call.
499New traffic generated by any of the local machines, designated in the
500several function calls, will be aliased to the same address.
501Consider the following example:
502.Bd -literal -offset indent
503LibAliasRedirectAddr(la, inet_aton("192.168.0.2"),
504                        inet_aton("141.221.254.101"));
505LibAliasRedirectAddr(la, inet_aton("192.168.0.3"),
506                        inet_aton("141.221.254.101"));
507LibAliasRedirectAddr(la, inet_aton("192.168.0.4"),
508                        inet_aton("141.221.254.101"));
509.Ed
510.Pp
511Any outgoing connections such as
512.Xr telnet 1
513or
514.Xr ftp 1
515from 192.168.0.2, 192.168.0.3 and 192.168.0.4 will appear to come from
516141.221.254.101.
517Any incoming connections to 141.221.254.101 will be directed to 192.168.0.4.
518.Pp
519Any calls to
520.Fn LibAliasRedirectPort
521will have precedence over address mappings designated by
522.Fn LibAliasRedirectAddr .
523.Pp
524This function returns a pointer which can subsequently be used by
525.Fn LibAliasRedirectDelete .
526If
527.Dv NULL
528is returned, then the function call did not complete successfully.
529.Ed
530.Pp
531.Ft int
532.Fo LibAliasAddServer
533.Fa "struct libalias *"
534.Fa "struct alias_link *link"
535.Fa "struct in_addr addr"
536.Fa "u_short port"
537.Fc
538.Bd -ragged -offset indent
539This function sets the
540.Fa link
541up for Load Sharing using IP Network Address Translation (RFC 2391, LSNAT).
542LSNAT operates as follows.
543A client attempts to access a server by using the server virtual address.
544The LSNAT router transparently redirects the request to one of the hosts
545in server pool, selected using a real-time load sharing algorithm.
546Multiple sessions may be initiated from the same client, and each session
547could be directed to a different host based on load balance across server
548pool hosts at the time.
549If load share is desired for just a few specific services, the configuration
550on LSNAT could be defined to restrict load share for just the services
551desired.
552.Pp
553Currently, only the simplest selection algorithm is implemented, where a
554host is selected on a round-robin basis only, without regard to load on
555the host.
556.Pp
557First, the
558.Fa link
559is created by either
560.Fn LibAliasRedirectPort
561or
562.Fn LibAliasRedirectAddr .
563Then,
564.Fn LibAliasAddServer
565is called multiple times to add entries to the
566.Fa link Ns 's
567server pool.
568.Pp
569For links created with
570.Fn LibAliasRedirectAddr ,
571the
572.Fa port
573argument is ignored and could have any value, e.g.\& htons(~0).
574.Pp
575This function returns 0 on success, \-1 otherwise.
576.Ed
577.Pp
578.Ft int
579.Fn LibAliasRedirectDynamic "struct libalias *" "struct alias_link *link"
580.Bd -ragged -offset indent
581This function marks the specified static redirect rule entered by
582.Fn LibAliasRedirectPort
583as dynamic.
584This can be used to e.g.\& dynamically redirect a single TCP connection,
585after which the rule is removed.
586Only fully specified links can be made dynamic.
587(See the
588.Sx STATIC AND DYNAMIC LINKS
589and
590.Sx PARTIALLY SPECIFIED ALIASING LINKS
591sections below for a definition of static vs.\& dynamic,
592and partially vs.\& fully specified links.)
593.Pp
594This function returns 0 on success, \-1 otherwise.
595.Ed
596.Pp
597.Ft void
598.Fn LibAliasRedirectDelete "struct libalias *" "struct alias_link *link"
599.Bd -ragged -offset indent
600This function will delete a specific static redirect rule entered by
601.Fn LibAliasRedirectPort
602or
603.Fn LibAliasRedirectAddr .
604The parameter
605.Fa link
606is the pointer returned by either of the redirection functions.
607If an invalid pointer is passed to
608.Fn LibAliasRedirectDelete ,
609then a program crash or unpredictable operation could result, so it is
610necessary to be careful using this function.
611.Ed
612.Pp
613.Ft int
614.Fn LibAliasProxyRule "struct libalias *" "const char *cmd"
615.Bd -ragged -offset indent
616The passed
617.Fa cmd
618string consists of one or more pairs of words.
619The first word in each pair is a token and the second is the value that
620should be applied for that token.
621Tokens and their argument types are as follows:
622.Bl -tag -width indent
623.It Cm type encode_ip_hdr | encode_tcp_stream | no_encode
624In order to support transparent proxying, it is necessary to somehow
625pass the original address and port information into the new destination
626server.
627If
628.Cm encode_ip_hdr
629is specified, the original destination address and port are passed
630as an extra IP option.
631If
632.Cm encode_tcp_stream
633is specified, the original destination address and port are passed
634as the first piece of data in the TCP stream in the format
635.Dq Li DEST Ar IP port .
636.It Cm port Ar portnum
637Only packets with the destination port
638.Ar portnum
639are proxied.
640.It Cm server Ar host Ns Op : Ns Ar portnum
641This specifies the
642.Ar host
643and
644.Ar portnum
645that the data is to be redirected to.
646.Ar host
647must be an IP address rather than a DNS host name.
648If
649.Ar portnum
650is not specified, the destination port number is not changed.
651.Pp
652The
653.Ar server
654specification is mandatory unless the
655.Cm delete
656command is being used.
657.It Cm rule Ar index
658Normally, each call to
659.Fn LibAliasProxyRule
660inserts the next rule at the start of a linear list of rules.
661If an
662.Ar index
663is specified, the new rule will be checked after all rules with lower
664indices.
665Calls to
666.Fn LibAliasProxyRule
667that do not specify a rule are assigned rule 0.
668.It Cm delete Ar index
669This token and its argument MUST NOT be used with any other tokens.
670When used, all existing rules with the given
671.Ar index
672are deleted.
673.It Cm proto tcp | udp
674If specified, only packets of the given protocol type are matched.
675.It Cm src Ar IP Ns Op / Ns Ar bits
676If specified, only packets with a source address matching the given
677.Ar IP
678are matched.
679If
680.Ar bits
681is also specified, then the first
682.Ar bits
683bits of
684.Ar IP
685are taken as a network specification, and all IP addresses from that
686network will be matched.
687.It Cm dst Ar IP Ns Op / Ns Ar bits
688If specified, only packets with a destination address matching the given
689.Ar IP
690are matched.
691If
692.Ar bits
693is also specified, then the first
694.Ar bits
695bits of
696.Ar IP
697are taken as a network specification, and all IP addresses from that
698network will be matched.
699.El
700.Pp
701This function is usually used to redirect outgoing connections for
702internal machines that are not permitted certain types of internet
703access, or to restrict access to certain external machines.
704.Ed
705.Pp
706.Ft struct alias_link *
707.Fo LibAliasRedirectProto
708.Fa "struct libalias *"
709.Fa "struct in_addr local_addr"
710.Fa "struct in_addr remote_addr"
711.Fa "struct in_addr alias_addr"
712.Fa "u_char proto"
713.Fc
714.Bd -ragged -offset indent
715This function specifies that any IP packet with protocol number of
716.Fa proto
717from a given remote address to an alias address be
718redirected to a specified local address.
719.Pp
720If
721.Fa local_addr
722or
723.Fa alias_addr
724is zero, this indicates that the packet aliasing address as established
725by
726.Fn LibAliasSetAddress
727is to be used.
728Even if
729.Fn LibAliasSetAddress
730is called to change the address after
731.Fn LibAliasRedirectProto
732is called, a zero reference will track this change.
733.Pp
734If
735.Fa remote_addr
736is zero, this indicates to redirect packets from any remote address.
737Non-zero remote addresses can sometimes be useful for firewalling.
738.Pp
739If two calls to
740.Fn LibAliasRedirectProto
741overlap in their address specifications, then the most recent call
742will have precedence.
743.Pp
744This function returns a pointer which can subsequently be used by
745.Fn LibAliasRedirectDelete .
746If
747.Dv NULL
748is returned, then the function call did not complete successfully.
749.Ed
750.Sh FRAGMENT HANDLING
751The functions in this section are used to deal with incoming fragments.
752.Pp
753Outgoing fragments are handled within
754.Fn LibAliasOut
755by changing the address according to any applicable mapping set by
756.Fn LibAliasRedirectAddr ,
757or the default aliasing address set by
758.Fn LibAliasSetAddress .
759.Pp
760Incoming fragments are handled in one of two ways.
761If the header of a fragmented IP packet has already been seen, then all
762subsequent fragments will be re-mapped in the same manner the header
763fragment was.
764Fragments which arrive before the header are saved and then retrieved
765once the header fragment has been resolved.
766.Pp
767.Ft int
768.Fn LibAliasSaveFragment "struct libalias *" "char *ptr"
769.Bd -ragged -offset indent
770When
771.Fn LibAliasIn
772returns
773.Dv PKT_ALIAS_UNRESOLVED_FRAGMENT ,
774this function can be used to save the pointer to the unresolved fragment.
775.Pp
776It is implicitly assumed that
777.Fa ptr
778points to a block of memory allocated by
779.Xr malloc 3 .
780If the fragment is never resolved, the packet aliasing engine will
781automatically free the memory after a timeout period.
782[Eventually this function should be modified so that a callback function
783for freeing memory is passed as an argument.]
784.Pp
785This function returns
786.Dv PKT_ALIAS_OK
787if it was successful and
788.Dv PKT_ALIAS_ERROR
789if there was an error.
790.Ed
791.Pp
792.Ft char *
793.Fn LibAliasGetFragment "struct libalias *" "char *buffer"
794.Bd -ragged -offset indent
795This function can be used to retrieve fragment pointers saved by
796.Fn LibAliasSaveFragment .
797The IP header fragment pointed to by
798.Fa buffer
799is the header fragment indicated when
800.Fn LibAliasIn
801returns
802.Dv PKT_ALIAS_FOUND_HEADER_FRAGMENT .
803Once a fragment pointer is retrieved, it becomes the calling program's
804responsibility to free the dynamically allocated memory for the fragment.
805.Pp
806The
807.Fn LibAliasGetFragment
808function can be called sequentially until there are no more fragments
809available, at which time it returns
810.Dv NULL .
811.Ed
812.Pp
813.Ft void
814.Fn LibAliasFragmentIn "struct libalias *" "char *header" "char *fragment"
815.Bd -ragged -offset indent
816When a fragment is retrieved with
817.Fn LibAliasGetFragment ,
818it can then be de-aliased with a call to
819.Fn LibAliasFragmentIn .
820The
821.Fa header
822argument is the pointer to a header fragment used as a template, and
823.Fa fragment
824is the pointer to the packet to be de-aliased.
825.Ed
826.Sh MISCELLANEOUS FUNCTIONS
827.Ft struct alias_link *
828.Fn AddLink "struct libalias *" "struct in_addr src_addr" "struct in_addr dst_addr" \
829"struct in_addr alias_addr" "u_short src_port" "u_short dst_port" \
830"int alias_param" "int link_type"
831.Bd -ragged -offset indent
832This function adds new state to instance hash table.
833Zero can be specified instead of dst_address and/or dst port.
834This makes link partially specified dynamic.
835However due to hashing method such links can be resolved on inbound (ext -> int) only.
836.Ed
837.Pp
838.Ft void
839.Fn LibAliasSetTarget "struct libalias *" "struct in_addr addr"
840.Bd -ragged -offset indent
841When an incoming packet not associated with any pre-existing aliasing link
842arrives at the host machine, it will be sent to the address indicated by a
843call to
844.Fn LibAliasSetTarget .
845.Pp
846If this function is called with an
847.Dv INADDR_NONE
848address argument, then all new incoming packets go to the address set by
849.Fn LibAliasSetAddress .
850.Pp
851If this function is not called, or is called with an
852.Dv INADDR_ANY
853address argument, then all new incoming packets go to the address specified
854in the packet.
855This allows external machines to talk directly to internal machines if they
856can route packets to the machine in question.
857.Ed
858.Pp
859.Ft int
860.Fn LibAliasCheckNewLink "struct libalias *"
861.Bd -ragged -offset indent
862This function returns a non-zero value when a new aliasing link is created.
863In circumstances where incoming traffic is being sequentially sent to
864different local servers, this function can be used to trigger when
865.Fn LibAliasSetTarget
866is called to change the default target address.
867.Ed
868.Pp
869.Ft u_short
870.Fn LibAliasInternetChecksum "struct libalias *" "u_short *buffer" "int nbytes"
871.Bd -ragged -offset indent
872This is a utility function that does not seem to be available elsewhere and
873is included as a convenience.
874It computes the internet checksum, which is used in both IP and
875protocol-specific headers (TCP, UDP, ICMP).
876.Pp
877The
878.Fa buffer
879argument points to the data block to be checksummed, and
880.Fa nbytes
881is the number of bytes.
882The 16-bit checksum field should be zeroed before computing the checksum.
883.Pp
884Checksums can also be verified by operating on a block of data including
885its checksum.
886If the checksum is valid,
887.Fn LibAliasInternetChecksum
888will return zero.
889.Ed
890.Pp
891.Ft int
892.Fn LibAliasUnaliasOut "struct libalias *" "char *buffer" "int maxpacketsize"
893.Bd -ragged -offset indent
894An outgoing packet, which has already been aliased,
895has its private address/port information restored by this function.
896The IP packet is pointed to by
897.Fa buffer ,
898and
899.Fa maxpacketsize
900is provided for error checking purposes.
901This function can be used if an already-aliased packet needs to have its
902original IP header restored for further processing (e.g.\& logging).
903.Ed
904.Sh AUTHORS
905.An Charles Mott Aq cm@linktel.net ,
906versions 1.0 - 1.8, 2.0 - 2.4.
907.An Eivind Eklund Aq eivind@FreeBSD.org ,
908versions 1.8b, 1.9 and 2.5.
909Added IRC DCC support as well as contributing a number of architectural
910improvements; added the firewall bypass for FTP/IRC DCC.
911.An Erik Salander Aq erik@whistle.com
912added support for PPTP and RTSP.
913.An Junichi Satoh Aq junichi@junichi.org
914added support for RTSP/PNA.
915.An Ruslan Ermilov Aq ru@FreeBSD.org
916added support for PPTP and LSNAT as well as general hacking.
917.An Paolo Pisati Aq piso@FreeBSD.org
918made the library modular, moving support for all
919protocols (except for IP, TCP and UDP) to external modules.
920.Sh ACKNOWLEDGMENTS
921Listed below, in approximate chronological order, are individuals who
922have provided valuable comments and/or debugging assistance.
923.Bd -ragged -offset indent
924.An -split
925.An Gary Roberts
926.An Tom Torrance
927.An Reto Burkhalter
928.An Martin Renters
929.An Brian Somers
930.An Paul Traina
931.An Ari Suutari
932.An Dave Remien
933.An J. Fortes
934.An Andrzej Bialecki
935.An Gordon Burditt
936.Ed
937.Sh CONCEPTUAL BACKGROUND
938This section is intended for those who are planning to modify the source
939code or want to create somewhat esoteric applications using the packet
940aliasing functions.
941.Pp
942The conceptual framework under which the packet aliasing engine operates
943is described here.
944Central to the discussion is the idea of an
945.Em aliasing link
946which describes the relationship for a given packet transaction between
947the local machine, aliased identity and remote machine.
948It is discussed how such links come into existence and are destroyed.
949.Ss ALIASING LINKS
950There is a notion of an
951.Em aliasing link ,
952which is a 7-tuple describing a specific translation:
953.Bd -literal -offset indent
954(local addr, local port, alias addr, alias port,
955 remote addr, remote port, protocol)
956.Ed
957.Pp
958Outgoing packets have the local address and port number replaced with the
959alias address and port number.
960Incoming packets undergo the reverse process.
961The packet aliasing engine attempts to match packets against an internal
962table of aliasing links to determine how to modify a given IP packet.
963Both the IP header and protocol dependent headers are modified as necessary.
964Aliasing links are created and deleted as necessary according to network
965traffic.
966.Pp
967Protocols can be TCP, UDP or even ICMP in certain circumstances.
968(Some types of ICMP packets can be aliased according to sequence or ID
969number which acts as an equivalent port number for identifying how
970individual packets should be handled.)
971.Pp
972Each aliasing link must have a unique combination of the following five
973quantities: alias address/port, remote address/port and protocol.
974This ensures that several machines on a local network can share the
975same aliasing IP address.
976In cases where conflicts might arise, the aliasing port is chosen so that
977uniqueness is maintained.
978.Ss STATIC AND DYNAMIC LINKS
979Aliasing links can either be static or dynamic.
980Static links persist indefinitely and represent fixed rules for translating
981IP packets.
982Dynamic links come into existence for a specific TCP connection or UDP
983transaction or ICMP ECHO sequence.
984For the case of TCP, the connection can be monitored to see when the
985associated aliasing link should be deleted.
986Aliasing links for UDP transactions (and ICMP ECHO and TIMESTAMP requests)
987work on a simple timeout rule.
988When no activity is observed on a dynamic link for a certain amount of time
989it is automatically deleted.
990Timeout rules also apply to TCP connections which do not open or close
991properly.
992.Ss PARTIALLY SPECIFIED ALIASING LINKS
993Aliasing links can be partially specified, meaning that the remote address
994and/or remote port are unknown.
995In this case, when a packet matching the incomplete specification is found,
996a fully specified dynamic link is created.
997If the original partially specified link is dynamic, it will be deleted
998after the fully specified link is created, otherwise it will persist.
999.Pp
1000For instance, a partially specified link might be
1001.Bd -literal -offset indent
1002(192.168.0.4, 23, 204.228.203.215, 8066, 0, 0, tcp)
1003.Ed
1004.Pp
1005The zeros denote unspecified components for the remote address and port.
1006If this link were static it would have the effect of redirecting all
1007incoming traffic from port 8066 of 204.228.203.215 to port 23 (telnet)
1008of machine 192.168.0.4 on the local network.
1009Each individual telnet connection would initiate the creation of a distinct
1010dynamic link.
1011.Ss DYNAMIC LINK CREATION
1012In addition to aliasing links, there are also address mappings that can be
1013stored within the internal data table of the packet aliasing mechanism.
1014.Bd -literal -offset indent
1015(local addr, alias addr)
1016.Ed
1017.Pp
1018Address mappings are searched when creating new dynamic links.
1019.Pp
1020All outgoing packets from the local network automatically create a dynamic
1021link if they do not match an already existing fully specified link.
1022If an address mapping exists for the outgoing packet, this determines
1023the alias address to be used.
1024If no mapping exists, then a default address, usually the address of the
1025packet aliasing host, is used.
1026If necessary, this default address can be changed as often as each individual
1027packet arrives.
1028.Pp
1029The aliasing port number is determined such that the new dynamic link does
1030not conflict with any existing links.
1031In the default operating mode, the packet aliasing engine attempts to set
1032the aliasing port equal to the local port number.
1033If this results in a conflict, then port numbers are randomly chosen until
1034a unique aliasing link can be established.
1035In an alternate operating mode, the first choice of an aliasing port is also
1036random and unrelated to the local port number.
1037.Sh MODULAR ARCHITECTURE (AND Xr ipfw 4 Sh SUPPORT)
1038One of the latest improvements to
1039.Nm
1040was to make its support
1041for new protocols independent from the rest of the library, giving it
1042the ability to load/unload support for new protocols at run-time.
1043To achieve this feature, all the code for protocol handling was moved
1044to a series of modules outside of the main library.
1045These modules are compiled from the same sources but work in
1046different ways, depending on whether they are compiled to work inside a kernel
1047or as part of the userland library.
1048.Ss LIBALIAS MODULES IN KERNEL LAND
1049When compiled for the kernel,
1050.Nm
1051modules are plain KLDs recognizable with the
1052.Pa alias_
1053prefix.
1054.Pp
1055To add support for a new protocol, load the corresponding module.
1056For example:
1057.Pp
1058.Dl "kldload alias_ftp"
1059.Pp
1060When support for a protocol is no longer needed, its module can be unloaded:
1061.Pp
1062.Dl "kldunload alias_ftp"
1063.Ss LIBALIAS MODULES IN USERLAND
1064Due to the differences between kernel and userland (no KLD mechanism,
1065many different address spaces, etc.), we had to change a bit how to
1066handle module loading/tracking/unloading in userland.
1067.Pp
1068While compiled for a userland
1069.Nm ,
1070all the modules are plain libraries, residing in
1071.Pa /usr/lib ,
1072and recognizable with the
1073.Pa libalias_
1074prefix.
1075.Pp
1076There is a configuration file,
1077.Pa /etc/libalias.conf ,
1078with the following contents (by default):
1079.Bd -literal -offset indent
1080/usr/lib/libalias_cuseeme.so
1081/usr/lib/libalias_ftp.so
1082/usr/lib/libalias_irc.so
1083/usr/lib/libalias_nbt.so
1084/usr/lib/libalias_pptp.so
1085/usr/lib/libalias_skinny.so
1086/usr/lib/libalias_smedia.so
1087.Ed
1088.Pp
1089This file contains the paths to the modules that
1090.Nm
1091will load.
1092To load/unload a new module, just add its path to
1093.Pa libalias.conf
1094and call
1095.Fn LibAliasRefreshModules
1096from the program.
1097In case the application provides a
1098.Dv SIGHUP
1099signal handler, add a call to
1100.Fn LibAliasRefreshModules
1101inside the handler, and everytime you want to refresh the loaded modules,
1102send it the
1103.Dv SIGHUP
1104signal:
1105.Pp
1106.Dl "kill -HUP <process_pid>"
1107.Ss MODULAR ARCHITECURE: HOW IT WORKS
1108The modular architecture of
1109.Nm
1110works similar whether it is running inside the
1111kernel or in userland.
1112From
1113.Pa alias_mod.c :
1114.Bd -literal
1115/* Protocol and userland module handlers chains. */
1116LIST_HEAD(handler_chain, proto_handler) handler_chain ...
1117\&...
1118SLIST_HEAD(dll_chain, dll) dll_chain ...
1119.Ed
1120.Pp
1121.Va handler_chain
1122keep tracks of all the protocol handlers loaded, while
1123.Va ddl_chain
1124takes care of userland modules loaded.
1125.Pp
1126.Va handler_chain
1127is composed of
1128.Vt "struct proto_handler"
1129entries:
1130.Bd -literal
1131struct proto_handler {
1132	u_int pri;
1133	int16_t dir;
1134	uint8_t proto;
1135	int (*fingerprint)(struct libalias *la,
1136		 struct ip *pip, struct alias_data *ah);
1137	int (*protohandler)(struct libalias *la,
1138		 struct ip *pip, struct alias_data *ah);
1139	LIST_ENTRY(proto_handler) entries;
1140};
1141.Ed
1142.Pp
1143where:
1144.Bl -inset
1145.It Va pri
1146is the priority assigned to a protocol handler, lower
1147is better.
1148.It Va dir
1149is the direction of packets: ingoing or outgoing.
1150.It Va proto
1151says at which protocol this packet belongs: IP, TCP or UDP.
1152.It Va fingerprint
1153points to the fingerprint function while protohandler points
1154to the protocol handler function.
1155.El
1156.Pp
1157The
1158.Va fingerprint
1159function has the double of scope of checking if the
1160incoming packet is found and if it belongs to any categories that this
1161module can handle.
1162.Pp
1163The
1164.Va protohandler
1165function actually manipulates
1166the packet to make
1167.Nm
1168correctly NAT it.
1169.Pp
1170When a packet enters
1171.Nm ,
1172if it meets a module hook,
1173.Va handler_chain
1174is searched to see if there is an handler that matches
1175this type of a packet (it checks protocol and direction of packet), then if
1176more than one handler is found, it starts with the module with
1177the lowest priority number: it calls the
1178.Va fingerprint
1179function and interprets the result.
1180.Pp
1181If the result value is equal to 0 then it calls the protocol handler
1182of this handler and returns.
1183Otherwise, it proceeds to the next eligible module until the
1184.Va handler_chain
1185is exhausted.
1186.Pp
1187Inside
1188.Nm ,
1189the module hook looks like this:
1190.Bd -literal -offset indent
1191struct alias_data ad = {
1192	lnk,
1193	&original_address,
1194	&alias_address,
1195	&alias_port,
1196	&ud->uh_sport,          /* original source port */
1197	&ud->uh_dport,		/* original dest port */
1198	256                     /* maxpacketsize */
1199};
1200
1201\&...
1202
1203/* walk out chain */
1204err = find_handler(IN, UDP, la, pip, &ad);
1205.Ed
1206.Pp
1207All data useful to a module are gathered together in an
1208.Vt alias_data
1209structure, then
1210.Fn find_handler
1211is called.
1212The
1213.Fn find_handler
1214function is responsible for walking out the handler
1215chain, it receives as input parameters:
1216.Bl -tag -width indent
1217.It Fa IN
1218direction
1219.It Fa UDP
1220working protocol
1221.It Fa la
1222pointer to this instance of libalias
1223.It Fa pip
1224pointer to a
1225.Vt "struct ip"
1226.It Fa ad
1227pointer to
1228.Vt "struct alias_data"
1229(see above)
1230.El
1231.Pp
1232In this case,
1233.Fn find_handler
1234will search only for modules registered for
1235supporting INcoming UDP packets.
1236.Pp
1237As was mentioned earlier,
1238.Nm
1239in userland is a bit different, cause
1240care has to be taken of module handling too (avoiding duplicate load of
1241module, avoiding module with same name, etc.) so
1242.Va dll_chain
1243was introduced.
1244.Pp
1245.Va dll_chain
1246contains a list of all userland
1247.Nm
1248modules loaded.
1249.Pp
1250When an application calls
1251.Fn LibAliasRefreshModules ,
1252.Nm
1253first unloads all the loaded modules, then reloads all the modules listed in
1254.Pa /etc/libalias.conf :
1255for every module loaded, a new entry to
1256.Va dll_chain
1257is added.
1258.Pp
1259.Va dll_chain
1260is composed of
1261.Vt "struct dll"
1262entries:
1263.Bd -literal
1264struct dll {
1265	/* name of module */
1266	char            name[DLL_LEN];
1267	/*
1268	 * ptr to shared obj obtained through
1269	 * dlopen() - use this ptr to get access
1270	 * to any symbols from a loaded module
1271	 * via dlsym()
1272	 */
1273	void            *handle;
1274	struct dll      *next;
1275};
1276.Ed
1277.Bl -inset
1278.It Va name
1279is the name of the module
1280.It Va handle
1281is a pointer to the module obtained through
1282.Xr dlopen 3
1283.El
1284Whenever a module is loaded in userland, an entry is added to
1285.Va dll_chain ,
1286then every protocol handler present in that module
1287is resolved and registered in
1288.Va handler_chain .
1289.Ss HOW TO WRITE A MODULE FOR LIBALIAS
1290There is a module (called
1291.Pa alias_dummy.[ch] )
1292in
1293.Nm
1294that can be used as a skeleton for future work, here we analyse some parts of that
1295module.
1296From
1297.Pa alias_dummy.c :
1298.Bd -literal
1299struct proto_handler handlers [] = {{666, IN|OUT, UDP|TCP,
1300				    &fingerprint, &protohandler}};
1301.Ed
1302.Pp
1303The variable
1304.Va handlers
1305is the
1306.Dq "most important thing"
1307in a module
1308cause it describes the handlers present and lets the outside world use
1309it in an opaque way.
1310.Pp
1311It must ALWAYS be present in every module, and it MUST retain
1312the name
1313.Va handlers ,
1314otherwise attempting to load a module in userland will fail and
1315complain about missing symbols: for more information about module
1316load/unload, please refer to
1317.Fn LibAliasRefreshModules ,
1318.Fn LibAliasLoadModule
1319and
1320.Fn LibAliasUnloadModule
1321in
1322.Pa alias.c .
1323.Pp
1324.Va handlers
1325contains all the
1326.Vt proto_handler
1327structures present in a module.
1328.Bd -literal
1329static int
1330mod_handler(module_t mod, int type, void *data)
1331{
1332	int error;
1333
1334	switch (type) {
1335	case MOD_LOAD:
1336		error = 0;
1337		attach_handlers(handlers);
1338		break;
1339	case MOD_UNLOAD:
1340		error = 0;
1341		detach_handlers(handlers;
1342		break;
1343	default:
1344		error = EINVAL;
1345	}
1346	return (error);
1347}
1348.Ed
1349When running as KLD,
1350.Fn mod_handler
1351register/deregister the module using
1352.Fn attach_handlers
1353and
1354.Fn detach_handlers ,
1355respectively.
1356.Pp
1357Every module must contain at least 2 functions: one fingerprint
1358function and a protocol handler function.
1359.Bd -literal
1360#ifdef _KERNEL
1361static
1362#endif
1363int
1364fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah)
1365{
1366
1367\&...
1368}
1369
1370#ifdef _KERNEL
1371static
1372#endif
1373int
1374protohandler(struct libalias *la, struct ip *pip,
1375             struct alias_data *ah)
1376{
1377
1378\&...
1379}
1380.Ed
1381and they must accept exactly these input parameters.
1382.Ss PATCHING AN APPLICATION FOR USERLAND LIBALIAS MODULES
1383To add module support into an application that uses
1384.Nm ,
1385the following simple steps can be followed.
1386.Bl -enum
1387.It
1388Find the main file of an application
1389(let us call it
1390.Pa main.c ) .
1391.It
1392Add this to the header section of
1393.Pa main.c ,
1394if not already present:
1395.Pp
1396.Dl "#include <signal.h>"
1397.Pp
1398and this just after the header section:
1399.Pp
1400.Dl "static void signal_handler(int);"
1401.It
1402Add the following line to the init function of an application or,
1403if it does not have any init function, put it in
1404.Fn main :
1405.Pp
1406.Dl "signal(SIGHUP, signal_handler);"
1407.Pp
1408and place the
1409.Fn signal_handler
1410function somewhere in
1411.Pa main.c :
1412.Bd -literal -offset indent
1413static void
1414signal_handler(int sig)
1415{
1416
1417	LibAliasRefreshModules();
1418}
1419.Ed
1420.Pp
1421Otherwise, if an application already traps the
1422.Dv SIGHUP
1423signal, just add a call to
1424.Fn LibAliasRefreshModules
1425in the signal handler function.
1426.El
1427For example, to patch
1428.Xr natd 8
1429to use
1430.Nm
1431modules, just add the following line to
1432.Fn RefreshAddr "int sig __unused" :
1433.Pp
1434.Dl "LibAliasRefreshModules()"
1435.Pp
1436recompile and you are done.
1437.Ss LOGGING SUPPORT IN KERNEL LAND
1438When working as KLD,
1439.Nm
1440now has log support that
1441happens on a buffer allocated inside
1442.Vt "struct libalias"
1443(from
1444.Pa alias_local.h ) :
1445.Bd -literal
1446struct libalias {
1447       ...
1448
1449	/* log descriptor        */
1450#ifdef	KERNEL_LOG
1451	char           *logDesc;        /*
1452					 * ptr to an auto-malloced
1453					 * memory buffer when libalias
1454					 * works as kld
1455					 */
1456#else
1457	FILE           *logDesc;	/*
1458					 * ptr to /var/log/alias.log
1459					 * when libalias runs as a
1460					 * userland lib
1461					 */
1462#endif
1463
1464	...
1465}
1466.Ed
1467so all applications using
1468.Nm
1469will be able to handle their
1470own logs, if they want, accessing
1471.Va logDesc .
1472Moreover, every change to a log buffer is automatically added to
1473.Xr syslog 3
1474with the
1475.Dv LOG_SECURITY
1476facility and the
1477.Dv LOG_INFO
1478level.
1479