X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fnetdev-dummy.c;h=083a4ddb518e26822d7f238cea1bf1b73202e605;hb=2b459b83afe20f644f801dbdeafb750c7dade5d1;hp=94dea765ef490c07e7275bb7a0486154b3ae67c0;hpb=fbac791aea04553de6efa02e78a9724d85cccb88;p=openvswitch diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c index 94dea765..083a4ddb 100644 --- a/lib/netdev-dummy.c +++ b/lib/netdev-dummy.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011 Nicira Networks. + * Copyright (c) 2010, 2011, 2012 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ #include "packets.h" #include "poll-loop.h" #include "shash.h" +#include "sset.h" #include "unixctl.h" #include "vlog.h" @@ -156,6 +157,7 @@ netdev_dummy_recv(struct netdev *netdev_, void *buffer, size_t size) { struct netdev_dummy *netdev = netdev_dummy_cast(netdev_); struct ofpbuf *packet; + size_t packet_size; if (list_is_empty(&netdev->recv_queue)) { return -EAGAIN; @@ -165,11 +167,12 @@ netdev_dummy_recv(struct netdev *netdev_, void *buffer, size_t size) if (packet->size > size) { return -EMSGSIZE; } + packet_size = packet->size; memcpy(buffer, packet->data, packet->size); ofpbuf_delete(packet); - return packet->size; + return packet_size; } static void @@ -349,7 +352,7 @@ static const struct netdev_class dummy_class = { NULL, /* get_in6 */ NULL, /* add_router */ NULL, /* get_next_hop */ - NULL, /* get_status */ + NULL, /* get_drv_info */ NULL, /* arp_lookup */ netdev_dummy_update_flags, @@ -407,7 +410,7 @@ netdev_dummy_receive(struct unixctl_conn *conn, dummy_dev = shash_find_data(&dummy_netdev_devs, argv[1]); if (!dummy_dev) { - unixctl_command_reply(conn, 501, "no such dummy netdev"); + unixctl_command_reply_error(conn, "no such dummy netdev"); return; } @@ -418,7 +421,7 @@ netdev_dummy_receive(struct unixctl_conn *conn, packet = eth_from_packet_or_flow(argv[i]); if (!packet) { - unixctl_command_reply(conn, 501, "bad packet syntax"); + unixctl_command_reply_error(conn, "bad packet syntax"); return; } @@ -434,16 +437,35 @@ netdev_dummy_receive(struct unixctl_conn *conn, } if (!n_listeners) { - unixctl_command_reply(conn, 202, "packets queued but nobody listened"); + unixctl_command_reply(conn, "packets queued but nobody listened"); } else { - unixctl_command_reply(conn, 200, "success"); + unixctl_command_reply(conn, "success"); } } void -netdev_dummy_register(void) +netdev_dummy_register(bool override) { - netdev_register_provider(&dummy_class); unixctl_command_register("netdev-dummy/receive", "NAME PACKET|FLOW...", 2, INT_MAX, netdev_dummy_receive, NULL); + + if (override) { + struct sset types; + const char *type; + + sset_init(&types); + netdev_enumerate_types(&types); + SSET_FOR_EACH (type, &types) { + if (!netdev_unregister_provider(type)) { + struct netdev_class *class; + + class = xmalloc(sizeof *class); + *class = dummy_class; + class->type = xstrdup(type); + netdev_register_provider(class); + } + } + sset_destroy(&types); + } + netdev_register_provider(&dummy_class); }