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.

igs.h 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* This file is part of Netsukuku
  2. * (c) Copyright 2005 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 IGS_H
  19. #define IGS_H
  20. #include "route.h"
  21. /*
  22. * The IGS_MULTI_GW feature relies heavily on netfilter and the linux advanced
  23. * routing.
  24. */
  25. #ifdef GNU_LINUX
  26. #define IGS_MULTI_GW
  27. #endif
  28. /*\
  29. * * Bandwidth notes *
  30. *
  31. * When we talk of `bandwidth' we mean the average of the download and
  32. * upload bandwidth of a particular node.
  33. * The bandwidth of a gnode is the average of all the bandwidths of the nodes
  34. * belonging to that gnode.
  35. *
  36. * Internally we save the `bandwidth' as a u_char variable using the
  37. * `bandwidth_in_8bit' function (see igs.c)
  38. \*/
  39. /* Minum bandwidth necessary to share an internet connection */
  40. #define MIN_CONN_BANDWIDTH 3 /* 16 Kb/s */
  41. #define MAX_INTERNET_HNAMES 10
  42. #define MAX_INTERNET_HNAME_SZ 64
  43. #define INET_HOST_PING_TIMEOUT 3
  44. #define IGW_HOST_PING_TIMEOUT 10
  45. #define INET_NEXT_PING_WAIT 10
  46. #define IGW_BW_DELTA 1 /* If the difference between the old and the new
  47. igw->bandwidth is >= IGW_BW_DELTA, then
  48. me.igws is reordered and the routing table
  49. updated */
  50. #define MAXIGWS MAXGROUPNODE /* max number of internet
  51. gateways in each level */
  52. #define RTTABLE_IGW 221 /* Routing tables from 221 to 244 */
  53. #define RTTABLE_ALISHIELD 245 /* Anti Loop multi-Igw Shield
  54. (what a damn long name, read the Ntk_IGS
  55. RFC) */
  56. #define FWMARK_ALISHIELD 25
  57. #ifdef DEBUG
  58. #undef INET_NEXT_PING_WAIT
  59. #define INET_NEXT_PING_WAIT 5
  60. #endif
  61. /*
  62. * inet_gw flags
  63. */
  64. #define IGW_TUNNELED 1
  65. #define IGW_ACTIVE (1<<1) /* This gw is being used in the
  66. routing table */
  67. #define IGW_RTRULE (1<<2) /* The relative routing rule is already
  68. present */
  69. /*
  70. * internet_gateway
  71. *
  72. * This struct points to a particular (g)node which is sharing its Internet
  73. * connection
  74. */
  75. struct internet_gateway
  76. {
  77. LLIST_HDR (struct internet_gateway);
  78. u_int ip[MAX_IP_INT];
  79. u_char gid;
  80. map_node *node;
  81. char flags;
  82. u_char bandwidth; /* Its Internet bandwidth */
  83. };
  84. typedef struct internet_gateway inet_gw;
  85. /* We pack only `gid' and `bandwidth' */
  86. #define INET_GW_PACK_SZ (sizeof(u_char)*2 + MAX_IP_SZ)
  87. struct inet_gw_pack_hdr
  88. {
  89. int16_t gws[MAX_LEVELS];/* Number of inet_gws there are in the
  90. pack, for each level */
  91. u_char levels;
  92. }_PACKED_;
  93. INT_INFO inet_gw_pack_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { MAX_LEVELS } };
  94. /*
  95. * The inet_gw_pack_body is:
  96. * inet_gw_pack igw[hdr.gws[i]] for all the i that goes from 0 to
  97. * hdr.levels
  98. */
  99. #define IGWS_PACK_SZ(hdr) \
  100. ({ \
  101. size_t _sz; int _pi; \
  102. _sz=sizeof(struct inet_gw_pack_hdr); \
  103. for(_pi=0; _pi<(hdr)->levels; _pi++) \
  104. _sz+=INET_GW_PACK_SZ*((hdr)->gws[_pi]); \
  105. _sz; \
  106. })
  107. #define MAX_IGWS_PACK_SZ(levels) (sizeof(struct inet_gw_pack_hdr) + \
  108. INET_GW_PACK_SZ*MAXIGWS*(levels))
  109. /*\
  110. *
  111. * * * Multi Internet Gateways * * *
  112. *
  113. \*/
  114. /*
  115. * igw_nexthop
  116. *
  117. * The multigw allows the simultaneus use of multiple internet gateways.
  118. * The multigw requires one routing table and one tunnel for each
  119. * nexthop in the default multipath route. With an array of `igw_nexthop' we
  120. * keep track of them.
  121. */
  122. struct default_inet_gw_nexthop {
  123. inet_prefix nexthop;
  124. u_char flags; /* inet_gw flags */
  125. u_char table;
  126. u_char tunl; /* `tunl' is the number of the tunnel
  127. we are using to reach this igw.
  128. (tunl = 4 means we are using the
  129. "tunl4" device) */
  130. };
  131. typedef struct default_inet_gw_nexthop igw_nexthop;
  132. /*\
  133. * Notes on the IGW packed in a qspn pkt
  134. *
  135. * The simplest way to tell the other nodes that we are sharing our Internet
  136. * connection or that in our gnode there is an available gw is to use the
  137. * bnode block included in the qspn packets.
  138. * We consider an Internet gw as a bnode connected to a virtual gnode (the
  139. * Internet), therefore in the relative bnode_chunk we set:
  140. * bchunk.gnode = 0; this value has no meaning
  141. * bchunk.level = GET_LEVELS(my_family) + 1;
  142. * bchunk.rtt = the bandwidth of the internet connection of the gw.
  143. * It is in the bandwidth_in_8bit() format.
  144. \*/
  145. #define MAX_IGW_PER_QSPN_CHUNK 16 /* Maximum number of IGWs
  146. contained in a single
  147. QSPN chunk */
  148. /*\
  149. *
  150. * * * Globals * * *
  151. *
  152. \*/
  153. int active_gws;
  154. igw_nexthop multigw_nh[MAX_MULTIPATH_ROUTES];
  155. /*\
  156. *
  157. * * * Functions declaration * *
  158. *
  159. \*/
  160. u_char bandwidth_in_8bit(u_int x);
  161. int str_to_inet_gw(char *str, inet_prefix *gw, char **dev);
  162. char **parse_internet_hosts(char *str, int *hosts);
  163. void free_internet_hosts(char **hnames, int hosts);
  164. void init_my_igw(void);
  165. void init_igws(inet_gw ***igws, int **igws_counter, int levels);
  166. void reset_igws(inet_gw **igws, int *igws_counter, int levels);
  167. void free_igws(inet_gw **igws, int *igws_counter, int levels);
  168. void init_my_igws(inet_gw **igws, int *igws_counter,
  169. inet_gw ***my_new_igws, u_char my_bandwidth,
  170. map_node *cur_node, quadro_group *qg);
  171. void free_my_igws(inet_gw ***my_igs);
  172. void init_internet_gateway_search(void);
  173. void close_internet_gateway_search(void);
  174. inet_gw *igw_add_node(inet_gw **igws, int *igws_counter, int level,
  175. int gid, map_node *node, int ip[MAX_IP_INT], u_char bandwidth);
  176. int igw_del(inet_gw **igws, int *igws_counter, inet_gw *igw, int level);
  177. inet_gw *igw_find_node(inet_gw **igws, int level, map_node *node);
  178. inet_gw *igw_find_ip(inet_gw **igws, int level, u_int ip[MAX_IP_INT]);
  179. int igw_del_node(inet_gw **, int *, int, map_node *);
  180. void igw_update_gnode_bw(int *, inet_gw **, inet_gw *, int, int, int);
  181. void igw_order(inet_gw **igws, int *igws_counter, inet_gw **my_igws, int level);
  182. int igw_check_inet_conn(void);
  183. void *igw_check_inet_conn_t(void *null);
  184. void *igw_monitor_igws_t(void *null);
  185. int igw_exec_masquerade_sh(char *script, int stop);
  186. int igw_exec_tcshaper_sh(char *script, int stop,
  187. char *dev, int upload_bw, int dnload_bw);
  188. void reset_igw_nexthop(igw_nexthop *igwn);
  189. void reset_igw_rules(void);
  190. int igw_replace_def_igws(inet_gw **igws, int *igws_counter,
  191. inet_gw **my_igws, int max_levels, int family);
  192. char *igw_build_bentry(u_char level, size_t *pack_sz, int *new_bblocks);
  193. int igw_store_bblock(bnode_hdr *bblock_hdr, bnode_chunk *bchunk, u_char level);
  194. char *pack_igws(inet_gw **igws, int *igws_counter, int levels, int *pack_sz);
  195. int unpack_igws(char *pack, size_t pack_sz,
  196. map_node *int_map, map_gnode **ext_map, int levels,
  197. inet_gw ***new_igws, int **new_igws_counter);
  198. #endif /*IGS_H*/