mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-04 12:28:58 +00:00
When translating the interface name when "eth?" is given, do not
use the internal index number as the unit number to compare with. The first ethernet interface in Linux is called "eth0", whereas our internal index starts wth 1 and is not unique to ethernet interfaces (lo0 has index 1 for example). Instead, use a function- local index number that starts with 0 and is incremented only for ethernet interfaces. This way the unit number will match the n-th ethernet interface in the system, which is exactly what it means in Linux. Tested by: Glenn Johnson <gjohnson@srrc.ars.usda.gov> MFC after: 3 days
This commit is contained in:
parent
54d8895199
commit
53b9d88fc4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=87335
@ -1793,6 +1793,7 @@ ifname_linux_to_bsd(const char *lxname, char *bsdname)
|
||||
struct ifnet *ifp;
|
||||
int len, unit;
|
||||
char *ep;
|
||||
int is_eth, index;
|
||||
|
||||
for (len = 0; len < LINUX_IFNAMSIZ; ++len)
|
||||
if (!isalpha(lxname[len]))
|
||||
@ -1802,13 +1803,18 @@ ifname_linux_to_bsd(const char *lxname, char *bsdname)
|
||||
unit = (int)strtoul(lxname + len, &ep, 10);
|
||||
if (ep == NULL || ep == lxname + len || ep >= lxname + LINUX_IFNAMSIZ)
|
||||
return (NULL);
|
||||
index = 0;
|
||||
is_eth = (len == 3 && !strncmp(lxname, "eth", len)) ? 1 : 0;
|
||||
TAILQ_FOREACH(ifp, &ifnet, if_link) {
|
||||
/* allow Linux programs to use FreeBSD names */
|
||||
/*
|
||||
* Allow Linux programs to use FreeBSD names. Don't presume
|
||||
* we never have an interface named "eth", so don't make
|
||||
* the test optional based on is_eth.
|
||||
*/
|
||||
if (ifp->if_unit == unit && ifp->if_name[len] == '\0' &&
|
||||
strncmp(ifp->if_name, lxname, len) == 0)
|
||||
break;
|
||||
if (ifp->if_index == unit && IFP_IS_ETH(ifp) &&
|
||||
strncmp(lxname, "eth", len) == 0)
|
||||
if (is_eth && IFP_IS_ETH(ifp) && unit == index++)
|
||||
break;
|
||||
}
|
||||
if (ifp != NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user