Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ jobs:
run: |
rustup override set stable
rustup update stable
rustup component add llvm-tools-preview

- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Test and Generate code coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: lcov.info
fail_ci_if_error: true
- name: Test
run: cargo test
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
max_width = 80
wrap_comments = true
reorder_imports = true
format_strings = true
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
edition = "2021"
15 changes: 6 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "netlink-packet-xfrm"
version = "0.3.1"
authors = ["Scott Zuk <zooknotic@proton.me>"]
edition = "2018"
edition = "2021"
homepage = "https://github.com/rust-netlink/netlink-packet-xfrm"
repository = "https://github.com/rust-netlink/netlink-packet-xfrm"
keywords = ["netlink", "linux", "ipsec", "xfrm"]
Expand All @@ -11,13 +11,10 @@ readme = "README.md"
description = "netlink xfrm packet types for IPsec"

[dependencies]
anyhow = "1.0.39"
byteorder = "1.4.2"
libc= "0.2.86"
netlink-packet-core = { version = "0.7.0" }
netlink-packet-utils = { version = "0.5.2" }
libc= "0.2.177"
netlink-packet-core = { version = "0.8.1" }

[dev-dependencies]
lazy_static = "1.4.0"
netlink-proto = { version = "0.11.2" }
netlink-sys = { version = "0.8.4" }
lazy_static = "1.5.0"
netlink-proto = { version = "0.12" }
netlink-sys = { version = "0.8.7" }
2 changes: 1 addition & 1 deletion src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};

use netlink_packet_utils::{buffer, traits::*, DecodeError};
use netlink_packet_core::{DecodeError, Emitable, Parseable};

pub const XFRM_ADDRESS_LEN: usize = 16;

Expand Down
6 changes: 2 additions & 4 deletions src/async_event_id.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;

use core::ops::Range;

use netlink_packet_core::{DecodeError, Emitable, ErrorContext, Parseable};

use crate::{
Address, AddressBuffer, UserSaId, UserSaIdBuffer, XFRM_ADDRESS_LEN,
XFRM_USER_SA_ID_LEN,
};

use netlink_packet_utils::{buffer, traits::*, DecodeError};

#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
pub struct AsyncEventId {
pub sa_id: UserSaId,
Expand Down
8 changes: 4 additions & 4 deletions src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_core::{
DecodeError, ErrorContext, Parseable, ParseableParametrized,
};

use crate::{
constants::*,
Expand Down Expand Up @@ -35,8 +37,6 @@ use crate::{
XfrmMessage,
};

use netlink_packet_utils::{traits::*, DecodeError};

pub struct XfrmBuffer<T> {
buffer: T,
}
Expand All @@ -61,7 +61,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> XfrmBuffer<&'a T> {
}
}

