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"
31 #include "dpif-linux.h"
35 #include "netdev-linux.h"
36 #include "netdev-provider.h"
38 #include "netlink-socket.h"
40 #include "openvswitch/datapath-protocol.h"
41 #include "openvswitch/tunnel.h"
43 #include "route-table.h"
44 #include "rtnetlink.h"
46 #include "socket-util.h"
49 VLOG_DEFINE_THIS_MODULE(netdev_vport);
51 struct netdev_vport_notifier {
52 struct netdev_notifier notifier;
53 struct list list_node;
54 struct shash_node *shash_node;
57 struct netdev_dev_vport {
58 struct netdev_dev netdev_dev;
59 struct ofpbuf *options;
60 int dp_ifindex; /* -1 if unknown. */
61 uint32_t port_no; /* UINT32_MAX if unknown. */
69 enum odp_vport_type type;
70 struct netdev_class netdev_class;
71 int (*parse_config)(const char *name, const char *type,
72 const struct shash *args, struct ofpbuf *options);
73 int (*unparse_config)(const char *name, const char *type,
74 const struct nlattr *options, size_t options_len,
78 static struct shash netdev_vport_notifiers =
79 SHASH_INITIALIZER(&netdev_vport_notifiers);
81 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
83 static int netdev_vport_create(const struct netdev_class *, const char *,
84 const struct shash *, struct netdev_dev **);
85 static void netdev_vport_poll_notify(const struct netdev *);
86 static int tnl_port_config_from_nlattr(const struct nlattr *options,
88 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1]);
90 static const char *netdev_vport_get_tnl_iface(const struct netdev *netdev);
93 is_vport_class(const struct netdev_class *class)
95 return class->create == netdev_vport_create;
98 static const struct vport_class *
99 vport_class_cast(const struct netdev_class *class)
101 assert(is_vport_class(class));
102 return CONTAINER_OF(class, struct vport_class, netdev_class);
105 static struct netdev_dev_vport *
106 netdev_dev_vport_cast(const struct netdev_dev *netdev_dev)
108 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
109 return CONTAINER_OF(netdev_dev, struct netdev_dev_vport, netdev_dev);
112 static struct netdev_vport *
113 netdev_vport_cast(const struct netdev *netdev)
115 struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
116 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
117 return CONTAINER_OF(netdev, struct netdev_vport, netdev);
120 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
121 * options to include in ODP_VPORT_ATTR_OPTIONS for configuring that vport.
122 * Otherwise returns NULL. */
123 const struct ofpbuf *
124 netdev_vport_get_options(const struct netdev *netdev)
126 const struct netdev_dev *dev = netdev_get_dev(netdev);
128 return (is_vport_class(netdev_dev_get_class(dev))
129 ? netdev_dev_vport_cast(dev)->options
134 netdev_vport_get_vport_type(const struct netdev *netdev)
136 const struct netdev_dev *dev = netdev_get_dev(netdev);
137 const struct netdev_class *class = netdev_dev_get_class(dev);
139 return (is_vport_class(class) ? vport_class_cast(class)->type
140 : class == &netdev_internal_class ? ODP_VPORT_TYPE_INTERNAL
141 : class == &netdev_linux_class ? ODP_VPORT_TYPE_NETDEV
142 : ODP_VPORT_TYPE_UNSPEC);
146 netdev_vport_get_netdev_type(const struct dpif_linux_vport *vport)
148 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1];
150 switch (vport->type) {
151 case ODP_VPORT_TYPE_UNSPEC:
154 case ODP_VPORT_TYPE_NETDEV:
157 case ODP_VPORT_TYPE_INTERNAL:
160 case ODP_VPORT_TYPE_PATCH:
163 case ODP_VPORT_TYPE_GRE:
164 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
168 return (nl_attr_get_u32(a[ODP_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
169 ? "ipsec_gre" : "gre");
171 case ODP_VPORT_TYPE_CAPWAP:
174 case __ODP_VPORT_TYPE_MAX:
178 VLOG_WARN_RL(&rl, "dp%d: port `%s' has unsupported type %u",
179 vport->dp_ifindex, vport->name, (unsigned int) vport->type);
184 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
185 const struct shash *args,
186 struct netdev_dev **netdev_devp)
188 const struct vport_class *vport_class = vport_class_cast(netdev_class);
189 struct ofpbuf *options = NULL;
190 struct shash fetched_args;
195 shash_init(&fetched_args);
198 port_no = UINT32_MAX;
199 if (!shash_is_empty(args)) {
200 /* Parse the provided configuration. */
201 options = ofpbuf_new(64);
202 error = vport_class->parse_config(name, netdev_class->type,
205 /* Fetch an existing configuration from the kernel.
207 * This case could be ambiguous with initializing a new vport with an
208 * empty configuration, but none of the existing vport classes accept
209 * an empty configuration. */
210 struct dpif_linux_vport reply;
213 error = dpif_linux_vport_get(name, &reply, &buf);
215 /* XXX verify correct type */
216 error = vport_class->unparse_config(name, netdev_class->type,
221 VLOG_ERR_RL(&rl, "%s: failed to parse kernel config (%s)",
222 name, strerror(error));
224 options = ofpbuf_clone_data(reply.options, reply.options_len);
225 dp_ifindex = reply.dp_ifindex;
226 port_no = reply.port_no;
230 VLOG_ERR_RL(&rl, "%s: vport query failed (%s)",
231 name, strerror(error));
236 struct netdev_dev_vport *dev;
238 dev = xmalloc(sizeof *dev);
239 netdev_dev_init(&dev->netdev_dev, name,
240 shash_is_empty(&fetched_args) ? args : &fetched_args,
242 dev->options = options;
243 dev->dp_ifindex = dp_ifindex;
244 dev->port_no = port_no;
246 *netdev_devp = &dev->netdev_dev;
247 route_table_register();
249 ofpbuf_delete(options);
252 shash_destroy(&fetched_args);
258 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
260 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
262 route_table_unregister();
267 netdev_vport_open(struct netdev_dev *netdev_dev_, int ethertype OVS_UNUSED,
268 struct netdev **netdevp)
270 struct netdev_vport *netdev;
272 netdev = xmalloc(sizeof *netdev);
273 netdev_init(&netdev->netdev, netdev_dev_);
275 *netdevp = &netdev->netdev;
280 netdev_vport_close(struct netdev *netdev_)
282 struct netdev_vport *netdev = netdev_vport_cast(netdev_);
287 netdev_vport_set_config(struct netdev_dev *dev_, const struct shash *args)
289 const struct netdev_class *netdev_class = netdev_dev_get_class(dev_);
290 const struct vport_class *vport_class = vport_class_cast(netdev_class);
291 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
292 const char *name = netdev_dev_get_name(dev_);
293 struct ofpbuf *options;
296 options = ofpbuf_new(64);
297 error = vport_class->parse_config(name, netdev_dev_get_type(dev_),
300 && (options->size != dev->options->size
301 || memcmp(options->data, dev->options->data, options->size))) {
302 struct dpif_linux_vport vport;
304 dpif_linux_vport_init(&vport);
305 vport.cmd = ODP_VPORT_CMD_SET;
307 vport.options = options->data;
308 vport.options_len = options->size;
309 error = dpif_linux_vport_transact(&vport, NULL, NULL);
310 if (!error || error == ENODEV) {
311 /* Either reconfiguration succeeded or this vport is not installed
312 * in the kernel (e.g. it hasn't been added to a dpif yet with
313 * dpif_port_add()). */
314 ofpbuf_delete(dev->options);
315 dev->options = options;
320 ofpbuf_delete(options);
326 netdev_vport_send(struct netdev *netdev, const void *data, size_t size)
328 struct netdev_dev *dev_ = netdev_get_dev(netdev);
329 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
331 if (dev->dp_ifindex == -1) {
332 const char *name = netdev_get_name(netdev);
333 struct dpif_linux_vport reply;
337 error = dpif_linux_vport_get(name, &reply, &buf);
339 VLOG_ERR_RL(&rl, "%s: failed to query vport for send (%s)",
340 name, strerror(error));
343 dev->dp_ifindex = reply.dp_ifindex;
344 dev->port_no = reply.port_no;
348 return dpif_linux_vport_send(dev->dp_ifindex, dev->port_no, data, size);
352 netdev_vport_set_etheraddr(struct netdev *netdev,
353 const uint8_t mac[ETH_ADDR_LEN])
355 struct dpif_linux_vport vport;
358 dpif_linux_vport_init(&vport);
359 vport.cmd = ODP_VPORT_CMD_SET;
360 vport.name = netdev_get_name(netdev);
363 error = dpif_linux_vport_transact(&vport, NULL, NULL);
365 netdev_vport_poll_notify(netdev);
371 netdev_vport_get_etheraddr(const struct netdev *netdev,
372 uint8_t mac[ETH_ADDR_LEN])
374 struct dpif_linux_vport reply;
378 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
381 memcpy(mac, reply.address, ETH_ADDR_LEN);
391 netdev_vport_get_mtu(const struct netdev *netdev, int *mtup)
393 struct dpif_linux_vport reply;
397 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
406 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
408 struct dpif_linux_vport reply;
412 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
415 } else if (!reply.stats) {
420 netdev_stats_from_rtnl_link_stats64(stats, reply.stats);
428 netdev_vport_set_stats(struct netdev *netdev, const struct netdev_stats *stats)
430 struct rtnl_link_stats64 rtnl_stats;
431 struct dpif_linux_vport vport;
434 netdev_stats_to_rtnl_link_stats64(&rtnl_stats, stats);
436 dpif_linux_vport_init(&vport);
437 vport.cmd = ODP_VPORT_CMD_SET;
438 vport.name = netdev_get_name(netdev);
439 vport.stats = &rtnl_stats;
441 err = dpif_linux_vport_transact(&vport, NULL, NULL);
443 /* If the vport layer doesn't know about the device, that doesn't mean it
444 * doesn't exist (after all were able to open it when netdev_open() was
445 * called), it just means that it isn't attached and we'll be getting
446 * stats a different way. */
455 netdev_vport_get_status(const struct netdev *netdev, struct shash *sh)
457 const char *iface = netdev_vport_get_tnl_iface(netdev);
460 struct netdev *egress_netdev;
462 shash_add(sh, "tunnel_egress_iface", xstrdup(iface));
464 if (!netdev_open_default(iface, &egress_netdev)) {
465 shash_add(sh, "tunnel_egress_iface_carrier",
466 xstrdup(netdev_get_carrier(egress_netdev)
468 netdev_close(egress_netdev);
476 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
477 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
478 enum netdev_flags *old_flagsp)
480 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
484 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
489 make_poll_name(const struct netdev *netdev)
491 return xasprintf("%s:%s", netdev_get_type(netdev), netdev_get_name(netdev));
495 netdev_vport_poll_add(struct netdev *netdev,
496 void (*cb)(struct netdev_notifier *), void *aux,
497 struct netdev_notifier **notifierp)
499 char *poll_name = make_poll_name(netdev);
500 struct netdev_vport_notifier *notifier;
502 struct shash_node *shash_node;
504 shash_node = shash_find(&netdev_vport_notifiers, poll_name);
506 list = xmalloc(sizeof *list);
508 shash_node = shash_add(&netdev_vport_notifiers, poll_name, list);
510 list = shash_node->data;
513 notifier = xmalloc(sizeof *notifier);
514 netdev_notifier_init(¬ifier->notifier, netdev, cb, aux);
515 list_push_back(list, ¬ifier->list_node);
516 notifier->shash_node = shash_node;
518 *notifierp = ¬ifier->notifier;
525 netdev_vport_poll_remove(struct netdev_notifier *notifier_)
527 struct netdev_vport_notifier *notifier =
528 CONTAINER_OF(notifier_, struct netdev_vport_notifier, notifier);
532 list = list_remove(¬ifier->list_node);
533 if (list_is_empty(list)) {
534 shash_delete(&netdev_vport_notifiers, notifier->shash_node);
542 netdev_vport_run(void)
548 netdev_vport_wait(void)
553 /* get_tnl_iface() implementation. */
555 netdev_vport_get_tnl_iface(const struct netdev *netdev)
557 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1];
559 struct netdev_dev_vport *ndv;
560 static char name[IFNAMSIZ];
562 ndv = netdev_dev_vport_cast(netdev_get_dev(netdev));
563 if (tnl_port_config_from_nlattr(ndv->options->data, ndv->options->size,
567 route = nl_attr_get_be32(a[ODP_TUNNEL_ATTR_DST_IPV4]);
569 if (route_table_get_name(route, name)) {
576 /* Helper functions. */
579 netdev_vport_poll_notify(const struct netdev *netdev)
581 char *poll_name = make_poll_name(netdev);
582 struct list *list = shash_find_data(&netdev_vport_notifiers,
586 struct netdev_vport_notifier *notifier;
588 LIST_FOR_EACH (notifier, list_node, list) {
589 struct netdev_notifier *n = ¬ifier->notifier;
597 /* Code specific to individual vport types. */
600 set_key(const struct shash *args, const char *name, uint16_t type,
601 struct ofpbuf *options)
605 s = shash_find_data(args, name);
607 s = shash_find_data(args, "key");
613 if (!strcmp(s, "flow")) {
614 /* This is the default if no attribute is present. */
616 nl_msg_put_be64(options, type, htonll(strtoull(s, NULL, 0)));
621 parse_tunnel_config(const char *name, const char *type,
622 const struct shash *args, struct ofpbuf *options)
625 bool is_ipsec = false;
626 struct shash_node *node;
627 bool ipsec_mech_set = false;
628 ovs_be32 daddr = htonl(0);
631 flags = TNL_F_DF_DEFAULT | TNL_F_PMTUD | TNL_F_HDR_CACHE;
632 if (!strcmp(type, "gre")) {
634 } else if (!strcmp(type, "ipsec_gre")) {
637 flags |= TNL_F_IPSEC;
638 flags &= ~TNL_F_HDR_CACHE;
641 SHASH_FOR_EACH (node, args) {
642 if (!strcmp(node->name, "remote_ip")) {
643 struct in_addr in_addr;
644 if (lookup_ip(node->data, &in_addr)) {
645 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
647 daddr = in_addr.s_addr;
649 } else if (!strcmp(node->name, "local_ip")) {
650 struct in_addr in_addr;
651 if (lookup_ip(node->data, &in_addr)) {
652 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
654 nl_msg_put_be32(options, ODP_TUNNEL_ATTR_SRC_IPV4,
657 } else if (!strcmp(node->name, "tos")) {
658 if (!strcmp(node->data, "inherit")) {
659 flags |= TNL_F_TOS_INHERIT;
661 nl_msg_put_u8(options, ODP_TUNNEL_ATTR_TOS, atoi(node->data));
663 } else if (!strcmp(node->name, "ttl")) {
664 if (!strcmp(node->data, "inherit")) {
665 flags |= TNL_F_TTL_INHERIT;
667 nl_msg_put_u8(options, ODP_TUNNEL_ATTR_TTL, atoi(node->data));
669 } else if (!strcmp(node->name, "csum") && is_gre) {
670 if (!strcmp(node->data, "true")) {
673 } else if (!strcmp(node->name, "df_inherit")) {
674 if (!strcmp(node->data, "true")) {
675 flags |= TNL_F_DF_INHERIT;
677 } else if (!strcmp(node->name, "df_default")) {
678 if (!strcmp(node->data, "false")) {
679 flags &= ~TNL_F_DF_DEFAULT;
681 } else if (!strcmp(node->name, "pmtud")) {
682 if (!strcmp(node->data, "false")) {
683 flags &= ~TNL_F_PMTUD;
685 } else if (!strcmp(node->name, "header_cache")) {
686 if (!strcmp(node->data, "false")) {
687 flags &= ~TNL_F_HDR_CACHE;
689 } else if (!strcmp(node->name, "peer_cert") && is_ipsec) {
690 if (shash_find(args, "certificate")) {
691 ipsec_mech_set = true;
693 const char *use_ssl_cert;
695 /* If the "use_ssl_cert" is true, then "certificate" and
696 * "private_key" will be pulled from the SSL table. The
697 * use of this option is strongly discouraged, since it
698 * will like be removed when multiple SSL configurations
699 * are supported by OVS.
701 use_ssl_cert = shash_find_data(args, "use_ssl_cert");
702 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
703 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
707 ipsec_mech_set = true;
709 } else if (!strcmp(node->name, "psk") && is_ipsec) {
710 ipsec_mech_set = true;
712 && (!strcmp(node->name, "certificate")
713 || !strcmp(node->name, "private_key")
714 || !strcmp(node->name, "use_ssl_cert"))) {
715 /* Ignore options not used by the netdev. */
716 } else if (is_gre && (!strcmp(node->name, "key") ||
717 !strcmp(node->name, "in_key") ||
718 !strcmp(node->name, "out_key"))) {
719 /* Handled separately below. */
721 VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->name);
726 char *file_name = xasprintf("%s/%s", ovs_rundir(),
727 "ovs-monitor-ipsec.pid");
728 pid_t pid = read_pidfile(file_name);
731 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
736 if (shash_find(args, "peer_cert") && shash_find(args, "psk")) {
737 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name);
741 if (!ipsec_mech_set) {
742 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
749 set_key(args, "in_key", ODP_TUNNEL_ATTR_IN_KEY, options);
750 set_key(args, "out_key", ODP_TUNNEL_ATTR_OUT_KEY, options);
754 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
758 nl_msg_put_be32(options, ODP_TUNNEL_ATTR_DST_IPV4, daddr);
760 nl_msg_put_u32(options, ODP_TUNNEL_ATTR_FLAGS, flags);
766 tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len,
767 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1])
769 static const struct nl_policy odp_tunnel_policy[] = {
770 [ODP_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32 },
771 [ODP_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32 },
772 [ODP_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true },
773 [ODP_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true },
774 [ODP_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true },
775 [ODP_TUNNEL_ATTR_TOS] = { .type = NL_A_U8, .optional = true },
776 [ODP_TUNNEL_ATTR_TTL] = { .type = NL_A_U8, .optional = true },
780 ofpbuf_use_const(&buf, options, options_len);
781 if (!nl_policy_parse(&buf, 0, odp_tunnel_policy,
782 a, ARRAY_SIZE(odp_tunnel_policy))) {
789 get_be64_or_zero(const struct nlattr *a)
791 return a ? ntohll(nl_attr_get_be64(a)) : 0;
795 unparse_tunnel_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
796 const struct nlattr *options, size_t options_len,
799 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1];
804 error = tnl_port_config_from_nlattr(options, options_len, a);
809 flags = nl_attr_get_u32(a[ODP_TUNNEL_ATTR_FLAGS]);
810 if (!(flags & TNL_F_HDR_CACHE) == !(flags & TNL_F_IPSEC)) {
811 smap_add(args, "header_cache",
812 flags & TNL_F_HDR_CACHE ? "true" : "false");
815 daddr = nl_attr_get_be32(a[ODP_TUNNEL_ATTR_DST_IPV4]);
816 shash_add(args, "remote_ip", xasprintf(IP_FMT, IP_ARGS(&daddr)));
818 if (a[ODP_TUNNEL_ATTR_SRC_IPV4]) {
819 ovs_be32 saddr = nl_attr_get_be32(a[ODP_TUNNEL_ATTR_SRC_IPV4]);
820 shash_add(args, "local_ip", xasprintf(IP_FMT, IP_ARGS(&saddr)));
823 if (!a[ODP_TUNNEL_ATTR_IN_KEY] && !a[ODP_TUNNEL_ATTR_OUT_KEY]) {
824 smap_add(args, "key", "flow");
826 uint64_t in_key = get_be64_or_zero(a[ODP_TUNNEL_ATTR_IN_KEY]);
827 uint64_t out_key = get_be64_or_zero(a[ODP_TUNNEL_ATTR_OUT_KEY]);
829 if (in_key && in_key == out_key) {
830 shash_add(args, "key", xasprintf("%"PRIu64, in_key));
832 if (!a[ODP_TUNNEL_ATTR_IN_KEY]) {
833 smap_add(args, "in_key", "flow");
835 shash_add(args, "in_key", xasprintf("%"PRIu64, in_key));
838 if (!a[ODP_TUNNEL_ATTR_OUT_KEY]) {
839 smap_add(args, "out_key", "flow");
840 } else if (out_key) {
841 shash_add(args, "out_key", xasprintf("%"PRIu64, out_key));
846 if (flags & TNL_F_TTL_INHERIT) {
847 smap_add(args, "tos", "inherit");
848 } else if (a[ODP_TUNNEL_ATTR_TTL]) {
849 int ttl = nl_attr_get_u8(a[ODP_TUNNEL_ATTR_TTL]);
850 shash_add(args, "tos", xasprintf("%d", ttl));
853 if (flags & TNL_F_TOS_INHERIT) {
854 smap_add(args, "tos", "inherit");
855 } else if (a[ODP_TUNNEL_ATTR_TOS]) {
856 int tos = nl_attr_get_u8(a[ODP_TUNNEL_ATTR_TOS]);
857 shash_add(args, "tos", xasprintf("%d", tos));
860 if (flags & TNL_F_CSUM) {
861 smap_add(args, "csum", "true");
863 if (flags & TNL_F_DF_INHERIT) {
864 smap_add(args, "df_inherit", "true");
866 if (!(flags & TNL_F_DF_DEFAULT)) {
867 smap_add(args, "df_default", "false");
869 if (!(flags & TNL_F_PMTUD)) {
870 smap_add(args, "pmtud", "false");
877 parse_patch_config(const char *name, const char *type OVS_UNUSED,
878 const struct shash *args, struct ofpbuf *options)
882 peer = shash_find_data(args, "peer");
884 VLOG_ERR("%s: patch type requires valid 'peer' argument", name);
888 if (shash_count(args) > 1) {
889 VLOG_ERR("%s: patch type takes only a 'peer' argument", name);
893 if (strlen(peer) >= IFNAMSIZ) {
894 VLOG_ERR("%s: patch 'peer' arg too long", name);
898 if (!strcmp(name, peer)) {
899 VLOG_ERR("%s: patch peer must not be self", name);
903 nl_msg_put_string(options, ODP_PATCH_ATTR_PEER, peer);
909 unparse_patch_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
910 const struct nlattr *options, size_t options_len,
913 static const struct nl_policy odp_patch_policy[] = {
914 [ODP_PATCH_ATTR_PEER] = { .type = NL_A_STRING,
919 struct nlattr *a[ARRAY_SIZE(odp_patch_policy)];
922 ofpbuf_use_const(&buf, options, options_len);
923 if (!nl_policy_parse(&buf, 0, odp_patch_policy,
924 a, ARRAY_SIZE(odp_patch_policy))) {
928 smap_add(args, "peer", nl_attr_get_string(a[ODP_PATCH_ATTR_PEER]));
932 #define VPORT_FUNCTIONS(GET_STATUS) \
937 netdev_vport_create, \
938 netdev_vport_destroy, \
939 netdev_vport_set_config, \
942 netdev_vport_close, \
944 NULL, /* enumerate */ \
947 NULL, /* recv_wait */ \
950 netdev_vport_send, /* send */ \
951 NULL, /* send_wait */ \
953 netdev_vport_set_etheraddr, \
954 netdev_vport_get_etheraddr, \
955 netdev_vport_get_mtu, \
956 NULL, /* get_ifindex */ \
957 NULL, /* get_carrier */ \
958 NULL, /* get_miimon */ \
959 netdev_vport_get_stats, \
960 netdev_vport_set_stats, \
962 NULL, /* get_features */ \
963 NULL, /* set_advertisements */ \
964 NULL, /* get_vlan_vid */ \
966 NULL, /* set_policing */ \
967 NULL, /* get_qos_types */ \
968 NULL, /* get_qos_capabilities */ \
969 NULL, /* get_qos */ \
970 NULL, /* set_qos */ \
971 NULL, /* get_queue */ \
972 NULL, /* set_queue */ \
973 NULL, /* delete_queue */ \
974 NULL, /* get_queue_stats */ \
975 NULL, /* dump_queues */ \
976 NULL, /* dump_queue_stats */ \
978 NULL, /* get_in4 */ \
979 NULL, /* set_in4 */ \
980 NULL, /* get_in6 */ \
981 NULL, /* add_router */ \
982 NULL, /* get_next_hop */ \
984 NULL, /* arp_lookup */ \
986 netdev_vport_update_flags, \
988 netdev_vport_poll_add, \
989 netdev_vport_poll_remove,
992 netdev_vport_register(void)
994 static const struct vport_class vport_classes[] = {
995 { ODP_VPORT_TYPE_GRE,
996 { "gre", VPORT_FUNCTIONS(netdev_vport_get_status) },
997 parse_tunnel_config, unparse_tunnel_config },
999 { ODP_VPORT_TYPE_GRE,
1000 { "ipsec_gre", VPORT_FUNCTIONS(netdev_vport_get_status) },
1001 parse_tunnel_config, unparse_tunnel_config },
1003 { ODP_VPORT_TYPE_CAPWAP,
1004 { "capwap", VPORT_FUNCTIONS(netdev_vport_get_status) },
1005 parse_tunnel_config, unparse_tunnel_config },
1007 { ODP_VPORT_TYPE_PATCH,
1008 { "patch", VPORT_FUNCTIONS(NULL) },
1009 parse_patch_config, unparse_patch_config }
1014 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
1015 netdev_register_provider(&vport_classes[i].netdev_class);