Discussion:
[rancid] clogin bug in $prompt matching, does not work well IOS XR
Kristian Larsson
2009-01-20 17:33:01 UTC
Permalink
Hello!

I have found what I believe is a bug in clogin.

When using clogin to automatically send commands
and retrieve its output from an IOS XR device the
prompt is not correctly parsed.

When clogin first logs in, it sends a simple
carriage return (\n) to the router to be able to
determine the prompt. Here's an strace of that..

recvfrom(3, "RP/0/RP1/CPU0:AMS-CORE-1#", 6938, 0, NULL, NULL) = 25
write(1, "RP/0/RP1/CPU0:AMS-CORE-1#", 25) = 25
read(0, "\r", 8177) = 1
sendto(3, "\r\0", 2, 0, NULL, 0) = 2
recvfrom(3, "\r\n\rRP/0/RP1/CPU0:AMS-CORE-1#", 6913, 0, NULL, NULL) = 28
write(1, "\r\n\rRP/0/RP1/CPU0:AMS-CORE-1#", 28) = 28

So far, everything is fine and dandy. The router
is obviously called ams-core-1 and it has the
prompt RP/0/RP1/CPU0:AMS-CORE-1# which clogin
correctly identifies.
Here comes the next part, clogin sends 'terminal
length 0'...

read(0, "terminal length 0\r", 8176) = 18
sendto(3, "terminal length 0\r\0", 19, 0, NULL, 0) = 19
recvfrom(3, "terminal\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length 0\r\n\r", 6885, 0, NULL, NULL) = 95

So it reads 'terminal length 0' from clogin, sends
it to the CRS and then receives the output.

Now, IOS XR does one thing a tad differently than
IOS, it has command completion on the space key
as well as on the tab key. My guess is that this
mechanism forces the IOS XR CLI to redraw the line
each and every time a space is entered.
If we examine the recvfrom line

recvfrom(3, "terminal\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length 0\r\n\r", 6885, 0, NULL, NULL) = 95

we see that "terminal" is first echoed back to
the client. Then, as a space was entered, IOS XR
does a carriage return and redraws the entire line
starting with the prompt and filling up with
"terminal length" and the same thing over again to
"terminal length 0".

As clogin merely looks for $prompt which is
'RP/0/RP1/CPU0:AMS-CORE-1#', it will get a match
several times over and is thus unable to interpret
the situation correctly.

I've tried modifying clogin in several ways
- adding \n to prompt or several of the places
where $prompt is used and so forth but so far
without much luck. My TCL-fu is not strong enough.

Could some TCL guru have a look at this? I could
probably arrange access to an IOS XR device for
testing.

Oh, I'm running clogin version 2.3.2a9

Kind regards,
Kristian.
--
Kristian Larsson KLL-RIPE
Network Engineer / Internet Core Tele2 / SWIPnet [AS1257]
+46 704 910401 ***@spritelink.net
Lance Vermilion
2009-01-20 17:43:33 UTC
Permalink
Have you tried adding something like the following to you .cloginrc?

add userprompt AMS-CORE-1 "RP/0/RP1/CPU0:AMS-CORE-1"

On Tue, Jan 20, 2009 at 10:33 AM, Kristian Larsson
Post by Kristian Larsson
Hello!
I have found what I believe is a bug in clogin.
When using clogin to automatically send commands
and retrieve its output from an IOS XR device the
prompt is not correctly parsed.
When clogin first logs in, it sends a simple
carriage return (\n) to the router to be able to
determine the prompt. Here's an strace of that..
recvfrom(3, "RP/0/RP1/CPU0:AMS-CORE-1#", 6938, 0, NULL, NULL) = 25
write(1, "RP/0/RP1/CPU0:AMS-CORE-1#", 25) = 25
read(0, "\r", 8177) = 1
sendto(3, "\r\0", 2, 0, NULL, 0) = 2
recvfrom(3, "\r\n\rRP/0/RP1/CPU0:AMS-CORE-1#", 6913, 0, NULL, NULL) = 28
write(1, "\r\n\rRP/0/RP1/CPU0:AMS-CORE-1#", 28) = 28
So far, everything is fine and dandy. The router
is obviously called ams-core-1 and it has the
prompt RP/0/RP1/CPU0:AMS-CORE-1# which clogin
correctly identifies.
Here comes the next part, clogin sends 'terminal
length 0'...
read(0, "terminal length 0\r", 8176) = 18
sendto(3, "terminal length 0\r\0", 19, 0, NULL, 0) = 19
recvfrom(3, "terminal\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length 0\r\n\r", 6885, 0, NULL, NULL) = 95
So it reads 'terminal length 0' from clogin, sends
it to the CRS and then receives the output.
Now, IOS XR does one thing a tad differently than
IOS, it has command completion on the space key
as well as on the tab key. My guess is that this
mechanism forces the IOS XR CLI to redraw the line
each and every time a space is entered.
If we examine the recvfrom line
recvfrom(3, "terminal\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length 0\r\n\r", 6885, 0, NULL, NULL) = 95
we see that "terminal" is first echoed back to
the client. Then, as a space was entered, IOS XR
does a carriage return and redraws the entire line
starting with the prompt and filling up with
"terminal length" and the same thing over again to
"terminal length 0".
As clogin merely looks for $prompt which is
'RP/0/RP1/CPU0:AMS-CORE-1#', it will get a match
several times over and is thus unable to interpret
the situation correctly.
I've tried modifying clogin in several ways
- adding \n to prompt or several of the places
where $prompt is used and so forth but so far
without much luck. My TCL-fu is not strong enough.
Could some TCL guru have a look at this? I could
probably arrange access to an IOS XR device for
testing.
Oh, I'm running clogin version 2.3.2a9
Kind regards,
Kristian.
--
Kristian Larsson KLL-RIPE
Network Engineer / Internet Core Tele2 / SWIPnet [AS1257]
_______________________________________________
Rancid-discuss mailing list
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
Kristian Larsson
2009-01-20 21:10:21 UTC
Permalink
Post by Lance Vermilion
Have you tried adding something like the following to you .cloginrc?
No.
Post by Lance Vermilion
add userprompt AMS-CORE-1 "RP/0/RP1/CPU0:AMS-CORE-1"
This looks just like the prompt on the router,
which clogin already detects correctly.
Anyway, I just tried now adding it to my .cloginrc
and I'm running into the same problem.

