You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/42-xdp-loadbalancer/README.md
+33-2Lines changed: 33 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -470,9 +470,20 @@ You can test the setup by starting HTTP servers on the two backend namespaces (`
470
470
471
471
Start servers on `h2` and `h3`:
472
472
473
+
**Important**: The HTTP servers must bind to `0.0.0.0` so they listen on all local addresses in the namespace and can accept connections arriving via the load balancer. The forwarded HTTP requests will use the load balancer's virtual IP and port in the `Host` header (for example, `Host: 10.0.0.10:8000`), which may differ from the backend's own IP address; for this tutorial we use simple HTTP servers that accept such requests without enforcing strict `Host` header checks.
474
+
475
+
**Option 1**: Using the provided simple HTTP server (recommended):
476
+
477
+
```sh
478
+
sudo ip netns exec h2 python3 simple_http_server.py &
479
+
sudo ip netns exec h3 python3 simple_http_server.py &
480
+
```
481
+
482
+
**Option 2**: Using Python's built-in http.server with explicit binding:
The load balancer will distribute traffic to the backends (`h2` and `h3`) based on the hashing function.
485
496
497
+
> **Note**: If you experience hanging requests with `curl`, ensure the backend HTTP servers are bound to `0.0.0.0` and accept requests with any Host header. The XDP load balancer operates at Layer 3/4 (IP/TCP) and does not modify HTTP headers, so the Host header in requests will still show `10.0.0.10:8000` even though packets are forwarded to the backend IPs (10.0.0.2 or 10.0.0.3).
498
+
486
499
### Monitoring with `bpf_printk`
487
500
488
501
You can monitor the load balancer's activity by checking the `bpf_printk` logs. The BPF program prints diagnostic messages whenever a packet is processed. You can view these logs using:
@@ -507,6 +520,24 @@ Example output:
507
520
508
521
### Debugging Issues
509
522
523
+
#### Curl Requests Hanging
524
+
525
+
If `curl` requests to the load balancer hang and never complete, the most likely cause is that the backend HTTP servers are rejecting requests with mismatched Host headers.
526
+
527
+
**Problem**: When you run `curl 10.0.0.10:8000`, the HTTP request includes a Host header set to `10.0.0.10:8000`. The XDP load balancer forwards the packet at Layer 3/4 (IP/TCP) to a backend server (10.0.0.2 or 10.0.0.3), but the HTTP headers remain unchanged. If the backend HTTP server validates the Host header and expects it to match its own IP address, it may reject or drop the request.
528
+
529
+
**Solution**: Ensure backend HTTP servers bind to `0.0.0.0` and accept requests with any Host header:
530
+
- Use `python3 simple_http_server.py` (provided in this directory), or
531
+
- Use `python3 -m http.server --bind 0.0.0.0`
532
+
533
+
**Verification**: Check the backend server logs to see if requests are being received. You can also use `tcpdump` in the backend namespace to verify packets are arriving:
534
+
535
+
```sh
536
+
sudo ip netns exec h2 tcpdump -i veth2 -n port 8000
537
+
```
538
+
539
+
#### XDP Packet Forwarding Issues
540
+
510
541
Some systems may experience packet loss or failure to forward packets due to issues similar to those described in this [blog post](https://fedepaol.github.io/blog/2023/09/11/xdp-ate-my-packets-and-how-i-debugged-it/). You can debug these issues using `bpftrace` to trace XDP errors:
0 commit comments