Lines Matching refs:req
455 DHCPRequest *req, DHCPPacket *packet, in dhcp_server_send_packet() argument
462 assert(req); in dhcp_server_send_packet()
463 assert(req->max_optlen > 0); in dhcp_server_send_packet()
464 assert(req->message); in dhcp_server_send_packet()
465 assert(optoffset <= req->max_optlen); in dhcp_server_send_packet()
468 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &optoffset, 0, in dhcp_server_send_packet()
474 if (req->agent_info_option) { in dhcp_server_send_packet()
475 size_t opt_full_length = *(req->agent_info_option + 1) + 2; in dhcp_server_send_packet()
477 if (optoffset + opt_full_length < req->max_optlen) { in dhcp_server_send_packet()
478 … memcpy(packet->dhcp.options + optoffset, req->agent_info_option, opt_full_length); in dhcp_server_send_packet()
483 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &optoffset, 0, in dhcp_server_send_packet()
511 if (req->message->giaddr != 0) { in dhcp_server_send_packet()
512 destination = req->message->giaddr; in dhcp_server_send_packet()
516 } else if (req->message->ciaddr != 0 && type != DHCP_NAK) in dhcp_server_send_packet()
517 destination = req->message->ciaddr; in dhcp_server_send_packet()
519 bool l2_broadcast = requested_broadcast(req->message) || type == DHCP_NAK; in dhcp_server_send_packet()
520 return dhcp_server_send(server, req->message->hlen, req->message->chaddr, in dhcp_server_send_packet()
529 DHCPRequest *req) { in server_message_init() argument
539 assert(req); in server_message_init()
541 packet = malloc0(sizeof(DHCPPacket) + req->max_optlen); in server_message_init()
546 be32toh(req->message->xid), type, in server_message_init()
547 req->message->htype, req->message->hlen, req->message->chaddr, in server_message_init()
548 req->max_optlen, &optoffset); in server_message_init()
552 packet->dhcp.flags = req->message->flags; in server_message_init()
553 packet->dhcp.giaddr = req->message->giaddr; in server_message_init()
563 DHCPRequest *req, in server_send_offer_or_ack() argument
574 assert(req); in server_send_offer_or_ack()
577 r = server_message_init(server, &packet, type, &offset, req); in server_send_offer_or_ack()
584 lease_time = htobe32(req->lifetime); in server_send_offer_or_ack()
585 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0, in server_send_offer_or_ack()
591 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0, in server_send_offer_or_ack()
597 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0, in server_send_offer_or_ack()
607 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0, in server_send_offer_or_ack()
615 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0, in server_send_offer_or_ack()
637 &packet->dhcp, req->max_optlen, &offset, 0, in server_send_offer_or_ack()
648 &packet->dhcp, req->max_optlen, &offset, 0, in server_send_offer_or_ack()
657 r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0, in server_send_offer_or_ack()
665 &packet->dhcp, req->max_optlen, &offset, 0, in server_send_offer_or_ack()
672 return dhcp_server_send_packet(server, req, packet, type, offset); in server_send_offer_or_ack()
675 static int server_send_nak_or_ignore(sd_dhcp_server *server, bool init_reboot, DHCPRequest *req) { in server_send_nak_or_ignore() argument
687 r = server_message_init(server, &packet, DHCP_NAK, &offset, req); in server_send_nak_or_ignore()
691 r = dhcp_server_send_packet(server, req, packet, DHCP_NAK, offset); in server_send_nak_or_ignore()
695 log_dhcp_server(server, "NAK (0x%x)", be32toh(req->message->xid)); in server_send_nak_or_ignore()
736 DHCPRequest *req = userdata; in parse_request() local
738 assert(req); in parse_request()
743 req->lifetime = unaligned_read_be32(option); in parse_request()
748 memcpy(&req->requested_ip, option, sizeof(be32_t)); in parse_request()
753 memcpy(&req->server_id, option, sizeof(be32_t)); in parse_request()
764 free_and_replace(req->client_id.data, data); in parse_request()
765 req->client_id.length = len; in parse_request()
772 req->max_optlen = unaligned_read_be16(option) - sizeof(DHCPPacket); in parse_request()
776 req->agent_info_option = (uint8_t*)option - 2; in parse_request()
784 static DHCPRequest* dhcp_request_free(DHCPRequest *req) { in dhcp_request_free() argument
785 if (!req) in dhcp_request_free()
788 free(req->client_id.data); in dhcp_request_free()
789 return mfree(req); in dhcp_request_free()
794 static int ensure_sane_request(sd_dhcp_server *server, DHCPRequest *req, DHCPMessage *message) { in ensure_sane_request() argument
795 assert(req); in ensure_sane_request()
798 req->message = message; in ensure_sane_request()
804 if (!req->client_id.data) { in ensure_sane_request()
817 req->client_id.length = message->hlen + 1; in ensure_sane_request()
818 req->client_id.data = data; in ensure_sane_request()
826 if (!req->client_id.data) in ensure_sane_request()
829 … if (req->client_id.length <= 1 || req->client_id.length > sizeof(message->chaddr) + 1) in ensure_sane_request()
832 if (req->client_id.data[0] != 0x01) in ensure_sane_request()
835 message->hlen = req->client_id.length - 1; in ensure_sane_request()
836 memcpy(message->chaddr, req->client_id.data + 1, message->hlen); in ensure_sane_request()
839 if (req->max_optlen < DHCP_MIN_OPTIONS_SIZE) in ensure_sane_request()
840 req->max_optlen = DHCP_MIN_OPTIONS_SIZE; in ensure_sane_request()
842 if (req->lifetime <= 0) in ensure_sane_request()
843 req->lifetime = MAX(1ULL, server->default_lease_time); in ensure_sane_request()
845 if (server->max_lease_time > 0 && req->lifetime > server->max_lease_time) in ensure_sane_request()
846 req->lifetime = server->max_lease_time; in ensure_sane_request()
982 static int server_ack_request(sd_dhcp_server *server, DHCPRequest *req, DHCPLease *existing_lease, … in server_ack_request() argument
987 assert(req); in server_ack_request()
994 expiration = usec_add(req->lifetime * USEC_PER_SEC, time_now); in server_ack_request()
1004 r = prepare_new_lease(&lease, address, &req->client_id, in server_ack_request()
1005 req->message->htype, req->message->hlen, in server_ack_request()
1006 req->message->chaddr, req->message->giaddr, expiration); in server_ack_request()
1023 r = server_send_offer_or_ack(server, req, address, DHCP_ACK); in server_ack_request()
1027 log_dhcp_server(server, "ACK (0x%x)", be32toh(req->message->xid)); in server_ack_request()
1069 _cleanup_(dhcp_request_freep) DHCPRequest *req = NULL; in dhcp_server_handle_message()
1080 req = new0(DHCPRequest, 1); in dhcp_server_handle_message()
1081 if (!req) in dhcp_server_handle_message()
1084 type = dhcp_option_parse(message, length, parse_request, req, &error_message); in dhcp_server_handle_message()
1088 r = ensure_sane_request(server, req, message); in dhcp_server_handle_message()
1096 existing_lease = hashmap_get(server->bound_leases_by_client_id, &req->client_id); in dhcp_server_handle_message()
1097 static_lease = hashmap_get(server->static_leases_by_client_id, &req->client_id); in dhcp_server_handle_message()
1104 log_dhcp_server(server, "DISCOVER (0x%x)", be32toh(req->message->xid)); in dhcp_server_handle_message()
1124 client_id_hash_func(&req->client_id, &state); in dhcp_server_handle_message()
1142 r = server_send_offer_or_ack(server, req, address, DHCP_OFFER); in dhcp_server_handle_message()
1147 log_dhcp_server(server, "OFFER (0x%x)", be32toh(req->message->xid)); in dhcp_server_handle_message()
1151 … log_dhcp_server(server, "DECLINE (0x%x): %s", be32toh(req->message->xid), strna(error_message)); in dhcp_server_handle_message()
1163 if (req->server_id != 0) { in dhcp_server_handle_message()
1165 be32toh(req->message->xid)); in dhcp_server_handle_message()
1168 if (req->server_id != server->address) in dhcp_server_handle_message()
1172 if (req->message->ciaddr != 0) in dhcp_server_handle_message()
1176 if (req->requested_ip == 0) in dhcp_server_handle_message()
1181 address = req->requested_ip; in dhcp_server_handle_message()
1182 } else if (req->requested_ip != 0) { in dhcp_server_handle_message()
1184 be32toh(req->message->xid)); in dhcp_server_handle_message()
1187 if (req->message->ciaddr != 0) in dhcp_server_handle_message()
1192 address = req->requested_ip; in dhcp_server_handle_message()
1196 be32toh(req->message->xid)); in dhcp_server_handle_message()
1199 if (req->message->ciaddr == 0) in dhcp_server_handle_message()
1203 address = req->message->ciaddr; in dhcp_server_handle_message()
1215 return server_send_nak_or_ignore(server, init_reboot, req); in dhcp_server_handle_message()
1217 return server_ack_request(server, req, existing_lease, address); in dhcp_server_handle_message()
1225 return server_send_nak_or_ignore(server, init_reboot, req); in dhcp_server_handle_message()
1227 return server_ack_request(server, req, existing_lease, address); in dhcp_server_handle_message()
1230 return server_send_nak_or_ignore(server, init_reboot, req); in dhcp_server_handle_message()
1235 be32toh(req->message->xid)); in dhcp_server_handle_message()
1240 if (existing_lease->address != req->message->ciaddr) in dhcp_server_handle_message()