PcapPlusPlus  Next
SomeIpSdLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "IpAddress.h"
4 #include "Layer.h"
5 #include "SomeIpLayer.h"
6 #include <cstring>
7 #include <iterator>
8 #include <unordered_map>
9 #include <memory>
10 #include <stdexcept>
11 #include <vector>
12 
14 
19 namespace pcpp
20 {
24  enum SomeIpSdProtocolType : uint8_t
25  {
27  SD_TCP = 0x06,
29  SD_UDP = 0x11
30  };
31 
32  class SomeIpSdLayer;
33 
39  {
40  public:
41  friend class SomeIpSdLayer;
42 
46  enum class OptionType : uint8_t
47  {
49  Unknown = 0x00,
51  ConfigurationString = 0x01,
53  LoadBalancing = 0x02,
55  IPv4Endpoint = 0x04,
57  IPv6Endpoint = 0x06,
59  IPv4Multicast = 0x14,
61  IPv6Multicast = 0x16,
63  IPv4SdEndpoint = 0x24,
65  IPv6SdEndpoint = 0x26
66  };
67 
72 #pragma pack(push, 1)
74  {
76  uint16_t length;
78  uint8_t type;
80  uint8_t reserved;
81  };
82 #pragma pack(pop)
83 
87  virtual ~SomeIpSdOption();
88 
94 
99  size_t getLength() const
100  {
101  return m_DataLen;
102  }
103 
108  uint8_t* getDataPtr() const;
109 
115 
116  protected:
117  const IDataContainer* m_DataContainer;
118  size_t m_Offset;
119  uint8_t* m_ShadowData;
120  size_t m_DataLen;
121 
122  SomeIpSdOption() : m_DataContainer(nullptr), m_Offset(0), m_ShadowData(nullptr), m_DataLen(0)
123  {}
124 
125  SomeIpSdOption(const IDataContainer* dataContainer, size_t offset)
126  : m_DataContainer(dataContainer), m_Offset(offset), m_ShadowData(nullptr), m_DataLen(0)
127  {}
128 
129  void initStdFields(OptionType type);
130 
131  SomeIpSdOption(const SomeIpSdOption&) = delete;
132  SomeIpSdOption& operator=(const SomeIpSdOption&) = delete;
133  };
134 
140  {
141  public:
142  friend class SomeIpSdLayer;
143 
148  {
155  };
156 
164  SomeIpSdIPv4Option(IPv4OptionType type, IPv4Address ipAddress, uint16_t port, SomeIpSdProtocolType l4Protocol);
165 
171  SomeIpSdIPv4Option(const IDataContainer* dataContainer, size_t offset);
172 
178 
183  uint16_t getPort() const;
184 
190 
191  private:
196 #pragma pack(push, 1)
197  struct someipsdhdroptionsipv4 : someipsdhdroptionsbase
198  {
199  /* IPv4-Address field */
200  uint32_t ipv4Address;
201  /* Reserved */
202  // cppcheck-suppress duplInheritedMember
203  uint8_t reserved;
204  /* Layer 4 Protocol field (L4-Proto) - Either UDP or TCP */
205  SomeIpSdProtocolType l4Protocol;
206  /* Port number of UDP or TCP */
207  uint16_t portNumber;
208  };
209 #pragma pack(pop)
210  };
211 
217  {
218  public:
219  friend class SomeIpSdLayer;
220 
225  {
232  };
233 
241  SomeIpSdIPv6Option(IPv6OptionType type, IPv6Address ipAddress, uint16_t port, SomeIpSdProtocolType l4Protocol);
242 
248  SomeIpSdIPv6Option(const IDataContainer* dataContainer, size_t offset);
249 
255 
260  uint16_t getPort() const;
261 
267 
268  private:
273 #pragma pack(push, 1)
274  struct someipsdhdroptionsipv6 : someipsdhdroptionsbase
275  {
276  /* IPv6-Address field */
277  uint8_t ipv6Address[16];
278  /* Reserved */
279  // cppcheck-suppress duplInheritedMember
280  uint8_t reserved;
281  /* Layer 4 Protocol field (L4-Proto) - Either UDP or TCP */
282  SomeIpSdProtocolType l4Protocol;
283  /* Port number of UDP or TCP */
284  uint16_t portNumber;
285  };
286 #pragma pack(pop)
287  };
288 
294  {
295  public:
296  friend class SomeIpSdLayer;
297 
302  explicit SomeIpSdConfigurationOption(const std::string& configurationString);
303 
309  SomeIpSdConfigurationOption(const IDataContainer* dataContainer, size_t offset);
310 
315  std::string getConfigurationString() const;
316  };
317 
323  {
324  public:
325  friend class SomeIpSdLayer;
326 
332  SomeIpSdLoadBalancingOption(uint16_t priority, uint16_t weight);
333 
339  SomeIpSdLoadBalancingOption(const IDataContainer* dataContainer, size_t offset);
340 
345  uint16_t getPriority() const;
346 
351  uint16_t getWeight() const;
352 
353  private:
358 #pragma pack(push, 1)
359  struct someipsdhdroptionsload : someipsdhdroptionsbase
360  {
361  /* Priority field */
362  uint16_t priority;
363  /* Weight field */
364  uint16_t weight;
365  };
366 #pragma pack(pop)
367  };
368 
374  {
375  public:
376  friend class SomeIpSdLayer;
377 
381  enum class EntryType : uint8_t
382  {
384  FindService,
386  OfferService,
399  };
400 
405 #pragma pack(push, 1)
407  {
409  uint8_t type;
414 #if (BYTE_ORDER == LITTLE_ENDIAN)
415  uint8_t
417  nrOpt2 : 4,
419  nrOpt1 : 4;
420 #else
421  uint8_t
423  nrOpt1 : 4,
425  nrOpt2 : 4;
426 #endif
428  uint16_t serviceID;
430  uint16_t instanceID;
434  uint32_t data;
435  };
436 #pragma pack(pop)
437 
447  SomeIpSdEntry(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL,
448  uint32_t minorVersion);
449 
460  SomeIpSdEntry(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL,
461  uint8_t counter, uint16_t eventGroupID);
462 
468  SomeIpSdEntry(const SomeIpSdLayer* pSomeIpSdLayer, size_t offset);
469 
474 
479  uint8_t* getDataPtr() const;
480 
486 
492  {
493  return m_EntryType;
494  }
495 
500  size_t getLength() const
501  {
502  return sizeof(someipsdhdrentry);
503  }
504 
509  uint32_t getNumOptions() const;
510 
515  uint16_t getServiceId() const;
516 
521  void setServiceId(uint16_t serviceId);
522 
527  uint16_t getInstanceId() const;
528 
533  void setInstanceId(uint16_t instanceId);
534 
539  uint8_t getMajorVersion() const;
540 
545  void setMajorVersion(uint8_t majorVersion);
546 
551  uint32_t getTtl() const;
552 
557  void setTtl(uint32_t ttl);
558 
563  uint32_t getMinorVersion() const;
564 
569  void setMinorVersion(uint32_t minorVersion);
570 
575  uint8_t getCounter() const;
576 
581  void setCounter(uint8_t counter);
582 
587  uint16_t getEventgroupId() const;
588 
593  void setEventgroupId(uint16_t eventgroupID);
594 
595  private:
600  enum class TypeInternal : uint8_t
601  {
603  FindService_Internal = 0x00,
605  OfferService_Internal = 0x01,
607  SubscribeEventgroup_Internal = 0x06,
609  SubscribeEventgroupAck_Internal = 0x07,
610  };
611 
612  EntryType m_EntryType;
613  const SomeIpSdLayer* m_Layer;
614  size_t m_Offset;
615  uint8_t* m_ShadowData;
616 
617  void initStdFields(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL);
618 
619  SomeIpSdEntry(const SomeIpSdEntry&) = delete;
620  SomeIpSdEntry& operator=(const SomeIpSdEntry&) = delete;
621 
622  static const uint32_t SOMEIPSD_HDR_ENTRY_MASK_TTL = 0x00FFFFFF;
623  };
624 
629  class SomeIpSdLayer : public SomeIpLayer
630  {
631  public:
632  friend class SomeIpSdEntry;
633 
634  typedef SomeIpSdEntry* EntryPtr;
635  typedef std::vector<EntryPtr> EntriesVec;
636  typedef SomeIpSdOption* OptionPtr;
637  typedef std::vector<OptionPtr> OptionsVec;
638 
646  SomeIpSdLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
647 
659  SomeIpSdLayer(uint16_t serviceID, uint16_t methodID, uint16_t clientID, uint16_t sessionID,
660  uint8_t interfaceVersion, MsgType type, uint8_t returnCode, uint8_t flags);
661 
665  ~SomeIpSdLayer() override = default;
666 
672  static bool isSomeIpSdPort(uint16_t port)
673  {
674  return port == 30490;
675  }
676 
683  static bool isDataValid(const uint8_t* data, size_t dataLen);
684 
689  uint8_t getFlags() const;
690 
695  void setFlags(uint8_t flags);
696 
701  uint32_t getNumEntries() const;
702 
707  uint32_t getNumOptions() const;
708 
713  const EntriesVec getEntries() const;
714 
719  const OptionsVec getOptions() const;
720 
726  const OptionsVec getOptionsFromEntry(uint32_t index) const;
727 
733  uint32_t addEntry(const SomeIpSdEntry& entry);
734 
743  bool addOptionTo(uint32_t indexEntry, const SomeIpSdOption& option);
744 
748  void computeCalculateFields() override {};
749 
753  std::string toString() const override;
754 
755  private:
760 #pragma pack(push, 1)
761  struct someipsdhdr : someiphdr
762  {
764  uint8_t flags;
766  uint8_t reserved1;
768  uint8_t reserved2;
770  uint8_t reserved3;
771  };
772 #pragma pack(pop)
773 
774  uint32_t m_NumOptions;
775 
776  static bool countOptions(uint32_t& count, const uint8_t* data);
777  uint32_t findOption(const SomeIpSdOption& option);
778  void addOption(const SomeIpSdOption& option);
779  bool addOptionIndex(uint32_t indexEntry, uint32_t indexOffset);
780  OptionPtr parseOption(SomeIpSdOption::OptionType type, size_t offset) const;
781 
782  static size_t getLenEntries(const uint8_t* data);
783  size_t getLenEntries() const;
784  static size_t getLenOptions(const uint8_t* data);
785  size_t getLenOptions() const;
786  void setLenEntries(uint32_t length);
787  void setLenOptions(uint32_t length);
788  };
789 
790 } // namespace pcpp
Definition: Layer.h:23
Definition: IpAddress.h:32
Definition: IpAddress.h:199
Definition: Layer.h:69
Definition: Packet.h:27
Definition: SomeIpLayer.h:20
MsgType
Definition: SomeIpLayer.h:26
Definition: SomeIpSdLayer.h:294
SomeIpSdConfigurationOption(const std::string &configurationString)
SomeIpSdConfigurationOption(const IDataContainer *dataContainer, size_t offset)
std::string getConfigurationString() const
Definition: SomeIpSdLayer.h:374
EntryType getType() const
Definition: SomeIpSdLayer.h:491
uint16_t getEventgroupId() const
size_t getLength() const
Definition: SomeIpSdLayer.h:500
uint8_t * getDataPtr() const
void setMajorVersion(uint8_t majorVersion)
uint32_t getTtl() const
void setCounter(uint8_t counter)
void setEventgroupId(uint16_t eventgroupID)
uint8_t getMajorVersion() const
uint32_t getNumOptions() const
EntryType
Definition: SomeIpSdLayer.h:382
@ SubscribeEventgroupNack
@ SubscribeEventgroup
@ UnknownEntryType
@ StopOfferService
@ StopSubscribeEventgroup
@ SubscribeEventgroupAck
@ OfferService
@ FindService
SomeIpSdEntry(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL, uint8_t counter, uint16_t eventGroupID)
void setMinorVersion(uint32_t minorVersion)
~SomeIpSdEntry()
uint16_t getInstanceId() const
void setInstanceId(uint16_t instanceId)
void setTtl(uint32_t ttl)
uint8_t getCounter() const
void setServiceId(uint16_t serviceId)
SomeIpSdEntry(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL, uint32_t minorVersion)
uint16_t getServiceId() const
SomeIpSdEntry(const SomeIpSdLayer *pSomeIpSdLayer, size_t offset)
uint32_t getMinorVersion() const
someipsdhdrentry * getSomeIpSdEntryHeader() const
Definition: SomeIpSdLayer.h:140
SomeIpSdIPv4Option(IPv4OptionType type, IPv4Address ipAddress, uint16_t port, SomeIpSdProtocolType l4Protocol)
IPv4Address getIpAddress() const
SomeIpSdIPv4Option(const IDataContainer *dataContainer, size_t offset)
IPv4OptionType
Definition: SomeIpSdLayer.h:148
@ IPv4Multicast
Definition: SomeIpSdLayer.h:152
@ IPv4SdEndpoint
Definition: SomeIpSdLayer.h:154
@ IPv4Endpoint
Definition: SomeIpSdLayer.h:150
SomeIpSdProtocolType getProtocol() const
uint16_t getPort() const
Definition: SomeIpSdLayer.h:217
IPv6Address getIpAddress() const
SomeIpSdProtocolType getProtocol() const
uint16_t getPort() const
SomeIpSdIPv6Option(const IDataContainer *dataContainer, size_t offset)
SomeIpSdIPv6Option(IPv6OptionType type, IPv6Address ipAddress, uint16_t port, SomeIpSdProtocolType l4Protocol)
IPv6OptionType
Definition: SomeIpSdLayer.h:225
@ IPv6Multicast
Definition: SomeIpSdLayer.h:229
@ IPv6SdEndpoint
Definition: SomeIpSdLayer.h:231
@ IPv6Endpoint
Definition: SomeIpSdLayer.h:227
Definition: SomeIpSdLayer.h:630
uint32_t addEntry(const SomeIpSdEntry &entry)
const OptionsVec getOptionsFromEntry(uint32_t index) const
std::string toString() const override
bool addOptionTo(uint32_t indexEntry, const SomeIpSdOption &option)
static bool isSomeIpSdPort(uint16_t port)
Definition: SomeIpSdLayer.h:672
SomeIpSdLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
void computeCalculateFields() override
Definition: SomeIpSdLayer.h:748
uint8_t getFlags() const
static bool isDataValid(const uint8_t *data, size_t dataLen)
uint32_t getNumEntries() const
~SomeIpSdLayer() override=default
const OptionsVec getOptions() const
SomeIpSdLayer(uint16_t serviceID, uint16_t methodID, uint16_t clientID, uint16_t sessionID, uint8_t interfaceVersion, MsgType type, uint8_t returnCode, uint8_t flags)
void setFlags(uint8_t flags)
uint32_t getNumOptions() const
const EntriesVec getEntries() const
Definition: SomeIpSdLayer.h:323
SomeIpSdLoadBalancingOption(const IDataContainer *dataContainer, size_t offset)
SomeIpSdLoadBalancingOption(uint16_t priority, uint16_t weight)
Definition: SomeIpSdLayer.h:39
OptionType
Definition: SomeIpSdLayer.h:47
someipsdhdroptionsbase * getSomeIpSdOptionHeader() const
uint8_t * getDataPtr() const
virtual ~SomeIpSdOption()
OptionType getType() const
size_t getLength() const
Definition: SomeIpSdLayer.h:99
The main namespace for the PcapPlusPlus lib.
SomeIpSdProtocolType
Definition: SomeIpSdLayer.h:25
@ SD_UDP
Definition: SomeIpSdLayer.h:29
@ SD_TCP
Definition: SomeIpSdLayer.h:27
Definition: SomeIpLayer.h:65
Definition: SomeIpSdLayer.h:407
uint32_t data
Definition: SomeIpSdLayer.h:434
uint8_t nrOpt2
Definition: SomeIpSdLayer.h:417
uint32_t majorVersion_ttl
Definition: SomeIpSdLayer.h:432
uint8_t type
Definition: SomeIpSdLayer.h:409
uint8_t indexFirstOption
Definition: SomeIpSdLayer.h:411
uint8_t nrOpt1
Definition: SomeIpSdLayer.h:419
uint16_t serviceID
Definition: SomeIpSdLayer.h:428
uint8_t indexSecondOption
Definition: SomeIpSdLayer.h:413
uint16_t instanceID
Definition: SomeIpSdLayer.h:430
Definition: SomeIpSdLayer.h:74
uint8_t reserved
Definition: SomeIpSdLayer.h:80
uint16_t length
Definition: SomeIpSdLayer.h:76
uint8_t type
Definition: SomeIpSdLayer.h:78