* [PATCH] ip: mpls: fix printing of mpls labels
@ 2017-05-09  6:04 David Ahern
  2017-05-10 10:02 ` Simon Horman
  2017-05-11 18:09 ` Stephen Hemminger
  0 siblings, 2 replies; 4+ messages in thread
From: David Ahern @ 2017-05-09  6:04 UTC (permalink / raw)
  To: stephen, netdev; +Cc: roopa, David Ahern
If the kernel returns more labels than iproute2 expects, none of
the labels are printed and (null) is shown instead:
    $ ip -f mpls ro ls
    101 as to (null) via inet 172.16.2.2 dev virt12
    201 as to 202/203 via inet6 2001:db8:2::2 dev virt12
Remove the use of MPLS_MAX_LABELS and rely on buffer length that is
passed to mpls_ntop. With this change ip can print the label stack
returned by the kernel up to 255 characters (limit is due to size of
buf passed in) which amounts to 31 labels with a separator.
With this change the above is:
    $ ip/ip -f mpls ro ls
    101 as to 102/103/104/105/106/107/108/109/110 via inet 172.16.2.2 dev virt12
Signed-off-by: David Ahern <dsahern@gmail.com>
---
 lib/mpls_ntop.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/mpls_ntop.c b/lib/mpls_ntop.c
index 945d6d5e..5902f503 100644
--- a/lib/mpls_ntop.c
+++ b/lib/mpls_ntop.c
@@ -10,18 +10,20 @@ static const char *mpls_ntop1(const struct mpls_label *addr, char *buf, size_t b
 {
 	size_t destlen = buflen;
 	char *dest = buf;
-	int count;
+	int count = 0;
 
-	for (count = 0; count < MPLS_MAX_LABELS; count++) {
-		uint32_t entry = ntohl(addr[count].entry);
+	while (1) {
+		uint32_t entry = ntohl(addr[count++].entry);
 		uint32_t label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
 		int len = snprintf(dest, destlen, "%u", label);
 
+		if (len >= destlen)
+			break;
+
 		/* Is this the end? */
 		if (entry & MPLS_LS_S_MASK)
 			return buf;
 
-
 		dest += len;
 		destlen -= len;
 		if (destlen) {
-- 
2.11.0 (Apple Git-81)
^ permalink raw reply related	[flat|nested] 4+ messages in thread- * Re: [PATCH] ip: mpls: fix printing of mpls labels
  2017-05-09  6:04 [PATCH] ip: mpls: fix printing of mpls labels David Ahern
@ 2017-05-10 10:02 ` Simon Horman
  2017-05-11 18:09 ` Stephen Hemminger
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Horman @ 2017-05-10 10:02 UTC (permalink / raw)
  To: David Ahern; +Cc: stephen, netdev, roopa
On Mon, May 08, 2017 at 11:04:13PM -0700, David Ahern wrote:
> If the kernel returns more labels than iproute2 expects, none of
> the labels are printed and (null) is shown instead:
>     $ ip -f mpls ro ls
>     101 as to (null) via inet 172.16.2.2 dev virt12
>     201 as to 202/203 via inet6 2001:db8:2::2 dev virt12
> 
> Remove the use of MPLS_MAX_LABELS and rely on buffer length that is
> passed to mpls_ntop. With this change ip can print the label stack
> returned by the kernel up to 255 characters (limit is due to size of
> buf passed in) which amounts to 31 labels with a separator.
> 
> With this change the above is:
>     $ ip/ip -f mpls ro ls
>     101 as to 102/103/104/105/106/107/108/109/110 via inet 172.16.2.2 dev virt12
> 
> Signed-off-by: David Ahern <dsahern@gmail.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
^ permalink raw reply	[flat|nested] 4+ messages in thread 
- * Re: [PATCH] ip: mpls: fix printing of mpls labels
  2017-05-09  6:04 [PATCH] ip: mpls: fix printing of mpls labels David Ahern
  2017-05-10 10:02 ` Simon Horman
@ 2017-05-11 18:09 ` Stephen Hemminger
  2017-05-11 20:52   ` David Ahern
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2017-05-11 18:09 UTC (permalink / raw)
  To: David Ahern; +Cc: netdev, roopa
On Mon,  8 May 2017 23:04:13 -0700
David Ahern <dsahern@gmail.com> wrote:
> If the kernel returns more labels than iproute2 expects, none of
> the labels are printed and (null) is shown instead:
>     $ ip -f mpls ro ls
>     101 as to (null) via inet 172.16.2.2 dev virt12
>     201 as to 202/203 via inet6 2001:db8:2::2 dev virt12
> 
> Remove the use of MPLS_MAX_LABELS and rely on buffer length that is
> passed to mpls_ntop. With this change ip can print the label stack
> returned by the kernel up to 255 characters (limit is due to size of
> buf passed in) which amounts to 31 labels with a separator.
> 
> With this change the above is:
>     $ ip/ip -f mpls ro ls
>     101 as to 102/103/104/105/106/107/108/109/110 via inet 172.16.2.2 dev virt12
> 
> Signed-off-by: David Ahern <dsahern@gmail.com>
Much better. Applied thanks.
^ permalink raw reply	[flat|nested] 4+ messages in thread 
- * Re: [PATCH] ip: mpls: fix printing of mpls labels
  2017-05-11 18:09 ` Stephen Hemminger
@ 2017-05-11 20:52   ` David Ahern
  0 siblings, 0 replies; 4+ messages in thread
From: David Ahern @ 2017-05-11 20:52 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, roopa
On 5/11/17 11:09 AM, Stephen Hemminger wrote:
> On Mon,  8 May 2017 23:04:13 -0700
> David Ahern <dsahern@gmail.com> wrote:
> 
>> If the kernel returns more labels than iproute2 expects, none of
>> the labels are printed and (null) is shown instead:
>>     $ ip -f mpls ro ls
>>     101 as to (null) via inet 172.16.2.2 dev virt12
>>     201 as to 202/203 via inet6 2001:db8:2::2 dev virt12
>>
>> Remove the use of MPLS_MAX_LABELS and rely on buffer length that is
>> passed to mpls_ntop. With this change ip can print the label stack
>> returned by the kernel up to 255 characters (limit is due to size of
>> buf passed in) which amounts to 31 labels with a separator.
>>
>> With this change the above is:
>>     $ ip/ip -f mpls ro ls
>>     101 as to 102/103/104/105/106/107/108/109/110 via inet 172.16.2.2 dev virt12
>>
>> Signed-off-by: David Ahern <dsahern@gmail.com>
> 
> Much better. Applied thanks.
> 
This is only one-half of the solution; the install side is harder. I'll
send something in the next few days.
^ permalink raw reply	[flat|nested] 4+ messages in thread 
 
end of thread, other threads:[~2017-05-11 20:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-09  6:04 [PATCH] ip: mpls: fix printing of mpls labels David Ahern
2017-05-10 10:02 ` Simon Horman
2017-05-11 18:09 ` Stephen Hemminger
2017-05-11 20:52   ` David Ahern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).