Proxying broadcasts? SOLVED

Nejc Škoberne nejc at skoberne.net
Thu Aug 28 19:29:09 UTC 2008


Hey,

> The simple answer is no: if you want subnet-local broadcast traffic to
> be received, then your DB servers and your clients need to be on the
> same subnet.  Routers are designed and required to not propagate
> broadcast traffic, although you could switch to doing bridging rather
> than routing.  Or, you could set up Sybase's SQL.INI to list all of the
> databases you care about, if I recall correctly...

Actually, a little perl script (running daemonized on the firewall) for
each of the USERS networks solved my problem. It is somewhat ugly, but it
works.

-------------------------------------------------------------------------
#!/usr/local/bin/perl -w
# syproxy - Sybase broadcast proxy

use File::Basename;
use Fcntl qw(LOCK_EX LOCK_NB);
use IO::Socket;
use strict;
use Net::RawIP;

### Configuration
# Destination IP (broadcast) of the servers network
my $DESTINATION = "192.168.1.255";
# Sybase port
my $PORT = 2638;
# Broadcast address of the USERS network
my $LISTEN = "192.168.3.255";
# Packet length
my $MAXLEN = 1024;

my $sport;
my $source;
my $ipaddr;
my $data;
my $progname = basename($0);

# Selflock
open(SELFLOCK, "<$0") or die("Couldn't open $0: $!\n");
flock(SELFLOCK, LOCK_EX | LOCK_NB) or die("Aborting: another $progname is already running\n");
chdir('/');

# Double-fork to avoid leaving a zombie process behind:
exit if (fork());
exit if (fork());
sleep 1 until getppid() == 1;

# Create the socket
my $recv_socket = IO::Socket::INET->new(
 Proto          => 'udp',
 LocalPort      => $PORT,
 LocalAddr      => $LISTEN,
 Broadcast      => 1,
 ReuseAddr      => 1
) or die "Creating socket: $!\n";

while (1) {
        # Wait for packets
        $recv_socket->recv($data, $MAXLEN);

        # Get the sender address
        ($sport, $ipaddr) = unpack_sockaddr_in($recv_socket->peername);
        $source = inet_ntoa($ipaddr);

        # Construct the packet
        my $send_socket = new Net::RawIP({udp =>{}});
        $send_socket->set({ip => {saddr => $source , daddr => $DESTINATION,
                           tos => 22}, udp  => {source => $sport,
                           dest => $PORT, data => $data }});

        # Send the spoofed packet
        $send_socket->send;
}
-------------------------------------------------------------------------

Thanks,
Nejc


More information about the freebsd-questions mailing list