interface.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
  3. * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License version 2.1
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __MDNS_INTERFACE_H
  15. #define __MDNS_INTERFACE_H
  16. #include <sys/types.h>
  17. #include <sys/uio.h>
  18. #include <arpa/inet.h>
  19. #include <libubox/uloop.h>
  20. #include <libubox/vlist.h>
  21. extern struct vlist_tree interfaces;
  22. #define SOCKTYPE_BIT_IPV6 (1 << 1)
  23. #define SOCKTYPE_BIT_UNICAST (1 << 0)
  24. enum umdns_socket_type {
  25. SOCK_MC_IPV4 = 0,
  26. SOCK_UC_IPV4 = SOCKTYPE_BIT_UNICAST,
  27. SOCK_MC_IPV6 = SOCKTYPE_BIT_IPV6,
  28. SOCK_UC_IPV6 = SOCKTYPE_BIT_IPV6 | SOCKTYPE_BIT_UNICAST,
  29. };
  30. struct interface_addr_list {
  31. union {
  32. struct {
  33. struct in_addr addr, mask;
  34. } *v4;
  35. struct {
  36. struct in6_addr addr, mask;
  37. } *v6;
  38. };
  39. int n_addr;
  40. };
  41. struct interface {
  42. struct vlist_node node;
  43. const char *name;
  44. enum umdns_socket_type type;
  45. int ifindex;
  46. struct interface_addr_list addrs;
  47. struct uloop_timeout announce_timer;
  48. int announce_state;
  49. };
  50. static inline bool interface_multicast(struct interface *iface)
  51. {
  52. return !(iface->type & SOCKTYPE_BIT_UNICAST);
  53. }
  54. static inline bool interface_ipv6(struct interface *iface)
  55. {
  56. return !!(iface->type & SOCKTYPE_BIT_IPV6);
  57. }
  58. int interface_add(const char *name);
  59. int interface_init(void);
  60. void interface_shutdown(void);
  61. int interface_send_packet(struct interface *iface, struct sockaddr *to, struct iovec *iov, int iov_len);
  62. struct interface* interface_get(const char *name, enum umdns_socket_type type);
  63. #endif