The problem is _not_ with how clogin identifies
the prompt, it does this correctly so the value
stored in $prompt is correct.

The problem is when clogin matches $prompt towards
the lines received thereafter. Due to the way IOS
XR behaves the $prompt variable could appear
several times though not a complete line (with a
new line at the end) and this confuses clogin.

Please look at the strace output and you will see
how you receive parts of the line several times
before it is finally sent with an ending \n. That
is where the problem lies. Or so I believe ;-)

Kind regards,
Kristian.
Post by Lance Vermilion
On Tue, Jan 20, 2009 at 10:33 AM, Kristian Larsson
Post by Kristian Larsson
Hello!
I have found what I believe is a bug in clogin.
When using clogin to automatically send commands
and retrieve its output from an IOS XR device the
prompt is not correctly parsed.
When clogin first logs in, it sends a simple
carriage return (\n) to the router to be able to
determine the prompt. Here's an strace of that..
recvfrom(3, "RP/0/RP1/CPU0:AMS-CORE-1#", 6938, 0, NULL, NULL) = 25
write(1, "RP/0/RP1/CPU0:AMS-CORE-1#", 25) = 25
read(0, "\r", 8177) = 1
sendto(3, "\r\0", 2, 0, NULL, 0) = 2
recvfrom(3, "\r\n\rRP/0/RP1/CPU0:AMS-CORE-1#", 6913, 0, NULL, NULL) = 28
write(1, "\r\n\rRP/0/RP1/CPU0:AMS-CORE-1#", 28) = 28
So far, everything is fine and dandy. The router
is obviously called ams-core-1 and it has the
prompt RP/0/RP1/CPU0:AMS-CORE-1# which clogin
correctly identifies.
Here comes the next part, clogin sends 'terminal
length 0'...
read(0, "terminal length 0\r", 8176) = 18
sendto(3, "terminal length 0\r\0", 19, 0, NULL, 0) = 19
recvfrom(3, "terminal\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length 0\r\n\r", 6885, 0, NULL, NULL) = 95
So it reads 'terminal length 0' from clogin, sends
it to the CRS and then receives the output.
Now, IOS XR does one thing a tad differently than
IOS, it has command completion on the space key
as well as on the tab key. My guess is that this
mechanism forces the IOS XR CLI to redraw the line
each and every time a space is entered.
If we examine the recvfrom line
recvfrom(3, "terminal\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length\rRP/0/RP1/CPU0:AMS-CORE-1#terminal length 0\r\n\r", 6885, 0, NULL, NULL) = 95
we see that "terminal" is first echoed back to
the client. Then, as a space was entered, IOS XR
does a carriage return and redraws the entire line
starting with the prompt and filling up with
"terminal length" and the same thing over again to
"terminal length 0".
As clogin merely looks for $prompt which is
'RP/0/RP1/CPU0:AMS-CORE-1#', it will get a match
several times over and is thus unable to interpret
the situation correctly.
I've tried modifying clogin in several ways
- adding \n to prompt or several of the places
where $prompt is used and so forth but so far
without much luck. My TCL-fu is not strong enough.
Could some TCL guru have a look at this? I could
probably arrange access to an IOS XR device for
testing.
Oh, I'm running clogin version 2.3.2a9
Kind regards,
Kristian.
--
Kristian Larsson KLL-RIPE
Network Engineer / Internet Core Tele2 / SWIPnet [AS1257]
_______________________________________________
Rancid-discuss mailing list
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
_______________________________________________
Rancid-discuss mailing list
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
--
Kristian Larsson KLL-RIPE
Network Engineer / Internet Core Tele2 / SWIPnet [AS1257]
+46 704 910401 ***@spritelink.net
Loading...