When attempting to add a tap device, the error message is fairly cryptic
as to what really happened. If possible, try to load the tun module and
then try again to add the tap device again to improve the user
experience.
Signed-off-by: Doug Goldstein <cardoe(a)gentoo.org>
---
src/util/bridge.c | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/util/bridge.c b/src/util/bridge.c
index 7d0caae..ca4bcc9 100644
--- a/src/util/bridge.c
+++ b/src/util/bridge.c
@@ -486,12 +486,29 @@ brAddTap(brControl *ctl,
{
int fd;
struct ifreq ifr;
+ const char * const argv[] = { "modprobe", "tun", NULL };
+ int err, exitstatus = 0;
if (!ctl || !ctl->fd || !bridge || !ifname)
return EINVAL;
- if ((fd = open("/dev/net/tun", O_RDWR)) < 0)
- return errno;
+ if ((fd = open("/dev/net/tun", O_RDWR)) < 0) {
+ err = errno;
+
+ /* If the tun device was non-existent, lets try to load the module */
+ if (err == ENOENT) {
+ if (virRun(argv, &exitstatus) < 0) {
+ return ENOENT;
+ }
+
+ /* Now lets try to open the tun device again */
+ if ((fd = open("/dev/net/tun", O_RDWR)) < 0) {
+ return errno;
+ }
+ } else {
+ return err;
+ }
+ }
memset(&ifr, 0, sizeof(ifr));
--
1.7.2