• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

HttpSessionAccept.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #include "HttpSessionAccept.h"
00025 #include "IPAllow.h"
00026 #include "HttpClientSession.h"
00027 #include "I_Machine.h"
00028 #include "Error.h"
00029 
00030 void
00031 HttpSessionAccept::accept(NetVConnection * netvc, MIOBuffer * iobuf, IOBufferReader * reader)
00032 {
00033   sockaddr const* client_ip = netvc->get_remote_addr();
00034   const AclRecord *acl_record = NULL;
00035   ip_port_text_buffer ipb;
00036   IpAllow::scoped_config ipallow;
00037 
00038   // The backdoor port is now only bound to "localhost", so no
00039   // reason to check for if it's incoming from "localhost" or not.
00040   if (backdoor) {
00041     acl_record = IpAllow::AllMethodAcl();
00042   } else if (ipallow && (((acl_record = ipallow->match(client_ip)) == NULL) || (acl_record->isEmpty()))) {
00043     ////////////////////////////////////////////////////
00044     // if client address forbidden, close immediately //
00045     ////////////////////////////////////////////////////
00046     Warning("client '%s' prohibited by ip-allow policy", ats_ip_ntop(client_ip, ipb, sizeof(ipb)));
00047     netvc->do_io_close();
00048 
00049     return;
00050   }
00051 
00052   netvc->attributes = transport_type;
00053 
00054   if (is_debug_tag_set("http_seq")) {
00055     Debug("http_seq", "[HttpSessionAccept:mainEvent %p] accepted connection from %s transport type = %d", netvc, ats_ip_nptop(client_ip, ipb, sizeof(ipb)), netvc->attributes);
00056   }
00057 
00058   HttpClientSession *new_session = THREAD_ALLOC_INIT(httpClientSessionAllocator, this_ethread());
00059 
00060   // copy over session related data.
00061   new_session->f_outbound_transparent = f_outbound_transparent;
00062   new_session->f_transparent_passthrough = f_transparent_passthrough;
00063   new_session->outbound_ip4 = outbound_ip4;
00064   new_session->outbound_ip6 = outbound_ip6;
00065   new_session->outbound_port = outbound_port;
00066   new_session->host_res_style = ats_host_res_from(client_ip->sa_family, host_res_preference);
00067   new_session->acl_record = acl_record;
00068 
00069   new_session->new_connection(netvc, iobuf, reader, backdoor);
00070 
00071   return;
00072 }
00073 
00074 int
00075 HttpSessionAccept::mainEvent(int event, void *data)
00076 {
00077   ink_release_assert(event == NET_EVENT_ACCEPT || event == EVENT_ERROR);
00078   ink_release_assert((event == NET_EVENT_ACCEPT) ? (data != 0) : (1));
00079 
00080   if (event == NET_EVENT_ACCEPT) {
00081     this->accept(static_cast<NetVConnection *>(data), NULL, NULL);
00082     return EVENT_CONT;
00083   }
00084 
00085   /////////////////
00086   // EVENT_ERROR //
00087   /////////////////
00088   if (((long) data) == -ECONNABORTED) {
00089     /////////////////////////////////////////////////
00090     // Under Solaris, when accept() fails and sets //
00091     // errno to EPROTO, it means the client has    //
00092     // sent a TCP reset before the connection has  //
00093     // been accepted by the server...  Note that   //
00094     // in 2.5.1 with the Internet Server Supplement//
00095     // and also in 2.6 the errno for this case has //
00096     // changed from EPROTO to ECONNABORTED.        //
00097     /////////////////////////////////////////////////
00098 
00099     // FIX: add time to user_agent_hangup
00100     HTTP_SUM_DYN_STAT(http_ua_msecs_counts_errors_pre_accept_hangups_stat, 0);
00101   }
00102 
00103   MachineFatal("HTTP accept received fatal error: errno = %d", -((int)(intptr_t)data));
00104   return EVENT_CONT;
00105 }

Generated by  doxygen 1.7.1