2005-05-03 Dan Williams <dcbw@redhat.com>
* Kill dhcpcd. We now use "dhcdbd", a dbus daemon that controls dhclient. This means that NetworkManager shouldn't have DHCP issues anymore. It also means you need dhcdbd, which you can get here (get the latest one): http://people.redhat.com/jvdias/dhcdbd/ Technically NetworkManager can use any DHCP daemon that uses the same DBUS interface as dhcdbd. * Rewrite device activation to facilitate the new DHCP infrastructure and future improvements. Its now "activation request" based, ie there is a single activation request composed of the device, access point, and other info which follows the entire activation process. There are 5 stages of the activation process which correspond to: 1) Device preparation 2) Device configuration (bring it up, set ESSID/Key/etc) 3) IP Config Start (fire off DHCP if we're using it) 4) IP Config Get (grab config from DHCP or static config files) 5) IP Config Commit (set device's IP address, DNS, etc) Note that there is no longer a "scanning" step, since the access point must be known _before_ activation starts. If the access point drops out or does not exist for some reason, the entire activation process fails and must be restarted for a different access point or device. Patch from Bill Moss: * gnome/applet/applet.c - Fix type of vpn_failure dialog -> vpn_banner dialog git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@597 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
32
ChangeLog
32
ChangeLog
@@ -1,3 +1,35 @@
|
|||||||
|
2005-05-03 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
|
* Kill dhcpcd. We now use "dhcdbd", a dbus daemon that controls dhclient.
|
||||||
|
This means that NetworkManager shouldn't have DHCP issues anymore. It also
|
||||||
|
means you need dhcdbd, which you can get here (get the latest one):
|
||||||
|
|
||||||
|
http://people.redhat.com/jvdias/dhcdbd/
|
||||||
|
|
||||||
|
Technically NetworkManager can use any DHCP daemon that uses the same DBUS
|
||||||
|
interface as dhcdbd.
|
||||||
|
|
||||||
|
* Rewrite device activation to facilitate the new DHCP infrastructure and
|
||||||
|
future improvements. Its now "activation request" based, ie there is a single
|
||||||
|
activation request composed of the device, access point, and other info which
|
||||||
|
follows the entire activation process. There are 5 stages of the activation
|
||||||
|
process which correspond to:
|
||||||
|
|
||||||
|
1) Device preparation
|
||||||
|
2) Device configuration (bring it up, set ESSID/Key/etc)
|
||||||
|
3) IP Config Start (fire off DHCP if we're using it)
|
||||||
|
4) IP Config Get (grab config from DHCP or static config files)
|
||||||
|
5) IP Config Commit (set device's IP address, DNS, etc)
|
||||||
|
|
||||||
|
Note that there is no longer a "scanning" step, since the access point must
|
||||||
|
be known _before_ activation starts. If the access point drops out or does
|
||||||
|
not exist for some reason, the entire activation process fails and must be
|
||||||
|
restarted for a different access point or device.
|
||||||
|
|
||||||
|
Patch from Bill Moss:
|
||||||
|
* gnome/applet/applet.c
|
||||||
|
- Fix type of vpn_failure dialog -> vpn_banner dialog
|
||||||
|
|
||||||
2005-04-27 Dan Williams <dcbw@redhat.com>
|
2005-04-27 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
* gnome/applet/applet-dbus-vpn.c
|
* gnome/applet/applet-dbus-vpn.c
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
SUBDIRS = utils dhcpcd src dispatcher-daemon gnome vpn-daemons initscript test po
|
SUBDIRS = utils src dispatcher-daemon gnome vpn-daemons initscript test po
|
||||||
|
|
||||||
EXTRA_DIST = CONTRIBUTING NetworkManager.pc.in NetworkManager.h
|
EXTRA_DIST = CONTRIBUTING NetworkManager.pc.in NetworkManager.h
|
||||||
|
|
||||||
|
@@ -263,6 +263,7 @@ utils/Makefile
|
|||||||
src/Makefile
|
src/Makefile
|
||||||
src/named-manager/Makefile
|
src/named-manager/Makefile
|
||||||
src/vpn-manager/Makefile
|
src/vpn-manager/Makefile
|
||||||
|
src/dhcp-manager/Makefile
|
||||||
src/backends/Makefile
|
src/backends/Makefile
|
||||||
dispatcher-daemon/Makefile
|
dispatcher-daemon/Makefile
|
||||||
gnome/Makefile
|
gnome/Makefile
|
||||||
@@ -270,7 +271,6 @@ gnome/applet/Makefile
|
|||||||
gnome/applet/icons/Makefile
|
gnome/applet/icons/Makefile
|
||||||
gnome/libnm_glib/libnm_glib.pc
|
gnome/libnm_glib/libnm_glib.pc
|
||||||
gnome/libnm_glib/Makefile
|
gnome/libnm_glib/Makefile
|
||||||
dhcpcd/Makefile
|
|
||||||
test/Makefile
|
test/Makefile
|
||||||
initscript/Makefile
|
initscript/Makefile
|
||||||
initscript/RedHat/Makefile
|
initscript/RedHat/Makefile
|
||||||
|
@@ -1,2 +0,0 @@
|
|||||||
Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
|
|
||||||
Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
340
dhcpcd/COPYING
340
dhcpcd/COPYING
@@ -1,340 +0,0 @@
|
|||||||
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.
|
|
794
dhcpcd/ChangeLog
794
dhcpcd/ChangeLog
@@ -1,794 +0,0 @@
|
|||||||
12/31/02 - v.1.3.22-pl4
|
|
||||||
Peter Poeml <poeml@suse.de> submitted patches to:
|
|
||||||
1. enable support for Token Ring.
|
|
||||||
2. disable second DHCP_DISCOVER message. S.V - added "-S" option to dhcpcd command
|
|
||||||
line to make second DHCP_DISCOVER message optional.
|
|
||||||
3. Make dhcpcd write to the console if syslogd is not running only with
|
|
||||||
"-d" DebugFlag.
|
|
||||||
Robert Whaley <rwhaley@applieddata.net> submitted patch to elimited potential
|
|
||||||
race condition between setting up the setjmp for dhcpReboot and the sigalarm handler.
|
|
||||||
Ian Sharpe <ian.sharpe@sharpe-practice.co.uk> submitted patch to handle situations
|
|
||||||
with DHCP server changing lease or T1,T2 times from renewal to renewal.
|
|
||||||
Jamey Hicks <jamey.hicks@hp.com> pointed out the setting of the netmask for
|
|
||||||
static route still doesn't always work correctly. Wrote "getgenmask" function
|
|
||||||
to try to deduce the netmask for static routes - S.V.
|
|
||||||
Per-Olof Pettersson <peope@peope.net> suggested "-G" option to prevent
|
|
||||||
dhcpcd from installing default routes. Expanded "-G" to include optional
|
|
||||||
[gateway] parameter for ip address of default router - S.V. The "-G" option
|
|
||||||
has also been added by Peter Poeml <poeml@suse.de> in one of the patches he sent.
|
|
||||||
S.V.- moved parts of the code from client.c into cache.c and dhcpconfig.c files.
|
|
||||||
|
|
||||||
09/30/02 - v.1.3.22-pl3
|
|
||||||
Duke Cho <duke@embeddedweb.co.kr> submitted patch for dhcpSendAndRecv() to scan
|
|
||||||
for begining of IP header in the received Ethernet frame rather than assume
|
|
||||||
it begins right after Ethernet header. It made dhcpcd work for ARM7TDMI cored SoC
|
|
||||||
boards.
|
|
||||||
Marc Beuchat <marc@siana.ch> submitted patch to open 0,1,2 file descriptors
|
|
||||||
at the start of dhcpcd if they are closed as in a case when dhcpcd starts from
|
|
||||||
pcmcia-cs network script.
|
|
||||||
|
|
||||||
09/21/02 - v.1.3.22-pl2
|
|
||||||
James Hicks <Jamey.Hicks@hp.com> submitted patch to set the netmask properly
|
|
||||||
for static routes provided by the DHCP server.
|
|
||||||
Michal Dobes <dobes@tesnet.cz> pointed out there could be situation with
|
|
||||||
many dhcpcd clients starting at the same time on different machines on the
|
|
||||||
same network in which case they will generate the DHCP messages with the
|
|
||||||
same XID and potentially configure the same IP addresses. Fixed by
|
|
||||||
including CLientHwAddr (MAC address) into the seed for srandom(). -S.V.
|
|
||||||
David Fallon <davef@d2.com> recomended changing sbindir to = ${exec_prefix}/sbin
|
|
||||||
rather than ${prefix} in Makefile.am. Also changed docdir=/usr/doc. -S.V.
|
|
||||||
Henning Spruth <henning.spruth@epost.de> suggested replacing
|
|
||||||
getuid() call with geteuid() in dhcpcd.c to enable setuid tools
|
|
||||||
to launch dhcpcd.
|
|
||||||
David Oleszkiewicz <davole@us.ibm.com> pointed out "logger" should
|
|
||||||
be used in dhcpcd.exe script instead of direct write to a log files.
|
|
||||||
Tobias Blomberg <tobias.blomberg@home.se> pointed out to a bug report at
|
|
||||||
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=65515
|
|
||||||
what appears to be dhcpcd cache overriding command line options -I and -i.
|
|
||||||
The related problem has been also reported by <20>yvind Bakksj<73>
|
|
||||||
<oyvind@bakksjo.no>. Fixed by calling clientIDsetup and classIDsetup
|
|
||||||
even after successfull cache read.
|
|
||||||
Kosbar, Kurt Louis <kosbar@umr.edu> submitted patch to fix a case of
|
|
||||||
dhcpcd client crash because of some DHCP server sending no dhcpMessageType
|
|
||||||
field in DHCP message.
|
|
||||||
Simon Kelley <simon@thekelleys.org.uk> pointed out at security bug in dhcpcd
|
|
||||||
related to *.info file. A malicios administrator of untrusted DHCP server
|
|
||||||
may execute any command with root privileges on DHCP client machine by
|
|
||||||
sending the command enclosed in shell metacharacters in one of DHCP server
|
|
||||||
provided options. Fixed by enclosing all strings in *.info file into single
|
|
||||||
quotes and replacing any single quotes found in DHCP option strings
|
|
||||||
with space. - S.V.
|
|
||||||
|
|
||||||
01/20/02 - v.1.3.22-pl1
|
|
||||||
S.V. - added support for virtual interfaces (eth0:1, eth1:2, etc)
|
|
||||||
inside dhcpcd itself. The "external" support (with external script
|
|
||||||
using *.info file) has been added in v.1.3.22-pl0.
|
|
||||||
|
|
||||||
01/19/02 - v.1.3.22-pl0
|
|
||||||
Scott Gifford <sgifford@tir.com> and Victor McSmith <vmcs@mail.ru>
|
|
||||||
suggested letting custom scripts instead of dhcpcd do all the
|
|
||||||
interface configuration work using DHCP info secured by dhcpcd
|
|
||||||
and stored in the *.info file.
|
|
||||||
Pramod Immaneni <pramod@aligo.com> suggested adding -L option to
|
|
||||||
dhcpcd to enable writing configuration information into a given *.info
|
|
||||||
file to be later used by other scripts. He also suggested modifying
|
|
||||||
-T option to save configuration information rather than just exiting after
|
|
||||||
DHCP negotiation sequence.
|
|
||||||
S.V. - the above proposals inspired the following changes to dhcpcd:
|
|
||||||
|
|
||||||
1. "-L <ConfigDir>" option has been added. Dhcpcd will store *.info,
|
|
||||||
*.cache files under <ConfigDir> rather than default /etc/dhcpc.
|
|
||||||
2. *.pid file has moved from under /var/run to under <ConfigDir>
|
|
||||||
(default /etc/dhcpc) subdirectory.
|
|
||||||
3. -T option behaviour has been modified to include writing
|
|
||||||
*.info, *.cache, *.pid files under <ConfigDir>, and executing
|
|
||||||
*.exe script in the same manner as without -T option.
|
|
||||||
Now with -T option dhcpcd will do everything except actually
|
|
||||||
configuring interface or changing any files under /etc.
|
|
||||||
Also now with -T option dhcpcd will not exit at the end of DHCP
|
|
||||||
negotiation sequence but will go into background and attempt
|
|
||||||
to renew the lease as usual.
|
|
||||||
-T option in conjunction with -L <ConfigDir> and -I <ClientID> will
|
|
||||||
enable users to negotiate/renew multiple IP addresses using the same
|
|
||||||
dummy interface.
|
|
||||||
It should also enable configuration of virtual interfaces.
|
|
||||||
4. <ConfigDir>/dhcpcd.exe script calling convention has changed. Now
|
|
||||||
dhcpcd will pass the path to *.info file as first argument and "up/down/new"
|
|
||||||
keyword as second argument. The third argument is optional
|
|
||||||
debugFlag "-d" passed from dhcpcd command line. See sample dhcpcd.exe
|
|
||||||
script supplied with distribution.
|
|
||||||
5. "-c <ExecFile>" option has been given second life and its behaviour
|
|
||||||
has slightly changed. Now <ExecFile> script will be executed instead of
|
|
||||||
default <ConfigDir>/dhcpcd.exe and in the same manner as
|
|
||||||
<ConfigDir>/dhcpcd.exe script (see Item 4 above).
|
|
||||||
6. The following lines has been added to *.info file written by
|
|
||||||
dhcpcd:
|
|
||||||
INTERFACE=<interface> (e.g. INTERFACE=eth1)
|
|
||||||
CLASSID=<class_id_string> (e.g. CLASSID="Linux 2.4.14 i686")
|
|
||||||
CLIENTID=<client_id_string> (e.g. CLIENT_ID=10:32:C3:37:25:14 or
|
|
||||||
CLIENT_ID="test1")
|
|
||||||
7. dhcpcd now will rename previous *.info file to *.info.old
|
|
||||||
|
|
||||||
Other changes:
|
|
||||||
Tim Wright <timw@polyserve.com> submitted patch to prevent dhcpcd
|
|
||||||
from altering network interface flags that it should not change.
|
|
||||||
Pavel Roskin <proski@gnu.org> submitted patch to dhcpcd.spec file
|
|
||||||
to fix the installation directories.
|
|
||||||
Tim Goodwin <tjg@star.le.ac.uk> suggested using full-qualified
|
|
||||||
host names rather than truncating them at first ".".
|
|
||||||
|
|
||||||
12/31/01 - v.1.3.21-pl2
|
|
||||||
D. Hugh Redelmeier <hugh@mimosa.com> pointed out a problem with
|
|
||||||
binding udpFooSocket in client.c to address 0.0.0.0 port 68 and
|
|
||||||
exiting with error status if binding fails as in a case of more
|
|
||||||
than one dhcpcd process. This effectively prevented dhcpcd from
|
|
||||||
running on more than one interface. Fixed for now by disabling
|
|
||||||
error exit in a case udpFooSocket binding fails. Perhaps a better
|
|
||||||
solution is needed.
|
|
||||||
Thomas Aeby <tomae@sfi.ch> pointed out nisDomainName should not
|
|
||||||
be used in /etc/resolv.conf file. Fixed.
|
|
||||||
Roger Maclean <rmaclean@marchnetworks.com> suggested to increase
|
|
||||||
"time since bootup" parameter in DHCP message to 10, otherwise
|
|
||||||
dhcpcd may not get an IP address from WinNT DHCP server.
|
|
||||||
Jani Averbach <jaa@cc.jyu.fi> suggested changes to Makefile.am to
|
|
||||||
make ./configure accept installation options.
|
|
||||||
Yaacov Akiba Slama <slamaya@yahoo.com> submitted a patch to make use
|
|
||||||
dhcp-spoof feature of adsl modems/routers. The patch sets netmask to
|
|
||||||
255.255.255.255 in a case the dhcpConfig routine fails to set it to
|
|
||||||
the netmask supplied by DHCP server.
|
|
||||||
|
|
||||||
10/13/01 - v.1.3.21-pl1
|
|
||||||
Pavel Roskin <proski@gnu.org> submitted patch for dhcpcd.spec.in
|
|
||||||
file to fix "rpm -ta dhcpcd-1.3.21-pl1.tar.gz" RPM package creation.
|
|
||||||
|
|
||||||
10/09/01 - v.1.3.21-pl0
|
|
||||||
Toralf Lund <toralf@kscanners.com> submitted patch to add
|
|
||||||
support for NIS and NTP server options in DHCP. -Y and -N
|
|
||||||
flags have been added to dhcpcd command line. Dhcpcd now creates
|
|
||||||
/etc/yp.conf and /etc/ntp.conf files unless -Y or -N
|
|
||||||
options are specified (see dhcpcd manual page). Among other things
|
|
||||||
in the patch: dhcpcd saves the hostname and domainname of the host
|
|
||||||
and restores it upon exit; dhcpcd now retries HWADDR_TRIES times
|
|
||||||
to retrieve NIC MAC address in dhcpStart().
|
|
||||||
Jarno Huuskonen <Jarno.Huuskonen@uku.fi> pointed out
|
|
||||||
dhcpcd sets mode of the pid file corresponding to the umask of
|
|
||||||
the calling process which may be a security risk if calling
|
|
||||||
process has umask 000 which happens when dhcpcd runs from APM
|
|
||||||
suspend/resume. Fixed by setting umask of dhcpcd process to 022 at
|
|
||||||
the very beginning in dhcpcd.c.
|
|
||||||
Olivier Baudron <Olivier.Baudron@ens.fr> suggested using just one
|
|
||||||
dhcpcd.exe script, which is to run every time interface is
|
|
||||||
configured or brought down. The interface name will be passed as
|
|
||||||
first parameter and configuration state as second parameter to the
|
|
||||||
script. So /etc/dhcpc/dhcpcd.exe script is invoked as
|
|
||||||
/etc/dhcpc/dhcpcd.exe <interface> <up|down|new> [ip_address] [-d]
|
|
||||||
Second parameter has value "up" when interface is brought up with
|
|
||||||
the same IP address as before, "new" when interface is brought up
|
|
||||||
with new IP address, and "down" when interface is brought down when
|
|
||||||
dhcpcd exits. This usage to the executable script was suggested by
|
|
||||||
Scott Gifford <sgifford@tir.com>.
|
|
||||||
**** This version requires rewrite of dhcpcd*.exe script(s) as it is
|
|
||||||
incompatible with previous versions of dhcpcd.
|
|
||||||
|
|
||||||
10/08/01 - v.1.3.20-pl2
|
|
||||||
Fabrizio Gennari <fabrizio.gennari@philips.com> reported
|
|
||||||
dhcpcd could not add a static route supplied by his DHCP server. He suggested
|
|
||||||
changing a line in client.c
|
|
||||||
rtent.rt_flags = RTF_UP|RTF_HOST;
|
|
||||||
to
|
|
||||||
rtent.rt_flags = RTF_UP|RTF_HOST|RTF_GATEWAY;
|
|
||||||
which fixed the problem for him. I will give it a shot .. with RoadRunner
|
|
||||||
no matter how much you screw dhcpcd, it always works ..
|
|
||||||
Simon Oliver <simon.oliver@umist.ac.uk> reported an interesting case
|
|
||||||
if DHCP server supplying dhcpAddrLeaseTime>0 and dhcpT1value=0 and
|
|
||||||
dhcpT2value=0 which made dhcpcd go mad about lease renewal. Fixed by
|
|
||||||
checking for dhcpT1value=0 and dhcpT2value=0 in client.c
|
|
||||||
|
|
||||||
10/01/01 - v.1.3.20-pl1
|
|
||||||
Matteo Frigo <athena@fftw.org> pointed out a bug in client.c:
|
|
||||||
in a case of class A network and DHCP server not supplying subnet mask
|
|
||||||
dhcpcd did not zero out second octet in subnet mask.
|
|
||||||
Elliot Lee <sopwith@redhat.com> submitted patches:
|
|
||||||
1. dhcpcd to accept IEEE 802 TokenRing interface (not sure if this one
|
|
||||||
will actually make dhcpcd work with TokenRing, since
|
|
||||||
dhcpcd builds messages on top of Ethernet frames)
|
|
||||||
2. make some globally defined variables to be local
|
|
||||||
3. use nis domain name along with dns domain name in search string of
|
|
||||||
/etc/resolv.conf file.
|
|
||||||
4. run a script when interface gets configured in addition to
|
|
||||||
/etc/dhcpc/dhcpcd-eth0.exe script which runs only when IP address
|
|
||||||
changes. S.V. - made the script name /etc/dhcpc/dhcpcd_up-eth0.exe
|
|
||||||
S.V - make dhcpcd run a script when interface goes down, the script is
|
|
||||||
/etc/dhcpc/dhcpcd_down-eth0.exe. This was also suggested by
|
|
||||||
Jason Bodnar <jbodnar@buzzard.kdi.com>
|
|
||||||
Craig Lawson <craig.lawson@symphony-systems.com> pointed out to a bug
|
|
||||||
in dhcpcd when it runs on multiple interfaces. When dhcpcd exits
|
|
||||||
it tries to restore resolv.conf.sv back to resolv.conf even if
|
|
||||||
dhcpcd did not rename it at first. Fixed.
|
|
||||||
Olivier Baudron <Olivier.Baudron@ens.fr> submitted patch to bind a
|
|
||||||
datagram socket to udp port 68 to prevent icmp error message from
|
|
||||||
the kernel. This problem has also been report by Robert Paluszak
|
|
||||||
<paluszak@nycap.rr.com>.
|
|
||||||
S.V.- cleaned up "configure" scripts to make sure ./configure will
|
|
||||||
create the Makefile with correct installation paths.
|
|
||||||
|
|
||||||
04/06/01 - v.1.3.20-pl0
|
|
||||||
S.V - removed 0x0 from ClientID and ClassID options
|
|
||||||
|
|
||||||
04/03/01 - v.1.3.19-pl9
|
|
||||||
Young, Jeremy <jeremy.young@cccnetsys.com> pointed out
|
|
||||||
to a bug introduced in v.1.3.19-pl6 which resulted in
|
|
||||||
7-byte long MAC address with 0x0 at the end. Fixed.
|
|
||||||
|
|
||||||
03/10/01 - v.1.3.19-pl8
|
|
||||||
Rune Torgersen <rune36@home.com> pointed out
|
|
||||||
at a bug introduced in v.1.3.19-pl7 with "rootPath"
|
|
||||||
option. The dhcpParamRequest had to be changed to 14.
|
|
||||||
The bug probably disabled "-h hostname" option to dhcpcd
|
|
||||||
in v.1.3.19-pl7.
|
|
||||||
|
|
||||||
02/22/01 - v.1.3.19-pl7
|
|
||||||
Chris Petro <petro@auctionwatch.com>
|
|
||||||
submitted patch to disable processing of
|
|
||||||
"routersOnSubnet" DHCP option if it is not
|
|
||||||
provided by DHCP server, as "routersOnSubnet" is
|
|
||||||
indeed optional.
|
|
||||||
Jason A. Pattie <pattieja@pcxperience.com>
|
|
||||||
submitted patch to include "rootPath" DHCP option.
|
|
||||||
Peter Poeml <poeml@suse.de> submitted patch
|
|
||||||
to work around a problem with dhcpcd setting
|
|
||||||
hostname when it is not provided by DHCP server if
|
|
||||||
there is no initial /etc/resolv.conf file to
|
|
||||||
be able to resolv hostname from obtained IP address.
|
|
||||||
|
|
||||||
01/14/01 - v.1.3.19-pl6
|
|
||||||
Simon Byrnand <sbyrnand@xtra.co.nz> reported the compilation
|
|
||||||
on older kernels broke again somewhere in pl3-pl5.
|
|
||||||
Pavel Roskin <proski@gnu.org> submitted patch to fix the
|
|
||||||
problem with compilation on older kernels.
|
|
||||||
S.V - added 0x0 to the end of ClientID and ClassID
|
|
||||||
options in the DHCP message.
|
|
||||||
|
|
||||||
12/21/00 - v.1.3.19-pl5
|
|
||||||
Pavel Roskin <proski@gnu.org> submitted patch:
|
|
||||||
README:
|
|
||||||
- Mention that MediaOne is now AT&T Broadband. dhcpcd works with it.
|
|
||||||
Makefile.am:
|
|
||||||
- Copy the binary dhcpcd to the distribution. Added a comment about
|
|
||||||
the dist-hook target.
|
|
||||||
configure.in:
|
|
||||||
- Remove AC_CANONICAL_TARGET - dhcpcd is not a compiler.
|
|
||||||
- Don't check Linux version - it can be determined at the compile time.
|
|
||||||
- Don't call uname directly - rely on the results of
|
|
||||||
AC_CANONICAL_HOST instead.
|
|
||||||
- Don't ever ignore predefined CFLAGS.
|
|
||||||
client.c:
|
|
||||||
- Include <linux/version.h>
|
|
||||||
- Define OLD_LINUX_VERSION for kernels older than 2.1.1.
|
|
||||||
|
|
||||||
The patch is also available here:
|
|
||||||
http://www.red-bean.com/~proski/dhcpcd/dhcpcd-pl4.diff
|
|
||||||
|
|
||||||
12/19/00 - v.1.3.19-pl4
|
|
||||||
Pavel Roskin <proski@gnu.org>
|
|
||||||
submitted patch to work around broken version of automake
|
|
||||||
which was used in generating v.1.3.19-pl3. Also
|
|
||||||
dhcpcd-1.3.19-pl4.tar.gz has been generated using
|
|
||||||
"make distcheck"
|
|
||||||
|
|
||||||
12/15/00 - v.1.3.19-pl3
|
|
||||||
Nico Baggus <nico_baggus@compuserve.com>
|
|
||||||
- added version checking to the cache file
|
|
||||||
- added support for specifying window size for the
|
|
||||||
gateway routes (default = 32768) (gives better throughput
|
|
||||||
when used for Cablenetworks...;-)
|
|
||||||
- modified defining the offsets in the ipudphdr & ipicmphdr
|
|
||||||
to get the stuff through gcc 2.96
|
|
||||||
|
|
||||||
Pavel Roskin <proski@gnu.org>
|
|
||||||
Makefile.am:
|
|
||||||
- Manuals and examples added to EXTRA_DIST
|
|
||||||
- dhcpcd.spec added to the distribution.
|
|
||||||
- dhcpcd.spec is now rebuilt by "make all".
|
|
||||||
- "make rpm" depends on "make distcheck" and uses the dhcpcd.conf
|
|
||||||
embedded into the tarball.
|
|
||||||
config.guess:
|
|
||||||
- Updated to the latest version. PA-Linux team will appreciate it.
|
|
||||||
config.sub:
|
|
||||||
- Likewise.
|
|
||||||
configure.in:
|
|
||||||
- Versioning simplified to ensure the right tarball name.
|
|
||||||
Removed dash from the patchlevel to accomodate rpm.
|
|
||||||
- Avoid square brackets or quote them properly.
|
|
||||||
dhcpcd.spec.in:
|
|
||||||
- Substitute "Source".
|
|
||||||
- "BuildRoot" should be under /var/tmp, not /usr/tmp.
|
|
||||||
- Don't use filelists - it breaks with rpm-3.0.5 that compresses
|
|
||||||
manuals.
|
|
||||||
- Include directory /etc/dhcpc.
|
|
||||||
- Exclude dhcpcd.spec.in from docs.
|
|
||||||
- Include any *.lsm file.
|
|
||||||
missing:
|
|
||||||
- Updated to avoid problems with future versions of automake.
|
|
||||||
|
|
||||||
10/11/00 - v.1.3.19-pl2
|
|
||||||
Nils Ohlmeier <nils.ohlmeier@innominate.de> and
|
|
||||||
Warren Jones <wjones@tc.fluke.com> rightfully pointed out
|
|
||||||
nisDomainName should not be used in resolv.conf file.
|
|
||||||
Fixed.
|
|
||||||
|
|
||||||
08/05/00 - v.1.3.19-pl1
|
|
||||||
Simon Byrnand <sbyrnand@xtra.co.nz> submitted patches to make
|
|
||||||
ioctl(dhcpSocket,SIOCSIFADDR,&ifr) call in dhcpStop() routine
|
|
||||||
applicable only to kernels versions > 2.0 and
|
|
||||||
to fix handling of SIGCHLD signal.
|
|
||||||
|
|
||||||
08/05/00 - v.1.3.19-pl0
|
|
||||||
Lenz Grimmer <grimmer@suse.de> submitted patch to prevent
|
|
||||||
"unaligned memory access" warnings to appear on IA64-based systems.
|
|
||||||
|
|
||||||
08/05/00 - v.1.3.18-pl9
|
|
||||||
uncommented ioctl(dhcpSocket,SIOCSIFADDR,&ifr) call in dhcpStop()
|
|
||||||
routine to prevent interface from having invalid IP address
|
|
||||||
during DHCP negotiation.
|
|
||||||
|
|
||||||
Simon Byrnand <sbyrnand@xtra.co.nz> submitted patch to take
|
|
||||||
care of the following:
|
|
||||||
o Make dhcpcd both libc5 and glibc compatible
|
|
||||||
o Rebind dhcpSocket after change in IP address to avoid
|
|
||||||
problem with 2.0 kernel losing socket binding to the interface
|
|
||||||
after resetting of the interface
|
|
||||||
o Problem with lost DhcpRelease message under 2.0 kernel
|
|
||||||
when interface gets shut down
|
|
||||||
|
|
||||||
Brian K. White <linut@squonk.net> submitted "Note 4." to the
|
|
||||||
README file.
|
|
||||||
|
|
||||||
05/10/00 - v.1.3.18-pl8
|
|
||||||
Konstantin Boldyshev <konst@linuxassembly.org> submitted patch
|
|
||||||
to make dhcpcd work with 2.0 kernels. Modified configure script
|
|
||||||
to pass -DOLD_LINUX_VERSION flag to compiler if the kernel version
|
|
||||||
is 2.0.xx, in which case socket(AF_INET,SOCK_PACKET,..) call is used
|
|
||||||
instead of socket(AF_PACKET,SOCK_PACKET,..) and the local route
|
|
||||||
is added. Local route is added automatically under more recent kernels.
|
|
||||||
|
|
||||||
Rolf Jentsch <RJentsch@electronicpartner.de> submitted patch to
|
|
||||||
add -T flag to the dhcpcd command line. With -T flag dhcpcd will
|
|
||||||
go through normal DHCP negotiation sequence but will not configure
|
|
||||||
the interface or otherwise change anything on the system. Useful for
|
|
||||||
testing DHCP servers.
|
|
||||||
|
|
||||||
05/06/00 - v.1.3.18-pl7
|
|
||||||
Simon Baatz <baatz@informatik.uni-bonn.de> submited patch to fix
|
|
||||||
possible problem in retransmitting DHCP requests, and make dhcpcd
|
|
||||||
adapt to possible change in DHCP server address in the middle of a
|
|
||||||
client's lease.
|
|
||||||
|
|
||||||
Habibie <habibie@MailandNews.com> submitted patch to include
|
|
||||||
GNU automake, autoconf, and RPM packaging features into dhcpcd
|
|
||||||
distribution. Now dhcpcd build follows usual GNU scheme:
|
|
||||||
|
|
||||||
./configure
|
|
||||||
make
|
|
||||||
|
|
||||||
In any case, the old Makefile is also included. ./configure overwrites
|
|
||||||
it with generated version.
|
|
||||||
|
|
||||||
Added "-n" flag to dhcpcd command line. Now "dhcpcd -n" will force
|
|
||||||
currently running dhcpcd to try to renew the lease. This behavior
|
|
||||||
is similar to "pump -R".
|
|
||||||
|
|
||||||
04/15/00 - v.1.3.18-pl6
|
|
||||||
Jarno Huuskonen <jhuuskon@messi.uku.fi> submited patch to set
|
|
||||||
dhcpcd's process umask to 022 before creating /etc/resolv.conf file.
|
|
||||||
|
|
||||||
Scott Bronson <bronson@trestle.com> sent some feedback on how RH "pump"
|
|
||||||
behaves vs. dhcpcd. Now dhcpcd will also send second DHCP_DISCOVER
|
|
||||||
message.
|
|
||||||
|
|
||||||
Performing checksum on received packets is now optional and can be
|
|
||||||
switched on with -C option on dhcpcd command line.
|
|
||||||
|
|
||||||
03/27/00 - v.1.3.18-pl5
|
|
||||||
Lenz Grimmer <grimmer@suse.de> sent a patch to make dhcpcd do
|
|
||||||
reverse hostname lookup in a case DHCP server did not provide
|
|
||||||
hostName option with -H flag or in a case DHCP server did not provide
|
|
||||||
domainName option with -D flag to dhcpcd.
|
|
||||||
A bit enhanced version of the patch moved into "production".
|
|
||||||
|
|
||||||
03/27/00 - v.1.3.18-pl4
|
|
||||||
Removed "-m586" from Makefile.
|
|
||||||
The static executable contained with the distribution has been compiled
|
|
||||||
against glibc-2.1.3 and 2.3.99-pre3 kernel.
|
|
||||||
|
|
||||||
10/27/99 - v.1.3.18-pl3
|
|
||||||
Mike Hartman <wild@klondike.com> pointed out to include
|
|
||||||
NULL byte at the end of the HostName string.
|
|
||||||
|
|
||||||
10/26/99 - v.1.3.18-pl2
|
|
||||||
Mike Hartman <wild@klondike.com> submited a patch to fix
|
|
||||||
a bug in handling "-h" flag. Hostname option flag has been broken
|
|
||||||
since v.1.3.18-pl0.
|
|
||||||
|
|
||||||
09/17/99 - v.1.3.18-pl1
|
|
||||||
Put back "1.3.17-pl10" patch with some tweaking to get rid
|
|
||||||
of error in recvfrom call. Some minor cleanup.
|
|
||||||
|
|
||||||
09/01/99 - v.1.3.18-pl0
|
|
||||||
Reversed 1.3.17-pl10 patch. Binding dhcpSocket to the
|
|
||||||
interface produced error in recvfrom() call.
|
|
||||||
Chris G. Demetriou <cgd@netbsd.org> sent a patch
|
|
||||||
to make dhcpcd code portable to ARM platform.
|
|
||||||
Added "-s [ipaddr]" command-line option which makes dhcpcd
|
|
||||||
send DHCP_INFORM message. Added "-B" command-line option
|
|
||||||
to make dhcpcd solicit broadcast response. Added LOG_CONS option to
|
|
||||||
openlog(3). Changed "domain xxx" entry in resolv.conf to point
|
|
||||||
by default to nisDomainName, added "search nisDomainName" and
|
|
||||||
"search domainName" entries to resolv.conf file.
|
|
||||||
dhcpcd-<interface>.info file has minor changes to the format.
|
|
||||||
Namely, DNS and GATEWAY entries now will provide a comma-separated
|
|
||||||
list of corresponding IP addresses, not just the first IP address in
|
|
||||||
the list. Added support for static route option.
|
|
||||||
|
|
||||||
07/23/99 - v.1.3.17-pl10.
|
|
||||||
Johan Verrept <Johan.Verrept@alcatel.be> suggested "bind"-ing
|
|
||||||
dhcpSocket to the interface so the socket does not
|
|
||||||
receive packets from other interfaces. Change made to dhcpStart
|
|
||||||
routine to include a call to the bind().
|
|
||||||
|
|
||||||
07/09/99 - v.1.3.17-pl9.
|
|
||||||
PETAZZONI <jpetazzo@ryu.univ-mlv.fr> reported a case of
|
|
||||||
DHCP server responding with IpAddrLeaseTime=0 which
|
|
||||||
drove dhcpcd-1.3 mad. Added check for IpAddrLeaseTime=0 so
|
|
||||||
when dhcpcd receives IpAddrLeasetime=0 it will assume
|
|
||||||
DEFAULT_LEASETIME, infinite by default.
|
|
||||||
Added '-V' flag to dhcpcd syntax. Dhcpcd will print
|
|
||||||
copyright/version banner when used with '-V' flag.
|
|
||||||
|
|
||||||
06/19/99 - v.1.3.17-pl8.
|
|
||||||
Olivier Baudron <Olivier.Baudron@ens.fr> pointed out
|
|
||||||
to a problem with in_cksum routine when compiling with
|
|
||||||
egcs or gcc-2.8.xx compilers and proposed a patch to
|
|
||||||
work around the compiler bug.
|
|
||||||
Changed in_cksum routine in udpipgen.c file to
|
|
||||||
get rid of problems with wrong checksums if compiled
|
|
||||||
with egcs or gcc-2.8.xx compilers.
|
|
||||||
|
|
||||||
06/10/99 - v.1.3.17-pl7.
|
|
||||||
Hans Andersson <Hans.XH.Andersson@trab.se> and some
|
|
||||||
other gentlemen pointed out at 64-bit uncleanless of
|
|
||||||
current dhcpcd code, and sent relevant patches.
|
|
||||||
This release is an attempt to make dhcpcd-1.3
|
|
||||||
64-bit safe. No new functionality has been added.
|
|
||||||
This is left for v.1.3.18.
|
|
||||||
|
|
||||||
05/10/99 - v.1.3.17-pl6.
|
|
||||||
Andrew S. Howell <andy@tibco.com> submitted a patch
|
|
||||||
eliminating unnecessary padOptions in buildmsg.c file.
|
|
||||||
It helped with his cable modem. Removed
|
|
||||||
"Your IP address=xxx.xxx.xxx.xxx" message on a screen
|
|
||||||
when dhcpcd configures the interface.
|
|
||||||
|
|
||||||
03/14/99 - v.1.3.17-pl5.
|
|
||||||
Mike Benoit <ipso@academyoflearning.ca> submitted
|
|
||||||
debugging info. Change made to "client.c" to allow
|
|
||||||
dhcpcd to get router IP address from DHCP_ACK message
|
|
||||||
if it didn't come with DHCP_OFFER.
|
|
||||||
|
|
||||||
03/10/99 - v.1.3.17-pl4.
|
|
||||||
Tim Auckland <tim.auckland@Corp.Sun.COM> submitted
|
|
||||||
patch to dhcpcd-1.3.17-pl3 to close all standard
|
|
||||||
file descriptors when dhcpcd forks into background.
|
|
||||||
It should help with pcmcia cards which use popen() call.
|
|
||||||
|
|
||||||
02/04/99 - v.1.3.17-pl3.
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Now if dhcpcd does not get DHCP_ACK for the same
|
|
||||||
IP address as before reboot, it will fall back
|
|
||||||
to dhcpInit and will send DHCP_DISCOVER message(s).
|
|
||||||
Dhcpcd will now write pid file before forking
|
|
||||||
into background not after. Updated manual page.
|
|
||||||
|
|
||||||
01/15/99 - v.1.3.17-pl2.
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Changed the dhcpcd exec-bin directory from /usr/sbin to /sbin.
|
|
||||||
Pavel Polischouk <pavelp@iil.intel.com> sent a tcpdump
|
|
||||||
which inspired me to make some changes to the code
|
|
||||||
to avoid potential race condition when there are multiple
|
|
||||||
DHCP servers on the network.
|
|
||||||
|
|
||||||
01/12/99 - v.1.3.17-pl1.
|
|
||||||
Marc ZYNGIER <Marc.Zyngier@wanadoo.fr> submitted another
|
|
||||||
patch to dhcpcd-1.3 to make it work on Linux Alpha
|
|
||||||
platforms.
|
|
||||||
|
|
||||||
01/10/99 - v.1.3.17
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Came across patch for dhcpcd-1.3.16
|
|
||||||
submitted to linux.debian.alpha
|
|
||||||
by Marc Zyngier Marc.Zyngier@bull.net.
|
|
||||||
Changed the default lease time requested
|
|
||||||
to infinite.
|
|
||||||
Removed "mlip" client 'cause of www.ml.org death.
|
|
||||||
Did some other minor changes to the code.
|
|
||||||
|
|
||||||
11/09/98 - v.1.3.16
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Thanks to a great help from Brion Vibber <brion@pobox.com>
|
|
||||||
another nasty bug has been found and hopefully
|
|
||||||
squashed. Also the problem with setting default
|
|
||||||
route on some of the systems has been finally
|
|
||||||
solved. Kernel refuses to accept a route for a gateway
|
|
||||||
if its IP address does not seem to be on the same
|
|
||||||
subnet as in a case with bridged subnets.
|
|
||||||
The work around suggested by Brion Vibber is
|
|
||||||
to add a local route to the gateway. I hope we've got
|
|
||||||
it right in v.1.3.16.
|
|
||||||
|
|
||||||
11/07/98 - v.1.3.15
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Fixed rather nasty bug in dhcpSendAndRecv routine
|
|
||||||
introduced in v.1.3.13 which might have prevented
|
|
||||||
quite of few users from receiving DHCP_OFFER message.
|
|
||||||
Added command-line options -D,-H,-R to dhcpcd.
|
|
||||||
Request and patch submitted by Aron Griffis <agriffis@css.tayloru.edu>
|
|
||||||
|
|
||||||
10/28/98 - v.1.3.14
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Removed setting a local route in addition to default one
|
|
||||||
in v.1.3.13. This did not help with the problem
|
|
||||||
one user experiences with setting a default route but
|
|
||||||
rather resulted in duplicate entries for the local
|
|
||||||
route in the routing table.
|
|
||||||
|
|
||||||
10/27/98 - v.1.3.13
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Fixed a minor bug in dhcpSendAndRecv routine
|
|
||||||
which caused quite a few bogus "DHCP server declined request: op=XX"
|
|
||||||
messages in /var/log/debug file.
|
|
||||||
Add (or rather put back) setting of local route.
|
|
||||||
Normally the local route is set automatically by
|
|
||||||
the kernel when default route entry is added, however
|
|
||||||
as it seems that doesn't always work for everybody.
|
|
||||||
|
|
||||||
10/25/98 - v.1.3.12
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Made a good faith attempt to squash a bug in UDP/IP
|
|
||||||
layer of dhcpcd which might have been a cause of
|
|
||||||
problems on PPC-based systems. Originally reported
|
|
||||||
by Martin Costabel <martin@wanadoo.fr>.
|
|
||||||
Rewrote quite a bit of UDP/IP code so if dhcpcd-1.3.12
|
|
||||||
doesn't work for you at all you may try v.1.3.11.
|
|
||||||
There seemed to be a problem with setting default
|
|
||||||
route on 2.1.125 kernel reported by Brion Vibber
|
|
||||||
<brion@pobox.com>. Changed "dhcpConfig" to not force
|
|
||||||
dhcpcd to die if it cannot set default route. At least
|
|
||||||
it would be easier to find the cause of problem...
|
|
||||||
Also did some changes to "client.c" code to move it
|
|
||||||
closer to the point when one can add support for Token Ring
|
|
||||||
and/or other link protocols.
|
|
||||||
|
|
||||||
10/15/98 - v.1.3.11
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Put back '-c filename' option for dhcpcd due to
|
|
||||||
a requests from some users of Mediaone cable modems
|
|
||||||
who were trying to use 'ipup' et similar bootup scripts.
|
|
||||||
Originally requested by Robert Shapiro <rshapiro@mediaone.com>
|
|
||||||
Some minor fixes.
|
|
||||||
|
|
||||||
10/13/98 - v.1.3.10
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Added a new feature: whenever the assigned IP address for the
|
|
||||||
interface changes dhcpcd will execute /etc/dhcpc/dhcpcd-interface.exe
|
|
||||||
program. The word <interface> is substituted by
|
|
||||||
the actual interface name like e.g. eth0.
|
|
||||||
Caution: do not use /etc/dhcpc/dhcpcd-interface.exe as a bootup
|
|
||||||
script. It will not be executed if the assigned IP address
|
|
||||||
is the same as it was before reboot.
|
|
||||||
The included sample /etc/dhcpc/dhcpcd-interface.exe will log
|
|
||||||
the time of IP change to /var/log/messages file.
|
|
||||||
The included mlip program changes the IP address
|
|
||||||
for your host at DNS servers provided by www.ml.org
|
|
||||||
in a case you happen to be a member of Monolith's DynDNS.
|
|
||||||
Edit mlip.h file to supply your hostname, username, and password at
|
|
||||||
Monolith. Do "make mlip" to compile it. Then copy the executable
|
|
||||||
to /etc/dhcpc/dhcpcd-interface.exe.
|
|
||||||
|
|
||||||
Added a compile time options '-DSETHOSTNAME' and '-DSETDOMAINNAME'
|
|
||||||
to Makefile. If used, dhcpcd will set hostname and/or domainname
|
|
||||||
of the host to the values it receives from DHCP server.
|
|
||||||
|
|
||||||
Rehashed the Changes file to reverse the time order of entries.
|
|
||||||
|
|
||||||
10/02/98 - v.1.3.9
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Reduced the timeouts for sending and receiving DHCP messages.
|
|
||||||
Commented out arpCheck() call. It didn't work anyway
|
|
||||||
because there won't be ARP_REPLY message unless the
|
|
||||||
sender's IP address is set which defeats the purpose
|
|
||||||
of doing ARP check. This is something for the authors
|
|
||||||
of RFC 2131 to fix.
|
|
||||||
|
|
||||||
09/04/98 - v.1.3.8
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Some user reported he couldn't get dhcpcd to configure
|
|
||||||
interface because it failed to set broadcast address.
|
|
||||||
Changed the order dhcpcd configures the interface so it does
|
|
||||||
1. sets IP address
|
|
||||||
2. sets netmask
|
|
||||||
3. sets broadcast address (redundant?)
|
|
||||||
Reduced the timeout for ARP check from 10secs to 3 secs, so
|
|
||||||
dhcpcd finishes faster.
|
|
||||||
|
|
||||||
08/01/98 -
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
Changed the "time since bootup" parameter in DHCP_DISCOVER
|
|
||||||
message from zero to 5 secs to accomodate for WinNT DHCP server
|
|
||||||
wishes. General cleanup.
|
|
||||||
|
|
||||||
01/31/98 -
|
|
||||||
Sergei Viznyuk <sv@phystech.com> :
|
|
||||||
Changed dhcpcd to use socket(AF_PACKET,SOCK_PACKET,..)
|
|
||||||
instead of socket(AF_INET,SOCK_DGRAM,..) which did not
|
|
||||||
work with newer kernels.
|
|
||||||
Dropped 'dhcpcd -c filename' usage in favor of dhcpcd
|
|
||||||
returning valid exit status to the parent.
|
|
||||||
Added '-t timeout' option which specifies for how
|
|
||||||
long 'dhcpcd' will try to get an IP address before
|
|
||||||
forking into background.
|
|
||||||
Changed 'dhcpcd -d' option to be a debug flag.
|
|
||||||
|
|
||||||
|
|
||||||
======== before v.1.3 ============
|
|
||||||
|
|
||||||
08/28/97 1. added '-I' (client identifier) option.
|
|
||||||
0.70 2. added '-h' (hostname) option (Note 10).
|
|
||||||
|
|
||||||
04/24/97 changed the source UDP port from a random number to 68
|
|
||||||
0.65 because some servers respond to NOT port 68 but the source
|
|
||||||
UDP port in the received datagram (Note 9).
|
|
||||||
|
|
||||||
03/16/97 1. fixed the bug that DHCPDECLINE message was RFC1541
|
|
||||||
0.6 compliant. Now dhcpcd can send both Interned Draft
|
|
||||||
compliant DHCPDECLINE message and RFC1541 compliant
|
|
||||||
one (mkDhcpDeclineMsg).
|
|
||||||
2. fixed the bug that the broadcast address and the
|
|
||||||
subnetmask were set to the wrong value under the
|
|
||||||
following condition:
|
|
||||||
1. dhcpcd is in the REBOOTING state
|
|
||||||
2. received DHCP ACK msg does not include the
|
|
||||||
broadcast or subnetmask option.
|
|
||||||
(rebooting in client.c)
|
|
||||||
3. fixed the bug that dhcpcd does not send a DHCPDECLINE
|
|
||||||
msg when it detects the duplicate IP adddress
|
|
||||||
(arpCheck in arp.c)..
|
|
||||||
4. changed the way to make a DHCPREQUEST msg in the
|
|
||||||
SELECTING state (selecting, mkDhcpRequestMsg)
|
|
||||||
5. changed the pcmcia/network script to unmount the NFS
|
|
||||||
filesystems before invoking "dhcpcd -k" command when
|
|
||||||
the card service goes down.
|
|
||||||
6. added a new environment variable DHCP_DEVICE, which
|
|
||||||
contains the name of network interface to which
|
|
||||||
dhcpcd is attached.
|
|
||||||
|
|
||||||
03/07/97 1. fixed the bug that the renewal time and the rebind time
|
|
||||||
are messed up (becomes minus number :p) when dhcpcd gets
|
|
||||||
the lease time whose least significant byte is greater
|
|
||||||
than or equal to 0x80 (setDhcpInfo in client.c) (Note 7).
|
|
||||||
For example, if the lease time is 24 hours, dhcpcd does
|
|
||||||
not work.
|
|
||||||
2. added the hostname option to the parameter request list
|
|
||||||
(mkDhcpDiscoverMsg and mkDhcpRequestMsg in client.c)
|
|
||||||
3. fixed the bug that dhcpcd sends a DHCPREQUEST message
|
|
||||||
which does not have the server identifier option in the
|
|
||||||
SELECTING state (mkDhcpRequestMsg in client.c)
|
|
||||||
4. fixed the bug that dhcpcd uses the information from the
|
|
||||||
DHCPOFFER message for configuring the host (it must use
|
|
||||||
the information from the DHCPREQUEST message) (initHost
|
|
||||||
in client.c) (Note 8).
|
|
||||||
|
|
||||||
01/30/97 made version 0.5a2 into 0.5, and released it.
|
|
||||||
0.5
|
|
||||||
|
|
||||||
01/20/97 changed init, renewing, rebinding (client.c), and
|
|
||||||
0.5a2 rcvAndCheckDhcpMsg (socket-if.c) to fix the bug that dhcpcd
|
|
||||||
exited with holding the assigned IP address when it failed in
|
|
||||||
invoking sendto system call in the RENEWING state. This happened
|
|
||||||
when the server is down in the RENEWING state. It causes
|
|
||||||
hosts to use expired IP addresses (how dangerous!). Now
|
|
||||||
dhcpcd does not exit even when it gets an error from sendto
|
|
||||||
in the RENEWING state. It continues to use the assigned IP
|
|
||||||
address until the lease time is expired, then it
|
|
||||||
initializes the network interface and goes into the INIT
|
|
||||||
state (Note 6).
|
|
||||||
|
|
||||||
01/13/97 1. added IFF_MULTICAST in initHost (client.c) (Note 1).
|
|
||||||
0.5a 2. fixed the bug that dhcpcd core-dumped when it received a
|
|
||||||
datagram containig the DHCP message option (parseDhcpMsg
|
|
||||||
in options.c) (Note 2).
|
|
||||||
3. added -r option which makes dhcpcd RFC1541 compliant
|
|
||||||
(Note 3).
|
|
||||||
4. changed mkDhcpRequestMsg (client.c) to put the
|
|
||||||
parameter request list option into the DHCPREQUEST
|
|
||||||
message in order to support the CMU version of DHCP
|
|
||||||
server (Note 4). But I do not check whether it works
|
|
||||||
with the CMU version of DHCP server.
|
|
||||||
5. changed the argument to logOpen from LOG_CONS to LOG_PID
|
|
||||||
(Note 5).
|
|
||||||
6. add nextState initialization in rebinding (client.c).
|
|
||||||
7. changed the host information file name from "hostinfo"
|
|
||||||
to "hostinfo-ifname" (saveHostInfo in hostinfo.c)
|
|
||||||
(Note 5). Ifname is actually replaced with the network
|
|
||||||
interface name like "eth0". This is good when multiple
|
|
||||||
dhcpcd's attach to different network interfaces.
|
|
||||||
|
|
||||||
09/22/96 made dhcpcd compliant to the Internet Draft in order to
|
|
||||||
0.4 work with ISC version of DHCP server.
|
|
||||||
Changed client.c, options.c, socket-if.c
|
|
||||||
|
|
||||||
09/19/96 quick fix to make it work with ISC's dhcpd. I made BROACAST
|
|
||||||
0.33 flag available and added the NEED_BCAST_RESPONSE macro.
|
|
||||||
ISC's DHCP server is the Internet Draft compliant, but
|
|
||||||
dhcpcd is RFC1541 compliant. So this is a "workaround" version.
|
|
||||||
|
|
||||||
09/17/96 added the code checking option field to parseDhcpMsg (options.c)
|
|
||||||
0.32
|
|
||||||
|
|
||||||
09/16/96 fixed a typo in selecting (client.c)
|
|
||||||
0.31
|
|
||||||
|
|
||||||
09/13/96 1. enhanced NTP support. Now dhcpcd creates the file, ntp.conf
|
|
||||||
0.3 in the directory, /etc/dhcpc.
|
|
||||||
2. added the code verifying if router addresses are correct
|
|
||||||
|
|
||||||
09/12/96 added the following sample shell scripts:
|
|
||||||
0.3b 1. "network" for pcmcia-cs
|
|
||||||
2. "rc" scripts (rc.inet1, rc.inet2, rc.M)
|
|
||||||
3. "rc.dhcp", a command file which can be executed from dhcpcd
|
|
||||||
|
|
||||||
09/11/96 1. fixed a bug in setDefRoute (if.c). rt_flags was RT_UP.
|
|
||||||
0.3a It should be RT_GATEWAY.
|
|
||||||
2. fixed typos in openRecvSocket (socket-if.c)
|
|
||||||
3. changed the way to invoke a command file from using
|
|
||||||
signal to forking twice
|
|
||||||
4. removed unnecessary socket close/re-open
|
|
||||||
|
|
||||||
09/09/96 added support to the "router" option.
|
|
||||||
0.25a changed files: options.c, dhcp-options.h, dhcp.h, hostinfo.c,
|
|
||||||
if.c, client.c
|
|
||||||
|
|
||||||
08/09/96 added the code to make a copy of the DHCP options in the
|
|
||||||
0.2 DHCPOFFER message because Windows NT server does not put
|
|
||||||
DHCP options in the DHCPACK message except for netmask, T1
|
|
||||||
time, and T2time. Other DHCP options are only in the
|
|
||||||
DHCPOFFER message.
|
|
||||||
|
|
||||||
07/27/96 added '-i' option specifying the class identifier because
|
|
||||||
0.2a RFC1541 says "The client implementation of DHCP should
|
|
||||||
provide a mechanism for the user to select directly the
|
|
||||||
'class-identifier' value.".
|
|
||||||
|
|
||||||
07/23/96 1. moved ARP check from just after dhcpcd received a
|
|
||||||
0.2a DHCPOFFER message to just after dhcpcd received a
|
|
||||||
DHCPACK message.
|
|
||||||
2. added 'Parameter Request List' in the DHCPDISCOVER message.
|
|
||||||
3. added code to output the content of DHCP message option from
|
|
||||||
the server
|
|
||||||
|
|
||||||
Note 1: Koji Okamura suggested this.
|
|
||||||
Note 2: This fix was made by Dan Halbert.
|
|
||||||
Note 3: Dan Halbert found that dhcpcd-0.4 does not work with some
|
|
||||||
RFC1541 compliant DHCP servers, and made a patch for it.
|
|
||||||
Brandon Mitchell suggested -r option.
|
|
||||||
Note 4: N. Komazaki found that CMU's DHCP server (dhcpd-3.3.7
|
|
||||||
+patch) requires the parameter request option in the
|
|
||||||
DHCPREQUEST message.
|
|
||||||
Note 5: Ulrich Windl suggested this.
|
|
||||||
Note 6: Koji Okamura found this bug.
|
|
||||||
Note 7: Andrew Kieschnick found this bug.
|
|
||||||
Note 8: Tim Riker found this bug.
|
|
||||||
Note 9: I found this problem by using the tcpdump log which
|
|
||||||
Larry Hawkins sent me.
|
|
||||||
Note 10: I found some DHCP servers require this option by using the
|
|
||||||
tcpdump log which David Filiatrault sent me.
|
|
||||||
|
|
@@ -1,25 +0,0 @@
|
|||||||
INCLUDES = -I${top_srcdir} -I${top_srcdir}/src
|
|
||||||
|
|
||||||
noinst_LIBRARIES = libdhcpc.a
|
|
||||||
|
|
||||||
libdhcpc_a_CPPFLAGS = \
|
|
||||||
-DBINDIR=\"$(bindir)\" \
|
|
||||||
-DDATADIR=\"$(datadir)\" \
|
|
||||||
-DARP_DEBUG \
|
|
||||||
-DDEBUG
|
|
||||||
|
|
||||||
libdhcpc_a_SOURCES= \
|
|
||||||
buildmsg.c \
|
|
||||||
buildmsg.h \
|
|
||||||
arp.c \
|
|
||||||
arp.h \
|
|
||||||
client.c \
|
|
||||||
client.h \
|
|
||||||
dhcpcd.c \
|
|
||||||
dhcpcd.h \
|
|
||||||
udpipgen.c \
|
|
||||||
udpipgen.h
|
|
||||||
|
|
||||||
noinst_PROGRAMS = dhcp_test
|
|
||||||
dhcp_test_SOURCES = dhcp_test.c
|
|
||||||
dhcp_test_LDADD = libdhcpc.a
|
|
@@ -1,3 +0,0 @@
|
|||||||
Please refer to
|
|
||||||
http://www.phystech.com/download/
|
|
||||||
|
|
276
dhcpcd/README
276
dhcpcd/README
@@ -1,276 +0,0 @@
|
|||||||
0. Introduction
|
|
||||||
|
|
||||||
This is an RFC2131,RFC2132, and RFC1541 compliant DHCP client daemon.
|
|
||||||
RFC1541 was obsoleted by RFC2131, but there are still some RFC1541 compliant
|
|
||||||
DHCP servers. dhcpcd gets an IP address and other information from a
|
|
||||||
corresponding DHCP server, configures the network interface
|
|
||||||
automatically, and tries to renew the lease time according to RFC2131
|
|
||||||
or RFC1541 depending on the command line option.
|
|
||||||
|
|
||||||
dhcpcd-1.3 has been reported to compile
|
|
||||||
on Intel,PPC, and Alpha-based Linux platforms
|
|
||||||
providing glibc-2.0.5 or later has been
|
|
||||||
installed. Please refer to the Notes below for details.
|
|
||||||
|
|
||||||
dhcpcd-1.3 has been reported as compatible with DHCP servers
|
|
||||||
used by the following network service providers:
|
|
||||||
|
|
||||||
1. Time Warner RoadRunner http://www.rr.com/
|
|
||||||
2. MediaOne (now AT&T Broadband) http://www.attbroadband.com/
|
|
||||||
3. Comcast.Net, formerly @Home Networks http://www.comcast.net/
|
|
||||||
4. France Telecom ADSL http://www.wanadoo.fr/
|
|
||||||
5. USWest.net DSL (now Qwest) http://www.uswest.com/
|
|
||||||
6. France CyberCable http://www.cybercable.fr/
|
|
||||||
7. BellSouth ADSL http://www.bellsouth.net/
|
|
||||||
8. BCtel Multimedia Gateway ADSL http://www.bctel.net/
|
|
||||||
9. Cogeco Cable Canada http://www.cogeco.ca/
|
|
||||||
10.Sympatico High Speed Edition ADSL http://www.hse.sympatico.ca/
|
|
||||||
11.Adelphia PowerLink http://powerlink.adelphia.net/
|
|
||||||
12.Videotron, Canada http://www.videotron.ca/
|
|
||||||
13.Access Cable, Nova Scotia, Canada http://www.accesscable.net/
|
|
||||||
14.A2000 Cable, Netherlands http://www.a2000.nl/
|
|
||||||
15.Tele-Communications, Inc http://www.tci.com/
|
|
||||||
16.Telenet, Belgium http://www.telenet.be/
|
|
||||||
17.Telekabel Wien, Austria http://www.telekabel.at/
|
|
||||||
18.RMCnet, France http://www.rmcnet.fr/
|
|
||||||
19.Retecal, Spain http://www.retecal.es/
|
|
||||||
20.TVD, Belgium http://www.tvd.net/
|
|
||||||
21.Optimum Online, NY http://www.optimumonline.com/
|
|
||||||
22.Knology Comm. http://www.knology.com/
|
|
||||||
23.Highpernet, Switzeland. http://www.highpernet.ch/
|
|
||||||
24.TeledisNet, Belgium. http://www.teledisnet.be/
|
|
||||||
25.Southwestern Bell DSL. http://www.swbell.net/
|
|
||||||
26.Brutele, Belgium. http://www.brutele.be/
|
|
||||||
27.Telus, Canada. http://www.telusplanet.net/
|
|
||||||
28.Chello, Netherlands. http://www.chello.nl/
|
|
||||||
29.RCN. http://www.rcn.com/
|
|
||||||
30.Pandora, Belgium. http://www.pandora.be/
|
|
||||||
31.Armstrong's Cable Services, PA. http://www.zbzoom.net/
|
|
||||||
32.21st Century, Chicago. http://www.21stcentury.net/
|
|
||||||
33.Supercable, Spain. http://www.supercable.es/
|
|
||||||
34.Primacom, Germany. http://www.primacom.net/
|
|
||||||
35.Click! Network, Tacoma, WA. http://www.click-network.com/
|
|
||||||
36.Telocity, Cupertino, CA. http://www.telocity.com/
|
|
||||||
37.Charter Communications. http://www.chartercom.com/
|
|
||||||
38.Tebenet, Netherlands. http://www.tebenet.nl/
|
|
||||||
39.ZoomTown, Cincinnati, OH. http://www.zoomtown.com/
|
|
||||||
40.Telecom New Zealand Jetstream ADSL. http://www.telecom.co.nz/
|
|
||||||
41.Belgacom Turboline ADSL. http://www.turboline.be/
|
|
||||||
42.ISP Channel. http://www.ispchannel.com/
|
|
||||||
43.Telia.Com Sweden. http://www.telia.com/
|
|
||||||
44.Netcabo Portugal. http://www.netcabo.pt/
|
|
||||||
45.CyberCity xDSL, Denmark. http://www.cybercity.dk/
|
|
||||||
46.Tokyo Metallic Comm. http://www.metallic.co.jp/
|
|
||||||
47.Telenor, Norway. http://www.telenor.no/
|
|
||||||
48.Telstra, Austria. http://www.telstra.com/
|
|
||||||
49.Look Wireless, Montreal. http://www.look.ca/
|
|
||||||
50.Virtua, Brazil. http://www.virtua.com.br/
|
|
||||||
51.Verizon DSL. http://www.verizon.com/dsl/
|
|
||||||
52.Sonera, Netherlands. http://www.soneraplaza.nl/
|
|
||||||
53.NTL, UK. http://www.ntl.co.uk/cablemodems/
|
|
||||||
54.Telewest, UK. http://www.telewest.co.uk/
|
|
||||||
55.VTR, Chile. http://www.vtr.net/
|
|
||||||
56.Millennium Digital Media. http://www.mdm.net/
|
|
||||||
57.Madritel, Spain. http://www.madritel.es/
|
|
||||||
58.Cistron Telecom, Netherlands. http://www.cistron.nl/
|
|
||||||
59.Cox Express, Las Vegas. http://www.cox.com/
|
|
||||||
60.Cablecom GMBH, Switzerland. http://www.hispeed.ch/
|
|
||||||
61.Elektro Ablasser Hausmannstaetten, Austria. http://www.catv4u.at/
|
|
||||||
62.Kiva Networking, Indiana. http://www.kiva.net/
|
|
||||||
63.Blueyonder, UK. http://www.blueyonder.co.uk/
|
|
||||||
64.Salzburg-Online, Austria. http://www.salzburg-online.at/
|
|
||||||
65.Cablenet, Colombia. http://www.cable.net.co/
|
|
||||||
66.i-Cable, Hong Kong. http://www.i-cable.com/
|
|
||||||
67.Shaw High Speed. http://www.shaw.ca/
|
|
||||||
68.Rogers Communications. http://www.rogers.com/
|
|
||||||
69.Chello, France. http://www.chello.fr/
|
|
||||||
70.Acesserapido, Brazil. http://www.acesserapido.com.br/
|
|
||||||
71.Wirefire. http://www.wirefire.com/
|
|
||||||
72.Ajato, Brazil. http://www.ajato.com.br/
|
|
||||||
73.TDC/TeleDanmark, Denmark. http://www.teledanmark.dk/
|
|
||||||
74.Telstra Bigpond Broadband ADSL, Australia. http://www.bigpond.com.au/
|
|
||||||
75.Eastern Connecticut Cable. http://www.myeastern.com/
|
|
||||||
76.ADSL Brazil Telecom. http://www.internetturbo.com.br/
|
|
||||||
77.InsightBB.com. http://www.insightbb.com/
|
|
||||||
78.S?derhamn Teknikpark AB, Sweden. http://www.teknikpark.se/
|
|
||||||
79.Tele 2, Sweden. http://www.tele2.se/
|
|
||||||
|
|
||||||
if you have been successfully using dhcpcd-1.3
|
|
||||||
on your network please report the fact along
|
|
||||||
with network provider's name/URL/whatever and dhcpcd version
|
|
||||||
to the author <sv@phystech.com>.
|
|
||||||
|
|
||||||
dhcpcd-1.3 primary web site is
|
|
||||||
http://www.phystech.com/download/
|
|
||||||
ftp://ftp.phystech.com/pub/
|
|
||||||
|
|
||||||
1. Install
|
|
||||||
|
|
||||||
Make sure your kernel is compiled with support for SOCK_PACKET
|
|
||||||
(CONFIG_PACKET option). Cd to source distribution directory. Do
|
|
||||||
./configure --prefix=/
|
|
||||||
Please note the GNU default installation --prefix=/usr/local
|
|
||||||
is not what most users want for dhcpcd installation.
|
|
||||||
Edit Makefile to customize compile time options.
|
|
||||||
Do 'make' followed by 'make install'.
|
|
||||||
To enable dhcpcd error logging add the following line to your
|
|
||||||
/etc/syslog.conf file:
|
|
||||||
local0.* /var/log/dhcpcd.log
|
|
||||||
and then refresh syslogd daemon:
|
|
||||||
kill -1 `cat /var/run/syslogd.pid`
|
|
||||||
|
|
||||||
Note 1.
|
|
||||||
to compile dhcpcd-1.3.X you have to install glibc-2.0.5 or later.
|
|
||||||
dhcpcd-1.3.X might not compile under libc.5.
|
|
||||||
If you don't have glibc installed you can use the precompiled
|
|
||||||
binary included with the distribution.
|
|
||||||
If you are trying to compile dhcpcd yourself and getting error
|
|
||||||
"cannot find net/ethernet.h file", you don't have glibc
|
|
||||||
installed.
|
|
||||||
|
|
||||||
Note 2.
|
|
||||||
some releases of GNU C compiler, notably
|
|
||||||
gcc-2.8.1 are buggy. The same goes for egcs as of 05/10/99.
|
|
||||||
If you have compiled dhcpcd with gcc-2.8.1 or egcs you may
|
|
||||||
get the following errors in dhcpcd.log file:
|
|
||||||
May 4 12:43:03 dhcpcd[423]: corrupted UDP msg with uh_ulen=319 in_cksum=-2 discarded
|
|
||||||
and dhcpcd won't work. The workaround is to compile dhcpcd without
|
|
||||||
-O2 in Makefile.
|
|
||||||
|
|
||||||
Note 3.
|
|
||||||
if you are trying to run dhcpcd and are getting the following error in
|
|
||||||
the log file:
|
|
||||||
dhcpcd[xx]: dhcpStart: socket(): Invalid argument
|
|
||||||
it means you kernel is compiled without support for SOCK_PACKET
|
|
||||||
(CONFIG_PACKET option).
|
|
||||||
|
|
||||||
Note 4.
|
|
||||||
if your dhcpcd binary compiles fine and runs OK with "--help" flag
|
|
||||||
only and otherwise immediately coredumps with "Segmentation Fault"
|
|
||||||
error then delete /etc/dhcpc/dhcpcd-<interface>.cache file and
|
|
||||||
try running dhcpcd again. There is a chance your dhcpcd cache file
|
|
||||||
is from old version of dhcpcd.
|
|
||||||
|
|
||||||
Note 5.
|
|
||||||
If you replace your network card or upgrade to a different version of
|
|
||||||
dhcpcd you might not be able to obtain the same old IP address from
|
|
||||||
DHCP server. This is because the DHCP server identifies clients by
|
|
||||||
ClientID DHCP option which by default is MAC address of the network
|
|
||||||
card. The work around is to use -I ClientID option with some
|
|
||||||
unique "ClientID" string.
|
|
||||||
Also, upgrading to a different version of dhcpcd invalidates *.cache
|
|
||||||
file where dhcpcd stores IP address which it tries to renew on restart.
|
|
||||||
|
|
||||||
2. How to Use It
|
|
||||||
|
|
||||||
Invoke the client by typing 'dhcpcd'. Note you should NOT
|
|
||||||
explicitly put it in the background with the '&' character -
|
|
||||||
background processing is automatic unless 'dhcpcd' was
|
|
||||||
compiled with -DDEBUG flag. Dhcpcd will fork into background
|
|
||||||
as soon as it configures the interface. By default, dhcpcd will
|
|
||||||
attach to 'eth0' unless you explicitly give an interface name on the
|
|
||||||
command line.
|
|
||||||
The example below demonstrates dhcpcd usage in a case where
|
|
||||||
linux box serves as a router/firewall for the local network 192.168.12.0.
|
|
||||||
|
|
||||||
if dhcpcd eth1; then
|
|
||||||
inetd
|
|
||||||
/usr/sbin/sendmail -bd
|
|
||||||
httpd
|
|
||||||
echo 1 > /proc/sys/net/ipv4/ip_forward
|
|
||||||
modprobe ip_tables
|
|
||||||
modprobe iptable_nat
|
|
||||||
modprobe iptable_filter
|
|
||||||
modprobe ipt_MASQUERADE
|
|
||||||
modprobe ip_nat_ftp
|
|
||||||
modprobe ip_conntrack_ftp
|
|
||||||
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
|
|
||||||
else
|
|
||||||
echo "**** Unable to configure eth0"
|
|
||||||
fi
|
|
||||||
|
|
||||||
The bootup process will wait until 'dhcpcd' configures
|
|
||||||
interface or until dhcpcd times out before proceeding further.
|
|
||||||
|
|
||||||
Any time dhcpcd configures or shuts down interface it will try to
|
|
||||||
execute <ConfigDir>/dhcpcd.exe script with appropriate
|
|
||||||
parameters passed. The exact pathname of the executable script can be
|
|
||||||
changed with "-c ExecFilePath" dhcpcd option. The <ConfigDir>
|
|
||||||
directory can be specified with "-L <ConfigDir>" option, otherwise
|
|
||||||
it defaults to /etc/dhcpc/. The dhcpcd.exe script invokation is:
|
|
||||||
<ConfigDir>/dhcpcd.exe <HostInfoFilePath> <up|down|new> [-d]
|
|
||||||
where <HostInfoFilePath> is actually <ConfigDir>/dhcpcd-<interface>.info
|
|
||||||
file; optional parameter [-d] is a debug flag passed if dhcpcd has
|
|
||||||
been invoked with -d flag. The second parameter to dhcpcd.exe script is
|
|
||||||
"up" if the interface has been configured with the same IP
|
|
||||||
address as before reboot, "down" if the interface has been shut
|
|
||||||
down, "new" if the interface has been configured with new IP address.
|
|
||||||
|
|
||||||
3. Supported DHCP Options
|
|
||||||
|
|
||||||
The current version of dhcpcd supports the following DHCP options:
|
|
||||||
|
|
||||||
o lease time
|
|
||||||
o renewal (T1) time
|
|
||||||
o rebind (T2) time
|
|
||||||
o netmask
|
|
||||||
o broadcast address
|
|
||||||
o router
|
|
||||||
o dns
|
|
||||||
o host name
|
|
||||||
o domain name
|
|
||||||
o nis domain name
|
|
||||||
o nis servers
|
|
||||||
o ntp servers
|
|
||||||
o static routes
|
|
||||||
|
|
||||||
5. Cache File
|
|
||||||
|
|
||||||
dhcpcd saves the assigned IP address into the file
|
|
||||||
<ConfigDir>/dhcpcd-<interface>.cache (the word <interface> is actually
|
|
||||||
replaced with the interface name like eth0, etc. to which dhcpcd is
|
|
||||||
attached) so that it can try to use that IP address when it is invoked
|
|
||||||
next time. Remove the file <ConfigDir>/dhcpcd-<interface>.cache before
|
|
||||||
you invoke dhcpcd unless you like using the previously assigned IP
|
|
||||||
address.
|
|
||||||
|
|
||||||
6. Information File
|
|
||||||
|
|
||||||
dhcpcd writes the configuration information into
|
|
||||||
<ConfigDir>/dhcpcd-<interface>.info file. The word <interface> is actually
|
|
||||||
replaced with the interface name like eth0, etc. to which dhcpcd is
|
|
||||||
attached. That file may be included into a Bourne or Korn shell script
|
|
||||||
to set an environment variables like e.g. HOSTNAME, DOMAIN, NETMASK, etc.
|
|
||||||
The supplied sample <ConfigDir>/dhcpcd.exe script demonstrates usage
|
|
||||||
of <ConfigDir>/dhcpcd-<interface>.info file.
|
|
||||||
|
|
||||||
7. Other Information
|
|
||||||
|
|
||||||
dhcpcd sends DHCP_RELEASE message to the DHCP server, deletes the
|
|
||||||
<ConfigDir>/dhcpcd-<interface>.cache file and brings the attached
|
|
||||||
network interface down when it gets SIGHUP signal. It will
|
|
||||||
not send DHCP_RELEASE message and will not delete
|
|
||||||
<ConfigDir>/dhcpcd-<interface>.cache file in a case it gets
|
|
||||||
SIGTERM as normally happens upon reboot.
|
|
||||||
|
|
||||||
dhcpcd may be used to obtain multiple IP addresses for the same
|
|
||||||
dummy interface providing one invokes dhcpcd with
|
|
||||||
-I ClientID -L ConfigDir -T -c ExecFilePath
|
|
||||||
options where ClientID and ConfigDir are unique to each of the requested
|
|
||||||
IP addresses. The same way it can be used to obtain IP addresses
|
|
||||||
for virtual interfaces, e.g. eth0:1
|
|
||||||
|
|
||||||
dhcpcd currently supports only Ethernet link protocol.
|
|
||||||
|
|
||||||
8. In case dhcpcd does not work:
|
|
||||||
Run 'dhcpcd -d' and mail me the relevant messages
|
|
||||||
from /var/log/dhcpcd.log file. Also run
|
|
||||||
tcpdump -evvn -i eth0
|
|
||||||
and mail me the results of that.
|
|
||||||
If the things are too bad for you,
|
|
||||||
uncomment -DDEBUG flag in Makefile
|
|
||||||
and recompile 'dhcpcd'. Run 'dhcpcd -d'
|
|
||||||
and mail me what you see.
|
|
||||||
|
|
||||||
Sergei Viznyuk <sv@phystech.com>
|
|
||||||
|
|
195
dhcpcd/arp.c
195
dhcpcd/arp.c
@@ -1,195 +0,0 @@
|
|||||||
/*
|
|
||||||
* dhcpcd - DHCP client daemon -
|
|
||||||
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
*
|
|
||||||
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
|
|
||||||
*
|
|
||||||
* This 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <net/if_arp.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <syslog.h>
|
|
||||||
#include "client.h"
|
|
||||||
#include "arp.h"
|
|
||||||
|
|
||||||
#define BasicArpLen(A) (sizeof(A) - (sizeof(A.ethhdr) + sizeof(A.pad)))
|
|
||||||
|
|
||||||
extern int DebugFlag;
|
|
||||||
|
|
||||||
int eth2tr(struct packed_ether_header *frame, int datalen);
|
|
||||||
int tr2eth(struct packed_ether_header *frame);
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
#ifdef ARPCHECK
|
|
||||||
int arpCheck(const dhcp_interface *iface)
|
|
||||||
{
|
|
||||||
arpMessage arp_msg_send;
|
|
||||||
arpMessage arp_msg_recv;
|
|
||||||
struct sockaddr addr;
|
|
||||||
int j,i=0;
|
|
||||||
|
|
||||||
memset (&arp_msg_send, 0, sizeof(arpMessage));
|
|
||||||
memcpy (arp_msg_send.ethhdr.ether_dhost, MAC_BCAST_ADDR, ETH_ALEN);
|
|
||||||
memcpy (arp_msg_send.ethhdr.ether_shost, iface->chaddr, ETH_ALEN);
|
|
||||||
arp_msg_send.ethhdr.ether_type = htons(ETHERTYPE_ARP);
|
|
||||||
|
|
||||||
arp_msg_send.htype = htons(ARPHRD_ETHER);
|
|
||||||
arp_msg_send.ptype = htons(ETHERTYPE_IP);
|
|
||||||
arp_msg_send.hlen = ETH_ALEN;
|
|
||||||
arp_msg_send.plen = 4;
|
|
||||||
arp_msg_send.operation = htons(ARPOP_REQUEST);
|
|
||||||
memcpy (arp_msg_send.sHaddr, iface->chaddr, ETH_ALEN);
|
|
||||||
memcpy (&arp_msg_send.tInaddr, &(iface->ciaddr), 4);
|
|
||||||
|
|
||||||
if ( DebugFlag )
|
|
||||||
{
|
|
||||||
syslog(LOG_DEBUG, "broadcasting ARPOP_REQUEST for %u.%u.%u.%u\n",
|
|
||||||
arp_msg_send.tInaddr[0],arp_msg_send.tInaddr[1],
|
|
||||||
arp_msg_send.tInaddr[2],arp_msg_send.tInaddr[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if ( i++ > 4 )
|
|
||||||
return 0; /* 5 probes */
|
|
||||||
memset (&addr, 0, sizeof(struct sockaddr));
|
|
||||||
memcpy (addr.sa_data, iface->iface, strlen (iface->iface));
|
|
||||||
if ( sendto(iface->sk, &arp_msg_send, sizeof (arpMessage), 0, &addr, sizeof(struct sockaddr)) == -1 )
|
|
||||||
{
|
|
||||||
syslog(LOG_ERR,"arpCheck: sendto: %m\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} while ( peekfd(iface->sk,50000) ); /* 50 msec timeout */
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
memset (&arp_msg_recv, 0, sizeof(arpMessage));
|
|
||||||
j = sizeof(struct sockaddr);
|
|
||||||
if ( recvfrom(iface->sk, &arp_msg_recv, sizeof(arpMessage), 0, (struct sockaddr *)&addr, &j) == -1 )
|
|
||||||
{
|
|
||||||
syslog(LOG_ERR,"arpCheck: recvfrom: %m\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( arp_msg_recv.ethhdr.ether_type != htons(ETHERTYPE_ARP) )
|
|
||||||
continue;
|
|
||||||
if ( arp_msg_recv.operation == htons(ARPOP_REPLY) )
|
|
||||||
{
|
|
||||||
if ( DebugFlag )
|
|
||||||
syslog(LOG_DEBUG, "ARPOP_REPLY received from %u.%u.%u.%u for %u.%u.%u.%u\n",
|
|
||||||
arp_msg_recv.sInaddr[0],arp_msg_recv.sInaddr[1],
|
|
||||||
arp_msg_recv.sInaddr[2],arp_msg_recv.sInaddr[3],
|
|
||||||
arp_msg_recv.tInaddr[0],arp_msg_recv.tInaddr[1],
|
|
||||||
arp_msg_recv.tInaddr[2],arp_msg_recv.tInaddr[3]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
if ( memcmp (arp_msg_recv.tHaddr, iface->chaddr, ETH_ALEN) )
|
|
||||||
{
|
|
||||||
if ( DebugFlag )
|
|
||||||
syslog(LOG_DEBUG,
|
|
||||||
"target hardware address mismatch: %02X.%02X.%02X.%02X.%02X.%02X received, %02X.%02X.%02X.%02X.%02X.%02X expected\n",
|
|
||||||
arp_msg_recv.tHaddr[0],arp_msg_recv.tHaddr[1],arp_msg_recv.tHaddr[2],
|
|
||||||
arp_msg_recv.tHaddr[3],arp_msg_recv.tHaddr[4],arp_msg_recv.tHaddr[5],
|
|
||||||
iface->chaddr[0],iface->chaddr[1],
|
|
||||||
iface->chaddr[2],iface->chaddr[3],
|
|
||||||
iface->chaddr[4],iface->chaddr[5]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (memcmp (&arp_msg_recv.sInaddr, &(iface->ciaddr), 4))
|
|
||||||
{
|
|
||||||
if ( DebugFlag )
|
|
||||||
syslog(LOG_DEBUG, "sender IP address mismatch: %u.%u.%u.%u received, %u.%u.%u.%u expected\n",
|
|
||||||
arp_msg_recv.sInaddr[0],arp_msg_recv.sInaddr[1],arp_msg_recv.sInaddr[2],arp_msg_recv.sInaddr[3],
|
|
||||||
((unsigned char *)&(iface->ciaddr))[0],
|
|
||||||
((unsigned char *)&(iface->ciaddr))[1],
|
|
||||||
((unsigned char *)&(iface->ciaddr))[2],
|
|
||||||
((unsigned char *)&(iface->ciaddr))[3]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
} while ( peekfd(iface->sk,50000) == 0 );
|
|
||||||
} while ( 1 );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/*****************************************************************************/
|
|
||||||
int arpRelease(const dhcp_interface *iface) /* sends UNARP message, cf. RFC1868 */
|
|
||||||
{
|
|
||||||
arpMessage ArpMsgSend;
|
|
||||||
struct sockaddr addr;
|
|
||||||
const int inaddr_broadcast = INADDR_BROADCAST;
|
|
||||||
|
|
||||||
/* build Ethernet header */
|
|
||||||
memset (&ArpMsgSend,0,sizeof(arpMessage));
|
|
||||||
memcpy (ArpMsgSend.ethhdr.ether_dhost, MAC_BCAST_ADDR, ETH_ALEN);
|
|
||||||
memcpy (ArpMsgSend.ethhdr.ether_shost, iface->chaddr, ETH_ALEN);
|
|
||||||
ArpMsgSend.ethhdr.ether_type = htons(ETHERTYPE_ARP);
|
|
||||||
|
|
||||||
/* build UNARP message */
|
|
||||||
ArpMsgSend.htype = htons(ARPHRD_ETHER);
|
|
||||||
ArpMsgSend.ptype = htons(ETHERTYPE_IP);
|
|
||||||
ArpMsgSend.plen = 4;
|
|
||||||
ArpMsgSend.operation= htons(ARPOP_REPLY);
|
|
||||||
memcpy (&ArpMsgSend.sInaddr, &(iface->ciaddr), 4);
|
|
||||||
memcpy (&ArpMsgSend.tInaddr, &inaddr_broadcast, 4);
|
|
||||||
|
|
||||||
memset(&addr,0,sizeof(struct sockaddr));
|
|
||||||
memcpy(addr.sa_data,iface->iface,strlen (iface->iface));
|
|
||||||
if ( sendto (iface->sk, &ArpMsgSend, sizeof (arpMessage), 0, &addr, sizeof(struct sockaddr)) == -1 )
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR,"arpRelease: sendto: %m\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
int arpInform(const dhcp_interface *iface)
|
|
||||||
{
|
|
||||||
arpMessage ArpMsgSend;
|
|
||||||
struct sockaddr addr;
|
|
||||||
const int inaddr_broadcast = INADDR_BROADCAST;
|
|
||||||
|
|
||||||
memset (&ArpMsgSend, 0, sizeof(arpMessage));
|
|
||||||
memcpy (ArpMsgSend.ethhdr.ether_dhost, MAC_BCAST_ADDR, ETH_ALEN);
|
|
||||||
memcpy (ArpMsgSend.ethhdr.ether_shost, iface->chaddr, ETH_ALEN);
|
|
||||||
ArpMsgSend.ethhdr.ether_type = htons(ETHERTYPE_ARP);
|
|
||||||
|
|
||||||
ArpMsgSend.htype = htons(ARPHRD_ETHER);
|
|
||||||
ArpMsgSend.ptype = htons(ETHERTYPE_IP);
|
|
||||||
ArpMsgSend.hlen = ETH_ALEN;
|
|
||||||
ArpMsgSend.plen = 4;
|
|
||||||
ArpMsgSend.operation= htons(ARPOP_REPLY);
|
|
||||||
memcpy (ArpMsgSend.sHaddr, iface->chaddr, ETH_ALEN);
|
|
||||||
memcpy (ArpMsgSend.tHaddr, iface->shaddr, ETH_ALEN);
|
|
||||||
memcpy (ArpMsgSend.sInaddr, &(iface->ciaddr), 4);
|
|
||||||
memcpy (ArpMsgSend.tInaddr, &inaddr_broadcast, 4);
|
|
||||||
|
|
||||||
memset (&addr, 0, sizeof(struct sockaddr));
|
|
||||||
memcpy (addr.sa_data, iface->iface, strlen (iface->iface));
|
|
||||||
if ( sendto (iface->sk, &ArpMsgSend, sizeof (arpMessage), 0, &addr, sizeof(struct sockaddr)) == -1 )
|
|
||||||
{
|
|
||||||
syslog(LOG_ERR,"arpInform: sendto: %m\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
50
dhcpcd/arp.h
50
dhcpcd/arp.h
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* dhcpcd - DHCP client daemon -
|
|
||||||
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
*
|
|
||||||
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
|
|
||||||
*
|
|
||||||
* This 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ARP_H
|
|
||||||
#define ARP_H
|
|
||||||
|
|
||||||
#include "client.h"
|
|
||||||
|
|
||||||
typedef struct arpMessage
|
|
||||||
{
|
|
||||||
struct packed_ether_header ethhdr;
|
|
||||||
u_short htype; /* hardware type (must be ARPHRD_ETHER) */
|
|
||||||
u_short ptype; /* protocol type (must be ETHERTYPE_IP) */
|
|
||||||
u_char hlen; /* hardware address length (must be 6) */
|
|
||||||
u_char plen; /* protocol address length (must be 4) */
|
|
||||||
u_short operation; /* ARP opcode */
|
|
||||||
u_char sHaddr[ETH_ALEN]; /* sender's hardware address */
|
|
||||||
u_char sInaddr[4]; /* sender's IP address */
|
|
||||||
u_char tHaddr[ETH_ALEN]; /* target's hardware address */
|
|
||||||
u_char tInaddr[4]; /* target's IP address */
|
|
||||||
u_char pad[18]; /* pad for min. Ethernet payload (60 bytes) */
|
|
||||||
} __attribute__((packed)) arpMessage;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ARPCHECK
|
|
||||||
int arpCheck(const dhcp_interface *iface);
|
|
||||||
#endif
|
|
||||||
int arpRelease(const dhcp_interface *iface);
|
|
||||||
int arpInform(const dhcp_interface *iface);
|
|
||||||
|
|
||||||
#endif
|
|
@@ -1,373 +0,0 @@
|
|||||||
/*
|
|
||||||
* dhcpcd - DHCP client daemon -
|
|
||||||
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
*
|
|
||||||
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
|
|
||||||
*
|
|
||||||
* This 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 Softwarme
|
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <net/if_arp.h>
|
|
||||||
#include "client.h"
|
|
||||||
#include "buildmsg.h"
|
|
||||||
#include "udpipgen.h"
|
|
||||||
|
|
||||||
extern int DebugFlag;
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
void fill_common_fields (dhcp_interface *iface, udpipMessage *msg, unsigned char dhost_addr[6], int bcast_resp)
|
|
||||||
{
|
|
||||||
dhcpMessage *dhcp_msg = (dhcpMessage *)&(msg->udpipmsg[sizeof(udpiphdr)]);
|
|
||||||
int magic_cookie = htonl (MAGIC_COOKIE);
|
|
||||||
|
|
||||||
/* build Ethernet header */
|
|
||||||
memcpy (msg->ethhdr.ether_dhost, dhost_addr, ETH_ALEN);
|
|
||||||
memcpy (msg->ethhdr.ether_shost, iface->chaddr, ETH_ALEN);
|
|
||||||
msg->ethhdr.ether_type = htons (ETHERTYPE_IP);
|
|
||||||
|
|
||||||
dhcp_msg->op = DHCP_BOOTREQUEST;
|
|
||||||
dhcp_msg->htype = ARPHRD_ETHER;
|
|
||||||
dhcp_msg->hlen = ETH_ALEN;
|
|
||||||
dhcp_msg->xid = iface->xid;
|
|
||||||
dhcp_msg->secs = htons (10);
|
|
||||||
|
|
||||||
if (bcast_resp && iface->client_options->do_broadcast_response)
|
|
||||||
dhcp_msg->flags = htons (BROADCAST_FLAG);
|
|
||||||
|
|
||||||
memcpy (dhcp_msg->chaddr, iface->chaddr, ETH_ALEN);
|
|
||||||
memcpy (dhcp_msg->options, &magic_cookie, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
unsigned char *fill_host_and_class_id (dhcp_interface *iface, unsigned char *p)
|
|
||||||
{
|
|
||||||
const char *host_name = iface->client_options->host_name;
|
|
||||||
int host_name_len = strlen (host_name);
|
|
||||||
|
|
||||||
if (host_name_len)
|
|
||||||
{
|
|
||||||
*p++ = hostName;
|
|
||||||
*p++ = host_name_len;
|
|
||||||
memcpy (p, host_name, host_name_len);
|
|
||||||
p += host_name_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iface->cls_id_len)
|
|
||||||
{
|
|
||||||
*p++ = dhcpClassIdentifier;
|
|
||||||
*p++ = iface->cls_id_len;
|
|
||||||
memcpy (p, iface->cls_id, iface->cls_id_len);
|
|
||||||
p += iface->cls_id_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iface->cli_id_len)
|
|
||||||
{
|
|
||||||
*p++ = dhcpClientIdentifier;
|
|
||||||
*p++ = iface->cli_id_len;
|
|
||||||
memcpy (p, iface->cli_id, iface->cli_id_len);
|
|
||||||
p += iface->cli_id_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
unsigned char *fill_param_request (unsigned char *p)
|
|
||||||
{
|
|
||||||
*p++ = dhcpParamRequest;
|
|
||||||
*p++ = 9;
|
|
||||||
*p++ = subnetMask;
|
|
||||||
*p++ = routersOnSubnet;
|
|
||||||
*p++ = dns;
|
|
||||||
*p++ = hostName;
|
|
||||||
*p++ = domainName;
|
|
||||||
*p++ = broadcastAddr;
|
|
||||||
*p++ = nisDomainName;
|
|
||||||
*p++ = nisServers;
|
|
||||||
*p++ = ntpServers;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
unsigned char *fill_requested_ipaddr (dhcp_interface *iface, unsigned char *p)
|
|
||||||
{
|
|
||||||
*p++ = dhcpRequestedIPaddr;
|
|
||||||
*p++ = 4;
|
|
||||||
memcpy (p, &(iface->ciaddr), 4);
|
|
||||||
p += 4;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
unsigned char *fill_lease_time (unsigned int *lease_time, unsigned char *p)
|
|
||||||
{
|
|
||||||
*p++ = dhcpIPaddrLeaseTime;
|
|
||||||
*p++ = 4;
|
|
||||||
memcpy (p, lease_time, 4);
|
|
||||||
p += 4;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
unsigned char *fill_server_id (unsigned int *server_id, unsigned char *p)
|
|
||||||
{
|
|
||||||
*p++ = dhcpServerIdentifier;
|
|
||||||
*p++ = 4;
|
|
||||||
memcpy (p, server_id, 4);
|
|
||||||
p += 4;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
unsigned char *fill_message_type (unsigned char request, unsigned char *p)
|
|
||||||
{
|
|
||||||
#define MAX_DHCP_MSG_SIZE 576
|
|
||||||
const unsigned short dhcpMsgSize = htons (MAX_DHCP_MSG_SIZE);
|
|
||||||
|
|
||||||
*p++ = dhcpMessageType;
|
|
||||||
*p++ = 1;
|
|
||||||
*p++ = request;
|
|
||||||
*p++ = dhcpMaxMsgSize;
|
|
||||||
*p++ = 2;
|
|
||||||
memcpy (p, &dhcpMsgSize, 2);
|
|
||||||
p += 2;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
unsigned char *fill_padding (dhcpMessage *start, unsigned char *p)
|
|
||||||
{
|
|
||||||
#define PAD_STOP 304 /* DHCP messages must be at least 300 bytes long. +4 for good measure */
|
|
||||||
|
|
||||||
while ((char *)p - (char *)start < PAD_STOP)
|
|
||||||
*p++ = 0;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
udpipMessage *build_dhcp_discover (dhcp_interface *iface, int *msg_len)
|
|
||||||
{
|
|
||||||
udpipMessage *udp_msg = calloc (1, sizeof (udpipMessage));
|
|
||||||
dhcpMessage *dhcp_msg = (dhcpMessage *)&(udp_msg->udpipmsg[sizeof(udpiphdr)]);
|
|
||||||
register unsigned char *p = dhcp_msg->options + 4;
|
|
||||||
unsigned int lease_time = htonl (iface->default_lease_time);
|
|
||||||
int dhcp_msg_len;
|
|
||||||
|
|
||||||
fill_common_fields (iface, udp_msg, MAC_BCAST_ADDR, 1);
|
|
||||||
p = fill_message_type (DHCP_DISCOVER, p);
|
|
||||||
if ( iface->ciaddr )
|
|
||||||
{
|
|
||||||
if ( iface->client_options->do_rfc1541 )
|
|
||||||
dhcp_msg->ciaddr = iface->ciaddr;
|
|
||||||
else
|
|
||||||
p = fill_requested_ipaddr (iface, p);
|
|
||||||
}
|
|
||||||
p = fill_lease_time (&lease_time, p);
|
|
||||||
p = fill_param_request (p);
|
|
||||||
p = fill_host_and_class_id (iface, p);
|
|
||||||
*p++ = endOption;
|
|
||||||
p = fill_padding (dhcp_msg, p);
|
|
||||||
|
|
||||||
/* build UDP/IP header */
|
|
||||||
dhcp_msg_len = (char *)p - (char *)dhcp_msg;
|
|
||||||
udpipgen ((udpiphdr *)(udp_msg->udpipmsg), 0, INADDR_BROADCAST, &iface->ip_id, dhcp_msg_len);
|
|
||||||
*msg_len = (char *)p - (char *)udp_msg;
|
|
||||||
return (udp_msg);
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
udpipMessage *build_dhcp_request (dhcp_interface *iface, int *msg_len)
|
|
||||||
{
|
|
||||||
udpipMessage *udp_msg = calloc (1, sizeof (udpipMessage));
|
|
||||||
dhcpMessage *dhcp_msg = (dhcpMessage *)&(udp_msg->udpipmsg[sizeof(udpiphdr)]);
|
|
||||||
register unsigned char *p = dhcp_msg->options + 4;
|
|
||||||
int dhcp_msg_len;
|
|
||||||
|
|
||||||
fill_common_fields (iface, udp_msg, MAC_BCAST_ADDR, 1);
|
|
||||||
p = fill_message_type (DHCP_REQUEST, p);
|
|
||||||
p = fill_server_id (iface->dhcp_options.val[dhcpServerIdentifier], p);
|
|
||||||
if ( iface->client_options->do_rfc1541 )
|
|
||||||
dhcp_msg->ciaddr = iface->ciaddr;
|
|
||||||
else
|
|
||||||
p = fill_requested_ipaddr (iface, p);
|
|
||||||
if ( iface->dhcp_options.val[dhcpIPaddrLeaseTime] )
|
|
||||||
p = fill_lease_time (iface->dhcp_options.val[dhcpIPaddrLeaseTime], p);
|
|
||||||
p = fill_param_request (p);
|
|
||||||
p = fill_host_and_class_id (iface, p);
|
|
||||||
*p++ = endOption;
|
|
||||||
p = fill_padding (dhcp_msg, p);
|
|
||||||
|
|
||||||
/* build UDP/IP header */
|
|
||||||
dhcp_msg_len = (char *)p - (char *)dhcp_msg;
|
|
||||||
udpipgen ((udpiphdr *)(udp_msg->udpipmsg), 0, INADDR_BROADCAST, &iface->ip_id, dhcp_msg_len);
|
|
||||||
*msg_len = (char *)(p++) - (char *)udp_msg;
|
|
||||||
return udp_msg;
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
udpipMessage *build_dhcp_renew (dhcp_interface *iface, int *msg_len)
|
|
||||||
{
|
|
||||||
udpipMessage *udp_msg = calloc (1, sizeof (udpipMessage));
|
|
||||||
dhcpMessage *dhcp_msg = (dhcpMessage *)&(udp_msg->udpipmsg[sizeof(udpiphdr)]);
|
|
||||||
register unsigned char *p = dhcp_msg->options + 4;
|
|
||||||
int dhcp_msg_len;
|
|
||||||
|
|
||||||
fill_common_fields (iface, udp_msg, iface->shaddr, 1);
|
|
||||||
dhcp_msg->ciaddr = iface->ciaddr;
|
|
||||||
p = fill_message_type (DHCP_REQUEST, p);
|
|
||||||
#if 0
|
|
||||||
if ( iface->dhcp_options.val[dhcpIPaddrLeaseTime] )
|
|
||||||
p = fill_lease_time (iface->dhcp_options.val[dhcpIPaddrLeaseTime], p);
|
|
||||||
#endif
|
|
||||||
p = fill_param_request (p);
|
|
||||||
p = fill_host_and_class_id (iface, p);
|
|
||||||
*p++ = endOption;
|
|
||||||
p = fill_padding (dhcp_msg, p);
|
|
||||||
|
|
||||||
/* build UDP/IP header */
|
|
||||||
dhcp_msg_len = (char *)p - (char *)dhcp_msg;
|
|
||||||
udpipgen ((udpiphdr *)(udp_msg->udpipmsg), iface->ciaddr, iface->siaddr, &iface->ip_id, dhcp_msg_len);
|
|
||||||
*msg_len = (char *)(p++) - (char *)udp_msg;
|
|
||||||
return (udp_msg);
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
udpipMessage *build_dhcp_rebind (dhcp_interface *iface, int *msg_len)
|
|
||||||
{
|
|
||||||
udpipMessage *udp_msg = calloc (1, sizeof (udpipMessage));
|
|
||||||
dhcpMessage *dhcp_msg = (dhcpMessage *)&(udp_msg->udpipmsg[sizeof(udpiphdr)]);
|
|
||||||
register unsigned char *p = dhcp_msg->options + 4;
|
|
||||||
int dhcp_msg_len;
|
|
||||||
|
|
||||||
fill_common_fields (iface, udp_msg, MAC_BCAST_ADDR, 1);
|
|
||||||
dhcp_msg->ciaddr = iface->ciaddr;
|
|
||||||
p = fill_message_type (DHCP_REQUEST, p);
|
|
||||||
if ( iface->dhcp_options.val[dhcpIPaddrLeaseTime] )
|
|
||||||
p = fill_lease_time (iface->dhcp_options.val[dhcpIPaddrLeaseTime], p);
|
|
||||||
p = fill_param_request (p);
|
|
||||||
p = fill_host_and_class_id (iface, p);
|
|
||||||
*p++ = endOption;
|
|
||||||
p = fill_padding (dhcp_msg, p);
|
|
||||||
|
|
||||||
/* build UDP/IP header */
|
|
||||||
dhcp_msg_len = (char *)p - (char *)dhcp_msg;
|
|
||||||
udpipgen ((udpiphdr *)(udp_msg->udpipmsg), iface->ciaddr, INADDR_BROADCAST, &iface->ip_id, dhcp_msg_len);
|
|
||||||
*msg_len = (char *)(p++) - (char *)udp_msg;
|
|
||||||
return udp_msg;
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
udpipMessage *build_dhcp_reboot (dhcp_interface *iface, int *msg_len)
|
|
||||||
{
|
|
||||||
udpipMessage *udp_msg = calloc (1, sizeof (udpipMessage));
|
|
||||||
dhcpMessage *dhcp_msg = (dhcpMessage *)&(udp_msg->udpipmsg[sizeof(udpiphdr)]);
|
|
||||||
register unsigned char *p = dhcp_msg->options + 4;
|
|
||||||
unsigned int lease_time = htonl (iface->default_lease_time);
|
|
||||||
int dhcp_msg_len;
|
|
||||||
|
|
||||||
fill_common_fields (iface, udp_msg, MAC_BCAST_ADDR, 1);
|
|
||||||
p = fill_message_type (DHCP_REQUEST, p);
|
|
||||||
if ( iface->client_options->do_rfc1541 )
|
|
||||||
dhcp_msg->ciaddr = iface->ciaddr;
|
|
||||||
else
|
|
||||||
p = fill_requested_ipaddr (iface, p);
|
|
||||||
p = fill_lease_time (&lease_time, p);
|
|
||||||
p = fill_param_request (p);
|
|
||||||
p = fill_host_and_class_id (iface, p);
|
|
||||||
*p++ = endOption;
|
|
||||||
p = fill_padding (dhcp_msg, p);
|
|
||||||
|
|
||||||
/* build UDP/IP header */
|
|
||||||
dhcp_msg_len = (char *)p - (char *)dhcp_msg;
|
|
||||||
udpipgen ((udpiphdr *)(udp_msg->udpipmsg), 0, INADDR_BROADCAST, &iface->ip_id, dhcp_msg_len);
|
|
||||||
*msg_len = (char *)(p++) - (char *)udp_msg;
|
|
||||||
return (udp_msg);
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
udpipMessage *build_dhcp_release (dhcp_interface *iface, int *msg_len)
|
|
||||||
{
|
|
||||||
udpipMessage *udp_msg = calloc (1, sizeof (udpipMessage));
|
|
||||||
dhcpMessage *dhcp_msg = (dhcpMessage *)&(udp_msg->udpipmsg[sizeof(udpiphdr)]);
|
|
||||||
register unsigned char *p = dhcp_msg->options + 4;
|
|
||||||
int dhcp_msg_len;
|
|
||||||
|
|
||||||
fill_common_fields (iface, udp_msg, iface->shaddr, 1);
|
|
||||||
dhcp_msg->ciaddr = iface->ciaddr;
|
|
||||||
*p++ = dhcpMessageType;
|
|
||||||
*p++ = 1;
|
|
||||||
*p++ = DHCP_RELEASE;
|
|
||||||
p = fill_server_id (iface->dhcp_options.val[dhcpServerIdentifier], p);
|
|
||||||
memcpy(p, iface->cli_id, iface->cli_id_len);
|
|
||||||
p += iface->cli_id_len;
|
|
||||||
*p++ = endOption;
|
|
||||||
p = fill_padding (dhcp_msg, p);
|
|
||||||
|
|
||||||
/* build UDP/IP header */
|
|
||||||
dhcp_msg_len = (char *)p - (char *)dhcp_msg;
|
|
||||||
udpipgen ((udpiphdr *)(udp_msg->udpipmsg), iface->ciaddr, iface->siaddr, &iface->ip_id, dhcp_msg_len);
|
|
||||||
*msg_len = (char *)(p++) - (char *)udp_msg;
|
|
||||||
return (udp_msg);
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
#ifdef ARPCHECK
|
|
||||||
udpipMessage *build_dhcp_decline (dhcp_interface *iface, int *msg_len)
|
|
||||||
{
|
|
||||||
udpipMessage *udp_msg = calloc (1, sizeof (udpipMessage));
|
|
||||||
dhcpMessage *dhcp_msg = (dhcpMessage *)&(udp_msg->udpipmsg[sizeof(udpiphdr)]);
|
|
||||||
register unsigned char *p = dhcp_msg->options + 4;
|
|
||||||
int dhcp_msg_len;
|
|
||||||
|
|
||||||
fill_common_fields (iface, udp_msg, iface->shaddr, 1);
|
|
||||||
*p++ = dhcpMessageType;
|
|
||||||
*p++ = 1;
|
|
||||||
*p++ = DHCP_DECLINE;
|
|
||||||
p = fill_server_id (iface->dhcp_options.val[dhcpServerIdentifier], p);
|
|
||||||
if ( iface->client_options->do_rfc1541 )
|
|
||||||
dhcp_msg->ciaddr = iface->ciaddr;
|
|
||||||
else
|
|
||||||
p = fill_requested_ipaddr (iface, p);
|
|
||||||
memcpy (p, iface->cli_id, iface->cli_id_len);
|
|
||||||
p += iface->cli_id_len;
|
|
||||||
*p++ = endOption;
|
|
||||||
p = fill_padding (dhcp_msg, p);
|
|
||||||
|
|
||||||
/* build UDP/IP header */
|
|
||||||
dhcp_msg_len = (char *)p - (char *)dhcp_msg;
|
|
||||||
udpipgen ((udpiphdr *)(udp_msg->udpipmsg), 0, iface->siaddr, &iface->ip_id, dhcp_msg_len);
|
|
||||||
*msg_len = (char *)(p++) - (char *)udp_msg;
|
|
||||||
return (udp_msg);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/*****************************************************************************/
|
|
||||||
udpipMessage *build_dhcp_inform (dhcp_interface *iface, int *msg_len)
|
|
||||||
{
|
|
||||||
udpipMessage *udp_msg = calloc (1, sizeof (udpipMessage));
|
|
||||||
dhcpMessage *dhcp_msg = (dhcpMessage *)&(udp_msg->udpipmsg[sizeof(udpiphdr)]);
|
|
||||||
register unsigned char *p = dhcp_msg->options + 4;
|
|
||||||
int dhcp_msg_len;
|
|
||||||
|
|
||||||
fill_common_fields (iface, udp_msg, iface->shaddr, 1);
|
|
||||||
dhcp_msg->ciaddr = iface->ciaddr;
|
|
||||||
p = fill_message_type (DHCP_INFORM, p);
|
|
||||||
p = fill_param_request (p);
|
|
||||||
p = fill_host_and_class_id (iface, p);
|
|
||||||
*p++ = endOption;
|
|
||||||
p = fill_padding (dhcp_msg, p);
|
|
||||||
|
|
||||||
/* build UDP/IP header */
|
|
||||||
dhcp_msg_len = (char *)p - (char *)dhcp_msg;
|
|
||||||
udpipgen((udpiphdr *)(udp_msg->udpipmsg), 0, INADDR_BROADCAST, &iface->ip_id, dhcp_msg_len);
|
|
||||||
*msg_len = (char *)(p++) - (char *)udp_msg;
|
|
||||||
return (udp_msg);
|
|
||||||
}
|
|
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* dhcpcd - DHCP client daemon -
|
|
||||||
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
*
|
|
||||||
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
|
|
||||||
*
|
|
||||||
* This 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BUILDMSG_H
|
|
||||||
#define BUILDMSG_H
|
|
||||||
|
|
||||||
#include "client.h"
|
|
||||||
|
|
||||||
udpipMessage *build_dhcp_discover (dhcp_interface *iface, int *msg_len);
|
|
||||||
udpipMessage *build_dhcp_request (dhcp_interface *iface, int *msg_len);
|
|
||||||
udpipMessage *build_dhcp_renew (dhcp_interface *iface, int *msg_len);
|
|
||||||
udpipMessage *build_dhcp_rebind (dhcp_interface *iface, int *msg_len);
|
|
||||||
udpipMessage *build_dhcp_reboot (dhcp_interface *iface, int *msg_len);
|
|
||||||
udpipMessage *build_dhcp_release (dhcp_interface *iface, int *msg_len);
|
|
||||||
#ifdef ARPCHECK
|
|
||||||
udpipMessage *build_dhcp_decline (dhcp_interface *iface, int *msg_len);
|
|
||||||
#endif
|
|
||||||
udpipMessage *build_dhcp_inform (dhcp_interface *iface, int *msg_len);
|
|
||||||
|
|
||||||
#endif
|
|
1120
dhcpcd/client.c
1120
dhcpcd/client.c
File diff suppressed because it is too large
Load Diff
288
dhcpcd/client.h
288
dhcpcd/client.h
@@ -1,288 +0,0 @@
|
|||||||
/*
|
|
||||||
* dhcpcd - DHCP client daemon -
|
|
||||||
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
*
|
|
||||||
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
|
|
||||||
*
|
|
||||||
* This 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CLIENT_H
|
|
||||||
#define CLIENT_H
|
|
||||||
|
|
||||||
#include <net/ethernet.h>
|
|
||||||
#include <linux/types.h>
|
|
||||||
#include <linux/if_tr.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include "dhcpcd.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define IPPACKET_SIZE 1500
|
|
||||||
#define MAGIC_COOKIE 0x63825363
|
|
||||||
#define BROADCAST_FLAG 0x8000
|
|
||||||
#define MAC_BCAST_ADDR "\xff\xff\xff\xff\xff\xff"
|
|
||||||
#define IP_BCAST_ADDR 0xFFFFFFFF
|
|
||||||
#ifndef AF_PACKET
|
|
||||||
#define AF_PACKET 17 /* should have been in socketbits.h */
|
|
||||||
#endif
|
|
||||||
#define HWADDR_TRIES 3
|
|
||||||
|
|
||||||
/* UDP port numbers for DHCP */
|
|
||||||
#define DHCP_SERVER_PORT 67 /* from client to server */
|
|
||||||
#define DHCP_CLIENT_PORT 68 /* from server to client */
|
|
||||||
|
|
||||||
/* DHCP message OP code */
|
|
||||||
#define DHCP_BOOTREQUEST 1
|
|
||||||
#define DHCP_BOOTREPLY 2
|
|
||||||
|
|
||||||
/* DHCP message type */
|
|
||||||
#define DHCP_DISCOVER 1
|
|
||||||
#define DHCP_OFFER 2
|
|
||||||
#define DHCP_REQUEST 3
|
|
||||||
#define DHCP_DECLINE 4
|
|
||||||
#define DHCP_ACK 5
|
|
||||||
#define DHCP_NAK 6
|
|
||||||
#define DHCP_RELEASE 7
|
|
||||||
#define DHCP_INFORM 8
|
|
||||||
/* DHCP RETRANSMISSION TIMEOUT (seconds) */
|
|
||||||
#define DHCP_INITIAL_RTO (5)
|
|
||||||
#define DHCP_MAX_RTO (64)
|
|
||||||
#define DHCP_OPTIONS_LENGTH 312
|
|
||||||
|
|
||||||
typedef struct dhcpMessage
|
|
||||||
{
|
|
||||||
u_char op; /* message type */
|
|
||||||
u_char htype; /* hardware address type */
|
|
||||||
u_char hlen; /* hardware address length */
|
|
||||||
u_char hops; /* should be zero in client's message */
|
|
||||||
u_int xid; /* transaction id */
|
|
||||||
u_short secs; /* elapsed time in sec. from trying to boot */
|
|
||||||
u_short flags;
|
|
||||||
u_int ciaddr; /* (previously allocated) client IP address */
|
|
||||||
u_int yiaddr; /* 'your' client IP address */
|
|
||||||
u_int siaddr; /* should be zero in client's messages */
|
|
||||||
u_int giaddr; /* should be zero in client's messages */
|
|
||||||
u_char chaddr[16]; /* client's hardware address */
|
|
||||||
u_char sname[64]; /* server host name, null terminated string */
|
|
||||||
u_char file[128]; /* boot file name, null terminated string */
|
|
||||||
u_char options[DHCP_OPTIONS_LENGTH]; /* message options */
|
|
||||||
} __attribute__((packed)) dhcpMessage;
|
|
||||||
|
|
||||||
typedef struct dhcpOptions
|
|
||||||
{
|
|
||||||
u_char len[256];
|
|
||||||
void *val[256];
|
|
||||||
u_char num;
|
|
||||||
} __attribute__((packed)) dhcpOptions;
|
|
||||||
|
|
||||||
struct packed_ether_header
|
|
||||||
{
|
|
||||||
u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
|
|
||||||
u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */
|
|
||||||
u_int16_t ether_type; /* packet type ID field */
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
#define TOKEN_RING_HEADER_PAD sizeof(struct trh_hdr) + sizeof(struct trllc)
|
|
||||||
typedef struct udpipMessage
|
|
||||||
{
|
|
||||||
struct packed_ether_header ethhdr;
|
|
||||||
char udpipmsg[IPPACKET_SIZE];
|
|
||||||
char pad_for_tokenring_header[TOKEN_RING_HEADER_PAD];
|
|
||||||
} __attribute__((packed)) udpipMessage;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct dhcp_interface
|
|
||||||
{
|
|
||||||
char *iface;
|
|
||||||
int cease;
|
|
||||||
int running;
|
|
||||||
int sk;
|
|
||||||
int foo_sk;
|
|
||||||
short int saved_if_flags;
|
|
||||||
unsigned int default_lease_time;
|
|
||||||
struct in_addr default_router;
|
|
||||||
|
|
||||||
int ciaddr;
|
|
||||||
unsigned char chaddr[ETH_ALEN];
|
|
||||||
int siaddr;
|
|
||||||
unsigned char shaddr[ETH_ALEN];
|
|
||||||
unsigned int xid;
|
|
||||||
unsigned short ip_id;
|
|
||||||
unsigned char cls_id[DHCP_CLASS_ID_MAX_LEN];
|
|
||||||
int cls_id_len;
|
|
||||||
unsigned char cli_id[DHCP_CLIENT_ID_MAX_LEN];
|
|
||||||
int cli_id_len;
|
|
||||||
dhcpOptions dhcp_options;
|
|
||||||
|
|
||||||
dhcp_client_options *client_options;
|
|
||||||
} dhcp_interface;
|
|
||||||
|
|
||||||
typedef struct dhcp_option_table
|
|
||||||
{
|
|
||||||
const char *name;
|
|
||||||
const int len_hint;
|
|
||||||
dhcp_option_type type;
|
|
||||||
} dhcp_option_table;
|
|
||||||
|
|
||||||
static dhcp_option_table dhcp_opt_table[] =
|
|
||||||
{
|
|
||||||
/* Names come from http://www.iana.org/assignments/bootp-dhcp-parameters, not to be changed */
|
|
||||||
|
|
||||||
/* 0 */ { "Pad", 0, DHCP_OPT_INVALID },
|
|
||||||
/* 1 */ { "Subnet Mask", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 2 */ { "Time Offset", 4, DHCP_OPT_TIME },
|
|
||||||
/* 3 */ { "Router", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 4 */ { "Time Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 5 */ { "Name Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 6 */ { "Domain Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 7 */ { "Log Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 8 */ { "Quotes Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 9 */ { "LPR Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 10 */ { "Impress Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 11 */ { "RLP Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 12 */ { "Hostname", 1, DHCP_OPT_STRING },
|
|
||||||
/* 13 */ { "Boot File Size", 2, DHCP_OPT_COUNT },
|
|
||||||
/* 14 */ { "Merit Dump File", 1, DHCP_OPT_STRING },
|
|
||||||
/* 15 */ { "Domain Name", 1, DHCP_OPT_STRING },
|
|
||||||
/* 16 */ { "Swap Server", 1, DHCP_OPT_ADDRESS },
|
|
||||||
/* 17 */ { "Root Path", 1, DHCP_OPT_STRING },
|
|
||||||
/* 18 */ { "Extension Path", 1, DHCP_OPT_STRING },
|
|
||||||
/* 19 */ { "Forward On/Off", 1, DHCP_OPT_TOGGLE },
|
|
||||||
/* 20 */ { "SrcRte On/Off", 1, DHCP_OPT_TOGGLE },
|
|
||||||
/* 21 */ { "Policy Filter", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 22 */ { "Max DG Assembly", 2, DHCP_OPT_COUNT },
|
|
||||||
/* 23 */ { "Default IP TTL", 1, DHCP_OPT_COUNT },
|
|
||||||
/* 24 */ { "MTU Timeout", 4, DHCP_OPT_TIME },
|
|
||||||
/* 25 */ { "MTU Plateau", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 26 */ { "MTU Interface", 2, DHCP_OPT_COUNT },
|
|
||||||
/* 27 */ { "MTU Subnet", 1, DHCP_OPT_TOGGLE },
|
|
||||||
/* 28 */ { "Broadcast Address", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 29 */ { "Mask Discovery", 1, DHCP_OPT_TOGGLE },
|
|
||||||
/* 30 */ { "Mask Supplier", 1, DHCP_OPT_TOGGLE },
|
|
||||||
/* 31 */ { "Router Discovery", 1, DHCP_OPT_TOGGLE },
|
|
||||||
/* 32 */ { "Router Request", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 33 */ { "Static Route", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 34 */ { "Trailers", 1, DHCP_OPT_TOGGLE },
|
|
||||||
/* 35 */ { "ARP Timeout", 4, DHCP_OPT_TIME },
|
|
||||||
/* 36 */ { "Ethernet", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 37 */ { "Default TCP TTL", 1, DHCP_OPT_COUNT},
|
|
||||||
/* 38 */ { "Keepalive Time", 4, DHCP_OPT_TIME },
|
|
||||||
/* 39 */ { "Keepalive Data", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 40 */ { "NIS Domain", 1, DHCP_OPT_STRING },
|
|
||||||
/* 41 */ { "NIS Servers", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 42 */ { "NTP Servers", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 43 */ { "Vendor Specific", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 44 */ { "NETBIOS Name Srv", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 45 */ { "NETBIOS Dist Srv", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 46 */ { "NETBIOS Node Type", 1, DHCP_OPT_NUMBER },
|
|
||||||
/* 47 */ { "NETBIOS Scope", 1, DHCP_OPT_NUMBER },
|
|
||||||
/* 48 */ { "X Window Font", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 49 */ { "X Window Manager", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 50 */ { "Address Request", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 51 */ { "Address Time", 4, DHCP_OPT_TIME },
|
|
||||||
/* 52 */ { "Overload", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 53 */ { "DHCP Msg Type", 1, DHCP_OPT_NUMBER },
|
|
||||||
/* 54 */ { "DHCP Server Id", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 55 */ { "Parameter List", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 56 */ { "DHCP Message", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 57 */ { "DHCP Max Msg Size", 2, DHCP_OPT_COUNT },
|
|
||||||
/* 58 */ { "Renewal Time", 4, DHCP_OPT_TIME },
|
|
||||||
/* 59 */ { "Rebinding Time", 4, DHCP_OPT_TIME },
|
|
||||||
/* 60 */ { "Class Id", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 61 */ { "Client Id", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 62 */ { "NetWare/IP Domain", 1, DHCP_OPT_STRING },
|
|
||||||
/* 63 */ { "NetWare/IP Option", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 64 */ { "NIS-Domain-Name", 1, DHCP_OPT_STRING },
|
|
||||||
/* 65 */ { "NIS-Server-Addr", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 66 */ { "Server-Name", 1, DHCP_OPT_STRING },
|
|
||||||
/* 67 */ { "Bootfile-Name", 1, DHCP_OPT_STRING },
|
|
||||||
/* 68 */ { "Home-Agent-Addrs", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 69 */ { "SMTP-Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 70 */ { "POP3-Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 71 */ { "NNTP-Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 72 */ { "WWW-Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 73 */ { "Finger-Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 74 */ { "IRC-Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 75 */ { "StreetTalk-Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 76 */ { "STDA-Server", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 77 */ { "User-Class", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 78 */ { "Directory Agent", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 79 */ { "Service Scope", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 80 */ { "Rapid Commit", 0, DHCP_OPT_BLOB },
|
|
||||||
/* 81 */ { "Client FQDN", 1, DHCP_OPT_STRING },
|
|
||||||
/* 82 */ { "Relay Agent Information", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 83 */ { "iSNS", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 84 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 85 */ { "NDS Servers", 4, DHCP_OPT_ADDRESS },
|
|
||||||
/* 86 */ { "NDS Tree Name", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 87 */ { "NDS Context", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 88 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 89 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 90 */ { "Authentication", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 91 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 92 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 93 */ { "Client System", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 94 */ { "Client NDI", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 95 */ { "LDAP", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 96 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 97 */ { "UUID/GUID", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 98 */ { "User-Auth", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 99 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 100 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 101 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 102 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 103 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 104 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 105 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 106 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 107 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 108 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 109 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 110 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 111 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 112 */ { "Netinfo Address", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 113 */ { "Netinfo Tag", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 114 */ { "URL", 1, DHCP_OPT_STRING },
|
|
||||||
/* 115 */ { NULL, 1, DHCP_OPT_BLOB },
|
|
||||||
/* 116 */ { "Auto-Config", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 117 */ { "Name Service Search", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 118 */ { "Subnet Selection Option", 4, DHCP_OPT_BLOB },
|
|
||||||
/* 119 */ { "Domain Search", 1, DHCP_OPT_STRING },
|
|
||||||
/* 120 */ { "SIP Servers DHCP Option", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 121 */ { "Classless Static Route Option", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 122 */ { "CCC", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 123 */ { "GeoConf Option", 16, DHCP_OPT_BLOB },
|
|
||||||
/* 124 */ { "V-I Vendor Class", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 125 */ { "V-I Vendor-Specific Information", 1, DHCP_OPT_BLOB },
|
|
||||||
/* 126 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
/* 127 */ { NULL, 0, DHCP_OPT_INVALID },
|
|
||||||
};
|
|
||||||
static const int dhcp_opt_table_len = sizeof(dhcp_opt_table)/sizeof(*dhcp_opt_table);
|
|
||||||
|
|
||||||
typedef udpipMessage *(*dhcp_msg_build_proc)(dhcp_interface *, int *msg_len);
|
|
||||||
|
|
||||||
int dhcp_reboot(dhcp_interface *iface);
|
|
||||||
int dhcp_init(dhcp_interface *iface);
|
|
||||||
int dhcp_request(dhcp_interface *iface, dhcp_msg_build_proc buildDhcpMsg);
|
|
||||||
int dhcp_renew(dhcp_interface *iface);
|
|
||||||
int dhcp_rebind(dhcp_interface *iface);
|
|
||||||
int dhcp_release(dhcp_interface *iface);
|
|
||||||
#ifdef ARPCHECK
|
|
||||||
int dhcp_decline(dhcp_interface *iface);
|
|
||||||
#endif
|
|
||||||
int dhcp_inform(dhcp_interface *iface);
|
|
||||||
|
|
||||||
#endif
|
|
@@ -1,32 +0,0 @@
|
|||||||
#include "dhcpcd.h"
|
|
||||||
#include "client.h"
|
|
||||||
#include <syslog.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
dhcp_client_options opts;
|
|
||||||
dhcp_interface *iface;
|
|
||||||
|
|
||||||
if (argc < 2 || argv[1] == NULL)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "Need an interface\n");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset (&opts, 0, sizeof (dhcp_client_options));
|
|
||||||
opts.base_timeout = 5;
|
|
||||||
|
|
||||||
openlog ("dhcp_test", LOG_CONS | LOG_PERROR, LOG_USER);
|
|
||||||
|
|
||||||
if (!(iface = dhcp_interface_init (argv[1], &opts)))
|
|
||||||
exit (1);
|
|
||||||
|
|
||||||
dhcp_init (iface);
|
|
||||||
|
|
||||||
dhcp_interface_free (iface);
|
|
||||||
|
|
||||||
exit (0);
|
|
||||||
}
|
|
346
dhcpcd/dhcpcd.c
346
dhcpcd/dhcpcd.c
@@ -1,346 +0,0 @@
|
|||||||
/*
|
|
||||||
* dhcpcd - DHCP client daemon -
|
|
||||||
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
*
|
|
||||||
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
|
|
||||||
*
|
|
||||||
* This 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <syslog.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <net/if_packet.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <net/route.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include "dhcpcd.h"
|
|
||||||
#include "client.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* DHCP Client Daemon v1.3.22-pl4
|
|
||||||
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
* Location: http://www.phystech.com/download/
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern void class_id_setup (dhcp_interface *iface, const char *g_cls_id);
|
|
||||||
extern void client_id_setup (dhcp_interface *iface, const char *g_cli_id);
|
|
||||||
extern void release_dhcp_options (dhcp_interface *iface);
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
dhcp_interface *dhcp_interface_init (const char *if_name, dhcp_client_options *in_opts)
|
|
||||||
{
|
|
||||||
int o = 1;
|
|
||||||
unsigned i = 3;
|
|
||||||
struct ifreq ifr;
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
dhcp_interface *iface = NULL;
|
|
||||||
dhcp_client_options *opts = NULL;
|
|
||||||
struct rtentry route;
|
|
||||||
|
|
||||||
if (!if_name || !in_opts)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!(iface = calloc (1, sizeof (dhcp_interface))))
|
|
||||||
return NULL;
|
|
||||||
iface->iface = strdup (if_name);
|
|
||||||
iface->default_lease_time = DHCP_DEFAULT_LEASETIME;
|
|
||||||
iface->xid = random ();
|
|
||||||
iface->sk = -1;
|
|
||||||
iface->foo_sk = -1;
|
|
||||||
|
|
||||||
/* Copy in client-specific options */
|
|
||||||
if (!(opts = calloc (1, sizeof (dhcp_client_options))))
|
|
||||||
goto err_out;
|
|
||||||
memcpy (opts, in_opts, sizeof (dhcp_client_options));
|
|
||||||
opts->host_name[DHCP_HOSTNAME_MAX_LEN - 1] = '\0';
|
|
||||||
opts->class_id[DHCP_CLASS_ID_MAX_LEN - 1] = '\0';
|
|
||||||
opts->client_id[DHCP_CLIENT_ID_MAX_LEN - 1] = '\0';
|
|
||||||
iface->client_options = opts;
|
|
||||||
|
|
||||||
/* Grab a control socket for the device */
|
|
||||||
memset (&ifr, 0, sizeof(struct ifreq));
|
|
||||||
memcpy (ifr.ifr_name, iface->iface, strlen (iface->iface));
|
|
||||||
iface->sk = socket (AF_PACKET, SOCK_PACKET, htons(ETH_P_ALL));
|
|
||||||
if (iface->sk == -1)
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR,"dhcp_interface_init: socket: %m\n");
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ioctl (iface->sk, SIOCGIFFLAGS, &ifr))
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR, "dhcp_interface_init: ioctl SIOCGIFFLAGS: %m\n");
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
iface->saved_if_flags = ifr.ifr_flags;
|
|
||||||
|
|
||||||
/* Try to get a valid MAC address. Sometimes when you bring a card up, especially ones
|
|
||||||
* with downloadable firmware, it takes a couple tries to get a valid MAC address
|
|
||||||
* since the firmware is busy for a bit doing who knows what.
|
|
||||||
*/
|
|
||||||
do
|
|
||||||
{
|
|
||||||
struct sockaddr_pkt sap;
|
|
||||||
struct sockaddr_in *addrp;
|
|
||||||
|
|
||||||
if ( ioctl (iface->sk, SIOCGIFHWADDR, &ifr) )
|
|
||||||
{
|
|
||||||
syslog(LOG_ERR,"dhcp_interface_init: ioctl SIOCGIFHWADDR: %m\n");
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
memcpy (iface->chaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
|
|
||||||
|
|
||||||
if (setsockopt (iface->sk, SOL_SOCKET, SO_BROADCAST, &o, sizeof(o)) == -1)
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR,"dhcp_interface_init: setsockopt (SO_BROADCAST): %m\n");
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ifr.ifr_flags = iface->saved_if_flags | IFF_UP | IFF_BROADCAST | IFF_NOTRAILERS | IFF_RUNNING;
|
|
||||||
if (ioctl (iface->sk, SIOCSIFFLAGS, &ifr))
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR,"dhcp_interface_init: ioctl SIOCSIFFLAGS: %m");
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset (&ifr, 0, sizeof (ifr));
|
|
||||||
addrp = (struct sockaddr_in *) &ifr.ifr_addr;
|
|
||||||
strcpy (ifr.ifr_name, iface->iface);
|
|
||||||
addrp->sin_family = AF_INET;
|
|
||||||
addrp->sin_port = 0;
|
|
||||||
memset (&addrp->sin_addr, 0, sizeof (addrp->sin_addr));
|
|
||||||
addrp->sin_addr.s_addr = htonl (0);
|
|
||||||
if (ioctl (iface->sk, SIOCSIFADDR, &ifr))
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR, "dhcp_interface_init: SIOCSIFADDR returned errno %d", errno);
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
o = 1;
|
|
||||||
if (setsockopt (iface->sk, SOL_SOCKET, SO_REUSEADDR, &o, sizeof(o)) == -1)
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR,"dhcp_interface_init: setsockopt (SO_REUSEADDR): %m");
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setsockopt (iface->sk, SOL_SOCKET, SO_BINDTODEVICE, iface->iface, strlen (iface->iface)+1))
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR, "dhcp_interface_init: SO_BINDTODEVICE %s (%d) failed: %s", iface->iface, strlen (iface->iface), strerror (errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
memset (&sap, 0, sizeof(sap));
|
|
||||||
sap.spkt_protocol = htons (ETH_P_ALL);
|
|
||||||
memcpy (sap.spkt_device, iface->iface, strlen (iface->iface));
|
|
||||||
sap.spkt_family = AF_PACKET;
|
|
||||||
if ( bind (iface->sk, (void*)&sap, sizeof(struct sockaddr)) == -1 )
|
|
||||||
syslog (LOG_ERR,"dhcp_interface_init: bind: %m\n");
|
|
||||||
|
|
||||||
if (ioctl (iface->sk, SIOCGIFHWADDR, &ifr))
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR,"dhcp_interface_init: ioctl SIOCGIFHWADDR: %m");
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy (iface->chaddr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
|
|
||||||
syslog (LOG_INFO, "dhcp_interface_init: MAC address = %02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
||||||
iface->chaddr[0], iface->chaddr[1], iface->chaddr[2], iface->chaddr[3], iface->chaddr[4], iface->chaddr[5]);
|
|
||||||
i--;
|
|
||||||
} while (iface->chaddr[0] && iface->chaddr[1] && iface->chaddr[2] && iface->chaddr[3] && iface->chaddr[4] && iface->chaddr[5] && (i > 0));
|
|
||||||
|
|
||||||
iface->foo_sk = socket (AF_INET, SOCK_DGRAM, 0);
|
|
||||||
if ( iface->foo_sk == -1 )
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR,"dhcp_interface_init: socket: %m\n");
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setsockopt (iface->foo_sk, SOL_SOCKET, SO_BROADCAST, &o, sizeof(o)))
|
|
||||||
syslog (LOG_ERR,"dhcp_interface_init: setsockopt: %m\n");
|
|
||||||
memset (&addr, 0, sizeof (addr));
|
|
||||||
addr.sin_family = AF_INET;
|
|
||||||
addr.sin_port = htons (DHCP_CLIENT_PORT);
|
|
||||||
if ( bind (iface->foo_sk, (struct sockaddr *)&addr, sizeof(addr)) )
|
|
||||||
{
|
|
||||||
if (errno != EADDRINUSE)
|
|
||||||
syslog (LOG_ERR,"dhcp_interface_init: bind: %m\n");
|
|
||||||
close (iface->foo_sk);
|
|
||||||
iface->foo_sk = -1;
|
|
||||||
}
|
|
||||||
else if (fcntl (iface->foo_sk, F_SETFL, O_NONBLOCK) == -1)
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR,"dhcp_interface_init: fcntl: %m\n");
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set up at least the broadcast route or something */
|
|
||||||
memset (&addr, 0, sizeof (addr));
|
|
||||||
addr.sin_family = AF_INET;
|
|
||||||
addr.sin_port = 0;
|
|
||||||
|
|
||||||
memset (&route, 0, sizeof (route));
|
|
||||||
memcpy (&route.rt_gateway, &addr, sizeof (addr));
|
|
||||||
|
|
||||||
addr.sin_addr.s_addr = INADDR_ANY;
|
|
||||||
memcpy (&route.rt_dst, &addr, sizeof(addr));
|
|
||||||
memcpy (&route.rt_genmask, &addr, sizeof(addr));
|
|
||||||
|
|
||||||
route.rt_dev = iface->iface;
|
|
||||||
route.rt_flags = RTF_UP;
|
|
||||||
route.rt_metric = 0;
|
|
||||||
|
|
||||||
if (ioctl (iface->sk, SIOCADDRT, &route) && (errno != EEXIST))
|
|
||||||
{
|
|
||||||
syslog (LOG_ERR, "dhcp_interface_init: SIOCADDRT failed, errno = %d, dev = %s\n", errno, iface->iface);
|
|
||||||
goto err_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = time (NULL) + iface->chaddr[5] + 4*iface->chaddr[4] + 8*iface->chaddr[3] +
|
|
||||||
16*iface->chaddr[2] + 32*iface->chaddr[1] + 64*iface->chaddr[0];
|
|
||||||
srandom (i);
|
|
||||||
iface->ip_id = i & 0xffff;
|
|
||||||
|
|
||||||
class_id_setup (iface, iface->client_options->class_id);
|
|
||||||
client_id_setup (iface, iface->client_options->client_id);
|
|
||||||
|
|
||||||
return iface;
|
|
||||||
|
|
||||||
err_out:
|
|
||||||
dhcp_interface_free (iface);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
void dhcp_interface_free (dhcp_interface *iface)
|
|
||||||
{
|
|
||||||
struct ifreq ifr;
|
|
||||||
struct sockaddr_in *p = (struct sockaddr_in *)&(ifr.ifr_addr);
|
|
||||||
|
|
||||||
if (!iface)
|
|
||||||
return;
|
|
||||||
|
|
||||||
release_dhcp_options (iface);
|
|
||||||
|
|
||||||
if (iface->foo_sk >= 0)
|
|
||||||
close (iface->foo_sk);
|
|
||||||
if (iface->sk >= 0)
|
|
||||||
close (iface->sk);
|
|
||||||
free (iface->iface);
|
|
||||||
free (iface->client_options);
|
|
||||||
free (iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
void dhcp_interface_cease (dhcp_interface *iface)
|
|
||||||
{
|
|
||||||
if (!iface)
|
|
||||||
return;
|
|
||||||
|
|
||||||
iface->cease = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int dhcp_interface_option_present (dhcp_interface *iface, int val)
|
|
||||||
{
|
|
||||||
if (!iface) return 0;
|
|
||||||
|
|
||||||
return (!!iface->dhcp_options.len[val]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
void *dhcp_interface_option_payload (dhcp_interface *iface, int val)
|
|
||||||
{
|
|
||||||
if (!iface) return 0;
|
|
||||||
|
|
||||||
return (iface->dhcp_options.val[val]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int dhcp_interface_option_len (dhcp_interface *iface, int val)
|
|
||||||
{
|
|
||||||
if (!iface) return 0;
|
|
||||||
|
|
||||||
return (iface->dhcp_options.len[val]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int dhcp_option_element_len (int val)
|
|
||||||
{
|
|
||||||
if ((val >= 0) && (val < dhcp_opt_table_len))
|
|
||||||
return (dhcp_opt_table[val].len_hint);
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
const char *dhcp_option_name (int val)
|
|
||||||
{
|
|
||||||
if ((val >= 0) && (val < dhcp_opt_table_len))
|
|
||||||
return (dhcp_opt_table[val].name);
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
dhcp_option_type dhcp_option_element_type (int val)
|
|
||||||
{
|
|
||||||
if ((val >= 0) && (val < dhcp_opt_table_len))
|
|
||||||
return (dhcp_opt_table[val].type);
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* case-insensitive alpha/num string comparison; skips over white space and punctuation */
|
|
||||||
static int dhcp_strcmp (const unsigned char *s1, const unsigned char *s2)
|
|
||||||
{
|
|
||||||
while (!isalnum(*s1) && (*s1 != 0))
|
|
||||||
s1++;
|
|
||||||
while (!isalnum(*s2) && (*s2 != 0))
|
|
||||||
s2++;
|
|
||||||
while (*s1 != 0) {
|
|
||||||
if (tolower(*s1) != tolower(*s2))
|
|
||||||
return ((tolower(*s1) < tolower(*s2))?-1:1);
|
|
||||||
s1++;
|
|
||||||
s2++;
|
|
||||||
while (!isalnum(*s1) && (*s1 != 0))
|
|
||||||
s1++;
|
|
||||||
while (!isalnum(*s2) && (*s2 != 0))
|
|
||||||
s2++;
|
|
||||||
}
|
|
||||||
if (*s2 != 0)
|
|
||||||
return ((tolower(*s1) < tolower(*s2))?-1:1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int dhcp_option_id_by_name (const char *name)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < dhcp_opt_table_len; i++)
|
|
||||||
if ((dhcp_opt_table[i].name != NULL) && (dhcp_strcmp (name, dhcp_opt_table[i].name) == 0))
|
|
||||||
return (i);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
149
dhcpcd/dhcpcd.h
149
dhcpcd/dhcpcd.h
@@ -1,149 +0,0 @@
|
|||||||
/*
|
|
||||||
* dhcpcd - DHCP client daemon -
|
|
||||||
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
*
|
|
||||||
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
|
|
||||||
*
|
|
||||||
* This 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DHCPCD_H
|
|
||||||
#define DHCPCD_H
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#define DHCP_DEFAULT_TIMEOUT 60
|
|
||||||
#define DHCP_DEFAULT_LEASETIME 0xffffffff /* infinite lease time */
|
|
||||||
#define DHCP_CLASS_ID_MAX_LEN 48
|
|
||||||
#define DHCP_CLIENT_ID_MAX_LEN 48
|
|
||||||
#define DHCP_HOSTNAME_MAX_LEN 64
|
|
||||||
|
|
||||||
/* DHCP option and value (cf. RFC1533) */
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
padOption = 0,
|
|
||||||
subnetMask = 1,
|
|
||||||
timerOffset = 2,
|
|
||||||
routersOnSubnet = 3,
|
|
||||||
timeServer = 4,
|
|
||||||
nameServer = 5,
|
|
||||||
dns = 6,
|
|
||||||
logServer = 7,
|
|
||||||
cookieServer = 8,
|
|
||||||
lprServer = 9,
|
|
||||||
impressServer = 10,
|
|
||||||
resourceLocationServer = 11,
|
|
||||||
hostName = 12,
|
|
||||||
bootFileSize = 13,
|
|
||||||
meritDumpFile = 14,
|
|
||||||
domainName = 15,
|
|
||||||
swapServer = 16,
|
|
||||||
rootPath = 17,
|
|
||||||
extentionsPath = 18,
|
|
||||||
IPforwarding = 19,
|
|
||||||
nonLocalSourceRouting = 20,
|
|
||||||
policyFilter = 21,
|
|
||||||
maxDgramReasmSize = 22,
|
|
||||||
defaultIPTTL = 23,
|
|
||||||
pathMTUagingTimeout = 24,
|
|
||||||
pathMTUplateauTable = 25,
|
|
||||||
ifMTU = 26,
|
|
||||||
allSubnetsLocal = 27,
|
|
||||||
broadcastAddr = 28,
|
|
||||||
performMaskDiscovery = 29,
|
|
||||||
maskSupplier = 30,
|
|
||||||
performRouterDiscovery = 31,
|
|
||||||
routerSolicitationAddr = 32,
|
|
||||||
staticRoute = 33,
|
|
||||||
trailerEncapsulation = 34,
|
|
||||||
arpCacheTimeout = 35,
|
|
||||||
ethernetEncapsulation = 36,
|
|
||||||
tcpDefaultTTL = 37,
|
|
||||||
tcpKeepaliveInterval = 38,
|
|
||||||
tcpKeepaliveGarbage = 39,
|
|
||||||
nisDomainName = 40,
|
|
||||||
nisServers = 41,
|
|
||||||
ntpServers = 42,
|
|
||||||
vendorSpecificInfo = 43,
|
|
||||||
netBIOSnameServer = 44,
|
|
||||||
netBIOSdgramDistServer = 45,
|
|
||||||
netBIOSnodeType = 46,
|
|
||||||
netBIOSscope = 47,
|
|
||||||
xFontServer = 48,
|
|
||||||
xDisplayManager = 49,
|
|
||||||
dhcpRequestedIPaddr = 50,
|
|
||||||
dhcpIPaddrLeaseTime = 51,
|
|
||||||
dhcpOptionOverload = 52,
|
|
||||||
dhcpMessageType = 53,
|
|
||||||
dhcpServerIdentifier = 54,
|
|
||||||
dhcpParamRequest = 55,
|
|
||||||
dhcpMsg = 56,
|
|
||||||
dhcpMaxMsgSize = 57,
|
|
||||||
dhcpT1value = 58,
|
|
||||||
dhcpT2value = 59,
|
|
||||||
dhcpClassIdentifier = 60,
|
|
||||||
dhcpClientIdentifier = 61,
|
|
||||||
endOption = 255
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef enum dhcp_option_type
|
|
||||||
{
|
|
||||||
DHCP_OPT_INVALID,
|
|
||||||
DHCP_OPT_ADDRESS,
|
|
||||||
DHCP_OPT_TIME,
|
|
||||||
DHCP_OPT_STRING,
|
|
||||||
DHCP_OPT_COUNT,
|
|
||||||
DHCP_OPT_TOGGLE,
|
|
||||||
DHCP_OPT_BLOB,
|
|
||||||
DHCP_OPT_NUMBER,
|
|
||||||
} dhcp_option_type;
|
|
||||||
|
|
||||||
/* Return codes */
|
|
||||||
#define RET_DHCP_ERROR 0
|
|
||||||
#define RET_DHCP_ADDRESS_IN_USE 1
|
|
||||||
#define RET_DHCP_TIMEOUT 2
|
|
||||||
#define RET_DHCP_CEASED 3
|
|
||||||
#define RET_DHCP_NAK 4
|
|
||||||
#define RET_DHCP_SUCCESS 5
|
|
||||||
#define RET_DHCP_BOUND 6
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct dhcp_client_options
|
|
||||||
{
|
|
||||||
unsigned char host_name[DHCP_HOSTNAME_MAX_LEN];
|
|
||||||
unsigned char class_id[DHCP_CLASS_ID_MAX_LEN];
|
|
||||||
unsigned char client_id[DHCP_CLIENT_ID_MAX_LEN];
|
|
||||||
int do_rfc1541;
|
|
||||||
int do_broadcast_response;
|
|
||||||
time_t base_timeout;
|
|
||||||
int do_checksum;
|
|
||||||
int send_second_discover;
|
|
||||||
int window;
|
|
||||||
} dhcp_client_options;
|
|
||||||
|
|
||||||
struct dhcp_interface *dhcp_interface_init (const char *if_name, dhcp_client_options *in_opts);
|
|
||||||
void dhcp_interface_free (struct dhcp_interface *iface);
|
|
||||||
void dhcp_interface_cease (struct dhcp_interface *iface);
|
|
||||||
|
|
||||||
int dhcp_interface_option_present (struct dhcp_interface *iface, int val);
|
|
||||||
int dhcp_interface_option_len (struct dhcp_interface *iface, int val);
|
|
||||||
void *dhcp_interface_option_payload (struct dhcp_interface *iface, int val);
|
|
||||||
int dhcp_option_element_len (int val);
|
|
||||||
dhcp_option_type dhcp_option_element_type (int val);
|
|
||||||
int dhcp_option_id_by_name (const char *name);
|
|
||||||
const char * dhcp_option_name (int val);
|
|
||||||
|
|
||||||
#endif
|
|
@@ -1,524 +0,0 @@
|
|||||||
/*
|
|
||||||
* dhcpcd - DHCP client daemon -
|
|
||||||
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
*
|
|
||||||
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
|
|
||||||
*
|
|
||||||
* This 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <net/route.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <arpa/nameser.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <syslog.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <resolv.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include "pathnames.h"
|
|
||||||
#include "client.h"
|
|
||||||
#include "arp.h"
|
|
||||||
|
|
||||||
extern int SetDHCPDefaultRoutes;
|
|
||||||
extern int DebugFlag;
|
|
||||||
extern int SetDomainName;
|
|
||||||
extern int SetHostName;
|
|
||||||
extern int ReplResolvConf;
|
|
||||||
extern int ReplNISConf;
|
|
||||||
extern int ReplNTPConf;
|
|
||||||
|
|
||||||
int resolv_renamed = 0;
|
|
||||||
int yp_renamed = 0;
|
|
||||||
int ntp_renamed = 0;
|
|
||||||
|
|
||||||
/* Note: Legths initialised to negative to allow us to distinguish between "empty" and "not set" */
|
|
||||||
char InitialHostName[HOSTNAME_MAX_LEN];
|
|
||||||
int InitialHostName_len=-1;
|
|
||||||
char InitialDomainName[HOSTNAME_MAX_LEN];
|
|
||||||
int InitialDomainName_len=-1;
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
char *cleanmetas(char *cstr) /* this is to clean single quotes out of DHCP strings */
|
|
||||||
{
|
|
||||||
register char *c=cstr;
|
|
||||||
do
|
|
||||||
if ( *c == 39 )
|
|
||||||
*c = ' ';
|
|
||||||
while ( *c++ );
|
|
||||||
return cstr;
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
unsigned long getgenmask(unsigned long ip_in) /* this is to guess genmask form network address */
|
|
||||||
{
|
|
||||||
unsigned long t,p=ntohl(ip_in);
|
|
||||||
|
|
||||||
if ( IN_CLASSA(p) )
|
|
||||||
t= ~IN_CLASSA_NET;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( IN_CLASSB(p) )
|
|
||||||
t= ~IN_CLASSB_NET;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( IN_CLASSC(p) )
|
|
||||||
t= ~IN_CLASSC_NET;
|
|
||||||
else
|
|
||||||
t=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while ( t & p )
|
|
||||||
t >>= 1;
|
|
||||||
|
|
||||||
return htonl(~t);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int setResolvConf(dhcp_interface *iface)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
resolv_renamed = 1 + rename (RESOLV_CONF, ""RESOLV_CONF".sv");
|
|
||||||
f = fopen(RESOLV_CONF,"w");
|
|
||||||
if ( f )
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
#if 0
|
|
||||||
if ( iface->dchp_options.len[nisDomainName] )
|
|
||||||
fprintf(f,"domain %s\n",(char *)iface->dhcp_options.val[nisDomainName]);
|
|
||||||
else
|
|
||||||
if ( iface->dhcp_options.len[domainName] )
|
|
||||||
fprintf(f,"domain %s\n",(char *)iface->dhcp_options.val[domainName]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i = 0; i < iface->dhcp_options.len[dns]; i += 4)
|
|
||||||
{
|
|
||||||
fprintf(f,"nameserver %u.%u.%u.%u\n",
|
|
||||||
((unsigned char *)iface->dhcp_options.val[dns])[i],
|
|
||||||
((unsigned char *)iface->dhcp_options.val[dns])[i+1],
|
|
||||||
((unsigned char *)iface->dhcp_options.val[dns])[i+2],
|
|
||||||
((unsigned char *)iface->dhcp_options.val[dns])[i+3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if ( iface->dhcp_options.len[nisDomainName] + iface->dhcp_options.len[domainName] )
|
|
||||||
{
|
|
||||||
fprintf (f,"search");
|
|
||||||
if ( iface->dhcp_options.len[nisDomainName] )
|
|
||||||
fprintf (f," %s",(char *)iface->dhcp_options.val[nisDomainName]);
|
|
||||||
if ( iface->dhcp_options.len[domainName] )
|
|
||||||
fprintf (f," %s",(char *)iface->dhcp_options.val[domainName]);
|
|
||||||
fprintf (f,"\n");
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if ( iface->dhcp_options.len[domainName] )
|
|
||||||
fprintf(f,"search %s\n",(char *)iface->dhcp_options.val[domainName]);
|
|
||||||
#endif
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
syslog(LOG_ERR,"dhcpConfig: fopen: %m\n");
|
|
||||||
|
|
||||||
/* moved the next section of code from before to after we've created
|
|
||||||
* resolv.conf. See below for explanation. <poeml@suse.de>
|
|
||||||
* res_init() is normally called from within the first function of the
|
|
||||||
* resolver which is called. Here, we want resolv.conf to be
|
|
||||||
* reread. Otherwise, we won't be able to find out about our hostname,
|
|
||||||
* because the resolver won't notice the change in resolv.conf
|
|
||||||
*/
|
|
||||||
(void)res_init();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int setNISConf(dhcp_interface *iface)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
yp_renamed = 1 + rename (NIS_CONF, ""NIS_CONF".sv");
|
|
||||||
f = fopen (NIS_CONF,"w");
|
|
||||||
if (f)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *domain=NULL;
|
|
||||||
|
|
||||||
if ( iface->dhcp_options.len[nisDomainName] )
|
|
||||||
domain=(char *)iface->dhcp_options.val[nisDomainName];
|
|
||||||
else
|
|
||||||
domain=(char *)iface->dhcp_options.val[domainName];
|
|
||||||
|
|
||||||
for ( i = 0; i < iface->dhcp_options.len[nisServers]; i += 4)
|
|
||||||
{
|
|
||||||
fprintf( f,"domain %s server %u.%u.%u.%u\n", (domain ? domain : "localdomain"),
|
|
||||||
((unsigned char *)iface->dhcp_options.val[nisServers])[i],
|
|
||||||
((unsigned char *)iface->dhcp_options.val[nisServers])[i+1],
|
|
||||||
((unsigned char *)iface->dhcp_options.val[nisServers])[i+2],
|
|
||||||
((unsigned char *)iface->dhcp_options.val[nisServers])[i+3]);
|
|
||||||
}
|
|
||||||
if ( !iface->dhcp_options.len[nisServers] )
|
|
||||||
fprintf (f, "domain %s broadcast\n", (domain ? domain : "localdomain"));
|
|
||||||
fclose (f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
syslog (LOG_ERR, "dhcpConfig: fopen: %m\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int setNTPConf(dhcp_interface *iface)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
ntp_renamed = 1 + rename (NTP_CONF,""NTP_CONF".sv");
|
|
||||||
f = fopen(NTP_CONF,"w");
|
|
||||||
if ( f )
|
|
||||||
{
|
|
||||||
int net, mask;
|
|
||||||
|
|
||||||
memcpy (&mask, iface->dhcp_options.val[subnetMask], 4);
|
|
||||||
net = iface->ciaddr & mask;
|
|
||||||
|
|
||||||
/* Note: Revise drift/log file names and stratum for local clock */
|
|
||||||
fprintf(f,"restrict default noquery notrust nomodify\n");
|
|
||||||
fprintf(f,"restrict 127.0.0.1\n");
|
|
||||||
fprintf(f,"restrict %u.%u.%u.%u mask %u.%u.%u.%u\n",
|
|
||||||
((unsigned char *)&net)[0], ((unsigned char *)&net)[1],
|
|
||||||
((unsigned char *)&net)[2], ((unsigned char *)&net)[3],
|
|
||||||
((unsigned char *)&mask)[0], ((unsigned char *)&mask)[1],
|
|
||||||
((unsigned char *)&mask)[2], ((unsigned char *)&mask)[3]);
|
|
||||||
|
|
||||||
if ( iface->dhcp_options.len[ntpServers] >= 4 )
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char addr[4*3+3*1+1];
|
|
||||||
|
|
||||||
for ( i = 0; i < iface->dhcp_options.len[ntpServers]; i += 4)
|
|
||||||
{
|
|
||||||
snprintf(addr,sizeof(addr),"%u.%u.%u.%u",
|
|
||||||
((unsigned char *)iface->dhcp_options.val[ntpServers])[i],
|
|
||||||
((unsigned char *)iface->dhcp_options.val[ntpServers])[i+1],
|
|
||||||
((unsigned char *)iface->dhcp_options.val[ntpServers])[i+2],
|
|
||||||
((unsigned char *)iface->dhcp_options.val[ntpServers])[i+3]);
|
|
||||||
fprintf(f,"restrict %s\nserver %s\n",addr,addr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ /* No servers found, use local clock */
|
|
||||||
fprintf(f, "fudge 127.127.1.0 stratum 3\n");
|
|
||||||
fprintf(f, "server 127.127.1.0\n");
|
|
||||||
}
|
|
||||||
fprintf(f, "driftfile /etc/ntp.drift\n");
|
|
||||||
fprintf(f, "logfile /var/log/ntp.log\n");
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
syslog(LOG_ERR,"dhcpConfig: fopen: %m\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int setHostName (dhcp_interface *iface)
|
|
||||||
{
|
|
||||||
struct hostent *hp = NULL;
|
|
||||||
char *dname = NULL;
|
|
||||||
int dname_len = 0;
|
|
||||||
|
|
||||||
if ( !iface->dhcp_options.len[hostName] )
|
|
||||||
{
|
|
||||||
hp = gethostbyaddr ((char *)&iface->ciaddr, sizeof(iface->ciaddr), AF_INET);
|
|
||||||
if ( hp )
|
|
||||||
{
|
|
||||||
dname = hp->h_name;
|
|
||||||
while ( *dname > 32 )
|
|
||||||
#if 0
|
|
||||||
if ( *dname == '.' )
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
dname++;
|
|
||||||
|
|
||||||
dname_len = dname-hp->h_name;
|
|
||||||
iface->dhcp_options.val[hostName] = (char *)malloc(dname_len+1);
|
|
||||||
iface->dhcp_options.len[hostName] = dname_len;
|
|
||||||
memcpy ((char *)iface->dhcp_options.val[hostName], hp->h_name, dname_len);
|
|
||||||
((char *)iface->dhcp_options.val[hostName])[dname_len] = 0;
|
|
||||||
iface->dhcp_options.num++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( InitialHostName_len < 0 && gethostname(InitialHostName, sizeof(InitialHostName)) == 0 )
|
|
||||||
{
|
|
||||||
InitialHostName_len = strlen(InitialHostName);
|
|
||||||
if ( DebugFlag )
|
|
||||||
fprintf (stdout, "dhcpcd: orig hostname = %s\n", InitialHostName);
|
|
||||||
}
|
|
||||||
if ( iface->dhcp_options.len[hostName] )
|
|
||||||
{
|
|
||||||
sethostname (iface->dhcp_options.val[hostName], iface->dhcp_options.len[hostName]);
|
|
||||||
if ( DebugFlag )
|
|
||||||
fprintf(stdout,"dhcpcd: your hostname = %s\n", (char *)iface->dhcp_options.val[hostName]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int setDomainName (dhcp_interface *iface)
|
|
||||||
{
|
|
||||||
struct hostent *hp = NULL;
|
|
||||||
char *dname = NULL;
|
|
||||||
int dname_len = 0;
|
|
||||||
|
|
||||||
if ( InitialDomainName_len < 0 && getdomainname(InitialDomainName,sizeof(InitialDomainName)) == 0 )
|
|
||||||
{
|
|
||||||
InitialDomainName_len = strlen(InitialDomainName);
|
|
||||||
if ( DebugFlag )
|
|
||||||
fprintf(stdout,"dhcpcd: orig domainname = %s\n",InitialDomainName);
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
if ( iface->dhcp_options.len[nisDomainName] )
|
|
||||||
{
|
|
||||||
setdomainname (iface->dhcp_options.val[nisDomainName], iface->dhcp_options.len[nisDomainName]);
|
|
||||||
if ( DebugFlag )
|
|
||||||
fprintf(stdout, "dhcpcd: your domainname = %s\n", (char *)iface->dhcp_options.val[nisDomainName]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
if ( ! iface->dhcp_options.len[domainName] )
|
|
||||||
{
|
|
||||||
hp = gethostbyaddr((char *)&iface->ciaddr, sizeof(iface->ciaddr), AF_INET);
|
|
||||||
if ( hp )
|
|
||||||
{
|
|
||||||
dname=hp->h_name;
|
|
||||||
while ( *dname > 32 )
|
|
||||||
{
|
|
||||||
if ( *dname == '.' )
|
|
||||||
{
|
|
||||||
dname++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
dname++;
|
|
||||||
}
|
|
||||||
|
|
||||||
dname_len = strlen (dname);
|
|
||||||
if ( dname_len )
|
|
||||||
{
|
|
||||||
iface->dhcp_options.val[domainName]=(char *)malloc(dname_len+1);
|
|
||||||
iface->dhcp_options.len[domainName]=dname_len;
|
|
||||||
memcpy((char *)iface->dhcp_options.val[domainName], dname,dname_len);
|
|
||||||
((char *)iface->dhcp_options.val[domainName])[dname_len]=0;
|
|
||||||
iface->dhcp_options.num++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( iface->dhcp_options.len[domainName] )
|
|
||||||
{
|
|
||||||
setdomainname(iface->dhcp_options.val[domainName], iface->dhcp_options.len[domainName]);
|
|
||||||
if ( DebugFlag )
|
|
||||||
fprintf(stdout,"dhcpcd: your domainname = %s\n", (char *)iface->dhcp_options.val[domainName]);
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
int setDefaultRoute (dhcp_interface *iface, char *route_addr)
|
|
||||||
{
|
|
||||||
struct rtentry rtent;
|
|
||||||
struct sockaddr_in *p;
|
|
||||||
|
|
||||||
memset (&rtent, 0, sizeof(struct rtentry));
|
|
||||||
p = (struct sockaddr_in *)&rtent.rt_dst;
|
|
||||||
p->sin_family = AF_INET;
|
|
||||||
p->sin_addr.s_addr = 0;
|
|
||||||
p = (struct sockaddr_in *)&rtent.rt_gateway;
|
|
||||||
p->sin_family = AF_INET;
|
|
||||||
memcpy (&p->sin_addr.s_addr, route_addr, 4);
|
|
||||||
p = (struct sockaddr_in *)&rtent.rt_genmask;
|
|
||||||
p->sin_family = AF_INET;
|
|
||||||
p->sin_addr.s_addr = 0;
|
|
||||||
rtent.rt_dev = iface->iface;
|
|
||||||
rtent.rt_metric = 1;
|
|
||||||
rtent.rt_window = iface->client_options->window;
|
|
||||||
rtent.rt_flags = RTF_UP | RTF_GATEWAY | ( rtent.rt_window ? RTF_WINDOW : 0);
|
|
||||||
|
|
||||||
if ( ioctl(iface->sk,SIOCADDRT,&rtent) == -1 )
|
|
||||||
{
|
|
||||||
if ( errno == ENETUNREACH ) /* possibly gateway is over the bridge */
|
|
||||||
{ /* try adding a route to gateway first */
|
|
||||||
struct rtentry rtent2;
|
|
||||||
|
|
||||||
memset (&rtent2, 0, sizeof(struct rtentry));
|
|
||||||
p = (struct sockaddr_in *)&rtent2.rt_dst;
|
|
||||||
p->sin_family = AF_INET;
|
|
||||||
p = (struct sockaddr_in *)&rtent2.rt_gateway;
|
|
||||||
p->sin_family = AF_INET;
|
|
||||||
p->sin_addr.s_addr = 0;
|
|
||||||
memcpy (&p->sin_addr.s_addr, route_addr, 4);
|
|
||||||
p = (struct sockaddr_in *)&rtent2.rt_genmask;
|
|
||||||
p->sin_family = AF_INET;
|
|
||||||
p->sin_addr.s_addr = 0xffffffff;
|
|
||||||
rtent2.rt_dev = iface->iface;
|
|
||||||
rtent2.rt_metric = 0;
|
|
||||||
rtent2.rt_flags = RTF_UP | RTF_HOST;
|
|
||||||
|
|
||||||
if ( ioctl (iface->sk, SIOCADDRT, &rtent2) == 0 )
|
|
||||||
{
|
|
||||||
if ( ioctl (iface->sk, SIOCADDRT, &rtent) == -1 )
|
|
||||||
{
|
|
||||||
syslog(LOG_ERR,"dhcpConfig: ioctl SIOCADDRT: %m\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
syslog(LOG_ERR,"dhcpConfig: ioctl SIOCADDRT: %m\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
int dhcpConfig(dhcp_interface *iface)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
struct ifreq ifr;
|
|
||||||
struct rtentry rtent;
|
|
||||||
struct sockaddr_in *p = (struct sockaddr_in *)&(ifr.ifr_addr);
|
|
||||||
|
|
||||||
/* setting IP address */
|
|
||||||
memset (&ifr, 0, sizeof(struct ifreq));
|
|
||||||
memcpy (ifr.ifr_name, iface->iface, strlen (iface->iface));
|
|
||||||
p->sin_family = AF_INET;
|
|
||||||
p->sin_addr.s_addr = iface->ciaddr;
|
|
||||||
if ( ioctl (iface->sk, SIOCSIFADDR, &ifr) == -1 )
|
|
||||||
{
|
|
||||||
syslog(LOG_ERR,"dhcpConfig: ioctl SIOCSIFADDR: %m\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* setting netmask */
|
|
||||||
memcpy(&p->sin_addr.s_addr,iface->dhcp_options.val[subnetMask],4);
|
|
||||||
if ( ioctl(iface->sk,SIOCSIFNETMASK,&ifr) == -1 )
|
|
||||||
{
|
|
||||||
p->sin_addr.s_addr = 0xffffffff; /* try 255.255.255.255 */
|
|
||||||
if ( ioctl(iface->sk,SIOCSIFNETMASK,&ifr) == -1 )
|
|
||||||
{
|
|
||||||
syslog(LOG_ERR,"dhcpConfig: ioctl SIOCSIFNETMASK: %m\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* setting broadcast address */
|
|
||||||
memcpy (&p->sin_addr.s_addr, iface->dhcp_options.val[broadcastAddr], 4);
|
|
||||||
if ( ioctl(iface->sk,SIOCSIFBRDADDR,&ifr) == -1 )
|
|
||||||
syslog(LOG_ERR,"dhcpConfig: ioctl SIOCSIFBRDADDR: %m\n");
|
|
||||||
|
|
||||||
/* setting static routes */
|
|
||||||
for ( i = 0; i < iface->dhcp_options.len[staticRoute]; i += 8)
|
|
||||||
{
|
|
||||||
struct sockaddr_in *dstp;
|
|
||||||
struct sockaddr_in *gwp;
|
|
||||||
struct sockaddr_in *mskp;
|
|
||||||
|
|
||||||
memset (&rtent,0,sizeof(struct rtentry));
|
|
||||||
dstp = (struct sockaddr_in *)&rtent.rt_dst;
|
|
||||||
dstp->sin_family = AF_INET;
|
|
||||||
memcpy(&dstp->sin_addr.s_addr,((char *)iface->dhcp_options.val[staticRoute])+i,4);
|
|
||||||
|
|
||||||
gwp = (struct sockaddr_in *)&rtent.rt_gateway;
|
|
||||||
gwp->sin_family = AF_INET;
|
|
||||||
memcpy(&gwp->sin_addr.s_addr,((char *)iface->dhcp_options.val[staticRoute])+i+4,4);
|
|
||||||
|
|
||||||
mskp = (struct sockaddr_in *)&rtent.rt_genmask;
|
|
||||||
mskp->sin_family = AF_INET;
|
|
||||||
mskp->sin_addr.s_addr = getgenmask (dstp->sin_addr.s_addr);
|
|
||||||
|
|
||||||
rtent.rt_flags = RTF_UP|RTF_GATEWAY;
|
|
||||||
if ( mskp->sin_addr.s_addr == 0xffffffff )
|
|
||||||
rtent.rt_flags |= RTF_HOST;
|
|
||||||
|
|
||||||
rtent.rt_dev = iface->iface;
|
|
||||||
rtent.rt_metric = 1;
|
|
||||||
if ( ioctl(iface->sk,SIOCADDRT,&rtent) )
|
|
||||||
syslog(LOG_ERR,"dhcpConfig: ioctl SIOCADDRT: %m\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( SetDHCPDefaultRoutes )
|
|
||||||
{
|
|
||||||
if ( iface->dhcp_options.len[routersOnSubnet] > 3 )
|
|
||||||
for ( i = 0; i < iface->dhcp_options.len[routersOnSubnet]; i += 4)
|
|
||||||
setDefaultRoute (iface, iface->dhcp_options.val[routersOnSubnet]);
|
|
||||||
}
|
|
||||||
else if ( iface->default_router.s_addr > 0 )
|
|
||||||
setDefaultRoute (iface, (char *)&(iface->default_router.s_addr));
|
|
||||||
|
|
||||||
arpInform(iface);
|
|
||||||
|
|
||||||
if ( DebugFlag )
|
|
||||||
fprintf(stdout,"dhcpcd: your IP address = %u.%u.%u.%u\n",
|
|
||||||
((unsigned char *)&iface->ciaddr)[0],
|
|
||||||
((unsigned char *)&iface->ciaddr)[1],
|
|
||||||
((unsigned char *)&iface->ciaddr)[2],
|
|
||||||
((unsigned char *)&iface->ciaddr)[3]);
|
|
||||||
|
|
||||||
if ( ReplResolvConf )
|
|
||||||
setResolvConf (iface);
|
|
||||||
|
|
||||||
if ( ReplNISConf )
|
|
||||||
setNISConf (iface);
|
|
||||||
|
|
||||||
if ( ReplNTPConf )
|
|
||||||
setNTPConf (iface);
|
|
||||||
|
|
||||||
if ( SetHostName )
|
|
||||||
setHostName (iface);
|
|
||||||
|
|
||||||
if ( SetDomainName )
|
|
||||||
setDomainName (iface);
|
|
||||||
#if 0
|
|
||||||
if ( iface->ciaddr == previous ip address )
|
|
||||||
{
|
|
||||||
/* execute_on_change("up"); */
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* IP address has changed */
|
|
||||||
/* execute_on_change("new"); */
|
|
||||||
}
|
|
||||||
if ( *(unsigned int *)iface->dhcp_options.val[dhcpIPaddrLeaseTime] == 0xffffffff )
|
|
||||||
{
|
|
||||||
syslog(LOG_INFO,"infinite IP address lease time. Exiting\n");
|
|
||||||
/* exit(0); */
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* dhcpcd - DHCP client daemon -
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
*
|
|
||||||
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
|
|
||||||
*
|
|
||||||
* This 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "udpipgen.h"
|
|
||||||
#include "client.h"
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
unsigned short in_cksum(unsigned short *addr, int len)
|
|
||||||
{
|
|
||||||
register int sum = 0;
|
|
||||||
register u_short *w = addr;
|
|
||||||
register int nleft = len;
|
|
||||||
while ( nleft > 1 )
|
|
||||||
{
|
|
||||||
sum += *w++;
|
|
||||||
nleft -= 2;
|
|
||||||
}
|
|
||||||
if ( nleft == 1 )
|
|
||||||
{
|
|
||||||
u_short a = 0;
|
|
||||||
memcpy(&a,w,1);
|
|
||||||
sum += a;
|
|
||||||
}
|
|
||||||
sum = (sum >> 16) + (sum & 0xffff);
|
|
||||||
sum += (sum >> 16);
|
|
||||||
return ~sum;
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
void udpipgen (udpiphdr *udpip, unsigned int saddr, unsigned int daddr, unsigned short *ip_id, int dhcp_msg_len)
|
|
||||||
{
|
|
||||||
/* Use local copy because udpip->ip is not aligned. */
|
|
||||||
struct ip ip_local;
|
|
||||||
struct ip *ip = &ip_local;
|
|
||||||
struct ipovly *io = (struct ipovly *)udpip->ip;
|
|
||||||
struct udphdr *udp = (struct udphdr *)udpip->udp;
|
|
||||||
|
|
||||||
io->ih_next = io->ih_prev = 0;
|
|
||||||
io->ih_x1 = 0;
|
|
||||||
io->ih_pr = IPPROTO_UDP;
|
|
||||||
io->ih_len = htons (dhcp_msg_len + sizeof (struct udphdr));
|
|
||||||
io->ih_src.s_addr = saddr;
|
|
||||||
io->ih_dst.s_addr = daddr;
|
|
||||||
udp->source = htons (DHCP_CLIENT_PORT);
|
|
||||||
udp->dest = htons (DHCP_SERVER_PORT);
|
|
||||||
udp->len = io->ih_len;
|
|
||||||
udp->check = 0;
|
|
||||||
udp->check = in_cksum ((unsigned short *)udpip, dhcp_msg_len + sizeof (udpiphdr));
|
|
||||||
if (udp->check == 0)
|
|
||||||
udp->check = 0xffff;
|
|
||||||
memcpy (ip,(struct ip *)udpip->ip, sizeof (ip_local));
|
|
||||||
ip->ip_hl = 5;
|
|
||||||
ip->ip_v = IPVERSION;
|
|
||||||
ip->ip_tos = IPTOS_LOWDELAY;
|
|
||||||
ip->ip_len = htons (dhcp_msg_len + sizeof (udpiphdr));
|
|
||||||
|
|
||||||
/* Hmm, since the UDP packets shouldnt' be fragmented, ip_id = 0 */
|
|
||||||
#if 0
|
|
||||||
ip->ip_id = htons (*ip_id); *ip_id++;
|
|
||||||
#else
|
|
||||||
ip->ip_id = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ip->ip_off = 0;
|
|
||||||
ip->ip_ttl = IPDEFTTL; /* time to live, 64 by default */
|
|
||||||
ip->ip_p = IPPROTO_UDP;
|
|
||||||
ip->ip_src.s_addr = saddr;
|
|
||||||
ip->ip_dst.s_addr = daddr;
|
|
||||||
ip->ip_sum = 0;
|
|
||||||
memcpy (udpip->ip, ip, sizeof (ip_local));
|
|
||||||
ip->ip_sum = in_cksum ((unsigned short *)&ip_local, sizeof (struct ip));
|
|
||||||
memcpy (udpip->ip, ip, sizeof (ip_local));
|
|
||||||
}
|
|
||||||
/*****************************************************************************/
|
|
||||||
int udpipchk(udpiphdr *udpip)
|
|
||||||
{
|
|
||||||
int hl;
|
|
||||||
struct ip save_ip;
|
|
||||||
struct ip *ip = (struct ip *)udpip->ip;
|
|
||||||
struct ipovly *io = (struct ipovly *)udpip->ip;
|
|
||||||
struct udphdr *udp = (struct udphdr *)udpip->udp;
|
|
||||||
udpiphdr *nudpip = udpip;
|
|
||||||
|
|
||||||
hl = ip->ip_hl<<2;
|
|
||||||
if (in_cksum ((unsigned short *)udpip, hl))
|
|
||||||
return -1;
|
|
||||||
memcpy (&save_ip, udpip->ip, sizeof (struct ip));
|
|
||||||
hl -= sizeof (struct ip);
|
|
||||||
if (hl)
|
|
||||||
{
|
|
||||||
/* thrash IP options */
|
|
||||||
nudpip = (udpiphdr *)((char *)udpip + hl);
|
|
||||||
memmove ((char *)nudpip, udpip, sizeof (struct ip));
|
|
||||||
io = (struct ipovly *)nudpip->ip;
|
|
||||||
ip = (struct ip *)nudpip->ip;
|
|
||||||
udp = (struct udphdr *)nudpip->udp;
|
|
||||||
}
|
|
||||||
if (udp->check == 0)
|
|
||||||
return 0; /* no checksum has been done by sender */
|
|
||||||
io->ih_next = io->ih_prev = 0;
|
|
||||||
io->ih_x1 = 0;
|
|
||||||
io->ih_len = udp->len;
|
|
||||||
hl = ntohs (udp->len) + sizeof (struct ip);
|
|
||||||
if (in_cksum ((unsigned short *)nudpip, hl))
|
|
||||||
return -2;
|
|
||||||
memcpy (udpip->ip, &save_ip, sizeof(struct ip));
|
|
||||||
return 0;
|
|
||||||
}
|
|
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* dhcpcd - DHCP client daemon -
|
|
||||||
* Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
|
|
||||||
*
|
|
||||||
* dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
|
|
||||||
*
|
|
||||||
* This 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef UDPIPGEN_H
|
|
||||||
#define UDPIPGEN_H
|
|
||||||
|
|
||||||
#include <netinet/ip.h>
|
|
||||||
#include <netinet/udp.h>
|
|
||||||
|
|
||||||
#ifndef IPDEFTTL
|
|
||||||
#define IPDEFTTL 64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct ipovly
|
|
||||||
{
|
|
||||||
int ih_next,ih_prev;
|
|
||||||
u_char ih_x1;
|
|
||||||
u_char ih_pr;
|
|
||||||
u_short ih_len;
|
|
||||||
struct in_addr ih_src;
|
|
||||||
struct in_addr ih_dst;
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
typedef struct udpiphdr
|
|
||||||
{
|
|
||||||
char ip[sizeof(struct ip)];
|
|
||||||
char udp[sizeof(struct udphdr)];
|
|
||||||
} __attribute__((packed)) udpiphdr;
|
|
||||||
|
|
||||||
void udpipgen (udpiphdr *udpip, unsigned int saddr, unsigned int daddr, unsigned short *ip_id, int dhcp_msg_len);
|
|
||||||
int udpipchk (udpiphdr *udpip);
|
|
||||||
|
|
||||||
#endif
|
|
@@ -38,76 +38,6 @@
|
|||||||
void nmwa_dbus_devices_schedule_copy (NMWirelessApplet *applet);
|
void nmwa_dbus_devices_schedule_copy (NMWirelessApplet *applet);
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nmwa_dbus_get_active_device_cb
|
|
||||||
*
|
|
||||||
* Callback from nmwa_dbus_get_active_device
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void nmwa_dbus_get_active_device_cb (DBusPendingCall *pcall, void *user_data)
|
|
||||||
{
|
|
||||||
DBusMessage * reply;
|
|
||||||
NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
|
|
||||||
const char * act_dev;
|
|
||||||
|
|
||||||
g_return_if_fail (pcall != NULL);
|
|
||||||
g_return_if_fail (applet != NULL);
|
|
||||||
|
|
||||||
dbus_pending_call_ref (pcall);
|
|
||||||
|
|
||||||
if (!dbus_pending_call_get_completed (pcall))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (!(reply = dbus_pending_call_steal_reply (pcall)))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (dbus_message_is_error (reply, NM_DBUS_NO_ACTIVE_DEVICE_ERROR))
|
|
||||||
{
|
|
||||||
dbus_message_unref (reply);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &act_dev, DBUS_TYPE_INVALID))
|
|
||||||
{
|
|
||||||
g_free (applet->dbus_active_device_path);
|
|
||||||
applet->dbus_active_device_path = g_strdup (act_dev);
|
|
||||||
}
|
|
||||||
dbus_message_unref (reply);
|
|
||||||
|
|
||||||
out:
|
|
||||||
applet->dev_pending_call_list = g_slist_remove (applet->dev_pending_call_list, pcall);
|
|
||||||
nmwa_dbus_devices_schedule_copy (applet);
|
|
||||||
|
|
||||||
dbus_pending_call_unref (pcall);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nmwa_dbus_get_active_device
|
|
||||||
*
|
|
||||||
* Get the active device from NetworkManager
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void nmwa_dbus_get_active_device (NMWirelessApplet *applet)
|
|
||||||
{
|
|
||||||
DBusMessage * message;
|
|
||||||
DBusPendingCall * pcall = NULL;
|
|
||||||
|
|
||||||
g_return_if_fail (applet != NULL);
|
|
||||||
|
|
||||||
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getActiveDevice")))
|
|
||||||
{
|
|
||||||
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
|
|
||||||
dbus_message_unref (message);
|
|
||||||
if (pcall)
|
|
||||||
{
|
|
||||||
dbus_pending_call_set_notify (pcall, nmwa_dbus_get_active_device_cb, applet, NULL);
|
|
||||||
applet->dev_pending_call_list = g_slist_append (applet->dev_pending_call_list, pcall);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nmwa_dbus_nm_state_cb
|
* nmwa_dbus_nm_state_cb
|
||||||
*
|
*
|
||||||
@@ -604,11 +534,6 @@ void nmwa_free_gui_data_model (NMWirelessApplet *applet)
|
|||||||
g_slist_free (applet->gui_device_list);
|
g_slist_free (applet->gui_device_list);
|
||||||
applet->gui_device_list = NULL;
|
applet->gui_device_list = NULL;
|
||||||
}
|
}
|
||||||
if (applet->gui_active_device)
|
|
||||||
{
|
|
||||||
network_device_unref (applet->gui_active_device);
|
|
||||||
applet->gui_active_device = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -624,13 +549,6 @@ void nmwa_free_dbus_data_model (NMWirelessApplet *applet)
|
|||||||
g_slist_free (applet->dbus_device_list);
|
g_slist_free (applet->dbus_device_list);
|
||||||
applet->dbus_device_list = NULL;
|
applet->dbus_device_list = NULL;
|
||||||
}
|
}
|
||||||
if (applet->dbus_active_device)
|
|
||||||
{
|
|
||||||
network_device_unref (applet->dbus_active_device);
|
|
||||||
applet->dbus_active_device = NULL;
|
|
||||||
}
|
|
||||||
g_free (applet->dbus_active_device_path);
|
|
||||||
applet->dbus_active_device_path = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -657,21 +575,9 @@ void nmwa_copy_data_model (NMWirelessApplet *applet)
|
|||||||
NetworkDevice *dst = network_device_copy (src);
|
NetworkDevice *dst = network_device_copy (src);
|
||||||
|
|
||||||
if (dst)
|
if (dst)
|
||||||
{
|
|
||||||
/* Transfer ownership of device to list, don't need to unref it */
|
|
||||||
applet->gui_device_list = g_slist_append (applet->gui_device_list, dst);
|
applet->gui_device_list = g_slist_append (applet->gui_device_list, dst);
|
||||||
|
|
||||||
/* Make sure we get the right active device for the gui data model */
|
|
||||||
if (applet->dbus_active_device == src)
|
|
||||||
{
|
|
||||||
network_device_ref (dst);
|
|
||||||
act_dev = dst;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* active_device is just a pointer into the device list, no need to deep-copy it */
|
|
||||||
applet->gui_active_device = act_dev;
|
|
||||||
applet->gui_nm_state = applet->dbus_nm_state;
|
applet->gui_nm_state = applet->dbus_nm_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -919,6 +825,7 @@ void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_data)
|
|||||||
const char * iface = NULL;
|
const char * iface = NULL;
|
||||||
dbus_uint32_t type = 0;
|
dbus_uint32_t type = 0;
|
||||||
const char * udi = NULL;
|
const char * udi = NULL;
|
||||||
|
dbus_bool_t active = FALSE;
|
||||||
dbus_uint32_t ip4_address = 0;
|
dbus_uint32_t ip4_address = 0;
|
||||||
const char * hw_addr = NULL;
|
const char * hw_addr = NULL;
|
||||||
dbus_uint32_t mode = 0;
|
dbus_uint32_t mode = 0;
|
||||||
@@ -950,6 +857,7 @@ void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_data)
|
|||||||
DBUS_TYPE_STRING, &iface,
|
DBUS_TYPE_STRING, &iface,
|
||||||
DBUS_TYPE_UINT32, &type,
|
DBUS_TYPE_UINT32, &type,
|
||||||
DBUS_TYPE_STRING, &udi,
|
DBUS_TYPE_STRING, &udi,
|
||||||
|
DBUS_TYPE_BOOLEAN,&active,
|
||||||
DBUS_TYPE_UINT32, &ip4_address,
|
DBUS_TYPE_UINT32, &ip4_address,
|
||||||
DBUS_TYPE_STRING, &hw_addr,
|
DBUS_TYPE_STRING, &hw_addr,
|
||||||
DBUS_TYPE_UINT32, &mode,
|
DBUS_TYPE_UINT32, &mode,
|
||||||
@@ -965,6 +873,7 @@ void nmwa_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_data)
|
|||||||
|
|
||||||
network_device_set_hal_udi (dev, udi);
|
network_device_set_hal_udi (dev, udi);
|
||||||
network_device_set_address (dev, hw_addr);
|
network_device_set_address (dev, hw_addr);
|
||||||
|
network_device_set_active (dev, active);
|
||||||
network_device_set_link (dev, link_active);
|
network_device_set_link (dev, link_active);
|
||||||
network_device_set_driver_support_level (dev, driver_support_level);
|
network_device_set_driver_support_level (dev, driver_support_level);
|
||||||
|
|
||||||
@@ -1021,8 +930,6 @@ void nmwa_dbus_device_update_one_device (NMWirelessApplet *applet, const char *d
|
|||||||
g_return_if_fail (applet != NULL);
|
g_return_if_fail (applet != NULL);
|
||||||
g_return_if_fail (dev_path != NULL);
|
g_return_if_fail (dev_path != NULL);
|
||||||
|
|
||||||
nmwa_dbus_get_active_device (applet);
|
|
||||||
|
|
||||||
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties")))
|
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties")))
|
||||||
{
|
{
|
||||||
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
|
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
|
||||||
@@ -1098,8 +1005,6 @@ void nmwa_dbus_update_devices (NMWirelessApplet *applet)
|
|||||||
|
|
||||||
nmwa_free_dbus_data_model (applet);
|
nmwa_free_dbus_data_model (applet);
|
||||||
|
|
||||||
nmwa_dbus_get_active_device (applet);
|
|
||||||
|
|
||||||
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDevices")))
|
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDevices")))
|
||||||
{
|
{
|
||||||
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
|
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
|
||||||
@@ -1281,7 +1186,7 @@ void free_strength_cb_data (StrengthCBData *data)
|
|||||||
/*
|
/*
|
||||||
* nmwa_dbus_update_device_strength_cb
|
* nmwa_dbus_update_device_strength_cb
|
||||||
*
|
*
|
||||||
* nmwa_dbus_update_active_device_strength callback.
|
* nmwa_dbus_update_device_strength callback.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void nmwa_dbus_update_device_strength_cb (DBusPendingCall *pcall, void *user_data)
|
void nmwa_dbus_update_device_strength_cb (DBusPendingCall *pcall, void *user_data)
|
||||||
@@ -1313,17 +1218,15 @@ void nmwa_dbus_update_device_strength_cb (DBusPendingCall *pcall, void *user_dat
|
|||||||
|
|
||||||
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID))
|
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_INT32, &strength, DBUS_TYPE_INVALID))
|
||||||
{
|
{
|
||||||
|
NetworkDevice *dev;
|
||||||
|
|
||||||
/* Update strength on dbus active device */
|
/* Update strength on dbus active device */
|
||||||
if ( cb_data->dev_path
|
if ((dev = nmwa_get_device_for_nm_device (applet->dbus_device_list, cb_data->dev_path)))
|
||||||
&& applet->dbus_active_device
|
network_device_set_strength (dev, strength);
|
||||||
&& !strcmp (cb_data->dev_path, network_device_get_nm_path (applet->dbus_active_device)))
|
|
||||||
network_device_set_strength (applet->dbus_active_device, strength);
|
|
||||||
|
|
||||||
/* Update strength on gui active device too */
|
/* Update strength on gui active device too */
|
||||||
if ( cb_data->dev_path
|
if ((dev = nmwa_get_device_for_nm_device (applet->gui_device_list, cb_data->dev_path)))
|
||||||
&& applet->gui_active_device
|
network_device_set_strength (dev, strength);
|
||||||
&& !strcmp (cb_data->dev_path, network_device_get_nm_path (applet->gui_active_device)))
|
|
||||||
network_device_set_strength (applet->gui_active_device, strength);
|
|
||||||
}
|
}
|
||||||
dbus_message_unref (reply);
|
dbus_message_unref (reply);
|
||||||
|
|
||||||
@@ -1332,23 +1235,15 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
static void get_each_device_strength (NetworkDevice *dev, NMWirelessApplet *applet)
|
||||||
* nmwa_dbus_update_active_device_strength
|
{
|
||||||
*
|
g_return_if_fail (dev != NULL);
|
||||||
* Update the active device's strength.
|
|
||||||
*
|
if (network_device_get_active (dev))
|
||||||
*/
|
|
||||||
gboolean nmwa_dbus_update_active_device_strength (NMWirelessApplet *applet)
|
|
||||||
{
|
{
|
||||||
NetworkDevice * dev;
|
|
||||||
DBusMessage * message;
|
DBusMessage * message;
|
||||||
DBusPendingCall * pcall;
|
DBusPendingCall * pcall;
|
||||||
|
|
||||||
g_return_val_if_fail (applet != NULL, TRUE);
|
|
||||||
|
|
||||||
if (!(dev = applet->dbus_active_device))
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, network_device_get_nm_path (dev), NM_DBUS_INTERFACE_DEVICES, "getStrength")))
|
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, network_device_get_nm_path (dev), NM_DBUS_INTERFACE_DEVICES, "getStrength")))
|
||||||
{
|
{
|
||||||
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
|
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
|
||||||
@@ -1362,6 +1257,24 @@ gboolean nmwa_dbus_update_active_device_strength (NMWirelessApplet *applet)
|
|||||||
dbus_pending_call_set_notify (pcall, nmwa_dbus_update_device_strength_cb, cb_data, (DBusFreeFunction) free_strength_cb_data);
|
dbus_pending_call_set_notify (pcall, nmwa_dbus_update_device_strength_cb, cb_data, (DBusFreeFunction) free_strength_cb_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nmwa_dbus_update_device_strength
|
||||||
|
*
|
||||||
|
* Update the each active device's strength.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gboolean nmwa_dbus_update_device_strength (NMWirelessApplet *applet)
|
||||||
|
{
|
||||||
|
NetworkDevice * dev;
|
||||||
|
DBusMessage * message;
|
||||||
|
DBusPendingCall * pcall;
|
||||||
|
|
||||||
|
g_return_val_if_fail (applet != NULL, TRUE);
|
||||||
|
|
||||||
|
g_slist_foreach (applet->dbus_device_list, (GFunc) get_each_device_strength, applet);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -1435,17 +1348,12 @@ static gboolean nmwa_dbus_devices_lock_and_copy (NMWirelessApplet *applet)
|
|||||||
/* Sort the devices for display */
|
/* Sort the devices for display */
|
||||||
applet->dbus_device_list = g_slist_sort (applet->dbus_device_list, sort_devices_function);
|
applet->dbus_device_list = g_slist_sort (applet->dbus_device_list, sort_devices_function);
|
||||||
|
|
||||||
/* Match up the active device path with a device in the list */
|
|
||||||
if (applet->dbus_active_device_path &&
|
|
||||||
(applet->dbus_active_device = nmwa_get_device_for_nm_device (applet->dbus_device_list, applet->dbus_active_device_path)))
|
|
||||||
network_device_ref (applet->dbus_active_device);
|
|
||||||
|
|
||||||
/* Now copy the data over to the GUI side */
|
/* Now copy the data over to the GUI side */
|
||||||
g_mutex_lock (applet->data_mutex);
|
g_mutex_lock (applet->data_mutex);
|
||||||
nmwa_copy_data_model (applet);
|
nmwa_copy_data_model (applet);
|
||||||
g_mutex_unlock (applet->data_mutex);
|
g_mutex_unlock (applet->data_mutex);
|
||||||
|
|
||||||
nmwa_dbus_update_active_device_strength (applet);
|
nmwa_dbus_update_device_strength (applet);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@@ -32,11 +32,10 @@
|
|||||||
|
|
||||||
void nmwa_dbus_update_one_vpn_connection (DBusConnection *connection, const char *name, NMWirelessApplet *applet, gboolean is_active);
|
void nmwa_dbus_update_one_vpn_connection (DBusConnection *connection, const char *name, NMWirelessApplet *applet, gboolean is_active);
|
||||||
void nmwa_dbus_update_vpn_connections (NMWirelessApplet *applet);
|
void nmwa_dbus_update_vpn_connections (NMWirelessApplet *applet);
|
||||||
gboolean nmwa_dbus_update_active_device_strength (NMWirelessApplet *applet);
|
gboolean nmwa_dbus_update_device_strength (NMWirelessApplet *applet);
|
||||||
|
|
||||||
void nmwa_dbus_update_nm_state (NMWirelessApplet *applet);
|
void nmwa_dbus_update_nm_state (NMWirelessApplet *applet);
|
||||||
|
|
||||||
void nmwa_dbus_get_active_device (NMWirelessApplet *applet);
|
|
||||||
void nmwa_dbus_update_devices (NMWirelessApplet *applet);
|
void nmwa_dbus_update_devices (NMWirelessApplet *applet);
|
||||||
void nmwa_dbus_device_update_one_device (NMWirelessApplet *applet, const char *dev_path);
|
void nmwa_dbus_device_update_one_device (NMWirelessApplet *applet, const char *dev_path);
|
||||||
void nmwa_dbus_device_remove_one_device (NMWirelessApplet *applet, const char *dev_path);
|
void nmwa_dbus_device_remove_one_device (NMWirelessApplet *applet, const char *dev_path);
|
||||||
|
@@ -71,14 +71,13 @@ static DBusMessage * nmi_dbus_get_key_for_network (NMWirelessApplet *applet, DBu
|
|||||||
NetworkDevice *dev = NULL;
|
NetworkDevice *dev = NULL;
|
||||||
WirelessNetwork *net = NULL;
|
WirelessNetwork *net = NULL;
|
||||||
|
|
||||||
|
g_mutex_lock (applet->data_mutex);
|
||||||
if ((dev = nmwa_get_device_for_nm_device (applet->gui_device_list, dev_path)))
|
if ((dev = nmwa_get_device_for_nm_device (applet->gui_device_list, dev_path)))
|
||||||
{
|
{
|
||||||
if ((net = network_device_get_wireless_network_by_nm_path (dev, net_path)))
|
if ((net = network_device_get_wireless_network_by_nm_path (dev, net_path)))
|
||||||
{
|
success = nmi_passphrase_dialog_schedule_show (dev, net, message, applet);
|
||||||
nmi_passphrase_dialog_show (applet->passphrase_dialog, dev, net, message);
|
|
||||||
success = TRUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
g_mutex_unlock (applet->data_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
@@ -837,7 +836,7 @@ DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBu
|
|||||||
if (strcmp ("getKeyForNetwork", method) == 0)
|
if (strcmp ("getKeyForNetwork", method) == 0)
|
||||||
reply = nmi_dbus_get_key_for_network (applet, message);
|
reply = nmi_dbus_get_key_for_network (applet, message);
|
||||||
else if (strcmp ("cancelGetKeyForNetwork", method) == 0)
|
else if (strcmp ("cancelGetKeyForNetwork", method) == 0)
|
||||||
nmi_passphrase_dialog_cancel (applet->passphrase_dialog);
|
nmi_passphrase_dialog_schedule_cancel (applet);
|
||||||
else if (strcmp ("networkNotFound", method) == 0)
|
else if (strcmp ("networkNotFound", method) == 0)
|
||||||
{
|
{
|
||||||
const char * network;
|
const char * network;
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
#include "applet-dbus-vpn.h"
|
#include "applet-dbus-vpn.h"
|
||||||
#include "applet-dbus-info.h"
|
#include "applet-dbus-info.h"
|
||||||
#include "vpn-connection.h"
|
#include "vpn-connection.h"
|
||||||
|
#include "passphrase-dialog.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
|
|
||||||
#define DBUS_NO_SERVICE_ERROR "org.freedesktop.DBus.Error.ServiceDoesNotExist"
|
#define DBUS_NO_SERVICE_ERROR "org.freedesktop.DBus.Error.ServiceDoesNotExist"
|
||||||
@@ -439,7 +440,10 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
|
|||||||
nmwa_dbus_vpn_update_vpn_connections (applet);
|
nmwa_dbus_vpn_update_vpn_connections (applet);
|
||||||
}
|
}
|
||||||
else if (old_owner_good && !new_owner_good)
|
else if (old_owner_good && !new_owner_good)
|
||||||
|
{
|
||||||
applet->nm_running = FALSE;
|
applet->nm_running = FALSE;
|
||||||
|
nmi_passphrase_dialog_schedule_cancel (applet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -449,14 +453,16 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
|
|||||||
|
|
||||||
if (dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID))
|
if (dbus_message_get_args (message, NULL, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID))
|
||||||
{
|
{
|
||||||
|
NetworkDevice *act_dev = nmwa_get_first_active_device (applet->dbus_device_list);
|
||||||
|
|
||||||
/* If we've switched to connecting, update the active device to ensure that we have
|
/* If we've switched to connecting, update the active device to ensure that we have
|
||||||
* valid wireless network information for it.
|
* valid wireless network information for it.
|
||||||
*/
|
*/
|
||||||
if ( (state == NM_STATE_CONNECTING)
|
if ( (state == NM_STATE_CONNECTING)
|
||||||
&& applet->dbus_active_device
|
&& act_dev
|
||||||
&& (network_device_get_type (applet->dbus_active_device) == DEVICE_TYPE_WIRELESS_ETHERNET))
|
&& (network_device_get_type (act_dev) == DEVICE_TYPE_WIRELESS_ETHERNET))
|
||||||
{
|
{
|
||||||
nmwa_dbus_device_update_one_device (applet, network_device_get_nm_path (applet->dbus_active_device));
|
nmwa_dbus_device_update_one_device (applet, network_device_get_nm_path (act_dev));
|
||||||
}
|
}
|
||||||
applet->dbus_nm_state = state;
|
applet->dbus_nm_state = state;
|
||||||
applet->gui_nm_state = state;
|
applet->gui_nm_state = state;
|
||||||
@@ -733,7 +739,7 @@ gpointer nmwa_dbus_worker (gpointer user_data)
|
|||||||
g_source_attach (timeout_source, applet->thread_context);
|
g_source_attach (timeout_source, applet->thread_context);
|
||||||
|
|
||||||
strength_source = g_timeout_source_new (2000);
|
strength_source = g_timeout_source_new (2000);
|
||||||
g_source_set_callback (strength_source, (GSourceFunc) nmwa_dbus_update_active_device_strength, applet, NULL);
|
g_source_set_callback (strength_source, (GSourceFunc) nmwa_dbus_update_device_strength, applet, NULL);
|
||||||
g_source_attach (strength_source, applet->thread_context);
|
g_source_attach (strength_source, applet->thread_context);
|
||||||
|
|
||||||
if (applet->connection && nmwa_dbus_nm_is_running (applet->connection))
|
if (applet->connection && nmwa_dbus_nm_is_running (applet->connection))
|
||||||
|
@@ -98,6 +98,31 @@ int nm_null_safe_strcmp (const char *s1, const char *s2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nmwa_get_first_active_device
|
||||||
|
*
|
||||||
|
* Return the first device marked as "active".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
NetworkDevice * nmwa_get_first_active_device (GSList *dev_list)
|
||||||
|
{
|
||||||
|
GSList * elt;
|
||||||
|
|
||||||
|
if (!dev_list)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (elt = dev_list; elt; elt = g_slist_next (elt))
|
||||||
|
{
|
||||||
|
NetworkDevice *dev = (NetworkDevice *)(elt->data);
|
||||||
|
|
||||||
|
if (network_device_get_active (dev))
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void nmwa_init (NMWirelessApplet *applet)
|
static void nmwa_init (NMWirelessApplet *applet)
|
||||||
{
|
{
|
||||||
applet->animation_id = 0;
|
applet->animation_id = 0;
|
||||||
@@ -280,8 +305,8 @@ static gboolean nmwa_show_vpn_login_banner_dialog (char *message)
|
|||||||
g_return_val_if_fail (message != NULL, FALSE);
|
g_return_val_if_fail (message != NULL, FALSE);
|
||||||
|
|
||||||
dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, message, NULL);
|
dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, message, NULL);
|
||||||
g_signal_connect (dialog, "response", G_CALLBACK (vpn_login_failure_dialog_close_cb), NULL);
|
g_signal_connect (dialog, "response", G_CALLBACK (vpn_login_banner_dialog_close_cb), NULL);
|
||||||
g_signal_connect (dialog, "close", G_CALLBACK (vpn_login_failure_dialog_close_cb), NULL);
|
g_signal_connect (dialog, "close", G_CALLBACK (vpn_login_banner_dialog_close_cb), NULL);
|
||||||
g_object_set_data (G_OBJECT (dialog), "message", message);
|
g_object_set_data (G_OBJECT (dialog), "message", message);
|
||||||
gtk_widget_show_all (dialog);
|
gtk_widget_show_all (dialog);
|
||||||
|
|
||||||
@@ -305,7 +330,7 @@ void nmwa_schedule_vpn_login_banner_dialog (NMWirelessApplet *applet, const char
|
|||||||
|
|
||||||
msg = g_strdup_printf (_("<span weight=\"bold\" size=\"larger\">VPN Login Message</span>\n\n"
|
msg = g_strdup_printf (_("<span weight=\"bold\" size=\"larger\">VPN Login Message</span>\n\n"
|
||||||
"VPN connection '%s' said:\n\n\"%s\""), vpn_name, banner);
|
"VPN connection '%s' said:\n\n\"%s\""), vpn_name, banner);
|
||||||
g_idle_add ((GSourceFunc) nmwa_show_vpn_login_failure_dialog, msg);
|
g_idle_add ((GSourceFunc) nmwa_show_vpn_login_banner_dialog, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -596,6 +621,8 @@ static void nmwa_set_icon (NMWirelessApplet *applet, GdkPixbuf *new_icon)
|
|||||||
*/
|
*/
|
||||||
static gboolean animation_timeout (NMWirelessApplet *applet)
|
static gboolean animation_timeout (NMWirelessApplet *applet)
|
||||||
{
|
{
|
||||||
|
NetworkDevice *act_dev = nmwa_get_first_active_device (applet->dbus_device_list);
|
||||||
|
|
||||||
if (!applet->nm_running)
|
if (!applet->nm_running)
|
||||||
{
|
{
|
||||||
applet->animation_step = 0;
|
applet->animation_step = 0;
|
||||||
@@ -604,14 +631,14 @@ static gboolean animation_timeout (NMWirelessApplet *applet)
|
|||||||
|
|
||||||
switch (applet->gui_nm_state)
|
switch (applet->gui_nm_state)
|
||||||
{
|
{
|
||||||
case (NM_STATE_CONNECTING):
|
case NM_STATE_CONNECTING:
|
||||||
if (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRELESS_ETHERNET)
|
if (act_dev && (network_device_get_type (act_dev) == DEVICE_TYPE_WIRELESS_ETHERNET))
|
||||||
{
|
{
|
||||||
if (applet->animation_step >= NUM_WIRELESS_CONNECTING_FRAMES)
|
if (applet->animation_step >= NUM_WIRELESS_CONNECTING_FRAMES)
|
||||||
applet->animation_step = 0;
|
applet->animation_step = 0;
|
||||||
nmwa_set_icon (applet, applet->wireless_connecting_icons[applet->animation_step]);
|
nmwa_set_icon (applet, applet->wireless_connecting_icons[applet->animation_step]);
|
||||||
}
|
}
|
||||||
else
|
else if (act_dev)
|
||||||
{
|
{
|
||||||
if (applet->animation_step >= NUM_WIRED_CONNECTING_FRAMES)
|
if (applet->animation_step >= NUM_WIRED_CONNECTING_FRAMES)
|
||||||
applet->animation_step = 0;
|
applet->animation_step = 0;
|
||||||
@@ -620,13 +647,6 @@ static gboolean animation_timeout (NMWirelessApplet *applet)
|
|||||||
applet->animation_step ++;
|
applet->animation_step ++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (NM_STATE_SCANNING):
|
|
||||||
if (applet->animation_step >= NUM_WIRELESS_SCANNING_FRAMES)
|
|
||||||
applet->animation_step = 0;
|
|
||||||
nmwa_set_icon (applet, applet->wireless_scanning_icons[applet->animation_step]);
|
|
||||||
applet->animation_step ++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -651,13 +671,15 @@ static void nmwa_update_state (NMWirelessApplet *applet)
|
|||||||
gint strength = -1;
|
gint strength = -1;
|
||||||
char * tip = NULL;
|
char * tip = NULL;
|
||||||
WirelessNetwork * active_network = NULL;
|
WirelessNetwork * active_network = NULL;
|
||||||
|
NetworkDevice * act_dev = NULL;
|
||||||
|
|
||||||
g_mutex_lock (applet->data_mutex);
|
g_mutex_lock (applet->data_mutex);
|
||||||
|
|
||||||
if (applet->gui_active_device && (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRELESS_ETHERNET))
|
act_dev = nmwa_get_first_active_device (applet->gui_device_list);
|
||||||
|
if (act_dev && (network_device_get_type (act_dev) == DEVICE_TYPE_WIRELESS_ETHERNET))
|
||||||
{
|
{
|
||||||
active_network = network_device_get_active_wireless_network (applet->gui_active_device);
|
active_network = network_device_get_active_wireless_network (act_dev);
|
||||||
strength = CLAMP ((int)network_device_get_strength (applet->gui_active_device), 0, 100);
|
strength = CLAMP ((int)network_device_get_strength (act_dev), 0, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!applet->nm_running)
|
if (!applet->nm_running)
|
||||||
@@ -667,7 +689,7 @@ static void nmwa_update_state (NMWirelessApplet *applet)
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!applet->gui_active_device)
|
if (!act_dev)
|
||||||
applet->gui_nm_state = NM_STATE_DISCONNECTED;
|
applet->gui_nm_state = NM_STATE_DISCONNECTED;
|
||||||
|
|
||||||
switch (applet->gui_nm_state)
|
switch (applet->gui_nm_state)
|
||||||
@@ -678,12 +700,12 @@ static void nmwa_update_state (NMWirelessApplet *applet)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case NM_STATE_CONNECTED:
|
case NM_STATE_CONNECTED:
|
||||||
if (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRED_ETHERNET)
|
if (network_device_get_type (act_dev) == DEVICE_TYPE_WIRED_ETHERNET)
|
||||||
{
|
{
|
||||||
pixbuf = applet->wired_icon;
|
pixbuf = applet->wired_icon;
|
||||||
tip = g_strdup (_("Wired network connection"));
|
tip = g_strdup (_("Wired network connection"));
|
||||||
}
|
}
|
||||||
else if (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRELESS_ETHERNET)
|
else if (network_device_get_type (act_dev) == DEVICE_TYPE_WIRELESS_ETHERNET)
|
||||||
{
|
{
|
||||||
if (applet->is_adhoc)
|
if (applet->is_adhoc)
|
||||||
{
|
{
|
||||||
@@ -709,9 +731,9 @@ static void nmwa_update_state (NMWirelessApplet *applet)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case NM_STATE_CONNECTING:
|
case NM_STATE_CONNECTING:
|
||||||
if (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRED_ETHERNET)
|
if (network_device_get_type (act_dev) == DEVICE_TYPE_WIRED_ETHERNET)
|
||||||
tip = g_strdup (_("Connecting to a wired network..."));
|
tip = g_strdup (_("Connecting to a wired network..."));
|
||||||
else if (network_device_get_type (applet->gui_active_device) == DEVICE_TYPE_WIRELESS_ETHERNET)
|
else if (network_device_get_type (act_dev) == DEVICE_TYPE_WIRELESS_ETHERNET)
|
||||||
tip = g_strdup_printf (_("Connecting to wireless network '%s'..."),
|
tip = g_strdup_printf (_("Connecting to wireless network '%s'..."),
|
||||||
active_network ? wireless_network_get_essid (active_network) : "(unknown)");
|
active_network ? wireless_network_get_essid (active_network) : "(unknown)");
|
||||||
need_animation = TRUE;
|
need_animation = TRUE;
|
||||||
@@ -1009,7 +1031,7 @@ static void nmwa_menu_add_text_item (GtkWidget *menu, char *text)
|
|||||||
* Add a network device to the menu
|
* Add a network device to the menu
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void nmwa_menu_add_device_item (GtkWidget *menu, NetworkDevice *device, gboolean current, gint n_devices, NMWirelessApplet *applet)
|
static void nmwa_menu_add_device_item (GtkWidget *menu, NetworkDevice *device, gint n_devices, NMWirelessApplet *applet)
|
||||||
{
|
{
|
||||||
GtkWidget * menu_item;
|
GtkWidget * menu_item;
|
||||||
|
|
||||||
@@ -1024,7 +1046,7 @@ static void nmwa_menu_add_device_item (GtkWidget *menu, NetworkDevice *device, g
|
|||||||
NMWiredMenuItem *item = wired_menu_item_new ();
|
NMWiredMenuItem *item = wired_menu_item_new ();
|
||||||
GtkCheckMenuItem *gtk_item = wired_menu_item_get_check_item (item);
|
GtkCheckMenuItem *gtk_item = wired_menu_item_get_check_item (item);
|
||||||
wired_menu_item_update (item, device, n_devices);
|
wired_menu_item_update (item, device, n_devices);
|
||||||
if (applet->gui_active_device == device)
|
if (network_device_get_active (device))
|
||||||
gtk_check_menu_item_set_active (gtk_item, TRUE);
|
gtk_check_menu_item_set_active (gtk_item, TRUE);
|
||||||
|
|
||||||
g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (network_device_get_iface (device)));
|
g_object_set_data (G_OBJECT (gtk_item), "device", g_strdup (network_device_get_iface (device)));
|
||||||
@@ -1127,7 +1149,7 @@ void nmwa_add_networks_helper (NetworkDevice *dev, WirelessNetwork *net, gpointe
|
|||||||
gtk_item = network_menu_item_get_check_item (item);
|
gtk_item = network_menu_item_get_check_item (item);
|
||||||
|
|
||||||
gtk_menu_shell_append (GTK_MENU_SHELL (cb_data->menu), GTK_WIDGET (gtk_item));
|
gtk_menu_shell_append (GTK_MENU_SHELL (cb_data->menu), GTK_WIDGET (gtk_item));
|
||||||
if (cb_data->applet->gui_active_device == dev && wireless_network_get_active (net))
|
if (network_device_get_active (dev) && wireless_network_get_active (net))
|
||||||
gtk_check_menu_item_set_active (gtk_item, TRUE);
|
gtk_check_menu_item_set_active (gtk_item, TRUE);
|
||||||
network_menu_item_update (item, net, cb_data->has_encrypted);
|
network_menu_item_update (item, net, cb_data->has_encrypted);
|
||||||
|
|
||||||
@@ -1285,7 +1307,6 @@ static void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet)
|
|||||||
|
|
||||||
if (dev)
|
if (dev)
|
||||||
{
|
{
|
||||||
gboolean current = (dev == applet->gui_active_device);
|
|
||||||
gint n_devices = 0;
|
gint n_devices = 0;
|
||||||
|
|
||||||
switch (network_device_get_type (dev))
|
switch (network_device_get_type (dev))
|
||||||
@@ -1304,7 +1325,7 @@ static void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet)
|
|||||||
|
|
||||||
if (n_devices >= 0)
|
if (n_devices >= 0)
|
||||||
{
|
{
|
||||||
nmwa_menu_add_device_item (menu, dev, current, n_devices, applet);
|
nmwa_menu_add_device_item (menu, dev, n_devices, applet);
|
||||||
nmwa_menu_device_add_networks (menu, dev, applet);
|
nmwa_menu_device_add_networks (menu, dev, applet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1795,14 +1816,11 @@ static GtkWidget * nmwa_get_instance (NMWirelessApplet *applet)
|
|||||||
applet->nm_running = FALSE;
|
applet->nm_running = FALSE;
|
||||||
applet->dev_pending_call_list = NULL;
|
applet->dev_pending_call_list = NULL;
|
||||||
applet->dbus_device_list = NULL;
|
applet->dbus_device_list = NULL;
|
||||||
applet->dbus_active_device = NULL;
|
|
||||||
applet->dbus_active_device_path = NULL;
|
|
||||||
applet->dbus_active_vpn_name = NULL;
|
applet->dbus_active_vpn_name = NULL;
|
||||||
applet->dbus_vpn_connections = NULL;
|
applet->dbus_vpn_connections = NULL;
|
||||||
applet->dbus_nm_state = NM_STATE_DISCONNECTED;
|
applet->dbus_nm_state = NM_STATE_DISCONNECTED;
|
||||||
applet->vpn_pending_call_list = NULL;
|
applet->vpn_pending_call_list = NULL;
|
||||||
applet->gui_device_list = NULL;
|
applet->gui_device_list = NULL;
|
||||||
applet->gui_active_device = NULL;
|
|
||||||
applet->gui_active_vpn = NULL;
|
applet->gui_active_vpn = NULL;
|
||||||
applet->gui_vpn_connections = NULL;
|
applet->gui_vpn_connections = NULL;
|
||||||
applet->gui_nm_state = NM_STATE_DISCONNECTED;
|
applet->gui_nm_state = NM_STATE_DISCONNECTED;
|
||||||
|
@@ -85,13 +85,10 @@ typedef struct
|
|||||||
gboolean nm_running;
|
gboolean nm_running;
|
||||||
|
|
||||||
GSList * gui_device_list;
|
GSList * gui_device_list;
|
||||||
NetworkDevice * gui_active_device;
|
|
||||||
NMState gui_nm_state;
|
NMState gui_nm_state;
|
||||||
|
|
||||||
GSList * dev_pending_call_list;
|
GSList * dev_pending_call_list;
|
||||||
GSList * dbus_device_list;
|
GSList * dbus_device_list;
|
||||||
NetworkDevice * dbus_active_device;
|
|
||||||
char * dbus_active_device_path;
|
|
||||||
NMState dbus_nm_state;
|
NMState dbus_nm_state;
|
||||||
|
|
||||||
GSList * gui_vpn_connections;
|
GSList * gui_vpn_connections;
|
||||||
@@ -151,6 +148,8 @@ gboolean nmwa_driver_notify (gpointer user_data);
|
|||||||
void nmwa_schedule_vpn_login_failure_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *error_msg);
|
void nmwa_schedule_vpn_login_failure_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *error_msg);
|
||||||
void nmwa_schedule_vpn_login_banner_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *banner);
|
void nmwa_schedule_vpn_login_banner_dialog (NMWirelessApplet *applet, const char *vpn_name, const char *banner);
|
||||||
|
|
||||||
|
NetworkDevice * nmwa_get_first_active_device (GSList *dev_list);
|
||||||
|
|
||||||
int nm_null_safe_strcmp (const char *s1, const char *s2);
|
int nm_null_safe_strcmp (const char *s1, const char *s2);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -37,6 +37,7 @@ struct NetworkDevice
|
|||||||
char * desc;
|
char * desc;
|
||||||
char * nm_path;
|
char * nm_path;
|
||||||
NMDeviceType type;
|
NMDeviceType type;
|
||||||
|
gboolean active;
|
||||||
gboolean link;
|
gboolean link;
|
||||||
NMDriverSupportLevel driver_support_level;
|
NMDriverSupportLevel driver_support_level;
|
||||||
char * addr;
|
char * addr;
|
||||||
@@ -95,6 +96,7 @@ NetworkDevice *network_device_copy (NetworkDevice *src)
|
|||||||
dev->iface = g_strdup (src->iface);
|
dev->iface = g_strdup (src->iface);
|
||||||
dev->desc = g_strdup (src->desc);
|
dev->desc = g_strdup (src->desc);
|
||||||
dev->udi = g_strdup (src->udi);
|
dev->udi = g_strdup (src->udi);
|
||||||
|
dev->active = src->active;
|
||||||
dev->strength = src->strength;
|
dev->strength = src->strength;
|
||||||
|
|
||||||
for (elt = src->networks; elt; elt = g_slist_next (elt))
|
for (elt = src->networks; elt; elt = g_slist_next (elt))
|
||||||
@@ -468,6 +470,23 @@ void network_device_set_link (NetworkDevice *dev, gboolean link)
|
|||||||
dev->link = link;
|
dev->link = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Accessors for active
|
||||||
|
*/
|
||||||
|
gboolean network_device_get_active (NetworkDevice *dev)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (dev != NULL, FALSE);
|
||||||
|
|
||||||
|
return (dev->active);
|
||||||
|
}
|
||||||
|
|
||||||
|
void network_device_set_active (NetworkDevice *dev, gboolean active)
|
||||||
|
{
|
||||||
|
g_return_if_fail (dev != NULL);
|
||||||
|
|
||||||
|
dev->active = active;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Accessors for desc
|
* Accessors for desc
|
||||||
*/
|
*/
|
||||||
|
@@ -73,6 +73,9 @@ void network_device_set_hal_udi (NetworkDevice *dev, const char *hal_udi)
|
|||||||
gboolean network_device_get_link (NetworkDevice *dev);
|
gboolean network_device_get_link (NetworkDevice *dev);
|
||||||
void network_device_set_link (NetworkDevice *dev, gboolean link);
|
void network_device_set_link (NetworkDevice *dev, gboolean link);
|
||||||
|
|
||||||
|
gboolean network_device_get_active (NetworkDevice *dev);
|
||||||
|
void network_device_set_active (NetworkDevice *dev, gboolean active);
|
||||||
|
|
||||||
const char * network_device_get_desc (NetworkDevice *dev);
|
const char * network_device_get_desc (NetworkDevice *dev);
|
||||||
void network_device_set_desc (NetworkDevice *dev, const char *desc);
|
void network_device_set_desc (NetworkDevice *dev, const char *desc);
|
||||||
|
|
||||||
|
@@ -282,30 +282,39 @@ void nmi_passphrase_dialog_cancel_clicked (GtkWidget *cancel_button, gpointer us
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct PPDialogCBData
|
||||||
|
{
|
||||||
|
NMWirelessApplet * applet;
|
||||||
|
NetworkDevice * dev;
|
||||||
|
WirelessNetwork * net;
|
||||||
|
DBusMessage * message;
|
||||||
|
} PPDialogCBData;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nmi_passphrase_dialog_show
|
* nmi_passphrase_dialog_show
|
||||||
*
|
*
|
||||||
* Pop up the user key dialog in response to a dbus message
|
* Pop up the user key dialog in response to a dbus message
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void nmi_passphrase_dialog_show (GtkWidget *dialog, NetworkDevice *dev, WirelessNetwork *net, DBusMessage *message)
|
static gboolean nmi_passphrase_dialog_show (PPDialogCBData *cb_data)
|
||||||
{
|
{
|
||||||
|
GtkWidget * dialog;
|
||||||
GladeXML * dialog_xml;
|
GladeXML * dialog_xml;
|
||||||
const char * orig_label_text;
|
const char * orig_label_text;
|
||||||
|
|
||||||
g_return_if_fail (dialog != NULL);
|
g_return_val_if_fail (cb_data != NULL, FALSE);
|
||||||
g_return_if_fail (dev != NULL);
|
g_return_val_if_fail (cb_data->applet != NULL, FALSE);
|
||||||
g_return_if_fail (net != NULL);
|
g_return_val_if_fail (cb_data->dev != NULL, FALSE);
|
||||||
g_return_if_fail ((dialog_xml = get_dialog_xml (dialog)) != NULL);
|
g_return_val_if_fail (cb_data->net != NULL, FALSE);
|
||||||
|
|
||||||
|
dialog = cb_data->applet->passphrase_dialog;
|
||||||
|
g_return_val_if_fail ((dialog_xml = get_dialog_xml (dialog)) != NULL, FALSE);
|
||||||
|
|
||||||
if (GTK_WIDGET_VISIBLE (dialog))
|
if (GTK_WIDGET_VISIBLE (dialog))
|
||||||
return;
|
return FALSE;
|
||||||
|
|
||||||
if (!(orig_label_text = g_object_get_data (G_OBJECT (dialog), "orig-label-text")))
|
if (!(orig_label_text = g_object_get_data (G_OBJECT (dialog), "orig-label-text")))
|
||||||
return;
|
return FALSE;
|
||||||
|
|
||||||
network_device_ref (dev);
|
|
||||||
wireless_network_ref (net);
|
|
||||||
|
|
||||||
nmi_passphrase_dialog_clear (dialog);
|
nmi_passphrase_dialog_clear (dialog);
|
||||||
|
|
||||||
@@ -313,17 +322,48 @@ void nmi_passphrase_dialog_show (GtkWidget *dialog, NetworkDevice *dev, Wireless
|
|||||||
if (orig_label_text)
|
if (orig_label_text)
|
||||||
{
|
{
|
||||||
GtkWidget * label = glade_xml_get_widget (dialog_xml, "label1");
|
GtkWidget * label = glade_xml_get_widget (dialog_xml, "label1");
|
||||||
char * new_label_text = g_strdup_printf (orig_label_text, wireless_network_get_essid (net));
|
char * new_label_text = g_strdup_printf (orig_label_text, wireless_network_get_essid (cb_data->net));
|
||||||
|
|
||||||
gtk_label_set_label (GTK_LABEL (label), new_label_text);
|
gtk_label_set_label (GTK_LABEL (label), new_label_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_set_data (G_OBJECT (dialog), "device", dev);
|
g_object_set_data (G_OBJECT (dialog), "device", cb_data->dev);
|
||||||
g_object_set_data (G_OBJECT (dialog), "network", net);
|
g_object_set_data (G_OBJECT (dialog), "network", cb_data->net);
|
||||||
dbus_message_ref (message);
|
g_object_set_data (G_OBJECT (dialog), "dbus-message", cb_data->message);
|
||||||
g_object_set_data (G_OBJECT (dialog), "dbus-message", message);
|
|
||||||
|
|
||||||
gtk_widget_show (dialog);
|
gtk_widget_show (dialog);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nmi_passphrase_dialog_schedule_show
|
||||||
|
*
|
||||||
|
* Schedule the passphrase dialog to show
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gboolean nmi_passphrase_dialog_schedule_show (NetworkDevice *dev, WirelessNetwork *net, DBusMessage *message, NMWirelessApplet *applet)
|
||||||
|
{
|
||||||
|
PPDialogCBData * cb_data;
|
||||||
|
|
||||||
|
g_return_val_if_fail (dev != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (net != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (message != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (applet != NULL, FALSE);
|
||||||
|
|
||||||
|
cb_data = g_malloc0 (sizeof (PPDialogCBData));
|
||||||
|
network_device_ref (dev);
|
||||||
|
cb_data->dev = dev;
|
||||||
|
wireless_network_ref (net);
|
||||||
|
cb_data->net = net;
|
||||||
|
cb_data->applet = applet;
|
||||||
|
dbus_message_ref (message);
|
||||||
|
cb_data->message = message;
|
||||||
|
|
||||||
|
g_idle_add ((GSourceFunc) nmi_passphrase_dialog_show, cb_data);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -333,12 +373,31 @@ void nmi_passphrase_dialog_show (GtkWidget *dialog, NetworkDevice *dev, Wireless
|
|||||||
* Cancel and hide any user key dialog that might be up
|
* Cancel and hide any user key dialog that might be up
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void nmi_passphrase_dialog_cancel (GtkWidget *dialog)
|
static gboolean nmi_passphrase_dialog_cancel (NMWirelessApplet *applet)
|
||||||
{
|
{
|
||||||
g_return_if_fail (dialog != NULL);
|
GtkWidget *dialog;
|
||||||
|
|
||||||
|
g_return_val_if_fail (applet != NULL, FALSE);
|
||||||
|
dialog = applet->passphrase_dialog;
|
||||||
|
|
||||||
if (GTK_WIDGET_VISIBLE (dialog))
|
if (GTK_WIDGET_VISIBLE (dialog))
|
||||||
nmi_passphrase_dialog_clear (dialog);
|
nmi_passphrase_dialog_clear (dialog);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nmi_passphrase_dialog_schedule_cancel
|
||||||
|
*
|
||||||
|
* Schedule the passphrase dialog cancellation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void nmi_passphrase_dialog_schedule_cancel (NMWirelessApplet *applet)
|
||||||
|
{
|
||||||
|
g_return_if_fail (applet != NULL);
|
||||||
|
|
||||||
|
g_idle_add ((GSourceFunc) nmi_passphrase_dialog_cancel, applet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -30,8 +30,8 @@ GtkWidget * nmi_passphrase_dialog_init (NMWirelessApplet *applet);
|
|||||||
|
|
||||||
void nmi_passphrase_dialog_destroy (GtkWidget *dialog);
|
void nmi_passphrase_dialog_destroy (GtkWidget *dialog);
|
||||||
|
|
||||||
void nmi_passphrase_dialog_show (GtkWidget *dialog, NetworkDevice *dev, WirelessNetwork *net, DBusMessage *message);
|
gboolean nmi_passphrase_dialog_schedule_show (NetworkDevice *dev, WirelessNetwork *net, DBusMessage *message, NMWirelessApplet *applet);
|
||||||
|
|
||||||
void nmi_passphrase_dialog_cancel (GtkWidget *dialog);
|
void nmi_passphrase_dialog_schedule_cancel (NMWirelessApplet *applet);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
SUBDIRS=named-manager vpn-manager backends
|
SUBDIRS=named-manager vpn-manager dhcp-manager backends
|
||||||
|
|
||||||
INCLUDES = -I${top_srcdir} -I${top_srcdir}/src/named-manager -I${top_srcdir}/src/vpn-manager -I${top_srcdir}/utils
|
INCLUDES = -I${top_srcdir} -I${top_srcdir}/src/named-manager -I${top_srcdir}/src/vpn-manager -I${top_srcdir}/src/dhcp-manager -I${top_srcdir}/utils
|
||||||
|
|
||||||
bin_PROGRAMS = NetworkManager
|
bin_PROGRAMS = NetworkManager
|
||||||
|
|
||||||
@@ -19,12 +19,8 @@ NetworkManager_SOURCES = \
|
|||||||
nm-dbus-device.h \
|
nm-dbus-device.h \
|
||||||
nm-dbus-net.c \
|
nm-dbus-net.c \
|
||||||
nm-dbus-net.h \
|
nm-dbus-net.h \
|
||||||
nm-dbus-dhcp.c \
|
|
||||||
nm-dbus-dhcp.h \
|
|
||||||
nm-dbus-nmi.c \
|
nm-dbus-nmi.c \
|
||||||
nm-dbus-nmi.h \
|
nm-dbus-nmi.h \
|
||||||
NetworkManagerDHCP.c \
|
|
||||||
NetworkManagerDHCP.h \
|
|
||||||
NetworkManagerDevice.c \
|
NetworkManagerDevice.c \
|
||||||
NetworkManagerDevice.h \
|
NetworkManagerDevice.h \
|
||||||
NetworkManagerDevicePrivate.h \
|
NetworkManagerDevicePrivate.h \
|
||||||
@@ -42,7 +38,10 @@ NetworkManager_SOURCES = \
|
|||||||
NetworkManagerSystem.h \
|
NetworkManagerSystem.h \
|
||||||
nm-netlink-monitor.c \
|
nm-netlink-monitor.c \
|
||||||
nm-netlink-monitor.h \
|
nm-netlink-monitor.h \
|
||||||
autoip.c
|
nm-activation-request.c \
|
||||||
|
nm-activation-request.h \
|
||||||
|
autoip.c \
|
||||||
|
autoip.h
|
||||||
|
|
||||||
NetworkManager_CPPFLAGS = \
|
NetworkManager_CPPFLAGS = \
|
||||||
$(DBUS_CFLAGS) \
|
$(DBUS_CFLAGS) \
|
||||||
@@ -70,9 +69,9 @@ NetworkManager_LDADD = \
|
|||||||
$(HAL_LIBS) \
|
$(HAL_LIBS) \
|
||||||
$(IWLIB) \
|
$(IWLIB) \
|
||||||
$(top_builddir)/utils/libnmutils.la \
|
$(top_builddir)/utils/libnmutils.la \
|
||||||
../dhcpcd/libdhcpc.a \
|
|
||||||
./named-manager/libnamed-manager.la \
|
./named-manager/libnamed-manager.la \
|
||||||
./vpn-manager/libvpn-manager.la \
|
./vpn-manager/libvpn-manager.la \
|
||||||
|
./dhcp-manager/libdhcp-manager.la \
|
||||||
./backends/libnmbackend.la
|
./backends/libnmbackend.la
|
||||||
|
|
||||||
if WITH_GCRYPT
|
if WITH_GCRYPT
|
||||||
|
@@ -46,6 +46,7 @@
|
|||||||
#include "nm-named-manager.h"
|
#include "nm-named-manager.h"
|
||||||
#include "nm-dbus-vpn.h"
|
#include "nm-dbus-vpn.h"
|
||||||
#include "nm-netlink-monitor.h"
|
#include "nm-netlink-monitor.h"
|
||||||
|
#include "nm-dhcp-manager.h"
|
||||||
|
|
||||||
#define NM_WIRELESS_LINK_STATE_POLL_INTERVAL (5 * 1000)
|
#define NM_WIRELESS_LINK_STATE_POLL_INTERVAL (5 * 1000)
|
||||||
|
|
||||||
@@ -132,11 +133,9 @@ NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi, cons
|
|||||||
data->dev_list = g_slist_append (data->dev_list, dev);
|
data->dev_list = g_slist_append (data->dev_list, dev);
|
||||||
nm_device_deactivate (dev, TRUE);
|
nm_device_deactivate (dev, TRUE);
|
||||||
|
|
||||||
nm_device_update_link_state (dev);
|
|
||||||
|
|
||||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||||
|
|
||||||
nm_policy_schedule_state_update (data);
|
nm_policy_schedule_device_change_check (data);
|
||||||
nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_ADDED);
|
nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_ADDED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -176,22 +175,17 @@ void nm_remove_device_from_list (NMData *data, const char *udi)
|
|||||||
|
|
||||||
if (dev && (nm_null_safe_strcmp (nm_device_get_udi (dev), udi) == 0))
|
if (dev && (nm_null_safe_strcmp (nm_device_get_udi (dev), udi) == 0))
|
||||||
{
|
{
|
||||||
if (data->active_device && (dev == data->active_device))
|
|
||||||
{
|
|
||||||
data->active_device = NULL;
|
|
||||||
data->active_device_locked = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
nm_device_set_removed (dev, TRUE);
|
nm_device_set_removed (dev, TRUE);
|
||||||
nm_device_deactivate (dev, FALSE);
|
nm_device_deactivate (dev, FALSE);
|
||||||
nm_device_worker_thread_stop (dev);
|
nm_device_worker_thread_stop (dev);
|
||||||
nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_REMOVED);
|
nm_dbus_signal_device_status_change (data->dbus_connection, dev, DEVICE_REMOVED);
|
||||||
|
|
||||||
nm_device_unref (dev);
|
nm_device_unref (dev);
|
||||||
|
|
||||||
/* Remove the device entry from the device list and free its data */
|
/* Remove the device entry from the device list and free its data */
|
||||||
data->dev_list = g_slist_remove_link (data->dev_list, elt);
|
data->dev_list = g_slist_remove_link (data->dev_list, elt);
|
||||||
g_slist_free (elt);
|
g_slist_free (elt);
|
||||||
nm_policy_schedule_state_update (data);
|
nm_policy_schedule_device_change_check (data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,6 +193,33 @@ void nm_remove_device_from_list (NMData *data, const char *udi)
|
|||||||
} else nm_warning ("could not acquire device list mutex." );
|
} else nm_warning ("could not acquire device list mutex." );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_get_active_device
|
||||||
|
*
|
||||||
|
* Return the currently active device.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
NMDevice *nm_get_active_device (NMData *data)
|
||||||
|
{
|
||||||
|
NMDevice * dev = NULL;
|
||||||
|
GSList * elt;
|
||||||
|
|
||||||
|
g_return_val_if_fail (data != NULL, NULL);
|
||||||
|
|
||||||
|
nm_lock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||||
|
for (elt = data->dev_list; elt; elt = g_slist_next (elt))
|
||||||
|
{
|
||||||
|
if ((dev = (NMDevice *)(elt->data)) && nm_device_get_act_request (dev))
|
||||||
|
break;
|
||||||
|
dev = NULL;
|
||||||
|
}
|
||||||
|
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||||
|
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Hal doesn't really give us any way to pass a GMainContext to our
|
/* Hal doesn't really give us any way to pass a GMainContext to our
|
||||||
* mainloop integration function unfortunately. So we have to use
|
* mainloop integration function unfortunately. So we have to use
|
||||||
* a global.
|
* a global.
|
||||||
@@ -280,15 +301,6 @@ static void nm_hal_device_new_capability (LibHalContext *ctx, const char *udi, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_hal_device_lost_capability
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static void nm_hal_device_lost_capability (LibHalContext *ctx, const char *udi, const char *capability)
|
|
||||||
{
|
|
||||||
/* nm_debug ("nm_hal_device_lost_capability() called with udi = %s, capability = %s", udi, capability );*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_add_initial_devices
|
* nm_add_initial_devices
|
||||||
*
|
*
|
||||||
@@ -300,7 +312,6 @@ static void nm_add_initial_devices (NMData *data)
|
|||||||
char ** net_devices;
|
char ** net_devices;
|
||||||
int num_net_devices;
|
int num_net_devices;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
DBusError error;
|
DBusError error;
|
||||||
|
|
||||||
g_return_if_fail (data != NULL);
|
g_return_if_fail (data != NULL);
|
||||||
@@ -310,8 +321,7 @@ static void nm_add_initial_devices (NMData *data)
|
|||||||
net_devices = libhal_find_device_by_capability (data->hal_ctx, "net", &num_net_devices, &error);
|
net_devices = libhal_find_device_by_capability (data->hal_ctx, "net", &num_net_devices, &error);
|
||||||
if (dbus_error_is_set (&error))
|
if (dbus_error_is_set (&error))
|
||||||
{
|
{
|
||||||
nm_warning ("could not find existing networking devices: %s",
|
nm_warning ("could not find existing networking devices: %s", error.message);
|
||||||
error.message);
|
|
||||||
dbus_error_free (&error);
|
dbus_error_free (&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,71 +376,6 @@ void nm_schedule_state_change_signal_broadcast (NMData *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_poll_and_update_wireless_link_state
|
|
||||||
*
|
|
||||||
* Called every 2s to poll wireless cards and determine if they have a link
|
|
||||||
* or not.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
gboolean nm_poll_and_update_wireless_link_state (NMData *data)
|
|
||||||
{
|
|
||||||
GSList *elt;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data != NULL, TRUE);
|
|
||||||
|
|
||||||
if ((data->wireless_enabled == FALSE) || (data->asleep == TRUE))
|
|
||||||
return (TRUE);
|
|
||||||
|
|
||||||
/* Attempt to acquire mutex for device list iteration.
|
|
||||||
* If the acquire fails, just ignore the device deletion entirely.
|
|
||||||
*/
|
|
||||||
if (!nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
|
||||||
{
|
|
||||||
nm_warning ("could not acquire device list mutex." );
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (elt = data->dev_list; elt; elt = g_slist_next (elt))
|
|
||||||
{
|
|
||||||
NMDevice *dev = (NMDevice *)(elt->data);
|
|
||||||
|
|
||||||
if (dev && nm_device_is_wireless (dev))
|
|
||||||
{
|
|
||||||
if (!nm_device_is_up (dev))
|
|
||||||
nm_device_bring_up (dev);
|
|
||||||
|
|
||||||
nm_device_update_link_state (dev);
|
|
||||||
|
|
||||||
/* Is this the currently selected device?
|
|
||||||
* If so, let's make sure it's still has
|
|
||||||
* an active link. If it lost the link,
|
|
||||||
* find a better access point.
|
|
||||||
*/
|
|
||||||
if ( (dev == data->active_device)
|
|
||||||
&& !nm_device_has_active_link (dev))
|
|
||||||
{
|
|
||||||
if ( nm_device_get_supports_wireless_scan (dev)
|
|
||||||
&& !data->forcing_device
|
|
||||||
&& data->state_modified_idle_id == 0)
|
|
||||||
{
|
|
||||||
nm_device_update_best_ap (dev);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( !nm_device_is_activating (dev)
|
|
||||||
&& !data->forcing_device
|
|
||||||
&& data->state_modified_idle_id == 0)
|
|
||||||
nm_device_update_best_ap (dev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
|
||||||
|
|
||||||
return (TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_data_new
|
* nm_data_new
|
||||||
*
|
*
|
||||||
@@ -468,7 +413,7 @@ static NMData *nm_data_new (gboolean enable_test_devices)
|
|||||||
sigaction (SIGINT, &action, NULL);
|
sigaction (SIGINT, &action, NULL);
|
||||||
sigaction (SIGTERM, &action, NULL);
|
sigaction (SIGTERM, &action, NULL);
|
||||||
|
|
||||||
data->named = nm_named_manager_new (data->main_context);
|
data->named_manager = nm_named_manager_new (data->main_context);
|
||||||
|
|
||||||
/* Initialize the device list mutex to protect additions/deletions to it. */
|
/* Initialize the device list mutex to protect additions/deletions to it. */
|
||||||
data->dev_list_mutex = g_mutex_new ();
|
data->dev_list_mutex = g_mutex_new ();
|
||||||
@@ -490,19 +435,27 @@ static NMData *nm_data_new (gboolean enable_test_devices)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
data->state_modified_idle_id = 0;
|
|
||||||
|
|
||||||
data->enable_test_devices = enable_test_devices;
|
data->enable_test_devices = enable_test_devices;
|
||||||
|
|
||||||
data->scanning_enabled = TRUE;
|
data->scanning_enabled = TRUE;
|
||||||
data->wireless_enabled = TRUE;
|
data->wireless_enabled = TRUE;
|
||||||
|
|
||||||
nm_policy_schedule_state_update (data);
|
nm_policy_schedule_device_change_check (data);
|
||||||
|
|
||||||
return (data);
|
return (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void device_stop_and_free (NMDevice *dev, gpointer user_data)
|
||||||
|
{
|
||||||
|
g_return_if_fail (dev != NULL);
|
||||||
|
|
||||||
|
nm_device_set_removed (dev, TRUE);
|
||||||
|
nm_device_deactivate (dev, FALSE);
|
||||||
|
nm_device_unref (dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_data_free
|
* nm_data_free
|
||||||
*
|
*
|
||||||
@@ -514,12 +467,14 @@ static void nm_data_free (NMData *data)
|
|||||||
g_return_if_fail (data != NULL);
|
g_return_if_fail (data != NULL);
|
||||||
|
|
||||||
nm_vpn_manager_dispose (data->vpn_manager);
|
nm_vpn_manager_dispose (data->vpn_manager);
|
||||||
g_object_unref (data->named);
|
nm_dhcp_manager_dispose (data->dhcp_manager);
|
||||||
|
g_object_unref (data->named_manager);
|
||||||
|
|
||||||
nm_device_unref (data->active_device);
|
/* Stop and destroy all devices */
|
||||||
|
nm_lock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||||
g_slist_foreach (data->dev_list, (GFunc) nm_device_unref, NULL);
|
g_slist_foreach (data->dev_list, (GFunc) device_stop_and_free, NULL);
|
||||||
g_slist_free (data->dev_list);
|
g_slist_free (data->dev_list);
|
||||||
|
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||||
|
|
||||||
g_mutex_free (data->dev_list_mutex);
|
g_mutex_free (data->dev_list_mutex);
|
||||||
|
|
||||||
@@ -549,10 +504,9 @@ static void sigterm_handler (int signum)
|
|||||||
static gboolean sigterm_pipe_handler (GIOChannel *src, GIOCondition condition, gpointer user_data)
|
static gboolean sigterm_pipe_handler (GIOChannel *src, GIOCondition condition, gpointer user_data)
|
||||||
{
|
{
|
||||||
NMData * data = user_data;
|
NMData * data = user_data;
|
||||||
|
NMDevice * act_dev = NULL;
|
||||||
|
|
||||||
nm_info ("Caught terminiation signal");
|
nm_info ("Caught terminiation signal");
|
||||||
if (data->active_device)
|
|
||||||
nm_device_deactivate (data->active_device, FALSE);
|
|
||||||
g_main_loop_quit (data->main_loop);
|
g_main_loop_quit (data->main_loop);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -579,6 +533,46 @@ static void nm_print_usage (void)
|
|||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_poll_and_update_wireless_link_state
|
||||||
|
*
|
||||||
|
* Called every 2s to poll wireless cards and determine if they have a link
|
||||||
|
* or not.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gboolean nm_poll_and_update_wireless_link_state (NMData *data)
|
||||||
|
{
|
||||||
|
GSList *elt;
|
||||||
|
|
||||||
|
g_return_val_if_fail (data != NULL, TRUE);
|
||||||
|
|
||||||
|
if ((data->wireless_enabled == FALSE) || (data->asleep == TRUE))
|
||||||
|
return (TRUE);
|
||||||
|
|
||||||
|
/* Attempt to acquire mutex for device list iteration.
|
||||||
|
* If the acquire fails, just ignore the device deletion entirely.
|
||||||
|
*/
|
||||||
|
if (!nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
||||||
|
{
|
||||||
|
nm_warning ("could not acquire device list mutex." );
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (elt = data->dev_list; elt; elt = g_slist_next (elt))
|
||||||
|
{
|
||||||
|
NMDevice *dev = (NMDevice *)(elt->data);
|
||||||
|
|
||||||
|
if (dev && nm_device_is_wireless (dev) && !nm_device_is_activating (dev))
|
||||||
|
{
|
||||||
|
nm_device_set_link_active (dev, nm_device_probe_link_state (dev));
|
||||||
|
nm_device_update_signal_strength (dev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||||
|
|
||||||
|
return (TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nm_monitor_wireless_link_state (NMData *data)
|
nm_monitor_wireless_link_state (NMData *data)
|
||||||
{
|
{
|
||||||
@@ -586,7 +580,7 @@ nm_monitor_wireless_link_state (NMData *data)
|
|||||||
link_source = g_timeout_source_new (NM_WIRELESS_LINK_STATE_POLL_INTERVAL);
|
link_source = g_timeout_source_new (NM_WIRELESS_LINK_STATE_POLL_INTERVAL);
|
||||||
g_source_set_callback (link_source,
|
g_source_set_callback (link_source,
|
||||||
(GSourceFunc) nm_poll_and_update_wireless_link_state,
|
(GSourceFunc) nm_poll_and_update_wireless_link_state,
|
||||||
nm_data, NULL);
|
data, NULL);
|
||||||
g_source_attach (link_source, nm_data->main_context);
|
g_source_attach (link_source, nm_data->main_context);
|
||||||
g_source_unref (link_source);
|
g_source_unref (link_source);
|
||||||
}
|
}
|
||||||
@@ -601,23 +595,14 @@ nm_wired_link_activated (NmNetlinkMonitor *monitor,
|
|||||||
NMDevice *dev = nm_get_device_by_iface (data, interface_name);
|
NMDevice *dev = nm_get_device_by_iface (data, interface_name);
|
||||||
|
|
||||||
/* Don't do anything if we already have a link */
|
/* Don't do anything if we already have a link */
|
||||||
if ( (dev != NULL)
|
if ( dev
|
||||||
&& nm_device_is_wired (dev)
|
&& nm_device_is_wired (dev)
|
||||||
&& !nm_device_has_active_link (dev))
|
&& !nm_device_has_active_link (dev))
|
||||||
{
|
{
|
||||||
nm_device_set_link_active (dev, TRUE);
|
NMDevice *act_dev = NULL;
|
||||||
|
|
||||||
/* If a network cable just got plugged in, force-switch from a wireless
|
nm_device_set_link_active (dev, TRUE);
|
||||||
* to a wired connection.
|
nm_policy_schedule_device_change_check (data);
|
||||||
*/
|
|
||||||
if (nm_device_has_active_link (dev)
|
|
||||||
&& data->active_device
|
|
||||||
&& data->active_device_locked
|
|
||||||
&& nm_device_is_wireless (data->active_device))
|
|
||||||
{
|
|
||||||
data->active_device_locked = FALSE;
|
|
||||||
nm_policy_schedule_state_update (data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||||
}
|
}
|
||||||
@@ -849,7 +834,9 @@ int main( int argc, char *argv[] )
|
|||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Need to happen after DBUS is initialized */
|
||||||
nm_data->vpn_manager = nm_vpn_manager_new (nm_data);
|
nm_data->vpn_manager = nm_vpn_manager_new (nm_data);
|
||||||
|
nm_data->dhcp_manager = nm_dhcp_manager_new (nm_data);
|
||||||
|
|
||||||
/* If NMI is running, grab allowed wireless network lists from it ASAP */
|
/* If NMI is running, grab allowed wireless network lists from it ASAP */
|
||||||
if (nm_dbus_is_info_daemon_running (nm_data->dbus_connection))
|
if (nm_dbus_is_info_daemon_running (nm_data->dbus_connection))
|
||||||
@@ -873,11 +860,10 @@ int main( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
|
|
||||||
nm_hal_mainloop_integration (ctx, nm_data->dbus_connection);
|
nm_hal_mainloop_integration (ctx, nm_data->dbus_connection);
|
||||||
|
|
||||||
libhal_ctx_set_dbus_connection (ctx, nm_data->dbus_connection);
|
libhal_ctx_set_dbus_connection (ctx, nm_data->dbus_connection);
|
||||||
|
|
||||||
dbus_error_init (&dbus_error);
|
dbus_error_init (&dbus_error);
|
||||||
if(!libhal_ctx_init (ctx, &dbus_error)) {
|
if(!libhal_ctx_init (ctx, &dbus_error))
|
||||||
|
{
|
||||||
nm_error ("libhal_ctx_init() failed: %s\n"
|
nm_error ("libhal_ctx_init() failed: %s\n"
|
||||||
"Make sure the hal daemon is running?",
|
"Make sure the hal daemon is running?",
|
||||||
dbus_error.message);
|
dbus_error.message);
|
||||||
@@ -888,22 +874,13 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
nm_data->hal_ctx = ctx;
|
nm_data->hal_ctx = ctx;
|
||||||
libhal_ctx_set_user_data (nm_data->hal_ctx, nm_data);
|
libhal_ctx_set_user_data (nm_data->hal_ctx, nm_data);
|
||||||
|
libhal_ctx_set_device_added (ctx, nm_hal_device_added);
|
||||||
libhal_ctx_set_device_added (ctx,
|
libhal_ctx_set_device_removed (ctx, nm_hal_device_removed);
|
||||||
nm_hal_device_added);
|
libhal_ctx_set_device_new_capability (ctx, nm_hal_device_new_capability);
|
||||||
libhal_ctx_set_device_removed (ctx,
|
|
||||||
nm_hal_device_removed);
|
|
||||||
libhal_ctx_set_device_new_capability (ctx,
|
|
||||||
nm_hal_device_new_capability);
|
|
||||||
libhal_ctx_set_device_lost_capability (ctx,
|
|
||||||
nm_hal_device_lost_capability);
|
|
||||||
|
|
||||||
libhal_device_property_watch_all (nm_data->hal_ctx, &dbus_error);
|
libhal_device_property_watch_all (nm_data->hal_ctx, &dbus_error);
|
||||||
|
|
||||||
if (dbus_error_is_set (&dbus_error))
|
if (dbus_error_is_set (&dbus_error))
|
||||||
{
|
{
|
||||||
nm_error ("libhal_device_property_watch_all(): %s",
|
nm_error ("libhal_device_property_watch_all(): %s", dbus_error.message);
|
||||||
dbus_error.message);
|
|
||||||
dbus_error_free (&dbus_error);
|
dbus_error_free (&dbus_error);
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@@ -915,7 +892,7 @@ int main( int argc, char *argv[] )
|
|||||||
/* We run dhclient when we need to, and we don't want any stray ones
|
/* We run dhclient when we need to, and we don't want any stray ones
|
||||||
* lying around upon launch.
|
* lying around upon launch.
|
||||||
*/
|
*/
|
||||||
nm_system_kill_all_dhcp_daemons ();
|
// nm_system_kill_all_dhcp_daemons ();
|
||||||
|
|
||||||
/* Bring up the loopback interface. */
|
/* Bring up the loopback interface. */
|
||||||
nm_system_enable_loopback ();
|
nm_system_enable_loopback ();
|
||||||
@@ -924,7 +901,7 @@ int main( int argc, char *argv[] )
|
|||||||
nm_monitor_wireless_link_state (nm_data);
|
nm_monitor_wireless_link_state (nm_data);
|
||||||
nm_monitor_wired_link_state (nm_data);
|
nm_monitor_wired_link_state (nm_data);
|
||||||
|
|
||||||
if (!nm_named_manager_start (nm_data->named, &error))
|
if (!nm_named_manager_start (nm_data->named_manager, &error))
|
||||||
{
|
{
|
||||||
nm_error ("couldn't initialize nameserver: %s",
|
nm_error ("couldn't initialize nameserver: %s",
|
||||||
error->message);
|
error->message);
|
||||||
@@ -940,9 +917,9 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
libhal_ctx_shutdown (nm_data->hal_ctx, &dbus_error);
|
libhal_ctx_shutdown (nm_data->hal_ctx, &dbus_error);
|
||||||
if (dbus_error_is_set (&dbus_error)) {
|
if (dbus_error_is_set (&dbus_error))
|
||||||
nm_warning ("libhal shutdown failed - %s",
|
{
|
||||||
dbus_error.message);
|
nm_warning ("libhal shutdown failed - %s", dbus_error.message);
|
||||||
dbus_error_free (&dbus_error);
|
dbus_error_free (&dbus_error);
|
||||||
}
|
}
|
||||||
libhal_ctx_free (nm_data->hal_ctx);
|
libhal_ctx_free (nm_data->hal_ctx);
|
||||||
|
@@ -179,6 +179,7 @@ void nm_ap_set_timestamp (NMAccessPoint *ap, const GTimeVal *timestamp)
|
|||||||
*/
|
*/
|
||||||
char * nm_ap_get_essid (const NMAccessPoint *ap)
|
char * nm_ap_get_essid (const NMAccessPoint *ap)
|
||||||
{
|
{
|
||||||
|
g_assert (ap);
|
||||||
g_return_val_if_fail (ap != NULL, NULL);
|
g_return_val_if_fail (ap != NULL, NULL);
|
||||||
|
|
||||||
return (ap->essid);
|
return (ap->essid);
|
||||||
@@ -311,7 +312,7 @@ void nm_ap_set_auth_method (NMAccessPoint *ap, NMDeviceAuthMethod auth_method)
|
|||||||
* Get/set functions for address
|
* Get/set functions for address
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
struct ether_addr * nm_ap_get_address (const NMAccessPoint *ap)
|
const struct ether_addr * nm_ap_get_address (const NMAccessPoint *ap)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (ap != NULL, NULL);
|
g_return_val_if_fail (ap != NULL, NULL);
|
||||||
|
|
||||||
|
@@ -51,7 +51,7 @@ void nm_ap_set_auth_method (NMAccessPoint *ap, const NMDeviceAuthMethod auth_
|
|||||||
gboolean nm_ap_get_encrypted (const NMAccessPoint *ap);
|
gboolean nm_ap_get_encrypted (const NMAccessPoint *ap);
|
||||||
void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean encrypted);
|
void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean encrypted);
|
||||||
|
|
||||||
struct ether_addr * nm_ap_get_address (const NMAccessPoint *ap);
|
const struct ether_addr * nm_ap_get_address (const NMAccessPoint *ap);
|
||||||
void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr *addr);
|
void nm_ap_set_address (NMAccessPoint *ap, const struct ether_addr *addr);
|
||||||
|
|
||||||
NMNetworkMode nm_ap_get_mode (const NMAccessPoint *ap);
|
NMNetworkMode nm_ap_get_mode (const NMAccessPoint *ap);
|
||||||
|
@@ -498,7 +498,6 @@ gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *me
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Add the merge AP to the list. */
|
/* Add the merge AP to the list. */
|
||||||
|
|
||||||
nm_ap_list_append_ap (list, merge_ap);
|
nm_ap_list_append_ap (list, merge_ap);
|
||||||
*new = TRUE;
|
*new = TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -1,338 +0,0 @@
|
|||||||
/* NetworkManager -- Network link manager
|
|
||||||
*
|
|
||||||
* Dan Williams <dcbw@redhat.com>
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* (C) Copyright 2004 Red Hat, Inc.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <glib.h>
|
|
||||||
#include <syslog.h>
|
|
||||||
#include "NetworkManager.h"
|
|
||||||
#include "NetworkManagerMain.h"
|
|
||||||
#include "NetworkManagerDevice.h"
|
|
||||||
#include "NetworkManagerDevicePrivate.h"
|
|
||||||
#include "NetworkManagerDHCP.h"
|
|
||||||
#include "NetworkManagerSystem.h"
|
|
||||||
#include "NetworkManagerPolicy.h"
|
|
||||||
#include "nm-named-manager.h"
|
|
||||||
#include "../dhcpcd/client.h"
|
|
||||||
#include "nm-utils.h"
|
|
||||||
|
|
||||||
extern gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_device_new_ip4_autoip_config
|
|
||||||
*
|
|
||||||
* Build up an IP config with a Link Local address
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
NMIP4Config *nm_device_new_ip4_autoip_config (NMDevice *dev)
|
|
||||||
{
|
|
||||||
struct in_addr ip;
|
|
||||||
NMIP4Config * config = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (dev != NULL, NULL);
|
|
||||||
|
|
||||||
if (get_autoip (dev, &ip))
|
|
||||||
{
|
|
||||||
#define LINKLOCAL_BCAST 0xa9feffff
|
|
||||||
int temp = ip.s_addr;
|
|
||||||
|
|
||||||
config = nm_ip4_config_new ();
|
|
||||||
|
|
||||||
nm_ip4_config_set_address (config, (guint32)(ip.s_addr));
|
|
||||||
nm_ip4_config_set_netmask (config, (guint32)(ntohl (0xFFFF0000)));
|
|
||||||
nm_ip4_config_set_broadcast (config, (guint32)(ntohl (LINKLOCAL_BCAST)));
|
|
||||||
nm_ip4_config_set_gateway (config, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_device_dhcp_request
|
|
||||||
*
|
|
||||||
* Start a DHCP transaction on particular device.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static int nm_device_dhcp_request (NMDevice *dev)
|
|
||||||
{
|
|
||||||
dhcp_client_options opts;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
g_return_val_if_fail (dev != NULL, RET_DHCP_ERROR);
|
|
||||||
|
|
||||||
if (dev->dhcp_iface)
|
|
||||||
{
|
|
||||||
nm_warning ("nm_device_dhcp_request(): device DHCP info exists, but it should have been cleared already.\n");
|
|
||||||
dhcp_interface_free (dev->dhcp_iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset (&opts, 0, sizeof (dhcp_client_options));
|
|
||||||
gethostname (&(opts.host_name[0]), DHCP_HOSTNAME_MAX_LEN);
|
|
||||||
opts.base_timeout = 30;
|
|
||||||
if (!(dev->dhcp_iface = dhcp_interface_init (nm_device_get_iface (dev), &opts)))
|
|
||||||
return RET_DHCP_ERROR;
|
|
||||||
|
|
||||||
/* Start off in DHCP INIT state, get a completely new IP address
|
|
||||||
* and settings.
|
|
||||||
*/
|
|
||||||
if ((err = dhcp_init (dev->dhcp_iface)) == RET_DHCP_BOUND)
|
|
||||||
nm_device_dhcp_setup_timeouts (dev);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dhcp_interface_free (dev->dhcp_iface);
|
|
||||||
dev->dhcp_iface = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_device_new_ip4_dhcp_config
|
|
||||||
*
|
|
||||||
* Get IPv4 configuration info via DHCP, running the DHCP
|
|
||||||
* transaction if necessary.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
NMIP4Config *nm_device_new_ip4_dhcp_config (NMDevice *dev)
|
|
||||||
{
|
|
||||||
NMIP4Config * config = NULL;
|
|
||||||
int err;
|
|
||||||
dhcp_interface *dhcp_info = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (dev != NULL, NULL);
|
|
||||||
|
|
||||||
err = nm_device_dhcp_request (dev);
|
|
||||||
dhcp_info = dev->dhcp_iface;
|
|
||||||
if ((err == RET_DHCP_BOUND) && dev->dhcp_iface)
|
|
||||||
{
|
|
||||||
guint32 temp;
|
|
||||||
|
|
||||||
config = nm_ip4_config_new ();
|
|
||||||
|
|
||||||
nm_ip4_config_set_address (config, dhcp_info->ciaddr);
|
|
||||||
|
|
||||||
if (dhcp_interface_option_present (dhcp_info, subnetMask))
|
|
||||||
{
|
|
||||||
memcpy (&temp, dhcp_interface_option_payload (dhcp_info, subnetMask), dhcp_option_element_len (subnetMask));
|
|
||||||
nm_ip4_config_set_netmask (config, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dhcp_interface_option_present (dhcp_info, broadcastAddr))
|
|
||||||
{
|
|
||||||
memcpy (&temp, dhcp_interface_option_payload (dhcp_info, broadcastAddr), dhcp_option_element_len (broadcastAddr));
|
|
||||||
nm_ip4_config_set_broadcast (config, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Default route */
|
|
||||||
if (dhcp_interface_option_present (dhcp_info, routersOnSubnet))
|
|
||||||
{
|
|
||||||
memcpy (&temp, dhcp_interface_option_payload (dhcp_info, routersOnSubnet), dhcp_option_element_len (routersOnSubnet));
|
|
||||||
nm_ip4_config_set_gateway (config, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update /etc/resolv.conf */
|
|
||||||
if (dhcp_interface_option_present (dhcp_info, dns))
|
|
||||||
{
|
|
||||||
guint32 *data = dhcp_interface_option_payload (dhcp_info, dns);
|
|
||||||
int len = dhcp_interface_option_len (dhcp_info, dns) / sizeof (guint32);
|
|
||||||
|
|
||||||
for (temp = 0; temp < len; temp++)
|
|
||||||
nm_ip4_config_add_nameserver (config, data[temp]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dhcp_interface_option_present (dhcp_info, domainName))
|
|
||||||
{
|
|
||||||
char **searches = g_strsplit (dhcp_interface_option_payload (dev->dhcp_iface, domainName), " ", 0);
|
|
||||||
char **s;
|
|
||||||
|
|
||||||
for (s = searches; *s; s++)
|
|
||||||
nm_ip4_config_add_domain (config, *s);
|
|
||||||
|
|
||||||
g_strfreev (searches);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_device_dhcp_cease
|
|
||||||
*
|
|
||||||
* Signal dhcp that its supposed to stop and return.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void nm_device_dhcp_cease (NMDevice *dev)
|
|
||||||
{
|
|
||||||
g_return_if_fail (dev != NULL);
|
|
||||||
g_return_if_fail (dev->dhcp_iface != NULL);
|
|
||||||
|
|
||||||
dhcp_interface_cease (dev->dhcp_iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_device_dhcp_setup_timeouts
|
|
||||||
*
|
|
||||||
* Set up the DHCP renew and rebind timeouts for a device.
|
|
||||||
*
|
|
||||||
* Returns: FALSE on error
|
|
||||||
* TRUE on success
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
gboolean nm_device_dhcp_setup_timeouts (NMDevice *dev)
|
|
||||||
{
|
|
||||||
int t1 = 0, t2 = 0;
|
|
||||||
GSource *t1_source, *t2_source;
|
|
||||||
|
|
||||||
g_return_val_if_fail (dev != NULL, FALSE);
|
|
||||||
|
|
||||||
if (dhcp_interface_option_present (dev->dhcp_iface, dhcpT1value))
|
|
||||||
{
|
|
||||||
memcpy (&t1, dhcp_interface_option_payload (dev->dhcp_iface, dhcpT1value), sizeof (int));
|
|
||||||
t1 = ntohl (t1);
|
|
||||||
}
|
|
||||||
if (dhcp_interface_option_present (dev->dhcp_iface, dhcpT2value))
|
|
||||||
{
|
|
||||||
memcpy (&t2, dhcp_interface_option_payload (dev->dhcp_iface, dhcpT2value), sizeof (int));
|
|
||||||
t2 = ntohl (t2);
|
|
||||||
}
|
|
||||||
if (!t1 || !t2)
|
|
||||||
{
|
|
||||||
nm_warning ("DHCP renew/rebind values were 0! Won't renew lease.");
|
|
||||||
return (FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
t1_source = g_timeout_source_new (t1 * 1000);
|
|
||||||
t2_source = g_timeout_source_new (t2 * 1000);
|
|
||||||
g_source_set_callback (t1_source, nm_device_dhcp_renew, dev, NULL);
|
|
||||||
g_source_set_callback (t2_source, nm_device_dhcp_rebind, dev, NULL);
|
|
||||||
dev->renew_timeout = g_source_attach (t1_source, dev->context);
|
|
||||||
dev->rebind_timeout = g_source_attach (t2_source, dev->context);
|
|
||||||
|
|
||||||
return (TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_device_dhcp_remove_timeouts
|
|
||||||
*
|
|
||||||
* Remove the DHCP renew and rebind timeouts for a device.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void nm_device_dhcp_remove_timeouts (NMDevice *dev)
|
|
||||||
{
|
|
||||||
g_return_if_fail (dev != NULL);
|
|
||||||
|
|
||||||
if (dev->renew_timeout > 0)
|
|
||||||
{
|
|
||||||
g_source_destroy (g_main_context_find_source_by_id (dev->context, dev->renew_timeout));
|
|
||||||
dev->renew_timeout = 0;
|
|
||||||
}
|
|
||||||
if (dev->rebind_timeout > 0)
|
|
||||||
{
|
|
||||||
g_source_destroy (g_main_context_find_source_by_id (dev->context, dev->rebind_timeout));
|
|
||||||
dev->renew_timeout = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_device_dhcp_renew
|
|
||||||
*
|
|
||||||
* Renew a DHCP address.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
gboolean nm_device_dhcp_renew (gpointer user_data)
|
|
||||||
{
|
|
||||||
NMDevice *dev = (NMDevice *)user_data;
|
|
||||||
|
|
||||||
g_return_val_if_fail (dev != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (dev->app_data != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (dev->dhcp_iface, FALSE);
|
|
||||||
|
|
||||||
if (dhcp_renew (dev->dhcp_iface) != RET_DHCP_BOUND)
|
|
||||||
{
|
|
||||||
/* If the T1 renewal fails, then we wait around until T2
|
|
||||||
* for rebind.
|
|
||||||
*/
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Lease renewed, start timers again from 0 */
|
|
||||||
nm_device_dhcp_setup_timeouts (dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Always return false to remove ourselves, since we just
|
|
||||||
* set up another timeout above.
|
|
||||||
*/
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_device_dhcp_rebind
|
|
||||||
*
|
|
||||||
* Renew a DHCP address.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
gboolean nm_device_dhcp_rebind (gpointer user_data)
|
|
||||||
{
|
|
||||||
NMDevice *dev = (NMDevice *)user_data;
|
|
||||||
|
|
||||||
g_return_val_if_fail (dev != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (dev->app_data != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (dev->dhcp_iface, FALSE);
|
|
||||||
|
|
||||||
if (dhcp_rebind (dev->dhcp_iface) != RET_DHCP_BOUND)
|
|
||||||
{
|
|
||||||
/* T2 rebind failed, so flush the device's address and signal
|
|
||||||
* that we should find another device to use.
|
|
||||||
*/
|
|
||||||
/* FIXME: technically we should run out the entire lease time before
|
|
||||||
* flushing the address and getting a new device. We'll leave that for
|
|
||||||
* a bit later (do a new timer for entire lease time, blah, blah).
|
|
||||||
*/
|
|
||||||
nm_system_device_flush_addresses (dev);
|
|
||||||
nm_device_update_ip4_address (dev);
|
|
||||||
nm_policy_schedule_state_update (dev->app_data);
|
|
||||||
|
|
||||||
dhcp_interface_free (dev->dhcp_iface);
|
|
||||||
dev->dhcp_iface = NULL;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Lease renewed, start timers again from 0 */
|
|
||||||
nm_device_dhcp_setup_timeouts (dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Always return false to remove ourselves, since we just
|
|
||||||
* set up another timeout above.
|
|
||||||
*/
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
@@ -1,37 +0,0 @@
|
|||||||
/* NetworkManager -- Network link manager
|
|
||||||
*
|
|
||||||
* Dan Williams <dcbw@redhat.com>
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* (C) Copyright 2004 Red Hat, Inc.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NETWORK_MANAGER_DHCP_H
|
|
||||||
#define NETWORK_MANAGER_DHCP_H
|
|
||||||
|
|
||||||
#include "../dhcpcd/dhcpcd.h"
|
|
||||||
|
|
||||||
void nm_device_dhcp_cease (NMDevice *dev);
|
|
||||||
gboolean nm_device_dhcp_setup_timeouts (NMDevice *dev);
|
|
||||||
void nm_device_dhcp_remove_timeouts(NMDevice *dev);
|
|
||||||
gboolean nm_device_dhcp_renew (gpointer user_data);
|
|
||||||
gboolean nm_device_dhcp_rebind (gpointer user_data);
|
|
||||||
|
|
||||||
|
|
||||||
NMIP4Config * nm_device_new_ip4_autoip_config (NMDevice *dev);
|
|
||||||
NMIP4Config * nm_device_new_ip4_dhcp_config (NMDevice *dev);
|
|
||||||
|
|
||||||
#endif
|
|
@@ -39,10 +39,11 @@
|
|||||||
#include "nm-dbus-nm.h"
|
#include "nm-dbus-nm.h"
|
||||||
#include "nm-dbus-device.h"
|
#include "nm-dbus-device.h"
|
||||||
#include "nm-dbus-net.h"
|
#include "nm-dbus-net.h"
|
||||||
#include "nm-dbus-dhcp.h"
|
|
||||||
#include "nm-dbus-vpn.h"
|
#include "nm-dbus-vpn.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
|
#include "nm-dhcp-manager.h"
|
||||||
|
|
||||||
|
static char *get_nmi_match_string (const char *owner);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_dbus_create_error_message
|
* nm_dbus_create_error_message
|
||||||
@@ -288,7 +289,7 @@ void nm_dbus_schedule_device_status_change (NMDevice *dev, DeviceStatus status)
|
|||||||
void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice *dev, DeviceStatus status)
|
void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice *dev, DeviceStatus status)
|
||||||
{
|
{
|
||||||
DBusMessage * message;
|
DBusMessage * message;
|
||||||
gchar *dev_path;
|
char * dev_path;
|
||||||
const char * signal = NULL;
|
const char * signal = NULL;
|
||||||
NMAccessPoint * ap = NULL;
|
NMAccessPoint * ap = NULL;
|
||||||
|
|
||||||
@@ -300,24 +301,22 @@ void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice *
|
|||||||
|
|
||||||
switch (status)
|
switch (status)
|
||||||
{
|
{
|
||||||
case (DEVICE_NO_LONGER_ACTIVE):
|
case DEVICE_NO_LONGER_ACTIVE:
|
||||||
signal = "DeviceNoLongerActive";
|
signal = "DeviceNoLongerActive";
|
||||||
break;
|
break;
|
||||||
case (DEVICE_NOW_ACTIVE):
|
case DEVICE_NOW_ACTIVE:
|
||||||
signal = "DeviceNowActive";
|
signal = "DeviceNowActive";
|
||||||
break;
|
break;
|
||||||
case (DEVICE_ACTIVATING):
|
case DEVICE_ACTIVATING:
|
||||||
signal = "DeviceActivating";
|
signal = "DeviceActivating";
|
||||||
break;
|
break;
|
||||||
case (DEVICE_ACTIVATION_FAILED):
|
case DEVICE_ACTIVATION_FAILED:
|
||||||
signal = "DeviceActivationFailed";
|
signal = "DeviceActivationFailed";
|
||||||
if (nm_device_is_wireless (dev))
|
|
||||||
ap = nm_device_get_best_ap (dev);
|
|
||||||
break;
|
break;
|
||||||
case (DEVICE_ADDED):
|
case DEVICE_ADDED:
|
||||||
signal = "DeviceAdded";
|
signal = "DeviceAdded";
|
||||||
break;
|
break;
|
||||||
case (DEVICE_REMOVED):
|
case DEVICE_REMOVED:
|
||||||
signal = "DeviceRemoved";
|
signal = "DeviceRemoved";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -363,26 +362,22 @@ void nm_dbus_signal_device_status_change (DBusConnection *connection, NMDevice *
|
|||||||
*/
|
*/
|
||||||
NMState nm_get_app_state_from_data (NMData *data)
|
NMState nm_get_app_state_from_data (NMData *data)
|
||||||
{
|
{
|
||||||
char *status = NULL;
|
NMDevice * act_dev = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (data != NULL, NM_STATE_DISCONNECTED);
|
g_return_val_if_fail (data != NULL, NM_STATE_DISCONNECTED);
|
||||||
|
|
||||||
if (data->asleep == TRUE)
|
if (data->asleep == TRUE)
|
||||||
return NM_STATE_ASLEEP;
|
return NM_STATE_ASLEEP;
|
||||||
if (data->forcing_device)
|
|
||||||
return NM_STATE_SCANNING;
|
act_dev = nm_get_active_device (data);
|
||||||
else if (data->active_device && nm_device_is_activating (data->active_device))
|
if (!act_dev)
|
||||||
{
|
|
||||||
if (nm_device_is_wireless (data->active_device) && nm_device_get_now_scanning (data->active_device))
|
|
||||||
return NM_STATE_SCANNING;
|
|
||||||
else
|
|
||||||
return NM_STATE_CONNECTING;
|
|
||||||
}
|
|
||||||
else if (data->active_device)
|
|
||||||
return NM_STATE_CONNECTED;
|
|
||||||
else
|
|
||||||
return NM_STATE_DISCONNECTED;
|
return NM_STATE_DISCONNECTED;
|
||||||
|
|
||||||
|
if (nm_device_is_activating (act_dev))
|
||||||
|
return NM_STATE_CONNECTING;
|
||||||
|
else
|
||||||
|
return NM_STATE_CONNECTED;
|
||||||
|
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
|
|
||||||
return NM_STATE_UNKNOWN;
|
return NM_STATE_UNKNOWN;
|
||||||
@@ -518,25 +513,6 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef struct GetKeyForNetworkCBData
|
|
||||||
{
|
|
||||||
NMData * data;
|
|
||||||
char * dev_path;
|
|
||||||
char * net_path;
|
|
||||||
} GetKeyForNetworkCBData;
|
|
||||||
|
|
||||||
|
|
||||||
void free_get_key_for_network_cb_data (GetKeyForNetworkCBData *data)
|
|
||||||
{
|
|
||||||
if (data)
|
|
||||||
{
|
|
||||||
g_free (data->dev_path);
|
|
||||||
g_free (data->net_path);
|
|
||||||
memset (data, 0, sizeof (GetKeyForNetworkCBData));
|
|
||||||
g_free (data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_dbus_get_user_key_for_network_cb
|
* nm_dbus_get_user_key_for_network_cb
|
||||||
*
|
*
|
||||||
@@ -544,20 +520,31 @@ void free_get_key_for_network_cb_data (GetKeyForNetworkCBData *data)
|
|||||||
* the new user key.
|
* the new user key.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void nm_dbus_get_user_key_for_network_cb (DBusPendingCall *pcall, GetKeyForNetworkCBData *cb_data)
|
static void nm_dbus_get_user_key_for_network_cb (DBusPendingCall *pcall, NMActRequest *req)
|
||||||
{
|
{
|
||||||
DBusMessage * reply;
|
DBusMessage * reply;
|
||||||
|
NMData * data;
|
||||||
|
NMDevice * dev;
|
||||||
|
NMAccessPoint * ap;
|
||||||
char * passphrase = NULL;
|
char * passphrase = NULL;
|
||||||
NMEncKeyType key_type = -1;
|
NMEncKeyType key_type = -1;
|
||||||
|
|
||||||
g_return_if_fail (pcall != NULL);
|
g_return_if_fail (pcall != NULL);
|
||||||
g_return_if_fail (cb_data != NULL);
|
g_return_if_fail (req != NULL);
|
||||||
g_return_if_fail (cb_data->data != NULL);
|
|
||||||
g_return_if_fail (cb_data->dev_path != NULL);
|
data = nm_act_request_get_data (req);
|
||||||
g_return_if_fail (cb_data->net_path != NULL);
|
g_assert (data);
|
||||||
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
ap = nm_act_request_get_ap (req);
|
||||||
|
g_assert (ap);
|
||||||
|
|
||||||
dbus_pending_call_ref (pcall);
|
dbus_pending_call_ref (pcall);
|
||||||
|
|
||||||
|
nm_info ("Activation (%s) New wireless user key for network '%s' received.", nm_device_get_iface (dev), nm_ap_get_essid (ap));
|
||||||
|
|
||||||
if (!dbus_pending_call_get_completed (pcall))
|
if (!dbus_pending_call_get_completed (pcall))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
@@ -566,29 +553,19 @@ static void nm_dbus_get_user_key_for_network_cb (DBusPendingCall *pcall, GetKeyF
|
|||||||
|
|
||||||
if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
|
if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
|
||||||
{
|
{
|
||||||
|
/* FIXME: stop activation for this device if the dialog couldn't show */
|
||||||
dbus_message_unref (reply);
|
dbus_message_unref (reply);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &passphrase, DBUS_TYPE_INT32, &key_type, DBUS_TYPE_INVALID))
|
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &passphrase, DBUS_TYPE_INT32, &key_type, DBUS_TYPE_INVALID))
|
||||||
{
|
nm_device_set_user_key_for_network (req, passphrase, key_type);
|
||||||
char * dev_path = nm_dbus_unescape_object_path (cb_data->dev_path);
|
|
||||||
char * net_path = nm_dbus_unescape_object_path (cb_data->net_path);
|
|
||||||
NMDevice * dev;
|
|
||||||
NMAccessPoint * ap;
|
|
||||||
|
|
||||||
if ((dev = nm_dbus_get_device_from_object_path (cb_data->data, dev_path)))
|
|
||||||
{
|
|
||||||
if ((ap = nm_device_ap_list_get_ap_by_obj_path (dev, net_path)))
|
|
||||||
nm_device_set_user_key_for_network (dev, cb_data->data->invalid_ap_list, ap, passphrase, key_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (dev_path);
|
|
||||||
g_free (net_path);
|
|
||||||
}
|
|
||||||
dbus_message_unref (reply);
|
dbus_message_unref (reply);
|
||||||
|
|
||||||
|
nm_act_request_set_user_key_pending_call (req, NULL);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
nm_act_request_unref (req);
|
||||||
dbus_pending_call_unref (pcall);
|
dbus_pending_call_unref (pcall);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -599,19 +576,30 @@ out:
|
|||||||
* Asks NetworkManagerInfo for a user-entered WEP key.
|
* Asks NetworkManagerInfo for a user-entered WEP key.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, int attempt)
|
void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMActRequest *req)
|
||||||
{
|
{
|
||||||
DBusMessage * message;
|
DBusMessage * message;
|
||||||
DBusPendingCall * pcall;
|
DBusPendingCall * pcall;
|
||||||
|
NMData * data;
|
||||||
|
NMDevice * dev;
|
||||||
|
NMAccessPoint * ap;
|
||||||
|
gint32 attempt = 1;
|
||||||
char * dev_path;
|
char * dev_path;
|
||||||
char * net_path;
|
char * net_path;
|
||||||
|
|
||||||
g_return_if_fail (connection != NULL);
|
g_return_if_fail (connection != NULL);
|
||||||
g_return_if_fail (dev != NULL);
|
g_return_if_fail (req != NULL);
|
||||||
g_return_if_fail (nm_device_get_app_data (dev) != NULL);
|
|
||||||
g_return_if_fail (ap != NULL);
|
data = nm_act_request_get_data (req);
|
||||||
g_return_if_fail (nm_ap_get_essid (ap) != NULL);
|
g_assert (data);
|
||||||
g_return_if_fail (attempt > 0);
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
ap = nm_act_request_get_ap (req);
|
||||||
|
g_assert (ap);
|
||||||
|
|
||||||
|
nm_info ("Activation (%s) New wireless user key requested for network '%s'.", nm_device_get_iface (dev), nm_ap_get_essid (ap));
|
||||||
|
|
||||||
if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getKeyForNetwork")))
|
if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getKeyForNetwork")))
|
||||||
{
|
{
|
||||||
@@ -629,17 +617,14 @@ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev
|
|||||||
DBUS_TYPE_INVALID);
|
DBUS_TYPE_INVALID);
|
||||||
if (dbus_connection_send_with_reply (connection, message, &pcall, INT_MAX) && pcall)
|
if (dbus_connection_send_with_reply (connection, message, &pcall, INT_MAX) && pcall)
|
||||||
{
|
{
|
||||||
GetKeyForNetworkCBData * cb_data = g_malloc0 (sizeof (GetKeyForNetworkCBData));
|
nm_act_request_ref (req);
|
||||||
|
nm_act_request_set_stage (req, ACT_STAGE_NEED_USER_KEY);
|
||||||
cb_data->data = nm_device_get_app_data (dev);
|
nm_act_request_set_user_key_pending_call (req, pcall);
|
||||||
cb_data->dev_path = g_strdup (dev_path);
|
dbus_pending_call_set_notify (pcall, (DBusPendingCallNotifyFunction) nm_dbus_get_user_key_for_network_cb, req, NULL);
|
||||||
cb_data->net_path = g_strdup (net_path);
|
|
||||||
dbus_pending_call_set_notify (pcall, (DBusPendingCallNotifyFunction) nm_dbus_get_user_key_for_network_cb,
|
|
||||||
cb_data, (DBusFreeFunction) free_get_key_for_network_cb_data);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
nm_warning ("nm_dbus_get_user_key_for_network(): could not send dbus message");
|
nm_warning ("nm_dbus_get_user_key_for_network(): could not send dbus message");
|
||||||
}
|
} else nm_warning ("nm_dbus_get_user_key_for_network(): bad object path data");
|
||||||
g_free (net_path);
|
g_free (net_path);
|
||||||
g_free (dev_path);
|
g_free (dev_path);
|
||||||
|
|
||||||
@@ -653,11 +638,16 @@ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev
|
|||||||
* Sends a user-key cancellation message to NetworkManagerInfo
|
* Sends a user-key cancellation message to NetworkManagerInfo
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection)
|
void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection, NMActRequest *req)
|
||||||
{
|
{
|
||||||
DBusMessage * message;
|
DBusMessage * message;
|
||||||
|
DBusPendingCall * pcall;
|
||||||
|
|
||||||
g_return_if_fail (connection != NULL);
|
g_return_if_fail (connection != NULL);
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
if ((pcall = nm_act_request_get_user_key_pending_call (req)))
|
||||||
|
dbus_pending_call_cancel (pcall);
|
||||||
|
|
||||||
if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "cancelGetKeyForNetwork")))
|
if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "cancelGetKeyForNetwork")))
|
||||||
{
|
{
|
||||||
@@ -1076,7 +1066,10 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus
|
|||||||
|
|
||||||
method = dbus_message_get_member (message);
|
method = dbus_message_get_member (message);
|
||||||
if (!(object_path = dbus_message_get_path (message)))
|
if (!(object_path = dbus_message_get_path (message)))
|
||||||
return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||||
|
|
||||||
|
if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
|
||||||
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||||
|
|
||||||
/* nm_debug ("nm_dbus_nmi_filter() got method %s for path %s", method, object_path); */
|
/* nm_debug ("nm_dbus_nmi_filter() got method %s for path %s", method, object_path); */
|
||||||
|
|
||||||
@@ -1107,6 +1100,12 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus
|
|||||||
handled = TRUE;
|
handled = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "Disconnected"))
|
||||||
|
{
|
||||||
|
/* FIXME: try to recover from disconnection */
|
||||||
|
data->dbus_connection = NULL;
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
|
else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
|
||||||
{
|
{
|
||||||
char *service;
|
char *service;
|
||||||
@@ -1123,19 +1122,41 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus
|
|||||||
|
|
||||||
if (!old_owner_good && new_owner_good) /* NMI just appeared */
|
if (!old_owner_good && new_owner_good) /* NMI just appeared */
|
||||||
{
|
{
|
||||||
|
char *match = get_nmi_match_string (new_owner);
|
||||||
|
dbus_bus_add_match (connection, match, NULL);
|
||||||
nm_policy_schedule_allowed_ap_list_update (data);
|
nm_policy_schedule_allowed_ap_list_update (data);
|
||||||
nm_dbus_vpn_schedule_vpn_connections_update (data);
|
nm_dbus_vpn_schedule_vpn_connections_update (data);
|
||||||
|
g_free (match);
|
||||||
|
handled = TRUE;
|
||||||
}
|
}
|
||||||
|
else if (old_owner_good && !new_owner_good) /* NMI went away */
|
||||||
|
{
|
||||||
|
char *match = get_nmi_match_string (old_owner);
|
||||||
|
dbus_bus_remove_match (connection, match, NULL);
|
||||||
|
g_free (match);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (nm_dhcp_manager_process_name_owner_changed (data->dhcp_manager, service, old_owner, new_owner) == TRUE)
|
||||||
|
{
|
||||||
|
/* Processed by the DHCP manager */
|
||||||
|
handled = TRUE;
|
||||||
}
|
}
|
||||||
else if (nm_vpn_manager_process_name_owner_changed (data->vpn_manager, service, old_owner, new_owner) == TRUE)
|
else if (nm_vpn_manager_process_name_owner_changed (data->vpn_manager, service, old_owner, new_owner) == TRUE)
|
||||||
{
|
{
|
||||||
/* Processed by the VPN manager */
|
/* Processed by the VPN manager */
|
||||||
|
handled = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (nm_dhcp_manager_process_signal (data->dhcp_manager, message) == TRUE)
|
||||||
|
{
|
||||||
|
/* Processed by the DHCP manager */
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
else if (nm_vpn_manager_process_signal (data->vpn_manager, message) == TRUE)
|
else if (nm_vpn_manager_process_signal (data->vpn_manager, message) == TRUE)
|
||||||
{
|
{
|
||||||
/* Processed by the VPN manager */
|
/* Processed by the VPN manager */
|
||||||
|
handled = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbus_error_is_set (&error))
|
if (dbus_error_is_set (&error))
|
||||||
@@ -1228,41 +1249,6 @@ static DBusHandlerResult nm_dbus_devices_message_handler (DBusConnection *connec
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_dbus_dhcp_message_handler
|
|
||||||
*
|
|
||||||
* Dispatch messages against our NetworkManager DHCP object
|
|
||||||
*
|
|
||||||
* All calls are in the form /NM_DBUS_PATH_DHCP->METHOD (STRING attribute)
|
|
||||||
* For example, /org/freedesktop/NetworkManager/DhcpOptions->getType ("Name Server")
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static DBusHandlerResult nm_dbus_dhcp_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data)
|
|
||||||
{
|
|
||||||
NMData *data = (NMData *)user_data;
|
|
||||||
gboolean handled = TRUE;
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
NMDbusCBData cb_data;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
|
|
||||||
g_return_val_if_fail (data->dhcp_methods != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
|
|
||||||
g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
|
|
||||||
g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
|
|
||||||
|
|
||||||
cb_data.data = data;
|
|
||||||
cb_data.dev = NULL;
|
|
||||||
cb_data.opt_id = -1;
|
|
||||||
handled = nm_dbus_method_dispatch (data->dhcp_methods, connection, message, &cb_data, &reply);
|
|
||||||
if (reply)
|
|
||||||
{
|
|
||||||
dbus_connection_send (connection, reply, NULL);
|
|
||||||
dbus_message_unref (reply);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (handled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_dbus_vpn_message_handler
|
* nm_dbus_vpn_message_handler
|
||||||
*
|
*
|
||||||
@@ -1283,7 +1269,6 @@ static DBusHandlerResult nm_dbus_vpn_message_handler (DBusConnection *connection
|
|||||||
|
|
||||||
cb_data.data = data;
|
cb_data.data = data;
|
||||||
cb_data.dev = NULL;
|
cb_data.dev = NULL;
|
||||||
cb_data.opt_id = -1;
|
|
||||||
handled = nm_dbus_method_dispatch (data->vpn_methods, connection, message, &cb_data, &reply);
|
handled = nm_dbus_method_dispatch (data->vpn_methods, connection, message, &cb_data, &reply);
|
||||||
if (reply)
|
if (reply)
|
||||||
{
|
{
|
||||||
@@ -1311,8 +1296,46 @@ gboolean nm_dbus_is_info_daemon_running (DBusConnection *connection)
|
|||||||
dbus_error_init (&error);
|
dbus_error_init (&error);
|
||||||
running = dbus_bus_name_has_owner (connection, NMI_DBUS_SERVICE, &error);
|
running = dbus_bus_name_has_owner (connection, NMI_DBUS_SERVICE, &error);
|
||||||
if (dbus_error_is_set (&error))
|
if (dbus_error_is_set (&error))
|
||||||
|
{
|
||||||
|
running = FALSE;
|
||||||
dbus_error_free (&error);
|
dbus_error_free (&error);
|
||||||
return (running);
|
}
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *get_name_owner (DBusConnection *con, const char *name)
|
||||||
|
{
|
||||||
|
DBusMessage * message;
|
||||||
|
DBusMessage * reply;
|
||||||
|
char * owner = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (con != NULL, NULL);
|
||||||
|
g_return_val_if_fail (name != NULL, NULL);
|
||||||
|
|
||||||
|
if ((message = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetNameOwner")))
|
||||||
|
{
|
||||||
|
dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
|
||||||
|
if ((reply = dbus_connection_send_with_reply_and_block (con, message, -1, NULL)))
|
||||||
|
{
|
||||||
|
const char *tmp_name = NULL;
|
||||||
|
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &tmp_name, DBUS_TYPE_INVALID))
|
||||||
|
owner = g_strdup (tmp_name);
|
||||||
|
dbus_message_unref (reply);
|
||||||
|
}
|
||||||
|
dbus_message_unref (message);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "GetNameOwner returning owner '%s' for name '%s'.\n", owner, name);
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *get_nmi_match_string (const char *owner)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (owner != NULL, NULL);
|
||||||
|
|
||||||
|
return g_strdup_printf ("type='signal',interface='" NMI_DBUS_INTERFACE "',sender='%s',path='" NMI_DBUS_PATH "'", owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1328,8 +1351,8 @@ DBusConnection *nm_dbus_init (NMData *data)
|
|||||||
DBusConnection * connection;
|
DBusConnection * connection;
|
||||||
DBusObjectPathVTable nm_vtable = {NULL, &nm_dbus_nm_message_handler, NULL, NULL, NULL, NULL};
|
DBusObjectPathVTable nm_vtable = {NULL, &nm_dbus_nm_message_handler, NULL, NULL, NULL, NULL};
|
||||||
DBusObjectPathVTable devices_vtable = {NULL, &nm_dbus_devices_message_handler, NULL, NULL, NULL, NULL};
|
DBusObjectPathVTable devices_vtable = {NULL, &nm_dbus_devices_message_handler, NULL, NULL, NULL, NULL};
|
||||||
DBusObjectPathVTable dhcp_vtable = {NULL, &nm_dbus_dhcp_message_handler, NULL, NULL, NULL, NULL};
|
|
||||||
DBusObjectPathVTable vpn_vtable = {NULL, &nm_dbus_vpn_message_handler, NULL, NULL, NULL, NULL};
|
DBusObjectPathVTable vpn_vtable = {NULL, &nm_dbus_vpn_message_handler, NULL, NULL, NULL, NULL};
|
||||||
|
char * owner;
|
||||||
|
|
||||||
dbus_connection_set_change_sigpipe (TRUE);
|
dbus_connection_set_change_sigpipe (TRUE);
|
||||||
|
|
||||||
@@ -1348,12 +1371,10 @@ DBusConnection *nm_dbus_init (NMData *data)
|
|||||||
data->nm_methods = nm_dbus_nm_methods_setup ();
|
data->nm_methods = nm_dbus_nm_methods_setup ();
|
||||||
data->device_methods = nm_dbus_device_methods_setup ();
|
data->device_methods = nm_dbus_device_methods_setup ();
|
||||||
data->net_methods = nm_dbus_net_methods_setup ();
|
data->net_methods = nm_dbus_net_methods_setup ();
|
||||||
data->dhcp_methods = nm_dbus_dhcp_methods_setup ();
|
|
||||||
data->vpn_methods = nm_dbus_vpn_methods_setup ();
|
data->vpn_methods = nm_dbus_vpn_methods_setup ();
|
||||||
|
|
||||||
if ( !dbus_connection_register_object_path (connection, NM_DBUS_PATH, &nm_vtable, data)
|
if ( !dbus_connection_register_object_path (connection, NM_DBUS_PATH, &nm_vtable, data)
|
||||||
|| !dbus_connection_register_fallback (connection, NM_DBUS_PATH_DEVICES, &devices_vtable, data)
|
|| !dbus_connection_register_fallback (connection, NM_DBUS_PATH_DEVICES, &devices_vtable, data)
|
||||||
|| !dbus_connection_register_object_path (connection, NM_DBUS_PATH_DHCP, &dhcp_vtable, data)
|
|
||||||
|| !dbus_connection_register_object_path (connection, NM_DBUS_PATH_VPN, &vpn_vtable, data))
|
|| !dbus_connection_register_object_path (connection, NM_DBUS_PATH_VPN, &vpn_vtable, data))
|
||||||
{
|
{
|
||||||
nm_error ("nm_dbus_init() could not register D-BUS handlers. Cannot continue.");
|
nm_error ("nm_dbus_init() could not register D-BUS handlers. Cannot continue.");
|
||||||
@@ -1368,19 +1389,21 @@ DBusConnection *nm_dbus_init (NMData *data)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbus_bus_add_match (connection,
|
|
||||||
"type='signal',"
|
|
||||||
"interface='" NMI_DBUS_INTERFACE "',"
|
|
||||||
"sender='" NMI_DBUS_SERVICE "',"
|
|
||||||
"path='" NMI_DBUS_PATH "'",
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
dbus_bus_add_match (connection,
|
dbus_bus_add_match (connection,
|
||||||
"type='signal',"
|
"type='signal',"
|
||||||
"interface='" DBUS_INTERFACE_DBUS "',"
|
"interface='" DBUS_INTERFACE_DBUS "',"
|
||||||
"sender='" DBUS_SERVICE_DBUS "'",
|
"sender='" DBUS_SERVICE_DBUS "'",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
if ((owner = get_name_owner (connection, NMI_DBUS_SERVICE)))
|
||||||
|
{
|
||||||
|
char *match = get_nmi_match_string (owner);
|
||||||
|
|
||||||
|
dbus_bus_add_match (connection, match, NULL);
|
||||||
|
g_free (match);
|
||||||
|
g_free (owner);
|
||||||
|
}
|
||||||
|
|
||||||
dbus_error_init (&error);
|
dbus_error_init (&error);
|
||||||
dbus_bus_request_name (connection, NM_DBUS_SERVICE, 0, &error);
|
dbus_bus_request_name (connection, NM_DBUS_SERVICE, 0, &error);
|
||||||
if (dbus_error_is_set (&error))
|
if (dbus_error_is_set (&error))
|
||||||
|
@@ -52,6 +52,7 @@ static inline gboolean message_is_error (DBusMessage *msg)
|
|||||||
DBusConnection *nm_dbus_init (NMData *data);
|
DBusConnection *nm_dbus_init (NMData *data);
|
||||||
|
|
||||||
gboolean nm_dbus_is_info_daemon_running (DBusConnection *connection);
|
gboolean nm_dbus_is_info_daemon_running (DBusConnection *connection);
|
||||||
|
char * get_name_owner (DBusConnection *con, const char *name);
|
||||||
|
|
||||||
char * nm_dbus_get_object_path_for_device (NMDevice *dev);
|
char * nm_dbus_get_object_path_for_device (NMDevice *dev);
|
||||||
char * nm_dbus_get_object_path_for_network (NMDevice *dev, NMAccessPoint *ap);
|
char * nm_dbus_get_object_path_for_network (NMDevice *dev, NMAccessPoint *ap);
|
||||||
@@ -67,9 +68,9 @@ void nm_dbus_signal_device_ip4_address_change(DBusConnection *connection, NMDe
|
|||||||
|
|
||||||
void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, NMNetworkStatus status, gint8 strength);
|
void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, NMNetworkStatus status, gint8 strength);
|
||||||
|
|
||||||
void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, int attempt);
|
void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMActRequest *req);
|
||||||
|
|
||||||
void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection);
|
void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection, NMActRequest *req);
|
||||||
|
|
||||||
NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetworkType type, const char *network);
|
NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetworkType type, const char *network);
|
||||||
|
|
||||||
|
@@ -28,15 +28,12 @@
|
|||||||
#include <dbus/dbus-glib.h>
|
#include <dbus/dbus-glib.h>
|
||||||
|
|
||||||
#include "NetworkManagerDevice.h"
|
#include "NetworkManagerDevice.h"
|
||||||
#include "dhcpcd/dhcpcd.h"
|
|
||||||
|
|
||||||
typedef struct NMDbusCBData
|
typedef struct NMDbusCBData
|
||||||
{
|
{
|
||||||
NMData *data;
|
NMData *data;
|
||||||
NMDevice *dev;
|
NMDevice *dev;
|
||||||
NMAccessPoint *ap;
|
NMAccessPoint *ap;
|
||||||
int opt_id;
|
|
||||||
struct dhcp_interface *dhcp_iface;
|
|
||||||
} NMDbusCBData;
|
} NMDbusCBData;
|
||||||
|
|
||||||
typedef DBusMessage* (*NMDbusMethod) (DBusConnection *, DBusMessage *, NMDbusCBData *);
|
typedef DBusMessage* (*NMDbusMethod) (DBusConnection *, DBusMessage *, NMDbusCBData *);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -51,7 +51,6 @@ NMDriverSupportLevel nm_device_get_driver_support_level (NMDevice *dev);
|
|||||||
|
|
||||||
gboolean nm_device_is_wireless (NMDevice *dev);
|
gboolean nm_device_is_wireless (NMDevice *dev);
|
||||||
gboolean nm_device_is_wired (NMDevice *dev);
|
gboolean nm_device_is_wired (NMDevice *dev);
|
||||||
/* There is no nm_device_set_iface_type() because that's determined when you set the device's iface */
|
|
||||||
|
|
||||||
NMData * nm_device_get_app_data (const NMDevice *dev);
|
NMData * nm_device_get_app_data (const NMDevice *dev);
|
||||||
|
|
||||||
@@ -60,7 +59,7 @@ void nm_device_set_removed (NMDevice *dev, const gboolean removed);
|
|||||||
|
|
||||||
gboolean nm_device_has_active_link (NMDevice *dev);
|
gboolean nm_device_has_active_link (NMDevice *dev);
|
||||||
void nm_device_set_link_active (NMDevice *dev, const gboolean active);
|
void nm_device_set_link_active (NMDevice *dev, const gboolean active);
|
||||||
void nm_device_update_link_state (NMDevice *dev);
|
gboolean nm_device_probe_link_state (NMDevice *dev);
|
||||||
|
|
||||||
char * nm_device_get_essid (NMDevice *dev);
|
char * nm_device_get_essid (NMDevice *dev);
|
||||||
void nm_device_set_essid (NMDevice *dev, const char *essid);
|
void nm_device_set_essid (NMDevice *dev, const char *essid);
|
||||||
@@ -72,7 +71,7 @@ NMNetworkMode nm_device_get_mode (NMDevice *dev);
|
|||||||
guint32 nm_device_get_ip4_address (NMDevice *dev);
|
guint32 nm_device_get_ip4_address (NMDevice *dev);
|
||||||
void nm_device_update_ip4_address (NMDevice *dev);
|
void nm_device_update_ip4_address (NMDevice *dev);
|
||||||
|
|
||||||
void nm_device_get_hw_address (NMDevice *dev, unsigned char *eth_addr);
|
void nm_device_get_hw_address (NMDevice *dev, struct ether_addr *addr);
|
||||||
void nm_device_update_hw_address (NMDevice *dev);
|
void nm_device_update_hw_address (NMDevice *dev);
|
||||||
|
|
||||||
void nm_device_get_ip6_address (NMDevice *dev);
|
void nm_device_get_ip6_address (NMDevice *dev);
|
||||||
@@ -87,30 +86,26 @@ gint8 nm_device_get_signal_strength (NMDevice *dev);
|
|||||||
void nm_device_update_signal_strength (NMDevice *dev);
|
void nm_device_update_signal_strength (NMDevice *dev);
|
||||||
|
|
||||||
NMAccessPoint *nm_device_get_best_ap (NMDevice *dev);
|
NMAccessPoint *nm_device_get_best_ap (NMDevice *dev);
|
||||||
void nm_device_set_best_ap (NMDevice *dev, NMAccessPoint *ap);
|
|
||||||
void nm_device_update_best_ap (NMDevice *dev);
|
|
||||||
gboolean nm_device_need_ap_switch (NMDevice *dev);
|
|
||||||
|
|
||||||
void nm_device_freeze_best_ap (NMDevice *dev);
|
void nm_device_freeze_best_ap (NMDevice *dev);
|
||||||
void nm_device_unfreeze_best_ap (NMDevice *dev);
|
void nm_device_unfreeze_best_ap (NMDevice *dev);
|
||||||
gboolean nm_device_is_best_ap_frozen (NMDevice *dev);
|
gboolean nm_device_is_best_ap_frozen (NMDevice *dev);
|
||||||
struct dhcp_interface *nm_device_get_dhcp_iface (NMDevice *dev);
|
|
||||||
|
|
||||||
/* There is no function to get the WEP key since that's a slight security risk */
|
/* There is no function to get the WEP key since that's a slight security risk */
|
||||||
void nm_device_set_enc_key (NMDevice *dev, const char *key, NMDeviceAuthMethod auth_method);
|
void nm_device_set_enc_key (NMDevice *dev, const char *key, NMDeviceAuthMethod auth_method);
|
||||||
|
|
||||||
gboolean nm_device_activation_schedule_start(NMDevice *dev);
|
NMActRequest * nm_device_get_act_request (NMDevice *dev);
|
||||||
|
gboolean nm_device_activation_start (NMActRequest *req);
|
||||||
|
void nm_device_activate_schedule_stage4_ip_config_get (NMActRequest *req);
|
||||||
|
void nm_device_activate_schedule_stage4_ip_config_timeout (NMActRequest *req);
|
||||||
void nm_device_activation_cancel (NMDevice *dev);
|
void nm_device_activation_cancel (NMDevice *dev);
|
||||||
gboolean nm_device_activation_should_cancel (NMDevice *dev);
|
gboolean nm_device_activation_should_cancel (NMDevice *dev);
|
||||||
gboolean nm_device_is_activating (NMDevice *dev);
|
gboolean nm_device_is_activating (NMDevice *dev);
|
||||||
gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added);
|
gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added);
|
||||||
|
|
||||||
gboolean nm_device_get_now_scanning (NMDevice *dev);
|
NMAccessPoint *nm_device_wireless_get_activation_ap (NMDevice *dev, const char *essid, const char *key, NMEncKeyType key_type);
|
||||||
|
|
||||||
void nm_device_schedule_force_use (NMDevice *dev, const char *network, const char *key, NMEncKeyType key_type);
|
void nm_device_set_user_key_for_network (NMActRequest *req, const char *key, const NMEncKeyType enc_type);
|
||||||
|
|
||||||
void nm_device_set_user_key_for_network (NMDevice *dev, struct NMAccessPointList *invalid_list, NMAccessPoint *ap,
|
|
||||||
unsigned char *key, NMEncKeyType enc_type);
|
|
||||||
|
|
||||||
void nm_device_bring_up (NMDevice *dev);
|
void nm_device_bring_up (NMDevice *dev);
|
||||||
void nm_device_bring_down (NMDevice *dev);
|
void nm_device_bring_down (NMDevice *dev);
|
||||||
|
@@ -50,13 +50,6 @@ typedef struct NMDeviceWirelessOptions
|
|||||||
NMAccessPointList * ap_list;
|
NMAccessPointList * ap_list;
|
||||||
guint8 scan_interval; /* seconds */
|
guint8 scan_interval; /* seconds */
|
||||||
guint32 last_scan;
|
guint32 last_scan;
|
||||||
|
|
||||||
NMAccessPoint *best_ap;
|
|
||||||
GMutex *best_ap_mutex;
|
|
||||||
gboolean freeze_best_ap;
|
|
||||||
|
|
||||||
gboolean user_key_received;
|
|
||||||
gboolean now_scanning;
|
|
||||||
} NMDeviceWirelessOptions;
|
} NMDeviceWirelessOptions;
|
||||||
|
|
||||||
/* Wired device specific options */
|
/* Wired device specific options */
|
||||||
@@ -89,7 +82,7 @@ struct NMDevice
|
|||||||
gboolean link_active;
|
gboolean link_active;
|
||||||
guint32 ip4_address;
|
guint32 ip4_address;
|
||||||
/* FIXME: ipv6 address too */
|
/* FIXME: ipv6 address too */
|
||||||
unsigned char hw_addr[ETH_ALEN];
|
struct ether_addr hw_addr;
|
||||||
NMData * app_data;
|
NMData * app_data;
|
||||||
NMDeviceOptions options;
|
NMDeviceOptions options;
|
||||||
|
|
||||||
@@ -97,7 +90,6 @@ struct NMDevice
|
|||||||
void * system_config_data; /* Distro-specific config data (parsed config file, etc) */
|
void * system_config_data; /* Distro-specific config data (parsed config file, etc) */
|
||||||
gboolean use_dhcp;
|
gboolean use_dhcp;
|
||||||
NMIP4Config * ip4_config; /* Config from DHCP, PPP, or system config files */
|
NMIP4Config * ip4_config; /* Config from DHCP, PPP, or system config files */
|
||||||
struct dhcp_interface * dhcp_iface;
|
|
||||||
|
|
||||||
GMainContext * context;
|
GMainContext * context;
|
||||||
GMainLoop * loop;
|
GMainLoop * loop;
|
||||||
@@ -106,7 +98,7 @@ struct NMDevice
|
|||||||
guint renew_timeout;
|
guint renew_timeout;
|
||||||
guint rebind_timeout;
|
guint rebind_timeout;
|
||||||
|
|
||||||
gboolean activating; /* Set by main thread before beginning activation */
|
NMActRequest * act_request;
|
||||||
gboolean quit_activation; /* Flag to signal activation thread to stop activating */
|
gboolean quit_activation; /* Flag to signal activation thread to stop activating */
|
||||||
|
|
||||||
gboolean test_device;
|
gboolean test_device;
|
||||||
|
@@ -31,9 +31,26 @@
|
|||||||
#include "nm-netlink-monitor.h"
|
#include "nm-netlink-monitor.h"
|
||||||
#include "nm-named-manager.h"
|
#include "nm-named-manager.h"
|
||||||
|
|
||||||
typedef struct NMDbusMethodList NMDbusMethodList;
|
|
||||||
typedef struct NMVPNManager NMVPNManager;
|
|
||||||
|
|
||||||
|
typedef enum NMIntState
|
||||||
|
{
|
||||||
|
NM_INT_STATE_UNKNOWN = 0,
|
||||||
|
NM_INT_STATE_ASLEEP,
|
||||||
|
NM_INT_STATE_CONFIGURE_AP,
|
||||||
|
NM_INT_STATE_CONFIGURE_DEV,
|
||||||
|
NM_INT_STATE_CONFIGURE_IP,
|
||||||
|
NM_INT_STATE_CONNECTED,
|
||||||
|
NM_INT_STATE_DISCONNECTED
|
||||||
|
} NMIntState;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct NMDbusMethodList NMDbusMethodList;
|
||||||
|
typedef struct NMActRequest NMActRequest;
|
||||||
|
typedef struct NMVPNManager NMVPNManager;
|
||||||
|
typedef struct NMDHCPManager NMDHCPManager;
|
||||||
|
|
||||||
|
#define DHCP_SERVICE_NAME "com.redhat.dhcp"
|
||||||
|
#define DHCP_OBJECT_PATH "/com/redhat/dhcp"
|
||||||
|
|
||||||
typedef struct NMData
|
typedef struct NMData
|
||||||
{
|
{
|
||||||
@@ -44,30 +61,25 @@ typedef struct NMData
|
|||||||
|
|
||||||
NmNetlinkMonitor * netlink_monitor;
|
NmNetlinkMonitor * netlink_monitor;
|
||||||
|
|
||||||
NMNamedManager *named;
|
NMNamedManager * named_manager;
|
||||||
NMVPNManager * vpn_manager;
|
NMVPNManager * vpn_manager;
|
||||||
|
NMDHCPManager * dhcp_manager;
|
||||||
|
|
||||||
DBusConnection * dbus_connection;
|
DBusConnection * dbus_connection;
|
||||||
NMDbusMethodList * nm_methods;
|
NMDbusMethodList * nm_methods;
|
||||||
NMDbusMethodList * device_methods;
|
NMDbusMethodList * device_methods;
|
||||||
NMDbusMethodList * net_methods;
|
NMDbusMethodList * net_methods;
|
||||||
NMDbusMethodList *dhcp_methods;
|
|
||||||
NMDbusMethodList * vpn_methods;
|
NMDbusMethodList * vpn_methods;
|
||||||
|
|
||||||
GMainContext * main_context;
|
GMainContext * main_context;
|
||||||
GMainLoop * main_loop;
|
GMainLoop * main_loop;
|
||||||
gboolean enable_test_devices;
|
gboolean enable_test_devices;
|
||||||
|
|
||||||
guint state_modified_idle_id;
|
guint dev_change_check_idle_id;
|
||||||
|
|
||||||
GSList * dev_list;
|
GSList * dev_list;
|
||||||
GMutex * dev_list_mutex;
|
GMutex * dev_list_mutex;
|
||||||
|
|
||||||
struct NMDevice *active_device;
|
|
||||||
gboolean active_device_locked;
|
|
||||||
|
|
||||||
gboolean forcing_device;
|
|
||||||
|
|
||||||
gboolean scanning_enabled;
|
gboolean scanning_enabled;
|
||||||
gboolean wireless_enabled;
|
gboolean wireless_enabled;
|
||||||
gboolean asleep;
|
gboolean asleep;
|
||||||
@@ -77,6 +89,8 @@ typedef struct NMData
|
|||||||
} NMData;
|
} NMData;
|
||||||
|
|
||||||
|
|
||||||
|
struct NMDevice * nm_get_active_device (NMData *data);
|
||||||
|
|
||||||
struct NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi, const char *iface,
|
struct NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi, const char *iface,
|
||||||
gboolean test_device, NMDeviceType test_device_type);
|
gboolean test_device, NMDeviceType test_device_type);
|
||||||
|
|
||||||
|
@@ -33,9 +33,160 @@
|
|||||||
#include "NetworkManagerAP.h"
|
#include "NetworkManagerAP.h"
|
||||||
#include "NetworkManagerAPList.h"
|
#include "NetworkManagerAPList.h"
|
||||||
#include "NetworkManagerDbus.h"
|
#include "NetworkManagerDbus.h"
|
||||||
|
#include "nm-activation-request.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_policy_activation_finish
|
||||||
|
*
|
||||||
|
* Finishes up activation by sending out dbus signals, which has to happen
|
||||||
|
* on the main thread.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gboolean nm_policy_activation_finish (NMActRequest *req)
|
||||||
|
{
|
||||||
|
NMDevice *dev = NULL;
|
||||||
|
NMAccessPoint *ap = NULL;
|
||||||
|
NMData *data = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (req != NULL, FALSE);
|
||||||
|
|
||||||
|
data = nm_act_request_get_data (req);
|
||||||
|
g_assert (data);
|
||||||
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
/* Tell NetworkManagerInfo to store the MAC address of the active device's AP */
|
||||||
|
if (nm_device_is_wireless (dev))
|
||||||
|
{
|
||||||
|
struct ether_addr addr;
|
||||||
|
NMAccessPoint * ap = nm_act_request_get_ap (req);
|
||||||
|
|
||||||
|
nm_device_get_ap_address (dev, &addr);
|
||||||
|
if (!nm_ap_get_address (ap) || !nm_ethernet_address_is_valid (nm_ap_get_address (ap)))
|
||||||
|
nm_ap_set_address (ap, &addr);
|
||||||
|
|
||||||
|
/* Don't store MAC addresses for non-infrastructure networks */
|
||||||
|
if ((nm_ap_get_mode (ap) == NETWORK_MODE_INFRA) && nm_ethernet_address_is_valid (&addr))
|
||||||
|
nm_dbus_add_network_address (data->dbus_connection, NETWORK_TYPE_ALLOWED, nm_ap_get_essid (ap), &addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
nm_act_request_set_stage (req, ACT_STAGE_ACTIVATED);
|
||||||
|
nm_info ("Activation (%s) successful, device activated.", nm_device_get_iface (dev));
|
||||||
|
|
||||||
|
nm_schedule_state_change_signal_broadcast (data);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_policy_schedule_activation_finish
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void nm_policy_schedule_activation_finish (NMActRequest *req)
|
||||||
|
{
|
||||||
|
GSource * source;
|
||||||
|
NMData * data;
|
||||||
|
NMDevice * dev;
|
||||||
|
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
data = nm_act_request_get_data (req);
|
||||||
|
g_assert (data);
|
||||||
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
source = g_idle_source_new ();
|
||||||
|
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
|
||||||
|
g_source_set_callback (source, (GSourceFunc) nm_policy_activation_finish, req, NULL);
|
||||||
|
g_source_attach (source, data->main_context);
|
||||||
|
g_source_unref (source);
|
||||||
|
nm_info ("Activation (%s) Finish handler scheduled.", nm_device_get_iface (dev));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_policy_activation_failed
|
||||||
|
*
|
||||||
|
* Clean up a failed activation.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static gboolean nm_policy_activation_failed (NMActRequest *req)
|
||||||
|
{
|
||||||
|
NMDevice *dev = NULL;
|
||||||
|
NMAccessPoint *ap = NULL;
|
||||||
|
NMData *data = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (req != NULL, FALSE);
|
||||||
|
|
||||||
|
data = nm_act_request_get_data (req);
|
||||||
|
g_assert (data);
|
||||||
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
if (nm_device_is_wireless (dev))
|
||||||
|
{
|
||||||
|
if ((ap = nm_act_request_get_ap (req)))
|
||||||
|
{
|
||||||
|
/* Only pop up the Network Not Found dialog when its a user-requested access point
|
||||||
|
* that failed, not one that we've automatically found and connected to.
|
||||||
|
*/
|
||||||
|
if (nm_act_request_get_user_requested (req))
|
||||||
|
nm_dbus_schedule_network_not_found_signal (data, nm_ap_get_essid (ap));
|
||||||
|
|
||||||
|
/* Add the AP to the invalid list and force a best ap update */
|
||||||
|
nm_ap_set_invalid (ap, TRUE);
|
||||||
|
nm_ap_list_append_ap (data->invalid_ap_list, ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
nm_info ("Activation (%s) failed for access point (%s)", nm_device_get_iface (dev),
|
||||||
|
ap ? nm_ap_get_essid (ap) : "(none)");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
nm_info ("Activation (%s) failed.", nm_device_get_iface (dev));
|
||||||
|
|
||||||
|
nm_device_deactivate (dev, FALSE);
|
||||||
|
nm_schedule_state_change_signal_broadcast (data);
|
||||||
|
nm_policy_schedule_device_change_check (data);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_policy_schedule_activation_failed
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void nm_policy_schedule_activation_failed (NMActRequest *req)
|
||||||
|
{
|
||||||
|
GSource * source;
|
||||||
|
NMData * data;
|
||||||
|
NMDevice * dev;
|
||||||
|
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
data = nm_act_request_get_data (req);
|
||||||
|
g_assert (data);
|
||||||
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
source = g_idle_source_new ();
|
||||||
|
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
|
||||||
|
g_source_set_callback (source, (GSourceFunc) nm_policy_activation_failed, req, NULL);
|
||||||
|
g_source_attach (source, data->main_context);
|
||||||
|
g_source_unref (source);
|
||||||
|
nm_info ("Activation (%s) failure scheduled...", nm_device_get_iface (dev));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_policy_auto_get_best_device
|
* nm_policy_auto_get_best_device
|
||||||
*
|
*
|
||||||
@@ -43,7 +194,7 @@
|
|||||||
* "locked" on one device at this time.
|
* "locked" on one device at this time.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static NMDevice * nm_policy_auto_get_best_device (NMData *data)
|
static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **ap)
|
||||||
{
|
{
|
||||||
GSList *elt;
|
GSList *elt;
|
||||||
NMDevice *best_wired_dev = NULL;
|
NMDevice *best_wired_dev = NULL;
|
||||||
@@ -53,6 +204,10 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data)
|
|||||||
NMDevice *highest_priority_dev = NULL;
|
NMDevice *highest_priority_dev = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (data != NULL, NULL);
|
g_return_val_if_fail (data != NULL, NULL);
|
||||||
|
g_return_val_if_fail (ap != NULL, NULL);
|
||||||
|
|
||||||
|
if (data->asleep)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
for (elt = data->dev_list; elt != NULL; elt = g_slist_next (elt))
|
for (elt = data->dev_list; elt != NULL; elt = g_slist_next (elt))
|
||||||
{
|
{
|
||||||
@@ -77,9 +232,7 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data)
|
|||||||
if (link_active)
|
if (link_active)
|
||||||
prio += 1;
|
prio += 1;
|
||||||
|
|
||||||
if ( data->active_device
|
if (nm_device_get_act_request (dev) && link_active)
|
||||||
&& (dev == data->active_device)
|
|
||||||
&& link_active)
|
|
||||||
prio += 1;
|
prio += 1;
|
||||||
|
|
||||||
if (prio > best_wired_prio)
|
if (prio > best_wired_prio)
|
||||||
@@ -90,21 +243,6 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data)
|
|||||||
}
|
}
|
||||||
else if ((dev_type == DEVICE_TYPE_WIRELESS_ETHERNET) && data->wireless_enabled)
|
else if ((dev_type == DEVICE_TYPE_WIRELESS_ETHERNET) && data->wireless_enabled)
|
||||||
{
|
{
|
||||||
NMAccessPoint *best_ap = nm_device_get_best_ap (dev);
|
|
||||||
|
|
||||||
/* This deals with the case where the WEP key we have
|
|
||||||
* for an access point is wrong. In that case, the
|
|
||||||
* MAC address of the associated AP will be invalid,
|
|
||||||
* so link_active will be FALSE. However, we still want
|
|
||||||
* to use this card and AP, just need to get the correct
|
|
||||||
* WEP key from the user via NetworkManagerInfo.
|
|
||||||
*/
|
|
||||||
if ( !link_active
|
|
||||||
&& best_ap
|
|
||||||
&& nm_ap_get_encrypted (best_ap)
|
|
||||||
&& !nm_device_need_ap_switch (dev))
|
|
||||||
link_active = TRUE;
|
|
||||||
|
|
||||||
if (link_active)
|
if (link_active)
|
||||||
prio += 1;
|
prio += 1;
|
||||||
|
|
||||||
@@ -113,9 +251,7 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data)
|
|||||||
else
|
else
|
||||||
prio += 1;
|
prio += 1;
|
||||||
|
|
||||||
if ( data->active_device
|
if (nm_device_get_act_request (dev) && link_active)
|
||||||
&& (dev == data->active_device)
|
|
||||||
&& link_active)
|
|
||||||
prio += 3;
|
prio += 3;
|
||||||
|
|
||||||
if (prio > best_wireless_prio)
|
if (prio > best_wireless_prio)
|
||||||
@@ -123,352 +259,163 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data)
|
|||||||
best_wireless_dev = dev;
|
best_wireless_dev = dev;
|
||||||
best_wireless_prio = prio;
|
best_wireless_prio = prio;
|
||||||
}
|
}
|
||||||
if (best_ap)
|
|
||||||
nm_ap_unref (best_ap);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
nm_info ("AUTO: Best wired device = %s, best wireless device = %s (%s)", best_wired_dev ? nm_device_get_iface (best_wired_dev) : "(null)",
|
|
||||||
best_wireless_dev ? nm_device_get_iface (best_wireless_dev) : "(null)", best_wireless_dev ? nm_device_get_essid (best_wireless_dev) : "null" );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (best_wireless_dev || best_wired_dev)
|
|
||||||
{
|
|
||||||
if (best_wired_dev)
|
if (best_wired_dev)
|
||||||
highest_priority_dev = best_wired_dev;
|
highest_priority_dev = best_wired_dev;
|
||||||
else
|
else if (best_wireless_dev)
|
||||||
|
{
|
||||||
highest_priority_dev = best_wireless_dev;
|
highest_priority_dev = best_wireless_dev;
|
||||||
|
*ap = nm_device_get_best_ap (highest_priority_dev);
|
||||||
|
/* If the device doesn't have a "best" ap, then we can't use it */
|
||||||
|
if (!*ap)
|
||||||
|
highest_priority_dev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (highest_priority_dev);
|
nm_info ("AUTO: Best wired device = %s, best wireless device = %s (%s)", best_wired_dev ? nm_device_get_iface (best_wired_dev) : "(null)",
|
||||||
|
best_wireless_dev ? nm_device_get_iface (best_wireless_dev) : "(null)", (best_wireless_dev && *ap) ? nm_ap_get_essid (*ap) : "null" );
|
||||||
|
|
||||||
|
return highest_priority_dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_policy_get_best_device
|
* nm_policy_device_change_check
|
||||||
*
|
|
||||||
* Find the best device to use, taking into account if we are
|
|
||||||
* "locked" on one device or not. That lock may also be cleared
|
|
||||||
* under certain conditions.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static NMDevice * nm_policy_get_best_device (NMDevice *switch_to_dev, NMData *data, gboolean *should_lock_on_activate)
|
|
||||||
{
|
|
||||||
NMDevice *best_dev = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data != NULL, NULL);
|
|
||||||
|
|
||||||
/* Can't lock the active device if you don't have one */
|
|
||||||
if (!data->active_device)
|
|
||||||
data->active_device_locked = FALSE;
|
|
||||||
|
|
||||||
if (should_lock_on_activate)
|
|
||||||
*should_lock_on_activate = FALSE;
|
|
||||||
|
|
||||||
if (data->asleep == TRUE)
|
|
||||||
{
|
|
||||||
data->active_device_locked = FALSE;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Prefer a device forced on us by the user */
|
|
||||||
if (switch_to_dev && !nm_device_get_removed (switch_to_dev))
|
|
||||||
{
|
|
||||||
best_dev = switch_to_dev;
|
|
||||||
*should_lock_on_activate = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine whether we need to clear the active device and unlock it.
|
|
||||||
* This occurs if the best device is removed, for example.
|
|
||||||
*/
|
|
||||||
if (!best_dev && data->active_device_locked)
|
|
||||||
{
|
|
||||||
switch (nm_device_get_type (data->active_device))
|
|
||||||
{
|
|
||||||
/* Wired devices get unlocked only if they have lost their link */
|
|
||||||
case (DEVICE_TYPE_WIRED_ETHERNET):
|
|
||||||
if (nm_device_has_active_link (data->active_device))
|
|
||||||
best_dev = data->active_device;
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Wireless devices get unlocked if the user removes the card
|
|
||||||
* or turns wireless off.
|
|
||||||
*/
|
|
||||||
case (DEVICE_TYPE_WIRELESS_ETHERNET):
|
|
||||||
if (data->wireless_enabled == TRUE)
|
|
||||||
best_dev = data->active_device;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fall back to automatic device picking */
|
|
||||||
if (!best_dev)
|
|
||||||
{
|
|
||||||
data->active_device_locked = FALSE;
|
|
||||||
best_dev = nm_policy_auto_get_best_device (data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Ensure we support this driver */
|
|
||||||
if (best_dev && (nm_device_get_driver_support_level (best_dev) == NM_DRIVER_UNSUPPORTED))
|
|
||||||
{
|
|
||||||
nm_warning ("nm_policy_get_best_device(): tried to switch to unsupported device '%s'!\n", nm_device_get_iface (best_dev));
|
|
||||||
best_dev = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (best_dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_policy_activation_finish
|
|
||||||
*
|
|
||||||
* Finishes up activation by sending out dbus signals, which has to happen
|
|
||||||
* on the main thread.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
gboolean nm_policy_activation_finish (gpointer user_data)
|
|
||||||
{
|
|
||||||
NMActivationResult *result = (NMActivationResult *)user_data;
|
|
||||||
NMDevice *dev = NULL;
|
|
||||||
NMAccessPoint *failed_ap = NULL;
|
|
||||||
NMData *data = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (result != NULL, FALSE);
|
|
||||||
|
|
||||||
if (!(dev = result->dev))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
failed_ap = result->failed_ap;
|
|
||||||
|
|
||||||
if (!(data = nm_device_get_app_data (dev)))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
switch (result->result)
|
|
||||||
{
|
|
||||||
case DEVICE_NOW_ACTIVE:
|
|
||||||
nm_dbus_signal_device_status_change (data->dbus_connection, dev, result->result);
|
|
||||||
/* Tell NetworkManagerInfo to store the MAC address of the active device's AP */
|
|
||||||
if (nm_device_is_wireless (dev))
|
|
||||||
{
|
|
||||||
NMAccessPoint *ap = NULL;
|
|
||||||
|
|
||||||
if ((ap = nm_device_get_best_ap (dev)))
|
|
||||||
{
|
|
||||||
struct ether_addr addr;
|
|
||||||
|
|
||||||
nm_device_get_ap_address (dev, &addr);
|
|
||||||
if (!nm_ap_get_address (ap) || !nm_ethernet_address_is_valid (nm_ap_get_address (ap)))
|
|
||||||
nm_ap_set_address (ap, &addr);
|
|
||||||
|
|
||||||
/* Don't store MAC addresses for non-infrastructure networks */
|
|
||||||
if ((nm_ap_get_mode (ap) == NETWORK_MODE_INFRA) && nm_ethernet_address_is_valid (&addr))
|
|
||||||
nm_dbus_add_network_address (data->dbus_connection, NETWORK_TYPE_ALLOWED, nm_ap_get_essid (ap), &addr);
|
|
||||||
|
|
||||||
nm_ap_unref (ap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nm_info ("Activation (%s) successful, device activated.", nm_device_get_iface (data->active_device));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DEVICE_ACTIVATION_FAILED:
|
|
||||||
nm_dbus_signal_device_status_change (data->dbus_connection, dev, result->result);
|
|
||||||
if (nm_device_is_wireless (dev))
|
|
||||||
{
|
|
||||||
if (failed_ap)
|
|
||||||
{
|
|
||||||
/* Add the AP to the invalid list and force a best ap update */
|
|
||||||
nm_ap_list_append_ap (data->invalid_ap_list, failed_ap);
|
|
||||||
nm_device_update_best_ap (dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
nm_info ("Activation (%s) failed for access point (%s)", nm_device_get_iface (dev),
|
|
||||||
failed_ap ? nm_ap_get_essid (failed_ap) : "(none)");
|
|
||||||
|
|
||||||
/* Failed AP got reffed by nm_device_get_best_ap() during activation,
|
|
||||||
* must unref it here.
|
|
||||||
*/
|
|
||||||
if (failed_ap)
|
|
||||||
nm_ap_unref (failed_ap);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
nm_info ("Activation (%s) failed.", nm_device_get_iface (dev));
|
|
||||||
if (data->active_device == dev)
|
|
||||||
{
|
|
||||||
nm_device_unref (dev);
|
|
||||||
data->active_device = NULL;
|
|
||||||
}
|
|
||||||
nm_device_deactivate (dev, FALSE);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DEVICE_ACTIVATION_CANCELED:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
nm_schedule_state_change_signal_broadcast (data);
|
|
||||||
nm_policy_schedule_state_update (data);
|
|
||||||
|
|
||||||
out:
|
|
||||||
nm_device_unref (dev);
|
|
||||||
g_free (result);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct NMStateUpdateData
|
|
||||||
{
|
|
||||||
NMDevice *switch_to_dev;
|
|
||||||
NMData *app_data;
|
|
||||||
} NMStateUpdateData;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_policy_state_update
|
|
||||||
*
|
*
|
||||||
* Figures out which interface to switch the active
|
* Figures out which interface to switch the active
|
||||||
* network connection to if our global network state has changed.
|
* network connection to if our global network state has changed.
|
||||||
* Global network state changes are triggered by:
|
* Global network state changes are triggered by:
|
||||||
* 1) insertion/deletion of interfaces
|
* 1) insertion/deletion of interfaces
|
||||||
* 2) link state change of an interface
|
* 2) link state change of an interface
|
||||||
|
* 3) wireless network topology changes
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static gboolean nm_policy_state_update (gpointer user_data)
|
static gboolean nm_policy_device_change_check (NMData *data)
|
||||||
{
|
{
|
||||||
NMStateUpdateData *cb_data = (NMStateUpdateData *)user_data;
|
NMAccessPoint * ap = NULL;
|
||||||
NMData *app_data;
|
NMDevice * new_dev = NULL;
|
||||||
|
NMDevice * old_dev = NULL;
|
||||||
g_return_val_if_fail (cb_data != NULL, FALSE);
|
|
||||||
|
|
||||||
app_data = cb_data->app_data;
|
|
||||||
if (!app_data)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
app_data->state_modified_idle_id = 0;
|
|
||||||
|
|
||||||
/* If we're currently waiting for a force-device operation to complete, don't try
|
|
||||||
* to change devices. We'll be notified of what device to switch to explicitly
|
|
||||||
* when the force-device operation completes.
|
|
||||||
*/
|
|
||||||
if (!cb_data->switch_to_dev && app_data->forcing_device)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
app_data->forcing_device = FALSE;
|
|
||||||
|
|
||||||
if (nm_try_acquire_mutex (app_data->dev_list_mutex, __FUNCTION__))
|
|
||||||
{
|
|
||||||
gboolean should_lock_on_activate = FALSE;
|
|
||||||
gboolean do_switch = FALSE;
|
gboolean do_switch = FALSE;
|
||||||
NMDevice *best_dev = NULL;
|
|
||||||
|
|
||||||
if ((best_dev = nm_policy_get_best_device (cb_data->switch_to_dev, app_data, &should_lock_on_activate)))
|
g_return_val_if_fail (data != NULL, FALSE);
|
||||||
nm_device_ref (best_dev);
|
|
||||||
|
|
||||||
/* Figure out if we need to change devices or wireless networks */
|
data->dev_change_check_idle_id = 0;
|
||||||
if (best_dev != app_data->active_device)
|
|
||||||
|
old_dev = nm_get_active_device (data);
|
||||||
|
|
||||||
|
if (!nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* Don't interrupt a currently activating device. */
|
||||||
|
if (old_dev && nm_device_is_activating (old_dev))
|
||||||
{
|
{
|
||||||
if (best_dev)
|
nm_info ("Old device '%s' activating, won't change.", nm_device_get_iface (old_dev));
|
||||||
nm_info (" SWITCH: best device changed");
|
goto out;
|
||||||
else
|
|
||||||
nm_info (" SWITCH: old device no longer good, but no better device was available");
|
|
||||||
do_switch = TRUE; /* Device changed */
|
|
||||||
}
|
|
||||||
else if (best_dev)
|
|
||||||
{
|
|
||||||
if (nm_device_is_wireless (best_dev) && !nm_device_is_activating (best_dev) && nm_device_need_ap_switch (best_dev))
|
|
||||||
{
|
|
||||||
nm_info (" SWITCH: need to associate with new access point or create a wireless network.");
|
|
||||||
do_switch = TRUE;
|
|
||||||
}
|
|
||||||
else if (!nm_device_is_activating (best_dev) && !nm_device_get_ip4_address (best_dev))
|
|
||||||
{
|
|
||||||
nm_info (" SWITCH: need to get an IP address.");
|
|
||||||
do_switch = TRUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_switch)
|
new_dev = nm_policy_auto_get_best_device (data, &ap);
|
||||||
{
|
|
||||||
/* Deactivate the old device */
|
|
||||||
if (app_data->active_device)
|
|
||||||
{
|
|
||||||
nm_device_deactivate (app_data->active_device, FALSE);
|
|
||||||
nm_device_unref (app_data->active_device);
|
|
||||||
app_data->active_device = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (best_dev)
|
/* Four cases here:
|
||||||
{
|
*
|
||||||
/* Begin activation on the new device */
|
* 1) old device is NULL, new device is NULL - we aren't currently connected to anything, and we
|
||||||
nm_device_ref (best_dev);
|
* can't find anything to connect to. Do nothing.
|
||||||
app_data->active_device = best_dev;
|
*
|
||||||
nm_device_activation_schedule_start (app_data->active_device);
|
* 2) old device is NULL, new device is good - we aren't currenlty connected to anything, but
|
||||||
|
* we have something we can connect to. Connect to it.
|
||||||
/* nm_policy_get_best_device() signals us that the user forced
|
*
|
||||||
* a device upon us and that we should lock the active device.
|
* 3) old device is good, new device is NULL - have a current connection, but it's no good since
|
||||||
|
* auto device picking didn't come up with the save device. Terminate current connection.
|
||||||
|
*
|
||||||
|
* 4) old device is good, new device is good - have a current connection, and auto device picking
|
||||||
|
* came up with a device too. More considerations:
|
||||||
|
* a) different devices? activate new device
|
||||||
|
* b) same device, different access points? activate new device
|
||||||
|
* c) same device, same access point? do nothing
|
||||||
*/
|
*/
|
||||||
if (should_lock_on_activate)
|
|
||||||
app_data->active_device_locked = TRUE;
|
if (!old_dev && !new_dev)
|
||||||
|
{
|
||||||
|
/* Do nothing, wait for something like link-state to change, or an access point to be found */
|
||||||
|
}
|
||||||
|
else if (!old_dev && new_dev)
|
||||||
|
{
|
||||||
|
/* Activate new device */
|
||||||
|
nm_info ("SWITCH: no current connection, found better connection '%s'.", nm_device_get_iface (new_dev));
|
||||||
|
do_switch = TRUE;
|
||||||
|
}
|
||||||
|
else if (old_dev && !new_dev)
|
||||||
|
{
|
||||||
|
/* Terminate current connection */
|
||||||
|
nm_info ("SWITCH: terminating current connection '%s' because it's no longer valid.", nm_device_get_iface (old_dev));
|
||||||
|
nm_device_deactivate (old_dev, FALSE);
|
||||||
|
do_switch = TRUE;
|
||||||
|
}
|
||||||
|
else if (old_dev && new_dev)
|
||||||
|
{
|
||||||
|
if (old_dev != new_dev)
|
||||||
|
{
|
||||||
|
nm_info ("SWITCH: found better connection '%s' than current connection '%s'.", nm_device_get_iface (new_dev), nm_device_get_iface (old_dev));
|
||||||
|
do_switch = TRUE;
|
||||||
|
}
|
||||||
|
else if ((old_dev == new_dev) && nm_device_is_wireless (new_dev))
|
||||||
|
{
|
||||||
|
NMAccessPoint *old_ap = nm_act_request_get_ap (nm_device_get_act_request (old_dev));
|
||||||
|
|
||||||
|
/* Stick with the current access point unless we don't have a link to it anymore */
|
||||||
|
|
||||||
|
/* Schedule new activation if the currently associated access point is not the "best" one */
|
||||||
|
if (strcmp (nm_ap_get_essid (old_ap), nm_ap_get_essid (ap)) != 0)
|
||||||
|
{
|
||||||
|
nm_info ("SWITCH: found better connection '%s/%s' than current connection '%s/%s'.", nm_device_get_iface (new_dev), nm_ap_get_essid (ap),
|
||||||
|
nm_device_get_iface (old_dev), nm_ap_get_essid (old_ap));
|
||||||
|
do_switch = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (best_dev)
|
if (do_switch && (nm_device_is_wired (new_dev) || (nm_device_is_wireless (new_dev) && ap)))
|
||||||
nm_device_unref (best_dev);
|
{
|
||||||
|
NMActRequest * act_req = NULL;
|
||||||
|
|
||||||
nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
|
if ((act_req = nm_act_request_new (data, new_dev, ap, FALSE)))
|
||||||
|
|
||||||
|
{
|
||||||
|
nm_info ("Will activate connection '%s%s%s'.", nm_device_get_iface (new_dev), ap ? "/" : "", ap ? nm_ap_get_essid (ap) : "");
|
||||||
|
nm_policy_schedule_device_activation (act_req);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ap)
|
||||||
|
nm_ap_unref (ap);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
g_free (cb_data);
|
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
|
||||||
return (FALSE);
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_policy_schedule_state_update
|
* nm_policy_schedule_device_change_check
|
||||||
*
|
*
|
||||||
* Queue up an idle handler to deal with state changes.
|
* Queue up an idle handler to deal with state changes that could
|
||||||
|
* cause us to activate a different device or wireless network.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void nm_policy_schedule_state_update (NMData *app_data)
|
void nm_policy_schedule_device_change_check (NMData *data)
|
||||||
{
|
|
||||||
g_return_if_fail (app_data != NULL);
|
|
||||||
|
|
||||||
nm_policy_schedule_device_switch (NULL, app_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_policy_schedule_device_switch
|
|
||||||
*
|
|
||||||
* Queue up an idle handler to deal with state changes when we want
|
|
||||||
* to force a particular device to be the active device.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void nm_policy_schedule_device_switch (NMDevice *switch_to_dev, NMData *app_data)
|
|
||||||
{
|
{
|
||||||
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
|
||||||
|
|
||||||
g_return_if_fail (app_data != NULL);
|
g_return_if_fail (data != NULL);
|
||||||
|
|
||||||
g_static_mutex_lock (&mutex);
|
g_static_mutex_lock (&mutex);
|
||||||
|
|
||||||
/* Don't queue the idle handler if switch_to_dev is NULL and there's already
|
if (data->dev_change_check_idle_id == 0)
|
||||||
* an idle handler queued. Always queue the idle handler if we were passed
|
|
||||||
* a switch_to_dev.
|
|
||||||
*/
|
|
||||||
if (switch_to_dev || (app_data->state_modified_idle_id == 0))
|
|
||||||
{
|
{
|
||||||
GSource * source = g_idle_source_new ();
|
GSource * source = g_idle_source_new ();
|
||||||
NMStateUpdateData *cb_data = g_malloc0 (sizeof (NMStateUpdateData));
|
|
||||||
|
|
||||||
cb_data->switch_to_dev = switch_to_dev;
|
g_source_set_callback (source, (GSourceFunc) nm_policy_device_change_check, data, NULL);
|
||||||
cb_data->app_data = app_data;
|
data->dev_change_check_idle_id = g_source_attach (source, data->main_context);
|
||||||
|
|
||||||
g_source_set_callback (source, nm_policy_state_update, cb_data, NULL);
|
|
||||||
app_data->state_modified_idle_id = g_source_attach (source, app_data->main_context);
|
|
||||||
g_source_unref (source);
|
g_source_unref (source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,6 +423,66 @@ void nm_policy_schedule_device_switch (NMDevice *switch_to_dev, NMData *app_data
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_policy_device_activation
|
||||||
|
*
|
||||||
|
* Handle device activation, shutting down all other devices and starting
|
||||||
|
* activation on the requested device.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static gboolean nm_policy_device_activation (NMActRequest *req)
|
||||||
|
{
|
||||||
|
NMData * data;
|
||||||
|
NMDevice * new_dev = NULL;
|
||||||
|
NMDevice * old_dev = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (req != NULL, FALSE);
|
||||||
|
|
||||||
|
data = nm_act_request_get_data (req);
|
||||||
|
g_assert (data);
|
||||||
|
|
||||||
|
if ((old_dev = nm_get_active_device (data)))
|
||||||
|
nm_device_deactivate (old_dev, FALSE);
|
||||||
|
|
||||||
|
new_dev = nm_act_request_get_dev (req);
|
||||||
|
if (nm_device_is_activating (new_dev))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
nm_device_activation_start (req);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_policy_schedule_device_activation
|
||||||
|
*
|
||||||
|
* Activate a particular device (and possibly access point)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void nm_policy_schedule_device_activation (NMActRequest *req)
|
||||||
|
{
|
||||||
|
GSource * source;
|
||||||
|
NMData * data;
|
||||||
|
NMDevice * dev;
|
||||||
|
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
data = nm_act_request_get_data (req);
|
||||||
|
g_assert (data);
|
||||||
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
source = g_idle_source_new ();
|
||||||
|
g_source_set_priority (source, G_PRIORITY_HIGH_IDLE);
|
||||||
|
g_source_set_callback (source, (GSourceFunc) nm_policy_device_activation, req, NULL);
|
||||||
|
g_source_attach (source, data->main_context);
|
||||||
|
g_source_unref (source);
|
||||||
|
nm_info ("Device %s activation scheduled...", nm_device_get_iface (dev));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean allowed_list_update_pending = FALSE;
|
static gboolean allowed_list_update_pending = FALSE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -546,9 +553,8 @@ static gboolean device_list_update_pending = FALSE;
|
|||||||
* allowed wireless networks.
|
* allowed wireless networks.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static gboolean nm_policy_device_list_update_from_allowed_list (gpointer user_data)
|
static gboolean nm_policy_device_list_update_from_allowed_list (NMData *data)
|
||||||
{
|
{
|
||||||
NMData *data = (NMData *)user_data;
|
|
||||||
GSList * elt;
|
GSList * elt;
|
||||||
|
|
||||||
device_list_update_pending = FALSE;
|
device_list_update_pending = FALSE;
|
||||||
@@ -560,6 +566,8 @@ static gboolean nm_policy_device_list_update_from_allowed_list (gpointer user_da
|
|||||||
NMDevice *dev = (NMDevice *)(elt->data);
|
NMDevice *dev = (NMDevice *)(elt->data);
|
||||||
if (nm_device_is_wireless (dev))
|
if (nm_device_is_wireless (dev))
|
||||||
{
|
{
|
||||||
|
NMAccessPoint *best_ap;
|
||||||
|
|
||||||
if (nm_device_get_supports_wireless_scan (dev))
|
if (nm_device_get_supports_wireless_scan (dev))
|
||||||
{
|
{
|
||||||
/* Once we have the list, copy in any relevant information from our Allowed list and fill
|
/* Once we have the list, copy in any relevant information from our Allowed list and fill
|
||||||
@@ -576,23 +584,9 @@ static gboolean nm_policy_device_list_update_from_allowed_list (gpointer user_da
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the active device doesn't have a best_ap already, make it update to
|
nm_policy_schedule_device_change_check (data);
|
||||||
* get the new data.
|
|
||||||
*/
|
|
||||||
if ( data->active_device
|
|
||||||
&& nm_device_is_activating (data->active_device)
|
|
||||||
&& nm_device_is_wireless (data->active_device))
|
|
||||||
{
|
|
||||||
NMAccessPoint *best_ap;
|
|
||||||
|
|
||||||
best_ap = nm_device_get_best_ap (data->active_device);
|
return FALSE;
|
||||||
if (!best_ap)
|
|
||||||
nm_device_update_best_ap (data->active_device);
|
|
||||||
else
|
|
||||||
nm_ap_unref (best_ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -25,22 +25,16 @@
|
|||||||
#include "NetworkManager.h"
|
#include "NetworkManager.h"
|
||||||
#include "NetworkManagerDevice.h"
|
#include "NetworkManagerDevice.h"
|
||||||
#include "NetworkManagerDbus.h"
|
#include "NetworkManagerDbus.h"
|
||||||
|
#include "nm-activation-request.h"
|
||||||
|
|
||||||
typedef struct
|
void nm_policy_schedule_device_change_check (NMData *data);
|
||||||
{
|
|
||||||
NMDevice *dev;
|
|
||||||
NMAccessPoint *failed_ap;
|
|
||||||
DeviceStatus result;
|
|
||||||
} NMActivationResult;
|
|
||||||
|
|
||||||
|
void nm_policy_schedule_device_activation (NMActRequest *req);
|
||||||
void nm_policy_schedule_state_update (NMData *app_data);
|
|
||||||
|
|
||||||
void nm_policy_schedule_device_switch (NMDevice *dev, NMData *app_data);
|
|
||||||
|
|
||||||
void nm_policy_schedule_allowed_ap_list_update (NMData *app_data);
|
void nm_policy_schedule_allowed_ap_list_update (NMData *app_data);
|
||||||
void nm_policy_schedule_device_ap_lists_update_from_allowed (NMData *app_data);
|
void nm_policy_schedule_device_ap_lists_update_from_allowed (NMData *app_data);
|
||||||
|
|
||||||
gboolean nm_policy_activation_finish (gpointer user_data);
|
void nm_policy_schedule_activation_finish (NMActRequest *req);
|
||||||
|
void nm_policy_schedule_activation_failed (NMActRequest *req);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -204,8 +204,8 @@ gboolean nm_system_device_set_from_ip4_config (NMDevice *dev)
|
|||||||
sleep (1);
|
sleep (1);
|
||||||
nm_system_device_set_ip4_route (dev, nm_ip4_config_get_gateway (config), 0, 0);
|
nm_system_device_set_ip4_route (dev, nm_ip4_config_get_gateway (config), 0, 0);
|
||||||
|
|
||||||
set_nameservers (app_data->named, config);
|
set_nameservers (app_data->named_manager, config);
|
||||||
set_search_domains (app_data->named, config);
|
set_search_domains (app_data->named_manager, config);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -544,11 +544,11 @@ static gboolean nm_system_device_set_ip4_route_with_iface (NMDevice *dev, const
|
|||||||
if (ioctl (nm_dev_sock_get_fd (sk), SIOCADDRT, &rtent) == 0 )
|
if (ioctl (nm_dev_sock_get_fd (sk), SIOCADDRT, &rtent) == 0 )
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
else
|
else
|
||||||
nm_warning ("nm_system_device_set_ip4_default_route (%s): failed to set IPv4 default route! errno = %d", iface, errno);
|
nm_warning ("nm_system_device_set_ip4_route_with_iface (%s): failed to set IPv4 default route! errno = %d", iface, errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
nm_warning ("nm_system_device_set_ip4_default_route (%s): failed to set IPv4 default route! errno = %d", iface, errno);
|
nm_warning ("nm_system_device_set_ip4_route_with_iface (%s): failed to set IPv4 default route! errno = %d", iface, errno);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
|
@@ -327,7 +327,7 @@ int nm_null_safe_strcmp (const char *s1, const char *s2)
|
|||||||
* Compares an ethernet address against known invalid addresses.
|
* Compares an ethernet address against known invalid addresses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
gboolean nm_ethernet_address_is_valid (struct ether_addr *test_addr)
|
gboolean nm_ethernet_address_is_valid (const struct ether_addr *test_addr)
|
||||||
{
|
{
|
||||||
gboolean valid = FALSE;
|
gboolean valid = FALSE;
|
||||||
struct ether_addr invalid_addr1 = { {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} };
|
struct ether_addr invalid_addr1 = { {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} };
|
||||||
@@ -678,9 +678,7 @@ static void nm_v_wait_for_completion_or_timeout(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
/* #define NM_SLEEP_DEBUG */
|
||||||
#define NM_SLEEP_DEBUG
|
|
||||||
#endif
|
|
||||||
#ifdef NM_SLEEP_DEBUG
|
#ifdef NM_SLEEP_DEBUG
|
||||||
syslog (LOG_INFO, "sleeping or %d usecs", interval_usecs);
|
syslog (LOG_INFO, "sleeping or %d usecs", interval_usecs);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -56,7 +56,7 @@ void nm_print_open_socks (void);
|
|||||||
|
|
||||||
int nm_null_safe_strcmp (const char *s1, const char *s2);
|
int nm_null_safe_strcmp (const char *s1, const char *s2);
|
||||||
|
|
||||||
gboolean nm_ethernet_address_is_valid (struct ether_addr *test_addr);
|
gboolean nm_ethernet_address_is_valid (const struct ether_addr *test_addr);
|
||||||
|
|
||||||
void nm_dispose_scan_results (wireless_scan *result_list);
|
void nm_dispose_scan_results (wireless_scan *result_list);
|
||||||
|
|
||||||
|
57
src/autoip.c
57
src/autoip.c
@@ -29,7 +29,6 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "../dhcpcd/arp.h"
|
|
||||||
#include "NetworkManager.h"
|
#include "NetworkManager.h"
|
||||||
#include "NetworkManagerDevice.h"
|
#include "NetworkManagerDevice.h"
|
||||||
#include "NetworkManagerMain.h"
|
#include "NetworkManagerMain.h"
|
||||||
@@ -48,6 +47,31 @@
|
|||||||
|
|
||||||
#define FAILURE_TIMEOUT 14
|
#define FAILURE_TIMEOUT 14
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct EtherHeader
|
||||||
|
{
|
||||||
|
u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */
|
||||||
|
u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */
|
||||||
|
u_int16_t ether_type; /* packet type ID field */
|
||||||
|
} __attribute__((packed)) EtherHeader;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct ARPMessage
|
||||||
|
{
|
||||||
|
EtherHeader ethhdr;
|
||||||
|
u_short htype; /* hardware type (must be ARPHRD_ETHER) */
|
||||||
|
u_short ptype; /* protocol type (must be ETHERTYPE_IP) */
|
||||||
|
u_char hlen; /* hardware address length (must be 6) */
|
||||||
|
u_char plen; /* protocol address length (must be 4) */
|
||||||
|
u_short operation; /* ARP opcode */
|
||||||
|
u_char sHaddr[ETH_ALEN]; /* sender's hardware address */
|
||||||
|
u_char sInaddr[4]; /* sender's IP address */
|
||||||
|
u_char tHaddr[ETH_ALEN]; /* target's hardware address */
|
||||||
|
u_char tInaddr[4]; /* target's IP address */
|
||||||
|
u_char pad[18]; /* pad for min. Ethernet payload (60 bytes) */
|
||||||
|
} __attribute__((packed)) ARPMessage;
|
||||||
|
|
||||||
|
|
||||||
// Times here are in seconds
|
// Times here are in seconds
|
||||||
#define ARP_DEFAULT_LEASETIME 100
|
#define ARP_DEFAULT_LEASETIME 100
|
||||||
|
|
||||||
@@ -77,7 +101,7 @@ static gboolean arp(int fd, struct sockaddr *saddr, int op,
|
|||||||
struct ether_addr *source_addr, struct in_addr source_ip,
|
struct ether_addr *source_addr, struct in_addr source_ip,
|
||||||
struct ether_addr *target_addr, struct in_addr target_ip)
|
struct ether_addr *target_addr, struct in_addr target_ip)
|
||||||
{
|
{
|
||||||
struct arpMessage p;
|
struct ARPMessage p;
|
||||||
gboolean success = FALSE;
|
gboolean success = FALSE;
|
||||||
|
|
||||||
memset (&p, 0, sizeof (p));
|
memset (&p, 0, sizeof (p));
|
||||||
@@ -104,7 +128,7 @@ static gboolean arp(int fd, struct sockaddr *saddr, int op,
|
|||||||
else
|
else
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
|
|
||||||
return (success);
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -135,6 +159,15 @@ static int timeval_subtract (struct timeval *result, struct timeval *x, struct t
|
|||||||
/* Return 1 if result is negative. */
|
/* Return 1 if result is negative. */
|
||||||
return x->tv_sec < y->tv_sec;
|
return x->tv_sec < y->tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum return_vals
|
||||||
|
{
|
||||||
|
RET_ERROR = 0,
|
||||||
|
RET_TIMEOUT,
|
||||||
|
RET_CEASED,
|
||||||
|
RET_SUCCESS
|
||||||
|
};
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* "timeout" should be the future point in time when we wish to stop
|
/* "timeout" should be the future point in time when we wish to stop
|
||||||
* checking for data on the socket.
|
* checking for data on the socket.
|
||||||
@@ -159,21 +192,21 @@ static int peekfd (NMDevice *dev, int sk, struct timeval *timeout)
|
|||||||
FD_SET (sk, &fs);
|
FD_SET (sk, &fs);
|
||||||
|
|
||||||
if (select (sk+1, &fs, NULL, NULL, &wait) == -1)
|
if (select (sk+1, &fs, NULL, NULL, &wait) == -1)
|
||||||
return RET_DHCP_ERROR;
|
return RET_ERROR;
|
||||||
if (FD_ISSET(sk, &fs))
|
if (FD_ISSET(sk, &fs))
|
||||||
return RET_DHCP_SUCCESS;
|
return RET_SUCCESS;
|
||||||
if (nm_device_activation_should_cancel (dev))
|
if (nm_device_activation_should_cancel (dev))
|
||||||
return RET_DHCP_CEASED;
|
return RET_CEASED;
|
||||||
gettimeofday (&now, NULL);
|
gettimeofday (&now, NULL);
|
||||||
};
|
};
|
||||||
return RET_DHCP_TIMEOUT;
|
return RET_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
||||||
{
|
{
|
||||||
struct sockaddr saddr;
|
struct sockaddr saddr;
|
||||||
arpMessage p;
|
ARPMessage p;
|
||||||
struct ether_addr addr;
|
struct ether_addr addr;
|
||||||
struct in_addr ip = {0};
|
struct in_addr ip = {0};
|
||||||
NMSock *sk;
|
NMSock *sk;
|
||||||
@@ -205,7 +238,7 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
nm_device_get_hw_address (dev, &(addr.ether_addr_octet[0]));
|
nm_device_get_hw_address (dev, &addr);
|
||||||
|
|
||||||
/* initialize pseudo random selection of IP addresses */
|
/* initialize pseudo random selection of IP addresses */
|
||||||
srandom ( (addr.ether_addr_octet[ETHER_ADDR_LEN-4] << 24) |
|
srandom ( (addr.ether_addr_octet[ETHER_ADDR_LEN-4] << 24) |
|
||||||
@@ -265,11 +298,11 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
|||||||
|
|
||||||
nm_info ("autoip: Waiting for reply...");
|
nm_info ("autoip: Waiting for reply...");
|
||||||
err = peekfd (dev, nm_dev_sock_get_fd (sk), &timeout);
|
err = peekfd (dev, nm_dev_sock_get_fd (sk), &timeout);
|
||||||
if ((err == RET_DHCP_ERROR) || (err == RET_DHCP_CEASED))
|
if ((err == RET_ERROR) || (err == RET_CEASED))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* There's some data waiting for us */
|
/* There's some data waiting for us */
|
||||||
if (err == RET_DHCP_SUCCESS)
|
if (err == RET_SUCCESS)
|
||||||
{
|
{
|
||||||
nm_info ("autoip: Got some data to check for reply packet.");
|
nm_info ("autoip: Got some data to check for reply packet.");
|
||||||
|
|
||||||
@@ -312,5 +345,5 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
nm_dev_sock_close (sk);
|
nm_dev_sock_close (sk);
|
||||||
return (success);
|
return success;
|
||||||
}
|
}
|
||||||
|
@@ -375,10 +375,12 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev)
|
|||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
char *addr;
|
char *addr;
|
||||||
|
struct ether_addr hw_addr;
|
||||||
unsigned char eui[8];
|
unsigned char eui[8];
|
||||||
|
|
||||||
nm_device_get_hw_address(dev, &eui[0]);
|
nm_device_get_hw_address(dev, &hw_addr);
|
||||||
|
|
||||||
|
memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet));
|
||||||
memmove(eui+5, eui+3, 3);
|
memmove(eui+5, eui+3, 3);
|
||||||
eui[3] = 0xff;
|
eui[3] = 0xff;
|
||||||
eui[4] = 0xfe;
|
eui[4] = 0xfe;
|
||||||
|
@@ -238,7 +238,6 @@ void nm_system_flush_arp_cache (void)
|
|||||||
*/
|
*/
|
||||||
void nm_system_kill_all_dhcp_daemons (void)
|
void nm_system_kill_all_dhcp_daemons (void)
|
||||||
{
|
{
|
||||||
nm_spawn_process ("/usr/bin/killall -q dhclient");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -311,10 +310,12 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev)
|
|||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
char *addr;
|
char *addr;
|
||||||
|
struct ether_addr hw_addr;
|
||||||
unsigned char eui[8];
|
unsigned char eui[8];
|
||||||
|
|
||||||
nm_device_get_hw_address(dev, &eui[0]);
|
nm_device_get_hw_address(dev, &hw_addr);
|
||||||
|
|
||||||
|
memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet));
|
||||||
memmove (eui+5, eui+3, 3);
|
memmove (eui+5, eui+3, 3);
|
||||||
eui[3] = 0xff;
|
eui[3] = 0xff;
|
||||||
eui[4] = 0xfe;
|
eui[4] = 0xfe;
|
||||||
|
@@ -1,3 +1,2 @@
|
|||||||
Makefile
|
Makefile
|
||||||
Makefile.in
|
Makefile.in
|
||||||
dhcp_test
|
|
20
src/dhcp-manager/Makefile.am
Normal file
20
src/dhcp-manager/Makefile.am
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
INCLUDES = -I${top_srcdir} -I${top_srcdir}/utils -I${top_srcdir}/src -I${top_srcdir}/src/named-manager
|
||||||
|
|
||||||
|
noinst_LTLIBRARIES = libdhcp-manager.la
|
||||||
|
|
||||||
|
libdhcp_manager_la_SOURCES = nm-dhcp-manager.c \
|
||||||
|
nm-dhcp-manager.h
|
||||||
|
|
||||||
|
libdhcp_manager_la_CPPFLAGS = $(DBUS_CFLAGS) \
|
||||||
|
$(GTHREAD_CFLAGS) \
|
||||||
|
$(HAL_CFLAGS) \
|
||||||
|
-g \
|
||||||
|
-Wall \
|
||||||
|
-DDBUS_API_SUBJECT_TO_CHANGE \
|
||||||
|
-DG_DISABLE_DEPRECATED \
|
||||||
|
-DBINDIR=\"$(bindir)\" \
|
||||||
|
-DDATADIR=\"$(datadir)\" \
|
||||||
|
-DSYSCONFDIR=\"$(sysconfdir)\"
|
||||||
|
|
||||||
|
|
||||||
|
libdhcp_manager_la_LIBADD = $(DBUS_LIBS) $(GTHREAD_LIBS)
|
664
src/dhcp-manager/nm-dhcp-manager.c
Normal file
664
src/dhcp-manager/nm-dhcp-manager.c
Normal file
@@ -0,0 +1,664 @@
|
|||||||
|
/* nm-dhcp-manager.c - Handle the DHCP daemon for NetworkManager
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 Dan Williams
|
||||||
|
*
|
||||||
|
* 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, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <dbus/dbus.h>
|
||||||
|
#include "nm-dhcp-manager.h"
|
||||||
|
#include "NetworkManagerDevice.h"
|
||||||
|
#include "NetworkManagerPolicy.h"
|
||||||
|
#include "nm-activation-request.h"
|
||||||
|
#include "nm-utils.h"
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define DHCP_DAEMON_PROGRAM "/sbin/dhcdbd"
|
||||||
|
|
||||||
|
struct NMDHCPManager
|
||||||
|
{
|
||||||
|
NMData * data;
|
||||||
|
gboolean running;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
char *get_dhcp_match_string (const char *owner)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (owner != NULL, NULL);
|
||||||
|
|
||||||
|
return g_strdup_printf ("type='signal',interface='" DHCP_SERVICE_NAME ".state',sender='%s'", owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean state_is_bound (guint8 state)
|
||||||
|
{
|
||||||
|
if ( (state == 2) /* BOUND */
|
||||||
|
|| (state == 3) /* RENEW */
|
||||||
|
|| (state == 4) /* REBOOT */
|
||||||
|
|| (state == 5)) /* REBIND */
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean state_is_down (guint8 state)
|
||||||
|
{
|
||||||
|
if ( (state == 0) /* NBI */
|
||||||
|
|| (state == 11) /* RELEASE */
|
||||||
|
|| (state == 13) /* ABEND */
|
||||||
|
|| (state == 14)) /* END */
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_dhcp_manager_exec_daemon
|
||||||
|
*
|
||||||
|
* Launch the DHCP daemon.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static gboolean nm_dhcp_manager_exec_daemon (NMDHCPManager *manager)
|
||||||
|
{
|
||||||
|
GPtrArray *dhcp_argv;
|
||||||
|
GError *error = NULL;
|
||||||
|
GPid pid;
|
||||||
|
|
||||||
|
g_return_val_if_fail (manager != NULL, FALSE);
|
||||||
|
|
||||||
|
dhcp_argv = g_ptr_array_new ();
|
||||||
|
g_ptr_array_add (dhcp_argv, DHCP_DAEMON_PROGRAM);
|
||||||
|
g_ptr_array_add (dhcp_argv, "--system");
|
||||||
|
g_ptr_array_add (dhcp_argv, NULL);
|
||||||
|
|
||||||
|
if (!g_spawn_async ("/", (char **) dhcp_argv->pdata, NULL, 0, NULL, NULL, &pid, &error))
|
||||||
|
{
|
||||||
|
g_ptr_array_free (dhcp_argv, TRUE);
|
||||||
|
nm_warning ("Could not activate the DHCP daemon " DHCP_DAEMON_PROGRAM ". error: '%s'.", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
g_ptr_array_free (dhcp_argv, TRUE);
|
||||||
|
nm_info ("Activated the DHCP daemon " DHCP_DAEMON_PROGRAM " with PID %d.", pid);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NMDHCPManager * nm_dhcp_manager_new (NMData *data)
|
||||||
|
{
|
||||||
|
NMDHCPManager * manager;
|
||||||
|
char * owner;
|
||||||
|
|
||||||
|
g_return_val_if_fail (data != NULL, NULL);
|
||||||
|
g_return_val_if_fail (data->dbus_connection != NULL, NULL);
|
||||||
|
|
||||||
|
manager = g_malloc0 (sizeof (NMDHCPManager));
|
||||||
|
manager->data = data;
|
||||||
|
manager->running = dbus_bus_name_has_owner (manager->data->dbus_connection, DHCP_SERVICE_NAME, NULL);
|
||||||
|
|
||||||
|
if (manager->running && (owner = get_name_owner (data->dbus_connection, DHCP_SERVICE_NAME)))
|
||||||
|
{
|
||||||
|
char *match = get_dhcp_match_string (owner);
|
||||||
|
dbus_bus_add_match (data->dbus_connection, match, NULL);
|
||||||
|
g_free (match);
|
||||||
|
g_free (owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void nm_dhcp_manager_dispose (NMDHCPManager *manager)
|
||||||
|
{
|
||||||
|
g_return_if_fail (manager != NULL);
|
||||||
|
|
||||||
|
memset (manager, 0, sizeof (NMDHCPManager));
|
||||||
|
g_free (manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
guint8 nm_dhcp_manager_get_state_for_device (NMDHCPManager *manager, NMDevice *dev)
|
||||||
|
{
|
||||||
|
DBusMessage * message;
|
||||||
|
DBusMessage * reply;
|
||||||
|
char * path;
|
||||||
|
guint8 state = 0;
|
||||||
|
DBusError error;
|
||||||
|
|
||||||
|
g_return_val_if_fail (manager != NULL, 0);
|
||||||
|
g_return_val_if_fail (dev != NULL, 0);
|
||||||
|
|
||||||
|
if (!manager->running)
|
||||||
|
{
|
||||||
|
if (nm_dhcp_manager_exec_daemon (manager) == FALSE)
|
||||||
|
return 0;
|
||||||
|
sleep (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
path = g_strdup_printf (DHCP_OBJECT_PATH"/%s", nm_device_get_iface (dev));
|
||||||
|
message = dbus_message_new_method_call (DHCP_SERVICE_NAME, path, DHCP_SERVICE_NAME".dbus.get", "reason");
|
||||||
|
g_free (path);
|
||||||
|
if (message == NULL)
|
||||||
|
{
|
||||||
|
nm_warning ("nm_dhcp_manager_get_state_for_device(): Couldn't allocate the dbus message");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbus_error_init (&error);
|
||||||
|
reply = dbus_connection_send_with_reply_and_block (manager->data->dbus_connection, message, -1, &error);
|
||||||
|
dbus_message_unref (message);
|
||||||
|
if (dbus_error_is_set (&error))
|
||||||
|
{
|
||||||
|
nm_info ("Error from dhcdbd on 'reason' request because: name '%s', message '%s'.", error.name, error.message);
|
||||||
|
dbus_error_free (&error);
|
||||||
|
}
|
||||||
|
if (reply)
|
||||||
|
{
|
||||||
|
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID))
|
||||||
|
state = 0;
|
||||||
|
dbus_message_unref (reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_dhcp_manager_handle_timeout
|
||||||
|
*
|
||||||
|
* Called after timeout of a DHCP transaction to notify device of the failure.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gboolean nm_dhcp_manager_handle_timeout (NMActRequest *req)
|
||||||
|
{
|
||||||
|
NMData * data;
|
||||||
|
NMDevice * dev;
|
||||||
|
|
||||||
|
g_return_val_if_fail (req != NULL, FALSE);
|
||||||
|
|
||||||
|
data = nm_act_request_get_data (req);
|
||||||
|
g_assert (data);
|
||||||
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
nm_info ("Device '%s' DHCP transaction took too long (>25s), stopping it.", nm_device_get_iface (dev));
|
||||||
|
|
||||||
|
if (nm_act_request_get_stage (req) == ACT_STAGE_IP_CONFIG_START)
|
||||||
|
{
|
||||||
|
nm_device_activate_schedule_stage4_ip_config_timeout (req);
|
||||||
|
nm_act_request_set_dhcp_timeout (req, 0);
|
||||||
|
nm_dhcp_manager_cancel_transaction (data->dhcp_manager, req);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gboolean nm_dhcp_manager_begin_transaction (NMDHCPManager *manager, NMActRequest *req)
|
||||||
|
{
|
||||||
|
DBusError error;
|
||||||
|
DBusMessage * message;
|
||||||
|
DBusMessage * reply;
|
||||||
|
NMDevice * dev;
|
||||||
|
char * path;
|
||||||
|
const guint32 opt1 = 31; /* turns off ALL actions and dhclient-script just writes options to dhcdbd */
|
||||||
|
const guint32 opt2 = 0; /* dhclient is run in ONE SHOT mode */
|
||||||
|
GSource * source;
|
||||||
|
|
||||||
|
g_return_val_if_fail (manager != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (req != NULL, FALSE);
|
||||||
|
|
||||||
|
if (!manager->running)
|
||||||
|
{
|
||||||
|
if (nm_dhcp_manager_exec_daemon (manager) == FALSE)
|
||||||
|
return FALSE;
|
||||||
|
sleep (1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Cancel any DHCP transaction already in progress */
|
||||||
|
nm_dhcp_manager_cancel_transaction (manager, req);
|
||||||
|
/* FIXME don't sleep */
|
||||||
|
sleep (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
nm_info ("Activation (%s) Beginning DHCP transaction.", nm_device_get_iface (dev));
|
||||||
|
|
||||||
|
path = g_strdup_printf (DHCP_OBJECT_PATH"/%s", nm_device_get_iface (dev));
|
||||||
|
message = dbus_message_new_method_call (DHCP_SERVICE_NAME, path, DHCP_SERVICE_NAME, "up");
|
||||||
|
g_free (path);
|
||||||
|
if (message == NULL)
|
||||||
|
{
|
||||||
|
nm_warning ("nm_dhcp_manager_begin_transaction(): Couldn't allocate the dbus message");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
dbus_message_append_args (message, DBUS_TYPE_UINT32, &opt1, DBUS_TYPE_UINT32, &opt2, DBUS_TYPE_INVALID);
|
||||||
|
dbus_error_init (&error);
|
||||||
|
reply = dbus_connection_send_with_reply_and_block (manager->data->dbus_connection, message, -1, &error);
|
||||||
|
if (dbus_error_is_set (&error))
|
||||||
|
{
|
||||||
|
nm_info ("Couldn't send DHCP 'up' message because: name '%s', message '%s'.", error.name, error.message);
|
||||||
|
dbus_error_free (&error);
|
||||||
|
}
|
||||||
|
if (reply)
|
||||||
|
dbus_message_unref (reply);
|
||||||
|
dbus_message_unref (message);
|
||||||
|
|
||||||
|
/* Set up a timeout on the transaction to kill it after 25s */
|
||||||
|
source = g_timeout_source_new (25000);
|
||||||
|
g_source_set_callback (source, (GSourceFunc) nm_dhcp_manager_handle_timeout, req, NULL);
|
||||||
|
nm_act_request_set_dhcp_timeout (req, g_source_attach (source, manager->data->main_context));
|
||||||
|
g_source_unref (source);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void remove_timeout (NMDHCPManager *manager, NMActRequest *req)
|
||||||
|
{
|
||||||
|
guint id;
|
||||||
|
|
||||||
|
g_return_if_fail (manager != NULL);
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
/* Remove any pending timeouts on the request */
|
||||||
|
if ((id = nm_act_request_get_dhcp_timeout (req)) > 0)
|
||||||
|
{
|
||||||
|
GSource * source = g_main_context_find_source_by_id (manager->data->main_context, id);
|
||||||
|
nm_act_request_set_dhcp_timeout (req, 0);
|
||||||
|
g_source_destroy (source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_dhcp_manager_cancel_transaction
|
||||||
|
*
|
||||||
|
* Stop any in-progress DHCP transaction on a particular device.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void nm_dhcp_manager_cancel_transaction (NMDHCPManager *manager, NMActRequest *req)
|
||||||
|
{
|
||||||
|
NMDevice *dev;
|
||||||
|
|
||||||
|
g_return_if_fail (manager != NULL);
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
if (manager->running && !state_is_down (nm_act_request_get_dhcp_state (req)))
|
||||||
|
{
|
||||||
|
guint id;
|
||||||
|
DBusMessage * message;
|
||||||
|
char * path = g_strdup_printf (DHCP_OBJECT_PATH"/%s", nm_device_get_iface (dev));
|
||||||
|
|
||||||
|
if ((message = dbus_message_new_method_call (DHCP_SERVICE_NAME, path, DHCP_SERVICE_NAME, "down")))
|
||||||
|
{
|
||||||
|
dbus_connection_send (manager->data->dbus_connection, message, NULL);
|
||||||
|
dbus_message_unref (message);
|
||||||
|
}
|
||||||
|
g_free (path);
|
||||||
|
|
||||||
|
remove_timeout (manager, req);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean get_ip4_uint32s (NMDHCPManager *manager, NMDevice *dev, const char *item, guint32 **ip4_uint32, guint32 *num_items)
|
||||||
|
{
|
||||||
|
DBusMessage * message = NULL;
|
||||||
|
DBusMessage * reply = NULL;
|
||||||
|
char * path;
|
||||||
|
gboolean success = FALSE;
|
||||||
|
|
||||||
|
g_return_val_if_fail (manager != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (dev != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (ip4_uint32 != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (num_items != NULL, FALSE);
|
||||||
|
|
||||||
|
*ip4_uint32 = NULL;
|
||||||
|
*num_items = 0;
|
||||||
|
path = g_strdup_printf (DHCP_OBJECT_PATH"/%s", nm_device_get_iface (dev));
|
||||||
|
if ((message = dbus_message_new_method_call (DHCP_SERVICE_NAME, path, DHCP_SERVICE_NAME".dbus.get", item)))
|
||||||
|
{
|
||||||
|
DBusError error;
|
||||||
|
|
||||||
|
dbus_error_init (&error);
|
||||||
|
reply = dbus_connection_send_with_reply_and_block (manager->data->dbus_connection, message, -1, &error);
|
||||||
|
if (reply)
|
||||||
|
{
|
||||||
|
GArray *buffer;
|
||||||
|
DBusMessageIter iter;
|
||||||
|
|
||||||
|
dbus_message_iter_init (reply, &iter);
|
||||||
|
|
||||||
|
buffer = g_array_new (TRUE, TRUE, sizeof (guint32));
|
||||||
|
while (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_UINT32)
|
||||||
|
{
|
||||||
|
guint32 value;
|
||||||
|
|
||||||
|
dbus_message_iter_get_basic (&iter, &value);
|
||||||
|
g_array_append_val (buffer, value);
|
||||||
|
dbus_message_iter_next (&iter);
|
||||||
|
success = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
*ip4_uint32 = (guint32 *)(buffer->data);
|
||||||
|
*num_items = buffer->len;
|
||||||
|
}
|
||||||
|
g_array_free (buffer, FALSE);
|
||||||
|
dbus_message_unref (reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dbus_error_is_set (&error))
|
||||||
|
{
|
||||||
|
nm_warning ("get_ip4_uint32(): error calling '%s', DHCP daemon returned error '%s', message '%s'.", item, error.name, error.message);
|
||||||
|
dbus_error_free (&error);
|
||||||
|
}
|
||||||
|
dbus_message_unref (message);
|
||||||
|
}
|
||||||
|
g_free (path);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean get_ip4_string (NMDHCPManager *manager, NMDevice *dev, const char *item, char **string)
|
||||||
|
{
|
||||||
|
DBusMessage * message = NULL;
|
||||||
|
DBusMessage * reply = NULL;
|
||||||
|
char * path;
|
||||||
|
gboolean success = FALSE;
|
||||||
|
|
||||||
|
g_return_val_if_fail (manager != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (dev != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (string != NULL, FALSE);
|
||||||
|
|
||||||
|
*string = NULL;
|
||||||
|
path = g_strdup_printf (DHCP_OBJECT_PATH"/%s", nm_device_get_iface (dev));
|
||||||
|
if ((message = dbus_message_new_method_call (DHCP_SERVICE_NAME, path, DHCP_SERVICE_NAME".dbus.get", item)))
|
||||||
|
{
|
||||||
|
DBusError error;
|
||||||
|
|
||||||
|
dbus_error_init (&error);
|
||||||
|
if ((reply = dbus_connection_send_with_reply_and_block (manager->data->dbus_connection, message, -1, &error)))
|
||||||
|
{
|
||||||
|
char *dbus_string;
|
||||||
|
|
||||||
|
dbus_error_init (&error);
|
||||||
|
if (dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &dbus_string, DBUS_TYPE_INVALID))
|
||||||
|
{
|
||||||
|
*string = g_strdup (dbus_string);
|
||||||
|
success = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dbus_error_is_set (&error))
|
||||||
|
{
|
||||||
|
nm_warning ("get_ip4_string(): error calling '%s', DHCP daemon returned error '%s', message '%s'.", item, error.name, error.message);
|
||||||
|
dbus_error_free (&error);
|
||||||
|
*string = NULL;
|
||||||
|
}
|
||||||
|
dbus_message_unref (message);
|
||||||
|
}
|
||||||
|
g_free (path);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_dhcp_manager_get_ip4_config
|
||||||
|
*
|
||||||
|
* Get IP4 configuration values from the DHCP daemon
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
NMIP4Config * nm_dhcp_manager_get_ip4_config (NMDHCPManager *manager, NMActRequest *req)
|
||||||
|
{
|
||||||
|
NMDevice * dev;
|
||||||
|
NMIP4Config * ip4_config = NULL;
|
||||||
|
int i;
|
||||||
|
guint32 count = 0;
|
||||||
|
guint32 * ip4_address = NULL;
|
||||||
|
guint32 * ip4_netmask = NULL;
|
||||||
|
guint32 * ip4_broadcast = NULL;
|
||||||
|
guint32 * ip4_nameservers = NULL;
|
||||||
|
guint32 * ip4_gateway = NULL;
|
||||||
|
guint32 num_ip4_nameservers = 0;
|
||||||
|
char * domain_names = NULL;
|
||||||
|
struct in_addr temp_addr;
|
||||||
|
|
||||||
|
g_return_val_if_fail (manager != NULL, NULL);
|
||||||
|
g_return_val_if_fail (req != NULL, NULL);
|
||||||
|
|
||||||
|
if (!manager->running)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
dev = nm_act_request_get_dev (req);
|
||||||
|
g_assert (dev);
|
||||||
|
|
||||||
|
if (!state_is_bound (nm_act_request_get_dhcp_state (req)))
|
||||||
|
{
|
||||||
|
nm_warning ("Tried to get IP4 Config for a device when dhcdbd wasn't in a BOUND state!");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!get_ip4_uint32s (manager, dev, "ip_address", &ip4_address, &count) || !count)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!get_ip4_uint32s (manager, dev, "subnet_mask", &ip4_netmask, &count) || !count)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!get_ip4_uint32s (manager, dev, "broadcast_address", &ip4_broadcast, &count) || !count)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!get_ip4_uint32s (manager, dev, "routers", &ip4_gateway, &count) || !count)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!get_ip4_uint32s (manager, dev, "domain_name_servers", &ip4_nameservers, &num_ip4_nameservers) || !num_ip4_nameservers)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
get_ip4_string (manager, dev, "domain_name", &domain_names);
|
||||||
|
|
||||||
|
nm_info ("Retrieved the following IP4 configuration from the DHCP daemon:");
|
||||||
|
|
||||||
|
ip4_config = nm_ip4_config_new ();
|
||||||
|
nm_ip4_config_set_address (ip4_config, ip4_address[0]);
|
||||||
|
temp_addr.s_addr = ip4_address[0];
|
||||||
|
nm_info (" address %s", inet_ntoa (temp_addr));
|
||||||
|
|
||||||
|
nm_ip4_config_set_netmask (ip4_config, ip4_netmask[0]);
|
||||||
|
temp_addr.s_addr = ip4_netmask[0];
|
||||||
|
nm_info (" netmask %s", inet_ntoa (temp_addr));
|
||||||
|
|
||||||
|
nm_ip4_config_set_broadcast (ip4_config, ip4_broadcast[0]);
|
||||||
|
temp_addr.s_addr = ip4_broadcast[0];
|
||||||
|
nm_info (" broadcast %s", inet_ntoa (temp_addr));
|
||||||
|
|
||||||
|
nm_ip4_config_set_gateway (ip4_config, ip4_gateway[0]);
|
||||||
|
temp_addr.s_addr = ip4_gateway[0];
|
||||||
|
nm_info (" gateway %s", inet_ntoa (temp_addr));
|
||||||
|
|
||||||
|
for (i = 0; i < num_ip4_nameservers; i++)
|
||||||
|
{
|
||||||
|
nm_ip4_config_add_nameserver (ip4_config, ip4_nameservers[i]);
|
||||||
|
temp_addr.s_addr = ip4_nameservers[i];
|
||||||
|
nm_info (" nameserver %s", inet_ntoa (temp_addr));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (domain_names)
|
||||||
|
{
|
||||||
|
char **searches = g_strsplit (domain_names, " ", 0);
|
||||||
|
char **s;
|
||||||
|
|
||||||
|
for (s = searches; *s; s++)
|
||||||
|
{
|
||||||
|
nm_info (" domain name '%s'", *s);
|
||||||
|
nm_ip4_config_add_domain (ip4_config, *s);
|
||||||
|
}
|
||||||
|
g_strfreev (searches);
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ip4_config;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_dhcp_manager_process_signal
|
||||||
|
*
|
||||||
|
* Possibly process a signal from the bus, if it comes from the currently
|
||||||
|
* active DHCP daemon, if any. Return TRUE if processed, FALSE if not.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gboolean nm_dhcp_manager_process_signal (NMDHCPManager *manager, DBusMessage *message)
|
||||||
|
{
|
||||||
|
const char * object_path;
|
||||||
|
const char * member;
|
||||||
|
const char * interface;
|
||||||
|
const char * temp_op;
|
||||||
|
const char * service_name;
|
||||||
|
gboolean handled = FALSE;
|
||||||
|
NMDevice * dev;
|
||||||
|
NMActRequest * req = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (manager != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (message != NULL, FALSE);
|
||||||
|
|
||||||
|
if (!(object_path = dbus_message_get_path (message)))
|
||||||
|
return FALSE;
|
||||||
|
if (!(member = dbus_message_get_member (message)))
|
||||||
|
return FALSE;
|
||||||
|
if (!(interface = dbus_message_get_interface (message)))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* nm_info ("nm_dhcp_manager_process_signal(): got signal op='%s' member='%s' interface='%s'", object_path, member, interface); */
|
||||||
|
|
||||||
|
dev = nm_get_device_by_iface (manager->data, member);
|
||||||
|
if (dev && (req = nm_device_get_act_request (dev)))
|
||||||
|
{
|
||||||
|
if (dbus_message_is_signal (message, "com.redhat.dhcp.state", nm_device_get_iface (dev)))
|
||||||
|
{
|
||||||
|
guint8 state;
|
||||||
|
|
||||||
|
if (dbus_message_get_args (message, NULL, DBUS_TYPE_BYTE, &state, DBUS_TYPE_INVALID))
|
||||||
|
{
|
||||||
|
nm_info ("DHCP daemon state now %d for interface %s", state, nm_device_get_iface (dev));
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case 2: /* BOUND */
|
||||||
|
case 3: /* RENEW */
|
||||||
|
case 4: /* REBOOT */
|
||||||
|
case 5: /* REBIND */
|
||||||
|
if (nm_act_request_get_stage (req) == ACT_STAGE_IP_CONFIG_START)
|
||||||
|
{
|
||||||
|
nm_device_activate_schedule_stage4_ip_config_get (req);
|
||||||
|
remove_timeout (manager, req);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 8: /* TIMEOUT - timed out trying to contact server */
|
||||||
|
if (nm_act_request_get_stage (req) == ACT_STAGE_IP_CONFIG_START)
|
||||||
|
{
|
||||||
|
nm_device_activate_schedule_stage4_ip_config_timeout (req);
|
||||||
|
remove_timeout (manager, req);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 9: /* FAIL */
|
||||||
|
case 13: /* ABEND */
|
||||||
|
if (nm_act_request_get_stage (req) == ACT_STAGE_IP_CONFIG_START)
|
||||||
|
{
|
||||||
|
nm_policy_schedule_activation_failed (req);
|
||||||
|
remove_timeout (manager, req);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nm_act_request_set_dhcp_state (req, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_dhcp_manager_process_name_owner_changed
|
||||||
|
*
|
||||||
|
* Respond to "service created"/"service deleted" signals from dbus for the active DHCP daemon.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gboolean nm_dhcp_manager_process_name_owner_changed (NMDHCPManager *manager, const char *changed_service_name, const char *old_owner, const char *new_owner)
|
||||||
|
{
|
||||||
|
gboolean handled = FALSE;
|
||||||
|
gboolean old_owner_good = (old_owner && strlen (old_owner));
|
||||||
|
gboolean new_owner_good = (new_owner && strlen (new_owner));
|
||||||
|
|
||||||
|
g_return_val_if_fail (manager != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (changed_service_name != NULL, FALSE);
|
||||||
|
|
||||||
|
/* Can't handle the signal if its not from the DHCP service */
|
||||||
|
if (strcmp (DHCP_SERVICE_NAME, changed_service_name) != 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (!old_owner_good && new_owner_good)
|
||||||
|
{
|
||||||
|
char *match = get_dhcp_match_string (new_owner);
|
||||||
|
|
||||||
|
/* DHCP service got created */
|
||||||
|
dbus_bus_add_match (manager->data->dbus_connection, match, NULL);
|
||||||
|
g_free (match);
|
||||||
|
|
||||||
|
manager->running = TRUE;
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
|
else if (old_owner_good && !new_owner_good)
|
||||||
|
{
|
||||||
|
char *match = get_dhcp_match_string (old_owner);
|
||||||
|
|
||||||
|
/* DHCP service went away */
|
||||||
|
dbus_bus_remove_match (manager->data->dbus_connection, match, NULL);
|
||||||
|
g_free (match);
|
||||||
|
|
||||||
|
manager->running = FALSE;
|
||||||
|
handled = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
42
src/dhcp-manager/nm-dhcp-manager.h
Normal file
42
src/dhcp-manager/nm-dhcp-manager.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/* nm-dhcp-manager.c - Handle the DHCP daemon for NetworkManager
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 Dan Williams
|
||||||
|
*
|
||||||
|
* 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, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NM_DHCP_MANAGER_H
|
||||||
|
#define NM_DHCP_MANAGER_H
|
||||||
|
|
||||||
|
#include "NetworkManagerMain.h"
|
||||||
|
#include "NetworkManagerDevice.h"
|
||||||
|
|
||||||
|
char * get_dhcp_match_string (const char *owner);
|
||||||
|
|
||||||
|
NMDHCPManager * nm_dhcp_manager_new (NMData *data);
|
||||||
|
void nm_dhcp_manager_dispose (NMDHCPManager *manager);
|
||||||
|
|
||||||
|
gboolean nm_dhcp_manager_begin_transaction (NMDHCPManager *manager, NMActRequest *req);
|
||||||
|
void nm_dhcp_manager_cancel_transaction (NMDHCPManager *manager, NMActRequest *req);
|
||||||
|
|
||||||
|
NMIP4Config * nm_dhcp_manager_get_ip4_config (NMDHCPManager *manager, NMActRequest *req);
|
||||||
|
|
||||||
|
gboolean nm_dhcp_manager_process_signal (NMDHCPManager *manager, DBusMessage *message);
|
||||||
|
gboolean nm_dhcp_manager_process_name_owner_changed (NMDHCPManager *manager, const char *changed_service_name, const char *old_owner, const char *new_owner);
|
||||||
|
|
||||||
|
guint8 nm_dhcp_manager_get_state_for_device (NMDHCPManager *manager, NMDevice *dev);
|
||||||
|
|
||||||
|
#endif
|
216
src/nm-activation-request.c
Normal file
216
src/nm-activation-request.c
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
/* NetworkManager -- Network link manager
|
||||||
|
*
|
||||||
|
* Dan Williams <dcbw@redhat.com>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* (C) Copyright 2005 Red Hat, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "nm-activation-request.h"
|
||||||
|
#include "NetworkManagerDevice.h"
|
||||||
|
#include "nm-dhcp-manager.h"
|
||||||
|
#include "nm-utils.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct NMActRequest
|
||||||
|
{
|
||||||
|
int refcount;
|
||||||
|
NMData * data;
|
||||||
|
NMDevice * dev;
|
||||||
|
NMAccessPoint * ap;
|
||||||
|
NMIP4Config * ip4_config;
|
||||||
|
|
||||||
|
gboolean user_requested;
|
||||||
|
|
||||||
|
NMActStage stage;
|
||||||
|
DBusPendingCall * user_key_pcall;
|
||||||
|
|
||||||
|
guint8 dhcp_state;
|
||||||
|
guint dhcp_timeout;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
NMActRequest * nm_act_request_new (NMData *data, NMDevice *dev, NMAccessPoint *ap, gboolean user_requested)
|
||||||
|
{
|
||||||
|
NMActRequest * req;
|
||||||
|
|
||||||
|
g_return_val_if_fail (data != NULL, NULL);
|
||||||
|
g_return_val_if_fail (dev != NULL, NULL);
|
||||||
|
|
||||||
|
if (nm_device_is_wireless (dev))
|
||||||
|
g_return_val_if_fail (ap != NULL, NULL);
|
||||||
|
|
||||||
|
req = g_malloc0 (sizeof (NMActRequest));
|
||||||
|
req->refcount = 1;
|
||||||
|
req->data = data;
|
||||||
|
|
||||||
|
nm_device_ref (dev);
|
||||||
|
req->dev = dev;
|
||||||
|
|
||||||
|
if (ap)
|
||||||
|
nm_ap_ref (ap);
|
||||||
|
req->ap = ap;
|
||||||
|
|
||||||
|
req->user_requested = user_requested;
|
||||||
|
req->dhcp_state = nm_dhcp_manager_get_state_for_device (data->dhcp_manager, dev);
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nm_act_request_ref (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
req->refcount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void nm_act_request_unref (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
if (req->refcount == 1)
|
||||||
|
{
|
||||||
|
nm_device_unref (req->dev);
|
||||||
|
if (req->ap)
|
||||||
|
nm_ap_unref (req->ap);
|
||||||
|
|
||||||
|
if (req->dhcp_timeout > 0)
|
||||||
|
{
|
||||||
|
GSource * source = g_main_context_find_source_by_id (req->data->main_context, req->dhcp_timeout);
|
||||||
|
g_source_destroy (source);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset (req, 0, sizeof (NMActRequest));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
req->refcount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
NMDevice * nm_act_request_get_dev (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (req != NULL, NULL);
|
||||||
|
|
||||||
|
return req->dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NMData * nm_act_request_get_data (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (req != NULL, NULL);
|
||||||
|
|
||||||
|
return req->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NMAccessPoint * nm_act_request_get_ap (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (req != NULL, NULL);
|
||||||
|
|
||||||
|
return req->ap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gboolean nm_act_request_get_user_requested (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (req != NULL, FALSE);
|
||||||
|
|
||||||
|
return req->user_requested;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NMIP4Config * nm_act_request_get_ip4_config (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (req != NULL, NULL);
|
||||||
|
|
||||||
|
return req->ip4_config;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nm_act_request_set_ip4_config (NMActRequest *req, NMIP4Config *ip4_config)
|
||||||
|
{
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
if (req->ip4_config)
|
||||||
|
{
|
||||||
|
nm_ip4_config_unref (req->ip4_config);
|
||||||
|
req->ip4_config = NULL;
|
||||||
|
}
|
||||||
|
if (ip4_config)
|
||||||
|
{
|
||||||
|
nm_ip4_config_ref (ip4_config);
|
||||||
|
req->ip4_config = ip4_config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NMActStage nm_act_request_get_stage (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (req != NULL, ACT_STAGE_UNKNOWN);
|
||||||
|
|
||||||
|
return req->stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nm_act_request_set_stage (NMActRequest *req, NMActStage stage)
|
||||||
|
{
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
req->stage = stage;
|
||||||
|
}
|
||||||
|
|
||||||
|
DBusPendingCall * nm_act_request_get_user_key_pending_call (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (req != NULL, NULL);
|
||||||
|
|
||||||
|
return req->user_key_pcall;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nm_act_request_set_user_key_pending_call (NMActRequest *req, DBusPendingCall *pcall)
|
||||||
|
{
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
req->user_key_pcall = pcall;
|
||||||
|
}
|
||||||
|
|
||||||
|
guint8 nm_act_request_get_dhcp_state (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (req != NULL, 0);
|
||||||
|
|
||||||
|
return req->dhcp_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nm_act_request_set_dhcp_state (NMActRequest *req, guint8 dhcp_state)
|
||||||
|
{
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
req->dhcp_state = dhcp_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
guint nm_act_request_get_dhcp_timeout (NMActRequest *req)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (req != NULL, 0);
|
||||||
|
|
||||||
|
return req->dhcp_timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nm_act_request_set_dhcp_timeout (NMActRequest *req, guint dhcp_timeout)
|
||||||
|
{
|
||||||
|
g_return_if_fail (req != NULL);
|
||||||
|
|
||||||
|
req->dhcp_timeout = dhcp_timeout;
|
||||||
|
}
|
||||||
|
|
71
src/nm-activation-request.h
Normal file
71
src/nm-activation-request.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
/* NetworkManager -- Network link manager
|
||||||
|
*
|
||||||
|
* Dan Williams <dcbw@redhat.com>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* (C) Copyright 2005 Red Hat, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NM_ACTIVATION_REQUEST_H
|
||||||
|
#define NM_ACTIVATION_REQUEST_H
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <dbus/dbus.h>
|
||||||
|
#include "NetworkManager.h"
|
||||||
|
#include "NetworkManagerMain.h"
|
||||||
|
#include "NetworkManagerDevice.h"
|
||||||
|
#include "NetworkManagerAP.h"
|
||||||
|
#include "nm-ip4-config.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum NMActStage
|
||||||
|
{
|
||||||
|
ACT_STAGE_UNKNOWN = 0,
|
||||||
|
ACT_STAGE_DEVICE_PREPARE,
|
||||||
|
ACT_STAGE_DEVICE_CONFIG,
|
||||||
|
ACT_STAGE_NEED_USER_KEY,
|
||||||
|
ACT_STAGE_IP_CONFIG_START,
|
||||||
|
ACT_STAGE_IP_CONFIG_GET,
|
||||||
|
ACT_STAGE_IP_CONFIG_COMMIT,
|
||||||
|
ACT_STAGE_ACTIVATED
|
||||||
|
} NMActStage;
|
||||||
|
|
||||||
|
|
||||||
|
NMActRequest * nm_act_request_new (NMData *data, NMDevice *dev, NMAccessPoint *ap, gboolean user_requested);
|
||||||
|
void nm_act_request_ref (NMActRequest *req);
|
||||||
|
void nm_act_request_unref (NMActRequest *req);
|
||||||
|
|
||||||
|
NMDevice * nm_act_request_get_dev (NMActRequest *req);
|
||||||
|
NMData * nm_act_request_get_data (NMActRequest *req);
|
||||||
|
NMAccessPoint * nm_act_request_get_ap (NMActRequest *req);
|
||||||
|
gboolean nm_act_request_get_user_requested (NMActRequest *req);
|
||||||
|
|
||||||
|
NMIP4Config * nm_act_request_get_ip4_config (NMActRequest *req);
|
||||||
|
void nm_act_request_set_ip4_config (NMActRequest *req, NMIP4Config *ip4_config);
|
||||||
|
|
||||||
|
NMActStage nm_act_request_get_stage (NMActRequest *req);
|
||||||
|
void nm_act_request_set_stage (NMActRequest *req, NMActStage stage);
|
||||||
|
|
||||||
|
DBusPendingCall * nm_act_request_get_user_key_pending_call (NMActRequest *req);
|
||||||
|
void nm_act_request_set_user_key_pending_call (NMActRequest *req, DBusPendingCall *pcall);
|
||||||
|
|
||||||
|
guint8 nm_act_request_get_dhcp_state (NMActRequest *req);
|
||||||
|
void nm_act_request_set_dhcp_state (NMActRequest *req, guint8 dhcp_state);
|
||||||
|
|
||||||
|
guint nm_act_request_get_dhcp_timeout (NMActRequest *req);
|
||||||
|
void nm_act_request_set_dhcp_timeout (NMActRequest *req, guint dhcp_timeout);
|
||||||
|
|
||||||
|
#endif
|
@@ -118,7 +118,7 @@ static DBusMessage *nm_dbus_device_get_hw_address (DBusConnection *connection, D
|
|||||||
char char_addr[20];
|
char char_addr[20];
|
||||||
char *ptr = &char_addr[0];
|
char *ptr = &char_addr[0];
|
||||||
|
|
||||||
nm_device_get_hw_address (dev, (unsigned char *)&(addr.ether_addr_octet));
|
nm_device_get_hw_address (dev, &addr);
|
||||||
memset (char_addr, 0, 20);
|
memset (char_addr, 0, 20);
|
||||||
ether_ntoa_r (&addr, &char_addr[0]);
|
ether_ntoa_r (&addr, &char_addr[0]);
|
||||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &ptr, DBUS_TYPE_INVALID);
|
dbus_message_append_args (reply, DBUS_TYPE_STRING, &ptr, DBUS_TYPE_INVALID);
|
||||||
@@ -203,24 +203,21 @@ static DBusMessage *nm_dbus_device_get_active_network (DBusConnection *connectio
|
|||||||
}
|
}
|
||||||
else if ((reply = dbus_message_new_method_return (message)))
|
else if ((reply = dbus_message_new_method_return (message)))
|
||||||
{
|
{
|
||||||
NMAccessPoint *best_ap;
|
NMActRequest * req = nm_device_get_act_request (dev);
|
||||||
|
NMAccessPoint * ap;
|
||||||
|
|
||||||
/* Return the network associated with the ESSID the card is currently associated with,
|
if (req && (ap = nm_act_request_get_ap (req)))
|
||||||
* if any, and only if that network is the "best" network.
|
|
||||||
*/
|
|
||||||
if ((best_ap = nm_device_get_best_ap (dev)))
|
|
||||||
{
|
{
|
||||||
NMAccessPoint *tmp_ap;
|
NMAccessPoint *tmp_ap;
|
||||||
char * object_path = NULL;
|
char * object_path = NULL;
|
||||||
|
|
||||||
if ( (tmp_ap = nm_device_ap_list_get_ap_by_essid (dev, nm_ap_get_essid (best_ap)))
|
if ( (tmp_ap = nm_device_ap_list_get_ap_by_essid (dev, nm_ap_get_essid (ap)))
|
||||||
&& (object_path = nm_dbus_get_object_path_for_network (dev, tmp_ap)))
|
&& (object_path = nm_dbus_get_object_path_for_network (dev, tmp_ap)))
|
||||||
{
|
{
|
||||||
dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID);
|
dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID);
|
||||||
g_free (object_path);
|
g_free (object_path);
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
}
|
}
|
||||||
nm_ap_unref (best_ap);
|
|
||||||
}
|
}
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
@@ -332,7 +329,7 @@ static DBusMessage *nm_dbus_device_set_link_active (DBusConnection *connection,
|
|||||||
if (dbus_message_get_args (message, &error, DBUS_TYPE_BOOLEAN, &link, DBUS_TYPE_INVALID))
|
if (dbus_message_get_args (message, &error, DBUS_TYPE_BOOLEAN, &link, DBUS_TYPE_INVALID))
|
||||||
{
|
{
|
||||||
nm_device_set_link_active (dev, link);
|
nm_device_set_link_active (dev, link);
|
||||||
nm_policy_schedule_state_update (data->data);
|
nm_policy_schedule_device_change_check (data->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,32 +356,33 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
|
|||||||
char * hw_addr_buf_ptr = &hw_addr_buf[0];
|
char * hw_addr_buf_ptr = &hw_addr_buf[0];
|
||||||
dbus_uint32_t mode = 0;
|
dbus_uint32_t mode = 0;
|
||||||
dbus_int32_t strength = -1;
|
dbus_int32_t strength = -1;
|
||||||
NMAccessPoint * best_ap;
|
|
||||||
char * active_network_path = NULL;
|
char * active_network_path = NULL;
|
||||||
dbus_bool_t link_active = (dbus_bool_t) nm_device_has_active_link (dev);
|
dbus_bool_t link_active = (dbus_bool_t) nm_device_has_active_link (dev);
|
||||||
dbus_uint32_t driver_support_level = (dbus_uint32_t) nm_device_get_driver_support_level (dev);
|
dbus_uint32_t driver_support_level = (dbus_uint32_t) nm_device_get_driver_support_level (dev);
|
||||||
char ** networks = NULL;
|
char ** networks = NULL;
|
||||||
int num_networks = 0;
|
int num_networks = 0;
|
||||||
|
dbus_bool_t active = nm_device_get_act_request (dev) ? TRUE : FALSE;
|
||||||
|
|
||||||
nm_device_get_hw_address (dev, (unsigned char *)&(hw_addr.ether_addr_octet));
|
nm_device_get_hw_address (dev, &hw_addr);
|
||||||
memset (hw_addr_buf, 0, 20);
|
memset (hw_addr_buf, 0, 20);
|
||||||
ether_ntoa_r (&hw_addr, &hw_addr_buf[0]);
|
ether_ntoa_r (&hw_addr, &hw_addr_buf[0]);
|
||||||
|
|
||||||
if (nm_device_is_wireless (dev))
|
if (nm_device_is_wireless (dev))
|
||||||
{
|
{
|
||||||
|
NMActRequest * req = nm_device_get_act_request (dev);
|
||||||
|
NMAccessPoint * ap;
|
||||||
NMAccessPointList * ap_list;
|
NMAccessPointList * ap_list;
|
||||||
NMAPListIter * iter;
|
NMAPListIter * iter;
|
||||||
|
|
||||||
strength = (dbus_int32_t) nm_device_get_signal_strength (dev);
|
strength = (dbus_int32_t) nm_device_get_signal_strength (dev);
|
||||||
mode = (dbus_uint32_t) nm_device_get_mode (dev);
|
mode = (dbus_uint32_t) nm_device_get_mode (dev);
|
||||||
|
|
||||||
if ((best_ap = nm_device_get_best_ap (dev)))
|
if (req && (ap = nm_act_request_get_ap (req)))
|
||||||
{
|
{
|
||||||
NMAccessPoint *tmp_ap;
|
NMAccessPoint *tmp_ap;
|
||||||
|
|
||||||
if ((tmp_ap = nm_device_ap_list_get_ap_by_essid (dev, nm_ap_get_essid (best_ap))))
|
if ((tmp_ap = nm_device_ap_list_get_ap_by_essid (dev, nm_ap_get_essid (ap))))
|
||||||
active_network_path = nm_dbus_get_object_path_for_network (dev, tmp_ap);
|
active_network_path = nm_dbus_get_object_path_for_network (dev, tmp_ap);
|
||||||
nm_ap_unref (best_ap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ap_list = nm_device_ap_list_get (dev);
|
ap_list = nm_device_ap_list_get (dev);
|
||||||
@@ -415,6 +413,7 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
|
|||||||
DBUS_TYPE_STRING, &iface,
|
DBUS_TYPE_STRING, &iface,
|
||||||
DBUS_TYPE_UINT32, &type,
|
DBUS_TYPE_UINT32, &type,
|
||||||
DBUS_TYPE_STRING, &udi,
|
DBUS_TYPE_STRING, &udi,
|
||||||
|
DBUS_TYPE_BOOLEAN,&active,
|
||||||
DBUS_TYPE_UINT32, &ip4_address,
|
DBUS_TYPE_UINT32, &ip4_address,
|
||||||
DBUS_TYPE_STRING, &hw_addr_buf_ptr,
|
DBUS_TYPE_STRING, &hw_addr_buf_ptr,
|
||||||
DBUS_TYPE_UINT32, &mode,
|
DBUS_TYPE_UINT32, &mode,
|
||||||
|
@@ -1,312 +0,0 @@
|
|||||||
/* NetworkManager -- Network link manager
|
|
||||||
*
|
|
||||||
* Dan Williams <dcbw@redhat.com>
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* (C) Copyright 2005 Red Hat, Inc.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "NetworkManagerDevice.h"
|
|
||||||
#include "NetworkManagerDbus.h"
|
|
||||||
#include "NetworkManagerAP.h"
|
|
||||||
#include "NetworkManagerAPList.h"
|
|
||||||
#include "NetworkManagerUtils.h"
|
|
||||||
#include "nm-dbus-dhcp.h"
|
|
||||||
#include "dhcpcd/dhcpcd.h"
|
|
||||||
|
|
||||||
static int nm_dbus_dhcp_element_type (int id)
|
|
||||||
{
|
|
||||||
switch (dhcp_option_element_type (id))
|
|
||||||
{
|
|
||||||
case DHCP_OPT_INVALID:
|
|
||||||
return DBUS_TYPE_INVALID;
|
|
||||||
case DHCP_OPT_ADDRESS:
|
|
||||||
case DHCP_OPT_TIME:
|
|
||||||
case DHCP_OPT_COUNT:
|
|
||||||
case DHCP_OPT_NUMBER:
|
|
||||||
return DBUS_TYPE_UINT32;
|
|
||||||
case DHCP_OPT_STRING:
|
|
||||||
return DBUS_TYPE_STRING;
|
|
||||||
case DHCP_OPT_TOGGLE:
|
|
||||||
return DBUS_TYPE_BOOLEAN;
|
|
||||||
case DHCP_OPT_BLOB:
|
|
||||||
return DBUS_TYPE_BYTE;
|
|
||||||
}
|
|
||||||
g_assert_not_reached();
|
|
||||||
return DBUS_TYPE_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DBUS_REPLY_BYTYPE(Dtype, Ctype, as_blob) do { \
|
|
||||||
int __len; \
|
|
||||||
\
|
|
||||||
if (dhcp_interface_option_present (dhcp_iface, data->opt_id) \
|
|
||||||
&& (sizeof (Ctype) >= (__len = dhcp_option_element_len (data->opt_id))) \
|
|
||||||
&& ((reply = dbus_message_new_method_return (message)) != NULL)) \
|
|
||||||
{ \
|
|
||||||
Ctype *__blob; \
|
|
||||||
int __count; \
|
|
||||||
\
|
|
||||||
__blob = dhcp_interface_option_payload (dhcp_iface, data->opt_id); \
|
|
||||||
__count = as_blob ? __len : (dhcp_interface_option_len (dhcp_iface, data->opt_id) / __len); \
|
|
||||||
dbus_message_append_args (reply, DBUS_TYPE_ARRAY, Dtype, &__blob, __count, DBUS_TYPE_INVALID); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define DBUS_REPLY_STRING(Dtype, Ctype) do { \
|
|
||||||
int __len; \
|
|
||||||
\
|
|
||||||
if (dhcp_interface_option_present (dhcp_iface, data->opt_id) \
|
|
||||||
&& ((__len = dhcp_option_element_len (data->opt_id)) == 1) \
|
|
||||||
&& ((reply = dbus_message_new_method_return (message)) != NULL)) \
|
|
||||||
{ \
|
|
||||||
Ctype __val; \
|
|
||||||
Ctype* __ptr = &__val; \
|
|
||||||
\
|
|
||||||
__val = (Ctype)dhcp_interface_option_payload (dhcp_iface, data->opt_id); \
|
|
||||||
/* We always return an array even if there's only 1 element */ \
|
|
||||||
dbus_message_append_args (reply, DBUS_TYPE_ARRAY, Dtype, &__ptr, 1, DBUS_TYPE_INVALID); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_dbus_dhcp_get_element_type
|
|
||||||
*
|
|
||||||
* Gets the length of individual elements within the specified DHCP option.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static DBusMessage *nm_dbus_dhcp_get_element_type (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
struct dhcp_interface *dhcp_iface;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
|
||||||
dhcp_iface = data->dhcp_iface;
|
|
||||||
|
|
||||||
if ((reply = dbus_message_new_method_return (message)) != NULL)
|
|
||||||
{
|
|
||||||
dbus_uint32_t type = nm_dbus_dhcp_element_type (data->opt_id);
|
|
||||||
dbus_message_append_args (reply, DBUS_TYPE_UINT32, &type, DBUS_TYPE_INVALID);
|
|
||||||
}
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static DBusMessage *nm_dbus_dhcp_get_boolean (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
struct dhcp_interface *dhcp_iface;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
|
||||||
dhcp_iface = data->dhcp_iface;
|
|
||||||
|
|
||||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BOOLEAN, dbus_bool_t, FALSE);
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static DBusMessage *nm_dbus_dhcp_get_byte (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
struct dhcp_interface *dhcp_iface;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
|
||||||
dhcp_iface = data->dhcp_iface;
|
|
||||||
|
|
||||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BYTE, unsigned char, FALSE);
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static DBusMessage *nm_dbus_dhcp_get_integer (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
struct dhcp_interface *dhcp_iface;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
|
||||||
dhcp_iface = data->dhcp_iface;
|
|
||||||
|
|
||||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_UINT32, dbus_uint32_t, FALSE);
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static DBusMessage *nm_dbus_dhcp_get_string (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
struct dhcp_interface *dhcp_iface;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
|
||||||
dhcp_iface = data->dhcp_iface;
|
|
||||||
|
|
||||||
DBUS_REPLY_STRING (DBUS_TYPE_STRING, const char *);
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
static DBusMessage *nm_dbus_dhcp_get_blob (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
struct dhcp_interface *dhcp_iface;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
|
||||||
dhcp_iface = data->dhcp_iface;
|
|
||||||
|
|
||||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BYTE, unsigned char, TRUE);
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
static DBusMessage *nm_dbus_dhcp_get_generic (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
struct dhcp_interface *dhcp_iface;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
|
||||||
dhcp_iface = data->dhcp_iface;
|
|
||||||
|
|
||||||
switch (nm_dbus_dhcp_element_type (data->opt_id))
|
|
||||||
{
|
|
||||||
case DBUS_TYPE_BOOLEAN:
|
|
||||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BOOLEAN, dbus_bool_t, FALSE);
|
|
||||||
break;
|
|
||||||
case DBUS_TYPE_BYTE:
|
|
||||||
DBUS_REPLY_BYTYPE (DBUS_TYPE_BYTE, unsigned char, FALSE);
|
|
||||||
break;
|
|
||||||
case DBUS_TYPE_UINT32:
|
|
||||||
DBUS_REPLY_BYTYPE(DBUS_TYPE_UINT32, dbus_uint32_t, FALSE);
|
|
||||||
break;
|
|
||||||
case DBUS_TYPE_STRING:
|
|
||||||
DBUS_REPLY_STRING (DBUS_TYPE_STRING, const char *);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static DBusMessage *nm_dbus_dhcp_get_name (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data && data->data && (data->opt_id >= 0) && (data->dhcp_iface != NULL) && connection && message, NULL);
|
|
||||||
|
|
||||||
if ((reply = dbus_message_new_method_return (message)) != NULL)
|
|
||||||
{
|
|
||||||
const char *name;
|
|
||||||
name = dhcp_option_name (data->opt_id);
|
|
||||||
dbus_message_append_args (reply, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
|
|
||||||
}
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_dbus_dhcp_validate
|
|
||||||
*
|
|
||||||
* Grab an option name or ID from the message and make sure its valid
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static DBusMessage *nm_dbus_dhcp_validate (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
DBusError error;
|
|
||||||
int id;
|
|
||||||
char *attribute = NULL;
|
|
||||||
gboolean success = FALSE;
|
|
||||||
struct dhcp_interface *dhcp_iface;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data && data->data && connection && message, NULL);
|
|
||||||
|
|
||||||
/* Caller can ask for DHCP option by either name or ID. Try name first, then ID. */
|
|
||||||
dbus_error_init (&error);
|
|
||||||
if (!dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &attribute, DBUS_TYPE_INVALID) || (attribute == NULL))
|
|
||||||
{
|
|
||||||
if (dbus_error_is_set (&error))
|
|
||||||
dbus_error_free (&error);
|
|
||||||
dbus_error_init (&error);
|
|
||||||
if (dbus_message_get_args (message, &error, DBUS_TYPE_UINT32, &id, DBUS_TYPE_INVALID) && (id >= 0))
|
|
||||||
success = TRUE;
|
|
||||||
}
|
|
||||||
else if (isdigit (*attribute) && ((id = atoi (attribute)) == 0) && (*attribute != '0'))
|
|
||||||
{
|
|
||||||
/* If user passed a DHCP option name, find that option's ID */
|
|
||||||
if ((id = dhcp_option_id_by_name (attribute)) != -1)
|
|
||||||
success = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success == TRUE)
|
|
||||||
{
|
|
||||||
if (!data->data->active_device || !(dhcp_iface = nm_device_get_dhcp_iface (data->data->active_device)))
|
|
||||||
{
|
|
||||||
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DhcpOptionsNotAvailable",
|
|
||||||
"DhcpOptions are not available at this time.");
|
|
||||||
success = FALSE;
|
|
||||||
}
|
|
||||||
else if (!dhcp_interface_option_present (dhcp_iface, id))
|
|
||||||
{
|
|
||||||
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DhcpOptionNotPresent",
|
|
||||||
"The DhcpOption requested was not present.");
|
|
||||||
success = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
data->opt_id = id;
|
|
||||||
/* We're gonna need some locking here for dhcp_iface, right now we
|
|
||||||
* just hope it never goes away between the validate and the
|
|
||||||
* dispatch functions. ie, device gets deactivated, removed, etc.
|
|
||||||
*/
|
|
||||||
data->dhcp_iface = dhcp_iface;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "OptionNotFound",
|
|
||||||
"The requested DHCP option does not exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return reply;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_dbus_dhcp_methods_setup
|
|
||||||
*
|
|
||||||
* Register handlers for dbus methods on the
|
|
||||||
* org.freedesktop.NetworkManager.DhcpOptions object.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
NMDbusMethodList *nm_dbus_dhcp_methods_setup (void)
|
|
||||||
{
|
|
||||||
NMDbusMethodList *list = nm_dbus_method_list_new (nm_dbus_dhcp_validate);
|
|
||||||
|
|
||||||
nm_dbus_method_list_add_method (list, "getElementType", nm_dbus_dhcp_get_element_type);
|
|
||||||
nm_dbus_method_list_add_method (list, "getBoolean", nm_dbus_dhcp_get_boolean);
|
|
||||||
nm_dbus_method_list_add_method (list, "getByte", nm_dbus_dhcp_get_byte);
|
|
||||||
nm_dbus_method_list_add_method (list, "getBlob", nm_dbus_dhcp_get_blob);
|
|
||||||
nm_dbus_method_list_add_method (list, "getInteger", nm_dbus_dhcp_get_integer);
|
|
||||||
nm_dbus_method_list_add_method (list, "getString", nm_dbus_dhcp_get_string);
|
|
||||||
nm_dbus_method_list_add_method (list, "get", nm_dbus_dhcp_get_generic);
|
|
||||||
nm_dbus_method_list_add_method (list, "getName", nm_dbus_dhcp_get_name);
|
|
||||||
|
|
||||||
return (list);
|
|
||||||
}
|
|
@@ -1,29 +0,0 @@
|
|||||||
/* NetworkManager -- Network link manager
|
|
||||||
*
|
|
||||||
* Dan Williams <dcbw@redhat.com>
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* (C) Copyright 2005 Red Hat, Inc.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NM_DBUS_DHCP_H
|
|
||||||
#define NM_DBUS_DHCP_H
|
|
||||||
|
|
||||||
#include "NetworkManagerDbusUtils.h"
|
|
||||||
|
|
||||||
NMDbusMethodList *nm_dbus_dhcp_methods_setup (void);
|
|
||||||
|
|
||||||
#endif
|
|
@@ -33,43 +33,6 @@
|
|||||||
#include "NetworkManagerPolicy.h"
|
#include "NetworkManagerPolicy.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_dbus_nm_get_active_device
|
|
||||||
*
|
|
||||||
* Returns the object path of the currently active device
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static DBusMessage *nm_dbus_nm_get_active_device (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
|
|
||||||
{
|
|
||||||
DBusMessage *reply = NULL;
|
|
||||||
|
|
||||||
g_return_val_if_fail (data != NULL, NULL);
|
|
||||||
g_return_val_if_fail (data->data != NULL, NULL);
|
|
||||||
g_return_val_if_fail (connection != NULL, NULL);
|
|
||||||
g_return_val_if_fail (message != NULL, NULL);
|
|
||||||
|
|
||||||
/* Construct object path of "active" device and return it */
|
|
||||||
if (data->data->active_device)
|
|
||||||
{
|
|
||||||
char *op;
|
|
||||||
|
|
||||||
if (!(reply = dbus_message_new_method_return (message)))
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
op = nm_dbus_get_object_path_for_device (data->data->active_device);
|
|
||||||
dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &op, DBUS_TYPE_INVALID);
|
|
||||||
g_free (op);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "NoActiveDevice",
|
|
||||||
"There is no currently active device.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (reply);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_dbus_nm_get_devices
|
* nm_dbus_nm_get_devices
|
||||||
*
|
*
|
||||||
@@ -154,6 +117,8 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
|
|||||||
const char * essid = NULL;
|
const char * essid = NULL;
|
||||||
const char * key = NULL;
|
const char * key = NULL;
|
||||||
const int key_type = -1;
|
const int key_type = -1;
|
||||||
|
NMActRequest * req = NULL;
|
||||||
|
NMAccessPoint * ap = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (connection != NULL, NULL);
|
g_return_val_if_fail (connection != NULL, NULL);
|
||||||
g_return_val_if_fail (message != NULL, NULL);
|
g_return_val_if_fail (message != NULL, NULL);
|
||||||
@@ -194,17 +159,16 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
nm_device_ref (dev);
|
|
||||||
|
|
||||||
data->data->forcing_device = TRUE;
|
|
||||||
nm_device_deactivate (dev, FALSE);
|
nm_device_deactivate (dev, FALSE);
|
||||||
|
|
||||||
nm_schedule_state_change_signal_broadcast (data->data);
|
nm_schedule_state_change_signal_broadcast (data->data);
|
||||||
nm_device_schedule_force_use (dev, essid, key, key_type);
|
|
||||||
|
if (nm_device_is_wireless (dev))
|
||||||
|
ap = nm_device_wireless_get_activation_ap (dev, essid, key, key_type);
|
||||||
|
nm_policy_schedule_device_activation (nm_act_request_new (data->data, dev, ap, TRUE));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
return reply;
|
||||||
return (reply);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -260,8 +224,6 @@ static DBusMessage *nm_dbus_nm_create_wireless_network (DBusConnection *connecti
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->data->forcing_device = TRUE;
|
|
||||||
|
|
||||||
new_ap = nm_ap_new ();
|
new_ap = nm_ap_new ();
|
||||||
|
|
||||||
/* Fill in the description of the network to create */
|
/* Fill in the description of the network to create */
|
||||||
@@ -275,12 +237,7 @@ static DBusMessage *nm_dbus_nm_create_wireless_network (DBusConnection *connecti
|
|||||||
nm_ap_set_mode (new_ap, NETWORK_MODE_ADHOC);
|
nm_ap_set_mode (new_ap, NETWORK_MODE_ADHOC);
|
||||||
nm_ap_set_user_created (new_ap, TRUE);
|
nm_ap_set_user_created (new_ap, TRUE);
|
||||||
|
|
||||||
nm_device_set_best_ap (dev, new_ap);
|
nm_policy_schedule_device_activation (nm_act_request_new (data->data, dev, new_ap, TRUE));
|
||||||
nm_device_freeze_best_ap (dev);
|
|
||||||
nm_device_activation_cancel (dev);
|
|
||||||
|
|
||||||
/* Schedule this device to be used next. */
|
|
||||||
nm_policy_schedule_device_switch (dev, data->data);
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
nm_device_unref (dev);
|
nm_device_unref (dev);
|
||||||
@@ -423,7 +380,7 @@ static DBusMessage *nm_dbus_nm_set_wireless_enabled (DBusConnection *connection,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
|
nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
|
||||||
nm_policy_schedule_state_update (app_data);
|
nm_policy_schedule_device_change_check (data->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -465,7 +422,7 @@ static DBusMessage *nm_dbus_nm_sleep (DBusConnection *connection, DBusMessage *m
|
|||||||
nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
|
nm_unlock_mutex (app_data->dev_list_mutex, __FUNCTION__);
|
||||||
|
|
||||||
nm_schedule_state_change_signal_broadcast (app_data);
|
nm_schedule_state_change_signal_broadcast (app_data);
|
||||||
nm_policy_schedule_state_update (app_data);
|
nm_policy_schedule_device_change_check (data->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -484,7 +441,7 @@ static DBusMessage *nm_dbus_nm_wake (DBusConnection *connection, DBusMessage *me
|
|||||||
app_data->asleep = FALSE;
|
app_data->asleep = FALSE;
|
||||||
|
|
||||||
nm_schedule_state_change_signal_broadcast (app_data);
|
nm_schedule_state_change_signal_broadcast (app_data);
|
||||||
nm_policy_schedule_state_update (app_data);
|
nm_policy_schedule_device_change_check (data->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -515,7 +472,6 @@ NMDbusMethodList *nm_dbus_nm_methods_setup (void)
|
|||||||
{
|
{
|
||||||
NMDbusMethodList *list = nm_dbus_method_list_new (NULL);
|
NMDbusMethodList *list = nm_dbus_method_list_new (NULL);
|
||||||
|
|
||||||
nm_dbus_method_list_add_method (list, "getActiveDevice", nm_dbus_nm_get_active_device);
|
|
||||||
nm_dbus_method_list_add_method (list, "getDevices", nm_dbus_nm_get_devices);
|
nm_dbus_method_list_add_method (list, "getDevices", nm_dbus_nm_get_devices);
|
||||||
nm_dbus_method_list_add_method (list, "setActiveDevice", nm_dbus_nm_set_active_device);
|
nm_dbus_method_list_add_method (list, "setActiveDevice", nm_dbus_nm_set_active_device);
|
||||||
nm_dbus_method_list_add_method (list, "createWirelessNetwork", nm_dbus_nm_create_wireless_network);
|
nm_dbus_method_list_add_method (list, "createWirelessNetwork", nm_dbus_nm_create_wireless_network);
|
||||||
|
@@ -268,12 +268,6 @@ nm_netlink_monitor_new (void)
|
|||||||
return NM_NETLINK_MONITOR (instance);
|
return NM_NETLINK_MONITOR (instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
nm_netlink_monitor_clear_event_source (NmNetlinkMonitor *monitor)
|
|
||||||
{
|
|
||||||
monitor->priv->event_source = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
nm_netlink_monitor_attach (NmNetlinkMonitor *monitor,
|
nm_netlink_monitor_attach (NmNetlinkMonitor *monitor,
|
||||||
GMainContext *context)
|
GMainContext *context)
|
||||||
@@ -296,7 +290,7 @@ nm_netlink_monitor_attach (NmNetlinkMonitor *monitor,
|
|||||||
(GSourceFunc) nm_netlink_monitor_event_handler,
|
(GSourceFunc) nm_netlink_monitor_event_handler,
|
||||||
monitor,
|
monitor,
|
||||||
(GDestroyNotify)
|
(GDestroyNotify)
|
||||||
nm_netlink_monitor_clear_event_source);
|
g_nullify_pointer);
|
||||||
g_source_attach (event_source, context);
|
g_source_attach (event_source, context);
|
||||||
monitor->priv->event_source = event_source;
|
monitor->priv->event_source = event_source;
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include "nm-vpn-connection.h"
|
#include "nm-vpn-connection.h"
|
||||||
#include "nm-vpn-service.h"
|
#include "nm-vpn-service.h"
|
||||||
#include "nm-dbus-vpn.h"
|
#include "nm-dbus-vpn.h"
|
||||||
|
#include "nm-activation-request.h"
|
||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
|
|
||||||
#define VPN_SERVICE_FILE_PATH SYSCONFDIR"/NetworkManager/VPN"
|
#define VPN_SERVICE_FILE_PATH SYSCONFDIR"/NetworkManager/VPN"
|
||||||
@@ -86,8 +87,8 @@ void nm_vpn_manager_dispose (NMVPNManager *manager)
|
|||||||
|
|
||||||
if (manager->active_config)
|
if (manager->active_config)
|
||||||
{
|
{
|
||||||
nm_system_remove_ip4_config_nameservers (manager->app_data->named, manager->active_config);
|
nm_system_remove_ip4_config_nameservers (manager->app_data->named_manager, manager->active_config);
|
||||||
nm_system_remove_ip4_config_search_domains (manager->app_data->named, manager->active_config);
|
nm_system_remove_ip4_config_search_domains (manager->app_data->named_manager, manager->active_config);
|
||||||
nm_ip4_config_unref (manager->active_config);
|
nm_ip4_config_unref (manager->active_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,8 +211,8 @@ static void nm_vpn_manager_set_active_vpn_connection (NMVPNManager *manager, NMV
|
|||||||
|
|
||||||
if (manager->active_config)
|
if (manager->active_config)
|
||||||
{
|
{
|
||||||
nm_system_remove_ip4_config_nameservers (manager->app_data->named, manager->active_config);
|
nm_system_remove_ip4_config_nameservers (manager->app_data->named_manager, manager->active_config);
|
||||||
nm_system_remove_ip4_config_search_domains (manager->app_data->named, manager->active_config);
|
nm_system_remove_ip4_config_search_domains (manager->app_data->named_manager, manager->active_config);
|
||||||
nm_ip4_config_unref (manager->active_config);
|
nm_ip4_config_unref (manager->active_config);
|
||||||
manager->active_config = NULL;
|
manager->active_config = NULL;
|
||||||
}
|
}
|
||||||
@@ -430,12 +431,16 @@ void nm_vpn_manager_handle_ip4_config_signal (NMVPNManager *manager, DBusMessage
|
|||||||
|
|
||||||
manager->active_device = g_strdup (tundev);
|
manager->active_device = g_strdup (tundev);
|
||||||
manager->active_config = config;
|
manager->active_config = config;
|
||||||
nm_system_vpn_device_set_from_ip4_config (manager->app_data->named, manager->app_data->active_device,
|
vpn_dev = nm_get_active_device (manager->app_data);
|
||||||
|
if (vpn_dev)
|
||||||
|
{
|
||||||
|
nm_system_vpn_device_set_from_ip4_config (manager->app_data->named_manager, vpn_dev,
|
||||||
manager->active_device, manager->active_config);
|
manager->active_device, manager->active_config);
|
||||||
if (login_banner && strlen (login_banner))
|
if (login_banner && strlen (login_banner))
|
||||||
nm_dbus_vpn_signal_vpn_login_banner (manager->app_data->dbus_connection, con, login_banner);
|
nm_dbus_vpn_signal_vpn_login_banner (manager->app_data->dbus_connection, con, login_banner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -726,6 +731,7 @@ void nm_vpn_manager_deactivate_vpn_connection (NMVPNManager *manager)
|
|||||||
const char * service_name;
|
const char * service_name;
|
||||||
NMVPNConnection * active;
|
NMVPNConnection * active;
|
||||||
NMIP4Config * config;
|
NMIP4Config * config;
|
||||||
|
NMDevice * dev;
|
||||||
|
|
||||||
g_return_if_fail (manager != NULL);
|
g_return_if_fail (manager != NULL);
|
||||||
|
|
||||||
@@ -753,8 +759,8 @@ out:
|
|||||||
nm_vpn_manager_set_active_vpn_connection (manager, NULL);
|
nm_vpn_manager_set_active_vpn_connection (manager, NULL);
|
||||||
nm_vpn_connection_unref (active);
|
nm_vpn_connection_unref (active);
|
||||||
|
|
||||||
if (manager->app_data->active_device)
|
if ((dev = nm_get_active_device (manager->app_data)))
|
||||||
nm_system_device_set_from_ip4_config (manager->app_data->active_device);
|
nm_system_device_set_from_ip4_config (dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@ AM_CPPFLAGS = \
|
|||||||
-DBINDIR=\"$(bindir)\" \
|
-DBINDIR=\"$(bindir)\" \
|
||||||
-DDATADIR=\"$(datadir)\"
|
-DDATADIR=\"$(datadir)\"
|
||||||
|
|
||||||
noinst_PROGRAMS = nmtest nminfotest nmtestdevices libnm_glib_test nm-dhcp-opt-test
|
noinst_PROGRAMS = nmtest nminfotest nmtestdevices libnm_glib_test
|
||||||
|
|
||||||
nmtest_SOURCES = nmtest.c
|
nmtest_SOURCES = nmtest.c
|
||||||
nmtest_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \
|
nmtest_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \
|
||||||
@@ -28,8 +28,3 @@ libnm_glib_test_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) \
|
|||||||
$(top_builddir)/utils/libnmutils.la \
|
$(top_builddir)/utils/libnmutils.la \
|
||||||
../gnome/libnm_glib/libnm_glib.la
|
../gnome/libnm_glib/libnm_glib.la
|
||||||
|
|
||||||
|
|
||||||
nm_dhcp_opt_test_SOURCES = nm-dhcp-opt-test.c
|
|
||||||
nm_dhcp_opt_test_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) \
|
|
||||||
$(top_builddir)/utils/libnmutils.la
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user