2 * Copyright (c) 2010, 2011, 2012 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 struct netdev_dev_vport
{
56 struct netdev_dev netdev_dev
;
57 struct ofpbuf
*options
;
58 unsigned int change_seq
;
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 int (*unparse_config
)(const char *name
, const char *type
,
71 const struct nlattr
*options
, size_t options_len
,
75 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(5, 20);
77 static int netdev_vport_create(const struct netdev_class
*, const char *,
78 struct netdev_dev
**);
79 static void netdev_vport_poll_notify(const struct netdev
*);
80 static int tnl_port_config_from_nlattr(const struct nlattr
*options
,
82 struct nlattr
*a
[OVS_TUNNEL_ATTR_MAX
+ 1]);
84 static const char *netdev_vport_get_tnl_iface(const struct netdev
*netdev
);
87 is_vport_class(const struct netdev_class
*class)
89 return class->create
== netdev_vport_create
;
92 static const struct vport_class
*
93 vport_class_cast(const struct netdev_class
*class)
95 assert(is_vport_class(class));
96 return CONTAINER_OF(class, struct vport_class
, netdev_class
);
99 static struct netdev_dev_vport
*
100 netdev_dev_vport_cast(const struct netdev_dev
*netdev_dev
)
102 assert(is_vport_class(netdev_dev_get_class(netdev_dev
)));
103 return CONTAINER_OF(netdev_dev
, struct netdev_dev_vport
, netdev_dev
);
106 static struct netdev_vport
*
107 netdev_vport_cast(const struct netdev
*netdev
)
109 struct netdev_dev
*netdev_dev
= netdev_get_dev(netdev
);
110 assert(is_vport_class(netdev_dev_get_class(netdev_dev
)));
111 return CONTAINER_OF(netdev
, struct netdev_vport
, netdev
);
114 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
115 * options to include in OVS_VPORT_ATTR_OPTIONS for configuring that vport.
116 * Otherwise returns NULL. */
117 const struct ofpbuf
*
118 netdev_vport_get_options(const struct netdev
*netdev
)
120 const struct netdev_dev
*dev
= netdev_get_dev(netdev
);
122 return (is_vport_class(netdev_dev_get_class(dev
))
123 ? netdev_dev_vport_cast(dev
)->options
128 netdev_vport_get_vport_type(const struct netdev
*netdev
)
130 const struct netdev_dev
*dev
= netdev_get_dev(netdev
);
131 const struct netdev_class
*class = netdev_dev_get_class(dev
);
133 return (is_vport_class(class) ? vport_class_cast(class)->type
134 : class == &netdev_internal_class
? OVS_VPORT_TYPE_INTERNAL
135 : (class == &netdev_linux_class
||
136 class == &netdev_tap_class
) ? OVS_VPORT_TYPE_NETDEV
137 : OVS_VPORT_TYPE_UNSPEC
);
141 get_u32_or_zero(const struct nlattr
*a
)
143 return a
? nl_attr_get_u32(a
) : 0;
147 netdev_vport_get_netdev_type(const struct dpif_linux_vport
*vport
)
149 struct nlattr
*a
[OVS_TUNNEL_ATTR_MAX
+ 1];
151 switch (vport
->type
) {
152 case OVS_VPORT_TYPE_UNSPEC
:
155 case OVS_VPORT_TYPE_NETDEV
:
158 case OVS_VPORT_TYPE_INTERNAL
:
161 case OVS_VPORT_TYPE_PATCH
:
164 case OVS_VPORT_TYPE_GRE
:
165 if (tnl_port_config_from_nlattr(vport
->options
, vport
->options_len
,
169 return (get_u32_or_zero(a
[OVS_TUNNEL_ATTR_FLAGS
]) & TNL_F_IPSEC
170 ? "ipsec_gre" : "gre");
172 case OVS_VPORT_TYPE_GRE64
:
173 if (tnl_port_config_from_nlattr(vport
->options
, vport
->options_len
,
177 return (get_u32_or_zero(a
[OVS_TUNNEL_ATTR_FLAGS
]) & TNL_F_IPSEC
178 ? "ipsec_gre64" : "gre64");
180 case OVS_VPORT_TYPE_CAPWAP
:
183 case OVS_VPORT_TYPE_VXLAN
:
186 case OVS_VPORT_TYPE_FT_GRE
:
187 case __OVS_VPORT_TYPE_MAX
:
191 VLOG_WARN_RL(&rl
, "dp%d: port `%s' has unsupported type %u",
192 vport
->dp_ifindex
, vport
->name
, (unsigned int) vport
->type
);
197 netdev_vport_create(const struct netdev_class
*netdev_class
, const char *name
,
198 struct netdev_dev
**netdev_devp
)
200 struct netdev_dev_vport
*dev
;
202 dev
= xmalloc(sizeof *dev
);
203 netdev_dev_init(&dev
->netdev_dev
, name
, netdev_class
);
207 *netdev_devp
= &dev
->netdev_dev
;
208 route_table_register();
214 netdev_vport_destroy(struct netdev_dev
*netdev_dev_
)
216 struct netdev_dev_vport
*netdev_dev
= netdev_dev_vport_cast(netdev_dev_
);
218 ofpbuf_delete(netdev_dev
->options
);
219 route_table_unregister();
224 netdev_vport_open(struct netdev_dev
*netdev_dev_
, struct netdev
**netdevp
)
226 struct netdev_vport
*netdev
;
228 netdev
= xmalloc(sizeof *netdev
);
229 netdev_init(&netdev
->netdev
, netdev_dev_
);
231 *netdevp
= &netdev
->netdev
;
236 netdev_vport_close(struct netdev
*netdev_
)
238 struct netdev_vport
*netdev
= netdev_vport_cast(netdev_
);
243 netdev_vport_get_config(struct netdev_dev
*dev_
, struct smap
*args
)
245 const struct netdev_class
*netdev_class
= netdev_dev_get_class(dev_
);
246 const struct vport_class
*vport_class
= vport_class_cast(netdev_class
);
247 struct netdev_dev_vport
*dev
= netdev_dev_vport_cast(dev_
);
248 const char *name
= netdev_dev_get_name(dev_
);
252 struct dpif_linux_vport reply
;
255 error
= dpif_linux_vport_get(name
, &reply
, &buf
);
257 VLOG_ERR_RL(&rl
, "%s: vport query failed (%s)",
258 name
, strerror(error
));
262 dev
->options
= ofpbuf_clone_data(reply
.options
, reply
.options_len
);
266 error
= vport_class
->unparse_config(name
, netdev_class
->type
,
271 VLOG_ERR_RL(&rl
, "%s: failed to parse kernel config (%s)",
272 name
, strerror(error
));
278 netdev_vport_set_config(struct netdev_dev
*dev_
, const struct smap
*args
)
280 const struct netdev_class
*netdev_class
= netdev_dev_get_class(dev_
);
281 const struct vport_class
*vport_class
= vport_class_cast(netdev_class
);
282 struct netdev_dev_vport
*dev
= netdev_dev_vport_cast(dev_
);
283 const char *name
= netdev_dev_get_name(dev_
);
284 struct ofpbuf
*options
;
287 options
= ofpbuf_new(64);
288 error
= vport_class
->parse_config(name
, netdev_dev_get_type(dev_
),
292 || options
->size
!= dev
->options
->size
293 || memcmp(options
->data
, dev
->options
->data
, options
->size
))) {
294 struct dpif_linux_vport vport
;
296 dpif_linux_vport_init(&vport
);
297 vport
.cmd
= OVS_VPORT_CMD_SET
;
299 vport
.options
= options
->data
;
300 vport
.options_len
= options
->size
;
301 error
= dpif_linux_vport_transact(&vport
, NULL
, NULL
);
302 if (!error
|| error
== ENODEV
) {
303 /* Either reconfiguration succeeded or this vport is not installed
304 * in the kernel (e.g. it hasn't been added to a dpif yet with
305 * dpif_port_add()). */
306 ofpbuf_delete(dev
->options
);
307 dev
->options
= options
;
312 ofpbuf_delete(options
);
318 netdev_vport_set_etheraddr(struct netdev
*netdev
,
319 const uint8_t mac
[ETH_ADDR_LEN
])
321 struct dpif_linux_vport vport
;
324 dpif_linux_vport_init(&vport
);
325 vport
.cmd
= OVS_VPORT_CMD_SET
;
326 vport
.name
= netdev_get_name(netdev
);
329 error
= dpif_linux_vport_transact(&vport
, NULL
, NULL
);
331 netdev_vport_poll_notify(netdev
);
337 netdev_vport_get_etheraddr(const struct netdev
*netdev
,
338 uint8_t mac
[ETH_ADDR_LEN
])
340 struct dpif_linux_vport reply
;
344 error
= dpif_linux_vport_get(netdev_get_name(netdev
), &reply
, &buf
);
347 memcpy(mac
, reply
.address
, ETH_ADDR_LEN
);
356 /* Copies 'src' into 'dst', performing format conversion in the process.
358 * 'src' is allowed to be misaligned. */
360 netdev_stats_from_ovs_vport_stats(struct netdev_stats
*dst
,
361 const struct ovs_vport_stats
*src
)
363 dst
->rx_packets
= get_unaligned_u64(&src
->rx_packets
);
364 dst
->tx_packets
= get_unaligned_u64(&src
->tx_packets
);
365 dst
->rx_bytes
= get_unaligned_u64(&src
->rx_bytes
);
366 dst
->tx_bytes
= get_unaligned_u64(&src
->tx_bytes
);
367 dst
->rx_errors
= get_unaligned_u64(&src
->rx_errors
);
368 dst
->tx_errors
= get_unaligned_u64(&src
->tx_errors
);
369 dst
->rx_dropped
= get_unaligned_u64(&src
->rx_dropped
);
370 dst
->tx_dropped
= get_unaligned_u64(&src
->tx_dropped
);
373 dst
->rx_length_errors
= 0;
374 dst
->rx_over_errors
= 0;
375 dst
->rx_crc_errors
= 0;
376 dst
->rx_frame_errors
= 0;
377 dst
->rx_fifo_errors
= 0;
378 dst
->rx_missed_errors
= 0;
379 dst
->tx_aborted_errors
= 0;
380 dst
->tx_carrier_errors
= 0;
381 dst
->tx_fifo_errors
= 0;
382 dst
->tx_heartbeat_errors
= 0;
383 dst
->tx_window_errors
= 0;
387 netdev_vport_get_stats(const struct netdev
*netdev
, struct netdev_stats
*stats
)
389 struct dpif_linux_vport reply
;
393 error
= dpif_linux_vport_get(netdev_get_name(netdev
), &reply
, &buf
);
396 } else if (!reply
.stats
) {
401 netdev_stats_from_ovs_vport_stats(stats
, reply
.stats
);
409 netdev_vport_get_drv_info(const struct netdev
*netdev
, struct smap
*smap
)
411 const char *iface
= netdev_vport_get_tnl_iface(netdev
);
414 struct netdev
*egress_netdev
;
416 smap_add(smap
, "tunnel_egress_iface", iface
);
418 if (!netdev_open(iface
, "system", &egress_netdev
)) {
419 smap_add(smap
, "tunnel_egress_iface_carrier",
420 netdev_get_carrier(egress_netdev
) ? "up" : "down");
421 netdev_close(egress_netdev
);
429 netdev_vport_update_flags(struct netdev
*netdev OVS_UNUSED
,
430 enum netdev_flags off
, enum netdev_flags on OVS_UNUSED
,
431 enum netdev_flags
*old_flagsp
)
433 if (off
& (NETDEV_UP
| NETDEV_PROMISC
)) {
437 *old_flagsp
= NETDEV_UP
| NETDEV_PROMISC
;
442 netdev_vport_change_seq(const struct netdev
*netdev
)
444 return netdev_dev_vport_cast(netdev_get_dev(netdev
))->change_seq
;
448 netdev_vport_run(void)
454 netdev_vport_wait(void)
459 /* get_tnl_iface() implementation. */
461 netdev_vport_get_tnl_iface(const struct netdev
*netdev
)
463 struct nlattr
*a
[OVS_TUNNEL_ATTR_MAX
+ 1];
464 struct netdev_dev_vport
*ndv
;
465 static char name
[IFNAMSIZ
];
467 ndv
= netdev_dev_vport_cast(netdev_get_dev(netdev
));
468 if (tnl_port_config_from_nlattr(ndv
->options
->data
, ndv
->options
->size
,
472 if (a
[OVS_TUNNEL_ATTR_DST_IPV4
]) {
473 ovs_be32 route
= nl_attr_get_be32(a
[OVS_TUNNEL_ATTR_DST_IPV4
]);
475 if (route_table_get_name(route
, name
)) {
482 /* Helper functions. */
485 netdev_vport_poll_notify(const struct netdev
*netdev
)
487 struct netdev_dev_vport
*ndv
;
489 ndv
= netdev_dev_vport_cast(netdev_get_dev(netdev
));
492 if (!ndv
->change_seq
) {
497 /* Code specific to individual vport types. */
500 set_key(const struct smap
*args
, const char *name
, uint16_t type
,
501 struct ofpbuf
*options
)
505 s
= smap_get(args
, name
);
507 s
= smap_get(args
, "key");
513 if (!strcmp(s
, "flow")) {
514 /* This is the default if no attribute is present. */
516 nl_msg_put_be64(options
, type
, htonll(strtoull(s
, NULL
, 0)));
521 parse_tunnel_config(const char *name
, const char *type
,
522 const struct smap
*args
, struct ofpbuf
*options
)
525 bool is_ipsec
= false;
526 bool needs_dst_port
= false;
527 bool found_dst_port
= false;
528 struct smap_node
*node
;
529 bool ipsec_mech_set
= false;
530 ovs_be32 daddr
= htonl(0);
531 ovs_be32 saddr
= htonl(0);
534 if (!strcmp(type
, "capwap")) {
535 VLOG_WARN_ONCE("CAPWAP tunnel support is deprecated.");
538 flags
= TNL_F_DF_DEFAULT
;
539 if (!strcmp(type
, "gre") || !strcmp(type
, "gre64")) {
541 } else if (!strcmp(type
, "ipsec_gre") || !strcmp(type
, "ipsec_gre64")) {
544 flags
|= TNL_F_IPSEC
;
545 } else if (!strcmp(type
, "vxlan")) {
546 needs_dst_port
= true;
549 SMAP_FOR_EACH (node
, args
) {
550 if (!strcmp(node
->key
, "remote_ip")) {
551 struct in_addr in_addr
;
552 if (lookup_ip(node
->value
, &in_addr
)) {
553 VLOG_WARN("%s: bad %s 'remote_ip'", name
, type
);
555 daddr
= in_addr
.s_addr
;
557 } else if (!strcmp(node
->key
, "local_ip")) {
558 struct in_addr in_addr
;
559 if (lookup_ip(node
->value
, &in_addr
)) {
560 VLOG_WARN("%s: bad %s 'local_ip'", name
, type
);
562 saddr
= in_addr
.s_addr
;
564 } else if (!strcmp(node
->key
, "tos")) {
565 if (!strcmp(node
->value
, "inherit")) {
566 flags
|= TNL_F_TOS_INHERIT
;
570 tos
= strtol(node
->value
, &endptr
, 0);
571 if (*endptr
== '\0' && tos
== (tos
& IP_DSCP_MASK
)) {
572 nl_msg_put_u8(options
, OVS_TUNNEL_ATTR_TOS
, tos
);
574 VLOG_WARN("%s: invalid TOS %s", name
, node
->value
);
577 } else if (!strcmp(node
->key
, "ttl")) {
578 if (!strcmp(node
->value
, "inherit")) {
579 flags
|= TNL_F_TTL_INHERIT
;
581 nl_msg_put_u8(options
, OVS_TUNNEL_ATTR_TTL
, atoi(node
->value
));
583 } else if (!strcmp(node
->key
, "dst_port") && needs_dst_port
) {
584 nl_msg_put_u16(options
, OVS_TUNNEL_ATTR_DST_PORT
,
586 found_dst_port
= true;
587 } else if (!strcmp(node
->key
, "csum") && is_gre
) {
588 if (!strcmp(node
->value
, "true")) {
591 } else if (!strcmp(node
->key
, "df_inherit")) {
592 if (!strcmp(node
->value
, "true")) {
593 flags
|= TNL_F_DF_INHERIT
;
595 } else if (!strcmp(node
->key
, "df_default")) {
596 if (!strcmp(node
->value
, "false")) {
597 flags
&= ~TNL_F_DF_DEFAULT
;
599 } else if (!strcmp(node
->key
, "pmtud")) {
600 if (!strcmp(node
->value
, "true")) {
601 VLOG_WARN_ONCE("%s: The tunnel Path MTU discovery is "
602 "deprecated and may be removed in February "
603 "2013. Please email dev@openvswitch.org with "
605 flags
|= TNL_F_PMTUD
;
607 } else if (!strcmp(node
->key
, "peer_cert") && is_ipsec
) {
608 if (smap_get(args
, "certificate")) {
609 ipsec_mech_set
= true;
611 const char *use_ssl_cert
;
613 /* If the "use_ssl_cert" is true, then "certificate" and
614 * "private_key" will be pulled from the SSL table. The
615 * use of this option is strongly discouraged, since it
616 * will like be removed when multiple SSL configurations
617 * are supported by OVS.
619 use_ssl_cert
= smap_get(args
, "use_ssl_cert");
620 if (!use_ssl_cert
|| strcmp(use_ssl_cert
, "true")) {
621 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
625 ipsec_mech_set
= true;
627 } else if (!strcmp(node
->key
, "psk") && is_ipsec
) {
628 ipsec_mech_set
= true;
630 && (!strcmp(node
->key
, "certificate")
631 || !strcmp(node
->key
, "private_key")
632 || !strcmp(node
->key
, "use_ssl_cert"))) {
633 /* Ignore options not used by the netdev. */
634 } else if (!strcmp(node
->key
, "key") ||
635 !strcmp(node
->key
, "in_key") ||
636 !strcmp(node
->key
, "out_key")) {
637 /* Handled separately below. */
639 VLOG_WARN("%s: unknown %s argument '%s'", name
, type
, node
->key
);
643 /* Add a default destination port for VXLAN if none specified. */
644 if (needs_dst_port
&& !found_dst_port
) {
645 nl_msg_put_u16(options
, OVS_TUNNEL_ATTR_DST_PORT
, VXLAN_DST_PORT
);
649 static pid_t pid
= 0;
651 char *file_name
= xasprintf("%s/%s", ovs_rundir(),
652 "ovs-monitor-ipsec.pid");
653 pid
= read_pidfile(file_name
);
658 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
663 if (smap_get(args
, "peer_cert") && smap_get(args
, "psk")) {
664 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name
);
668 if (!ipsec_mech_set
) {
669 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
675 set_key(args
, "in_key", OVS_TUNNEL_ATTR_IN_KEY
, options
);
676 set_key(args
, "out_key", OVS_TUNNEL_ATTR_OUT_KEY
, options
);
679 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
683 nl_msg_put_be32(options
, OVS_TUNNEL_ATTR_DST_IPV4
, daddr
);
686 if (ip_is_multicast(daddr
)) {
687 VLOG_WARN("%s: remote_ip is multicast, ignoring local_ip", name
);
689 nl_msg_put_be32(options
, OVS_TUNNEL_ATTR_SRC_IPV4
, saddr
);
693 nl_msg_put_u32(options
, OVS_TUNNEL_ATTR_FLAGS
, flags
);
699 tnl_port_config_from_nlattr(const struct nlattr
*options
, size_t options_len
,
700 struct nlattr
*a
[OVS_TUNNEL_ATTR_MAX
+ 1])
702 static const struct nl_policy ovs_tunnel_policy
[] = {
703 [OVS_TUNNEL_ATTR_FLAGS
] = { .type
= NL_A_U32
, .optional
= true },
704 [OVS_TUNNEL_ATTR_DST_IPV4
] = { .type
= NL_A_BE32
, .optional
= true },
705 [OVS_TUNNEL_ATTR_SRC_IPV4
] = { .type
= NL_A_BE32
, .optional
= true },
706 [OVS_TUNNEL_ATTR_IN_KEY
] = { .type
= NL_A_BE64
, .optional
= true },
707 [OVS_TUNNEL_ATTR_OUT_KEY
] = { .type
= NL_A_BE64
, .optional
= true },
708 [OVS_TUNNEL_ATTR_TOS
] = { .type
= NL_A_U8
, .optional
= true },
709 [OVS_TUNNEL_ATTR_TTL
] = { .type
= NL_A_U8
, .optional
= true },
710 [OVS_TUNNEL_ATTR_DST_PORT
] = { .type
= NL_A_U16
, .optional
= true },
714 ofpbuf_use_const(&buf
, options
, options_len
);
715 if (!nl_policy_parse(&buf
, 0, ovs_tunnel_policy
,
716 a
, ARRAY_SIZE(ovs_tunnel_policy
))) {
723 get_be64_or_zero(const struct nlattr
*a
)
725 return a
? ntohll(nl_attr_get_be64(a
)) : 0;
729 unparse_tunnel_config(const char *name OVS_UNUSED
, const char *type OVS_UNUSED
,
730 const struct nlattr
*options
, size_t options_len
,
733 struct nlattr
*a
[OVS_TUNNEL_ATTR_MAX
+ 1];
737 error
= tnl_port_config_from_nlattr(options
, options_len
, a
);
742 if (a
[OVS_TUNNEL_ATTR_DST_IPV4
]) {
743 ovs_be32 daddr
= nl_attr_get_be32(a
[OVS_TUNNEL_ATTR_DST_IPV4
]);
744 smap_add_format(args
, "remote_ip", IP_FMT
, IP_ARGS(daddr
));
747 if (a
[OVS_TUNNEL_ATTR_SRC_IPV4
]) {
748 ovs_be32 saddr
= nl_attr_get_be32(a
[OVS_TUNNEL_ATTR_SRC_IPV4
]);
749 smap_add_format(args
, "local_ip", IP_FMT
, IP_ARGS(saddr
));
752 if (!a
[OVS_TUNNEL_ATTR_IN_KEY
] && !a
[OVS_TUNNEL_ATTR_OUT_KEY
]) {
753 smap_add(args
, "key", "flow");
755 uint64_t in_key
= get_be64_or_zero(a
[OVS_TUNNEL_ATTR_IN_KEY
]);
756 uint64_t out_key
= get_be64_or_zero(a
[OVS_TUNNEL_ATTR_OUT_KEY
]);
758 if (in_key
&& in_key
== out_key
) {
759 smap_add_format(args
, "key", "%"PRIu64
, in_key
);
761 if (!a
[OVS_TUNNEL_ATTR_IN_KEY
]) {
762 smap_add(args
, "in_key", "flow");
764 smap_add_format(args
, "in_key", "%"PRIu64
, in_key
);
767 if (!a
[OVS_TUNNEL_ATTR_OUT_KEY
]) {
768 smap_add(args
, "out_key", "flow");
769 } else if (out_key
) {
770 smap_add_format(args
, "out_key", "%"PRIu64
, out_key
);
775 flags
= get_u32_or_zero(a
[OVS_TUNNEL_ATTR_FLAGS
]);
777 if (flags
& TNL_F_TTL_INHERIT
) {
778 smap_add(args
, "ttl", "inherit");
779 } else if (a
[OVS_TUNNEL_ATTR_TTL
]) {
780 int ttl
= nl_attr_get_u8(a
[OVS_TUNNEL_ATTR_TTL
]);
781 smap_add_format(args
, "ttl", "%d", ttl
);
784 if (flags
& TNL_F_TOS_INHERIT
) {
785 smap_add(args
, "tos", "inherit");
786 } else if (a
[OVS_TUNNEL_ATTR_TOS
]) {
787 int tos
= nl_attr_get_u8(a
[OVS_TUNNEL_ATTR_TOS
]);
788 smap_add_format(args
, "tos", "0x%x", tos
);
791 if (a
[OVS_TUNNEL_ATTR_DST_PORT
]) {
792 uint16_t dst_port
= nl_attr_get_u16(a
[OVS_TUNNEL_ATTR_DST_PORT
]);
793 if (dst_port
!= VXLAN_DST_PORT
) {
794 smap_add_format(args
, "dst_port", "%d", dst_port
);
798 if (flags
& TNL_F_CSUM
) {
799 smap_add(args
, "csum", "true");
801 if (flags
& TNL_F_DF_INHERIT
) {
802 smap_add(args
, "df_inherit", "true");
804 if (!(flags
& TNL_F_DF_DEFAULT
)) {
805 smap_add(args
, "df_default", "false");
807 if (flags
& TNL_F_PMTUD
) {
808 smap_add(args
, "pmtud", "true");
815 parse_patch_config(const char *name
, const char *type OVS_UNUSED
,
816 const struct smap
*args
, struct ofpbuf
*options
)
820 peer
= smap_get(args
, "peer");
822 VLOG_ERR("%s: patch type requires valid 'peer' argument", name
);
826 if (smap_count(args
) > 1) {
827 VLOG_ERR("%s: patch type takes only a 'peer' argument", name
);
831 if (strlen(peer
) >= IFNAMSIZ
) {
832 VLOG_ERR("%s: patch 'peer' arg too long", name
);
836 if (!strcmp(name
, peer
)) {
837 VLOG_ERR("%s: patch peer must not be self", name
);
841 nl_msg_put_string(options
, OVS_PATCH_ATTR_PEER
, peer
);
847 unparse_patch_config(const char *name OVS_UNUSED
, const char *type OVS_UNUSED
,
848 const struct nlattr
*options
, size_t options_len
,
851 static const struct nl_policy ovs_patch_policy
[] = {
852 [OVS_PATCH_ATTR_PEER
] = { .type
= NL_A_STRING
,
857 struct nlattr
*a
[ARRAY_SIZE(ovs_patch_policy
)];
860 ofpbuf_use_const(&buf
, options
, options_len
);
861 if (!nl_policy_parse(&buf
, 0, ovs_patch_policy
,
862 a
, ARRAY_SIZE(ovs_patch_policy
))) {
866 smap_add(args
, "peer", nl_attr_get_string(a
[OVS_PATCH_ATTR_PEER
]));
870 #define VPORT_FUNCTIONS(GET_STATUS) \
875 netdev_vport_create, \
876 netdev_vport_destroy, \
877 netdev_vport_get_config, \
878 netdev_vport_set_config, \
881 netdev_vport_close, \
885 NULL, /* recv_wait */ \
889 NULL, /* send_wait */ \
891 netdev_vport_set_etheraddr, \
892 netdev_vport_get_etheraddr, \
893 NULL, /* get_mtu */ \
894 NULL, /* set_mtu */ \
895 NULL, /* get_ifindex */ \
896 NULL, /* get_carrier */ \
897 NULL, /* get_carrier_resets */ \
898 NULL, /* get_miimon */ \
899 netdev_vport_get_stats, \
900 NULL, /* set_stats */ \
902 NULL, /* get_features */ \
903 NULL, /* set_advertisements */ \
905 NULL, /* set_policing */ \
906 NULL, /* get_qos_types */ \
907 NULL, /* get_qos_capabilities */ \
908 NULL, /* get_qos */ \
909 NULL, /* set_qos */ \
910 NULL, /* get_queue */ \
911 NULL, /* set_queue */ \
912 NULL, /* delete_queue */ \
913 NULL, /* get_queue_stats */ \
914 NULL, /* dump_queues */ \
915 NULL, /* dump_queue_stats */ \
917 NULL, /* get_in4 */ \
918 NULL, /* set_in4 */ \
919 NULL, /* get_in6 */ \
920 NULL, /* add_router */ \
921 NULL, /* get_next_hop */ \
923 NULL, /* arp_lookup */ \
925 netdev_vport_update_flags, \
927 netdev_vport_change_seq
930 netdev_vport_register(void)
932 static const struct vport_class vport_classes
[] = {
933 { OVS_VPORT_TYPE_GRE
,
934 { "gre", VPORT_FUNCTIONS(netdev_vport_get_drv_info
) },
935 parse_tunnel_config
, unparse_tunnel_config
},
937 { OVS_VPORT_TYPE_GRE
,
938 { "ipsec_gre", VPORT_FUNCTIONS(netdev_vport_get_drv_info
) },
939 parse_tunnel_config
, unparse_tunnel_config
},
941 { OVS_VPORT_TYPE_GRE64
,
942 { "gre64", VPORT_FUNCTIONS(netdev_vport_get_drv_info
) },
943 parse_tunnel_config
, unparse_tunnel_config
},
945 { OVS_VPORT_TYPE_GRE64
,
946 { "ipsec_gre64", VPORT_FUNCTIONS(netdev_vport_get_drv_info
) },
947 parse_tunnel_config
, unparse_tunnel_config
},
949 { OVS_VPORT_TYPE_CAPWAP
,
950 { "capwap", VPORT_FUNCTIONS(netdev_vport_get_drv_info
) },
951 parse_tunnel_config
, unparse_tunnel_config
},
953 { OVS_VPORT_TYPE_VXLAN
,
954 { "vxlan", VPORT_FUNCTIONS(netdev_vport_get_drv_info
) },
955 parse_tunnel_config
, unparse_tunnel_config
},
957 { OVS_VPORT_TYPE_PATCH
,
958 { "patch", VPORT_FUNCTIONS(NULL
) },
959 parse_patch_config
, unparse_patch_config
}
964 for (i
= 0; i
< ARRAY_SIZE(vport_classes
); i
++) {
965 netdev_register_provider(&vport_classes
[i
].netdev_class
);