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.

conf.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 CONF_H
  19. #define CONF_H
  20. #define CONF_MAX_LINES 500 /* Max number of option lines */
  21. #define CONF_GET_VALUE(opt) (getenv(config_str[(opt)]))
  22. #define CONF_GET_INT_VALUE(opt, n) \
  23. ({ \
  24. char *_val; \
  25. _val=CONF_GET_VALUE((opt)); \
  26. if(_val) \
  27. (n)=atoi(_val); \
  28. })
  29. #define CONF_GET_STRN_VALUE(opt, str, maxbytes) \
  30. ({ \
  31. char *_val; \
  32. _val=CONF_GET_VALUE((opt)); \
  33. if(_val) \
  34. *(str)=xstrndup(_val, (maxbytes)); \
  35. })
  36. #define CONF_SET_STRN_OPT(opt, cnf_name, n) \
  37. { \
  38. char *v; \
  39. v = CONF_GET_VALUE((cnf_name)); \
  40. if(v) \
  41. { \
  42. if(strlen(v) > n - 1) v[n] = '\0'; \
  43. *opt = realloc(*opt, strlen(v)); \
  44. if(!opt) \
  45. { \
  46. perror("Unable to allocate memory for option"); \
  47. exit(-1); \
  48. } \
  49. strcpy(*opt, v); \
  50. }\
  51. }
  52. /*
  53. * The allowed options in the configuration file
  54. */
  55. enum config_options {
  56. CONF_NTK_INT_MAP_FILE,
  57. CONF_NTK_BNODE_MAP_FILE,
  58. CONF_NTK_EXT_MAP_FILE,
  59. CONF_ANDNA_HNAMES_FILE,
  60. CONF_SNSD_NODES_FILE,
  61. CONF_ANDNA_CACHE_FILE,
  62. CONF_ANDNA_LCLKEY_FILE,
  63. CONF_ANDNA_LCL_FILE,
  64. CONF_ANDNA_RHC_FILE,
  65. CONF_ANDNA_COUNTER_C_FILE,
  66. CONF_NTK_PID_FILE,
  67. CONF_NTK_MAX_CONNECTIONS,
  68. CONF_NTK_MAX_ACCEPTS_PER_HOST,
  69. CONF_NTK_MAX_ACCEPTS_PER_HOST_TIME,
  70. CONF_DISABLE_ANDNA,
  71. CONF_DISABLE_RESOLVCONF,
  72. CONF_NTK_RESTRICTED_MODE,
  73. CONF_NTK_RESTRICTED_CLASS,
  74. CONF_NTK_INTERNET_CONNECTION,
  75. CONF_NTK_INTERNET_GW,
  76. CONF_NTK_INTERNET_UPLOAD,
  77. CONF_NTK_INTERNET_DOWNLOAD,
  78. CONF_NTK_INTERNET_PING_HOSTS,
  79. CONF_SHARE_INTERNET,
  80. CONF_SHAPE_INTERNET,
  81. CONF_USE_SHARED_INET,
  82. CONF_NTK_IP_MASQ_SCRIPT,
  83. CONF_NTK_TC_SHAPER_SCRIPT,
  84. };
  85. const static char config_str[][30] = {
  86. {"ntk_int_map_file"},
  87. {"ntk_bnode_map_file"},
  88. {"ntk_ext_map_file"},
  89. {"andna_hnames_file"},
  90. {"snsd_nodes_file"},
  91. {"andna_cache_file"},
  92. {"andna_lclkey_file"},
  93. {"andna_lcl_file"},
  94. {"andna_rhc_file"},
  95. {"andna_counter_c_file"},
  96. {"pid_file"},
  97. {"ntk_max_connections"},
  98. {"ntk_max_accepts_per_host"},
  99. {"max_accepts_per_host_time"},
  100. {"disable_andna"},
  101. {"disable_resolvconf"},
  102. {"ntk_restricted_mode"},
  103. {"ntk_restricted_class"},
  104. {"internet_connection"},
  105. {"internet_gateway"},
  106. {"internet_upload_rate"},
  107. {"internet_download_rate"},
  108. {"internet_ping_hosts"},
  109. {"share_internet"},
  110. {"shape_internet"},
  111. {"use_shared_internet"},
  112. {"ip_masquerade_script"},
  113. {"tc_shaper_script"},
  114. {0},
  115. };
  116. void clear_config_env(void);
  117. int load_config_file(char *file);
  118. #endif /*CONF_H */