-
Notifications
You must be signed in to change notification settings - Fork 753
Expand file tree
/
Copy pathip_vs_proto.c
More file actions
149 lines (118 loc) · 4.13 KB
/
ip_vs_proto.c
File metadata and controls
149 lines (118 loc) · 4.13 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
/*
* DPVS is a software load balancer (Virtual Server) based on DPDK.
*
* Copyright (C) 2021 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.
*
*/
#include <assert.h>
#include "conf/common.h"
#include "dpdk.h"
#include "ipv4.h"
#include "ipvs/ipvs.h"
#include "ipvs/proto.h"
#include "ipvs/conn.h"
#include "ipvs/service.h"
#define DPVS_MAX_PROTOS 256 /* never change it */
static struct dp_vs_proto *dp_vs_protocols[DPVS_MAX_PROTOS];
static int proto_register(struct dp_vs_proto *proto)
{
/* sanity check */
if (!proto->name || proto->proto >= DPVS_MAX_PROTOS
|| !proto->conn_sched || !proto->conn_lookup)
return EDPVS_INVAL;
if (dp_vs_protocols[proto->proto])
return EDPVS_EXIST;
dp_vs_protocols[proto->proto] = proto;
if (proto->init)
proto->init(proto);
return EDPVS_OK;
}
static int proto_unregister(struct dp_vs_proto *proto)
{
assert(proto && proto->proto < DPVS_MAX_PROTOS);
if (!dp_vs_protocols[proto->proto])
return EDPVS_NOTEXIST;
dp_vs_protocols[proto->proto] = NULL;
if (proto->exit)
proto->exit(proto);
return EDPVS_OK;
}
struct dp_vs_proto *dp_vs_proto_lookup(uint8_t proto)
{
assert(proto < DPVS_MAX_PROTOS);
/* NULL if protocol is not registered */
return dp_vs_protocols[proto];
}
extern struct dp_vs_proto dp_vs_proto_udp;
extern struct dp_vs_proto dp_vs_proto_tcp;
extern struct dp_vs_proto dp_vs_proto_icmp;
extern struct dp_vs_proto dp_vs_proto_icmp6;
extern struct dp_vs_proto dp_vs_proto_esp;
extern struct dp_vs_proto dp_vs_proto_ah;
int dp_vs_proto_init(void)
{
int err;
if ((err = proto_register(&dp_vs_proto_udp)) != EDPVS_OK) {
RTE_LOG(ERR, IPVS, "%s: fail to register UDP\n", __func__);
return err;
}
if ((err = proto_register(&dp_vs_proto_tcp)) != EDPVS_OK) {
RTE_LOG(ERR, IPVS, "%s: fail to register TCP\n", __func__);
goto tcp_error;
}
if ((err = proto_register(&dp_vs_proto_icmp6)) != EDPVS_OK) {
RTE_LOG(ERR, IPVS, "%s: fail to register ICMPV6\n", __func__);
goto icmp6_error;
}
if ((err = proto_register(&dp_vs_proto_icmp)) != EDPVS_OK) {
RTE_LOG(ERR, IPVS, "%s: fail to register ICMP\n", __func__);
goto icmp_error;
}
if ((err = proto_register(&dp_vs_proto_esp)) != EDPVS_OK) {
RTE_LOG(ERR, IPVS, "%s: fail to register ESP\n", __func__);
goto esp_error;
}
if ((err = proto_register(&dp_vs_proto_ah)) != EDPVS_OK) {
RTE_LOG(ERR, IPVS, "%s: fail to register AH\n", __func__);
goto ah_error;
}
return EDPVS_OK;
icmp_error:
proto_unregister(&dp_vs_proto_icmp6);
icmp6_error:
proto_unregister(&dp_vs_proto_tcp);
tcp_error:
proto_unregister(&dp_vs_proto_udp);
esp_error:
proto_unregister(&dp_vs_proto_esp);
ah_error:
proto_unregister(&dp_vs_proto_ah);
return err;
}
int dp_vs_proto_term(void)
{
if (proto_unregister(&dp_vs_proto_icmp) != EDPVS_OK)
RTE_LOG(ERR, IPVS, "%s: fail to unregister ICMP\n", __func__);
if (proto_unregister(&dp_vs_proto_icmp6) != EDPVS_OK)
RTE_LOG(ERR, IPVS, "%s: fail to unregister ICMPV6\n", __func__);
if (proto_unregister(&dp_vs_proto_tcp) != EDPVS_OK)
RTE_LOG(ERR, IPVS, "%s: fail to unregister TCP\n", __func__);
if (proto_unregister(&dp_vs_proto_udp) != EDPVS_OK)
RTE_LOG(ERR, IPVS, "%s: fail to unregister UDP\n", __func__);
if (proto_unregister(&dp_vs_proto_ah) != EDPVS_OK)
RTE_LOG(ERR, IPVS, "%s: fail to unregister AH\n", __func__);
if (proto_unregister(&dp_vs_proto_esp) != EDPVS_OK)
RTE_LOG(ERR, IPVS, "%s: fail to unregister ESP\n", __func__);
return EDPVS_OK;
}