Skip to main content

fosr_lib/inject/
mod.rs

1use crate::structs::FlowId;
2
3#[cfg(feature = "net_injection")]
4/// Fast injection, that does not wait for packet response
5pub mod fast;
6#[cfg(feature = "net_injection")]
7pub use fast::start_fast;
8#[cfg(feature = "net_injection")]
9/// Reliable injection, that waits for packet response
10pub mod reliable;
11#[cfg(feature = "net_injection")]
12pub use reliable::start_reliable;
13
14#[cfg(all(
15    any(target_os = "windows", target_os = "linux"),
16    feature = "ebpf",
17    feature = "net_injection"
18))]
19/// Network enabler based on eBPF
20pub mod ebpf;
21#[cfg(all(target_os = "linux", feature = "iptables", feature = "net_injection"))]
22/// Network enable based on iptables
23pub mod iptables;
24
25/// A trait for network enablers
26pub trait NetEnabler: Clone + std::marker::Send + 'static {
27    fn get_ttl(&self) -> Option<u8>;
28
29    /// is this packet sent by Fos-R ?
30    fn is_packet_relevant(&self, flags: u8) -> bool;
31
32    /// should we send the packet without waiting for any answer?
33    fn is_fast(&self) -> bool;
34
35    /// close the connection
36    fn close_session(&self, f: &FlowId);
37
38    /// set-up the connection
39    fn open_session(&self, f: &FlowId);
40}
41
42#[derive(Debug, Clone)]
43/// Used when no network injection is performed
44pub struct DummyNetEnabler {}
45
46impl NetEnabler for DummyNetEnabler {
47    fn is_packet_relevant(&self, _: u8) -> bool {
48        false
49    }
50    fn is_fast(&self) -> bool {
51        false
52    }
53    fn close_session(&self, _: &FlowId) {}
54    fn open_session(&self, _: &FlowId) {}
55    fn get_ttl(&self) -> Option<u8> {
56        None
57    }
58}