2 * Copyright (c) 2010, 2011, 2012, 2013 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "netdev-vport.h"
23 #include <sys/socket.h>
24 #include <linux/openvswitch.h>
25 #include <linux/rtnetlink.h>
27 #include <sys/ioctl.h>
29 #include "byte-order.h"
33 #include "dpif-linux.h"
37 #include "netdev-linux.h"
38 #include "netdev-provider.h"
40 #include "netlink-notifier.h"
41 #include "netlink-socket.h"
43 #include "openvswitch/tunnel.h"
45 #include "route-table.h"
47 #include "socket-util.h"
48 #include "unaligned.h"
51 VLOG_DEFINE_THIS_MODULE(netdev_vport);
53 /* Default to the OTV port, per the VXLAN IETF draft. */
54 #define VXLAN_DST_PORT 8472
56 #define DEFAULT_TTL 64
58 struct netdev_dev_vport {
59 struct netdev_dev netdev_dev;
60 unsigned int change_seq;
61 uint8_t etheraddr[ETH_ADDR_LEN];
64 struct ofpbuf *options;
65 struct netdev_tunnel_config tnl_cfg;
68 struct netdev_stats stats;
73 enum ovs_vport_type type;
74 struct netdev_class netdev_class;
77 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
79 static int netdev_vport_create(const struct netdev_class *, const char *,
80 struct netdev_dev **);
81 static void netdev_vport_poll_notify(const struct netdev *);
82 static int tnl_port_config_from_nlattr(const struct nlattr *options,
84 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1]);
87 is_vport_class(const struct netdev_class *class)
89 return class->create == netdev_vport_create;
92 static const struct vport_class *
93 vport_class_cast(const struct netdev_class *class)
95 ovs_assert(is_vport_class(class));
96 return CONTAINER_OF(class, struct vport_class, netdev_class);
99 static struct netdev_dev_vport *
100 netdev_dev_vport_cast(const struct netdev_dev *netdev_dev)
102 ovs_assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
103 return CONTAINER_OF(netdev_dev, struct netdev_dev_vport, netdev_dev);
106 static struct netdev_dev_vport *
107 netdev_vport_get_dev(const struct netdev *netdev)
109 return netdev_dev_vport_cast(netdev_get_dev(netdev));
112 static const struct netdev_tunnel_config *
113 get_netdev_tunnel_config(const struct netdev_dev *netdev_dev)
115 return &netdev_dev_vport_cast(netdev_dev)->tnl_cfg;
118 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
119 * options to include in OVS_VPORT_ATTR_OPTIONS for configuring that vport.
120 * Otherwise returns NULL. */
121 const struct ofpbuf *
122 netdev_vport_get_options(const struct netdev *netdev)
124 const struct netdev_dev *dev = netdev_get_dev(netdev);
126 return (is_vport_class(netdev_dev_get_class(dev))
127 ? netdev_dev_vport_cast(dev)->options
132 netdev_vport_get_vport_type(const struct netdev *netdev)
134 const struct netdev_dev *dev = netdev_get_dev(netdev);
135 const struct netdev_class *class = netdev_dev_get_class(dev);
137 return (is_vport_class(class) ? vport_class_cast(class)->type
138 : class == &netdev_internal_class ? OVS_VPORT_TYPE_INTERNAL
139 : (class == &netdev_linux_class ||
140 class == &netdev_tap_class) ? OVS_VPORT_TYPE_NETDEV
141 : OVS_VPORT_TYPE_UNSPEC);
145 netdev_vport_is_patch(const struct netdev *netdev)
147 return netdev_vport_get_vport_type(netdev) == OVS_VPORT_TYPE_PATCH;
151 get_u32_or_zero(const struct nlattr *a)
153 return a ? nl_attr_get_u32(a) : 0;
157 netdev_vport_get_netdev_type(const struct dpif_linux_vport *vport)
159 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
161 switch (vport->type) {
162 case OVS_VPORT_TYPE_UNSPEC:
165 case OVS_VPORT_TYPE_NETDEV:
168 case OVS_VPORT_TYPE_INTERNAL:
171 case OVS_VPORT_TYPE_PATCH:
174 case OVS_VPORT_TYPE_GRE:
175 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
179 return (get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
180 ? "ipsec_gre" : "gre");
182 case OVS_VPORT_TYPE_GRE64:
183 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
187 return (get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
188 ? "ipsec_gre64" : "gre64");
190 case OVS_VPORT_TYPE_CAPWAP:
193 case OVS_VPORT_TYPE_VXLAN:
196 case __OVS_VPORT_TYPE_MAX:
200 VLOG_WARN_RL(&rl, "dp%d: port `%s' has unsupported type %u",
201 vport->dp_ifindex, vport->name, (unsigned int) vport->type);
206 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
207 struct netdev_dev **netdev_devp)
209 struct netdev_dev_vport *dev;
211 dev = xzalloc(sizeof *dev);
212 netdev_dev_init(&dev->netdev_dev, name, netdev_class);
214 eth_addr_random(dev->etheraddr);
216 *netdev_devp = &dev->netdev_dev;
217 route_table_register();
223 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
225 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
227 ofpbuf_delete(netdev_dev->options);
228 route_table_unregister();
229 free(netdev_dev->peer);
234 netdev_vport_open(struct netdev_dev *netdev_dev, struct netdev **netdevp)
236 *netdevp = xmalloc(sizeof **netdevp);
237 netdev_init(*netdevp, netdev_dev);
242 netdev_vport_close(struct netdev *netdev)
248 netdev_vport_set_etheraddr(struct netdev *netdev,
249 const uint8_t mac[ETH_ADDR_LEN])
251 memcpy(netdev_vport_get_dev(netdev)->etheraddr, mac, ETH_ADDR_LEN);
252 netdev_vport_poll_notify(netdev);
257 netdev_vport_get_etheraddr(const struct netdev *netdev,
258 uint8_t mac[ETH_ADDR_LEN])
260 memcpy(mac, netdev_vport_get_dev(netdev)->etheraddr, ETH_ADDR_LEN);
264 /* Copies 'src' into 'dst', performing format conversion in the process.
266 * 'src' is allowed to be misaligned. */
268 netdev_stats_from_ovs_vport_stats(struct netdev_stats *dst,
269 const struct ovs_vport_stats *src)
271 dst->rx_packets = get_unaligned_u64(&src->rx_packets);
272 dst->tx_packets = get_unaligned_u64(&src->tx_packets);
273 dst->rx_bytes = get_unaligned_u64(&src->rx_bytes);
274 dst->tx_bytes = get_unaligned_u64(&src->tx_bytes);
275 dst->rx_errors = get_unaligned_u64(&src->rx_errors);
276 dst->tx_errors = get_unaligned_u64(&src->tx_errors);
277 dst->rx_dropped = get_unaligned_u64(&src->rx_dropped);
278 dst->tx_dropped = get_unaligned_u64(&src->tx_dropped);
281 dst->rx_length_errors = 0;
282 dst->rx_over_errors = 0;
283 dst->rx_crc_errors = 0;
284 dst->rx_frame_errors = 0;
285 dst->rx_fifo_errors = 0;
286 dst->rx_missed_errors = 0;
287 dst->tx_aborted_errors = 0;
288 dst->tx_carrier_errors = 0;
289 dst->tx_fifo_errors = 0;
290 dst->tx_heartbeat_errors = 0;
291 dst->tx_window_errors = 0;
295 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
297 struct dpif_linux_vport reply;
301 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
304 } else if (!reply.stats) {
309 netdev_stats_from_ovs_vport_stats(stats, reply.stats);
317 tunnel_get_status(const struct netdev *netdev, struct smap *smap)
319 static char iface[IFNAMSIZ];
322 route = netdev_vport_get_dev(netdev)->tnl_cfg.ip_dst;
323 if (route_table_get_name(route, iface)) {
324 struct netdev *egress_netdev;
326 smap_add(smap, "tunnel_egress_iface", iface);
328 if (!netdev_open(iface, "system", &egress_netdev)) {
329 smap_add(smap, "tunnel_egress_iface_carrier",
330 netdev_get_carrier(egress_netdev) ? "up" : "down");
331 netdev_close(egress_netdev);
339 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
340 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
341 enum netdev_flags *old_flagsp)
343 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
347 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
352 netdev_vport_change_seq(const struct netdev *netdev)
354 return netdev_vport_get_dev(netdev)->change_seq;
358 netdev_vport_run(void)
364 netdev_vport_wait(void)
369 /* Helper functions. */
372 netdev_vport_poll_notify(const struct netdev *netdev)
374 struct netdev_dev_vport *ndv = netdev_vport_get_dev(netdev);
377 if (!ndv->change_seq) {
382 /* Code specific to tunnel types. */
385 parse_key(const struct smap *args, const char *name,
386 bool *present, bool *flow)
393 s = smap_get(args, name);
395 s = smap_get(args, "key");
403 if (!strcmp(s, "flow")) {
407 return htonll(strtoull(s, NULL, 0));
412 set_tunnel_config(struct netdev_dev *dev_, const struct smap *args)
414 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
415 const char *name = netdev_dev_get_name(dev_);
416 const char *type = netdev_dev_get_type(dev_);
417 bool ipsec_mech_set, needs_dst_port, has_csum;
418 struct netdev_tunnel_config tnl_cfg;
419 struct smap_node *node;
420 struct ofpbuf *options;
424 flags = TNL_F_DF_DEFAULT;
425 has_csum = strstr(type, "gre");
426 ipsec_mech_set = false;
427 memset(&tnl_cfg, 0, sizeof tnl_cfg);
429 options = ofpbuf_new(64);
431 if (!strcmp(type, "capwap")) {
432 VLOG_WARN_ONCE("CAPWAP tunnel support is deprecated.");
435 needs_dst_port = !strcmp(type, "vxlan");
436 tnl_cfg.ipsec = strstr(type, "ipsec");
438 flags |= TNL_F_IPSEC;
440 tnl_cfg.dont_fragment = true;
442 SMAP_FOR_EACH (node, args) {
443 if (!strcmp(node->key, "remote_ip")) {
444 struct in_addr in_addr;
445 if (lookup_ip(node->value, &in_addr)) {
446 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
448 tnl_cfg.ip_dst = in_addr.s_addr;
450 } else if (!strcmp(node->key, "local_ip")) {
451 struct in_addr in_addr;
452 if (lookup_ip(node->value, &in_addr)) {
453 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
455 tnl_cfg.ip_src = in_addr.s_addr;
457 } else if (!strcmp(node->key, "tos")) {
458 if (!strcmp(node->value, "inherit")) {
459 flags |= TNL_F_TOS_INHERIT;
460 tnl_cfg.tos_inherit = true;
464 tos = strtol(node->value, &endptr, 0);
465 if (*endptr == '\0' && tos == (tos & IP_DSCP_MASK)) {
466 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TOS, tos);
469 VLOG_WARN("%s: invalid TOS %s", name, node->value);
472 } else if (!strcmp(node->key, "ttl")) {
473 if (!strcmp(node->value, "inherit")) {
474 flags |= TNL_F_TTL_INHERIT;
475 tnl_cfg.ttl_inherit = true;
477 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TTL, atoi(node->value));
478 tnl_cfg.ttl = atoi(node->value);
480 } else if (!strcmp(node->key, "dst_port") && needs_dst_port) {
481 tnl_cfg.dst_port = htons(atoi(node->value));
482 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT,
484 } else if (!strcmp(node->key, "csum") && has_csum) {
485 if (!strcmp(node->value, "true")) {
489 } else if (!strcmp(node->key, "df_default")) {
490 if (!strcmp(node->value, "false")) {
491 flags &= ~TNL_F_DF_DEFAULT;
492 tnl_cfg.dont_fragment = false;
494 } else if (!strcmp(node->key, "peer_cert") && tnl_cfg.ipsec) {
495 if (smap_get(args, "certificate")) {
496 ipsec_mech_set = true;
498 const char *use_ssl_cert;
500 /* If the "use_ssl_cert" is true, then "certificate" and
501 * "private_key" will be pulled from the SSL table. The
502 * use of this option is strongly discouraged, since it
503 * will like be removed when multiple SSL configurations
504 * are supported by OVS.
506 use_ssl_cert = smap_get(args, "use_ssl_cert");
507 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
508 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
512 ipsec_mech_set = true;
514 } else if (!strcmp(node->key, "psk") && tnl_cfg.ipsec) {
515 ipsec_mech_set = true;
516 } else if (tnl_cfg.ipsec
517 && (!strcmp(node->key, "certificate")
518 || !strcmp(node->key, "private_key")
519 || !strcmp(node->key, "use_ssl_cert"))) {
520 /* Ignore options not used by the netdev. */
521 } else if (!strcmp(node->key, "key") ||
522 !strcmp(node->key, "in_key") ||
523 !strcmp(node->key, "out_key")) {
524 /* Handled separately below. */
526 VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->key);
530 /* Add a default destination port for VXLAN if none specified. */
531 if (needs_dst_port && !tnl_cfg.dst_port) {
532 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT, VXLAN_DST_PORT);
533 tnl_cfg.dst_port = htons(VXLAN_DST_PORT);
537 static pid_t pid = 0;
539 char *file_name = xasprintf("%s/%s", ovs_rundir(),
540 "ovs-monitor-ipsec.pid");
541 pid = read_pidfile(file_name);
546 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
551 if (smap_get(args, "peer_cert") && smap_get(args, "psk")) {
552 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name);
556 if (!ipsec_mech_set) {
557 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
563 if (!tnl_cfg.ip_dst) {
564 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
568 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_DST_IPV4, tnl_cfg.ip_dst);
570 if (tnl_cfg.ip_src) {
571 if (ip_is_multicast(tnl_cfg.ip_dst)) {
572 VLOG_WARN("%s: remote_ip is multicast, ignoring local_ip", name);
575 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_SRC_IPV4, tnl_cfg.ip_src);
580 tnl_cfg.ttl = DEFAULT_TTL;
583 tnl_cfg.in_key = parse_key(args, "in_key",
584 &tnl_cfg.in_key_present,
585 &tnl_cfg.in_key_flow);
586 if (tnl_cfg.in_key_present && !tnl_cfg.in_key_flow) {
587 nl_msg_put_be64(options, OVS_TUNNEL_ATTR_IN_KEY, tnl_cfg.in_key);
590 tnl_cfg.out_key = parse_key(args, "out_key",
591 &tnl_cfg.out_key_present,
592 &tnl_cfg.out_key_flow);
593 if (tnl_cfg.out_key_present && !tnl_cfg.out_key_flow) {
594 nl_msg_put_be64(options, OVS_TUNNEL_ATTR_OUT_KEY, tnl_cfg.out_key);
596 nl_msg_put_u32(options, OVS_TUNNEL_ATTR_FLAGS, flags);
598 dev->tnl_cfg = tnl_cfg;
602 || options->size != dev->options->size
603 || memcmp(options->data, dev->options->data, options->size)) {
604 struct dpif_linux_vport vport;
606 dpif_linux_vport_init(&vport);
607 vport.cmd = OVS_VPORT_CMD_SET;
609 vport.options = options->data;
610 vport.options_len = options->size;
611 error = dpif_linux_vport_transact(&vport, NULL, NULL);
612 if (!error || error == ENODEV) {
613 /* Either reconfiguration succeeded or this vport is not installed
614 * in the kernel (e.g. it hasn't been added to a dpif yet with
615 * dpif_port_add()). */
616 ofpbuf_delete(dev->options);
617 dev->options = options;
624 ofpbuf_delete(options);
629 tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len,
630 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1])
632 static const struct nl_policy ovs_tunnel_policy[] = {
633 [OVS_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32, .optional = true },
634 [OVS_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32, .optional = true },
635 [OVS_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true },
636 [OVS_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true },
637 [OVS_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true },
638 [OVS_TUNNEL_ATTR_TOS] = { .type = NL_A_U8, .optional = true },
639 [OVS_TUNNEL_ATTR_TTL] = { .type = NL_A_U8, .optional = true },
640 [OVS_TUNNEL_ATTR_DST_PORT] = { .type = NL_A_U16, .optional = true },
644 ofpbuf_use_const(&buf, options, options_len);
645 if (!nl_policy_parse(&buf, 0, ovs_tunnel_policy,
646 a, ARRAY_SIZE(ovs_tunnel_policy))) {
653 get_be64_or_zero(const struct nlattr *a)
655 return a ? ntohll(nl_attr_get_be64(a)) : 0;
659 get_tunnel_config(struct netdev_dev *dev_, struct smap *args)
661 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
662 const char *name = netdev_dev_get_name(dev_);
663 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
668 struct dpif_linux_vport reply;
671 error = dpif_linux_vport_get(name, &reply, &buf);
673 VLOG_ERR_RL(&rl, "%s: vport query failed (%s)", name,
678 dev->options = ofpbuf_clone_data(reply.options, reply.options_len);
682 error = tnl_port_config_from_nlattr(dev->options->data, dev->options->size,
685 VLOG_ERR_RL(&rl, "%s: failed to parse kernel config (%s)",
686 name, strerror(error));
690 if (a[OVS_TUNNEL_ATTR_DST_IPV4]) {
691 ovs_be32 daddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
692 smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(daddr));
695 if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) {
696 ovs_be32 saddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_SRC_IPV4]);
697 smap_add_format(args, "local_ip", IP_FMT, IP_ARGS(saddr));
700 if (!a[OVS_TUNNEL_ATTR_IN_KEY] && !a[OVS_TUNNEL_ATTR_OUT_KEY]) {
701 smap_add(args, "key", "flow");
703 uint64_t in_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_IN_KEY]);
704 uint64_t out_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_OUT_KEY]);
706 if (in_key && in_key == out_key) {
707 smap_add_format(args, "key", "%"PRIu64, in_key);
709 if (!a[OVS_TUNNEL_ATTR_IN_KEY]) {
710 smap_add(args, "in_key", "flow");
712 smap_add_format(args, "in_key", "%"PRIu64, in_key);
715 if (!a[OVS_TUNNEL_ATTR_OUT_KEY]) {
716 smap_add(args, "out_key", "flow");
717 } else if (out_key) {
718 smap_add_format(args, "out_key", "%"PRIu64, out_key);
723 flags = get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]);
725 if (flags & TNL_F_TTL_INHERIT) {
726 smap_add(args, "ttl", "inherit");
727 } else if (a[OVS_TUNNEL_ATTR_TTL]) {
728 int ttl = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TTL]);
729 smap_add_format(args, "ttl", "%d", ttl);
732 if (flags & TNL_F_TOS_INHERIT) {
733 smap_add(args, "tos", "inherit");
734 } else if (a[OVS_TUNNEL_ATTR_TOS]) {
735 int tos = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TOS]);
736 smap_add_format(args, "tos", "0x%x", tos);
739 if (a[OVS_TUNNEL_ATTR_DST_PORT]) {
740 uint16_t dst_port = nl_attr_get_u16(a[OVS_TUNNEL_ATTR_DST_PORT]);
741 if (dst_port != VXLAN_DST_PORT) {
742 smap_add_format(args, "dst_port", "%d", dst_port);
746 if (flags & TNL_F_CSUM) {
747 smap_add(args, "csum", "true");
750 if (!(flags & TNL_F_DF_DEFAULT)) {
751 smap_add(args, "df_default", "false");
757 /* Code specific to patch ports. */
760 netdev_vport_patch_peer(const struct netdev *netdev)
762 return netdev_vport_is_patch(netdev)
763 ? netdev_vport_get_dev(netdev)->peer
768 netdev_vport_patch_inc_rx(const struct netdev *netdev,
769 const struct dpif_flow_stats *stats)
771 if (netdev_vport_is_patch(netdev)) {
772 struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev);
773 dev->stats.rx_packets += stats->n_packets;
774 dev->stats.rx_bytes += stats->n_bytes;
779 netdev_vport_patch_inc_tx(const struct netdev *netdev,
780 const struct dpif_flow_stats *stats)
782 if (netdev_vport_is_patch(netdev)) {
783 struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev);
784 dev->stats.tx_packets += stats->n_packets;
785 dev->stats.tx_bytes += stats->n_bytes;
790 get_patch_config(struct netdev_dev *dev_, struct smap *args)
792 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
795 smap_add(args, "peer", dev->peer);
801 set_patch_config(struct netdev_dev *dev_, const struct smap *args)
803 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
804 const char *name = netdev_dev_get_name(dev_);
807 peer = smap_get(args, "peer");
809 VLOG_ERR("%s: patch type requires valid 'peer' argument", name);
813 if (smap_count(args) > 1) {
814 VLOG_ERR("%s: patch type takes only a 'peer' argument", name);
818 if (!strcmp(name, peer)) {
819 VLOG_ERR("%s: patch peer must not be self", name);
824 dev->peer = xstrdup(peer);
830 patch_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
832 struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev);
833 memcpy(stats, &dev->stats, sizeof *stats);
837 #define VPORT_FUNCTIONS(GET_CONFIG, SET_CONFIG, \
838 GET_TUNNEL_CONFIG, GET_STATS, \
844 netdev_vport_create, \
845 netdev_vport_destroy, \
851 netdev_vport_close, \
855 NULL, /* recv_wait */ \
859 NULL, /* send_wait */ \
861 netdev_vport_set_etheraddr, \
862 netdev_vport_get_etheraddr, \
863 NULL, /* get_mtu */ \
864 NULL, /* set_mtu */ \
865 NULL, /* get_ifindex */ \
866 NULL, /* get_carrier */ \
867 NULL, /* get_carrier_resets */ \
868 NULL, /* get_miimon */ \
870 NULL, /* set_stats */ \
872 NULL, /* get_features */ \
873 NULL, /* set_advertisements */ \
875 NULL, /* set_policing */ \
876 NULL, /* get_qos_types */ \
877 NULL, /* get_qos_capabilities */ \
878 NULL, /* get_qos */ \
879 NULL, /* set_qos */ \
880 NULL, /* get_queue */ \
881 NULL, /* set_queue */ \
882 NULL, /* delete_queue */ \
883 NULL, /* get_queue_stats */ \
884 NULL, /* dump_queues */ \
885 NULL, /* dump_queue_stats */ \
887 NULL, /* get_in4 */ \
888 NULL, /* set_in4 */ \
889 NULL, /* get_in6 */ \
890 NULL, /* add_router */ \
891 NULL, /* get_next_hop */ \
893 NULL, /* arp_lookup */ \
895 netdev_vport_update_flags, \
897 netdev_vport_change_seq
899 #define TUNNEL_CLASS(NAME, VPORT_TYPE) \
901 { NAME, VPORT_FUNCTIONS(get_tunnel_config, \
903 get_netdev_tunnel_config, \
904 netdev_vport_get_stats, \
905 tunnel_get_status) }}
908 netdev_vport_register(void)
910 static const struct vport_class vport_classes[] = {
911 TUNNEL_CLASS("gre", OVS_VPORT_TYPE_GRE),
912 TUNNEL_CLASS("ipsec_gre", OVS_VPORT_TYPE_GRE),
913 TUNNEL_CLASS("gre64", OVS_VPORT_TYPE_GRE64),
914 TUNNEL_CLASS("ipsec_gre64", OVS_VPORT_TYPE_GRE64),
915 TUNNEL_CLASS("capwap", OVS_VPORT_TYPE_CAPWAP),
916 TUNNEL_CLASS("vxlan", OVS_VPORT_TYPE_VXLAN),
918 { OVS_VPORT_TYPE_PATCH,
919 { "patch", VPORT_FUNCTIONS(get_patch_config,
928 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
929 netdev_register_provider(&vport_classes[i].netdev_class);