Coverage Report

Created: 2024-02-25 06:29

/src/PcapPlusPlus/Packet++/header/BgpLayer.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
3
#include <vector>
4
#include "Layer.h"
5
#include "IpAddress.h"
6
7
/**
8
 * @file
9
 * This file contains classes for parsing, creating and editing Border Gateway Protocol (BGP) version 4 packets.
10
 * It contains an abstract class named BgpLayer which has common functionality and 5 inherited classes that
11
 * represent the different BGP message types: OPEN, UPDATE, NOTIFICATION, KEEPALIVE and ROUTE-REFRESH.
12
 * Each of these classes contains unique functionality for parsing. creating and editing of these message.
13
 */
14
15
/**
16
 * \namespace pcpp
17
 * \brief The main namespace for the PcapPlusPlus lib
18
 */
19
namespace pcpp
20
{
21
22
/**
23
 * @class BgpLayer
24
 * Represents Border Gateway Protocol (BGP) v4 protocol layer. This is an abstract class that cannot be instantiated,
25
 * and contains functionality which is common to all BGP message types.
26
 */
27
class BgpLayer : public Layer
28
{
29
public:
30
31
  /**
32
   * An enum representing BGP message types
33
   */
34
  enum BgpMessageType
35
  {
36
    /** BGP OPEN message */
37
    Open = 1,
38
    /** BGP UPDATE message */
39
    Update = 2,
40
    /** BGP NOTIFICATION message */
41
    Notification = 3,
42
    /** BGP KEEPALIVE message */
43
    Keepalive = 4,
44
    /** BGP ROUTE-REFRESH message */
45
    RouteRefresh = 5,
46
  };
47
48
  /**
49
   * @struct bgp_common_header
50
   * Represents the common fields of a BGP 4 message
51
   */
52
  #pragma pack(push, 1)
53
  struct bgp_common_header
54
  {
55
    /** 16-octet marker */
56
    uint8_t marker[16];
57
    /** Total length of the message, including the header */
58
    uint16_t length;
59
    /** BGP message type */
60
    uint8_t messageType;
61
  };
62
  #pragma pack(pop)
63
64
  /**
65
   * @return BGP message type
66
   */
67
  virtual BgpMessageType getBgpMessageType() const = 0;
68
69
  /**
70
   * @return BGP message type as string. Return value can be one of the following:
71
   * "OPEN", "UPDATE", "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH", "Unknown"
72
   */
73
  std::string getMessageTypeAsString() const;
74
75
  /**
76
   * A static method that checks whether a source or dest port match those associated with the BGP protocol
77
   * @param[in] portSrc Source port number to check
78
   * @param[in] portDst Dest port number to check
79
   * @return True if the source or dest port match those associated with the BGP protocol
80
   */
81
208k
  static bool isBgpPort(uint16_t portSrc, uint16_t portDst) { return portSrc == 179 || portDst == 179; }
82
83
  /**
84
   * A method that creates a BGP layer from packet raw data
85
   * @param[in] data A pointer to the raw data
86
   * @param[in] dataLen Size of the data in bytes
87
   * @param[in] prevLayer A pointer to the previous layer
88
   * @param[in] packet A pointer to the Packet instance where layer will be stored
89
   * @return A newly allocated BGP layer of one of the following types (according to the message type):
90
   * BgpOpenMessageLayer, BgpUpdateMessageLayer, BgpNotificationMessageLayer, BgpKeepaliveMessageLayer,
91
   * BgpRouteRefreshMessageLayer
92
   */
93
  static BgpLayer* parseBgpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
94
95
  // implement abstract methods
96
97
  /**
98
   * @return The size of the BGP message
99
   */
100
  size_t getHeaderLen() const;
101
102
  /**
103
   * Multiple BGP messages can reside in a single packet, and the only layer that can come after a BGP message
104
   * is another BGP message. This method checks for remaining data and parses it as another BGP layer
105
   */
106
  void parseNextLayer();
107
108
  std::string toString() const;
109
110
13.7k
  OsiModelLayer getOsiModelLayer() const { return OsiModelApplicationLayer; }
111
112
  /**
113
   * Calculates the basic BGP fields:
114
   * - Set marker to all ones
115
   * - Set message type value
116
   * - Set message length
117
   */
118
  void computeCalculateFields();
119
120
protected:
121
122
  // protected c'tors, this class cannot be instantiated by users
123
0
  BgpLayer() {}
124
113k
  BgpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = BGP; }
125
126
1.05M
  bgp_common_header* getBasicHeader() const { return (bgp_common_header*)m_Data; }
127
128
  void setBgpFields(size_t messageLen = 0);
129
130
};
131
132
133
134
/**
135
 * @class BgpOpenMessageLayer
136
 * Represents a BGP v4 OPEN message
137
 */
