rocker.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * QEMU rocker switch emulation
  3. *
  4. * Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
  5. * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
  6. * Copyright (c) 2014 Neil Horman <nhorman@tuxdriver.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #ifndef ROCKER_H
  19. #define ROCKER_H
  20. #include "qemu/sockets.h"
  21. #if defined(DEBUG_ROCKER)
  22. # define DPRINTF(fmt, ...) \
  23. do { \
  24. struct timeval tv; \
  25. char timestr[64]; \
  26. time_t now; \
  27. gettimeofday(&tv, NULL); \
  28. now = tv.tv_sec; \
  29. strftime(timestr, sizeof(timestr), "%T", localtime(&now)); \
  30. fprintf(stderr, "%s.%06ld ", timestr, tv.tv_usec); \
  31. fprintf(stderr, "ROCKER: " fmt, ## __VA_ARGS__); \
  32. } while (0)
  33. #else
  34. static inline GCC_FMT_ATTR(1, 2) int DPRINTF(const char *fmt, ...)
  35. {
  36. return 0;
  37. }
  38. #endif
  39. #define __le16 uint16_t
  40. #define __le32 uint32_t
  41. #define __le64 uint64_t
  42. #define __be16 uint16_t
  43. #define __be32 uint32_t
  44. #define __be64 uint64_t
  45. static inline bool ipv4_addr_is_multicast(__be32 addr)
  46. {
  47. return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
  48. }
  49. typedef struct ipv6_addr {
  50. union {
  51. uint8_t addr8[16];
  52. __be16 addr16[8];
  53. __be32 addr32[4];
  54. };
  55. } Ipv6Addr;
  56. static inline bool ipv6_addr_is_multicast(const Ipv6Addr *addr)
  57. {
  58. return (addr->addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
  59. }
  60. typedef struct rocker Rocker;
  61. typedef struct world World;
  62. typedef struct desc_info DescInfo;
  63. typedef struct desc_ring DescRing;
  64. Rocker *rocker_find(const char *name);
  65. uint32_t rocker_fp_ports(Rocker *r);
  66. int rocker_event_link_changed(Rocker *r, uint32_t pport, bool link_up);
  67. int rocker_event_mac_vlan_seen(Rocker *r, uint32_t pport, uint8_t *addr,
  68. uint16_t vlan_id);
  69. int rx_produce(World *world, uint32_t pport,
  70. const struct iovec *iov, int iovcnt, uint8_t copy_to_cpu);
  71. int rocker_port_eg(Rocker *r, uint32_t pport,
  72. const struct iovec *iov, int iovcnt);
  73. #endif /* ROCKER_H */