pub struct NetworkPolicy {
pub default_egress: Action,
pub default_ingress: Action,
pub rules: Vec<Rule>,
}Expand description
Network policy: single ordered rule list plus per-direction default actions.
Rules carry a Direction field that determines which evaluator
considers them. Egress evaluation iterates rules where
direction ∈ {Egress, Both}; ingress evaluation iterates rules where
direction ∈ {Ingress, Both}. First-match-wins within a direction.
Fields§
§default_egress: ActionDefault action for egress traffic not matching any rule.
Deny paired with an implicit allow-Public rule reproduces
today’s “public internet only” reachability.
default_ingress: ActionDefault action for ingress traffic not matching any rule. The
per-field serde default is Deny so partially-specified JSON
fails closed; permissive presets like NetworkPolicy::public_only
flip this back to Allow explicitly.
rules: Vec<Rule>Ordered list of rules, evaluated first-match-wins per direction.
Implementations§
Source§impl NetworkPolicy
impl NetworkPolicy
Sourcepub fn builder() -> NetworkPolicyBuilder
pub fn builder() -> NetworkPolicyBuilder
Start building a NetworkPolicy via the fluent builder.
Source§impl NetworkPolicy
impl NetworkPolicy
Sourcepub fn public_only() -> Self
pub fn public_only() -> Self
Public internet only — allow egress to public IPs, deny private, loopback, link-local, and metadata. Ingress defaults to allow (preserves today’s unfiltered published-port behavior).
Sourcepub fn non_local() -> Self
pub fn non_local() -> Self
Non-local network access — allow public internet and private/LAN egress; deny loopback, link-local, and metadata. Ingress defaults to allow.
Sourcepub fn evaluate_egress(
&self,
dst: SocketAddr,
protocol: Protocol,
shared: &SharedState,
) -> Action
pub fn evaluate_egress( &self, dst: SocketAddr, protocol: Protocol, shared: &SharedState, ) -> Action
Evaluate an outbound connection against the rule list.
Iterates rules in order, considering only rules where
direction ∈ {Egress, Any}. Returns the action from the first
matching rule, or default_egress if no rule matches.
Sourcepub fn evaluate_egress_ip(
&self,
dst: IpAddr,
protocol: Protocol,
shared: &SharedState,
) -> Action
pub fn evaluate_egress_ip( &self, dst: IpAddr, protocol: Protocol, shared: &SharedState, ) -> Action
Evaluate an outbound ICMP packet against the rule list.
Same as Self::evaluate_egress but without port matching —
ICMP has no ports. Rules with a non-empty ports filter are
skipped since applying a port range to a portless protocol would
be semantically incorrect.
Sourcepub fn evaluate_ingress(
&self,
peer: SocketAddr,
guest_port: u16,
protocol: Protocol,
shared: &SharedState,
) -> Action
pub fn evaluate_ingress( &self, peer: SocketAddr, guest_port: u16, protocol: Protocol, shared: &SharedState, ) -> Action
Evaluate an inbound connection against the rule list.
Iterates rules in order, considering only rules where
direction ∈ {Ingress, Any}. peer is the source of the
incoming connection (peer IP and source port — only the IP is
matched). guest_port is the guest-side listening port; rules’
ports filter is matched against guest_port, not the peer’s
port.
Trait Implementations§
Source§impl Clone for NetworkPolicy
impl Clone for NetworkPolicy
Source§fn clone(&self) -> NetworkPolicy
fn clone(&self) -> NetworkPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more