private static uint HandlePktSendHook(ref IntPtr Packet, ref uint PacketSize, uint ControlCode, uint IpAddress, IntPtr Reserved, IntPtr PktContext) { var stopPropagation = false; var packet = new DhcpServerPacketWritable(Packet, (int)PacketSize); var serverAddress = DhcpServerIpAddress.FromNative(IpAddress); // ControlCode is ignored in this wrapper as: // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363294.aspx // "The only acceptable value in this version of the DHCP Server API is DHCP_SEND_PACKET." foreach (var consumer in Consumers) { if (consumer.SupportFlags.HasFlag(CalloutConsumerSupportFlags.PacketSend)) { try { consumer.Proxy.PacketSend(packet, serverAddress, ref stopPropagation); } catch (Win32Exception ex) { return((uint)ex.NativeErrorCode); } catch (Exception) { return(0x1U); //ERROR_INVALID_FUNCTION } // stop propagation if instructed if (stopPropagation) { break; } } } // write packet if (packet.BufferModified) { packet.WriteBuffer(Packet, ref PacketSize); } // chain if (!stopPropagation && ChainTable.DhcpPktSendHook != null) { return(ChainTable.DhcpPktSendHook(ref Packet, ref PacketSize, ControlCode, IpAddress, Reserved, PktContext)); } return(ERROR_SUCCESS); }
private static uint HandleNewPktHook(ref IntPtr Packet, ref uint PacketSize, uint IpAddress, IntPtr Reserved, IntPtr PktContext, out bool ProcessIt) { ProcessIt = true; var stopPropagation = false; var packet = new DhcpServerPacketWritable(Packet, (int)PacketSize); var serverAddress = DhcpServerIpAddress.FromNative(IpAddress); foreach (var consumer in Consumers) { if (consumer.SupportFlags.HasFlag(CalloutConsumerSupportFlags.NewPacket)) { try { consumer.Proxy.NewPacket(packet, serverAddress, ref ProcessIt, ref stopPropagation); } catch (Win32Exception ex) { return((uint)ex.NativeErrorCode); } catch (Exception) { return(0x1U); //ERROR_INVALID_FUNCTION } // stop propagation if instructed or the packet is not to be processed if (stopPropagation || !ProcessIt) { break; } } } // write packet if (ProcessIt && packet.BufferModified) { packet.WriteBuffer(Packet, ref PacketSize); } // chain if (ProcessIt && !stopPropagation && ChainTable.DhcpNewPktHook != null) { return(ChainTable.DhcpNewPktHook(ref Packet, ref PacketSize, IpAddress, Reserved, PktContext, out ProcessIt)); } return(ERROR_SUCCESS); }