Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
8bbca3cc
Unverified
Commit
8bbca3cc
authored
Jul 17, 2020
by
Christian Brauner
Committed by
GitHub
Jul 17, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3487 from samboyles1/master
Improve efficiency of lxc_ifname_alnum_case_sensitive
parents
19be19a3
4810a7a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
18 deletions
+2
-18
network.c
src/lxc/network.c
+2
-18
No files found.
src/lxc/network.c
View file @
8bbca3cc
...
...
@@ -2754,9 +2754,7 @@ static const char padchar[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM
char
*
lxc_ifname_alnum_case_sensitive
(
char
*
template
)
{
int
ret
;
struct
netns_ifaddrs
*
ifa
,
*
ifaddr
;
char
name
[
IFNAMSIZ
];
bool
exists
=
false
;
size_t
i
=
0
;
#ifdef HAVE_RAND_R
unsigned
int
seed
;
...
...
@@ -2770,18 +2768,11 @@ char *lxc_ifname_alnum_case_sensitive(char *template)
if
(
strlen
(
template
)
>=
IFNAMSIZ
)
return
NULL
;
/* Get all the network interfaces. */
ret
=
netns_getifaddrs
(
&
ifaddr
,
-
1
,
&
(
bool
){
false
});
if
(
ret
<
0
)
return
log_error_errno
(
NULL
,
errno
,
"Failed to get network interfaces"
);
/* Generate random names until we find one that doesn't exist. */
for
(;;)
{
name
[
0
]
=
'\0'
;
(
void
)
strlcpy
(
name
,
template
,
IFNAMSIZ
);
exists
=
false
;
for
(
i
=
0
;
i
<
strlen
(
name
);
i
++
)
{
if
(
name
[
i
]
==
'X'
)
{
#ifdef HAVE_RAND_R
...
...
@@ -2792,18 +2783,11 @@ char *lxc_ifname_alnum_case_sensitive(char *template)
}
}
for
(
ifa
=
ifaddr
;
ifa
!=
NULL
;
ifa
=
ifa
->
ifa_next
)
{
if
(
!
strcmp
(
ifa
->
ifa_name
,
name
))
{
exists
=
true
;
break
;
}
}
if
(
!
exists
)
if
(
if_nametoindex
(
name
)
==
0
)
{
break
;
}
}
netns_freeifaddrs
(
ifaddr
);
(
void
)
strlcpy
(
template
,
name
,
strlen
(
template
)
+
1
);
return
template
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment