Register/UnregisterInterface() are now private.
Moved report code into its own class. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4106 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "KPPPStateMachine.h"
|
||||
#include "KPPPLCP.h"
|
||||
#include "KPPPReport.h"
|
||||
#include "KPPPReportManager.h"
|
||||
|
||||
#include "List.h"
|
||||
#include "LockerHelper.h"
|
||||
@@ -40,10 +40,6 @@ class PPPInterface {
|
||||
PPPLCP& LCP() const
|
||||
{ return fLCP; }
|
||||
|
||||
bool RegisterInterface();
|
||||
// adds us to the manager module and
|
||||
// saves the returned ifnet structure
|
||||
bool UnregisterInterface();
|
||||
ifnet *Ifnet() const
|
||||
{ return fIfnet; }
|
||||
|
||||
@@ -105,11 +101,8 @@ class PPPInterface {
|
||||
bool Down();
|
||||
bool IsUp() const;
|
||||
|
||||
void EnableReports(PPP_REPORT_TYPE type, thread_id thread,
|
||||
int32 flags = PPP_NO_REPORT_FLAGS);
|
||||
void DisableReports(PPP_REPORT_TYPE type, thread_id thread);
|
||||
bool DoesReport(PPP_REPORT_TYPE type, thread_id thread);
|
||||
bool Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 length);
|
||||
bool Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 length)
|
||||
{ fReportManager.Report(type, code, data, length); }
|
||||
// returns false if reply was bad (or an error occured)
|
||||
|
||||
bool LoadModules(const driver_settings *settings,
|
||||
@@ -126,6 +119,11 @@ class PPPInterface {
|
||||
// SendToDevice()!
|
||||
|
||||
private:
|
||||
bool RegisterInterface();
|
||||
// adds us to the manager module and
|
||||
// saves the returned ifnet structure
|
||||
bool UnregisterInterface();
|
||||
|
||||
void CalculateMRU();
|
||||
|
||||
// multilink methods
|
||||
@@ -136,6 +134,7 @@ class PPPInterface {
|
||||
driver_parameter *fSettings;
|
||||
PPPStateMachine fStateMachine;
|
||||
PPPLCP fLCP;
|
||||
PPPReportManager fReportManager;
|
||||
ifnet *fIfnet;
|
||||
|
||||
ppp_manager_info *fManager;
|
||||
@@ -156,7 +155,6 @@ class PPPInterface {
|
||||
PPPEncapsulator *fFirstEncapsulator;
|
||||
List<PPPProtocol*> fProtocols;
|
||||
List<ppp_module_info*> fModules;
|
||||
List<ppp_report_request> fReportRequests;
|
||||
|
||||
BLocker& fLock;
|
||||
};
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
#ifndef _K_PPP_REPORT__H
|
||||
#define _K_PPP_REPORT__H
|
||||
#ifndef _K_PPP_REPORT_DEFS__H
|
||||
#define _K_PPP_REPORT_DEFS__H
|
||||
|
||||
#define PPP_REPORT_DATA_LIMIT 128
|
||||
// how much optional data can be added to the report
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef _K_PPP_REPORT_MANAGER__H
|
||||
#define _K_PPP_REPORT_MANAGER__H
|
||||
|
||||
#include "KPPPReportDefs.h"
|
||||
|
||||
#include "List.h"
|
||||
#include "LockerHelper.h"
|
||||
|
||||
|
||||
class PPPReportManager {
|
||||
public:
|
||||
PPPReportManager(BLocker& lock);
|
||||
|
||||
void EnableReports(PPP_REPORT_TYPE type, thread_id thread,
|
||||
int32 flags = PPP_NO_REPORT_FLAGS);
|
||||
void DisableReports(PPP_REPORT_TYPE type, thread_id thread);
|
||||
bool DoesReport(PPP_REPORT_TYPE type, thread_id thread);
|
||||
bool Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 length);
|
||||
// returns false if reply was bad (or an error occured)
|
||||
|
||||
private:
|
||||
BLocker& fLock;
|
||||
List<ppp_report_request> fReportRequests;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -25,9 +25,9 @@
|
||||
|
||||
PPPInterface::PPPInterface(driver_settings *settings, PPPInterface *parent = NULL)
|
||||
: fSettings(dup_driver_settings(settings)),
|
||||
StateMachine(*this), LCP(*this), fIfnet(NULL), fLinkMTU(1500),
|
||||
fAccessing(0), fChildrenCount(0), fDevice(NULL), fFirstEncapsulator(NULL),
|
||||
fLock(StateMachine().Locker())
|
||||
fStateMachine(*this), fLCP(*this), fReportManager(StateMachine().Locker()),
|
||||
fIfnet(NULL), fLinkMTU(1500), fAccessing(0), fChildrenCount(0),
|
||||
fDevice(NULL), fFirstEncapsulator(NULL), fLock(StateMachine().Locker())
|
||||
{
|
||||
if(get_module(PPP_MANAGER_MODULE_NAME, (module_info**) &fManager) != B_OK)
|
||||
fManager = NULL;
|
||||
@@ -119,54 +119,6 @@ PPPInterface::InitCheck() const
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPInterface::RegisterInterface()
|
||||
{
|
||||
if(fIfnet)
|
||||
return true;
|
||||
// we are already registered
|
||||
|
||||
if(!InitCheck())
|
||||
return false;
|
||||
// we cannot register if something is wrong
|
||||
|
||||
// only MainInterfaces get an ifnet
|
||||
if(IsMultilink() && Parent() && Parent()->RegisterInterface())
|
||||
return true;
|
||||
|
||||
if(!fManager)
|
||||
return false;
|
||||
|
||||
fIfnet = fManager->add_interface(this);
|
||||
|
||||
if(!fIfnet)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPInterface::UnregisterInterface()
|
||||
{
|
||||
if(!fIfnet)
|
||||
return true;
|
||||
// we are already unregistered
|
||||
|
||||
// only MainInterfaces get an ifnet
|
||||
if(IsMultilink() && Parent())
|
||||
return true;
|
||||
|
||||
if(!fManager)
|
||||
return false;
|
||||
|
||||
fManager->remove_interface(this);
|
||||
fIfnet = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPInterface::SetLinkMTU(uint32 linkMTU)
|
||||
{
|
||||
@@ -509,107 +461,6 @@ PPPInterface::IsUp() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPInterface::EnableReports(PPP_REPORT_TYPE type, thread_id thread,
|
||||
int32 flags = PPP_NO_REPORT_FLAGS)
|
||||
{
|
||||
LockerHelper locker(fLock);
|
||||
|
||||
ppp_report_request request;
|
||||
request.type = type;
|
||||
request.thread = thread;
|
||||
request.flags = flags;
|
||||
|
||||
fReportRequests.AddItem(request);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPInterface::DisableReports(PPP_REPORT_TYPE type, thread_id thread)
|
||||
{
|
||||
LockerHelper locker(fLock);
|
||||
|
||||
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
|
||||
ppp_report_request& request = fReportRequests.ItemAt(i);
|
||||
|
||||
if(request.thread != thread)
|
||||
continue;
|
||||
|
||||
if(report.type == type)
|
||||
fReportRequest.RemoveItem(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPInterface::DoesReport(PPP_REPORT_TYPE type, thread_id thread)
|
||||
{
|
||||
LockerHelper locker(fLock);
|
||||
|
||||
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
|
||||
ppp_report_request& request = fReportRequests.ItemAt(i);
|
||||
|
||||
if(request.thread == thread && request.type == type)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPInterface::Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 length)
|
||||
{
|
||||
if(length > PPP_REPORT_DATA_LIMIT)
|
||||
return false;
|
||||
|
||||
if(fReportRequests.CountItems() == 0)
|
||||
return true;
|
||||
|
||||
if(!data)
|
||||
length = 0;
|
||||
|
||||
LockerHelper locker(fLock);
|
||||
|
||||
int32 code, query, result;
|
||||
thread_id sender;
|
||||
bool acceptable = true;
|
||||
|
||||
report_packet report;
|
||||
report.type = type;
|
||||
report.code = code;
|
||||
report.length = length;
|
||||
memcpy(report.data, data, length);
|
||||
|
||||
for(int32 index = 0; index < fReportRequests.CountItems(); index++) {
|
||||
ppp_report_request& request = fReportRequests.ItemAt(index);
|
||||
|
||||
result = send_data_with_timeout(request.port, PPP_REPORT_CODE, &report,
|
||||
sizeof(report), PPP_REPORT_TIMEOUT);
|
||||
|
||||
if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY) {
|
||||
fReportRequests.RemoveItem(request);
|
||||
--index;
|
||||
continue;
|
||||
} else if(result == B_OK) {
|
||||
if(request.flags & PPP_WAIT_FOR_REPLY) {
|
||||
result = receive_data_with_timeout(fPort, &code, NULL, 0,
|
||||
PPP_REPORT_TIMEOUT);
|
||||
if(result == B_OK && code != B_OK)
|
||||
successful = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(request.flags & PPP_REMOVE_AFTER_REPORT) {
|
||||
fReportRequests.RemoveItem(request);
|
||||
--index;
|
||||
}
|
||||
}
|
||||
|
||||
return acceptable;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPInterface::LoadModules(const driver_settings *settings,
|
||||
int32 start, int32 count)
|
||||
@@ -927,6 +778,54 @@ PPPInterface::ReceiveFromDevice(mbuf *packet)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPInterface::RegisterInterface()
|
||||
{
|
||||
if(fIfnet)
|
||||
return true;
|
||||
// we are already registered
|
||||
|
||||
if(!InitCheck())
|
||||
return false;
|
||||
// we cannot register if something is wrong
|
||||
|
||||
// only MainInterfaces get an ifnet
|
||||
if(IsMultilink() && Parent() && Parent()->RegisterInterface())
|
||||
return true;
|
||||
|
||||
if(!fManager)
|
||||
return false;
|
||||
|
||||
fIfnet = fManager->add_interface(this);
|
||||
|
||||
if(!fIfnet)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPInterface::UnregisterInterface()
|
||||
{
|
||||
if(!fIfnet)
|
||||
return true;
|
||||
// we are already unregistered
|
||||
|
||||
// only MainInterfaces get an ifnet
|
||||
if(IsMultilink() && Parent())
|
||||
return true;
|
||||
|
||||
if(!fManager)
|
||||
return false;
|
||||
|
||||
fManager->remove_interface(this);
|
||||
fIfnet = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPInterface::CalculateMRU()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
#include "KPPPReportManager.h"
|
||||
|
||||
|
||||
PPPReportManager::PPPReportManager(BLocker& lock)
|
||||
: fLock(lock)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPReportManager::EnableReports(PPP_REPORT_TYPE type, thread_id thread,
|
||||
int32 flags = PPP_NO_REPORT_FLAGS)
|
||||
{
|
||||
LockerHelper locker(fLock);
|
||||
|
||||
ppp_report_request request;
|
||||
request.type = type;
|
||||
request.thread = thread;
|
||||
request.flags = flags;
|
||||
|
||||
fReportRequests.AddItem(request);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PPPReportManager::DisableReports(PPP_REPORT_TYPE type, thread_id thread)
|
||||
{
|
||||
LockerHelper locker(fLock);
|
||||
|
||||
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
|
||||
ppp_report_request& request = fReportRequests.ItemAt(i);
|
||||
|
||||
if(request.thread != thread)
|
||||
continue;
|
||||
|
||||
if(report.type == type)
|
||||
fReportRequest.RemoveItem(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPReportManager::DoesReport(PPP_REPORT_TYPE type, thread_id thread)
|
||||
{
|
||||
LockerHelper locker(fLock);
|
||||
|
||||
for(int32 i = 0; i < fReportRequests.CountItems(); i++) {
|
||||
ppp_report_request& request = fReportRequests.ItemAt(i);
|
||||
|
||||
if(request.thread == thread && request.type == type)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PPPReportManager::Report(PPP_REPORT_TYPE type, int32 code, void *data, int32 length)
|
||||
{
|
||||
if(length > PPP_REPORT_DATA_LIMIT)
|
||||
return false;
|
||||
|
||||
if(fReportRequests.CountItems() == 0)
|
||||
return true;
|
||||
|
||||
if(!data)
|
||||
length = 0;
|
||||
|
||||
LockerHelper locker(fLock);
|
||||
|
||||
int32 code, query, result;
|
||||
thread_id sender;
|
||||
bool acceptable = true;
|
||||
|
||||
report_packet report;
|
||||
report.type = type;
|
||||
report.code = code;
|
||||
report.length = length;
|
||||
memcpy(report.data, data, length);
|
||||
|
||||
for(int32 index = 0; index < fReportRequests.CountItems(); index++) {
|
||||
ppp_report_request& request = fReportRequests.ItemAt(index);
|
||||
|
||||
result = send_data_with_timeout(request.port, PPP_REPORT_CODE, &report,
|
||||
sizeof(report), PPP_REPORT_TIMEOUT);
|
||||
|
||||
if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY) {
|
||||
fReportRequests.RemoveItem(request);
|
||||
--index;
|
||||
continue;
|
||||
} else if(result == B_OK) {
|
||||
if(request.flags & PPP_WAIT_FOR_REPLY) {
|
||||
result = receive_data_with_timeout(fPort, &code, NULL, 0,
|
||||
PPP_REPORT_TIMEOUT);
|
||||
if(result == B_OK && code != B_OK)
|
||||
successful = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(request.flags & PPP_REMOVE_AFTER_REPORT) {
|
||||
fReportRequests.RemoveItem(request);
|
||||
--index;
|
||||
}
|
||||
}
|
||||
|
||||
return acceptable;
|
||||
}
|
||||
@@ -624,9 +624,9 @@ PPPStateMachine::RCRGoodEvent(mbuf *packet)
|
||||
NewPhase(PPP_ESTABLISHMENT_PHASE);
|
||||
// tell handlers that we are reconfiguring
|
||||
locker.UnlockNow();
|
||||
ThisLayerDown();
|
||||
SendConfigureRequest();
|
||||
SendConfigureAck(packet);
|
||||
ThisLayerDown();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user