Subject: Re: [PATCH net v2] rtnetlink: enable alt_ifname for setlink/newlink

From: Jakub Kicinski <[email-masked]>
Date: Fri, 1 Apr 2022 10:43:42 -0700

On Fri,  1 Apr 2022 17:39:39 +0200 Florent Fourcot wrote:
> buffer called "ifname" given in function rtnl_dev_get
> is always valid when called by setlink/newlink,
> but contains only empty string when IFLA_IFNAME is not given. So
> IFLA_ALT_IFNAME is always ignored
> 
> This patch fixes rtnl_dev_get function with a remove of ifname argument,
> and move ifname copy in do_setlink when required
> 
> Changes in v2:
>  * Remove ifname argument in rtnl_dev_get/do_setlink
>    functions (simplify code)
> 
> Fixes: 76c9ac0ee878 ("net: rtnetlink: add possibility to use alternative names as message handle")
> CC: Jiri Pirko <[email-masked]>
> Signed-off-by: Florent Fourcot <[email-masked]>
> Signed-off-by: Brian Baboch <[email-masked]>

> @@ -3262,7 +3257,7 @@ static int rtnl_group_changelink(const struct sk_buff *skb,
>  
>  	for_each_netdev_safe(net, dev, aux) {
>  		if (dev->group == group) {
> -			err = do_setlink(skb, dev, ifm, extack, tb, NULL, 0);
> +			err = do_setlink(skb, dev, ifm, extack, tb, 0);

This part depends on your other change, right? Do you care about this
getting into stable? Otherwise we can downgrade it from a fix to -next
and merge after your other patch. It never worked so we can go either
way on it being a fix. Actually leaning slightly towards it _not_ being
a fix.

>  			if (err < 0)
>  				return err;
>  		}

> @@ -3450,7 +3440,10 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
>  	if (!ops->alloc && !ops->setup)
>  		return -EOPNOTSUPP;
>  
> -	if (!ifname[0]) {
> +	if (tb[IFLA_IFNAME]) {
> +		nla_strscpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
> +	}
> +	else {

Formatting slightly off here, should be

	} else {

>  		snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind);
>  		name_assign_type = NET_NAME_ENUM;
>  	}
> @@ -3622,8 +3615,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
>  	if (ifm->ifi_index > 0)
>  		dev = __dev_get_by_index(tgt_net, ifm->ifi_index);
>  	else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
> -		dev = rtnl_dev_get(tgt_net, tb[IFLA_IFNAME],
> -				   tb[IFLA_ALT_IFNAME], NULL);
> +		dev = rtnl_dev_get(tgt_net, tb[IFLA_IFNAME], tb[IFLA_ALT_IFNAME]);

How about we pass tb and extract IFLA_IFNAME and IFLA_ALT_IFNAME inside
rtnl_dev_get()? All callers seem to pass the same args now.

>  	else
>  		goto out;