Changeset 2491 for trunk


Ignore:
Timestamp:
Sep 28, 2009, 10:53:22 PM (15 years ago)
Author:
oremanj
Message:

[invirt-dhcp] Improve standards compliance

Provide a server-identifier option containing our IP address, as
is required by several DHCP clients including gPXE (used for the
Debathena network install CD) and Windows.

Reuse the existing DHCP socket in a bindtodevice - sendto - restore
global binding sequence, instead of creating a new socket for each
reply, in order to keep replies coming from port 67. This is required
by the standard, some client programs, and all DHCP forwarders.

Location:
trunk/packages/invirt-dhcp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/invirt-dhcp/debian/changelog

    r2362 r2491  
     1invirt-dhcp (0.0.3) unstable; urgency=low
     2
     3  * Detect local IP address and pass it as the DHCP server-identifier
     4    option, as required by several DHCP clients.
     5  * Reuse the existing DHCP socket for replies by binding it to the
     6    client VM interface and then restoring its global binding after
     7    sendto(); this keeps replies coming from port 67, as is standard.
     8
     9 -- Joshua Oreman <oremanj@mit.edu>  Mon, 28 Sep 2009 22:46:41 -0400
     10
    111invirt-dhcp (0.0.2) unstable; urgency=low
    212
  • trunk/packages/invirt-dhcp/invirt-dhcpserver

    r2362 r2491  
    163163        intf = self.backend.find_interface(packet)
    164164        if intf:
    165             out_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    166             out_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1)
    167             out_socket.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, intf)
    168             #out_socket.bind((ip, self.listen_port))
    169             ret = out_socket.sendto(packet.EncodePacket(), (To,self.emit_port))
    170             out_socket.close()
     165            self.dhcp_socket.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, intf)
     166            ret = self.dhcp_socket.sendto(packet.EncodePacket(), (To,self.emit_port))
     167            self.dhcp_socket.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, '')
    171168            return ret
    172169        else:
     
    258255                "client_listen_port":68,
    259256                "listen_address":"0.0.0.0"}
     257
     258    myip = socket.gethostbyname(socket.gethostname())
     259    if not myip:
     260        print "invirt-dhcpserver: cannot determine local IP address by looking up %s" % socket.gethostname()
     261        sys.exit(1)
     262   
     263    dhcp_options['server_identifier'] = myip
     264
    260265    backend = DhcpBackend()
    261266    server = DhcpServer(backend, options)
Note: See TracChangeset for help on using the changeset viewer.