Esempio n. 1
0
    def _request(self, request_id, client_request):
        dhcp = self._ongoing.get(request_id, None)
        if (not dhcp):
            dhcp = ServerResponse(client_request.intf, server=self)

        result = dhcp.ack(client_request)
        # not responding per rfc 2131
        if (result == DHCP.DROP):
            self._ongoing.pop(request_id, None)
            response_mtype, record = None, None

        # sending NAK per rfc 2131
        elif (result == DHCP.NAK):
            client_request.handout_ip = INADDR_ANY
            response_mtype, record = DHCP.NAK, None

        # responding with ACK
        elif (result):
            client_request.handout_ip = result
            response_mtype = DHCP.ACK
            record = (DHCP.LEASED, fast_time(), client_request.mac)

        # protecting return on invalid dhcp types | NOTE: validate if this even does anything. :)
        else:
            response_mtype, record = None, None

        return response_mtype, record
Esempio n. 2
0
    def _discover(self, request_id, client_request):
        dhcp = ServerResponse(client_request.sock.name, server=self)
        self._ongoing[request_id] = dhcp

        client_request.handout_ip = dhcp.offer(client_request)

        return DHCP.OFFER, (DHCP.OFFERED, fast_time(), client_request.mac)
Esempio n. 3
0
    def _request(self, request_id, client_request):
        dhcp = self._ongoing.get(request_id, None)
        if (not dhcp):
            dhcp = ServerResponse(client_request.sock.name, server=self)

        request_mtype, handout_ip = dhcp.ack(client_request)
        # not responding per rfc 2131
        if (request_mtype is DHCP.DROP):
            record = None

        # sending NAK per rfc 2131
        elif (request_mtype is DHCP.NAK):
            client_request.handout_ip = INADDR_ANY
            record = None

        # responding with ACK
        elif (request_mtype in [DHCP.ACK, DHCP.RENEWING, DHCP.REBINDING]):
            client_request.handout_ip = handout_ip
            record = (DHCP.LEASED, fast_time(), client_request.mac)

        # protecting return on invalid dhcp types | TODO: validate if this even does anything. :)
        else:
            record = None

        # removing the request from ongoing since we are sending the final message and do
        # not need any objects from the request instance anymore.
        self._ongoing.pop(request_id, None)

        return request_mtype, record
Esempio n. 4
0
    def _release(self, ip_address, mac_address):
        dhcp = ServerResponse(server=self)

        # if mac/ lease mac match, the lease will be removed from the table
        if dhcp.release(ip_address, mac_address):
            self.leases.modify(ip_address) # pylint: disable=no-member

        else:
            Log.warning(f'Client {mac_address} attempted invalid release.')
Esempio n. 5
0
    def _release(self, ip_address, mac_address):
        dhcp = ServerResponse(server=self)

        # if mac/ lease mac match, the lease will be removed from the table
        if dhcp.release(ip_address, mac_address):
            self.leases.modify(ip_address, None)  # pylint: disable=no-member