global using System; global using System.Runtime.InteropServices; global using Vanara.Extensions; global using Vanara.InteropServices; global using static Vanara.PInvoke.Ws2_32; global using IN_ADDR_IPV4 = Vanara.PInvoke.Ws2_32.IN_ADDR; global using IN_ADDR_IPV6 = Vanara.PInvoke.Ws2_32.IN6_ADDR; namespace Vanara.PInvoke; /// Items from Qwave.dll. public static partial class Qwave { /// /// This flag can be used to prevent any rsvp signaling messages from being sent. Local traffic control will be invoked, but no RSVP Path /// messages will be sent. This flag can also be used in conjunction with a receiving flowspec to suppress the automatic generation of a /// Reserve message. The application would receive notification that a Path message had arrived and would then need to alter the QOS by /// issuing WSAIoctl( SIO_SET_QOS ), to unset this flag and thereby causing Reserve messages to go out. /// public const uint SERVICE_NO_QOS_SIGNALING = 0x40000000; private const uint QOS_GENERAL_ID_BASE = 2000; private const uint RSVP_OBJECT_ID_BASE = 1000; private const uint QOS_TRAFFIC_GENERAL_ID_BASE = 4000; /// Specifies the type of object to which QOS_OBJECT_HDR is attached. [PInvokeData("qos.h", MSDNShortId = "NS:qos.__unnamed_struct_0")] public enum QOS_OBJ_TYPE : uint { /// QOS_End_of_list structure passed [CorrespondingType(typeof(QOS_OBJECT_HDR))] QOS_OBJECT_END_OF_LIST = 0x00000001 + QOS_GENERAL_ID_BASE, /// QOS_ShapeDiscard structure passed [CorrespondingType(typeof(QOS_SD_MODE))] QOS_OBJECT_SD_MODE = 0x00000002 + QOS_GENERAL_ID_BASE, /// QOS_ShapingRate structure [CorrespondingType(typeof(QOS_SHAPING_RATE))] QOS_OBJECT_SHAPING_RATE = 0x00000003 + QOS_GENERAL_ID_BASE, /// QOS_DestAddr structure (defined in qossp.h) [CorrespondingType(typeof(QOS_DESTADDR))] QOS_OBJECT_DESTADDR = 0x00000004 + QOS_GENERAL_ID_BASE, /// QOS_DS_CLASS structure [CorrespondingType(typeof(QOS_DS_CLASS))] QOS_OBJECT_DS_CLASS = 0x00000001 + QOS_TRAFFIC_GENERAL_ID_BASE, /// QOS_TRAFFIC_CLASS structure [CorrespondingType(typeof(QOS_TRAFFIC_CLASS))] QOS_OBJECT_TRAFFIC_CLASS = 0x00000002 + QOS_TRAFFIC_GENERAL_ID_BASE, /// QOS_DIFFSERV structure [CorrespondingType(typeof(QOS_DIFFSERV))] QOS_OBJECT_DIFFSERV = 0x00000003 + QOS_TRAFFIC_GENERAL_ID_BASE, /// QOS_TCP_TRAFFIC structure [CorrespondingType(typeof(QOS_TCP_TRAFFIC))] QOS_OBJECT_TCP_TRAFFIC = 0x00000004 + QOS_TRAFFIC_GENERAL_ID_BASE, /// QOS_FRIENDLY_NAME structure [CorrespondingType(typeof(QOS_FRIENDLY_NAME))] QOS_OBJECT_FRIENDLY_NAME = 0x00000005 + QOS_TRAFFIC_GENERAL_ID_BASE, /// RSVP_STATUS_INFO structure [CorrespondingType(typeof(RSVP_STATUS_INFO))] RSVP_OBJECT_STATUS_INFO = 0x00000000 + RSVP_OBJECT_ID_BASE, /// RSVP_RESERVE_INFO structure [CorrespondingType(typeof(RSVP_RESERVE_INFO))] RSVP_OBJECT_RESERVE_INFO = 0x00000001 + RSVP_OBJECT_ID_BASE, /// RSVP_ADSPEC structure [CorrespondingType(typeof(RSVP_ADSPEC))] RSVP_OBJECT_ADSPEC = 0x00000002 + RSVP_OBJECT_ID_BASE, /// RSVP_POLICY_INFO structure [CorrespondingType(typeof(RSVP_POLICY_INFO))] RSVP_OBJECT_POLICY_INFO = 0x00000003 + RSVP_OBJECT_ID_BASE, /// RSVP_FILTERSPEC structure [CorrespondingType(typeof(RSVP_FILTERSPEC))] RSVP_OBJECT_FILTERSPEC_LIST = 0x00000004 + RSVP_OBJECT_ID_BASE, } /// Specifies the requested behavior of the packet shaper. [PInvokeData("qos.h", MSDNShortId = "NS:qos._QOS_SD_MODE")] public enum TC_NONCONF { /// /// This mode is currently only available to the TC API. It is not available to users of the QOS API. Instructs the packet shaper to /// borrow remaining available resources after all higher priority flows have been serviced. If the TokenRate member of /// FLOWSPEC is specified for this flow, packets that exceed the value of TokenRate will have their priority demoted to less /// than SERVICETYPE_BESTEFFORT, as defined in the ServiceType member of the FLOWSPEC structure. /// TC_NONCONF_BORROW = 0, /// /// Instructs the packet shaper to retain packets until network resources are available to the flow in sufficient quantity to make /// such packets conforming. (For example, a 100K packet will be retained in the packet shaper until 100K worth of credit is accrued /// for the flow, allowing the packet to be transmitted as conforming). Note that TokenRate must be specified if using TC_NONCONF_SHAPE. /// TC_NONCONF_SHAPE = 1, /// Instructs the packet shaper to discard all nonconforming packets. TC_NONCONF_DISCARD should be used with care. TC_NONCONF_DISCARD = 2, /// Not currently supported. TC_NONCONF_BORROW_PLUS = 3, } /// Represents a structure that starts with . public interface IQoSObjectHdr { } /// The QOS object QOS_OBJECT_HDR is attached to each QOS object. It specifies the object type and its length. // https://learn.microsoft.com/en-us/windows/win32/api/qos/ns-qos-qos_object_hdr typedef struct { ULONG ObjectType; ULONG ObjectLength; } // QOS_OBJECT_HDR, *LPQOS_OBJECT_HDR; [PInvokeData("qos.h", MSDNShortId = "NS:qos.__unnamed_struct_0")] [StructLayout(LayoutKind.Sequential)] public struct QOS_OBJECT_HDR { /// /// Specifies the type of object to which QOS_OBJECT_HDR is attached. The following values are valid for QOS_OBJECT_HDR: /// QOS_OBJECT_DESTADDR /// QOS_OBJECT_END_OF_LIST /// QOS_OBJECT_SD_MODE /// QOS_OBJECT_SHAPING_RATE /// RSVP_OBJECT_ADSPEC /// RSVP_OBJECT_FILTERSPEC_LIST /// RSVP_OBJECT_POLICY_INFO /// RSVP_OBJECT_RESERVE_INFO /// public QOS_OBJ_TYPE ObjectType; /// Specifies the length of the attached object, inclusive of QOS_OBJECT_HDR. public uint ObjectLength; /// Initializes this instance from a type. /// The structure to use. /// Initialized header. /// public static QOS_OBJECT_HDR Init() where T : IQoSObjectHdr { var ot = CorrespondingTypeAttribute.CanGet(typeof(T), out var e) ? e : throw new ArgumentException(); return new() { ObjectType = ot, ObjectLength = (uint)Marshal.SizeOf(typeof(T)) }; } } /// The QOS object QOS_SD_MODE defines the behavior of the traffic control-packet shaper component. // https://learn.microsoft.com/en-us/windows/win32/api/qos/ns-qos-qos_sd_mode typedef struct _QOS_SD_MODE { QOS_OBJECT_HDR ObjectHdr; // ULONG ShapeDiscardMode; } QOS_SD_MODE, *LPQOS_SD_MODE; [PInvokeData("qos.h", MSDNShortId = "NS:qos._QOS_SD_MODE")] [StructLayout(LayoutKind.Sequential)] public struct QOS_SD_MODE : IQoSObjectHdr { /// The QOS object QOS_OBJECT_HDR. The object type for this QOS object should be QOS_SD_MODE. public QOS_OBJECT_HDR ObjectHdr; /// /// /// Specifies the requested behavior of the packet shaper. Note that there are elements of packet handling within these predefined /// behaviors that depend on the flow settings specified within FLOWSPEC. /// /// /// /// Value /// Meaning /// /// /// TC_NONCONF_BORROW /// /// This mode is currently only available to the TC API. It is not available to users of the QOS API. Instructs the packet shaper to /// borrow remaining available resources after all higher priority flows have been serviced. If the TokenRate member of /// FLOWSPEC is specified for this flow, packets that exceed the value of TokenRate will have their priority demoted to less /// than SERVICETYPE_BESTEFFORT, as defined in the ServiceType member of the FLOWSPEC structure. /// /// /// /// TC_NONCONF_SHAPE /// /// Instructs the packet shaper to retain packets until network resources are available to the flow in sufficient quantity to make /// such packets conforming. (For example, a 100K packet will be retained in the packet shaper until 100K worth of credit is accrued /// for the flow, allowing the packet to be transmitted as conforming). Note that TokenRate must be specified if using TC_NONCONF_SHAPE. /// /// /// /// TC_NONCONF_DISCARD /// Instructs the packet shaper to discard all nonconforming packets. TC_NONCONF_DISCARD should be used with care. /// /// /// public TC_NONCONF ShapeDiscardMode; } /// The QOS object QOS_SHAPING_RATE specifies the uniform traffic shaping rate be applied to a given flow. // https://learn.microsoft.com/en-us/windows/win32/api/qos/ns-qos-qos_shaping_rate typedef struct _QOS_SHAPING_RATE { QOS_OBJECT_HDR // ObjectHdr; ULONG ShapingRate; } QOS_SHAPING_RATE, *LPQOS_SHAPING_RATE; [PInvokeData("qos.h", MSDNShortId = "NS:qos._QOS_SHAPING_RATE")] [StructLayout(LayoutKind.Sequential)] public struct QOS_SHAPING_RATE : IQoSObjectHdr { /// The QOS object QOS_OBJECT_HDR. The object type for this QOS object should be QOS_SHAPING_RATE. public QOS_OBJECT_HDR ObjectHdr; /// Unsigned 32-bit integer that specifies the uniform traffic shaping rate in bytes per second. public uint ShapingRate; } }