]>
Commit | Line | Data |
---|---|---|
3fd57f2a ER |
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 | |
89293676 ER |
3 | @@ -310,6 +310,12 @@ |
4 | AC_ARG_ENABLE(efence,, | |
5 | AC_MSG_ERROR([ Invalid option. Use --with-efence/--without-efence instead ]) ) | |
6 | ||
7 | +AC_ARG_WITH(nl, | |
8 | +[ --with-nl Look for and use libnl (linux only).], | |
9 | + use_nl="$withval") | |
10 | +AC_ARG_ENABLE(nl,, | |
11 | + AC_MSG_ERROR([ Invalid option. Use --with-nl/--without-nl instead ]) ) | |
12 | + | |
13 | tryrsaref=no | |
14 | AC_ARG_WITH(rsaref, | |
15 | [ --with-rsaref=PATH Look for librsaref in PATH/lib.], | |
16 | @@ -2664,6 +2670,21 @@ | |
17 | AC_CHECK_LIB(efence, EF_Exit) | |
18 | fi | |
19 | ||
20 | +if test "x$use_nl" != "xno"; then | |
21 | + case $target_os in | |
22 | + linux*) # Check for libnl (linux) | |
23 | + AC_CHECK_HEADERS(netlink/netlink.h, | |
24 | + AC_CHECK_LIB(nl, nl_connect, [ | |
3fd57f2a ER |
25 | + AC_DEFINE_UNQUOTED(HAVE_NL, "1", [have libnl]) |
26 | + LIBNL_LIBS="-lnl" | |
27 | + LIBNL="Yes" | |
89293676 ER |
28 | + ]) |
29 | + ) | |
30 | + ;; | |
31 | + esac | |
32 | +fi | |
3fd57f2a | 33 | +AC_SUBST(LIBNL_LIBS) |
89293676 ER |
34 | + |
35 | # Checks for libraries. | |
36 | # AC_CHECK_LIB(des, main) | |
37 | # AC_CHECK_LIB(m, asin) | |
061ca4f5 ER |
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 | |
40 | @@ -81,7 +81,7 @@ | |
3fd57f2a | 41 | |
061ca4f5 ER |
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) | |
7e3fdb63 | 49 | --- net-snmp-5.4.2.1-nl/agent/mibgroup/mibII/tcpTable.c 2009-01-23 02:28:12.726994792 +0200 |
50 | +++ net-snmp-5.4.2.1/agent/mibgroup/mibII/tcpTable.c 2009-02-05 20:46:32.738258556 +0200 | |
51 | @@ -29,6 +29,13 @@ | |
3fd57f2a ER |
52 | #if HAVE_NETINET_TCP_VAR_H |
53 | #include <netinet/tcp_var.h> | |
54 | #endif | |
55 | +#if HAVE_NETLINK_NETLINK_H | |
7e3fdb63 | 56 | +#include <netlink/helpers.h> |
3fd57f2a | 57 | +#include <netlink/netlink.h> |
7e3fdb63 | 58 | +#include <sys/socket.h> |
59 | +#include <sys/types.h> | |
81db991d | 60 | +#include <linux/inet_diag.h> |
3fd57f2a ER |
61 | +#endif |
62 | ||
63 | #include <net-snmp/net-snmp-includes.h> | |
64 | #include <net-snmp/agent/net-snmp-agent-includes.h> | |
7e3fdb63 | 65 | @@ -543,6 +550,94 @@ |
3fd57f2a ER |
66 | #else /* hpux11 */ |
67 | ||
68 | #ifdef linux | |
69 | + | |
70 | +// see <netinet/tcp.h> | |
81db991d | 71 | +#define TCP_ALL ((1 << (TCP_CLOSING + 1)) - 1) |
3fd57f2a ER |
72 | + |
73 | +static int | |
74 | +tcpTable_load_netlink() | |
75 | +{ | |
7e3fdb63 | 76 | + struct nl_handle nl; |
3fd57f2a | 77 | + |
7e3fdb63 | 78 | + memset(&nl, 0, sizeof(nl)); |
3fd57f2a | 79 | + |
7e3fdb63 | 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()); | |
3fd57f2a ER |
83 | + return -1; |
84 | + } | |
85 | + | |
86 | + struct inet_diag_req req = { | |
4c6b3fb4 | 87 | + .idiag_family = AF_INET, |
3fd57f2a ER |
88 | + .idiag_states = TCP_ALL, |
89 | + }; | |
90 | + | |
7e3fdb63 | 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()); | |
3fd57f2a ER |
94 | + return -1; |
95 | + } | |
96 | + | |
7e3fdb63 | 97 | + struct sockaddr_nl addr; |
98 | + char *buf = NULL; | |
3fd57f2a ER |
99 | + int running = 1, len; |
100 | + | |
101 | + while (running) { | |
7e3fdb63 | 102 | + if ((len = nl_recv(&nl, &addr, (void *)&buf)) <= 0) { |
3fd57f2a ER |
103 | + DEBUGMSGTL(("mibII/tcpTable", "nl_recv(): %s\n", nl_geterror())); |
104 | + snmp_log(LOG_ERR, "snmpd: nl_recv(): %s\n", nl_geterror()); | |
105 | + return -1; | |
106 | + } | |
107 | + | |
108 | + struct nlmsghdr *h = (struct nlmsghdr*)buf; | |
7e3fdb63 | 109 | + while (NLMSG_OK(h, len)) { |
3fd57f2a ER |
110 | + if (h->nlmsg_type == NLMSG_DONE) { |
111 | + running = 0; | |
112 | + break; | |
113 | + } | |
114 | + | |
7e3fdb63 | 115 | + struct inet_diag_msg *r = NLMSG_DATA(h); |
3fd57f2a ER |
116 | + struct inpcb pcb, *nnew; |
117 | + static int linux_states[12] = | |
118 | + { 1, 5, 3, 4, 6, 7, 11, 1, 8, 9, 2, 10 }; | |
119 | + | |
120 | + memcpy(&pcb.inp_laddr.s_addr, r->id.idiag_src, r->idiag_family == AF_INET ? 4 : 6); | |
172cdc5d | 121 | + memcpy(&pcb.inp_faddr.s_addr, r->id.idiag_dst, r->idiag_family == AF_INET ? 4 : 6); |
3fd57f2a | 122 | + |
764668d1 ER |
123 | + pcb.inp_lport = r->id.idiag_sport; |
124 | + pcb.inp_fport = r->id.idiag_dport; | |
3fd57f2a ER |
125 | + |
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 */ ) | |
129 | + tcp_estab++; | |
130 | + pcb.uid = r->idiag_uid; | |
131 | + | |
132 | + nnew = SNMP_MALLOC_TYPEDEF(struct inpcb); | |
133 | + if (nnew == NULL) { | |
134 | + running = 0; | |
135 | + // XXX report malloc error and return -1? | |
136 | + break; | |
137 | + } | |
138 | + memcpy(nnew, &pcb, sizeof(struct inpcb)); | |
139 | + nnew->inp_next = tcp_head; | |
140 | + tcp_head = nnew; | |
141 | + | |
7e3fdb63 | 142 | + h = NLMSG_NEXT(h, len); |
3fd57f2a ER |
143 | + } |
144 | + free(buf); | |
145 | + } | |
146 | + | |
7e3fdb63 | 147 | + nl_close(&nl); |
3fd57f2a | 148 | + |
7e3fdb63 | 149 | + if (tcp_head) { |
3fd57f2a | 150 | + DEBUGMSGTL(("mibII/tcpTable", "Loaded TCP Table using netlink\n")); |
7e3fdb63 | 151 | + return 0; |
152 | + } | |
153 | + DEBUGMSGTL(("mibII/tcpTable", "Failed to load TCP Table (netlink)\n")); | |
154 | + return -1; | |
3fd57f2a ER |
155 | +} |
156 | + | |
157 | int | |
158 | tcpTable_load(netsnmp_cache *cache, void *vmagic) | |
159 | { | |
7e3fdb63 | 160 | @@ -551,6 +646,10 @@ |
3fd57f2a ER |
161 | |
162 | tcpTable_free(cache, NULL); | |
163 | ||
164 | + if (tcpTable_load_netlink() == 0) { | |
165 | + return 0; | |
166 | + } | |
167 | + | |
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"); |