2 * Copyright (c) 2010, 2011, 2012 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"
32 #include "dpif-linux.h"
36 #include "netdev-linux.h"
37 #include "netdev-provider.h"
39 #include "netlink-notifier.h"
40 #include "netlink-socket.h"
42 #include "openvswitch/tunnel.h"
44 #include "route-table.h"
46 #include "socket-util.h"
47 #include "unaligned.h"
50 VLOG_DEFINE_THIS_MODULE(netdev_vport);
52 /* Default to the OTV port, per the VXLAN IETF draft. */
53 #define VXLAN_DST_PORT 8472
55 struct netdev_dev_vport {
56 struct netdev_dev netdev_dev;
57 struct ofpbuf *options;
58 unsigned int change_seq;
66 enum ovs_vport_type type;
67 struct netdev_class netdev_class;
68 int (*parse_config)(const char *name, const char *type,
69 const struct smap *args, struct ofpbuf *options);
70 int (*unparse_config)(const char *name, const char *type,
71 const struct nlattr *options, size_t options_len,
75 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
77 static int netdev_vport_create(const struct netdev_class *, const char *,
78 struct netdev_dev **);
79 static void netdev_vport_poll_notify(const struct netdev *);
80 static int tnl_port_config_from_nlattr(const struct nlattr *options,
82 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1]);
84 static const char *netdev_vport_get_tnl_iface(const struct netdev *netdev);
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 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 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_vport *
107 netdev_vport_cast(const struct netdev *netdev)
109 struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
110 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
111 return CONTAINER_OF(netdev, struct netdev_vport, netdev);
114 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
115 * options to include in OVS_VPORT_ATTR_OPTIONS for configuring that vport.
116 * Otherwise returns NULL. */
117 const struct ofpbuf *
118 netdev_vport_get_options(const struct netdev *netdev)
120 const struct netdev_dev *dev = netdev_get_dev(netdev);
122 return (is_vport_class(netdev_dev_get_class(dev))
123 ? netdev_dev_vport_cast(dev)->options
128 netdev_vport_get_vport_type(const struct netdev *netdev)
130 const struct netdev_dev *dev = netdev_get_dev(netdev);
131 const struct netdev_class *class = netdev_dev_get_class(dev);
133 return (is_vport_class(class) ? vport_class_cast(class)->type
134 : class == &netdev_internal_class ? OVS_VPORT_TYPE_INTERNAL
135 : (class == &netdev_linux_class ||
136 class == &netdev_tap_class) ? OVS_VPORT_TYPE_NETDEV
137 : OVS_VPORT_TYPE_UNSPEC);
141 netdev_vport_get_netdev_type(const struct dpif_linux_vport *vport)
143 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
145 switch (vport->type) {
146 case OVS_VPORT_TYPE_UNSPEC:
149 case OVS_VPORT_TYPE_NETDEV:
152 case OVS_VPORT_TYPE_INTERNAL:
155 case OVS_VPORT_TYPE_PATCH:
158 case OVS_VPORT_TYPE_GRE:
159 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
163 return (nl_attr_get_u32(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
164 ? "ipsec_gre" : "gre");
166 case OVS_VPORT_TYPE_GRE64:
167 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
171 return (nl_attr_get_u32(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
172 ? "ipsec_gre64" : "gre64");
174 case OVS_VPORT_TYPE_CAPWAP:
177 case OVS_VPORT_TYPE_VXLAN:
180 case OVS_VPORT_TYPE_FT_GRE:
181 case __OVS_VPORT_TYPE_MAX:
185 VLOG_WARN_RL(&rl, "dp%d: port `%s' has unsupported type %u",
186 vport->dp_ifindex, vport->name, (unsigned int) vport->type);
191 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
192 struct netdev_dev **netdev_devp)
194 struct netdev_dev_vport *dev;
196 dev = xmalloc(sizeof *dev);
197 netdev_dev_init(&dev->netdev_dev, name, netdev_class);
201 *netdev_devp = &dev->netdev_dev;
202 route_table_register();
208 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
210 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
212 ofpbuf_delete(netdev_dev->options);
213 route_table_unregister();
218 netdev_vport_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp)
220 struct netdev_vport *netdev;
222 netdev = xmalloc(sizeof *netdev);
223 netdev_init(&netdev->netdev, netdev_dev_);
225 *netdevp = &netdev->netdev;
230 netdev_vport_close(struct netdev *netdev_)
232 struct netdev_vport *netdev = netdev_vport_cast(netdev_);
237 netdev_vport_get_config(struct netdev_dev *dev_, struct smap *args)
239 const struct netdev_class *netdev_class = netdev_dev_get_class(dev_);
240 const struct vport_class *vport_class = vport_class_cast(netdev_class);
241 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
242 const char *name = netdev_dev_get_name(dev_);
246 struct dpif_linux_vport reply;
249 error = dpif_linux_vport_get(name, &reply, &buf);
251 VLOG_ERR_RL(&rl, "%s: vport query failed (%s)",
252 name, strerror(error));
256 dev->options = ofpbuf_clone_data(reply.options, reply.options_len);
260 error = vport_class->unparse_config(name, netdev_class->type,
265 VLOG_ERR_RL(&rl, "%s: failed to parse kernel config (%s)",
266 name, strerror(error));
272 netdev_vport_set_config(struct netdev_dev *dev_, const struct smap *args)
274 const struct netdev_class *netdev_class = netdev_dev_get_class(dev_);
275 const struct vport_class *vport_class = vport_class_cast(netdev_class);
276 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
277 const char *name = netdev_dev_get_name(dev_);
278 struct ofpbuf *options;
281 options = ofpbuf_new(64);
282 error = vport_class->parse_config(name, netdev_dev_get_type(dev_),
286 || options->size != dev->options->size
287 || memcmp(options->data, dev->options->data, options->size))) {
288 struct dpif_linux_vport vport;
290 dpif_linux_vport_init(&vport);
291 vport.cmd = OVS_VPORT_CMD_SET;
293 vport.options = options->data;
294 vport.options_len = options->size;
295 error = dpif_linux_vport_transact(&vport, NULL, NULL);
296 if (!error || error == ENODEV) {
297 /* Either reconfiguration succeeded or this vport is not installed
298 * in the kernel (e.g. it hasn't been added to a dpif yet with
299 * dpif_port_add()). */
300 ofpbuf_delete(dev->options);
301 dev->options = options;
306 ofpbuf_delete(options);
312 netdev_vport_set_etheraddr(struct netdev *netdev,
313 const uint8_t mac[ETH_ADDR_LEN])
315 struct dpif_linux_vport vport;
318 dpif_linux_vport_init(&vport);
319 vport.cmd = OVS_VPORT_CMD_SET;
320 vport.name = netdev_get_name(netdev);
323 error = dpif_linux_vport_transact(&vport, NULL, NULL);
325 netdev_vport_poll_notify(netdev);
331 netdev_vport_get_etheraddr(const struct netdev *netdev,
332 uint8_t mac[ETH_ADDR_LEN])
334 struct dpif_linux_vport reply;
338 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
341 memcpy(mac, reply.address, ETH_ADDR_LEN);
350 /* Copies 'src' into 'dst', performing format conversion in the process.
352 * 'src' is allowed to be misaligned. */
354 netdev_stats_from_ovs_vport_stats(struct netdev_stats *dst,
355 const struct ovs_vport_stats *src)
357 dst->rx_packets = get_unaligned_u64(&src->rx_packets);
358 dst->tx_packets = get_unaligned_u64(&src->tx_packets);
359 dst->rx_bytes = get_unaligned_u64(&src->rx_bytes);
360 dst->tx_bytes = get_unaligned_u64(&src->tx_bytes);
361 dst->rx_errors = get_unaligned_u64(&src->rx_errors);
362 dst->tx_errors = get_unaligned_u64(&src->tx_errors);
363 dst->rx_dropped = get_unaligned_u64(&src->rx_dropped);
364 dst->tx_dropped = get_unaligned_u64(&src->tx_dropped);
367 dst->rx_length_errors = 0;
368 dst->rx_over_errors = 0;
369 dst->rx_crc_errors = 0;
370 dst->rx_frame_errors = 0;
371 dst->rx_fifo_errors = 0;
372 dst->rx_missed_errors = 0;
373 dst->tx_aborted_errors = 0;
374 dst->tx_carrier_errors = 0;
375 dst->tx_fifo_errors = 0;
376 dst->tx_heartbeat_errors = 0;
377 dst->tx_window_errors = 0;
381 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
383 struct dpif_linux_vport reply;
387 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
390 } else if (!reply.stats) {
395 netdev_stats_from_ovs_vport_stats(stats, reply.stats);
403 netdev_vport_get_drv_info(const struct netdev *netdev, struct smap *smap)
405 const char *iface = netdev_vport_get_tnl_iface(netdev);
408 struct netdev *egress_netdev;
410 smap_add(smap, "tunnel_egress_iface", iface);
412 if (!netdev_open(iface, "system", &egress_netdev)) {
413 smap_add(smap, "tunnel_egress_iface_carrier",
414 netdev_get_carrier(egress_netdev) ? "up" : "down");
415 netdev_close(egress_netdev);
423 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
424 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
425 enum netdev_flags *old_flagsp)
427 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
431 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
436 netdev_vport_change_seq(const struct netdev *netdev)
438 return netdev_dev_vport_cast(netdev_get_dev(netdev))->change_seq;
442 netdev_vport_run(void)
448 netdev_vport_wait(void)
453 /* get_tnl_iface() implementation. */
455 netdev_vport_get_tnl_iface(const struct netdev *netdev)
457 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
459 struct netdev_dev_vport *ndv;
460 static char name[IFNAMSIZ];
462 ndv = netdev_dev_vport_cast(netdev_get_dev(netdev));
463 if (tnl_port_config_from_nlattr(ndv->options->data, ndv->options->size,
467 route = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
469 if (route_table_get_name(route, name)) {
476 /* Helper functions. */
479 netdev_vport_poll_notify(const struct netdev *netdev)
481 struct netdev_dev_vport *ndv;
483 ndv = netdev_dev_vport_cast(netdev_get_dev(netdev));
486 if (!ndv->change_seq) {
491 /* Code specific to individual vport types. */
494 set_key(const struct smap *args, const char *name, uint16_t type,
495 struct ofpbuf *options)
499 s = smap_get(args, name);
501 s = smap_get(args, "key");
507 if (!strcmp(s, "flow")) {
508 /* This is the default if no attribute is present. */
510 nl_msg_put_be64(options, type, htonll(strtoull(s, NULL, 0)));
515 parse_tunnel_config(const char *name, const char *type,
516 const struct smap *args, struct ofpbuf *options)
519 bool is_ipsec = false;
520 bool needs_dst_port = false;
521 bool found_dst_port = false;
522 struct smap_node *node;
523 bool ipsec_mech_set = false;
524 ovs_be32 daddr = htonl(0);
525 ovs_be32 saddr = htonl(0);
528 if (!strcmp(type, "capwap")) {
529 VLOG_WARN_ONCE("CAPWAP tunnel support is deprecated.");
532 flags = TNL_F_DF_DEFAULT;
533 if (!strcmp(type, "gre") || !strcmp(type, "gre64")) {
535 } else if (!strcmp(type, "ipsec_gre") || !strcmp(type, "ipsec_gre64")) {
538 flags |= TNL_F_IPSEC;
539 } else if (!strcmp(type, "vxlan")) {
540 needs_dst_port = true;
543 SMAP_FOR_EACH (node, args) {
544 if (!strcmp(node->key, "remote_ip")) {
545 struct in_addr in_addr;
546 if (lookup_ip(node->value, &in_addr)) {
547 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
549 daddr = in_addr.s_addr;
551 } else if (!strcmp(node->key, "local_ip")) {
552 struct in_addr in_addr;
553 if (lookup_ip(node->value, &in_addr)) {
554 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
556 saddr = in_addr.s_addr;
558 } else if (!strcmp(node->key, "tos")) {
559 if (!strcmp(node->value, "inherit")) {
560 flags |= TNL_F_TOS_INHERIT;
564 tos = strtol(node->value, &endptr, 0);
565 if (*endptr == '\0' && tos == (tos & IP_DSCP_MASK)) {
566 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TOS, tos);
568 VLOG_WARN("%s: invalid TOS %s", name, node->value);
571 } else if (!strcmp(node->key, "ttl")) {
572 if (!strcmp(node->value, "inherit")) {
573 flags |= TNL_F_TTL_INHERIT;
575 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TTL, atoi(node->value));
577 } else if (!strcmp(node->key, "dst_port") && needs_dst_port) {
578 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT,
580 found_dst_port = true;
581 } else if (!strcmp(node->key, "csum") && is_gre) {
582 if (!strcmp(node->value, "true")) {
585 } else if (!strcmp(node->key, "df_inherit")) {
586 if (!strcmp(node->value, "true")) {
587 flags |= TNL_F_DF_INHERIT;
589 } else if (!strcmp(node->key, "df_default")) {
590 if (!strcmp(node->value, "false")) {
591 flags &= ~TNL_F_DF_DEFAULT;
593 } else if (!strcmp(node->key, "pmtud")) {
594 if (!strcmp(node->value, "true")) {
595 VLOG_WARN_ONCE("%s: The tunnel Path MTU discovery is "
596 "deprecated and may be removed in February "
597 "2013. Please email dev@openvswitch.org with "
599 flags |= TNL_F_PMTUD;
601 } else if (!strcmp(node->key, "peer_cert") && is_ipsec) {
602 if (smap_get(args, "certificate")) {
603 ipsec_mech_set = true;
605 const char *use_ssl_cert;
607 /* If the "use_ssl_cert" is true, then "certificate" and
608 * "private_key" will be pulled from the SSL table. The
609 * use of this option is strongly discouraged, since it
610 * will like be removed when multiple SSL configurations
611 * are supported by OVS.
613 use_ssl_cert = smap_get(args, "use_ssl_cert");
614 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
615 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
619 ipsec_mech_set = true;
621 } else if (!strcmp(node->key, "psk") && is_ipsec) {
622 ipsec_mech_set = true;
624 && (!strcmp(node->key, "certificate")
625 || !strcmp(node->key, "private_key")
626 || !strcmp(node->key, "use_ssl_cert"))) {
627 /* Ignore options not used by the netdev. */
628 } else if (!strcmp(node->key, "key") ||
629 !strcmp(node->key, "in_key") ||
630 !strcmp(node->key, "out_key")) {
631 /* Handled separately below. */
633 VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->key);
637 /* Add a default destination port for VXLAN if none specified. */
638 if (needs_dst_port && !found_dst_port) {
639 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT, VXLAN_DST_PORT);
643 static pid_t pid = 0;
645 char *file_name = xasprintf("%s/%s", ovs_rundir(),
646 "ovs-monitor-ipsec.pid");
647 pid = read_pidfile(file_name);
652 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
657 if (smap_get(args, "peer_cert") && smap_get(args, "psk")) {
658 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name);
662 if (!ipsec_mech_set) {
663 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
669 set_key(args, "in_key", OVS_TUNNEL_ATTR_IN_KEY, options);
670 set_key(args, "out_key", OVS_TUNNEL_ATTR_OUT_KEY, options);
673 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
677 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_DST_IPV4, daddr);
680 if (ip_is_multicast(daddr)) {
681 VLOG_WARN("%s: remote_ip is multicast, ignoring local_ip", name);
683 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_SRC_IPV4, saddr);
687 nl_msg_put_u32(options, OVS_TUNNEL_ATTR_FLAGS, flags);
693 tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len,
694 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1])
696 static const struct nl_policy ovs_tunnel_policy[] = {
697 [OVS_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32 },
698 [OVS_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32 },
699 [OVS_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true },
700 [OVS_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true },
701 [OVS_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true },
702 [OVS_TUNNEL_ATTR_TOS] = { .type = NL_A_U8, .optional = true },
703 [OVS_TUNNEL_ATTR_TTL] = { .type = NL_A_U8, .optional = true },
704 [OVS_TUNNEL_ATTR_DST_PORT] = { .type = NL_A_U16, .optional = true },
708 ofpbuf_use_const(&buf, options, options_len);
709 if (!nl_policy_parse(&buf, 0, ovs_tunnel_policy,
710 a, ARRAY_SIZE(ovs_tunnel_policy))) {
717 get_be64_or_zero(const struct nlattr *a)
719 return a ? ntohll(nl_attr_get_be64(a)) : 0;
723 unparse_tunnel_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
724 const struct nlattr *options, size_t options_len,
727 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
732 error = tnl_port_config_from_nlattr(options, options_len, a);
738 daddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
739 smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(daddr));
741 if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) {
742 ovs_be32 saddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_SRC_IPV4]);
743 smap_add_format(args, "local_ip", IP_FMT, IP_ARGS(saddr));
746 if (!a[OVS_TUNNEL_ATTR_IN_KEY] && !a[OVS_TUNNEL_ATTR_OUT_KEY]) {
747 smap_add(args, "key", "flow");
749 uint64_t in_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_IN_KEY]);
750 uint64_t out_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_OUT_KEY]);
752 if (in_key && in_key == out_key) {
753 smap_add_format(args, "key", "%"PRIu64, in_key);
755 if (!a[OVS_TUNNEL_ATTR_IN_KEY]) {
756 smap_add(args, "in_key", "flow");
758 smap_add_format(args, "in_key", "%"PRIu64, in_key);
761 if (!a[OVS_TUNNEL_ATTR_OUT_KEY]) {
762 smap_add(args, "out_key", "flow");
763 } else if (out_key) {
764 smap_add_format(args, "out_key", "%"PRIu64, out_key);
769 flags = nl_attr_get_u32(a[OVS_TUNNEL_ATTR_FLAGS]);
770 if (flags & TNL_F_TTL_INHERIT) {
771 smap_add(args, "ttl", "inherit");
772 } else if (a[OVS_TUNNEL_ATTR_TTL]) {
773 int ttl = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TTL]);
774 smap_add_format(args, "ttl", "%d", ttl);
777 if (flags & TNL_F_TOS_INHERIT) {
778 smap_add(args, "tos", "inherit");
779 } else if (a[OVS_TUNNEL_ATTR_TOS]) {
780 int tos = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TOS]);
781 smap_add_format(args, "tos", "0x%x", tos);
784 if (a[OVS_TUNNEL_ATTR_DST_PORT]) {
785 uint16_t dst_port = nl_attr_get_u16(a[OVS_TUNNEL_ATTR_DST_PORT]);
786 if (dst_port != VXLAN_DST_PORT) {
787 smap_add_format(args, "dst_port", "%d", dst_port);
791 if (flags & TNL_F_CSUM) {
792 smap_add(args, "csum", "true");
794 if (flags & TNL_F_DF_INHERIT) {
795 smap_add(args, "df_inherit", "true");
797 if (!(flags & TNL_F_DF_DEFAULT)) {
798 smap_add(args, "df_default", "false");
800 if (flags & TNL_F_PMTUD) {
801 smap_add(args, "pmtud", "true");
808 parse_patch_config(const char *name, const char *type OVS_UNUSED,
809 const struct smap *args, struct ofpbuf *options)
813 peer = smap_get(args, "peer");
815 VLOG_ERR("%s: patch type requires valid 'peer' argument", name);
819 if (smap_count(args) > 1) {
820 VLOG_ERR("%s: patch type takes only a 'peer' argument", name);
824 if (strlen(peer) >= IFNAMSIZ) {
825 VLOG_ERR("%s: patch 'peer' arg too long", name);
829 if (!strcmp(name, peer)) {
830 VLOG_ERR("%s: patch peer must not be self", name);
834 nl_msg_put_string(options, OVS_PATCH_ATTR_PEER, peer);
840 unparse_patch_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
841 const struct nlattr *options, size_t options_len,
844 static const struct nl_policy ovs_patch_policy[] = {
845 [OVS_PATCH_ATTR_PEER] = { .type = NL_A_STRING,
850 struct nlattr *a[ARRAY_SIZE(ovs_patch_policy)];
853 ofpbuf_use_const(&buf, options, options_len);
854 if (!nl_policy_parse(&buf, 0, ovs_patch_policy,
855 a, ARRAY_SIZE(ovs_patch_policy))) {
859 smap_add(args, "peer", nl_attr_get_string(a[OVS_PATCH_ATTR_PEER]));
863 #define VPORT_FUNCTIONS(GET_STATUS) \
868 netdev_vport_create, \
869 netdev_vport_destroy, \
870 netdev_vport_get_config, \
871 netdev_vport_set_config, \
874 netdev_vport_close, \
878 NULL, /* recv_wait */ \
882 NULL, /* send_wait */ \
884 netdev_vport_set_etheraddr, \
885 netdev_vport_get_etheraddr, \
886 NULL, /* get_mtu */ \
887 NULL, /* set_mtu */ \
888 NULL, /* get_ifindex */ \
889 NULL, /* get_carrier */ \
890 NULL, /* get_carrier_resets */ \
891 NULL, /* get_miimon */ \
892 netdev_vport_get_stats, \
893 NULL, /* set_stats */ \
895 NULL, /* get_features */ \
896 NULL, /* set_advertisements */ \
898 NULL, /* set_policing */ \
899 NULL, /* get_qos_types */ \
900 NULL, /* get_qos_capabilities */ \
901 NULL, /* get_qos */ \
902 NULL, /* set_qos */ \
903 NULL, /* get_queue */ \
904 NULL, /* set_queue */ \
905 NULL, /* delete_queue */ \
906 NULL, /* get_queue_stats */ \
907 NULL, /* dump_queues */ \
908 NULL, /* dump_queue_stats */ \
910 NULL, /* get_in4 */ \
911 NULL, /* set_in4 */ \
912 NULL, /* get_in6 */ \
913 NULL, /* add_router */ \
914 NULL, /* get_next_hop */ \
916 NULL, /* arp_lookup */ \
918 netdev_vport_update_flags, \
920 netdev_vport_change_seq
923 netdev_vport_register(void)
925 static const struct vport_class vport_classes[] = {
926 { OVS_VPORT_TYPE_GRE,
927 { "gre", VPORT_FUNCTIONS(netdev_vport_get_drv_info) },
928 parse_tunnel_config, unparse_tunnel_config },
930 { OVS_VPORT_TYPE_GRE,
931 { "ipsec_gre", VPORT_FUNCTIONS(netdev_vport_get_drv_info) },
932 parse_tunnel_config, unparse_tunnel_config },
934 { OVS_VPORT_TYPE_GRE64,
935 { "gre64", VPORT_FUNCTIONS(netdev_vport_get_drv_info) },
936 parse_tunnel_config, unparse_tunnel_config },
938 { OVS_VPORT_TYPE_GRE64,
939 { "ipsec_gre64", VPORT_FUNCTIONS(netdev_vport_get_drv_info) },
940 parse_tunnel_config, unparse_tunnel_config },
942 { OVS_VPORT_TYPE_CAPWAP,
943 { "capwap", VPORT_FUNCTIONS(netdev_vport_get_drv_info) },
944 parse_tunnel_config, unparse_tunnel_config },
946 { OVS_VPORT_TYPE_VXLAN,
947 { "vxlan", VPORT_FUNCTIONS(netdev_vport_get_drv_info) },
948 parse_tunnel_config, unparse_tunnel_config },
950 { OVS_VPORT_TYPE_PATCH,
951 { "patch", VPORT_FUNCTIONS(NULL) },
952 parse_patch_config, unparse_patch_config }
957 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
958 netdev_register_provider(&vport_classes[i].netdev_class);