AirVantage / sbulb

UDP load balancer prototype using bcc (XDP/Bpf)
36 stars 9 forks source link

Handle TTL field from IP header. #15

Open sbernard31 opened 5 years ago

sbernard31 commented 5 years ago

The IP header contains a TTL field (see RFC 791):

This field indicates the maximum time the datagram is allowed to remain in the internet system. If this field contains the value zero, then the datagram must be destroyed. This field is modified in internet header processing. The time is measured in units of seconds, but since every module that processes a datagram must decrease the TTL by at least one even if it process the datagram in less than a second, the TTL must be thought of only as an upper bound on the time a datagram may exist. The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime.

The wikipedia explanation is maybe better :

The time-to-live value can be thought of as an upper bound on the time that an IP datagram can exist in an Internet system. The TTL field is set by the sender of the datagram, and reduced by every router on the route to its destination. If the TTL field reaches zero before the datagram arrives at its destination, then the datagram is discarded and an Internet Control Message Protocol (ICMP) error datagram (11 - Time Exceeded) is sent back to the sender. The purpose of the TTL field is to avoid a situation in which an undeliverable datagram keeps circulating on an Internet system, and such a system eventually becoming swamped by such "immortals".

We can consider sbulb as a router, so If we want to be a good internet citizen we should update TTL field and discard packet if needed. This part should be easy to implement.

About sending an ICMP packet, I don't know if this is easy maybe we can just let the Linux kernel do that ? (return XDP_PASS)

sbernard31 commented 5 years ago

It seems this is possible to send ICMP packet from XDP, katran seems to do that.

sbernard31 commented 4 years ago

some example about decrease TTL : https://github.com/torvalds/linux/blob/master/samples/bpf/xdp_fwd_kern.c

sbernard31 commented 4 years ago

Partially done by #33 but we don't send ICMP packet for now.