xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/KPPPLayer.cpp (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //
5 //  Copyright (c) 2003 Waldemar Kornewald, Waldemar.Kornewald@web.de
6 //---------------------------------------------------------------------
7 
8 #include <KPPPLayer.h>
9 
10 #include <cstdlib>
11 #include <cstring>
12 #include <core_funcs.h>
13 
14 #ifdef _KERNEL_MODE
15 	#include <kernel_cpp.h>
16 #endif
17 
18 
19 PPPLayer::PPPLayer(const char *name, ppp_level level, uint32 overhead)
20 	: fInitStatus(B_OK),
21 	fOverhead(overhead),
22 	fLevel(level),
23 	fNext(NULL)
24 {
25 	if(name)
26 		fName = strdup(name);
27 	else
28 		fName = strdup("Unknown");
29 }
30 
31 
32 PPPLayer::~PPPLayer()
33 {
34 	free(fName);
35 }
36 
37 
38 status_t
39 PPPLayer::InitCheck() const
40 {
41 	return fInitStatus;
42 }
43 
44 
45 status_t
46 PPPLayer::SendToNext(struct mbuf *packet, uint16 protocolNumber) const
47 {
48 	// Find the next possible handler for this packet.
49 	// Normal protocols (Level() >= PPP_PROTOCOL_LEVEL) do not encapsulate anything.
50 	if(Next()) {
51 		if(Next()->IsAllowedToSend() && Next()->Level() < PPP_PROTOCOL_LEVEL)
52 			return Next()->Send(packet, protocolNumber);
53 		else
54 			return Next()->SendToNext(packet, protocolNumber);
55 	} else {
56 		m_freem(packet);
57 		return B_ERROR;
58 	}
59 }
60 
61 
62 void
63 PPPLayer::Pulse()
64 {
65 	// do nothing by default
66 }
67