feat(networks): add MTU option to network creation

This commit is contained in:
Mauricio Siu 2026-08-03 04:09:50 -06:00
parent a1230098c9
commit 69a5615544
6 changed files with 8969 additions and 1 deletions

View File

@ -54,6 +54,14 @@ const networkFormSchema = z
attachable: z.boolean(),
enableIPv4: z.boolean(),
enableIPv6: z.boolean(),
mtu: z
.string()
.refine(
(value) =>
value === "" ||
(/^\d+$/.test(value) && +value >= 68 && +value <= 65535),
{ message: "MTU must be a number between 68 and 65535" },
),
ipamDriver: z.string().optional(),
ipamConfig: z.array(ipamConfigEntrySchema),
})
@ -85,6 +93,7 @@ const defaultValues: NetworkFormValues = {
attachable: false,
enableIPv4: true,
enableIPv6: false,
mtu: "",
ipamDriver: "",
ipamConfig: [],
};
@ -147,6 +156,7 @@ export const HandleNetwork = ({ serverId, children }: HandleNetworkProps) => {
attachable: data.attachable,
enableIPv4: data.enableIPv4,
enableIPv6: data.enableIPv6,
mtu: data.mtu ? Number(data.mtu) : undefined,
ipam: {
driver: data.ipamDriver || undefined,
config: data.ipamConfig,
@ -232,6 +242,23 @@ export const HandleNetwork = ({ serverId, children }: HandleNetworkProps) => {
</FormItem>
)}
/>
<FormField
control={form.control}
name="mtu"
render={({ field }) => (
<FormItem>
<FormLabel>MTU (optional)</FormLabel>
<FormControl>
<Input placeholder="1500" inputMode="numeric" {...field} />
</FormControl>
<FormDescription className="text-muted-foreground">
Maximum transmission unit. Leave empty to use Docker's
default.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
{toggleOptions.map((option) => (

View File

@ -0,0 +1 @@
ALTER TABLE "network" ADD COLUMN "mtu" integer;

File diff suppressed because it is too large Load Diff

View File

@ -1247,6 +1247,13 @@
"when": 1785709848209,
"tag": "0177_glossy_brother_voodoo",
"breakpoints": true
},
{
"idx": 178,
"version": "7",
"when": 1785751631838,
"tag": "0178_silky_randall",
"breakpoints": true
}
]
}

View File

@ -1,5 +1,12 @@
import { relations } from "drizzle-orm";
import { boolean, jsonb, pgEnum, pgTable, text } from "drizzle-orm/pg-core";
import {
boolean,
integer,
jsonb,
pgEnum,
pgTable,
text,
} from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { nanoid } from "nanoid";
import { z } from "zod";
@ -19,6 +26,7 @@ export const network = pgTable("network", {
attachable: boolean("attachable").notNull().default(false),
enableIPv4: boolean("enableIPv4").notNull().default(true),
enableIPv6: boolean("enableIPv6").notNull().default(false),
mtu: integer("mtu"),
ipam: jsonb("ipam")
.$type<{
driver?: string;
@ -55,6 +63,7 @@ const createSchema = createInsertSchema(network, {
attachable: z.boolean().optional(),
enableIPv4: z.boolean().optional(),
enableIPv6: z.boolean().optional(),
mtu: z.number().int().min(68).max(65535).optional().nullable(),
ipam: z
.object({
driver: z.string().optional(),
@ -109,6 +118,7 @@ export const apiCreateNetwork = createSchema
attachable: true,
enableIPv4: true,
enableIPv6: true,
mtu: true,
ipam: true,
serverId: true,
})

View File

@ -24,6 +24,7 @@ type DockerNetworkInfo = {
Ingress?: boolean;
EnableIPv4?: boolean;
EnableIPv6?: boolean;
Options?: Record<string, string> | null;
IPAM?: {
Driver?: string;
Config?: Array<{
@ -34,6 +35,11 @@ type DockerNetworkInfo = {
};
};
const parseMtu = (value: string | undefined) => {
const mtu = Number.parseInt(value ?? "", 10);
return Number.isNaN(mtu) ? null : mtu;
};
const isImportableDockerNetwork = (dockerNetwork: DockerNetworkInfo) =>
!RESERVED_NETWORKS.includes(dockerNetwork.Name) &&
!dockerNetwork.Ingress &&
@ -51,6 +57,7 @@ const mapDockerNetworkToRow = (
// Older daemons don't report EnableIPv4; IPv4 is always on there
enableIPv4: dockerNetwork.EnableIPv4 ?? true,
enableIPv6: dockerNetwork.EnableIPv6 ?? false,
mtu: parseMtu(dockerNetwork.Options?.["com.docker.network.driver.mtu"]),
ipam: {
driver: dockerNetwork.IPAM?.Driver,
config: (dockerNetwork.IPAM?.Config ?? []).map((c) => ({
@ -255,6 +262,9 @@ const createDockerNetworkFromRow = async (row: typeof network.$inferSelect) => {
// the daemon (API >= 1.47); the body is sent as-is
EnableIPv4: row.enableIPv4,
EnableIPv6: row.enableIPv6,
Options: row.mtu
? { "com.docker.network.driver.mtu": String(row.mtu) }
: undefined,
IPAM: {
Driver: ipam.driver || "default",
Config: ipamConfig.length > 0 ? ipamConfig : undefined,