[PATCH] Re: Bringing down ethernet

Jitendra Vegiraju jvegiraju at netscape.net
Fri Mar 28 20:54:38 UTC 2003


I have dealt with the same requirement in a different way.
Why not fix the rtems_bsdnet_ifconfig() function itself.
In the code that handles SIOCSIFFLAGS, add the following lines.

                        if ( (*((short*) param) & IFF_UP ) == 0 ) {
                            /* set the interface down */
                            ifreq.ifr_flags &= ~(IFF_UP);
                        }
                        r = ioctl (s, SIOCSIFFLAGS, &ifreq);

Joel, please apply the patch if it is acceptable to networking code 
maintainers.

The patch is against rtems-ss-20030128.
Thanks,
-Jitendra

Charles Steaderman wrote:

> Is there a simple function for bringing down and ethernet port? I 
> tried using something like:
>
> short flags = ~IFF_UP;
> rtems_bsdnet_ifconfig ("eth0", SIOCGIFFLAGS, &flags);
>
> but when I traced throught the rtems_bsdnet_ifconfig source it appears 
> that you can only ADD flags, but never DELETE them. Is this correct? I 
> ended up copying a source snippet from rtems_bsdnet_ifconfig which 
> looks as follows:
>
> int ifDown(const char* sIfName)
> {
>   int           status = 0;
>   int           s, r = 0;
>   struct ifreq  ifreq;
>
>   s = socket (AF_INET, SOCK_DGRAM, 0);
>   if (s < 0)
>       return(-1);
>
>   strncpy (ifreq.ifr_name, sIfName, IFNAMSIZ);
>
>   rtems_bsdnet_semaphore_obtain ();
>
>   if ((r = ioctl (s, SIOCGIFFLAGS, &ifreq)) < 0)
>           status = -1;
>
>   if(status == 0)
>   {
>       ifreq.ifr_flags &= ~IFF_UP;
>       r = ioctl (s, SIOCSIFFLAGS, &ifreq);
>   }
>
>   rtems_bsdnet_semaphore_release ();
>
>   close (s);
>     return status;
> }
>
> but I didn't like having to expose myself to such low level code. Any 
> comments would be appreciated.
>
> - Charlie
>
>

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ifdown-fix.diff
URL: <http://lists.rtems.org/pipermail/users/attachments/20030328/91c22fdc/attachment.ksh>


More information about the users mailing list