Multi-Homed Subnet Routing & RFC 1350 TFTP Kernel Delivery

Assigning a dummy gateway4 on your static USB-Ethernet bench adapter silently hijacks the host's default route and kills internet access, while misconfiguring tftpd-hpa paths or colliding zImage and Device Tree RAM addresses stalls U-Boot network boot.

20 minfree previewLinux 6.12C11glibc 2.39→ module 3 lab
What you'll learn
  • Configure a multi-homed Netplan/iproute2 host table keeping 0.0.0.0/0 on WAN while serving 192.168.10.0/24 on-link to the target board.
  • Trace RFC 1350 TFTP opcodes (RRQ=1, WRQ=2, DATA=3, ACK=4, ERROR=5), ephemeral UDP TIDs, and exact-512B-multiple 0-byte EOF packets.
  • Verify non-overlapping U-Boot DDR3 load addresses (0x80800000 zImage, 0x83000000 .dtb) before executing bootz.

Why Plugging In Your Board's Ethernet Cable Suddenly Breaks Host Internet

Watch what happens on almost every engineer's first embedded network-boot setup: the laptop or VM has working internet over wlan0 (or eth0 NAT), the engineer plugs a USB-Ethernet dongle (enx00e04c680102) straight into the i.MX6ULL board's RJ45 port, opens network settings, types IP 192.168.10.10, mask 255.255.255.0, and—out of habit—fills in Gateway: 192.168.10.1. Instantly, git fetch, apt update, and SSH to cloud servers hang completely!

Why? The Linux kernel Forwarding Information Base (FIB, inspected via ip route) matches destinations by longest prefix length first (/24 beats /0), and breaks ties between equal prefixes (0.0.0.0/0) by lowest metric. NetworkManager and systemd-networkd assign wired Ethernet metric 100 and Wi-Fi metric 600.

Adding a fake gateway on the wired bench dongle installs default via 192.168.10.1 metric 100, routing all world internet packets down a 1-meter cable connected only to your target board! Leaving gateway blank on the bench NIC preserves 192.168.10.0/24 scope link for U-Boot TFTP while keeping 0.0.0.0/0 cleanly on wlan0.

fig_m03_l02_a.svg — An isolated point-to-point or bench-switch subnet needs…

Figure 3.2a. An isolated point-to-point or bench-switch subnet needs only an on-link /24 prefix (ARP), never a default gateway.

mental model: A default gateway (0.0.0.0/0) is the highway on-ramp sign for *'All Other Cities'*. If you bolt a private cul-de-sac driveway (192.168.10.0/24) onto the back of your lab and hang an *'All Other Cities — Express Lane'* (metric 100) sign over that dead-end driveway, every delivery truck bound for New York drives straight into your workbench wall! Labelling the driveway strictly *'192.168.10.1–.254 Only'* (scope link) sends board traffic down the cable and everything else onto the real highway.

Where it stops working: If two NICs accidentally share the same IPv4 subnet (for instance corporate Wi-Fi is already 192.168.10.0/24 and you assign 192.168.10.10/24 to the bench dongle), even omitting gateway fails because both interfaces own /24 prefixes of equal length—pick a dedicated RFC 1918 bench subnet like 192.168.77.0/24 or 10.77.0.0/24!

definition (RFC 1350 Trivial File Transfer Protocol (TFTP) Lockstep Framing): Designed in 1981 (RFC 1350) to fit inside tiny 4 KiB boot ROMs and U-Boot without a TCP state machine, TFTP runs over UDP. Every packet starts with a 16-bit big-endian opcode: 1 = RRQ (Read Request to UDP/69 carrying NUL-terminated filename + "octet\0"), 2 = WRQ, 3 = DATA (2 B opcode + 2 B 1-based block number + 0..512 B payload), 4 = ACK (2 B opcode + 2 B block number), and 5 = ERROR. Because DATA headers carry no length field, UDP datagram payload length determines end-of-file: 512 B means more blocks follow, whereas 0..511 B terminates the transfer immediately.

