Use datagram_common in netlink

This commit is contained in:
Ruihan Li
2025-04-20 17:30:39 +08:00
committed by Tate, Hongliang Tian
parent c9f939bcc4
commit 26253829bb
4 changed files with 126 additions and 115 deletions

View File

@ -3,10 +3,12 @@
use super::bound::BoundNetlinkRoute;
use crate::{
events::IoEvents,
net::socket::netlink::{
table::NETLINK_SOCKET_TABLE, NetlinkSocketAddr, StandardNetlinkProtocol,
net::socket::{
netlink::{table::NETLINK_SOCKET_TABLE, NetlinkSocketAddr, StandardNetlinkProtocol},
util::datagram_common,
},
prelude::*,
process::signal::Pollee,
};
pub(super) struct UnboundNetlinkRoute {
@ -17,19 +19,40 @@ impl UnboundNetlinkRoute {
pub(super) const fn new() -> Self {
Self { _private: () }
}
}
pub(super) fn bind(
self,
addr: &NetlinkSocketAddr,
) -> core::result::Result<BoundNetlinkRoute, (Error, Self)> {
let bound_handle = NETLINK_SOCKET_TABLE
.bind(StandardNetlinkProtocol::ROUTE as _, addr)
.map_err(|err| (err, self))?;
impl datagram_common::Unbound for UnboundNetlinkRoute {
type Endpoint = NetlinkSocketAddr;
type BindOptions = ();
type Bound = BoundNetlinkRoute;
fn bind(
&mut self,
endpoint: &Self::Endpoint,
_pollee: &Pollee,
_options: Self::BindOptions,
) -> Result<BoundNetlinkRoute> {
let bound_handle =
NETLINK_SOCKET_TABLE.bind(StandardNetlinkProtocol::ROUTE as _, endpoint)?;
Ok(BoundNetlinkRoute::new(bound_handle))
}
pub(super) fn check_io_events(&self) -> IoEvents {
fn bind_ephemeral(
&mut self,
_remote_endpoint: &Self::Endpoint,
_pollee: &Pollee,
) -> Result<Self::Bound> {
let bound_handle = NETLINK_SOCKET_TABLE.bind(
StandardNetlinkProtocol::ROUTE as _,
&NetlinkSocketAddr::new_unspecified(),
)?;
Ok(BoundNetlinkRoute::new(bound_handle))
}
fn check_io_events(&self) -> IoEvents {
IoEvents::OUT
}
}