00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.hh"
00020
00021 #ifndef QOLYESTER_ENABLE_VIRTUAL
00022
00023 # ifndef QOLYESTER_DAEMON_SYS_LINUX_INTERFACECONFIG_HH
00024 # define QOLYESTER_DAEMON_SYS_LINUX_INTERFACECONFIG_HH 1
00025
00026 # include <string>
00027
00028 namespace olsr {
00029
00030 namespace sys {
00031
00032 namespace internal {
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 class InterfaceConfig {
00057 public:
00058 InterfaceConfig(const std::string& name)
00059 : _name(name),
00060 _configured(false)
00061 {}
00062
00063 void setup() {
00064 if (_configured)
00065 return;
00066
00067 # if QOLYESTER_FAMILY_INET == 4
00068 std::string prefix("/proc/sys/net/ipv4/conf/");
00069 # elif QOLYESTER_FAMILY_INET == 6
00070 std::string prefix("/proc/sys/net/ipv6/conf/");
00071 # endif
00072
00073 # define SET(Name, Value) \
00074 do { \
00075 get_and_set(prefix + _name + "/" #Name, #Value, _ ## Name); \
00076 } while (0)
00077
00078 # define SET_ALL(Name, Value) \
00079 do { \
00080 get_and_set(prefix + "all/" #Name, #Value, _all_ ## Name); \
00081 } while (0)
00082
00083 SET(accept_redirects, 0);
00084 # if QOLYESTER_FAMILY_INET == 4
00085 SET_ALL(forwarding, 1);
00086 SET(rp_filter, 0);
00087 SET_ALL(secure_redirects, 0);
00088 SET(secure_redirects, 0);
00089 SET_ALL(send_redirects, 0);
00090 SET(send_redirects, 0);
00091 SET_ALL(shared_media, 0);
00092 SET(shared_media, 0);
00093 # elif QOLYESTER_FAMILY_INET == 6
00094 SET_ALL(forwarding, 1);
00095 SET(accept_ra, 0);
00096 SET(autoconf, 0);
00097 SET(dad_transmits, 0);
00098 # endif
00099
00100 # undef SET
00101 # undef SET_ALL
00102 _configured = true;
00103 }
00104
00105 void revert() {
00106 if (!_configured)
00107 return;
00108
00109 # if QOLYESTER_FAMILY_INET == 4
00110 std::string prefix("/proc/sys/net/ipv4/conf/");
00111 # elif QOLYESTER_FAMILY_INET == 6
00112 std::string prefix("/proc/sys/net/ipv6/conf/");
00113 # endif
00114
00115 # define RESET(Name) \
00116 do { \
00117 set(prefix + _name + "/" #Name, _ ## Name); \
00118 } while (0)
00119
00120 # define RESET_ALL(Name) \
00121 do { \
00122 set(prefix + "all/" #Name, _all_ ## Name); \
00123 } while (0)
00124
00125 RESET(accept_redirects);
00126
00127 # if QOLYESTER_FAMILY_INET == 4
00128 RESET_ALL(forwarding);
00129 RESET(rp_filter);
00130 RESET_ALL(secure_redirects);
00131 RESET(secure_redirects);
00132 RESET_ALL(send_redirects);
00133 RESET(send_redirects);
00134 RESET_ALL(shared_media);
00135 RESET(shared_media);
00136 # elif QOLYESTER_FAMILY_INET == 6
00137 RESET_ALL(forwarding);
00138 RESET(accept_ra);
00139 RESET(autoconf);
00140 RESET(dad_transmits);
00141 # endif
00142
00143 # undef RESET
00144 # undef RESET_ALL
00145 _configured = false;
00146 }
00147
00148 private:
00149 inline void get_and_set(const std::string& path,
00150 const std::string& value,
00151 std::string& old_value);
00152
00153 inline void set(const std::string& path, const std::string& value);
00154
00155 std::string _name;
00156 bool _configured;
00157
00158 std::string _accept_redirects;
00159
00160 # if QOLYESTER_FAMILY_INET == 4
00161 std::string _all_forwarding;
00162 std::string _rp_filter;
00163 std::string _all_secure_redirects;
00164 std::string _secure_redirects;
00165 std::string _all_send_redirects;
00166 std::string _send_redirects;
00167 std::string _all_shared_media;
00168 std::string _shared_media;
00169 # else // QOLYESTER_FAMILY_INET != 4
00170 std::string _all_forwarding;
00171 std::string _accept_ra;
00172 std::string _autoconf;
00173 std::string _dad_transmits;
00174 # endif
00175 };
00176
00177 }
00178
00179 }
00180
00181 }
00182
00183 # include "interfaceconfig.hxx"
00184
00185 # endif // ! QOLYESTER_DAEMON_SYS_LINUX_INTERFACECONFIG_HH
00186
00187 #endif // ! QOLYESTER_ENABLE_VIRTUAL