UDP with IP Spoofing (om_udpspoof)

This module sends log messages as UDP datagrams to the address and port specified and allows the source address in the UDP packet to be spoofed to make the packets appear as if they were sent from another host. This is particularly useful in situations where log data needs to be forwarded to another server and the server uses the client address to identify the data source. With IP spoofing the UDP packets will contain the IP address of the originating client that produced the message instead of the forwarding server.

This module is very similar to the om_udp module and can be used as a drop-in replacement. The SpoofAddress configuration directive can be used to set the address if necessary. The UDP datagram will be sent with the local IP address if the IP address to be spoofed is invalid. The source port in the UDP datagram will be set to the port number of the local connection (the port number is not spoofed).

The network input modules (im_udp, im_tcp, and im_ssl) all set the $MessageSourceAddress field, and this value will be used when sending the UDP datagrams (unless SpoofAddress is explicitly set to something else). This allows logs to be collected over reliable and secure transports (like SSL), while the om_udpspoof module is only used for forwarding to the destination server that requires spoofed UDP input.

Configuration

The om_udpspoof module accepts the following directives in addition to the common module directives. The Host directive is required.

Required directives

The following directive is required for the module to start.

Host

Set this directive to the IP address or hostname of the remote host to connect to. If you specify a hostname, the module resolves it to an IP address on each new connection.

The module uses port 514 by default. To connect to a different port, add the port number after the IP address or hostname, separated by a colon (host:port).

Enclose IPv6 addresses in square brackets ([addr]:port). For example, [2001:0db8:85a3:0:0:8a2e:0370:7334]:514.

You can set this directive more than once to allow failover between different hosts or ports. List IPv4 and IPv6 addresses separately if needed. If you use a DNS name, make sure it resolves to fewer than 16 addresses or CNAMEs to prevent problems with DNS response size limits.

If you configure more than one Host directive, or a DNS lookup returns multiple addresses, the module connects to the first reachable address and stays connected until it stops or the connection drops. It does not detect DNS changes on its own.

If a connection attempt fails, the module tries the next address in the current Host directive, then moves to the next Host directive, if any. Once it checks all Host directives, it starts over from the first and keeps trying until it connects.

Optional directives

LocalPort

Set this directive to the local port number to use for the connection, for example to satisfy a firewall rule that expects traffic from a known port. If you do not set this directive, the module uses a random high port number, which a firewall may block.

Attempts to bind to LocalPort may fail because of the required TIME-WAIT delay in closing connections. When this happens, the module writes Address already in use to the NXLog Agent log file. If it persists, it can degrade network performance.

MTU

This directive can be used to specify the maximum transfer size of the IP data fragments. If this value exceeds the MTU size of the sending interface, an error may occur and the packet be dropped. The default MTU value is 1500.

OutputType

See the OutputType directive in the list of common module directives. If this directive is not specified, the default is Dgram.

Reconnect

Set this directive to the number of seconds to wait between reconnection attempts. If you do not set this directive, the module starts with a 1 second interval and doubles it after each failed attempt, resetting to 1 second once it reconnects successfully.

Setting this directive on multiple systems can cause them to send reconnection requests to the same destination at the same time, potentially overloading it. This can also cause NXLog Agent to consume unusually high system resources or become unresponsive.

ReconnectOnData

Set this directive to TRUE to have the module reconnect to the remote host only when it has data to send, instead of keeping the connection open at all times. The default is FALSE; the module always keeps a connection open with the remote host.

SockBufSize

This optional directive sets the socket buffer size (SO_SNDBUF) to the value specified. If this is not set, the operating system default is used.

SpoofAddress

The module rewrites the IP address depending on the value of this directive:

Directive not specified

The value of the $MessageSourceAddress field is used as the SpoofAddress.

Constant literal value

The value can be a string or ipaddr type. For example, SpoofAddress  '10.0.0.42' or SpoofAddress  10.0.0.42.

Expression

The expression specified will be evaluated for each message to be sent. The expression can be a field name or any other value that evaluates to a string or an ipaddr type. For example, SpoofAddress  $MessageSourceAddress.

On Windows 7, Vista, and XP (SP2/SP3), UDP datagrams cannot be sent with a non-existing source address. See the Microsoft documentation on Limitations on Raw Sockets for details.

TcpSendStallDetect

Set this directive to TRUE to monitor for pipeline backpressure by logging a warning whenever the module cannot send data to the destination. The module writes the following message to the NXLog Agent log file:

TCP send buffer full for <instance_name> - write blocked

The default is FALSE; the module does not check for send stalls.

Procedures

The following procedures are exported by om_udpspoof.

reconnect();

Force a reconnection. This can be used from a Schedule block to periodically reconnect to the server.

The reconnect() procedure must be used with caution. If configured, it can attempt to reconnect after every event sent, potentially overloading the destination system.

Examples

Example 1. Log forwarding with IP address spoofing

The im_tcp module will accept log messages via TCP and will set the $MessageSourceAddress field for each event. This value will be used by om_udpspoof to set the UDP source address when sending the data to logserver via UDP.

nxlog.conf
<Input tcp>
    Module      im_tcp
    ListenAddr  0.0.0.0:1514
</Input>

<Output udpspoof>
    Module      om_udpspoof
    Host        logserver.example.com:1514
</Output>

<Route tcp_to_udpspoof>
    Path        tcp => udpspoof
</Route>
Example 2. Log forwarding with a spoofed IP address from multiple sources

This configuration accepts log messages via TCP and UDP and also reads logs from a file. Both im_tcp and im_udp set the $MessageSourceAddress field for incoming messages, and in both cases this is used to set $sourceaddr. The im_file module instance is configured to set the $sourceaddr field to 10.1.2.3 for all log messages. Finally, the om_udpspoof output module instance is configured to read the value of the $sourceaddr field for spoofing the UDP source address.

nxlog.conf
<Input tcp>
    Module          im_tcp
    ListenAddr      0.0.0.0:1514
    Exec            $sourceaddr = $MessageSourceAddress;
</Input>

<Input udp>
    Module          im_udp
    ListenAddr      0.0.0.0:1514
    Exec            $sourceaddr = $MessageSourceAddress;
</Input>

<Input file>
    Module          im_file
    File            '/var/log/myapp.log'
    Exec            $sourceaddr = 10.1.2.3;
</Input>

<Output udpspoof>
    Module          om_udpspoof
    Host            10.0.0.1:1514
    SpoofAddress    $sourceaddr
</Output>

<Route all_to_file>
    Path            tcp, udp, file => udpspoof
</Route>