subnet.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef TINC_SUBNET_H
  2. #define TINC_SUBNET_H
  3. /*
  4. subnet.h -- header for subnet.c
  5. Copyright (C) 2000-2009 Guus Sliepen <guus@tinc-vpn.org>,
  6. 2000-2005 Ivo Timmermans
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License along
  16. with this program; if not, write to the Free Software Foundation, Inc.,
  17. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. #include "net.h"
  20. typedef enum subnet_type_t {
  21. SUBNET_MAC = 0,
  22. SUBNET_IPV4,
  23. SUBNET_IPV6,
  24. SUBNET_TYPES, /* Guardian */
  25. } subnet_type_t;
  26. typedef struct subnet_mac_t {
  27. mac_t address;
  28. } subnet_mac_t;
  29. typedef struct subnet_ipv4_t {
  30. ipv4_t address;
  31. int prefixlength;
  32. } subnet_ipv4_t;
  33. typedef struct subnet_ipv6_t {
  34. ipv6_t address;
  35. int prefixlength;
  36. } subnet_ipv6_t;
  37. #include "node.h"
  38. typedef struct subnet_t {
  39. struct node_t *owner; /* the owner of this subnet */
  40. subnet_type_t type; /* subnet type (IPv4? IPv6? MAC? something even weirder?) */
  41. time_t expires; /* expiry time */
  42. int weight; /* weight (higher value is higher priority) */
  43. /* And now for the actual subnet: */
  44. union net {
  45. subnet_mac_t mac;
  46. subnet_ipv4_t ipv4;
  47. subnet_ipv6_t ipv6;
  48. } net;
  49. } subnet_t;
  50. #define MAXNETSTR 64
  51. extern avl_tree_t *subnet_tree;
  52. extern subnet_t *new_subnet(void) __attribute__((__malloc__));
  53. extern void free_subnet(subnet_t *subnet);
  54. extern void init_subnets(void);
  55. extern void exit_subnets(void);
  56. extern avl_tree_t *new_subnet_tree(void) __attribute__((__malloc__));
  57. extern void free_subnet_tree(avl_tree_t *subnet_tree);
  58. extern void subnet_add(struct node_t *owner, subnet_t *subnet);
  59. extern void subnet_del(struct node_t *owner, subnet_t *subnet);
  60. extern void subnet_update(struct node_t *owner, subnet_t *subnet, bool up);
  61. extern bool net2str(char *netstr, int len, const subnet_t *subnet);
  62. extern bool str2net(subnet_t *subnet, const char *netstr);
  63. extern subnet_t *lookup_subnet(const struct node_t *owner, const subnet_t *subnet);
  64. extern subnet_t *lookup_subnet_mac(const struct node_t *owner, const mac_t *address);
  65. extern subnet_t *lookup_subnet_ipv4(const ipv4_t *address);
  66. extern subnet_t *lookup_subnet_ipv6(const ipv6_t *address);
  67. extern void dump_subnets(void);
  68. extern void subnet_cache_flush(void);
  69. #endif