Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not wait network to be available #783

Open
wants to merge 2 commits into
base: network
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void CConfig::Load (void)
m_INetworkIPAddress = m_Properties.GetIPAddress("NetworkIPAddress") != 0;
m_INetworkSubnetMask = m_Properties.GetIPAddress("NetworkSubnetMask") != 0;
m_INetworkDefaultGateway = m_Properties.GetIPAddress("NetworkDefaultGateway") != 0;
m_bSyslogEnabled = m_Properties.GetNumber ("SyslogEnabled", 0) != 0;
m_INetworkDNSServer = m_Properties.GetIPAddress("NetworkDNSServer") != 0;

const u8 *pSyslogServerIP = m_Properties.GetIPAddress ("NetworkSyslogServerIPAddress");
Expand Down Expand Up @@ -774,6 +775,11 @@ CIPAddress CConfig::GetNetworkDNSServer (void) const
return m_INetworkDNSServer;
}

bool CConfig::GetSyslogEnabled (void) const
{
return m_bSyslogEnabled;
}

CIPAddress CConfig::GetNetworkSyslogServerIPAddress (void) const
{
return m_INetworkSyslogServerIPAddress;
Expand Down
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class CConfig // Configuration for MiniDexed
CIPAddress GetNetworkSubnetMask (void) const;
CIPAddress GetNetworkDefaultGateway (void) const;
CIPAddress GetNetworkDNSServer (void) const;
bool GetSyslogEnabled (void) const;
CIPAddress GetNetworkSyslogServerIPAddress (void) const;

private:
Expand Down Expand Up @@ -373,6 +374,7 @@ class CConfig // Configuration for MiniDexed
CIPAddress m_INetworkSubnetMask;
CIPAddress m_INetworkDefaultGateway;
CIPAddress m_INetworkDNSServer;
bool m_bSyslogEnabled;
CIPAddress m_INetworkSyslogServerIPAddress;
};

Expand Down
56 changes: 30 additions & 26 deletions src/minidexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ bool CMiniDexed::Initialize (void)
return false;
}
#endif
InitNetwork();
InitNetwork(); // returns bool but we continue even if something goes wrong

return true;
}
Expand Down Expand Up @@ -2201,15 +2201,13 @@ void CMiniDexed::UpdateNetwork()
if (!m_pNet)
return;

//add wired network check as well
//add wired network check as well
bool bNetIsRunning = m_pNet->IsRunning();
if (m_pNetDevice->GetType() == NetDeviceTypeEthernet)
bNetIsRunning &= m_pNetDevice->IsLinkUp();
else if (m_pNetDevice->GetType() == NetDeviceTypeWLAN)
bNetIsRunning &= m_WPASupplicant.IsConnected();

if (!m_bNetworkInit)
if (!m_bNetworkInit && bNetIsRunning)
{
m_bNetworkInit = true;
CString IPString;
Expand Down Expand Up @@ -2248,7 +2246,21 @@ void CMiniDexed::UpdateNetwork()
{
LOGPANIC ("Cannot publish mdns service");
}

// syslog configuration
if (m_pConfig->GetSyslogEnabled())
{
CIPAddress ServerIP = m_pConfig->GetNetworkSyslogServerIPAddress();
if (ServerIP.IsSet () && !ServerIP.IsNull ())
{
static const u16 usServerPort = 8514; // standard port is 514
CString IPString;
ServerIP.Format (&IPString);
LOGNOTE ("Sending log messages to syslog server %s:%u",
(const char *) IPString, (unsigned) usServerPort);

new CSysLogDaemon (m_pNet, ServerIP, usServerPort);
}
}
m_bNetworkReady = true;
}

Expand Down Expand Up @@ -2290,15 +2302,14 @@ bool CMiniDexed::InitNetwork()
if (m_pConfig->GetNetworkEnabled () && (strcmp(m_pConfig->GetNetworkType(), "wifi") == 0))
{
LOGNOTE("Initializing WLAN");

if (m_WLAN.Initialize() && m_WPASupplicant.Initialize())
NetDeviceType = NetDeviceTypeWLAN;
if (m_WLAN.Initialize())
{
LOGNOTE("wlan and wpasupplicant initialized");
NetDeviceType = NetDeviceTypeWLAN;

LOGNOTE("WLAN initialized");
}
else
LOGERR("Failed to initialize WLAN");
LOGERR("Failed to initialize WLAN, maybe firmware files are missing?");
return false;
}
else if (m_pConfig->GetNetworkEnabled () && (strcmp(m_pConfig->GetNetworkType(), "ethernet") == 0))
{
Expand All @@ -2319,29 +2330,22 @@ bool CMiniDexed::InitNetwork()
m_pConfig->GetNetworkHostname(),
NetDeviceType
);

if (!m_pNet->Initialize())
if (!m_pNet->Initialize(false))
{
LOGERR("Failed to initialize network subsystem");
delete m_pNet;
m_pNet = nullptr;
}

m_pNetDevice = CNetDevice::GetNetDevice(NetDeviceType);

// syslog configuration
CIPAddress ServerIP = m_pConfig->GetNetworkSyslogServerIPAddress();
if (ServerIP.IsSet () && !ServerIP.IsNull ())
// WPASupplicant needs to be started after netdevice available
if (NetDeviceType == NetDeviceTypeWLAN)
{
static const u16 usServerPort = 8514; // standard port is 514
CString IPString;
ServerIP.Format (&IPString);
LOGNOTE ("Sending log messages to syslog server %s:%u",
(const char *) IPString, (unsigned) usServerPort);

new CSysLogDaemon (m_pNet, ServerIP, usServerPort);
if (!m_WPASupplicant.Initialize()) {
// It seems no way to catch if config is missing unless circle provides it
// or we catch the faults in config file ourselves
LOGERR("Failed to initialize WPASupplicant, maybe wifi config is missing?");
}
}

}
return m_pNet != nullptr;
}