-
Notifications
You must be signed in to change notification settings - Fork 753
Expand file tree
/
Copy pathdest.h
More file actions
213 lines (170 loc) · 6.69 KB
/
dest.h
File metadata and controls
213 lines (170 loc) · 6.69 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* 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_DEST_H__
#define __DPVS_DEST_H__
#include "ipvs/service.h"
/* must consistent with IP_VS_CONN_F_XXX (libipvs-2.6/ip_vs.h) */
enum dpvs_fwd_mode {
DPVS_FWD_MASQ = 0,
DPVS_FWD_LOCALNODE = 1,
DPVS_FWD_MODE_TUNNEL = 2,
DPVS_FWD_MODE_DR = 3,
DPVS_FWD_MODE_BYPASS = 4,
DPVS_FWD_MODE_FNAT = 5,
DPVS_FWD_MODE_NAT = DPVS_FWD_MASQ,
DPVS_FWD_MODE_SNAT = 6,
};
enum {
DPVS_DEST_F_AVAILABLE = 0x1<<0,
DPVS_DEST_F_OVERLOAD = 0x1<<1,
};
#ifdef __DPVS__
#include "common.h"
#include "list.h"
#include "dpdk.h"
struct dp_vs_dest {
struct list_head n_list; /* for the dests in the service */
int af; /* address family */
/*
* normally, addr/port is for Real Server,
* but for SNAT, addr/port is the "to-source"
* (the target source ip/port translated to).
*/
union inet_addr addr; /* IP address of the server */
uint16_t port; /* port number of the server */
volatile unsigned flags; /* dest status flags */
rte_atomic16_t conn_flags; /* flags to copy to conn */
rte_atomic16_t weight; /* server weight */
rte_atomic32_t refcnt; /* reference counter */
struct dp_vs_stats *stats; /* Use per-cpu statistics for destination server */
enum dpvs_fwd_mode fwdmode;
/* connection counters and thresholds */
rte_atomic32_t actconns; /* active connections */
rte_atomic32_t inactconns; /* inactive connections */
rte_atomic32_t persistconns; /* persistent connections */
uint32_t max_conn; /* upper threshold */
uint32_t min_conn; /* lower threshold */
/* for virtual service */
uint16_t proto; /* which protocol (TCP/UDP) */
uint16_t vport; /* virtual port number */
uint32_t vfwmark; /* firewall mark of service */
struct dp_vs_service *svc; /* service it belongs to */
union inet_addr vaddr; /* virtual IP address */
unsigned conn_timeout; /* conn timeout copied from svc*/
unsigned limit_proportion; /* limit copied from svc*/
} __rte_cache_aligned;
#endif
struct dp_vs_dest_conf {
/* destination server address */
int af;
union inet_addr addr;
uint16_t port;
enum dpvs_fwd_mode fwdmode;
/* real server options */
unsigned conn_flags; /* connection flags */
int weight; /* destination weight */
/* thresholds for active connections */
uint32_t max_conn; /* upper threshold */
uint32_t min_conn; /* lower threshold */
};
struct dp_vs_dest_entry {
int af;
union inet_addr addr; /* destination address */
uint16_t port;
unsigned conn_flags; /* connection flags */
int weight; /* destination weight */
uint32_t max_conn; /* upper threshold */
uint32_t min_conn; /* lower threshold */
uint32_t actconns; /* active connections */
uint32_t inactconns; /* inactive connections */
uint32_t persistconns; /* persistent connections */
/* statistics */
struct dp_vs_stats stats;
};
struct dp_vs_get_dests {
/* which service: user fills in these */
int af;
uint16_t proto;
union inet_addr addr; /* virtual address */
uint16_t port;
uint32_t fwmark; /* firwall mark of service */
/* number of real servers */
unsigned int num_dests;
char srange[256];
char drange[256];
char iifname[IFNAMSIZ];
char oifname[IFNAMSIZ];
/* the real servers */
struct dp_vs_dest_entry entrytable[0];
};
struct dp_vs_dest_user{
int af;
union inet_addr addr;
uint16_t port;
unsigned conn_flags;
int weight;
uint32_t max_conn;
uint32_t min_conn;
};
#ifdef __DPVS__
static inline bool
dp_vs_dest_is_avail(struct dp_vs_dest *dest)
{
return (dest->flags & DPVS_DEST_F_AVAILABLE) ? true : false;
}
static inline bool
dp_vs_dest_is_overload(struct dp_vs_dest *dest)
{
return (dest->flags & DPVS_DEST_F_OVERLOAD) ? true : false;
}
static inline int16_t
dp_vs_dest_get_weight(struct dp_vs_dest *dest)
{
return rte_atomic16_read(&dest->weight);
}
static inline bool
dp_vs_dest_is_valid(struct dp_vs_dest *dest)
{
return (dest
&& dp_vs_dest_is_avail(dest)
&& !dp_vs_dest_is_overload(dest)
&& dp_vs_dest_get_weight(dest) > 0) ? true : false;
}
int dp_vs_new_dest(struct dp_vs_service *svc, struct dp_vs_dest_conf *udest,
struct dp_vs_dest **dest_p);
struct dp_vs_dest *dp_vs_lookup_dest(int af, struct dp_vs_service *svc,
const union inet_addr *daddr, uint16_t dport);
struct dp_vs_dest *dp_vs_find_dest(int af, const union inet_addr *daddr,
uint16_t dport, const union inet_addr *vaddr,
uint16_t vport, uint16_t protocol);
struct dp_vs_dest *dp_vs_trash_get_dest(struct dp_vs_service *svc,
const union inet_addr *daddr, uint16_t dport);
void dp_vs_trash_cleanup(void);
int dp_vs_add_dest(struct dp_vs_service *svc, struct dp_vs_dest_conf *udest);
int dp_vs_edit_dest(struct dp_vs_service *svc, struct dp_vs_dest_conf *udest);
void __dp_vs_unlink_dest(struct dp_vs_service *svc,
struct dp_vs_dest *dest, int svcupd);
void __dp_vs_del_dest(struct dp_vs_dest *dest);
int dp_vs_del_dest(struct dp_vs_service *svc, struct dp_vs_dest_conf *udest);
int dp_vs_get_dest_entries(const struct dp_vs_service *svc,
const struct dp_vs_get_dests *get,
struct dp_vs_get_dests *uptr);
int dp_vs_dest_init(void);
int dp_vs_dest_term(void);
#endif
#endif /* __DPVS_DEST_H__ */