2
0

interface.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. struct interface *peer;
  44. const char *name;
  45. enum umdns_socket_type type;
  46. int ifindex;
  47. struct interface_addr_list addrs;
  48. struct uloop_timeout announce_timer;
  49. int announce_state;
  50. };
  51. static inline bool interface_multicast(struct interface *iface)
  52. {
  53. return !(iface->type & SOCKTYPE_BIT_UNICAST);
  54. }
  55. static inline bool interface_ipv6(struct interface *iface)
  56. {
  57. return !!(iface->type & SOCKTYPE_BIT_IPV6);
  58. }
  59. int interface_add(const char *name);
  60. int interface_init(void);
  61. void interface_shutdown(void);
  62. int interface_send_packet(struct interface *iface, struct sockaddr *to, struct iovec *iov, int iov_len);
  63. struct interface* interface_get(const char *name, enum umdns_socket_type type);
  64. #endif