Add network filters metadata

This commit is contained in:
Pierre HUBERT 2024-01-03 19:53:47 +01:00
parent 0710c61909
commit a7bfb80547
5 changed files with 78 additions and 4 deletions

View File

@ -74,3 +74,6 @@ pub const BUILTIN_NETWORK_FILTER_RULES: [&str; 24] = [
"qemu-announce-self", "qemu-announce-self",
"qemu-announce-self-rarp", "qemu-announce-self-rarp",
]; ];
/// List of valid network chains
pub const NETWORK_CHAINS: [&str; 8] = ["root", "mac", "stp", "vlan", "arp", "rarp", "ipv4", "ipv6"];

View File

@ -15,8 +15,9 @@ struct StaticConfig {
oidc_auth_enabled: bool, oidc_auth_enabled: bool,
iso_mimetypes: &'static [&'static str], iso_mimetypes: &'static [&'static str],
net_mac_prefix: &'static str, net_mac_prefix: &'static str,
constraints: ServerConstraints,
builtin_nwfilter_rules: &'static [&'static str], builtin_nwfilter_rules: &'static [&'static str],
nwfilter_chains: &'static [&'static str],
constraints: ServerConstraints,
} }
#[derive(serde::Serialize)] #[derive(serde::Serialize)]
@ -25,6 +26,12 @@ struct LenConstraints {
max: usize, max: usize,
} }
#[derive(serde::Serialize)]
struct SLenConstraints {
min: i64,
max: i64,
}
#[derive(serde::Serialize)] #[derive(serde::Serialize)]
struct ServerConstraints { struct ServerConstraints {
iso_max_size: usize, iso_max_size: usize,
@ -37,6 +44,9 @@ struct ServerConstraints {
net_name_size: LenConstraints, net_name_size: LenConstraints,
net_title_size: LenConstraints, net_title_size: LenConstraints,
dhcp_reservation_host_name: LenConstraints, dhcp_reservation_host_name: LenConstraints,
nwfilter_name_size: LenConstraints,
nwfilter_comment_size: LenConstraints,
nwfilter_priority: SLenConstraints,
} }
pub async fn static_config(local_auth: LocalAuthEnabled) -> impl Responder { pub async fn static_config(local_auth: LocalAuthEnabled) -> impl Responder {
@ -47,6 +57,7 @@ pub async fn static_config(local_auth: LocalAuthEnabled) -> impl Responder {
iso_mimetypes: &constants::ALLOWED_ISO_MIME_TYPES, iso_mimetypes: &constants::ALLOWED_ISO_MIME_TYPES,
net_mac_prefix: constants::NET_MAC_ADDR_PREFIX, net_mac_prefix: constants::NET_MAC_ADDR_PREFIX,
builtin_nwfilter_rules: &constants::BUILTIN_NETWORK_FILTER_RULES, builtin_nwfilter_rules: &constants::BUILTIN_NETWORK_FILTER_RULES,
nwfilter_chains: &constants::NETWORK_CHAINS,
constraints: ServerConstraints { constraints: ServerConstraints {
iso_max_size: constants::ISO_MAX_SIZE, iso_max_size: constants::ISO_MAX_SIZE,
@ -71,6 +82,13 @@ pub async fn static_config(local_auth: LocalAuthEnabled) -> impl Responder {
net_title_size: LenConstraints { min: 0, max: 50 }, net_title_size: LenConstraints { min: 0, max: 50 },
dhcp_reservation_host_name: LenConstraints { min: 2, max: 250 }, dhcp_reservation_host_name: LenConstraints { min: 2, max: 250 },
nwfilter_name_size: LenConstraints { min: 2, max: 250 },
nwfilter_comment_size: LenConstraints { min: 0, max: 256 },
nwfilter_priority: SLenConstraints {
min: -1000,
max: 1000,
},
}, },
}) })
} }

View File

