summaryrefslogtreecommitdiff
path: root/net/net.c
diff options
context:
space:
mode:
authorSeokYeon Hwang <syeon.hwang@samsung.com>2016-06-20 15:25:33 +0900
committerSeokYeon Hwang <syeon.hwang@samsung.com>2016-06-20 15:25:33 +0900
commitb5b5a72b01ac12c4dfb5867deb00c7b39f4fece5 (patch)
treef28c18fd9706691e01dfbb9dd4d5b91b02bb78dd /net/net.c
parent00b7f2169caa54deb7f2e9d64908e7c6d2ff9d8e (diff)
parentbfc766d38e1fae5767d43845c15c79ac8fa6d6af (diff)
downloadqemu-b5b5a72b01ac12c4dfb5867deb00c7b39f4fece5.tar.gz
qemu-b5b5a72b01ac12c4dfb5867deb00c7b39f4fece5.tar.bz2
qemu-b5b5a72b01ac12c4dfb5867deb00c7b39f4fece5.zip
Merge tag 'v2.6.0' into develop
v2.6.0 release Change-Id: I76aaeae2ace35ddf6dbbd4c11436724688b01929 Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c166
1 files changed, 101 insertions, 65 deletions
diff --git a/net/net.c b/net/net.c
index 9f7c9e467c..5703d24fe6 100644
--- a/net/net.c
+++ b/net/net.c
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-#include "config-host.h"
+#include "qemu/osdep.h"
#include "net/net.h"
#include "clients.h"
@@ -32,9 +32,11 @@
#include "monitor/monitor.h"
#include "qemu-common.h"
+#include "qemu/help_option.h"
#include "qapi/qmp/qerror.h"
#include "qemu/error-report.h"
#include "qemu/sockets.h"
+#include "qemu/cutils.h"
#include "qemu/config-file.h"
#include "qmp-commands.h"
#include "hw/qdev.h"
@@ -42,9 +44,9 @@
#include "qemu/main-loop.h"
#include "qapi-visit.h"
#include "qapi/opts-visitor.h"
-#include "qapi/dealloc-visitor.h"
#include "sysemu/sysemu.h"
#include "net/filter.h"
+#include "qapi/string-output-visitor.h"
/* Net bridge is currently not supported for W32. */
#if !defined(_WIN32)
@@ -79,34 +81,6 @@ int default_net = 1;
/***********************************************************/
/* network device redirectors */
-#if defined(DEBUG_NET)
-static void hex_dump(FILE *f, const uint8_t *buf, int size)
-{
- int len, i, j, c;
-
- for(i=0;i<size;i+=16) {
- len = size - i;
- if (len > 16)
- len = 16;
- fprintf(f, "%08x ", i);
- for(j=0;j<16;j++) {
- if (j < len)
- fprintf(f, " %02x", buf[i+j]);
- else
- fprintf(f, " ");
- }
- fprintf(f, " ");
- for(j=0;j<len;j++) {
- c = buf[i+j];
- if (c < ' ' || c > '~')
- c = '.';
- fprintf(f, "%c", c);
- }
- fprintf(f, "\n");
- }
-}
-#endif
-
static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
{
const char *p, *p1;
@@ -580,11 +554,21 @@ static ssize_t filter_receive_iov(NetClientState *nc,
ssize_t ret = 0;
NetFilterState *nf = NULL;
- QTAILQ_FOREACH(nf, &nc->filters, next) {
- ret = qemu_netfilter_receive(nf, direction, sender, flags, iov,
- iovcnt, sent_cb);
- if (ret) {
- return ret;
+ if (direction == NET_FILTER_DIRECTION_TX) {
+ QTAILQ_FOREACH(nf, &nc->filters, next) {
+ ret = qemu_netfilter_receive(nf, direction, sender, flags, iov,
+ iovcnt, sent_cb);
+ if (ret) {
+ return ret;
+ }
+ }
+ } else {
+ QTAILQ_FOREACH_REVERSE(nf, &nc->filters, NetFilterHead, next) {
+ ret = qemu_netfilter_receive(nf, direction, sender, flags, iov,
+ iovcnt, sent_cb);
+ if (ret) {
+ return ret;
+ }
}
}
@@ -652,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
#ifdef DEBUG_NET
printf("qemu_send_packet_async:\n");
- hex_dump(stdout, buf, size);
+ qemu_hexdump((const char *)buf, stdout, "net", size);
#endif
if (sender->link_down || !sender->peer) {
@@ -699,23 +683,28 @@ ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
static ssize_t nc_sendv_compat(NetClientState *nc, const struct iovec *iov,
int iovcnt, unsigned flags)
{
- uint8_t buf[NET_BUFSIZE];
+ uint8_t *buf = NULL;
uint8_t *buffer;
size_t offset;
+ ssize_t ret;
if (iovcnt == 1) {
buffer = iov[0].iov_base;
offset = iov[0].iov_len;
} else {
+ buf = g_new(uint8_t, NET_BUFSIZE);
buffer = buf;
- offset = iov_to_buf(iov, iovcnt, 0, buf, sizeof(buf));
+ offset = iov_to_buf(iov, iovcnt, 0, buf, NET_BUFSIZE);
}
if (flags & QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) {
- return nc->info->receive_raw(nc, buffer, offset);
+ ret = nc->info->receive_raw(nc, buffer, offset);
} else {
- return nc->info->receive(nc, buffer, offset);
+ ret = nc->info->receive(nc, buffer, offset);
}
+
+ g_free(buf);
+ return ret;
}
ssize_t qemu_deliver_packet_iov(NetClientState *sender,
@@ -883,7 +872,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
const NetLegacyNicOptions *nic;
assert(opts->type == NET_CLIENT_OPTIONS_KIND_NIC);
- nic = opts->u.nic;
+ nic = opts->u.nic.data;
idx = nic_get_free_idx();
if (idx == -1 || nb_nics >= MAX_NICS) {
@@ -943,7 +932,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
}
-static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
+static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND__MAX])(
const NetClientOptions *opts,
const char *name,
NetClientState *peer, Error **errp) = {
@@ -1015,7 +1004,7 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
/* Do not add to a vlan if it's a nic with a netdev= parameter. */
if (opts->type != NET_CLIENT_OPTIONS_KIND_NIC ||
- !opts->u.nic->has_netdev) {
+ !opts->u.nic.data->has_netdev) {
peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL);
}
}
@@ -1032,41 +1021,63 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
}
-static void net_visit(Visitor *v, int is_netdev, void **object, Error **errp)
-{
- if (is_netdev) {
- visit_type_Netdev(v, (Netdev **)object, NULL, errp);
- } else {
- visit_type_NetLegacy(v, (NetLegacy **)object, NULL, errp);
- }
-}
-
-
int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
{
void *object = NULL;
Error *err = NULL;
int ret = -1;
+ OptsVisitor *ov = opts_visitor_new(opts);
+ Visitor *v = opts_get_visitor(ov);
{
- OptsVisitor *ov = opts_visitor_new(opts);
+ /* Parse convenience option format ip6-net=fec0::0[/64] */
+ const char *ip6_net = qemu_opt_get(opts, "ipv6-net");
- net_visit(opts_get_visitor(ov), is_netdev, &object, &err);
- opts_visitor_cleanup(ov);
+ if (ip6_net) {
+ char buf[strlen(ip6_net) + 1];
+
+ if (get_str_sep(buf, sizeof(buf), &ip6_net, '/') < 0) {
+ /* Default 64bit prefix length. */
+ qemu_opt_set(opts, "ipv6-prefix", ip6_net, &error_abort);
+ qemu_opt_set_number(opts, "ipv6-prefixlen", 64, &error_abort);
+ } else {
+ /* User-specified prefix length. */
+ unsigned long len;
+ int err;
+
+ qemu_opt_set(opts, "ipv6-prefix", buf, &error_abort);
+ err = qemu_strtoul(ip6_net, NULL, 10, &len);
+
+ if (err) {
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+ "ipv6-prefix", "a number");
+ } else {
+ qemu_opt_set_number(opts, "ipv6-prefixlen", len,
+ &error_abort);
+ }
+ }
+ qemu_opt_unset(opts, "ipv6-net");
+ }
+ }
+
+ if (is_netdev) {
+ visit_type_Netdev(v, NULL, (Netdev **)&object, &err);
+ } else {
+ visit_type_NetLegacy(v, NULL, (NetLegacy **)&object, &err);
}
if (!err) {
ret = net_client_init1(object, is_netdev, &err);
}
- if (object) {
- QapiDeallocVisitor *dv = qapi_dealloc_visitor_new();
-
- net_visit(qapi_dealloc_get_visitor(dv), is_netdev, &object, NULL);
- qapi_dealloc_visitor_cleanup(dv);
+ if (is_netdev) {
+ qapi_free_Netdev(object);
+ } else {
+ qapi_free_NetLegacy(object);
}
error_propagate(errp, err);
+ opts_visitor_cleanup(ov);
return ret;
}
@@ -1185,6 +1196,30 @@ void qmp_netdev_del(const char *id, Error **errp)
qemu_opts_del(opts);
}
+static void netfilter_print_info(Monitor *mon, NetFilterState *nf)
+{
+ char *str;
+ ObjectProperty *prop;
+ ObjectPropertyIterator iter;
+ StringOutputVisitor *ov;
+
+ /* generate info str */
+ object_property_iter_init(&iter, OBJECT(nf));
+ while ((prop = object_property_iter_next(&iter))) {
+ if (!strcmp(prop->name, "type")) {
+ continue;
+ }
+ ov = string_output_visitor_new(false);
+ object_property_get(OBJECT(nf), string_output_get_visitor(ov),
+ prop->name, NULL);
+ str = string_output_get_string(ov);
+ string_output_visitor_cleanup(ov);
+ monitor_printf(mon, ",%s=%s", prop->name, str);
+ g_free(str);
+ }
+ monitor_printf(mon, "\n");
+}
+
void print_net_client(Monitor *mon, NetClientState *nc)
{
NetFilterState *nf;
@@ -1198,9 +1233,10 @@ void print_net_client(Monitor *mon, NetClientState *nc)
}
QTAILQ_FOREACH(nf, &nc->filters, next) {
char *path = object_get_canonical_path_component(OBJECT(nf));
- monitor_printf(mon, " - %s: type=%s%s\n", path,
- object_get_typename(OBJECT(nf)),
- nf->info_str);
+
+ monitor_printf(mon, " - %s: type=%s", path,
+ object_get_typename(OBJECT(nf)));
+ netfilter_print_info(mon, nf);
g_free(path);
}
}
@@ -1296,7 +1332,7 @@ void qmp_set_link(const char *name, bool up, Error **errp)
int queues, i;
queues = qemu_find_net_clients_except(name, ncs,
- NET_CLIENT_OPTIONS_KIND_MAX,
+ NET_CLIENT_OPTIONS_KIND__MAX,
MAX_QUEUE_NUM);
if (queues == 0) {