This function will always return the packet aliasing engine to the same initial state. The LibAliasSetAddress function is normally called afterwards, and any desired changes from the default mode bits listed above require a call to LibAliasSetMode.
It is mandatory that this function be called at the beginning of a program prior to any packet handling.
PKT_ALIAS_LOG |
| Enables logging into /var/log/alias.log. Each time an aliasing link is created or deleted, the log file is appended with the current number of ICMP, TCP and UDP links. Mainly useful for debugging when the log file is viewed continuously with tail(1). |
PKT_ALIAS_DENY_INCOMING |
| If this mode bit is set, all incoming packets associated with new TCP connections or new UDP transactions will be marked for being ignored ( LibAliasIn returns PKT_ALIAS_IGNORED code) by the calling program. Response packets to connections or transactions initiated from the packet aliasing host or local network will be unaffected. This mode bit is useful for implementing a one-way firewall. |
PKT_ALIAS_SAME_PORTS |
| If this mode bit is set, the packet aliasing engine will attempt to leave the alias port numbers unchanged from the actual local port numbers. This can be done as long as the quintuple (proto, alias addr, alias port, remote addr, remote port) is unique. If a conflict exists, a new aliasing port number is chosen even if this mode bit is set. |
PKT_ALIAS_USE_SOCKETS |
| This bit should be set when the packet aliasing host originates network traffic as well as forwards it. When the packet aliasing host is waiting for a connection from an unknown host address or unknown port number (e.g. an FTP data connection), this mode bit specifies that a socket be allocated as a place holder to prevent port conflicts. Once a connection is established, usually within a minute or so, the socket is closed. |
PKT_ALIAS_UNREGISTERED_ONLY |
| If this mode bit is set, traffic on the local network which does not originate from unregistered address spaces will be ignored. Standard Class A, B and C unregistered addresses are:
10.0.0.0-> 10.255.255.255 (Class A subnet)
172.16.0.0 -> 172.31.255.255 (Class B subnets)
192.168.0.0 -> 192.168.255.255 (Class C subnets)
This option is useful in the case that packet aliasing host has both registered and unregistered subnets on different interfaces. The registered subnet is fully accessible to the outside world, so traffic from it does not need to be passed through the packet aliasing engine. |
PKT_ALIAS_RESET_ON_ADDR_CHANGE |
| When this mode bit is set and LibAliasSetAddress is called to change the aliasing address, the internal link table of the packet aliasing engine will be cleared. This operating mode is useful for ppp(8) links where the interface address can sometimes change or remain the same between dial-up attempts. If this mode bit is not set, the link table will never be reset in the event of an address change. |
PKT_ALIAS_PUNCH_FW |
| This option makes libalias punch holes in an ipfirewall(4) based firewall for FTP/IRC DCC connections. The holes punched are bound by from/to IP address and port; it will not be possible to use a hole for another connection. A hole is removed when the connection that uses it dies. To cater to unexpected death of a program using libalias (e.g. kill -9), changing the state of the flag will clear the entire firewall range allocated for holes. This will also happen on the initial call to LibAliasSetFWBase. This call must happen prior to setting this flag. |
PKT_ALIAS_REVERSE |
| This option makes libalias reverse the way it handles incoming and outgoing packets, allowing it to be fed with data that passes through the internal interface rather than the external one. |
PKT_ALIAS_PROXY_ONLY |
| This option tells libalias to obey transparent proxy rules only. Normal packet aliasing is not performed. See LibAliasProxyRule below for details. |
|
PORT AND ADDRESS REDIRECTION
The functions described in this section allow machines on the local network to be accessible in some degree to new incoming connections from the external network. Individual ports can be re-mapped or static network address translations can be designated. struct alias_link *
.Fo LibAliasRedirectPort "struct libalias *" "struct in_addr local_addr" "u_short local_port" "struct in_addr remote_addr" "u_short remote_port" "struct in_addr alias_addr" "u_short alias_port" "u_char proto"
.Fc
This function specifies that traffic from a given remote address/port to
an alias address/port be redirected to a specified local address/port.
The parameter
proto
can be either
IPPROTO_TCP
or
IPPROTO_UDP,
as defined in
.In netinet/in.h .
If
local_addr
or
alias_addr
is zero, this indicates that the packet aliasing address as established
by
LibAliasSetAddress
is to be used.
Even if
LibAliasSetAddress
is called to change the address after
LibAliasRedirectPort
is called, a zero reference will track this change.
If the link is further set up to operate for a load sharing, then
local_addr
and
local_port
are ignored, and are selected dynamically from the server pool, as described in
LibAliasAddServer
below.
If
remote_addr
is zero, this indicates to redirect packets from any remote address.
Likewise, if
remote_port
is zero, this indicates to redirect packets originating from any remote
port number.
Almost always, the remote port specification will be zero, but non-zero
remote addresses can sometimes be useful for firewalling.
If two calls to
LibAliasRedirectPort
overlap in their address/port specifications, then the most recent call
will have precedence.
This function returns a pointer which can subsequently be used by
LibAliasRedirectDelete.
If
NULL
is returned, then the function call did not complete successfully.
All port numbers should be in network address byte order, so it is necessary
to use
htons(3)
to convert these parameters from internally readable numbers to network byte
order.
Addresses are also in network byte order, which is implicit in the use of the
struct in_addr
data type.
struct alias_link *
.Fo LibAliasRedirectAddr "struct libalias *" "struct in_addr local_addr" "struct in_addr alias_addr"
.Fc
This function designates that all incoming traffic to
alias_addr
be redirected to
local_addr.
Similarly, all outgoing traffic from
local_addr
is aliased to
alias_addr.
If
local_addr
or
alias_addr
is zero, this indicates that the packet aliasing address as established by
LibAliasSetAddress
is to be used.
Even if
LibAliasSetAddress
is called to change the address after
LibAliasRedirectAddr
is called, a zero reference will track this change.
If the link is further set up to operate for a load sharing, then
local_addr
is ignored, and is selected dynamically from the server pool, as described in
LibAliasAddServer
below.
If subsequent calls to
LibAliasRedirectAddr
use the same aliasing address, all new incoming traffic to this aliasing
address will be redirected to the local address made in the last function
call.
New traffic generated by any of the local machines, designated in the
several function calls, will be aliased to the same address.
Consider the following example:
LibAliasRedirectAddr(la, inet_aton("192.168.0.2"),
inet_aton("141.221.254.101"));
LibAliasRedirectAddr(la, inet_aton("192.168.0.3"),
inet_aton("141.221.254.101"));
LibAliasRedirectAddr(la, inet_aton("192.168.0.4"),
inet_aton("141.221.254.101"));
Any outgoing connections such as telnet(1) or ftp(1) from 192.168.0.2, 192.168.0.3 and 192.168.0.4 will appear to come from 141.221.254.101. Any incoming connections to 141.221.254.101 will be directed to 192.168.0.4.
Any calls to LibAliasRedirectPort will have precedence over address mappings designated by LibAliasRedirectAddr.
This function returns a pointer which can subsequently be used by LibAliasRedirectDelete. If NULL is returned, then the function call did not complete successfully.
int
.Fo LibAliasAddServer "struct libalias *" "struct alias_link *link" "struct in_addr addr" "u_short port"
.Fc
This function sets the
link
up for Load Sharing using IP Network Address Translation (RFC 2391, LSNAT).
LSNAT operates as follows.
A client attempts to access a server by using the server virtual address.
The LSNAT router transparently redirects the request to one of the hosts
in server pool, selected using a real-time load sharing algorithm.
Multiple sessions may be initiated from the same client, and each session
could be directed to a different host based on load balance across server
pool hosts at the time.
If load share is desired for just a few specific services, the configuration
on LSNAT could be defined to restrict load share for just the services
desired.
Currently, only the simplest selection algorithm is implemented, where a
host is selected on a round-robin basis only, without regard to load on
the host.
First, the
link
is created by either
LibAliasRedirectPort
or
LibAliasRedirectAddr.
Then,
LibAliasAddServer
is called multiple times to add entries to the
link s
server pool.
For links created with
LibAliasRedirectAddr,
the
port
argument is ignored and could have any value, e.g. htons(~0).
This function returns 0 on success, -1 otherwise.
int LibAliasRedirectDynamic "struct libalias *" "struct alias_link *link"
This function marks the specified static redirect rule entered by
LibAliasRedirectPort
as dynamic.
This can be used to e.g. dynamically redirect a single TCP connection,
after which the rule is removed.
Only fully specified links can be made dynamic.
(See the
STATIC AND DYNAMIC LINKS
and
PARTIALLY SPECIFIED ALIASING LINKS
sections below for a definition of static vs. dynamic,
and partially vs. fully specified links.)
This function returns 0 on success, -1 otherwise.
void LibAliasRedirectDelete "struct libalias *" "struct alias_link *link"
This function will delete a specific static redirect rule entered by
LibAliasRedirectPort
or
LibAliasRedirectAddr.
The parameter
link
is the pointer returned by either of the redirection functions.
If an invalid pointer is passed to
LibAliasRedirectDelete,
then a program crash or unpredictable operation could result, so it is
necessary to be careful using this function.
int LibAliasProxyRule "struct libalias *" "const char *cmd"
The passed
cmd
string consists of one or more pairs of words.
The first word in each pair is a token and the second is the value that
should be applied for that token.
Tokens and their argument types are as follows:
This function is usually used to redirect outgoing connections for internal machines that are not permitted certain types of internet access, or to restrict access to certain external machines.