Re: ifconfig

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Fri, 20 Jun 2003 21:17:52 +0200
Daniele Bellucci <bellucda@tiscali.it> wrote:

>Hi,
>i'm trying to make a simple hack to my e100 netdriver.... but i've a problem:
>i need to understand what does "ifconfig eth0 up" performs...

Let's take a look at what happens.

When you do "ifconfig eth0 up" a simple strace(8) tracing tells you a 
ioctl(SIOCSIFFLAGS) starts. This is useful for setting IFF_UP flag in dev->flag.
What's important to realize is what really happens (please take net/core/dev.c
handy).

In dev_ioctl() you can see

  	case SIOCSIFFLAGS:
			if (!capable(CAP_NET_ADMIN))
                                return -EPERM;
                        dev_load(ifr.ifr_name);
                        dev_probe_lock();
                        rtnl_lock();
                        ret = dev_ifsioc(&ifr, cmd);
                        rtnl_unlock();
                        dev_probe_unlock();     
                        return ret;

Let's take a look at dev_ifsioc().

	case SIOCSIFFLAGS:      /* Set interface flags */
                        return dev_change_flags(dev, ifr->ifr_flags);

And now the really interesting part of dev_change_flags()

	int old_flags = dev->flags;
           
        /*
         *      Set the flags on our device.
         */                    
        
        dev->flags = (flags & (IFF_DEBUG|IFF_NOTRAILERS|IFF_NOARP|
			       IFF_DYNAMIC| IFF_MULTICAST|IFF_PORTSEL|
			       IFF_AUTOMEDIA)) | (dev->flags & (IFF_UP|
			       IFF_VOLATILE|IFF_PROMISC|IFF_ALLMULTI));
        
        /*
         *      Load in the correct multicast list now the flags have changed.
         */
          
        dev_mc_upload(dev);

        /*
         *      Have we downed the interface. We handle IFF_UP ourselves
         *      according to user attempts to set it, rather than blindly
         *      setting it.
         */
                
        ret = 0;
        if ((old_flags^flags)&IFF_UP)   /* Bit is different  ? */
        {               
                ret = ((old_flags & IFF_UP) ? dev_close : dev_open)(dev);
                
                if (ret == 0)
                        dev_mc_upload(dev);
        }


Please take a look here. As you can see, if IFF_UP was not set (if down),
what happens is simply

		ret = dev_open(dev);

and if you look at dev_open()
 	
	if (dev->open) {   
                        ret = dev->open(dev);

	

so it calls the interface open method thus 'opening' your NIC. The open
method usually requests an IRQ and register it and does few other things.

Similarly, when you clear IFF_UP the interface close method is called.

Take a look at dev.c please. You can find anything there.

>I need to know what syscalls are needed to "wakeup"/setup a net link....
> i suppose that an ioctl cmd is needed ... but i can't understand what 
> should be open in /dev ....

Network interfaces do not use dev special files but they are maintained by
the kernel through struct netdevice's linked through a global linked list.

Ciao.

- --

Angelo Dell'Aera 'buffer' 
Antifork Research, Inc.	  	http://buffer.antifork.org

PGP information in e-mail header



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE+9EHrpONIzxnBXKIRAtgAAJkBlpSrbLj6FFpCKzueFWHzh9qapgCgrQmC
VaDw1KoGY6+o4MiYHUj5jMw=
=Cf+1
-----END PGP SIGNATURE-----
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux