Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fun getAllAIGeneratedValidators(): Map<Validator, OptionValueInformation> {
Validator("config_parse_codel_bool", "QDISC_KIND_CODEL") to ConfigParseCodelBoolOptionValue() as OptionValueInformation,
Validator("config_parse_codel_u32", "QDISC_KIND_CODEL") to ConfigParseCodelU32OptionValue() as OptionValueInformation,
Validator("config_parse_collect_mode", "0") to ConfigParseCollectModeOptionValue() as OptionValueInformation,
Validator("config_parse_cpuset_partition", "0") to ConfigParseCpusetPartitionOptionValue() as OptionValueInformation,
Validator("config_parse_df", "0") to ConfigParseDfOptionValue() as OptionValueInformation,
Validator("config_parse_dhcp6_client_start_mode", "0") to ConfigParseDhcp6ClientStartModeOptionValue() as OptionValueInformation,
Validator("config_parse_dhcp6_pd_prefix_hint", "0") to ConfigParseDhcp6PdPrefixHintOptionValue() as OptionValueInformation,
Expand All @@ -64,6 +65,7 @@ fun getAllAIGeneratedValidators(): Map<Validator, OptionValueInformation> {
Validator("config_parse_dhcp_route_metric", "AF_INET") to ConfigParseDhcpRouteMetricOptionValue() as OptionValueInformation,
Validator("config_parse_dhcp_send_hostname", "AF_INET6") to ConfigParseDhcpSendHostnameOptionValue() as OptionValueInformation,
Validator("config_parse_dhcp_send_hostname", "AF_INET") to ConfigParseDhcpSendHostnameOptionValue() as OptionValueInformation,
Validator("config_parse_dhcp_server_emit", "0") to ConfigParseDhcpServerEmitOptionValue() as OptionValueInformation,
Validator("config_parse_dhcp_server_persist_leases", "0") to ConfigParseDhcpServerPersistLeasesOptionValue() as OptionValueInformation,
Validator("config_parse_dhcp_static_lease_address", "0") to ConfigParseDhcpStaticLeaseAddressOptionValue() as OptionValueInformation,
Validator("config_parse_disable_controllers", "0") to ConfigParseDisableControllersOptionValue() as OptionValueInformation,
Expand Down Expand Up @@ -122,6 +124,8 @@ fun getAllAIGeneratedValidators(): Map<Validator, OptionValueInformation> {
Validator("config_parse_macvlan_broadcast_queue_size", "0") to ConfigParseMacvlanBroadcastQueueSizeOptionValue() as OptionValueInformation,
Validator("config_parse_macvlan_broadcast_queue_threshold", "0") to ConfigParseMacvlanBroadcastQueueThresholdOptionValue() as OptionValueInformation,
Validator("config_parse_macvlan_mode", "0") to ConfigParseMacvlanModeOptionValue() as OptionValueInformation,
Validator("config_parse_managed_oom_mem_pressure_duration_sec", "0") to ConfigParseManagedOomMemPressureDurationSecOptionValue() as OptionValueInformation,
Validator("config_parse_managed_oom_mem_pressure_limit", "0") to ConfigParseManagedOomMemPressureLimitOptionValue() as OptionValueInformation,
Validator("config_parse_mdi", "0") to ConfigParseMdiOptionValue() as OptionValueInformation,
Validator("config_parse_pressure_watch", "0") to ConfigParseMemoryPressureWatchOptionValue() as OptionValueInformation,
Validator("config_parse_mtu", "AF_INET6") to ConfigParseMtuOptionValue() as OptionValueInformation,
Expand Down Expand Up @@ -165,8 +169,10 @@ fun getAllAIGeneratedValidators(): Map<Validator, OptionValueInformation> {
Validator("config_parse_rx_tx_queues", "0") to ConfigParseRxTxQueuesOptionValue() as OptionValueInformation,
Validator("config_parse_service_restart_mode", "0") to ConfigParseServiceRestartModeOptionValue() as OptionValueInformation,
Validator("config_parse_socket_defer_trigger", "0") to ConfigParseSocketDeferTriggerOptionValue() as OptionValueInformation,
Validator("config_parse_sr_iov_boolean", "0") to ConfigParseSrIovBooleanOptionValue() as OptionValueInformation,
Validator("config_parse_sr_iov_link_state", "0") to ConfigParseSrIovLinkStateOptionValue() as OptionValueInformation,
Validator("config_parse_sr_iov_num_vfs", "0") to ConfigParseSrIovNumVfsOptionValue() as OptionValueInformation,
Validator("config_parse_sr_iov_uint32", "0") to ConfigParseSrIovUint32OptionValue() as OptionValueInformation,
Validator("config_parse_sr_iov_vlan_proto", "0") to ConfigParseSrIovVlanProtoOptionValue() as OptionValueInformation,
Validator("config_parse_swap_priority", "0") to ConfigParseSwapPriorityOptionValue() as OptionValueInformation,
Validator("config_parse_tasks_max", "0") to ConfigParseTasksMaxOptionValue() as OptionValueInformation,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.ai

import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.SimpleGrammarOptionValues
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*

/**
* Validator for CPUSetPartition=.
*
* C function: config_parse_cpuset_partition, expanded via
* DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT in src/core/cgroup-util.c. The accepted values are
* exactly the entries of cpuset_partition_table in src/core/cgroup.c:
* - member
* - root
* - isolated
*
* Empty also resolves (to the default _CPUSET_PARTITION_INVALID), but the inspector won't be
* called on an empty value in any case.
*/
class ConfigParseCpusetPartitionOptionValue : SimpleGrammarOptionValues(
"config_parse_cpuset_partition",
SequenceCombinator(
LiteralChoiceTerminal("member", "root", "isolated"),
EOF()
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.ai

import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.SimpleGrammarOptionValues
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*

/**
* Validator for the [DHCPServer] address-list options: DNS=, NTP=, SIP=, POP3=, SMTP=, LPR=.
*
* (Not to be confused with the EmitDNS=, EmitNTP=, ... toggles, which are plain booleans.)
*
* C function: config_parse_dhcp_server_emit in src/network/networkd-dhcp-server.c. Each
* whitespace-separated word is either the literal token `_server_address` (resolved to the
* server's own address at runtime) or a non-null IPv4 address parsed via in_addr_from_string
* (AF_INET, ...). The grammar reflects that.
*/
class ConfigParseDhcpServerEmitOptionValue : SimpleGrammarOptionValues(
"config_parse_dhcp_server_emit",
SequenceCombinator(
AlternativeCombinator(LiteralChoiceTerminal("_server_address"), IPV4_ADDR),
ZeroOrMore(SequenceCombinator(
WhitespaceTerminal(),
AlternativeCombinator(LiteralChoiceTerminal("_server_address"), IPV4_ADDR)
)),
EOF()
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.ai

import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.SimpleGrammarOptionValues
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*

/**
* Validator for ManagedOOMMemoryPressureDurationSec=.
*
* C function: config_parse_managed_oom_mem_pressure_duration_sec in src/core/load-fragment.c.
* Empty resets to USEC_INFINITY. Otherwise calls parse_sec(rvalue) and additionally requires
* the result to be at least 1s and strictly less than infinity.
*
* The grammar matches parse_sec syntax (which is the existing TIME_VALUE: "infinity" or a
* compound time expression). The semantic "must be >= 1s and != infinity" can't be enforced
* by a grammar without arithmetic — leaving that as a runtime check (the systemd parser will
* still log a warning at unit load).
*/
class ConfigParseManagedOomMemPressureDurationSecOptionValue : SimpleGrammarOptionValues(
"config_parse_managed_oom_mem_pressure_duration_sec",
SequenceCombinator(
OptionalWhitespacePrefix(TIME_VALUE),
EOF()
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.ai

import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.SimpleGrammarOptionValues
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*

/**
* Validator for ManagedOOMMemoryPressureLimit=.
*
* C function: config_parse_managed_oom_mem_pressure_limit in src/core/load-fragment.c. After
* a "supported for this unit type" check it calls parse_permyriad(rvalue), which accepts
* N(.NN)?% / N(.N)?‰ / N‱. Only the ASCII percent form is matched here (the Unicode forms are
* vanishingly rare in unit files).
*/
class ConfigParseManagedOomMemPressureLimitOptionValue : SimpleGrammarOptionValues(
"config_parse_managed_oom_mem_pressure_limit",
SequenceCombinator(
AlternativeCombinator(
// 0..99 with optional one or two decimal places, followed by %
SequenceCombinator(IntegerTerminal(0, 100), ZeroOrOne(RegexTerminal("\\.[0-9]{1,2}", "\\.[0-9]{1,2}")), LiteralChoiceTerminal("%")),
// Exactly 100% or 100.0% / 100.00%
SequenceCombinator(LiteralChoiceTerminal("100"), ZeroOrOne(RegexTerminal("\\.0{1,2}", "\\.0{1,2}")), LiteralChoiceTerminal("%"))
),
EOF()
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.ai

import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.SimpleGrammarOptionValues
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*

/**
* Validator for the [SR-IOV] boolean options: MACSpoofCheck=, QueryReceiveSideScaling=, Trust=.
*
* C function: config_parse_sr_iov_boolean in src/shared/netif-sriov.c. After branching on the
* lvalue it calls parse_boolean(rvalue), so the accepted syntax is exactly the values handled
* by the existing BOOLEAN grammar terminal.
*/
class ConfigParseSrIovBooleanOptionValue : SimpleGrammarOptionValues(
"config_parse_sr_iov_boolean",
SequenceCombinator(
BOOLEAN,
EOF()
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.ai

import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.SimpleGrammarOptionValues
import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.grammar.*

/**
* Validator for the [SR-IOV] uint32 options: VirtualFunction=, VLANId=, QualityOfService=.
*
* C function: config_parse_sr_iov_uint32 in src/shared/netif-sriov.c. After branching on the
* lvalue it calls safe_atou32. Tighter per-lvalue bounds exist (VLANId 1..4095,
* VirtualFunction < INT_MAX) but they can't be expressed in this validator since it has no
* access to the lvalue at evaluation time. The conservative shape is "any uint32".
*/
class ConfigParseSrIovUint32OptionValue : SimpleGrammarOptionValues(
"config_parse_sr_iov_uint32",
SequenceCombinator(
IntegerTerminal(0, 4_294_967_296L),
EOF()
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.sjrx.intellij.plugins.systemdunitfiles.inspections.ai

import net.sjrx.intellij.plugins.systemdunitfiles.AbstractUnitFileTest
import net.sjrx.intellij.plugins.systemdunitfiles.inspections.InvalidValueInspection
import org.junit.Test

class ConfigParseCpusetPartitionOptionValueTest : AbstractUnitFileTest() {

@Test
fun testValidValues() {
// language="unit file (systemd)"
val file = """
[Service]
CPUSetPartition=member
CPUSetPartition=root
CPUSetPartition=isolated
""".trimIndent()

setupFileInEditor("file.service", file)
enableInspection(InvalidValueInspection::class.java)
val highlights = myFixture.doHighlighting()

assertSize(0, highlights)
}

@Test
fun testInvalidValues() {
// language="unit file (systemd)"
val file = """
[Service]
CPUSetPartition=<error descr="Invalid value">none</error>
CPUSetPartition=<error descr="Invalid value">Member</error>
CPUSetPartition=<error descr="Invalid value">root isolated</error>
CPUSetPartition=<error descr="Invalid value">123</error>
""".trimIndent()

setupFileInEditor("file.service", file)
enableInspection(InvalidValueInspection::class.java)
val highlights = myFixture.doHighlighting()

assertSize(4, highlights)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package net.sjrx.intellij.plugins.systemdunitfiles.inspections.ai

import net.sjrx.intellij.plugins.systemdunitfiles.AbstractUnitFileTest
import net.sjrx.intellij.plugins.systemdunitfiles.inspections.InvalidValueInspection
import org.junit.Test

class ConfigParseDhcpServerEmitOptionValueTest : AbstractUnitFileTest() {

@Test
fun testValidValues() {
// language="unit file (systemd)"
val file = """
[DHCPServer]
DNS=192.168.1.1
NTP=192.168.1.1 192.168.1.2
SIP=_server_address
POP3=_server_address 8.8.8.8
SMTP=8.8.4.4 1.1.1.1 _server_address
LPR=10.0.0.1
""".trimIndent()

setupFileInEditor("file.network", file)
enableInspection(InvalidValueInspection::class.java)
val highlights = myFixture.doHighlighting()

assertSize(0, highlights)
}

@Test
fun testInvalidValues() {
// language="unit file (systemd)"
val file = """
[DHCPServer]
DNS=<error descr="Invalid value">not-an-ip</error>
DNS=<error descr="Invalid value">192.168.1.256</error>
NTP=<error descr="Invalid value">::1</error>
SIP=<error descr="Invalid value">192.168.1.1, 192.168.1.2</error>
LPR=<error descr="Invalid value">_other_address</error>
""".trimIndent()

setupFileInEditor("file.network", file)
enableInspection(InvalidValueInspection::class.java)
val highlights = myFixture.doHighlighting()

assertSize(5, highlights)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.sjrx.intellij.plugins.systemdunitfiles.inspections.ai

import net.sjrx.intellij.plugins.systemdunitfiles.AbstractUnitFileTest
import net.sjrx.intellij.plugins.systemdunitfiles.inspections.InvalidValueInspection
import org.junit.Test

class ConfigParseManagedOomMemPressureDurationSecOptionValueTest : AbstractUnitFileTest() {

@Test
fun testValidValues() {
// language="unit file (systemd)"
val file = """
[Service]
ManagedOOMMemoryPressureDurationSec=infinity
ManagedOOMMemoryPressureDurationSec=10
ManagedOOMMemoryPressureDurationSec=30s
ManagedOOMMemoryPressureDurationSec=2min
ManagedOOMMemoryPressureDurationSec=1h
ManagedOOMMemoryPressureDurationSec=1min 30s
""".trimIndent()

setupFileInEditor("file.service", file)
enableInspection(InvalidValueInspection::class.java)
val highlights = myFixture.doHighlighting()

assertSize(0, highlights)
}

@Test
fun testInvalidValues() {
// language="unit file (systemd)"
val file = """
[Service]
ManagedOOMMemoryPressureDurationSec=<error descr="Invalid value">abc</error>
ManagedOOMMemoryPressureDurationSec=<error descr="Invalid value">-1s</error>
ManagedOOMMemoryPressureDurationSec=<error descr="Invalid value">10zz</error>
""".trimIndent()

setupFileInEditor("file.service", file)
enableInspection(InvalidValueInspection::class.java)
val highlights = myFixture.doHighlighting()

assertSize(3, highlights)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.sjrx.intellij.plugins.systemdunitfiles.inspections.ai

import net.sjrx.intellij.plugins.systemdunitfiles.AbstractUnitFileTest
import net.sjrx.intellij.plugins.systemdunitfiles.inspections.InvalidValueInspection
import org.junit.Test

class ConfigParseManagedOomMemPressureLimitOptionValueTest : AbstractUnitFileTest() {

@Test
fun testValidValues() {
// language="unit file (systemd)"
val file = """
[Service]
ManagedOOMMemoryPressureLimit=0%
ManagedOOMMemoryPressureLimit=50%
ManagedOOMMemoryPressureLimit=99.9%
ManagedOOMMemoryPressureLimit=12.34%
ManagedOOMMemoryPressureLimit=100%
ManagedOOMMemoryPressureLimit=100.0%
ManagedOOMMemoryPressureLimit=100.00%
""".trimIndent()

setupFileInEditor("file.service", file)
enableInspection(InvalidValueInspection::class.java)
val highlights = myFixture.doHighlighting()

assertSize(0, highlights)
}

@Test
fun testInvalidValues() {
// language="unit file (systemd)"
val file = """
[Service]
ManagedOOMMemoryPressureLimit=<error descr="Invalid value">50</error>
ManagedOOMMemoryPressureLimit=<error descr="Invalid value">100.1%</error>
ManagedOOMMemoryPressureLimit=<error descr="Invalid value">250%</error>
ManagedOOMMemoryPressureLimit=<error descr="Invalid value">abc</error>
ManagedOOMMemoryPressureLimit=<error descr="Invalid value">12.345%</error>
ManagedOOMMemoryPressureLimit=<error descr="Invalid value">-5%</error>
""".trimIndent()

setupFileInEditor("file.service", file)
enableInspection(InvalidValueInspection::class.java)
val highlights = myFixture.doHighlighting()

assertSize(6, highlights)
}
}
Loading
Loading