*** tools/ipfs.c	Mon May 10 16:05:30 2004
--- tools/ipfs.c	Mon May 10 17:10:45 2004
***************
*** 38,45 ****
--- 38,46 ----
  #include <netdb.h>
  #include <arpa/nameser.h>
  #include <resolv.h>
  #include "ipf.h"
+ #include "ipl.h"
  
  #if !defined(lint)
  static const char rcsid[] = "@(#)$Id: patch-toolsipfs.c,v 1.3 2004/05/10 15:23:58 davidg Exp $";
  #endif
***************
*** 216,233 ****
  	while ((c = getopt(argc, argv, "d:f:lNnSRruvWw")) != -1)
  		switch (c)
  		{
  		case 'd' :
! 			if ((set == 0) && !dirname && !filename)
! 				dirname = optarg;
! 			else
  				usage();
  			break;
  		case 'f' :
! 			if ((set == 0) && !dirname && !filename)
! 				filename = optarg;
! 			else
  				usage();
  			break;
  		case 'i' :
  			ifs = optarg;
  			set = 1;
--- 217,234 ----
  	while ((c = getopt(argc, argv, "d:f:lNnSRruvWw")) != -1)
  		switch (c)
  		{
  		case 'd' :
! 			if (dirname || filename)
  				usage();
+ 			else
+ 				dirname = optarg;
  			break;
  		case 'f' :
! 			if (dirname || filename)
  				usage();
+ 			else
+ 				filename = optarg;
  			break;
  		case 'i' :
  			ifs = optarg;
  			set = 1;
***************
*** 247,255 ****
  			ns = 0;
  			set = 1;
  			break;
  		case 'r' :
! 			if ((ns >= 0) || dirname || (rw != -1))
  				usage();
  			rw = 0;
  			set = 1;
  			break;
--- 248,256 ----
  			ns = 0;
  			set = 1;
  			break;
  		case 'r' :
! 			if ((ns == -1) || dirname || (rw != -1))
  				usage();
  			rw = 0;
  			set = 1;
  			break;
***************
*** 271,279 ****
  			break;
  		case 'v' :
  			opts |= OPT_VERBOSE;
  			break;
! 		case 'w' :
  			if (dirname || (rw != -1) || (ns == -1))
  				usage();
  			rw = 1;
  			set = 1;
--- 272,280 ----
  			break;
  		case 'v' :
  			opts |= OPT_VERBOSE;
  			break;
! 		case 'w' :		
  			if (dirname || (rw != -1) || (ns == -1))
  				usage();
  			rw = 1;
  			set = 1;
***************
*** 286,293 ****
--- 287,297 ----
  		default :
  			usage();
  		}
  
+ 	if (set == 0)
+ 		usage();
+ 
  	if (ifs) {
  		if (!filename || ns < 0)
  			usage();
  		if (ns == 0)
***************
*** 382,389 ****
--- 386,394 ----
  int fd;
  char *file;
  {
  	ipstate_save_t ips, *ipsp;
+ 	ipfobj_t obj;
  	int wfd = -1;
  
  	if (!file)
  		file = IPF_STATEFILE;
***************
*** 397,408 ****
  
  	ipsp = &ips;
  	bzero((char *)ipsp, sizeof(ips));
  
  	do {
  		if (opts & OPT_VERBOSE)
  			printf("Getting state from addr %p\n", ips.ips_next);
! 		if (ioctl(fd, SIOCSTGET, &ipsp)) {
  			if (errno == ENOENT)
  				break;
  			perror("state:SIOCSTGET");
  			close(wfd);
--- 402,420 ----
  
  	ipsp = &ips;
  	bzero((char *)ipsp, sizeof(ips));
  
+ 	bzero((char *)&obj,sizeof(ipfobj_t));
+ 	obj.ipfo_rev = IPFILTER_VERSION;
+ 	obj.ipfo_size = sizeof(ipstate_save_t);
+ 	obj.ipfo_type = IPFOBJ_STATESAVE;
+ 	obj.ipfo_ptr = (void *)ipsp;
+ 
  	do {
  		if (opts & OPT_VERBOSE)
  			printf("Getting state from addr %p\n", ips.ips_next);
! 
! 		if (ioctl(fd, SIOCSTGET, &obj)) {
  			if (errno == ENOENT)
  				break;
  			perror("state:SIOCSTGET");
  			close(wfd);
***************
*** 426,433 ****
--- 438,446 ----
  int fd;
  char *file;
  {
  	ipstate_save_t ips, *is, *ipshead = NULL, *is1, *ipstail = NULL;
+ 	ipfobj_t obj;
  	int sfd = -1, i;
  
  	if (!file)
  		file = IPF_STATEFILE;
***************
*** 495,514 ****
  	} while (1);
  
  	close(sfd);
  
  	for (is = ipshead; is; is = is->ips_next) {
  		if (opts & OPT_VERBOSE)
  			printf("Loading new state table entry\n");
  		if (is->ips_is.is_flags & SI_NEWFR) {
  			if (opts & OPT_VERBOSE)
  				printf("Loading new filter rule\n");
  		}
  		if (!(opts & OPT_DONOTHING))
! 			if (ioctl(fd, SIOCSTPUT, &is)) {
  				perror("SIOCSTPUT");
  				return 1;
  			}
  
  		if (is->ips_is.is_flags & SI_NEWFR) {
  			if (opts & OPT_VERBOSE)
  				printf("Real rule addr %p\n", is->ips_rule);
--- 508,535 ----
  	} while (1);
  
  	close(sfd);
  
+ 	bzero((char *)&obj,sizeof(ipfobj_t));
+ 	obj.ipfo_rev = IPFILTER_VERSION;
+ 	obj.ipfo_size = sizeof(ipstate_save_t);
+ 	obj.ipfo_type = IPFOBJ_STATESAVE;
+ 
  	for (is = ipshead; is; is = is->ips_next) {
  		if (opts & OPT_VERBOSE)
  			printf("Loading new state table entry\n");
  		if (is->ips_is.is_flags & SI_NEWFR) {
  			if (opts & OPT_VERBOSE)
  				printf("Loading new filter rule\n");
  		}
  		if (!(opts & OPT_DONOTHING))
! 		{
! 			obj.ipfo_ptr = (void *)&is;
! 			if (ioctl(fd, SIOCSTPUT, &obj)) {
  				perror("SIOCSTPUT");
  				return 1;
  			}
+ 		}
  
  		if (is->ips_is.is_flags & SI_NEWFR) {
  			if (opts & OPT_VERBOSE)
  				printf("Real rule addr %p\n", is->ips_rule);
***************
*** 528,535 ****
--- 549,557 ----
  {
  	nat_save_t ipn, *in, *ipnhead, *in1, *ipntail, *ipnp;
  	int nfd, i;
  	nat_t *nat;
+ 	ipfobj_t obj;
  
  	nfd = -1;
  	in = NULL;
  	ipnhead = NULL;
***************
*** 624,631 ****
--- 646,659 ----
  	} while (1);
  
  	close(nfd);
  
+ 
+ 	bzero((char *)&obj,sizeof(ipfobj_t));
+ 	obj.ipfo_rev = IPFILTER_VERSION;
+ 	obj.ipfo_size = sizeof(nat_save_t);
+ 	obj.ipfo_type = IPFOBJ_NATSAVE;
+ 
  	for (in = ipnhead; in; in = in->ipn_next) {
  		if (opts & OPT_VERBOSE)
  			printf("Loading new NAT table entry\n");
  		nat = &in->ipn_nat;
***************
*** 633,644 ****
  			if (opts & OPT_VERBOSE)
  				printf("Loading new filter rule\n");
  		}
  		if (!(opts & OPT_DONOTHING))
! 			if (ioctl(fd, SIOCSTPUT, &in)) {
  				perror("SIOCSTPUT");
  				return 1;
  			}
  
  		if (nat->nat_flags & SI_NEWFR) {
  			if (opts & OPT_VERBOSE)
  				printf("Real rule addr %p\n", nat->nat_fr);
--- 661,675 ----
  			if (opts & OPT_VERBOSE)
  				printf("Loading new filter rule\n");
  		}
  		if (!(opts & OPT_DONOTHING))
! 		{
! 			obj.ipfo_ptr = (void *)in;
! 			if (ioctl(fd, SIOCSTPUT, &obj)) {
  				perror("SIOCSTPUT");
  				return 1;
  			}
+ 		}
  
  		if (nat->nat_flags & SI_NEWFR) {
  			if (opts & OPT_VERBOSE)
  				printf("Real rule addr %p\n", nat->nat_fr);
***************
*** 658,665 ****
--- 689,697 ----
  {
  	nat_save_t *ipnp = NULL, *next = NULL;
  	int nfd = -1;
  	natget_t ng;
+ 	ipfobj_t obj;
  
  	if (!file)
  		file = IPF_NATFILE;
  
***************
*** 669,682 ****
--- 701,717 ----
  		perror("nat:open");
  		return 1;
  	}
  
+ 	bzero((char *)&obj,sizeof(ipfobj_t));
+ 	obj.ipfo_rev = IPFILTER_VERSION;
  
  	do {
  		if (opts & OPT_VERBOSE)
  			printf("Getting nat from addr %p\n", ipnp);
  		ng.ng_ptr = next;
  		ng.ng_sz = 0;
+ 
  		if (ioctl(fd, SIOCSTGSZ, &ng)) {
  			perror("nat:SIOCSTGSZ");
  			close(nfd);
  			if (ipnp != NULL)
***************
*** 701,709 ****
  		}
  
  		bzero((char *)ipnp, ng.ng_sz);
  		ipnp->ipn_next = next;
! 		if (ioctl(fd, SIOCSTGET, &ipnp)) {
  			if (errno == ENOENT)
  				break;
  			perror("nat:SIOCSTGET");
  			close(nfd);
--- 736,748 ----
  		}
  
  		bzero((char *)ipnp, ng.ng_sz);
  		ipnp->ipn_next = next;
! 		obj.ipfo_size = sizeof(nat_save_t);
! 		obj.ipfo_type = IPFOBJ_NATSAVE;
! 		obj.ipfo_ptr = (void *)ipnp;
! 		
! 		if (ioctl(fd, SIOCSTGET, &obj)) {
  			if (errno == ENOENT)
  				break;
  			perror("nat:SIOCSTGET");
  			close(nfd);
