1 --- net-snmp-5.4.2.1-dev/configure.in 2009-01-22 20:00:37.030183514 +0200
2 +++ net-snmp-5.4.2.1-netlink/configure.in 2009-01-23 01:30:24.148211644 +0200
5 AC_MSG_ERROR([ Invalid option. Use --with-efence/--without-efence instead ]) )
8 +[ --with-nl Look for and use libnl (linux only).],
11 + AC_MSG_ERROR([ Invalid option. Use --with-nl/--without-nl instead ]) )
15 [ --with-rsaref=PATH Look for librsaref in PATH/lib.],
16 @@ -2664,6 +2670,21 @@
17 AC_CHECK_LIB(efence, EF_Exit)
20 +if test "x$use_nl" != "xno"; then
22 + linux*) # Check for libnl (linux)
23 + AC_CHECK_HEADERS(netlink/netlink.h,
24 + AC_CHECK_LIB(nl, nl_connect, [
25 + AC_DEFINE_UNQUOTED(HAVE_NL, "1", [have libnl])
35 # Checks for libraries.
36 # AC_CHECK_LIB(des, main)
37 # AC_CHECK_LIB(m, asin)
38 --- net-snmp-5.4.2.1/agent/Makefile.in~ 2009-01-23 01:25:58.000000000 +0200
39 +++ net-snmp-5.4.2.1/agent/Makefile.in 2009-01-23 01:31:48.951541328 +0200
43 libnetsnmpmibs.$(LIB_EXTENSION)$(LIB_VERSION): ${LMIBOBJS} $(HELPERLIB) $(AGENTLIB) $(USELIBS)
44 - $(LIB_LD_CMD) $(MIBLIB) ${LMIBOBJS} $(HELPERLIB) $(AGENTLIB) $(USELIBS) $(LDFLAGS) ${LMIBLIBS} $(LIB_LD_LIBS)
45 + $(LIB_LD_CMD) $(MIBLIB) ${LMIBOBJS} $(HELPERLIB) $(AGENTLIB) $(USELIBS) @LIBNL_LIBS@ $(LDFLAGS) ${LMIBLIBS} $(LIB_LD_LIBS)
49 --- net-snmp-5.4.2.1/agent/mibgroup/mibII/tcpTable.c 2009-01-23 01:22:10.435006124 +0200
50 +++ net-snmp-5.4.2.1-nl/agent/mibgroup/mibII/tcpTable.c 2009-01-23 02:28:12.726994792 +0200
52 #if HAVE_NETINET_TCP_VAR_H
53 #include <netinet/tcp_var.h>
55 +#if HAVE_NETLINK_NETLINK_H
56 +#include <netlink/netlink.h>
57 +#include <linux/inet_diag.h>
58 +#include <sys/socket.h>
59 +#include <sys/types.h>
62 #include <net-snmp/net-snmp-includes.h>
63 #include <net-snmp/agent/net-snmp-agent-includes.h>
69 +// see <netinet/tcp.h>
70 +#define TCP_ALL ((1 << TCP_CLOSING + 1) - 1)
73 +tcpTable_load_netlink()
75 + struct inpcb pcb, *nnew;
76 + struct nl_handle nl;
78 + memset(&nl, 0, sizeof(nl));
80 + if (nl_connect(&nl, NETLINK_TCPDIAG) < 0) {
81 + DEBUGMSGTL(("mibII/tcpTable", "Failed to connect to netlink: %s\n", nl_geterror()));
82 + snmp_log(LOG_ERR, "snmpd: Couldn't connect to netlink: %s\n", nl_geterror());
86 + struct inet_diag_req req = {
87 + .idiag_family = AF_INET,
88 + .idiag_states = TCP_ALL,
91 + if (nl_request_with_data(&nl, TCPDIAG_GETSOCK, NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST, (void *)&req, sizeof(struct inet_diag_req)) < 0) {
92 + DEBUGMSGTL(("mibII/tcpTable", "nl_send(): %s\n", nl_geterror()));
93 + snmp_log(LOG_ERR, "snmpd: nl_send(): %s\n", nl_geterror());
97 + struct sockaddr_nl addr;
99 + int running = 1, len;
102 + if ((len = nl_recv(&nl, &addr, (void *)&buf)) <= 0) {
103 + DEBUGMSGTL(("mibII/tcpTable", "nl_recv(): %s\n", nl_geterror()));
104 + snmp_log(LOG_ERR, "snmpd: nl_recv(): %s\n", nl_geterror());
108 + struct nlmsghdr *h = (struct nlmsghdr*)buf;
109 + while (NLMSG_OK(h, len)) {
110 + if (h->nlmsg_type == NLMSG_DONE) {
115 + struct inet_diag_msg *r = NLMSG_DATA(h);
116 + struct inpcb pcb, *nnew;
117 + static int linux_states[12] =
118 + { 1, 5, 3, 4, 6, 7, 11, 1, 8, 9, 2, 10 };
120 + memcpy(&pcb.inp_laddr.s_addr, r->id.idiag_src, r->idiag_family == AF_INET ? 4 : 6);
121 + memcpy(&pcb.inp_laddr.s_addr, r->id.idiag_dst, r->idiag_family == AF_INET ? 4 : 6);
123 + pcb.inp_lport = r->id.idiag_sport;
124 + pcb.inp_fport = r->id.idiag_dport;
126 + pcb.inp_state = (r->idiag_state & 0xf) < 12 ? linux_states[r->idiag_state & 0xf] : 2;
127 + if (pcb.inp_state == 5 /* established */ ||
128 + pcb.inp_state == 8 /* closeWait */ )
130 + pcb.uid = r->idiag_uid;
132 + nnew = SNMP_MALLOC_TYPEDEF(struct inpcb);
133 + if (nnew == NULL) {
135 + // XXX report malloc error and return -1?
138 + memcpy(nnew, &pcb, sizeof(struct inpcb));
139 + nnew->inp_next = tcp_head;
142 + h = NLMSG_NEXT(h, len);
150 + DEBUGMSGTL(("mibII/tcpTable", "Loaded TCP Table using netlink\n"));
153 + DEBUGMSGTL(("mibII/tcpTable", "Failed to load TCP Table (netlink)\n"));
158 tcpTable_load(netsnmp_cache *cache, void *vmagic)
162 tcpTable_free(cache, NULL);
164 + if (tcpTable_load_netlink() == 0) {
168 if (!(in = fopen("/proc/net/tcp", "r"))) {
169 DEBUGMSGTL(("mibII/tcpTable", "Failed to load TCP Table (linux1)\n"));
170 snmp_log(LOG_ERR, "snmpd: cannot open /proc/net/tcp ...\n");