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 July 04, 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 the 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.Sh INITIALIZATION AND CONTROL 65One special function, 66.Fn LibAliasInit , 67must always be called before any packet handling may be performed, and 68the returned instance pointer must be passed to all the other functions. 69Normally, the 70.Fn LibAliasSetAddress 71function is called afterwards, to set the default aliasing address. 72In addition, the operating mode of the packet aliasing engine can be 73customized by calling 74.Fn LibAliasSetMode . 75.Pp 76.Ft "struct libalias *" 77.Fn LibAliasInit "struct libalias *" 78.Bd -ragged -offset indent 79This function is used to initialize 80internal data structures. 81When called the first time, a 82.Dv NULL 83pointer should be passed as an argument. 84The following mode bits are always set after calling 85.Fn LibAliasInit . 86See the description of 87.Fn LibAliasSetMode 88below for the meaning of these mode bits. 89.Pp 90.Bl -item -offset indent -compact 91.It 92.Dv PKT_ALIAS_SAME_PORTS 93.It 94.Dv PKT_ALIAS_USE_SOCKETS 95.It 96.Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE 97.El 98.Pp 99This function will always return the packet aliasing engine to the same 100initial state. 101The 102.Fn LibAliasSetAddress 103function is normally called afterwards, and any desired changes from the 104default mode bits listed above require a call to 105.Fn LibAliasSetMode . 106.Pp 107It is mandatory that this function be called at the beginning of a program 108prior to any packet handling. 109.Ed 110.Pp 111.Ft void 112.Fn LibAliasUninit "struct libalias *" 113.Bd -ragged -offset indent 114This function has no return value and is used to clear any 115resources attached to internal data structures. 116.Pp 117This function should be called when a program stops using the aliasing 118engine; amongst other things, it clears out any firewall holes. 119To provide backwards compatibility and extra security, it is added to 120the 121.Xr atexit 3 122chain by 123.Fn LibAliasInit . 124.Ed 125.Pp 126.Ft void 127.Fn LibAliasSetAddress "struct libalias *" "struct in_addr addr" 128.Bd -ragged -offset indent 129This function sets the source address to which outgoing packets from the 130local area network are aliased. 131All outgoing packets are re-mapped to this address unless overridden by a 132static address mapping established by 133.Fn LibAliasRedirectAddr . 134If this function has not been called, and no static rules match, an outgoing 135packet retains its source address. 136.Pp 137If the 138.Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE 139mode bit is set (the default mode of operation), then the internal aliasing 140link tables will be reset any time the aliasing address changes. 141This is useful for interfaces such as 142.Xr ppp 8 , 143where the IP 144address may or may not change on successive dial-up attempts. 145.Pp 146If the 147.Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE 148mode bit is set to zero, this function can also be used to dynamically change 149the aliasing address on a packet-to-packet basis (it is a low overhead call). 150.Pp 151It is mandatory that this function be called prior to any packet handling. 152.Ed 153.Pp 154.Ft unsigned int 155.Fn LibAliasSetMode "struct libalias *" "unsigned int flags" "unsigned int mask" 156.Bd -ragged -offset indent 157This function sets or clears mode bits 158according to the value of 159.Fa flags . 160Only bits marked in 161.Fa mask 162are affected. 163The following mode bits are defined in 164.In alias.h : 165.Bl -tag -width indent 166.It Dv PKT_ALIAS_LOG 167Enables logging into 168.Pa /var/log/alias.log . 169Each time an aliasing link is created or deleted, the log file is appended to 170with the current number of ICMP, TCP and UDP links. 171Mainly useful for debugging when the log file is viewed continuously with 172.Xr tail 1 . 173.It Dv PKT_ALIAS_DENY_INCOMING 174If this mode bit is set, all incoming packets associated with new TCP 175connections or new UDP transactions will be marked for being ignored 176.Fn ( LibAliasIn 177returns 178.Dv PKT_ALIAS_IGNORED 179code) 180by the calling program. 181Response packets to connections or transactions initiated from the packet 182aliasing host or local network will be unaffected. 183This mode bit is useful for implementing a one-way firewall. 184.It Dv PKT_ALIAS_SAME_PORTS 185If this mode bit is set, the packet-aliasing engine will attempt to leave 186the alias port numbers unchanged from the actual local port numbers. 187This can be done as long as the quintuple (proto, alias addr, alias port, 188remote addr, remote port) is unique. 189If a conflict exists, a new aliasing port number is chosen even if this 190mode bit is set. 191.It Dv PKT_ALIAS_USE_SOCKETS 192This bit should be set when the packet aliasing host originates network 193traffic as well as forwards it. 194When the packet aliasing host is waiting for a connection from an unknown 195host address or unknown port number (e.g.\& an FTP data connection), this 196mode bit specifies that a socket be allocated as a place holder to prevent 197port conflicts. 198Once a connection is established, usually within a minute or so, the socket 199is closed. 200.It Dv PKT_ALIAS_UNREGISTERED_ONLY 201If this mode bit is set, traffic on the local network which does not 202originate from unregistered address spaces will be ignored. 203Standard Class A, B and C unregistered addresses are: 204.Bd -literal -offset indent 20510.0.0.0 -> 10.255.255.255 (Class A subnet) 206172.16.0.0 -> 172.31.255.255 (Class B subnets) 207192.168.0.0 -> 192.168.255.255 (Class C subnets) 208.Ed 209.Pp 210This option is useful in the case that the packet aliasing host has both 211registered and unregistered subnets on different interfaces. 212The registered subnet is fully accessible to the outside world, so traffic 213from it does not need to be passed through the packet aliasing engine. 214.It Dv PKT_ALIAS_RESET_ON_ADDR_CHANGE 215When this mode bit is set and 216.Fn LibAliasSetAddress 217is called to change the aliasing address, the internal link table of the 218packet aliasing engine will be cleared. 219This operating mode is useful for 220.Xr ppp 8 221links where the interface address can sometimes change or remain the same 222between dial-up attempts. 223If this mode bit is not set, the link table will never be reset in the event 224of an address change. 225.It Dv PKT_ALIAS_PUNCH_FW 226This option makes 227.Nm 228.Dq punch holes 229in an 230.Xr ipfirewall 4 - 231based firewall for FTP/IRC DCC connections. 232The holes punched are bound by from/to IP address and port; it will not be 233possible to use a hole for another connection. 234A hole is removed when the connection that uses it dies. 235To cater to unexpected death of a program using 236.Nm 237(e.g.\& kill -9), 238changing the state of the flag will clear the entire firewall range 239allocated for holes. 240This clearing will also happen on the initial call to 241.Fn LibAliasSetFWBase , 242which must happen prior to setting this flag. 243.It Dv PKT_ALIAS_REVERSE 244This option makes 245.Nm 246reverse the way it handles incoming and outgoing packets, allowing it 247to be fed with data that passes through the internal interface rather 248than the external one. 249.It Dv PKT_ALIAS_PROXY_ONLY 250This option tells 251.Nm 252to obey transparent proxy rules only. 253Normal packet aliasing is not performed. 254See 255.Fn LibAliasProxyRule 256below for details. 257.It Dv PKT_ALIAS_SKIP_GLOBAL 258This option is used by 259.Pa ipfw_nat 260only. 261Specifying it as a flag to 262.Fn LibAliasSetMode 263has no effect. 264See section 265.Sx NETWORK ADDRESS TRANSLATION 266in 267.Xr ipfw 8 268for more details. 269.El 270.Ed 271.Pp 272.Ft void 273.Fn LibAliasSetFWBase "struct libalias *" "unsigned int base" "unsigned int num" 274.Bd -ragged -offset indent 275Set the firewall range allocated for punching firewall holes (with the 276.Dv PKT_ALIAS_PUNCH_FW 277flag). 278The range is cleared for all rules on initialization. 279.Ed 280.Pp 281.Ft void 282.Fn LibAliasSkinnyPort "struct libalias *" "unsigned int port" 283.Bd -ragged -offset indent 284Set the TCP port used by the Skinny Station protocol. 285Skinny is used by Cisco IP phones to communicate with 286Cisco Call Managers to set up voice over IP calls. 287If this is not set, Skinny aliasing will not be done. 288The typical port used by Skinny is 2000. 289.Ed 290.Sh PACKET HANDLING 291The packet handling functions are used to modify incoming (remote to local) 292and outgoing (local to remote) packets. 293The calling program is responsible for receiving and sending packets via 294network interfaces. 295.Pp 296Along with 297.Fn LibAliasInit 298and 299.Fn LibAliasSetAddress , 300the two packet handling functions, 301.Fn LibAliasIn 302and 303.Fn LibAliasOut , 304comprise the minimal set of functions needed for a basic IP masquerading 305implementation. 306.Pp 307.Ft int 308.Fn LibAliasIn "struct libalias *" "char *buffer" "int maxpacketsize" 309.Bd -ragged -offset indent 310An incoming packet coming from a remote machine to the local network is 311de-aliased by this function. 312The IP packet is pointed to by 313.Fa buffer , 314and 315.Fa maxpacketsize 316indicates the size of the data structure containing the packet and should 317be at least as large as the actual packet size. 318.Pp 319Return codes: 320.Bl -tag -width indent 321.It Dv PKT_ALIAS_OK 322The packet aliasing process was successful. 323.It Dv PKT_ALIAS_IGNORED 324The packet was ignored and not de-aliased. 325This can happen if the protocol is unrecognized, as for an ICMP message 326type that is not handled, or if incoming packets for new connections are being 327ignored (if the 328.Dv PKT_ALIAS_DENY_INCOMING 329mode bit was set using 330.Fn LibAliasSetMode ) . 331.It Dv PKT_ALIAS_UNRESOLVED_FRAGMENT 332This is returned when a fragment cannot be resolved because the header 333fragment has not been sent yet. 334In this situation, fragments must be saved with 335.Fn LibAliasSaveFragment 336until a header fragment is found. 337.It Dv PKT_ALIAS_FOUND_HEADER_FRAGMENT 338The packet aliasing process was successful, and a header fragment was found. 339This is a signal to retrieve any unresolved fragments with 340.Fn LibAliasGetFragment 341and de-alias them with 342.Fn LibAliasFragmentIn . 343.It Dv PKT_ALIAS_ERROR 344An internal error within the packet aliasing engine occurred. 345.El 346.Ed 347.Pp 348.Ft int 349.Fn LibAliasOut "struct libalias *" "char *buffer" "int maxpacketsize" 350.Bd -ragged -offset indent 351An outgoing packet coming from the local network to a remote machine is 352aliased by this function. 353The IP packet is pointed to by 354.Fa buffer , 355and 356.Fa maxpacketsize 357indicates the maximum packet size permissible should the packet length be 358changed. 359IP encoding protocols place address and port information in the encapsulated 360data stream which has to be modified and can account for changes in packet 361length. 362Well known examples of such protocols are FTP and IRC DCC. 363.Pp 364Return codes: 365.Bl -tag -width indent 366.It Dv PKT_ALIAS_OK 367The packet aliasing process was successful. 368.It Dv PKT_ALIAS_IGNORED 369The packet was ignored and not aliased. 370This can happen if the protocol is unrecognized, or possibly an ICMP message 371type is not handled. 372.It Dv PKT_ALIAS_ERROR 373An internal error within the packet aliasing engine occurred. 374.El 375.Ed 376.Sh PORT AND ADDRESS REDIRECTION 377The functions described in this section allow machines on the local network 378to be accessible in some degree to new incoming connections from the external 379network. 380Individual ports can be re-mapped or static network address translations can 381be designated. 382.Pp 383.Ft struct alias_link * 384.Fo LibAliasRedirectPort 385.Fa "struct libalias *" 386.Fa "struct in_addr local_addr" 387.Fa "u_short local_port" 388.Fa "struct in_addr remote_addr" 389.Fa "u_short remote_port" 390.Fa "struct in_addr alias_addr" 391.Fa "u_short alias_port" 392.Fa "u_char proto" 393.Fc 394.Bd -ragged -offset indent 395This function specifies that traffic from a given remote address/port to 396an alias address/port be redirected to a specified local address/port. 397The parameter 398.Fa proto 399can be either 400.Dv IPPROTO_TCP 401or 402.Dv IPPROTO_UDP , 403as defined in 404.In netinet/in.h . 405.Pp 406If 407.Fa local_addr 408or 409.Fa alias_addr 410is zero, this indicates that the packet aliasing address as established 411by 412.Fn LibAliasSetAddress 413is to be used. 414Even if 415.Fn LibAliasSetAddress 416is called to change the address after 417.Fn LibAliasRedirectPort 418is called, a zero reference will track this change. 419.Pp 420If the link is further set up to operate with load sharing, then 421.Fa local_addr 422and 423.Fa local_port 424are ignored, and are selected dynamically from the server pool, as described in 425.Fn LibAliasAddServer 426below. 427.Pp 428If 429.Fa remote_addr 430is zero, this indicates to redirect packets from any remote address. 431Likewise, if 432.Fa remote_port 433is zero, this indicates to redirect packets originating from any remote 434port number. 435The remote port specification will almost always be zero, but non-zero 436remote addresses can sometimes be useful for firewalling. 437If two calls to 438.Fn LibAliasRedirectPort 439overlap in their address/port specifications, then the most recent call 440will have precedence. 441.Pp 442This function returns a pointer which can subsequently be used by 443.Fn LibAliasRedirectDelete . 444If 445.Dv NULL 446is returned, then the function call did not complete successfully. 447.Pp 448All port numbers should be in network address byte order, so it is necessary 449to use 450.Xr htons 3 451to convert these parameters from internally readable numbers to network byte 452order. 453Addresses are also in network byte order, which is implicit in the use of the 454.Fa struct in_addr 455data type. 456.Ed 457.Pp 458.Ft struct alias_link * 459.Fo LibAliasRedirectAddr 460.Fa "struct libalias *" 461.Fa "struct in_addr local_addr" 462.Fa "struct in_addr alias_addr" 463.Fc 464.Bd -ragged -offset indent 465This function designates that all incoming traffic to 466.Fa alias_addr 467be redirected to 468.Fa local_addr . 469Similarly, all outgoing traffic from 470.Fa local_addr 471is aliased to 472.Fa alias_addr . 473.Pp 474If 475.Fa local_addr 476or 477.Fa alias_addr 478is zero, this indicates that the packet aliasing address as established by 479.Fn LibAliasSetAddress 480is to be used. 481Even if 482.Fn LibAliasSetAddress 483is called to change the address after 484.Fn LibAliasRedirectAddr 485is called, a zero reference will track this change. 486.Pp 487If the link is further set up to operate with load sharing, then the 488.Fa local_addr 489argument is ignored, and is selected dynamically from the server pool, 490as 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 the server pool, 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 the load balance across server 548pool hosts when the sessions are initiated. 549If load sharing is desired for just a few specific services, the configuration 550on LSNAT could be defined to restrict load sharing to 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 610care is needed when 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 will 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 the instance hash table. 833The dst_address and/or dst_port may be given as zero, which 834introduces some dynamic character into the link, since 835LibAliasSetAddress can change the address that is used. 836However, in the current implementation, such links can only be used 837for inbound (ext -> int) traffic. 838.Ed 839.Pp 840.Ft void 841.Fn LibAliasSetTarget "struct libalias *" "struct in_addr addr" 842.Bd -ragged -offset indent 843When an incoming packet not associated with any pre-existing aliasing link 844arrives at the host machine, it will be sent to the address indicated by a 845call to 846.Fn LibAliasSetTarget . 847.Pp 848If this function is called with an 849.Dv INADDR_NONE 850address argument, then all new incoming packets go to the address set by 851.Fn LibAliasSetAddress . 852.Pp 853If this function is not called, or is called with an 854.Dv INADDR_ANY 855address argument, then all new incoming packets go to the address specified 856in the packet. 857This allows external machines to talk directly to internal machines if they 858can route packets to the machine in question. 859.Ed 860.Pp 861.Ft int 862.Fn LibAliasCheckNewLink "struct libalias *" 863.Bd -ragged -offset indent 864This function returns a non-zero value when a new aliasing link is created. 865In circumstances where incoming traffic is being sequentially sent to 866different local servers, this function can be used to trigger when 867.Fn LibAliasSetTarget 868is called to change the default target address. 869.Ed 870.Pp 871.Ft u_short 872.Fn LibAliasInternetChecksum "struct libalias *" "u_short *buffer" "int nbytes" 873.Bd -ragged -offset indent 874This is a utility function that does not seem to be available elsewhere and 875is included as a convenience. 876It computes the internet checksum, which is used in both IP and 877protocol-specific headers (TCP, UDP, ICMP). 878.Pp 879The 880.Fa buffer 881argument points to the data block to be checksummed, and 882.Fa nbytes 883is the number of bytes. 884The 16-bit checksum field should be zeroed before computing the checksum. 885.Pp 886Checksums can also be verified by operating on a block of data including 887its checksum. 888If the checksum is valid, 889.Fn LibAliasInternetChecksum 890will return zero. 891.Ed 892.Pp 893.Ft int 894.Fn LibAliasUnaliasOut "struct libalias *" "char *buffer" "int maxpacketsize" 895.Bd -ragged -offset indent 896An outgoing packet, which has already been aliased, 897has its private address/port information restored by this function. 898The IP packet is pointed to by 899.Fa buffer , 900and 901.Fa maxpacketsize 902is provided for error checking purposes. 903This function can be used if an already-aliased packet needs to have its 904original IP header restored for further processing (e.g.\& logging). 905.Ed 906.Sh AUTHORS 907.An Charles Mott Aq cm@linktel.net , 908versions 1.0 - 1.8, 2.0 - 2.4. 909.An Eivind Eklund Aq eivind@FreeBSD.org , 910versions 1.8b, 1.9 and 2.5. 911Added IRC DCC support as well as contributing a number of architectural 912improvements; added the firewall bypass for FTP/IRC DCC. 913.An Erik Salander Aq erik@whistle.com 914added support for PPTP and RTSP. 915.An Junichi Satoh Aq junichi@junichi.org 916added support for RTSP/PNA. 917.An Ruslan Ermilov Aq ru@FreeBSD.org 918added support for PPTP and LSNAT as well as general hacking. 919.An Paolo Pisati Aq piso@FreeBSD.org 920made the library modular, moving support for all 921protocols (except for IP, TCP and UDP) to external modules. 922.Sh ACKNOWLEDGMENTS 923Listed below, in approximate chronological order, are individuals who 924have provided valuable comments and/or debugging assistance. 925.Bd -ragged -offset indent 926.An -split 927.An Gary Roberts 928.An Tom Torrance 929.An Reto Burkhalter 930.An Martin Renters 931.An Brian Somers 932.An Paul Traina 933.An Ari Suutari 934.An Dave Remien 935.An J. Fortes 936.An Andrzej Bialecki 937.An Gordon Burditt 938.Ed 939.Sh CONCEPTUAL BACKGROUND 940This section is intended for those who are planning to modify the source 941code or want to create somewhat esoteric applications using the packet 942aliasing functions. 943.Pp 944The conceptual framework under which the packet aliasing engine operates 945is described here. 946Central to the discussion is the idea of an 947.Em aliasing link 948which describes the relationship for a given packet transaction between 949the local machine, aliased identity and remote machine. 950It is discussed how such links come into existence and are destroyed. 951.Ss ALIASING LINKS 952There is a notion of an 953.Em aliasing link , 954which is a 7-tuple describing a specific translation: 955.Bd -literal -offset indent 956(local addr, local port, alias addr, alias port, 957 remote addr, remote port, protocol) 958.Ed 959.Pp 960Outgoing packets have the local address and port number replaced with the 961alias address and port number. 962Incoming packets undergo the reverse process. 963The packet aliasing engine attempts to match packets against an internal 964table of aliasing links to determine how to modify a given IP packet. 965Both the IP header and protocol dependent headers are modified as necessary. 966Aliasing links are created and deleted as necessary according to network 967traffic. 968.Pp 969Protocols can be TCP, UDP or even ICMP in certain circumstances. 970(Some types of ICMP packets can be aliased according to sequence or ID 971number which acts as an equivalent port number for identifying how 972individual packets should be handled.) 973.Pp 974Each aliasing link must have a unique combination of the following five 975quantities: alias address/port, remote address/port and protocol. 976This ensures that several machines on a local network can share the 977same aliasing IP address. 978In cases where conflicts might arise, the aliasing port is chosen so that 979uniqueness is maintained. 980.Ss STATIC AND DYNAMIC LINKS 981Aliasing links can either be static or dynamic. 982Static links persist indefinitely and represent fixed rules for translating 983IP packets. 984Dynamic links come into existence for a specific TCP connection or UDP 985transaction or ICMP ECHO sequence. 986For the case of TCP, the connection can be monitored to see when the 987associated aliasing link should be deleted. 988Aliasing links for UDP transactions (and ICMP ECHO and TIMESTAMP requests) 989work on a simple timeout rule. 990When no activity is observed on a dynamic link for a certain amount of time 991it is automatically deleted. 992Timeout rules also apply to TCP connections which do not open or close 993properly. 994.Ss PARTIALLY SPECIFIED ALIASING LINKS 995Aliasing links can be partially specified, meaning that the remote address 996and/or remote port are unknown. 997In this case, when a packet matching the incomplete specification is found, 998a fully specified dynamic link is created. 999If the original partially specified link is dynamic, it will be deleted 1000after the fully specified link is created, otherwise it will persist. 1001.Pp 1002For instance, a partially specified link might be 1003.Bd -literal -offset indent 1004(192.168.0.4, 23, 204.228.203.215, 8066, 0, 0, tcp) 1005.Ed 1006.Pp 1007The zeros denote unspecified components for the remote address and port. 1008If this link were static it would have the effect of redirecting all 1009incoming traffic from port 8066 of 204.228.203.215 to port 23 (telnet) 1010of machine 192.168.0.4 on the local network. 1011Each individual telnet connection would initiate the creation of a distinct 1012dynamic link. 1013.Ss DYNAMIC LINK CREATION 1014In addition to aliasing links, there are also address mappings that can be 1015stored within the internal data table of the packet aliasing mechanism. 1016.Bd -literal -offset indent 1017(local addr, alias addr) 1018.Ed 1019.Pp 1020Address mappings are searched when creating new dynamic links. 1021.Pp 1022All outgoing packets from the local network automatically create a dynamic 1023link if they do not match an already existing fully specified link. 1024If an address mapping exists for the outgoing packet, this determines 1025the alias address to be used. 1026If no mapping exists, then a default address, usually the address of the 1027packet aliasing host, is used. 1028If necessary, this default address can be changed as often as each individual 1029packet arrives. 1030.Pp 1031The aliasing port number is determined such that the new dynamic link does 1032not conflict with any existing links. 1033In the default operating mode, the packet aliasing engine attempts to set 1034the aliasing port equal to the local port number. 1035If this results in a conflict, then port numbers are randomly chosen until 1036a unique aliasing link can be established. 1037In an alternate operating mode, the first choice of an aliasing port is also 1038random and unrelated to the local port number. 1039.Sh MODULAR ARCHITECTURE (AND Xr ipfw 4 Sh SUPPORT) 1040One of the latest improvements to 1041.Nm 1042was to make its support 1043for new protocols independent from the rest of the library, giving it 1044the ability to load/unload support for new protocols at run-time. 1045To achieve this feature, all the code for protocol handling was moved 1046to a series of modules outside of the main library. 1047These modules are compiled from the same sources but work in 1048different ways, depending on whether they are compiled to work inside a kernel 1049or as part of the userland library. 1050.Ss LIBALIAS MODULES IN KERNEL LAND 1051When compiled for the kernel, 1052.Nm 1053modules are plain KLDs recognizable with the 1054.Pa alias_ 1055prefix. 1056.Pp 1057To add support for a new protocol, load the corresponding module. 1058For example: 1059.Pp 1060.Dl "kldload alias_ftp" 1061.Pp 1062When support for a protocol is no longer needed, its module can be unloaded: 1063.Pp 1064.Dl "kldunload alias_ftp" 1065.Ss LIBALIAS MODULES IN USERLAND 1066Due to the differences between kernel and userland (no KLD mechanism, 1067many different address spaces, etc.), we had to change a bit how to 1068handle module loading/tracking/unloading in userland. 1069.Pp 1070While compiled for a userland 1071.Nm , 1072all the modules are plain libraries, residing in 1073.Pa /usr/lib , 1074and recognizable with the 1075.Pa libalias_ 1076prefix. 1077.Pp 1078There is a configuration file, 1079.Pa /etc/libalias.conf , 1080with the following contents (by default): 1081.Bd -literal -offset indent 1082/usr/lib/libalias_cuseeme.so 1083/usr/lib/libalias_ftp.so 1084/usr/lib/libalias_irc.so 1085/usr/lib/libalias_nbt.so 1086/usr/lib/libalias_pptp.so 1087/usr/lib/libalias_skinny.so 1088/usr/lib/libalias_smedia.so 1089.Ed 1090.Pp 1091This file contains the paths to the modules that 1092.Nm 1093will load. 1094To load/unload a new module, just add its path to 1095.Pa libalias.conf 1096and call 1097.Fn LibAliasRefreshModules 1098from the program. 1099In case the application provides a 1100.Dv SIGHUP 1101signal handler, add a call to 1102.Fn LibAliasRefreshModules 1103inside the handler, and everytime you want to refresh the loaded modules, 1104send it the 1105.Dv SIGHUP 1106signal: 1107.Pp 1108.Dl "kill -HUP <process_pid>" 1109.Ss MODULAR ARCHITECURE: HOW IT WORKS 1110The modular architecture of 1111.Nm 1112works similar whether it is running inside the 1113kernel or in userland. 1114From 1115.Pa alias_mod.c : 1116.Bd -literal 1117/* Protocol and userland module handlers chains. */ 1118LIST_HEAD(handler_chain, proto_handler) handler_chain ... 1119\&... 1120SLIST_HEAD(dll_chain, dll) dll_chain ... 1121.Ed 1122.Pp 1123.Va handler_chain 1124keeps track of all the protocol handlers loaded, while 1125.Va ddl_chain 1126tracks which userland modules are loaded. 1127.Pp 1128.Va handler_chain 1129is composed of 1130.Vt "struct proto_handler" 1131entries: 1132.Bd -literal 1133struct proto_handler { 1134 u_int pri; 1135 int16_t dir; 1136 uint8_t proto; 1137 int (*fingerprint)(struct libalias *la, 1138 struct ip *pip, struct alias_data *ah); 1139 int (*protohandler)(struct libalias *la, 1140 struct ip *pip, struct alias_data *ah); 1141 LIST_ENTRY(proto_handler) entries; 1142}; 1143.Ed 1144.Pp 1145where: 1146.Bl -inset 1147.It Va pri 1148is the priority assigned to a protocol handler; lower priority 1149is better. 1150.It Va dir 1151is the direction of packets: ingoing or outgoing. 1152.It Va proto 1153indicates to which protocol this packet belongs: IP, TCP or UDP. 1154.It Va fingerprint 1155points to the fingerprint function while protohandler points 1156to the protocol handler function. 1157.El 1158.Pp 1159The 1160.Va fingerprint 1161function has the dual role of checking if the 1162incoming packet is found, and if it belongs to any categories that this 1163module can handle. 1164.Pp 1165The 1166.Va protohandler 1167function actually manipulates 1168the packet to make 1169.Nm 1170correctly NAT it. 1171.Pp 1172When a packet enters 1173.Nm , 1174if it meets a module hook, 1175.Va handler_chain 1176is searched to see if there is an handler that matches 1177this type of a packet (it checks protocol and direction of packet). 1178Then, if more than one handler is found, it starts with the module with 1179the lowest priority number: it calls the 1180.Va fingerprint 1181function and interprets the result. 1182.Pp 1183If the result value is equal to 0 then it calls the protocol handler 1184of this handler and returns. 1185Otherwise, it proceeds to the next eligible module until the 1186.Va handler_chain 1187is exhausted. 1188.Pp 1189Inside 1190.Nm , 1191the module hook looks like this: 1192.Bd -literal -offset indent 1193struct alias_data ad = { 1194 lnk, 1195 &original_address, 1196 &alias_address, 1197 &alias_port, 1198 &ud->uh_sport, /* original source port */ 1199 &ud->uh_dport, /* original dest port */ 1200 256 /* maxpacketsize */ 1201}; 1202 1203\&... 1204 1205/* walk out chain */ 1206err = find_handler(IN, UDP, la, pip, &ad); 1207.Ed 1208.Pp 1209All data useful to a module are gathered together in an 1210.Vt alias_data 1211structure, then 1212.Fn find_handler 1213is called. 1214The 1215.Fn find_handler 1216function is responsible for walking the handler 1217chain; it receives as input parameters: 1218.Bl -tag -width indent 1219.It Fa IN 1220direction 1221.It Fa UDP 1222working protocol 1223.It Fa la 1224pointer to this instance of libalias 1225.It Fa pip 1226pointer to a 1227.Vt "struct ip" 1228.It Fa ad 1229pointer to 1230.Vt "struct alias_data" 1231(see above) 1232.El 1233.Pp 1234In this case, 1235.Fn find_handler 1236will search only for modules registered for 1237supporting INcoming UDP packets. 1238.Pp 1239As was mentioned earlier, 1240.Nm 1241in userland is a bit different, as 1242care must be taken in module handling as well (avoiding duplicate load of 1243modules, avoiding modules with same name, etc.) so 1244.Va dll_chain 1245was introduced. 1246.Pp 1247.Va dll_chain 1248contains a list of all userland 1249.Nm 1250modules loaded. 1251.Pp 1252When an application calls 1253.Fn LibAliasRefreshModules , 1254.Nm 1255first unloads all the loaded modules, then reloads all the modules listed in 1256.Pa /etc/libalias.conf : 1257for every module loaded, a new entry is added to 1258.Va dll_chain . 1259.Pp 1260.Va dll_chain 1261is composed of 1262.Vt "struct dll" 1263entries: 1264.Bd -literal 1265struct dll { 1266 /* name of module */ 1267 char name[DLL_LEN]; 1268 /* 1269 * ptr to shared obj obtained through 1270 * dlopen() - use this ptr to get access 1271 * to any symbols from a loaded module 1272 * via dlsym() 1273 */ 1274 void *handle; 1275 struct dll *next; 1276}; 1277.Ed 1278.Bl -inset 1279.It Va name 1280is the name of the module 1281.It Va handle 1282is a pointer to the module obtained through 1283.Xr dlopen 3 1284.El 1285Whenever a module is loaded in userland, an entry is added to 1286.Va dll_chain , 1287then every protocol handler present in that module 1288is resolved and registered in 1289.Va handler_chain . 1290.Ss HOW TO WRITE A MODULE FOR LIBALIAS 1291There is a module (called 1292.Pa alias_dummy.[ch] ) 1293in 1294.Nm 1295that can be used as a skeleton for future work. 1296Here we analyse some parts of that module. 1297From 1298.Pa alias_dummy.c : 1299.Bd -literal 1300struct proto_handler handlers [] = {{666, IN|OUT, UDP|TCP, 1301 &fingerprint, &protohandler}}; 1302.Ed 1303.Pp 1304The variable 1305.Va handlers 1306is the 1307.Dq "most important thing" 1308in a module 1309since it describes the handlers present and lets the outside world use 1310it in an opaque way. 1311.Pp 1312It must ALWAYS be present in every module, and it MUST retain 1313the name 1314.Va handlers , 1315otherwise attempting to load a module in userland will fail and 1316complain about missing symbols: for more information about module 1317load/unload, please refer to 1318.Fn LibAliasRefreshModules , 1319.Fn LibAliasLoadModule 1320and 1321.Fn LibAliasUnloadModule 1322in 1323.Pa alias.c . 1324.Pp 1325.Va handlers 1326contains all the 1327.Vt proto_handler 1328structures present in a module. 1329.Bd -literal 1330static int 1331mod_handler(module_t mod, int type, void *data) 1332{ 1333 int error; 1334 1335 switch (type) { 1336 case MOD_LOAD: 1337 error = 0; 1338 attach_handlers(handlers); 1339 break; 1340 case MOD_UNLOAD: 1341 error = 0; 1342 detach_handlers(handlers; 1343 break; 1344 default: 1345 error = EINVAL; 1346 } 1347 return (error); 1348} 1349.Ed 1350When running as KLD, 1351.Fn mod_handler 1352registers/deregisters the module using 1353.Fn attach_handlers 1354and 1355.Fn detach_handlers , 1356respectively. 1357.Pp 1358Every module must contain at least 2 functions: one fingerprint 1359function and a protocol handler function. 1360.Bd -literal 1361#ifdef _KERNEL 1362static 1363#endif 1364int 1365fingerprint(struct libalias *la, struct ip *pip, struct alias_data *ah) 1366{ 1367 1368\&... 1369} 1370 1371#ifdef _KERNEL 1372static 1373#endif 1374int 1375protohandler(struct libalias *la, struct ip *pip, 1376 struct alias_data *ah) 1377{ 1378 1379\&... 1380} 1381.Ed 1382and they must accept exactly these input parameters. 1383.Ss PATCHING AN APPLICATION FOR USERLAND LIBALIAS MODULES 1384To add module support into an application that uses 1385.Nm , 1386the following simple steps can be followed. 1387.Bl -enum 1388.It 1389Find the main file of an application 1390(let us call it 1391.Pa main.c ) . 1392.It 1393Add this to the header section of 1394.Pa main.c , 1395if not already present: 1396.Pp 1397.Dl "#include <signal.h>" 1398.Pp 1399and this just after the header section: 1400.Pp 1401.Dl "static void signal_handler(int);" 1402.It 1403Add the following line to the init function of an application or, 1404if it does not have any init function, put it in 1405.Fn main : 1406.Pp 1407.Dl "signal(SIGHUP, signal_handler);" 1408.Pp 1409and place the 1410.Fn signal_handler 1411function somewhere in 1412.Pa main.c : 1413.Bd -literal -offset indent 1414static void 1415signal_handler(int sig) 1416{ 1417 1418 LibAliasRefreshModules(); 1419} 1420.Ed 1421.Pp 1422Otherwise, if an application already traps the 1423.Dv SIGHUP 1424signal, just add a call to 1425.Fn LibAliasRefreshModules 1426in the signal handler function. 1427.El 1428For example, to patch 1429.Xr natd 8 1430to use 1431.Nm 1432modules, just add the following line to 1433.Fn RefreshAddr "int sig __unused" : 1434.Pp 1435.Dl "LibAliasRefreshModules()" 1436.Pp 1437recompile and you are done. 1438.Ss LOGGING SUPPORT IN KERNEL LAND 1439When working as KLD, 1440.Nm 1441now has log support that 1442happens on a buffer allocated inside 1443.Vt "struct libalias" 1444(from 1445.Pa alias_local.h ) : 1446.Bd -literal 1447struct libalias { 1448 ... 1449 1450 /* log descriptor */ 1451#ifdef KERNEL_LOG 1452 char *logDesc; /* 1453 * ptr to an auto-malloced 1454 * memory buffer when libalias 1455 * works as kld 1456 */ 1457#else 1458 FILE *logDesc; /* 1459 * ptr to /var/log/alias.log 1460 * when libalias runs as a 1461 * userland lib 1462 */ 1463#endif 1464 1465 ... 1466} 1467.Ed 1468so all applications using 1469.Nm 1470will be able to handle their 1471own logs, if they want, accessing 1472.Va logDesc . 1473Moreover, every change to a log buffer is automatically added to 1474.Xr syslog 3 1475with the 1476.Dv LOG_SECURITY 1477facility and the 1478.Dv LOG_INFO 1479level. 1480