int udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
uint32_t source_nip, int source_port,
- uint32_t dest_nip, int dest_port) FAST_FUNC;
+ uint32_t dest_nip, int dest_port,
+ int send_flags
+) FAST_FUNC;
void udhcp_sp_setup(void) FAST_FUNC;
void udhcp_sp_fd_set(struct pollfd *pfds, int extra_fd) FAST_FUNC;
opt_ptr = add_d6_client_options(opt_ptr);
bb_error_msg("sending %s", "renew");
- if (server_ipv6)
+ if (server_ipv6) {
return d6_send_kernel_packet(
&packet, (opt_ptr - (uint8_t*) &packet),
our_cur_ipv6, CLIENT_PORT6,
server_ipv6, SERVER_PORT6,
client_config.ifindex
+ /* TODO? send_flags: MSG_DONTROUTE (see IPv4 code for reason why) */
);
+ }
return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
}
static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server)
{
- if (server)
+ if (server) {
+ /* Without MSG_DONTROUTE, the packet was seen routed over
+ * _other interface_ if server ID is bogus (example: 1.1.1.1).
+ */
return udhcp_send_kernel_packet(packet,
ciaddr, CLIENT_PORT,
- server, SERVER_PORT);
+ server, SERVER_PORT,
+ /*send_flags: "to hosts only on directly connected networks" */ MSG_DONTROUTE
+ );
+ }
return raw_bcast_from_client_config_ifindex(packet, ciaddr);
}
static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requested)
{
struct dhcp_packet packet;
- struct in_addr addr;
+ struct in_addr temp_addr;
/*
* RFC 2131 4.3.2 DHCPREQUEST message
*/
add_client_options(&packet);
- addr.s_addr = requested;
- bb_error_msg("sending select for %s", inet_ntoa(addr));
+ temp_addr.s_addr = requested;
+ bb_error_msg("sending select for %s", inet_ntoa(temp_addr));
return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
}
static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
{
struct dhcp_packet packet;
+ struct in_addr temp_addr;
/*
* RFC 2131 4.3.2 DHCPREQUEST message
*/
add_client_options(&packet);
- bb_error_msg("sending %s", "renew");
+ temp_addr.s_addr = server;
+ bb_error_msg("sending renew to %s", inet_ntoa(temp_addr));
return bcast_or_ucast(&packet, ciaddr, server);
}
* Anyway, it does recover by eventually failing through
* into INIT_SELECTING state.
*/
- send_renew(xid, server_addr, requested_ip);
- timeout >>= 1;
- continue;
+ if (send_renew(xid, server_addr, requested_ip) >= 0) {
+ timeout >>= 1;
+ continue;
+ }
+ /* else: error sending.
+ * example: ENETUNREACH seen with server
+ * which gave us bogus server ID 1.1.1.1
+ * which wasn't reachable (and probably did not exist).
+ */
}
- /* Timed out, enter rebinding state */
+ /* Timed out or error, enter rebinding state */
log1("entering rebinding state");
state = REBINDING;
/* fall right through */
/* Let the kernel do all the work for packet generation */
int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
uint32_t source_nip, int source_port,
- uint32_t dest_nip, int dest_port)
+ uint32_t dest_nip, int dest_port,
+ int send_flags)
{
struct sockaddr_in sa;
unsigned padding;
padding = DHCP_OPTIONS_BUFSIZE - 1 - udhcp_end_option(dhcp_pkt->options);
if (padding > DHCP_SIZE - 300)
padding = DHCP_SIZE - 300;
- result = safe_write(fd, dhcp_pkt, DHCP_SIZE - padding);
- msg = "write";
+ result = send(fd, dhcp_pkt, DHCP_SIZE - padding, send_flags);
+ msg = "send";
ret_close:
close(fd);
if (result < 0) {