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 #define DEFAULT_TTL 64
57 struct netdev_dev_vport {
58 struct netdev_dev netdev_dev;
59 struct ofpbuf *options;
60 unsigned int change_seq;
61 uint8_t etheraddr[ETH_ADDR_LEN];
62 struct netdev_tunnel_config tnl_cfg;
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 struct netdev_tunnel_config *tnl_cfg);
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 const struct netdev_tunnel_config *
112 get_netdev_tunnel_config(const struct netdev_dev *netdev_dev)
114 return &netdev_dev_vport_cast(netdev_dev)->tnl_cfg;
117 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
118 * options to include in OVS_VPORT_ATTR_OPTIONS for configuring that vport.
119 * Otherwise returns NULL. */
120 const struct ofpbuf *
121 netdev_vport_get_options(const struct netdev *netdev)
123 const struct netdev_dev *dev = netdev_get_dev(netdev);
125 return (is_vport_class(netdev_dev_get_class(dev))
126 ? netdev_dev_vport_cast(dev)->options
131 netdev_vport_get_vport_type(const struct netdev *netdev)
133 const struct netdev_dev *dev = netdev_get_dev(netdev);
134 const struct netdev_class *class = netdev_dev_get_class(dev);
136 return (is_vport_class(class) ? vport_class_cast(class)->type
137 : class == &netdev_internal_class ? OVS_VPORT_TYPE_INTERNAL
138 : (class == &netdev_linux_class ||
139 class == &netdev_tap_class) ? OVS_VPORT_TYPE_NETDEV
140 : OVS_VPORT_TYPE_UNSPEC);
144 get_u32_or_zero(const struct nlattr *a)
146 return a ? nl_attr_get_u32(a) : 0;
150 netdev_vport_get_netdev_type(const struct dpif_linux_vport *vport)
152 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
154 switch (vport->type) {
155 case OVS_VPORT_TYPE_UNSPEC:
158 case OVS_VPORT_TYPE_NETDEV:
161 case OVS_VPORT_TYPE_INTERNAL:
164 case OVS_VPORT_TYPE_PATCH:
167 case OVS_VPORT_TYPE_GRE:
168 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
172 return (get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
173 ? "ipsec_gre" : "gre");
175 case OVS_VPORT_TYPE_GRE64:
176 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
180 return (get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
181 ? "ipsec_gre64" : "gre64");
183 case OVS_VPORT_TYPE_CAPWAP:
186 case OVS_VPORT_TYPE_VXLAN:
189 case OVS_VPORT_TYPE_FT_GRE:
190 case __OVS_VPORT_TYPE_MAX:
194 VLOG_WARN_RL(&rl, "dp%d: port `%s' has unsupported type %u",
195 vport->dp_ifindex, vport->name, (unsigned int) vport->type);
200 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
201 struct netdev_dev **netdev_devp)
203 struct netdev_dev_vport *dev;
205 dev = xzalloc(sizeof *dev);
206 netdev_dev_init(&dev->netdev_dev, name, netdev_class);
208 eth_addr_random(dev->etheraddr);
210 *netdev_devp = &dev->netdev_dev;
211 route_table_register();
217 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
219 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
221 ofpbuf_delete(netdev_dev->options);
222 route_table_unregister();
227 netdev_vport_open(struct netdev_dev *netdev_dev, struct netdev **netdevp)
229 *netdevp = xmalloc(sizeof **netdevp);
230 netdev_init(*netdevp, netdev_dev);
235 netdev_vport_close(struct netdev *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 netdev_tunnel_config tnl_cfg;
283 struct ofpbuf *options;
286 options = ofpbuf_new(64);
287 error = vport_class->parse_config(name, netdev_dev_get_type(dev_),
288 args, options, &tnl_cfg);
291 || options->size != dev->options->size
292 || memcmp(options->data, dev->options->data, options->size))) {
293 struct dpif_linux_vport vport;
295 dpif_linux_vport_init(&vport);
296 vport.cmd = OVS_VPORT_CMD_SET;
298 vport.options = options->data;
299 vport.options_len = options->size;
300 error = dpif_linux_vport_transact(&vport, NULL, NULL);
301 if (!error || error == ENODEV) {
302 /* Either reconfiguration succeeded or this vport is not installed
303 * in the kernel (e.g. it hasn't been added to a dpif yet with
304 * dpif_port_add()). */
305 ofpbuf_delete(dev->options);
306 dev->options = options;
307 dev->tnl_cfg = tnl_cfg;
312 ofpbuf_delete(options);
318 netdev_vport_set_etheraddr(struct netdev *netdev,
319 const uint8_t mac[ETH_ADDR_LEN])
321 memcpy(netdev_vport_get_dev(netdev)->etheraddr, mac, ETH_ADDR_LEN);
322 netdev_vport_poll_notify(netdev);
327 netdev_vport_get_etheraddr(const struct netdev *netdev,
328 uint8_t mac[ETH_ADDR_LEN])
330 memcpy(mac, netdev_vport_get_dev(netdev)->etheraddr, ETH_ADDR_LEN);
334 /* Copies 'src' into 'dst', performing format conversion in the process.
336 * 'src' is allowed to be misaligned. */
338 netdev_stats_from_ovs_vport_stats(struct netdev_stats *dst,
339 const struct ovs_vport_stats *src)
341 dst->rx_packets = get_unaligned_u64(&src->rx_packets);
342 dst->tx_packets = get_unaligned_u64(&src->tx_packets);
343 dst->rx_bytes = get_unaligned_u64(&src->rx_bytes);
344 dst->tx_bytes = get_unaligned_u64(&src->tx_bytes);
345 dst->rx_errors = get_unaligned_u64(&src->rx_errors);
346 dst->tx_errors = get_unaligned_u64(&src->tx_errors);
347 dst->rx_dropped = get_unaligned_u64(&src->rx_dropped);
348 dst->tx_dropped = get_unaligned_u64(&src->tx_dropped);
351 dst->rx_length_errors = 0;
352 dst->rx_over_errors = 0;
353 dst->rx_crc_errors = 0;
354 dst->rx_frame_errors = 0;
355 dst->rx_fifo_errors = 0;
356 dst->rx_missed_errors = 0;
357 dst->tx_aborted_errors = 0;
358 dst->tx_carrier_errors = 0;
359 dst->tx_fifo_errors = 0;
360 dst->tx_heartbeat_errors = 0;
361 dst->tx_window_errors = 0;
365 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
367 struct dpif_linux_vport reply;
371 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
374 } else if (!reply.stats) {
379 netdev_stats_from_ovs_vport_stats(stats, reply.stats);
387 tunnel_get_status(const struct netdev *netdev, struct smap *smap)
389 static char iface[IFNAMSIZ];
392 route = netdev_vport_get_dev(netdev)->tnl_cfg.ip_dst;
393 if (route_table_get_name(route, iface)) {
394 struct netdev *egress_netdev;
396 smap_add(smap, "tunnel_egress_iface", iface);
398 if (!netdev_open(iface, "system", &egress_netdev)) {
399 smap_add(smap, "tunnel_egress_iface_carrier",
400 netdev_get_carrier(egress_netdev) ? "up" : "down");
401 netdev_close(egress_netdev);
409 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
410 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
411 enum netdev_flags *old_flagsp)
413 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
417 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
422 netdev_vport_change_seq(const struct netdev *netdev)
424 return netdev_vport_get_dev(netdev)->change_seq;
428 netdev_vport_run(void)
434 netdev_vport_wait(void)
439 /* Helper functions. */
442 netdev_vport_poll_notify(const struct netdev *netdev)
444 struct netdev_dev_vport *ndv = netdev_vport_get_dev(netdev);
447 if (!ndv->change_seq) {
452 /* Code specific to individual vport types. */
455 parse_key(const struct smap *args, const char *name,
456 bool *present, bool *flow)
463 s = smap_get(args, name);
465 s = smap_get(args, "key");
473 if (!strcmp(s, "flow")) {
477 return htonll(strtoull(s, NULL, 0));
482 parse_tunnel_config(const char *name, const char *type,
483 const struct smap *args, struct ofpbuf *options,
484 struct netdev_tunnel_config *tnl_cfg_)
486 bool ipsec_mech_set, needs_dst_port, has_csum;
487 struct netdev_tunnel_config tnl_cfg;
488 struct smap_node *node;
491 flags = TNL_F_DF_DEFAULT;
492 has_csum = strstr(type, "gre");
493 ipsec_mech_set = false;
494 memset(&tnl_cfg, 0, sizeof tnl_cfg);
496 if (!strcmp(type, "capwap")) {
497 VLOG_WARN_ONCE("CAPWAP tunnel support is deprecated.");
500 needs_dst_port = !strcmp(type, "vxlan");
501 tnl_cfg.ipsec = strstr(type, "ipsec");
503 flags |= TNL_F_IPSEC;
505 tnl_cfg.dont_fragment = true;
507 SMAP_FOR_EACH (node, args) {
508 if (!strcmp(node->key, "remote_ip")) {
509 struct in_addr in_addr;
510 if (lookup_ip(node->value, &in_addr)) {
511 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
513 tnl_cfg.ip_dst = in_addr.s_addr;
515 } else if (!strcmp(node->key, "local_ip")) {
516 struct in_addr in_addr;
517 if (lookup_ip(node->value, &in_addr)) {
518 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
520 tnl_cfg.ip_src = in_addr.s_addr;
522 } else if (!strcmp(node->key, "tos")) {
523 if (!strcmp(node->value, "inherit")) {
524 flags |= TNL_F_TOS_INHERIT;
525 tnl_cfg.tos_inherit = true;
529 tos = strtol(node->value, &endptr, 0);
530 if (*endptr == '\0' && tos == (tos & IP_DSCP_MASK)) {
531 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TOS, tos);
534 VLOG_WARN("%s: invalid TOS %s", name, node->value);
537 } else if (!strcmp(node->key, "ttl")) {
538 if (!strcmp(node->value, "inherit")) {
539 flags |= TNL_F_TTL_INHERIT;
540 tnl_cfg.ttl_inherit = true;
542 nl_msg_put_u8(options, OVS_TUNNEL_ATTR_TTL, atoi(node->value));
543 tnl_cfg.ttl = atoi(node->value);
545 } else if (!strcmp(node->key, "dst_port") && needs_dst_port) {
546 tnl_cfg.dst_port = htons(atoi(node->value));
547 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT,
549 } else if (!strcmp(node->key, "csum") && has_csum) {
550 if (!strcmp(node->value, "true")) {
554 } else if (!strcmp(node->key, "df_default")) {
555 if (!strcmp(node->value, "false")) {
556 flags &= ~TNL_F_DF_DEFAULT;
557 tnl_cfg.dont_fragment = false;
559 } else if (!strcmp(node->key, "peer_cert") && tnl_cfg.ipsec) {
560 if (smap_get(args, "certificate")) {
561 ipsec_mech_set = true;
563 const char *use_ssl_cert;
565 /* If the "use_ssl_cert" is true, then "certificate" and
566 * "private_key" will be pulled from the SSL table. The
567 * use of this option is strongly discouraged, since it
568 * will like be removed when multiple SSL configurations
569 * are supported by OVS.
571 use_ssl_cert = smap_get(args, "use_ssl_cert");
572 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
573 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
577 ipsec_mech_set = true;
579 } else if (!strcmp(node->key, "psk") && tnl_cfg.ipsec) {
580 ipsec_mech_set = true;
581 } else if (tnl_cfg.ipsec
582 && (!strcmp(node->key, "certificate")
583 || !strcmp(node->key, "private_key")
584 || !strcmp(node->key, "use_ssl_cert"))) {
585 /* Ignore options not used by the netdev. */
586 } else if (!strcmp(node->key, "key") ||
587 !strcmp(node->key, "in_key") ||
588 !strcmp(node->key, "out_key")) {
589 /* Handled separately below. */
591 VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->key);
595 /* Add a default destination port for VXLAN if none specified. */
596 if (needs_dst_port && !tnl_cfg.dst_port) {
597 nl_msg_put_u16(options, OVS_TUNNEL_ATTR_DST_PORT, VXLAN_DST_PORT);
598 tnl_cfg.dst_port = htons(VXLAN_DST_PORT);
602 static pid_t pid = 0;
604 char *file_name = xasprintf("%s/%s", ovs_rundir(),
605 "ovs-monitor-ipsec.pid");
606 pid = read_pidfile(file_name);
611 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
616 if (smap_get(args, "peer_cert") && smap_get(args, "psk")) {
617 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name);
621 if (!ipsec_mech_set) {
622 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
628 if (!tnl_cfg.ip_dst) {
629 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
633 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_DST_IPV4, tnl_cfg.ip_dst);
635 if (tnl_cfg.ip_src) {
636 if (ip_is_multicast(tnl_cfg.ip_dst)) {
637 VLOG_WARN("%s: remote_ip is multicast, ignoring local_ip", name);
640 nl_msg_put_be32(options, OVS_TUNNEL_ATTR_SRC_IPV4, tnl_cfg.ip_src);
645 tnl_cfg.ttl = DEFAULT_TTL;
648 tnl_cfg.in_key = parse_key(args, "in_key",
649 &tnl_cfg.in_key_present,
650 &tnl_cfg.in_key_flow);
651 if (tnl_cfg.in_key_present && !tnl_cfg.in_key_flow) {
652 nl_msg_put_be64(options, OVS_TUNNEL_ATTR_IN_KEY, tnl_cfg.in_key);
655 tnl_cfg.out_key = parse_key(args, "out_key",
656 &tnl_cfg.out_key_present,
657 &tnl_cfg.out_key_flow);
658 if (tnl_cfg.out_key_present && !tnl_cfg.out_key_flow) {
659 nl_msg_put_be64(options, OVS_TUNNEL_ATTR_OUT_KEY, tnl_cfg.out_key);
661 nl_msg_put_u32(options, OVS_TUNNEL_ATTR_FLAGS, flags);
669 tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len,
670 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1])
672 static const struct nl_policy ovs_tunnel_policy[] = {
673 [OVS_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32, .optional = true },
674 [OVS_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32, .optional = true },
675 [OVS_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true },
676 [OVS_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true },
677 [OVS_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true },
678 [OVS_TUNNEL_ATTR_TOS] = { .type = NL_A_U8, .optional = true },
679 [OVS_TUNNEL_ATTR_TTL] = { .type = NL_A_U8, .optional = true },
680 [OVS_TUNNEL_ATTR_DST_PORT] = { .type = NL_A_U16, .optional = true },
684 ofpbuf_use_const(&buf, options, options_len);
685 if (!nl_policy_parse(&buf, 0, ovs_tunnel_policy,
686 a, ARRAY_SIZE(ovs_tunnel_policy))) {
693 get_be64_or_zero(const struct nlattr *a)
695 return a ? ntohll(nl_attr_get_be64(a)) : 0;
699 unparse_tunnel_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
700 const struct nlattr *options, size_t options_len,
703 struct nlattr *a[OVS_TUNNEL_ATTR_MAX + 1];
707 error = tnl_port_config_from_nlattr(options, options_len, a);
712 if (a[OVS_TUNNEL_ATTR_DST_IPV4]) {
713 ovs_be32 daddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_DST_IPV4]);
714 smap_add_format(args, "remote_ip", IP_FMT, IP_ARGS(daddr));
717 if (a[OVS_TUNNEL_ATTR_SRC_IPV4]) {
718 ovs_be32 saddr = nl_attr_get_be32(a[OVS_TUNNEL_ATTR_SRC_IPV4]);
719 smap_add_format(args, "local_ip", IP_FMT, IP_ARGS(saddr));
722 if (!a[OVS_TUNNEL_ATTR_IN_KEY] && !a[OVS_TUNNEL_ATTR_OUT_KEY]) {
723 smap_add(args, "key", "flow");
725 uint64_t in_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_IN_KEY]);
726 uint64_t out_key = get_be64_or_zero(a[OVS_TUNNEL_ATTR_OUT_KEY]);
728 if (in_key && in_key == out_key) {
729 smap_add_format(args, "key", "%"PRIu64, in_key);
731 if (!a[OVS_TUNNEL_ATTR_IN_KEY]) {
732 smap_add(args, "in_key", "flow");
734 smap_add_format(args, "in_key", "%"PRIu64, in_key);
737 if (!a[OVS_TUNNEL_ATTR_OUT_KEY]) {
738 smap_add(args, "out_key", "flow");
739 } else if (out_key) {
740 smap_add_format(args, "out_key", "%"PRIu64, out_key);
745 flags = get_u32_or_zero(a[OVS_TUNNEL_ATTR_FLAGS]);
747 if (flags & TNL_F_TTL_INHERIT) {
748 smap_add(args, "ttl", "inherit");
749 } else if (a[OVS_TUNNEL_ATTR_TTL]) {
750 int ttl = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TTL]);
751 smap_add_format(args, "ttl", "%d", ttl);
754 if (flags & TNL_F_TOS_INHERIT) {
755 smap_add(args, "tos", "inherit");
756 } else if (a[OVS_TUNNEL_ATTR_TOS]) {
757 int tos = nl_attr_get_u8(a[OVS_TUNNEL_ATTR_TOS]);
758 smap_add_format(args, "tos", "0x%x", tos);
761 if (a[OVS_TUNNEL_ATTR_DST_PORT]) {
762 uint16_t dst_port = nl_attr_get_u16(a[OVS_TUNNEL_ATTR_DST_PORT]);
763 if (dst_port != VXLAN_DST_PORT) {
764 smap_add_format(args, "dst_port", "%d", dst_port);
768 if (flags & TNL_F_CSUM) {
769 smap_add(args, "csum", "true");
771 if (flags & TNL_F_DF_INHERIT) {
772 /* Shouldn't happen as "df_inherit" is no longer supported. However,
773 * for completeness we report it if it's there. */
774 smap_add(args, "df_inherit", "true");
776 if (!(flags & TNL_F_DF_DEFAULT)) {
777 smap_add(args, "df_default", "false");
784 parse_patch_config(const char *name, const char *type OVS_UNUSED,
785 const struct smap *args, struct ofpbuf *options,
786 struct netdev_tunnel_config *tnl_cfg)
790 memset(tnl_cfg, 0, sizeof *tnl_cfg);
792 peer = smap_get(args, "peer");
794 VLOG_ERR("%s: patch type requires valid 'peer' argument", name);
798 if (smap_count(args) > 1) {
799 VLOG_ERR("%s: patch type takes only a 'peer' argument", name);
803 if (strlen(peer) >= IFNAMSIZ) {
804 VLOG_ERR("%s: patch 'peer' arg too long", name);
808 if (!strcmp(name, peer)) {
809 VLOG_ERR("%s: patch peer must not be self", name);
813 nl_msg_put_string(options, OVS_PATCH_ATTR_PEER, peer);
819 unparse_patch_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
820 const struct nlattr *options, size_t options_len,
823 static const struct nl_policy ovs_patch_policy[] = {
824 [OVS_PATCH_ATTR_PEER] = { .type = NL_A_STRING,
829 struct nlattr *a[ARRAY_SIZE(ovs_patch_policy)];
832 ofpbuf_use_const(&buf, options, options_len);
833 if (!nl_policy_parse(&buf, 0, ovs_patch_policy,
834 a, ARRAY_SIZE(ovs_patch_policy))) {
838 smap_add(args, "peer", nl_attr_get_string(a[OVS_PATCH_ATTR_PEER]));
842 #define VPORT_FUNCTIONS(GET_TUNNEL_CONFIG, GET_STATUS) \
847 netdev_vport_create, \
848 netdev_vport_destroy, \
849 netdev_vport_get_config, \
850 netdev_vport_set_config, \
854 netdev_vport_close, \
858 NULL, /* recv_wait */ \
862 NULL, /* send_wait */ \
864 netdev_vport_set_etheraddr, \
865 netdev_vport_get_etheraddr, \
866 NULL, /* get_mtu */ \
867 NULL, /* set_mtu */ \
868 NULL, /* get_ifindex */ \
869 NULL, /* get_carrier */ \
870 NULL, /* get_carrier_resets */ \
871 NULL, /* get_miimon */ \
872 netdev_vport_get_stats, \
873 NULL, /* set_stats */ \
875 NULL, /* get_features */ \
876 NULL, /* set_advertisements */ \
878 NULL, /* set_policing */ \
879 NULL, /* get_qos_types */ \
880 NULL, /* get_qos_capabilities */ \
881 NULL, /* get_qos */ \
882 NULL, /* set_qos */ \
883 NULL, /* get_queue */ \
884 NULL, /* set_queue */ \
885 NULL, /* delete_queue */ \
886 NULL, /* get_queue_stats */ \
887 NULL, /* dump_queues */ \
888 NULL, /* dump_queue_stats */ \
890 NULL, /* get_in4 */ \
891 NULL, /* set_in4 */ \
892 NULL, /* get_in6 */ \
893 NULL, /* add_router */ \
894 NULL, /* get_next_hop */ \
896 NULL, /* arp_lookup */ \
898 netdev_vport_update_flags, \
900 netdev_vport_change_seq
902 #define TUNNEL_CLASS(NAME, VPORT_TYPE) \
904 { NAME, VPORT_FUNCTIONS(get_netdev_tunnel_config, \
905 tunnel_get_status) }, \
906 parse_tunnel_config, unparse_tunnel_config }
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(NULL, NULL) },
921 parse_patch_config, unparse_patch_config }
926 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
927 netdev_register_provider(&vport_classes[i].netdev_class);