struct net_device * ipsec_mast_get_device(int vifnum) { int ovifnum = vifnum; if(vifnum > IPSECDEV_OFFSET) { return ipsec_tunnel_get_device(vifnum-IPSECDEV_OFFSET); } else { struct net_device *nd; if(vifnum >= MASTTRANSPORT_OFFSET) { vifnum -= MASTTRANSPORT_OFFSET; } if(vifnum <= mastdevices_max) { nd = mastdevices[vifnum]; if(nd) ipsec_dev_hold(nd); return nd; } else { KLIPS_ERROR(debug_tunnel, "no such vif %d (ovif=%d)\n", vifnum, ovifnum); return NULL; } } }
int ipsec_mast_createnum(int vifnum) { struct net_device *im; int vifentry; char name[IFNAMSIZ]; if (vifnum >= IPSEC_NUM_IFMAX) return -ENOENT; if (mastdevices[vifnum] != NULL) return -EEXIST; /* no identical device */ if (vifnum > mastdevices_max) mastdevices_max = vifnum; vifentry = vifnum; snprintf(name, IFNAMSIZ, MAST_DEV_FORMAT, vifnum); #ifdef alloc_netdev im = alloc_netdev(sizeof(struct mastpriv), name, ipsec_mast_netdev_setup); #else im = (struct net_device *)kmalloc(sizeof(struct net_device), GFP_KERNEL); #endif if (im == NULL) { printk(KERN_ERR "failed to allocate space for mast%d device\n", vifnum); return -ENOMEM; } #ifndef alloc_netdev memset((caddr_t)im, 0, sizeof(struct net_device)); memcpy(im->name, name, IFNAMSIZ); #endif #ifdef USE_NETDEV_OPS im->netdev_ops = &ipsec_mast_ops; #else im->init = ipsec_mast_probe; #endif if (register_netdev(im) != 0) { printk(KERN_ERR "ipsec_mast: failed to register %s\n", im->name); return -EIO; } ipsec_dev_hold(im); mastdevices[vifentry] = im; return 0; }