Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 7994 - Patch to net-tools to allow mii-tool to activate/deactive interfaces based on media
Summary: Patch to net-tools to allow mii-tool to activate/deactive interfaces based on...
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High enhancement with 1 vote (vote)
Assignee: Mobile Herd (OBSOLETE)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-09-16 11:30 UTC by Pat Double
Modified: 2003-12-30 14:06 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch to mii-tool.c to allow activation of interface based on media state (net-tools-1.60-mii-tool-activate.patch,3.46 KB, patch)
2002-09-16 11:34 UTC, Pat Double
Details | Diff
Patch to mii-tool (and man page) to add -a,--activate option (net-tools-1.60-mii-tool-activate.patch,10.76 KB, patch)
2002-09-26 07:39 UTC, Pat Double
Details | Diff
init script to start and stop watching interfaces to activate (netlinkactivate-init.d,536 bytes, text/plain)
2002-09-26 07:41 UTC, Pat Double
Details
Configuration file for /etc/init.d/netlinkactivate (netlinkactivate-conf.d,216 bytes, text/plain)
2002-09-26 07:43 UTC, Pat Double
Details
Modified ebuild to incorporate patches and init script (net-tools-1.60-r4.ebuild,2.03 KB, text/plain)
2002-09-26 07:44 UTC, Pat Double
Details
net-tools.tar.gz: net-tools ebuilds (Updated) (net-tools.tar.gz,10.65 KB, application/x-tgz)
2002-10-07 06:18 UTC, Pat Double
Details
net-tools.tgz: (Updated to specify start/stop/pause) (net-tools.tgz,10.44 KB, application/octet-stream)
2002-12-18 05:43 UTC, Pat Double
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pat Double 2002-09-16 11:30:42 UTC
Please find attached a patch to net-tools to add an option to mii-tool to 
activate/deactive interfaces based on the media state. It works with the "-w" 
(watch) option. When the media state changes (linked, unlinked), the 
appropriate /etc/init.d/net.% start|stop command will be called. This feature 
is very useful to laptops that have a built in NIC which are not always 
connected. When the cable is plugged in, the network is brought, when 
unplugged it is brought down. 
 
Thanks. 
 
Pat
Comment 1 Pat Double 2002-09-16 11:34:07 UTC
Created attachment 3957 [details, diff]
Patch to mii-tool.c to allow activation of interface based on media state
Comment 2 Pat Double 2002-09-16 11:34:51 UTC
If you want an ebuild based on the latest net-tools ebuild, I'm willing to put 
that together as well and attached. 
Comment 3 Seemant Kulleen (RETIRED) gentoo-dev 2002-09-16 19:19:21 UTC
hi Pat, have you sent this patch upstream as well?
Comment 4 Pat Double 2002-09-20 10:11:40 UTC
You mean to the developers of net-tools? Yes, at least a month ago and    
received no response. 
 
The problem is that the startup scripts for the network    
are distro dependent. Also, I'm using /sbin/ifconfig, grep etc. to determine   
if the interface it up or down, which may not be desirable. If I was better at   
Linux system level programming, I would probably know how to determine if an   
interface is up or down with ifconfig and grep, and then making the command   
for starting/stopping an interface in a config file would probably be better.   
I have some other enhancements to post too, like an init script and config   
file that when started will monitor certain interfaces for activation. This   
way a user doesn't need to put the command into a startup script like rc.local   
(or the Gentoo equiv). 
 
Any suggestions for improvement on this patch are welcome, I'm willing to 
develop it. 
Comment 5 Pat Double 2002-09-20 10:14:24 UTC
Hmmm... I really should do more research. It finally dawned on me that 
ifconfig is in the same build as mii-tool. Argh. I will research into this 
more to make a better patch. 
Comment 6 Pat Double 2002-09-26 07:37:57 UTC
I've finally got this thing into a decent state. The mii-tool patch no longer  
uses ifconfig/grep to determine if the interface is up or down. It uses the  
code in the net-tools library routines, just like ifconfig. Also the 
-a,--activate option takes as a parameter the initscript to use for starting 
and stopping the interface(s). A "%s" in the string will be replaced by the 
interface name. For example: 
 
mii-tool --watch --activate=/etc/init.d/net.%s 
 
This is used for Gentoo. 
 
ALSO provided are two files that allow this feature to be incorporated into 
the runlevel system. I've named the service "netlinkactivate", any suggestions 
are welcome :) The netlinkactivate-init.d file will be placed into 
/etc/init.d/netlinkactivate and is used to start and stop watching 
interface(s) for link status changes. The netlinkactivate-conf.d is placed 
into /etc/conf.d/netlinkactivate and configures which interfaces will be 
watched. 
 
SO, to use this feature: 
 
1. emerge it 
2. edit /etc/conf.d/netlinkactivate to configure your interfaces (eth0 is 
there on install) 
3. rc-update add netlinkactivate default 
 
Thoughts, ideas, suggestions.... 
Comment 7 Pat Double 2002-09-26 07:39:43 UTC
Created attachment 4205 [details, diff]
Patch to mii-tool (and man page) to add -a,--activate option

