From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aapsg-00047y-GY for mharc-grub-devel@gnu.org; Tue, 01 Mar 2016 14:22:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aapsZ-00047f-7T for grub-devel@gnu.org; Tue, 01 Mar 2016 14:22:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aapsV-0005t9-Q5 for grub-devel@gnu.org; Tue, 01 Mar 2016 14:22:43 -0500 Received: from mail-lb0-x230.google.com ([2a00:1450:4010:c04::230]:33918) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aapsV-0005sw-Cu for grub-devel@gnu.org; Tue, 01 Mar 2016 14:22:39 -0500 Received: by mail-lb0-x230.google.com with SMTP id of3so105116971lbc.1 for ; Tue, 01 Mar 2016 11:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=zV8DlzixlkBffNXoIxU+XQI9wf6O/JaQmITvK2MQWAQ=; b=X/aQMGNTldqtJ3UskeFunqt8dbCA0gyTjtflXwqtI8M0zc+w1IWvv6OnWMlDR8HBLv vFiqOISGc8Yf6LWfzVSGd4DeRwePmaEeSymXb68uonkT+TdZTkCypZkahQSa7L/+maJa MVmv2uXnoaWMwGoFmxVx2eh66SAP+VR16NMgLsDkVPjRc2fHg2YeqGgy6b26xAf3Ymx3 Pl6b487fBJYxkZQZG7h4WrhJcI8Dc5/vpAKvEfb0nugYLD7Indm9Fh7327y5D3y5Df0h aJlgsxhTd42sEj32Oc+SHoHLo5uMsf/uD6a4TgUsYUTD+4a9f6azKL35c4GAb1Py3l1A 8Cdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=zV8DlzixlkBffNXoIxU+XQI9wf6O/JaQmITvK2MQWAQ=; b=YbG+MNT5ZE2wwLmpXXaz7dZE3TPNLbMuIKEnO9JUSMQPVD6x2FKQH9G9AWopKXLaGh 8wyNpjLw4j2WzeWFH9werPRfhAJjwGX3Y5NL5QqZriqt9phEIxqlRP6jqr8GWKR1pI32 GuUImOaUgaXgrhya2yKoS2hHOX3x/GB6aWILKH/KuKlo5lCLExD+PtX/oT0sbu8sBkGJ FjV+35TmGJWwLFmX+5sor3YPGy9Jk1A5LTeuyeiWv3azzvTA7AOvko9j0mSOFv4X1BL3 I0hCnuadvcrzCk/pU43Rn/qVrkw5I+Aj51BKotWFsT0EFqkVzgRO7xYZfpFyQ6IntxBu wGqA== X-Gm-Message-State: AD7BkJJ+yJ4WV+I6AXZKrtKQ1Gn88pMeLoMJehZa4D9FofPlJKLxIxSE7J1Vpbz0+EwzVA== X-Received: by 10.112.137.41 with SMTP id qf9mr8540741lbb.140.1456860158476; Tue, 01 Mar 2016 11:22:38 -0800 (PST) Received: from [192.168.1.41] (ppp109-252-76-159.pppoe.spdop.ru. [109.252.76.159]) by smtp.gmail.com with ESMTPSA id cc7sm5015908lbd.11.2016.03.01.11.22.37 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 01 Mar 2016 11:22:37 -0800 (PST) Subject: Re: [PATCH] dns: realloc address buffer after each packet To: Josef Bacik , The development of GNU GRUB References: <1456341072-13356-1-git-send-email-jbacik@fb.com> <56D058B3.6060202@fb.com> <56D1DF39.5060005@gmail.com> <56D5C572.3020600@fb.com> From: Andrei Borzenkov X-Enigmail-Draft-Status: N1110 Message-ID: <56D5EBFC.7010504@gmail.com> Date: Tue, 1 Mar 2016 22:22:36 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <56D5C572.3020600@fb.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::230 Cc: Kernel Team X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Mar 2016 19:22:48 -0000 01.03.2016 19:38, Josef Bacik пишет: > On 02/27/2016 12:39 PM, Andrei Borzenkov wrote: >> 26.02.2016 16:52, Josef Bacik пишет: >>> On 02/26/2016 05:22 AM, Andrei Borzenkov wrote: >>>> On Wed, Feb 24, 2016 at 10:11 PM, Josef Bacik wrote: >>>>> Sometimes DNS responses come in slower than we poll for them which >>>>> can lead us >>>>> to process multiple DNS packets which overflows the addresses array. >>>>> So instead >>>>> realloc the array each time to make sure we are accounting for any >>>>> answers we >>>>> currently have in the address array. We also move the caching of the >>>>> addresses >>>>> outside of the recv hook so we can be sure to cache all the responses >>>>> at once >>>>> instead of one packet at a time. Thanks, >>>>> >>>> >>>> This still does not address the problem that we stop waiting for >>>> further packets as soon as we get any response, so we still depend on >>>> delivery order to get correct record. >>>> >>>> What about following >>>> >>>> - send both A and AAAA query concurrently if requested >>>> - keep track of both requests (i.e. have data.id[2] and >>>> data.addresses[2]) >>>> - reset request ID (or otherwise mark it as "received") as soon as we >>>> got reply. Note that reply may contain no addresses - NXDOMAIN is >>>> prerfectly valid - so condition should not be "got any record of type >>>> A or AAAA" as it is now but rather simply "got reply to request with >>>> id XX". This also allows us to implement negative caching at some >>>> point :) >>> >>> So we check the rcode so a NXDOMAIN response will just be discarded, we >>> don't have to worry about this case. >>> >>>> - return both A and AAAA results separately to grub_net_dns_lookup() >>>> - combine them in grub_net_dns_lookup() depending on preference - i.e. >>>> put either A or AAAA first in final result. >>>> >>>> This seems to cover all issues so far - we do not wait too long, we >>>> are guaranteed to get both A and AAAA if we request them and we return >>>> them in proper order for further processing. >>>> >>>> Do I miss something? >>>> >>> >>> So my patch previous to this one changes it so DNS servers we get from >>> dhcp are bound to either ipv4 or ipv6, so the only way we get >>> PREFER_IPV* is if an admin sets it. >> >> In this case I do not follow why you want to collect multiple answers in >> the first place. The only reason for me was to make sure we have both A >> and AAAA replies; otherwise every reply packet is supposed to contain >> exactly the same content. Following this logic the right thing to do is >> to just drop all subsequent duplicated replies. > > I don't want to collect multiple answers. We bail as soon as we get an > answer we care about. No, we do not. In DNS receive hook we set stop condition and bail out when grub_net_poll_cards() checks it. But it checks it only after going through all active cards. Multiple DNS servers may be reachable through different cards so we can have multiple packets from different servers in the same iteration, before stop condition is checked. And even with single active card we may still get multiple packets even from single server in case replies were delayed because receive_packets() consumes multiple packets if present. > If a user sets --prefer-ipv6 then they must have > an environment that also gives them an ipv4 address so they can handle > an A record response. I want to make sure that we only get both an A > and AAAA record when we have both kinds of ipvX interfaces, and if not > we bail as soon as we get one we want. > >> >>> So now the only time we'll get both >>> an A _and_ an AAAA record is if we have both types of interfaces on the >>> system, so it won't matter which answer is first as we'll be able to >>> send traffic to either. >> >> User can set preference using net_add_dns --prefer-ipvX | --only-ipvX. >> We should respect it. >> > > And we still will, prefer means we try but we don't make guarantees and > the --only will work as it has always worked. Thanks, > > Josef