]>
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) | |
d85e9245 ER |
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 | |
f0880bdc | 51 | @@ -29,6 +29,11 @@ |
3fd57f2a ER |
52 | #if HAVE_NETINET_TCP_VAR_H |
53 | #include <netinet/tcp_var.h> | |
54 | #endif | |
55 | +#if HAVE_NETLINK_NETLINK_H | |
56 | +#include <netlink/netlink.h> | |
f0880bdc | 57 | +#include <netlink/msg.h> |
81db991d | 58 | +#include <linux/inet_diag.h> |
3fd57f2a ER |
59 | +#endif |
60 | ||
61 | #include <net-snmp/net-snmp-includes.h> | |
62 | #include <net-snmp/agent/net-snmp-agent-includes.h> | |
d85e9245 | 63 | @@ -543,6 +548,112 @@ |
3fd57f2a ER |
64 | #else /* hpux11 */ |
65 | ||
66 | #ifdef linux | |
67 | + | |
68 | +// see <netinet/tcp.h> | |
81db991d | 69 | +#define TCP_ALL ((1 << (TCP_CLOSING + 1)) - 1) |
3fd57f2a ER |
70 | + |
71 | +static int | |
72 | +tcpTable_load_netlink() | |
73 | +{ | |
f0880bdc ER |
74 | + // TODO: perhaps use permanent nl handle? |
75 | + struct nl_handle *nl = nl_handle_alloc(); | |
3fd57f2a | 76 | + |
f0880bdc ER |
77 | + if (nl == NULL) { |
78 | + DEBUGMSGTL(("mibII/tcpTable", "Failed to allocate netlink handle\n")); | |
79 | + snmp_log(LOG_ERR, "snmpd: Failed to allocate netlink handle\n"); | |
80 | + return -1; | |
81 | + } | |
3fd57f2a | 82 | + |
f0880bdc ER |
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); | |
3fd57f2a ER |
87 | + return -1; |
88 | + } | |
89 | + | |
90 | + struct inet_diag_req req = { | |
4c6b3fb4 | 91 | + .idiag_family = AF_INET, |
3fd57f2a ER |
92 | + .idiag_states = TCP_ALL, |
93 | + }; | |
94 | + | |
f0880bdc ER |
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); | |
97 | + | |
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); | |
3fd57f2a ER |
102 | + return -1; |
103 | + } | |
f0880bdc | 104 | + nlmsg_free(nm); |
3fd57f2a | 105 | + |
f0880bdc ER |
106 | + struct sockaddr_nl peer; |
107 | + unsigned char *buf = NULL; | |
3fd57f2a ER |
108 | + int running = 1, len; |
109 | + | |
110 | + while (running) { | |
f0880bdc | 111 | + if ((len = nl_recv(nl, &peer, &buf, NULL)) <= 0) { |
3fd57f2a ER |
112 | + DEBUGMSGTL(("mibII/tcpTable", "nl_recv(): %s\n", nl_geterror())); |
113 | + snmp_log(LOG_ERR, "snmpd: nl_recv(): %s\n", nl_geterror()); | |
f0880bdc | 114 | + nl_handle_destroy(nl); |
3fd57f2a ER |
115 | + return -1; |
116 | + } | |
117 | + | |
118 | + struct nlmsghdr *h = (struct nlmsghdr*)buf; | |
f0880bdc | 119 | + while (nlmsg_ok(h, len)) { |
3fd57f2a ER |
120 | + if (h->nlmsg_type == NLMSG_DONE) { |
121 | + running = 0; | |
122 | + break; | |
123 | + } | |
124 | + | |
f0880bdc | 125 | + struct inet_diag_msg *r = nlmsg_data(h); |
d85e9245 ER |
126 | + |
127 | + if (r->idiag_family != AF_INET) { | |
128 | + h = nlmsg_next(h, &len); | |
129 | + continue; | |
130 | + } | |
131 | + | |
3fd57f2a ER |
132 | + struct inpcb pcb, *nnew; |
133 | + static int linux_states[12] = | |
134 | + { 1, 5, 3, 4, 6, 7, 11, 1, 8, 9, 2, 10 }; | |
135 | + | |
136 | + memcpy(&pcb.inp_laddr.s_addr, r->id.idiag_src, r->idiag_family == AF_INET ? 4 : 6); | |
172cdc5d | 137 | + memcpy(&pcb.inp_faddr.s_addr, r->id.idiag_dst, r->idiag_family == AF_INET ? 4 : 6); |
3fd57f2a | 138 | + |
764668d1 ER |
139 | + pcb.inp_lport = r->id.idiag_sport; |
140 | + pcb.inp_fport = r->id.idiag_dport; | |
3fd57f2a ER |
141 | + |
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 */ ) | |
145 | + tcp_estab++; | |
146 | + pcb.uid = r->idiag_uid; | |
147 | + | |
148 | + nnew = SNMP_MALLOC_TYPEDEF(struct inpcb); | |
149 | + if (nnew == NULL) { | |
150 | + running = 0; | |
151 | + // XXX report malloc error and return -1? | |
152 | + break; | |
153 | + } | |
154 | + memcpy(nnew, &pcb, sizeof(struct inpcb)); | |
155 | + nnew->inp_next = tcp_head; | |
156 | + tcp_head = nnew; | |
157 | + | |
f0880bdc | 158 | + h = nlmsg_next(h, &len); |
3fd57f2a ER |
159 | + } |
160 | + free(buf); | |
161 | + } | |
162 | + | |
f0880bdc | 163 | + nl_handle_destroy(nl); |
3fd57f2a | 164 | + |
f0880bdc | 165 | + if (tcp_head) { |
3fd57f2a | 166 | + DEBUGMSGTL(("mibII/tcpTable", "Loaded TCP Table using netlink\n")); |
f0880bdc ER |
167 | + return 0; |
168 | + } | |
169 | + DEBUGMSGTL(("mibII/tcpTable", "Failed to load TCP Table (netlink)\n")); | |
170 | + return -1; | |
3fd57f2a ER |
171 | +} |
172 | + | |
173 | int | |
174 | tcpTable_load(netsnmp_cache *cache, void *vmagic) | |
175 | { | |
d85e9245 | 176 | @@ -551,6 +662,10 @@ |
3fd57f2a ER |
177 | |
178 | tcpTable_free(cache, NULL); | |
179 | ||
180 | + if (tcpTable_load_netlink() == 0) { | |
181 | + return 0; | |
182 | + } | |
183 | + | |
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"); |