[LEDE-DEV] [PATCH netifd] system-linux: add support for hotplug event 'move'

Martin Schiller ms at dev.tdt.de
Thu Sep 28 23:47:43 PDT 2017


On 2017-09-29 00:36, Philip Prindeville wrote:
> Inline…
> 
> 
>> On Sep 28, 2017, at 2:32 AM, Martin Schiller <ms at dev.tdt.de> wrote:
>> 
>> If you rename a network interface, there is a move uevent
>> invoked instead of remove/add.
>> 
>> This patch adds support for this kind of event.
>> 
>> Signed-off-by: Martin Schiller <ms at dev.tdt.de>
>> ---
>> system-linux.c | 31 ++++++++++++++++++++++++++++---
>> 1 file changed, 28 insertions(+), 3 deletions(-)
>> 
>> diff --git a/system-linux.c b/system-linux.c
>> index 6d97a02..e2017d0 100644
>> --- a/system-linux.c
>> +++ b/system-linux.c
>> @@ -543,16 +543,20 @@ out:
>> static void
>> handle_hotplug_msg(char *data, int size)
>> {
>> -	const char *subsystem = NULL, *interface = NULL;
>> +	const char *subsystem = NULL, *interface = NULL, *interface_old = 
>> NULL;
>> 	char *cur, *end, *sep;
>> 	struct device *dev;
>> 	int skip;
>> -	bool add;
>> +	bool add, move = false;
>> 
>> 	if (!strncmp(data, "add@", 4))
>> 		add = true;
>> 	else if (!strncmp(data, "remove@", 7))
>> 		add = false;
>> +	else if (!strncmp(data, "move@", 5)) {
>> +		add = true;
>> +		move = true;
>> +	}
>> 	else
>> 		return;
>> 
>> @@ -574,11 +578,32 @@ handle_hotplug_msg(char *data, int size)
>> 			if (strcmp(subsystem, "net") != 0)
>> 				return;
>> 		}
>> -		if (subsystem && interface)
>> +		else if (!strcmp(cur, "DEVPATH_OLD")) {
>> +			interface_old = strrchr(sep + 1, '/');
>> +			if (interface_old)
>> +				interface_old++;
>> +		}
>> +	}
>> +
>> +	if (subsystem && interface) {
>> +		if (move && interface_old)
>> +			goto move;
>> +		else
>> 			goto found;
>> 	}
>> +
>> 	return;
>> 
>> +move:
>> +	dev = device_find(interface_old);
>> +	if (!dev)
>> +		goto found;
>> +
>> +	if (dev->type != &simple_device_type)
>> +		goto found;
>> +
>> +	device_set_present(dev, false);
>> +
>> found:
>> 	dev = device_find(interface);
>> 	if (!dev)
>> 
> 
> 
> I’m a little unclear about how all of this would work.
> 
> We have a platform where the kernel always detects certain devices
> (mostly i210 and i350 Intel NICs) in the wrong order, so early on
> (S19) we run an init.d script which looks at their PCI bus information
> and then depending on whether it matches the pattern of the devices
> which get mis-numbered, we do the following:
> 
> ip link set eth0 name _eth0
> ip link set eth1 name _eth1
> ...
> ip link set eth7 name _eth7
> 
> ip link set _eth7 name eth0
> ip link set _eth6 name eth1
> ...
> ip link set _eth0 name eth7
> 
> so it seems to me that your logic would get confused by the “old”
> instance of “eth0” and the new one.
> 
> Am I missing anything?

I can't see any reason why the logic would get confused here:

After the "ip link set eth0 name _eth0", the eth0 device would be set to 
"NOT-present".
And after "ip link set _eth7 name eth0", the eth0 device would be set to 
"present" again.

Martin.




More information about the Lede-dev mailing list