Skip to content
Snippets Groups Projects
Commit 1c6338a6 authored by g0dil's avatar g0dil
Browse files

PPI: Add TargetDgramWriter

Socket: Add up(), down() and isUp() members to NetdeviceController
Utils/Daemon: Fix dup() bug
Utils/Daemon: Dump registered scheduler events on fork() WARNING
parent 1294360f
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,42 @@ ...@@ -30,6 +30,42 @@
#define prefix_ inline #define prefix_ inline
///////////////////////////////cti.p/////////////////////////////////////// ///////////////////////////////cti.p///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// senf::ppi::TargetDgramWriter<HandleType>
template <class HandleType>
prefix_ senf::ppi::TargetDgramWriter<HandleType>::TargetDgramWriter()
{}
template <class HandleType>
prefix_ senf::ppi::TargetDgramWriter<HandleType>::
TargetDgramWriter(typename Handle::Address const & target)
: target_ (target)
{}
template <class HandleType>
prefix_ typename senf::ppi::TargetDgramWriter<HandleType>::Handle::Address
senf::ppi::TargetDgramWriter<HandleType>::target()
const
{
return target_;
}
template <class HandleType>
prefix_ void
senf::ppi::TargetDgramWriter<HandleType>::target(typename Handle::Address const & target)
{
target_ = target;
}
template <class HandleType>
prefix_ void senf::ppi::TargetDgramWriter<HandleType>::operator()(Handle handle,
Packet const & packet)
{
if (target_)
handle.writeto(target_, packet.data());
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// senf::ppi::module::ActiveSocketSink<Writer> // senf::ppi::module::ActiveSocketSink<Writer>
......
...@@ -65,6 +65,24 @@ namespace ppi { ...@@ -65,6 +65,24 @@ namespace ppi {
\param[in] packet Packet to write */ \param[in] packet Packet to write */
}; };
template <class HandleType>
class TargetDgramWriter
{
public:
typedef HandleType Handle;
TargetDgramWriter();
TargetDgramWriter(typename Handle::Address const & target);
typename Handle::Address target() const;
void target(typename Handle::Address const & target);
void operator()(Handle handle, Packet const & packet);
private:
typename Handle::Address target_;
};
class IPv4SourceForcingDgramWriter : ConnectedDgramWriter class IPv4SourceForcingDgramWriter : ConnectedDgramWriter
{ {
public: public:
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
prefix_ senf::scheduler::detail::EventManager::EventManager() prefix_ senf::scheduler::detail::EventManager::EventManager()
{ {
#ifndef SENF_DISABLE_CONSOLE #ifndef SENF_DISABLE_CONSOLE
consoleDir_().add("events", senf::membind(&EventManager::consoleEvents, this)) consoleDir_().add("events", senf::membind(&EventManager::listEvents, this))
.doc("List all scheduler events sorted by priority\n" .doc("List all scheduler events sorted by priority\n"
"\n" "\n"
"Columns:\n" "Columns:\n"
...@@ -61,7 +61,7 @@ prefix_ senf::scheduler::detail::EventManager::EventManager() ...@@ -61,7 +61,7 @@ prefix_ senf::scheduler::detail::EventManager::EventManager()
#endif #endif
} }
prefix_ void senf::scheduler::detail::EventManager::consoleEvents(std::ostream & os) prefix_ void senf::scheduler::detail::EventManager::listEvents(std::ostream & os)
{ {
// On an 80 column display, this wraps nicely directly before the INFO column // On an 80 column display, this wraps nicely directly before the INFO column
boost::format fmt ("%s %-55.55s 0x%08x %8d %s %s\n"); boost::format fmt ("%s %-55.55s 0x%08x %8d %s %s\n");
......
...@@ -105,6 +105,8 @@ namespace detail { ...@@ -105,6 +105,8 @@ namespace detail {
iterator begin() const; iterator begin() const;
iterator end() const; iterator end() const;
void listEvents(std::ostream & os);
protected: protected:
private: private:
...@@ -115,8 +117,6 @@ namespace detail { ...@@ -115,8 +117,6 @@ namespace detail {
friend class singleton<EventManager>; friend class singleton<EventManager>;
#ifndef SENF_DISABLE_CONSOLE #ifndef SENF_DISABLE_CONSOLE
void consoleEvents(std::ostream & os);
console::LazyDirectory consoleDir_; console::LazyDirectory consoleDir_;
#endif #endif
}; };
......
...@@ -136,6 +136,33 @@ prefix_ void senf::NetdeviceController::promisc(bool mode) ...@@ -136,6 +136,33 @@ prefix_ void senf::NetdeviceController::promisc(bool mode)
doIoctl( ifr, SIOCSIFFLAGS); doIoctl( ifr, SIOCSIFFLAGS);
} }
prefix_ bool senf::NetdeviceController::isUp()
const
{
struct ifreq ifr;
ifrName(ifr);
doIoctl(ifr, SIOCGIFFLAGS);
return ifr.ifr_flags & IFF_UP;
}
prefix_ void senf::NetdeviceController::up()
{
struct ifreq ifr;
ifrName(ifr);
doIoctl(ifr, SIOCGIFFLAGS);
ifr.ifr_flags |= IFF_UP;
doIoctl(ifr, SIOCSIFFLAGS);
}
prefix_ void senf::NetdeviceController::down()
{
struct ifreq ifr;
ifrName(ifr);
doIoctl(ifr, SIOCGIFFLAGS);
ifr.ifr_flags &= ~IFF_UP;
doIoctl(ifr, SIOCSIFFLAGS);
}
prefix_ int senf::NetdeviceController::interfaceIndex() prefix_ int senf::NetdeviceController::interfaceIndex()
const const
{ {
......
...@@ -84,7 +84,11 @@ namespace senf { ...@@ -84,7 +84,11 @@ namespace senf {
bool promisc() const; ///< return \c true if interface is in promiscuous mode bool promisc() const; ///< return \c true if interface is in promiscuous mode
void promisc(bool mode); ///< enable/disable promiscuous mode of the interface void promisc(bool mode); ///< enable/disable promiscuous mode of the interface
/**< Note, that this is a privileged operation. */ /**< Note, that this is a privileged operation. */
bool isUp() const; ///< return \c true if interface is up
void up(); ///< ifconfig up interface
void down(); ///< ifconfig down interface
private: private:
void openSocket(); void openSocket();
void doIoctl(ifreq& ifr, int request) const; void doIoctl(ifreq& ifr, int request) const;
......
...@@ -132,17 +132,19 @@ prefix_ void senf::Daemon::openLog() ...@@ -132,17 +132,19 @@ prefix_ void senf::Daemon::openLog()
<< " Could not open \"" << stdoutLog_ << "\" for redirecting stdout."; << " Could not open \"" << stdoutLog_ << "\" for redirecting stdout.";
stdout_ = fd; stdout_ = fd;
} }
if (stderrLog_ == stdoutLog_) { if (! stderrLog_.empty()) {
stderr_ = ::dup(fd); if (stderrLog_ == stdoutLog_) {
if (stderr_ < 0) stderr_ = ::dup(fd);
SENF_THROW_SYSTEM_EXCEPTION("::dup()"); if (stderr_ < 0)
} SENF_THROW_SYSTEM_EXCEPTION("::dup()");
else if (! stderrLog_.empty()) { }
fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666); else {
if (fd < 0) fd = ::open(stdoutLog_.c_str(), O_WRONLY | O_APPEND | O_CREAT, 0666);
SENF_THROW_SYSTEM_EXCEPTION("") if (fd < 0)
<< " Could not open \"" << stderrLog_ << "\" for redirecting stderr."; SENF_THROW_SYSTEM_EXCEPTION("")
stderr_ = fd; << " Could not open \"" << stderrLog_ << "\" for redirecting stderr.";
stderr_ = fd;
}
} }
} }
...@@ -369,14 +371,17 @@ prefix_ void senf::Daemon::fork() ...@@ -369,14 +371,17 @@ prefix_ void senf::Daemon::fork()
LIBC_CALL( ::sigaddset, (&cldsig, SIGCHLD) ); LIBC_CALL( ::sigaddset, (&cldsig, SIGCHLD) );
LIBC_CALL( ::sigprocmask, (SIG_BLOCK, &cldsig, &oldsig) ); LIBC_CALL( ::sigprocmask, (SIG_BLOCK, &cldsig, &oldsig) );
if (! senf::scheduler::empty() ) if (! senf::scheduler::empty() ) {
std::cerr << std::cerr <<
"\n" "\n"
"*** WARNING ***\n" "*** WARNING ***\n"
"Scheduler not empty before fork(). THIS MUST NOT HAPPEN.\n" "Scheduler not empty before fork(). THIS MUST NOT HAPPEN.\n"
"The scheduler will be reinitialized by the fork() and lose all registrations.\n" "The scheduler will be reinitialized by the fork() and lose all registrations.\n\n";
"*** WARNING ***\n" senf::scheduler::detail::EventManager::instance().listEvents(std::cerr);
std::cerr <<
"\n*** WARNING ***\n"
"\n"; "\n";
}
LIBC_CALL_RV( pid, ::fork, () ); LIBC_CALL_RV( pid, ::fork, () );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment