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:31:48.951541328 +0200
39 +++ net-snmp-5.4.2.1/agent/Makefile.in 2009-02-05 20:50:30.825174223 +0200
42 LOCAL_LIBS = -L../snmplib/.libs -L../snmplib -L./.libs -L./helpers/.libs -L./helpers
43 LAGENTLIBS = @LAGENTLIBS@
44 -LMIBLIBS = @LMIBLIBS@
45 +LMIBLIBS = @LMIBLIBS@ @LIBNL_LIBS@
46 PERLLDOPTS_FOR_APPS = @PERLLDOPTS_FOR_APPS@
47 PERLLDOPTS_FOR_LIBS = @PERLLDOPTS_FOR_LIBS@
48 LIBS = $(USELIBS) @AGENTLIBS@ $(PERLLDOPTS_FOR_APPS)
49 --- net-snmp-5.4.2.1-nl/agent/mibgroup/mibII/tcpTable.c 2009-03-10 21:53:36.453773342 +0200
50 +++ net-snmp-5.4.2.1-nl/agent/mibgroup/mibII/tcpTable.c 2009-03-10 22:49:50.326352782 +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 <netlink/msg.h>
58 +#include <linux/inet_diag.h>
61 #include <net-snmp/net-snmp-includes.h>
62 #include <net-snmp/agent/net-snmp-agent-includes.h>
68 +// see <netinet/tcp.h>
69 +#define TCP_ALL ((1 << (TCP_CLOSING + 1)) - 1)
72 +tcpTable_load_netlink()
74 + // TODO: perhaps use permanent nl handle?
75 + struct nl_handle *nl = nl_handle_alloc();
78 + DEBUGMSGTL(("mibII/tcpTable", "Failed to allocate netlink handle\n"));
79 + snmp_log(LOG_ERR, "snmpd: Failed to allocate netlink handle\n");
83 + if (nl_connect(nl, NETLINK_INET_DIAG) < 0) {
84 + DEBUGMSGTL(("mibII/tcpTable", "Failed to connect to netlink: %s\n", nl_geterror()));
85 + snmp_log(LOG_ERR, "snmpd: Couldn't connect to netlink: %s\n", nl_geterror());
86 + nl_handle_destroy(nl);
90 + struct inet_diag_req req = {
91 + .idiag_family = AF_INET,
92 + .idiag_states = TCP_ALL,
95 + struct nl_msg *nm = nlmsg_alloc_simple(TCPDIAG_GETSOCK, NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST);
96 + nlmsg_append(nm, &req, sizeof(struct inet_diag_req), 0);
98 + if (nl_send_auto_complete(nl, nm) < 0) {
99 + DEBUGMSGTL(("mibII/tcpTable", "nl_send_autocomplete(): %s\n", nl_geterror()));
100 + snmp_log(LOG_ERR, "snmpd: nl_send_autocomplete(): %s\n", nl_geterror());
101 + nl_handle_destroy(nl);
106 + struct sockaddr_nl peer;
107 + unsigned char *buf = NULL;
108 + int running = 1, len;
111 + if ((len = nl_recv(nl, &peer, &buf, NULL)) <= 0) {
112 + DEBUGMSGTL(("mibII/tcpTable", "nl_recv(): %s\n", nl_geterror()));
113 + snmp_log(LOG_ERR, "snmpd: nl_recv(): %s\n", nl_geterror());
114 + nl_handle_destroy(nl);
118 + struct nlmsghdr *h = (struct nlmsghdr*)buf;
119 + while (nlmsg_ok(h, len)) {
120 + if (h->nlmsg_type == NLMSG_DONE) {
125 + struct inet_diag_msg *r = nlmsg_data(h);
127 + if (r->idiag_family != AF_INET) {
128 + h = nlmsg_next(h, &len);
132 + struct inpcb pcb, *nnew;
133 + static int linux_states[12] =
134 + { 1, 5, 3, 4, 6, 7, 11, 1, 8, 9, 2, 10 };
136 + memcpy(&pcb.inp_laddr.s_addr, r->id.idiag_src, r->idiag_family == AF_INET ? 4 : 6);
137 + memcpy(&pcb.inp_faddr.s_addr, r->id.idiag_dst, r->idiag_family == AF_INET ? 4 : 6);
139 + pcb.inp_lport = r->id.idiag_sport;
140 + pcb.inp_fport = r->id.idiag_dport;
142 + pcb.inp_state = (r->idiag_state & 0xf) < 12 ? linux_states[r->idiag_state & 0xf] : 2;
143 + if (pcb.inp_state == 5 /* established */ ||
144 + pcb.inp_state == 8 /* closeWait */ )
146 + pcb.uid = r->idiag_uid;
148 + nnew = SNMP_MALLOC_TYPEDEF(struct inpcb);
149 + if (nnew == NULL) {
151 + // XXX report malloc error and return -1?
154 + memcpy(nnew, &pcb, sizeof(struct inpcb));
155 + nnew->inp_next = tcp_head;
158 + h = nlmsg_next(h, &len);
163 + nl_handle_destroy(nl);
166 + DEBUGMSGTL(("mibII/tcpTable", "Loaded TCP Table using netlink\n"));
169 + DEBUGMSGTL(("mibII/tcpTable", "Failed to load TCP Table (netlink)\n"));
174 tcpTable_load(netsnmp_cache *cache, void *vmagic)
178 tcpTable_free(cache, NULL);
180 + if (tcpTable_load_netlink() == 0) {
184 if (!(in = fopen("/proc/net/tcp", "r"))) {
185 DEBUGMSGTL(("mibII/tcpTable", "Failed to load TCP Table (linux1)\n"));
186 snmp_log(LOG_ERR, "snmpd: cannot open /proc/net/tcp ...\n");