Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diag: add support for SOCK_DESTROY #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
43 changes: 42 additions & 1 deletion src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
DecodeError,
};

use crate::{inet, unix, SockDiagBuffer, SOCK_DIAG_BY_FAMILY};
use crate::{inet, unix, SockDiagBuffer, SOCK_DESTROY, SOCK_DIAG_BY_FAMILY};

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum SockDiagMessage {
Expand Down Expand Up @@ -93,3 +93,44 @@
NetlinkPayload::InnerMessage(message)
}
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct SockDiagDestroy(SockDiagMessage);

impl SockDiagDestroy {
pub fn new(message: SockDiagMessage) -> SockDiagDestroy {
SockDiagDestroy(message)
}

Check warning on line 103 in src/message.rs

View check run for this annotation

Codecov / codecov/patch

src/message.rs#L101-L103

Added lines #L101 - L103 were not covered by tests
}

impl NetlinkSerializable for SockDiagDestroy {
fn message_type(&self) -> u16 {
SOCK_DESTROY
}

Check warning on line 109 in src/message.rs

View check run for this annotation

Codecov / codecov/patch

src/message.rs#L107-L109

Added lines #L107 - L109 were not covered by tests

fn buffer_len(&self) -> usize {
NetlinkSerializable::buffer_len(&self.0)
}

Check warning on line 113 in src/message.rs

View check run for this annotation

Codecov / codecov/patch

src/message.rs#L111-L113

Added lines #L111 - L113 were not covered by tests

fn serialize(&self, buffer: &mut [u8]) {
self.0.serialize(buffer)
}

Check warning on line 117 in src/message.rs

View check run for this annotation

Codecov / codecov/patch

src/message.rs#L115-L117

Added lines #L115 - L117 were not covered by tests
}

impl NetlinkDeserializable for SockDiagDestroy {
type Error = DecodeError;
fn deserialize(
header: &NetlinkHeader,
payload: &[u8],
) -> Result<Self, Self::Error> {
Ok(SockDiagDestroy::new(SockDiagMessage::deserialize(
header, payload,
)?))
}

Check warning on line 129 in src/message.rs

View check run for this annotation

Codecov / codecov/patch

src/message.rs#L122-L129

Added lines #L122 - L129 were not covered by tests
}

impl From<SockDiagDestroy> for NetlinkPayload<SockDiagDestroy> {
fn from(message: SockDiagDestroy) -> Self {
NetlinkPayload::InnerMessage(message)
}

Check warning on line 135 in src/message.rs

View check run for this annotation

Codecov / codecov/patch

src/message.rs#L133-L135

Added lines #L133 - L135 were not covered by tests
}
Loading