]>
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) | |
3fd57f2a ER |
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 | |
40 | @@ -147,7 +147,7 @@ | |
41 | $(RANLIB) $(AGENTLIB) | |
42 | ||
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) | |
46 | $(RANLIB) $(MIBLIB) | |
47 | ||
48 | agentlib: $(AGENTLIB) | |
49 | --- net-snmp-5.4.2.1-dev/agent/mibgroup/mibII/tcpTable.c 2007-10-14 15:12:58.000000000 +0300 | |
50 | +++ net-snmp-5.4.2.1/agent/mibgroup/mibII/tcpTable.c 2009-01-23 01:22:10.435006124 +0200 | |
51 | @@ -29,6 +29,12 @@ | |
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 <linux/inet_diag.h> | |
58 | +#include <sys/socket.h> | |
59 | +#include <sys/types.h> | |
60 | +#endif | |
61 | ||
62 | #include <net-snmp/net-snmp-includes.h> | |
63 | #include <net-snmp/agent/net-snmp-agent-includes.h> | |
64 | @@ -543,6 +549,95 @@ | |
65 | #else /* hpux11 */ | |
66 | ||
67 | #ifdef linux | |
68 | + | |
69 | +// see <netinet/tcp.h> | |
70 | +#define TCP_ALL ((1 << TCP_CLOSING + 1) - 1) | |
71 | + | |
72 | +static int | |
73 | +tcpTable_load_netlink() | |
74 | +{ | |
75 | + struct inpcb pcb, *nnew; | |
76 | + struct nl_handle nl; | |
77 | + | |
78 | + memset(&nl, 0, sizeof(nl)); | |
79 | + | |
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()); | |
83 | + return -1; | |
84 | + } | |
85 | + | |
86 | + struct inet_diag_req req = { | |
87 | + .idiag_family = AF_INET || AF_INET6, | |
88 | + .idiag_states = TCP_ALL, | |
89 | + }; | |
90 | + | |
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()); | |
94 | + return -1; | |
95 | + } | |
96 | + | |
97 | + struct sockaddr_nl addr; | |
98 | + char *buf = NULL; | |
99 | + int running = 1, len; | |
100 | + | |
101 | + while (running) { | |
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()); | |
105 | + return -1; | |
106 | + } | |
107 | + | |
108 | + struct nlmsghdr *h = (struct nlmsghdr*)buf; | |
109 | + while (NLMSG_OK(h, len)) { | |
110 | + if (h->nlmsg_type == NLMSG_DONE) { | |
111 | + running = 0; | |
112 | + break; | |
113 | + } | |
114 | + | |
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 }; | |
119 | + | |
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); | |
122 | + | |
123 | + pcb.inp_lport = htons(r->id.idiag_sport); | |
124 | + pcb.inp_fport = htons(r->id.idiag_dport); | |
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 | + | |
142 | + h = NLMSG_NEXT(h, len); | |
143 | + } | |
144 | + free(buf); | |
145 | + } | |
146 | + | |
147 | + nl_close(&nl); | |
148 | + | |
149 | + if (tcp_head) { | |
150 | + DEBUGMSGTL(("mibII/tcpTable", "Loaded TCP Table using netlink\n")); | |
151 | + return 0; | |
152 | + } | |
153 | + DEBUGMSGTL(("mibII/tcpTable", "Failed to load TCP Table (netlink)\n")); | |
154 | + return -1; | |
155 | +} | |
156 | + | |
157 | int | |
158 | tcpTable_load(netsnmp_cache *cache, void *vmagic) | |
159 | { | |
160 | @@ -551,6 +646,10 @@ | |
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"); |