~ubuntu-branches/ubuntu/hardy/net-snmp/hardy-updates

« back to all changes in this revision

Viewing changes to agent/mibgroup/tcp-mib/data_access/tcpConn_linux.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-12-08 14:59:50 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20071208145950-u1tykhpw56nyzqik
Tags: 5.4.1~dfsg-4ubuntu1
* Merge from debian unstable.
* Remaining Ubuntu changes:
  - Remove stop links from rc0 and rc6
  - Munge Maintainer field as per spec.
* Ubuntu changes dropped:
  - Symlink common files between the packages, CDBS ought to handle that
    for us automatically.
* The latest Debian changes has dropped history from the changelog. Slot in
  the Ubuntu changes as best I can. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  tcpConnTable MIB architecture support
3
3
 *
4
 
 * $Id: tcpConn_linux.c,v 1.5 2005/12/10 16:35:37 rstory Exp $
 
4
 * $Id: tcpConn_linux.c 15654 2006-12-08 14:30:56Z rstory $
5
5
 */
6
6
#include <net-snmp/net-snmp-config.h>
7
7
#include <net-snmp/net-snmp-includes.h>
16
16
linux_states[12] = { 1, 5, 3, 4, 6, 7, 11, 1, 8, 9, 2, 10 };
17
17
 
18
18
static int _load4(netsnmp_container *container, u_int flags);
19
 
#if defined (INET6)
 
19
#if defined (NETSNMP_ENABLE_IPV6)
20
20
static int _load6(netsnmp_container *container, u_int flags);
21
21
#endif
22
22
 
80
80
{
81
81
    int rc = 0;
82
82
 
 
83
    DEBUGMSGTL(("access:tcpconn:container",
 
84
                "tcpconn_container_arch_load (flags %p)\n", load_flags));
 
85
 
 
86
    if (NULL == container) {
 
87
        snmp_log(LOG_ERR, "no container specified/found for access_tcpconn\n");
 
88
        return -1;
 
89
    }
 
90
 
83
91
    rc = _load4(container, load_flags);
84
 
    if(rc < 0) {
85
 
        u_int flags = NETSNMP_ACCESS_TCPCONN_FREE_KEEP_CONTAINER;
86
 
        netsnmp_access_tcpconn_container_free(container, flags);
 
92
 
 
93
#if defined (NETSNMP_ENABLE_IPV6)
 
94
    if((0 != rc) || (load_flags & NETSNMP_ACCESS_TCPCONN_LOAD_IPV4_ONLY))
87
95
        return rc;
88
 
    }
89
96
 
90
 
#if defined (INET6)
 
97
    /*
 
98
     * load ipv6. ipv6 module might not be loaded,
 
99
     * so ignore -2 err (file not found)
 
100
     */
91
101
    rc = _load6(container, load_flags);
92
 
    if(rc < 0) {
93
 
        u_int flags = NETSNMP_ACCESS_TCPCONN_FREE_KEEP_CONTAINER;
94
 
        netsnmp_access_tcpconn_container_free(container, flags);
95
 
        return rc;
96
 
    }
 
102
    if (-2 == rc)
 
103
        rc = 0;
97
104
#endif
98
105
 
99
 
    return 0;
 
106
    return rc;
100
107
}
101
108
 
102
109
/**
127
134
     */
128
135
    while (fgets(line, sizeof(line), in)) {
129
136
        netsnmp_tcpconn_entry *entry;
130
 
        int             state, rc, local_port, remote_port, buf_len, offset, tmp_state;
 
137
        int             state, rc, local_port, remote_port, tmp_state;
 
138
        size_t          buf_len, offset;
131
139
        u_char          local_addr[10], remote_addr[10];
132
140
        u_char         *tmp_ptr;
133
141
 
168
176
            break;
169
177
        }
170
178
 
171
 
        entry->loc_port = htons((unsigned short) local_port);
172
 
        entry->rmt_port = htons((unsigned short) remote_port);
 
179
        /** oddly enough, these appear to already be in network order */
 
180
        entry->loc_port = (unsigned short) local_port;
 
181
        entry->rmt_port = (unsigned short) remote_port;
173
182
        entry->tcpConnState = state;
 
183
        
 
184
        /** the addr string may need work */
174
185
        buf_len = strlen(local_addr);
175
 
        netsnmp_assert(8 == buf_len);
 
186
        if ((8 != buf_len) ||
 
187
            (-1 == netsnmp_addrstr_hton(local_addr, 8))) {
 
188
            DEBUGMSGT(("verbose:access:tcpconn:container",
 
189
                       " error processing local address\n"));
 
190
            netsnmp_access_tcpconn_entry_free(entry);
 
191
            continue;
 
192
        }
176
193
        offset = 0;
177
194
        tmp_ptr = entry->loc_addr;
