Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/dist/ipf/tools PR/21334: Mike M. Volokhov: NAT halts on ipfs...



details:   https://anonhg.NetBSD.org/src/rev/8264222e7c59
branches:  trunk
changeset: 566458:8264222e7c59
user:      christos <christos%NetBSD.org@localhost>
date:      Mon May 10 00:36:19 2004 +0000

description:
PR/21334: Mike M. Volokhov: NAT halts on ipfs(8) restore in case of ftp
proxy used. Apply userland patch from this PR, since the kernel patch does
not match at all anymore, and seems to have been applied differently.

diffstat:

 dist/ipf/tools/ipfs.c |  44 +++++++++++++++++++++++++-------------------
 1 files changed, 25 insertions(+), 19 deletions(-)

diffs (99 lines):

diff -r f57b488f60a5 -r 8264222e7c59 dist/ipf/tools/ipfs.c
--- a/dist/ipf/tools/ipfs.c     Mon May 10 00:35:10 2004 +0000
+++ b/dist/ipf/tools/ipfs.c     Mon May 10 00:36:19 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ipfs.c,v 1.1.1.1 2004/03/28 08:56:32 martti Exp $      */
+/*     $NetBSD: ipfs.c,v 1.2 2004/05/10 00:36:19 christos Exp $        */
 
 /*
  * Copyright (C) 1999-2001, 2003 by Darren Reed.
@@ -528,9 +528,11 @@
 int fd;
 char *file;
 {
-       nat_save_t ipn, *in, *ipnhead, *in1, *ipntail, *ipnp;
+       nat_save_t ipn, *in, *ipnhead = NULL, *in1, *ipntail = NULL;
        int nfd, i;
        nat_t *nat;
+       char *s;
+       int n;
 
        nfd = -1;
        in = NULL;
@@ -548,7 +550,6 @@
        }
 
        bzero((char *)&ipn, sizeof(ipn));
-       ipnp = &ipn;
 
        /*
         * 1. Read all state information in.
@@ -570,33 +571,36 @@
                }
 
                if (ipn.ipn_dsize > 0) {
-                       char *s = ipnp->ipn_data;
-                       int n = ipnp->ipn_dsize;
+                       n = ipn.ipn_dsize;
 
-                       n -= sizeof(ipnp->ipn_data);
+                       if (n > sizeof(ipn.ipn_data))
+                               n -= sizeof(ipn.ipn_data);
+                       else
+                               n = 0;
                        in = malloc(sizeof(*in) + n);
                        if (!in)
                                break;
-
-                       s += sizeof(ipnp->ipn_data);
-                       i = read(nfd, s, n);
-                       if (i == 0)
-                               break;
-                       if (i != n) {
-                               fprintf(stderr, "incomplete read: %d != %d\n",
-                                       i, n);
-                               close(nfd);
-                               free(in);
-                               return 1;
+                       if (n > 0) {
+                               s = in->ipn_data + sizeof(in->ipn_data);
+                               i = read(nfd, s, n);
+                               if (i == 0)
+                                       break;
+                               if (i != n) {
+                                       fprintf(stderr,
+                                               "incomplete read: %d != %d\n",
+                                               i, n);
+                                       close(nfd);
+                                       return 1;
+                               }
                        }
                } else {
                        ipn.ipn_dsize = 0;
                        in = (nat_save_t *)malloc(sizeof(*in));
                }
-               bcopy((char *)ipnp, (char *)in, sizeof(ipn));
+               bcopy((char *)&ipn, (char *)in, sizeof(ipn));
 
                /*
-                * Check to see if this is the first state entry that will
+                * Check to see if this is the first NAT entry that will
                 * reference a particular rule and if so, flag it as such
                 * else just adjust the rule pointer to become a pointer to
                 * the other.  We do this so we have a means later for tracking
@@ -626,6 +630,7 @@
        } while (1);
 
        close(nfd);
+       nfd = -1;
 
        for (in = ipnhead; in; in = in->ipn_next) {
                if (opts & OPT_VERBOSE)
@@ -740,6 +745,7 @@
                dirname = IPF_SAVEDIR;
 
        if (chdir(dirname)) {
+               fprintf(stderr, "IPF_SAVEDIR=%s: ", dirname);
                perror("chdir(IPF_SAVEDIR)");
                return 1;
        }



Home | Main Index | Thread Index | Old Index