Ticket #3124: patch.4.fbsdcompat.diff

File patch.4.fbsdcompat.diff, 2.8 KB (added by Adek336, 15 years ago)
  • src/libs/compat/freebsd_network/if.c

     
    2828if_alloc(u_char type)
    2929{
    3030    char semName[64];
     31    int i;
    3132
    3233    struct ifnet *ifp = _kernel_malloc(sizeof(struct ifnet), M_ZERO);
    3334    if (ifp == NULL)
     
    5253    ifp->flags = 0;
    5354    ifq_init(&ifp->receive_queue, semName);
    5455
     56    for (i=0; i < MAX_DEVICES; i++)
     57        if (gDevices[i] == NULL)
     58        {
     59            ifp->if_index = i;
     60            gDevices[i] = ifp;
     61            gDeviceCount++;
     62            break;
     63        }
     64
     65    if (i == MAX_DEVICES)
     66        panic("unit too large");
     67
    5568    ifp->if_type = type;
    5669    IF_ADDR_LOCK_INIT(ifp);
    5770    return ifp;
     
    6780void
    6881if_free(struct ifnet *ifp)
    6982{
     83    int i;
     84    for (i=0; i < MAX_DEVICES; i++)
     85        if (ifp->device_name == gDeviceNameList[i])
     86        {
     87            int last;
     88            for (last = 0; last < MAX_DEVICES; last++)
     89                if (gDeviceNameList[last] == NULL)
     90                    break;
     91            last--;
     92
     93            if (i == last)
     94                gDeviceNameList[i] = NULL;
     95            else {
     96                gDeviceNameList[i] = gDeviceNameList[last];
     97                gDeviceNameList[last] = NULL;
     98            }
     99            break;
     100        }
     101
     102    gDevices[ifp->if_index] = NULL;
     103    gDeviceCount--;
     104   
    70105    IF_ADDR_LOCK_DESTROY(ifp);
    71106    if (ifp->if_type == IFT_ETHER)
    72107        _kernel_free(ifp->if_l2com);
     
    81116void
    82117if_initname(struct ifnet *ifp, const char *name, int unit)
    83118{
     119    int i;
    84120    dprintf("if_initname(%p, %s, %d)\n", ifp, name, unit);
    85121
     122//XXX what if name[0] == '\0' ?
    86123    if (name == NULL)
    87124        panic("interface goes unamed");
    88125
    89     if (gDeviceCount >= MAX_DEVICES)
    90         panic("unit too large");
    91 
    92126    ifp->if_dname = name;
    93127    ifp->if_dunit = unit;
    94     ifp->if_index = gDeviceCount++;
    95128
    96129    strlcpy(ifp->if_xname, name, sizeof(ifp->if_xname));
    97130
     
    100133
    101134    driver_printf("%s: /dev/%s\n", gDriverName, ifp->device_name);
    102135
    103     gDeviceNameList[ifp->if_index] = ifp->device_name;
    104     gDevices[ifp->if_index] = ifp;
     136    for (i=0; i < MAX_DEVICES; i++)
     137        if (gDeviceNameList[i] == NULL)
     138        {
     139            gDeviceNameList[i] = ifp->device_name;
     140            break;
     141        }
     142    if (i == MAX_DEVICES)
     143        panic("unit too large");
    105144
    106145    ifp->root_device = find_root_device(unit);
    107146}
  • src/libs/compat/freebsd_network/device.c

     
    2828    struct ifreq ifr;
    2929    int i;
    3030
    31     for (i = 0; gDeviceNameList[i] != NULL; i++) {
    32         if (strcmp(gDeviceNameList[i], name) == 0)
     31    for (i = 0; i < MAX_DEVICES; i++) {
     32        if (gDevices[i] != NULL
     33            && strncmp(gDevices[i]->device_name, name, sizeof(gDevices[i]->device_name))==0)
    3334            break;
    3435    }
    3536
    36     if (gDeviceNameList[i] == NULL)
     37    if (i == MAX_DEVICES)
    3738        return B_ERROR;
    3839
    3940    if (get_module(NET_STACK_MODULE_NAME, (module_info **)&gStack) != B_OK)