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"
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]);
85 is_vport_class(const struct netdev_class *class)
87 return class->create == netdev_vport_create;
90 static const struct vport_class *
91 vport_class_cast(const struct netdev_class *class)
93 assert(is_vport_class(class));
94 return CONTAINER_OF(class, struct vport_class, netdev_class);
97 static struct netdev_dev_vport *
98 netdev_dev_vport_cast(const struct netdev_dev *netdev_dev)
100 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
101 return CONTAINER_OF(netdev_dev, struct netdev_dev_vport, netdev_dev);
104 static struct netdev_vport *
105 netdev_vport_cast(const struct netdev *netdev)
107 struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
108 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
109 return CONTAINER_OF(netdev, struct netdev_vport, netdev);
112 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
113 * options to include in OVS_VPORT_ATTR_OPTIONS for configuring that vport.
114 * Otherwise returns NULL. */
115 const struct ofpbuf *
116 netdev_vport_get_options(const struct netdev *netdev)
118 const struct netdev_dev *dev = netdev_get_dev(netdev);
120 return (is_vport_class(netdev_dev_get_class(dev))
121 ? netdev_dev_vport_cast(dev)->options
126 netdev_vport_get_vport_type(const struct netdev *netdev)
128 const struct netdev_dev *dev = netdev_get_dev(netdev);
129 const struct netdev_class *class = netdev_dev_get_class(dev);
131 return (is_vport_class(class) ? vport_class_cast(class)->type
132 : class == &netdev_internal_class ? OVS_VPORT_TYPE_INTERNAL
133 : (class == &netdev_linux_class ||
134 class == &netdev_tap_class) ? OVS_VPORT_TYPE_NETDEV
135 : OVS_VPORT_TYPE_UNSPEC);
139 get_u32_or_zero(const struct nlattr *a)
141 return a ? nl_attr_get_u32(a) : 0;
145 netdev_vport_get_netdev_type(const struct dpif_linux_vport *vport)
147 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
149 switch (vport->type) {
150 case OVS_VPORT_TYPE_UNSPEC:
153 case OVS_VPORT_TYPE_NETDEV:
156 case OVS_VPORT_TYPE_INTERNAL:
159 case OVS_VPORT_TYPE_PATCH:
162 case OVS_VPORT_TYPE_GRE:
163 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
167 return (get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
168 ? "ipsec_gre" : "gre");
170 case OVS_VPORT_TYPE_GRE64:
171 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
175 return (get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
176 ? "ipsec_gre64" : "gre64");
178 case OVS_VPORT_TYPE_CAPWAP:
181 case OVS_VPORT_TYPE_VXLAN:
184 case OVS_VPORT_TYPE_FT_GRE:
185 case __OVS_VPORT_TYPE_MAX:
189 VLOG_WARN_RL(&rl, "dp%d: port `%s' has unsupported type %u",
190 vport->dp_ifindex, vport->name, (unsigned int) vport->type);
195 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
196 struct netdev_dev **netdev_devp)
198 struct netdev_dev_vport *dev;
200 dev = xmalloc(sizeof *dev);
201 netdev_dev_init(&dev->netdev_dev, name, netdev_class);
205 *netdev_devp = &dev->netdev_dev;
206 route_table_register();
212 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
214 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
216 ofpbuf_delete(netdev_dev->options);
217 route_table_unregister();
222 netdev_vport_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp)
224 struct netdev_vport *netdev;
226 netdev = xmalloc(sizeof *netdev);
227 netdev_init(&netdev->netdev, netdev_dev_);
229 *netdevp = &netdev->netdev;
234 netdev_vport_close(struct netdev *netdev_)
236 struct netdev_vport *netdev = netdev_vport_cast(netdev_);
241 netdev_vport_get_config(struct netdev_dev *dev_, struct smap *args)
243 const struct netdev_class *netdev_class = netdev_dev_get_class(dev_);
244 const struct vport_class *vport_class = vport_class_cast(netdev_class);
245 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
246 const char *name = netdev_dev_get_name(dev_);
250 struct dpif_linux_vport reply;
253 error = dpif_linux_vport_get(name, &reply, &buf);
255 VLOG_ERR_RL(&rl, "%s: vport query failed (%s)",
256 name, strerror(error));
260 dev->options = ofpbuf_clone_data(reply.options, reply.options_len);
264 error = vport_class->unparse_config(name, netdev_class->type,
269 VLOG_ERR_RL(&rl, "%s: failed to parse kernel config (%s)",
270 name, strerror(error));
276 netdev_vport_set_config(struct netdev_dev *dev_, const struct smap *args)
278 const struct netdev_class *netdev_class = netdev_dev_get_class(dev_);
279 const struct vport_class *vport_class = vport_class_cast(netdev_class);
280 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
281 const char *name = netdev_dev_get_name(dev_);
282 struct ofpbuf *options;
285 options = ofpbuf_new(64);
286 error = vport_class->parse_config(name, netdev_dev_get_type(dev_),
290 || options->size != dev->options->size
291 || memcmp(options->data, dev->options->data, options->size))) {
292 struct dpif_linux_vport vport;
294 dpif_linux_vport_init(&vport);
295 vport.cmd = OVS_VPORT_CMD_SET;
297 vport.options = options->data;
298 vport.options_len = options->size;
299 error = dpif_linux_vport_transact(&vport, NULL, NULL);
300 if (!error || error == ENODEV) {
301 /* Either reconfiguration succeeded or this vport is not installed
302 * in the kernel (e.g. it hasn't been added to a dpif yet with
303 * dpif_port_add()). */
304 ofpbuf_delete(dev->options);
305 dev->options = options;
310 ofpbuf_delete(options);
316 netdev_vport_set_etheraddr(struct netdev *netdev,
317 const uint8_t mac[ETH_ADDR_LEN])
319 struct dpif_linux_vport vport;
322 dpif_linux_vport_init(&vport);
323 vport.cmd = OVS_VPORT_CMD_SET;
324 vport.name = netdev_get_name(netdev);
327 error = dpif_linux_vport_transact(&vport, NULL, NULL);
329 netdev_vport_poll_notify(netdev);
335 netdev_vport_get_etheraddr(const struct netdev *netdev,
336 uint8_t mac[ETH_ADDR_LEN])
338 struct dpif_linux_vport reply;
342 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
345 memcpy(mac, reply.address, ETH_ADDR_LEN);
354 /* Copies 'src' into 'dst', performing format conversion in the process.
356 * 'src' is allowed to be misaligned. */
358 netdev_stats_from_ovs_vport_stats(struct netdev_stats *dst,
359 const struct ovs_vport_stats *src)
361 dst->rx_packets = get_unaligned_u64(&src->rx_packets);
362 dst->tx_packets = get_unaligned_u64(&src->tx_packets);
363 dst->rx_bytes = get_unaligned_u64(&src->rx_bytes);
364 dst->tx_bytes = get_unaligned_u64(&src->tx_bytes);
365 dst->rx_errors = get_unaligned_u64(&src->rx_errors);
366 dst->tx_errors = get_unaligned_u64(&src->tx_errors);
367 dst->rx_dropped = get_unaligned_u64(&src->rx_dropped);
368 dst->tx_dropped = get_unaligned_u64(&src->tx_dropped);
371 dst->rx_length_errors = 0;
372 dst->rx_over_errors = 0;
373 dst->rx_crc_errors = 0;
374 dst->rx_frame_errors = 0;
375 dst->rx_fifo_errors = 0;
376 dst->rx_missed_errors = 0;
377 dst->tx_aborted_errors = 0;
378 dst->tx_carrier_errors = 0;
379 dst->tx_fifo_errors = 0;
380 dst->tx_heartbeat_errors = 0;
381 dst->tx_window_errors = 0;
385 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
387 struct dpif_linux_vport reply;
391 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
394 } else if (!reply.stats) {
399 netdev_stats_from_ovs_vport_stats(stats, reply.stats);
407 tunnel_get_status(const struct netdev *netdev, struct smap *smap)
409 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
410 struct netdev_dev_vport *ndv;
411 static char iface[IFNAMSIZ];
414 ndv = netdev_dev_vport_cast(netdev_get_dev(netdev));
416 /* Race condition when 'ndv' was created, but did not have it's
417 * configuration set yet. */
421 if (tnl_port_config_from_nlattr(ndv->options->data,
422 ndv->options->size, a)) {
425 route = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
427 if (route_table_get_name(route, iface)) {
428 struct netdev *egress_netdev;
430 smap_add(smap, "tunnel_egress_iface", iface);
432 if (!netdev_open(iface, "system", &egress_netdev)) {
433 smap_add(smap, "tunnel_egress_iface_carrier",
434 netdev_get_carrier(egress_netdev) ? "up" : "down");
435 netdev_close(egress_netdev);
443 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
444 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
445 enum netdev_flags *old_flagsp)
447 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
451 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
456 netdev_vport_change_seq(const struct netdev *netdev)
458 return netdev_dev_vport_cast(netdev_get_dev(netdev))->change_seq;
462 netdev_vport_run(void)
468 netdev_vport_wait(void)
473 /* Helper functions. */
476 netdev_vport_poll_notify(const struct netdev *netdev)
478 struct netdev_dev_vport *ndv;
480 ndv = netdev_dev_vport_cast(netdev_get_dev(netdev));
483 if (!ndv->change_seq) {
488 /* Code specific to individual vport types. */
491 set_key(const struct smap *args, const char *name, uint16_t type,
492 struct ofpbuf *options)
496 s = smap_get(args, name);
498 s = smap_get(args, "key");
504 if (!strcmp(s, "flow")) {
505 /* This is the default if no attribute is present. */
507 nl_msg_put_be64(options, type, htonll(strtoull(s, NULL, 0)));
512 parse_tunnel_config(const char *name, const char *type,
513 const struct smap *args, struct ofpbuf *options)
516 bool is_ipsec = false;
517 bool needs_dst_port = false;
518 bool found_dst_port = false;
519 struct smap_node *node;
520 bool ipsec_mech_set = false;
521 ovs_be32 daddr = htonl(0);
522 ovs_be32 saddr = htonl(0);
525 if (!strcmp(type, "capwap")) {
526 VLOG_WARN_ONCE("CAPWAP tunnel support is deprecated.");
529 flags = TNL_F_DF_DEFAULT;
530 if (!strcmp(type, "gre") || !strcmp(type, "gre64")) {
532 } else if (!strcmp(type, "ipsec_gre") || !strcmp(type, "ipsec_gre64")) {
535 flags |= TNL_F_IPSEC;
536 } else if (!strcmp(type, "vxlan")) {
537 needs_dst_port = true;
540 SMAP_FOR_EACH (node, args) {
541 if (!strcmp(node->key, "remote_ip")) {
542 struct in_addr in_addr;
543 if (lookup_ip(node->value, &in_addr)) {
544 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
546 daddr = in_addr.s_addr;
548 } else if (!strcmp(node->key, "local_ip")) {
549 struct in_addr in_addr;
550 if (lookup_ip(node->value, &in_addr)) {
551 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
553 saddr = in_addr.s_addr;
555 } else if (!strcmp(node->key, "tos")) {
556 if (!strcmp(node->value, "inherit")) {
557 flags |= TNL_F_TOS_INHERIT;
561 tos = strtol(node->value, &endptr, 0);
562 if (*endptr == '\0' && tos == (tos & IP_DSCP_MASK)) {
563 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TOS, tos);
565 VLOG_WARN("%s: invalid TOS %s", name, node->value);
568 } else if (!strcmp(node->key, "ttl")) {
569 if (!strcmp(node->value, "inherit")) {
570 flags |= TNL_F_TTL_INHERIT;
572 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TTL, atoi(node->value));
574 } else if (!strcmp(node->key, "dst_port") && needs_dst_port) {
575 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT,
577 found_dst_port = true;
578 } else if (!strcmp(node->key, "csum") && is_gre) {
579 if (!strcmp(node->value, "true")) {
582 } else if (!strcmp(node->key, "df_inherit")) {
583 if (!strcmp(node->value, "true")) {
584 flags |= TNL_F_DF_INHERIT;
586 } else if (!strcmp(node->key, "df_default")) {
587 if (!strcmp(node->value, "false")) {
588 flags &= ~TNL_F_DF_DEFAULT;
590 } else if (!strcmp(node->key, "pmtud")) {
591 if (!strcmp(node->value, "true")) {
592 VLOG_WARN_ONCE("%s: The tunnel Path MTU discovery is "
593 "deprecated and may be removed in February "
594 "2013. Please email dev@openvswitch.org with "
596 flags |= TNL_F_PMTUD;
598 } else if (!strcmp(node->key, "peer_cert") && is_ipsec) {
599 if (smap_get(args, "certificate")) {
600 ipsec_mech_set = true;
602 const char *use_ssl_cert;
604 /* If the "use_ssl_cert" is true, then "certificate" and
605 * "private_key" will be pulled from the SSL table. The
606 * use of this option is strongly discouraged, since it
607 * will like be removed when multiple SSL configurations
608 * are supported by OVS.
610 use_ssl_cert = smap_get(args, "use_ssl_cert");
611 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
612 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
616 ipsec_mech_set = true;
618 } else if (!strcmp(node->key, "psk") && is_ipsec) {
619 ipsec_mech_set = true;
621 && (!strcmp(node->key, "certificate")
622 || !strcmp(node->key, "private_key")
623 || !strcmp(node->key, "use_ssl_cert"))) {
624 /* Ignore options not used by the netdev. */
625 } else if (!strcmp(node->key, "key") ||
626 !strcmp(node->key, "in_key") ||
627 !strcmp(node->key, "out_key")) {
628 /* Handled separately below. */
630 VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->key);
634 /* Add a default destination port for VXLAN if none specified. */
635 if (needs_dst_port && !found_dst_port) {
636 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT, VXLAN_DST_PORT);
640 static pid_t pid = 0;
642 char *file_name = xasprintf("%s/%s", ovs_rundir(),
643 "ovs-monitor-ipsec.pid");
644 pid = read_pidfile(file_name);
649 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
654 if (smap_get(args, "peer_cert") && smap_get(args, "psk")) {
655 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name);
659 if (!ipsec_mech_set) {
660 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
666 set_key(args, "in_key", OVS_TUNNEL_ATTR_IN_KEY, options);
667 set_key(args, "out_key", OVS_TUNNEL_ATTR_OUT_KEY, options);
670 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
674 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_DST_IPV4, daddr);
677 if (ip_is_multicast(daddr)) {
678 VLOG_WARN("%s: remote_ip is multicast, ignoring local_ip", name);
680 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_SRC_IPV4, saddr);
684 nl_msg_put_u32(options, OVS_TUNNEL_ATTR_FLAGS, flags);
690 tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len,
691 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1])
693 static const struct nl_policy ovs_tunnel_policy[] = {
694 [OVS_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32, .optional = true },
695 [OVS_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32, .optional = true },
696 [OVS_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true },
697 [OVS_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true },
698 [OVS_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true },
699 [OVS_TUNNEL_ATTR_TOS] = { .type = NL_A_U8, .optional = true },
700 [OVS_TUNNEL_ATTR_TTL] = { .type = NL_A_U8, .optional = true },
701 [OVS_TUNNEL_ATTR_DST_PORT] = { .type = NL_A_U16, .optional = true },
705 ofpbuf_use_const(&buf, options, options_len);
706 if (!nl_policy_parse(&buf, 0, ovs_tunnel_policy,
707 a, ARRAY_SIZE(ovs_tunnel_policy))) {
714 get_be64_or_zero(const struct nlattr *a)
716 return a ? ntohll(nl_attr_get_be64(a)) : 0;
720 unparse_tunnel_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
721 const struct nlattr *options, size_t options_len,
724 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
728 error = tnl_port_config_from_nlattr(options, options_len, a);
733 if (a[OVS_TUNNEL_ATTR_DST_IPV4]) {
734 ovs_be32 daddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
735 smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(daddr));
738 if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) {
739 ovs_be32 saddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_SRC_IPV4]);
740 smap_add_format(args, "local_ip", IP_FMT, IP_ARGS(saddr));
743 if (!a[OVS_TUNNEL_ATTR_IN_KEY] && !a[OVS_TUNNEL_ATTR_OUT_KEY]) {
744 smap_add(args, "key", "flow");
746 uint64_t in_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_IN_KEY]);
747 uint64_t out_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_OUT_KEY]);
749 if (in_key && in_key == out_key) {
750 smap_add_format(args, "key", "%"PRIu64, in_key);
752 if (!a[OVS_TUNNEL_ATTR_IN_KEY]) {
753 smap_add(args, "in_key", "flow");
755 smap_add_format(args, "in_key", "%"PRIu64, in_key);
758 if (!a[OVS_TUNNEL_ATTR_OUT_KEY]) {
759 smap_add(args, "out_key", "flow");
760 } else if (out_key) {
761 smap_add_format(args, "out_key", "%"PRIu64, out_key);
766 flags = get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]);
768 if (flags & TNL_F_TTL_INHERIT) {
769 smap_add(args, "ttl", "inherit");
770 } else if (a[OVS_TUNNEL_ATTR_TTL]) {
771 int ttl = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TTL]);
772 smap_add_format(args, "ttl", "%d", ttl);
775 if (flags & TNL_F_TOS_INHERIT) {
776 smap_add(args, "tos", "inherit");
777 } else if (a[OVS_TUNNEL_ATTR_TOS]) {
778 int tos = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TOS]);
779 smap_add_format(args, "tos", "0x%x", tos);
782 if (a[OVS_TUNNEL_ATTR_DST_PORT]) {
783 uint16_t dst_port = nl_attr_get_u16(a[OVS_TUNNEL_ATTR_DST_PORT]);
784 if (dst_port != VXLAN_DST_PORT) {
785 smap_add_format(args, "dst_port", "%d", dst_port);
789 if (flags & TNL_F_CSUM) {
790 smap_add(args, "csum", "true");
792 if (flags & TNL_F_DF_INHERIT) {
793 smap_add(args, "df_inherit", "true");
795 if (!(flags & TNL_F_DF_DEFAULT)) {
796 smap_add(args, "df_default", "false");
798 if (flags & TNL_F_PMTUD) {
799 smap_add(args, "pmtud", "true");
806 parse_patch_config(const char *name, const char *type OVS_UNUSED,
807 const struct smap *args, struct ofpbuf *options)
811 peer = smap_get(args, "peer");
813 VLOG_ERR("%s: patch type requires valid 'peer' argument", name);
817 if (smap_count(args) > 1) {
818 VLOG_ERR("%s: patch type takes only a 'peer' argument", name);
822 if (strlen(peer) >= IFNAMSIZ) {
823 VLOG_ERR("%s: patch 'peer' arg too long", name);
827 if (!strcmp(name, peer)) {
828 VLOG_ERR("%s: patch peer must not be self", name);
832 nl_msg_put_string(options, OVS_PATCH_ATTR_PEER, peer);
838 unparse_patch_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
839 const struct nlattr *options, size_t options_len,
842 static const struct nl_policy ovs_patch_policy[] = {
843 [OVS_PATCH_ATTR_PEER] = { .type = NL_A_STRING,
848 struct nlattr *a[ARRAY_SIZE(ovs_patch_policy)];
851 ofpbuf_use_const(&buf, options, options_len);
852 if (!nl_policy_parse(&buf, 0, ovs_patch_policy,
853 a, ARRAY_SIZE(ovs_patch_policy))) {
857 smap_add(args, "peer", nl_attr_get_string(a[OVS_PATCH_ATTR_PEER]));
861 #define VPORT_FUNCTIONS(GET_STATUS) \
866 netdev_vport_create, \
867 netdev_vport_destroy, \
868 netdev_vport_get_config, \
869 netdev_vport_set_config, \
872 netdev_vport_close, \
876 NULL, /* recv_wait */ \
880 NULL, /* send_wait */ \
882 netdev_vport_set_etheraddr, \
883 netdev_vport_get_etheraddr, \
884 NULL, /* get_mtu */ \
885 NULL, /* set_mtu */ \
886 NULL, /* get_ifindex */ \
887 NULL, /* get_carrier */ \
888 NULL, /* get_carrier_resets */ \
889 NULL, /* get_miimon */ \
890 netdev_vport_get_stats, \
891 NULL, /* set_stats */ \
893 NULL, /* get_features */ \
894 NULL, /* set_advertisements */ \
896 NULL, /* set_policing */ \
897 NULL, /* get_qos_types */ \
898 NULL, /* get_qos_capabilities */ \
899 NULL, /* get_qos */ \
900 NULL, /* set_qos */ \
901 NULL, /* get_queue */ \
902 NULL, /* set_queue */ \
903 NULL, /* delete_queue */ \
904 NULL, /* get_queue_stats */ \
905 NULL, /* dump_queues */ \
906 NULL, /* dump_queue_stats */ \
908 NULL, /* get_in4 */ \
909 NULL, /* set_in4 */ \
910 NULL, /* get_in6 */ \
911 NULL, /* add_router */ \
912 NULL, /* get_next_hop */ \
914 NULL, /* arp_lookup */ \
916 netdev_vport_update_flags, \
918 netdev_vport_change_seq
921 netdev_vport_register(void)
923 static const struct vport_class vport_classes[] = {
924 { OVS_VPORT_TYPE_GRE,
925 { "gre", VPORT_FUNCTIONS(tunnel_get_status) },
926 parse_tunnel_config, unparse_tunnel_config },
928 { OVS_VPORT_TYPE_GRE,
929 { "ipsec_gre", VPORT_FUNCTIONS(tunnel_get_status) },
930 parse_tunnel_config, unparse_tunnel_config },
932 { OVS_VPORT_TYPE_GRE64,
933 { "gre64", VPORT_FUNCTIONS(tunnel_get_status) },
934 parse_tunnel_config, unparse_tunnel_config },
936 { OVS_VPORT_TYPE_GRE64,
937 { "ipsec_gre64", VPORT_FUNCTIONS(tunnel_get_status) },
938 parse_tunnel_config, unparse_tunnel_config },
940 { OVS_VPORT_TYPE_CAPWAP,
941 { "capwap", VPORT_FUNCTIONS(tunnel_get_status) },
942 parse_tunnel_config, unparse_tunnel_config },
944 { OVS_VPORT_TYPE_VXLAN,
945 { "vxlan", VPORT_FUNCTIONS(tunnel_get_status) },
946 parse_tunnel_config, unparse_tunnel_config },
948 { OVS_VPORT_TYPE_PATCH,
949 { "patch", VPORT_FUNCTIONS(NULL) },
950 parse_patch_config, unparse_patch_config }
955 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
956 netdev_register_provider(&vport_classes[i].netdev_class);