This will patch mii-tool.c and the English man page to provide the activate
functionality. Please note that the Makefile will also be changed to link
mii-tool with the net-tools library.
Comment 8 Pat Double 2002-09-26 07:41:14 UTC
Created attachment 4206 [details]
init script to start and stop watching interfaces to activate

This file will be placed into /etc/init.d/netlinkactivate and runs mii-tool to
watch the interfaces defined in /etc/conf.d/netlinkactivate. This file should
be placed in the "files" directory of the ebuild.
Comment 9 Pat Double 2002-09-26 07:43:10 UTC
Created attachment 4207 [details]
Configuration file for /etc/init.d/netlinkactivate

This is the configuration for the /etc/init.d/netlinkactivate init script
(attached in the bug as netlinkactivate-init.d). It defines one variable,
INTERFACES, that is a whitespace separated list of interfaces to watch and
activate. Making this empty will watch all known interfaces. Perhaps this
should be the default?
Comment 10 Pat Double 2002-09-26 07:44:29 UTC
Created attachment 4208 [details]
Modified ebuild to incorporate patches and init script

This ebuild has been modified from the official portage tree to apply the patch
and install netlinkactivate-init.d into /etc/init.d/netlinkactivate and
netlinkactivate-conf.d into /etc/conf.d/netlinkactivate.
Comment 11 Pat Double 2002-10-07 06:18:46 UTC
Created attachment 4476 [details]
net-tools.tar.gz: net-tools ebuilds (Updated)

I thought it would be easily to have a tarball of the entire ebuild directory.
This one has both net-tools-1.60-r4 and net-tools-1.60-r5 modified for the
patch.
Comment 12 Grant Goodyear (RETIRED) gentoo-dev 2002-11-01 13:38:34 UTC
unexpectedly away; reassigning
Comment 13 Chad Huneycutt (RETIRED) gentoo-dev 2002-12-15 16:22:59 UTC
This looks like a cool addition, but I need 2 things before I commit this to the
tree.

1. Does anyone else need this functionality?  Can you send an e-mail to the
mailing lists to get a feel, please?

2. Given the number of patch files added to the files directory, we should
probably  switch to a different scheme:  tar up the patches and other files used
to modify the source.  I will put that tarball on ibiblio, and then the ebuild
needs to be modified to download the patchball, unpack it, and take the patches
from there instead of FILESDIR.
Comment 14 Pat Double 2002-12-18 05:43:47 UTC
Created attachment 6581 [details]
net-tools.tgz: (Updated to specify start/stop/pause)

This update has changed the parameters of mii-tool to specify separate scripts
for starting and stopping the interface per request by the gentoo-dev list. I
opted to call these options "startif" and "stopif" since they are tied to
starting and stopping the interface. If the media link becomes online, the code
checks if the interface is already started, if so, it does nothing. Similar
behavior with stopping the interface, it won't issue the command if the
interface is already stopped.

In addition to the mii-tool changes, the conf.d file has variables STARTIF and
STOPIF defined. These are the initscript commands. STARTIF should always be
"start". STOPIF may be "stop" or "pause" depending on user preference.

The tarball includes only net-tools-1.60-r5 since it is marked as stable now.
It is in sync with the latest in portage.

Enjoy!
Comment 15 Wout Mertens (RETIRED) gentoo-dev 2003-03-19 05:38:06 UTC
Hey Pat, 
 
while you did impressive work, I would like to point out the ifplugd ebuild. Ifplugd supports 3 
different kernel media detection interfaces, where mii-tool only handles the mii one. Furthermore, it 
has an option to wait a bit after the interface is down before actually bringing down the interface, 
and it has full daemonization support and beeping. 
 
I am saying this because I think that gentoo should not incorporate your patch in the standard 
net-tools ebuild, or at most with a local USE flag. This to prevent losing the feature later on should 
you stop supporting your patch. 
 
I think your best bet would be to get your patches accepted upstream. I am all for choice. 
 
Wout. 
 
PS: If you do get your patches accepted upstream, can you get them to add an fflush(stdout) after the  
printing of the information? That way, scripts can be written to use mii-tool -w. I actually wrote 
such a script but had daemonization issues, and now I use ifplugd which is better. 
Comment 16 Pat Double 2003-03-29 07:16:00 UTC
Either ifplugd was not available or I couldn't find it when I wrote this patch. I will 
probably just drop it, as I've not ever gotten ANY response from the maintainers of 
net-tools, not even a "your patch is not general enough to use", or something like that. 
I've not submitted the latest here, but ifplugd appears to handle things better. 
 
BTW, I cannot get ifplugd to work. It brings the interface to an "UP" state, preventing 
the /etc/init.d/net.eth0 script to start dhcpcd because it detects it is "UP". I'm sure this 
is something on my end as apparently ifplugd works great for others. 
Comment 17 Warp Zero (RETIRED) gentoo-dev 2003-12-30 14:06:27 UTC
Gentoo's init.d script system is not designed for this kind of use anyway, it is designed more for starting services such as ifplugd at bootup.

Have a nice day.