Updated according to name changes in kernel classes.

IPCP and PAP (hopefully) make use of profiles.
Minor changes.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6284 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald 2004-01-25 12:57:01 +00:00
parent 683165b7d1
commit 1cea3d8564
14 changed files with 93 additions and 85 deletions

View File

@ -8,6 +8,7 @@
#include "Protocol.h"
#include <KPPPConfigurePacket.h>
#include <KPPPInterface.h>
#include <settings_tools.h>
#include <LockerHelper.h>
@ -21,8 +22,8 @@
// 3 seconds
IPCP::IPCP(PPPInterface& interface, driver_parameter *settings)
: PPPProtocol("IPCP", PPP_NCP_PHASE, IPCP_PROTOCOL, PPP_PROTOCOL_LEVEL,
IPCP::IPCP(KPPPInterface& interface, driver_parameter *settings)
: KPPPProtocol("IPCP", PPP_NCP_PHASE, IPCP_PROTOCOL, PPP_PROTOCOL_LEVEL,
AF_INET, 0, interface, settings, PPP_INCLUDES_NCP),
fDefaultRoute(NULL),
fRequestPrimaryDNS(false),
@ -46,12 +47,10 @@ IPCP::IPCP(PPPInterface& interface, driver_parameter *settings)
// Parse settings:
// "Local" and "Peer" describe each side's settings
for(int32 index = 0; index < settings->parameter_count; index++) {
if(!strcasecmp(settings->parameters[index].name, "Local"))
ParseSideRequests(&settings->parameters[index], PPP_LOCAL_SIDE);
else if(!strcasecmp(settings->parameters[index].name, "Peer"))
ParseSideRequests(&settings->parameters[index], PPP_PEER_SIDE);
}
const driver_parameter *profile
= Interface().Profile().SettingsFor("protocol", "ipcp");
ParseSideRequests(get_parameter_with_name("Local", profile), PPP_LOCAL_SIDE);
ParseSideRequests(get_parameter_with_name("Peer", profile), PPP_PEER_SIDE);
}
@ -86,7 +85,7 @@ IPCP::StackControl(uint32 op, void *data)
default:
dprintf("IPCP: Unknown ioctl: %ld\n", op);
return PPPProtocol::StackControl(op, data);
return KPPPProtocol::StackControl(op, data);
}
return B_OK;
@ -306,8 +305,11 @@ IPCP::Pulse()
bool
IPCP::ParseSideRequests(driver_parameter *requests, ppp_side side)
IPCP::ParseSideRequests(const driver_parameter *requests, ppp_side side)
{
if(!requests)
return false;
ipcp_requests *selectedRequests;
if(side == PPP_LOCAL_SIDE) {
@ -419,12 +421,14 @@ IPCP::UpdateAddresses()
dprintf("IPCP: UpdateAddress(): SIOCSIFNETMASK returned error!\n");
// add default/subnet route
if(rtrequest(RTM_ADD, (struct sockaddr*) &inreq.ifra_mask,
(struct sockaddr*) &fGateway, (struct sockaddr*) &inreq.ifra_mask,
RTF_UP | RTF_GATEWAY, &fDefaultRoute) != B_OK)
dprintf("IPCP: UpdateAddress(): could not add default/subnet route!\n");
--fDefaultRoute->rt_refcnt;
if(Side() == PPP_LOCAL_SIDE) {
if(rtrequest(RTM_ADD, (struct sockaddr*) &inreq.ifra_mask,
(struct sockaddr*) &fGateway, (struct sockaddr*) &inreq.ifra_mask,
RTF_UP | RTF_GATEWAY, &fDefaultRoute) != B_OK)
dprintf("IPCP: UpdateAddress(): could not add default/subnet route!\n");
--fDefaultRoute->rt_refcnt;
}
}
@ -546,9 +550,9 @@ IPCP::RCREvent(struct mbuf *packet)
dprintf("IPCP: RCREvent() state=%d\n", State());
#endif
PPPConfigurePacket request(packet);
PPPConfigurePacket nak(PPP_CONFIGURE_NAK);
PPPConfigurePacket reject(PPP_CONFIGURE_REJECT);
KPPPConfigurePacket request(packet);
KPPPConfigurePacket nak(PPP_CONFIGURE_NAK);
KPPPConfigurePacket reject(PPP_CONFIGURE_REJECT);
// we should not use the same id as the peer
if(fID == mtod(packet, ppp_lcp_packet*)->id)
@ -753,7 +757,7 @@ IPCP::RCAEvent(struct mbuf *packet)
}
// parse this ack
PPPConfigurePacket ack(packet);
KPPPConfigurePacket ack(packet);
ppp_configure_item *item;
in_addr_t *requestedAddress, *wishedAddress = NULL, *configuredAddress = NULL;
for(int32 index = 0; index < ack.CountItems(); index++) {
@ -863,7 +867,7 @@ IPCP::RCNEvent(struct mbuf *packet)
}
// parse this nak/reject
PPPConfigurePacket nak_reject(packet);
KPPPConfigurePacket nak_reject(packet);
ppp_configure_item *item;
in_addr_t *requestedAddress;
if(nak_reject.Code() == PPP_CONFIGURE_NAK)
@ -1182,7 +1186,7 @@ IPCP::SendConfigureRequest()
fNextTimeout = system_time() + PPP_STATE_MACHINE_TIMEOUT;
locker.UnlockNow();
PPPConfigurePacket request(PPP_CONFIGURE_REQUEST);
KPPPConfigurePacket request(PPP_CONFIGURE_REQUEST);
request.SetID(NextID());
fRequestID = request.ID();
ip_item ipItem;
@ -1236,7 +1240,7 @@ IPCP::SendConfigureAck(struct mbuf *packet)
return false;
mtod(packet, ppp_lcp_packet*)->code = PPP_CONFIGURE_ACK;
PPPConfigurePacket ack(packet);
KPPPConfigurePacket ack(packet);
// verify items
ppp_configure_item *item;

