View | Details | Raw Unified | Return to bug 241737 | Differences between
and this patch

Collapse All | Expand All

(-)pci_virtio_net.c (-2 / +73 lines)
Lines 60-65 Link Here
60
#include <pthread.h>
60
#include <pthread.h>
61
#include <pthread_np.h>
61
#include <pthread_np.h>
62
#include <sysexits.h>
62
#include <sysexits.h>
63
#include <net/if.h>
64
#include <net/if_tap.h>
65
#include <dirent.h>
63
66
64
#include "bhyverun.h"
67
#include "bhyverun.h"
65
#include "pci_emul.h"
68
#include "pci_emul.h"
Lines 817-822 Link Here
817
	}
820
	}
818
}
821
}
819
822
823
824
/* this function lists the tap device in /dev
825
input : ** char already allocated
826
output : integer represents the number of tap file found */
827
int dirDev(char ** tbl)
828
{
829
        /* Openning directory */
830
        DIR *d;
831
        int i = 0; // number of interface found
832
        struct dirent *dir;
833
        d = opendir("/dev/");
834
        /* readding file in directory if not empty */
835
        if (d) {
836
                while ((dir = readdir(d)) != NULL) {
837
                        /* looking for tap file and implement it on the table tbl */
838
                        if(strncmp("tap", dir->d_name, 3) == 0) {
839
                                tbl = realloc(tbl,i+1);
840
                                tbl[i] = (char *)malloc(sizeof(dir->d_name));
841
                                sprintf(tbl[i],"%s",dir->d_name);
842
                                i++;
843
                        }
844
                }
845
                /* closing directory */
846
                closedir(d);
847
        }
848
        return(i);
849
}
850
851
/* this function returns the name of the device according to the name in input
852
input : * char is the interface name (or alias)
853
output : * char is the name present in /dev
854
if the interface does not exist the function return the input by default */
855
char * findDevName(char * intName) {
856
857
        /* variable implementation */
858
        int i, nbrIntTap, fd;
859
        char * path = "/dev/";
860
        char *tbuf, *devName;
861
        char ** tblTapInt;
862
        struct ifreq myTapInfo; //use to find the tap name
863
864
        /* variable initialisation */
865
        tbuf = (char*) malloc(sizeof(char*));
866
        devName = (char*) malloc(sizeof(char*));
867
        devName = strdup(intName);
868
        tblTapInt = malloc(1);
869
        nbrIntTap = dirDev(tblTapInt); // get the list of tap device in /dev
870
871
        /* for each entry, we check the tap name */
872
        for (i=0;i<nbrIntTap;i++) {
873
                tbuf = (char *) realloc(tbuf,sizeof(path) + sizeof(tblTapInt[i]) -1 );
874
                tbuf = strdup(path);
875
                strcat(tbuf, tblTapInt[i]);
876
                fd = open(tbuf, O_RDONLY); // opening the device
877
                ioctl(fd, TAPGIFNAME, &myTapInfo); // looking for the tap device name
878
                /* If finded we break the loop */
879
                if(strcmp(myTapInfo.ifr_name,intName) == 0 || strcmp(tblTapInt[i],intName) == 0) {
880
                        devName = strdup(tblTapInt[i]);
881
                        close(fd);
882
                        break;
883
                }
884
                close(fd);
885
        }
886
        free(tblTapInt);
887
        free(tbuf);
888
        return devName;
889
}
890
820
static int
891
static int
821
pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
892
pci_vtnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
822
{
893
{
Lines 855-862 Link Here
855
	if (opts != NULL) {
926
	if (opts != NULL) {
856
		int err;
927
		int err;
857
928
858
		devname = vtopts = strdup(opts);
929
                vtopts = strdup(opts);
859
		(void) strsep(&vtopts, ",");
930
                devname = findDevName(strsep(&vtopts,","));
860
931
861
		if (vtopts != NULL) {
932
		if (vtopts != NULL) {
862
			err = pci_vtnet_parsemac(vtopts, sc->vsc_config.mac);
933
			err = pci_vtnet_parsemac(vtopts, sc->vsc_config.mac);

Return to bug 241737