Skip to content
This repository was archived by the owner on Mar 28, 2018. It is now read-only.

Networking: Adding Base Networking Support for CC using iproute2 #44

Merged
merged 46 commits into from
Aug 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
989bdb7
Initial draft of redesign necessary to support networking.
jodh-intel Jul 14, 2016
803338a
Merge branch 'master' into networking
jodh-intel Jul 15, 2016
e320d0d
Merge branch 'master' into networking
jodh-intel Jul 15, 2016
3899585
Merge branch 'master' into networking
jodh-intel Jul 15, 2016
416b11e
Recreate state file to allow "start" to work.
jodh-intel Jul 15, 2016
14e4eed
Merge branch 'master' into networking
jodh-intel Jul 15, 2016
f1f7773
Merge branch 'master' into networking
jodh-intel Jul 15, 2016
c175dae
Merge branch 'master' into networking
jodh-intel Jul 18, 2016
9482c47
Merge branch 'master' into networking
jodh-intel Jul 18, 2016
50a8de7
Merge branch 'master' into networking
jodh-intel Jul 18, 2016
dddd5bf
Merge branch 'master' into networking
jodh-intel Jul 18, 2016
b0dc2fb
Merge branch 'master' into networking
jodh-intel Jul 18, 2016
7de5308
Merge branch 'master' into networking
jodh-intel Jul 19, 2016
553d3b1
Merge branch 'master' into networking
jodh-intel Jul 19, 2016
fc62d6b
Merge branch 'master' into networking
jodh-intel Jul 19, 2016
97cb5f7
Merge branch 'master' into networking
jodh-intel Jul 19, 2016
7d49cf6
Merge branch 'master' into networking
jodh-intel Jul 19, 2016
6029b1c
Merge branch 'master' into networking
jodh-intel Jul 19, 2016
863b887
Merge branch 'master' into networking
jodh-intel Jul 19, 2016
9ba1eed
Merge branch 'master' into networking
jodh-intel Jul 19, 2016
a58122e
Merge branch 'master' into networking
jodh-intel Jul 20, 2016
c2da04a
Merge branch 'master' into networking
jodh-intel Jul 20, 2016
834cd4f
Merge branch 'master' into networking
jodh-intel Jul 20, 2016
267c7f2
Merge branch 'master' into networking
jodh-intel Jul 20, 2016
cba7da5
Merge branch 'master' into networking
jodh-intel Jul 20, 2016
a41c96e
Merge branch 'master' into networking
jodh-intel Jul 20, 2016
aca3568
Networking: Basic Networking Support
mcastelino Jul 20, 2016
bd6ba81
Networking: Fix prehook invocation
mcastelino Jul 20, 2016
91d31cd
Networking: Adding support for docker --net=none
mcastelino Jul 21, 2016
48c9096
Networking: free network config parameters
mcastelino Jul 21, 2016
f942e18
Merge pull request #43 from mcastelino/networking
mcastelino Jul 21, 2016
d19098a
Networking: Incorporate code review feedback
mcastelino Jul 21, 2016
a78ccdd
Merge pull request #45 from mcastelino/networking
mcastelino Jul 21, 2016
ce6117d
configure.ac: add libnetlink check from iproute2
miguelinux Jul 22, 2016
e94ceb7
Merge pull request #46 from miguelinux/networking-add-libnetlink-requ…
mcastelino Jul 23, 2016
31d1714
DOCS: Add iproute2 dependency to build cc-oci-runtime
gorozco1 Jul 27, 2016
90c6efc
Merge pull request #52 from gorozco1/networking
Jul 28, 2016
f699092
Merge branch 'master' into networking
jodh-intel Aug 2, 2016
c5540bd
Merge branch 'master' into networking
jodh-intel Aug 2, 2016
40dbfcd
Remove duplicate net cfg variable expansion code caused by bad merge.
jodh-intel Aug 2, 2016
ac08179
Networking: Address code review comments
mcastelino Aug 3, 2016
c17c9b9
Merge branch 'master' into networking
jodh-intel Aug 4, 2016
fa9a42b
Networking: Default gateway support
mcastelino Aug 4, 2016
2fbfd7f
Merge pull request #75 from mcastelino/networking
mcastelino Aug 4, 2016
e90b253
Networking: Remove netlink dependency
mcastelino Aug 4, 2016
e376cf6
Merge pull request #76 from mcastelino/networking
mcastelino Aug 4, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions INSTALL_DOCKER.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Install the following bundles and RPMs to enable our work in progress linux-cont
sudo rpm -ivh --nodeps --force https://download.clearlinux.org/current/x86_64/os/Packages/json-glib-lib-1.2.0-8.x86_64.rpm
sudo rpm -ivh --nodeps --force https://download.clearlinux.org/current/x86_64/os/Packages/linux-container-testing-4.5-9.x86_64.rpm
sudo rpm -ivh --nodeps --force https://download.clearlinux.org/current/x86_64/os/Packages/linux-container-testing-extra-4.5-9.x86_64.rpm
sudo rpm -ivh --nodeps --force https://download.clearlinux.org/current/x86_64/os/Packages/iproute2-dev-4.3.0-25.x86_64.rpm
#Note: Ignore the errorldconfig:*
#/usr/lib64/libguile-2.0.so.22.7.2-gdb.scm is not an ELF file - it has the wrong magic bytes at the start.*

Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ common_sources = \
src/process.c src/process.h \
src/mount.c src/mount.h \
src/network.c src/network.h \
src/networking.c src/networking.h \
src/state.c src/state.h \
src/events.c src/events.h \
src/runtime.c src/runtime.h \
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ installed on your system:
- glib
- json-glib
- uuid
- iproute2

