Exemplo n.º 1
0
        static void SendAppleBootList(DHCPRequest dhcpRequest)
        {
            Trace.WriteLine("Request Is An Apple NetBoot");
            int bsdpPort = 68;
            var vendorSpecificInformation = OptionData.GetOptionData(DHCPOption.VendorSpecificInformation, dhcpRequest.requestData);
            var strVendorInformation      = Utility.ByteArrayToString(vendorSpecificInformation, true);

            if (strVendorInformation.Length >= 21)
            {
                var isReturnPort = strVendorInformation.Substring(14, 4);
                if (isReturnPort == "0502")
                {
                    var returnPort = strVendorInformation.Substring(18, 4);
                    bsdpPort = Convert.ToInt32(returnPort, 16);
                }
            }

            var replyOptions = new DHCPReplyOptions();

            replyOptions.OtherOptions.Add(DHCPOption.Vendorclassidentifier, Settings.AAPLBSDPC);
            replyOptions.OtherOptions.Add(DHCPOption.VendorSpecificInformation, Utility.StringToByteArray(Settings.VendorInfo));
            var reply = new DHCPReply(dhcpRequest);

            reply.Send(DHCPMsgType.DHCPACK, replyOptions, bsdpPort);
        }
Exemplo n.º 2
0
        static void ProcessPXERequest(DHCPRequest dhcpRequest)
        {
            //Trace.WriteLine("Request Is A PXE Boot");
            var replyOptions = new DHCPReplyOptions();

            replyOptions.OtherOptions.Add(DHCPOption.Vendorclassidentifier, Settings.PXEClient);
            var reply = new DHCPReply(dhcpRequest);

            reply.Send(DHCPMsgType.DHCPOFFER, replyOptions, 68);
        }
