Ticket #812: 0001-merge-pppoe_branch.patch
File 0001-merge-pppoe_branch.patch, 259.8 KB (added by , 11 years ago) |
---|
-
build/jam/HaikuImage
From f90e7e6fc79b73f3a0e0edd7502d3fa45831b5be Mon Sep 17 00:00:00 2001 From: mshlyn <linlongzhou@163.com> Date: Wed, 20 Mar 2013 01:34:37 +0800 Subject: [PATCH] merge pppoe_branch --- build/jam/HaikuImage | 5 +- build/jam/ReleaseBuildProfiles | 2 +- headers/private/net/net_datalink.h | 5 + headers/private/net/net_datalink_protocol.h | 3 +- headers/private/net/net_stack.h | 2 + src/add-ons/kernel/network/Jamfile | 1 + .../ethernet_frame/ethernet_frame.cpp | 12 +- .../kernel/network/devices/ethernet/ethernet.cpp | 3 +- src/add-ons/kernel/network/ppp/Jamfile | 5 +- src/add-ons/kernel/network/ppp/KPPPManager/Jamfile | 44 ++ .../kernel/network/ppp/KPPPManager/KPPPManager.cpp | 375 +++++++++ src/add-ons/kernel/network/ppp/ipcp/Jamfile | 38 +- src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp | 876 ++++++++++++--------- src/add-ons/kernel/network/ppp/ipcp/Protocol.h | 38 +- src/add-ons/kernel/network/ppp/ipcp/bitypes.h | 1 + src/add-ons/kernel/network/ppp/ipcp/config.h | 69 ++ src/add-ons/kernel/network/ppp/ipcp/ipcp.cpp | 44 +- src/add-ons/kernel/network/ppp/ipcp/port_after.h | 529 +++++++++++++ src/add-ons/kernel/network/ppp/ipcp/port_before.h | 215 +++++ src/add-ons/kernel/network/ppp/pap/Jamfile | 8 +- src/add-ons/kernel/network/ppp/pap/Protocol.cpp | 141 ++-- src/add-ons/kernel/network/ppp/pap/Protocol.h | 15 +- src/add-ons/kernel/network/ppp/pap/pap.cpp | 25 +- src/add-ons/kernel/network/ppp/ppp/Jamfile | 38 + src/add-ons/kernel/network/ppp/ppp/ppp.cpp | 390 +++++++++ src/add-ons/kernel/network/ppp/ppp_frame/Jamfile | 40 + .../kernel/network/ppp/ppp_frame/ppp_frame.cpp | 318 ++++++++ .../kernel/network/ppp/pppoe/DiscoveryPacket.cpp | 57 +- .../kernel/network/ppp/pppoe/DiscoveryPacket.h | 9 +- src/add-ons/kernel/network/ppp/pppoe/Jamfile | 8 +- src/add-ons/kernel/network/ppp/pppoe/PPPoE.h | 9 +- .../kernel/network/ppp/pppoe/PPPoEDevice.cpp | 316 +++++--- src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h | 18 +- src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp | 231 ++++-- .../kernel/network/ppp/shared/libkernelppp/Jamfile | 6 +- .../shared/libkernelppp/KPPPConfigurePacket.cpp | 60 +- .../network/ppp/shared/libkernelppp/KPPPDevice.cpp | 3 +- .../ppp/shared/libkernelppp/KPPPInterface.cpp | 246 +++--- .../network/ppp/shared/libkernelppp/KPPPLCP.cpp | 48 +- .../network/ppp/shared/libkernelppp/KPPPLayer.cpp | 8 +- .../ppp/shared/libkernelppp/KPPPReportManager.cpp | 14 +- .../ppp/shared/libkernelppp/KPPPStateMachine.cpp | 424 ++++++---- .../libkernelppp/headers/KPPPConfigurePacket.h | 9 +- .../ppp/shared/libkernelppp/headers/KPPPDevice.h | 6 +- .../shared/libkernelppp/headers/KPPPInterface.h | 22 +- .../ppp/shared/libkernelppp/headers/KPPPLCP.h | 7 +- .../shared/libkernelppp/headers/KPPPLCPExtension.h | 2 +- .../ppp/shared/libkernelppp/headers/KPPPLayer.h | 7 +- .../ppp/shared/libkernelppp/headers/KPPPManager.h | 13 +- .../ppp/shared/libkernelppp/headers/KPPPProtocol.h | 4 +- .../libkernelppp/headers/KPPPReportManager.h | 7 +- .../shared/libkernelppp/headers/KPPPStateMachine.h | 39 +- .../ppp/shared/libkernelppp/headers/PPPDefs.h | 5 +- .../ppp/shared/libkernelppp/headers/asm_defs.h | 17 + .../ppp/shared/libkernelppp/headers/directories.h | 69 ++ .../ppp/shared/libkernelppp/headers/ppp_device.h | 17 + .../ppp/shared/libkernelppp/settings_tools.cpp | 7 +- .../kernel/network/ppp/shared/libppp/Jamfile | 5 +- .../network/ppp/shared/libppp/_libppputils.cpp | 2 +- .../network/ppp/shared/libppp/_libppputils.h | 6 +- .../network/ppp/shared/libppp/headers/PPPManager.h | 1 + .../network/ppp/shared/libppp/net_stack_driver.h | 162 ++++ src/add-ons/kernel/network/stack/datalink.cpp | 43 +- .../kernel/network/stack/device_interfaces.cpp | 7 +- src/add-ons/kernel/network/stack/interfaces.cpp | 75 ++ src/add-ons/kernel/network/stack/interfaces.h | 2 + src/add-ons/kernel/network/stack/stack.cpp | 4 + src/bin/network/Jamfile | 4 +- src/bin/network/ifconfig/ifconfig.cpp | 4 +- src/bin/network/ppp_up/Jamfile | 8 +- src/bin/network/ppp_up/PPPStatusView.h | 4 +- src/bin/network/pppconfig/Jamfile | 4 +- 72 files changed, 4190 insertions(+), 1071 deletions(-) create mode 100644 src/add-ons/kernel/network/ppp/KPPPManager/Jamfile create mode 100644 src/add-ons/kernel/network/ppp/KPPPManager/KPPPManager.cpp create mode 100644 src/add-ons/kernel/network/ppp/ipcp/bitypes.h create mode 100644 src/add-ons/kernel/network/ppp/ipcp/config.h create mode 100644 src/add-ons/kernel/network/ppp/ipcp/port_after.h create mode 100644 src/add-ons/kernel/network/ppp/ipcp/port_before.h create mode 100644 src/add-ons/kernel/network/ppp/ppp/Jamfile create mode 100644 src/add-ons/kernel/network/ppp/ppp/ppp.cpp create mode 100644 src/add-ons/kernel/network/ppp/ppp_frame/Jamfile create mode 100644 src/add-ons/kernel/network/ppp/ppp_frame/ppp_frame.cpp create mode 100644 src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/asm_defs.h create mode 100644 src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/directories.h create mode 100644 src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/ppp_device.h create mode 100644 src/add-ons/kernel/network/ppp/shared/libppp/net_stack_driver.h diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index 9bf9115..533c6b9 100644
a b SYSTEM_SERVERS = [ FFilterByBuildFeatures 90 90 syslog_daemon dns_resolver_server nfs4_idmapper_server 91 91 ] ; 92 92 93 SYSTEM_NETWORK_DEVICES = ethernet loopback ;93 SYSTEM_NETWORK_DEVICES = ethernet loopback ppp ; 94 94 SYSTEM_NETWORK_DATALINK_PROTOCOLS = ethernet_frame <module>arp loopback_frame 95 ipv6_datagram ; 95 ipv6_datagram ppp_frame ; 96 SYSTEM_NETWORK_PPP = ipcp pap pppoe KPPPManager ; 96 97 #SYSTEM_NETWORK_PPP = ipcp modem pap pppoe ; 97 98 SYSTEM_NETWORK_PROTOCOLS = ipv4 tcp udp icmp unix icmp6 ipv6 ; 98 99 -
build/jam/ReleaseBuildProfiles
diff --git a/build/jam/ReleaseBuildProfiles b/build/jam/ReleaseBuildProfiles index 0fc925f..70b68b4 100644
a b switch $(HAIKU_BUILD_PROFILE) { 41 41 AddGroupToHaikuImage party : 101 : user sshd ; 42 42 HAIKU_STRIP_DEBUG_FROM_OPTIONAL_PACKAGES = 1 ; 43 43 HAIKU_IMAGE_HOST_NAME = shredder ; 44 HAIKU_IMAGE_SIZE = 600 ;44 HAIKU_IMAGE_SIZE = 800 ; 45 45 46 46 AddOptionalHaikuImagePackages Pe Nano Vision P7zip XZ-Utils ; 47 47 AddOptionalHaikuImagePackages Development Git OpenSSH OpenSSL ; -
headers/private/net/net_datalink.h
diff --git a/headers/private/net/net_datalink.h b/headers/private/net/net_datalink.h index 5d01473..59dbf5a 100644
a b struct net_datalink_module_info { 86 86 net_interface_address** _interfaceAddress); 87 87 88 88 net_interface* (*get_interface)(net_domain* domain, uint32 index); 89 net_interface* (*get_interface_by_name)(net_domain* domain, const char* ifname); 89 90 net_interface* (*get_interface_with_address)( 90 91 const struct sockaddr* address); 91 92 void (*put_interface)(net_interface* interface); 92 93 93 94 net_interface_address* (*get_interface_address)( 94 95 const struct sockaddr* address); 96 net_interface_address* (*get_interface_address_by_name)(const char* name, 97 net_domain* domain); 98 status_t (*set_interface_address)( 99 net_domain* _domain, struct ifaliasreq request); 95 100 bool (*get_next_interface_address)(net_interface* interface, 96 101 net_interface_address** _address); 97 102 void (*put_interface_address)(net_interface_address* address); -
headers/private/net/net_datalink_protocol.h
diff --git a/headers/private/net/net_datalink_protocol.h b/headers/private/net/net_datalink_protocol.h index 7df4d98..110123e 100644
a b 7 7 8 8 9 9 #include <net_buffer.h> 10 10 #define NET_DATA_LINK_INTERFACE_MODULE_NAME "network/stack/datalink/interface/v1" 11 11 12 12 13 typedef struct net_datalink_protocol { 13 14 struct net_datalink_protocol* next; -
headers/private/net/net_stack.h
diff --git a/headers/private/net/net_stack.h b/headers/private/net/net_stack.h index 1ec5e87..e626aad 100644
a b enum { 86 86 B_NET_FRAME_TYPE_IPV6 = 0x0002, 87 87 B_NET_FRAME_TYPE_IPX = 0x0003, 88 88 B_NET_FRAME_TYPE_APPLE_TALK = 0x0004, 89 B_NET_FRAME_TYPE_PPPOE_DISCOVERY = 0x0005, 90 B_NET_FRAME_TYPE_PPPOE = 0x0006, 89 91 90 92 B_NET_FRAME_TYPE_ALL = 0x0000 91 93 }; -
src/add-ons/kernel/network/Jamfile
diff --git a/src/add-ons/kernel/network/Jamfile b/src/add-ons/kernel/network/Jamfile index 7667873..5862dab 100644
a b SubInclude HAIKU_TOP src add-ons kernel network dns_resolver ; 6 6 SubInclude HAIKU_TOP src add-ons kernel network notifications ; 7 7 SubInclude HAIKU_TOP src add-ons kernel network protocols ; 8 8 SubInclude HAIKU_TOP src add-ons kernel network stack ; 9 SubInclude HAIKU_TOP src add-ons kernel network ppp ; -
src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp
diff --git a/src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp b/src/add-ons/kernel/network/datalink_protocols/ethernet_frame/ethernet_frame.cpp index a46b35d..eac51ad 100644
a b struct net_buffer_module_info* gBufferModule; 36 36 int32 37 37 ethernet_deframe(net_device* device, net_buffer* buffer) 38 38 { 39 //dprintf("asked to deframe buffer for device %s\n", device->name);40 41 39 NetBufferHeaderRemover<ether_header> bufferHeader(buffer); 42 40 if (bufferHeader.Status() != B_OK) 43 41 return bufferHeader.Status(); … … ethernet_deframe(net_device* device, net_buffer* buffer) 84 82 buffer->type = B_NET_FRAME_TYPE_IPX; 85 83 break; 86 84 85 case ETHER_TYPE_PPPOE_DISCOVERY: 86 buffer->type = B_NET_FRAME_TYPE(IFT_ETHER, type); 87 // buffer->type = B_NET_FRAME_PPPOE_DISCOVERY; 88 break; 89 90 case ETHER_TYPE_PPPOE: 91 buffer->type = B_NET_FRAME_TYPE(IFT_ETHER, type); 92 // buffer->type = B_NET_FRAME_PPPOE; 93 break; 94 87 95 default: 88 96 buffer->type = B_NET_FRAME_TYPE(IFT_ETHER, type); 89 97 break; -
src/add-ons/kernel/network/devices/ethernet/ethernet.cpp
diff --git a/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp b/src/add-ons/kernel/network/devices/ethernet/ethernet.cpp index 47c701e..a36d10f 100644
a b ethernet_link_checker(void *) 100 100 break; 101 101 102 102 // check link state of all existing devices 103 104 103 DoublyLinkedList<ethernet_device>::Iterator iterator 105 104 = sCheckList.GetIterator(); 106 105 while (iterator.HasNext()) { … … ethernet_receive_data(net_device *_device, net_buffer **_buffer) 342 341 343 342 err: 344 343 gBufferModule->free(buffer); 344 // should free the unused buffer 345 dprintf("%s::%s!!!!!!!!!!!!!!!!!!!!!!!!some severe fault!!!!!!!!!!!!!\n",__FILE__,__func__); 345 346 return status; 346 347 } 347 348 -
src/add-ons/kernel/network/ppp/Jamfile
diff --git a/src/add-ons/kernel/network/ppp/Jamfile b/src/add-ons/kernel/network/ppp/Jamfile index 2a05e24..650965d 100644
a b 1 1 SubDir HAIKU_TOP src add-ons kernel network ppp ; 2 2 3 3 SubInclude HAIKU_TOP src add-ons kernel network ppp ipcp ; 4 SubInclude HAIKU_TOP src add-ons kernel network ppp modem ;4 # SubInclude HAIKU_TOP src add-ons kernel network ppp modem ; 5 5 SubInclude HAIKU_TOP src add-ons kernel network ppp pap ; 6 6 SubInclude HAIKU_TOP src add-ons kernel network ppp pppoe ; 7 7 SubInclude HAIKU_TOP src add-ons kernel network ppp shared ; 8 SubInclude HAIKU_TOP src add-ons kernel network ppp ppp ; 9 SubInclude HAIKU_TOP src add-ons kernel network ppp ppp_frame ; 10 SubInclude HAIKU_TOP src add-ons kernel network ppp KPPPManager ; -
new file src/add-ons/kernel/network/ppp/KPPPManager/Jamfile
diff --git a/src/add-ons/kernel/network/ppp/KPPPManager/Jamfile b/src/add-ons/kernel/network/ppp/KPPPManager/Jamfile new file mode 100644 index 0000000..deb91e4
- + 1 SubDir HAIKU_TOP src add-ons kernel network ppp KPPPManager ; 2 3 SetSubDirSupportedPlatformsBeOSCompatible ; 4 5 if $(TARGET_PLATFORM) != haiku { 6 UseHeaders [ FStandardOSHeaders ] : true ; 7 # Needed for <support/Errors.h> and maybe other stuff. 8 UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ; 9 # We need the public network headers also when not compiling for Haiku. 10 # Unfortunately we get more than we want, namely all POSIX headers. 11 } 12 13 UsePrivateKernelHeaders ; 14 # UsePrivateHeaders net ; 15 16 UsePrivateHeaders kernel net ; 17 UsePrivateHeaders [ FDirName kernel ] ; 18 UsePrivateHeaders [ FDirName kernel util ] ; 19 20 UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared 21 libkernelppp headers ] : true ; 22 23 24 { 25 SubDirC++Flags -fno-rtti ; 26 } 27 28 29 KernelAddon KPPPManager : 30 KPPPManager.cpp 31 ; 32 33 LinkAgainst KPPPManager : libkernelppp.a ; 34 35 # Installation 36 HaikuInstall install-networking : /boot/home/config/add-ons/kernel/haiku_network/ppp 37 : KPPPManager ; 38 39 Package haiku-networkingkit-cvs : 40 haiku : 41 boot home config add-ons kernel haiku_network datalink_protocols ; 42 43 SEARCH on [ FGristFiles kernel_cpp.cpp ] 44 = [ FDirName $(HAIKU_TOP) src system kernel util ] ; -
new file src/add-ons/kernel/network/ppp/KPPPManager/KPPPManager.cpp
diff --git a/src/add-ons/kernel/network/ppp/KPPPManager/KPPPManager.cpp b/src/add-ons/kernel/network/ppp/KPPPManager/KPPPManager.cpp new file mode 100644 index 0000000..4712287
- + 1 /* 2 * Copyright 2006-2010, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 #include <net_stack.h> 10 #include <NetBufferUtilities.h> 11 12 #include <ByteOrder.h> 13 #include <KernelExport.h> 14 15 #include <lock.h> 16 #include <util/AutoLock.h> 17 #include <util/DoublyLinkedList.h> 18 19 #include <new> 20 #include <string.h> 21 22 #include <KPPPInterface.h> 23 #include <KPPPManager.h> 24 #include <ppp_device.h> 25 26 // #define TRACE(x) dprintf(x) 27 28 struct entry_private : ppp_interface_entry, DoublyLinkedListLinkImpl<entry_private> { 29 }; 30 31 static DoublyLinkedList<entry_private> sEntryList; 32 33 net_buffer_module_info* gBufferModule = NULL; 34 net_stack_module_info* gStackModule = NULL; 35 // static struct net_interface* sinterface; 36 static mutex sListLock; 37 static uint32 ppp_interface_count; 38 ppp_interface_entry entry[4]; 39 40 // #pragma mark - 41 42 static KPPPInterface * GetInterface(ppp_interface_id ID); 43 44 static ppp_interface_id 45 CreateInterface(const driver_settings *settings, ppp_interface_id parentID) 46 { 47 MutexLocker _(sListLock); // auto_lock 48 49 if (parentID>0){ 50 TRACE("Not support Multi_Link yet!\n"); 51 return 0l; 52 } 53 54 if (settings==NULL){ 55 TRACE("No driver_settings yet!\n"); 56 return 0l; 57 } 58 59 ppp_interface_count++; 60 61 if (GetInterface(ppp_interface_count) != NULL) 62 return 0l; 63 64 entry_private* pentry = new (std::nothrow) entry_private; 65 memset(pentry,0,sizeof(entry_private)); 66 pentry->accessing=ppp_interface_count; 67 sEntryList.Add(pentry); 68 69 KPPPInterface *device = new (std::nothrow) KPPPInterface(NULL, 70 pentry,ppp_interface_count,NULL,NULL); 71 72 if(device==NULL || pentry==NULL) { 73 TRACE("device or pentry is NULL\n"); 74 ppp_interface_count--; 75 return 0l; 76 } 77 78 TRACE("setting ppp_interface_count %ld\n",ppp_interface_count); 79 80 81 return ppp_interface_count; // only support 1 ppp connection right now 82 } 83 84 85 static ppp_interface_id 86 CreateInterfaceWithName(const char *name, ppp_interface_id parentID) 87 { 88 MutexLocker _(sListLock); // auto_lock 89 90 if (parentID>0){ 91 dprintf("Not support Multi_Link yet!\n"); 92 return(0); 93 } 94 95 if (!strncmp(name,"ppp1",4) || !strncmp(name,"ppp2",4) || !strncmp(name,"ppp3",4)){ 96 dprintf("create ppp fine: you are requesting %s!\n",name); 97 } else { 98 dprintf("only ppp1-3 support: you are requesting %s!\n",name); 99 return(0); 100 } 101 102 ppp_interface_count++; 103 if (GetInterface(ppp_interface_count) != NULL){ 104 TRACE("PPP Interface already exist!\n"); 105 return 0l; 106 } 107 108 entry_private* pentry = new (std::nothrow) entry_private; 109 memset(pentry,0,sizeof(entry_private)); 110 pentry->accessing=ppp_interface_count; 111 sEntryList.Add(pentry); 112 113 KPPPInterface* device = new (std::nothrow) KPPPInterface(name, 114 pentry,ppp_interface_count,NULL,NULL); 115 116 117 if(device==NULL || pentry==NULL) { 118 TRACE("can not create ppp interface!\n"); 119 ppp_interface_count--; 120 return 0l; 121 } else 122 TRACE("create ppp interface:%ld!\n", ppp_interface_count); 123 124 TRACE("setting ppp_interface_count %ld\n",ppp_interface_count); 125 126 return ppp_interface_count; 127 } 128 129 130 static bool 131 DeleteInterface(ppp_interface_id ID) 132 { 133 MutexLocker _(sListLock); // auto_lock 134 135 DoublyLinkedList<entry_private>::Iterator iterator 136 = sEntryList.GetIterator(); 137 while (iterator.HasNext()) { 138 entry_private* pentry = iterator.Next(); 139 if ((ppp_interface_id)pentry->accessing == ID){ 140 pentry->deleting=true; 141 return true; 142 } 143 } 144 145 return false; 146 } 147 148 149 static bool 150 RemoveInterface(ppp_interface_id ID) 151 { 152 MutexLocker _(sListLock); // auto_lock 153 if (ID <= 0 || ID > ppp_interface_count) 154 return false; 155 156 DoublyLinkedList<entry_private>::Iterator iterator 157 = sEntryList.GetIterator(); 158 while (iterator.HasNext()) { 159 entry_private* pentry = iterator.Next(); 160 if ((ppp_interface_id)pentry->accessing==ID){ 161 pentry->deleting=true; 162 break; 163 } 164 } 165 166 return false; 167 } 168 169 170 static net_device * 171 RegisterInterface(ppp_interface_id ID) 172 { 173 // MutexLocker _(sListLock); // auto_lock 174 175 entry_private* entry = NULL; 176 177 DoublyLinkedList<entry_private>::Iterator iterator 178 = sEntryList.GetIterator(); 179 while (iterator.HasNext()) { 180 entry_private* pentry = iterator.Next(); 181 if ((ppp_interface_id)pentry->accessing==ID){ 182 entry = pentry; 183 break; 184 } 185 } 186 187 if (entry == NULL) 188 return NULL; 189 190 ppp_device *device = new (std::nothrow) ppp_device; 191 if(device==NULL) 192 return NULL; 193 194 memset(device, 0, sizeof(ppp_device)); 195 device->KPPP_Interface = entry->interface; 196 197 return device; 198 } 199 200 201 static KPPPInterface * 202 GetInterface(ppp_interface_id ID) 203 { 204 // MutexLocker _(sListLock); // auto_lock 205 206 DoublyLinkedList<entry_private>::Iterator iterator 207 = sEntryList.GetIterator(); 208 while (iterator.HasNext()) { 209 entry_private* pentry = iterator.Next(); 210 TRACE("testing interface id:%ld\n",pentry->accessing); 211 if ((ppp_interface_id)(pentry->accessing)==ID){ 212 TRACE("get interface id:%ld\n",ID); 213 return pentry->interface; 214 } 215 } 216 217 TRACE("can not get interface id:%ld\n",ID); 218 219 return NULL; 220 221 } 222 223 224 static bool 225 UnregisterInterface(ppp_interface_id ID) 226 { 227 MutexLocker _(sListLock); // auto_lock 228 229 if(ID<=0 || ID>ppp_interface_count) 230 return false; 231 return true; 232 } 233 234 235 static status_t 236 ControlInterface(ppp_interface_id ID, uint32 op, void *data, size_t length) 237 { 238 MutexLocker _(sListLock); // auto_lock 239 240 if(ID<=0 || ID>ppp_interface_count) 241 return B_ERROR; 242 243 DoublyLinkedList<entry_private>::Iterator iterator 244 = sEntryList.GetIterator(); 245 while (iterator.HasNext()) { 246 entry_private* pentry = iterator.Next(); 247 if ((ppp_interface_id)pentry->accessing == ID) 248 return B_OK; 249 } 250 251 return B_ERROR; 252 } 253 254 255 static int32 256 GetInterfaces(ppp_interface_id *interfaces, int32 count, ppp_interface_filter filter) 257 { 258 MutexLocker _(sListLock); 259 260 if (count<=0 || count>(int32)ppp_interface_count) 261 return(0); 262 263 uint32 ppp_count = 0; 264 265 DoublyLinkedList<entry_private>::Iterator iterator 266 = sEntryList.GetIterator(); 267 while (iterator.HasNext()) { 268 entry_private* pentry = iterator.Next(); 269 interfaces[ppp_count] = pentry->accessing; 270 ppp_count++; 271 } 272 273 return(ppp_count); 274 } 275 276 277 static int32 278 CountInterfaces(ppp_interface_filter filter) 279 { 280 MutexLocker _(sListLock); // auto_lock 281 282 uint32 ppp_count = 0; 283 284 DoublyLinkedList<entry_private>::Iterator iterator 285 = sEntryList.GetIterator(); 286 while (iterator.HasNext()) { 287 // entry_private* pentry = 288 iterator.Next(); 289 ppp_count++; 290 } 291 292 return(ppp_count); 293 } 294 295 296 static void 297 EnableReports(ppp_report_type type, thread_id thread, int32 flags) 298 { 299 MutexLocker _(sListLock); // auto_lock 300 301 return; // need more portrait 302 } 303 304 305 static void 306 DisableReports(ppp_report_type type, thread_id thread) 307 { 308 MutexLocker _(sListLock); // auto_lock 309 310 return; // need more portrait 311 } 312 313 314 static bool 315 DoesReport(ppp_report_type type, thread_id thread) 316 { 317 MutexLocker _(sListLock); // auto_lock 318 319 return false; // need more portrait 320 } 321 322 323 324 static status_t 325 KPPPManager_std_ops(int32 op, ...) 326 { 327 switch (op) { 328 case B_MODULE_INIT: 329 mutex_init(&sListLock, "KPPPManager"); 330 new (&sEntryList) DoublyLinkedList<entry_private>; 331 // static C++ objects are not initialized in the module startup 332 ppp_interface_count = 0; 333 get_module(NET_STACK_MODULE_NAME, (module_info**)&gStackModule); 334 get_module(NET_BUFFER_MODULE_NAME, (module_info**)&gBufferModule); 335 return B_OK; 336 337 case B_MODULE_UNINIT: 338 mutex_destroy(&sListLock); 339 340 put_module(NET_BUFFER_MODULE_NAME); 341 put_module(NET_STACK_MODULE_NAME); 342 return B_OK; 343 344 default: 345 return B_ERROR; 346 } 347 } 348 349 350 static ppp_interface_module_info sKPPPManagerModule = { 351 { 352 PPP_INTERFACE_MODULE_NAME, 353 0, 354 KPPPManager_std_ops 355 }, 356 CreateInterface, 357 CreateInterfaceWithName, 358 DeleteInterface, 359 RemoveInterface, 360 RegisterInterface, 361 GetInterface, 362 UnregisterInterface, 363 ControlInterface, 364 GetInterfaces, 365 CountInterfaces, 366 EnableReports, 367 DisableReports, 368 DoesReport 369 }; 370 371 372 module_info* modules[] = { 373 (module_info*)&sKPPPManagerModule, 374 NULL 375 }; -
src/add-ons/kernel/network/ppp/ipcp/Jamfile
diff --git a/src/add-ons/kernel/network/ppp/ipcp/Jamfile b/src/add-ons/kernel/network/ppp/ipcp/Jamfile index 9e304f0..fc1ad7e 100644
a b SubDir HAIKU_TOP src add-ons kernel network ppp ipcp ; 3 3 SetSubDirSupportedPlatformsBeOSCompatible ; 4 4 5 5 if $(TARGET_PLATFORM) != haiku { 6 UseHeaders [ FStandardOSHeaders ] : true ; 7 # Needed for the atomic_add64() prototype. :-/ 6 8 UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ; 7 9 # We need the public network headers also when not compiling for Haiku. 8 10 # Unfortunately we get more than we want, namely all POSIX headers. 9 11 } 10 12 11 13 # for kernel_cpp.h and BLocker 12 UseHeaders [ FDirName $(HAIKU_TOP) headers cpp ] : true ; 14 # UseHeaders [ FDirName $(HAIKU_TOP) headers cpp ] : true ; 15 # UseHeaders [ FDirName $(HAIKU_TOP) headers kernel shared ] : true ; 16 UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ; 17 # for linking inet_addr function 18 19 # UsePrivateHeaders shared ; 20 UsePrivateKernelHeaders ; 13 21 UsePrivateHeaders net ; 22 23 UsePrivateHeaders libroot net ; 14 24 UsePrivateHeaders [ FDirName kernel ] ; 15 25 UsePrivateHeaders [ FDirName kernel util ] ; 16 26 UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared … … UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared 23 33 24 34 25 35 KernelAddon ipcp : 36 atomic.S 37 kernel_cpp.cpp 38 26 39 # imported from libnet 27 40 inet_addr.c 28 41 … … KernelAddon ipcp : 30 43 Protocol.cpp 31 44 ; 32 45 46 SEARCH on [ FGristFiles bitypes.h ] 47 = [ FDirName $(HAIKU_TOP) src kits network libbind include sys ] ; 48 49 SEARCH on [ FGristFiles port_before.h ] 50 = [ FDirName $(HAIKU_TOP) src kits network libbind ] ; 51 52 SEARCH on [ FGristFiles port_after.h ] 53 = [ FDirName $(HAIKU_TOP) src kits network libbind ] ; 54 55 SEARCH on [ FGristFiles config.h ] 56 = [ FDirName $(HAIKU_TOP) src kits network libbind ] ; 57 33 58 SEARCH on [ FGristFiles inet_addr.c ] 34 = [ FDirName $(HAIKU_TOP) src kits network compat libnet ] ; 59 = [ FDirName $(HAIKU_TOP) src kits network libbind inet ] ; 60 61 SEARCH on [ FGristFiles kernel_cpp.cpp ] 62 = [ FDirName $(HAIKU_TOP) src system kernel util ] ; 63 SEARCH on [ FGristFiles atomic.S ] 64 = [ FDirName $(HAIKU_TOP) src system libroot os arch $(TARGET_ARCH) ] ; 35 65 36 66 LinkAgainst ipcp : libkernelppp.a ; 37 67 38 68 # Installation 39 69 HaikuInstall install-networking 40 : /boot/home/config/add-ons/kernel/ obos_network/ppp70 : /boot/home/config/add-ons/kernel/haiku_network/ppp 41 71 : ipcp ; 42 72 43 73 Package haiku-networkingkit-cvs : 44 74 ipcp : 45 boot home config add-ons kernel obos_network ppp ;75 boot home config add-ons kernel haiku_network ppp ; -
src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp
diff --git a/src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp b/src/add-ons/kernel/network/ppp/ipcp/Protocol.cpp index 7105440..b8914e0 100644
a b 14 14 #include <settings_tools.h> 15 15 16 16 #include <cstring> 17 #include <netinet/in_var.h> 18 #include <core_funcs.h> 17 18 #include <net/route.h> // for route_entry 19 #include <arpa/inet.h> // for inet_addr 20 #include <net_stack.h> 21 #include <net_buffer.h> 19 22 #include <sys/sockio.h> 20 23 24 extern net_buffer_module_info *gBufferModule; 25 static net_datalink_protocol_module_info *sDatalinkInterfaceProtocolModule; 26 static struct net_datalink_module_info *sDatalinkModule; 27 static struct net_stack_module_info *sStackModule; 21 28 22 29 #if DEBUG 23 30 #include <unistd.h> … … static int sFD; 26 33 // the file descriptor for debug output 27 34 static char sDigits[] = "0123456789ABCDEF"; 28 35 void 29 dump_packet( struct mbuf*packet, const char *direction)36 dump_packet(net_buffer *packet, const char *direction) 30 37 { 31 38 if(!packet) 32 39 return; 33 40 34 41 uint8 *data = mtod(packet, uint8*); 35 42 uint8 buffer[128]; 36 43 uint8 bufferIndex = 0; 37 44 38 45 sprintf((char*) buffer, "Dumping %s packet;len=%ld;pkthdr.len=%d\n", direction, 39 46 packet->m_len, packet->m_flags & M_PKTHDR ? packet->m_pkthdr.len : -1); 40 47 write(sFD, buffer, strlen((char*) buffer)); 41 48 42 49 for(uint32 index = 0; index < packet->m_len; index++) { 43 50 buffer[bufferIndex++] = sDigits[data[index] >> 4]; 44 51 buffer[bufferIndex++] = sDigits[data[index] & 0x0F]; … … IPCP::IPCP(KPPPInterface& interface, driver_parameter *settings) 75 82 // reset configurations 76 83 memset(&fLocalConfiguration, 0, sizeof(ipcp_configuration)); 77 84 memset(&fPeerConfiguration, 0, sizeof(ipcp_configuration)); 78 85 79 86 // reset requests 80 87 memset(&fLocalRequests, 0, sizeof(ipcp_requests)); 81 88 memset(&fPeerRequests, 0, sizeof(ipcp_requests)); 82 89 83 90 // Parse settings: 84 91 // "Local" and "Peer" describe each side's settings 85 92 ParseSideRequests(get_parameter_with_name(IPCP_LOCAL_SIDE_KEY, Settings()), 86 93 PPP_LOCAL_SIDE); 87 94 ParseSideRequests(get_parameter_with_name(IPCP_PEER_SIDE_KEY, Settings()), 88 95 PPP_PEER_SIDE); 89 96 97 get_module(NET_DATALINK_MODULE_NAME, (module_info **)&sDatalinkModule); 98 get_module(NET_STACK_MODULE_NAME, (module_info **)&sStackModule); 99 get_module(NET_DATA_LINK_INTERFACE_MODULE_NAME, (module_info **)&sDatalinkInterfaceProtocolModule); 90 100 #if DEBUG 91 101 sFD = open("/boot/home/ipcpdebug", O_WRONLY | O_CREAT | O_TRUNC); 92 102 #endif … … IPCP::IPCP(KPPPInterface& interface, driver_parameter *settings) 95 105 96 106 IPCP::~IPCP() 97 107 { 108 109 put_module(NET_DATALINK_MODULE_NAME); 110 put_module(NET_STACK_MODULE_NAME); 111 put_module(NET_DATA_LINK_INTERFACE_MODULE_NAME); 98 112 #if DEBUG 99 113 close(sFD); 100 114 #endif … … status_t 112 126 IPCP::StackControl(uint32 op, void *data) 113 127 { 114 128 TRACE("IPCP: StackControl(op=%ld)\n", op); 115 129 116 130 // TODO: 117 131 // check values 118 132 119 133 switch(op) { 120 134 case SIOCSIFADDR: 121 135 break; 122 136 123 137 case SIOCSIFFLAGS: 124 138 break; 125 139 126 140 case SIOCSIFDSTADDR: 127 141 break; 128 142 129 143 case SIOCSIFNETMASK: 130 144 break; 131 145 132 146 default: 133 147 ERROR("IPCP: Unknown ioctl: %ld\n", op); 134 148 return KPPPProtocol::StackControl(op, data); 135 149 } 136 150 137 151 return B_OK; 138 152 } 139 153 … … bool 142 156 IPCP::Up() 143 157 { 144 158 TRACE("IPCP: Up() state=%d\n", State()); 145 159 146 160 // Servers do not send a configure-request when Up() is called. They wait until 147 161 // the client requests this protocol. 148 162 if(Interface().Mode() == PPP_SERVER_MODE) 149 163 return true; 150 164 151 165 switch(State()) { 152 166 case PPP_INITIAL_STATE: 153 167 NewState(PPP_REQ_SENT_STATE); 154 168 InitializeRestartCount(); 155 169 SendConfigureRequest(); 156 170 break; 157 171 158 172 default: 159 173 ; 160 174 } 161 175 162 176 return true; 163 177 } 164 178 … … bool 167 181 IPCP::Down() 168 182 { 169 183 TRACE("IPCP: Down() state=%d\n", State()); 170 184 171 185 switch(Interface().Phase()) { 172 186 case PPP_DOWN_PHASE: 173 187 // interface finished terminating … … IPCP::Down() 175 189 ReportDownEvent(); 176 190 // this will also reset and update addresses 177 191 break; 178 192 179 193 /* case PPP_TERMINATION_PHASE: 180 194 // interface is terminating 181 195 break; 182 196 183 197 case PPP_ESTABLISHMENT_PHASE: 184 198 // interface is reconfiguring 185 199 break; 186 */ 200 */ 187 201 case PPP_ESTABLISHED_PHASE: 188 202 // terminate this NCP individually (block until we finished terminating) 189 203 if(State() != PPP_INITIAL_STATE && State() != PPP_CLOSING_STATE) { … … IPCP::Down() 191 205 InitializeRestartCount(); 192 206 SendTerminateRequest(); 193 207 } 194 208 195 209 while(State() == PPP_CLOSING_STATE) 196 210 snooze(50000); 197 211 break; 198 212 199 213 default: 200 214 ; 201 215 } 202 216 203 217 return true; 204 218 } 205 219 206 220 207 221 status_t 208 IPCP::Send( struct mbuf*packet, uint16 protocolNumber)222 IPCP::Send(net_buffer *packet, uint16 protocolNumber) 209 223 { 210 224 TRACE("IPCP: Send(0x%X)\n", protocolNumber); 211 225 212 226 if((protocolNumber == IP_PROTOCOL && State() == PPP_OPENED_STATE) 213 227 || protocolNumber == IPCP_PROTOCOL) { 214 228 #if DEBUG … … IPCP::Send(struct mbuf *packet, uint16 protocolNumber) 217 231 Interface().UpdateIdleSince(); 218 232 return SendToNext(packet, protocolNumber); 219 233 } 220 234 221 235 ERROR("IPCP: Send() failed because of wrong state or protocol number!\n"); 222 223 m_freem(packet);236 237 gBufferModule->free(packet); 224 238 return B_ERROR; 225 239 } 226 240 227 241 228 242 status_t 229 IPCP::Receive( struct mbuf*packet, uint16 protocolNumber)243 IPCP::Receive(net_buffer *packet, uint16 protocolNumber) 230 244 { 231 245 TRACE("IPCP: Receive(0x%X)\n", protocolNumber); 232 246 233 247 if(!packet) 234 248 return B_ERROR; 235 249 236 250 if(protocolNumber == IP_PROTOCOL) 237 251 return ReceiveIPPacket(packet, protocolNumber); 238 252 239 253 if(protocolNumber != IPCP_PROTOCOL) 240 254 return PPP_UNHANDLED; 241 242 ppp_lcp_packet *data = mtod(packet, ppp_lcp_packet*); 243 244 // remove padding 245 int32 length = packet->m_len; 246 if(packet->m_flags & M_PKTHDR) 247 length = packet->m_pkthdr.len; 248 length -= ntohs(data->length); 249 if(length) 250 m_adj(packet, -length); 251 252 if(ntohs(data->length) < 4) 255 256 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 257 if(bufferheader.Status()!=B_OK) 253 258 return B_ERROR; 254 259 ppp_lcp_packet &data = bufferheader.Data(); 260 261 // // remove padding 262 // int32 length = packet->m_len; 263 // if(packet->m_flags & M_PKTHDR) 264 // length = packet->m_pkthdr.len; 265 // length -= ntohs(data.length); 266 // if(length) 267 // m_adj(packet, -length); 268 269 if(ntohs(data.length) < 4) 270 return B_ERROR; 271 255 272 // packet is freed by event methods 256 switch(data ->code) {273 switch(data.code) { 257 274 case PPP_CONFIGURE_REQUEST: 258 275 RCREvent(packet); 259 276 break; 260 277 261 278 case PPP_CONFIGURE_ACK: 262 279 RCAEvent(packet); 263 280 break; 264 281 265 282 case PPP_CONFIGURE_NAK: 266 283 case PPP_CONFIGURE_REJECT: 267 284 RCNEvent(packet); 268 285 break; 269 286 270 287 case PPP_TERMINATE_REQUEST: 271 288 RTREvent(packet); 272 289 break; 273 290 274 291 case PPP_TERMINATE_ACK: 275 292 RTAEvent(packet); 276 293 break; 277 294 278 295 case PPP_CODE_REJECT: 279 296 RXJBadEvent(packet); 280 297 // we implemented the minimum requirements 281 298 break; 282 299 283 300 default: 284 301 RUCEvent(packet); 285 302 return PPP_REJECTED; 286 303 } 287 304 288 305 return B_OK; 289 306 } 290 307 291 308 292 309 status_t 293 IPCP::ReceiveIPPacket( struct mbuf*packet, uint16 protocolNumber)310 IPCP::ReceiveIPPacket(net_buffer *packet, uint16 protocolNumber) 294 311 { 295 312 if(protocolNumber != IP_PROTOCOL || State() != PPP_OPENED_STATE) 296 313 return PPP_UNHANDLED; 297 314 298 315 // TODO: add VJC support (the packet would be decoded here) 299 300 if (gProto[IPPROTO_IP] && gProto[IPPROTO_IP]->pr_input) { 316 317 if (packet) // gProto[IPPROTO_IP] && gProto[IPPROTO_IP]->pr_input) 318 { 301 319 #if DEBUG 302 320 dump_packet(packet, "incoming"); 303 321 #endif 304 322 Interface().UpdateIdleSince(); 305 gProto[IPPROTO_IP]->pr_input(packet, 0); 323 // gProto[IPPROTO_IP]->pr_input(packet, 0); 324 TRACE("We got 1 IP packet from %s::%s\n", __FILE__, __func__); 325 gBufferModule->free(packet); 306 326 return B_OK; 307 327 } else { 308 328 ERROR("IPCP: Error: Could not find input function for IP!\n"); 309 m_freem(packet);329 gBufferModule->free(packet); 310 330 return B_ERROR; 311 331 } 312 332 } … … IPCP::Pulse() 318 338 if(fNextTimeout == 0 || fNextTimeout > system_time()) 319 339 return; 320 340 fNextTimeout = 0; 321 341 322 342 switch(State()) { 323 343 case PPP_CLOSING_STATE: 324 344 if(fTerminateCounter <= 0) … … IPCP::Pulse() 326 346 else 327 347 TOGoodEvent(); 328 348 break; 329 349 330 350 case PPP_REQ_SENT_STATE: 331 351 case PPP_ACK_RCVD_STATE: 332 352 case PPP_ACK_SENT_STATE: … … IPCP::Pulse() 335 355 else 336 356 TOGoodEvent(); 337 357 break; 338 358 339 359 default: 340 360 ; 341 361 } … … IPCP::ParseSideRequests(const driver_parameter *requests, ppp_side side) 347 367 { 348 368 if(!requests) 349 369 return false; 350 370 351 371 ipcp_requests *selectedRequests; 352 372 353 373 if(side == PPP_LOCAL_SIDE) { 354 374 selectedRequests = &fLocalRequests; 355 375 fRequestPrimaryDNS = fRequestSecondaryDNS = false; 356 376 } else 357 377 selectedRequests = &fPeerRequests; 358 378 359 379 memset(selectedRequests, 0, sizeof(ipcp_requests)); 360 380 // reset current requests 361 381 362 382 // The following values are allowed: 363 383 // "Address" the ip address that will be suggested 364 384 // "Netmask" the netmask that should be used 365 385 // "PrimaryDNS" primary DNS server 366 386 // "SecondaryDNS" secondary DNS server 367 387 // Setting any value to 0.0.0.0 or "auto" means it should be chosen automatically. 368 388 369 389 in_addr_t address = INADDR_ANY; 370 390 for(int32 index = 0; index < requests->parameter_count; index++) { 371 391 if(requests->parameters[index].value_count == 0) 372 392 continue; 373 393 374 394 // all values are IP addresses, so parse the address here 375 395 if(strcasecmp(requests->parameters[index].values[0], "auto")) { 376 396 address = inet_addr(requests->parameters[index].values[0]); 397 // address = INADDR_ANY; 377 398 if(address == INADDR_NONE) 378 399 continue; 379 400 } 380 401 381 402 if(!strcasecmp(requests->parameters[index].name, IPCP_IP_ADDRESS_KEY)) 382 403 selectedRequests->address = address; 383 404 else if(!strcasecmp(requests->parameters[index].name, IPCP_NETMASK_KEY)) … … IPCP::ParseSideRequests(const driver_parameter *requests, ppp_side side) 393 414 fRequestSecondaryDNS = true; 394 415 } 395 416 } 396 417 397 418 return true; 398 419 } 399 420 … … IPCP::ParseSideRequests(const driver_parameter *requests, ppp_side side) 401 422 void 402 423 IPCP::UpdateAddresses() 403 424 { 425 TRACE("%s::%s: entering UpdateAddresses\n",__FILE__,__func__); 404 426 RemoveRoutes(); 405 427 406 428 if(State() != PPP_OPENED_STATE && !Interface().DoesConnectOnDemand()) 407 429 return; 408 409 struct in_aliasreq inreq; 410 struct ifreq ifreqAddress, ifreqDestination; 411 memset(&inreq, 0, sizeof(struct in_aliasreq)); 412 memset(&ifreqAddress, 0, sizeof(struct ifreq)); 413 memset(&ifreqDestination, 0, sizeof(struct ifreq)); 414 memset(&fGateway, 0, sizeof(struct sockaddr_in)); 415 430 431 struct sockaddr newAddr = {6, AF_INET, {0x00,0x00,0x00,0x00,0x00,0x0}}; 432 // newAddr.sa_len=8; newAddr.sa_family=AF_INET; newAddr.sa_data 433 416 434 // create local address 417 inreq.ifra_addr.sin_family = AF_INET;418 435 if(fLocalRequests.address != INADDR_ANY) 419 inreq.ifra_addr.sin_addr.s_addr = fLocalRequests.address; 420 else if(fLocalConfiguration.address == INADDR_ANY) 421 inreq.ifra_addr.sin_addr.s_addr = 0x010F0F0F; // was: INADDR_BROADCAST 422 else 423 inreq.ifra_addr.sin_addr.s_addr = fLocalConfiguration.address; 424 inreq.ifra_addr.sin_len = sizeof(struct sockaddr_in); 425 memcpy(&ifreqAddress.ifr_addr, &inreq.ifra_addr, sizeof(struct sockaddr_in)); 426 427 // create destination address 428 fGateway.sin_family = AF_INET; 429 if(fPeerRequests.address != INADDR_ANY) 430 fGateway.sin_addr.s_addr = fPeerRequests.address; 431 else if(fPeerConfiguration.address == INADDR_ANY) 432 fGateway.sin_addr.s_addr = 0x020F0F0F; // was: INADDR_BROADCAST 433 else 434 fGateway.sin_addr.s_addr = fPeerConfiguration.address; 435 fGateway.sin_len = sizeof(struct sockaddr_in); 436 memcpy(&inreq.ifra_dstaddr, &fGateway, 437 sizeof(struct sockaddr_in)); 438 memcpy(&ifreqDestination.ifr_dstaddr, &inreq.ifra_dstaddr, 439 sizeof(struct sockaddr_in)); 440 441 // create netmask 442 inreq.ifra_mask.sin_family = AF_INET; 443 inreq.ifra_mask.sin_addr.s_addr = fLocalRequests.netmask; 444 inreq.ifra_mask.sin_len = sizeof(struct sockaddr_in); 445 446 // tell stack to use these values 447 if(in_control(NULL, SIOCAIFADDR, (caddr_t) &inreq, 448 Interface().Ifnet()) != B_OK) 449 ERROR("IPCP: UpdateAddress(): SIOCAIFADDR returned error!\n"); 450 if(in_control(NULL, SIOCSIFADDR, (caddr_t) &ifreqAddress, 451 Interface().Ifnet()) != B_OK) 452 ERROR("IPCP: UpdateAddress(): SIOCSIFADDR returned error!\n"); 453 if(in_control(NULL, SIOCSIFDSTADDR, (caddr_t) &ifreqDestination, 454 Interface().Ifnet()) != B_OK) 455 ERROR("IPCP: UpdateAddress(): SIOCSIFDSTADDR returned error!\n"); 456 memcpy(&inreq.ifra_addr, &inreq.ifra_mask, sizeof(struct sockaddr_in)); 457 // SIOCISFNETMASK wants the netmask to be in ifra_addr 458 if(in_control(NULL, SIOCSIFNETMASK, (caddr_t) &inreq, 459 Interface().Ifnet()) != B_OK) 460 ERROR("IPCP: UpdateAddress(): SIOCSIFNETMASK returned error!\n"); 461 436 memcpy(newAddr.sa_data+2, &fLocalRequests.address, sizeof(in_addr_t)); 437 else if(fLocalConfiguration.address == INADDR_ANY) { 438 in_addr_t inaddr_broadcast = 0x010F0F0F; // was: INADDR_BROADCAST 439 memcpy(newAddr.sa_data+2, &inaddr_broadcast, sizeof(in_addr_t)); 440 } else 441 memcpy(newAddr.sa_data+2, &fLocalConfiguration.address, sizeof(in_addr_t)); 442 443 TRACE("%s::%s: entering ChangeAddress\n",__FILE__,__func__); 444 if (sDatalinkInterfaceProtocolModule == NULL || sDatalinkModule == NULL) { 445 TRACE("%s::%s: some module not found!\n",__FILE__,__func__); 446 return; 447 } 448 449 net_domain* nd = sStackModule->get_domain(AF_INET); 450 net_interface_address* ppp_interface_address = sDatalinkModule->get_interface_address_by_name(Interface().Name(), nd); 451 if (ppp_interface_address != NULL){ 452 TRACE("%s::%s: ppp_interface_address found\n",__FILE__,__func__); 453 sDatalinkInterfaceProtocolModule->change_address(NULL, ppp_interface_address, SIOCSIFADDR, ppp_interface_address->local, &newAddr); 454 // sDatalinkModule->put_interface_address(ppp_interface_address); 455 } else 456 dprintf("%s::%s: ppp_interface_address not found\n",__FILE__,__func__); 457 458 /* 459 struct ifaliasreq inreq; 460 memset(&inreq, 0, sizeof(struct ifaliasreq)); 461 memcpy(inreq.ifra_name, Interface().Name(), IF_NAMESIZE); 462 463 struct sockaddr_in netmask; 464 memset(&netmask, 0, sizeof(struct sockaddr_in)); 465 netmask.sin_family = AF_INET; 466 netmask.sin_addr.s_addr = fLocalRequests.netmask; 467 netmask.sin_len = sizeof(struct sockaddr_in); 468 memcpy(&inreq.ifra_mask, &netmask, sizeof(struct sockaddr_in)); 469 470 struct sockaddr_in addr; 471 memset(&addr, 0, sizeof(struct sockaddr_in)); 472 addr.sin_family = AF_INET; 473 addr.sin_addr.s_addr = fLocalRequests.address; 474 addr.sin_len = sizeof(struct sockaddr_in); 475 memcpy(&inreq.ifra_addr, &addr, sizeof(struct sockaddr_in)); 476 477 struct sockaddr_in broadaddr; 478 memset(&broadaddr, 0, sizeof(struct sockaddr_in)); 479 broadaddr.sin_family = AF_INET; 480 broadaddr.sin_addr.s_addr = fLocalRequests.address | (~fLocalRequests.netmask); 481 broadaddr.sin_len = sizeof(struct sockaddr_in); 482 memcpy(&inreq.ifra_addr, &broadaddr, sizeof(struct sockaddr_in)); 483 484 //status_t status = sDatalinkModule->set_interface_address(nd, inreq); 485 status_t status = B_OK; 486 if (status != B_OK){ 487 dprintf("%s:%s: sDatalinkModule->set_interface_address\n", __FILE__, __func__); 488 return; 489 } 490 // dprintf("%s:%s: add interface address fine\n", __FILE__, __func__); 491 */ 492 493 // struct in_aliasreq inreq; 494 // struct ifreq ifreqAddress, ifreqDestination; 495 // memset(&inreq, 0, sizeof(struct in_aliasreq)); 496 // memset(&ifreqAddress, 0, sizeof(struct ifreq)); 497 // memset(&ifreqDestination, 0, sizeof(struct ifreq)); 498 // memset(&fGateway, 0, sizeof(struct sockaddr_in)); 499 500 // // create netmask 501 // inreq.ifra_mask.sin_family = AF_INET; 502 // inreq.ifra_mask.sin_addr.s_addr = fLocalRequests.netmask; 503 // inreq.ifra_mask.sin_len = sizeof(struct sockaddr_in); 504 // 505 // tell stack to use these values 506 // if(in_control(NULL, SIOCAIFADDR, (caddr_t) &inreq, 507 // Interface().Ifnet()) != B_OK) 508 // ERROR("IPCP: UpdateAddress(): SIOCAIFADDR returned error!\n"); 509 // if(in_control(NULL, SIOCSIFADDR, (caddr_t) &ifreqAddress, 510 // Interface().Ifnet()) != B_OK) 511 // ERROR("IPCP: UpdateAddress(): SIOCSIFADDR returned error!\n"); 512 // if(in_control(NULL, SIOCSIFDSTADDR, (caddr_t) &ifreqDestination, 513 // Interface().Ifnet()) != B_OK) 514 // ERROR("IPCP: UpdateAddress(): SIOCSIFDSTADDR returned error!\n"); 515 // memcpy(&inreq.ifra_addr, &inreq.ifra_mask, sizeof(struct sockaddr_in)); 516 // SIOCISFNETMASK wants the netmask to be in ifra_addr 517 // if(in_control(NULL, SIOCSIFNETMASK, (caddr_t) &inreq, 518 // Interface().Ifnet()) != B_OK) 519 // ERROR("IPCP: UpdateAddress(): SIOCSIFNETMASK returned error!\n"); 520 462 521 // add default/subnet route 463 522 if(Side() == PPP_LOCAL_SIDE) { 464 if(rtrequest(RTM_ADD, (struct sockaddr*) &inreq.ifra_mask, 465 (struct sockaddr*) &fGateway, (struct sockaddr*) &inreq.ifra_mask, 466 RTF_UP | RTF_GATEWAY, &fDefaultRoute) != B_OK) 467 ERROR("IPCP: UpdateAddress(): could not add default/subnet route!\n"); 468 469 --fDefaultRoute->rt_refcnt; 523 // struct sockaddr ethaddr = { 8, AF_INET, {0x00,0x00,0x0a,0x00,0x00,0x00} }; 524 struct sockaddr gw_addr = { 8, AF_INET, {0x00,0x00,0x00,0x00,0x00,0x00} }; 525 // ethaddr.sa_len=4; ethaddr.sa_family = AF_INET; ethaddr.sa_data={0x85,0xBE,0x00,0x00}; 526 527 // create destination address 528 if(fPeerRequests.address != INADDR_ANY) 529 memcpy(gw_addr.sa_data+2, &fPeerRequests.address, sizeof(in_addr_t)); 530 else if(fPeerConfiguration.address == INADDR_ANY) { 531 in_addr_t gateway = 0x020F0F0F; 532 memcpy(gw_addr.sa_data+2, &gateway, sizeof(in_addr_t)); 533 // was: INADDR_BROADCAST 534 } else 535 memcpy(gw_addr.sa_data+2,&fPeerConfiguration.address,sizeof(in_addr_t)); 536 537 // net_domain* nd = sStackModule->get_domain(AF_INET); 538 // net_route* rt = sDatalinkModule->get_route(nd, ðaddr); 539 net_route dft_rt; 540 541 dft_rt.destination = NULL; 542 dft_rt.mask = NULL; 543 dft_rt.gateway = &gw_addr; 544 dft_rt.flags= RTF_DEFAULT | RTF_GATEWAY; 545 dft_rt.interface_address = ppp_interface_address;//rt->interface_address; 546 547 status_t st = sDatalinkModule->add_route(nd, &dft_rt); 548 549 if(st==B_OK) 550 dprintf("%s::%s: add route default OK!\n",__FILE__,__func__); 551 else 552 dprintf("%s::%s: add route default Fail!\n",__FILE__,__func__); 553 554 // if(rtrequest(RTM_ADD, (struct sockaddr*) &inreq.ifra_mask, 555 // (struct sockaddr*) &fGateway, (struct sockaddr*) &inreq.ifra_mask, 556 // RTF_UP | RTF_GATEWAY, &fDefaultRoute) != B_OK) 557 // ERROR("IPCP: UpdateAddress(): could not add default/subnet route!\n"); 558 559 // --fDefaultRoute->rt_refcnt; 470 560 } 471 561 } 472 562 … … void 475 565 IPCP::RemoveRoutes() 476 566 { 477 567 // note: netstack creates and deletes destination route automatically 478 568 dprintf("%s::%s: entering RemoveRoutes!\n",__FILE__,__func__); 569 570 struct sockaddr ethaddr = { 8, AF_INET, {0x00,0x00,0x85,0xBD,0x00,0x00} }; 571 // ethaddr.sa_len = 4; ethaddr.sa_family = AF_INET; ethaddr.sa_data = {0x85,0xBE,0x00,0x00}; 572 573 net_domain* nd = sStackModule->get_domain(AF_INET); 574 net_route* rt = sDatalinkModule->get_route(nd, ðaddr); 575 576 if(rt == NULL) { 577 dprintf("%s::%s: can not get route 133.189.0.0\n",__FILE__,__func__); 578 } else { 579 dprintf("get route 133.189.0.0!\n"); 580 status_t st = sDatalinkModule->remove_route(nd, rt); 581 if(st==B_OK) 582 dprintf("%s::%s: remove route 133.189.0.0 OK!\n",__FILE__,__func__); 583 else 584 dprintf("%s::%s: remove route 133.189.0.0 Fail!\n",__FILE__,__func__); 585 } 586 479 587 if(fDefaultRoute) { 480 588 struct sockaddr_in netmask; 481 589 memset(&netmask, 0, sizeof(struct sockaddr_in)); 482 590 483 591 netmask.sin_family = AF_INET; 484 592 netmask.sin_addr.s_addr = fLocalRequests.netmask; 485 593 netmask.sin_len = sizeof(struct sockaddr_in); 486 487 if(rtrequest(RTM_DELETE, (struct sockaddr*) &netmask,488 (struct sockaddr*) &fGateway, (struct sockaddr*) &netmask,489 RTF_UP | RTF_GATEWAY, &fDefaultRoute) != B_OK)594 595 // if(rtrequest(RTM_DELETE, (struct sockaddr*) &netmask, 596 // (struct sockaddr*) &fGateway, (struct sockaddr*) &netmask, 597 // RTF_UP | RTF_GATEWAY, &fDefaultRoute) != B_OK) 490 598 ERROR("IPCP: RemoveRoutes(): could not remove default/subnet route!\n"); 491 599 492 600 fDefaultRoute = NULL; 493 601 } 494 602 } … … void 505 613 IPCP::NewState(ppp_state next) 506 614 { 507 615 TRACE("IPCP: NewState(%d) state=%d\n", next, State()); 508 616 509 617 // report state changes 510 618 if(State() == PPP_INITIAL_STATE && next != State()) 511 619 UpStarted(); 512 620 else if(State() == PPP_OPENED_STATE && next != State()) 513 621 DownStarted(); 514 622 515 623 // maybe we do not need the timer anymore 516 624 if(next < PPP_CLOSING_STATE || next == PPP_OPENED_STATE) 517 625 fNextTimeout = 0; 518 626 519 627 fState = next; 520 628 } 521 629 … … IPCP::TOGoodEvent() 526 634 #if DEBUG 527 635 printf("IPCP: TOGoodEvent() state=%d\n", State()); 528 636 #endif 529 637 530 638 switch(State()) { 531 639 case PPP_CLOSING_STATE: 532 640 SendTerminateRequest(); 533 641 break; 534 642 535 643 case PPP_ACK_RCVD_STATE: 536 644 NewState(PPP_REQ_SENT_STATE); 537 645 538 646 case PPP_REQ_SENT_STATE: 539 647 case PPP_ACK_SENT_STATE: 540 648 SendConfigureRequest(); 541 649 break; 542 650 543 651 default: 544 652 IllegalEvent(PPP_TO_GOOD_EVENT); 545 653 } … … void 550 658 IPCP::TOBadEvent() 551 659 { 552 660 TRACE("IPCP: TOBadEvent() state=%d\n", State()); 553 661 554 662 switch(State()) { 555 663 case PPP_CLOSING_STATE: 556 664 NewState(PPP_INITIAL_STATE); 557 665 ReportDownEvent(); 558 666 break; 559 667 560 668 case PPP_REQ_SENT_STATE: 561 669 case PPP_ACK_RCVD_STATE: 562 670 case PPP_ACK_SENT_STATE: 563 671 NewState(PPP_INITIAL_STATE); 564 672 ReportUpFailedEvent(); 565 673 break; 566 674 567 675 default: 568 676 IllegalEvent(PPP_TO_BAD_EVENT); 569 677 } … … IPCP::TOBadEvent() 571 679 572 680 573 681 void 574 IPCP::RCREvent( struct mbuf*packet)682 IPCP::RCREvent(net_buffer *packet) 575 683 { 576 684 TRACE("IPCP: RCREvent() state=%d\n", State()); 577 685 578 686 KPPPConfigurePacket request(packet); 579 687 KPPPConfigurePacket nak(PPP_CONFIGURE_NAK); 580 688 KPPPConfigurePacket reject(PPP_CONFIGURE_REJECT); 581 689 690 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 691 if(bufferheader.Status()!=B_OK) 692 return; 693 ppp_lcp_packet &lcp_hdr = bufferheader.Data(); 694 582 695 // we should not use the same id as the peer 583 if(fID == mtod(packet, ppp_lcp_packet*)->id)696 if(fID == lcp_hdr.id) 584 697 fID -= 128; 585 698 586 699 nak.SetID(request.ID()); 587 700 reject.SetID(request.ID()); 588 701 589 702 // parse each item 590 703 ppp_configure_item *item; 591 704 in_addr_t *requestedAddress, *wishedAddress = NULL; … … IPCP::RCREvent(struct mbuf *packet) 593 706 item = request.ItemAt(index); 594 707 if(!item) 595 708 continue; 596 709 597 710 // addresses have special handling to reduce code size 598 711 switch(item->type) { 599 712 case IPCP_ADDRESSES: … … IPCP::RCREvent(struct mbuf *packet) 601 714 case IPCP_ADDRESS: 602 715 wishedAddress = &fPeerRequests.address; 603 716 break; 604 717 605 718 case IPCP_PRIMARY_DNS: 606 719 wishedAddress = &fPeerRequests.primaryDNS; 607 720 break; 608 721 609 722 case IPCP_SECONDARY_DNS: 610 723 wishedAddress = &fPeerRequests.secondaryDNS; 611 724 break; 612 725 } 613 726 614 727 // now parse item 615 728 switch(item->type) { 616 729 case IPCP_ADDRESSES: … … IPCP::RCREvent(struct mbuf *packet) 620 733 case IPCP_SECONDARY_DNS: 621 734 if(item->length != 6) { 622 735 // the packet is invalid 623 m_freem(packet);736 gBufferModule->free(packet); 624 737 NewState(PPP_INITIAL_STATE); 625 738 ReportUpFailedEvent(); 626 739 return; 627 740 } 628 741 629 742 requestedAddress = (in_addr_t*) item->data; 630 743 if(*wishedAddress == INADDR_ANY) { 631 744 if(*requestedAddress == INADDR_ANY) { 632 745 // we do not have an address for you 633 m_freem(packet);746 gBufferModule->free(packet); 634 747 NewState(PPP_INITIAL_STATE); 635 748 ReportUpFailedEvent(); 636 749 return; … … IPCP::RCREvent(struct mbuf *packet) 644 757 nak.AddItem((ppp_configure_item*) &ipItem); 645 758 } 646 759 break; 647 760 648 761 // case IPCP_COMPRESSION_PROTOCOL: 649 762 // TODO: implement me! 650 763 // break; 651 764 652 765 default: 653 766 reject.AddItem(item); 654 767 } 655 768 } 656 769 657 770 // append additional values to the nak 658 771 if(!request.ItemWithType(IPCP_ADDRESS) && fPeerRequests.address == INADDR_ANY) { 659 772 // The peer did not provide us his address. Tell him to do so. … … IPCP::RCREvent(struct mbuf *packet) 663 776 ipItem.address = INADDR_ANY; 664 777 nak.AddItem((ppp_configure_item*) &ipItem); 665 778 } 666 779 667 780 if(nak.CountItems() > 0) { 668 781 RCRBadEvent(nak.ToMbuf(Interface().MRU(), Interface().PacketOverhead()), NULL); 669 m_freem(packet);782 gBufferModule->free(packet); 670 783 } else if(reject.CountItems() > 0) { 671 784 RCRBadEvent(NULL, reject.ToMbuf(Interface().MRU(), 672 785 Interface().PacketOverhead())); 673 m_freem(packet);786 gBufferModule->free(packet); 674 787 } else 675 788 RCRGoodEvent(packet); 676 789 } 677 790 678 791 679 792 void 680 IPCP::RCRGoodEvent( struct mbuf*packet)793 IPCP::RCRGoodEvent(net_buffer *packet) 681 794 { 682 795 TRACE("IPCP: RCRGoodEvent() state=%d\n", State()); 683 796 684 797 switch(State()) { 685 798 case PPP_INITIAL_STATE: 686 799 NewState(PPP_ACK_SENT_STATE); … … IPCP::RCRGoodEvent(struct mbuf *packet) 688 801 SendConfigureRequest(); 689 802 SendConfigureAck(packet); 690 803 break; 691 804 692 805 case PPP_REQ_SENT_STATE: 693 806 NewState(PPP_ACK_SENT_STATE); 694 807 695 808 case PPP_ACK_SENT_STATE: 696 809 SendConfigureAck(packet); 697 810 break; 698 811 699 812 case PPP_ACK_RCVD_STATE: 700 813 NewState(PPP_OPENED_STATE); 701 814 SendConfigureAck(packet); 702 815 ReportUpEvent(); 703 816 break; 704 817 705 818 case PPP_OPENED_STATE: 706 819 NewState(PPP_ACK_SENT_STATE); 707 820 SendConfigureRequest(); 708 821 SendConfigureAck(packet); 709 822 break; 710 823 711 824 default: 712 m_freem(packet);825 gBufferModule->free(packet); 713 826 } 714 827 } 715 828 716 829 717 830 void 718 IPCP::RCRBadEvent( struct mbuf *nak, struct mbuf*reject)831 IPCP::RCRBadEvent(net_buffer *nak, net_buffer *reject) 719 832 { 720 833 TRACE("IPCP: RCRBadEvent() state=%d\n", State()); 721 834 835 uint16 lcp_hdr_reject_length = 0; 836 uint16 lcp_hdr_nak_length = 0; 837 838 if (nak) { 839 NetBufferHeaderReader<ppp_lcp_packet> bufferheader_nak(nak); 840 if(bufferheader_nak.Status()!=B_OK) 841 return; 842 ppp_lcp_packet &lcp_hdr_nak = bufferheader_nak.Data(); 843 lcp_hdr_nak_length = lcp_hdr_nak.length; 844 } 845 846 847 if (reject) { 848 NetBufferHeaderReader<ppp_lcp_packet> bufferheader_reject(reject); 849 if(bufferheader_reject.Status()!=B_OK) 850 return; 851 ppp_lcp_packet &lcp_hdr_reject = bufferheader_reject.Data(); 852 lcp_hdr_reject_length = lcp_hdr_reject.length; 853 } 854 722 855 switch(State()) { 723 856 case PPP_OPENED_STATE: 724 857 NewState(PPP_REQ_SENT_STATE); 725 858 SendConfigureRequest(); 726 859 727 860 case PPP_ACK_SENT_STATE: 728 861 if(State() == PPP_ACK_SENT_STATE) 729 862 NewState(PPP_REQ_SENT_STATE); 730 863 // OPENED_STATE might have set this already 731 864 732 865 case PPP_INITIAL_STATE: 733 866 case PPP_REQ_SENT_STATE: 734 867 case PPP_ACK_RCVD_STATE: 735 if(nak && ntohs( mtod(nak, ppp_lcp_packet*)->length) > 3)868 if(nak && ntohs(lcp_hdr_nak_length) > 3) 736 869 SendConfigureNak(nak); 737 else if(reject && ntohs( mtod(reject, ppp_lcp_packet*)->length) > 3)870 else if(reject && ntohs(lcp_hdr_reject_length) > 3) 738 871 SendConfigureNak(reject); 739 872 return; 740 873 // prevents the nak/reject from being m_freem()'d 741 874 742 875 default: 743 876 ; 744 877 } 745 878 746 879 if(nak) 747 m_freem(nak);880 gBufferModule->free(nak); 748 881 if(reject) 749 m_freem(reject);882 gBufferModule->free(reject); 750 883 } 751 884 752 885 753 886 void 754 IPCP::RCAEvent( struct mbuf*packet)887 IPCP::RCAEvent(net_buffer *packet) 755 888 { 756 TRACE("IPCP: RCAEvent() state=%d\n", State()); 757 758 if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { 889 ERROR("IPCP: RCAEvent() state=%d\n", State()); 890 891 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 892 if(bufferheader.Status()!=B_OK) 893 return; 894 ppp_lcp_packet &lcp_hdr = bufferheader.Data(); 895 if(fRequestID != lcp_hdr.id) { 759 896 // this packet is not a reply to our request 760 897 761 898 // TODO: log this event 762 m_freem(packet);899 gBufferModule->free(packet); 763 900 return; 764 901 } 765 902 766 903 // parse this ack 767 904 KPPPConfigurePacket ack(packet); 768 905 ppp_configure_item *item; … … IPCP::RCAEvent(struct mbuf *packet) 771 908 item = ack.ItemAt(index); 772 909 if(!item) 773 910 continue; 774 911 775 912 // addresses have special handling to reduce code size 776 913 switch(item->type) { 777 914 case IPCP_ADDRESSES: … … IPCP::RCAEvent(struct mbuf *packet) 780 917 wishedAddress = &fLocalRequests.address; 781 918 configuredAddress = &fLocalConfiguration.address; 782 919 break; 783 920 784 921 case IPCP_PRIMARY_DNS: 785 922 wishedAddress = &fLocalRequests.primaryDNS; 786 923 configuredAddress = &fLocalConfiguration.primaryDNS; 787 924 break; 788 925 789 926 case IPCP_SECONDARY_DNS: 790 927 wishedAddress = &fLocalRequests.secondaryDNS; 791 928 configuredAddress = &fLocalConfiguration.secondaryDNS; 792 929 break; 793 930 } 794 931 795 932 // now parse item 796 933 switch(item->type) { 797 934 case IPCP_ADDRESSES: … … IPCP::RCAEvent(struct mbuf *packet) 804 941 || *wishedAddress == *requestedAddress) 805 942 *configuredAddress = *requestedAddress; 806 943 break; 807 944 808 945 // case IPCP_COMPRESSION_PROTOCOL: 809 946 // TODO: implement me 810 947 // break; 811 948 812 949 default: 813 950 ; 814 951 } 815 952 } 816 953 817 954 // if address was not specified we should select the given one 818 955 if(!ack.ItemWithType(IPCP_ADDRESS)) 819 956 fLocalConfiguration.address = fLocalRequests.address; 820 821 957 958 822 959 switch(State()) { 823 960 case PPP_INITIAL_STATE: 824 961 IllegalEvent(PPP_RCA_EVENT); 825 962 break; 826 963 827 964 case PPP_REQ_SENT_STATE: 828 965 NewState(PPP_ACK_RCVD_STATE); 829 966 InitializeRestartCount(); 830 967 break; 831 968 832 969 case PPP_ACK_RCVD_STATE: 833 970 NewState(PPP_REQ_SENT_STATE); 834 971 SendConfigureRequest(); 835 972 break; 836 973 837 974 case PPP_ACK_SENT_STATE: 838 975 NewState(PPP_OPENED_STATE); 839 976 InitializeRestartCount(); 840 977 ReportUpEvent(); 841 978 break; 842 979 843 980 case PPP_OPENED_STATE: 844 981 NewState(PPP_REQ_SENT_STATE); 845 982 SendConfigureRequest(); 846 983 break; 847 984 848 985 default: 849 986 ; 850 987 } 851 852 m_freem(packet);988 989 gBufferModule->free(packet); 853 990 } 854 991 855 992 856 993 void 857 IPCP::RCNEvent( struct mbuf*packet)994 IPCP::RCNEvent(net_buffer *packet) 858 995 { 859 996 TRACE("IPCP: RCNEvent() state=%d\n", State()); 860 861 if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { 997 998 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 999 if(bufferheader.Status()!=B_OK) 1000 return; 1001 ppp_lcp_packet &lcp_hdr = bufferheader.Data(); 1002 1003 if(fRequestID != lcp_hdr.id) { 862 1004 // this packet is not a reply to our request 863 1005 864 1006 // TODO: log this event 865 m_freem(packet);1007 gBufferModule->free(packet); 866 1008 return; 867 1009 } 868 1010 869 1011 // parse this nak/reject 870 1012 KPPPConfigurePacket nak_reject(packet); 871 1013 ppp_configure_item *item; … … IPCP::RCNEvent(struct mbuf *packet) 875 1017 item = nak_reject.ItemAt(index); 876 1018 if(!item) 877 1019 continue; 878 1020 879 1021 switch(item->type) { 880 1022 case IPCP_ADDRESSES: 881 1023 // abandoned by the standard 882 1024 case IPCP_ADDRESS: 883 1025 if(item->length != 6) 884 1026 continue; 885 1027 886 1028 requestedAddress = (in_addr_t*) item->data; 887 1029 if(fLocalRequests.address == INADDR_ANY 888 1030 && *requestedAddress != INADDR_ANY) 889 1031 fLocalConfiguration.address = *requestedAddress; 890 1032 // this will be used in our next request 891 1033 break; 892 1034 893 1035 // case IPCP_COMPRESSION_PROTOCOL: 894 1036 // TODO: implement me! 895 1037 // break; 896 1038 897 1039 case IPCP_PRIMARY_DNS: 898 1040 if(item->length != 6) 899 1041 continue; 900 1042 901 1043 requestedAddress = (in_addr_t*) item->data; 902 1044 if(fRequestPrimaryDNS 903 1045 && fLocalRequests.primaryDNS == INADDR_ANY … … IPCP::RCNEvent(struct mbuf *packet) 905 1047 fLocalConfiguration.primaryDNS = *requestedAddress; 906 1048 // this will be used in our next request 907 1049 break; 908 1050 909 1051 case IPCP_SECONDARY_DNS: 910 1052 if(item->length != 6) 911 1053 continue; 912 1054 913 1055 requestedAddress = (in_addr_t*) item->data; 914 1056 if(fRequestSecondaryDNS 915 1057 && fLocalRequests.secondaryDNS == INADDR_ANY … … IPCP::RCNEvent(struct mbuf *packet) 917 1059 fLocalConfiguration.secondaryDNS = *requestedAddress; 918 1060 // this will be used in our next request 919 1061 break; 920 1062 921 1063 default: 922 1064 ; 923 1065 } … … IPCP::RCNEvent(struct mbuf *packet) 927 1069 item = nak_reject.ItemAt(index); 928 1070 if(!item) 929 1071 continue; 930 1072 931 1073 switch(item->type) { 932 1074 // case IPCP_COMPRESSION_PROTOCOL: 933 1075 // TODO: implement me! 934 1076 // break; 935 1077 936 1078 default: 937 1079 // DNS and addresses must be supported if we set them to auto 938 m_freem(packet);1080 gBufferModule->free(packet); 939 1081 NewState(PPP_INITIAL_STATE); 940 1082 ReportUpFailedEvent(); 941 1083 return; 942 1084 } 943 1085 } 944 1086 945 1087 switch(State()) { 946 1088 case PPP_INITIAL_STATE: 947 1089 IllegalEvent(PPP_RCN_EVENT); 948 1090 break; 949 1091 950 1092 case PPP_REQ_SENT_STATE: 951 1093 case PPP_ACK_SENT_STATE: 952 1094 InitializeRestartCount(); 953 1095 954 1096 case PPP_ACK_RCVD_STATE: 955 1097 case PPP_OPENED_STATE: 956 1098 if(State() == PPP_ACK_RCVD_STATE || State() == PPP_OPENED_STATE) 957 1099 NewState(PPP_REQ_SENT_STATE); 958 1100 SendConfigureRequest(); 959 1101 break; 960 1102 961 1103 default: 962 1104 ; 963 1105 } 964 965 m_freem(packet);1106 1107 gBufferModule->free(packet); 966 1108 } 967 1109 968 1110 969 1111 void 970 IPCP::RTREvent( struct mbuf*packet)1112 IPCP::RTREvent(net_buffer *packet) 971 1113 { 972 1114 TRACE("IPCP: RTREvent() state=%d\n", State()); 973 1115 1116 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 1117 if(bufferheader.Status()!=B_OK) 1118 return; 1119 ppp_lcp_packet &lcp_hdr = bufferheader.Data(); 1120 974 1121 // we should not use the same ID as the peer 975 if(fID == mtod(packet, ppp_lcp_packet*)->id)1122 if(fID == lcp_hdr.id) 976 1123 fID -= 128; 977 1124 978 1125 switch(State()) { 979 1126 case PPP_INITIAL_STATE: 980 1127 IllegalEvent(PPP_RTR_EVENT); 981 1128 break; 982 1129 983 1130 case PPP_ACK_RCVD_STATE: 984 1131 case PPP_ACK_SENT_STATE: 985 1132 NewState(PPP_REQ_SENT_STATE); 986 1133 987 1134 case PPP_CLOSING_STATE: 988 1135 case PPP_REQ_SENT_STATE: 989 1136 SendTerminateAck(packet); 990 1137 return; 991 // do not m_freem()packet992 1138 // do not free packet 1139 993 1140 case PPP_OPENED_STATE: 994 1141 NewState(PPP_CLOSING_STATE); 995 1142 ResetRestartCount(); 996 1143 SendTerminateAck(packet); 997 1144 return; 998 // do not m_freem()packet999 1145 // do not free packet 1146 1000 1147 default: 1001 1148 ; 1002 1149 } 1003 1004 m_freem(packet);1150 1151 gBufferModule->free(packet); 1005 1152 } 1006 1153 1007 1154 1008 1155 void 1009 IPCP::RTAEvent( struct mbuf*packet)1156 IPCP::RTAEvent(net_buffer *packet) 1010 1157 { 1011 1158 TRACE("IPCP: RTAEvent() state=%d\n", State()); 1012 1013 if(fTerminateID != mtod(packet, ppp_lcp_packet*)->id) { 1159 1160 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 1161 if(bufferheader.Status()!=B_OK) 1162 return; 1163 ppp_lcp_packet &lcp_hdr = bufferheader.Data(); 1164 if(fTerminateID != lcp_hdr.id) { 1014 1165 // this packet is not a reply to our request 1015 1166 1016 1167 // TODO: log this event 1017 m_freem(packet);1168 gBufferModule->free(packet); 1018 1169 return; 1019 1170 } 1020 1171 1021 1172 switch(State()) { 1022 1173 case PPP_INITIAL_STATE: 1023 1174 IllegalEvent(PPP_RTA_EVENT); 1024 1175 break; 1025 1176 1026 1177 case PPP_CLOSING_STATE: 1027 1178 NewState(PPP_INITIAL_STATE); 1028 1179 ReportDownEvent(); 1029 1180 break; 1030 1181 1031 1182 case PPP_ACK_RCVD_STATE: 1032 1183 NewState(PPP_REQ_SENT_STATE); 1033 1184 break; 1034 1185 1035 1186 case PPP_OPENED_STATE: 1036 1187 NewState(PPP_REQ_SENT_STATE); 1037 1188 SendConfigureRequest(); 1038 1189 break; 1039 1190 1040 1191 default: 1041 1192 ; 1042 1193 } 1043 1044 m_freem(packet);1194 1195 gBufferModule->free(packet); 1045 1196 } 1046 1197 1047 1198 1048 1199 void 1049 IPCP::RUCEvent( struct mbuf*packet)1200 IPCP::RUCEvent(net_buffer *packet) 1050 1201 { 1051 1202 TRACE("IPCP: RUCEvent() state=%d\n", State()); 1052 1203 1053 1204 SendCodeReject(packet); 1054 1205 } 1055 1206 1056 1207 1057 1208 void 1058 IPCP::RXJBadEvent( struct mbuf*packet)1209 IPCP::RXJBadEvent(net_buffer *packet) 1059 1210 { 1060 1211 TRACE("IPCP: RXJBadEvent() state=%d\n", State()); 1061 1212 1062 1213 switch(State()) { 1063 1214 case PPP_INITIAL_STATE: 1064 1215 IllegalEvent(PPP_RXJ_BAD_EVENT); 1065 1216 break; 1066 1217 1067 1218 case PPP_CLOSING_STATE: 1068 1219 NewState(PPP_INITIAL_STATE); 1069 1220 ReportDownEvent(); 1070 1221 break; 1071 1222 1072 1223 case PPP_REQ_SENT_STATE: 1073 1224 case PPP_ACK_RCVD_STATE: 1074 1225 case PPP_ACK_SENT_STATE: 1075 1226 NewState(PPP_INITIAL_STATE); 1076 1227 ReportUpFailedEvent(); 1077 1228 break; 1078 1229 1079 1230 case PPP_OPENED_STATE: 1080 1231 NewState(PPP_CLOSING_STATE); 1081 1232 InitializeRestartCount(); 1082 1233 SendTerminateRequest(); 1083 1234 break; 1084 1235 1085 1236 default: 1086 1237 ; 1087 1238 } 1088 1089 m_freem(packet);1239 1240 gBufferModule->free(packet); 1090 1241 } 1091 1242 1092 1243 … … IPCP::ReportUpFailedEvent() 1105 1256 // reset configurations 1106 1257 memset(&fLocalConfiguration, 0, sizeof(ipcp_configuration)); 1107 1258 memset(&fPeerConfiguration, 0, sizeof(ipcp_configuration)); 1108 1259 1109 1260 UpdateAddresses(); 1110 1261 1111 1262 UpFailedEvent(); 1112 1263 } 1113 1264 … … void 1116 1267 IPCP::ReportUpEvent() 1117 1268 { 1118 1269 UpdateAddresses(); 1119 1270 1120 1271 UpEvent(); 1121 1272 } 1122 1273 … … IPCP::ReportDownEvent() 1127 1278 // reset configurations 1128 1279 memset(&fLocalConfiguration, 0, sizeof(ipcp_configuration)); 1129 1280 memset(&fPeerConfiguration, 0, sizeof(ipcp_configuration)); 1130 1281 1131 1282 UpdateAddresses(); 1132 1283 1133 1284 DownEvent(); 1134 1285 } 1135 1286 … … bool 1156 1307 IPCP::SendConfigureRequest() 1157 1308 { 1158 1309 TRACE("IPCP: SendConfigureRequest() state=%d\n", State()); 1159 1310 1160 1311 --fRequestCounter; 1161 1312 fNextTimeout = system_time() + kIPCPStateMachineTimeout; 1162 1313 1163 1314 KPPPConfigurePacket request(PPP_CONFIGURE_REQUEST); 1164 1315 request.SetID(NextID()); 1165 1316 fRequestID = request.ID(); 1166 1317 ip_item ipItem; 1167 1318 ipItem.length = 6; 1168 1319 1169 1320 // add address 1170 1321 ipItem.type = IPCP_ADDRESS; 1171 1322 if(fLocalRequests.address == INADDR_ANY) 1172 ipItem.address = fLocalConfiguration.address;1323 ipItem.address = (fLocalConfiguration.address); 1173 1324 else 1174 ipItem.address = fLocalRequests.address;1325 ipItem.address =(fLocalRequests.address); 1175 1326 request.AddItem((ppp_configure_item*) &ipItem); 1176 1177 TRACE("IPCP: SCR: confaddr=% lX; reqaddr=%lX; addr=%lX\n",1327 1328 TRACE("IPCP: SCR: confaddr=%X; reqaddr=%X; addr=%X\n", 1178 1329 fLocalConfiguration.address, fLocalRequests.address, 1179 1330 ((ip_item*)request.ItemAt(0))->address); 1180 1331 1181 1332 // add primary DNS (if needed) 1182 1333 if(fRequestPrimaryDNS && fLocalRequests.primaryDNS == INADDR_ANY) { 1183 1334 ipItem.type = IPCP_PRIMARY_DNS; … … IPCP::SendConfigureRequest() 1185 1336 // at first this is 0.0.0.0, but a nak might have set it to a correct value 1186 1337 request.AddItem((ppp_configure_item*) &ipItem); 1187 1338 } 1188 1339 1189 1340 // add secondary DNS (if needed) 1190 1341 if(fRequestSecondaryDNS && fLocalRequests.primaryDNS == INADDR_ANY) { 1191 1342 ipItem.type = IPCP_SECONDARY_DNS; … … IPCP::SendConfigureRequest() 1193 1344 // at first this is 0.0.0.0, but a nak might have set it to a correct value 1194 1345 request.AddItem((ppp_configure_item*) &ipItem); 1195 1346 } 1196 1347 1197 1348 // TODO: add VJC support 1198 1349 1199 1350 return Send(request.ToMbuf(Interface().MRU(), 1200 1351 Interface().PacketOverhead())) == B_OK; 1201 1352 } 1202 1353 1203 1354 1204 1355 bool 1205 IPCP::SendConfigureAck( struct mbuf*packet)1356 IPCP::SendConfigureAck(net_buffer *packet) 1206 1357 { 1207 1358 TRACE("IPCP: SendConfigureAck() state=%d\n", State()); 1208 1359 1209 1360 if(!packet) 1210 1361 return false; 1211 1212 mtod(packet, ppp_lcp_packet*)->code = PPP_CONFIGURE_ACK; 1362 1363 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 1364 if(bufferheader.Status()!=B_OK) 1365 return false; 1366 ppp_lcp_packet &lcpheader = bufferheader.Data(); 1367 lcpheader.code = PPP_CONFIGURE_ACK; 1368 1369 bufferheader.Sync(); 1370 1213 1371 KPPPConfigurePacket ack(packet); 1214 1372 1215 1373 // verify items 1216 1374 ppp_configure_item *item; 1217 1375 in_addr_t *requestedAddress, *wishedAddress = NULL, *configuredAddress = NULL; … … IPCP::SendConfigureAck(struct mbuf *packet) 1219 1377 item = ack.ItemAt(index); 1220 1378 if(!item) 1221 1379 continue; 1222 1380 1223 1381 // addresses have special handling to reduce code size 1224 1382 switch(item->type) { 1225 1383 case IPCP_ADDRESSES: … … IPCP::SendConfigureAck(struct mbuf *packet) 1228 1386 wishedAddress = &fPeerRequests.address; 1229 1387 configuredAddress = &fPeerConfiguration.address; 1230 1388 break; 1231 1389 1232 1390 case IPCP_PRIMARY_DNS: 1233 1391 wishedAddress = &fPeerRequests.primaryDNS; 1234 1392 configuredAddress = &fPeerConfiguration.primaryDNS; 1235 1393 break; 1236 1394 1237 1395 case IPCP_SECONDARY_DNS: 1238 1396 wishedAddress = &fPeerRequests.secondaryDNS; 1239 1397 configuredAddress = &fPeerConfiguration.secondaryDNS; 1240 1398 break; 1241 1399 } 1242 1400 1243 1401 // now parse item 1244 1402 switch(item->type) { 1245 1403 case IPCP_ADDRESSES: … … IPCP::SendConfigureAck(struct mbuf *packet) 1252 1410 || *wishedAddress == *requestedAddress) 1253 1411 *configuredAddress = *requestedAddress; 1254 1412 break; 1255 1413 1256 1414 // case IPCP_COMPRESSION_PROTOCOL: 1257 1415 // TODO: implement me! 1258 1416 // break; 1259 1417 1260 1418 default: 1261 1419 ; 1262 1420 } 1263 1421 } 1264 1422 1265 1423 // if address was not specified we should select the given one 1266 1424 if(!ack.ItemWithType(IPCP_ADDRESS)) 1267 1425 fPeerConfiguration.address = fPeerRequests.address; 1268 1426 1269 1427 return Send(packet) == B_OK; 1270 1428 } 1271 1429 1272 1430 1273 1431 bool 1274 IPCP::SendConfigureNak( struct mbuf*packet)1432 IPCP::SendConfigureNak(net_buffer *packet) 1275 1433 { 1276 1434 TRACE("IPCP: SendConfigureNak() state=%d\n", State()); 1277 1435 1278 1436 if(!packet) 1279 1437 return false; 1280 1281 ppp_lcp_packet *nak = mtod(packet, ppp_lcp_packet*); 1282 if(nak->code == PPP_CONFIGURE_NAK) { 1438 1439 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 1440 if(bufferheader.Status()!=B_OK) 1441 return false; 1442 1443 ppp_lcp_packet &nak = bufferheader.Data(); 1444 1445 if(nak.code == PPP_CONFIGURE_NAK) { 1283 1446 if(fNakCounter == 0) { 1284 1447 // We sent enough naks. Let's try a reject. 1285 nak ->code = PPP_CONFIGURE_REJECT;1448 nak.code = PPP_CONFIGURE_REJECT; 1286 1449 } else 1287 1450 --fNakCounter; 1288 1451 } 1289 1452 1453 bufferheader.Sync(); 1454 1290 1455 return Send(packet) == B_OK; 1291 1456 } 1292 1457 … … bool 1295 1460 IPCP::SendTerminateRequest() 1296 1461 { 1297 1462 TRACE("IPCP: SendTerminateRequest() state=%d\n", State()); 1298 1463 1299 1464 --fTerminateCounter; 1300 1465 fNextTimeout = system_time() + kIPCPStateMachineTimeout; 1301 1302 struct mbuf *packet = m_gethdr(MT_DATA);1466 1467 net_buffer *packet = gBufferModule->create(256); 1303 1468 if(!packet) 1304 1469 return false; 1305 1306 packet->m_pkthdr.len = packet->m_len = 4; 1307 1308 // reserve some space for other protocols 1309 packet->m_data += Interface().PacketOverhead(); 1310 1311 ppp_lcp_packet *request = mtod(packet, ppp_lcp_packet*); 1470 1471 ppp_lcp_packet *request; 1472 status_t status = gBufferModule->append_size(packet,1492,(void **)(&request)); 1473 if(status!=B_OK) 1474 return false; 1475 1312 1476 request->code = PPP_TERMINATE_REQUEST; 1313 1477 request->id = fTerminateID = NextID(); 1314 1478 request->length = htons(4); 1315 1479 1480 status=gBufferModule->trim(packet,4); 1481 if(status!=B_OK) 1482 return false; 1483 1316 1484 return Send(packet) == B_OK; 1317 1485 } 1318 1486 1319 1487 1320 1488 bool 1321 IPCP::SendTerminateAck( struct mbuf*request)1489 IPCP::SendTerminateAck(net_buffer *request) 1322 1490 { 1323 1491 TRACE("IPCP: SendTerminateAck() state=%d\n", State()); 1324 1325 struct mbuf *reply = request; 1326 1327 ppp_lcp_packet *ack; 1328 1492 1493 net_buffer *reply = request; 1494 1329 1495 if(!reply) { 1330 reply = m_gethdr(MT_DATA); 1331 if(!reply) 1496 reply = gBufferModule->create(256); 1497 ppp_lcp_packet *ack; 1498 status_t status = gBufferModule->append_size(reply,1492,(void **)(&ack) ); 1499 if (status != B_OK) { 1500 gBufferModule->free(reply); 1332 1501 return false; 1333 1334 reply->m_data += Interface().PacketOverhead(); 1335 reply->m_pkthdr.len = reply->m_len = 4; 1336 1337 ack = mtod(reply, ppp_lcp_packet*); 1502 } 1338 1503 ack->id = NextID(); 1339 } else 1340 ack = mtod(reply, ppp_lcp_packet*); 1341 1342 ack->code = PPP_TERMINATE_ACK; 1343 ack->length = htons(4); 1344 1504 ack->code = PPP_TERMINATE_ACK; 1505 ack->length = htons(4); 1506 gBufferModule->trim(reply,4); 1507 } else { 1508 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(reply); 1509 if (bufferHeader.Status() < B_OK) 1510 return false; 1511 ppp_lcp_packet &ack = bufferHeader.Data(); 1512 ack.code = PPP_TERMINATE_ACK; 1513 ack.length = htons(4); 1514 } 1515 1345 1516 return Send(reply) == B_OK; 1346 1517 } 1347 1518 1348 1519 1349 1520 bool 1350 IPCP::SendCodeReject( struct mbuf*packet)1521 IPCP::SendCodeReject(net_buffer *packet) 1351 1522 { 1352 1523 TRACE("IPCP: SendCodeReject() state=%d\n", State()); 1353 1524 1354 1525 if(!packet) 1355 1526 return false; 1356 1357 M_PREPEND(packet, 4); 1358 // add some space for the header 1359 1360 // adjust packet if too big 1361 int32 adjust = Interface().MRU(); 1362 if(packet->m_flags & M_PKTHDR) { 1363 adjust -= packet->m_pkthdr.len; 1364 } else 1365 adjust -= packet->m_len; 1366 1367 if(adjust < 0) 1368 m_adj(packet, adjust); 1369 1370 ppp_lcp_packet *reject = mtod(packet, ppp_lcp_packet*); 1371 reject->code = PPP_CODE_REJECT; 1372 reject->id = NextID(); 1373 if(packet->m_flags & M_PKTHDR) 1374 reject->length = htons(packet->m_pkthdr.len); 1375 else 1376 reject->length = htons(packet->m_len); 1377 1527 1528 NetBufferPrepend<ppp_lcp_packet> bufferHeader(packet); 1529 if (bufferHeader.Status() != B_OK) 1530 return false; 1531 1532 ppp_lcp_packet &reject = bufferHeader.Data(); 1533 1534 reject.code = PPP_CODE_REJECT; 1535 reject.id = NextID(); 1536 reject.length = htons(packet->size); 1537 1538 bufferHeader.Sync(); 1539 1378 1540 return Send(packet) == B_OK; 1379 1541 } -
src/add-ons/kernel/network/ppp/ipcp/Protocol.h
diff --git a/src/add-ons/kernel/network/ppp/ipcp/Protocol.h b/src/add-ons/kernel/network/ppp/ipcp/Protocol.h index 626619b..d363876 100644
a b 9 9 #include <driver_settings.h> 10 10 11 11 #include <KPPPProtocol.h> 12 #include <Locker.h>13 12 14 13 #include <arpa/inet.h> 14 #include <net_datalink.h> 15 #include <net_datalink_protocol.h> 16 #include <net/route.h> 15 17 16 18 17 19 #define IPCP_PROTOCOL 0x8021 … … class IPCP : public KPPPProtocol { 71 73 virtual bool Up(); 72 74 virtual bool Down(); 73 75 74 virtual status_t Send( struct mbuf*packet,76 virtual status_t Send(net_buffer *packet, 75 77 uint16 protocolNumber = IPCP_PROTOCOL); 76 virtual status_t Receive( struct mbuf*packet, uint16 protocolNumber);77 status_t ReceiveIPPacket( struct mbuf*packet, uint16 protocolNumber);78 virtual status_t Receive(net_buffer *packet, uint16 protocolNumber); 79 status_t ReceiveIPPacket(net_buffer *packet, uint16 protocolNumber); 78 80 virtual void Pulse(); 79 81 80 82 private: … … class IPCP : public KPPPProtocol { 90 92 // events 91 93 void TOGoodEvent(); 92 94 void TOBadEvent(); 93 void RCREvent( struct mbuf*packet);94 void RCRGoodEvent( struct mbuf*packet);95 void RCRBadEvent( struct mbuf *nak, struct mbuf*reject);96 void RCAEvent( struct mbuf*packet);97 void RCNEvent( struct mbuf*packet);98 void RTREvent( struct mbuf*packet);99 void RTAEvent( struct mbuf*packet);100 void RUCEvent( struct mbuf*packet);101 void RXJBadEvent( struct mbuf*packet);95 void RCREvent(net_buffer *packet); 96 void RCRGoodEvent(net_buffer *packet); 97 void RCRBadEvent(net_buffer *nak, net_buffer *reject); 98 void RCAEvent(net_buffer *packet); 99 void RCNEvent(net_buffer *packet); 100 void RTREvent(net_buffer *packet); 101 void RTAEvent(net_buffer *packet); 102 void RUCEvent(net_buffer *packet); 103 void RXJBadEvent(net_buffer *packet); 102 104 103 105 // actions 104 106 void IllegalEvent(ppp_event event); … … class IPCP : public KPPPProtocol { 108 110 void InitializeRestartCount(); 109 111 void ResetRestartCount(); 110 112 bool SendConfigureRequest(); 111 bool SendConfigureAck( struct mbuf*packet);112 bool SendConfigureNak( struct mbuf*packet);113 bool SendConfigureAck(net_buffer *packet); 114 bool SendConfigureNak(net_buffer *packet); 113 115 bool SendTerminateRequest(); 114 bool SendTerminateAck( struct mbuf*request = NULL);115 bool SendCodeReject( struct mbuf*packet);116 bool SendTerminateAck(net_buffer *request = NULL); 117 bool SendCodeReject(net_buffer *packet); 116 118 117 119 private: 118 120 ipcp_configuration fLocalConfiguration, fPeerConfiguration; … … class IPCP : public KPPPProtocol { 120 122 121 123 // default route 122 124 struct sockaddr_in fGateway; 123 rtentry*fDefaultRoute;125 net_route *fDefaultRoute; 124 126 125 127 // used for local requests 126 128 bool fRequestPrimaryDNS, fRequestSecondaryDNS; -
new file src/add-ons/kernel/network/ppp/ipcp/bitypes.h
diff --git a/src/add-ons/kernel/network/ppp/ipcp/bitypes.h b/src/add-ons/kernel/network/ppp/ipcp/bitypes.h new file mode 100644 index 0000000..9a6118b
- + 1 #include <stdint.h> -
new file src/add-ons/kernel/network/ppp/ipcp/config.h
diff --git a/src/add-ons/kernel/network/ppp/ipcp/config.h b/src/add-ons/kernel/network/ppp/ipcp/config.h new file mode 100644 index 0000000..0c68ffa
- + 1 /* config.h. Generated from config.h.in by configure. */ 2 /* #undef _SOCKADDR_LEN */ 3 #define HAVE_FCNTL_H 1 4 #define HAVE_PATHS_H 1 5 #define HAVE_INTTYPES_H 1 6 /* #undef HAVE_STROPTS_H */ 7 /* #undef HAVE_SYS_TIMERS_H */ 8 #define HAVE_SYS_SELECT_H 1 9 #define HAVE_MEMORY_H 1 10 /* #undef SYS_CDEFS_H */ 11 /* #undef _POSIX_PTHREAD_SEMANTICS */ 12 /* #undef POSIX_GETPWUID_R */ 13 /* #undef POSIX_GETPWNAM_R */ 14 /* #undef POSIX_GETGRGID_R */ 15 /* #undef POSIX_GETGRNAM_R */ 16 #define HAVE_MEMMOVE 1 17 #define HAVE_MEMCHR 1 18 /* #undef SPRINTF_CHAR */ 19 /* #undef VSPRINTF_CHAR */ 20 #define USE_SYSERROR_LIST 1 21 /* #undef NEED_STRTOUL */ 22 /* #undef NEED_SUN4PROTOS */ 23 /* #undef REENABLE_SEND */ 24 25 #define NEED_SETGROUPENT 1 26 /* #undef NEED_GETGROUPLIST */ 27 28 /* define if prototype for getgrnam_r() is required */ 29 /* #undef NEED_GETGRNAM_R */ 30 /* #undef NEED_GETGRGID_R */ 31 /* #undef NEED_GETGRENT_R */ 32 #define NEED_SETGRENT_R 1 33 #define NEED_ENDGRENT_R 1 34 35 #define NEED_INNETGR_R 1 36 /* #undef NEED_SETNETGRENT_R */ 37 #define NEED_ENDNETGRENT_R 1 38 39 /* #undef NEED_GETPWNAM_R */ 40 /* #undef NEED_GETPWUID_R */ 41 #define NEED_SETPWENT_R 1 42 #define NEED_SETPASSENT_R 1 43 #define NEED_SETPWENT_R 1 44 /* #undef NEED_GETPWENT_R */ 45 #define NEED_ENDPWENT_R 1 46 47 #define NEED_SETPASSENT 1 48 49 /* #undef HAS_PW_CLASS */ 50 51 /* #undef ssize_t */ 52 /* #undef uintptr_t */ 53 54 /* Shut up warnings about sputaux in stdio.h on BSD/OS pre-4.1 */ 55 /* #undef SHUTUP_SPUTAUX */ 56 #ifdef SHUTUP_SPUTAUX 57 struct __sFILE; 58 extern __inline int __sputaux(int _c, struct __sFILE *_p); 59 #endif 60 /* #undef BROKEN_IN6ADDR_INIT_MACROS */ 61 #define HAVE_STRLCAT 1 62 /* Shut up warnings about missing braces */ 63 /* #undef SHUTUP_MUTEX_INITIALIZER */ 64 #ifdef SHUTUP_MUTEX_INITIALIZER 65 #define LIBBIND_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER } 66 #else 67 #define LIBBIND_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER 68 #endif 69 -
src/add-ons/kernel/network/ppp/ipcp/ipcp.cpp
diff --git a/src/add-ons/kernel/network/ppp/ipcp/ipcp.cpp b/src/add-ons/kernel/network/ppp/ipcp/ipcp.cpp index fbf4137..3427d64 100644
a b 5 5 6 6 #include <KernelExport.h> 7 7 #include <driver_settings.h> 8 #include <core_funcs.h>9 #include <net_module.h>10 8 11 #include <KPPPInterface.h> 9 #include <net_buffer.h> 10 #include <net_stack.h> 11 #include <NetBufferUtilities.h> 12 13 #include <KPPPDefs.h> 12 14 #include <KPPPModule.h> 15 #include <KPPPInterface.h> 13 16 14 17 #include "Protocol.h" 18 // #define NET_CORE_MODULE_NAME "net_stack" 19 // #define NET_STACK_MODULE_NAME "network/stack/v1" 15 20 21 #define IPCP_MODULE_NAME NETWORK_MODULES_ROOT "/ppp/ipcp" 16 22 17 #define IPCP_MODULE_NAME NETWORK_MODULES_ROOT "ppp/ipcp"18 19 struct protosw *gProto[IPPROTO_MAX];20 struct core_module_info *core = NULL;21 23 status_t std_ops(int32 op, ...); 22 24 25 net_stack_module_info *gStackModule = NULL; 26 net_buffer_module_info *gBufferModule = NULL; 27 // net_device_module_info *sEthernetModule; 28 29 23 30 24 31 // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 25 32 // TODO: Remove isascii() (needed for inet_aton()) when our kernel is finished! … … extern "C" 28 35 int 29 36 isascii(char c) 30 37 { 31 return c & ~0x7f == 0; // If c is a 7 bit value.38 return ( (c & (~0x7f)) == 0 ); // If c is a 7 bit value. 32 39 } 33 40 // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 34 41 … … add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface, 51 58 success = mainInterface.AddProtocol(ipcp); 52 59 } 53 60 54 TRACE("IPCP: add_to(): %s\n",61 dprintf("IPCP: add_to(): %s\n", 55 62 success && ipcp && ipcp->InitCheck() == B_OK ? "OK" : "ERROR"); 56 63 57 64 return success && ipcp && ipcp->InitCheck() == B_OK; 58 65 } 59 66 60 67 68 61 69 static ppp_module_info ipcp_module = { 62 70 { 63 71 IPCP_MODULE_NAME, … … std_ops(int32 op, ...) 75 83 { 76 84 switch(op) { 77 85 case B_MODULE_INIT: 78 if(get_module(NET_CORE_MODULE_NAME, (module_info**) &core) != B_OK) 86 if(get_module(NET_STACK_MODULE_NAME, 87 (module_info**) &gStackModule) != B_OK) 88 return B_ERROR; 89 if(get_module(NET_BUFFER_MODULE_NAME, 90 (module_info **)&gBufferModule) != B_OK) { 91 put_module(NET_STACK_MODULE_NAME); 79 92 return B_ERROR; 80 memset(gProto, 0, sizeof(struct protosw*) * IPPROTO_MAX);81 add_protosw(gProto, NET_LAYER1);82 return B_OK;93 } 94 return B_OK; 95 break; 83 96 84 97 case B_MODULE_UNINIT: 85 put_module(NET_CORE_MODULE_NAME); 86 break; 98 put_module(NET_BUFFER_MODULE_NAME); 99 put_module(NET_STACK_MODULE_NAME); 100 break; 87 101 88 102 default: 89 103 return B_ERROR; -
new file src/add-ons/kernel/network/ppp/ipcp/port_after.h
diff --git a/src/add-ons/kernel/network/ppp/ipcp/port_after.h b/src/add-ons/kernel/network/ppp/ipcp/port_after.h new file mode 100644 index 0000000..1e2969d
- + 1 /* 2 * Copyright (C) 2004-2008 Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (C) 2001-2003 Internet Software Consortium. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 * PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 /* $Id: port_after.h.in,v 1.60 2008/02/28 05:34:17 marka Exp $ */ 19 20 #ifndef port_after_h 21 #define port_after_h 22 23 #include <stdio.h> 24 #include <sys/types.h> 25 #include <sys/socket.h> 26 #include <sys/param.h> 27 #include <sys/time.h> 28 #if (!defined(BSD)) || (BSD < 199306) 29 #include "bitypes.h" 30 #endif 31 #ifdef HAVE_INTTYPES_H 32 #include <inttypes.h> 33 #endif 34 #ifdef HAVE_SYS_SELECT_H 35 #include <sys/select.h> 36 #endif /* HAVE_SYS_SELECT_H */ 37 38 #ifdef REENABLE_SEND 39 #undef send 40 #endif 41 42 #undef NEED_PSELECT 43 #define HAVE_SA_LEN 1 44 #undef HAVE_MINIMUM_IFREQ 45 #undef NEED_DAEMON 46 /* manual Haiku change */ 47 #define NEED_STRSEP 1 48 #undef NEED_STRERROR 49 #ifdef NEED_STRERROR 50 const char *isc_strerror(int); 51 #define strerror isc_strerror 52 #endif 53 #define HAS_INET6_STRUCTS 1 54 #define HAVE_SIN6_SCOPE_ID 1 55 #undef NEED_IN6ADDR_ANY 56 #define HAS_IN_ADDR6 57 #define HAVE_SOCKADDR_STORAGE 1 58 #undef NEED_GETTIMEOFDAY 59 #define HAVE_STRNDUP 1 60 #undef USE_FIONBIO_IOCTL 61 #undef INNETGR_ARGS 62 #undef SETNETGRENT_ARGS 63 #undef USE_IFNAMELINKID 64 #define PORT_NONBLOCK O_NONBLOCK 65 66 #ifndef _POSIX_PATH_MAX 67 #define _POSIX_PATH_MAX 255 68 #endif 69 #ifndef PATH_MAX 70 #define PATH_MAX _POSIX_PATH_MAX 71 #endif 72 73 /* 74 * We need to know the IPv6 address family number even on IPv4-only systems. 75 * Note that this is NOT a protocol constant, and that if the system has its 76 * own AF_INET6, different from ours below, all of BIND's libraries and 77 * executables will need to be recompiled after the system <sys/socket.h> 78 * has had this type added. The type number below is correct on most BSD- 79 * derived systems for which AF_INET6 is defined. 80 */ 81 #ifndef AF_INET6 82 #define AF_INET6 24 83 #endif 84 85 #ifndef PF_INET6 86 #define PF_INET6 AF_INET6 87 #endif 88 89 #ifndef HAS_INET6_STRUCTS 90 /* Replace with structure from later rev of O/S if known. */ 91 struct in6_addr { 92 u_int8_t s6_addr[16]; 93 }; 94 95 #define IN6ADDR_ANY_INIT \ 96 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} 98 99 #define IN6ADDR_LOOPBACK_INIT \ 100 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }} 102 103 /* Replace with structure from later rev of O/S if known. */ 104 struct sockaddr_in6 { 105 #ifdef HAVE_SA_LEN 106 u_int8_t sin6_len; /* length of this struct */ 107 u_int8_t sin6_family; /* AF_INET6 */ 108 #else 109 u_int16_t sin6_family; /* AF_INET6 */ 110 #endif 111 u_int16_t sin6_port; /* transport layer port # */ 112 u_int32_t sin6_flowinfo; /* IPv6 flow information */ 113 struct in6_addr sin6_addr; /* IPv6 address */ 114 u_int32_t sin6_scope_id; /* set of interfaces for a scope */ 115 }; 116 #endif /* HAS_INET6_STRUCTS */ 117 118 #ifdef BROKEN_IN6ADDR_INIT_MACROS 119 #undef IN6ADDR_ANY_INIT 120 #undef IN6ADDR_LOOPBACK_INIT 121 #endif 122 123 #ifdef _AIX 124 #ifndef IN6ADDR_ANY_INIT 125 #define IN6ADDR_ANY_INIT {{{ 0, 0, 0, 0 }}} 126 #endif 127 #ifndef IN6ADDR_LOOPBACK_INIT 128 #if BYTE_ORDER == BIG_ENDIAN 129 #define IN6ADDR_LOOPBACK_INIT {{{ 0, 0, 0, 1 }}} 130 #else 131 #define IN6ADDR_LOOPBACK_INIT {{{0, 0, 0, 0x01000000}}} 132 #endif 133 #endif 134 #endif 135 136 #ifdef __HAIKU__ 137 #define isc_in6addr_any in6addr_any 138 #define isc_in6addr_loopback in6addr_loopback 139 #endif 140 141 #ifndef IN6ADDR_ANY_INIT 142 #ifdef s6_addr 143 #define IN6ADDR_ANY_INIT \ 144 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} 146 #else 147 #define IN6ADDR_ANY_INIT \ 148 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 149 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }} 150 #endif 151 152 #endif 153 #ifndef IN6ADDR_LOOPBACK_INIT 154 #ifdef s6_addr 155 #define IN6ADDR_LOOPBACK_INIT \ 156 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} 158 #else 159 #define IN6ADDR_LOOPBACK_INIT \ 160 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }} 162 #endif 163 #endif 164 165 #ifndef HAVE_SOCKADDR_STORAGE 166 #define __SS_MAXSIZE 128 167 #define __SS_ALLIGSIZE (sizeof (long)) 168 169 struct sockaddr_storage { 170 #ifdef HAVE_SA_LEN 171 u_int8_t ss_len; /* address length */ 172 u_int8_t ss_family; /* address family */ 173 char __ss_pad1[__SS_ALLIGSIZE - 2 * sizeof(u_int8_t)]; 174 long __ss_align; 175 char __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE]; 176 #else 177 u_int16_t ss_family; /* address family */ 178 char __ss_pad1[__SS_ALLIGSIZE - sizeof(u_int16_t)]; 179 long __ss_align; 180 char __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE]; 181 #endif 182 }; 183 #endif 184 185 186 #if !defined(HAS_INET6_STRUCTS) || defined(NEED_IN6ADDR_ANY) 187 #define in6addr_any isc_in6addr_any 188 extern const struct in6_addr in6addr_any; 189 #endif 190 191 /* 192 * IN6_ARE_ADDR_EQUAL, IN6_IS_ADDR_UNSPECIFIED, IN6_IS_ADDR_V4COMPAT and 193 * IN6_IS_ADDR_V4MAPPED are broken in glibc 2.1. 194 */ 195 #ifdef __GLIBC__ 196 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2) 197 #undef IN6_ARE_ADDR_EQUAL 198 #undef IN6_IS_ADDR_UNSPECIFIED 199 #undef IN6_IS_ADDR_V4COMPAT 200 #undef IN6_IS_ADDR_V4MAPPED 201 #endif 202 #endif 203 204 #ifndef IN6_ARE_ADDR_EQUAL 205 #define IN6_ARE_ADDR_EQUAL(a,b) \ 206 (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) 207 #endif 208 209 #ifndef IN6_IS_ADDR_UNSPECIFIED 210 #define IN6_IS_ADDR_UNSPECIFIED(a) \ 211 IN6_ARE_ADDR_EQUAL(a, &in6addr_any) 212 #endif 213 214 #ifndef IN6_IS_ADDR_LOOPBACK 215 extern const struct in6_addr isc_in6addr_loopback; 216 #define IN6_IS_ADDR_LOOPBACK(a) \ 217 IN6_ARE_ADDR_EQUAL(a, &isc_in6addr_loopback) 218 #endif 219 220 #ifndef IN6_IS_ADDR_V4MAPPED 221 #define IN6_IS_ADDR_V4MAPPED(a) \ 222 ((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \ 223 (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \ 224 (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \ 225 (a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 && \ 226 (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \ 227 (a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff) 228 #endif 229 230 #ifndef IN6_IS_ADDR_SITELOCAL 231 #define IN6_IS_ADDR_SITELOCAL(a) \ 232 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) 233 #endif 234 235 #ifndef IN6_IS_ADDR_LINKLOCAL 236 #define IN6_IS_ADDR_LINKLOCAL(a) \ 237 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) 238 #endif 239 240 #ifndef IN6_IS_ADDR_MULTICAST 241 #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) 242 #endif 243 244 #ifndef __IPV6_ADDR_MC_SCOPE 245 #define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) 246 #endif 247 248 #ifndef __IPV6_ADDR_SCOPE_SITELOCAL 249 #define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 250 #endif 251 #ifndef __IPV6_ADDR_SCOPE_ORGLOCAL 252 #define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 253 #endif 254 255 #ifndef IN6_IS_ADDR_MC_SITELOCAL 256 #define IN6_IS_ADDR_MC_SITELOCAL(a) \ 257 (IN6_IS_ADDR_MULTICAST(a) && \ 258 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) 259 #endif 260 261 #ifndef IN6_IS_ADDR_MC_ORGLOCAL 262 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \ 263 (IN6_IS_ADDR_MULTICAST(a) && \ 264 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) 265 #endif 266 267 #ifndef INADDR_NONE 268 #define INADDR_NONE 0xffffffff 269 #endif 270 271 #ifndef MAXHOSTNAMELEN 272 #define MAXHOSTNAMELEN 256 273 #endif 274 275 #ifndef INET6_ADDRSTRLEN 276 /* sizeof("aaaa:bbbb:cccc:dddd:eeee:ffff:123.123.123.123") */ 277 #define INET6_ADDRSTRLEN 46 278 #endif 279 280 #ifndef MIN 281 #define MIN(x,y) (((x) <= (y)) ? (x) : (y)) 282 #endif 283 284 #ifndef MAX 285 #define MAX(x,y) (((x) >= (y)) ? (x) : (y)) 286 #endif 287 288 #ifdef NEED_DAEMON 289 int daemon(int nochdir, int noclose); 290 #endif 291 292 #ifdef NEED_STRSEP 293 char * strsep(char **stringp, const char *delim); 294 #endif 295 296 #ifndef ALIGN 297 #define ALIGN(p) (((uintptr_t)(p) + (sizeof(long) - 1)) & ~(sizeof(long) - 1)) 298 #endif 299 300 #ifdef NEED_SETGROUPENT 301 int setgroupent(int stayopen); 302 #endif 303 304 #ifdef NEED_GETGROUPLIST 305 int getgrouplist(GETGROUPLIST_ARGS); 306 #endif 307 308 #ifdef POSIX_GETGRNAM_R 309 int 310 __posix_getgrnam_r(const char *, struct group *, char *, int, struct group **); 311 #endif 312 313 #ifdef NEED_GETGRNAM_R 314 int 315 getgrnam_r(const char *, struct group *, char *, size_t, struct group **); 316 #endif 317 318 #ifdef POSIX_GETGRGID_R 319 int 320 __posix_getgrgid_r(gid_t, struct group *, char *, int, struct group **) ; 321 #endif 322 323 #ifdef NEED_GETGRGID_R 324 int 325 getgrgid_r(gid_t, struct group *, char *, size_t, struct group **); 326 #endif 327 328 #ifdef NEED_GETGRENT_R 329 GROUP_R_RETURN getgrent_r(struct group *gptr, GROUP_R_ARGS); 330 #endif 331 332 #ifdef NEED_SETGRENT_R 333 GROUP_R_SET_RETURN setgrent_r(GROUP_R_ENT_ARGS); 334 #endif 335 336 #ifdef NEED_ENDGRENT_R 337 GROUP_R_END_RETURN endgrent_r(GROUP_R_ENT_ARGS); 338 #endif 339 340 #if defined(NEED_INNETGR_R) && defined(NGR_R_RETURN) 341 NGR_R_RETURN 342 innetgr_r(const char *, const char *, const char *, const char *); 343 #endif 344 345 #ifdef NEED_SETNETGRENT_R 346 #ifdef NGR_R_SET_ARGS 347 NGR_R_SET_RETURN setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS); 348 #else 349 NGR_R_SET_RETURN setnetgrent_r(NGR_R_SET_CONST char *netgroup); 350 #endif 351 #endif 352 353 #ifdef NEED_ENDNETGRENT_R 354 #ifdef NGR_R_END_ARGS 355 NGR_R_END_RETURN endnetgrent_r(NGR_R_END_ARGS); 356 #else 357 NGR_R_END_RETURN endnetgrent_r(void); 358 #endif 359 #endif 360 361 #ifdef POSIX_GETPWNAM_R 362 int 363 __posix_getpwnam_r(const char *login, struct passwd *pwptr, 364 char *buf, size_t buflen, struct passwd **result); 365 #endif 366 367 #ifdef NEED_GETPWNAM_R 368 int 369 getpwnam_r(const char *login, struct passwd *pwptr, 370 char *buf, size_t buflen, struct passwd **result); 371 #endif 372 373 #ifdef POSIX_GETPWUID_R 374 int 375 __posix_getpwuid_r(uid_t uid, struct passwd *pwptr, 376 char *buf, int buflen, struct passwd **result); 377 #endif 378 379 #ifdef NEED_GETPWUID_R 380 int 381 getpwuid_r(uid_t uid, struct passwd *pwptr, 382 char *buf, size_t buflen, struct passwd **result); 383 #endif 384 385 #ifdef NEED_SETPWENT_R 386 #ifdef PASS_R_ENT_ARGS 387 PASS_R_SET_RETURN setpwent_r(PASS_R_ENT_ARGS); 388 #else 389 PASS_R_SET_RETURN setpwent_r(void); 390 #endif 391 392 #endif 393 394 #ifdef NEED_SETPASSENT_R 395 #ifdef PASS_R_ENT_ARGS 396 PASS_R_SET_RETURN setpassent_r(int stayopen, PASS_R_ENT_ARGS); 397 #else 398 PASS_R_SET_RETURN setpassent_r(int stayopen); 399 #endif 400 #endif 401 402 #ifdef NEED_GETPWENT_R 403 PASS_R_RETURN getpwent_r(struct passwd *pwptr, PASS_R_ARGS); 404 #endif 405 406 #ifdef NEED_ENDPWENT_R 407 void endpwent_r(void); 408 #endif 409 410 #ifdef NEED_SETPASSENT 411 int setpassent(int stayopen); 412 #endif 413 414 #ifndef __HAIKU__ 415 #define gettimeofday isc__gettimeofday 416 #ifdef NEED_GETTIMEOFDAY 417 int isc__gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp); 418 #else 419 int isc__gettimeofday(struct timeval *tp, struct timezone *tzp); 420 #endif 421 #endif 422 423 int getnetgrent(NGR_R_CONST char **machinep, NGR_R_CONST char **userp, 424 NGR_R_CONST char **domainp); 425 426 #ifdef NGR_R_ARGS 427 int getnetgrent_r(NGR_R_CONST char **machinep, NGR_R_CONST char **userp, 428 NGR_R_CONST char **domainp, NGR_R_ARGS); 429 #endif 430 431 #ifdef SETNETGRENT_ARGS 432 void setnetgrent(SETNETGRENT_ARGS); 433 #else 434 void setnetgrent(const char *netgroup); 435 #endif 436 437 void endnetgrent(void); 438 439 #ifdef INNETGR_ARGS 440 int innetgr(INNETGR_ARGS); 441 #else 442 int innetgr(const char *netgroup, const char *machine, 443 const char *user, const char *domain); 444 #endif 445 446 #ifdef NGR_R_SET_ARGS 447 NGR_R_SET_RETURN 448 setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS); 449 #else 450 NGR_R_SET_RETURN 451 setnetgrent_r(NGR_R_SET_CONST char *netgroup); 452 #endif 453 454 #ifdef NEED_STRTOUL 455 unsigned long strtoul(const char *, char **, int); 456 #endif 457 458 #ifdef NEED_SUN4PROTOS 459 #include <stdarg.h> 460 #ifndef __SIZE_TYPE__ 461 #define __SIZE_TYPE__ int 462 #endif 463 struct sockaddr; 464 struct iovec; 465 struct timeval; 466 struct timezone; 467 int fprintf(FILE *, const char *, ...); 468 int getsockname(int, struct sockaddr *, int *); 469 int getpeername(int, struct sockaddr *, int *); 470 int socket(int, int, int); 471 int connect(int, const struct sockaddr *, int); 472 int writev(int, struct iovec *, int); 473 int readv(int, struct iovec *, int); 474 int send(int, const char *, int, int); 475 void bzero(char *, int); 476 int recvfrom(int, char *, int, int, struct sockaddr *, int *); 477 int syslog(int, const char *, ... ); 478 int printf(const char *, ...); 479 __SIZE_TYPE__ fread(void *, __SIZE_TYPE__, __SIZE_TYPE__, FILE *); 480 __SIZE_TYPE__ fwrite(const void *, __SIZE_TYPE__, __SIZE_TYPE__, FILE *); 481 int fclose(FILE *); 482 int ungetc(int, FILE *); 483 int scanf(const char *, ...); 484 int sscanf(const char *, const char *, ... ); 485 int tolower(int); 486 int toupper(int); 487 int strcasecmp(const char *, const char *); 488 int strncasecmp(const char *, const char *, int); 489 int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); 490 #ifdef gettimeofday 491 #undef gettimeofday 492 int gettimeofday(struct timeval *, struct timezone *); 493 #define gettimeofday isc__gettimeofday 494 #else 495 int gettimeofday(struct timeval *, struct timezone *); 496 #endif 497 long strtol(const char*, char **, int); 498 int fseek(FILE *, long, int); 499 int setsockopt(int, int, int, const char *, int); 500 int bind(int, const struct sockaddr *, int); 501 void bcopy(char *, char *, int); 502 int fputc(char, FILE *); 503 int listen(int, int); 504 int accept(int, struct sockaddr *, int *); 505 int getsockopt(int, int, int, char *, int *); 506 int vfprintf(FILE *, const char *, va_list); 507 int fflush(FILE *); 508 int fgetc(FILE *); 509 int fputs(const char *, FILE *); 510 int fchown(int, int, int); 511 void setbuf(FILE *, char *); 512 int gethostname(char *, int); 513 int rename(const char *, const char *); 514 time_t time(time_t *); 515 int fscanf(FILE *, const char *, ...); 516 int sscanf(const char *, const char *, ...); 517 int ioctl(int, int, caddr_t); 518 void perror(const char *); 519 520 #if !defined(__USE_FIXED_PROTOTYPES__) && !defined(__cplusplus) && !defined(__STRICT_ANSI__) 521 /* 522 * 'gcc -ansi' changes the prototype for vsprintf(). 523 * Use this prototype when 'gcc -ansi' is not in effect. 524 */ 525 char *vsprintf(char *, const char *, va_list); 526 #endif 527 #endif 528 529 #endif -
new file src/add-ons/kernel/network/ppp/ipcp/port_before.h
diff --git a/src/add-ons/kernel/network/ppp/ipcp/port_before.h b/src/add-ons/kernel/network/ppp/ipcp/port_before.h new file mode 100644 index 0000000..9107450
- + 1 /* 2 * Copyright (C) 2005-2008 Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (C) 2001 Internet Software Consortium. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 * PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 /* $Id: port_before.h.in,v 1.31 2008/02/28 05:36:10 marka Exp $ */ 19 20 #ifndef port_before_h 21 #define port_before_h 22 #include "config.h" 23 24 #ifdef NEED_SUN4PROTOS 25 #define _PARAMS(x) x 26 #endif 27 28 #ifdef __HAIKU__ 29 # include <sys/sockio.h> 30 # define ETOOMANYREFS EBADF 31 32 // inet_*() are just weak symbols 33 # define inet_addr __inet_addr 34 # define inet_aton __inet_aton 35 # define inet_lnaof __inet_lnaof 36 # define inet_makeaddr __inet_makeaddr 37 # define inet_neta __inet_neta 38 # define inet_netof __inet_netof 39 # define inet_network __inet_network 40 # define inet_net_ntop __inet_net_ntop 41 # define inet_net_pton __inet_net_pton 42 # define inet_cidr_ntop __inet_cidr_ntop 43 # define inet_cidr_pton __inet_cidr_pton 44 # define inet_ntoa __inet_ntoa 45 # define inet_pton __inet_pton 46 # define inet_ntop __inet_ntop 47 # define inet_nsap_addr __inet_nsap_addr 48 # define inet_nsap_ntoa __inet_nsap_ntoa 49 #endif 50 51 struct group; /* silence warning */ 52 struct passwd; /* silence warning */ 53 struct timeval; /* silence warning */ 54 struct timezone; /* silence warning */ 55 56 #ifdef HAVE_SYS_TIMERS_H 57 #include <sys/timers.h> 58 #endif 59 #include <limits.h> 60 61 #ifdef ISC_PLATFORM_NEEDTIMESPEC 62 #include <time.h> /* For time_t */ 63 struct timespec { 64 time_t tv_sec; /* seconds */ 65 long tv_nsec; /* nanoseconds */ 66 }; 67 #endif 68 #ifndef HAVE_MEMMOVE 69 #define memmove(a,b,c) bcopy(b,a,c) 70 #endif 71 72 #undef WANT_IRS_GR 73 #undef WANT_IRS_NIS 74 #undef WANT_IRS_PW 75 76 #undef BSD_COMP 77 #undef HAVE_POLL 78 #undef HAVE_MD5 79 #undef SOLARIS2 80 81 #define DO_PTHREADS 82 #define GETGROUPLIST_ARGS const char *name, gid_t basegid, gid_t *groups, int *ngroups 83 #define GETNETBYADDR_ADDR_T long 84 #define SETPWENT_VOID 1 85 #define SETGRENT_VOID 1 86 87 #define NET_R_ARGS char *buf, int buflen 88 #define NET_R_BAD NULL 89 #define NET_R_COPY buf, buflen 90 #define NET_R_COPY_ARGS NET_R_ARGS 91 #define NET_R_END_RESULT(x) /*empty*/ 92 #define NET_R_END_RETURN void 93 #undef NET_R_ENT_ARGS /*empty*/ 94 #define NET_R_OK nptr 95 #define NET_R_RETURN struct netent * 96 #undef NET_R_SET_RESULT /*empty*/ 97 #undef NET_R_SETANSWER 98 #define NET_R_SET_RETURN void 99 #undef NETENT_DATA 100 101 102 #define GROUP_R_SET_RETURN void 103 #undef GROUP_R_SET_RESULT /*empty*/ 104 #define GROUP_R_END_RETURN void 105 #define GROUP_R_END_RESULT(x) /*empty*/ 106 107 #define GROUP_R_ENT_ARGS void 108 109 110 111 #define HOST_R_ARGS char *buf, int buflen, int *h_errnop 112 #define HOST_R_BAD NULL 113 #define HOST_R_COPY buf, buflen 114 #define HOST_R_COPY_ARGS char *buf, int buflen 115 #define HOST_R_END_RESULT(x) /*empty*/ 116 #define HOST_R_END_RETURN void 117 #undef HOST_R_ENT_ARGS /*empty*/ 118 #define HOST_R_ERRNO *h_errnop = h_errno 119 #define HOST_R_OK hptr 120 #define HOST_R_RETURN struct hostent * 121 #undef HOST_R_SETANSWER 122 #undef HOST_R_SET_RESULT 123 #define HOST_R_SET_RETURN void 124 #undef HOSTENT_DATA 125 126 #define NGR_R_ARGS char *buf, int buflen 127 #define NGR_R_BAD (0) 128 #define NGR_R_COPY buf, buflen 129 #define NGR_R_COPY_ARGS NGR_R_ARGS 130 #define NGR_R_CONST 131 #define NGR_R_END_RESULT(x) /*empty*/ 132 #define NGR_R_END_RETURN void 133 #undef NGR_R_END_ARGS /*empty*/ 134 #define NGR_R_OK 1 135 #define NGR_R_RETURN int 136 #define NGR_R_SET_CONST const 137 #undef NGR_R_SET_RESULT /*empty*/ 138 #define NGR_R_SET_RETURN void 139 #undef NGR_R_SET_ARGS 140 141 142 #if !defined(NGR_R_SET_ARGS) && defined(NGR_R_END_ARGS) 143 #define NGR_R_SET_ARGS NGR_R_END_ARGS 144 #endif 145 146 #define PROTO_R_ARGS char *buf, int buflen 147 #define PROTO_R_BAD NULL 148 #define PROTO_R_COPY buf, buflen 149 #define PROTO_R_COPY_ARGS PROTO_R_ARGS 150 #define PROTO_R_END_RESULT(x) /*empty*/ 151 #define PROTO_R_END_RETURN void 152 #undef PROTO_R_ENT_ARGS /*empty*/ 153 #undef PROTO_R_ENT_UNUSED 154 #define PROTO_R_OK pptr 155 #undef PROTO_R_SETANSWER 156 #define PROTO_R_RETURN struct protoent * 157 #undef PROTO_R_SET_RESULT 158 #define PROTO_R_SET_RETURN void 159 #undef PROTOENT_DATA 160 161 162 163 164 165 #define PASS_R_END_RESULT(x) /*empty*/ 166 #define PASS_R_END_RETURN void 167 #undef PASS_R_ENT_ARGS 168 169 170 #undef PASS_R_SET_RESULT /*empty*/ 171 #define PASS_R_SET_RETURN void 172 173 #define SERV_R_ARGS char *buf, int buflen 174 #define SERV_R_BAD NULL 175 #define SERV_R_COPY buf, buflen 176 #define SERV_R_COPY_ARGS SERV_R_ARGS 177 #define SERV_R_END_RESULT(x) /*empty*/ 178 #define SERV_R_END_RETURN void 179 #undef SERV_R_ENT_ARGS /*empty*/ 180 #undef SERV_R_ENT_UNUSED /*empty*/ 181 #define SERV_R_OK sptr 182 #undef SERV_R_SETANSWER 183 #define SERV_R_RETURN struct servent * 184 #undef SERV_R_SET_RESULT 185 #define SERV_R_SET_RETURN void 186 187 188 189 #define DE_CONST(konst, var) \ 190 do { \ 191 union { const void *k; void *v; } _u; \ 192 _u.k = konst; \ 193 var = _u.v; \ 194 } while (0) 195 196 #define UNUSED(x) (x) = (x) 197 198 #undef NEED_SOLARIS_BITTYPES 199 #define ISC_SOCKLEN_T socklen_t 200 201 #ifdef __GNUC__ 202 #define ISC_FORMAT_PRINTF(fmt, args) \ 203 __attribute__((__format__(__printf__, fmt, args))) 204 #else 205 #define ISC_FORMAT_PRINTF(fmt, args) 206 #endif 207 208 /* Pull in host order macros when _XOPEN_SOURCE_EXTENDED is defined. */ 209 #if defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED) 210 #include <sys/byteorder.h> 211 #endif 212 213 #endif 214 215 /*! \file */ -
src/add-ons/kernel/network/ppp/pap/Jamfile
diff --git a/src/add-ons/kernel/network/ppp/pap/Jamfile b/src/add-ons/kernel/network/ppp/pap/Jamfile index f1724c7..b224f74 100644
a b if $(TARGET_PLATFORM) != haiku { 9 9 } 10 10 11 11 # for kernel_cpp.h and BLocker 12 UseHeaders [ FDirName $(HAIKU_TOP) headers cpp ] : true ; 12 # UseHeaders [ FDirName $(HAIKU_TOP) headers cpp ] : true ; 13 UsePrivateKernelHeaders ; 14 #for arch_int.h 13 15 UsePrivateHeaders net ; 14 16 UsePrivateHeaders [ FDirName kernel ] ; 15 17 UsePrivateHeaders [ FDirName kernel util ] ; … … LinkAgainst pap : libkernelppp.a ; 31 33 32 34 # Installation 33 35 HaikuInstall install-networking 34 : /boot/home/config/add-ons/kernel/ obos_network/ppp36 : /boot/home/config/add-ons/kernel/haiku_network/ppp 35 37 : pap ; 36 38 37 39 Package haiku-networkingkit-cvs : 38 40 pap : 39 boot home config add-ons kernel obos_network ppp ;41 boot home config add-ons kernel haiku_network ppp ; -
src/add-ons/kernel/network/ppp/pap/Protocol.cpp
diff --git a/src/add-ons/kernel/network/ppp/pap/Protocol.cpp b/src/add-ons/kernel/network/ppp/pap/Protocol.cpp index 29d8760..9977d7b 100644
a b 9 9 10 10 #include <cstring> 11 11 #include <netinet/in.h> 12 #include <core_funcs.h>13 #include <sys/sockio.h>14 12 13 #include <net_buffer.h> 14 15 #include <sys/sockio.h> 15 16 17 // static net_buffer_module_info *gBufferModule = NULL; 16 18 static const bigtime_t kPAPTimeout = 3000000; 17 19 // 3 seconds 18 20 … … PAPHandler::PAPHandler(PAP& owner, KPPPInterface& interface) 33 35 { 34 36 } 35 37 38 status_t 39 PAPHandler::SendingAck(const KPPPConfigurePacket& ack) 40 { 41 TRACE("%s::%s: We should activate PAP Protocol here\n", __FILE__, __func__); 42 return KPPPOptionHandler::SendingAck(ack); 43 } 44 36 45 37 46 status_t 38 47 PAPHandler::AddToRequest(KPPPConfigurePacket& request) … … PAP::Down() 159 168 160 169 161 170 status_t 162 PAP::Send( struct mbuf*packet, uint16 protocolNumber)171 PAP::Send(net_buffer *packet, uint16 protocolNumber) 163 172 { 164 173 // we do not encapsulate PAP packets 165 m_freem(packet); 174 TRACE("PAP: we should not send packet!\n"); 175 if (packet != NULL) 176 gBufferModule->free(packet); 166 177 return B_ERROR; 167 178 } 168 179 169 180 170 181 status_t 171 PAP::Receive( struct mbuf*packet, uint16 protocolNumber)182 PAP::Receive(net_buffer *packet, uint16 protocolNumber) 172 183 { 173 184 if(!packet) 174 185 return B_ERROR; … … PAP::Receive(struct mbuf *packet, uint16 protocolNumber) 176 187 if(protocolNumber != PAP_PROTOCOL) 177 188 return PPP_UNHANDLED; 178 189 179 ppp_lcp_packet *data = mtod(packet, ppp_lcp_packet*); 190 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 191 if(bufferheader.Status()!=B_OK) 192 return B_ERROR; 193 ppp_lcp_packet &data = bufferheader.Data(); 180 194 181 195 // check if the packet is meant for us: 182 196 // only peer authenticators handle requests 183 if(data ->code == PPP_CONFIGURE_REQUEST && Side() != PPP_PEER_SIDE)197 if(data.code == PPP_CONFIGURE_REQUEST && Side() != PPP_PEER_SIDE) 184 198 return PPP_UNHANDLED; 185 199 // only local authenticators handle acks and naks 186 if((data ->code == PPP_CONFIGURE_ACK || data->code == PPP_CONFIGURE_NAK)200 if((data.code == PPP_CONFIGURE_ACK || data.code == PPP_CONFIGURE_NAK) 187 201 && Side() != PPP_LOCAL_SIDE) 188 202 return PPP_UNHANDLED; 189 203 190 204 // remove padding 191 int32 length = packet->m_len; 192 if(packet->m_flags & M_PKTHDR) 193 length = packet->m_pkthdr.len; 194 length -= ntohs(data->length); 195 if(length) 196 m_adj(packet, -length); 197 198 if(ntohs(data->length) < 4) 205 int32 length = packet->size; 206 length -= ntohs(data.length); 207 208 if(ntohs(data.length) < 4) 199 209 return B_ERROR; 200 210 201 211 // packet is freed by event methods 202 212 // code values are the same as for LCP (but very reduced) 203 switch(data ->code) {213 switch(data.code) { 204 214 case PPP_CONFIGURE_REQUEST: 205 215 RREvent(packet); 206 216 break; … … PAP::TOBadEvent() 320 330 321 331 322 332 void 323 PAP::RREvent( struct mbuf*packet)333 PAP::RREvent(net_buffer *packet) 324 334 { 325 335 TRACE("PAP: RREvent() state=%d\n", State()); 326 336 327 ppp_lcp_packet *request = mtod(packet, ppp_lcp_packet*); 328 int32 length = ntohs(request->length); 329 uint8 *data = request->data; 337 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 338 if(bufferheader.Status()!=B_OK) 339 return; 340 ppp_lcp_packet &request = bufferheader.Data(); 341 int32 length = ntohs(request.length); 342 uint8 *data = request.data; 330 343 uint8 *userLength = data; 331 344 uint8 *passwordLength = data + 1 + data[0]; 332 345 333 346 // make sure the length values are all okay 334 347 if(6 + *userLength + *passwordLength > length) { 335 m_freem(packet);348 gBufferModule->free(packet); 336 349 return; 337 350 } 338 351 … … PAP::RREvent(struct mbuf *packet) 357 370 358 371 359 372 void 360 PAP::RAEvent( struct mbuf*packet)373 PAP::RAEvent(net_buffer *packet) 361 374 { 362 375 TRACE("PAP: RAEvent() state=%d\n", State()); 363 376 364 if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { 377 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 378 if(bufferheader.Status()!=B_OK) 379 return; 380 ppp_lcp_packet &lcp_hdr = bufferheader.Data(); 381 if(fRequestID != lcp_hdr.id) { 365 382 // this packet is not a reply to our request 366 383 367 384 // TODO: log this event 368 m_freem(packet);385 gBufferModule->free(packet); 369 386 return; 370 387 } 371 388 … … PAP::RAEvent(struct mbuf *packet) 381 398 ; 382 399 } 383 400 384 m_freem(packet);401 gBufferModule->free(packet); 385 402 } 386 403 387 404 388 405 void 389 PAP::RNEvent( struct mbuf*packet)406 PAP::RNEvent(net_buffer *packet) 390 407 { 391 408 TRACE("PAP: RNEvent() state=%d\n", State()); 392 409 393 if(fRequestID != mtod(packet, ppp_lcp_packet*)->id) { 410 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 411 if(bufferheader.Status()!=B_OK) 412 return; 413 ppp_lcp_packet &lcp_hdr = bufferheader.Data(); 414 if(fRequestID != lcp_hdr.id) { 394 415 // this packet is not a reply to our request 395 416 396 417 // TODO: log this event 397 m_freem(packet);418 gBufferModule->free(packet); 398 419 return; 399 420 } 400 421 … … PAP::RNEvent(struct mbuf *packet) 410 431 ; 411 432 } 412 433 413 m_freem(packet);434 gBufferModule->free(packet); 414 435 } 415 436 416 437 … … PAP::SendRequest() 429 450 --fRequestCounter; 430 451 fNextTimeout = system_time() + kPAPTimeout; 431 452 432 struct mbuf *packet = m_gethdr(MT_DATA);453 net_buffer *packet = gBufferModule->create(256); 433 454 if(!packet) 434 455 return false; 435 456 457 ppp_lcp_packet *request; 458 gBufferModule->append_size(packet,1492,(void **)&request); 459 436 460 const char *username = Interface().Username(), *password = Interface().Password(); 461 uint16 pack_len = 6 + strlen(username) + strlen(password); 462 // 6 : lcp header 4 byte + username length 1 byte + password length 1 byte 437 463 438 packet->m_pkthdr.len = packet->m_len = 6 + strlen(username) + strlen(password);439 440 // reserve some space for overhead (we are lazy and reserve too much)441 packet->m_data += Interface().PacketOverhead();442 443 ppp_lcp_packet *request = mtod(packet, ppp_lcp_packet*);444 464 request->code = PPP_CONFIGURE_REQUEST; 445 465 request->id = fRequestID = NextID(); 446 request->length = htons(pack et->m_len);466 request->length = htons(pack_len); 447 467 uint8 *data = request->data; 448 468 data[0] = strlen(username); 449 469 memcpy(data + 1, username, strlen(username)); 450 470 data[1 + data[0]] = strlen(password); 451 471 memcpy(data + 2 + data[0], password, strlen(password)); 472 473 gBufferModule->trim(packet,pack_len); 452 474 453 475 return Interface().Send(packet, PAP_PROTOCOL) == B_OK; 454 476 } 455 477 456 478 457 479 bool 458 PAP::SendAck( struct mbuf*packet)480 PAP::SendAck(net_buffer *packet) 459 481 { 460 482 TRACE("PAP: SendAck() state=%d\n", State()); 461 483 462 484 if(!packet) 463 485 return false; 464 486 465 ppp_lcp_packet *ack = mtod(packet, ppp_lcp_packet*); 466 ack->code = PPP_CONFIGURE_ACK; 467 packet->m_len = 5; 468 if(packet->m_flags & M_PKTHDR) 469 packet->m_pkthdr.len = 5; 470 ack->length = htons(packet->m_len); 471 472 ack->data[0] = 0; 487 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 488 if(bufferheader.Status()!=B_OK) 489 return false; 490 ppp_lcp_packet &ack = bufferheader.Data(); 491 492 ack.code = PPP_CONFIGURE_ACK; 493 ack.length = htons(5); 494 ack.data[0] = 0; 495 gBufferModule->trim(packet,5); 496 497 bufferheader.Sync(); 473 498 474 499 return Interface().Send(packet, PAP_PROTOCOL) == B_OK; 475 500 } 476 501 477 502 478 503 bool 479 PAP::SendNak( struct mbuf*packet)504 PAP::SendNak(net_buffer *packet) 480 505 { 481 TRACE("PAP: SendNak() state=%d\n", State());506 ERROR("PAP: SendNak() state=%d\n", State()); 482 507 483 508 if(!packet) 484 509 return false; 485 510 486 ppp_lcp_packet *nak = mtod(packet, ppp_lcp_packet*);487 nak->code = PPP_CONFIGURE_NAK;488 packet->m_len = 5;489 if(packet->m_flags & M_PKTHDR)490 packet->m_pkthdr.len = 5;491 nak ->length = htons(packet->m_len);492 493 nak->data[0] = 0;511 NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet); 512 if(bufferheader.Status()!=B_OK) 513 return false; 514 ppp_lcp_packet &nak = bufferheader.Data(); 515 nak.code = PPP_CONFIGURE_NAK; 516 nak.length = htons(5); 517 nak.data[0] = 0; 518 gBufferModule->trim(packet,5); 494 519 495 520 return Interface().Send(packet, PAP_PROTOCOL) == B_OK; 496 521 } -
src/add-ons/kernel/network/ppp/pap/Protocol.h
diff --git a/src/add-ons/kernel/network/ppp/pap/Protocol.h b/src/add-ons/kernel/network/ppp/pap/Protocol.h index 43a1bc7..e1546eb 100644
a b class PAPHandler : public KPPPOptionHandler { 36 36 { return fOwner; } 37 37 38 38 virtual status_t AddToRequest(KPPPConfigurePacket& request); 39 virtual status_t SendingAck(const KPPPConfigurePacket&); 39 40 virtual status_t ParseRequest(const KPPPConfigurePacket& request, 40 41 int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject); 41 42 … … class PAP : public KPPPProtocol { 57 58 virtual bool Up(); 58 59 virtual bool Down(); 59 60 60 virtual status_t Send( struct mbuf*packet, uint16 protocolNumber);61 virtual status_t Receive( struct mbuf*packet, uint16 protocolNumber);61 virtual status_t Send(net_buffer *packet, uint16 protocolNumber); 62 virtual status_t Receive(net_buffer *packet, uint16 protocolNumber); 62 63 virtual void Pulse(); 63 64 64 65 private: … … class PAP : public KPPPProtocol { 70 71 // events 71 72 void TOGoodEvent(); 72 73 void TOBadEvent(); 73 void RREvent( struct mbuf*packet);74 void RAEvent( struct mbuf*packet);75 void RNEvent( struct mbuf*packet);74 void RREvent(net_buffer *packet); 75 void RAEvent(net_buffer *packet); 76 void RNEvent(net_buffer *packet); 76 77 77 78 // actions 78 79 void ReportUpFailedEvent(); … … class PAP : public KPPPProtocol { 80 81 void ReportDownEvent(); 81 82 void InitializeRestartCount(); 82 83 bool SendRequest(); 83 bool SendAck( struct mbuf*packet);84 bool SendNak( struct mbuf*packet);84 bool SendAck(net_buffer *packet); 85 bool SendNak(net_buffer *packet); 85 86 86 87 private: 87 88 // for state machine -
src/add-ons/kernel/network/ppp/pap/pap.cpp
diff --git a/src/add-ons/kernel/network/ppp/pap/pap.cpp b/src/add-ons/kernel/network/ppp/pap/pap.cpp index 5805238..f32e30c 100644
a b 5 5 6 6 #include <KernelExport.h> 7 7 #include <driver_settings.h> 8 #include <core_funcs.h> 9 #include <net_module.h> 8 9 #include <net_stack.h> 10 #include <net_buffer.h> 10 11 11 12 #include <KPPPInterface.h> 12 13 #include <KPPPModule.h> 13 14 14 15 #include "Protocol.h" 15 16 17 #define PAP_MODULE_NAME NETWORK_MODULES_ROOT "/ppp/pap" 16 18 17 #define PAP_MODULE_NAME NETWORK_MODULES_ROOT "ppp/pap" 18 19 struct core_module_info *core = NULL; 19 net_stack_module_info *gStackModule = NULL; 20 net_buffer_module_info *gBufferModule = NULL; 20 21 status_t std_ops(int32 op, ...); 21 22 22 23 static 24 bool 23 static bool 25 24 add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface, 26 25 driver_parameter *settings, ppp_module_key_type type) 27 26 { … … std_ops(int32 op, ...) 62 61 { 63 62 switch(op) { 64 63 case B_MODULE_INIT: 65 if(get_module(NET_CORE_MODULE_NAME, (module_info**) &core) != B_OK) 64 if(get_module(NET_STACK_MODULE_NAME, (module_info**) &gStackModule) != B_OK) 65 return B_ERROR; 66 if(get_module(NET_BUFFER_MODULE_NAME, 67 (module_info **)&gBufferModule) != B_OK) { 68 put_module(NET_STACK_MODULE_NAME); 66 69 return B_ERROR; 70 } 67 71 return B_OK; 68 72 69 73 case B_MODULE_UNINIT: 70 put_module(NET_CORE_MODULE_NAME); 74 put_module(NET_BUFFER_MODULE_NAME); 75 put_module(NET_STACK_MODULE_NAME); 71 76 break; 72 77 73 78 default: -
new file src/add-ons/kernel/network/ppp/ppp/Jamfile
diff --git a/src/add-ons/kernel/network/ppp/ppp/Jamfile b/src/add-ons/kernel/network/ppp/ppp/Jamfile new file mode 100644 index 0000000..a95e8a9
- + 1 SubDir HAIKU_TOP src add-ons kernel network ppp ppp ; 2 3 SetSubDirSupportedPlatformsBeOSCompatible ; 4 5 if $(TARGET_PLATFORM) != haiku { 6 UseHeaders [ FStandardOSHeaders ] : true ; 7 # Needed for <support/Errors.h> and maybe other stuff. 8 UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ; 9 # We need the public network headers also when not compiling for Haiku. 10 # Unfortunately we get more than we want, namely all POSIX headers. 11 } 12 13 UsePrivateKernelHeaders ; 14 UsePrivateHeaders net ; 15 UsePrivateHeaders [ FDirName kernel ] ; 16 UsePrivateHeaders [ FDirName kernel util ] ; 17 18 UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared 19 libkernelppp headers ] : true ; 20 21 22 { 23 SubDirC++Flags -fno-rtti ; 24 } 25 26 27 KernelAddon ppp : 28 ppp.cpp 29 ; 30 31 # Installation 32 HaikuInstall install-networking : /boot/home/config/add-ons/kernel/haiku_network/ppp 33 : ppp ; 34 35 Package haiku-networkingkit-cvs : 36 haiku : 37 boot home config add-ons kernel haiku_network ppp ; 38 -
new file src/add-ons/kernel/network/ppp/ppp/ppp.cpp
diff --git a/src/add-ons/kernel/network/ppp/ppp/ppp.cpp b/src/add-ons/kernel/network/ppp/ppp/ppp.cpp new file mode 100644 index 0000000..284d626
- + 1 /* 2 * Copyright 2006-2009, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include <ethernet.h> 11 #include <ether_driver.h> 12 #include <net_datalink_protocol.h> 13 #include <net_buffer.h> 14 #include <net_device.h> 15 #include <net_stack.h> 16 #include <NetBufferUtilities.h> 17 18 #include <lock.h> 19 #include <util/AutoLock.h> 20 #include <util/DoublyLinkedList.h> 21 22 #include <KernelExport.h> 23 24 #include <errno.h> 25 #include <ByteOrder.h> 26 #include <net/if.h> 27 #include <net/if_dl.h> 28 #include <net/if_media.h> 29 #include <net/if_types.h> 30 #include <new> 31 #include <stdlib.h> 32 #include <string.h> 33 34 #include <KPPPInterface.h> 35 #include <KPPPManager.h> 36 37 #include <ppp_device.h> 38 39 #define PPP_HEADER_LENGTH (8+ETHER_HEADER_LENGTH) 40 41 42 net_buffer* create_buffer_for_frame(uint8 *frame, uint16 frame_size); 43 44 static const bigtime_t kLinkCheckInterval = 1000000; 45 // 1 second 46 // static ppp_device * s_ppp_dev= NULL; 47 48 net_buffer_module_info *gBufferModule; 49 ppp_interface_module_info* gPPPInterfaceModule; 50 // net_device_module_info *sEthernetModule; 51 static net_stack_module_info *sStackModule; 52 53 static mutex sListLock; 54 static DoublyLinkedList<ppp_device> sCheckList; 55 static sem_id sLinkChangeSemaphore; 56 static thread_id sLinkCheckerThread; 57 58 59 60 // #pragma mark - 61 // 62 63 status_t 64 ppp_init(const char *name, net_device **_device) 65 { 66 // ppp device 67 dprintf("%s::%s: entering!\n",__FILE__,__func__); 68 if (strncmp(name, "ppp", 3)) { 69 dprintf("[%s] not ppp device\n",name); 70 return B_BAD_VALUE; 71 }else{ 72 dprintf("[%s] is ppp device\n",name); 73 } 74 75 status_t status = get_module(NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule); 76 if (status < B_OK) 77 return status; 78 79 // ppp_device *device = new (std::nothrow) ppp_device; 80 ppp_interface_id interface_id = gPPPInterfaceModule->CreateInterfaceWithName(name,0); 81 KPPPInterface * ppp_interface = gPPPInterfaceModule->GetInterface(interface_id); 82 83 if (interface_id <= 0 || ppp_interface==NULL) { 84 if(interface_id<=0) 85 dprintf("%s::%s: interface_id:%ld\n",__FILE__,__func__,interface_id); 86 else 87 dprintf("%s::%s: ppp_interface==NULL %ld\n",__FILE__,__func__,interface_id); 88 put_module(NET_BUFFER_MODULE_NAME); 89 return B_NO_MEMORY; 90 } 91 92 // Ifnet available until interface up phase 93 ppp_device *device = (ppp_device *)ppp_interface->Ifnet(); 94 if (device==NULL) { 95 dprintf("%s::%s: can not get ppp_device\n",__FILE__,__func__); 96 put_module(NET_BUFFER_MODULE_NAME); 97 return B_NO_MEMORY; 98 } 99 100 strcpy(device->name, name); 101 device->flags = (IFF_BROADCAST | IFF_LINK) & (~IFF_UP); 102 device->type = IFT_PPP; 103 device->mtu = 1492; 104 device->frame_size = 1500; 105 device->media = IFM_ACTIVE | IFM_ETHER; 106 device->header_length = PPP_HEADER_LENGTH; 107 108 status =sStackModule->init_fifo(&(device->ppp_fifo), "ppp_fifo", 10*1500); //10 ppp at most 109 if (status < B_OK){ 110 dprintf("sorry! can not init ppp_fifo\n"); 111 return(status); 112 } 113 114 TRACE("[%s] finish\n", "allocate ppp_device"); 115 *_device = device; 116 117 return B_OK; 118 } 119 120 121 status_t 122 ppp_uninit(net_device *device) 123 { 124 dprintf("%s::%s: uninit ppp\n",__FILE__,__func__); 125 ppp_device *ppp_dev=(ppp_device *)device; 126 127 sStackModule->uninit_fifo(&(ppp_dev->ppp_fifo)); 128 put_module(NET_BUFFER_MODULE_NAME); 129 130 // delete ppp_dev->KPPP_Interface; 131 delete ppp_dev; 132 133 return B_OK; 134 } 135 136 status_t 137 ppp_up(net_device *_device) 138 { 139 ppp_device *device = (ppp_device *)_device; 140 141 if (device->KPPP_Interface == NULL) { 142 dprintf("%s::%s: warning! can not find pppinterface KPPP_Interface\n",__FILE__,__func__); 143 return B_ERROR; 144 } 145 146 if(device->KPPP_Interface->Up() != true) 147 { 148 dprintf("%s::%s: warning! KPPP_Interface->Up() failure\n",__FILE__,__func__); 149 return B_ERROR; 150 } 151 152 device->mtu = device->frame_size - device->header_length; 153 // s_pppoe_dev=device; 154 155 dprintf("%s::%s: congratulations! Find pppinterface (device->KPPP_Interface)\n",__FILE__,__func__); 156 157 return B_OK; 158 } 159 160 161 void 162 ppp_down(net_device *_device) 163 { 164 dprintf("%s::%s: set ppp down\n",__FILE__,__func__); 165 ppp_device *device = (ppp_device *)_device; 166 device->KPPP_Interface->Down(); 167 168 MutexLocker _(sListLock); 169 170 // if the device is still part of the list, remove it 171 if (device->GetDoublyLinkedListLink()->next != NULL 172 || device->GetDoublyLinkedListLink()->previous != NULL 173 || device == sCheckList.Head()) 174 sCheckList.Remove(device); 175 176 // device->KPPP_Interface=NULL; 177 178 return; 179 } 180 181 182 status_t 183 ppp_control(net_device *_device, int32 op, void *argument, 184 size_t length) 185 { 186 TRACE("%s::%s: ppp control\n",__FILE__,__func__); 187 ppp_device *device = (ppp_device *)_device; 188 189 if (device->KPPP_Interface != NULL){ 190 dprintf("ppp's KPPP_Interface is found \n"); 191 return B_OK; 192 } else { 193 dprintf("%s::%s: can not find KPPP_Interface for ppp\n",__FILE__,__func__); 194 return B_OK; 195 } 196 197 device->KPPP_Interface->Control(op,argument,length); 198 199 return B_OK; 200 } 201 202 status_t 203 ppp_send_data(net_device *_device, net_buffer *buffer) 204 { 205 TRACE("%s::%s: ppp send data\n",__FILE__,__func__); 206 ppp_device *device = (ppp_device *)_device; 207 208 if (buffer->size > device->frame_size || buffer->size < device->header_length){ 209 device->stats.send.errors++; 210 dprintf("sorry! we can't send out the ppp packet,size wrong!\n"); 211 return B_BAD_VALUE; 212 } 213 214 if (device->KPPP_Interface==NULL) { 215 device->stats.send.errors++; 216 dprintf("sorry! we can't send out the ppp packet,no eth for ppp!\n"); 217 return B_BAD_VALUE; 218 } 219 220 device->KPPP_Interface->Send(buffer,0x0021); //IP_PROTOCOL 0x0021 221 // set the size for ppp payload length 222 // uint16 ip_frame_size=buffer->size; 223 224 return B_OK; 225 } 226 227 status_t 228 ppp_receive_data(net_device *_device, net_buffer **_buffer) 229 { 230 TRACE("%s::%s: receive data\n",__FILE__,__func__); 231 ppp_device *device = (ppp_device *)_device; 232 233 if (device->KPPP_Interface == NULL) 234 return B_FILE_ERROR; 235 236 TRACE("%s::%s: trying fifo_dequeue_buffer\n",__FILE__,__func__); 237 status_t status = sStackModule->fifo_dequeue_buffer(&(device->ppp_fifo), 0, 10000000, _buffer); 238 239 if (status < B_OK) { 240 TRACE("sorry! can not fifo_dequeue_buffer!\n"); 241 return status; 242 } 243 244 // (*_buffer)->interface_address = NULL; // strange need to put here 245 device->stats.receive.bytes += (*_buffer)->size; 246 device->stats.receive.packets++; 247 248 return B_OK; 249 } 250 251 252 status_t 253 ppp_set_mtu(net_device *_device, size_t mtu) 254 { 255 ppp_device *device = (ppp_device *)_device; 256 257 if (mtu > device->frame_size - ETHER_HEADER_LENGTH - 8 258 || mtu <= ETHER_HEADER_LENGTH + 8 + 10) 259 return B_BAD_VALUE; 260 261 device->mtu = mtu; 262 return B_OK; 263 } 264 265 266 status_t 267 ppp_set_promiscuous(net_device *_device, bool promiscuous) 268 { 269 return B_NOT_SUPPORTED; 270 } 271 272 273 status_t 274 ppp_set_media(net_device *device, uint32 media) 275 { 276 return B_NOT_SUPPORTED; 277 } 278 279 280 status_t 281 ppp_add_multicast(struct net_device *_device, const sockaddr *_address) 282 { 283 // ppp_device *device = (ppp_device *)_device; 284 285 if (_address->sa_family != AF_LINK) 286 return B_BAD_VALUE; 287 288 const sockaddr_dl *address = (const sockaddr_dl *)_address; 289 if (address->sdl_type != IFT_ETHER) 290 return B_BAD_VALUE; 291 292 return B_NOT_SUPPORTED; 293 } 294 295 296 status_t 297 ppp_remove_multicast(struct net_device *_device, const sockaddr *_address) 298 { 299 // ppp_device *device = (ppp_device *)_device; 300 301 if (_address->sa_family != AF_LINK) 302 return B_BAD_VALUE; 303 304 const sockaddr_dl *address = (const sockaddr_dl *)_address; 305 if (address->sdl_type != IFT_ETHER) 306 return B_BAD_VALUE; 307 308 return B_NOT_SUPPORTED; 309 } 310 311 312 static status_t 313 ppp_std_ops(int32 op, ...) 314 { 315 switch (op) { 316 case B_MODULE_INIT: 317 { 318 status_t status = get_module(NET_STACK_MODULE_NAME, 319 (module_info **)&sStackModule); 320 if (status < B_OK) 321 return status; 322 323 status = get_module(PPP_INTERFACE_MODULE_NAME, 324 (module_info**)&gPPPInterfaceModule); 325 if (status < B_OK){ 326 dprintf("%s::%s: can not get %s module\n",__FILE__,__func__,PPP_INTERFACE_MODULE_NAME); 327 return status; 328 } 329 330 new (&sCheckList) DoublyLinkedList<ppp_device>; 331 // static C++ objects are not initialized in the module startup 332 333 sLinkCheckerThread = -1; 334 335 sLinkChangeSemaphore = create_sem(0, "ppp link change"); 336 if (sLinkChangeSemaphore < B_OK) { 337 put_module(NET_STACK_MODULE_NAME); 338 put_module(PPP_INTERFACE_MODULE_NAME); 339 return sLinkChangeSemaphore; 340 } 341 342 mutex_init(&sListLock, "ppp devices"); 343 344 return B_OK; 345 } 346 347 case B_MODULE_UNINIT: 348 { 349 delete_sem(sLinkChangeSemaphore); 350 351 status_t status; 352 wait_for_thread(sLinkCheckerThread, &status); 353 354 mutex_destroy(&sListLock); 355 // put_module("network/devices/ethernet/v1"); 356 put_module(PPP_INTERFACE_MODULE_NAME); 357 put_module(NET_STACK_MODULE_NAME); 358 return B_OK; 359 } 360 361 default: 362 return B_ERROR; 363 } 364 } 365 366 367 net_device_module_info spppModule = { 368 { 369 "network/devices/ppp/v1", 370 0, 371 ppp_std_ops 372 }, 373 ppp_init, 374 ppp_uninit, 375 ppp_up, 376 ppp_down, 377 ppp_control, 378 ppp_send_data, 379 ppp_receive_data, 380 ppp_set_mtu, 381 ppp_set_promiscuous, 382 ppp_set_media, 383 ppp_add_multicast, 384 ppp_remove_multicast, 385 }; 386 387 module_info *modules[] = { 388 (module_info *)&spppModule, 389 NULL 390 }; -
new file src/add-ons/kernel/network/ppp/ppp_frame/Jamfile
diff --git a/src/add-ons/kernel/network/ppp/ppp_frame/Jamfile b/src/add-ons/kernel/network/ppp/ppp_frame/Jamfile new file mode 100644 index 0000000..19325ec
- + 1 SubDir HAIKU_TOP src add-ons kernel network ppp ppp_frame ; 2 3 SetSubDirSupportedPlatformsBeOSCompatible ; 4 5 if $(TARGET_PLATFORM) != haiku { 6 UseHeaders [ FStandardOSHeaders ] : true ; 7 # Needed for <support/Errors.h> and maybe other stuff. 8 UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ; 9 # We need the public network headers also when not compiling for Haiku. 10 # Unfortunately we get more than we want, namely all POSIX headers. 11 } 12 13 UsePrivateKernelHeaders ; 14 UsePrivateHeaders kernel net ; 15 UsePrivateHeaders [ FDirName kernel ] ; 16 UsePrivateHeaders [ FDirName kernel util ] ; 17 18 UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared 19 libkernelppp headers ] : true ; 20 21 22 { 23 SubDirC++Flags -fno-rtti ; 24 } 25 26 27 KernelAddon ppp_frame : 28 ppp_frame.cpp 29 ; 30 31 # Installation 32 HaikuInstall install-networking : /boot/home/config/add-ons/kernel/haiku_network/ppp 33 : ppp_frame ; 34 35 Package haiku-networkingkit-cvs : 36 haiku : 37 boot home config add-ons kernel haiku_network ppp ; 38 39 SEARCH on [ FGristFiles kernel_cpp.cpp ] 40 = [ FDirName $(HAIKU_TOP) src system kernel util ] ; -
new file src/add-ons/kernel/network/ppp/ppp_frame/ppp_frame.cpp
diff --git a/src/add-ons/kernel/network/ppp/ppp_frame/ppp_frame.cpp b/src/add-ons/kernel/network/ppp/ppp_frame/ppp_frame.cpp new file mode 100644 index 0000000..333af83
- + 1 /* 2 * Copyright 2006-2010, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include <ethernet.h> 11 #include <net_datalink_protocol.h> 12 #include <net_device.h> 13 #include <net_datalink.h> 14 #include <net_stack.h> 15 #include <NetBufferUtilities.h> 16 17 #include <ByteOrder.h> 18 #include <KernelExport.h> 19 20 #include <lock.h> 21 // #include <util/AutoLock.h> 22 #include <util/DoublyLinkedList.h> 23 24 25 #include <net/if.h> 26 #include <net/if_types.h> 27 #include <net/if_dl.h> 28 #include <new> 29 #include <string.h> 30 31 #include <KPPPManager.h> 32 #include <KPPPInterface.h> 33 #include <PPPControl.h> 34 35 36 #define TRACE_PPPoED 37 // #define TRACE(x) dprintf(x) 38 39 struct ppp_device : net_device, DoublyLinkedListLinkImpl<ppp_device> { 40 KPPPInterface * KPPP_Interface; 41 uint32 frame_size; 42 }; 43 44 struct ppp_frame_protocol : net_datalink_protocol { 45 }; 46 47 struct net_buffer_module_info* gBufferModule; 48 struct ppp_interface_module_info* gPPPInterfaceModule; 49 static struct net_interface* sinterface; 50 51 status_t 52 ppp_deframe(net_device* device, net_buffer* buffer) 53 { 54 // dprintf("%s::%s: I am deframeing pppoe frame\n",__FILE__,__FUNCTION__); 55 return B_OK; 56 } 57 58 // #pragma mark - 59 60 status_t 61 ppp_frame_init(struct net_interface* interface, net_domain* domain, 62 net_datalink_protocol** _protocol) 63 { 64 // We only support a single type! 65 dprintf("in function: %s::%s\n",__FILE__,__func__); 66 if (interface->device->type != IFT_PPP) 67 return B_BAD_TYPE; 68 69 ppp_frame_protocol* protocol; 70 71 net_stack_module_info* stack; 72 status_t status = get_module(NET_STACK_MODULE_NAME, (module_info**)&stack); 73 if (status != B_OK) 74 return status; 75 76 status = stack->register_device_deframer(interface->device, 77 &ppp_deframe); 78 if (status != B_OK) 79 goto err1; 80 81 status = stack->register_domain_device_handler( 82 interface->device, B_NET_FRAME_TYPE(IFT_ETHER, ETHER_TYPE_PPPOE), domain); 83 if (status != B_OK) 84 goto err1; 85 86 status = stack->register_domain_device_handler( 87 interface->device, B_NET_FRAME_TYPE_IPV4, domain); 88 if (status != B_OK) 89 goto err1; 90 91 sinterface = interface; 92 93 // Locally received buffers don't need a domain device handler, as the 94 // buffer reception is handled internally. 95 96 protocol = new(std::nothrow) ppp_frame_protocol; 97 if (protocol == NULL) { 98 status = B_NO_MEMORY; 99 goto err2; 100 } 101 102 put_module(NET_STACK_MODULE_NAME); 103 104 *_protocol = protocol; 105 return B_OK; 106 107 err2: 108 stack->unregister_device_deframer(interface->device); 109 err1: 110 put_module(NET_STACK_MODULE_NAME); 111 return status; 112 } 113 114 115 status_t 116 ppp_frame_uninit(net_datalink_protocol* protocol) 117 { 118 net_stack_module_info* stack; 119 if (get_module(NET_STACK_MODULE_NAME, (module_info**)&stack) == B_OK) { 120 stack->unregister_device_deframer(protocol->interface->device); 121 stack->unregister_device_handler(protocol->interface->device, 0); 122 put_module(NET_STACK_MODULE_NAME); 123 } 124 125 delete protocol; 126 dprintf("in function: %s\n",__func__); 127 return B_OK; 128 } 129 130 131 status_t 132 ppp_frame_send_data(net_datalink_protocol* protocol, net_buffer* buffer) 133 { 134 TRACE("%s::%s: next module is %s\n",__FILE__,__func__,protocol->next->module->info.name); 135 return protocol->next->module->send_data(protocol->next, buffer); 136 } 137 138 139 status_t 140 ppp_frame_up(net_datalink_protocol* protocol) 141 { 142 TRACE("in function: %s\n",__func__); 143 net_stack_module_info* stack; 144 status_t status = get_module(NET_STACK_MODULE_NAME, (module_info**)&stack); 145 if (status != B_OK) 146 return status; 147 148 status = stack->register_device_deframer(sinterface->device, 149 &ppp_deframe); 150 if (status != B_OK) 151 dprintf("%s::%s: can not register_device_deframer for pppoe\n",__FILE__,__func__); 152 153 put_module(NET_STACK_MODULE_NAME); 154 155 return protocol->next->module->interface_up(protocol->next); 156 } 157 158 159 void 160 ppp_frame_down(net_datalink_protocol* protocol) 161 { 162 TRACE("%s::%s: entry\n", __FILE__, __func__); 163 protocol->next->module->interface_down(protocol->next); 164 return; 165 } 166 167 168 status_t 169 ppp_frame_change_address(net_datalink_protocol* protocol, 170 net_interface_address* address, int32 option, 171 const struct sockaddr* oldAddress, const struct sockaddr* newAddress) 172 { 173 TRACE("in function: %s::%s\n", __FILE__, __func__); 174 return protocol->next->module->change_address(protocol->next, address, 175 option, oldAddress, newAddress); 176 } 177 178 179 static status_t 180 PPP_module_control(int32 option, void* argument, size_t length) 181 { 182 // control_net_module_args* args=(control_net_module_args*)argument; 183 184 if(option < PPPC_CONTROL_MODULE || option > PPP_CONTROL_OPS_END) 185 return B_ERROR; 186 187 // if(args->name != PPP_INTERFACE_MODULE_NAME) 188 // return B_ERROR; 189 190 switch(option) 191 { 192 case PPPC_CREATE_INTERFACE: 193 // process_CreateInterface(args->data, args->length); 194 case PPPC_CREATE_INTERFACE_WITH_NAME: 195 case PPPC_DELETE_INTERFACE: 196 case PPPC_BRING_INTERFACE_UP: 197 case PPPC_BRING_INTERFACE_DOWN: 198 case PPPC_CONTROL_INTERFACE: 199 case PPPC_GET_INTERFACES: 200 case PPPC_COUNT_INTERFACES: 201 case PPPC_FIND_INTERFACE_WITH_SETTINGS: 202 203 // interface control 204 case PPPC_GET_INTERFACE_INFO: 205 case PPPC_SET_USERNAME: 206 case PPPC_SET_PASSWORD: 207 case PPPC_SET_ASK_BEFORE_CONNECTING: 208 // ppp_up uses this in order to finalize a connection request 209 case PPPC_SET_MRU: 210 case PPPC_SET_CONNECT_ON_DEMAND: 211 case PPPC_SET_AUTO_RECONNECT: 212 case PPPC_HAS_INTERFACE_SETTINGS: 213 case PPPC_GET_STATISTICS: 214 // handler access 215 case PPPC_CONTROL_DEVICE: 216 case PPPC_CONTROL_PROTOCOL: 217 case PPPC_CONTROL_OPTION_HANDLER: 218 case PPPC_CONTROL_LCP_EXTENSION: 219 case PPPC_CONTROL_CHILD: 220 // KPPPDevice 221 case PPPC_GET_DEVICE_INFO: 222 // KPPPProtocol 223 case PPPC_GET_PROTOCOL_INFO: 224 // Common/mixed ops 225 case PPPC_ENABLE: 226 case PPPC_GET_SIMPLE_HANDLER_INFO: 227 228 // these two control ops use the ppp_report_request structure 229 case PPPC_ENABLE_REPORTS: 230 case PPPC_DISABLE_REPORTS: 231 232 case PPP_CONTROL_OPS_END: 233 case PPPC_CONTROL_MODULE: 234 default: 235 return B_ERROR; 236 } 237 238 239 } 240 241 static status_t 242 ppp_frame_control(net_datalink_protocol* protocol, int32 option, 243 void* argument, size_t length) 244 { 245 TRACE("in function: %s\n",__func__); 246 247 if(option >= PPPC_CONTROL_MODULE && option <=PPP_CONTROL_OPS_END) 248 { 249 status_t status =PPP_module_control(option,argument,length); 250 // gPPPInterfaceModule->ControlInterface(1, option, argument, length); 251 return(status); 252 } 253 254 return protocol->next->module->control(protocol->next, option, argument, 255 length); 256 } 257 258 259 static status_t 260 ppp_frame_join_multicast(net_datalink_protocol* protocol, 261 const sockaddr* address) 262 { 263 TRACE("in function: %s\n",__func__); 264 return protocol->next->module->join_multicast(protocol->next, address); 265 } 266 267 268 static status_t 269 ppp_frame_leave_multicast(net_datalink_protocol* protocol, 270 const sockaddr* address) 271 { 272 TRACE("in function: %s\n",__func__); 273 return protocol->next->module->leave_multicast(protocol->next, address); 274 } 275 276 277 static status_t 278 pppoe_frame_std_ops(int32 op, ...) 279 { 280 switch (op) { 281 case B_MODULE_INIT: 282 get_module(PPP_INTERFACE_MODULE_NAME, 283 (module_info**)&gPPPInterfaceModule); 284 return get_module(NET_BUFFER_MODULE_NAME, 285 (module_info**)&gBufferModule); 286 287 case B_MODULE_UNINIT: 288 put_module(NET_BUFFER_MODULE_NAME); 289 put_module(PPP_INTERFACE_MODULE_NAME); 290 return B_OK; 291 292 default: 293 return B_ERROR; 294 } 295 } 296 297 298 static net_datalink_protocol_module_info sPPPFrameModule = { 299 { 300 "network/datalink_protocols/ppp_frame/v1", 301 0, 302 pppoe_frame_std_ops 303 }, 304 ppp_frame_init, 305 ppp_frame_uninit, 306 ppp_frame_send_data, 307 ppp_frame_up, 308 ppp_frame_down, 309 ppp_frame_change_address, 310 ppp_frame_control, 311 ppp_frame_join_multicast, 312 ppp_frame_leave_multicast, 313 }; 314 315 module_info* modules[] = { 316 (module_info*)&sPPPFrameModule, 317 NULL 318 }; -
src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.cpp
diff --git a/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.cpp b/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.cpp index 3f7a227..d1449e5 100644
a b 5 5 6 6 #include "DiscoveryPacket.h" 7 7 8 #include <core_funcs.h> 9 8 #include <net_buffer.h> 9 #include <NetBufferUtilities.h> 10 #include <ByteOrder.h> 10 11 11 12 DiscoveryPacket::DiscoveryPacket(uint8 code, uint16 sessionID) 12 13 : fCode(code), … … DiscoveryPacket::DiscoveryPacket(uint8 code, uint16 sessionID) 16 17 } 17 18 18 19 19 DiscoveryPacket::DiscoveryPacket( struct mbuf*packet, uint32 start)20 DiscoveryPacket::DiscoveryPacket(net_buffer *packet, uint32 start) 20 21 { 21 22 // decode packet 22 uint8 *data = mtod(packet, uint8*); 23 data += start; 24 pppoe_header *header = (pppoe_header*) data; 23 NetBufferHeaderReader<pppoe_header> bufferheader(packet); 24 if(bufferheader.Status()!=B_OK) { 25 dprintf("NetBufferHeaderReader create fail\n"); 26 fInitStatus = B_ERROR; 27 return; 28 } 29 pppoe_header &header = bufferheader.Data(); 25 30 26 SetCode(header ->code);31 SetCode(header.code); 27 32 28 uint16 length = ntohs(header ->length);33 uint16 length = ntohs(header.length); 29 34 30 if(length > packet->m_len - PPPoE_HEADER_SIZE - start) { 35 if(length > packet->size - PPPoE_HEADER_SIZE) { 36 dprintf("packet size less than pppoe payload\n"); 37 dprintf("pppoe payload:%d\n",length); 38 dprintf("PPPoE_HEADER_SIZE:%d\n",PPPoE_HEADER_SIZE); 39 dprintf("packet->size:%ld\n",packet->size); 31 40 fInitStatus = B_ERROR; 32 41 return; 33 42 // there are no tags (or one corrupted tag) … … DiscoveryPacket::DiscoveryPacket(struct mbuf *packet, uint32 start) 37 46 pppoe_tag *tag; 38 47 39 48 while(position <= length - 4) { 40 tag = (pppoe_tag*) (header ->data + position);49 tag = (pppoe_tag*) (header.data + position); 41 50 position += ntohs(tag->length) + 4; 42 51 43 52 AddTag(ntohs(tag->type), tag->data, ntohs(tag->length)); … … DiscoveryPacket::TagWithType(uint16 type) const 116 125 } 117 126 118 127 119 struct mbuf*128 net_buffer* 120 129 DiscoveryPacket::ToMbuf(uint32 MTU, uint32 reserve) 121 130 { 122 struct mbuf *packet = m_gethdr(MT_DATA); 123 packet->m_data += reserve; 124 125 pppoe_header *header = mtod(packet, pppoe_header*); 131 net_buffer *packet = gBufferModule->create(256); 132 if (packet==NULL){ 133 dprintf("create buffer failure\n"); 134 return NULL; 135 } 136 137 pppoe_header *header ; 138 status_t status = gBufferModule->append_size(packet,1492,(void **)&header); 139 if (status != B_OK){ 140 dprintf("append size failure\n"); 141 return NULL; 142 } 126 143 127 144 header->version = PPPoE_VERSION; 128 145 header->type = PPPoE_TYPE; … … DiscoveryPacket::ToMbuf(uint32 MTU, uint32 reserve) 137 154 138 155 // make sure we have enough space left 139 156 if(MTU - length < tag->length) { 140 m_freem(packet);157 gBufferModule->free(packet); 141 158 return NULL; 142 159 } 143 160 … … DiscoveryPacket::ToMbuf(uint32 MTU, uint32 reserve) 150 167 } 151 168 152 169 header->length = htons(length); 153 packet->m_pkthdr.len = packet->m_len = length + PPPoE_HEADER_SIZE; 154 170 status = gBufferModule->trim(packet,length + PPPoE_HEADER_SIZE); 171 if (status != B_OK){ 172 dprintf("trim buffer failure\n"); 173 return NULL; 174 } 175 155 176 return packet; 156 177 } -
src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.h
diff --git a/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.h b/src/add-ons/kernel/network/ppp/pppoe/DiscoveryPacket.h index 6c0416f..fbab7ec 100644
a b 10 10 11 11 #include <TemplateList.h> 12 12 13 #define ETHER_HDR_LEN 14 13 14 14 15 enum PPPoE_TAG_TYPE { 15 16 END_OF_LIST = 0x0000, … … typedef struct pppoe_tag { 37 38 uint16 type; 38 39 uint16 length; 39 40 uint8 data[0]; 40 } ;41 } pppoe_tag; 41 42 42 43 43 44 class DiscoveryPacket { 44 45 public: 45 46 DiscoveryPacket(uint8 code, uint16 sessionID = 0x0000); 46 DiscoveryPacket( struct mbuf*packet, uint32 start = 0);47 DiscoveryPacket(net_buffer *packet, uint32 start = 0); 47 48 ~DiscoveryPacket(); 48 49 49 50 status_t InitCheck() const … … class DiscoveryPacket { 66 67 pppoe_tag *TagAt(int32 index) const; 67 68 pppoe_tag *TagWithType(uint16 type) const; 68 69 69 struct mbuf*ToMbuf(uint32 MTU, uint32 reserve = ETHER_HDR_LEN);70 // the user is responsible for freeing the mbuf70 net_buffer *ToMbuf(uint32 MTU, uint32 reserve = ETHER_HDR_LEN); 71 // the user is responsible for freeing the net_buffer 71 72 72 73 private: 73 74 uint8 fCode; -
src/add-ons/kernel/network/ppp/pppoe/Jamfile
diff --git a/src/add-ons/kernel/network/ppp/pppoe/Jamfile b/src/add-ons/kernel/network/ppp/pppoe/Jamfile index 8f81a90..90ce728 100644
a b if $(TARGET_PLATFORM) != haiku { 9 9 } 10 10 11 11 # for kernel_cpp.h and BLocker 12 UseHeaders [ FDirName $(HAIKU_TOP) headers cpp ] : true ; 12 # UseHeaders [ FDirName $(HAIKU_TOP) headers cpp ] : true ; 13 14 UsePrivateKernelHeaders ; 13 15 UsePrivateHeaders net ; 14 16 UsePrivateHeaders [ FDirName kernel ] ; 15 17 UsePrivateHeaders [ FDirName kernel util ] ; … … LinkAgainst pppoe : libkernelppp.a ; 32 34 33 35 # Installation 34 36 HaikuInstall install-networking 35 : /boot/home/config/add-ons/kernel/ obos_network/ppp37 : /boot/home/config/add-ons/kernel/haiku_network/ppp 36 38 : pppoe ; 37 39 38 40 Package haiku-networkingkit-cvs : 39 41 pppoe : 40 boot home config add-ons kernel obos_network ppp ;42 boot home config add-ons kernel haiku_network ppp ; -
src/add-ons/kernel/network/ppp/pppoe/PPPoE.h
diff --git a/src/add-ons/kernel/network/ppp/pppoe/PPPoE.h b/src/add-ons/kernel/network/ppp/pppoe/PPPoE.h index 6bb9350..faa68b3 100644
a b 8 8 9 9 #include <SupportDefs.h> 10 10 #include <net/if.h> 11 #include <netinet/if_ether.h> 11 #include <ethernet.h> 12 #include <ether_driver.h> 13 #include <net_stack.h> 14 // #include <netinet/if_ether.h> 12 15 13 16 class PPPoEDevice; 14 17 … … typedef struct complete_pppoe_header { 60 63 61 64 62 65 // defined in pppoe.cpp 63 extern ifnet*FindPPPoEInterface(const char *name);66 extern net_device *FindPPPoEInterface(const char *name); 64 67 extern uint32 NewHostUniq(); 65 68 extern void add_device(PPPoEDevice *device); 66 69 extern void remove_device(PPPoEDevice *device); 67 70 68 71 #if DEBUG 69 72 // defined in PPPoEDevice.cpp 70 extern void dump_packet( struct mbuf*packet);73 extern void dump_packet(net_buffer *packet); 71 74 #endif // DEBUG 72 75 73 76 -
src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp
diff --git a/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp b/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.cpp index 70c49dd..fe265a0 100644
a b 5 5 6 6 #include "PPPoEDevice.h" 7 7 #include "DiscoveryPacket.h" 8 #include <ethernet.h> 9 #include <ether_driver.h> 10 11 #include <net_stack.h> 12 #include <ByteOrder.h> 13 #include <net/if_dl.h> 8 14 9 #include <core_funcs.h>10 15 #include <cstdlib> 11 16 12 17 // from libkernelppp 13 18 #include <settings_tools.h> 14 19 20 extern net_stack_module_info *gStackModule; 21 extern net_buffer_module_info *gBufferModule; 22 extern status_t 23 pppoe_input(void *cookie, net_device *_device, net_buffer *packet); 15 24 16 25 #if DEBUG 17 26 static char sDigits[] = "0123456789ABCDEF"; 18 27 void 19 dump_packet( struct mbuf*packet)28 dump_packet(net_buffer *packet) 20 29 { 21 30 if(!packet) 22 31 return; 23 32 24 uint8 *data = mtod(packet, uint8*); 33 BufferHeaderReader<uint8> bufferheader(packet); 34 if(bufferheader.Status() != B_OK) 35 return; 36 uint8 &buffer = bufferheader.Data(); 37 uint8 *data = &buffer; 25 38 uint8 buffer[33]; 26 39 uint8 bufferIndex = 0; 27 40 … … PPPoEDevice::PPPoEDevice(KPPPInterface& interface, driver_parameter *settings) 62 75 // we do not want to fail just because the other side requests PFC 63 76 64 77 memset(fPeer, 0xFF, sizeof(fPeer)); 78 memcpy(fEtherAddr,etheraddr,sizeof(fEtherAddr)); 79 65 80 SetMTU(1494); 66 81 // MTU size does not contain PPP header 67 82 83 if(!settings) 84 dprintf("%s::%s: settings is NULL\n",__FILE__,__func__); 85 68 86 // find ethernet device 69 const char *interfaceName = get_parameter_value(PPPoE_INTERFACE_KEY, settings);70 if(!interfaceName)71 return;72 87 finterfaceName = get_parameter_value(PPPoE_INTERFACE_KEY, settings); 88 TRACE("%s::%s: finterfaceName is %s\n",__FILE__,__func__, 89 finterfaceName ? finterfaceName : "NULL"); 90 73 91 fACName = get_parameter_value(PPPoE_AC_NAME_KEY, settings); 92 TRACE("fACName is %s\n",fACName ? fACName : "NULL"); 93 74 94 fServiceName = get_parameter_value(PPPoE_SERVICE_NAME_KEY, settings); 95 TRACE("fServiceName is %s\n", fServiceName ? fServiceName : "NULL"); 75 96 76 fEthernetIfnet = FindPPPoEInterface(interfaceName);97 // fEthernetIfnet = FindPPPoEInterface(interfaceName); 77 98 78 99 #if DEBUG 79 100 if(!fEthernetIfnet) 80 101 TRACE("PPPoEDevice::ctor: could not find ethernet interface\n"); 102 else 103 TRACE("%s::%s: Find Ethernet device",__FILE__,__func__); 81 104 #endif 82 105 } 83 106 … … PPPoEDevice::PPPoEDevice(KPPPInterface& interface, driver_parameter *settings) 85 108 status_t 86 109 PPPoEDevice::InitCheck() const 87 110 { 88 return EthernetIfnet() && EthernetIfnet()->output 89 && KPPPDevice::InitCheck() == B_OK ? B_OK : B_ERROR; 111 if(KPPPDevice::InitCheck() != B_OK) 112 dprintf("%s::%s: KPPPDevice::InitCheck() has error\n",__FILE__,__func__); 113 114 return KPPPDevice::InitCheck() == B_OK ? B_OK : B_ERROR; 90 115 } 91 116 92 117 … … PPPoEDevice::Up() 101 126 if(IsUp()) 102 127 return true; 103 128 129 fEthernetIfnet = FindPPPoEInterface(finterfaceName); 130 131 if(fEthernetIfnet == NULL){ 132 dprintf("%s::%s: fEthernetIfnet %s not found\n",__FILE__,__func__,finterfaceName); 133 return false; 134 } 135 136 memcpy(fEtherAddr, fEthernetIfnet->address.data, ETHER_ADDRESS_LENGTH); 137 dprintf("ppp's corresponding addr is %02x:%02x:%02x:%02x:%02x:%02x\n", 138 fEtherAddr[0],fEtherAddr[1],fEtherAddr[2], 139 fEtherAddr[3],fEtherAddr[4],fEtherAddr[5]); 140 141 if(fEthernetIfnet->module == NULL){ 142 dprintf("%s::%s: fEthernetIfnet->module not found\n",__FILE__,__func__); 143 return false; 144 } 145 104 146 add_device(this); 105 147 106 148 fState = INITIAL; … … PPPoEDevice::Up() 125 167 discovery.AddTag(END_OF_LIST, NULL, 0); 126 168 127 169 // set up PPP header 128 struct mbuf*packet = discovery.ToMbuf(MTU());170 net_buffer *packet = discovery.ToMbuf(MTU()); 129 171 if(!packet) 130 172 return false; 131 173 132 // create destination 133 struct ether_header *ethernetHeader; 134 struct sockaddr destination; 135 memset(&destination, 0, sizeof(destination)); 136 destination.sa_family = AF_UNSPEC; 137 // raw packet with ethernet header 138 ethernetHeader = (struct ether_header*) destination.sa_data; 139 ethernetHeader->ether_type = ETHERTYPE_PPPOEDISC; 140 memcpy(ethernetHeader->ether_dhost, fPeer, sizeof(fPeer)); 141 174 // create ether header 175 NetBufferPrepend<ether_header> ethernetHeader(packet); 176 if (ethernetHeader.Status() != B_OK) 177 return false; 178 ether_header &header = ethernetHeader.Data(); 179 180 memset(header.destination, 0xff, ETHER_ADDRESS_LENGTH); 181 memcpy(header.source, fEtherAddr, ETHER_ADDRESS_LENGTH); 182 header.type=htons(ETHER_TYPE_PPPOE_DISCOVERY); 183 ethernetHeader.Sync(); 184 // raw packet with ethernet header 185 142 186 // check if we are allowed to go up now (user intervention might disallow that) 143 187 if(fAttempts > 0 && !UpStarted()) { 144 188 fAttempts = 0; … … PPPoEDevice::Up() 151 195 fState = PADI_SENT; 152 196 // needed before sending, otherwise we might not get all packets 153 197 154 if(EthernetIfnet()->output(EthernetIfnet(), packet, &destination, NULL) != B_OK) { 198 status_t status = gStackModule->register_device_handler(fEthernetIfnet, 199 B_NET_FRAME_TYPE(IFT_ETHER, ETHER_TYPE_PPPOE_DISCOVERY), &pppoe_input, NULL); 200 if (status != B_OK) 201 return false; 202 203 status = gStackModule->register_device_handler(fEthernetIfnet, 204 B_NET_FRAME_TYPE(IFT_ETHER, ETHER_TYPE_PPPOE), &pppoe_input, NULL); 205 if (status != B_OK) 206 return false; 207 208 if(EthernetIfnet()->module->send_data(EthernetIfnet(), packet) != B_OK) { 155 209 fState = INITIAL; 156 210 fAttempts = 0; 157 211 ERROR("PPPoEDevice::Up(): EthernetIfnet()->output() failed!\n"); 158 212 return false; 159 213 } 160 214 215 dprintf("PPPoEDevice::Up(): EthernetIfnet()->output() success!\n"); 161 216 fNextTimeout = system_time() + PPPoE_TIMEOUT; 162 217 163 218 return true; … … PPPoEDevice::Down() 169 224 { 170 225 TRACE("PPPoEDevice: Down()\n"); 171 226 227 gStackModule->unregister_device_handler(fEthernetIfnet, 228 B_NET_FRAME_TYPE(IFT_ETHER, ETHER_TYPE_PPPOE_DISCOVERY)); 229 gStackModule->unregister_device_handler(fEthernetIfnet, 230 B_NET_FRAME_TYPE(IFT_ETHER, ETHER_TYPE_PPPOE)); 231 172 232 remove_device(this); 173 233 174 234 if(InitCheck() != B_OK) … … PPPoEDevice::Down() 191 251 DiscoveryPacket discovery(PADT, SessionID()); 192 252 discovery.AddTag(END_OF_LIST, NULL, 0); 193 253 194 struct mbuf*packet = discovery.ToMbuf(MTU());254 net_buffer *packet = discovery.ToMbuf(MTU()); 195 255 if(!packet) { 196 256 ERROR("PPPoEDevice::Down(): ToMbuf() failed; MTU=%ld\n", MTU()); 197 257 DownEvent(); … … PPPoEDevice::Down() 205 265 destination.sa_family = AF_UNSPEC; 206 266 // raw packet with ethernet header 207 267 ethernetHeader = (struct ether_header*) destination.sa_data; 208 ethernetHeader-> ether_type = ETHERTYPE_PPPOEDISC;209 memcpy(ethernetHeader-> ether_dhost, fPeer, sizeof(fPeer));268 ethernetHeader->type = ETHER_TYPE_PPPOE_DISCOVERY; 269 memcpy(ethernetHeader->destination, fPeer, sizeof(fPeer)); 210 270 211 271 // reset connection settings 212 272 memset(fPeer, 0xFF, sizeof(fPeer)); 213 273 214 EthernetIfnet()-> output(EthernetIfnet(), packet, &destination, NULL);274 EthernetIfnet()->module->send_data(EthernetIfnet(), packet); 215 275 DownEvent(); 216 276 217 277 return true; … … PPPoEDevice::CountOutputBytes() const 242 302 243 303 244 304 status_t 245 PPPoEDevice::Send( struct mbuf*packet, uint16 protocolNumber)305 PPPoEDevice::Send(net_buffer *packet, uint16 protocolNumber) 246 306 { 247 307 // Send() is only for PPP packets. PPPoE packets are sent directly to ethernet. 248 308 … … PPPoEDevice::Send(struct mbuf *packet, uint16 protocolNumber) 252 312 return B_ERROR; 253 313 else if(InitCheck() != B_OK || protocolNumber != 0) { 254 314 ERROR("PPPoEDevice::Send(): InitCheck() != B_OK!\n"); 255 m_freem(packet);315 gBufferModule->free(packet); 256 316 return B_ERROR; 257 317 } 258 318 259 319 if(!IsUp()) { 260 320 ERROR("PPPoEDevice::Send(): no connection!\n"); 261 m_freem(packet);321 gBufferModule->free(packet); 262 322 return PPP_NO_CONNECTION; 263 323 } 264 324 265 uint16 length = packet-> m_flags & M_PKTHDR ? packet->m_pkthdr.len : packet->m_len;325 uint16 length = packet->size; 266 326 267 327 // encapsulate packet into pppoe header 268 M_PREPEND(packet, PPPoE_HEADER_SIZE); 269 pppoe_header *header = mtod(packet, pppoe_header*); 270 header->version = PPPoE_VERSION; 271 header->type = PPPoE_TYPE; 272 header->code = 0x00; 273 header->sessionID = SessionID(); 274 header->length = htons(length); 275 276 // create destination 277 struct ether_header *ethernetHeader; 278 struct sockaddr destination; 279 memset(&destination, 0, sizeof(destination)); 280 destination.sa_family = AF_UNSPEC; 281 // raw packet with ethernet header 282 ethernetHeader = (struct ether_header*) destination.sa_data; 283 ethernetHeader->ether_type = ETHERTYPE_PPPOE; 284 memcpy(ethernetHeader->ether_dhost, fPeer, sizeof(fPeer)); 328 NetBufferPrepend<pppoe_header> bufferheader(packet); 329 if(bufferheader.Status() != B_OK) 330 return B_ERROR; 331 pppoe_header &header = bufferheader.Data(); 332 header.version = PPPoE_VERSION; 333 header.type = PPPoE_TYPE; 334 header.code = 0x00; 335 header.sessionID = SessionID(); 336 header.length = htons(length); 337 bufferheader.Sync(); 338 339 // create ether header 340 NetBufferPrepend<ether_header> ethernetHeader(packet); 341 if (ethernetHeader.Status() != B_OK) 342 return false; 343 ether_header ðheader = ethernetHeader.Data(); 344 345 memcpy(ethheader.destination, fPeer, ETHER_ADDRESS_LENGTH); 346 memcpy(ethheader.source, fEtherAddr, ETHER_ADDRESS_LENGTH); 347 ethheader.type=htons(ETHER_TYPE_PPPOE); 348 ethernetHeader.Sync(); 349 // raw packet with ethernet header 285 350 286 if(!packet || !mtod(packet, pppoe_header*))351 if(!packet) 287 352 ERROR("PPPoEDevice::Send(): packet is NULL!\n"); 288 353 289 if(EthernetIfnet()-> output(EthernetIfnet(), packet, &destination, NULL) != B_OK) {354 if(EthernetIfnet()->module->send_data(EthernetIfnet(), packet) != B_OK) { 290 355 ERROR("PPPoEDevice::Send(): EthernetIfnet()->output() failed!\n"); 291 356 remove_device(this); 292 357 DownEvent(); … … PPPoEDevice::Send(struct mbuf *packet, uint16 protocolNumber) 297 362 return B_OK; 298 363 } 299 364 300 301 365 status_t 302 PPPoEDevice::Receive( struct mbuf*packet, uint16 protocolNumber)366 PPPoEDevice::Receive(net_buffer *packet, uint16 protocolNumber) 303 367 { 368 TRACE("%s entering %s: protocolNumber:%x\n",__FILE__,__func__,protocolNumber); 304 369 if(!packet) 305 370 return B_ERROR; 306 371 else if(InitCheck() != B_OK || IsDown()) { 307 m_freem(packet); 372 dprintf("PPPoED InitCheck fail or IsDown\n"); 373 //gBufferModule->free(packet); 374 dprintf("PPPoEDevice::Receive fail\n"); 308 375 return B_ERROR; 309 376 } 310 377 311 complete_pppoe_header *completeHeader = mtod(packet, complete_pppoe_header*); 312 if(!completeHeader) { 313 m_freem(packet); 314 return B_ERROR; 315 } 378 // NetBufferHeaderReader<pppoe_header> bufferheader(packet); 379 // if(bufferheader.Status() != B_OK) 380 // return B_ERROR; 381 // pppoe_header &completeHeader = bufferheader.Data(); 382 383 // if(!completeHeader) { 384 // gBufferModule->free(packet); 385 // return B_ERROR; 386 // } 316 387 317 388 uint8 ethernetSource[6]; 318 memcpy(ethernetSource, completeHeader->ethernetHeader.ether_shost, sizeof(fPeer)); 389 struct sockaddr_dl& source = *(struct sockaddr_dl*)packet->source; 390 memcpy(ethernetSource, source.sdl_data, sizeof(fPeer)); 391 319 392 status_t result = B_OK; 320 321 if(completeHeader->ethernetHeader.ether_type == ETHERTYPE_PPPOE) { 322 m_adj(packet, ETHER_HDR_LEN); 323 pppoe_header *header = mtod(packet, pppoe_header*); 324 325 if(!IsUp() || header->version != PPPoE_VERSION || header->type != PPPoE_TYPE 326 || header->code != 0x0 || header->sessionID != SessionID()) { 327 m_freem(packet); 393 394 // bufferheader.Remove(); 395 // bufferheader.Sync(); 396 397 if(packet->type == B_NET_FRAME_TYPE(IFT_ETHER, ETHER_TYPE_PPPOE)) { 398 TRACE("ETHER_TYPE_PPPOE\n"); 399 NetBufferHeaderReader<pppoe_header> bufferheader(packet); 400 if(bufferheader.Status() != B_OK) { 401 TRACE("creat NetBufferHeaderReader fail\n"); 328 402 return B_ERROR; 329 403 } 330 331 m_adj(packet, PPPoE_HEADER_SIZE); 404 pppoe_header &header = bufferheader.Data(); 405 uint16 ppppoe_payload = ntohs(header.length); 406 407 if(!IsUp() || header.version != PPPoE_VERSION || header.type != PPPoE_TYPE 408 || header.code != 0x0 || header.sessionID != SessionID()) { 409 // gBufferModule->free(packet); 410 TRACE("basic pppoe header check fail\n"); 411 return B_ERROR; 412 } 413 414 bufferheader.Remove(); 415 bufferheader.Sync(); 416 417 //trim the packet according to actual pppoe_payload 418 gBufferModule->trim(packet, ppppoe_payload); 419 332 420 return Interface().ReceiveFromDevice(packet); 333 } else if(completeHeader->ethernetHeader.ether_type == ETHERTYPE_PPPOEDISC) { 334 m_adj(packet, ETHER_HDR_LEN); 335 pppoe_header *header = mtod(packet, pppoe_header*); 421 } else if(packet->type == B_NET_FRAME_TYPE(IFT_ETHER, ETHER_TYPE_PPPOE_DISCOVERY)) { 422 TRACE("ETHER_TYPE_PPPOE_DISCOVERY\n"); 423 NetBufferHeaderReader<pppoe_header> bufferheader(packet); 424 if(bufferheader.Status() != B_OK) { 425 TRACE("create NetBufferHeaderReader fail\n"); 426 return B_ERROR; 427 } 428 pppoe_header &header = bufferheader.Data(); 336 429 337 430 // we do not need to check HOST_UNIQ tag as this is done in pppoe.cpp 338 if(header->version != PPPoE_VERSION || header->type != PPPoE_TYPE) { 339 m_freem(packet); 431 if(header.version != PPPoE_VERSION || header.type != PPPoE_TYPE) { 432 //gBufferModule->free(packet); 433 dprintf("PPPoEDevice::Receive fail version type wrong\n"); 340 434 return B_ERROR; 341 435 } 342 436 343 437 if(IsDown()) { 344 m_freem(packet); 438 //gBufferModule->free(packet); 439 dprintf("PPPoEDevice::Receive fail PPPoEDev IsDown\n"); 345 440 return B_ERROR; 346 441 } 347 442 348 443 DiscoveryPacket discovery(packet); 349 444 switch(discovery.Code()) { 350 445 case PADO: { 446 dprintf("processing PADO\n"); 351 447 if(fState != PADI_SENT) { 352 m_freem(packet); 448 //gBufferModule->free(packet); 449 dprintf("PPPoEDevice::Receive faile not PADI_Sent \n"); 353 450 return B_OK; 354 451 } 355 452 … … PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber) 364 461 switch(tag->type) { 365 462 case SERVICE_NAME: 366 463 if(!hasServiceName && (!ServiceName() 367 || ( strlen(ServiceName()) == tag->length)464 || ((strlen(ServiceName()) == tag->length) 368 465 && !memcmp(tag->data, ServiceName(), 369 tag->length))) {466 tag->length)))) { 370 467 hasServiceName = true; 371 468 reply.AddTag(tag->type, tag->data, tag->length); 372 469 } … … PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber) 374 471 375 472 case AC_NAME: 376 473 if(!hasACName && (!ACName() 377 || ( strlen(ACName()) == tag->length)474 || ((strlen(ACName()) == tag->length) 378 475 && !memcmp(tag->data, ACName(), 379 tag->length))) {476 tag->length)))) { 380 477 hasACName = true; 381 478 reply.AddTag(tag->type, tag->data, tag->length); 382 479 } … … PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber) 390 487 case SERVICE_NAME_ERROR: 391 488 case AC_SYSTEM_ERROR: 392 489 case GENERIC_ERROR: 393 m_freem(packet); 490 //gBufferModule->free(packet); 491 dprintf("PPPoEDevice::generic error faile\n"); 394 492 return B_ERROR; 395 493 break; 396 494 … … PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber) 400 498 } 401 499 402 500 if(!hasServiceName) { 403 m_freem(packet); 501 //gBufferModule->free(packet); 502 dprintf("PPPoEDevice::Receive faile no svc name\n"); 404 503 return B_ERROR; 405 504 } 406 505 506 dprintf("reply.AddTag\n"); 407 507 reply.AddTag(HOST_UNIQ, &fHostUniq, sizeof(fHostUniq)); 408 508 reply.AddTag(END_OF_LIST, NULL, 0); 409 struct mbuf*replyPacket = reply.ToMbuf(MTU());509 net_buffer *replyPacket = reply.ToMbuf(MTU()); 410 510 if(!replyPacket) { 411 m_freem(packet); 511 //gBufferModule->free(packet); 512 dprintf("PPPoEDevice::Receive fail no reply pack\n"); 412 513 return B_ERROR; 413 514 } 414 515 415 memcpy(fPeer, ethernetSource, sizeof(fPeer));516 memcpy(fPeer, ethernetSource, ETHER_ADDRESS_LENGTH); 416 517 417 // create destination 418 struct ether_header *ethernetHeader; 419 struct sockaddr destination; 420 memset(&destination, 0, sizeof(destination)); 421 destination.sa_family = AF_UNSPEC; 422 // raw packet with ethernet header 423 ethernetHeader = (struct ether_header*) destination.sa_data; 424 ethernetHeader->ether_type = ETHERTYPE_PPPOEDISC; 425 memcpy(ethernetHeader->ether_dhost, fPeer, sizeof(fPeer)); 518 // create ether header 519 NetBufferPrepend<ether_header> ethernetHeader(replyPacket); 520 if (ethernetHeader.Status() != B_OK) 521 return false; 522 ether_header &header = ethernetHeader.Data(); 523 524 memcpy(header.destination, fPeer, ETHER_ADDRESS_LENGTH); 525 memcpy(header.source, fEtherAddr, ETHER_ADDRESS_LENGTH); 526 header.type=htons(ETHER_TYPE_PPPOE_DISCOVERY); 527 ethernetHeader.Sync(); 528 // raw packet with ethernet header 426 529 427 530 fState = PADR_SENT; 428 531 429 if(EthernetIfnet()-> output(EthernetIfnet(), replyPacket, &destination,430 NULL) != B_OK) {431 m_freem(packet);532 if(EthernetIfnet()->module->send_data(EthernetIfnet(), replyPacket) != B_OK) { 533 gBufferModule->free(replyPacket); 534 dprintf("PPPoEDevice::Receive fail send PADR\n"); 432 535 return B_ERROR; 433 536 } 434 537 … … PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber) 436 539 } break; 437 540 438 541 case PADS: 542 dprintf("procesing PADS\n"); 439 543 if(fState != PADR_SENT 440 544 || memcmp(ethernetSource, fPeer, sizeof(fPeer))) { 441 m_freem(packet); 545 //gBufferModule->free(packet); 546 dprintf("PPPoEDevice::Receive PADS but no PADR sent\n"); 442 547 return B_ERROR; 443 548 } 444 549 445 fSessionID = header ->sessionID;550 fSessionID = header.sessionID; 446 551 fState = OPENED; 447 552 fNextTimeout = 0; 448 553 UpEvent(); 449 554 break; 450 555 451 556 case PADT: 557 dprintf("procesing PADT\n"); 452 558 if(!IsUp() 453 559 || memcmp(ethernetSource, fPeer, sizeof(fPeer)) 454 || header->sessionID != SessionID()) { 455 m_freem(packet); 560 || header.sessionID != SessionID()) { 561 //gBufferModule->free(packet); 562 dprintf("PPPoEDevice::Receive fail not up yet\n"); 456 563 return B_ERROR; 457 564 } 458 565 … … PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber) 465 572 break; 466 573 467 574 default: 468 m_freem(packet); 575 dprintf("PPPoEDevice::Receive fail unknown pppoed code\n"); 576 //gBufferModule->free(packet); 469 577 return B_ERROR; 470 578 } 471 579 } else 472 580 result = B_ERROR; 473 581 474 m_freem(packet); 582 dprintf("PPPoEDevice::Receive fail unknow packet type\n"); 583 //gBufferModule->free(packet); 475 584 return result; 476 585 } 477 586 … … void 480 589 PPPoEDevice::Pulse() 481 590 { 482 591 // We use Pulse() for timeout of connection establishment. 483 484 592 if(fNextTimeout == 0 || IsUp() || IsDown()) 485 593 return; 486 594 -
src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h
diff --git a/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h b/src/add-ons/kernel/network/ppp/pppoe/PPPoEDevice.h index 3955058..ccc7756 100644
a b 10 10 11 11 #include <KPPPDevice.h> 12 12 13 #include <net/if_types.h> 14 #include <net_stack.h> 15 16 17 const uint8 etheraddr[6]={ 18 0x00,0x00,0x00,0x00,0x00,0x00 //src for Y470 19 }; 20 13 21 14 22 enum pppoe_state { 15 23 INITIAL, … … class PPPoEDevice : public KPPPDevice { 25 33 public: 26 34 PPPoEDevice(KPPPInterface& interface, driver_parameter *settings); 27 35 28 ifnet*EthernetIfnet() const36 net_device *EthernetIfnet() const 29 37 { return fEthernetIfnet; } 30 38 31 39 const uint8 *Peer() const … … class PPPoEDevice : public KPPPDevice { 50 58 51 59 virtual uint32 CountOutputBytes() const; 52 60 53 virtual status_t Send( struct mbuf*packet, uint16 protocolNumber = 0);54 virtual status_t Receive( struct mbuf*packet, uint16 protocolNumber = 0);61 virtual status_t Send(net_buffer *packet, uint16 protocolNumber = 0); 62 virtual status_t Receive(net_buffer *packet, uint16 protocolNumber = 0); 55 63 56 64 virtual void Pulse(); 57 65 58 66 private: 59 ifnet*fEthernetIfnet;67 net_device *fEthernetIfnet; 60 68 uint8 fPeer[6]; 69 uint8 fEtherAddr[6]; 61 70 uint16 fSessionID; 62 71 uint32 fHostUniq; 63 72 const char *fACName, *fServiceName; 73 const char *finterfaceName; 64 74 65 75 uint32 fAttempts; 66 76 bigtime_t fNextTimeout; -
src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp
diff --git a/src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp b/src/add-ons/kernel/network/ppp/pppoe/pppoe.cpp index 5d0884a..d3d5c7c 100644
a b 5 5 6 6 #include <KernelExport.h> 7 7 #include <driver_settings.h> 8 #include <core_funcs.h>9 #include <net_module.h>10 8 11 #include <ethernet_module.h> 9 #include <net_stack.h> 10 #include <net_datalink.h> //for get_interface_by_name 11 #include <net_buffer.h> 12 #include <NetBufferUtilities.h> 13 14 #include <net/if_types.h> 15 #include <net/if_dl.h> 12 16 13 17 #include <KPPPInterface.h> 14 18 #include <KPPPModule.h> 15 19 #include <KPPPUtils.h> 16 #include <LockerHelper.h> 20 21 #include <lock.h> 22 #include <util/AutoLock.h> 23 #include <ByteOrder.h> 17 24 18 25 #include "PPPoEDevice.h" 19 26 #include "DiscoveryPacket.h" 20 27 21 28 22 29 typedef struct pppoe_query { 23 ifnet*ethernetIfnet;30 net_device *ethernetIfnet; 24 31 uint32 hostUniq; 25 32 thread_id receiver; 26 33 } pppoe_query; 27 34 28 #define PPPoE_MODULE_NAME NETWORK_MODULES_ROOT "ppp/pppoe" 35 #define PPPoE_MODULE_NAME "network/ppp/pppoe" 36 37 net_stack_module_info *gStackModule = NULL; 38 net_buffer_module_info *gBufferModule = NULL; 39 net_datalink_module_info *sDatalinkModule = NULL; 29 40 30 struct core_module_info *core = NULL; 31 static struct ethernet_module_info *sEthernet; 41 // static net_device_module_info *sEthernetModule = NULL; 32 42 static int32 sHostUniq = 0; 33 43 status_t std_ops(int32 op, ...); 34 44 35 static BLocker sLock("PPPoEList"); 45 // static mutex sLock("PPPoEList"); 46 // static mutex sLock; // ("PPPoEList"); 47 36 48 static TemplateList<PPPoEDevice*> *sDevices; 37 49 static TemplateList<pppoe_query*> *sQueries; 38 50 … … SendQueryPacket(pppoe_query *query, DiscoveryPacket& discovery) 76 88 } 77 89 78 90 79 ifnet*91 net_device* 80 92 FindPPPoEInterface(const char *name) 81 93 { 82 94 if(!name) 83 95 return NULL; 84 96 85 ifnet *current = get_interfaces(); 86 for(; current; current = current->if_next) { 87 if(current->if_type == IFT_ETHER && current->if_name 88 && !strcmp(current->if_name, name)) 89 return current; 97 // net_device *current = NULL; 98 // sEthernetModule->get_device(¤t, name); 99 net_interface* eth_if = NULL; 100 net_domain* nd = NULL; 101 102 if (sDatalinkModule){ 103 TRACE("sDatalinkModule can not find eth\n"); 104 nd = gStackModule->get_domain(AF_INET); 105 eth_if = sDatalinkModule->get_interface_by_name(nd, name); 90 106 } 91 107 108 if (eth_if == NULL) 109 dprintf("sDatalinkModule->get_interface_by_name can not find eth\n"); 110 else { 111 dprintf("interface name:%s, device name:%s\n", eth_if->name, eth_if->device->name); 112 } 113 114 if (eth_if && eth_if->device) 115 return eth_if->device; 116 92 117 return NULL; 93 118 } 94 119 95 96 120 uint32 97 121 NewHostUniq() 98 122 { … … add_device(PPPoEDevice *device) 105 129 { 106 130 TRACE("PPPoE: add_device()\n"); 107 131 108 LockerHelper locker(sLock);132 // MutexLocker locker(sLock); 109 133 if(!sDevices->HasItem(device)) 110 134 sDevices->AddItem(device); 111 135 } … … remove_device(PPPoEDevice *device) 116 140 { 117 141 TRACE("PPPoE: remove_device()\n"); 118 142 119 LockerHelper locker(sLock);143 // MutexLocker locker(sLock); 120 144 sDevices->RemoveItem(device); 121 145 } 122 146 123 147 124 static 125 void 126 pppoe_input(struct mbuf *packet) 148 status_t 149 pppoe_input(void *cookie, net_device *_device, net_buffer *packet) 127 150 { 128 151 if(!packet) 129 return; 152 return B_ERROR; 153 TRACE("%s::%s: receive pppoe packet type:%ld!\n",__FILE__,__func__,packet->type); 130 154 131 ifnet *sourceIfnet = packet->m_pkthdr.rcvif; 132 complete_pppoe_header *header = mtod(packet, complete_pppoe_header*); 155 NetBufferHeaderReader<pppoe_header> bufferheader(packet); 156 if(bufferheader.Status() != B_OK) 157 return B_ERROR; 158 pppoe_header &header = bufferheader.Data(); 159 160 // remove the following two lines when pppoe server is enabled 161 if (header.code==PADI) 162 return B_ERROR; 163 164 if (header.code==PADI || header.code==PADO || header.code==PADR || header.code==PADS || 165 header.code==PADT) 166 { 167 uint8 peerether_addr[ETHER_ADDRESS_LENGTH]; 168 struct sockaddr_dl& source = *(struct sockaddr_dl*)packet->source; 169 memcpy(peerether_addr, source.sdl_data, ETHER_ADDRESS_LENGTH); 170 const char *str = (header.code==PADI) ? "PADI" : 171 (header.code==PADO) ? "PADO" : 172 (header.code==PADR) ? "PADR" : 173 (header.code==PADS) ? "PADS" : 174 "PADT" ; 175 176 dprintf("%s from:%02x:%02x:%02x:%02x:%02x:%02x code:%02x\n", str, 177 peerether_addr[0],peerether_addr[1],peerether_addr[2], 178 peerether_addr[3],peerether_addr[4],peerether_addr[5], 179 header.code); 180 } 181 133 182 PPPoEDevice *device; 134 183 pppoe_query *query; 184 185 sockaddr_dl& linkAddress = *(sockaddr_dl*)packet->source; 186 int32 specificType = B_NET_FRAME_TYPE(linkAddress.sdl_type, 187 ntohs(linkAddress.sdl_e_type)); 135 188 136 LockerHelper locker(sLock); 137 138 if(header->ethernetHeader.ether_type == ETHERTYPE_PPPOEDISC 139 && header->pppoeHeader.length <= PPPoE_QUERY_REPORT_SIZE) { 189 // MutexLocker locker(sLock); 190 TRACE("type by linkAddress: %lx\n", specificType); 191 TRACE("packet->type: %lx\n", packet->type ); 192 193 // why packet->type changed since ethernet_deframe??? 194 packet->type = specificType; 195 196 if( (packet->type == B_NET_FRAME_TYPE(IFT_ETHER, ETHER_TYPE_PPPOE_DISCOVERY)) 197 && ntohs(header.length) <= PPPoE_QUERY_REPORT_SIZE) { 140 198 for(int32 index = 0; index < sDevices->CountItems(); index++) { 141 199 query = sQueries->ItemAt(index); 142 143 if(query && query->ethernetIfnet == sourceIfnet) {144 if(header ->pppoeHeader.code == PADO) {200 201 if(query) {// && query->ethernetIfnet == sourceIfnet) { 202 if(header.code == PADO) { 145 203 DiscoveryPacket discovery(packet, ETHER_HDR_LEN); 146 204 if(discovery.InitCheck() != B_OK) { 147 205 ERROR("PPPoE: received corrupted discovery packet!\n"); 148 m_freem(packet);149 return ;206 // gBufferModule->free(packet); 207 return B_ERROR; 150 208 } 151 209 152 210 pppoe_tag *hostTag = discovery.TagWithType(HOST_UNIQ); 153 211 if(hostTag && hostTag->length == 4 154 212 && *((uint32*)hostTag->data) == query->hostUniq) { 155 213 SendQueryPacket(query, discovery); 156 m_freem(packet);157 return ;214 // gBufferModule->free(packet); 215 return B_ERROR; 158 216 } 159 217 } 160 218 } 161 219 } 162 220 } 163 221 222 TRACE("in pppoed processing sDevices->CountItems(): %ld\n",sDevices->CountItems()); 164 223 for(int32 index = 0; index < sDevices->CountItems(); index++) { 165 224 device = sDevices->ItemAt(index); 166 167 if(device && device->EthernetIfnet() == sourceIfnet) { 168 if(header->ethernetHeader.ether_type == ETHERTYPE_PPPOE 169 && header->pppoeHeader.sessionID == device->SessionID()) { 225 226 TRACE("device->SessionID() %d,header.sessionID: %d\n", device->SessionID(), 227 header.sessionID); 228 229 if(device) {// && device->EthernetIfnet() == sourceIfnet) { 230 231 if( (packet->type == B_NET_FRAME_TYPE(IFT_ETHER, ETHER_TYPE_PPPOE)) 232 && header.sessionID == device->SessionID()) { 170 233 TRACE("PPPoE: session packet\n"); 171 234 device->Receive(packet); 172 return; 173 } else if(header->ethernetHeader.ether_type == ETHERTYPE_PPPOEDISC 174 && header->pppoeHeader.code != PADI 175 && header->pppoeHeader.code != PADR 235 return B_OK; 236 } else if( (packet->type == 237 B_NET_FRAME_TYPE(IFT_ETHER, ETHER_TYPE_PPPOE_DISCOVERY)) 238 && header.code != PADI 239 && header.code != PADR 176 240 && !device->IsDown()) { 177 241 TRACE("PPPoE: discovery packet\n"); 242 178 243 DiscoveryPacket discovery(packet, ETHER_HDR_LEN); 179 244 if(discovery.InitCheck() != B_OK) { 180 245 ERROR("PPPoE: received corrupted discovery packet!\n"); 181 m_freem(packet);182 return ;246 gBufferModule->free(packet); 247 return B_OK; 183 248 } 184 249 185 250 pppoe_tag *tag = discovery.TagWithType(HOST_UNIQ); 186 if(header ->pppoeHeader.code == PADT || (tag && tag->length == 4187 251 if(header.code == PADT || (tag && tag->length == 4 252 && *((uint32*)tag->data) == device->HostUniq())) { 188 253 device->Receive(packet); 189 return ;254 return B_OK; 190 255 } 256 191 257 } 192 258 } 193 259 } 194 260 195 ERROR("PPPoE: No device found for packet from: %s\n", sourceIfnet->if_name); 196 m_freem(packet); 261 ERROR("PPPoE: No device found for packet from: %s\n", "ethernet"); 262 // gBufferModule->free(packet); 263 return B_ERROR; 197 264 } 198 265 199 266 … … control(uint32 op, void *data, size_t length) 231 298 int32 position = 0, count = 0; 232 299 char *names = (char*) data; 233 300 234 ifnet *current =get_interfaces();235 for(; current; current = current->if_next) {236 if(current-> if_type == IFT_ETHER && current->if_name) {237 if(position + strlen(current-> if_name) + 1 > length)301 net_device *current = NULL;//get_interfaces(); 302 for(; current; current = NULL) { 303 if(current->type == IFT_ETHER && current->name) { 304 if(position + strlen(current->name) + 1 > length) 238 305 return B_NO_MEMORY; 239 306 240 strcpy(names + position, current-> if_name);241 position += strlen(current-> if_name);307 strcpy(names + position, current->name); 308 position += strlen(current->name); 242 309 names[position++] = 0; 243 310 ++count; 244 311 } … … control(uint32 op, void *data, size_t length) 263 330 query.hostUniq = NewHostUniq(); 264 331 query.receiver = request->receiver; 265 332 266 sLock.Lock(); 267 sQueries->AddItem(&query); 268 sLock.Unlock(); 333 { 334 // MutexLocker tlocker(sLock); 335 TRACE("add query\n"); 336 sQueries->AddItem(&query); 337 } 269 338 270 339 snooze(2000000); 271 340 // wait two seconds for results 272 273 sLock.Lock(); 274 sQueries->RemoveItem(&query); 275 sLock.Unlock(); 341 { 342 // MutexLocker tlocker(sLock); 343 TRACE("remove query\n"); 344 sQueries->RemoveItem(&query); 345 } 276 346 } break; 277 347 278 348 default: … … std_ops(int32 op, ...) 300 370 { 301 371 switch(op) { 302 372 case B_MODULE_INIT: 303 if(get_module(NET_ CORE_MODULE_NAME, (module_info**)&core) != B_OK)373 if(get_module(NET_STACK_MODULE_NAME, (module_info**)&gStackModule) != B_OK) 304 374 return B_ERROR; 375 // if(get_module("network/devices/ethernet/v1", 376 // (module_info **)&sEthernetModule) != B_OK) 377 // return B_ERROR; 378 if(get_module(NET_DATALINK_MODULE_NAME, 379 (module_info **)&sDatalinkModule) != B_OK) 380 return B_ERROR; 381 if(get_module(NET_BUFFER_MODULE_NAME, 382 (module_info **)&gBufferModule) != B_OK) 383 return B_ERROR; 305 384 306 if(get_module(NET_ETHERNET_MODULE_NAME,307 (module_info**) &sEthernet) != B_OK) {308 put_module(NET_CORE_MODULE_NAME);309 return B_ERROR;310 }385 // if(get_module(NET_ETHERNET_MODULE_NAME, 386 // (module_info**) &sEthernet) != B_OK) { 387 // put_module(NET_CORE_MODULE_NAME); 388 // return B_ERROR; 389 // } 311 390 312 set_max_linkhdr(2 + PPPoE_HEADER_SIZE + ETHER_HDR_LEN);391 // set_max_linkhdr(2 + PPPoE_HEADER_SIZE + ETHER_HDR_LEN); 313 392 // 2 bytes for PPP header 314 393 sDevices = new TemplateList<PPPoEDevice*>; 315 394 sQueries = new TemplateList<pppoe_query*>; 316 sEthernet->set_pppoe_receiver(pppoe_input);395 // sEthernet->set_pppoe_receiver(pppoe_input); 317 396 318 397 TRACE("PPPoE: Registered PPPoE receiver.\n"); 319 398 return B_OK; 320 399 321 400 case B_MODULE_UNINIT: 322 401 delete sDevices; 323 sEthernet->unset_pppoe_receiver();402 // sEthernet->unset_pppoe_receiver(); 324 403 TRACE("PPPoE: Unregistered PPPoE receiver.\n"); 325 put_module(NET_CORE_MODULE_NAME); 326 put_module(NET_ETHERNET_MODULE_NAME); 404 put_module(NET_BUFFER_MODULE_NAME); 405 put_module(NET_DATALINK_MODULE_NAME); 406 // put_module("network/devices/ethernet/v1"); 407 put_module(NET_STACK_MODULE_NAME); 327 408 break; 328 409 329 410 default: -
src/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile b/src/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile index 3b701b5..fe4cd26 100644
a b if $(TARGET_PLATFORM) != haiku { 10 10 # Unfortunately we get more than we want, namely all POSIX headers. 11 11 } 12 12 13 UsePrivateKernelHeaders ; 14 UsePrivateHeaders net ; 15 13 16 UsePrivateHeaders libroot net ; 14 17 UsePrivateHeaders [ FDirName kernel ] ; 15 18 UsePrivateHeaders [ FDirName kernel util ] ; … … KernelStaticLibrary libkernelppp.a : 37 40 KPPPReportManager.cpp 38 41 KPPPStateMachine.cpp 39 42 KPPPUtils.cpp 40 Locker.cpp41 43 settings_tools.cpp 42 44 43 45 # integrated modules … … KernelStaticLibrary libkernelppp.a : 49 51 50 52 SEARCH on [ FGristFiles kernel_cpp.cpp ] 51 53 = [ FDirName $(HAIKU_TOP) src system kernel util ] ; 52 SEARCH on [ FGristFiles Locker.cpp ]53 = [ FDirName $(HAIKU_TOP) src system kernel disk_device_manager ] ;54 54 SEARCH on [ FGristFiles atomic.S ] 55 55 = [ FDirName $(HAIKU_TOP) src system libroot os arch $(TARGET_ARCH) ] ; -
src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPConfigurePacket.cpp
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 bbe5e39..d0d5bdb 100644
a b 12 12 #include <KPPPConfigurePacket.h> 13 13 #include <KPPPInterface.h> 14 14 15 #include <core_funcs.h> 15 #include <net_buffer.h> 16 #include <ByteOrder.h> 17 #include <net_stack.h> 16 18 17 19 18 20 /*! \brief Constructor. … … KPPPConfigurePacket::KPPPConfigurePacket(uint8 code) 27 29 28 30 29 31 //! Decodes a packet and adds its items to this object. 30 KPPPConfigurePacket::KPPPConfigurePacket( struct mbuf*packet)32 KPPPConfigurePacket::KPPPConfigurePacket(net_buffer *packet) 31 33 { 32 34 // decode packet 33 ppp_lcp_packet *header = mtod(packet, ppp_lcp_packet*); 35 NetBufferHeaderReader<ppp_lcp_packet> bufferhead(packet); 36 if(bufferhead.Status() != B_OK) 37 return; 38 ppp_lcp_packet &header = bufferhead.Data(); 34 39 35 SetID(header ->id);36 if (!SetCode(header ->code))40 SetID(header.id); 41 if (!SetCode(header.code)) 37 42 return; 38 43 39 uint16 length = ntohs(header ->length);44 uint16 length = ntohs(header.length); 40 45 41 if (length < 6 || length > packet-> m_len)46 if (length < 6 || length > packet->size) 42 47 return; 43 48 // there are no items (or one corrupted item) 44 49 … … KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet) 46 51 ppp_configure_item *item; 47 52 48 53 while (position < length - 4) { 49 item = (ppp_configure_item*) (header ->data + position);54 item = (ppp_configure_item*) (header.data + position); 50 55 if (item->length < 2) 51 56 return; 52 57 // found a corrupted item … … KPPPConfigurePacket::ItemWithType(uint8 type) const 157 162 } 158 163 159 164 160 /*! \brief Converts this packet into an mbufstructure.165 /*! \brief Converts this packet into an net_buffer structure. 161 166 162 167 ATTENTION: You are responsible for freeing this packet by calling \c m_freem()! 163 168 164 169 \param MRU The interface's maximum receive unit (MRU). 165 170 \param reserve Number of bytes to reserve at the beginning of the packet. 166 171 167 \return The mbufstructure or \c NULL on error (e.g.: too big for given MRU).172 \return The net_buffer structure or \c NULL on error (e.g.: too big for given MRU). 168 173 */ 169 struct mbuf*174 net_buffer* 170 175 KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve) 171 176 { 172 struct mbuf *packet = m_gethdr(MT_DATA); 173 packet->m_data += reserve; 174 175 ppp_lcp_packet *header = mtod(packet, ppp_lcp_packet*); 176 177 net_buffer *buffer = gBufferModule->create(256); 178 if (buffer == NULL){ 179 TRACE("%s::%s: gBufferModule->create fail\n", __FILE__, __func__); 180 return(NULL); 181 } 182 183 ppp_lcp_packet *header; 184 status_t status = gBufferModule->append_size(buffer, 1492, (void **)&header); 185 if (status != B_OK) { 186 TRACE("%s::%s: gBufferModule->append_size\n", __FILE__, __func__); 187 gBufferModule->free(buffer); 188 return(NULL); 189 } 190 177 191 header->code = Code(); 178 192 header->id = ID(); 179 193 … … KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve) 185 199 186 200 // make sure we have enough space left 187 201 if (MRU - length < item->length) { 188 m_freem(packet);202 gBufferModule->free(buffer); 189 203 return NULL; 190 204 } 191 205 … … KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve) 195 209 196 210 length += 4; 197 211 header->length = htons(length); 198 packet->m_pkthdr.len = packet->m_len = length; 199 200 return packet; 212 213 status = gBufferModule->trim(buffer, length); 214 if (status < B_OK) { 215 dprintf("%s::%s: gBufferModule->trim\n", __FILE__, __func__); 216 gBufferModule->free(buffer); 217 return(NULL); 218 } 219 220 return buffer; 201 221 } -
src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPDevice.cpp
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 62c3945..a3193a1 100644
a b 14 14 #include <KPPPDevice.h> 15 15 16 16 #include <net/if.h> 17 #include <core_funcs.h>18 17 19 18 #include <PPPControl.h> 20 19 … … KPPPDevice::IsAllowedToSend() const 89 88 90 89 //! This method is never used. 91 90 status_t 92 KPPPDevice::Receive( struct mbuf*packet, uint16 protocolNumber)91 KPPPDevice::Receive(net_buffer *packet, uint16 protocolNumber) 93 92 { 94 93 // let the interface handle the packet 95 94 if (protocolNumber == 0) -
src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPInterface.cpp
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 db04a63..68bda37 100644
a b 23 23 // void (KernelExport.h) and once with int (stdio.h). 24 24 #include <cstdio> 25 25 #include <cstring> 26 #include < core_funcs.h>26 #include <net_buffer.h> 27 27 28 #include <ppp_device.h> 29 #include <net_stack.h> 30 #include <ByteOrder.h> 28 31 // now our headers... 29 32 #include <KPPPInterface.h> 30 33 … … 38 41 #include <KPPPUtils.h> 39 42 40 43 // general helper classes not only belonging to us 41 #include <LockerHelper.h> 44 // #include <lock.h> 45 // #include <util/AutoLock.h> 42 46 43 47 // tools only for us :) 44 48 #include "settings_tools.h" … … typedef struct reconnect_info { 62 66 uint32 delay; 63 67 } reconnect_info; 64 68 69 // module related to net_buffer objects 70 extern net_buffer_module_info *gBufferModule; 71 extern net_stack_module_info *gStackModule; 72 65 73 status_t reconnect_thread(void *data); 66 74 67 75 // other functions … … KPPPInterface::~KPPPInterface() 250 258 // This lock is not released until we are actually deleted. 251 259 while (true) { 252 260 Down(); 253 fLock.Lock(); 254 if (State() == PPP_INITIAL_STATE && Phase() == PPP_DOWN_PHASE) 255 break; 256 fLock.Unlock(); 261 { 262 MutexLocker (fLock); 263 if (State() == PPP_INITIAL_STATE && Phase() == PPP_DOWN_PHASE) 264 break; 265 } 257 266 } 258 267 259 268 Report(PPP_DESTRUCTION_REPORT, 0, &fID, sizeof(ppp_interface_id)); … … KPPPInterface::~KPPPInterface() 296 305 void 297 306 KPPPInterface::Delete() 298 307 { 299 LockerHelper locker(fLock); 308 // MutexLocker locker(fLock); 309 // alreay locked in KPPPStatemachine::DownEvent 310 // uncomment this line will cause double lock 300 311 301 312 if (fDeleteCounter > 0) 302 313 return; … … KPPPInterface::SetMRU(uint32 MRU) 364 375 if (Device() && MRU > Device()->MTU() - 2) 365 376 return false; 366 377 367 LockerHelper locker(fLock); 378 // MutexLocker locker(fLock); 379 //uncomment this line will cause double lock 380 //alreay locked in ::Up and ::KPPPInterface 368 381 369 382 fMRU = MRU; 370 383 … … KPPPInterface::Control(uint32 op, void *data, size_t length) 417 430 if (Name()) 418 431 strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT); 419 432 if (Ifnet()) 420 info->if_unit = Ifnet()->i f_unit;433 info->if_unit = Ifnet()->index; 421 434 else 422 435 info->if_unit = -1; 423 436 info->mode = Mode(); … … KPPPInterface::Control(uint32 op, void *data, size_t length) 456 469 if (!data) 457 470 return B_ERROR; 458 471 459 LockerHelper locker(fLock);472 MutexLocker locker(fLock); 460 473 // login information can only be changed before we authenticate 461 474 if (Phase() >= PPP_AUTHENTICATION_PHASE) 462 475 return B_NOT_ALLOWED; … … KPPPInterface::Control(uint32 op, void *data, size_t length) 471 484 if (!data) 472 485 return B_ERROR; 473 486 474 LockerHelper locker(fLock);487 MutexLocker locker(fLock); 475 488 // login information can only be changed before we authenticate 476 489 if (Phase() >= PPP_AUTHENTICATION_PHASE) 477 490 return B_NOT_ALLOWED; … … KPPPInterface::Control(uint32 op, void *data, size_t length) 524 537 if (length < sizeof(ppp_report_request) || !data) 525 538 return B_ERROR; 526 539 527 LockerHelper locker(fLock);540 MutexLocker locker(fLock); 528 541 ppp_report_request *request = (ppp_report_request*) data; 529 542 // first, we send an initial state report 530 543 if (request->type == PPP_CONNECTION_REPORT) { … … KPPPInterface::SetDevice(KPPPDevice *device) 656 669 return false; 657 670 // main interfaces do not have devices 658 671 659 LockerHelper locker(fLock);672 MutexLocker locker(fLock); 660 673 661 674 if (Phase() != PPP_DOWN_PHASE) 662 675 return false; … … KPPPInterface::AddProtocol(KPPPProtocol *protocol) 704 717 || protocol->Level() == PPP_INTERFACE_LEVEL) 705 718 return false; 706 719 707 LockerHelper locker(fLock);720 MutexLocker locker(fLock); 708 721 709 722 if (Phase() != PPP_DOWN_PHASE) 710 723 return false; … … KPPPInterface::RemoveProtocol(KPPPProtocol *protocol) 768 781 TRACE("KPPPInterface: RemoveProtocol(%X)\n", 769 782 protocol ? protocol->ProtocolNumber() : 0); 770 783 771 LockerHelper locker(fLock);784 MutexLocker locker(fLock); 772 785 773 786 if (Phase() != PPP_DOWN_PHASE) 774 787 return false; … … KPPPInterface::RemoveProtocol(KPPPProtocol *protocol) 809 822 int32 810 823 KPPPInterface::CountProtocols() const 811 824 { 812 LockerHelper locker(fLock);825 MutexLocker locker(fLock); 813 826 814 827 KPPPProtocol *protocol = FirstProtocol(); 815 828 … … KPPPInterface::CountProtocols() const 825 838 KPPPProtocol* 826 839 KPPPInterface::ProtocolAt(int32 index) const 827 840 { 828 LockerHelper locker(fLock);841 MutexLocker locker(fLock); 829 842 830 843 KPPPProtocol *protocol = FirstProtocol(); 831 844 … … KPPPInterface::ProtocolFor(uint16 protocolNumber, KPPPProtocol *start) const 849 862 { 850 863 TRACE("KPPPInterface: ProtocolFor(%X)\n", protocolNumber); 851 864 852 LockerHelper locker(fLock); 865 // MutexLocker locker(fLock); 866 // already locked in ::Receive,uncomment this line will cause double lock 853 867 854 868 KPPPProtocol *current = start ? start : FirstProtocol(); 855 869 … … KPPPInterface::AddChild(KPPPInterface *child) 874 888 if (!child) 875 889 return false; 876 890 877 LockerHelper locker(fLock);891 MutexLocker locker(fLock); 878 892 879 893 if (fChildren.HasItem(child) || !fChildren.AddItem(child)) 880 894 return false; … … KPPPInterface::RemoveChild(KPPPInterface *child) 891 905 { 892 906 TRACE("KPPPInterface: RemoveChild(%lX)\n", child ? child->ID() : 0); 893 907 894 LockerHelper locker(fLock);908 MutexLocker locker(fLock); 895 909 896 910 if (!fChildren.RemoveItem(child)) 897 911 return false; … … KPPPInterface::ChildAt(int32 index) const 912 926 { 913 927 TRACE("KPPPInterface: ChildAt(%ld)\n", index); 914 928 915 LockerHelper locker(fLock);929 MutexLocker locker(fLock); 916 930 917 931 KPPPInterface *child = fChildren.ItemAt(index); 918 932 … … KPPPInterface::SetConnectOnDemand(bool connectOnDemand) 945 959 946 960 TRACE("KPPPInterface: SetConnectOnDemand(%s)\n", connectOnDemand ? "true" : "false"); 947 961 948 LockerHelper locker(fLock);962 MutexLocker locker(fLock); 949 963 950 964 // Only clients support ConnectOnDemand. 951 965 if (Mode() != PPP_CLIENT_MODE) { … … KPPPInterface::SetConnectOnDemand(bool connectOnDemand) 973 987 // check if we need to set/unset flags 974 988 if (connectOnDemand) { 975 989 if (Ifnet()) 976 Ifnet()-> if_flags |= IFF_UP;990 Ifnet()->flags |= IFF_UP; 977 991 } else if (!connectOnDemand && Phase() < PPP_ESTABLISHED_PHASE) { 978 992 if (Ifnet()) 979 Ifnet()-> if_flags &= ~IFF_UP;993 Ifnet()->flags &= ~IFF_UP; 980 994 } 981 995 } 982 996 … … KPPPInterface::SetConnectOnDemand(bool connectOnDemand) 985 999 void 986 1000 KPPPInterface::SetAskBeforeConnecting(bool ask) 987 1001 { 988 LockerHelper locker(fLock);1002 MutexLocker locker(fLock); 989 1003 990 1004 bool old = fAskBeforeConnecting; 991 1005 fAskBeforeConnecting = ask; 992 1006 993 1007 if (old && fAskBeforeConnecting == false && State() == PPP_STARTING_STATE 994 1008 && Phase() == PPP_DOWN_PHASE) { 995 locker.UnlockNow();1009 // locker.Unlock(); 996 1010 StateMachine().ContinueOpenEvent(); 997 1011 } 998 1012 } … … KPPPInterface::SetPFCOptions(uint8 pfcOptions) 1004 1018 { 1005 1019 TRACE("KPPPInterface: SetPFCOptions(0x%X)\n", pfcOptions); 1006 1020 1007 LockerHelper locker(fLock);1021 MutexLocker locker(fLock); 1008 1022 1009 1023 if (PFCOptions() & PPP_FREEZE_PFC_OPTIONS) 1010 1024 return false; … … KPPPInterface::Up() 1032 1046 if (IsUp()) 1033 1047 return true; 1034 1048 1035 LockerHelper locker(fLock);1049 MutexLocker locker(fLock); 1036 1050 StateMachine().OpenEvent(); 1037 1051 1038 1052 return true; … … KPPPInterface::Down() 1059 1073 send_data_with_timeout(fReconnectThread, 0, NULL, 0, 200); 1060 1074 // tell the reconnect thread to abort its attempt (if it's still waiting) 1061 1075 1062 LockerHelper locker(fLock);1076 MutexLocker locker(fLock); 1063 1077 StateMachine().CloseEvent(); 1064 1078 1065 1079 return true; … … KPPPInterface::WaitForConnection() 1074 1088 1075 1089 if (InitCheck() != B_OK) 1076 1090 return false; 1091 1092 return true; // for temporary 1077 1093 1078 1094 ReportManager().EnableReports(PPP_CONNECTION_REPORT, find_thread(NULL)); 1079 1095 … … KPPPInterface::WaitForConnection() 1097 1113 } 1098 1114 1099 1115 ReportManager().DisableReports(PPP_CONNECTION_REPORT, find_thread(NULL)); 1116 dprintf("KPPPInterface: WaitForConnection():%s\n", successful?"True":"False"); 1100 1117 return successful; 1101 1118 } 1102 1119 … … KPPPInterface::IsAllowedToSend() const 1233 1250 - \c B_ERROR: Some error occured. 1234 1251 */ 1235 1252 status_t 1236 KPPPInterface::Send( struct mbuf*packet, uint16 protocolNumber)1253 KPPPInterface::Send(net_buffer *packet, uint16 protocolNumber) 1237 1254 { 1238 1255 TRACE("KPPPInterface: Send(0x%X)\n", protocolNumber); 1239 1256 1240 1257 if (!packet) 1241 1258 return B_ERROR; 1242 1259 1243 1260 // we must pass the basic tests like: 1244 1261 // do we have a device? 1245 1262 // did we load all modules? 1246 1263 if (InitCheck() != B_OK) { 1247 m_freem(packet); 1264 ERROR("InitCheck() fail\n"); 1265 gBufferModule->free(packet); 1248 1266 return B_ERROR; 1249 1267 } 1250 1268 1269 1251 1270 // go up if ConnectOnDemand is enabled and we are disconnected 1252 1271 // TODO: our new netstack will simplify ConnectOnDemand handling, so 1253 1272 // we do not have to handle it here … … KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) 1255 1274 && (Phase() == PPP_DOWN_PHASE 1256 1275 || Phase() == PPP_ESTABLISHMENT_PHASE) 1257 1276 && !Up()) || !WaitForConnection()) { 1258 m_freem(packet);1277 gBufferModule->free(packet); 1259 1278 return B_ERROR; 1260 1279 } 1261 1280 … … KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) 1279 1298 #endif 1280 1299 1281 1300 // make sure that protocol is allowed to send and everything is up 1282 if (!Device()->IsUp() || !protocol || !protocol->IsEnabled() 1301 if (Device()->IsUp() && protocolNumber==0x0021){ //IP_PROTOCOL 0x0021 1302 TRACE("KPPPInterface::Send(): send IP packet!\n"); 1303 } else if (!Device()->IsUp() || !protocol || !protocol->IsEnabled() 1283 1304 || !IsProtocolAllowed(*protocol)) { 1284 1305 ERROR("KPPPInterface::Send(): cannot send!\n"); 1285 m_freem(packet);1306 gBufferModule->free(packet); 1286 1307 return B_ERROR; 1287 1308 } 1288 1309 1289 1310 // encode in ppp frame and consider using PFC 1290 if (UseLocalPFC() && protocolNumber & 0xFF00 == 0) { 1291 M_PREPEND(packet, 1); 1292 1293 if (packet == NULL) 1294 return B_ERROR; 1311 if ( UseLocalPFC() && ((protocolNumber & 0xFF00) == 0) ) { 1312 TRACE("%s::%s should not go here\n",__FILE__,__func__); 1313 NetBufferPrepend<uint8> bufferHeader(packet); 1314 if (bufferHeader.Status() != B_OK) 1315 return bufferHeader.Status(); 1316 1317 uint8 &header = bufferHeader.Data(); 1318 1319 // memcpy(header.destination, ether_pppoe_ppp_header, 1); 1320 header = (protocolNumber & 0x00FF); 1321 // bufferHeader.Sync(); 1295 1322 1296 uint8 *header = mtod(packet, uint8*);1297 *header = protocolNumber & 0xFF;1298 1323 } else { 1299 M_PREPEND(packet, 2); 1300 1301 if (packet == NULL) 1302 return B_ERROR; 1303 1324 NetBufferPrepend<uint16> bufferHeader(packet); 1325 if (bufferHeader.Status() != B_OK) 1326 return bufferHeader.Status(); 1327 1328 uint16 &header = bufferHeader.Data(); 1329 1304 1330 // set protocol (the only header field) 1305 protocolNumber = htons(protocolNumber); 1306 uint16 *header = mtod(packet, uint16*); 1307 *header = protocolNumber; 1331 header = htons(protocolNumber); 1332 // bufferHeader.Sync(); 1308 1333 } 1309 1334 1310 1335 // pass to device if we're either not a multilink interface or a child interface 1311 1336 if (!IsMultilink() || Parent()) { 1312 1337 // check if packet is too big for device 1313 uint32 length = packet->m_flags & M_PKTHDR ? (uint32) packet->m_pkthdr.len : 1314 packet->m_len; 1338 uint32 length = packet->size; 1315 1339 1316 1340 if (length > MRU()) { 1317 m_freem(packet); 1341 dprintf("packet too large!\n"); 1342 gBufferModule->free(packet); 1318 1343 return B_ERROR; 1319 1344 } 1320 1345 1321 1346 atomic_add64(&fStatistics.bytesSent, length); 1322 1347 atomic_add64(&fStatistics.packetsSent, 1); 1348 TRACE("%s::%s SendToNext\n",__FILE__,__func__); 1323 1349 return SendToNext(packet, 0); 1324 1350 // this is normally the device, but there can be something inbetween 1325 1351 } else { 1326 1352 // the multilink protocol should have sent it to some child interface 1327 m_freem(packet); 1353 TRACE("It is weird to go here!\n"); 1354 gBufferModule->free(packet); 1328 1355 return B_ERROR; 1329 1356 } 1330 1357 } … … KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber) 1348 1375 - \c PPP_DISCARDED: The protocol handler(s) did not handle this packet. 1349 1376 */ 1350 1377 status_t 1351 KPPPInterface::Receive( struct mbuf*packet, uint16 protocolNumber)1378 KPPPInterface::Receive(net_buffer *packet, uint16 protocolNumber) 1352 1379 { 1353 1380 TRACE("KPPPInterface: Receive(0x%X)\n", protocolNumber); 1354 1381 1355 1382 if (!packet) 1356 1383 return B_ERROR; 1357 1384 1358 LockerHelper locker(fLock);1385 MutexLocker locker(fLock); 1359 1386 1360 1387 int32 result = PPP_REJECTED; 1361 1388 // assume we have no handler 1362 1389 1363 // Set our interface as the receiver. 1364 // The real netstack protocols (IP, IPX, etc.) might get confused if our 1365 // interface is a main interface and at the same time not registered 1366 // because then there is no receiver interface. 1367 // PPP NCPs should be aware of that! 1368 if (packet->m_flags & M_PKTHDR && Ifnet() != NULL) 1369 packet->m_pkthdr.rcvif = Ifnet(); 1390 if (protocolNumber==0x0021 && Device() && Device()->IsUp()){ //IP_PROTOCOL 0x0021 1391 TRACE("%s::%s: receiving IP packet\n", __FILE__, __func__); 1392 ppp_device* dev=(ppp_device*)Ifnet(); 1393 1394 if(dev){ 1395 return gStackModule->fifo_enqueue_buffer(&(dev->ppp_fifo), packet); 1396 } else { 1397 dprintf("%s::%s: no ppp_device\n", __FILE__, __func__); 1398 return B_ERROR; 1399 } 1400 } 1401 // // Set our interface as the receiver. 1402 // // The real netstack protocols (IP, IPX, etc.) might get confused if our 1403 // // interface is a main interface and at the same time not registered 1404 // // because then there is no receiver interface. 1405 // // PPP NCPs should be aware of that! 1406 // if (packet->m_flags & M_PKTHDR && Ifnet() != NULL) 1407 // packet->m_pkthdr.rcvif = Ifnet(); 1370 1408 1371 1409 // Find handler and let it parse the packet. 1372 1410 // The handler does need not be up because if we are a server … … KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber) 1396 1434 return Parent()->Receive(packet, protocolNumber); 1397 1435 1398 1436 if (result == PPP_UNHANDLED) { 1399 m_freem(packet);1437 gBufferModule->free(packet); 1400 1438 return PPP_DISCARDED; 1401 1439 } else { 1402 1440 StateMachine().RUCEvent(packet, protocolNumber); … … KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber) 1419 1457 - \c PPP_DISCARDED: The protocol handler(s) did not handle this packet. 1420 1458 */ 1421 1459 status_t 1422 KPPPInterface::ReceiveFromDevice( struct mbuf*packet)1460 KPPPInterface::ReceiveFromDevice(net_buffer *packet) 1423 1461 { 1424 1462 TRACE("KPPPInterface: ReceiveFromDevice()\n"); 1425 1463 … … KPPPInterface::ReceiveFromDevice(struct mbuf *packet) 1427 1465 return B_ERROR; 1428 1466 1429 1467 if (InitCheck() != B_OK) { 1430 m_freem(packet);1468 gBufferModule->free(packet); 1431 1469 return B_ERROR; 1432 1470 } 1433 1471 1434 uint32 length = packet->m_flags & M_PKTHDR ? (uint32) packet->m_pkthdr.len : 1435 packet->m_len; 1436 1472 uint32 length = packet->size; 1437 1473 // decode ppp frame and recognize PFC 1438 uint16 protocolNumber = *mtod(packet, uint8*); 1439 if (protocolNumber & 1) { 1440 m_adj(packet, 1); 1474 NetBufferHeaderReader<uint16> bufferHeader(packet); 1475 if (bufferHeader.Status() < B_OK) 1476 return bufferHeader.Status(); 1477 1478 uint16 &header = bufferHeader.Data(); 1479 uint16 protocolNumber=ntohs(header); //copy the protocol number 1480 TRACE("%s::%s: ppp protocol number:%x\n",__FILE__,__func__,protocolNumber); 1481 1482 bufferHeader.Remove(); 1483 bufferHeader.Sync(); 1484 1485 // PFC only use 1 byte for protocol, the next byte is in first byte of message 1486 if (protocolNumber & (1UL<<8)) { 1487 NetBufferPrepend<uint8> bufferprepend(packet); 1488 if (bufferprepend.Status() < B_OK){ 1489 gBufferModule->free(packet); 1490 return bufferprepend.Status(); 1491 } 1492 1493 uint8 &prepend = bufferprepend.Data(); 1494 prepend = (uint8)(protocolNumber & 0x00FF); 1495 // bufferprepend.Sync(); 1496 1497 TRACE("%s::%s:PFC protocol:%x\n",__FILE__,__func__,protocolNumber>>8); 1441 1498 } else { 1442 protocolNumber = ntohs(*mtod(packet, uint16*)); 1443 m_adj(packet, 2); 1499 TRACE("%s::%s:Non-PFC protocol:%x\n",__FILE__,__func__, protocolNumber); 1444 1500 } 1445 1501 1446 1502 atomic_add64(&fStatistics.bytesReceived, length); 1447 1503 atomic_add64(&fStatistics.packetsReceived, 1); 1448 1504 return Receive(packet, protocolNumber); … … KPPPInterface::ReceiveFromDevice(struct mbuf *packet) 1453 1509 void 1454 1510 KPPPInterface::Pulse() 1455 1511 { 1456 LockerHelper locker(fLock);1512 MutexLocker locker(fLock); 1457 1513 1458 1514 if (Device()) 1459 1515 Device()->Pulse(); … … KPPPInterface::RegisterInterface() 1485 1541 return true; 1486 1542 // we are already registered 1487 1543 1488 LockerHelper locker(fLock);1544 MutexLocker locker(fLock); 1489 1545 1490 1546 // only MainInterfaces get an ifnet 1491 1547 if (IsMultilink() && Parent() && Parent()->RegisterInterface()) … … KPPPInterface::RegisterInterface() 1496 1552 1497 1553 fIfnet = fManager->RegisterInterface(ID()); 1498 1554 1499 if (!fIfnet) 1555 if (!fIfnet){ 1556 dprintf("%s:%s: damn it no fIfnet device\n", __FILE__, __func__); 1500 1557 return false; 1558 } 1501 1559 1502 1560 if (DoesConnectOnDemand()) 1503 fIfnet-> if_flags |= IFF_UP;1561 fIfnet->flags |= IFF_UP; 1504 1562 1505 1563 CalculateInterfaceMTU(); 1506 1564 CalculateBaudRate(); … … KPPPInterface::UnregisterInterface() 1519 1577 return true; 1520 1578 // we are already unregistered 1521 1579 1522 LockerHelper locker(fLock);1580 MutexLocker locker(fLock); 1523 1581 1524 1582 // only MainInterfaces get an ifnet 1525 1583 if (IsMultilink() && Parent()) … … KPPPInterface::StackControlEachHandler(uint32 op, void *data) 1587 1645 1588 1646 status_t result = B_BAD_VALUE, tmp; 1589 1647 1590 LockerHelper locker(fLock);1648 MutexLocker locker(fLock); 1591 1649 1592 1650 KPPPProtocol *protocol = FirstProtocol(); 1593 1651 for (; protocol; protocol = protocol->NextProtocol()) { … … KPPPInterface::CalculateInterfaceMTU() 1613 1671 { 1614 1672 TRACE("KPPPInterface: CalculateInterfaceMTU()\n"); 1615 1673 1616 LockerHelper locker(fLock); 1674 // MutexLocker locker(fLock); 1675 //uncomment this line will cause double lock 1676 //alreay locked in ::KPPPInterface 1617 1677 1618 1678 fInterfaceMTU = fMRU; 1619 1679 fHeaderLength = 2; … … KPPPInterface::CalculateInterfaceMTU() 1628 1688 fInterfaceMTU -= fHeaderLength; 1629 1689 1630 1690 if (Ifnet()) { 1631 Ifnet()->if_mtu = fInterfaceMTU; 1632 Ifnet()->if_hdrlen = fHeaderLength; 1691 Ifnet()->mtu = fInterfaceMTU; 1692 Ifnet()->header_length = fHeaderLength; 1693 return; 1633 1694 } 1634 1695 1635 1696 if (Parent()) … … KPPPInterface::CalculateBaudRate() 1643 1704 { 1644 1705 TRACE("KPPPInterface: CalculateBaudRate()\n"); 1645 1706 1646 LockerHelper locker(fLock);1707 // MutexLocker locker(fLock); //uncomment this will cause double lock 1647 1708 1648 1709 if (!Ifnet()) 1649 1710 return; 1650 1711 1651 1712 if (Device()) 1652 fIfnet-> if_baudrate= max_c(Device()->InputTransferRate(),1653 1713 fIfnet->link_speed = max_c(Device()->InputTransferRate(), 1714 Device()->OutputTransferRate()); 1654 1715 else { 1655 fIfnet-> if_baudrate= 0;1716 fIfnet->link_speed = 0; 1656 1717 for (int32 index = 0; index < CountChildren(); index++) 1657 1718 if (ChildAt(index)->Ifnet()) 1658 fIfnet->if_baudrate += ChildAt(index)->Ifnet()->if_baudrate; 1719 fIfnet->link_speed += ChildAt(index)->Ifnet()->link_speed; 1720 return; 1659 1721 } 1660 1722 } 1661 1723 … … KPPPInterface::Reconnect(uint32 delay) 1666 1728 { 1667 1729 TRACE("KPPPInterface: Reconnect(%ld)\n", delay); 1668 1730 1669 LockerHelper locker(fLock);1731 MutexLocker locker(fLock); 1670 1732 1671 1733 if (fReconnectThread != -1) 1672 1734 return; -
src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLCP.cpp
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 d84a072..1f05cf4 100644
a b 20 20 #include <KPPPOptionHandler.h> 21 21 22 22 #include <netinet/in.h> 23 #include <core_funcs.h> 23 24 #include <net_buffer.h> 24 25 #include <sys/socket.h> 25 26 27 extern net_buffer_module_info *gBufferModule; 28 26 29 27 30 //! Creates a new LCP protocol for the given interface. 28 31 KPPPLCP::KPPPLCP(KPPPInterface& interface) … … KPPPLCP::Down() 230 233 231 234 //! Sends a packet to the target (if there is one) or to the interface. 232 235 status_t 233 KPPPLCP::Send( struct mbuf*packet, uint16 protocolNumber)236 KPPPLCP::Send(net_buffer *packet, uint16 protocolNumber) 234 237 { 235 238 if (Target()) 236 239 return Target()->Send(packet, PPP_LCP_PROTOCOL); … … KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber) 241 244 242 245 //! Decodes the LCP packet and passes it to the KPPPStateMachine or an LCP extension. 243 246 status_t 244 KPPPLCP::Receive( struct mbuf*packet, uint16 protocolNumber)247 KPPPLCP::Receive(net_buffer *packet, uint16 protocolNumber) 245 248 { 246 249 if (!packet) 247 250 return B_ERROR; … … KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber) 250 253 ERROR("KPPPLCP::Receive(): wrong protocol number!\n"); 251 254 return PPP_UNHANDLED; 252 255 } 253 254 ppp_lcp_packet *data = mtod(packet, ppp_lcp_packet*); 256 257 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 258 if (bufferHeader.Status() < B_OK) 259 return bufferHeader.Status(); 260 261 ppp_lcp_packet &data = bufferHeader.Data(); 255 262 256 263 // remove padding 257 int32 length = packet->m_len;258 if (packet->m_flags & M_PKTHDR)259 length = packet->m_pkthdr.len;260 length -= ntohs(data->length);261 if (length)262 m_adj(packet, -length);263 264 struct mbuf *copy = m_gethdr(MT_DATA);265 if (copy) {266 copy->m_data += AdditionalOverhead();267 copy->m_pkthdr.len = copy->m_len = packet->m_len;268 memcpy(copy->m_data, packet->m_data, copy->m_len);269 }270 264 271 if (ntohs(data->length) < 4) 265 net_buffer *copy=gBufferModule->duplicate(packet); 266 267 if (ntohs(data.length) < 4) 272 268 return B_ERROR; 273 269 274 270 bool handled = true; 275 271 276 switch (data ->code) {272 switch (data.code) { 277 273 case PPP_CONFIGURE_REQUEST: 278 274 StateMachine().RCREvent(packet); 279 275 break; … … KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber) 310 306 break; 311 307 312 308 default: 313 m_freem(packet);309 // gBufferModule->free(packet); 314 310 handled = false; 315 311 } 316 312 … … KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber) 324 320 // Try to find LCP extensions that can handle this code. 325 321 // We must duplicate the packet in order to ask all handlers. 326 322 int32 index = 0; 327 KPPPLCPExtension *lcpExtension = LCPExtensionFor(data ->code, &index);328 for (; lcpExtension; lcpExtension = LCPExtensionFor(data ->code, &(++index))) {323 KPPPLCPExtension *lcpExtension = LCPExtensionFor(data.code, &index); 324 for (; lcpExtension; lcpExtension = LCPExtensionFor(data.code, &(++index))) { 329 325 if (!lcpExtension->IsEnabled()) 330 326 continue; 331 327 332 result = lcpExtension->Receive(packet, data ->code);328 result = lcpExtension->Receive(packet, data.code); 333 329 334 330 // check return value and return it on error 335 331 if (result == B_OK) 336 332 handled = true; 337 333 else if (result != PPP_UNHANDLED) { 338 m_freem(packet);334 gBufferModule->free(packet); 339 335 return result; 340 336 } 341 337 } … … KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber) 345 341 return PPP_REJECTED; 346 342 } 347 343 348 m_freem(packet);344 gBufferModule->free(packet); 349 345 350 346 return result; 351 347 } -
src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp
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 b967e22..9515921 100644
a b 19 19 20 20 #include <KPPPLayer.h> 21 21 22 #include <net_buffer.h> 23 22 24 #include <cstdlib> 23 25 #include <cstring> 24 #include <core_funcs.h>25 26 27 extern net_buffer_module_info *gBufferModule; 26 28 27 29 /*! \brief Creates a new layer. 28 30 … … KPPPLayer::InitCheck() const 56 58 57 59 //! Sends a packet to the next layer in the chain. 58 60 status_t 59 KPPPLayer::SendToNext( struct mbuf*packet, uint16 protocolNumber) const61 KPPPLayer::SendToNext(net_buffer *packet, uint16 protocolNumber) const 60 62 { 61 63 if (!packet) 62 64 return B_ERROR; … … KPPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const 70 72 return Next()->SendToNext(packet, protocolNumber); 71 73 } else { 72 74 ERROR("KPPPLayer: SendToNext() failed because there is no next handler!\n"); 73 m_freem(packet);75 gBufferModule->free(packet); 74 76 return B_ERROR; 75 77 } 76 78 } -
src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPReportManager.cpp
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 17acd2b..847b351 100644
a b 9 9 10 10 #include <KPPPReportManager.h> 11 11 12 #include <LockerHelper.h> 12 #include <lock.h> 13 #include <util/AutoLock.h> 14 13 15 #include <KPPPUtils.h> 14 16 15 17 … … report_sender_thread(void *data) 33 35 34 36 \param lock The BLocker that should be used by this report manager. 35 37 */ 36 KPPPReportManager::KPPPReportManager( BLocker& lock)38 KPPPReportManager::KPPPReportManager(mutex& lock) 37 39 : fLock(lock) 38 40 { 39 41 } … … KPPPReportManager::EnableReports(ppp_report_type type, thread_id thread, 88 90 if (thread < 0 || type == PPP_ALL_REPORTS) 89 91 return; 90 92 91 LockerHelper locker(fLock);93 MutexLocker locker(fLock); 92 94 93 95 ppp_report_request *request = new ppp_report_request; 94 96 request->type = type; … … KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread) 106 108 if (thread < 0) 107 109 return; 108 110 109 LockerHelper locker(fLock);111 MutexLocker locker(fLock); 110 112 111 113 ppp_report_request *request; 112 114 … … KPPPReportManager::DoesReport(ppp_report_type type, thread_id thread) 135 137 if (thread < 0) 136 138 return false; 137 139 138 LockerHelper locker(fLock);140 MutexLocker locker(fLock); 139 141 140 142 ppp_report_request *request; 141 143 … … KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 le 177 179 if (!data) 178 180 length = 0; 179 181 180 LockerHelper locker(fLock);182 MutexLocker locker(fLock); 181 183 182 184 status_t result; 183 185 thread_id me = find_thread(NULL); -
src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPStateMachine.cpp
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 06f30ba..9867485 100644
a b 22 22 #include <KPPPUtils.h> 23 23 24 24 #include <net/if.h> 25 #include <core_funcs.h>26 25 26 #include <net_buffer.h> 27 #include <ByteOrder.h> 28 #include <NetBufferUtilities.h> 29 30 extern net_buffer_module_info *gBufferModule; 27 31 28 32 static const bigtime_t kPPPStateMachineTimeout = 3000000; 29 33 // 3 seconds … … KPPPStateMachine::KPPPStateMachine(KPPPInterface& interface) 48 52 fRequestID(0), 49 53 fTerminateID(0), 50 54 fEchoID(0), 51 fNextTimeout(0) ,52 fLock("KPPPStateMachine")55 fNextTimeout(0)//, 56 //fLock("KPPPStateMachine") 53 57 { 58 mutex_init(&fLock,"KPPPStateMachine"); 54 59 } 55 60 56 61 … … KPPPStateMachine::NewPhase(ppp_phase next) 114 119 // The report threads get their notification later. 115 120 if (Phase() == PPP_ESTABLISHED_PHASE && next != Phase()) { 116 121 if (Interface().Ifnet()) { 117 Interface().Ifnet()->if_flags &= ~IFF_RUNNING;118 Interface().Ifnet()-> if_flags &= ~IFF_UP;122 // Interface().Ifnet()->flags &= ~IFF_RUNNING; 123 Interface().Ifnet()->flags &= ~IFF_UP; 119 124 } 120 125 121 126 if (Interface().Parent()) … … KPPPStateMachine::NewPhase(ppp_phase next) 128 133 Interface().fConnectedSince = system_time(); 129 134 130 135 if (Interface().Ifnet()) 131 Interface().Ifnet()-> if_flags |= IFF_UP| IFF_RUNNING;136 Interface().Ifnet()->flags |= IFF_UP;// | IFF_RUNNING; 132 137 133 138 Interface().fConnectAttempt = 0; 134 139 // when we Reconnect() this becomes 1 (the first connection attempt) … … KPPPStateMachine::SendEchoRequest() 172 177 if (State() != PPP_OPENED_STATE) 173 178 return false; 174 179 175 struct mbuf *packet = m_gethdr(MT_DATA);176 if (!packet)180 net_buffer *packet = gBufferModule->create(256); 181 if (packet == NULL) 177 182 return false; 178 179 packet->m_data += LCP().AdditionalOverhead(); 180 packet->m_pkthdr.len = packet->m_len = 8; 181 // echo requests are at least eight bytes long 182 183 ppp_lcp_packet *request = mtod(packet, ppp_lcp_packet*); 184 request->code = PPP_ECHO_REQUEST; 185 request->id = NextID(); 186 fEchoID = request->id; 187 request->length = htons(packet->m_len); 188 memcpy(request->data, &fMagicNumber, sizeof(fMagicNumber)); 183 184 void *data; 185 status_t status = gBufferModule->append_size(packet, 1492, &data); 186 if (status == B_OK && data == NULL) { 187 gBufferModule->free(packet); 188 return false; 189 } 190 191 // echo requests are at least eight bytes long 192 ppp_lcp_packet request; 193 request.code = PPP_ECHO_REQUEST; 194 request.id = NextID(); 195 request.length = htons(8); 196 fEchoID = request.id; 197 198 memcpy(data, &request, sizeof(request)); 199 memcpy(request.data, &fMagicNumber, sizeof(fMagicNumber)); 200 201 status = gBufferModule->trim(packet, sizeof(request)+sizeof(fMagicNumber)); 202 if (status < B_OK) { 203 gBufferModule->free(packet); 204 return false; 205 } 189 206 190 207 return LCP().Send(packet) == B_OK; 191 208 } … … KPPPStateMachine::SendDiscardRequest() 197 214 { 198 215 TRACE("KPPPSM: SendDiscardRequest() state=%d phase=%d\n", State(), Phase()); 199 216 200 if (State() != PPP_OPENED_STATE) 217 net_buffer *packet = gBufferModule->create(256); 218 if (packet == NULL) 201 219 return false; 202 203 struct mbuf *packet = m_gethdr(MT_DATA); 204 if (!packet) 220 221 void *data; 222 status_t status = gBufferModule->append_size(packet, 1492, &data); 223 if (status == B_OK && data == NULL) { 224 gBufferModule->free(packet); 205 225 return false; 206 207 packet->m_data += LCP().AdditionalOverhead(); 208 packet->m_pkthdr.len = packet->m_len = 8; 226 } 227 209 228 // discard requests are at least eight bytes long 210 211 ppp_lcp_packet *request = mtod(packet, ppp_lcp_packet*); 212 request->code = PPP_DISCARD_REQUEST; 213 request->id = NextID(); 214 request->length = htons(packet->m_len); 215 memcpy(request->data, &fMagicNumber, sizeof(fMagicNumber)); 229 // echo requests are at least eight bytes long 230 ppp_lcp_packet request; 231 request.code = PPP_DISCARD_REQUEST; 232 request.id = NextID(); 233 request.length = htons(8); 234 fEchoID = request.id; 235 236 memcpy(data, &request, sizeof(request)); 237 memcpy(request.data, &fMagicNumber, sizeof(fMagicNumber)); 238 239 status = gBufferModule->trim(packet, sizeof(request)+sizeof(fMagicNumber)); 240 if (status < B_OK) { 241 gBufferModule->free(packet); 242 return false; 243 } 216 244 217 245 return LCP().Send(packet) == B_OK; 218 246 } … … KPPPStateMachine::TOBadEvent() 893 921 894 922 // receive configure request (acceptable request) 895 923 void 896 KPPPStateMachine::RCRGoodEvent( struct mbuf*packet)924 KPPPStateMachine::RCRGoodEvent(net_buffer *packet) 897 925 { 898 926 TRACE("KPPPSM: RCRGoodEvent() state=%d phase=%d\n", State(), Phase()); 899 927 900 928 switch (State()) { 901 929 case PPP_INITIAL_STATE: 902 930 case PPP_STARTING_STATE: 931 TRACE("%s::%s: PPP_STARTING_STATE\n",__FILE__,__func__); 903 932 IllegalEvent(PPP_RCR_GOOD_EVENT); 904 m_freem(packet);933 gBufferModule->free(packet); 905 934 break; 906 935 907 936 case PPP_CLOSED_STATE: 937 TRACE("%s::%s: PPP_CLOSED_STATE\n",__FILE__,__func__); 908 938 SendTerminateAck(); 909 m_freem(packet);939 gBufferModule->free(packet); 910 940 break; 911 941 912 942 case PPP_STOPPED_STATE: 943 TRACE("%s::%s: PPP_STOPPED_STATE\n",__FILE__,__func__); 913 944 // irc,scr,sca/8 914 945 // XXX: should we do nothing and wait for DownEvent()? 915 m_freem(packet);946 gBufferModule->free(packet); 916 947 break; 917 948 918 949 case PPP_REQ_SENT_STATE: 919 950 NewState(PPP_ACK_SENT_STATE); 920 951 921 952 case PPP_ACK_SENT_STATE: 953 TRACE("%s::%s: PPP_ACK_SENT_STATE size %ld\n",__FILE__,__func__, 954 packet->size); 922 955 SendConfigureAck(packet); 923 956 break; 924 957 925 958 case PPP_ACK_RCVD_STATE: 959 TRACE("%s::%s: PPP_ACK_RCVD_STATE\n",__FILE__,__func__); 926 960 NewState(PPP_OPENED_STATE); 927 961 SendConfigureAck(packet); 928 962 ThisLayerUp(); 929 963 break; 930 964 931 965 case PPP_OPENED_STATE: 966 TRACE("%s::%s: PPP_OPENED_STATE\n",__FILE__,__func__); 932 967 NewState(PPP_ACK_SENT_STATE); 933 968 NewPhase(PPP_ESTABLISHMENT_PHASE); 934 969 // indicates to handlers that we are reconfiguring … … KPPPStateMachine::RCRGoodEvent(struct mbuf *packet) 938 973 break; 939 974 940 975 default: 941 m_freem(packet); 976 TRACE("free peer's ppp request packet\n"); 977 gBufferModule->free(packet); 942 978 } 943 979 } 944 980 945 981 946 982 // receive configure request (unacceptable request) 947 983 void 948 KPPPStateMachine::RCRBadEvent( struct mbuf *nak, struct mbuf*reject)984 KPPPStateMachine::RCRBadEvent(net_buffer *nak, net_buffer *reject) 949 985 { 950 986 TRACE("KPPPSM: RCRBadEvent() state=%d phase=%d\n", State(), Phase()); 987 988 uint16 nak_len,reject_len; 951 989 952 990 switch (State()) { 953 991 case PPP_INITIAL_STATE: … … KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) 978 1016 979 1017 case PPP_REQ_SENT_STATE: 980 1018 case PPP_ACK_RCVD_STATE: 981 if (nak && ntohs(mtod(nak, ppp_lcp_packet*)->length) > 3) 1019 if (nak) { 1020 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader_nak(nak); 1021 if (bufferHeader_nak.Status() < B_OK) 1022 break; 1023 ppp_lcp_packet &header_nak = bufferHeader_nak.Data(); 1024 nak_len=header_nak.length; 1025 } 1026 1027 if (reject) { 1028 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader_reject(reject); 1029 if (bufferHeader_reject.Status() < B_OK) 1030 break; 1031 ppp_lcp_packet &header_reject = bufferHeader_reject.Data(); 1032 reject_len=header_reject.length; 1033 } 1034 1035 if (nak && nak_len > 3) 982 1036 SendConfigureNak(nak); 983 else if (reject && ntohs(mtod(reject, ppp_lcp_packet*)->length)> 3)1037 else if (reject && reject_len > 3) 984 1038 SendConfigureNak(reject); 985 1039 return; 986 1040 // prevents the nak/reject from being m_freem()'d … … KPPPStateMachine::RCRBadEvent(struct mbuf *nak, struct mbuf *reject) 990 1044 } 991 1045 992 1046 if (nak) 993 m_freem(nak);1047 gBufferModule->free(nak); 994 1048 if (reject) 995 m_freem(reject);1049 gBufferModule->free(reject); 996 1050 } 997 1051 998 1052 999 1053 // receive configure ack 1000 1054 void 1001 KPPPStateMachine::RCAEvent( struct mbuf*packet)1055 KPPPStateMachine::RCAEvent(net_buffer *packet) 1002 1056 { 1003 1057 TRACE("KPPPSM: RCAEvent() state=%d phase=%d\n", State(), Phase()); 1004 1058 1005 if (fRequestID != mtod(packet, ppp_lcp_packet*)->id) { 1059 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 1060 if (bufferHeader.Status() < B_OK) 1061 return; 1062 ppp_lcp_packet &header = bufferHeader.Data(); 1063 1064 if (fRequestID != header.id) { 1006 1065 // this packet is not a reply to our request 1007 1066 1008 1067 // TODO: 1009 1068 // log this event 1010 m_freem(packet);1069 gBufferModule->free(packet); 1011 1070 return; 1012 1071 } 1013 1072 … … KPPPStateMachine::RCAEvent(struct mbuf *packet) 1017 1076 for (int32 index = 0; index < LCP().CountOptionHandlers(); index++) { 1018 1077 optionHandler = LCP().OptionHandlerAt(index); 1019 1078 if (optionHandler->ParseAck(ack) != B_OK) { 1020 m_freem(packet);1079 gBufferModule->free(packet); 1021 1080 CloseEvent(); 1022 1081 return; 1023 1082 } … … KPPPStateMachine::RCAEvent(struct mbuf *packet) 1062 1121 ; 1063 1122 } 1064 1123 1065 m_freem(packet);1124 gBufferModule->free(packet); 1066 1125 } 1067 1126 1068 1127 1069 1128 // receive configure nak/reject 1070 1129 void 1071 KPPPStateMachine::RCNEvent( struct mbuf*packet)1130 KPPPStateMachine::RCNEvent(net_buffer *packet) 1072 1131 { 1073 1132 TRACE("KPPPSM: RCNEvent() state=%d phase=%d\n", State(), Phase()); 1074 1133 1075 if (fRequestID != mtod(packet, ppp_lcp_packet*)->id) { 1134 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 1135 if (bufferHeader.Status() < B_OK) 1136 return; 1137 ppp_lcp_packet &header = bufferHeader.Data(); 1138 1139 if (fRequestID != header.id) { 1076 1140 // this packet is not a reply to our request 1077 1141 1078 1142 // TODO: 1079 1143 // log this event 1080 m_freem(packet);1144 gBufferModule->free(packet); 1081 1145 return; 1082 1146 } 1083 1147 … … KPPPStateMachine::RCNEvent(struct mbuf *packet) 1089 1153 1090 1154 if (nak_reject.Code() == PPP_CONFIGURE_NAK) { 1091 1155 if (optionHandler->ParseNak(nak_reject) != B_OK) { 1092 m_freem(packet);1156 gBufferModule->free(packet); 1093 1157 CloseEvent(); 1094 1158 return; 1095 1159 } 1096 1160 } else if (nak_reject.Code() == PPP_CONFIGURE_REJECT) { 1097 1161 if (optionHandler->ParseReject(nak_reject) != B_OK) { 1098 m_freem(packet);1162 gBufferModule->free(packet); 1099 1163 CloseEvent(); 1100 1164 return; 1101 1165 } … … KPPPStateMachine::RCNEvent(struct mbuf *packet) 1135 1199 ; 1136 1200 } 1137 1201 1138 m_freem(packet);1202 gBufferModule->free(packet); 1139 1203 } 1140 1204 1141 1205 1142 1206 // receive terminate request 1143 1207 void 1144 KPPPStateMachine::RTREvent( struct mbuf*packet)1208 KPPPStateMachine::RTREvent(net_buffer *packet) 1145 1209 { 1146 1210 TRACE("KPPPSM: RTREvent() state=%d phase=%d\n", State(), Phase()); 1147 1211 1212 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 1213 if (bufferHeader.Status() < B_OK) 1214 return; 1215 ppp_lcp_packet &header = bufferHeader.Data(); 1216 1148 1217 // we should not use the same ID as the peer 1149 if (fID == mtod(packet, ppp_lcp_packet*)->id)1218 if (fID == header.id) 1150 1219 fID -= 128; 1151 1220 1152 1221 fLocalAuthenticationStatus = PPP_NOT_AUTHENTICATED; … … KPPPStateMachine::RTREvent(struct mbuf *packet) 1156 1225 case PPP_INITIAL_STATE: 1157 1226 case PPP_STARTING_STATE: 1158 1227 IllegalEvent(PPP_RTR_EVENT); 1159 m_freem(packet);1228 gBufferModule->free(packet); 1160 1229 break; 1161 1230 1162 1231 case PPP_ACK_RCVD_STATE: … … KPPPStateMachine::RTREvent(struct mbuf *packet) 1186 1255 1187 1256 // receive terminate ack 1188 1257 void 1189 KPPPStateMachine::RTAEvent( struct mbuf*packet)1258 KPPPStateMachine::RTAEvent(net_buffer *packet) 1190 1259 { 1191 1260 TRACE("KPPPSM: RTAEvent() state=%d phase=%d\n", State(), Phase()); 1192 1261 1193 if (fTerminateID != mtod(packet, ppp_lcp_packet*)->id) { 1262 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 1263 if (bufferHeader.Status() < B_OK) 1264 return; 1265 ppp_lcp_packet &header = bufferHeader.Data(); 1266 1267 if (fTerminateID != header.id) { 1194 1268 // this packet is not a reply to our request 1195 1269 1196 1270 // TODO: 1197 1271 // log this event 1198 m_freem(packet);1272 gBufferModule->free(packet); 1199 1273 return; 1200 1274 } 1201 1275 … … KPPPStateMachine::RTAEvent(struct mbuf *packet) 1231 1305 ; 1232 1306 } 1233 1307 1234 m_freem(packet);1308 gBufferModule->free(packet); 1235 1309 } 1236 1310 1237 1311 1238 1312 // receive unknown code 1239 1313 void 1240 KPPPStateMachine::RUCEvent( struct mbuf*packet, uint16 protocolNumber,1314 KPPPStateMachine::RUCEvent(net_buffer *packet, uint16 protocolNumber, 1241 1315 uint8 code) 1242 1316 { 1243 1317 TRACE("KPPPSM: RUCEvent() state=%d phase=%d\n", State(), Phase()); … … KPPPStateMachine::RUCEvent(struct mbuf *packet, uint16 protocolNumber, 1246 1320 case PPP_INITIAL_STATE: 1247 1321 case PPP_STARTING_STATE: 1248 1322 IllegalEvent(PPP_RUC_EVENT); 1249 m_freem(packet);1323 gBufferModule->free(packet); 1250 1324 break; 1251 1325 1252 1326 default: … … KPPPStateMachine::RUCEvent(struct mbuf *packet, uint16 protocolNumber, 1257 1331 1258 1332 // receive code/protocol reject (acceptable such as IPX reject) 1259 1333 void 1260 KPPPStateMachine::RXJGoodEvent( struct mbuf*packet)1334 KPPPStateMachine::RXJGoodEvent(net_buffer *packet) 1261 1335 { 1262 1336 TRACE("KPPPSM: RXJGoodEvent() state=%d phase=%d\n", State(), Phase()); 1263 1337 … … KPPPStateMachine::RXJGoodEvent(struct mbuf *packet) 1282 1356 1283 1357 // receive code/protocol reject (catastrophic such as LCP reject) 1284 1358 void 1285 KPPPStateMachine::RXJBadEvent( struct mbuf*packet)1359 KPPPStateMachine::RXJBadEvent(net_buffer *packet) 1286 1360 { 1287 1361 TRACE("KPPPSM: RXJBadEvent() state=%d phase=%d\n", State(), Phase()); 1288 1362 … … KPPPStateMachine::RXJBadEvent(struct mbuf *packet) 1321 1395 break; 1322 1396 } 1323 1397 1324 m_freem(packet);1398 gBufferModule->free(packet); 1325 1399 } 1326 1400 1327 1401 1328 1402 // receive echo request/reply, discard request 1329 1403 void 1330 KPPPStateMachine::RXREvent( struct mbuf*packet)1404 KPPPStateMachine::RXREvent(net_buffer *packet) 1331 1405 { 1332 1406 TRACE("KPPPSM: RXREvent() state=%d phase=%d\n", State(), Phase()); 1333 1407 1334 ppp_lcp_packet *echo = mtod(packet, ppp_lcp_packet*); 1408 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 1409 if (bufferHeader.Status() < B_OK) 1410 return; 1411 ppp_lcp_packet &echo = bufferHeader.Data(); 1335 1412 1336 if (echo ->code == PPP_ECHO_REPLY && echo->id != fEchoID) {1413 if (echo.code == PPP_ECHO_REPLY && echo.id != fEchoID) { 1337 1414 // TODO: 1338 1415 // log that we got a reply, but no request was sent 1339 1416 } … … KPPPStateMachine::RXREvent(struct mbuf *packet) 1345 1422 break; 1346 1423 1347 1424 case PPP_OPENED_STATE: 1348 if (echo ->code == PPP_ECHO_REQUEST)1425 if (echo.code == PPP_ECHO_REQUEST) 1349 1426 SendEchoReply(packet); 1350 1427 return; 1351 1428 // this prevents the packet from being freed … … KPPPStateMachine::RXREvent(struct mbuf *packet) 1354 1431 ; 1355 1432 } 1356 1433 1357 m_freem(packet);1434 gBufferModule->free(packet); 1358 1435 } 1359 1436 1360 1437 … … KPPPStateMachine::TimerEvent() 1397 1474 1398 1475 1399 1476 // ReceiveConfigureRequest 1400 // Here we get a configure-request packet from LCP and a ksall OptionHandlers1477 // Here we get a configure-request packet from LCP and ask all OptionHandlers 1401 1478 // if its values are acceptable. From here we call our Good/Bad counterparts. 1402 1479 void 1403 KPPPStateMachine::RCREvent( struct mbuf*packet)1480 KPPPStateMachine::RCREvent(net_buffer *packet) 1404 1481 { 1405 TRACE("KPPPSM: RCREvent() state=%d phase=%d\n", State(), Phase()); 1482 TRACE("KPPPSM: RCREvent() state=%d phase=%d lcppacket size=%ld\n", State(), Phase(), 1483 packet->size); 1406 1484 1407 1485 KPPPConfigurePacket request(packet); 1408 1486 KPPPConfigurePacket nak(PPP_CONFIGURE_NAK); 1409 1487 KPPPConfigurePacket reject(PPP_CONFIGURE_REJECT); 1410 1488 1489 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 1490 if (bufferHeader.Status() < B_OK) 1491 return; 1492 ppp_lcp_packet &header = bufferHeader.Data(); 1493 1411 1494 // we should not use the same id as the peer 1412 if (fID == mtod(packet, ppp_lcp_packet*)->id)1495 if (fID == header.id) 1413 1496 fID -= 128; 1497 // or maybe we should use peer's ID plus 1 ? 1414 1498 1415 1499 nak.SetID(request.ID()); 1416 1500 reject.SetID(request.ID()); … … KPPPStateMachine::RCREvent(struct mbuf *packet) 1423 1507 optionHandler = LCP().OptionHandlerFor(request.ItemAt(index)->type); 1424 1508 1425 1509 if (!optionHandler || !optionHandler->IsEnabled()) { 1426 ERROR("KPPPSM::RCREvent():unknown type:%d\n", request.ItemAt(index)->type); 1427 // unhandled items should be added to the reject 1428 reject.AddItem(request.ItemAt(index)); 1429 continue; 1510 TRACE("KPPPSM::RCREvent():unknown type:%d\n", request.ItemAt(index)->type); 1511 if(request.ItemAt(index)->type==0x5) 1512 { 1513 // type 0x5 is Magic Number, Need no processing. 1514 TRACE("Peer Magic Number:%02x %02x %02x %02x\n", 1515 (request.ItemAt(index)->data)[0], 1516 (request.ItemAt(index)->data)[1], 1517 (request.ItemAt(index)->data)[2], 1518 (request.ItemAt(index)->data)[3]); 1519 continue; 1520 } else { 1521 // unhandled items should be added to the reject 1522 TRACE("why come here %ld\n",index); 1523 reject.AddItem(request.ItemAt(index)); 1524 continue; 1525 } 1430 1526 } 1431 1527 1432 1528 TRACE("KPPPSM::RCREvent(): OH=%s\n", … … KPPPStateMachine::RCREvent(struct mbuf *packet) 1435 1531 1436 1532 if (result == PPP_UNHANDLED) { 1437 1533 // unhandled items should be added to the reject 1534 TRACE("PPP_UNHANDLED %ld\n",index); 1438 1535 reject.AddItem(request.ItemAt(index)); 1439 1536 continue; 1440 1537 } else if (result != B_OK) { 1441 1538 // the request contains a value that has been sent more than 1442 1539 // once or the value is corrupted 1443 1540 ERROR("KPPPSM::RCREvent(): OptionHandler returned parse error!\n"); 1444 m_freem(packet);1541 gBufferModule->free(packet); 1445 1542 CloseEvent(); 1446 1543 return; 1447 1544 } … … KPPPStateMachine::RCREvent(struct mbuf *packet) 1460 1557 // the request contains a value that has been sent more than 1461 1558 // once or the value is corrupted 1462 1559 ERROR("KPPPSM::RCREvent():OptionHandler returned append error!\n"); 1463 m_freem(packet);1560 gBufferModule->free(packet); 1464 1561 CloseEvent(); 1465 1562 return; 1466 1563 } … … KPPPStateMachine::RCREvent(struct mbuf *packet) 1469 1566 } 1470 1567 1471 1568 if (reject.CountItems() > 0) { 1569 TRACE("%s:reject number more than 0\n",__func__); 1472 1570 RCRBadEvent(NULL, reject.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead())); 1473 m_freem(packet);1571 gBufferModule->free(packet); 1474 1572 } else if (nak.CountItems() > 0) { 1573 TRACE("%s:nak number more than 0\n",__func__); 1475 1574 RCRBadEvent(nak.ToMbuf(Interface().MRU(), LCP().AdditionalOverhead()), NULL); 1476 m_freem(packet);1575 gBufferModule->free(packet); 1477 1576 } else 1478 1577 RCRGoodEvent(packet); 1479 1578 } … … KPPPStateMachine::RCREvent(struct mbuf *packet) 1483 1582 // LCP received a code/protocol-reject packet and we look if it is acceptable. 1484 1583 // From here we call our Good/Bad counterparts. 1485 1584 void 1486 KPPPStateMachine::RXJEvent( struct mbuf*packet)1585 KPPPStateMachine::RXJEvent(net_buffer *packet) 1487 1586 { 1488 1587 TRACE("KPPPSM: RXJEvent() state=%d phase=%d\n", State(), Phase()); 1489 1588 1490 ppp_lcp_packet *reject = mtod(packet, ppp_lcp_packet*); 1589 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 1590 if (bufferHeader.Status() < B_OK) 1591 return; 1592 ppp_lcp_packet &reject = bufferHeader.Data(); 1491 1593 1492 if (reject ->code == PPP_CODE_REJECT) {1493 uint8 rejectedCode = reject ->data[0];1594 if (reject.code == PPP_CODE_REJECT) { 1595 uint8 rejectedCode = reject.data[0]; 1494 1596 1495 1597 // test if the rejected code belongs to the minimum LCP requirements 1496 1598 if (rejectedCode >= PPP_MIN_LCP_CODE && rejectedCode <= PPP_MAX_LCP_CODE) { 1497 1599 if (Interface().IsMultilink() && !Interface().Parent()) { 1498 1600 // Main interfaces do not have states between STARTING and OPENED. 1499 1601 // An RXJBadEvent() would enter one of those states which is bad. 1500 m_freem(packet);1602 gBufferModule->free(packet); 1501 1603 CloseEvent(); 1502 1604 } else 1503 1605 RXJBadEvent(packet); … … KPPPStateMachine::RXJEvent(struct mbuf *packet) 1514 1616 lcpExtension->SetEnabled(false); 1515 1617 } 1516 1618 1517 m_freem(packet);1518 } else if (reject ->code == PPP_PROTOCOL_REJECT) {1619 gBufferModule->free(packet); 1620 } else if (reject.code == PPP_PROTOCOL_REJECT) { 1519 1621 // disable all handlers for rejected protocol type 1520 uint16 rejected = *((uint16*) reject ->data);1622 uint16 rejected = *((uint16*) reject.data); 1521 1623 // rejected protocol number 1522 1624 1523 1625 if (rejected == PPP_LCP_PROTOCOL) { … … KPPPStateMachine::RXJEvent(struct mbuf *packet) 1541 1643 if (Interface().Parent()) 1542 1644 Interface().Parent()->StateMachine().RXJEvent(packet); 1543 1645 else 1544 m_freem(packet);1646 gBufferModule->free(packet); 1545 1647 } 1546 1648 } 1547 1649 … … KPPPStateMachine::IllegalEvent(ppp_event event) 1552 1654 { 1553 1655 // TODO: 1554 1656 // update error statistics 1555 ERROR("KPPPSM: IllegalEvent(event=%d) state=%d phase=%d\n",1657 TRACE("KPPPSM: IllegalEvent(event=%d) state=%d phase=%d\n", 1556 1658 event, State(), Phase()); 1557 1659 } 1558 1660 … … KPPPStateMachine::SendConfigureRequest() 1649 1751 1650 1752 1651 1753 bool 1652 KPPPStateMachine::SendConfigureAck( struct mbuf*packet)1754 KPPPStateMachine::SendConfigureAck(net_buffer *packet) 1653 1755 { 1654 1756 TRACE("KPPPSM: SendConfigureAck() state=%d phase=%d\n", State(), Phase()); 1655 1757 1656 1758 if (!packet) 1657 1759 return false; 1658 1760 1659 mtod(packet, ppp_lcp_packet*)->code = PPP_CONFIGURE_ACK; 1761 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 1762 if (bufferHeader.Status() < B_OK) 1763 return false; 1764 ppp_lcp_packet &header = bufferHeader.Data(); 1765 1766 header.code = PPP_CONFIGURE_ACK; 1767 bufferHeader.Sync(); 1768 1660 1769 KPPPConfigurePacket ack(packet); 1661 1770 1662 1771 // notify all option handlers that we are sending an ack for each value 1663 1772 for (int32 index = 0; index < LCP().CountOptionHandlers(); index++) { 1664 1773 if (LCP().OptionHandlerAt(index)->SendingAck(ack) != B_OK) { 1665 m_freem(packet); 1774 TRACE("%s::%s: SendingAck %ld fail\n",__FILE__,__func__,index); 1775 gBufferModule->free(packet); 1666 1776 CloseEvent(); 1667 1777 return false; 1668 1778 } 1669 1779 } 1670 1780 1781 TRACE("%s::%s: LCP().Send\n",__FILE__,__func__); 1671 1782 return LCP().Send(packet) == B_OK; 1672 1783 } 1673 1784 1674 1785 1675 1786 bool 1676 KPPPStateMachine::SendConfigureNak( struct mbuf*packet)1787 KPPPStateMachine::SendConfigureNak(net_buffer *packet) 1677 1788 { 1678 1789 TRACE("KPPPSM: SendConfigureNak() state=%d phase=%d\n", State(), Phase()); 1679 1790 1680 1791 if (!packet) 1681 1792 return false; 1682 1793 1683 ppp_lcp_packet *nak = mtod(packet, ppp_lcp_packet*); 1684 if (nak->code == PPP_CONFIGURE_NAK) { 1794 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 1795 if (bufferHeader.Status() < B_OK) 1796 return false; 1797 ppp_lcp_packet &nak = bufferHeader.Data(); 1798 1799 if (nak.code == PPP_CONFIGURE_NAK) { 1685 1800 if (fNakCounter == 0) { 1686 1801 // We sent enough naks. Let's try a reject. 1687 nak ->code = PPP_CONFIGURE_REJECT;1802 nak.code = PPP_CONFIGURE_REJECT; 1688 1803 } else 1689 1804 --fNakCounter; 1690 1805 } … … KPPPStateMachine::SendTerminateRequest() 1700 1815 1701 1816 --fTerminateCounter; 1702 1817 fNextTimeout = system_time() + kPPPStateMachineTimeout; 1703 1704 struct mbuf *packet = m_gethdr(MT_DATA); 1818 1819 net_buffer *buffer = gBufferModule->create(256); 1820 if (buffer == NULL) 1821 return(NULL); 1822 1823 ppp_lcp_packet *packet; 1824 status_t status = gBufferModule->append_size(buffer, 1492, (void **)&packet); 1825 if (status == B_OK && packet == NULL) { 1826 gBufferModule->free(buffer); 1827 return(NULL); 1828 } 1829 1705 1830 if (!packet) 1706 1831 return false; 1707 1832 1708 packet-> m_pkthdr.len = packet->m_len = 4;1709 1710 // reserve some space for other protocols1711 packet->m_data += LCP().AdditionalOverhead(); 1712 1713 ppp_lcp_packet *request = mtod(packet, ppp_lcp_packet*); 1714 request->code = PPP_TERMINATE_REQUEST;1715 request->id = fTerminateID = NextID();1716 request->length = htons(4); 1717 1718 return LCP().Send( packet) == B_OK;1833 packet->code = PPP_TERMINATE_REQUEST; 1834 packet->id = fTerminateID = NextID(); 1835 packet->length = htons(4); 1836 1837 status = gBufferModule->trim(buffer, 4); 1838 if (status < B_OK) { 1839 gBufferModule->free(buffer); 1840 return(NULL); 1841 } 1842 1843 return LCP().Send(buffer) == B_OK; 1719 1844 } 1720 1845 1721 1846 1722 1847 bool 1723 KPPPStateMachine::SendTerminateAck( struct mbuf*request)1848 KPPPStateMachine::SendTerminateAck(net_buffer *request) 1724 1849 { 1725 1850 TRACE("KPPPSM: SendTerminateAck() state=%d phase=%d\n", State(), Phase()); 1726 1851 1727 struct mbuf*reply = request;1852 net_buffer *reply = request; 1728 1853 1729 ppp_lcp_packet *ack; 1854 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(request); 1855 if (bufferHeader.Status() < B_OK) 1856 return false; 1857 ppp_lcp_packet &ack = bufferHeader.Data(); 1730 1858 1731 1859 if (!reply) { 1732 reply = m_gethdr(MT_DATA); 1733 if (!reply) 1734 return false; 1735 1736 reply->m_data += LCP().AdditionalOverhead(); 1737 reply->m_pkthdr.len = reply->m_len = 4; 1738 1739 ack = mtod(reply, ppp_lcp_packet*); 1740 ack->id = NextID(); 1741 } else 1742 ack = mtod(reply, ppp_lcp_packet*); 1860 ack.length = htons(4); 1861 ack.id = NextID(); 1862 } 1743 1863 1744 ack ->code = PPP_TERMINATE_ACK;1745 ack ->length = htons(4);1864 ack.code = PPP_TERMINATE_ACK; 1865 ack.length = htons(4); 1746 1866 1747 1867 return LCP().Send(reply) == B_OK; 1748 1868 } 1749 1869 1750 1870 1751 1871 bool 1752 KPPPStateMachine::SendCodeReject( struct mbuf*packet, uint16 protocolNumber, uint8 code)1872 KPPPStateMachine::SendCodeReject(net_buffer *packet, uint16 protocolNumber, uint8 code) 1753 1873 { 1754 1874 TRACE("KPPPSM: SendCodeReject(protocolNumber=%X;code=%d) state=%d phase=%d\n", 1755 1875 protocolNumber, code, State(), Phase()); … … KPPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uin 1764 1884 else 1765 1885 length = 4; 1766 1886 1767 M_PREPEND(packet, length); 1768 // add some space for the header 1769 1770 // adjust packet if too big 1771 int32 adjust = Interface().MRU(); 1772 if (packet->m_flags & M_PKTHDR) { 1773 adjust -= packet->m_pkthdr.len; 1774 } else 1775 adjust -= packet->m_len; 1776 1777 if (adjust < 0) 1778 m_adj(packet, adjust); 1779 1780 ppp_lcp_packet *reject = mtod(packet, ppp_lcp_packet*); 1781 reject->code = code; 1782 reject->id = NextID(); 1783 if (packet->m_flags & M_PKTHDR) 1784 reject->length = htons(packet->m_pkthdr.len); 1785 else 1786 reject->length = htons(packet->m_len); 1887 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(packet); 1888 if (bufferHeader.Status() < B_OK) 1889 return false; 1890 ppp_lcp_packet &reject = bufferHeader.Data(); 1891 1892 reject.code = code; 1893 reject.id = NextID(); 1894 reject.length = htons(length); 1787 1895 1788 1896 protocolNumber = htons(protocolNumber); 1789 1897 if (code == PPP_PROTOCOL_REJECT) 1790 memcpy(&reject ->data, &protocolNumber, sizeof(protocolNumber));1898 memcpy(&reject.data, &protocolNumber, sizeof(protocolNumber)); 1791 1899 1792 1900 return LCP().Send(packet) == B_OK; 1793 1901 } 1794 1902 1795 1903 1796 1904 bool 1797 KPPPStateMachine::SendEchoReply( struct mbuf*request)1905 KPPPStateMachine::SendEchoReply(net_buffer *request) 1798 1906 { 1799 1907 TRACE("KPPPSM: SendEchoReply() state=%d phase=%d\n", State(), Phase()); 1800 1908 1801 1909 if (!request) 1802 1910 return false; 1803 1911 1804 ppp_lcp_packet *reply = mtod(request, ppp_lcp_packet*); 1805 reply->code = PPP_ECHO_REPLY; 1912 NetBufferHeaderReader<ppp_lcp_packet> bufferHeader(request); 1913 if (bufferHeader.Status() < B_OK) 1914 return false; 1915 ppp_lcp_packet &reply = bufferHeader.Data(); 1916 1917 reply.code = PPP_ECHO_REPLY; 1806 1918 // the request becomes a reply 1807 1919 1808 if (request->m_flags & M_PKTHDR) 1809 request->m_pkthdr.len = 8; 1810 request->m_len = 8; 1811 1812 memcpy(reply->data, &fMagicNumber, sizeof(fMagicNumber)); 1920 memcpy(reply.data, &fMagicNumber, sizeof(fMagicNumber)); 1813 1921 1814 1922 return LCP().Send(request) == B_OK; 1815 1923 } -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPConfigurePacket.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPConfigurePacket.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPConfigurePacket.h index 408dabc..c067a6b 100644
a b 7 7 #define _K_PPP_CONFIGURE_PACKET__H 8 8 9 9 #include <TemplateList.h> 10 11 struct mbuf; 10 #include <net_buffer.h> 12 11 13 12 //! An abstract configure item. 14 13 typedef struct ppp_configure_item { … … class KPPPConfigurePacket { 29 28 30 29 public: 31 30 KPPPConfigurePacket(uint8 code); 32 KPPPConfigurePacket( struct mbuf*packet);31 KPPPConfigurePacket(net_buffer *packet); 33 32 ~KPPPConfigurePacket(); 34 33 35 34 bool SetCode(uint8 code); … … class KPPPConfigurePacket { 52 51 ppp_configure_item *ItemAt(int32 index) const; 53 52 ppp_configure_item *ItemWithType(uint8 type) const; 54 53 55 struct mbuf*ToMbuf(uint32 MRU, uint32 reserve = 0);56 // the user is responsible for freeing the mbuf54 net_buffer *ToMbuf(uint32 MRU, uint32 reserve = 0); 55 // the user is responsible for freeing the net_buffer 57 56 58 57 private: 59 58 uint8 fCode, fID; -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPDevice.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPDevice.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPDevice.h index e2cd971..a691734 100644
a b 9 9 #include <KPPPDefs.h> 10 10 #include <KPPPLayer.h> 11 11 12 #include <net_buffer.h> 13 12 14 #ifndef _K_PPP_INTERFACE__H 13 15 #include <KPPPInterface.h> 14 16 #endif … … class KPPPDevice : public KPPPLayer { 96 98 This should enqueue the packet and return immediately (never block). 97 99 The device is responsible for freeing the packet by calling \c m_freem(). 98 100 */ 99 virtual status_t Send( struct mbuf*packet, uint16 protocolNumber) = 0;100 virtual status_t Receive( struct mbuf*packet, uint16 protocolNumber);101 virtual status_t Send(net_buffer *packet, uint16 protocolNumber) = 0; 102 virtual status_t Receive(net_buffer *packet, uint16 protocolNumber); 101 103 102 104 protected: 103 105 //! Use this to set the device's maximum transfer unit (in bytes). -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPInterface.h index a2c22e5..a1c92d8 100644
a b 30 30 31 31 #include <TemplateList.h> 32 32 33 #include <net_buffer.h> 34 #include <net_device.h> 35 36 #include <lock.h> 37 #include <util/AutoLock.h> 38 33 39 class KPPPDevice; 34 40 class KPPPProtocol; 35 41 class KPPPOptionHandler; … … class KPPPInterface : public KPPPLayer { 48 54 KPPPInterface(const KPPPInterface& copy); 49 55 KPPPInterface& operator= (const KPPPInterface& copy); 50 56 57 public: 58 // we should set to private after finishing test 51 59 // only PPPManager may construct us! 52 60 KPPPInterface(const char *name, ppp_interface_entry *entry, 53 61 ppp_interface_id ID, const driver_settings *settings, … … class KPPPInterface : public KPPPLayer { 75 83 { return fLCP; } 76 84 77 85 //! Returns the interfac's ifnet structure that is exported to the netstack. 78 struct ifnet*Ifnet() const79 { return fIfnet; }86 net_device *Ifnet() const 87 { return fIfnet; } 80 88 81 89 const char *Username() const; 82 90 const char *Password() const; … … class KPPPInterface : public KPPPLayer { 220 228 virtual bool IsAllowedToSend() const; 221 229 // always returns true 222 230 223 virtual status_t Send( struct mbuf*packet, uint16 protocolNumber);231 virtual status_t Send(net_buffer *packet, uint16 protocolNumber); 224 232 // sends the packet to the next handler (normally the device) 225 virtual status_t Receive( struct mbuf*packet, uint16 protocolNumber);233 virtual status_t Receive(net_buffer *packet, uint16 protocolNumber); 226 234 227 status_t ReceiveFromDevice( struct mbuf*packet);235 status_t ReceiveFromDevice(net_buffer *packet); 228 236 // This must not block KPPPDevice::Send()! 229 237 230 238 void Pulse(); … … class KPPPInterface : public KPPPLayer { 255 263 ppp_interface_id fID; 256 264 // the manager assigns an ID to every interface 257 265 driver_settings *fSettings; 258 struct ifnet*fIfnet;266 net_device *fIfnet; 259 267 260 268 char *fUsername, *fPassword; 261 269 … … class KPPPInterface : public KPPPLayer { 288 296 KPPPStateMachine fStateMachine; 289 297 KPPPLCP fLCP; 290 298 KPPPReportManager fReportManager; 291 BLocker& fLock;299 mutex& fLock; 292 300 int32 fDeleteCounter; 293 301 }; 294 302 -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCP.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCP.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCP.h index 5919911..e48c79f 100644
a b 20 20 #include <KPPPStateMachine.h> 21 21 #endif 22 22 23 #include <net_buffer.h> 24 #include <NetBufferUtilities.h> 25 23 26 class KPPPLCPExtension; 24 27 class KPPPOptionHandler; 25 28 … … class KPPPLCP : public KPPPProtocol { 85 88 virtual bool Up(); 86 89 virtual bool Down(); 87 90 88 virtual status_t Send( struct mbuf*packet,91 virtual status_t Send(net_buffer *packet, 89 92 uint16 protocolNumber = PPP_LCP_PROTOCOL); 90 virtual status_t Receive( struct mbuf*packet, uint16 protocolNumber);93 virtual status_t Receive(net_buffer *packet, uint16 protocolNumber); 91 94 92 95 virtual void Pulse(); 93 96 -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCPExtension.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCPExtension.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLCPExtension.h index 8d21c7b..828a0a1 100644
a b class KPPPLCPExtension { 51 51 // called by netstack (forwarded by KPPPInterface) 52 52 53 53 //! Must be overridden. Called when an LCP packet with your code is received. 54 virtual status_t Receive( struct mbuf*packet, uint8 code) = 0;54 virtual status_t Receive(net_buffer *packet, uint8 code) = 0; 55 55 56 56 virtual void Reset(); 57 57 virtual void Pulse(); -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLayer.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLayer.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPLayer.h index 4aba95d..98731b8 100644
a b 8 8 9 9 #include <KPPPDefs.h> 10 10 11 #include <net_buffer.h> 11 12 12 13 class KPPPLayer { 13 14 protected: … … class KPPPLayer { 48 49 virtual bool IsAllowedToSend() const = 0; 49 50 50 51 //! Send a packet with the given protocol number. 51 virtual status_t Send( struct mbuf*packet, uint16 protocolNumber) = 0;52 virtual status_t Send(net_buffer *packet, uint16 protocolNumber) = 0; 52 53 //! Receive a packet with the given protocol number. 53 virtual status_t Receive( struct mbuf*packet, uint16 protocolNumber) = 0;54 virtual status_t Receive(net_buffer *packet, uint16 protocolNumber) = 0; 54 55 55 status_t SendToNext( struct mbuf*packet, uint16 protocolNumber) const;56 status_t SendToNext(net_buffer *packet, uint16 protocolNumber) const; 56 57 // send the packet to the next layer 57 58 58 59 virtual void Pulse(); -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPManager.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPManager.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPManager.h index dd92c8f..347e0aa 100644
a b 6 6 #ifndef _K_PPP_MANAGER__H 7 7 #define _K_PPP_MANAGER__H 8 8 9 #include "net_module.h" 9 #include <module.h> 10 #include <net_device.h> 10 11 #include <PPPControl.h> 11 12 #include <PPPReportDefs.h> 12 13 13 14 #define PPP_INTERFACE_MODULE_NAME NETWORK_MODULES_ROOT "interfaces/ppp" 14 #define PPP_INTERFACE_MODULE_NAME NETWORK_MODULES_ROOT "/ppp/KPPPManager/v1" 15 15 16 16 #define PPP_UNDEFINED_INTERFACE_ID 0 17 17 // CreateInterface() returns this value on failure … … typedef struct ppp_interface_entry { 34 34 deletes them when they are not needed anymore. 35 35 */ 36 36 typedef struct ppp_interface_module_info { 37 kernel_net_module_info knminfo; 38 //!< Exports needed network module functions. 37 struct module_info info; 39 38 40 39 ppp_interface_id (*CreateInterface)(const driver_settings *settings, 41 40 ppp_interface_id parentID); … … typedef struct ppp_interface_module_info { 46 45 bool (*RemoveInterface)(ppp_interface_id ID); 47 46 // remove the interface from database (make sure you can delete it yourself!) 48 47 49 ifnet *(*RegisterInterface)(ppp_interface_id ID); 48 net_device *(*RegisterInterface)(ppp_interface_id ID); 49 KPPPInterface *(*GetInterface)(ppp_interface_id ID); 50 // for accessing KPPPInterface directly 50 51 bool (*UnregisterInterface)(ppp_interface_id ID); 51 52 52 53 status_t (*ControlInterface)(ppp_interface_id ID, uint32 op, void *data, -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPProtocol.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPProtocol.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPProtocol.h index 824fd91..bc1a8a0 100644
a b class KPPPProtocol : public KPPPLayer { 105 105 virtual bool IsAllowedToSend() const; 106 106 107 107 //! Encapsulate the packet with the given protocol number. 108 virtual status_t Send( struct mbuf*packet, uint16 protocolNumber) = 0;108 virtual status_t Send(net_buffer *packet, uint16 protocolNumber) = 0; 109 109 //! Receive a packet with the given protocol number. 110 virtual status_t Receive( struct mbuf*packet, uint16 protocolNumber) = 0;110 virtual status_t Receive(net_buffer *packet, uint16 protocolNumber) = 0; 111 111 112 112 protected: 113 113 //! \brief Requests Up() to be called. -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPReportManager.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPReportManager.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPReportManager.h index 1d5f1ea..91bf637 100644
a b 13 13 14 14 #include <TemplateList.h> 15 15 16 #include <lock.h> 17 #include <util/AutoLock.h> 18 16 19 17 20 class KPPPReportManager { 18 21 public: 19 KPPPReportManager( BLocker& lock);22 KPPPReportManager(mutex& lock); 20 23 ~KPPPReportManager(); 21 24 22 25 static bool SendReport(thread_id thread, const ppp_report_packet *report); … … class KPPPReportManager { 30 33 // returns false if reply was bad (or an error occured) 31 34 32 35 private: 33 BLocker& fLock;36 mutex& fLock; 34 37 TemplateList<ppp_report_request*> fReportRequests; 35 38 }; 36 39 -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPStateMachine.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPStateMachine.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPStateMachine.h index d281e0d..414681e 100644
a b class KPPPProtocol; 14 14 #include <KPPPInterface.h> 15 15 #endif 16 16 17 #include <Locker.h> 17 #include <lock.h> 18 #include <util/AutoLock.h> 18 19 19 20 class PPPManager; 20 21 class KPPPInterface; … … class KPPPStateMachine { 116 117 void CloseEvent(); 117 118 void TOGoodEvent(); 118 119 void TOBadEvent(); 119 void RCRGoodEvent( struct mbuf*packet);120 void RCRBadEvent( struct mbuf *nak, struct mbuf*reject);121 void RCAEvent( struct mbuf*packet);122 void RCNEvent( struct mbuf*packet);123 void RTREvent( struct mbuf*packet);124 void RTAEvent( struct mbuf*packet);125 void RUCEvent( struct mbuf*packet, uint16 protocolNumber,120 void RCRGoodEvent(net_buffer *packet); 121 void RCRBadEvent(net_buffer *nak, net_buffer *reject); 122 void RCAEvent(net_buffer *packet); 123 void RCNEvent(net_buffer *packet); 124 void RTREvent(net_buffer *packet); 125 void RTAEvent(net_buffer *packet); 126 void RUCEvent(net_buffer *packet, uint16 protocolNumber, 126 127 uint8 code = PPP_PROTOCOL_REJECT); 127 void RXJGoodEvent( struct mbuf*packet);128 void RXJBadEvent( struct mbuf*packet);129 void RXREvent( struct mbuf*packet);128 void RXJGoodEvent(net_buffer *packet); 129 void RXJBadEvent(net_buffer *packet); 130 void RXREvent(net_buffer *packet); 130 131 131 132 // general events (for Good/Bad events) 132 133 void TimerEvent(); 133 void RCREvent( struct mbuf*packet);134 void RXJEvent( struct mbuf*packet);134 void RCREvent(net_buffer *packet); 135 void RXJEvent(net_buffer *packet); 135 136 136 137 // actions 137 138 void IllegalEvent(ppp_event event); … … class KPPPStateMachine { 142 143 void InitializeRestartCount(); 143 144 void ZeroRestartCount(); 144 145 bool SendConfigureRequest(); 145 bool SendConfigureAck( struct mbuf*packet);146 bool SendConfigureNak( struct mbuf*packet);146 bool SendConfigureAck(net_buffer *packet); 147 bool SendConfigureNak(net_buffer *packet); 147 148 bool SendTerminateRequest(); 148 bool SendTerminateAck( struct mbuf*request = NULL);149 bool SendCodeReject( struct mbuf*packet, uint16 protocolNumber, uint8 code);150 bool SendEchoReply( struct mbuf*request);149 bool SendTerminateAck(net_buffer *request = NULL); 150 bool SendCodeReject(net_buffer *packet, uint16 protocolNumber, uint8 code); 151 bool SendEchoReply(net_buffer *request); 151 152 152 153 void BringProtocolsUp(); 153 154 uint32 BringPhaseUp(); … … class KPPPStateMachine { 177 178 // the ID we used for the last configure/terminate/echo request 178 179 bigtime_t fNextTimeout; 179 180 180 BLockerfLock;181 mutex fLock; 181 182 }; 182 183 183 184 -
src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPDefs.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPDefs.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/PPPDefs.h index afa85d1..c13a5c2 100644
a b 10 10 11 11 #include <directories.h> 12 12 13 #include "net_module.h"13 // #include "net_module.h" 14 14 15 15 16 16 typedef uint32 ppp_interface_id; … … typedef uint32 ppp_interface_id; 37 37 #define PPP_SERVER_MODE_VALUE "Server" 38 38 39 39 // path defines 40 #define PPP_MODULES_PATH NETWORK_MODULES_ROOT "ppp" 40 #define NETWORK_MODULES_ROOT "network" 41 #define PPP_MODULES_PATH NETWORK_MODULES_ROOT "/ppp" 41 42 #define PTP_INTERFACE_SETTINGS_PATH \ 42 43 kUserSettingsDirectory "/kernel/drivers/ptpnet" 43 44 // TODO: should be: /etc/ptpnet -
new file src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/asm_defs.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/asm_defs.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/asm_defs.h new file mode 100644 index 0000000..798fa02
- + 1 /* 2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef SYSTEM_ARCH_X86_ASM_DEFS_H 6 #define SYSTEM_ARCH_X86_ASM_DEFS_H 7 8 9 #define SYMBOL(name) .global name; name 10 #define SYMBOL_END(name) 1: .size name, 1b - name 11 #define STATIC_FUNCTION(name) .type name, @function; name 12 #define FUNCTION(name) .global name; .type name, @function; name 13 #define FUNCTION_END(name) 1: .size name, 1b - name 14 15 16 #endif /* SYSTEM_ARCH_X86_ASM_DEFS_H */ 17 -
new file src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/directories.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/directories.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/directories.h new file mode 100644 index 0000000..fe34d04
- + 1 /* 2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _SYSTEM_DIRECTORIES_H 6 #define _SYSTEM_DIRECTORIES_H 7 8 9 #define kGlobalBinDirectory "/bin" 10 #define kGlobalEtcDirectory "/etc" 11 #define kGlobalPackageLinksDirectory "/packages" 12 #define kGlobalSystemDirectory "/system" 13 #define kGlobalTempDirectory "/tmp" 14 #define kGlobalVarDirectory "/var" 15 16 #define kAppsDirectory "/boot/apps" 17 #define kPreferencesDirectory "/boot/preferences" 18 19 #define kAppLocalAddonsDirectory "%A/add-ons" 20 #define kAppLocalLibDirectory "%A/lib" 21 22 #define kVolumeLocalSystemKernelAddonsDirectory "system/add-ons/kernel" 23 #define kVolumeLocalCommonNonpackagedKernelAddonsDirectory \ 24 "common/non-packaged/add-ons/kernel" 25 #define kVolumeLocalCommonKernelAddonsDirectory "common/add-ons/kernel" 26 #define kVolumeLocalUserNonpackagedKernelAddonsDirectory \ 27 "home/config/non-packaged/add-ons/kernel" 28 #define kVolumeLocalUserKernelAddonsDirectory "home/config/add-ons/kernel" 29 30 #define kSystemDirectory "/boot/system" 31 #define kSystemAddonsDirectory "/boot/system/add-ons" 32 #define kSystemAppsDirectory "/boot/system/apps" 33 #define kSystemBinDirectory "/boot/system/bin" 34 #define kSystemDataDirectory "/boot/system/data" 35 #define kSystemDevelopDirectory "/boot/develop" 36 #define kSystemLibDirectory "/boot/system/lib" 37 #define kSystemPackagesDirectory "/boot/system/packages" 38 #define kSystemPackageLinksDirectory "/boot/system/package-links" 39 #define kSystemPreferencesDirectory "/boot/system/preferences" 40 #define kSystemServersDirectory "/boot/system/servers" 41 42 #define kCommonDirectory "/boot/common" 43 #define kCommonAddonsDirectory "/boot/common/add-ons" 44 #define kCommonBinDirectory "/boot/common/bin" 45 #define kCommonDevelopToolsBinDirectory "/boot/develop/tools/current/bin" 46 #define kCommonEtcDirectory "/boot/common/etc" 47 #define kCommonLibDirectory "/boot/common/lib" 48 #define kCommonPackagesDirectory "/boot/common/packages" 49 #define kCommonSettingsDirectory "/boot/common/settings" 50 #define kCommonTempDirectory "/boot/common/cache/tmp" 51 #define kCommonVarDirectory "/boot/common/var" 52 #define kCommonLogDirectory "/boot/common/var/log" 53 #define kCommonNonpackagedAddonsDirectory "/boot/common/non-packaged/add-ons" 54 #define kCommonNonpackagedBinDirectory "/boot/common/non-packaged/bin" 55 #define kCommonNonpackagedLibDirectory "/boot/common/non-packaged/lib" 56 57 #define kUserDirectory "/boot/home" 58 #define kUserConfigDirectory "/boot/home/config" 59 #define kUserAddonsDirectory "/boot/home/config/add-ons" 60 #define kUserBinDirectory "/boot/home/config/bin" 61 #define kUserLibDirectory "/boot/home/config/lib" 62 #define kUserPackagesDirectory "/boot/home/config/packages" 63 #define kUserSettingsDirectory "/boot/home/config/settings" 64 #define kUserNonpackagedAddonsDirectory "/boot/home/config/non-packaged/add-ons" 65 #define kUserNonpackagedBinDirectory "/boot/home/config/non-packaged/bin" 66 #define kUserNonpackagedLibDirectory "/boot/home/config/non-packaged/lib" 67 68 69 #endif // _SYSTEM_DIRECTORIES_H -
new file src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/ppp_device.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/ppp_device.h b/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/ppp_device.h new file mode 100644 index 0000000..21255db
- + 1 #ifndef __PPP_DEV_H 2 #define __PPP_DEV_H 3 #include <net_device.h> 4 #include <net_stack.h> 5 #include <KPPPInterface.h> 6 7 #include <lock.h> 8 #include <util/AutoLock.h> 9 #include <util/DoublyLinkedList.h> 10 11 struct ppp_device : net_device, DoublyLinkedListLinkImpl<ppp_device> { 12 KPPPInterface * KPPP_Interface; 13 uint32 frame_size; 14 net_fifo ppp_fifo; 15 }; 16 17 #endif -
src/add-ons/kernel/network/ppp/shared/libkernelppp/settings_tools.cpp
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 5e3c536..5968d08 100644
a b get_parameter_with_name(const char *name, const driver_settings *settings) 366 366 return NULL; 367 367 368 368 for (int32 index = 0; index < settings->parameter_count; index++) 369 { 370 // dprintf("parameter name: %s \n",settings->parameters[index].name); 369 371 if (!strcasecmp(settings->parameters[index].name, name)) 370 372 return &settings->parameters[index]; 373 } 371 374 372 375 return NULL; 373 376 } … … get_settings_value(const char *name, const driver_settings *settings) 378 381 { 379 382 const driver_parameter *parameter = get_parameter_with_name(name, settings); 380 383 381 if (parameter && parameter->value_count > 0 && parameter->values) 384 if (parameter && parameter->value_count > 0 && parameter->values){ 385 // dprintf("name: %s value: %s \n", name, parameter->values[0]); 382 386 return parameter->values[0]; 387 } 383 388 384 389 return NULL; 385 390 } -
src/add-ons/kernel/network/ppp/shared/libppp/Jamfile
diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/Jamfile b/src/add-ons/kernel/network/ppp/shared/libppp/Jamfile index 4d658b0..ae5f939 100644
a b if $(TARGET_PLATFORM) != haiku { 10 10 # Unfortunately we get more than we want, namely all POSIX headers. 11 11 } 12 12 13 UsePrivateKernelHeaders ; 13 14 UsePrivateHeaders net ; 14 15 UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared libppp 15 16 headers ] : true ; … … UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared 19 20 20 21 StaticLibrary libppp.a : 21 22 strlcat.c 22 driver_settings.c 23 driver_settings.cpp 23 24 settings_tools.cpp 24 25 KPPPUtils.cpp 25 26 … … StaticLibrary libppp.a : 31 32 ; 32 33 33 34 SEARCH on [ FGristFiles strlcat.c ] = [ FDirName $(HAIKU_TOP) src system libroot posix string ] ; 34 SEARCH on [ FGristFiles driver_settings.c ] = [ FDirName $(HAIKU_TOP) src system libroot os ] ;35 SEARCH on [ FGristFiles driver_settings.cpp ] = [ FDirName $(HAIKU_TOP) src system libroot os ] ; 35 36 SEARCH on [ FGristFiles settings_tools.cpp ] = [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared libkernelppp ] ; 36 37 SEARCH on [ FGristFiles KPPPUtils.cpp ] = [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared libkernelppp ] ; -
src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.cpp
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 b81c10f..b725f74 100644
a b 9 9 #include <cstring> 10 10 11 11 12 c har*12 const char* 13 13 get_stack_driver_path() 14 14 { 15 15 char *path; -
src/add-ons/kernel/network/ppp/shared/libppp/_libppputils.h
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 db72c1a..fef0ed4 100644
a b 6 6 #ifndef __libppputils__h 7 7 #define __libppputils__h 8 8 9 #include <net_stack_driver.h> 9 #include "net_stack_driver.h" 10 // #define NET_STACK_DRIVER_PATH "/boot/common/system/add-ons/kernel/network" 10 11 11 12 char *get_stack_driver_path(); 12 const char *get_stack_driver_path(); 13 13 14 14 15 15 #endif -
src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPManager.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPManager.h b/src/add-ons/kernel/network/ppp/shared/libppp/headers/PPPManager.h index b3ae547..da5229c 100644
a b 8 8 9 9 #include <KPPPManager.h> 10 10 #include <String.h> 11 #include <Directory.h> 11 12 12 13 13 14 class PPPManager { -
new file src/add-ons/kernel/network/ppp/shared/libppp/net_stack_driver.h
diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/net_stack_driver.h b/src/add-ons/kernel/network/ppp/shared/libppp/net_stack_driver.h new file mode 100644 index 0000000..bb27f76
- + 1 /* net_stack_driver.h 2 * structures and defines to deal with the network stack pseudo-driver... 3 */ 4 5 #ifndef NET_STACK_DRIVER_H 6 #define NET_STACK_DRIVER_H 7 8 #include <OS.h> 9 #include <sys/select.h> 10 11 // Forward declaration 12 struct sockaddr; 13 14 #define NET_STACK_DRIVER_DEV "net/stack" 15 #define NET_STACK_DRIVER_PATH "/dev/net/stack" // ## NET_STACK_DRIVER_DEV 16 17 enum { 18 // Paranoia mode: be far away of B_DEVICE_OP_CODES_END opcodes!!! 19 // You never know what another device driver ioctl() will do 20 // if think our NET_STACK_* is in fact his DO_RISKY_BUSINESS opcode, or whatever... 21 NET_IOCTL_BASE = 0xbe230000, 22 NET_STACK_IOCTL_BASE = NET_IOCTL_BASE + 0x200 23 }; 24 25 enum { 26 NET_STACK_SOCKET = NET_STACK_IOCTL_BASE, // socket_args * 27 NET_STACK_BIND, // sockaddr_args * 28 NET_STACK_RECVFROM, // struct msghdr * 29 NET_STACK_RECV, // transfer_args * 30 NET_STACK_SENDTO, // struct msghdr * 31 NET_STACK_SEND, // transfer_args * 32 NET_STACK_LISTEN, // int_args * (value = backlog) 33 NET_STACK_ACCEPT, // sockaddr_args * 34 NET_STACK_CONNECT, // sockaddr_args * 35 NET_STACK_SHUTDOWN, // int_args * (value = how) 36 NET_STACK_GETSOCKOPT, // sockopt_args * 37 NET_STACK_SETSOCKOPT, // sockopt_args * 38 NET_STACK_GETSOCKNAME, // sockaddr_args * 39 NET_STACK_GETPEERNAME, // sockaddr_args * 40 41 NET_STACK_SYSCTL, // sysctl_args * 42 NET_STACK_SELECT, // select_args * 43 NET_STACK_DESELECT, // select_args * 44 45 NET_STACK_GET_COOKIE, // void ** 46 47 NET_STACK_STOP, 48 49 NET_STACK_NOTIFY_SOCKET_EVENT, // notify_socket_event_args * (userland stack only) 50 51 NET_STACK_CONTROL_NET_MODULE, 52 53 NET_STACK_IOCTL_MAX 54 }; 55 56 struct sockaddr_args { // used by NET_STACK_CONNECT/_BIND/_GETSOCKNAME/_GETPEERNAME 57 struct sockaddr *addr; 58 int addrlen; 59 }; 60 61 struct sockopt_args { // used by NET_STACK_SETSOCKOPT/_GETSOCKOPT 62 int level; 63 int option; 64 void *optval; 65 int optlen; 66 }; 67 68 struct transfer_args { // used by NET_STACK_SEND/_RECV 69 void *data; 70 size_t datalen; 71 int flags; 72 struct sockaddr *addr; // unused in *_SEND and *_RECV cases 73 int addrlen; // unused in *_SEND and *_RECV cases 74 }; 75 76 struct socket_args { // used by NET_STACK_SOCKET 77 int family; 78 int type; 79 int proto; 80 }; 81 82 struct accept_args { // used by NET_STACK_ACCEPT 83 void *cookie; 84 struct sockaddr *addr; 85 int addrlen; 86 }; 87 88 struct sysctl_args { // used by NET_STACK_SYSCTL 89 int *name; 90 uint namelen; 91 void *oldp; 92 size_t *oldlenp; 93 void *newp; 94 size_t newlen; 95 }; 96 97 struct control_net_module_args { // used by NET_STACK_CONTROL_NET_MODULE 98 const char *name; 99 uint32 op; 100 void *data; 101 size_t length; 102 }; 103 104 /* 105 Userland stack driver on_socket_event() callback mecanism implementation: 106 the driver start a kernel thread waiting on a port for 107 a NET_STACK_SOCKET_EVENT_MSG message, which come with a socket_event_data block. 108 109 The on_socket_event() mechanism stay in driver (kernelland) because it's 110 only there we can call kernel's notify_select_event() on BONE systems. 111 For non-BONE systems, we use our own r5_notify_select_event() 112 implementation, that could be moved into the userland net_server code, 113 but it'll have split (again!) the /dev/net/stack driver code... 114 */ 115 116 struct notify_socket_event_args { // used by NET_STACK_NOTIFY_SOCKET_EVENT 117 port_id notify_port; // port waiting for notification, -1 = stop notify 118 void * cookie; // this cookie value will be pass back in the socket_event_args 119 }; 120 121 #define NET_STACK_SOCKET_EVENT_NOTIFICATION 'sevn' 122 123 struct socket_event_data { 124 uint32 event; // B_SELECT_READ, B_SELECT_WRITE or B_SELECT_ERROR 125 void * cookie; // The cookie as set in notify_socket_event_args for this socket 126 }; 127 128 /* 129 R5.0.3 and before select() kernel support is too buggy to be used, so 130 here are the structures we used to support select() on sockets, and *only* on 131 sockets! 132 */ 133 134 struct select_args { // used by NET_STACK_SELECT and NET_STACK_DESELECT 135 struct selectsync * sync; // in fact, it's the area_id of a r5_selectsync struct!!! 136 uint32 ref; 137 }; 138 139 struct r5_selectsync { 140 sem_id lock; // lock this r5_selectsync 141 sem_id wakeup; // sem to release to wakeup select() 142 struct fd_set rbits; // read event bits field 143 struct fd_set wbits; // write event bits field 144 struct fd_set ebits; // exception event bits field 145 }; 146 147 148 struct stack_driver_args { 149 union { 150 int integer; 151 struct socket_args socket; 152 struct accept_args accept; 153 struct sockaddr_args sockaddr; 154 struct sockopt_args sockopt; 155 struct transfer_args transfer; 156 struct sysctl_args sysctl; 157 struct select_args select; 158 struct control_net_module_args control; 159 } u; 160 }; 161 162 #endif /* NET_STACK_DRIVER_H */ -
src/add-ons/kernel/network/stack/datalink.cpp
diff --git a/src/add-ons/kernel/network/stack/datalink.cpp b/src/add-ons/kernel/network/stack/datalink.cpp index 74ed66b..fc8a1bb 100644
a b fill_address(const sockaddr* from, sockaddr* to, size_t maxLength) 193 193 194 194 // #pragma mark - datalink module 195 195 196 static status_t 197 datalink_set_interface_address(net_domain* _domain, struct ifaliasreq request) 198 { 199 200 net_domain_private* domain = (net_domain_private*)_domain; 201 202 Interface* interface = get_interface(domain, request.ifra_name); 203 if (interface != NULL) { 204 // A new alias is added to this interface 205 status_t status = interface->ChangeAddress(domain, request); 206 notify_interface_changed(interface); 207 interface->ReleaseReference(); 208 209 return status; 210 } 211 212 return B_ERROR; 213 } 196 214 197 215 static status_t 198 216 datalink_control(net_domain* _domain, int32 option, void* value, … … datalink_get_interface(net_domain* domain, uint32 index) 528 546 529 547 530 548 static net_interface* 549 datalink_get_interface_by_name(net_domain* domain, const char* ifname) 550 { 551 return get_interface(domain, ifname); 552 } 553 554 555 static net_interface* 531 556 datalink_get_interface_with_address(const sockaddr* address) 532 557 { 533 558 InterfaceAddress* interfaceAddress = get_interface_address(address); … … datalink_get_interface_address(const struct sockaddr* address) 560 585 } 561 586 562 587 588 static net_interface_address* 589 datalink_get_interface_address_by_name(const char* name, net_domain* domain) 590 { 591 if (name==NULL || domain==NULL) 592 return NULL; 593 594 Interface* interface = get_interface(domain, name); 595 if (interface==NULL) 596 return NULL; 597 598 return interface->FirstForFamily(domain->family); 599 } 600 563 601 /*! Returns a reference to the next address of the given interface in 564 602 \a _address. When you call this function the first time, \a _address must 565 603 point to a NULL address. Upon the next call, the reference to the previous … … net_datalink_module_info gNetDatalinkModule = { 1008 1046 datalink_is_local_link_address, 1009 1047 1010 1048 datalink_get_interface, 1049 datalink_get_interface_by_name, 1011 1050 datalink_get_interface_with_address, 1012 1051 datalink_put_interface, 1013 1052 1014 1053 datalink_get_interface_address, 1054 datalink_get_interface_address_by_name, 1055 datalink_set_interface_address, 1015 1056 datalink_get_next_interface_address, 1016 1057 datalink_put_interface_address, 1017 1058 … … net_datalink_module_info gNetDatalinkModule = { 1030 1071 1031 1072 net_datalink_protocol_module_info gDatalinkInterfaceProtocolModule = { 1032 1073 { 1033 N ULL,1074 NET_DATA_LINK_INTERFACE_MODULE_NAME, 1034 1075 0, 1035 1076 NULL 1036 1077 }, -
src/add-ons/kernel/network/stack/device_interfaces.cpp
diff --git a/src/add-ons/kernel/network/stack/device_interfaces.cpp b/src/add-ons/kernel/network/stack/device_interfaces.cpp index a3030f0..f29df7b 100644
a b device_consumer_thread(void* _interface) 129 129 } 130 130 } 131 131 132 if (buffer != NULL) 132 if (buffer != NULL){ 133 // should free the unused buffer 134 dprintf("%s::%s: severe fault!!!!\n",__FILE__,__func__); 133 135 gNetBufferModule.free(buffer); 136 } 134 137 } 135 138 136 139 return B_OK; … … down_device_interface(net_device_interface* interface) 556 559 status_t status; 557 560 wait_for_thread(readerThread, &status); 558 561 } 562 563 559 564 } 560 565 561 566 -
src/add-ons/kernel/network/stack/interfaces.cpp
diff --git a/src/add-ons/kernel/network/stack/interfaces.cpp b/src/add-ons/kernel/network/stack/interfaces.cpp index 20b4110..bfa95c4 100644
a b Interface::RemoveAddresses() 729 729 } 730 730 731 731 732 status_t 733 Interface::ChangeAddress(net_domain* domain, ifaliasreq& aliasRequest) 734 { 735 RecursiveLocker locker(fLock); 736 737 InterfaceAddress* address = NULL; 738 if (aliasRequest.ifra_index < 0) { 739 if (!domain->address_module->is_empty_address( 740 (const sockaddr*)&aliasRequest.ifra_addr, false)) { 741 // Find first address that matches the local address 742 address = AddressForLocal(domain, 743 (const sockaddr*)&aliasRequest.ifra_addr); 744 } 745 if (address == NULL) { 746 // Find first address for family 747 address = FirstForFamily(domain->family); 748 } 749 if (address == NULL) { 750 // Create new on the fly 751 address = new(std::nothrow) InterfaceAddress(this, domain); 752 if (address == NULL) 753 return B_NO_MEMORY; 754 755 status_t status = AddAddress(address); 756 if (status != B_OK) { 757 delete address; 758 return status; 759 } 760 761 // Note, even if setting the address failed, the empty 762 // address added here will still be added to the interface. 763 address->AcquireReference(); 764 } 765 } else 766 address = AddressAt(aliasRequest.ifra_index); 767 768 if (address == NULL) 769 return B_BAD_VALUE; 770 771 status_t status = B_OK; 772 773 if (!domain->address_module->equal_addresses( 774 (sockaddr*)&aliasRequest.ifra_addr, address->local)) { 775 status = _ChangeAddress(locker, address, SIOCSIFADDR, 776 address->local, (sockaddr*)&aliasRequest.ifra_addr); 777 } 778 779 if (status == B_OK && !domain->address_module->equal_addresses( 780 (sockaddr*)&aliasRequest.ifra_mask, address->mask) 781 && !domain->address_module->is_empty_address( 782 (sockaddr*)&aliasRequest.ifra_mask, false)) { 783 status = _ChangeAddress(locker, address, SIOCSIFNETMASK, 784 address->mask, (sockaddr*)&aliasRequest.ifra_mask); 785 } 786 787 if (status == B_OK && !domain->address_module->equal_addresses( 788 (sockaddr*)&aliasRequest.ifra_destination, 789 address->destination) 790 && !domain->address_module->is_empty_address( 791 (sockaddr*)&aliasRequest.ifra_destination, false)) { 792 status = _ChangeAddress(locker, address, 793 (domain->address_module->flags 794 & NET_ADDRESS_MODULE_FLAG_BROADCAST_ADDRESS) != 0 795 ? SIOCSIFBRDADDR : SIOCSIFDSTADDR, 796 address->destination, 797 (sockaddr*)&aliasRequest.ifra_destination); 798 } 799 800 address->ReleaseReference(); 801 return status; 802 } 803 804 732 805 /*! This is called in order to call the correct methods of the datalink 733 806 protocols, ie. it will translate address changes to 734 807 net_datalink_protocol::change_address(), and IFF_UP changes to … … Interface::Control(net_domain* domain, int32 option, ifreq& request, 823 896 824 897 status_t status = B_OK; 825 898 899 dprintf("%s:%s: begin change address\n", __FILE__, __func__); 900 826 901 if (!domain->address_module->equal_addresses( 827 902 (sockaddr*)&aliasRequest.ifra_addr, address->local)) { 828 903 status = _ChangeAddress(locker, address, SIOCSIFADDR, -
src/add-ons/kernel/network/stack/interfaces.h
diff --git a/src/add-ons/kernel/network/stack/interfaces.h b/src/add-ons/kernel/network/stack/interfaces.h index f7bc63b..944403a 100644
a b public: 139 139 ifreq& request, ifreq* userRequest, 140 140 size_t length); 141 141 142 status_t ChangeAddress(net_domain* domain, 143 ifaliasreq& aliasRequest); 142 144 void SetDown(); 143 145 void WentDown(); 144 146 -
src/add-ons/kernel/network/stack/stack.cpp
diff --git a/src/add-ons/kernel/network/stack/stack.cpp b/src/add-ons/kernel/network/stack/stack.cpp index 9ca32c0..7e9a31c 100644
a b init_stack() 836 836 // TODO: for now! 837 837 register_domain_datalink_protocols(AF_INET, IFT_LOOP, 838 838 "network/datalink_protocols/loopback_frame/v1", NULL); 839 // add ppp datalink protocol 840 register_domain_datalink_protocols(AF_INET, IFT_PPP, 841 "network/datalink_protocols/ppp_frame/v1", NULL); 839 842 register_domain_datalink_protocols(AF_INET6, IFT_LOOP, 840 843 "network/datalink_protocols/loopback_frame/v1", NULL); 841 844 register_domain_datalink_protocols(AF_INET, IFT_ETHER, … … module_info* modules[] = { 992 995 (module_info*)&gNetDatalinkModule, 993 996 (module_info*)&gLinkModule, 994 997 (module_info*)&gNetStackInterfaceModule, 998 (module_info*)&gDatalinkInterfaceProtocolModule, 995 999 NULL 996 1000 }; -
src/bin/network/Jamfile
diff --git a/src/bin/network/Jamfile b/src/bin/network/Jamfile index 1f2e1d5..95fef6f 100644
a b SubInclude HAIKU_TOP src bin network ifconfig ; 12 12 SubInclude HAIKU_TOP src bin network mount_nfs ; 13 13 SubInclude HAIKU_TOP src bin network netcat ; 14 14 SubInclude HAIKU_TOP src bin network netstat ; 15 #SubInclude HAIKU_TOP src bin network pppconfig ;16 #SubInclude HAIKU_TOP src bin network ppp_up ;15 SubInclude HAIKU_TOP src bin network pppconfig ; 16 SubInclude HAIKU_TOP src bin network ppp_up ; 17 17 SubInclude HAIKU_TOP src bin network ping ; 18 18 SubInclude HAIKU_TOP src bin network ping6 ; 19 19 SubInclude HAIKU_TOP src bin network route ; -
src/bin/network/ifconfig/ifconfig.cpp
diff --git a/src/bin/network/ifconfig/ifconfig.cpp b/src/bin/network/ifconfig/ifconfig.cpp index e103055..d514caf 100644
a b configure_interface(const char* name, char* const* args, int32 argCount) 739 739 740 740 status_t status = roster.AddInterface(interface); 741 741 if (status != B_OK) { 742 fprintf(stderr, "%s: Could not add interface: %s \n", kProgramName,743 strerror(status) );742 fprintf(stderr, "%s: Could not add interface: %s;error code:[%d]\n", kProgramName, 743 strerror(status),status); 744 744 exit(1); 745 745 } 746 746 } -
src/bin/network/ppp_up/Jamfile
diff --git a/src/bin/network/ppp_up/Jamfile b/src/bin/network/ppp_up/Jamfile index 6ef1a22..543bccc 100644
a b 1 SubDir HAIKU_TOP src bin ppp_up ;1 SubDir HAIKU_TOP src bin network ppp_up ; 2 2 3 3 SetSubDirSupportedPlatforms $(HAIKU_BONE_COMPATIBLE_PLATFORMS) ; 4 4 … … if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) { 8 8 # Unfortunately we get more than we want, namely all POSIX headers. 9 9 } 10 10 11 UsePrivateHeaders net ; 11 UsePrivateHeaders net app libroot shared interface libbe be root tracker textencoding 12 root ; 13 12 14 UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared libppp 13 15 headers ] : true ; 14 16 UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared … … BinCommand ppp_up : 24 26 PPPStatusWindow.cpp 25 27 PPPUpApplication.cpp 26 28 : 27 libppp.a be 29 libppp.a be $(TARGET_LIBSUPC++) translation $(HAIKU_LOCALE_LIBS) root 28 30 ; 29 31 30 32 # Installation -
src/bin/network/ppp_up/PPPStatusView.h
diff --git a/src/bin/network/ppp_up/PPPStatusView.h b/src/bin/network/ppp_up/PPPStatusView.h index 8463f5c..bb58244 100644
a b 6 6 #ifndef STATUS_VIEW__H 7 7 #define STATUS_VIEW__H 8 8 9 #include <View.h> 9 // #include <View.h> 10 #include <StringView.h> 10 11 #include <PPPInterface.h> 12 #include <Button.h> 11 13 12 14 13 15 class PPPStatusView : public BView { -
src/bin/network/pppconfig/Jamfile
diff --git a/src/bin/network/pppconfig/Jamfile b/src/bin/network/pppconfig/Jamfile index 9984a4a..921d1f4 100644
a b 1 SubDir HAIKU_TOP src bin pppconfig ;1 SubDir HAIKU_TOP src bin network pppconfig ; 2 2 3 3 SetSubDirSupportedPlatforms $(HAIKU_BONE_COMPATIBLE_PLATFORMS) ; 4 4 … … UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared 17 17 BinCommand pppconfig : 18 18 pppconfig.cpp 19 19 : 20 be libppp.a 20 be libppp.a $(TARGET_LIBSUPC++) 21 21 ; 22 22 23 23 # Installation -- in the test directory for the time being