diff --git a/src/add-ons/kernel/network/interfaces/ppp/PPPManager.cpp b/src/add-ons/kernel/network/interfaces/ppp/PPPManager.cpp index c23275bd97..75a01d4de3 100644 --- a/src/add-ons/kernel/network/interfaces/ppp/PPPManager.cpp +++ b/src/add-ons/kernel/network/interfaces/ppp/PPPManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -19,7 +19,7 @@ #include -static const char sKPPPIfNameBase[] = "ppp"; +static const char sKPPPIfNameBase[] = "ppp"; static @@ -87,16 +87,6 @@ PPPManager::~PPPManager() } } - // also delete all ppp_up references - ppp_app_entry *app = NULL; - for(int32 index = 0; index < fApps.CountItems(); index++) { - app = fApps.ItemAt(index); - if(app) { - free(app->interfaceName); - delete app; - } - } - free(fDefaultInterface); } @@ -242,7 +232,7 @@ PPPManager::DeleteInterface(ppp_interface_id ID) if(entry->deleting) return true; - // this check prevents a dead-lock + // this prevents an endless loop between Delete() and interface->Down() entry->deleting = true; atomic_add(&entry->accessing, 1); @@ -695,23 +685,6 @@ PPPManager::EntryFor(const driver_settings *settings) const } -ppp_app_entry* -PPPManager::AppFor(const char *name) const -{ - if(!name) - return NULL; - - ppp_app_entry *app; - for(int32 index = 0; index < fApps.CountItems(); index++) { - app = fApps.ItemAt(index); - if(app && !strcmp(app->interfaceName, name)) - return app; - } - - return NULL; -} - - void PPPManager::SettingsChanged() { @@ -794,26 +767,8 @@ PPPManager::_CreateInterface(const char *name, return PPP_UNDEFINED_INTERFACE_ID; } - // find an existing ppp_up entry or create a new one otherwise - if(entry->name) { - ppp_app_entry *app = AppFor(entry->name); - thread_info info; - if(!app || get_thread_info(app->thread, &info) != B_OK) { - if(!app) { - app = new ppp_app_entry; - app->interfaceName = strdup(entry->name); - fApps.AddItem(app); - } - - // run new ppp_up instance - const char *argv[] = { "/boot/beos/bin/ppp_up", entry->name, NULL }; - const char *env[] = { NULL }; - app->thread = load_image(2, argv, env); - if(app->thread < 0) - ERROR("KPPPInterface::Up(): Error: could not load ppp_up!\n"); - resume_thread(app->thread); - } - } else + // hidden/child interfaces should never bother the user + if(!entry->name) entry->interface->SetAskBeforeConnecting(false); locker.UnlockNow(); @@ -890,19 +845,6 @@ PPPManager::DeleterThreadEvent() delete entry; } } - - // remove dead ppp_up entries - ppp_app_entry *app; - thread_info info; - for(int32 index = 0; index < fApps.CountItems(); index++) { - app = fApps.ItemAt(index); - if(app && get_thread_info(app->thread, &info) != B_OK) { - fApps.RemoveItem(index); - --index; - free(app->interfaceName); - delete app; - } - } } diff --git a/src/add-ons/kernel/network/interfaces/ppp/PPPManager.h b/src/add-ons/kernel/network/interfaces/ppp/PPPManager.h index 02051d2557..84c578e611 100644 --- a/src/add-ons/kernel/network/interfaces/ppp/PPPManager.h +++ b/src/add-ons/kernel/network/interfaces/ppp/PPPManager.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -11,13 +11,6 @@ #include -// used to identify a ppp_up instance -typedef struct ppp_app_entry { - char *interfaceName; - thread_id thread; -} ppp_app_entry; - - // these functions are defined in ppp.cpp extern int ppp_ifnet_stop(ifnet *ifp); extern int ppp_ifnet_output(ifnet *ifp, struct mbuf *buf, struct sockaddr *dst, @@ -65,7 +58,6 @@ class PPPManager { ppp_interface_entry *EntryFor(ifnet *ifp, int32 *saveIndex = NULL) const; ppp_interface_entry *EntryFor(const char *name, int32 *saveIndex = NULL) const; ppp_interface_entry *EntryFor(const driver_settings *settings) const; - ppp_app_entry *AppFor(const char *name) const; void SettingsChanged(); @@ -85,7 +77,6 @@ class PPPManager { char *fDefaultInterface; KPPPReportManager fReportManager; TemplateList fEntries; - TemplateList fApps; ppp_interface_id fNextID; thread_id fDeleterThread, fPulseTimer; }; diff --git a/src/add-ons/kernel/network/interfaces/ppp/ppp.cpp b/src/add-ons/kernel/network/interfaces/ppp/ppp.cpp index 1f947787f6..6a1548d7c4 100644 --- a/src/add-ons/kernel/network/interfaces/ppp/ppp.cpp +++ b/src/add-ons/kernel/network/interfaces/ppp/ppp.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ diff --git a/src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp b/src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp index 07c6a976b6..71054406e0 100644 --- a/src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp +++ b/src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -13,8 +13,6 @@ #include #include -#include - #include #include #include @@ -72,8 +70,7 @@ IPCP::IPCP(KPPPInterface& interface, driver_parameter *settings) fMaxNak(5), fRequestID(0), fTerminateID(0), - fNextTimeout(0), - fLock("IPCP") + fNextTimeout(0) { // reset configurations memset(&fLocalConfiguration, 0, sizeof(ipcp_configuration)); @@ -151,13 +148,10 @@ IPCP::Up() if(Interface().Mode() == PPP_SERVER_MODE) return true; - LockerHelper locker(fLock); - switch(State()) { case PPP_INITIAL_STATE: NewState(PPP_REQ_SENT_STATE); InitializeRestartCount(); - locker.UnlockNow(); SendConfigureRequest(); break; @@ -174,13 +168,10 @@ IPCP::Down() { TRACE("IPCP: Down() state=%d\n", State()); - LockerHelper locker(fLock); - switch(Interface().Phase()) { case PPP_DOWN_PHASE: // interface finished terminating NewState(PPP_INITIAL_STATE); - locker.UnlockNow(); ReportDownEvent(); // this will also reset and update addresses break; @@ -198,7 +189,6 @@ IPCP::Down() if(State() != PPP_INITIAL_STATE && State() != PPP_CLOSING_STATE) { NewState(PPP_CLOSING_STATE); InitializeRestartCount(); - locker.UnlockNow(); SendTerminateRequest(); } @@ -325,11 +315,9 @@ IPCP::ReceiveIPPacket(struct mbuf *packet, uint16 protocolNumber) void IPCP::Pulse() { - LockerHelper locker(fLock); if(fNextTimeout == 0 || fNextTimeout > system_time()) return; fNextTimeout = 0; - locker.UnlockNow(); switch(State()) { case PPP_CLOSING_STATE: @@ -539,11 +527,8 @@ IPCP::TOGoodEvent() printf("IPCP: TOGoodEvent() state=%d\n", State()); #endif - LockerHelper locker(fLock); - switch(State()) { case PPP_CLOSING_STATE: - locker.UnlockNow(); SendTerminateRequest(); break; @@ -552,7 +537,6 @@ printf("IPCP: TOGoodEvent() state=%d\n", State()); case PPP_REQ_SENT_STATE: case PPP_ACK_SENT_STATE: - locker.UnlockNow(); SendConfigureRequest(); break; @@ -567,12 +551,9 @@ IPCP::TOBadEvent() { TRACE("IPCP: TOBadEvent() state=%d\n", State()); - LockerHelper locker(fLock); - switch(State()) { case PPP_CLOSING_STATE: NewState(PPP_INITIAL_STATE); - locker.UnlockNow(); ReportDownEvent(); break; @@ -580,7 +561,6 @@ IPCP::TOBadEvent() case PPP_ACK_RCVD_STATE: case PPP_ACK_SENT_STATE: NewState(PPP_INITIAL_STATE); - locker.UnlockNow(); ReportUpFailedEvent(); break; @@ -701,13 +681,10 @@ IPCP::RCRGoodEvent(struct mbuf *packet) { TRACE("IPCP: RCRGoodEvent() state=%d\n", State()); - LockerHelper locker(fLock); - switch(State()) { case PPP_INITIAL_STATE: NewState(PPP_ACK_SENT_STATE); InitializeRestartCount(); - locker.UnlockNow(); SendConfigureRequest(); SendConfigureAck(packet); break; @@ -716,20 +693,17 @@ IPCP::RCRGoodEvent(struct mbuf *packet) NewState(PPP_ACK_SENT_STATE); case PPP_ACK_SENT_STATE: - locker.UnlockNow(); SendConfigureAck(packet); break; case PPP_ACK_RCVD_STATE: NewState(PPP_OPENED_STATE); - locker.UnlockNow(); SendConfigureAck(packet); ReportUpEvent(); break; case PPP_OPENED_STATE: NewState(PPP_ACK_SENT_STATE); - locker.UnlockNow(); SendConfigureRequest(); SendConfigureAck(packet); break; @@ -745,12 +719,9 @@ IPCP::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) { TRACE("IPCP: RCRBadEvent() state=%d\n", State()); - LockerHelper locker(fLock); - switch(State()) { case PPP_OPENED_STATE: NewState(PPP_REQ_SENT_STATE); - locker.UnlockNow(); SendConfigureRequest(); case PPP_ACK_SENT_STATE: @@ -761,7 +732,6 @@ IPCP::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) case PPP_INITIAL_STATE: case PPP_REQ_SENT_STATE: case PPP_ACK_RCVD_STATE: - locker.UnlockNow(); if(nak && ntohs(mtod(nak, ppp_lcp_packet*)->length) > 3) SendConfigureNak(nak); else if(reject && ntohs(mtod(reject, ppp_lcp_packet*)->length) > 3) @@ -785,8 +755,6 @@ IPCP::RCAEvent(struct mbuf *packet) { TRACE("IPCP: RCAEvent() state=%d\n", State()); - LockerHelper locker(fLock); - if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request @@ -863,20 +831,17 @@ IPCP::RCAEvent(struct mbuf *packet) case PPP_ACK_RCVD_STATE: NewState(PPP_REQ_SENT_STATE); - locker.UnlockNow(); SendConfigureRequest(); break; case PPP_ACK_SENT_STATE: NewState(PPP_OPENED_STATE); InitializeRestartCount(); - locker.UnlockNow(); ReportUpEvent(); break; case PPP_OPENED_STATE: NewState(PPP_REQ_SENT_STATE); - locker.UnlockNow(); SendConfigureRequest(); break; @@ -893,8 +858,6 @@ IPCP::RCNEvent(struct mbuf *packet) { TRACE("IPCP: RCNEvent() state=%d\n", State()); - LockerHelper locker(fLock); - if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request @@ -992,7 +955,6 @@ IPCP::RCNEvent(struct mbuf *packet) case PPP_OPENED_STATE: if(State() == PPP_ACK_RCVD_STATE || State() == PPP_OPENED_STATE) NewState(PPP_REQ_SENT_STATE); - locker.UnlockNow(); SendConfigureRequest(); break; @@ -1009,8 +971,6 @@ IPCP::RTREvent(struct mbuf *packet) { TRACE("IPCP: RTREvent() state=%d\n", State()); - LockerHelper locker(fLock); - // we should not use the same ID as the peer if(fID == mtod(packet, ppp_lcp_packet*)->id) fID -= 128; @@ -1026,15 +986,13 @@ IPCP::RTREvent(struct mbuf *packet) case PPP_CLOSING_STATE: case PPP_REQ_SENT_STATE: - locker.UnlockNow(); SendTerminateAck(packet); return; // do not m_freem() packet case PPP_OPENED_STATE: NewState(PPP_CLOSING_STATE); - ZeroRestartCount(); - locker.UnlockNow(); + ResetRestartCount(); SendTerminateAck(packet); return; // do not m_freem() packet @@ -1052,8 +1010,6 @@ IPCP::RTAEvent(struct mbuf *packet) { TRACE("IPCP: RTAEvent() state=%d\n", State()); - LockerHelper locker(fLock); - if(fTerminateID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request @@ -1069,7 +1025,6 @@ IPCP::RTAEvent(struct mbuf *packet) case PPP_CLOSING_STATE: NewState(PPP_INITIAL_STATE); - locker.UnlockNow(); ReportDownEvent(); break; @@ -1079,7 +1034,6 @@ IPCP::RTAEvent(struct mbuf *packet) case PPP_OPENED_STATE: NewState(PPP_REQ_SENT_STATE); - locker.UnlockNow(); SendConfigureRequest(); break; @@ -1105,8 +1059,6 @@ IPCP::RXJBadEvent(struct mbuf *packet) { TRACE("IPCP: RXJBadEvent() state=%d\n", State()); - LockerHelper locker(fLock); - switch(State()) { case PPP_INITIAL_STATE: IllegalEvent(PPP_RXJ_BAD_EVENT); @@ -1114,7 +1066,6 @@ IPCP::RXJBadEvent(struct mbuf *packet) case PPP_CLOSING_STATE: NewState(PPP_INITIAL_STATE); - locker.UnlockNow(); ReportDownEvent(); break; @@ -1122,14 +1073,12 @@ IPCP::RXJBadEvent(struct mbuf *packet) case PPP_ACK_RCVD_STATE: case PPP_ACK_SENT_STATE: NewState(PPP_INITIAL_STATE); - locker.UnlockNow(); ReportUpFailedEvent(); break; case PPP_OPENED_STATE: NewState(PPP_CLOSING_STATE); InitializeRestartCount(); - locker.UnlockNow(); SendTerminateRequest(); break; @@ -1195,7 +1144,7 @@ IPCP::InitializeRestartCount() void -IPCP::ZeroRestartCount() +IPCP::ResetRestartCount() { fRequestCounter = 0; fTerminateCounter = 0; @@ -1208,10 +1157,8 @@ IPCP::SendConfigureRequest() { TRACE("IPCP: SendConfigureRequest() state=%d\n", State()); - LockerHelper locker(fLock); --fRequestCounter; fNextTimeout = system_time() + kIPCPStateMachineTimeout; - locker.UnlockNow(); KPPPConfigurePacket request(PPP_CONFIGURE_REQUEST); request.SetID(NextID()); @@ -1349,10 +1296,8 @@ IPCP::SendTerminateRequest() { TRACE("IPCP: SendTerminateRequest() state=%d\n", State()); - LockerHelper locker(fLock); --fTerminateCounter; fNextTimeout = system_time() + kIPCPStateMachineTimeout; - locker.UnlockNow(); struct mbuf *packet = m_gethdr(MT_DATA); if(!packet) diff --git a/src/add-ons/kernel/network/ppp/ipcp/Protocol.h b/src/add-ons/kernel/network/ppp/ipcp/Protocol.h index 96030944f1..626619b9a2 100644 --- a/src/add-ons/kernel/network/ppp/ipcp/Protocol.h +++ b/src/add-ons/kernel/network/ppp/ipcp/Protocol.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -106,7 +106,7 @@ class IPCP : public KPPPProtocol { void ReportUpEvent(); void ReportDownEvent(); void InitializeRestartCount(); - void ZeroRestartCount(); + void ResetRestartCount(); bool SendConfigureRequest(); bool SendConfigureAck(struct mbuf *packet); bool SendConfigureNak(struct mbuf *packet); @@ -135,8 +135,6 @@ class IPCP : public KPPPProtocol { uint8 fRequestID, fTerminateID; // the ID we used for the last configure/terminate request bigtime_t fNextTimeout; - - BLocker fLock; }; diff --git a/src/add-ons/kernel/network/ppp/modem/ModemDevice.cpp b/src/add-ons/kernel/network/ppp/modem/ModemDevice.cpp index dc3bdfafcd..585c1ce119 100644 --- a/src/add-ons/kernel/network/ppp/modem/ModemDevice.cpp +++ b/src/add-ons/kernel/network/ppp/modem/ModemDevice.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -16,7 +16,6 @@ // from libkernelppp #include -#include #if DEBUG @@ -185,8 +184,7 @@ ModemDevice::ModemDevice(KPPPInterface& interface, driver_parameter *settings) fHandle(-1), fWorkerThread(-1), fOutputBytes(0), - fState(INITIAL), - fLock("ModemDevice") + fState(INITIAL) { #if DEBUG TRACE("ModemDevice: Constructor\n"); @@ -239,8 +237,6 @@ ModemDevice::Up() if(InitCheck() != B_OK) return false; - LockerHelper locker(fLock); - if(IsUp()) return true; @@ -277,8 +273,6 @@ ModemDevice::Down() if(InitCheck() != B_OK) return false; - LockerHelper locker(fLock); - fState = TERMINATING; if(!IsUp()) { @@ -293,7 +287,6 @@ ModemDevice::Down() // worker_thread will notice that we are terminating (IsUp() == false) // ConnectionLost() will be called so we can terminate the connection there. - locker.UnlockNow(); int32 tmp; wait_for_thread(fWorkerThread, &tmp); @@ -336,8 +329,6 @@ ModemDevice::CountOutputBytes() const void ModemDevice::OpenModem() { - LockerHelper locker(fLock); - if(Handle() >= 0) return; @@ -370,8 +361,6 @@ ModemDevice::OpenModem() void ModemDevice::CloseModem() { - LockerHelper locker(fLock); - if(Handle() >= 0) close(Handle()); @@ -382,8 +371,6 @@ ModemDevice::CloseModem() void ModemDevice::FinishedDialing() { - LockerHelper locker(fLock); - fOutputBytes = 0; fState = OPENED; UpEvent(); @@ -393,8 +380,6 @@ ModemDevice::FinishedDialing() void ModemDevice::FailedDialing() { - LockerHelper locker(fLock); - fWorkerThread = -1; fState = INITIAL; CloseModem(); @@ -405,8 +390,6 @@ ModemDevice::FailedDialing() void ModemDevice::ConnectionLost() { - LockerHelper locker(fLock); - // switch to command mode and disconnect fWorkerThread = -1; fOutputBytes = 0; diff --git a/src/add-ons/kernel/network/ppp/modem/ModemDevice.h b/src/add-ons/kernel/network/ppp/modem/ModemDevice.h index f885fb36e6..8c20968cab 100644 --- a/src/add-ons/kernel/network/ppp/modem/ModemDevice.h +++ b/src/add-ons/kernel/network/ppp/modem/ModemDevice.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -77,8 +77,6 @@ class ModemDevice : public KPPPDevice { modem_state fState; ACFCHandler *fACFC; - - BLocker fLock; }; diff --git a/src/add-ons/kernel/network/ppp/pap/Protocol.cpp b/src/add-ons/kernel/network/ppp/pap/Protocol.cpp index d83f042a98..c840fe5d75 100644 --- a/src/add-ons/kernel/network/ppp/pap/Protocol.cpp +++ b/src/add-ons/kernel/network/ppp/pap/Protocol.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -7,8 +7,6 @@ #include #include -#include - #include #include #include @@ -81,8 +79,7 @@ PAP::PAP(KPPPInterface& interface, driver_parameter *settings) fID(system_time() & 0xFF), fMaxRequest(3), fRequestID(0), - fNextTimeout(0), - fLock("PAP") + fNextTimeout(0) { } @@ -107,14 +104,11 @@ PAP::Up() { TRACE("PAP: Up() state=%d\n", State()); - LockerHelper locker(fLock); - switch(State()) { case INITIAL: if(Side() == PPP_LOCAL_SIDE) { NewState(REQ_SENT); InitializeRestartCount(); - locker.UnlockNow(); SendRequest(); } else if(Side() == PPP_PEER_SIDE) { NewState(WAITING_FOR_REQ); @@ -139,15 +133,12 @@ PAP::Down() { TRACE("PAP: Down() state=%d\n", State()); - LockerHelper locker(fLock); - switch(Interface().Phase()) { case PPP_DOWN_PHASE: // interface finished terminating case PPP_ESTABLISHED_PHASE: // terminate this NCP individually (block until we finished terminating) NewState(INITIAL); - locker.UnlockNow(); DownEvent(); break; @@ -233,11 +224,9 @@ PAP::Receive(struct mbuf *packet, uint16 protocolNumber) void PAP::Pulse() { - LockerHelper locker(fLock); if(fNextTimeout == 0 || fNextTimeout > system_time()) return; fNextTimeout = 0; - locker.UnlockNow(); switch(State()) { case REQ_SENT: @@ -290,11 +279,8 @@ PAP::TOGoodEvent() { TRACE("PAP: TOGoodEvent() state=%d\n", State()); - LockerHelper locker(fLock); - switch(State()) { case REQ_SENT: - locker.UnlockNow(); SendRequest(); break; @@ -313,13 +299,10 @@ PAP::TOBadEvent() { TRACE("PAP: TOBadEvent() state=%d\n", State()); - LockerHelper locker(fLock); - switch(State()) { case REQ_SENT: case WAITING_FOR_REQ: NewState(INITIAL); - locker.UnlockNow(); if(State() == REQ_SENT) Interface().StateMachine().LocalAuthenticationDenied( Interface().Username()); @@ -341,8 +324,6 @@ PAP::RREvent(struct mbuf *packet) { TRACE("PAP: RREvent() state=%d\n", State()); - LockerHelper locker(fLock); - ppp_lcp_packet *request = mtod(packet, ppp_lcp_packet*); int32 length = ntohs(request->length); uint8 *data = request->data; @@ -363,13 +344,11 @@ PAP::RREvent(struct mbuf *packet) && !strncmp(peerUsername, username, *userLength) && !strncmp(peerPassword, password, *passwordLength)) { NewState(ACCEPTED); - locker.UnlockNow(); Interface().StateMachine().PeerAuthenticationAccepted(username); UpEvent(); SendAck(packet); } else { NewState(INITIAL); - locker.UnlockNow(); Interface().StateMachine().PeerAuthenticationDenied(username); UpFailedEvent(); SendNak(packet); @@ -382,8 +361,6 @@ PAP::RAEvent(struct mbuf *packet) { TRACE("PAP: RAEvent() state=%d\n", State()); - LockerHelper locker(fLock); - if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request @@ -395,7 +372,6 @@ PAP::RAEvent(struct mbuf *packet) switch(State()) { case REQ_SENT: NewState(ACCEPTED); - locker.UnlockNow(); Interface().StateMachine().LocalAuthenticationAccepted( Interface().Username()); UpEvent(); @@ -414,8 +390,6 @@ PAP::RNEvent(struct mbuf *packet) { TRACE("PAP: RNEvent() state=%d\n", State()); - LockerHelper locker(fLock); - if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request @@ -427,7 +401,6 @@ PAP::RNEvent(struct mbuf *packet) switch(State()) { case REQ_SENT: NewState(INITIAL); - locker.UnlockNow(); Interface().StateMachine().LocalAuthenticationDenied( Interface().Username()); UpFailedEvent(); @@ -453,10 +426,8 @@ PAP::SendRequest() { TRACE("PAP: SendRequest() state=%d\n", State()); - LockerHelper locker(fLock); --fRequestCounter; fNextTimeout = system_time() + kPAPTimeout; - locker.UnlockNow(); struct mbuf *packet = m_gethdr(MT_DATA); if(!packet) diff --git a/src/add-ons/kernel/network/ppp/pap/Protocol.h b/src/add-ons/kernel/network/ppp/pap/Protocol.h index b925a2a542..43a1bc7dea 100644 --- a/src/add-ons/kernel/network/ppp/pap/Protocol.h +++ b/src/add-ons/kernel/network/ppp/pap/Protocol.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -94,8 +94,6 @@ class PAP : public KPPPProtocol { uint8 fRequestID; // the ID we used for the last configure/terminate request bigtime_t fNextTimeout; - - BLocker fLock; }; diff --git a/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp b/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp index c457f6fed6..70c49ddd1d 100644 --- a/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp +++ b/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -11,7 +11,6 @@ // from libkernelppp #include -#include #if DEBUG @@ -51,8 +50,7 @@ PPPoEDevice::PPPoEDevice(KPPPInterface& interface, driver_parameter *settings) fServiceName(NULL), fAttempts(0), fNextTimeout(0), - fState(INITIAL), - fLock("PPPoEDevice") + fState(INITIAL) { #if DEBUG TRACE("PPPoEDevice: Constructor\n"); @@ -81,16 +79,6 @@ PPPoEDevice::PPPoEDevice(KPPPInterface& interface, driver_parameter *settings) if(!fEthernetIfnet) TRACE("PPPoEDevice::ctor: could not find ethernet interface\n"); #endif - - add_device(this); -} - - -PPPoEDevice::~PPPoEDevice() -{ - TRACE("PPPoEDevice: Destructor\n"); - - remove_device(this); } @@ -110,11 +98,11 @@ PPPoEDevice::Up() if(InitCheck() != B_OK) return false; - LockerHelper locker(fLock); - if(IsUp()) return true; + add_device(this); + fState = INITIAL; // reset state @@ -154,6 +142,7 @@ PPPoEDevice::Up() // check if we are allowed to go up now (user intervention might disallow that) if(fAttempts > 0 && !UpStarted()) { fAttempts = 0; + remove_device(this); DownEvent(); return true; // there was no error @@ -180,11 +169,11 @@ PPPoEDevice::Down() { TRACE("PPPoEDevice: Down()\n"); + remove_device(this); + if(InitCheck() != B_OK) return false; - LockerHelper locker(fLock); - fState = INITIAL; fAttempts = 0; fNextTimeout = 0; @@ -267,8 +256,6 @@ PPPoEDevice::Send(struct mbuf *packet, uint16 protocolNumber) return B_ERROR; } - LockerHelper locker(fLock); - if(!IsUp()) { ERROR("PPPoEDevice::Send(): no connection!\n"); m_freem(packet); @@ -296,13 +283,12 @@ PPPoEDevice::Send(struct mbuf *packet, uint16 protocolNumber) ethernetHeader->ether_type = ETHERTYPE_PPPOE; memcpy(ethernetHeader->ether_dhost, fPeer, sizeof(fPeer)); - locker.UnlockNow(); - if(!packet || !mtod(packet, pppoe_header*)) ERROR("PPPoEDevice::Send(): packet is NULL!\n"); if(EthernetIfnet()->output(EthernetIfnet(), packet, &destination, NULL) != B_OK) { ERROR("PPPoEDevice::Send(): EthernetIfnet()->output() failed!\n"); + remove_device(this); DownEvent(); // DownEvent() without DownStarted() indicates connection lost return PPP_NO_CONNECTION; @@ -354,8 +340,6 @@ PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber) return B_ERROR; } - LockerHelper locker(fLock); - if(IsDown()) { m_freem(packet); return B_ERROR; @@ -476,6 +460,7 @@ PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber) fAttempts = 0; fSessionID = 0; fNextTimeout = 0; + remove_device(this); DownEvent(); break; @@ -499,8 +484,6 @@ PPPoEDevice::Pulse() if(fNextTimeout == 0 || IsUp() || IsDown()) return; - LockerHelper locker(fLock); - // check if timed out if(system_time() >= fNextTimeout) { if(!Up()) diff --git a/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h b/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h index 6fd9600d8c..39550587a3 100644 --- a/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h +++ b/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -24,7 +24,6 @@ enum pppoe_state { class PPPoEDevice : public KPPPDevice { public: PPPoEDevice(KPPPInterface& interface, driver_parameter *settings); - virtual ~PPPoEDevice(); ifnet *EthernetIfnet() const { return fEthernetIfnet; } @@ -66,8 +65,6 @@ class PPPoEDevice : public KPPPDevice { uint32 fAttempts; bigtime_t fNextTimeout; pppoe_state fState; - - BLocker fLock; }; diff --git a/src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp b/src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp index 81920d4a1d..5d0884a020 100644 --- a/src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp +++ b/src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -106,7 +106,8 @@ add_device(PPPoEDevice *device) TRACE("PPPoE: add_device()\n"); LockerHelper locker(sLock); - sDevices->AddItem(device); + if(!sDevices->HasItem(device)) + sDevices->AddItem(device); } diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPInterface.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPInterface.cpp index 289a76398a..85bce69c5f 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPInterface.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPInterface.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -235,8 +235,6 @@ KPPPInterface::~KPPPInterface() { TRACE("KPPPInterface: Destructor\n"); - ++fDeleteCounter; - // tell protocols to uninit (remove routes, etc.) KPPPProtocol *protocol = FirstProtocol(); for(; protocol; protocol = protocol->NextProtocol()) @@ -298,22 +296,17 @@ KPPPInterface::~KPPPInterface() void KPPPInterface::Delete() { - if(atomic_add(&fDeleteCounter, 1) > 0) + LockerHelper locker(fLock); + + if(fDeleteCounter > 0) return; // only one thread should delete us! - if(fManager) - fManager->DeleteInterface(ID()); - // This will mark us for deletion. - // Any subsequent calls to delete_interface() will do nothing. - else { - // We were not created by the manager. - // Spawn a thread that will delete us. - thread_id interfaceDeleterThread - = spawn_kernel_thread(interface_deleter_thread, - "KPPPInterface: interface_deleter_thread", B_NORMAL_PRIORITY, this); - resume_thread(interfaceDeleterThread); - } + fDeleteCounter = 1; + + fManager->DeleteInterface(ID()); + // This will mark us for deletion. + // Any subsequent calls to delete_interface() will do nothing. } @@ -801,6 +794,8 @@ KPPPInterface::RemoveProtocol(KPPPProtocol *protocol) int32 KPPPInterface::CountProtocols() const { + LockerHelper locker(fLock); + KPPPProtocol *protocol = FirstProtocol(); int32 count = 0; @@ -815,6 +810,8 @@ KPPPInterface::CountProtocols() const KPPPProtocol* KPPPInterface::ProtocolAt(int32 index) const { + LockerHelper locker(fLock); + KPPPProtocol *protocol = FirstProtocol(); int32 currentIndex = 0; @@ -837,6 +834,8 @@ KPPPInterface::ProtocolFor(uint16 protocolNumber, KPPPProtocol *start) const { TRACE("KPPPInterface: ProtocolFor(%X)\n", protocolNumber); + LockerHelper locker(fLock); + KPPPProtocol *current = start ? start : FirstProtocol(); for(; current; current = current->NextProtocol()) { @@ -898,6 +897,8 @@ KPPPInterface::ChildAt(int32 index) const { TRACE("KPPPInterface: ChildAt(%ld)\n", index); + LockerHelper locker(fLock); + KPPPInterface *child = fChildren.ItemAt(index); if(child == fChildren.GetDefaultItem()) @@ -916,8 +917,6 @@ KPPPInterface::SetAutoReconnect(bool autoReconnect) if(Mode() != PPP_CLIENT_MODE) return; - LockerHelper locker(fLock); - fAutoReconnect = autoReconnect; } @@ -931,6 +930,8 @@ KPPPInterface::SetConnectOnDemand(bool connectOnDemand) TRACE("KPPPInterface: SetConnectOnDemand(%s)\n", connectOnDemand ? "true" : "false"); + LockerHelper locker(fLock); + // Only clients support ConnectOnDemand. if(Mode() != PPP_CLIENT_MODE) { TRACE("KPPPInterface::SetConnectOnDemand(): Wrong mode!\n"); @@ -939,8 +940,6 @@ KPPPInterface::SetConnectOnDemand(bool connectOnDemand) } else if(DoesConnectOnDemand() == connectOnDemand) return; - LockerHelper locker(fLock); - fConnectOnDemand = connectOnDemand; // Do not allow changes when we are disconnected (only main interfaces). @@ -972,8 +971,10 @@ void KPPPInterface::SetAskBeforeConnecting(bool ask) { LockerHelper locker(fLock); + bool old = fAskBeforeConnecting; fAskBeforeConnecting = ask; + if(old && fAskBeforeConnecting == false && State() == PPP_STARTING_STATE && Phase() == PPP_DOWN_PHASE) { locker.UnlockNow(); @@ -988,6 +989,8 @@ KPPPInterface::SetPFCOptions(uint8 pfcOptions) { TRACE("KPPPInterface: SetPFCOptions(0x%X)\n", pfcOptions); + LockerHelper locker(fLock); + if(PFCOptions() & PPP_FREEZE_PFC_OPTIONS) return false; @@ -1014,13 +1017,8 @@ KPPPInterface::Up() if(IsUp()) return true; - // Lock needs timeout because destructor could have locked the interface. - while(fLock.LockWithTimeout(100000) != B_NO_ERROR) - if(fDeleteCounter > 0) - return false; - + LockerHelper locker(fLock); StateMachine().OpenEvent(); - fLock.Unlock(); return true; } @@ -1045,6 +1043,8 @@ KPPPInterface::Down() send_data_with_timeout(fReconnectThread, 0, NULL, 0, 200); // tell the reconnect thread to abort its attempt (if it's still waiting) + + LockerHelper locker(fLock); StateMachine().CloseEvent(); return true; @@ -1060,13 +1060,7 @@ KPPPInterface::WaitForConnection() if(InitCheck() != B_OK) return false; - // Lock needs timeout because destructor could have locked the interface. - while(fLock.LockWithTimeout(100000) != B_NO_ERROR) - if(fDeleteCounter > 0) - return false; - ReportManager().EnableReports(PPP_CONNECTION_REPORT, find_thread(NULL)); - fLock.Unlock(); ppp_report_packet report; thread_id sender; @@ -1092,15 +1086,6 @@ KPPPInterface::WaitForConnection() } -//! Returns if the interface is connected. -bool -KPPPInterface::IsUp() const -{ - LockerHelper locker(fLock); - return Phase() == PPP_ESTABLISHED_PHASE; -} - - /*! \brief Loads modules specified in the settings structure. \param settings PPP interface description file format settings. @@ -1221,7 +1206,9 @@ KPPPInterface::IsAllowedToSend() const This brings the interface up if connect-on-demand is enabled and we are not connected. \n - PFC encoding is handled here. + PFC encoding is handled here. \n + NOTE: In order to prevent interface destruction while sending you must either + hold a refcount for this interface or make sure it is locked. \param packet The packet. \param protocolNumber The packet's protocol number. @@ -1247,6 +1234,8 @@ KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) } // go up if ConnectOnDemand is enabled and we are disconnected + // TODO: our new netstack will simplify ConnectOnDemand handling, so + // we do not have to handle it here if((protocolNumber != PPP_LCP_PROTOCOL && DoesConnectOnDemand() && (Phase() == PPP_DOWN_PHASE || Phase() == PPP_ESTABLISHMENT_PHASE) @@ -1303,7 +1292,7 @@ KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) *header = protocolNumber; } - // pass to device/children + // pass to device if we're either not a multilink interface or a child interface if(!IsMultilink() || Parent()) { // check if packet is too big for device uint32 length = packet->m_flags & M_PKTHDR ? (uint32) packet->m_pkthdr.len : @@ -1351,6 +1340,8 @@ KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber) if(!packet) return B_ERROR; + LockerHelper locker(fLock); + int32 result = PPP_REJECTED; // assume we have no handler @@ -1447,6 +1438,8 @@ KPPPInterface::ReceiveFromDevice(struct mbuf *packet) void KPPPInterface::Pulse() { + LockerHelper locker(fLock); + if(Device()) Device()->Pulse(); @@ -1579,6 +1572,8 @@ KPPPInterface::StackControlEachHandler(uint32 op, void *data) status_t result = B_BAD_VALUE, tmp; + LockerHelper locker(fLock); + KPPPProtocol *protocol = FirstProtocol(); for(; protocol; protocol = protocol->NextProtocol()) { tmp = protocol->StackControl(op, data); @@ -1603,6 +1598,8 @@ KPPPInterface::CalculateInterfaceMTU() { TRACE("KPPPInterface: CalculateInterfaceMTU()\n"); + LockerHelper locker(fLock); + fInterfaceMTU = fMRU; fHeaderLength = 2; @@ -1631,6 +1628,8 @@ KPPPInterface::CalculateBaudRate() { TRACE("KPPPInterface: CalculateBaudRate()\n"); + LockerHelper locker(fLock); + if(!Ifnet()) return; @@ -1652,6 +1651,8 @@ KPPPInterface::Reconnect(uint32 delay) { TRACE("KPPPInterface: Reconnect(%ld)\n", delay); + LockerHelper locker(fLock); + if(fReconnectThread != -1) return; @@ -1692,26 +1693,3 @@ reconnect_thread(void *data) return B_OK; } - - -// ---------------------------------- -// Function: interface_deleter_thread -// ---------------------------------- -//! Private class. -class KPPPInterfaceAccess { - public: - KPPPInterfaceAccess() {} - - void Delete(KPPPInterface *interface) - { delete interface; } -}; - - -status_t -interface_deleter_thread(void *data) -{ - KPPPInterfaceAccess access; - access.Delete((KPPPInterface*) data); - - return B_OK; -} diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCP.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCP.cpp index ac4dddb269..0b17cea5cf 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCP.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCP.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -19,8 +19,6 @@ #include #include -#include - #include #include #include @@ -59,8 +57,6 @@ KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler) if(!optionHandler || &optionHandler->Interface() != &Interface()) return false; - LockerHelper locker(StateMachine().fLock); - if(Interface().Phase() != PPP_DOWN_PHASE || OptionHandlerFor(optionHandler->Type())) return false; @@ -78,8 +74,6 @@ KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler) bool KPPPLCP::RemoveOptionHandler(KPPPOptionHandler *optionHandler) { - LockerHelper locker(StateMachine().fLock); - if(Interface().Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change @@ -138,8 +132,6 @@ KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension) if(!lcpExtension || &lcpExtension->Interface() != &Interface()) return false; - LockerHelper locker(StateMachine().fLock); - if(Interface().Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change @@ -155,8 +147,6 @@ KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension) bool KPPPLCP::RemoveLCPExtension(KPPPLCPExtension *lcpExtension) { - LockerHelper locker(StateMachine().fLock); - if(Interface().Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPStateMachine.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPStateMachine.cpp index aec1d32c7d..8cece1c9ae 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPStateMachine.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPStateMachine.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2006, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -150,8 +149,6 @@ KPPPStateMachine::Reconfigure() { TRACE("KPPPSM: Reconfigure() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - if(State() < PPP_REQ_SENT_STATE) return false; @@ -162,8 +159,6 @@ KPPPStateMachine::Reconfigure() DownProtocols(); ResetLCPHandlers(); - locker.UnlockNow(); - return SendConfigureRequest(); } @@ -235,8 +230,6 @@ KPPPStateMachine::LocalAuthenticationRequested() TRACE("KPPPSM: LocalAuthenticationRequested() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - fLastConnectionReportCode = PPP_REPORT_AUTHENTICATION_REQUESTED; Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_AUTHENTICATION_REQUESTED, &fInterface.fID, @@ -260,8 +253,6 @@ KPPPStateMachine::LocalAuthenticationAccepted(const char *name) TRACE("KPPPSM: LocalAuthenticationAccepted() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - fLocalAuthenticationStatus = PPP_AUTHENTICATION_SUCCESSFUL; free(fLocalAuthenticationName); if(name) @@ -282,8 +273,6 @@ KPPPStateMachine::LocalAuthenticationDenied(const char *name) { TRACE("KPPPSM: LocalAuthenticationDenied() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - fLocalAuthenticationStatus = PPP_AUTHENTICATION_FAILED; free(fLocalAuthenticationName); if(name) @@ -302,8 +291,6 @@ KPPPStateMachine::PeerAuthenticationRequested() TRACE("KPPPSM: PeerAuthenticationRequested() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - fLastConnectionReportCode = PPP_REPORT_AUTHENTICATION_REQUESTED; Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_AUTHENTICATION_REQUESTED, &fInterface.fID, @@ -327,8 +314,6 @@ KPPPStateMachine::PeerAuthenticationAccepted(const char *name) TRACE("KPPPSM: PeerAuthenticationAccepted() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - fPeerAuthenticationStatus = PPP_AUTHENTICATION_SUCCESSFUL; free(fPeerAuthenticationName); if(name) @@ -349,8 +334,6 @@ KPPPStateMachine::PeerAuthenticationDenied(const char *name) { TRACE("KPPPSM: PeerAuthenticationDenied() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - fPeerAuthenticationStatus = PPP_AUTHENTICATION_FAILED; free(fPeerAuthenticationName); if(name) @@ -381,8 +364,6 @@ KPPPStateMachine::UpEvent(KPPPInterface& interface) { TRACE("KPPPSM: UpEvent(interface) state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - if(Phase() <= PPP_TERMINATION_PHASE) { interface.StateMachine().CloseEvent(); return; @@ -393,7 +374,6 @@ KPPPStateMachine::UpEvent(KPPPInterface& interface) if(Phase() == PPP_ESTABLISHMENT_PHASE) { // this is the first interface that went up Interface().SetMRU(interface.MRU()); - locker.UnlockNow(); ThisLayerUp(); } else if(Interface().MRU() > interface.MRU()) Interface().SetMRU(interface.MRU()); @@ -409,8 +389,6 @@ KPPPStateMachine::DownEvent(KPPPInterface& interface) { TRACE("KPPPSM: DownEvent(interface) state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - uint32 MRU = 0; // the new MRU @@ -439,10 +417,8 @@ KPPPStateMachine::DownEvent(KPPPInterface& interface) else Interface().SetMRU(MRU); - if(count == 0) { - locker.UnlockNow(); + if(count == 0) DownEvent(); - } } } @@ -484,8 +460,6 @@ KPPPStateMachine::UpEvent(KPPPProtocol *protocol) { TRACE("KPPPSM: UpEvent(protocol) state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - if(Phase() >= PPP_ESTABLISHMENT_PHASE) BringProtocolsUp(); } @@ -516,8 +490,6 @@ KPPPStateMachine::TLSNotify() { TRACE("KPPPSM: TLSNotify() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - if(State() == PPP_STARTING_STATE) { if(Phase() == PPP_DOWN_PHASE) NewPhase(PPP_ESTABLISHMENT_PHASE); @@ -542,8 +514,6 @@ KPPPStateMachine::TLFNotify() { TRACE("KPPPSM: TLFNotify() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - NewPhase(PPP_TERMINATION_PHASE); // tell DownEvent() that it may create a connection-lost-report @@ -557,8 +527,6 @@ KPPPStateMachine::UpFailedEvent() { TRACE("KPPPSM: UpFailedEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - switch(State()) { case PPP_STARTING_STATE: fLastConnectionReportCode = PPP_REPORT_DEVICE_UP_FAILED; @@ -587,8 +555,6 @@ KPPPStateMachine::UpEvent() // This call is public, thus, it might not only be called by the device. // We must recognize these attempts to fool us and handle them correctly. - LockerHelper locker(fLock); - if(!Interface().Device() || !Interface().Device()->IsUp()) return; // it is not our device that went up... @@ -603,7 +569,6 @@ KPPPStateMachine::UpEvent() // connection, so this is an illegal event IllegalEvent(PPP_UP_EVENT); NewState(PPP_CLOSED_STATE); - locker.UnlockNow(); ThisLayerFinished(); return; @@ -612,7 +577,6 @@ KPPPStateMachine::UpEvent() // TODO: handle server-up! (maybe already done correctly) NewState(PPP_REQ_SENT_STATE); InitializeRestartCount(); - locker.UnlockNow(); SendConfigureRequest(); break; @@ -624,14 +588,12 @@ KPPPStateMachine::UpEvent() // to go up IllegalEvent(PPP_UP_EVENT); NewState(PPP_CLOSED_STATE); - locker.UnlockNow(); ThisLayerFinished(); break; } NewState(PPP_REQ_SENT_STATE); InitializeRestartCount(); - locker.UnlockNow(); SendConfigureRequest(); break; @@ -651,8 +613,6 @@ KPPPStateMachine::DownEvent() { TRACE("KPPPSM: DownEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - if(Interface().Device() && Interface().Device()->IsUp()) return; // it is not our device that went down... @@ -753,8 +713,6 @@ KPPPStateMachine::OpenEvent() { TRACE("KPPPSM: OpenEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - // reset all handlers if(Phase() != PPP_ESTABLISHED_PHASE) { DownProtocols(); @@ -777,10 +735,8 @@ KPPPStateMachine::OpenEvent() } else NewState(PPP_STARTING_STATE); - if(Interface().fAskBeforeConnecting == false) { - locker.UnlockNow(); + if(Interface().fAskBeforeConnecting == false) ContinueOpenEvent(); - } break; case PPP_CLOSED_STATE: @@ -792,7 +748,6 @@ KPPPStateMachine::OpenEvent() NewState(PPP_REQ_SENT_STATE); NewPhase(PPP_ESTABLISHMENT_PHASE); InitializeRestartCount(); - locker.UnlockNow(); SendConfigureRequest(); break; @@ -812,7 +767,6 @@ KPPPStateMachine::ContinueOpenEvent() TRACE("KPPPSM: ContinueOpenEvent() state=%d phase=%d\n", State(), Phase()); if(Interface().IsMultilink() && !Interface().Parent()) { - LockerHelper locker(fLock); NewPhase(PPP_ESTABLISHMENT_PHASE); for(int32 index = 0; index < Interface().CountChildren(); index++) if(Interface().ChildAt(index)->Mode() == Interface().Mode()) @@ -827,8 +781,6 @@ KPPPStateMachine::CloseEvent() { TRACE("KPPPSM: CloseEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - if(Interface().IsMultilink() && !Interface().Parent()) { NewState(PPP_INITIAL_STATE); @@ -852,7 +804,6 @@ KPPPStateMachine::CloseEvent() NewPhase(PPP_TERMINATION_PHASE); // indicates to handlers that we are terminating InitializeRestartCount(); - locker.UnlockNow(); if(State() == PPP_OPENED_STATE) ThisLayerDown(); SendTerminateRequest(); @@ -868,7 +819,6 @@ KPPPStateMachine::CloseEvent() NewPhase(PPP_DOWN_PHASE); // this says the following DownEvent() was not caused by // a connection fault - locker.UnlockNow(); ThisLayerFinished(); } break; @@ -893,12 +843,9 @@ KPPPStateMachine::TOGoodEvent() { TRACE("KPPPSM: TOGoodEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - switch(State()) { case PPP_CLOSING_STATE: case PPP_STOPPING_STATE: - locker.UnlockNow(); SendTerminateRequest(); break; @@ -907,7 +854,6 @@ KPPPStateMachine::TOGoodEvent() case PPP_REQ_SENT_STATE: case PPP_ACK_SENT_STATE: - locker.UnlockNow(); SendConfigureRequest(); break; @@ -923,13 +869,10 @@ KPPPStateMachine::TOBadEvent() { TRACE("KPPPSM: TOBadEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - switch(State()) { case PPP_CLOSING_STATE: NewState(PPP_CLOSED_STATE); NewPhase(PPP_TERMINATION_PHASE); - locker.UnlockNow(); ThisLayerFinished(); break; @@ -939,7 +882,6 @@ KPPPStateMachine::TOBadEvent() case PPP_ACK_SENT_STATE: NewState(PPP_STOPPED_STATE); NewPhase(PPP_TERMINATION_PHASE); - locker.UnlockNow(); ThisLayerFinished(); break; @@ -955,8 +897,6 @@ KPPPStateMachine::RCRGoodEvent(struct mbuf *packet) { TRACE("KPPPSM: RCRGoodEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - switch(State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: @@ -965,7 +905,6 @@ KPPPStateMachine::RCRGoodEvent(struct mbuf *packet) break; case PPP_CLOSED_STATE: - locker.UnlockNow(); SendTerminateAck(); m_freem(packet); break; @@ -980,13 +919,11 @@ KPPPStateMachine::RCRGoodEvent(struct mbuf *packet) NewState(PPP_ACK_SENT_STATE); case PPP_ACK_SENT_STATE: - locker.UnlockNow(); SendConfigureAck(packet); break; case PPP_ACK_RCVD_STATE: NewState(PPP_OPENED_STATE); - locker.UnlockNow(); SendConfigureAck(packet); ThisLayerUp(); break; @@ -995,7 +932,6 @@ KPPPStateMachine::RCRGoodEvent(struct mbuf *packet) NewState(PPP_ACK_SENT_STATE); NewPhase(PPP_ESTABLISHMENT_PHASE); // indicates to handlers that we are reconfiguring - locker.UnlockNow(); ThisLayerDown(); SendConfigureRequest(); SendConfigureAck(packet); @@ -1013,8 +949,6 @@ KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) { TRACE("KPPPSM: RCRBadEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - switch(State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: @@ -1022,7 +956,6 @@ KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) break; case PPP_CLOSED_STATE: - locker.UnlockNow(); SendTerminateAck(); break; @@ -1035,7 +968,6 @@ KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) NewState(PPP_REQ_SENT_STATE); NewPhase(PPP_ESTABLISHMENT_PHASE); // indicates to handlers that we are reconfiguring - locker.UnlockNow(); ThisLayerDown(); SendConfigureRequest(); @@ -1046,7 +978,6 @@ KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) case PPP_REQ_SENT_STATE: case PPP_ACK_RCVD_STATE: - locker.UnlockNow(); if(nak && ntohs(mtod(nak, ppp_lcp_packet*)->length) > 3) SendConfigureNak(nak); else if(reject && ntohs(mtod(reject, ppp_lcp_packet*)->length) > 3) @@ -1071,8 +1002,6 @@ KPPPStateMachine::RCAEvent(struct mbuf *packet) { TRACE("KPPPSM: RCAEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request @@ -1089,7 +1018,6 @@ KPPPStateMachine::RCAEvent(struct mbuf *packet) optionHandler = LCP().OptionHandlerAt(index); if(optionHandler->ParseAck(ack) != B_OK) { m_freem(packet); - locker.UnlockNow(); CloseEvent(); return; } @@ -1103,7 +1031,6 @@ KPPPStateMachine::RCAEvent(struct mbuf *packet) case PPP_CLOSED_STATE: case PPP_STOPPED_STATE: - locker.UnlockNow(); SendTerminateAck(); break; @@ -1114,14 +1041,12 @@ KPPPStateMachine::RCAEvent(struct mbuf *packet) case PPP_ACK_RCVD_STATE: NewState(PPP_REQ_SENT_STATE); - locker.UnlockNow(); SendConfigureRequest(); break; case PPP_ACK_SENT_STATE: NewState(PPP_OPENED_STATE); InitializeRestartCount(); - locker.UnlockNow(); ThisLayerUp(); break; @@ -1129,7 +1054,6 @@ KPPPStateMachine::RCAEvent(struct mbuf *packet) NewState(PPP_REQ_SENT_STATE); NewPhase(PPP_ESTABLISHMENT_PHASE); // indicates to handlers that we are reconfiguring - locker.UnlockNow(); ThisLayerDown(); SendConfigureRequest(); break; @@ -1148,8 +1072,6 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet) { TRACE("KPPPSM: RCNEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request @@ -1168,14 +1090,12 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet) if(nak_reject.Code() == PPP_CONFIGURE_NAK) { if(optionHandler->ParseNak(nak_reject) != B_OK) { m_freem(packet); - locker.UnlockNow(); CloseEvent(); return; } } else if(nak_reject.Code() == PPP_CONFIGURE_REJECT) { if(optionHandler->ParseReject(nak_reject) != B_OK) { m_freem(packet); - locker.UnlockNow(); CloseEvent(); return; } @@ -1190,7 +1110,6 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet) case PPP_CLOSED_STATE: case PPP_STOPPED_STATE: - locker.UnlockNow(); SendTerminateAck(); break; @@ -1201,7 +1120,6 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet) case PPP_ACK_RCVD_STATE: if(State() == PPP_ACK_RCVD_STATE) NewState(PPP_REQ_SENT_STATE); - locker.UnlockNow(); SendConfigureRequest(); break; @@ -1209,7 +1127,6 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet) NewState(PPP_REQ_SENT_STATE); NewPhase(PPP_ESTABLISHMENT_PHASE); // indicates to handlers that we are reconfiguring - locker.UnlockNow(); ThisLayerDown(); SendConfigureRequest(); break; @@ -1228,8 +1145,6 @@ KPPPStateMachine::RTREvent(struct mbuf *packet) { TRACE("KPPPSM: RTREvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - // we should not use the same ID as the peer if(fID == mtod(packet, ppp_lcp_packet*)->id) fID -= 128; @@ -1249,7 +1164,6 @@ KPPPStateMachine::RTREvent(struct mbuf *packet) NewState(PPP_REQ_SENT_STATE); NewPhase(PPP_TERMINATION_PHASE); // indicates to handlers that we are terminating - locker.UnlockNow(); SendTerminateAck(packet); break; @@ -1258,7 +1172,6 @@ KPPPStateMachine::RTREvent(struct mbuf *packet) NewPhase(PPP_TERMINATION_PHASE); // indicates to handlers that we are terminating ZeroRestartCount(); - locker.UnlockNow(); ThisLayerDown(); SendTerminateAck(packet); break; @@ -1266,7 +1179,6 @@ KPPPStateMachine::RTREvent(struct mbuf *packet) default: NewPhase(PPP_TERMINATION_PHASE); // indicates to handlers that we are terminating - locker.UnlockNow(); SendTerminateAck(packet); } } @@ -1278,8 +1190,6 @@ KPPPStateMachine::RTAEvent(struct mbuf *packet) { TRACE("KPPPSM: RTAEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - if(fTerminateID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request @@ -1297,13 +1207,11 @@ KPPPStateMachine::RTAEvent(struct mbuf *packet) case PPP_CLOSING_STATE: NewState(PPP_CLOSED_STATE); - locker.UnlockNow(); ThisLayerFinished(); break; case PPP_STOPPING_STATE: NewState(PPP_STOPPED_STATE); - locker.UnlockNow(); ThisLayerFinished(); break; @@ -1315,7 +1223,6 @@ KPPPStateMachine::RTAEvent(struct mbuf *packet) NewState(PPP_REQ_SENT_STATE); NewPhase(PPP_ESTABLISHMENT_PHASE); // indicates to handlers that we are reconfiguring - locker.UnlockNow(); ThisLayerDown(); SendConfigureRequest(); break; @@ -1335,8 +1242,6 @@ KPPPStateMachine::RUCEvent(struct mbuf *packet, uint16 protocolNumber, { TRACE("KPPPSM: RUCEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - switch(State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: @@ -1345,7 +1250,6 @@ KPPPStateMachine::RUCEvent(struct mbuf *packet, uint16 protocolNumber, break; default: - locker.UnlockNow(); SendCodeReject(packet, protocolNumber, code); } } @@ -1359,7 +1263,6 @@ KPPPStateMachine::RXJGoodEvent(struct mbuf *packet) // This method does not m_freem(packet) because the acceptable rejects are // also passed to the parent. RXJEvent() will m_freem(packet) when needed. - LockerHelper locker(fLock); switch(State()) { case PPP_INITIAL_STATE: @@ -1383,8 +1286,6 @@ KPPPStateMachine::RXJBadEvent(struct mbuf *packet) { TRACE("KPPPSM: RXJBadEvent() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - switch(State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: @@ -1395,7 +1296,6 @@ KPPPStateMachine::RXJBadEvent(struct mbuf *packet) NewState(PPP_CLOSED_STATE); case PPP_CLOSED_STATE: - locker.UnlockNow(); ThisLayerFinished(); break; @@ -1408,7 +1308,6 @@ KPPPStateMachine::RXJBadEvent(struct mbuf *packet) NewPhase(PPP_TERMINATION_PHASE); case PPP_STOPPED_STATE: - locker.UnlockNow(); ThisLayerFinished(); break; @@ -1417,7 +1316,6 @@ KPPPStateMachine::RXJBadEvent(struct mbuf *packet) NewPhase(PPP_TERMINATION_PHASE); // indicates to handlers that we are terminating InitializeRestartCount(); - locker.UnlockNow(); ThisLayerDown(); SendTerminateRequest(); break; @@ -1469,15 +1367,10 @@ KPPPStateMachine::TimerEvent() TRACE("KPPPSM: TimerEvent()\n"); #endif - // We might cause a dead-lock. Thus, abort if we cannot get the lock. - if(fLock.LockWithTimeout(100000) != B_OK) + if(fNextTimeout == 0 || fNextTimeout > system_time()) return; - if(fNextTimeout == 0 || fNextTimeout > system_time()) { - fLock.Unlock(); - return; - } + fNextTimeout = 0; - fLock.Unlock(); switch(State()) { case PPP_CLOSING_STATE: @@ -1669,8 +1562,6 @@ KPPPStateMachine::ThisLayerUp() { TRACE("KPPPSM: ThisLayerUp() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); - // We begin with authentication phase and wait until each phase is done. // We stop when we reach established phase. @@ -1680,8 +1571,6 @@ KPPPStateMachine::ThisLayerUp() NewPhase(PPP_AUTHENTICATION_PHASE); - locker.UnlockNow(); - BringProtocolsUp(); } @@ -1739,10 +1628,8 @@ KPPPStateMachine::SendConfigureRequest() { TRACE("KPPPSM: SendConfigureRequest() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); --fRequestCounter; fNextTimeout = system_time() + kPPPStateMachineTimeout; - locker.UnlockNow(); KPPPConfigurePacket request(PPP_CONFIGURE_REQUEST); request.SetID(NextID()); @@ -1811,10 +1698,8 @@ KPPPStateMachine::SendTerminateRequest() { TRACE("KPPPSM: SendTerminateRequest() state=%d phase=%d\n", State(), Phase()); - LockerHelper locker(fLock); --fTerminateCounter; fNextTimeout = system_time() + kPPPStateMachineTimeout; - locker.UnlockNow(); struct mbuf *packet = m_gethdr(MT_DATA); if(!packet) @@ -1939,8 +1824,6 @@ KPPPStateMachine::BringProtocolsUp() if(BringPhaseUp() > 0) break; - LockerHelper locker(fLock); - if(Phase() < PPP_AUTHENTICATION_PHASE) return; // phase was changed by another event @@ -1961,8 +1844,6 @@ KPPPStateMachine::BringPhaseUp() // Servers do not need to bring all protocols up. // The client specifies which protocols he wants to go up. - LockerHelper locker(fLock); - // check for phase change if(Phase() < PPP_AUTHENTICATION_PHASE) return 0; diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h index 3907d60359..a2c22e50d7 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Haiku Inc. + * Copyright 2003-2006, Haiku Inc. * Distributed under the terms of the MIT License. */ @@ -42,7 +42,6 @@ struct ppp_interface_entry; class KPPPInterface : public KPPPLayer { friend class PPPManager; friend class KPPPStateMachine; - friend class KPPPInterfaceAccess; private: //! Copies are not allowed. @@ -201,7 +200,9 @@ class KPPPInterface : public KPPPLayer { // in server mode Up() listens for an incoming connection virtual bool Down(); bool WaitForConnection(); - bool IsUp() const; + //! Returns if the interface is connected. + bool IsUp() const + { return Phase() == PPP_ESTABLISHED_PHASE; } //! Returns interface's report manager. KPPPReportManager& ReportManager()