-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working with TC egress implementation
- Loading branch information
1 parent
28a0234
commit 9f29bbc
Showing
8 changed files
with
145 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use aya_ebpf::bindings::TC_ACT_PIPE; | ||
use aya_ebpf::macros::map; | ||
use aya_ebpf::maps::{LruHashMap, PerfEventArray}; | ||
use aya_ebpf::programs::TcContext; | ||
use network_types::eth::{EthHdr, EtherType}; | ||
use network_types::ip::Ipv4Hdr; | ||
use nflux_common::EgressEvent; | ||
|
||
#[map] | ||
static ACTIVE_CONNECTIONS: LruHashMap<u32, u32> = LruHashMap::with_max_entries(1024, 0); | ||
|
||
#[map] | ||
static EGRESS_EVENT: PerfEventArray<EgressEvent> = PerfEventArray::new(0); | ||
|
||
pub fn try_tc_egress(ctx: TcContext) -> Result<i32, ()> { | ||
let ethhdr: EthHdr = ctx.load(0).map_err(|_| ())?; | ||
match ethhdr.ether_type { | ||
EtherType::Ipv4 => unsafe { | ||
let ipv4hdr: Ipv4Hdr = ctx.load(EthHdr::LEN).map_err(|_| ())?; | ||
let destination = u32::from_be(ipv4hdr.dst_addr); | ||
|
||
// Check if this destination is already active | ||
if ACTIVE_CONNECTIONS.get(&destination).is_none() { | ||
// Log only new connections | ||
let event = EgressEvent { dst_ip: destination }; | ||
EGRESS_EVENT.output(&ctx, &event, 0); | ||
|
||
// Mark connection as active | ||
ACTIVE_CONNECTIONS.insert(&destination, &1, 0).map_err(|_| ())?; | ||
} | ||
} | ||
_ => return Ok(TC_ACT_PIPE), | ||
} | ||
|
||
Ok(TC_ACT_PIPE) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters