Skip to content

Commit 51db32b

Browse files
committed
Bug #13548252: MYSQL ASSUMES ALL ETHERNET DEVICES ARE NAMED ETHX
Bug #63055 : mysql assumes all ethernet devices are named ethX The MySQL server is using the first non-zero hardware address of an arbitrary network interface for generating UUIDs. On Linux, the MySQL server is only trying interface names "eth{0-5}". The patch retrieves the list of known interface names rather than assuming names of a certain pattern. Patch contributed by Honza Horak
1 parent 6e597e1 commit 51db32b

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

mysys/my_gethwaddr.c

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -68,30 +68,61 @@ my_bool my_gethwaddr(uchar *to)
6868
#include <sys/ioctl.h>
6969
#include <net/ethernet.h>
7070

71+
#define MAX_IFS 64
72+
7173
my_bool my_gethwaddr(uchar *to)
7274
{
73-
int fd, res= 1;
75+
int fd= -1;
76+
int res= 1;
7477
struct ifreq ifr;
78+
struct ifreq ifs[MAX_IFS];
79+
struct ifreq *ifri= NULL;
80+
struct ifreq *ifend= NULL;
81+
7582
char zero_array[ETHER_ADDR_LEN] = {0};
83+
struct ifconf ifc;
7684

7785
fd = socket(AF_INET, SOCK_DGRAM, 0);
7886
if (fd < 0)
79-
goto err;
87+
return 1;
88+
89+
/* Retrieve interfaces */
90+
ifc.ifc_len= sizeof(ifs);
91+
ifc.ifc_req= ifs;
92+
if (ioctl(fd, SIOCGIFCONF, &ifc) < 0)
93+
{
94+
close(fd);
95+
return 1;
96+
}
97+
98+
/* Initialize out parameter */
99+
memcpy(to, zero_array, ETHER_ADDR_LEN);
80100

81-
memset(&ifr, 0, sizeof(ifr));
82-
strnmov(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
101+
/* Calculate first address after array */
102+
ifend= ifs + (ifc.ifc_len / sizeof(struct ifreq));
83103

84-
do
104+
/* Loop over all interfaces */
105+
for (ifri= ifc.ifc_req; ifri < ifend; ifri++)
85106
{
86-
if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
107+
if (ifri->ifr_addr.sa_family == AF_INET)
87108
{
88-
memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
89-
res= memcmp(to, zero_array, ETHER_ADDR_LEN) ? 0 : 1;
90-
}
91-
} while (res && (errno == 0 || errno == ENODEV) && ifr.ifr_name[3]++ < '6');
109+
/* Reset struct, copy interface name */
110+
memset(&ifr, 0, sizeof(ifr));
111+
strncpy(ifr.ifr_name, ifri->ifr_name, sizeof(ifr.ifr_name));
92112

113+
/* Get HW address, break if not 0 */
114+
if (ioctl(fd, SIOCGIFHWADDR, &ifr) >= 0)
115+
{
116+
memcpy(to, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
117+
if (memcmp(to, zero_array, ETHER_ADDR_LEN))
118+
{
119+
res= 0;
120+
break;
121+
}
122+
}
123+
}
124+
}
93125
close(fd);
94-
err:
95126
return res;
96127
}
97128

0 commit comments

Comments
 (0)