178
195
        rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
187
204
            continue;
188
205
        }
189
206
 
190
 
        buf_len = strlen(remote_addr);
191
 
        netsnmp_assert(8 == buf_len);
 
207
        /** the addr string may need work */
 
208
        buf_len = strlen((char*)remote_addr);
 
209
        if ((8 != buf_len) ||
 
210
            (-1 == netsnmp_addrstr_hton(remote_addr, 8))) {
 
211
            DEBUGMSGT(("verbose:access:tcpconn:container",
 
212
                       " error processing remote address\n"));
 
213
            netsnmp_access_tcpconn_entry_free(entry);
 
214
            continue;
 
215
        }
192
216
        offset = 0;
193
217
        tmp_ptr = entry->rmt_addr;
194
218
        rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
218
242
    return 0;
219
243
}
220
244
 
221
 
#if defined (INET6)
 
245
#if defined (NETSNMP_ENABLE_IPV6)
222
246
/**
223
247
 *
224
248
 * @retval  0 no errors
230
254
    int             rc = 0;
231
255
    FILE           *in;
232
256
    char            line[180];
233
 
    
 
257
    static int      log_open_err = 1;
 
258
 
234
259
    netsnmp_assert(NULL != container);
235
260
 
236
261
#undef PROCFILE
237
262
#define PROCFILE "/proc/net/tcp6"
238
263
    if (!(in = fopen(PROCFILE, "r"))) {
239
264
        snmp_log(LOG_ERR,"could not open " PROCFILE "\n");
 
265
        if (1 == log_open_err) {
 
266
            snmp_log(LOG_ERR,"could not open " PROCFILE "\n");
 
267
            log_open_err = 0;
 
268
        }
240
269
        return -2;
241
270
    }
 
271
    /*
 
272
     * if we turned off logging of open errors, turn it back on now that
 
273
     * we have been able to open the file.
 
274
     */
 
275
    if (0 == log_open_err)
 
276
        log_open_err = 1;
242
277
    
243
278
    fgets(line, sizeof(line), in); /* skip header */
244
279
 
245
280
    /*
 
281
     * Note: PPC (big endian)
 
282
     *
246
283
     *   sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
247
284
     *  0: 00000000000000000000000000000001:1466 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000   500        0 326699 1 efb81580 3000 0 0 2 -1
248
285
     */
249
286
    while (fgets(line, sizeof(line), in)) {
250
287
        netsnmp_tcpconn_entry *entry;
251
 
        int             state, rc, local_port, remote_port, buf_len, offset,
252
 
                        tmp_state;
 
288
        int             state, rc, local_port, remote_port, tmp_state;
 
289
        size_t          buf_len, offset;
253
290
        u_char          local_addr[48], remote_addr[48];
254
291
        u_char         *tmp_ptr;
255
292
 
290
327
            break;
291
328
        }
292
329
 
293
 
        entry->loc_port = htons((unsigned short) local_port);
294
 
        entry->rmt_port = htons((unsigned short) remote_port);
 
330
        /** oddly enough, these appear to already be in network order */
 
331
        entry->loc_port = (unsigned short) local_port;
 
332
        entry->rmt_port = (unsigned short) remote_port;
295
333
        entry->tcpConnState = state;
296
334
 
297
 
        buf_len = strlen(local_addr);
 
335
        /** the addr string may need work */
 
336
        buf_len = strlen((char*)local_addr);
 
337
        if ((32 != buf_len) ||
 
338
            (-1 == netsnmp_addrstr_hton(local_addr, 32))) {
 
339
            DEBUGMSGT(("verbose:access:tcpconn:container",
 
340
                       " error processing local address\n"));
 
341
            netsnmp_access_tcpconn_entry_free(entry);
 
342
            continue;
 
343
        }
298
344
        offset = 0;
299
345
        tmp_ptr = entry->loc_addr;
300
346
        rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
309
355
            continue;
310
356
        }
311
357
 
312
 
        buf_len = strlen(remote_addr);
 
358
        buf_len = strlen((char*)remote_addr);
 
359
        if ((32 != buf_len) ||
 
360
            (-1 == netsnmp_addrstr_hton(remote_addr, 32))) {
 
361
            DEBUGMSGT(("verbose:access:tcpconn:container",
 
362
                       " error processing remote address\n"));
 
363
            netsnmp_access_tcpconn_entry_free(entry);
 
364
            continue;
 
365
        }
313
366
        offset = 0;
314
367
        tmp_ptr = entry->rmt_addr;
315
368
        rc = netsnmp_hex_to_binary(&tmp_ptr, &buf_len,
339
392
 
340
393
    return 0;
341
394
}
342
 
#endif /* INET6 */
 
395
#endif /* NETSNMP_ENABLE_IPV6 */