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