netstack3_filter/
lib.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Packet filtering framework.
6
7#![no_std]
8#![warn(missing_docs)]
9
10extern crate fakealloc as alloc;
11
12mod actions;
13mod api;
14mod conntrack;
15mod context;
16mod logic;
17mod matchers;
18mod packets;
19mod state;
20
21use logic::nat::NatConfig;
22
23/// A connection as tracked by conntrack.
24pub type ConntrackConnection<I, A, BT> = conntrack::Connection<I, NatConfig<I, A>, BT>;
25
26pub use actions::MarkAction;
27pub use api::FilterApi;
28pub use conntrack::{
29    ConnectionDirection, Table, TransportProtocol, Tuple,
30    WeakConnection as WeakConntrackConnection, WeakConnectionError,
31};
32pub use context::{
33    FilterBindingsContext, FilterBindingsTypes, FilterContext, FilterIpContext, NatContext,
34};
35pub use logic::{
36    FilterHandler, FilterImpl, FilterTimerId, IngressVerdict, ProofOfEgressCheck, Verdict,
37};
38pub use matchers::{
39    AddressMatcher, AddressMatcherType, InterfaceMatcher, InterfaceProperties, PacketMatcher,
40    PortMatcher, TransportProtocolMatcher,
41};
42pub use packets::{
43    FilterIpExt, ForwardedPacket, IcmpMessage, IpPacket, MaybeTransportPacket,
44    MaybeTransportPacketMut, RawIpBody, TransportPacketSerializer, TxPacket,
45};
46pub use state::validation::{ValidRoutines, ValidationError};
47pub use state::{
48    Action, FilterIpMetadata, FilterMarkMetadata, Hook, IpRoutines, NatRoutines, Routine, Routines,
49    Rule, State, TransparentProxy, UninstalledRoutine,
50};
51
52/// Testing-related utilities for use by other crates.
53#[cfg(any(test, feature = "testutils"))]
54pub mod testutil {
55    pub use crate::logic::testutil::NoopImpl;
56
57    #[cfg(test)]
58    pub(crate) trait TestIpExt:
59        crate::context::testutil::TestIpExt + crate::packets::testutil::internal::TestIpExt
60    {
61    }
62
63    #[cfg(test)]
64    impl<I> TestIpExt for I where
65        I: crate::context::testutil::TestIpExt + crate::packets::testutil::internal::TestIpExt
66    {
67    }
68}