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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.