Inquirer.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 49 SNMP Interface */
10
11#include "squid.h"
12#include "base/TextException.h"
13#include "comm.h"
14#include "comm/Connection.h"
15#include "CommCalls.h"
16#include "ipc/UdsOp.h"
17#include "snmp/Inquirer.h"
18#include "snmp/Request.h"
19#include "snmp/Response.h"
20#include "snmp_core.h"
21
23
24Snmp::Inquirer::Inquirer(const Request& aRequest, const Ipc::StrandCoords& coords):
25 Ipc::Inquirer(aRequest.clone(), coords, 2),
26 aggrPdu(aRequest.pdu)
27{
29 conn->fd = aRequest.fd;
30 ImportFdIntoComm(conn, SOCK_DGRAM, IPPROTO_UDP, Ipc::fdnInSnmpSocket);
31
32 debugs(49, 5, MYNAME);
33 closer = asyncCall(49, 5, "Snmp::Inquirer::noteCommClosed",
36
37 // forget client FD to avoid sending it to strands that may forget to close
38 if (Request *snmpRequest = dynamic_cast<Request*>(request.getRaw()))
39 snmpRequest->fd = -1;
40}
41
43void
45{
47 if (closer != nullptr) {
49 closer = nullptr;
50 }
51 conn->close();
52 }
53 conn = nullptr;
54}
55
56void
58{
59 debugs(49, 5, MYNAME);
62 inquire();
63}
64
65void
66Snmp::Inquirer::handleException(const std::exception& e)
67{
68 aggrPdu.errstat = SNMP_ERR_GENERR;
70}
71
72bool
74{
75 Snmp::Response& response = static_cast<Snmp::Response&>(*aResponse);
76 bool error = response.pdu.errstat != SNMP_ERR_NOERROR;
77 if (error) {
78 aggrPdu = response.pdu;
79 } else {
80 aggrPdu.aggregate(response.pdu);
81 }
82 return !error;
83}
84
86void
88{
89 debugs(49, 5, MYNAME);
90 Must(!Comm::IsConnOpen(conn) || conn->fd == params.conn->fd);
91 closer = nullptr;
92 if (conn) {
93 conn->noteClosure();
94 conn = nullptr;
95 }
96 mustStop("commClosed");
97}
98
99bool
101{
102 return !writer && Ipc::Inquirer::doneAll();
103}
104
105void
107{
108 debugs(49, 5, MYNAME);
109
111 return; // client gone
112
113 aggrPdu.fixAggregate();
114 aggrPdu.command = SNMP_PDU_RESPONSE;
115 u_char buffer[SNMP_REQUEST_SIZE];
116 int len = sizeof(buffer);
117 Snmp::Request& req = static_cast<Snmp::Request&>(*request);
118 snmp_build(&req.session, &aggrPdu, buffer, &len);
119 comm_udp_sendto(conn->fd, req.address, buffer, len);
120}
121
AsyncCall * asyncCall(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:154
#define Must(condition)
Definition: TextException.h:71
int conn
the current server connection FD
Definition: Transport.cc:26
void error(char *format,...)
Comm::ConnectionPointer conn
Definition: CommCalls.h:85
virtual bool doneAll() const
whether positive goal has been reached
Definition: Inquirer.cc:116
virtual void handleException(const std::exception &e)
do specific exception handling
Definition: Inquirer.cc:122
virtual void start()
called by AsyncStart; do not call directly
Definition: Inquirer.cc:57
Request::Pointer request
cache manager request received from client
Definition: Inquirer.h:74
C * getRaw() const
Definition: RefCount.h:80
virtual void handleException(const std::exception &e)
do specific exception handling
Definition: Inquirer.cc:66
virtual void start()
called by AsyncStart; do not call directly
Definition: Inquirer.cc:57
void noteCommClosed(const CommCloseCbParams &params)
called when the some external force closed our socket
Definition: Inquirer.cc:87
AsyncCall::Pointer closer
comm_close handler
Definition: Inquirer.h:52
virtual bool doneAll() const
whether positive goal has been reached
Definition: Inquirer.cc:100
virtual void sendResponse()
send response to client
Definition: Inquirer.cc:106
Comm::ConnectionPointer conn
client connection descriptor
Definition: Inquirer.h:49
Inquirer(const Request &aRequest, const Ipc::StrandCoords &coords)
Definition: Inquirer.cc:24
virtual bool aggregate(Ipc::Response::Pointer aResponse)
perform aggregating of responses and returns true if need to continue
Definition: Inquirer.cc:73
virtual void cleanup()
closes our copy of the client connection socket
Definition: Inquirer.cc:44
void aggregate(const Pdu &pdu)
Definition: Pdu.cc:55
SNMP request.
Definition: Request.h:25
Session session
SNMP session.
Definition: Request.h:37
Ip::Address address
client address
Definition: Request.h:39
int fd
client connection descriptor
Definition: Request.h:38
Pdu pdu
SNMP protocol data unit.
Definition: Response.h:33
AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *handler, void *data)
Definition: comm.cc:921
void comm_remove_close_handler(int fd, CLCB *handler, void *data)
Definition: comm.cc:950
int comm_udp_sendto(int fd, const Ip::Address &to_addr, const void *buf, int len)
Definition: comm.cc:890
#define MYNAME
Definition: Stream.h:238
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
CBDATA_NAMESPACED_CLASS_INIT(Ipc, Inquirer)
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:27
Definition: IpcIoFile.h:24
@ fdnInSnmpSocket
Definition: FdNotes.h:22
const Comm::ConnectionPointer & ImportFdIntoComm(const Comm::ConnectionPointer &conn, int socktype, int protocol, FdNoteId noteId)
import socket fd from another strand into our Comm state
Definition: UdsOp.cc:194
std::vector< StrandCoord > StrandCoords
a collection of strand coordinates; the order, if any, is owner-dependent
Definition: StrandCoords.h:19
SSL Connection
Definition: Session.h:45
Definition: forward.h:15
int snmp_build(struct snmp_session *, struct snmp_pdu *, u_char *, int *)
Definition: snmp_api.c:106
#define SNMP_REQUEST_SIZE
Definition: snmp_core.h:21
#define SNMP_ERR_GENERR
Definition: snmp_error.h:47
#define SNMP_ERR_NOERROR
Definition: snmp_error.h:42
#define SNMP_PDU_RESPONSE
Definition: snmp_pdu.h:94
int errstat
Definition: snmp_pdu.h:55

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors