mirror of
https://github.com/Rudd-O/qubes-network-server.git
synced 2025-03-01 14:22:35 +01:00
Merge branch 'master' into r4.1
This commit is contained in:
commit
524f2f4341
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,3 +6,6 @@ pkgs/
|
|||||||
*.tar.gz
|
*.tar.gz
|
||||||
*.rpm
|
*.rpm
|
||||||
.*.swp
|
.*.swp
|
||||||
|
build
|
||||||
|
*.egg-info
|
||||||
|
src/*.service
|
||||||
|
339
COPYING
Normal file
339
COPYING
Normal file
@ -0,0 +1,339 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser General
|
||||||
|
Public License instead of this License.
|
17
Makefile
17
Makefile
@ -2,6 +2,7 @@ SBINDIR=/usr/local/sbin
|
|||||||
UNITDIR=/etc/systemd/system
|
UNITDIR=/etc/systemd/system
|
||||||
DESTDIR=
|
DESTDIR=
|
||||||
PROGNAME=qubes-network-server
|
PROGNAME=qubes-network-server
|
||||||
|
PYTHON=/usr/bin/python3
|
||||||
|
|
||||||
all: src/qubes-routing-manager.service
|
all: src/qubes-routing-manager.service
|
||||||
|
|
||||||
@ -10,11 +11,12 @@ src/qubes-routing-manager.service: src/qubes-routing-manager.service.in
|
|||||||
|
|
||||||
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
.PHONY: clean dist rpm srpm install
|
.PHONY: clean dist rpm srpm install-template install-dom0
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
find -name '*.pyc' -o -name '*~' -print0 | xargs -0 rm -f
|
cd $(ROOT_DIR) || exit $$? ; find -name '*.pyc' -o -name '*~' -print0 | xargs -0 rm -f
|
||||||
rm -rf *.tar.gz *.rpm
|
cd $(ROOT_DIR) || exit $$? ; rm -rf *.tar.gz *.rpm
|
||||||
|
cd $(ROOT_DIR) || exit $$? ; rm -rf *.egg-info build
|
||||||
|
|
||||||
dist: clean
|
dist: clean
|
||||||
@which rpmspec || { echo 'rpmspec is not available. Please install the rpm-build package with the command `dnf install rpm-build` to continue, then rerun this step.' ; exit 1 ; }
|
@which rpmspec || { echo 'rpmspec is not available. Please install the rpm-build package with the command `dnf install rpm-build` to continue, then rerun this step.' ; exit 1 ; }
|
||||||
@ -29,6 +31,13 @@ rpm: dist
|
|||||||
cd $(ROOT_DIR) || exit $$? ; rpmbuild --define "_srcrpmdir ." --define "_rpmdir builddir.rpm" -ta `rpmspec -q --queryformat '%{name}-%{version}.tar.gz\n' *spec | head -1`
|
cd $(ROOT_DIR) || exit $$? ; rpmbuild --define "_srcrpmdir ." --define "_rpmdir builddir.rpm" -ta `rpmspec -q --queryformat '%{name}-%{version}.tar.gz\n' *spec | head -1`
|
||||||
cd $(ROOT_DIR) ; mv -f builddir.rpm/*/* . && rm -rf builddir.rpm
|
cd $(ROOT_DIR) ; mv -f builddir.rpm/*/* . && rm -rf builddir.rpm
|
||||||
|
|
||||||
install: all
|
install-template: all
|
||||||
install -Dm 755 src/qubes-routing-manager -t $(DESTDIR)/$(SBINDIR)/
|
install -Dm 755 src/qubes-routing-manager -t $(DESTDIR)/$(SBINDIR)/
|
||||||
|
sed -i "s,^#!.*,#!$(PYTHON)," $(DESTDIR)/$(SBINDIR)/qubes-routing-manager
|
||||||
install -Dm 644 src/qubes-routing-manager.service -t $(DESTDIR)/$(UNITDIR)/
|
install -Dm 644 src/qubes-routing-manager.service -t $(DESTDIR)/$(UNITDIR)/
|
||||||
|
|
||||||
|
# Python 3 is always used for Qubes admin package.
|
||||||
|
install-dom0:
|
||||||
|
PYTHONDONTWRITEBYTECODE=1 python3 setup.py install $(PYTHON_PREFIX_ARG) -O0 --root $(DESTDIR)
|
||||||
|
|
||||||
|
install: install-dom0 install-template
|
||||||
|
@ -1,3 +1 @@
|
|||||||
ifneq ($(PACKAGE_SET),dom0)
|
|
||||||
RPM_SPEC_FILES=qubes-network-server.spec
|
RPM_SPEC_FILES=qubes-network-server.spec
|
||||||
endif
|
|
||||||
|
143
README.md
143
README.md
@ -33,7 +33,7 @@ which give the user control over outbound connections taking place from
|
|||||||
user VMs. ProxyVMs in turn attach to NetVMs, which provide outbound
|
user VMs. ProxyVMs in turn attach to NetVMs, which provide outbound
|
||||||
connectivity for ProxyVMs and other user VMs alike.
|
connectivity for ProxyVMs and other user VMs alike.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
No provision is made for running a server in a virtualized environment,
|
No provision is made for running a server in a virtualized environment,
|
||||||
such that the server's ports are accessible by (a) other VMs (b) machines
|
such that the server's ports are accessible by (a) other VMs (b) machines
|
||||||
@ -45,7 +45,7 @@ attack vectors. The Qubes OS user interface provides no help either.
|
|||||||
|
|
||||||
Qubes network server changes all that.
|
Qubes network server changes all that.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
With the Qubes network server software, it becomes possible to make
|
With the Qubes network server software, it becomes possible to make
|
||||||
network servers in user VMs available to other machines, be them
|
network servers in user VMs available to other machines, be them
|
||||||
@ -102,97 +102,20 @@ Here are documents that will help you take advantage of Qubes network server:
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Installation consists of two steps.
|
Installation consists of two steps:
|
||||||
|
|
||||||
### Apply software patch to `dom0`
|
1. Deploy the `qubes-core-admin-addon-network-server` RPM to your `dom0`.
|
||||||
|
2. Deploy the `qubes-network-server` RPM to the TemplateVM backing your
|
||||||
|
NetVM (which must be a Fedora instance). If your NetVM is a StandaloneVM,
|
||||||
|
then you must deploy this RPM to the NetVM directly.
|
||||||
|
|
||||||
The first step is to apply a patch to your Qubes OS `dom0`.
|
After that, to make it all take effect:
|
||||||
The patch is distributed in the source, within the `src/` directory.
|
|
||||||
Future releases of this software will contain a better method for
|
|
||||||
deploying the `dom0` part of the software.
|
|
||||||
|
|
||||||
Copy the patch to your `dom0` somehow, then apply it:
|
1. Power off the TemplateVM.
|
||||||
|
2. Reboot the NetVM.
|
||||||
|
|
||||||
```
|
You're done. You can verify that the necessary component is running by launching
|
||||||
# Change into the Python 3.5 site-packages directory.
|
a terminal in your NetVM, then typing the following:
|
||||||
cd /usr/lib/python3.5/site-packages
|
|
||||||
|
|
||||||
# Back up your `net.py` file.
|
|
||||||
if ! test -f qubes/vm/mix/net.py.bak
|
|
||||||
sudo cp qubes/vm/mix/net.py qubes/vm/mix/net.py.bak
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Patch the `net.py` file.
|
|
||||||
sudo patch -p1 < /home/user/qubes-network-server-dom0.patch
|
|
||||||
|
|
||||||
# Restart qubesd.
|
|
||||||
sudo systemctl restart qubesd.service
|
|
||||||
```
|
|
||||||
|
|
||||||
You can now verify that `qubesd` is running:
|
|
||||||
|
|
||||||
```
|
|
||||||
sudo systemctl status qubesd.service | cat
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Restoring from backup in case of failed installation.
|
|
||||||
|
|
||||||
If `qubesd` has failed for some reason, you can restore
|
|
||||||
from the backup and restart again. This will nullify
|
|
||||||
the changes you made in this routine. To restore from
|
|
||||||
the backup, use the following commands:
|
|
||||||
|
|
||||||
```
|
|
||||||
udo cp qubes/vm/mix/net.py.bak qubes/vm/mix/net.py
|
|
||||||
sudo systemctl restart qubesd.service
|
|
||||||
```
|
|
||||||
|
|
||||||
### Install the agent in the TemplateVM
|
|
||||||
|
|
||||||
The second step is to build and install the component that goes
|
|
||||||
in the TemplateVM that your NetVM (typically `sys-net` uses).
|
|
||||||
If your NetVM is a StandaloneVM, you should modify these instructions
|
|
||||||
to install the component directly in the NetVM, as in this case
|
|
||||||
your NetVM does not instantiation from a Qubes template.
|
|
||||||
|
|
||||||
Within a DisposableVM, build said package as follows:
|
|
||||||
|
|
||||||
```
|
|
||||||
# Dependencies
|
|
||||||
dnf install git rpm-build make coreutils tar gawk findutils systemd systemd-rpm-macros
|
|
||||||
# Source code
|
|
||||||
git clone https://github.com/Rudd-O/qubes-network-server
|
|
||||||
# <make sure you are in the correct branch now>
|
|
||||||
cd qubes-network-server
|
|
||||||
make rpm
|
|
||||||
```
|
|
||||||
|
|
||||||
The process will output a `qubes-network-server-*.noarch.rpm` in the
|
|
||||||
directory where it ran. Copy that RPM to your TemplateVM. Here is
|
|
||||||
a trick to do that from `dom0`, which fetchs the RPM file from the DisposableVM
|
|
||||||
and saves it within the TemplateVM, which you can then feed as an argument
|
|
||||||
to the `rpm -ivh` command:
|
|
||||||
|
|
||||||
```
|
|
||||||
qvm-run --pass-io disp8474 'cat /home/user/qubes-network-server/qubes-network-server*.noarch.rpm' | \
|
|
||||||
qvm-run --pass-io fedora-30 'cat > qns.rpm'
|
|
||||||
```
|
|
||||||
|
|
||||||
You can power off the DisposableVM now.
|
|
||||||
|
|
||||||
Now you can install this package in your TemplateVM (or NetVM, if it is a StandaloneVM):
|
|
||||||
|
|
||||||
```
|
|
||||||
# (In TemplateVM)
|
|
||||||
# rpm -ivh qns.rpm
|
|
||||||
```
|
|
||||||
|
|
||||||
Now power off both your TemplateVM and your NetVM.
|
|
||||||
|
|
||||||
Then start your NetVM back up.
|
|
||||||
|
|
||||||
You can verify that the necessary component is running by launching a terminal
|
|
||||||
in your NetVM, then typing the following:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
systemctl status qubes-routing-manager.service
|
systemctl status qubes-routing-manager.service
|
||||||
@ -200,11 +123,51 @@ systemctl status qubes-routing-manager.service
|
|||||||
|
|
||||||
The routing manager should show as `enabled` and `active` in the terminal output.
|
The routing manager should show as `enabled` and `active` in the terminal output.
|
||||||
|
|
||||||
|
### How to build the packages to install
|
||||||
|
|
||||||
|
You will first build the `qubes-core-admin-addon-network-server` RPM.
|
||||||
|
|
||||||
|
To build this package, you will need to use a `chroot` jail containing
|
||||||
|
a Fedora installation of the exact same release as your `dom0` (Fedora 25
|
||||||
|
for Qubes release 4.0, Fedora 31 for Qubes release 4.1).
|
||||||
|
|
||||||
|
Copy the source of the package to your `chroot`. Then start a shell in
|
||||||
|
your `chroot`, and type `make rpm`. You may have to install some packages
|
||||||
|
in your `chroot` -- use `dnf install git rpm-build make coreutils tar gawk findutils systemd systemd-rpm-macros`
|
||||||
|
to get the minimum dependency set installed.
|
||||||
|
|
||||||
|
Once built, in the source directory you will find the RPM built for the
|
||||||
|
exact release of Qubes you need.
|
||||||
|
|
||||||
|
Alternatively, you may first create a source RPM using `make srpm` on your
|
||||||
|
regular workstation, then use `mock` to rebuild the source RPM produced
|
||||||
|
in the source directory, using a Fedora release compatible with your `dom0`.
|
||||||
|
|
||||||
|
To build the `qubes-network-server` RPM, you can use a DisposableVM running
|
||||||
|
the same Fedora release as your NetVM. Build said package as follows:
|
||||||
|
|
||||||
|
```
|
||||||
|
# Dependencies
|
||||||
|
dnf install git rpm-build make coreutils tar gawk findutils systemd systemd-rpm-macros
|
||||||
|
# Source code
|
||||||
|
cd /path/to/qubes-network-server
|
||||||
|
# <make sure you are in the correct branch now>
|
||||||
|
make rpm
|
||||||
|
```
|
||||||
|
|
||||||
|
The process will output a `qubes-network-server-*.noarch.rpm` in the
|
||||||
|
directory where it ran. Fish it out and save it into the VM where you'll
|
||||||
|
install it.
|
||||||
|
|
||||||
|
You can power off the DisposableVM now.
|
||||||
|
|
||||||
### Upgrading to new / bug-fixing releases
|
### Upgrading to new / bug-fixing releases
|
||||||
|
|
||||||
Follow the same procedures as above, but when asked to install the package
|
Follow the same procedures as above, but when asked to install the packages
|
||||||
with `rpm -ivh`, change it to `rpm -Uvh` (uppercase U for upgrade).
|
with `rpm -ivh`, change it to `rpm -Uvh` (uppercase U for upgrade).
|
||||||
|
|
||||||
|
Always restart your NetVMs between upgrades.
|
||||||
|
|
||||||
## Theory of operation
|
## Theory of operation
|
||||||
|
|
||||||
Qubes OS relies on layer 3 (IP) routing. VMs in its networked tree send traffic through
|
Qubes OS relies on layer 3 (IP) routing. VMs in its networked tree send traffic through
|
||||||
|
@ -1,47 +1,84 @@
|
|||||||
%{!?python2_sitearch: %define python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
|
|
||||||
|
|
||||||
%define debug_package %{nil}
|
%define debug_package %{nil}
|
||||||
|
|
||||||
%define mybuildnumber %{?build_number}%{?!build_number:1}
|
%define mybuildnumber %{?build_number}%{?!build_number:1}
|
||||||
|
|
||||||
Name: qubes-network-server
|
Name: qubes-network-server
|
||||||
Version: 0.0.12
|
Version: 0.0.13
|
||||||
Release: %{mybuildnumber}%{?dist}
|
Release: %{mybuildnumber}%{?dist}
|
||||||
Summary: Turn your Qubes OS into a network server
|
Summary: Turn your Qubes OS into a network server
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
|
|
||||||
License: GPLv3+
|
License: GPLv2+
|
||||||
URL: https://github.com/Rudd-O/qubes-network-server
|
URL: https://github.com/Rudd-O/qubes-network-server
|
||||||
Source0: https://github.com/Rudd-O/%{name}/archive/{%version}.tar.gz#/%{name}-%{version}.tar.gz
|
Source0: https://github.com/Rudd-O/%{name}/archive/{%version}.tar.gz#/%{name}-%{version}.tar.gz
|
||||||
|
|
||||||
BuildRequires: make
|
BuildRequires: make
|
||||||
BuildRequires: coreutils
|
BuildRequires: coreutils
|
||||||
BuildRequires: tar
|
BuildRequires: tar
|
||||||
BuildRequires: gawk
|
|
||||||
BuildRequires: findutils
|
BuildRequires: findutils
|
||||||
BuildRequires: systemd
|
%if 0%{?fedora} < 31
|
||||||
|
BuildRequires: python2
|
||||||
|
BuildRequires: python2-rpm-macros
|
||||||
|
%global pythoninterp %{_bindir}/python2
|
||||||
|
%else
|
||||||
|
BuildRequires: python3
|
||||||
|
BuildRequires: python3-rpm-macros
|
||||||
|
%global pythoninterp %{_bindir}/python3
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%if 0%{?fedora} > 29
|
||||||
BuildRequires: systemd-rpm-macros
|
BuildRequires: systemd-rpm-macros
|
||||||
|
%else
|
||||||
|
%global _presetdir %{_prefix}/lib/systemd/system-preset
|
||||||
|
%global _unitdir %{_prefix}/lib/systemd/system
|
||||||
|
%endif
|
||||||
|
|
||||||
Requires: qubes-core-agent-networking >= 4.1
|
Requires: qubes-core-agent-networking >= 4.1
|
||||||
Requires: python3
|
Requires: python3
|
||||||
Requires: python3-qubesdb
|
Requires: python3-qubesdb
|
||||||
|
|
||||||
%description
|
%description
|
||||||
This package lets you turn your Qubes OS into a network server.
|
This package lets you turn your Qubes OS into a network server. Install this
|
||||||
|
in the TemplateVM of your NetVM. Then install the companion
|
||||||
|
qubes-core-admin-addon-network-server package in your dom0.
|
||||||
|
|
||||||
Please see README.md enclosed in the package for instructions on how to use this.
|
Please see README.md enclosed in the package for instructions on how to use
|
||||||
|
this software.
|
||||||
|
|
||||||
|
%package -n qubes-core-admin-addon-network-server
|
||||||
|
Summary: dom0 administrative extension for Qubes network server
|
||||||
|
|
||||||
|
BuildRequires: make
|
||||||
|
BuildRequires: coreutils
|
||||||
|
BuildRequires: tar
|
||||||
|
BuildRequires: findutils
|
||||||
|
BuildRequires: python3
|
||||||
|
BuildRequires: python3-rpm-macros
|
||||||
|
BuildRequires: python3-setuptools
|
||||||
|
|
||||||
|
Requires: python3
|
||||||
|
Requires: qubes-core-dom0 >= 4.0.49-1
|
||||||
|
Conflicts: qubes-core-dom0 >= 4.1
|
||||||
|
|
||||||
|
%description -n qubes-core-admin-addon-network-server
|
||||||
|
This package lets you turn your Qubes OS into a network server. Install this
|
||||||
|
in your dom0. Then install the companion qubes-network-server package in the
|
||||||
|
TemplateVM of your NetVM.
|
||||||
|
|
||||||
|
Please see README.md enclosed in the package for instructions on how to use
|
||||||
|
this software.
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup -q
|
%setup -q
|
||||||
|
|
||||||
%build
|
%build
|
||||||
# variables must be kept in sync with install
|
# variables must be kept in sync with install
|
||||||
make DESTDIR=$RPM_BUILD_ROOT SBINDIR=%{_sbindir} UNITDIR=%{_unitdir}
|
make DESTDIR=$RPM_BUILD_ROOT SBINDIR=%{_sbindir} UNITDIR=%{_unitdir} PYTHON=%{pythoninterp}
|
||||||
|
|
||||||
%install
|
%install
|
||||||
rm -rf $RPM_BUILD_ROOT
|
rm -rf $RPM_BUILD_ROOT
|
||||||
# variables must be kept in sync with build
|
# variables must be kept in sync with build
|
||||||
make install DESTDIR=$RPM_BUILD_ROOT SBINDIR=%{_sbindir} UNITDIR=%{_unitdir}
|
make install DESTDIR=$RPM_BUILD_ROOT SBINDIR=%{_sbindir} UNITDIR=%{_unitdir} PYTHON=%{pythoninterp}
|
||||||
mkdir -p "$RPM_BUILD_ROOT"/%{_presetdir}
|
mkdir -p "$RPM_BUILD_ROOT"/%{_presetdir}
|
||||||
echo 'enable qubes-routing-manager.service' > "$RPM_BUILD_ROOT"/%{_presetdir}/75-%{name}.preset
|
echo 'enable qubes-routing-manager.service' > "$RPM_BUILD_ROOT"/%{_presetdir}/75-%{name}.preset
|
||||||
|
|
||||||
@ -51,6 +88,10 @@ echo 'enable qubes-routing-manager.service' > "$RPM_BUILD_ROOT"/%{_presetdir}/75
|
|||||||
%config %attr(0644, root, root) %{_unitdir}/qubes-routing-manager.service
|
%config %attr(0644, root, root) %{_unitdir}/qubes-routing-manager.service
|
||||||
%doc README.md TODO
|
%doc README.md TODO
|
||||||
|
|
||||||
|
%files -n qubes-core-admin-addon-network-server
|
||||||
|
%attr(0644, root, root) %{python3_sitelib}/qubesnetworkserver
|
||||||
|
%{python3_sitelib}/qubesnetworkserver-*.egg-info
|
||||||
|
|
||||||
%post
|
%post
|
||||||
%systemd_post qubes-routing-manager.service
|
%systemd_post qubes-routing-manager.service
|
||||||
|
|
||||||
@ -60,6 +101,20 @@ echo 'enable qubes-routing-manager.service' > "$RPM_BUILD_ROOT"/%{_presetdir}/75
|
|||||||
%postun
|
%postun
|
||||||
%systemd_postun_with_restart qubes-routing-manager.service
|
%systemd_postun_with_restart qubes-routing-manager.service
|
||||||
|
|
||||||
|
%post -n qubes-core-admin-addon-network-server
|
||||||
|
%if 0%{?fedora} > 29
|
||||||
|
%systemd_post qubesd.service
|
||||||
|
%else
|
||||||
|
systemctl try-restart qubesd.service
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%postun -n qubes-core-admin-addon-network-server
|
||||||
|
%if 0%{?fedora} > 29
|
||||||
|
%systemd_postun_with_restart qubesd.service
|
||||||
|
%else
|
||||||
|
systemctl try-restart qubesd.service
|
||||||
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
* Mon Apr 13 2020 Manuel Amador (Rudd-O) <rudd-o@rudd-o.com>
|
* Mon Apr 13 2020 Manuel Amador (Rudd-O) <rudd-o@rudd-o.com>
|
||||||
- Update to Qubes 4.0
|
- Update to Qubes 4.0
|
||||||
|
98
qubesnetworkserver/__init__.py
Normal file
98
qubesnetworkserver/__init__.py
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
import qubes.ext
|
||||||
|
import qubes.vm.templatevm
|
||||||
|
|
||||||
|
|
||||||
|
class QubesNetworkServerExtension(qubes.ext.Extension):
|
||||||
|
|
||||||
|
def shutdown_routing_for_vm(self, netvm, appvm):
|
||||||
|
self.reload_routing_for_vm(netvm, appvm, True)
|
||||||
|
|
||||||
|
def reload_routing_for_vm(self, netvm, appvm, shutdown=False):
|
||||||
|
'''Reload the routing method for the VM.'''
|
||||||
|
if not netvm.is_running():
|
||||||
|
return
|
||||||
|
for addr_family in (4, 6):
|
||||||
|
ip = appvm.ip6 if addr_family == 6 else appvm.ip
|
||||||
|
if ip is None:
|
||||||
|
continue
|
||||||
|
# report routing method
|
||||||
|
self.setup_forwarding_for_vm(netvm, appvm, ip, remove=shutdown)
|
||||||
|
|
||||||
|
def setup_forwarding_for_vm(self, netvm, appvm, ip, remove=False):
|
||||||
|
'''
|
||||||
|
Record in Qubes DB that the passed VM may be meant to have traffic
|
||||||
|
forwarded to and from it, rather than masqueraded from it and blocked
|
||||||
|
to it.
|
||||||
|
|
||||||
|
The relevant incantation on the command line to assign the forwarding
|
||||||
|
behavior is `qvm-features <VM> routing-method forward`. If the feature
|
||||||
|
is set on the TemplateVM upon which the VM is based, then that counts
|
||||||
|
as the forwarding method for the VM as well.
|
||||||
|
|
||||||
|
The counterpart code in qubes-firewall handles setting up the NetVM
|
||||||
|
with the proper networking configuration to permit forwarding without
|
||||||
|
masquerading behavior.
|
||||||
|
|
||||||
|
If `remove` is True, then we remove the respective routing method from
|
||||||
|
the Qubes DB instead.
|
||||||
|
'''
|
||||||
|
if ip is None:
|
||||||
|
return
|
||||||
|
routing_method = appvm.features.check_with_template(
|
||||||
|
'routing-method', 'masquerade'
|
||||||
|
)
|
||||||
|
base_file = '/qubes-routing-method/{}'.format(ip)
|
||||||
|
if remove:
|
||||||
|
netvm.untrusted_qdb.rm(base_file)
|
||||||
|
elif routing_method == 'forward':
|
||||||
|
netvm.untrusted_qdb.write(base_file, 'forward')
|
||||||
|
else:
|
||||||
|
netvm.untrusted_qdb.write(base_file, 'masquerade')
|
||||||
|
|
||||||
|
@qubes.ext.handler(
|
||||||
|
'domain-feature-set:routing-method',
|
||||||
|
'domain-feature-delete:routing-method',
|
||||||
|
)
|
||||||
|
def on_routing_method_changed(
|
||||||
|
self,
|
||||||
|
vm,
|
||||||
|
ignored_feature,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
# pylint: disable=no-self-use,unused-argument
|
||||||
|
if 'oldvalue' not in kwargs or kwargs.get('oldvalue') != kwargs.get('value'):
|
||||||
|
if vm.netvm:
|
||||||
|
self.reload_routing_for_vm(vm.netvm, vm)
|
||||||
|
|
||||||
|
@qubes.ext.handler('domain-qdb-create')
|
||||||
|
def on_domain_qdb_create(self, vm, event, **kwargs):
|
||||||
|
''' Fills the QubesDB with firewall entries. '''
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
if vm.netvm:
|
||||||
|
self.reload_routing_for_vm(vm.netvm, vm)
|
||||||
|
|
||||||
|
@qubes.ext.handler('domain-start')
|
||||||
|
def on_domain_started(self, vm, event, **kwargs):
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
try:
|
||||||
|
for downstream_vm in vm.connected_vms:
|
||||||
|
self.reload_routing_for_vm(vm, downstream_vm)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@qubes.ext.handler('domain-shutdown')
|
||||||
|
def on_domain_shutdown(self, vm, event, **kwargs):
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
try:
|
||||||
|
for downstream_vm in self.connected_vms:
|
||||||
|
self.shutdown_routing_for_vm(vm, downstream_vm)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
if vm.netvm:
|
||||||
|
self.shutdown_routing_for_vm(vm.netvm, vm)
|
||||||
|
|
||||||
|
@qubes.ext.handler('net-domain-connect')
|
||||||
|
def on_net_domain_connect(self, vm, event):
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
if vm.netvm:
|
||||||
|
self.reload_routing_for_vm(vm.netvm, vm)
|
24
setup.py
Normal file
24
setup.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import os
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
version = open(os.path.join(os.path.dirname(__file__), 'qubes-network-server.spec')).read().strip()
|
||||||
|
version = [v for v in version.splitlines() if v.startswith("Version:")][0]
|
||||||
|
version = version.split()[-1]
|
||||||
|
setuptools.setup(
|
||||||
|
name='qubesnetworkserver',
|
||||||
|
version=version,
|
||||||
|
author='Manuel Amador (Rudd-O)',
|
||||||
|
author_email='rudd-o@rudd-o.com',
|
||||||
|
description='Qubes network server dom0 component',
|
||||||
|
license='GPL2+',
|
||||||
|
url='https://github.com/Rudd-O/qubes-network-server',
|
||||||
|
|
||||||
|
packages=('qubesnetworkserver',),
|
||||||
|
|
||||||
|
entry_points={
|
||||||
|
'qubes.ext': [
|
||||||
|
'qubesnetworkserver = qubesnetworkserver:QubesNetworkServerExtension',
|
||||||
|
],
|
||||||
|
}
|
||||||
|
)
|
@ -1,153 +0,0 @@
|
|||||||
commit 88e88244d38a91ab0628ba2b6dad60ea692c14e0
|
|
||||||
Author: Manuel Amador (Rudd-O) <rudd-o@rudd-o.com>
|
|
||||||
Date: Tue Apr 14 00:27:10 2020 +0000
|
|
||||||
|
|
||||||
AdminVM support for Qubes network server (release 4.1).
|
|
||||||
|
|
||||||
These modifications create a new feature `routing-method` which defaults to the normal Qubes OS behavior of masquerading outgoing traffic from AppVMs. When the `routing-method` feature is set on a VM, its value is written to a `/qubes-routing-method/<IP>` Qubes DB entry within its NetVM.
|
|
||||||
|
|
||||||
NetVMs can thus use that information to switch from masquerading to normal IP forwarding for VMs designated with `routing-method=forward` by the administrator.
|
|
||||||
|
|
||||||
Other than creating the necessary `/qubes-routing-method/<IP>` hierarchy in Qubes DB, this code does nothing else.
|
|
||||||
|
|
||||||
This feature does not yet support chains of NetVMs -- only the NetVM directly attached to the AppVM is affected.
|
|
||||||
|
|
||||||
To see the companion agent that uses this new Qubes DB information, please refer to branch `r4.0` of https://github.com/Rudd-O/qubes-network-server/tree/r4.0 . The agent in that branch supports reading from the `/qubes-routing-method` tree to configure the NetVM appropriately.
|
|
||||||
|
|
||||||
I am working, in parallel, on a Qubes OS >= 4.1.compatible implementation.
|
|
||||||
|
|
||||||
diff --git a/qubes/vm/mix/net.py b/qubes/vm/mix/net.py
|
|
||||||
index a5e3f0e5..d22b4ef3 100644
|
|
||||||
--- a/qubes/vm/mix/net.py
|
|
||||||
+++ b/qubes/vm/mix/net.py
|
|
||||||
@@ -262,6 +262,8 @@ class NetVMMixin(qubes.events.Emitter):
|
|
||||||
This will allow re-reconnecting them cleanly later.
|
|
||||||
'''
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
+ if self.netvm:
|
|
||||||
+ self.netvm.shutdown_routing_for_vm(self)
|
|
||||||
for vm in self.connected_vms:
|
|
||||||
if not vm.is_running():
|
|
||||||
continue
|
|
||||||
@@ -271,6 +273,19 @@ class NetVMMixin(qubes.events.Emitter):
|
|
||||||
# ignore errors
|
|
||||||
pass
|
|
||||||
|
|
||||||
+ @qubes.ext.handler(
|
|
||||||
+ 'domain-feature-set:routing-method',
|
|
||||||
+ 'domain-feature-delete:routing-method',
|
|
||||||
+ )
|
|
||||||
+ def on_routing_method_changed(
|
|
||||||
+ self,
|
|
||||||
+ event, feature,
|
|
||||||
+ value=None, oldvalue=None
|
|
||||||
+ ):
|
|
||||||
+ # pylint: disable=unused-argument
|
|
||||||
+ if self.netvm:
|
|
||||||
+ self.netvm.reload_routing_for_vm(self)
|
|
||||||
+
|
|
||||||
@qubes.events.handler('domain-start')
|
|
||||||
def on_domain_started(self, event, **kwargs):
|
|
||||||
'''Connect this domain to its downstream domains. Also reload firewall
|
|
||||||
@@ -281,6 +296,7 @@ class NetVMMixin(qubes.events.Emitter):
|
|
||||||
|
|
||||||
if self.netvm:
|
|
||||||
self.netvm.reload_firewall_for_vm(self) # pylint: disable=no-member
|
|
||||||
+ self.netvm.reload_routing_for_vm(self) # pylint: disable=no-member
|
|
||||||
|
|
||||||
for vm in self.connected_vms:
|
|
||||||
if not vm.is_running():
|
|
||||||
@@ -350,6 +366,20 @@ class NetVMMixin(qubes.events.Emitter):
|
|
||||||
|
|
||||||
return self.netvm is not None
|
|
||||||
|
|
||||||
+ def shutdown_routing_for_vm(self, vm):
|
|
||||||
+ self.reload_routing_for_vm(vm, True)
|
|
||||||
+
|
|
||||||
+ def reload_routing_for_vm(self, vm, shutdown=False):
|
|
||||||
+ '''Reload the routing method for the VM.'''
|
|
||||||
+ if not self.is_running():
|
|
||||||
+ return
|
|
||||||
+ for addr_family in (4, 6):
|
|
||||||
+ ip = vm.ip6 if addr_family == 6 else vm.ip
|
|
||||||
+ if ip is None:
|
|
||||||
+ continue
|
|
||||||
+ # report routing method
|
|
||||||
+ self.setup_non_masquerade_forwarding_for_vm(vm, ip, remove=shutdown)
|
|
||||||
+
|
|
||||||
def reload_firewall_for_vm(self, vm):
|
|
||||||
''' Reload the firewall rules for the vm '''
|
|
||||||
if not self.is_running():
|
|
||||||
@@ -370,6 +400,35 @@ class NetVMMixin(qubes.events.Emitter):
|
|
||||||
# signal its done
|
|
||||||
self.untrusted_qdb.write(base_dir[:-1], '')
|
|
||||||
|
|
||||||
+ def setup_non_masquerade_forwarding_for_vm(self, vm, ip, remove=False):
|
|
||||||
+ '''
|
|
||||||
+ Record in Qubes DB that the passed VM may be meant to have traffic
|
|
||||||
+ forwarded to and from it, rather than masqueraded from it and blocked
|
|
||||||
+ to it.
|
|
||||||
+
|
|
||||||
+ The relevant incantation on the command line to assign the forwarding
|
|
||||||
+ behavior is `qvm-features <VM> routing-method forward`. If the feature
|
|
||||||
+ is set on the TemplateVM upon which the VM is based, then that counts
|
|
||||||
+ as the forwarding method for the VM as well.
|
|
||||||
+
|
|
||||||
+ The counterpart code in qubes-firewall handles setting up the NetVM
|
|
||||||
+ with the proper networking configuration to permit forwarding without
|
|
||||||
+ masquerading behavior.
|
|
||||||
+
|
|
||||||
+ If `remove` is True, then we remove the respective routing method from
|
|
||||||
+ the Qubes DB instead.
|
|
||||||
+ '''
|
|
||||||
+ if ip is None:
|
|
||||||
+ return
|
|
||||||
+ routing_method = vm.features.check_with_template('routing-method', 'masquerade')
|
|
||||||
+ base_file = '/qubes-routing-method/{}'.format(ip)
|
|
||||||
+ if remove:
|
|
||||||
+ self.untrusted_qdb.rm(base_file)
|
|
||||||
+ elif routing_method == 'forward':
|
|
||||||
+ self.untrusted_qdb.write(base_file, 'forward')
|
|
||||||
+ else:
|
|
||||||
+ self.untrusted_qdb.write(base_file, 'masquerade')
|
|
||||||
+
|
|
||||||
def set_mapped_ip_info_for_vm(self, vm):
|
|
||||||
'''
|
|
||||||
Set configuration to possibly hide real IP from the VM.
|
|
||||||
@@ -467,6 +526,11 @@ class NetVMMixin(qubes.events.Emitter):
|
|
||||||
self.create_qdb_entries()
|
|
||||||
self.attach_network()
|
|
||||||
|
|
||||||
+ if oldvalue is not None and oldvalue.is_running():
|
|
||||||
+ # Delete now obsolete IP from the
|
|
||||||
+ # attached NetVM.
|
|
||||||
+ oldvalue.reload_routing_for_vm(self)
|
|
||||||
+
|
|
||||||
newvalue.fire_event('net-domain-connect', vm=self)
|
|
||||||
|
|
||||||
@qubes.events.handler('net-domain-connect')
|
|
||||||
@@ -474,6 +538,7 @@ class NetVMMixin(qubes.events.Emitter):
|
|
||||||
''' Reloads the firewall config for vm '''
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
self.reload_firewall_for_vm(vm)
|
|
||||||
+ self.reload_routing_for_vm(vm)
|
|
||||||
|
|
||||||
@qubes.events.handler('domain-qdb-create')
|
|
||||||
def on_domain_qdb_create(self, event):
|
|
||||||
@@ -486,6 +551,7 @@ class NetVMMixin(qubes.events.Emitter):
|
|
||||||
if vm.is_running():
|
|
||||||
self.set_mapped_ip_info_for_vm(vm)
|
|
||||||
self.reload_firewall_for_vm(vm)
|
|
||||||
+ self.reload_routing_for_vm(vm)
|
|
||||||
|
|
||||||
@qubes.events.handler('firewall-changed', 'domain-spawn')
|
|
||||||
def on_firewall_changed(self, event, **kwargs):
|
|
||||||
@@ -494,7 +560,7 @@ class NetVMMixin(qubes.events.Emitter):
|
|
||||||
if self.is_running() and self.netvm:
|
|
||||||
self.netvm.reload_connected_ips()
|
|
||||||
self.netvm.set_mapped_ip_info_for_vm(self)
|
|
||||||
- self.netvm.reload_firewall_for_vm(self) # pylint: disable=no-member
|
|
||||||
+ self.netvm.reload_firewall_for_vm(self)
|
|
||||||
|
|
||||||
# CORE2: swallowed get_firewall_conf, write_firewall_conf,
|
|
||||||
# get_firewall_defaults
|
|
@ -1,54 +1,62 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
'''
|
"""
|
||||||
This program reads the /qubes-firewall/{ip}/qubes-routing-method file
|
This program reads the /qubes-firewall/{ip}/qubes-routing-method file
|
||||||
for any firewall configuration, then configures the network to obey
|
for any firewall configuration, then configures the network to obey
|
||||||
the routing method for the VM. If the routing method is "masquerade",
|
the routing method for the VM. If the routing method is "masquerade",
|
||||||
then nothing happens. If, however, the routing method is "forward",
|
then nothing happens. If, however, the routing method is "forward",
|
||||||
then VM-specific rules are enacted in the VM's attached NetVM to allow
|
then VM-specific rules are enacted in the VM's attached NetVM to allow
|
||||||
traffic coming from other VMs and the outside world to reach this VM.
|
traffic coming from other VMs and the outside world to reach this VM.
|
||||||
'''
|
"""
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
import logging
|
import logging
|
||||||
import qubesdb
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import socket
|
import socket
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import qubesdb
|
||||||
|
|
||||||
|
|
||||||
FORWARD_ROUTING_METHOD = 'forward'
|
def _s(v):
|
||||||
|
if isinstance(v, bytes):
|
||||||
|
return v.decode("utf-8")
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
FORWARD_ROUTING_METHOD = "forward"
|
||||||
|
|
||||||
|
|
||||||
class AdjunctWorker(object):
|
class AdjunctWorker(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.qdb = qubesdb.QubesDB()
|
self.qdb = qubesdb.QubesDB()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_ip6(addr):
|
def is_ip6(addr):
|
||||||
return addr.count(':') > 0
|
return addr.count(":") > 0
|
||||||
|
|
||||||
def setup_plain_forwarding_for_address(self, source, enable, family):
|
def setup_plain_forwarding_for_address(self, source, enable, family):
|
||||||
|
|
||||||
def find_pos_of_first_rule(table, startswith):
|
def find_pos_of_first_rule(table, startswith):
|
||||||
rules = [n for n, l in enumerate(out) if l.startswith(startswith)]
|
rules = [n for n, l in enumerate(out) if l.startswith(startswith)]
|
||||||
if rules:
|
if rules:
|
||||||
return rules[0]
|
return rules[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
cmd = 'ip6tables' if family == 6 else 'iptables'
|
cmd = "ip6tables" if family == 6 else "iptables"
|
||||||
mask = '/128' if family == 6 else '/32'
|
mask = "/128" if family == 6 else "/32"
|
||||||
def run_ipt(*args):
|
|
||||||
return subprocess.check_call([cmd, '-w'] + list(args))
|
|
||||||
|
|
||||||
out = subprocess.check_output([cmd + '-save', '-w'], universal_newlines=True).splitlines()
|
def run_ipt(*args):
|
||||||
|
return subprocess.check_call([cmd, "-w"] + list(args))
|
||||||
|
|
||||||
|
out = subprocess.check_output(
|
||||||
|
[cmd + "-save"], universal_newlines=True
|
||||||
|
).splitlines()
|
||||||
|
|
||||||
if enable:
|
if enable:
|
||||||
# Create necessary prerouting chain.
|
# Create necessary prerouting chain.
|
||||||
if not find_pos_of_first_rule(out, ':PR-PLAIN-FORWARDING - '):
|
if not find_pos_of_first_rule(out, ":PR-PLAIN-FORWARDING - "):
|
||||||
run_ipt('-t', 'nat', '-N', 'PR-PLAIN-FORWARDING')
|
run_ipt("-t", "nat", "-N", "PR-PLAIN-FORWARDING")
|
||||||
|
|
||||||
# Route prerouting traffic to necessary chain.
|
# Route prerouting traffic to necessary chain.
|
||||||
if not find_pos_of_first_rule(out, "-A POSTROUTING -j PR-PLAIN-FORWARDING"):
|
if not find_pos_of_first_rule(out, "-A POSTROUTING -j PR-PLAIN-FORWARDING"):
|
||||||
rule_num = find_pos_of_first_rule(out, "-A POSTROUTING -j MASQUERADE")
|
rule_num = find_pos_of_first_rule(out, "-A POSTROUTING -j MASQUERADE")
|
||||||
@ -59,15 +67,25 @@ class AdjunctWorker(object):
|
|||||||
first_rule_num = find_pos_of_first_rule(out, "-A POSTROUTING")
|
first_rule_num = find_pos_of_first_rule(out, "-A POSTROUTING")
|
||||||
pos = rule_num - first_rule_num + 1
|
pos = rule_num - first_rule_num + 1
|
||||||
logging.info("Adding POSTROUTING chain PR-PLAIN-FORWARDING.")
|
logging.info("Adding POSTROUTING chain PR-PLAIN-FORWARDING.")
|
||||||
run_ipt('-t', 'nat', '-I', 'POSTROUTING', str(pos), '-j', 'PR-PLAIN-FORWARDING')
|
run_ipt(
|
||||||
|
"-t",
|
||||||
|
"nat",
|
||||||
|
"-I",
|
||||||
|
"POSTROUTING",
|
||||||
|
str(pos),
|
||||||
|
"-j",
|
||||||
|
"PR-PLAIN-FORWARDING",
|
||||||
|
)
|
||||||
|
|
||||||
# Create necessary forward chain.
|
# Create necessary forward chain.
|
||||||
if not find_pos_of_first_rule(out, ':PLAIN-FORWARDING - '):
|
if not find_pos_of_first_rule(out, ":PLAIN-FORWARDING - "):
|
||||||
run_ipt('-t', 'filter', '-N', 'PLAIN-FORWARDING')
|
run_ipt("-t", "filter", "-N", "PLAIN-FORWARDING")
|
||||||
|
|
||||||
# Route forward traffic to necessary chain.
|
# Route forward traffic to necessary chain.
|
||||||
if not find_pos_of_first_rule(out, "-A FORWARD -j PLAIN-FORWARDING"):
|
if not find_pos_of_first_rule(out, "-A FORWARD -j PLAIN-FORWARDING"):
|
||||||
rule_num = find_pos_of_first_rule(out, "-A FORWARD -i vif+ -o vif+ -j DROP")
|
rule_num = find_pos_of_first_rule(
|
||||||
|
out, "-A FORWARD -i vif+ -o vif+ -j DROP"
|
||||||
|
)
|
||||||
if not rule_num:
|
if not rule_num:
|
||||||
# This table does not contain the masquerading rule.
|
# This table does not contain the masquerading rule.
|
||||||
# Accordingly, we will not do anything.
|
# Accordingly, we will not do anything.
|
||||||
@ -75,34 +93,43 @@ class AdjunctWorker(object):
|
|||||||
first_rule_num = find_pos_of_first_rule(out, "-A FORWARD")
|
first_rule_num = find_pos_of_first_rule(out, "-A FORWARD")
|
||||||
pos = rule_num - first_rule_num + 1
|
pos = rule_num - first_rule_num + 1
|
||||||
logging.info("Adding FORWARD chain PLAIN-FORWARDING.")
|
logging.info("Adding FORWARD chain PLAIN-FORWARDING.")
|
||||||
run_ipt('-t', 'filter', '-I', 'FORWARD', str(pos), '-j', 'PLAIN-FORWARDING')
|
run_ipt(
|
||||||
|
"-t", "filter", "-I", "FORWARD", str(pos), "-j", "PLAIN-FORWARDING"
|
||||||
|
)
|
||||||
|
|
||||||
rule = find_pos_of_first_rule(
|
rule = find_pos_of_first_rule(
|
||||||
out,
|
out, "-A PR-PLAIN-FORWARDING -s {}{} -j ACCEPT".format(source, mask)
|
||||||
'-A PR-PLAIN-FORWARDING -s {}{} -j ACCEPT'.format(source, mask)
|
|
||||||
)
|
)
|
||||||
if enable:
|
if enable:
|
||||||
if rule:
|
if rule:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
logging.info("Adding POSTROUTING rule to forward traffic from %s.", source)
|
logging.info(
|
||||||
|
"Adding POSTROUTING rule to forward traffic from %s.", source
|
||||||
|
)
|
||||||
run_ipt(
|
run_ipt(
|
||||||
'-t', 'nat', '-A',
|
"-t",
|
||||||
'PR-PLAIN-FORWARDING', '-s', '{}{}'.format(source, mask),
|
"nat",
|
||||||
'-j', 'ACCEPT'
|
"-A",
|
||||||
|
"PR-PLAIN-FORWARDING",
|
||||||
|
"-s",
|
||||||
|
"{}{}".format(source, mask),
|
||||||
|
"-j",
|
||||||
|
"ACCEPT",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if rule:
|
if rule:
|
||||||
first_rule = find_pos_of_first_rule(out, '-A PR-PLAIN-FORWARDING')
|
first_rule = find_pos_of_first_rule(out, "-A PR-PLAIN-FORWARDING")
|
||||||
pos = rule - first_rule + 1
|
pos = rule - first_rule + 1
|
||||||
logging.info("Removing POSTROUTING rule forwarding traffic from %s.", source)
|
logging.info(
|
||||||
run_ipt('-t', 'nat', '-D', 'PR-PLAIN-FORWARDING', str(pos))
|
"Removing POSTROUTING rule forwarding traffic from %s.", source
|
||||||
|
)
|
||||||
|
run_ipt("-t", "nat", "-D", "PR-PLAIN-FORWARDING", str(pos))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
rule = find_pos_of_first_rule(
|
rule = find_pos_of_first_rule(
|
||||||
out,
|
out, "-A PLAIN-FORWARDING -d {}{} -o vif+ -j ACCEPT".format(source, mask)
|
||||||
'-A PLAIN-FORWARDING -d {}{} -o vif+ -j ACCEPT'.format(source, mask)
|
|
||||||
)
|
)
|
||||||
if enable:
|
if enable:
|
||||||
if rule:
|
if rule:
|
||||||
@ -110,16 +137,23 @@ class AdjunctWorker(object):
|
|||||||
else:
|
else:
|
||||||
logging.info("Adding FORWARD rule to allow traffic to %s.", source)
|
logging.info("Adding FORWARD rule to allow traffic to %s.", source)
|
||||||
run_ipt(
|
run_ipt(
|
||||||
'-t', 'filter', '-A',
|
"-t",
|
||||||
'PLAIN-FORWARDING', '-d', '{}{}'.format(source, mask),
|
"filter",
|
||||||
'-o', 'vif+', '-j', 'ACCEPT'
|
"-A",
|
||||||
|
"PLAIN-FORWARDING",
|
||||||
|
"-d",
|
||||||
|
"{}{}".format(source, mask),
|
||||||
|
"-o",
|
||||||
|
"vif+",
|
||||||
|
"-j",
|
||||||
|
"ACCEPT",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if rule:
|
if rule:
|
||||||
logging.info("Removing FORWARD rule allowing traffic to %s.", source)
|
logging.info("Removing FORWARD rule allowing traffic to %s.", source)
|
||||||
first_rule = find_pos_of_first_rule(out, '-A PLAIN-FORWARDING')
|
first_rule = find_pos_of_first_rule(out, "-A PLAIN-FORWARDING")
|
||||||
pos = rule - first_rule + 1
|
pos = rule - first_rule + 1
|
||||||
run_ipt('-t', 'filter', '-D', 'PLAIN-FORWARDING', str(pos))
|
run_ipt("-t", "filter", "-D", "PLAIN-FORWARDING", str(pos))
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -131,46 +165,47 @@ class AdjunctWorker(object):
|
|||||||
# specific IP addresses in question, but it is not clear to me how
|
# specific IP addresses in question, but it is not clear to me how
|
||||||
# to cause this outcome to take place.
|
# to cause this outcome to take place.
|
||||||
if family == 6:
|
if family == 6:
|
||||||
globber = '/proc/sys/net/ipv6/conf/*/proxy_ndp'
|
globber = "/proc/sys/net/ipv6/conf/*/proxy_ndp"
|
||||||
name = 'proxy NDP'
|
name = "proxy NDP"
|
||||||
elif family == 4:
|
elif family == 4:
|
||||||
globber = '/proc/sys/net/ipv4/conf/*/proxy_arp'
|
globber = "/proc/sys/net/ipv4/conf/*/proxy_arp"
|
||||||
name = 'proxy ARP'
|
name = "proxy ARP"
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
if enabled:
|
if enabled:
|
||||||
action = 'Enabling'
|
action = "Enabling"
|
||||||
val = '1\n'
|
val = "1\n"
|
||||||
else:
|
else:
|
||||||
action = 'Disabling'
|
action = "Disabling"
|
||||||
val = '0\n'
|
val = "0\n"
|
||||||
|
|
||||||
matches = glob.glob(globber)
|
matches = glob.glob(globber)
|
||||||
for m in matches:
|
for m in matches:
|
||||||
iface = m.split('/')[6]
|
iface = m.split("/")[6]
|
||||||
if iface in ('all', 'lo') or iface.startswith('vif'):
|
if iface in ("all", "lo") or iface.startswith("vif"):
|
||||||
# No need to enable it for "all", or VIFs, or loopback.
|
# No need to enable it for "all", or VIFs, or loopback.
|
||||||
continue
|
continue
|
||||||
with open(m, 'w+') as f:
|
with open(m, "w+") as f:
|
||||||
oldval = f.read()
|
oldval = f.read()
|
||||||
f.seek(0)
|
|
||||||
if oldval != val:
|
if oldval != val:
|
||||||
logging.info('%s %s on interface %s.', action, name, iface)
|
logging.info("%s %s on interface %s.", action, name, iface)
|
||||||
|
f.seek(0)
|
||||||
f.write(val)
|
f.write(val)
|
||||||
|
|
||||||
def handle_addr(self, addr):
|
def handle_addr(self, addr):
|
||||||
# Setup plain forwarding for this specific address.
|
# Setup plain forwarding for this specific address.
|
||||||
routing_method = self.qdb.read('/qubes-routing-method/{}'.format(addr))
|
routing_method = _s(self.qdb.read("/qubes-routing-method/{}".format(addr)))
|
||||||
self.setup_plain_forwarding_for_address(
|
self.setup_plain_forwarding_for_address(
|
||||||
addr,
|
addr,
|
||||||
routing_method == FORWARD_ROUTING_METHOD,
|
routing_method == FORWARD_ROUTING_METHOD,
|
||||||
6 if self.is_ip6(addr) else 4
|
6 if self.is_ip6(addr) else 4,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Manipulate proxy ARP for all known addresses.
|
# Manipulate proxy ARP for all known addresses.
|
||||||
methods = [
|
methods = [
|
||||||
(k.split('/')[2], v) for k, v in self.qdb.multiread('/qubes-routing-method/').items()
|
(_s(k).split("/")[2], _s(v))
|
||||||
|
for k, v in self.qdb.multiread("/qubes-routing-method/").items()
|
||||||
]
|
]
|
||||||
mmethods = {
|
mmethods = {
|
||||||
4: [m[1] for m in methods if not self.is_ip6(m[0])],
|
4: [m[1] for m in methods if not self.is_ip6(m[0])],
|
||||||
@ -178,21 +213,20 @@ class AdjunctWorker(object):
|
|||||||
}
|
}
|
||||||
for family, methods in mmethods.items():
|
for family, methods in mmethods.items():
|
||||||
self.setup_proxy_arp_ndp(
|
self.setup_proxy_arp_ndp(
|
||||||
FORWARD_ROUTING_METHOD in methods,
|
FORWARD_ROUTING_METHOD in methods, family,
|
||||||
family,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def list_targets(self):
|
def list_targets(self):
|
||||||
return set(t.split('/')[2] for t in self.qdb.list('/qubes-routing-method/'))
|
return set(_s(t).split("/")[2] for t in self.qdb.list("/qubes-routing-method/"))
|
||||||
|
|
||||||
def sd_notify(self, state):
|
def sd_notify(self, state):
|
||||||
'''Send notification to systemd, if available'''
|
"""Send notification to systemd, if available"""
|
||||||
# based on sdnotify python module
|
# based on sdnotify python module
|
||||||
if not 'NOTIFY_SOCKET' in os.environ:
|
if not "NOTIFY_SOCKET" in os.environ:
|
||||||
return
|
return
|
||||||
addr = os.environ['NOTIFY_SOCKET']
|
addr = os.environ["NOTIFY_SOCKET"]
|
||||||
if addr[0] == '@':
|
if addr[0] == "@":
|
||||||
addr = '\0' + addr[1:]
|
addr = "\0" + addr[1:]
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||||
sock.connect(addr)
|
sock.connect(addr)
|
||||||
@ -203,17 +237,18 @@ class AdjunctWorker(object):
|
|||||||
|
|
||||||
def main(self):
|
def main(self):
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
self.qdb.watch('/qubes-routing-method/')
|
self.qdb.watch("/qubes-routing-method/")
|
||||||
for source_addr in self.list_targets():
|
for source_addr in self.list_targets():
|
||||||
self.handle_addr(source_addr)
|
self.handle_addr(source_addr)
|
||||||
self.sd_notify('READY=1')
|
self.sd_notify("READY=1")
|
||||||
try:
|
try:
|
||||||
for watch_path in iter(self.qdb.read_watch, None):
|
for watch_path in iter(self.qdb.read_watch, None):
|
||||||
# ignore writing rules itself - wait for final write at
|
# ignore writing rules itself - wait for final write at
|
||||||
# source_addr level empty write (/qubes-firewall/SOURCE_ADDR)
|
# source_addr level empty write (/qubes-firewall/SOURCE_ADDR)
|
||||||
if watch_path.count('/') != 2:
|
watch_path = _s(watch_path)
|
||||||
|
if watch_path.count("/") != 2:
|
||||||
continue
|
continue
|
||||||
source_addr = watch_path.split('/')[2]
|
source_addr = watch_path.split("/")[2]
|
||||||
self.handle_addr(source_addr)
|
self.handle_addr(source_addr)
|
||||||
except OSError: # EINTR
|
except OSError: # EINTR
|
||||||
# signal received, don't continue the loop
|
# signal received, don't continue the loop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user