xorp

firewall_transaction.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2008-2009 XORP, Inc.
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/fea/firewall_transaction.hh,v 1.5 2008/10/02 21:56:47 bms Exp $
00021 
00022 #ifndef __FEA_FIREWALL_TRANSACTION_HH__
00023 #define __FEA_FIREWALL_TRANSACTION_HH__
00024 
00025 #include "libxorp/ipv4.hh"
00026 #include "libxorp/ipv4net.hh"
00027 #include "libxorp/ipv6.hh"
00028 #include "libxorp/ipv6net.hh"
00029 #include "libxorp/transaction.hh"
00030 
00031 #include "firewall_manager.hh"
00032 
00033 
00034 //
00035 // Firewall transactions.
00036 //
00037 
00044 class FirewallTransactionManager : public TransactionManager {
00045 public:
00052     FirewallTransactionManager(EventLoop& eventloop)
00053     : TransactionManager(eventloop, TIMEOUT_MS, MAX_PENDING)
00054     {}
00055 
00062     const string& error() const     { return _first_error; }
00063 
00064 protected:
00073     virtual void pre_commit(uint32_t tid);
00074 
00083     virtual void operation_result(bool success,
00084                   const TransactionOperation& op);
00085 
00086 private:
00090     void reset_error()          { _first_error.erase(); }
00091 
00092     string  _first_error;       // The string with the first error
00093     uint32_t    _tid_exec;      // The transaction ID
00094 
00095     enum { TIMEOUT_MS = 5000, MAX_PENDING = 10 };
00096 };
00097 
00101 class FirewallTransactionOperation : public TransactionOperation {
00102 public:
00103     FirewallTransactionOperation(FirewallManager& firewall_manager)
00104     : _firewall_manager(firewall_manager) {}
00105     virtual ~FirewallTransactionOperation() {}
00106 
00113     const string& error_reason() const { return (_error_reason); }
00114 
00115 protected:
00116     FirewallManager& firewall_manager() { return _firewall_manager; }
00117 
00118     string  _error_reason;      // The reason for a failure
00119 
00120 private:
00121     FirewallManager& _firewall_manager;
00122 };
00123 
00124 class FirewallAddEntry4 : public FirewallTransactionOperation {
00125 public:
00126     FirewallAddEntry4(FirewallManager&  firewall_manager,
00127               FirewallEntry&    firewall_entry)
00128     : FirewallTransactionOperation(firewall_manager),
00129       _entry(firewall_entry)
00130       {}
00131 
00132     bool dispatch() {
00133     if (firewall_manager().add_entry(_entry, _error_reason) != XORP_OK)
00134         return (false);
00135     return (true);
00136     }
00137 
00138     string str() const {
00139     return c_format("AddEntry4: %s", _entry.str().c_str());
00140     }
00141 
00142 private:
00143     FirewallEntry _entry;
00144 };
00145 
00146 class FirewallReplaceEntry4 : public FirewallTransactionOperation {
00147 public:
00148     FirewallReplaceEntry4(FirewallManager&  firewall_manager,
00149               FirewallEntry&    firewall_entry)
00150     : FirewallTransactionOperation(firewall_manager),
00151       _entry(firewall_entry)
00152       {}
00153 
00154     bool dispatch() {
00155     if (firewall_manager().replace_entry(_entry, _error_reason) != XORP_OK)
00156         return (false);
00157     return (true);
00158     }
00159 
00160     string str() const {
00161     return c_format("ReplaceEntry4: %s", _entry.str().c_str());
00162     }
00163 
00164 private:
00165     FirewallEntry _entry;
00166 };
00167 
00168 class FirewallDeleteEntry4 : public FirewallTransactionOperation {
00169 public:
00170     FirewallDeleteEntry4(FirewallManager&   firewall_manager,
00171              FirewallEntry&     firewall_entry)
00172     : FirewallTransactionOperation(firewall_manager),
00173       _entry(firewall_entry)
00174       {}
00175 
00176     bool dispatch() {
00177     if (firewall_manager().delete_entry(_entry, _error_reason) != XORP_OK)
00178         return (false);
00179     return (true);
00180     }
00181 
00182     string str() const {
00183     return c_format("DeleteEntry4: %s", _entry.str().c_str());
00184     }
00185 
00186 private:
00187     FirewallEntry _entry;
00188 };
00189 
00190 class FirewallDeleteAllEntries4 : public FirewallTransactionOperation {
00191 public:
00192     FirewallDeleteAllEntries4(FirewallManager& firewall_manager)
00193     : FirewallTransactionOperation(firewall_manager)
00194     {}
00195 
00196     bool dispatch() {
00197     if (firewall_manager().delete_all_entries4(_error_reason) != XORP_OK)
00198         return (false);
00199     return (true);
00200     }
00201 
00202     string str() const { return c_format("DeleteAllEntries4"); }
00203 };
00204 
00205 class FirewallAddEntry6 : public FirewallTransactionOperation {
00206 public:
00207     FirewallAddEntry6(FirewallManager&  firewall_manager,
00208               FirewallEntry&    firewall_entry)
00209     : FirewallTransactionOperation(firewall_manager),
00210       _entry(firewall_entry)
00211       {}
00212 
00213     bool dispatch() {
00214     if (firewall_manager().add_entry(_entry, _error_reason) != XORP_OK)
00215         return (false);
00216     return (true);
00217     }
00218 
00219     string str() const {
00220     return c_format("AddEntry6: %s", _entry.str().c_str());
00221     }
00222 
00223 private:
00224     FirewallEntry _entry;
00225 };
00226 
00227 class FirewallReplaceEntry6 : public FirewallTransactionOperation {
00228 public:
00229     FirewallReplaceEntry6(FirewallManager&  firewall_manager,
00230               FirewallEntry&    firewall_entry)
00231     : FirewallTransactionOperation(firewall_manager),
00232       _entry(firewall_entry)
00233       {}
00234 
00235     bool dispatch() {
00236     if (firewall_manager().replace_entry(_entry, _error_reason) != XORP_OK)
00237         return (false);
00238     return (true);
00239     }
00240 
00241     string str() const {
00242     return c_format("ReplaceEntry6: %s", _entry.str().c_str());
00243     }
00244 
00245 private:
00246     FirewallEntry _entry;
00247 };
00248 
00249 class FirewallDeleteEntry6 : public FirewallTransactionOperation {
00250 public:
00251     FirewallDeleteEntry6(FirewallManager&   firewall_manager,
00252              FirewallEntry&     firewall_entry)
00253     : FirewallTransactionOperation(firewall_manager),
00254       _entry(firewall_entry)
00255       {}
00256 
00257     bool dispatch() {
00258     if (firewall_manager().delete_entry(_entry, _error_reason) != XORP_OK)
00259         return (false);
00260     return (true);
00261     }
00262 
00263     string str() const {
00264     return c_format("DeleteEntry6: %s", _entry.str().c_str());
00265     }
00266 
00267 private:
00268     FirewallEntry _entry;
00269 };
00270 
00271 class FirewallDeleteAllEntries6 : public FirewallTransactionOperation {
00272 public:
00273     FirewallDeleteAllEntries6(FirewallManager& firewall_manager)
00274     : FirewallTransactionOperation(firewall_manager)
00275     {}
00276 
00277     bool dispatch() {
00278     if (firewall_manager().delete_all_entries6(_error_reason) != XORP_OK)
00279         return (false);
00280     return (true);
00281     }
00282 
00283     string str() const { return c_format("DeleteAllEntries6"); }
00284 };
00285 
00286 #endif // __FEA_FIREWALL_TRANSACTION_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations