From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0721.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe46::721]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C06A91A1E01 for ; Tue, 6 Sep 2016 02:37:42 -0700 (PDT) Received: from DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM (10.162.192.143) by DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM (10.162.192.143) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.599.9; Tue, 6 Sep 2016 09:37:41 +0000 Received: from DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM ([10.162.192.143]) by DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM ([10.162.192.143]) with mapi id 15.01.0599.016; Tue, 6 Sep 2016 09:37:41 +0000 From: "Hegde, Nagaraj P" To: "Fu, Siyuan" , "Wu, Jiaxin" , "edk2-devel@lists.01.org" CC: "Ye, Ting" Thread-Topic: [edk2] [PATCH v2] NetworkPkg/DnsDxe: Handle CNAME type responded from the name server Thread-Index: AQHSCBvb/3D+SaGeWUKleZ+ZvhwmmqBsK+eAgAAIZFA= Date: Tue, 6 Sep 2016 09:37:41 +0000 Message-ID: References: <1473151854-70952-1-git-send-email-jiaxin.wu@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=nagaraj-p.hegde@hpe.com; x-originating-ip: [15.219.195.6] x-ms-office365-filtering-correlation-id: dbbd4bff-db86-4046-7f1a-08d3d639729c x-microsoft-exchange-diagnostics: 1; DF4PR84MB0041; 6:5Uxk7vKtsNP4NmaSMxw6H4MjJUleyoXFsF29KZORz8jTOMETR/nmwXBDxG9mGYbP6JSqeRChjq9iriHOuEEc8NXRiluvTtn2D6Q0QGFNafl3k8h3st+0t1ptj2Q/3WqmpzMl02fxJ7wLeA0qVUmncOjEO7SQxzostBjXTjyCRr6FOGrnOjYC8nK0OAEyTJNv+fHJyetJ4URyOM7JwqqDRis8LYSUAEu504Oslk2ZbE0HssFA+cMGZb4bJw6fpl+7NIXZ6JRJ9bBeSfg7aUH9713joYoPxlcJHOf/+YLBwWY4EjIkfN+KjVX/Oqhy/AMftjUe3T524S4JE4tzyWvYDg==; 5:bg3SrKH5cFDYNIgtpZHerplJI25P+2bhmesw8Rvol7+kBih1/qIvTLiyDJo2zENsKdJViKdz2dGx3LQxD40ub8WtWPhp2Ia1FehfaVrlVm44yjY0p90qvdiFOfEE6VBbHStBoq3mqn52vCDm+QiC6A==; 24:MSY+b8b7MEOe++NFJlkFwGcOMVptHT9GX54ivw4AGc/NGDwM1t0okJHdD+AtNu23q0pL/bocN5oZ8k2HyJKp9ktu3EUO8j13Jt/dOCbfpl0=; 7:7bpy5Q7TAgq0KQV9UkhU+VuGzuedc/GTflanmqdndcJg3s4MzRdTaPBqgBckk6t8xsN5HT/wxfLB2V/RHYewmyDmgjuzQiLAkln34eKw9NWXKhwpKlqILwCG6+fpikOaIxgccjh1BASrfSo5TYaLUYxDDtZy3BABdImZeTL6tTICL9vxCzhycs4qWffnE+YIoiGhO00ZsVK0TnYnsv7mogmjTdgoZny01EW8Gn3YJx8QUg/z6A+RW8fcfYf5uMfD x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DF4PR84MB0041; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(227479698468861)(158342451672863)(150554046322364)(162533806227266)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:DF4PR84MB0041; BCL:0; PCL:0; RULEID:; SRVR:DF4PR84MB0041; x-forefront-prvs: 0057EE387C x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(7916002)(377454003)(199003)(189002)(13464003)(4326007)(87936001)(7736002)(81166006)(6116002)(86362001)(15975445007)(3660700001)(8676002)(5002640100001)(122556002)(2950100001)(2900100001)(101416001)(77096005)(105586002)(33656002)(10400500002)(7696003)(3280700002)(106356001)(106116001)(66066001)(2501003)(11100500001)(97736004)(9686002)(305945005)(5001770100001)(586003)(81156014)(5660300001)(8936002)(7846002)(19580405001)(99286002)(92566002)(19580395003)(74316002)(3846002)(102836003)(189998001)(50986999)(2906002)(68736007)(76176999)(54356999)(19627235001); DIR:OUT; SFP:1102; SCL:1; SRVR:DF4PR84MB0041; H:DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: hpe.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Sep 2016 09:37:41.2860 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0041 Subject: Re: [PATCH v2] NetworkPkg/DnsDxe: Handle CNAME type responded from the name server X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Sep 2016 09:37:43 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Tested-by: Hegde Nagaraj P -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Fu, = Siyuan Sent: Tuesday, September 06, 2016 2:37 PM To: Wu, Jiaxin ; edk2-devel@lists.01.org Cc: Ye, Ting Subject: Re: [edk2] [PATCH v2] NetworkPkg/DnsDxe: Handle CNAME type respond= ed from the name server Reviewed-by: Fu Siyuan > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of=20 > Jiaxin Wu > Sent: Tuesday, September 6, 2016 4:51 PM > To: edk2-devel@lists.01.org > Cc: Ye, Ting ; Fu, Siyuan > Subject: [edk2] [PATCH v2] NetworkPkg/DnsDxe: Handle CNAME type=20 > responded from the name server >=20 > v2: > * Code refine. > * For DnsCache, the minimum value of TTL is selected between CNAME and=20 > A/AAAA record. >=20 > According RFC 1034 - 3.6.2, if the query name is an alias, the name=20 > server will include the CNAME record in the response and restart the=20 > query at the domain name specified in the data field of the CNAME=20 > record. RFC also provides one example server action when A query=20 > received: >=20 > Suppose a name server was processing a query with for USCISIC.ARPA,=20 > asking for type A information, and had the following resource records: > USC-ISIC.ARPA IN CNAME C.ISI.EDU > C.ISI.EDU IN A 10.0.0.52 > Both of these RRs would be returned in the response to the type A query. >=20 > Currently, DnsDxe driver doesn't handle the CNAME type response, which=20 > will cause any exception result. The driver need continue the packet=20 > parsing while CNAME type record parsed. So, this patch is used to=20 > handle it correctly. >=20 > Cc: Hegde Nagaraj P > Cc: Fu Siyuan > Cc: Ye Ting > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jiaxin Wu > --- > NetworkPkg/DnsDxe/DnsImpl.c | 81=20 > +++++++++++++++++++++++++++++----------- > ----- > 1 file changed, 52 insertions(+), 29 deletions(-) >=20 > diff --git a/NetworkPkg/DnsDxe/DnsImpl.c b/NetworkPkg/DnsDxe/DnsImpl.c=20 > index 360f68e..cfaa4c7 100644 > --- a/NetworkPkg/DnsDxe/DnsImpl.c > +++ b/NetworkPkg/DnsDxe/DnsImpl.c > @@ -1125,10 +1125,11 @@ ParseDnsResponse ( > DNS6_TOKEN_ENTRY *Dns6TokenEntry; >=20 > UINT32 IpCount; > UINT32 RRCount; > UINT32 AnswerSectionNum; > + UINT32 CNameTtl; >=20 > EFI_IPv4_ADDRESS *HostAddr4; > EFI_IPv6_ADDRESS *HostAddr6; >=20 > EFI_DNS4_CACHE_ENTRY *Dns4CacheEntry; @@ -1146,10 +1147,11 @@=20 > ParseDnsResponse ( > Dns6TokenEntry =3D NULL; >=20 > IpCount =3D 0; > RRCount =3D 0; > AnswerSectionNum =3D 0; > + CNameTtl =3D 0; >=20 > HostAddr4 =3D NULL; > HostAddr6 =3D NULL; >=20 > Dns4CacheEntry =3D NULL; > @@ -1231,17 +1233,10 @@ ParseDnsResponse ( > if (DnsHeader->Flags.Bits.RCode !=3D DNS_FLAGS_RCODE_NO_ERROR || > DnsHeader->AnswersNum < 1 || \ > DnsHeader->Flags.Bits.QR !=3D DNS_FLAGS_QR_RESPONSE) { > Status =3D EFI_ABORTED; > goto ON_EXIT; > } > - > - // > - // Free the sending packet. > - // > - if (Item->Value !=3D NULL) { > - NetbufFree ((NET_BUF *) (Item->Value)); > - } >=20 > // > // Do some buffer allocations. > // > if (Instance->Service->IpVersion =3D=3D IP_VERSION_4) { @@ -1288,40=20 > +1283,42 @@ ParseDnsResponse ( > // > // It's the GeneralLookUp querying. > // > Dns6TokenEntry->Token->RspData.GLookupData =3D AllocatePool=20 > (sizeof (DNS_RESOURCE_RECORD)); > if (Dns6TokenEntry->Token->RspData.GLookupData =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > Dns6TokenEntry->Token->RspData.GLookupData->RRList =3D=20 > AllocatePool (DnsHeader->AnswersNum * sizeof (DNS_RESOURCE_RECORD)); > if (Dns6TokenEntry->Token->RspData.GLookupData->RRList =3D=3D NULL= ) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > } else { > // > // It's not the GeneralLookUp querying. Check the Query type. > // > if (QuerySection->Type =3D=3D DNS_TYPE_AAAA) { > Dns6TokenEntry->Token->RspData.H2AData =3D AllocatePool (sizeof= =20 > (DNS6_HOST_TO_ADDR_DATA)); > if (Dns6TokenEntry->Token->RspData.H2AData =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > Dns6TokenEntry->Token->RspData.H2AData->IpList =3D AllocatePool= =20 > (DnsHeader->AnswersNum * sizeof (EFI_IPv6_ADDRESS)); > if (Dns6TokenEntry->Token->RspData.H2AData->IpList =3D=3D NULL) = { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > } else { > Status =3D EFI_UNSUPPORTED; > goto ON_EXIT; > } > } > } >=20 > + Status =3D EFI_NOT_FOUND; > + > // > // Processing AnswerSection. > // > while (AnswerSectionNum < DnsHeader->AnswersNum) { > // > @@ -1348,51 +1345,53 @@ ParseDnsResponse ( > // > // Fill the ResourceRecord. > // > Dns4RR[RRCount].QName =3D AllocateZeroPool (AsciiStrLen=20 > (QueryName) + 1); > if (Dns4RR[RRCount].QName =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > CopyMem (Dns4RR[RRCount].QName, QueryName, AsciiStrLen (QueryName)= ); > Dns4RR[RRCount].QType =3D AnswerSection->Type; > Dns4RR[RRCount].QClass =3D AnswerSection->Class; > Dns4RR[RRCount].TTL =3D AnswerSection->Ttl; > Dns4RR[RRCount].DataLength =3D AnswerSection->DataLength; > Dns4RR[RRCount].RData =3D AllocateZeroPool=20 > (Dns4RR[RRCount].DataLength); > if (Dns4RR[RRCount].RData =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > CopyMem (Dns4RR[RRCount].RData, AnswerData,=20 > Dns4RR[RRCount].DataLength); >=20 > RRCount ++; > + Status =3D EFI_SUCCESS; > } else if (Instance->Service->IpVersion =3D=3D IP_VERSION_6 && > Dns6TokenEntry->GeneralLookUp) { > Dns6RR =3D Dns6TokenEntry->Token->RspData.GLookupData->RRList; > AnswerData =3D (UINT8 *) AnswerSection + sizeof (*AnswerSection); >=20 > // > // Fill the ResourceRecord. > // > Dns6RR[RRCount].QName =3D AllocateZeroPool (AsciiStrLen=20 > (QueryName) + 1); > if (Dns6RR[RRCount].QName =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > CopyMem (Dns6RR[RRCount].QName, QueryName, AsciiStrLen (QueryName)= ); > Dns6RR[RRCount].QType =3D AnswerSection->Type; > Dns6RR[RRCount].QClass =3D AnswerSection->Class; > Dns6RR[RRCount].TTL =3D AnswerSection->Ttl; > Dns6RR[RRCount].DataLength =3D AnswerSection->DataLength; > Dns6RR[RRCount].RData =3D AllocateZeroPool=20 > (Dns6RR[RRCount].DataLength); > if (Dns6RR[RRCount].RData =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > CopyMem (Dns6RR[RRCount].RData, AnswerData,=20 > Dns6RR[RRCount].DataLength); >=20 > RRCount ++; > + Status =3D EFI_SUCCESS; > } else { > // > // It's not the GeneralLookUp querying. > // Check the Query type, parse the response packet. > // > @@ -1425,30 +1424,36 @@ ParseDnsResponse ( > // > // Allocate new CacheEntry pool. > // > Dns4CacheEntry =3D AllocateZeroPool (sizeof (EFI_DNS4_CACHE_ENTR= Y)); > if (Dns4CacheEntry =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > Dns4CacheEntry->HostName =3D AllocateZeroPool (2 * > (StrLen(Dns4TokenEntry->QueryHostName) + 1)); > if (Dns4CacheEntry->HostName =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > CopyMem (Dns4CacheEntry->HostName,=20 > Dns4TokenEntry->QueryHostName, > 2 * (StrLen(Dns4TokenEntry->QueryHostName) + 1)); > Dns4CacheEntry->IpAddress =3D AllocateZeroPool (sizeof=20 > (EFI_IPv4_ADDRESS)); > if (Dns4CacheEntry->IpAddress =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > CopyMem (Dns4CacheEntry->IpAddress, AnswerData, sizeof=20 > (EFI_IPv4_ADDRESS)); > - Dns4CacheEntry->Timeout =3D AnswerSection->Ttl; > + > + if (CNameTtl !=3D 0 && AnswerSection->Ttl !=3D 0) { > + Dns4CacheEntry->Timeout =3D MIN (CNameTtl, AnswerSection->Ttl)= ; > + } else { > + Dns4CacheEntry->Timeout =3D MAX (CNameTtl, AnswerSection->Ttl)= ; > + } >=20 > UpdateDns4Cache (&mDriverData->Dns4CacheList, FALSE, TRUE,=20 > *Dns4CacheEntry); >=20 > - IpCount ++; > + IpCount ++; > + Status =3D EFI_SUCCESS; > break; > case DNS_TYPE_AAAA: > // > // This is address entry, get Data. > // > @@ -1476,30 +1481,44 @@ ParseDnsResponse ( > // > // Allocate new CacheEntry pool. > // > Dns6CacheEntry =3D AllocateZeroPool (sizeof (EFI_DNS6_CACHE_ENTR= Y)); > if (Dns6CacheEntry =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > Dns6CacheEntry->HostName =3D AllocateZeroPool (2 * > (StrLen(Dns6TokenEntry->QueryHostName) + 1)); > if (Dns6CacheEntry->HostName =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > CopyMem (Dns6CacheEntry->HostName,=20 > Dns6TokenEntry->QueryHostName, > 2 * (StrLen(Dns6TokenEntry->QueryHostName) + 1)); > Dns6CacheEntry->IpAddress =3D AllocateZeroPool (sizeof=20 > (EFI_IPv6_ADDRESS)); > if (Dns6CacheEntry->IpAddress =3D=3D NULL) { > - Status =3D EFI_UNSUPPORTED; > + Status =3D EFI_OUT_OF_RESOURCES; > goto ON_EXIT; > } > CopyMem (Dns6CacheEntry->IpAddress, AnswerData, sizeof=20 > (EFI_IPv6_ADDRESS)); > - Dns6CacheEntry->Timeout =3D AnswerSection->Ttl; > + > + if (CNameTtl !=3D 0 && AnswerSection->Ttl !=3D 0) { > + Dns6CacheEntry->Timeout =3D MIN (CNameTtl, AnswerSection->Ttl)= ; > + } else { > + Dns6CacheEntry->Timeout =3D MAX (CNameTtl, AnswerSection->Ttl)= ; > + } >=20 > UpdateDns6Cache (&mDriverData->Dns6CacheList, FALSE, TRUE,=20 > *Dns6CacheEntry); >=20 > IpCount ++; > + Status =3D EFI_SUCCESS; > + break; > + case DNS_TYPE_CNAME: > + // > + // According RFC 1034 - 3.6.2, if the query name is an alias,=20 > + the > name server will include the CNAME > + // record in the response and restart the query at the domain > name specified in the data field of the > + // CNAME record. So, just record the TTL value of the CNAME,=20 > + then > skip to parse the next record. > + // > + CNameTtl =3D AnswerSection->Ttl; > break; > default: > Status =3D EFI_UNSUPPORTED; > goto ON_EXIT; > } > @@ -1539,24 +1558,28 @@ ParseDnsResponse ( > } > } > } >=20 > // > - // Parsing is complete, SignalEvent here. > + // Parsing is complete, free the sending packet and signal Event here. > // > + if (Item !=3D NULL && Item->Value !=3D NULL) { > + NetbufFree ((NET_BUF *) (Item->Value)); } > + > if (Instance->Service->IpVersion =3D=3D IP_VERSION_4) { > ASSERT (Dns4TokenEntry !=3D NULL); > Dns4RemoveTokenEntry (&Instance->Dns4TxTokens, Dns4TokenEntry); > - Dns4TokenEntry->Token->Status =3D EFI_SUCCESS; > + Dns4TokenEntry->Token->Status =3D Status; > if (Dns4TokenEntry->Token->Event !=3D NULL) { > gBS->SignalEvent (Dns4TokenEntry->Token->Event); > DispatchDpc (); > } > } else { > ASSERT (Dns6TokenEntry !=3D NULL); > Dns6RemoveTokenEntry (&Instance->Dns6TxTokens, Dns6TokenEntry); > - Dns6TokenEntry->Token->Status =3D EFI_SUCCESS; > + Dns6TokenEntry->Token->Status =3D Status; > if (Dns6TokenEntry->Token->Event !=3D NULL) { > gBS->SignalEvent (Dns6TokenEntry->Token->Event); > DispatchDpc (); > } > } > @@ -2035,11 +2058,11 @@ DnsOnTimerUpdate ( > } >=20 > Entry =3D mDriverData->Dns4CacheList.ForwardLink; > while (Entry !=3D &mDriverData->Dns4CacheList) { > Item4 =3D NET_LIST_USER_STRUCT (Entry, DNS4_CACHE, AllCacheLink); > - if (Item4->DnsCache.Timeout<=3D0) { > + if (Item4->DnsCache.Timeout =3D=3D 0) { > RemoveEntryList (&Item4->AllCacheLink); > Entry =3D mDriverData->Dns4CacheList.ForwardLink; > } else { > Entry =3D Entry->ForwardLink; > } > @@ -2054,11 +2077,11 @@ DnsOnTimerUpdate ( > } >=20 > Entry =3D mDriverData->Dns6CacheList.ForwardLink; > while (Entry !=3D &mDriverData->Dns6CacheList) { > Item6 =3D NET_LIST_USER_STRUCT (Entry, DNS6_CACHE, AllCacheLink); > - if (Item6->DnsCache.Timeout<=3D0) { > + if (Item6->DnsCache.Timeout =3D=3D 0) { > RemoveEntryList (&Item6->AllCacheLink); > Entry =3D mDriverData->Dns6CacheList.ForwardLink; > } else { > Entry =3D Entry->ForwardLink; > } > -- > 1.9.5.msysgit.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel