interfaceconfig.hh

Go to the documentation of this file.
00001 // Copyright (C) 2003, 2004, 2005 Laboratoire de Recherche en Informatique
00002 
00003 // This file is part of Qolyester.
00004 
00005 // Qolyester is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 // Qolyester is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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         ipv?/eth?/accept_redirects = 0
00036 
00037         ipv4/eth?/rp_filter = 0
00038         ipv4/all/secure_redirects = 0
00039         ipv4/eth?/secure_redirects = 0
00040         ipv4/all/send_redirects = 0
00041         ipv4/eth?/send_redirects = 0
00042         ipv4/all/shared_media = 0
00043         ipv4/eth?/shared_media = 0
00044 
00045         ipv6/eth?/accept_ra = 0
00046         ipv6/eth?/autoconf = 0
00047         ipv6/eth?/dad_transmits = 0
00048 
00049         The following should not be like this, but separate forwarding
00050         for each interface seems not to be supported for IPv6.
00051 
00052         ipv4/eth?/forwarding = 1
00053         ipv6/all/forwarding = 1
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     } // namespace internal
00178 
00179   } // namespace sys
00180 
00181 } // namespace olsr
00182 
00183 #  include "interfaceconfig.hxx"
00184 
00185 # endif // ! QOLYESTER_DAEMON_SYS_LINUX_INTERFACECONFIG_HH
00186 
00187 #endif // ! QOLYESTER_ENABLE_VIRTUAL

Generated on Mon Sep 10 17:02:12 2007 for Qolyester daemon by  doxygen 1.5.1