mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
feat(wireguard): Add analyzer to check if PersistentKeepalive is set
This commit is contained in:
parent
911e080fbb
commit
cdb9017c4d
@ -26,6 +26,7 @@ func (p wireguardParser) analyze() []protocol.Diagnostic {
|
||||
diagnostics := []protocol.Diagnostic{}
|
||||
diagnostics = append(diagnostics, p.checkForDuplicateProperties()...)
|
||||
diagnostics = append(diagnostics, p.analyzeDNSContainsFallback()...)
|
||||
diagnostics = append(diagnostics, p.analyzeKeepAliveIsSet()...)
|
||||
|
||||
return diagnostics
|
||||
}
|
||||
@ -89,7 +90,8 @@ func (p wireguardParser) analyzeDNSContainsFallback() []protocol.Diagnostic {
|
||||
dnsAmount := len(strings.Split(property.Value.Value, ","))
|
||||
|
||||
if dnsAmount == 1 {
|
||||
severity := protocol.DiagnosticSeverityWarning
|
||||
severity := protocol.DiagnosticSeverityHint
|
||||
|
||||
return []protocol.Diagnostic{
|
||||
{
|
||||
Message: "There is one DNS server specified. It is recommended to set up fallback DNS servers",
|
||||
@ -111,6 +113,37 @@ func (p wireguardParser) analyzeDNSContainsFallback() []protocol.Diagnostic {
|
||||
return []protocol.Diagnostic{}
|
||||
}
|
||||
|
||||
func (p wireguardParser) analyzeKeepAliveIsSet() []protocol.Diagnostic {
|
||||
diagnostics := make([]protocol.Diagnostic, 0)
|
||||
|
||||
for _, section := range p.Sections {
|
||||
if section.Name != nil && *section.Name == "Peer" {
|
||||
// If an endpoint is set, then we should only check for the keepalive property
|
||||
if section.fetchFirstProperty("Endpoint") != nil {
|
||||
if section.fetchFirstProperty("PersistentKeepalive") == nil {
|
||||
severity := protocol.DiagnosticSeverityHint
|
||||
diagnostics = append(diagnostics, protocol.Diagnostic{
|
||||
Message: "PersistentKeepalive is not set. It is recommended to set this property, as it helps to maintain the connection when users are behind NAT",
|
||||
Severity: &severity,
|
||||
Range: protocol.Range{
|
||||
Start: protocol.Position{
|
||||
Line: section.StartLine,
|
||||
Character: 0,
|
||||
},
|
||||
End: protocol.Position{
|
||||
Line: section.StartLine,
|
||||
Character: 99999999,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
// Check if the values are valid.
|
||||
// Assumes that sections have been analyzed already.
|
||||
func (p wireguardParser) checkIfValuesAreValid() []protocol.Diagnostic {
|
||||
|
@ -62,6 +62,16 @@ func (s wireguardSection) String() string {
|
||||
return fmt.Sprintf("[%s]; %d-%d: %v", name, s.StartLine, s.EndLine, s.Properties)
|
||||
}
|
||||
|
||||
func (s *wireguardSection) fetchFirstProperty(name string) *wireguardProperty {
|
||||
for _, property := range s.Properties {
|
||||
if property.Key.Name == name {
|
||||
return &property
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *wireguardSection) findProperty(lineNumber uint32) (*wireguardProperty, error) {
|
||||
property, found := s.Properties[lineNumber]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user