Remove echld/.

It has been unsupported for some years and when talking about removing it
in the past I received some positive and no negative feedback.

There is one instance of echld left:
capchild/capture_sync.c:                 * echld might have already reaped the child.

Can that case be removed or should be comment be updated to something more
accurate? (left for a separate patch)

Change-Id: Idac397158dd86fd0728eb95379449ee4a463fc28
Reviewed-on: https://code.wireshark.org/review/20619
Petri-Dish: Jörg Mayer <jmayer@loplof.de>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
pespin/osmux-stats
Joerg Mayer 2017-03-19 13:47:11 +01:00 committed by Anders Broman
parent a65c0c4576
commit 0b6b152694
18 changed files with 3 additions and 5576 deletions

View File

@ -33,7 +33,7 @@ indent_size = 4
[{capinfos,captype,mergecap,tfshark,tshark}.c]
indent_size = 2
[{dftest,echld_test,randpkt,trigcap}.c]
[{dftest,randpkt,trigcap}.c]
indent_style = tab
indent_size = tab

1
.gitignore vendored
View File

@ -85,7 +85,6 @@ depcomp
dftest
dumpcap
editcap
echld_test
exntest
install-sh
libtool

View File

@ -1173,10 +1173,6 @@ if(NOT WIN32)
add_custom_target(dumpabi DEPENDS dumpabi-libwireshark dumpabi-libwiretap dumpabi-libwsutil)
endif()
if(ENABLE_ECHLD)
add_subdirectory( echld )
endif()
if(BUILD_wireshark_gtk AND GTK_FOUND)
add_subdirectory( ui/gtk )
endif()

View File

@ -53,7 +53,6 @@ else()
endif()
# todo
option(ENABLE_STATIC "Build a static version of Wireshark (not yet working)" OFF)
option(ENABLE_ECHLD "Enable echld support" OFF)
option(ENABLE_PLUGINS "Build with plugins" ON)
option(ENABLE_PLUGIN_IFDEMO "Build with plugin interface demo" OFF)
option(ENABLE_EXTCAP "Build with extcap hooks" ON)

View File

@ -45,12 +45,11 @@ bin_PROGRAMS = \
@dumpcap_bin@ \
@reordercap_bin@ \
@rawshark_bin@ \
@sharkd_bin@ \
@echld_test_bin@
@sharkd_bin@
EXTRA_PROGRAMS = wireshark-gtk wireshark tshark tfshark capinfos captype \
editcap mergecap dftest randpkt text2pcap dumpcap reordercap \
rawshark sharkd echld_test
rawshark sharkd
#
# Wireshark configuration files are put in $(pkgdatadir).
@ -718,30 +717,6 @@ dftest_LDADD = \
@PCAP_LIBS@ \
${EPAN_EXTRA_LIBS}
echld_test_SOURCES = \
echld_test.c \
capture_opts.c \
capture_stop_conditions.c \
cfile.c \
conditions.c \
ringbuffer.c \
sync_pipe_write.c
echld_test_CPPFLAGS = $(AM_CPPFLAGS) $(GLIB_CFLAGS)
echld_test_LDADD = \
epan/libwireshark.la \
echld/libechld.la \
writecap/libwritecap.a \
wsutil/libwsutil.la \
@GLIB_LIBS@ \
@PCAP_LIBS@ \
@C_ARES_LIBS@
echld_test_DEPENDENCIES = \
echld/libechld.la \
epan/libwireshark.la
dumpcap_SOURCES = \
capture_opts.c \
capture_stop_conditions.c \
@ -908,7 +883,6 @@ DIST_SUBDIRS = \
codecs \
doc \
epan \
echld \
ui \
ui/cli \
ui/gtk \
@ -932,7 +906,6 @@ SUBDIRS = \
epan \
capchild \
caputils \
@echld_dir@ \
@plugins_dir@ \
packaging \
help \

View File

