PcapPlusPlus  22.11
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  uint8_t reserved;
200  /* Layer 4 Protocol field (L4-Proto) - Either UDP or TCP */
201  SomeIpSdProtocolType l4Protocol;
202  /* Port number of UDP or TCP */
203  uint16_t portNumber;
204  };
205 #pragma pack(pop)
206 };
207 
213 {
214 public:
215  friend class SomeIpSdLayer;
216 
221  {
228  };
229 
237  SomeIpSdIPv6Option(IPv6OptionType type, IPv6Address ipAddress, uint16_t port, SomeIpSdProtocolType l4Protocol);
238 
244  SomeIpSdIPv6Option(const IDataContainer *dataContainer, size_t offset);
245 
250  IPv6Address getIpAddress() const;
251 
256  uint16_t getPort() const;
257 
262  SomeIpSdProtocolType getProtocol() const;
263 
264 private:
269 #pragma pack(push, 1)
270  struct someipsdhdroptionsipv6 : someipsdhdroptionsbase
271  {
272  /* IPv6-Address field */
273  uint8_t ipv6Address[16];
274  /* Reserved */
275  uint8_t reserved;
276  /* Layer 4 Protocol field (L4-Proto) - Either UDP or TCP */
277  SomeIpSdProtocolType l4Protocol;
278  /* Port number of UDP or TCP */
279  uint16_t portNumber;
280  };
281 #pragma pack(pop)
282 };
283 
289 {
290 public:
291  friend class SomeIpSdLayer;
292 
297  SomeIpSdConfigurationOption(const std::string &configurationString);
298 
304  SomeIpSdConfigurationOption(const IDataContainer *dataContainer, size_t offset);
305 
310  std::string getConfigurationString() const;
311 };
312 
318 {
319 public:
320  friend class SomeIpSdLayer;
321 
327  SomeIpSdLoadBalancingOption(uint16_t priority, uint16_t weight);
328 
334  SomeIpSdLoadBalancingOption(const IDataContainer *dataContainer, size_t offset);
335 
340  uint16_t getPriority() const;
341 
346  uint16_t getWeight() const;
347 
348 private:
353 #pragma pack(push, 1)
354  struct someipsdhdroptionsload : someipsdhdroptionsbase
355  {
356  /* Priority field */
357  uint16_t priority;
358  /* Weight field */
359  uint16_t weight;
360  };
361 #pragma pack(pop)
362 };
363 
369 {
370 public:
371  friend class SomeIpSdLayer;
372 
376  enum class EntryType : uint8_t
377  {
379  FindService,
381  OfferService,
383  StopOfferService,
385  SubscribeEventgroup,
387  StopSubscribeEventgroup,
389  SubscribeEventgroupAck,
391  SubscribeEventgroupNack,
393  UnknownEntryType
394  };
395 
400 #pragma pack(push, 1)
402  {
404  uint8_t type;
409 #if (BYTE_ORDER == LITTLE_ENDIAN)
410  uint8_t
412  nrOpt2 : 4,
414  nrOpt1 : 4;
415 #else
416  uint8_t
418  nrOpt1 : 4,
420  nrOpt2 : 4;
421 #endif
422 
423  uint16_t serviceID;
425  uint16_t instanceID;
429  uint32_t data;
430  };
431 #pragma pack(pop)
432 
442  SomeIpSdEntry(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL,
443  uint32_t minorVersion);
444 
455  SomeIpSdEntry(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL,
456  uint8_t counter, uint16_t eventGroupID);
457 
463  SomeIpSdEntry(const SomeIpSdLayer *pSomeIpSdLayer, size_t offset);
464 
468  ~SomeIpSdEntry();
469 
474  uint8_t *getDataPtr() const;
475 
480  someipsdhdrentry *getSomeIpSdEntryHeader() const;
481 
486  EntryType getType() const { return m_EntryType; }
487 
492  size_t getLength() const { return sizeof(someipsdhdrentry); }
493 
498  uint32_t getNumOptions() const;
499 
504  uint16_t getServiceId() const;
505 
510  void setServiceId(uint16_t serviceId);
511 
516  uint16_t getInstanceId() const;
517 
522  void setInstanceId(uint16_t instanceId);
523 
528  uint8_t getMajorVersion() const;
529 
534  void setMajorVersion(uint8_t majorVersion);
535 
540  uint32_t getTtl() const;
541 
546  void setTtl(uint32_t ttl);
547 
552  uint32_t getMinorVersion() const;
553 
558  void setMinorVersion(uint32_t minorVersion);
559 
564  uint8_t getCounter() const;
565 
570  void setCounter(uint8_t counter);
571 
576  uint16_t getEventgroupId() const;
577 
582  void setEventgroupId(uint16_t eventgroupID);
583 
584 private:
589  enum class TypeInternal : uint8_t
590  {
592  FindService_Internal = 0x00,
594  OfferService_Internal = 0x01,
596  SubscribeEventgroup_Internal = 0x06,
598  SubscribeEventgroupAck_Internal = 0x07,
599  };
600 
601  EntryType m_EntryType;
602  const SomeIpSdLayer *m_Layer;
603  size_t m_Offset;
604  uint8_t *m_ShadowData;
605 
606  void initStdFields(EntryType type, uint16_t serviceID, uint16_t instanceID, uint8_t majorVersion, uint32_t TTL);
607 
608  SomeIpSdEntry(const SomeIpSdEntry &) = delete;
609  SomeIpSdEntry &operator=(const SomeIpSdEntry &) = delete;
610 
611  static const uint32_t SOMEIPSD_HDR_ENTRY_MASK_TTL = 0x00FFFFFF;
612 };
613 
619 {
620 public:
621  friend class SomeIpSdEntry;
622 
623  typedef SomeIpSdEntry* EntryPtr;
624  typedef std::vector<EntryPtr> EntriesVec;
625  typedef SomeIpSdOption* OptionPtr;
626  typedef std::vector<OptionPtr> OptionsVec;
627 
635  SomeIpSdLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet);
636 
648  SomeIpSdLayer(uint16_t serviceID, uint16_t methodID, uint16_t clientID, uint16_t sessionID,
649  uint8_t interfaceVersion, MsgType type, uint8_t returnCode, uint8_t flags);
650 
655 
661  static bool isSomeIpSdPort(uint16_t port) { return port == 30490; }
662 
667  uint8_t getFlags() const;
668 
673  void setFlags(uint8_t flags);
674 
679  uint32_t getNumEntries() const;
680 
685  uint32_t getNumOptions() const;
686 
691  const EntriesVec getEntries() const;
692 
697  const OptionsVec getOptions() const;
698 
704  const OptionsVec getOptionsFromEntry(uint32_t index) const;
705 
711  uint32_t addEntry(const SomeIpSdEntry &entry);
712 
721  bool addOptionTo(uint32_t indexEntry, const SomeIpSdOption &option);
722 
727 
731  std::string toString() const;
732 
733 private:
738 #pragma pack(push, 1)
739  struct someipsdhdr : someiphdr
740  {
742  uint8_t flags;
744  uint8_t reserved1;
746  uint8_t reserved2;
748  uint8_t reserved3;
749  };
750 #pragma pack(pop)
751 
752  uint32_t m_NumOptions;
753 
754  uint32_t countOptions();
755  uint32_t findOption(const SomeIpSdOption &option);
756  void addOption(const SomeIpSdOption &option);
757  bool addOptionIndex(uint32_t indexEntry, uint32_t indexOffset);
758  OptionPtr parseOption(SomeIpSdOption::OptionType type, size_t offset) const;
759 
760  size_t getLenEntries() const;
761  size_t getLenOptions() const;
762  void setLenEntries(uint32_t length);
763  void setLenOptions(uint32_t length);
764 };
765 
766 } // namespace pcpp
767 #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:212
uint8_t indexFirstOption
Definition: SomeIpSdLayer.h:406
uint32_t data
Definition: SomeIpSdLayer.h:429
~SomeIpSdLayer()
Definition: SomeIpSdLayer.h:654
uint16_t instanceID
Definition: SomeIpSdLayer.h:425
void computeCalculateFields()
Definition: SomeIpSdLayer.h:726
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:423
uint32_t majorVersion_ttl
Definition: SomeIpSdLayer.h:427
Definition: SomeIpSdLayer.h:401
static bool isSomeIpSdPort(uint16_t port)
Definition: SomeIpSdLayer.h:661
Definition: SomeIpSdLayer.h:223
size_t getLength() const
Definition: SomeIpSdLayer.h:101
Definition: SomeIpSdLayer.h:227
Definition: SomeIpSdLayer.h:225
uint8_t reserved
Definition: SomeIpSdLayer.h:82
uint8_t * getDataPtr() const
OptionType getType() const
uint8_t type
Definition: SomeIpSdLayer.h:404
Definition: SomeIpLayer.h:65
Definition: SomeIpSdLayer.h:40
Definition: SomeIpSdLayer.h:368
Definition: SomeIpSdLayer.h:151
Definition: SomeIpSdLayer.h:317
IPv6OptionType
Definition: SomeIpSdLayer.h:220
EntryType getType() const
Definition: SomeIpSdLayer.h:486
Definition: IpAddress.h:27
Definition: IpAddress.h:167
IPv4OptionType
Definition: SomeIpSdLayer.h:144
uint8_t nrOpt2
Definition: SomeIpSdLayer.h:412
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:618
OptionType
Definition: SomeIpSdLayer.h:48
Definition: Layer.h:23
size_t getLength() const
Definition: SomeIpSdLayer.h:492
Definition: SomeIpSdLayer.h:288
uint8_t indexSecondOption
Definition: SomeIpSdLayer.h:408
EntryType
Definition: SomeIpSdLayer.h:376
Definition: SomeIpSdLayer.h:75
Definition: SomeIpSdLayer.h:136