|
|
@@ -23,7 +23,10 @@
|
|
|
* program_netkexec_main() then runs stop-and-wait: every datagram is acked
|
|
|
* with the next expected offset, so a lost or duplicated datagram costs one
|
|
|
* retransmit. Datagrams addressed to the broadcast IP are accepted too, so
|
|
|
- * the host can push without knowing whether the board is up yet.
|
|
|
+ * the host can push without knowing whether the board is up yet. While the
|
|
|
+ * receive owns the NIC it keeps answering ARP/ICMP, otherwise the host's
|
|
|
+ * neighbour entry expires in the middle of a long upload and the host drops
|
|
|
+ * every datagram while sendto() still succeeds.
|
|
|
*/
|
|
|
|
|
|
#include "install.h"
|
|
|
@@ -163,11 +166,15 @@ static int netkexec_poll_nd(const struct netdev *nd, int capture)
|
|
|
* ICMP echo requests for our IP (so the board can be pinged,
|
|
|
* and a host can resolve its MAC, without running a
|
|
|
* command). Until an address is configured there is nothing
|
|
|
- * to answer for. */
|
|
|
- if (net_is_configured()) {
|
|
|
- int rlen = net_build_reply(rxbuf, (unsigned int)len,
|
|
|
- replybuf,
|
|
|
- sizeof(replybuf));
|
|
|
+ * to answer for. Use the receiving NIC's MAC: this also
|
|
|
+ * runs for the active NIC when the management link is a
|
|
|
+ * different device. A driver's link-local default address
|
|
|
+ * (ASIX) is answerable even when the active NIC has none. */
|
|
|
+ if (net_is_configured() || nd->default_ip) {
|
|
|
+ int rlen = net_build_reply_dev(nd, rxbuf,
|
|
|
+ (unsigned int)len,
|
|
|
+ replybuf,
|
|
|
+ sizeof(replybuf));
|
|
|
if (rlen > 0)
|
|
|
nd->tx(replybuf, (unsigned int)rlen);
|
|
|
}
|
|
|
@@ -268,9 +275,9 @@ int netkexec_capture_frame(const unsigned char *frame, unsigned int len)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-static void send_ack(unsigned int next_offset, unsigned int status)
|
|
|
+static void send_ack(const struct netdev *nd, unsigned int next_offset,
|
|
|
+ unsigned int status)
|
|
|
{
|
|
|
- const struct netdev *nd = netdev_mgmt();
|
|
|
unsigned char src[4];
|
|
|
|
|
|
if (!nd)
|
|
|
@@ -295,24 +302,26 @@ static int netkexec_recv(unsigned int stage_base)
|
|
|
return -1;
|
|
|
kexec_total = x_size;
|
|
|
kexec_progress = 0;
|
|
|
- send_ack(0, ACK_CONTINUE); /* header ok, send from offset 0 */
|
|
|
+ send_ack(nd, 0, ACK_CONTINUE); /* header ok, send from offset 0 */
|
|
|
|
|
|
while (offset < x_size) {
|
|
|
const unsigned char *payload;
|
|
|
- unsigned int plen, port, doff, dlen;
|
|
|
+ unsigned int plen, doff, dlen;
|
|
|
+ unsigned char p_mac[6], p_ip[4];
|
|
|
+ unsigned int p_port;
|
|
|
int len, i;
|
|
|
|
|
|
/* A host that trickles one datagram at a time can keep the
|
|
|
- * per-packet deadline alive forever, holding the NIC (and the
|
|
|
- * background ARP/ICMP responder) hostage. Cap the whole
|
|
|
- * transfer as well. */
|
|
|
+ * per-packet deadline alive forever, holding the NIC (and
|
|
|
+ * the auto-detect loop) hostage. Cap the whole transfer as
|
|
|
+ * well. */
|
|
|
if ((int)(get_ticks_ms() - hard_deadline) > 0)
|
|
|
return -1;
|
|
|
|
|
|
if ((int)(get_ticks_ms() - deadline) > 0) {
|
|
|
if (++retries > 10)
|
|
|
return -1; /* host gave up */
|
|
|
- send_ack(offset, ACK_CONTINUE);
|
|
|
+ send_ack(nd, offset, ACK_CONTINUE);
|
|
|
deadline = get_ticks_ms() + 1000;
|
|
|
continue;
|
|
|
}
|
|
|
@@ -325,28 +334,48 @@ static int netkexec_recv(unsigned int stage_base)
|
|
|
process_sleep_ms(1);
|
|
|
continue;
|
|
|
}
|
|
|
+
|
|
|
+ /* We own the NIC for the whole transfer, so the idle loop's
|
|
|
+ * ARP/ICMP responder cannot run. Keep answering here: a
|
|
|
+ * multi-megabyte upload lasts long enough for the host's
|
|
|
+ * neighbour entry to go STALE, and once its probes go
|
|
|
+ * unanswered the host drops every datagram while sendto()
|
|
|
+ * still returns success (the transfer would stall at a
|
|
|
+ * random offset until the host gives up). */
|
|
|
if (!parse_udp(rxbuf, (unsigned int)len, &payload, &plen,
|
|
|
- peer_mac, peer_ip, &port)) {
|
|
|
- process_sleep_ms(1);
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (plen < 12 || rd32(payload) != X_MAGIC_DATA) {
|
|
|
+ p_mac, p_ip, &p_port) ||
|
|
|
+ plen < 12 || rd32(payload) != X_MAGIC_DATA) {
|
|
|
+ net_arp_input(rxbuf, (unsigned int)len);
|
|
|
+ if (net_is_configured() || nd->default_ip) {
|
|
|
+ int rlen = net_build_reply_dev(nd, rxbuf,
|
|
|
+ (unsigned int)len,
|
|
|
+ replybuf,
|
|
|
+ sizeof(replybuf));
|
|
|
+ if (rlen > 0)
|
|
|
+ nd->tx(replybuf, (unsigned int)rlen);
|
|
|
+ }
|
|
|
+ /* Yield after a frame that was not ours (ARP/ICMP or
|
|
|
+ * a stray datagram), so a broadcast storm cannot keep
|
|
|
+ * the BKL for the whole transfer. */
|
|
|
process_sleep_ms(1);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
doff = rd32(payload + 4);
|
|
|
dlen = rd32(payload + 8);
|
|
|
- if (dlen > NETKEXEC_DATA_MAX || plen < 12 + dlen) {
|
|
|
- process_sleep_ms(1);
|
|
|
+ if (dlen > NETKEXEC_DATA_MAX || plen < 12 + dlen)
|
|
|
continue;
|
|
|
- }
|
|
|
|
|
|
if (doff == offset) {
|
|
|
for (i = 0; i < (int)dlen; i++) {
|
|
|
stage[offset + i] = payload[12 + i];
|
|
|
sum += payload[12 + i];
|
|
|
}
|
|
|
+ for (i = 0; i < 6; i++)
|
|
|
+ peer_mac[i] = p_mac[i];
|
|
|
+ for (i = 0; i < 4; i++)
|
|
|
+ peer_ip[i] = p_ip[i];
|
|
|
+ peer_port = p_port;
|
|
|
offset += dlen;
|
|
|
kexec_progress = offset;
|
|
|
retries = 0;
|
|
|
@@ -355,14 +384,14 @@ static int netkexec_recv(unsigned int stage_base)
|
|
|
io_putchar('.');
|
|
|
}
|
|
|
if (offset < x_size)
|
|
|
- send_ack(offset, ACK_CONTINUE); /* also acks duplicates */
|
|
|
+ send_ack(nd, offset, ACK_CONTINUE); /* acks duplicates */
|
|
|
}
|
|
|
|
|
|
if (sum != x_csum) {
|
|
|
- send_ack(offset, ACK_BADSUM);
|
|
|
+ send_ack(nd, offset, ACK_BADSUM);
|
|
|
return -1;
|
|
|
}
|
|
|
- send_ack(x_size, ACK_DONE);
|
|
|
+ send_ack(nd, x_size, ACK_DONE);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -454,7 +483,7 @@ void program_netkexec_main(void)
|
|
|
if (x_pack_size < ROOTFS_HDR_SIZE ||
|
|
|
rh->pack_bytes > x_pack_size - ROOTFS_HDR_SIZE) {
|
|
|
io_putstr("netinstall: bad rootfs image\n");
|
|
|
- send_ack(x_size, ACK_INSTALL_FAIL);
|
|
|
+ send_ack(netdev_mgmt(), x_size, ACK_INSTALL_FAIL);
|
|
|
kexec_stage_free();
|
|
|
netdev_release();
|
|
|
kexec_busy = 0;
|
|
|
@@ -465,13 +494,13 @@ void program_netkexec_main(void)
|
|
|
rh, x_pack_size);
|
|
|
if (r != 0) {
|
|
|
io_putstr("netinstall: failed; disk not updated\n");
|
|
|
- send_ack(x_size, ACK_INSTALL_FAIL);
|
|
|
+ send_ack(netdev_mgmt(), x_size, ACK_INSTALL_FAIL);
|
|
|
kexec_stage_free();
|
|
|
netdev_release();
|
|
|
kexec_busy = 0;
|
|
|
return;
|
|
|
}
|
|
|
- send_ack(x_size, ACK_INSTALLED);
|
|
|
+ send_ack(netdev_mgmt(), x_size, ACK_INSTALLED);
|
|
|
io_putstr("netinstall: persisted to ");
|
|
|
io_putstr(x_install_target);
|
|
|
io_putstr(" -> jumping\n");
|