PcapPlusPlus  23.09
SomeIpSdLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_SOMEIPSD_LAYER
2 #define PACKETPP_SOMEIPSD_LAYER
3 
4 #include "EndianPortable.h"
5 #include "IpAddress.h"
6 #include "Layer.h"
7 #include "SomeIpLayer.h"
8 #include <cstring>
9 #include <iterator>
10 #include <map>
11 #include <memory>
12 #include <stdexcept>
13 #include <vector>
14 
16 
21 namespace pcpp
22 {
26 enum SomeIpSdProtocolType : uint8_t
27 {
29  SD_TCP = 0x06,
31  SD_UDP = 0x11
32 };
33 
34 class SomeIpSdLayer;
35 
41 {
42 public:
43  friend class SomeIpSdLayer;
44 
48  enum class OptionType : uint8_t
49  {
51  Unknown = 0x00,
53  ConfigurationString = 0x01,
55  LoadBalancing = 0x02,
57  IPv4Endpoint = 0x04,
59  IPv6Endpoint = 0x06,
61  IPv4Multicast = 0x14,
63  IPv6Multicast = 0x16,
65  IPv4SdEndpoint = 0x24,
67  IPv6SdEndpoint = 0x26
68  };
69 
74 #pragma pack(push, 1)
76  {
78  uint16_t length;
80  uint8_t type;
82  uint8_t reserved;
83  };
84 #pragma pack(pop)
85 
89  virtual ~SomeIpSdOption();
90 
95  OptionType getType() const;
96 
101  size_t getLength() const { return m_DataLen; }
102 
107  uint8_t *getDataPtr() const;
108 
114 
115 protected:
116  const IDataContainer *m_DataContainer;
117  size_t m_Offset;
118  uint8_t *m_ShadowData;
119  size_t m_DataLen;
120 
121  SomeIpSdOption() : m_DataContainer(nullptr), m_Offset(0), m_ShadowData(nullptr), m_DataLen(0) {}
122 
123  SomeIpSdOption(const IDataContainer *dataContainer, size_t offset)
124  : m_DataContainer(dataContainer), m_Offset(offset), m_ShadowData(nullptr), m_DataLen(0) {}
125 
126  void initStdFields(OptionType type);
127 
128  SomeIpSdOption(const SomeIpSdOption &) = delete;
129  SomeIpSdOption &operator=(const SomeIpSdOption &) = delete;
130 };
131 
137 {
138 public:
139  friend class SomeIpSdLayer;
140 
145  {
152  };
153 
161  SomeIpSdIPv4Option(IPv4OptionType type, IPv4Address ipAddress, uint16_t port, SomeIpSdProtocolType l4Protocol);
162 
168  SomeIpSdIPv4Option(const IDataContainer *dataContainer, size_t offset);
169 
174  IPv4Address getIpAddress() const;
175 
180  uint16_t getPort() const;
181 
186  SomeIpSdProtocolType getProtocol() const;
187 
188 private:
193 #pragma pack(push, 1)
194  struct someipsdhdroptionsipv4 : someipsdhdroptionsbase
195  {
196  /* IPv4-Address field */
197  uint32_t ipv4Address;
198  /* Reserved */
199  // cppcheck-suppress duplInheritedMember
200  uint8_t reserved;
201  /* Layer 4 Protocol field (L4-Proto) - Either UDP or TCP */
202  SomeIpSdProtocolType l4Protocol;
203  /* Port number of UDP or TCP */
204  uint16_t portNumber;
205  };
206 #pragma pack(pop)
207 };
208 
214 {
215 public:
216  friend class SomeIpSdLayer;
217 
222  {
229  };
230 
238  SomeIpSdIPv6Option(IPv6OptionType type, IPv6Address ipAddress, uint16_t port, SomeIpSdProtocolType l4Protocol);
239 
245  SomeIpSdIPv6Option(const IDataContainer *dataContainer, size_t offset);
246 
251  IPv6Address getIpAddress() const;
252 
257  uint16_t getPort() const;
258 
263  SomeIpSdProtocolType getProtocol() const;
264 
265 private:
270 #pragma pack(push, 1)
271  struct someipsdhdroptionsipv6 : someipsdhdroptionsbase
272  {
273  /* IPv6-Address field */
274  uint8_t ipv6Address[16];
275  /* Reserved */
276  // cppcheck-suppress duplInheritedMember
277  uint8_t reserved;
278  /* Layer 4 Protocol field (L4-Proto) - Either UDP or TCP */
279  SomeIpSdProtocolType l4Protocol;
280  /* Port number of UDP or TCP */
281  uint16_t portNumber;
282  };
283 #pragma pack(pop)
284 };
285 
291 {
292 public:
293  friend class SomeIpSdLayer;
294 
299  explicit SomeIpSdConfigurationOption(const std::string &configurationString);
300 
306  SomeIpSdConfigurationOption(const IDataContainer *dataContainer, size_t offset);
307 
312  std::string getConfigurationString() const;
313 };
314 
320 {
321 public:
322  friend class SomeIpSdLayer;
323 
329  SomeIpSdLoadBalancingOption(uint16_t priority, uint16_t weight);
330 
336  SomeIpSdLoadBalancingOption(const IDataContainer *dataContainer, size_t offset);
337 
342  uint16_t getPriority() const;
343 
348  uint16_t getWeight() const;
349 
350 private:
355 #pragma pack(push, 1)
356  struct someipsdhdroptionsload : someipsdhdroptionsbase
357  {
358  /* Priority field */
359  uint16_t priority;
360  /* Weight field */
361  uint16_t weight;
362  };
363 #pragma pack(pop)
364 };
365 
371 {
372 public:
373  friend class SomeIpSdLayer;
374 
378  enum class EntryType : uint8_t
379  {
381  FindService,
383  OfferService,
385  StopOfferService,
387  SubscribeEventgroup,
389  StopSubscribeEventgroup,
391  SubscribeEventgroupAck,
393  SubscribeEventgroupNack,
395  UnknownEntryType
396  };
397 
402 #pragma pack(push, 1)
404  {
406  uint8_t type;
411 #if (BYTE_ORDER == LITTLE_ENDIAN)
412  uint8_t
414  nrOpt2 : 4,
416  nrOpt1 : 4;
417 #else
418  uint8_t
420  nrOpt1 : 4,
422  nrOpt2 : 4;
423 #endif
424 
425  uint16_t serviceID;
427  uint16_t instanceID;
431  uint32_t data;
432  };
433 #pragma pack(pop)
434 
444  SomeIpSdEntry(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL,
445  uint32_t minorVersion);
446 
457  SomeIpSdEntry(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL,
458  uint8_t counter, uint16_t eventGroupID);
459 
465  SomeIpSdEntry(const SomeIpSdLayer *pSomeIpSdLayer, size_t offset);
466 
470  ~SomeIpSdEntry();
471 
476  uint8_t *getDataPtr() const;
477 
482  someipsdhdrentry *getSomeIpSdEntryHeader() const;
483 
488  EntryType getType() const { return m_EntryType; }
489 
494  size_t getLength() const { return sizeof(someipsdhdrentry); }
495 
500  uint32_t getNumOptions() const;
501 
506  uint16_t getServiceId() const;
507 
512  void setServiceId(uint16_t serviceId);
513 
518  uint16_t getInstanceId() const;
519 
524  void setInstanceId(uint16_t instanceId);
525 
530  uint8_t getMajorVersion() const;
531 
536  void setMajorVersion(uint8_t majorVersion);
537 
542  uint32_t getTtl() const;
543 
548  void setTtl(uint32_t ttl);
549 
554  uint32_t getMinorVersion() const;
555 
560  void setMinorVersion(uint32_t minorVersion);
561 
566  uint8_t getCounter() const;
567 
572  void setCounter(uint8_t counter);
573 
578  uint16_t getEventgroupId() const;
579 
584  void setEventgroupId(uint16_t eventgroupID);
585 
586 private:
591  enum class TypeInternal : uint8_t
592  {
594  FindService_Internal = 0x00,
596  OfferService_Internal = 0x01,
598  SubscribeEventgroup_Internal = 0x06,
600  SubscribeEventgroupAck_Internal = 0x07,
601  };
602 
603  EntryType m_EntryType;
604  const SomeIpSdLayer *m_Layer;
605  size_t m_Offset;
606  uint8_t *m_ShadowData;
607 
608  void initStdFields(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL);
609 
610  SomeIpSdEntry(const SomeIpSdEntry &) = delete;
611  SomeIpSdEntry &operator=(const SomeIpSdEntry &) = delete;
612 
613  static const uint32_t SOMEIPSD_HDR_ENTRY_MASK_TTL = 0x00FFFFFF;
614 };
615 
621 {
622 public:
623  friend class SomeIpSdEntry;
624 
625  typedef SomeIpSdEntry* EntryPtr;
626  typedef std::vector<EntryPtr> EntriesVec;
627  typedef SomeIpSdOption* OptionPtr;
628  typedef std::vector<OptionPtr> OptionsVec;
629 
637  SomeIpSdLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet);
638 
650  SomeIpSdLayer(uint16_t serviceID, uint16_t methodID, uint16_t clientID, uint16_t sessionID,
651  uint8_t interfaceVersion, MsgType type, uint8_t returnCode, uint8_t flags);
652 
657 
663  static bool isSomeIpSdPort(uint16_t port) { return port == 30490; }
664 
671  static bool isDataValid(const uint8_t* data, size_t dataLen);
672 
677  uint8_t getFlags() const;
678 
683  void setFlags(uint8_t flags);
684 
689  uint32_t getNumEntries() const;
690 
695  uint32_t getNumOptions() const;
696 
701  const EntriesVec getEntries() const;
702 
707  const OptionsVec getOptions() const;
708 
714  const OptionsVec getOptionsFromEntry(uint32_t index) const;
715 
721  uint32_t addEntry(const SomeIpSdEntry &entry);
722 
731  bool addOptionTo(uint32_t indexEntry, const SomeIpSdOption &option);
732 
737 
741  std::string toString() const;
742 
743 private:
748 #pragma pack(push, 1)
749  struct someipsdhdr : someiphdr
750  {
752  uint8_t flags;
754  uint8_t reserved1;
756  uint8_t reserved2;
758  uint8_t reserved3;
759  };
760 #pragma pack(pop)
761 
762  uint32_t m_NumOptions;
763 
764  uint32_t countOptions();
765  uint32_t findOption(const SomeIpSdOption &option);
766  void addOption(const SomeIpSdOption &option);
767  bool addOptionIndex(uint32_t indexEntry, uint32_t indexOffset);
768  OptionPtr parseOption(SomeIpSdOption::OptionType type, size_t offset) const;
769 
770  static size_t getLenEntries(const uint8_t* data);
771  size_t getLenEntries() const;
772  size_t getLenOptions() const;
773  void setLenEntries(uint32_t length);
774  void setLenOptions(uint32_t length);
775 };
776 
777 } // namespace pcpp
778 #endif /* PACKETPP_SOMEIPSD_LAYER */
The main namespace for the PcapPlusPlus lib.
Definition: SomeIpSdLayer.h:149
uint8_t type
Definition: SomeIpSdLayer.h:80
Definition: SomeIpSdLayer.h:213
uint8_t indexFirstOption
Definition: SomeIpSdLayer.h:408
uint32_t data
Definition: SomeIpSdLayer.h:431
~SomeIpSdLayer()
Definition: SomeIpSdLayer.h:656
uint16_t instanceID
Definition: SomeIpSdLayer.h:427
void computeCalculateFields()
Definition: SomeIpSdLayer.h:736
Definition: Layer.h:70
Definition: SomeIpSdLayer.h:29
uint16_t length
Definition: SomeIpSdLayer.h:78
Definition: Packet.h:26
Definition: SomeIpSdLayer.h:147
uint16_t serviceID
Definition: SomeIpSdLayer.h:425
uint32_t majorVersion_ttl
Definition: SomeIpSdLayer.h:429
Definition: SomeIpSdLayer.h:403
static bool isSomeIpSdPort(uint16_t port)
Definition: SomeIpSdLayer.h:663
Definition: SomeIpSdLayer.h:224
size_t getLength() const
Definition: SomeIpSdLayer.h:101
Definition: SomeIpSdLayer.h:228
Definition: SomeIpSdLayer.h:226
uint8_t reserved
Definition: SomeIpSdLayer.h:82
uint8_t * getDataPtr() const
OptionType getType() const
uint8_t type
Definition: SomeIpSdLayer.h:406
Definition: SomeIpLayer.h:65
Definition: SomeIpSdLayer.h:40
Definition: SomeIpSdLayer.h:370
Definition: SomeIpSdLayer.h:151
Definition: SomeIpSdLayer.h:319
IPv6OptionType
Definition: SomeIpSdLayer.h:221
EntryType getType() const
Definition: SomeIpSdLayer.h:488
Definition: IpAddress.h:42
Definition: IpAddress.h:192
IPv4OptionType
Definition: SomeIpSdLayer.h:144
uint8_t nrOpt2
Definition: SomeIpSdLayer.h:414
Definition: SomeIpLayer.h:20
virtual ~SomeIpSdOption()
SomeIpSdProtocolType
Definition: SomeIpSdLayer.h:26
MsgType
Definition: SomeIpLayer.h:26
someipsdhdroptionsbase * getSomeIpSdOptionHeader() const
Definition: SomeIpSdLayer.h:31
Definition: SomeIpSdLayer.h:620
OptionType
Definition: SomeIpSdLayer.h:48
Definition: Layer.h:23
size_t getLength() const
Definition: SomeIpSdLayer.h:494
Definition: SomeIpSdLayer.h:290
uint8_t indexSecondOption
Definition: SomeIpSdLayer.h:410
EntryType
Definition: SomeIpSdLayer.h:378
Definition: SomeIpSdLayer.h:75
Definition: SomeIpSdLayer.h:136