[Devel] [PATCH RH7 3/3] net: openvswitch: add capability to specify ifindex of new links

Vasily Averin vvs at virtuozzo.com
Mon Aug 17 09:18:41 MSK 2020


On 8/17/20 9:15 AM, Vasily Averin wrote:
> On 8/14/20 8:01 PM, Andrey Zhadchenko wrote:
>> Openvswitch creates several net devices, but unlike rtnetlink API there is
>> no option to specify ifindex for link. This is crucial for criu during
>> restore stage.
>> Use ovs_header->dp_ifindex during OVS_DP_CMD_NEW as desired ifindex.
>> Use OVS_VPORT_ATTR_IFINDEX during OVS_VPORT_CMD_NEW to specify new netdev
>> ifindex. Both values were not relevant for corresponding requests, so
>> existing software won't mess with it.
>>
>> https://jira.sw.ru/browse/PSBM-105844
>> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
>> ---
>>  net/openvswitch/datapath.c           | 16 ++++++++++++++--
>>  net/openvswitch/vport-internal_dev.c |  1 +
>>  net/openvswitch/vport.h              |  2 ++
>>  3 files changed, 17 insertions(+), 2 deletions(-)
>>
>> diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
>> index 6d63ace..47bf4db 100644
>> --- a/net/openvswitch/datapath.c
>> +++ b/net/openvswitch/datapath.c
>> @@ -1582,6 +1582,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
>>  	struct vport *vport;
>>  	struct ovs_net *ovs_net;
>>  	int err, i;
>> +	struct ovs_header *ovs_header = info->userhdr;
>>  
>>  	err = -EINVAL;
>>  	if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID])
>> @@ -1626,6 +1627,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
>>  	parms.dp = dp;
>>  	parms.port_no = OVSP_LOCAL;
>>  	parms.upcall_portids = a[OVS_DP_ATTR_UPCALL_PID];
>> +	parms.desired_ifindex = ovs_header->dp_ifindex;
>>  
>>  	ovs_dp_change(dp, a);
>>  
>> @@ -2013,7 +2015,10 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
>>  	if (!a[OVS_VPORT_ATTR_NAME] || !a[OVS_VPORT_ATTR_TYPE] ||
>>  	    !a[OVS_VPORT_ATTR_UPCALL_PID])
>>  		return -EINVAL;
>> -	if (a[OVS_VPORT_ATTR_IFINDEX])
>> +
>> +	parms.type = nla_get_u32(a[OVS_VPORT_ATTR_TYPE]);
>> +
>> +	if (a[OVS_VPORT_ATTR_IFINDEX] && parms.type != OVS_VPORT_TYPE_INTERNAL)
>>  		return -EOPNOTSUPP;
>>  
>>  	port_no = a[OVS_VPORT_ATTR_PORT_NO]
>> @@ -2050,12 +2055,19 @@ restart:
>>  	}
>>  
>>  	parms.name = nla_data(a[OVS_VPORT_ATTR_NAME]);
>> -	parms.type = nla_get_u32(a[OVS_VPORT_ATTR_TYPE]);
>>  	parms.options = a[OVS_VPORT_ATTR_OPTIONS];
>>  	parms.dp = dp;
>>  	parms.port_no = port_no;
>>  	parms.upcall_portids = a[OVS_VPORT_ATTR_UPCALL_PID];
>>  
>> +	if (parms.type == OVS_VPORT_TYPE_INTERNAL) {
>> +		if (a[OVS_VPORT_ATTR_IFINDEX])
>> +			parms.desired_ifindex =
>> +				nla_get_u32(a[OVS_VPORT_ATTR_IFINDEX]);
>> +		else
>> +			parms.desired_ifindex = 0;
>> +	}
>> +
>>  	vport = new_vport(&parms);
>>  	err = PTR_ERR(vport);
>>  	if (IS_ERR(vport)) {
>> diff --git a/net/openvswitch/vport-internal_dev.c b/net/openvswitch/vport-internal_dev.c
>> index 2757f21..8ec8ae5 100644
>> --- a/net/openvswitch/vport-internal_dev.c
>> +++ b/net/openvswitch/vport-internal_dev.c
>> @@ -202,6 +202,7 @@ static struct vport *internal_dev_create(const struct vport_parms *parms)
>>  	if (vport->port_no == OVSP_LOCAL)
>>  		vport->dev->features |= NETIF_F_NETNS_LOCAL;
>>  
>> +	dev->ifindex = parms->desired_ifindex;   <<<<< VvS 
> 
> in my version of kernel sources dev is not used in this fuction

ok, it was introduced by first patch of your patch set.

> 
>>  	rtnl_lock();
>>  	err = register_netdevice(vport->dev);
>>  	if (err)
>> diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h
>> index cda66c2..c5281b5 100644
>> --- a/net/openvswitch/vport.h
>> +++ b/net/openvswitch/vport.h
>> @@ -109,6 +109,8 @@ struct vport_parms {
>>  	enum ovs_vport_type type;
>>  	struct nlattr *options;
>>  
>> +	int desired_ifindex;
>> +
>>  	/* For ovs_vport_alloc(). */
>>  	struct datapath *dp;
>>  	u16 port_no;
>>
> _______________________________________________
> Devel mailing list
> Devel at openvz.org
> https://lists.openvz.org/mailman/listinfo/devel
> 


More information about the Devel mailing list