Lines Matching refs:req

336 static bool requested_broadcast(DHCPRequest *req) {
337 assert(req);
339 return req->message->flags & htobe16(0x8000);
343 DHCPRequest *req, DHCPPacket *packet,
349 assert(req);
350 assert(req->max_optlen);
351 assert(optoffset <= req->max_optlen);
354 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &optoffset, 0,
360 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &optoffset, 0,
388 if (req->message->giaddr) {
389 destination = req->message->giaddr;
392 } else if (req->message->ciaddr && type != DHCP_NAK)
393 destination = req->message->ciaddr;
398 else if (requested_broadcast(req) || type == DHCP_NAK)
412 DHCPRequest *req) {
422 packet = malloc0(sizeof(DHCPPacket) + req->max_optlen);
427 be32toh(req->message->xid), type, ARPHRD_ETHER,
428 req->max_optlen, &optoffset);
432 packet->dhcp.flags = req->message->flags;
433 packet->dhcp.giaddr = req->message->giaddr;
434 memcpy(&packet->dhcp.chaddr, &req->message->chaddr, ETH_ALEN);
443 static int server_send_offer(sd_dhcp_server *server, DHCPRequest *req,
450 r = server_message_init(server, &packet, DHCP_OFFER, &offset, req);
456 lease_time = htobe32(req->lifetime);
457 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
463 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
468 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
473 r = dhcp_server_send_packet(server, req, packet, DHCP_OFFER, offset);
480 static int server_send_ack(sd_dhcp_server *server, DHCPRequest *req,
487 r = server_message_init(server, &packet, DHCP_ACK, &offset, req);
493 lease_time = htobe32(req->lifetime);
494 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
500 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
505 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
512 &packet->dhcp, req->max_optlen, &offset, 0,
521 &packet->dhcp, req->max_optlen, &offset, 0,
530 &packet->dhcp, req->max_optlen, &offset, 0,
537 r = dhcp_server_send_packet(server, req, packet, DHCP_ACK, offset);
544 static int server_send_nak(sd_dhcp_server *server, DHCPRequest *req) {
549 r = server_message_init(server, &packet, DHCP_NAK, &offset, req);
553 return dhcp_server_send_packet(server, req, packet, DHCP_NAK, offset);
592 DHCPRequest *req = userdata;
594 assert(req);
599 req->lifetime = be32toh(*(be32_t*)option);
604 req->requested_ip = *(be32_t*)option;
609 req->server_id = *(be32_t*)option;
620 free(req->client_id.data);
621 req->client_id.data = data;
622 req->client_id.length = len;
628 req->max_optlen = be16toh(*(be16_t*)option) -
637 static void dhcp_request_free(DHCPRequest *req) {
638 if (!req)
641 free(req->client_id.data);
642 free(req);
648 static int ensure_sane_request(sd_dhcp_server *server, DHCPRequest *req, DHCPMessage *message) {
649 assert(req);
652 req->message = message;
656 if (!req->client_id.data) {
666 req->client_id.length = ETH_ALEN + 1;
667 req->client_id.data = data;
670 if (req->max_optlen < DHCP_MIN_OPTIONS_SIZE)
671 req->max_optlen = DHCP_MIN_OPTIONS_SIZE;
673 if (req->lifetime <= 0)
674 req->lifetime = MAX(1ULL, server->default_lease_time);
676 if (server->max_lease_time > 0 && req->lifetime > server->max_lease_time)
677 req->lifetime = server->max_lease_time;
699 _cleanup_dhcp_request_free_ DHCPRequest *req = NULL;
712 req = new0(DHCPRequest, 1);
713 if (!req)
716 type = dhcp_option_parse(message, length, parse_request, req, &error_message);
720 r = ensure_sane_request(server, req, message);
726 &req->client_id);
735 be32toh(req->message->xid));
754 client_id_hash_func(&req->client_id, &state);
771 r = server_send_offer(server, req, address);
779 be32toh(req->message->xid));
786 log_dhcp_server(server, "DECLINE (0x%x): %s", be32toh(req->message->xid), strna(error_message));
799 if (req->server_id) {
801 be32toh(req->message->xid));
804 if (req->server_id != server->address)
808 if (req->message->ciaddr)
812 if (!req->requested_ip)
817 address = req->requested_ip;
818 } else if (req->requested_ip) {
820 be32toh(req->message->xid));
823 if (req->message->ciaddr)
828 address = req->requested_ip;
832 be32toh(req->message->xid));
835 if (!req->message->ciaddr)
839 address = req->message->ciaddr;
853 lease->address = req->requested_ip;
854 lease->client_id.data = memdup(req->client_id.data,
855 req->client_id.length);
860 lease->client_id.length = req->client_id.length;
861 memcpy(&lease->chaddr, &req->message->chaddr,
863 lease->gateway = req->message->giaddr;
876 lease->expiration = req->lifetime * USEC_PER_SEC + time_now;
878 r = server_send_ack(server, req, address);
890 be32toh(req->message->xid));
899 r = server_send_nak(server, req);
907 be32toh(req->message->xid));
919 be32toh(req->message->xid));
924 if (existing_lease->address != req->message->ciaddr)
927 pool_offset = get_pool_offset(server, req->message->ciaddr);