udhcp: added some FIXMEs; code shrink. -49 bytes
This commit is contained in:
networking/udhcp
@ -79,8 +79,18 @@ static void add_param_req_option(struct dhcpMessage *packet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int raw_bcast_from_client_config_ifindex(struct dhcpMessage *packet)
|
||||||
|
{
|
||||||
|
return udhcp_send_raw_packet(packet,
|
||||||
|
/*src*/ INADDR_ANY, CLIENT_PORT,
|
||||||
|
/*dst*/ INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR,
|
||||||
|
client_config.ifindex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if ENABLE_FEATURE_UDHCPC_ARPING
|
#if ENABLE_FEATURE_UDHCPC_ARPING
|
||||||
/* Unicast a DHCP decline message */
|
/* Broadcast a DHCP decline message */
|
||||||
|
//FIXME: maybe it should be unicast?
|
||||||
int FAST_FUNC send_decline(uint32_t xid, uint32_t server, uint32_t requested)
|
int FAST_FUNC send_decline(uint32_t xid, uint32_t server, uint32_t requested)
|
||||||
{
|
{
|
||||||
struct dhcpMessage packet;
|
struct dhcpMessage packet;
|
||||||
@ -92,8 +102,7 @@ int FAST_FUNC send_decline(uint32_t xid, uint32_t server, uint32_t requested)
|
|||||||
|
|
||||||
bb_info_msg("Sending decline...");
|
bb_info_msg("Sending decline...");
|
||||||
|
|
||||||
return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
return raw_bcast_from_client_config_ifindex(&packet);
|
||||||
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -114,13 +123,13 @@ int FAST_FUNC send_discover(uint32_t xid, uint32_t requested)
|
|||||||
add_param_req_option(&packet);
|
add_param_req_option(&packet);
|
||||||
|
|
||||||
bb_info_msg("Sending discover...");
|
bb_info_msg("Sending discover...");
|
||||||
return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
return raw_bcast_from_client_config_ifindex(&packet);
|
||||||
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Broadcasts a DHCP request message */
|
/* Broadcasts a DHCP request message */
|
||||||
int FAST_FUNC send_selecting(uint32_t xid, uint32_t server, uint32_t requested)
|
//FIXME: maybe it should be unicast?
|
||||||
|
int FAST_FUNC send_select(uint32_t xid, uint32_t server, uint32_t requested)
|
||||||
{
|
{
|
||||||
struct dhcpMessage packet;
|
struct dhcpMessage packet;
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
@ -134,8 +143,7 @@ int FAST_FUNC send_selecting(uint32_t xid, uint32_t server, uint32_t requested)
|
|||||||
|
|
||||||
addr.s_addr = requested;
|
addr.s_addr = requested;
|
||||||
bb_info_msg("Sending select for %s...", inet_ntoa(addr));
|
bb_info_msg("Sending select for %s...", inet_ntoa(addr));
|
||||||
return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
return raw_bcast_from_client_config_ifindex(&packet);
|
||||||
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -151,10 +159,11 @@ int FAST_FUNC send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
|
|||||||
add_param_req_option(&packet);
|
add_param_req_option(&packet);
|
||||||
bb_info_msg("Sending renew...");
|
bb_info_msg("Sending renew...");
|
||||||
if (server)
|
if (server)
|
||||||
return udhcp_send_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
|
return udhcp_send_kernel_packet(&packet,
|
||||||
|
ciaddr, CLIENT_PORT,
|
||||||
|
server, SERVER_PORT);
|
||||||
|
|
||||||
return udhcp_send_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
return raw_bcast_from_client_config_ifindex(&packet);
|
||||||
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,8 +66,9 @@ int udhcp_recv_kernel_packet(struct dhcpMessage *packet, int fd) FAST_FUNC;
|
|||||||
|
|
||||||
int udhcp_send_raw_packet(struct dhcpMessage *payload,
|
int udhcp_send_raw_packet(struct dhcpMessage *payload,
|
||||||
uint32_t source_ip, int source_port,
|
uint32_t source_ip, int source_port,
|
||||||
uint32_t dest_ip, int dest_port,
|
uint32_t dest_ip, int dest_port, const uint8_t *dest_arp,
|
||||||
const uint8_t *dest_arp, int ifindex) FAST_FUNC;
|
int ifindex) FAST_FUNC;
|
||||||
|
|
||||||
int udhcp_send_kernel_packet(struct dhcpMessage *payload,
|
int udhcp_send_kernel_packet(struct dhcpMessage *payload,
|
||||||
uint32_t source_ip, int source_port,
|
uint32_t source_ip, int source_port,
|
||||||
uint32_t dest_ip, int dest_port) FAST_FUNC;
|
uint32_t dest_ip, int dest_port) FAST_FUNC;
|
||||||
|
@ -389,7 +389,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (state == RENEW_REQUESTED) /* unicast */
|
if (state == RENEW_REQUESTED) /* unicast */
|
||||||
send_renew(xid, server_addr, requested_ip);
|
send_renew(xid, server_addr, requested_ip);
|
||||||
else /* broadcast */
|
else /* broadcast */
|
||||||
send_selecting(xid, server_addr, requested_ip);
|
send_select(xid, server_addr, requested_ip);
|
||||||
|
|
||||||
timeout = discover_timeout;
|
timeout = discover_timeout;
|
||||||
packet_num++;
|
packet_num++;
|
||||||
@ -430,7 +430,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
* try to find DHCP server using broadcast */
|
* try to find DHCP server using broadcast */
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
/* send a request packet */
|
/* send a request packet */
|
||||||
send_renew(xid, 0, requested_ip); /* broadcast */
|
send_renew(xid, 0 /* INADDR_ANY*/, requested_ip); /* broadcast */
|
||||||
timeout >>= 1;
|
timeout >>= 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -529,6 +529,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (lease_seconds < 10) /* and not too small */
|
if (lease_seconds < 10) /* and not too small */
|
||||||
lease_seconds = 10;
|
lease_seconds = 10;
|
||||||
}
|
}
|
||||||
|
//FIXME: why do we check ARP only after we've got DHCPACK?
|
||||||
|
//Shouldn't we do it immediately after DHCPOFFER?
|
||||||
#if ENABLE_FEATURE_UDHCPC_ARPING
|
#if ENABLE_FEATURE_UDHCPC_ARPING
|
||||||
if (opt & OPT_a) {
|
if (opt & OPT_a) {
|
||||||
if (!arpping(packet.yiaddr,
|
if (!arpping(packet.yiaddr,
|
||||||
@ -538,6 +540,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
) {
|
) {
|
||||||
bb_info_msg("offered address is in use "
|
bb_info_msg("offered address is in use "
|
||||||
"(got ARP reply), declining");
|
"(got ARP reply), declining");
|
||||||
|
//NB: not clear whether it should be unicast or bcast.
|
||||||
|
//Currently it is a bcast. Why?
|
||||||
send_decline(xid, server_addr, packet.yiaddr);
|
send_decline(xid, server_addr, packet.yiaddr);
|
||||||
|
|
||||||
if (state != REQUESTING)
|
if (state != REQUESTING)
|
||||||
|
@ -39,7 +39,7 @@ struct client_config_t {
|
|||||||
|
|
||||||
uint32_t random_xid(void) FAST_FUNC;
|
uint32_t random_xid(void) FAST_FUNC;
|
||||||
int send_discover(uint32_t xid, uint32_t requested) FAST_FUNC;
|
int send_discover(uint32_t xid, uint32_t requested) FAST_FUNC;
|
||||||
int send_selecting(uint32_t xid, uint32_t server, uint32_t requested) FAST_FUNC;
|
int send_select(uint32_t xid, uint32_t server, uint32_t requested) FAST_FUNC;
|
||||||
#if ENABLE_FEATURE_UDHCPC_ARPING
|
#if ENABLE_FEATURE_UDHCPC_ARPING
|
||||||
int send_decline(uint32_t xid, uint32_t server, uint32_t requested) FAST_FUNC;
|
int send_decline(uint32_t xid, uint32_t server, uint32_t requested) FAST_FUNC;
|
||||||
#endif
|
#endif
|
||||||
|
@ -118,7 +118,8 @@ uint16_t FAST_FUNC udhcp_checksum(void *addr, int count)
|
|||||||
/* Construct a ip/udp header for a packet, send packet */
|
/* Construct a ip/udp header for a packet, send packet */
|
||||||
int FAST_FUNC udhcp_send_raw_packet(struct dhcpMessage *payload,
|
int FAST_FUNC udhcp_send_raw_packet(struct dhcpMessage *payload,
|
||||||
uint32_t source_ip, int source_port,
|
uint32_t source_ip, int source_port,
|
||||||
uint32_t dest_ip, int dest_port, const uint8_t *dest_arp, int ifindex)
|
uint32_t dest_ip, int dest_port, const uint8_t *dest_arp,
|
||||||
|
int ifindex)
|
||||||
{
|
{
|
||||||
struct sockaddr_ll dest;
|
struct sockaddr_ll dest;
|
||||||
struct udp_dhcp_packet packet;
|
struct udp_dhcp_packet packet;
|
||||||
|
@ -59,8 +59,10 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas
|
|||||||
ciaddr = payload->yiaddr;
|
ciaddr = payload->yiaddr;
|
||||||
chaddr = payload->chaddr;
|
chaddr = payload->chaddr;
|
||||||
}
|
}
|
||||||
return udhcp_send_raw_packet(payload, server_config.server, SERVER_PORT,
|
return udhcp_send_raw_packet(payload,
|
||||||
ciaddr, CLIENT_PORT, chaddr, server_config.ifindex);
|
/*src*/ server_config.server, SERVER_PORT,
|
||||||
|
/*dst*/ ciaddr, CLIENT_PORT, chaddr,
|
||||||
|
server_config.ifindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user