]> git.pld-linux.org Git - packages/net-snmp.git/blob - net-snmp-snmpnetstat-getbulk.patch
- rel 18; STBR
[packages/net-snmp.git] / net-snmp-snmpnetstat-getbulk.patch
1 --- net-snmp-5.4.2.1-dev/apps/snmpnetstat/inet.c        2009-01-22 18:26:23.264301468 +0200
2 +++ net-snmp-5.4.2.1-dev/apps/snmpnetstat/inet.c        2009-01-22 18:48:30.400620330 +0200
3 @@ -106,20 +106,65 @@
4  };
5  #define TCP_NSTATES 11
6  
7 -void
8 -tcpprotopr(const char *name)
9 +static void
10 +tcpprotoprint_line(const char *name, netsnmp_variable_list *vp, int *first)
11  {
12 -    netsnmp_variable_list *var, *vp;
13 -    oid    tcpConnState_oid[] = { 1,3,6,1,2,1,6,13,1,1 };
14 -    size_t tcpConnState_len   = OID_LENGTH( tcpConnState_oid );
15      int    state, width;
16 +    char  *cp;
17      union {
18          struct in_addr addr;
19          char      data[4];
20      } tmpAddr;
21      oid    localPort, remotePort;
22      struct in_addr localAddr, remoteAddr;
23 -    char  *cp;
24 +
25 +       state = *vp->val.integer;
26 +       if (!aflag && state == MIB_TCPCONNSTATE_LISTEN) {
27 +               return;
28 +       }
29 +
30 +       if (*first) {
31 +               printf("Active Internet (%s) Connections", name);
32 +               if (aflag)
33 +                       printf(" (including servers)");
34 +               putchar('\n');
35 +               width = Aflag ? 18 : 22;
36 +               printf("%-5.5s %*.*s %*.*s %s\n",
37 +                          "Proto", -width, width, "Local Address",
38 +                                               -width, width, "Remote Address", "(state)");
39 +               *first = 0;
40 +       }
41 +       
42 +       /* Extract the local/remote information from the index values */
43 +       cp = tmpAddr.data;
44 +       cp[0] = vp->name[ 10 ] & 0xff;
45 +       cp[1] = vp->name[ 11 ] & 0xff;
46 +       cp[2] = vp->name[ 12 ] & 0xff;
47 +       cp[3] = vp->name[ 13 ] & 0xff;
48 +       localAddr.s_addr = tmpAddr.addr.s_addr;
49 +       localPort        = ntohs(vp->name[ 14 ]);
50 +       cp = tmpAddr.data;
51 +       cp[0] = vp->name[ 15 ] & 0xff;
52 +       cp[1] = vp->name[ 16 ] & 0xff;
53 +       cp[2] = vp->name[ 17 ] & 0xff;
54 +       cp[3] = vp->name[ 18 ] & 0xff;
55 +       remoteAddr.s_addr = tmpAddr.addr.s_addr;
56 +       remotePort        = ntohs(vp->name[ 19 ]);
57 +
58 +       printf("%-5.5s", name);
59 +       inetprint(&localAddr,  localPort,  name, 1);
60 +       inetprint(&remoteAddr, remotePort, name, 0);
61 +       if (state < 1 || state > TCP_NSTATES) {
62 +               printf("%d\n", state );
63 +       } else {
64 +               printf("%s\n", tcpstates[state]);
65 +       }
66 +}
67 +
68 +static void
69 +tcpprotopr_get(const char *name, oid *root, size_t root_len)
70 +{
71 +    netsnmp_variable_list *var, *vp;
72      int    first = 1;
73  
74      /*
75 @@ -127,7 +172,7 @@
76       *   the necessary information.
77       */
78      var = NULL;
79 -    snmp_varlist_add_variable( &var, tcpConnState_oid, tcpConnState_len,
80 +    snmp_varlist_add_variable( &var, root, root_len,
81                                     ASN_NULL, NULL,  0);
82      if (!var)
83          return;
84 @@ -137,45 +182,111 @@
85      for (vp = var; vp ; vp=vp->next_variable) {
86 -        state = *vp->val.integer;
87 -        if (!aflag && state == MIB_TCPCONNSTATE_LISTEN)
88 -            continue;
89 -
90 -        if (first) {
91 -            printf("Active Internet (%s) Connections", name);
92 -            if (aflag)
93 -                printf(" (including servers)");
94 -            putchar('\n');
95 -            width = Aflag ? 18 : 22;
96 -            printf("%-5.5s %*.*s %*.*s %s\n",
97 -                   "Proto", -width, width, "Local Address",
98 -                            -width, width, "Remote Address", "(state)");
99 -            first=0;
100 -        }
101 -        
102 -        /* Extract the local/remote information from the index values */
103 -        cp = tmpAddr.data;
104 -        cp[0] = vp->name[ 10 ] & 0xff;
105 -        cp[1] = vp->name[ 11 ] & 0xff;
106 -        cp[2] = vp->name[ 12 ] & 0xff;
107 -        cp[3] = vp->name[ 13 ] & 0xff;
108 -        localAddr.s_addr = tmpAddr.addr.s_addr;
109 -        localPort        = ntohs(vp->name[ 14 ]);
110 -        cp = tmpAddr.data;
111 -        cp[0] = vp->name[ 15 ] & 0xff;
112 -        cp[1] = vp->name[ 16 ] & 0xff;
113 -        cp[2] = vp->name[ 17 ] & 0xff;
114 -        cp[3] = vp->name[ 18 ] & 0xff;
115 -        remoteAddr.s_addr = tmpAddr.addr.s_addr;
116 -        remotePort        = ntohs(vp->name[ 19 ]);
117 -
118 -        printf("%-5.5s", name);
119 -        inetprint(&localAddr,  localPort,  name, 1);
120 -        inetprint(&remoteAddr, remotePort, name, 0);
121 -        if ( state < 1 || state > TCP_NSTATES )
122 -            printf("%d\n", state );
123 -        else
124 -            printf("%s\n", tcpstates[ state ]);
125 +               tcpprotoprint_line(name, vp, &first);
126      }
127      snmp_free_varbind( var );
128  }
129  
130 +void
131 +tcpprotopr_bulkget(const char *name, oid *root, size_t root_len)
132 +{
133 +    netsnmp_variable_list *vp;
134 +       netsnmp_pdu    *pdu, *response;
135 +    oid             tcpConnState_oid[MAX_OID_LEN];
136 +       size_t          tcpConnState_len;
137 +    int    first = 1;
138 +    int    running = 1;
139 +    int    status;
140 +
141 +       /*
142 +     * setup initial object name
143 +     */
144 +       memmove(tcpConnState_oid, root, sizeof(root) * root_len);
145 +       tcpConnState_len = root_len;
146 +
147 +    /*
148 +     * Walking the tcpConnState column will provide all
149 +     *   the necessary information.
150 +     */
151 +       while (running) {
152 +        /*
153 +         * create PDU for GETBULK request and add object name to request
154 +         */
155 +        pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
156 +        pdu->non_repeaters = 0;
157 +        pdu->max_repetitions = max_getbulk;    /* fill the packet */
158 +        snmp_add_null_var(pdu, tcpConnState_oid, tcpConnState_len);
159 +
160 +        /*
161 +         * do the request
162 +         */
163 +        status = snmp_synch_response(ss, pdu, &response);
164 +        if (status == STAT_SUCCESS) {
165 +            if (response->errstat == SNMP_ERR_NOERROR) {
166 +                               for (vp = response->variables; vp ; vp=vp->next_variable) {
167 +                    if ((vp->name_length < root_len) ||
168 +                                                       (memcmp(root, vp->name, sizeof(oid) * root_len) != 0)) {
169 +                        /*
170 +                         * not part of this subtree
171 +                         */
172 +                        running = 0;
173 +                        continue;
174 +                    }
175 +
176 +                                       tcpprotoprint_line(name, vp, &first);
177 +
178 +                    if ((vp->type != SNMP_ENDOFMIBVIEW) &&
179 +                        (vp->type != SNMP_NOSUCHOBJECT) &&
180 +                        (vp->type != SNMP_NOSUCHINSTANCE)) {
181 +                        /*
182 +                         * Check if last variable, and if so, save for next request.
183 +                         */
184 +                        if (vp->next_variable == NULL) {
185 +                            memmove(tcpConnState_oid, vp->name,
186 +                                    vp->name_length * sizeof(oid));
187 +                            tcpConnState_len = vp->name_length;
188 +                        }
189 +                    } else {
190 +                        /*
191 +                         * an exception value, so stop
192 +                         */
193 +                        running = 0;
194 +                    }
195 +                               }
196 +            } else {
197 +                /*
198 +                 * error in response, print it
199 +                 */
200 +                running = 0;
201 +            }
202 +        } else if (status == STAT_TIMEOUT) {
203 +            running = 0;
204 +        } else {                /* status == STAT_ERROR */
205 +            running = 0;
206 +        }
207 +
208 +        if (response) {
209 +            snmp_free_pdu(response);
210 +               }
211 +       }
212 +}
213 +
214 +void
215 +tcpprotopr(const char *name)
216 +{
217 +    oid    tcpConnState_oid[] = { 1,3,6,1,2,1,6,13,1,1 };
218 +    size_t tcpConnState_len   = OID_LENGTH( tcpConnState_oid );
219 +       int    use_getbulk = 1;
220 +
221 +#ifndef NETSNMP_DISABLE_SNMPV1
222 +    if (ss->version == SNMP_VERSION_1) {
223 +        use_getbulk = 0;
224 +       }
225 +#endif
226 +
227 +       if (use_getbulk) {
228 +               tcpprotopr_bulkget(name, tcpConnState_oid, tcpConnState_len);
229 +       } else {
230 +               tcpprotopr_get(name, tcpConnState_oid, tcpConnState_len);
231 +       }
232 +}
233 +
234  /*
235 --- net-snmp-5.4.2.1/man/snmpnetstat.1.def      2009-01-22 18:43:30.073986008 +0200
236 +++ net-snmp-5.4.2.1-dev/man/snmpnetstat.1.def  2009-01-22 18:57:34.170565184 +0200
237 @@ -92,6 +92,12 @@
238  traffic on the configured network interfaces.
239  The fourth form displays statistics about the named protocol.
240  .PP
241 +.B snmpnetstat
242 +will issue GETBULK requests to query for information
243 +if at least protocol version
244 +.I v2
245 +is used.
246 +.PP
247  AGENT identifies a target SNMP agent, which is
248  instrumented to monitor the given objects.
249  At its simplest, the AGENT specification will
250 @@ -164,6 +170,11 @@
251  is also present, show per-protocol routing statistics instead of 
252  the routing tables.
253  .PP
254 +.BI \-CR " repeaters"
255 +For GETBULK requests,
256 +.I repeaters
257 +specifies the max-repeaters value to use.
258 +.PP
259  When  snmpnetstat is invoked with an interval argument, it
260  displays a running count of statistics related to  network
261  interfaces.
262 --- net-snmp-5.4.2.1/apps/snmpnetstat/main.c    2006-09-15 03:48:50.000000000 +0300
263 +++ net-snmp-5.4.2.1-dev/apps/snmpnetstat/main.c        2009-01-22 18:48:17.313950236 +0200
264 @@ -75,9 +75,11 @@
265  int    tflag;          /* show i/f watchdog timers */
266  int    vflag;          /* be verbose */
267  
268 +
269  int    interval;       /* repeat interval for i/f stats */
270  char   *intrface;      /* desired i/f for stats, or NULL for all i/fs */
271  int    af;             /* address family */
272 +int     max_getbulk = 32;  /* specifies the max-repeaters value to use with GETBULK requests */
273  
274  char    *progname = NULL;
275  
276 @@ -231,6 +233,24 @@
277                 case 'r':
278                         rflag = 1;
279                         break;
280 +               case 'R':
281 +                        if (optind < argc) {
282 +                            if (argv[optind]) {
283 +                                max_getbulk = atoi(argv[optind]);
284 +                                if (max_getbulk == 0) {
285 +                                    usage();
286 +                                    fprintf(stderr, "Bad -CR option: %s\n", 
287 +                                            argv[optind]);
288 +                                    exit(1);
289 +                                }
290 +                            }
291 +                        } else {
292 +                            usage();
293 +                            fprintf(stderr, "Bad -CR option: no argument given\n");
294 +                            exit(1);
295 +                        }
296 +                        optind++;
297 +                        break;
298                 case 'S':            /* FreeBSD:
299                                         NetBSD:  Semi-numeric display
300                                         OpenBSD: Show route source selector */
301 --- net-snmp-5.4.2.1/apps/snmpnetstat/netstat.h~        2009-01-22 19:09:36.000000000 +0200
302 +++ net-snmp-5.4.2.1/apps/snmpnetstat/netstat.h 2009-01-22 19:09:38.270836446 +0200
303 @@ -62,6 +62,7 @@
304  extern char    *intrface;      /* desired i/f for stats, or NULL for all i/fs */
305  
306  extern int     af;             /* address family */
307 +extern int  max_getbulk;  /* specifies the max-repeaters value to use with GETBULK requests */
308  
309  extern char *__progname; /* program name, from crt0.o */
310  
This page took 0.065605 seconds and 3 git commands to generate.