Regents of the University of California (UCSD)
Reinhard Posmyk <Reinhard.Posmyk@arxes.de>
Reinhard Sojka <reinhard.sojka@parlament.gv.at>
- Renaud Metrich <renaud.metrich@gmail.com>
Rene Geile <rene.geile@t-online.de>
Reuben Farrelly <reuben@reub.net>
Ricardo Ferreira Ribeiro <garb12@pm.me>
#if SQUID_SNMP
-Ip::Address *
-client_entry(Ip::Address *current)
+const Ip::Address *
+client_entry(const Ip::Address *current)
{
char key[MAX_IPSTRLEN];
hash_first(client_table);
MemBuf tmp;
debugs(49, 6, "Current : length=" << Var->name_length << ": " << snmpDebugOid(Var->name, Var->name_length, tmp));
if (Var->name_length == 16) {
- oid2addr(&(Var->name[12]), keyIp, 4);
+ keyIp = oid2addr(&(Var->name[12]), 4).value();
} else if (Var->name_length == 28) {
- oid2addr(&(Var->name[12]), keyIp, 16);
+ keyIp = oid2addr(&(Var->name[12]), 16).value();
} else {
*ErrP = SNMP_ERR_NOSUCHNAME;
return nullptr;
#endif
#if SQUID_SNMP
-Ip::Address *client_entry(Ip::Address *current);
+const Ip::Address *client_entry(const Ip::Address *);
variable_list *snmp_meshCtblFn(variable_list *, snint *);
#endif
// parse it into status=, url= and rewrite-url= keys
if (replySize) {
MemBuf replyBuffer;
- replyBuffer.init(replySize + 1, replySize + 1); // with space for 0-terminator added by append()
- Assure(replySize <= size_t(reply.other().contentSize()));
- replyBuffer.append(reply.other().content(), replySize);
+ replyBuffer.init(replySize, replySize);
+ replyBuffer.append(reply.other().content(), reply.other().contentSize());
char * result = replyBuffer.content();
Helper::Reply newReply;
{
oid *instance = nullptr;
Ip::Address laddr;
- Ip::Address *aux;
+ const Ip::Address *aux;
int size = 0;
int newshift = 0;
*len += size ;
}
} else {
- int shift = *len - current->len ; // i.e 4 or 16
- oid2addr(&name[*len - shift], laddr,shift);
- aux = client_entry(&laddr);
+ const auto ip = oid2addr(&name[current->len], *len - current->len);
+ aux = ip ? client_entry(&ip.value()) : nullptr;
if (aux)
laddr = *aux;
else
* Debug calls, prints out the OID for debugging purposes.
*/
const char *
-snmpDebugOid(oid * Name, snint Len, MemBuf &outbuf)
+snmpDebugOid(const oid * const Name, const snint Len, MemBuf &outbuf)
{
char mbuf[16];
int x;
oid == 32.1.50.239.162.33.251.20.50.0.0.0.0.0.0.0.0.0.1 ==>
IPv6 address : 20:01:32:ef:a2:21:fb:32:00:00:00:00:00:00:00:00:OO:01
*/
-void
-oid2addr(oid * id, Ip::Address &addr, u_int size)
+std::optional<Ip::Address>
+oid2addr(const oid * const id, const size_t size)
{
+ MemBuf tmp;
+ debugs(49, 7, "oid=" << snmpDebugOid(id, size, tmp));
+
struct in_addr i4addr;
struct in6_addr i6addr;
u_int i;
u_char *cp;
if ( size == sizeof(struct in_addr) )
cp = (u_char *) &(i4addr.s_addr);
- else
+ else if ( size == sizeof(struct in6_addr) )
cp = (u_char *) &(i6addr);
- MemBuf tmp;
- debugs(49, 7, "oid2addr: id : " << snmpDebugOid(id, size, tmp) );
+ else
+ return std::nullopt;
+
for (i=0 ; i<size; ++i) {
cp[i] = id[i];
}
if ( size == sizeof(struct in_addr) )
- addr = i4addr;
+ return i4addr;
else
- addr = i6addr;
+ return i6addr;
}
int
#include "ip/forward.h"
#include "snmp_vars.h"
+#include <optional>
+
class MemBuf;
#define SNMP_REQUEST_SIZE 4096
extern Comm::ConnectionPointer snmpOutgoingConn;
extern PF snmpHandleUdp;
-const char * snmpDebugOid(oid * Name, snint Len, MemBuf &outbuf);
+const char * snmpDebugOid(const oid *, snint Len, MemBuf &outbuf);
void addr2oid(Ip::Address &addr, oid *Dest);
-void oid2addr(oid *Dest, Ip::Address &addr, u_int code);
+
+/// Parses raw OID suffix of a given size as an IP address.
+/// \returns nil if the suffix does not represent an IPv4 or IPv6 address
+std::optional<Ip::Address> oid2addr(const oid *, size_t);
namespace Acl
{
ClientInfo *clientdbGetInfo(const Ip::Address &) STUB_RETVAL(nullptr)
#endif
#if SQUID_SNMP
-Ip::Address *client_entry(Ip::Address *) STUB_RETVAL(nullptr)
+const Ip::Address *client_entry(const Ip::Address *) STUB_RETVAL(nullptr)
variable_list *snmp_meshCtblFn(variable_list *, snint *) STUB_RETVAL(nullptr)
#endif