pub struct Registration<T: Filter> { /* private fields */ }
Expand description

A registration of a networking filter.

Examples

The following is an example of a function that attaches an inbound filter (that always accepts all packets after printing their lengths) on the specified device (in the init ns).

use kernel::net::{self, filter as netfilter};

struct MyFilter;
impl netfilter::Filter for MyFilter {
    fn filter(_data: (), skb: &net::SkBuff) -> netfilter::Disposition {
        pr_info!("Packet of length {}\n", skb.len());
        netfilter::Disposition::Accept
    }
}

fn register(name: &CStr) -> Result<Pin<Box<netfilter::Registration<MyFilter>>>> {
    let ns = net::init_ns();
    let dev = ns.dev_get_by_name(name).ok_or(ENOENT)?;
    netfilter::Registration::new_pinned(
        netfilter::Family::NetDev(netfilter::netdev::Hook::Ingress),
        0,
        ns.into(),
        Some(dev),
        (),
    )
}

Implementations

Creates a new Registration but does not register it yet.

It is allowed to move.

Creates a new filter registration and registers it.

Returns a pinned heap-allocated representation of the registration.

Registers a network filter.

It must be pinned because the C portion of the kernel stores a pointer to it while it is registered.

The priority is relative to the family’s base priority. For example, if the base priority is 100 and priority is -1, the actual priority will be 99. If a family doesn’t explicitly allow a base to be specified, 0 is assumed.

Trait Implementations

Returns the “default value” for a type. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

This documentation is an old archive. Please see https://rust.docs.kernel.org instead.