netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
To: Simon Horman <simon.horman@netronome.com>
Cc: netdev@vger.kernel.org, stephen@networkplumber.org
Subject: Re: [PATCH iproute2] ip: add support for more MPLS labels
Date: Tue, 16 May 2017 08:21:49 -0700	[thread overview]
Message-ID: <0bbdf1f7-9761-a135-65c4-41f72601a73b@gmail.com> (raw)
In-Reply-To: <20170516083224.GC15081@vergenet.net>

On 5/16/17 1:32 AM, Simon Horman wrote:
>> diff --git a/lib/mpls_pton.c b/lib/mpls_pton.c
>> index bd448cfcf14a..6d2e6a69436a 100644
>> --- a/lib/mpls_pton.c
>> +++ b/lib/mpls_pton.c
>> @@ -7,12 +7,13 @@
>>  #include "utils.h"
>>  
>>  
>> -static int mpls_pton1(const char *name, struct mpls_label *addr)
>> +static int mpls_pton1(const char *name, struct mpls_label *addr,
>> +		      unsigned int maxlabels)
>>  {
>>  	char *endp;
>>  	unsigned count;
>>  
>> -	for (count = 0; count < MPLS_MAX_LABELS; count++) {
>> +	for (count = 0; count < maxlabels; count++) {
>>  		unsigned long label;
>>  
>>  		label = strtoul(name, &endp, 0);
>> @@ -37,17 +38,19 @@ static int mpls_pton1(const char *name, struct mpls_label *addr)
>>  		addr += 1;
>>  	}
>>  	/* The address was too long */
>> +	fprintf(stderr, "Error: too many labels.\n");
>>  	return 0;
>>  }
>>  
>> -int mpls_pton(int af, const char *src, void *addr)
>> +int mpls_pton(int af, const char *src, void *addr, size_t alen)
>>  {
>> +	unsigned int maxlabels = alen / sizeof(struct mpls_label);
> 
> Could ARRAY_SIZE be used?
> 
> Also, I know its only calculated twice, but might it be nicer to
> provide a function or macro to do so? It seems like an ugly thing
> to open code.

I did it this way with intention -- to mpls_pton addr is just a buffer
of a given length. mpls_pton converts the alen into the number of labels
that the buffer can hold and passes that max to mpls_pton1 to do the
heavy lifting.

  reply	other threads:[~2017-05-16 15:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-14  1:27 [PATCH iproute2] ip: add support for more MPLS labels David Ahern
2017-05-16  8:32 ` Simon Horman
2017-05-16 15:21   ` David Ahern [this message]
2017-05-22 18:04 ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0bbdf1f7-9761-a135-65c4-41f72601a73b@gmail.com \
    --to=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=simon.horman@netronome.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).