X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIp4Dxe%2FIp4Impl.c;h=6a26143e307d3e4effe40bc1f190fb0833afd3d0;hp=2fb4f4c1ca2abd3d7dc820fc5798445cc44abf4a;hb=a5f525fc48a71521f69e395d85a36d72917eeabd;hpb=3d0a49ad47619c30c84bbee8a33f54b64dddbcec diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c index 2fb4f4c1ca..6a26143e30 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c @@ -1,6 +1,6 @@ /** @file -Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -550,6 +550,7 @@ Ip4InitProtocol ( IpInstance->Signature = IP4_PROTOCOL_SIGNATURE; CopyMem (&IpInstance->Ip4Proto, &mEfiIp4ProtocolTemplete, sizeof (IpInstance->Ip4Proto)); IpInstance->State = IP4_STATE_UNCONFIGED; + IpInstance->InDestroy = FALSE; IpInstance->Service = IpSb; InitializeListHead (&IpInstance->Link); @@ -563,7 +564,6 @@ Ip4InitProtocol ( } - /** Configure the IP4 child. If the child is already configured, change the configuration parameter. Otherwise configure it @@ -596,9 +596,13 @@ Ip4ConfigProtocol ( IP4_ADDR Ip; IP4_ADDR Netmask; EFI_ARP_PROTOCOL *Arp; + EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2; + EFI_IP4_CONFIG2_POLICY Policy; IpSb = IpInstance->Service; + Ip4Config2 = NULL; + // // User is changing packet filters. It must be stopped // before the station address can be changed. @@ -674,14 +678,26 @@ Ip4ConfigProtocol ( } else { // - // Use the default address. If the default configuration hasn't - // been started, start it. + // Use the default address. Check the state. // if (IpSb->State == IP4_SERVICE_UNSTARTED) { - Status = Ip4StartAutoConfig (&IpSb->Ip4Config2Instance); - - if (EFI_ERROR (Status)) { - goto ON_ERROR; + // + // Trigger the EFI_IP4_CONFIG2_PROTOCOL to retrieve the + // default IPv4 address if it is not available yet. + // + Policy = IpSb->Ip4Config2Instance.Policy; + if (Policy != Ip4Config2PolicyDhcp) { + Ip4Config2 = &IpSb->Ip4Config2Instance.Ip4Config2; + Policy = Ip4Config2PolicyDhcp; + Status= Ip4Config2->SetData ( + Ip4Config2, + Ip4Config2DataTypePolicy, + sizeof (EFI_IP4_CONFIG2_POLICY), + &Policy + ); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } } } @@ -711,6 +727,7 @@ Ip4ConfigProtocol ( EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER ); if (EFI_ERROR (Status)) { + Ip4FreeInterface (IpIf, IpInstance); goto ON_ERROR; } } @@ -811,66 +828,6 @@ Ip4CleanProtocol ( } -/** - Validate that Ip/Netmask pair is OK to be used as station - address. Only continuous netmasks are supported. and check - that StationAddress is a unicast address on the newtwork. - - @param[in] Ip The IP address to validate. - @param[in] Netmask The netmaks of the IP. - - @retval TRUE The Ip/Netmask pair is valid. - @retval FALSE The Ip/Netmask pair is invalid. - -**/ -BOOLEAN -Ip4StationAddressValid ( - IN IP4_ADDR Ip, - IN IP4_ADDR Netmask - ) -{ - IP4_ADDR NetBrdcastMask; - INTN Len; - INTN Type; - - // - // Only support the station address with 0.0.0.0/0 to enable DHCP client. - // - if (Netmask == IP4_ALLZERO_ADDRESS) { - return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS); - } - - // - // Only support the continuous net masks - // - if ((Len = NetGetMaskLength (Netmask)) == IP4_MASK_NUM) { - return FALSE; - } - - // - // Station address can't be class D or class E address - // - if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) { - return FALSE; - } - - // - // Station address can't be subnet broadcast/net broadcast address - // - if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) { - return FALSE; - } - - NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)]; - - if (Ip == (Ip | ~NetBrdcastMask)) { - return FALSE; - } - - return TRUE; -} - - /** Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance. @@ -998,8 +955,7 @@ EfiIp4Configure ( Status = Ip4CleanProtocol (IpInstance); // - // Don't change the state if it is DESTROY, consider the following - // valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped, + // Consider the following valid sequence: Mnp is unloaded-->Ip Stopped-->Udp Stopped, // Configure (ThisIp, NULL). If the state is changed to UNCONFIGED, // the unload fails miserably. // @@ -1092,8 +1048,8 @@ Ip4Groups ( // is decreamented each time an address is removed.. // for (Index = IpInstance->GroupCount; Index > 0 ; Index--) { + ASSERT (IpInstance->Groups != NULL); Group = IpInstance->Groups[Index - 1]; - if ((GroupAddress == NULL) || EFI_IP4_EQUAL (&Group, GroupAddress)) { if (EFI_ERROR (Ip4LeaveGroup (IpInstance, NTOHL (Group)))) { return EFI_DEVICE_ERROR; @@ -2293,12 +2249,10 @@ Ip4SentPacketTicking ( return EFI_SUCCESS; } - /** - The heart beat timer of IP4 service instance. It times out - all of its IP4 children's received-but-not-delivered and - transmitted-but-not-recycle packets, and provides time input - for its IGMP protocol. + This heart beat timer of IP4 service instance times out all of its IP4 children's + received-but-not-delivered and transmitted-but-not-recycle packets, and provides + time input for its IGMP protocol. @param[in] Event The IP4 service instance's heart beat timer. @param[in] Context The IP4 service instance. @@ -2315,7 +2269,64 @@ Ip4TimerTicking ( IpSb = (IP4_SERVICE *) Context; NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE); - + Ip4PacketTimerTicking (IpSb); Ip4IgmpTicking (IpSb); } + +/** + This dedicated timer is used to poll underlying network media status. In case + of cable swap or wireless network switch, a new round auto configuration will + be initiated. The timer will signal the IP4 to run DHCP configuration again. + IP4 driver will free old IP address related resource, such as route table and + Interface, then initiate a DHCP process to acquire new IP, eventually create + route table for new IP address. + + @param[in] Event The IP4 service instance's heart beat timer. + @param[in] Context The IP4 service instance. + +**/ +VOID +EFIAPI +Ip4TimerReconfigChecking ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + IP4_SERVICE *IpSb; + BOOLEAN OldMediaPresent; + EFI_STATUS Status; + EFI_SIMPLE_NETWORK_MODE SnpModeData; + + IpSb = (IP4_SERVICE *) Context; + NET_CHECK_SIGNATURE (IpSb, IP4_SERVICE_SIGNATURE); + + OldMediaPresent = IpSb->MediaPresent; + + // + // Get fresh mode data from MNP, since underlying media status may change. + // Here, it needs to mention that the MediaPresent can also be checked even if + // EFI_NOT_STARTED returned while this MNP child driver instance isn't configured. + // + Status = IpSb->Mnp->GetModeData (IpSb->Mnp, NULL, &SnpModeData); + if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) { + return; + } + + IpSb->MediaPresent = SnpModeData.MediaPresent; + // + // Media transimit Unpresent to Present means new link movement is detected. + // + if (!OldMediaPresent && IpSb->MediaPresent && (IpSb->Ip4Config2Instance.Policy == Ip4Config2PolicyDhcp)) { + // + // Signal the IP4 to run the dhcp configuration again. IP4 driver will free + // old IP address related resource, such as route table and Interface, then + // initiate a DHCP round to acquire new IP, eventually + // create route table for new IP address. + // + if (IpSb->ReconfigEvent != NULL) { + Status = gBS->SignalEvent (IpSb->ReconfigEvent); + DispatchDpc (); + } + } +}