"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/agent/subagents/freebsd/net.cpp" between
netxms-3.8.382.tar.gz and netxms-3.8.405.tar.gz

About: NetXMS is a multi-platform open source network management and monitoring system.

net.cpp  (netxms-3.8.382):net.cpp  (netxms-3.8.405)
/* /*
** NetXMS subagent for FreeBSD ** NetXMS subagent for FreeBSD
** Copyright (C) 2004 Alex Kirhenshtein ** Copyright (C) 2004 Alex Kirhenshtein
** Copyright (C) 2008 Mark Ibell ** Copyright (C) 2008 Mark Ibell
** Copyright (C) 2016 Raden Solutions ** Copyright (C) 2016-2021 Raden Solutions
** **
** This program is free software; you can redistribute it and/or modify ** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by ** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or ** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version. ** (at your option) any later version.
** **
** This program is distributed in the hope that it will be useful, ** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details. ** GNU General Public License for more details.
skipping to change at line 43 skipping to change at line 43
#include <net/if_media.h> #include <net/if_media.h>
#include <net/if_dl.h> #include <net/if_dl.h>
#include <net/if_types.h> #include <net/if_types.h>
#include <net/if_var.h> #include <net/if_var.h>
#include <net/route.h> #include <net/route.h>
#include <netinet/if_ether.h> #include <netinet/if_ether.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#if __FreeBSD__ >= 13
#include <net/if_mib.h>
#else
#include <kvm.h> #include <kvm.h>
#include <nlist.h> #include <nlist.h>
#endif
#if HAVE_NET_ISO88025_H #if HAVE_NET_ISO88025_H
#include <net/iso88025.h> #include <net/iso88025.h>
#endif #endif
#include "freebsd_subagent.h" #include "freebsd_subagent.h"
typedef struct t_IfList typedef struct t_IfList
{ {
char *name; char *name;
skipping to change at line 190 skipping to change at line 195
int nSocket; int nSocket;
nRet = SYSINFO_RC_ERROR; nRet = SYSINFO_RC_ERROR;
nSocket = socket(AF_INET, SOCK_DGRAM, 0); nSocket = socket(AF_INET, SOCK_DGRAM, 0);
if (nSocket > 0) if (nSocket > 0)
{ {
struct ifmediareq ifmr; struct ifmediareq ifmr;
memset(&ifmr, 0, sizeof(ifmr)); memset(&ifmr, 0, sizeof(ifmr));
strncpy(ifmr.ifm_name, szArg, sizeof(ifmr.ifm_nam e)); strlcpy(ifmr.ifm_name, szArg, sizeof(ifmr.ifm_nam e));
if (ioctl(nSocket, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) if (ioctl(nSocket, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0)
{ {
if ((ifmr.ifm_status & IFM_AVALID) == IFM _AVALID && if ((ifmr.ifm_status & IFM_AVALID) == IFM _AVALID &&
(ifmr.ifm_status & IFM_AC TIVE) == IFM_ACTIVE) (ifmr.ifm_status & IFM_AC TIVE) == IFM_ACTIVE)
{ {
ret_int(value, 1); ret_int(value, 1);
nRet = SYSINFO_RC_SUCCESS; nRet = SYSINFO_RC_SUCCESS;
} }
else else
{ {
skipping to change at line 348 skipping to change at line 353
{ {
rti_info[i] = sa; rti_info[i] = sa;
sa = (struct sockaddr *)((char *)(sa) + R OUNDUP(sa->sa_len)); sa = (struct sockaddr *)((char *)(sa) + R OUNDUP(sa->sa_len));
} }
else else
{ {
rti_info[i] = NULL; rti_info[i] = NULL;
} }
} }
if (rti_info[RTAX_DST] != NULL if ((rti_info[RTAX_DST] != NULL)
#if HAVE_DECL_RTF_WASCLONED #if HAVE_DECL_RTF_WASCLONED
&& !(rtm->rtm_flags & RTF_WASCLONED)) && !(rtm->rtm_flags & RTF_WASCLONED)
#else
)
#endif #endif
)
{ {
char szOut[1024]; char szOut[1024];
char szTmp[64]; char szTmp[64];
if (sa2sin(rti_info[RTAX_DST])->sin_addr.s_addr = = INADDR_ANY) if (sa2sin(rti_info[RTAX_DST])->sin_addr.s_addr = = INADDR_ANY)
{ {
strcpy(szOut, "0.0.0.0/0 "); strcpy(szOut, "0.0.0.0/0 ");
} }
else else
{ {
skipping to change at line 588 skipping to change at line 592
} }
/** /**
* Handler for Net.InterfaceNames list * Handler for Net.InterfaceNames list
*/ */
LONG H_NetIfNames(const TCHAR *pszParam, const TCHAR *pArg, StringList *value, A bstractCommSession *session) LONG H_NetIfNames(const TCHAR *pszParam, const TCHAR *pArg, StringList *value, A bstractCommSession *session)
{ {
return GetInterfaceList(value, true); return GetInterfaceList(value, true);
} }
#if __FreeBSD__ >= 13
/**
* Handler for interface statistics parameters (retrieved via sysctl)
*/
LONG H_NetIfInfo(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCom
mSession *session)
{
char ifName[256];
if (!AgentGetParameterArgA(param, 1, ifName, sizeof(ifName)))
return SYSINFO_RC_UNSUPPORTED;
if (ifName[0] == 0)
return SYSINFO_RC_UNSUPPORTED;
int ifIndex;
if ((ifName[0] >= '0') && (ifName[0] <= '9'))
{
ifIndex = atoi(ifName);
}
else
{
ifIndex = if_nametoindex(ifName);
if (ifIndex == 0)
{
nxlog_debug(7, _T("H_NetIfInfo: cannot find interface index for name %h
s"), ifName);
return SYSINFO_RC_UNSUPPORTED;
}
}
struct ifmibdata ifData;
size_t len = sizeof(ifData);
int name[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, ifIndex, IFDA
TA_GENERAL };
if (sysctl(name, 6, &ifData, &len, nullptr, 0) != 0)
{
nxlog_debug(7, _T("H_NetIfInfo: sysctl error for interface %hs index %d"),
ifName, ifIndex);
return SYSINFO_RC_UNSUPPORTED;
}
switch(CAST_FROM_POINTER(arg, int))
{
case IF_INFO_BYTES_IN:
ret_uint(value, static_cast<uint32_t>(ifData.ifmd_data.ifi_ibytes));
break;
case IF_INFO_BYTES_IN_64:
ret_uint64(value, ifData.ifmd_data.ifi_ibytes);
break;
case IF_INFO_BYTES_OUT:
ret_uint(value, static_cast<uint32_t>(ifData.ifmd_data.ifi_obytes));
break;
case IF_INFO_BYTES_OUT_64:
ret_uint64(value, ifData.ifmd_data.ifi_obytes);
break;
case IF_INFO_IN_ERRORS:
ret_uint(value, static_cast<uint32_t>(ifData.ifmd_data.ifi_ierrors));
break;
case IF_INFO_IN_ERRORS_64:
ret_uint64(value, ifData.ifmd_data.ifi_ierrors);
break;
case IF_INFO_OUT_ERRORS:
ret_uint(value, static_cast<uint32_t>(ifData.ifmd_data.ifi_oerrors));
break;
case IF_INFO_OUT_ERRORS_64:
ret_uint64(value, ifData.ifmd_data.ifi_oerrors);
break;
case IF_INFO_PACKETS_IN:
ret_uint(value, static_cast<uint32_t>(ifData.ifmd_data.ifi_ipackets));
break;
case IF_INFO_PACKETS_IN_64:
ret_uint64(value, ifData.ifmd_data.ifi_ipackets);
break;
case IF_INFO_PACKETS_OUT:
ret_uint(value, static_cast<uint32_t>(ifData.ifmd_data.ifi_opackets));
break;
case IF_INFO_PACKETS_OUT_64:
ret_uint64(value, ifData.ifmd_data.ifi_opackets);
break;
default:
return SYSINFO_RC_UNSUPPORTED;
}
return SYSINFO_RC_SUCCESS;
}
#else /* not __FreeBSD__ >= 13 */
/** /**
* KVM name list * KVM name list
*/ */
struct nlist s_nl[] = struct nlist s_nl[] =
{ {
{ (char *)"_ifnet" }, { (char *)"_ifnet" },
{ NULL } { nullptr }
}; };
/** /**
* KVM handle * KVM handle
*/ */
static kvm_t *s_kvmd = NULL; static kvm_t *s_kvmd = nullptr;
/** /**
* KVM lock * KVM lock
*/ */
static Mutex s_kvmLock; static Mutex s_kvmLock;
#if __FreeBSD__ >= 10 #if __FreeBSD__ >= 10
/** /**
* Read kernel counter * Read kernel counter
*/ */
inline UINT64 ReadKernelCounter64(counter_u64_t cnt) inline uint64_t ReadKernelCounter64(counter_u64_t cnt)
{ {
UINT64 value; uint64_t value;
if (kvm_read(s_kvmd, (u_long)cnt, &value, sizeof(UINT64)) != sizeof(UINT6 if (kvm_read(s_kvmd, (u_long)cnt, &value, sizeof(uint64_t)) != sizeof(uint64_
4)) t))
{ {
nxlog_debug(7, _T("ReadKernelCounter64: kvm_read failed (%hs)"), nxlog_debug(7, _T("ReadKernelCounter64: kvm_read failed (%hs) at address %
kvm_geterr(s_kvmd)); p"), kvm_geterr(s_kvmd), cnt);
return 0; return 0;
} }
return value; return value;
} }
#endif #endif
/** /**
* Handler for interface statistics parameters * Handler for interface statistics parameters (retrieved via KVM)
*/ */
LONG H_NetIfInfoFromKVM(const TCHAR *param, const TCHAR *arg, TCHAR *value, Abst ractCommSession *session) LONG H_NetIfInfo(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCom mSession *session)
{ {
char ifName[256]; char ifName[256];
if (!AgentGetParameterArgA(param, 1, ifName, sizeof(ifName))) if (!AgentGetParameterArgA(param, 1, ifName, sizeof(ifName)))
return SYSINFO_RC_UNSUPPORTED; return SYSINFO_RC_UNSUPPORTED;
if (ifName[0] == 0) if (ifName[0] == 0)
return SYSINFO_RC_UNSUPPORTED; return SYSINFO_RC_UNSUPPORTED;
if ((ifName[0] >= '0') && (ifName[0] <= '9')) if ((ifName[0] >= '0') && (ifName[0] <= '9'))
{ {
int ifIndex = atoi(ifName); int ifIndex = atoi(ifName);
if (if_indextoname(ifIndex, ifName) != ifName) if (if_indextoname(ifIndex, ifName) != ifName)
{ {
nxlog_debug(7, _T("H_NetIfInfoFromKVM: cannot find interf ace name for index %d"), ifIndex); nxlog_debug(7, _T("H_NetIfInfo: cannot find interface nam e for index %d"), ifIndex);
return SYSINFO_RC_UNSUPPORTED; return SYSINFO_RC_UNSUPPORTED;
} }
} }
s_kvmLock.lock(); s_kvmLock.lock();
if (s_kvmd == NULL) if (s_kvmd == NULL)
{ {
char errmsg[_POSIX2_LINE_MAX]; char errmsg[_POSIX2_LINE_MAX];
s_kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errmsg); s_kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errmsg);
if (s_kvmd == NULL) if (s_kvmd == NULL)
{ {
nxlog_debug(7, _T("H_NetIfInfoFromKVM: kvm_openfiles fail ed (%hs)"), errmsg); nxlog_debug(7, _T("H_NetIfInfo: kvm_openfiles failed (%hs )"), errmsg);
s_kvmLock.unlock(); s_kvmLock.unlock();
return SYSINFO_RC_ERROR; return SYSINFO_RC_ERROR;
} }
if (kvm_nlist(s_kvmd, s_nl) < 0) if (kvm_nlist(s_kvmd, s_nl) < 0)
{ {
nxlog_debug(7, _T("H_NetIfInfoFromKVM: kvm_nlist failed ( %hs)"), kvm_geterr(s_kvmd)); nxlog_debug(7, _T("H_NetIfInfo: kvm_nlist failed (%hs)"), kvm_geterr(s_kvmd));
kvm_close(s_kvmd); kvm_close(s_kvmd);
s_kvmd = NULL; s_kvmd = NULL;
s_kvmLock.unlock(); s_kvmLock.unlock();
return SYSINFO_RC_UNSUPPORTED; return SYSINFO_RC_UNSUPPORTED;
} }
if (s_nl[0].n_type == 0) if (s_nl[0].n_type == 0)
{ {
nxlog_debug(7, _T("H_NetIfInfoFromKVM: symbol %hs not fou nd in kernel symbol table"), s_nl[0].n_name); nxlog_debug(7, _T("H_NetIfInfo: symbol %hs not found in k ernel symbol table"), s_nl[0].n_name);
kvm_close(s_kvmd); kvm_close(s_kvmd);
s_kvmd = NULL; s_kvmd = NULL;
s_kvmLock.unlock(); s_kvmLock.unlock();
return SYSINFO_RC_UNSUPPORTED; return SYSINFO_RC_UNSUPPORTED;
} }
} }
int rc = SYSINFO_RC_UNSUPPORTED; int rc = SYSINFO_RC_UNSUPPORTED;
u_long curr = s_nl[0].n_value; u_long curr = s_nl[0].n_value;
struct ifnethead head; struct ifnethead head;
if (kvm_read(s_kvmd, curr, &head, sizeof(head)) != sizeof(head)) if (kvm_read(s_kvmd, curr, &head, sizeof(head)) != sizeof(head))
{ {
nxlog_debug(7, _T("H_NetIfInfoFromKVM: kvm_read failed (%hs)"), k vm_geterr(s_kvmd)); nxlog_debug(7, _T("H_NetIfInfo: kvm_read failed (%hs)"), kvm_gete rr(s_kvmd));
s_kvmLock.unlock(); s_kvmLock.unlock();
return SYSINFO_RC_ERROR; return SYSINFO_RC_ERROR;
} }
#if __FreeBSD__ >= 12 #if __FreeBSD__ >= 12
curr = (u_long)STAILQ_FIRST(&head); curr = (u_long)STAILQ_FIRST(&head);
#else #else
curr = (u_long)TAILQ_FIRST(&head); curr = (u_long)TAILQ_FIRST(&head);
#endif #endif
while(curr != 0) while(curr != 0)
{ {
struct ifnet ifnet; struct ifnet ifnet;
if (kvm_read(s_kvmd, curr, &ifnet, sizeof(ifnet)) != sizeof(ifnet )) if (kvm_read(s_kvmd, curr, &ifnet, sizeof(ifnet)) != sizeof(ifnet ))
{ {
nxlog_debug(7, _T("H_NetIfInfoFromKVM: kvm_read failed (% hs)"), kvm_geterr(s_kvmd)); nxlog_debug(7, _T("H_NetIfInfo: kvm_read failed (%hs)"), kvm_geterr(s_kvmd));
rc = SYSINFO_RC_ERROR; rc = SYSINFO_RC_ERROR;
break; break;
} }
#if __FreeBSD__ >= 12 #if __FreeBSD__ >= 12
curr = (u_long)STAILQ_NEXT(&ifnet, if_link); curr = (u_long)STAILQ_NEXT(&ifnet, if_link);
#else #else
curr = (u_long)TAILQ_NEXT(&ifnet, if_link); curr = (u_long)TAILQ_NEXT(&ifnet, if_link);
#endif #endif
#if __FreeBSD__ >= 5 #if __FreeBSD__ >= 5
const char *currName = ifnet.if_xname; const char *currName = ifnet.if_xname;
#else #else
char currName[IFNAMSIZ]; char currName[IFNAMSIZ];
if (kvm_read(s_kvmd, ifnet.if_name, currName, sizeof(currName)) ! = sizeof(currName)) if (kvm_read(s_kvmd, ifnet.if_name, currName, sizeof(currName)) ! = sizeof(currName))
{ {
nxlog_debug(7, _T("H_NetIfInfoFromKVM: kvm_read failed (% hs)"), kvm_geterr(s_kvmd)); nxlog_debug(7, _T("H_NetIfInfo: kvm_read failed (%hs)"), kvm_geterr(s_kvmd));
rc = SYSINFO_RC_ERROR; rc = SYSINFO_RC_ERROR;
break; break;
} }
currName[sizeof(currName) - 2] = 0; currName[sizeof(currName) - 2] = 0;
size_t len = strlen(currName); size_t len = strlen(currName);
snprintf(&currName[len], sizeof(currName) - len, "%d", ifnet.if_u nit); snprintf(&currName[len], sizeof(currName) - len, "%d", ifnet.if_u nit);
#endif #endif
if (!strcmp(currName, ifName)) if (!strcmp(currName, ifName))
{ {
rc = SYSINFO_RC_SUCCESS; rc = SYSINFO_RC_SUCCESS;
skipping to change at line 799 skipping to change at line 888
break; break;
} }
#endif #endif
break; break;
} }
} }
s_kvmLock.unlock(); s_kvmLock.unlock();
return rc; return rc;
} }
#endif /* __FreeBSD__ >= 13 */
/** /**
* Handler for Net.Interface.64BitCounters * Handler for Net.Interface.64BitCounters
*/ */
LONG H_NetInterface64bitSupport(const TCHAR *param, const TCHAR *arg, TCHAR *val ue, AbstractCommSession *session) LONG H_NetInterface64bitSupport(const TCHAR *param, const TCHAR *arg, TCHAR *val ue, AbstractCommSession *session)
{ {
#if __FreeBSD__ >= 10 #if __FreeBSD__ >= 10
ret_int(value, 1); ret_int(value, 1);
#else #else
ret_int(value, 0); ret_int(value, 0);
#endif #endif
 End of changes. 23 change blocks. 
28 lines changed or deleted 123 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)