Re: [design] near-fatal unregister_netdevice errors (freeswan 2.04)

"Ian Ward" <[email protected]> Tue, 27 Jan 2004 10:45:53 +1100
Newsgroups gmane.network.freeswan.user,gmane.network.freeswan.devel
Message-ID <00f801c3e466$899de790$a94dfea9@hellcat>
Sorry, I need help with applying this patch (I'm a dope)

> On Friday 23 January 2004 16:16, Michael Richardson wrote:
> > Okay, I reproduced the problem on the train. I have a patch.
> > I don't understand why this wasn't an issue before - probably it was.
>
> The patch works for me; using my old laptop to replicate the error, I can
cleanly reboot without having to power off.
>
> Here is the patch against 2.04's ipsec_tunnel.c (little difference except
for line numbers).
>
> --
> Sam Sgro
> [email protected]
>
> --- ipsec_tunnel.c.orig Sat Jan 24 14:13:39 2004
> +++ ipsec_tunnel.c      Sat Jan 24 14:20:05 2004
> SNIP ---- BLAH..BLAH..BLAH...

OK, here is a screen dump.  The patch file I created by saving Sam's message
as plain text.  I am obviously doing something wrong.  Is it just line
numbers? I thought patch figured that out.

[root@gwwa BUILD]# cd freeswan-2.04/linux/net/ipsec/
[root@gwwa ipsec]#
[root@gwwa ipsec]# ls -la
total 744
drwxr-xr-x    2 root     bin          4096 Nov 12 08:40 .
drwxr-xr-x    4 root     bin          4096 Nov 12 08:40 ..
-rw-r--r--    1 root     bin          1725 Apr 24  2002 Config.in
-rw-r--r--    1 root     bin           839 Jul 29  2002 .cvsignore
-rw-r--r--    1 root     bin          2954 Feb 25  2003 defconfig
-rw-r--r--    1 root     bin         20151 Apr  4  2003 ipcomp.c
-rw-r--r--    1 root     bin         22815 Aug  1 08:47 ipsec_init.c
-rw-r--r--    1 root     bin          6615 Feb  6  2003 ipsec_life.c
-rw-r--r--    1 root     bin         29253 Jun 23  2003 ipsec_mast.c
-rw-r--r--    1 root     bin         12997 Sep 10  2002 ipsec_md5c.c
-rw-r--r--    1 root     bin         12958 Feb 13  2003 ipsec_netlink.c
-rw-r--r--    1 root     bin         28652 Jun 20  2003 ipsec_proc.c
-rw-r--r--    1 root     bin         23809 Oct 13  2002 ipsec_radij.c
-rw-r--r--    1 root     bin         74790 Sep  3 05:51 ipsec_rcv.c
-rw-r--r--    1 root     bin         38504 Feb  6  2003 ipsec_sa.c
-rw-r--r--    1 root     bin          7093 Sep 10  2002 ipsec_sha1.c
-rw-r--r--    1 root     bin         79509 Sep 11 02:46 ipsec_tunnel.c
-rw-r--r--    1 root     bin         11625 May 14  2002 ipsec_xform.c
-rw-r--r--    1 root     bin         50354 Jun 20  2003 ipsec_xmit.c
-rw-r--r--    1 root     bin         13791 Jun 23  2003 Makefile
-rw-r--r--    1 root     bin         54559 Apr  4  2003 pfkey_v2.c
-rw-r--r--    1 root     bin         22978 Feb  6  2003
pfkey_v2_ext_process.c
-rw-r--r--    1 root     bin        124137 Apr  4  2003 pfkey_v2_parser.c
-rw-r--r--    1 root     bin         33040 Jul 25  2002 radij.c
-rw-r--r--    1 root     bin          6310 Apr 24  2002 sysctl_net_ipsec.c
-rw-r--r--    1 root     bin           121 Jun 23  2003 tagsfile.mak
[root@gwwa ipsec]# patch < /tmp/freepatch.txt
(Stripping trailing CRs from patch.)
patching file ipsec_tunnel.c
Hunk #1 FAILED at 1097.
Hunk #2 FAILED at 1167.
Hunk #3 FAILED at 1235.
Hunk #4 FAILED at 1245.
Hunk #5 FAILED at 1255.
5 out of 5 hunks FAILED -- saving rejects to file ipsec_tunnel.c.rej

[root@gwwa ipsec]# cat ipsec_tunnel.c.rej
***************
*** 1097,1102 ****
                     prv->dev ? prv->dev->name : "NULL",
                     dev->name);

         prv->dev = NULL;
         prv->hard_start_xmit = NULL;
         prv->get_stats = NULL;
--- 1097,1103 ----
                     prv->dev ? prv->dev->name : "NULL",
                     dev->name);

