refactor: cleaned up some code

there was an attempt to use libnl to look up addresses directly with
FIB_LOOKUP, and some of that code was left over. This commit cleans up
such leftover code
This commit is contained in:
Andrew Rioux 2023-05-01 06:00:27 -04:00
parent 04a529e32f
commit 113a43ac41
4 changed files with 3 additions and 30 deletions

View File

@ -19,7 +19,4 @@
int netlink_route() {
return NETLINK_ROUTE;
}
int netlink_fib_lookup() {
return NETLINK_FIB_LOOKUP;
}

View File

@ -13,8 +13,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use std::net::Ipv4Addr;
pub mod nl_ffi;
pub mod netlink;
pub mod route;
@ -23,7 +21,6 @@ pub mod error;
// from bridge.c
extern "C" {
pub(crate) fn netlink_route() -> libc::c_int;
pub(crate) fn netlink_fib_lookup() -> libc::c_int;
}
/* fn main() -> error::Result<()> {

View File

@ -23,22 +23,8 @@ pub struct Socket {
pub(crate) sock: *mut nl_sock
}
pub enum SocketType {
Routing,
Lookup
}
impl SocketType {
pub fn to_proto(&self) -> i32 {
unsafe { match self {
Self::Routing => crate::netlink_route(),
Self::Lookup => crate::netlink_fib_lookup()
} }
}
}
impl Socket {
pub fn new(stype: SocketType) -> error::Result<Self> {
pub fn new() -> error::Result<Self> {
unsafe {
let sock = Socket { sock: nl_socket_alloc() };
@ -124,13 +110,6 @@ where
}
impl<T: From<*mut nl_object>> Cache<T> {
pub(crate) fn new(cache: *mut nl_cache) -> Cache<T> {
Cache {
cache,
dt: PhantomData
}
}
pub fn iter(&self) -> CacheIter<'_, T> {
let cache_size = unsafe {
nl_cache_nitems(self.cache)

View File

@ -15,9 +15,9 @@
use std::{ffi::{CStr, CString}, net::Ipv4Addr};
use libc::{c_int, AF_INET, AF_UNIX, AF_UNSPEC, c_uint};
use libc::{c_int, AF_INET, c_uint};
use crate::{error, netlink::{Cache, Socket}};
use crate::{error, netlink::Cache};
use super::nl_ffi::*;