278N/A/*
278N/A* License:
278N/A* Copyright 2004 The Apache Software Foundation
278N/A*
278N/A* Licensed under the Apache License, Version 2.0 (the "License");
278N/A* you may not use this file except in compliance with the License.
278N/A* You may obtain a copy of the License at
278N/A*
278N/A* http://www.apache.org/licenses/LICENSE-2.0
278N/A*
278N/A* Unless required by applicable law or agreed to in writing, software
278N/A* distributed under the License is distributed on an "AS IS" BASIS,
278N/A* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
278N/A* See the License for the specific language governing permissions and
278N/A* limitations under the License.
278N/A*
278N/A* Module Name: mod_dtrace
278N/A*
278N/A* Purpose: Apache implements a set of hooks and filters to allow
278N/A* modules to view and modify requests sent to the server.
278N/A* This module takes advantage of this architecture to
278N/A* implement several DTrace hooks.
278N/A*
278N/A* Notes: To get the most use out of the mod_dtrace Apache module, it will
278N/A* be useful to familiarize yourself with the Apache request_rec,
278N/A* server_rec and conn_rec structures. These can be viewed on the
278N/A* docx website:
278N/A*
278N/A* http://docx.webperf.org/httpd_8h-source.html
278N/A*
278N/A* A basic overview of each structure is included below:
278N/A*
278N/A* request_rec : Contains all of the attributes (URI, filename,
278N/A* method, bytes_sent) needed to describe an
278N/A* HTTP request
278N/A*
278N/A* conn_rec : Stores the connection attributes including
278N/A* IP addresses and ports
278N/A*
278N/A* server_rec : Stores information to describe each virtual server
278N/A*
278N/A* Last Modified: 02-08-2007
278N/A*
278N/A* Author: Matty < matty91 at gmail dot com >
278N/A*
278N/A* Version: 0.3a
278N/A*
278N/A* Release history:
278N/A*
278N/A* 0.3a: Fixed bug due to NULL values -- Sebastien Bouchex Bellomie
278N/A*
278N/A* 0.2a: Initial release
278N/A*
278N/A* Build instructions are available at the following site:
278N/A* http://prefetch.net/projects/apache_modtrace/build.txt
278N/A*
278N/A*/
278N/A
278N/A#include "ap_config.h"
278N/A#include "httpd.h"
278N/A#include "http_config.h"
278N/A#include "http_connection.h"
278N/A#include "http_protocol.h"
278N/A#include "http_request.h"
278N/A#include <sys/sdt.h>
278N/A
278N/Amodule AP_MODULE_DECLARE_DATA dtrace_module;
278N/A
278N/A/*
278N/A* Probe Function Purpoose:
278N/A* This probe will fire each time a request is send to the server.
278N/A*
278N/A* arg0 -> address of the request_rec structure
278N/A*/
278N/Aint apache_receive_request(request_rec *r)
278N/A{
278N/A DTRACE_PROBE1(apache,
278N/A receive__request,
278N/A r);
278N/A
278N/A return DECLINED;
278N/A}
278N/A
278N/A/*
278N/A* This probe will fire each time the web server invokes the logging handlers.
278N/A* Since the request_rec, server_rec and conn_rec should be completely filled
278N/A* in when this probe fires -- this will be a useful probe.
278N/A*
278N/A* arg0 -> The address of the request_rec structure
278N/A*/
278N/Aint apache_log_request(request_rec *r)
278N/A{
278N/A /* apr_table_get will return the value of User-Agent or NULL */
278N/A const char *userAgent = NULL;
278N/A if (r->headers_in != NULL)
278N/A {
278N/A userAgent = apr_table_get(r->headers_in, "User-Agent");
278N/A }
278N/A
278N/A /* apr_table_get will return the value of Location or NULL */
278N/A const char *redirectLocation = NULL;
278N/A if (r->headers_out) {
278N/A redirectLocation = apr_table_get(r->headers_out, "Location");
278N/A }
278N/A
278N/A DTRACE_PROBE3(apache,
278N/A log__request,
278N/A r,
278N/A userAgent,
278N/A redirectLocation);
278N/A
278N/A return DECLINED;
278N/A}
278N/A
278N/A/*
278N/A* This probe will fire each time an httpd child process is created
278N/A*/
278N/Avoid apache_create_child(apr_pool_t *p, server_rec *s)
278N/A{
278N/A DTRACE_PROBE(apache,
278N/A create__child);
278N/A}
278N/A
278N/A/*
278N/A* This probe will fire each time a new TCP connection is created
278N/A*
278N/A* arg0 -> Client's IP address
278N/A*/
278N/Aint apache_accept_connection(conn_rec *c, void *csd)
278N/A{
278N/A DTRACE_PROBE1(apache,
278N/A accept__connection,
278N/A c);
278N/A
278N/A return DECLINED;
278N/A}
278N/A
278N/A/*
278N/A* This probe will fire when the authentication stage is encountered
278N/A*
278N/A* arg0 -> The address of the request_rec structure
278N/A*
278N/A*/
278N/Aint apache_check_user(request_rec *r)
278N/A{
278N/A DTRACE_PROBE1(apache,
278N/A check__user__credentials,
278N/A r);
278N/A
278N/A return DECLINED;
278N/A}
278N/A
278N/A/*
278N/A* This probe will fire when the access checking stage is encountered
278N/A*
278N/A* arg0 -> The address of the request_rec structure
278N/A*
278N/A*/
278N/Aint apache_check_access(request_rec *r)
278N/A{
278N/A DTRACE_PROBE1(apache,
278N/A check__access,
278N/A r);
278N/A
278N/A return DECLINED;
278N/A}
278N/A
278N/A/*
278N/A* This probe will fire when the authorization checking stage is encountered
278N/A*
278N/A* arg0 -> The address of the request_rec structure
278N/A*
278N/A*/
278N/Aint apache_check_authorization(request_rec *r)
278N/A{
278N/A DTRACE_PROBE1(apache,
278N/A check__authorization,
278N/A r);
278N/A
278N/A return DECLINED;
278N/A}
278N/A
278N/A/*
278N/A* Define the hooks and the functions registered to those hooks
278N/A*/
278N/Avoid dtrace_register_hooks(apr_pool_t *p)
278N/A{
278N/A ap_hook_post_read_request(apache_receive_request,NULL,NULL,APR_HOOK_MIDDLE);
278N/A ap_hook_child_init(apache_create_child,NULL, NULL, APR_HOOK_MIDDLE);
278N/A ap_hook_pre_connection(apache_accept_connection,NULL, NULL, APR_HOOK_MIDDLE);
278N/A ap_hook_check_user_id(apache_check_user,NULL,NULL,APR_HOOK_MIDDLE);
278N/A ap_hook_access_checker(apache_check_access,NULL,NULL,APR_HOOK_MIDDLE);
278N/A ap_hook_auth_checker(apache_check_authorization,NULL,NULL,APR_HOOK_MIDDLE);
278N/A ap_hook_log_transaction(apache_log_request,NULL,NULL,APR_HOOK_MIDDLE);
278N/A}
278N/A
278N/Amodule AP_MODULE_DECLARE_DATA dtrace_module =
278N/A{
278N/A STANDARD20_MODULE_STUFF,
278N/A NULL,
278N/A NULL,
278N/A NULL,
278N/A NULL,
278N/A NULL,
278N/A dtrace_register_hooks
278N/A};
278N/A
278N/A