proper handling of the UP flag
[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     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     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 *msg, char *reply, size_t reply_size)
207 {
208     int ifd = -1, ofd = -1, maxfd;
209     size_t bytes_to_write, bytes_to_read,
210            bytes_written = 0, bytes_read = 0;
211     int error = 0;
212     char *ofname = NULL, *ifname = NULL;
213
214     ofname = xasprintf("/vsys/%s.out", script);
215     ifname = xasprintf("/vsys/%s.in", script);
216     if (!ofname || !ifname) {
217         VLOG_ERR("Out of memory");
218         error = ENOMEM;
219         goto cleanup;
220     }
221
222     ofd = open(ofname, O_RDONLY | O_NONBLOCK);
223     if (ofd < 0) {
224         VLOG_ERR("Cannot open %s: %s", ofname, strerror(errno));
225         error = errno;
226         goto cleanup;
227     }
228     ifd = open(ifname, O_WRONLY | O_NONBLOCK);
229     if (ifd < 0) {
230         VLOG_ERR("Cannot open %s: %s", ifname, strerror(errno));
231         error = errno;
232         goto cleanup;
233     }
234     maxfd = (ifd < ofd) ? ofd : ifd;
235
236     bytes_to_write = strlen(msg);
237     bytes_to_read = reply_size;
238     while (bytes_to_write || bytes_to_read) {
239         fd_set readset, writeset, errorset;
240
241         FD_ZERO(&readset);
242         FD_ZERO(&writeset);
243         FD_ZERO(&errorset);
244         if (bytes_to_write) {
245             FD_SET(ifd, &writeset);
246             FD_SET(ifd, &errorset);
247         }
248         FD_SET(ofd, &readset);
249         FD_SET(ofd, &errorset);
250         if (select(maxfd + 1, &readset, &writeset, &errorset, NULL) < 0) {
251             if (errno == EINTR)
252                 continue;
253             VLOG_ERR("selec error: %s", strerror(errno));
254             error = errno;
255             goto cleanup;
256         }
257         if (FD_ISSET(ifd, &errorset) || FD_ISSET(ofd, &errorset)) {
258             VLOG_ERR("error condition on ifd or ofd");
259             goto cleanup;
260         }
261         if (FD_ISSET(ifd, &writeset)) {
262             ssize_t n = write(ifd, msg + bytes_written, bytes_to_write);    
263             if (n < 0) {
264                 if (errno != EAGAIN && errno != EINTR) {
265                     VLOG_ERR("write on %s: %s", ifname, strerror(errno));
266                     error = errno;
267                     goto cleanup;
268                 }
269             } else {
270                 bytes_written += n;
271                 bytes_to_write -= n;
272                 if (bytes_to_write == 0)
273                     close(ifd);
274             }
275         }
276         if (FD_ISSET(ofd, &readset)) {
277             ssize_t n = read(ofd, reply + bytes_read, bytes_to_read);    
278             if (n < 0) {
279                 if (errno != EAGAIN && errno != EINTR) {
280                     VLOG_ERR("read on %s: %s", ofname, strerror(errno));
281                     error = errno;
282                     goto cleanup;
283                 }
284             } else if (n == 0) {
285                 bytes_to_read = 0;
286             } else {
287                 bytes_read += n;
288                 bytes_to_read -= n;
289             }
290         }
291     }
292     if (bytes_read) {
293         reply[bytes_read] = '\0';
294         VLOG_ERR("%s returned: %s", script, reply);
295         error = EAGAIN;
296         goto cleanup;
297     }
298
299 cleanup:
300     free(ofname);
301     free(ifname);
302     close(ifd);
303     close(ofd);
304     return error;
305 }
306
307 static int
308 netdev_pltap_up(struct netdev_dev_pltap *dev)
309 {
310     int error;
311     char *msg = NULL, *reply = NULL;
312     const size_t reply_size = 1024;
313
314     if (!netdev_pltap_finalized(dev)) {
315         return 0;
316     }
317     
318     msg = xasprintf("%s\n"IP_FMT"\n%d\n",
319        dev->real_name,
320        IP_ARGS(&dev->local_addr.sin_addr),
321        dev->local_netmask);
322     reply = (char*)xmalloc(reply_size);
323     if (!msg || !reply) {
324         VLOG_ERR("Out of memory\n");
325         error = ENOMEM;
326         goto cleanup;
327     }
328     error = vsys_transaction("vif_up", msg, reply, reply_size);
329     if (error) {
330         goto cleanup;
331     }
332     netdev_pltap_update_seq(dev);
333
334 cleanup:
335     free(msg);
336     free(reply);
337
338     return error;
339 }
340
341 static void
342 netdev_pltap_sync_flags(struct netdev_dev_pltap *dev)
343 {
344     int error = 0;
345     char *msg = NULL, *reply = NULL;
346     const size_t reply_size = 1024;
347
348     if (dev->fd < 0 || !netdev_pltap_finalized(dev))
349         return;
350     
351     VLOG_DBG("sync_flags(%s): current: %s %s  target: %s %s",
352         dev->real_name,
353         (dev->flags & NETDEV_UP ? "UP" : "-"),
354         (dev->flags & NETDEV_PROMISC ? "PROMISC" : "-"),
355         (dev->new_flags & NETDEV_UP ? "UP" : "-"),
356         (dev->new_flags & NETDEV_PROMISC ? "PROMISC" : "-"));
357
358     if ((dev->new_flags & NETDEV_UP) && !(dev->flags & NETDEV_UP)) {
359         (void) netdev_pltap_up(dev);
360     } /* TODO: implement the down case */
361
362     if ((dev->new_flags & NETDEV_PROMISC) ^ (dev->flags & NETDEV_PROMISC)) {
363         msg = xasprintf("%s\n%s",
364            dev->real_name,
365            (dev->new_flags & NETDEV_PROMISC ? "" : "-\n"));
366         reply = (char*)xmalloc(reply_size);
367         if (!msg || !reply) {
368             VLOG_ERR("Out of memory\n");
369             goto cleanup;
370         }
371         error = vsys_transaction("promisc", msg, reply, reply_size);
372         if (error) {
373             goto cleanup;
374         }
375         netdev_pltap_update_seq(dev);
376     }
377
378 cleanup:
379
380     sync_done(dev);
381     free(msg);
382     free(reply);
383
384     return error;
385 }
386
387
388 static int
389 netdev_pltap_get_config(struct netdev_dev *dev_, struct smap *args)
390 {
391     struct netdev_dev_pltap *netdev_dev = netdev_dev_pltap_cast(dev_);
392
393     if (netdev_dev->valid_local_ip)
394         smap_add_format(args, "local_ip", IP_FMT,
395             IP_ARGS(&netdev_dev->local_addr.sin_addr));
396     if (netdev_dev->valid_local_netmask)
397         smap_add_format(args, "local_netmask", "%"PRIu32,
398             ntohs(netdev_dev->local_netmask));
399     return 0;
400 }
401
402 static int
403 netdev_pltap_set_config(struct netdev_dev *dev_, const struct smap *args)
404 {
405     struct netdev_dev_pltap *netdev_dev = netdev_dev_pltap_cast(dev_);
406     struct shash_node *node;
407
408     VLOG_DBG("pltap_set_config(%s)", netdev_dev_get_name(dev_));
409     SMAP_FOR_EACH(node, args) {
410         VLOG_DBG("arg: %s->%s", node->name, (char*)node->data);
411         if (!strcmp(node->name, "local_ip")) {
412             struct in_addr addr;
413             if (lookup_ip(node->data, &addr)) {
414                 VLOG_WARN("%s: bad 'local_ip'", node->name);
415             } else {
416                 netdev_dev->local_addr.sin_addr = addr;
417                 netdev_dev->valid_local_ip = true;
418             }
419         } else if (!strcmp(node->name, "local_netmask")) {
420             netdev_dev->local_netmask = atoi(node->data);
421             // XXX check valididy
422             netdev_dev->valid_local_netmask = true;
423         } else {
424             VLOG_WARN("%s: unknown argument '%s'", 
425                 netdev_dev_get_name(dev_), node->name);
426         }
427     }
428     if (netdev_pltap_finalized(netdev_dev)) {
429         netdev_dev->new_flags |= NETDEV_UP;
430         sync_needed(netdev_dev);
431     }
432     return 0;
433 }
434
435 static int
436 netdev_pltap_listen(struct netdev *netdev_ OVS_UNUSED)
437 {
438     struct netdev_dev_pltap *dev = 
439         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
440     if (!netdev_pltap_finalized(dev))
441         return 0;
442     return netdev_pltap_up(dev);
443 }
444
445 static int
446 netdev_pltap_recv(struct netdev *netdev_, void *buffer, size_t size)
447 {
448     struct netdev_dev_pltap *dev = 
449         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
450     char prefix[4];
451     struct iovec iov[2] = {
452         { .iov_base = prefix, .iov_len = 4 },
453         { .iov_base = buffer, .iov_len = size }
454     };
455     for (;;) {
456         ssize_t retval;
457         retval = readv(dev->fd, iov, 2);
458         if (retval >= 0) {
459             if (retval <= size) {
460                 return retval;
461             } else {
462                 return -EMSGSIZE;
463             }
464         } else if (errno != EINTR) {
465             if (errno != EAGAIN) {
466                 VLOG_WARN_RL(&rl, "error receiveing Ethernet packet on %s: %s",
467                     netdev_get_name(netdev_), strerror(errno));
468             }
469             return -errno;
470         }
471     }
472 }
473
474 static void
475 netdev_pltap_recv_wait(struct netdev *netdev_)
476 {
477     struct netdev_dev_pltap *dev = 
478         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
479     if (dev->fd >= 0 && netdev_pltap_finalized(dev)) {
480         poll_fd_wait(dev->fd, POLLIN);
481     }
482 }
483
484 static int
485 netdev_pltap_send(struct netdev *netdev_, const void *buffer, size_t size)
486 {
487     struct netdev_dev_pltap *dev = 
488         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
489     char prefix[4] = { 0, 0, 8, 6 };
490     struct iovec iov[2] = {
491         { .iov_base = prefix, .iov_len = 4 },
492         { .iov_base = (char*) buffer, .iov_len = size }
493     };
494     if (dev->fd < 0)
495         return EAGAIN;
496     for (;;) {
497         ssize_t retval;
498         retval = writev(dev->fd, iov, 2);
499         if (retval >= 0) {
500             if (retval != size + 4) {
501                 VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%zd bytes of %zu) on %s",
502                              retval, size + 4, netdev_get_name(netdev_));
503             }
504             return 0;
505         } else if (errno != EINTR) {
506             if (errno != EAGAIN) {
507                 VLOG_WARN_RL(&rl, "error sending Ethernet packet on %s: %s",
508                     netdev_get_name(netdev_), strerror(errno));
509             }
510             return errno;
511         }
512     }
513 }
514
515 static void
516 netdev_pltap_send_wait(struct netdev *netdev_)
517 {
518     struct netdev_dev_pltap *dev = 
519         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
520     if (dev->fd >= 0 && netdev_pltap_finalized(dev)) {
521         poll_fd_wait(dev->fd, POLLOUT);
522     }
523 }
524
525 static int
526 netdev_pltap_drain(struct netdev *netdev_)
527 {
528     struct netdev_dev_pltap *dev = 
529         netdev_dev_pltap_cast(netdev_get_dev(netdev_));
530     char buffer[128];
531     int error;
532
533     if (dev->fd < 0)
534         return EAGAIN;
535     for (;;) {
536         error = recv(dev->fd, buffer, 128, MSG_TRUNC);
537         if (error) {
538             if (error == -EAGAIN)
539                 break;
540             else if (error != -EMSGSIZE)
541                 return error;
542         }
543     }
544     return 0;
545 }
546
547 static int
548 netdev_pltap_set_etheraddr(struct netdev *netdevi OVS_UNUSED,
549                            const uint8_t mac[ETH_ADDR_LEN] OVS_UNUSED)
550 {
551     return ENOTSUP;
552 }
553
554
555 // XXX from netdev-linux.c
556 static int
557 get_etheraddr(struct netdev_dev_pltap *dev, uint8_t ea[ETH_ADDR_LEN])
558 {
559     struct ifreq ifr;
560     int hwaddr_family;
561
562     memset(&ifr, 0, sizeof ifr);
563     ovs_strzcpy(ifr.ifr_name, dev->real_name, sizeof ifr.ifr_name);
564     if (ioctl(af_inet_sock, SIOCGIFHWADDR, &ifr) < 0) {
565         /* ENODEV probably means that a vif disappeared asynchronously and
566          * hasn't been removed from the database yet, so reduce the log level
567          * to INFO for that case. */
568         VLOG(errno == ENODEV ? VLL_INFO : VLL_ERR,
569              "ioctl(SIOCGIFHWADDR) on %s device failed: %s",
570              dev->real_name, strerror(errno));
571         return errno;
572     }
573     hwaddr_family = ifr.ifr_hwaddr.sa_family;
574     if (hwaddr_family != AF_UNSPEC && hwaddr_family != ARPHRD_ETHER) {
575         VLOG_WARN("%s device has unknown hardware address family %d",
576                   dev->real_name, hwaddr_family);
577     }
578     memcpy(ea, ifr.ifr_hwaddr.sa_data, ETH_ADDR_LEN);
579     return 0;
580 }
581
582 static int
583 get_flags(struct netdev_dev_pltap *dev, enum netdev_flags *flags)
584 {
585     struct ifreq ifr;
586
587     memset(&ifr, 0, sizeof ifr);
588     ovs_strzcpy(ifr.ifr_name, dev->real_name, sizeof ifr.ifr_name);
589     if (ioctl(af_inet_sock, SIOCGIFFLAGS, &ifr) < 0)
590         return errno;
591     *flags = 0;
592     if (ifr.ifr_flags & IFF_UP)
593         *flags |= NETDEV_UP;
594     if (ifr.ifr_flags & IFF_PROMISC)
595         *flags |= NETDEV_PROMISC;
596     return 0;
597 }
598
599 static int
600 netdev_pltap_get_etheraddr(const struct netdev *netdev,
601                            uint8_t mac[ETH_ADDR_LEN])
602 {
603     struct netdev_dev_pltap *dev = 
604         netdev_dev_pltap_cast(netdev_get_dev(netdev));
605     if (dev->fd < 0)
606         return EAGAIN;
607     return get_etheraddr(dev, mac);
608 }
609
610
611 // XXX can we read stats in planetlab?
612 static int
613 netdev_pltap_get_stats(const struct netdev *netdev OVS_UNUSED, struct netdev_stats *stats OVS_UNUSED)
614 {
615     return ENOTSUP;
616 }
617
618 static int
619 netdev_pltap_set_stats(struct netdev *netdev OVS_UNUSED, const struct netdev_stats *stats OVS_UNUSED)
620 {
621     return ENOTSUP;
622 }
623
624
625 static int
626 netdev_pltap_update_flags(struct netdev *netdev,
627                           enum netdev_flags off, enum netdev_flags on,
628                           enum netdev_flags *old_flagsp)
629 {
630     struct netdev_dev_pltap *dev =
631         netdev_dev_pltap_cast(netdev_get_dev(netdev));
632     int error = 0;
633
634     if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) {
635         return EINVAL;
636     }
637
638     error = get_flags(dev, &dev->flags);
639     *old_flagsp = dev->flags;
640     dev->new_flags |= on;
641     dev->new_flags &= ~off;
642     if (dev->flags != dev->new_flags) {
643         /* we cannot sync here, since we may be in a signal handler */
644         sync_needed(dev);
645     }
646
647     return error;
648 }
649
650 static unsigned int
651 netdev_pltap_change_seq(const struct netdev *netdev)
652 {
653     return netdev_dev_pltap_cast(netdev_get_dev(netdev))->change_seq;
654 }
655 \f
656 /* Helper functions. */
657
658 static void
659 netdev_pltap_update_seq(struct netdev_dev_pltap *dev)
660 {
661     dev->change_seq++;
662     if (!dev->change_seq) {
663         dev->change_seq++;
664     }
665 }
666
667 static void
668 netdev_pltap_get_real_name(struct unixctl_conn *conn,
669                      int argc OVS_UNUSED, const char *argv[], void *aux OVS_UNUSED)
670 {
671     struct netdev_dev_pltap *pltap_dev;
672
673     pltap_dev = shash_find_data(&pltap_netdev_devs, argv[1]);
674     if (!pltap_dev) {
675         unixctl_command_reply_error(conn, "no such pltap netdev");
676         return;
677     }
678     if (pltap_dev->fd < 0) {
679         unixctl_command_reply_error(conn, "no real device attached");
680         return;
681     }
682
683     unixctl_command_reply(conn, pltap_dev->real_name);
684 }
685
686 static int
687 netdev_pltap_init(void)
688 {
689     list_init(&sync_list);
690     af_inet_sock = socket(AF_INET, SOCK_DGRAM, 0);
691     if (af_inet_sock < 0) {
692         VLOG_ERR("failed to create inet socket: %s", strerror(errno));
693     }
694     unixctl_command_register("netdev-pltap/get-tapname", "port",
695                              1, 1, netdev_pltap_get_real_name, NULL);
696     return 0;
697 }
698
699 static void
700 netdev_pltap_run(void)
701 {
702     struct netdev_dev_pltap *iter, *next;
703     LIST_FOR_EACH_SAFE(iter, next, sync_list, &sync_list) {
704         netdev_pltap_sync_flags(iter);
705     }
706 }
707
708 static void
709 netdev_pltap_wait(void)
710 {
711     if (!list_is_empty(&sync_list)) {
712         VLOG_DBG("netdev_pltap: scheduling sync");
713         poll_immediate_wake();
714     }
715 }
716
717 const struct netdev_class netdev_pltap_class = {
718     "pltap",
719     netdev_pltap_init,
720     netdev_pltap_run,  
721     netdev_pltap_wait,            
722
723     netdev_pltap_create,
724     netdev_pltap_destroy,
725     netdev_pltap_get_config,
726     netdev_pltap_set_config, 
727
728     netdev_pltap_open,
729     netdev_pltap_close,
730
731     netdev_pltap_listen,
732     netdev_pltap_recv,
733     netdev_pltap_recv_wait,
734     netdev_pltap_drain,
735
736     netdev_pltap_send, 
737     netdev_pltap_send_wait,  
738
739     netdev_pltap_set_etheraddr,
740     netdev_pltap_get_etheraddr,
741     NULL,                       /* get_mtu */
742     NULL,                       /* set_mtu */
743     NULL,                       /* get_ifindex */
744     NULL,                       /* get_carrier */
745     NULL,                       /* get_carrier_resets */
746     NULL,                       /* get_miimon */
747     netdev_pltap_get_stats,
748     netdev_pltap_set_stats,
749
750     NULL,                       /* get_features */
751     NULL,                       /* set_advertisements */
752
753     NULL,                       /* set_policing */
754     NULL,                       /* get_qos_types */
755     NULL,                       /* get_qos_capabilities */
756     NULL,                       /* get_qos */
757     NULL,                       /* set_qos */
758     NULL,                       /* get_queue */
759     NULL,                       /* set_queue */
760     NULL,                       /* delete_queue */
761     NULL,                       /* get_queue_stats */
762     NULL,                       /* dump_queues */
763     NULL,                       /* dump_queue_stats */
764
765     NULL,                       /* get_in4 */
766     NULL,                       /* set_in4 */
767     NULL,                       /* get_in6 */
768     NULL,                       /* add_router */
769     NULL,                       /* get_next_hop */
770     NULL,                       /* get_drv_info */
771     NULL,                       /* arp_lookup */
772
773     netdev_pltap_update_flags,
774
775     netdev_pltap_change_seq
776 };