Exemplo n.º 3
0
        static void SendSelectedNetBoot(DHCPRequest dhcpRequest)
        {
            //This Reply is the client selecting which image they want to boot from
            Trace.WriteLine("Request Is An Apple NetBoot Selection");

            var vendorSpecificInformation    = dhcpRequest.GetVendorSpecificInformation();
            var strVendorSpecificInformation = Utility.ByteArrayToString(vendorSpecificInformation, true);
            var imageIdHex            = strVendorSpecificInformation.Substring(strVendorSpecificInformation.Length - 4);
            var targetNbi             = Settings.RootPath.Replace("[nbi_id]", imageIdHex);
            var targetAppleBootFile   = Settings.AppleBootFile.Replace("[nbi_id]", imageIdHex);
            var clientHardwareAddress = new PhysicalAddress(dhcpRequest.GetChaddr());

            var replyOptions = new DHCPReplyOptions();

            replyOptions.NextServer = IPAddress.Parse(Settings.NextServer);
            replyOptions.OtherOptions.Add(DHCPOption.Vendorclassidentifier, Settings.AAPLBSDPC);
            replyOptions.OtherOptions.Add(DHCPOption.VendorSpecificInformation, Utility.StringToByteArray(Settings.VendorInfo));
            replyOptions.OtherOptions.Add(DHCPOption.RootPath, Encoding.UTF8.GetBytes(targetNbi));

            //Modification to allow both a clonedeploy linux and osx imaging environment to work simultaneously without two proxy dhcp servers running
            if (imageIdHex == "0F49" || imageIdHex == "98DB") //image ids of 3913 or 39131
            {
                replyOptions.BootFileName = Settings.AppleEFIBootFile;
            }
            else
            {
                replyOptions.BootFileName = targetAppleBootFile;
            }

            if (DHCPServer.Reservations.ContainsKey(clientHardwareAddress))
            {
                replyOptions.NextServer =
                    IPAddress.Parse(DHCPServer.Reservations[clientHardwareAddress].ReserveNextServer);
                replyOptions.BootFileName = DHCPServer.Reservations[clientHardwareAddress].ReserveBootFile;
            }

            var reply = new DHCPReply(dhcpRequest);

            reply.Send(DHCPMsgType.DHCPACK, replyOptions, 68);
        }
        static void ProcessProxyRequest(DHCPRequest dhcpRequest)
        {
            Trace.WriteLine("Request Is A Proxy PXE Boot");

            bool isWebReservation   = false;
            bool isLocalReservation = false;
            var  replyOptions       = new DHCPReplyOptions();

            var clientHardwareAddress = new PhysicalAddress(dhcpRequest.GetChaddr());

            if (DHCPServer.Reservations.ContainsKey(clientHardwareAddress))
            {
                isLocalReservation = true;
                Trace.WriteLine("Local Reservation Found");
                replyOptions.NextServer =
                    IPAddress.Parse(DHCPServer.Reservations[clientHardwareAddress].ReserveNextServer);
                replyOptions.BootFileName = DHCPServer.Reservations[clientHardwareAddress].ReserveBootFile;
                if (DHCPServer.Reservations[clientHardwareAddress].ReserveBCDFile != null)
                {
                    replyOptions.OtherOptions.Add(DHCPOption.Wpad,
                                                  Encoding.UTF8.GetBytes(DHCPServer.Reservations[clientHardwareAddress].ReserveBCDFile));
                }
            }
            else if (Settings.CheckWebReservations)
            {
                if (!string.IsNullOrEmpty(Settings.CloneDeployServiceURL))
                {
                    ProxyReservationDTO webReservation;

                    lock (dhcpRequest)
                    {
                        var mac = Utility.AddHexColons(Utility.ByteArrayToString(dhcpRequest.GetChaddr(), true));
                        webReservation = new APICall().ProxyDhcpApi.GetProxyReservation(mac);
                    }


                    if (webReservation.BootFile != null && webReservation.BootFile != "NotFound" &&
                        webReservation.BootFile != "NotEnabled")
                    {
                        isWebReservation = true;
                        Trace.WriteLine("Web Reservation Found");
                        if (!string.IsNullOrEmpty(webReservation.NextServer))
                        {
                            replyOptions.NextServer = IPAddress.Parse(webReservation.NextServer);
                        }
                        else
                        {
                            if (Settings.CheckTftpCluster)
                            {
                                var mac = Utility.AddHexColons(Utility.ByteArrayToString(dhcpRequest.GetChaddr(), true));
                                replyOptions.NextServer = new TftpCluster().GetNextServer(mac);
                            }
                            else
                            {
                                replyOptions.NextServer = IPAddress.Parse(Settings.NextServer);
                            }
                        }
                        replyOptions.BootFileName = webReservation.BootFile;
                        if (webReservation.BcdFile != null)
                        {
                            replyOptions.OtherOptions.Add(DHCPOption.Wpad,
                                                          Encoding.UTF8.GetBytes(webReservation.BcdFile));
                        }
                    }
                }
            }

            if (!isWebReservation && !isLocalReservation)
            {
                if (Settings.CheckTftpCluster && !string.IsNullOrEmpty(Settings.CloneDeployServiceURL))
                {
                    var mac = Utility.AddHexColons(Utility.ByteArrayToString(dhcpRequest.GetChaddr(), true));
                    replyOptions.NextServer = new TftpCluster().GetNextServer(mac);
                }
                else
                {
                    replyOptions.NextServer = IPAddress.Parse(Settings.NextServer);
                }

                var clientArch = dhcpRequest.GetClientSystemArch();
                if (clientArch != DHCPRequest.ClientSystemArch.Error)
                {
                    Trace.WriteLine("Client Architecture: " + clientArch);
                    bool unsupportedArch = false;
                    switch (clientArch)
                    {
                    case DHCPRequest.ClientSystemArch.Intelx86PC:     //legacy bios
                        replyOptions.BootFileName = Settings.BiosBootFile;
                        replyOptions.OtherOptions.Add(DHCPOption.Wpad, Encoding.UTF8.GetBytes(@"\boot\BCDx86"));
                        break;

                    case DHCPRequest.ClientSystemArch.EFIIA32:     //efi x86
                        replyOptions.BootFileName = Settings.Efi32BootFile;
                        replyOptions.OtherOptions.Add(DHCPOption.Wpad, Encoding.UTF8.GetBytes(@"\boot\BCDx86"));
                        break;

                    case DHCPRequest.ClientSystemArch.EFIBC:     //efi x64
                        replyOptions.BootFileName = Settings.Efi64BootFile;
                        replyOptions.OtherOptions.Add(DHCPOption.Wpad, Encoding.UTF8.GetBytes(@"\boot\BCDx64"));
                        break;

                    case DHCPRequest.ClientSystemArch.EFIx8664:     //efi x64
                        replyOptions.BootFileName = Settings.Efi64BootFile;
                        replyOptions.OtherOptions.Add(DHCPOption.Wpad, Encoding.UTF8.GetBytes(@"\boot\BCDx64"));
                        break;

                    default:
                        Trace.WriteLine("Unsupported Client System Architecture " + clientArch + " - Ignoring");
                        unsupportedArch = true;
                        break;
                    }

                    if (unsupportedArch)
                    {
                        return;
                    }
                }
                else
                {
                    Trace.WriteLine("Unsupported Client System Architecture " + clientArch + " - Ignoring");
                    return;
                }
            }


            var replyPort = dhcpRequest.GetSourcePort() == 4011 ? 4011 : 68;
            var reply     = new DHCPReply(dhcpRequest);

            reply.Send(DHCPMsgType.DHCPACK, replyOptions, replyPort);
        }
