2 * Copyright (c) 2010, 2011 Nicira Networks.
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/rtnetlink.h>
26 #include <sys/ioctl.h>
28 #include "byte-order.h"
29 #include "dpif-linux.h"
33 #include "netdev-provider.h"
35 #include "netlink-socket.h"
37 #include "openvswitch/datapath-protocol.h"
38 #include "openvswitch/tunnel.h"
40 #include "route-table.h"
41 #include "rtnetlink.h"
43 #include "socket-util.h"
46 VLOG_DEFINE_THIS_MODULE(netdev_vport);
48 struct netdev_vport_notifier {
49 struct netdev_notifier notifier;
50 struct list list_node;
51 struct shash_node *shash_node;
54 struct netdev_dev_vport {
55 struct netdev_dev netdev_dev;
56 struct ofpbuf *options;
64 enum odp_vport_type type;
65 struct netdev_class netdev_class;
66 int (*parse_config)(const char *name, const char *type,
67 const struct shash *args, struct ofpbuf *options);
68 int (*unparse_config)(const char *name, const char *type,
69 const struct nlattr *options, size_t options_len,
73 static struct shash netdev_vport_notifiers =
74 SHASH_INITIALIZER(&netdev_vport_notifiers);
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 const struct shash *, 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[ODP_TUNNEL_ATTR_MAX + 1]);
85 static const char *netdev_vport_get_tnl_iface(const struct netdev *netdev);
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 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 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_vport *
108 netdev_vport_cast(const struct netdev *netdev)
110 struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
111 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
112 return CONTAINER_OF(netdev, struct netdev_vport, netdev);
115 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
116 * options to include in ODP_VPORT_ATTR_OPTIONS for configuring that vport.
117 * Otherwise returns NULL. */
118 const struct ofpbuf *
119 netdev_vport_get_options(const struct netdev *netdev)
121 const struct netdev_dev *dev = netdev_get_dev(netdev);
123 return (is_vport_class(netdev_dev_get_class(dev))
124 ? netdev_dev_vport_cast(dev)->options
129 netdev_vport_get_vport_type(const struct netdev *netdev)
131 const struct netdev_dev *dev = netdev_get_dev(netdev);
132 const struct netdev_class *class = netdev_dev_get_class(dev);
134 return (is_vport_class(class) ? vport_class_cast(class)->type
135 : class == &netdev_internal_class ? ODP_VPORT_TYPE_INTERNAL
136 : class == &netdev_linux_class ? ODP_VPORT_TYPE_NETDEV
137 : ODP_VPORT_TYPE_UNSPEC);
141 netdev_vport_get_netdev_type(const struct dpif_linux_vport *vport)
143 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1];
145 switch (vport->type) {
146 case ODP_VPORT_TYPE_UNSPEC:
149 case ODP_VPORT_TYPE_NETDEV:
152 case ODP_VPORT_TYPE_INTERNAL:
155 case ODP_VPORT_TYPE_PATCH:
158 case ODP_VPORT_TYPE_GRE:
159 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
163 return (nl_attr_get_u32(a[ODP_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
164 ? "ipsec_gre" : "gre");
166 case ODP_VPORT_TYPE_CAPWAP:
169 case __ODP_VPORT_TYPE_MAX:
173 VLOG_WARN_RL(&rl, "dp%d: port `%s' has unsupported type %u",
174 vport->dp_ifindex, vport->name, (unsigned int) vport->type);
179 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
180 const struct shash *args,
181 struct netdev_dev **netdev_devp)
183 const struct vport_class *vport_class = vport_class_cast(netdev_class);
184 struct ofpbuf *options = NULL;
185 struct shash fetched_args;
188 shash_init(&fetched_args);
190 if (!shash_is_empty(args)) {
191 /* Parse the provided configuration. */
192 options = ofpbuf_new(64);
193 error = vport_class->parse_config(name, netdev_class->type,
196 /* Fetch an existing configuration from the kernel.
198 * This case could be ambiguous with initializing a new vport with an
199 * empty configuration, but none of the existing vport classes accept
200 * an empty configuration. */
201 struct dpif_linux_vport reply;
204 error = dpif_linux_vport_get(name, &reply, &buf);
206 /* XXX verify correct type */
207 error = vport_class->unparse_config(name, netdev_class->type,
212 VLOG_ERR_RL(&rl, "%s: failed to parse kernel config (%s)",
213 name, strerror(error));
215 options = ofpbuf_clone_data(reply.options, reply.options_len);
219 VLOG_ERR_RL(&rl, "%s: vport query failed (%s)",
220 name, strerror(error));
225 struct netdev_dev_vport *dev;
227 dev = xmalloc(sizeof *dev);
228 netdev_dev_init(&dev->netdev_dev, name,
229 shash_is_empty(&fetched_args) ? args : &fetched_args,
231 dev->options = options;
233 *netdev_devp = &dev->netdev_dev;
234 route_table_register();
236 ofpbuf_delete(options);
239 shash_destroy(&fetched_args);
245 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
247 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
249 route_table_unregister();
254 netdev_vport_open(struct netdev_dev *netdev_dev_, int ethertype OVS_UNUSED,
255 struct netdev **netdevp)
257 struct netdev_vport *netdev;
259 netdev = xmalloc(sizeof *netdev);
260 netdev_init(&netdev->netdev, netdev_dev_);
262 *netdevp = &netdev->netdev;
267 netdev_vport_close(struct netdev *netdev_)
269 struct netdev_vport *netdev = netdev_vport_cast(netdev_);
274 netdev_vport_set_config(struct netdev_dev *dev_, const struct shash *args)
276 const struct netdev_class *netdev_class = netdev_dev_get_class(dev_);
277 const struct vport_class *vport_class = vport_class_cast(netdev_class);
278 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
279 const char *name = netdev_dev_get_name(dev_);
280 struct ofpbuf *options;
283 options = ofpbuf_new(64);
284 error = vport_class->parse_config(name, netdev_dev_get_type(dev_),
287 && (options->size != dev->options->size
288 || memcmp(options->data, dev->options->data, options->size))) {
289 struct dpif_linux_vport vport;
291 dpif_linux_vport_init(&vport);
292 vport.cmd = ODP_VPORT_CMD_SET;
294 vport.options = options->data;
295 vport.options_len = options->size;
296 error = dpif_linux_vport_transact(&vport, NULL, NULL);
297 if (!error || error == ENODEV) {
298 /* Either reconfiguration succeeded or this vport is not installed
299 * in the kernel (e.g. it hasn't been added to a dpif yet with
300 * dpif_port_add()). */
301 ofpbuf_delete(dev->options);
302 dev->options = options;
307 ofpbuf_delete(options);
313 netdev_vport_set_etheraddr(struct netdev *netdev,
314 const uint8_t mac[ETH_ADDR_LEN])
316 struct dpif_linux_vport vport;
319 dpif_linux_vport_init(&vport);
320 vport.cmd = ODP_VPORT_CMD_SET;
321 vport.name = netdev_get_name(netdev);
324 error = dpif_linux_vport_transact(&vport, NULL, NULL);
326 netdev_vport_poll_notify(netdev);
332 netdev_vport_get_etheraddr(const struct netdev *netdev,
333 uint8_t mac[ETH_ADDR_LEN])
335 struct dpif_linux_vport reply;
339 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
342 memcpy(mac, reply.address, ETH_ADDR_LEN);
352 netdev_vport_get_mtu(const struct netdev *netdev, int *mtup)
354 struct dpif_linux_vport reply;
358 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
367 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
369 struct dpif_linux_vport reply;
373 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
376 } else if (!reply.stats) {
381 stats->rx_packets = reply.stats->rx_packets;
382 stats->tx_packets = reply.stats->tx_packets;
383 stats->rx_bytes = reply.stats->rx_bytes;
384 stats->tx_bytes = reply.stats->tx_bytes;
385 stats->rx_errors = reply.stats->rx_errors;
386 stats->tx_errors = reply.stats->tx_errors;
387 stats->rx_dropped = reply.stats->rx_dropped;
388 stats->tx_dropped = reply.stats->tx_dropped;
389 stats->multicast = reply.stats->multicast;
390 stats->collisions = reply.stats->collisions;
391 stats->rx_length_errors = reply.stats->rx_length_errors;
392 stats->rx_over_errors = reply.stats->rx_over_errors;
393 stats->rx_crc_errors = reply.stats->rx_crc_errors;
394 stats->rx_frame_errors = reply.stats->rx_frame_errors;
395 stats->rx_fifo_errors = reply.stats->rx_fifo_errors;
396 stats->rx_missed_errors = reply.stats->rx_missed_errors;
397 stats->tx_aborted_errors = reply.stats->tx_aborted_errors;
398 stats->tx_carrier_errors = reply.stats->tx_carrier_errors;
399 stats->tx_fifo_errors = reply.stats->tx_fifo_errors;
400 stats->tx_heartbeat_errors = reply.stats->tx_heartbeat_errors;
401 stats->tx_window_errors = reply.stats->tx_window_errors;
409 netdev_vport_set_stats(struct netdev *netdev, const struct netdev_stats *stats)
411 struct rtnl_link_stats64 rtnl_stats;
412 struct dpif_linux_vport vport;
415 rtnl_stats.rx_packets = stats->rx_packets;
416 rtnl_stats.tx_packets = stats->tx_packets;
417 rtnl_stats.rx_bytes = stats->rx_bytes;
418 rtnl_stats.tx_bytes = stats->tx_bytes;
419 rtnl_stats.rx_errors = stats->rx_errors;
420 rtnl_stats.tx_errors = stats->tx_errors;
421 rtnl_stats.rx_dropped = stats->rx_dropped;
422 rtnl_stats.tx_dropped = stats->tx_dropped;
423 rtnl_stats.multicast = stats->multicast;
424 rtnl_stats.collisions = stats->collisions;
425 rtnl_stats.rx_length_errors = stats->rx_length_errors;
426 rtnl_stats.rx_over_errors = stats->rx_over_errors;
427 rtnl_stats.rx_crc_errors = stats->rx_crc_errors;
428 rtnl_stats.rx_frame_errors = stats->rx_frame_errors;
429 rtnl_stats.rx_fifo_errors = stats->rx_fifo_errors;
430 rtnl_stats.rx_missed_errors = stats->rx_missed_errors;
431 rtnl_stats.tx_aborted_errors = stats->tx_aborted_errors;
432 rtnl_stats.tx_carrier_errors = stats->tx_carrier_errors;
433 rtnl_stats.tx_fifo_errors = stats->tx_fifo_errors;
434 rtnl_stats.tx_heartbeat_errors = stats->tx_heartbeat_errors;
435 rtnl_stats.tx_window_errors = stats->tx_window_errors;
437 dpif_linux_vport_init(&vport);
438 vport.cmd = ODP_VPORT_CMD_SET;
439 vport.name = netdev_get_name(netdev);
440 vport.stats = &rtnl_stats;
442 err = dpif_linux_vport_transact(&vport, NULL, NULL);
444 /* If the vport layer doesn't know about the device, that doesn't mean it
445 * doesn't exist (after all were able to open it when netdev_open() was
446 * called), it just means that it isn't attached and we'll be getting
447 * stats a different way. */
456 netdev_vport_get_status(const struct netdev *netdev, struct shash *sh)
458 const char *iface = netdev_vport_get_tnl_iface(netdev);
461 struct netdev *egress_netdev;
463 shash_add(sh, "tunnel_egress_iface", xstrdup(iface));
465 if (!netdev_open_default(iface, &egress_netdev)) {
466 shash_add(sh, "tunnel_egress_iface_carrier",
467 xstrdup(netdev_get_carrier(egress_netdev)
469 netdev_close(egress_netdev);
477 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
478 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
479 enum netdev_flags *old_flagsp)
481 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
485 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
490 make_poll_name(const struct netdev *netdev)
492 return xasprintf("%s:%s", netdev_get_type(netdev), netdev_get_name(netdev));
496 netdev_vport_poll_add(struct netdev *netdev,
497 void (*cb)(struct netdev_notifier *), void *aux,
498 struct netdev_notifier **notifierp)
500 char *poll_name = make_poll_name(netdev);
501 struct netdev_vport_notifier *notifier;
503 struct shash_node *shash_node;
505 shash_node = shash_find_data(&netdev_vport_notifiers, poll_name);
507 list = xmalloc(sizeof *list);
509 shash_node = shash_add(&netdev_vport_notifiers, poll_name, list);
511 list = shash_node->data;
514 notifier = xmalloc(sizeof *notifier);
515 netdev_notifier_init(¬ifier->notifier, netdev, cb, aux);
516 list_push_back(list, ¬ifier->list_node);
517 notifier->shash_node = shash_node;
519 *notifierp = ¬ifier->notifier;
526 netdev_vport_poll_remove(struct netdev_notifier *notifier_)
528 struct netdev_vport_notifier *notifier =
529 CONTAINER_OF(notifier_, struct netdev_vport_notifier, notifier);
533 list = list_remove(¬ifier->list_node);
534 if (list_is_empty(list)) {
535 shash_delete(&netdev_vport_notifiers, notifier->shash_node);
543 netdev_vport_run(void)
549 netdev_vport_wait(void)
554 /* get_tnl_iface() implementation. */
556 netdev_vport_get_tnl_iface(const struct netdev *netdev)
558 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1];
560 struct netdev_dev_vport *ndv;
561 static char name[IFNAMSIZ];
563 ndv = netdev_dev_vport_cast(netdev_get_dev(netdev));
564 if (tnl_port_config_from_nlattr(ndv->options->data, ndv->options->size,
568 route = nl_attr_get_be32(a[ODP_TUNNEL_ATTR_DST_IPV4]);
570 if (route_table_get_name(route, name)) {
577 /* Helper functions. */
580 netdev_vport_poll_notify(const struct netdev *netdev)
582 char *poll_name = make_poll_name(netdev);
583 struct list *list = shash_find_data(&netdev_vport_notifiers,
587 struct netdev_vport_notifier *notifier;
589 LIST_FOR_EACH (notifier, list_node, list) {
590 struct netdev_notifier *n = ¬ifier->notifier;
598 /* Code specific to individual vport types. */
601 set_key(const struct shash *args, const char *name, uint16_t type,
602 struct ofpbuf *options)
606 s = shash_find_data(args, name);
608 s = shash_find_data(args, "key");
614 if (!strcmp(s, "flow")) {
615 /* This is the default if no attribute is present. */
617 nl_msg_put_be64(options, type, htonll(strtoull(s, NULL, 0)));
622 parse_tunnel_config(const char *name, const char *type,
623 const struct shash *args, struct ofpbuf *options)
626 bool is_ipsec = false;
627 struct shash_node *node;
628 bool ipsec_mech_set = false;
629 ovs_be32 daddr = htonl(0);
632 flags = TNL_F_PMTUD | TNL_F_HDR_CACHE;
633 if (!strcmp(type, "gre")) {
635 } else if (!strcmp(type, "ipsec_gre")) {
638 flags |= TNL_F_IPSEC;
639 flags &= ~TNL_F_HDR_CACHE;
642 SHASH_FOR_EACH (node, args) {
643 if (!strcmp(node->name, "remote_ip")) {
644 struct in_addr in_addr;
645 if (lookup_ip(node->data, &in_addr)) {
646 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
648 daddr = in_addr.s_addr;
650 } else if (!strcmp(node->name, "local_ip")) {
651 struct in_addr in_addr;
652 if (lookup_ip(node->data, &in_addr)) {
653 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
655 nl_msg_put_be32(options, ODP_TUNNEL_ATTR_SRC_IPV4,
658 } else if (!strcmp(node->name, "tos")) {
659 if (!strcmp(node->data, "inherit")) {
660 flags |= TNL_F_TOS_INHERIT;
662 nl_msg_put_u8(options, ODP_TUNNEL_ATTR_TOS, atoi(node->data));
664 } else if (!strcmp(node->name, "ttl")) {
665 if (!strcmp(node->data, "inherit")) {
666 flags |= TNL_F_TTL_INHERIT;
668 nl_msg_put_u8(options, ODP_TUNNEL_ATTR_TTL, atoi(node->data));
670 } else if (!strcmp(node->name, "csum") && is_gre) {
671 if (!strcmp(node->data, "true")) {
674 } else if (!strcmp(node->name, "pmtud")) {
675 if (!strcmp(node->data, "false")) {
676 flags &= ~TNL_F_PMTUD;
678 } else if (!strcmp(node->name, "header_cache")) {
679 if (!strcmp(node->data, "false")) {
680 flags &= ~TNL_F_HDR_CACHE;
682 } else if (!strcmp(node->name, "peer_cert") && is_ipsec) {
683 if (shash_find(args, "certificate")) {
684 ipsec_mech_set = true;
686 const char *use_ssl_cert;
688 /* If the "use_ssl_cert" is true, then "certificate" and
689 * "private_key" will be pulled from the SSL table. The
690 * use of this option is strongly discouraged, since it
691 * will like be removed when multiple SSL configurations
692 * are supported by OVS.
694 use_ssl_cert = shash_find_data(args, "use_ssl_cert");
695 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
696 VLOG_WARN("%s: 'peer_cert' requires 'certificate' argument",
700 ipsec_mech_set = true;
702 } else if (!strcmp(node->name, "psk") && is_ipsec) {
703 ipsec_mech_set = true;
705 && (!strcmp(node->name, "certificate")
706 || !strcmp(node->name, "private_key")
707 || !strcmp(node->name, "use_ssl_cert"))) {
708 /* Ignore options not used by the netdev. */
709 } else if (is_gre && (!strcmp(node->name, "key") &&
710 !strcmp(node->name, "in_key") &&
711 !strcmp(node->name, "out_key"))) {
712 /* Handled separately below. */
714 VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->name);
719 if (shash_find(args, "peer_cert") && shash_find(args, "psk")) {
720 VLOG_WARN("%s: cannot define both 'peer_cert' and 'psk'", name);
724 if (!ipsec_mech_set) {
725 VLOG_WARN("%s: IPsec requires an 'peer_cert' or psk' argument",
732 set_key(args, "in_key", ODP_TUNNEL_ATTR_IN_KEY, options);
733 set_key(args, "out_key", ODP_TUNNEL_ATTR_OUT_KEY, options);
737 VLOG_WARN("%s: %s type requires valid 'remote_ip' argument",
741 nl_msg_put_be32(options, ODP_TUNNEL_ATTR_DST_IPV4, daddr);
743 nl_msg_put_u32(options, ODP_TUNNEL_ATTR_FLAGS, flags);
749 tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len,
750 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1])
752 static const struct nl_policy odp_tunnel_policy[] = {
753 [ODP_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32 },
754 [ODP_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32 },
755 [ODP_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true },
756 [ODP_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true },
757 [ODP_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true },
758 [ODP_TUNNEL_ATTR_TOS] = { .type = NL_A_U8, .optional = true },
759 [ODP_TUNNEL_ATTR_TTL] = { .type = NL_A_U8, .optional = true },
763 ofpbuf_use_const(&buf, options, options_len);
764 if (!nl_policy_parse(&buf, 0, odp_tunnel_policy,
765 a, ARRAY_SIZE(odp_tunnel_policy))) {
772 get_be64_or_zero(const struct nlattr *a)
774 return a ? ntohll(nl_attr_get_be64(a)) : 0;
778 unparse_tunnel_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
779 const struct nlattr *options, size_t options_len,
782 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1];
787 error = tnl_port_config_from_nlattr(options, options_len, a);
792 flags = nl_attr_get_u32(a[ODP_TUNNEL_ATTR_FLAGS]);
793 if (!(flags & TNL_F_HDR_CACHE) == !(flags & TNL_F_IPSEC)) {
794 smap_add(args, "header_cache",
795 flags & TNL_F_HDR_CACHE ? "true" : "false");
798 daddr = nl_attr_get_be32(a[ODP_TUNNEL_ATTR_DST_IPV4]);
799 shash_add(args, "remote_ip", xasprintf(IP_FMT, IP_ARGS(&daddr)));
801 if (a[ODP_TUNNEL_ATTR_SRC_IPV4]) {
802 ovs_be32 saddr = nl_attr_get_be32(a[ODP_TUNNEL_ATTR_SRC_IPV4]);
803 shash_add(args, "local_ip", xasprintf(IP_FMT, IP_ARGS(&saddr)));
806 if (!a[ODP_TUNNEL_ATTR_IN_KEY] && !a[ODP_TUNNEL_ATTR_OUT_KEY]) {
807 smap_add(args, "key", "flow");
809 uint64_t in_key = get_be64_or_zero(a[ODP_TUNNEL_ATTR_IN_KEY]);
810 uint64_t out_key = get_be64_or_zero(a[ODP_TUNNEL_ATTR_OUT_KEY]);
812 if (in_key && in_key == out_key) {
813 shash_add(args, "key", xasprintf("%"PRIu64, in_key));
815 if (!a[ODP_TUNNEL_ATTR_IN_KEY]) {
816 smap_add(args, "in_key", "flow");
818 shash_add(args, "in_key", xasprintf("%"PRIu64, in_key));
821 if (!a[ODP_TUNNEL_ATTR_OUT_KEY]) {
822 smap_add(args, "out_key", "flow");
823 } else if (out_key) {
824 shash_add(args, "out_key", xasprintf("%"PRIu64, out_key));
829 if (flags & TNL_F_TTL_INHERIT) {
830 smap_add(args, "tos", "inherit");
831 } else if (a[ODP_TUNNEL_ATTR_TTL]) {
832 int ttl = nl_attr_get_u8(a[ODP_TUNNEL_ATTR_TTL]);
833 shash_add(args, "tos", xasprintf("%d", ttl));
836 if (flags & TNL_F_TOS_INHERIT) {
837 smap_add(args, "tos", "inherit");
838 } else if (a[ODP_TUNNEL_ATTR_TOS]) {
839 int tos = nl_attr_get_u8(a[ODP_TUNNEL_ATTR_TOS]);
840 shash_add(args, "tos", xasprintf("%d", tos));
843 if (flags & TNL_F_CSUM) {
844 smap_add(args, "csum", "true");
846 if (!(flags & TNL_F_PMTUD)) {
847 smap_add(args, "pmtud", "false");
854 parse_patch_config(const char *name, const char *type OVS_UNUSED,
855 const struct shash *args, struct ofpbuf *options)
859 peer = shash_find_data(args, "peer");
861 VLOG_WARN("%s: patch type requires valid 'peer' argument", name);
865 if (shash_count(args) > 1) {
866 VLOG_WARN("%s: patch type takes only a 'peer' argument", name);
870 if (strlen(peer) >= IFNAMSIZ) {
871 VLOG_WARN("%s: patch 'peer' arg too long", name);
875 if (!strcmp(name, peer)) {
876 VLOG_WARN("%s: patch peer must not be self", name);
880 nl_msg_put_string(options, ODP_PATCH_ATTR_PEER, peer);
886 unparse_patch_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
887 const struct nlattr *options, size_t options_len,
890 static const struct nl_policy odp_patch_policy[] = {
891 [ODP_PATCH_ATTR_PEER] = { .type = NL_A_STRING,
896 struct nlattr *a[ARRAY_SIZE(odp_patch_policy)];
899 ofpbuf_use_const(&buf, options, options_len);
900 if (!nl_policy_parse(&buf, 0, odp_patch_policy,
901 a, ARRAY_SIZE(odp_patch_policy))) {
905 smap_add(args, "peer", nl_attr_get_string(a[ODP_PATCH_ATTR_PEER]));
909 #define VPORT_FUNCTIONS(GET_STATUS) \
914 netdev_vport_create, \
915 netdev_vport_destroy, \
916 netdev_vport_set_config, \
919 netdev_vport_close, \
921 NULL, /* enumerate */ \
924 NULL, /* recv_wait */ \
928 NULL, /* send_wait */ \
930 netdev_vport_set_etheraddr, \
931 netdev_vport_get_etheraddr, \
932 netdev_vport_get_mtu, \
933 NULL, /* get_ifindex */ \
934 NULL, /* get_carrier */ \
935 NULL, /* get_miimon */ \
936 netdev_vport_get_stats, \
937 netdev_vport_set_stats, \
939 NULL, /* get_features */ \
940 NULL, /* set_advertisements */ \
941 NULL, /* get_vlan_vid */ \
943 NULL, /* set_policing */ \
944 NULL, /* get_qos_types */ \
945 NULL, /* get_qos_capabilities */ \
946 NULL, /* get_qos */ \
947 NULL, /* set_qos */ \
948 NULL, /* get_queue */ \
949 NULL, /* set_queue */ \
950 NULL, /* delete_queue */ \
951 NULL, /* get_queue_stats */ \
952 NULL, /* dump_queues */ \
953 NULL, /* dump_queue_stats */ \
955 NULL, /* get_in4 */ \
956 NULL, /* set_in4 */ \
957 NULL, /* get_in6 */ \
958 NULL, /* add_router */ \
959 NULL, /* get_next_hop */ \
961 NULL, /* arp_lookup */ \
963 netdev_vport_update_flags, \
965 netdev_vport_poll_add, \
966 netdev_vport_poll_remove,
969 netdev_vport_register(void)
971 static const struct vport_class vport_classes[] = {
972 { ODP_VPORT_TYPE_GRE,
973 { "gre", VPORT_FUNCTIONS(netdev_vport_get_status) },
974 parse_tunnel_config, unparse_tunnel_config },
976 { ODP_VPORT_TYPE_GRE,
977 { "ipsec_gre", VPORT_FUNCTIONS(netdev_vport_get_status) },
978 parse_tunnel_config, unparse_tunnel_config },
980 { ODP_VPORT_TYPE_CAPWAP,
981 { "capwap", VPORT_FUNCTIONS(netdev_vport_get_status) },
982 parse_tunnel_config, unparse_tunnel_config },
984 { ODP_VPORT_TYPE_PATCH,
985 { "patch", VPORT_FUNCTIONS(NULL) },
986 parse_patch_config, unparse_patch_config }
991 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
992 netdev_register_provider(&vport_classes[i].netdev_class);