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