Protocol.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /************************************
  2. * Protocol.h
  3. *************************************/
  4. #ifndef __PROTOCOL_H__
  5. #define __PROTOCOL_H__
  6. #define IPV4 4
  7. #define IPV6 6
  8. struct ArpHeader {
  9. struct arphdr arp;
  10. unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
  11. unsigned char ar_sip[4]; /* sender IP address */
  12. unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
  13. unsigned char ar_tip[4]; /* target IP address */
  14. }/*__attribute__((packed))*/;
  15. struct TransportHeaderT
  16. {
  17. union
  18. {
  19. struct udphdr uhdr;
  20. struct tcphdr thdr;
  21. };
  22. } __attribute__((packed));
  23. typedef struct TransportHeaderT xporthdr;
  24. typedef enum _E_NWPKT_IPFRAME_TYPE
  25. {
  26. eNonIPPacket,
  27. eIPv4Packet,
  28. eIPv6Packet
  29. }E_NWPKT_IPFRAME_TYPE;
  30. typedef enum _E_NWPKT_ETHFRAME_TYPE
  31. {
  32. eEthUnsupportedFrame,
  33. eEth802LLCFrame,
  34. eEth802LLCSNAPFrame,
  35. eEth802QVLANFrame,
  36. eEthOtherFrame
  37. } E_NWPKT_ETHFRAME_TYPE;
  38. typedef struct _S_ETHCS_PKT_INFO
  39. {
  40. E_NWPKT_IPFRAME_TYPE eNwpktIPFrameType;
  41. E_NWPKT_ETHFRAME_TYPE eNwpktEthFrameType;
  42. USHORT usEtherType;
  43. UCHAR ucDSAP;
  44. }S_ETHCS_PKT_INFO,*PS_ETHCS_PKT_INFO;
  45. typedef struct _ETH_CS_802_Q_FRAME
  46. {
  47. ETH_HEADER_STRUC EThHdr;
  48. USHORT UserPriority:3;
  49. USHORT CFI:1;
  50. USHORT VLANID:12;
  51. USHORT EthType;
  52. } __attribute__((packed)) ETH_CS_802_Q_FRAME;
  53. typedef struct _ETH_CS_802_LLC_FRAME
  54. {
  55. ETH_HEADER_STRUC EThHdr;
  56. unsigned char DSAP;
  57. unsigned char SSAP;
  58. unsigned char Control;
  59. }__attribute__((packed)) ETH_CS_802_LLC_FRAME;
  60. typedef struct _ETH_CS_802_LLC_SNAP_FRAME
  61. {
  62. ETH_HEADER_STRUC EThHdr;
  63. unsigned char DSAP;
  64. unsigned char SSAP;
  65. unsigned char Control;
  66. unsigned char OUI[3];
  67. unsigned short usEtherType;
  68. } __attribute__((packed)) ETH_CS_802_LLC_SNAP_FRAME;
  69. typedef struct _ETH_CS_ETH2_FRAME
  70. {
  71. ETH_HEADER_STRUC EThHdr;
  72. } __attribute__((packed)) ETH_CS_ETH2_FRAME;
  73. #define ETHERNET_FRAMETYPE_IPV4 ntohs(0x0800)
  74. #define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd)
  75. #define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100)
  76. //Per SF CS Specification Encodings
  77. typedef enum _E_SERVICEFLOW_CS_SPEC_
  78. {
  79. eCSSpecUnspecified =0,
  80. eCSPacketIPV4,
  81. eCSPacketIPV6,
  82. eCS802_3PacketEthernet,
  83. eCS802_1QPacketVLAN,
  84. eCSPacketIPV4Over802_3Ethernet,
  85. eCSPacketIPV6Over802_3Ethernet,
  86. eCSPacketIPV4Over802_1QVLAN,
  87. eCSPacketIPV6Over802_1QVLAN,
  88. eCSPacketUnsupported
  89. }E_SERVICEFLOW_CS_SPEC;
  90. #define IP6_HEADER_LEN 40
  91. #define IP_VERSION(byte) (((byte&0xF0)>>4))
  92. #define MAC_ADDRESS_SIZE 6
  93. #define ETH_AND_IP_HEADER_LEN 14 + 20
  94. #define L4_SRC_PORT_LEN 2
  95. #define L4_DEST_PORT_LEN 2
  96. #define CTRL_PKT_LEN 8 + ETH_AND_IP_HEADER_LEN
  97. #define ETH_ARP_FRAME 0x806
  98. #define ETH_IPV4_FRAME 0x800
  99. #define ETH_IPV6_FRAME 0x86DD
  100. #define UDP 0x11
  101. #define TCP 0x06
  102. #define ARP_OP_REQUEST 0x01
  103. #define ARP_OP_REPLY 0x02
  104. #define ARP_PKT_SIZE 60
  105. // This is the format for the TCP packet header
  106. typedef struct _TCP_HEADER
  107. {
  108. USHORT usSrcPort;
  109. USHORT usDestPort;
  110. ULONG ulSeqNumber;
  111. ULONG ulAckNumber;
  112. UCHAR HeaderLength;
  113. UCHAR ucFlags;
  114. USHORT usWindowsSize;
  115. USHORT usChkSum;
  116. USHORT usUrgetPtr;
  117. } TCP_HEADER,*PTCP_HEADER;
  118. #define TCP_HEADER_LEN sizeof(TCP_HEADER)
  119. #define TCP_ACK 0x10 //Bit 4 in tcpflags field.
  120. #define GET_TCP_HEADER_LEN(byte) ((byte&0xF0)>>4)
  121. #endif //__PROTOCOL_H__