-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from wqld/feat/support-wireguard
feat(rsln): support genl netlink
- Loading branch information
Showing
23 changed files
with
383 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
# rsln | ||
|
||
Implements the netlink protocol based kernel interfaces required by the sinabro project in Rust. | ||
|
||
## Supported netlink protocols | ||
|
||
### Netlink route | ||
|
||
- link | ||
- address | ||
- route | ||
- neighbor | ||
|
||
### Generic netlink | ||
|
||
- family |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
use anyhow::{anyhow, Result}; | ||
|
||
use crate::{ | ||
core::message::Message, | ||
handle::zero_terminated, | ||
types::{ | ||
generic::{GenlFamilies, GenlFamily}, | ||
message::{Attribute, GenlMessage, RouteAttr}, | ||
}, | ||
}; | ||
|
||
use super::sock_handle::SocketHandle; | ||
|
||
pub struct GenericHandle<'a> { | ||
pub socket: &'a mut SocketHandle, | ||
} | ||
|
||
impl<'a> Deref for GenericHandle<'a> { | ||
type Target = SocketHandle; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
self.socket | ||
} | ||
} | ||
|
||
impl DerefMut for GenericHandle<'_> { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
self.socket | ||
} | ||
} | ||
|
||
impl<'a> From<&'a mut SocketHandle> for GenericHandle<'a> { | ||
fn from(socket: &'a mut SocketHandle) -> Self { | ||
Self { socket } | ||
} | ||
} | ||
|
||
impl GenericHandle<'_> { | ||
pub fn list_family(&mut self) -> Result<GenlFamilies> { | ||
let mut req = Message::new(libc::GENL_ID_CTRL as u16, libc::NLM_F_DUMP); | ||
let msg = GenlMessage::get_family_message(); | ||
|
||
req.add(&msg.serialize()?); | ||
|
||
let msgs = self.request(&mut req, 0)?; | ||
|
||
GenlFamilies::try_from(msgs) | ||
} | ||
|
||
pub fn get_family(&mut self, name: &str) -> Result<GenlFamily> { | ||
let mut req = Message::new(libc::GENL_ID_CTRL as u16, 0); | ||
let msg = GenlMessage::get_family_message(); | ||
let family_name = | ||
RouteAttr::new(libc::CTRL_ATTR_FAMILY_NAME as u16, &zero_terminated(name)); | ||
|
||
req.add(&msg.serialize()?); | ||
req.add(&family_name.serialize()?); | ||
|
||
let msgs = self.request(&mut req, 0)?; | ||
|
||
GenlFamilies::try_from(msgs)? | ||
.first() | ||
.cloned() | ||
.ok_or_else(|| anyhow!("invalid response for GENL_CTRL_CMD_GETFAMILY")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod addr; | ||
pub mod generic; | ||
pub mod link; | ||
pub mod neigh; | ||
pub mod routing; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.