1 /** @file
2
3 A brief file description
4
5 @section license License
6
7 Licensed to the Apache Software Foundation (ASF) under one
8 or more contributor license agreements. See the NOTICE file
9 distributed with this work for additional information
10 regarding copyright ownership. The ASF licenses this file
11 to you under the Apache License, Version 2.0 (the
12 "License"); you may not use this file except in compliance
13 with the License. You may obtain a copy of the License at
14
15 http://www.apache.org/licenses/LICENSE-2.0
16
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
23
24 /****************************************************************************
25
26 NetVConnection.cc
27
28 This file implements an I/O Processor for network I/O.
29
30
31 ****************************************************************************/
32
33 #include "P_Net.h"
34 #include "ts/apidefs.h"
35
36 ////
37 // NetVConnection
38 //
39 Action *
send_OOB(Continuation *,char *,int)40 NetVConnection::send_OOB(Continuation *, char *, int)
41 {
42 return ACTION_RESULT_DONE;
43 }
44
45 void
cancel_OOB()46 NetVConnection::cancel_OOB()
47 {
48 return;
49 }
50
51 /**
52 PROXY Protocol check with IOBufferReader
53
54 If the buffer has PROXY Protocol, it will be consumed by this function.
55 */
56 bool
has_proxy_protocol(IOBufferReader * reader)57 NetVConnection::has_proxy_protocol(IOBufferReader *reader)
58 {
59 char buf[PPv1_CONNECTION_HEADER_LEN_MAX + 1];
60 ts::TextView tv;
61 tv.assign(buf, reader->memcpy(buf, sizeof(buf), 0));
62
63 size_t len = proxy_protocol_parse(&this->pp_info, tv);
64
65 if (len > 0) {
66 reader->consume(len);
67 return true;
68 }
69
70 return false;
71 }
72
73 /**
74 PROXY Protocol check with buffer
75
76 If the buffer has PROXY Protocol, it will be consumed by this function.
77 */
78 bool
has_proxy_protocol(char * buffer,int64_t * bytes_r)79 NetVConnection::has_proxy_protocol(char *buffer, int64_t *bytes_r)
80 {
81 ts::TextView tv;
82 tv.assign(buffer, *bytes_r);
83
84 size_t len = proxy_protocol_parse(&this->pp_info, tv);
85
86 if (len <= 0) {
87 *bytes_r = -EAGAIN;
88 return false;
89 }
90
91 *bytes_r -= len;
92 if (*bytes_r <= 0) {
93 *bytes_r = -EAGAIN;
94 } else {
95 Debug("ssl", "Moving %" PRId64 " characters remaining in the buffer from %p to %p", *bytes_r, buffer + len, buffer);
96 memmove(buffer, buffer + len, *bytes_r);
97 }
98
99 return true;
100 }
101
102 ////
103 // NetVCOptions
104 //
105 std::string_view
get_proto_string() const106 NetVCOptions::get_proto_string() const
107 {
108 switch (ip_proto) {
109 case USE_TCP:
110 return IP_PROTO_TAG_TCP;
111 case USE_UDP:
112 return IP_PROTO_TAG_UDP;
113 default:
114 break;
115 }
116 return {};
117 }
118
119 std::string_view
get_family_string() const120 NetVCOptions::get_family_string() const
121 {
122 switch (ip_family) {
123 case AF_INET:
124 return IP_PROTO_TAG_IPV4;
125 case AF_INET6:
126 return IP_PROTO_TAG_IPV6;
127 default:
128 break;
129 }
130 return {};
131 }
132