Coverage Report

Created: 2023-01-17 06:15

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