Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

RFC: diag: add support for SOCK_DESTROY #283

Open
wants to merge 1 commit into
base: master
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
39 changes: 39 additions & 0 deletions netlink-packet-sock-diag/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
NetlinkPayload,
NetlinkSerializable,
SockDiagBuffer,
SOCK_DESTROY,
SOCK_DIAG_BY_FAMILY,
};

Expand Down Expand Up @@ -93,3 +94,41 @@ impl From<SockDiagMessage> for NetlinkPayload<SockDiagMessage> {
NetlinkPayload::InnerMessage(message)
}
}

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

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

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

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

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

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

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