Coverage Report

Created: 2026-01-17 08:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/src/PPPoELayer.cpp
Line
Count
Source
1
0
#define LOG_MODULE PacketLogModulePPPoELayer
2
3
#include "PPPoELayer.h"
4
#include "IPv4Layer.h"
5
#include "IPv6Layer.h"
6
#include "PayloadLayer.h"
7
#include "Logger.h"
8
#include <unordered_map>
9
#include <sstream>
10
#include "EndianPortable.h"
11
12
namespace pcpp
13
{
14
15
  /// PPPoELayer
16
  /// ~~~~~~~~~~
17
18
  PPPoELayer::PPPoELayer(uint8_t version, uint8_t type, PPPoELayer::PPPoECode code, uint16_t sessionId,
19
                         size_t additionalBytesToAllocate)
20
0
  {
21
0
    const size_t dataLen = sizeof(pppoe_header) + additionalBytesToAllocate;
22
0
    m_DataLen = dataLen;
23
0
    m_Data = new uint8_t[dataLen];
24
0
    memset(m_Data, 0, dataLen);
25
26
0
    pppoe_header* pppoeHdr = getPPPoEHeader();
27
0
    pppoeHdr->version = (version & 0xf);
28
0
    pppoeHdr->type = (type & 0x0f);
29
0
    pppoeHdr->code = code;
30
0
    pppoeHdr->sessionId = htobe16(sessionId);
31
0
    pppoeHdr->payloadLength = 0;
32
0
  }
33
34
  void PPPoELayer::computeCalculateFields()
35
3.17k
  {
36
3.17k
    pppoe_header* pppoeHdr = getPPPoEHeader();
37
3.17k
    pppoeHdr->payloadLength = htobe16(m_DataLen - sizeof(pppoe_header));
38
3.17k
  }
39
40
  /// PPPoESessionLayer
41
  /// ~~~~~~~~~~~~~~~~~
42
43
  void PPPoESessionLayer::parseNextLayer()
44
34.7k
  {
45
34.7k
    size_t headerLen = getHeaderLen();
46
34.7k
    if (m_DataLen <= headerLen)
47
0
      return;
48
49
34.7k
    uint8_t* payload = m_Data + headerLen;
50
34.7k
    size_t payloadLen = m_DataLen - headerLen;
51
52
34.7k
    switch (getPPPNextProtocol())
53
34.7k
    {
54
34.1k
    case PCPP_PPP_IP:
55
34.1k
      m_NextLayer = IPv4Layer::isDataValid(payload, payloadLen)
56
34.1k
                        ? static_cast<Layer*>(new IPv4Layer(payload, payloadLen, this, m_Packet))
57
34.1k
                        : static_cast<Layer*>(new PayloadLayer(payload, payloadLen, this, m_Packet));
58
34.1k
      break;
59
15
    case PCPP_PPP_IPV6:
60
15
      m_NextLayer = IPv6Layer::isDataValid(payload, payloadLen)
61
15
                        ? static_cast<Layer*>(new IPv6Layer(payload, payloadLen, this, m_Packet))
62
15
                        : static_cast<Layer*>(new PayloadLayer(payload, payloadLen, this, m_Packet));
63
15
      break;
64
584
    default:
65
584
      m_NextLayer = new PayloadLayer(payload, payloadLen, this, m_Packet);
66
584
      break;
67
34.7k
    }
68
34.7k
  }
69
70
  uint16_t PPPoESessionLayer::getPPPNextProtocol() const
71
41.1k
  {
72
41.1k
    if (m_DataLen < getHeaderLen())
73
0
    {
74
0
      PCPP_LOG_ERROR("ERROR: size of layer is smaller then PPPoE session header");
75
0
      return 0;
76
0
    }
77
78
41.1k
    uint16_t pppNextProto = *reinterpret_cast<uint16_t*>(m_Data + sizeof(pppoe_header));
79
41.1k
    return be16toh(pppNextProto);
80
41.1k
  }
81
82
  void PPPoESessionLayer::setPPPNextProtocol(uint16_t nextProtocol)
83
0
  {
84
0
    if (m_DataLen < getHeaderLen())
85
0
    {
86
0
      PCPP_LOG_ERROR("ERROR: size of layer is smaller then PPPoE session header");
87
0
      return;
88
0
    }
89
90
0
    uint16_t* pppProto = reinterpret_cast<uint16_t*>(m_Data + sizeof(pppoe_header));
91
0
    *pppProto = htobe16(nextProtocol);
92
0
  }
93
94
  std::unordered_map<uint16_t, std::string> createPPPNextProtoToStringMap()
95
2
  {
96
2
    std::unordered_map<uint16_t, std::string> tempMap;
97
2
    tempMap[PCPP_PPP_PADDING] = "Padding Protocol";
98
2
    tempMap[PCPP_PPP_ROHC_SCID] = "ROHC small-CID";
99
2
    tempMap[PCPP_PPP_ROHC_LCID] = "ROHC large-CID";
100
2
    tempMap[PCPP_PPP_IP] = "Internet Protocol version 4";
101
2
    tempMap[PCPP_PPP_OSI] = "OSI Network Layer";
102
2
    tempMap[PCPP_PPP_XNSIDP] = "Xerox NS IDP";
103
2
    tempMap[PCPP_PPP_DEC4] = "DECnet Phase IV";
104
2
    tempMap[PCPP_PPP_AT] = "Appletalk";
105
2
    tempMap[PCPP_PPP_IPX] = "Novell IPX";
106
2
    tempMap[PCPP_PPP_VJC_COMP] = "Van Jacobson Compressed TCP/IP";
107
2
    tempMap[PCPP_PPP_VJC_UNCOMP] = "Van Jacobson Uncompressed TCP/IP";
108
2
    tempMap[PCPP_PPP_BCP] = "Bridging PDU";
109
2
    tempMap[PCPP_PPP_ST] = "Stream Protocol (ST-II)";
110
2
    tempMap[PCPP_PPP_VINES] = "Banyan Vines";
111
2
    tempMap[PCPP_PPP_AT_EDDP] = "AppleTalk EDDP";
112
2
    tempMap[PCPP_PPP_AT_SB] = "AppleTalk SmartBuffered";
113
2
    tempMap[PCPP_PPP_MP] = "Multi-Link";
114
2
    tempMap[PCPP_PPP_NB] = "NETBIOS Framing";
115
2
    tempMap[PCPP_PPP_CISCO] = "Cisco Systems";
116
2
    tempMap[PCPP_PPP_ASCOM] = "Ascom Timeplex";
117
2
    tempMap[PCPP_PPP_LBLB] = "Fujitsu Link Backup and Load Balancing (LBLB)";
118
2
    tempMap[PCPP_PPP_RL] = "DCA Remote Lan";
119
2
    tempMap[PCPP_PPP_SDTP] = "Serial Data Transport Protocol (PPP-SDTP)";
120
2
    tempMap[PCPP_PPP_LLC] = "SNA over 802.2";
121
2
    tempMap[PCPP_PPP_SNA] = "SNA";
122
2
    tempMap[PCPP_PPP_IPV6HC] = "IPv6 Header Compression ";
123
2
    tempMap[PCPP_PPP_KNX] = "KNX Bridging Data";
124
2
    tempMap[PCPP_PPP_ENCRYPT] = "Encryption";
125
2
    tempMap[PCPP_PPP_ILE] = "Individual Link Encryption";
126
2
    tempMap[PCPP_PPP_IPV6] = "Internet Protocol version 6";
127
2
    tempMap[PCPP_PPP_MUX] = "PPP Muxing";
128
2
    tempMap[PCPP_PPP_VSNP] = "Vendor-Specific Network Protocol (VSNP)";
129
2
    tempMap[PCPP_PPP_TNP] = "TRILL Network Protocol (TNP)";
130
2
    tempMap[PCPP_PPP_RTP_FH] = "RTP IPHC Full Header";
131
2
    tempMap[PCPP_PPP_RTP_CTCP] = "RTP IPHC Compressed TCP";
132
2
    tempMap[PCPP_PPP_RTP_CNTCP] = "RTP IPHC Compressed Non TCP";
133
2
    tempMap[PCPP_PPP_RTP_CUDP8] = "RTP IPHC Compressed UDP 8";
134
2
    tempMap[PCPP_PPP_RTP_CRTP8] = "RTP IPHC Compressed RTP 8";
135
2
    tempMap[PCPP_PPP_STAMPEDE] = "Stampede Bridging";
136
2
    tempMap[PCPP_PPP_MPPLUS] = "MP+ Protocol";
137
2
    tempMap[PCPP_PPP_NTCITS_IPI] = "NTCITS IPI";
138
2
    tempMap[PCPP_PPP_ML_SLCOMP] = "Single link compression in multilink";
139
2
    tempMap[PCPP_PPP_COMP] = "Compressed datagram";
140
2
    tempMap[PCPP_PPP_STP_HELLO] = "802.1d Hello Packets";
141
2
    tempMap[PCPP_PPP_IBM_SR] = "IBM Source Routing BPDU";
142
2
    tempMap[PCPP_PPP_DEC_LB] = "DEC LANBridge100 Spanning Tree";
143
2
    tempMap[PCPP_PPP_CDP] = "Cisco Discovery Protocol";
144
2
    tempMap[PCPP_PPP_NETCS] = "Netcs Twin Routing";
145
2
    tempMap[PCPP_PPP_STP] = "STP - Scheduled Transfer Protocol";
146
2
    tempMap[PCPP_PPP_EDP] = "EDP - Extreme Discovery Protocol";
147
2
    tempMap[PCPP_PPP_OSCP] = "Optical Supervisory Channel Protocol (OSCP)";
148
2
    tempMap[PCPP_PPP_OSCP2] = "Optical Supervisory Channel Protocol (OSCP)";
149
2
    tempMap[PCPP_PPP_LUXCOM] = "Luxcom";
150
2
    tempMap[PCPP_PPP_SIGMA] = "Sigma Network Systems";
151
2
    tempMap[PCPP_PPP_ACSP] = "Apple Client Server Protocol";
152
2
    tempMap[PCPP_PPP_MPLS_UNI] = "MPLS Unicast";
153
2
    tempMap[PCPP_PPP_MPLS_MULTI] = "MPLS Multicast";
154
2
    tempMap[PCPP_PPP_P12844] = "IEEE p1284.4 standard - data packets";
155
2
    tempMap[PCPP_PPP_TETRA] = "ETSI TETRA Network Protocol Type 1";
156
2
    tempMap[PCPP_PPP_MFTP] = "Multichannel Flow Treatment Protocol";
157
2
    tempMap[PCPP_PPP_RTP_CTCPND] = "RTP IPHC Compressed TCP No Delta";
158
2
    tempMap[PCPP_PPP_RTP_CS] = "RTP IPHC Context State";
159
2
    tempMap[PCPP_PPP_RTP_CUDP16] = "RTP IPHC Compressed UDP 16";
160
2
    tempMap[PCPP_PPP_RTP_CRDP16] = "RTP IPHC Compressed RTP 16";
161
2
    tempMap[PCPP_PPP_CCCP] = "Cray Communications Control Protocol";
162
2
    tempMap[PCPP_PPP_CDPD_MNRP] = "CDPD Mobile Network Registration Protocol";
163
2
    tempMap[PCPP_PPP_EXPANDAP] = "Expand accelerator protocol";
164
2
    tempMap[PCPP_PPP_ODSICP] = "ODSICP NCP";
165
2
    tempMap[PCPP_PPP_DOCSIS] = "DOCSIS DLL";
166
2
    tempMap[PCPP_PPP_CETACEANNDP] = "Cetacean Network Detection Protocol";
167
2
    tempMap[PCPP_PPP_LZS] = "Stacker LZS";
168
2
    tempMap[PCPP_PPP_REFTEK] = "RefTek Protocol";
169
2
    tempMap[PCPP_PPP_FC] = "Fibre Channel";
170
2
    tempMap[PCPP_PPP_EMIT] = "EMIT Protocols";
171
2
    tempMap[PCPP_PPP_VSP] = "Vendor-Specific Protocol (VSP)";
172
2
    tempMap[PCPP_PPP_TLSP] = "TRILL Link State Protocol (TLSP)";
173
2
    tempMap[PCPP_PPP_IPCP] = "Internet Protocol Control Protocol";
174
2
    tempMap[PCPP_PPP_OSINLCP] = "OSI Network Layer Control Protocol";
175
2
    tempMap[PCPP_PPP_XNSIDPCP] = "Xerox NS IDP Control Protocol";
176
2
    tempMap[PCPP_PPP_DECNETCP] = "DECnet Phase IV Control Protocol";
177
2
    tempMap[PCPP_PPP_ATCP] = "AppleTalk Control Protocol";
178
2
    tempMap[PCPP_PPP_IPXCP] = "Novell IPX Control Protocol";
179
2
    tempMap[PCPP_PPP_BRIDGENCP] = "Bridging NCP";
180
2
    tempMap[PCPP_PPP_SPCP] = "Stream Protocol Control Protocol";
181
2
    tempMap[PCPP_PPP_BVCP] = "Banyan Vines Control Protocol";
182
2
    tempMap[PCPP_PPP_MLCP] = "Multi-Link Control Protocol";
183
2
    tempMap[PCPP_PPP_NBCP] = "NETBIOS Framing Control Protocol";
184
2
    tempMap[PCPP_PPP_CISCOCP] = "Cisco Systems Control Protocol";
185
2
    tempMap[PCPP_PPP_ASCOMCP] = "Ascom Timeplex";
186
2
    tempMap[PCPP_PPP_LBLBCP] = "Fujitsu LBLB Control Protocol";
187
2
    tempMap[PCPP_PPP_RLNCP] = "DCA Remote Lan Network Control Protocol (RLNCP)";
188
2
    tempMap[PCPP_PPP_SDCP] = "Serial Data Control Protocol (PPP-SDCP)";
189
2
    tempMap[PCPP_PPP_LLCCP] = "SNA over 802.2 Control Protocol";
190
2
    tempMap[PCPP_PPP_SNACP] = "SNA Control Protocol";
191
2
    tempMap[PCPP_PPP_IP6HCCP] = "IP6 Header Compression Control Protocol";
192
2
    tempMap[PCPP_PPP_KNXCP] = "KNX Bridging Control Protocol";
193
2
    tempMap[PCPP_PPP_ECP] = "Encryption Control Protocol";
194
2
    tempMap[PCPP_PPP_ILECP] = "Individual Link Encryption Control Protocol";
195
2
    tempMap[PCPP_PPP_IPV6CP] = "IPv6 Control Protocol";
196
2
    tempMap[PCPP_PPP_MUXCP] = "PPP Muxing Control Protocol";
197
2
    tempMap[PCPP_PPP_VSNCP] = "Vendor-Specific Network Control Protocol (VSNCP)";
198
2
    tempMap[PCPP_PPP_TNCP] = "TRILL Network Control Protocol";
199
2
    tempMap[PCPP_PPP_STAMPEDECP] = "Stampede Bridging Control Protocol";
200
2
    tempMap[PCPP_PPP_MPPCP] = "MP+ Control Protocol";
201
2
    tempMap[PCPP_PPP_IPICP] = "NTCITS IPI Control Protocol";
202
2
    tempMap[PCPP_PPP_SLCC] = "Single link compression in multilink control";
203
2
    tempMap[PCPP_PPP_CCP] = "Compression Control Protocol";
204
2
    tempMap[PCPP_PPP_CDPCP] = "Cisco Discovery Protocol Control Protocol";
205
2
    tempMap[PCPP_PPP_NETCSCP] = "Netcs Twin Routing";
206
2
    tempMap[PCPP_PPP_STPCP] = "STP - Control Protocol";
207
2
    tempMap[PCPP_PPP_EDPCP] = "EDPCP - Extreme Discovery Protocol Control Protocol";
208
2
    tempMap[PCPP_PPP_ACSPC] = "Apple Client Server Protocol Control";
209
2
    tempMap[PCPP_PPP_MPLSCP] = "MPLS Control Protocol";
210
2
    tempMap[PCPP_PPP_P12844CP] = "IEEE p1284.4 standard - Protocol Control";
211
2
    tempMap[PCPP_PPP_TETRACP] = "ETSI TETRA TNP1 Control Protocol";
212
2
    tempMap[PCPP_PPP_MFTPCP] = "Multichannel Flow Treatment Protocol";
213
2
    tempMap[PCPP_PPP_LCP] = "Link Control Protocol";
214
2
    tempMap[PCPP_PPP_PAP] = "Password Authentication Protocol";
215
2
    tempMap[PCPP_PPP_LQR] = "Link Quality Report";
216
2
    tempMap[PCPP_PPP_SPAP] = "Shiva Password Authentication Protocol";
217
2
    tempMap[PCPP_PPP_CBCP] = "Callback Control Protocol (CBCP)";
218
2
    tempMap[PCPP_PPP_BACP] = "BACP Bandwidth Allocation Control Protocol";
219
2
    tempMap[PCPP_PPP_BAP] = "BAP Bandwidth Allocation Protocol";
220
2
    tempMap[PCPP_PPP_VSAP] = "Vendor-Specific Authentication Protocol (VSAP)";
221
2
    tempMap[PCPP_PPP_CONTCP] = "Container Control Protocol";
222
2
    tempMap[PCPP_PPP_CHAP] = "Challenge Handshake Authentication Protocol";
223
2
    tempMap[PCPP_PPP_RSAAP] = "RSA Authentication Protocol";
224
2
    tempMap[PCPP_PPP_EAP] = "Extensible Authentication Protocol";
225
2
    tempMap[PCPP_PPP_SIEP] = "Mitsubishi Security Information Exchange Protocol (SIEP)";
226
2
    tempMap[PCPP_PPP_SBAP] = "Stampede Bridging Authorization Protocol";
227
2
    tempMap[PCPP_PPP_PRPAP] = "Proprietary Authentication Protocol";
228
2
    tempMap[PCPP_PPP_PRPAP2] = "Proprietary Authentication Protocol";
229
2
    tempMap[PCPP_PPP_PRPNIAP] = "Proprietary Node ID Authentication Protocol";
230
2
    return tempMap;
231
2
  }
232
233
  const std::unordered_map<uint16_t, std::string> PPPNextProtoToString = createPPPNextProtoToStringMap();
234
235
  std::string PPPoESessionLayer::toString() const
236
6.28k
  {
237
6.28k
    auto findResult = PPPNextProtoToString.find(getPPPNextProtocol());
238
6.28k
    std::string nextProtocol;
239
6.28k
    if (findResult != PPPNextProtoToString.end())
240
6.12k
      nextProtocol = findResult->second;
241
156
    else
242
156
    {
243
156
      std::ostringstream stream;
244
156
      stream << "Unknown (0x" << std::hex << getPPPNextProtocol() << ")";
245
156
      nextProtocol = stream.str();
246
156
    }
247
248
6.28k
    return "PPP-over-Ethernet Session (followed by '" + nextProtocol + "')";
249
6.28k
  }
250
251
  /// PPPoEDiscoveryLayer
252
  /// ~~~~~~~~~~~~~~~~~~~
253
254
  PPPoEDiscoveryLayer::PPPoETagTypes PPPoEDiscoveryLayer::PPPoETag::getType() const
255
0
  {
256
0
    if (m_Data == nullptr)
257
0
      return PPPoEDiscoveryLayer::PPPoETagTypes::PPPOE_TAG_EOL;
258
259
0
    return static_cast<PPPoEDiscoveryLayer::PPPoETagTypes>(be16toh(m_Data->recordType));
260
0
  }
261
262
  size_t PPPoEDiscoveryLayer::PPPoETag::getTotalSize() const
263
0
  {
264
0
    if (m_Data == nullptr)
265
0
      return 0;
266
267
0
    return 2 * sizeof(uint16_t) + be16toh(m_Data->recordLen);
268
0
  }
269
270
  size_t PPPoEDiscoveryLayer::PPPoETag::getDataSize() const
271
0
  {
272
0
    if (m_Data == nullptr)
273
0
      return 0;
274
275
0
    return be16toh(m_Data->recordLen);
276
0
  }
277
278
  PPPoEDiscoveryLayer::PPPoETag PPPoEDiscoveryLayer::PPPoETagBuilder::build() const
279
0
  {
280
0
    size_t tagSize = 2 * sizeof(uint16_t) + m_RecValueLen;
281
0
    uint8_t* recordBuffer = new uint8_t[tagSize];
282
0
    uint16_t tagTypeVal = htobe16(static_cast<uint16_t>(m_RecType));
283
0
    uint16_t tagLength = htobe16(static_cast<uint16_t>(m_RecValueLen));
284
0
    memcpy(recordBuffer, &tagTypeVal, sizeof(uint16_t));
285
0
    memcpy(recordBuffer + sizeof(uint16_t), &tagLength, sizeof(uint16_t));
286
0
    if (tagLength > 0 && m_RecValue != nullptr)
287
0
      memcpy(recordBuffer + 2 * sizeof(uint16_t), m_RecValue, m_RecValueLen);
288
289
0
    return PPPoEDiscoveryLayer::PPPoETag(recordBuffer);
290
0
  }
291
292
  PPPoEDiscoveryLayer::PPPoETag PPPoEDiscoveryLayer::getTag(PPPoEDiscoveryLayer::PPPoETagTypes tagType) const
293
0
  {
294
0
    return m_TagReader.getTLVRecord(static_cast<uint32_t>(tagType), getTagBasePtr(),
295
0
                                    m_DataLen - sizeof(pppoe_header));
296
0
  }
297
298
  PPPoEDiscoveryLayer::PPPoETag PPPoEDiscoveryLayer::getFirstTag() const
299
0
  {
300
0
    return m_TagReader.getFirstTLVRecord(getTagBasePtr(), m_DataLen - sizeof(pppoe_header));
301
0
  }
302
303
  PPPoEDiscoveryLayer::PPPoETag PPPoEDiscoveryLayer::getNextTag(const PPPoEDiscoveryLayer::PPPoETag& tag) const
304
0
  {
305
0
    return m_TagReader.getNextTLVRecord(const_cast<PPPoEDiscoveryLayer::PPPoETag&>(tag), getTagBasePtr(),
306
0
                                        m_DataLen - sizeof(pppoe_header));
307
0
  }
308
309
  int PPPoEDiscoveryLayer::getTagCount() const
310
0
  {
311
0
    return m_TagReader.getTLVRecordCount(getTagBasePtr(), m_DataLen - sizeof(pppoe_header));
312
0
  }
313
314
  PPPoEDiscoveryLayer::PPPoETag PPPoEDiscoveryLayer::addTagAt(const PPPoETagBuilder& tagBuilder, int offset)
315
0
  {
316
0
    PPPoETag newTag = tagBuilder.build();
317
0
    if (newTag.isNull())
318
0
    {
319
0
      PCPP_LOG_ERROR("Cannot build new tag of type " << (int)newTag.getType());
320
0
      return newTag;
321
0
    }
322
323
0
    size_t sizeToExtend = newTag.getTotalSize();
324
325
0
    if (!extendLayer(offset, sizeToExtend))
326
0
    {
327
0
      PCPP_LOG_ERROR("Could not extend PPPoEDiscoveryLayer in [" << sizeToExtend << "] bytes");
328
0
      newTag.purgeRecordData();
329
0
      return PPPoETag(nullptr);
330
0
    }
331
332
0
    memcpy(m_Data + offset, newTag.getRecordBasePtr(), newTag.getTotalSize());
333
334
0
    uint8_t* newTagPtr = m_Data + offset;
335
336
0
    m_TagReader.changeTLVRecordCount(1);
337
338
0
    newTag.purgeRecordData();
339
340
0
    getPPPoEHeader()->payloadLength += htobe16(sizeToExtend);
341
342
0
    return PPPoETag(newTagPtr);
343
0
  }
344
345
  PPPoEDiscoveryLayer::PPPoETag PPPoEDiscoveryLayer::addTagAfter(const PPPoETagBuilder& tagBuilder,
346
                                                                 PPPoETagTypes prevTagType)
347
0
  {
348
0
    int offset = 0;
349
350
0
    PPPoETag prevTag = getTag(prevTagType);
351
352
0
    if (prevTag.isNull())
353
0
    {
354
0
      offset = getHeaderLen();
355
0
    }
356
0
    else
357
0
    {
358
0
      offset = prevTag.getRecordBasePtr() + prevTag.getTotalSize() - m_Data;
359
0
    }
360
361
0
    return addTagAt(tagBuilder, offset);
362
0
  }
363
364
  PPPoEDiscoveryLayer::PPPoETag PPPoEDiscoveryLayer::addTag(const PPPoETagBuilder& tagBuilder)
365
0
  {
366
0
    return addTagAt(tagBuilder, getHeaderLen());
367
0
  }
368
369
  size_t PPPoEDiscoveryLayer::getHeaderLen() const
370
188
  {
371
188
    size_t payloadLen = sizeof(pppoe_header) + be16toh(getPPPoEHeader()->payloadLength);
372
188
    if (payloadLen > m_DataLen)
373
171
      return m_DataLen;
374
375
17
    return payloadLen;
376
188
  }
377
378
  bool PPPoEDiscoveryLayer::removeTag(PPPoEDiscoveryLayer::PPPoETagTypes tagType)
379
0
  {
380
0
    PPPoEDiscoveryLayer::PPPoETag tagToRemove = getTag(tagType);
381
0
    if (tagToRemove.isNull())
382
0
    {
383
0
      PCPP_LOG_ERROR("Couldn't find tag");
384
0
      return false;
385
0
    }
386
387
0
    int offset = tagToRemove.getRecordBasePtr() - m_Data;
388
389
0
    uint16_t tagTotalSize = tagToRemove.getTotalSize();
390
391
0
    if (!shortenLayer(offset, tagTotalSize))
392
0
    {
393
0
      return false;
394
0
    }
395
396
0
    m_TagReader.changeTLVRecordCount(-1);
397
398
0
    getPPPoEHeader()->payloadLength -= htobe16(tagTotalSize);
399
0
    return true;
400
0
  }
401
402
  bool PPPoEDiscoveryLayer::removeAllTags()
403
0
  {
404
0
    size_t tagCount = getTagCount();
405
0
    int offset = sizeof(pppoe_header);
406
0
    if (!shortenLayer(offset, m_DataLen - offset))
407
0
    {
408
0
      return false;
409
0
    }
410
0
    m_TagReader.changeTLVRecordCount(0 - tagCount);
411
0
    getPPPoEHeader()->payloadLength = 0;
412
0
    return true;
413
0
  }
414
415
  std::string PPPoEDiscoveryLayer::codeToString(PPPoECode code) const
416
64
  {
417
64
    switch (code)
418
64
    {
419
14
    case PPPoELayer::PPPOE_CODE_SESSION:
420
14
      return std::string("PPPoE Session");
421
0
    case PPPoELayer::PPPOE_CODE_PADO:
422
0
      return std::string("PADO");
423
0
    case PPPoELayer::PPPOE_CODE_PADI:
424
0
      return std::string("PADI");
425
0
    case PPPoELayer::PPPOE_CODE_PADG:
426
0
      return std::string("PADG");
427
0
    case PPPoELayer::PPPOE_CODE_PADC:
428
0
      return std::string("PADC");
429
0
    case PPPoELayer::PPPOE_CODE_PADQ:
430
0
      return std::string("PADQ");
431
0
    case PPPoELayer::PPPOE_CODE_PADR:
432
0
      return std::string("PADR");
433
50
    case PPPoELayer::PPPOE_CODE_PADS:
434
50
      return std::string("PADS");
435
0
    case PPPoELayer::PPPOE_CODE_PADT:
436
0
      return std::string("PADT");
437
0
    case PPPoELayer::PPPOE_CODE_PADM:
438
0
      return std::string("PADM");
439
0
    case PPPoELayer::PPPOE_CODE_PADN:
440
0
      return std::string("PADN");
441
0
    default:
442
0
      return std::string("Unknown PPPoE code");
443
64
    }
444
64
  }
445
446
}  // namespace pcpp