X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fdpif-linux.c;h=15a21e6688aa636defe7bfd0704d0c35aad4989b;hb=f137ed099e3feaa4a9d8c5dc5f5234945451795e;hp=55d22b40ca4845893c8d2da312b35875359df97c;hpb=d8abf60c72e9a2ec4be5c8a4bf481da9dcde043a;p=openvswitch diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 55d22b40..15a21e66 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -39,15 +39,15 @@ #include "netdev.h" #include "netdev-linux.h" #include "netdev-vport.h" +#include "netlink-notifier.h" #include "netlink-socket.h" #include "netlink.h" #include "odp-util.h" #include "ofpbuf.h" +#include "openvswitch/datapath-compat.h" #include "openvswitch/tunnel.h" #include "packets.h" #include "poll-loop.h" -#include "rtnetlink.h" -#include "rtnetlink-link.h" #include "shash.h" #include "sset.h" #include "unaligned.h" @@ -60,6 +60,10 @@ enum { LRU_MAX_PORTS = 1024 }; enum { LRU_MASK = LRU_MAX_PORTS - 1}; BUILD_ASSERT_DECL(IS_POW2(LRU_MAX_PORTS)); +/* This ethtool flag was introduced in Linux 2.6.24, so it might be + * missing if we have old headers. */ +#define ETH_FLAG_LRO (1 << 15) /* LRO is enabled */ + struct dpif_linux_dp { /* Generic Netlink header. */ uint8_t cmd; @@ -134,7 +138,7 @@ struct dpif_linux { /* Change notification. */ struct sset changed_ports; /* Ports that have changed. */ - struct rtnetlink_notifier port_notifier; + struct nln_notifier *port_notifier; bool change_error; /* Queue of unused ports. */ @@ -154,11 +158,12 @@ static int ovs_packet_family; /* Generic Netlink socket. */ static struct nl_sock *genl_sock; +static struct nln *nln = NULL; static int dpif_linux_init(void); -static int open_dpif(const struct dpif_linux_dp *, struct dpif **); -static void dpif_linux_port_changed(const struct rtnetlink_link_change *, - void *dpif); +static void open_dpif(const struct dpif_linux_dp *, struct dpif **); +static bool dpif_linux_nln_parse(struct ofpbuf *, void *); +static void dpif_linux_port_changed(const void *vport, void *dpif); static void dpif_linux_vport_to_ofpbuf(const struct dpif_linux_vport *, struct ofpbuf *); @@ -239,25 +244,21 @@ dpif_linux_open(const struct dpif_class *class OVS_UNUSED, const char *name, if (error) { return error; } - error = open_dpif(&dp, dpifp); - ofpbuf_delete(buf); - return error; + open_dpif(&dp, dpifp); + ofpbuf_delete(buf); + return 0; } -static int +static void open_dpif(const struct dpif_linux_dp *dp, struct dpif **dpifp) { struct dpif_linux *dpif; - int error; int i; dpif = xmalloc(sizeof *dpif); - error = rtnetlink_link_notifier_register(&dpif->port_notifier, - dpif_linux_port_changed, dpif); - if (error) { - goto error_free; - } + dpif->port_notifier = nln_notifier_create(nln, dpif_linux_port_changed, + dpif); dpif_init(&dpif->dpif, &dpif_linux_class, dp->name, dp->dp_ifindex, dp->dp_ifindex); @@ -278,19 +279,15 @@ open_dpif(const struct dpif_linux_dp *dp, struct dpif **dpifp) for (i = 1; i < LRU_MAX_PORTS; i++) { dpif_linux_push_port(dpif, i); } - return 0; - -error_free: - free(dpif); - return error; } static void dpif_linux_close(struct dpif *dpif_) { struct dpif_linux *dpif = dpif_linux_cast(dpif_); + + nln_notifier_destroy(dpif->port_notifier); nl_sock_destroy(dpif->mc_sock); - rtnetlink_link_notifier_unregister(&dpif->port_notifier); sset_destroy(&dpif->changed_ports); free(dpif->lru_bitmap); free(dpif); @@ -311,13 +308,17 @@ dpif_linux_destroy(struct dpif *dpif_) static void dpif_linux_run(struct dpif *dpif OVS_UNUSED) { - rtnetlink_link_notifier_run(); + if (nln) { + nln_run(nln); + } } static void dpif_linux_wait(struct dpif *dpif OVS_UNUSED) { - rtnetlink_link_notifier_wait(); + if (nln) { + nln_wait(nln); + } } static int @@ -393,6 +394,10 @@ dpif_linux_port_add(struct dpif *dpif_, struct netdev *netdev, request.options_len = options->size; } + if (request.type == OVS_VPORT_TYPE_NETDEV) { + netdev_linux_ethtool_set_flag(netdev, ETH_FLAG_LRO, "LRO", false); + } + /* Loop until we find a port that isn't used. */ do { request.port_no = dpif_linux_pop_port(dpif); @@ -447,12 +452,6 @@ dpif_linux_port_query__(const struct dpif *dpif, uint32_t port_no, dpif_port->name = xstrdup(reply.name); dpif_port->type = xstrdup(netdev_vport_get_netdev_type(&reply)); dpif_port->port_no = reply.port_no; - if (reply.stats) { - netdev_stats_from_rtnl_link_stats64(&dpif_port->stats, - reply.stats); - } else { - memset(&dpif_port->stats, 0xff, sizeof dpif_port->stats); - } ofpbuf_delete(buf); } return error; @@ -548,11 +547,6 @@ dpif_linux_port_dump_next(const struct dpif *dpif OVS_UNUSED, void *state_, dpif_port->name = (char *) vport.name; dpif_port->type = (char *) netdev_vport_get_netdev_type(&vport); dpif_port->port_no = vport.port_no; - if (vport.stats) { - netdev_stats_from_rtnl_link_stats64(&dpif_port->stats, vport.stats); - } else { - memset(&dpif_port->stats, 0xff, sizeof dpif_port->stats); - } return 0; } @@ -1097,6 +1091,8 @@ dpif_linux_init(void) static int error = -1; if (error < 0) { + unsigned int ovs_vport_mcgroup; + error = nl_lookup_genl_family(OVS_DATAPATH_FAMILY, &ovs_datapath_family); if (error) { @@ -1117,6 +1113,16 @@ dpif_linux_init(void) if (!error) { error = nl_sock_create(NETLINK_GENERIC, &genl_sock); } + if (!error) { + error = nl_lookup_genl_mcgroup(OVS_VPORT_FAMILY, OVS_VPORT_MCGROUP, + &ovs_vport_mcgroup, + OVS_VPORT_MCGROUP_FALLBACK_ID); + } + if (!error) { + static struct dpif_linux_vport vport; + nln = nln_create(NETLINK_GENERIC, ovs_vport_mcgroup, + dpif_linux_nln_parse, &vport); + } } return error; @@ -1162,20 +1168,27 @@ dpif_linux_vport_send(int dp_ifindex, uint32_t port_no, actions.data, actions.size, &packet); } +static bool +dpif_linux_nln_parse(struct ofpbuf *buf, void *vport_) +{ + struct dpif_linux_vport *vport = vport_; + return dpif_linux_vport_from_ofpbuf(vport, buf) == 0; +} + static void -dpif_linux_port_changed(const struct rtnetlink_link_change *change, - void *dpif_) +dpif_linux_port_changed(const void *vport_, void *dpif_) { + const struct dpif_linux_vport *vport = vport_; struct dpif_linux *dpif = dpif_; - if (change) { - if (change->master_ifindex == dpif->dp_ifindex - && (change->nlmsg_type == RTM_NEWLINK - || change->nlmsg_type == RTM_DELLINK)) - { - /* Our datapath changed, either adding a new port or deleting an - * existing one. */ - sset_add(&dpif->changed_ports, change->ifname); + if (vport) { + if (vport->dp_ifindex == dpif->dp_ifindex + && (vport->cmd == OVS_VPORT_CMD_NEW + || vport->cmd == OVS_VPORT_CMD_DEL + || vport->cmd == OVS_VPORT_CMD_SET)) { + VLOG_DBG("port_changed: dpif:%s vport:%s cmd:%"PRIu8, + dpif->dpif.full_name, vport->name, vport->cmd); + sset_add(&dpif->changed_ports, vport->name); } } else { dpif->change_error = true; @@ -1197,17 +1210,15 @@ dpif_linux_vport_from_ofpbuf(struct dpif_linux_vport *vport, [OVS_VPORT_ATTR_TYPE] = { .type = NL_A_U32 }, [OVS_VPORT_ATTR_NAME] = { .type = NL_A_STRING, .max_len = IFNAMSIZ }, [OVS_VPORT_ATTR_STATS] = { .type = NL_A_UNSPEC, - .min_len = sizeof(struct rtnl_link_stats64), - .max_len = sizeof(struct rtnl_link_stats64), + .min_len = sizeof(struct ovs_vport_stats), + .max_len = sizeof(struct ovs_vport_stats), .optional = true }, [OVS_VPORT_ATTR_ADDRESS] = { .type = NL_A_UNSPEC, .min_len = ETH_ADDR_LEN, .max_len = ETH_ADDR_LEN, .optional = true }, - [OVS_VPORT_ATTR_MTU] = { .type = NL_A_U32, .optional = true }, [OVS_VPORT_ATTR_OPTIONS] = { .type = NL_A_NESTED, .optional = true }, [OVS_VPORT_ATTR_IFINDEX] = { .type = NL_A_U32, .optional = true }, - [OVS_VPORT_ATTR_IFLINK] = { .type = NL_A_U32, .optional = true }, }; struct nlattr *a[ARRAY_SIZE(ovs_vport_policy)]; @@ -1240,11 +1251,6 @@ dpif_linux_vport_from_ofpbuf(struct dpif_linux_vport *vport, if (a[OVS_VPORT_ATTR_ADDRESS]) { vport->address = nl_attr_get(a[OVS_VPORT_ATTR_ADDRESS]); } - if (a[OVS_VPORT_ATTR_MTU]) { - vport->mtu = nl_attr_get_u32(a[OVS_VPORT_ATTR_MTU]); - } else { - vport->mtu = INT_MAX; - } if (a[OVS_VPORT_ATTR_OPTIONS]) { vport->options = nl_attr_get(a[OVS_VPORT_ATTR_OPTIONS]); vport->options_len = nl_attr_get_size(a[OVS_VPORT_ATTR_OPTIONS]); @@ -1252,9 +1258,6 @@ dpif_linux_vport_from_ofpbuf(struct dpif_linux_vport *vport, if (a[OVS_VPORT_ATTR_IFINDEX]) { vport->ifindex = nl_attr_get_u32(a[OVS_VPORT_ATTR_IFINDEX]); } - if (a[OVS_VPORT_ATTR_IFLINK]) { - vport->iflink = nl_attr_get_u32(a[OVS_VPORT_ATTR_IFLINK]); - } return 0; } @@ -1294,10 +1297,6 @@ dpif_linux_vport_to_ofpbuf(const struct dpif_linux_vport *vport, vport->address, ETH_ADDR_LEN); } - if (vport->mtu && vport->mtu != INT_MAX) { - nl_msg_put_u32(buf, OVS_VPORT_ATTR_MTU, vport->mtu); - } - if (vport->options) { nl_msg_put_nested(buf, OVS_VPORT_ATTR_OPTIONS, vport->options, vport->options_len); @@ -1306,10 +1305,6 @@ dpif_linux_vport_to_ofpbuf(const struct dpif_linux_vport *vport, if (vport->ifindex) { nl_msg_put_u32(buf, OVS_VPORT_ATTR_IFINDEX, vport->ifindex); } - - if (vport->iflink) { - nl_msg_put_u32(buf, OVS_VPORT_ATTR_IFLINK, vport->iflink); - } } /* Clears 'vport' to "empty" values. */