-
Notifications
You must be signed in to change notification settings - Fork 753
Expand file tree
/
Copy pathservice.h
More file actions
264 lines (213 loc) · 7.61 KB
/
service.h
File metadata and controls
264 lines (213 loc) · 7.61 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
* 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_SVC_H__
#define __DPVS_SVC_H__
#include <stdint.h>
#include <net/if.h>
#include "match.h"
#include "ipvs/stats.h"
#include "ipvs/dest.h"
#include "inet.h"
#define DP_VS_SCHEDNAME_MAXLEN 16
#ifdef __DPVS__
#include "list.h"
#include "dpdk.h"
#include "netif.h"
#include "ipvs/ipvs.h"
#include "ipvs/sched.h"
#define RTE_LOGTYPE_SERVICE RTE_LOGTYPE_USER3
#define DP_VS_SVC_F_PERSISTENT 0x0001 /* peristent port */
#define DP_VS_SVC_F_HASHED 0x0002 /* hashed entry */
#define DP_VS_SVC_F_SYNPROXY 0x8000 /* synrpoxy flag */
#define DP_VS_SVC_F_SIP_HASH 0x0100 /* sip hash target */
#define DP_VS_SVC_F_QID_HASH 0x0200 /* quic cid hash target */
rte_rwlock_t __dp_vs_svc_lock;
struct laddr_list_pre_lcore {
struct list_head laddr_list; /* local address (LIP) pool */
struct list_head *laddr_curr;
uint32_t num_laddrs;
};
/* virtual service */
struct dp_vs_service {
struct list_head s_list; /* node for normal service table */
struct list_head f_list; /* node for fwmark service table */
struct list_head m_list; /* node for match service table */
rte_atomic32_t refcnt;
rte_atomic32_t usecnt;
/*
* to identify a service
* 1. <af, proto, vip, vport>
* 2. fwmark (no use now).
* 3. match.
*/
int af;
uint8_t proto; /* TCP/UDP/... */
union inet_addr addr; /* virtual IP address */
uint16_t port;
uint32_t fwmark;
struct dp_vs_match *match;
unsigned flags;
unsigned timeout;
unsigned conn_timeout;
unsigned bps;
unsigned limit_proportion;
uint32_t netmask;
struct list_head dests; /* real services (dp_vs_dest{}) */
uint32_t num_dests;
long weight; /* sum of servers weight */
struct dp_vs_scheduler *scheduler;
void *sched_data;
rte_rwlock_t sched_lock;
struct dp_vs_stats *stats;
/* FNAT only */
struct list_head laddr_list; /* local address (LIP) pool */
struct list_head *laddr_curr;
rte_rwlock_t laddr_lock;
uint32_t num_laddrs;
struct laddr_list_pre_lcore pre_list[RTE_MAX_LCORE];
#define this_pre_list pre_list[rte_lcore_id()]
/* ... flags, timer ... */
} __rte_cache_aligned;
#endif
struct dp_vs_service_conf {
/* virtual service addresses */
uint16_t af;
uint16_t protocol;
union inet_addr addr; /* virtual ip address */
uint16_t port;
uint32_t fwmark; /* firwall mark of service */
struct dp_vs_match match;
/* virtual service options */
char *sched_name;
unsigned flags; /* virtual service flags */
unsigned timeout; /* persistent timeout in sec */
unsigned conn_timeout;
uint32_t netmask; /* persistent netmask */
unsigned bps;
unsigned limit_proportion;
};
struct dp_vs_service_entry {
int af;
uint16_t proto;
union inet_addr addr;
uint16_t port;
uint32_t fwmark;
char sched_name[DP_VS_SCHEDNAME_MAXLEN];
unsigned flags;
unsigned timeout;
unsigned conn_timeout;
uint32_t netmask;
unsigned bps;
unsigned limit_proportion;
unsigned int num_dests;
unsigned int num_laddrs;
struct dp_vs_stats stats;
char srange[256];
char drange[256];
char iifname[IFNAMSIZ];
char oifname[IFNAMSIZ];
};
struct dp_vs_get_services {
unsigned int num_services;
struct dp_vs_service_entry entrytable[0];
};
struct dp_vs_service_user{
int af;
uint16_t proto;
union inet_addr addr;
uint16_t port;
uint32_t fwmark;
char sched_name[DP_VS_SCHEDNAME_MAXLEN];
unsigned flags;
unsigned timeout;
unsigned conn_timeout;
uint32_t netmask;
unsigned bps;
unsigned limit_proportion;
char srange[256];
char drange[256];
char iifname[IFNAMSIZ];
char oifname[IFNAMSIZ];
};
struct dp_vs_getinfo {
unsigned int version;
unsigned int size;
unsigned int num_services;
};
#ifdef __DPVS__
int dp_vs_service_init(void);
int dp_vs_service_term(void);
int dp_vs_add_service(struct dp_vs_service_conf *u,
struct dp_vs_service **svc_p);
int dp_vs_del_service(struct dp_vs_service *svc);
int dp_vs_edit_service(struct dp_vs_service *svc,
struct dp_vs_service_conf *u);
struct dp_vs_service *
dp_vs_service_lookup(int af, uint16_t protocol,
const union inet_addr *vaddr,
uint16_t vport, uint32_t fwmark,
const struct rte_mbuf *mbuf,
const struct dp_vs_match *match,
bool *outwall);
int dp_vs_match_parse(const char *srange, const char *drange,
const char *iifname, const char *oifname,
struct dp_vs_match *match);
void __dp_vs_bind_svc(struct dp_vs_dest *dest, struct dp_vs_service *svc);
void __dp_vs_unbind_svc(struct dp_vs_dest *dest);
struct dp_vs_service *dp_vs_lookup_vip(int af, uint16_t protocol,
const union inet_addr *vaddr);
static inline void dp_vs_service_put(struct dp_vs_service *svc)
{
rte_atomic32_dec(&svc->usecnt);
}
struct dp_vs_service *__dp_vs_service_get(int af, uint16_t protocol,
const union inet_addr *vaddr, uint16_t vport);
struct dp_vs_service *__dp_vs_svc_fwm_get(int af, uint32_t fwmark);
int dp_vs_get_service_entries(const struct dp_vs_get_services *get,
struct dp_vs_get_services *uptr);
unsigned dp_vs_get_conn_timeout(struct dp_vs_conn *conn);
/* flush all services */
int dp_vs_flush(void);
int dp_vs_zero_service(struct dp_vs_service *svc);
int dp_vs_zero_all(void);
enum{
DPVS_SO_SET_FLUSH = 200,
DPVS_SO_SET_ZERO,
DPVS_SO_SET_ADD,
DPVS_SO_SET_EDIT,
DPVS_SO_SET_DEL,
DPVS_SO_SET_ADDDEST,
DPVS_SO_SET_EDITDEST,
DPVS_SO_SET_DELDEST,
DPVS_SO_SET_GRATARP,
DPVS_SO_SET_CONN_SYNC,
};
enum{
DPVS_SO_GET_VERSION = 200,
DPVS_SO_GET_INFO,
DPVS_SO_GET_SERVICES,
DPVS_SO_GET_SERVICE,
DPVS_SO_GET_DESTS,
};
#define SOCKOPT_SVC_BASE DPVS_SO_SET_FLUSH
#define SOCKOPT_SVC_SET_CMD_MAX DPVS_SO_SET_CONN_SYNC
#define SOCKOPT_SVC_GET_CMD_MAX DPVS_SO_GET_DESTS
#define MAX_ARG_LEN (sizeof(struct dp_vs_service_user) + \
sizeof(struct dp_vs_dest_user))
#endif
#endif /* __DPVS_SVC_H__ */