Apache HTTPD
mod_proxy_fdpass.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "mod_proxy.h"
18
19#include <sys/types.h>
20#include <sys/socket.h>
21#include <sys/un.h>
22
23#ifndef CMSG_DATA
24#error This module only works on unix platforms with the correct OS support
25#endif
26
27#include "mod_proxy_fdpass.h"
28
29module AP_MODULE_DECLARE_DATA proxy_fdpass_module;
30
32{
33 const char *path;
34
35 if (ap_cstr_casecmpn(url, "fd://", 5) == 0) {
36 url += 5;
37 }
38 else {
39 return DECLINED;
40 }
41
43
44 r->filename = apr_pstrcat(r->pool, "proxy:fd://", path, NULL);
45
47 "set r->filename to %s", r->filename);
48 return OK;
49}
50
52 const char* path,
54{
56 apr_status_t rv;
57 *out_sock = NULL;
58
60 if (rv != APR_SUCCESS) {
61 return rv;
62 }
63
65 if (rv != APR_SUCCESS) {
66 return rv;
67 }
68
69 *out_sock = s;
70
71 return APR_SUCCESS;
72}
73
77{
78 apr_status_t rv;
81 struct msghdr msg;
82 struct cmsghdr *cmsg;
83 struct iovec iov;
84 char b = '\0';
85
87 if (rv != APR_SUCCESS) {
88 return rv;
89 }
90
92 if (rv != APR_SUCCESS) {
93 return rv;
94 }
95
96 memset(&msg, 0, sizeof(msg));
97
98 msg.msg_iov = &iov;
99 msg.msg_iovlen = 1;
100
101 iov.iov_base = &b;
102 iov.iov_len = 1;
103
104 cmsg = apr_palloc(p, sizeof(*cmsg) + sizeof(rawsock));
105 cmsg->cmsg_len = sizeof(*cmsg) + sizeof(rawsock);
106 cmsg->cmsg_level = SOL_SOCKET;
107 cmsg->cmsg_type = SCM_RIGHTS;
108
109 memcpy(CMSG_DATA(cmsg), &rawsock, sizeof(rawsock));
110
111 msg.msg_control = cmsg;
112 msg.msg_controllen = cmsg->cmsg_len;
113
114 rv = sendmsg(srawsock, &msg, 0);
115
116 if (rv == -1) {
117 return errno;
118 }
119
120 return APR_SUCCESS;
121}
122
124 proxy_server_conf *conf,
125 char *url, const char *proxyname,
127{
128 apr_status_t rv;
131
132 if (ap_cstr_casecmpn(url, "fd://", 5) == 0) {
133 url += 5;
134 }
135 else {
136 return DECLINED;
137 }
138
140
141 if (rv != APR_SUCCESS) {
143 "Failed to connect to '%s'", url);
145 }
146
147 {
148 int status;
149 const char *flush_method = *worker->s->flusher ? worker->s->flusher : "flush";
150
152 flush_method, "0");
153
154 if (!flush) {
156 "Unable to find configured flush provider '%s'",
159 }
160
161 status = flush->flusher(r);
162 if (status) {
163 return status;
164 }
165 }
166
168
170 if (rv != APR_SUCCESS) {
171 ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01154) "send_socket failed:");
173 }
174
175 {
177 /* Create a dummy unconnected socket, and set it as the one we were
178 * connected to, so that when the core closes it, it doesn't close
179 * the tcp connection to the client.
180 */
182 r->connection->pool);
183 if (rv != APR_SUCCESS) {
185 "failed to create dummy socket");
187 }
189 }
190
191 return OK;
192}
193
195{
196 int status;
198 apr_bucket *e;
199
201
204
206
208
209 if (status != OK) {
211 "ap_pass_brigade failed:");
212 return status;
213 }
214
215 return OK;
216}
217
218
220{
221 "flush",
223 NULL
224};
225
232
235 NULL, /* create per-directory config structure */
236 NULL, /* merge per-directory config structures */
237 NULL, /* create per-server config structure */
238 NULL, /* merge per-server config structures */
239 NULL, /* command apr_table_t */
240 register_hooks /* register hooks */
241};
#define AP_DECLARE_MODULE(foo)
char * ap_server_root_relative(apr_pool_t *p, const char *fname)
Definition config.c:1594
request_rec int int apr_table_t const char * path
request_rec * r
int flush
#define DECLINED
Definition httpd.h:457
#define OK
Definition httpd.h:456
apr_status_t ap_pass_brigade(ap_filter_t *filter, apr_bucket_brigade *bucket)
apr_socket_t * ap_get_conn_socket(conn_rec *c)
Definition core.c:5202
#define ap_set_core_module_config(v, val)
Definition http_core.h:385
#define APLOGNO(n)
Definition http_log.h:117
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_ERR
Definition http_log.h:67
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_DEBUG
Definition http_log.h:71
apr_status_t ap_register_provider(apr_pool_t *pool, const char *provider_group, const char *provider_name, const char *provider_version, const void *provider)
Definition provider.c:35
void * ap_lookup_provider(const char *provider_group, const char *provider_name, const char *provider_version)
Definition provider.c:99
void * dummy
Definition http_vhost.h:62
#define APR_BRIGADE_INSERT_TAIL(b, e)
apr_bucket * e
const char * url
Definition apr_escape.h:120
#define APR_HOOK_FIRST
Definition apr_hooks.h:301
#define HTTP_INTERNAL_SERVER_ERROR
Definition httpd.h:535
#define APR_PROTO_TCP
apr_status_t ap_proxy_connect_uds(apr_socket_t *sock, const char *uds_path, apr_pool_t *p)
void proxy_hook_canon_handler(proxy_HOOK_canon_handler_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition mod_proxy.c:3412
void proxy_hook_scheme_handler(proxy_HOOK_scheme_handler_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition mod_proxy.c:3406
#define STANDARD20_MODULE_STUFF
int ap_cstr_casecmpn(const char *s1, const char *s2, apr_size_t n)
Definition util.c:3559
@ AP_CONN_CLOSE
Definition httpd.h:1145
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
apr_socket_t * sock
apr_uint16_t apr_port_t
#define APR_INET
apr_pool_t * b
Definition apr_pools.h:529
int apr_os_sock_t
const char * s
Definition apr_strings.h:95
int int status
apr_pool_t * p
Definition md_event.c:32
Proxy Extension Module for Apache.
static const proxy_fdpass_flush builtin_flush
static apr_status_t send_socket(apr_pool_t *p, apr_socket_t *s, apr_socket_t *outbound)
static int proxy_fdpass_handler(request_rec *r, proxy_worker *worker, proxy_server_conf *conf, char *url, const char *proxyname, apr_port_t proxyport)
static void register_hooks(apr_pool_t *p)
static int proxy_fdpass_canon(request_rec *r, char *url)
static apr_status_t get_socket_from_path(apr_pool_t *p, const char *path, apr_socket_t **out_sock)
static int standard_flush(request_rec *r)
FD Passing interfaces.
#define PROXY_FDPASS_FLUSHER
return NULL
Definition mod_so.c:359
apr_pool_t * pool
Definition httpd.h:1154
ap_conn_keepalive_e keepalive
Definition httpd.h:1223
struct apr_bucket_alloc_t * bucket_alloc
Definition httpd.h:1201
struct ap_conf_vector_t * conn_config
Definition httpd.h:1190
proxy_worker_shared * s
Definition mod_proxy.h:505
A structure that represents the current request.
Definition httpd.h:845
struct ap_filter_t * output_filters
Definition httpd.h:1070
apr_pool_t * pool
Definition httpd.h:847
char * filename
Definition httpd.h:1018
conn_rec * connection
Definition httpd.h:849
apr_status_t apr_os_sock_get(apr_os_sock_t *thesock, apr_socket_t *sock)
Definition sockets.c:506
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type, int protocol, apr_pool_t *cont)
Definition sockets.c:116