Files
RouterOS/RouterOSAssistant/Core/Models/VlanEntry.swift
T
KayandClaude Sonnet 5 5c8b5fd9d2 M8: Mehrere LAN-Interfaces + Netzwerk-Isolation (Firewall-Regeln pro Netzwerk)
lanConfig wird zu lanConfigs: [LanDhcpConfig] (analog zum VLAN-Listen-
Muster) — mehrere physische Interfaces mit je eigenem DHCP-Server.
Neues isolated-Feld auf LanDhcpConfig/VlanEntry: FirewallConfig erzeugt
daraus paarweise Forward-Drop-Regeln zwischen jedem isolierten Netzwerk
und allen anderen konfigurierten Netzwerken (Pair-Dedup bei gegenseitiger
Isolation). Behebt nebenbei, dass VlanStepView bisher Isolation im
Hilfetext behauptete, ohne dass eine Regel das durchsetzte.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYoWFMLHACvzzRC8u4iKF9
2026-09-13 19:57:15 +02:00

60 lines
2.4 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
/// Blocks forward traffic to/from every other configured LAN/VLAN network — see
/// `FirewallConfig.NetworkSegment`. Internet access (WAN NAT) is unaffected.
var isolated: Bool = false
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.add(
menuPath: "/interface vlan",
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
}
}