quip_client.c revision 1.6 1 1.6 itojun /* $NetBSD: quip_client.c,v 1.6 2002/03/05 04:11:52 itojun Exp $ */
2 1.6 itojun /* $KAME: quip_client.c,v 1.7 2001/12/28 00:50:28 itojun Exp $ */
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (C) 1999-2000
5 1.1 thorpej * Sony Computer Science Laboratories, Inc. All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej *
16 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
17 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
20 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 thorpej * SUCH DAMAGE.
27 1.1 thorpej */
28 1.1 thorpej
29 1.1 thorpej #include <sys/param.h>
30 1.1 thorpej #include <sys/socket.h>
31 1.1 thorpej #include <sys/un.h>
32 1.1 thorpej
33 1.1 thorpej #include <stdio.h>
34 1.1 thorpej #include <stdlib.h>
35 1.1 thorpej #include <unistd.h>
36 1.1 thorpej #include <string.h>
37 1.1 thorpej #include <errno.h>
38 1.1 thorpej #include <err.h>
39 1.1 thorpej
40 1.1 thorpej #include "quip_client.h"
41 1.1 thorpej #include "altqstat.h"
42 1.1 thorpej
43 1.1 thorpej /*
44 1.1 thorpej * quip (queue information protocol) is a http-like protocol
45 1.1 thorpej * in order to retrieve information from the server.
46 1.1 thorpej * a unix domain TCP socket "/var/run/altq_quip" is used for
47 1.5 wiz * client-server style communication.
48 1.1 thorpej *
49 1.1 thorpej * there are 2 quip message types: request and response.
50 1.1 thorpej * request format: (only single-line request message is used at this moment)
51 1.1 thorpej * request-line
52 1.1 thorpej *
53 1.1 thorpej * request-line = <method> <operation>[?<query>] <quip-version>
54 1.1 thorpej * <method> = GET (only GET is defined at this moment)
55 1.1 thorpej * <operation> = list | handle-to-name | qdisc | filter
56 1.1 thorpej * query format is operation dependent but most query takes
57 1.1 thorpej * <interface> or <class> or <filter>.
58 1.1 thorpej * <interface> = <if_name>
59 1.1 thorpej * <class> = <if_name>:<class_path>/<class_name>
60 1.1 thorpej * <filter> = <if_name>:<class_path>/<class_name>:<filter_name>
61 1.1 thorpej * "list" operation accepts "*" as a wildcard.
62 1.1 thorpej *
63 1.1 thorpej * response format:
64 1.1 thorpej * status-line
65 1.1 thorpej * response-headers (0 or more)
66 1.1 thorpej * <blank line>
67 1.1 thorpej * body
68 1.1 thorpej *
69 1.1 thorpej * status-line = <quip-version> <status-code> <reason phrase>
70 1.1 thorpej * response-header = Content-Length:<value>
71 1.1 thorpej *
72 1.1 thorpej * "Content-Length" specifies the length of the message body.
73 1.1 thorpej *
74 1.1 thorpej * example:
75 1.1 thorpej * to retrieve a list of classes (handle and name) on interface "fxp0":
76 1.1 thorpej * a request message looks like,
77 1.1 thorpej * GET list?fxp0:* QUIP/1.0<cr>
78 1.1 thorpej * a response message looks like,
79 1.1 thorpej * QUIP/1.0 200 OK<cr>
80 1.1 thorpej * Content-Length:86<cr>
81 1.1 thorpej * <cr>
82 1.1 thorpej * 0000000000 fxp0:/root<cr>
83 1.1 thorpej * 0xc0d1be00 fxp0:/root/parent<cr>
84 1.1 thorpej * 0xc0d1ba00 fxp0:/root/parent/child<cr>
85 1.1 thorpej *
86 1.1 thorpej * other examples:
87 1.1 thorpej * list all interfaces, classes, and filters:
88 1.1 thorpej * GET list QUIP/1.0<cr>
89 1.1 thorpej * list all interfaces:
90 1.1 thorpej * GET list?* QUIP/1.0<cr>
91 1.1 thorpej * list all classes:
92 1.1 thorpej * GET list?*:* QUIP/1.0<cr>
93 1.1 thorpej * list all filters:
94 1.1 thorpej * GET list?*:*:* QUIP/1.0<cr>
95 1.1 thorpej * convert class handle to class name:
96 1.1 thorpej * GET handle-to-name?fxp0:0xc0d1be00 QUIP/1.0<cr>
97 1.1 thorpej * convert filter handle to filter name:
98 1.1 thorpej * GET handle-to-name?fxp0::0x1000000a QUIP/1.0<cr>
99 1.1 thorpej */
100 1.1 thorpej
101 1.4 itojun #define MAXLINESIZE 1024
102 1.4 itojun
103 1.1 thorpej enum nametype { INTERFACE, CLASS, FILTER, CONDITIONER };
104 1.1 thorpej
105 1.1 thorpej static FILE *server = NULL;
106 1.1 thorpej int quip_echo = 0;
107 1.1 thorpej
108 1.2 itojun static char *extract_ifname(const char *);
109 1.1 thorpej
110 1.1 thorpej int
111 1.1 thorpej quip_openserver(void)
112 1.1 thorpej {
113 1.1 thorpej struct sockaddr_un addr;
114 1.1 thorpej int fd;
115 1.1 thorpej
116 1.1 thorpej if ((fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0)
117 1.1 thorpej err(1, "can't open socket");
118 1.1 thorpej
119 1.1 thorpej bzero(&addr, sizeof(addr));
120 1.1 thorpej addr.sun_family = AF_LOCAL;
121 1.2 itojun strlcpy(addr.sun_path, QUIP_PATH,sizeof(addr.sun_path));
122 1.1 thorpej
123 1.1 thorpej if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
124 1.1 thorpej fprintf(stderr, "can't talk to altqd!\n"
125 1.1 thorpej "probably, altqd is not running\n");
126 1.1 thorpej return (-1);
127 1.1 thorpej }
128 1.1 thorpej
129 1.1 thorpej if ((server = fdopen(fd, "r+")) == NULL) {
130 1.1 thorpej warn("fdopen: can't open stream to the quip server");
131 1.1 thorpej return (-1);
132 1.1 thorpej }
133 1.1 thorpej return (0);
134 1.1 thorpej }
135 1.1 thorpej
136 1.1 thorpej int
137 1.1 thorpej quip_closeserver(void)
138 1.1 thorpej {
139 1.1 thorpej if (server != NULL)
140 1.1 thorpej return fclose(server);
141 1.1 thorpej return (0);
142 1.1 thorpej }
143 1.1 thorpej
144 1.1 thorpej void
145 1.1 thorpej quip_sendrequest(FILE *fp, const char *request)
146 1.1 thorpej {
147 1.2 itojun char buf[QUIPMSG_MAXSIZE], *cp;
148 1.1 thorpej int n;
149 1.1 thorpej
150 1.1 thorpej if ((cp = strstr(request, "QUIP")) == NULL) {
151 1.1 thorpej cp = strchr(request, '\n');
152 1.1 thorpej n = cp - request;
153 1.2 itojun if (cp == NULL || n > REQ_MAXSIZE - 10)
154 1.2 itojun return;
155 1.1 thorpej strncpy(buf, request, n);
156 1.4 itojun snprintf(buf + n, REQ_MAXSIZE - n, " QUIP/1.0");
157 1.4 itojun strlcat(buf, cp, REQ_MAXSIZE);
158 1.1 thorpej }
159 1.1 thorpej else
160 1.2 itojun strlcpy(buf, request, REQ_MAXSIZE);
161 1.1 thorpej
162 1.1 thorpej if (fputs(buf, fp) != 0)
163 1.1 thorpej err(1, "fputs");
164 1.1 thorpej if (fflush(fp) != 0)
165 1.1 thorpej err(1, "fflush");
166 1.1 thorpej if (quip_echo) {
167 1.1 thorpej fputs("<< ", stdout);
168 1.1 thorpej fputs(buf, stdout);
169 1.1 thorpej }
170 1.1 thorpej }
171 1.1 thorpej
172 1.1 thorpej /*
173 1.1 thorpej * recv_response receives a response message from the server
174 1.1 thorpej * and returns status_code.
175 1.1 thorpej */
176 1.1 thorpej int
177 1.1 thorpej quip_recvresponse(FILE *fp, char *header, char *body, int *blen)
178 1.1 thorpej {
179 1.4 itojun char buf[MAXLINESIZE], version[MAXLINESIZE];
180 1.4 itojun int code, resid, len, buflen;
181 1.1 thorpej int end_of_header = 0;
182 1.1 thorpej
183 1.1 thorpej if (blen != NULL)
184 1.1 thorpej *blen = 0;
185 1.1 thorpej code = 0;
186 1.1 thorpej resid = 0;
187 1.4 itojun buflen = RES_MAXSIZE;
188 1.2 itojun while (fgets(buf, sizeof(buf), fp) != 0) {
189 1.1 thorpej if (quip_echo) {
190 1.1 thorpej fputs("> ", stdout);
191 1.1 thorpej fputs(buf, stdout);
192 1.1 thorpej }
193 1.1 thorpej
194 1.1 thorpej if (!end_of_header) {
195 1.1 thorpej /* process message header */
196 1.4 itojun if (header != NULL) {
197 1.4 itojun len = strlcpy(header, buf, buflen);
198 1.4 itojun if (len >= buflen) {
199 1.4 itojun /* header too long */
200 1.4 itojun fpurge(fp);
201 1.4 itojun return (-1);
202 1.4 itojun }
203 1.4 itojun header += len;
204 1.4 itojun buflen -= len;
205 1.4 itojun }
206 1.1 thorpej
207 1.1 thorpej if (code == 0) {
208 1.1 thorpej /* status line expected */
209 1.1 thorpej if (buf[0] == '\n') {
210 1.1 thorpej /* ignore blank lines */
211 1.1 thorpej }
212 1.1 thorpej else if (sscanf(buf, "%s %d",
213 1.1 thorpej version, &code) != 2) {
214 1.1 thorpej /* can't get result code */
215 1.1 thorpej fpurge(fp);
216 1.1 thorpej return (-1);
217 1.1 thorpej }
218 1.1 thorpej }
219 1.1 thorpej else {
220 1.1 thorpej /* entity header expected */
221 1.1 thorpej char *field, *cp;
222 1.1 thorpej
223 1.1 thorpej if (buf[0] == '\n') {
224 1.1 thorpej /* end of header */
225 1.1 thorpej end_of_header = 1;
226 1.4 itojun buflen = BODY_MAXSIZE;
227 1.1 thorpej if (resid == 0)
228 1.1 thorpej /* no message body */
229 1.1 thorpej return (code);
230 1.1 thorpej }
231 1.1 thorpej
232 1.1 thorpej cp = buf;
233 1.1 thorpej field = strsep(&cp, ":");
234 1.1 thorpej if (strcmp(field, "Content-Length") == 0) {
235 1.2 itojun if (sscanf(cp, "%d", &resid) != 1) {
236 1.2 itojun fpurge(fp);
237 1.2 itojun return (-1);
238 1.2 itojun }
239 1.1 thorpej if (blen != NULL)
240 1.1 thorpej *blen = resid;
241 1.1 thorpej }
242 1.1 thorpej }
243 1.1 thorpej }
244 1.1 thorpej else {
245 1.1 thorpej /* process message body */
246 1.1 thorpej if (body != NULL) {
247 1.4 itojun len = strlcpy(body, buf, buflen);
248 1.4 itojun if (len >= buflen) {
249 1.4 itojun /* body too long */
250 1.4 itojun fpurge(fp);
251 1.4 itojun return (-1);
252 1.4 itojun }
253 1.1 thorpej body += len;
254 1.4 itojun buflen -= len;
255 1.1 thorpej }
256 1.1 thorpej else
257 1.1 thorpej len = strlen(buf);
258 1.1 thorpej resid -= len;
259 1.1 thorpej if (resid <= 0)
260 1.1 thorpej return (code);
261 1.1 thorpej }
262 1.1 thorpej }
263 1.1 thorpej return (-1);
264 1.1 thorpej }
265 1.1 thorpej
266 1.1 thorpej void
267 1.1 thorpej quip_rawmode(void)
268 1.1 thorpej {
269 1.4 itojun char line[MAXLINESIZE];
270 1.1 thorpej int result_code;
271 1.1 thorpej
272 1.1 thorpej printf(">>>Entering the raw interactive mode to the server:\n\n");
273 1.1 thorpej if (server == NULL) {
274 1.1 thorpej printf("No server available!\n");
275 1.1 thorpej return;
276 1.1 thorpej }
277 1.1 thorpej
278 1.1 thorpej while (1) {
279 1.1 thorpej printf("%% "); fflush(stdout);
280 1.1 thorpej /* read a line from stdin */
281 1.4 itojun if (fgets(line, sizeof(line), stdin) == NULL)
282 1.1 thorpej break;
283 1.1 thorpej
284 1.1 thorpej if (line[0] == '\n') {
285 1.1 thorpej /* if a blank line, echo locally */
286 1.1 thorpej fputs(line, stdout);
287 1.1 thorpej continue;
288 1.1 thorpej }
289 1.1 thorpej if (line[0] == 'q') {
290 1.1 thorpej printf("Exit\n");
291 1.1 thorpej break;
292 1.1 thorpej }
293 1.1 thorpej
294 1.1 thorpej /* send the input line to the server */
295 1.1 thorpej quip_sendrequest(server, line);
296 1.1 thorpej
297 1.1 thorpej /* get a response message from the server */
298 1.1 thorpej result_code = quip_recvresponse(server, NULL, NULL, NULL);
299 1.1 thorpej }
300 1.1 thorpej }
301 1.1 thorpej
302 1.1 thorpej char *
303 1.1 thorpej quip_selectinterface(char *ifname)
304 1.1 thorpej {
305 1.4 itojun char buf[BODY_MAXSIZE], *cp;
306 1.1 thorpej int result_code, len;
307 1.1 thorpej u_int if_index;
308 1.1 thorpej static char interface[64];
309 1.1 thorpej
310 1.1 thorpej if (server == NULL)
311 1.1 thorpej return (ifname);
312 1.1 thorpej
313 1.1 thorpej /* get an inferface list from the server */
314 1.1 thorpej quip_sendrequest(server, "GET list?*\n");
315 1.1 thorpej
316 1.1 thorpej result_code = quip_recvresponse(server, NULL, buf, &len);
317 1.1 thorpej if (result_code != 200)
318 1.1 thorpej errx(1, "can't get interface list");
319 1.1 thorpej
320 1.1 thorpej cp = buf;
321 1.1 thorpej while (1) {
322 1.1 thorpej if (sscanf(cp, "%x %s", &if_index, interface) != 2)
323 1.1 thorpej break;
324 1.1 thorpej if (ifname == NULL) {
325 1.1 thorpej /* if name isn't specified, return the 1st entry */
326 1.1 thorpej return (interface);
327 1.1 thorpej }
328 1.1 thorpej if (strcmp(ifname, interface) == 0)
329 1.4 itojun /* found the matching entry */
330 1.4 itojun return (interface);
331 1.1 thorpej if ((cp = strchr(cp+1, '\n')) == NULL)
332 1.1 thorpej break;
333 1.1 thorpej }
334 1.1 thorpej errx(1, "can't get interface");
335 1.1 thorpej return (NULL);
336 1.1 thorpej }
337 1.1 thorpej
338 1.1 thorpej char *
339 1.1 thorpej quip_selectqdisc(char *ifname, char *qdisc_name)
340 1.1 thorpej {
341 1.2 itojun char buf[BODY_MAXSIZE], req[REQ_MAXSIZE];
342 1.1 thorpej int result_code, len;
343 1.1 thorpej static char qdisc[64];
344 1.1 thorpej
345 1.1 thorpej if (server == NULL) {
346 1.1 thorpej if (ifname == NULL || qdisc_name == NULL)
347 1.1 thorpej errx(1, "when disabling server communication,\n"
348 1.1 thorpej "specify both interface (-i) and qdisc (-q)!");
349 1.1 thorpej return (qdisc_name);
350 1.1 thorpej }
351 1.1 thorpej
352 1.1 thorpej /* get qdisc info from the server */
353 1.2 itojun snprintf(req, sizeof(req), "GET qdisc?%s\n", ifname);
354 1.1 thorpej quip_sendrequest(server, req);
355 1.1 thorpej
356 1.1 thorpej result_code = quip_recvresponse(server, NULL, buf, &len);
357 1.1 thorpej if (result_code != 200)
358 1.1 thorpej errx(1, "can't get qdisc info");
359 1.1 thorpej
360 1.1 thorpej if (sscanf(buf, "%s", qdisc) != 1)
361 1.1 thorpej errx(1, "can't get qdisc name");
362 1.1 thorpej
363 1.1 thorpej if (qdisc_name != NULL && strcmp(qdisc, qdisc_name) != 0)
364 1.1 thorpej errx(1, "qdisc %s on %s doesn't match specified qdisc %s",
365 1.1 thorpej qdisc, ifname, qdisc_name);
366 1.1 thorpej
367 1.1 thorpej return (qdisc);
368 1.1 thorpej }
369 1.1 thorpej
370 1.1 thorpej void
371 1.2 itojun quip_chandle2name(const char *ifname, u_long handle, char *name, size_t size)
372 1.1 thorpej {
373 1.2 itojun char buf[BODY_MAXSIZE], req[REQ_MAXSIZE], *cp;
374 1.1 thorpej int result_code, len;
375 1.1 thorpej
376 1.1 thorpej name[0] = '\0';
377 1.1 thorpej if (server == NULL)
378 1.1 thorpej return;
379 1.1 thorpej
380 1.1 thorpej /* get class name from the server */
381 1.2 itojun snprintf(req, sizeof(req), "GET handle-to-name?%s:%#lx\n", ifname, handle);
382 1.1 thorpej quip_sendrequest(server, req);
383 1.1 thorpej
384 1.1 thorpej result_code = quip_recvresponse(server, NULL, buf, &len);
385 1.1 thorpej if (result_code != 200)
386 1.1 thorpej errx(1, "can't get class name");
387 1.1 thorpej
388 1.1 thorpej if ((cp = strchr(buf, '\n')) != NULL)
389 1.1 thorpej *cp = '\0';
390 1.1 thorpej if ((cp = strrchr(buf, '/')) != NULL)
391 1.2 itojun strlcpy(name, cp+1, size);
392 1.1 thorpej }
393 1.1 thorpej
394 1.1 thorpej void
395 1.1 thorpej quip_printqdisc(const char *ifname)
396 1.1 thorpej {
397 1.2 itojun char buf[BODY_MAXSIZE], req[REQ_MAXSIZE], *cp;
398 1.1 thorpej int result_code, len;
399 1.1 thorpej
400 1.1 thorpej if (server == NULL) {
401 1.1 thorpej printf("No server available!\n");
402 1.1 thorpej return;
403 1.1 thorpej }
404 1.1 thorpej
405 1.1 thorpej /* get qdisc info from the server */
406 1.2 itojun snprintf(req, sizeof(req), "GET qdisc?%s\n", ifname);
407 1.1 thorpej quip_sendrequest(server, req);
408 1.1 thorpej
409 1.1 thorpej result_code = quip_recvresponse(server, NULL, buf, &len);
410 1.1 thorpej if (result_code != 200)
411 1.1 thorpej errx(1, "can't get qdisc info");
412 1.1 thorpej
413 1.1 thorpej /* replace newline by space */
414 1.1 thorpej cp = buf;
415 1.1 thorpej while ((cp = strchr(cp, '\n')) != NULL)
416 1.1 thorpej *cp = ' ';
417 1.1 thorpej
418 1.1 thorpej printf(" qdisc:%s\n", buf);
419 1.1 thorpej }
420 1.1 thorpej
421 1.1 thorpej void
422 1.1 thorpej quip_printfilter(const char *ifname, const u_long handle)
423 1.1 thorpej {
424 1.2 itojun char buf[BODY_MAXSIZE], req[REQ_MAXSIZE], *cp;
425 1.1 thorpej int result_code, len;
426 1.1 thorpej
427 1.1 thorpej /* get qdisc info from the server */
428 1.2 itojun snprintf(req, sizeof(req), "GET filter?%s::%#lx\n", ifname, handle);
429 1.1 thorpej quip_sendrequest(server, req);
430 1.1 thorpej
431 1.1 thorpej result_code = quip_recvresponse(server, NULL, buf, &len);
432 1.1 thorpej if (result_code != 200)
433 1.1 thorpej errx(1, "can't get filter info");
434 1.1 thorpej
435 1.1 thorpej if ((cp = strchr(buf, '\n')) != NULL)
436 1.1 thorpej *cp = '\0';
437 1.1 thorpej printf("%s", buf);
438 1.1 thorpej }
439 1.1 thorpej
440 1.1 thorpej static char *
441 1.1 thorpej extract_ifname(const char *name)
442 1.1 thorpej {
443 1.1 thorpej char *cp;
444 1.1 thorpej int len;
445 1.1 thorpej static char ifname[64];
446 1.1 thorpej
447 1.1 thorpej if ((cp = strchr(name, ':')) != NULL)
448 1.1 thorpej len = cp - name;
449 1.1 thorpej else
450 1.1 thorpej len = strlen(name);
451 1.1 thorpej len = MIN(len, 63);
452 1.1 thorpej strncpy(ifname, name, len);
453 1.1 thorpej ifname[len] = '\0';
454 1.1 thorpej return (ifname);
455 1.1 thorpej }
456 1.1 thorpej
457 1.1 thorpej void
458 1.1 thorpej quip_printconfig(void)
459 1.1 thorpej {
460 1.4 itojun char buf[BODY_MAXSIZE], name[256], *cp, *p, *flname;
461 1.1 thorpej int result_code, len;
462 1.1 thorpej enum nametype type;
463 1.1 thorpej u_long handle;
464 1.1 thorpej
465 1.1 thorpej /* get a total list from the server */
466 1.1 thorpej quip_sendrequest(server, "GET list\n");
467 1.1 thorpej
468 1.1 thorpej result_code = quip_recvresponse(server, NULL, buf, &len);
469 1.1 thorpej if (result_code != 200)
470 1.1 thorpej errx(1, "can't get total list");
471 1.1 thorpej
472 1.1 thorpej printf("------------ current configuration ------------");
473 1.1 thorpej
474 1.1 thorpej cp = buf;
475 1.1 thorpej while (1) {
476 1.1 thorpej if (sscanf(cp, "%lx %s", &handle, name) != 2)
477 1.1 thorpej break;
478 1.1 thorpej
479 1.1 thorpej if ((p = strchr(name, ':')) == NULL)
480 1.1 thorpej type = INTERFACE;
481 1.1 thorpej else if (strchr(p+1, ':') == NULL)
482 1.1 thorpej type = CLASS;
483 1.1 thorpej else
484 1.1 thorpej type = FILTER;
485 1.1 thorpej
486 1.1 thorpej switch (type) {
487 1.1 thorpej case INTERFACE:
488 1.1 thorpej printf("\ninterface: %s (index:%lu)\n",
489 1.1 thorpej name, handle);
490 1.1 thorpej quip_printqdisc(name);
491 1.1 thorpej break;
492 1.1 thorpej case CLASS:
493 1.1 thorpej printf("class: %s (handle:%#lx)\n",
494 1.1 thorpej name, handle);
495 1.1 thorpej break;
496 1.1 thorpej case FILTER:
497 1.1 thorpej flname = strrchr(name, ':') + 1;
498 1.1 thorpej printf(" filter: name:%s [", flname);
499 1.1 thorpej quip_printfilter(extract_ifname(name), handle);
500 1.1 thorpej printf("] (handle:%#lx)\n", handle);
501 1.1 thorpej break;
502 1.1 thorpej case CONDITIONER:
503 1.1 thorpej break;
504 1.1 thorpej }
505 1.1 thorpej
506 1.1 thorpej if ((cp = strchr(cp+1, '\n')) == NULL)
507 1.1 thorpej break;
508 1.1 thorpej }
509 1.1 thorpej printf("-----------------------------------------------\n\n");
510 1.1 thorpej }
511 1.1 thorpej
512