NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
packets.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef DOCA_GPUNETIO_PACKETS_H
27 #define DOCA_GPUNETIO_PACKETS_H
28 
29 #include "common.h"
30 
31 #define TCP_PROTOCOL_ID 0x6
32 #define UDP_PROTOCOL_ID 0x11
33 
34 #define DNS_POST 0x35
35 #define WHITESPACE_ASCII 0x20
36 
37 /* ICMP packet types */
38 #define ICMP_ECHO_REPLY 0
39 #define ICMP_ECHO_REQUEST 8
40 
41 enum tcp_flags {
42  TCP_FLAG_FIN = (1 << 0),
43  /* set tcp packet with Fin flag */
44  TCP_FLAG_SYN = (1 << 1),
45  /* set tcp packet with Syn flag */
46  TCP_FLAG_RST = (1 << 2),
47  /* set tcp packet with Rst flag */
48  TCP_FLAG_PSH = (1 << 3),
49  /* set tcp packet with Psh flag */
50  TCP_FLAG_ACK = (1 << 4),
51  /* set tcp packet with Ack flag */
52  TCP_FLAG_URG = (1 << 5),
53  /* set tcp packet with Urg flag */
54  TCP_FLAG_ECE = (1 << 6),
55  /* set tcp packet with ECE flag */
56  TCP_FLAG_CWR = (1 << 7),
57  /* set tcp packet with CQE flag */
58 };
59 
60 struct ether_hdr {
61  uint8_t d_addr_bytes[ETHER_ADDR_LEN]; /* Destination addr bytes in tx order */
62  uint8_t s_addr_bytes[ETHER_ADDR_LEN]; /* Source addr bytes in tx order */
63  uint16_t ether_type; /* Frame type */
64 } __attribute__((__packed__));
65 
66 struct ipv4_hdr {
67  uint8_t version_ihl; /* version and header length */
68  uint8_t type_of_service; /* type of service */
69  uint16_t total_length; /* length of packet */
70  uint16_t packet_id; /* packet ID */
71  uint16_t fragment_offset; /* fragmentation offset */
72  uint8_t time_to_live; /* time to live */
73  uint8_t next_proto_id; /* protocol ID */
74  uint16_t hdr_checksum; /* header checksum */
75  uint32_t src_addr; /* source address */
76  uint32_t dst_addr; /* destination address */
77 } __attribute__((__packed__));
78 
79 struct tcp_hdr {
80  uint16_t src_port; /* TCP source port */
81  uint16_t dst_port; /* TCP destination port */
82  uint32_t sent_seq; /* TX data sequence number */
83  uint32_t recv_ack; /* RX data acknowledgment sequence number */
84  uint8_t dt_off; /* Data offset */
85  uint8_t tcp_flags; /* TCP flags */
86  uint16_t rx_win; /* RX flow control window */
87  uint16_t cksum; /* TCP checksum */
88  uint16_t tcp_urp; /* TCP urgent pointer, if any */
89 } __attribute__((__packed__));
90 
92  struct ether_hdr l2_hdr; /* Ethernet header */
93  struct ipv4_hdr l3_hdr; /* IP header */
94  struct tcp_hdr l4_hdr; /* TCP header */
95 } __attribute__((__packed__));
96 
97 struct udp_hdr {
98  uint16_t src_port; /* UDP source port */
99  uint16_t dst_port; /* UDP destination port */
100  uint16_t dgram_len; /* UDP datagram length */
101  uint16_t dgram_cksum; /* UDP datagram checksum */
102 } __attribute__((__packed__));
103 
105  struct ether_hdr l2_hdr; /* Ethernet header */
106  struct ipv4_hdr l3_hdr; /* IP header */
107  struct udp_hdr l4_hdr; /* UDP header */
108 } __attribute__((__packed__));
109 
113 struct icmp_hdr {
114  uint8_t type; /* ICMP packet type */
115  uint8_t code; /* ICMP packet code */
116  uint16_t cksum; /* ICMP packet checksum */
117  uint16_t ident; /* ICMP packet identifier */
118  uint16_t seq_nb; /* ICMP packet sequence number */
119 } __attribute__((__packed__));
120 
122  struct ether_hdr l2_hdr; /* Ethernet header */
123  struct ipv4_hdr l3_hdr; /* IP header */
124  struct icmp_hdr l4_hdr; /* ICMP header */
125 } __attribute__((__packed__));
126 
127 #endif /* DOCA_GPUNETIO_PACKETS_H */
#define ETHER_ADDR_LEN
Definition: defines.h:77
struct ether_hdr __attribute__((__packed__))
Definition: doca_flow.h:267
tcp_flags
Definition: packets.h:41
@ TCP_FLAG_RST
Definition: packets.h:46
@ TCP_FLAG_FIN
Definition: packets.h:42
@ TCP_FLAG_PSH
Definition: packets.h:48
@ TCP_FLAG_CWR
Definition: packets.h:56
@ TCP_FLAG_ACK
Definition: packets.h:50
@ TCP_FLAG_ECE
Definition: packets.h:54
@ TCP_FLAG_URG
Definition: packets.h:52
@ TCP_FLAG_SYN
Definition: packets.h:44
struct icmp_hdr l4_hdr
Definition: packets.h:124
struct ether_hdr l2_hdr
Definition: packets.h:122
struct ipv4_hdr l3_hdr
Definition: packets.h:123
struct ipv4_hdr l3_hdr
Definition: packets.h:93
struct tcp_hdr l4_hdr
Definition: packets.h:94
struct ether_hdr l2_hdr
Definition: packets.h:92
struct ipv4_hdr l3_hdr
Definition: packets.h:106
struct ether_hdr l2_hdr
Definition: packets.h:105
struct udp_hdr l4_hdr
Definition: packets.h:107
uint8_t s_addr_bytes[ETHER_ADDR_LEN]
Definition: packets.h:62
uint8_t d_addr_bytes[ETHER_ADDR_LEN]
Definition: packets.h:61
uint16_t ether_type
Definition: packets.h:63
uint16_t ident
Definition: packets.h:117
uint8_t type
Definition: packets.h:114
uint16_t seq_nb
Definition: packets.h:118
uint8_t code
Definition: packets.h:115
uint16_t cksum
Definition: packets.h:116
uint16_t fragment_offset
Definition: packets.h:71
uint32_t src_addr
Definition: packets.h:75
uint16_t packet_id
Definition: packets.h:70
uint32_t dst_addr
Definition: packets.h:76
uint8_t type_of_service
Definition: packets.h:68
uint8_t time_to_live
Definition: packets.h:72
uint16_t total_length
Definition: packets.h:69
uint16_t hdr_checksum
Definition: packets.h:74
uint8_t version_ihl
Definition: packets.h:67
uint8_t next_proto_id
Definition: packets.h:73
uint32_t recv_ack
Definition: packets.h:83
uint16_t src_port
Definition: packets.h:80
uint32_t sent_seq
Definition: packets.h:82
uint8_t tcp_flags
Definition: packets.h:85
uint16_t dst_port
Definition: packets.h:81
uint16_t cksum
Definition: packets.h:87
uint16_t tcp_urp
Definition: packets.h:88
uint8_t dt_off
Definition: packets.h:84
uint16_t rx_win
Definition: packets.h:86
uint16_t dst_port
Definition: packets.h:99
uint16_t dgram_len
Definition: packets.h:100
uint16_t dgram_cksum
Definition: packets.h:101
uint16_t src_port
Definition: packets.h:98