xorp

ifconfig_transaction.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
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 #ifndef __FEA_IFCONFIG_TRANSACTION_HH__
00021 #define __FEA_IFCONFIG_TRANSACTION_HH__
00022 
00023 #include "libxorp/c_format.hh"
00024 #include "libxorp/transaction.hh"
00025 #include "libxorp/fea_share.hh"
00026 #include "ifconfig.hh"
00027 #include "iftree.hh"
00028 
00029 
00030 class IfConfigTransactionManager : public TransactionManager {
00031 public:
00037     IfConfigTransactionManager(EventLoop& eventloop)
00038     : TransactionManager(eventloop, TIMEOUT_MS, MAX_PENDING)
00039     {
00040         _tid_exec = 0xFFFFFFFF;
00041     }
00042 
00049     const string& error() const     { return _first_error; }
00050 
00051 protected:
00060     virtual void pre_commit(uint32_t tid);
00061 
00070     virtual void operation_result(bool success,
00071                   const TransactionOperation& op);
00072 
00073 private:
00077     void reset_error()          { _first_error.erase(); }
00078 
00079     string  _first_error;       // The string with the first error
00080     uint32_t    _tid_exec;      // The transaction ID
00081 
00082     enum { TIMEOUT_MS = 5000, MAX_PENDING = 10 };
00083 };
00084 
00089 class IfConfigTransactionOperation : public TransactionOperation {
00090 public:
00091     IfConfigTransactionOperation(IfConfig& ifconfig, const string& ifname)
00092     : _ifconfig(ifconfig),
00093       _iftree(ifconfig.user_config()),  // XXX: The iftree to modify
00094       _ifname(ifname) {}
00095 
00099     virtual string path() const         { return _ifname; }
00100 
00106     const string& ifname() const        { return _ifname; }
00107 
00108 protected:
00114     IfConfig& ifconfig()            { return _ifconfig; }
00115 
00121     IfTree& iftree()                { return _iftree; }
00122 
00123 private:
00124     IfConfig&       _ifconfig;
00125     IfTree&     _iftree;
00126     const string    _ifname;
00127 };
00128 
00132 class AddInterface : public IfConfigTransactionOperation {
00133 public:
00134     AddInterface(IfConfig& ifconfig, const string& ifname)
00135     : IfConfigTransactionOperation(ifconfig, ifname) {}
00136 
00137     bool dispatch() {
00138     if (ifconfig().add_interface(ifname()) != XORP_OK)
00139         return (false);
00140     return (true);
00141     }
00142 
00143     string str() const { return string("AddInterface: ") + ifname(); }
00144 };
00145 
00149 class RemoveInterface : public IfConfigTransactionOperation {
00150 public:
00151     RemoveInterface(IfConfig& ifconfig, const string& ifname)
00152     : IfConfigTransactionOperation(ifconfig, ifname) { }
00153 
00154     bool dispatch();
00155 
00156     string str() const {
00157     return string("RemoveInterface: ") + ifname();
00158     }
00159 };
00160 
00165 class ConfigureAllInterfacesFromSystem : public IfConfigTransactionOperation {
00166 public:
00167     ConfigureAllInterfacesFromSystem(IfConfig& ifconfig, bool enable)
00168     : IfConfigTransactionOperation(ifconfig, ""),
00169       _enable(enable)
00170     {}
00171 
00172     bool dispatch() {
00173     // Force a read of ALL interfaces, not just ones we are configured
00174     // to care about.
00175     ifconfig().full_pulled_config();
00176 
00177     if (_enable) {
00178         //
00179         // Configure all interfaces
00180         //
00181         const IfTree& dev_config = ifconfig().system_config();
00182         IfTree::IfMap::const_iterator iter;
00183         for (iter = dev_config.interfaces().begin();
00184          iter != dev_config.interfaces().end();
00185          ++iter) {
00186         const IfTreeInterface& iface = *(iter->second);
00187         if (ifconfig().update_interface(iface) != XORP_OK)
00188             return (false);
00189         }
00190     }
00191 
00192     //
00193     // Set the "default_system_config" flag for all interfaces
00194     //
00195     IfTree::IfMap::iterator iter;
00196     for (iter = iftree().interfaces().begin();
00197          iter != iftree().interfaces().end();
00198          ++iter) {
00199         IfTreeInterface& iface = *(iter->second);
00200         iface.set_default_system_config(_enable);
00201     }
00202 
00203     return (true);
00204     }
00205 
00206     string str() const {
00207     return c_format("ConfigureAllInterfacesFromSystem: %s",
00208             bool_c_str(_enable));
00209     }
00210 
00211 private:
00212     bool    _enable;
00213 };
00214 
00219 class ConfigureInterfaceFromSystem : public IfConfigTransactionOperation {
00220 public:
00221     ConfigureInterfaceFromSystem(IfConfig&  ifconfig,
00222                  const string&  ifname,
00223                  bool       enable)
00224     : IfConfigTransactionOperation(ifconfig, ifname),
00225       _enable(enable)
00226     {}
00227 
00228     bool dispatch() {
00229     IfTreeInterface* ifp = iftree().find_interface(ifname());
00230     if (ifp == NULL)
00231         return (false);
00232     ifp->set_default_system_config(_enable);
00233     return (true);
00234     }
00235 
00236     string str() const {
00237     return c_format("ConfigureInterfaceFromSystem: %s %s",
00238             ifname().c_str(), bool_c_str(_enable));
00239     }
00240 
00241 private:
00242     bool    _enable;
00243 };
00244 
00248 class InterfaceModifier : public IfConfigTransactionOperation {
00249 public:
00250     InterfaceModifier(IfConfig&     ifconfig,
00251               const string& ifname)
00252     : IfConfigTransactionOperation(ifconfig, ifname) {}
00253 
00254 protected:
00255     IfTreeInterface* interface() {
00256     IfTreeInterface* ifp = iftree().find_interface(ifname());
00257     return (ifp);
00258     }
00259 };
00260 
00264 class SetInterfaceEnabled : public InterfaceModifier {
00265 public:
00266     SetInterfaceEnabled(IfConfig&   ifconfig,
00267             const string&   ifname,
00268             bool        enabled)
00269     : InterfaceModifier(ifconfig, ifname), _enabled(enabled) {}
00270 
00271     bool dispatch() {
00272     IfTreeInterface* fi = interface();
00273     if (fi == NULL)
00274         return (false);
00275     fi->set_enabled(_enabled);
00276     return (true);
00277     }
00278 
00279     string str() const {
00280     return c_format("SetInterfaceEnabled: %s %s",
00281             ifname().c_str(), bool_c_str(_enabled));
00282     }
00283 
00284 private:
00285     bool _enabled;
00286 };
00287 
00291 class SetInterfaceDiscard : public InterfaceModifier {
00292 public:
00293     SetInterfaceDiscard(IfConfig&   ifconfig,
00294             const string&   ifname,
00295             bool        discard)
00296     : InterfaceModifier(ifconfig, ifname), _discard(discard) {}
00297 
00298     bool dispatch() {
00299     IfTreeInterface* fi = interface();
00300     if (fi == NULL)
00301         return (false);
00302     fi->set_discard(_discard);
00303     return (true);
00304     }
00305 
00306     string str() const {
00307     return c_format("SetInterfaceDiscard: %s %s",
00308             ifname().c_str(), bool_c_str(_discard));
00309     }
00310 
00311 private:
00312     bool _discard;
00313 };
00314 
00318 class SetInterfaceUnreachable : public InterfaceModifier {
00319 public:
00320     SetInterfaceUnreachable(IfConfig&       ifconfig,
00321                 const string&   ifname,
00322                 bool        unreachable)
00323     : InterfaceModifier(ifconfig, ifname), _unreachable(unreachable) {}
00324 
00325     bool dispatch() {
00326     IfTreeInterface* fi = interface();
00327     if (fi == NULL)
00328         return (false);
00329     fi->set_unreachable(_unreachable);
00330     return (true);
00331     }
00332 
00333     string str() const {
00334     return c_format("SetInterfaceUnreachable: %s %s",
00335             ifname().c_str(), bool_c_str(_unreachable));
00336     }
00337 
00338 private:
00339     bool _unreachable;
00340 };
00341 
00345 class SetInterfaceManagement : public InterfaceModifier {
00346 public:
00347     SetInterfaceManagement(IfConfig&        ifconfig,
00348                const string&    ifname,
00349                bool         management)
00350     : InterfaceModifier(ifconfig, ifname), _management(management) {}
00351 
00352     bool dispatch() {
00353     IfTreeInterface* fi = interface();
00354     if (fi == NULL)
00355         return (false);
00356     fi->set_management(_management);
00357     return (true);
00358     }
00359 
00360     string str() const {
00361     return c_format("SetInterfaceManagement: %s %s",
00362             ifname().c_str(), bool_c_str(_management));
00363     }
00364 
00365 private:
00366     bool _management;
00367 };
00368 
00372 class SetInterfaceMtu : public InterfaceModifier {
00373 public:
00374     SetInterfaceMtu(IfConfig&       ifconfig,
00375             const string&   ifname,
00376             uint32_t        mtu)
00377     : InterfaceModifier(ifconfig, ifname), _mtu(mtu) {}
00378 
00379     // Minimum and maximum MTU (as defined in RFC 791 and RFC 1191)
00380     static const uint32_t MIN_MTU = 68;
00381     static const uint32_t MAX_MTU = 65536;
00382     
00383     bool dispatch() {
00384     IfTreeInterface* fi = interface();
00385     if (fi == NULL)
00386         return (false);
00387 
00388     if (_mtu < MIN_MTU || _mtu > MAX_MTU)
00389         return (false);
00390     
00391     fi->set_mtu(_mtu);
00392     return (true);
00393     }
00394 
00395     string str() const {
00396     string s = c_format("SetInterfaceMtu: %s %u", ifname().c_str(),
00397                 XORP_UINT_CAST(_mtu));
00398     if (_mtu < MIN_MTU || _mtu > MAX_MTU) {
00399         s += c_format(" (valid range %u--%u)",
00400               XORP_UINT_CAST(MIN_MTU), XORP_UINT_CAST(MAX_MTU));
00401     }
00402     return s;
00403     }
00404 
00405 private:
00406     uint32_t _mtu;
00407 };
00408 
00412 class RestoreInterfaceMtu : public InterfaceModifier {
00413 public:
00414     RestoreInterfaceMtu(IfConfig&   ifconfig,
00415             const string&   ifname)
00416     : InterfaceModifier(ifconfig, ifname) {}
00417 
00418     bool dispatch() {
00419     // Get the original MTU
00420     const IfTree& orig_iftree = ifconfig().original_config();
00421     const IfTreeInterface* orig_fi = orig_iftree.find_interface(ifname());
00422     if (orig_fi == NULL)
00423         return (false);
00424     uint32_t orig_mtu = orig_fi->mtu();
00425 
00426     IfTreeInterface* fi = interface();
00427     if (fi == NULL)
00428         return (false);
00429     fi->set_mtu(orig_mtu);
00430     return (true);
00431     }
00432 
00433     string str() const {
00434     return c_format("RestoreInterfaceMtu: %s", ifname().c_str());
00435     }
00436 
00437 private:
00438 };
00439 
00443 class SetInterfaceMac : public InterfaceModifier {
00444 public:
00445     SetInterfaceMac(IfConfig&       ifconfig,
00446             const string&   ifname,
00447             const Mac&      mac)
00448     : InterfaceModifier(ifconfig, ifname), _mac(mac) {}
00449 
00450     bool dispatch() {
00451     IfTreeInterface* fi = interface();
00452     if (fi == NULL)
00453         return (false);
00454     fi->set_mac(_mac);
00455     return (true);
00456     }
00457 
00458     string str() const {
00459     return c_format("SetInterfaceMac: %s %s",
00460             ifname().c_str(), _mac.str().c_str());
00461     }
00462 private:
00463     Mac _mac;
00464 };
00465 
00469 class RestoreInterfaceMac : public InterfaceModifier {
00470 public:
00471     RestoreInterfaceMac(IfConfig&   ifconfig,
00472             const string&   ifname)
00473     : InterfaceModifier(ifconfig, ifname) {}
00474 
00475     bool dispatch() {
00476     // Get the original MAC
00477     const IfTree& orig_iftree = ifconfig().original_config();
00478     const IfTreeInterface* orig_fi = orig_iftree.find_interface(ifname());
00479     if (orig_fi == NULL)
00480         return (false);
00481     const Mac& orig_mac = orig_fi->mac();
00482 
00483     IfTreeInterface* fi = interface();
00484     if (fi == NULL)
00485         return (false);
00486     fi->set_mac(orig_mac);
00487     return (true);
00488     }
00489 
00490     string str() const {
00491     return c_format("RestoreInterfaceMac: %s", ifname().c_str());
00492     }
00493 
00494 private:
00495 };
00496 
00500 class AddInterfaceVif : public InterfaceModifier {
00501 public:
00502     AddInterfaceVif(IfConfig&       ifconfig,
00503             const string&   ifname,
00504             const string&   vifname)
00505     : InterfaceModifier(ifconfig, ifname), _vifname(vifname) {}
00506 
00507     bool dispatch() {
00508     IfTreeInterface* fi = interface();
00509     if (fi == NULL)
00510         return (false);
00511     fi->add_vif(_vifname);
00512     return (true);
00513     }
00514 
00515     string str() const {
00516     return c_format("AddInterfaceVif: %s %s",
00517             ifname().c_str(), _vifname.c_str());
00518     }
00519 
00520 private:
00521     const string _vifname;
00522 };
00523 
00527 class RemoveInterfaceVif : public InterfaceModifier {
00528 public:
00529     RemoveInterfaceVif(IfConfig&    ifconfig,
00530             const string&   ifname,
00531             const string&   vifname)
00532     : InterfaceModifier(ifconfig, ifname), _vifname(vifname) {}
00533 
00534     bool dispatch() {
00535     IfTreeInterface* fi = interface();
00536     if (fi == NULL)
00537         return (false);
00538     if (fi->remove_vif(_vifname) != XORP_OK)
00539         return (false);
00540     return (true);
00541     }
00542 
00543     string str() const {
00544     return c_format("RemoveInterfaceVif: %s %s",
00545             ifname().c_str(), _vifname.c_str());
00546     }
00547 
00548 private:
00549     const string _vifname;
00550 };
00551 
00552 
00556 class SetIfString : public InterfaceModifier {
00557 public:
00558     SetIfString(IfConfig&   ifconfig,
00559         const string&   ifname,
00560         const string&   str,
00561         IfStringTypeE tp)
00562     : InterfaceModifier(ifconfig, ifname),
00563       _str(str),
00564       _tp(tp) {}
00565 
00566     bool dispatch() {
00567     IfTreeInterface* fi = interface();
00568     if (fi == NULL)
00569         return false;
00570     switch (_tp) {
00571     case IF_STRING_PARENT_IFNAME:
00572         fi->set_parent_ifname(_str);
00573         return true;
00574     case IF_STRING_IFTYPE:
00575         fi->set_iface_type(_str);
00576         return true;
00577     case IF_STRING_VID:
00578         fi->set_vid(_str);
00579         return true;
00580     default:
00581         XLOG_ERROR("Unknown string type: %i\n", _tp);
00582         return false;
00583     }
00584     }
00585 
00586     string str() const {
00587     return c_format("SetIfString: %s %s %i",
00588             path().c_str(), _str.c_str(),
00589             _tp);
00590     }
00591 
00592 private:
00593     string _str;
00594     IfStringTypeE _tp;
00595 };
00596 
00597 
00601 class VifModifier : public InterfaceModifier {
00602 public:
00603     VifModifier(IfConfig&   ifconfig,
00604         const string&   ifname,
00605         const string&   vifname)
00606     : InterfaceModifier(ifconfig, ifname), _vifname(vifname) {}
00607 
00608     string path() const {
00609     return InterfaceModifier::path() + string(" ") + vifname();
00610     }
00611 
00612     const string& vifname() const       { return _vifname; }
00613 
00614 protected:
00615     IfTreeVif* vif() {
00616     IfTreeVif* vifp = iftree().find_vif(ifname(), _vifname);
00617     return (vifp);
00618     }
00619 
00620 protected:
00621     const string _vifname;
00622 };
00623 
00627 class SetVifEnabled : public VifModifier {
00628 public:
00629     SetVifEnabled(IfConfig&     ifconfig,
00630           const string& ifname,
00631           const string& vifname,
00632           bool      enabled)
00633     : VifModifier(ifconfig, ifname, vifname), _enabled(enabled) {}
00634 
00635     bool dispatch() {
00636     IfTreeVif* fv = vif();
00637     if (fv == NULL)
00638         return (false);
00639     fv->set_enabled(_enabled);
00640     return (true);
00641     }
00642 
00643     string str() const {
00644     return c_format("SetVifEnabled: %s %s",
00645             path().c_str(), bool_c_str(_enabled));
00646     }
00647 
00648 private:
00649     bool _enabled;
00650 };
00651 
00652 
00656 class AddAddr4 : public VifModifier {
00657 public:
00658     AddAddr4(IfConfig&      ifconfig,
00659          const string&  ifname,
00660          const string&  vifname,
00661          const IPv4&    addr)
00662     : VifModifier(ifconfig, ifname, vifname), _addr(addr) {}
00663 
00664     bool dispatch() {
00665     IfTreeVif* fv = vif();
00666     if (fv == NULL)
00667         return (false);
00668     fv->add_addr(_addr);
00669     return (true);
00670     }
00671 
00672     string str() const {
00673     return c_format("AddAddr4: %s %s",
00674             path().c_str(), _addr.str().c_str());
00675     }
00676 
00677 private:
00678     IPv4 _addr;
00679 };
00680 
00684 class RemoveAddr4 : public VifModifier {
00685 public:
00686     RemoveAddr4(IfConfig&   ifconfig,
00687         const string&   ifname,
00688         const string&   vifname,
00689         const IPv4& addr)
00690     : VifModifier(ifconfig, ifname, vifname), _addr(addr) {}
00691 
00692     bool dispatch() {
00693     IfTreeVif* fv = vif();
00694     if (fv == NULL)
00695         return (false);
00696     if (fv->remove_addr(_addr) != XORP_OK)
00697         return (false);
00698     return (true);
00699     }
00700 
00701     string str() const {
00702     return c_format("RemoveAddr4: %s %s",
00703             path().c_str(), _addr.str().c_str());
00704     }
00705 
00706 private:
00707     IPv4 _addr;
00708 };
00709 
00713 class AddAddr6 : public VifModifier {
00714 public:
00715     AddAddr6(IfConfig&      ifconfig,
00716          const string&  ifname,
00717          const string&  vifname,
00718          const IPv6&    addr)
00719     : VifModifier(ifconfig, ifname, vifname), _addr(addr) {}
00720 
00721     bool dispatch() {
00722     IfTreeVif* fv = vif();
00723     if (fv == NULL)
00724         return (false);
00725     if (fv->add_addr(_addr) != XORP_OK)
00726         return (false);
00727     return (true);
00728     }
00729 
00730     string str() const {
00731     return c_format("AddAddr6: %s %s",
00732             path().c_str(), _addr.str().c_str());
00733     }
00734 
00735 private:
00736     IPv6 _addr;
00737 };
00738 
00742 class RemoveAddr6 : public VifModifier {
00743 public:
00744     RemoveAddr6(IfConfig&   ifconfig,
00745         const string&   ifname,
00746         const string&   vifname,
00747         const IPv6&     addr)
00748     : VifModifier(ifconfig, ifname, vifname), _addr(addr) {}
00749 
00750     bool dispatch() {
00751     IfTreeVif* fv = vif();
00752     if (fv == NULL)
00753         return (false);
00754     if (fv->remove_addr(_addr) != XORP_OK)
00755         return (false);
00756     return (true);
00757     }
00758 
00759     string str() const {
00760     return c_format("RemoveAddr6: %s %s",
00761             path().c_str(), _addr.str().c_str());
00762     }
00763 
00764 private:
00765     IPv6 _addr;
00766 };
00767 
00771 class Addr4Modifier : public VifModifier {
00772 public:
00773     Addr4Modifier(IfConfig&     ifconfig,
00774           const string& ifname,
00775           const string& vifname,
00776           const IPv4&   addr)
00777     : VifModifier(ifconfig, ifname, vifname), _addr(addr) {}
00778 
00779     string path() const {
00780     return VifModifier::path() + string(" ") + _addr.str();
00781     }
00782 
00783 protected:
00784     IfTreeAddr4* addr() {
00785     IfTreeAddr4* ap = iftree().find_addr(ifname(), vifname(), _addr);
00786     return (ap);
00787     }
00788 
00789 protected:
00790     const IPv4 _addr;
00791 };
00792 
00796 class SetAddr4Enabled : public Addr4Modifier {
00797 public:
00798     SetAddr4Enabled(IfConfig&       ifconfig,
00799             const string&   ifname,
00800             const string&   vifname,
00801             const IPv4&     addr,
00802             bool        enabled)
00803     : Addr4Modifier(ifconfig, ifname, vifname, addr), _enabled(enabled) {}
00804 
00805     bool dispatch() {
00806     IfTreeAddr4* fa = addr();
00807     if (fa == NULL)
00808         return (false);
00809     fa->set_enabled(_enabled);
00810     return (true);
00811     }
00812 
00813     string str() const {
00814     return c_format("SetAddr4Enabled: %s %s",
00815             path().c_str(), bool_c_str(_enabled));
00816     }
00817 
00818 protected:
00819     bool _enabled;
00820 };
00821 
00825 class SetAddr4Prefix : public Addr4Modifier {
00826 public:
00827     SetAddr4Prefix(IfConfig&        ifconfig,
00828            const string&    ifname,
00829            const string&    vifname,
00830            const IPv4&      addr,
00831            uint32_t     prefix_len)
00832     : Addr4Modifier(ifconfig, ifname, vifname, addr),
00833       _prefix_len(prefix_len) {}
00834 
00835     static const uint32_t MAX_PREFIX_LEN = 32;
00836     
00837     bool dispatch() {
00838     IfTreeAddr4* fa = addr();
00839     if (fa == NULL || _prefix_len > MAX_PREFIX_LEN)
00840         return (false);
00841     if (fa->set_prefix_len(_prefix_len) != XORP_OK)
00842         return (false);
00843     return (true);
00844     }
00845 
00846     string str() const {
00847     string s = c_format("SetAddr4Prefix: %s %u", path().c_str(),
00848                 XORP_UINT_CAST(_prefix_len));
00849     if (_prefix_len > MAX_PREFIX_LEN)
00850         s += c_format(" (valid range 0--%u)",
00851               XORP_UINT_CAST(MAX_PREFIX_LEN));
00852     return s;
00853     }
00854 
00855 protected:
00856     uint32_t _prefix_len;
00857 };
00858 
00862 class SetAddr4Endpoint : public Addr4Modifier {
00863 public:
00864     SetAddr4Endpoint(IfConfig&      ifconfig,
00865              const string&  ifname,
00866              const string&  vifname,
00867              const IPv4&    addr,
00868              const IPv4&    endpoint)
00869     : Addr4Modifier(ifconfig, ifname, vifname, addr), _endpoint(endpoint) {}
00870 
00871     bool dispatch() {
00872     IfTreeAddr4* fa = addr();
00873     if (fa == NULL)
00874         return (false);
00875     fa->set_endpoint(_endpoint);
00876     fa->set_point_to_point(true);
00877     return (true);
00878     }
00879 
00880     string str() const {
00881     return c_format("SetAddr4Endpoint: %s %s",
00882             path().c_str(), _endpoint.str().c_str());
00883     }
00884 
00885 protected:
00886     IPv4 _endpoint;
00887 };
00888 
00892 class SetAddr4Broadcast : public Addr4Modifier {
00893 public:
00894     SetAddr4Broadcast(IfConfig&     ifconfig,
00895               const string& ifname,
00896               const string& vifname,
00897               const IPv4&   addr,
00898               const IPv4&   bcast)
00899     : Addr4Modifier(ifconfig, ifname, vifname, addr), _bcast(bcast) {}
00900 
00901     bool dispatch() {
00902     IfTreeAddr4* fa = addr();
00903     if (fa == NULL)
00904         return (false);
00905     fa->set_bcast(_bcast);
00906     fa->set_broadcast(true);
00907     return (true);
00908     }
00909 
00910     string str() const {
00911     return c_format("SetAddr4Broadcast: %s %s",
00912             path().c_str(), _bcast.str().c_str());
00913     }
00914 
00915 protected:
00916     IPv4 _bcast;
00917 };
00918 
00922 class Addr6Modifier : public VifModifier {
00923 public:
00924     Addr6Modifier(IfConfig& ifconfig,
00925           const string& ifname,
00926           const string& vifname,
00927           const IPv6&   addr)
00928     : VifModifier(ifconfig, ifname, vifname), _addr(addr) {}
00929 
00930     string path() const {
00931     return VifModifier::path() + string(" ") + _addr.str();
00932     }
00933 
00934 protected:
00935     IfTreeAddr6* addr() {
00936     IfTreeAddr6* ap = iftree().find_addr(ifname(), vifname(), _addr);
00937     return (ap);
00938     }
00939 
00940 protected:
00941     const IPv6 _addr;
00942 };
00943 
00947 class SetAddr6Enabled : public Addr6Modifier {
00948 public:
00949     SetAddr6Enabled(IfConfig&       ifconfig,
00950             const string&   ifname,
00951             const string&   vifname,
00952             const IPv6&     addr,
00953             bool        enabled)
00954     : Addr6Modifier(ifconfig, ifname, vifname, addr), _enabled(enabled) {}
00955 
00956     bool dispatch() {
00957     IfTreeAddr6* fa = addr();
00958     if (fa == NULL)
00959         return (false);
00960     fa->set_enabled(_enabled);
00961     return (true);
00962     }
00963 
00964     string str() const {
00965     return c_format("SetAddr6Enabled: %s %s",
00966             path().c_str(), bool_c_str(_enabled));
00967     }
00968 
00969 protected:
00970     bool _enabled;
00971 };
00972 
00976 class SetAddr6Prefix : public Addr6Modifier {
00977 public:
00978     SetAddr6Prefix(IfConfig&        ifconfig,
00979            const string&    ifname,
00980            const string&    vifname,
00981            const IPv6&      addr,
00982            uint32_t     prefix_len)
00983     : Addr6Modifier(ifconfig, ifname, vifname, addr),
00984       _prefix_len(prefix_len) {}
00985 
00986     static const uint32_t MAX_PREFIX_LEN = 128;
00987     
00988     bool dispatch() {
00989     IfTreeAddr6* fa = addr();
00990     if (fa == NULL || _prefix_len > MAX_PREFIX_LEN)
00991         return (false);
00992     if (fa->set_prefix_len(_prefix_len) != XORP_OK)
00993         return (false);
00994     return (true);
00995     }
00996 
00997     string str() const {
00998     string s = c_format("SetAddr6Prefix: %s %u", path().c_str(),
00999                 XORP_UINT_CAST(_prefix_len));
01000     if (_prefix_len > MAX_PREFIX_LEN)
01001         s += c_format(" (valid range 0--%u)",
01002               XORP_UINT_CAST(MAX_PREFIX_LEN));
01003     return s;
01004     }
01005 
01006 protected:
01007     uint32_t _prefix_len;
01008 };
01009 
01013 class SetAddr6Endpoint : public Addr6Modifier {
01014 public:
01015     SetAddr6Endpoint(IfConfig&      ifconfig,
01016              const string&  ifname,
01017              const string&  vifname,
01018              const IPv6&    addr,
01019              const IPv6&    endpoint)
01020     : Addr6Modifier(ifconfig, ifname, vifname, addr), _endpoint(endpoint) {}
01021 
01022     bool dispatch() {
01023     IfTreeAddr6* fa = addr();
01024     if (fa == NULL)
01025         return (false);
01026     fa->set_endpoint(_endpoint);
01027     fa->set_point_to_point(true);
01028     return (true);
01029     }
01030 
01031     string str() const {
01032     return c_format("SetAddr6Endpoint: %s %s",
01033             path().c_str(), _endpoint.str().c_str());
01034     }
01035 
01036 protected:
01037     IPv6 _endpoint;
01038 };
01039 
01040 #endif // __FEA_IFCONFIG_TRANSACTION_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations