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