rocker.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include "qom/object.h"
  22. #if defined(DEBUG_ROCKER)
  23. # define DPRINTF(fmt, ...) \
  24. do { \
  25. g_autoptr(GDateTime) now = g_date_time_new_now_local(); \
  26. g_autofree char *nowstr = g_date_time_format(now, "%T.%f");\
  27. fprintf(stderr, "%s ROCKER: " fmt, nowstr, ## __VA_ARGS__);\
  28. } while (0)
  29. #else
  30. static inline G_GNUC_PRINTF(1, 2) int DPRINTF(const char *fmt, ...)
  31. {
  32. return 0;
  33. }
  34. #endif
  35. #define __le16 uint16_t
  36. #define __le32 uint32_t
  37. #define __le64 uint64_t
  38. #define __be16 uint16_t
  39. #define __be32 uint32_t
  40. #define __be64 uint64_t
  41. static inline bool ipv4_addr_is_multicast(__be32 addr)
  42. {
  43. return (addr & htonl(0xf0000000)) == htonl(0xe0000000);
  44. }
  45. typedef struct ipv6_addr {
  46. union {
  47. uint8_t addr8[16];
  48. __be16 addr16[8];
  49. __be32 addr32[4];
  50. };
  51. } Ipv6Addr;
  52. static inline bool ipv6_addr_is_multicast(const Ipv6Addr *addr)
  53. {
  54. return (addr->addr32[0] & htonl(0xFF000000)) == htonl(0xFF000000);
  55. }
  56. typedef struct world World;
  57. typedef struct desc_info DescInfo;
  58. typedef struct desc_ring DescRing;
  59. #define TYPE_ROCKER "rocker"
  60. typedef struct rocker Rocker;
  61. DECLARE_INSTANCE_CHECKER(Rocker, ROCKER,
  62. TYPE_ROCKER)
  63. Rocker *rocker_find(const char *name);
  64. int rocker_event_link_changed(Rocker *r, uint32_t pport, bool link_up);
  65. int rocker_event_mac_vlan_seen(Rocker *r, uint32_t pport, uint8_t *addr,
  66. uint16_t vlan_id);
  67. int rx_produce(World *world, uint32_t pport,
  68. const struct iovec *iov, int iovcnt, uint8_t copy_to_cpu);
  69. int rocker_port_eg(Rocker *r, uint32_t pport,
  70. const struct iovec *iov, int iovcnt);
  71. #endif /* ROCKER_H */