]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ipfilter/lib/ipf_dotuning.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ipfilter / lib / ipf_dotuning.c
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 2003-2005 by Darren Reed.
5  * 
6  * See the IPFILTER.LICENCE file for details on licencing.  
7  *   
8  * $Id: ipf_dotuning.c,v 1.2.4.3 2006/06/16 17:21:02 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                                         perror("ioctl(SIOCIPFGETNEXT)");
35                                         break;
36                                 }
37                                 if (tu.ipft_cookie == NULL)
38                                         break;
39
40                                 tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0';
41                                 printtunable(&tu);
42                         }
43                 } else if ((t = strchr(s, '=')) != NULL) {
44                         tu.ipft_cookie = NULL;
45                         *t++ = '\0';
46                         strncpy(tu.ipft_name, s, sizeof(tu.ipft_name));
47                         if (sscanf(t, "%lu", &tu.ipft_vlong) == 1) {
48                                 if ((*iocfn)(fd, SIOCIPFSET, &obj) == -1) {
49                                         perror("ioctl(SIOCIPFSET)");
50                                         return;
51                                 }
52                         } else {
53                                 fprintf(stderr, "invalid value '%s'\n", s);
54                                 return;
55                         }
56                 } else {
57                         tu.ipft_cookie = NULL;
58                         strncpy(tu.ipft_name, s, sizeof(tu.ipft_name));
59                         if ((*iocfn)(fd, SIOCIPFGET, &obj) == -1) {
60                                 perror("ioctl(SIOCIPFGET)");
61                                 return;
62                         }
63                         if (tu.ipft_cookie == NULL) {
64                                 fprintf(stderr, "Null cookie for %s\n", s);
65                                 return;
66                         }
67
68                         tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0';
69                         printtunable(&tu);
70                 }
71         }
72 }