2 * Copyright (c) 2010, 2011, 2012, 2013 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
;
59 uint8_t etheraddr
[ETH_ADDR_LEN
];
63 enum ovs_vport_type type
;
64 struct netdev_class netdev_class
;
65 int (*parse_config
)(const char *name
, const char *type
,
66 const struct smap
*args
, struct ofpbuf
*options
);
67 int (*unparse_config
)(const char *name
, const char *type
,
68 const struct nlattr
*options
, size_t options_len
,
72 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(5, 20);
74 static int netdev_vport_create(const struct netdev_class
*, const char *,
75 struct netdev_dev
**);
76 static void netdev_vport_poll_notify(const struct netdev
*);
77 static int tnl_port_config_from_nlattr(const struct nlattr
*options
,
79 struct nlattr
*a
[OVS_TUNNEL_ATTR_MAX
+ 1]);
82 is_vport_class(const struct netdev_class
*class)
84 return class->create
== netdev_vport_create
;
87 static const struct vport_class
*
88 vport_class_cast(const struct netdev_class
*class)
90 assert(is_vport_class(class));
91 return CONTAINER_OF(class, struct vport_class
, netdev_class
);
94 static struct netdev_dev_vport
*
95 netdev_dev_vport_cast(const struct netdev_dev
*netdev_dev
)
97 assert(is_vport_class(netdev_dev_get_class(netdev_dev
)));
98 return CONTAINER_OF(netdev_dev
, struct netdev_dev_vport
, netdev_dev
);
101 static struct netdev_dev_vport
*
102 netdev_vport_get_dev(const struct netdev
*netdev
)
104 return netdev_dev_vport_cast(netdev_get_dev(netdev
));
107 /* If 'netdev' is a vport netdev, returns an ofpbuf that contains Netlink
108 * options to include in OVS_VPORT_ATTR_OPTIONS for configuring that vport.
109 * Otherwise returns NULL. */
110 const struct ofpbuf
*
111 netdev_vport_get_options(const struct netdev
*netdev
)
113 const struct netdev_dev
*dev
= netdev_get_dev(netdev
);
115 return (is_vport_class(netdev_dev_get_class(dev
))
116 ? netdev_dev_vport_cast(dev
)->options
121 netdev_vport_get_vport_type(const struct netdev
*netdev
)
123 const struct netdev_dev
*dev
= netdev_get_dev(netdev
);
124 const struct netdev_class
*class = netdev_dev_get_class(dev
);
126 return (is_vport_class(class) ? vport_class_cast(class)->type
127 : class == &netdev_internal_class
? OVS_VPORT_TYPE_INTERNAL
128 : (class == &netdev_linux_class
||
129 class == &netdev_tap_class
) ? OVS_VPORT_TYPE_NETDEV
130 : OVS_VPORT_TYPE_UNSPEC
);
134 get_u32_or_zero(const struct nlattr
*a
)
136 return a
? nl_attr_get_u32(a
) : 0;
140 netdev_vport_get_netdev_type(const struct dpif_linux_vport
*vport
)
142 struct nlattr
*a
[OVS_TUNNEL_ATTR_MAX
+ 1];
144 switch (vport
->type
) {
145 case OVS_VPORT_TYPE_UNSPEC
:
148 case OVS_VPORT_TYPE_NETDEV
:
151 case OVS_VPORT_TYPE_INTERNAL
:
154 case OVS_VPORT_TYPE_PATCH
:
157 case OVS_VPORT_TYPE_GRE
:
158 if (tnl_port_config_from_nlattr(vport
->options
, vport
->options_len
,
162 return (get_u32_or_zero(a
[OVS_TUNNEL_ATTR_FLAGS
]) & TNL_F_IPSEC
163 ? "ipsec_gre" : "gre");
165 case OVS_VPORT_TYPE_GRE64
:
166 if (tnl_port_config_from_nlattr(vport
->options
, vport
->options_len
,
170 return (get_u32_or_zero(a
[OVS_TUNNEL_ATTR_FLAGS
]) & TNL_F_IPSEC
171 ? "ipsec_gre64" : "gre64");
173 case OVS_VPORT_TYPE_CAPWAP
:
176 case OVS_VPORT_TYPE_VXLAN
:
179 case OVS_VPORT_TYPE_FT_GRE
:
180 case __OVS_VPORT_TYPE_MAX
:
184 VLOG_WARN_RL(&rl
, "dp%d: port `%s' has unsupported type %u",
185 vport
->dp_ifindex
, vport
->name
, (unsigned int) vport
->type
);
190 netdev_vport_create(const struct netdev_class
*netdev_class
, const char *name
,
191 struct netdev_dev
**netdev_devp
)
193 struct netdev_dev_vport
*dev
;
195 dev
= xmalloc(sizeof *dev
);
196 netdev_dev_init(&dev
->netdev_dev
, name
, netdev_class
);
199 eth_addr_random(dev
->etheraddr
);
201 *netdev_devp
= &dev
->netdev_dev
;
202 route_table_register();
208 netdev_vport_destroy(struct netdev_dev
*netdev_dev_
)
210 struct netdev_dev_vport
*netdev_dev
= netdev_dev_vport_cast(netdev_dev_
);
212 ofpbuf_delete(netdev_dev
->options
);
213 route_table_unregister();
218 netdev_vport_open(struct netdev_dev
*netdev_dev
, struct netdev
**netdevp
)
220 *netdevp
= xmalloc(sizeof **netdevp
);
221 netdev_init(*netdevp
, netdev_dev
);
226 netdev_vport_close(struct netdev
*netdev
)
232 netdev_vport_get_config(struct netdev_dev
*dev_
, struct smap
*args
)
234 const struct netdev_class
*netdev_class
= netdev_dev_get_class(dev_
);
235 const struct vport_class
*vport_class
= vport_class_cast(netdev_class
);
236 struct netdev_dev_vport
*dev
= netdev_dev_vport_cast(dev_
);
237 const char *name
= netdev_dev_get_name(dev_
);
241 struct dpif_linux_vport reply
;
244 error
= dpif_linux_vport_get(name
, &reply
, &buf
);
246 VLOG_ERR_RL(&rl
, "%s: vport query failed (%s)",
247 name
, strerror(error
));
251 dev
->options
= ofpbuf_clone_data(reply
.options
, reply
.options_len
);
255 error
= vport_class
->unparse_config(name
, netdev_class
->type
,
260 VLOG_ERR_RL(&rl
, "%s: failed to parse kernel config (%s)",
261 name
, strerror(error
));
267 netdev_vport_set_config(struct netdev_dev
*dev_
, const struct smap
*args
)
269 const struct netdev_class
*netdev_class
= netdev_dev_get_class(dev_
);
270 const struct vport_class
*vport_class
= vport_class_cast(netdev_class
);
271 struct netdev_dev_vport
*dev
= netdev_dev_vport_cast(dev_
);
272 const char *name
= netdev_dev_get_name(dev_
);
273 struct ofpbuf
*options
;
276 options
= ofpbuf_new(64);
277 error
= vport_class
->parse_config(name
, netdev_dev_get_type(dev_
),
281 || options
->size
!= dev
->options
->size
282 || memcmp(options
->data
, dev
->options
->data
, options
->size
))) {
283 struct dpif_linux_vport vport
;
285 dpif_linux_vport_init(&vport
);
286 vport
.cmd
= OVS_VPORT_CMD_SET
;
288 vport
.options
= options
->data
;
289 vport
.options_len
= options
->size
;
290 error
= dpif_linux_vport_transact(&vport
, NULL
, NULL
);
291 if (!error
|| error
== ENODEV
) {
292 /* Either reconfiguration succeeded or this vport is not installed
293 * in the kernel (e.g. it hasn't been added to a dpif yet with
294 * dpif_port_add()). */
295 ofpbuf_delete(dev
->options
);
296 dev
->options
= options
;
301 ofpbuf_delete(options
);
307 netdev_vport_set_etheraddr(struct netdev
*netdev
,
308 const uint8_t mac
[ETH_ADDR_LEN
])
310 memcpy(netdev_vport_get_dev(netdev
)->etheraddr
, mac
, ETH_ADDR_LEN
);
311 netdev_vport_poll_notify(netdev
);
316 netdev_vport_get_etheraddr(const struct netdev
*netdev
,
317 uint8_t mac
[ETH_ADDR_LEN
])
319 memcpy(mac
, netdev_vport_get_dev(netdev
)->etheraddr
, ETH_ADDR_LEN
);
323 /* Copies 'src' into 'dst', performing format conversion in the process.
325 * 'src' is allowed to be misaligned. */
327 netdev_stats_from_ovs_vport_stats(struct netdev_stats
*dst
,
328 const struct ovs_vport_stats
*src
)
330 dst
->rx_packets
= get_unaligned_u64(&src
->rx_packets
);
331 dst
->tx_packets
= get_unaligned_u64(&src
->tx_packets
);
332 dst
->rx_bytes
= get_unaligned_u64(&src
->rx_bytes
);
333 dst
->tx_bytes
= get_unaligned_u64(&src
->tx_bytes
);
334 dst
->rx_errors
= get_unaligned_u64(&src
->rx_errors
);
335 dst
->tx_errors
= get_unaligned_u64(&src
->tx_errors
);
336 dst
->rx_dropped
= get_unaligned_u64(&src
->rx_dropped
);
337 dst
->tx_dropped
= get_unaligned_u64(&src
->tx_dropped
);
340 dst
->rx_length_errors
= 0;
341 dst
->rx_over_errors
= 0;
342 dst
->rx_crc_errors
= 0;
343 dst
->rx_frame_errors
= 0;
344 dst
->rx_fifo_errors
= 0;
345 dst
->rx_missed_errors
= 0;
346 dst
->tx_aborted_errors
= 0;
347 dst
->tx_carrier_errors
= 0;
348 dst
->tx_fifo_errors
= 0;
349 dst
->tx_heartbeat_errors
= 0;
350 dst
->tx_window_errors
= 0;
354 netdev_vport_get_stats(const struct netdev
*netdev
, struct netdev_stats
*stats
)
356 struct dpif_linux_vport reply
;
360 error
= dpif_linux_vport_get(netdev_get_name(netdev
), &reply
, &buf
);
363 } else if (!reply
.stats
) {
368 netdev_stats_from_ovs_vport_stats(stats
, reply
.stats
);
376 tunnel_get_status(const struct netdev
*netdev
, struct smap
*smap
)
378 struct netdev_dev_vport
*ndv
= netdev_vport_get_dev(netdev
);
379 struct nlattr
*a
[OVS_TUNNEL_ATTR_MAX
+ 1];
380 static char iface
[IFNAMSIZ
];
384 /* Race condition when 'ndv' was created, but did not have it's
385 * configuration set yet. */
389 if (tnl_port_config_from_nlattr(ndv
->options
->data
,
390 ndv
->options
->size
, a
)) {
393 route
= nl_attr_get_be32(a
[OVS_TUNNEL_ATTR_DST_IPV4
]);
395 if (route_table_get_name(route
, iface
)) {
396 struct netdev
*egress_netdev
;
398 smap_add(smap
, "tunnel_egress_iface", iface
);
400 if (!netdev_open(iface
, "system", &egress_netdev
)) {
401 smap_add(smap
, "tunnel_egress_iface_carrier",
402 netdev_get_carrier(egress_netdev
) ? "up" : "down");
403 netdev_close(egress_netdev
);
411 netdev_vport_update_flags(struct netdev
*netdev OVS_UNUSED
,
412 enum netdev_flags off
, enum netdev_flags on OVS_UNUSED
,
413 enum netdev_flags
*old_flagsp
)
415 if (off
& (NETDEV_UP
| NETDEV_PROMISC
)) {
419 *old_flagsp
= NETDEV_UP
| NETDEV_PROMISC
;
424 netdev_vport_change_seq(const struct netdev
*netdev
)
426 return netdev_vport_get_dev(netdev
)->change_seq
;
430 netdev_vport_run(void)
436 netdev_vport_wait(void)
441 /* Helper functions. */
444 netdev_vport_poll_notify(const struct netdev
*netdev
)
446 struct netdev_dev_vport
*ndv
= netdev_vport_get_dev(netdev
);
449 if (!ndv
->change_seq
) {
454 /* Code specific to individual vport types. */
457 set_key(const struct smap
*args
, const char *name
, uint16_t type
,
458 struct ofpbuf
*options
)
462 s
= smap_get(args
, name
);
464 s
= smap_get(args
, "key");
470 if (!strcmp(s
, "flow")) {
471 /* This is the default if no attribute is present. */
473 nl_msg_put_be64(options
, type
, htonll(strtoull(s
, NULL
, 0)));
478 parse_tunnel_config(const char *name
, const char *type
,
479 const struct smap
*args
, struct ofpbuf
*options
)
482 bool is_ipsec
= false;
483 bool needs_dst_port
= false;
484 bool found_dst_port
= false;
485 struct smap_node
*node
;
486 bool ipsec_mech_set
= false;
487 ovs_be32 daddr
= htonl(0);
488 ovs_be32 saddr
= htonl(0);
491 if (!strcmp(type
, "capwap")) {
492 VLOG_WARN_ONCE("CAPWAP tunnel support is deprecated.");
495 flags
= TNL_F_DF_DEFAULT
;
496 if (!strcmp(type
, "gre") || !strcmp(type
, "gre64")) {
498 } else if (!strcmp(type
, "ipsec_gre") || !strcmp(type
, "ipsec_gre64")) {
501 flags
|= TNL_F_IPSEC
;
502 } else if (!strcmp(type
, "vxlan")) {
503 needs_dst_port
= true;
506 SMAP_FOR_EACH (node
, args
) {
507 if (!strcmp(node
->key
, "remote_ip")) {
508 struct in_addr in_addr
;
509 if (lookup_ip(node
->value
, &in_addr
)) {
510 VLOG_WARN("%s: bad %s 'remote_ip'", name
, type
);
512 daddr
= in_addr
.s_addr
;
514 } else if (!strcmp(node
->key
, "local_ip")) {
515 struct in_addr in_addr
;
516 if (lookup_ip(node
->value
, &in_addr
)) {
517 VLOG_WARN("%s: bad %s 'local_ip'", name
, type
);
519 saddr
= in_addr
.s_addr
;
521 } else if (!strcmp(node
->key
, "tos")) {
522 if (!strcmp(node
->value
, "inherit")) {
523 flags
|= TNL_F_TOS_INHERIT
;
527 tos
= strtol(node
->value
, &endptr
, 0);
528 if (*endptr
== '\0' && tos
== (tos
& IP_DSCP_MASK
)) {
529 nl_msg_put_u8(options
, OVS_TUNNEL_ATTR_TOS
, tos
);
531 VLOG_WARN("%s: invalid TOS %s", name
, node
->value
);
534 } else if (!strcmp(node
->key
, "ttl")) {
535 if (!strcmp(node
->value
, "inherit")) {
536 flags
|= TNL_F_TTL_INHERIT
;
538 nl_msg_put_u8(options
, OVS_TUNNEL_ATTR_TTL
, atoi(node
->value
));
540 } else if (!strcmp(node
->key
, "dst_port") && needs_dst_port
) {
541 nl_msg_put_u16(options
, OVS_TUNNEL_ATTR_DST_PORT
,
543 found_dst_port
= true;
544 } else if (!strcmp(node
->key
, "csum") && is_gre
) {
545 if (!strcmp(node
->value
, "true")) {
548 } else if (!strcmp(node
->key
, "df_default")) {
549 if (!strcmp(node
->value
, "false")) {
550 flags
&= ~TNL_F_DF_DEFAULT
;
552 } else if (!strcmp(node
->key
, "peer_cert") && is_ipsec
) {
553 if (smap_get(args
, "certificate")) {
554 ipsec_mech_set
= true;
556 const char *use_ssl_cert
;
558 /* If the "use_ssl_cert" is true, then "certificate" and
559 * "private_key" will be pulled from the SSL table. The
560 * use of this option is strongly discouraged, since it
561 * will like be removed when multiple SSL configurations
562 * are supported by OVS.
564 use_ssl_cert
= smap_get(args
, "use_ssl_cert");
565 if (!use_ssl_cert
|| strcmp(use_ssl_cert
, "true")) {
566 VLOG_ERR("%s: 'peer_cert' requires 'certificate' argument",
570 ipsec_mech_set
= true;
572 } else if (!strcmp(node
->key
, "psk") && is_ipsec
) {
573 ipsec_mech_set
= true;
575 && (!strcmp(node
->key
, "certificate")
576 || !strcmp(node
->key
, "private_key")
577 || !strcmp(node
->key
, "use_ssl_cert"))) {
578 /* Ignore options not used by the netdev. */
579 } else if (!strcmp(node
->key
, "key") ||
580 !strcmp(node
->key
, "in_key") ||
581 !strcmp(node
->key
, "out_key")) {
582 /* Handled separately below. */
584 VLOG_WARN("%s: unknown %s argument '%s'", name
, type
, node
->key
);
588 /* Add a default destination port for VXLAN if none specified. */
589 if (needs_dst_port
&& !found_dst_port
) {
590 nl_msg_put_u16(options
, OVS_TUNNEL_ATTR_DST_PORT
, VXLAN_DST_PORT
);
594 static pid_t pid
= 0;
596 char *file_name
= xasprintf("%s/%s", ovs_rundir(),
597 "ovs-monitor-ipsec.pid");
598 pid
= read_pidfile(file_name
);
603 VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
608 if (smap_get(args
, "peer_cert") && smap_get(args
, "psk")) {
609 VLOG_ERR("%s: cannot define both 'peer_cert' and 'psk'", name
);
613 if (!ipsec_mech_set
) {
614 VLOG_ERR("%s: IPsec requires an 'peer_cert' or psk' argument",
620 set_key(args
, "in_key", OVS_TUNNEL_ATTR_IN_KEY
, options
);
621 set_key(args
, "out_key", OVS_TUNNEL_ATTR_OUT_KEY
, options
);
624 VLOG_ERR("%s: %s type requires valid 'remote_ip' argument",
628 nl_msg_put_be32(options
, OVS_TUNNEL_ATTR_DST_IPV4
, daddr
);
631 if (ip_is_multicast(daddr
)) {
632 VLOG_WARN("%s: remote_ip is multicast, ignoring local_ip", name
);
634 nl_msg_put_be32(options
, OVS_TUNNEL_ATTR_SRC_IPV4
, saddr
);
638 nl_msg_put_u32(options
, OVS_TUNNEL_ATTR_FLAGS
, flags
);
644 tnl_port_config_from_nlattr(const struct nlattr
*options
, size_t options_len
,
645 struct nlattr
*a
[OVS_TUNNEL_ATTR_MAX
+ 1])
647 static const struct nl_policy ovs_tunnel_policy
[] = {
648 [OVS_TUNNEL_ATTR_FLAGS
] = { .type
= NL_A_U32
, .optional
= true },
649 [OVS_TUNNEL_ATTR_DST_IPV4
] = { .type
= NL_A_BE32
, .optional
= true },
650 [OVS_TUNNEL_ATTR_SRC_IPV4
] = { .type
= NL_A_BE32
, .optional
= true },
651 [OVS_TUNNEL_ATTR_IN_KEY
] = { .type
= NL_A_BE64
, .optional
= true },
652 [OVS_TUNNEL_ATTR_OUT_KEY
] = { .type
= NL_A_BE64
, .optional
= true },
653 [OVS_TUNNEL_ATTR_TOS
] = { .type
= NL_A_U8
, .optional
= true },
654 [OVS_TUNNEL_ATTR_TTL
] = { .type
= NL_A_U8
, .optional
= true },
655 [OVS_TUNNEL_ATTR_DST_PORT
] = { .type
= NL_A_U16
, .optional
= true },
659 ofpbuf_use_const(&buf
, options
, options_len
);
660 if (!nl_policy_parse(&buf
, 0, ovs_tunnel_policy
,
661 a
, ARRAY_SIZE(ovs_tunnel_policy
))) {
668 get_be64_or_zero(const struct nlattr
*a
)
670 return a
? ntohll(nl_attr_get_be64(a
)) : 0;
674 unparse_tunnel_config(const char *name OVS_UNUSED
, const char *type OVS_UNUSED
,
675 const struct nlattr
*options
, size_t options_len
,
678 struct nlattr
*a
[OVS_TUNNEL_ATTR_MAX
+ 1];
682 error
= tnl_port_config_from_nlattr(options
, options_len
, a
);
687 if (a
[OVS_TUNNEL_ATTR_DST_IPV4
]) {
688 ovs_be32 daddr
= nl_attr_get_be32(a
[OVS_TUNNEL_ATTR_DST_IPV4
]);
689 smap_add_format(args
, "remote_ip", IP_FMT
, IP_ARGS(daddr
));
692 if (a
[OVS_TUNNEL_ATTR_SRC_IPV4
]) {
693 ovs_be32 saddr
= nl_attr_get_be32(a
[OVS_TUNNEL_ATTR_SRC_IPV4
]);
694 smap_add_format(args
, "local_ip", IP_FMT
, IP_ARGS(saddr
));
697 if (!a
[OVS_TUNNEL_ATTR_IN_KEY
] && !a
[OVS_TUNNEL_ATTR_OUT_KEY
]) {
698 smap_add(args
, "key", "flow");
700 uint64_t in_key
= get_be64_or_zero(a
[OVS_TUNNEL_ATTR_IN_KEY
]);
701 uint64_t out_key
= get_be64_or_zero(a
[OVS_TUNNEL_ATTR_OUT_KEY
]);
703 if (in_key
&& in_key
== out_key
) {
704 smap_add_format(args
, "key", "%"PRIu64
, in_key
);
706 if (!a
[OVS_TUNNEL_ATTR_IN_KEY
]) {
707 smap_add(args
, "in_key", "flow");
709 smap_add_format(args
, "in_key", "%"PRIu64
, in_key
);
712 if (!a
[OVS_TUNNEL_ATTR_OUT_KEY
]) {
713 smap_add(args
, "out_key", "flow");
714 } else if (out_key
) {
715 smap_add_format(args
, "out_key", "%"PRIu64
, out_key
);
720 flags
= get_u32_or_zero(a
[OVS_TUNNEL_ATTR_FLAGS
]);
722 if (flags
& TNL_F_TTL_INHERIT
) {
723 smap_add(args
, "ttl", "inherit");
724 } else if (a
[OVS_TUNNEL_ATTR_TTL
]) {
725 int ttl
= nl_attr_get_u8(a
[OVS_TUNNEL_ATTR_TTL
]);
726 smap_add_format(args
, "ttl", "%d", ttl
);
729 if (flags
& TNL_F_TOS_INHERIT
) {
730 smap_add(args
, "tos", "inherit");
731 } else if (a
[OVS_TUNNEL_ATTR_TOS
]) {
732 int tos
= nl_attr_get_u8(a
[OVS_TUNNEL_ATTR_TOS
]);
733 smap_add_format(args
, "tos", "0x%x", tos
);
736 if (a
[OVS_TUNNEL_ATTR_DST_PORT
]) {
737 uint16_t dst_port
= nl_attr_get_u16(a
[OVS_TUNNEL_ATTR_DST_PORT
]);
738 if (dst_port
!= VXLAN_DST_PORT
) {
739 smap_add_format(args
, "dst_port", "%d", dst_port
);
743 if (flags
& TNL_F_CSUM
) {
744 smap_add(args
, "csum", "true");
746 if (flags
& TNL_F_DF_INHERIT
) {
747 /* Shouldn't happen as "df_inherit" is no longer supported. However,
748 * for completeness we report it if it's there. */
749 smap_add(args
, "df_inherit", "true");
751 if (!(flags
& TNL_F_DF_DEFAULT
)) {
752 smap_add(args
, "df_default", "false");
759 parse_patch_config(const char *name
, const char *type OVS_UNUSED
,
760 const struct smap
*args
, struct ofpbuf
*options
)
764 peer
= smap_get(args
, "peer");
766 VLOG_ERR("%s: patch type requires valid 'peer' argument", name
);
770 if (smap_count(args
) > 1) {
771 VLOG_ERR("%s: patch type takes only a 'peer' argument", name
);
775 if (strlen(peer
) >= IFNAMSIZ
) {
776 VLOG_ERR("%s: patch 'peer' arg too long", name
);
780 if (!strcmp(name
, peer
)) {
781 VLOG_ERR("%s: patch peer must not be self", name
);
785 nl_msg_put_string(options
, OVS_PATCH_ATTR_PEER
, peer
);
791 unparse_patch_config(const char *name OVS_UNUSED
, const char *type OVS_UNUSED
,
792 const struct nlattr
*options
, size_t options_len
,
795 static const struct nl_policy ovs_patch_policy
[] = {
796 [OVS_PATCH_ATTR_PEER
] = { .type
= NL_A_STRING
,
801 struct nlattr
*a
[ARRAY_SIZE(ovs_patch_policy
)];
804 ofpbuf_use_const(&buf
, options
, options_len
);
805 if (!nl_policy_parse(&buf
, 0, ovs_patch_policy
,
806 a
, ARRAY_SIZE(ovs_patch_policy
))) {
810 smap_add(args
, "peer", nl_attr_get_string(a
[OVS_PATCH_ATTR_PEER
]));
814 #define VPORT_FUNCTIONS(GET_STATUS) \
819 netdev_vport_create, \
820 netdev_vport_destroy, \
821 netdev_vport_get_config, \
822 netdev_vport_set_config, \
825 netdev_vport_close, \
829 NULL, /* recv_wait */ \
833 NULL, /* send_wait */ \
835 netdev_vport_set_etheraddr, \
836 netdev_vport_get_etheraddr, \
837 NULL, /* get_mtu */ \
838 NULL, /* set_mtu */ \
839 NULL, /* get_ifindex */ \
840 NULL, /* get_carrier */ \
841 NULL, /* get_carrier_resets */ \
842 NULL, /* get_miimon */ \
843 netdev_vport_get_stats, \
844 NULL, /* set_stats */ \
846 NULL, /* get_features */ \
847 NULL, /* set_advertisements */ \
849 NULL, /* set_policing */ \
850 NULL, /* get_qos_types */ \
851 NULL, /* get_qos_capabilities */ \
852 NULL, /* get_qos */ \
853 NULL, /* set_qos */ \
854 NULL, /* get_queue */ \
855 NULL, /* set_queue */ \
856 NULL, /* delete_queue */ \
857 NULL, /* get_queue_stats */ \
858 NULL, /* dump_queues */ \
859 NULL, /* dump_queue_stats */ \
861 NULL, /* get_in4 */ \
862 NULL, /* set_in4 */ \
863 NULL, /* get_in6 */ \
864 NULL, /* add_router */ \
865 NULL, /* get_next_hop */ \
867 NULL, /* arp_lookup */ \
869 netdev_vport_update_flags, \
871 netdev_vport_change_seq
873 #define TUNNEL_CLASS(NAME, VPORT_TYPE) \
875 { NAME, VPORT_FUNCTIONS(tunnel_get_status) }, \
876 parse_tunnel_config, unparse_tunnel_config }
879 netdev_vport_register(void)
881 static const struct vport_class vport_classes
[] = {
882 TUNNEL_CLASS("gre", OVS_VPORT_TYPE_GRE
),
883 TUNNEL_CLASS("ipsec_gre", OVS_VPORT_TYPE_GRE
),
884 TUNNEL_CLASS("gre64", OVS_VPORT_TYPE_GRE64
),
885 TUNNEL_CLASS("ipsec_gre64", OVS_VPORT_TYPE_GRE64
),
886 TUNNEL_CLASS("capwap", OVS_VPORT_TYPE_CAPWAP
),
887 TUNNEL_CLASS("vxlan", OVS_VPORT_TYPE_VXLAN
),
889 { OVS_VPORT_TYPE_PATCH
,
890 { "patch", VPORT_FUNCTIONS(NULL
) },
891 parse_patch_config
, unparse_patch_config
}
896 for (i
= 0; i
< ARRAY_SIZE(vport_classes
); i
++) {
897 netdev_register_provider(&vport_classes
[i
].netdev_class
);