]>
Commit | Line | Data |
---|---|---|
51ea0904 CT |
1 | /* |
2 | * $Id$ | |
3 | * | |
4 | * DEBUG: section 49 SNMP Interface | |
5 | * | |
6 | */ | |
7 | ||
8 | #include "config.h" | |
9 | #include "base/TextException.h" | |
10 | #include "CommCalls.h" | |
11 | #include "ipc/UdsOp.h" | |
12 | #include "snmp_core.h" | |
d6e3ad20 CT |
13 | #include "snmp/Inquirer.h" |
14 | #include "snmp/Response.h" | |
15 | #include "snmp/Request.h" | |
51ea0904 CT |
16 | |
17 | ||
18 | CBDATA_NAMESPACED_CLASS_INIT(Snmp, Inquirer); | |
19 | ||
20 | ||
21 | Snmp::Inquirer::Inquirer(const Request& aRequest, const Ipc::StrandCoords& coords): | |
22 | Ipc::Inquirer(aRequest.clone(), coords, 2), | |
23 | aggrPdu(aRequest.pdu), | |
24 | fd(ImportFdIntoComm(aRequest.fd, SOCK_DGRAM, IPPROTO_UDP, Ipc::fdnInSnmpSocket)) | |
25 | { | |
26 | debugs(49, 5, HERE); | |
933a6aed | 27 | closer = asyncCall(49, 5, "Snmp::Inquirer::noteCommClosed", |
51ea0904 CT |
28 | CommCbMemFunT<Inquirer, CommCloseCbParams>(this, &Inquirer::noteCommClosed)); |
29 | comm_add_close_handler(fd, closer); | |
30 | } | |
31 | ||
32 | /// closes our copy of the client connection socket | |
33 | void | |
34 | Snmp::Inquirer::cleanup() | |
35 | { | |
36 | if (fd >= 0) { | |
37 | if (closer != NULL) { | |
38 | comm_remove_close_handler(fd, closer); | |
39 | closer = NULL; | |
40 | } | |
41 | comm_close(fd); | |
42 | fd = -1; | |
43 | } | |
44 | } | |
45 | ||
46 | void | |
47 | Snmp::Inquirer::start() | |
48 | { | |
49 | debugs(49, 5, HERE); | |
50 | Ipc::Inquirer::start(); | |
51 | Must(fd >= 0); | |
52 | inquire(); | |
53 | } | |
54 | ||
55 | void | |
56 | Snmp::Inquirer::handleException(const std::exception& e) | |
57 | { | |
58 | aggrPdu.errstat = SNMP_ERR_GENERR; | |
59 | Ipc::Inquirer::handleException(e); | |
60 | } | |
61 | ||
62 | bool | |
63 | Snmp::Inquirer::aggregate(Response::Pointer aResponse) | |
64 | { | |
65 | Snmp::Response& response = static_cast<Snmp::Response&>(*aResponse); | |
66 | bool error = response.pdu.errstat != SNMP_ERR_NOERROR; | |
67 | if (error) { | |
68 | aggrPdu = response.pdu; | |
69 | } else { | |
70 | aggrPdu.aggregate(response.pdu); | |
71 | } | |
5654a599 | 72 | return !error; |
51ea0904 CT |
73 | } |
74 | ||
75 | /// called when the some external force closed our socket | |
76 | void | |
77 | Snmp::Inquirer::noteCommClosed(const CommCloseCbParams& params) | |
78 | { | |
79 | debugs(49, 5, HERE); | |
80 | Must(fd < 0 || fd == params.fd); | |
81 | fd = -1; | |
82 | mustStop("commClosed"); | |
83 | } | |
84 | ||
85 | bool | |
86 | Snmp::Inquirer::doneAll() const | |
87 | { | |
88 | return !writer && Ipc::Inquirer::doneAll(); | |
89 | } | |
90 | ||
91 | void | |
92 | Snmp::Inquirer::sendResponse() | |
93 | { | |
94 | debugs(49, 5, HERE); | |
e26257b2 | 95 | aggrPdu.fixAggregate(); |
51ea0904 CT |
96 | aggrPdu.command = SNMP_PDU_RESPONSE; |
97 | u_char buffer[SNMP_REQUEST_SIZE]; | |
98 | int len = sizeof(buffer); | |
99 | Snmp::Request& req = static_cast<Snmp::Request&>(*request); | |
100 | snmp_build(&req.session, &aggrPdu, buffer, &len); | |
101 | comm_udp_sendto(fd, req.address, buffer, len); | |
102 | } |