ast_m03_l02.svg — Omit gateway on bench NICs, pass bare names to --secure…step 1/4
  1. Step 1. Assign a /24 address without a gateway to the wired bench interface and verify routing with ip route get 8.8.8.8 and ip route get 192.168.10.50.
  2. Step 2. Configure /etc/default/tftpd-hpa with --secure so U-Boot requests bare filenames ('zImage') confined inside /srv/tftp.
  3. Step 3. Copy compiled zImage and .dtb artifacts into /srv/tftp with world-readable 0644 permissions for the unprivileged tftp daemon.
  4. Step 4. Fetch zImage at 0x80800000 and Device Tree at 0x83000000 in U-Boot, then launch Linux 6.12 via bootz.

Figure 3.2b. Omit gateway on bench NICs, pass bare names to --secure tftpd, and separate DTB by 40 MiB.

RFC 1350 Wire Bytes, Exact-512B EOF Edge Case & DDR3 Load Map

Examine RFC 1350's wire framing closely because you will implement its verifier in the Module 3 studio. When U-Boot runs tftp 0x80800000 zImage, it sends RRQ [00 01 'z' 'I' 'm' 'a' 'g' 'e' 00 'o' 'c' 't' 'e' 't' 00] to 192.168.10.10:69. in.tftpd opens a fresh ephemeral socket (UDP/54321, the server Transfer Identifier TID) and sends DATA [00 03 00 01 <512B>] directly from port 54321 (leaving port 69 free for other boards; note host ufw/nftables needs nf_conntrack_tftp or bench interface allow-rules so ephemeral replies aren't dropped!).

What if board.dtb is exactly 32,768 bytes (64 * 512, size % 512 == 0)? Block 64 carries 512 bytes, which tells U-Boot more data follows! After U-Boot sends ACK 64, tftpd must transmit Block 65 ([00 03 00 41] with 0 payload bytes, 4 B total UDP payload) to signal EOF (total_blocks = size / 512 + 1!). Finally, on i.MX6ULL (512 MiB DDR3 at 0x80000000..0x9FFFFFFF), zImage at 0x80800000 (+8 MiB) decompresses Image (typically 12..24 MiB + .bss); placing .dtb at 0x83000000 (+48 MiB) guarantees a 40 MiB decompression buffer!

fig_m03_l02_b.svg — Exact-multiple-of-512 files require N/512 + 1 DATA…

Figure 3.2b. Exact-multiple-of-512 files require N/512 + 1 DATA blocks (a final 0-byte DATA packet) to close an RFC 1350 session cleanly.

Symptom on BenchUnderlying Network / Memory Root CauseDiagnostic CommandFix
Host internet dies when bench NIC connectsBench NIC configured a gateway, installing 0.0.0.0/0 metric 100ip route show & ip route get 8.8.8.8Remove gateway4/routes: default on static bench NIC
U-Boot prints TFTP error: 'File not found' (1)Passed /srv/tftp/zImage to --secure chrooted tftpd-hpajournalctl -u tftpd-hpaUse relative tftp 0x80800000 zImage + chmod 0644
U-Boot prints T T T T (timeouts)Host firewall (ufw) blocks UDP/69 or bench NIC lacks /24 IP`ss -ulnpgrep :69 & sudo tcpdump -ni enx0`sudo ufw allow in on enx0 to any port 69 proto udp
Starting kernel ... hangs silentlyLoaded .dtb at 0x80A00000, overwritten by zImage decompression!Check bdinfo & fdtaddr in U-BootLoad .dtb at 0x83000000 (>= 32 MiB above 0x80800000)
learner@ksa: ~/gl-e00/m03-l02
learner@ksa:~/gl-e00/m03-l02$ bat -H 5 -H 9 99-bench-dual-nic.yaml File: 99-bench-dual-nic.yaml    # /etc/netplan/99-bench-dual-nic.yaml (chmod 0600 root:root -> sudo netplan apply)    network:      version: 2      ethernets:      enp0s3:          # Adapter 1 (WAN / NAT): owns sole 0.0.0.0/0 default gateway          dhcp4: true        enx00e04c680102: # Adapter 2 (USB-Ethernet to i.MX6ULL): ON-LINK ONLY, NO routes/gateway4!          dhcp4: false        addresses:            - 192.168.10.10/24
  1. WAN interface acquires 0.0.0.0/0 via DHCP so git and apt remain online at all times.
  2. Omitting routes/gateway4 installs only '192.168.10.0/24 scope link', preventing dual-gateway blackholes.
in.tftpd(8) at a glance — GL-E00
in.tftpd(8)                 GL-E00 Quick Reference                 in.tftpd(8) NAME       in.tftpd, ip-route, bootz - RFC 1350 TFTP server, FIB routing, and       U-Boot ARMv7 boot SYNOPSIS       ip route show # Verify sole 0.0.0.0/0 WAN route ip route get       192.168.10.50 # Confirm on-link bench NIC selection sudo systemctl       status tftpd-hpa && ss -ulnp | grep :69        U-Boot COMMANDS (i.MX6ULL DDR3 @ 0x80000000) setenv ipaddr       192.168.10.50; setenv serverip 192.168.10.10 tftp 0x80800000 zImage       tftp 0x83000000 imx6ull-board.dtb bootz 0x80800000 - 0x83000000 Kernel Systems Academy                 Lesson 3.2                  in.tftpd(8) GL-E00 quick reference · full manual page: man 8 in.tftpd 

Simulating Kernel FIB Longest-Prefix Lookup and RFC 1350 Framing in C11

In verify.c, we build two deterministic verifiers in ISO C11. First, fib_lookup() implements exact Linux kernel IPv4 longest-prefix-length + lowest-metric tie-breaking, demonstrating mathematically how adding 0.0.0.0/0 metric 100 on enx0 steals 8.8.8.8 away from wlan0 (metric 600), while an on-link /24 (gateway == 0) keeps 8.8.8.8 on wlan0 and routes 192.168.10.50 (0xC0A80A32) straight to enx0.

Second, run_tftp_codec() encodes a real big-endian RFC 1350 RRQ + DATA/ACK transfer for a 1,024-byte (2 * 512) payload, verifying that 3 DATA blocks (512 + 512 + 0 bytes) and 3 ACK blocks execute in lockstep, alongside checking zImage/DTB DDR3 decompression clearance.

