FreeBSD Bugzilla – Attachment 208881 Details for
Bug 241737
cannot use the tap interface name to build a VM
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
modification on pci_virtio_net.c
bhyve_pci_virtio_net.patch (text/plain), 3.35 KB, created by
Fabien Costard
on 2019-11-05 16:43:31 UTC
(
hide
)
Description:
modification on pci_virtio_net.c
Filename:
MIME Type:
Creator:
Fabien Costard
Created:
2019-11-05 16:43:31 UTC
Size:
3.35 KB
patch
obsolete
>Index: pci_virtio_net.c >=================================================================== >--- pci_virtio_net.c (revision 354360) >+++ pci_virtio_net.c (working copy) >@@ -60,6 +60,9 @@ > #include <pthread.h> > #include <pthread_np.h> > #include <sysexits.h> >+#include <net/if.h> >+#include <net/if_tap.h> >+#include <dirent.h> > > #include "bhyverun.h" > #include "pci_emul.h" >@@ -817,6 +820,74 @@ > } > } > >+ >+/* this function lists the tap device in /dev >+input : ** char already allocated >+output : integer represents the number of tap file found */ >+int dirDev(char ** tbl) >+{ >+ /* Openning directory */ >+ DIR *d; >+ int i = 0; // number of interface found >+ struct dirent *dir; >+ d = opendir("/dev/"); >+ /* readding file in directory if not empty */ >+ if (d) { >+ while ((dir = readdir(d)) != NULL) { >+ /* looking for tap file and implement it on the table tbl */ >+ if(strncmp("tap", dir->d_name, 3) == 0) { >+ tbl = realloc(tbl,i+1); >+ tbl[i] = (char *)malloc(sizeof(dir->d_name)); >+ sprintf(tbl[i],"%s",dir->d_name); >+ i++; >+ } >+ } >+ /* closing directory */ >+ closedir(d); >+ } >+ return(i); >+} >+ >+/* this function returns the name of the device according to the name in input >+input : * char is the interface name (or alias) >+output : * char is the name present in /dev >+if the interface does not exist the function return the input by default */ >+char * findDevName(char * intName) { >+ >+ /* variable implementation */ >+ int i, nbrIntTap, fd; >+ char * path = "/dev/"; >+ char *tbuf, *devName; >+ char ** tblTapInt; >+ struct ifreq myTapInfo; //use to find the tap name >+ >+ /* variable initialisation */ >+ tbuf = (char*) malloc(sizeof(char*)); >+ devName = (char*) malloc(sizeof(char*)); >+ devName = strdup(intName); >+ tblTapInt = malloc(1); >+ nbrIntTap = dirDev(tblTapInt); // get the list of tap device in /dev >+ >+ /* for each entry, we check the tap name */ >+ for (i=0;i<nbrIntTap;i++) { >+ tbuf = (char *) realloc(tbuf,sizeof(path) + sizeof(tblTapInt[i]) -1 ); >+ tbuf = strdup(path); >+ strcat(tbuf, tblTapInt[i]); >+ fd = open(tbuf, O_RDONLY); // opening the device >+ ioctl(fd, TAPGIFNAME, &myTapInfo); // looking for the tap device name >+ /* If finded we break the loop */ >+ if(strcmp(myTapInfo.ifr_name,intName) == 0 || strcmp(tblTapInt[i],intName) == 0) { >+ devName = strdup(tblTapInt[i]); >+ close(fd); >+ break; >+ } >+ close(fd); >+ } >+ free(tblTapInt); >+ free(tbuf); >+ return devName; >+} >+ > static int > pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) > { >@@ -855,8 +926,8 @@ > if (opts != NULL) { > int err; > >- devname = vtopts = strdup(opts); >- (void) strsep(&vtopts, ","); >+ vtopts = strdup(opts); >+ devname = findDevName(strsep(&vtopts,",")); > > if (vtopts != NULL) { > err = pci_vtnet_parsemac(vtopts, sc->vsc_config.mac);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 241737
:
208881
|
209488