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