add UNLEASHED_OBJ to unleashed.mk
[unleashed/tickless.git] / usr / src / cmd / ipf / lib / common / ipf_dotuning.c
blob0746bd1e67ad27284a3eabc3f7719aae12ae12ad
1 /*
2 * Copyright (C) 1993-2005 by Darren Reed.
3 * See the IPFILTER.LICENCE file for details on licencing.
4 */
6 #include "ipf.h"
7 #include "netinet/ipl.h"
8 #include <sys/ioctl.h>
10 void ipf_dotuning(fd, tuneargs, iocfn)
11 int fd;
12 char *tuneargs;
13 ioctlfunc_t iocfn;
15 ipfobj_t obj;
16 ipftune_t tu;
17 char *s, *t;
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;
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;
32 if (tu.ipft_cookie == NULL)
33 break;
35 tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0';
36 printtunable(&tu);
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;
47 } else {
48 fprintf(stderr, "invalid value '%s'\n", s);
49 return;
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;
58 if (tu.ipft_cookie == NULL) {
59 fprintf(stderr, "Null cookie for %s\n", s);
60 return;
63 tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0';
64 printtunable(&tu);