141edb306SCy Schubert
241edb306SCy Schubert /*
341edb306SCy Schubert * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert *
541edb306SCy Schubert * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert *
741edb306SCy Schubert * $Id$
841edb306SCy Schubert */
941edb306SCy Schubert
1041edb306SCy Schubert #include "ipf.h"
1141edb306SCy Schubert #include "netinet/ipl.h"
1241edb306SCy Schubert #include <sys/ioctl.h>
1341edb306SCy Schubert
ipf_dotuning(int fd,char * tuneargs,ioctlfunc_t iocfn)14efeb8bffSCy Schubert void ipf_dotuning(int fd, char *tuneargs, ioctlfunc_t iocfn)
1541edb306SCy Schubert {
1641edb306SCy Schubert ipfobj_t obj;
1741edb306SCy Schubert ipftune_t tu;
1841edb306SCy Schubert char *s, *t;
1941edb306SCy Schubert
2041edb306SCy Schubert bzero((char *)&tu, sizeof(tu));
2141edb306SCy Schubert obj.ipfo_rev = IPFILTER_VERSION;
22*540be39bSElyes Haouas obj.ipfo_size = sizeof(tu);
2341edb306SCy Schubert obj.ipfo_ptr = (void *)&tu;
2441edb306SCy Schubert obj.ipfo_type = IPFOBJ_TUNEABLE;
2541edb306SCy Schubert
2641edb306SCy Schubert for (s = strtok(tuneargs, ","); s != NULL; s = strtok(NULL, ",")) {
2741edb306SCy Schubert if (!strcmp(s, "list")) {
2841edb306SCy Schubert while (1) {
2941edb306SCy Schubert if ((*iocfn)(fd, SIOCIPFGETNEXT, &obj) == -1) {
3041edb306SCy Schubert ipf_perror_fd(fd, iocfn,
3141edb306SCy Schubert "ioctl(SIOCIPFGETNEXT)");
3241edb306SCy Schubert break;
3341edb306SCy Schubert }
3441edb306SCy Schubert if (tu.ipft_cookie == NULL)
3541edb306SCy Schubert break;
3641edb306SCy Schubert
3741edb306SCy Schubert tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0';
3841edb306SCy Schubert printtunable(&tu);
3941edb306SCy Schubert }
4041edb306SCy Schubert } else if ((t = strchr(s, '=')) != NULL) {
4141edb306SCy Schubert tu.ipft_cookie = NULL;
4241edb306SCy Schubert *t++ = '\0';
4341edb306SCy Schubert strncpy(tu.ipft_name, s, sizeof(tu.ipft_name));
4441edb306SCy Schubert if (sscanf(t, "%lu", &tu.ipft_vlong) == 1) {
4541edb306SCy Schubert if ((*iocfn)(fd, SIOCIPFSET, &obj) == -1) {
4641edb306SCy Schubert ipf_perror_fd(fd, iocfn,
4741edb306SCy Schubert "ioctl(SIOCIPFSET)");
4841edb306SCy Schubert return;
4941edb306SCy Schubert }
5041edb306SCy Schubert } else {
5141edb306SCy Schubert fprintf(stderr, "invalid value '%s'\n", s);
5241edb306SCy Schubert return;
5341edb306SCy Schubert }
5441edb306SCy Schubert } else {
5541edb306SCy Schubert tu.ipft_cookie = NULL;
5641edb306SCy Schubert strncpy(tu.ipft_name, s, sizeof(tu.ipft_name));
5741edb306SCy Schubert if ((*iocfn)(fd, SIOCIPFGET, &obj) == -1) {
5841edb306SCy Schubert ipf_perror_fd(fd, iocfn, "ioctl(SIOCIPFGET)");
5941edb306SCy Schubert return;
6041edb306SCy Schubert }
6141edb306SCy Schubert if (tu.ipft_cookie == NULL) {
6241edb306SCy Schubert fprintf(stderr, "Null cookie for %s\n", s);
6341edb306SCy Schubert return;
6441edb306SCy Schubert }
6541edb306SCy Schubert
6641edb306SCy Schubert tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0';
6741edb306SCy Schubert printtunable(&tu);
6841edb306SCy Schubert }
6941edb306SCy Schubert }
7041edb306SCy Schubert }
71