learner@ksa: ~/gl-e00/m03-l02
learner@ksa:~/gl-e00/m03-l02$ bat -H 20 -H 31 verify.c File: verify.c    #define _POSIX_C_SOURCE 200809L    #include <stdint.h>    #include <stdio.h>    #include <string.h>        typedef struct {        const char *dev;        uint32_t prefix;        int prefix_len;        uint32_t gateway;        int metric;    } fib_route_t;        static uint32_t mask_from_len(int plen) {        return (plen <= 0) ? 0U : (0xFFFFFFFFU << (32 - plen));    }        static const fib_route_t *fib_lookup(const fib_route_t *rt, size_t n, uint32_t dst_ip) {        const fib_route_t *best = NULL;      for (size_t i = 0; i < n; ++i) {            uint32_t m = mask_from_len(rt[i].prefix_len);            if ((dst_ip & m) != (rt[i].prefix & m)) continue;            if (!best || rt[i].prefix_len > best->prefix_len ||                (rt[i].prefix_len == best->prefix_len && rt[i].metric < best->metric)) {                best = &rt[i];            }        }        return best;    }      static int simulate_tftp_blocks(size_t file_bytes, size_t *last_payload_out) {        size_t blocks = (file_bytes / 512U) + 1U;        *last_payload_out = file_bytes % 512U;        unsigned char pkt[516];        for (size_t b = 1; b <= blocks; ++b) {            size_t pay = (b < blocks) ? 512U : *last_payload_out;            pkt[0] = 0x00U; pkt[1] = 0x03U; /* DATA opcode = 3 */            pkt[2] = (unsigned char)((b >> 8) & 0xFFU);            pkt[3] = (unsigned char)(b & 0xFFU);            uint16_t rx_op = ((uint16_t)pkt[0] << 8) | pkt[1];            uint16_t rx_blk = ((uint16_t)pkt[2] << 8) | pkt[3];            if (rx_op != 3U || rx_blk != (uint16_t)b) return -1;            if (b == blocks && pay >= 512U) return -2;        }        return (int)blocks;    }        static int check_ddr3_bootz_gap(uint32_t zimage_addr, uint32_t zimage_len, uint32_t dtb_addr) {        uint64_t decomp_end = (uint64_t)zimage_addr + (uint64_t)zimage_len * 4ULL;        return (zimage_addr >= 0x80000000U && (uint64_t)dtb_addr >= decomp_end) ? 0 : -1;    }        int main(void) {        uint32_t wan_dns = 0x08080808U;      /* 8.8.8.8 */        uint32_t board_ip = 0xC0A80A32U;     /* 192.168.10.50 */        uint32_t bench_sub = 0xC0A80A00U;    /* 192.168.10.0 */            fib_route_t broken_tbl[] = {            {"wlan0", 0x00000000U, 0, 0x0A000202U, 600},            {"enx0",  0x00000000U, 0, 0xC0A80A01U, 100}, /* Fatal bench default gw! */            {"enx0",  bench_sub,  24, 0x00000000U, 100},        };        fib_route_t clean_tbl[] = {            {"wlan0", 0x00000000U, 0, 0x0A000202U, 600},            {"enx0",  bench_sub,  24, 0x00000000U, 100}, /* On-link only */        };            const fib_route_t *b_wan = fib_lookup(broken_tbl, 3, wan_dns);        const fib_route_t *c_wan = fib_lookup(clean_tbl, 2, wan_dns);        const fib_route_t *c_brd = fib_lookup(clean_tbl, 2, board_ip);            size_t last_pay = 999U;        int blks_1024 = simulate_tftp_blocks(1024U, &last_pay);        int gap_ok = check_ddr3_bootz_gap(0x80800000U, 7U * 1024U * 1024U, 0x83000000U);        int gap_bad = check_ddr3_bootz_gap(0x80800000U, 7U * 1024U * 1024U, 0x81000000U);            printf("fib_routing: broken_8888=%s clean_8888=%s clean_board=%s\n",               b_wan->dev, c_wan->dev, c_brd->dev);        printf("tftp_1024B: blocks=%d final_eof_bytes=%zu\n", blks_1024, last_pay);        printf("ddr3_gap: dtb_0x83000000=%d dtb_0x81000000_collision=%d\n", gap_ok, gap_bad);            return (strcmp(b_wan->dev, "enx0") == 0 && strcmp(c_wan->dev, "wlan0") == 0 &&                strcmp(c_brd->dev, "enx0") == 0 && blks_1024 == 3 && last_pay == 0U &&                gap_ok == 0 && gap_bad == -1) ? 0 : 1;    }
  1. Longest prefix (/24 > /0) wins first; ties at /0 pick lowest metric (100 beats 600, hijacking WAN!).
  2. An exact 1,024-byte file requires (1024 / 512) + 1 = 3 DATA blocks, ending with a 0-byte EOF packet.

Verifying FIB Selection, 0-Byte TFTP EOF & DDR3 Separation

Confirm all three lines of output from ./verify: in broken_tbl, 8.8.8.8 routes mistakenly out enx0 (metric 100), whereas clean_tbl sends 8.8.8.8 to wlan0 and 192.168.10.50 to enx0. Meanwhile, the 1,024 B TFTP transfer produces blocks=3 with final_eof_bytes=0, and placing .dtb too close at 0x81000000 (+8 MiB above a 7 MiB zImage expanding ~4x to 28 MiB) triggers -1 collision detection.

learner@ksa: ~/gl-e00/m03-l02
learner@ksa:~/gl-e00/m03-l02gcc -std=c11 -Wall -Wextra -Werror verify.c -o verifylearner@ksa:~/gl-e00/m03-l02./verifyfib_routing: broken_8888=enx0 clean_8888=wlan0 clean_board=enx0tftp_1024B: blocks=3 final_eof_bytes=0ddr3_gap: dtb_0x83000000=0 dtb_0x81000000_collision=-1learner@ksa:~/gl-e00/m03-l02
strace — learner@ksa: ~/gl-e00/m03-l02
learner@ksa:~/gl-e00/m03-l02strace -e trace=write,exit_group ./verifywrite(1, "fib_routing: broken_8888=enx0 cl"..., 158) = 158exit_group(0)                           = ?+++ exited with 0 +++

Firewall Ephemeral UDP Drops & bootm vs bootz Confusion

With clean dual-NIC routing and TFTP delivering zImage and .dtb into DDR3 in under two seconds, the final piece of a frictionless driver-development bench is mounting the live root filesystem over NFS in Lesson 3.3.

Host Firewall Allows UDP/69 Yet TFTP Still Hangs at 0%:

  • Symptom: tcpdump shows RRQ arriving on UDP/69 and in.tftpd sending DATA block 1 from UDP/53104, yet ACK block 1 from the board is dropped by the host (ICMP port unreachable).
  • Root Cause: Because RFC 1350 switches from UDP/69 to an ephemeral server port (TID) on the first reply, a stateless firewall rule allowing only port 69 drops incoming ACK packets to 53104 unless nf_conntrack_tftp or an interface-level allow rule is present.
  • Fix: Trust the isolated dedicated bench interface (sudo ufw allow in on enx00e04c680102) or load the TFTP connection-tracking helper (sudo modprobe nf_conntrack_tftp).

Running U-Boot 'bootm' on an ARMv7 zImage:

  • Symptom: tftp 0x80800000 zImage succeeds, then bootm 0x80800000 - 0x83000000 fails with Wrong Image Format for bootm command / ERROR: can't get kernel image!.
  • Root Cause: bootm expects a legacy 64-byte mkimage uImage header (0x27051956 magic) or FIT image, whereas Kbuild make zImage produces a self-decompressing ARMv7 zImage (0x016F2818 magic at 0x24).
  • Fix: Use bootz 0x80800000 - 0x83000000 for ARMv7-A zImage (booti is for 64-bit ARM64 Image, and bootm is for uImage / FIT .itb images).

Guided Practice

Extend simulate_tftp_blocks() in verify.c to parse the RFC 1350 blksize option extension (RFC 2348, e.g., blksize=1468 negotiated by modern U-Boot to avoid IP fragmentation on 1500-byte Ethernet MTU) and verify how many blocks a 6,291,456-byte (6 MiB) zImage needs at 1468 B versus 512 B!

Independent Practice

Add a check to fib_lookup() that scans the entire routing table before lookup and returns an error if two distinct interfaces configure overlapping IPv4 subnets (for example both wlan0 and enx0 claiming 192.168.1.0/24).

Verification Checks

quiz · 1 of 3

Your workstation connects to internet Wi-Fi (wlan0, DHCP 192.168.1.44/24, metric 600) and a wired bench adapter (enx0, static 192.168.10.10/24). Why must enx0 NOT define gateway4: 192.168.10.1?

quiz · 2 of 3

Under RFC 1350 TFTP (512-byte standard blocks), how many DATA packets (opcode 3) are transmitted for a Device Tree blob that is exactly 32,768 bytes (64 * 512)?

quiz · 3 of 3

With TFTP_DIRECTORY="/srv/tftp" and TFTP_OPTIONS="--secure" in /etc/default/tftpd-hpa, which U-Boot command fetches /srv/tftp/zImage into DDR3?

Key takeaways

  • On a dual-NIC workstation, the WAN interface (Wi-Fi/LAN DHCP) owns the sole 0.0.0.0/0 default route while the static bench NIC (e.g., 192.168.10.10/24) configures NO default gateway, using on-link ARP only.
  • Setting a gateway on an isolated wired bench NIC installs a lower-metric 0.0.0.0/0 route (metric 100 wired vs 600 Wi-Fi) in the Linux kernel FIB, blackholing internet traffic onto the board cable.
  • RFC 1350 TFTP initiates via RRQ (opcode 1) on UDP port 69 and transfers 512-byte DATA blocks (opcode 3) in lockstep with ACK packets (opcode 4), signaling EOF with a final DATA block strictly under 512 bytes (0 bytes if image_size % 512 == 0).
  • In i.MX6ULL DDR3 RAM (base 0x80000000), U-Boot loads zImage at 0x80800000 and the flattened Device Tree (.dtb) at 0x83000000 (~40 MiB higher) so kernel self-decompression never overwrites the Device Tree.
Progress is saved on this device.

search — fzf

0/0 ───────────────────────────────────────────

keyboard shortcuts — less

/
search
f
focus mode
[
previous
]
next
?
help
Esc
close

figure