138
class BgpOpenMessageLayer : public BgpLayer
139
{
140
public:
141
142
  /**
143
   * @struct bgp_open_message
144
   * BGP OPEN message structure
145
   */
146
  #pragma pack(push, 1)
147
  typedef struct bgp_open_message : bgp_common_header
148
  {
149
    /** BGP version number */
150
    uint8_t version;
151
    /** Autonomous System number of the sender */
152
    uint16_t myAutonomousSystem;
153
    /** The number of seconds the sender proposes for the value of the Hold Timer */
154
    uint16_t holdTime;
155
    /** BGP Identifier of the sender */
156
    uint32_t bgpId;
157
    /** The total length of the Optional Parameters field */
158
    uint8_t optionalParameterLength;
159
  } bgp_open_message;
160
  #pragma pack(pop)
161
162
  /**
163
   * @struct optional_parameter
164
   * A structure that represents BGP OPEN message optional parameters
165
   */
166
  struct optional_parameter
167
  {
168
    /** Parameter type */
169
    uint8_t type;
170
    /** Parameter length */
171
    uint8_t length;
172
    /** Parameter data */
173
    uint8_t value[32];
174
175
    /**
176
     * A default c'tor that zeroes all data
177
     */
178
64.9k
    optional_parameter() {}
179
180
    /**
181
     * A c'tor that initializes the values of the struct
182
     * @param[in] typeVal Parameter type value
183
     * @param[in] valueAsHexString Parameter data as hex string. The length field will be set accordingly.
184
     * If this parameter is not a valid hex string the data will remain zeroed and length will be also zero
185
     */
186
    optional_parameter(uint8_t typeVal, const std::string& valueAsHexString);
187
  };
188
189
  /**
190
   * A constructor that creates the layer from an existing packet raw data
191
   * @param[in] data A pointer to the raw data
192
   * @param[in] dataLen Size of the data in bytes
193
   * @param[in] prevLayer A pointer to the previous layer
194
   * @param[in] packet A pointer to the Packet instance where layer will be stored in
195
   */
196
16.8k
  BgpOpenMessageLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : BgpLayer(data, dataLen, prevLayer, packet) {}
197
198
  /**
199
   * A c'tor that creates a new BGP OPEN message
200
   * @param[in] myAutonomousSystem The Autonomous System number of the sender
201
   * @param[in] holdTime The number of seconds the sender proposes for the value of the Hold Timer
202
   * @param[in] bgpId The BGP Identifier of the sender
203
   * @param[in] optionalParams A vector of optional parameters. This parameter is optional and if not provided no parameters will be
204
   * set on the message
205
   */
206
  BgpOpenMessageLayer(uint16_t myAutonomousSystem, uint16_t holdTime, const IPv4Address& bgpId,
207
    const std::vector<optional_parameter>& optionalParams = std::vector<optional_parameter>());
208
209
  /**
210
   * Get a pointer to the open message data. Notice this points directly to the data, so any change will modify the actual packet data
211
   * @return A pointer to a bgp_open_message structure containing the data
212
   */
213
33.6k
  bgp_open_message* getOpenMsgHeader() const { return (bgp_open_message*)m_Data; }
214
215
  /**
216
   * @return The BGP identifier as IPv4Address object
217
   */
218
0
  IPv4Address getBgpId() const { return IPv4Address(getOpenMsgHeader()->bgpId); }
219
220
  /**
221
   * Set the BGP identifier
222
   * @param[in] newBgpId BGP identifier to set. If value is not a valid IPv4 address it won't be set
223
   */
224
  void setBgpId(const IPv4Address& newBgpId);
225
226
  /**
227
   * Get a vector of the optional parameters in the message
228
   * @param[out] optionalParameters The vector where the optional parameters will be written to. This method doesn't remove any
229
   * existing data on this vector before pushing data to it
230
   */
231
  void getOptionalParameters(std::vector<optional_parameter>& optionalParameters);
232
233
  /**
234
   * @return The length in [bytes] of the optional parameters data in the message
235
   */
236
  size_t getOptionalParametersLength();
237
238
  /**
239
   * Set optional parameters in the message. This method will override all existing optional parameters currently in the message.
240
   * If the input is an empty vector all optional parameters will be cleared. This method automatically sets the
241
   * bgp_common_header#length and the bgp_open_message#optionalParameterLength fields on the message
242
   * @param[in] optionalParameters A vector of new optional parameters to set in the message
243
   * @return True if all optional parameters were set successfully or false otherwise. In case of an error an appropriate message
244
   * will be printed to log
245
   */
246
  bool setOptionalParameters(const std::vector<optional_parameter>& optionalParameters);
247
248
  /**
249
   * Clear all optional parameters currently in the message. This is equivalent to calling setOptionalParameters() with an empty
250
   * vector as a parameter
251
   * @return True if all optional parameters were successfully cleared or false otherwise. In case of an error an appropriate message
252
   * will be printed to log
253
   */
254
  bool clearOptionalParameters();
255
256
  // implement abstract methods
257
258
15.5k
  BgpMessageType getBgpMessageType() const { return BgpLayer::Open; }
259
260
private:
261
262
  size_t optionalParamsToByteArray(const std::vector<optional_parameter>& optionalParams, uint8_t* resultByteArr, size_t maxByteArrSize);
263
264
};
265
266
267
268
/**
269
 * @class BgpUpdateMessageLayer
270
 * Represents a BGP v4 UPDATE message
271
 */
