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
3f0ed090
Commit
3f0ed090
authored
Jul 05, 2019
by
Thomas Parrott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
network: Adds mode param (bridge, router) to veth network setting
Defaulting to bridge mode. Signed-off-by:
Thomas Parrott
<
thomas.parrott@canonical.com
>
parent
3e7d1bd1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
0 deletions
+102
-0
confile.c
src/lxc/confile.c
+70
-0
confile_utils.c
src/lxc/confile_utils.c
+22
-0
confile_utils.h
src/lxc/confile_utils.h
+1
-0
macro.h
src/lxc/macro.h
+8
-0
network.h
src/lxc/network.h
+1
-0
No files found.
src/lxc/confile.c
View file @
3f0ed090
...
...
@@ -139,6 +139,7 @@ lxc_config_define(net_nic);
lxc_config_define
(
net_script_down
);
lxc_config_define
(
net_script_up
);
lxc_config_define
(
net_type
);
lxc_config_define
(
net_veth_mode
);
lxc_config_define
(
net_veth_pair
);
lxc_config_define
(
net_veth_ipv4_route
);
lxc_config_define
(
net_veth_ipv6_route
);
...
...
@@ -234,6 +235,7 @@ static struct lxc_config_t config_jump_table[] = {
{
"lxc.net.script.up"
,
set_config_net_script_up
,
get_config_net_script_up
,
clr_config_net_script_up
,
},
{
"lxc.net.type"
,
set_config_net_type
,
get_config_net_type
,
clr_config_net_type
,
},
{
"lxc.net.vlan.id"
,
set_config_net_vlan_id
,
get_config_net_vlan_id
,
clr_config_net_vlan_id
,
},
{
"lxc.net.veth.mode"
,
set_config_net_veth_mode
,
get_config_net_veth_mode
,
clr_config_net_veth_mode
,
},
{
"lxc.net.veth.pair"
,
set_config_net_veth_pair
,
get_config_net_veth_pair
,
clr_config_net_veth_pair
,
},
{
"lxc.net.veth.ipv4.route"
,
set_config_net_veth_ipv4_route
,
get_config_net_veth_ipv4_route
,
clr_config_net_veth_ipv4_route
,
},
{
"lxc.net.veth.ipv6.route"
,
set_config_net_veth_ipv6_route
,
get_config_net_veth_ipv6_route
,
clr_config_net_veth_ipv6_route
,
},
...
...
@@ -303,6 +305,7 @@ static int set_config_net_type(const char *key, const char *value,
netdev
->
type
=
LXC_NET_VETH
;
lxc_list_init
(
&
netdev
->
priv
.
veth_attr
.
ipv4_routes
);
lxc_list_init
(
&
netdev
->
priv
.
veth_attr
.
ipv6_routes
);
lxc_veth_mode_to_flag
(
&
netdev
->
priv
.
veth_attr
.
mode
,
"bridge"
);
}
else
if
(
strcmp
(
value
,
"macvlan"
)
==
0
)
{
netdev
->
type
=
LXC_NET_MACVLAN
;
lxc_macvlan_mode_to_flag
(
&
netdev
->
priv
.
macvlan_attr
.
mode
,
"private"
);
...
...
@@ -450,6 +453,21 @@ static int set_config_net_name(const char *key, const char *value,
return
network_ifname
(
netdev
->
name
,
value
,
sizeof
(
netdev
->
name
));
}
static
int
set_config_net_veth_mode
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
lxc_config_value_empty
(
value
))
return
clr_config_net_veth_mode
(
key
,
lxc_conf
,
data
);
if
(
!
netdev
)
return
-
1
;
return
lxc_veth_mode_to_flag
(
&
netdev
->
priv
.
veth_attr
.
mode
,
value
);
}
static
int
set_config_net_veth_pair
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
...
...
@@ -5094,6 +5112,22 @@ static int clr_config_net_ipvlan_isolation(const char *key,
return
0
;
}
static
int
clr_config_net_veth_mode
(
const
char
*
key
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
netdev
)
return
minus_one_set_errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_VETH
)
return
0
;
netdev
->
priv
.
veth_attr
.
mode
=
-
1
;
return
0
;
}
static
int
clr_config_net_veth_pair
(
const
char
*
key
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
...
...
@@ -5516,6 +5550,42 @@ static int get_config_net_ipvlan_isolation(const char *key, char *retv, int inle
return
fulllen
;
}
static
int
get_config_net_veth_mode
(
const
char
*
key
,
char
*
retv
,
int
inlen
,
struct
lxc_conf
*
c
,
void
*
data
)
{
int
len
;
int
fulllen
=
0
;
const
char
*
mode
;
struct
lxc_netdev
*
netdev
=
data
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
netdev
)
return
minus_one_set_errno
(
EINVAL
);
if
(
netdev
->
type
!=
LXC_NET_VETH
)
return
0
;
switch
(
netdev
->
priv
.
veth_attr
.
mode
)
{
case
VETH_MODE_BRIDGE
:
mode
=
"bridge"
;
break
;
case
VETH_MODE_ROUTER
:
mode
=
"router"
;
break
;
default:
mode
=
"(invalid)"
;
break
;
}
strprint
(
retv
,
inlen
,
"%s"
,
mode
);
return
fulllen
;
}
static
int
get_config_net_veth_pair
(
const
char
*
key
,
char
*
retv
,
int
inlen
,
struct
lxc_conf
*
c
,
void
*
data
)
{
...
...
src/lxc/confile_utils.c
View file @
3f0ed090
...
...
@@ -501,6 +501,28 @@ void lxc_free_networks(struct lxc_list *networks)
lxc_list_init
(
networks
);
}
static
struct
lxc_veth_mode
{
char
*
name
;
int
mode
;
}
veth_mode
[]
=
{
{
"bridge"
,
VETH_MODE_BRIDGE
},
{
"router"
,
VETH_MODE_ROUTER
},
};
int
lxc_veth_mode_to_flag
(
int
*
mode
,
const
char
*
value
)
{
for
(
size_t
i
=
0
;
i
<
sizeof
(
veth_mode
)
/
sizeof
(
veth_mode
[
0
]);
i
++
)
{
if
(
strcmp
(
veth_mode
[
i
].
name
,
value
)
!=
0
)
continue
;
*
mode
=
veth_mode
[
i
].
mode
;
return
0
;
}
return
minus_one_set_errno
(
EINVAL
);
}
static
struct
lxc_macvlan_mode
{
char
*
name
;
int
mode
;
...
...
src/lxc/confile_utils.h
View file @
3f0ed090
...
...
@@ -56,6 +56,7 @@ lxc_get_netdev_by_idx(struct lxc_conf *conf, unsigned int idx, bool allocate);
extern
void
lxc_log_configured_netdevs
(
const
struct
lxc_conf
*
conf
);
extern
bool
lxc_remove_nic_by_idx
(
struct
lxc_conf
*
conf
,
unsigned
int
idx
);
extern
void
lxc_free_networks
(
struct
lxc_list
*
networks
);
extern
int
lxc_veth_mode_to_flag
(
int
*
mode
,
const
char
*
value
);
extern
int
lxc_macvlan_mode_to_flag
(
int
*
mode
,
const
char
*
value
);
extern
char
*
lxc_macvlan_flag_to_mode
(
int
mode
);
extern
int
lxc_ipvlan_mode_to_flag
(
int
*
mode
,
const
char
*
value
);
...
...
src/lxc/macro.h
View file @
3f0ed090
...
...
@@ -281,6 +281,14 @@ extern int __build_bug_on_failed;
#define VETH_INFO_PEER 1
#endif
#ifndef VETH_MODE_BRIDGE
#define VETH_MODE_BRIDGE 1
#endif
#ifndef VETH_MODE_ROUTER
#define VETH_MODE_ROUTER 2
#endif
#ifndef IFLA_MACVLAN_MODE
#define IFLA_MACVLAN_MODE 1
#endif
...
...
src/lxc/network.h
View file @
3f0ed090
...
...
@@ -98,6 +98,7 @@ struct ifla_veth {
int
ifindex
;
struct
lxc_list
ipv4_routes
;
struct
lxc_list
ipv6_routes
;
int
mode
;
/* bridge, router */
};
struct
ifla_vlan
{
...
...
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