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. */
62 unsigned int change_seq
;
70 enum odp_vport_type type
;
71 struct netdev_class netdev_class
;
72 int (*parse_config
)(const char *name
, const char *type
,
73 const struct shash
*args
, struct ofpbuf
*options
);
74 int (*unparse_config
)(const char *name
, const char *type
,
75 const struct nlattr
*options
, size_t options_len
,
79 static struct shash netdev_vport_notifiers
=
80 SHASH_INITIALIZER(&netdev_vport_notifiers
);
82 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(5, 20);
84 static int netdev_vport_create(const struct netdev_class
*, const char *,
85 const struct shash
*, struct netdev_dev
**);
86 static void netdev_vport_poll_notify(const struct netdev
*);
87 static int tnl_port_config_from_nlattr(const struct nlattr
*options
,
89 struct nlattr
*a
[ODP_TUNNEL_ATTR_MAX
+ 1]);
91 static const char *netdev_vport_get_tnl_iface(const struct netdev
*netdev
);
94 is_vport_class(const struct netdev_class
*class)
96 return class->create
== netdev_vport_create
;
99 static const struct vport_class
*
100 vport_class_cast(const struct netdev_class
*class)
102 assert(is_vport_class(class));
103 return CONTAINER_OF(class, struct vport_class
, netdev_class
);
106 static struct netdev_dev_vport
*
107 netdev_dev_vport_cast(const struct netdev_dev
*netdev_dev
)
109 assert(is_vport_class(netdev_dev_get_class(netdev_dev
)));
110 return CONTAINER_OF(netdev_dev
, struct netdev_dev_vport
, netdev_dev
);
113 static struct netdev_vport
*
114 netdev_vport_cast(const struct netdev
*netdev
)
116 struct netdev_dev
*netdev_dev
= netdev_get_dev(netdev
);
117 assert(is_vport_class(netdev_dev_get_class(netdev_dev
)));
118 return CONTAINER_OF(netdev
, struct netdev_vport
, netdev
);
121 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
122 * options to include in ODP_VPORT_ATTR_OPTIONS for configuring that vport.
123 * Otherwise returns NULL. */
124 const struct ofpbuf
*
125 netdev_vport_get_options(const struct netdev
*netdev
)
127 const struct netdev_dev
*dev
= netdev_get_dev(netdev
);
129 return (is_vport_class(netdev_dev_get_class(dev
))
130 ? netdev_dev_vport_cast(dev
)->options
135 netdev_vport_get_vport_type(const struct netdev
*netdev
)
137 const struct netdev_dev
*dev
= netdev_get_dev(netdev
);
138 const struct netdev_class
*class = netdev_dev_get_class(dev
);
140 return (is_vport_class(class) ? vport_class_cast(class)->type
141 : class == &netdev_internal_class
? ODP_VPORT_TYPE_INTERNAL
142 : class == &netdev_linux_class
? ODP_VPORT_TYPE_NETDEV
143 : ODP_VPORT_TYPE_UNSPEC
);
147 netdev_vport_get_netdev_type(const struct dpif_linux_vport
*vport
)
149 struct nlattr
*a
[ODP_TUNNEL_ATTR_MAX
+ 1];
151 switch (vport
->type
) {
152 case ODP_VPORT_TYPE_UNSPEC
:
155 case ODP_VPORT_TYPE_NETDEV
:
158 case ODP_VPORT_TYPE_INTERNAL
:
161 case ODP_VPORT_TYPE_PATCH
:
164 case ODP_VPORT_TYPE_GRE
:
165 if (tnl_port_config_from_nlattr(vport
->options
, vport
->options_len
,
169 return (nl_attr_get_u32(a
[ODP_TUNNEL_ATTR_FLAGS
]) & TNL_F_IPSEC
170 ? "ipsec_gre" : "gre");
172 case ODP_VPORT_TYPE_CAPWAP
:
175 case __ODP_VPORT_TYPE_MAX
:
179 VLOG_WARN_RL(&rl
, "dp%d: port `%s' has unsupported type %u",
180 vport
->dp_ifindex
, vport
->name
, (unsigned int) vport
->type
);
185 netdev_vport_create(const struct netdev_class
*netdev_class
, const char *name
,
186 const struct shash
*args
,
187 struct netdev_dev
**netdev_devp
)
189 const struct vport_class
*vport_class
= vport_class_cast(netdev_class
);
190 struct ofpbuf
*options
= NULL
;
191 struct shash fetched_args
;
196 shash_init(&fetched_args
);
199 port_no
= UINT32_MAX
;
200 if (!shash_is_empty(args
)) {
201 /* Parse the provided configuration. */
202 options
= ofpbuf_new(64);
203 error
= vport_class
->parse_config(name
, netdev_class
->type
,
206 /* Fetch an existing configuration from the kernel.
208 * This case could be ambiguous with initializing a new vport with an
209 * empty configuration, but none of the existing vport classes accept
210 * an empty configuration. */
211 struct dpif_linux_vport reply
;
214 error
= dpif_linux_vport_get(name
, &reply
, &buf
);
216 /* XXX verify correct type */
217 error
= vport_class
->unparse_config(name
, netdev_class
->type
,
222 VLOG_ERR_RL(&rl
, "%s: failed to parse kernel config (%s)",
223 name
, strerror(error
));
225 options
= ofpbuf_clone_data(reply
.options
, reply
.options_len
);
226 dp_ifindex
= reply
.dp_ifindex
;
227 port_no
= reply
.port_no
;
231 VLOG_ERR_RL(&rl
, "%s: vport query failed (%s)",
232 name
, strerror(error
));
237 struct netdev_dev_vport
*dev
;
239 dev
= xmalloc(sizeof *dev
);
240 netdev_dev_init(&dev
->netdev_dev
, name
,
241 shash_is_empty(&fetched_args
) ? args
: &fetched_args
,
243 dev
->options
= options
;
244 dev
->dp_ifindex
= dp_ifindex
;
245 dev
->port_no
= port_no
;
248 *netdev_devp
= &dev
->netdev_dev
;
249 route_table_register();
251 ofpbuf_delete(options
);
254 shash_destroy(&fetched_args
);
260 netdev_vport_destroy(struct netdev_dev
*netdev_dev_
)
262 struct netdev_dev_vport
*netdev_dev
= netdev_dev_vport_cast(netdev_dev_
);
264 route_table_unregister();
269 netdev_vport_open(struct netdev_dev
*netdev_dev_
, int ethertype OVS_UNUSED
,
270 struct netdev
**netdevp
)
272 struct netdev_vport
*netdev
;
274 netdev
= xmalloc(sizeof *netdev
);
275 netdev_init(&netdev
->netdev
, netdev_dev_
);
277 *netdevp
= &netdev
->netdev
;
282 netdev_vport_close(struct netdev
*netdev_
)
284 struct netdev_vport
*netdev
= netdev_vport_cast(netdev_
);
289 netdev_vport_set_config(struct netdev_dev
*dev_
, const struct shash
*args
)
291 const struct netdev_class
*netdev_class
= netdev_dev_get_class(dev_
);
292 const struct vport_class
*vport_class
= vport_class_cast(netdev_class
);
293 struct netdev_dev_vport
*dev
= netdev_dev_vport_cast(dev_
);
294 const char *name
= netdev_dev_get_name(dev_
);
295 struct ofpbuf
*options
;
298 options
= ofpbuf_new(64);
299 error
= vport_class
->parse_config(name
, netdev_dev_get_type(dev_
),
302 && (options
->size
!= dev
->options
->size
303 || memcmp(options
->data
, dev
->options
->data
, options
->size
))) {
304 struct dpif_linux_vport vport
;
306 dpif_linux_vport_init(&vport
);
307 vport
.cmd
= ODP_VPORT_CMD_SET
;
309 vport
.options
= options
->data
;
310 vport
.options_len
= options
->size
;
311 error
= dpif_linux_vport_transact(&vport
, NULL
, NULL
);
312 if (!error
|| error
== ENODEV
) {
313 /* Either reconfiguration succeeded or this vport is not installed
314 * in the kernel (e.g. it hasn't been added to a dpif yet with
315 * dpif_port_add()). */
316 ofpbuf_delete(dev
->options
);
317 dev
->options
= options
;
322 ofpbuf_delete(options
);
328 netdev_vport_send(struct netdev
*netdev
, const void *data
, size_t size
)
330 struct netdev_dev
*dev_
= netdev_get_dev(netdev
);
331 struct netdev_dev_vport
*dev
= netdev_dev_vport_cast(dev_
);
333 if (dev
->dp_ifindex
== -1) {
334 const char *name
= netdev_get_name(netdev
);
335 struct dpif_linux_vport reply
;
339 error
= dpif_linux_vport_get(name
, &reply
, &buf
);
341 VLOG_ERR_RL(&rl
, "%s: failed to query vport for send (%s)",
342 name
, strerror(error
));
345 dev
->dp_ifindex
= reply
.dp_ifindex
;
346 dev
->port_no
= reply
.port_no
;
350 return dpif_linux_vport_send(dev
->dp_ifindex
, dev
->port_no
, data
, size
);
354 netdev_vport_set_etheraddr(struct netdev
*netdev
,
355 const uint8_t mac
[ETH_ADDR_LEN
])
357 struct dpif_linux_vport vport
;
360 dpif_linux_vport_init(&vport
);
361 vport
.cmd
= ODP_VPORT_CMD_SET
;
362 vport
.name
= netdev_get_name(netdev
);
365 error
= dpif_linux_vport_transact(&vport
, NULL
, NULL
);
367 netdev_vport_poll_notify(netdev
);
373 netdev_vport_get_etheraddr(const struct netdev
*netdev
,
374 uint8_t mac
[ETH_ADDR_LEN
])
376 struct dpif_linux_vport reply
;
380 error
= dpif_linux_vport_get(netdev_get_name(netdev
), &reply
, &buf
);
383 memcpy(mac
, reply
.address
, ETH_ADDR_LEN
);
393 netdev_vport_get_mtu(const struct netdev
*netdev
, int *mtup
)
395 struct dpif_linux_vport reply
;
399 error
= dpif_linux_vport_get(netdev_get_name(netdev
), &reply
, &buf
);
408 netdev_vport_get_stats(const struct netdev
*netdev
, struct netdev_stats
*stats
)
410 struct dpif_linux_vport reply
;
414 error
= dpif_linux_vport_get(netdev_get_name(netdev
), &reply
, &buf
);
417 } else if (!reply
.stats
) {
422 netdev_stats_from_rtnl_link_stats64(stats
, reply
.stats
);
430 netdev_vport_set_stats(struct netdev
*netdev
, const struct netdev_stats
*stats
)
432 struct rtnl_link_stats64 rtnl_stats
;
433 struct dpif_linux_vport vport
;
436 netdev_stats_to_rtnl_link_stats64(&rtnl_stats
, stats
);
438 dpif_linux_vport_init(&vport
);
439 vport
.cmd
= ODP_VPORT_CMD_SET
;
440 vport
.name
= netdev_get_name(netdev
);
441 vport
.stats
= &rtnl_stats
;
443 err
= dpif_linux_vport_transact(&vport
, NULL
, NULL
);
445 /* If the vport layer doesn't know about the device, that doesn't mean it
446 * doesn't exist (after all were able to open it when netdev_open() was
447 * called), it just means that it isn't attached and we'll be getting
448 * stats a different way. */
457 netdev_vport_get_status(const struct netdev
*netdev
, struct shash
*sh
)
459 const char *iface
= netdev_vport_get_tnl_iface(netdev
);
462 struct netdev
*egress_netdev
;
464 shash_add(sh
, "tunnel_egress_iface", xstrdup(iface
));
466 if (!netdev_open_default(iface
, &egress_netdev
)) {
467 shash_add(sh
, "tunnel_egress_iface_carrier",
468 xstrdup(netdev_get_carrier(egress_netdev
)
470 netdev_close(egress_netdev
);
478 netdev_vport_update_flags(struct netdev
*netdev OVS_UNUSED
,
479 enum netdev_flags off
, enum netdev_flags on OVS_UNUSED
,
480 enum netdev_flags
*old_flagsp
)
482 if (off
& (NETDEV_UP
| NETDEV_PROMISC
)) {
486 *old_flagsp
= NETDEV_UP
| NETDEV_PROMISC
;
491 make_poll_name(const struct netdev
*netdev
)
493 return xasprintf("%s:%s", netdev_get_type(netdev
), netdev_get_name(netdev
));
497 netdev_vport_poll_add(struct netdev
*netdev
,
498 void (*cb
)(struct netdev_notifier
*), void *aux
,
499 struct netdev_notifier
**notifierp
)
501 char *poll_name
= make_poll_name(netdev
);
502 struct netdev_vport_notifier
*notifier
;
504 struct shash_node
*shash_node
;
506 shash_node
= shash_find(&netdev_vport_notifiers
, poll_name
);
508 list
= xmalloc(sizeof *list
);
510 shash_node
= shash_add(&netdev_vport_notifiers
, poll_name
, list
);
512 list
= shash_node
->data
;
515 notifier
= xmalloc(sizeof *notifier
);
516 netdev_notifier_init(¬ifier
->notifier
, netdev
, cb
, aux
);
517 list_push_back(list
, ¬ifier
->list_node
);
518 notifier
->shash_node
= shash_node
;
520 *notifierp
= ¬ifier
->notifier
;
527 netdev_vport_poll_remove(struct netdev_notifier
*notifier_
)
529 struct netdev_vport_notifier
*notifier
=
530 CONTAINER_OF(notifier_
, struct netdev_vport_notifier
, notifier
);
534 list
= list_remove(¬ifier
->list_node
);
535 if (list_is_empty(list
)) {
536 shash_delete(&netdev_vport_notifiers
, notifier
->shash_node
);
544 netdev_vport_change_seq(const struct netdev
*netdev
)
546 return netdev_dev_vport_cast(netdev_get_dev(netdev
))->change_seq
;
550 netdev_vport_run(void)
556 netdev_vport_wait(void)
561 /* get_tnl_iface() implementation. */
563 netdev_vport_get_tnl_iface(const struct netdev
*netdev
)
565 struct nlattr
*a
[ODP_TUNNEL_ATTR_MAX
+ 1];
567 struct netdev_dev_vport
*ndv
;
568 static char name
[IFNAMSIZ
];
570 ndv
= netdev_dev_vport_cast(netdev_get_dev(netdev
));
571 if (tnl_port_config_from_nlattr(ndv
->options
->data
, ndv
->options
->size
,
575 route
= nl_attr_get_be32(a
[ODP_TUNNEL_ATTR_DST_IPV4
]);
577 if (route_table_get_name(route
, name
)) {
584 /* Helper functions. */
587 netdev_vport_poll_notify(const struct netdev
*netdev
)
589 char *poll_name
= make_poll_name(netdev
);
590 struct list
*list
= shash_find_data(&netdev_vport_notifiers
,
592 struct netdev_dev_vport
*ndv
;
594 ndv
= netdev_dev_vport_cast(netdev_get_dev(netdev
));
597 struct netdev_vport_notifier
*notifier
;
599 LIST_FOR_EACH (notifier
, list_node
, list
) {
600 struct netdev_notifier
*n
= ¬ifier
->notifier
;
606 if (!ndv
->change_seq
) {
613 /* Code specific to individual vport types. */
616 set_key(const struct shash
*args
, const char *name
, uint16_t type
,
617 struct ofpbuf
*options
)
621 s
= shash_find_data(args
, name
);
623 s
= shash_find_data(args
, "key");
629 if (!strcmp(s
, "flow")) {
630 /* This is the default if no attribute is present. */
632 nl_msg_put_be64(options
, type
, htonll(strtoull(s
, NULL
, 0)));
637 parse_tunnel_config(const char *name
, const char *type
,
638 const struct shash
*args
, struct ofpbuf
*options
)
641 bool is_ipsec
= false;
642 struct shash_node
*node
;
643 bool ipsec_mech_set
= false;
644 ovs_be32 daddr
= htonl(0);
647 flags
= TNL_F_DF_DEFAULT
| TNL_F_PMTUD
| TNL_F_HDR_CACHE
;
648 if (!strcmp(type
, "gre")) {
650 } else if (!strcmp(type
, "ipsec_gre")) {
653 flags
|= TNL_F_IPSEC
;
654 flags
&= ~TNL_F_HDR_CACHE
;
657 SHASH_FOR_EACH (node
, args
) {
658 if (!strcmp(node
->name
, "remote_ip")) {
659 struct in_addr in_addr
;
660 if (lookup_ip(node
->data
, &in_addr
)) {
661 VLOG_WARN("%s: bad %s 'remote_ip'", name
, type
);
663 daddr
= in_addr
.s_addr
;
665 } else if (!strcmp(node
->name
, "local_ip")) {
666 struct in_addr in_addr
;
667 if (lookup_ip(node
->data
, &in_addr
)) {
668 VLOG_WARN("%s: bad %s 'local_ip'", name
, type
);
670 nl_msg_put_be32(options
, ODP_TUNNEL_ATTR_SRC_IPV4
,
673 } else if (!strcmp(node
->name
, "tos")) {
674 if (!strcmp(node
->data
, "inherit")) {
675 flags
|= TNL_F_TOS_INHERIT
;
677 nl_msg_put_u8(options
, ODP_TUNNEL_ATTR_TOS
, atoi(node
->data
));
679 } else if (!strcmp(node
->name
, "ttl")) {
680 if (!strcmp(node
->data
, "inherit")) {
681 flags
|= TNL_F_TTL_INHERIT
;
683 nl_msg_put_u8(options
, ODP_TUNNEL_ATTR_TTL
, atoi(node
->data
));
685 } else if (!strcmp(node
->name
, "csum") && is_gre
) {
686 if (!strcmp(node
->data
, "true")) {
689 } else if (!strcmp(node
->name
, "df_inherit")) {
690 if (!strcmp(node
->data
, "true")) {
691 flags
|= TNL_F_DF_INHERIT
;
693 } else if (!strcmp(node
->name
, "df_default")) {
694 if (!strcmp(node
->data
, "false")) {
695 flags
&= ~TNL_F_DF_DEFAULT
;
697 } else if (!strcmp(node
->name
, "pmtud")) {
698 if (!strcmp(node
->data
, "false")) {
699 flags
&= ~TNL_F_PMTUD
;
701 } else if (!strcmp(node
->name
, "header_cache")) {
702 if (!strcmp(node
->data
, "false")) {
703 flags
&= ~TNL_F_HDR_CACHE
;
705 } else if (!strcmp(node
->name
, "peer_cert") && is_ipsec
) {
706 if (shash_find(args
, "certificate")) {
707 ipsec_mech_set
= true;
709 const char *use_ssl_cert
;
711 /* If the "use_ssl_cert" is true, then "certificate" and
712 * "private_key" will be pulled from the SSL table. The
713 * use of this option is strongly discouraged, since it
714 * will like be removed when multiple SSL configurations
715 * are supported by OVS.
717 use_ssl_cert
= shash_find_data(args
, "use_ssl_cert");
718 if (!use_ssl_cert
|| strcmp(use_ssl_cert
, "true")) {
719 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
723 ipsec_mech_set
= true;
725 } else if (!strcmp(node
->name
, "psk") && is_ipsec
) {
726 ipsec_mech_set
= true;
728 && (!strcmp(node
->name
, "certificate")
729 || !strcmp(node
->name
, "private_key")
730 || !strcmp(node
->name
, "use_ssl_cert"))) {
731 /* Ignore options not used by the netdev. */
732 } else if (is_gre
&& (!strcmp(node
->name
, "key") ||
733 !strcmp(node
->name
, "in_key") ||
734 !strcmp(node
->name
, "out_key"))) {
735 /* Handled separately below. */
737 VLOG_WARN("%s: unknown %s argument '%s'", name
, type
, node
->name
);
742 char *file_name
= xasprintf("%s/%s", ovs_rundir(),
743 "ovs-monitor-ipsec.pid");
744 pid_t pid
= read_pidfile(file_name
);
747 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
752 if (shash_find(args
, "peer_cert") && shash_find(args
, "psk")) {
753 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name
);
757 if (!ipsec_mech_set
) {
758 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
765 set_key(args
, "in_key", ODP_TUNNEL_ATTR_IN_KEY
, options
);
766 set_key(args
, "out_key", ODP_TUNNEL_ATTR_OUT_KEY
, options
);
770 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
774 nl_msg_put_be32(options
, ODP_TUNNEL_ATTR_DST_IPV4
, daddr
);
776 nl_msg_put_u32(options
, ODP_TUNNEL_ATTR_FLAGS
, flags
);
782 tnl_port_config_from_nlattr(const struct nlattr
*options
, size_t options_len
,
783 struct nlattr
*a
[ODP_TUNNEL_ATTR_MAX
+ 1])
785 static const struct nl_policy odp_tunnel_policy
[] = {
786 [ODP_TUNNEL_ATTR_FLAGS
] = { .type
= NL_A_U32
},
787 [ODP_TUNNEL_ATTR_DST_IPV4
] = { .type
= NL_A_BE32
},
788 [ODP_TUNNEL_ATTR_SRC_IPV4
] = { .type
= NL_A_BE32
, .optional
= true },
789 [ODP_TUNNEL_ATTR_IN_KEY
] = { .type
= NL_A_BE64
, .optional
= true },
790 [ODP_TUNNEL_ATTR_OUT_KEY
] = { .type
= NL_A_BE64
, .optional
= true },
791 [ODP_TUNNEL_ATTR_TOS
] = { .type
= NL_A_U8
, .optional
= true },
792 [ODP_TUNNEL_ATTR_TTL
] = { .type
= NL_A_U8
, .optional
= true },
796 ofpbuf_use_const(&buf
, options
, options_len
);
797 if (!nl_policy_parse(&buf
, 0, odp_tunnel_policy
,
798 a
, ARRAY_SIZE(odp_tunnel_policy
))) {
805 get_be64_or_zero(const struct nlattr
*a
)
807 return a
? ntohll(nl_attr_get_be64(a
)) : 0;
811 unparse_tunnel_config(const char *name OVS_UNUSED
, const char *type OVS_UNUSED
,
812 const struct nlattr
*options
, size_t options_len
,
815 struct nlattr
*a
[ODP_TUNNEL_ATTR_MAX
+ 1];
820 error
= tnl_port_config_from_nlattr(options
, options_len
, a
);
825 flags
= nl_attr_get_u32(a
[ODP_TUNNEL_ATTR_FLAGS
]);
826 if (!(flags
& TNL_F_HDR_CACHE
) == !(flags
& TNL_F_IPSEC
)) {
827 smap_add(args
, "header_cache",
828 flags
& TNL_F_HDR_CACHE
? "true" : "false");
831 daddr
= nl_attr_get_be32(a
[ODP_TUNNEL_ATTR_DST_IPV4
]);
832 shash_add(args
, "remote_ip", xasprintf(IP_FMT
, IP_ARGS(&daddr
)));
834 if (a
[ODP_TUNNEL_ATTR_SRC_IPV4
]) {
835 ovs_be32 saddr
= nl_attr_get_be32(a
[ODP_TUNNEL_ATTR_SRC_IPV4
]);
836 shash_add(args
, "local_ip", xasprintf(IP_FMT
, IP_ARGS(&saddr
)));
839 if (!a
[ODP_TUNNEL_ATTR_IN_KEY
] && !a
[ODP_TUNNEL_ATTR_OUT_KEY
]) {
840 smap_add(args
, "key", "flow");
842 uint64_t in_key
= get_be64_or_zero(a
[ODP_TUNNEL_ATTR_IN_KEY
]);
843 uint64_t out_key
= get_be64_or_zero(a
[ODP_TUNNEL_ATTR_OUT_KEY
]);
845 if (in_key
&& in_key
== out_key
) {
846 shash_add(args
, "key", xasprintf("%"PRIu64
, in_key
));
848 if (!a
[ODP_TUNNEL_ATTR_IN_KEY
]) {
849 smap_add(args
, "in_key", "flow");
851 shash_add(args
, "in_key", xasprintf("%"PRIu64
, in_key
));
854 if (!a
[ODP_TUNNEL_ATTR_OUT_KEY
]) {
855 smap_add(args
, "out_key", "flow");
856 } else if (out_key
) {
857 shash_add(args
, "out_key", xasprintf("%"PRIu64
, out_key
));
862 if (flags
& TNL_F_TTL_INHERIT
) {
863 smap_add(args
, "tos", "inherit");
864 } else if (a
[ODP_TUNNEL_ATTR_TTL
]) {
865 int ttl
= nl_attr_get_u8(a
[ODP_TUNNEL_ATTR_TTL
]);
866 shash_add(args
, "tos", xasprintf("%d", ttl
));
869 if (flags
& TNL_F_TOS_INHERIT
) {
870 smap_add(args
, "tos", "inherit");
871 } else if (a
[ODP_TUNNEL_ATTR_TOS
]) {
872 int tos
= nl_attr_get_u8(a
[ODP_TUNNEL_ATTR_TOS
]);
873 shash_add(args
, "tos", xasprintf("%d", tos
));
876 if (flags
& TNL_F_CSUM
) {
877 smap_add(args
, "csum", "true");
879 if (flags
& TNL_F_DF_INHERIT
) {
880 smap_add(args
, "df_inherit", "true");
882 if (!(flags
& TNL_F_DF_DEFAULT
)) {
883 smap_add(args
, "df_default", "false");
885 if (!(flags
& TNL_F_PMTUD
)) {
886 smap_add(args
, "pmtud", "false");
893 parse_patch_config(const char *name
, const char *type OVS_UNUSED
,
894 const struct shash
*args
, struct ofpbuf
*options
)
898 peer
= shash_find_data(args
, "peer");
900 VLOG_ERR("%s: patch type requires valid 'peer' argument", name
);
904 if (shash_count(args
) > 1) {
905 VLOG_ERR("%s: patch type takes only a 'peer' argument", name
);
909 if (strlen(peer
) >= IFNAMSIZ
) {
910 VLOG_ERR("%s: patch 'peer' arg too long", name
);
914 if (!strcmp(name
, peer
)) {
915 VLOG_ERR("%s: patch peer must not be self", name
);
919 nl_msg_put_string(options
, ODP_PATCH_ATTR_PEER
, peer
);
925 unparse_patch_config(const char *name OVS_UNUSED
, const char *type OVS_UNUSED
,
926 const struct nlattr
*options
, size_t options_len
,
929 static const struct nl_policy odp_patch_policy
[] = {
930 [ODP_PATCH_ATTR_PEER
] = { .type
= NL_A_STRING
,
935 struct nlattr
*a
[ARRAY_SIZE(odp_patch_policy
)];
938 ofpbuf_use_const(&buf
, options
, options_len
);
939 if (!nl_policy_parse(&buf
, 0, odp_patch_policy
,
940 a
, ARRAY_SIZE(odp_patch_policy
))) {
944 smap_add(args
, "peer", nl_attr_get_string(a
[ODP_PATCH_ATTR_PEER
]));
948 #define VPORT_FUNCTIONS(GET_STATUS) \
953 netdev_vport_create, \
954 netdev_vport_destroy, \
955 netdev_vport_set_config, \
958 netdev_vport_close, \
960 NULL, /* enumerate */ \
963 NULL, /* recv_wait */ \
966 netdev_vport_send, /* send */ \
967 NULL, /* send_wait */ \
969 netdev_vport_set_etheraddr, \
970 netdev_vport_get_etheraddr, \
971 netdev_vport_get_mtu, \
972 NULL, /* get_ifindex */ \
973 NULL, /* get_carrier */ \
974 NULL, /* get_miimon */ \
975 netdev_vport_get_stats, \
976 netdev_vport_set_stats, \
978 NULL, /* get_features */ \
979 NULL, /* set_advertisements */ \
980 NULL, /* get_vlan_vid */ \
982 NULL, /* set_policing */ \
983 NULL, /* get_qos_types */ \
984 NULL, /* get_qos_capabilities */ \
985 NULL, /* get_qos */ \
986 NULL, /* set_qos */ \
987 NULL, /* get_queue */ \
988 NULL, /* set_queue */ \
989 NULL, /* delete_queue */ \
990 NULL, /* get_queue_stats */ \
991 NULL, /* dump_queues */ \
992 NULL, /* dump_queue_stats */ \
994 NULL, /* get_in4 */ \
995 NULL, /* set_in4 */ \
996 NULL, /* get_in6 */ \
997 NULL, /* add_router */ \
998 NULL, /* get_next_hop */ \
1000 NULL, /* arp_lookup */ \
1002 netdev_vport_update_flags, \
1004 netdev_vport_poll_add, \
1005 netdev_vport_poll_remove, \
1006 netdev_vport_change_seq
1009 netdev_vport_register(void)
1011 static const struct vport_class vport_classes
[] = {
1012 { ODP_VPORT_TYPE_GRE
,
1013 { "gre", VPORT_FUNCTIONS(netdev_vport_get_status
) },
1014 parse_tunnel_config
, unparse_tunnel_config
},
1016 { ODP_VPORT_TYPE_GRE
,
1017 { "ipsec_gre", VPORT_FUNCTIONS(netdev_vport_get_status
) },
1018 parse_tunnel_config
, unparse_tunnel_config
},
1020 { ODP_VPORT_TYPE_CAPWAP
,
1021 { "capwap", VPORT_FUNCTIONS(netdev_vport_get_status
) },
1022 parse_tunnel_config
, unparse_tunnel_config
},
1024 { ODP_VPORT_TYPE_PATCH
,
1025 { "patch", VPORT_FUNCTIONS(NULL
) },
1026 parse_patch_config
, unparse_patch_config
}
1031 for (i
= 0; i
< ARRAY_SIZE(vport_classes
); i
++) {
1032 netdev_register_provider(&vport_classes
[i
].netdev_class
);