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_dev_vport {
52 struct netdev_dev netdev_dev;
53 struct ofpbuf *options;
54 int dp_ifindex; /* -1 if unknown. */
55 uint32_t port_no; /* UINT32_MAX if unknown. */
56 unsigned int change_seq;
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 vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
75 static int netdev_vport_create(const struct netdev_class *, const char *,
76 const struct shash *, struct netdev_dev **);
77 static void netdev_vport_poll_notify(const struct netdev *);
78 static int tnl_port_config_from_nlattr(const struct nlattr *options,
80 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1]);
82 static const char *netdev_vport_get_tnl_iface(const struct netdev *netdev);
85 is_vport_class(const struct netdev_class *class)
87 return class->create == netdev_vport_create;
90 static const struct vport_class *
91 vport_class_cast(const struct netdev_class *class)
93 assert(is_vport_class(class));
94 return CONTAINER_OF(class, struct vport_class, netdev_class);
97 static struct netdev_dev_vport *
98 netdev_dev_vport_cast(const struct netdev_dev *netdev_dev)
100 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
101 return CONTAINER_OF(netdev_dev, struct netdev_dev_vport, netdev_dev);
104 static struct netdev_vport *
105 netdev_vport_cast(const struct netdev *netdev)
107 struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
108 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
109 return CONTAINER_OF(netdev, struct netdev_vport, netdev);
112 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
113 * options to include in ODP_VPORT_ATTR_OPTIONS for configuring that vport.
114 * Otherwise returns NULL. */
115 const struct ofpbuf *
116 netdev_vport_get_options(const struct netdev *netdev)
118 const struct netdev_dev *dev = netdev_get_dev(netdev);
120 return (is_vport_class(netdev_dev_get_class(dev))
121 ? netdev_dev_vport_cast(dev)->options
126 netdev_vport_get_vport_type(const struct netdev *netdev)
128 const struct netdev_dev *dev = netdev_get_dev(netdev);
129 const struct netdev_class *class = netdev_dev_get_class(dev);
131 return (is_vport_class(class) ? vport_class_cast(class)->type
132 : class == &netdev_internal_class ? ODP_VPORT_TYPE_INTERNAL
133 : class == &netdev_linux_class ? ODP_VPORT_TYPE_NETDEV
134 : ODP_VPORT_TYPE_UNSPEC);
138 netdev_vport_get_netdev_type(const struct dpif_linux_vport *vport)
140 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1];
142 switch (vport->type) {
143 case ODP_VPORT_TYPE_UNSPEC:
146 case ODP_VPORT_TYPE_NETDEV:
149 case ODP_VPORT_TYPE_INTERNAL:
152 case ODP_VPORT_TYPE_PATCH:
155 case ODP_VPORT_TYPE_GRE:
156 if (tnl_port_config_from_nlattr(vport->options, vport->options_len,
160 return (nl_attr_get_u32(a[ODP_TUNNEL_ATTR_FLAGS]) & TNL_F_IPSEC
161 ? "ipsec_gre" : "gre");
163 case ODP_VPORT_TYPE_CAPWAP:
166 case __ODP_VPORT_TYPE_MAX:
170 VLOG_WARN_RL(&rl, "dp%d: port `%s' has unsupported type %u",
171 vport->dp_ifindex, vport->name, (unsigned int) vport->type);
176 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
177 const struct shash *args,
178 struct netdev_dev **netdev_devp)
180 const struct vport_class *vport_class = vport_class_cast(netdev_class);
181 struct ofpbuf *options = NULL;
182 struct shash fetched_args;
187 shash_init(&fetched_args);
190 port_no = UINT32_MAX;
191 if (!shash_is_empty(args)) {
192 /* Parse the provided configuration. */
193 options = ofpbuf_new(64);
194 error = vport_class->parse_config(name, netdev_class->type,
197 /* Fetch an existing configuration from the kernel.
199 * This case could be ambiguous with initializing a new vport with an
200 * empty configuration, but none of the existing vport classes accept
201 * an empty configuration. */
202 struct dpif_linux_vport reply;
205 error = dpif_linux_vport_get(name, &reply, &buf);
207 /* XXX verify correct type */
208 error = vport_class->unparse_config(name, netdev_class->type,
213 VLOG_ERR_RL(&rl, "%s: failed to parse kernel config (%s)",
214 name, strerror(error));
216 options = ofpbuf_clone_data(reply.options, reply.options_len);
217 dp_ifindex = reply.dp_ifindex;
218 port_no = reply.port_no;
222 VLOG_ERR_RL(&rl, "%s: vport query failed (%s)",
223 name, strerror(error));
228 struct netdev_dev_vport *dev;
230 dev = xmalloc(sizeof *dev);
231 netdev_dev_init(&dev->netdev_dev, name,
232 shash_is_empty(&fetched_args) ? args : &fetched_args,
234 dev->options = options;
235 dev->dp_ifindex = dp_ifindex;
236 dev->port_no = port_no;
239 *netdev_devp = &dev->netdev_dev;
240 route_table_register();
242 ofpbuf_delete(options);
245 shash_destroy(&fetched_args);
251 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
253 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
255 route_table_unregister();
260 netdev_vport_open(struct netdev_dev *netdev_dev_, int ethertype OVS_UNUSED,
261 struct netdev **netdevp)
263 struct netdev_vport *netdev;
265 netdev = xmalloc(sizeof *netdev);
266 netdev_init(&netdev->netdev, netdev_dev_);
268 *netdevp = &netdev->netdev;
273 netdev_vport_close(struct netdev *netdev_)
275 struct netdev_vport *netdev = netdev_vport_cast(netdev_);
280 netdev_vport_set_config(struct netdev_dev *dev_, const struct shash *args)
282 const struct netdev_class *netdev_class = netdev_dev_get_class(dev_);
283 const struct vport_class *vport_class = vport_class_cast(netdev_class);
284 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
285 const char *name = netdev_dev_get_name(dev_);
286 struct ofpbuf *options;
289 options = ofpbuf_new(64);
290 error = vport_class->parse_config(name, netdev_dev_get_type(dev_),
293 && (options->size != dev->options->size
294 || memcmp(options->data, dev->options->data, options->size))) {
295 struct dpif_linux_vport vport;
297 dpif_linux_vport_init(&vport);
298 vport.cmd = ODP_VPORT_CMD_SET;
300 vport.options = options->data;
301 vport.options_len = options->size;
302 error = dpif_linux_vport_transact(&vport, NULL, NULL);
303 if (!error || error == ENODEV) {
304 /* Either reconfiguration succeeded or this vport is not installed
305 * in the kernel (e.g. it hasn't been added to a dpif yet with
306 * dpif_port_add()). */
307 ofpbuf_delete(dev->options);
308 dev->options = options;
313 ofpbuf_delete(options);
319 netdev_vport_send(struct netdev *netdev, const void *data, size_t size)
321 struct netdev_dev *dev_ = netdev_get_dev(netdev);
322 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
324 if (dev->dp_ifindex == -1) {
325 const char *name = netdev_get_name(netdev);
326 struct dpif_linux_vport reply;
330 error = dpif_linux_vport_get(name, &reply, &buf);
332 VLOG_ERR_RL(&rl, "%s: failed to query vport for send (%s)",
333 name, strerror(error));
336 dev->dp_ifindex = reply.dp_ifindex;
337 dev->port_no = reply.port_no;
341 return dpif_linux_vport_send(dev->dp_ifindex, dev->port_no, data, size);
345 netdev_vport_set_etheraddr(struct netdev *netdev,
346 const uint8_t mac[ETH_ADDR_LEN])
348 struct dpif_linux_vport vport;
351 dpif_linux_vport_init(&vport);
352 vport.cmd = ODP_VPORT_CMD_SET;
353 vport.name = netdev_get_name(netdev);
356 error = dpif_linux_vport_transact(&vport, NULL, NULL);
358 netdev_vport_poll_notify(netdev);
364 netdev_vport_get_etheraddr(const struct netdev *netdev,
365 uint8_t mac[ETH_ADDR_LEN])
367 struct dpif_linux_vport reply;
371 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
374 memcpy(mac, reply.address, ETH_ADDR_LEN);
384 netdev_vport_get_mtu(const struct netdev *netdev, int *mtup)
386 struct dpif_linux_vport reply;
390 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
399 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
401 struct dpif_linux_vport reply;
405 error = dpif_linux_vport_get(netdev_get_name(netdev), &reply, &buf);
408 } else if (!reply.stats) {
413 netdev_stats_from_rtnl_link_stats64(stats, reply.stats);
421 netdev_vport_set_stats(struct netdev *netdev, const struct netdev_stats *stats)
423 struct rtnl_link_stats64 rtnl_stats;
424 struct dpif_linux_vport vport;
427 netdev_stats_to_rtnl_link_stats64(&rtnl_stats, stats);
429 dpif_linux_vport_init(&vport);
430 vport.cmd = ODP_VPORT_CMD_SET;
431 vport.name = netdev_get_name(netdev);
432 vport.stats = &rtnl_stats;
434 err = dpif_linux_vport_transact(&vport, NULL, NULL);
436 /* If the vport layer doesn't know about the device, that doesn't mean it
437 * doesn't exist (after all were able to open it when netdev_open() was
438 * called), it just means that it isn't attached and we'll be getting
439 * stats a different way. */
448 netdev_vport_get_status(const struct netdev *netdev, struct shash *sh)
450 const char *iface = netdev_vport_get_tnl_iface(netdev);
453 struct netdev *egress_netdev;
455 shash_add(sh, "tunnel_egress_iface", xstrdup(iface));
457 if (!netdev_open_default(iface, &egress_netdev)) {
458 shash_add(sh, "tunnel_egress_iface_carrier",
459 xstrdup(netdev_get_carrier(egress_netdev)
461 netdev_close(egress_netdev);
469 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
470 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
471 enum netdev_flags *old_flagsp)
473 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
477 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
482 netdev_vport_change_seq(const struct netdev *netdev)
484 return netdev_dev_vport_cast(netdev_get_dev(netdev))->change_seq;
488 netdev_vport_run(void)
494 netdev_vport_wait(void)
499 /* get_tnl_iface() implementation. */
501 netdev_vport_get_tnl_iface(const struct netdev *netdev)
503 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1];
505 struct netdev_dev_vport *ndv;
506 static char name[IFNAMSIZ];
508 ndv = netdev_dev_vport_cast(netdev_get_dev(netdev));
509 if (tnl_port_config_from_nlattr(ndv->options->data, ndv->options->size,
513 route = nl_attr_get_be32(a[ODP_TUNNEL_ATTR_DST_IPV4]);
515 if (route_table_get_name(route, name)) {
522 /* Helper functions. */
525 netdev_vport_poll_notify(const struct netdev *netdev)
527 struct netdev_dev_vport *ndv;
529 ndv = netdev_dev_vport_cast(netdev_get_dev(netdev));
532 if (!ndv->change_seq) {
537 /* Code specific to individual vport types. */
540 set_key(const struct shash *args, const char *name, uint16_t type,
541 struct ofpbuf *options)
545 s = shash_find_data(args, name);
547 s = shash_find_data(args, "key");
553 if (!strcmp(s, "flow")) {
554 /* This is the default if no attribute is present. */
556 nl_msg_put_be64(options, type, htonll(strtoull(s, NULL, 0)));
561 parse_tunnel_config(const char *name, const char *type,
562 const struct shash *args, struct ofpbuf *options)
565 bool is_ipsec = false;
566 struct shash_node *node;
567 bool ipsec_mech_set = false;
568 ovs_be32 daddr = htonl(0);
571 flags = TNL_F_DF_DEFAULT | TNL_F_PMTUD | TNL_F_HDR_CACHE;
572 if (!strcmp(type, "gre")) {
574 } else if (!strcmp(type, "ipsec_gre")) {
577 flags |= TNL_F_IPSEC;
578 flags &= ~TNL_F_HDR_CACHE;
581 SHASH_FOR_EACH (node, args) {
582 if (!strcmp(node->name, "remote_ip")) {
583 struct in_addr in_addr;
584 if (lookup_ip(node->data, &in_addr)) {
585 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
587 daddr = in_addr.s_addr;
589 } else if (!strcmp(node->name, "local_ip")) {
590 struct in_addr in_addr;
591 if (lookup_ip(node->data, &in_addr)) {
592 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
594 nl_msg_put_be32(options, ODP_TUNNEL_ATTR_SRC_IPV4,
597 } else if (!strcmp(node->name, "tos")) {
598 if (!strcmp(node->data, "inherit")) {
599 flags |= TNL_F_TOS_INHERIT;
601 nl_msg_put_u8(options, ODP_TUNNEL_ATTR_TOS, atoi(node->data));
603 } else if (!strcmp(node->name, "ttl")) {
604 if (!strcmp(node->data, "inherit")) {
605 flags |= TNL_F_TTL_INHERIT;
607 nl_msg_put_u8(options, ODP_TUNNEL_ATTR_TTL, atoi(node->data));
609 } else if (!strcmp(node->name, "csum") && is_gre) {
610 if (!strcmp(node->data, "true")) {
613 } else if (!strcmp(node->name, "df_inherit")) {
614 if (!strcmp(node->data, "true")) {
615 flags |= TNL_F_DF_INHERIT;
617 } else if (!strcmp(node->name, "df_default")) {
618 if (!strcmp(node->data, "false")) {
619 flags &= ~TNL_F_DF_DEFAULT;
621 } else if (!strcmp(node->name, "pmtud")) {
622 if (!strcmp(node->data, "false")) {
623 flags &= ~TNL_F_PMTUD;
625 } else if (!strcmp(node->name, "header_cache")) {
626 if (!strcmp(node->data, "false")) {
627 flags &= ~TNL_F_HDR_CACHE;
629 } else if (!strcmp(node->name, "peer_cert") && is_ipsec) {
630 if (shash_find(args, "certificate")) {
631 ipsec_mech_set = true;
633 const char *use_ssl_cert;
635 /* If the "use_ssl_cert" is true, then "certificate" and
636 * "private_key" will be pulled from the SSL table. The
637 * use of this option is strongly discouraged, since it
638 * will like be removed when multiple SSL configurations
639 * are supported by OVS.
641 use_ssl_cert = shash_find_data(args, "use_ssl_cert");
642 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
643 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
647 ipsec_mech_set = true;
649 } else if (!strcmp(node->name, "psk") && is_ipsec) {
650 ipsec_mech_set = true;
652 && (!strcmp(node->name, "certificate")
653 || !strcmp(node->name, "private_key")
654 || !strcmp(node->name, "use_ssl_cert"))) {
655 /* Ignore options not used by the netdev. */
656 } else if (is_gre && (!strcmp(node->name, "key") ||
657 !strcmp(node->name, "in_key") ||
658 !strcmp(node->name, "out_key"))) {
659 /* Handled separately below. */
661 VLOG_WARN("%s: unknown %s argument '%s'", name, type, node->name);
666 char *file_name = xasprintf("%s/%s", ovs_rundir(),
667 "ovs-monitor-ipsec.pid");
668 pid_t pid = read_pidfile(file_name);
671 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
676 if (shash_find(args, "peer_cert") && shash_find(args, "psk")) {
677 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name);
681 if (!ipsec_mech_set) {
682 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
689 set_key(args, "in_key", ODP_TUNNEL_ATTR_IN_KEY, options);
690 set_key(args, "out_key", ODP_TUNNEL_ATTR_OUT_KEY, options);
694 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
698 nl_msg_put_be32(options, ODP_TUNNEL_ATTR_DST_IPV4, daddr);
700 nl_msg_put_u32(options, ODP_TUNNEL_ATTR_FLAGS, flags);
706 tnl_port_config_from_nlattr(const struct nlattr *options, size_t options_len,
707 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1])
709 static const struct nl_policy odp_tunnel_policy[] = {
710 [ODP_TUNNEL_ATTR_FLAGS] = { .type = NL_A_U32 },
711 [ODP_TUNNEL_ATTR_DST_IPV4] = { .type = NL_A_BE32 },
712 [ODP_TUNNEL_ATTR_SRC_IPV4] = { .type = NL_A_BE32, .optional = true },
713 [ODP_TUNNEL_ATTR_IN_KEY] = { .type = NL_A_BE64, .optional = true },
714 [ODP_TUNNEL_ATTR_OUT_KEY] = { .type = NL_A_BE64, .optional = true },
715 [ODP_TUNNEL_ATTR_TOS] = { .type = NL_A_U8, .optional = true },
716 [ODP_TUNNEL_ATTR_TTL] = { .type = NL_A_U8, .optional = true },
720 ofpbuf_use_const(&buf, options, options_len);
721 if (!nl_policy_parse(&buf, 0, odp_tunnel_policy,
722 a, ARRAY_SIZE(odp_tunnel_policy))) {
729 get_be64_or_zero(const struct nlattr *a)
731 return a ? ntohll(nl_attr_get_be64(a)) : 0;
735 unparse_tunnel_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
736 const struct nlattr *options, size_t options_len,
739 struct nlattr *a[ODP_TUNNEL_ATTR_MAX + 1];
744 error = tnl_port_config_from_nlattr(options, options_len, a);
749 flags = nl_attr_get_u32(a[ODP_TUNNEL_ATTR_FLAGS]);
750 if (!(flags & TNL_F_HDR_CACHE) == !(flags & TNL_F_IPSEC)) {
751 smap_add(args, "header_cache",
752 flags & TNL_F_HDR_CACHE ? "true" : "false");
755 daddr = nl_attr_get_be32(a[ODP_TUNNEL_ATTR_DST_IPV4]);
756 shash_add(args, "remote_ip", xasprintf(IP_FMT, IP_ARGS(&daddr)));
758 if (a[ODP_TUNNEL_ATTR_SRC_IPV4]) {
759 ovs_be32 saddr = nl_attr_get_be32(a[ODP_TUNNEL_ATTR_SRC_IPV4]);
760 shash_add(args, "local_ip", xasprintf(IP_FMT, IP_ARGS(&saddr)));
763 if (!a[ODP_TUNNEL_ATTR_IN_KEY] && !a[ODP_TUNNEL_ATTR_OUT_KEY]) {
764 smap_add(args, "key", "flow");
766 uint64_t in_key = get_be64_or_zero(a[ODP_TUNNEL_ATTR_IN_KEY]);
767 uint64_t out_key = get_be64_or_zero(a[ODP_TUNNEL_ATTR_OUT_KEY]);
769 if (in_key && in_key == out_key) {
770 shash_add(args, "key", xasprintf("%"PRIu64, in_key));
772 if (!a[ODP_TUNNEL_ATTR_IN_KEY]) {
773 smap_add(args, "in_key", "flow");
775 shash_add(args, "in_key", xasprintf("%"PRIu64, in_key));
778 if (!a[ODP_TUNNEL_ATTR_OUT_KEY]) {
779 smap_add(args, "out_key", "flow");
780 } else if (out_key) {
781 shash_add(args, "out_key", xasprintf("%"PRIu64, out_key));
786 if (flags & TNL_F_TTL_INHERIT) {
787 smap_add(args, "tos", "inherit");
788 } else if (a[ODP_TUNNEL_ATTR_TTL]) {
789 int ttl = nl_attr_get_u8(a[ODP_TUNNEL_ATTR_TTL]);
790 shash_add(args, "tos", xasprintf("%d", ttl));
793 if (flags & TNL_F_TOS_INHERIT) {
794 smap_add(args, "tos", "inherit");
795 } else if (a[ODP_TUNNEL_ATTR_TOS]) {
796 int tos = nl_attr_get_u8(a[ODP_TUNNEL_ATTR_TOS]);
797 shash_add(args, "tos", xasprintf("%d", tos));
800 if (flags & TNL_F_CSUM) {
801 smap_add(args, "csum", "true");
803 if (flags & TNL_F_DF_INHERIT) {
804 smap_add(args, "df_inherit", "true");
806 if (!(flags & TNL_F_DF_DEFAULT)) {
807 smap_add(args, "df_default", "false");
809 if (!(flags & TNL_F_PMTUD)) {
810 smap_add(args, "pmtud", "false");
817 parse_patch_config(const char *name, const char *type OVS_UNUSED,
818 const struct shash *args, struct ofpbuf *options)
822 peer = shash_find_data(args, "peer");
824 VLOG_ERR("%s: patch type requires valid 'peer' argument", name);
828 if (shash_count(args) > 1) {
829 VLOG_ERR("%s: patch type takes only a 'peer' argument", name);
833 if (strlen(peer) >= IFNAMSIZ) {
834 VLOG_ERR("%s: patch 'peer' arg too long", name);
838 if (!strcmp(name, peer)) {
839 VLOG_ERR("%s: patch peer must not be self", name);
843 nl_msg_put_string(options, ODP_PATCH_ATTR_PEER, peer);
849 unparse_patch_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED,
850 const struct nlattr *options, size_t options_len,
853 static const struct nl_policy odp_patch_policy[] = {
854 [ODP_PATCH_ATTR_PEER] = { .type = NL_A_STRING,
859 struct nlattr *a[ARRAY_SIZE(odp_patch_policy)];
862 ofpbuf_use_const(&buf, options, options_len);
863 if (!nl_policy_parse(&buf, 0, odp_patch_policy,
864 a, ARRAY_SIZE(odp_patch_policy))) {
868 smap_add(args, "peer", nl_attr_get_string(a[ODP_PATCH_ATTR_PEER]));
872 #define VPORT_FUNCTIONS(GET_STATUS) \
877 netdev_vport_create, \
878 netdev_vport_destroy, \
879 netdev_vport_set_config, \
882 netdev_vport_close, \
884 NULL, /* enumerate */ \
887 NULL, /* recv_wait */ \
890 netdev_vport_send, /* send */ \
891 NULL, /* send_wait */ \
893 netdev_vport_set_etheraddr, \
894 netdev_vport_get_etheraddr, \
895 netdev_vport_get_mtu, \
896 NULL, /* get_ifindex */ \
897 NULL, /* get_carrier */ \
898 NULL, /* get_miimon */ \
899 netdev_vport_get_stats, \
900 netdev_vport_set_stats, \
902 NULL, /* get_features */ \
903 NULL, /* set_advertisements */ \
904 NULL, /* get_vlan_vid */ \
906 NULL, /* set_policing */ \
907 NULL, /* get_qos_types */ \
908 NULL, /* get_qos_capabilities */ \
909 NULL, /* get_qos */ \
910 NULL, /* set_qos */ \
911 NULL, /* get_queue */ \
912 NULL, /* set_queue */ \
913 NULL, /* delete_queue */ \
914 NULL, /* get_queue_stats */ \
915 NULL, /* dump_queues */ \
916 NULL, /* dump_queue_stats */ \
918 NULL, /* get_in4 */ \
919 NULL, /* set_in4 */ \
920 NULL, /* get_in6 */ \
921 NULL, /* add_router */ \
922 NULL, /* get_next_hop */ \
924 NULL, /* arp_lookup */ \
926 netdev_vport_update_flags, \
928 netdev_vport_change_seq
931 netdev_vport_register(void)
933 static const struct vport_class vport_classes[] = {
934 { ODP_VPORT_TYPE_GRE,
935 { "gre", VPORT_FUNCTIONS(netdev_vport_get_status) },
936 parse_tunnel_config, unparse_tunnel_config },
938 { ODP_VPORT_TYPE_GRE,
939 { "ipsec_gre", VPORT_FUNCTIONS(netdev_vport_get_status) },
940 parse_tunnel_config, unparse_tunnel_config },
942 { ODP_VPORT_TYPE_CAPWAP,
943 { "capwap", VPORT_FUNCTIONS(netdev_vport_get_status) },
944 parse_tunnel_config, unparse_tunnel_config },
946 { ODP_VPORT_TYPE_PATCH,
947 { "patch", VPORT_FUNCTIONS(NULL) },
948 parse_patch_config, unparse_patch_config }
953 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
954 netdev_register_provider(&vport_classes[i].netdev_class);