mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 19:08:20 +00:00
Add Static Route Backend
This commit is contained in:
parent
dec123e9ee
commit
3197f291fa
4 changed files with 40 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
package definitions
|
package definitions
|
||||||
|
|
||||||
type Network struct {
|
type Network struct {
|
||||||
Interfaces map[string]Interface `json:"interfaces" validate:"required,dive"`
|
Interfaces map[string]Interface `json:"interfaces" validate:"required,dive"`
|
||||||
|
StaticRoutes []StaticRoute `json:"static_routes" validate:"required,dive"`
|
||||||
}
|
}
|
||||||
|
|
13
internal/definitions/static_route.go
Normal file
13
internal/definitions/static_route.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package definitions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/netip"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StaticRoute struct {
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Interface string `json:"interface,omitempty"`
|
||||||
|
Gateway netip.Addr `json:"gateway,omitempty"`
|
||||||
|
Destination IPNet `json:"destination,omitempty"`
|
||||||
|
Metric uint `json:"metric,omitempty"`
|
||||||
|
}
|
|
@ -16,7 +16,8 @@ type NetworkdConfigFile struct {
|
||||||
type InterfaceWithName struct {
|
type InterfaceWithName struct {
|
||||||
Name string
|
Name string
|
||||||
definitions.Interface
|
definitions.Interface
|
||||||
Vlans []string
|
Vlans []string
|
||||||
|
StaticRoutes []definitions.StaticRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
type BondMembership struct {
|
type BondMembership struct {
|
||||||
|
@ -128,6 +129,7 @@ func GenerateNetworkdConfiguration(conf definitions.Config) ([]NetworkdConfigFil
|
||||||
|
|
||||||
// Step 6 Generate addressing network files
|
// Step 6 Generate addressing network files
|
||||||
for name, inter := range conf.Network.Interfaces {
|
for name, inter := range conf.Network.Interfaces {
|
||||||
|
// Vlans
|
||||||
vlans := []string{}
|
vlans := []string{}
|
||||||
if inter.Type != definitions.Vlan {
|
if inter.Type != definitions.Vlan {
|
||||||
vlans := []string{}
|
vlans := []string{}
|
||||||
|
@ -141,11 +143,20 @@ func GenerateNetworkdConfiguration(conf definitions.Config) ([]NetworkdConfigFil
|
||||||
slog.Info("Vlans on interface", "interface", name, "count", len(vlans))
|
slog.Info("Vlans on interface", "interface", name, "count", len(vlans))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Static Routes
|
||||||
|
staticRoutes := []definitions.StaticRoute{}
|
||||||
|
for _, route := range conf.Network.StaticRoutes {
|
||||||
|
if route.Interface == name {
|
||||||
|
staticRoutes = append(staticRoutes, route)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
err := templates.ExecuteTemplate(buf, "config-addressing.network.tmpl", InterfaceWithName{
|
err := templates.ExecuteTemplate(buf, "config-addressing.network.tmpl", InterfaceWithName{
|
||||||
Name: name,
|
Name: name,
|
||||||
Interface: inter,
|
Interface: inter,
|
||||||
Vlans: vlans,
|
Vlans: vlans,
|
||||||
|
StaticRoutes: staticRoutes,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("executing config-addressing.network.tmpl template: %w", err)
|
return nil, fmt.Errorf("executing config-addressing.network.tmpl template: %w", err)
|
||||||
|
|
|
@ -15,3 +15,12 @@ DHCP=yes
|
||||||
{{- range .Vlans }}
|
{{- range .Vlans }}
|
||||||
VLAN={{ . }}
|
VLAN={{ . }}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
||||||
|
{{- range .StaticRoutes }}
|
||||||
|
[Route]
|
||||||
|
Destination={{ Destination }}
|
||||||
|
Gateway={{ Gateway }}
|
||||||
|
{{- if ne .Metric 0 }}
|
||||||
|
Metric={{ Metric }}
|
||||||
|
{{- end }}
|
||||||
|
{{end}}
|
Loading…
Add table
Reference in a new issue