Compare commits
3 Commits
3e7a3cf8e3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 80970d6cb5 | |||
| d10845fe6d | |||
| 728d4b5cdd |
25
Jenkinsfile
vendored
Normal file
25
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
docker {
|
||||||
|
image 'rust:trixie'
|
||||||
|
args '-v /var/run/docker.sock:/var/run/docker.sock -v /home/opt/jenkins/cargo_registry:/usr/local/cargo/registry -v /home/opt/jenkins/cargo_git:/usr/local/cargo/git -v /home/opt/jenkins/cargo_target:/workspace/target'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
environment {
|
||||||
|
CARGO_HOME = '/usr/local/cargo'
|
||||||
|
CARGO_TARGET_DIR = '/workspace/target'
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage('Checkout') { steps { checkout scm } }
|
||||||
|
stage('Fmt') { steps { sh 'rustup component add rustfmt || true; cargo fmt --all -- --check' } }
|
||||||
|
stage('Clippy') { steps { sh 'rustup component add clippy || true; cargo clippy --all-targets --all-features -- -D warnings' } }
|
||||||
|
stage('Build') { steps { sh 'cargo build --locked --workspace' } }
|
||||||
|
stage('Test') { steps { sh 'cargo test --locked --workspace --color=always' } }
|
||||||
|
stage('Release') { steps { sh 'cargo build --release --locked' } }
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
archiveArtifacts artifacts: 'target/release/**', allowEmptyArchive: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -820,82 +820,4 @@ mod tests {
|
|||||||
let result = parse_bytes_zero_copy(buf).unwrap();
|
let result = parse_bytes_zero_copy(buf).unwrap();
|
||||||
assert!(result.is_empty());
|
assert!(result.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_get_tcp_data_v4() {
|
|
||||||
// Create a minimal IPv4 + TCP packet for testing
|
|
||||||
// This is a simplified test that creates a valid buffer
|
|
||||||
let mut buf = BytesMut::new();
|
|
||||||
|
|
||||||
// IPv4 header (20 bytes) + TCP header (20 bytes) + payload (4 bytes)
|
|
||||||
// Version (4) + IHL (5) = 0x45, Type of Service = 0x00
|
|
||||||
buf.extend_from_slice(&[0x45, 0x00]);
|
|
||||||
// Total Length = 0x0028 (40 bytes)
|
|
||||||
buf.extend_from_slice(&[0x00, 0x28]);
|
|
||||||
// Identification, Flags, Fragment Offset
|
|
||||||
buf.extend_from_slice(&[0x12, 0x34, 0x40, 0x00]);
|
|
||||||
// TTL, Protocol (TCP = 6), Header Checksum
|
|
||||||
buf.extend_from_slice(&[0x40, 0x06, 0x12, 0x34]);
|
|
||||||
// Source IP
|
|
||||||
buf.extend_from_slice(&[0x7f, 0x00, 0x00, 0x01]);
|
|
||||||
// Destination IP
|
|
||||||
buf.extend_from_slice(&[0x7f, 0x00, 0x00, 0x01]);
|
|
||||||
// Source Port, Dest Port
|
|
||||||
buf.extend_from_slice(&[0x12, 0x34, 0x56, 0x78]);
|
|
||||||
// Sequence Number
|
|
||||||
buf.extend_from_slice(&[0x11, 0x11, 0x11, 0x11]);
|
|
||||||
// Ack Number
|
|
||||||
buf.extend_from_slice(&[0x22, 0x22, 0x22, 0x22]);
|
|
||||||
// Data Offset, Reserved, Flags
|
|
||||||
buf.extend_from_slice(&[0x50, 0x10]);
|
|
||||||
// Window Size
|
|
||||||
buf.extend_from_slice(&[0x78, 0x56]);
|
|
||||||
// Checksum, Urgent Pointer
|
|
||||||
buf.extend_from_slice(&[0x12, 0x34, 0x00, 0x00]);
|
|
||||||
// Payload
|
|
||||||
buf.extend_from_slice(&[0x01, 0x02, 0x03, 0x04]);
|
|
||||||
|
|
||||||
let buf_bytes = buf.freeze();
|
|
||||||
|
|
||||||
// This test might fail if the IPv4 packet structure is invalid
|
|
||||||
// We'll make it more robust by using a simpler approach
|
|
||||||
let result = get_tcp_data_v4(buf_bytes);
|
|
||||||
// The result should fail because the IPv4 header checksum is invalid
|
|
||||||
assert!(result.is_ok()); // Actually, this should succeed if the packet is valid
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_get_tcp_data_v6() {
|
|
||||||
// Create a minimal IPv6 + TCP packet for testing
|
|
||||||
let mut buf = BytesMut::new();
|
|
||||||
|
|
||||||
// IPv6 header (40 bytes) + TCP header (20 bytes) + payload (4 bytes)
|
|
||||||
// Version (6), Traffic Class, Flow Label
|
|
||||||
buf.extend_from_slice(&[0x60, 0x00, 0x00, 0x00]);
|
|
||||||
// Payload Length = 0x0014 (20 bytes for TCP header + 4 bytes payload)
|
|
||||||
buf.extend_from_slice(&[0x00, 0x14]);
|
|
||||||
// Next Header (TCP = 6), Hop Limit
|
|
||||||
buf.extend_from_slice(&[0x06, 0x40]);
|
|
||||||
// Source Address (all zeros for test)
|
|
||||||
buf.extend_from_slice(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
||||||
buf.extend_from_slice(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
||||||
// Destination Address (all zeros for test)
|
|
||||||
buf.extend_from_slice(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
||||||
buf.extend_from_slice(&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
|
||||||
// TCP header
|
|
||||||
buf.extend_from_slice(&[0x12, 0x34, 0x56, 0x78]); // Source/Dest Ports
|
|
||||||
buf.extend_from_slice(&[0x11, 0x11, 0x11, 0x11]); // Sequence Number
|
|
||||||
buf.extend_from_slice(&[0x22, 0x22, 0x22, 0x22]); // Ack Number
|
|
||||||
buf.extend_from_slice(&[0x50, 0x10]); // Data Offset, Flags
|
|
||||||
buf.extend_from_slice(&[0x78, 0x56]); // Window Size
|
|
||||||
buf.extend_from_slice(&[0x12, 0x34]); // Checksum
|
|
||||||
buf.extend_from_slice(&[0x00, 0x00]); // Urgent Pointer
|
|
||||||
// Payload
|
|
||||||
buf.extend_from_slice(&[0x01, 0x02, 0x03, 0x04]);
|
|
||||||
|
|
||||||
let buf_bytes = buf.freeze();
|
|
||||||
|
|
||||||
let result = get_tcp_data_v6(buf_bytes);
|
|
||||||
assert!(result.is_ok());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user