dummy_device.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. device.c -- Dummy device
  3. Copyright (C) 2011 Guus Sliepen <guus@tinc-vpn.org>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "system.h"
  17. #include "device.h"
  18. #include "logger.h"
  19. #include "net.h"
  20. #include "xalloc.h"
  21. static const char *device_info = "dummy device";
  22. static uint64_t device_total_in = 0;
  23. static uint64_t device_total_out = 0;
  24. static bool setup_device(void) {
  25. device = xstrdup("dummy");
  26. iface = xstrdup("dummy");
  27. logger(LOG_INFO, "%s (%s) is a %s", device, iface, device_info);
  28. return true;
  29. }
  30. static void close_device(void) {
  31. free(device);
  32. free(iface);
  33. }
  34. static bool read_packet(vpn_packet_t *packet) {
  35. (void)packet;
  36. return false;
  37. }
  38. static bool write_packet(vpn_packet_t *packet) {
  39. device_total_out += packet->len;
  40. return true;
  41. }
  42. static void dump_device_stats(void) {
  43. logger(LOG_DEBUG, "Statistics for %s %s:", device_info, device);
  44. logger(LOG_DEBUG, " total bytes in: %10"PRIu64, device_total_in);
  45. logger(LOG_DEBUG, " total bytes out: %10"PRIu64, device_total_out);
  46. }
  47. const devops_t dummy_devops = {
  48. .setup = setup_device,
  49. .close = close_device,
  50. .read = read_packet,
  51. .write = write_packet,
  52. .dump_stats = dump_device_stats,
  53. };