Add --mac filter and rename IpFilter to PacketFilter
A packet is kept if its Ethernet source or destination MAC matches any --mac entry; combined with --ip, both must match. Empty dimensions match everything, so the unfiltered case is still the same code path. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b111ddfdc
commit
a9e283a87c
6 files changed
+189
-53
No files matched your search
+10
-10
@@ -1,5 +1,5 @@
|
||||
use crate::chunker::{Chunker, RawChunker, RecordAlignedChunker};
|
||||
use crate::filter::IpFilter;
|
||||
use crate::filter::PacketFilter;
|
||||
use crate::protocol::{Message, MessageSink, MessageSource};
|
||||
use crate::tail::{run_tail, SourceEvent};
|
||||
use crate::tracelog::Logger;
|
||||
@@ -28,10 +28,10 @@ pub struct SendOptions {
|
||||
/// anyway. See `Chunker::should_flush`.
|
||||
pub flush_after: Duration,
|
||||
pub level: i32,
|
||||
/// Which packets to forward. `IpFilter::match_all()` when no `--ip` was
|
||||
/// Which packets to forward. `PacketFilter::match_all()` when no `--ip`/`--mac` was
|
||||
/// given -- not a disabled filter, just one that says yes, so there is
|
||||
/// only ever one code path through the chunker.
|
||||
pub filter: IpFilter,
|
||||
pub filter: PacketFilter,
|
||||
pub log: Arc<Logger>,
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ pub fn run_send(opts: SendOptions, mut sink: Box<dyn MessageSink>) -> Result<()>
|
||||
// structure is the only way to tell real content from a preallocating
|
||||
// writer's not-yet-written tail. Here the chunker is a validator, not
|
||||
// a framer.
|
||||
// * a real `--ip` filter: deciding whether to forward a packet means
|
||||
// * a real `--ip`/`--mac` filter: deciding whether to forward a packet means
|
||||
// finding the packet, and record boundaries are the only way to know
|
||||
// where one starts. Here the chunker is a demultiplexer.
|
||||
// A final, uncompressed copy has neither: `run_recv` writes every Data
|
||||
@@ -273,7 +273,7 @@ mod tests {
|
||||
chunk_target: crate::chunker::DEFAULT_TARGET_BYTES,
|
||||
flush_after: crate::chunker::DEFAULT_FLUSH,
|
||||
level: crate::zstd_frame::DEFAULT_LEVEL,
|
||||
filter: IpFilter::match_all(),
|
||||
filter: PacketFilter::match_all(),
|
||||
log: Arc::new(Logger::none()),
|
||||
};
|
||||
run_pipe(opts, dest_final.clone(), dest_temp.clone()).unwrap();
|
||||
@@ -311,7 +311,7 @@ mod tests {
|
||||
chunk_target: crate::chunker::DEFAULT_TARGET_BYTES,
|
||||
flush_after: crate::chunker::DEFAULT_FLUSH,
|
||||
level: crate::zstd_frame::DEFAULT_LEVEL,
|
||||
filter: IpFilter::match_all(),
|
||||
filter: PacketFilter::match_all(),
|
||||
log: Arc::new(Logger::none()),
|
||||
};
|
||||
|
||||
@@ -360,7 +360,7 @@ mod tests {
|
||||
chunk_target: 512, // small target to force multiple frames
|
||||
flush_after: crate::chunker::DEFAULT_FLUSH,
|
||||
level: crate::zstd_frame::DEFAULT_LEVEL,
|
||||
filter: IpFilter::match_all(),
|
||||
filter: PacketFilter::match_all(),
|
||||
log: Arc::new(Logger::none()),
|
||||
};
|
||||
run_pipe(opts, dest_final.clone(), dest_temp.clone()).unwrap();
|
||||
@@ -398,7 +398,7 @@ mod tests {
|
||||
chunk_target: crate::chunker::DEFAULT_TARGET_BYTES,
|
||||
flush_after: crate::chunker::DEFAULT_FLUSH,
|
||||
level: crate::zstd_frame::DEFAULT_LEVEL,
|
||||
filter: IpFilter::match_all(),
|
||||
filter: PacketFilter::match_all(),
|
||||
log: Arc::new(Logger::none()),
|
||||
};
|
||||
assert!(run_pipe(opts, dest_final.clone(), dest_temp).is_err());
|
||||
@@ -421,8 +421,8 @@ mod tests {
|
||||
record_bytes(&pkt, 1_700_000_000)
|
||||
}
|
||||
|
||||
fn ip_filter(specs: &[&str]) -> IpFilter {
|
||||
IpFilter::parse(&specs.iter().map(|s| s.to_string()).collect::<Vec<_>>()).unwrap()
|
||||
fn ip_filter(specs: &[&str]) -> PacketFilter {
|
||||
PacketFilter::parse(&specs.iter().map(|s| s.to_string()).collect::<Vec<_>>(), &[]).unwrap()
|
||||
}
|
||||
|
||||
/// Source stream plus the exact pcap a `--ip 1.1.1.1` transfer should
|
||||
|
||||
Reference in new issue
Block a user