*
*/
#include "squid.h"
-#include "comm.h"
-#include "cache_snmp.h"
#include "acl/FilledChecklist.h"
-#include "ip/IpAddress.h"
+#include "cache_snmp.h"
+#include "comm.h"
+#include "ipc/StartListening.h"
+#include "compat/strsep.h"
+#include "ip/Address.h"
#define SNMP_REQUEST_SIZE 4096
#define MAX_PROTOSTAT 5
-IpAddress theOutSNMPAddr;
+/// dials snmpConnectionOpened call
+class SnmpListeningStartedDialer: public CallDialer,
+ public Ipc::StartListeningCb
+{
+public:
+ typedef void (*Handler)(int fd, int errNo);
+ SnmpListeningStartedDialer(Handler aHandler): handler(aHandler) {}
+
+ virtual void print(std::ostream &os) const { startPrint(os) << ')'; }
+
+ virtual bool canDial(AsyncCall &) const { return true; }
+ virtual void dial(AsyncCall &) { (handler)(fd, errNo); }
+
+public:
+ Handler handler;
+};
+
+
+Ip::Address theOutSNMPAddr;
typedef struct _mib_tree_entry mib_tree_entry;
typedef oid *(instance_Fn) (oid * name, snint * len, mib_tree_entry * current, oid_ParseFn ** Fn);
mib_tree_entry *mib_tree_head;
mib_tree_entry *mib_tree_last;
+static void snmpIncomingConnectionOpened(int fd, int errNo);
+static void snmpOutgoingConnectionOpened(int fd, int errNo);
+
static mib_tree_entry * snmpAddNodeStr(const char *base_str, int o, oid_ParseFn * parsefunction, instance_Fn * instancefunction);
static mib_tree_entry *snmpAddNode(oid * name, int len, oid_ParseFn * parsefunction, instance_Fn * instancefunction, int children,...);
static oid *snmpCreateOid(int length,...);
void
snmpConnectionOpen(void)
{
- struct addrinfo *xaddr = NULL;
- int x;
-
debugs(49, 5, "snmpConnectionOpen: Called");
if (Config.Port.snmp > 0) {
Config.Addrs.snmp_incoming.SetPort(Config.Port.snmp);
- enter_suid();
- theInSnmpConnection = comm_open_listener(SOCK_DGRAM,
- IPPROTO_UDP,
- Config.Addrs.snmp_incoming,
- COMM_NONBLOCKING,
- "SNMP Port");
- leave_suid();
-
- if (theInSnmpConnection < 0)
- fatal("Cannot open SNMP Port");
- commSetSelect(theInSnmpConnection, COMM_SELECT_READ, snmpHandleUdp, NULL, 0);
+ AsyncCall::Pointer call = asyncCall(49, 2,
+ "snmpIncomingConnectionOpened",
+ SnmpListeningStartedDialer(&snmpIncomingConnectionOpened));
- debugs(1, 1, "Accepting SNMP messages on " << Config.Addrs.snmp_incoming << ", FD " << theInSnmpConnection << ".");
+ Ipc::StartListening(SOCK_DGRAM,
+ IPPROTO_UDP,
+ Config.Addrs.snmp_incoming,
+ COMM_NONBLOCKING,
+ Ipc::fdnInSnmpSocket, call);
if (!Config.Addrs.snmp_outgoing.IsNoAddr()) {
Config.Addrs.snmp_outgoing.SetPort(Config.Port.snmp);
- enter_suid();
- theOutSnmpConnection = comm_open_listener(SOCK_DGRAM,
- IPPROTO_UDP,
- Config.Addrs.snmp_outgoing,
- COMM_NONBLOCKING,
- "SNMP Port");
- leave_suid();
- if (theOutSnmpConnection < 0)
- fatal("Cannot open Outgoing SNMP Port");
+ AsyncCall::Pointer call = asyncCall(49, 2,
+ "snmpOutgoingConnectionOpened",
+ SnmpListeningStartedDialer(&snmpOutgoingConnectionOpened));
- commSetSelect(theOutSnmpConnection,
- COMM_SELECT_READ,
- snmpHandleUdp,
- NULL, 0);
+ Ipc::StartListening(SOCK_DGRAM,
+ IPPROTO_UDP,
+ Config.Addrs.snmp_outgoing,
+ COMM_NONBLOCKING,
+ Ipc::fdnOutSnmpSocket, call);
+ }
+ }
+}
- debugs(1, 1, "Outgoing SNMP messages on " << Config.Addrs.snmp_outgoing << ", FD " << theOutSnmpConnection << ".");
+static void
+snmpIncomingConnectionOpened(int fd, int errNo)
+{
+ theInSnmpConnection = fd;
+ if (theInSnmpConnection < 0)
+ fatal("Cannot open Incoming SNMP Port");
- fd_note(theOutSnmpConnection, "Outgoing SNMP socket");
+ commSetSelect(theInSnmpConnection, COMM_SELECT_READ, snmpHandleUdp, NULL,
+ 0);
+
+ debugs(1, 1, "Accepting SNMP messages on " << Config.Addrs.snmp_incoming <<
+ ", FD " << theInSnmpConnection << ".");
+
+ if (Config.Addrs.snmp_outgoing.IsNoAddr())
+ theOutSnmpConnection = theInSnmpConnection;
+}
+
+static void
+snmpOutgoingConnectionOpened(int fd, int errNo)
+{
+ theOutSnmpConnection = fd;
+ if (theOutSnmpConnection < 0)
+ fatal("Cannot open Outgoing SNMP Port");
+
+ commSetSelect(theOutSnmpConnection, COMM_SELECT_READ, snmpHandleUdp, NULL,
+ 0);
+
+ debugs(1, 1, "Outgoing SNMP messages on " << Config.Addrs.snmp_outgoing <<
+ ", FD " << theOutSnmpConnection << ".");
+
+ {
+ struct addrinfo *xaddr = NULL;
+ int x;
- fd_note(theInSnmpConnection, "Incoming SNMP socket");
- } else {
- theOutSnmpConnection = theInSnmpConnection;
- }
theOutSNMPAddr.SetEmpty();
snmpHandleUdp(int sock, void *not_used)
{
LOCAL_ARRAY(char, buf, SNMP_REQUEST_SIZE);
- IpAddress from;
+ Ip::Address from;
snmp_request_t *snmp_rq;
int len;
client_Inst(oid * name, snint * len, mib_tree_entry * current, oid_ParseFn ** Fn)
{
oid *instance = NULL;
- IpAddress laddr;
- IpAddress *aux;
+ Ip::Address laddr;
+ Ip::Address *aux;
int size = 0;
int newshift = 0;
}
int i, r = 1;
- while (r <= namelen) {
+ while (r < namelen) {
/* Find the child node which matches this */
for (i = 0; i < e->children && e->leaves[i]->name[r] != name[r]; i++) ; // seek-loop
*name = NULL;
*nl = 0;
char *s = xstrdup(str);
+ char *s_ = s;
/* Parse the OID string into oid bits */
- while ( (p = strsep(&s, delim)) != NULL) {
+ while ( (p = strsep(&s_, delim)) != NULL) {
*name = (oid*)xrealloc(*name, sizeof(oid) * ((*nl) + 1));
(*name)[*nl] = atoi(p);
(*nl)++;
oid == 32.1.50.239.162.33.251.20.50.0.0.0.0.0.0.0.0.0.1
*/
void
-addr2oid(IpAddress &addr, oid * Dest)
+addr2oid(Ip::Address &addr, oid * Dest)
{
u_int i ;
u_char *cp = NULL;
IPv6 adress : 20:01:32:ef:a2:21:fb:32:00:00:00:00:00:00:00:00:OO:01
*/
void
-oid2addr(oid * id, IpAddress &addr, u_int size)
+oid2addr(oid * id, Ip::Address &addr, u_int size)
{
struct in_addr iaddr;
u_int i;