mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
To add timestamp to output, push the timestamp when packet was processed from kernel as part of the rtt-event. Also keep track of minimum encountered RTT for each flow in kernel, and also push that as part of the RTT-event. Additionally, avoid pushing RTT messages at all if no flow-state information can be found (due to ex. being deleted from egress side), as no valid min-RTT can then be given. Furthermore, no longer delete flow-information once seeing the FIN-flag on egress in order to keep useful flow-state around for RTT-messages longer. Due to the FIN-handshake process, it is sufficient if the ingress program deletes the flow-state upon seeing FIN. However, still delete flow-state from either ingress or egress upon seeing RST flag, as RST does not have a handshake process allowing for delayed deletion. While minimum RTT could also be tracked from the userspace process, userspace is not aware of when the flow is closed so would have to add additional logic to keep track of minimum RTT for each flow and periodically clean them up. Furthermore, keeping RTT statistics in the flow-state map is useful for implementing future features, such as an RTT-based sampling interval. It would also be useful in case pping is changed to no longer have a long-running userspace process printing out all the calculated RTTs, but instead simply occasionally looks up the RTT from the flow-state map. Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
62 lines
1.3 KiB
C
62 lines
1.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
#ifndef PPING_H
|
|
#define PPING_H
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/in6.h>
|
|
|
|
#define INGRESS_PROG_SEC "xdp"
|
|
#define EGRESS_PROG_SEC "classifier"
|
|
|
|
struct bpf_config {
|
|
__u64 rate_limit;
|
|
};
|
|
|
|
/*
|
|
* Struct that can hold the source or destination address for a flow (l3+l4).
|
|
* Works for both IPv4 and IPv6, as IPv4 addresses can be mapped to IPv6 ones
|
|
* based on RFC 4291 Section 2.5.5.2.
|
|
*/
|
|
struct flow_address {
|
|
struct in6_addr ip;
|
|
__u16 port;
|
|
__u16 reserved;
|
|
};
|
|
|
|
/*
|
|
* Struct to hold a full network tuple
|
|
* The ipv member is technically not necessary, but makes it easier to
|
|
* determine if saddr/daddr are IPv4 or IPv6 address (don't need to look at the
|
|
* first 12 bytes of address). The proto memeber is not currently used, but
|
|
* could be useful once pping is extended to work for other protocols than TCP.
|
|
*/
|
|
struct network_tuple {
|
|
struct flow_address saddr;
|
|
struct flow_address daddr;
|
|
__u16 proto; //IPPROTO_TCP, IPPROTO_ICMP, QUIC etc
|
|
__u8 ipv; //AF_INET or AF_INET6
|
|
__u8 reserved;
|
|
};
|
|
|
|
struct flow_state {
|
|
__u64 min_rtt;
|
|
__u64 last_timestamp;
|
|
__u32 last_id;
|
|
__u32 reserved;
|
|
};
|
|
|
|
struct packet_id {
|
|
struct network_tuple flow;
|
|
__u32 identifier; //tsval for TCP packets
|
|
};
|
|
|
|
struct rtt_event {
|
|
__u64 rtt;
|
|
__u64 min_rtt;
|
|
__u64 timestamp;
|
|
struct network_tuple flow;
|
|
__u32 reserved;
|
|
};
|
|
|
|
#endif
|