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;
59 uint8_t etheraddr[ETH_ADDR_LEN];
67 enum ovs_vport_type type;
68 struct netdev_class netdev_class;
69 int (*parse_config)(const char *name, const char *type,
70 const struct smap *args, struct ofpbuf *options);
71 int (*unparse_config)(const char *name, const char *type,
72 const struct nlattr *options, size_t options_len,
76 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
78 static int netdev_vport_create(const struct netdev_class *, const char *,
79 struct netdev_dev **);
80 static void netdev_vport_poll_notify(const struct netdev *);
81 static int tnl_port_config_from_nlattr(const struct nlattr *options,
83 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1]);
86 is_vport_class(const struct netdev_class *class)
88 return class->create == netdev_vport_create;
91 static const struct vport_class *
92 vport_class_cast(const struct netdev_class *class)
94 assert(is_vport_class(class));
95 return CONTAINER_OF(class, struct vport_class, netdev_class);
98 static struct netdev_dev_vport *
99 netdev_dev_vport_cast(const struct netdev_dev *netdev_dev)
101 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
102 return CONTAINER_OF(netdev_dev, struct netdev_dev_vport, netdev_dev);
105 static struct netdev_dev_vport *
106 netdev_vport_get_dev(const struct netdev *netdev)
108 return netdev_dev_vport_cast(netdev_get_dev(netdev));
111 static struct netdev_vport *
112 netdev_vport_cast(const struct netdev *netdev)
114 struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
115 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
116 return CONTAINER_OF(netdev, struct netdev_vport, netdev);
119 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
120 * options to include in OVS_VPORT_ATTR_OPTIONS for configuring that vport.
121 * Otherwise returns NULL. */
122 const struct ofpbuf *
123 netdev_vport_get_options(const struct netdev *netdev)
125 const struct netdev_dev *dev = netdev_get_dev(netdev);
127 return (is_vport_class(netdev_dev_get_class(dev))
128 ? netdev_dev_vport_cast(dev)->options
133 netdev_vport_get_vport_type(const struct netdev *netdev)
135 const struct netdev_dev *dev = netdev_get_dev(netdev);
136 const struct netdev_class *class = netdev_dev_get_class(dev);
138 return (is_vport_class(class) ? vport_class_cast(class)->type
139 : class == &netdev_internal_class ? OVS_VPORT_TYPE_INTERNAL
140 : (class == &netdev_linux_class ||
141 class == &netdev_tap_class) ? OVS_VPORT_TYPE_NETDEV
142 : OVS_VPORT_TYPE_UNSPEC);
146 get_u32_or_zero(const struct nlattr *a)
148 return a ? nl_attr_get_u32(a) : 0;
152 netdev_vport_get_netdev_type(const struct dpif_linux_vport *vport)
154 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
156 switch (vport->type) {
157 case OVS_VPORT_TYPE_UNSPEC:
160 case OVS_VPORT_TYPE_NETDEV:
163 case OVS_VPORT_TYPE_INTERNAL:
166 case OVS_VPORT_TYPE_PATCH:
169 case OVS_VPORT_TYPE_GRE:
170 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
174 return (get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
175 ? "ipsec_gre" : "gre");
177 case OVS_VPORT_TYPE_GRE64:
178 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
182 return (get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
183 ? "ipsec_gre64" : "gre64");
185 case OVS_VPORT_TYPE_CAPWAP:
188 case OVS_VPORT_TYPE_VXLAN:
191 case OVS_VPORT_TYPE_FT_GRE:
192 case __OVS_VPORT_TYPE_MAX:
196 VLOG_WARN_RL(&rl, "dp%d: port `%s' has unsupported type %u",
197 vport->dp_ifindex, vport->name, (unsigned int) vport->type);
202 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
203 struct netdev_dev **netdev_devp)
205 struct netdev_dev_vport *dev;
207 dev = xmalloc(sizeof *dev);
208 netdev_dev_init(&dev->netdev_dev, name, netdev_class);
211 eth_addr_random(dev->etheraddr);
213 *netdev_devp = &dev->netdev_dev;
214 route_table_register();
220 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
222 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
224 ofpbuf_delete(netdev_dev->options);
225 route_table_unregister();
230 netdev_vport_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp)
232 struct netdev_vport *netdev;
234 netdev = xmalloc(sizeof *netdev);
235 netdev_init(&netdev->netdev, netdev_dev_);
237 *netdevp = &netdev->netdev;
242 netdev_vport_close(struct netdev *netdev_)
244 struct netdev_vport *netdev = netdev_vport_cast(netdev_);
249 netdev_vport_get_config(struct netdev_dev *dev_, struct smap *args)
251 const struct netdev_class *netdev_class = netdev_dev_get_class(dev_);
252 const struct vport_class *vport_class = vport_class_cast(netdev_class);
253 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
254 const char *name = netdev_dev_get_name(dev_);
258 struct dpif_linux_vport reply;
261 error = dpif_linux_vport_get(name, &reply, &buf);
263 VLOG_ERR_RL(&rl, "%s: vport query failed (%s)",
264 name, strerror(error));
268 dev->options = ofpbuf_clone_data(reply.options, reply.options_len);
272 error = vport_class->unparse_config(name, netdev_class->type,
277 VLOG_ERR_RL(&rl, "%s: failed to parse kernel config (%s)",
278 name, strerror(error));
284 netdev_vport_set_config(struct netdev_dev *dev_, const struct smap *args)
286 const struct netdev_class *netdev_class = netdev_dev_get_class(dev_);
287 const struct vport_class *vport_class = vport_class_cast(netdev_class);
288 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
289 const char *name = netdev_dev_get_name(dev_);
290 struct ofpbuf *options;
293 options = ofpbuf_new(64);
294 error = vport_class->parse_config(name, netdev_dev_get_type(dev_),
298 || options->size != dev->options->size
299 || memcmp(options->data, dev->options->data, options->size))) {
300 struct dpif_linux_vport vport;
302 dpif_linux_vport_init(&vport);
303 vport.cmd = OVS_VPORT_CMD_SET;
305 vport.options = options->data;
306 vport.options_len = options->size;
307 error = dpif_linux_vport_transact(&vport, NULL, NULL);
308 if (!error || error == ENODEV) {
309 /* Either reconfiguration succeeded or this vport is not installed
310 * in the kernel (e.g. it hasn't been added to a dpif yet with
311 * dpif_port_add()). */
312 ofpbuf_delete(dev->options);
313 dev->options = options;
318 ofpbuf_delete(options);
324 netdev_vport_set_etheraddr(struct netdev *netdev,
325 const uint8_t mac[ETH_ADDR_LEN])
327 memcpy(netdev_vport_get_dev(netdev)->etheraddr, mac, ETH_ADDR_LEN);
328 netdev_vport_poll_notify(netdev);
333 netdev_vport_get_etheraddr(const struct netdev *netdev,
334 uint8_t mac[ETH_ADDR_LEN])
336 memcpy(mac, netdev_vport_get_dev(netdev)->etheraddr, ETH_ADDR_LEN);
340 /* Copies 'src' into 'dst', performing format conversion in the process.
342 * 'src' is allowed to be misaligned. */
344 netdev_stats_from_ovs_vport_stats(struct netdev_stats *dst,
345 const struct ovs_vport_stats *src)
347 dst->rx_packets = get_unaligned_u64(&src->rx_packets);
348 dst->tx_packets = get_unaligned_u64(&src->tx_packets);
349 dst->rx_bytes = get_unaligned_u64(&src->rx_bytes);
350 dst->tx_bytes = get_unaligned_u64(&src->tx_bytes);
351 dst->rx_errors = get_unaligned_u64(&src->rx_errors);
352 dst->tx_errors = get_unaligned_u64(&src->tx_errors);
353 dst->rx_dropped = get_unaligned_u64(&src->rx_dropped);
354 dst->tx_dropped = get_unaligned_u64(&src->tx_dropped);
357 dst->rx_length_errors = 0;
358 dst->rx_over_errors = 0;
359 dst->rx_crc_errors = 0;
360 dst->rx_frame_errors = 0;
361 dst->rx_fifo_errors = 0;
362 dst->rx_missed_errors = 0;
363 dst->tx_aborted_errors = 0;
364 dst->tx_carrier_errors = 0;
365 dst->tx_fifo_errors = 0;
366 dst->tx_heartbeat_errors = 0;
367 dst->tx_window_errors = 0;
371 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
373 struct dpif_linux_vport reply;
377 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
380 } else if (!reply.stats) {
385 netdev_stats_from_ovs_vport_stats(stats, reply.stats);
393 tunnel_get_status(const struct netdev *netdev, struct smap *smap)
395 struct netdev_dev_vport *ndv = netdev_vport_get_dev(netdev);
396 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
397 static char iface[IFNAMSIZ];
401 /* Race condition when 'ndv' was created, but did not have it's
402 * configuration set yet. */
406 if (tnl_port_config_from_nlattr(ndv->options->data,
407 ndv->options->size, a)) {
410 route = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
412 if (route_table_get_name(route, iface)) {
413 struct netdev *egress_netdev;
415 smap_add(smap, "tunnel_egress_iface", iface);
417 if (!netdev_open(iface, "system", &egress_netdev)) {
418 smap_add(smap, "tunnel_egress_iface_carrier",
419 netdev_get_carrier(egress_netdev) ? "up" : "down");
420 netdev_close(egress_netdev);
428 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
429 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
430 enum netdev_flags *old_flagsp)
432 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
436 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
441 netdev_vport_change_seq(const struct netdev *netdev)
443 return netdev_vport_get_dev(netdev)->change_seq;
447 netdev_vport_run(void)
453 netdev_vport_wait(void)
458 /* Helper functions. */
461 netdev_vport_poll_notify(const struct netdev *netdev)
463 struct netdev_dev_vport *ndv = netdev_vport_get_dev(netdev);
466 if (!ndv->change_seq) {
471 /* Code specific to individual vport types. */
474 set_key(const struct smap *args, const char *name, uint16_t type,
475 struct ofpbuf *options)
479 s = smap_get(args, name);
481 s = smap_get(args, "key");
487 if (!strcmp(s, "flow")) {
488 /* This is the default if no attribute is present. */
490 nl_msg_put_be64(options, type, htonll(strtoull(s, NULL, 0)));
495 parse_tunnel_config(const char *name, const char *type,
496 const struct smap *args, struct ofpbuf *options)
499 bool is_ipsec = false;
500 bool needs_dst_port = false;
501 bool found_dst_port = false;
502 struct smap_node *node;
503 bool ipsec_mech_set = false;
504 ovs_be32 daddr = htonl(0);
505 ovs_be32 saddr = htonl(0);
508 if (!strcmp(type, "capwap")) {
509 VLOG_WARN_ONCE("CAPWAP tunnel support is deprecated.");
512 flags = TNL_F_DF_DEFAULT;
513 if (!strcmp(type, "gre") || !strcmp(type, "gre64")) {
515 } else if (!strcmp(type, "ipsec_gre") || !strcmp(type, "ipsec_gre64")) {
518 flags |= TNL_F_IPSEC;
519 } else if (!strcmp(type, "vxlan")) {
520 needs_dst_port = true;
523 SMAP_FOR_EACH (node, args) {
524 if (!strcmp(node->key, "remote_ip")) {
525 struct in_addr in_addr;
526 if (lookup_ip(node->value, &in_addr)) {
527 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
529 daddr = in_addr.s_addr;
531 } else if (!strcmp(node->key, "local_ip")) {
532 struct in_addr in_addr;
533 if (lookup_ip(node->value, &in_addr)) {
534 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
536 saddr = in_addr.s_addr;
538 } else if (!strcmp(node->key, "tos")) {
539 if (!strcmp(node->value, "inherit")) {
540 flags |= TNL_F_TOS_INHERIT;
544 tos = strtol(node->value, &endptr, 0);
545 if (*endptr == '\0' && tos == (tos & IP_DSCP_MASK)) {
546 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TOS, tos);
548 VLOG_WARN("%s: invalid TOS %s", name, node->value);
551 } else if (!strcmp(node->key, "ttl")) {
552 if (!strcmp(node->value, "inherit")) {
553 flags |= TNL_F_TTL_INHERIT;
555 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TTL, atoi(node->value));
557 } else if (!strcmp(node->key, "dst_port") && needs_dst_port) {
558 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT,
560 found_dst_port = true;
561 } else if (!strcmp(node->key, "csum") && is_gre) {
562 if (!strcmp(node->value, "true")) {
565 } else if (!strcmp(node->key, "df_inherit")) {
566 if (!strcmp(node->value, "true")) {
567 flags |= TNL_F_DF_INHERIT;
569 } else if (!strcmp(node->key, "df_default")) {
570 if (!strcmp(node->value, "false")) {
571 flags &= ~TNL_F_DF_DEFAULT;
573 } else if (!strcmp(node->key, "peer_cert") && is_ipsec) {
574 if (smap_get(args, "certificate")) {
575 ipsec_mech_set = true;
577 const char *use_ssl_cert;
579 /* If the "use_ssl_cert" is true, then "certificate" and
580 * "private_key" will be pulled from the SSL table. The
581 * use of this option is strongly discouraged, since it
582 * will like be removed when multiple SSL configurations
583 * are supported by OVS.
585 use_ssl_cert = smap_get(args, "use_ssl_cert");
586 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
587 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
591 ipsec_mech_set = true;
593 } else if (!strcmp(node->key, "psk") && is_ipsec) {
594 ipsec_mech_set = true;
596 && (!strcmp(node->key, "certificate")
597 || !strcmp(node->key, "private_key")
598 || !strcmp(node->key, "use_ssl_cert"))) {
599 /* Ignore options not used by the netdev. */
600 } else if (!strcmp(node->key, "key") ||
601 !strcmp(node->key, "in_key") ||
602 !strcmp(node->key, "out_key")) {
603 /* Handled separately below. */
605 VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->key);
609 /* Add a default destination port for VXLAN if none specified. */
610 if (needs_dst_port && !found_dst_port) {
611 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT, VXLAN_DST_PORT);
615 static pid_t pid = 0;
617 char *file_name = xasprintf("%s/%s", ovs_rundir(),
618 "ovs-monitor-ipsec.pid");
619 pid = read_pidfile(file_name);
624 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
629 if (smap_get(args, "peer_cert") && smap_get(args, "psk")) {
630 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name);
634 if (!ipsec_mech_set) {
635 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
641 set_key(args, "in_key", OVS_TUNNEL_ATTR_IN_KEY, options);
642 set_key(args, "out_key", OVS_TUNNEL_ATTR_OUT_KEY, options);
645 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
649 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_DST_IPV4, daddr);
652 if (ip_is_multicast(daddr)) {
653 VLOG_WARN("%s: remote_ip is multicast, ignoring local_ip", name);
655 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_SRC_IPV4, saddr);
659 nl_msg_put_u32(options, OVS_TUNNEL_ATTR_FLAGS, flags);
665 tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len,
666 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1])
668 static const struct nl_policy ovs_tunnel_policy[] = {
669 [OVS_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32, .optional = true },
670 [OVS_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32, .optional = true },
671 [OVS_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true },
672 [OVS_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true },
673 [OVS_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true },
674 [OVS_TUNNEL_ATTR_TOS] = { .type = NL_A_U8, .optional = true },
675 [OVS_TUNNEL_ATTR_TTL] = { .type = NL_A_U8, .optional = true },
676 [OVS_TUNNEL_ATTR_DST_PORT] = { .type = NL_A_U16, .optional = true },
680 ofpbuf_use_const(&buf, options, options_len);
681 if (!nl_policy_parse(&buf, 0, ovs_tunnel_policy,
682 a, ARRAY_SIZE(ovs_tunnel_policy))) {
689 get_be64_or_zero(const struct nlattr *a)
691 return a ? ntohll(nl_attr_get_be64(a)) : 0;
695 unparse_tunnel_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
696 const struct nlattr *options, size_t options_len,
699 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
703 error = tnl_port_config_from_nlattr(options, options_len, a);
708 if (a[OVS_TUNNEL_ATTR_DST_IPV4]) {
709 ovs_be32 daddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
710 smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(daddr));
713 if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) {
714 ovs_be32 saddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_SRC_IPV4]);
715 smap_add_format(args, "local_ip", IP_FMT, IP_ARGS(saddr));
718 if (!a[OVS_TUNNEL_ATTR_IN_KEY] && !a[OVS_TUNNEL_ATTR_OUT_KEY]) {
719 smap_add(args, "key", "flow");
721 uint64_t in_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_IN_KEY]);
722 uint64_t out_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_OUT_KEY]);
724 if (in_key && in_key == out_key) {
725 smap_add_format(args, "key", "%"PRIu64, in_key);
727 if (!a[OVS_TUNNEL_ATTR_IN_KEY]) {
728 smap_add(args, "in_key", "flow");
730 smap_add_format(args, "in_key", "%"PRIu64, in_key);
733 if (!a[OVS_TUNNEL_ATTR_OUT_KEY]) {
734 smap_add(args, "out_key", "flow");
735 } else if (out_key) {
736 smap_add_format(args, "out_key", "%"PRIu64, out_key);
741 flags = get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]);
743 if (flags & TNL_F_TTL_INHERIT) {
744 smap_add(args, "ttl", "inherit");
745 } else if (a[OVS_TUNNEL_ATTR_TTL]) {
746 int ttl = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TTL]);
747 smap_add_format(args, "ttl", "%d", ttl);
750 if (flags & TNL_F_TOS_INHERIT) {
751 smap_add(args, "tos", "inherit");
752 } else if (a[OVS_TUNNEL_ATTR_TOS]) {
753 int tos = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TOS]);
754 smap_add_format(args, "tos", "0x%x", tos);
757 if (a[OVS_TUNNEL_ATTR_DST_PORT]) {
758 uint16_t dst_port = nl_attr_get_u16(a[OVS_TUNNEL_ATTR_DST_PORT]);
759 if (dst_port != VXLAN_DST_PORT) {
760 smap_add_format(args, "dst_port", "%d", dst_port);
764 if (flags & TNL_F_CSUM) {
765 smap_add(args, "csum", "true");
767 if (flags & TNL_F_DF_INHERIT) {
768 smap_add(args, "df_inherit", "true");
770 if (!(flags & TNL_F_DF_DEFAULT)) {
771 smap_add(args, "df_default", "false");
778 parse_patch_config(const char *name, const char *type OVS_UNUSED,
779 const struct smap *args, struct ofpbuf *options)
783 peer = smap_get(args, "peer");
785 VLOG_ERR("%s: patch type requires valid 'peer' argument", name);
789 if (smap_count(args) > 1) {
790 VLOG_ERR("%s: patch type takes only a 'peer' argument", name);
794 if (strlen(peer) >= IFNAMSIZ) {
795 VLOG_ERR("%s: patch 'peer' arg too long", name);
799 if (!strcmp(name, peer)) {
800 VLOG_ERR("%s: patch peer must not be self", name);
804 nl_msg_put_string(options, OVS_PATCH_ATTR_PEER, peer);
810 unparse_patch_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
811 const struct nlattr *options, size_t options_len,
814 static const struct nl_policy ovs_patch_policy[] = {
815 [OVS_PATCH_ATTR_PEER] = { .type = NL_A_STRING,
820 struct nlattr *a[ARRAY_SIZE(ovs_patch_policy)];
823 ofpbuf_use_const(&buf, options, options_len);
824 if (!nl_policy_parse(&buf, 0, ovs_patch_policy,
825 a, ARRAY_SIZE(ovs_patch_policy))) {
829 smap_add(args, "peer", nl_attr_get_string(a[OVS_PATCH_ATTR_PEER]));
833 #define VPORT_FUNCTIONS(GET_STATUS) \
838 netdev_vport_create, \
839 netdev_vport_destroy, \
840 netdev_vport_get_config, \
841 netdev_vport_set_config, \
844 netdev_vport_close, \
848 NULL, /* recv_wait */ \
852 NULL, /* send_wait */ \
854 netdev_vport_set_etheraddr, \
855 netdev_vport_get_etheraddr, \
856 NULL, /* get_mtu */ \
857 NULL, /* set_mtu */ \
858 NULL, /* get_ifindex */ \
859 NULL, /* get_carrier */ \
860 NULL, /* get_carrier_resets */ \
861 NULL, /* get_miimon */ \
862 netdev_vport_get_stats, \
863 NULL, /* set_stats */ \
865 NULL, /* get_features */ \
866 NULL, /* set_advertisements */ \
868 NULL, /* set_policing */ \
869 NULL, /* get_qos_types */ \
870 NULL, /* get_qos_capabilities */ \
871 NULL, /* get_qos */ \
872 NULL, /* set_qos */ \
873 NULL, /* get_queue */ \
874 NULL, /* set_queue */ \
875 NULL, /* delete_queue */ \
876 NULL, /* get_queue_stats */ \
877 NULL, /* dump_queues */ \
878 NULL, /* dump_queue_stats */ \
880 NULL, /* get_in4 */ \
881 NULL, /* set_in4 */ \
882 NULL, /* get_in6 */ \
883 NULL, /* add_router */ \
884 NULL, /* get_next_hop */ \
886 NULL, /* arp_lookup */ \
888 netdev_vport_update_flags, \
890 netdev_vport_change_seq
893 netdev_vport_register(void)
895 static const struct vport_class vport_classes[] = {
896 { OVS_VPORT_TYPE_GRE,
897 { "gre", VPORT_FUNCTIONS(tunnel_get_status) },
898 parse_tunnel_config, unparse_tunnel_config },
900 { OVS_VPORT_TYPE_GRE,
901 { "ipsec_gre", VPORT_FUNCTIONS(tunnel_get_status) },
902 parse_tunnel_config, unparse_tunnel_config },
904 { OVS_VPORT_TYPE_GRE64,
905 { "gre64", VPORT_FUNCTIONS(tunnel_get_status) },
906 parse_tunnel_config, unparse_tunnel_config },
908 { OVS_VPORT_TYPE_GRE64,
909 { "ipsec_gre64", VPORT_FUNCTIONS(tunnel_get_status) },
910 parse_tunnel_config, unparse_tunnel_config },
912 { OVS_VPORT_TYPE_CAPWAP,
913 { "capwap", VPORT_FUNCTIONS(tunnel_get_status) },
914 parse_tunnel_config, unparse_tunnel_config },
916 { OVS_VPORT_TYPE_VXLAN,
917 { "vxlan", VPORT_FUNCTIONS(tunnel_get_status) },
918 parse_tunnel_config, unparse_tunnel_config },
920 { OVS_VPORT_TYPE_PATCH,
921 { "patch", VPORT_FUNCTIONS(NULL) },
922 parse_patch_config, unparse_patch_config }
927 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
928 netdev_register_provider(&vport_classes[i].netdev_class);