home *** CD-ROM | disk | FTP | other *** search
/ Handbook of Infosec Terms 2.0 / Handbook_of_Infosec_Terms_Version_2.0_ISSO.iso / text / rfcs / rfc1143.txt < prev    next >
Text File  |  1996-05-07  |  23KB  |  278 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                       D. Bernstein Request for Comments: 1143                                           NYU                                                            February 1990 
  8.  
  9.           The Q Method of Implementing TELNET Option Negotiation 
  10.  
  11.  Status of This Memo 
  12.  
  13.    This is RFC discusses an implementation approach to option    negotiation in the Telnet protocol (RFC 854).  It does not propose    any changes to the TELNET protocol.  Rather, it discusses the    implementation of the protocol of one feature, only.  This is not a    protocol specification.  This is an experimental method of    implementing a protocol.  This memo is not a recommendation of the    Telnet Working Group of the Internet Engineering Task Force (IETF).    This RFC is Copyright 1990, Daniel J. Bernstein.  However,    distribution of this memo in original form is unlimited. 
  14.  
  15. 1. Introduction 
  16.  
  17.    This RFC amplifies, supplements, and extends the RFC 854 [7] option    negotiation rules and guidelines, which are insufficient to prevent    all option negotiation loops.  This RFC also presents an example of    correct implementation. 
  18.  
  19.    DISCUSSION: 
  20.  
  21.    The two items in this RFC of the most interest to implementors are    1. the examples of option negotiation loops given below; and 2. the    example of a TELNET state machine preventing loops. 
  22.  
  23.       1. Implementors of TELNET should read the examples of option          negotiation loops and beware that preventing such loops is a          nontrivial task. 
  24.  
  25.       2. Section 7 of this RFC shows by example a working method          of avoiding loops.  It prescribes the state information that          you must keep about each side of each option; it shows what          to do in each state when you receive WILL/WONT/DO/DONT from          the network, and when the user or process requests that an          option be enabled or disabled.  An implementor who uses the          procedures given in that example need not worry about          compliance with this RFC or with a large chunk of RFC 854. 
  26.  
  27.    In short, all implementors should be familiar with TELNET loops, and    some implementors may wish to use the pre-written example here in 
  28.  
  29.  
  30.  
  31. Bernstein                                                       [Page 1] 
  32.  RFC 1143                        Q Method                   February 1990 
  33.  
  34.     writing a new TELNET implementation. 
  35.  
  36.    NOTE: Reading This Document 
  37.  
  38.       A TELNET implementation is not compliant with this RFC if it fails       to satisfy all rules marked MUST.  It is compliant if it satisfies       all rules marked MUST.  If it is compliant, it is unconditionally       compliant if it also satisfies all rules marked SHOULD and       conditionally compliant otherwise.  Rules marked MAY are optional. 
  39.  
  40.       Options are in almost all cases negotiated separately for each       side of the connection.  The option on one side is separate from       the option on the other side. In this document, "the" option       referred to by a DONT/WONT or DO/WILL is really two options,       combined only for semantic convenience.  Each sentence could be       split into two, one with the words before the slash and one with       the words after the slash. 
  41.  
  42.       An implementor should be able to determine whether or not an       implementation complies with this RFC without reading any text       marked DISCUSSION.  An implementor should be able to implement       option negotiation machinery compliant with both this RFC and RFC       854 using just the information in Section 7. 
  43.  
  44. 2. RFC 854 Option Negotiation Requirements 
  45.  
  46.    As specified by RFC 854: A TELNET implementation MUST obey a refusal    to enable an option; i.e., if it receives a DONT/WONT in response to    a WILL/DO, it MUST NOT enable the option. 
  47.  
  48.    DISCUSSION: 
  49.  
  50.       Where RFC 854 implies that the other side may reject a request to       enable an option, it means that you must accept such a rejection. 
  51.  
  52.    It MUST therefore remember that it is negotiating a WILL/DO, and this    negotiation state MUST be separate from the enabled state and from    the disabled state.  During the negotiation state, any effects of    having the option enabled MUST NOT be used. 
  53.  
  54.    If it receives WONT/DONT and the option is enabled, it MUST respond    DONT/WONT repectively and disable the option.  It MUST NOT initiate a    DO/WILL negotiation for an already enabled option or a DONT/WONT    negotiation for a disabled option.  It MUST NOT respond to receipt of    such a negotiation.  It MUST respond to receipt of a negotiation that    does propose to change the status quo. 
  55.  
  56.  
  57.  
  58.  
  59.  
  60. Bernstein                                                       [Page 2] 
  61.  RFC 1143                        Q Method                   February 1990 
  62.  
  63.     DISCUSSION: 
  64.  
  65.       Many existing implementations respond to rejection by confirming       the rejection; i.e., if they send WILL and receive DONT, they send       WONT.  This has been construed as acceptable behavior under a       certain (strained) interpretation of RFC 854.  However, to allow       this possibility severely complicates later rules; there seems to       be no use for the wasted bandwidth and processing.  Note that an       implementation compliant with this RFC will simply ignore the       extra WONT if the other side sends it. 
  66.  
  67.    The implementation MUST NOT automatically respond to the rejection of    a request by submitting a new request.  As a rule of thumb, new    requests should be sent either at the beginning of a connection or in    response to an external stimulus, i.e., input from the human user or    from the process behind the server. 
  68.  
  69.    A TELNET implementation MUST refuse (DONT/WONT) a request to enable    an option for which it does not comply with the appropriate protocol    specification. 
  70.  
  71.    DISCUSSION: 
  72.  
  73.       This is not stated as strongly in RFC 854.  However, any other       action would be counterproductive.  This rule appears in       Requirements for Internet Hosts [6, Section 3.2.2]; it appears       here for completeness. 
  74.  
  75. 3. Rule: Remember DONT/WONT requests 
  76.  
  77.    A TELNET implementation MUST remember starting a DONT/WONT    negotiation. 
  78.  
  79.    DISCUSSION: 
  80.  
  81.       It is not clear from RFC 854 whether or not TELNET must remember       beginning a DONT/WONT negotiation.  There seem to be no reasons to       remember starting a DONT/WONT negotiation: 1. The argument for       remembering a DO/WILL negotiation (viz., the state of negotiating       for enabling means different things for the data stream than the       state of having the option enabled) does not apply.  2. There is       no choice for the other side in responding to a DONT/WONT; the       option is going to end up disabled.  3. If we simply disable the       option immediately and forget negotiating, we will ignore the       WONT/DONT response since the option is disabled. 
  82.  
  83.       Unfortunately, that conclusion is wrong.  Consider the following       TELNET conversation between two parties, "us" and "him".  (The 
  84.  
  85.  
  86.  
  87. Bernstein                                                       [Page 3] 
  88.  RFC 1143                        Q Method                   February 1990 
  89.  
  90.        reader of this RFC may want to sort the steps into chronological       order for a different view.) 
  91.  
  92.       LOOP EXAMPLE 1 
  93.  
  94.          Both sides know that the option is on. 
  95.  
  96.          On his side:        1 He decides to disable.  He sends DONT and disables the option.        2 He decides to reenable.  He sends DO and remembers he is          negotiating.        5 He receives WONT and gives up on negotiation.        6 He decides to try once again to reenable.  He sends DO and          remembers he is negotiating.        7 He receives WONT and gives up on negotiation.          For whatever reason, he decides to agree with future requests.       10 He receives WILL and agrees. He responds DO and enables the          option.       11 He receives WONT and sighs. He responds DONT and disables the          option.          (repeat 10 and then 11, forever) 
  97.  
  98.          On our side:        3 We receive DONT and sigh.  We respond WONT and disable the          option.        4 We receive DO but disagree.  We respond WONT.        8 We receive DO and decide to agree.  We respond WILL and enable          the option.        9 We decide to disable.  We send WONT and disable the option.          For whatever reason, we decide to agree with future requests.       12 We receive DO and agree.  We send WILL and enable the option.       13 We receive DONT and sigh.  We send WONT and disable the option.          (repeat 12 and then 13, forever) 
  99.  
  100.       Both sides have followed RFC 854; but we end in an option       negotiation loop, as DONT DO DO and then DO DONT forever travel       through the network one way, and WONT WONT followed by WILL WONT       forever travel through the network the other way.  The behavior in       steps 1 and 9 is responsible for this loop.  Hence this section's       rule.  In Section 6 below is discussion of whether separate states       are needed for "negotiate for disable" and "negotiate for enable"       or whether a single "negotiate" state suffices. 
  101.  
  102. 4. Rule: Prohibit new requests before completing old negotiation 
  103.  
  104.    A TELNET implementation MUST NOT initiate a new WILL/WONT/DO/DONT    request about an option that is under negotiation, i.e., for which it    has already made such a request and not yet received a response. 
  105.  
  106.  
  107.  
  108. Bernstein                                                       [Page 4] 
  109.  RFC 1143                        Q Method                   February 1990 
  110.  
  111.     DISCUSSION: 
  112.  
  113.       It is unclear from RFC 854 whether or not a TELNET implementation       may allow new requests about an option that is currently under       negotiation; it certainly seems limiting to prohibit "option       typeahead".  Unfortunately, consider the following: 
  114.  
  115.       LOOP EXAMPLE 2 
  116.  
  117.          Suppose an option is disabled, and we decide in quick          succession to enable it, disable it, and reenable it.  We send          WILL WONT WILL and at the end remember that we are negotiating.          The other side agrees with DO DONT DO. We receive the first DO,          enable the option, and forget we have negotiated.  Now DONT DO          are coming through the network and both sides have forgotten          they are negotiating; consequently we loop. 
  118.  
  119.       (All possible TELNET loops eventually degenerate into the same       form, where WILL WONT [or WONT WILL, or WILL WONT WILL WONT, etc.]       go through the network while both sides think negotiation is over;       the response is DO DONT and we loop forever.  TELNET implementors       are encouraged to implement any option that can detect such a loop       and cut it off; e.g., a method of explicitly differentiating       requests from acknowledgments would be sufficient.  No such option       exists as of February 1990.) 
  120.  
  121.       This particular case is of considerable practical importance: most       combinations of existing user-server TELNET implementations do       enter an infinite loop when asked quickly a few times to enable       and then disable an option.  This has taken on an even greater       importance with the advent of LINEMODE [4], because LINEMODE is       the first option that tends to generate such rapidly changing       requests in the normal course of communication.  It is clear that       a new rule is needed. 
  122.  
  123.       One might try to prevent the several-alternating-requests problem       by maintaining a more elaborate state than YES/NO/WANTwhatever,       e.g., a state that records all outstanding requests.  Dave Borman       has proposed an apparently working scheme [2] that won't blow up       if both sides initiate several requests at once, and that seems to       prevent option negotiation loops; complete analysis of his       solution is somewhat difficult since it means that TELNET can no       longer be a finite-state automaton.  He has implemented his       solution in the latest BSD telnet version [5]; as of May 1989, he       does not intend to publish it for others to use [3]. 
  124.  
  125.       Here the author decided to preserve TELNET's finite-state       property, for robustness and because the result can be easily 
  126.  
  127.  
  128.  
  129. Bernstein                                                       [Page 5] 
  130.  RFC 1143                        Q Method                   February 1990 
  131.  
  132.        proven to work.  Hence the above rule. 
  133.  
  134.       A more restrictive solution would be to buffer all data and do       absolutely nothing until the response comes back.  There is no       apparent reason for this, though some existing TELNET       implementations do so anyway at the beginning of a connection,       when most options are negotiated. 
  135.  
  136. 5. How to reallow the request queue 
  137.  
  138.    DISCUSSION: 
  139.  
  140.       The above rule prevents queueing of more than one request through       the network.  However, it is possible to queue new requests within       the TELNET implementation, so that "option typeahead" is       effectively restored. 
  141.  
  142.       An obvious possibility is to maintain a list of requests that have       been made but not yet sent, so that when one negotiation finishes,       the next can be started immediately.  So while negotiating for a       WILL, TELNET could buffer the user's requests for WONT, then WILL       again, then WONT, then WILL, then WONT, as far as desired. 
  143.  
  144.       This requires a dynamic and potentially unmanageable buffer.       However, the restrictions upon possible requests guarantee that       the list of requests must simply alternate between WONT and WILL.       It is wasteful to enable an option and then disable it, just to       enable it again; we might as well just enable it in the first       place.  The few possible exceptions to this rule do not outweigh       the immense simplification afforded by remembering only the last       few entries on the queue. 
  145.  
  146.       To be more precise, during a WILL negotiation, the only sensible       queues are WONT and WONT WILL, and similarly during a WONT       negotiation.  In the interest of simplicity, the Q method does not       allow the WONT WILL possibility. 
  147.  
  148.       We are now left with a queue consisting of either nothing or the       opposite of the current negotiation.  When we receive a reply to       the negotiation, if the queue indicates that the option should be       changed, we send the opposite request immediately and empty the       queue.  Note that this does not conflict with the RFC 854 rule       about automatic regeneration of requests, as these new requests       are simply the delayed effects of user or process commands. 
  149.  
  150.    An implementation SHOULD support the queue, where support is defined    by the rules following. 
  151.  
  152.  
  153.  
  154.  Bernstein                                                       [Page 6] 
  155.  RFC 1143                        Q Method                   February 1990 
  156.  
  157.     If it does support the queue, and if an option is currently under    negotiation, it MUST NOT handle a new request from the user or    process to switch the state of that option by sending a new request    through the network.  Instead, it MUST remember internally that the    new request was made. 
  158.  
  159.    If the user or process makes a second new request, for switching back    again, while the original negotiation is still incomplete, the    implementation SHOULD handle the request simply by forgetting the    previous one.  The third request SHOULD be treated like the first,    etc.  In any case, these further requests MUST NOT generate immediate    requests through the network. 
  160.  
  161.    When the option negotiation completes, if the implementation is    remembering a request internally, and that request is for the    opposite state to the result of the completed negotiation, then the    implementation MUST act as if that request had been made after the    completion of the negotiation.  It SHOULD thus immediately generate a    new request through the network. 
  162.  
  163.    The implementation MAY provide a method by which support for the    queue may be turned off and back on.  In this case, it MUST default    to having the support turned on.  Furthermore, when support is turned    off, if the implementation is remembering a new request for an    outstanding negotiation, it SHOULD continue remembering and then deal    with it at the close of the outstanding negotiation, as if support    were still turned on through that point. 
  164.  
  165.    DISCUSSION: 
  166.  
  167.       It is intended (and it is the author's belief) that this queue       system restores the full functionality of TELNET.  Dave Borman has       provided some informal analysis of this issue [1]; the most       important possible problem of note is that certain options which       may require buffering could be slowed by the queue.  The author       believes that network delays caused by buffering are independent       of the implementation method used, and that the Q Method does not       cause any problems; this is borne out by examples. 
  168.  
  169. 6. Rule: Separate WANTNO and WANTYES 
  170.  
  171.    Implementations SHOULD separate any states of negotiating WILL/DO    from any states of negotiating WONT/DONT. 
  172.  
  173.    DISCUSSION: 
  174.  
  175.       It is possible to maintain a working TELNET implementation if the       NO/YES/WANTNO/WANTYES states are simplified to NO/YES/WANT. 
  176.  
  177.  
  178.  
  179. Bernstein                                                       [Page 7] 
  180.  RFC 1143                        Q Method                   February 1990 
  181.  
  182.        However, in a hostile environment this is a bad idea, as it means       that handling a DO/WILL response to a WONT/DONT cannot be done       correctly.  It does not greatly simplify code; and the simplicity       gained is lost in the extra complexity needed to maintain the       queue. 
  183.  
  184. 7. Example of Correct Implementation 
  185.  
  186.    To ease the task of writing TELNET implementations, the author    presents here a precise example of the response that a compliant    TELNET implementation could give in each possible situation.  All    TELNET implementations compliant with this RFC SHOULD follow the    procedures shown here. 
  187.  
  188.    EXAMPLE STATE MACHINE    FOR THE Q METHOD OF IMPLEMENTING TELNET OPTION NEGOTIATION 
  189.  
  190.       There are two sides, we (us) and he (him).  We keep four       variables: 
  191.  
  192.          us: state of option on our side (NO/WANTNO/WANTYES/YES)          usq: a queue bit (EMPTY/OPPOSITE) if us is WANTNO or WANTYES          him: state of option on his side          himq: a queue bit if him is WANTNO or WANTYES 
  193.  
  194.       An option is enabled if and only if its state is YES.  Note that       us/usq and him/himq could be combined into two six-choice states. 
  195.  
  196.       "Error" below means that producing diagnostic information may be a       good idea, though it isn't required. 
  197.  
  198.       Upon receipt of WILL, we choose based upon him and himq:          NO            If we agree that he should enable, him=YES, send                        DO; otherwise, send DONT.          YES           Ignore.          WANTNO  EMPTY Error: DONT answered by WILL. him=NO.               OPPOSITE Error: DONT answered by WILL. him=YES*,                        himq=EMPTY.          WANTYES EMPTY him=YES.               OPPOSITE him=WANTNO, himq=EMPTY, send DONT. 
  199.  
  200.       * This behavior is debatable; DONT will never be answered by WILL         over a reliable connection between TELNETs compliant with this         RFC, so this was chosen (1) not to generate further messages,         because if we know we're dealing with a noncompliant TELNET we         shouldn't trust it to be sensible; (2) to empty the queue         sensibly. 
  201.  
  202.  
  203.  
  204.  Bernstein                                                       [Page 8] 
  205.  RFC 1143                        Q Method                   February 1990 
  206.  
  207.        Upon receipt of WONT, we choose based upon him and himq:          NO            Ignore.          YES           him=NO, send DONT.          WANTNO  EMPTY him=NO.               OPPOSITE him=WANTYES, himq=NONE, send DO.          WANTYES EMPTY him=NO.*               OPPOSITE him=NO, himq=NONE.** 
  208.  
  209.       * Here is the only spot a length-two queue could be useful; after         a WILL negotiation was refused, a queue of WONT WILL would mean         to request the option again. This seems of too little utility         and too much potential waste; there is little chance that the         other side will change its mind immediately. 
  210.  
  211.       ** Here we don't have to generate another request because we've          been "refused into" the correct state anyway. 
  212.  
  213.       If we decide to ask him to enable:          NO            him=WANTYES, send DO.          YES           Error: Already enabled.          WANTNO  EMPTY If we are queueing requests, himq=OPPOSITE;                        otherwise, Error: Cannot initiate new request                        in the middle of negotiation.               OPPOSITE Error: Already queued an enable request.          WANTYES EMPTY Error: Already negotiating for enable.               OPPOSITE himq=EMPTY. 
  214.  
  215.       If we decide to ask him to disable:          NO            Error: Already disabled.          YES           him=WANTNO, send DONT.          WANTNO  EMPTY Error: Already negotiating for disable.               OPPOSITE himq=EMPTY.          WANTYES EMPTY If we are queueing requests, himq=OPPOSITE;                        otherwise, Error: Cannot initiate new request                        in the middle of negotiation.               OPPOSITE Error: Already queued a disable request. 
  216.  
  217.       We handle the option on our side by the same procedures, with DO-       WILL, DONT-WONT, him-us, himq-usq swapped. 
  218.  
  219. 8. References 
  220.  
  221.    [1] Borman, D., private communication, April 1989. 
  222.  
  223.    [2] Borman, D., private communication, May 1989. 
  224.  
  225.    [3] Borman, D., private communication, May 1989. 
  226.  
  227.  
  228.  
  229.  Bernstein                                                       [Page 9] 
  230.  RFC 1143                        Q Method                   February 1990 
  231.  
  232.     [4] Borman, D., Editor, "Telnet Linemode Option", RFC 1116, Cray        Research, August 1989. 
  233.  
  234.    [5] Borman, D., BSD Telnet Source, November 1989. 
  235.  
  236.    [6] Braden, R., Editor, "Requirements for Internet Hosts --        Application and Support", RFC 1123, USC/Information Sciences        Institute, October 1989. 
  237.  
  238.    [7] Postel, J., and J. Reynolds, "Telnet Protocol Specification", RFC        854, USC/Information Sciences Institute, May 1983. 
  239.  
  240. 9. Acknowledgments 
  241.  
  242.    Thanks to Dave Borman, dab@opus.cray.com, for his helpful comments. 
  243.  
  244. Author's Address 
  245.  
  246.    Daniel J. Bernstein    5 Brewster Lane    Bellport, NY 11713 
  247.  
  248.    Phone:  516-286-1339 
  249.  
  250.    Email:  brnstnd@acf10.nyu.edu 
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  Bernstein                                                      [Page 10] 
  277.  
  278.