Neuer optionaler Schritt im Einrichten-Wizard, standardmäßig übersprungen (Toggle): legt ein VLAN-Interface auf einem gewählten Basis-Anschluss an, mit eigenem IP-Bereich und eigenem DHCP-Server — z.B. für Gäste/IoT. Bewusst ohne Port-Zuweisung (Access/Trunk): das bräuchte RouterOS Bridge-VLAN-Filtering mit "set"-Operationen auf bestehende Einträge, die unser bisheriges reines "add"-Befehlsmodell (identisch für REST+SSH) nicht abdeckt. Wer ein VLAN auf einem bestimmten Switch-Port braucht, muss den Trunk weiterhin manuell einrichten. Entscheidung mit Nutzer abgestimmt. DHCP-Befehlsbau (Adresse+Pool+Server+Netzwerk) aus dem LAN-Schritt in DhcpServerCommandBuilder extrahiert, da jetzt zweimal identisch gebraucht (LAN direkt, VLAN pro Eintrag). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HReLXMbmPvtQ23p1iWiJNW
57 lines
2.2 KiB
Swift
57 lines
2.2 KiB
Swift
import Foundation
|
|
|
|
/// One additional virtual network: a VLAN interface on top of an existing (typically LAN
|
|
/// bridge) interface, with its own IP range and DHCP server — e.g. a guest or IoT network.
|
|
/// Deliberately not port-based (no access/trunk assignment): that needs RouterOS bridge
|
|
/// VLAN filtering, which requires "set" operations our REST/SSH command model doesn't
|
|
/// support yet (it only ever creates new items). Someone who needs a VLAN on a specific
|
|
/// switch port still has to configure that port as a tagged trunk manually.
|
|
struct VlanEntry: Identifiable, Equatable {
|
|
var id = UUID()
|
|
var name: String
|
|
var vlanID: Int
|
|
var parentInterface: String
|
|
var networkAddress: String
|
|
var routerAddress: String
|
|
var poolRangeStart: String
|
|
var poolRangeEnd: String
|
|
var leaseTimeHours: Int = 24
|
|
var dnsServers: String
|
|
|
|
init(name: String = "Gäste", vlanID: Int, parentInterface: String) {
|
|
self.name = name
|
|
self.vlanID = vlanID
|
|
self.parentInterface = parentInterface
|
|
let octet = vlanID % 256
|
|
self.networkAddress = "192.168.\(octet).0/24"
|
|
self.routerAddress = "192.168.\(octet).1/24"
|
|
self.poolRangeStart = "192.168.\(octet).10"
|
|
self.poolRangeEnd = "192.168.\(octet).254"
|
|
self.dnsServers = "192.168.\(octet).1"
|
|
}
|
|
|
|
var interfaceName: String { "vlan\(vlanID)" }
|
|
|
|
func buildCommands() -> [RouterOSCommand] {
|
|
let createVlan = RouterOSCommand(
|
|
cliPath: "/interface vlan add",
|
|
restPath: "interface/vlan",
|
|
arguments: ["name": interfaceName, "vlan-id": "\(vlanID)", "interface": parentInterface],
|
|
summary: "VLAN \"\(name)\" (ID \(vlanID)) auf \(parentInterface) anlegen"
|
|
)
|
|
|
|
let dhcpCommands = DhcpServerCommandBuilder.buildCommands(
|
|
interfaceName: interfaceName,
|
|
routerAddress: routerAddress,
|
|
networkAddress: networkAddress,
|
|
poolRangeStart: poolRangeStart,
|
|
poolRangeEnd: poolRangeEnd,
|
|
leaseTimeHours: leaseTimeHours,
|
|
dnsServers: dnsServers,
|
|
context: "für VLAN \"\(name)\""
|
|
)
|
|
|
|
return [createVlan] + dhcpCommands
|
|
}
|
|
}
|