Configure Stage
~~~~~~~~~~~~~~~
Expand Down
6 changes: 5 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ AC_ARG_WITH([qemu-path],
[with_qemu_path=no]
)


# Check for netlink from iproute2
#AC_CHECK_HEADERS(libnetlink.h, dummy=yes,
# AC_MSG_ERROR(libnetlink header file from iproute2 is required))
#AC_SEARCH_LIBS(rtnl_close, netlink, dummy=yes,
# AC_MSG_ERROR(netlink library support from iproute2 is required))

AC_CACHE_CHECK(
[for qemu that supports pc-lite machine], [ac_cv_path_QEMU],
Expand Down
6 changes: 5 additions & 1 deletion data/hypervisor.args.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ memory-backend-file,id=mem0,mem-path=@IMAGE@,size=@SIZE@
-kernel
@KERNEL@
-append
@KERNEL_PARAMS@
@KERNEL_PARAMS@ @KERNEL_NET_PARAMS@
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do not put KERNEL_NET_PARAMS in a new line?

Copy link
Contributor Author

@mcastelino mcastelino Jul 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devimc That is because it is actually a concatenation to the same param (i.e kernel command line). Hence we have to put it in the same line. The way the current param expansion logic works it has to be on the same line AFAIK

-device
virtio-9p-pci,fsdev=workload9p,mount_tag=rootfs
-fsdev
Expand Down Expand Up @@ -42,3 +42,7 @@ unix:@COMMS_SOCKET@,server,nowait
-nographic
-vga
none
@NETDEV@
@NETDEV_PARAMS@
@NETDEVICE@
@NETDEVICE_PARAMS@
119 changes: 107 additions & 12 deletions src/hypervisor.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,63 @@
private gchar *sysconfdir = SYSCONFDIR;
private gchar *defaultsdir = DEFAULTSDIR;

static gchar *
cc_oci_expand_net_cmdline(struct cc_oci_config *config) {
/* www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt
* ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:
* <device>:<autoconf>:<dns0-ip>:<dns1-ip>
*/

/* FIXME. Sending multiple ip= does not seem to work
* Hence support one or the other for now
* Explore dracut or systemd based network init
*/

if ( config->net.ip_address != NULL ) {
return ( g_strdup_printf("ip=%s::%s:%s:%s:%s:off::",
config->net.ip_address,
config->net.gateway,
config->net.subnet_mask,
config->net.hostname,
config->net.ifname) );
}

if ( config->net.ipv6_address != NULL ) {
return ( g_strdup_printf("ip=[%s]:::::%s:off::",
config->net.ipv6_address,
config->net.ifname) );
}

return g_strdup("");
}

#define QEMU_FMT_NETDEV "tap,ifname=%s,script=no,downscript=no,id=%s"

static gchar *
cc_oci_expand_netdev_cmdline(struct cc_oci_config *config) {

return g_strdup_printf(QEMU_FMT_NETDEV,
config->net.tap_device,
config->net.tap_device);
}

#define QEMU_FMT_DEVICE "driver=virtio-net,netdev=%s"
#define QEMU_FMT_DEVICE_MAC QEMU_FMT_DEVICE ",mac=%s"

static gchar *
cc_oci_expand_net_device_cmdline(struct cc_oci_config *config) {

if ( config->net.mac_address == NULL ) {
return g_strdup_printf(QEMU_FMT_DEVICE,
config->net.tap_device);
} else {
return g_strdup_printf(QEMU_FMT_DEVICE_MAC,
config->net.tap_device,
config->net.mac_address);
}
}


/*!
* Replace any special tokens found in \p args with their expanded
* values.
Expand All @@ -56,7 +113,7 @@ private gchar *defaultsdir = DEFAULTSDIR;
*
* \return \c true on success, else \c false.
*/
private gboolean
gboolean
cc_oci_expand_cmdline (struct cc_oci_config *config,
gchar **args)
{
Expand All @@ -74,6 +131,12 @@ cc_oci_expand_cmdline (struct cc_oci_config *config,
char uuid_str[UUID_MAX] = { 0 };
gint uuid_index = 0;

gchar *kernel_net_params = NULL;
gchar *net_device_params = NULL;
gchar *netdev_params = NULL;
gchar *net_device_option = NULL;
gchar *netdev_option = NULL;

if (! (config && args)) {
return false;
}
Expand Down Expand Up @@ -201,20 +264,47 @@ cc_oci_expand_cmdline (struct cc_oci_config *config,

procsock_device = g_strdup_printf ("socket,id=procsock,path=%s,server,nowait", config->state.procsock_path);

kernel_net_params = cc_oci_expand_net_cmdline(config);

if ( config->net.tap_device == NULL ) {
/* Support --net=none */
/* Hacky, no clean way to add/remove args today
* For multiple network we need to have a way to append
* args to the hypervisor command line vs substitution
*/
netdev_option = g_strdup("-net");
netdev_params = g_strdup("none");
net_device_option = g_strdup("-net");
net_device_params = g_strdup("none");
} else {
netdev_option = g_strdup("-netdev");
net_device_option = g_strdup("-device");
netdev_params = cc_oci_expand_netdev_cmdline(config);
net_device_params = cc_oci_expand_net_device_cmdline(config);
}

/* Note: @NETDEV@: For multiple network we need to have a way to append
* args to the hypervisor command line vs substitution
*/
struct special_tag {
const gchar* name;
const gchar* value;
} special_tags[] = {
{ "@WORKLOAD_DIR@" , config->oci.root.path },
{ "@KERNEL@" , config->vm->kernel_path },
{ "@KERNEL_PARAMS@" , config->vm->kernel_params },
{ "@IMAGE@" , config->vm->image_path },
{ "@SIZE@" , bytes },
{ "@COMMS_SOCKET@" , config->state.comms_path },
{ "@PROCESS_SOCKET@", procsock_device },
{ "@CONSOLE_DEVICE@", console_device },
{ "@NAME@" , g_strrstr(uuid_str, "-")+1 },
{ "@UUID@" , uuid_str },
{ "@WORKLOAD_DIR@" , config->oci.root.path },
{ "@KERNEL@" , config->vm->kernel_path },
{ "@KERNEL_PARAMS@" , config->vm->kernel_params },
{ "@KERNEL_NET_PARAMS@" , kernel_net_params },
{ "@IMAGE@" , config->vm->image_path },
{ "@SIZE@" , bytes },
{ "@COMMS_SOCKET@" , config->state.comms_path },
{ "@PROCESS_SOCKET@" , procsock_device },
{ "@CONSOLE_DEVICE@" , console_device },
{ "@NAME@" , g_strrstr(uuid_str, "-")+1 },
{ "@UUID@" , uuid_str },
{ "@NETDEV@" , netdev_option },
{ "@NETDEV_PARAMS@" , netdev_params },
{ "@NETDEVICE@" , net_device_option },
{ "@NETDEVICE_PARAMS@" , net_device_params },
{ NULL }
};

Expand Down Expand Up @@ -260,6 +350,11 @@ cc_oci_expand_cmdline (struct cc_oci_config *config,
out:
g_free_if_set (bytes);
g_free_if_set (console_device);
g_free_if_set (kernel_net_params);
g_free_if_set (net_device_params);
g_free_if_set (netdev_params);
g_free_if_set (net_device_option);
g_free_if_set (netdev_option);

return ret;
}
Expand Down Expand Up @@ -327,7 +422,7 @@ cc_oci_vm_args_file_path (const struct cc_oci_config *config)
}

/*!
* Generate the list of hypervisor arguments to use.
* Generate the unexpanded list of hypervisor arguments to use.
*
* \param config \ref cc_oci_config.
* \param[out] args Command-line to expand.
Expand Down
2 changes: 2 additions & 0 deletions src/hypervisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@

gboolean cc_oci_vm_args_get (struct cc_oci_config *config,
gchar ***args);
gboolean cc_oci_expand_cmdline (struct cc_oci_config *config,
gchar **args);

#endif /* _CC_OCI_HYPERVISOR_H */
Loading