tech-kern archive

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

Re: if_tun module doesn't autoload if opening /dev/tunN



On Wed, 7 Sep 2016, Paul Goyette wrote:

On Wed, 7 Sep 2016, Martin Husemann wrote:

On Wed, Sep 07, 2016 at 01:50:07PM +0800, Paul Goyette wrote:
I can see a couple of ways to "fix" this:

	1. Rename the module (with all appropriate updates to the
	   sets lists in src/distrib/sets/lists), or
	2. Add code to spec_vnops.c to try loading module if_xxx if the
	   autoload of module xxx fails.

Add a static list of name exceptions? There probably are few.

OK, perhaps something like the attached diffs?

I'm building now....

Well, I did have to make a few minor changes to the patch (new diffs are attached to this Email). But it appears to work. Opening /dev/tun0 results in ifconfig showing the new device. So progress has been made and the module is correctly auto-loaded if needed. I plan to commit these changes tomorrow unless there's some strong objections.

I don't have enough qemu networking clue to actually test for any real functionality (passing of packets), but I've got a real-life scenario where I can make that test. :) I'll check that out in the next few days.

Thanks, Martin, for the suggestion of an appropriate fix mechanism.


+------------------+--------------------------+------------------------+
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:      |
| (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org |
+------------------+--------------------------+------------------------+
Index: spec_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/specfs/spec_vnops.c,v
retrieving revision 1.163
diff -u -p -r1.163 spec_vnops.c
--- spec_vnops.c	20 Aug 2016 12:37:09 -0000	1.163
+++ spec_vnops.c	7 Sep 2016 12:02:28 -0000
@@ -482,6 +482,16 @@ spec_lookup(void *v)
 
 typedef int (*spec_ioctl_t)(dev_t, u_long, void *, int, struct lwp *);
 
+struct dev_to_mod {
+	const char *dev_name, *mod_name;
+};
+
+struct dev_to_mod dev_mod_table[] = {
+	{ "tap", "if_tap" },
+	{ "tun", "if_tun" },
+	{ NULL, NULL }
+};
+	
 /*
  * Open a special file.
  */
@@ -505,6 +515,7 @@ spec_open(void *v)
 	u_int gen;
 	const char *name;
 	struct partinfo pi;
+	struct dev_to_mod *conv;
 	
 	l = curlwp;
 	vp = ap->a_vp;
@@ -571,6 +582,16 @@ spec_open(void *v)
 			/* Get device name from devsw_conv array */
 			if ((name = cdevsw_getname(major(dev))) == NULL)
 				break;
+
+			/* Check exception table for alternate module name */
+			conv = dev_mod_table;
+			while (conv->dev_name != NULL) {
+				if (strcmp(conv->dev_name, name) == 0) {
+					name = conv->mod_name;
+					break;
+				}
+				conv++;
+			}
 			
 			/* Try to autoload device module */
 			(void) module_autoload(name, MODULE_CLASS_DRIVER);
@@ -623,6 +644,16 @@ spec_open(void *v)
 
 			VOP_UNLOCK(vp);
 
+			/* Check exception table for alternate module name */
+			conv = dev_mod_table;
+			while (conv->dev_name != NULL) {
+				if (strcmp(conv->dev_name, name) == 0) {
+					name = conv->mod_name;
+					break;
+				}
+				conv++;
+			}
+
                         /* Try to autoload device module */
 			(void) module_autoload(name, MODULE_CLASS_DRIVER);
 			


Home | Main Index | Thread Index | Old Index