Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAT RPW #3804

Merged
merged 26 commits into from
Nov 18, 2023
Merged

NAT RPW #3804

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
315ff35
NAT RPW for instance networking
internet-diglett Jul 31, 2023
e29a612
undo change to nextest config
internet-diglett Oct 17, 2023
eda98c5
update omdb background tasks
internet-diglett Oct 18, 2023
8af0927
convert db tables to follow similar column names as dns rpws
internet-diglett Oct 19, 2023
8fa914e
add missing migration file
internet-diglett Oct 20, 2023
452e4d1
ensure test doesn't rely on table order
internet-diglett Oct 20, 2023
ed63b1c
Merge branch 'main' into nat_rpw
internet-diglett Oct 27, 2023
7fea2ac
Update deleted_by_external_ip to use new table strategy
internet-diglett Oct 31, 2023
38d6c5a
Merge branch 'main' into nat_rpw
internet-diglett Nov 9, 2023
a591710
enforce correct types for Ipv4NatEntry
internet-diglett Nov 13, 2023
9858397
refactor ensure_ipv4_nat_entry to use diesel query
internet-diglett Nov 13, 2023
92df045
refactor sql queries use diesel dsl
internet-diglett Nov 14, 2023
151516f
remove unnecessary internal endpoint
internet-diglett Nov 14, 2023
7f0c0a7
update endpoint to use internal_latencies instrumentation
internet-diglett Nov 14, 2023
18164ee
revert accidental change to non-gimlet/config-rss.toml
internet-diglett Nov 14, 2023
351a0a8
remove unnecessary view struct
internet-diglett Nov 14, 2023
d3e9c60
convert to SqlU32 to i64
internet-diglett Nov 14, 2023
b38ebe5
a wild u32 escaped
internet-diglett Nov 14, 2023
0ffee3f
error on attempt of ipv6 nat configuration
internet-diglett Nov 14, 2023
3ce9d98
remove /rpw prefix from internal endpoint
internet-diglett Nov 14, 2023
e8d4768
remote unnecessary version tracking struct
internet-diglett Nov 14, 2023
049f324
bump schema version
internet-diglett Nov 14, 2023
f547f8a
bump dendrite version
internet-diglett Nov 15, 2023
7bf9e93
fixup dbinit statement ordering for clarity
internet-diglett Nov 16, 2023
45cea66
Merge branch 'main' into nat_rpw
internet-diglett Nov 16, 2023
eff1828
bump dendrite and schema
internet-diglett Nov 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ pub enum ResourceType {
UserBuiltin,
Zpool,
Vmm,
Ipv4NatEntry,
}

// IDENTITY METADATA
Expand Down
17 changes: 16 additions & 1 deletion common/src/nexus_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ pub struct BackgroundTaskConfig {
pub dns_external: DnsTasksConfig,
/// configuration for external endpoint list watcher
pub external_endpoints: ExternalEndpointsConfig,
/// configuration for nat table garbage collector
pub nat_cleanup: NatCleanupConfig,
/// configuration for inventory tasks
pub inventory: InventoryConfig,
}
Expand Down Expand Up @@ -371,6 +373,14 @@ pub struct ExternalEndpointsConfig {
// allow/disallow wildcard certs, don't serve expired certs, etc.)
}

#[serde_as]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct NatCleanupConfig {
/// period (in seconds) for periodic activations of this background task
#[serde_as(as = "DurationSeconds<u64>")]
pub period_secs: Duration,
}

