4e544ef30279fcbc805561743164023cb3d32e7d
[sliver-openvswitch.git] / lib / netdev-pltap.c
1 /*
2  * Copyright (c) 2012 Giuseppe Lettieri
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <config.h>
18
19 #include <sys/types.h>
20 #include <unistd.h>
21 #include <fcntl.h>
22 #include <arpa/inet.h>
23 #include <sys/ioctl.h>
24 #include <sys/socket.h>
25 #include <net/if.h>
26 #include <net/if_arp.h>
27 #include <linux/if_tun.h>
28 #include <netinet/in.h>
29 #include <errno.h>
30
31 #include "flow.h"
32 #include "list.h"
33 #include "netdev-provider.h"
34 #include "odp-util.h"
35 #include "ofp-print.h"
36 #include "ofpbuf.h"
37 #include "packets.h"
38 #include "poll-loop.h"
39 #include "shash.h"
40 #include "sset.h"
41 #include "unixctl.h"
42 #include "socket-util.h"
43 #include "vlog.h"
44 #include "tunalloc.h"
45
46 VLOG_DEFINE_THIS_MODULE(netdev_pltap);
47
48 struct netdev_dev_pltap {
49     struct netdev_dev netdev_dev;
50     char *real_name;
51     struct netdev_stats stats;
52     enum netdev_flags new_flags;
53     enum netdev_flags flags;
54     int fd;
55     struct sockaddr_in local_addr;
56     int local_netmask;
57     bool valid_local_ip;
58     bool valid_local_netmask;
59     bool sync_flags_needed;
60     struct list sync_list;
61     unsigned int change_seq;
62 };
63
64 static struct list sync_list;
65
66 struct netdev_pltap {
67     struct netdev netdev;
68 };
69
70 static int af_inet_sock = -1;
71
72 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
73
74 static struct shash pltap_netdev_devs = SHASH_INITIALIZER(&pltap_netdev_devs);
75
76 static int netdev_pltap_create(const struct netdev_class *, const char *,
77                                struct netdev_dev **);
78
79 static void netdev_pltap_update_seq(struct netdev_dev_pltap *);
80 static int get_flags(struct netdev_dev_pltap *dev, enum netdev_flags *flags);
81
82 static bool
83 netdev_pltap_finalized(struct netdev_dev_pltap *dev)
84 {
85     return dev->valid_local_ip && dev->valid_local_netmask;
86 }
87
88 static bool
89 is_pltap_class(const struct netdev_class *class)
90 {
91     return class->create == netdev_pltap_create;
92 }
93
94 static struct netdev_dev_pltap *
95 netdev_dev_pltap_cast(const struct netdev_dev *netdev_dev)
96 {
97     ovs_assert(is_pltap_class(netdev_dev_get_class(netdev_dev)));
98     return CONTAINER_OF(netdev_dev, struct netdev_dev_pltap, netdev_dev);
99 }
100
101 static struct netdev_pltap *
102 netdev_pltap_cast(const struct netdev *netdev)
103 {
104     struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
105     ovs_assert(is_pltap_class(netdev_dev_get_class(netdev_dev)));
106     return CONTAINER_OF(netdev, struct netdev_pltap, netdev);
107 }
108
109 static void sync_needed(struct netdev_dev_pltap *dev)
110 {
111     if (dev->sync_flags_needed)
112         return;
113
114     dev->sync_flags_needed = true;
115     list_insert(&sync_list, &dev->sync_list);
116         
117 }
118
119 static void sync_done(struct netdev_dev_pltap *dev)
120 {
121     if (!dev->sync_flags_needed)
122         return;
123
124     (void) list_remove(&dev->sync_list);
125     dev->sync_flags_needed = false;
126 }
127
128 static int
129 netdev_pltap_create(const struct netdev_class *class OVS_UNUSED, const char *name,
130                     struct netdev_dev **netdev_devp)
131 {
132     struct netdev_dev_pltap *netdev_dev;
133     int error;
134
135     netdev_dev = xzalloc(sizeof *netdev_dev);
136
137     netdev_dev->real_name = xzalloc(IFNAMSIZ + 1);
138     memset(&netdev_dev->local_addr, 0, sizeof(netdev_dev->local_addr));
139     netdev_dev->valid_local_ip = false;
140     netdev_dev->valid_local_netmask = false;
141     netdev_dev->flags = 0;
142     netdev_dev->sync_flags_needed = false;
143     list_init(&netdev_dev->sync_list);
144
145
146     /* Open tap device. */
147     netdev_dev->fd = tun_alloc(IFF_TAP, netdev_dev->real_name);
148     if (netdev_dev->fd < 0) {
149         error = errno;
150         VLOG_WARN("tun_alloc(IFF_TAP, %s) failed: %s", name, strerror(error));
151         goto cleanup;
152     }
153     VLOG_DBG("real_name = %s", netdev_dev->real_name);
154
155     /* Make non-blocking. */
156     error = set_nonblocking(netdev_dev->fd);
157     if (error) {
158         goto cleanup;
159     }
160
161     netdev_dev_init(&netdev_dev->netdev_dev, name, &netdev_pltap_class);
162     shash_add(&pltap_netdev_devs, name, netdev_dev);
163     *netdev_devp = &netdev_dev->netdev_dev;
164     return 0;
165
166 cleanup:
167     free(netdev_dev);
168     return error;
169 }
170
171 static void
172 netdev_pltap_destroy(struct netdev_dev *netdev_dev_)
173 {
174     struct netdev_dev_pltap *netdev_dev = netdev_dev_pltap_cast(netdev_dev_);
175
176     if (netdev_dev->fd != -1)
177         close(netdev_dev->fd);
178
179     sync_done(netdev_dev);
180
181     shash_find_and_delete(&pltap_netdev_devs,
182                           netdev_dev_get_name(netdev_dev_));
183     free(netdev_dev);
184 }
185
186 static int
187 netdev_pltap_open(struct netdev_dev *netdev_dev_, struct netdev **netdevp)
188 {
189     struct netdev_pltap *netdev;
190
191     netdev = xmalloc(sizeof *netdev);
192     netdev_init(&netdev->netdev, netdev_dev_);
193
194     *netdevp = &netdev->netdev;
195     return 0;
196 }
197
198 static void
199 netdev_pltap_close(struct netdev *netdev_)
200 {
201     struct netdev_pltap *netdev = netdev_pltap_cast(netdev_);
202     free(netdev);
203 }
204
205 static int vsys_transaction(const char *script,
206         const char **preply, char *format, ...)
207 {
208     char *msg = NULL, *reply = NULL;
209     const size_t reply_size = 1024;
210     int ifd = -1, ofd = -1, maxfd;
211     size_t bytes_to_write, bytes_to_read,
212            bytes_written = 0, bytes_read = 0;
213     int error = 0;
214     char *ofname = NULL, *ifname = NULL;
215     va_list args;
216
217     va_start(args, format);
218     msg = xvasprintf(format, args);
219     va_end(args);
220     reply = (char*)xmalloc(reply_size);
221     if (!msg || !reply) {
222         VLOG_ERR("Out of memory");
223         error = ENOMEM;
224         goto cleanup;
225     }
226
227     ofname = xasprintf("/vsys/%s.out", script);
228     ifname = xasprintf("/vsys/%s.in", script);
229     if (!ofname || !ifname) {
230         VLOG_ERR("Out of memory");
231         error = ENOMEM;
232         goto cleanup;
233     }
234
235     ofd = open(ofname, O_RDONLY | O_NONBLOCK);
236     if (ofd < 0) {
237         VLOG_ERR("Cannot open %s: %s", ofname, strerror(errno));
238         error = errno;
239         goto cleanup;
240     }
241     ifd = open(ifname, O_WRONLY | O_NONBLOCK);
242     if (ifd < 0) {
243         VLOG_ERR("Cannot open %s: %s", ifname, strerror(errno));
244         error = errno;
245         goto cleanup;
246     }
247     maxfd = (ifd < ofd) ? ofd : ifd;
248
249     bytes_to_write = strlen(msg);
250     bytes_to_read = reply_size;
251     while (bytes_to_write || bytes_to_read) {
252         fd_set readset, writeset, errorset;
253
254         FD_ZERO(&readset);
255         FD_ZERO(&writeset);
256         FD_ZERO(&errorset);
257         if (bytes_to_write) {
258             FD_SET(ifd, &writeset);
259             FD_SET(ifd, &errorset);
260         }
261         FD_SET(ofd, &readset);
262         FD_SET(ofd, &errorset);
263         if (select(maxfd + 1, &readset, &writeset, &errorset, NULL) < 0) {
264             if (errno == EINTR)
265                 continue;
266             VLOG_ERR("selec error: %s", strerror(errno));
267             error = errno;
268             goto cleanup;
269         }
270         if (FD_ISSET(ifd, &errorset) || FD_ISSET(ofd, &errorset)) {
271             VLOG_ERR("error condition on ifd or ofd");
272             goto cleanup;
273         }
274         if (FD_ISSET(ifd, &writeset)) {
275             ssize_t n = write(ifd, msg + bytes_written, bytes_to_write);    
276             if (n < 0) {
277                 if (errno != EAGAIN && errno != EINTR) {
278                     VLOG_ERR("write on %s: %s", ifname, strerror(errno));
279                     error = errno;
280                     goto cleanup;
281                 }
282             } else {
283                 bytes_written += n;
284                 bytes_to_write -= n;
285                 if (bytes_to_write == 0)
286                     close(ifd);
287             }
288         }
289         if (FD_ISSET(ofd, &readset)) {
290             ssize_t n = read(ofd, reply + bytes_read, bytes_to_read);    
291             if (n < 0) {
292                 if (errno != EAGAIN && errno != EINTR) {
293                     VLOG_ERR("read on %s: %s", ofname, strerror(errno));
294                     error = errno;
295                     goto cleanup;
296                 }
297             } else if (n == 0) {
298                 bytes_to_read = 0;
299             } else {
300                 bytes_read += n;
301                 bytes_to_read -= n;
302             }
303         }
304     }
305     if (bytes_read) {
306         reply[bytes_read] = '\0';
307         if (preply) {
308                 *preply = reply;
309                 reply = NULL; /* prevent freeing the reply msg */
310         } else {
311                 VLOG_ERR("%s returned: %s", script, reply);
312         }
313         error = EAGAIN;
314         goto cleanup;
315     }
316
317 cleanup:
318     free(msg);
319     free(reply);
320     free(ofname);
321     free(ifname);
322     close(ifd);
323     close(ofd);
324     return error;
325 }
326
327 static int
328 netdev_pltap_up(struct netdev_dev_pltap *dev)
329 {
330     if (!netdev_pltap_finalized(dev)) {
331         return 0;
332     }
333     
334     return vsys_transaction("vif_up", NULL, "%s\n"IP_FMT"\n%d\n",
335                dev->real_name,
336                IP_ARGS(dev->local_addr.sin_addr.s_addr),
337                dev->local_netmask);
338 }
339
340 static int
341 netdev_pltap_down(struct netdev_dev_pltap *dev)
342 {
343     if (!netdev_pltap_finalized(dev)) {
344         return 0;
345     }
346     
347     return vsys_transaction("vif_down", NULL, "%s\n", dev->real_name);
348 }
349
350 static int
351 netdev_pltap_promisc(struct netdev_dev_pltap *dev, bool promisc)
352 {
353     if (!netdev_pltap_finalized(dev)) {
354         return 0;
355     }
356
357     return vsys_transaction("promisc", NULL, "%s\n%s",
358                dev->real_name,
359                (promisc ? "" : "-\n"));
360 }
361
362 static void
363 netdev_pltap_sync_flags(struct netdev_dev_pltap *dev)
364 {
365
366     if (dev->fd < 0 || !netdev_pltap_finalized(dev))
367         return;
368     
369     VLOG_DBG("sync_flags(%s): current: %s %s  target: %s %s",
370         dev->real_name,
371         (dev->flags & NETDEV_UP ? "UP" : "-"),
372         (dev->flags & NETDEV_PROMISC ? "PROMISC" : "-"),
373         (dev->new_flags & NETDEV_UP ? "UP" : "-"),
374         (dev->new_flags & NETDEV_PROMISC ? "PROMISC" : "-"));
375
376     if ((dev->new_flags & NETDEV_UP) && !(dev->flags & NETDEV_UP)) {
377         (void) netdev_pltap_up(dev);
378     } else if (!(dev->new_flags & NETDEV_UP) && (dev->flags & NETDEV_UP)) {
379         (void) netdev_pltap_down(dev);
380     }
381
382     if ((dev->new_flags & NETDEV_PROMISC) ^ (dev->flags & NETDEV_PROMISC)) {
383         (void) netdev_pltap_promisc(dev, dev->new_flags & NETDEV_PROMISC);
384     }
385
386     netdev_pltap_update_seq(dev);
387     sync_done(dev);
388 }
389
390
391 static int
392 netdev_pltap_get_config(struct netdev_dev *dev_, struct smap *args)
393 {
394     struct netdev_dev_pltap *netdev_dev = netdev_dev_pltap_cast(dev_);
395
396     if (netdev_dev->valid_local_ip)
397         smap_add_format(args, "local_ip", IP_FMT,
398             IP_ARGS(netdev_dev->local_addr.sin_addr.s_addr));
399     if (netdev_dev->valid_local_netmask)
400         smap_add_format(args, "local_netmask", "%"PRIu32,
401             ntohs(netdev_dev->local_netmask));
402     return 0;
403 }
404
405 static int
406 netdev_pltap_set_config(struct netdev_dev *dev_, const struct smap *args)
407 {
408     struct netdev_dev_pltap *netdev_dev = netdev_dev_pltap_cast(dev_);
409     struct shash_node *node;
410
411     VLOG_DBG("pltap_set_config(%s)", netdev_dev_get_name(dev_));
412     SMAP_FOR_EACH(node, args) {
413         VLOG_DBG("arg: %s->%s", node->name, (char*)node->data);
414         if (!strcmp(node->name, "local_ip")) {
415             struct in_addr addr;
416             if (lookup_ip(node->data, &addr)) {
417                 VLOG_WARN("%s: bad 'local_ip'", node->name);
418             } else {
419                 netdev_dev->local_addr.sin_addr = addr;
420                 netdev_dev->valid_local_ip = true;
421             }
422         } else if (!strcmp(node->name, "local_netmask")) {
423             netdev_dev->local_netmask = atoi(node->data);
424             // XXX check valididy
425             netdev_dev->valid_local_netmask = true;
426         } else {
427             VLOG_WARN("%s: unknown argument '%s'", 
428                 netdev_dev_get_name(dev_), node->name);
429         }
430     }
431     if (netdev_pltap_finalized(netdev_dev)) {
432         netdev_dev->new_flags |= NETDEV_UP;
433         sync_needed(netdev_dev);
434     }
435     return 0;
436 }
437
438 static int
439 netdev_pltap_listen(struct netdev *netdev_ OVS_UNUSED)
440 {
441     struct netdev_dev_pltap *dev = 
442         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
443     if (!netdev_pltap_finalized(dev))
444         return 0;
445     return netdev_pltap_up(dev);
446 }
447
448 static int
449 netdev_pltap_recv(struct netdev *netdev_, void *buffer, size_t size)
450 {
451     struct netdev_dev_pltap *dev = 
452         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
453     char prefix[4];
454     struct iovec iov[2] = {
455         { .iov_base = prefix, .iov_len = 4 },
456         { .iov_base = buffer, .iov_len = size }
457     };
458     for (;;) {
459         ssize_t retval;
460         retval = readv(dev->fd, iov, 2);
461         if (retval >= 0) {
462             if (retval <= size) {
463                 return retval;
464             } else {
465                 return -EMSGSIZE;
466             }
467         } else if (errno != EINTR) {
468             if (errno != EAGAIN) {
469                 VLOG_WARN_RL(&rl, "error receiveing Ethernet packet on %s: %s",
470                     netdev_get_name(netdev_), strerror(errno));
471             }
472             return -errno;
473         }
474     }
475 }
476
477 static void
478 netdev_pltap_recv_wait(struct netdev *netdev_)
479 {
480     struct netdev_dev_pltap *dev = 
481         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
482     if (dev->fd >= 0 && netdev_pltap_finalized(dev)) {
483         poll_fd_wait(dev->fd, POLLIN);
484     }
485 }
486
487 static int
488 netdev_pltap_send(struct netdev *netdev_, const void *buffer, size_t size)
489 {
490     struct netdev_dev_pltap *dev = 
491         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
492     char prefix[4] = { 0, 0, 8, 6 };
493     struct iovec iov[2] = {
494         { .iov_base = prefix, .iov_len = 4 },
495         { .iov_base = (char*) buffer, .iov_len = size }
496     };
497     if (dev->fd < 0)
498         return EAGAIN;
499     for (;;) {
500         ssize_t retval;
501         retval = writev(dev->fd, iov, 2);
502         if (retval >= 0) {
503             if (retval != size + 4) {
504                 VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%zd bytes of %zu) on %s",
505                              retval, size + 4, netdev_get_name(netdev_));
506             }
507             return 0;
508         } else if (errno != EINTR) {
509             if (errno != EAGAIN) {
510                 VLOG_WARN_RL(&rl, "error sending Ethernet packet on %s: %s",
511                     netdev_get_name(netdev_), strerror(errno));
512             }
513             return errno;
514         }
515     }
516 }
517
518 static void
519 netdev_pltap_send_wait(struct netdev *netdev_)
520 {
521     struct netdev_dev_pltap *dev = 
522         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
523     if (dev->fd >= 0 && netdev_pltap_finalized(dev)) {
524         poll_fd_wait(dev->fd, POLLOUT);
525     }
526 }
527
528 static int
529 netdev_pltap_drain(struct netdev *netdev_)
530 {
531     struct netdev_dev_pltap *dev = 
532         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
533     char buffer[128];
534     int error;
535
536     if (dev->fd < 0)
537         return EAGAIN;
538     for (;;) {
539         error = recv(dev->fd, buffer, 128, MSG_TRUNC);
540         if (error) {
541             if (error == -EAGAIN)
542                 break;
543             else if (error != -EMSGSIZE)
544                 return error;
545         }
546     }
547     return 0;
548 }
549
550 static int
551 netdev_pltap_set_etheraddr(struct netdev *netdevi OVS_UNUSED,
552                            const uint8_t mac[ETH_ADDR_LEN] OVS_UNUSED)
553 {
554     return ENOTSUP;
555 }
556
557
558 // XXX from netdev-linux.c
559 static int
560 get_etheraddr(struct netdev_dev_pltap *dev, uint8_t ea[ETH_ADDR_LEN])
561 {
562     struct ifreq ifr;
563     int hwaddr_family;
564
565     memset(&ifr, 0, sizeof ifr);
566     ovs_strzcpy(ifr.ifr_name, dev->real_name, sizeof ifr.ifr_name);
567     if (ioctl(af_inet_sock, SIOCGIFHWADDR, &ifr) < 0) {
568         /* ENODEV probably means that a vif disappeared asynchronously and
569          * hasn't been removed from the database yet, so reduce the log level
570          * to INFO for that case. */
571         VLOG(errno == ENODEV ? VLL_INFO : VLL_ERR,
572              "ioctl(SIOCGIFHWADDR) on %s device failed: %s",
573              dev->real_name, strerror(errno));
574         return errno;
575     }
576     hwaddr_family = ifr.ifr_hwaddr.sa_family;
577     if (hwaddr_family != AF_UNSPEC && hwaddr_family != ARPHRD_ETHER) {
578         VLOG_WARN("%s device has unknown hardware address family %d",
579                   dev->real_name, hwaddr_family);
580     }
581     memcpy(ea, ifr.ifr_hwaddr.sa_data, ETH_ADDR_LEN);
582     return 0;
583 }
584
585 static int
586 get_flags(struct netdev_dev_pltap *dev, enum netdev_flags *flags)
587 {
588     struct ifreq ifr;
589
590     memset(&ifr, 0, sizeof ifr);
591     ovs_strzcpy(ifr.ifr_name, dev->real_name, sizeof ifr.ifr_name);
592     if (ioctl(af_inet_sock, SIOCGIFFLAGS, &ifr) < 0)
593         return errno;
594     *flags = 0;
595     if (ifr.ifr_flags & IFF_UP)
596         *flags |= NETDEV_UP;
597     if (ifr.ifr_flags & IFF_PROMISC)
598         *flags |= NETDEV_PROMISC;
599     return 0;
600 }
601
602 static int
603 netdev_pltap_get_etheraddr(const struct netdev *netdev,
604                            uint8_t mac[ETH_ADDR_LEN])
605 {
606     struct netdev_dev_pltap *dev = 
607         netdev_dev_pltap_cast(netdev_get_dev(netdev));
608     if (dev->fd < 0)
609         return EAGAIN;
610     return get_etheraddr(dev, mac);
611 }
612
613
614 // XXX can we read stats in planetlab?
615 static int
616 netdev_pltap_get_stats(const struct netdev *netdev OVS_UNUSED, struct netdev_stats *stats OVS_UNUSED)
617 {
618     return ENOTSUP;
619 }
620
621 static int
622 netdev_pltap_set_stats(struct netdev *netdev OVS_UNUSED, const struct netdev_stats *stats OVS_UNUSED)
623 {
624     return ENOTSUP;
625 }
626
627
628 static int
629 netdev_pltap_update_flags(struct netdev *netdev,
630                           enum netdev_flags off, enum netdev_flags on,
631                           enum netdev_flags *old_flagsp)
632 {
633     struct netdev_dev_pltap *dev =
634         netdev_dev_pltap_cast(netdev_get_dev(netdev));
635     int error = 0;
636
637     if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) {
638         return EINVAL;
639     }
640
641     if (netdev_pltap_finalized(dev)) {
642         error = get_flags(dev, &dev->flags);
643     }
644     *old_flagsp = dev->flags;
645     dev->new_flags |= on;
646     dev->new_flags &= ~off;
647     if (dev->flags != dev->new_flags) {
648         /* we cannot sync here, since we may be in a signal handler */
649         sync_needed(dev);
650     }
651
652     return error;
653 }
654
655 static unsigned int
656 netdev_pltap_change_seq(const struct netdev *netdev)
657 {
658     return netdev_dev_pltap_cast(netdev_get_dev(netdev))->change_seq;
659 }
660 \f
661 /* Helper functions. */
662
663 static void
664 netdev_pltap_update_seq(struct netdev_dev_pltap *dev)
665 {
666     dev->change_seq++;
667     if (!dev->change_seq) {
668         dev->change_seq++;
669     }
670 }
671
672 static void
673 netdev_pltap_get_real_name(struct unixctl_conn *conn,
674                      int argc OVS_UNUSED, const char *argv[], void *aux OVS_UNUSED)
675 {
676     struct netdev_dev_pltap *pltap_dev;
677
678     pltap_dev = shash_find_data(&pltap_netdev_devs, argv[1]);
679     if (!pltap_dev) {
680         unixctl_command_reply_error(conn, "no such pltap netdev");
681         return;
682     }
683     if (pltap_dev->fd < 0) {
684         unixctl_command_reply_error(conn, "no real device attached");
685         return;
686     }
687
688     unixctl_command_reply(conn, pltap_dev->real_name);
689 }
690
691 static int
692 netdev_pltap_init(void)
693 {
694     list_init(&sync_list);
695     af_inet_sock = socket(AF_INET, SOCK_DGRAM, 0);
696     if (af_inet_sock < 0) {
697         VLOG_ERR("failed to create inet socket: %s", strerror(errno));
698     }
699     unixctl_command_register("netdev-pltap/get-tapname", "port",
700                              1, 1, netdev_pltap_get_real_name, NULL);
701     return 0;
702 }
703
704 static void
705 netdev_pltap_run(void)
706 {
707     struct netdev_dev_pltap *iter, *next;
708     LIST_FOR_EACH_SAFE(iter, next, sync_list, &sync_list) {
709         netdev_pltap_sync_flags(iter);
710     }
711 }
712
713 static void
714 netdev_pltap_wait(void)
715 {
716     if (!list_is_empty(&sync_list)) {
717         VLOG_DBG("netdev_pltap: scheduling sync");
718         poll_immediate_wake();
719     }
720 }
721
722 const struct netdev_class netdev_pltap_class = {
723     "pltap",
724     netdev_pltap_init,
725     netdev_pltap_run,  
726     netdev_pltap_wait,            
727
728     netdev_pltap_create,
729     netdev_pltap_destroy,
730     netdev_pltap_get_config,
731     netdev_pltap_set_config, 
732     NULL,                       /* get_tunnel_config */
733
734     netdev_pltap_open,
735     netdev_pltap_close,
736
737     netdev_pltap_listen,
738     netdev_pltap_recv,
739     netdev_pltap_recv_wait,
740     netdev_pltap_drain,
741
742     netdev_pltap_send, 
743     netdev_pltap_send_wait,  
744
745     netdev_pltap_set_etheraddr,
746     netdev_pltap_get_etheraddr,
747     NULL,                       /* get_mtu */
748     NULL,                       /* set_mtu */
749     NULL,                       /* get_ifindex */
750     NULL,                       /* get_carrier */
751     NULL,                       /* get_carrier_resets */
752     NULL,                       /* get_miimon */
753     netdev_pltap_get_stats,
754     netdev_pltap_set_stats,
755
756     NULL,                       /* get_features */
757     NULL,                       /* set_advertisements */
758
759     NULL,                       /* set_policing */
760     NULL,                       /* get_qos_types */
761     NULL,                       /* get_qos_capabilities */
762     NULL,                       /* get_qos */
763     NULL,                       /* set_qos */
764     NULL,                       /* get_queue */
765     NULL,                       /* set_queue */
766     NULL,                       /* delete_queue */
767     NULL,                       /* get_queue_stats */
768     NULL,                       /* dump_queues */
769     NULL,                       /* dump_queue_stats */
770
771     NULL,                       /* get_in4 */
772     NULL,                       /* set_in4 */
773     NULL,                       /* get_in6 */
774     NULL,                       /* add_router */
775     NULL,                       /* get_next_hop */
776     NULL,                       /* get_drv_info */
777     NULL,                       /* arp_lookup */
778
779     netdev_pltap_update_flags,
780
781     netdev_pltap_change_seq
782 };