View File

@ -58,9 +58,9 @@ extern struct protosw *gProto[];
// defined in ipcp.cpp
class IPCP : public PPPProtocol {
class IPCP : public KPPPProtocol {
public:
IPCP(PPPInterface& interface, driver_parameter *settings);
IPCP(KPPPInterface& interface, driver_parameter *settings);
virtual ~IPCP();
ppp_state State() const
@ -78,7 +78,7 @@ class IPCP : public PPPProtocol {
virtual void Pulse();
private:
bool ParseSideRequests(driver_parameter *requests, ppp_side side);
bool ParseSideRequests(const driver_parameter *requests, ppp_side side);
void UpdateAddresses();
void RemoveRoutes();

View File

@ -38,7 +38,7 @@ isascii(char c)
static
bool
add_to(PPPInterface& mainInterface, PPPInterface *subInterface,
add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface,
driver_parameter *settings, ppp_module_key_type type)
{
if(type != PPP_PROTOCOL_KEY_TYPE)

View File

@ -13,8 +13,8 @@
#define ACFC_TYPE 0x8
ACFCHandler::ACFCHandler(uint32 options, PPPInterface& interface)
: PPPOptionHandler("ACFC Handler", ACFC_TYPE, interface, NULL),
ACFCHandler::ACFCHandler(uint32 options, KPPPInterface& interface)
: KPPPOptionHandler("ACFC Handler", ACFC_TYPE, interface, NULL),
fOptions(options),
fLocalState(ACFC_DISABLED),
fPeerState(ACFC_DISABLED)
@ -23,7 +23,7 @@ ACFCHandler::ACFCHandler(uint32 options, PPPInterface& interface)
status_t
ACFCHandler::AddToRequest(PPPConfigurePacket& request)
ACFCHandler::AddToRequest(KPPPConfigurePacket& request)
{
// is ACFC not requested or was it rejected?
if(fLocalState == ACFC_REJECTED
@ -39,7 +39,7 @@ ACFCHandler::AddToRequest(PPPConfigurePacket& request)
status_t
ACFCHandler::ParseNak(const PPPConfigurePacket& nak)
ACFCHandler::ParseNak(const KPPPConfigurePacket& nak)
{
// naks do not contain ACFC items
if(nak.ItemWithType(ACFC_TYPE))
@ -50,7 +50,7 @@ ACFCHandler::ParseNak(const PPPConfigurePacket& nak)
status_t
ACFCHandler::ParseReject(const PPPConfigurePacket& reject)
ACFCHandler::ParseReject(const KPPPConfigurePacket& reject)
{
if(reject.ItemWithType(ACFC_TYPE)) {
fLocalState = ACFC_REJECTED;
@ -64,7 +64,7 @@ ACFCHandler::ParseReject(const PPPConfigurePacket& reject)
status_t
ACFCHandler::ParseAck(const PPPConfigurePacket& ack)
ACFCHandler::ParseAck(const KPPPConfigurePacket& ack)
{
if(ack.ItemWithType(ACFC_TYPE))
fLocalState = ACFC_ACCEPTED;
@ -80,8 +80,8 @@ ACFCHandler::ParseAck(const PPPConfigurePacket& ack)
status_t
ACFCHandler::ParseRequest(const PPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject)
ACFCHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{
if(!request.ItemWithType(ACFC_TYPE))
return B_OK;
@ -98,7 +98,7 @@ ACFCHandler::ParseRequest(const PPPConfigurePacket& request,
status_t
ACFCHandler::SendingAck(const PPPConfigurePacket& ack)
ACFCHandler::SendingAck(const KPPPConfigurePacket& ack)
{
ppp_configure_item *item = ack.ItemWithType(ACFC_TYPE);

View File

@ -29,9 +29,9 @@ enum acfc_state {
};
class ACFCHandler : public PPPOptionHandler {
class ACFCHandler : public KPPPOptionHandler {
public:
ACFCHandler(uint32 options, PPPInterface& interface);
ACFCHandler(uint32 options, KPPPInterface& interface);
uint32 Options() const
{ return fOptions; }
@ -40,14 +40,14 @@ class ACFCHandler : public PPPOptionHandler {
acfc_state PeerState() const
{ return fPeerState; }
virtual status_t AddToRequest(PPPConfigurePacket& request);
virtual status_t ParseNak(const PPPConfigurePacket& nak);
virtual status_t ParseReject(const PPPConfigurePacket& reject);
virtual status_t ParseAck(const PPPConfigurePacket& ack);
virtual status_t AddToRequest(KPPPConfigurePacket& request);
virtual status_t ParseNak(const KPPPConfigurePacket& nak);
virtual status_t ParseReject(const KPPPConfigurePacket& reject);
virtual status_t ParseAck(const KPPPConfigurePacket& ack);
virtual status_t ParseRequest(const PPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject);
virtual status_t SendingAck(const PPPConfigurePacket& ack);
virtual status_t ParseRequest(const KPPPConfigurePacket& request,
int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject);
virtual status_t SendingAck(const KPPPConfigurePacket& ack);
virtual void Reset();

View File

@ -179,8 +179,8 @@ worker_thread(void *data)
}
ModemDevice::ModemDevice(PPPInterface& interface, driver_parameter *settings)
: PPPDevice("PPPoE", 0, interface, settings),
ModemDevice::ModemDevice(KPPPInterface& interface, driver_parameter *settings)
: KPPPDevice("Modem", 0, interface, settings),
fInterfaceName(NULL),
fHandle(-1),
fWorkerThread(-1),
@ -229,7 +229,7 @@ ModemDevice::InitCheck() const
if(fState != INITIAL && Handle() == -1)
return B_ERROR;
return InterfaceName() && PPPDevice::InitCheck() == B_OK ? B_OK : B_ERROR;
return InterfaceName() && KPPPDevice::InitCheck() == B_OK ? B_OK : B_ERROR;
}
@ -486,7 +486,7 @@ ModemDevice::Send(struct mbuf *packet, uint16 protocolNumber = 0)
status_t
ModemDevice::DataReceived(uint8 *buffer, uint32 length)
{
// TODO: report corrupted packets to PPPInterface
// TODO: report corrupted packets to KPPPInterface
if(length < 3)
return B_ERROR;

View File

@ -25,9 +25,9 @@ enum modem_state {
class ACFCHandler;
class ModemDevice : public PPPDevice {
class ModemDevice : public KPPPDevice {
public:
ModemDevice(PPPInterface& interface, driver_parameter *settings);
ModemDevice(KPPPInterface& interface, driver_parameter *settings);
virtual ~ModemDevice();
const char *InterfaceName() const

View File

@ -25,7 +25,7 @@ status_t std_ops(int32 op, ...);
static
bool
add_to(PPPInterface& mainInterface, PPPInterface *subInterface,
add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface,
driver_parameter *settings, ppp_module_key_type type)
{
if(mainInterface.Mode() != PPP_CLIENT_MODE || type != PPP_DEVICE_KEY_TYPE)

View File

@ -32,15 +32,15 @@ typedef struct authentication_item {
} authentication_item;
PAPHandler::PAPHandler(PAP& owner, PPPInterface& interface)
: PPPOptionHandler("PAP", AUTHENTICATION_TYPE, interface, NULL),
PAPHandler::PAPHandler(PAP& owner, KPPPInterface& interface)
: KPPPOptionHandler("PAP", AUTHENTICATION_TYPE, interface, NULL),
fOwner(owner)
{
}
status_t
PAPHandler::AddToRequest(PPPConfigurePacket& request)
PAPHandler::AddToRequest(KPPPConfigurePacket& request)
{
// only local authenticators send requests to peer
if(Owner().Side() != PPP_PEER_SIDE)
@ -58,29 +58,29 @@ PAPHandler::AddToRequest(PPPConfigurePacket& request)
status_t
PAPHandler::ParseNak(const PPPConfigurePacket& nak)
PAPHandler::ParseNak(const KPPPConfigurePacket& nak)
{
return B_OK;
}
status_t
PAPHandler::ParseReject(const PPPConfigurePacket& reject)
PAPHandler::ParseReject(const KPPPConfigurePacket& reject)
{
return B_OK;
}
status_t
PAPHandler::ParseAck(const PPPConfigurePacket& ack)
PAPHandler::ParseAck(const KPPPConfigurePacket& ack)
{
return B_OK;
}
status_t
PAPHandler::ParseRequest(const PPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject)
PAPHandler::ParseRequest(const KPPPConfigurePacket& request,
int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject)
{
// only local authenticators handle requests from peer
if(Owner().Side() != PPP_LOCAL_SIDE)
@ -97,7 +97,7 @@ PAPHandler::ParseRequest(const PPPConfigurePacket& request,
status_t
PAPHandler::SendingAck(const PPPConfigurePacket& ack)
PAPHandler::SendingAck(const KPPPConfigurePacket& ack)
{
return B_OK;
}
@ -110,8 +110,8 @@ PAPHandler::Reset()
// PAP
PAP::PAP(PPPInterface& interface, driver_parameter *settings)
: PPPProtocol("PAP", PPP_AUTHENTICATION_PHASE, PAP_PROTOCOL, PPP_PROTOCOL_LEVEL,
PAP::PAP(KPPPInterface& interface, driver_parameter *settings)
: KPPPProtocol("PAP", PPP_AUTHENTICATION_PHASE, PAP_PROTOCOL, PPP_PROTOCOL_LEVEL,
AF_INET, 0, interface, settings, PPP_ALWAYS_ALLOWED,
AUTHENTICATOR_TYPE_STRING, new PAPHandler(*this, interface)),
fState(INITIAL),
@ -122,7 +122,7 @@ PAP::PAP(PPPInterface& interface, driver_parameter *settings)
{
fUser[0] = fPassword[0] = 0;
ParseSettings(settings);
ParseSettings(Interface().Profile().SettingsFor("authenticator", "pap"));
}
@ -137,7 +137,7 @@ PAP::InitCheck() const
if(Side() != PPP_LOCAL_SIDE && Side() != PPP_PEER_SIDE)
return B_ERROR;
return PPPProtocol::InitCheck();
return KPPPProtocol::InitCheck();
}
@ -298,11 +298,14 @@ PAP::Pulse()
bool
PAP::ParseSettings(driver_parameter *requests)
PAP::ParseSettings(const driver_parameter *requests)
{
memset(fUser, 0, sizeof(fUser));
memset(fPassword, 0, sizeof(fPassword));
if(!requests)
return false;
// The following values are allowed:
// "User"
// "Password"

View File

@ -29,21 +29,22 @@ enum pap_state {
class PAP;
class PAPHandler : public PPPOptionHandler {
class PAPHandler : public KPPPOptionHandler {
public:
PAPHandler(PAP& owner, PPPInterface& interface);
PAPHandler(PAP& owner, KPPPInterface& interface);
PAP& Owner() const
{ return fOwner; }
virtual status_t AddToRequest(PPPConfigurePacket& request);
virtual status_t ParseNak(const PPPConfigurePacket& nak);
virtual status_t ParseReject(const PPPConfigurePacket& reject);
virtual status_t ParseAck(const PPPConfigurePacket& ack);
virtual status_t AddToRequest(KPPPConfigurePacket& request);
virtual status_t ParseNak(const KPPPConfigurePacket& nak);
virtual status_t ParseReject(const KPPPConfigurePacket& reject);
virtual status_t ParseAck(const KPPPConfigurePacket& ack);
virtual status_t ParseRequest(const PPPConfigurePacket& request,
int32 index, PPPConfigurePacket& nak, PPPConfigurePacket& reject);
virtual status_t SendingAck(const PPPConfigurePacket& ack);
virtual status_t ParseRequest(const KPPPConfigurePacket& request,
int32 index, KPPPConfigurePacket& nak, KPPPConfigurePacket& reject);
virtual status_t SendingAck(const KPPPConfigurePacket& ack);
virtual void Reset();
@ -52,9 +53,9 @@ class PAPHandler : public PPPOptionHandler {
};
class PAP : public PPPProtocol {
class PAP : public KPPPProtocol {
public:
PAP(PPPInterface& interface, driver_parameter *settings);
PAP(KPPPInterface& interface, driver_parameter *settings);
virtual ~PAP();
virtual status_t InitCheck() const;
@ -70,7 +71,7 @@ class PAP : public PPPProtocol {
virtual void Pulse();
private:
bool ParseSettings(driver_parameter *settings);
bool ParseSettings(const driver_parameter *settings);
// for state machine
void NewState(pap_state next);

View File

@ -25,7 +25,7 @@ status_t std_ops(int32 op, ...);
static
bool
add_to(PPPInterface& mainInterface, PPPInterface *subInterface,
add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface,
driver_parameter *settings, ppp_module_key_type type)
{
if(type != PPP_AUTHENTICATOR_KEY_TYPE)

View File

@ -44,8 +44,8 @@ dump_packet(struct mbuf *packet)
#endif
PPPoEDevice::PPPoEDevice(PPPInterface& interface, driver_parameter *settings)
: PPPDevice("PPPoE", PPPoE_HEADER_SIZE + ETHER_HDR_LEN, interface, settings),
PPPoEDevice::PPPoEDevice(KPPPInterface& interface, driver_parameter *settings)
: KPPPDevice("PPPoE", PPPoE_HEADER_SIZE + ETHER_HDR_LEN, interface, settings),
fEthernetIfnet(NULL),
fSessionID(0),
fHostUniq(NewHostUniq()),
@ -114,7 +114,7 @@ status_t
PPPoEDevice::InitCheck() const
{
return EthernetIfnet() && EthernetIfnet()->output
&& PPPDevice::InitCheck() == B_OK ? B_OK : B_ERROR;
&& KPPPDevice::InitCheck() == B_OK ? B_OK : B_ERROR;
}

View File

@ -23,9 +23,9 @@ enum pppoe_state {
};
class PPPoEDevice : public PPPDevice {
class PPPoEDevice : public KPPPDevice {
public:
PPPoEDevice(PPPInterface& interface, driver_parameter *settings);
PPPoEDevice(KPPPInterface& interface, driver_parameter *settings);
virtual ~PPPoEDevice();
ifnet *EthernetIfnet() const

View File

@ -116,7 +116,7 @@ pppoe_input(struct mbuf *packet)
static
bool
add_to(PPPInterface& mainInterface, PPPInterface *subInterface,
add_to(KPPPInterface& mainInterface, KPPPInterface *subInterface,
driver_parameter *settings, ppp_module_key_type type)
{
if(mainInterface.Mode() != PPP_CLIENT_MODE || type != PPP_DEVICE_KEY_TYPE)