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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. LLIST_HDR(struct internet_gateway);
  77. u_int ip[MAX_IP_INT];
  78. u_char gid;
  79. map_node *node;
  80. char flags;
  81. u_char bandwidth; /* Its Internet bandwidth */
  82. };
  83. typedef struct internet_gateway inet_gw;
  84. /* We pack only `gid' and `bandwidth' */
  85. #define INET_GW_PACK_SZ (sizeof(u_char)*2 + MAX_IP_SZ)
  86. struct inet_gw_pack_hdr {
  87. int16_t gws[MAX_LEVELS]; /* Number of inet_gws there are in the
  88. pack, for each level */
  89. u_char levels;
  90. } _PACKED_;
  91. INT_INFO inet_gw_pack_hdr_iinfo =
  92. { 1, {INT_TYPE_16BIT}, {0}, {MAX_LEVELS} };
  93. /*
  94. * The inet_gw_pack_body is:
  95. * inet_gw_pack igw[hdr.gws[i]] for all the i that goes from 0 to
  96. * hdr.levels
  97. */
  98. #define IGWS_PACK_SZ(hdr) \
  99. ({ \
  100. size_t _sz; int _pi; \
  101. _sz=sizeof(struct inet_gw_pack_hdr); \
  102. for(_pi=0; _pi<(hdr)->levels; _pi++) \
  103. _sz+=INET_GW_PACK_SZ*((hdr)->gws[_pi]); \
  104. _sz; \
  105. })
  106. #define MAX_IGWS_PACK_SZ(levels) (sizeof(struct inet_gw_pack_hdr) + \
  107. INET_GW_PACK_SZ*MAXIGWS*(levels))
  108. /*\
  109. *
  110. * * * Multi Internet Gateways * * *
  111. *
  112. \*/
  113. /*
  114. * igw_nexthop
  115. *
  116. * The multigw allows the simultaneus use of multiple internet gateways.
  117. * The multigw requires one routing table and one tunnel for each
  118. * nexthop in the default multipath route. With an array of `igw_nexthop' we
  119. * keep track of them.
  120. */
  121. struct default_inet_gw_nexthop {
  122. inet_prefix nexthop;
  123. u_char flags; /* inet_gw flags */
  124. u_char table;
  125. u_char tunl; /* `tunl' is the number of the tunnel
  126. we are using to reach this igw.
  127. (tunl = 4 means we are using the
  128. "tunl4" device) */
  129. };
  130. typedef struct default_inet_gw_nexthop igw_nexthop;
  131. /*\
  132. * Notes on the IGW packed in a qspn pkt
  133. *
  134. * The simplest way to tell the other nodes that we are sharing our Internet
  135. * connection or that in our gnode there is an available gw is to use the
  136. * bnode block included in the qspn packets.
  137. * We consider an Internet gw as a bnode connected to a virtual gnode (the
  138. * Internet), therefore in the relative bnode_chunk we set:
  139. * bchunk.gnode = 0; this value has no meaning
  140. * bchunk.level = GET_LEVELS(my_family) + 1;
  141. * bchunk.rtt = the bandwidth of the internet connection of the gw.
  142. * It is in the bandwidth_in_8bit() format.
  143. \*/
  144. #define MAX_IGW_PER_QSPN_CHUNK 16 /* Maximum number of IGWs
  145. contained in a single
  146. QSPN chunk */
  147. /*\
  148. *
  149. * * * Globals * * *
  150. *
  151. \*/
  152. int active_gws;
  153. igw_nexthop multigw_nh[MAX_MULTIPATH_ROUTES];
  154. /*\
  155. *
  156. * * * Functions declaration * *
  157. *
  158. \*/
  159. u_char bandwidth_in_8bit(u_int x);
  160. int str_to_inet_gw(char *str, inet_prefix * gw, char **dev);
  161. char **parse_internet_hosts(char *str, int *hosts);
  162. void free_internet_hosts(char **hnames, int hosts);
  163. void init_my_igw(void);
  164. void init_igws(inet_gw *** igws, int **igws_counter, int levels);
  165. void reset_igws(inet_gw ** igws, int *igws_counter, int levels);
  166. void free_igws(inet_gw ** igws, int *igws_counter, int levels);
  167. void init_my_igws(inet_gw ** igws, int *igws_counter,
  168. inet_gw *** my_new_igws, u_char my_bandwidth,
  169. map_node * cur_node, quadro_group * qg);
  170. void free_my_igws(inet_gw *** my_igs);
  171. void init_internet_gateway_search(void);
  172. void close_internet_gateway_search(void);
  173. inet_gw *igw_add_node(inet_gw ** igws, int *igws_counter, int level,
  174. int gid, map_node * node, int ip[MAX_IP_INT],
  175. 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,
  182. int level);
  183. int igw_check_inet_conn(void);
  184. void *igw_check_inet_conn_t(void *null);
  185. void *igw_monitor_igws_t(void *null);
  186. int igw_exec_masquerade_sh(char *script, int stop);
  187. int igw_exec_tcshaper_sh(char *script, int stop,
  188. char *dev, int upload_bw, int dnload_bw);
  189. void reset_igw_nexthop(igw_nexthop * igwn);
  190. void reset_igw_rules(void);
  191. int igw_replace_def_igws(inet_gw ** igws, int *igws_counter,
  192. inet_gw ** my_igws, int max_levels, int family);
  193. char *igw_build_bentry(u_char level, size_t * pack_sz, int *new_bblocks);
  194. int igw_store_bblock(bnode_hdr * bblock_hdr, bnode_chunk * bchunk,
  195. u_char level);
  196. char *pack_igws(inet_gw ** igws, int *igws_counter, int levels,
  197. int *pack_sz);
  198. int unpack_igws(char *pack, size_t pack_sz, map_node * int_map,
  199. map_gnode ** ext_map, int levels, inet_gw *** new_igws,
  200. int **new_igws_counter);
  201. #endif /*IGS_H */