@ -6,8 +6,9 @@ export interface ServerConfig {
oidc_auth_enabled: boolean; oidc_auth_enabled: boolean;
iso_mimetypes: string[]; iso_mimetypes: string[];
net_mac_prefix: string; net_mac_prefix: string;
constraints: ServerConstraints;
builtin_nwfilter_rules: string[]; builtin_nwfilter_rules: string[];
nwfilter_chains: string[];
constraints: ServerConstraints;
} }
export interface ServerConstraints { export interface ServerConstraints {
@ -21,6 +22,9 @@ export interface ServerConstraints {
net_name_size: LenConstraint; net_name_size: LenConstraint;
net_title_size: LenConstraint; net_title_size: LenConstraint;
dhcp_reservation_host_name: LenConstraint; dhcp_reservation_host_name: LenConstraint;
nwfilter_name_size: LenConstraint;
nwfilter_comment_size: LenConstraint;
nwfilter_priority: LenConstraint;
} }
export interface LenConstraint { export interface LenConstraint {

View File

@ -17,6 +17,7 @@ export function CreateNWFilterRoute(): React.ReactElement {
const [nwfilter, setNWFilter] = React.useState<NWFilter>({ const [nwfilter, setNWFilter] = React.useState<NWFilter>({
name: "my-filter", name: "my-filter",
chain: { protocol: "root" },
join_filters: [], join_filters: [],
rules: [], rules: [],
}); });

View File

@ -1,4 +1,4 @@
import { Button } from "@mui/material"; import { Button, Grid } from "@mui/material";
import React, { ReactElement } from "react"; import React, { ReactElement } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { import {
@ -12,6 +12,10 @@ import { useSnackbar } from "../../hooks/providers/SnackbarProvider";
import { AsyncWidget } from "../AsyncWidget"; import { AsyncWidget } from "../AsyncWidget";
import { TabsWidget } from "../TabsWidget"; import { TabsWidget } from "../TabsWidget";
import { XMLAsyncWidget } from "../XMLWidget"; import { XMLAsyncWidget } from "../XMLWidget";
import { EditSection } from "../forms/EditSection";
import { TextInput } from "../forms/TextInput";
import { ServerApi } from "../../api/ServerApi";
import { SelectInput } from "../forms/SelectInput";
interface DetailsProps { interface DetailsProps {
nwfilter: NWFilter; nwfilter: NWFilter;
@ -96,7 +100,51 @@ export function NetworkFilterDetailsInner(
function NetworkFilterDetailsTabGeneral( function NetworkFilterDetailsTabGeneral(
p: InnerDetailsProps p: InnerDetailsProps
): React.ReactElement { ): React.ReactElement {
return <></>; return (
<Grid container spacing={2}>
{/* Metadata section */}
<EditSection title="Metadata">
<TextInput
label="Name"
editable={p.editable}
value={p.nwfilter.name}
onValueChange={(v) => {
p.nwfilter.name = v ?? "";
p.onChange?.();
}}
checkValue={(v) => /^[a-zA-Z0-9\_\-]+$/.test(v)}
size={ServerApi.Config.constraints.nwfilter_name_size}
/>
<TextInput label="UUID" editable={false} value={p.nwfilter.uuid} />
<SelectInput
label="Chain"
editable={p.editable}
value={p.nwfilter.chain?.protocol}
onValueChange={(v) => {
p.nwfilter.chain = v ? { protocol: v } : undefined;
p.onChange?.();
}}
options={ServerApi.Config.nwfilter_chains.map((c) => {
return { label: c, value: c };
})}
/>
<TextInput
label="Priority"
editable={p.editable}
value={p.nwfilter.priority?.toString()}
type="number"
onValueChange={(v) => {
p.nwfilter.priority = v && v !== "" ? Number(v) : undefined;
p.onChange?.();
}}
size={ServerApi.Config.constraints.nwfilter_priority}
/>
</EditSection>
</Grid>
);
} }
function NetworkFilterDetailsTabXML(p: InnerDetailsProps): React.ReactElement { function NetworkFilterDetailsTabXML(p: InnerDetailsProps): React.ReactElement {