You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hook.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* This file is part of Netsukuku
  2. * (c) Copyright 2004 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
  3. *
  4. * This source code is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as published
  6. * by the Free Software Foundation; either version 2 of the License,
  7. * or (at your option) any later version.
  8. *
  9. * This source code 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.
  12. * Please refer to the GNU Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Public License along with
  15. * this source code; if not, write to:
  16. * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef HOOK_H
  19. #define HOOK_H
  20. #include "qspn.h"
  21. #define MAX_FIRST_RADAR_SCANS 1 /* How many time we have to retry
  22. the first radar_scan if we
  23. didn't found anything */
  24. #ifdef DEBUG
  25. #undef MAX_FIRST_RADAR_SCANS
  26. #define MAX_FIRST_RADAR_SCANS 1
  27. #endif
  28. /* The IP class used during the hook */
  29. #define HOOKING_IP_10 0xa000001 /* 10.0.0.1 */
  30. #define HOOKING_IP_172 0xac100001 /* 172.16.0.1 */
  31. #define HOOKING_IPV6 0xfec00000 /* fec0:: */
  32. #define HOOK_RQ_TIMEOUT 8 /* seconds */
  33. /*
  34. * * * Global vars * * *
  35. */
  36. /* How many times netsukuku_hook() was launched */
  37. int total_hooks;
  38. /* Current join_rate */
  39. u_int hook_join_rate;
  40. u_int rnodes_rehooked; /* How many rnodes have rehooked with us */
  41. /*
  42. * * * Hook packets stuff * * *
  43. */
  44. /*
  45. * The free_nodes pkt is used to send the list of all the free/not used
  46. * nodes/gnodes present at level fn_hdr.level.
  47. * If level is == 0 then the pkt contains the list of free nodes of the fn_hdr.gid
  48. * gnode.
  49. * If level is > 0 then it contains the list of free gnodes which are inside
  50. * the gnode with `fn_hdr.gid' gid of the `fn_hdr.level'th level. So the free gnodes
  51. * are part of the (fn_hdr.level - 1)th level.
  52. */
  53. struct free_nodes_hdr {
  54. u_char max_levels; /* How many levels we are managing */
  55. uint32_t ipstart[MAX_IP_INT]; /* The ipstart of the gnode */
  56. u_char level; /* The level where the gnode belongs */
  57. u_char gid; /* The gnode id */
  58. u_char nodes; /* The number of free (g)nodes - 1 */
  59. uint32_t join_rate; /* Join_rate of `level' */
  60. } _PACKED_;
  61. INT_INFO free_nodes_hdr_iinfo = { 1, {INT_TYPE_32BIT},
  62. {sizeof(struct free_nodes_hdr) - sizeof(uint32_t)}
  63. ,
  64. {1}
  65. };
  66. #define FREE_NODES_SZ(nodes) (sizeof(struct free_nodes_hdr) +\
  67. (sizeof(u_char) * (nodes)))
  68. /*
  69. * the free_nodes block is:
  70. *
  71. * u_char free_nodes[fn_hdr.nodes/8]; The bit x inside `free_nodes'
  72. * tells if the node x, i.e.
  73. * int_map[x], is up or not.
  74. * If the bit is set to 1, it
  75. * is.
  76. *
  77. * The free_nodes pkt is:
  78. * fn_hdr;
  79. * fn_block;
  80. */
  81. /*
  82. * the qspn_round pkt is:
  83. * u_char max_levels;
  84. * int qspn_id[max_levels]; the qspn_id of the last qspn_round for each
  85. * fn_hdr.max_levels level
  86. * struct timeval qtime[max_levels]; qspn round time: how many seconds passed away
  87. * since the previous qspn round. There's a qtime
  88. * for each fn_hdr.max_levels level
  89. * u_int gcount[GCOUNT_LEVELS]; current qspn_gnode_count.
  90. */
  91. /* Note: for this int_info we are considering the timeval array as one int
  92. * with `max_levels'*2 members */
  93. INT_INFO qspn_round_pkt_iinfo = { 3,
  94. {INT_TYPE_32BIT, INT_TYPE_32BIT, INT_TYPE_32BIT}
  95. ,
  96. {sizeof(char), IINFO_DYNAMIC_VALUE, IINFO_DYNAMIC_VALUE},
  97. {IINFO_DYNAMIC_VALUE, IINFO_DYNAMIC_VALUE, GCOUNT_LEVELS}
  98. };
  99. #define QSPN_ROUND_PKT_SZ(levels) (sizeof(u_char) + \
  100. ((levels) * sizeof(int32_t)) + \
  101. ((levels) * sizeof(struct timeval))+\
  102. (GCOUNT_LEVELS * sizeof(u_int)))
  103. /*
  104. * * * Functions declaration * * *
  105. */
  106. int put_free_nodes(PACKET rq_pkt);
  107. int put_qspn_round(PACKET rq_pkt);
  108. int put_ext_map(PACKET rq_pkt);
  109. int put_int_map(PACKET rq_pkt);
  110. int put_bnode_map(PACKET rq_pkt);
  111. int create_gnodes(inet_prefix * ip, int final_level);
  112. void set_ip_and_def_gw(char *dev, inet_prefix ip);
  113. int hook_init(void);
  114. int netsukuku_hook(map_gnode * hook_gnode, int hook_level);
  115. #endif /*HOOK_H */