aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-01-06 07:48:55 -0600
committerGitHub <noreply@github.com>2023-01-06 07:48:55 -0600
commit9251a1be5f004f022a7e197112d89dd1972571fd (patch)
treef356bee09849a0a8cb0f391a14998d0eecbaaaca /src/slskd/Core
parent23c9d2fda9125f8bc0b35810521f2d53eead6be6 (diff)
parent20959a9a193a2148ddb5296bd22c832d87425177 (diff)
downloadslskd-9251a1be5f004f022a7e197112d89dd1972571fd.tar.gz
Merge pull request #822 from slskd/agent-cidr
Add CIDR filtering for Relay Agents
Diffstat (limited to 'src/slskd/Core')
-rw-r--r--src/slskd/Core/Options.cs35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index bc6f14a6..063da9e6 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -513,15 +513,46 @@ namespace slskd
/// <summary>
/// Relay agent configuration options.
/// </summary>
- public class RelayAgentConfigurationOptions
+ public class RelayAgentConfigurationOptions : IValidatableObject
{
/// <summary>
/// Gets the agent secret.
/// </summary>
+ [Description("shared secret for this agent")]
[StringLength(255, MinimumLength = 16)]
[NotNullOrWhiteSpace]
[Secret]
public string Secret { get; init; }
+
+ /// <summary>
+ /// Gets the comma separated list of CIDRs that are authorized to connect as this agent.
+ /// </summary>
+ [Description("optional; comma separated list of CIDRs that are authorized to connect as this agent")]
+ public string Cidr { get; init; } = "0.0.0.0/0,::/0";
+
+ /// <summary>
+ /// Extended validation.
+ /// </summary>
+ /// <param name="validationContext"></param>
+ /// <returns></returns>
+ public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
+ {
+ var results = new List<ValidationResult>();
+
+ foreach (var cidr in Cidr.Split(','))
+ {
+ try
+ {
+ _ = IPAddressRange.Parse(cidr);
+ }
+ catch (Exception ex)
+ {
+ results.Add(new ValidationResult($"CIDR {cidr} is invalid: {ex.Message}"));
+ }
+ }
+
+ return results;
+ }
}
}
@@ -1476,7 +1507,7 @@ namespace slskd
/// <summary>
/// Gets the comma separated list of CIDRs that are authorized to use the key.
/// </summary>
- [Description("An optional comma separated list of CIDRs that are authorized to use the key")]
+ [Description("optional; comma separated list of CIDRs that are authorized to use the key")]
public string Cidr { get; init; } = "0.0.0.0/0,::/0";
/// <summary>