aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/Configuration/IConfigurationManager.cs7
-rw-r--r--MediaBrowser.Common/MediaBrowser.Common.csproj3
-rw-r--r--MediaBrowser.Common/Net/INetworkManager.cs230
3 files changed, 188 insertions, 52 deletions
diff --git a/MediaBrowser.Common/Configuration/IConfigurationManager.cs b/MediaBrowser.Common/Configuration/IConfigurationManager.cs
index fe726090d..17520f8a3 100644
--- a/MediaBrowser.Common/Configuration/IConfigurationManager.cs
+++ b/MediaBrowser.Common/Configuration/IConfigurationManager.cs
@@ -47,10 +47,11 @@ namespace MediaBrowser.Common.Configuration
void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration);
/// <summary>
- /// Gets the configuration.
+ /// Manually pre-loads a factory so that it is available pre system initialisation.
/// </summary>
- /// <param name="key">The key.</param>
- /// <returns>System.Object.</returns>
+ /// <typeparam name="T">Class to register.</typeparam>
+ void RegisterConfiguration<T>();
+
object GetConfiguration(string key);
/// <summary>
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj
index e716a6610..d992f6b09 100644
--- a/MediaBrowser.Common/MediaBrowser.Common.csproj
+++ b/MediaBrowser.Common/MediaBrowser.Common.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<!-- ProjectGuid is only included as a requirement for SonarQube analysis -->
<PropertyGroup>
@@ -22,6 +22,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.9" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.8" />
+ <PackageReference Include="NetworkCollection" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
diff --git a/MediaBrowser.Common/Net/INetworkManager.cs b/MediaBrowser.Common/Net/INetworkManager.cs
index a0330afef..f60f369d6 100644
--- a/MediaBrowser.Common/Net/INetworkManager.cs
+++ b/MediaBrowser.Common/Net/INetworkManager.cs
@@ -1,97 +1,231 @@
-#pragma warning disable CS1591
-
+#nullable enable
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
+using Microsoft.AspNetCore.Http;
+using NetworkCollection;
namespace MediaBrowser.Common.Net
{
+ /// <summary>
+ /// Interface for the NetworkManager class.
+ /// </summary>
public interface INetworkManager
{
+ /// <summary>
+ /// Event triggered on network changes.
+ /// </summary>
event EventHandler NetworkChanged;
/// <summary>
- /// Gets or sets a function to return the list of user defined LAN addresses.
+ /// Gets the published server urls list.
+ /// </summary>
+ Dictionary<IPNetAddress, string> PublishedServerUrls { get; }
+
+ /// <summary>
+ /// Gets a value indicating whether is all IPv6 interfaces are trusted as internal.
+ /// </summary>
+ bool TrustAllIP6Interfaces { get; }
+
+ /// <summary>
+ /// Gets the remote address filter.
+ /// </summary>
+ NetCollection RemoteAddressFilter { get; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether iP6 is enabled.
/// </summary>
- Func<string[]> LocalSubnetsFn { get; set; }
+ bool IsIP6Enabled { get; set; }
/// <summary>
- /// Gets a random port TCP number that is currently available.
+ /// Gets or sets a value indicating whether iP4 is enabled.
/// </summary>
- /// <returns>System.Int32.</returns>
- int GetRandomUnusedTcpPort();
+ bool IsIP4Enabled { get; set; }
/// <summary>
- /// Gets a random port UDP number that is currently available.
+ /// Calculates the list of interfaces to use for Kestrel.
/// </summary>
- /// <returns>System.Int32.</returns>
- int GetRandomUnusedUdpPort();
+ /// <returns>A NetCollection object containing all the interfaces to bind.
+ /// If all the interfaces are specified, and none are excluded, it returns zero items
+ /// to represent any address.</returns>
+ /// <param name="individualInterfaces">When false, return <see cref="IPAddress.Any"/> or <see cref="IPAddress.IPv6Any"/> for all interfaces.</param>
+ NetCollection GetAllBindInterfaces(bool individualInterfaces = false);
/// <summary>
- /// Returns the MAC Address from first Network Card in Computer.
+ /// Returns a collection containing the loopback interfaces.
/// </summary>
- /// <returns>The MAC Address.</returns>
+ /// <returns>Netcollection.</returns>
+ NetCollection GetLoopbacks();
+
+ /// <summary>
+ /// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
+ /// If no bind addresses are specified, an internal interface address is selected.
+ /// The priority of selection is as follows:-
+ ///
+ /// The value contained in the startup parameter --published-server-url.
+ ///
+ /// If the user specified custom subnet overrides, the correct subnet for the source address.
+ ///
+ /// If the user specified bind interfaces to use:-
+ /// The bind interface that contains the source subnet.
+ /// The first bind interface specified that suits best first the source's endpoint. eg. external or internal.
+ ///
+ /// If the source is from a public subnet address range and the user hasn't specified any bind addresses:-
+ /// The first public interface that isn't a loopback and contains the source subnet.
+ /// The first public interface that isn't a loopback. Priority is given to interfaces with gateways.
+ /// An internal interface if there are no public ip addresses.
+ ///
+ /// If the source is from a private subnet address range and the user hasn't specified any bind addresses:-
+ /// The first private interface that contains the source subnet.
+ /// The first private interface that isn't a loopback. Priority is given to interfaces with gateways.
+ ///
+ /// If no interfaces meet any of these criteria, then a loopback address is returned.
+ ///
+ /// Interface that have been specifically excluded from binding are not used in any of the calculations.
+ /// </summary>
+ /// <param name="source">Source of the request.</param>
+ /// <param name="port">Optional port returned, if it's part of an override.</param>
+ /// <returns>IP Address to use, or loopback address if all else fails.</returns>
+ string GetBindInterface(IPObject source, out int? port);
+
+ /// <summary>
+ /// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
+ /// If no bind addresses are specified, an internal interface address is selected.
+ /// (See <see cref="GetBindInterface(IPObject, out int?)"/>.
+ /// </summary>
+ /// <param name="source">Source of the request.</param>
+ /// <param name="port">Optional port returned, if it's part of an override.</param>
+ /// <returns>IP Address to use, or loopback address if all else fails.</returns>
+ string GetBindInterface(HttpRequest source, out int? port);
+
+ /// <summary>
+ /// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
+ /// If no bind addresses are specified, an internal interface address is selected.
+ /// (See <see cref="GetBindInterface(IPObject, out int?)"/>.
+ /// </summary>
+ /// <param name="source">IP address of the request.</param>
+ /// <param name="port">Optional port returned, if it's part of an override.</param>
+ /// <returns>IP Address to use, or loopback address if all else fails.</returns>
+ string GetBindInterface(IPAddress source, out int? port);
+
+ /// <summary>
+ /// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
+ /// If no bind addresses are specified, an internal interface address is selected.
+ /// (See <see cref="GetBindInterface(IPObject, out int?)"/>.
+ /// </summary>
+ /// <param name="source">Source of the request.</param>
+ /// <param name="port">Optional port returned, if it's part of an override.</param>
+ /// <returns>IP Address to use, or loopback address if all else fails.</returns>
+ string GetBindInterface(string source, out int? port);
+
+ /// <summary>
+ /// Checks to see if the ip address is specifically excluded in LocalNetworkAddresses.
+ /// </summary>
+ /// <param name="address">IP address to check.</param>
+ /// <returns>True if it is.</returns>
+ bool IsExcludedInterface(IPAddress address);
+
+ /// <summary>
+ /// Get a list of all the MAC addresses associated with active interfaces.
+ /// </summary>
+ /// <returns>List of MAC addresses.</returns>
List<PhysicalAddress> GetMacAddresses();
/// <summary>
- /// Determines whether [is in private address space] [the specified endpoint].
+ /// Checks to see if the IP Address provided matches an interface that has a gateway.
+ /// </summary>
+ /// <param name="addressObj">IP to check. Can be an IPAddress or an IPObject.</param>
+ /// <returns>Result of the check.</returns>
+ bool IsGatewayInterface(object? addressObj);
+
+ /// <summary>
+ /// Returns true if the address is a private address.
+ /// The config option TrustIP6Interfaces overrides this functions behaviour.
+ /// </summary>
+ /// <param name="address">Address to check.</param>
+ /// <returns>True or False.</returns>
+ bool IsPrivateAddressRange(IPObject address);
+
+ /// <summary>
+ /// Returns true if the address is part of the user defined LAN.
+ /// The config option TrustIP6Interfaces overrides this functions behaviour.
+ /// </summary>
+ /// <param name="address">IP to check.</param>
+ /// <returns>True if endpoint is within the LAN range.</returns>
+ bool IsInLocalNetwork(string address);
+
+ /// <summary>
+ /// Returns true if the address is part of the user defined LAN.
+ /// The config option TrustIP6Interfaces overrides this functions behaviour.
+ /// </summary>
+ /// <param name="address">IP to check.</param>
+ /// <returns>True if endpoint is within the LAN range.</returns>
+ bool IsInLocalNetwork(IPObject address);
+
+ /// <summary>
+ /// Returns true if the address is part of the user defined LAN.
+ /// The config option TrustIP6Interfaces overrides this functions behaviour.
+ /// </summary>
+ /// <param name="address">IP to check.</param>
+ /// <returns>True if endpoint is within the LAN range.</returns>
+ bool IsInLocalNetwork(IPAddress address);
+
+ /// <summary>
+ /// Attempts to convert the token to an IP address, permitting for interface descriptions and indexes.
+ /// eg. "eth1", or "TP-LINK Wireless USB Adapter".
/// </summary>
- /// <param name="endpoint">The endpoint.</param>
- /// <returns><c>true</c> if [is in private address space] [the specified endpoint]; otherwise, <c>false</c>.</returns>
- bool IsInPrivateAddressSpace(string endpoint);
+ /// <param name="token">Token to parse.</param>
+ /// <param name="result">Resultant object's ip addresses, if successful.</param>
+ /// <returns>Success of the operation.</returns>
+ bool TryParseInterface(string token, out NetCollection? result);
/// <summary>
- /// Determines whether [is in private address space 10.x.x.x] [the specified endpoint] and exists in the subnets returned by GetSubnets().
+ /// Parses an array of strings into a NetCollection.
/// </summary>
- /// <param name="endpoint">The endpoint.</param>
- /// <returns><c>true</c> if [is in private address space 10.x.x.x] [the specified endpoint]; otherwise, <c>false</c>.</returns>
- bool IsInPrivateAddressSpaceAndLocalSubnet(string endpoint);
+ /// <param name="values">Values to parse.</param>
+ /// <param name="bracketed">When true, only include values in []. When false, ignore bracketed values.</param>
+ /// <returns>IPCollection object containing the value strings.</returns>
+ NetCollection CreateIPCollection(string[] values, bool bracketed = false);
/// <summary>
- /// Determines whether [is in local network] [the specified endpoint].
+ /// Returns all the internal Bind interface addresses.
/// </summary>
- /// <param name="endpoint">The endpoint.</param>
- /// <returns><c>true</c> if [is in local network] [the specified endpoint]; otherwise, <c>false</c>.</returns>
- bool IsInLocalNetwork(string endpoint);
+ /// <returns>An internal list of interfaces addresses.</returns>
+ NetCollection GetInternalBindAddresses();
/// <summary>
- /// Investigates an caches a list of interface addresses, excluding local link and LAN excluded addresses.
+ /// Checks to see if an IP address is still a valid interface address.
/// </summary>
- /// <returns>The list of ipaddresses.</returns>
- IPAddress[] GetLocalIpAddresses();
+ /// <param name="address">IP address to check.</param>
+ /// <returns>True if it is.</returns>
+ bool IsValidInterfaceAddress(IPAddress address);
/// <summary>
- /// Checks if the given address falls within the ranges given in [subnets]. The addresses in subnets can be hosts or subnets in the CIDR format.
+ /// Returns true if the IP address is in the excluded list.
/// </summary>
- /// <param name="addressString">The address to check.</param>
- /// <param name="subnets">If true, check against addresses in the LAN settings surrounded by brackets ([]).</param>
- /// <returns><c>true</c>if the address is in at least one of the given subnets, <c>false</c> otherwise.</returns>
- bool IsAddressInSubnets(string addressString, string[] subnets);
+ /// <param name="ip">IP to check.</param>
+ /// <returns>True if excluded.</returns>
+ bool IsExcluded(IPAddress ip);
/// <summary>
- /// Returns true if address is in the LAN list in the config file.
+ /// Returns true if the IP address is in the excluded list.
/// </summary>
- /// <param name="address">The address to check.</param>
- /// <param name="excludeInterfaces">If true, check against addresses in the LAN settings which have [] arroud and return true if it matches the address give in address.</param>
- /// <param name="excludeRFC">If true, returns false if address is in the 127.x.x.x or 169.128.x.x range.</param>
- /// <returns><c>false</c>if the address isn't in the LAN list, <c>true</c> if the address has been defined as a LAN address.</returns>
- bool IsAddressInSubnets(IPAddress address, bool excludeInterfaces, bool excludeRFC);
+ /// <param name="ip">IP to check.</param>
+ /// <returns>True if excluded.</returns>
+ bool IsExcluded(EndPoint ip);
/// <summary>
- /// Checks if address is in the LAN list in the config file.
+ /// Gets the filtered LAN ip addresses.
/// </summary>
- /// <param name="address1">Source address to check.</param>
- /// <param name="address2">Destination address to check against.</param>
- /// <param name="subnetMask">Destination subnet to check against.</param>
- /// <returns><c>true/false</c>depending on whether address1 is in the same subnet as IPAddress2 with subnetMask.</returns>
- bool IsInSameSubnet(IPAddress address1, IPAddress address2, IPAddress subnetMask);
+ /// <param name="filter">Optional filter for the list.</param>
+ /// <returns>Returns a filtered list of LAN addresses.</returns>
+ NetCollection GetFilteredLANSubnets(NetCollection? filter = null);
/// <summary>
- /// Returns the subnet mask of an interface with the given address.
+ /// Reloads all settings and re-initialises the instance.
/// </summary>
- /// <param name="address">The address to check.</param>
- /// <returns>Returns the subnet mask of an interface with the given address, or null if an interface match cannot be found.</returns>
- IPAddress GetLocalIpSubnetMask(IPAddress address);
+ /// <param name="configuration">The configuration to use.</param>
+ void UpdateSettings(object configuration);
}
}