]>
Commit | Line | Data |
---|---|---|
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 | |
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, [ | |
25 | + AC_DEFINE_UNQUOTED(HAVE_NL, "1", [have libnl]) | |
26 | + LIBNL_LIBS="-lnl" | |
27 | + LIBNL="Yes" | |
28 | + ]) | |
29 | + ) | |
30 | + ;; | |
31 | + esac | |
32 | +fi | |
33 | +AC_SUBST(LIBNL_LIBS) | |
34 | + | |
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 | |
40 | @@ -81,7 +81,7 @@ | |
41 | ||
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 | |
51 | @@ -29,6 +29,11 @@ | |
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> | |
57 | +#include <netlink/msg.h> | |
58 | +#include <linux/inet_diag.h> | |
59 | +#endif | |
60 | ||
61 | #include <net-snmp/net-snmp-includes.h> | |
62 | #include <net-snmp/agent/net-snmp-agent-includes.h> | |
63 | @@ -543,6 +548,112 @@ | |
64 | #else /* hpux11 */ | |
65 | ||
66 | #ifdef linux | |
67 | + | |
68 | +// see <netinet/tcp.h> | |
69 | +#define TCP_ALL ((1 << (TCP_CLOSING + 1)) - 1) | |
70 | + | |
71 | +static int | |
72 | +tcpTable_load_netlink() | |
73 | +{ | |
74 | + // TODO: perhaps use permanent nl handle? | |
75 | + struct nl_handle *nl = nl_handle_alloc(); | |
76 | + | |
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 | + } | |
82 | + | |
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); | |
87 | + return -1; | |
88 | + } | |
89 | + | |
90 | + struct inet_diag_req req = { | |
91 | + .idiag_family = AF_INET, | |
92 | + .idiag_states = TCP_ALL, | |
93 | + }; | |
94 | + | |
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); | |
102 | + return -1; | |
103 | + } | |
104 | + nlmsg_free(nm); | |
105 | + | |
106 | + struct sockaddr_nl peer; | |
107 | + unsigned char *buf = NULL; | |
108 | + int running = 1, len; | |
109 | + | |
110 | + while (running) { | |
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); | |
115 | + return -1; | |
116 | + } | |
117 | + | |
118 | + struct nlmsghdr *h = (struct nlmsghdr*)buf; | |
119 | + while (nlmsg_ok(h, len)) { | |
120 | + if (h->nlmsg_type == NLMSG_DONE) { | |
121 | + running = 0; | |
122 | + break; | |
123 | + } | |
124 | + | |
125 | + struct inet_diag_msg *r = nlmsg_data(h); | |
126 | + | |
127 | + if (r->idiag_family != AF_INET) { | |
128 | + h = nlmsg_next(h, &len); | |
129 | + continue; | |
130 | + } | |
131 | + | |
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); | |
137 | + memcpy(&pcb.inp_faddr.s_addr, r->id.idiag_dst, r->idiag_family == AF_INET ? 4 : 6); | |
138 | + | |
139 | + pcb.inp_lport = r->id.idiag_sport; | |
140 | + pcb.inp_fport = r->id.idiag_dport; | |
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 | + | |
158 | + h = nlmsg_next(h, &len); | |
159 | + } | |
160 | + free(buf); | |
161 | + } | |
162 | + | |
163 | + nl_handle_destroy(nl); | |
164 | + | |
165 | + if (tcp_head) { | |
166 | + DEBUGMSGTL(("mibII/tcpTable", "Loaded TCP Table using netlink\n")); | |
167 | + return 0; | |
168 | + } | |
169 | + DEBUGMSGTL(("mibII/tcpTable", "Failed to load TCP Table (netlink)\n")); | |
170 | + return -1; | |
171 | +} | |
172 | + | |
173 | int | |
174 | tcpTable_load(netsnmp_cache *cache, void *vmagic) | |
175 | { | |
176 | @@ -551,6 +662,10 @@ | |
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"); |