impl<'a, T: AsRef<[u8]> + AsMut<[u8]> + ?Sized> XfrmBuffer<&'a mut T> {
impl<T: AsRef<[u8]> + AsMut<[u8]> + ?Sized> XfrmBuffer<&mut T> {
pub fn inner_mut(&mut self) -> &mut [u8] {
self.buffer.as_mut()
}
Expand Down
4 changes: 1 addition & 3 deletions src/id.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_core::{DecodeError, Emitable, ErrorContext, Parseable};

use crate::{Address, AddressBuffer, XFRM_ADDRESS_LEN};

use netlink_packet_utils::{buffer, traits::*, DecodeError};

#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
pub struct Id {
pub daddr: Address,
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub use user_sa_info::*;
pub mod user_spi_info;
pub use user_spi_info::*;

#[macro_use]
extern crate netlink_packet_core;

#[cfg(test)]
mod tests;
#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/lifetime.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

use crate::XFRM_INF;
use netlink_packet_core::{DecodeError, Emitable, Parseable};

use netlink_packet_utils::{buffer, traits::*, DecodeError};
use crate::XFRM_INF;

// Lifetime config

Expand Down
10 changes: 5 additions & 5 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// SPDX-License-Identifier: MIT

use netlink_packet_core::{
DecodeError, Emitable, NetlinkDeserializable, NetlinkHeader,
NetlinkPayload, NetlinkSerializable, ParseableParametrized,
};

use crate::{
constants::*,
monitor::{
Expand All @@ -20,11 +25,6 @@ use crate::{
XfrmBuffer,
};

use netlink_packet_core::{
NetlinkDeserializable, NetlinkHeader, NetlinkPayload, NetlinkSerializable,
};
use netlink_packet_utils::{traits::*, DecodeError};

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum XfrmMessage {
AddPolicy(PolicyModifyMessage),
Expand Down
8 changes: 2 additions & 6 deletions src/monitor/acquire/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// SPDX-License-Identifier: MIT

use crate::XFRM_USER_ACQUIRE_LEN;
use netlink_packet_core::{DecodeError, NlaBuffer, NlasIterator};

use netlink_packet_utils::{
buffer,
nla::{NlaBuffer, NlasIterator},
DecodeError,
};
use crate::XFRM_USER_ACQUIRE_LEN;

pub const MONITOR_ACQUIRE_HEADER_LEN: usize = XFRM_USER_ACQUIRE_LEN;

Expand Down
4 changes: 1 addition & 3 deletions src/monitor/acquire/message.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_core::{DecodeError, Emitable, ErrorContext, Parseable};

use crate::{AcquireMessageBuffer, UserAcquire, UserAcquireBuffer, XfrmAttrs};

use netlink_packet_utils::{traits::*, DecodeError};

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct AcquireMessage {
pub acquire: UserAcquire,
Expand Down
4 changes: 2 additions & 2 deletions src/monitor/expire/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

use crate::XFRM_USER_EXPIRE_LEN;
use netlink_packet_core::buffer;

use netlink_packet_utils::{buffer, DecodeError};
use crate::XFRM_USER_EXPIRE_LEN;

pub const MONITOR_EXPIRE_HEADER_LEN: usize = XFRM_USER_EXPIRE_LEN;

Expand Down
4 changes: 1 addition & 3 deletions src/monitor/expire/message.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_core::{DecodeError, Emitable, ErrorContext, Parseable};

use crate::{ExpireMessageBuffer, UserExpire, UserExpireBuffer};

use netlink_packet_utils::{traits::*, DecodeError};

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct ExpireMessage {
pub expire: UserExpire,
Expand Down
4 changes: 2 additions & 2 deletions src/monitor/get_async_event/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

use crate::XFRM_ASYNC_EVENT_ID_LEN;
use netlink_packet_core::buffer;

use netlink_packet_utils::{buffer, DecodeError};
use crate::XFRM_ASYNC_EVENT_ID_LEN;

pub const MONITOR_GET_ASYNC_EVENT_HEADER_LEN: usize = XFRM_ASYNC_EVENT_ID_LEN;

Expand Down
4 changes: 1 addition & 3 deletions src/monitor/get_async_event/message.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_core::{DecodeError, Emitable, ErrorContext, Parseable};

use crate::{AsyncEventId, AsyncEventIdBuffer, GetAsyncEventMessageBuffer};

use netlink_packet_utils::{traits::*, DecodeError};

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct GetAsyncEventMessage {
pub id: AsyncEventId,
Expand Down
4 changes: 2 additions & 2 deletions src/monitor/mapping/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

use crate::XFRM_USER_MAPPING_LEN;
use netlink_packet_core::buffer;

use netlink_packet_utils::{buffer, DecodeError};
use crate::XFRM_USER_MAPPING_LEN;

pub const MONITOR_MAPPING_HEADER_LEN: usize = XFRM_USER_MAPPING_LEN;

Expand Down
4 changes: 1 addition & 3 deletions src/monitor/mapping/message.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_core::{DecodeError, Emitable, ErrorContext, Parseable};

use crate::{MappingMessageBuffer, UserMapping, UserMappingBuffer};

use netlink_packet_utils::{traits::*, DecodeError};

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct MappingMessage {
pub map: UserMapping,
Expand Down
8 changes: 2 additions & 6 deletions src/monitor/migrate/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// SPDX-License-Identifier: MIT

use crate::XFRM_USER_POLICY_ID_LEN;
use netlink_packet_core::{DecodeError, NlaBuffer, NlasIterator};

use netlink_packet_utils::{
buffer,
nla::{NlaBuffer, NlasIterator},
DecodeError,
};
use crate::XFRM_USER_POLICY_ID_LEN;

pub const MONITOR_MIGRATE_HEADER_LEN: usize = XFRM_USER_POLICY_ID_LEN;

Expand Down
4 changes: 1 addition & 3 deletions src/monitor/migrate/message.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_core::{DecodeError, Emitable, ErrorContext, Parseable};

use crate::{
MigrateMessageBuffer, UserPolicyId, UserPolicyIdBuffer, XfrmAttrs,
};

use netlink_packet_utils::{traits::*, DecodeError};

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct MigrateMessage {
pub user_policy_id: UserPolicyId,
Expand Down
8 changes: 2 additions & 6 deletions src/monitor/new_async_event/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// SPDX-License-Identifier: MIT

use crate::XFRM_ASYNC_EVENT_ID_LEN;
use netlink_packet_core::{buffer, DecodeError, NlaBuffer, NlasIterator};

use netlink_packet_utils::{
buffer,
nla::{NlaBuffer, NlasIterator},
DecodeError,
};
use crate::XFRM_ASYNC_EVENT_ID_LEN;

pub const MONITOR_NEW_ASYNC_EVENT_HEADER_LEN: usize = XFRM_ASYNC_EVENT_ID_LEN;

Expand Down
4 changes: 1 addition & 3 deletions src/monitor/new_async_event/message.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_core::{DecodeError, Emitable, ErrorContext, Parseable};

use crate::{
AsyncEventId, AsyncEventIdBuffer, NewAsyncEventMessageBuffer, XfrmAttrs,
};

use netlink_packet_utils::{traits::*, DecodeError};

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct NewAsyncEventMessage {
pub id: AsyncEventId,
Expand Down
8 changes: 2 additions & 6 deletions src/monitor/polexpire/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// SPDX-License-Identifier: MIT

use crate::XFRM_USER_POLICY_EXPIRE_LEN;
use netlink_packet_core::{buffer, DecodeError, NlaBuffer, NlasIterator};

use netlink_packet_utils::{
buffer,
nla::{NlaBuffer, NlasIterator},
DecodeError,
};
use crate::XFRM_USER_POLICY_EXPIRE_LEN;

pub const MONITOR_POLICY_EXPIRE_HEADER_LEN: usize = XFRM_USER_POLICY_EXPIRE_LEN;

Expand Down
4 changes: 1 addition & 3 deletions src/monitor/polexpire/message.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_core::{DecodeError, Emitable, ErrorContext, Parseable};

use crate::{
PolicyExpireMessageBuffer, UserPolicyExpire, UserPolicyExpireBuffer,
XfrmAttrs,
};

use netlink_packet_utils::{traits::*, DecodeError};

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct PolicyExpireMessage {
pub expire: UserPolicyExpire,
Expand Down
8 changes: 2 additions & 6 deletions src/monitor/report/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// SPDX-License-Identifier: MIT

use crate::XFRM_USER_REPORT_LEN;
use netlink_packet_core::{buffer, DecodeError, NlaBuffer, NlasIterator};

use netlink_packet_utils::{
buffer,
nla::{NlaBuffer, NlasIterator},
DecodeError,
};
use crate::XFRM_USER_REPORT_LEN;

pub const MONITOR_REPORT_HEADER_LEN: usize = XFRM_USER_REPORT_LEN;

Expand Down
4 changes: 1 addition & 3 deletions src/monitor/report/message.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
use netlink_packet_core::{DecodeError, Emitable, ErrorContext, Parseable};

use crate::{ReportMessageBuffer, UserReport, UserReportBuffer, XfrmAttrs};

use netlink_packet_utils::{traits::*, DecodeError};

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct ReportMessage {
pub report: UserReport,
Expand Down
Loading