ippool.c (353093) | ippool.c (353094) |
---|---|
1/* $FreeBSD: stable/11/contrib/ipfilter/tools/ippool.c 353093 2019-10-04 02:09:51Z cy $ */ | 1/* $FreeBSD: stable/11/contrib/ipfilter/tools/ippool.c 353094 2019-10-04 02:11:45Z cy $ */ |
2 3/* 4 * Copyright (C) 2012 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 */ 8#include <sys/types.h> 9#include <sys/time.h> --- 238 unchanged lines hidden (view full) --- 248 249 250int 251poolcommand(remove, argc, argv) 252 int remove, argc; 253 char *argv[]; 254{ 255 int type, role, c, err; | 2 3/* 4 * Copyright (C) 2012 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 */ 8#include <sys/types.h> 9#include <sys/time.h> --- 238 unchanged lines hidden (view full) --- 248 249 250int 251poolcommand(remove, argc, argv) 252 int remove, argc; 253 char *argv[]; 254{ 255 int type, role, c, err; |
256 char *poolname; | 256 char *poolname, *typearg = NULL; |
257 iphtable_t iph; 258 ip_pool_t pool; 259 260 err = 1; 261 role = 0; 262 type = 0; 263 poolname = NULL; 264 role = IPL_LOGIPF; 265 bzero((char *)&iph, sizeof(iph)); 266 bzero((char *)&pool, sizeof(pool)); 267 | 257 iphtable_t iph; 258 ip_pool_t pool; 259 260 err = 1; 261 role = 0; 262 type = 0; 263 poolname = NULL; 264 role = IPL_LOGIPF; 265 bzero((char *)&iph, sizeof(iph)); 266 bzero((char *)&pool, sizeof(pool)); 267 |
268 while ((c = getopt(argc, argv, "dm:no:S:v")) != -1) | 268 while ((c = getopt(argc, argv, "dm:no:S:vt:")) != -1) |
269 switch (c) 270 { 271 case 'd' : 272 opts |= OPT_DEBUG; 273 ippool_yydebug++; 274 break; 275 case 'm' : 276 poolname = optarg; --- 9 unchanged lines hidden (view full) --- 286 } 287 break; 288 case 'S' : 289 if (remove == 0) 290 iph.iph_seed = atoi(optarg); 291 else 292 usage(argv[0]); 293 break; | 269 switch (c) 270 { 271 case 'd' : 272 opts |= OPT_DEBUG; 273 ippool_yydebug++; 274 break; 275 case 'm' : 276 poolname = optarg; --- 9 unchanged lines hidden (view full) --- 286 } 287 break; 288 case 'S' : 289 if (remove == 0) 290 iph.iph_seed = atoi(optarg); 291 else 292 usage(argv[0]); 293 break; |
294 case 't' : 295 type = gettype(optarg, &iph.iph_type); 296 typearg = optarg; 297 break; |
|
294 case 'v' : 295 opts |= OPT_VERBOSE; 296 break; 297 default : 298 usage(argv[0]); 299 break; /* keep compiler happy */ 300 } 301 302 if (argc - 1 - optind > 0) 303 usage(argv[0]); 304 305 if (opts & OPT_DEBUG) 306 fprintf(stderr, "poolcommand: opts = %#x\n", opts); 307 308 if (poolname == NULL) { 309 fprintf(stderr, "poolname not given with add/remove pool\n"); 310 return -1; 311 } 312 | 298 case 'v' : 299 opts |= OPT_VERBOSE; 300 break; 301 default : 302 usage(argv[0]); 303 break; /* keep compiler happy */ 304 } 305 306 if (argc - 1 - optind > 0) 307 usage(argv[0]); 308 309 if (opts & OPT_DEBUG) 310 fprintf(stderr, "poolcommand: opts = %#x\n", opts); 311 312 if (poolname == NULL) { 313 fprintf(stderr, "poolname not given with add/remove pool\n"); 314 return -1; 315 } 316 |
313 type = gettype(argv[optind], &iph.iph_type); 314 if (type == IPLT_NONE) { 315 fprintf(stderr, "unknown type '%s'\n", argv[optind]); | 317 if (type == IPLT_NONE && remove == 0) { 318 if (typearg == NULL) { 319 fprintf(stderr, "type must be specified\n"); 320 usage(argv[0]); 321 } else { 322 fprintf(stderr, "unknown type '%s'\n", typearg); 323 } |
316 return -1; 317 } 318 | 324 return -1; 325 } 326 |
319 if (type == IPLT_HASH) { | 327 if (type == IPLT_HASH || (type == IPLT_NONE && remove == 1)) { |
320 strncpy(iph.iph_name, poolname, sizeof(iph.iph_name)); 321 iph.iph_name[sizeof(iph.iph_name) - 1] = '\0'; 322 iph.iph_unit = role; | 328 strncpy(iph.iph_name, poolname, sizeof(iph.iph_name)); 329 iph.iph_name[sizeof(iph.iph_name) - 1] = '\0'; 330 iph.iph_unit = role; |
323 } else if (type == IPLT_POOL) { | 331 } 332 if (type == IPLT_POOL || (type == IPLT_NONE && remove == 1)) { |
324 strncpy(pool.ipo_name, poolname, sizeof(pool.ipo_name)); 325 pool.ipo_name[sizeof(pool.ipo_name) - 1] = '\0'; 326 pool.ipo_unit = role; 327 } 328 329 if (remove == 0) { 330 switch (type) 331 { --- 8 unchanged lines hidden (view full) --- 340 switch (type) 341 { 342 case IPLT_HASH : 343 err = remove_hash(&iph, ioctl); 344 break; 345 case IPLT_POOL : 346 err = remove_pool(&pool, ioctl); 347 break; | 333 strncpy(pool.ipo_name, poolname, sizeof(pool.ipo_name)); 334 pool.ipo_name[sizeof(pool.ipo_name) - 1] = '\0'; 335 pool.ipo_unit = role; 336 } 337 338 if (remove == 0) { 339 switch (type) 340 { --- 8 unchanged lines hidden (view full) --- 349 switch (type) 350 { 351 case IPLT_HASH : 352 err = remove_hash(&iph, ioctl); 353 break; 354 case IPLT_POOL : 355 err = remove_pool(&pool, ioctl); 356 break; |
357 case IPLT_NONE : 358 err = 1; 359 { 360 int err_h, err_p; 361 err_h = remove_hash(&iph, ioctl); 362 err_p = remove_pool(&pool, ioctl); 363 if (err_h == 0 || err_p == 0) 364 err = 0; 365 } 366 break; |
|
348 } 349 } 350 return err; 351} 352 353 354int 355loadpoolfile(argc, argv, infile) --- 740 unchanged lines hidden --- | 367 } 368 } 369 return err; 370} 371 372 373int 374loadpoolfile(argc, argv, infile) --- 740 unchanged lines hidden --- |