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
8b7ffa30
Commit
8b7ffa30
authored
Dec 16, 2016
by
Serge Hallyn
Committed by
GitHub
Dec 16, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1343 from lifupan/master
confile: support the network link string pattern matching
parents
7d091d9e
576400e5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
1 deletion
+76
-1
confile.c
src/lxc/confile.c
+76
-1
No files found.
src/lxc/confile.c
View file @
8b7ffa30
...
@@ -50,6 +50,12 @@
...
@@ -50,6 +50,12 @@
#include "network.h"
#include "network.h"
#include "lxcseccomp.h"
#include "lxcseccomp.h"
#if HAVE_IFADDRS_H
#include <ifaddrs.h>
#else
#include <../include/ifaddrs.h>
#endif
#if HAVE_SYS_PERSONALITY_H
#if HAVE_SYS_PERSONALITY_H
#include <sys/personality.h>
#include <sys/personality.h>
#endif
#endif
...
@@ -672,16 +678,85 @@ static int config_network_flags(const char *key, const char *value,
...
@@ -672,16 +678,85 @@ static int config_network_flags(const char *key, const char *value,
return
0
;
return
0
;
}
}
static
int
set_network_link
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
struct
lxc_netdev
*
netdev
;
netdev
=
network_netdev
(
key
,
value
,
&
lxc_conf
->
network
);
if
(
!
netdev
)
return
-
1
;
return
network_ifname
(
&
netdev
->
link
,
value
);
}
static
int
create_matched_ifnames
(
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
struct
ifaddrs
*
ifaddr
,
*
ifa
;
const
char
*
type_key
=
"lxc.network.type"
;
const
char
*
link_key
=
"lxc.network.link"
;
const
char
*
tmpvalue
=
"phys"
;
int
n
,
ret
=
0
;
if
(
getifaddrs
(
&
ifaddr
)
==
-
1
)
{
SYSERROR
(
"Get network interfaces failed"
);
return
-
1
;
}
for
(
ifa
=
ifaddr
,
n
=
0
;
ifa
!=
NULL
;
ifa
=
ifa
->
ifa_next
,
n
++
)
{
if
(
!
ifa
->
ifa_addr
)
continue
;
if
(
ifa
->
ifa_addr
->
sa_family
!=
AF_PACKET
)
continue
;
if
(
!
strncmp
(
value
,
ifa
->
ifa_name
,
strlen
(
value
)
-
1
))
{
ret
=
config_network_type
(
type_key
,
tmpvalue
,
lxc_conf
);
if
(
!
ret
)
{
ret
=
set_network_link
(
link_key
,
ifa
->
ifa_name
,
lxc_conf
);
if
(
ret
)
{
ERROR
(
"failed to create matched ifnames"
);
break
;
}
}
else
{
ERROR
(
"failed to create matched ifnames"
);
break
;
}
}
}
freeifaddrs
(
ifaddr
);
/* free the dynamic memory */
ifaddr
=
NULL
;
/* prevent use after free */
return
ret
;
}
static
int
config_network_link
(
const
char
*
key
,
const
char
*
value
,
static
int
config_network_link
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
struct
lxc_conf
*
lxc_conf
)
{
{
struct
lxc_netdev
*
netdev
;
struct
lxc_netdev
*
netdev
;
struct
lxc_list
*
it
;
int
ret
=
0
;
netdev
=
network_netdev
(
key
,
value
,
&
lxc_conf
->
network
);
netdev
=
network_netdev
(
key
,
value
,
&
lxc_conf
->
network
);
if
(
!
netdev
)
if
(
!
netdev
)
return
-
1
;
return
-
1
;
return
network_ifname
(
&
netdev
->
link
,
value
);
if
(
value
[
strlen
(
value
)
-
1
]
==
'+'
&&
netdev
->
type
==
LXC_NET_PHYS
)
{
//get the last network list and remove it.
it
=
lxc_conf
->
network
.
prev
;
if
(((
struct
lxc_netdev
*
)(
it
->
elem
))
->
type
!=
LXC_NET_PHYS
)
{
ERROR
(
"lxc config cannot support string pattern matching for this link type"
);
return
-
1
;
}
lxc_list_del
(
it
);
free
(
it
);
ret
=
create_matched_ifnames
(
value
,
lxc_conf
);
}
else
{
ret
=
network_ifname
(
&
netdev
->
link
,
value
);
}
return
ret
;
}
}
static
int
config_network_name
(
const
char
*
key
,
const
char
*
value
,
static
int
config_network_name
(
const
char
*
key
,
const
char
*
value
,
...
...
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