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_FT_GRE:
197 case __OVS_VPORT_TYPE_MAX:
201 VLOG_WARN_RL(&rl, "dp%d: port `%s' has unsupported type %u",
202 vport->dp_ifindex, vport->name, (unsigned int) vport->type);
207 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
208 struct netdev_dev **netdev_devp)
210 struct netdev_dev_vport *dev;
212 dev = xzalloc(sizeof *dev);
213 netdev_dev_init(&dev->netdev_dev, name, netdev_class);
215 eth_addr_random(dev->etheraddr);
217 *netdev_devp = &dev->netdev_dev;
218 route_table_register();
224 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
226 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
228 ofpbuf_delete(netdev_dev->options);
229 route_table_unregister();
230 free(netdev_dev->peer);
235 netdev_vport_open(struct netdev_dev *netdev_dev, struct netdev **netdevp)
237 *netdevp = xmalloc(sizeof **netdevp);
238 netdev_init(*netdevp, netdev_dev);
243 netdev_vport_close(struct netdev *netdev)
249 netdev_vport_set_etheraddr(struct netdev *netdev,
250 const uint8_t mac[ETH_ADDR_LEN])
252 memcpy(netdev_vport_get_dev(netdev)->etheraddr, mac, ETH_ADDR_LEN);
253 netdev_vport_poll_notify(netdev);
258 netdev_vport_get_etheraddr(const struct netdev *netdev,
259 uint8_t mac[ETH_ADDR_LEN])
261 memcpy(mac, netdev_vport_get_dev(netdev)->etheraddr, ETH_ADDR_LEN);
265 /* Copies 'src' into 'dst', performing format conversion in the process.
267 * 'src' is allowed to be misaligned. */
269 netdev_stats_from_ovs_vport_stats(struct netdev_stats *dst,
270 const struct ovs_vport_stats *src)
272 dst->rx_packets = get_unaligned_u64(&src->rx_packets);
273 dst->tx_packets = get_unaligned_u64(&src->tx_packets);
274 dst->rx_bytes = get_unaligned_u64(&src->rx_bytes);
275 dst->tx_bytes = get_unaligned_u64(&src->tx_bytes);
276 dst->rx_errors = get_unaligned_u64(&src->rx_errors);
277 dst->tx_errors = get_unaligned_u64(&src->tx_errors);
278 dst->rx_dropped = get_unaligned_u64(&src->rx_dropped);
279 dst->tx_dropped = get_unaligned_u64(&src->tx_dropped);
282 dst->rx_length_errors = 0;
283 dst->rx_over_errors = 0;
284 dst->rx_crc_errors = 0;
285 dst->rx_frame_errors = 0;
286 dst->rx_fifo_errors = 0;
287 dst->rx_missed_errors = 0;
288 dst->tx_aborted_errors = 0;
289 dst->tx_carrier_errors = 0;
290 dst->tx_fifo_errors = 0;
291 dst->tx_heartbeat_errors = 0;
292 dst->tx_window_errors = 0;
296 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
298 struct dpif_linux_vport reply;
302 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
305 } else if (!reply.stats) {
310 netdev_stats_from_ovs_vport_stats(stats, reply.stats);
318 tunnel_get_status(const struct netdev *netdev, struct smap *smap)
320 static char iface[IFNAMSIZ];
323 route = netdev_vport_get_dev(netdev)->tnl_cfg.ip_dst;
324 if (route_table_get_name(route, iface)) {
325 struct netdev *egress_netdev;
327 smap_add(smap, "tunnel_egress_iface", iface);
329 if (!netdev_open(iface, "system", &egress_netdev)) {
330 smap_add(smap, "tunnel_egress_iface_carrier",
331 netdev_get_carrier(egress_netdev) ? "up" : "down");
332 netdev_close(egress_netdev);
340 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
341 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
342 enum netdev_flags *old_flagsp)
344 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
348 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
353 netdev_vport_change_seq(const struct netdev *netdev)
355 return netdev_vport_get_dev(netdev)->change_seq;
359 netdev_vport_run(void)
365 netdev_vport_wait(void)
370 /* Helper functions. */
373 netdev_vport_poll_notify(const struct netdev *netdev)
375 struct netdev_dev_vport *ndv = netdev_vport_get_dev(netdev);
378 if (!ndv->change_seq) {
383 /* Code specific to tunnel types. */
386 parse_key(const struct smap *args, const char *name,
387 bool *present, bool *flow)
394 s = smap_get(args, name);
396 s = smap_get(args, "key");
404 if (!strcmp(s, "flow")) {
408 return htonll(strtoull(s, NULL, 0));
413 set_tunnel_config(struct netdev_dev *dev_, const struct smap *args)
415 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
416 const char *name = netdev_dev_get_name(dev_);
417 const char *type = netdev_dev_get_type(dev_);
418 bool ipsec_mech_set, needs_dst_port, has_csum;
419 struct netdev_tunnel_config tnl_cfg;
420 struct smap_node *node;
421 struct ofpbuf *options;
425 flags = TNL_F_DF_DEFAULT;
426 has_csum = strstr(type, "gre");
427 ipsec_mech_set = false;
428 memset(&tnl_cfg, 0, sizeof tnl_cfg);
430 options = ofpbuf_new(64);
432 if (!strcmp(type, "capwap")) {
433 VLOG_WARN_ONCE("CAPWAP tunnel support is deprecated.");
436 needs_dst_port = !strcmp(type, "vxlan");
437 tnl_cfg.ipsec = strstr(type, "ipsec");
439 flags |= TNL_F_IPSEC;
441 tnl_cfg.dont_fragment = true;
443 SMAP_FOR_EACH (node, args) {
444 if (!strcmp(node->key, "remote_ip")) {
445 struct in_addr in_addr;
446 if (lookup_ip(node->value, &in_addr)) {
447 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
449 tnl_cfg.ip_dst = in_addr.s_addr;
451 } else if (!strcmp(node->key, "local_ip")) {
452 struct in_addr in_addr;
453 if (lookup_ip(node->value, &in_addr)) {
454 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
456 tnl_cfg.ip_src = in_addr.s_addr;
458 } else if (!strcmp(node->key, "tos")) {
459 if (!strcmp(node->value, "inherit")) {
460 flags |= TNL_F_TOS_INHERIT;
461 tnl_cfg.tos_inherit = true;
465 tos = strtol(node->value, &endptr, 0);
466 if (*endptr == '\0' && tos == (tos & IP_DSCP_MASK)) {
467 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TOS, tos);
470 VLOG_WARN("%s: invalid TOS %s", name, node->value);
473 } else if (!strcmp(node->key, "ttl")) {
474 if (!strcmp(node->value, "inherit")) {
475 flags |= TNL_F_TTL_INHERIT;
476 tnl_cfg.ttl_inherit = true;
478 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TTL, atoi(node->value));
479 tnl_cfg.ttl = atoi(node->value);
481 } else if (!strcmp(node->key, "dst_port") && needs_dst_port) {
482 tnl_cfg.dst_port = htons(atoi(node->value));
483 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT,
485 } else if (!strcmp(node->key, "csum") && has_csum) {
486 if (!strcmp(node->value, "true")) {
490 } else if (!strcmp(node->key, "df_default")) {
491 if (!strcmp(node->value, "false")) {
492 flags &= ~TNL_F_DF_DEFAULT;
493 tnl_cfg.dont_fragment = false;
495 } else if (!strcmp(node->key, "peer_cert") && tnl_cfg.ipsec) {
496 if (smap_get(args, "certificate")) {
497 ipsec_mech_set = true;
499 const char *use_ssl_cert;
501 /* If the "use_ssl_cert" is true, then "certificate" and
502 * "private_key" will be pulled from the SSL table. The
503 * use of this option is strongly discouraged, since it
504 * will like be removed when multiple SSL configurations
505 * are supported by OVS.
507 use_ssl_cert = smap_get(args, "use_ssl_cert");
508 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
509 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
513 ipsec_mech_set = true;
515 } else if (!strcmp(node->key, "psk") && tnl_cfg.ipsec) {
516 ipsec_mech_set = true;
517 } else if (tnl_cfg.ipsec
518 && (!strcmp(node->key, "certificate")
519 || !strcmp(node->key, "private_key")
520 || !strcmp(node->key, "use_ssl_cert"))) {
521 /* Ignore options not used by the netdev. */
522 } else if (!strcmp(node->key, "key") ||
523 !strcmp(node->key, "in_key") ||
524 !strcmp(node->key, "out_key")) {
525 /* Handled separately below. */
527 VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->key);
531 /* Add a default destination port for VXLAN if none specified. */
532 if (needs_dst_port && !tnl_cfg.dst_port) {
533 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT, VXLAN_DST_PORT);
534 tnl_cfg.dst_port = htons(VXLAN_DST_PORT);
538 static pid_t pid = 0;
540 char *file_name = xasprintf("%s/%s", ovs_rundir(),
541 "ovs-monitor-ipsec.pid");
542 pid = read_pidfile(file_name);
547 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
552 if (smap_get(args, "peer_cert") && smap_get(args, "psk")) {
553 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name);
557 if (!ipsec_mech_set) {
558 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
564 if (!tnl_cfg.ip_dst) {
565 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
569 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_DST_IPV4, tnl_cfg.ip_dst);
571 if (tnl_cfg.ip_src) {
572 if (ip_is_multicast(tnl_cfg.ip_dst)) {
573 VLOG_WARN("%s: remote_ip is multicast, ignoring local_ip", name);
576 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_SRC_IPV4, tnl_cfg.ip_src);
581 tnl_cfg.ttl = DEFAULT_TTL;
584 tnl_cfg.in_key = parse_key(args, "in_key",
585 &tnl_cfg.in_key_present,
586 &tnl_cfg.in_key_flow);
587 if (tnl_cfg.in_key_present && !tnl_cfg.in_key_flow) {
588 nl_msg_put_be64(options, OVS_TUNNEL_ATTR_IN_KEY, tnl_cfg.in_key);
591 tnl_cfg.out_key = parse_key(args, "out_key",
592 &tnl_cfg.out_key_present,
593 &tnl_cfg.out_key_flow);
594 if (tnl_cfg.out_key_present && !tnl_cfg.out_key_flow) {
595 nl_msg_put_be64(options, OVS_TUNNEL_ATTR_OUT_KEY, tnl_cfg.out_key);
597 nl_msg_put_u32(options, OVS_TUNNEL_ATTR_FLAGS, flags);
599 dev->tnl_cfg = tnl_cfg;
603 || options->size != dev->options->size
604 || memcmp(options->data, dev->options->data, options->size)) {
605 struct dpif_linux_vport vport;
607 dpif_linux_vport_init(&vport);
608 vport.cmd = OVS_VPORT_CMD_SET;
610 vport.options = options->data;
611 vport.options_len = options->size;
612 error = dpif_linux_vport_transact(&vport, NULL, NULL);
613 if (!error || error == ENODEV) {
614 /* Either reconfiguration succeeded or this vport is not installed
615 * in the kernel (e.g. it hasn't been added to a dpif yet with
616 * dpif_port_add()). */
617 ofpbuf_delete(dev->options);
618 dev->options = options;
625 ofpbuf_delete(options);
630 tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len,
631 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1])
633 static const struct nl_policy ovs_tunnel_policy[] = {
634 [OVS_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32, .optional = true },
635 [OVS_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32, .optional = true },
636 [OVS_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true },
637 [OVS_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true },
638 [OVS_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true },
639 [OVS_TUNNEL_ATTR_TOS] = { .type = NL_A_U8, .optional = true },
640 [OVS_TUNNEL_ATTR_TTL] = { .type = NL_A_U8, .optional = true },
641 [OVS_TUNNEL_ATTR_DST_PORT] = { .type = NL_A_U16, .optional = true },
645 ofpbuf_use_const(&buf, options, options_len);
646 if (!nl_policy_parse(&buf, 0, ovs_tunnel_policy,
647 a, ARRAY_SIZE(ovs_tunnel_policy))) {
654 get_be64_or_zero(const struct nlattr *a)
656 return a ? ntohll(nl_attr_get_be64(a)) : 0;
660 get_tunnel_config(struct netdev_dev *dev_, struct smap *args)
662 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
663 const char *name = netdev_dev_get_name(dev_);
664 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
669 struct dpif_linux_vport reply;
672 error = dpif_linux_vport_get(name, &reply, &buf);
674 VLOG_ERR_RL(&rl, "%s: vport query failed (%s)", name,
679 dev->options = ofpbuf_clone_data(reply.options, reply.options_len);
683 error = tnl_port_config_from_nlattr(dev->options->data, dev->options->size,
686 VLOG_ERR_RL(&rl, "%s: failed to parse kernel config (%s)",
687 name, strerror(error));
691 if (a[OVS_TUNNEL_ATTR_DST_IPV4]) {
692 ovs_be32 daddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
693 smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(daddr));
696 if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) {
697 ovs_be32 saddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_SRC_IPV4]);
698 smap_add_format(args, "local_ip", IP_FMT, IP_ARGS(saddr));
701 if (!a[OVS_TUNNEL_ATTR_IN_KEY] && !a[OVS_TUNNEL_ATTR_OUT_KEY]) {
702 smap_add(args, "key", "flow");
704 uint64_t in_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_IN_KEY]);
705 uint64_t out_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_OUT_KEY]);
707 if (in_key && in_key == out_key) {
708 smap_add_format(args, "key", "%"PRIu64, in_key);
710 if (!a[OVS_TUNNEL_ATTR_IN_KEY]) {
711 smap_add(args, "in_key", "flow");
713 smap_add_format(args, "in_key", "%"PRIu64, in_key);
716 if (!a[OVS_TUNNEL_ATTR_OUT_KEY]) {
717 smap_add(args, "out_key", "flow");
718 } else if (out_key) {
719 smap_add_format(args, "out_key", "%"PRIu64, out_key);
724 flags = get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]);
726 if (flags & TNL_F_TTL_INHERIT) {
727 smap_add(args, "ttl", "inherit");
728 } else if (a[OVS_TUNNEL_ATTR_TTL]) {
729 int ttl = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TTL]);
730 smap_add_format(args, "ttl", "%d", ttl);
733 if (flags & TNL_F_TOS_INHERIT) {
734 smap_add(args, "tos", "inherit");
735 } else if (a[OVS_TUNNEL_ATTR_TOS]) {
736 int tos = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TOS]);
737 smap_add_format(args, "tos", "0x%x", tos);
740 if (a[OVS_TUNNEL_ATTR_DST_PORT]) {
741 uint16_t dst_port = nl_attr_get_u16(a[OVS_TUNNEL_ATTR_DST_PORT]);
742 if (dst_port != VXLAN_DST_PORT) {
743 smap_add_format(args, "dst_port", "%d", dst_port);
747 if (flags & TNL_F_CSUM) {
748 smap_add(args, "csum", "true");
751 if (!(flags & TNL_F_DF_DEFAULT)) {
752 smap_add(args, "df_default", "false");
758 /* Code specific to patch ports. */
761 netdev_vport_patch_peer(const struct netdev *netdev)
763 return netdev_vport_is_patch(netdev)
764 ? netdev_vport_get_dev(netdev)->peer
769 netdev_vport_patch_inc_rx(const struct netdev *netdev,
770 const struct dpif_flow_stats *stats)
772 if (netdev_vport_is_patch(netdev)) {
773 struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev);
774 dev->stats.rx_packets += stats->n_packets;
775 dev->stats.rx_bytes += stats->n_bytes;
780 netdev_vport_patch_inc_tx(const struct netdev *netdev,
781 const struct dpif_flow_stats *stats)
783 if (netdev_vport_is_patch(netdev)) {
784 struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev);
785 dev->stats.tx_packets += stats->n_packets;
786 dev->stats.tx_bytes += stats->n_bytes;
791 get_patch_config(struct netdev_dev *dev_, struct smap *args)
793 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
796 smap_add(args, "peer", dev->peer);
802 set_patch_config(struct netdev_dev *dev_, const struct smap *args)
804 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
805 const char *name = netdev_dev_get_name(dev_);
808 peer = smap_get(args, "peer");
810 VLOG_ERR("%s: patch type requires valid 'peer' argument", name);
814 if (smap_count(args) > 1) {
815 VLOG_ERR("%s: patch type takes only a 'peer' argument", name);
819 if (!strcmp(name, peer)) {
820 VLOG_ERR("%s: patch peer must not be self", name);
825 dev->peer = xstrdup(peer);
831 patch_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
833 struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev);
834 memcpy(stats, &dev->stats, sizeof *stats);
838 #define VPORT_FUNCTIONS(GET_CONFIG, SET_CONFIG, \
839 GET_TUNNEL_CONFIG, GET_STATS, \
845 netdev_vport_create, \
846 netdev_vport_destroy, \
852 netdev_vport_close, \
856 NULL, /* recv_wait */ \
860 NULL, /* send_wait */ \
862 netdev_vport_set_etheraddr, \
863 netdev_vport_get_etheraddr, \
864 NULL, /* get_mtu */ \
865 NULL, /* set_mtu */ \
866 NULL, /* get_ifindex */ \
867 NULL, /* get_carrier */ \
868 NULL, /* get_carrier_resets */ \
869 NULL, /* get_miimon */ \
871 NULL, /* set_stats */ \
873 NULL, /* get_features */ \
874 NULL, /* set_advertisements */ \
876 NULL, /* set_policing */ \
877 NULL, /* get_qos_types */ \
878 NULL, /* get_qos_capabilities */ \
879 NULL, /* get_qos */ \
880 NULL, /* set_qos */ \
881 NULL, /* get_queue */ \
882 NULL, /* set_queue */ \
883 NULL, /* delete_queue */ \
884 NULL, /* get_queue_stats */ \
885 NULL, /* dump_queues */ \
886 NULL, /* dump_queue_stats */ \
888 NULL, /* get_in4 */ \
889 NULL, /* set_in4 */ \
890 NULL, /* get_in6 */ \
891 NULL, /* add_router */ \
892 NULL, /* get_next_hop */ \
894 NULL, /* arp_lookup */ \
896 netdev_vport_update_flags, \
898 netdev_vport_change_seq
900 #define TUNNEL_CLASS(NAME, VPORT_TYPE) \
902 { NAME, VPORT_FUNCTIONS(get_tunnel_config, \
904 get_netdev_tunnel_config, \
905 netdev_vport_get_stats, \
906 tunnel_get_status) }}
909 netdev_vport_register(void)
911 static const struct vport_class vport_classes[] = {
912 TUNNEL_CLASS("gre", OVS_VPORT_TYPE_GRE),
913 TUNNEL_CLASS("ipsec_gre", OVS_VPORT_TYPE_GRE),
914 TUNNEL_CLASS("gre64", OVS_VPORT_TYPE_GRE64),
915 TUNNEL_CLASS("ipsec_gre64", OVS_VPORT_TYPE_GRE64),
916 TUNNEL_CLASS("capwap", OVS_VPORT_TYPE_CAPWAP),
917 TUNNEL_CLASS("vxlan", OVS_VPORT_TYPE_VXLAN),
919 { OVS_VPORT_TYPE_PATCH,
920 { "patch", VPORT_FUNCTIONS(get_patch_config,
929 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
930 netdev_register_provider(&vport_classes[i].netdev_class);