X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=vswitchd%2Fovs-brcompatd.c;h=df9332f3aaf38bc6e73b4f293392b4eed93864c2;hb=2702241699d0539d6ff4a2d44c5bc0ab9d7f7fc8;hp=4f35452156d9374fbf58c7d1c60c97cc89dde466;hpb=2b01925c18a52b2f7dbff5c70269a4b4d8aec027;p=openvswitch diff --git a/vswitchd/ovs-brcompatd.c b/vswitchd/ovs-brcompatd.c index 4f354521..df9332f3 100644 --- a/vswitchd/ovs-brcompatd.c +++ b/vswitchd/ovs-brcompatd.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks +/* Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -43,13 +44,13 @@ #include "leak-checker.h" #include "netdev.h" #include "netlink.h" +#include "netlink-notifier.h" #include "netlink-socket.h" #include "ofpbuf.h" #include "openvswitch/brcompat-netlink.h" #include "packets.h" #include "poll-loop.h" #include "process.h" -#include "rtnetlink.h" #include "rtnetlink-link.h" #include "signals.h" #include "sset.h" @@ -75,7 +76,7 @@ static char *appctl_program; static char *vsctl_program; /* Options that we should generally pass to ovs-vsctl. */ -#define VSCTL_OPTIONS "--timeout=5", "-vANY:console:WARN" +#define VSCTL_OPTIONS "--timeout=5", "-vconsole:warn" /* Netlink socket to bridge compatibility kernel module. */ static struct nl_sock *brc_sock; @@ -279,25 +280,25 @@ parse_command(struct ofpbuf *buffer, uint32_t *seq, const char **br_name, return 0; } -/* Composes and returns a reply to a request made by the datapath with Netlink - * sequence number 'seq' and error code 'error'. The caller may add additional - * attributes to the message, then it may send it with send_reply(). */ +/* Composes and returns a reply to a request made by the datapath with error + * code 'error'. The caller may add additional attributes to the message, then + * it may send it with send_reply(). */ static struct ofpbuf * -compose_reply(uint32_t seq, int error) +compose_reply(int error) { struct ofpbuf *reply = ofpbuf_new(4096); nl_msg_put_genlmsghdr(reply, 32, brc_family, NLM_F_REQUEST, BRC_GENL_C_DP_RESULT, 1); - ((struct nlmsghdr *) reply->data)->nlmsg_seq = seq; nl_msg_put_u32(reply, BRC_GENL_A_ERR_CODE, error); return reply; } -/* Sends 'reply' to the datapath and frees it. */ +/* Sends 'reply' to the datapath, using sequence number 'nlmsg_seq', and frees + * it. */ static void -send_reply(struct ofpbuf *reply) +send_reply(struct ofpbuf *reply, uint32_t nlmsg_seq) { - int retval = nl_sock_send(brc_sock, reply, false); + int retval = nl_sock_send_seq(brc_sock, reply, nlmsg_seq, false); if (retval) { VLOG_WARN_RL(&rl, "replying to brcompat request: %s", strerror(retval)); @@ -310,7 +311,7 @@ send_reply(struct ofpbuf *reply) static void send_simple_reply(uint32_t seq, int error) { - send_reply(compose_reply(seq, error)); + send_reply(compose_reply(error), seq); } static int @@ -363,25 +364,29 @@ handle_port_cmd(struct ofpbuf *buffer, bool add) } static char * -linux_bridge_to_ovs_bridge(const char *linux_name) +linux_bridge_to_ovs_bridge(const char *linux_name, int *br_vlanp) { char *save_ptr = NULL; - const char *br_name; + const char *br_name, *br_vlan; char *br_name_copy; char *output; - output = capture_vsctl(vsctl_program, VSCTL_OPTIONS, "br-to-parent", - linux_name, (char *) NULL); + output = capture_vsctl(vsctl_program, VSCTL_OPTIONS, + "--", "br-to-parent", linux_name, + "--", "br-to-vlan", linux_name, + (char *) NULL); if (!output) { return NULL; } br_name = strtok_r(output, " \t\r\n", &save_ptr); - if (!br_name) { + br_vlan = strtok_r(NULL, " \t\r\n", &save_ptr); + if (!br_name || !br_vlan) { free(output); return NULL; } br_name_copy = xstrdup(br_name); + *br_vlanp = atoi(br_vlan); free(output); @@ -451,14 +456,14 @@ handle_fdb_query_cmd(struct ofpbuf *buffer) uint32_t seq; int error; - /* Parse the command received from brcompat_mod. */ + /* Parse the command received from brcompat. */ error = parse_command(buffer, &seq, &linux_name, NULL, &count, &skip); if (error) { return error; } /* Figure out vswitchd bridge and VLAN. */ - br_name = linux_bridge_to_ovs_bridge(linux_name); + br_name = linux_bridge_to_ovs_bridge(linux_name, &br_vlan); if (!br_name) { error = EINVAL; send_simple_reply(seq, error); @@ -484,7 +489,7 @@ handle_fdb_query_cmd(struct ofpbuf *buffer) struct mac *mac = &local_macs[n_local_macs]; struct netdev *netdev; - error = netdev_open_default(iface_name, &netdev); + error = netdev_open(iface_name, "system", &netdev); if (!error) { if (!netdev_get_etheraddr(netdev, mac->addr)) { n_local_macs++; @@ -550,10 +555,10 @@ handle_fdb_query_cmd(struct ofpbuf *buffer) free(output); /* Compose and send reply to datapath. */ - reply = compose_reply(seq, 0); + reply = compose_reply(0); nl_msg_put_unspec(reply, BRC_GENL_A_FDB_DATA, query_data.data, query_data.size); - send_reply(reply); + send_reply(reply, seq); /* Free memory. */ ofpbuf_uninit(&query_data); @@ -589,10 +594,10 @@ send_ifindex_reply(uint32_t seq, char *output) } /* Compose and send reply. */ - reply = compose_reply(seq, 0); + reply = compose_reply(0); nl_msg_put_unspec(reply, BRC_GENL_A_IFINDEXES, indices, n_indices * sizeof *indices); - send_reply(reply); + send_reply(reply, seq); /* Free memory. */ free(indices); @@ -649,56 +654,53 @@ handle_get_ports_cmd(struct ofpbuf *buffer) return 0; } -static struct ofpbuf * -brc_recv_update__(void) +static bool +brc_recv_update__(struct ofpbuf *buffer) { for (;;) { - struct ofpbuf *buffer; - int retval; - - retval = nl_sock_recv(brc_sock, &buffer, false); + int retval = nl_sock_recv(brc_sock, buffer, false); switch (retval) { case 0: if (nl_msg_nlmsgerr(buffer, NULL) || nl_msg_nlmsghdr(buffer)->nlmsg_type == NLMSG_DONE) { break; } - return buffer; + return true; case ENOBUFS: break; case EAGAIN: - return NULL; + return false; default: VLOG_WARN_RL(&rl, "brc_recv_update: %s", strerror(retval)); - return NULL; + return false; } - ofpbuf_delete(buffer); } } static void brc_recv_update(void) { - struct ofpbuf *buffer; struct genlmsghdr *genlmsghdr; + uint64_t buffer_stub[1024 / 8]; + struct ofpbuf buffer; - buffer = brc_recv_update__(); - if (!buffer) { - return; + ofpbuf_use_stub(&buffer, buffer_stub, sizeof buffer_stub); + if (!brc_recv_update__(&buffer)) { + goto error; } - genlmsghdr = nl_msg_genlmsghdr(buffer); + genlmsghdr = nl_msg_genlmsghdr(&buffer); if (!genlmsghdr) { VLOG_WARN_RL(&rl, "received packet too short for generic NetLink"); goto error; } - if (nl_msg_nlmsghdr(buffer)->nlmsg_type != brc_family) { + if (nl_msg_nlmsghdr(&buffer)->nlmsg_type != brc_family) { VLOG_DBG_RL(&rl, "received type (%"PRIu16") != brcompat family (%d)", - nl_msg_nlmsghdr(buffer)->nlmsg_type, brc_family); + nl_msg_nlmsghdr(&buffer)->nlmsg_type, brc_family); goto error; } @@ -720,35 +722,35 @@ brc_recv_update(void) * (XenServer Tools 5.5.0 does not exhibit this behavior, and neither does * a VM without Tools installed at all.) */ - rtnetlink_link_notifier_run(); + rtnetlink_link_run(); switch (genlmsghdr->cmd) { case BRC_GENL_C_DP_ADD: - handle_bridge_cmd(buffer, true); + handle_bridge_cmd(&buffer, true); break; case BRC_GENL_C_DP_DEL: - handle_bridge_cmd(buffer, false); + handle_bridge_cmd(&buffer, false); break; case BRC_GENL_C_PORT_ADD: - handle_port_cmd(buffer, true); + handle_port_cmd(&buffer, true); break; case BRC_GENL_C_PORT_DEL: - handle_port_cmd(buffer, false); + handle_port_cmd(&buffer, false); break; case BRC_GENL_C_FDB_QUERY: - handle_fdb_query_cmd(buffer); + handle_fdb_query_cmd(&buffer); break; case BRC_GENL_C_GET_BRIDGES: - handle_get_bridges_cmd(buffer); + handle_get_bridges_cmd(&buffer); break; case BRC_GENL_C_GET_PORTS: - handle_get_ports_cmd(buffer); + handle_get_ports_cmd(&buffer); break; default: @@ -758,7 +760,7 @@ brc_recv_update(void) } error: - ofpbuf_delete(buffer); + ofpbuf_uninit(&buffer); } static void @@ -786,7 +788,7 @@ netdev_changed_cb(const struct rtnetlink_link_change *change, port_name, br_name); run_vsctl(vsctl_program, VSCTL_OPTIONS, - "--", "--if-exists", "del-port", br_name, port_name, + "--", "--if-exists", "del-port", port_name, "--", "comment", "ovs-brcompatd:", port_name, "disappeared", (char *) NULL); } @@ -795,7 +797,7 @@ int main(int argc, char *argv[]) { extern struct vlog_module VLM_reconnect; - struct rtnetlink_notifier link_notifier; + struct nln_notifier *link_notifier; struct unixctl_server *unixctl; int retval; @@ -819,26 +821,25 @@ main(int argc, char *argv[]) "\"brcompat\" kernel module."); } - - rtnetlink_link_notifier_register(&link_notifier, netdev_changed_cb, NULL); + link_notifier = rtnetlink_link_notifier_create(netdev_changed_cb, NULL); daemonize_complete(); for (;;) { unixctl_server_run(unixctl); - rtnetlink_link_notifier_run(); + rtnetlink_link_run(); brc_recv_update(); netdev_run(); nl_sock_wait(brc_sock, POLLIN); unixctl_server_wait(unixctl); - rtnetlink_link_notifier_wait(); + rtnetlink_link_wait(); netdev_wait(); poll_block(); } - rtnetlink_link_notifier_unregister(&link_notifier); + rtnetlink_link_notifier_destroy(link_notifier); return 0; } @@ -876,12 +877,11 @@ parse_options(int argc, char *argv[]) } switch (c) { - case 'H': case 'h': usage(); case 'V': - OVS_PRINT_VERSION(0, 0); + ovs_print_version(0, 0); exit(EXIT_SUCCESS); case OPT_APPCTL: