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