netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: David Ahern <dsahern@gmail.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net,
	jakub.kicinski@netronome.com, roopa@cumulusnetworks.com,
	dcbw@redhat.com, nikolay@cumulusnetworks.com, mkubecek@suse.cz,
	andrew@lunn.ch, parav@mellanox.com, saeedm@mellanox.com,
	f.fainelli@gmail.com, stephen@networkplumber.org,
	sd@queasysnail.net, sbrivio@redhat.com, pabeni@redhat.com,
	mlxsw@mellanox.com
Subject: Re: [patch iproute2-next v2 2/2] ip: allow to use alternative names as handle
Date: Wed, 9 Oct 2019 14:41:41 +0200	[thread overview]
Message-ID: <20191009124141.GI2326@nanopsycho> (raw)
In-Reply-To: <ad655086-3f95-3897-c93b-bf15a52c2903@gmail.com>

Mon, Oct 07, 2019 at 11:52:46PM CEST, dsahern@gmail.com wrote:
>On 10/2/19 4:56 AM, Jiri Pirko wrote:
>> @@ -1106,7 +1106,8 @@ int iplink_get(char *name, __u32 filt_mask)
>>  
>>  	if (name) {
>>  		addattr_l(&req.n, sizeof(req),
>> -			  IFLA_IFNAME, name, strlen(name) + 1);
>> +			  !check_ifname(name) ? IFLA_IFNAME : IFLA_ALT_IFNAME,
>
>If this trick works here ...
>
>> +			  name, strlen(name) + 1);
>>  	}
>>  	addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
>>  
>> diff --git a/lib/ll_map.c b/lib/ll_map.c
>> index e0ed54bf77c9..04dfb0f2320b 100644
>> --- a/lib/ll_map.c
>> +++ b/lib/ll_map.c
>> @@ -70,7 +70,7 @@ static struct ll_cache *ll_get_by_name(const char *name)
>>  		struct ll_cache *im
>>  			= container_of(n, struct ll_cache, name_hash);
>>  
>> -		if (strncmp(im->name, name, IFNAMSIZ) == 0)
>> +		if (strcmp(im->name, name) == 0)
>>  			return im;
>>  	}
>>  
>> @@ -240,6 +240,43 @@ int ll_index_to_flags(unsigned idx)
>>  	return im ? im->flags : -1;
>>  }
>>  
>> +static int altnametoindex(const char *name)
>> +{
>> +	struct {
>> +		struct nlmsghdr		n;
>> +		struct ifinfomsg	ifm;
>> +		char			buf[1024];
>> +	} req = {
>> +		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
>> +		.n.nlmsg_flags = NLM_F_REQUEST,
>> +		.n.nlmsg_type = RTM_GETLINK,
>> +	};
>> +	struct rtnl_handle rth = {};
>> +	struct nlmsghdr *answer;
>> +	struct ifinfomsg *ifm;
>> +	int rc = 0;
>> +
>> +	if (rtnl_open(&rth, 0) < 0)
>> +		return 0;
>> +
>> +	addattr32(&req.n, sizeof(req), IFLA_EXT_MASK,
>> +		  RTEXT_FILTER_VF | RTEXT_FILTER_SKIP_STATS);
>> +	addattr_l(&req.n, sizeof(req), IFLA_ALT_IFNAME, name, strlen(name) + 1);
>
>then why is altnametoindex even needed? why not just use the same check
>in the current ll_link_get?

Good point. Reworked. Thanks!


>
>> +
>> +	if (rtnl_talk_suppress_rtnl_errmsg(&rth, &req.n, &answer) < 0)
>> +		goto out;
>> +
>> +	ifm = NLMSG_DATA(answer);
>> +	rc = ifm->ifi_index;
>> +
>> +	free(answer);
>> +
>> +	rtnl_close(&rth);
>> +out:
>> +	return rc;
>> +}
>> +
>> +
>>  unsigned ll_name_to_index(const char *name)
>>  {
>>  	const struct ll_cache *im;
>> @@ -257,6 +294,8 @@ unsigned ll_name_to_index(const char *name)
>>  		idx = if_nametoindex(name);
>>  	if (idx == 0)
>>  		idx = ll_idx_a2n(name);
>> +	if (idx == 0)
>> +		idx = altnametoindex(name);
>
>And then this ordering does not need to be fixed (altname check should
>come before if_nametoindex.
>
>>  	return idx;
>>  }
>>  
>> 
>

      reply	other threads:[~2019-10-09 12:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-02 10:56 [patch iproute2-next v2 0/2] ip: add support for alternative names Jiri Pirko
2019-10-02 10:56 ` [patch iproute2-next v2 1/2] ip: add support for alternative name addition/deletion/list Jiri Pirko
2019-10-07 21:37   ` David Ahern
2019-10-09 11:13     ` Jiri Pirko
2019-10-02 10:56 ` [patch iproute2-next v2 2/2] ip: allow to use alternative names as handle Jiri Pirko
2019-10-07 21:52   ` David Ahern
2019-10-09 12:41     ` Jiri Pirko [this message]

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=20191009124141.GI2326@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dcbw@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=mkubecek@suse.cz \
    --cc=mlxsw@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=nikolay@cumulusnetworks.com \
    --cc=pabeni@redhat.com \
    --cc=parav@mellanox.com \
    --cc=roopa@cumulusnetworks.com \
    --cc=saeedm@mellanox.com \
    --cc=sbrivio@redhat.com \
    --cc=sd@queasysnail.net \
    --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).