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
bad2f913
Unverified
Commit
bad2f913
authored
Feb 26, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
network: make callback naming consistent and understandable
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
32d40452
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
55 deletions
+57
-55
network.c
src/lxc/network.c
+57
-55
No files found.
src/lxc/network.c
View file @
bad2f913
...
@@ -46,8 +46,10 @@
...
@@ -46,8 +46,10 @@
lxc_log_define
(
network
,
lxc
);
lxc_log_define
(
network
,
lxc
);
typedef
int
(
*
instantiate_cb
)(
struct
lxc_handler
*
,
struct
lxc_netdev
*
);
typedef
int
(
*
netdev_configure_server_cb
)(
struct
lxc_handler
*
,
struct
lxc_netdev
*
);
typedef
int
(
*
instantiate_ns_cb
)(
struct
lxc_netdev
*
);
typedef
int
(
*
netdev_configure_container_cb
)(
struct
lxc_netdev
*
);
typedef
int
(
*
netdev_shutdown_server_cb
)(
struct
lxc_handler
*
,
struct
lxc_netdev
*
);
static
const
char
loop_device
[]
=
"lo"
;
static
const
char
loop_device
[]
=
"lo"
;
static
int
lxc_ip_route_dest
(
__u16
nlmsg_type
,
int
family
,
int
ifindex
,
void
*
dest
,
unsigned
int
netmask
)
static
int
lxc_ip_route_dest
(
__u16
nlmsg_type
,
int
family
,
int
ifindex
,
void
*
dest
,
unsigned
int
netmask
)
...
@@ -537,7 +539,7 @@ static int setup_veth_ovs_bridge_vlan(char *veth1, struct lxc_netdev *netdev)
...
@@ -537,7 +539,7 @@ static int setup_veth_ovs_bridge_vlan(char *veth1, struct lxc_netdev *netdev)
return
0
;
return
0
;
}
}
static
int
instantiate
_veth
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_server
_veth
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
int
err
;
int
err
;
unsigned
int
mtu
=
1500
;
unsigned
int
mtu
=
1500
;
...
@@ -771,7 +773,7 @@ out_delete:
...
@@ -771,7 +773,7 @@ out_delete:
return
-
1
;
return
-
1
;
}
}
static
int
instantiate
_macvlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_server
_macvlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
char
peer
[
IFNAMSIZ
];
char
peer
[
IFNAMSIZ
];
int
err
;
int
err
;
...
@@ -921,7 +923,7 @@ static int lxc_ipvlan_create(const char *parent, const char *name, int mode, int
...
@@ -921,7 +923,7 @@ static int lxc_ipvlan_create(const char *parent, const char *name, int mode, int
return
netlink_transaction
(
nlh_ptr
,
nlmsg
,
answer
);
return
netlink_transaction
(
nlh_ptr
,
nlmsg
,
answer
);
}
}
static
int
instantiate
_ipvlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_server
_ipvlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
char
peer
[
IFNAMSIZ
];
char
peer
[
IFNAMSIZ
];
int
err
;
int
err
;
...
@@ -995,7 +997,7 @@ on_error:
...
@@ -995,7 +997,7 @@ on_error:
return
-
1
;
return
-
1
;
}
}
static
int
instantiate
_vlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_server
_vlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
char
peer
[
IFNAMSIZ
];
char
peer
[
IFNAMSIZ
];
int
err
;
int
err
;
...
@@ -1069,7 +1071,7 @@ on_error:
...
@@ -1069,7 +1071,7 @@ on_error:
return
-
1
;
return
-
1
;
}
}
static
int
instantiate
_phys
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_server
_phys
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
int
err
,
mtu_orig
=
0
;
int
err
,
mtu_orig
=
0
;
...
@@ -1139,7 +1141,7 @@ static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netd
...
@@ -1139,7 +1141,7 @@ static int instantiate_phys(struct lxc_handler *handler, struct lxc_netdev *netd
return
0
;
return
0
;
}
}
static
int
instantiate
_empty
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_server
_empty
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
int
ret
;
int
ret
;
char
*
argv
[]
=
{
char
*
argv
[]
=
{
...
@@ -1159,23 +1161,23 @@ static int instantiate_empty(struct lxc_handler *handler, struct lxc_netdev *net
...
@@ -1159,23 +1161,23 @@ static int instantiate_empty(struct lxc_handler *handler, struct lxc_netdev *net
return
0
;
return
0
;
}
}
static
int
instantiate
_none
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_server
_none
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
netdev
->
ifindex
=
0
;
netdev
->
ifindex
=
0
;
return
0
;
return
0
;
}
}
static
instantiate_cb
netdev_conf
[
LXC_NET_MAXCONFTYPE
+
1
]
=
{
static
netdev_configure_server_cb
netdev_configure_server
[
LXC_NET_MAXCONFTYPE
+
1
]
=
{
[
LXC_NET_VETH
]
=
instantiate
_veth
,
[
LXC_NET_VETH
]
=
netdev_configure_server
_veth
,
[
LXC_NET_MACVLAN
]
=
instantiate
_macvlan
,
[
LXC_NET_MACVLAN
]
=
netdev_configure_server
_macvlan
,
[
LXC_NET_IPVLAN
]
=
instantiate
_ipvlan
,
[
LXC_NET_IPVLAN
]
=
netdev_configure_server
_ipvlan
,
[
LXC_NET_VLAN
]
=
instantiate
_vlan
,
[
LXC_NET_VLAN
]
=
netdev_configure_server
_vlan
,
[
LXC_NET_PHYS
]
=
instantiate
_phys
,
[
LXC_NET_PHYS
]
=
netdev_configure_server
_phys
,
[
LXC_NET_EMPTY
]
=
instantiate
_empty
,
[
LXC_NET_EMPTY
]
=
netdev_configure_server
_empty
,
[
LXC_NET_NONE
]
=
instantiate
_none
,
[
LXC_NET_NONE
]
=
netdev_configure_server
_none
,
};
};
static
int
__
instantiate_ns
_common
(
struct
lxc_netdev
*
netdev
)
static
int
__
netdev_configure_container
_common
(
struct
lxc_netdev
*
netdev
)
{
{
char
current_ifname
[
IFNAMSIZ
];
char
current_ifname
[
IFNAMSIZ
];
...
@@ -1217,53 +1219,53 @@ static int __instantiate_ns_common(struct lxc_netdev *netdev)
...
@@ -1217,53 +1219,53 @@ static int __instantiate_ns_common(struct lxc_netdev *netdev)
return
0
;
return
0
;
}
}
static
int
instantiate_ns
_veth
(
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_container
_veth
(
struct
lxc_netdev
*
netdev
)
{
{
return
__
instantiate_ns
_common
(
netdev
);
return
__
netdev_configure_container
_common
(
netdev
);
}
}
static
int
instantiate_ns
_macvlan
(
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_container
_macvlan
(
struct
lxc_netdev
*
netdev
)
{
{
return
__
instantiate_ns
_common
(
netdev
);
return
__
netdev_configure_container
_common
(
netdev
);
}
}
static
int
instantiate_ns
_ipvlan
(
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_container
_ipvlan
(
struct
lxc_netdev
*
netdev
)
{
{
return
__
instantiate_ns
_common
(
netdev
);
return
__
netdev_configure_container
_common
(
netdev
);
}
}
static
int
instantiate_ns
_vlan
(
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_container
_vlan
(
struct
lxc_netdev
*
netdev
)
{
{
return
__
instantiate_ns
_common
(
netdev
);
return
__
netdev_configure_container
_common
(
netdev
);
}
}
static
int
instantiate_ns
_phys
(
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_container
_phys
(
struct
lxc_netdev
*
netdev
)
{
{
return
__
instantiate_ns
_common
(
netdev
);
return
__
netdev_configure_container
_common
(
netdev
);
}
}
static
int
instantiate_ns
_empty
(
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_container
_empty
(
struct
lxc_netdev
*
netdev
)
{
{
return
0
;
return
0
;
}
}
static
int
instantiate_ns
_none
(
struct
lxc_netdev
*
netdev
)
static
int
netdev_configure_container
_none
(
struct
lxc_netdev
*
netdev
)
{
{
return
0
;
return
0
;
}
}
static
instantiate_ns_cb
netdev_ns_conf
[
LXC_NET_MAXCONFTYPE
+
1
]
=
{
static
netdev_configure_container_cb
netdev_configure_container
[
LXC_NET_MAXCONFTYPE
+
1
]
=
{
[
LXC_NET_VETH
]
=
instantiate_ns
_veth
,
[
LXC_NET_VETH
]
=
netdev_configure_container
_veth
,
[
LXC_NET_MACVLAN
]
=
instantiate_ns
_macvlan
,
[
LXC_NET_MACVLAN
]
=
netdev_configure_container
_macvlan
,
[
LXC_NET_IPVLAN
]
=
instantiate_ns
_ipvlan
,
[
LXC_NET_IPVLAN
]
=
netdev_configure_container
_ipvlan
,
[
LXC_NET_VLAN
]
=
instantiate_ns
_vlan
,
[
LXC_NET_VLAN
]
=
netdev_configure_container
_vlan
,
[
LXC_NET_PHYS
]
=
instantiate_ns
_phys
,
[
LXC_NET_PHYS
]
=
netdev_configure_container
_phys
,
[
LXC_NET_EMPTY
]
=
instantiate_ns
_empty
,
[
LXC_NET_EMPTY
]
=
netdev_configure_container
_empty
,
[
LXC_NET_NONE
]
=
instantiate_ns
_none
,
[
LXC_NET_NONE
]
=
netdev_configure_container
_none
,
};
};
static
int
shutdown
_veth
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_shutdown_server
_veth
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
int
ret
;
int
ret
;
char
*
argv
[]
=
{
char
*
argv
[]
=
{
...
@@ -1290,7 +1292,7 @@ static int shutdown_veth(struct lxc_handler *handler, struct lxc_netdev *netdev)
...
@@ -1290,7 +1292,7 @@ static int shutdown_veth(struct lxc_handler *handler, struct lxc_netdev *netdev)
return
0
;
return
0
;
}
}
static
int
shutdown
_macvlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_shutdown_server
_macvlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
int
ret
;
int
ret
;
char
*
argv
[]
=
{
char
*
argv
[]
=
{
...
@@ -1310,7 +1312,7 @@ static int shutdown_macvlan(struct lxc_handler *handler, struct lxc_netdev *netd
...
@@ -1310,7 +1312,7 @@ static int shutdown_macvlan(struct lxc_handler *handler, struct lxc_netdev *netd
return
0
;
return
0
;
}
}
static
int
shutdown
_ipvlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_shutdown_server
_ipvlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
int
ret
;
int
ret
;
char
*
argv
[]
=
{
char
*
argv
[]
=
{
...
@@ -1330,7 +1332,7 @@ static int shutdown_ipvlan(struct lxc_handler *handler, struct lxc_netdev *netde
...
@@ -1330,7 +1332,7 @@ static int shutdown_ipvlan(struct lxc_handler *handler, struct lxc_netdev *netde
return
0
;
return
0
;
}
}
static
int
shutdown
_vlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_shutdown_server
_vlan
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
int
ret
;
int
ret
;
char
*
argv
[]
=
{
char
*
argv
[]
=
{
...
@@ -1350,7 +1352,7 @@ static int shutdown_vlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
...
@@ -1350,7 +1352,7 @@ static int shutdown_vlan(struct lxc_handler *handler, struct lxc_netdev *netdev)
return
0
;
return
0
;
}
}
static
int
shutdown
_phys
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_shutdown_server
_phys
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
int
ret
;
int
ret
;
char
*
argv
[]
=
{
char
*
argv
[]
=
{
...
@@ -1370,7 +1372,7 @@ static int shutdown_phys(struct lxc_handler *handler, struct lxc_netdev *netdev)
...
@@ -1370,7 +1372,7 @@ static int shutdown_phys(struct lxc_handler *handler, struct lxc_netdev *netdev)
return
0
;
return
0
;
}
}
static
int
shutdown
_empty
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_shutdown_server
_empty
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
int
ret
;
int
ret
;
char
*
argv
[]
=
{
char
*
argv
[]
=
{
...
@@ -1389,19 +1391,19 @@ static int shutdown_empty(struct lxc_handler *handler, struct lxc_netdev *netdev
...
@@ -1389,19 +1391,19 @@ static int shutdown_empty(struct lxc_handler *handler, struct lxc_netdev *netdev
return
0
;
return
0
;
}
}
static
int
shutdown
_none
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
static
int
netdev_shutdown_server
_none
(
struct
lxc_handler
*
handler
,
struct
lxc_netdev
*
netdev
)
{
{
return
0
;
return
0
;
}
}
static
instantiate
_cb
netdev_deconf
[
LXC_NET_MAXCONFTYPE
+
1
]
=
{
static
netdev_shutdown_server
_cb
netdev_deconf
[
LXC_NET_MAXCONFTYPE
+
1
]
=
{
[
LXC_NET_VETH
]
=
shutdown
_veth
,
[
LXC_NET_VETH
]
=
netdev_shutdown_server
_veth
,
[
LXC_NET_MACVLAN
]
=
shutdown
_macvlan
,
[
LXC_NET_MACVLAN
]
=
netdev_shutdown_server
_macvlan
,
[
LXC_NET_IPVLAN
]
=
shutdown
_ipvlan
,
[
LXC_NET_IPVLAN
]
=
netdev_shutdown_server
_ipvlan
,
[
LXC_NET_VLAN
]
=
shutdown
_vlan
,
[
LXC_NET_VLAN
]
=
netdev_shutdown_server
_vlan
,
[
LXC_NET_PHYS
]
=
shutdown
_phys
,
[
LXC_NET_PHYS
]
=
netdev_shutdown_server
_phys
,
[
LXC_NET_EMPTY
]
=
shutdown
_empty
,
[
LXC_NET_EMPTY
]
=
netdev_shutdown_server
_empty
,
[
LXC_NET_NONE
]
=
shutdown
_none
,
[
LXC_NET_NONE
]
=
netdev_shutdown_server
_none
,
};
};
static
int
lxc_netdev_move_by_index_fd
(
int
ifindex
,
int
fd
,
const
char
*
ifname
)
static
int
lxc_netdev_move_by_index_fd
(
int
ifindex
,
int
fd
,
const
char
*
ifname
)
...
@@ -3379,7 +3381,7 @@ static int lxc_create_network_priv(struct lxc_handler *handler)
...
@@ -3379,7 +3381,7 @@ static int lxc_create_network_priv(struct lxc_handler *handler)
return
log_error_errno
(
-
1
,
errno
,
"Failed to setup l2proxy"
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to setup l2proxy"
);
}
}
if
(
netdev_conf
[
netdev
->
type
](
handler
,
netdev
))
if
(
netdev_conf
igure_server
[
netdev
->
type
](
handler
,
netdev
))
return
log_error_errno
(
-
1
,
errno
,
"Failed to create network device"
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to create network device"
);
}
}
...
@@ -3843,7 +3845,7 @@ int lxc_setup_network_in_child_namespaces(const struct lxc_conf *conf,
...
@@ -3843,7 +3845,7 @@ int lxc_setup_network_in_child_namespaces(const struct lxc_conf *conf,
struct
lxc_netdev
*
netdev
=
iterator
->
elem
;
struct
lxc_netdev
*
netdev
=
iterator
->
elem
;
int
ret
;
int
ret
;
ret
=
netdev_
ns_conf
[
netdev
->
type
](
netdev
);
ret
=
netdev_
configure_container
[
netdev
->
type
](
netdev
);
if
(
!
ret
)
if
(
!
ret
)
ret
=
lxc_network_setup_in_child_namespaces_common
(
netdev
);
ret
=
lxc_network_setup_in_child_namespaces_common
(
netdev
);
if
(
ret
)
if
(
ret
)
...
...
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