From fc1cf1a3d24bc28201c314c56be8d2816550f3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 27 Mar 2007 00:14:30 +0000 Subject: [PATCH] Style cleanup, patch by Vasilis Kaoutsis - thanks! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20430 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../libkernelppp/KPPPConfigurePacket.cpp | 32 +- .../ppp/shared/libkernelppp/KPPPDevice.cpp | 22 +- .../ppp/shared/libkernelppp/KPPPInterface.cpp | 509 +++++++++--------- .../ppp/shared/libkernelppp/KPPPLCP.cpp | 111 ++-- .../shared/libkernelppp/KPPPLCPExtension.cpp | 33 +- .../ppp/shared/libkernelppp/KPPPLayer.cpp | 10 +- .../shared/libkernelppp/KPPPOptionHandler.cpp | 39 +- .../ppp/shared/libkernelppp/KPPPProtocol.cpp | 53 +- .../shared/libkernelppp/KPPPReportManager.cpp | 40 +- .../shared/libkernelppp/KPPPStateMachine.cpp | 440 +++++++-------- .../ppp/shared/libkernelppp/KPPPUtils.cpp | 20 +- .../_KPPPAuthenticationHandler.cpp | 62 +-- .../shared/libkernelppp/_KPPPMRUHandler.cpp | 24 +- .../shared/libkernelppp/_KPPPPFCHandler.cpp | 22 +- .../shared/libkernelppp/settings_tools.cpp | 116 ++-- .../libppp/MessageDriverSettingsUtils.cpp | 64 +-- .../ppp/shared/libppp/PPPInterface.cpp | 36 +- .../shared/libppp/PPPInterfaceListener.cpp | 24 +- .../network/ppp/shared/libppp/PPPManager.cpp | 62 +-- .../ppp/shared/libppp/_libppputils.cpp | 4 +- .../network/ppp/shared/libppp/_libppputils.h | 2 +- 21 files changed, 872 insertions(+), 853 deletions(-) diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPConfigurePacket.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPConfigurePacket.cpp index 8c2fdb767e..bbe5e39e6f 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPConfigurePacket.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPConfigurePacket.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -33,21 +33,21 @@ KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet) ppp_lcp_packet *header = mtod(packet, ppp_lcp_packet*); SetID(header->id); - if(!SetCode(header->code)) + if (!SetCode(header->code)) return; uint16 length = ntohs(header->length); - if(length < 6 || length > packet->m_len) + if (length < 6 || length > packet->m_len) return; // there are no items (or one corrupted item) int32 position = 0; ppp_configure_item *item; - while(position < length - 4) { + while (position < length - 4) { item = (ppp_configure_item*) (header->data + position); - if(item->length < 2) + if (item->length < 2) return; // found a corrupted item @@ -60,7 +60,7 @@ KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet) //! Frees all items. KPPPConfigurePacket::~KPPPConfigurePacket() { - for(int32 index = 0; index < CountItems(); index++) + for (int32 index = 0; index < CountItems(); index++) free(ItemAt(index)); } @@ -70,7 +70,7 @@ bool KPPPConfigurePacket::SetCode(uint8 code) { // only configure codes are allowed! - if(code < PPP_CONFIGURE_REQUEST || code > PPP_CONFIGURE_REJECT) + if (code < PPP_CONFIGURE_REQUEST || code > PPP_CONFIGURE_REJECT) return false; fCode = code; @@ -94,18 +94,18 @@ KPPPConfigurePacket::SetCode(uint8 code) bool KPPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index) { - if(!item || item->length < 2) + if (!item || item->length < 2) return false; ppp_configure_item *add = (ppp_configure_item*) malloc(item->length); memcpy(add, item, item->length); bool status; - if(index < 0) + if (index < 0) status = fItems.AddItem(add); else status = fItems.AddItem(add, index); - if(!status) { + if (!status) { free(add); return false; } @@ -118,7 +118,7 @@ KPPPConfigurePacket::AddItem(const ppp_configure_item *item, int32 index) bool KPPPConfigurePacket::RemoveItem(ppp_configure_item *item) { - if(!fItems.HasItem(item)) + if (!fItems.HasItem(item)) return false; fItems.RemoveItem(item); @@ -134,7 +134,7 @@ KPPPConfigurePacket::ItemAt(int32 index) const { ppp_configure_item *item = fItems.ItemAt(index); - if(item == fItems.GetDefaultItem()) + if (item == fItems.GetDefaultItem()) return NULL; return item; @@ -147,9 +147,9 @@ KPPPConfigurePacket::ItemWithType(uint8 type) const { ppp_configure_item *item; - for(int32 index = 0; index < CountItems(); index++) { + for (int32 index = 0; index < CountItems(); index++) { item = ItemAt(index); - if(item && item->type == type) + if (item && item->type == type) return item; } @@ -180,11 +180,11 @@ KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve) uint16 length = 0; ppp_configure_item *item; - for(int32 index = 0; index < CountItems(); index++) { + for (int32 index = 0; index < CountItems(); index++) { item = ItemAt(index); // make sure we have enough space left - if(MRU - length < item->length) { + if (MRU - length < item->length) { m_freem(packet); return NULL; } diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPDevice.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPDevice.cpp index d40ee02477..c4adf9c77a 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPDevice.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPDevice.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -40,7 +40,7 @@ KPPPDevice::KPPPDevice(const char *name, uint32 overhead, KPPPInterface& interfa //! Destructor. Removes device from interface. KPPPDevice::~KPPPDevice() { - if(Interface().Device() == this) + if (Interface().Device() == this) Interface().SetDevice(NULL); } @@ -52,26 +52,26 @@ KPPPDevice::~KPPPDevice() status_t KPPPDevice::Control(uint32 op, void *data, size_t length) { - switch(op) { - case PPPC_GET_DEVICE_INFO: { - if(length < sizeof(ppp_device_info_t) || !data) + switch (op) { + case PPPC_GET_DEVICE_INFO: + if (length < sizeof(ppp_device_info_t) || !data) return B_NO_MEMORY; - + ppp_device_info *info = (ppp_device_info*) data; memset(info, 0, sizeof(ppp_device_info_t)); - if(Name()) + if (Name()) strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); info->MTU = MTU(); info->inputTransferRate = InputTransferRate(); info->outputTransferRate = OutputTransferRate(); info->outputBytesCount = CountOutputBytes(); info->isUp = IsUp(); - } break; - + break; + default: return B_BAD_VALUE; } - + return B_OK; } @@ -90,7 +90,7 @@ status_t KPPPDevice::Receive(struct mbuf *packet, uint16 protocolNumber) { // let the interface handle the packet - if(protocolNumber == 0) + if (protocolNumber == 0) return Interface().ReceiveFromDevice(packet); else return Interface().Receive(packet, protocolNumber); 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 85bce69c5f..db04a6358d 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-2006, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -77,9 +77,9 @@ status_t interface_deleter_thread(void *data); \param parent (Optional): Interface's parent (only used for multilink interfaces). */ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, - ppp_interface_id ID, const driver_settings *settings, - KPPPInterface *parent) - : KPPPLayer(name, PPP_INTERFACE_LEVEL, 2), + ppp_interface_id ID, const driver_settings *settings, KPPPInterface *parent) + : + KPPPLayer(name, PPP_INTERFACE_LEVEL, 2), fID(ID), fSettings(NULL), fIfnet(NULL), @@ -111,14 +111,14 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, { entry->interface = this; - if(name) { + if (name) { // load settings from description file char path[B_PATH_NAME_LENGTH]; sprintf(path, "ptpnet/%s", name); // XXX: TODO: change base path to "/etc/ptpnet" void *handle = load_driver_settings(path); - if(!handle) { + if (!handle) { fInitStatus = B_ERROR; return; } @@ -129,28 +129,28 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, fSettings = dup_driver_settings(settings); // use the given settings - if(!fSettings) { + if (!fSettings) { fInitStatus = B_ERROR; return; } // add internal modules // LCP - if(!AddProtocol(&LCP())) { + if (!AddProtocol(&LCP())) { fInitStatus = B_ERROR; return; } // MRU _KPPPMRUHandler *mruHandler = new _KPPPMRUHandler(*this); - if(!LCP().AddOptionHandler(mruHandler) || mruHandler->InitCheck() != B_OK) { + if (!LCP().AddOptionHandler(mruHandler) || mruHandler->InitCheck() != B_OK) { ERROR("KPPPInterface: Could not add MRU handler!\n"); delete mruHandler; } // authentication _KPPPAuthenticationHandler *authenticationHandler = new _KPPPAuthenticationHandler(*this); - if(!LCP().AddOptionHandler(authenticationHandler) + if (!LCP().AddOptionHandler(authenticationHandler) || authenticationHandler->InitCheck() != B_OK) { ERROR("KPPPInterface: Could not add authentication handler!\n"); delete authenticationHandler; @@ -158,7 +158,7 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, // PFC _KPPPPFCHandler *pfcHandler = new _KPPPPFCHandler(fLocalPFCState, fPeerPFCState, *this); - if(!LCP().AddOptionHandler(pfcHandler) || pfcHandler->InitCheck() != B_OK) { + if (!LCP().AddOptionHandler(pfcHandler) || pfcHandler->InitCheck() != B_OK) { ERROR("KPPPInterface: Could not add PFC handler!\n"); delete pfcHandler; } @@ -169,11 +169,11 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, fReconnectDelay = 1000; // 1s delay between lost connection and reconnect - if(get_module(PPP_INTERFACE_MODULE_NAME, (module_info**) &fManager) != B_OK) + if (get_module(PPP_INTERFACE_MODULE_NAME, (module_info**) &fManager) != B_OK) ERROR("KPPPInterface: Manager module not found!\n"); // are we a multilink subinterface? - if(parent && parent->IsMultilink()) { + if (parent && parent->IsMultilink()) { fParent = parent; fParent->AddChild(this); fIsMultilink = true; @@ -181,7 +181,7 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, RegisterInterface(); - if(!fSettings) { + if (!fSettings) { fInitStatus = B_ERROR; return; } @@ -196,17 +196,17 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, // get DisonnectAfterIdleSince settings value = get_settings_value(PPP_DISONNECT_AFTER_IDLE_SINCE_KEY, fSettings); - if(!value) + if (!value) fDisconnectAfterIdleSince = 0; else fDisconnectAfterIdleSince = atoi(value) * 1000; - if(fDisconnectAfterIdleSince < 0) + if (fDisconnectAfterIdleSince < 0) fDisconnectAfterIdleSince = 0; // get mode settings value = get_settings_value(PPP_MODE_KEY, fSettings); - if(value && !strcasecmp(value, PPP_SERVER_MODE_VALUE)) + if (value && !strcasecmp(value, PPP_SERVER_MODE_VALUE)) fMode = PPP_SERVER_MODE; else fMode = PPP_CLIENT_MODE; @@ -223,7 +223,7 @@ KPPPInterface::KPPPInterface(const char *name, ppp_interface_entry *entry, get_settings_value(PPP_ASK_BEFORE_CONNECTING_KEY, fSettings), false); // load all protocols and the device - if(!LoadModules(fSettings, 0, fSettings->parameter_count)) { + if (!LoadModules(fSettings, 0, fSettings->parameter_count)) { ERROR("KPPPInterface: Error loading modules!\n"); fInitStatus = B_ERROR; } @@ -237,21 +237,21 @@ KPPPInterface::~KPPPInterface() // tell protocols to uninit (remove routes, etc.) KPPPProtocol *protocol = FirstProtocol(); - for(; protocol; protocol = protocol->NextProtocol()) + for (; protocol; protocol = protocol->NextProtocol()) protocol->Uninit(); // make sure we are not accessible by any thread before we continue UnregisterInterface(); - if(fManager) + if (fManager) fManager->RemoveInterface(ID()); // Call Down() until we get a lock on an interface that is down. // This lock is not released until we are actually deleted. - while(true) { + while (true) { Down(); fLock.Lock(); - if(State() == PPP_INITIAL_STATE && Phase() == PPP_DOWN_PHASE) + if (State() == PPP_INITIAL_STATE && Phase() == PPP_DOWN_PHASE) break; fLock.Unlock(); } @@ -264,30 +264,30 @@ KPPPInterface::~KPPPInterface() // tell thread that we are being destroyed (200ms timeout) wait_for_thread(fReconnectThread, &tmp); - while(CountChildren()) + while (CountChildren()) delete ChildAt(0); delete Device(); - while(FirstProtocol()) { - if(FirstProtocol() == &LCP()) + while (FirstProtocol()) { + if (FirstProtocol() == &LCP()) fFirstProtocol = fFirstProtocol->NextProtocol(); else delete FirstProtocol(); // destructor removes protocol from list } - for(int32 index = 0; index < fModules.CountItems(); index++) { + for (int32 index = 0; index < fModules.CountItems(); index++) { put_module(fModules.ItemAt(index)); delete[] fModules.ItemAt(index); } free_driver_settings(fSettings); - if(Parent()) + if (Parent()) Parent()->RemoveChild(this); - if(fManager) + if (fManager) put_module(PPP_INTERFACE_MODULE_NAME); } @@ -298,7 +298,7 @@ KPPPInterface::Delete() { LockerHelper locker(fLock); - if(fDeleteCounter > 0) + if (fDeleteCounter > 0) return; // only one thread should delete us! @@ -314,17 +314,17 @@ KPPPInterface::Delete() status_t KPPPInterface::InitCheck() const { - if(fInitStatus != B_OK) + if (fInitStatus != B_OK) return fInitStatus; - if(!fSettings || !fManager) + if (!fSettings || !fManager) return B_ERROR; // sub-interfaces should have a device - if(IsMultilink()) { - if(Parent() && !fDevice) + if (IsMultilink()) { + if (Parent() && !fDevice) return B_ERROR; - } else if(!fDevice) + } else if (!fDevice) return B_ERROR; return B_OK; @@ -336,7 +336,7 @@ const char* KPPPInterface::Username() const { // this data is not available before we authenticate - if(Phase() < PPP_AUTHENTICATION_PHASE) + if (Phase() < PPP_AUTHENTICATION_PHASE) return NULL; return fUsername; @@ -348,7 +348,7 @@ const char* KPPPInterface::Password() const { // this data is not available before we authenticate - if(Phase() < PPP_AUTHENTICATION_PHASE) + if (Phase() < PPP_AUTHENTICATION_PHASE) return NULL; return fPassword; @@ -361,7 +361,7 @@ KPPPInterface::SetMRU(uint32 MRU) { TRACE("KPPPInterface: SetMRU(%ld)\n", MRU); - if(Device() && MRU > Device()->MTU() - 2) + if (Device() && MRU > Device()->MTU() - 2) return false; LockerHelper locker(fLock); @@ -380,7 +380,7 @@ KPPPInterface::PacketOverhead() const { uint32 overhead = fHeaderLength + 2; - if(Device()) + if (Device()) overhead += Device()->Overhead(); return overhead; @@ -406,16 +406,17 @@ KPPPInterface::PacketOverhead() const status_t KPPPInterface::Control(uint32 op, void *data, size_t length) { - switch(op) { - case PPPC_GET_INTERFACE_INFO: { - if(length < sizeof(ppp_interface_info_t) || !data) + switch (op) { + case PPPC_GET_INTERFACE_INFO: + { + if (length < sizeof(ppp_interface_info_t) || !data) return B_ERROR; - + ppp_interface_info *info = (ppp_interface_info*) data; memset(info, 0, sizeof(ppp_interface_info_t)); - if(Name()) + if (Name()) strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); - if(Ifnet()) + if (Ifnet()) info->if_unit = Ifnet()->if_unit; else info->if_unit = -1; @@ -447,168 +448,182 @@ KPPPInterface::Control(uint32 op, void *data, size_t length) info->hasDevice = Device(); info->isMultilink = IsMultilink(); info->hasParent = Parent(); - } break; - - case PPPC_SET_USERNAME: { - if(!data) + break; + } + + case PPPC_SET_USERNAME: + { + if (!data) return B_ERROR; - + LockerHelper locker(fLock); // login information can only be changed before we authenticate - if(Phase() >= PPP_AUTHENTICATION_PHASE) + if (Phase() >= PPP_AUTHENTICATION_PHASE) return B_NOT_ALLOWED; - + free(fUsername); fUsername = data ? strdup((const char*) data) : strdup(""); - } break; - - case PPPC_SET_PASSWORD: { - if(!data) + break; + } + + case PPPC_SET_PASSWORD: + { + if (!data) return B_ERROR; LockerHelper locker(fLock); // login information can only be changed before we authenticate - if(Phase() >= PPP_AUTHENTICATION_PHASE) + if (Phase() >= PPP_AUTHENTICATION_PHASE) return B_NOT_ALLOWED; free(fPassword); fPassword = data ? strdup((const char*) data) : strdup(""); - } break; - + break; + } + case PPPC_SET_ASK_BEFORE_CONNECTING: - if(length < sizeof(uint32) || !data) + if (length < sizeof(uint32) || !data) return B_ERROR; - + SetAskBeforeConnecting(*((uint32*)data)); - break; - + break; + case PPPC_SET_MRU: - if(length < sizeof(uint32) || !data) + if (length < sizeof(uint32) || !data) return B_ERROR; - + SetMRU(*((uint32*)data)); - break; - + break; + case PPPC_SET_CONNECT_ON_DEMAND: - if(length < sizeof(uint32) || !data) + if (length < sizeof(uint32) || !data) return B_ERROR; - + SetConnectOnDemand(*((uint32*)data)); - break; - + break; + case PPPC_SET_AUTO_RECONNECT: - if(length < sizeof(uint32) || !data) + if (length < sizeof(uint32) || !data) return B_ERROR; SetAutoReconnect(*((uint32*)data)); - break; - + break; + case PPPC_HAS_INTERFACE_SETTINGS: - if(length < sizeof(driver_settings) || !data) + if (length < sizeof(driver_settings) || !data) return B_ERROR; - - if(equal_interface_settings(Settings(), (driver_settings*) data)) + + if (equal_interface_settings(Settings(), (driver_settings*) data)) return B_OK; else return B_ERROR; - break; - - case PPPC_ENABLE_REPORTS: { - if(length < sizeof(ppp_report_request) || !data) + break; + + case PPPC_ENABLE_REPORTS: + { + if (length < sizeof(ppp_report_request) || !data) return B_ERROR; - + LockerHelper locker(fLock); ppp_report_request *request = (ppp_report_request*) data; // first, we send an initial state report - if(request->type == PPP_CONNECTION_REPORT) { + if (request->type == PPP_CONNECTION_REPORT) { ppp_report_packet report; report.type = PPP_CONNECTION_REPORT; report.code = StateMachine().fLastConnectionReportCode; report.length = sizeof(fID); KPPPReportManager::SendReport(request->thread, &report); - if(request->flags & PPP_REMOVE_AFTER_REPORT) + if (request->flags & PPP_REMOVE_AFTER_REPORT) return B_OK; } ReportManager().EnableReports(request->type, request->thread, request->flags); - } break; - - case PPPC_DISABLE_REPORTS: { - if(length < sizeof(ppp_report_request) || !data) + break; + } + + case PPPC_DISABLE_REPORTS: + { + if (length < sizeof(ppp_report_request) || !data) return B_ERROR; - + ppp_report_request *request = (ppp_report_request*) data; ReportManager().DisableReports(request->type, request->thread); - } break; - - case PPPC_GET_STATISTICS: { - if(length < sizeof(ppp_statistics) || !data) + break; + } + + case PPPC_GET_STATISTICS: + if (length < sizeof(ppp_statistics) || !data) return B_ERROR; - + memcpy(data, &fStatistics, sizeof(ppp_statistics)); - } break; - - case PPPC_CONTROL_DEVICE: { - if(length < sizeof(ppp_control_info) || !data) + break; + + case PPPC_CONTROL_DEVICE: + { + if (length < sizeof(ppp_control_info) || !data) return B_ERROR; ppp_control_info *control = (ppp_control_info*) data; - if(control->index != 0 || !Device()) + if (control->index != 0 || !Device()) return B_BAD_INDEX; - + return Device()->Control(control->op, control->data, control->length); - } break; - - case PPPC_CONTROL_PROTOCOL: { - if(length < sizeof(ppp_control_info) || !data) + } + + case PPPC_CONTROL_PROTOCOL: + { + if (length < sizeof(ppp_control_info) || !data) return B_ERROR; ppp_control_info *control = (ppp_control_info*) data; KPPPProtocol *protocol = ProtocolAt(control->index); - if(!protocol) + if (!protocol) return B_BAD_INDEX; return protocol->Control(control->op, control->data, control->length); - } break; - - case PPPC_CONTROL_OPTION_HANDLER: { - if(length < sizeof(ppp_control_info) || !data) + } + + case PPPC_CONTROL_OPTION_HANDLER: + { + if (length < sizeof(ppp_control_info) || !data) return B_ERROR; - + ppp_control_info *control = (ppp_control_info*) data; KPPPOptionHandler *optionHandler = LCP().OptionHandlerAt(control->index); - if(!optionHandler) + if (!optionHandler) return B_BAD_INDEX; - + return optionHandler->Control(control->op, control->data, control->length); - } break; - - case PPPC_CONTROL_LCP_EXTENSION: { - if(length < sizeof(ppp_control_info) || !data) + } + + case PPPC_CONTROL_LCP_EXTENSION: + { + if (length < sizeof(ppp_control_info) || !data) return B_ERROR; - + ppp_control_info *control = (ppp_control_info*) data; KPPPLCPExtension *lcpExtension = LCP().LCPExtensionAt(control->index); - if(!lcpExtension) + if (!lcpExtension) return B_BAD_INDEX; - + return lcpExtension->Control(control->op, control->data, control->length); - } break; - - case PPPC_CONTROL_CHILD: { - if(length < sizeof(ppp_control_info) || !data) + } + + case PPPC_CONTROL_CHILD: + { + if (length < sizeof(ppp_control_info) || !data) return B_ERROR; - + ppp_control_info *control = (ppp_control_info*) data; KPPPInterface *child = ChildAt(control->index); - if(!child) + if (!child) return B_BAD_INDEX; - + return child->Control(control->op, control->data, control->length); - } break; - + } + default: return B_BAD_VALUE; } @@ -634,26 +649,26 @@ KPPPInterface::SetDevice(KPPPDevice *device) { TRACE("KPPPInterface: SetDevice(%p)\n", device); - if(device && &device->Interface() != this) + if (device && &device->Interface() != this) return false; - if(IsMultilink() && !Parent()) + if (IsMultilink() && !Parent()) return false; // main interfaces do not have devices LockerHelper locker(fLock); - if(Phase() != PPP_DOWN_PHASE) + if (Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change - if(fDevice && (IsUp() || fDevice->IsUp())) + if (fDevice && (IsUp() || fDevice->IsUp())) Down(); fDevice = device; SetNext(device); - if(fDevice) + if (fDevice) fMRU = fDevice->MTU() - 2; CalculateInterfaceMTU(); @@ -685,28 +700,28 @@ KPPPInterface::AddProtocol(KPPPProtocol *protocol) TRACE("KPPPInterface: AddProtocol(%X)\n", protocol ? protocol->ProtocolNumber() : 0); - if(!protocol || &protocol->Interface() != this + if (!protocol || &protocol->Interface() != this || protocol->Level() == PPP_INTERFACE_LEVEL) return false; LockerHelper locker(fLock); - if(Phase() != PPP_DOWN_PHASE) + if (Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change KPPPProtocol *current = fFirstProtocol, *previous = NULL; - while(current) { - if(current->Level() < protocol->Level()) + while (current) { + if (current->Level() < protocol->Level()) break; previous = current; current = current->NextProtocol(); } - if(!current) { - if(!previous) + if (!current) { + if (!previous) fFirstProtocol = protocol; else previous->SetNextProtocol(protocol); @@ -719,16 +734,16 @@ KPPPInterface::AddProtocol(KPPPProtocol *protocol) } else { protocol->SetNextProtocol(current); - if(!previous) + if (!previous) fFirstProtocol = protocol; else previous->SetNextProtocol(protocol); } - if(protocol->Level() < PPP_PROTOCOL_LEVEL) + if (protocol->Level() < PPP_PROTOCOL_LEVEL) CalculateInterfaceMTU(); - if(IsUp() || Phase() >= protocol->ActivationPhase()) + if (IsUp() || Phase() >= protocol->ActivationPhase()) protocol->Up(); return true; @@ -755,22 +770,22 @@ KPPPInterface::RemoveProtocol(KPPPProtocol *protocol) LockerHelper locker(fLock); - if(Phase() != PPP_DOWN_PHASE) + if (Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change KPPPProtocol *current = fFirstProtocol, *previous = NULL; - while(current) { - if(current == protocol) { - if(!protocol->IsDown()) + while (current) { + if (current == protocol) { + if (!protocol->IsDown()) protocol->Down(); - if(previous) { + if (previous) { previous->SetNextProtocol(current->NextProtocol()); // set us as next layer if needed - if(!previous->Next()) + if (!previous->Next()) previous->SetNext(this); } else fFirstProtocol = current->NextProtocol(); @@ -799,7 +814,7 @@ KPPPInterface::CountProtocols() const KPPPProtocol *protocol = FirstProtocol(); int32 count = 0; - for(; protocol; protocol = protocol->NextProtocol()) + for (; protocol; protocol = protocol->NextProtocol()) ++count; return count; @@ -815,7 +830,7 @@ KPPPInterface::ProtocolAt(int32 index) const KPPPProtocol *protocol = FirstProtocol(); int32 currentIndex = 0; - for(; protocol && currentIndex != index; protocol = protocol->NextProtocol()) + for (; protocol && currentIndex != index; protocol = protocol->NextProtocol()) ++currentIndex; return protocol; @@ -838,8 +853,8 @@ KPPPInterface::ProtocolFor(uint16 protocolNumber, KPPPProtocol *start) const KPPPProtocol *current = start ? start : FirstProtocol(); - for(; current; current = current->NextProtocol()) { - if(current->ProtocolNumber() == protocolNumber + for (; current; current = current->NextProtocol()) { + if (current->ProtocolNumber() == protocolNumber || (current->Flags() & PPP_INCLUDES_NCP && (current->ProtocolNumber() & 0x7FFF) == (protocolNumber & 0x7FFF))) @@ -856,12 +871,12 @@ KPPPInterface::AddChild(KPPPInterface *child) { TRACE("KPPPInterface: AddChild(%lX)\n", child ? child->ID() : 0); - if(!child) + if (!child) return false; LockerHelper locker(fLock); - if(fChildren.HasItem(child) || !fChildren.AddItem(child)) + if (fChildren.HasItem(child) || !fChildren.AddItem(child)) return false; child->SetParent(this); @@ -878,13 +893,13 @@ KPPPInterface::RemoveChild(KPPPInterface *child) LockerHelper locker(fLock); - if(!fChildren.RemoveItem(child)) + if (!fChildren.RemoveItem(child)) return false; child->SetParent(NULL); // parents cannot exist without their children - if(CountChildren() == 0 && fManager && Ifnet()) + if (CountChildren() == 0 && fManager && Ifnet()) Delete(); return true; @@ -901,7 +916,7 @@ KPPPInterface::ChildAt(int32 index) const KPPPInterface *child = fChildren.ItemAt(index); - if(child == fChildren.GetDefaultItem()) + if (child == fChildren.GetDefaultItem()) return NULL; return child; @@ -914,7 +929,7 @@ KPPPInterface::SetAutoReconnect(bool autoReconnect) { TRACE("KPPPInterface: SetAutoReconnect(%s)\n", autoReconnect ? "true" : "false"); - if(Mode() != PPP_CLIENT_MODE) + if (Mode() != PPP_CLIENT_MODE) return; fAutoReconnect = autoReconnect; @@ -933,11 +948,11 @@ KPPPInterface::SetConnectOnDemand(bool connectOnDemand) LockerHelper locker(fLock); // Only clients support ConnectOnDemand. - if(Mode() != PPP_CLIENT_MODE) { + if (Mode() != PPP_CLIENT_MODE) { TRACE("KPPPInterface::SetConnectOnDemand(): Wrong mode!\n"); fConnectOnDemand = false; return; - } else if(DoesConnectOnDemand() == connectOnDemand) + } else if (DoesConnectOnDemand() == connectOnDemand) return; fConnectOnDemand = connectOnDemand; @@ -947,8 +962,8 @@ KPPPInterface::SetConnectOnDemand(bool connectOnDemand) // - enabling: this cannot happen because hidden interfaces are deleted if they // could not establish a connection (the user cannot access hidden interfaces) // - disabling: the interface disappears as seen from the user, so we delete it - if(!Parent() && State() == PPP_INITIAL_STATE && Phase() == PPP_DOWN_PHASE) { - if(!connectOnDemand) + if (!Parent() && State() == PPP_INITIAL_STATE && Phase() == PPP_DOWN_PHASE) { + if (!connectOnDemand) Delete(); // as long as the protocols were not configured we can just delete us @@ -956,11 +971,11 @@ KPPPInterface::SetConnectOnDemand(bool connectOnDemand) } // check if we need to set/unset flags - if(connectOnDemand) { - if(Ifnet()) + if (connectOnDemand) { + if (Ifnet()) Ifnet()->if_flags |= IFF_UP; - } else if(!connectOnDemand && Phase() < PPP_ESTABLISHED_PHASE) { - if(Ifnet()) + } else if (!connectOnDemand && Phase() < PPP_ESTABLISHED_PHASE) { + if (Ifnet()) Ifnet()->if_flags &= ~IFF_UP; } } @@ -975,7 +990,7 @@ KPPPInterface::SetAskBeforeConnecting(bool ask) bool old = fAskBeforeConnecting; fAskBeforeConnecting = ask; - if(old && fAskBeforeConnecting == false && State() == PPP_STARTING_STATE + if (old && fAskBeforeConnecting == false && State() == PPP_STARTING_STATE && Phase() == PPP_DOWN_PHASE) { locker.UnlockNow(); StateMachine().ContinueOpenEvent(); @@ -991,7 +1006,7 @@ KPPPInterface::SetPFCOptions(uint8 pfcOptions) LockerHelper locker(fLock); - if(PFCOptions() & PPP_FREEZE_PFC_OPTIONS) + if (PFCOptions() & PPP_FREEZE_PFC_OPTIONS) return false; fPFCOptions = pfcOptions; @@ -1011,10 +1026,10 @@ KPPPInterface::Up() { TRACE("KPPPInterface: Up()\n"); - if(InitCheck() != B_OK || Phase() == PPP_TERMINATION_PHASE) + if (InitCheck() != B_OK || Phase() == PPP_TERMINATION_PHASE) return false; - if(IsUp()) + if (IsUp()) return true; LockerHelper locker(fLock); @@ -1036,9 +1051,9 @@ KPPPInterface::Down() { TRACE("KPPPInterface: Down()\n"); - if(InitCheck() != B_OK) + if (InitCheck() != B_OK) return false; - else if(State() == PPP_INITIAL_STATE && Phase() == PPP_DOWN_PHASE) + else if (State() == PPP_INITIAL_STATE && Phase() == PPP_DOWN_PHASE) return true; send_data_with_timeout(fReconnectThread, 0, NULL, 0, 200); @@ -1057,7 +1072,7 @@ KPPPInterface::WaitForConnection() { TRACE("KPPPInterface: WaitForConnection()\n"); - if(InitCheck() != B_OK) + if (InitCheck() != B_OK) return false; ReportManager().EnableReports(PPP_CONNECTION_REPORT, find_thread(NULL)); @@ -1065,19 +1080,19 @@ KPPPInterface::WaitForConnection() ppp_report_packet report; thread_id sender; bool successful = false; - while(true) { - if(receive_data(&sender, &report, sizeof(report)) != PPP_REPORT_CODE) + while (true) { + if (receive_data(&sender, &report, sizeof(report)) != PPP_REPORT_CODE) continue; - if(report.type == PPP_DESTRUCTION_REPORT) + if (report.type == PPP_DESTRUCTION_REPORT) break; - else if(report.type != PPP_CONNECTION_REPORT) + else if (report.type != PPP_CONNECTION_REPORT) continue; - if(report.code == PPP_REPORT_UP_SUCCESSFUL) { + if (report.code == PPP_REPORT_UP_SUCCESSFUL) { successful = true; break; - } else if(report.code == PPP_REPORT_DOWN_SUCCESSFUL) + } else if (report.code == PPP_REPORT_DOWN_SUCCESSFUL) break; } @@ -1099,7 +1114,7 @@ KPPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count) { TRACE("KPPPInterface: LoadModules()\n"); - if(Phase() != PPP_DOWN_PHASE) + if (Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change @@ -1109,11 +1124,11 @@ KPPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count) const char *name = NULL; // multilink handling - for(int32 index = start; + for (int32 index = start; index < settings->parameter_count && index < (start + count); index++) { - if(!strcasecmp(settings->parameters[index].name, PPP_MULTILINK_KEY) + if (!strcasecmp(settings->parameters[index].name, PPP_MULTILINK_KEY) && settings->parameters[index].value_count > 0) { - if(!LoadModule(settings->parameters[index].values[0], + if (!LoadModule(settings->parameters[index].values[0], &settings->parameters[index], PPP_MULTILINK_KEY_TYPE)) return false; break; @@ -1121,32 +1136,32 @@ KPPPInterface::LoadModules(driver_settings *settings, int32 start, int32 count) } // are we a multilink main interface? - if(IsMultilink() && !Parent()) { + if (IsMultilink() && !Parent()) { // main interfaces only load the multilink module // and create a child using their settings fManager->CreateInterface(settings, ID()); return true; } - for(int32 index = start; + for (int32 index = start; index < settings->parameter_count && index < start + count; index++) { type = PPP_UNDEFINED_KEY_TYPE; name = settings->parameters[index].name; - if(!strcasecmp(name, PPP_LOAD_MODULE_KEY)) + if (!strcasecmp(name, PPP_LOAD_MODULE_KEY)) type = PPP_LOAD_MODULE_KEY_TYPE; - else if(!strcasecmp(name, PPP_DEVICE_KEY)) + else if (!strcasecmp(name, PPP_DEVICE_KEY)) type = PPP_DEVICE_KEY_TYPE; - else if(!strcasecmp(name, PPP_PROTOCOL_KEY)) + else if (!strcasecmp(name, PPP_PROTOCOL_KEY)) type = PPP_PROTOCOL_KEY_TYPE; - else if(!strcasecmp(name, PPP_AUTHENTICATOR_KEY)) + else if (!strcasecmp(name, PPP_AUTHENTICATOR_KEY)) type = PPP_AUTHENTICATOR_KEY_TYPE; - if(type >= 0) - for(int32 value_id = 0; value_id < settings->parameters[index].value_count; + if (type >= 0) + for (int32 value_id = 0; value_id < settings->parameters[index].value_count; value_id++) - if(!LoadModule(settings->parameters[index].values[value_id], + if (!LoadModule(settings->parameters[index].values[value_id], &settings->parameters[index], type)) return false; } @@ -1169,11 +1184,11 @@ KPPPInterface::LoadModule(const char *name, driver_parameter *parameter, { TRACE("KPPPInterface: LoadModule(%s)\n", name ? name : "XXX: NO NAME"); - if(Phase() != PPP_DOWN_PHASE) + if (Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change - if(!name || strlen(name) > B_FILE_NAME_LENGTH) + if (!name || strlen(name) > B_FILE_NAME_LENGTH) return false; char *moduleName = new char[B_PATH_NAME_LENGTH]; @@ -1181,7 +1196,7 @@ KPPPInterface::LoadModule(const char *name, driver_parameter *parameter, sprintf(moduleName, "%s/%s", PPP_MODULES_PATH, name); ppp_module_info *module; - if(get_module(moduleName, (module_info**) &module) != B_OK) { + if (get_module(moduleName, (module_info**) &module) != B_OK) { delete[] moduleName; return false; } @@ -1222,13 +1237,13 @@ KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) { TRACE("KPPPInterface: Send(0x%X)\n", protocolNumber); - if(!packet) + if (!packet) return B_ERROR; // we must pass the basic tests like: // do we have a device? // did we load all modules? - if(InitCheck() != B_OK) { + if (InitCheck() != B_OK) { m_freem(packet); return B_ERROR; } @@ -1236,7 +1251,7 @@ 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() + if ((protocolNumber != PPP_LCP_PROTOCOL && DoesConnectOnDemand() && (Phase() == PPP_DOWN_PHASE || Phase() == PPP_ESTABLISHMENT_PHASE) && !Up()) || !WaitForConnection()) { @@ -1246,25 +1261,25 @@ KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) // find the protocol handler for the current protocol number KPPPProtocol *protocol = ProtocolFor(protocolNumber); - while(protocol && !protocol->IsEnabled()) + while (protocol && !protocol->IsEnabled()) protocol = protocol->NextProtocol() ? ProtocolFor(protocolNumber, protocol->NextProtocol()) : NULL; #if DEBUG - if(!protocol) + if (!protocol) TRACE("KPPPInterface::Send(): no protocol found!\n"); - else if(!Device()->IsUp()) + else if (!Device()->IsUp()) TRACE("KPPPInterface::Send(): device is not up!\n"); - else if(!protocol->IsEnabled()) + else if (!protocol->IsEnabled()) TRACE("KPPPInterface::Send(): protocol not enabled!\n"); - else if(!IsProtocolAllowed(*protocol)) + else if (!IsProtocolAllowed(*protocol)) TRACE("KPPPInterface::Send(): protocol not allowed to send!\n"); else TRACE("KPPPInterface::Send(): protocol allowed\n"); #endif // make sure that protocol is allowed to send and everything is up - if(!Device()->IsUp() || !protocol || !protocol->IsEnabled() + if (!Device()->IsUp() || !protocol || !protocol->IsEnabled() || !IsProtocolAllowed(*protocol)) { ERROR("KPPPInterface::Send(): cannot send!\n"); m_freem(packet); @@ -1272,10 +1287,10 @@ KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) } // encode in ppp frame and consider using PFC - if(UseLocalPFC() && protocolNumber & 0xFF00 == 0) { + if (UseLocalPFC() && protocolNumber & 0xFF00 == 0) { M_PREPEND(packet, 1); - if(packet == NULL) + if (packet == NULL) return B_ERROR; uint8 *header = mtod(packet, uint8*); @@ -1283,7 +1298,7 @@ KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) } else { M_PREPEND(packet, 2); - if(packet == NULL) + if (packet == NULL) return B_ERROR; // set protocol (the only header field) @@ -1293,12 +1308,12 @@ KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) } // pass to device if we're either not a multilink interface or a child interface - if(!IsMultilink() || Parent()) { + if (!IsMultilink() || Parent()) { // check if packet is too big for device uint32 length = packet->m_flags & M_PKTHDR ? (uint32) packet->m_pkthdr.len : packet->m_len; - if(length > MRU()) { + if (length > MRU()) { m_freem(packet); return B_ERROR; } @@ -1337,7 +1352,7 @@ KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber) { TRACE("KPPPInterface: Receive(0x%X)\n", protocolNumber); - if(!packet) + if (!packet) return B_ERROR; LockerHelper locker(fLock); @@ -1350,7 +1365,7 @@ KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber) // interface is a main interface and at the same time not registered // because then there is no receiver interface. // PPP NCPs should be aware of that! - if(packet->m_flags & M_PKTHDR && Ifnet() != NULL) + if (packet->m_flags & M_PKTHDR && Ifnet() != NULL) packet->m_pkthdr.rcvif = Ifnet(); // Find handler and let it parse the packet. @@ -1358,17 +1373,17 @@ KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber) // the handler might be upped by this packet. // If authenticating we only allow authentication phase protocols. KPPPProtocol *protocol = ProtocolFor(protocolNumber); - for(; protocol; + for (; protocol; protocol = protocol->NextProtocol() ? ProtocolFor(protocolNumber, protocol->NextProtocol()) : NULL) { TRACE("KPPPInterface::Receive(): trying protocol\n"); - if(!protocol->IsEnabled() || !IsProtocolAllowed(*protocol)) + if (!protocol->IsEnabled() || !IsProtocolAllowed(*protocol)) continue; // skip handler if disabled or not allowed result = protocol->Receive(packet, protocolNumber); - if(result == PPP_UNHANDLED) + if (result == PPP_UNHANDLED) continue; return result; @@ -1377,10 +1392,10 @@ KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber) TRACE("KPPPInterface::Receive(): trying parent\n"); // maybe the parent interface can handle the packet - if(Parent()) + if (Parent()) return Parent()->Receive(packet, protocolNumber); - if(result == PPP_UNHANDLED) { + if (result == PPP_UNHANDLED) { m_freem(packet); return PPP_DISCARDED; } else { @@ -1408,10 +1423,10 @@ KPPPInterface::ReceiveFromDevice(struct mbuf *packet) { TRACE("KPPPInterface: ReceiveFromDevice()\n"); - if(!packet) + if (!packet) return B_ERROR; - if(InitCheck() != B_OK) { + if (InitCheck() != B_OK) { m_freem(packet); return B_ERROR; } @@ -1421,7 +1436,7 @@ KPPPInterface::ReceiveFromDevice(struct mbuf *packet) // decode ppp frame and recognize PFC uint16 protocolNumber = *mtod(packet, uint8*); - if(protocolNumber & 1) { + if (protocolNumber & 1) { m_adj(packet, 1); } else { protocolNumber = ntohs(*mtod(packet, uint16*)); @@ -1440,21 +1455,21 @@ KPPPInterface::Pulse() { LockerHelper locker(fLock); - if(Device()) + if (Device()) Device()->Pulse(); KPPPProtocol *protocol = FirstProtocol(); - for(; protocol; protocol = protocol->NextProtocol()) + for (; protocol; protocol = protocol->NextProtocol()) protocol->Pulse(); uint32 currentTime = real_time_clock(); - if(fUpdateIdleSince) { + if (fUpdateIdleSince) { fIdleSince = currentTime; fUpdateIdleSince = false; } // check our idle time and disconnect if needed - if(fDisconnectAfterIdleSince > 0 && fIdleSince != 0 + if (fDisconnectAfterIdleSince > 0 && fIdleSince != 0 && fIdleSince - currentTime >= fDisconnectAfterIdleSince) StateMachine().CloseEvent(); } @@ -1466,25 +1481,25 @@ KPPPInterface::RegisterInterface() { TRACE("KPPPInterface: RegisterInterface()\n"); - if(fIfnet) + if (fIfnet) return true; // we are already registered LockerHelper locker(fLock); // only MainInterfaces get an ifnet - if(IsMultilink() && Parent() && Parent()->RegisterInterface()) + if (IsMultilink() && Parent() && Parent()->RegisterInterface()) return true; - if(!fManager) + if (!fManager) return false; fIfnet = fManager->RegisterInterface(ID()); - if(!fIfnet) + if (!fIfnet) return false; - if(DoesConnectOnDemand()) + if (DoesConnectOnDemand()) fIfnet->if_flags |= IFF_UP; CalculateInterfaceMTU(); @@ -1500,17 +1515,17 @@ KPPPInterface::UnregisterInterface() { TRACE("KPPPInterface: UnregisterInterface()\n"); - if(!fIfnet) + if (!fIfnet) return true; // we are already unregistered LockerHelper locker(fLock); // only MainInterfaces get an ifnet - if(IsMultilink() && Parent()) + if (IsMultilink() && Parent()) return true; - if(!fManager) + if (!fManager) return false; fManager->UnregisterInterface(ID()); @@ -1527,7 +1542,7 @@ KPPPInterface::StackControl(uint32 op, void *data) { TRACE("KPPPInterface: StackControl(0x%lX)\n", op); - switch(op) { + switch (op) { default: return StackControlEachHandler(op, data); } @@ -1544,12 +1559,12 @@ class CallStackControl { : fOp(op), fData(data), fResult(result) {} inline void operator() (T *item) { - if(!item || !item->IsEnabled()) + if (!item || !item->IsEnabled()) return; status_t tmp = item->StackControl(fOp, fData); - if(tmp == B_OK && fResult == B_BAD_VALUE) + if (tmp == B_OK && fResult == B_BAD_VALUE) fResult = B_OK; - else if(tmp != B_BAD_VALUE) + else if (tmp != B_BAD_VALUE) fResult = tmp; } private: @@ -1575,11 +1590,11 @@ KPPPInterface::StackControlEachHandler(uint32 op, void *data) LockerHelper locker(fLock); KPPPProtocol *protocol = FirstProtocol(); - for(; protocol; protocol = protocol->NextProtocol()) { + for (; protocol; protocol = protocol->NextProtocol()) { tmp = protocol->StackControl(op, data); - if(tmp == B_OK && result == B_BAD_VALUE) + if (tmp == B_OK && result == B_BAD_VALUE) result = B_OK; - else if(tmp != B_BAD_VALUE) + else if (tmp != B_BAD_VALUE) result = tmp; } @@ -1605,19 +1620,19 @@ KPPPInterface::CalculateInterfaceMTU() // sum all headers (the protocol field is not counted) KPPPProtocol *protocol = FirstProtocol(); - for(; protocol; protocol = protocol->NextProtocol()) { - if(protocol->Level() < PPP_PROTOCOL_LEVEL) + for (; protocol; protocol = protocol->NextProtocol()) { + if (protocol->Level() < PPP_PROTOCOL_LEVEL) fHeaderLength += protocol->Overhead(); } fInterfaceMTU -= fHeaderLength; - if(Ifnet()) { + if (Ifnet()) { Ifnet()->if_mtu = fInterfaceMTU; Ifnet()->if_hdrlen = fHeaderLength; } - if(Parent()) + if (Parent()) Parent()->CalculateInterfaceMTU(); } @@ -1630,16 +1645,16 @@ KPPPInterface::CalculateBaudRate() LockerHelper locker(fLock); - if(!Ifnet()) + if (!Ifnet()) return; - if(Device()) + if (Device()) fIfnet->if_baudrate = max_c(Device()->InputTransferRate(), Device()->OutputTransferRate()); else { fIfnet->if_baudrate = 0; - for(int32 index = 0; index < CountChildren(); index++) - if(ChildAt(index)->Ifnet()) + for (int32 index = 0; index < CountChildren(); index++) + if (ChildAt(index)->Ifnet()) fIfnet->if_baudrate += ChildAt(index)->Ifnet()->if_baudrate; } } @@ -1653,7 +1668,7 @@ KPPPInterface::Reconnect(uint32 delay) LockerHelper locker(fLock); - if(fReconnectThread != -1) + if (fReconnectThread != -1) return; ++fConnectAttempt; @@ -1683,7 +1698,7 @@ reconnect_thread(void *data) receive_data(&sender, &info, sizeof(reconnect_info)); // we try to receive data instead of snooze, so we can quit on destruction - if(receive_data_with_timeout(&sender, &code, NULL, 0, info.delay) == B_OK) { + if (receive_data_with_timeout(&sender, &code, NULL, 0, info.delay) == B_OK) { *info.thread = -1; 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 0b17cea5cf..d84a0728cb 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-2006, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -26,7 +26,8 @@ //! Creates a new LCP protocol for the given interface. KPPPLCP::KPPPLCP(KPPPInterface& interface) - : KPPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL, + : + KPPPProtocol("LCP", PPP_ESTABLISHMENT_PHASE, PPP_LCP_PROTOCOL, PPP_PROTOCOL_LEVEL, AF_UNSPEC, 0, interface, NULL, PPP_ALWAYS_ALLOWED), fStateMachine(interface.StateMachine()), fTarget(NULL) @@ -39,9 +40,9 @@ KPPPLCP::KPPPLCP(KPPPInterface& interface) //! Deletes all added option handlers and LCP extensions. KPPPLCP::~KPPPLCP() { - while(CountOptionHandlers()) + while (CountOptionHandlers()) delete OptionHandlerAt(0); - while(CountLCPExtensions()) + while (CountLCPExtensions()) delete LCPExtensionAt(0); } @@ -54,10 +55,10 @@ KPPPLCP::~KPPPLCP() bool KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler) { - if(!optionHandler || &optionHandler->Interface() != &Interface()) + if (!optionHandler || &optionHandler->Interface() != &Interface()) return false; - if(Interface().Phase() != PPP_DOWN_PHASE + if (Interface().Phase() != PPP_DOWN_PHASE || OptionHandlerFor(optionHandler->Type())) return false; // a running connection may not change and there may only be @@ -74,7 +75,7 @@ KPPPLCP::AddOptionHandler(KPPPOptionHandler *optionHandler) bool KPPPLCP::RemoveOptionHandler(KPPPOptionHandler *optionHandler) { - if(Interface().Phase() != PPP_DOWN_PHASE) + if (Interface().Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change @@ -88,7 +89,7 @@ KPPPLCP::OptionHandlerAt(int32 index) const { KPPPOptionHandler *optionHandler = fOptionHandlers.ItemAt(index); - if(optionHandler == fOptionHandlers.GetDefaultItem()) + if (optionHandler == fOptionHandlers.GetDefaultItem()) return NULL; return optionHandler; @@ -105,14 +106,14 @@ KPPPLCP::OptionHandlerFor(uint8 type, int32 *start) const int32 index = start ? *start : 0; - if(index < 0) + if (index < 0) return NULL; KPPPOptionHandler *current = OptionHandlerAt(index); - for(; current; current = OptionHandlerAt(++index)) { - if(current->Type() == type) { - if(start) + for (; current; current = OptionHandlerAt(++index)) { + if (current->Type() == type) { + if (start) *start = index; return current; } @@ -129,10 +130,10 @@ KPPPLCP::OptionHandlerFor(uint8 type, int32 *start) const bool KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension) { - if(!lcpExtension || &lcpExtension->Interface() != &Interface()) + if (!lcpExtension || &lcpExtension->Interface() != &Interface()) return false; - if(Interface().Phase() != PPP_DOWN_PHASE) + if (Interface().Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change @@ -147,7 +148,7 @@ KPPPLCP::AddLCPExtension(KPPPLCPExtension *lcpExtension) bool KPPPLCP::RemoveLCPExtension(KPPPLCPExtension *lcpExtension) { - if(Interface().Phase() != PPP_DOWN_PHASE) + if (Interface().Phase() != PPP_DOWN_PHASE) return false; // a running connection may not change @@ -161,7 +162,7 @@ KPPPLCP::LCPExtensionAt(int32 index) const { KPPPLCPExtension *lcpExtension = fLCPExtensions.ItemAt(index); - if(lcpExtension == fLCPExtensions.GetDefaultItem()) + if (lcpExtension == fLCPExtensions.GetDefaultItem()) return NULL; return lcpExtension; @@ -178,14 +179,14 @@ KPPPLCP::LCPExtensionFor(uint8 code, int32 *start) const int32 index = start ? *start : 0; - if(index < 0) + if (index < 0) return NULL; KPPPLCPExtension *current = LCPExtensionAt(index); - for(; current; current = LCPExtensionAt(++index)) { - if(current->Code() == code) { - if(start) + for (; current; current = LCPExtensionAt(++index)) { + if (current->Code() == code) { + if (start) *start = index; return current; } @@ -201,10 +202,10 @@ KPPPLCP::AdditionalOverhead() const { uint32 overhead = Interface().Overhead(); - if(Target()) + if (Target()) overhead += Target()->Overhead(); - if(Interface().Device()) + if (Interface().Device()) overhead += Interface().Device()->Overhead(); return overhead; @@ -231,7 +232,7 @@ KPPPLCP::Down() status_t KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber) { - if(Target()) + if (Target()) return Target()->Send(packet, PPP_LCP_PROTOCOL); else return Interface().Send(packet, PPP_LCP_PROTOCOL); @@ -242,10 +243,10 @@ KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber) status_t KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber) { - if(!packet) + if (!packet) return B_ERROR; - if(protocolNumber != PPP_LCP_PROTOCOL) { + if (protocolNumber != PPP_LCP_PROTOCOL) { ERROR("KPPPLCP::Receive(): wrong protocol number!\n"); return PPP_UNHANDLED; } @@ -254,60 +255,60 @@ KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber) // remove padding int32 length = packet->m_len; - if(packet->m_flags & M_PKTHDR) + if (packet->m_flags & M_PKTHDR) length = packet->m_pkthdr.len; length -= ntohs(data->length); - if(length) + if (length) m_adj(packet, -length); struct mbuf *copy = m_gethdr(MT_DATA); - if(copy) { + if (copy) { copy->m_data += AdditionalOverhead(); copy->m_pkthdr.len = copy->m_len = packet->m_len; memcpy(copy->m_data, packet->m_data, copy->m_len); } - if(ntohs(data->length) < 4) + if (ntohs(data->length) < 4) return B_ERROR; - + bool handled = true; - - switch(data->code) { + + switch (data->code) { case PPP_CONFIGURE_REQUEST: StateMachine().RCREvent(packet); - break; - + break; + case PPP_CONFIGURE_ACK: StateMachine().RCAEvent(packet); - break; - + break; + case PPP_CONFIGURE_NAK: case PPP_CONFIGURE_REJECT: StateMachine().RCNEvent(packet); - break; - + break; + case PPP_TERMINATE_REQUEST: StateMachine().RTREvent(packet); - break; - + break; + case PPP_TERMINATE_ACK: StateMachine().RTAEvent(packet); - break; - + break; + case PPP_CODE_REJECT: StateMachine().RXJEvent(packet); - break; - + break; + case PPP_PROTOCOL_REJECT: StateMachine().RXJEvent(packet); - break; - + break; + case PPP_ECHO_REQUEST: case PPP_ECHO_REPLY: case PPP_DISCARD_REQUEST: StateMachine().RXREvent(packet); - break; - + break; + default: m_freem(packet); handled = false; @@ -315,7 +316,7 @@ KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber) packet = copy; - if(!packet) + if (!packet) return handled ? B_OK : B_ERROR; status_t result = B_OK; @@ -324,22 +325,22 @@ KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber) // We must duplicate the packet in order to ask all handlers. int32 index = 0; KPPPLCPExtension *lcpExtension = LCPExtensionFor(data->code, &index); - for(; lcpExtension; lcpExtension = LCPExtensionFor(data->code, &(++index))) { - if(!lcpExtension->IsEnabled()) + for (; lcpExtension; lcpExtension = LCPExtensionFor(data->code, &(++index))) { + if (!lcpExtension->IsEnabled()) continue; result = lcpExtension->Receive(packet, data->code); // check return value and return it on error - if(result == B_OK) + if (result == B_OK) handled = true; - else if(result != PPP_UNHANDLED) { + else if (result != PPP_UNHANDLED) { m_freem(packet); return result; } } - if(!handled) { + if (!handled) { StateMachine().RUCEvent(packet, PPP_LCP_PROTOCOL, PPP_CODE_REJECT); return PPP_REJECTED; } @@ -356,6 +357,6 @@ KPPPLCP::Pulse() { StateMachine().TimerEvent(); - for(int32 index = 0; index < CountLCPExtensions(); index++) + for (int32 index = 0; index < CountLCPExtensions(); index++) LCPExtensionAt(index)->Pulse(); } diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCPExtension.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCPExtension.cpp index e5e5451d07..e3165459a4 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCPExtension.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCPExtension.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -10,7 +10,6 @@ */ #include - #include @@ -31,7 +30,7 @@ KPPPLCPExtension::KPPPLCPExtension(const char *name, uint8 code, fCode(code), fEnabled(true) { - if(name) + if (name) fName = strdup(name); else fName = NULL; @@ -59,29 +58,31 @@ KPPPLCPExtension::InitCheck() const status_t KPPPLCPExtension::Control(uint32 op, void *data, size_t length) { - switch(op) { - case PPPC_GET_SIMPLE_HANDLER_INFO: { - if(length < sizeof(ppp_simple_handler_info_t) || !data) + switch (op) { + case PPPC_GET_SIMPLE_HANDLER_INFO: + { + if (length < sizeof(ppp_simple_handler_info_t) || !data) return B_ERROR; ppp_simple_handler_info *info = (ppp_simple_handler_info*) data; memset(info, 0, sizeof(ppp_simple_handler_info_t)); - if(Name()) + if (Name()) strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); info->isEnabled = IsEnabled(); - } break; - + break; + } + case PPPC_ENABLE: - if(length < sizeof(uint32) || !data) + if (length < sizeof(uint32) || !data) return B_ERROR; - + SetEnabled(*((uint32*)data)); - break; - + break; + default: return B_BAD_VALUE; } - + return B_OK; } @@ -90,11 +91,11 @@ KPPPLCPExtension::Control(uint32 op, void *data, size_t length) status_t KPPPLCPExtension::StackControl(uint32 op, void *data) { - switch(op) { + switch (op) { default: return B_BAD_VALUE; } - + return B_OK; } diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp index 1a781c432c..b967e220d7 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -58,13 +58,13 @@ KPPPLayer::InitCheck() const status_t KPPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const { - if(!packet) + if (!packet) return B_ERROR; // Find the next possible handler for this packet. // Normal protocols (Level() >= PPP_PROTOCOL_LEVEL) do not encapsulate anything. - if(Next()) { - if(Next()->IsAllowedToSend() && Next()->Level() < PPP_PROTOCOL_LEVEL) + if (Next()) { + if (Next()->IsAllowedToSend() && Next()->Level() < PPP_PROTOCOL_LEVEL) return Next()->Send(packet, protocolNumber); else return Next()->SendToNext(packet, protocolNumber); @@ -93,7 +93,7 @@ KPPPLayer::SetName(const char *name) { free(fName); - if(name) + if (name) fName = strdup(name); else fName = NULL; diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp index 982d7c9f22..19522cf320 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPOptionHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -24,14 +24,15 @@ \param settings Settings for this handler. */ KPPPOptionHandler::KPPPOptionHandler(const char *name, uint8 type, - KPPPInterface& interface, driver_parameter *settings) - : fInitStatus(B_OK), + KPPPInterface& interface, driver_parameter *settings) + : + fInitStatus(B_OK), fType(type), fInterface(interface), fSettings(settings), fEnabled(true) { - if(name) + if (name) fName = strdup(name); else fName = NULL; @@ -59,29 +60,31 @@ KPPPOptionHandler::InitCheck() const status_t KPPPOptionHandler::Control(uint32 op, void *data, size_t length) { - switch(op) { - case PPPC_GET_SIMPLE_HANDLER_INFO: { - if(length < sizeof(ppp_simple_handler_info_t) || !data) + switch (op) { + case PPPC_GET_SIMPLE_HANDLER_INFO: + { + if (length < sizeof(ppp_simple_handler_info_t) || !data) return B_ERROR; - + ppp_simple_handler_info *info = (ppp_simple_handler_info*) data; memset(info, 0, sizeof(ppp_simple_handler_info_t)); - if(Name()) + if (Name()) strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); info->isEnabled = IsEnabled(); - } break; - + break; + } + case PPPC_ENABLE: - if(length < sizeof(uint32) || !data) + if (length < sizeof(uint32) || !data) return B_ERROR; - + SetEnabled(*((uint32*)data)); - break; - + break; + default: return B_BAD_VALUE; } - + return B_OK; } @@ -90,7 +93,7 @@ KPPPOptionHandler::Control(uint32 op, void *data, size_t length) status_t KPPPOptionHandler::StackControl(uint32 op, void *data) { - switch(op) { + switch (op) { default: return B_BAD_VALUE; } @@ -152,7 +155,7 @@ KPPPOptionHandler::ParseAck(const KPPPConfigurePacket& ack) Index may be behind the last item which means additional values can be appended. - + \param request The requested values. \param index Index of item in \a request. \param nak Values for the nak should be added here. diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProtocol.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProtocol.cpp index 372b543cc9..eb7f056e0f 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProtocol.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPProtocol.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -39,11 +39,12 @@ \param optionHandler Optional handler associated with this protocol. */ KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase, - uint16 protocolNumber, ppp_level level, int32 addressFamily, - uint32 overhead, KPPPInterface& interface, - driver_parameter *settings, int32 flags, - const char *type, KPPPOptionHandler *optionHandler) - : KPPPLayer(name, level, overhead), + uint16 protocolNumber, ppp_level level, int32 addressFamily, + uint32 overhead, KPPPInterface& interface, + driver_parameter *settings, int32 flags, + const char *type, KPPPOptionHandler *optionHandler) + : + KPPPLayer(name, level, overhead), fActivationPhase(activationPhase), fProtocolNumber(protocolNumber), fAddressFamily(addressFamily), @@ -56,16 +57,16 @@ KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase, fUpRequested(true), fConnectionPhase(PPP_DOWN_PHASE) { - if(type) + if (type) fType = strdup(type); else fType = NULL; const char *sideString = get_parameter_value("side", settings); - if(sideString) + if (sideString) fSide = get_side_string_value(sideString, PPP_LOCAL_SIDE); else { - if(interface.Mode() == PPP_CLIENT_MODE) + if (interface.Mode() == PPP_CLIENT_MODE) fSide = PPP_LOCAL_SIDE; else fSide = PPP_PEER_SIDE; @@ -77,7 +78,6 @@ KPPPProtocol::KPPPProtocol(const char *name, ppp_phase activationPhase, KPPPProtocol::~KPPPProtocol() { Interface().RemoveProtocol(this); - free(fType); } @@ -100,16 +100,17 @@ KPPPProtocol::Uninit() status_t KPPPProtocol::Control(uint32 op, void *data, size_t length) { - switch(op) { - case PPPC_GET_PROTOCOL_INFO: { - if(length < sizeof(ppp_protocol_info_t) || !data) + switch (op) { + case PPPC_GET_PROTOCOL_INFO: + { + if (length < sizeof(ppp_protocol_info_t) || !data) return B_ERROR; ppp_protocol_info *info = (ppp_protocol_info*) data; memset(info, 0, sizeof(ppp_protocol_info_t)); - if(Name()) + if (Name()) strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); - if(Type()) + if (Type()) strncpy(info->type, Type(), PPP_HANDLER_NAME_LENGTH_LIMIT); info->activationPhase = ActivationPhase(); info->addressFamily = AddressFamily(); @@ -121,15 +122,16 @@ KPPPProtocol::Control(uint32 op, void *data, size_t length) info->protocolNumber = ProtocolNumber(); info->isEnabled = IsEnabled(); info->isUpRequested = IsUpRequested(); - } break; - + break; + } + case PPPC_ENABLE: - if(length < sizeof(uint32) || !data) + if (length < sizeof(uint32) || !data) return B_ERROR; SetEnabled(*((uint32*)data)); - break; - + break; + default: return B_BAD_VALUE; } @@ -142,7 +144,7 @@ KPPPProtocol::Control(uint32 op, void *data, size_t length) status_t KPPPProtocol::StackControl(uint32 op, void *data) { - switch(op) { + switch (op) { default: return B_BAD_VALUE; } @@ -160,10 +162,10 @@ KPPPProtocol::SetEnabled(bool enabled) { fEnabled = enabled; - if(!enabled) { - if(IsUp() || IsGoingUp()) + if (!enabled) { + if (IsUp() || IsGoingUp()) Down(); - } else if(!IsUp() && !IsGoingUp() && IsUpRequested() && Interface().IsUp()) + } else if (!IsUp() && !IsGoingUp() && IsUpRequested() && Interface().IsUp()) Up(); } @@ -207,7 +209,6 @@ void KPPPProtocol::UpFailedEvent() { fConnectionPhase = PPP_DOWN_PHASE; - Interface().StateMachine().UpFailedEvent(this); } @@ -220,7 +221,6 @@ void KPPPProtocol::UpEvent() { fConnectionPhase = PPP_ESTABLISHED_PHASE; - Interface().StateMachine().UpEvent(this); } @@ -233,6 +233,5 @@ void KPPPProtocol::DownEvent() { fConnectionPhase = PPP_DOWN_PHASE; - Interface().StateMachine().DownEvent(this); } diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPReportManager.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPReportManager.cpp index 4a1c4803ed..17acd2bf35 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPReportManager.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPReportManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -42,7 +42,7 @@ KPPPReportManager::KPPPReportManager(BLocker& lock) //! Deletes all report requests. KPPPReportManager::~KPPPReportManager() { - for(int32 index = 0; index < fReportRequests.CountItems(); index++) + for (int32 index = 0; index < fReportRequests.CountItems(); index++) delete fReportRequests.ItemAt(index); } @@ -57,10 +57,10 @@ KPPPReportManager::~KPPPReportManager() bool KPPPReportManager::SendReport(thread_id thread, const ppp_report_packet *report) { - if(!report) + if (!report) return false; - if(thread == find_thread(NULL)) { + if (thread == find_thread(NULL)) { report_sender_info *info = new report_sender_info; info->thread = thread; memcpy(&info->report, report, sizeof(ppp_report_packet)); @@ -85,7 +85,7 @@ void KPPPReportManager::EnableReports(ppp_report_type type, thread_id thread, int32 flags) { - if(thread < 0 || type == PPP_ALL_REPORTS) + if (thread < 0 || type == PPP_ALL_REPORTS) return; LockerHelper locker(fLock); @@ -103,25 +103,25 @@ KPPPReportManager::EnableReports(ppp_report_type type, thread_id thread, void KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread) { - if(thread < 0) + if (thread < 0) return; LockerHelper locker(fLock); ppp_report_request *request; - for(int32 i = 0; i < fReportRequests.CountItems(); i++) { + for (int32 i = 0; i < fReportRequests.CountItems(); i++) { request = fReportRequests.ItemAt(i); - if(request->thread != thread) + if (request->thread != thread) continue; - if(request->type == type || type == PPP_ALL_REPORTS) + if (request->type == type || type == PPP_ALL_REPORTS) fReportRequests.RemoveItem(request); } // empty message queue - while(has_data(thread)) { + while (has_data(thread)) { thread_id sender; receive_data(&sender, NULL, 0); } @@ -132,17 +132,17 @@ KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread) bool KPPPReportManager::DoesReport(ppp_report_type type, thread_id thread) { - if(thread < 0) + if (thread < 0) return false; LockerHelper locker(fLock); ppp_report_request *request; - for(int32 i = 0; i < fReportRequests.CountItems(); i++) { + for (int32 i = 0; i < fReportRequests.CountItems(); i++) { request = fReportRequests.ItemAt(i); - if(request->thread == thread && request->type == type) + if (request->thread == thread && request->type == type) return true; } @@ -168,13 +168,13 @@ KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 le TRACE("KPPPReportManager: Report(type=%d code=%ld length=%ld) to %ld receivers\n", type, code, length, fReportRequests.CountItems()); - if(length > PPP_REPORT_DATA_LIMIT) + if (length > PPP_REPORT_DATA_LIMIT) return false; - if(fReportRequests.CountItems() == 0) + if (fReportRequests.CountItems() == 0) return true; - if(!data) + if (!data) length = 0; LockerHelper locker(fLock); @@ -190,22 +190,22 @@ KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 le ppp_report_request *request; - for(int32 index = 0; index < fReportRequests.CountItems(); index++) { + for (int32 index = 0; index < fReportRequests.CountItems(); index++) { request = fReportRequests.ItemAt(index); // do not send to yourself - if(request->thread == me) + if (request->thread == me) continue; result = send_data_with_timeout(request->thread, PPP_REPORT_CODE, &report, sizeof(report), PPP_REPORT_TIMEOUT); #if DEBUG - if(result == B_TIMED_OUT) + if (result == B_TIMED_OUT) TRACE("KPPPReportManager::Report(): timed out sending\n"); #endif - if(result == B_BAD_THREAD_ID || result == B_NO_MEMORY + if (result == B_BAD_THREAD_ID || result == B_NO_MEMORY || request->flags & PPP_REMOVE_AFTER_REPORT) { fReportRequests.RemoveItem(request); --index; 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 8cece1c9ae..06f30baf9d 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-2006, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -81,10 +81,10 @@ KPPPStateMachine::NewState(ppp_state next) TRACE("KPPPSM: NewState(%d) state=%d\n", next, State()); // maybe we do not need the timer anymore - if(next < PPP_CLOSING_STATE || next == PPP_OPENED_STATE) + if (next < PPP_CLOSING_STATE || next == PPP_OPENED_STATE) fNextTimeout = 0; - if(State() == PPP_OPENED_STATE && next != State()) + if (State() == PPP_OPENED_STATE && next != State()) ResetLCPHandlers(); fState = next; @@ -100,34 +100,34 @@ void KPPPStateMachine::NewPhase(ppp_phase next) { #if DEBUG - if(next <= PPP_ESTABLISHMENT_PHASE || next == PPP_ESTABLISHED_PHASE) + if (next <= PPP_ESTABLISHMENT_PHASE || next == PPP_ESTABLISHED_PHASE) TRACE("KPPPSM: NewPhase(%d) phase=%d\n", next, Phase()); #endif // there is nothing after established phase and nothing before down phase - if(next > PPP_ESTABLISHED_PHASE) + if (next > PPP_ESTABLISHED_PHASE) next = PPP_ESTABLISHED_PHASE; - else if(next < PPP_DOWN_PHASE) + else if (next < PPP_DOWN_PHASE) next = PPP_DOWN_PHASE; // Report a down event to parent if we are not usable anymore. // The report threads get their notification later. - if(Phase() == PPP_ESTABLISHED_PHASE && next != Phase()) { - if(Interface().Ifnet()) { + if (Phase() == PPP_ESTABLISHED_PHASE && next != Phase()) { + if (Interface().Ifnet()) { Interface().Ifnet()->if_flags &= ~IFF_RUNNING; Interface().Ifnet()->if_flags &= ~IFF_UP; } - if(Interface().Parent()) + if (Interface().Parent()) Interface().Parent()->StateMachine().DownEvent(Interface()); } fPhase = next; - if(Phase() == PPP_ESTABLISHED_PHASE) { + if (Phase() == PPP_ESTABLISHED_PHASE) { Interface().fConnectedSince = system_time(); - if(Interface().Ifnet()) + if (Interface().Ifnet()) Interface().Ifnet()->if_flags |= IFF_UP | IFF_RUNNING; Interface().fConnectAttempt = 0; @@ -149,7 +149,7 @@ KPPPStateMachine::Reconfigure() { TRACE("KPPPSM: Reconfigure() state=%d phase=%d\n", State(), Phase()); - if(State() < PPP_REQ_SENT_STATE) + if (State() < PPP_REQ_SENT_STATE) return false; NewState(PPP_REQ_SENT_STATE); @@ -169,11 +169,11 @@ KPPPStateMachine::SendEchoRequest() { TRACE("KPPPSM: SendEchoRequest() state=%d phase=%d\n", State(), Phase()); - if(State() != PPP_OPENED_STATE) + if (State() != PPP_OPENED_STATE) return false; struct mbuf *packet = m_gethdr(MT_DATA); - if(!packet) + if (!packet) return false; packet->m_data += LCP().AdditionalOverhead(); @@ -197,11 +197,11 @@ KPPPStateMachine::SendDiscardRequest() { TRACE("KPPPSM: SendDiscardRequest() state=%d phase=%d\n", State(), Phase()); - if(State() != PPP_OPENED_STATE) + if (State() != PPP_OPENED_STATE) return false; struct mbuf *packet = m_gethdr(MT_DATA); - if(!packet) + if (!packet) return false; packet->m_data += LCP().AdditionalOverhead(); @@ -255,7 +255,7 @@ KPPPStateMachine::LocalAuthenticationAccepted(const char *name) fLocalAuthenticationStatus = PPP_AUTHENTICATION_SUCCESSFUL; free(fLocalAuthenticationName); - if(name) + if (name) fLocalAuthenticationName = strdup(name); else fLocalAuthenticationName = NULL; @@ -275,7 +275,7 @@ KPPPStateMachine::LocalAuthenticationDenied(const char *name) fLocalAuthenticationStatus = PPP_AUTHENTICATION_FAILED; free(fLocalAuthenticationName); - if(name) + if (name) fLocalAuthenticationName = strdup(name); else fLocalAuthenticationName = NULL; @@ -316,7 +316,7 @@ KPPPStateMachine::PeerAuthenticationAccepted(const char *name) fPeerAuthenticationStatus = PPP_AUTHENTICATION_SUCCESSFUL; free(fPeerAuthenticationName); - if(name) + if (name) fPeerAuthenticationName = strdup(name); else fPeerAuthenticationName = NULL; @@ -336,7 +336,7 @@ KPPPStateMachine::PeerAuthenticationDenied(const char *name) fPeerAuthenticationStatus = PPP_AUTHENTICATION_FAILED; free(fPeerAuthenticationName); - if(name) + if (name) fPeerAuthenticationName = strdup(name); else fPeerAuthenticationName = NULL; @@ -364,18 +364,18 @@ KPPPStateMachine::UpEvent(KPPPInterface& interface) { TRACE("KPPPSM: UpEvent(interface) state=%d phase=%d\n", State(), Phase()); - if(Phase() <= PPP_TERMINATION_PHASE) { + if (Phase() <= PPP_TERMINATION_PHASE) { interface.StateMachine().CloseEvent(); return; } Interface().CalculateBaudRate(); - if(Phase() == PPP_ESTABLISHMENT_PHASE) { + if (Phase() == PPP_ESTABLISHMENT_PHASE) { // this is the first interface that went up Interface().SetMRU(interface.MRU()); ThisLayerUp(); - } else if(Interface().MRU() > interface.MRU()) + } else if (Interface().MRU() > interface.MRU()) Interface().SetMRU(interface.MRU()); // MRU should always be the smallest value of all children @@ -395,29 +395,29 @@ KPPPStateMachine::DownEvent(KPPPInterface& interface) Interface().CalculateBaudRate(); // when all children are down we should not be running - if(Interface().IsMultilink() && !Interface().Parent()) { + if (Interface().IsMultilink() && !Interface().Parent()) { uint32 count = 0; KPPPInterface *child; - for(int32 index = 0; index < Interface().CountChildren(); index++) { + for (int32 index = 0; index < Interface().CountChildren(); index++) { child = Interface().ChildAt(index); - if(child && child->IsUp()) { + if (child && child->IsUp()) { // set MRU to the smallest value of all children - if(MRU == 0) + if (MRU == 0) MRU = child->MRU(); - else if(MRU > child->MRU()) + else if (MRU > child->MRU()) MRU = child->MRU(); ++count; } } - if(MRU == 0) + if (MRU == 0) Interface().SetMRU(1500); else Interface().SetMRU(MRU); - if(count == 0) + if (count == 0) DownEvent(); } } @@ -433,13 +433,13 @@ KPPPStateMachine::UpFailedEvent(KPPPProtocol *protocol) { TRACE("KPPPSM: UpFailedEvent(protocol) state=%d phase=%d\n", State(), Phase()); - if((protocol->Flags() & PPP_NOT_IMPORTANT) == 0) { - if(Interface().Mode() == PPP_CLIENT_MODE) { + if ((protocol->Flags() & PPP_NOT_IMPORTANT) == 0) { + if (Interface().Mode() == PPP_CLIENT_MODE) { // pretend we lost connection - if(Interface().IsMultilink() && !Interface().Parent()) - for(int32 index = 0; index < Interface().CountChildren(); index++) + if (Interface().IsMultilink() && !Interface().Parent()) + for (int32 index = 0; index < Interface().CountChildren(); index++) Interface().ChildAt(index)->StateMachine().CloseEvent(); - else if(Interface().Device()) + else if (Interface().Device()) Interface().Device()->Down(); else CloseEvent(); @@ -460,7 +460,7 @@ KPPPStateMachine::UpEvent(KPPPProtocol *protocol) { TRACE("KPPPSM: UpEvent(protocol) state=%d phase=%d\n", State(), Phase()); - if(Phase() >= PPP_ESTABLISHMENT_PHASE) + if (Phase() >= PPP_ESTABLISHMENT_PHASE) BringProtocolsUp(); } @@ -490,8 +490,8 @@ KPPPStateMachine::TLSNotify() { TRACE("KPPPSM: TLSNotify() state=%d phase=%d\n", State(), Phase()); - if(State() == PPP_STARTING_STATE) { - if(Phase() == PPP_DOWN_PHASE) + if (State() == PPP_STARTING_STATE) { + if (Phase() == PPP_DOWN_PHASE) NewPhase(PPP_ESTABLISHMENT_PHASE); // this says that the device is going up return true; @@ -527,18 +527,18 @@ KPPPStateMachine::UpFailedEvent() { TRACE("KPPPSM: UpFailedEvent() state=%d phase=%d\n", State(), Phase()); - switch(State()) { + switch (State()) { case PPP_STARTING_STATE: fLastConnectionReportCode = PPP_REPORT_DEVICE_UP_FAILED; Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_DEVICE_UP_FAILED, &fInterface.fID, sizeof(ppp_interface_id)); - if(Interface().Parent()) + if (Interface().Parent()) Interface().Parent()->StateMachine().UpFailedEvent(Interface()); NewPhase(PPP_DOWN_PHASE); // tell DownEvent() that it should not create a connection-lost-report DownEvent(); - break; + break; default: IllegalEvent(PPP_UP_FAILED_EVENT); @@ -555,15 +555,15 @@ 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. - if(!Interface().Device() || !Interface().Device()->IsUp()) + if (!Interface().Device() || !Interface().Device()->IsUp()) return; // it is not our device that went up... Interface().CalculateBaudRate(); - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: - if(Interface().Mode() != PPP_SERVER_MODE + if (Interface().Mode() != PPP_SERVER_MODE || Phase() != PPP_ESTABLISHMENT_PHASE) { // we are a client or we do not listen for an incoming // connection, so this is an illegal event @@ -578,11 +578,11 @@ KPPPStateMachine::UpEvent() NewState(PPP_REQ_SENT_STATE); InitializeRestartCount(); SendConfigureRequest(); - break; + break; case PPP_STARTING_STATE: // we must have called TLS() which sets establishment phase - if(Phase() != PPP_ESTABLISHMENT_PHASE) { + if (Phase() != PPP_ESTABLISHMENT_PHASE) { // there must be a BUG in the device add-on or someone is trying to // fool us (UpEvent() is public) as we did not request the device // to go up @@ -595,7 +595,7 @@ KPPPStateMachine::UpEvent() NewState(PPP_REQ_SENT_STATE); InitializeRestartCount(); SendConfigureRequest(); - break; + break; default: IllegalEvent(PPP_UP_EVENT); @@ -613,7 +613,7 @@ KPPPStateMachine::DownEvent() { TRACE("KPPPSM: DownEvent() state=%d phase=%d\n", State(), Phase()); - if(Interface().Device() && Interface().Device()->IsUp()) + if (Interface().Device() && Interface().Device()->IsUp()) return; // it is not our device that went down... @@ -622,22 +622,22 @@ KPPPStateMachine::DownEvent() // reset IdleSince Interface().fIdleSince = 0; - switch(State()) { + switch (State()) { // XXX: this does not belong to the standard, but may happen in our // implementation case PPP_STARTING_STATE: - break; + break; case PPP_CLOSED_STATE: case PPP_CLOSING_STATE: NewState(PPP_INITIAL_STATE); - break; + break; case PPP_STOPPED_STATE: // The RFC says we should reconnect, but our implementation // will only do this if auto-reconnect is enabled (only clients). NewState(PPP_STARTING_STATE); - break; + break; case PPP_STOPPING_STATE: case PPP_REQ_SENT_STATE: @@ -645,7 +645,7 @@ KPPPStateMachine::DownEvent() case PPP_ACK_SENT_STATE: case PPP_OPENED_STATE: NewState(PPP_STARTING_STATE); - break; + break; default: IllegalEvent(PPP_DOWN_EVENT); @@ -657,11 +657,11 @@ KPPPStateMachine::DownEvent() DownProtocols(); // maybe we need to reconnect - if(State() == PPP_STARTING_STATE) { + if (State() == PPP_STARTING_STATE) { bool deleteInterface = false, retry = false; // we do not try to reconnect if authentication failed - if(fLocalAuthenticationStatus == PPP_AUTHENTICATION_FAILED + if (fLocalAuthenticationStatus == PPP_AUTHENTICATION_FAILED || fLocalAuthenticationStatus == PPP_AUTHENTICATING || fPeerAuthenticationStatus == PPP_AUTHENTICATION_FAILED || fPeerAuthenticationStatus == PPP_AUTHENTICATING) { @@ -671,10 +671,10 @@ KPPPStateMachine::DownEvent() sizeof(ppp_interface_id)); deleteInterface = true; } else { - if(Interface().fConnectAttempt > (Interface().fConnectRetriesLimit + 1)) + if (Interface().fConnectAttempt > (Interface().fConnectRetriesLimit + 1)) deleteInterface = true; - if(oldPhase == PPP_DOWN_PHASE) { + if (oldPhase == PPP_DOWN_PHASE) { // failed to bring device up (UpFailedEvent() was called) retry = true; // this may have been overridden by "deleteInterface = true" @@ -686,12 +686,12 @@ KPPPStateMachine::DownEvent() } } - if(Interface().Parent()) + if (Interface().Parent()) Interface().Parent()->StateMachine().UpFailedEvent(Interface()); NewState(PPP_INITIAL_STATE); - if(!deleteInterface && (retry || Interface().DoesAutoReconnect())) + if (!deleteInterface && (retry || Interface().DoesAutoReconnect())) Interface().Reconnect(Interface().ReconnectDelay()); else Interface().Delete(); @@ -714,33 +714,33 @@ KPPPStateMachine::OpenEvent() TRACE("KPPPSM: OpenEvent() state=%d phase=%d\n", State(), Phase()); // reset all handlers - if(Phase() != PPP_ESTABLISHED_PHASE) { + if (Phase() != PPP_ESTABLISHED_PHASE) { DownProtocols(); ResetLCPHandlers(); } - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: fLastConnectionReportCode = PPP_REPORT_GOING_UP; Interface().Report(PPP_CONNECTION_REPORT, PPP_REPORT_GOING_UP, &fInterface.fID, sizeof(ppp_interface_id)); - if(Interface().Mode() == PPP_SERVER_MODE) { + if (Interface().Mode() == PPP_SERVER_MODE) { NewPhase(PPP_ESTABLISHMENT_PHASE); - if(Interface().Device() && !Interface().Device()->Up()) { + if (Interface().Device() && !Interface().Device()->Up()) { Interface().Device()->UpFailedEvent(); return; } } else NewState(PPP_STARTING_STATE); - if(Interface().fAskBeforeConnecting == false) + if (Interface().fAskBeforeConnecting == false) ContinueOpenEvent(); - break; + break; case PPP_CLOSED_STATE: - if(Phase() == PPP_DOWN_PHASE) { + if (Phase() == PPP_DOWN_PHASE) { // the device is already going down return; } @@ -749,11 +749,11 @@ KPPPStateMachine::OpenEvent() NewPhase(PPP_ESTABLISHMENT_PHASE); InitializeRestartCount(); SendConfigureRequest(); - break; + break; case PPP_CLOSING_STATE: NewState(PPP_STOPPING_STATE); - break; + break; default: ; @@ -766,10 +766,10 @@ KPPPStateMachine::ContinueOpenEvent() { TRACE("KPPPSM: ContinueOpenEvent() state=%d phase=%d\n", State(), Phase()); - if(Interface().IsMultilink() && !Interface().Parent()) { + if (Interface().IsMultilink() && !Interface().Parent()) { NewPhase(PPP_ESTABLISHMENT_PHASE); - for(int32 index = 0; index < Interface().CountChildren(); index++) - if(Interface().ChildAt(index)->Mode() == Interface().Mode()) + for (int32 index = 0; index < Interface().CountChildren(); index++) + if (Interface().ChildAt(index)->Mode() == Interface().Mode()) Interface().ChildAt(index)->StateMachine().OpenEvent(); } else ThisLayerStarted(); @@ -781,21 +781,21 @@ KPPPStateMachine::CloseEvent() { TRACE("KPPPSM: CloseEvent() state=%d phase=%d\n", State(), Phase()); - if(Interface().IsMultilink() && !Interface().Parent()) { + if (Interface().IsMultilink() && !Interface().Parent()) { NewState(PPP_INITIAL_STATE); - if(Phase() != PPP_DOWN_PHASE) + if (Phase() != PPP_DOWN_PHASE) NewPhase(PPP_TERMINATION_PHASE); ThisLayerDown(); - for(int32 index = 0; index < Interface().CountChildren(); index++) + for (int32 index = 0; index < Interface().CountChildren(); index++) Interface().ChildAt(index)->StateMachine().CloseEvent(); return; } - switch(State()) { + switch (State()) { case PPP_OPENED_STATE: case PPP_REQ_SENT_STATE: case PPP_ACK_RCVD_STATE: @@ -804,32 +804,32 @@ KPPPStateMachine::CloseEvent() NewPhase(PPP_TERMINATION_PHASE); // indicates to handlers that we are terminating InitializeRestartCount(); - if(State() == PPP_OPENED_STATE) + if (State() == PPP_OPENED_STATE) ThisLayerDown(); SendTerminateRequest(); - break; + break; case PPP_STARTING_STATE: NewState(PPP_INITIAL_STATE); // TLSNotify() will know that we were faster because we // are in PPP_INITIAL_STATE now - if(Phase() == PPP_ESTABLISHMENT_PHASE) { + if (Phase() == PPP_ESTABLISHMENT_PHASE) { // the device is already up NewPhase(PPP_DOWN_PHASE); // this says the following DownEvent() was not caused by // a connection fault ThisLayerFinished(); } - break; + break; case PPP_STOPPING_STATE: NewState(PPP_CLOSING_STATE); - break; + break; case PPP_STOPPED_STATE: NewState(PPP_STOPPED_STATE); - break; + break; default: ; @@ -843,11 +843,11 @@ KPPPStateMachine::TOGoodEvent() { TRACE("KPPPSM: TOGoodEvent() state=%d phase=%d\n", State(), Phase()); - switch(State()) { + switch (State()) { case PPP_CLOSING_STATE: case PPP_STOPPING_STATE: SendTerminateRequest(); - break; + break; case PPP_ACK_RCVD_STATE: NewState(PPP_REQ_SENT_STATE); @@ -855,7 +855,7 @@ KPPPStateMachine::TOGoodEvent() case PPP_REQ_SENT_STATE: case PPP_ACK_SENT_STATE: SendConfigureRequest(); - break; + break; default: IllegalEvent(PPP_TO_GOOD_EVENT); @@ -869,12 +869,12 @@ KPPPStateMachine::TOBadEvent() { TRACE("KPPPSM: TOBadEvent() state=%d phase=%d\n", State(), Phase()); - switch(State()) { + switch (State()) { case PPP_CLOSING_STATE: NewState(PPP_CLOSED_STATE); NewPhase(PPP_TERMINATION_PHASE); ThisLayerFinished(); - break; + break; case PPP_STOPPING_STATE: case PPP_REQ_SENT_STATE: @@ -883,7 +883,7 @@ KPPPStateMachine::TOBadEvent() NewState(PPP_STOPPED_STATE); NewPhase(PPP_TERMINATION_PHASE); ThisLayerFinished(); - break; + break; default: IllegalEvent(PPP_TO_BAD_EVENT); @@ -897,36 +897,36 @@ KPPPStateMachine::RCRGoodEvent(struct mbuf *packet) { TRACE("KPPPSM: RCRGoodEvent() state=%d phase=%d\n", State(), Phase()); - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: IllegalEvent(PPP_RCR_GOOD_EVENT); m_freem(packet); - break; + break; case PPP_CLOSED_STATE: SendTerminateAck(); m_freem(packet); - break; + break; case PPP_STOPPED_STATE: // irc,scr,sca/8 // XXX: should we do nothing and wait for DownEvent()? m_freem(packet); - break; + break; case PPP_REQ_SENT_STATE: NewState(PPP_ACK_SENT_STATE); case PPP_ACK_SENT_STATE: SendConfigureAck(packet); - break; + break; case PPP_ACK_RCVD_STATE: NewState(PPP_OPENED_STATE); SendConfigureAck(packet); ThisLayerUp(); - break; + break; case PPP_OPENED_STATE: NewState(PPP_ACK_SENT_STATE); @@ -935,7 +935,7 @@ KPPPStateMachine::RCRGoodEvent(struct mbuf *packet) ThisLayerDown(); SendConfigureRequest(); SendConfigureAck(packet); - break; + break; default: m_freem(packet); @@ -949,20 +949,20 @@ KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) { TRACE("KPPPSM: RCRBadEvent() state=%d phase=%d\n", State(), Phase()); - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: IllegalEvent(PPP_RCR_BAD_EVENT); - break; + break; case PPP_CLOSED_STATE: SendTerminateAck(); - break; + break; case PPP_STOPPED_STATE: // irc,scr,scn/6 // XXX: should we do nothing and wait for DownEvent()? - break; + break; case PPP_OPENED_STATE: NewState(PPP_REQ_SENT_STATE); @@ -972,26 +972,26 @@ KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) SendConfigureRequest(); case PPP_ACK_SENT_STATE: - if(State() == PPP_ACK_SENT_STATE) + if (State() == PPP_ACK_SENT_STATE) NewState(PPP_REQ_SENT_STATE); // OPENED_STATE might have set this already case PPP_REQ_SENT_STATE: case PPP_ACK_RCVD_STATE: - if(nak && ntohs(mtod(nak, ppp_lcp_packet*)->length) > 3) + if (nak && ntohs(mtod(nak, ppp_lcp_packet*)->length) > 3) SendConfigureNak(nak); - else if(reject && ntohs(mtod(reject, ppp_lcp_packet*)->length) > 3) + else if (reject && ntohs(mtod(reject, ppp_lcp_packet*)->length) > 3) SendConfigureNak(reject); - return; + return; // prevents the nak/reject from being m_freem()'d default: ; } - if(nak) + if (nak) m_freem(nak); - if(reject) + if (reject) m_freem(reject); } @@ -1002,7 +1002,7 @@ KPPPStateMachine::RCAEvent(struct mbuf *packet) { TRACE("KPPPSM: RCAEvent() state=%d phase=%d\n", State(), Phase()); - if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { + if (fRequestID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request // TODO: @@ -1014,41 +1014,41 @@ KPPPStateMachine::RCAEvent(struct mbuf *packet) // let the option handlers parse this ack KPPPConfigurePacket ack(packet); KPPPOptionHandler *optionHandler; - for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) { + for (int32 index = 0; index < LCP().CountOptionHandlers(); index++) { optionHandler = LCP().OptionHandlerAt(index); - if(optionHandler->ParseAck(ack) != B_OK) { + if (optionHandler->ParseAck(ack) != B_OK) { m_freem(packet); CloseEvent(); return; } } - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: IllegalEvent(PPP_RCA_EVENT); - break; + break; case PPP_CLOSED_STATE: case PPP_STOPPED_STATE: SendTerminateAck(); - break; + break; case PPP_REQ_SENT_STATE: NewState(PPP_ACK_RCVD_STATE); InitializeRestartCount(); - break; + break; case PPP_ACK_RCVD_STATE: NewState(PPP_REQ_SENT_STATE); SendConfigureRequest(); - break; + break; case PPP_ACK_SENT_STATE: NewState(PPP_OPENED_STATE); InitializeRestartCount(); ThisLayerUp(); - break; + break; case PPP_OPENED_STATE: NewState(PPP_REQ_SENT_STATE); @@ -1056,7 +1056,7 @@ KPPPStateMachine::RCAEvent(struct mbuf *packet) // indicates to handlers that we are reconfiguring ThisLayerDown(); SendConfigureRequest(); - break; + break; default: ; @@ -1072,7 +1072,7 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet) { TRACE("KPPPSM: RCNEvent() state=%d phase=%d\n", State(), Phase()); - if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { + if (fRequestID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request // TODO: @@ -1084,17 +1084,17 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet) // let the option handlers parse this nak/reject KPPPConfigurePacket nak_reject(packet); KPPPOptionHandler *optionHandler; - for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) { + for (int32 index = 0; index < LCP().CountOptionHandlers(); index++) { optionHandler = LCP().OptionHandlerAt(index); - if(nak_reject.Code() == PPP_CONFIGURE_NAK) { - if(optionHandler->ParseNak(nak_reject) != B_OK) { + if (nak_reject.Code() == PPP_CONFIGURE_NAK) { + if (optionHandler->ParseNak(nak_reject) != B_OK) { m_freem(packet); CloseEvent(); return; } - } else if(nak_reject.Code() == PPP_CONFIGURE_REJECT) { - if(optionHandler->ParseReject(nak_reject) != B_OK) { + } else if (nak_reject.Code() == PPP_CONFIGURE_REJECT) { + if (optionHandler->ParseReject(nak_reject) != B_OK) { m_freem(packet); CloseEvent(); return; @@ -1102,26 +1102,26 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet) } } - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: IllegalEvent(PPP_RCN_EVENT); - break; + break; case PPP_CLOSED_STATE: case PPP_STOPPED_STATE: SendTerminateAck(); - break; + break; case PPP_REQ_SENT_STATE: case PPP_ACK_SENT_STATE: InitializeRestartCount(); case PPP_ACK_RCVD_STATE: - if(State() == PPP_ACK_RCVD_STATE) + if (State() == PPP_ACK_RCVD_STATE) NewState(PPP_REQ_SENT_STATE); SendConfigureRequest(); - break; + break; case PPP_OPENED_STATE: NewState(PPP_REQ_SENT_STATE); @@ -1129,7 +1129,7 @@ KPPPStateMachine::RCNEvent(struct mbuf *packet) // indicates to handlers that we are reconfiguring ThisLayerDown(); SendConfigureRequest(); - break; + break; default: ; @@ -1146,18 +1146,18 @@ KPPPStateMachine::RTREvent(struct mbuf *packet) TRACE("KPPPSM: RTREvent() state=%d phase=%d\n", State(), Phase()); // we should not use the same ID as the peer - if(fID == mtod(packet, ppp_lcp_packet*)->id) + if (fID == mtod(packet, ppp_lcp_packet*)->id) fID -= 128; fLocalAuthenticationStatus = PPP_NOT_AUTHENTICATED; fPeerAuthenticationStatus = PPP_NOT_AUTHENTICATED; - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: IllegalEvent(PPP_RTR_EVENT); m_freem(packet); - break; + break; case PPP_ACK_RCVD_STATE: case PPP_ACK_SENT_STATE: @@ -1165,7 +1165,7 @@ KPPPStateMachine::RTREvent(struct mbuf *packet) NewPhase(PPP_TERMINATION_PHASE); // indicates to handlers that we are terminating SendTerminateAck(packet); - break; + break; case PPP_OPENED_STATE: NewState(PPP_STOPPING_STATE); @@ -1174,7 +1174,7 @@ KPPPStateMachine::RTREvent(struct mbuf *packet) ZeroRestartCount(); ThisLayerDown(); SendTerminateAck(packet); - break; + break; default: NewPhase(PPP_TERMINATION_PHASE); @@ -1190,7 +1190,7 @@ KPPPStateMachine::RTAEvent(struct mbuf *packet) { TRACE("KPPPSM: RTAEvent() state=%d phase=%d\n", State(), Phase()); - if(fTerminateID != mtod(packet, ppp_lcp_packet*)->id) { + if (fTerminateID != mtod(packet, ppp_lcp_packet*)->id) { // this packet is not a reply to our request // TODO: @@ -1199,25 +1199,25 @@ KPPPStateMachine::RTAEvent(struct mbuf *packet) return; } - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: IllegalEvent(PPP_RTA_EVENT); - break; + break; case PPP_CLOSING_STATE: NewState(PPP_CLOSED_STATE); ThisLayerFinished(); - break; + break; case PPP_STOPPING_STATE: NewState(PPP_STOPPED_STATE); ThisLayerFinished(); - break; + break; case PPP_ACK_RCVD_STATE: NewState(PPP_REQ_SENT_STATE); - break; + break; case PPP_OPENED_STATE: NewState(PPP_REQ_SENT_STATE); @@ -1225,7 +1225,7 @@ KPPPStateMachine::RTAEvent(struct mbuf *packet) // indicates to handlers that we are reconfiguring ThisLayerDown(); SendConfigureRequest(); - break; + break; default: ; @@ -1242,12 +1242,12 @@ KPPPStateMachine::RUCEvent(struct mbuf *packet, uint16 protocolNumber, { TRACE("KPPPSM: RUCEvent() state=%d phase=%d\n", State(), Phase()); - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: IllegalEvent(PPP_RUC_EVENT); m_freem(packet); - break; + break; default: SendCodeReject(packet, protocolNumber, code); @@ -1264,15 +1264,15 @@ 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. - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: IllegalEvent(PPP_RXJ_GOOD_EVENT); - break; + break; case PPP_ACK_RCVD_STATE: NewState(PPP_REQ_SENT_STATE); - break; + break; default: ; @@ -1286,18 +1286,18 @@ KPPPStateMachine::RXJBadEvent(struct mbuf *packet) { TRACE("KPPPSM: RXJBadEvent() state=%d phase=%d\n", State(), Phase()); - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: IllegalEvent(PPP_RXJ_BAD_EVENT); - break; + break; case PPP_CLOSING_STATE: NewState(PPP_CLOSED_STATE); case PPP_CLOSED_STATE: ThisLayerFinished(); - break; + break; case PPP_REQ_SENT_STATE: case PPP_ACK_RCVD_STATE: @@ -1309,7 +1309,7 @@ KPPPStateMachine::RXJBadEvent(struct mbuf *packet) case PPP_STOPPED_STATE: ThisLayerFinished(); - break; + break; case PPP_OPENED_STATE: NewState(PPP_STOPPING_STATE); @@ -1318,7 +1318,7 @@ KPPPStateMachine::RXJBadEvent(struct mbuf *packet) InitializeRestartCount(); ThisLayerDown(); SendTerminateRequest(); - break; + break; } m_freem(packet); @@ -1333,22 +1333,22 @@ KPPPStateMachine::RXREvent(struct mbuf *packet) ppp_lcp_packet *echo = mtod(packet, ppp_lcp_packet*); - if(echo->code == PPP_ECHO_REPLY && echo->id != fEchoID) { + if (echo->code == PPP_ECHO_REPLY && echo->id != fEchoID) { // TODO: // log that we got a reply, but no request was sent } - switch(State()) { + switch (State()) { case PPP_INITIAL_STATE: case PPP_STARTING_STATE: IllegalEvent(PPP_RXR_EVENT); - break; + break; case PPP_OPENED_STATE: - if(echo->code == PPP_ECHO_REQUEST) + if (echo->code == PPP_ECHO_REQUEST) SendEchoReply(packet); - return; - // this prevents the packet from being freed + return; + // this prevents the packet from being freed default: ; @@ -1363,32 +1363,32 @@ void KPPPStateMachine::TimerEvent() { #if DEBUG - if(fNextTimeout != 0) + if (fNextTimeout != 0) TRACE("KPPPSM: TimerEvent()\n"); #endif - if(fNextTimeout == 0 || fNextTimeout > system_time()) + if (fNextTimeout == 0 || fNextTimeout > system_time()) return; fNextTimeout = 0; - switch(State()) { + switch (State()) { case PPP_CLOSING_STATE: case PPP_STOPPING_STATE: - if(fTerminateCounter <= 0) + if (fTerminateCounter <= 0) TOBadEvent(); else TOGoodEvent(); - break; + break; case PPP_REQ_SENT_STATE: case PPP_ACK_RCVD_STATE: case PPP_ACK_SENT_STATE: - if(fRequestCounter <= 0) + if (fRequestCounter <= 0) TOBadEvent(); else TOGoodEvent(); - break; + break; default: ; @@ -1409,7 +1409,7 @@ KPPPStateMachine::RCREvent(struct mbuf *packet) KPPPConfigurePacket reject(PPP_CONFIGURE_REJECT); // we should not use the same id as the peer - if(fID == mtod(packet, ppp_lcp_packet*)->id) + if (fID == mtod(packet, ppp_lcp_packet*)->id) fID -= 128; nak.SetID(request.ID()); @@ -1419,10 +1419,10 @@ KPPPStateMachine::RCREvent(struct mbuf *packet) status_t result; // the return value of ParseRequest() KPPPOptionHandler *optionHandler; - for(int32 index = 0; index < request.CountItems(); index++) { + for (int32 index = 0; index < request.CountItems(); index++) { optionHandler = LCP().OptionHandlerFor(request.ItemAt(index)->type); - if(!optionHandler || !optionHandler->IsEnabled()) { + if (!optionHandler || !optionHandler->IsEnabled()) { ERROR("KPPPSM::RCREvent():unknown type:%d\n", request.ItemAt(index)->type); // unhandled items should be added to the reject reject.AddItem(request.ItemAt(index)); @@ -1433,11 +1433,11 @@ KPPPStateMachine::RCREvent(struct mbuf *packet) optionHandler->Name() ? optionHandler->Name() : "Unknown"); result = optionHandler->ParseRequest(request, index, nak, reject); - if(result == PPP_UNHANDLED) { + if (result == PPP_UNHANDLED) { // unhandled items should be added to the reject reject.AddItem(request.ItemAt(index)); continue; - } else if(result != B_OK) { + } else if (result != B_OK) { // the request contains a value that has been sent more than // once or the value is corrupted ERROR("KPPPSM::RCREvent(): OptionHandler returned parse error!\n"); @@ -1449,14 +1449,14 @@ KPPPStateMachine::RCREvent(struct mbuf *packet) // Additional values may be appended. // If we sent too many naks we should not append additional values. - if(fNakCounter > 0) { - for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) { + if (fNakCounter > 0) { + for (int32 index = 0; index < LCP().CountOptionHandlers(); index++) { optionHandler = LCP().OptionHandlerAt(index); - if(optionHandler && optionHandler->IsEnabled()) { + if (optionHandler && optionHandler->IsEnabled()) { result = optionHandler->ParseRequest(request, request.CountItems(), nak, reject); - if(result != B_OK) { + if (result != B_OK) { // the request contains a value that has been sent more than // once or the value is corrupted ERROR("KPPPSM::RCREvent():OptionHandler returned append error!\n"); @@ -1468,10 +1468,10 @@ KPPPStateMachine::RCREvent(struct mbuf *packet) } } - if(reject.CountItems() > 0) { + if (reject.CountItems() > 0) { RCRBadEvent(NULL, reject.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead())); m_freem(packet); - } else if(nak.CountItems() > 0) { + } else if (nak.CountItems() > 0) { RCRBadEvent(nak.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead()), NULL); m_freem(packet); } else @@ -1489,12 +1489,12 @@ KPPPStateMachine::RXJEvent(struct mbuf *packet) ppp_lcp_packet *reject = mtod(packet, ppp_lcp_packet*); - if(reject->code == PPP_CODE_REJECT) { + if (reject->code == PPP_CODE_REJECT) { uint8 rejectedCode = reject->data[0]; // test if the rejected code belongs to the minimum LCP requirements - if(rejectedCode >= PPP_MIN_LCP_CODE && rejectedCode <= PPP_MAX_LCP_CODE) { - if(Interface().IsMultilink() && !Interface().Parent()) { + if (rejectedCode >= PPP_MIN_LCP_CODE && rejectedCode <= PPP_MAX_LCP_CODE) { + if (Interface().IsMultilink() && !Interface().Parent()) { // Main interfaces do not have states between STARTING and OPENED. // An RXJBadEvent() would enter one of those states which is bad. m_freem(packet); @@ -1507,20 +1507,20 @@ KPPPStateMachine::RXJEvent(struct mbuf *packet) // find the LCP extension and disable it KPPPLCPExtension *lcpExtension; - for(int32 index = 0; index < LCP().CountLCPExtensions(); index++) { + for (int32 index = 0; index < LCP().CountLCPExtensions(); index++) { lcpExtension = LCP().LCPExtensionAt(index); - if(lcpExtension->Code() == rejectedCode) + if (lcpExtension->Code() == rejectedCode) lcpExtension->SetEnabled(false); } m_freem(packet); - } else if(reject->code == PPP_PROTOCOL_REJECT) { + } else if (reject->code == PPP_PROTOCOL_REJECT) { // disable all handlers for rejected protocol type uint16 rejected = *((uint16*) reject->data); // rejected protocol number - if(rejected == PPP_LCP_PROTOCOL) { + if (rejected == PPP_LCP_PROTOCOL) { // LCP must not be rejected! RXJBadEvent(packet); return; @@ -1528,8 +1528,8 @@ KPPPStateMachine::RXJEvent(struct mbuf *packet) // disable protocols with the rejected protocol number KPPPProtocol *protocol = Interface().FirstProtocol(); - for(; protocol; protocol = protocol->NextProtocol()) { - if(protocol->ProtocolNumber() == rejected) + for (; protocol; protocol = protocol->NextProtocol()) { + if (protocol->ProtocolNumber() == rejected) protocol->SetEnabled(false); // disable protocol } @@ -1538,7 +1538,7 @@ KPPPStateMachine::RXJEvent(struct mbuf *packet) // this event handler does not m_freem(packet)!!! // notify parent, too - if(Interface().Parent()) + if (Interface().Parent()) Interface().Parent()->StateMachine().RXJEvent(packet); else m_freem(packet); @@ -1566,7 +1566,7 @@ KPPPStateMachine::ThisLayerUp() // We stop when we reach established phase. // Do not forget to check if we are going down. - if(Phase() != PPP_ESTABLISHMENT_PHASE) + if (Phase() != PPP_ESTABLISHMENT_PHASE) return; NewPhase(PPP_AUTHENTICATION_PHASE); @@ -1590,7 +1590,7 @@ KPPPStateMachine::ThisLayerStarted() { TRACE("KPPPSM: ThisLayerStarted() state=%d phase=%d\n", State(), Phase()); - if(Interface().Device() && !Interface().Device()->Up()) + if (Interface().Device() && !Interface().Device()->Up()) Interface().Device()->UpFailedEvent(); } @@ -1600,7 +1600,7 @@ KPPPStateMachine::ThisLayerFinished() { TRACE("KPPPSM: ThisLayerFinished() state=%d phase=%d\n", State(), Phase()); - if(Interface().Device()) + if (Interface().Device()) Interface().Device()->Down(); } @@ -1635,9 +1635,9 @@ KPPPStateMachine::SendConfigureRequest() request.SetID(NextID()); fRequestID = request.ID(); - for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) { + for (int32 index = 0; index < LCP().CountOptionHandlers(); index++) { // add all items - if(LCP().OptionHandlerAt(index)->AddToRequest(request) != B_OK) { + if (LCP().OptionHandlerAt(index)->AddToRequest(request) != B_OK) { CloseEvent(); return false; } @@ -1653,15 +1653,15 @@ KPPPStateMachine::SendConfigureAck(struct mbuf *packet) { TRACE("KPPPSM: SendConfigureAck() state=%d phase=%d\n", State(), Phase()); - if(!packet) + if (!packet) return false; mtod(packet, ppp_lcp_packet*)->code = PPP_CONFIGURE_ACK; KPPPConfigurePacket ack(packet); // notify all option handlers that we are sending an ack for each value - for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) { - if(LCP().OptionHandlerAt(index)->SendingAck(ack) != B_OK) { + for (int32 index = 0; index < LCP().CountOptionHandlers(); index++) { + if (LCP().OptionHandlerAt(index)->SendingAck(ack) != B_OK) { m_freem(packet); CloseEvent(); return false; @@ -1677,12 +1677,12 @@ KPPPStateMachine::SendConfigureNak(struct mbuf *packet) { TRACE("KPPPSM: SendConfigureNak() state=%d phase=%d\n", State(), Phase()); - if(!packet) + if (!packet) return false; ppp_lcp_packet *nak = mtod(packet, ppp_lcp_packet*); - if(nak->code == PPP_CONFIGURE_NAK) { - if(fNakCounter == 0) { + if (nak->code == PPP_CONFIGURE_NAK) { + if (fNakCounter == 0) { // We sent enough naks. Let's try a reject. nak->code = PPP_CONFIGURE_REJECT; } else @@ -1702,7 +1702,7 @@ KPPPStateMachine::SendTerminateRequest() fNextTimeout = system_time() + kPPPStateMachineTimeout; struct mbuf *packet = m_gethdr(MT_DATA); - if(!packet) + if (!packet) return false; packet->m_pkthdr.len = packet->m_len = 4; @@ -1728,9 +1728,9 @@ KPPPStateMachine::SendTerminateAck(struct mbuf *request) ppp_lcp_packet *ack; - if(!reply) { + if (!reply) { reply = m_gethdr(MT_DATA); - if(!reply) + if (!reply) return false; reply->m_data += LCP().AdditionalOverhead(); @@ -1754,12 +1754,12 @@ KPPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uin TRACE("KPPPSM: SendCodeReject(protocolNumber=%X;code=%d) state=%d phase=%d\n", protocolNumber, code, State(), Phase()); - if(!packet) + if (!packet) return false; int32 length; // additional space needed for this reject - if(code == PPP_PROTOCOL_REJECT) + if (code == PPP_PROTOCOL_REJECT) length = 6; else length = 4; @@ -1769,24 +1769,24 @@ KPPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uin // adjust packet if too big int32 adjust = Interface().MRU(); - if(packet->m_flags & M_PKTHDR) { + if (packet->m_flags & M_PKTHDR) { adjust -= packet->m_pkthdr.len; } else adjust -= packet->m_len; - if(adjust < 0) + if (adjust < 0) m_adj(packet, adjust); ppp_lcp_packet *reject = mtod(packet, ppp_lcp_packet*); reject->code = code; reject->id = NextID(); - if(packet->m_flags & M_PKTHDR) + if (packet->m_flags & M_PKTHDR) reject->length = htons(packet->m_pkthdr.len); else reject->length = htons(packet->m_len); protocolNumber = htons(protocolNumber); - if(code == PPP_PROTOCOL_REJECT) + if (code == PPP_PROTOCOL_REJECT) memcpy(&reject->data, &protocolNumber, sizeof(protocolNumber)); return LCP().Send(packet) == B_OK; @@ -1798,14 +1798,14 @@ KPPPStateMachine::SendEchoReply(struct mbuf *request) { TRACE("KPPPSM: SendEchoReply() state=%d phase=%d\n", State(), Phase()); - if(!request) + if (!request) return false; ppp_lcp_packet *reply = mtod(request, ppp_lcp_packet*); reply->code = PPP_ECHO_REPLY; // the request becomes a reply - if(request->m_flags & M_PKTHDR) + if (request->m_flags & M_PKTHDR) request->m_pkthdr.len = 8; request->m_len = 8; @@ -1820,15 +1820,15 @@ void KPPPStateMachine::BringProtocolsUp() { // use a simple check for phase changes (e.g., caused by CloseEvent()) - while(Phase() <= PPP_ESTABLISHED_PHASE && Phase() >= PPP_AUTHENTICATION_PHASE) { - if(BringPhaseUp() > 0) + while (Phase() <= PPP_ESTABLISHED_PHASE && Phase() >= PPP_AUTHENTICATION_PHASE) { + if (BringPhaseUp() > 0) break; - if(Phase() < PPP_AUTHENTICATION_PHASE) + if (Phase() < PPP_AUTHENTICATION_PHASE) return; // phase was changed by another event - else if(Phase() == PPP_ESTABLISHED_PHASE) { - if(Interface().Parent()) + else if (Phase() == PPP_ESTABLISHED_PHASE) { + if (Interface().Parent()) Interface().Parent()->StateMachine().UpEvent(Interface()); break; } else @@ -1845,17 +1845,17 @@ KPPPStateMachine::BringPhaseUp() // The client specifies which protocols he wants to go up. // check for phase change - if(Phase() < PPP_AUTHENTICATION_PHASE) + if (Phase() < PPP_AUTHENTICATION_PHASE) return 0; uint32 count = 0; KPPPProtocol *protocol = Interface().FirstProtocol(); - for(; protocol; protocol = protocol->NextProtocol()) { - if(protocol->IsEnabled() && protocol->ActivationPhase() == Phase()) { - if(protocol->IsGoingUp() && Interface().Mode() == PPP_CLIENT_MODE) + for (; protocol; protocol = protocol->NextProtocol()) { + if (protocol->IsEnabled() && protocol->ActivationPhase() == Phase()) { + if (protocol->IsGoingUp() && Interface().Mode() == PPP_CLIENT_MODE) ++count; - else if(protocol->IsDown() && protocol->IsUpRequested()) { - if(Interface().Mode() == PPP_CLIENT_MODE) + else if (protocol->IsDown() && protocol->IsUpRequested()) { + if (Interface().Mode() == PPP_CLIENT_MODE) ++count; protocol->Up(); @@ -1864,7 +1864,7 @@ KPPPStateMachine::BringPhaseUp() } // We only wait until authentication is complete. - if(Interface().Mode() == PPP_SERVER_MODE + if (Interface().Mode() == PPP_SERVER_MODE && (LocalAuthenticationStatus() == PPP_AUTHENTICATING || PeerAuthenticationStatus() == PPP_AUTHENTICATING)) ++count; @@ -1878,8 +1878,8 @@ KPPPStateMachine::DownProtocols() { KPPPProtocol *protocol = Interface().FirstProtocol(); - for(; protocol; protocol = protocol->NextProtocol()) - if(protocol->IsEnabled()) + for (; protocol; protocol = protocol->NextProtocol()) + if (protocol->IsEnabled()) protocol->Down(); } @@ -1887,9 +1887,9 @@ KPPPStateMachine::DownProtocols() void KPPPStateMachine::ResetLCPHandlers() { - for(int32 index = 0; index < LCP().CountOptionHandlers(); index++) + for (int32 index = 0; index < LCP().CountOptionHandlers(); index++) LCP().OptionHandlerAt(index)->Reset(); - for(int32 index = 0; index < LCP().CountLCPExtensions(); index++) + for (int32 index = 0; index < LCP().CountLCPExtensions(); index++) LCP().LCPExtensionAt(index)->Reset(); } diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPUtils.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPUtils.cpp index beddc13df3..13d66c2a1a 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPUtils.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPUtils.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -13,11 +13,11 @@ bool IsProtocolAllowed(const KPPPProtocol& protocol) { - if(protocol.ProtocolNumber() == PPP_LCP_PROTOCOL) + if (protocol.ProtocolNumber() == PPP_LCP_PROTOCOL) return true; - else if(protocol.Interface().State() != PPP_OPENED_STATE) + else if (protocol.Interface().State() != PPP_OPENED_STATE) return false; - else if(protocol.Interface().Phase() > PPP_AUTHENTICATION_PHASE + else if (protocol.Interface().Phase() > PPP_AUTHENTICATION_PHASE || (protocol.Interface().Phase() >= PPP_ESTABLISHMENT_PHASE && protocol.Flags() & PPP_ALWAYS_ALLOWED)) return true; @@ -30,14 +30,14 @@ status_t send_data_with_timeout(thread_id thread, int32 code, void *buffer, size_t buffer_size, uint32 timeout) { - for(uint32 tries = 0; tries < timeout; tries += 5) { - if(has_data(thread)) + for (uint32 tries = 0; tries < timeout; tries += 5) { + if (has_data(thread)) snooze(5000); else break; } - if(!has_data(thread)) + if (!has_data(thread)) return send_data(thread, code, buffer, buffer_size); else return B_TIMED_OUT; @@ -49,14 +49,14 @@ receive_data_with_timeout(thread_id *sender, int32 *code, void *buffer, size_t buffer_size, uint32 timeout) { thread_id me = find_thread(NULL); - for(uint32 tries = 0; tries < timeout; tries += 5) { - if(!has_data(me)) + for (uint32 tries = 0; tries < timeout; tries += 5) { + if (!has_data(me)) snooze(5000); else break; } - if(has_data(find_thread(NULL))) { + if (has_data(find_thread(NULL))) { *code = receive_data(sender, buffer, buffer_size); return B_OK; } else diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.cpp index 289ef9370b..ea0ae053d7 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPAuthenticationHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -39,8 +39,8 @@ _KPPPAuthenticationHandler::NextAuthenticator(const KPPPProtocol *start, // find the next authenticator for side, beginning at start KPPPProtocol *current = start ? start->NextProtocol() : Interface().FirstProtocol(); - for(; current; current = current->NextProtocol()) { - if(current->Type() && !strcasecmp(current->Type(), kAuthenticatorTypeString) + for (; current; current = current->NextProtocol()) { + if (current->Type() && !strcasecmp(current->Type(), kAuthenticatorTypeString) && current->OptionHandler() && current->Side() == side) return current; } @@ -56,14 +56,14 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request) // add an authentication request if needed. This request is added // by the authenticator's OptionHandler. - if(fPeerAuthenticator) + if (fPeerAuthenticator) fPeerAuthenticator->SetEnabled(false); - if(fSuggestedPeerAuthenticator) + if (fSuggestedPeerAuthenticator) fSuggestedPeerAuthenticator->SetEnabled(false); KPPPProtocol *authenticator; - if(fPeerAuthenticatorRejected) { - if(!fSuggestedPeerAuthenticator) { + if (fPeerAuthenticatorRejected) { + if (!fSuggestedPeerAuthenticator) { // This happens when the protocol is rejected, but no alternative // protocol is supplied to us or the suggested protocol is not supported. // We can use this chance to increase fPeerIndex to the next authenticator. @@ -73,7 +73,7 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request) fPeerAuthenticatorRejected = false; } else { - if(!fPeerAuthenticator) { + if (!fPeerAuthenticator) { // there is no authenticator selected, so find one for us authenticator = NextAuthenticator(fPeerAuthenticator, PPP_PEER_SIDE); } else @@ -81,8 +81,8 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request) } // check if all authenticators were rejected or if no authentication needed - if(!authenticator) { - if(fPeerAuthenticator) + if (!authenticator) { + if (fPeerAuthenticator) return B_ERROR; // all authenticators were denied else @@ -90,7 +90,7 @@ _KPPPAuthenticationHandler::AddToRequest(KPPPConfigurePacket& request) // no peer authentication needed } - if(!authenticator || !authenticator->OptionHandler()) + if (!authenticator || !authenticator->OptionHandler()) return B_ERROR; fPeerAuthenticator = authenticator; @@ -113,17 +113,17 @@ _KPPPAuthenticationHandler::ParseNak(const KPPPConfigurePacket& nak) authentication_item *item = (authentication_item*) nak.ItemWithType(kAuthenticationType); - if(!item) + if (!item) return B_OK; // the request was not rejected - if(item->length < 4) + if (item->length < 4) return B_ERROR; - if(fSuggestedPeerAuthenticator) { + if (fSuggestedPeerAuthenticator) { fSuggestedPeerAuthenticator->SetEnabled(false); // if no alternative protocol is supplied we will choose a new one in // AddToRequest() - if(ntohs(item->protocolNumber) == + if (ntohs(item->protocolNumber) == fSuggestedPeerAuthenticator->ProtocolNumber()) { fSuggestedPeerAuthenticator = NULL; return B_OK; @@ -132,7 +132,7 @@ _KPPPAuthenticationHandler::ParseNak(const KPPPConfigurePacket& nak) fPeerAuthenticatorRejected = true; KPPPProtocol *authenticator = Interface().ProtocolFor(ntohs(item->protocolNumber)); - if(authenticator && authenticator->Type() + if (authenticator && authenticator->Type() && !strcasecmp(authenticator->Type(), kAuthenticatorTypeString) && authenticator->OptionHandler()) fSuggestedPeerAuthenticator = authenticator; @@ -147,7 +147,7 @@ status_t _KPPPAuthenticationHandler::ParseReject(const KPPPConfigurePacket& reject) { // an authentication request must not be rejected! - if(reject.ItemWithType(kAuthenticationType)) + if (reject.ItemWithType(kAuthenticationType)) return B_ERROR; return B_OK; @@ -160,14 +160,14 @@ _KPPPAuthenticationHandler::ParseAck(const KPPPConfigurePacket& ack) authentication_item *item = (authentication_item*) ack.ItemWithType(kAuthenticationType); - if(!item) { - if(fPeerAuthenticator) + if (!item) { + if (fPeerAuthenticator) return B_ERROR; // the ack does not contain our request else return B_OK; // no authentication needed - } else if(!fPeerAuthenticator + } else if (!fPeerAuthenticator || ntohs(item->protocolNumber) != fPeerAuthenticator->ProtocolNumber()) return B_ERROR; // this item was never requested @@ -181,11 +181,11 @@ status_t _KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request, int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject) { - if(fLocalAuthenticator) + if (fLocalAuthenticator) fLocalAuthenticator->SetEnabled(false); authentication_item *item = (authentication_item*) request.ItemAt(index); - if(!item) + if (!item) return B_OK; // no authentication requested by peer (index > request.CountItems()) @@ -193,7 +193,7 @@ _KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request, // try to find the requested protocol fLocalAuthenticator = Interface().ProtocolFor(ntohs(item->protocolNumber)); - if(fLocalAuthenticator && fLocalAuthenticator->Type() + if (fLocalAuthenticator && fLocalAuthenticator->Type() && !strcasecmp(fLocalAuthenticator->Type(), kAuthenticatorTypeString) && fLocalAuthenticator->OptionHandler()) return fLocalAuthenticator->OptionHandler()->ParseRequest(request, index, @@ -203,8 +203,8 @@ _KPPPAuthenticationHandler::ParseRequest(const KPPPConfigurePacket& request, KPPPProtocol *nextAuthenticator = NextAuthenticator(fSuggestedLocalAuthenticator, PPP_LOCAL_SIDE); - if(!nextAuthenticator) { - if(!fSuggestedLocalAuthenticator) { + if (!nextAuthenticator) { + if (!fSuggestedLocalAuthenticator) { // reject the complete authentication option reject.AddItem((ppp_configure_item*) item); return B_OK; @@ -234,17 +234,17 @@ _KPPPAuthenticationHandler::SendingAck(const KPPPConfigurePacket& ack) authentication_item *item = (authentication_item*) ack.ItemWithType(kAuthenticationType); - if(!item) + if (!item) return B_OK; // no authentication needed fSuggestedLocalAuthenticator = NULL; - if(!fLocalAuthenticator) + if (!fLocalAuthenticator) return B_ERROR; // no authenticator selected (our suggestions must be requested, too) - if(!fLocalAuthenticator) + if (!fLocalAuthenticator) return B_ERROR; fLocalAuthenticator->SetEnabled(true); @@ -256,15 +256,15 @@ _KPPPAuthenticationHandler::SendingAck(const KPPPConfigurePacket& ack) void _KPPPAuthenticationHandler::Reset() { - if(fLocalAuthenticator) { + if (fLocalAuthenticator) { fLocalAuthenticator->SetEnabled(false); fLocalAuthenticator->OptionHandler()->Reset(); } - if(fPeerAuthenticator) { + if (fPeerAuthenticator) { fPeerAuthenticator->SetEnabled(false); fPeerAuthenticator->OptionHandler()->Reset(); } - if(fSuggestedPeerAuthenticator) { + if (fSuggestedPeerAuthenticator) { fSuggestedPeerAuthenticator->SetEnabled(false); fSuggestedPeerAuthenticator->OptionHandler()->Reset(); } diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.cpp index 8660f28b8a..a185e9d450 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPMRUHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -32,7 +32,7 @@ _KPPPMRUHandler::_KPPPMRUHandler(KPPPInterface& interface) status_t _KPPPMRUHandler::AddToRequest(KPPPConfigurePacket& request) { - if(!Interface().Device() || Interface().MRU() == 1500) + if (!Interface().Device() || Interface().MRU() == 1500) return B_OK; // add MRU request @@ -48,11 +48,11 @@ status_t _KPPPMRUHandler::ParseNak(const KPPPConfigurePacket& nak) { mru_item *item = (mru_item*) nak.ItemWithType(kMRUType); - if(!item || item->length != 4) + if (!item || item->length != 4) return B_OK; uint16 MRU = ntohs(item->MRU); - if(MRU < fLocalMRU) + if (MRU < fLocalMRU) fLocalMRU = MRU; return B_OK; @@ -62,7 +62,7 @@ _KPPPMRUHandler::ParseNak(const KPPPConfigurePacket& nak) status_t _KPPPMRUHandler::ParseReject(const KPPPConfigurePacket& reject) { - if(reject.ItemWithType(kMRUType)) + if (reject.ItemWithType(kMRUType)) return B_ERROR; return B_OK; @@ -75,10 +75,10 @@ _KPPPMRUHandler::ParseAck(const KPPPConfigurePacket& ack) uint16 MRU = 1500; mru_item *item = (mru_item*) ack.ItemWithType(kMRUType); - if(item) + if (item) MRU = ntohs(item->MRU); - if(MRU < Interface().MRU()) + if (MRU < Interface().MRU()) fLocalMRU = MRU; return B_OK; @@ -89,7 +89,7 @@ status_t _KPPPMRUHandler::ParseRequest(const KPPPConfigurePacket& request, int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject) { - if(index == reject.CountItems()) + if (index == reject.CountItems()) return B_OK; return ParseRequestedItem((mru_item*) request.ItemAt(index), Interface()); @@ -111,15 +111,15 @@ ParseRequestedItem(mru_item *item, KPPPInterface& interface) { uint16 MRU = 1500; - if(item) { - if(item->length != 4) + if (item) { + if (item->length != 4) return B_ERROR; // the request has a corrupted item MRU = ntohs(item->MRU); } - if(MRU < interface.MRU()) + if (MRU < interface.MRU()) interface.SetMRU(MRU); return B_OK; @@ -129,7 +129,7 @@ ParseRequestedItem(mru_item *item, KPPPInterface& interface) void _KPPPMRUHandler::Reset() { - if(Interface().Device()) { + if (Interface().Device()) { fLocalMRU = Interface().Device()->MTU() - 2; Interface().SetMRU(fLocalMRU); } else { diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.cpp index c179979394..1bff325155 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/_KPPPPFCHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -24,7 +24,7 @@ status_t _KPPPPFCHandler::AddToRequest(KPPPConfigurePacket& request) { // is PFC not requested or was it rejected? - if(fLocalPFCState == PPP_PFC_REJECTED + if (fLocalPFCState == PPP_PFC_REJECTED || (Interface().PFCOptions() & PPP_REQUEST_PFC) == 0) return B_OK; @@ -40,7 +40,7 @@ status_t _KPPPPFCHandler::ParseNak(const KPPPConfigurePacket& nak) { // naks do not contain PFC items - if(nak.ItemWithType(kPFCType)) + if (nak.ItemWithType(kPFCType)) return B_ERROR; return B_OK; @@ -50,10 +50,10 @@ _KPPPPFCHandler::ParseNak(const KPPPConfigurePacket& nak) status_t _KPPPPFCHandler::ParseReject(const KPPPConfigurePacket& reject) { - if(reject.ItemWithType(kPFCType)) { + if (reject.ItemWithType(kPFCType)) { fLocalPFCState = PPP_PFC_REJECTED; - if(Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST) + if (Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST) return B_ERROR; } @@ -64,12 +64,12 @@ _KPPPPFCHandler::ParseReject(const KPPPConfigurePacket& reject) status_t _KPPPPFCHandler::ParseAck(const KPPPConfigurePacket& ack) { - if(ack.ItemWithType(kPFCType)) + if (ack.ItemWithType(kPFCType)) fLocalPFCState = PPP_PFC_ACCEPTED; else { fLocalPFCState = PPP_PFC_DISABLED; - if(Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST) + if (Interface().PFCOptions() & PPP_FORCE_PFC_REQUEST) return B_ERROR; } @@ -81,10 +81,10 @@ status_t _KPPPPFCHandler::ParseRequest(const KPPPConfigurePacket& request, int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject) { - if(!request.ItemWithType(kPFCType)) + if (!request.ItemWithType(kPFCType)) return B_OK; - if((Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) { + if ((Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) { ppp_configure_item item; item.type = kPFCType; item.length = 2; @@ -100,10 +100,10 @@ _KPPPPFCHandler::SendingAck(const KPPPConfigurePacket& ack) { ppp_configure_item *item = ack.ItemWithType(kPFCType); - if(item && (Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) + if (item && (Interface().PFCOptions() & PPP_ALLOW_PFC) == 0) return B_ERROR; - if(item) + if (item) fPeerPFCState = PPP_PFC_ACCEPTED; else fPeerPFCState = PPP_PFC_DISABLED; diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/settings_tools.cpp b/src/add-ons/kernel/network/ppp/shared/libkernelppp/settings_tools.cpp index f70c277f41..5e3c5365e1 100644 --- a/src/add-ons/kernel/network/ppp/shared/libkernelppp/settings_tools.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libkernelppp/settings_tools.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -26,21 +26,21 @@ static const char *sSkipInterfaceParameters[] = { driver_settings* dup_driver_settings(const driver_settings *dup) { - if(!dup) + if (!dup) return NULL; // we got a NULL pointer, so return nothing driver_settings *ret = new_driver_settings(); ret->parameter_count = dup->parameter_count; - if(ret->parameter_count > 0) { + if (ret->parameter_count > 0) { ret->parameters = (driver_parameter*) malloc(ret->parameter_count * sizeof(driver_parameter)); memset(ret->parameters, 0, ret->parameter_count * sizeof(driver_parameter)); } else ret->parameters = NULL; - for(int32 index = 0; index < ret->parameter_count; index++) + for (int32 index = 0; index < ret->parameter_count; index++) copy_driver_parameter(&dup->parameters[index], &ret->parameters[index]); return ret; @@ -50,10 +50,10 @@ dup_driver_settings(const driver_settings *dup) void free_driver_settings(driver_settings *settings) { - if(!settings) + if (!settings) return; - for(int32 index = 0; index < settings->parameter_count; index++) + for (int32 index = 0; index < settings->parameter_count; index++) free_driver_parameter_fields(&settings->parameters[index]); free(settings->parameters); @@ -74,12 +74,12 @@ free_driver_parameter_fields(driver_parameter *parameter) { free(parameter->name); - for(int32 index = 0; index < parameter->value_count; index++) + for (int32 index = 0; index < parameter->value_count; index++) free(parameter->values[index]); free(parameter->values); - for(int32 index = 0; index < parameter->parameter_count; index++) + for (int32 index = 0; index < parameter->parameter_count; index++) free_driver_parameter_fields(¶meter->parameters[index]); free(parameter->parameters); @@ -111,35 +111,35 @@ new_driver_parameter(const char *name) bool copy_driver_parameter(const driver_parameter *from, driver_parameter *to) { - if(!from || !to) + if (!from || !to) return false; free_driver_parameter_fields(to); - if(from->name) + if (from->name) to->name = strdup(from->name); else to->name = NULL; to->value_count = from->value_count; - if(from->value_count > 0) + if (from->value_count > 0) to->values = (char**) malloc(from->value_count * sizeof(char*)); else to->values = NULL; - for(int32 index = 0; index < to->value_count; index++) + for (int32 index = 0; index < to->value_count; index++) to->values[index] = strdup(from->values[index]); to->parameter_count = from->parameter_count; - if(to->parameter_count > 0) { + if (to->parameter_count > 0) { to->parameters = (driver_parameter*) malloc(to->parameter_count * sizeof(driver_parameter)); memset(to->parameters, 0, to->parameter_count * sizeof(driver_parameter)); } else to->parameters = NULL; - for(int32 index = 0; index < to->parameter_count; index++) + for (int32 index = 0; index < to->parameter_count; index++) copy_driver_parameter(&from->parameters[index], &to->parameters[index]); return true; @@ -149,12 +149,12 @@ copy_driver_parameter(const driver_parameter *from, driver_parameter *to) bool set_driver_parameter_name(const char *name, driver_parameter *parameter) { - if(!parameter) + if (!parameter) return false; free(parameter->name); - if(name) + if (name) parameter->name = strdup(name); else parameter->name = NULL; @@ -166,7 +166,7 @@ set_driver_parameter_name(const char *name, driver_parameter *parameter) bool add_driver_parameter_value(const char *value, driver_parameter *to) { - if(!value || !to) + if (!value || !to) return false; int32 oldCount = to->value_count; @@ -174,7 +174,7 @@ add_driver_parameter_value(const char *value, driver_parameter *to) to->values = (char**) malloc((oldCount + 1) * sizeof(char*)); - if(!to->values) { + if (!to->values) { to->values = old; return false; } @@ -190,7 +190,7 @@ add_driver_parameter_value(const char *value, driver_parameter *to) bool add_driver_parameter(driver_parameter *add, driver_settings *to) { - if(!add || !to) + if (!add || !to) return false; int32 oldCount = to->parameter_count; @@ -199,7 +199,7 @@ add_driver_parameter(driver_parameter *add, driver_settings *to) to->parameters = (driver_parameter*) malloc((oldCount + 1) * sizeof(driver_parameter)); - if(!to->parameters) { + if (!to->parameters) { to->parameters = old; return false; } @@ -215,16 +215,16 @@ add_driver_parameter(driver_parameter *add, driver_settings *to) bool equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs) { - if(!lhs && !rhs) + if (!lhs && !rhs) return true; - else if(!lhs || !rhs) + else if (!lhs || !rhs) return false; - if(lhs->parameter_count != rhs->parameter_count) + if (lhs->parameter_count != rhs->parameter_count) return false; - for(int32 index = 0; index < lhs->parameter_count; index++) { - if(!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index])) + for (int32 index = 0; index < lhs->parameter_count; index++) { + if (!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index])) return false; } @@ -235,28 +235,28 @@ equal_driver_settings(const driver_settings *lhs, const driver_settings *rhs) bool equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs) { - if(!lhs && !rhs) + if (!lhs && !rhs) return true; - else if(!lhs || !rhs) + else if (!lhs || !rhs) return false; - if(lhs->name && rhs->name) { - if(strcmp(lhs->name, rhs->name)) + if (lhs->name && rhs->name) { + if (strcmp(lhs->name, rhs->name)) return false; - } else if(lhs->name != rhs->name) + } else if (lhs->name != rhs->name) return false; - if(lhs->value_count != rhs->value_count + if (lhs->value_count != rhs->value_count || lhs->parameter_count != rhs->parameter_count) return false; - for(int32 index = 0; index < lhs->value_count; index++) { - if(strcmp(lhs->values[index], rhs->values[index])) + for (int32 index = 0; index < lhs->value_count; index++) { + if (strcmp(lhs->values[index], rhs->values[index])) return false; } - for(int32 index = 0; index < lhs->parameter_count; index++) { - if(!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index])) + for (int32 index = 0; index < lhs->parameter_count; index++) { + if (!equal_driver_parameters(&lhs->parameters[index], &rhs->parameters[index])) return false; } @@ -267,11 +267,11 @@ equal_driver_parameters(const driver_parameter *lhs, const driver_parameter *rhs bool skip_interface_parameter(const driver_parameter *parameter) { - if(!parameter || !parameter->name) + if (!parameter || !parameter->name) return false; - for(int32 index = 0; sSkipInterfaceParameters[index]; index++) - if(!strcasecmp(parameter->name, sSkipInterfaceParameters[index])) + for (int32 index = 0; sSkipInterfaceParameters[index]; index++) + if (!strcasecmp(parameter->name, sSkipInterfaceParameters[index])) return true; return false; @@ -281,30 +281,30 @@ skip_interface_parameter(const driver_parameter *parameter) bool equal_interface_settings(const driver_settings *lhs, const driver_settings *rhs) { - if(!lhs && !rhs) + if (!lhs && !rhs) return true; - else if(!lhs || !rhs) + else if (!lhs || !rhs) return false; int32 lhsIndex = 0, rhsIndex = 0; - for(; lhsIndex < lhs->parameter_count; lhsIndex++) { - if(skip_interface_parameter(&lhs->parameters[lhsIndex])) + for (; lhsIndex < lhs->parameter_count; lhsIndex++) { + if (skip_interface_parameter(&lhs->parameters[lhsIndex])) continue; - for(; rhsIndex < rhs->parameter_count; rhsIndex++) - if(!skip_interface_parameter(&rhs->parameters[rhsIndex])) + for (; rhsIndex < rhs->parameter_count; rhsIndex++) + if (!skip_interface_parameter(&rhs->parameters[rhsIndex])) break; - if(rhsIndex >= rhs->parameter_count) + if (rhsIndex >= rhs->parameter_count) return false; - if(!equal_driver_parameters(&lhs->parameters[lhsIndex], + if (!equal_driver_parameters(&lhs->parameters[lhsIndex], &rhs->parameters[rhsIndex])) return false; } - for(; rhsIndex < rhs->parameter_count; rhsIndex++) - if(!skip_interface_parameter(&rhs->parameters[rhsIndex])) + for (; rhsIndex < rhs->parameter_count; rhsIndex++) + if (!skip_interface_parameter(&rhs->parameters[rhsIndex])) return false; return true; @@ -314,17 +314,17 @@ equal_interface_settings(const driver_settings *lhs, const driver_settings *rhs) ppp_side get_side_string_value(const char *sideString, ppp_side unknownValue) { - if(!sideString) + if (!sideString) return unknownValue; - if(!strcasecmp(sideString, "local")) + if (!strcasecmp(sideString, "local")) return PPP_LOCAL_SIDE; - if(!strcasecmp(sideString, "peer")) + if (!strcasecmp(sideString, "peer")) return PPP_PEER_SIDE; - if(!strcasecmp(sideString, "none") + if (!strcasecmp(sideString, "none") || !strcasecmp(sideString, "no")) return PPP_NO_SIDE; - if(!strcasecmp(sideString, "both")) + if (!strcasecmp(sideString, "both")) return PPP_BOTH_SIDES; // no correct value has been found => return default value @@ -335,7 +335,7 @@ get_side_string_value(const char *sideString, ppp_side unknownValue) bool get_boolean_value(const char *string, bool unknownValue) { - if(!string) + if (!string) return unknownValue; if (!strcmp(string, "1") @@ -362,11 +362,11 @@ get_boolean_value(const char *string, bool unknownValue) const driver_parameter* get_parameter_with_name(const char *name, const driver_settings *settings) { - if(!name || !settings) + if (!name || !settings) return NULL; - for(int32 index = 0; index < settings->parameter_count; index++) - if(!strcasecmp(settings->parameters[index].name, name)) + for (int32 index = 0; index < settings->parameter_count; index++) + if (!strcasecmp(settings->parameters[index].name, name)) return &settings->parameters[index]; return NULL; @@ -378,7 +378,7 @@ get_settings_value(const char *name, const driver_settings *settings) { const driver_parameter *parameter = get_parameter_with_name(name, settings); - if(parameter && parameter->value_count > 0 && parameter->values) + if (parameter && parameter->value_count > 0 && parameter->values) return parameter->values[0]; return NULL; diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/MessageDriverSettingsUtils.cpp b/src/add-ons/kernel/network/ppp/shared/libppp/MessageDriverSettingsUtils.cpp index af0d1ff44e..e3912e8257 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/MessageDriverSettingsUtils.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libppp/MessageDriverSettingsUtils.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2004, Waldemar Kornewald + * Copyright 2004-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -24,10 +24,10 @@ FindMessageParameter(const char *name, const BMessage& message, BMessage *save, // XXX: this should be removed when we can replace BMessage with something better BString string; int32 index = startIndex ? *startIndex : 0; - for(; message.FindMessage(MDSU_PARAMETERS, index, save) == B_OK; index++) { - if(save->FindString(MDSU_NAME, &string) == B_OK + for (; message.FindMessage(MDSU_PARAMETERS, index, save) == B_OK; index++) { + if (save->FindString(MDSU_NAME, &string) == B_OK && string.ICompare(name) == 0) { - if(startIndex) + if (startIndex) *startIndex = index; return true; } @@ -42,9 +42,9 @@ bool AddValues(const BMessage& message, driver_parameter *parameter) { const char *value; - for(int32 index = 0; message.FindString(MDSU_VALUES, index, &value) == B_OK; + for (int32 index = 0; message.FindString(MDSU_VALUES, index, &value) == B_OK; index++) - if(!add_driver_parameter_value(value, parameter)) + if (!add_driver_parameter_value(value, parameter)) return false; return true; @@ -55,7 +55,7 @@ inline bool AddParameters(const BMessage& message, driver_parameter *to) { - if(!to) + if (!to) return false; return AddParameters(message, @@ -70,11 +70,11 @@ AddParameters(const BMessage& message, driver_settings *to) const char *name; BMessage current; driver_parameter *parameter; - for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, + for (int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, ¤t) == B_OK; index++) { name = current.FindString(MDSU_NAME); parameter = new_driver_parameter(name); - if(!AddValues(current, parameter)) + if (!AddValues(current, parameter)) return false; AddParameters(current, parameter); @@ -90,7 +90,7 @@ MessageToDriverSettings(const BMessage& message) { driver_settings *settings = new_driver_settings(); - if(!AddParameters(message, settings)) { + if (!AddParameters(message, settings)) { free_driver_settings(settings); return NULL; } @@ -103,19 +103,19 @@ static bool AddParameter(const driver_parameter *parameter, BMessage *message) { - if(!parameter || !message) + if (!parameter || !message) return false; - if(parameter->name) + if (parameter->name) message->AddString(MDSU_NAME, parameter->name); else return false; - for(int32 index = 0; index < parameter->value_count; index++) - if(parameter->values[index]) + for (int32 index = 0; index < parameter->value_count; index++) + if (parameter->values[index]) message->AddString(MDSU_VALUES, parameter->values[index]); - for(int32 index = 0; index < parameter->parameter_count; index++) { + for (int32 index = 0; index < parameter->parameter_count; index++) { BMessage parameterMessage; AddParameter(¶meter->parameters[index], ¶meterMessage); message->AddMessage(MDSU_PARAMETERS, ¶meterMessage); @@ -128,19 +128,19 @@ AddParameter(const driver_parameter *parameter, BMessage *message) bool ReadMessageDriverSettings(const char *name, BMessage *message) { - if(!name || !message) + if (!name || !message) return false; void *handle = load_driver_settings(name); - if(!handle) + if (!handle) return false; const driver_settings *settings = get_driver_settings(handle); - if(!settings) { + if (!settings) { unload_driver_settings(handle); return false; } - for(int32 index = 0; index < settings->parameter_count; index++) { + for (int32 index = 0; index < settings->parameter_count; index++) { BMessage parameter; AddParameter(&settings->parameters[index], ¶meter); message->AddMessage(MDSU_PARAMETERS, ¶meter); @@ -168,30 +168,30 @@ bool WriteParameter(BFile& file, const BMessage& parameter, int32 level) { const char *name; - if(parameter.FindString(MDSU_NAME, &name) != B_OK || !name) + if (parameter.FindString(MDSU_NAME, &name) != B_OK || !name) return false; BString line, word(name); EscapeWord(word); bool needsEscaping = word.FindFirst(' ') >= 0; line.SetTo('\t', level); - if(needsEscaping) + if (needsEscaping) line << '\"'; line << word; - if(needsEscaping) + if (needsEscaping) line << '\"'; - for(int32 index = 0; parameter.FindString(MDSU_VALUES, index, &name) == B_OK; + for (int32 index = 0; parameter.FindString(MDSU_VALUES, index, &name) == B_OK; index++) - if(name) { + if (name) { line << ' '; word = name; EscapeWord(word); needsEscaping = word.FindFirst(' ') >= 0; - if(needsEscaping) + if (needsEscaping) line << '\"'; line << word; - if(needsEscaping) + if (needsEscaping) line << '\"'; } @@ -199,15 +199,15 @@ WriteParameter(BFile& file, const BMessage& parameter, int32 level) int32 parameterCount; parameter.GetInfo(MDSU_PARAMETERS, &type, ¶meterCount); - if(parameterCount > 0) + if (parameterCount > 0) line << " {"; line << '\n'; file.Write(line.String(), line.Length()); - if(parameterCount > 0) { + if (parameterCount > 0) { BMessage subParameter; - for(int32 index = 0; parameter.FindMessage(MDSU_PARAMETERS, index, + for (int32 index = 0; parameter.FindMessage(MDSU_PARAMETERS, index, &subParameter) == B_OK; index++) WriteParameter(file, subParameter, level + 1); @@ -223,16 +223,16 @@ WriteParameter(BFile& file, const BMessage& parameter, int32 level) bool WriteMessageDriverSettings(BFile& file, const BMessage& message) { - if(file.InitCheck() != B_OK || !file.IsWritable()) + if (file.InitCheck() != B_OK || !file.IsWritable()) return false; file.SetSize(0); file.Seek(0, SEEK_SET); BMessage parameter; - for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, ¶meter) == B_OK; + for (int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, ¶meter) == B_OK; index++) { - if(index > 0) + if (index > 0) file.Write("\n", 1); WriteParameter(file, parameter, 0); } diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterface.cpp b/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterface.cpp index 5d7a357286..5a4118c1c3 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterface.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterface.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -45,7 +45,7 @@ PPPInterface::PPPInterface(const PPPInterface& copy) //! Destructor. PPPInterface::~PPPInterface() { - if(fFD >= 0) + if (fFD >= 0) close(fFD); } @@ -62,9 +62,9 @@ PPPInterface::~PPPInterface() status_t PPPInterface::InitCheck() const { - if(fFD < 0) + if (fFD < 0) return B_ERROR; - if(fID == PPP_UNDEFINED_INTERFACE_ID) + if (fID == PPP_UNDEFINED_INTERFACE_ID) return B_BAD_INDEX; return B_OK; @@ -87,11 +87,11 @@ PPPInterface::InitCheck() const status_t PPPInterface::SetTo(ppp_interface_id ID) { - if(fFD < 0) + if (fFD < 0) return B_ERROR; ppp_interface_info_t info; - if(GetInterfaceInfo(&info)) { + if (GetInterfaceInfo(&info)) { fName = info.info.name; fID = ID; } else { @@ -119,7 +119,7 @@ PPPInterface::SetTo(ppp_interface_id ID) status_t PPPInterface::Control(uint32 op, void *data, size_t length) const { - if(InitCheck() != B_OK) + if (InitCheck() != B_OK) return InitCheck(); ppp_control_info control; @@ -143,7 +143,7 @@ PPPInterface::Control(uint32 op, void *data, size_t length) const bool PPPInterface::SetUsername(const char *username) const { - if(InitCheck() != B_OK || !username) + if (InitCheck() != B_OK || !username) return false; return Control(PPPC_SET_USERNAME, const_cast(username), strlen(username)) @@ -155,7 +155,7 @@ PPPInterface::SetUsername(const char *username) const bool PPPInterface::SetPassword(const char *password) const { - if(InitCheck() != B_OK || !password) + if (InitCheck() != B_OK || !password) return false; return Control(PPPC_SET_PASSWORD, const_cast(password), strlen(password)) @@ -167,7 +167,7 @@ PPPInterface::SetPassword(const char *password) const bool PPPInterface::SetAskBeforeConnecting(bool askBeforeConnecting) const { - if(InitCheck() != B_OK) + if (InitCheck() != B_OK) return false; uint32 value = askBeforeConnecting ? 1 : 0; @@ -188,9 +188,9 @@ PPPInterface::SetAskBeforeConnecting(bool askBeforeConnecting) const status_t PPPInterface::GetSettingsEntry(BEntry *entry) const { - if(InitCheck() != B_OK) + if (InitCheck() != B_OK) return InitCheck(); - else if(!entry || strlen(Name()) == 0) + else if (!entry || strlen(Name()) == 0) return B_BAD_VALUE; BDirectory directory(PTP_INTERFACE_SETTINGS_PATH); @@ -205,7 +205,7 @@ PPPInterface::GetSettingsEntry(BEntry *entry) const bool PPPInterface::GetInterfaceInfo(ppp_interface_info_t *info) const { - if(InitCheck() != B_OK || !info) + if (InitCheck() != B_OK || !info) return false; return Control(PPPC_GET_INTERFACE_INFO, &info, sizeof(ppp_interface_info_t)) @@ -222,7 +222,7 @@ PPPInterface::GetInterfaceInfo(ppp_interface_info_t *info) const bool PPPInterface::GetStatistics(ppp_statistics *statistics) const { - if(!statistics) + if (!statistics) return false; return Control(PPPC_GET_STATISTICS, statistics, sizeof(ppp_statistics)) == B_OK; @@ -233,10 +233,10 @@ PPPInterface::GetStatistics(ppp_statistics *statistics) const bool PPPInterface::HasSettings(const driver_settings *settings) const { - if(InitCheck() != B_OK || !settings) + if (InitCheck() != B_OK || !settings) return false; - if(Control(PPPC_HAS_INTERFACE_SETTINGS, const_cast(settings), + if (Control(PPPC_HAS_INTERFACE_SETTINGS, const_cast(settings), sizeof(driver_settings)) == B_OK) return true; @@ -248,7 +248,7 @@ PPPInterface::HasSettings(const driver_settings *settings) const bool PPPInterface::Up() const { - if(InitCheck() != B_OK) + if (InitCheck() != B_OK) return false; int32 id = ID(); @@ -266,7 +266,7 @@ PPPInterface::Up() const bool PPPInterface::Down() const { - if(InitCheck() != B_OK) + if (InitCheck() != B_OK) return false; int32 id = ID(); diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterfaceListener.cpp b/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterfaceListener.cpp index 19171b303a..8a71bf4ac1 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterfaceListener.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libppp/PPPInterfaceListener.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -40,22 +40,22 @@ report_thread(void *data) thread_id sender; BMessage message; - while(true) { + while (true) { code = receive_data(&sender, &report, sizeof(report)); - if(code == kCodeQuitReportThread) + if (code == kCodeQuitReportThread) break; - else if(code != PPP_REPORT_CODE) + else if (code != PPP_REPORT_CODE) continue; BMessenger messenger(listener->Target()); - if(messenger.IsValid()) { + if (messenger.IsValid()) { message.MakeEmpty(); message.what = PPP_REPORT_MESSAGE; message.AddInt32("type", report.type); message.AddInt32("code", report.code); - if(report.length >= sizeof(ppp_interface_id) + if (report.length >= sizeof(ppp_interface_id) && ((report.type == PPP_MANAGER_REPORT && report.code == PPP_REPORT_INTERFACE_CREATED) || report.type >= PPP_INTERFACE_REPORT_TYPE_MIN)) { @@ -121,7 +121,7 @@ PPPInterfaceListener::~PPPInterfaceListener() status_t PPPInterfaceListener::InitCheck() const { - if(fReportThread < 0) + if (fReportThread < 0) return B_ERROR; return Manager().InitCheck(); @@ -147,20 +147,20 @@ PPPInterfaceListener::SetTarget(BHandler *target) bool PPPInterfaceListener::WatchInterface(ppp_interface_id ID) { - if(ID == fInterface) + if (ID == fInterface) return true; StopWatchingInterface(); - if(ID == PPP_UNDEFINED_INTERFACE_ID) + if (ID == PPP_UNDEFINED_INTERFACE_ID) return true; // enable reports PPPInterface interface(ID); - if(interface.InitCheck() != B_OK) + if (interface.InitCheck() != B_OK) return false; - if(!interface.EnableReports(PPP_CONNECTION_REPORT, fReportThread, PPP_NO_FLAGS)) + if (!interface.EnableReports(PPP_CONNECTION_REPORT, fReportThread, PPP_NO_FLAGS)) return false; fIsWatching = true; @@ -185,7 +185,7 @@ PPPInterfaceListener::WatchManager() void PPPInterfaceListener::StopWatchingInterface() { - if(!fIsWatching) + if (!fIsWatching) return; PPPInterface interface(fInterface); diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/PPPManager.cpp b/src/add-ons/kernel/network/ppp/shared/libppp/PPPManager.cpp index ae403efed3..3ca8c5a453 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/PPPManager.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libppp/PPPManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -36,7 +36,7 @@ PPPManager::PPPManager() //! Destructor. PPPManager::~PPPManager() { - if(fFD >= 0) + if (fFD >= 0) close(fFD); } @@ -47,26 +47,26 @@ PPPManager::SetDefaultInterface(const BString name) { // load current settings and replace value of "default" with BMessage settings; - if(!ReadMessageDriverSettings("ptpnet.settings", &settings)) + if (!ReadMessageDriverSettings("ptpnet.settings", &settings)) settings.MakeEmpty(); BMessage parameter; int32 index = 0; - if(FindMessageParameter("default", settings, ¶meter, &index)) + if (FindMessageParameter("default", settings, ¶meter, &index)) settings.RemoveData(MDSU_PARAMETERS, index); parameter.MakeEmpty(); - if(name != "") { + if (name != "") { parameter.AddString(MDSU_NAME, "default"); parameter.AddString(MDSU_VALUES, name); settings.AddMessage(MDSU_PARAMETERS, ¶meter); } BFile file(PTP_SETTINGS_PATH, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); - if(file.InitCheck() != B_OK) + if (file.InitCheck() != B_OK) return false; - if(WriteMessageDriverSettings(file, settings)) + if (WriteMessageDriverSettings(file, settings)) return true; else return false; @@ -88,12 +88,12 @@ PPPManager::DefaultInterface() bool PPPManager::GetSettingsDirectory(BDirectory *settingsDirectory) { - if(settingsDirectory) { + if (settingsDirectory) { BDirectory settings(PTP_INTERFACE_SETTINGS_PATH); - if(settings.InitCheck() != B_OK) { + if (settings.InitCheck() != B_OK) { create_directory(PTP_INTERFACE_SETTINGS_PATH, 0750); settings.SetTo(PTP_INTERFACE_SETTINGS_PATH); - if(settings.InitCheck() != B_OK) + if (settings.InitCheck() != B_OK) return false; } @@ -108,7 +108,7 @@ PPPManager::GetSettingsDirectory(BDirectory *settingsDirectory) status_t PPPManager::InitCheck() const { - if(fFD < 0) + if (fFD < 0) return B_ERROR; else return B_OK; @@ -129,7 +129,7 @@ PPPManager::InitCheck() const status_t PPPManager::Control(uint32 op, void *data, size_t length) const { - if(InitCheck() != B_OK) + if (InitCheck() != B_OK) return B_ERROR; control_net_module_args args; @@ -165,7 +165,7 @@ status_t PPPManager::ControlModule(const char *name, uint32 op, void *data, size_t length) const { - if(!name) + if (!name) return B_ERROR; control_net_module_args args; @@ -189,7 +189,7 @@ PPPManager::CreateInterface(const driver_settings *settings) const ppp_interface_description_info info; info.u.settings = settings; - if(Control(PPPC_CREATE_INTERFACE, &info, sizeof(info)) != B_OK) + if (Control(PPPC_CREATE_INTERFACE, &info, sizeof(info)) != B_OK) return PPP_UNDEFINED_INTERFACE_ID; else return info.interface; @@ -210,7 +210,7 @@ PPPManager::CreateInterfaceWithName(const char *name) const ppp_interface_description_info info; info.u.name = name; - if(Control(PPPC_CREATE_INTERFACE_WITH_NAME, &info, sizeof(info)) != B_OK) + if (Control(PPPC_CREATE_INTERFACE_WITH_NAME, &info, sizeof(info)) != B_OK) return PPP_UNDEFINED_INTERFACE_ID; else return info.interface; @@ -221,7 +221,7 @@ PPPManager::CreateInterfaceWithName(const char *name) const bool PPPManager::DeleteInterface(ppp_interface_id ID) const { - if(Control(PPPC_DELETE_INTERFACE, &ID, sizeof(ID)) != B_OK) + if (Control(PPPC_DELETE_INTERFACE, &ID, sizeof(ID)) != B_OK) return false; else return true; @@ -251,21 +251,21 @@ PPPManager::Interfaces(int32 *count, ppp_interface_id *interfaces; // loop until we get all interfaces - while(true) { + while (true) { requestCount = *count = CountInterfaces(filter); - if(*count == -1) + if (*count == -1) return NULL; requestCount += 10; // request some more interfaces in case some are added in the mean time interfaces = new ppp_interface_id[requestCount]; *count = GetInterfaces(interfaces, requestCount, filter); - if(*count == -1) { + if (*count == -1) { delete interfaces; return NULL; } - if(*count < requestCount) + if (*count < requestCount) break; delete interfaces; @@ -285,7 +285,7 @@ PPPManager::GetInterfaces(ppp_interface_id *interfaces, int32 count, info.count = count; info.filter = filter; - if(Control(PPPC_GET_INTERFACES, &info, sizeof(info)) != B_OK) + if (Control(PPPC_GET_INTERFACES, &info, sizeof(info)) != B_OK) return -1; else return info.resultCount; @@ -313,16 +313,16 @@ PPPManager::InterfaceWithUnit(int32 if_unit) const int32 count; ppp_interface_id *interfaces = Interfaces(&count, PPP_REGISTERED_INTERFACES); - if(!interfaces) + if (!interfaces) return PPP_UNDEFINED_INTERFACE_ID; ppp_interface_id id = PPP_UNDEFINED_INTERFACE_ID; PPPInterface interface; ppp_interface_info_t info; - for(int32 index = 0; index < count; index++) { + for (int32 index = 0; index < count; index++) { interface.SetTo(interfaces[index]); - if(interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info) + if (interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info) && info.info.if_unit == if_unit) { id = interface.ID(); break; @@ -339,22 +339,22 @@ PPPManager::InterfaceWithUnit(int32 if_unit) const ppp_interface_id PPPManager::InterfaceWithName(const char *name) const { - if(!name) + if (!name) return PPP_UNDEFINED_INTERFACE_ID; int32 count; ppp_interface_id *interfaces = Interfaces(&count, PPP_REGISTERED_INTERFACES); - if(!interfaces) + if (!interfaces) return PPP_UNDEFINED_INTERFACE_ID; ppp_interface_id id = PPP_UNDEFINED_INTERFACE_ID; PPPInterface interface; ppp_interface_info_t info; - for(int32 index = 0; index < count; index++) { + for (int32 index = 0; index < count; index++) { interface.SetTo(interfaces[index]); - if(interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info) + if (interface.InitCheck() == B_OK && interface.GetInterfaceInfo(&info) && strlen(info.info.name) > 0 && !strcasecmp(info.info.name, name)) { id = interface.ID(); break; @@ -363,11 +363,11 @@ PPPManager::InterfaceWithName(const char *name) const delete interfaces; - if(id != PPP_UNDEFINED_INTERFACE_ID) + if (id != PPP_UNDEFINED_INTERFACE_ID) return id; - else if(!strncmp(name, "ppp", 3) && strlen(name) > 3 && isdigit(name[3])) + else if (!strncmp(name, "ppp", 3) && strlen(name) > 3 && isdigit(name[3])) return InterfaceWithUnit(atoi(name + 3)); - else if(isdigit(name[0])) + else if (isdigit(name[0])) return atoi(name); else return PPP_UNDEFINED_INTERFACE_ID; diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.cpp b/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.cpp index 6de6e33cee..b81c10fde2 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.cpp +++ b/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */ @@ -16,7 +16,7 @@ get_stack_driver_path() // user-defined stack driver path? path = getenv("NET_STACK_DRIVER_PATH"); - if(path) + if (path) return path; // use the default stack driver path diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.h b/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.h index 91bd4c7f7c..db72c1aaca 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.h +++ b/src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2005, Waldemar Kornewald + * Copyright 2003-2007, Waldemar Kornewald * Distributed under the terms of the MIT License. */