Skip to content

Commit 1336572

Browse files
committed
Why not name some rules?
1 parent 923f9ee commit 1336572

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

lib/oxide-vpc/src/api.rs renamed to lib/oxide-vpc/src/api/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
// Copyright 2024 Oxide Computer Company
5+
// Copyright 2025 Oxide Computer Company
66

77
use alloc::collections::BTreeMap;
88
use alloc::collections::BTreeSet;
@@ -19,6 +19,8 @@ use serde::Deserialize;
1919
use serde::Serialize;
2020
use uuid::Uuid;
2121

22+
pub mod stat;
23+
2224
/// This is the MAC address that OPTE uses to act as the virtual gateway.
2325
pub const GW_MAC_ADDR: MacAddr =
2426
MacAddr::from_const([0xA8, 0x40, 0x25, 0xFF, 0x77, 0x77]);

lib/oxide-vpc/src/api/stat.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
// Copyright 2025 Oxide Computer Company
6+
7+
//! Stat IDs for the Oxide VPC API.
8+
9+
use uuid::Uuid;
10+
11+
pub static FW_DEFAULT_IN: Uuid =
12+
Uuid::from_fields(0x01de_f00d, 0x7777, 0x0000, &0u64.to_be_bytes());
13+
pub static FW_DEFAULT_OUT: Uuid =
14+
Uuid::from_fields(0x01de_f00d, 0x7777, 0x0000, &1u64.to_be_bytes());
15+
16+
pub static GATEWAY_NOSPOOF_IN: Uuid =
17+
Uuid::from_fields(0x01de_f00d, 0x7777, 0x0001, &0u64.to_be_bytes());
18+
pub static GATEWAY_NOSPOOF_OUT: Uuid =
19+
Uuid::from_fields(0x01de_f00d, 0x7777, 0x0001, &1u64.to_be_bytes());
20+
21+
pub static ROUTER_NOROUTE: Uuid =
22+
Uuid::from_fields(0x01de_f00d, 0x7777, 0x0002, &0u64.to_be_bytes());
23+
24+
pub static NAT_SNAT_V4: Uuid =
25+
Uuid::from_fields(0x01de_f00d, 0x7777, 0x0003, &0u64.to_be_bytes());
26+
pub static NAT_SNAT_V6: Uuid =
27+
Uuid::from_fields(0x01de_f00d, 0x7777, 0x0003, &1u64.to_be_bytes());
28+
pub static NAT_VALID_IGW_V4: Uuid =
29+
Uuid::from_fields(0x01de_f00d, 0x7777, 0x0003, &2u64.to_be_bytes());
30+
pub static NAT_VALID_IGW_V6: Uuid =
31+
Uuid::from_fields(0x01de_f00d, 0x7777, 0x0003, &3u64.to_be_bytes());
32+
pub static NAT_NONE: Uuid =
33+
Uuid::from_fields(0x01de_f00d, 0x7777, 0x0003, &255u64.to_be_bytes());

lib/oxide-vpc/src/engine/firewall.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::api::Ports;
1818
pub use crate::api::ProtoFilter;
1919
use crate::api::RemFwRuleReq;
2020
use crate::api::SetFwRulesReq;
21+
use crate::api::stat::*;
2122
use crate::engine::overlay::ACTION_META_VNI;
2223
use alloc::string::ToString;
2324
use core::num::NonZeroU32;
@@ -60,7 +61,9 @@ pub fn setup(
6061
// allow.
6162
let actions = LayerActions {
6263
default_in: DefaultAction::Deny,
64+
default_in_stat_id: Some(FW_DEFAULT_IN),
6365
default_out: DefaultAction::StatefulAllow,
66+
default_out_stat_id: Some(FW_DEFAULT_OUT),
6467
..Default::default()
6568
};
6669

lib/oxide-vpc/src/engine/gateway/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ use opte::engine::rule::MetaAction;
7777
use opte::engine::rule::ModMetaResult;
7878
use opte::engine::rule::Rule;
7979
use opte::engine::rule::StaticAction;
80+
use crate::api::stat::*;
8081

8182
pub mod arp;
8283
pub mod dhcp;
@@ -105,7 +106,9 @@ pub fn setup(
105106
// for inbound traffic to be that of the gateway.
106107
let actions = LayerActions {
107108
default_in: DefaultAction::Deny,
109+
default_in_stat_id: Some(GATEWAY_NOSPOOF_IN),
108110
default_out: DefaultAction::Deny,
111+
default_out_stat_id: Some(GATEWAY_NOSPOOF_IN),
109112
..Default::default()
110113
};
111114

lib/oxide-vpc/src/engine/nat.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use opte::engine::rule::Rule;
4747
use opte::engine::snat::ConcreteIpAddr;
4848
use opte::engine::snat::SNat;
4949
use uuid::Uuid;
50+
use crate::api::stat::*;
5051

5152
pub const NAT_LAYER_NAME: &str = "nat";
5253
const FLOATING_ONE_TO_ONE_NAT_PRIORITY: u16 = 5;
@@ -102,7 +103,9 @@ pub fn setup(
102103
// be forwarded to boundary services.
103104
let actions = LayerActions {
104105
default_in: DefaultAction::Allow,
106+
default_in_stat_id: Some(NAT_NONE),
105107
default_out: DefaultAction::Allow,
108+
default_out_stat_id: Some(NAT_NONE),
106109
..Default::default()
107110
};
108111

@@ -289,7 +292,7 @@ fn setup_ipv4_nat(
289292

290293
for igw_id in igw_matches {
291294
let mut rule =
292-
Rule::new(SNAT_PRIORITY, Action::Stateful(snat.clone()));
295+
Rule::new_with_id(SNAT_PRIORITY, Action::Stateful(snat.clone()), Some(NAT_SNAT_V4));
293296

294297
rule.add_predicate(Predicate::InnerEtherType(vec![
295298
EtherTypeMatch::Exact(ETHER_TYPE_IPV4),
@@ -438,7 +441,7 @@ fn setup_ipv6_nat(
438441

439442
for igw_id in igw_matches {
440443
let mut rule =
441-
Rule::new(SNAT_PRIORITY, Action::Stateful(snat.clone()));
444+
Rule::new_with_id(SNAT_PRIORITY, Action::Stateful(snat.clone()), Some(NAT_SNAT_V6));
442445

443446
rule.add_predicate(Predicate::InnerEtherType(vec![
444447
EtherTypeMatch::Exact(ETHER_TYPE_IPV6),

lib/oxide-vpc/src/engine/router.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use opte::engine::rule::MetaAction;
4848
use opte::engine::rule::ModMetaResult;
4949
use opte::engine::rule::Rule;
5050
use uuid::Uuid;
51+
use crate::api::stat::*;
5152

5253
pub const ROUTER_LAYER_NAME: &str = "router";
5354

@@ -259,6 +260,7 @@ pub fn setup(
259260
let actions = LayerActions {
260261
default_in: DefaultAction::Allow,
261262
default_out: DefaultAction::Deny,
263+
default_out_stat_id: Some(ROUTER_NOROUTE),
262264
..Default::default()
263265
};
264266

0 commit comments

Comments
 (0)