ipf_dotuning.c revision 145519
1/* $FreeBSD: head/contrib/ipfilter/lib/ipf_dotuning.c 145519 2005-04-25 18:20:15Z darrenr $ */ 2 3#include "ipf.h" 4#include "ipl.h" 5#include <sys/ioctl.h> 6 7void ipf_dotuning(fd, tuneargs, iocfn) 8int fd; 9char *tuneargs; 10ioctlfunc_t iocfn; 11{ 12 ipfobj_t obj; 13 ipftune_t tu; 14 char *s, *t; 15 16 bzero((char *)&tu, sizeof(tu)); 17 obj.ipfo_rev = IPFILTER_VERSION; 18 obj.ipfo_size = sizeof(tu);; 19 obj.ipfo_ptr = (void *)&tu; 20 obj.ipfo_type = IPFOBJ_TUNEABLE; 21 22 for (s = strtok(tuneargs, ","); s != NULL; s = strtok(NULL, ",")) { 23 if (!strcmp(s, "list")) { 24 while (1) { 25 if ((*iocfn)(fd, SIOCIPFGETNEXT, &obj) == -1) { 26 perror("ioctl(SIOCIPFGETNEXT)"); 27 break; 28 } 29 if (tu.ipft_cookie == NULL) 30 break; 31 32 tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0'; 33 printtunable(&tu); 34 } 35 } else if ((t = strchr(s, '=')) != NULL) { 36 *t++ = '\0'; 37 strncpy(tu.ipft_name, s, sizeof(tu.ipft_name)); 38 if (sscanf(t, "%lu", &tu.ipft_vlong) == 1) { 39 if ((*iocfn)(fd, SIOCIPFSET, &obj) == -1) { 40 perror("ioctl(SIOCIPFSET)"); 41 return; 42 } 43 } else { 44 fprintf(stderr, "invalid value '%s'\n", s); 45 return; 46 } 47 } else { 48 strncpy(tu.ipft_name, s, sizeof(tu.ipft_name)); 49 if ((*iocfn)(fd, SIOCIPFGET, &obj) == -1) { 50 perror("ioctl(SIOCIPFGET)"); 51 return; 52 } 53 if (tu.ipft_cookie == NULL) 54 return; 55 56 tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0'; 57 printtunable(&tu); 58 } 59 } 60} 61