1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- use bitmap::{traits::BitMapOps, AllocBitmap};
- use core::intrinsics::unlikely;
- use system_error::SystemError;
- use crate::libs::lazy_init::Lazy;
- pub const PROTO_INUSE_NR: usize = 64;
- pub trait Protocol {
- fn close(&self);
-
- }
- pub struct Proto<'a> {
- name: &'a str,
-
- obj_size: usize,
- inuse_idx: Option<usize>,
- }
- impl Protocol for Proto<'_> {
- fn close(&self) {}
- }
- pub static mut NETLINK_PROTO: Proto = Proto {
- name: "NETLINK",
-
- obj_size: core::mem::size_of::<Proto>(),
-
- inuse_idx: None,
- };
- pub fn proto_register(proto: &mut Proto, alloc_slab: i32) -> Result<i32, SystemError> {
- let mut ret = Err(SystemError::ENOBUFS);
- if alloc_slab != 0 {
- log::info!("TODO: netlink_proto: slab allocation not supported\n");
- return ret;
- }
- ret = assign_proto_idx(proto);
- ret
- }
- pub fn assign_proto_idx(prot: &mut Proto) -> Result<i32, SystemError> {
-
-
- if unlikely(prot.inuse_idx == Some(PROTO_INUSE_NR - 1)) {
- log::info!("PROTO_INUSE_NR exhausted\n");
- return Err(SystemError::ENOSPC);
- }
-
-
- return Ok(0);
- }
|