ziutek / telnet

Package to handle a telnet connection
Other
141 stars 60 forks source link

Two questions about telnet option #12

Closed vinllen closed 6 years ago

vinllen commented 6 years ago

Hi, Dear Ziutek,

Sorry to bother you again. I have two questions about the telnet option recently. I used your library to telnet different switch and router. Some of them are OK, while some are not.

  1. The "Password:" string didn't show After login into the switch using telnet, the Username: characters show normally. Some switches don't show the password: characters after typing the username. Actually, no response occurred whatever I type.
    In my experiments, some switches can display the password: character but some aren't. I can't find any help in the google results and (rfc854)[https://tools.ietf.org/html/rfc854]. Do you know it's telnet option problem or switch configuration problem? Supplement: the password: string can all be displayed normally when using (Linux telnet client)[https://linux.die.net/man/1/telnet].

  2. "echo option" negotiate loop I didn't modify your code so that for every IAC WILL ECHO/255 251 1 reply IAC DO ECHO/255 253 2; for every IAC WON'T ECHO/255 252 1 reply IAC DON'T ECHO/255 254 1. This strategy should work OK according to the (rfc854)[https://tools.ietf.org/html/rfc854]. But some switches go into dead loop, here comes the print from debug:

    received cmd: 251 1
    received cmd: 251 1
    received cmd: 251 1
    received cmd: 251 3
    received cmd: 253 24
    received cmd: 253 31
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 254 24
    received cmd: 254 31
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    received cmd: 251 1
    received cmd: 252 1
    .... // print omit: "255 251 1" and "255 252 1" display respectively

    I don't know whether it's problem of switch telnet version. What I want is accept any echo configuration. Here comes the description of option response in rfc854:

If a party receives what appears to be a request to enter some mode it is already in, the request should not be acknowledged. This non-response is essential to prevent endless loops in the negotiation. It is required that a response be sent to requests for a change of mode -- even if the mode is not changed.

In my understanding, no response means enable. So I modify your code in func (c *Conn) cmd(cmd byte) that doesn't reply any do and don't when receive will and won't:

    switch o {
    case optEcho:
        // Accept any echo configuration.
        switch cmd {
        case cmdDo:
            if !c.cliEcho {
                c.cliEcho = true
                err = c.will(o)
            }
        case cmdDont:
            if c.cliEcho {
                c.cliEcho = false
                err = c.wont(o)
            }
        case cmdWill:
            // err = c.do(o) // erase
        case cmdWont:
            // err = c.dont(o) // erase
        }

It looks like the switch enable echo option which is what I want. Do you think it's a right way to erase these two line code to enable echo option?

ziutek commented 6 years ago

I added checking to avoid optEcho loop. Try the modified code and report does it help.

vinllen commented 6 years ago

It doesn't work. Is it the problem that different switch uses different telnet protocol version?

vinllen commented 6 years ago

Does no response mean accept in telnet protocol?

vinllen commented 6 years ago

When I set the echo option to false in the (func (c *Conn) SetEcho(echo bool)), the optEcho loop still exists. However, this loop disappears when setting the option to true. This phenomenon is very strange. Setting echo option true receive:

received cmd: 251 1
received cmd: 251 1
received cmd: 251 1
received cmd: 251 3
received cmd: 253 24
received cmd: 253 31
received cmd: 254 24
vinllen commented 6 years ago

About the first problem, it looks like some switches need character \r after \n