#[serde_as]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct InventoryConfig {
Expand Down Expand Up @@ -498,7 +508,7 @@ mod test {
BackgroundTaskConfig, Config, ConfigDropshotWithTls, ConsoleConfig,
Database, DeploymentConfig, DnsTasksConfig, DpdConfig,
ExternalEndpointsConfig, InternalDns, InventoryConfig, LoadError,
LoadErrorKind, MgdConfig, PackageConfig, SchemeName,
LoadErrorKind, MgdConfig, NatCleanupConfig, PackageConfig, SchemeName,
TimeseriesDbConfig, Tunables, UpdatesConfig,
};
use crate::address::{Ipv6Subnet, RACK_PREFIX};
Expand Down Expand Up @@ -649,6 +659,7 @@ mod test {
dns_external.period_secs_propagation = 7
dns_external.max_concurrent_server_updates = 8
external_endpoints.period_secs = 9
nat_cleanup.period_secs = 30
inventory.period_secs = 10
inventory.nkeep = 11
inventory.disable = false
Expand Down Expand Up @@ -746,6 +757,9 @@ mod test {
external_endpoints: ExternalEndpointsConfig {
period_secs: Duration::from_secs(9),
},
nat_cleanup: NatCleanupConfig {
period_secs: Duration::from_secs(30),
},
inventory: InventoryConfig {
period_secs: Duration::from_secs(10),
nkeep: 11,
Expand Down Expand Up @@ -804,6 +818,7 @@ mod test {
dns_external.period_secs_propagation = 7
dns_external.max_concurrent_server_updates = 8
external_endpoints.period_secs = 9
nat_cleanup.period_secs = 30
inventory.period_secs = 10
inventory.nkeep = 3
inventory.disable = false
Expand Down
1 change: 1 addition & 0 deletions dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ async fn cmd_nexus_background_tasks_show(
"dns_config_external",
"dns_servers_external",
"dns_propagation_external",
"nat_v4_garbage_collector",
] {
if let Some(bgtask) = tasks.remove(name) {
print_task(&bgtask);
Expand Down
15 changes: 15 additions & 0 deletions dev-tools/omdb/tests/env.out
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ task: "inventory_collection"
collects hardware and software inventory data from the whole system


task: "nat_v4_garbage_collector"
prunes soft-deleted IPV4 NAT entries from ipv4_nat_entry table based on a
predetermined retention policy


---------------------------------------------
stderr:
note: using Nexus URL http://127.0.0.1:REDACTED_PORT
Expand Down Expand Up @@ -121,6 +126,11 @@ task: "inventory_collection"
collects hardware and software inventory data from the whole system


task: "nat_v4_garbage_collector"
prunes soft-deleted IPV4 NAT entries from ipv4_nat_entry table based on a
predetermined retention policy


---------------------------------------------
stderr:
note: Nexus URL not specified. Will pick one from DNS.
Expand Down Expand Up @@ -168,6 +178,11 @@ task: "inventory_collection"
collects hardware and software inventory data from the whole system


task: "nat_v4_garbage_collector"
prunes soft-deleted IPV4 NAT entries from ipv4_nat_entry table based on a
predetermined retention policy


---------------------------------------------
stderr:
note: Nexus URL not specified. Will pick one from DNS.
Expand Down
12 changes: 12 additions & 0 deletions dev-tools/omdb/tests/successes.out
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ task: "inventory_collection"
collects hardware and software inventory data from the whole system


task: "nat_v4_garbage_collector"
prunes soft-deleted IPV4 NAT entries from ipv4_nat_entry table based on a
predetermined retention policy


---------------------------------------------
stderr:
note: using Nexus URL http://127.0.0.1:REDACTED_PORT/
Expand Down Expand Up @@ -319,6 +324,13 @@ task: "dns_propagation_external"
[::1]:REDACTED_PORT success


task: "nat_v4_garbage_collector"
configured period: every 30s
currently executing: no
last completed activation: iter 2, triggered by an explicit signal
started at <REDACTED TIMESTAMP> (<REDACTED DURATION>s ago) and ran for <REDACTED DURATION>ms
warning: unknown background task: "nat_v4_garbage_collector" (don't know how to interpret details: Null)

task: "external_endpoints"
configured period: every 1m
currently executing: no
Expand Down
81 changes: 81 additions & 0 deletions nexus/db-model/src/ipv4_nat_entry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use std::net::{Ipv4Addr, Ipv6Addr};

use super::MacAddr;
use crate::{schema::ipv4_nat_entry, Ipv4Net, Ipv6Net, SqlU16, Vni};
use chrono::{DateTime, Utc};
use omicron_common::api::external;
use schemars::JsonSchema;
use serde::Serialize;
use uuid::Uuid;

/// Values used to create an Ipv4NatEntry
#[derive(Insertable, Debug, Clone)]
#[diesel(table_name = ipv4_nat_entry)]
pub struct Ipv4NatValues {
pub external_address: Ipv4Net,
pub first_port: SqlU16,
pub last_port: SqlU16,
pub sled_address: Ipv6Net,
pub vni: Vni,
pub mac: MacAddr,
}

/// Database representation of an Ipv4 NAT Entry.
#[derive(Queryable, Debug, Clone, Selectable)]
#[diesel(table_name = ipv4_nat_entry)]
pub struct Ipv4NatEntry {
pub id: Uuid,
pub external_address: Ipv4Net,
pub first_port: SqlU16,
pub last_port: SqlU16,
pub sled_address: Ipv6Net,
pub vni: Vni,
pub mac: MacAddr,
pub version_added: i64,
pub version_removed: Option<i64>,
pub time_created: DateTime<Utc>,
pub time_deleted: Option<DateTime<Utc>>,
}

impl Ipv4NatEntry {
pub fn first_port(&self) -> u16 {
self.first_port.into()
}

pub fn last_port(&self) -> u16 {
self.last_port.into()
}
}

/// NAT Record
#[derive(Clone, Debug, Serialize, JsonSchema)]
pub struct Ipv4NatEntryView {
pub external_address: Ipv4Addr,
pub first_port: u16,
pub last_port: u16,
pub sled_address: Ipv6Addr,
pub vni: external::Vni,
pub mac: external::MacAddr,
pub gen: i64,
pub deleted: bool,
}

impl From<Ipv4NatEntry> for Ipv4NatEntryView {
fn from(value: Ipv4NatEntry) -> Self {
let (gen, deleted) = match value.version_removed {
Some(gen) => (gen, true),
None => (value.version_added, false),
};

Self {
external_address: value.external_address.ip(),
first_port: value.first_port(),
last_port: value.last_port(),
sled_address: value.sled_address.ip(),
vni: value.vni.0,
mac: *value.mac,
gen,
deleted,
}
}
}
2 changes: 2 additions & 0 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ mod system_update;
// These actually represent subqueries, not real table.
// However, they must be defined in the same crate as our tables
// for join-based marker trait generation.
mod ipv4_nat_entry;
pub mod queries;
mod rack;
mod region;
Expand Down Expand Up @@ -124,6 +125,7 @@ pub use instance_cpu_count::*;
pub use instance_state::*;
pub use inventory::*;
pub use ip_pool::*;
pub use ipv4_nat_entry::*;
pub use ipv4net::*;
pub use ipv6::*;
pub use ipv6net::*;
Expand Down
28 changes: 27 additions & 1 deletion nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,32 @@ table! {
}
}

table! {
ipv4_nat_entry (id) {
id -> Uuid,
external_address -> Inet,
first_port -> Int4,
last_port -> Int4,
sled_address -> Inet,
vni -> Int4,
mac -> Int8,
version_added -> Int8,
version_removed -> Nullable<Int8>,
time_created -> Timestamptz,
time_deleted -> Nullable<Timestamptz>,
}
}

// This is the sequence used for the version number
// in ipv4_nat_entry.
table! {
ipv4_nat_version (last_value) {
last_value -> Int8,
log_cnt -> Int8,
is_called -> Bool,
}
}

table! {
external_ip (id) {
id -> Uuid,
Expand Down Expand Up @@ -1243,7 +1269,7 @@ table! {
///
/// This should be updated whenever the schema is changed. For more details,
/// refer to: schema/crdb/README.adoc
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(10, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(11, 0, 0);

allow_tables_to_appear_in_same_query!(
system_update,
Expand Down
Loading
Loading