mirror of
https://github.com/h44z/wg-portal.git
synced 2025-10-04 15:36:18 +00:00
wip: basic CRUD for interfaces (#426)
This commit is contained in:
@@ -10,6 +10,7 @@ const (
|
||||
// Controller extras can be used to store additional information available for specific controllers only.
|
||||
|
||||
type MikrotikInterfaceExtras struct {
|
||||
Id string // internal mikrotik ID
|
||||
Comment string
|
||||
Disabled bool
|
||||
}
|
||||
|
@@ -227,6 +227,11 @@ func (p *PhysicalInterface) SetExtras(extras any) {
|
||||
}
|
||||
|
||||
func ConvertPhysicalInterface(pi *PhysicalInterface) *Interface {
|
||||
networks := make([]Cidr, 0, len(pi.Addresses))
|
||||
for _, addr := range pi.Addresses {
|
||||
networks = append(networks, addr.NetworkAddr())
|
||||
}
|
||||
|
||||
// create a new basic interface with the data from the physical interface
|
||||
iface := &Interface{
|
||||
Identifier: pi.Identifier,
|
||||
@@ -247,11 +252,11 @@ func ConvertPhysicalInterface(pi *PhysicalInterface) *Interface {
|
||||
Type: InterfaceTypeAny,
|
||||
DriverType: pi.DeviceType,
|
||||
Disabled: nil,
|
||||
PeerDefNetworkStr: "",
|
||||
PeerDefNetworkStr: CidrsToString(networks),
|
||||
PeerDefDnsStr: "",
|
||||
PeerDefDnsSearchStr: "",
|
||||
PeerDefEndpoint: "",
|
||||
PeerDefAllowedIPsStr: "",
|
||||
PeerDefAllowedIPsStr: CidrsToString(networks),
|
||||
PeerDefMtu: pi.Mtu,
|
||||
PeerDefPersistentKeepalive: 0,
|
||||
PeerDefFirewallMark: 0,
|
||||
@@ -291,6 +296,15 @@ func MergeToPhysicalInterface(pi *PhysicalInterface, i *Interface) {
|
||||
pi.FirewallMark = i.FirewallMark
|
||||
pi.DeviceUp = !i.IsDisabled()
|
||||
pi.Addresses = i.Addresses
|
||||
|
||||
switch pi.ImportSource {
|
||||
case ControllerTypeMikrotik:
|
||||
extras := MikrotikInterfaceExtras{
|
||||
Comment: i.DisplayName,
|
||||
Disabled: i.IsDisabled(),
|
||||
}
|
||||
pi.SetExtras(extras)
|
||||
}
|
||||
}
|
||||
|
||||
type RoutingTableInfo struct {
|
||||
|
Reference in New Issue
Block a user