On Wed, Jun 16, 2004 at 11:58:15 +0530, Bhaskar-ROCSYS wrote: > Hi all, > > Is there any way to create a dynamic interface from kernel space. > > Is it possible to change the parameters of an interface from kernel > space? > > All these can be done by using ifconfig. But I want to do it from > kernel space. > I want to change the IP address from kernel space and change the IP > address. I have written a small code to do this but i am not able to > see the effect. ifconfig obviously runs in userspace. So it can't touch the kernel varaibles. So it has to communicate the data somehow. Look how it works (strace will suffice -- you just need to know the syscalls it calls). Then read the code of those syscalls until you get past the copy_from_user stuff and basic sanity-checiking. Then call the function that does the works. > The code I had written is: > [...] > int init_module() > { > struct in_device *in_dev; > struct in_ifaddr **ifap = NULL; > struct in_ifaddr *ifa = NULL; > struct net_device *dev; > > if((dev = __dev_get_by_name("eth0")) == NULL) > { > printk("<1>Cannot get info for eth0\n"); > return -1; > } > > if((in_dev = __in_dev_get(dev))!= NULL) > { > for (ifap=&in_dev->ifa_list; (ifa=*ifap) != NULL; ifap=&ifa->ifa_next) > { > if ((strcmp("eth0", ifa->ifa_label) == 0)) > break; /* found */ > } > } > if(ifa) > { > ifa->ifa_local = htonl(0xac100f63); > > ifa->ifa_prefixlen = 24; > ifa->ifa_mask = inet_make_mask(ifa->ifa_prefixlen); > if ((dev->flags&IFF_BROADCAST) && ifa->ifa_prefixlen < > 31) > ifa->ifa_broadcast = > ifa->ifa_address|~ifa->ifa_mask; > } > else printk("<1>Could not find the device\n"); > > return 0; > } > > The changes are made but when I am trying to send packet its failing. > > Is there any other way to change the interface parameters from kernel > space ? It's likely harder than just changing the value. There might be other data structures, that need updating. Just read the code used by ifconfig to set it and call it or do the same. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz>
Attachment:
signature.asc
Description: Digital signature