/*packet.yiaddr = req_align; */ if((req_align != server_config.server) #ifdef SUPPORT_DHCP_FRAG && (req_align != router_ip) && (1 == tmpNum))/*A36D02806, s60000658, 20060906*/ #else && (req_align != router_ip))/*A36D02806, s60000658, 20060906*/ #endif { packet.yiaddr = req_align; } else { #ifdef SUPPORT_DHCP_FRAG if(1 == inmaster) { packet.yiaddr = find_address2(0); } else #endif packet.yiaddr = find_address(0); } /*end of DHCP 网关会分配自己的维护IP porting by w44771 20060505*/ /* otherwise, find a free IP */ } else { #ifdef SUPPORT_DHCP_FRAG if(1 == inmaster) { packet.yiaddr = find_address2(0); }
/* send a DHCP OFFER to a DHCP DISCOVER */ int sendOffer(struct dhcpMessage *oldpacket) { struct dhcpMessage packet; struct dhcpOfferedAddr *lease = NULL; u_int32_t req_align, lease_time_align = server_config.lease; unsigned char *req, *lease_time; struct option_set *curr; struct in_addr addr; unsigned char mac[6]; u_int32_t reserved_ip; memcpy(mac, oldpacket->chaddr, 6); init_packet(&packet, oldpacket, DHCPOFFER); /* ADDME: if static, short circuit */ /* the client is in our lease/offered table */ if ((lease = find_lease_by_chaddr(oldpacket->chaddr)) && /* Make sure the IP is not already used on network */ !check_ip(lease->yiaddr)) { if (!lease_expired(lease)) lease_time_align = lease->expires - time(0); packet.yiaddr = lease->yiaddr; /* Find a reserved ip for this MAC */ } else if ( (reserved_ip = find_reserved_ip(mac)) != 0) { packet.yiaddr = htonl(reserved_ip); /* Or the client has a requested ip */ } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) && /* Don't look here (ugly hackish thing to do) */ memcpy(&req_align, req, 4) && /* check if the requested ip has been reserved */ check_reserved_ip(req_align, mac) && /* and the ip is in the lease range */ ntohl(req_align) >= ntohl(server_config.start) && ntohl(req_align) <= ntohl(server_config.end) && /* Check that this request ip is not on network */ //!check_ip(ntohl(req_align)) && /* the input parameter of check_ip() should be network order */ !check_ip(req_align) && /* modified by Max Ding, 07/07/2011 @TD #42 of WNR3500Lv2 */ /* and its not already taken/offered */ /* ADDME: check that its not a static lease */ ((!(lease = find_lease_by_yiaddr(req_align)) || /* or its taken, but expired */ /* ADDME: or maybe in here */ lease_expired(lease)))) { packet.yiaddr = req_align; /* otherwise, find a free IP */ /*ADDME: is it a static lease? */ } else { packet.yiaddr = find_address2(0, mac); /* try for an expired lease */ if (!packet.yiaddr) packet.yiaddr = find_address2(1, mac); } if(!packet.yiaddr) { LOG(LOG_WARNING, "no IP addresses to give -- OFFER abandoned"); return -1; } if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) { LOG(LOG_WARNING, "lease pool is full -- OFFER abandoned"); return -1; } if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) { memcpy(&lease_time_align, lease_time, 4); lease_time_align = ntohl(lease_time_align); if (lease_time_align > server_config.lease) lease_time_align = server_config.lease; } /* Make sure we aren't just using the lease time from the previous offer */ if (lease_time_align < server_config.min_lease) lease_time_align = server_config.lease; /* For guest network clients, set lease time to 30 minutes */ if (is_guest_network(mac)) { lease_time_align = GUEST_LEASE_TIME; DEBUG(LOG_INFO, "send OFFER to guest network client with lease time %d sec", GUEST_LEASE_TIME); } /* ADDME: end of short circuit */ add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align)); curr = server_config.options; while (curr) { if (curr->data[OPT_CODE] != DHCP_LEASE_TIME) add_option_string(packet.options, curr->data); curr = curr->next; } add_bootp_options(&packet); addr.s_addr = packet.yiaddr; LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr)); return send_packet(&packet, 0); }