1 /* $FreeBSD$ */ 2 3 /* 4 * Copyright (C) 2012 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 * 8 * $Id$ 9 */ 10 11 #include "ipf.h" 12 #include "netinet/ipl.h" 13 #include <sys/ioctl.h> 14 15 void ipf_dotuning(int fd, char *tuneargs, ioctlfunc_t iocfn) 16 { 17 ipfobj_t obj; 18 ipftune_t tu; 19 char *s, *t; 20 21 bzero((char *)&tu, sizeof(tu)); 22 obj.ipfo_rev = IPFILTER_VERSION; 23 obj.ipfo_size = sizeof(tu);; 24 obj.ipfo_ptr = (void *)&tu; 25 obj.ipfo_type = IPFOBJ_TUNEABLE; 26 27 for (s = strtok(tuneargs, ","); s != NULL; s = strtok(NULL, ",")) { 28 if (!strcmp(s, "list")) { 29 while (1) { 30 if ((*iocfn)(fd, SIOCIPFGETNEXT, &obj) == -1) { 31 ipf_perror_fd(fd, iocfn, 32 "ioctl(SIOCIPFGETNEXT)"); 33 break; 34 } 35 if (tu.ipft_cookie == NULL) 36 break; 37 38 tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0'; 39 printtunable(&tu); 40 } 41 } else if ((t = strchr(s, '=')) != NULL) { 42 tu.ipft_cookie = NULL; 43 *t++ = '\0'; 44 strncpy(tu.ipft_name, s, sizeof(tu.ipft_name)); 45 if (sscanf(t, "%lu", &tu.ipft_vlong) == 1) { 46 if ((*iocfn)(fd, SIOCIPFSET, &obj) == -1) { 47 ipf_perror_fd(fd, iocfn, 48 "ioctl(SIOCIPFSET)"); 49 return; 50 } 51 } else { 52 fprintf(stderr, "invalid value '%s'\n", s); 53 return; 54 } 55 } else { 56 tu.ipft_cookie = NULL; 57 strncpy(tu.ipft_name, s, sizeof(tu.ipft_name)); 58 if ((*iocfn)(fd, SIOCIPFGET, &obj) == -1) { 59 ipf_perror_fd(fd, iocfn, "ioctl(SIOCIPFGET)"); 60 return; 61 } 62 if (tu.ipft_cookie == NULL) { 63 fprintf(stderr, "Null cookie for %s\n", s); 64 return; 65 } 66 67 tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0'; 68 printtunable(&tu); 69 } 70 } 71 } 72