Exemplo n.º 5
0
        static void ProcessProxyRequest(DHCPRequest dhcpRequest)
        {
            Trace.WriteLine("Request Is A Proxy PXE Boot");

            var replyOptions = new DHCPReplyOptions();

            replyOptions.NextServer = IPAddress.Parse(Settings.NextServer);

            var clientHardwareAddress = new PhysicalAddress(dhcpRequest.GetChaddr());

            if (DHCPServer.Reservations.ContainsKey(clientHardwareAddress))
            {
                Trace.WriteLine("Local Reservation Found");
                replyOptions.NextServer =
                    IPAddress.Parse(DHCPServer.Reservations[clientHardwareAddress].ReserveNextServer);
                replyOptions.BootFileName = DHCPServer.Reservations[clientHardwareAddress].ReserveBootFile;
                if (DHCPServer.Reservations[clientHardwareAddress].ReserveBCDFile != null)
                {
                    replyOptions.OtherOptions.Add(DHCPOption.Wpad, Encoding.UTF8.GetBytes(DHCPServer.Reservations[clientHardwareAddress].ReserveBCDFile));
                }
            }
            else
            {
                //Check for Web Reservation
                var webReservation = new WebReservation();
                if (!string.IsNullOrEmpty(Settings.CloneDeployServiceURL))
                {
                    lock (dhcpRequest)
                    {
                        using (var client = new WebClient())
                        {
                            var mac  = Utility.AddHexColons(Utility.ByteArrayToString(dhcpRequest.GetChaddr(), true));
                            var json =
                                client.DownloadString(Settings.CloneDeployServiceURL + "GetProxyReservation?mac=" + mac);
                            webReservation = JsonConvert.DeserializeObject <WebReservation>(json);
                        }
                    }
                }

                if (webReservation.BootFile != null && webReservation.BootFile != "NotFound" &&
                    webReservation.BootFile != "NotEnabled")
                {
                    Trace.WriteLine("Web Reservation Found");
                    replyOptions.NextServer   = IPAddress.Parse(webReservation.NextServer);
                    replyOptions.BootFileName = webReservation.BootFile;
                    if (webReservation.BcdFile != null)
                    {
                        replyOptions.OtherOptions.Add(DHCPOption.Wpad, Encoding.UTF8.GetBytes(webReservation.BcdFile));
                    }
                }
                else
                {
                    Trace.WriteLine("No Reservation Found. Using Default config");
                    var clientArch = dhcpRequest.GetClientSystemArch();
                    if (clientArch != DHCPRequest.ClientSystemArch.Error)
                    {
                        Trace.WriteLine("Client Architecture: " + clientArch);
                        bool unsupportedArch = false;
                        switch (clientArch)
                        {
                        case DHCPRequest.ClientSystemArch.Intelx86PC:     //legacy bios
                            replyOptions.BootFileName = Settings.BiosBootFile;
                            replyOptions.OtherOptions.Add(DHCPOption.Wpad, Encoding.UTF8.GetBytes(@"\boot\BCDx86"));
                            break;

                        case DHCPRequest.ClientSystemArch.EFIIA32:     //efi x86
                            replyOptions.BootFileName = Settings.Efi32BootFile;
                            replyOptions.OtherOptions.Add(DHCPOption.Wpad, Encoding.UTF8.GetBytes(@"\boot\BCDx86"));
                            break;

                        case DHCPRequest.ClientSystemArch.EFIBC:     //efi x64
                            replyOptions.BootFileName = Settings.Efi64BootFile;
                            replyOptions.OtherOptions.Add(DHCPOption.Wpad, Encoding.UTF8.GetBytes(@"\boot\BCDx64"));
                            break;

                        case DHCPRequest.ClientSystemArch.EFIx8664:     //efi x64
                            replyOptions.BootFileName = Settings.Efi64BootFile;
                            replyOptions.OtherOptions.Add(DHCPOption.Wpad, Encoding.UTF8.GetBytes(@"\boot\BCDx64"));
                            break;

                        default:
                            Trace.WriteLine("Unsupported Client System Architecture " + clientArch + " - Ignoring");
                            unsupportedArch = true;
                            break;
                        }

                        if (unsupportedArch)
                        {
                            return;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Unsupported Client System Architecture " + clientArch + " - Ignoring");
                        return;
                    }
                }
            }

            var replyPort = dhcpRequest.GetSourcePort() == 4011 ? 4011 : 68;
            var reply     = new DHCPReply(dhcpRequest);

            reply.Send(DHCPMsgType.DHCPACK, replyOptions, replyPort);
        }