BIND like listen and query-source

BIND like listen and query-source

Post by William St » Thu, 09 Sep 2004 07:58:10


Wondering how one would implement two features similar to how BIND DNS does
(say UDP only to keep it simple.)
1) BIND can listen on "Any" IP and port or specific IP(s) and port. Is one
listener thread per IP/port combo the way to handle this? Or could you keep
it simplier and listen on "Any" IP and just ignore anything on one of the
non-listener IPs?

2) You can also select the query-source port for internally generated
queries. This (I would think) would also require you have a listener on the
query-source IP/port to listen for the reply. Would that just be another
listener thread on the query port if that port was already not one of the
listeners in #1?

So how to handle query-source listener when server is already listening on
all IPs at that port? How are they handling that?

Example:
Config1:
listen Any port 53
query-source 192.168.0.2 port 53

Config2:
listen 192.168.0.2 53
listen 192.168.0.3 53
query-source 192.168.0.2 53

Config3:
listen Any port 53
query-source Any

Hope that makes some sense. TIA
--
William Stacey
 
 
 

BIND like listen and query-source

Post by Phil Frisb » Thu, 09 Sep 2004 08:14:07


A socket can be bound to "any" or to one IP address. So if you want to choose
only certain IPs to listen on then you will need one socket for each IP/port
combination. Whether you use threads or select() is up to you.


I don't know enough about how BIND uses that option to answer that question, sorry.

--
Phil Frisbie, Jr.
Hawk Software
http://www.yqcomputer.com/

 
 
 

BIND like listen and query-source

Post by William St » Thu, 09 Sep 2004 12:12:35

Thanks Phil. So what happens when first UDP socket binds to
192.168.0.221:53 and another socket binds to Any:53 and they both block on
rec() ? Which one gets the datagram? TIA

--
William Stacey




does
one
keep
the
choose
IP/port
the
another
the
question, sorry.
 
 
 

BIND like listen and query-source

Post by Phil Frisb » Fri, 10 Sep 2004 01:33:12


The only way the second bind() would succeed would be if the first socket had
the SO_REUSEADDR socket option set first. Then both sockets would get a copy of
all UDP packets sent to port 53.

--
Phil Frisbie, Jr.
Hawk Software
http://www.yqcomputer.com/
 
 
 

BIND like listen and query-source

Post by William St » Fri, 10 Sep 2004 12:13:19

Named (which is BIND exe) binds to Any for internal queries/replies and all
local IPs (by default) and listens on those local IPs.
named.exe:4020 UDP 0.0.0.0:53 *:*
named.exe:4020 UDP 127.0.0.1:53 *:*
named.exe:4020 UDP 192.168.0.221:53 *:*
named.exe:4020 UDP 192.168.50.1:53 *:*
named.exe:4020 UDP 192.168.138.1:53 *:*

I have a sample that shows I can bind to any:52 and 192.168.0.221:52 without
reuse - so what gives?
NetDns.exe:1768 UDP 0.0.0.0:52 *:*
NetDns.exe:1768 UDP 192.168.0.221:52 *:*

The following is .Net c# code sample. I don't think they call reuse
internally to allow this as it is a socket option you need to set:

IPEndPoint ep1 = new IPEndPoint(IPAddress.Parse("192.168.0.221"), 52);
IPEndPoint ep2 = new IPEndPoint(IPAddress.Any, 52);

Socket s = new Socket(ep1.Address.AddressFamily,
SocketType.Dgram,
ProtocolType.Udp);
Socket s2 = new Socket(ep2.Address.AddressFamily,
SocketType.Dgram,
ProtocolType.Udp);

s.Bind(ep1); // works
s2.Bind(ep2); // works

Confused. TIA
--
William Stacey




on
had
copy of