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 *plstp;
387 + ip_pool_stat_t plstat;
388 + iphtstat_t htstat;
387 389 iphtable_t *hptr;
388 390 iplookupop_t op;
389 391 ip_pool_t *ptr;
390 392
391 393 core = NULL;
392 394 kernel = NULL;
393 395 live_kernel = 1;
394 396 type = IPLT_ALL;
395 397 poolname = NULL;
396 398 role = IPL_LOGALL;
397 399
398 400 while ((c = getopt(argc, argv, "dG:m:M:N:o:Rt:vz:")) != -1)
399 401 switch (c)
400 402 {
401 403 case 'd' :
402 404 opts |= OPT_DEBUG;
403 405 break;
404 406 case 'G' :
405 407 setzonename_global(optarg);
406 408 break;
407 409 case 'm' :
408 410 poolname = optarg;
409 411 break;
410 412 case 'M' :
411 413 live_kernel = 0;
412 414 core = optarg;
413 415 break;
414 416 case 'N' :
415 417 live_kernel = 0;
416 418 kernel = optarg;
417 419 break;
418 420 case 'o' :
419 421 role = getrole(optarg);
420 422 if (role == IPL_LOGNONE) {
421 423 fprintf(stderr, "unknown role '%s'\n", optarg);
422 424 return -1;
423 425 }
424 426 break;
425 427 case 'R' :
426 428 opts |= OPT_NORESOLVE;
427 429 break;
428 430 case 't' :
429 431 type = gettype(optarg, NULL);
430 432 if (type == IPLT_NONE) {
431 433 fprintf(stderr, "unknown type '%s'\n", optarg);
432 434 return -1;
433 435 }
434 436 break;
435 437 case 'v' :
436 438 opts |= OPT_VERBOSE;
437 439 break;
438 440 case 'z' :
439 441 setzonename(optarg);
440 442 break;
441 443 }
442 444
443 445 if (opts & OPT_DEBUG)
444 446 fprintf(stderr, "poollist: opts = %#x\n", opts);
445 447
446 448 if (!(opts & OPT_DONOTHING) && (fd == -1)) {
447 449 fd = open(IPLOOKUP_NAME, O_RDWR);
448 450 if (fd == -1) {
449 451 perror("open(IPLOOKUP_NAME)");
450 452 exit(1);
451 453 }
452 454
453 455 if (setzone(fd) != 0) {
454 456 close(fd);
455 457 exit(1);
456 458 }
457 459 }
458 460
459 461 bzero((char *)&op, sizeof(op));
460 462 if (poolname != NULL) {
461 463 strncpy(op.iplo_name, poolname, sizeof(op.iplo_name));
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
462 464 op.iplo_name[sizeof(op.iplo_name) - 1] = '\0';
463 465 }
464 466 op.iplo_unit = role;
465 467
466 468 if (live_kernel == 0) {
467 469 poollist_dead(role, poolname, type, kernel, core);
468 470 return (0);
469 471 }
470 472
471 473 if (type == IPLT_ALL || type == IPLT_POOL) {
472 - plstp = &plstat;
473 474 op.iplo_type = IPLT_POOL;
474 475 op.iplo_size = sizeof(plstat);
475 476 op.iplo_struct = &plstat;
476 477 op.iplo_name[0] = '\0';
477 478 op.iplo_arg = 0;
478 479
479 480 if (role != IPL_LOGALL) {
480 481 op.iplo_unit = role;
481 482
482 483 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
483 484 if (c == -1) {
484 485 perror("ioctl(SIOCLOOKUPSTAT)");
485 486 return -1;
486 487 }
487 488
488 489 showpools_live(fd, role, &plstat, poolname, opts);
489 490 } else {
490 491 for (role = 0; role <= IPL_LOGMAX; role++) {
491 492 op.iplo_unit = role;
492 493
493 494 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
494 495 if (c == -1) {
495 496 perror("ioctl(SIOCLOOKUPSTAT)");
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
496 497 return -1;
497 498 }
498 499
499 500 showpools_live(fd, role, &plstat, poolname, opts);
500 501 }
501 502
502 503 role = IPL_LOGALL;
503 504 }
504 505 }
505 506 if (type == IPLT_ALL || type == IPLT_HASH) {
506 - htstp = &htstat;
507 507 op.iplo_type = IPLT_HASH;
508 508 op.iplo_size = sizeof(htstat);
509 509 op.iplo_struct = &htstat;
510 510 op.iplo_name[0] = '\0';
511 511 op.iplo_arg = 0;
512 512
513 513 if (role != IPL_LOGALL) {
514 514 op.iplo_unit = role;
515 515
516 516 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
517 517 if (c == -1) {
518 518 perror("ioctl(SIOCLOOKUPSTAT)");
519 519 return -1;
520 520 }
521 521 showhashs_live(fd, role, &htstat, poolname, opts);
522 522 } else {
523 523 for (role = 0; role <= IPL_LOGMAX; role++) {
524 524
525 525 op.iplo_unit = role;
526 526 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
527 527 if (c == -1) {
528 528 perror("ioctl(SIOCLOOKUPSTAT)");
529 529 return -1;
530 530 }
531 531
532 532 showhashs_live(fd, role, &htstat, poolname, opts);
533 533 }
534 534 }
535 535 }
536 536 return 0;
537 537 }
538 538
539 539 void poollist_dead(role, poolname, type, kernel, core)
540 540 int role, type;
541 541 char *poolname, *kernel, *core;
542 542 {
543 543 iphtable_t *hptr;
544 544 ip_pool_t *ptr;
545 545
546 546 if (openkmem(kernel, core) == -1)
547 547 exit(-1);
548 548
549 549 if (type == IPLT_ALL || type == IPLT_POOL) {
550 550 ip_pool_t *pools[IPL_LOGSIZE];
551 551 struct nlist names[2] = { { "ip_pool_list" } , { "" } };
552 552
553 553 if (nlist(kernel, names) != 1)
554 554 return;
555 555
556 556 bzero(&pools, sizeof(pools));
557 557 if (kmemcpy((char *)&pools, names[0].n_value, sizeof(pools)))
558 558 return;
559 559
560 560 if (role != IPL_LOGALL) {
561 561 ptr = pools[role];
562 562 while (ptr != NULL) {
563 563 ptr = printpool(ptr, kmemcpywrap,
564 564 poolname, opts);
565 565 }
566 566 } else {
567 567 for (role = 0; role <= IPL_LOGMAX; role++) {
568 568 ptr = pools[role];
569 569 while (ptr != NULL) {
570 570 ptr = printpool(ptr, kmemcpywrap,
571 571 poolname, opts);
572 572 }
573 573 }
574 574 role = IPL_LOGALL;
575 575 }
576 576 }
577 577 if (type == IPLT_ALL || type == IPLT_HASH) {
578 578 iphtable_t *tables[IPL_LOGSIZE];
579 579 struct nlist names[2] = { { "ipf_htables" } , { "" } };
580 580
581 581 if (nlist(kernel, names) != 1)
582 582 return;
583 583
584 584 bzero(&tables, sizeof(tables));
585 585 if (kmemcpy((char *)&tables, names[0].n_value, sizeof(tables)))
586 586 return;
587 587
588 588 if (role != IPL_LOGALL) {
589 589 hptr = tables[role];
590 590 while (hptr != NULL) {
591 591 hptr = printhash(hptr, kmemcpywrap,
592 592 poolname, opts);
593 593 }
594 594 } else {
595 595 for (role = 0; role <= IPL_LOGMAX; role++) {
596 596 hptr = tables[role];
597 597 while (hptr != NULL) {
598 598 hptr = printhash(hptr, kmemcpywrap,
599 599 poolname, opts);
600 600 }
601 601 }
602 602 }
603 603 }
604 604 }
605 605
606 606
607 607 void
608 608 showpools_live(fd, role, plstp, poolname, opts)
609 609 int fd, role;
610 610 ip_pool_stat_t *plstp;
611 611 char *poolname;
612 612 int opts;
613 613 {
614 614 ipflookupiter_t iter;
615 615 ip_pool_t pool;
616 616 ipfobj_t obj;
617 617
618 618 obj.ipfo_rev = IPFILTER_VERSION;
619 619 obj.ipfo_type = IPFOBJ_LOOKUPITER;
620 620 obj.ipfo_size = sizeof(iter);
621 621 obj.ipfo_ptr = &iter;
622 622
623 623 iter.ili_type = IPLT_POOL;
624 624 iter.ili_otype = IPFLOOKUPITER_LIST;
625 625 iter.ili_ival = IPFGENITER_LOOKUP;
626 626 iter.ili_data = &pool;
627 627 iter.ili_unit = role;
628 628 *iter.ili_name = '\0';
629 629
630 630 while (plstp->ipls_list[role] != NULL) {
631 631 if (ioctl(fd, SIOCLOOKUPITER, &obj)) {
632 632 perror("ioctl(SIOCLOOKUPITER)");
633 633 break;
634 634 }
↓ open down ↓ |
118 lines elided |
↑ open up ↑ |
635 635 (void) printpool_live(&pool, fd, poolname, opts);
636 636
637 637 plstp->ipls_list[role] = pool.ipo_next;
638 638 }
639 639 }
640 640
641 641 int poolstats(argc, argv)
642 642 int argc;
643 643 char *argv[];
644 644 {
645 - int c, type, role, live_kernel;
645 + int c, type, role;
646 646 ip_pool_stat_t plstat;
647 - char *kernel, *core;
648 647 iphtstat_t htstat;
649 648 iplookupop_t op;
650 649
651 - core = NULL;
652 - kernel = NULL;
653 - live_kernel = 1;
654 650 type = IPLT_ALL;
655 651 role = IPL_LOGALL;
656 652
657 653 bzero((char *)&op, sizeof(op));
658 654
659 655 while ((c = getopt(argc, argv, "dG:M:N:o:t:vz:")) != -1)
660 656 switch (c)
661 657 {
662 658 case 'd' :
663 659 opts |= OPT_DEBUG;
664 660 break;
665 661 case 'G' :
666 662 setzonename_global(optarg);
667 663 break;
668 664 case 'M' :
669 - live_kernel = 0;
670 - core = optarg;
671 665 break;
672 666 case 'N' :
673 - live_kernel = 0;
674 - kernel = optarg;
675 667 break;
676 668 case 'o' :
677 669 role = getrole(optarg);
678 670 if (role == IPL_LOGNONE) {
679 671 fprintf(stderr, "unknown role '%s'\n", optarg);
680 672 return -1;
681 673 }
682 674 break;
683 675 case 't' :
684 676 type = gettype(optarg, NULL);
685 677 if (type != IPLT_POOL) {
686 678 fprintf(stderr,
687 679 "-s not supported for this type yet\n");
688 680 return -1;
689 681 }
690 682 break;
691 683 case 'v' :
692 684 opts |= OPT_VERBOSE;
693 685 break;
694 686 case 'z' :
695 687 setzonename(optarg);
696 688 break;
697 689 }
698 690
699 691 if (opts & OPT_DEBUG)
700 692 fprintf(stderr, "poolstats: opts = %#x\n", opts);
701 693
702 694 if (!(opts & OPT_DONOTHING) && (fd == -1)) {
703 695 fd = open(IPLOOKUP_NAME, O_RDWR);
704 696 if (fd == -1) {
705 697 perror("open(IPLOOKUP_NAME)");
706 698 exit(1);
707 699 }
708 700
709 701 if (setzone(fd) != 0) {
710 702 close(fd);
711 703 exit(1);
712 704 }
713 705 }
714 706
715 707 if (type == IPLT_ALL || type == IPLT_POOL) {
716 708 op.iplo_type = IPLT_POOL;
717 709 op.iplo_struct = &plstat;
718 710 op.iplo_size = sizeof(plstat);
719 711 if (!(opts & OPT_DONOTHING)) {
720 712 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
721 713 if (c == -1) {
722 714 perror("ioctl(SIOCLOOKUPSTAT)");
723 715 return -1;
724 716 }
725 717 printf("Pools:\t%lu\n", plstat.ipls_pools);
726 718 printf("Nodes:\t%lu\n", plstat.ipls_nodes);
727 719 }
728 720 }
729 721
730 722 if (type == IPLT_ALL || type == IPLT_HASH) {
731 723 op.iplo_type = IPLT_HASH;
732 724 op.iplo_struct = &htstat;
733 725 op.iplo_size = sizeof(htstat);
734 726 if (!(opts & OPT_DONOTHING)) {
735 727 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
736 728 if (c == -1) {
737 729 perror("ioctl(SIOCLOOKUPSTAT)");
738 730 return -1;
739 731 }
740 732 printf("Hash Tables:\t%lu\n", htstat.iphs_numtables);
741 733 printf("Nodes:\t%lu\n", htstat.iphs_numnodes);
742 734 printf("Out of Memory:\t%lu\n", htstat.iphs_nomem);
743 735 }
744 736 }
745 737 return 0;
746 738 }
747 739
748 740
749 741 int poolflush(argc, argv)
750 742 int argc;
751 743 char *argv[];
752 744 {
753 745 int c, role, type, arg;
754 746 iplookupflush_t flush;
755 747
756 748 arg = IPLT_ALL;
757 749 type = IPLT_ALL;
758 750 role = IPL_LOGALL;
759 751
760 752 while ((c = getopt(argc, argv, "do:t:vz:")) != -1)
761 753 switch (c)
762 754 {
763 755 case 'd' :
764 756 opts |= OPT_DEBUG;
765 757 break;
766 758 case 'o' :
767 759 role = getrole(optarg);
768 760 if (role == IPL_LOGNONE) {
769 761 fprintf(stderr, "unknown role '%s'\n", optarg);
770 762 return -1;
771 763 }
772 764 break;
773 765 case 't' :
774 766 type = gettype(optarg, NULL);
775 767 if (type == IPLT_NONE) {
776 768 fprintf(stderr, "unknown type '%s'\n", optarg);
777 769 return -1;
778 770 }
779 771 break;
780 772 case 'v' :
781 773 opts |= OPT_VERBOSE;
782 774 break;
783 775 case 'z' :
784 776 setzonename(optarg);
785 777 break;
786 778 }
787 779
788 780 if (opts & OPT_DEBUG)
789 781 fprintf(stderr, "poolflush: opts = %#x\n", opts);
790 782
791 783 if (!(opts & OPT_DONOTHING) && (fd == -1)) {
792 784 fd = open(IPLOOKUP_NAME, O_RDWR);
793 785 if (fd == -1) {
794 786 perror("open(IPLOOKUP_NAME)");
795 787 exit(1);
796 788 }
797 789
798 790 if (setzone(fd) != 0) {
799 791 close(fd);
800 792 exit(1);
801 793 }
802 794 }
803 795
804 796 bzero((char *)&flush, sizeof(flush));
805 797 flush.iplf_type = type;
806 798 flush.iplf_unit = role;
807 799 flush.iplf_arg = arg;
808 800
809 801 if (!(opts & OPT_DONOTHING)) {
810 802 if (ioctl(fd, SIOCLOOKUPFLUSH, &flush) == -1) {
811 803 perror("ioctl(SIOCLOOKUPFLUSH)");
812 804 exit(1);
813 805 }
814 806
815 807 }
816 808 printf("%u object%s flushed\n", flush.iplf_count,
817 809 (flush.iplf_count == 1) ? "" : "s");
818 810
819 811 return 0;
820 812 }
821 813
822 814
823 815 int getrole(rolename)
824 816 char *rolename;
825 817 {
826 818 int role;
827 819
828 820 if (!strcasecmp(rolename, "ipf")) {
829 821 role = IPL_LOGIPF;
830 822 #if 0
831 823 } else if (!strcasecmp(rolename, "nat")) {
832 824 role = IPL_LOGNAT;
833 825 } else if (!strcasecmp(rolename, "state")) {
834 826 role = IPL_LOGSTATE;
835 827 } else if (!strcasecmp(rolename, "auth")) {
836 828 role = IPL_LOGAUTH;
837 829 } else if (!strcasecmp(rolename, "sync")) {
838 830 role = IPL_LOGSYNC;
839 831 } else if (!strcasecmp(rolename, "scan")) {
840 832 role = IPL_LOGSCAN;
841 833 } else if (!strcasecmp(rolename, "pool")) {
842 834 role = IPL_LOGLOOKUP;
843 835 } else if (!strcasecmp(rolename, "count")) {
844 836 role = IPL_LOGCOUNT;
845 837 #endif
846 838 } else {
847 839 role = IPL_LOGNONE;
848 840 }
849 841
850 842 return role;
851 843 }
852 844
853 845
854 846 int gettype(typename, minor)
855 847 char *typename;
856 848 u_int *minor;
857 849 {
858 850 int type;
859 851
860 852 if (!strcasecmp(optarg, "tree")) {
861 853 type = IPLT_POOL;
862 854 } else if (!strcasecmp(optarg, "hash")) {
863 855 type = IPLT_HASH;
864 856 if (minor != NULL)
865 857 *minor = IPHASH_LOOKUP;
866 858 } else if (!strcasecmp(optarg, "group-map")) {
867 859 type = IPLT_HASH;
868 860 if (minor != NULL)
869 861 *minor = IPHASH_GROUPMAP;
870 862 } else {
871 863 type = IPLT_NONE;
872 864 }
873 865 return type;
874 866 }
875 867
876 868 void showhashs_live(fd, role, htstp, poolname, opts)
877 869 int fd, role;
878 870 iphtstat_t *htstp;
879 871 char *poolname;
880 872 int opts;
881 873 {
882 874 ipflookupiter_t iter;
883 875 iphtable_t table;
884 876 ipfobj_t obj;
885 877
886 878 obj.ipfo_rev = IPFILTER_VERSION;
887 879 obj.ipfo_type = IPFOBJ_LOOKUPITER;
888 880 obj.ipfo_size = sizeof(iter);
889 881 obj.ipfo_ptr = &iter;
890 882
891 883 iter.ili_type = IPLT_HASH;
892 884 iter.ili_otype = IPFLOOKUPITER_LIST;
893 885 iter.ili_ival = IPFGENITER_LOOKUP;
894 886 iter.ili_data = &table;
895 887 iter.ili_unit = role;
896 888 *iter.ili_name = '\0';
897 889
898 890 while (htstp->iphs_tables != NULL) {
899 891 if (ioctl(fd, SIOCLOOKUPITER, &obj)) {
900 892 perror("ioctl(SIOCLOOKUPITER)");
901 893 break;
902 894 }
903 895
904 896 printhash_live(&table, fd, poolname, opts);
905 897
906 898 htstp->iphs_tables = table.iph_next;
907 899 }
908 900 }
↓ open down ↓ |
224 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX