Ticket #812: 0001-merge-pppoe_branch.patch

File 0001-merge-pppoe_branch.patch, 259.8 KB (added by mshlyn, 7 years ago)

porting ppp to new netstack

  • 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  
    9090    syslog_daemon dns_resolver_server nfs4_idmapper_server
    9191] ;
    9292
    93 SYSTEM_NETWORK_DEVICES = ethernet loopback ;
     93SYSTEM_NETWORK_DEVICES = ethernet loopback ppp ;
    9494SYSTEM_NETWORK_DATALINK_PROTOCOLS = ethernet_frame <module>arp loopback_frame
    95     ipv6_datagram ;
     95    ipv6_datagram ppp_frame ;
     96SYSTEM_NETWORK_PPP = ipcp pap pppoe KPPPManager ;
    9697#SYSTEM_NETWORK_PPP = ipcp modem pap pppoe ;
    9798SYSTEM_NETWORK_PROTOCOLS = ipv4 tcp udp icmp unix icmp6 ipv6 ;
    9899
  • build/jam/ReleaseBuildProfiles

    diff --git a/build/jam/ReleaseBuildProfiles b/build/jam/ReleaseBuildProfiles
    index 0fc925f..70b68b4 100644
    a b switch $(HAIKU_BUILD_PROFILE) {  
    4141        AddGroupToHaikuImage party : 101 : user sshd ;
    4242        HAIKU_STRIP_DEBUG_FROM_OPTIONAL_PACKAGES = 1 ;
    4343        HAIKU_IMAGE_HOST_NAME = shredder ;
    44         HAIKU_IMAGE_SIZE = 600 ;
     44        HAIKU_IMAGE_SIZE = 800 ;
    4545
    4646        AddOptionalHaikuImagePackages Pe Nano Vision P7zip XZ-Utils ;
    4747        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 {  
    8686                        net_interface_address** _interfaceAddress);
    8787
    8888    net_interface*  (*get_interface)(net_domain* domain, uint32 index);
     89    net_interface*  (*get_interface_by_name)(net_domain* domain, const char* ifname);
    8990    net_interface*  (*get_interface_with_address)(
    9091                        const struct sockaddr* address);
    9192    void            (*put_interface)(net_interface* interface);
    9293
    9394    net_interface_address* (*get_interface_address)(
    9495                        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);
    95100    bool            (*get_next_interface_address)(net_interface* interface,
    96101                        net_interface_address** _address);
    97102    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  
    77
    88
    99#include <net_buffer.h>
    10 
     10#define NET_DATA_LINK_INTERFACE_MODULE_NAME "network/stack/datalink/interface/v1"
     11   
    1112
    1213typedef struct net_datalink_protocol {
    1314    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 {  
    8686    B_NET_FRAME_TYPE_IPV6               = 0x0002,
    8787    B_NET_FRAME_TYPE_IPX                = 0x0003,
    8888    B_NET_FRAME_TYPE_APPLE_TALK         = 0x0004,
     89    B_NET_FRAME_TYPE_PPPOE_DISCOVERY        = 0x0005,
     90    B_NET_FRAME_TYPE_PPPOE              = 0x0006,
    8991
    9092    B_NET_FRAME_TYPE_ALL                = 0x0000
    9193};
  • 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 ;  
    66SubInclude HAIKU_TOP src add-ons kernel network notifications ;
    77SubInclude HAIKU_TOP src add-ons kernel network protocols ;
    88SubInclude HAIKU_TOP src add-ons kernel network stack ;
     9SubInclude 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;  
    3636int32
    3737ethernet_deframe(net_device* device, net_buffer* buffer)
    3838{
    39     //dprintf("asked to deframe buffer for device %s\n", device->name);
    40 
    4139    NetBufferHeaderRemover<ether_header> bufferHeader(buffer);
    4240    if (bufferHeader.Status() != B_OK)
    4341        return bufferHeader.Status();
    ethernet_deframe(net_device* device, net_buffer* buffer)  
    8482            buffer->type = B_NET_FRAME_TYPE_IPX;
    8583            break;
    8684
     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
    8795        default:
    8896            buffer->type = B_NET_FRAME_TYPE(IFT_ETHER, type);
    8997            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 *)  
    100100            break;
    101101
    102102        // check link state of all existing devices
    103 
    104103        DoublyLinkedList<ethernet_device>::Iterator iterator
    105104            = sCheckList.GetIterator();
    106105        while (iterator.HasNext()) {
    ethernet_receive_data(net_device *_device, net_buffer **_buffer)  
    342341
    343342err:
    344343    gBufferModule->free(buffer);
     344    // should free the unused buffer
     345    dprintf("%s::%s!!!!!!!!!!!!!!!!!!!!!!!!some severe fault!!!!!!!!!!!!!\n",__FILE__,__func__);
    345346    return status;
    346347}
    347348
  • 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  
    11SubDir HAIKU_TOP src add-ons kernel network ppp ;
    22
    33SubInclude 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 ;
    55SubInclude HAIKU_TOP src add-ons kernel network ppp pap ;
    66SubInclude HAIKU_TOP src add-ons kernel network ppp pppoe ;
    77SubInclude HAIKU_TOP src add-ons kernel network ppp shared ;
     8SubInclude HAIKU_TOP src add-ons kernel network ppp ppp ;
     9SubInclude HAIKU_TOP src add-ons kernel network ppp ppp_frame ;
     10SubInclude 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
    - +  
     1SubDir HAIKU_TOP src add-ons kernel network ppp KPPPManager ;
     2
     3SetSubDirSupportedPlatformsBeOSCompatible ;
     4
     5if $(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
     13UsePrivateKernelHeaders ;
     14    # UsePrivateHeaders net ;
     15
     16UsePrivateHeaders kernel net ;
     17UsePrivateHeaders [ FDirName kernel ] ;
     18UsePrivateHeaders [ FDirName kernel util ] ;
     19
     20UseHeaders [ 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
     29KernelAddon KPPPManager :
     30    KPPPManager.cpp
     31;
     32
     33LinkAgainst KPPPManager : libkernelppp.a ;
     34
     35# Installation
     36HaikuInstall install-networking : /boot/home/config/add-ons/kernel/haiku_network/ppp
     37    : KPPPManager ;
     38
     39Package haiku-networkingkit-cvs :
     40    haiku :
     41    boot home config add-ons kernel haiku_network datalink_protocols ;
     42
     43SEARCH 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
     28struct entry_private : ppp_interface_entry, DoublyLinkedListLinkImpl<entry_private> {
     29};
     30
     31static DoublyLinkedList<entry_private> sEntryList;
     32
     33net_buffer_module_info* gBufferModule = NULL;
     34net_stack_module_info* gStackModule = NULL;
     35// static struct net_interface* sinterface;
     36static mutex sListLock;
     37static uint32 ppp_interface_count;
     38ppp_interface_entry entry[4];
     39
     40//  #pragma mark -
     41
     42static KPPPInterface * GetInterface(ppp_interface_id ID);
     43
     44static ppp_interface_id
     45CreateInterface(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
     85static ppp_interface_id
     86CreateInterfaceWithName(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
     130static bool
     131DeleteInterface(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
     149static bool
     150RemoveInterface(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
     170static net_device *
     171RegisterInterface(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
     201static KPPPInterface *
     202GetInterface(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
     224static bool
     225UnregisterInterface(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
     235static status_t
     236ControlInterface(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
     255static int32
     256GetInterfaces(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
     277static int32
     278CountInterfaces(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
     296static void
     297EnableReports(ppp_report_type type, thread_id thread, int32 flags)
     298{
     299    MutexLocker _(sListLock); // auto_lock
     300
     301    return; // need more portrait
     302}
     303
     304
     305static void
     306DisableReports(ppp_report_type type, thread_id thread)
     307{
     308    MutexLocker _(sListLock); // auto_lock
     309
     310    return; // need more portrait
     311}
     312
     313
     314static bool
     315DoesReport(ppp_report_type type, thread_id thread)
     316{
     317    MutexLocker _(sListLock); // auto_lock
     318
     319    return false; // need more portrait
     320}
     321
     322
     323
     324static status_t
     325KPPPManager_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
     350static 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
     372module_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 ;  
    33SetSubDirSupportedPlatformsBeOSCompatible ;
    44
    55if $(TARGET_PLATFORM) != haiku {
     6        UseHeaders [ FStandardOSHeaders ] : true ;
     7                # Needed for the atomic_add64() prototype. :-/
    68    UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ;
    79        # We need the public network headers also when not compiling for Haiku.
    810        # Unfortunately we get more than we want, namely all POSIX headers.
    911}
    1012
    1113# 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 ;
     16UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ;
     17    # for linking inet_addr function
     18
     19# UsePrivateHeaders shared ;
     20UsePrivateKernelHeaders ;
    1321UsePrivateHeaders net ;
     22
     23UsePrivateHeaders libroot net ;
    1424UsePrivateHeaders [ FDirName kernel ] ;
    1525UsePrivateHeaders [ FDirName kernel util ] ;
    1626UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared
    UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared  
    2333
    2434
    2535KernelAddon ipcp :
     36        atomic.S
     37        kernel_cpp.cpp
     38
    2639    # imported from libnet
    2740    inet_addr.c
    2841   
    KernelAddon ipcp :  
    3043    Protocol.cpp
    3144;
    3245
     46SEARCH on [ FGristFiles bitypes.h ]
     47    = [ FDirName $(HAIKU_TOP) src kits network libbind include sys ] ;
     48
     49SEARCH on [ FGristFiles port_before.h ]
     50    = [ FDirName $(HAIKU_TOP) src kits network libbind ] ;
     51
     52SEARCH on [ FGristFiles port_after.h ]
     53    = [ FDirName $(HAIKU_TOP) src kits network libbind ] ;
     54
     55SEARCH on [ FGristFiles config.h ]
     56    = [ FDirName $(HAIKU_TOP) src kits network libbind ] ;
     57
    3358SEARCH on [ FGristFiles inet_addr.c ]
    34     = [ FDirName $(HAIKU_TOP) src kits network compat libnet ] ;
     59    = [ FDirName $(HAIKU_TOP) src kits network libbind inet ] ;
     60
     61SEARCH on [ FGristFiles kernel_cpp.cpp ]
     62        = [ FDirName $(HAIKU_TOP) src system kernel util ] ;
     63SEARCH on [ FGristFiles atomic.S ]
     64        = [ FDirName $(HAIKU_TOP) src system libroot os arch $(TARGET_ARCH) ] ;
    3565
    3666LinkAgainst ipcp : libkernelppp.a ;
    3767
    3868# Installation
    3969HaikuInstall install-networking
    40     : /boot/home/config/add-ons/kernel/obos_network/ppp
     70    : /boot/home/config/add-ons/kernel/haiku_network/ppp
    4171    : ipcp ;
    4272
    4373Package haiku-networkingkit-cvs :
    4474    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  
    1414#include <settings_tools.h>
    1515
    1616#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>
    1922#include <sys/sockio.h>
    2023
     24extern net_buffer_module_info *gBufferModule;
     25static net_datalink_protocol_module_info *sDatalinkInterfaceProtocolModule;
     26static struct net_datalink_module_info *sDatalinkModule;
     27static struct net_stack_module_info *sStackModule;
    2128
    2229#if DEBUG
    2330#include <unistd.h>
    static int sFD;  
    2633    // the file descriptor for debug output
    2734static char sDigits[] = "0123456789ABCDEF";
    2835void
    29 dump_packet(struct mbuf *packet, const char *direction)
     36dump_packet(net_buffer *packet, const char *direction)
    3037{
    3138    if(!packet)
    3239        return;
    33    
     40
    3441    uint8 *data = mtod(packet, uint8*);
    3542    uint8 buffer[128];
    3643    uint8 bufferIndex = 0;
    37    
     44
    3845    sprintf((char*) buffer, "Dumping %s packet;len=%ld;pkthdr.len=%d\n", direction,
    3946        packet->m_len, packet->m_flags & M_PKTHDR ? packet->m_pkthdr.len : -1);
    4047    write(sFD, buffer, strlen((char*) buffer));
    41    
     48
    4249    for(uint32 index = 0; index < packet->m_len; index++) {
    4350        buffer[bufferIndex++] = sDigits[data[index] >> 4];
    4451        buffer[bufferIndex++] = sDigits[data[index] & 0x0F];
    IPCP::IPCP(KPPPInterface& interface, driver_parameter *settings)  
    7582    // reset configurations
    7683    memset(&fLocalConfiguration, 0, sizeof(ipcp_configuration));
    7784    memset(&fPeerConfiguration, 0, sizeof(ipcp_configuration));
    78    
     85
    7986    // reset requests
    8087    memset(&fLocalRequests, 0, sizeof(ipcp_requests));
    8188    memset(&fPeerRequests, 0, sizeof(ipcp_requests));
    82    
     89
    8390    // Parse settings:
    8491    // "Local" and "Peer" describe each side's settings
    8592    ParseSideRequests(get_parameter_with_name(IPCP_LOCAL_SIDE_KEY, Settings()),
    8693        PPP_LOCAL_SIDE);
    8794    ParseSideRequests(get_parameter_with_name(IPCP_PEER_SIDE_KEY, Settings()),
    8895        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);
    90100#if DEBUG
    91101    sFD = open("/boot/home/ipcpdebug", O_WRONLY | O_CREAT | O_TRUNC);
    92102#endif
    IPCP::IPCP(KPPPInterface& interface, driver_parameter *settings)  
    95105
    96106IPCP::~IPCP()
    97107{
     108
     109    put_module(NET_DATALINK_MODULE_NAME);
     110    put_module(NET_STACK_MODULE_NAME);
     111    put_module(NET_DATA_LINK_INTERFACE_MODULE_NAME);
    98112#if DEBUG
    99113    close(sFD);
    100114#endif
    status_t  
    112126IPCP::StackControl(uint32 op, void *data)
    113127{
    114128    TRACE("IPCP: StackControl(op=%ld)\n", op);
    115    
     129
    116130    // TODO:
    117131    // check values
    118    
     132
    119133    switch(op) {
    120134        case SIOCSIFADDR:
    121135        break;
    122        
     136
    123137        case SIOCSIFFLAGS:
    124138        break;
    125        
     139
    126140        case SIOCSIFDSTADDR:
    127141        break;
    128        
     142
    129143        case SIOCSIFNETMASK:
    130144        break;
    131        
     145
    132146        default:
    133147            ERROR("IPCP: Unknown ioctl: %ld\n", op);
    134148            return KPPPProtocol::StackControl(op, data);
    135149    }
    136    
     150
    137151    return B_OK;
    138152}
    139153
    bool  
    142156IPCP::Up()
    143157{
    144158    TRACE("IPCP: Up() state=%d\n", State());
    145    
     159
    146160    // Servers do not send a configure-request when Up() is called. They wait until
    147161    // the client requests this protocol.
    148162    if(Interface().Mode() == PPP_SERVER_MODE)
    149163        return true;
    150    
     164
    151165    switch(State()) {
    152166        case PPP_INITIAL_STATE:
    153167            NewState(PPP_REQ_SENT_STATE);
    154168            InitializeRestartCount();
    155169            SendConfigureRequest();
    156170        break;
    157        
     171
    158172        default:
    159173            ;
    160174    }
    161    
     175
    162176    return true;
    163177}
    164178
    bool  
    167181IPCP::Down()
    168182{
    169183    TRACE("IPCP: Down() state=%d\n", State());
    170    
     184
    171185    switch(Interface().Phase()) {
    172186        case PPP_DOWN_PHASE:
    173187            // interface finished terminating
    IPCP::Down()  
    175189            ReportDownEvent();
    176190                // this will also reset and update addresses
    177191        break;
    178        
     192
    179193/*      case PPP_TERMINATION_PHASE:
    180194            // interface is terminating
    181195        break;
    182        
     196
    183197        case PPP_ESTABLISHMENT_PHASE:
    184198            // interface is reconfiguring
    185199        break;
    186 */     
     200*/
    187201        case PPP_ESTABLISHED_PHASE:
    188202            // terminate this NCP individually (block until we finished terminating)
    189203            if(State() != PPP_INITIAL_STATE && State() != PPP_CLOSING_STATE) {
    IPCP::Down()  
    191205                InitializeRestartCount();
    192206                SendTerminateRequest();
    193207            }
    194            
     208
    195209            while(State() == PPP_CLOSING_STATE)
    196210                snooze(50000);
    197211        break;
    198        
     212
    199213        default:
    200214            ;
    201215    }
    202    
     216
    203217    return true;
    204218}
    205219
    206220
    207221status_t
    208 IPCP::Send(struct mbuf *packet, uint16 protocolNumber)
     222IPCP::Send(net_buffer *packet, uint16 protocolNumber)
    209223{
    210224    TRACE("IPCP: Send(0x%X)\n", protocolNumber);
    211    
     225
    212226    if((protocolNumber == IP_PROTOCOL && State() == PPP_OPENED_STATE)
    213227            || protocolNumber == IPCP_PROTOCOL) {
    214228#if DEBUG
    IPCP::Send(struct mbuf *packet, uint16 protocolNumber)  
    217231        Interface().UpdateIdleSince();
    218232        return SendToNext(packet, protocolNumber);
    219233    }
    220    
     234
    221235    ERROR("IPCP: Send() failed because of wrong state or protocol number!\n");
    222    
    223     m_freem(packet);
     236
     237    gBufferModule->free(packet);
    224238    return B_ERROR;
    225239}
    226240
    227241
    228242status_t
    229 IPCP::Receive(struct mbuf *packet, uint16 protocolNumber)
     243IPCP::Receive(net_buffer *packet, uint16 protocolNumber)
    230244{
    231245    TRACE("IPCP: Receive(0x%X)\n", protocolNumber);
    232    
     246
    233247    if(!packet)
    234248        return B_ERROR;
    235    
     249
    236250    if(protocolNumber == IP_PROTOCOL)
    237251        return ReceiveIPPacket(packet, protocolNumber);
    238    
     252
    239253    if(protocolNumber != IPCP_PROTOCOL)
    240254        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)
    253258        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
    255272    // packet is freed by event methods
    256     switch(data->code) {
     273    switch(data.code) {
    257274        case PPP_CONFIGURE_REQUEST:
    258275            RCREvent(packet);
    259276        break;
    260        
     277
    261278        case PPP_CONFIGURE_ACK:
    262279            RCAEvent(packet);
    263280        break;
    264        
     281
    265282        case PPP_CONFIGURE_NAK:
    266283        case PPP_CONFIGURE_REJECT:
    267284            RCNEvent(packet);
    268285        break;
    269        
     286
    270287        case PPP_TERMINATE_REQUEST:
    271288            RTREvent(packet);
    272289        break;
    273        
     290
    274291        case PPP_TERMINATE_ACK:
    275292            RTAEvent(packet);
    276293        break;
    277        
     294
    278295        case PPP_CODE_REJECT:
    279296            RXJBadEvent(packet);
    280297                // we implemented the minimum requirements
    281298        break;
    282        
     299
    283300        default:
    284301            RUCEvent(packet);
    285302            return PPP_REJECTED;
    286303    }
    287    
     304
    288305    return B_OK;
    289306}
    290307
    291308
    292309status_t
    293 IPCP::ReceiveIPPacket(struct mbuf *packet, uint16 protocolNumber)
     310IPCP::ReceiveIPPacket(net_buffer *packet, uint16 protocolNumber)
    294311{
    295312    if(protocolNumber != IP_PROTOCOL || State() != PPP_OPENED_STATE)
    296313        return PPP_UNHANDLED;
    297    
     314
    298315    // 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    {
    301319#if DEBUG
    302320        dump_packet(packet, "incoming");
    303321#endif
    304322        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);
    306326        return B_OK;
    307327    } else {
    308328        ERROR("IPCP: Error: Could not find input function for IP!\n");
    309         m_freem(packet);
     329        gBufferModule->free(packet);
    310330        return B_ERROR;
    311331    }
    312332}
    IPCP::Pulse()  
    318338    if(fNextTimeout == 0 || fNextTimeout > system_time())
    319339        return;
    320340    fNextTimeout = 0;
    321    
     341
    322342    switch(State()) {
    323343        case PPP_CLOSING_STATE:
    324344            if(fTerminateCounter <= 0)
    IPCP::Pulse()  
    326346            else
    327347                TOGoodEvent();
    328348        break;
    329        
     349
    330350        case PPP_REQ_SENT_STATE:
    331351        case PPP_ACK_RCVD_STATE:
    332352        case PPP_ACK_SENT_STATE:
    IPCP::Pulse()  
    335355            else
    336356                TOGoodEvent();
    337357        break;
    338        
     358
    339359        default:
    340360            ;
    341361    }
    IPCP::ParseSideRequests(const driver_parameter *requests, ppp_side side)  
    347367{
    348368    if(!requests)
    349369        return false;
    350    
     370
    351371    ipcp_requests *selectedRequests;
    352    
     372
    353373    if(side == PPP_LOCAL_SIDE) {
    354374        selectedRequests = &fLocalRequests;
    355375        fRequestPrimaryDNS = fRequestSecondaryDNS = false;
    356376    } else
    357377        selectedRequests = &fPeerRequests;
    358    
     378
    359379    memset(selectedRequests, 0, sizeof(ipcp_requests));
    360380        // reset current requests
    361    
     381
    362382    // The following values are allowed:
    363383    //  "Address"       the ip address that will be suggested
    364384    //  "Netmask"       the netmask that should be used
    365385    //  "PrimaryDNS"    primary DNS server
    366386    //  "SecondaryDNS"  secondary DNS server
    367387    // Setting any value to 0.0.0.0 or "auto" means it should be chosen automatically.
    368    
     388
    369389    in_addr_t address = INADDR_ANY;
    370390    for(int32 index = 0; index < requests->parameter_count; index++) {
    371391        if(requests->parameters[index].value_count == 0)
    372392            continue;
    373        
     393
    374394        // all values are IP addresses, so parse the address here
    375395        if(strcasecmp(requests->parameters[index].values[0], "auto")) {
    376396            address = inet_addr(requests->parameters[index].values[0]);
     397            // address = INADDR_ANY;
    377398            if(address == INADDR_NONE)
    378399                continue;
    379400        }
    380        
     401
    381402        if(!strcasecmp(requests->parameters[index].name, IPCP_IP_ADDRESS_KEY))
    382403            selectedRequests->address = address;
    383404        else if(!strcasecmp(requests->parameters[index].name, IPCP_NETMASK_KEY))
    IPCP::ParseSideRequests(const driver_parameter *requests, ppp_side side)  
    393414                fRequestSecondaryDNS = true;
    394415        }
    395416    }
    396    
     417
    397418    return true;
    398419}
    399420
    IPCP::ParseSideRequests(const driver_parameter *requests, ppp_side side)  
    401422void
    402423IPCP::UpdateAddresses()
    403424{
     425    TRACE("%s::%s: entering UpdateAddresses\n",__FILE__,__func__);
    404426    RemoveRoutes();
    405    
     427
    406428    if(State() != PPP_OPENED_STATE && !Interface().DoesConnectOnDemand())
    407429        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
    416434    // create local address
    417     inreq.ifra_addr.sin_family = AF_INET;
    418435    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
    462521    // add default/subnet route
    463522    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, &ethaddr);
     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;
    470560    }
    471561}
    472562
    void  
    475565IPCP::RemoveRoutes()
    476566{
    477567    // 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, &ethaddr);
     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
    479587    if(fDefaultRoute) {
    480588        struct sockaddr_in netmask;
    481589        memset(&netmask, 0, sizeof(struct sockaddr_in));
    482        
     590
    483591        netmask.sin_family = AF_INET;
    484592        netmask.sin_addr.s_addr = fLocalRequests.netmask;
    485593        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)
    490598            ERROR("IPCP: RemoveRoutes(): could not remove default/subnet route!\n");
    491        
     599
    492600        fDefaultRoute = NULL;
    493601    }
    494602}
    void  
    505613IPCP::NewState(ppp_state next)
    506614{
    507615    TRACE("IPCP: NewState(%d) state=%d\n", next, State());
    508    
     616
    509617    // report state changes
    510618    if(State() == PPP_INITIAL_STATE && next != State())
    511619        UpStarted();
    512620    else if(State() == PPP_OPENED_STATE && next != State())
    513621        DownStarted();
    514    
     622
    515623    // maybe we do not need the timer anymore
    516624    if(next < PPP_CLOSING_STATE || next == PPP_OPENED_STATE)
    517625        fNextTimeout = 0;
    518    
     626
    519627    fState = next;
    520628}
    521629
    IPCP::TOGoodEvent()  
    526634#if DEBUG
    527635printf("IPCP: TOGoodEvent() state=%d\n", State());
    528636#endif
    529    
     637
    530638    switch(State()) {
    531639        case PPP_CLOSING_STATE:
    532640            SendTerminateRequest();
    533641        break;
    534        
     642
    535643        case PPP_ACK_RCVD_STATE:
    536644            NewState(PPP_REQ_SENT_STATE);
    537        
     645
    538646        case PPP_REQ_SENT_STATE:
    539647        case PPP_ACK_SENT_STATE:
    540648            SendConfigureRequest();
    541649        break;
    542        
     650
    543651        default:
    544652            IllegalEvent(PPP_TO_GOOD_EVENT);
    545653    }
    void  
    550658IPCP::TOBadEvent()
    551659{
    552660    TRACE("IPCP: TOBadEvent() state=%d\n", State());
    553    
     661
    554662    switch(State()) {
    555663        case PPP_CLOSING_STATE:
    556664            NewState(PPP_INITIAL_STATE);
    557665            ReportDownEvent();
    558666        break;
    559        
     667
    560668        case PPP_REQ_SENT_STATE:
    561669        case PPP_ACK_RCVD_STATE:
    562670        case PPP_ACK_SENT_STATE:
    563671            NewState(PPP_INITIAL_STATE);
    564672            ReportUpFailedEvent();
    565673        break;
    566        
     674
    567675        default:
    568676            IllegalEvent(PPP_TO_BAD_EVENT);
    569677    }
    IPCP::TOBadEvent()  
    571679
    572680
    573681void
    574 IPCP::RCREvent(struct mbuf *packet)
     682IPCP::RCREvent(net_buffer *packet)
    575683{
    576684    TRACE("IPCP: RCREvent() state=%d\n", State());
    577    
     685
    578686    KPPPConfigurePacket request(packet);
    579687    KPPPConfigurePacket nak(PPP_CONFIGURE_NAK);
    580688    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
    582695    // 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)
    584697        fID -= 128;
    585    
     698
    586699    nak.SetID(request.ID());
    587700    reject.SetID(request.ID());
    588    
     701
    589702    // parse each item
    590703    ppp_configure_item *item;
    591704    in_addr_t *requestedAddress, *wishedAddress = NULL;
    IPCP::RCREvent(struct mbuf *packet)  
    593706        item = request.ItemAt(index);
    594707        if(!item)
    595708            continue;
    596        
     709
    597710        // addresses have special handling to reduce code size
    598711        switch(item->type) {
    599712            case IPCP_ADDRESSES:
    IPCP::RCREvent(struct mbuf *packet)  
    601714            case IPCP_ADDRESS:
    602715                wishedAddress = &fPeerRequests.address;
    603716            break;
    604            
     717
    605718            case IPCP_PRIMARY_DNS:
    606719                wishedAddress = &fPeerRequests.primaryDNS;
    607720            break;
    608            
     721
    609722            case IPCP_SECONDARY_DNS:
    610723                wishedAddress = &fPeerRequests.secondaryDNS;
    611724            break;
    612725        }
    613        
     726
    614727        // now parse item
    615728        switch(item->type) {
    616729            case IPCP_ADDRESSES:
    IPCP::RCREvent(struct mbuf *packet)  
    620733            case IPCP_SECONDARY_DNS:
    621734                if(item->length != 6) {
    622735                    // the packet is invalid
    623                     m_freem(packet);
     736                    gBufferModule->free(packet);
    624737                    NewState(PPP_INITIAL_STATE);
    625738                    ReportUpFailedEvent();
    626739                    return;
    627740                }
    628                
     741
    629742                requestedAddress = (in_addr_t*) item->data;
    630743                if(*wishedAddress == INADDR_ANY) {
    631744                    if(*requestedAddress == INADDR_ANY) {
    632745                        // we do not have an address for you
    633                         m_freem(packet);
     746                        gBufferModule->free(packet);
    634747                        NewState(PPP_INITIAL_STATE);
    635748                        ReportUpFailedEvent();
    636749                        return;
    IPCP::RCREvent(struct mbuf *packet)  
    644757                    nak.AddItem((ppp_configure_item*) &ipItem);
    645758                }
    646759            break;
    647            
     760
    648761//          case IPCP_COMPRESSION_PROTOCOL:
    649762                // TODO: implement me!
    650763//          break;
    651            
     764
    652765            default:
    653766                reject.AddItem(item);
    654767        }
    655768    }
    656    
     769
    657770    // append additional values to the nak
    658771    if(!request.ItemWithType(IPCP_ADDRESS) && fPeerRequests.address == INADDR_ANY) {
    659772        // The peer did not provide us his address. Tell him to do so.
    IPCP::RCREvent(struct mbuf *packet)  
    663776        ipItem.address = INADDR_ANY;
    664777        nak.AddItem((ppp_configure_item*) &ipItem);
    665778    }
    666    
     779
    667780    if(nak.CountItems() > 0) {
    668781        RCRBadEvent(nak.ToMbuf(Interface().MRU(), Interface().PacketOverhead()), NULL);
    669         m_freem(packet);
     782        gBufferModule->free(packet);
    670783    } else if(reject.CountItems() > 0) {
    671784        RCRBadEvent(NULL, reject.ToMbuf(Interface().MRU(),
    672785            Interface().PacketOverhead()));
    673         m_freem(packet);
     786        gBufferModule->free(packet);
    674787    } else
    675788        RCRGoodEvent(packet);
    676789}
    677790
    678791
    679792void
    680 IPCP::RCRGoodEvent(struct mbuf *packet)
     793IPCP::RCRGoodEvent(net_buffer *packet)
    681794{
    682795    TRACE("IPCP: RCRGoodEvent() state=%d\n", State());
    683    
     796
    684797    switch(State()) {
    685798        case PPP_INITIAL_STATE:
    686799            NewState(PPP_ACK_SENT_STATE);
    IPCP::RCRGoodEvent(struct mbuf *packet)  
    688801            SendConfigureRequest();
    689802            SendConfigureAck(packet);
    690803        break;
    691        
     804
    692805        case PPP_REQ_SENT_STATE:
    693806            NewState(PPP_ACK_SENT_STATE);
    694        
     807
    695808        case PPP_ACK_SENT_STATE:
    696809            SendConfigureAck(packet);
    697810        break;
    698        
     811
    699812        case PPP_ACK_RCVD_STATE:
    700813            NewState(PPP_OPENED_STATE);
    701814            SendConfigureAck(packet);
    702815            ReportUpEvent();
    703816        break;
    704        
     817
    705818        case PPP_OPENED_STATE:
    706819            NewState(PPP_ACK_SENT_STATE);
    707820            SendConfigureRequest();
    708821            SendConfigureAck(packet);
    709822        break;
    710        
     823
    711824        default:
    712             m_freem(packet);
     825            gBufferModule->free(packet);
    713826    }
    714827}
    715828
    716829
    717830void
    718 IPCP::RCRBadEvent(struct mbuf *nak, struct mbuf *reject)
     831IPCP::RCRBadEvent(net_buffer *nak, net_buffer *reject)
    719832{
    720833    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
    722855    switch(State()) {
    723856        case PPP_OPENED_STATE:
    724857            NewState(PPP_REQ_SENT_STATE);
    725858            SendConfigureRequest();
    726        
     859
    727860        case PPP_ACK_SENT_STATE:
    728861            if(State() == PPP_ACK_SENT_STATE)
    729862                NewState(PPP_REQ_SENT_STATE);
    730863                    // OPENED_STATE might have set this already
    731        
     864
    732865        case PPP_INITIAL_STATE:
    733866        case PPP_REQ_SENT_STATE:
    734867        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)
    736869                SendConfigureNak(nak);
    737             else if(reject && ntohs(mtod(reject, ppp_lcp_packet*)->length) > 3)
     870            else if(reject && ntohs(lcp_hdr_reject_length) > 3)
    738871                SendConfigureNak(reject);
    739872        return;
    740873            // prevents the nak/reject from being m_freem()'d
    741        
     874
    742875        default:
    743876            ;
    744877    }
    745    
     878
    746879    if(nak)
    747         m_freem(nak);
     880        gBufferModule->free(nak);
    748881    if(reject)
    749         m_freem(reject);
     882        gBufferModule->free(reject);
    750883}
    751884
    752885
    753886void
    754 IPCP::RCAEvent(struct mbuf *packet)
     887IPCP::RCAEvent(net_buffer *packet)
    755888{
    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) {
    759896        // this packet is not a reply to our request
    760        
     897
    761898        // TODO: log this event
    762         m_freem(packet);
     899        gBufferModule->free(packet);
    763900        return;
    764901    }
    765    
     902
    766903    // parse this ack
    767904    KPPPConfigurePacket ack(packet);
    768905    ppp_configure_item *item;
    IPCP::RCAEvent(struct mbuf *packet)  
    771908        item = ack.ItemAt(index);
    772909        if(!item)
    773910            continue;
    774        
     911
    775912        // addresses have special handling to reduce code size
    776913        switch(item->type) {
    777914            case IPCP_ADDRESSES:
    IPCP::RCAEvent(struct mbuf *packet)  
    780917                wishedAddress = &fLocalRequests.address;
    781918                configuredAddress = &fLocalConfiguration.address;
    782919            break;
    783            
     920
    784921            case IPCP_PRIMARY_DNS:
    785922                wishedAddress = &fLocalRequests.primaryDNS;
    786923                configuredAddress = &fLocalConfiguration.primaryDNS;
    787924            break;
    788            
     925
    789926            case IPCP_SECONDARY_DNS:
    790927                wishedAddress = &fLocalRequests.secondaryDNS;
    791928                configuredAddress = &fLocalConfiguration.secondaryDNS;
    792929            break;
    793930        }
    794        
     931
    795932        // now parse item
    796933        switch(item->type) {
    797934            case IPCP_ADDRESSES:
    IPCP::RCAEvent(struct mbuf *packet)  
    804941                        || *wishedAddress == *requestedAddress)
    805942                    *configuredAddress = *requestedAddress;
    806943            break;
    807            
     944
    808945//          case IPCP_COMPRESSION_PROTOCOL:
    809946                // TODO: implement me
    810947//          break;
    811            
     948
    812949            default:
    813950                ;
    814951        }
    815952    }
    816    
     953
    817954    // if address was not specified we should select the given one
    818955    if(!ack.ItemWithType(IPCP_ADDRESS))
    819956        fLocalConfiguration.address = fLocalRequests.address;
    820    
    821    
     957
     958
    822959    switch(State()) {
    823960        case PPP_INITIAL_STATE:
    824961            IllegalEvent(PPP_RCA_EVENT);
    825962        break;
    826        
     963
    827964        case PPP_REQ_SENT_STATE:
    828965            NewState(PPP_ACK_RCVD_STATE);
    829966            InitializeRestartCount();
    830967        break;
    831        
     968
    832969        case PPP_ACK_RCVD_STATE:
    833970            NewState(PPP_REQ_SENT_STATE);
    834971            SendConfigureRequest();
    835972        break;
    836        
     973
    837974        case PPP_ACK_SENT_STATE:
    838975            NewState(PPP_OPENED_STATE);
    839976            InitializeRestartCount();
    840977            ReportUpEvent();
    841978        break;
    842        
     979
    843980        case PPP_OPENED_STATE:
    844981            NewState(PPP_REQ_SENT_STATE);
    845982            SendConfigureRequest();
    846983        break;
    847        
     984
    848985        default:
    849986            ;
    850987    }
    851    
    852     m_freem(packet);
     988
     989    gBufferModule->free(packet);
    853990}
    854991
    855992
    856993void
    857 IPCP::RCNEvent(struct mbuf *packet)
     994IPCP::RCNEvent(net_buffer *packet)
    858995{
    859996    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) {
    8621004        // this packet is not a reply to our request
    863        
     1005
    8641006        // TODO: log this event
    865         m_freem(packet);
     1007        gBufferModule->free(packet);
    8661008        return;
    8671009    }
    868    
     1010
    8691011    // parse this nak/reject
    8701012    KPPPConfigurePacket nak_reject(packet);
    8711013    ppp_configure_item *item;
    IPCP::RCNEvent(struct mbuf *packet)  
    8751017            item = nak_reject.ItemAt(index);
    8761018            if(!item)
    8771019                continue;
    878            
     1020
    8791021            switch(item->type) {
    8801022                case IPCP_ADDRESSES:
    8811023                    // abandoned by the standard
    8821024                case IPCP_ADDRESS:
    8831025                    if(item->length != 6)
    8841026                        continue;
    885                    
     1027
    8861028                    requestedAddress = (in_addr_t*) item->data;
    8871029                    if(fLocalRequests.address == INADDR_ANY
    8881030                            && *requestedAddress != INADDR_ANY)
    8891031                        fLocalConfiguration.address = *requestedAddress;
    8901032                            // this will be used in our next request
    8911033                break;
    892                
     1034
    8931035//              case IPCP_COMPRESSION_PROTOCOL:
    8941036                    // TODO: implement me!
    8951037//              break;
    896                
     1038
    8971039                case IPCP_PRIMARY_DNS:
    8981040                    if(item->length != 6)
    8991041                        continue;
    900                    
     1042
    9011043                    requestedAddress = (in_addr_t*) item->data;
    9021044                    if(fRequestPrimaryDNS
    9031045                            && fLocalRequests.primaryDNS == INADDR_ANY
    IPCP::RCNEvent(struct mbuf *packet)  
    9051047                        fLocalConfiguration.primaryDNS = *requestedAddress;
    9061048                            // this will be used in our next request
    9071049                break;
    908                
     1050
    9091051                case IPCP_SECONDARY_DNS:
    9101052                    if(item->length != 6)
    9111053                        continue;
    912                    
     1054
    9131055                    requestedAddress = (in_addr_t*) item->data;
    9141056                    if(fRequestSecondaryDNS
    9151057                            && fLocalRequests.secondaryDNS == INADDR_ANY
    IPCP::RCNEvent(struct mbuf *packet)  
    9171059                        fLocalConfiguration.secondaryDNS = *requestedAddress;
    9181060                            // this will be used in our next request
    9191061                break;
    920                
     1062
    9211063                default:
    9221064                    ;
    9231065            }
    IPCP::RCNEvent(struct mbuf *packet)  
    9271069            item = nak_reject.ItemAt(index);
    9281070            if(!item)
    9291071                continue;
    930            
     1072
    9311073            switch(item->type) {
    9321074//              case IPCP_COMPRESSION_PROTOCOL:
    9331075                    // TODO: implement me!
    9341076//              break;
    935                
     1077
    9361078                default:
    9371079                    // DNS and addresses must be supported if we set them to auto
    938                     m_freem(packet);
     1080                    gBufferModule->free(packet);
    9391081                    NewState(PPP_INITIAL_STATE);
    9401082                    ReportUpFailedEvent();
    9411083                    return;
    9421084            }
    9431085        }
    944    
     1086
    9451087    switch(State()) {
    9461088        case PPP_INITIAL_STATE:
    9471089            IllegalEvent(PPP_RCN_EVENT);
    9481090        break;
    949        
     1091
    9501092        case PPP_REQ_SENT_STATE:
    9511093        case PPP_ACK_SENT_STATE:
    9521094            InitializeRestartCount();
    953        
     1095
    9541096        case PPP_ACK_RCVD_STATE:
    9551097        case PPP_OPENED_STATE:
    9561098            if(State() == PPP_ACK_RCVD_STATE || State() == PPP_OPENED_STATE)
    9571099                NewState(PPP_REQ_SENT_STATE);
    9581100            SendConfigureRequest();
    9591101        break;
    960        
     1102
    9611103        default:
    9621104            ;
    9631105    }
    964    
    965     m_freem(packet);
     1106
     1107    gBufferModule->free(packet);
    9661108}
    9671109
    9681110
    9691111void
    970 IPCP::RTREvent(struct mbuf *packet)
     1112IPCP::RTREvent(net_buffer *packet)
    9711113{
    9721114    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
    9741121    // 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)
    9761123        fID -= 128;
    977    
     1124
    9781125    switch(State()) {
    9791126        case PPP_INITIAL_STATE:
    9801127            IllegalEvent(PPP_RTR_EVENT);
    9811128        break;
    982        
     1129
    9831130        case PPP_ACK_RCVD_STATE:
    9841131        case PPP_ACK_SENT_STATE:
    9851132            NewState(PPP_REQ_SENT_STATE);
    986        
     1133
    9871134        case PPP_CLOSING_STATE:
    9881135        case PPP_REQ_SENT_STATE:
    9891136            SendTerminateAck(packet);
    9901137        return;
    991             // do not m_freem() packet
    992        
     1138            // do not free packet
     1139
    9931140        case PPP_OPENED_STATE:
    9941141            NewState(PPP_CLOSING_STATE);
    9951142            ResetRestartCount();
    9961143            SendTerminateAck(packet);
    9971144        return;
    998             // do not m_freem() packet
    999        
     1145            // do not free packet
     1146
    10001147        default:
    10011148            ;
    10021149    }
    1003    
    1004     m_freem(packet);
     1150
     1151    gBufferModule->free(packet);
    10051152}
    10061153
    10071154
    10081155void
    1009 IPCP::RTAEvent(struct mbuf *packet)
     1156IPCP::RTAEvent(net_buffer *packet)
    10101157{
    10111158    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) {
    10141165        // this packet is not a reply to our request
    1015        
     1166
    10161167        // TODO: log this event
    1017         m_freem(packet);
     1168        gBufferModule->free(packet);
    10181169        return;
    10191170    }
    1020    
     1171
    10211172    switch(State()) {
    10221173        case PPP_INITIAL_STATE:
    10231174            IllegalEvent(PPP_RTA_EVENT);
    10241175        break;
    1025        
     1176
    10261177        case PPP_CLOSING_STATE:
    10271178            NewState(PPP_INITIAL_STATE);
    10281179            ReportDownEvent();
    10291180        break;
    1030        
     1181
    10311182        case PPP_ACK_RCVD_STATE:
    10321183            NewState(PPP_REQ_SENT_STATE);
    10331184        break;
    1034        
     1185
    10351186        case PPP_OPENED_STATE:
    10361187            NewState(PPP_REQ_SENT_STATE);
    10371188            SendConfigureRequest();
    10381189        break;
    1039        
     1190
    10401191        default:
    10411192            ;
    10421193    }
    1043    
    1044     m_freem(packet);
     1194
     1195    gBufferModule->free(packet);
    10451196}
    10461197
    10471198
    10481199void
    1049 IPCP::RUCEvent(struct mbuf *packet)
     1200IPCP::RUCEvent(net_buffer *packet)
    10501201{
    10511202    TRACE("IPCP: RUCEvent() state=%d\n", State());
    1052    
     1203
    10531204    SendCodeReject(packet);
    10541205}
    10551206
    10561207
    10571208void
    1058 IPCP::RXJBadEvent(struct mbuf *packet)
     1209IPCP::RXJBadEvent(net_buffer *packet)
    10591210{
    10601211    TRACE("IPCP: RXJBadEvent() state=%d\n", State());
    1061    
     1212
    10621213    switch(State()) {
    10631214        case PPP_INITIAL_STATE:
    10641215            IllegalEvent(PPP_RXJ_BAD_EVENT);
    10651216        break;
    1066        
     1217
    10671218        case PPP_CLOSING_STATE:
    10681219            NewState(PPP_INITIAL_STATE);
    10691220            ReportDownEvent();
    10701221        break;
    1071        
     1222
    10721223        case PPP_REQ_SENT_STATE:
    10731224        case PPP_ACK_RCVD_STATE:
    10741225        case PPP_ACK_SENT_STATE:
    10751226            NewState(PPP_INITIAL_STATE);
    10761227            ReportUpFailedEvent();
    10771228        break;
    1078        
     1229
    10791230        case PPP_OPENED_STATE:
    10801231            NewState(PPP_CLOSING_STATE);
    10811232            InitializeRestartCount();
    10821233            SendTerminateRequest();
    10831234        break;
    1084        
     1235
    10851236        default:
    10861237            ;
    10871238    }
    1088    
    1089     m_freem(packet);
     1239
     1240    gBufferModule->free(packet);
    10901241}
    10911242
    10921243
    IPCP::ReportUpFailedEvent()  
    11051256    // reset configurations
    11061257    memset(&fLocalConfiguration, 0, sizeof(ipcp_configuration));
    11071258    memset(&fPeerConfiguration, 0, sizeof(ipcp_configuration));
    1108    
     1259
    11091260    UpdateAddresses();
    1110    
     1261
    11111262    UpFailedEvent();
    11121263}
    11131264
    void  
    11161267IPCP::ReportUpEvent()
    11171268{
    11181269    UpdateAddresses();
    1119    
     1270
    11201271    UpEvent();
    11211272}
    11221273
    IPCP::ReportDownEvent()  
    11271278    // reset configurations
    11281279    memset(&fLocalConfiguration, 0, sizeof(ipcp_configuration));
    11291280    memset(&fPeerConfiguration, 0, sizeof(ipcp_configuration));
    1130    
     1281
    11311282    UpdateAddresses();
    1132    
     1283
    11331284    DownEvent();
    11341285}
    11351286
    bool  
    11561307IPCP::SendConfigureRequest()
    11571308{
    11581309    TRACE("IPCP: SendConfigureRequest() state=%d\n", State());
    1159    
     1310
    11601311    --fRequestCounter;
    11611312    fNextTimeout = system_time() + kIPCPStateMachineTimeout;
    1162    
     1313
    11631314    KPPPConfigurePacket request(PPP_CONFIGURE_REQUEST);
    11641315    request.SetID(NextID());
    11651316    fRequestID = request.ID();
    11661317    ip_item ipItem;
    11671318    ipItem.length = 6;
    1168    
     1319
    11691320    // add address
    11701321    ipItem.type = IPCP_ADDRESS;
    11711322    if(fLocalRequests.address == INADDR_ANY)
    1172         ipItem.address = fLocalConfiguration.address;
     1323        ipItem.address = (fLocalConfiguration.address);
    11731324    else
    1174         ipItem.address = fLocalRequests.address;
     1325        ipItem.address =(fLocalRequests.address);
    11751326    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",
    11781329        fLocalConfiguration.address, fLocalRequests.address,
    11791330        ((ip_item*)request.ItemAt(0))->address);
    1180    
     1331
    11811332    // add primary DNS (if needed)
    11821333    if(fRequestPrimaryDNS && fLocalRequests.primaryDNS == INADDR_ANY) {
    11831334        ipItem.type = IPCP_PRIMARY_DNS;
    IPCP::SendConfigureRequest()  
    11851336            // at first this is 0.0.0.0, but a nak might have set it to a correct value
    11861337        request.AddItem((ppp_configure_item*) &ipItem);
    11871338    }
    1188    
     1339
    11891340    // add secondary DNS (if needed)
    11901341    if(fRequestSecondaryDNS && fLocalRequests.primaryDNS == INADDR_ANY) {
    11911342        ipItem.type = IPCP_SECONDARY_DNS;
    IPCP::SendConfigureRequest()  
    11931344            // at first this is 0.0.0.0, but a nak might have set it to a correct value
    11941345        request.AddItem((ppp_configure_item*) &ipItem);
    11951346    }
    1196    
     1347
    11971348    // TODO: add VJC support
    1198    
     1349
    11991350    return Send(request.ToMbuf(Interface().MRU(),
    12001351        Interface().PacketOverhead())) == B_OK;
    12011352}
    12021353
    12031354
    12041355bool
    1205 IPCP::SendConfigureAck(struct mbuf *packet)
     1356IPCP::SendConfigureAck(net_buffer *packet)
    12061357{
    12071358    TRACE("IPCP: SendConfigureAck() state=%d\n", State());
    1208    
     1359
    12091360    if(!packet)
    12101361        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
    12131371    KPPPConfigurePacket ack(packet);
    1214    
     1372
    12151373    // verify items
    12161374    ppp_configure_item *item;
    12171375    in_addr_t *requestedAddress, *wishedAddress = NULL, *configuredAddress = NULL;
    IPCP::SendConfigureAck(struct mbuf *packet)  
    12191377        item = ack.ItemAt(index);
    12201378        if(!item)
    12211379            continue;
    1222        
     1380
    12231381        // addresses have special handling to reduce code size
    12241382        switch(item->type) {
    12251383            case IPCP_ADDRESSES:
    IPCP::SendConfigureAck(struct mbuf *packet)  
    12281386                wishedAddress = &fPeerRequests.address;
    12291387                configuredAddress = &fPeerConfiguration.address;
    12301388            break;
    1231            
     1389
    12321390            case IPCP_PRIMARY_DNS:
    12331391                wishedAddress = &fPeerRequests.primaryDNS;
    12341392                configuredAddress = &fPeerConfiguration.primaryDNS;
    12351393            break;
    1236            
     1394
    12371395            case IPCP_SECONDARY_DNS:
    12381396                wishedAddress = &fPeerRequests.secondaryDNS;
    12391397                configuredAddress = &fPeerConfiguration.secondaryDNS;
    12401398            break;
    12411399        }
    1242        
     1400
    12431401        // now parse item
    12441402        switch(item->type) {
    12451403            case IPCP_ADDRESSES:
    IPCP::SendConfigureAck(struct mbuf *packet)  
    12521410                        || *wishedAddress == *requestedAddress)
    12531411                    *configuredAddress = *requestedAddress;
    12541412            break;
    1255            
     1413
    12561414//          case IPCP_COMPRESSION_PROTOCOL:
    12571415                // TODO: implement me!
    12581416//          break;
    1259            
     1417
    12601418            default:
    12611419                ;
    12621420        }
    12631421    }
    1264    
     1422
    12651423    // if address was not specified we should select the given one
    12661424    if(!ack.ItemWithType(IPCP_ADDRESS))
    12671425        fPeerConfiguration.address = fPeerRequests.address;
    1268    
     1426
    12691427    return Send(packet) == B_OK;
    12701428}
    12711429
    12721430
    12731431bool
    1274 IPCP::SendConfigureNak(struct mbuf *packet)
     1432IPCP::SendConfigureNak(net_buffer *packet)
    12751433{
    12761434    TRACE("IPCP: SendConfigureNak() state=%d\n", State());
    1277    
     1435
    12781436    if(!packet)
    12791437        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) {
    12831446        if(fNakCounter == 0) {
    12841447            // We sent enough naks. Let's try a reject.
    1285             nak->code = PPP_CONFIGURE_REJECT;
     1448            nak.code = PPP_CONFIGURE_REJECT;
    12861449        } else
    12871450            --fNakCounter;
    12881451    }
    1289    
     1452
     1453    bufferheader.Sync();
     1454
    12901455    return Send(packet) == B_OK;
    12911456}
    12921457
    bool  
    12951460IPCP::SendTerminateRequest()
    12961461{
    12971462    TRACE("IPCP: SendTerminateRequest() state=%d\n", State());
    1298    
     1463
    12991464    --fTerminateCounter;
    13001465    fNextTimeout = system_time() + kIPCPStateMachineTimeout;
    1301    
    1302     struct mbuf *packet = m_gethdr(MT_DATA);
     1466
     1467    net_buffer *packet = gBufferModule->create(256);
    13031468    if(!packet)
    13041469        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
    13121476    request->code = PPP_TERMINATE_REQUEST;
    13131477    request->id = fTerminateID = NextID();
    13141478    request->length = htons(4);
    1315    
     1479
     1480    status=gBufferModule->trim(packet,4);
     1481    if(status!=B_OK)
     1482        return false;
     1483
    13161484    return Send(packet) == B_OK;
    13171485}
    13181486
    13191487
    13201488bool
    1321 IPCP::SendTerminateAck(struct mbuf *request)
     1489IPCP::SendTerminateAck(net_buffer *request)
    13221490{
    13231491    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
    13291495    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);
    13321501            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        }
    13381503        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
    13451516    return Send(reply) == B_OK;
    13461517}
    13471518
    13481519
    13491520bool
    1350 IPCP::SendCodeReject(struct mbuf *packet)
     1521IPCP::SendCodeReject(net_buffer *packet)
    13511522{
    13521523    TRACE("IPCP: SendCodeReject() state=%d\n", State());
    1353    
     1524
    13541525    if(!packet)
    13551526        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
    13781540    return Send(packet) == B_OK;
    13791541}
  • 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  
    99#include <driver_settings.h>
    1010
    1111#include <KPPPProtocol.h>
    12 #include <Locker.h>
    1312
    1413#include <arpa/inet.h>
     14#include <net_datalink.h>
     15#include <net_datalink_protocol.h>
     16#include <net/route.h>
    1517
    1618
    1719#define IPCP_PROTOCOL   0x8021
    class IPCP : public KPPPProtocol {  
    7173        virtual bool Up();
    7274        virtual bool Down();
    7375       
    74         virtual status_t Send(struct mbuf *packet,
     76        virtual status_t Send(net_buffer *packet,
    7577            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);
    7880        virtual void Pulse();
    7981
    8082    private:
    class IPCP : public KPPPProtocol {  
    9092        // events
    9193        void TOGoodEvent();
    9294        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);
    102104       
    103105        // actions
    104106        void IllegalEvent(ppp_event event);
    class IPCP : public KPPPProtocol {  
    108110        void InitializeRestartCount();
    109111        void ResetRestartCount();
    110112        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);
    113115        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);
    116118
    117119    private:
    118120        ipcp_configuration fLocalConfiguration, fPeerConfiguration;
    class IPCP : public KPPPProtocol {  
    120122       
    121123        // default route
    122124        struct sockaddr_in fGateway;
    123         rtentry *fDefaultRoute;
     125        net_route *fDefaultRoute;
    124126       
    125127        // used for local requests
    126128        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
     57struct __sFILE;
     58extern __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  
    55
    66#include <KernelExport.h>
    77#include <driver_settings.h>
    8 #include <core_funcs.h>
    9 #include <net_module.h>
    108
    11 #include <KPPPInterface.h>
     9#include <net_buffer.h>
     10#include <net_stack.h>
     11#include <NetBufferUtilities.h>
     12
     13#include <KPPPDefs.h>
    1214#include <KPPPModule.h>
     15#include <KPPPInterface.h>
    1316
    1417#include "Protocol.h"
     18// #define NET_CORE_MODULE_NAME "net_stack"
     19// #define NET_STACK_MODULE_NAME "network/stack/v1"
    1520
     21#define IPCP_MODULE_NAME        NETWORK_MODULES_ROOT "/ppp/ipcp"
    1622
    17 #define IPCP_MODULE_NAME        NETWORK_MODULES_ROOT "ppp/ipcp"
    18 
    19 struct protosw *gProto[IPPROTO_MAX];
    20 struct core_module_info *core = NULL;
    2123status_t std_ops(int32 op, ...);
    2224
     25net_stack_module_info *gStackModule = NULL;
     26net_buffer_module_info *gBufferModule = NULL;
     27// net_device_module_info *sEthernetModule;
     28
     29
    2330
    2431// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    2532// TODO: Remove isascii() (needed for inet_aton()) when our kernel is finished!
    extern "C"  
    2835int
    2936isascii(char c)
    3037{
    31     return c & ~0x7f == 0; // If c is a 7 bit value.
     38    return ( (c & (~0x7f)) == 0 ); // If c is a 7 bit value.
    3239}
    3340// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    3441
    add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface,  
    5158        success = mainInterface.AddProtocol(ipcp);
    5259    }
    5360   
    54     TRACE("IPCP: add_to(): %s\n",
     61    dprintf("IPCP: add_to(): %s\n",
    5562        success && ipcp && ipcp->InitCheck() == B_OK ? "OK" : "ERROR");
    5663   
    5764    return success && ipcp && ipcp->InitCheck() == B_OK;
    5865}
    5966
    6067
     68
    6169static ppp_module_info ipcp_module = {
    6270    {
    6371        IPCP_MODULE_NAME,
    std_ops(int32 op, ...)  
    7583{
    7684    switch(op) {
    7785        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);
    7992                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;
    8396       
    8497        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;
    87101       
    88102        default:
    89103            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
     50const 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. */
     91struct 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. */
     104struct 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
     169struct 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
     188extern 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
     215extern 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
     289int daemon(int nochdir, int noclose);
     290#endif
     291
     292#ifdef NEED_STRSEP
     293char * 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
     301int setgroupent(int stayopen);
     302#endif
     303
     304#ifdef NEED_GETGROUPLIST
     305int getgrouplist(GETGROUPLIST_ARGS);
     306#endif
     307
     308#ifdef POSIX_GETGRNAM_R
     309int
     310__posix_getgrnam_r(const char *, struct group *, char *, int, struct group **);
     311#endif
     312
     313#ifdef NEED_GETGRNAM_R
     314int
     315getgrnam_r(const char *,  struct group *, char *, size_t, struct group **);
     316#endif
     317
     318#ifdef POSIX_GETGRGID_R
     319int
     320__posix_getgrgid_r(gid_t, struct group *, char *, int, struct group **) ;
     321#endif
     322
     323#ifdef NEED_GETGRGID_R
     324int
     325getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
     326#endif
     327
     328#ifdef NEED_GETGRENT_R
     329GROUP_R_RETURN getgrent_r(struct group *gptr, GROUP_R_ARGS);
     330#endif
     331
     332#ifdef NEED_SETGRENT_R
     333GROUP_R_SET_RETURN setgrent_r(GROUP_R_ENT_ARGS);
     334#endif
     335
     336#ifdef NEED_ENDGRENT_R
     337GROUP_R_END_RETURN endgrent_r(GROUP_R_ENT_ARGS);
     338#endif
     339
     340#if defined(NEED_INNETGR_R) && defined(NGR_R_RETURN)
     341NGR_R_RETURN
     342innetgr_r(const char *, const char *, const char *, const char *);
     343#endif
     344
     345#ifdef NEED_SETNETGRENT_R
     346#ifdef NGR_R_SET_ARGS
     347NGR_R_SET_RETURN setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS);
     348#else
     349NGR_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
     355NGR_R_END_RETURN endnetgrent_r(NGR_R_END_ARGS);
     356#else
     357NGR_R_END_RETURN endnetgrent_r(void);
     358#endif
     359#endif
     360
     361#ifdef POSIX_GETPWNAM_R
     362int
     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
     368int
     369getpwnam_r(const char *login,  struct passwd *pwptr,
     370        char *buf, size_t buflen, struct passwd **result);
     371#endif
     372
     373#ifdef POSIX_GETPWUID_R
     374int
     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
     380int
     381getpwuid_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
     387PASS_R_SET_RETURN setpwent_r(PASS_R_ENT_ARGS);
     388#else
     389PASS_R_SET_RETURN setpwent_r(void);
     390#endif
     391
     392#endif
     393
     394#ifdef NEED_SETPASSENT_R
     395#ifdef PASS_R_ENT_ARGS
     396PASS_R_SET_RETURN setpassent_r(int stayopen, PASS_R_ENT_ARGS);
     397#else
     398PASS_R_SET_RETURN setpassent_r(int stayopen);
     399#endif
     400#endif
     401
     402#ifdef NEED_GETPWENT_R
     403PASS_R_RETURN getpwent_r(struct passwd *pwptr, PASS_R_ARGS);
     404#endif
     405
     406#ifdef NEED_ENDPWENT_R
     407void endpwent_r(void);
     408#endif
     409
     410#ifdef NEED_SETPASSENT
     411int setpassent(int stayopen);
     412#endif
     413
     414#ifndef __HAIKU__
     415#define gettimeofday isc__gettimeofday
     416#ifdef NEED_GETTIMEOFDAY
     417int isc__gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp);
     418#else
     419int isc__gettimeofday(struct timeval *tp, struct timezone *tzp);
     420#endif
     421#endif
     422
     423int getnetgrent(NGR_R_CONST char **machinep, NGR_R_CONST char **userp,
     424        NGR_R_CONST char **domainp);
     425
     426#ifdef NGR_R_ARGS
     427int 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
     432void setnetgrent(SETNETGRENT_ARGS);
     433#else
     434void setnetgrent(const char *netgroup);
     435#endif
     436
     437void endnetgrent(void);
     438
     439#ifdef INNETGR_ARGS
     440int innetgr(INNETGR_ARGS);
     441#else
     442int innetgr(const char *netgroup, const char *machine,
     443        const char *user, const char *domain);
     444#endif
     445
     446#ifdef NGR_R_SET_ARGS
     447NGR_R_SET_RETURN
     448setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS);
     449#else
     450NGR_R_SET_RETURN
     451setnetgrent_r(NGR_R_SET_CONST char *netgroup);
     452#endif
     453
     454#ifdef NEED_STRTOUL
     455unsigned 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
     463struct sockaddr;
     464struct iovec;
     465struct timeval;
     466struct timezone;
     467int fprintf(FILE *, const char *, ...);
     468int getsockname(int, struct sockaddr *, int *);
     469int getpeername(int, struct sockaddr *, int *);
     470int socket(int, int, int);
     471int connect(int, const struct sockaddr *, int);
     472int writev(int, struct iovec *, int);
     473int readv(int, struct iovec *, int);
     474int send(int, const char *, int, int);
     475void bzero(char *, int);
     476int recvfrom(int, char *, int, int, struct sockaddr *, int *);
     477int syslog(int, const char *, ... );
     478int printf(const char *, ...);
     479__SIZE_TYPE__ fread(void *, __SIZE_TYPE__, __SIZE_TYPE__, FILE *);
     480__SIZE_TYPE__ fwrite(const void *, __SIZE_TYPE__, __SIZE_TYPE__, FILE *);
     481int fclose(FILE *);
     482int ungetc(int, FILE *);
     483int scanf(const char *, ...);
     484int sscanf(const char *, const char *, ... );
     485int tolower(int);
     486int toupper(int);
     487int strcasecmp(const char *, const char *);
     488int strncasecmp(const char *, const char *, int);
     489int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
     490#ifdef gettimeofday
     491#undef gettimeofday
     492int gettimeofday(struct timeval *, struct timezone *);
     493#define gettimeofday isc__gettimeofday
     494#else
     495int gettimeofday(struct timeval *, struct timezone *);
     496#endif
     497long strtol(const char*, char **, int);
     498int fseek(FILE *, long, int);
     499int setsockopt(int, int, int, const char *, int);
     500int bind(int, const struct sockaddr *, int);
     501void bcopy(char *, char *, int);
     502int fputc(char, FILE *);
     503int listen(int, int);
     504int accept(int, struct sockaddr *, int *);
     505int getsockopt(int, int, int, char *, int *);
     506int vfprintf(FILE *, const char *, va_list);
     507int fflush(FILE *);
     508int fgetc(FILE *);
     509int fputs(const char *, FILE *);
     510int fchown(int, int, int);
     511void setbuf(FILE *, char *);
     512int gethostname(char *, int);
     513int rename(const char *, const char *);
     514time_t time(time_t *);
     515int fscanf(FILE *, const char *, ...);
     516int sscanf(const char *, const char *, ...);
     517int ioctl(int, int, caddr_t);
     518void 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 */
     525char *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
     51struct group;           /* silence warning */
     52struct passwd;          /* silence warning */
     53struct timeval;         /* silence warning */
     54struct 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 */
     63struct 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 {  
    99}
    1010
    1111# for kernel_cpp.h and BLocker
    12 UseHeaders [ FDirName $(HAIKU_TOP) headers cpp ] : true ;
     12# UseHeaders [ FDirName $(HAIKU_TOP) headers cpp ] : true ;
     13UsePrivateKernelHeaders ;
     14    #for arch_int.h
    1315UsePrivateHeaders net ;
    1416UsePrivateHeaders [ FDirName kernel ] ;
    1517UsePrivateHeaders [ FDirName kernel util ] ;
    LinkAgainst pap : libkernelppp.a ;  
    3133
    3234# Installation
    3335HaikuInstall install-networking
    34     : /boot/home/config/add-ons/kernel/obos_network/ppp
     36    : /boot/home/config/add-ons/kernel/haiku_network/ppp
    3537    : pap ;
    3638
    3739Package haiku-networkingkit-cvs :
    3840    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  
    99
    1010#include <cstring>
    1111#include <netinet/in.h>
    12 #include <core_funcs.h>
    13 #include <sys/sockio.h>
    1412
     13#include <net_buffer.h>
     14
     15#include <sys/sockio.h>
    1516
     17// static net_buffer_module_info *gBufferModule = NULL;
    1618static const bigtime_t kPAPTimeout = 3000000;
    1719    // 3 seconds
    1820
    PAPHandler::PAPHandler(PAP& owner, KPPPInterface& interface)  
    3335{
    3436}
    3537
     38status_t
     39PAPHandler::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
    3645
    3746status_t
    3847PAPHandler::AddToRequest(KPPPConfigurePacket& request)
    PAP::Down()  
    159168
    160169
    161170status_t
    162 PAP::Send(struct mbuf *packet, uint16 protocolNumber)
     171PAP::Send(net_buffer *packet, uint16 protocolNumber)
    163172{
    164173    // 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);
    166177    return B_ERROR;
    167178}
    168179
    169180
    170181status_t
    171 PAP::Receive(struct mbuf *packet, uint16 protocolNumber)
     182PAP::Receive(net_buffer *packet, uint16 protocolNumber)
    172183{
    173184    if(!packet)
    174185        return B_ERROR;
    PAP::Receive(struct mbuf *packet, uint16 protocolNumber)  
    176187    if(protocolNumber != PAP_PROTOCOL)
    177188        return PPP_UNHANDLED;
    178189   
    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();
    180194   
    181195    // check if the packet is meant for us:
    182196    // 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)
    184198        return PPP_UNHANDLED;
    185199    // 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)
    187201            && Side() != PPP_LOCAL_SIDE)
    188202        return PPP_UNHANDLED;
    189203   
    190204    // 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)
    199209        return B_ERROR;
    200210   
    201211    // packet is freed by event methods
    202212    // code values are the same as for LCP (but very reduced)
    203     switch(data->code) {
     213    switch(data.code) {
    204214        case PPP_CONFIGURE_REQUEST:
    205215            RREvent(packet);
    206216        break;
    PAP::TOBadEvent()  
    320330
    321331
    322332void
    323 PAP::RREvent(struct mbuf *packet)
     333PAP::RREvent(net_buffer *packet)
    324334{
    325335    TRACE("PAP: RREvent() state=%d\n", State());
    326336   
    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;
    330343    uint8 *userLength = data;
    331344    uint8 *passwordLength = data + 1 + data[0];
    332345   
    333346    // make sure the length values are all okay
    334347    if(6 + *userLength + *passwordLength > length) {
    335         m_freem(packet);
     348        gBufferModule->free(packet);
    336349        return;
    337350    }
    338351   
    PAP::RREvent(struct mbuf *packet)  
    357370
    358371
    359372void
    360 PAP::RAEvent(struct mbuf *packet)
     373PAP::RAEvent(net_buffer *packet)
    361374{
    362375    TRACE("PAP: RAEvent() state=%d\n", State());
    363376   
    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) {
    365382        // this packet is not a reply to our request
    366383       
    367384        // TODO: log this event
    368         m_freem(packet);
     385        gBufferModule->free(packet);
    369386        return;
    370387    }
    371388   
    PAP::RAEvent(struct mbuf *packet)  
    381398            ;
    382399    }
    383400   
    384     m_freem(packet);
     401    gBufferModule->free(packet);
    385402}
    386403
    387404
    388405void
    389 PAP::RNEvent(struct mbuf *packet)
     406PAP::RNEvent(net_buffer *packet)
    390407{
    391408    TRACE("PAP: RNEvent() state=%d\n", State());
    392409   
    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) {
    394415        // this packet is not a reply to our request
    395416       
    396417        // TODO: log this event
    397         m_freem(packet);
     418        gBufferModule->free(packet);
    398419        return;
    399420    }
    400421   
    PAP::RNEvent(struct mbuf *packet)  
    410431            ;
    411432    }
    412433   
    413     m_freem(packet);
     434    gBufferModule->free(packet);
    414435}
    415436
    416437
    PAP::SendRequest()  
    429450    --fRequestCounter;
    430451    fNextTimeout = system_time() + kPAPTimeout;
    431452   
    432     struct mbuf *packet = m_gethdr(MT_DATA);
     453    net_buffer *packet = gBufferModule->create(256);
    433454    if(!packet)
    434455        return false;
    435    
     456
     457    ppp_lcp_packet *request;
     458    gBufferModule->append_size(packet,1492,(void **)&request);
     459
    436460    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
    437463   
    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*);
    444464    request->code = PPP_CONFIGURE_REQUEST;
    445465    request->id = fRequestID = NextID();
    446     request->length = htons(packet->m_len);
     466    request->length = htons(pack_len);
    447467    uint8 *data = request->data;
    448468    data[0] = strlen(username);
    449469    memcpy(data + 1, username, strlen(username));
    450470    data[1 + data[0]] = strlen(password);
    451471    memcpy(data + 2 + data[0], password, strlen(password));
     472
     473    gBufferModule->trim(packet,pack_len);
    452474   
    453475    return Interface().Send(packet, PAP_PROTOCOL) == B_OK;
    454476}
    455477
    456478
    457479bool
    458 PAP::SendAck(struct mbuf *packet)
     480PAP::SendAck(net_buffer *packet)
    459481{
    460482    TRACE("PAP: SendAck() state=%d\n", State());
    461483   
    462484    if(!packet)
    463485        return false;
    464486   
    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();
    473498   
    474499    return Interface().Send(packet, PAP_PROTOCOL) == B_OK;
    475500}
    476501
    477502
    478503bool
    479 PAP::SendNak(struct mbuf *packet)
     504PAP::SendNak(net_buffer *packet)
    480505{
    481     TRACE("PAP: SendNak() state=%d\n", State());
     506    ERROR("PAP: SendNak() state=%d\n", State());
    482507   
    483508    if(!packet)
    484509        return false;
    485510   
    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);
    494519   
    495520    return Interface().Send(packet, PAP_PROTOCOL) == B_OK;
    496521}
  • 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 {  
    3636            { return fOwner; }
    3737       
    3838        virtual status_t AddToRequest(KPPPConfigurePacket& request);
     39        virtual status_t SendingAck(const KPPPConfigurePacket&);
    3940        virtual status_t ParseRequest(const KPPPConfigurePacket& request,
    4041            int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject);
    4142
    class PAP : public KPPPProtocol {  
    5758        virtual bool Up();
    5859        virtual bool Down();
    5960       
    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);
    6263        virtual void Pulse();
    6364
    6465    private:
    class PAP : public KPPPProtocol {  
    7071        // events
    7172        void TOGoodEvent();
    7273        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);
    7677       
    7778        // actions
    7879        void ReportUpFailedEvent();
    class PAP : public KPPPProtocol {  
    8081        void ReportDownEvent();
    8182        void InitializeRestartCount();
    8283        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);
    8586
    8687    private:
    8788        // 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  
    55
    66#include <KernelExport.h>
    77#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>
    1011
    1112#include <KPPPInterface.h>
    1213#include <KPPPModule.h>
    1314
    1415#include "Protocol.h"
    1516
     17#define PAP_MODULE_NAME     NETWORK_MODULES_ROOT "/ppp/pap"
    1618
    17 #define PAP_MODULE_NAME     NETWORK_MODULES_ROOT "ppp/pap"
    18 
    19 struct core_module_info *core = NULL;
     19net_stack_module_info *gStackModule = NULL;
     20net_buffer_module_info *gBufferModule = NULL;
    2021status_t std_ops(int32 op, ...);
    2122
    22 
    23 static
    24 bool
     23static bool
    2524add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface,
    2625    driver_parameter *settings, ppp_module_key_type type)
    2726{
    std_ops(int32 op, ...)  
    6261{
    6362    switch(op) {
    6463        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);
    6669                return B_ERROR;
     70            }
    6771        return B_OK;
    6872       
    6973        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);
    7176        break;
    7277       
    7378        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
    - +  
     1SubDir HAIKU_TOP src add-ons kernel network ppp ppp ;
     2
     3SetSubDirSupportedPlatformsBeOSCompatible ;
     4
     5if $(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
     13UsePrivateKernelHeaders ;
     14UsePrivateHeaders net ;
     15UsePrivateHeaders [ FDirName kernel ] ;
     16UsePrivateHeaders [ FDirName kernel util ] ;
     17
     18UseHeaders [ 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
     27KernelAddon ppp :
     28    ppp.cpp
     29;
     30
     31# Installation
     32HaikuInstall install-networking : /boot/home/config/add-ons/kernel/haiku_network/ppp
     33    : ppp ;
     34
     35Package 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
     42net_buffer* create_buffer_for_frame(uint8 *frame, uint16 frame_size);
     43
     44static const bigtime_t kLinkCheckInterval = 1000000;
     45    // 1 second
     46// static ppp_device * s_ppp_dev= NULL;
     47
     48net_buffer_module_info *gBufferModule;
     49ppp_interface_module_info* gPPPInterfaceModule;
     50// net_device_module_info *sEthernetModule;
     51static net_stack_module_info *sStackModule;
     52
     53static mutex sListLock;
     54static DoublyLinkedList<ppp_device> sCheckList;
     55static sem_id sLinkChangeSemaphore;
     56static thread_id sLinkCheckerThread;
     57
     58
     59
     60//  #pragma mark -
     61//
     62
     63status_t
     64ppp_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
     121status_t
     122ppp_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
     136status_t
     137ppp_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
     161void
     162ppp_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
     182status_t
     183ppp_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
     202status_t
     203ppp_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
     227status_t
     228ppp_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
     252status_t
     253ppp_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
     266status_t
     267ppp_set_promiscuous(net_device *_device, bool promiscuous)
     268{
     269    return B_NOT_SUPPORTED;
     270}
     271
     272
     273status_t
     274ppp_set_media(net_device *device, uint32 media)
     275{
     276    return B_NOT_SUPPORTED;
     277}
     278
     279
     280status_t
     281ppp_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
     296status_t
     297ppp_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
     312static status_t
     313ppp_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
     367net_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
     387module_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
    - +  
     1SubDir HAIKU_TOP src add-ons kernel network ppp ppp_frame ;
     2
     3SetSubDirSupportedPlatformsBeOSCompatible ;
     4
     5if $(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
     13UsePrivateKernelHeaders ;
     14UsePrivateHeaders kernel net ;
     15UsePrivateHeaders [ FDirName kernel ] ;
     16UsePrivateHeaders [ FDirName kernel util ] ;
     17
     18UseHeaders [ 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
     27KernelAddon ppp_frame :
     28    ppp_frame.cpp
     29;
     30
     31# Installation
     32HaikuInstall install-networking : /boot/home/config/add-ons/kernel/haiku_network/ppp
     33    : ppp_frame ;
     34
     35Package haiku-networkingkit-cvs :
     36    haiku :
     37    boot home config add-ons kernel haiku_network ppp ;
     38
     39SEARCH 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
     39struct ppp_device : net_device, DoublyLinkedListLinkImpl<ppp_device> {
     40        KPPPInterface *     KPPP_Interface;
     41        uint32                  frame_size;
     42};
     43
     44struct ppp_frame_protocol : net_datalink_protocol {
     45};
     46
     47struct net_buffer_module_info* gBufferModule;
     48struct ppp_interface_module_info* gPPPInterfaceModule;
     49static struct net_interface* sinterface;
     50
     51status_t
     52ppp_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
     60status_t
     61ppp_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
     107err2:
     108    stack->unregister_device_deframer(interface->device);
     109err1:
     110    put_module(NET_STACK_MODULE_NAME);
     111    return status;
     112}
     113
     114
     115status_t
     116ppp_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
     131status_t
     132ppp_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
     139status_t
     140ppp_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
     159void
     160ppp_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
     168status_t
     169ppp_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
     179static status_t
     180PPP_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
     241static status_t
     242ppp_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
     259static status_t
     260ppp_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
     268static status_t
     269ppp_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
     277static status_t
     278pppoe_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
     298static 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
     315module_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  
    55
    66#include "DiscoveryPacket.h"
    77
    8 #include <core_funcs.h>
    9 
     8#include <net_buffer.h>
     9#include <NetBufferUtilities.h>
     10#include <ByteOrder.h>
    1011
    1112DiscoveryPacket::DiscoveryPacket(uint8 code, uint16 sessionID)
    1213    : fCode(code),
    DiscoveryPacket::DiscoveryPacket(uint8 code, uint16 sessionID)  
    1617}
    1718
    1819
    19 DiscoveryPacket::DiscoveryPacket(struct mbuf *packet, uint32 start)
     20DiscoveryPacket::DiscoveryPacket(net_buffer *packet, uint32 start)
    2021{
    2122    // 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();
    2530   
    26     SetCode(header->code);
     31    SetCode(header.code);
    2732   
    28     uint16 length = ntohs(header->length);
     33    uint16 length = ntohs(header.length);
    2934   
    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);
    3140        fInitStatus = B_ERROR;
    3241        return;
    3342            // there are no tags (or one corrupted tag)
    DiscoveryPacket::DiscoveryPacket(struct mbuf *packet, uint32 start)  
    3746    pppoe_tag *tag;
    3847   
    3948    while(position <= length - 4) {
    40         tag = (pppoe_tag*) (header->data + position);
     49        tag = (pppoe_tag*) (header.data + position);
    4150        position += ntohs(tag->length) + 4;
    4251       
    4352        AddTag(ntohs(tag->type), tag->data, ntohs(tag->length));
    DiscoveryPacket::TagWithType(uint16 type) const  
    116125}
    117126
    118127
    119 struct mbuf*
     128net_buffer*
    120129DiscoveryPacket::ToMbuf(uint32 MTU, uint32 reserve)
    121130{
    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    }
    126143   
    127144    header->version = PPPoE_VERSION;
    128145    header->type = PPPoE_TYPE;
    DiscoveryPacket::ToMbuf(uint32 MTU, uint32 reserve)  
    137154       
    138155        // make sure we have enough space left
    139156        if(MTU - length < tag->length) {
    140             m_freem(packet);
     157            gBufferModule->free(packet);
    141158            return NULL;
    142159        }
    143160       
    DiscoveryPacket::ToMbuf(uint32 MTU, uint32 reserve)  
    150167    }
    151168   
    152169    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
    155176    return packet;
    156177}
  • 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  
    1010
    1111#include <TemplateList.h>
    1212
     13#define ETHER_HDR_LEN 14
    1314
    1415enum PPPoE_TAG_TYPE {
    1516    END_OF_LIST = 0x0000,
    typedef struct pppoe_tag {  
    3738    uint16 type;
    3839    uint16 length;
    3940    uint8 data[0];
    40 };
     41} pppoe_tag;
    4142
    4243
    4344class DiscoveryPacket {
    4445    public:
    4546        DiscoveryPacket(uint8 code, uint16 sessionID = 0x0000);
    46         DiscoveryPacket(struct mbuf *packet, uint32 start = 0);
     47        DiscoveryPacket(net_buffer *packet, uint32 start = 0);
    4748        ~DiscoveryPacket();
    4849       
    4950        status_t InitCheck() const
    class DiscoveryPacket {  
    6667        pppoe_tag *TagAt(int32 index) const;
    6768        pppoe_tag *TagWithType(uint16 type) const;
    6869       
    69         struct mbuf *ToMbuf(uint32 MTU, uint32 reserve = ETHER_HDR_LEN);
    70             // the user is responsible for freeing the mbuf
     70        net_buffer *ToMbuf(uint32 MTU, uint32 reserve = ETHER_HDR_LEN);
     71            // the user is responsible for freeing the net_buffer
    7172
    7273    private:
    7374        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 {  
    99}
    1010
    1111# for kernel_cpp.h and BLocker
    12 UseHeaders [ FDirName $(HAIKU_TOP) headers cpp ] : true ;
     12# UseHeaders [ FDirName $(HAIKU_TOP) headers cpp ] : true ;
     13
     14UsePrivateKernelHeaders ;
    1315UsePrivateHeaders net ;
    1416UsePrivateHeaders [ FDirName kernel ] ;
    1517UsePrivateHeaders [ FDirName kernel util ] ;
    LinkAgainst pppoe : libkernelppp.a ;  
    3234
    3335# Installation
    3436HaikuInstall install-networking
    35     : /boot/home/config/add-ons/kernel/obos_network/ppp
     37    : /boot/home/config/add-ons/kernel/haiku_network/ppp
    3638    : pppoe ;
    3739
    3840Package haiku-networkingkit-cvs :
    3941    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  
    88
    99#include <SupportDefs.h>
    1010#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>
    1215
    1316class PPPoEDevice;
    1417
    typedef struct complete_pppoe_header {  
    6063
    6164
    6265// defined in pppoe.cpp
    63 extern ifnet *FindPPPoEInterface(const char *name);
     66extern net_device *FindPPPoEInterface(const char *name);
    6467extern uint32 NewHostUniq();
    6568extern void add_device(PPPoEDevice *device);
    6669extern void remove_device(PPPoEDevice *device);
    6770
    6871#if DEBUG
    6972// defined in PPPoEDevice.cpp
    70 extern void dump_packet(struct mbuf *packet);
     73extern void dump_packet(net_buffer *packet);
    7174#endif // DEBUG
    7275
    7376
  • 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  
    55
    66#include "PPPoEDevice.h"
    77#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>
    814
    9 #include <core_funcs.h>
    1015#include <cstdlib>
    1116
    1217// from libkernelppp
    1318#include <settings_tools.h>
    1419
     20extern net_stack_module_info *gStackModule;
     21extern net_buffer_module_info *gBufferModule;
     22extern status_t
     23pppoe_input(void *cookie, net_device *_device, net_buffer *packet);
    1524
    1625#if DEBUG
    1726static char sDigits[] = "0123456789ABCDEF";
    1827void
    19 dump_packet(struct mbuf *packet)
     28dump_packet(net_buffer *packet)
    2029{
    2130    if(!packet)
    2231        return;
    2332   
    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;
    2538    uint8 buffer[33];
    2639    uint8 bufferIndex = 0;
    2740   
    PPPoEDevice::PPPoEDevice(KPPPInterface& interface, driver_parameter *settings)  
    6275        // we do not want to fail just because the other side requests PFC
    6376   
    6477    memset(fPeer, 0xFF, sizeof(fPeer));
     78    memcpy(fEtherAddr,etheraddr,sizeof(fEtherAddr));
     79
    6580    SetMTU(1494);
    6681        // MTU size does not contain PPP header
    6782   
     83    if(!settings)
     84        dprintf("%s::%s: settings is NULL\n",__FILE__,__func__);
     85
    6886    // 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
    7391    fACName = get_parameter_value(PPPoE_AC_NAME_KEY, settings);
     92    TRACE("fACName is %s\n",fACName ? fACName : "NULL");
     93
    7494    fServiceName = get_parameter_value(PPPoE_SERVICE_NAME_KEY, settings);
     95    TRACE("fServiceName is %s\n", fServiceName ? fServiceName : "NULL");
    7596   
    76     fEthernetIfnet = FindPPPoEInterface(interfaceName);
     97    // fEthernetIfnet = FindPPPoEInterface(interfaceName);
    7798   
    7899#if DEBUG
    79100    if(!fEthernetIfnet)
    80101        TRACE("PPPoEDevice::ctor: could not find ethernet interface\n");
     102    else
     103        TRACE("%s::%s: Find Ethernet device",__FILE__,__func__);
    81104#endif
    82105}
    83106
    PPPoEDevice::PPPoEDevice(KPPPInterface& interface, driver_parameter *settings)  
    85108status_t
    86109PPPoEDevice::InitCheck() const
    87110{
    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;
    90115}
    91116
    92117
    PPPoEDevice::Up()  
    101126    if(IsUp())
    102127        return true;
    103128   
     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
    104146    add_device(this);
    105147   
    106148    fState = INITIAL;
    PPPoEDevice::Up()  
    125167    discovery.AddTag(END_OF_LIST, NULL, 0);
    126168   
    127169    // set up PPP header
    128     struct mbuf *packet = discovery.ToMbuf(MTU());
     170    net_buffer *packet = discovery.ToMbuf(MTU());
    129171    if(!packet)
    130172        return false;
    131173   
    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
    142186    // check if we are allowed to go up now (user intervention might disallow that)
    143187    if(fAttempts > 0 && !UpStarted()) {
    144188        fAttempts = 0;
    PPPoEDevice::Up()  
    151195    fState = PADI_SENT;
    152196        // needed before sending, otherwise we might not get all packets
    153197   
    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) {
    155209        fState = INITIAL;
    156210        fAttempts = 0;
    157211        ERROR("PPPoEDevice::Up(): EthernetIfnet()->output() failed!\n");
    158212        return false;
    159213    }
    160    
     214
     215    dprintf("PPPoEDevice::Up(): EthernetIfnet()->output() success!\n");
    161216    fNextTimeout = system_time() + PPPoE_TIMEOUT;
    162217   
    163218    return true;
    PPPoEDevice::Down()  
    169224{
    170225    TRACE("PPPoEDevice: Down()\n");
    171226   
     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
    172232    remove_device(this);
    173233   
    174234    if(InitCheck() != B_OK)
    PPPoEDevice::Down()  
    191251    DiscoveryPacket discovery(PADT, SessionID());
    192252    discovery.AddTag(END_OF_LIST, NULL, 0);
    193253   
    194     struct mbuf *packet = discovery.ToMbuf(MTU());
     254    net_buffer *packet = discovery.ToMbuf(MTU());
    195255    if(!packet) {
    196256        ERROR("PPPoEDevice::Down(): ToMbuf() failed; MTU=%ld\n", MTU());
    197257        DownEvent();
    PPPoEDevice::Down()  
    205265    destination.sa_family = AF_UNSPEC;
    206266        // raw packet with ethernet header
    207267    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));
    210270   
    211271    // reset connection settings
    212272    memset(fPeer, 0xFF, sizeof(fPeer));
    213273   
    214     EthernetIfnet()->output(EthernetIfnet(), packet, &destination, NULL);
     274    EthernetIfnet()->module->send_data(EthernetIfnet(), packet);
    215275    DownEvent();
    216276   
    217277    return true;
    PPPoEDevice::CountOutputBytes() const  
    242302
    243303
    244304status_t
    245 PPPoEDevice::Send(struct mbuf *packet, uint16 protocolNumber)
     305PPPoEDevice::Send(net_buffer *packet, uint16 protocolNumber)
    246306{
    247307    // Send() is only for PPP packets. PPPoE packets are sent directly to ethernet.
    248308   
    PPPoEDevice::Send(struct mbuf *packet, uint16 protocolNumber)  
    252312        return B_ERROR;
    253313    else if(InitCheck() != B_OK || protocolNumber != 0) {
    254314        ERROR("PPPoEDevice::Send(): InitCheck() != B_OK!\n");
    255         m_freem(packet);
     315        gBufferModule->free(packet);
    256316        return B_ERROR;
    257317    }
    258318   
    259319    if(!IsUp()) {
    260320        ERROR("PPPoEDevice::Send(): no connection!\n");
    261         m_freem(packet);
     321        gBufferModule->free(packet);
    262322        return PPP_NO_CONNECTION;
    263323    }
    264324   
    265     uint16 length = packet->m_flags & M_PKTHDR ? packet->m_pkthdr.len : packet->m_len;
     325    uint16 length = packet->size;
    266326   
    267327    // 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 &ethheader = 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
    285350   
    286     if(!packet || !mtod(packet, pppoe_header*))
     351    if(!packet)
    287352        ERROR("PPPoEDevice::Send(): packet is NULL!\n");
    288353   
    289     if(EthernetIfnet()->output(EthernetIfnet(), packet, &destination, NULL) != B_OK) {
     354    if(EthernetIfnet()->module->send_data(EthernetIfnet(), packet) != B_OK) {
    290355        ERROR("PPPoEDevice::Send(): EthernetIfnet()->output() failed!\n");
    291356        remove_device(this);
    292357        DownEvent();
    PPPoEDevice::Send(struct mbuf *packet, uint16 protocolNumber)  
    297362    return B_OK;
    298363}
    299364
    300 
    301365status_t
    302 PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber)
     366PPPoEDevice::Receive(net_buffer *packet, uint16 protocolNumber)
    303367{
     368    TRACE("%s entering %s: protocolNumber:%x\n",__FILE__,__func__,protocolNumber);
    304369    if(!packet)
    305370        return B_ERROR;
    306371    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");
    308375        return B_ERROR;
    309376    }
    310377   
    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//  }
    316387   
    317388    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
    319392    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");
    328402            return B_ERROR;
    329403        }
    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
    332420        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();
    336429       
    337430        // 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");
    340434            return B_ERROR;
    341435        }
    342436       
    343437        if(IsDown()) {
    344             m_freem(packet);
     438            //gBufferModule->free(packet);
     439            dprintf("PPPoEDevice::Receive fail PPPoEDev IsDown\n");
    345440            return B_ERROR;
    346441        }
    347442       
    348443        DiscoveryPacket discovery(packet);
    349444        switch(discovery.Code()) {
    350445            case PADO: {
     446                dprintf("processing PADO\n");
    351447                if(fState != PADI_SENT) {
    352                     m_freem(packet);
     448                    //gBufferModule->free(packet);
     449                    dprintf("PPPoEDevice::Receive faile not PADI_Sent \n");
    353450                    return B_OK;
    354451                }
    355452               
    PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber)  
    364461                    switch(tag->type) {
    365462                        case SERVICE_NAME:
    366463                            if(!hasServiceName && (!ServiceName()
    367                                     || (strlen(ServiceName()) == tag->length)
     464                                    || ((strlen(ServiceName()) == tag->length)
    368465                                        && !memcmp(tag->data, ServiceName(),
    369                                             tag->length))) {
     466                                            tag->length)))) {
    370467                                hasServiceName = true;
    371468                                reply.AddTag(tag->type, tag->data, tag->length);
    372469                            }
    PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber)  
    374471                       
    375472                        case AC_NAME:
    376473                            if(!hasACName && (!ACName()
    377                                     || (strlen(ACName()) == tag->length)
     474                                    || ((strlen(ACName()) == tag->length)
    378475                                        && !memcmp(tag->data, ACName(),
    379                                             tag->length))) {
     476                                            tag->length)))) {
    380477                                hasACName = true;
    381478                                reply.AddTag(tag->type, tag->data, tag->length);
    382479                            }
    PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber)  
    390487                        case SERVICE_NAME_ERROR:
    391488                        case AC_SYSTEM_ERROR:
    392489                        case GENERIC_ERROR:
    393                             m_freem(packet);
     490                            //gBufferModule->free(packet);
     491                            dprintf("PPPoEDevice::generic error faile\n");
    394492                            return B_ERROR;
    395493                        break;
    396494                       
    PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber)  
    400498                }
    401499               
    402500                if(!hasServiceName) {
    403                     m_freem(packet);
     501                    //gBufferModule->free(packet);
     502                    dprintf("PPPoEDevice::Receive faile no svc name\n");
    404503                    return B_ERROR;
    405504                }
    406505               
     506                dprintf("reply.AddTag\n");
    407507                reply.AddTag(HOST_UNIQ, &fHostUniq, sizeof(fHostUniq));
    408508                reply.AddTag(END_OF_LIST, NULL, 0);
    409                 struct mbuf *replyPacket = reply.ToMbuf(MTU());
     509                net_buffer *replyPacket = reply.ToMbuf(MTU());
    410510                if(!replyPacket) {
    411                     m_freem(packet);
     511                    //gBufferModule->free(packet);
     512                    dprintf("PPPoEDevice::Receive fail no reply pack\n");
    412513                    return B_ERROR;
    413514                }
    414515               
    415                 memcpy(fPeer, ethernetSource, sizeof(fPeer));
     516                memcpy(fPeer, ethernetSource, ETHER_ADDRESS_LENGTH);
    416517               
    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
    426529               
    427530                fState = PADR_SENT;
    428531               
    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");
    432535                    return B_ERROR;
    433536                }
    434537               
    PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber)  
    436539            } break;
    437540           
    438541            case PADS:
     542                dprintf("procesing PADS\n");
    439543                if(fState != PADR_SENT
    440544                        || memcmp(ethernetSource, fPeer, sizeof(fPeer))) {
    441                     m_freem(packet);
     545                    //gBufferModule->free(packet);
     546                    dprintf("PPPoEDevice::Receive PADS but no PADR sent\n");
    442547                    return B_ERROR;
    443548                }
    444549               
    445                 fSessionID = header->sessionID;
     550                fSessionID = header.sessionID;
    446551                fState = OPENED;
    447552                fNextTimeout = 0;
    448553                UpEvent();
    449554            break;
    450555           
    451556            case PADT:
     557                dprintf("procesing PADT\n");
    452558                if(!IsUp()
    453559                        || 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");
    456563                    return B_ERROR;
    457564                }
    458565               
    PPPoEDevice::Receive(struct mbuf *packet, uint16 protocolNumber)  
    465572            break;
    466573           
    467574            default:
    468                 m_freem(packet);
     575                dprintf("PPPoEDevice::Receive fail unknown pppoed code\n");
     576                //gBufferModule->free(packet);
    469577                return B_ERROR;
    470578        }
    471579    } else
    472580        result = B_ERROR;
    473581   
    474     m_freem(packet);
     582    dprintf("PPPoEDevice::Receive fail unknow packet type\n");
     583    //gBufferModule->free(packet);
    475584    return result;
    476585}
    477586
    void  
    480589PPPoEDevice::Pulse()
    481590{
    482591    // We use Pulse() for timeout of connection establishment.
    483    
    484592    if(fNextTimeout == 0 || IsUp() || IsDown())
    485593        return;
    486594   
  • 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  
    1010
    1111#include <KPPPDevice.h>
    1212
     13#include <net/if_types.h>
     14#include <net_stack.h>
     15
     16
     17const uint8 etheraddr[6]={
     18    0x00,0x00,0x00,0x00,0x00,0x00  //src for Y470
     19};
     20
    1321
    1422enum pppoe_state {
    1523    INITIAL,
    class PPPoEDevice : public KPPPDevice {  
    2533    public:
    2634        PPPoEDevice(KPPPInterface& interface, driver_parameter *settings);
    2735       
    28         ifnet *EthernetIfnet() const
     36        net_device *EthernetIfnet() const
    2937            { return fEthernetIfnet; }
    3038       
    3139        const uint8 *Peer() const
    class PPPoEDevice : public KPPPDevice {  
    5058       
    5159        virtual uint32 CountOutputBytes() const;
    5260       
    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);
    5563       
    5664        virtual void Pulse();
    5765
    5866    private:
    59         ifnet *fEthernetIfnet;
     67        net_device *fEthernetIfnet;
    6068        uint8 fPeer[6];
     69        uint8 fEtherAddr[6];
    6170        uint16 fSessionID;
    6271        uint32 fHostUniq;
    6372        const char *fACName, *fServiceName;
     73        const char *finterfaceName;
    6474       
    6575        uint32 fAttempts;
    6676        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  
    55
    66#include <KernelExport.h>
    77#include <driver_settings.h>
    8 #include <core_funcs.h>
    9 #include <net_module.h>
    108
    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>
    1216
    1317#include <KPPPInterface.h>
    1418#include <KPPPModule.h>
    1519#include <KPPPUtils.h>
    16 #include <LockerHelper.h>
     20
     21#include <lock.h>
     22#include <util/AutoLock.h>
     23#include <ByteOrder.h>
    1724
    1825#include "PPPoEDevice.h"
    1926#include "DiscoveryPacket.h"
    2027
    2128
    2229typedef struct pppoe_query {
    23     ifnet *ethernetIfnet;
     30    net_device *ethernetIfnet;
    2431    uint32 hostUniq;
    2532    thread_id receiver;
    2633} pppoe_query;
    2734
    28 #define PPPoE_MODULE_NAME       NETWORK_MODULES_ROOT "ppp/pppoe"
     35#define PPPoE_MODULE_NAME   "network/ppp/pppoe"
     36
     37net_stack_module_info *gStackModule = NULL;
     38net_buffer_module_info *gBufferModule = NULL;
     39net_datalink_module_info *sDatalinkModule = NULL;
    2940
    30 struct core_module_info *core = NULL;
    31 static struct ethernet_module_info *sEthernet;
     41// static net_device_module_info *sEthernetModule = NULL;
    3242static int32 sHostUniq = 0;
    3343status_t std_ops(int32 op, ...);
    3444
    35 static BLocker sLock("PPPoEList");
     45// static mutex sLock("PPPoEList");
     46// static mutex sLock; // ("PPPoEList");
     47
    3648static TemplateList<PPPoEDevice*> *sDevices;
    3749static TemplateList<pppoe_query*> *sQueries;
    3850
    SendQueryPacket(pppoe_query *query, DiscoveryPacket& discovery)  
    7688}
    7789
    7890
    79 ifnet*
     91net_device*
    8092FindPPPoEInterface(const char *name)
    8193{
    8294    if(!name)
    8395        return NULL;
    8496   
    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(&current, 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);
    90106    }
    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
    92117    return NULL;
    93118}
    94119
    95 
    96120uint32
    97121NewHostUniq()
    98122{
    add_device(PPPoEDevice *device)  
    105129{
    106130    TRACE("PPPoE: add_device()\n");
    107131   
    108     LockerHelper locker(sLock);
     132    // MutexLocker locker(sLock);
    109133    if(!sDevices->HasItem(device))
    110134        sDevices->AddItem(device);
    111135}
    remove_device(PPPoEDevice *device)  
    116140{
    117141    TRACE("PPPoE: remove_device()\n");
    118142   
    119     LockerHelper locker(sLock);
     143    // MutexLocker locker(sLock);
    120144    sDevices->RemoveItem(device);
    121145}
    122146
    123147
    124 static
    125 void
    126 pppoe_input(struct mbuf *packet)
     148status_t
     149pppoe_input(void *cookie, net_device *_device, net_buffer *packet)
    127150{
    128151    if(!packet)
    129         return;
     152        return B_ERROR;
     153    TRACE("%s::%s: receive pppoe packet type:%ld!\n",__FILE__,__func__,packet->type);
    130154   
    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
    133182    PPPoEDevice *device;
    134183    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));
    135188   
    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) {
    140198        for(int32 index = 0; index < sDevices->CountItems(); index++) {
    141199            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) {
    145203                    DiscoveryPacket discovery(packet, ETHER_HDR_LEN);
    146204                    if(discovery.InitCheck() != B_OK) {
    147205                        ERROR("PPPoE: received corrupted discovery packet!\n");
    148                         m_freem(packet);
    149                         return;
     206                        // gBufferModule->free(packet);
     207                        return B_ERROR;
    150208                    }
    151209                   
    152210                    pppoe_tag *hostTag = discovery.TagWithType(HOST_UNIQ);
    153211                    if(hostTag && hostTag->length == 4
    154212                            && *((uint32*)hostTag->data) == query->hostUniq) {
    155213                        SendQueryPacket(query, discovery);
    156                         m_freem(packet);
    157                         return;
     214                        // gBufferModule->free(packet);
     215                        return B_ERROR;
    158216                    }
    159217                }
    160218            }
    161219        }
    162220    }
    163221   
     222    TRACE("in pppoed processing sDevices->CountItems(): %ld\n",sDevices->CountItems());
    164223    for(int32 index = 0; index < sDevices->CountItems(); index++) {
    165224        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()) {
    170233                TRACE("PPPoE: session packet\n");
    171234                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
    176240                    && !device->IsDown()) {
    177241                TRACE("PPPoE: discovery packet\n");
     242
    178243                DiscoveryPacket discovery(packet, ETHER_HDR_LEN);
    179244                if(discovery.InitCheck() != B_OK) {
    180245                    ERROR("PPPoE: received corrupted discovery packet!\n");
    181                     m_freem(packet);
    182                     return;
     246                    gBufferModule->free(packet);
     247                    return B_OK;
    183248                }
    184249               
    185250                pppoe_tag *tag = discovery.TagWithType(HOST_UNIQ);
    186                 if(header->pppoeHeader.code == PADT || (tag && tag->length == 4
    187                         && *((uint32*)tag->data) == device->HostUniq())) {
     251                if(header.code == PADT || (tag && tag->length == 4
     252                    && *((uint32*)tag->data) == device->HostUniq())) {
    188253                    device->Receive(packet);
    189                     return;
     254                    return B_OK;
    190255                }
     256               
    191257            }
    192258        }
    193259    }
    194260   
    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;
    197264}
    198265
    199266
    control(uint32 op, void *data, size_t length)  
    231298            int32 position = 0, count = 0;
    232299            char *names = (char*) data;
    233300           
    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)
    238305                        return B_NO_MEMORY;
    239306                   
    240                     strcpy(names + position, current->if_name);
    241                     position += strlen(current->if_name);
     307                    strcpy(names + position, current->name);
     308                    position += strlen(current->name);
    242309                    names[position++] = 0;
    243310                    ++count;
    244311                }
    control(uint32 op, void *data, size_t length)  
    263330            query.hostUniq = NewHostUniq();
    264331            query.receiver = request->receiver;
    265332           
    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            }
    269338           
    270339            snooze(2000000);
    271340                // 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            }
    276346        } break;
    277347       
    278348        default:
    std_ops(int32 op, ...)  
    300370{
    301371    switch(op) {
    302372        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)
    304374                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;
    305384           
    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//          }
    311390           
    312             set_max_linkhdr(2 + PPPoE_HEADER_SIZE + ETHER_HDR_LEN);
     391            // set_max_linkhdr(2 + PPPoE_HEADER_SIZE + ETHER_HDR_LEN);
    313392                // 2 bytes for PPP header
    314393            sDevices = new TemplateList<PPPoEDevice*>;
    315394            sQueries = new TemplateList<pppoe_query*>;
    316             sEthernet->set_pppoe_receiver(pppoe_input);
     395            // sEthernet->set_pppoe_receiver(pppoe_input);
    317396           
    318397            TRACE("PPPoE: Registered PPPoE receiver.\n");
    319398        return B_OK;
    320399       
    321400        case B_MODULE_UNINIT:
    322401            delete sDevices;
    323             sEthernet->unset_pppoe_receiver();
     402            // sEthernet->unset_pppoe_receiver();
    324403            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);
    327408        break;
    328409       
    329410        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 {  
    1010        # Unfortunately we get more than we want, namely all POSIX headers.
    1111}
    1212
     13UsePrivateKernelHeaders ;
     14UsePrivateHeaders net ;
     15
    1316UsePrivateHeaders libroot net ;
    1417UsePrivateHeaders [ FDirName kernel ] ;
    1518UsePrivateHeaders [ FDirName kernel util ] ;
    KernelStaticLibrary libkernelppp.a :  
    3740    KPPPReportManager.cpp
    3841    KPPPStateMachine.cpp
    3942    KPPPUtils.cpp
    40     Locker.cpp
    4143    settings_tools.cpp
    4244   
    4345    # integrated modules
    KernelStaticLibrary libkernelppp.a :  
    4951
    5052SEARCH on [ FGristFiles kernel_cpp.cpp ]
    5153    = [ FDirName $(HAIKU_TOP) src system kernel util ] ;
    52 SEARCH on [ FGristFiles Locker.cpp ]
    53     = [ FDirName $(HAIKU_TOP) src system kernel disk_device_manager ] ;
    5454SEARCH on [ FGristFiles atomic.S ]
    5555    = [ 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  
    1212#include <KPPPConfigurePacket.h>
    1313#include <KPPPInterface.h>
    1414
    15 #include <core_funcs.h>
     15#include <net_buffer.h>
     16#include <ByteOrder.h>
     17#include <net_stack.h>
    1618
    1719
    1820/*! \brief Constructor.
    KPPPConfigurePacket::KPPPConfigurePacket(uint8 code)  
    2729
    2830
    2931//! Decodes a packet and adds its items to this object.
    30 KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet)
     32KPPPConfigurePacket::KPPPConfigurePacket(net_buffer *packet)
    3133{
    3234    // 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();
    3439   
    35     SetID(header->id);
    36     if (!SetCode(header->code))
     40    SetID(header.id);
     41    if (!SetCode(header.code))
    3742        return;
    3843   
    39     uint16 length = ntohs(header->length);
     44    uint16 length = ntohs(header.length);
    4045   
    41     if (length < 6 || length > packet->m_len)
     46    if (length < 6 || length > packet->size)
    4247        return;
    4348            // there are no items (or one corrupted item)
    4449   
    KPPPConfigurePacket::KPPPConfigurePacket(struct mbuf *packet)  
    4651    ppp_configure_item *item;
    4752   
    4853    while (position < length - 4) {
    49         item = (ppp_configure_item*) (header->data + position);
     54        item = (ppp_configure_item*) (header.data + position);
    5055        if (item->length < 2)
    5156            return;
    5257                // found a corrupted item
    KPPPConfigurePacket::ItemWithType(uint8 type) const  
    157162}
    158163
    159164
    160 /*! \brief Converts this packet into an mbuf structure.
     165/*! \brief Converts this packet into an net_buffer structure.
    161166   
    162167    ATTENTION: You are responsible for freeing this packet by calling \c m_freem()!
    163168   
    164169    \param MRU The interface's maximum receive unit (MRU).
    165170    \param reserve Number of bytes to reserve at the beginning of the packet.
    166171   
    167     \return The mbuf structure 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).
    168173*/
    169 struct mbuf*
     174net_buffer*
    170175KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve)
    171176{
    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
    177191    header->code = Code();
    178192    header->id = ID();
    179193   
    KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve)  
    185199       
    186200        // make sure we have enough space left
    187201        if (MRU - length < item->length) {
    188             m_freem(packet);
     202            gBufferModule->free(buffer);
    189203            return NULL;
    190204        }
    191205       
    KPPPConfigurePacket::ToMbuf(uint32 MRU, uint32 reserve)  
    195209   
    196210    length += 4;
    197211    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;
    201221}
  • 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  
    1414#include <KPPPDevice.h>
    1515
    1616#include <net/if.h>
    17 #include <core_funcs.h>
    1817
    1918#include <PPPControl.h>
    2019
    KPPPDevice::IsAllowedToSend() const  
    8988
    9089//! This method is never used.
    9190status_t
    92 KPPPDevice::Receive(struct mbuf *packet, uint16 protocolNumber)
     91KPPPDevice::Receive(net_buffer *packet, uint16 protocolNumber)
    9392{
    9493    // let the interface handle the packet
    9594    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  
    2323// void (KernelExport.h) and once with int (stdio.h).
    2424#include <cstdio>
    2525#include <cstring>
    26 #include <core_funcs.h>
     26#include <net_buffer.h>
    2727
     28#include <ppp_device.h>
     29#include <net_stack.h>
     30#include <ByteOrder.h>
    2831// now our headers...
    2932#include <KPPPInterface.h>
    3033
     
    3841#include <KPPPUtils.h>
    3942
    4043// general helper classes not only belonging to us
    41 #include <LockerHelper.h>
     44// #include <lock.h>
     45// #include <util/AutoLock.h>
    4246
    4347// tools only for us :)
    4448#include "settings_tools.h"
    typedef struct reconnect_info {  
    6266    uint32 delay;
    6367} reconnect_info;
    6468
     69// module related to net_buffer objects
     70extern net_buffer_module_info *gBufferModule;
     71extern net_stack_module_info *gStackModule;
     72
    6573status_t reconnect_thread(void *data);
    6674
    6775// other functions
    KPPPInterface::~KPPPInterface()  
    250258    // This lock is not released until we are actually deleted.
    251259    while (true) {
    252260        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        }
    257266    }
    258267   
    259268    Report(PPP_DESTRUCTION_REPORT, 0, &fID, sizeof(ppp_interface_id));
    KPPPInterface::~KPPPInterface()  
    296305void
    297306KPPPInterface::Delete()
    298307{
    299     LockerHelper locker(fLock);
     308    // MutexLocker locker(fLock);
     309        // alreay locked in KPPPStatemachine::DownEvent
     310        // uncomment this line will cause double lock
    300311   
    301312    if (fDeleteCounter > 0)
    302313        return;
    KPPPInterface::SetMRU(uint32 MRU)  
    364375    if (Device() && MRU > Device()->MTU() - 2)
    365376        return false;
    366377   
    367     LockerHelper locker(fLock);
     378    // MutexLocker locker(fLock);
     379        //uncomment this line will cause double lock
     380        //alreay locked in ::Up and ::KPPPInterface
    368381   
    369382    fMRU = MRU;
    370383   
    KPPPInterface::Control(uint32 op, void *data, size_t length)  
    417430            if (Name())
    418431                strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
    419432            if (Ifnet())
    420                 info->if_unit = Ifnet()->if_unit;
     433                info->if_unit = Ifnet()->index;
    421434            else
    422435                info->if_unit = -1;
    423436            info->mode = Mode();
    KPPPInterface::Control(uint32 op, void *data, size_t length)  
    456469            if (!data)
    457470                return B_ERROR;
    458471
    459             LockerHelper locker(fLock);
     472            MutexLocker locker(fLock);
    460473            // login information can only be changed before we authenticate
    461474            if (Phase() >= PPP_AUTHENTICATION_PHASE)
    462475                return B_NOT_ALLOWED;
    KPPPInterface::Control(uint32 op, void *data, size_t length)  
    471484            if (!data)
    472485                return B_ERROR;
    473486           
    474             LockerHelper locker(fLock);
     487            MutexLocker locker(fLock);
    475488            // login information can only be changed before we authenticate
    476489            if (Phase() >= PPP_AUTHENTICATION_PHASE)
    477490                return B_NOT_ALLOWED;
    KPPPInterface::Control(uint32 op, void *data, size_t length)  
    524537            if (length < sizeof(ppp_report_request) || !data)
    525538                return B_ERROR;
    526539
    527             LockerHelper locker(fLock);
     540            MutexLocker locker(fLock);
    528541            ppp_report_request *request = (ppp_report_request*) data;
    529542            // first, we send an initial state report
    530543            if (request->type == PPP_CONNECTION_REPORT) {
    KPPPInterface::SetDevice(KPPPDevice *device)  
    656669        return false;
    657670            // main interfaces do not have devices
    658671   
    659     LockerHelper locker(fLock);
     672    MutexLocker locker(fLock);
    660673   
    661674    if (Phase() != PPP_DOWN_PHASE)
    662675        return false;
    KPPPInterface::AddProtocol(KPPPProtocol *protocol)  
    704717            || protocol->Level() == PPP_INTERFACE_LEVEL)
    705718        return false;
    706719   
    707     LockerHelper locker(fLock);
     720    MutexLocker locker(fLock);
    708721   
    709722    if (Phase() != PPP_DOWN_PHASE)
    710723        return false;
    KPPPInterface::RemoveProtocol(KPPPProtocol *protocol)  
    768781    TRACE("KPPPInterface: RemoveProtocol(%X)\n",
    769782        protocol ? protocol->ProtocolNumber() : 0);
    770783   
    771     LockerHelper locker(fLock);
     784    MutexLocker locker(fLock);
    772785   
    773786    if (Phase() != PPP_DOWN_PHASE)
    774787        return false;
    KPPPInterface::RemoveProtocol(KPPPProtocol *protocol)  
    809822int32
    810823KPPPInterface::CountProtocols() const
    811824{
    812     LockerHelper locker(fLock);
     825    MutexLocker locker(fLock);
    813826   
    814827    KPPPProtocol *protocol = FirstProtocol();
    815828   
    KPPPInterface::CountProtocols() const  
    825838KPPPProtocol*
    826839KPPPInterface::ProtocolAt(int32 index) const
    827840{
    828     LockerHelper locker(fLock);
     841    MutexLocker locker(fLock);
    829842   
    830843    KPPPProtocol *protocol = FirstProtocol();
    831844   
    KPPPInterface::ProtocolFor(uint16 protocolNumber, KPPPProtocol *start) const  
    849862{
    850863    TRACE("KPPPInterface: ProtocolFor(%X)\n", protocolNumber);
    851864   
    852     LockerHelper locker(fLock);
     865    // MutexLocker locker(fLock);
     866        // already locked in ::Receive,uncomment this line will cause double lock
    853867   
    854868    KPPPProtocol *current = start ? start : FirstProtocol();
    855869   
    KPPPInterface::AddChild(KPPPInterface *child)  
    874888    if (!child)
    875889        return false;
    876890   
    877     LockerHelper locker(fLock);
     891    MutexLocker locker(fLock);
    878892   
    879893    if (fChildren.HasItem(child) || !fChildren.AddItem(child))
    880894        return false;
    KPPPInterface::RemoveChild(KPPPInterface *child)  
    891905{
    892906    TRACE("KPPPInterface: RemoveChild(%lX)\n", child ? child->ID() : 0);
    893907   
    894     LockerHelper locker(fLock);
     908    MutexLocker locker(fLock);
    895909   
    896910    if (!fChildren.RemoveItem(child))
    897911        return false;
    KPPPInterface::ChildAt(int32 index) const  
    912926{
    913927    TRACE("KPPPInterface: ChildAt(%ld)\n", index);
    914928   
    915     LockerHelper locker(fLock);
     929    MutexLocker locker(fLock);
    916930   
    917931    KPPPInterface *child = fChildren.ItemAt(index);
    918932   
    KPPPInterface::SetConnectOnDemand(bool connectOnDemand)  
    945959   
    946960    TRACE("KPPPInterface: SetConnectOnDemand(%s)\n", connectOnDemand ? "true" : "false");
    947961   
    948     LockerHelper locker(fLock);
     962    MutexLocker locker(fLock);
    949963   
    950964    // Only clients support ConnectOnDemand.
    951965    if (Mode() != PPP_CLIENT_MODE) {
    KPPPInterface::SetConnectOnDemand(bool connectOnDemand)  
    973987    // check if we need to set/unset flags
    974988    if (connectOnDemand) {
    975989        if (Ifnet())
    976             Ifnet()->if_flags |= IFF_UP;
     990            Ifnet()->flags |= IFF_UP;
    977991    } else if (!connectOnDemand && Phase() < PPP_ESTABLISHED_PHASE) {
    978992        if (Ifnet())
    979             Ifnet()->if_flags &= ~IFF_UP;
     993            Ifnet()->flags &= ~IFF_UP;
    980994    }
    981995}
    982996
    KPPPInterface::SetConnectOnDemand(bool connectOnDemand)  
    985999void
    9861000KPPPInterface::SetAskBeforeConnecting(bool ask)
    9871001{
    988     LockerHelper locker(fLock);
     1002    MutexLocker locker(fLock);
    9891003   
    9901004    bool old = fAskBeforeConnecting;
    9911005    fAskBeforeConnecting = ask;
    9921006   
    9931007    if (old && fAskBeforeConnecting == false && State() == PPP_STARTING_STATE
    9941008            && Phase() == PPP_DOWN_PHASE) {
    995         locker.UnlockNow();
     1009        // locker.Unlock();
    9961010        StateMachine().ContinueOpenEvent();
    9971011    }
    9981012}
    KPPPInterface::SetPFCOptions(uint8 pfcOptions)  
    10041018{
    10051019    TRACE("KPPPInterface: SetPFCOptions(0x%X)\n", pfcOptions);
    10061020   
    1007     LockerHelper locker(fLock);
     1021    MutexLocker locker(fLock);
    10081022   
    10091023    if (PFCOptions() & PPP_FREEZE_PFC_OPTIONS)
    10101024        return false;
    KPPPInterface::Up()  
    10321046    if (IsUp())
    10331047        return true;
    10341048   
    1035     LockerHelper locker(fLock);
     1049    MutexLocker locker(fLock);
    10361050    StateMachine().OpenEvent();
    10371051   
    10381052    return true;
    KPPPInterface::Down()  
    10591073    send_data_with_timeout(fReconnectThread, 0, NULL, 0, 200);
    10601074        // tell the reconnect thread to abort its attempt (if it's still waiting)
    10611075   
    1062     LockerHelper locker(fLock);
     1076    MutexLocker locker(fLock);
    10631077    StateMachine().CloseEvent();
    10641078   
    10651079    return true;
    KPPPInterface::WaitForConnection()  
    10741088   
    10751089    if (InitCheck() != B_OK)
    10761090        return false;
     1091
     1092    return true; // for temporary
    10771093   
    10781094    ReportManager().EnableReports(PPP_CONNECTION_REPORT, find_thread(NULL));
    10791095   
    KPPPInterface::WaitForConnection()  
    10971113    }
    10981114   
    10991115    ReportManager().DisableReports(PPP_CONNECTION_REPORT, find_thread(NULL));
     1116    dprintf("KPPPInterface: WaitForConnection():%s\n", successful?"True":"False");
    11001117    return successful;
    11011118}
    11021119
    KPPPInterface::IsAllowedToSend() const  
    12331250        - \c B_ERROR: Some error occured.
    12341251*/
    12351252status_t
    1236 KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)
     1253KPPPInterface::Send(net_buffer *packet, uint16 protocolNumber)
    12371254{
    12381255    TRACE("KPPPInterface: Send(0x%X)\n", protocolNumber);
    12391256   
    12401257    if (!packet)
    12411258        return B_ERROR;
    1242    
     1259
    12431260    // we must pass the basic tests like:
    12441261    // do we have a device?
    12451262    // did we load all modules?
    12461263    if (InitCheck() != B_OK) {
    1247         m_freem(packet);
     1264        ERROR("InitCheck() fail\n");
     1265        gBufferModule->free(packet);
    12481266        return B_ERROR;
    12491267    }
    1250    
     1268
     1269
    12511270    // go up if ConnectOnDemand is enabled and we are disconnected
    12521271    // TODO: our new netstack will simplify ConnectOnDemand handling, so
    12531272    // we do not have to handle it here
    KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)  
    12551274            && (Phase() == PPP_DOWN_PHASE
    12561275                || Phase() == PPP_ESTABLISHMENT_PHASE)
    12571276            && !Up()) || !WaitForConnection()) {
    1258         m_freem(packet);
     1277        gBufferModule->free(packet);
    12591278        return B_ERROR;
    12601279    }
    12611280   
    KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)  
    12791298#endif
    12801299   
    12811300    // 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()
    12831304            || !IsProtocolAllowed(*protocol)) {
    12841305        ERROR("KPPPInterface::Send(): cannot send!\n");
    1285         m_freem(packet);
     1306        gBufferModule->free(packet);
    12861307        return B_ERROR;
    12871308    }
    12881309   
    12891310    // 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();
    12951322       
    1296         uint8 *header = mtod(packet, uint8*);
    1297         *header = protocolNumber & 0xFF;
    12981323    } 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
    13041330        // 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();
    13081333    }
    1309    
     1334
    13101335    // pass to device if we're either not a multilink interface or a child interface
    13111336    if (!IsMultilink() || Parent()) {
    13121337        // 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;
    13151339       
    13161340        if (length > MRU()) {
    1317             m_freem(packet);
     1341            dprintf("packet too large!\n");
     1342            gBufferModule->free(packet);
    13181343            return B_ERROR;
    13191344        }
    13201345       
    13211346        atomic_add64(&fStatistics.bytesSent, length);
    13221347        atomic_add64(&fStatistics.packetsSent, 1);
     1348        TRACE("%s::%s SendToNext\n",__FILE__,__func__);
    13231349        return SendToNext(packet, 0);
    13241350            // this is normally the device, but there can be something inbetween
    13251351    } else {
    13261352        // 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);
    13281355        return B_ERROR;
    13291356    }
    13301357}
    KPPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)  
    13481375        - \c PPP_DISCARDED: The protocol handler(s) did not handle this packet.
    13491376*/
    13501377status_t
    1351 KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
     1378KPPPInterface::Receive(net_buffer *packet, uint16 protocolNumber)
    13521379{
    13531380    TRACE("KPPPInterface: Receive(0x%X)\n", protocolNumber);
    13541381   
    13551382    if (!packet)
    13561383        return B_ERROR;
    13571384   
    1358     LockerHelper locker(fLock);
     1385    MutexLocker locker(fLock);
    13591386   
    13601387    int32 result = PPP_REJECTED;
    13611388        // assume we have no handler
    13621389   
    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();
    13701408   
    13711409    // Find handler and let it parse the packet.
    13721410    // The handler does need not be up because if we are a server
    KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)  
    13961434        return Parent()->Receive(packet, protocolNumber);
    13971435   
    13981436    if (result == PPP_UNHANDLED) {
    1399         m_freem(packet);
     1437        gBufferModule->free(packet);
    14001438        return PPP_DISCARDED;
    14011439    } else {
    14021440        StateMachine().RUCEvent(packet, protocolNumber);
    KPPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)  
    14191457        - \c PPP_DISCARDED: The protocol handler(s) did not handle this packet.
    14201458*/
    14211459status_t
    1422 KPPPInterface::ReceiveFromDevice(struct mbuf *packet)
     1460KPPPInterface::ReceiveFromDevice(net_buffer *packet)
    14231461{
    14241462    TRACE("KPPPInterface: ReceiveFromDevice()\n");
    14251463   
    KPPPInterface::ReceiveFromDevice(struct mbuf *packet)  
    14271465        return B_ERROR;
    14281466   
    14291467    if (InitCheck() != B_OK) {
    1430         m_freem(packet);
     1468        gBufferModule->free(packet);
    14311469        return B_ERROR;
    14321470    }
    14331471   
    1434     uint32 length = packet->m_flags & M_PKTHDR ? (uint32) packet->m_pkthdr.len :
    1435         packet->m_len;
    1436    
     1472    uint32 length = packet->size;
    14371473    // 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);
    14411498    } else {
    1442         protocolNumber = ntohs(*mtod(packet, uint16*));
    1443         m_adj(packet, 2);
     1499        TRACE("%s::%s:Non-PFC protocol:%x\n",__FILE__,__func__, protocolNumber);
    14441500    }
    1445    
     1501
    14461502    atomic_add64(&fStatistics.bytesReceived, length);
    14471503    atomic_add64(&fStatistics.packetsReceived, 1);
    14481504    return Receive(packet, protocolNumber);
    KPPPInterface::ReceiveFromDevice(struct mbuf *packet)  
    14531509void
    14541510KPPPInterface::Pulse()
    14551511{
    1456     LockerHelper locker(fLock);
     1512    MutexLocker locker(fLock);
    14571513   
    14581514    if (Device())
    14591515        Device()->Pulse();
    KPPPInterface::RegisterInterface()  
    14851541        return true;
    14861542            // we are already registered
    14871543   
    1488     LockerHelper locker(fLock);
     1544    MutexLocker locker(fLock);
    14891545   
    14901546    // only MainInterfaces get an ifnet
    14911547    if (IsMultilink() && Parent() && Parent()->RegisterInterface())
    KPPPInterface::RegisterInterface()  
    14961552   
    14971553    fIfnet = fManager->RegisterInterface(ID());
    14981554   
    1499     if (!fIfnet)
     1555    if (!fIfnet){
     1556        dprintf("%s:%s: damn it no fIfnet device\n", __FILE__, __func__);
    15001557        return false;
     1558    }
    15011559   
    15021560    if (DoesConnectOnDemand())
    1503         fIfnet->if_flags |= IFF_UP;
     1561        fIfnet->flags |= IFF_UP;
    15041562   
    15051563    CalculateInterfaceMTU();
    15061564    CalculateBaudRate();
    KPPPInterface::UnregisterInterface()  
    15191577        return true;
    15201578            // we are already unregistered
    15211579   
    1522     LockerHelper locker(fLock);
     1580    MutexLocker locker(fLock);
    15231581   
    15241582    // only MainInterfaces get an ifnet
    15251583    if (IsMultilink() && Parent())
    KPPPInterface::StackControlEachHandler(uint32 op, void *data)  
    15871645   
    15881646    status_t result = B_BAD_VALUE, tmp;
    15891647   
    1590     LockerHelper locker(fLock);
     1648    MutexLocker locker(fLock);
    15911649   
    15921650    KPPPProtocol *protocol = FirstProtocol();
    15931651    for (; protocol; protocol = protocol->NextProtocol()) {
    KPPPInterface::CalculateInterfaceMTU()  
    16131671{
    16141672    TRACE("KPPPInterface: CalculateInterfaceMTU()\n");
    16151673   
    1616     LockerHelper locker(fLock);
     1674    // MutexLocker locker(fLock);
     1675        //uncomment this line will cause double lock
     1676        //alreay locked in ::KPPPInterface
    16171677   
    16181678    fInterfaceMTU = fMRU;
    16191679    fHeaderLength = 2;
    KPPPInterface::CalculateInterfaceMTU()  
    16281688    fInterfaceMTU -= fHeaderLength;
    16291689   
    16301690    if (Ifnet()) {
    1631         Ifnet()->if_mtu = fInterfaceMTU;
    1632         Ifnet()->if_hdrlen = fHeaderLength;
     1691        Ifnet()->mtu = fInterfaceMTU;
     1692        Ifnet()->header_length = fHeaderLength;
     1693        return;
    16331694    }
    16341695   
    16351696    if (Parent())
    KPPPInterface::CalculateBaudRate()  
    16431704{
    16441705    TRACE("KPPPInterface: CalculateBaudRate()\n");
    16451706   
    1646     LockerHelper locker(fLock);
     1707    // MutexLocker locker(fLock); //uncomment this will cause double lock
    16471708   
    16481709    if (!Ifnet())
    16491710        return;
    16501711   
    16511712    if (Device())
    1652         fIfnet->if_baudrate = max_c(Device()->InputTransferRate(),
    1653             Device()->OutputTransferRate());
     1713        fIfnet->link_speed = max_c(Device()->InputTransferRate(),
     1714        Device()->OutputTransferRate());
    16541715    else {
    1655         fIfnet->if_baudrate = 0;
     1716        fIfnet->link_speed = 0;
    16561717        for (int32 index = 0; index < CountChildren(); index++)
    16571718            if (ChildAt(index)->Ifnet())
    1658                 fIfnet->if_baudrate += ChildAt(index)->Ifnet()->if_baudrate;
     1719                fIfnet->link_speed += ChildAt(index)->Ifnet()->link_speed;
     1720                return;
    16591721    }
    16601722}
    16611723
    KPPPInterface::Reconnect(uint32 delay)  
    16661728{
    16671729    TRACE("KPPPInterface: Reconnect(%ld)\n", delay);
    16681730   
    1669     LockerHelper locker(fLock);
     1731    MutexLocker locker(fLock);
    16701732   
    16711733    if (fReconnectThread != -1)
    16721734        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  
    2020#include <KPPPOptionHandler.h>
    2121
    2222#include <netinet/in.h>
    23 #include <core_funcs.h>
     23
     24#include <net_buffer.h>
    2425#include <sys/socket.h>
    2526
     27extern net_buffer_module_info *gBufferModule;
     28
    2629
    2730//! Creates a new LCP protocol for the given interface.
    2831KPPPLCP::KPPPLCP(KPPPInterface& interface)
    KPPPLCP::Down()  
    230233
    231234//! Sends a packet to the target (if there is one) or to the interface.
    232235status_t
    233 KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber)
     236KPPPLCP::Send(net_buffer *packet, uint16 protocolNumber)
    234237{
    235238    if (Target())
    236239        return Target()->Send(packet, PPP_LCP_PROTOCOL);
    KPPPLCP::Send(struct mbuf *packet, uint16 protocolNumber)  
    241244
    242245//! Decodes the LCP packet and passes it to the KPPPStateMachine or an LCP extension.
    243246status_t
    244 KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
     247KPPPLCP::Receive(net_buffer *packet, uint16 protocolNumber)
    245248{
    246249    if (!packet)
    247250        return B_ERROR;
    KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)  
    250253        ERROR("KPPPLCP::Receive(): wrong protocol number!\n");
    251254        return PPP_UNHANDLED;
    252255    }
    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();
    255262   
    256263    // 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     }
    270264   
    271     if (ntohs(data->length) < 4)
     265    net_buffer *copy=gBufferModule->duplicate(packet);
     266   
     267    if (ntohs(data.length) < 4)
    272268        return B_ERROR;
    273269
    274270    bool handled = true;
    275271
    276     switch (data->code) {
     272    switch (data.code) {
    277273        case PPP_CONFIGURE_REQUEST:
    278274            StateMachine().RCREvent(packet);
    279275            break;
    KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)  
    310306            break;
    311307
    312308        default:
    313             m_freem(packet);
     309            // gBufferModule->free(packet);
    314310            handled = false;
    315311    }
    316312   
    KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)  
    324320    // Try to find LCP extensions that can handle this code.
    325321    // We must duplicate the packet in order to ask all handlers.
    326322    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))) {
    329325        if (!lcpExtension->IsEnabled())
    330326            continue;
    331327       
    332         result = lcpExtension->Receive(packet, data->code);
     328        result = lcpExtension->Receive(packet, data.code);
    333329       
    334330        // check return value and return it on error
    335331        if (result == B_OK)
    336332            handled = true;
    337333        else if (result != PPP_UNHANDLED) {
    338             m_freem(packet);
     334            gBufferModule->free(packet);
    339335            return result;
    340336        }
    341337    }
    KPPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)  
    345341        return PPP_REJECTED;
    346342    }
    347343   
    348     m_freem(packet);
     344    gBufferModule->free(packet);
    349345   
    350346    return result;
    351347}
  • 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  
    1919
    2020#include <KPPPLayer.h>
    2121
     22#include <net_buffer.h>
     23
    2224#include <cstdlib>
    2325#include <cstring>
    24 #include <core_funcs.h>
    2526
     27extern net_buffer_module_info *gBufferModule;
    2628
    2729/*! \brief Creates a new layer.
    2830   
    KPPPLayer::InitCheck() const  
    5658
    5759//! Sends a packet to the next layer in the chain.
    5860status_t
    59 KPPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const
     61KPPPLayer::SendToNext(net_buffer *packet, uint16 protocolNumber) const
    6062{
    6163    if (!packet)
    6264        return B_ERROR;
    KPPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const  
    7072            return Next()->SendToNext(packet, protocolNumber);
    7173    } else {
    7274        ERROR("KPPPLayer: SendToNext() failed because there is no next handler!\n");
    73         m_freem(packet);
     75        gBufferModule->free(packet);
    7476        return B_ERROR;
    7577    }
    7678}
  • 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  
    99
    1010#include <KPPPReportManager.h>
    1111
    12 #include <LockerHelper.h>
     12#include <lock.h>
     13#include <util/AutoLock.h>
     14
    1315#include <KPPPUtils.h>
    1416
    1517
    report_sender_thread(void *data)  
    3335   
    3436    \param lock The BLocker that should be used by this report manager.
    3537*/
    36 KPPPReportManager::KPPPReportManager(BLocker& lock)
     38KPPPReportManager::KPPPReportManager(mutex& lock)
    3739    : fLock(lock)
    3840{
    3941}
    KPPPReportManager::EnableReports(ppp_report_type type, thread_id thread,  
    8890    if (thread < 0 || type == PPP_ALL_REPORTS)
    8991        return;
    9092   
    91     LockerHelper locker(fLock);
     93    MutexLocker locker(fLock);
    9294   
    9395    ppp_report_request *request = new ppp_report_request;
    9496    request->type = type;
    KPPPReportManager::DisableReports(ppp_report_type type, thread_id thread)  
    106108    if (thread < 0)
    107109        return;
    108110   
    109     LockerHelper locker(fLock);
     111     MutexLocker locker(fLock);
    110112   
    111113    ppp_report_request *request;
    112114   
    KPPPReportManager::DoesReport(ppp_report_type type, thread_id thread)  
    135137    if (thread < 0)
    136138        return false;
    137139   
    138     LockerHelper locker(fLock);
     140    MutexLocker locker(fLock);
    139141   
    140142    ppp_report_request *request;
    141143   
    KPPPReportManager::Report(ppp_report_type type, int32 code, void *data, int32 le  
    177179    if (!data)
    178180        length = 0;
    179181   
    180     LockerHelper locker(fLock);
     182    MutexLocker locker(fLock);
    181183   
    182184    status_t result;
    183185    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  
    2222#include <KPPPUtils.h>
    2323
    2424#include <net/if.h>
    25 #include <core_funcs.h>
    2625
     26#include <net_buffer.h>
     27#include <ByteOrder.h>
     28#include <NetBufferUtilities.h>
     29
     30extern net_buffer_module_info *gBufferModule;
    2731
    2832static const bigtime_t kPPPStateMachineTimeout = 3000000;
    2933    // 3 seconds
    KPPPStateMachine::KPPPStateMachine(KPPPInterface& interface)  
    4852    fRequestID(0),
    4953    fTerminateID(0),
    5054    fEchoID(0),
    51     fNextTimeout(0),
    52     fLock("KPPPStateMachine")
     55    fNextTimeout(0)//,
     56    //fLock("KPPPStateMachine")
    5357{
     58    mutex_init(&fLock,"KPPPStateMachine");
    5459}
    5560
    5661
    KPPPStateMachine::NewPhase(ppp_phase next)  
    114119    // The report threads get their notification later.
    115120    if (Phase() == PPP_ESTABLISHED_PHASE && next != Phase()) {
    116121        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;
    119124        }
    120125       
    121126        if (Interface().Parent())
    KPPPStateMachine::NewPhase(ppp_phase next)  
    128133        Interface().fConnectedSince = system_time();
    129134       
    130135        if (Interface().Ifnet())
    131             Interface().Ifnet()->if_flags |= IFF_UP | IFF_RUNNING;
     136            Interface().Ifnet()->flags |= IFF_UP;// | IFF_RUNNING;
    132137       
    133138        Interface().fConnectAttempt = 0;
    134139            // when we Reconnect() this becomes 1 (the first connection attempt)
    KPPPStateMachine::SendEchoRequest()  
    172177    if (State() != PPP_OPENED_STATE)
    173178        return false;
    174179   
    175     struct mbuf *packet = m_gethdr(MT_DATA);
    176     if (!packet)
     180        net_buffer *packet = gBufferModule->create(256);
     181        if (packet == NULL)
    177182        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