272
class BgpUpdateMessageLayer : public BgpLayer
273
{
274
public:
275
276
  /**
277
   * @struct prefix_and_ip
278
   * A structure that contains IPv4 address and IP address mask (prefix) information.
279
   * It's used to represent BGP Withdrawn Routes and Network Layer Reachability Information (NLRI)
280
   */
281
  struct prefix_and_ip
282
  {
283
    /** IPv4 address mask, must contain one of the values: 8, 16, 24, 32 */
284
    uint8_t prefix;
285
    /** IPv4 address */
286
    IPv4Address ipAddr;
287
288
    /**
289
     * A default c'tor that zeroes all data
290
     */
291
11.0k
    prefix_and_ip(): prefix(0), ipAddr(IPv4Address::Zero) {}
292
293
    /**
294
     * A c'tor that initializes the values of the struct
295
     * @param[in] prefixVal IPv4 address mask value
296
     * @param[in] ipAddrVal IPv4 address
297
     */
298
40.0k
    prefix_and_ip(uint8_t prefixVal, const std::string& ipAddrVal): prefix(prefixVal), ipAddr(ipAddrVal) {}
299
  };
300
301
302
  /**
303
   * @struct path_attribute
304
   * A structure that represents BGP OPEN message Path Attributes information
305
   */
306
  struct path_attribute
307
  {
308
    /** Path attribute flags */
309
    uint8_t flags;
310
    /** Path attribute type */
311
    uint8_t type;
312
    /** Path attribute length */
313
    uint8_t length;
314
    /** Path attribute data. Max supported data length is 32 bytes */
315
    uint8_t data[32];
316
317
    /**
318
     * A default c'tor that zeroes all data
319
     */
320
27.0k
    path_attribute() {}
321
322
    /**
323
     * A c'tor that initializes the values of the struct
324
     * @param[in] flagsVal Path attribute flags value
325
     * @param[in] typeVal Path attribute type value
326
     * @param[in] dataAsHexString Path attribute data as hex string. The path_attribute#length field will be set accordingly.
327
     * If this parameter is not a valid hex string the data will remain zeroed and length will be also set to zero
328
     */
329
    path_attribute(uint8_t flagsVal, uint8_t typeVal, const std::string& dataAsHexString);
330
  };
331
332
  /**
333
   * A constructor that creates the layer from an existing packet raw data
334
   * @param[in] data A pointer to the raw data
335
   * @param[in] dataLen Size of the data in bytes
336
   * @param[in] prevLayer A pointer to the previous layer
337
   * @param[in] packet A pointer to the Packet instance where layer will be stored in
338
   */
339
87.2k
  BgpUpdateMessageLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : BgpLayer(data, dataLen, prevLayer, packet) {}
340
341
  /**
342
  * A static method that takes a byte array and detects whether it is a BgpUpdateMessage
343
  * @param[in] data A byte array
344
  * @param[in] dataSize The byte array size (in bytes)
345
  * @return True if the data looks like a valid BgpUpdateMessage layer
346
  */
347
  static bool isDataValid(const uint8_t *data, size_t dataSize);
348
349
  /**
350
   * A c'tor that creates a new BGP UPDATE message
351
   * @param[in] withdrawnRoutes A vector of withdrawn routes data. If left empty (which is the default value) no withdrawn route information will be written to the message
352
   * @param[in] pathAttributes A vector of path attributes data. If left empty (which is the default value) no path attribute information will be written to the message
353
   * @param[in] nlri A vector of network layer reachability data. If left empty (which is the default value) no reachability information will be written to the message
354
   */
355
  explicit BgpUpdateMessageLayer(
356
    const std::vector<prefix_and_ip>& withdrawnRoutes = std::vector<prefix_and_ip>(),
357
    const std::vector<path_attribute>& pathAttributes = std::vector<path_attribute>(),
358
    const std::vector<prefix_and_ip>& nlri = std::vector<prefix_and_ip>());
359
360
  /**
361
   * Get a pointer to the basic BGP message data. Notice this points directly to the data, so any change will modify the actual packet data
362
   * @return A pointer to a bgp_common_header structure containing the data
363
   */
364
0
  bgp_common_header* getBasicMsgHeader() const { return (bgp_common_header*)m_Data; }
365
366
  /**
367
   * @return The size in [bytes] of the Withdrawn Routes data
368
   */
369
  size_t getWithdrawnRoutesLength() const;
370
371
  /**
372
   * Get a vector of the Withdrawn Routes currently in the message
373
   * @param[out] withdrawnRoutes A reference to a vector the Withdrawn Routes data will be written to
374
   */
375
  void getWithdrawnRoutes(std::vector<prefix_and_ip>& withdrawnRoutes);
376
377
  /**
378
   * Set Withdrawn Routes in this message. This method will override any existing Withdrawn Routes in the message.
379
   * If the input is an empty vector all Withdrawn Routes will be removed. This method automatically sets the
380
   * bgp_common_header#length and the Withdrawn Routes length fields in the message
381
   * @param[in] withdrawnRoutes New Withdrawn Routes to set in the message
382
   * @return True if all Withdrawn Routes were set successfully or false otherwise. In case of an error an appropriate message
383
   * will be printed to log
384
   */
385
  bool setWithdrawnRoutes(const std::vector<prefix_and_ip>& withdrawnRoutes);
386
387
  /**
388
   * Clear all Withdrawn Routes data currently in the message. This is equivalent to calling setWithdrawnRoutes() with an empty
389
   * vector as a parameter
390
   * @return True if all Withdrawn Routes were successfully cleared or false otherwise. In case of an error an appropriate message
391
   * will be printed to log
392
   */
393
  bool clearWithdrawnRoutes();
394
395
  /**
396
   * @return The size in [bytes] of the Path Attributes data
397
   */
398
  size_t getPathAttributesLength() const;
399
400
  /**
401
   * Get a vector of the Path Attributes currently in the message
402
   * @param[out] pathAttributes A reference to a vector the Path Attributes data will be written to
403
   */
404
  void getPathAttributes(std::vector<path_attribute>& pathAttributes);
405
406
  /**
407
   * Set Path Attributes in this message. This method will override any existing Path Attributes in the message.
408
   * If the input is an empty vector all Path Attributes will be removed. This method automatically sets the
409
   * bgp_common_header#length and the Path Attributes length fields in the message
410
   * @param[in] pathAttributes New Path Attributes to set in the message
411
   * @return True if all Path Attributes were set successfully or false otherwise. In case of an error an appropriate message
412
   * will be printed to log
413
   */
414
  bool setPathAttributes(const std::vector<path_attribute>& pathAttributes);
415
416
  /**
417
   * Clear all Path Attributes data currently in the message. This is equivalent to calling setPathAttributes() with an empty
418
   * vector as a parameter
419
   * @return True if all Path Attributes were successfully cleared or false otherwise. In case of an error an appropriate message
420
   * will be printed to log
421
   */
422
  bool clearPathAttributes();
423
424
  /**
425
   * @return The size in [bytes] of the Network Layer Reachability Info
426
   */
427
  size_t getNetworkLayerReachabilityInfoLength() const;
428
429
  /**
430
   * Get a vector of the Network Layer Reachability Info currently in the message
431
   * @param[out] nlri A reference to a vector the NLRI data will be written to
432
   */
433
  void getNetworkLayerReachabilityInfo(std::vector<prefix_and_ip>& nlri);
434
435
  /**
436
   * Set NLRI data in this message. This method will override any existing NLRI data in the message.
437
   * If the input is an empty vector all NLRI data will be removed. This method automatically sets the
438
   * bgp_common_header#length field in the message
439
   * @param[in] nlri New NLRI data to set in the message
440
   * @return True if all NLRI data was set successfully or false otherwise. In case of an error an appropriate message
441
   * will be printed to log
442
   */
443
  bool setNetworkLayerReachabilityInfo(const std::vector<prefix_and_ip>& nlri);
444
445
  /**
446
   * Clear all NLRI data currently in the message. This is equivalent to calling setNetworkLayerReachabilityInfo() with an empty
447
   * vector as a parameter
448
   * @return True if all NLRI were successfully cleared or false otherwise. In case of an error an appropriate message
449
   * will be printed to log
450
   */
451
  bool clearNetworkLayerReachabilityInfo();
452
453
  // implement abstract methods
454
455
32.0k
  BgpMessageType getBgpMessageType() const { return BgpLayer::Update; }
456
457
private:
458
459
  void parsePrefixAndIPData(uint8_t* dataPtr, size_t dataLen, std::vector<prefix_and_ip>& result);
460
461
  size_t prefixAndIPDataToByteArray(const std::vector<prefix_and_ip>& prefixAndIpData, uint8_t* resultByteArr, size_t maxByteArrSize);
462
463
  size_t pathAttributesToByteArray(const std::vector<path_attribute>& pathAttributes, uint8_t* resultByteArr, size_t maxByteArrSize);
464
465
};
466
467
468
469
/**
470
 * @class BgpNotificationMessageLayer
471
 * Represents a BGP v4 NOTIFICATION message
472
 */