+        ipsec_dev_put(prv->dev);
         prv->dev = NULL;
         prv->hard_start_xmit = NULL;
         prv->get_stats = NULL;
***************
*** 1166,1173 ****
                     "klips_debug:ipsec_tunnel_clear: .\n");

         for(i = 0; i < IPSEC_NUM_IF; i++) {
-                sprintf(name, IPSEC_DEV_FORMAT, i);
-                if((ipsecdev = ipsec_dev_get(name)) != NULL) {
                         if((prv = (struct ipsecpriv *)(ipsecdev->priv))) {
                                 prvdev = (struct device *)(prv->dev);
                                 if(prvdev) {
--- 1167,1174 ----
                     "klips_debug:ipsec_tunnel_clear: .\n");

         for(i = 0; i < IPSEC_NUM_IF; i++) {
+                ipsecdev = ipsecdevices[i];
+                if(ipsecdev != NULL) {
                         if((prv = (struct ipsecpriv *)(ipsecdev->priv))) {
                                 prvdev = (struct device *)(prv->dev);
                                 if(prvdev) {
***************
*** 1234,1239 ****
                                     "klips_debug:ipsec_tunnel_ioctl: "
                                     "physical device %s requested is
null\n",
                                     cf->cf_name);
                         return -ENXIO;
                 }

--- 1235,1241 ----
                                     "klips_debug:ipsec_tunnel_ioctl: "
                                     "physical device %s requested is
null\n",
                                     cf->cf_name);
+                        ipsec_dev_put(them);
                         return -ENXIO;
                 }

***************
*** 1243,1248 ****
                                     "klips_debug:ipsec_tunnel_ioctl: "
                                     "physical device %s requested is not
up.\n",
                                     cf->cf_name);
                         return -ENXIO;
                 }
  #endif
--- 1245,1251 ----
                                     "klips_debug:ipsec_tunnel_ioctl: "
                                     "physical device %s requested is not
up.\n",
                                     cf->cf_name);
+                        ipsec_dev_put(them);
                         return -ENXIO;
                 }
  #endif
***************
*** 1252,1257 ****
                                     "klips_debug:ipsec_tunnel_ioctl: "
                                     "virtual device is already connected to
%s.\n",
                                     prv->dev->name ? prv->dev->name :
"NULL");
                         return -EBUSY;
                 }
                 return ipsec_tunnel_attach(dev, them);
--- 1255,1261 ----
                                     "klips_debug:ipsec_tunnel_ioctl: "
                                     "virtual device is already connected to
%s.\n",
                                     prv->dev->name ? prv->dev->name :
"NULL");
+                        ipsec_dev_put(them);
                         return -EBUSY;
                 }
                 return ipsec_tunnel_attach(dev, them);


[root@gwwa ipsec]#[root@gwwa ipsec]# cat /tmp/freepatch.txt
--- ipsec_tunnel.c.orig Sat Jan 24 14:13:39 2004
+++ ipsec_tunnel.c      Sat Jan 24 14:20:05 2004
@@ -1097,6 +1097,7 @@
                    prv->dev ? prv->dev->name : "NULL",
                    dev->name);

+       ipsec_dev_put(prv->dev);
        prv->dev = NULL;
        prv->hard_start_xmit = NULL;
        prv->get_stats = NULL;
@@ -1166,8 +1167,8 @@
                    "klips_debug:ipsec_tunnel_clear: .\n");

        for(i = 0; i < IPSEC_NUM_IF; i++) {
-               sprintf(name, IPSEC_DEV_FORMAT, i);
-               if((ipsecdev = ipsec_dev_get(name)) != NULL) {
+               ipsecdev = ipsecdevices[i];
+               if(ipsecdev != NULL) {
                        if((prv = (struct ipsecpriv *)(ipsecdev->priv))) {
                                prvdev = (struct device *)(prv->dev);
                                if(prvdev) {
@@ -1234,6 +1235,7 @@
                                    "klips_debug:ipsec_tunnel_ioctl: "
                                    "physical device %s requested is
null\n",
                                    cf->cf_name);
+                       ipsec_dev_put(them);
                        return -ENXIO;
                }

@@ -1243,6 +1245,7 @@
                                    "klips_debug:ipsec_tunnel_ioctl: "
                                    "physical device %s requested is not
up.\n",
                                    cf->cf_name);
+                       ipsec_dev_put(them);
                        return -ENXIO;
                }
 #endif
@@ -1252,6 +1255,7 @@
                                    "klips_debug:ipsec_tunnel_ioctl: "
                                    "virtual device is already connected to
%s.\n",
                                    prv->dev->name ? prv->dev->name :
"NULL");
+                       ipsec_dev_put(them);
                        return -EBUSY;
                }
                return ipsec_tunnel_attach(dev, them);

[root@gwwa ipsec]#