CNDP  22.08.0
cnet_const.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 __CNET_CONST_H
6 #define __CNET_CONST_H
7 
13 #include <sys/types.h>
14 #include <unistd.h>
15 #include <libgen.h>
16 
17 #include <cne_prefetch.h>
18 
19 #include <cne_log.h>
20 
21 #include <errno.h>
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /* Stack tick rate in milliseconds */
27 #define MS_PER_TICK 10
28 
29 /* Determine if a bit is set or cleared as a boolean expression */
30 #define is_set(x, y) (((x) & (y)) != 0)
31 #define is_clr(x, y) (((x) & (y)) == 0)
32 
33 #define PROTO_DEFAULT_MBUF_COUNT 1024
34 #define _IPPORT_RESERVED 49152
39 #define __cnet_no_return __attribute__((__no_return__))
40 
44 #define __cnet_attribute(...) __attribute__((__VA_ARGS__))
45 
46 #ifdef CNET_ASSERT_ENABLED
47 #define cnet_assert(x) assert(x)
48 #else
49 #define cnet_assert(x) \
50  do { \
51  } while (/*CONSTCOND*/ 0)
52 #endif
53 
54 enum {
55  CNET_MAX_INITS = 64,
56  PROTOSW_MAX_SIZE = 64,
57 };
58 
59 enum {
60  CNET_PRIORITY_0 = 0x0000,
61  CNET_PRIORITY_1 = 0x0100,
62  CNET_PRIORITY_2 = 0x0200,
63  CNET_PRIORITY_3 = 0x0300,
64  CNET_PRIORITY_4 = 0x0400,
65  CNET_PRIORITY_5 = 0x0500,
66  CNET_PRIORITY_6 = 0x0600,
67  CNET_PRIORITY_7 = 0x0700,
68  CNET_PRIORITY_8 = 0x0800,
69  CNET_PRIORITY_9 = 0x0900,
70  CNET_PRIORITY_10 = 0x0a00
71 };
72 
73 enum {
74  CNET_NETLINK_PRIO = (CNET_PRIORITY_1 + 0),
75  CNET_STK_PRIO = (CNET_PRIORITY_1 + 1),
76  CNET_PROTOSW_PRIO = (CNET_PRIORITY_1 + 2),
77 
78  CNET_IPV4_PRIO = (CNET_PRIORITY_2 + 0),
79  CNET_IPV6_PRIO = (CNET_PRIORITY_2 + 1),
80  CNET_ND_PRIO = (CNET_PRIORITY_2 + 2),
81 
82  CNET_ICMP_PRIO = (CNET_PRIORITY_3 + 0),
83  CNET_ICMP6_PRIO = (CNET_PRIORITY_3 + 1),
84  CNET_RARP_PRIO = (CNET_PRIORITY_3 + 2),
85 
86  CNET_PCB_PRIO = (CNET_PRIORITY_4 + 0),
87  CNET_UDP_PRIO = (CNET_PRIORITY_4 + 1),
88  CNET_TCP_PRIO = (CNET_PRIORITY_4 + 2),
89  CNET_RAW_PRIO = (CNET_PRIORITY_4 + 3),
90 
91  CNET_CHNL_PRIO = (CNET_PRIORITY_5 + 0),
92  CNET_RAW_CHNL_PRIO = (CNET_PRIORITY_5 + 1),
93  CNET_UDP_CHNL_PRIO = (CNET_PRIORITY_5 + 2),
94  CNET_TCP_CHNL_PRIO = (CNET_PRIORITY_5 + 3),
95  CNET_ICMP_CHNL_PRIO = (CNET_PRIORITY_5 + 4),
96  CNET_ICMP6_CHNL_PRIO = (CNET_PRIORITY_5 + 5),
97 
98  CNET_UTILS_PRIO = (CNET_PRIORITY_9 + 0),
99  CNET_CFG_PRIO = (CNET_PRIORITY_10),
100 };
101 
102 enum {
103  STK_VEC_COUNT = 32,
104  TCP_VEC_PCB_COUNT = 32,
105  UDP_VEC_PCB_COUNT = 32,
106  RAW_VEC_PCB_COUNT = 32,
107  ICMP_VEC_PCB_COUNT = 32,
108  ICMP6_VEC_PCB_COUNT = 32,
109  CHNL_OPT_VEC_COUNT = 8,
110 };
111 
112 /* Generic matching flags for pcb, route, and arp lookups */
113 typedef enum { EXACT_MATCH = 1, BEST_MATCH = 2, IPV6_TYPE = 0x80 } match_t;
114 
115 typedef enum { CNET_INIT = 1, CNET_STOP, CNET_ALL } init_types_e;
116 
117 struct netif;
118 struct chnl;
119 struct tcb_entry;
120 struct pcb_entry;
121 struct cnet;
122 struct stk_s;
123 struct pktmbuf_s;
124 
126 typedef int (*proto_input_t)(struct netif *netif, struct pktmbuf_s **vec);
127 
128 typedef int (*cfunc_t)(void *arg);
129 typedef int (*vfunc_t)(void);
130 
131 typedef union iofunc_s {
132  void (*generic)(void);
133 
134  int (*netif)(struct netif *netif);
135  int (*ifunc)(struct netif *netif, struct pktmbuf_s **vec);
136  void (*vfunc)(struct netif *netif, struct pktmbuf_s **vec);
137  int (*ioctl)(struct netif *netif, int cmd, void *data);
138 
139  int (*chfunc)(struct chnl *ch, struct pktmbuf_s **vec);
140  int (*tcbfunc)(struct tcb_entry *tcb);
141 } iofunc_t;
142 
143 enum {
146  _SELEXCEPT
147 };
148 
149 enum {
150  ARP_IO, /* Keep in this order, cnet_netif.c:netif_input */
151  RARP_IO,
152  IPV4_IO,
153  IPV6_IO,
154 
155  RAW_IO,
156  UDP_IO,
157  TCP_IO,
158  ICMP_IO,
159  ICMPV6_IO,
160  ND_IO,
161  LO_IO,
162  NETIF_IO,
163 
164  PROTO_IO_MAX
165 };
166 
167 static inline int
168 __errno_get(void)
169 {
170  return errno;
171 }
172 
180 static inline int
181 __errno_set(int errorValue)
182 {
183  return errno = errorValue, (errorValue ? -1 : 0);
184 }
185 
193 static inline void *
194 __errno_set_null(int errorValue)
195 {
196  return errno = errorValue, NULL;
197 }
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif /* __CNET_CONST_H */
@ CNET_NETLINK_PRIO
Definition: cnet_const.h:74
static void * __errno_set_null(int errorValue)
Definition: cnet_const.h:194
@ _SELEXCEPT
Definition: cnet_const.h:146
@ _SELWRITE
Definition: cnet_const.h:145
@ _SELREAD
Definition: cnet_const.h:144
int(* proto_input_t)(struct netif *netif, struct pktmbuf_s **vec)
Definition: cnet_const.h:126
static int __errno_set(int errorValue)
Definition: cnet_const.h:181