473
class BgpNotificationMessageLayer : public BgpLayer
474
{
475
public:
476
477
  /**
478
   * @struct bgp_notification_message
479
   * BGP NOTIFICATION message structure
480
   */
481
  #pragma pack(push, 1)
482
  typedef struct bgp_notification_message : bgp_common_header
483
  {
484
    /** BGP notification error code */
485
    uint8_t errorCode;
486
    /** BGP notification error sub-code */
487
    uint8_t errorSubCode;
488
  } bgp_notification_message;
489
  #pragma pack(pop)
490
491
  /**
492
   * A constructor that creates the layer from an existing packet raw data
493
   * @param[in] data A pointer to the raw data
494
   * @param[in] dataLen Size of the data in bytes
495
   * @param[in] prevLayer A pointer to the previous layer
496
   * @param[in] packet A pointer to the Packet instance where layer will be stored in
497
   */
498
3.21k
  BgpNotificationMessageLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : BgpLayer(data, dataLen, prevLayer, packet) {}
499
500
  /**
501
   * A c'tor that creates a new BGP NOTIFICATION message
502
   * @param[in] errorCode BGP notification error code
503
   * @param[in] errorSubCode BGP notification error sub code
504
   */
505
  BgpNotificationMessageLayer(uint8_t errorCode, uint8_t errorSubCode);
506
507
  /**
508
   * A c'tor that creates a new BGP Notification message
509
   * @param[in] errorCode BGP notification error code
510
   * @param[in] errorSubCode BGP notification error sub code
511
   * @param[in] notificationData A byte array that contains the notification data
512
   * @param[in] notificationDataLen The size of the byte array that contains the notification data
513
   */
514
  BgpNotificationMessageLayer(uint8_t errorCode, uint8_t errorSubCode, const uint8_t* notificationData, size_t notificationDataLen);
515
516
  /**
517
   * A c'tor that creates a new BGP Notification message
518
   * @param[in] errorCode BGP notification error code
519
   * @param[in] errorSubCode BGP notification error sub code
520
   * @param[in] notificationData A hex string that contains the notification data. This string will be converted to a byte array that will be
521
   * added to the message. If the input isn't a valid hex string notification data will remain empty and an error will be printed to log
522
   */
523
  BgpNotificationMessageLayer(uint8_t errorCode, uint8_t errorSubCode, const std::string& notificationData);
524
525
  /**
526
   * Get a pointer to the notification message data. Notice this points directly to the data, so any change will modify the actual packet data
527
   * @return A pointer to a bgp_notification_message structure containing the data
528
   */
529
0
  bgp_notification_message* getNotificationMsgHeader() const { return (bgp_notification_message*)m_Data; }
530
531
  /**
532
   * @return The size in [bytes] of the notification data. Notification data is a variable-length field used to diagnose the reason for
533
   * the BGP NOTIFICATION
534
   */
535
  size_t getNotificationDataLen() const;
536
537
  /**
538
   * @return A pointer to the notification data. Notification data is a variable-length field used to diagnose the reason for
539
   * the BGP NOTIFICATION
540
   */
541
  uint8_t* getNotificationData() const;
542
543
  /**
544
   * @return A hex string which represents the notification data. Notification data is a variable-length field used to diagnose the reason for
545
   * the BGP NOTIFICATION
546
   */
547
  std::string getNotificationDataAsHexString() const;
548
549
  /**
550
   * Set the notification data. This method will extend or shorten the existing layer to include the new notification data.
551
   * If newNotificationData is NULL or newNotificationDataLen is zero then notification data will be set to none.
552
   * @param[in] newNotificationData A byte array containing the new notification data
553
   * @param[in] newNotificationDataLen The size of the byte array
554
   * @return True if notification data was set successfully or false if any error occurred. In case of an error an appropriate
555
   * error message will be printed to log
556
   */
557
  bool setNotificationData(const uint8_t* newNotificationData, size_t newNotificationDataLen);
558
559
  /**
560
   * Set the notification data. This method will extend or shorten the existing layer to include the new notification data.
561
   * If newNotificationDataAsHexString is an empty string then notification data will be set to none.
562
   * @param[in] newNotificationDataAsHexString A hex string representing the new notification data. If the string is not a valid hex string
563
   * no data will be changed and an error will be returned
564
   * @return True if notification data was set successfully or false if any error occurred or if the string is not a valid hex string.
565
   * In case of an error an appropriate error message will be printed to log
566
   */
567
  bool setNotificationData(const std::string& newNotificationDataAsHexString);
568
569
  // implement abstract methods
570
571
2.50k
  BgpMessageType getBgpMessageType() const { return BgpLayer::Notification; }
572
573
private:
574
575
  void initMessageData(uint8_t errorCode, uint8_t errorSubCode, const uint8_t* notificationData, size_t notificationDataLen);
576
577
};
578
579
580
581
/**
582
 * @class BgpKeepaliveMessageLayer
583
 * Represents a BGP v4 KEEPALIVE message
584
 */
