Codebase list nsntrace / 6e63a1c
Update upstream source from tag 'upstream/3.9.g35e174d' Update to upstream version '3.9.g35e174d' with Debian dir 0e46e1c287e1eae9a87cb880e5a78b83cb3a60f6 Sudip Mukherjee 3 years ago
14 changed file(s) with 107 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
0
1 You may use, distribute and copy Kodi under the terms of GNU General
2 Public License version 2, which is displayed below.
3
4 -------------------------------------------------------------------------
5
6 GNU GENERAL PUBLIC LICENSE
7 Version 2, June 1991
8
9 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
10 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0 GNU GENERAL PUBLIC LICENSE
1 Version 2, June 1991
2
3 Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
4 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
115 Everyone is permitted to copy and distribute verbatim copies
126 of this license document, but changing it is not allowed.
137
14 Preamble
8 Preamble
159
1610 The licenses for most software are designed to take away your
1711 freedom to share and change it. By contrast, the GNU General Public
2014 General Public License applies to most of the Free Software
2115 Foundation's software and to any other program whose authors commit to
2216 using it. (Some other Free Software Foundation software is covered by
23 the GNU Library General Public License instead.) You can apply it to
17 the GNU Lesser General Public License instead.) You can apply it to
2418 your programs, too.
2519
2620 When we speak of free software, we are referring to freedom, not
6054
6155 The precise terms and conditions for copying, distribution and
6256 modification follow.
63
64 GNU GENERAL PUBLIC LICENSE
57
58 GNU GENERAL PUBLIC LICENSE
6559 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
6660
6761 0. This License applies to any program or other work which contains
115109 License. (Exception: if the Program itself is interactive but
116110 does not normally print such an announcement, your work based on
117111 the Program is not required to print an announcement.)
118
112
119113 These requirements apply to the modified work as a whole. If
120114 identifiable sections of that work are not derived from the Program,
121115 and can be reasonably considered independent and separate works in
173167 access to copy the source code from the same place counts as
174168 distribution of the source code, even though third parties are not
175169 compelled to copy the source along with the object code.
176
170
177171 4. You may not copy, modify, sublicense, or distribute the Program
178172 except as expressly provided under this License. Any attempt
179173 otherwise to copy, modify, sublicense or distribute the Program is
230224
231225 This section is intended to make thoroughly clear what is believed to
232226 be a consequence of the rest of this License.
233
227
234228 8. If the distribution and/or use of the Program is restricted in
235229 certain countries either by patents or by copyrighted interfaces, the
236230 original copyright holder who places the Program under this License
260254 of preserving the free status of all derivatives of our free software and
261255 of promoting the sharing and reuse of software generally.
262256
263 NO WARRANTY
257 NO WARRANTY
264258
265259 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
266260 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
282276 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
283277 POSSIBILITY OF SUCH DAMAGES.
284278
285 END OF TERMS AND CONDITIONS
286 -------------------------------------------------------------------------
279 END OF TERMS AND CONDITIONS
280
281 How to Apply These Terms to Your New Programs
282
283 If you develop a new program, and you want it to be of the greatest
284 possible use to the public, the best way to achieve this is to make it
285 free software which everyone can redistribute and change under these terms.
286
287 To do so, attach the following notices to the program. It is safest
288 to attach them to the start of each source file to most effectively
289 convey the exclusion of warranty; and each file should have at least
290 the "copyright" line and a pointer to where the full notice is found.
291
292 <one line to give the program's name and a brief idea of what it does.>
293 Copyright (C) <year> <name of author>
294
295 This program is free software; you can redistribute it and/or modify
296 it under the terms of the GNU General Public License as published by
297 the Free Software Foundation; either version 2 of the License, or
298 (at your option) any later version.
299
300 This program is distributed in the hope that it will be useful,
301 but WITHOUT ANY WARRANTY; without even the implied warranty of
302 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
303 GNU General Public License for more details.
304
305 You should have received a copy of the GNU General Public License along
306 with this program; if not, write to the Free Software Foundation, Inc.,
307 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
308
309 Also add information on how to contact you by electronic and paper mail.
310
311 If the program is interactive, make it output a short notice like this
312 when it starts in an interactive mode:
313
314 Gnomovision version 69, Copyright (C) year name of author
315 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
316 This is free software, and you are welcome to redistribute it
317 under certain conditions; type `show c' for details.
318
319 The hypothetical commands `show w' and `show c' should show the appropriate
320 parts of the General Public License. Of course, the commands you use may
321 be called something other than `show w' and `show c'; they could even be
322 mouse-clicks or menu items--whatever suits your program.
323
324 You should also get your employer (if you work as a programmer) or your
325 school, if any, to sign a "copyright disclaimer" for the program, if
326 necessary. Here is a sample; alter the names:
327
328 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
329 `Gnomovision' (which makes passes at compilers) written by James Hacker.
330
331 <signature of Ty Coon>, 1 April 1989
332 Ty Coon, President of Vice
333
334 This General Public License does not permit incorporating your program into
335 proprietary programs. If your program is a subroutine library, you may
336 consider it more useful to permit linking proprietary applications with the
337 library. If this is what you want to do, use the GNU Lesser General
338 Public License instead of this License.
22
33 This application uses Linux network namespaces to perform network traces of a single application. The traces are saved as pcap files. And can later be analyzed by for instance Wireshark.
44
5 The nsntrace application is heavily inspired by the askbubuntu reply [here](http://askubuntu.com/a/499850).
5 The nsntrace application is heavily inspired by the askbubuntu reply [here](https://askubuntu.com/a/499850).
66 And uses the same approach only confined to a single C program.
77
88 What the application does is use the clone syscall to create a new
3737 -o file send trace output to file (default nsntrace.pcap)
3838 -d device the network device to trace
3939 -f filter an optional capture filter
40 -u username run program as username
40 -u username run program as username/uid
4141
4242 ## example
4343 > sudo nsntrace -d eth1 wget www.google.com
0 #!/bin/sh
01 aclocal \
12 && autoreconf --install \
23 && automake --add-missing
22 # [bug reports],
33 # [tar-ball name])
44 AC_INIT([nsntrace],
5 [2],
5 [3],
66 [https://github.com/jonasdn/nsntrace/issues],
77 [nsntrace])
88
9797 </varlistentry>
9898
9999 <varlistentry>
100 <term><option>
101 --filter <replaceable>filter</replaceable></option></term>
100 <term><option>--filter <replaceable>filter</replaceable></option></term>
102101 <term><option>-f <replaceable>filter</replaceable></option></term>
103102
104103 <listitem><para>
1414
1515 nsntrace_SOURCES = $(headers) $(sources)
1616 nsntrace_CPPFLAGS = $(LIBNL_CFLAGS) $(warnings)
17 nsntrace_LDFLAGS = $(LIBNL_LIBS) -pthread
17 nsntrace_LDFLAGS = -pthread
18 nsntrace_LDADD = $(LIBNL_LIBS)
99 * for more details.
1010 *
1111 * You should have received a copy of the GNU General Public License along
12 * with nsntraces; if not, see <http://www.gnu.org/licenses/>.
12 * with nsntraces; if not, see <https://www.gnu.org/licenses/>.
1313 */
1414
1515 #include <pcap.h>
99 * for more details.
1010 *
1111 * You should have received a copy of the GNU General Public License along
12 * with nsntraces; if not, see <http://www.gnu.org/licenses/>.
12 * with nsntraces; if not, see <https://www.gnu.org/licenses/>.
1313 */
1414
1515 #ifndef _NSNTRACE_CAPTURE_H_
99 * for more details.
1010 *
1111 * You should have received a copy of the GNU General Public License along
12 * with nsntraces; if not, see <http://www.gnu.org/licenses/>.
12 * with nsntraces; if not, see <https://www.gnu.org/licenses/>.
1313 *
1414 */
1515
99 * for more details.
1010 *
1111 * You should have received a copy of the GNU General Public License along
12 * with nsntraces; if not, see <http://www.gnu.org/licenses/>.
12 * with nsntraces; if not, see <https://www.gnu.org/licenses/>.
1313 */
1414
1515 #ifndef _NSNTRACE_CMD_H_
99 * for more details.
1010 *
1111 * You should have received a copy of the GNU General Public License along
12 * with nsntraces; if not, see <http://www.gnu.org/licenses/>.
12 * with nsntraces; if not, see <https://www.gnu.org/licenses/>.
1313 *
1414 */
1515
99 * for more details.
1010 *
1111 * You should have received a copy of the GNU General Public License along
12 * with nsntraces; if not, see <http://www.gnu.org/licenses/>.
12 * with nsntraces; if not, see <https://www.gnu.org/licenses/>.
1313 */
1414
1515 #ifndef _NSNTRACE_NET_H_
99 * for more details.
1010 *
1111 * You should have received a copy of the GNU General Public License along
12 * with nsntraces; if not, see <http://www.gnu.org/licenses/>.
12 * with nsntraces; if not, see <https://www.gnu.org/licenses/>.
1313 *
1414 */
1515 #define _GNU_SOURCE
3131 /*
3232 * This application attempts to trace the network traffic of a single process.
3333 * It does so by creating a new network namespace. In Linux a network namespace
34 * partitions the use of the network effecticly virtualizing the network,
34 * partitions the use of the network effectively virtualizing the network,
3535 * devices, addresses, ports, routes firewall rules, etc into separate boxes.
3636 *
3737 * So what this application does is use the clone syscall to create a new
8585
8686 /*
8787 * We will attempt to catch the signals that can make us exit since
88 * we want to remove the temporary network configurations when we elave
88 * we want to remove the temporary network configurations when we leave
8989 *
9090 * This is hard. Which signals should we catch? This is what we have
9191 * now:
190190 if (options->user) {
191191 struct passwd* pwd;
192192
193 if (!(pwd = getpwnam(options->user))) {
193 if (sscanf(options->user, "%i", &uid) == 1) {
194 pwd = getpwuid(uid);
195 } else {
196 pwd = getpwnam(options->user);
197 }
198 if (!pwd) {
194199 fprintf(stderr,"Cannot find user '%s'\n",
195200 options->user);
196201 exit(EXIT_FAILURE);
274279 /* the tracee exited, we waited, stop capture */
275280 nsntrace_capture_stop();
276281
277 /* broken out of capture loop, clean up */
282 /* exited capture loop, clean up */
278283 _nsntrace_cleanup_ns();
279284 exit(ret);
280285 } else { /* child - tracee */
294299 "-o file\t\tsend trace output to file (default nsntrace.pcap)\n"
295300 "-d device\tthe network device to trace\n"
296301 "-f filter\tan optional capture filter\n"
297 "-u username\trun PROG as username\n");
302 "-u username\trun PROG as username/uid\n");
298303 }
299304
300305 static void
369374 }
370375
371376 if (!nsntrace_net_ip_forward_enabled()) {
372 fprintf(stderr,
373 "IP forward must be enabled to run this application\n"
374 "# cat /proc/sys/net/ipv4/ip_forward\n");
377 fprintf(stderr, "Please enable IP forwarding:\n");
378 if( NULL == getenv("SUDO_UID") ) {
379 fprintf(stderr, "# sysctl net.ipv4.ip_forward=1\n");
380 } else {
381 fprintf(stderr, "$ sudo sysctl net.ipv4.ip_forward=1\n");
382 }
375383 exit(EXIT_FAILURE);
376384 }
377385
1111
1212 RESULT="${?}"
1313
14 if [ "${EXPECTED}" != "${RESULT}" ]
15 then
16 echo "nsntrace ${*} did not return with exit code ${EXPECTED} (saw: ${RESULT})"
14 if [ "${EXPECTED}" != "${RESULT}" ] ; then
15 echo "Did not return with ${EXPECTED} (saw: ${RESULT})"
1716 RET="1"
1817 fi
1918 }
2726 check_return_code 1 -o /path/does/not/exist /bin/true
2827 check_return_code 1 -d invalid_device /bin/true
2928
29 rm -rf *.pcap
30
3031 exit ${RET}