@ -1876,26 +1876,6 @@ else
fi
AC_SUBST(sharkd_bin)
# Enable/disable echld
AC_ARG_ENABLE(echld,
AC_HELP_STRING( [--enable-echld],
[support echld (Experimental) @<:@default=no@:>@]),
have_echld=$enableval,have_echld=no)
AM_CONDITIONAL(HAVE_ECHLD, test "x$have_echld" = "xyes")
if test "x$have_echld" = "xyes"
then
AC_DEFINE(HAVE_ECHLD, 1, [Define if echld is enabled])
echld_test_bin="echld_test\$(EXEEXT)"
echld_dir="echld"
else
have_echld="no"
echld_test_bin=""
echld_dir=""
fi
AC_SUBST(echld_test_bin)
AC_SUBST(echld_dir)
# Enable/disable tfshark
AC_ARG_ENABLE(tfshark,
AC_HELP_STRING( [--enable-tfshark],
@ -3012,7 +2992,6 @@ AC_CONFIG_FILES(
writecap/Makefile
writecap/doxygen.cfg
wsutil/Makefile
echld/Makefile
_CUSTOM_AC_OUTPUT_
)
@ -3161,7 +3140,6 @@ echo " Build sshdump : $enable_sshdump"
echo " Build ciscodump : $enable_ciscodump"
echo " Build randpktdump : $enable_randpktdump"
echo " Build udpdump : $enable_udpdump"
echo " Build echld : $have_echld"
echo ""
echo " Save files as pcap-ng by default : $enable_pcap_ng_default"
echo " Install dumpcap with capabilities : $setcap_message"

View File

@ -1,251 +0,0 @@
EPAN CHILDREN
This document is a work in progress.
This document describes a potential interface between a master process and one or more working children.
The goal is to have along-running epan process without the troubles of epan reinit (leaks, mis-reinits, ...).
Working children are spawn to capture or read files, then terminated.
The long running parent process initializes epan and forks children that require no further initialization to run.
epan_child.h in the root directory describes the C interface.
Appendix A
ECHLD PROTOCOL INTERACTION DIAGRAMS
parent child dumpcap
| | |
A.1. creation
new_child() ---------->|
|<-----HELLO------|
IDLE
A.2. keepalive
A.2.1 p->c
ANY_STATE
|-------PING----->|
|<------PONG------|
SAME_STATE
A.2.2 c->p
ANY_STATE
|<------PING------|
|-------PONG----->|
SAME_STATE
A.3. destruction
A.3.1 normal
ANY_STATE
|---CLOSE_CHILD-->|
|<----CLOSING-----|
DYING
|<-- SIG_CHLD
delete_child()
A.3.2 fatal error
ANY_STATE
|<-----ERROR------| (fatal_err,"reason")
|<---SIG_CHLD
delete_child()
A.3.3 crash
ANY_STATE
|<---SIG_CHLD
delete_child()
A.4. getting current dir
ANY_STATE
|-------PWD------>|
|<------CWD-------| (dirname)
SAME_STATE
A.5. changing current dir
A.5.1 dir changed ok
ANY_STATE
|------CHDIR----->| (dirname)
|<------CWD-------| (dirname)
SAME_STATE
A.5.2 dir changed ko
ANY_STATE
|------CHDIR----->| (dirname)
|<-----ERROR------| (cannot_cd, "reason")
SAME_STATE
A.6. listing current directory
A.6.1 file list ok
ANY_STATE
|----LIST_FILES-->| ("*.*"")
|<---FILE_INFO----| (filename, format, encap, num_pkts, ...);
|<---FILE_INFO----| (filename, format, encap, num_pkts, ...);
.....
|<---FILE_INFO----| (filename, format, encap, num_pkts, ...);
SAME_STATE
A.6.2 file list ko
ANY_STATE
|----LIST_FILES-->| ("*.*"")
|<-----ERROR------| (no_files, "reason")
SAME_STATE
A.7. opening a file
A.7.1 opened ok
IDLE
|----OPEN_FILE---->| (filename, ...)
|<---FILE_OPENED---| (dirname)
READING
A.7.2 not opened
IDLE
|----OPEN_FILE---->| (filename, ...)
|<-----ERROR-------| (cannot_open, "reason")
IDLE
A.8. saving a file
A.8.1 save ok
READING/CAPTURING/DONE
|-----SAVE_FILE---->| ("new_filename",opts,...)
|<----FILE_SAVED----| (24, tree)
SAME_STATE
A.8.1 save ko
READING/CAPTURING/DONE
|-----SAVE_FILE---->| ("new_filename",opts,...)
|<------ERROR-------| (cannot_save, "reason")
SAME_STATE
A.9. listing interfaces
A.9.1 intf list ok
IDLE
|--LIST_INTERFACES-->| ("*.*"")
| |-------????------>|
| |<------????-------|
|<--INTERFACE_INFO---| (name, param1=val1, ...)
|<--INTERFACE_INFO---| (name, param1=val1, ...)
.....
|<--INTERFACE_INFO---| (name, param1=val1, ...)
IDLE
A.9.2 intf list ko
|--LIST_INTERFACES-->| ("*.*"")
| |-------????------>|
| |<------????-------|
|<------ERROR-------| (list_intf, "reason")
A.10. opening an interface
A.10.1 interface opened ok
IDLE
|---OPEN_INTERFACE-->|
| |-------????------>|
| |<------????-------|
|<--INTERFACE_OPENED-|
READY
A.10.2 interface open failure
IDLE
|--OPEN_INTERFACE--->|
| |-------????------>|
| |<------????-------|
|<-------ERROR-------| (intf, "reason")
IDLE
A.11. starting capture
A.11.1 started capture ok
READY
|---START_CAPTURE--->|
| |-------????------>|
| |<------????-------|
|<-CAPTURE_STARTED---|
IN_CAPTURE
A.11.2 capture start failure
READY
|----START_CAPTURE-->|
| |-------????------>|
| |<------????-------|
|<-------ERROR-------| (cannot_start, "reason")
READY
A.12. capturing or reading
IN_CAPTURE/READING
| |<------????-------|
|<----PACKET_SUM-----| (framenum, columns)
IN_CAPTURE
A.13 getting packet details
A.13.1 just frame
IN_CAPTURE/READING
|----GET_PACKETS--->| (framelist)
|<-----PACKET-------| (1, tree)
|<-----BUFFER-------| ("1", tvb)
|<-----PACKET-------| (2, tree)
|<-----BUFFER-------| ("2", tvb)
SAME_STATE
A.13.2 frame with reassembled buffer
IN_CAPTURE/READING/DONE
|----GET_PACKETS--->| (framelist)
|<-----PACKET-------| (framenum, tree)
|<-----BUFFER-------| ("framenum", tvb)
|<-----BUFFER-------| ("reas_num", tvb)
SAME_STATE
A.13.3 frame with known reassembled buffer
IN_CAPTURE/READING/DONE
|<-----PACKET-------| (framenum+N, tree)
|<-----BUFFER-------| ("framenum+N", tvb)
|<-----BUFFER-------| ("reas_num", NULL)
SAME_STATE
A.13.4 buffer request (e.g. un-cached buffer)
IN_CAPTURE/READING/DONE
|------GET_BUF----->| (bufname)
|<-----BUFFER-------| (bufname, NULL)
SAME_STATE
A.14 stpping capture
IN_CAPTURE
|---STOP_CAPTURE--->|
|<-CAPTURE_STOPPED--|
DONE
A.15. done reading
READING
|<-- EOF
|<--------EOF--------|
DONE
A.16 setting a note
A.16.1 note set ok
IN_CAPTURE/READING/DONE
|----ADD_NOTE------>| (framenum,note)
|<----NOTE_ADDED----|
SAME_STATE
A.16.2 note set failure
IN_CAPTURE/READING/DONE
|----ADD_NOTE------>| (framenum,note)
|<----NOTE_ADDED----|
SAME_STATE
A.17 applying a filter
IN_CAPTURE/READING/DONE
|---APPLY_FILTER--->| (dfilter_str)
|<---PACKET_LIST----| (Packet-Range)
|<---PACKET_LIST----| (Packet-Range)
SAME_STATE
A.18 setting a filter
IDLE
|-----SET_FILTER---->| (dfilter_str)
|<---FILTER_SET------|
IDLE

View File

@ -1,106 +0,0 @@
# CMakeLists.txt
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# 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.
#
set(CLEAN_FILES
echld-util.c
parent.c
)
set(DIRTY_FILES
child.c
common.c
dispatcher.c
)
set(echld_LIBS
${GLIB2_LIBRARIES}
)
set(ECHLD_FILES
${CLEAN_FILES}
${DIRTY_FILES}
)
set_source_files_properties(
${CLEAN_FILES}
PROPERTIES
COMPILE_FLAGS "${WERROR_COMMON_FLAGS}"
)
add_library(echld ${LINK_MODE_LIB}
${ECHLD_FILES}
)
set(FULL_SO_VERSION "0.0.0")
set_target_properties(echld PROPERTIES COMPILE_DEFINITIONS "WS_BUILD_DLL")
set_target_properties(echld PROPERTIES COMPILE_OPTIONS "${WS_WARNINGS_C_FLAGS}")
set_target_properties(echld PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
set_target_properties(echld PROPERTIES VERSION ${FULL_SO_VERSION} SOVERSION 0)
# discover and substitute list of include directories for ABI compatibility
# checks
#get_directory_property(INCLUDE_DIRS INCLUDE_DIRECTORIES)
#list(REMOVE_DUPLICATES INCLUDE_DIRS)
#string(REGEX REPLACE ";" "\n" INCLUDE_DIRS "${INCLUDE_DIRS}")
#configure_file(../abi-descriptor.template abi-descriptor.xml)
# ABI compliance checker can be obtained from
# http://ispras.linux-foundation.org/index.php/ABI_compliance_checker
# Checked using version 1.21.12
#file(GLOB HEADERS *.h)
#file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/abi-check-headers)
#
#file(COPY ${HEADERS} ../ws_symbol_export.h DESTINATION abi-check-headers)
#add_custom_command(OUTPUT libwsutil.abi.tar.gz
# COMMAND cp ../config.h abi-check-headers/
# COMMAND abi-compliance-checker -l libwsutil -v1 ${FULL_SO_VERSION}
# -relpath ${CMAKE_CURRENT_BINARY_DIR} -dump-abi abi-descriptor.xml
# || cat logs/libwsutil/[0-9]*/log.txt
# COMMAND cp abi_dumps/libwsutil/libwsutil_* libwsutil.abi.tar.gz
# COMMAND rm -rf abi-check-headers/* abi_dumps
# DEPENDS ${HEADERS} wsutil)
#add_custom_target(dumpabi-libwsutil DEPENDS libwsutil.abi.tar.gz)
target_link_libraries(echld ${echld_LIBS})
if(NOT ${ENABLE_STATIC})
install(TARGETS echld
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()
#
# Editor modelines - http://www.wireshark.org/tools/modelines.html
#
# Local variables:
# c-basic-offset: 8
# tab-width: 8
# indent-tabs-mode: t
# End:
#
# vi: set shiftwidth=8 tabstop=8 noexpandtab:
# :indentSize=8:tabSize=8:noTabs=false:
#

View File

@ -1,63 +0,0 @@
# Makefile.am
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# 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.
include $(top_srcdir)/Makefile.am.inc
AM_CPPFLAGS = -DWS_BUILD_DLL $(INCLUDEDIRS) $(WS_CPPFLAGS) \
$(GLIB_CFLAGS)
lib_LTLIBRARIES = libechld.la
libechld_la_SOURCES = \
echld-util.c \
dispatcher.c \
child.c \
parent.c \
common.c \
echld-int.h \
echld-util.h \
echld.h
libechld_la_LDFLAGS = -version-info 0:0:0 @LDFLAGS_SHAREDLIB@
libechld_la_LIBADD = \
../caputils/libcaputils.a \
../epan/libwireshark.la \
../wsutil/libwsutil.la \
../wiretap/libwiretap.la \
@GLIB_LIBS@
libechld_la_DEPENDENCIES = \
../caputils/libcaputils.a \
../epan/libwireshark.la \
../wiretap/libwiretap.la \
../wsutil/libwsutil.la
EXTRA_DIST = \
CMakeLists.txt
CLEANFILES = \
libechld.a \
libechld.la \
*~
MAINTAINERCLEANFILES = \
Makefile.in

View File

@ -1,731 +0,0 @@
/* echld_child.c
* epan working child internals
* Child process routines and definitions
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* Copyright (c) 2013 by Luis Ontanon <luis@ontanon.org>
*
* 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.
*/
#include "echld-int.h"
typedef struct _child {
child_state_t state;
int pid;
int dispatcher_pid;
int chld_id;
int reqh_id;
echld_reader_t parent;
struct _fds {
int pipe_to_parent;
int pipe_from_dumpcap;
int pipe_to_dumpcap;
int file_being_read;
} fds;
struct timeval started;
struct timeval now;
child_encoder_t* enc;
child_decoder_t* dec;
/* epan stuff */
char* cf_name;
char* cfilter;
char* dfilter;
#if 0
capture_file cfile;
#endif
dfilter_t* df;
} echld_child_t;
static echld_epan_stuff_t* stuff = NULL;
static echld_child_t child;
struct _st_map {
child_state_t id;
const char* str;
};
#ifdef DEBUG_CHILD
static int debug_lvl = DEBUG_CHILD;
static FILE* debug_fp = NULL;
#define DBG_BUF_LEN 1024
#define DCOM()
int child_debug(int level, const char* fmt, ...) {
va_list ap;
char str[DBG_BUF_LEN];
if (debug_lvl<level) return 1;
va_start(ap, fmt);
vsnprintf(str,DBG_BUF_LEN,fmt,ap);
va_end(ap);
fprintf(debug_fp, "child[%d-%d]: reqh_id=%d debug_lvl=%d message='%s'\n",
child.chld_id, child.pid, child.reqh_id, level, str);
return 1;
}
static char* param_get_dbg_level(char** err _U_) {
return g_strdup_printf("%d",debug_lvl);
}
static echld_bool_t param_set_dbg_level(char* val , char** err ) {
char* p;
int lvl = (int)strtol(val, &p, 10);
if (p<=val) {
*err = g_strdup("not an integer");
return FALSE;
} else if (lvl < 0 || lvl > 5) {
*err = g_strdup_printf("invalid level=%d (min=0 max=5)",lvl);
return FALSE;
}
debug_lvl = lvl;
DCOM();
return TRUE;
}
static long dbg_resp(GByteArray* em, echld_msg_type_t t) {
long st = echld_write_frame(child.fds.pipe_to_parent, em, child.chld_id, t, child.reqh_id, NULL);
child_debug(1, "SND fd=%d ch=%d ty='%s' rh=%d msg='%s'",
child.fds.pipe_to_parent, child.chld_id, TY(t), child.reqh_id, (st>0?"ok":g_strerror(errno)) );
return st;
}
#define CHILD_DBG(attrs) ( child_debug attrs )
#define CHILD_DBG_INIT() do { debug_fp = stderr; DCOM(); } while(0)
#define CHILD_DBG_START(fname) do { debug_fp = ws_fopen(fname,"a"); DCOM(); CHILD_DBG((0,"Log Started")); } while(0)
#define CHILD_RESP(BA,T) dbg_resp(BA,T)
#define CHILD_STATE(ST) do { DISP_DBG((0,"State %s => %s")) } while(0)
#else
#define CHILD_DBG(attrs)
#define CHILD_DBG_INIT()
#define CHILD_DBG_START(fname)
#define CHILD_RESP(BA,T) echld_write_frame(child.fds.pipe_to_parent,(BA),child.chld_id,T,child.reqh_id,NULL)
#endif
static struct timeval close_sleep_time;
static void sig_term(int sig _U_) {
CHILD_DBG((3,"Terminated, Closing"));
exit(0);
}
extern void echld_child_initialize(echld_chld_id_t chld_id, int pipe_from_parent, int pipe_to_parent, int reqh_id, echld_epan_stuff_t* es) {
stuff = es;
close_sleep_time.tv_sec = CHILD_CLOSE_SLEEP_TIME / 1000000;
close_sleep_time.tv_usec = CHILD_CLOSE_SLEEP_TIME % 1000000;
child.chld_id = chld_id;
child.state = IDLE;
child.pid = getpid();
child.dispatcher_pid = getppid();
child.reqh_id = reqh_id;
echld_init_reader( &(child.parent), pipe_from_parent,4096);
child.fds.pipe_to_parent = pipe_to_parent;
child.fds.pipe_from_dumpcap = -1;
child.fds.pipe_to_dumpcap = -1;
child.fds.file_being_read = -1;
gettimeofday(&child.started,NULL);
child.now.tv_sec = child.started.tv_sec;
child.now.tv_usec = child.started.tv_usec;
echld_get_all_codecs(&(child.enc), &(child.dec), NULL, NULL);
CHILD_DBG_INIT();
CHILD_DBG((5,"Child Initialized ch=%d from=%d to=%d rq=%d",chld_id, pipe_from_parent, pipe_to_parent, reqh_id));
/*clear signal handlers */
signal(SIGALRM,SIG_DFL);
signal(SIGTERM,sig_term);
signal(SIGPIPE,SIG_DFL);
signal(SIGINT,SIG_DFL);
signal(SIGABRT,SIG_DFL);
signal(SIGHUP,SIG_DFL);
/* epan stuff */
}
void child_err(int e, unsigned reqh_id, const char* fmt, ...) {
size_t len= 1024;
gchar err_str[len];
va_list ap;
static GByteArray* ba;
va_start(ap, fmt);
g_vsnprintf(err_str,len,fmt,ap);
va_end(ap);
CHILD_DBG((0,"error='%s'",err_str));
ba = child.enc->error(e, err_str);
echld_write_frame(child.fds.pipe_to_parent, ba, child.chld_id, ECHLD_ERROR, reqh_id, NULL);
g_byte_array_free(ba,TRUE);
}
static char* param_get_cwd(char** err ) {
char* pwd = getcwd(NULL, 128);
if (!pwd) {
*err = g_strdup(g_strerror(errno));
}
return pwd;
}
static echld_bool_t param_set_cwd(char* val , char** err ) {
/* XXX SANITIZE */
if (chdir(val) != 0) {
*err = g_strdup_printf("cannot chdir reas='%s'",g_strerror(errno));
return FALSE;
}
return TRUE;
}
static unsigned packet_count = 0;
static char* param_get_packet_count(char** err) {
if (child.state != CAPTURING && child.state != READING) {
*err = g_strdup("Must be reading or in-capture for packet_count");
return NULL;
}
return g_strdup_printf("%d",packet_count);
}
static echld_bool_t param_set_dfilter(char* val , char** err) {
dfilter_t *dfn = NULL;
if (child.state != IDLE && child.state != DONE ) {
*err = g_strdup("Only while idle or done");
return FALSE;
} else {
if ( dfilter_compile(val, &dfn, err) ) {
if (child.dfilter) g_free(child.dfilter);
if (child.df) dfilter_free(child.df);
child.df = dfn;
child.dfilter = g_strdup(val);
return TRUE;
} else {
return FALSE;
}
}
}
static char* param_get_dfilter(char** err _U_) { return g_strdup(child.dfilter ? child.dfilter : ""); }
char* param_profile = NULL;
static echld_bool_t param_set_profile(char* val , char** err ) {
if (child.state != IDLE) {
*err = g_strdup_printf("Cannot set Profile \"%s\", too late.", val);
return FALSE;
}
if (profile_exists (val, FALSE)) {
set_profile_name (val);
if (param_profile) g_free(param_profile);
param_profile = g_strdup(val);
return TRUE;
} else {
*err = g_strdup_printf("Configuration Profile \"%s\" does not exist", val);
return FALSE;
}
}
static char* param_get_profile(char** err _U_) { return g_strdup(param_profile ? param_profile : ""); }
static char* param_get_file_list(char** err) {
GError* gerror = NULL;
GDir* dir = g_dir_open(".", 0, &gerror);
GString* str = g_string_new("{ what='file_list', files=[");
const char* file;
if (gerror) {
*err = g_strdup_printf("Failed to open curr dir reason='%s'",gerror->message);
return NULL;
}
while(( file = g_dir_read_name(dir) )) {
g_string_append_printf(str,"{filename='%s'},\n",file);
}
g_dir_close(dir);
g_string_truncate(str, str->len-2); /* ',\n' */
g_string_append(str, "]}");
return g_string_free(str,FALSE);
}
#ifdef PCAP_NG_DEFAULT
static int out_file_type = WTAP_FILE_TYPE_SUBTYPE_PCAPNG;
#else
static int out_file_type = WTAP_FILE_TYPE_SUBTYPE_PCAP;
#endif
static echld_bool_t param_set_out_file_type(char* val, char** err) {
int oft = wtap_short_string_to_file_type_subtype(val);
if (oft < 0) {
*err = g_strdup_printf("\"%s\" isn't a valid capture file type", val);
return FALSE;
} else {
out_file_type = oft;
return TRUE;
}
}
static char* param_get_out_file_type(char** err _U_) {
return g_strdup_printf("%s(%d): %s",
wtap_file_type_subtype_short_string(out_file_type),
out_file_type, wtap_file_type_subtype_string(out_file_type));
}
static echld_bool_t param_set_add_hosts_file(char* val, char** err) {
if (add_hosts_file(val)) {
return TRUE;
} else {
*err = g_strdup_printf("Can't read host entries from \"%s\"",val);
return FALSE;
}
}
PARAM_BOOL(quiet,FALSE);
PARAM_BOOL(start_capture,FALSE);
PARAM_BOOL(push_details,FALSE);
PARAM_BOOL(print_hex,FALSE);
static char* param_get_params(char** err _U_);
static param_t child_params[] = {
#ifdef DEBUG_CHILD
PARAM(dbg_level,"Debug Level (0<int<5)"),
# endif
PARAM(profile,"Configuration Profile (str)"),
PARAM(cwd,"Current Directory (str)"),
PARAM(dfilter,"Dispay Filter (str)"),
RO_PARAM(packet_count,"Packets Read/Captured So Far (str)"),
RO_PARAM(file_list,"List of Files in the Current Dir"),
PARAM(start_capture,"Automatically start capture"),
PARAM(quiet,"Quiet Mode"),
PARAM(push_details,"Whether details of dissection should be passed"),
PARAM(print_hex,"Output in hex"),
PARAM(out_file_type,"Output File Type"),
WO_PARAM(add_hosts_file,"Add a Hosts File"),
RO_PARAM(params,"This List"),
{NULL,NULL,NULL,NULL}
};
static char* param_get_params(char** err _U_) {
return paramset_get_params_list(child_params,PARAM_LIST_FMT);
}
static void child_open_file(char* filename) {
CHILD_DBG((2,"CMD open file filename='%s'",filename));
child_err(ECHLD_ERR_UNIMPLEMENTED,child.reqh_id,"open file not implemented yet!");
child.state = READING;
}
static void child_open_interface(char* intf, char* pars) {
CHILD_DBG((2,"CMD open interface intf='%s', params='%s'",intf,pars));
child_err(ECHLD_ERR_UNIMPLEMENTED,child.reqh_id,"open interface not implemented yet!");
child.state = READY;
}
static void child_start_capture(void) {
CHILD_DBG((2,"CMD start capture"));
child_err(ECHLD_ERR_UNIMPLEMENTED,child.reqh_id,"start capture not implemented yet!");
child.state = CAPTURING;
}
static void child_stop_capure(void) {
CHILD_DBG((2,"CMD stop capture"));
child_err(ECHLD_ERR_UNIMPLEMENTED,child.reqh_id,"stop capture not implemented yet!");
child.state = DONE;
}
static void child_get_summary(char* range) {
CHILD_DBG((2,"CMD get summary range='%s'",range));
child_err(ECHLD_ERR_UNIMPLEMENTED,child.reqh_id,"get_summary not implemented yet!");
}
static void child_get_tree(char* range) {
CHILD_DBG((2,"CMD get tree range='%s'",range));
child_err(ECHLD_ERR_UNIMPLEMENTED,child.reqh_id,"get_tree not implemented yet!");
}
static void child_get_buffer(char* name) {
CHILD_DBG((2,"CMD get buffer name='%s'",name));
child_err(ECHLD_ERR_UNIMPLEMENTED,child.reqh_id,"get_buffer not implemented yet!");
}
static void child_add_note(int framenum, char* note) {
CHILD_DBG((2,"CMD add note framenum=%d note='%s'",framenum,note));
child_err(ECHLD_ERR_UNIMPLEMENTED,child.reqh_id,"add_note not implemented yet!");
}
static void child_apply_filter(char* filter) {
CHILD_DBG((2,"CMD apply filter filter='%s'",filter));
child_err(ECHLD_ERR_UNIMPLEMENTED,child.reqh_id,"apply_filter not implemented yet!");
}
static void child_save_file(char* filename, char* pars) {
CHILD_DBG((2,"CMD save file filename='%s' params='%s'",filename,pars));
child_err(ECHLD_ERR_UNIMPLEMENTED,child.reqh_id,"save_file not implemented yet!");
}
static long child_receive(guint8* b, size_t len, echld_chld_id_t chld_id, echld_msg_type_t type, echld_reqh_id_t reqh_id, void* data _U_) {
GByteArray ba;
GByteArray* gba;
char* err = NULL;
child.reqh_id = reqh_id;
CHILD_DBG((2,"RCVD type='%s' len='%d'",TY(type),len));
#if 0
gettimeofday(&(child.now), NULL);
#endif
if (child.chld_id != chld_id) {
child_err(ECHLD_ERR_WRONG_MSG,reqh_id,
"chld_id: own:%d given:%d msg_type='%s'",child.chld_id,chld_id,TY(type));
return 0;
}
ba.data = b;
ba.len = (guint)len;
switch(type) {
case ECHLD_NEW_CHILD: {
child.state = CREATING;
if ( !paramset_apply_em(child_params,(enc_msg_t*)&ba, &err) ) {
child_err(ECHLD_ERR_CRASHED_CHILD,reqh_id,
"Initial Paramset Error '%s'",err);
} else {
child.state = IDLE;
CHILD_RESP(NULL,ECHLD_HELLO);
}
break;
}
case ECHLD_PING:
CHILD_DBG((1,"PONG"));
CHILD_RESP(&ba,ECHLD_PONG);
break;
case ECHLD_SET_PARAM:{
char* param;
char* value;
if ( child.dec->set_param && child.dec->set_param(b,len,&param,&value) ) {
if (! paramset_apply_set (child_params, param, value, &err) ) {
child_err(ECHLD_CANNOT_SET_PARAM,reqh_id,"%s",err);
g_free(err);
return 0;
}
gba = child.enc->param(param,value);
CHILD_RESP(gba,ECHLD_PARAM);
g_byte_array_free(gba,TRUE);
CHILD_DBG((1,"Set Param: param='%s' value='%s'",param,value));
break;
} else {
goto misencoded;
}
}
case ECHLD_GET_PARAM: {
char* param;
if ( child.dec->get_param && child.dec->get_param(b,len,&param) ) {
char* val;
if (! (val = paramset_apply_get (child_params, param, &err)) ) {
child_err(ECHLD_CANNOT_GET_PARAM,reqh_id,"%s",err);
g_free(err);
return 0;
}
gba = child.enc->param(param,val);
CHILD_RESP(gba,ECHLD_PARAM);
g_byte_array_free(gba,TRUE);
CHILD_DBG((2,"Get Param: param='%s' value='%s'",param,val));
break;
} else {
goto misencoded;
}
}
case ECHLD_CLOSE_CHILD:
CHILD_RESP(NULL,ECHLD_CLOSING);
CHILD_DBG((3,"Closing"));
select(0,NULL,NULL,NULL,&close_sleep_time);
CHILD_DBG((1,"Bye"));
exit(0);
break;
case ECHLD_OPEN_FILE: {
char* filename;
if (child.state != IDLE) goto wrong_state;
if ( child.dec->open_file(b,len,&filename) ) {
child_open_file(filename);
} else {
child_err(ECHLD_DECODE_ERROR,reqh_id,"cannot decode open_file");
}
break;
}
case ECHLD_OPEN_INTERFACE: {
char* intf;
char* pars;
if (child.state != IDLE) goto wrong_state;
if ( child.dec->open_interface(b,len,&intf,&pars) ) {
child_open_interface(intf,pars);
} else {
child_err(ECHLD_DECODE_ERROR,reqh_id, "cannot decode open_interface");
}
break;
}
case ECHLD_START_CAPTURE:{
if (child.state != READY) goto wrong_state;
child_start_capture();
break;
}
case ECHLD_STOP_CAPTURE: {
if (child.state != CAPTURING) goto wrong_state;
child_stop_capure();
break;
}
case ECHLD_GET_SUM: {
char* range;
if (child.state != CAPTURING && child.state != READING && child.state != DONE) goto wrong_state;
if ( child.dec->get_sum(b,len,&range) ) {
child_get_summary(range);
} else {
child_err(ECHLD_DECODE_ERROR,reqh_id,"cannot decode get_summary");
}
break;
}
case ECHLD_GET_TREE:{
char* range;
if (child.state != CAPTURING && child.state != READING && child.state != DONE) goto wrong_state;
if ( child.dec->get_tree(b,len,&range) ) {
child_get_tree(range);
} else {
child_err(ECHLD_DECODE_ERROR,reqh_id,"cannot decode get_tree");
}
break;
}
case ECHLD_GET_BUFFER:{
char* name;
if (child.state != CAPTURING && child.state != READING && child.state != DONE) goto wrong_state;
if ( child.dec->get_buffer(b,len,&name) ) {
child_get_buffer(name);
} else {
child_err(ECHLD_DECODE_ERROR,reqh_id,"cannot decode get_buffer");
}
break;
}
case ECHLD_ADD_NOTE: {
int framenum;
char* note;
if (child.state != CAPTURING && child.state != READING && child.state != DONE) goto wrong_state;
if ( child.dec->add_note(b,len,&framenum,&note) ) {
child_add_note(framenum,note);
} else {
child_err(ECHLD_DECODE_ERROR,reqh_id,"cannot decode get_buffer");
}
break;
}
case ECHLD_APPLY_FILTER: {
char* filter;
if (child.state != DONE) goto wrong_state;
if ( child.dec->apply_filter(b,len,&filter) ) {
child_apply_filter(filter);
} else {
child_err(ECHLD_DECODE_ERROR,reqh_id,"cannot decode apply_filter");
}
break;
}
case ECHLD_SAVE_FILE: {
char* filename;
char* pars;
if (child.state != DONE) goto wrong_state;
if ( child.dec->save_file(b,len,&filename,&pars) ) {
child_save_file(filename,pars);
} else {
child_err(ECHLD_DECODE_ERROR,reqh_id,"cannot decode save_file");
}
break;
}
default:
child_err(ECHLD_ERR_WRONG_MSG,reqh_id,"wrong message: chld_id=%d msg_type='%s'",chld_id,TY(type));
break;
}
return 0;
misencoded:
/* dump the misencoded message (b,blen) */
child_err(ECHLD_ERR_WRONG_MSG,reqh_id,"misencoded msg msg_type='%s'",TY(type));
return 0;
wrong_state:
child_err(ECHLD_ERR_WRONG_MSG,reqh_id,"unexpected message: received in wrong state='%s', msg_type='%s'",ST(child.state),TY(type));
return 0;
}
static int child_dumpcap_read(void) {
/* this folk manages the reading of dumpcap's pipe
* it has to read interface descriptions when doing so
* and managing capture during capture
*/
CHILD_DBG((2,"child_dumpcap_read"));
return FALSE;
}
static void child_file_read(void) {
}
int echld_child_loop(void) {
int disp_from = child.parent.fd;
int disp_to = child.fds.pipe_to_parent;
#ifdef DEBUG_CHILD
int step = 0;
#endif
CHILD_DBG((0,"entering child_loop()"));
do {
fd_set rfds;
fd_set wfds;
fd_set efds;
struct timeval timeout;
int nfds;
gboolean captured = FALSE;
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_ZERO(&efds);
FD_SET(disp_from,&rfds);
FD_SET(disp_from,&efds);
FD_SET(disp_to,&efds);
if (child.fds.pipe_from_dumpcap > 0) {
FD_SET(child.fds.pipe_from_dumpcap,&rfds);
}
#ifdef DEBUG_CHILD
if (step <= 20) CHILD_DBG((4,"child_loop: select()ing step=%d",step++));
#endif
timeout.tv_sec = 0;
timeout.tv_usec = 999999;
nfds = select(FD_SETSIZE, &rfds, &wfds, &efds, &timeout);
#ifdef DEBUG_CHILD
if (step <= 20) CHILD_DBG((4,"child_loop: select()ed nfds=%d",nfds));
#endif
if ( FD_ISSET(disp_from,&efds) ) {
CHILD_DBG((0,"Broken Parent Pipe 'From' step=%d",step));
break;
}
if ( FD_ISSET(disp_to,&efds) ) {
CHILD_DBG((0,"Broken Parent Pipe 'To' step=%d",step));
break;
}
if (child.fds.pipe_from_dumpcap > 0 && FD_ISSET(child.fds.pipe_from_dumpcap,&efds) ) {
CHILD_DBG((0,"Broken Dumpcap Pipe step=%d",step));
break;
}
if (FD_ISSET(disp_from, &rfds)) {
long st = echld_read_frame(&(child.parent), child_receive, &child);
#ifdef DEBUG_CHILD
step = 0;
#endif
if (st < 0) {
CHILD_DBG((0,"Read Frame Failed step=%d",step));
return (int)st;
}
}
if (child.fds.pipe_from_dumpcap > 0 && FD_ISSET(child.fds.pipe_from_dumpcap,&rfds) ) {
#ifdef DEBUG_CHILD
step = 0;
#endif
captured = child_dumpcap_read();
}
if ( child.state == READING || captured ) {
child_file_read();
}
} while(1);
CHILD_RESP(NULL,ECHLD_CLOSING);
CHILD_DBG((3,"Closing"));
return 222;
}

View File

@ -1,922 +0,0 @@
/* echld_common.h
* common functions of ECHLD
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* Copyright (c) 2013 by Luis Ontanon <luis@ontanon.org>
*
* 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.
*/
#include "echld-int.h"
#ifdef DEBUG_BASE
static int dbg_level = DEBUG_BASE;
static FILE* dbg_fp;
static const char* dbg_prefix;
static void common_dbg(int level, const char* fmt, ...) {
va_list ap;
char str[1024];
if (level > dbg_level) return;
va_start(ap,fmt);
g_vsnprintf(str,1024,fmt,ap);
va_end(ap);
if (dbg_fp) {
fprintf(dbg_fp,"%s: level=%d msg='%s'\n",dbg_prefix,level,str);
fflush(dbg_fp);
}
}
extern void echld_common_set_dbg(int level, FILE* fp, const char* prefix) {
dbg_prefix = prefix;
dbg_level = level;
dbg_fp = fp;
}
#define DBG(attrs) ( common_dbg attrs )
#else
#define DBG(attrs)
#endif
struct _st_map
{
child_state_t id;
const char* str;
};
static struct _st_map st_map[] = {
{ FREE, "FREE"},
{ CREATING, "CREATING"},
{ IDLE, "IDLE"},
{ READY, "READY"},
{ READING, "READING"},
{ CAPTURING, "CAPTURING"},
{ DONE, "DONE"},
{ CLOSING, "CLOSING"},
{ CLOSED, "CLOSED"},
{ ERRORED, "ERRORED"},
{0,NULL}
};
const char* echld_state_str(child_state_t id) {
int i = 0;
for (;st_map[i].str;i++) {
if (id == st_map[i].id) return st_map[i].str;
}
return "UNKNOWN";
}
struct _t_map
{
echld_msg_type_t type;
const char* str;
};
static struct _t_map t_map[] = {
{ECHLD_ERROR,"ERROR"},
{ECHLD_TIMED_OUT,"TIMED_OUT"},
{ECHLD_NEW_CHILD,"NEW_CHILD"},
{ECHLD_HELLO,"HELLO"},
{ECHLD_CHILD_DEAD,"CHILD_DEAD"},
{ECHLD_CLOSE_CHILD,"CLOSE_CHILD"},
{ECHLD_CLOSING,"CLOSING"},
{ECHLD_SET_PARAM,"SET_PARAM"},
{ECHLD_GET_PARAM,"GET_PARAM"},
{ECHLD_PARAM,"PARAM"},
{ECHLD_PING,"PING"},
{ECHLD_PONG,"PONG"},
{ECHLD_OPEN_FILE,"OPEN_FILE"},
{ECHLD_FILE_OPENED,"FILE_OPENED"},
{ECHLD_OPEN_INTERFACE,"OPEN_INTERFACE"},
{ECHLD_INTERFACE_OPENED,"INTERFACE_OPENED"},
{ECHLD_START_CAPTURE,"START_CAPTURE"},
{ECHLD_CAPTURE_STARTED,"CAPTURE_STARTED"},
{ECHLD_NOTIFY,"NOTIFY"},
{ECHLD_GET_SUM,"GET_SUM"},
{ECHLD_PACKET_SUM,"PACKET_SUM"},
{ECHLD_GET_TREE,"GET_TREE"},
{ECHLD_TREE,"TREE"},
{ECHLD_GET_BUFFER,"GET_BUFFER"},
{ECHLD_BUFFER,"BUFFER"},
{ECHLD_EOF,"EOF"},
{ECHLD_STOP_CAPTURE,"STOP_CAPTURE"},
{ECHLD_CAPTURE_STOPPED,"CAPTURE_STOPPED"},
{ECHLD_ADD_NOTE,"ADD_NOTE"},
{ECHLD_NOTE_ADDED,"NOTE_ADDED"},
{ECHLD_APPLY_FILTER,"APPLY_FILTER"},
{ECHLD_PACKET_LIST,"PACKET_LIST"},
{ECHLD_SAVE_FILE,"SAVE_FILE"},
{ECHLD_FILE_SAVED,"FILE_SAVED"},
{ECHLD_NULL,NULL}
};
const char* echld_msg_type_str(echld_msg_type_t id) {
int i = 0;
for (;t_map[i].str;i++) {
if (id == t_map[i].type) return t_map[i].str;
}
return "UNKNOWN";
}
/**
the "epan pipe" protocol
**/
typedef void (*reader_realloc_t)(echld_reader_t*, size_t);
static void child_realloc_buff(echld_reader_t* r, size_t needed) {
size_t a = r->actual_len;
size_t s = r->len;
long rp_off = r->rp - r->data;
DBG((2,"REALLOC BUFF needed=%d",needed));
if ( a < (s + needed) ) {
guint8* data = r->data;
do {
a *= 2;
} while( a < (s + needed) );
data = (guint8*)g_realloc(data,a);
r->actual_len = a;