forked from iqiyi/dpvs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
95 lines (82 loc) · 3.25 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* DPVS is a software load balancer (Virtual Server) based on DPDK.
*
* Copyright (C) 2017 iQIYI (www.iqiyi.com).
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef __DPVS_COMMON_H__
#define __DPVS_COMMON_H__
#include <stdbool.h>
#include <stdint.h>
#include <linux/if_ether.h>
#ifndef NELEMS
#define NELEMS(a) (sizeof(a) / sizeof((a)[0]))
#endif
#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef __be32
typedef uint32_t __be32;
#endif
#ifndef __be16
typedef uint16_t __be16;
#endif
#define DPVS_MAX_SOCKET 2 /* num of NUMA socket */
typedef enum {
DPVS_STATE_STOP = 1,
DPVS_STATE_INIT,
DPVS_STATE_NORMAL,
DPVS_STATE_FINISH,
} dpvs_state_t;
void dpvs_state_set(dpvs_state_t stat);
dpvs_state_t dpvs_state_get(void);
bool is_power2(int num, int offset, int *lower);
enum {
EDPVS_OK = 0,
EDPVS_INVAL = -1, /* invalid parameter */
EDPVS_NOMEM = -2, /* no memory */
EDPVS_EXIST = -3, /* already exist */
EDPVS_NOTEXIST = -4, /* not exist */
EDPVS_INVPKT = -5, /* invalid packet */
EDPVS_DROP = -6, /* packet dropped */
EDPVS_NOPROT = -7, /* no protocol */
EDPVS_NOROUTE = -8, /* no route */
EDPVS_DEFRAG = -9, /* defragment error */
EDPVS_FRAG = -10, /* fragment error */
EDPVS_DPDKAPIFAIL = -11, /* DPDK error */
EDPVS_IDLE = -12, /* nothing to do */
EDPVS_BUSY = -13, /* resource busy */
EDPVS_NOTSUPP = -14, /* not support */
EDPVS_RESOURCE = -15, /* no resource */
EDPVS_OVERLOAD = -16, /* overloaded */
EDPVS_NOSERV = -17, /* no service */
EDPVS_DISABLED = -18, /* disabled */
EDPVS_NOROOM = -19, /* no room */
EDPVS_NONEALCORE = -20, /* non-eal thread lcore */
EDPVS_CALLBACKFAIL = -21, /* callbacks fail */
EDPVS_IO = -22, /* I/O error */
EDPVS_MSG_FAIL = -23, /* msg callback failed */
EDPVS_MSG_DROP = -24, /* msg callback dropped */
EDPVS_PKTSTOLEN = -25, /* stolen packet */
EDPVS_SYSCALL = -26, /* system call failed */
EDPVS_NODEV = -27, /* no such device */
/* positive code for non-error */
EDPVS_KNICONTINUE = 1, /* KNI to continue */
EDPVS_INPROGRESS = 2, /* in progress */
};
extern const char *dpvs_strerror(int err);
int linux_set_if_mac(const char *ifname, const unsigned char mac[ETH_ALEN]);
int linux_hw_mc_add(const char *ifname, const uint8_t hwma[ETH_ALEN]);
int linux_hw_mc_del(const char *ifname, const uint8_t hwma[ETH_ALEN]);
#endif /* __DPVS_COMMON_H__ */