Summary: | Patch to net-tools to allow mii-tool to activate/deactive interfaces based on media | ||
---|---|---|---|
Product: | Gentoo Linux | Reporter: | Pat Double <gentoo> |
Component: | New packages | Assignee: | Mobile Herd (OBSOLETE) <mobile+disabled> |
Status: | RESOLVED UPSTREAM | ||
Severity: | enhancement | CC: | gentoo, hanno |
Priority: | High | ||
Version: | 1.3 | ||
Hardware: | All | ||
OS: | Linux | ||
Whiteboard: | |||
Package list: | Runtime testing required: | --- | |
Attachments: |
Patch to mii-tool.c to allow activation of interface based on media state
Patch to mii-tool (and man page) to add -a,--activate option init script to start and stop watching interfaces to activate Configuration file for /etc/init.d/netlinkactivate Modified ebuild to incorporate patches and init script net-tools.tar.gz: net-tools ebuilds (Updated) net-tools.tgz: (Updated to specify start/stop/pause) |
Description
Pat Double
2002-09-16 11:30:42 UTC
Created attachment 3957 [details, diff]
Patch to mii-tool.c to allow activation of interface based on media state
If you want an ebuild based on the latest net-tools ebuild, I'm willing to put that together as well and attached. hi Pat, have you sent this patch upstream as well? 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. 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. 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.... 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.
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.
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?
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.
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.
unexpectedly away; reassigning 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. 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!
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. 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. 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. |