Add typed high-level ruleset and set API

This commit is contained in:
Vibe Myass
2026-03-16 03:51:49 +00:00
parent 458494221e
commit 1dfc6aebfd
12 changed files with 644 additions and 7 deletions

View File

@@ -18,6 +18,19 @@ public interface INftablesClient
/// <exception cref="NftNativeLoadException">Thrown when required native runtime components cannot be loaded.</exception>
NftValidationResult Validate(NftApplyRequest request, System.Threading.CancellationToken ct = default);
/// <summary>
/// Validates a typed nftables ruleset by rendering it to nft command text in dry-run mode.
/// </summary>
/// <param name="ruleset">The typed ruleset to validate.</param>
/// <param name="ct">A cancellation token.</param>
/// <returns>
/// A validation result. Invalid nft syntax or schema errors return <see cref="NftValidationResult.IsValid"/> = <see langword="false"/>.
/// </returns>
/// <exception cref="NftValidationException">Thrown when the typed model itself is invalid before native validation begins.</exception>
/// <exception cref="NftUnsupportedException">Thrown when runtime/platform is unsupported.</exception>
/// <exception cref="NftNativeLoadException">Thrown when required native runtime components cannot be loaded.</exception>
NftValidationResult ValidateRuleset(NftRuleset ruleset, System.Threading.CancellationToken ct = default);
/// <summary>
/// Asynchronously validates a ruleset request using dry-run mode.
/// </summary>
@@ -29,6 +42,17 @@ public interface INftablesClient
/// <exception cref="NftNativeLoadException">Thrown when required native runtime components cannot be loaded.</exception>
System.Threading.Tasks.Task<NftValidationResult> ValidateAsync(NftApplyRequest request, System.Threading.CancellationToken ct = default);
/// <summary>
/// Asynchronously validates a typed nftables ruleset by rendering it to nft command text in dry-run mode.
/// </summary>
/// <param name="ruleset">The typed ruleset to validate.</param>
/// <param name="ct">A cancellation token.</param>
/// <returns>A task that resolves to a validation result.</returns>
/// <exception cref="NftValidationException">Thrown when the typed model itself is invalid before native validation begins.</exception>
/// <exception cref="NftUnsupportedException">Thrown when runtime/platform is unsupported.</exception>
/// <exception cref="NftNativeLoadException">Thrown when required native runtime components cannot be loaded.</exception>
System.Threading.Tasks.Task<NftValidationResult> ValidateRulesetAsync(NftRuleset ruleset, System.Threading.CancellationToken ct = default);
/// <summary>
/// Applies a ruleset request.
/// </summary>
@@ -41,6 +65,18 @@ public interface INftablesClient
/// <exception cref="NftException">Thrown for other native execution failures.</exception>
void Apply(NftApplyRequest request, System.Threading.CancellationToken ct = default);
/// <summary>
/// Applies a typed nftables ruleset by rendering it to nft command text.
/// </summary>
/// <param name="ruleset">The typed ruleset to apply.</param>
/// <param name="ct">A cancellation token.</param>
/// <exception cref="NftValidationException">Thrown when the typed model itself is invalid or the rendered ruleset cannot be parsed/validated.</exception>
/// <exception cref="NftPermissionException">Thrown when insufficient privileges are available for runtime operation.</exception>
/// <exception cref="NftUnsupportedException">Thrown when runtime/platform is unsupported.</exception>
/// <exception cref="NftNativeLoadException">Thrown when required native runtime components cannot be loaded.</exception>
/// <exception cref="NftException">Thrown for other native execution failures.</exception>
void ApplyRuleset(NftRuleset ruleset, System.Threading.CancellationToken ct = default);
/// <summary>
/// Asynchronously applies a ruleset request.
/// </summary>
@@ -54,6 +90,19 @@ public interface INftablesClient
/// <exception cref="NftException">Thrown for other native execution failures.</exception>
System.Threading.Tasks.Task ApplyAsync(NftApplyRequest request, System.Threading.CancellationToken ct = default);
/// <summary>
/// Asynchronously applies a typed nftables ruleset by rendering it to nft command text.
/// </summary>
/// <param name="ruleset">The typed ruleset to apply.</param>
/// <param name="ct">A cancellation token.</param>
/// <returns>A completed task when apply succeeds.</returns>
/// <exception cref="NftValidationException">Thrown when the typed model itself is invalid or the rendered ruleset cannot be parsed/validated.</exception>
/// <exception cref="NftPermissionException">Thrown when insufficient privileges are available for runtime operation.</exception>
/// <exception cref="NftUnsupportedException">Thrown when runtime/platform is unsupported.</exception>
/// <exception cref="NftNativeLoadException">Thrown when required native runtime components cannot be loaded.</exception>
/// <exception cref="NftException">Thrown for other native execution failures.</exception>
System.Threading.Tasks.Task ApplyRulesetAsync(NftRuleset ruleset, System.Threading.CancellationToken ct = default);
/// <summary>
/// Captures the current nftables ruleset from the system.
/// </summary>