Ticket #728: mattb-vap-procentries.diff

File mattb-vap-procentries.diff, 6.7 kB (added by matt@mattb.net.nz, 3 years ago)

Add proc entry handling support to the VAP code

  • net80211/ieee80211.c

    old new  
    578578        ifmedia_removeall(&vap->iv_media); 
    579579 
    580580        ieee80211_sysctl_vdetach(vap); 
     581        ieee80211_proc_cleanup(vap); 
    581582        ieee80211_ioctl_vdetach(vap); 
    582583        ieee80211_vlan_vdetach(vap); 
    583584        ieee80211_scan_vdetach(vap); 
  • net80211/ieee80211_var.h

    old new  
    265265        u_int8_t num; 
    266266}; 
    267267 
     268#ifdef CONFIG_SYSCTL 
     269#define MAX_PROC_IEEE80211_SIZE 16383 
     270#define PROC_IEEE80211_PERM 0644 
     271 
     272struct proc_ieee80211_priv { 
     273     int rlen; 
     274     int max_rlen; 
     275     char *rbuf; 
     276 
     277     int wlen; 
     278     int max_wlen; 
     279     char *wbuf; 
     280}; 
     281 
     282struct ieee80211_proc_entry { 
     283        char *name; 
     284        struct file_operations *fileops; 
     285        struct proc_dir_entry *entry; 
     286        struct ieee80211_proc_entry *next; 
     287}; 
     288#endif 
     289 
    268290struct ieee80211vap { 
    269291        struct net_device *iv_dev;              /* associated device */ 
    270292        struct net_device_stats iv_devstats;    /* interface statistics */ 
     
    275297#ifdef CONFIG_SYSCTL 
    276298        struct ctl_table_header *iv_sysctl_header; 
    277299        struct ctl_table *iv_sysctls; 
    278         struct proc_dir_entry *iv_proc_stations; 
    279300        struct proc_dir_entry *iv_proc; 
     301        struct ieee80211_proc_entry *iv_proc_entries; 
    280302#endif 
    281303        struct vlan_group *iv_vlgrp;            /* vlan group state */ 
    282304 
  • net80211/ieee80211_linux.c

    old new  
    318318 
    319319#ifdef CONFIG_SYSCTL 
    320320 
    321 #define MAX_PROC_IEEE80211_SIZE 16383 
    322 #define PROC_IEEE80211_PERM 0644 
    323  
    324321static struct proc_dir_entry *proc_madwifi; 
    325322static int proc_madwifi_count = 0; 
    326323 
    327 /* XXX: Not the right place for such a declaration */ 
    328 struct proc_ieee80211_priv { 
    329      int rlen; 
    330      int max_rlen; 
    331      char *rbuf; 
    332  
    333      int wlen; 
    334      int max_wlen; 
    335      char *wbuf; 
    336 }; 
    337  
    338324static int 
    339325proc_read_nodes(struct ieee80211vap *vap, char *buf, int space) 
    340326{ 
     
    598584{ 
    599585        int i, space; 
    600586        char *devname = NULL; 
    601          
     587        struct ieee80211_proc_entry *tmp=NULL; 
     588 
    602589        space = 5 * sizeof(struct ctl_table) + sizeof(ieee80211_sysctl_template); 
    603590        vap->iv_sysctls = kmalloc(space, GFP_KERNEL); 
    604591        if (vap->iv_sysctls == NULL) { 
     
    649636                vap->iv_sysctls = NULL; 
    650637        } 
    651638 
     639        /* Ensure the base madwifi directory exists */ 
    652640        if (!proc_madwifi && proc_net != NULL) { 
    653641                proc_madwifi = proc_mkdir("madwifi", proc_net); 
    654642                if (!proc_madwifi) 
    655643                        printk(KERN_WARNING "Failed to mkdir /proc/net/madwifi\n"); 
    656644        } 
    657645 
     646        /* Create a proc directory named after the VAP */ 
    658647        if (proc_madwifi) { 
    659648                proc_madwifi_count++; 
    660649                vap->iv_proc = proc_mkdir(vap->iv_dev->name, proc_madwifi); 
    661                 if (vap->iv_proc) { 
    662                         vap->iv_proc_stations = create_proc_entry("associated_sta", 
    663                                 PROC_IEEE80211_PERM, vap->iv_proc); 
    664                         vap->iv_proc_stations->data = vap; 
    665                         vap->iv_proc_stations->proc_fops = &proc_ieee80211_ops; 
     650        } 
     651         
     652        /* Create a proc entry listing the associated stations */ 
     653        ieee80211_proc_vcreate(vap, &proc_ieee80211_ops, "associated_sta"); 
     654 
     655        /* Recreate any other proc entries that have been registered */ 
     656        if (vap->iv_proc) { 
     657                tmp = vap->iv_proc_entries; 
     658                while (tmp) { 
     659                        if (!tmp->entry) { 
     660                                tmp->entry = create_proc_entry(tmp->name,  
     661                                        PROC_IEEE80211_PERM, vap->iv_proc); 
     662                                tmp->entry->data = vap; 
     663                                tmp->entry->proc_fops = tmp->fileops; 
     664                        } 
     665                        tmp = tmp->next; 
    666666                } 
    667667        } 
    668668} 
    669669 
     670/* Frees all memory used for the list of proc entries */ 
     671void  
     672ieee80211_proc_cleanup(struct ieee80211vap *vap) 
     673{ 
     674        struct ieee80211_proc_entry *tmp=vap->iv_proc_entries; 
     675        struct ieee80211_proc_entry *next = NULL; 
     676        while (tmp) { 
     677                next = tmp->next; 
     678                kfree(tmp); 
     679                tmp = next; 
     680        } 
     681} 
     682 
     683/* Called by other modules to register a proc entry under the vap directory */ 
     684int  
     685ieee80211_proc_vcreate(struct ieee80211vap *vap,  
     686                struct file_operations *fileops, char *name) 
     687{ 
     688        struct ieee80211_proc_entry *entry; 
     689        struct ieee80211_proc_entry *tmp=NULL; 
     690 
     691        /* Ignore if already in the list */ 
     692        if (vap->iv_proc_entries) { 
     693                tmp = vap->iv_proc_entries; 
     694                do { 
     695                        if (strcmp(tmp->name, name)==0) 
     696                                return -1; 
     697                        /* Check for end of list */ 
     698                        if (!tmp->next) 
     699                                break; 
     700                        /* Otherwise move on */ 
     701                        tmp = tmp->next; 
     702                } while (1); 
     703        } 
     704         
     705        /* Create an item in our list for the new entry */ 
     706        entry = kmalloc(sizeof(struct ieee80211_proc_entry), GFP_KERNEL); 
     707        if (entry == NULL) { 
     708                printk("%s: no memory for new proc entry (%s)!\n", __func__,  
     709                                name); 
     710                return -1; 
     711        } 
     712 
     713        /* Replace null fileops pointers with our standard functions */ 
     714        if (!fileops->open) 
     715                fileops->open = proc_ieee80211_open; 
     716        if (!fileops->release) 
     717                fileops->release = proc_ieee80211_close; 
     718        if (!fileops->read) 
     719                fileops->read = proc_ieee80211_read; 
     720        if (!fileops->write) 
     721                fileops->write = proc_ieee80211_write; 
     722         
     723        /* Create the entry record */ 
     724        entry->name = name; 
     725        entry->fileops = fileops; 
     726        entry->next = NULL; 
     727        entry->entry = NULL; 
     728 
     729        /* Create the actual proc entry */ 
     730        if (vap->iv_proc) { 
     731                entry->entry = create_proc_entry(entry->name,  
     732                                PROC_IEEE80211_PERM, vap->iv_proc); 
     733                entry->entry->data = vap; 
     734                entry->entry->proc_fops = entry->fileops; 
     735        } 
     736 
     737        /* Add it to the list */ 
     738        if (!tmp) { 
     739                /* Add to the start */ 
     740                vap->iv_proc_entries = entry; 
     741        } else { 
     742                /* Add to the end */ 
     743                tmp->next = entry; 
     744        } 
     745 
     746        return 0; 
     747} 
     748EXPORT_SYMBOL(ieee80211_proc_vcreate); 
     749 
    670750void 
    671751ieee80211_sysctl_vdetach(struct ieee80211vap *vap) 
    672752{ 
     753        struct ieee80211_proc_entry *tmp=NULL; 
     754 
    673755        if (vap->iv_sysctl_header) { 
    674756                unregister_sysctl_table(vap->iv_sysctl_header); 
    675757                vap->iv_sysctl_header = NULL; 
    676758        } 
    677759 
    678760        if (vap->iv_proc) { 
    679                 remove_proc_entry("associated_sta", vap->iv_proc); 
     761                /* Remove child proc entries but leave them in the list */ 
     762                tmp = vap->iv_proc_entries; 
     763                while (tmp) { 
     764                        if (tmp->entry) { 
     765                                remove_proc_entry(tmp->name, vap->iv_proc); 
     766                                tmp->entry = NULL; 
     767                        } 
     768                        tmp = tmp->next; 
     769                } 
    680770                remove_proc_entry(vap->iv_proc->name, proc_madwifi); 
    681771                if (proc_madwifi_count == 1) { 
    682772                        remove_proc_entry("madwifi", proc_net); 
  • net80211/ieee80211_linux.h

    old new  
    479479 
    480480void ieee80211_sysctl_vattach(struct ieee80211vap *); 
    481481void ieee80211_sysctl_vdetach(struct ieee80211vap *); 
     482int ieee80211_proc_vcreate(struct ieee80211vap *, struct file_operations *, 
     483               char *); 
     484void ieee80211_proc_cleanup(struct ieee80211vap *); 
    482485#endif /* CONFIG_SYSCTL */ 
    483486 
    484487#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)