52 static_assert(
sizeof(
bgp_common_header) == 19,
"bgp_common_header size is not 19 bytes");
65 static bool isBgpPort(uint16_t portSrc, uint16_t portDst)
67 return portSrc == 179 || portDst == 179;
107 :
Layer(data, dataLen, prevLayer, packet,
BGP)
110 bgp_common_header* getBasicHeader()
const
112 return reinterpret_cast<bgp_common_header*
>(m_Data);
115 void setBgpFields(
size_t messageLen = 0);
117 bool extendLayer(
int offsetInLayer,
size_t numOfBytesToExtend)
override;
119 bool shortenLayer(
int offsetInLayer,
size_t numOfBytesToShorten)
override;
127 #pragma pack(push, 1)
174 :
BgpLayer(data, dataLen, prevLayer, packet)
184 const std::vector<optional_parameter>& optionalParams = std::vector<optional_parameter>());
235 size_t optionalParamsToByteArray(
const std::vector<optional_parameter>& optionalParams, uint8_t* resultByteArr,
236 size_t maxByteArrSize);
289 path_attribute(uint8_t flagsVal, uint8_t typeVal,
const std::string& dataAsHexString);
298 :
BgpLayer(data, dataLen, prevLayer, packet)
315 const std::vector<prefix_and_ip>& withdrawnRoutes = std::vector<prefix_and_ip>(),
316 const std::vector<path_attribute>& pathAttributes = std::vector<path_attribute>(),
317 const std::vector<prefix_and_ip>& nlri = std::vector<prefix_and_ip>());
398 void parsePrefixAndIPData(uint8_t* dataPtr,
size_t dataLen, std::vector<prefix_and_ip>& result);
400 size_t prefixAndIPDataToByteArray(
const std::vector<prefix_and_ip>& prefixAndIpData, uint8_t* resultByteArr,
401 size_t maxByteArrSize);
403 size_t pathAttributesToByteArray(
const std::vector<path_attribute>& pathAttributes, uint8_t* resultByteArr,
404 size_t maxByteArrSize);
412 #pragma pack(push, 1)
430 :
BgpLayer(data, dataLen, prevLayer, packet)
444 size_t notificationDataLen);
500 void initMessageData(uint8_t errorCode, uint8_t errorSubCode,
const uint8_t* notificationData,
501 size_t notificationDataLen);
519 :
BgpLayer(data, dataLen, prevLayer, packet)
546 #pragma pack(push, 1)
566 :
BgpLayer(data, dataLen, prevLayer, packet)
Definition: BgpLayer.h:507
bgp_common_header bgp_keepalive_message
Definition: BgpLayer.h:511
BgpMessageType getBgpMessageType() const override
Definition: BgpLayer.h:535
BgpKeepaliveMessageLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: BgpLayer.h:518
bgp_keepalive_message * getKeepaliveHeader() const
Definition: BgpLayer.h:528
BgpKeepaliveMessageLayer()
A c'tor that creates a new BGP KEEPALIVE message.
Definition: BgpLayer.h:22
void computeCalculateFields() override
static bool isBgpPort(uint16_t portSrc, uint16_t portDst)
Definition: BgpLayer.h:65
BgpMessageType
An enum representing BGP message types.
Definition: BgpLayer.h:26
@ RouteRefresh
BGP ROUTE-REFRESH message.
Definition: BgpLayer.h:36
@ Update
BGP UPDATE message.
Definition: BgpLayer.h:30
@ Keepalive
BGP KEEPALIVE message.
Definition: BgpLayer.h:34
@ Notification
BGP NOTIFICATION message.
Definition: BgpLayer.h:32
@ Open
BGP OPEN message.
Definition: BgpLayer.h:28
std::string toString() const override
std::string getMessageTypeAsString() const
OsiModelLayer getOsiModelLayer() const override
Definition: BgpLayer.h:91
size_t getHeaderLen() const override
void parseNextLayer() override
static BgpLayer * parseBgpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
virtual BgpMessageType getBgpMessageType() const =0
Definition: BgpLayer.h:410
BgpNotificationMessageLayer(uint8_t errorCode, uint8_t errorSubCode)
BgpNotificationMessageLayer(uint8_t errorCode, uint8_t errorSubCode, const std::string ¬ificationData)
BgpMessageType getBgpMessageType() const override
Definition: BgpLayer.h:494
bool setNotificationData(const std::string &newNotificationDataAsHexString)
bgp_notification_message * getNotificationMsgHeader() const
Definition: BgpLayer.h:457
std::string getNotificationDataAsHexString() const
bool setNotificationData(const uint8_t *newNotificationData, size_t newNotificationDataLen)
BgpNotificationMessageLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: BgpLayer.h:429
BgpNotificationMessageLayer(uint8_t errorCode, uint8_t errorSubCode, const uint8_t *notificationData, size_t notificationDataLen)
size_t getNotificationDataLen() const
uint8_t * getNotificationData() const
Definition: BgpLayer.h:125
void getOptionalParameters(std::vector< optional_parameter > &optionalParameters)
BgpMessageType getBgpMessageType() const override
Definition: BgpLayer.h:229
BgpOpenMessageLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: BgpLayer.h:173
void setBgpId(const IPv4Address &newBgpId)
bool setOptionalParameters(const std::vector< optional_parameter > &optionalParameters)
BgpOpenMessageLayer(uint16_t myAutonomousSystem, uint16_t holdTime, const IPv4Address &bgpId, const std::vector< optional_parameter > &optionalParams=std::vector< optional_parameter >())
bool clearOptionalParameters()
bgp_open_message * getOpenMsgHeader() const
Definition: BgpLayer.h:189
IPv4Address getBgpId() const
Definition: BgpLayer.h:195
size_t getOptionalParametersLength()
Definition: BgpLayer.h:544
BgpRouteRefreshMessageLayer(uint16_t afi, uint8_t safi)
BgpMessageType getBgpMessageType() const override
Definition: BgpLayer.h:584
BgpRouteRefreshMessageLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: BgpLayer.h:565
bgp_route_refresh_message * getRouteRefreshHeader() const
Definition: BgpLayer.h:577
Definition: BgpLayer.h:242
bool clearPathAttributes()
bool clearNetworkLayerReachabilityInfo()
void getPathAttributes(std::vector< path_attribute > &pathAttributes)
BgpMessageType getBgpMessageType() const override
Definition: BgpLayer.h:392
BgpUpdateMessageLayer(const std::vector< prefix_and_ip > &withdrawnRoutes=std::vector< prefix_and_ip >(), const std::vector< path_attribute > &pathAttributes=std::vector< path_attribute >(), const std::vector< prefix_and_ip > &nlri=std::vector< prefix_and_ip >())
static bool isDataValid(const uint8_t *data, size_t dataSize)
void getWithdrawnRoutes(std::vector< prefix_and_ip > &withdrawnRoutes)
bool setPathAttributes(const std::vector< path_attribute > &pathAttributes)
bool setNetworkLayerReachabilityInfo(const std::vector< prefix_and_ip > &nlri)
size_t getNetworkLayerReachabilityInfoLength() const
bool setWithdrawnRoutes(const std::vector< prefix_and_ip > &withdrawnRoutes)
size_t getPathAttributesLength() const
bool clearWithdrawnRoutes()
size_t getWithdrawnRoutesLength() const
bgp_common_header * getBasicMsgHeader() const
Definition: BgpLayer.h:322
void getNetworkLayerReachabilityInfo(std::vector< prefix_and_ip > &nlri)
BgpUpdateMessageLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: BgpLayer.h:297
Definition: IpAddress.h:30
const ProtocolType BGP
Border Gateway Protocol (BGP) version 4 protocol.
Definition: ProtocolType.h:165
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:261
@ OsiModelApplicationLayer
Application layer (layer 7)
Definition: ProtocolType.h:275
Definition: BgpLayer.h:416
uint8_t errorSubCode
BGP notification error sub-code.
Definition: BgpLayer.h:420
uint8_t errorCode
BGP notification error code.
Definition: BgpLayer.h:418
Definition: BgpLayer.h:131
uint16_t holdTime
The number of seconds the sender proposes for the value of the Hold Timer.
Definition: BgpLayer.h:137
uint8_t version
BGP version number.
Definition: BgpLayer.h:133
uint32_t bgpId
BGP Identifier of the sender.
Definition: BgpLayer.h:139
uint16_t myAutonomousSystem
Autonomous System number of the sender.
Definition: BgpLayer.h:135
uint8_t optionalParameterLength
The total length of the Optional Parameters field.
Definition: BgpLayer.h:141
Definition: BgpLayer.h:148
optional_parameter(uint8_t typeVal, const std::string &valueAsHexString)
uint8_t type
Parameter type.
Definition: BgpLayer.h:150
uint8_t length
Parameter length.
Definition: BgpLayer.h:152
optional_parameter()
A default c'tor that zeroes all data.
Definition: BgpLayer.h:158
uint8_t value[32]
Parameter data.
Definition: BgpLayer.h:154
Definition: BgpLayer.h:550
uint8_t safi
Subsequent Address Family Identifier.
Definition: BgpLayer.h:556
uint16_t afi
Address Family Identifier.
Definition: BgpLayer.h:552
uint8_t reserved
Reserved field.
Definition: BgpLayer.h:554
Definition: BgpLayer.h:268
path_attribute()
A default c'tor that zeroes all data.
Definition: BgpLayer.h:280
uint8_t type
Path attribute type.
Definition: BgpLayer.h:272
uint8_t flags
Path attribute flags.
Definition: BgpLayer.h:270
uint8_t data[32]
Path attribute data. Max supported data length is 32 bytes.
Definition: BgpLayer.h:276
path_attribute(uint8_t flagsVal, uint8_t typeVal, const std::string &dataAsHexString)
uint8_t length
Path attribute length.
Definition: BgpLayer.h:274
Definition: BgpLayer.h:248
uint8_t prefix
IPv4 address mask, must contain one of the values: 8, 16, 24, 32.
Definition: BgpLayer.h:250
prefix_and_ip()
A default c'tor that zeroes all data.
Definition: BgpLayer.h:255
prefix_and_ip(uint8_t prefixVal, const std::string &ipAddrVal)
Definition: BgpLayer.h:261
IPv4Address ipAddr
IPv4 address.
Definition: BgpLayer.h:252