Yeah! It finally works! The default route was missing, that was the only problem!

I established a connection with PPPoE and pinged goole and osnews. Net+ loaded half of www.osnews.com but then crashed because of a bug in our DNS resolver.
There is one more bug to fix: our core stack module does not remove the routes when an interface is deleted.
Thus, there will always remain the route(s) from the last connection(s).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5910 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Waldemar Kornewald
2004-01-05 13:34:11 +00:00
parent a243b54e73
commit 86c13dda5a
6 changed files with 104 additions and 29 deletions
@@ -179,10 +179,16 @@ IPCP::Down()
status_t status_t
IPCP::Send(struct mbuf *packet, uint16 protocolNumber = IPCP_PROTOCOL) IPCP::Send(struct mbuf *packet, uint16 protocolNumber = IPCP_PROTOCOL)
{ {
#if DEBUG
printf("IPCP: Send(0x%X)\n", protocolNumber);
#endif
if((protocolNumber == IP_PROTOCOL && State() == PPP_OPENED_STATE) if((protocolNumber == IP_PROTOCOL && State() == PPP_OPENED_STATE)
|| protocolNumber == IPCP_PROTOCOL) || protocolNumber == IPCP_PROTOCOL)
return SendToNext(packet, protocolNumber); return SendToNext(packet, protocolNumber);
printf("IPCP: Send() failed because of wrong state or protocol number!\n");
m_freem(packet); m_freem(packet);
return B_ERROR; return B_ERROR;
} }
@@ -191,6 +197,10 @@ IPCP::Send(struct mbuf *packet, uint16 protocolNumber = IPCP_PROTOCOL)
status_t status_t
IPCP::Receive(struct mbuf *packet, uint16 protocolNumber) IPCP::Receive(struct mbuf *packet, uint16 protocolNumber)
{ {
#if DEBUG
printf("IPCP: Receive(0x%X)\n", protocolNumber);
#endif
if(!packet) if(!packet)
return B_ERROR; return B_ERROR;
@@ -359,10 +369,14 @@ IPCP::UpdateAddresses()
if(State() != PPP_OPENED_STATE && !Interface().DoesDialOnDemand()) if(State() != PPP_OPENED_STATE && !Interface().DoesDialOnDemand())
return; return;
in_addr_t netmask; struct sockaddr_in gateway;
struct in_aliasreq inreq; struct in_aliasreq inreq;
struct ifreq ifreqAddress, ifreqDestination; struct ifreq ifreqAddress, ifreqDestination;
memset(&inreq, 0, sizeof(struct in_aliasreq));
memset(&ifreqAddress, 0, sizeof(struct ifreq));
memset(&ifreqDestination, 0, sizeof(struct ifreq));
// create local address
inreq.ifra_addr.sin_family = AF_INET; inreq.ifra_addr.sin_family = AF_INET;
if(fLocalRequests.address != INADDR_ANY) if(fLocalRequests.address != INADDR_ANY)
inreq.ifra_addr.sin_addr.s_addr = fLocalRequests.address; inreq.ifra_addr.sin_addr.s_addr = fLocalRequests.address;
@@ -370,42 +384,59 @@ IPCP::UpdateAddresses()
inreq.ifra_addr.sin_addr.s_addr = INADDR_BROADCAST; inreq.ifra_addr.sin_addr.s_addr = INADDR_BROADCAST;
else else
inreq.ifra_addr.sin_addr.s_addr = fLocalConfiguration.address; inreq.ifra_addr.sin_addr.s_addr = fLocalConfiguration.address;
inreq.ifra_addr.sin_len = sizeof(sockaddr_in); inreq.ifra_addr.sin_len = sizeof(struct sockaddr_in);
memcpy(&ifreqAddress.ifr_addr, &inreq.ifra_addr, sizeof(sockaddr_in)); memcpy(&ifreqAddress.ifr_addr, &inreq.ifra_addr, sizeof(struct sockaddr_in));
inreq.ifra_dstaddr.sin_family = AF_INET; // create destination address
gateway.sin_family = AF_INET;
if(fPeerRequests.address != INADDR_ANY) if(fPeerRequests.address != INADDR_ANY)
inreq.ifra_dstaddr.sin_addr.s_addr = fPeerRequests.address; gateway.sin_addr.s_addr = fPeerRequests.address;
else if(fPeerConfiguration.address == INADDR_ANY) else if(fPeerConfiguration.address == INADDR_ANY)
inreq.ifra_dstaddr.sin_addr.s_addr = INADDR_BROADCAST; gateway.sin_addr.s_addr = INADDR_BROADCAST;
else else
inreq.ifra_dstaddr.sin_addr.s_addr = fPeerConfiguration.address; gateway.sin_addr.s_addr = fPeerConfiguration.address;
inreq.ifra_dstaddr.sin_len = sizeof(sockaddr_in); gateway.sin_len = sizeof(struct sockaddr_in);
memcpy(&ifreqDestination.ifr_dstaddr, &inreq.ifra_dstaddr, sizeof(sockaddr_in)); memcpy(&inreq.ifra_dstaddr, &gateway,
sizeof(struct sockaddr_in));
memcpy(&ifreqDestination.ifr_dstaddr, &inreq.ifra_dstaddr,
sizeof(struct sockaddr_in));
// create netmask
inreq.ifra_mask.sin_family = AF_INET; inreq.ifra_mask.sin_family = AF_INET;
if(fLocalRequests.netmask != INADDR_ANY) inreq.ifra_mask.sin_addr.s_addr = fLocalRequests.netmask;
netmask = fLocalRequests.netmask; inreq.ifra_mask.sin_len = sizeof(struct sockaddr_in);
else if(State() != PPP_OPENED_STATE)
netmask = INADDR_BROADCAST;
else
netmask = 0x80000000;
inreq.ifra_mask.sin_addr.s_addr = netmask;
inreq.ifra_mask.sin_len = sizeof(sockaddr_in);
// tell stack to use these values
if(in_control(NULL, SIOCAIFADDR, (caddr_t) &inreq,
Interface().Ifnet()) != B_OK)
printf("IPCP: UpdateAddress(): SIOCAIFADDR returned error!\n");
if(in_control(NULL, SIOCSIFADDR, (caddr_t) &ifreqAddress, if(in_control(NULL, SIOCSIFADDR, (caddr_t) &ifreqAddress,
Interface().Ifnet()) != B_OK) Interface().Ifnet()) != B_OK)
printf("IPCP: UpdateAddress(): SIOCSIFADDR returned error!\n"); printf("IPCP: UpdateAddress(): SIOCSIFADDR returned error!\n");
if(in_control(NULL, SIOCSIFDSTADDR, (caddr_t) &ifreqDestination, if(in_control(NULL, SIOCSIFDSTADDR, (caddr_t) &ifreqDestination,
Interface().Ifnet()) != B_OK) Interface().Ifnet()) != B_OK)
printf("IPCP: UpdateAddress(): SIOCSIFDSTADDR returned error!\n"); printf("IPCP: UpdateAddress(): SIOCSIFDSTADDR returned error!\n");
memcpy(&inreq.ifra_addr, &inreq.ifra_mask, sizeof(struct sockaddr_in));
// SIOCISFNETMASK wants the netmask to be in ifra_addr
if(in_control(NULL, SIOCSIFNETMASK, (caddr_t) &inreq,
Interface().Ifnet()) != B_OK)
printf("IPCP: UpdateAddress(): SIOCSIFNETMASK returned error!\n");
// the netmask is optional for PPP interfaces // add default/subnet route
if(fLocalRequests.netmask != INADDR_ANY) { struct rtentry *rt;
if(in_control(NULL, SIOCSIFNETMASK, (caddr_t) &inreq.ifra_mask, struct sockaddr_in destination;
Interface().Ifnet()) != B_OK) destination.sin_family = AF_INET;
printf("IPCP: UpdateAddress(): SIOCSIFNETMASK returned error!\n"); destination.sin_addr.s_addr = fLocalRequests.netmask;
} if(fLocalRequests.netmask == INADDR_ANY)
destination.sin_len = 0;
else
destination.sin_len = sizeof(struct sockaddr_in);
if(rtrequest(RTM_ADD, (struct sockaddr*) &destination, (struct sockaddr*) &gateway,
(struct sockaddr*) &inreq.ifra_mask, RTF_UP | RTF_GATEWAY, &rt) != B_OK)
printf("IPCP: UpdateAddress(): could not add default route!\n");
--rt->rt_refcnt;
} }
@@ -282,14 +282,16 @@ PPPoEDevice::CountOutputBytes() const
status_t status_t
PPPoEDevice::Send(struct mbuf *packet, uint16 protocolNumber = 0) PPPoEDevice::Send(struct mbuf *packet, uint16 protocolNumber = 0)
{ {
// Send() is only for PPP packets. PPPoE packets are sent directly to ethernet.
#if DEBUG #if DEBUG
printf("PPPoEDevice: Send()\n"); printf("PPPoEDevice: Send()\n");
dump_packet(packet);
#endif #endif
if(!packet) if(!packet)
return B_ERROR; return B_ERROR;
else if(InitCheck() != B_OK || protocolNumber != 0) { else if(InitCheck() != B_OK || protocolNumber != 0) {
printf("PPPoEDevice::Send(): InitCheck() != B_OK!\n");
m_freem(packet); m_freem(packet);
return B_ERROR; return B_ERROR;
} }
@@ -297,6 +299,7 @@ PPPoEDevice::Send(struct mbuf *packet, uint16 protocolNumber = 0)
LockerHelper locker(fLock); LockerHelper locker(fLock);
if(!IsUp()) { if(!IsUp()) {
printf("PPPoEDevice::Send(): no connection!\n");
m_freem(packet); m_freem(packet);
return PPP_NO_CONNECTION; return PPP_NO_CONNECTION;
} }
@@ -648,16 +648,27 @@ PPPInterface::ProtocolAt(int32 index) const
PPPProtocol* PPPProtocol*
PPPInterface::ProtocolFor(uint16 protocolNumber, PPPProtocol *start = NULL) const PPPInterface::ProtocolFor(uint16 protocolNumber, PPPProtocol *start = NULL) const
{ {
#if DEBUG
printf("PPPInterface: ProtocolFor(%X), p&=%X\n", protocolNumber,
protocolNumber & 0x7FFF);
#endif
PPPProtocol *current = start ? start : FirstProtocol(); PPPProtocol *current = start ? start : FirstProtocol();
for(; current; current = current->NextProtocol()) { for(; current; current = current->NextProtocol()) {
#if DEBUG
printf("PPPInterface: ProtocolFor(): c=%X, c&=%X\n", current->ProtocolNumber(),
current->ProtocolNumber() & 0x7FFF);
#endif
if(current->ProtocolNumber() == protocolNumber if(current->ProtocolNumber() == protocolNumber
|| (current->Flags() & PPP_INCLUDES_NCP || (current->Flags() & PPP_INCLUDES_NCP
&& current->ProtocolNumber() & 0x7FFF == protocolNumber & 0x7FFF)) && (current->ProtocolNumber() & 0x7FFF)
== (protocolNumber & 0x7FFF)))
return current; return current;
} }
return current; return NULL;
} }
@@ -1194,9 +1205,23 @@ PPPInterface::Send(struct mbuf *packet, uint16 protocolNumber)
protocol = protocol->NextProtocol() ? protocol = protocol->NextProtocol() ?
ProtocolFor(protocolNumber, protocol->NextProtocol()) : NULL; ProtocolFor(protocolNumber, protocol->NextProtocol()) : NULL;
#if DEBUG
if(!protocol)
printf("PPPInterface::Send(): no protocol found!\n");
else if(!Device()->IsUp())
printf("PPPInterface::Send(): device is not up!\n");
else if(!protocol->IsEnabled())
printf("PPPInterface::Send(): protocol not enabled!\n");
else if(!IsProtocolAllowed(*protocol))
printf("PPPInterface::Send(): protocol not allowed to send!\n");
else
printf("PPPInterface::Send(): protocol allowed\n");
#endif
// make sure that protocol is allowed to send and everything is up // make sure that protocol is allowed to send and everything is up
if(!Device()->IsUp() || !protocol || !protocol->IsEnabled() if(!Device()->IsUp() || !protocol || !protocol->IsEnabled()
|| !IsProtocolAllowed(*protocol)) { || !IsProtocolAllowed(*protocol)) {
printf("PPPInterface::Send(): cannot send!\n");
m_freem(packet); m_freem(packet);
return B_ERROR; return B_ERROR;
} }
@@ -1272,6 +1297,10 @@ PPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
for(; protocol; for(; protocol;
protocol = protocol->NextProtocol() ? protocol = protocol->NextProtocol() ?
ProtocolFor(protocolNumber, protocol->NextProtocol()) : NULL) { ProtocolFor(protocolNumber, protocol->NextProtocol()) : NULL) {
#if DEBUG
printf("PPPInterface::Receive(): trying protocol\n");
#endif
if(!protocol->IsEnabled() || !IsProtocolAllowed(*protocol)) if(!protocol->IsEnabled() || !IsProtocolAllowed(*protocol))
continue; continue;
// skip handler if disabled or not allowed // skip handler if disabled or not allowed
@@ -1283,6 +1312,10 @@ PPPInterface::Receive(struct mbuf *packet, uint16 protocolNumber)
return result; return result;
} }
#if DEBUG
printf("PPPInterface::Receive(): trying parent\n");
#endif
// maybe the parent interface can handle the packet // maybe the parent interface can handle the packet
if(Parent()) if(Parent())
return Parent()->Receive(packet, protocolNumber); return Parent()->Receive(packet, protocolNumber);
@@ -217,8 +217,10 @@ PPPLCP::Receive(struct mbuf *packet, uint16 protocolNumber)
if(!packet) if(!packet)
return B_ERROR; return B_ERROR;
if(protocolNumber != PPP_LCP_PROTOCOL) if(protocolNumber != PPP_LCP_PROTOCOL) {
printf("PPPLCP::Receive(): wrong protocol number!\n");
return PPP_UNHANDLED; return PPP_UNHANDLED;
}
ppp_lcp_packet *data = mtod(packet, ppp_lcp_packet*); ppp_lcp_packet *data = mtod(packet, ppp_lcp_packet*);
@@ -11,8 +11,13 @@
#include <cstring> #include <cstring>
#include <core_funcs.h> #include <core_funcs.h>
#ifdef _KERNEL_MODE #ifdef _KERNEL_MODE
#include <kernel_cpp.h> #include <kernel_cpp.h>
#define spawn_thread spawn_kernel_thread
#define printf dprintf
#else
#include <cstdio>
#endif #endif
@@ -56,6 +61,7 @@ PPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const
else else
return Next()->SendToNext(packet, protocolNumber); return Next()->SendToNext(packet, protocolNumber);
} else { } else {
printf("PPPLayer: SendToNext() failed because there is no next handler!\n");
m_freem(packet); m_freem(packet);
return B_ERROR; return B_ERROR;
} }
@@ -20,7 +20,7 @@
#ifdef _KERNEL_MODE #ifdef _KERNEL_MODE
#define spawn_thread spawn_kernel_thread #define spawn_thread spawn_kernel_thread
#define printf dprintf #define printf dprintf
#else DEBUG #else
#include <cstdio> #include <cstdio>
#endif #endif
@@ -1893,7 +1893,7 @@ bool
PPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uint8 code) PPPStateMachine::SendCodeReject(struct mbuf *packet, uint16 protocolNumber, uint8 code)
{ {
#if DEBUG #if DEBUG
printf("PPPSM: SendCodeReject(protocolNumber=%d;code=%d) state=%d phase=%d\n", printf("PPPSM: SendCodeReject(protocolNumber=%X;code=%d) state=%d phase=%d\n",
protocolNumber, code, State(), Phase()); protocolNumber, code, State(), Phase());
#endif #endif