585
class BgpKeepaliveMessageLayer : public BgpLayer
586
{
587
public:
588
589
  /**
590
   * @typedef bgp_keepalive_message
591
   * BGP KEEPALIVE message structure
592
   */
593
  typedef bgp_common_header bgp_keepalive_message;
594
595
  /**
596
   * A constructor that creates the layer from an existing packet raw data
597
   * @param[in] data A pointer to the raw data
598
   * @param[in] dataLen Size of the data in bytes
599
   * @param[in] prevLayer A pointer to the previous layer
600
   * @param[in] packet A pointer to the Packet instance where layer will be stored in
601
   */
602
4.67k
  BgpKeepaliveMessageLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : BgpLayer(data, dataLen, prevLayer, packet) {}
603
604
  /**
605
   * A c'tor that creates a new BGP KEEPALIVE message
606
   */
607
  BgpKeepaliveMessageLayer();
608
609
  /**
610
   * Get a pointer to the KeepAlive message data. Notice this points directly to the data, so any change will modify the actual packet data
611
   * @return A pointer to a bgp_keepalive_message structure containing the data
612
   */
613
0
  bgp_keepalive_message* getKeepaliveHeader() const { return (bgp_keepalive_message*)getBasicHeader(); }
614
615
  // implement abstract methods
616
617
3.68k
  BgpMessageType getBgpMessageType() const { return BgpLayer::Keepalive; }
618
619
};
620
621
622
623
/**
624
 * @class BgpRouteRefreshMessageLayer
625
 * Represents a BGP v4 ROUTE-REFRESH message
626
 */
