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