summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2003-07-31 13:00:31 +0000
committerLennart Poettering <lennart@poettering.net>2003-07-31 13:00:31 +0000
commit86add5ad710adde499af6d08fe5479098dadaf29 (patch)
treec0358f501a174b66363c183f0b87540f5509b715
parentd2fd8fc1f819883d092b715b31d393295a9bc4e2 (diff)
moved to trunk
git-svn-id: file:///home/lennart/svn/public/ifplugd/trunk@26 2bf48fe7-cfc1-0310-909f-d9042e1e0fef
-rw-r--r--LICENSE340
-rw-r--r--Makefile.am35
-rwxr-xr-xbootstrap.sh39
-rw-r--r--conf/Makefile.am32
-rwxr-xr-xconf/ifplugd.action30
-rw-r--r--conf/ifplugd.conf34
-rwxr-xr-xconf/ifplugd.init.in108
-rw-r--r--configure.ac106
-rw-r--r--doc/Makefile.am36
-rw-r--r--doc/NEWS93
-rw-r--r--doc/README.html.in272
-rw-r--r--doc/SUPPORTED_DRIVERS23
-rw-r--r--doc/style.css10
-rw-r--r--ifplugd.spec.in67
-rw-r--r--man/Makefile.am36
-rw-r--r--man/ifplugd.8.xml.in275
-rw-r--r--man/ifplugd.conf.5.xml.in71
-rw-r--r--man/ifstatus.8.xml.in116
-rw-r--r--patches/8139too.c.0.9.26.patch13
-rw-r--r--patches/Makefile.am20
-rw-r--r--src/Makefile.am37
-rw-r--r--src/ethtool-kernel.h352
-rw-r--r--src/ethtool-local.h32
-rw-r--r--src/ifplugd.c792
-rw-r--r--src/ifstatus.c234
-rw-r--r--src/interface.c219
-rw-r--r--src/interface.h37
27 files changed, 3459 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d60c31a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..522d54e
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,35 @@
+# $Id: Makefile.am 22 2003-06-15 16:36:33Z lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+EXTRA_DIST=bootstrap.sh README LICENSE ifplugd.spec
+SUBDIRS=src man conf doc patches
+
+MAINTAINERCLEANFILES = README ifplugd.spec
+noinst_DATA = README ifplugd.spec
+
+README:
+ rm -f README
+ $(MAKE) -C doc README
+ ln -s doc/README README
+
+homepage:
+ test -d $$HOME/homepage/lennart
+ mkdir -p $$HOME/homepage/lennart/projects/ifplugd
+ cp *.tar.gz $$HOME/homepage/lennart/projects/ifplugd
+ cp doc/README.html doc/style.css doc/NEWS $$HOME/homepage/lennart/projects/ifplugd
+ cp $$HOME/homepage/lennart/projects/ifplugd/README.html $$HOME/homepage/lennart/projects/ifplugd/index.html
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100755
index 0000000..27dff71
--- /dev/null
+++ b/bootstrap.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# $Id: bootstrap.sh 20 2003-07-10 16:21:55Z lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+if [ "x$1" = "xam" ] ; then
+ set -ex
+ automake -a -c
+ ./config.status
+else
+ set -ex
+
+ make maintainer-clean || true
+
+ rm -rf autom4te.cache
+ rm -f config.cache
+
+ aclocal
+ autoheader
+ automake -a -c
+ autoconf -Wall
+
+ ./configure "$@"
+fi
+
diff --git a/conf/Makefile.am b/conf/Makefile.am
new file mode 100644
index 0000000..e873a24
--- /dev/null
+++ b/conf/Makefile.am
@@ -0,0 +1,32 @@
+# $Id: Makefile.am 22 2003-06-15 16:36:33Z lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+noinst_DATA = ifplugd.init ifplugd.action ifplugd.conf
+
+EXTRA_DIST = ifplugd.init.in ifplugd.action ifplugd.conf
+
+CLEANFILES = ifplugd.init
+
+ifplugd.init: ifplugd.init.in Makefile
+ sed -e 's,@sysconfdir\@,$(sysconfdir),g' -e 's,@sbindir\@,$(sbindir),g' $< > $@
+ chmod 755 $@
+
+install-data-local: ifplugd.init
+ $(INSTALL) -D -m755 ifplugd.init ${DESTDIR}/${sysconfdir}/init.d/ifplugd
+ $(INSTALL) -D -m755 ifplugd.action ${DESTDIR}/${sysconfdir}/ifplugd/ifplugd.action
+ $(INSTALL) -D -m644 ifplugd.conf ${DESTDIR}/${sysconfdir}/ifplugd/ifplugd.conf
diff --git a/conf/ifplugd.action b/conf/ifplugd.action
new file mode 100755
index 0000000..463fc0b
--- /dev/null
+++ b/conf/ifplugd.action
@@ -0,0 +1,30 @@
+#!/bin/sh
+# $Id: ifplugd.action 1.4 Wed, 23 Oct 2002 20:49:08 +0200 lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+set -e
+
+if [ -z "$1" ] || [ -z "$2" ] ; then
+ echo "Wrong arguments" > /dev/stderr
+ exit 1
+fi
+
+[ "$2" = "up" ] && exec /sbin/ifup $1
+[ "$2" = "down" ] && exec /sbin/ifdown $1
+
+exit 1
diff --git a/conf/ifplugd.conf b/conf/ifplugd.conf
new file mode 100644
index 0000000..0a48c37
--- /dev/null
+++ b/conf/ifplugd.conf
@@ -0,0 +1,34 @@
+# -*-sh-*-
+# $Id: ifplugd.conf 1.5 Wed, 13 Nov 2002 22:37:54 +0100 lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+# ifplugd configuration file
+
+# Specify the interfaces to control here, separated by spaces.
+# Ifplugd processes will be started for each of these interfaces
+# when the ifplugd init script is called with the "start" argument.
+# You may use the magic string "auto" to make the init script
+# start or stop ifplugd processes for ALL eth and wlan interfaces
+# that are available according to /proc/net/dev. Note that the
+# list of interfaces appearing in /proc/net/dev may depend on
+# which kernel modules you have loaded.
+INTERFACES="eth0"
+
+# Additional parameters for ifplugd.
+# (Run "ifplugd -h" for further information.)
+ARGS="-f -u0 -d10 -w -I"
diff --git a/conf/ifplugd.init.in b/conf/ifplugd.init.in
new file mode 100755
index 0000000..89ebdc6
--- /dev/null
+++ b/conf/ifplugd.init.in
@@ -0,0 +1,108 @@
+#!/bin/sh
+# $Id: ifplugd.init 1.6 Sat, 01 Feb 2003 03:00:07 +0100 lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+# ifplugd Brings up/down network automatically
+#
+# chkconfig: 2345 11 89
+# description: Brings networks interfaces up and down automatically when \
+# the cable is removed / inserted
+#
+# processname: @sbindir@/ifplugd
+# config: @sysconfdir@/ifplugd/ifplugd.conf
+
+### BEGIN INIT INFO
+# Provides: ifplugd
+# Required-Start: $network
+# X-UnitedLinux-Should-Start:
+# Required-Stop: $network
+# X-UnitedLinux-Should-Stop: $
+# Default-Start: 3 5
+# Default-Stop: 0 1 2 6
+# Short-Description: ifplugd daemon providing
+# Description: Start ifplugd to allow XY and provide YZ
+# continued on second line by '#<TAB>'
+# should contain enough info for the runlevel editor
+# to give admin some idea what this service does and
+# what it's needed for ...
+# (The Short-Description should already be a good hint.)
+### END INIT INFO
+
+CFG=@sysconfdir@/ifplugd/ifplugd.conf
+
+IFPLUGD=@sbindir@/ifplugd
+test -x $IFPLUGD || exit 0
+
+if [ `id -u` != "0" ] && [ "$1" = "start" -o "$1" = "stop" ] ; then
+ echo "You must be root to start, stop or restart ifplugd."
+ exit 1
+fi
+
+[ -f $CFG ] && . $CFG
+
+[ "$INTERFACES" = "auto" ] && INTERFACES=`cat /proc/net/dev | awk '{ print $1 }' | egrep '^(eth|wlan)' | cut -d: -f1`
+
+case "$1" in
+ start)
+ echo -n "Starting ethernet plugging daemon:"
+ for IF in $INTERFACES ; do
+ $IFPLUGD -i $IF $ARGS
+ echo -n " $IF"
+ done
+ echo "."
+ ;;
+ stop)
+ echo -n "Stopping ethernet plugging daemon:"
+ for IF in $INTERFACES ; do
+ $IFPLUGD -k -i $IF
+ echo -n " $IF"
+ done
+ echo "."
+ ;;
+ status)
+ for IF in $INTERFACES ; do
+ $IFPLUGD -c -i $IF
+ done
+ ;;
+ suspend)
+ echo -n "Suspending ethernet plugging daemon:"
+ for IF in $INTERFACES ; do
+ $IFPLUGD -S -i $IF
+ echo -n " $IF"
+ done
+ echo "."
+ ;;
+ resume)
+ echo -n "Resuming ethernet plugging daemon:"
+ for IF in $INTERFACES ; do
+ $IFPLUGD -R -i $IF
+ echo -n " $IF"
+ done
+ echo "."
+ ;;
+ force-reload|restart)
+ $0 stop
+ sleep 3
+ $0 start
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart|force-reload|status|suspend|resume}"
+ exit 1
+esac
+
+exit 0
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..cf41128
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,106 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+# $Id: Makefile.am 22 2003-06-15 16:36:33Z lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+AC_PREREQ(2.57)
+AC_INIT([ifplugd], [0.16], [mzvscyhtq@itaparica.org])
+AC_CONFIG_SRCDIR([src/ifplugd.c])
+AC_CONFIG_HEADERS([config.h])
+AM_INIT_AUTOMAKE([foreign -Wall])
+AM_MAINTAINER_MODE
+
+# Checks for programs.
+AC_PROG_CXX
+AC_PROG_CC
+
+# If using GCC specifiy some additional parameters
+if test "x$GCC" = "xyes" ; then
+ CFLAGS="$CFLAGS -pipe -Wall"
+fi
+
+AC_PROG_CPP
+AC_PROG_INSTALL
+AC_PROG_LN_S
+AC_PROG_MAKE_SET
+
+# Checks for libraries.
+AC_CHECK_LIB([daemon], [daemon_fork],, [AC_MSG_ERROR([*** Sorry, you have to install libdaemon ***])])
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_HEADER_SYS_WAIT
+AC_CHECK_HEADERS([fcntl.h limits.h netinet/in.h stdlib.h string.h sys/ioctl.h sys/time.h syslog.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_C_CONST
+AC_TYPE_PID_T
+AC_HEADER_TIME
+AC_C_VOLATILE
+
+# Checks for library functions.
+AC_FUNC_FORK
+AC_PROG_GCC_TRADITIONAL
+AC_FUNC_SELECT_ARGTYPES
+AC_FUNC_MALLOC
+AC_TYPE_SIGNAL
+AC_FUNC_VPRINTF
+AC_CHECK_FUNCS([alarm dup2 memset select setenv socket strchr strdup strerror strrchr])
+
+# LYNX documentation generation
+AC_ARG_ENABLE(lynx,
+ AC_HELP_STRING([--disable-lynx], [Turn off lynx usage for documentation generation]),
+[case "${enableval}" in
+ yes) lynx=yes ;;
+ no) lynx=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --disable-lynx) ;;
+esac],[lynx=yes])
+
+if test x$lynx = xyes ; then
+ AC_CHECK_PROG(have_lynx, lynx, yes, no)
+
+ if test x$have_lynx = xno ; then
+ AC_MSG_ERROR([*** Sorry, you have to install lynx or use --disable-lynx ***])
+ fi
+fi
+
+AM_CONDITIONAL([USE_LYNX], [test "x$lynx" = xyes])
+
+# XMLTOMAN manpage generation
+AC_ARG_ENABLE(xmltoman,
+ AC_HELP_STRING([--disable-xmltoman], [Disable rebuilding of man pages with xmltoman]),
+[case "${enableval}" in
+ yes) xmltoman=yes ;;
+ no) xmltoman=no ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --disable-xmltoman]) ;;
+esac],[xmltoman=yes])
+
+if test x$xmltoman = xyes ; then
+ AC_CHECK_PROG(have_xmltoman, xmltoman, yes, no)
+
+ if test x$have_xmltoman = xno ; then
+ AC_MSG_WARN([*** Not rebuilding man pages as xmltoman is not found ***])
+ xmltoman=no
+ fi
+fi
+
+AM_CONDITIONAL([USE_XMLTOMAN], [test "x$xmltoman" = xyes])
+
+AC_CONFIG_FILES([src/Makefile Makefile man/Makefile conf/Makefile doc/Makefile doc/README.html patches/Makefile ifplugd.spec])
+AC_OUTPUT
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644
index 0000000..e5fa91a
--- /dev/null
+++ b/doc/Makefile.am
@@ -0,0 +1,36 @@
+# $Id: Makefile.am 22 2003-06-15 16:36:33Z lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+noinst_DATA = README.html README
+EXTRA_DIST = $(noinst_DATA) style.css README.html.in SUPPORTED_HARDWARE
+
+MAINTAINERCLEANFILES = README README.html
+CLEANFILES =
+
+if USE_LYNX
+README: README.html
+ lynx --dump $^ | sed 's,file://localhost/.*/doc/README.html,README,' > $@
+
+CLEANFILES += README
+endif
+
+tidy: README.html
+ tidy -e < README.html
+
+.PHONY: tidy
+
diff --git a/doc/NEWS b/doc/NEWS
new file mode 100644
index 0000000..a3f4274
--- /dev/null
+++ b/doc/NEWS
@@ -0,0 +1,93 @@
+0.16 :: ... :: SVN ...
+ Spec file update
+ Build fixes
+
+0.15 :: 10. Jul 2003 :: SVN 16
+ umask fix
+ Documentation update
+
+0.14 :: 7. Jul 2003 :: SVN 9
+ Add WLAN support
+ Move to Autoconf
+ Add switch -F
+ Add suspend/resume
+ Modify logging
+ Depend on libdaemon
+
+0.13 :: 1. Feb 2003 :: PRCS 0.40
+ Add note about 3c59x on kernel 2.4.20 to SUPPORTED_DRIVERS
+ Add Suse/United Linux compatibility
+ Move Manpages from man/ to share/man/
+ Apply patch from Mandrake Linux regarding syslog, potential buffer overflow and more
+ Reduce stack usage
+ Remove -Werror from gcc command line
+ Small improvement to client program logging
+ Added option -c and adjustet init script accordingly
+
+0.12 :: 11. Jan 2003 :: PRCS 0.34
+ Fix to the specfile (thanks to Asgeir Nilsen)
+ chkonfig compatibility (the same)
+ RH6.2 compatibility (thanks to R. Steve McKown)
+ New option -x (as well)
+
+0.11 :: 24. Dec 2002 :: PRCS 0.25
+ added RPM specfile (thanks to Sean Reifschneider)
+ Extended SUPPORTED_DRIVERS
+
+0.10 :: 13. Nov 2002
+ Added the option -w
+ Portability fixes
+ Corrected daemonizing strategy
+ Removed PRCS residues from distribution
+
+0.9 :: 7. Nov 2002
+ Automatically remove all IP addresses from interface when doing "interface up" without -a
+ Add SUPPORTED_DRIVERS
+ Add patch for 8139too
+ Added trailing newline to version.h
+
+0.8 :: 25. Oct. 2002
+ Syslog spamming corrected
+ Makefile fixes
+ Manpage typos removed
+ Ignore-failure logic inverted, broken in 0.7
+
+0.7 :: 23. Oct. 2002
+ Introduced ifstatus
+ New manpages
+ Implemented support for SIOCPRIV
+ Fixed some bashisms and ashisms
+ Changed -m semantics
+ set -e in default action script
+ Created seperate module interface.c for link status detection functions
+ Documentation update
+ On request of Enrico Zini:
+ Environment variables are now exported to the action script
+ Network devices may be detected automatically
+
+0.6 :: 14. Oct. 2002
+ Documentation fixes
+ License fixes
+ Manpage added
+ New option -q
+
+0.5 :: n.n.
+ Workaround for kernel bug triggered by using tcpdump together with ifplugd
+
+0.4 :: n.n.
+ Link beat detection fixes
+
+0.3 :: n.n.
+ Link beat detection fixes
+ Syslog cleanup
+
+0.2 :: 30. Sept. 2002
+ New option -m
+ Command line parsing fixes
+ Documentation update
+ Installation script fixes
+
+0.1 :: 29. Sept. 2002
+ Initial version
+
+$Id: NEWS 1.23 Sat, 01 Feb 2003 03:03:31 +0100 lennart $
diff --git a/doc/README.html.in b/doc/README.html.in
new file mode 100644
index 0000000..dd0b778
--- /dev/null
+++ b/doc/README.html.in
@@ -0,0 +1,272 @@
+<?xml version="1.0" encoding="iso-8895-15"?> <!-- -*-html-helper-*- -->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+<title>ifplugd @PACKAGE_VERSION@</title>
+<link rel="stylesheet" type="text/css" href="style.css" />
+</head>
+
+<body>
+<h1><a name="top">ifplugd @PACKAGE_VERSION@</a></h1>
+
+<p><i>Copyright 2002,2003 Lennart Poettering &lt;mzvscyhtq [at] itaparica.org&gt;</i></p>
+
+<ul class="toc">
+ <li><a href="#license">License</a></li>
+ <li><a href="#news">News</a></li>
+ <li><a href="#overview">Overview</a></li>
+ <li><a href="#status">Status</a></li>
+ <li><a href="#documentation">Documentation</a></li>
+ <li><a href="#requirements">Requirements</a></li>
+ <li><a href="#installation">Installation</a></li>
+ <li><a href="#acks">Acknowledgements</a></li>
+ <li><a href="#download">Download</a></li>
+</ul>
+
+<h2><a name="license">License</a></h2>
+
+<p>This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.</p>
+
+<p>This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.</p>
+
+<p>You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</p>
+
+<h2><a name="news">News</a></h2>
+
+<div class="news-date">Thu July 10 2003: </div> <p class="news-text"><a
+href="http://www.stud.uni-hamburg.de/~lennart/projects/ifplugd/ifplugd-0.16.tar.gz">Version
+0.16</a> released, changes include: RPM spec file added, build fixes</p>
+
+<div class="news-date">Thu July 10 2003: </div> <p class="news-text"><a
+href="http://www.stud.uni-hamburg.de/~lennart/projects/ifplugd/ifplugd-0.15.tar.gz">Version
+0.15</a> released, changes include: bad umask fix, documentation update</p>
+
+<div class="news-date">Mon July 7 2003: </div> <p class="news-text"><a
+href="http://www.stud.uni-hamburg.de/~lennart/projects/ifplugd/ifplugd-0.14.tar.gz">Version
+0.14</a> released, changes include: autoconf usage, new dependency <a
+href="http://www.stud.uni-hamburg.de/~lennart/projects/libdaemon/"><tt>libdaemon</tt></a>, wireless LAN support, support for
+suspending/resuming, many fixes</p>
+
+<h2><a name="overview">Overview</a></h2>
+
+<p><tt>ifplugd</tt> is a Linux daemon which will automatically
+configure your ethernet device when a cable is plugged in and
+automatically unconfigure it if the cable is pulled. This is useful on
+laptops with onboard network adapters, since it will only configure
+the interface when a cable is really connected.
+
+<p><tt>ifplugd</tt> is a rather simplistic approach to this target since it relies
+on your distribution's native interface configuration system.</p>
+
+<p>Some features:</p>
+
+<ul>
+ <li>Uses your distribution's native <tt>ifup</tt>/<tt>ifdown</tt> programs.</li>
+
+ <li>May beep when the cable is unplugged, plugged, the interface
+ configuration succeeded or failed.</li>
+
+ <li>Supports the Linux <tt>SIOCETHTOOL</tt> (newer, aka <tt>ethtool</tt> API), <tt>SIOCGMIIREG</tt>
+ (older, aka <tt>mii-diag</tt>/<tt>mii-tool</tt> API) and SIOCDEVPRIVATE (oldest, aka
+ <tt>mii-tool</tt> API) <tt>ioctl()</tt>s for getting link status.</li>
+
+ <li>Syslog support</li>
+
+ <li>Simplistic C source code, just 19k binary (+11k for libdaemon)</li>
+
+ <li>Multiple ethernet interface support</li>
+
+ <li>May ignore short unplugged whiles (<tt>-d</tt> option) or plugged whiles (<tt>-u</tt>
+ option)</li>
+
+ <li>Support for wireless networking. Whenever an AP is detected the
+network is configured.</li>
+
+ <li>Compatibility mode for network devices which do not support cable detection (<tt>-F</tt> option)</li>
+</ul>
+
+<h2><a name="status">Status</a></h2>
+
+<p>Version 0.14 is stable and has all the sensible features its users could think of.</p>
+
+<h2><a name="documentation">Documentation</a></h2>
+
+<h3>Configuration</h3>
+
+<p>Edit <tt>/etc/ifplugd/ifplugd.conf</tt> for configuration
+changes. This file is a bourne shell script sourced by the init script
+and used to generate a suiting command line. You may specify more than
+one ethernet interface in <tt>INTERFACES</tt>. For each interface a
+seperate instance of <tt>ifplugd</tt> is spawned. The arguments specified in
+<tt>ARGS</tt> are append to <tt>ifplugd</tt>'s command line. Have a look on
+<tt>ifplugd -h</tt> or <tt>man ifplugd</tt> for further information
+about the available options.</p>
+
+<p>The network interface which is controlled by <tt>ifplugd</tt>
+should not be configured automatically by your distribution's network
+subsystem, since <tt>ifplugd</tt> will do this for you if needed. On
+Debian remove interface names beginning with <tt>eth</tt> or
+<tt>wlan</tt> from the <tt>auto</tt> option line in
+<tt>/etc/network/interfaces</tt>.</p>
+
+<h3>Troubleshooting</h3>
+
+<p>When you are using the hotplug subsystem (Debian package
+<tt>hotplug</tt>) you may notice that the network device is configured
+even when it is not listed on an <tt>auto</tt> line in
+<tt>/etc/network/interface</tt>. This may be due to <tt>hotplug</tt>
+being configured to <tt>ifup</tt> the network interface when it
+becomes available. This was the default behavior in the Debian
+<tt>hotplug</tt> package prior to release <tt>0.0.20030117-1</tt>, for
+example. To prevent this you should either upgrade your
+<tt>hotplug</tt> package or comment out the <tt>ifup</tt> call in
+<tt>/etc/hotplug/net.agent</tt>.</p>
+
+<p>When using <tt>ifplugd</tt> together with APM (and probably ACPI)
+suspends, strange things may happen: some network devices fail to
+detect the network cable for a short period of time before and after
+the suspend. When using the <tt>-f</tt> switch, this will be treated
+as "no link beat", thus the network is shutdown after a
+timeout. During this timeout the machine changes to suspended
+state. When it is resumed again, the timeout will be run out, the
+network is deconfigured, however, as the next cable detection
+succeeds, the network is configured again immediately. To fix this
+problem, <tt>ifplugd</tt> should be disabled before the APM suspend
+and enabled back after the suspend. This may be done by using
+<tt>apmd</tt> and adding a script to
+<tt>/etc/apm/{suspend,resume}.d</tt> which simply calls
+<tt>/etc/init.d/ifplugd suspend</tt>, resp. <tt>/etc/init.d/ifplugd
+resume</tt>. It might even be a good idea to shut down the network
+completely during suspend, this may be achieved by calling
+<tt>/etc/init.d/ifplugd stop</tt> and <tt>/etc/init.d/ifplugd
+start</tt> in the appropriate places. I strongly urge the packagers of
+this software for the Linux distributions to add such scripts to their
+packages.</p>
+
+<h3>FAQ</h3>
+
+<ol>
+ <li><p><b>Q:</b> I want to use <tt>ifplugd</tt> with my PCMCIA device, but <tt>ifplugd</tt> quits
+ when it doesn't find <tt>eth0</tt>, when I have not inserted the
+ card. What can I do?</p>
+
+ <p><b>A:</b> Use the <tt>-f</tt> switch. This is not very clean however,
+ since modprobe is called on each cable detection query of <tt>ifplugd</tt> to
+ load a module for the network device. This is suboptimal. You should
+ probably run <tt>ifplugd</tt> only when the card is really inserted.</p>
+ </li>
+
+ <li><p><b>Q:</b> I am using the <tt>-f</tt> switch, but the kernel logs are getting filled
+ with messages like "<tt>modprobe: modprobe: Can't locate module
+ eth0</tt>". What can I do?</p>
+
+ <p><b>A:</b> Make sure you have a line like <tt>alias eth0 off</tt> in your <tt>/etc/modules.conf</tt></p>
+ </li>
+
+ <li><p><b>Q:</b> When the cable is unplugged and the interface shut down it is
+ still available with <tt>ifconfig</tt> and markes as UP. Why this?</p>
+
+ <p><b>A:</b> <tt>ifplugd</tt> cannot detect the link beat with a shut down interface on
+ certain (most as of kernel 2.4.19) network drivers. Thus <tt>ifplugd</tt>
+ enables the interface before querying the link status. This may
+ be switched off with -a flag. You might want to use it if you
+ have a sane network driver (e.g. <tt>eepro100</tt>). The subdirectory
+ <tt>patches/</tt> in the <tt>ifplugd</tt> distribution includes a patch for the
+ 8139too 0.9.26 driver, which makes the driver compatible with
+ -a. Don't ask me how to apply this patch. If you don't know, you
+ won't need it.</p></li>
+
+ <li><p><b>Q:</b> Does it work with anything else than plain ethernet or wireless LAN?</p>
+
+ <p><b>A:</b> Certainly not, since the <tt>MII</tt> and
+<tt>ETHTOOL</tt> <tt>ioctl()</tt>s and the wireless extension don't
+exist on
+ other network device types.</p></li>
+
+ <li><p><b>Q:</b> I have a Realtek 8139 based network card. Everytime <tt>ifplugd</tt>
+ starts on bootup my machine freezes. What can I do?</p>
+
+ <p><b>A:</b> This is a bug in the <tt>8139too</tt> driver 0.9.25 (at least) shipped
+ with Linux 2.4.19, please upgrade to <tt>8139too</tt> 0.9.26 (Linux 2.4.20
+ or seperately at <a href="http://www.sourceforge.net/projects/gkernel/">http://www.sourceforge.net/projects/gkernel/</a>).</p></li>
+
+
+ <li><p><b>Q:</b> There are already <tt>laptop-net</tt>'s <tt>ifd</tt> and <tt>miid</tt>, why did you write
+ your own daemon?</p>
+
+ <p><b>A:</b> <tt>laptop-net</tt> simply sucks and I didn't know of <tt>miid</tt> when I wrote
+ <tt>ifplugd</tt>. However, <tt>ifplugd</tt> is far better than <tt>miid</tt>. For a
+ comparison of <tt>miid</tt> and <tt>ifplugd</tt>, have a look on
+
+ <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=162763&amp;repeatmerged=yes">http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=162763&amp;repeatmerged=yes</a></p></li>
+</ol>
+
+
+<h2><a name="requirements">Requirements</a></h2>
+
+<p>A newer Linux Kernel (I think 2.2 is good enough, alltough I tested it
+only with 2.4) with a compatible device driver and
+ethernet card. Most modern cards and drivers are compatible, like mine
+which works with the <tt>8139too</tt> driver.</p>
+
+<p><tt>ifplugd</tt> was developed and tested on Debian GNU/Linux
+"testing" from July 2003, it should work on most other Linux
+distributions (and maybe Unix versions) since it uses GNU autoconf and
+GNU libtool for source code configuration and shared library
+management.</p>
+
+<p>The machine used was a Medion 9580-F laptop with a Realtek 8139
+network card and a PRISM1 PCMCIA wireless LAN card.</p>
+
+<p><tt>ifplugd</tt> needs <a
+href="http://www.stud.uni-hamburg.de/~lennart/projects/libdaemon/"><tt>libdaemon</tt></a>.</p>
+
+<h2><a name="installation">Installation</a></h2>
+
+<p>As this package is made with the GNU autotools you should run
+<tt>./configure</tt> inside the distribution directory for configuring
+the source tree. After that you should run <tt>make</tt> for
+compilation and <tt>make install</tt> (as root) for installation of
+<tt>ifplugd</tt>.</p>
+
+<p>The installation scripts create an init script in
+<tt>${sysconfdir}/init.d/ifplugd</tt>, however no <tt>/etc/rc?.d/</tt> links are created
+for it.</p>
+
+<h2><a name="acks">Acknowledgements</a></h2>
+
+<p>For the developers of <tt>mii-diag</tt>, <tt>ethtool</tt> and <tt>laptop-net</tt>, since I looked
+on their source codes for learning how to use the link beat ioctls.</p>
+
+<p>Oliver Kurth for packaging <tt>ifplugd</tt> for Debian and <tt>ifplugd</tt>'s
+manpage</p>
+
+<p>Asgeir Nilsen, Sean Reifschneider, R. Steve McKown, David Mitchell for patches</p>
+
+<p>Frederic Lepied for integrating <tt>ifplugd</tt> into Mandrake Linux</p>
+
+<h2><a name="download">Download</a></h2>
+
+<p>The newest release is always available from <a href="http://www.stud.uni-hamburg.de/~lennart/projects/ifplugd/">http://www.stud.uni-hamburg.de/~lennart/projects/ifplugd/</a></p>
+
+<p>The current release is <a href="http://www.stud.uni-hamburg.de/~lennart/projects/ifplugd/ifplugd-@PACKAGE_VERSION@.tar.gz">@PACKAGE_VERSION@</a></p>
+
+<p>You may find a mostly up to date Debian package of <tt>ifplugd</tt> on the <a href="http://packages.debian.org/cgi-bin/search_packages.pl?keywords=ifplugd&amp;searchon=names&amp;subword=1&amp;version=all&amp;release=all">Debian package repository</a>.</p>
+
+<p>Packages for Mandrake Linux may be found in the Cooker distribution; Gentoo packages are available as well</p>
+
+<hr/>
+<address>Lennart Poettering &lt;mzvscyhtq [at] itaparica.org&gt;, July 2003</address>
+<div><i>$Id: README.html.in 9 2003-07-05 17:59:40Z lennart $</i></div>
+
+</body>
+</html>
diff --git a/doc/SUPPORTED_DRIVERS b/doc/SUPPORTED_DRIVERS
new file mode 100644
index 0000000..60c9c4b
--- /dev/null
+++ b/doc/SUPPORTED_DRIVERS
@@ -0,0 +1,23 @@
+The following list is a short summary of user experiences with certain
+network drivers.
+
+The version prefixed with k is the driver version of the specific
+kernel, the version prefixed with d is the driver version. Versions
+suffixed with p are patched with a patch supplied with ifplugd.
+
+Driver | Version | Support
+---------+----------------------+------------------------------------------------
+eepro100 | k2.4.19 | works fine, even with -a
+e100 | k2.4.20 | works fine, even with -a
+8139too | k2.4.19 | the machine may lock up, doesn't work with -a
+8139too | k2.4.20 or d0.9.26 | works, doesn't work with -a
+8139too | k2.4.20p or d0.9.26p | works, even with -a
+de4x5 | k2.4.18 | Fails completely
+tulip | k2.4.18 | works; does it work with -a???
+3c59x | k2.4.19 and .20 | Works, even with -a
+
+Please help me to extend this list and send me
+(mzvscyhtq [at] itaparica.org) more information about your
+experience with drivers not included in the list above yet.
+
+$Id: SUPPORTED_DRIVERS 1.4 Sat, 01 Feb 2003 02:36:25 +0100 lennart $
diff --git a/doc/style.css b/doc/style.css
new file mode 100644
index 0000000..71ccfe0
--- /dev/null
+++ b/doc/style.css
@@ -0,0 +1,10 @@
+/* $Id: style.css 8 2003-07-05 15:14:33Z lennart $ */
+body { color: black; background-color: white; margin: 0.5cm; }
+a:link, a:visited { color: #900000; }
+p { margin-left: 0.5cm; margin-right: 0.5cm; }
+div.news-date { margin-left: 0.5cm; font-size: 80%; color: #4f0000; }
+p.news-text { margin-left: 1cm; }
+ul { margin-left: 0.5cm; }
+h1 { color: #00009F; }
+h2 { color: #00009F; }
+h3 { color: #00004F; margin-left: 0.5cm; }
diff --git a/ifplugd.spec.in b/ifplugd.spec.in
new file mode 100644
index 0000000..848d49d
--- /dev/null
+++ b/ifplugd.spec.in
@@ -0,0 +1,67 @@
+%define debug_package %{nil}
+
+Summary: Detect and perform actions when an ethernet cable is (un)plugged.
+Name: ifplugd
+Version: @PACKAGE_VERSION@
+Release: 1
+Copyright: GPL
+Group: Networking/Daemons
+URL: http://www.stud.uni-hamburg.de/users/lennart/projects/ifplugd/
+Source: %{name}-%{version}.tar.gz
+Packager: Diego Santa Cruz <Diego.SantaCruz@epfl.ch>
+BuildRoot: %{_tmppath}/%{name}-%{version}-root
+BuildPrereq: libdaemon-devel
+
+%description
+ifplugd is a Linux daemon which will automatically configure your
+ethernet device when a cable is plugged in and automatically
+unconfigure it if the cable is pulled. This is useful on laptops with
+network adapters onboard , since it will only configure the interface
+when a cable is really connected.
+
+ifplugd is a rather simplistic approach to this target since it relies
+on your distribution's native interface configuration system.
+
+%prep
+%setup -q
+%build
+%configure
+make
+
+%install
+[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT"
+mkdir -p "$RPM_BUILD_ROOT"/usr/sbin
+make DESTDIR=$RPM_BUILD_ROOT PREFIX=%{prefix} install
+
+%clean
+[ -n "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != / ] && rm -rf "$RPM_BUILD_ROOT"
+
+%post
+/sbin/chkconfig --add ifplugd
+
+%preun
+/sbin/chkconfig --del ifplugd
+
+%files
+%defattr(755,root,root)
+%doc LICENSE README
+%doc doc/README.html doc/style.css
+%{_sbindir}/ifplugd
+%{_sbindir}/ifstatus
+%{_mandir}/man?/ifplugd*
+%{_mandir}/man?/ifstatus*
+%{_sysconfdir}/init.d/ifplugd
+%config %{_sysconfdir}/ifplugd/ifplugd.conf
+%config %{_sysconfdir}/ifplugd/ifplugd.action
+
+%changelog
+
+* Mon Jul 21 2003 Lennart Poettering 0.16
+- Modified slightly to be auto generated by autoconf
+
+* Wed Jul 16 2003 Diego Santa Cruz <Diego.SantaCruz@epfl.ch> 0.15
+- Updated to version 0.15
+- Make it depend on libdaemon
+
+* Thu Jan 9 2003 Asgeir Nilsen <rpmspec@asgeirnilsen.com> 0.11-2
+- Minor adjustments and init file patch
diff --git a/man/Makefile.am b/man/Makefile.am
new file mode 100644
index 0000000..1f18593
--- /dev/null
+++ b/man/Makefile.am
@@ -0,0 +1,36 @@
+# $Id: Makefile.am 22 2003-06-15 16:36:33Z lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+man_MANS = ifplugd.8 ifplugd.conf.5 ifstatus.8
+
+EXTRA_DIST = $(man_MANS) ifplugd.8.xml.in ifplugd.conf.5.xml.in ifstatus.8.xml.in
+
+if USE_XMLTOMAN
+
+CLEANFILES = $(man_MANS)
+
+ifplugd.8: ifplugd.8.xml.in Makefile
+ sed -e 's,@sysconfdir\@,$(sysconfdir),g' -e 's,@sbindir\@,$(sbindir),g' -e 's,@PACKAGE_BUGREPORT\@,$(PACKAGE_BUGREPORT),g' $< | xmltoman - > $@
+
+ifplugd.conf.5: ifplugd.conf.5.xml.in Makefile
+ sed -e 's,@sysconfdir\@,$(sysconfdir),g' -e 's,@sbindir\@,$(sbindir),g' -e 's,@PACKAGE_BUGREPORT\@,$(PACKAGE_BUGREPORT),g' $< | xmltoman - > $@
+
+ifstatus.8: ifstatus.8.xml.in Makefile
+ sed -e 's,@sysconfdir\@,$(sysconfdir),g' -e 's,@sbindir\@,$(sbindir),g' -e 's,@PACKAGE_BUGREPORT\@,$(PACKAGE_BUGREPORT),g' $< | xmltoman - > $@
+
+endif
diff --git a/man/ifplugd.8.xml.in b/man/ifplugd.8.xml.in
new file mode 100644
index 0000000..f252121
--- /dev/null
+++ b/man/ifplugd.8.xml.in
@@ -0,0 +1,275 @@
+<?xml version="1.0" standalone='no'?>
+<!DOCTYPE spec SYSTEM "man.dtd">
+
+<!-- $Id: ifplugd.8.xml 1.4 Sat, 01 Feb 2003 03:00:07 +0100 lennart $ -->
+
+<!--
+ This file is part of ifplugd.
+
+ ifplugd is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ ifplugd is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ifplugd; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+-->
+
+ <manpage name="ifplugd" section="8" desc="A link detection daemon for ethernet devices">
+
+ <synopsis>
+ <cmd>ifplugd [<arg>options</arg>]</cmd>
+ </synopsis>
+
+ <description>
+ <p>ifplugd is a daemon which will automatically configure your
+ ethernet device when a cable is plugged in and automatically
+ unconfigure it if the cable is pulled. This is useful on
+ laptops with on-board network adapters, since it will only
+ configure the interface when a cable is really connected.</p>
+
+ <p>It uses your distribution's native ifup/ifdown programs, but
+ can be configured to do anything you wish when the state of
+ the interface changes. It may ignore short unplugged whiles
+ (<opt>-d</opt> option) or plugged whiles (<opt>-u</opt>
+ option).</p>
+
+ <p>ifplugd may be used in "compatibility mode" by specifying -F
+ on the command line. Than ifplugd will treat network drivers
+ which do not support link beat querying as always online.</p>
+ </description>
+
+ <options>
+
+ <option>
+ <p><opt>-a | --no-auto</opt></p>
+ <optdesc><p>
+ Do not enable interface automatically (default: off)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-n | --no-daemon</opt></p>
+ <optdesc><p>
+ Do not daemonize (for debugging) (default: off)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-s | --no-syslog</opt></p>
+ <optdesc><p>
+ Do not use syslog, use stdout instead (for debugging) (default: off).
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-b | --no-beep</opt></p>
+ <optdesc><p>
+ Do not beep (off)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-f | --ignore-fail</opt></p>
+ <optdesc><p>
+ Ignore detection failure, retry instead. Failure is treated as "no link". (default: off)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-F | --ignore-fail-positive</opt></p>
+ <optdesc><p>
+ Ignore detection failure, retry instead. Failure is treated as "link detected". (default: off)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-i | --iface=</opt> <arg>IFACE</arg></p>
+ <optdesc><p>
+ Specify ethernet interface (default: eth0)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-r | --run=</opt> <arg>EXEC</arg></p>
+ <optdesc><p>
+ Specify program to execute when link status changes (default: <file>@sysconfdir@/ifplugd/ifplugd.action</file>)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-I | --ignore-retval</opt></p>
+ <optdesc><p>
+ Don't exit on nonzeor return value of program execute don link change. (default: off)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-t | --poll-time=</opt> <arg>SECS</arg></p>
+ <optdesc><p>
+ Specify poll time in seconds (default: 1)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-u | --delay-up=</opt> <arg>SECS</arg></p>
+ <optdesc><p>
+ Specify delay for configuring interface (default: 0)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-d | --delay-down=</opt> <arg>SECS</arg></p>
+ <optdesc><p>
+ Specify delay for deconfiguring interface (default: 5)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-m | --api-mode=</opt> <arg>MODE</arg></p> <optdesc><p>
+ Force a specific link beat detection ioctl() API. Possible
+ values are auto, wlan, ethtool, mii, and priv for automatic
+ detection, wireless extension, SIOCETHTOOL, SIOCGMIIREG
+ resp. SIOCPRIV. Only the first character of the argument is
+ relevant, case insensitive. (default: auto) </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-q | --no-shutdown</opt></p>
+ <optdesc><p>
+ Don't call the script for network shutdown on deamon quit (default: off)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-w | --wait-on-fork</opt></p>
+
+ <optdesc><p> When daemonizing, wait until the background
+ process finished with the initial link beat detection. When
+ this is enabled, the parent process will return the link
+ status on exit. 1 means link beat detected, 2 stands for link
+ beat not detected, everything else is an error.
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-x | --extra-arg=</opt> <arg>ARG</arg></p>
+ <optdesc><p>
+ Specify an extra argument to be passed to the action script.
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-h | --help</opt></p>
+ <optdesc><p>
+ Show help
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-k | --kill</opt></p>
+ <optdesc><p>
+ Kill a running daemon (Specify -i to select the daemon instance to kill)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-c | --check-running</opt></p>
+ <optdesc><p>
+ Check if a daemon is running for a given network interface. Sets the return value to 0 if a daemon is already running or to 255 if not.
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-v | --version</opt></p>
+ <optdesc><p>
+ Show version
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-S | --supend</opt></p> <optdesc><p> Suspend a running
+ daemon. The daemon will no longer check the link status until
+ it is resumed (-R) again. (Specify -i to select the daemon instance
+ to suspend.) </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-R | --resume</opt></p> <optdesc><p> Resume a suspended
+ daemon. (Specify -i to select the daemon instance
+ to resume.) </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-z | --info</opt></p> <optdesc><p>Request that a
+ running daemon shall write its status information to
+ syslog. (Specify -i to select the daemon instance to send the
+ request to.) </p></optdesc>
+ </option>
+
+ </options>
+
+ <section name="Files">
+
+ <p><file>@sysconfdir@/ifplugd/ifplugd.conf</file>: this file is sourced
+ by the init script <file>@sysconfdir@/init.d/ifplugd</file> and
+ contains the interface to be monitored and the options to be
+ used.</p>
+
+ <p><file>@sysconfdir@/ifplugd/ifplugd.action</file>: this is the script
+ which will be called by the daemon whenever the state of the
+ interface changes. It takes two areguments: the first is the interface
+ name (eg. eth0), the second either "up" or "down". </p>
+
+ <p><file>/var/run/ifplugd.&lt;iface&gt;.pid</file>: the pid file
+ for ifplugd.</p>
+
+ </section>
+
+ <section name="Environment">
+ <p>The action script will be called with two environment variables set:</p>
+
+ <p><arg>IFPLUGD_PREVIOUS</arg> The previous link status. Either
+ "up", "down", "error" or "disabled". The former values should be
+ obvious, the latter is set on daemon startup.</p>
+
+ <p><arg>IFPLUGD_CURRENT</arg> The current link status. See above
+ for possible values.</p>
+
+ </section>
+
+ <section name="Signals">
+ <p><arg>SIGINT, SIGTERM</arg> ifplugd will quit, possibly running the shutdown script. This is issued by passing -k to ifplugd.</p>
+ <p><arg>SIGQUIT</arg> ifplugd will quit, the shutdown script is never run.</p>
+ <p><arg>SIGHUP</arg> ifplugd will write its status information to syslog. This is issued by -z.</p>
+ <p><arg>SIGUSR1</arg> ifplugd will go to suspend mode. (-S)</p>
+ <p><arg>SIGUSR2</arg> ifplugd will resume from suspend mode. (-R)</p>
+ </section>
+
+ <section name="Author">
+ <p>ifplugd was written by Lennart Poettering
+ &lt;@PACKAGE_BUGREPORT@&gt;. ifplugd is available
+ at <url
+ href="http://www.stud.uni-hamburg.de/users/lennart/projects/ifplugd/"/>
+ </p>
+ </section>
+
+ <section name="See also">
+ <p>
+ <manref name="ifplugd.conf" section="5"/>, <manref name="ifup" section="8"/>, <manref name="interfaces"
+ section="5"/>, <manref name="ifconfig" section="8"/>
+ </p>
+ </section>
+
+ <section name="Comments">
+ <p>This man page was written using <manref name="xmltoman" section="1"
+ href="http://masqmail.cx/xml2man/"/> by Oliver Kurth.</p>
+ </section>
+
+ </manpage>
diff --git a/man/ifplugd.conf.5.xml.in b/man/ifplugd.conf.5.xml.in
new file mode 100644
index 0000000..8b580cd
--- /dev/null
+++ b/man/ifplugd.conf.5.xml.in
@@ -0,0 +1,71 @@
+<?xml version="1.0" standalone='no'?>
+<!DOCTYPE spec SYSTEM "man.dtd">
+
+<!-- $Id: ifplugd.conf.5.xml 1.2 Wed, 23 Oct 2002 20:49:08 +0200 lennart $ -->
+
+<!--
+ This file is part of ifplugd.
+
+ ifplugd is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ ifplugd is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ifplugd; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+-->
+
+ <manpage name="ifplugd.conf" section="5" desc="ifplugd configuration file">
+
+ <synopsis>
+ <cmd>@sysconfdir@/ifplugd/ifplugd.conf</cmd>
+ </synopsis>
+
+ <description>
+ <p>ifplugd.conf is the configuration file for ifplugd. It is a
+ shell script that is sourced by the init script starting
+ the daemon. It shall be used to set two environment variables which
+ are interpreted by the init script.</p>
+ </description>
+
+ <options>
+
+ <option>
+ <p><opt>INTERFACES</opt></p> <optdesc><p>Specifies the
+ ethernet interfaces to monitor. It has to contain a space
+ seperated list of network interfaces names. Most users will
+ probably use "eth0" here, however you may add additional
+ interfaces for monitoring more than one device. A special
+ value is supported as well: "auto" will enable a more or less
+ working auto detection of available network devices. This
+ won't make you happy when using network module auto loading,
+ since it cannot detect currently unloaded network
+ devices.</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>ARGS</opt></p> <optdesc><p>Additional command line
+ arguments for ifplugd invocation. See <manref name="ifplugd"
+ section="8"/> for further information.</p></optdesc>
+ </option>
+
+ </options>
+
+ <section name="See also">
+ <p>
+ <manref name="ifplugd" section="8"/>
+ </p>
+ </section>
+
+ <section name="Comments">
+ <p>This man page was written using <manref name="xmltoman" section="1"
+ href="http://masqmail.cx/xml2man/"/> by Oliver Kurth.</p>
+ </section>
+
+ </manpage>
diff --git a/man/ifstatus.8.xml.in b/man/ifstatus.8.xml.in
new file mode 100644
index 0000000..85bc127
--- /dev/null
+++ b/man/ifstatus.8.xml.in
@@ -0,0 +1,116 @@
+<?xml version="1.0" standalone='no'?>
+<!DOCTYPE spec SYSTEM "man.dtd">
+
+<!-- $Id: ifstatus.8.xml 1.3 Fri, 25 Oct 2002 21:12:38 +0200 lennart $ -->
+
+<!--
+ This file is part of ifplugd.
+
+ ifplugd is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ ifplugd is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ifplugd; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+-->
+
+ <manpage name="ifstatus" section="8" desc="A link beat detection tool">
+
+ <synopsis>
+ <cmd>ifstatus [<arg>options</arg>] [<arg>INTERFACE</arg>]</cmd>
+ </synopsis>
+
+ <description>
+ <p>ifstatus is an utility which may be used to detect the link
+ status of a local Linux ethernet device, much in the same way
+ mii-diag, mii-tool and ethtool work. In fact it supports all
+ three different APIs these three tools use. Thus, it provides
+ maximal compatibility. The newest API (ethtool) is used first,
+ than the next older (mii-diag) and at last the oldest
+ (mii-tool). It may be used in shell script since it returns the
+ current status as return value. It is especially useful to
+ detect the available APIs on the used network driver. (Option
+ <opt>-v</opt>)</p>
+ </description>
+
+ <options>
+
+ <p>You may speicify an ethernet device on the command
+ line. Otherwise ifstatus will check for eth0..eth9
+ automatically.</p>
+
+ <option>
+ <p><opt>-a | --auto</opt></p>
+ <optdesc><p>
+ Enable interface automatically before querying (default: off)
+ </p></optdesc>
+ </option>
+
+
+ <option>
+ <p><opt>-h | --help</opt></p>
+ <optdesc><p>
+ Show help
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-q | --quiet</opt></p> <optdesc><p>Decrease verbosity
+ by one. If the verbosity is &lt; 0, no text will be shown,
+ only the return value is relevant; if the verbosity is = 0, a
+ terse status will be shown; If the verbosity is &gt; 0,
+ detailed information about the used API is returned. (By
+ default the verbosity is 0)</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-v | --verbose</opt></p>
+ <optdesc><p>
+ Increase verbosity by one. See option <opt>-q</opt>.
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-V | --version</opt></p>
+ <optdesc><p>
+ Show version
+ </p></optdesc>
+ </option>
+
+ </options>
+
+ <section name="Return values">
+ <p><arg>0</arg> Success</p>
+ <p><arg>1</arg> Failure</p>
+ <p><arg>2</arg> Link beat detected (only available when an interface is specified)</p>
+ <p><arg>3</arg> Unplugged (same here)</p>
+ </section>
+
+ <section name="Author">
+ <p>ifplugd was written by Lennart Poettering
+ &lt;@PACKAGE_BUGREPORT@&gt;. ifplugd is available
+ at <url
+ href="http://www.stud.uni-hamburg.de/users/lennart/projects/ifplugd/"/>
+ </p>
+ </section>
+
+ <section name="See also">
+ <p>
+ <manref name="mii-diag" section="8"/>, <manref name="mii-tool"
+ section="8"/>, <manref name="ethtool" section="8"/>
+ </p>
+ </section>
+
+ <section name="Comments">
+ <p>This man page was written using <manref name="xml2man" section="1"
+ href="http://masqmail.cx/xml2man/"/> by Oliver Kurth.</p>
+ </section>
+
+ </manpage>
diff --git a/patches/8139too.c.0.9.26.patch b/patches/8139too.c.0.9.26.patch
new file mode 100644
index 0000000..3979a33
--- /dev/null
+++ b/patches/8139too.c.0.9.26.patch
@@ -0,0 +1,13 @@
+--- 8139too.c.dist Thu Oct 31 23:45:04 2002
++++ 8139too.c Thu Oct 31 23:45:46 2002
+@@ -2449,8 +2449,8 @@
+ int rc = 0;
+ int phy = tp->phys[0] & 0x3f;
+
+- if (!netif_running(dev))
+- return -EINVAL;
++// if (!netif_running(dev))
++// return -EINVAL;
+
+ if (cmd != SIOCETHTOOL) {
+ /* With SIOCETHTOOL, this would corrupt the pointer. */
diff --git a/patches/Makefile.am b/patches/Makefile.am
new file mode 100644
index 0000000..0650e7a
--- /dev/null
+++ b/patches/Makefile.am
@@ -0,0 +1,20 @@
+# $Id: Makefile.am 22 2003-06-15 16:36:33Z lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+EXTRA_DIST = 8139too.c.0.9.26.patch
+
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..cd2d344
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,37 @@
+# $Id: Makefile.am 22 2003-06-15 16:36:33Z lennart $
+
+# This file is part of ifplugd.
+#
+# ifplugd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifplugd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifplugd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+AM_CFLAGS = -DSYSCONFDIR="\"$(sysconfdir)\""
+
+sbin_PROGRAMS = ifplugd ifstatus
+ifplugd_SOURCES = ifplugd.c interface.c interface.h ethtool-kernel.h ethtool-local.h svn-revision.h
+ifstatus_SOURCES = ifstatus.c interface.c interface.h ethtool-kernel.h ethtool-local.h svn-revision.h
+
+MAINTAINERCLEANFILES = svn-revision.h
+
+ifplugd.o: svn-revision.h
+ifstatus.o: svn-revision.h
+
+svn-revision.h: Makefile
+ if test -d "$(top_srcdir)/.svn" ; then \
+ if REV=`svn info "$(top_srcdir)" | grep ^Revision | cut -f2 -d" "` 2> /dev/null ; then \
+ echo -e "#ifndef foosvnrevisionhfoo\n#define foosvnrevisionhfoo\n#define SVN_REVISION \"$$REV\"\n#endif" > $@ ; \
+ fi \
+ else \
+ test -f $@ || touch $@ ; \
+ fi
diff --git a/src/ethtool-kernel.h b/src/ethtool-kernel.h
new file mode 100644
index 0000000..a4af66c
--- /dev/null
+++ b/src/ethtool-kernel.h
@@ -0,0 +1,352 @@
+/*
+ * ethtool.h: Defines for Linux ethtool.
+ *
+ * Copyright (C) 1998 David S. Miller (davem@redhat.com)
+ * Copyright 2001 Jeff Garzik <jgarzik@mandrakesoft.com>
+ * Portions Copyright 2001 Sun Microsystems (thockin@sun.com)
+ * Portions Copyright 2002 Intel (eli.kupermann@intel.com,
+ * christopher.leech@intel.com,
+ * scott.feldman@intel.com)
+ */
+
+#ifndef _LINUX_ETHTOOL_H
+#define _LINUX_ETHTOOL_H
+
+
+/* This should work for both 32 and 64 bit userland. */
+struct ethtool_cmd {
+ u32 cmd;
+ u32 supported; /* Features this interface supports */
+ u32 advertising; /* Features this interface advertises */
+ u16 speed; /* The forced speed, 10Mb, 100Mb, gigabit */
+ u8 duplex; /* Duplex, half or full */
+ u8 port; /* Which connector port */
+ u8 phy_address;
+ u8 transceiver; /* Which tranceiver to use */
+ u8 autoneg; /* Enable or disable autonegotiation */
+ u32 maxtxpkt; /* Tx pkts before generating tx int */
+ u32 maxrxpkt; /* Rx pkts before generating rx int */
+ u32 reserved[4];
+};
+
+#define ETHTOOL_BUSINFO_LEN 32
+/* these strings are set to whatever the driver author decides... */
+struct ethtool_drvinfo {
+ u32 cmd;
+ char driver[32]; /* driver short name, "tulip", "eepro100" */
+ char version[32]; /* driver version string */
+ char fw_version[32]; /* firmware version string, if applicable */
+ char bus_info[ETHTOOL_BUSINFO_LEN]; /* Bus info for this IF. */
+ /* For PCI devices, use pci_dev->slot_name. */
+ char reserved1[32];
+ char reserved2[20];
+ u32 testinfo_len;
+ u32 eedump_len; /* Size of data from ETHTOOL_GEEPROM (bytes) */
+ u32 regdump_len; /* Size of data from ETHTOOL_GREGS (bytes) */
+};
+
+#define SOPASS_MAX 6
+/* wake-on-lan settings */
+struct ethtool_wolinfo {
+ u32 cmd;
+ u32 supported;
+ u32 wolopts;
+ u8 sopass[SOPASS_MAX]; /* SecureOn(tm) password */
+};
+
+/* for passing single values */
+struct ethtool_value {
+ u32 cmd;
+ u32 data;
+};
+
+/* for passing big chunks of data */
+struct ethtool_regs {
+ u32 cmd;
+ u32 version; /* driver-specific, indicates different chips/revs */
+ u32 len; /* bytes */
+ u8 data[0];
+};
+
+/* for passing EEPROM chunks */
+struct ethtool_eeprom {
+ u32 cmd;
+ u32 magic;
+ u32 offset; /* in bytes */
+ u32 len; /* in bytes */
+ u8 data[0];
+};
+
+/* for configuring coalescing parameters of chip */
+struct ethtool_coalesce {
+ u32 cmd; /* ETHTOOL_{G,S}COALESCE */
+
+ /* How many usecs to delay an RX interrupt after
+ * a packet arrives. If 0, only rx_max_coalesced_frames
+ * is used.
+ */
+ u32 rx_coalesce_usecs;
+
+ /* How many packets to delay an RX interrupt after
+ * a packet arrives. If 0, only rx_coalesce_usecs is
+ * used. It is illegal to set both usecs and max frames
+ * to zero as this would cause RX interrupts to never be
+ * generated.
+ */
+ u32 rx_max_coalesced_frames;
+
+ /* Same as above two parameters, except that these values
+ * apply while an IRQ is being services by the host. Not
+ * all cards support this feature and the values are ignored
+ * in that case.
+ */
+ u32 rx_coalesce_usecs_irq;
+ u32 rx_max_coalesced_frames_irq;
+
+ /* How many usecs to delay a TX interrupt after
+ * a packet is sent. If 0, only tx_max_coalesced_frames
+ * is used.
+ */
+ u32 tx_coalesce_usecs;
+
+ /* How many packets to delay a TX interrupt after
+ * a packet is sent. If 0, only tx_coalesce_usecs is
+ * used. It is illegal to set both usecs and max frames
+ * to zero as this would cause TX interrupts to never be
+ * generated.
+ */
+ u32 tx_max_coalesced_frames;
+
+ /* Same as above two parameters, except that these values
+ * apply while an IRQ is being services by the host. Not
+ * all cards support this feature and the values are ignored
+ * in that case.
+ */
+ u32 tx_coalesce_usecs_irq;
+ u32 tx_max_coalesced_frames_irq;
+
+ /* How many usecs to delay in-memory statistics
+ * block updates. Some drivers do not have an in-memory
+ * statistic block, and in such cases this value is ignored.
+ * This value must not be zero.
+ */
+ u32 stats_block_coalesce_usecs;
+
+ /* Adaptive RX/TX coalescing is an algorithm implemented by
+ * some drivers to improve latency under low packet rates and
+ * improve throughput under high packet rates. Some drivers
+ * only implement one of RX or TX adaptive coalescing. Anything
+ * not implemented by the driver causes these values to be
+ * silently ignored.
+ */
+ u32 use_adaptive_rx_coalesce;
+ u32 use_adaptive_tx_coalesce;
+
+ /* When the packet rate (measured in packets per second)
+ * is below pkt_rate_low, the {rx,tx}_*_low parameters are
+ * used.
+ */
+ u32 pkt_rate_low;
+ u32 rx_coalesce_usecs_low;
+ u32 rx_max_coalesced_frames_low;
+ u32 tx_coalesce_usecs_low;
+ u32 tx_max_coalesced_frames_low;
+
+ /* When the packet rate is below pkt_rate_high but above
+ * pkt_rate_low (both measured in packets per second) the
+ * normal {rx,tx}_* coalescing parameters are used.
+ */
+
+ /* When the packet rate is (measured in packets per second)
+ * is above pkt_rate_high, the {rx,tx}_*_high parameters are
+ * used.
+ */
+ u32 pkt_rate_high;
+ u32 rx_coalesce_usecs_high;
+ u32 rx_max_coalesced_frames_high;
+ u32 tx_coalesce_usecs_high;
+ u32 tx_max_coalesced_frames_high;
+
+ /* How often to do adaptive coalescing packet rate sampling,
+ * measured in seconds. Must not be zero.
+ */
+ u32 rate_sample_interval;
+};
+
+/* for configuring RX/TX ring parameters */
+struct ethtool_ringparam {
+ u32 cmd; /* ETHTOOL_{G,S}RINGPARAM */
+
+ /* Read only attributes. These indicate the maximum number
+ * of pending RX/TX ring entries the driver will allow the
+ * user to set.
+ */
+ u32 rx_max_pending;
+ u32 rx_mini_max_pending;
+ u32 rx_jumbo_max_pending;
+ u32 tx_max_pending;
+
+ /* Values changeable by the user. The valid values are
+ * in the range 1 to the "*_max_pending" counterpart above.
+ */
+ u32 rx_pending;
+ u32 rx_mini_pending;
+ u32 rx_jumbo_pending;
+ u32 tx_pending;
+};
+
+/* for configuring link flow control parameters */
+struct ethtool_pauseparam {
+ u32 cmd; /* ETHTOOL_{G,S}PAUSEPARAM */
+
+ /* If the link is being auto-negotiated (via ethtool_cmd.autoneg
+ * being true) the user may set 'autonet' here non-zero to have the
+ * pause parameters be auto-negotiated too. In such a case, the
+ * {rx,tx}_pause values below determine what capabilities are
+ * advertised.
+ *
+ * If 'autoneg' is zero or the link is not being auto-negotiated,
+ * then {rx,tx}_pause force the driver to use/not-use pause
+ * flow control.
+ */
+ u32 autoneg;
+ u32 rx_pause;
+ u32 tx_pause;
+};
+
+#define ETH_GSTRING_LEN 32
+enum ethtool_stringset {
+ ETH_SS_TEST = 0,
+ ETH_SS_STATS,
+};
+
+/* for passing string sets for data tagging */
+struct ethtool_gstrings {
+ u32 cmd; /* ETHTOOL_GSTRINGS */
+ u32 string_set; /* string set id e.c. ETH_SS_TEST, etc*/
+ u32 len; /* number of strings in the string set */
+ u8 data[0];
+};
+
+enum ethtool_test_flags {
+ ETH_TEST_FL_OFFLINE = (1 << 0), /* online / offline */
+ ETH_TEST_FL_FAILED = (1 << 1), /* test passed / failed */
+};
+
+/* for requesting NIC test and getting results*/
+struct ethtool_test {
+ u32 cmd; /* ETHTOOL_TEST */
+ u32 flags; /* ETH_TEST_FL_xxx */
+ u32 reserved;
+ u32 len; /* result length, in number of u64 elements */
+ u64 data[0];
+};
+
+/* CMDs currently supported */
+#define ETHTOOL_GSET 0x00000001 /* Get settings. */
+#define ETHTOOL_SSET 0x00000002 /* Set settings, privileged. */
+#define ETHTOOL_GDRVINFO 0x00000003 /* Get driver info. */
+#define ETHTOOL_GREGS 0x00000004 /* Get NIC registers, privileged. */
+#define ETHTOOL_GWOL 0x00000005 /* Get wake-on-lan options. */
+#define ETHTOOL_SWOL 0x00000006 /* Set wake-on-lan options, priv. */
+#define ETHTOOL_GMSGLVL 0x00000007 /* Get driver message level */
+#define ETHTOOL_SMSGLVL 0x00000008 /* Set driver msg level, priv. */
+#define ETHTOOL_NWAY_RST 0x00000009 /* Restart autonegotiation, priv. */
+#define ETHTOOL_GLINK 0x0000000a /* Get link status (ethtool_value) */
+#define ETHTOOL_GEEPROM 0x0000000b /* Get EEPROM data */
+#define ETHTOOL_SEEPROM 0x0000000c /* Set EEPROM data, priv. */
+#define ETHTOOL_GCOALESCE 0x0000000e /* Get coalesce config */
+#define ETHTOOL_SCOALESCE 0x0000000f /* Set coalesce config, priv. */
+#define ETHTOOL_GRINGPARAM 0x00000010 /* Get ring parameters */
+#define ETHTOOL_SRINGPARAM 0x00000011 /* Set ring parameters, priv. */
+#define ETHTOOL_GPAUSEPARAM 0x00000012 /* Get pause parameters */
+#define ETHTOOL_SPAUSEPARAM 0x00000013 /* Set pause parameters, priv. */
+#define ETHTOOL_GRXCSUM 0x00000014 /* Get RX hw csum enable (ethtool_value) */
+#define ETHTOOL_SRXCSUM 0x00000015 /* Set RX hw csum enable (ethtool_value) */
+#define ETHTOOL_GTXCSUM 0x00000016 /* Get TX hw csum enable (ethtool_value) */
+#define ETHTOOL_STXCSUM 0x00000017 /* Set TX hw csum enable (ethtool_value) */
+#define ETHTOOL_GSG 0x00000018 /* Get scatter-gather enable
+ * (ethtool_value) */
+#define ETHTOOL_SSG 0x00000019 /* Set scatter-gather enable
+ * (ethtool_value), priv. */
+#define ETHTOOL_TEST 0x0000001a /* execute NIC self-test, priv. */
+#define ETHTOOL_GSTRINGS 0x0000001b /* get specified string set */
+#define ETHTOOL_PHYS_ID 0x0000001c /* identify the NIC */
+
+/* compatibility with older code */
+#define SPARC_ETH_GSET ETHTOOL_GSET
+#define SPARC_ETH_SSET ETHTOOL_SSET
+
+/* Indicates what features are supported by the interface. */
+#define SUPPORTED_10baseT_Half (1 << 0)
+#define SUPPORTED_10baseT_Full (1 << 1)
+#define SUPPORTED_100baseT_Half (1 << 2)
+#define SUPPORTED_100baseT_Full (1 << 3)
+#define SUPPORTED_1000baseT_Half (1 << 4)
+#define SUPPORTED_1000baseT_Full (1 << 5)
+#define SUPPORTED_Autoneg (1 << 6)
+#define SUPPORTED_TP (1 << 7)
+#define SUPPORTED_AUI (1 << 8)
+#define SUPPORTED_MII (1 << 9)
+#define SUPPORTED_FIBRE (1 << 10)
+#define SUPPORTED_BNC (1 << 11)
+
+/* Indicates what features are advertised by the interface. */
+#define ADVERTISED_10baseT_Half (1 << 0)
+#define ADVERTISED_10baseT_Full (1 << 1)
+#define ADVERTISED_100baseT_Half (1 << 2)
+#define ADVERTISED_100baseT_Full (1 << 3)
+#define ADVERTISED_1000baseT_Half (1 << 4)
+#define ADVERTISED_1000baseT_Full (1 << 5)
+#define ADVERTISED_Autoneg (1 << 6)
+#define ADVERTISED_TP (1 << 7)
+#define ADVERTISED_AUI (1 << 8)
+#define ADVERTISED_MII (1 << 9)
+#define ADVERTISED_FIBRE (1 << 10)
+#define ADVERTISED_BNC (1 << 11)
+
+/* The following are all involved in forcing a particular link
+ * mode for the device for setting things. When getting the
+ * devices settings, these indicate the current mode and whether
+ * it was foced up into this mode or autonegotiated.
+ */
+
+/* The forced speed, 10Mb, 100Mb, gigabit. */
+#define SPEED_10 10
+#define SPEED_100 100
+#define SPEED_1000 1000
+
+/* Duplex, half or full. */
+#define DUPLEX_HALF 0x00
+#define DUPLEX_FULL 0x01
+
+/* Which connector port. */
+#define PORT_TP 0x00
+#define PORT_AUI 0x01
+#define PORT_MII 0x02
+#define PORT_FIBRE 0x03
+#define PORT_BNC 0x04
+
+/* Which tranceiver to use. */
+#define XCVR_INTERNAL 0x00
+#define XCVR_EXTERNAL 0x01
+#define XCVR_DUMMY1 0x02
+#define XCVR_DUMMY2 0x03
+#define XCVR_DUMMY3 0x04
+
+/* Enable or disable autonegotiation. If this is set to enable,
+ * the forced link modes above are completely ignored.
+ */
+#define AUTONEG_DISABLE 0x00
+#define AUTONEG_ENABLE 0x01
+
+/* Wake-On-Lan options. */
+#define WAKE_PHY (1 << 0)
+#define WAKE_UCAST (1 << 1)
+#define WAKE_MCAST (1 << 2)
+#define WAKE_BCAST (1 << 3)
+#define WAKE_ARP (1 << 4)
+#define WAKE_MAGIC (1 << 5)
+#define WAKE_MAGICSECURE (1 << 6) /* only meaningful if WAKE_MAGIC */
+
+#endif /* _LINUX_ETHTOOL_H */
diff --git a/src/ethtool-local.h b/src/ethtool-local.h
new file mode 100644
index 0000000..19a1cf9
--- /dev/null
+++ b/src/ethtool-local.h
@@ -0,0 +1,32 @@
+#ifndef fooethtoollocalhfoo
+#define fooethtoollocalhfoo
+
+/* $Id: ethtool-local.h 1.2 Wed, 23 Oct 2002 20:49:08 +0200 lennart $ */
+
+/*
+ * This file is part of ifplugd.
+ *
+ * ifplugd is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ifplugd is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with ifplugd; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+typedef unsigned long long u64;
+typedef __uint32_t u32;
+typedef __uint16_t u16;
+typedef __uint8_t u8;
+
+#include "ethtool-kernel.h"
+
+#endif
+
diff --git a/src/ifplugd.c b/src/ifplugd.c
new file mode 100644
index 0000000..9445383
--- /dev/null
+++ b/src/ifplugd.c
@@ -0,0 +1,792 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* $Id: ifplugd.c 1.12 Sat, 01 Feb 2003 03:00:07 +0100 lennart $ */
+
+/*
+ * This file is part of ifplugd.
+ *
+ * ifplugd is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ifplugd is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with ifplugd; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <getopt.h>
+#include <stdarg.h>
+#include <syslog.h>
+#include <fcntl.h>
+#include <linux/kd.h>
+#include <sys/ioctl.h>
+#include <limits.h>
+#include <net/if.h>
+#include <linux/sockios.h>
+#include <sys/types.h>
+#include <ctype.h>
+#include <sys/time.h>
+#include <time.h>
+
+#include <libdaemon/dlog.h>
+#include <libdaemon/dpid.h>
+#include <libdaemon/dsignal.h>
+#include <libdaemon/dfork.h>
+
+#include "ethtool-local.h"
+#include "interface.h"
+#include "svn-revision.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define VARRUN "/var/run"
+#define IFPLUGD_ENV_PREVIOUS "IFPLUGD_PREVIOUS"
+#define IFPLUGD_ENV_CURRENT "IFPLUGD_CURRENT"
+
+int interface_auto_up = 1, interface_do_message = 1;
+
+char *interface = "eth0";
+char *run = SYSCONFDIR"/ifplugd/ifplugd.action";
+char *extra_arg = NULL;
+int polltime = 1, delay_up = 0, delay_down = 5;
+int daemonize = 1, use_beep = 1, no_shutdown_script = 0, wait_on_fork = 0, use_syslog = 1, ignore_retval = 0, initial_down = 0;
+interface_status_t failure_status = IFSTATUS_ERR;
+
+enum { API_AUTO, API_ETHTOOL, API_MII, API_PRIVATE, API_WLAN } api_mode = API_AUTO;
+interface_status_t (*detect_beat_func)(int, char*);
+
+// 0: high, 1: low, 2: very low
+void beep(int b) {
+ int fd = -1, argp;
+
+ if (!use_beep)
+ return;
+
+ if ((fd = open("/dev/tty1", O_WRONLY)) < 0) {
+ use_beep = 0;
+ daemon_log(LOG_WARNING, "Could not open /dev/tty, cannot beep.");
+ goto finish;
+ }
+
+ switch (b) {
+ case 0: argp = (100<<16) + 0x637; break;
+ case 1: argp = (100<<16) + 0x937; break;
+ default: argp = (100<<16) + 0x1237; break;
+ }
+
+ if (ioctl(fd, KDMKTONE, argp) != 0) {
+ use_beep = 0;
+ daemon_log(LOG_WARNING, "Beep failure, disabled.");
+ goto finish;
+ }
+
+ usleep((argp >> 16)*1000);
+
+finish:
+
+ if (fd >= 0)
+ close(fd);
+
+ return;
+}
+
+const char *pid_file_proc() {
+ static char fn[PATH_MAX];
+ snprintf(fn, sizeof(fn), "%s/ifplugd.%s.pid", VARRUN, interface);
+ return fn;
+}
+
+int action(interface_status_t status) {
+ pid_t pid;
+ int _pipe[2];
+ unsigned n = 0;
+ static char buf[256];
+ char *arg = (status == IFSTATUS_UP ? "up" : "down");
+ int sigfd, r;
+ fd_set rfds;
+
+ daemon_log(LOG_INFO, "Executing '%s %s %s'.", run, interface, arg);
+
+ if (pipe(_pipe) < 0) {
+ daemon_log(LOG_ERR, "pipe() failed: %s", strerror(errno));
+ return -1;
+ }
+
+ if ((pid = fork()) < 0) {
+ daemon_log(LOG_ERR, "fork() failed: %s", strerror(errno));
+ return -1;
+
+ } else if (pid == 0) {
+ dup2(_pipe[1], 1);
+ dup2(_pipe[1], 2);
+
+ if (_pipe[0] > 2)
+ close(_pipe[0]);
+
+ if (_pipe[1] > 2)
+ close(_pipe[1]);
+
+ umask(0022); // Set up a sane umask
+
+ execl(run, run, interface, arg, extra_arg, 0);
+
+ _exit(EXIT_FAILURE);
+ }
+
+ close(_pipe[1]);
+
+ FD_ZERO(&rfds);
+ FD_SET(_pipe[0], &rfds);
+ FD_SET(sigfd = daemon_signal_fd(), &rfds);
+
+ n = 0;
+
+ for (;;) {
+ fd_set wrfds = rfds;
+
+ if (select(FD_SETSIZE, &wrfds, NULL, NULL, NULL) < 0) {
+
+ if (errno == EINTR)
+ continue;
+
+ break;
+ }
+
+
+ if (FD_ISSET(_pipe[0], &wrfds)) {
+ char c;
+
+ if (read(_pipe[0], &c, 1) != 1)
+ break;
+
+ buf[n] = c;
+
+ if (c == '\n' || n >= sizeof(buf) - 2) {
+ if (c != '\n') n++;
+ buf[n] = 0;
+
+ if (buf[0])
+ daemon_log(LOG_WARNING, "client: %s", buf);
+
+ n = 0;
+ } else
+ n++;
+ }
+
+ if (FD_ISSET(sigfd, &wrfds)) {
+ int sig;
+
+ if ((sig = daemon_signal_next()) < 0) {
+ daemon_log(LOG_ERR, "daemon_signal_next(): %s", strerror(errno));
+ break;
+ }
+
+ if (sig != SIGCHLD) {
+ daemon_log(LOG_WARNING, "Killing child.");
+ kill(pid, SIGTERM);
+ }
+
+ break;
+ }
+
+ }
+
+ if (n > 0) {
+ buf[n] = 0;
+ daemon_log(LOG_WARNING, "client: %s", buf);
+ }
+
+ waitpid(pid, &r, 0);
+
+ close(_pipe[0]);
+
+ if (!WIFEXITED(r) || WEXITSTATUS(r) != 0) {
+ if (status == IFSTATUS_UP)
+ beep(2);
+ daemon_log(LOG_ERR, "Program execution failed, return value is %i.", WEXITSTATUS(r));
+
+ return ignore_retval ? 0 : -1;
+ } else {
+ if (status == IFSTATUS_UP)
+ beep(0);
+
+ daemon_log(LOG_INFO, "Program executed successfully.");
+ return 0;
+ }
+}
+
+interface_status_t detect_beat_auto(int fd, char *iface) {
+ interface_status_t status;
+ static interface_status_t (*cached_func)(int, char*) = NULL;
+
+ if (cached_func && (status = cached_func(fd, iface)) != IFSTATUS_ERR)
+ return status;
+
+ if ((status = interface_detect_beat_mii(fd, iface)) != IFSTATUS_ERR) {
+ cached_func = interface_detect_beat_mii;
+ daemon_log(LOG_INFO, "Using detection mode: SIOCGMIIPHY");
+ return status;
+ }
+
+ if ((status = interface_detect_beat_ethtool(fd, iface)) != IFSTATUS_ERR) {
+ cached_func = interface_detect_beat_ethtool;
+ daemon_log(LOG_INFO, "Using detection mode: SIOCETHTOOL");
+ return status;
+ }
+
+ if ((status = interface_detect_beat_wlan(fd, iface)) != IFSTATUS_ERR) {
+ cached_func = interface_detect_beat_wlan;
+ daemon_log(LOG_INFO, "Using detection mode: wireless extension");
+ return status;
+ }
+
+ if ((status = interface_detect_beat_priv(fd, iface)) != IFSTATUS_ERR) {
+ cached_func = interface_detect_beat_priv;
+ daemon_log(LOG_INFO, "Using detection mode: SIOCDEVPRIVATE");
+ return status;
+ }
+
+ return IFSTATUS_ERR;
+}
+
+char *strstatus(interface_status_t s) {
+ switch(s) {
+ case IFSTATUS_UP: return "up";
+ case IFSTATUS_DOWN: return "down";
+ case IFSTATUS_ERR: return "error";
+ default: return "disabled";
+ }
+}
+
+interface_status_t detect_beat(int fd, char*iface) {
+ interface_status_t status;
+ static interface_status_t last_status = (interface_status_t) -1;
+
+ if ((status = detect_beat_func(fd, iface)) == IFSTATUS_ERR)
+ status = failure_status;
+
+ if (status == IFSTATUS_ERR && detect_beat_func == detect_beat_auto)
+ daemon_log(LOG_INFO, "Failed to find working plug detection mode for %s", interface);
+
+ if (status != last_status) {
+ setenv(IFPLUGD_ENV_PREVIOUS, strstatus(last_status), 1);
+ setenv(IFPLUGD_ENV_CURRENT, strstatus(status), 1);
+ last_status = status;
+ }
+
+ return status;
+}
+
+int open_iface(char *iface) {
+ int fd;
+ struct ifreq ifr;
+ struct ethtool_drvinfo drvinfo;
+ char txt[256];
+
+ if ((fd = interface_open(iface)) < 0) {
+ daemon_log(LOG_ERR, "Could not create socket: %s", strerror(errno));
+ return fd;
+ }
+
+ if (interface_auto_up)
+ interface_up(fd, iface);
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
+
+ if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1)
+ snprintf(txt, sizeof(txt)-1, "Using interface %s", iface);
+ else
+ snprintf(txt, sizeof(txt)-1, "Using interface %s/%02X:%02X:%02X:%02X:%02X:%02X", iface, ifr.ifr_hwaddr.sa_data[0] & 0xFF, ifr.ifr_hwaddr.sa_data[1] & 0xFF, ifr.ifr_hwaddr.sa_data[2] & 0xFF, ifr.ifr_hwaddr.sa_data[3] & 0xFF, ifr.ifr_hwaddr.sa_data[4] & 0xFF, ifr.ifr_hwaddr.sa_data[5] & 0xFF);
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
+
+ drvinfo.cmd = ETHTOOL_GDRVINFO;
+ ifr.ifr_data = (caddr_t) &drvinfo;
+
+ if (ioctl(fd, SIOCETHTOOL, &ifr) != -1)
+ daemon_log(LOG_INFO, "%s with driver <%s> (version: %s)", txt, drvinfo.driver, drvinfo.version);
+ else
+ daemon_log(LOG_INFO, "%s", txt);
+
+ return fd;
+}
+
+void work() {
+ interface_status_t status;
+ int fd = -1;
+ fd_set rfds;
+ int sigfd;
+ time_t t = 0;
+ int send_retval = 1;
+ int paused = 0;
+ static char log_ident[256];
+
+ snprintf(log_ident, sizeof(log_ident), "ifplugd(%s)", interface);
+
+ daemon_log_ident = log_ident;
+
+
+ if (daemon_pid_file_create() < 0) {
+ daemon_log(LOG_ERR, "Could not create PID file %s.", daemon_pid_file_proc());
+ goto finish;
+ }
+
+ if (daemon_signal_init(SIGINT, SIGTERM, SIGQUIT, SIGHUP, SIGCHLD, SIGUSR1, SIGUSR2, -1) < 0) {
+ daemon_log(LOG_ERR, "Could not register signal handler: %s", strerror(errno));
+ goto finish;
+ }
+
+ switch (api_mode) {
+ case API_ETHTOOL: detect_beat_func = interface_detect_beat_ethtool; break;
+ case API_MII: detect_beat_func = interface_detect_beat_mii; break;
+ case API_PRIVATE: detect_beat_func = interface_detect_beat_priv; break;
+ case API_WLAN: detect_beat_func = interface_detect_beat_wlan;break;
+
+ default:
+ detect_beat_func = detect_beat_auto;
+ interface_do_message = 0;
+ break;
+ }
+
+ if ((fd = open_iface(interface)) < 0)
+ goto finish;
+
+ if ((status = detect_beat(fd, interface)) == IFSTATUS_ERR)
+ goto finish;
+
+ daemon_log(LOG_INFO, "ifplugd "VERSION" successfully initialized, link beat %sdetected.", status == IFSTATUS_UP ? "" : "not ");
+ beep(status == IFSTATUS_UP ? 0 : 1);
+
+ if (status == IFSTATUS_UP || initial_down)
+ if (action(status) < 0)
+ goto finish;
+
+ if (daemonize && wait_on_fork) {
+ char c = status == IFSTATUS_UP ? 2 : (status == IFSTATUS_DOWN ? 3 : 1);
+ daemon_retval_send(c);
+ send_retval = 0;
+ }
+
+ FD_ZERO(&rfds);
+ FD_SET(sigfd = daemon_signal_fd(), &rfds);
+
+ for (;;) {
+ interface_status_t r;
+ fd_set wrfds = rfds;
+ struct timeval tv = { polltime, 0 };
+
+ if (select(FD_SETSIZE, &wrfds, NULL, NULL, &tv) < 0) {
+ if (errno == EINTR)
+ continue;
+
+ daemon_log(LOG_ERR, "select(): %s", strerror(errno));
+ goto finish;
+ }
+
+
+ if (FD_ISSET(sigfd, &wrfds)) {
+ int sig;
+
+ if ((sig = daemon_signal_next()) < 0) {
+ daemon_log(LOG_ERR, "daemon_signal_next(): %s", strerror(errno));
+ goto finish;
+ }
+
+
+ switch (sig) {
+
+ case SIGINT:
+ case SIGTERM:
+ goto cleanup;
+
+ case SIGQUIT:
+ goto finish;
+
+ case SIGCHLD:
+ break;
+
+ case SIGHUP:
+ daemon_log(LOG_INFO, "SIGHUP: %s, link detected on %s: %s", paused ? "Suspended" : "Running", interface, status == IFSTATUS_DOWN ? "no" : "yes");
+ break;
+
+ case SIGUSR1:
+ daemon_log(LOG_INFO, "SIGUSR1: Daemon suspended (#%i)", ++paused);
+ break;
+
+ case SIGUSR2:
+ if (paused > 0) {
+ daemon_log(LOG_INFO, "SIGUSR2: Daemon resumed (#%i)", paused);
+ paused --;
+ }
+
+ break;
+
+ default:
+ daemon_log(LOG_INFO, "Ignoring unknown signal %s", strsignal(sig));
+ break;
+ }
+ }
+
+
+ if (!paused) {
+ if ((r = detect_beat(fd, interface)) == IFSTATUS_ERR)
+ break;
+
+ if (status != r) {
+ status = r;
+
+ daemon_log(LOG_INFO, "Link beat %s.", status == IFSTATUS_DOWN ? "lost" : "detected");
+ beep(status == IFSTATUS_UP ? 0 : 1);
+
+
+ if (t)
+ t = 0;
+ else {
+ t = time(NULL);
+
+ if (status == IFSTATUS_UP)
+ t += delay_up;
+
+ if (status == IFSTATUS_DOWN)
+ t += delay_down;
+ }
+ }
+ }
+
+
+ if (t && t < time(NULL)) {
+ t = 0;
+
+ if (action(status) < 0)
+ goto finish;
+ }
+ }
+
+cleanup:
+ if (!no_shutdown_script && status == IFSTATUS_UP) {
+ setenv(IFPLUGD_ENV_PREVIOUS, strstatus(status), 1);
+ setenv(IFPLUGD_ENV_CURRENT, strstatus(-1), 1);
+ action(IFSTATUS_DOWN);
+ beep(1);
+ }
+
+finish:
+
+ if (fd >= 0)
+ close(fd);
+
+ if (send_retval && daemonize && wait_on_fork)
+ daemon_retval_send(1);
+
+ daemon_pid_file_remove();
+ daemon_signal_done();
+
+ daemon_log(LOG_INFO, "Exiting.");
+}
+
+void usage(char *p) {
+ char *m;
+
+ switch (api_mode) {
+ case API_ETHTOOL: m = "ethtool"; break;
+ case API_MII: m = "mii"; break;
+ case API_PRIVATE: m = "priv"; break;
+ case API_WLAN: m = "wlan"; break;
+ default: m = "auto";
+ }
+
+ if (strrchr(p, '/'))
+ p = strchr(p, '/')+1;
+
+ printf("%s [options]\n"
+ " -a --no-auto Do not enable interface automatically (%s)\n"
+ " -n --no-daemon Do not daemonize (for debugging) (%s)\n"
+ " -s --no-syslog Do not use syslog, use stderr instead (for debugging) (%s)\n"
+ " -b --no-beep Do not beep (%s)\n"
+ " -f --ignore-fail Ignore detection failure, retry instead (failure is treated as DOWN) (%s)\n"
+ " -F --ignore-fail-positive Ignore detection failure, retry instead (failure is treated as UP) (%s)\n"
+ " -i --iface=IFACE Specify ethernet interface (%s)\n"
+ " -r --run=EXEC Specify program to execute (%s)\n"
+ " -I --ignore-retval Don't exit on nonzero return value of program executed (%s)\n"
+ " -t --poll-time=SECS Specify poll time in seconds (%i)\n"
+ " -u --delay-up=SECS Specify delay for configuring interface (%i)\n"
+ " -d --delay-down=SECS Specify delay for deconfiguring interface (%i)\n"
+ " -m --api-mode=MODE Force API mode (mii, priv, ethtool, wlan, auto) (%s)\n"
+ " -q --no-shutdown Don't run script on daemon quit (%s)\n"
+ " -l --initial-down Run \"down\" script on startup if now cable is detected (%s)\n"
+ " -w --wait-on-fork Wait until daemon fork finished (%s)\n"
+ " -x --extra-arg Specify an extra argument for action script\n"
+ " -h --help Show this help\n"
+ " -k --kill Kill a running daemon\n"
+ " -c --check-running Check if a daemon is currently running\n"
+ " -v --version Show version\n"
+ " -S --suspend Suspend running daemon\n"
+ " -R --resume Resume running daemon\n"
+ " -z --info Write status of running daemon to syslog\n",
+ p,
+ !interface_auto_up ? "on" : "off",
+ !daemonize ? "on" : "off",
+ !use_syslog ? "on" : "off",
+ !use_beep ? "on" : "off",
+ failure_status == IFSTATUS_DOWN ? "on" : "off",
+ failure_status == IFSTATUS_UP ? "on" : "off",
+ interface,
+ run,
+ ignore_retval ? "on" : "off",
+ polltime,
+ delay_up,
+ delay_down,
+ m,
+ no_shutdown_script ? "on" : "off",
+ initial_down ? "on" : "off",
+ wait_on_fork ? "on" : "off");
+}
+
+void parse_args(int argc, char *argv[]) {
+ static struct option long_options[] = {
+ {"no-auto", no_argument, 0, 'a'},
+ {"no-daemon", no_argument, 0, 'n'},
+ {"no-syslog", no_argument, 0, 's'},
+ {"no-beep", no_argument, 0, 'b'},
+ {"ignore-fail", no_argument, 0, 'f'},
+ {"ignore-fail-positive", no_argument, 0, 'F'},
+ {"ignore-retval", no_argument, 0, 'I'},
+ {"iface", required_argument, 0, 'i'},
+ {"run", required_argument, 0, 'r'},
+ {"poll-time", required_argument, 0, 't'},
+ {"delay-up", required_argument, 0, 'u'},
+ {"delay-down", required_argument, 0, 'd'},
+ {"api-mode", required_argument, 0, 'm'},
+ {"wait-on-fork", no_argument, 0, 'w'},
+ {"no-shutdown", no_argument, 0, 'q'},
+ {"help", no_argument, 0, 'h'},
+ {"kill", no_argument, 0, 'k'},
+ {"check-running", no_argument, 0, 'c'},
+ {"version", no_argument, 0, 'v'},
+ {"extra-arg", required_argument, 0, 'x'},
+ {"suspend", no_argument, 0, 'S'},
+ {"resume", no_argument, 0, 'R'},
+ {"info", no_argument, 0, 'z'},
+ {"inital-down", no_argument, 0, 'l'},
+ {0, 0, 0, 0}
+ };
+ int option_index = 0;
+ int help = 0, _kill = 0, _check = 0, _version = 0, _suspend = 0, _resume = 0, _info = 0;
+
+ for (;;) {
+ int c;
+
+ if ((c = getopt_long(argc, argv, "asni:r:t:u:d:hkbfFvm:qwx:cISRzl", long_options, &option_index)) < 0)
+ break;
+
+ switch (c) {
+ case 'a' :
+ interface_auto_up = !interface_auto_up;
+ break;
+ case 's' :
+ use_syslog = !use_syslog;
+ break;
+ case 'n' :
+ daemonize = !daemonize;
+ break;
+ case 'i' :
+ interface = strdup(optarg);
+ break;
+ case 'r':
+ run = strdup(optarg);
+ break;
+ case 'I':
+ ignore_retval = !ignore_retval;
+ break;
+ case 't':
+ polltime = atoi(optarg);
+ if (polltime < 0) polltime = 0;
+ break;
+ case 'u':
+ delay_up = atoi(optarg);
+ break;
+ case 'd':
+ delay_down = atoi(optarg);
+ break;
+ case 'h':
+ help = 1;
+ break;
+ case 'k':
+ _kill = 1;
+ break;
+ case 'c':
+ _check = 1;
+ break;
+ case 'v':
+ _version = 1;
+ break;
+ case 'b':
+ use_beep = !use_beep;
+ break;
+ case 'f':
+ failure_status = IFSTATUS_DOWN;
+ break;
+ case 'F':
+ failure_status = IFSTATUS_UP;
+ break;
+ case 'm':
+ switch (tolower(optarg[0])) {
+ case 'e': api_mode = API_ETHTOOL; break;
+ case 'm': api_mode = API_MII; break;
+ case 'p': api_mode = API_PRIVATE; break;
+ case 'w': api_mode = API_WLAN; break;
+ case 'a': api_mode = API_AUTO; break;
+ default:
+ fprintf(stderr, "Unknown API mode: %s\n", optarg);
+ exit(2);
+ }
+ break;
+ case 'q':
+ no_shutdown_script = !no_shutdown_script;
+ break;
+ case 'l':
+ initial_down = !initial_down;
+ break;
+ case 'w':
+ wait_on_fork = !wait_on_fork;
+ break;
+ case 'x':
+ extra_arg = strdup(optarg);
+ break;
+ case 'S':
+ _suspend = 1;
+ break;
+ case 'R':
+ _resume = 1;
+ break;
+ case 'z':
+ _info = 1;
+ break;
+ default:
+ fprintf(stderr, "Unknown parameter.\n");
+ exit(1);
+ }
+ }
+
+
+ if (!use_syslog)
+ daemon_log_use = DAEMON_LOG_STDERR;
+
+
+ if (help) {
+ usage(argv[0]);
+ exit(0);
+ }
+
+ if (_kill || _resume || _suspend || _info) {
+ if (daemon_pid_file_kill(_kill ? SIGINT : (_resume ? SIGUSR2 : (_info ? SIGHUP : SIGUSR1))) < 0) {
+ daemon_log(LOG_ERR, "Failed to kill daemon. (%s)", strerror(errno));
+ exit(6);
+ }
+
+ exit(0);
+ }
+
+ if (_version) {
+
+#ifdef SVN_REVISION
+ printf("ifplugd "VERSION" (SVN: "SVN_REVISION")\n");
+#else
+ printf("ifplugd "VERSION"\n");
+#endif
+
+ exit(0);
+ }
+
+ if (_check) {
+ pid_t pid = daemon_pid_file_is_running();
+
+ if (pid == (pid_t) -1)
+ printf("ifplugd not running.\n");
+ else
+ printf("ifplugd process for device %s running as pid %u.\n", interface, pid);
+
+ exit(pid == 0 ? 255 : 0);
+ }
+
+}
+
+static volatile int alarmed = 0;
+
+void sigalrm() {
+ alarmed = 1;
+}
+
+int main(int argc, char* argv[]) {
+
+ daemon_pid_file_proc = pid_file_proc;
+
+ if ((daemon_log_ident = strrchr(argv[0], '/')))
+ daemon_log_ident++;
+ else
+ daemon_log_ident = argv[0];
+
+ parse_args(argc, argv);
+
+ if (geteuid() != 0) {
+ daemon_log(LOG_ERR, "Sorry, you need to be root to run this binary.");
+ return 2;
+ }
+
+
+ if (daemon_pid_file_is_running() >= 0) {
+ daemon_log(LOG_ERR, "Sorry, there is already an instance of ifplugd for %s running.", interface);
+ return 4;
+ }
+
+ if (daemonize) {
+ pid_t pid;
+
+ if (wait_on_fork)
+ if (daemon_retval_init() < 0) {
+ daemon_log(LOG_ERR, "Sorry, could not create pipe: %s", strerror(errno));
+ return 4;
+ }
+
+ if ((pid = daemon_fork()) < 0)
+ return 3;
+
+ if (pid) {
+ int c = 0;
+
+ // Parent process
+
+ if (wait_on_fork)
+ if ((c = daemon_retval_wait(60)) < 0) {
+ daemon_log(LOG_WARNING, "Killing background process.");
+ kill(pid, SIGTERM);
+ }
+
+
+ return c;
+ }
+ }
+
+ // Let's go
+ work();
+ return 0;
+}
diff --git a/src/ifstatus.c b/src/ifstatus.c
new file mode 100644
index 0000000..35a0b48
--- /dev/null
+++ b/src/ifstatus.c
@@ -0,0 +1,234 @@
+/* $Id: ifstatus.c 1.3 Wed, 13 Nov 2002 22:37:54 +0100 lennart $ */
+
+/*
+ * This file is part of ifplugd.
+ *
+ * ifplugd is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ifplugd is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with ifplugd; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+
+#include <libdaemon/dlog.h>
+
+#include "interface.h"
+#include "svn-revision.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+int interface_auto_up = 0, interface_do_message = 0;
+
+int verbose = 0;
+char *interface = NULL;
+
+int handle(char *iface) {
+ int fd, r = 0;
+ interface_status_t s;
+
+ if ((fd = interface_open(iface)) < 0)
+ return -1;
+
+ if (verbose > 0) {
+ printf("%s:\n", iface);
+
+ if ((s = interface_detect_beat_ethtool(fd, iface)) == IFSTATUS_ERR)
+ printf(" SIOCETHTOOL failed (%s)\n", strerror(errno));
+ else
+ printf(" SIOCETHTOOL: %s\n", s == IFSTATUS_UP ? "link beat detected" : "unplugged");
+
+ if ((s = interface_detect_beat_mii(fd, iface)) == IFSTATUS_ERR)
+ printf(" SIOCGMIIPHY failed (%s)\n", strerror(errno));
+ else
+ printf(" SIOCGMIIPHY: %s\n", s == IFSTATUS_UP ? "link beat detected" : "unplugged");
+
+ if ((s = interface_detect_beat_priv(fd, iface)) == IFSTATUS_ERR)
+ printf(" SIOCDEVPRIVATE failed (%s)\n", strerror(errno));
+ else
+ printf(" SIOCDEVPRIVATE: %s\n", s == IFSTATUS_UP ? "link beat detected" : "unplugged");
+
+ if ((s = interface_detect_beat_wlan(fd, iface)) == IFSTATUS_ERR)
+ printf(" Wireless failed.\n");
+ else
+ printf(" Wireless: %s\n", s == IFSTATUS_UP ? "link beat detected" : "unplugged");
+
+ } else {
+
+ if ((s = interface_detect_beat_mii(fd, iface)) == IFSTATUS_ERR)
+ if ((s = interface_detect_beat_ethtool(fd, iface)) == IFSTATUS_ERR)
+ if ((s = interface_detect_beat_wlan(fd, iface)) == IFSTATUS_ERR)
+ s = interface_detect_beat_priv(fd, iface);
+
+ switch(s) {
+ case IFSTATUS_UP:
+ if (!verbose)
+ printf("%s: link beat detected\n", iface);
+ r = 1;
+ break;
+
+ case IFSTATUS_DOWN:
+ if (!verbose)
+ printf("%s: unplugged\n", iface);
+ r = 2;
+ break;
+
+ default:
+ if (!verbose)
+ printf("%s: not supported\n", iface);
+
+ r = -1;
+ break;
+ }
+ }
+
+
+ close(fd);
+ return r;
+}
+
+void usage(char *p) {
+ if (strrchr(p, '/'))
+ p = strchr(p, '/')+1;
+
+ printf("%s [options] [INTERFACE]\n"
+ " -a --auto Enable interface automatically (%s)\n"
+ " -q --quiet Quiet behaviour (%s)\n"
+ " -v --verbose Enable verbosity (%s)\n"
+ " -h --help Show this help\n"
+ " -V --version Show version number\n",
+ p, interface_auto_up ? "on" : "off", verbose < 0 ? "on" : "off", verbose > 0 ? "on" : "off");
+}
+
+
+void parse(int argc, char *argv[]) {
+ static struct option long_options[] = {
+ {"auto", no_argument, 0, 'a'},
+ {"quiet", no_argument, 0, 'q'},
+ {"verbose", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {"version", no_argument, 0, 'V'},
+ {0, 0, 0, 0}
+ };
+ int option_index = 0;
+ int help = 0;
+
+ for (;;) {
+ int c;
+
+ if ((c = getopt_long(argc, argv, "avhqV", long_options, &option_index)) < 0)
+ break;
+
+ switch (c) {
+ case 'a' :
+ interface_auto_up = !interface_auto_up;
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case 'q':
+ verbose--;
+ break;
+ case 'h':
+ help = 1;
+ break;
+ case 'V':
+#ifdef SVN_REVISION
+ printf("ifstatus "VERSION" (SVN: "SVN_REVISION")\n");
+#else
+ printf("ifstatus "VERSION"\n");
+#endif
+ exit(0);
+ default:
+ fprintf(stderr, "Unknown parameter.\n");
+ exit(1);
+
+ }
+ }
+
+ if (help) {
+ usage(argv[0]);
+ exit(0);
+ }
+
+ if (optind < argc)
+ interface = argv[optind];
+}
+
+
+int main(int argc, char *argv[]) {
+ parse(argc, argv);
+
+ if (interface) {
+ int r;
+
+ if ((r = handle(interface)) < 0) {
+ if (verbose == 0)
+ fprintf(stderr, "Failure (%s)\n", strerror(errno));
+ return 1;
+ }
+
+ return r+1;
+
+ } else {
+ struct ifconf ifconf;
+ struct ifreq *ifr;
+ int m, n, s, fd;
+
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ fprintf(stderr, "socket(): %s\n", strerror(errno));
+ return 1;
+ }
+
+ s = sizeof(struct ifreq)*5;
+ for (;;) {
+ ifr = malloc(s);
+
+ ifconf.ifc_len = s;
+ ifconf.ifc_req = ifr;
+
+ if (ioctl(fd, SIOCGIFCONF, &ifconf) < 0) {
+ fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno));
+ free(ifr);
+ close(fd);
+ return 1;
+ }
+
+
+ if (ifconf.ifc_len != s)
+ break;
+
+ free(ifr);
+ s *= 2;
+ }
+
+ close(fd);
+
+ m = ifconf.ifc_len/sizeof(struct ifreq);
+ for (n = 0; n < m; n++)
+ if (strcmp(ifconf.ifc_req[n].ifr_name, "lo"))
+ handle(ifconf.ifc_req[n].ifr_name);
+
+ free(ifr);
+ }
+
+ return 0;
+}
diff --git a/src/interface.c b/src/interface.c
new file mode 100644
index 0000000..894922c
--- /dev/null
+++ b/src/interface.c
@@ -0,0 +1,219 @@
+/* $Id: interface.c 1.4 Thu, 07 Nov 2002 22:27:37 +0100 lennart $ */
+
+/*
+ * This file is part of ifplugd.
+ *
+ * ifplugd is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ifplugd is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with ifplugd; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include <linux/sockios.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <syslog.h>
+#include <string.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+#include "ethtool-local.h"
+#include "interface.h"
+
+#include <libdaemon/dlog.h>
+
+int interface_open(char *iface) {
+ return socket(AF_INET, SOCK_DGRAM, 0);
+}
+
+void interface_up(int fd, char *iface) {
+ struct ifreq ifr;
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
+
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
+ if (interface_do_message)
+ daemon_log(LOG_WARNING, "Warning: Could not get interface flags.");
+
+ return;
+ }
+
+ if ((ifr.ifr_flags & IFF_UP) == IFF_UP)
+ return;
+
+ if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) {
+ if (interface_do_message)
+ daemon_log(LOG_WARNING, "Warning: Could not get interface address.");
+ } else if (ifr.ifr_addr.sa_family != AF_INET) {
+ if (interface_do_message)
+ daemon_log(LOG_WARNING, "Warning: The interface is not IP-based.");
+ } else {
+ ((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr.s_addr = INADDR_ANY;
+ if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) {
+ if (interface_do_message)
+ daemon_log(LOG_WARNING, "Warning: Could not set interface address.");
+ }
+ }
+
+
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
+ if (interface_do_message)
+ daemon_log(LOG_WARNING, "Warning: Could not get interface flags.");
+
+ return;
+ }
+
+ ifr.ifr_flags |= IFF_UP;
+
+ if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
+ if (interface_do_message)
+ daemon_log(LOG_WARNING, "Warning: Could not set interface flags.");
+}
+
+interface_status_t interface_detect_beat_mii(int fd, char *iface) {
+ struct ifreq ifr;
+
+ if (interface_auto_up)
+ interface_up(fd, iface);
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
+
+ if (ioctl(fd, SIOCGMIIPHY, &ifr) == -1) {
+ if (interface_do_message)
+ daemon_log(LOG_ERR, "SIOCGMIIPHY failed: %s", strerror(errno));
+
+ return IFSTATUS_ERR;
+ }
+
+ ((unsigned short*) &ifr.ifr_data)[1] = 1;
+
+ if (ioctl(fd, SIOCGMIIREG, &ifr) == -1) {
+ if (interface_do_message)
+ daemon_log(LOG_ERR, "SIOCGMIIREG failed: %s", strerror(errno));
+
+ return IFSTATUS_ERR;
+ }
+
+ return (((unsigned short*) &ifr.ifr_data)[3] & 0x0016) == 0x0004 ? IFSTATUS_UP : IFSTATUS_DOWN;
+}
+
+interface_status_t interface_detect_beat_priv(int fd, char *iface) {
+ struct ifreq ifr;
+
+ if (interface_auto_up)
+ interface_up(fd, iface);
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
+
+ if (ioctl(fd, SIOCDEVPRIVATE, &ifr) == -1) {
+ if (interface_do_message)
+ daemon_log(LOG_ERR, "SIOCDEVPRIVATE failed: %s", strerror(errno));
+
+ return IFSTATUS_ERR;
+ }
+
+ ((unsigned short*) &ifr.ifr_data)[1] = 1;
+
+ if (ioctl(fd, SIOCDEVPRIVATE+1, &ifr) == -1) {
+ if (interface_do_message)
+ daemon_log(LOG_ERR, "SIOCDEVPRIVATE+1 failed: %s", strerror(errno));
+
+ return IFSTATUS_ERR;
+ }
+
+ return (((unsigned short*) &ifr.ifr_data)[3] & 0x0016) == 0x0004 ? IFSTATUS_UP : IFSTATUS_DOWN;
+}
+
+interface_status_t interface_detect_beat_ethtool(int fd, char *iface) {
+
+ struct ifreq ifr;
+ struct ethtool_value edata;
+
+ if (interface_auto_up)
+ interface_up(fd, iface);
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
+
+ edata.cmd = ETHTOOL_GLINK;
+ ifr.ifr_data = (caddr_t) &edata;
+
+ if (ioctl(fd, SIOCETHTOOL, &ifr) == -1) {
+ if (interface_do_message)
+ daemon_log(LOG_ERR, "ETHTOOL_GLINK failed: %s", strerror(errno));
+
+ return IFSTATUS_ERR;
+ }
+
+ return edata.data ? IFSTATUS_UP : IFSTATUS_DOWN;
+}
+
+interface_status_t interface_detect_beat_wlan(int fd, char *iface) {
+ FILE *f;
+ char buf[256];
+ char *bp;
+ int l;
+
+ if (interface_auto_up)
+ interface_up(fd, iface);
+
+ l = strlen(iface);
+
+ if (!(f = fopen("/proc/net/wireless", "r"))) {
+ if (interface_do_message)
+ daemon_log(LOG_WARNING, "Failed to open /proc/net/wireless: %s",strerror(errno));
+
+ return IFSTATUS_ERR;
+ }
+
+ while (fgets(buf, sizeof(buf)-1, f)) {
+ bp = buf;
+
+ while (*bp && isspace(*bp))
+ bp++;
+
+ if(!strncmp(bp, iface, l) && bp[l]==':') {
+
+ /*skip device name */
+ if (!(bp = strchr(bp,' ')))
+ break;
+
+ bp++;
+
+ /*skip status*/
+ if (!(bp = strchr(bp,' ')))
+ break;
+
+ fclose(f);
+
+ if (atoi(bp) > 0)
+ return IFSTATUS_UP;
+ else
+ return IFSTATUS_DOWN;
+ };
+ }
+
+ if (interface_do_message)
+ daemon_log(LOG_ERR, "Failed to find wireless interface %s\n", iface);
+
+ fclose(f);
+
+ return IFSTATUS_ERR;
+}
+
diff --git a/src/interface.h b/src/interface.h
new file mode 100644
index 0000000..2f9490e
--- /dev/null
+++ b/src/interface.h
@@ -0,0 +1,37 @@
+#ifndef foointerfacehfoo
+#define foointerfacehfoo
+
+/* $Id: interface.h 1.2 Wed, 23 Oct 2002 20:49:08 +0200 lennart $ */
+
+/*
+ * This file is part of ifplugd.
+ *
+ * ifplugd is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ifplugd is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with ifplugd; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+int interface_auto_up;
+int interface_do_message;
+
+typedef enum { IFSTATUS_UP, IFSTATUS_DOWN, IFSTATUS_ERR } interface_status_t;
+
+int interface_open(char *iface);
+void interface_up(int fd, char *iface);
+
+interface_status_t interface_detect_beat_mii(int fd, char *iface);
+interface_status_t interface_detect_beat_priv(int fd, char *iface);
+interface_status_t interface_detect_beat_ethtool(int fd, char *iface);
+interface_status_t interface_detect_beat_wlan(int fd, char *iface);
+
+#endif