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 int get_patch_config(struct netdev_dev *, struct smap *args);
82 static void netdev_vport_poll_notify(const struct netdev *);
83 static int tnl_port_config_from_nlattr(const struct nlattr *options,
85 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1]);
88 is_vport_class(const struct netdev_class *class)
90 return class->create == netdev_vport_create;
93 static const struct vport_class *
94 vport_class_cast(const struct netdev_class *class)
96 ovs_assert(is_vport_class(class));
97 return CONTAINER_OF(class, struct vport_class, netdev_class);
100 static struct netdev_dev_vport *
101 netdev_dev_vport_cast(const struct netdev_dev *netdev_dev)
103 ovs_assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
104 return CONTAINER_OF(netdev_dev, struct netdev_dev_vport, netdev_dev);
107 static struct netdev_dev_vport *
108 netdev_vport_get_dev(const struct netdev *netdev)
110 return netdev_dev_vport_cast(netdev_get_dev(netdev));
113 static const struct netdev_tunnel_config *
114 get_netdev_tunnel_config(const struct netdev_dev *netdev_dev)
116 return &netdev_dev_vport_cast(netdev_dev)->tnl_cfg;
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 netdev_vport_is_patch(const struct netdev *netdev)
148 const struct netdev_dev *dev = netdev_get_dev(netdev);
149 const struct netdev_class *class = netdev_dev_get_class(dev);
151 return class->get_config == get_patch_config;
155 netdev_vport_get_dpif_port(const struct netdev *netdev)
157 return netdev_get_name(netdev);
161 get_u32_or_zero(const struct nlattr *a)
163 return a ? nl_attr_get_u32(a) : 0;
167 netdev_vport_get_netdev_type(const struct dpif_linux_vport *vport)
169 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
171 switch (vport->type) {
172 case OVS_VPORT_TYPE_UNSPEC:
175 case OVS_VPORT_TYPE_NETDEV:
178 case OVS_VPORT_TYPE_INTERNAL:
181 case OVS_VPORT_TYPE_GRE:
182 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
186 return (get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
187 ? "ipsec_gre" : "gre");
189 case OVS_VPORT_TYPE_GRE64:
190 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
194 return (get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
195 ? "ipsec_gre64" : "gre64");
197 case OVS_VPORT_TYPE_CAPWAP:
200 case OVS_VPORT_TYPE_VXLAN:
203 case __OVS_VPORT_TYPE_MAX:
207 VLOG_WARN_RL(&rl, "dp%d: port `%s' has unsupported type %u",
208 vport->dp_ifindex, vport->name, (unsigned int) vport->type);
213 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
214 struct netdev_dev **netdev_devp)
216 struct netdev_dev_vport *dev;
218 dev = xzalloc(sizeof *dev);
219 netdev_dev_init(&dev->netdev_dev, name, netdev_class);
221 eth_addr_random(dev->etheraddr);
223 *netdev_devp = &dev->netdev_dev;
224 route_table_register();
230 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
232 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
234 ofpbuf_delete(netdev_dev->options);
235 route_table_unregister();
236 free(netdev_dev->peer);
241 netdev_vport_open(struct netdev_dev *netdev_dev, struct netdev **netdevp)
243 *netdevp = xmalloc(sizeof **netdevp);
244 netdev_init(*netdevp, netdev_dev);
249 netdev_vport_close(struct netdev *netdev)
255 netdev_vport_set_etheraddr(struct netdev *netdev,
256 const uint8_t mac[ETH_ADDR_LEN])
258 memcpy(netdev_vport_get_dev(netdev)->etheraddr, mac, ETH_ADDR_LEN);
259 netdev_vport_poll_notify(netdev);
264 netdev_vport_get_etheraddr(const struct netdev *netdev,
265 uint8_t mac[ETH_ADDR_LEN])
267 memcpy(mac, netdev_vport_get_dev(netdev)->etheraddr, ETH_ADDR_LEN);
271 /* Copies 'src' into 'dst', performing format conversion in the process.
273 * 'src' is allowed to be misaligned. */
275 netdev_stats_from_ovs_vport_stats(struct netdev_stats *dst,
276 const struct ovs_vport_stats *src)
278 dst->rx_packets = get_unaligned_u64(&src->rx_packets);
279 dst->tx_packets = get_unaligned_u64(&src->tx_packets);
280 dst->rx_bytes = get_unaligned_u64(&src->rx_bytes);
281 dst->tx_bytes = get_unaligned_u64(&src->tx_bytes);
282 dst->rx_errors = get_unaligned_u64(&src->rx_errors);
283 dst->tx_errors = get_unaligned_u64(&src->tx_errors);
284 dst->rx_dropped = get_unaligned_u64(&src->rx_dropped);
285 dst->tx_dropped = get_unaligned_u64(&src->tx_dropped);
288 dst->rx_length_errors = 0;
289 dst->rx_over_errors = 0;
290 dst->rx_crc_errors = 0;
291 dst->rx_frame_errors = 0;
292 dst->rx_fifo_errors = 0;
293 dst->rx_missed_errors = 0;
294 dst->tx_aborted_errors = 0;
295 dst->tx_carrier_errors = 0;
296 dst->tx_fifo_errors = 0;
297 dst->tx_heartbeat_errors = 0;
298 dst->tx_window_errors = 0;
302 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
304 struct dpif_linux_vport reply;
308 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
311 } else if (!reply.stats) {
316 netdev_stats_from_ovs_vport_stats(stats, reply.stats);
324 tunnel_get_status(const struct netdev *netdev, struct smap *smap)
326 static char iface[IFNAMSIZ];
329 route = netdev_vport_get_dev(netdev)->tnl_cfg.ip_dst;
330 if (route_table_get_name(route, iface)) {
331 struct netdev *egress_netdev;
333 smap_add(smap, "tunnel_egress_iface", iface);
335 if (!netdev_open(iface, "system", &egress_netdev)) {
336 smap_add(smap, "tunnel_egress_iface_carrier",
337 netdev_get_carrier(egress_netdev) ? "up" : "down");
338 netdev_close(egress_netdev);
346 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
347 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
348 enum netdev_flags *old_flagsp)
350 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
354 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
359 netdev_vport_change_seq(const struct netdev *netdev)
361 return netdev_vport_get_dev(netdev)->change_seq;
365 netdev_vport_run(void)
371 netdev_vport_wait(void)
376 /* Helper functions. */
379 netdev_vport_poll_notify(const struct netdev *netdev)
381 struct netdev_dev_vport *ndv = netdev_vport_get_dev(netdev);
384 if (!ndv->change_seq) {
389 /* Code specific to tunnel types. */
392 parse_key(const struct smap *args, const char *name,
393 bool *present, bool *flow)
400 s = smap_get(args, name);
402 s = smap_get(args, "key");
410 if (!strcmp(s, "flow")) {
414 return htonll(strtoull(s, NULL, 0));
419 set_tunnel_config(struct netdev_dev *dev_, const struct smap *args)
421 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
422 const char *name = netdev_dev_get_name(dev_);
423 const char *type = netdev_dev_get_type(dev_);
424 bool ipsec_mech_set, needs_dst_port, has_csum;
425 struct netdev_tunnel_config tnl_cfg;
426 struct smap_node *node;
427 struct ofpbuf *options;
431 flags = TNL_F_DF_DEFAULT;
432 has_csum = strstr(type, "gre");
433 ipsec_mech_set = false;
434 memset(&tnl_cfg, 0, sizeof tnl_cfg);
436 options = ofpbuf_new(64);
438 if (!strcmp(type, "capwap")) {
439 VLOG_WARN_ONCE("CAPWAP tunnel support is deprecated.");
442 needs_dst_port = !strcmp(type, "vxlan");
443 tnl_cfg.ipsec = strstr(type, "ipsec");
445 flags |= TNL_F_IPSEC;
447 tnl_cfg.dont_fragment = true;
449 SMAP_FOR_EACH (node, args) {
450 if (!strcmp(node->key, "remote_ip")) {
451 struct in_addr in_addr;
452 if (lookup_ip(node->value, &in_addr)) {
453 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
455 tnl_cfg.ip_dst = in_addr.s_addr;
457 } else if (!strcmp(node->key, "local_ip")) {
458 struct in_addr in_addr;
459 if (lookup_ip(node->value, &in_addr)) {
460 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
462 tnl_cfg.ip_src = in_addr.s_addr;
464 } else if (!strcmp(node->key, "tos")) {
465 if (!strcmp(node->value, "inherit")) {
466 flags |= TNL_F_TOS_INHERIT;
467 tnl_cfg.tos_inherit = true;
471 tos = strtol(node->value, &endptr, 0);
472 if (*endptr == '\0' && tos == (tos & IP_DSCP_MASK)) {
473 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TOS, tos);
476 VLOG_WARN("%s: invalid TOS %s", name, node->value);
479 } else if (!strcmp(node->key, "ttl")) {
480 if (!strcmp(node->value, "inherit")) {
481 flags |= TNL_F_TTL_INHERIT;
482 tnl_cfg.ttl_inherit = true;
484 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TTL, atoi(node->value));
485 tnl_cfg.ttl = atoi(node->value);
487 } else if (!strcmp(node->key, "dst_port") && needs_dst_port) {
488 tnl_cfg.dst_port = htons(atoi(node->value));
489 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT,
491 } else if (!strcmp(node->key, "csum") && has_csum) {
492 if (!strcmp(node->value, "true")) {
496 } else if (!strcmp(node->key, "df_default")) {
497 if (!strcmp(node->value, "false")) {
498 flags &= ~TNL_F_DF_DEFAULT;
499 tnl_cfg.dont_fragment = false;
501 } else if (!strcmp(node->key, "peer_cert") && tnl_cfg.ipsec) {
502 if (smap_get(args, "certificate")) {
503 ipsec_mech_set = true;
505 const char *use_ssl_cert;
507 /* If the "use_ssl_cert" is true, then "certificate" and
508 * "private_key" will be pulled from the SSL table. The
509 * use of this option is strongly discouraged, since it
510 * will like be removed when multiple SSL configurations
511 * are supported by OVS.
513 use_ssl_cert = smap_get(args, "use_ssl_cert");
514 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
515 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
519 ipsec_mech_set = true;
521 } else if (!strcmp(node->key, "psk") && tnl_cfg.ipsec) {
522 ipsec_mech_set = true;
523 } else if (tnl_cfg.ipsec
524 && (!strcmp(node->key, "certificate")
525 || !strcmp(node->key, "private_key")
526 || !strcmp(node->key, "use_ssl_cert"))) {
527 /* Ignore options not used by the netdev. */
528 } else if (!strcmp(node->key, "key") ||
529 !strcmp(node->key, "in_key") ||
530 !strcmp(node->key, "out_key")) {
531 /* Handled separately below. */
533 VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->key);
537 /* Add a default destination port for VXLAN if none specified. */
538 if (needs_dst_port && !tnl_cfg.dst_port) {
539 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT, VXLAN_DST_PORT);
540 tnl_cfg.dst_port = htons(VXLAN_DST_PORT);
544 static pid_t pid = 0;
546 char *file_name = xasprintf("%s/%s", ovs_rundir(),
547 "ovs-monitor-ipsec.pid");
548 pid = read_pidfile(file_name);
553 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
558 if (smap_get(args, "peer_cert") && smap_get(args, "psk")) {
559 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name);
563 if (!ipsec_mech_set) {
564 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
570 if (!tnl_cfg.ip_dst) {
571 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
575 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_DST_IPV4, tnl_cfg.ip_dst);
577 if (tnl_cfg.ip_src) {
578 if (ip_is_multicast(tnl_cfg.ip_dst)) {
579 VLOG_WARN("%s: remote_ip is multicast, ignoring local_ip", name);
582 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_SRC_IPV4, tnl_cfg.ip_src);
587 tnl_cfg.ttl = DEFAULT_TTL;
590 tnl_cfg.in_key = parse_key(args, "in_key",
591 &tnl_cfg.in_key_present,
592 &tnl_cfg.in_key_flow);
593 if (tnl_cfg.in_key_present && !tnl_cfg.in_key_flow) {
594 nl_msg_put_be64(options, OVS_TUNNEL_ATTR_IN_KEY, tnl_cfg.in_key);
597 tnl_cfg.out_key = parse_key(args, "out_key",
598 &tnl_cfg.out_key_present,
599 &tnl_cfg.out_key_flow);
600 if (tnl_cfg.out_key_present && !tnl_cfg.out_key_flow) {
601 nl_msg_put_be64(options, OVS_TUNNEL_ATTR_OUT_KEY, tnl_cfg.out_key);
603 nl_msg_put_u32(options, OVS_TUNNEL_ATTR_FLAGS, flags);
605 dev->tnl_cfg = tnl_cfg;
609 || options->size != dev->options->size
610 || memcmp(options->data, dev->options->data, options->size)) {
611 struct dpif_linux_vport vport;
613 dpif_linux_vport_init(&vport);
614 vport.cmd = OVS_VPORT_CMD_SET;
616 vport.options = options->data;
617 vport.options_len = options->size;
618 error = dpif_linux_vport_transact(&vport, NULL, NULL);
619 if (!error || error == ENODEV) {
620 /* Either reconfiguration succeeded or this vport is not installed
621 * in the kernel (e.g. it hasn't been added to a dpif yet with
622 * dpif_port_add()). */
623 ofpbuf_delete(dev->options);
624 dev->options = options;
631 ofpbuf_delete(options);
636 tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len,
637 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1])
639 static const struct nl_policy ovs_tunnel_policy[] = {
640 [OVS_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32, .optional = true },
641 [OVS_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32, .optional = true },
642 [OVS_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true },
643 [OVS_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true },
644 [OVS_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true },
645 [OVS_TUNNEL_ATTR_TOS] = { .type = NL_A_U8, .optional = true },
646 [OVS_TUNNEL_ATTR_TTL] = { .type = NL_A_U8, .optional = true },
647 [OVS_TUNNEL_ATTR_DST_PORT] = { .type = NL_A_U16, .optional = true },
651 ofpbuf_use_const(&buf, options, options_len);
652 if (!nl_policy_parse(&buf, 0, ovs_tunnel_policy,
653 a, ARRAY_SIZE(ovs_tunnel_policy))) {
660 get_be64_or_zero(const struct nlattr *a)
662 return a ? ntohll(nl_attr_get_be64(a)) : 0;
666 get_tunnel_config(struct netdev_dev *dev_, struct smap *args)
668 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
669 const char *name = netdev_dev_get_name(dev_);
670 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
675 struct dpif_linux_vport reply;
678 error = dpif_linux_vport_get(name, &reply, &buf);
680 VLOG_ERR_RL(&rl, "%s: vport query failed (%s)", name,
685 dev->options = ofpbuf_clone_data(reply.options, reply.options_len);
689 error = tnl_port_config_from_nlattr(dev->options->data, dev->options->size,
692 VLOG_ERR_RL(&rl, "%s: failed to parse kernel config (%s)",
693 name, strerror(error));
697 if (a[OVS_TUNNEL_ATTR_DST_IPV4]) {
698 ovs_be32 daddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
699 smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(daddr));
702 if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) {
703 ovs_be32 saddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_SRC_IPV4]);
704 smap_add_format(args, "local_ip", IP_FMT, IP_ARGS(saddr));
707 if (!a[OVS_TUNNEL_ATTR_IN_KEY] && !a[OVS_TUNNEL_ATTR_OUT_KEY]) {
708 smap_add(args, "key", "flow");
710 uint64_t in_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_IN_KEY]);
711 uint64_t out_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_OUT_KEY]);
713 if (in_key && in_key == out_key) {
714 smap_add_format(args, "key", "%"PRIu64, in_key);
716 if (!a[OVS_TUNNEL_ATTR_IN_KEY]) {
717 smap_add(args, "in_key", "flow");
719 smap_add_format(args, "in_key", "%"PRIu64, in_key);
722 if (!a[OVS_TUNNEL_ATTR_OUT_KEY]) {
723 smap_add(args, "out_key", "flow");
724 } else if (out_key) {
725 smap_add_format(args, "out_key", "%"PRIu64, out_key);
730 flags = get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]);
732 if (flags & TNL_F_TTL_INHERIT) {
733 smap_add(args, "ttl", "inherit");
734 } else if (a[OVS_TUNNEL_ATTR_TTL]) {
735 int ttl = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TTL]);
736 smap_add_format(args, "ttl", "%d", ttl);
739 if (flags & TNL_F_TOS_INHERIT) {
740 smap_add(args, "tos", "inherit");
741 } else if (a[OVS_TUNNEL_ATTR_TOS]) {
742 int tos = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TOS]);
743 smap_add_format(args, "tos", "0x%x", tos);
746 if (a[OVS_TUNNEL_ATTR_DST_PORT]) {
747 uint16_t dst_port = nl_attr_get_u16(a[OVS_TUNNEL_ATTR_DST_PORT]);
748 if (dst_port != VXLAN_DST_PORT) {
749 smap_add_format(args, "dst_port", "%d", dst_port);
753 if (flags & TNL_F_CSUM) {
754 smap_add(args, "csum", "true");
757 if (!(flags & TNL_F_DF_DEFAULT)) {
758 smap_add(args, "df_default", "false");
764 /* Code specific to patch ports. */
767 netdev_vport_patch_peer(const struct netdev *netdev)
769 return netdev_vport_is_patch(netdev)
770 ? netdev_vport_get_dev(netdev)->peer
775 netdev_vport_patch_inc_rx(const struct netdev *netdev,
776 const struct dpif_flow_stats *stats)
778 if (netdev_vport_is_patch(netdev)) {
779 struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev);
780 dev->stats.rx_packets += stats->n_packets;
781 dev->stats.rx_bytes += stats->n_bytes;
786 netdev_vport_patch_inc_tx(const struct netdev *netdev,
787 const struct dpif_flow_stats *stats)
789 if (netdev_vport_is_patch(netdev)) {
790 struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev);
791 dev->stats.tx_packets += stats->n_packets;
792 dev->stats.tx_bytes += stats->n_bytes;
797 get_patch_config(struct netdev_dev *dev_, struct smap *args)
799 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
802 smap_add(args, "peer", dev->peer);
808 set_patch_config(struct netdev_dev *dev_, const struct smap *args)
810 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
811 const char *name = netdev_dev_get_name(dev_);
814 peer = smap_get(args, "peer");
816 VLOG_ERR("%s: patch type requires valid 'peer' argument", name);
820 if (smap_count(args) > 1) {
821 VLOG_ERR("%s: patch type takes only a 'peer' argument", name);
825 if (!strcmp(name, peer)) {
826 VLOG_ERR("%s: patch peer must not be self", name);
831 dev->peer = xstrdup(peer);
837 patch_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
839 struct netdev_dev_vport *dev = netdev_vport_get_dev(netdev);
840 memcpy(stats, &dev->stats, sizeof *stats);
844 #define VPORT_FUNCTIONS(GET_CONFIG, SET_CONFIG, \
845 GET_TUNNEL_CONFIG, GET_STATS, \
851 netdev_vport_create, \
852 netdev_vport_destroy, \
858 netdev_vport_close, \
862 NULL, /* recv_wait */ \
866 NULL, /* send_wait */ \
868 netdev_vport_set_etheraddr, \
869 netdev_vport_get_etheraddr, \
870 NULL, /* get_mtu */ \
871 NULL, /* set_mtu */ \
872 NULL, /* get_ifindex */ \
873 NULL, /* get_carrier */ \
874 NULL, /* get_carrier_resets */ \
875 NULL, /* get_miimon */ \
877 NULL, /* set_stats */ \
879 NULL, /* get_features */ \
880 NULL, /* set_advertisements */ \
882 NULL, /* set_policing */ \
883 NULL, /* get_qos_types */ \
884 NULL, /* get_qos_capabilities */ \
885 NULL, /* get_qos */ \
886 NULL, /* set_qos */ \
887 NULL, /* get_queue */ \
888 NULL, /* set_queue */ \
889 NULL, /* delete_queue */ \
890 NULL, /* get_queue_stats */ \
891 NULL, /* dump_queues */ \
892 NULL, /* dump_queue_stats */ \
894 NULL, /* get_in4 */ \
895 NULL, /* set_in4 */ \
896 NULL, /* get_in6 */ \
897 NULL, /* add_router */ \
898 NULL, /* get_next_hop */ \
900 NULL, /* arp_lookup */ \
902 netdev_vport_update_flags, \
904 netdev_vport_change_seq
906 #define TUNNEL_CLASS(NAME, VPORT_TYPE) \
908 { NAME, VPORT_FUNCTIONS(get_tunnel_config, \
910 get_netdev_tunnel_config, \
911 netdev_vport_get_stats, \
912 tunnel_get_status) }}
915 netdev_vport_register(void)
917 static const struct vport_class vport_classes[] = {
918 TUNNEL_CLASS("gre", OVS_VPORT_TYPE_GRE),
919 TUNNEL_CLASS("ipsec_gre", OVS_VPORT_TYPE_GRE),
920 TUNNEL_CLASS("gre64", OVS_VPORT_TYPE_GRE64),
921 TUNNEL_CLASS("ipsec_gre64", OVS_VPORT_TYPE_GRE64),
922 TUNNEL_CLASS("capwap", OVS_VPORT_TYPE_CAPWAP),
923 TUNNEL_CLASS("vxlan", OVS_VPORT_TYPE_VXLAN),
925 { OVS_VPORT_TYPE_UNSPEC,
926 { "patch", VPORT_FUNCTIONS(get_patch_config,
935 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
936 netdev_register_provider(&vport_classes[i].netdev_class);