<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent">
<rfc category="std" submissionType="IETF" docName="draft-tllq-tsr-04" ipr="trust200902"
     xmlns:xi="http://www.w3.org/2001/XInclude" version="3"
     scripts="Common,Latin" sortRefs="false" consensus="true"
     symRefs="true" tocDepth="3" tocInclude="true" xml:lang="en">
  <front>
    <title abbrev='TSR EDNS option for mDNS'>
      Multicast DNS conflict resolution using the Time Since Received (TSR) EDNS option
    </title>
    <author initials="T" surname="Lemon" fullname="Ted Lemon">
      <organization>Apple Inc.</organization>
      <address>
	<postal>
          <street>One Apple Park Way</street>
          <city>Cupertino</city>
          <region>California</region>
          <code>95014</code>
          <country>USA</country>
        </postal>
        <email>mellon@fugue.com</email>
      </address>
    </author>

    <author asciiInitials="L" asciiSurname="Qin" asciiFullname="Liang Qin" initials="秦" surname="良" fullname="秦良">
      <address>
	<email>Leonqin0101@gmail.com</email>
      </address>
    </author>

    <date year='2024' month='March' day='4'/>
    <area>Internet</area>
    <workgroup>Internet Engineering Task Force</workgroup>
    <abstract>
      <t>
	This document specifies a new conflict resolution mechanism for DNS, for use in cases where the advertisement is
	being proxied, rather than advertised directly, e.g. when using a combined DNS-SD Advertising Proxy and SRP
	registrar. A new EDNS option is defined that communicates the time at which the set of resource records on a particular
	DNS owner name was most recently updated.
      </t>
    </abstract>
  </front>
  <middle>
    <section>
      <name>Introduction</name>
      <t>
	Unlike the Domain Name System <xref target="RFC1034"/>, with its authority servers and delegation of authority,
	Multicast DNS has no single source of authority. Because of this, mDNS has a mechanism, conflict resolution
	(<xref target="RFC6762" section="9" sectionFormat="of"/>) for detecting and fixing conflicts in mDNS advertisements.
      </t>
      <t>
	The current goal of mDNS conflict resolution is to prevent a new service being advertised from taking the place of
	an existing service with the same name that is already being advertised. This goal, however, assumes that the
	entity advertising an mDNS service is in fact authoritative for that service. In the case of an Advertising
	Proxy <xref target="I-D.sctl-advertising-proxy"/>, this is not the case: the source of truth for the service
	being advertised is an SRP <xref target="I-D.ietf-dnssd-srp"/> client.
      </t>
      <t>
	On a link with more than one SRP registrar, an SRP client may register with one SRP registrar, and then subsequently
	update its registration on a different SRP registrar. Both SRP registrars may be acting as advertising proxies. If so, the
	original server may still be advertising the old SRP registration using mDNS. If the information in the new SRP
	registration is identical to that in the old registration, this is not a problem. However if some information has
	changed (e.g., a new IP address has been added, or a TXT record updated), then the new registration will be seen to
	be in conflict with the old registration.
      </t>
      <t>
	In the case of such a supposed conflict, the current behavior of mDNS is for the older (stale) registration to win, and the
	newer (current) information to be discarded. This behavior, which is entirely correct for services that are
	advertising on their own behalf, is exactly wrong when a service registration is being proxied.
      </t>
      <section>
	<name>Current Behavior</name>
	<t>
	  When a new service is to be advertised, the server that wishes to advertise its service typically registers the
	  service with a central mDNS registrar on the host on which it is running.  This mDNS registrar may have an
	  internal database of services already registered, and may detect a conflict with one of those services. This can
	  be true whether the conflicting database entry is data for which the mDNS registrar is authoritative, or data it
	  has received via mDNS and cached.
	</t>
	<t>
	  In the case of such a conflict, no network transaction is required: the mDNS registrar detects it locally. It
	  addresses the conflict in one of two ways. The first alternative is that the mDNS registrar will report the
	  conflict to the server as an error, which the server must fix. Alternatively, the server may have indicated that
	  the mDNS mDNS registrar should automatically choose a new name for it, in which case the mDNS registrar does so
	  automatically, without notifying the server.
	</t>
	<t>
	  Once any locally-detectable conflicts have been resolved, the mDNS registrar probes (see
	  <xref target="RFC6762" section="8.1" sectionFormat="of"/>)
	  local network to see if any other host has already registered a service the conflicts with the proposed new
	  service. If such a service is present on the network, the mDNS registrar follows the same process previously
	  described, either reporting the error to the server or automatically choosing a new name.
	</t>
	<t>
	  The effect of this approach is that generally whichever server first registers a service under a particular name
	  wins. If a server comes along later and registers the same service with conflicting information, the newcomer’s
	  information is rejected.
	</t>
      </section>
      <section>
	<name>Problem Statement</name>
	<t>
	  The current behavior works well for services registering on their own behalf. However, for example in the case of
	  an SRP registrar, it works poorly: an SRP registrar acting as an advertising proxy proxies the contents of its
	  registration dataset(s) using mDNS. The source of truth for information in such datasets is whatever service has
	  registered with the SRP registrar, not the SRP registrar itself.
	</t>
	<t>
	  In the case of an advertising proxy proxying an SRP dataset, what we want is not the oldest information, but the
	  newest. When the SRP client is able to continue registering with the same SRP registrar, this works well: stale
	  data is automatically removed and replaced with current data. However, if more than one SRP registrar is
	  available, and for some reason the original SRP registrar with which the registration was completed is still
	  operating but no longer reachable (e.g., in the case of a network partition), the SRP client will wind up
	  registering with a different SRP registrar. Similarly, if the SRP service is being advertised using an anycast address,
	  there is no guarantee that the SRP renewal will be delivered to the same SRP registrar.
	</t>
	<t>
	  When the SRP client registers with a different SRP registrar, the behavior we get with the current conflict
	  resolution approach is that the SRP client will be given a new name, and both the old (stale) advertisement (A)
	  and the new (more recent) advertisement (A’) will be discoverable as separate services.
	</t>
	<t>
	  This creates a new burden on consumers of such services: they need to parse through the whole list of services of
	  their type, using metadata from the TXT record in the service instance data, if possible, to determine that
	  service A and service A’ are the same service. If no such information is present in the TXT record, the only way
	  to determine that one of these two registrations is stale is to attempt to use the advertised service, which may
	  no longer be reachable if, for example, the change that produced the conflict was an IP address change. When the
	  SRP lease for the stale service expires, that service's advertisement will be removed, and the service will no
	  longer be discoverable under the original name, even if the IP address hasn't changed.
	</t>
	<t>
	  This document proposes an enhancement to the current conflict resolution algorithm for mDNS, which allows an mDNS
	  proxy to report the time at which it received the registration it is newly advertising. This is done using a new
	  Time Since Received RR, which is attached to the name of the registration.
	</t>
      </section>
    </section>
    <section anchor="tsrrr">
      <name>Time Since Received EDNS Option</name>
      <t>
	The Time Since Received (TSR) EDNS option references a specific RR in the answer, authority or additional sections of
	an mDNS message. This option specific to an owner name, not to an individual RRset.
	When a service registration is successful, the mDNS registrar records the wall clock time at which
	the registration request was received. This may be the current time, or a time specified by a proxy service that is
	doing the registration. This time is only recorded if the service requesting the registration specifies it;
	otherwise, the time of receipt is not recorded. The registrar also has the public key that was used in the
	registration.
      </t>
      <t>
	The TSR EDNS option consists of three fields: the RR offset (two byte integer in network
	byte order), a key hash (32 bytes), and a time offset (four bytes).
      </t>
      <t>
	The RR offset points to the first name in a given section of the mDNS Message for which
	the TSR is in effect.  The first answer is at offset 0, the second answer at offset 1
	and so on. Or if there is only one answer but also an authority record, the first
	authority record is at offset 2. If following that record there is a record in the
	additional section (including the OPT RR itself), that record would be at offset 3.
	Questions can't have TSRs associated with them, and hence the counting starts with the
	first answer, not the first question.
      </t>
      <t>
	If there are multiple records in the mDNS Message with the same owner name, only one TSR option is emitted for
	that name, and it applies to every RR in the mDNS Message with that owner name. It is not possible in the
	SRP protocol for two updates at two different times to contain records that apply to the same name.
      </t>
      <t>
	The second field, the key hash, is an SHA-256 hash (TBD) of the public key that was used to authenticate
	the SRP update that most recently updated the RRs on the owner name to which the TSR option applies.
      </t>
      <t>
	The TSR time offset field contains the difference, in seconds, between the the
	time at which the TSR record is being generated and the time of receipt for recorded for
	that owner name. If this difference is greater than seven days (7 * 24 * 60 * 60), the
	mDNS registrar MUST use a value of seven days rather than the larger value.
      </t>
    </section>
    <section>
      <name>mDNS Registrar Behavior</name>
      <section>
	<name>When sending an mDNS message</name>
	<t>
	  When constructing an mDNS message, the mDNS registrar includes one TSR option for each unique owner name for
	  any RR added to the mDNS message for which the mDNS registrar is authoritative and which was registered using SRP.
	</t>
      </section>
      <section>
	<name>When processing an mDNS message</name>
	<t>
	  When an mDNS registrar receives an mDNS message query, it processes it as usual, unless
	  it discovers a conflict. When data in the mDNS message conflicts with data in the mDNS
	  querier's authority database, as described in <xref target="RFC6762" section="8.1"
	  sectionFormat="of"/>, this is considered to be a conflict.
	</t>
	<t>
	  When a conflict detected for which a TSR record in the mDNS message is applicable, and the local record was also
	  registered using SRP, the registrar checks to see if the key hashes match. If they do not, then the conflict is
	  processed as usual. If either the mDNS record or the local authoritative record does not contain TSR information,
	  the conflict is processed as usual.
	</t>
	<t>
	  When both versions of the data have TSR records, and the key hashes match, if the
	  record in the mDNS response is more recent, the local authoritative data is discarded
	  from the authority dtheatabase and the SRP registrar function is notified that that data
	  is stale.
	</t>
	<t>
	  If, however, the version of the data received in the mDNS response is less recent than the authoritative data,
	  the registrar ignores the data in the mDNS response.
	</t>
      </section>
    </section>
    <section>
      <name>mDNS querier behavior when processing an mDNS message</name>
      <t>
	As with with the mDNS registrar case, when an mDNS querier receives an mDNS Message, it compares TSR information
	in the local cache with the TSR information in the message. If TSR information is present in both locations,
	and the data in the mDNS message is more recent, the information in the cache is replaced with the information
	in the mDNS message. Otherwise, the information in the mDNS message is ignored.
      </t>
      <t>
	Note that some mDNS registrars only answer internal queries out of cache, and populate their cache using information
	they receive both from their own mDNS announcements and answers and from information received in responses sent by
	other mDNS registrars. In addition to the behavior described for mDNS registrars, such mDNS registrars MUST also
	implement the behavior described here for queriers with respect to cache updates.
      </t>
    </section>
    <section>
      <name>The effect of network latency on time computations</name>
      <t>
	Because TSR computations are affected by network latency, comparisons can’t be considered accurate. It is
	therefore necessary to tolerate some amount of error. In practice, however, it should generally not be the case
	that two advertising proxies receive SRP updates from the same SRP client at nearly the same time. So it should
	always be the case either that there is a clear ordering to the timestamps, or that there is no conflict in the
	data. For example with anycast, a retransmission could go to a different SRP registrar, but in this case both
	servers would simultaneously receive identical data, so the close ordering or even equality of the timestamps
	should not affect the outcome.
      </t>
    </section>
    <section>
      <name>Internal Handling of TSR data</name>
      <t>
	The TSR option that is sent on the wire is expressed in seconds relative to the time of receipt of the
	registration. In order to derive the time to send in a TSR option, the registrar must remember the time at which the registration
	occurred. This time is recorded as an absolute time, not a relative time. We refer to this as the time of
	receipt. When constructing a TSR option, the registrar computes the difference between the current time and the time of
	receipt, which must always be in the past. This difference, which should be a positive integer, is converted to
	seconds, and that unsigned value is then used to synthesize the TSR RR.
      </t>
    </section>
    <section>
      <name>Timeliness of Conflict Resolution</name>
      <t>
	It is expected that if a conflict exists, it will be recent, and will be resolved quickly. Different hosts may be
	able to record shorter or longer time differences. However, because of this expectation of recentness, mDNS
	registrars should never need to report a TSR of longer than seven days. It’s reasonable to expect that every mDNS
	implementation should be able to remember time intervals of at least seven days.
      </t>
    </section>
    <section>
      <name>Legacy Behavior</name>
      <t>y
	mDNS registrars and queriers that do not support the TSR option are expected to ignore the option, so they will behave
	as if no TSR option was sent. This may result in such registrars temporarily caching stale data. However, in the
	normal course of processing, more recent data will win. In cases where it does not, the Reconfirm process which
	is part of <xref target="RFC6762"/> already works to clear stale data: since we expect SRP servers to implement
	TSR, by the time a Reconfirm is attempted, all authoritative stale data should have been cleared.
      </t>
    </section>
    <section>
      <name>When to Use TSR</name>
      <t>
	TSR is only relevant for mDNS proxies. Regular (non-proxy) mDNS registrants are not expected to use it, since it
	will produce the wrong behavior for this use case. An mDNS registrant that is a proxy MUST explicitly request that a
	TSR be used for conflict resolution. mDNS registrars MUST NOT record a time of receipt unless the registrant has
	specifically requested it.
      </t>
    </section>
    <section>
      <name>Registrant API considerations</name>
      <t>
	When an mDNS proxy registers a service and requests the use of a time of receipt, the proxy MUST specify when it
	received the registration. In order to support this, the API is required not only to allow the registrant to specify
	that TSR conflict resolution is wanted, but must also provide a way for the proxy to specify an absolute time at
	which the registration was received.
      </t>
      <t>
	This is important, for example, in the case of SRP Replication <xref target="I-D.lemon-srp-replication"/>, where an
	SRP registrar may receive a registration from a peer during startup synchronization. This registration will have
	occurred at some significant amount of time in the past, and so it would be incorrect for the mDNS proxy receiving
	the registration to use the time that the mDNS proxy registers the service as the time of receipt.
      </t>
    </section>
    <section>
      <name>Security Considerations</name>
      <t>
	The TSR option is an optimization: it ameliorates an edge case for mDNS proxies. A malicious host on the same link could
	use the TSR option to win conflict resolution processes. However, because TSR is only used by proxies, this technique
	will not work for normal mDNS service registrations: in that case, normal mDNS conflict resolution is done, and the
	attacker gains no benefit from using TSR.
      </t>
      <t>
	Whether or not an mDNS registration has a recorded time of receipt, an attacker can deny service by announcing its
	own conflicting data and then answering the subsequent probe as described in
	<xref target="RFC6762" section="9" sectionFormat="of"/>.
	Because it does not include a TSR record in its authority section, it can win the simultaneous conflict resolution
	process that follows its bogus announcement.
      </t>
      <t>
	So the TSR-based conflict resolution process creates no new vulnerability. Addressing the existing vulnerability is
	out of scope for this document. Protocols that rely on mDNS MUST NOT assume that mDNS service is secure or
	private. If security (authentication, authorization and/or secrecy) are needed, these must be provided at the
	application layer, or by using DNSSEC rather than mDNS for service discovery.
      </t>
    </section>
    <section>
      <name>IANA Considerations</name>
      <t>
	IANA is requested to allocate a new OPT RR option code from the DNS EDNS0 Option Codes (OPT) registry for the 'Time Since
	Received' Option. The Name shall be 'mDNS-TSR'. The value shall be allocated by IANA. The meaning shall be
	'Multicast DNS Time Since Received". Reference shall refer to this document, once published.  IANA shall determine the registration date.
      </t>
    </section>
  </middle>
  <back>
    <references>
      <name>Informative References</name>
    </references>
    <references>
      <name>Normative References</name>
      <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.1034.xml"/>
      <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.6762.xml"/>
      <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml3/reference.I-D.lemon-srp-replication.xml"/>
      <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml3/reference.I-D.sctl-advertising-proxy.xml"/>
      <xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml3/reference.I-D.ietf-dnssd-srp.xml"/>
    </references>
  </back>
</rfc>
