CNDP  22.08.0
cne_inet.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2016-2022 Intel Corporation
3  */
4 
5 #ifndef __CNE_INET_H
6 #define __CNE_INET_H
7 
13 #include <stdio.h>
14 #include <arpa/inet.h>
15 #include <netinet/in.h>
16 
17 #include <cne_byteorder.h>
18 #include <net/cne_ether.h>
19 #include <net/cne_ip.h>
20 #include <net/cne_udp.h>
21 #include <net/cne_tcp.h>
22 #include <net/cne_icmp.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 enum { IPv4_VERSION = 4, IPv6_VERSION = 6 };
29 
30 /* Common defines for IPv */
31 enum {
32  IPV4_ADDR_LEN = 4, /* IPv4 Address length */
33  IPV6_ADDR_LEN = 16 /* IPv6 Address length */
34 };
35 
36 /* Common Channel address, internet style. */
37 struct in_caddr {
38  uint8_t cin_family;
39  uint8_t cin_len;
40  uint16_t cin_port;
41  struct in_addr cin_addr;
42 };
43 
44 /* Common Channel address, internet style. */
45 struct in6_caddr {
46  uint8_t cin_family;
47  uint8_t cin_len;
48  uint16_t cin_port;
49  struct in6_addr cin_addr;
50 };
51 
52 /* macros for casting struct in_caddr */
53 #define CIN_PORT(sa) (sa)->cin_port
54 #define CIN_FAMILY(sa) (sa)->cin_family
55 #define CIN_LEN(sa) (sa)->cin_len
56 #define CIN_ADDR(sa) (sa)->cin_addr
57 #define CIN_CADDR(sa) (sa)->cin_addr.s_addr
58 
59 /* IP overlay header for the pseudo header */
60 typedef struct ip_overlay_s {
61  uint32_t node[2];
62  uint8_t pad0; /* overlays ttl */
63  uint8_t proto; /* Protocol type */
64  uint16_t len; /* Protocol length, overlays cksum */
65  uint32_t src; /* Source address */
66  uint32_t dst; /* Destination address */
67 } __attribute__((__packed__)) ip_overlay_t;
68 
69 typedef unsigned int seq_t; /* TCP Sequence type */
70 
71 /* The UDP/IP Pseudo header */
72 typedef struct udpip_s {
73  ip_overlay_t ip; /* IPv4 overlay header */
74  struct cne_udp_hdr udp; /* UDP header for protocol */
75 } __attribute__((__packed__)) udpip_t;
76 
77 /* The TCP/IPv4 Pseudo header */
78 typedef struct tcpip_s {
79  ip_overlay_t ip; /* IPv4 overlay header */
80  struct cne_tcp_hdr tcp; /* TCP header for protocol */
81 } __attribute__((__packed__)) tcpip_t;
82 
83 typedef union {
84  uint16_t _16[3];
85  uint8_t _8[6];
86 } mac_e;
87 
88 typedef union {
89  uint16_t _16[2];
90  uint32_t _32;
91 } ip4_e;
92 
93 typedef struct pkt_hdr_s {
94  struct cne_ether_hdr eth;
96  union {
97  struct cne_ipv4_hdr ipv4;
98  struct cne_ipv6_hdr ipv6;
99  tcpip_t tip;
100  udpip_t uip;
101  struct cne_icmp_hdr icmp;
102  uint64_t pad[8];
103  };
104 } pkt_hdr_t;
105 
106 typedef struct ipv4_5tuple {
107  uint32_t ip_dst;
108  uint32_t ip_src;
109  uint16_t port_dst;
110  uint16_t port_src;
111  uint8_t proto;
112 } __cne_packed ipv4_5tuple_t;
113 
114 typedef struct l3_4route_s {
115  ipv4_5tuple_t key;
116  uint8_t ifid;
117 } __cne_packed l3_4route_t;
118 
119 #define IBUF_SIZE 256
120 
121 #define INET_MASK_STRLEN 4
122 #define IP4_ADDR_STRLEN (INET_ADDRSTRLEN + INET_MASK_STRLEN)
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 #endif /* __CNE_INET_H */
129 
130 #include <cne_inet4.h>
#define CNE_STD_C11
Definition: cne_common.h:91