Print this page
8485 Remove set but unused variables in usr/src/cmd
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/ipf/tools/ippool.c
+++ new/usr/src/cmd/ipf/tools/ippool.c
1 1 /*
2 2 * Copyright (C) 2003 by Darren Reed.
3 3 *
4 4 * See the IPFILTER.LICENCE file for details on licencing.
5 5 *
6 6 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
7 7 * Use is subject to license terms.
8 8 *
9 9 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
10 + * Copyright 2017 Gary Mills
10 11 */
11 12
12 13 #include <sys/types.h>
13 14 #include <sys/time.h>
14 15 #include <sys/param.h>
15 16 #include <sys/socket.h>
16 17 #if defined(BSD) && (BSD >= 199306)
17 18 # include <sys/cdefs.h>
18 19 #endif
19 20 #include <sys/ioctl.h>
20 21
21 22 #include <net/if.h>
22 23 #if __FreeBSD_version >= 300000
23 24 # include <net/if_var.h>
24 25 #endif
25 26 #include <netinet/in.h>
26 27
27 28 #include <arpa/inet.h>
28 29
29 30 #include <stdio.h>
30 31 #include <fcntl.h>
31 32 #include <stdlib.h>
32 33 #include <string.h>
33 34 #include <netdb.h>
34 35 #include <ctype.h>
35 36 #include <unistd.h>
36 37 #include <nlist.h>
37 38
38 39 #include "ipf.h"
39 40 #include "netinet/ipl.h"
40 41 #include "netinet/ip_lookup.h"
41 42 #include "netinet/ip_pool.h"
42 43 #include "netinet/ip_htable.h"
43 44 #include "kmem.h"
44 45 #include "ipfzone.h"
45 46
46 47 extern int ippool_yyparse __P((void));
47 48 extern int ippool_yydebug;
48 49 extern FILE *ippool_yyin;
49 50 extern char *optarg;
50 51 extern int lineNum;
51 52
52 53 void showpools __P((ip_pool_stat_t *));
53 54 void usage __P((char *));
54 55 int main __P((int, char **));
55 56 int poolcommand __P((int, int, char *[]));
56 57 int poolnodecommand __P((int, int, char *[]));
57 58 int loadpoolfile __P((int, char *[], char *));
58 59 int poollist __P((int, char *[]));
59 60 int poolflush __P((int, char *[]));
60 61 int poolstats __P((int, char *[]));
61 62 int gettype __P((char *, u_int *));
62 63 int getrole __P((char *));
63 64 void poollist_dead __P((int, char *, int, char *, char *));
64 65 void showpools_live(int, int, ip_pool_stat_t *, char *, int);
65 66 void showhashs_live(int, int, iphtstat_t *, char *, int);
66 67
67 68 int opts = 0;
68 69 int fd = -1;
69 70 int use_inet6 = 0;
70 71
71 72
72 73 void usage(prog)
73 74 char *prog;
74 75 {
75 76 const char *zoneopt = "[-G|-z zonename] ";
76 77 fprintf(stderr, "Usage:\t%s\n", prog);
77 78 fprintf(stderr, "\t\t\t-a [-dnv] %s[-m <name>] [-o <role>] -i <ipaddr>[/netmask]\n",
78 79 zoneopt);
79 80 fprintf(stderr, "\t\t\t-A [-dnv] %s[-m <name>] [-o <role>] [-S <seed>] [-t <type>]\n",
80 81 zoneopt);
81 82 fprintf(stderr, "\t\t\t-f <file> %s[-dnuv]\n", zoneopt);
82 83 fprintf(stderr, "\t\t\t-F [-dv] %s[-o <role>] [-t <type>]\n", zoneopt);
83 84 fprintf(stderr, "\t\t\t-l [-dv] %s[-m <name>] [-t <type>]\n", zoneopt);
84 85 fprintf(stderr, "\t\t\t-r [-dnv] %s[-m <name>] [-o <role>] -i <ipaddr>[/netmask]\n",
85 86 zoneopt);
86 87 fprintf(stderr, "\t\t\t-R [-dnv] %s[-m <name>] [-o <role>] [-t <type>]\n",
87 88 zoneopt);
88 89 fprintf(stderr, "\t\t\t-s [-dtv] %s[-M <core>] [-N <namelist>]\n",
89 90 zoneopt);
90 91 exit(1);
91 92 }
92 93
93 94
94 95 int main(argc, argv)
95 96 int argc;
96 97 char *argv[];
97 98 {
98 99 int err;
99 100
100 101 if (argc < 2)
101 102 usage(argv[0]);
102 103
103 104 switch (getopt(argc, argv, "aAf:FlrRs"))
104 105 {
105 106 case 'a' :
106 107 err = poolnodecommand(0, argc, argv);
107 108 break;
108 109 case 'A' :
109 110 err = poolcommand(0, argc, argv);
110 111 break;
111 112 case 'f' :
112 113 err = loadpoolfile(argc, argv, optarg);
113 114 break;
114 115 case 'F' :
115 116 err = poolflush(argc, argv);
116 117 break;
117 118 case 'l' :
118 119 err = poollist(argc, argv);
119 120 break;
120 121 case 'r' :
121 122 err = poolnodecommand(1, argc, argv);
122 123 break;
123 124 case 'R' :
124 125 err = poolcommand(1, argc, argv);
125 126 break;
126 127 case 's' :
127 128 err = poolstats(argc, argv);
128 129 break;
129 130 default :
130 131 exit(1);
131 132 }
132 133
133 134 return err;
134 135 }
135 136
136 137
137 138 int poolnodecommand(remove, argc, argv)
138 139 int remove, argc;
139 140 char *argv[];
140 141 {
141 142 char *poolname = NULL, *s;
142 143 int err, c, ipset, role;
143 144 ip_pool_node_t node;
144 145 struct in_addr mask;
145 146
146 147 ipset = 0;
147 148 role = IPL_LOGIPF;
148 149 bzero((char *)&node, sizeof(node));
149 150
150 151 while ((c = getopt(argc, argv, "di:G:m:no:Rvz:")) != -1)
151 152 switch (c)
152 153 {
153 154 case 'd' :
154 155 opts |= OPT_DEBUG;
155 156 ippool_yydebug++;
156 157 break;
157 158 case 'G' :
158 159 setzonename_global(optarg);
159 160 break;
160 161 case 'i' :
161 162 s = strchr(optarg, '/');
162 163 if (s == NULL)
163 164 mask.s_addr = 0xffffffff;
164 165 else if (strchr(s, '.') == NULL) {
165 166 if (ntomask(4, atoi(s + 1), &mask.s_addr) != 0)
166 167 return -1;
167 168 } else {
168 169 mask.s_addr = inet_addr(s + 1);
169 170 }
170 171 if (s != NULL)
171 172 *s = '\0';
172 173 ipset = 1;
173 174 node.ipn_addr.adf_len = sizeof(node.ipn_addr);
174 175 node.ipn_addr.adf_addr.in4.s_addr = inet_addr(optarg);
175 176 node.ipn_mask.adf_len = sizeof(node.ipn_mask);
176 177 node.ipn_mask.adf_addr.in4.s_addr = mask.s_addr;
177 178 break;
178 179 case 'm' :
179 180 poolname = optarg;
180 181 break;
181 182 case 'n' :
182 183 opts |= OPT_DONOTHING;
183 184 break;
184 185 case 'o' :
185 186 role = getrole(optarg);
186 187 if (role == IPL_LOGNONE)
187 188 return -1;
188 189 break;
189 190 case 'R' :
190 191 opts |= OPT_NORESOLVE;
191 192 break;
192 193 case 'v' :
193 194 opts |= OPT_VERBOSE;
194 195 break;
195 196 case 'z' :
196 197 setzonename(optarg);
197 198 break;
198 199 }
199 200
200 201 if (opts & OPT_DEBUG)
201 202 fprintf(stderr, "poolnodecommand: opts = %#x\n", opts);
202 203
203 204 if (ipset == 0)
204 205 return -1;
205 206 if (poolname == NULL) {
206 207 fprintf(stderr, "poolname not given with add/remove node\n");
207 208 return -1;
208 209 }
209 210
210 211 if (remove == 0)
211 212 err = load_poolnode(0, poolname, &node, ioctl);
212 213 else
213 214 err = remove_poolnode(0, poolname, &node, ioctl);
214 215 return err;
215 216 }
216 217
217 218
218 219 int poolcommand(remove, argc, argv)
219 220 int remove, argc;
220 221 char *argv[];
221 222 {
222 223 int type, role, c, err;
223 224 char *poolname;
224 225 iphtable_t iph;
225 226 ip_pool_t pool;
226 227
227 228 err = 1;
228 229 role = 0;
229 230 type = 0;
230 231 poolname = NULL;
231 232 role = IPL_LOGIPF;
232 233 bzero((char *)&iph, sizeof(iph));
233 234 bzero((char *)&pool, sizeof(pool));
234 235
235 236 while ((c = getopt(argc, argv, "dG:m:no:RS:t:vz:")) != -1)
236 237 switch (c)
237 238 {
238 239 case 'd' :
239 240 opts |= OPT_DEBUG;
240 241 ippool_yydebug++;
241 242 break;
242 243 case 'G' :
243 244 setzonename_global(optarg);
244 245 break;
245 246 case 'm' :
246 247 poolname = optarg;
247 248 break;
248 249 case 'n' :
249 250 opts |= OPT_DONOTHING;
250 251 break;
251 252 case 'o' :
252 253 role = getrole(optarg);
253 254 if (role == IPL_LOGNONE) {
254 255 fprintf(stderr, "unknown role '%s'\n", optarg);
255 256 return -1;
256 257 }
257 258 break;
258 259 case 'R' :
259 260 opts |= OPT_NORESOLVE;
260 261 break;
261 262 case 'S' :
262 263 iph.iph_seed = atoi(optarg);
263 264 break;
264 265 case 't' :
265 266 type = gettype(optarg, &iph.iph_type);
266 267 if (type == IPLT_NONE) {
267 268 fprintf(stderr, "unknown type '%s'\n", optarg);
268 269 return -1;
269 270 }
270 271 break;
271 272 case 'v' :
272 273 opts |= OPT_VERBOSE;
273 274 break;
274 275 case 'z' :
275 276 setzonename(optarg);
276 277 break;
277 278 }
278 279
279 280 if (opts & OPT_DEBUG)
280 281 fprintf(stderr, "poolcommand: opts = %#x\n", opts);
281 282
282 283 if (poolname == NULL) {
283 284 fprintf(stderr, "poolname not given with add/remove pool\n");
284 285 return -1;
285 286 }
286 287
287 288 if (type == IPLT_HASH) {
288 289 strncpy(iph.iph_name, poolname, sizeof(iph.iph_name));
289 290 iph.iph_name[sizeof(iph.iph_name) - 1] = '\0';
290 291 iph.iph_unit = role;
291 292 } else if (type == IPLT_POOL) {
292 293 strncpy(pool.ipo_name, poolname, sizeof(pool.ipo_name));
293 294 pool.ipo_name[sizeof(pool.ipo_name) - 1] = '\0';
294 295 pool.ipo_unit = role;
295 296 }
296 297
297 298 if (remove == 0) {
298 299 switch (type)
299 300 {
300 301 case IPLT_HASH :
301 302 err = load_hash(&iph, NULL, ioctl);
302 303 break;
303 304 case IPLT_POOL :
304 305 err = load_pool(&pool, ioctl);
305 306 break;
306 307 }
307 308 } else {
308 309 switch (type)
309 310 {
310 311 case IPLT_HASH :
311 312 err = remove_hash(&iph, ioctl);
312 313 break;
313 314 case IPLT_POOL :
314 315 err = remove_pool(&pool, ioctl);
315 316 break;
316 317 }
317 318 }
318 319 return err;
319 320 }
320 321
321 322
322 323 int loadpoolfile(argc, argv, infile)
323 324 int argc;
324 325 char *argv[], *infile;
325 326 {
326 327 int c;
327 328
328 329 infile = optarg;
329 330
330 331 while ((c = getopt(argc, argv, "dG:nRuvz:")) != -1)
331 332 switch (c)
332 333 {
333 334 case 'd' :
334 335 opts |= OPT_DEBUG;
335 336 ippool_yydebug++;
336 337 break;
337 338 case 'G' :
338 339 setzonename_global(optarg);
339 340 break;
340 341 case 'n' :
341 342 opts |= OPT_DONOTHING;
342 343 break;
343 344 case 'R' :
344 345 opts |= OPT_NORESOLVE;
345 346 break;
346 347 case 'u' :
347 348 opts |= OPT_REMOVE;
348 349 break;
349 350 case 'v' :
350 351 opts |= OPT_VERBOSE;
351 352 break;
352 353 case 'z' :
353 354 setzonename(optarg);
354 355 break;
355 356 }
356 357
357 358 if (opts & OPT_DEBUG)
358 359 fprintf(stderr, "loadpoolfile: opts = %#x\n", opts);
359 360
360 361 if (!(opts & OPT_DONOTHING) && (fd == -1)) {
361 362 fd = open(IPLOOKUP_NAME, O_RDWR);
362 363 if (fd == -1) {
363 364 perror("open(IPLOOKUP_NAME)");
364 365 exit(1);
365 366 }
366 367
367 368 if (setzone(fd) != 0) {
368 369 close(fd);
369 370 exit(1);
370 371 }
371 372 }
372 373
373 374 if (ippool_parsefile(fd, infile, ioctl) != 0)
374 375 return -1;
↓ open down ↓ |
355 lines elided |
↑ open up ↑ |
375 376 return 0;
376 377 }
377 378
378 379
379 380 int poollist(argc, argv)
380 381 int argc;
381 382 char *argv[];
382 383 {
383 384 char *kernel, *core, *poolname;
384 385 int c, role, type, live_kernel;
385 - ip_pool_stat_t *plstp, plstat;
386 - iphtstat_t *htstp, htstat;
386 + ip_pool_stat_t plstat;
387 + iphtstat_t htstat;
387 388 iphtable_t *hptr;
388 389 iplookupop_t op;
389 390 ip_pool_t *ptr;
390 391
391 392 core = NULL;
392 393 kernel = NULL;
393 394 live_kernel = 1;
394 395 type = IPLT_ALL;
395 396 poolname = NULL;
396 397 role = IPL_LOGALL;
397 398
398 399 while ((c = getopt(argc, argv, "dG:m:M:N:o:Rt:vz:")) != -1)
399 400 switch (c)
400 401 {
401 402 case 'd' :
402 403 opts |= OPT_DEBUG;
403 404 break;
404 405 case 'G' :
405 406 setzonename_global(optarg);
406 407 break;
407 408 case 'm' :
408 409 poolname = optarg;
409 410 break;
410 411 case 'M' :
411 412 live_kernel = 0;
412 413 core = optarg;
413 414 break;
414 415 case 'N' :
415 416 live_kernel = 0;
416 417 kernel = optarg;
417 418 break;
418 419 case 'o' :
419 420 role = getrole(optarg);
420 421 if (role == IPL_LOGNONE) {
421 422 fprintf(stderr, "unknown role '%s'\n", optarg);
422 423 return -1;
423 424 }
424 425 break;
425 426 case 'R' :
426 427 opts |= OPT_NORESOLVE;
427 428 break;
428 429 case 't' :
429 430 type = gettype(optarg, NULL);
430 431 if (type == IPLT_NONE) {
431 432 fprintf(stderr, "unknown type '%s'\n", optarg);
432 433 return -1;
433 434 }
434 435 break;
435 436 case 'v' :
436 437 opts |= OPT_VERBOSE;
437 438 break;
438 439 case 'z' :
439 440 setzonename(optarg);
440 441 break;
441 442 }
442 443
443 444 if (opts & OPT_DEBUG)
444 445 fprintf(stderr, "poollist: opts = %#x\n", opts);
445 446
446 447 if (!(opts & OPT_DONOTHING) && (fd == -1)) {
447 448 fd = open(IPLOOKUP_NAME, O_RDWR);
448 449 if (fd == -1) {
449 450 perror("open(IPLOOKUP_NAME)");
450 451 exit(1);
451 452 }
452 453
453 454 if (setzone(fd) != 0) {
454 455 close(fd);
455 456 exit(1);
456 457 }
457 458 }
458 459
459 460 bzero((char *)&op, sizeof(op));
460 461 if (poolname != NULL) {
461 462 strncpy(op.iplo_name, poolname, sizeof(op.iplo_name));
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
462 463 op.iplo_name[sizeof(op.iplo_name) - 1] = '\0';
463 464 }
464 465 op.iplo_unit = role;
465 466
466 467 if (live_kernel == 0) {
467 468 poollist_dead(role, poolname, type, kernel, core);
468 469 return (0);
469 470 }
470 471
471 472 if (type == IPLT_ALL || type == IPLT_POOL) {
472 - plstp = &plstat;
473 473 op.iplo_type = IPLT_POOL;
474 474 op.iplo_size = sizeof(plstat);
475 475 op.iplo_struct = &plstat;
476 476 op.iplo_name[0] = '\0';
477 477 op.iplo_arg = 0;
478 478
479 479 if (role != IPL_LOGALL) {
480 480 op.iplo_unit = role;
481 481
482 482 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
483 483 if (c == -1) {
484 484 perror("ioctl(SIOCLOOKUPSTAT)");
485 485 return -1;
486 486 }
487 487
488 488 showpools_live(fd, role, &plstat, poolname, opts);
489 489 } else {
490 490 for (role = 0; role <= IPL_LOGMAX; role++) {
491 491 op.iplo_unit = role;
492 492
493 493 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
494 494 if (c == -1) {
495 495 perror("ioctl(SIOCLOOKUPSTAT)");
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
496 496 return -1;
497 497 }
498 498
499 499 showpools_live(fd, role, &plstat, poolname, opts);
500 500 }
501 501
502 502 role = IPL_LOGALL;
503 503 }
504 504 }
505 505 if (type == IPLT_ALL || type == IPLT_HASH) {
506 - htstp = &htstat;
507 506 op.iplo_type = IPLT_HASH;
508 507 op.iplo_size = sizeof(htstat);
509 508 op.iplo_struct = &htstat;
510 509 op.iplo_name[0] = '\0';
511 510 op.iplo_arg = 0;
512 511
513 512 if (role != IPL_LOGALL) {
514 513 op.iplo_unit = role;
515 514
516 515 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
517 516 if (c == -1) {
518 517 perror("ioctl(SIOCLOOKUPSTAT)");
519 518 return -1;
520 519 }
521 520 showhashs_live(fd, role, &htstat, poolname, opts);
522 521 } else {
523 522 for (role = 0; role <= IPL_LOGMAX; role++) {
524 523
525 524 op.iplo_unit = role;
526 525 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
527 526 if (c == -1) {
528 527 perror("ioctl(SIOCLOOKUPSTAT)");
529 528 return -1;
530 529 }
531 530
532 531 showhashs_live(fd, role, &htstat, poolname, opts);
533 532 }
534 533 }
535 534 }
536 535 return 0;
537 536 }
538 537
539 538 void poollist_dead(role, poolname, type, kernel, core)
540 539 int role, type;
541 540 char *poolname, *kernel, *core;
542 541 {
543 542 iphtable_t *hptr;
544 543 ip_pool_t *ptr;
545 544
546 545 if (openkmem(kernel, core) == -1)
547 546 exit(-1);
548 547
549 548 if (type == IPLT_ALL || type == IPLT_POOL) {
550 549 ip_pool_t *pools[IPL_LOGSIZE];
551 550 struct nlist names[2] = { { "ip_pool_list" } , { "" } };
552 551
553 552 if (nlist(kernel, names) != 1)
554 553 return;
555 554
556 555 bzero(&pools, sizeof(pools));
557 556 if (kmemcpy((char *)&pools, names[0].n_value, sizeof(pools)))
558 557 return;
559 558
560 559 if (role != IPL_LOGALL) {
561 560 ptr = pools[role];
562 561 while (ptr != NULL) {
563 562 ptr = printpool(ptr, kmemcpywrap,
564 563 poolname, opts);
565 564 }
566 565 } else {
567 566 for (role = 0; role <= IPL_LOGMAX; role++) {
568 567 ptr = pools[role];
569 568 while (ptr != NULL) {
570 569 ptr = printpool(ptr, kmemcpywrap,
571 570 poolname, opts);
572 571 }
573 572 }
574 573 role = IPL_LOGALL;
575 574 }
576 575 }
577 576 if (type == IPLT_ALL || type == IPLT_HASH) {
578 577 iphtable_t *tables[IPL_LOGSIZE];
579 578 struct nlist names[2] = { { "ipf_htables" } , { "" } };
580 579
581 580 if (nlist(kernel, names) != 1)
582 581 return;
583 582
584 583 bzero(&tables, sizeof(tables));
585 584 if (kmemcpy((char *)&tables, names[0].n_value, sizeof(tables)))
586 585 return;
587 586
588 587 if (role != IPL_LOGALL) {
589 588 hptr = tables[role];
590 589 while (hptr != NULL) {
591 590 hptr = printhash(hptr, kmemcpywrap,
592 591 poolname, opts);
593 592 }
594 593 } else {
595 594 for (role = 0; role <= IPL_LOGMAX; role++) {
596 595 hptr = tables[role];
597 596 while (hptr != NULL) {
598 597 hptr = printhash(hptr, kmemcpywrap,
599 598 poolname, opts);
600 599 }
601 600 }
602 601 }
603 602 }
604 603 }
605 604
606 605
607 606 void
608 607 showpools_live(fd, role, plstp, poolname, opts)
609 608 int fd, role;
610 609 ip_pool_stat_t *plstp;
611 610 char *poolname;
612 611 int opts;
613 612 {
614 613 ipflookupiter_t iter;
615 614 ip_pool_t pool;
616 615 ipfobj_t obj;
617 616
618 617 obj.ipfo_rev = IPFILTER_VERSION;
619 618 obj.ipfo_type = IPFOBJ_LOOKUPITER;
620 619 obj.ipfo_size = sizeof(iter);
621 620 obj.ipfo_ptr = &iter;
622 621
623 622 iter.ili_type = IPLT_POOL;
624 623 iter.ili_otype = IPFLOOKUPITER_LIST;
625 624 iter.ili_ival = IPFGENITER_LOOKUP;
626 625 iter.ili_data = &pool;
627 626 iter.ili_unit = role;
628 627 *iter.ili_name = '\0';
629 628
630 629 while (plstp->ipls_list[role] != NULL) {
631 630 if (ioctl(fd, SIOCLOOKUPITER, &obj)) {
632 631 perror("ioctl(SIOCLOOKUPITER)");
633 632 break;
634 633 }
↓ open down ↓ |
118 lines elided |
↑ open up ↑ |
635 634 (void) printpool_live(&pool, fd, poolname, opts);
636 635
637 636 plstp->ipls_list[role] = pool.ipo_next;
638 637 }
639 638 }
640 639
641 640 int poolstats(argc, argv)
642 641 int argc;
643 642 char *argv[];
644 643 {
645 - int c, type, role, live_kernel;
644 + int c, type, role;
646 645 ip_pool_stat_t plstat;
647 - char *kernel, *core;
648 646 iphtstat_t htstat;
649 647 iplookupop_t op;
650 648
651 - core = NULL;
652 - kernel = NULL;
653 - live_kernel = 1;
654 649 type = IPLT_ALL;
655 650 role = IPL_LOGALL;
656 651
657 652 bzero((char *)&op, sizeof(op));
658 653
659 654 while ((c = getopt(argc, argv, "dG:M:N:o:t:vz:")) != -1)
660 655 switch (c)
661 656 {
662 657 case 'd' :
663 658 opts |= OPT_DEBUG;
664 659 break;
665 660 case 'G' :
666 661 setzonename_global(optarg);
667 662 break;
668 663 case 'M' :
669 - live_kernel = 0;
670 - core = optarg;
671 664 break;
672 665 case 'N' :
673 - live_kernel = 0;
674 - kernel = optarg;
675 666 break;
676 667 case 'o' :
677 668 role = getrole(optarg);
678 669 if (role == IPL_LOGNONE) {
679 670 fprintf(stderr, "unknown role '%s'\n", optarg);
680 671 return -1;
681 672 }
682 673 break;
683 674 case 't' :
684 675 type = gettype(optarg, NULL);
685 676 if (type != IPLT_POOL) {
686 677 fprintf(stderr,
687 678 "-s not supported for this type yet\n");
688 679 return -1;
689 680 }
690 681 break;
691 682 case 'v' :
692 683 opts |= OPT_VERBOSE;
693 684 break;
694 685 case 'z' :
695 686 setzonename(optarg);
696 687 break;
697 688 }
698 689
699 690 if (opts & OPT_DEBUG)
700 691 fprintf(stderr, "poolstats: opts = %#x\n", opts);
701 692
702 693 if (!(opts & OPT_DONOTHING) && (fd == -1)) {
703 694 fd = open(IPLOOKUP_NAME, O_RDWR);
704 695 if (fd == -1) {
705 696 perror("open(IPLOOKUP_NAME)");
706 697 exit(1);
707 698 }
708 699
709 700 if (setzone(fd) != 0) {
710 701 close(fd);
711 702 exit(1);
712 703 }
713 704 }
714 705
715 706 if (type == IPLT_ALL || type == IPLT_POOL) {
716 707 op.iplo_type = IPLT_POOL;
717 708 op.iplo_struct = &plstat;
718 709 op.iplo_size = sizeof(plstat);
719 710 if (!(opts & OPT_DONOTHING)) {
720 711 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
721 712 if (c == -1) {
722 713 perror("ioctl(SIOCLOOKUPSTAT)");
723 714 return -1;
724 715 }
725 716 printf("Pools:\t%lu\n", plstat.ipls_pools);
726 717 printf("Nodes:\t%lu\n", plstat.ipls_nodes);
727 718 }
728 719 }
729 720
730 721 if (type == IPLT_ALL || type == IPLT_HASH) {
731 722 op.iplo_type = IPLT_HASH;
732 723 op.iplo_struct = &htstat;
733 724 op.iplo_size = sizeof(htstat);
734 725 if (!(opts & OPT_DONOTHING)) {
735 726 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
736 727 if (c == -1) {
737 728 perror("ioctl(SIOCLOOKUPSTAT)");
738 729 return -1;
739 730 }
740 731 printf("Hash Tables:\t%lu\n", htstat.iphs_numtables);
741 732 printf("Nodes:\t%lu\n", htstat.iphs_numnodes);
742 733 printf("Out of Memory:\t%lu\n", htstat.iphs_nomem);
743 734 }
744 735 }
745 736 return 0;
746 737 }
747 738
748 739
749 740 int poolflush(argc, argv)
750 741 int argc;
751 742 char *argv[];
752 743 {
753 744 int c, role, type, arg;
754 745 iplookupflush_t flush;
755 746
756 747 arg = IPLT_ALL;
757 748 type = IPLT_ALL;
758 749 role = IPL_LOGALL;
759 750
760 751 while ((c = getopt(argc, argv, "do:t:vz:")) != -1)
761 752 switch (c)
762 753 {
763 754 case 'd' :
764 755 opts |= OPT_DEBUG;
765 756 break;
766 757 case 'o' :
767 758 role = getrole(optarg);
768 759 if (role == IPL_LOGNONE) {
769 760 fprintf(stderr, "unknown role '%s'\n", optarg);
770 761 return -1;
771 762 }
772 763 break;
773 764 case 't' :
774 765 type = gettype(optarg, NULL);
775 766 if (type == IPLT_NONE) {
776 767 fprintf(stderr, "unknown type '%s'\n", optarg);
777 768 return -1;
778 769 }
779 770 break;
780 771 case 'v' :
781 772 opts |= OPT_VERBOSE;
782 773 break;
783 774 case 'z' :
784 775 setzonename(optarg);
785 776 break;
786 777 }
787 778
788 779 if (opts & OPT_DEBUG)
789 780 fprintf(stderr, "poolflush: opts = %#x\n", opts);
790 781
791 782 if (!(opts & OPT_DONOTHING) && (fd == -1)) {
792 783 fd = open(IPLOOKUP_NAME, O_RDWR);
793 784 if (fd == -1) {
794 785 perror("open(IPLOOKUP_NAME)");
795 786 exit(1);
796 787 }
797 788
798 789 if (setzone(fd) != 0) {
799 790 close(fd);
800 791 exit(1);
801 792 }
802 793 }
803 794
804 795 bzero((char *)&flush, sizeof(flush));
805 796 flush.iplf_type = type;
806 797 flush.iplf_unit = role;
807 798 flush.iplf_arg = arg;
808 799
809 800 if (!(opts & OPT_DONOTHING)) {
810 801 if (ioctl(fd, SIOCLOOKUPFLUSH, &flush) == -1) {
811 802 perror("ioctl(SIOCLOOKUPFLUSH)");
812 803 exit(1);
813 804 }
814 805
815 806 }
816 807 printf("%u object%s flushed\n", flush.iplf_count,
817 808 (flush.iplf_count == 1) ? "" : "s");
818 809
819 810 return 0;
820 811 }
821 812
822 813
823 814 int getrole(rolename)
824 815 char *rolename;
825 816 {
826 817 int role;
827 818
828 819 if (!strcasecmp(rolename, "ipf")) {
829 820 role = IPL_LOGIPF;
830 821 #if 0
831 822 } else if (!strcasecmp(rolename, "nat")) {
832 823 role = IPL_LOGNAT;
833 824 } else if (!strcasecmp(rolename, "state")) {
834 825 role = IPL_LOGSTATE;
835 826 } else if (!strcasecmp(rolename, "auth")) {
836 827 role = IPL_LOGAUTH;
837 828 } else if (!strcasecmp(rolename, "sync")) {
838 829 role = IPL_LOGSYNC;
839 830 } else if (!strcasecmp(rolename, "scan")) {
840 831 role = IPL_LOGSCAN;
841 832 } else if (!strcasecmp(rolename, "pool")) {
842 833 role = IPL_LOGLOOKUP;
843 834 } else if (!strcasecmp(rolename, "count")) {
844 835 role = IPL_LOGCOUNT;
845 836 #endif
846 837 } else {
847 838 role = IPL_LOGNONE;
848 839 }
849 840
850 841 return role;
851 842 }
852 843
853 844
854 845 int gettype(typename, minor)
855 846 char *typename;
856 847 u_int *minor;
857 848 {
858 849 int type;
859 850
860 851 if (!strcasecmp(optarg, "tree")) {
861 852 type = IPLT_POOL;
862 853 } else if (!strcasecmp(optarg, "hash")) {
863 854 type = IPLT_HASH;
864 855 if (minor != NULL)
865 856 *minor = IPHASH_LOOKUP;
866 857 } else if (!strcasecmp(optarg, "group-map")) {
867 858 type = IPLT_HASH;
868 859 if (minor != NULL)
869 860 *minor = IPHASH_GROUPMAP;
870 861 } else {
871 862 type = IPLT_NONE;
872 863 }
873 864 return type;
874 865 }
875 866
876 867 void showhashs_live(fd, role, htstp, poolname, opts)
877 868 int fd, role;
878 869 iphtstat_t *htstp;
879 870 char *poolname;
880 871 int opts;
881 872 {
882 873 ipflookupiter_t iter;
883 874 iphtable_t table;
884 875 ipfobj_t obj;
885 876
886 877 obj.ipfo_rev = IPFILTER_VERSION;
887 878 obj.ipfo_type = IPFOBJ_LOOKUPITER;
888 879 obj.ipfo_size = sizeof(iter);
889 880 obj.ipfo_ptr = &iter;
890 881
891 882 iter.ili_type = IPLT_HASH;
892 883 iter.ili_otype = IPFLOOKUPITER_LIST;
893 884 iter.ili_ival = IPFGENITER_LOOKUP;
894 885 iter.ili_data = &table;
895 886 iter.ili_unit = role;
896 887 *iter.ili_name = '\0';
897 888
898 889 while (htstp->iphs_tables != NULL) {
899 890 if (ioctl(fd, SIOCLOOKUPITER, &obj)) {
900 891 perror("ioctl(SIOCLOOKUPITER)");
901 892 break;
902 893 }
903 894
904 895 printhash_live(&table, fd, poolname, opts);
905 896
906 897 htstp->iphs_tables = table.iph_next;
907 898 }
908 899 }
↓ open down ↓ |
224 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX