-
Notifications
You must be signed in to change notification settings - Fork 860
Expand file tree
/
Copy pathNetVConnection.cc
More file actions
166 lines (132 loc) · 3.58 KB
/
NetVConnection.cc
File metadata and controls
166 lines (132 loc) · 3.58 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
/** @file
A brief file description
@section license License
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/****************************************************************************
NetVConnection.cc
This file implements an I/O Processor for network I/O.
****************************************************************************/
#include "iocore/net/NetVConnection.h"
#include "iocore/eventsystem/IOBuffer.h"
#include "tsutil/DbgCtl.h"
#include <swoc/TextView.h>
namespace
{
DbgCtl dbg_ctl_ssl{"ssl"};
} // end anonymous namespace
////
// NetVConnection
//
/**
PROXY Protocol preface check with IOBufferReader.
*/
bool
NetVConnection::has_proxy_protocol_preface(IOBufferReader *reader) const
{
if (reader == nullptr) {
return false;
}
swoc::TextView tv;
char preface[PPv2_CONNECTION_HEADER_LEN];
tv.assign(preface, reader->memcpy(preface, sizeof(preface), 0));
return proxy_protocol_detect(tv);
}
/**
PROXY Protocol preface check with a raw buffer.
*/
bool
NetVConnection::has_proxy_protocol_preface(const char *buffer, int64_t bytes_r) const
{
if (buffer == nullptr || bytes_r <= 0) {
return false;
}
swoc::TextView tv;
tv.assign(buffer, static_cast<size_t>(bytes_r));
return proxy_protocol_detect(tv);
}
/**
PROXY Protocol check with IOBufferReader
If the buffer has PROXY Protocol, it will be consumed by this function.
*/
bool
NetVConnection::has_proxy_protocol(IOBufferReader *reader, int max_header_size)
{
swoc::TextView tv;
if (!this->has_proxy_protocol_preface(reader)) {
return false;
}
int bufsize = max_header_size;
char buf[bufsize];
tv.assign(buf, reader->memcpy(buf, bufsize, 0));
size_t len = proxy_protocol_parse(&this->pp_info, tv);
if (len > 0) {
reader->consume(len);
return true;
}
return false;
}
/**
PROXY Protocol check with buffer
If the buffer has PROXY Protocol, it will be consumed by this function.
*/
bool
NetVConnection::has_proxy_protocol(char *buffer, int64_t *bytes_r)
{
swoc::TextView tv;
tv.assign(buffer, *bytes_r);
size_t len = proxy_protocol_parse(&this->pp_info, tv);
if (len <= 0) {
*bytes_r = -EAGAIN;
return false;
}
*bytes_r -= len;
if (*bytes_r <= 0) {
*bytes_r = -EAGAIN;
} else {
Dbg(dbg_ctl_ssl, "Moving %" PRId64 " characters remaining in the buffer from %p to %p", *bytes_r, buffer + len, buffer);
memmove(buffer, buffer + len, *bytes_r);
}
return true;
}
////
// NetVCOptions
//
std::string_view
NetVCOptions::get_proto_string() const
{
switch (ip_proto) {
case USE_TCP:
return IP_PROTO_TAG_TCP;
case USE_UDP:
return IP_PROTO_TAG_UDP;
default:
break;
}
return {};
}
std::string_view
NetVCOptions::get_family_string() const
{
switch (ip_family) {
case AF_INET:
return IP_PROTO_TAG_IPV4;
case AF_INET6:
return IP_PROTO_TAG_IPV6;
default:
break;
}
return {};
}