627
class BgpRouteRefreshMessageLayer : public BgpLayer
628
{
629
public:
630
631
  /**
632
   * @struct bgp_route_refresh_message
633
   * BGP ROUTE-REFRESH message structure
634
   */
635
  #pragma pack(push, 1)
636
  typedef struct bgp_route_refresh_message : bgp_common_header
637
  {
638
    /** Address Family Identifier */
639
    uint16_t afi;
640
    /** Reserved field */
641
    uint8_t reserved;
642
    /** Subsequent Address Family Identifier */
643
    uint8_t safi;
644
  } bgp_route_refresh_message;
645
  #pragma pack(pop)
646
647
  /**
648
   * A constructor that creates the layer from an existing packet raw data
649
   * @param[in] data A pointer to the raw data
650
   * @param[in] dataLen Size of the data in bytes
651
   * @param[in] prevLayer A pointer to the previous layer
652
   * @param[in] packet A pointer to the Packet instance where layer will be stored in
653
   */
654
1.30k
  BgpRouteRefreshMessageLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : BgpLayer(data, dataLen, prevLayer, packet) {}
655
656
  /**
657
   * A c'tor that creates a new BGP ROUTE-REFRESH message
658
   * @param[in] afi The Address Family Identifier (AFI) value to set in the message
659
   * @param[in] safi The Subsequent Address Family Identifier (SAFI) value to set in the message
660
   */
661
  BgpRouteRefreshMessageLayer(uint16_t afi, uint8_t safi);
662
663
  /**
664
   * Get a pointer to the ROUTE-REFRESH message data. Notice this points directly to the data, so any change will modify the actual packet data
665
   * @return A pointer to a bgp_route_refresh_message structure containing the data
666
   */
667
0
  bgp_route_refresh_message* getRouteRefreshHeader() const { return (bgp_route_refresh_message*)getBasicHeader(); }
668
669
  // implement abstract methods
670
671
1.02k
  BgpMessageType getBgpMessageType() const { return BgpLayer::RouteRefresh; }
672
673
};
674
675
}