2 * Copyright (c) 2010 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"
32 #include "netdev-provider.h"
34 #include "netlink-socket.h"
36 #include "openvswitch/datapath-protocol.h"
37 #include "openvswitch/tunnel.h"
39 #include "rtnetlink.h"
40 #include "rtnetlink-route.h"
41 #include "rtnetlink-link.h"
43 #include "socket-util.h"
46 VLOG_DEFINE_THIS_MODULE(netdev_vport);
48 static struct hmap name_map;
49 static struct hmap route_map;
50 static struct rtnetlink_notifier netdev_vport_link_notifier;
51 static struct rtnetlink_notifier netdev_vport_route_notifier;
54 struct hmap_node node; /* Node in route_map. */
55 int rta_oif; /* Egress interface index. */
56 uint32_t rta_dst; /* Destination address in host byte order. */
57 unsigned char rtm_dst_len; /* Destination address length. */
61 struct hmap_node node; /* Node in name_map. */
62 uint32_t ifi_index; /* Kernel interface index. */
64 char ifname[IFNAMSIZ]; /* Interface name. */
67 struct netdev_vport_notifier {
68 struct netdev_notifier notifier;
69 struct list list_node;
70 struct shash_node *shash_node;
73 struct netdev_dev_vport {
74 struct netdev_dev netdev_dev;
75 uint64_t config[VPORT_CONFIG_SIZE / 8];
83 struct netdev_class netdev_class;
84 int (*parse_config)(const struct netdev_dev *, const struct shash *args,
88 static struct shash netdev_vport_notifiers =
89 SHASH_INITIALIZER(&netdev_vport_notifiers);
91 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
93 static int netdev_vport_do_ioctl(int cmd, void *arg);
94 static int netdev_vport_create(const struct netdev_class *, const char *,
95 const struct shash *, struct netdev_dev **);
96 static void netdev_vport_poll_notify(const struct netdev *);
98 static void netdev_vport_tnl_iface_init(void);
99 static void netdev_vport_route_change(const struct rtnetlink_route_change *,
101 static void netdev_vport_link_change(const struct rtnetlink_link_change *,
105 is_vport_class(const struct netdev_class *class)
107 return class->create == netdev_vport_create;
110 static const struct vport_class *
111 vport_class_cast(const struct netdev_class *class)
113 assert(is_vport_class(class));
114 return CONTAINER_OF(class, struct vport_class, netdev_class);
117 static struct netdev_dev_vport *
118 netdev_dev_vport_cast(const struct netdev_dev *netdev_dev)
120 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
121 return CONTAINER_OF(netdev_dev, struct netdev_dev_vport, netdev_dev);
124 static struct netdev_vport *
125 netdev_vport_cast(const struct netdev *netdev)
127 struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
128 assert(is_vport_class(netdev_dev_get_class(netdev_dev)));
129 return CONTAINER_OF(netdev, struct netdev_vport, netdev);
132 /* If 'netdev' is a vport netdev, copies its kernel configuration into
133 * 'config'. Otherwise leaves 'config' untouched. */
135 netdev_vport_get_config(const struct netdev *netdev, void *config)
137 const struct netdev_dev *dev = netdev_get_dev(netdev);
139 if (is_vport_class(netdev_dev_get_class(dev))) {
140 const struct netdev_dev_vport *vport = netdev_dev_vport_cast(dev);
141 memcpy(config, vport->config, VPORT_CONFIG_SIZE);
146 netdev_vport_init(void)
148 netdev_vport_tnl_iface_init();
153 netdev_vport_create(const struct netdev_class *netdev_class, const char *name,
154 const struct shash *args,
155 struct netdev_dev **netdev_devp)
157 const struct vport_class *vport_class = vport_class_cast(netdev_class);
158 struct netdev_dev_vport *dev;
161 dev = xmalloc(sizeof *dev);
162 *netdev_devp = &dev->netdev_dev;
163 netdev_dev_init(&dev->netdev_dev, name, netdev_class);
165 memset(dev->config, 0, sizeof dev->config);
166 error = vport_class->parse_config(&dev->netdev_dev, args, dev->config);
169 netdev_dev_uninit(&dev->netdev_dev, true);
175 netdev_vport_destroy(struct netdev_dev *netdev_dev_)
177 struct netdev_dev_vport *netdev_dev = netdev_dev_vport_cast(netdev_dev_);
183 netdev_vport_open(struct netdev_dev *netdev_dev_, int ethertype OVS_UNUSED,
184 struct netdev **netdevp)
186 struct netdev_vport *netdev;
188 netdev = xmalloc(sizeof *netdev);
189 netdev_init(&netdev->netdev, netdev_dev_);
191 *netdevp = &netdev->netdev;
196 netdev_vport_close(struct netdev *netdev_)
198 struct netdev_vport *netdev = netdev_vport_cast(netdev_);
203 netdev_vport_reconfigure(struct netdev_dev *dev_,
204 const struct shash *args)
206 const struct netdev_class *netdev_class = netdev_dev_get_class(dev_);
207 const struct vport_class *vport_class = vport_class_cast(netdev_class);
208 struct netdev_dev_vport *dev = netdev_dev_vport_cast(dev_);
209 struct odp_port port;
212 memset(&port, 0, sizeof port);
213 strncpy(port.devname, netdev_dev_get_name(dev_), sizeof port.devname);
214 strncpy(port.type, netdev_dev_get_type(dev_), sizeof port.type);
215 error = vport_class->parse_config(dev_, args, port.config);
216 if (!error && memcmp(port.config, dev->config, sizeof dev->config)) {
217 error = netdev_vport_do_ioctl(ODP_VPORT_MOD, &port);
218 if (!error || error == ENODEV) {
219 /* Either reconfiguration succeeded or this vport is not installed
220 * in the kernel (e.g. it hasn't been added to a dpif yet with
221 * dpif_port_add()). */
222 memcpy(dev->config, port.config, sizeof dev->config);
229 netdev_vport_set_etheraddr(struct netdev *netdev,
230 const uint8_t mac[ETH_ADDR_LEN])
232 struct odp_vport_ether vport_ether;
235 ovs_strlcpy(vport_ether.devname, netdev_get_name(netdev),
236 sizeof vport_ether.devname);
238 memcpy(vport_ether.ether_addr, mac, ETH_ADDR_LEN);
240 err = netdev_vport_do_ioctl(ODP_VPORT_ETHER_SET, &vport_ether);
245 netdev_vport_poll_notify(netdev);
250 netdev_vport_get_etheraddr(const struct netdev *netdev,
251 uint8_t mac[ETH_ADDR_LEN])
253 struct odp_vport_ether vport_ether;
256 ovs_strlcpy(vport_ether.devname, netdev_get_name(netdev),
257 sizeof vport_ether.devname);
259 err = netdev_vport_do_ioctl(ODP_VPORT_ETHER_GET, &vport_ether);
264 memcpy(mac, vport_ether.ether_addr, ETH_ADDR_LEN);
269 netdev_vport_get_mtu(const struct netdev *netdev, int *mtup)
271 struct odp_vport_mtu vport_mtu;
274 ovs_strlcpy(vport_mtu.devname, netdev_get_name(netdev),
275 sizeof vport_mtu.devname);
277 err = netdev_vport_do_ioctl(ODP_VPORT_MTU_GET, &vport_mtu);
282 *mtup = vport_mtu.mtu;
287 netdev_vport_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
289 const char *name = netdev_get_name(netdev);
290 struct odp_vport_stats_req ovsr;
293 ovs_strlcpy(ovsr.devname, name, sizeof ovsr.devname);
294 err = netdev_vport_do_ioctl(ODP_VPORT_STATS_GET, &ovsr);
299 stats->rx_packets = ovsr.stats.rx_packets;
300 stats->tx_packets = ovsr.stats.tx_packets;
301 stats->rx_bytes = ovsr.stats.rx_bytes;
302 stats->tx_bytes = ovsr.stats.tx_bytes;
303 stats->rx_errors = ovsr.stats.rx_errors;
304 stats->tx_errors = ovsr.stats.tx_errors;
305 stats->rx_dropped = ovsr.stats.rx_dropped;
306 stats->tx_dropped = ovsr.stats.tx_dropped;
307 stats->multicast = ovsr.stats.multicast;
308 stats->collisions = ovsr.stats.collisions;
309 stats->rx_length_errors = ovsr.stats.rx_length_errors;
310 stats->rx_over_errors = ovsr.stats.rx_over_errors;
311 stats->rx_crc_errors = ovsr.stats.rx_crc_errors;
312 stats->rx_frame_errors = ovsr.stats.rx_frame_errors;
313 stats->rx_fifo_errors = ovsr.stats.rx_fifo_errors;
314 stats->rx_missed_errors = ovsr.stats.rx_missed_errors;
315 stats->tx_aborted_errors = ovsr.stats.tx_aborted_errors;
316 stats->tx_carrier_errors = ovsr.stats.tx_carrier_errors;
317 stats->tx_fifo_errors = ovsr.stats.tx_fifo_errors;
318 stats->tx_heartbeat_errors = ovsr.stats.tx_heartbeat_errors;
319 stats->tx_window_errors = ovsr.stats.tx_window_errors;
325 netdev_vport_set_stats(struct netdev *netdev, const struct netdev_stats *stats)
327 struct odp_vport_stats_req ovsr;
330 ovs_strlcpy(ovsr.devname, netdev_get_name(netdev), sizeof ovsr.devname);
332 ovsr.stats.rx_packets = stats->rx_packets;
333 ovsr.stats.tx_packets = stats->tx_packets;
334 ovsr.stats.rx_bytes = stats->rx_bytes;
335 ovsr.stats.tx_bytes = stats->tx_bytes;
336 ovsr.stats.rx_errors = stats->rx_errors;
337 ovsr.stats.tx_errors = stats->tx_errors;
338 ovsr.stats.rx_dropped = stats->rx_dropped;
339 ovsr.stats.tx_dropped = stats->tx_dropped;
340 ovsr.stats.multicast = stats->multicast;
341 ovsr.stats.collisions = stats->collisions;
342 ovsr.stats.rx_length_errors = stats->rx_length_errors;
343 ovsr.stats.rx_over_errors = stats->rx_over_errors;
344 ovsr.stats.rx_crc_errors = stats->rx_crc_errors;
345 ovsr.stats.rx_frame_errors = stats->rx_frame_errors;
346 ovsr.stats.rx_fifo_errors = stats->rx_fifo_errors;
347 ovsr.stats.rx_missed_errors = stats->rx_missed_errors;
348 ovsr.stats.tx_aborted_errors = stats->tx_aborted_errors;
349 ovsr.stats.tx_carrier_errors = stats->tx_carrier_errors;
350 ovsr.stats.tx_fifo_errors = stats->tx_fifo_errors;
351 ovsr.stats.tx_heartbeat_errors = stats->tx_heartbeat_errors;
352 ovsr.stats.tx_window_errors = stats->tx_window_errors;
354 err = netdev_vport_do_ioctl(ODP_VPORT_STATS_SET, &ovsr);
356 /* If the vport layer doesn't know about the device, that doesn't mean it
357 * doesn't exist (after all were able to open it when netdev_open() was
358 * called), it just means that it isn't attached and we'll be getting
359 * stats a different way. */
368 netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED,
369 enum netdev_flags off, enum netdev_flags on OVS_UNUSED,
370 enum netdev_flags *old_flagsp)
372 if (off & (NETDEV_UP | NETDEV_PROMISC)) {
376 *old_flagsp = NETDEV_UP | NETDEV_PROMISC;
381 make_poll_name(const struct netdev *netdev)
383 return xasprintf("%s:%s", netdev_get_type(netdev), netdev_get_name(netdev));
387 netdev_vport_poll_add(struct netdev *netdev,
388 void (*cb)(struct netdev_notifier *), void *aux,
389 struct netdev_notifier **notifierp)
391 char *poll_name = make_poll_name(netdev);
392 struct netdev_vport_notifier *notifier;
394 struct shash_node *shash_node;
396 shash_node = shash_find_data(&netdev_vport_notifiers, poll_name);
398 list = xmalloc(sizeof *list);
400 shash_node = shash_add(&netdev_vport_notifiers, poll_name, list);
402 list = shash_node->data;
405 notifier = xmalloc(sizeof *notifier);
406 netdev_notifier_init(¬ifier->notifier, netdev, cb, aux);
407 list_push_back(list, ¬ifier->list_node);
408 notifier->shash_node = shash_node;
410 *notifierp = ¬ifier->notifier;
417 netdev_vport_poll_remove(struct netdev_notifier *notifier_)
419 struct netdev_vport_notifier *notifier =
420 CONTAINER_OF(notifier_, struct netdev_vport_notifier, notifier);
424 list = list_remove(¬ifier->list_node);
425 if (list_is_empty(list)) {
426 shash_delete(&netdev_vport_notifiers, notifier->shash_node);
434 netdev_vport_run(void)
436 rtnetlink_link_notifier_run();
437 rtnetlink_route_notifier_run();
441 netdev_vport_wait(void)
443 rtnetlink_link_notifier_wait();
444 rtnetlink_route_notifier_wait();
447 /* get_tnl_iface() implementation. */
449 static struct name_node *
450 name_node_lookup(int ifi_index)
452 struct name_node *nn;
454 HMAP_FOR_EACH_WITH_HASH(nn, node, hash_int(ifi_index, 0), &name_map) {
455 if (nn->ifi_index == ifi_index) {
463 static struct route_node *
464 route_node_lookup(int rta_oif, uint32_t rta_dst, unsigned char rtm_dst_len)
467 struct route_node *rn;
469 hash = hash_3words(rta_oif, rta_dst, rtm_dst_len);
470 HMAP_FOR_EACH_WITH_HASH(rn, node, hash, &route_map) {
471 if (rn->rta_oif == rn->rta_oif &&
472 rn->rta_dst == rn->rta_dst &&
473 rn->rtm_dst_len == rn->rtm_dst_len) {
481 /* Resets the name or route map depending on the value of 'is_name'. Clears
482 * the appropriate map, makes an rtnetlink dump request, and calls the change
483 * callback for each reply from the kernel. One should probably use
484 * netdev_vport_reset_routes or netdev_vport_reset_names instead. */
486 netdev_vport_reset_name_else_route(bool is_name)
491 struct rtgenmsg *rtmsg;
492 struct ofpbuf request, reply;
493 static struct nl_sock *rtnl_sock;
496 struct name_node *nn, *nn_next;
498 HMAP_FOR_EACH_SAFE(nn, nn_next, node, &name_map) {
499 hmap_remove(&name_map, &nn->node);
503 struct route_node *rn, *rn_next;
505 HMAP_FOR_EACH_SAFE(rn, rn_next, node, &route_map) {
506 hmap_remove(&route_map, &rn->node);
511 error = nl_sock_create(NETLINK_ROUTE, 0, 0, 0, &rtnl_sock);
513 VLOG_WARN_RL(&rl, "Failed to create NETLINK_ROUTE socket");
517 ofpbuf_init(&request, 0);
519 nlmsg_type = is_name ? RTM_GETLINK : RTM_GETROUTE;
520 nl_msg_put_nlmsghdr(&request, sizeof *rtmsg, nlmsg_type, NLM_F_REQUEST);
522 rtmsg = ofpbuf_put_zeros(&request, sizeof *rtmsg);
523 rtmsg->rtgen_family = AF_INET;
525 nl_dump_start(&dump, rtnl_sock, &request);
527 while (nl_dump_next(&dump, &reply)) {
529 struct rtnetlink_link_change change;
531 if (rtnetlink_link_parse(&reply, &change)) {
532 netdev_vport_link_change(&change, NULL);
535 struct rtnetlink_route_change change;
537 if (rtnetlink_route_parse(&reply, &change)) {
538 netdev_vport_route_change(&change, NULL);
543 error = nl_dump_done(&dump);
544 nl_sock_destroy(rtnl_sock);
550 netdev_vport_reset_routes(void)
552 return netdev_vport_reset_name_else_route(false);
556 netdev_vport_reset_names(void)
558 return netdev_vport_reset_name_else_route(true);
562 netdev_vport_route_change(const struct rtnetlink_route_change *change,
563 void *aux OVS_UNUSED)
567 netdev_vport_reset_routes();
568 } else if (change->nlmsg_type == RTM_NEWROUTE) {
570 struct route_node *rn;
572 if (route_node_lookup(change->rta_oif, change->rta_dst,
573 change->rtm_dst_len)) {
577 rn = xzalloc(sizeof *rn);
578 rn->rta_oif = change->rta_oif;
579 rn->rta_dst = change->rta_dst;
580 rn->rtm_dst_len = change->rtm_dst_len;
582 hash = hash_3words(rn->rta_oif, rn->rta_dst, rn->rtm_dst_len);
583 hmap_insert(&route_map, &rn->node, hash);
584 } else if (change->nlmsg_type == RTM_DELROUTE) {
585 struct route_node *rn;
587 rn = route_node_lookup(change->rta_oif, change->rta_dst,
588 change->rtm_dst_len);
591 hmap_remove(&route_map, &rn->node);
595 VLOG_WARN_RL(&rl, "Received unexpected rtnetlink message type %d",
601 netdev_vport_link_change(const struct rtnetlink_link_change *change,
602 void *aux OVS_UNUSED)
606 netdev_vport_reset_names();
607 } else if (change->nlmsg_type == RTM_NEWLINK) {
608 struct name_node *nn;
610 if (name_node_lookup(change->ifi_index)) {
614 nn = xzalloc(sizeof *nn);
615 nn->ifi_index = change->ifi_index;
617 strncpy(nn->ifname, change->ifname, IFNAMSIZ);
618 nn->ifname[IFNAMSIZ - 1] = '\0';
620 hmap_insert(&name_map, &nn->node, hash_int(nn->ifi_index, 0));
621 } else if (change->nlmsg_type == RTM_DELLINK) {
622 struct name_node *nn;
624 nn = name_node_lookup(change->ifi_index);
627 hmap_remove(&name_map, &nn->node);
631 /* Link deletions do not result in all of the RTM_DELROUTE messages one
632 * would expect. For now, go ahead and reset route_map whenever a link
634 netdev_vport_reset_routes();
636 VLOG_WARN_RL(&rl, "Received unexpected rtnetlink message type %d",
642 netdev_vport_tnl_iface_init(void)
644 static bool tnl_iface_is_init = false;
646 if (!tnl_iface_is_init) {
647 hmap_init(&name_map);
648 hmap_init(&route_map);
650 rtnetlink_link_notifier_register(&netdev_vport_link_notifier,
651 netdev_vport_link_change, NULL);
653 rtnetlink_route_notifier_register(&netdev_vport_route_notifier,
654 netdev_vport_route_change, NULL);
656 netdev_vport_reset_names();
657 netdev_vport_reset_routes();
658 tnl_iface_is_init = true;
663 netdev_vport_get_tnl_iface(const struct netdev *netdev)
667 struct netdev_dev_vport *ndv;
668 struct tnl_port_config *config;
669 struct route_node *rn, *rn_def, *rn_iter;
671 ndv = netdev_dev_vport_cast(netdev_get_dev(netdev));
672 config = (struct tnl_port_config *) ndv->config;
673 route = ntohl(config->daddr);
679 HMAP_FOR_EACH(rn_iter, node, &route_map) {
680 if (rn_iter->rtm_dst_len == 0 && rn_iter->rta_dst == 0) {
683 } else if (rn_iter->rtm_dst_len > dst_len) {
684 uint32_t mask = 0xffffffff << (32 - rn_iter->rtm_dst_len);
685 if ((route & mask) == (rn_iter->rta_dst & mask)) {
687 dst_len = rn_iter->rtm_dst_len;
698 struct name_node *nn;
700 hash = hash_int(rn->rta_oif, 0);
701 HMAP_FOR_EACH_WITH_HASH(nn, node, hash, &name_map) {
702 if (nn->ifi_index == rn->rta_oif) {
711 /* Helper functions. */
714 netdev_vport_do_ioctl(int cmd, void *arg)
716 static int ioctl_fd = -1;
719 ioctl_fd = open("/dev/net/dp0", O_RDONLY | O_NONBLOCK);
721 VLOG_ERR_RL(&rl, "failed to open ioctl fd: %s", strerror(errno));
726 return ioctl(ioctl_fd, cmd, arg) ? errno : 0;
730 netdev_vport_poll_notify(const struct netdev *netdev)
732 char *poll_name = make_poll_name(netdev);
733 struct list *list = shash_find_data(&netdev_vport_notifiers,
737 struct netdev_vport_notifier *notifier;
739 LIST_FOR_EACH (notifier, list_node, list) {
740 struct netdev_notifier *n = ¬ifier->notifier;
748 /* Code specific to individual vport types. */
751 parse_tunnel_config(const struct netdev_dev *dev, const struct shash *args,
754 const char *name = netdev_dev_get_name(dev);
755 const char *type = netdev_dev_get_type(dev);
757 bool is_ipsec = false;
758 struct tnl_port_config config;
759 struct shash_node *node;
760 bool ipsec_mech_set = false;
762 memset(&config, 0, sizeof config);
763 config.flags |= TNL_F_PMTUD;
764 config.flags |= TNL_F_HDR_CACHE;
766 if (!strcmp(type, "gre")) {
768 } else if (!strcmp(type, "ipsec_gre")) {
772 config.flags |= TNL_F_IPSEC;
774 /* IPsec doesn't work when header caching is enabled. */
775 config.flags &= ~TNL_F_HDR_CACHE;
778 SHASH_FOR_EACH (node, args) {
779 if (!strcmp(node->name, "remote_ip")) {
780 struct in_addr in_addr;
781 if (lookup_ip(node->data, &in_addr)) {
782 VLOG_WARN("%s: bad %s 'remote_ip'", name, type);
784 config.daddr = in_addr.s_addr;
786 } else if (!strcmp(node->name, "local_ip")) {
787 struct in_addr in_addr;
788 if (lookup_ip(node->data, &in_addr)) {
789 VLOG_WARN("%s: bad %s 'local_ip'", name, type);
791 config.saddr = in_addr.s_addr;
793 } else if (!strcmp(node->name, "key") && is_gre) {
794 if (!strcmp(node->data, "flow")) {
795 config.flags |= TNL_F_IN_KEY_MATCH;
796 config.flags |= TNL_F_OUT_KEY_ACTION;
798 uint64_t key = strtoull(node->data, NULL, 0);
799 config.out_key = config.in_key = htonll(key);
801 } else if (!strcmp(node->name, "in_key") && is_gre) {
802 if (!strcmp(node->data, "flow")) {
803 config.flags |= TNL_F_IN_KEY_MATCH;
805 config.in_key = htonll(strtoull(node->data, NULL, 0));
807 } else if (!strcmp(node->name, "out_key") && is_gre) {
808 if (!strcmp(node->data, "flow")) {
809 config.flags |= TNL_F_OUT_KEY_ACTION;
811 config.out_key = htonll(strtoull(node->data, NULL, 0));
813 } else if (!strcmp(node->name, "tos")) {
814 if (!strcmp(node->data, "inherit")) {
815 config.flags |= TNL_F_TOS_INHERIT;
817 config.tos = atoi(node->data);
819 } else if (!strcmp(node->name, "ttl")) {
820 if (!strcmp(node->data, "inherit")) {
821 config.flags |= TNL_F_TTL_INHERIT;
823 config.ttl = atoi(node->data);
825 } else if (!strcmp(node->name, "csum") && is_gre) {
826 if (!strcmp(node->data, "true")) {
827 config.flags |= TNL_F_CSUM;
829 } else if (!strcmp(node->name, "pmtud")) {
830 if (!strcmp(node->data, "false")) {
831 config.flags &= ~TNL_F_PMTUD;
833 } else if (!strcmp(node->name, "header_cache")) {
834 if (!strcmp(node->data, "false")) {
835 config.flags &= ~TNL_F_HDR_CACHE;
837 } else if (!strcmp(node->name, "peer_cert") && is_ipsec) {
838 if (shash_find(args, "certificate")) {
839 ipsec_mech_set = true;
841 const char *use_ssl_cert;
843 /* If the "use_ssl_cert" is true, then "certificate" and
844 * "private_key" will be pulled from the SSL table. The
845 * use of this option is strongly discouraged, since it
846 * will like be removed when multiple SSL configurations
847 * are supported by OVS.
849 use_ssl_cert = shash_find_data(args, "use_ssl_cert");
850 if (!use_ssl_cert || strcmp(use_ssl_cert, "true")) {
851 VLOG_WARN("%s: 'peer_cert' requires 'certificate' argument",
855 ipsec_mech_set = true;
857 } else if (!strcmp(node->name, "psk") && is_ipsec) {
858 ipsec_mech_set = true;
860 && (!strcmp(node->name, "certificate")
861 || !strcmp(node->name, "private_key")
862 || !strcmp(node->name, "use_ssl_cert"))) {
863 /* Ignore options not used by the netdev. */
865 VLOG_WARN("%s: unknown %s argument '%s'",
866 name, type, node->name);
871 if (shash_find(args, "peer_cert") && shash_find(args, "psk")) {
872 VLOG_WARN("%s: cannot define both 'peer_cert' and 'psk'", name);
876 if (!ipsec_mech_set) {
877 VLOG_WARN("%s: IPsec requires an 'peer_cert' or psk' argument",
884 VLOG_WARN("%s: %s type requires valid 'remote_ip' argument",
889 BUILD_ASSERT(sizeof config <= VPORT_CONFIG_SIZE);
890 memcpy(configp, &config, sizeof config);
895 parse_patch_config(const struct netdev_dev *dev, const struct shash *args,
898 const char *name = netdev_dev_get_name(dev);
901 peer = shash_find_data(args, "peer");
903 VLOG_WARN("%s: patch type requires valid 'peer' argument", name);
907 if (shash_count(args) > 1) {
908 VLOG_WARN("%s: patch type takes only a 'peer' argument", name);
912 if (strlen(peer) >= MIN(IFNAMSIZ, VPORT_CONFIG_SIZE)) {
913 VLOG_WARN("%s: patch 'peer' arg too long", name);
917 if (!strcmp(name, peer)) {
918 VLOG_WARN("%s: patch peer must not be self", name);
922 strncpy(configp, peer, VPORT_CONFIG_SIZE);
927 #define VPORT_FUNCTIONS(TNL_IFACE) \
932 netdev_vport_create, \
933 netdev_vport_destroy, \
934 netdev_vport_reconfigure, \
937 netdev_vport_close, \
939 NULL, /* enumerate */ \
942 NULL, /* recv_wait */ \
946 NULL, /* send_wait */ \
948 netdev_vport_set_etheraddr, \
949 netdev_vport_get_etheraddr, \
950 netdev_vport_get_mtu, \
951 NULL, /* get_ifindex */ \
952 NULL, /* get_carrier */ \
953 netdev_vport_get_stats, \
954 netdev_vport_set_stats, \
956 NULL, /* get_features */ \
957 NULL, /* set_advertisements */ \
958 NULL, /* get_vlan_vid */ \
960 NULL, /* set_policing */ \
961 NULL, /* get_qos_types */ \
962 NULL, /* get_qos_capabilities */ \
963 NULL, /* get_qos */ \
964 NULL, /* set_qos */ \
965 NULL, /* get_queue */ \
966 NULL, /* set_queue */ \
967 NULL, /* delete_queue */ \
968 NULL, /* get_queue_stats */ \
969 NULL, /* dump_queues */ \
970 NULL, /* dump_queue_stats */ \
972 NULL, /* get_in4 */ \
973 NULL, /* set_in4 */ \
974 NULL, /* get_in6 */ \
975 NULL, /* add_router */ \
976 NULL, /* get_next_hop */ \
978 NULL, /* arp_lookup */ \
980 netdev_vport_update_flags, \
982 netdev_vport_poll_add, \
983 netdev_vport_poll_remove,
986 netdev_vport_register(void)
988 static const struct vport_class vport_classes[] = {
989 { { "gre", VPORT_FUNCTIONS(netdev_vport_get_tnl_iface) },
990 parse_tunnel_config },
991 { { "ipsec_gre", VPORT_FUNCTIONS(netdev_vport_get_tnl_iface) },
992 parse_tunnel_config },
993 { { "capwap", VPORT_FUNCTIONS(netdev_vport_get_tnl_iface) },
994 parse_tunnel_config },
995 { { "patch", VPORT_FUNCTIONS(NULL) }, parse_patch_config }
1000 for (i = 0; i < ARRAY_SIZE(vport_classes); i++) {
1001 netdev_register_provider(&vport_classes[i].netdev_class);