]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
removing pointers from packet struct. adding unit test options to cmake.
authorJosh <jrosenba@cisco.com>
Fri, 6 Jun 2014 18:08:34 +0000 (14:08 -0400)
committerJosh <jrosenba@cisco.com>
Fri, 6 Jun 2014 18:56:57 +0000 (14:56 -0400)
226 files changed:
cmake/FindCHECK.cmake
cmake/setConfigureOptions.cmake
doc/CMakeLists.txt
src/CMakeLists.txt
src/Makefile.am
src/codecs/CMakeLists.txt
src/codecs/Makefile.am
src/codecs/checksum.cc
src/codecs/checksum.h
src/codecs/codec_api.cc
src/codecs/codec_events.cc
src/codecs/decode.h [deleted file]
src/codecs/ip/CMakeLists.txt
src/codecs/ip/Makefile.am
src/codecs/ip/cd_ah.cc
src/codecs/ip/cd_ah_module.h
src/codecs/ip/cd_dstopts.cc
src/codecs/ip/cd_esp_module.h
src/codecs/ip/cd_frag.cc
src/codecs/ip/cd_gre.cc
src/codecs/ip/cd_gre_module.h
src/codecs/ip/cd_hopopts.cc
src/codecs/ip/cd_icmp4.cc
src/codecs/ip/cd_icmp4_module.h
src/codecs/ip/cd_icmp6.cc
src/codecs/ip/cd_icmp6_module.h
src/codecs/ip/cd_igmp_module.h
src/codecs/ip/cd_ipv4.cc
src/codecs/ip/cd_ipv4_module.h
src/codecs/ip/cd_ipv6.cc
src/codecs/ip/cd_ipv6_module.h
src/codecs/ip/cd_mobility.cc [new file with mode: 0644]
src/codecs/ip/cd_no_next.cc
src/codecs/ip/cd_pgm_module.h
src/codecs/ip/cd_pim.cc [new file with mode: 0644]
src/codecs/ip/cd_routing.cc
src/codecs/ip/cd_sun_nd.cc [new file with mode: 0644]
src/codecs/ip/cd_swipe.cc
src/codecs/ip/cd_tcp.cc
src/codecs/ip/cd_tcp_module.h
src/codecs/ip/cd_udp.cc
src/codecs/ip/cd_udp_module.h
src/codecs/link/CMakeLists.txt
src/codecs/link/cd_arp.cc
src/codecs/link/cd_arp_module.h
src/codecs/link/cd_eapol.cc
src/codecs/link/cd_eapol_module.h
src/codecs/link/cd_erspan2.cc
src/codecs/link/cd_erspan2_module.h
src/codecs/link/cd_erspan3.cc
src/codecs/link/cd_erspan3_module.h
src/codecs/link/cd_ethloopback.cc
src/codecs/link/cd_mpls.cc
src/codecs/link/cd_mpls_module.cc
src/codecs/link/cd_mpls_module.h
src/codecs/link/cd_pppencap.cc
src/codecs/link/cd_pppoepkt.cc
src/codecs/link/cd_pppoepkt_module.cc
src/codecs/link/cd_pppoepkt_module.h
src/codecs/link/cd_transbridge.cc
src/codecs/link/cd_vlan.cc
src/codecs/link/cd_vlan_module.h
src/codecs/misc/cd_gtp.cc
src/codecs/misc/cd_gtp_module.h
src/codecs/misc/cd_teredo.cc
src/codecs/root/CMakeLists.txt
src/codecs/root/Makefile.am
src/codecs/root/cd_eth.cc
src/codecs/root/cd_eth_module.h
src/codecs/root/cd_ieee80211.cc [deleted file]
src/codecs/root/cd_linux_sll.cc [new file with mode: 0644]
src/codecs/root/cd_null.cc [moved from src/codecs/root/cd_null_root.cc with 86% similarity]
src/codecs/root/cd_raw4.cc
src/codecs/root/cd_raw6.cc
src/codecs/root/cd_tr.cc [moved from src/codecs/root/cd_trk.cc with 54% similarity]
src/codecs/root/cd_tr_module.cc [new file with mode: 0644]
src/codecs/root/cd_tr_module.h [moved from src/codecs/layer.h with 68% similarity]
src/codecs/root/cd_wlan.cc [new file with mode: 0644]
src/codecs/root/cd_wlan_module.cc [new file with mode: 0644]
src/codecs/root/cd_wlan_module.h [new file with mode: 0644]
src/codecs/root/prot_ipx.cc
src/codecs/root/root_chdlc.cc
src/codecs/root/root_enc.cc
src/codecs/root/root_fddi.cc
src/codecs/root/root_i4lciscoip.cc
src/codecs/root/root_i4lrawip.cc
src/codecs/root/root_linuxsll.cc [deleted file]
src/codecs/root/root_oldpflog.cc
src/codecs/root/root_pflog.cc
src/codecs/root/root_ppp.cc
src/codecs/root/root_pppserial.cc
src/codecs/root/root_slip.cc
src/codecs/template.cc
src/detection/detect.h
src/detection/detection_util.h
src/detection/fpdetect.cc
src/detection/fpdetect.h
src/detection/pcrm.h
src/detection/tag.cc
src/detection/tag.h
src/file_api/file_mime_process.cc
src/file_api/file_resume_block.cc
src/file_api/file_resume_block.h
src/filters/rate_filter.h
src/flow/CMakeLists.txt
src/flow/expect_cache.h
src/flow/flow.cc
src/flow/flow_control.cc
src/flow/flow_key.cc
src/framework/codec.h
src/ips_options/extract.cc
src/ips_options/extract.h
src/ips_options/ips_ack.cc
src/ips_options/ips_asn1.cc
src/ips_options/ips_base64_data.cc
src/ips_options/ips_base64_decode.cc
src/ips_options/ips_byte_extract.cc
src/ips_options/ips_byte_jump.cc
src/ips_options/ips_byte_test.cc
src/ips_options/ips_cvs.cc
src/ips_options/ips_dsize.cc
src/ips_options/ips_file_data.cc
src/ips_options/ips_flags.cc
src/ips_options/ips_flow.cc
src/ips_options/ips_flowbits.cc
src/ips_options/ips_fragbits.cc
src/ips_options/ips_fragoffset.cc
src/ips_options/ips_ftpbounce.cc
src/ips_options/ips_icmp_id.cc
src/ips_options/ips_icmp_seq.cc
src/ips_options/ips_icode.cc
src/ips_options/ips_id.cc
src/ips_options/ips_ip_proto.cc
src/ips_options/ips_ipopts.cc
src/ips_options/ips_isdataat.cc
src/ips_options/ips_itype.cc
src/ips_options/ips_pcre.cc
src/ips_options/ips_pkt_data.cc
src/ips_options/ips_react.cc
src/ips_options/ips_resp.cc
src/ips_options/ips_rpc.cc
src/ips_options/ips_sameip.cc
src/ips_options/ips_seq.cc
src/ips_options/ips_session.cc
src/ips_options/ips_tos.cc
src/ips_options/ips_ttl.cc
src/ips_options/ips_urilen.cc
src/ips_options/ips_window.cc
src/ips_options/replace.cc
src/log/CMakeLists.txt
src/log/log.cc
src/log/log.h
src/log/log_text.cc
src/log/obfuscation.cc
src/loggers/CMakeLists.txt
src/loggers/alert_csv.cc
src/loggers/alert_fast.cc
src/loggers/alert_full.cc
src/loggers/alert_syslog.cc
src/loggers/alert_test.cc
src/loggers/alert_unixsock.cc
src/loggers/log_tcpdump.cc
src/loggers/unified2.cc
src/main/analyzer.h
src/main/snort.cc
src/main/snort.h
src/managers/packet_manager.cc
src/managers/packet_manager.h
src/network_inspectors/arp_spoof/arp_spoof.cc
src/network_inspectors/normalize/norm.cc
src/network_inspectors/normalize/norm.h
src/network_inspectors/perf_monitor/perf.cc
src/network_inspectors/perf_monitor/perf.h
src/network_inspectors/perf_monitor/perf_base.h
src/network_inspectors/perf_monitor/perf_flow.h
src/network_inspectors/port_scan/port_scan.cc
src/network_inspectors/port_scan/ps_detect.cc
src/packet_io/active.h
src/parser/parse_otn.cc
src/parser/parse_rule.cc
src/parser/parser.cc
src/parser/parser.h
src/parser/vars.cc
src/protocols/CMakeLists.txt
src/protocols/Makefile.am
src/protocols/arp.h
src/protocols/decode.h [deleted file]
src/protocols/eapol.h [new file with mode: 0644]
src/protocols/gre.h
src/protocols/icmp6.h
src/protocols/ipv4.h
src/protocols/layer.cc [new file with mode: 0644]
src/protocols/layer.h [new file with mode: 0644]
src/protocols/linux_sll.h [new file with mode: 0644]
src/protocols/packet.h
src/protocols/protocol_ids.h
src/protocols/token_ring.h [new file with mode: 0644]
src/protocols/vlan.h [new file with mode: 0644]
src/protocols/wlan.h
src/service_inspectors/back_orifice/back_orifice.cc
src/service_inspectors/ftp_telnet/ft_main.h
src/service_inspectors/ftp_telnet/ftp_parse.h
src/service_inspectors/ftp_telnet/ftpp_include.h
src/service_inspectors/ftp_telnet/ftpp_si.h
src/service_inspectors/ftp_telnet/pp_ftp.h
src/service_inspectors/ftp_telnet/pp_telnet.h
src/service_inspectors/http_inspect/hi_main.cc
src/service_inspectors/http_inspect/hi_main.h
src/service_inspectors/http_inspect/hi_paf.cc
src/service_inspectors/http_inspect/hi_si.h
src/service_inspectors/http_inspect/http_inspect.cc
src/service_inspectors/rpc_decode/rpc_decode.cc
src/sfip/sf_iph.cc
src/stream/CMakeLists.txt
src/stream/icmp/CMakeLists.txt
src/stream/icmp/icmp_session.cc
src/stream/ip/ip_defrag.cc
src/stream/stream_api.cc
src/stream/tcp/stream_tcp.h
src/stream/tcp/tcp_session.cc
src/stream/udp/udp_session.cc
src/target_based/sftarget_protocol_reference.h
src/test/CMakeLists.txt
src/test/build_decl.sh [new file with mode: 0755]
src/test/build_list.sh [new file with mode: 0755]
src/time/ppm.cc

index 5e4e507962d64b6681046fe1c87349438cb0ba71..11da7497d6ed31e1a914fd956887dc0b9799fee0 100644 (file)
@@ -5,26 +5,26 @@ set(ERROR_MESSAGE
      'make check' command"
 )
 
-find_library(CHECK_LIBRARY
-    NAMES check
-)
 
-find_path (CHECK_INCLUDE_DIRS
+find_path (CHECK_INCLUDE_DIR
     NAMES check.h
 )
 
+find_library(CHECK_LIBRARIES
+    NAMES check
+)
 
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(CHECK
-    REQUIRED_VARS CHECK_INCLUDE_DIRS CHECK_INCLUDE_DIRS
+    REQUIRED_VARS CHECK_INCLUDE_DIR CHECK_LIBRARIES
     FAIL_MESSAGE "${ERROR_MESSAGE}"
 )
 
 
 
 mark_as_advanced(
-    CHECK_INCLUDE_DIR
-    CHECK_LIBRARIES 
+    CHECK_INCLUDE_DIR
+    CHECK_LIBRARIES
 )
 
 
index f3ba6bc2fd9a6c671d7e17673c508d55b033d41f..3fd059913cc3d4d54cd0557d6210ac0d392b9fd3 100644 (file)
@@ -86,6 +86,10 @@ if(ENABLE_PROFILE AND CMAKE_COMPILER_IS_GNUCXX)
 endif()
 
 
+if (BUILD_UNIT_TESTS)
+    enable_testing()
+endif()
+
 # sanity checks to re-check and set all necesssary variables
 
 if (NOT ASCIIDOC_FOUND)
index 4ddd1c3934f84e6bc8c7e10b2c6ce53c1d88a184..06d7080545b1320782d572423fc70c54106200ab 100644 (file)
@@ -1,7 +1,9 @@
 
 #
-# This list of built sources MUST be kept up to date with
-# the actual build targets located at the bottom of src/CMakelists.txt
+# Assuming a file the source file is 'file_name.txt' the BUILT_SOURCES
+# files will be created with the following command
+#
+#  snort --help-file_name > file_name.txt
 #
 set(BUILT_SOURCES
     builtin.txt
@@ -9,6 +11,8 @@ set(BUILT_SOURCES
     config.txt
     options.txt
     gids.txt
+#    version.txt   Required special formatting. manually add below.
+    CACHE INTERNAL "sources to be built" FORCE
 )
 
 set (UNBUILT_SOURCES
@@ -16,10 +20,10 @@ set (UNBUILT_SOURCES
     differences.txt
     style.txt
     tips.txt
-    images/snort.png
+    plugins.txt
+#    images/snort.png   # images directory is manually included as an a2x option
 )
 
-
 if (MAKE_HTML_DOC)
     set(HTML_DOCS
         snort_manual.html
@@ -32,46 +36,42 @@ if (MAKE_PDF_DOC)
     set(PDF_DOCS snort_manual.pdf)
 endif()
 
-
 # Docuements to be built
 set (EXTRA_DIST ${HTML_DOCS} ${PDF_DOCS})
 
 
-###############################################################################
-###############################################################################
-
-
-
-
-
 ###############################################################################
 ###############################################################################
 
 
 ###############################################################################
 #                                                                             #
-#  Since we'd lke to keep the source tree unpolluted, only build targets      #
-#  in the build directory.  The rest of this file creates custom commands to  #
-#  copy all of the documents into the doc/ directory.                         #
+#  Since we'd lke to keep the source tree unpolluted, create all targets in   #
+#  the build directory.  This section adds custom commands to copy all of the #
+#  BUILT_SOURCES into this directory and create all of the UNBUILT_SOURCES in #
+#  this directory.                                                            #
+#                                                                             #
+#  NOTE: BUILT_SOURCES recipes are actually defined in src/CMakeLists.txt to  #
+#  ensure a file dependency on Snort. This section copies those built sources #
+#  into this directory.                                                       #
 #                                                                             #
 ###############################################################################
 
-
-#  Due to the depency on the snort executable, the files are created in a 
-#  different directory and copied into the top level of the build directory
-#  This next loop copies all of the appropriate files into the doc direcotry
-
+# copy built files into this directory
 set (TARGET_DIR ${CMAKE_BINARY_DIR})
-foreach (file ${BUILT_SOURCES})
+foreach (file ${BUILT_SOURCES};version.txt)
     set(input ${CMAKE_BINARY_DIR}/${file})
     set (output ${CMAKE_CURRENT_BINARY_DIR}/${file})
 
+    # create this custom file name so it can be used below. Doesn't actually
+    # build the file itself.
     add_custom_command(
         OUTPUT ${input}
         COMMAND ${CMAKE_COMMAND}
             -E touch_nocreate ${input}
     )
 
+    #  complementary section to the foreach loop at the bottom of src/CMakeLists.txt
     add_custom_command(
         OUTPUT ${output}
         COMMAND ${CMAKE_COMMAND}
@@ -88,17 +88,6 @@ foreach (file ${BUILT_SOURCES})
 endforeach(file)
 
 
-#copying the images directory!
-add_custom_target(copy_images DEPENDS images)
-add_custom_command(
-    OUTPUT images
-    COMMAND ${CMAKE_COMMAND}
-            -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/images ${CMAKE_CURRENT_BINARY_DIR}/images
-    COMMENT "Copying doc/images.  If the doc/images directory changes, rerun the cmake command!!"
-)
-set_source_files_properties(images SYMBOLIC "YES")
-
-
 # Copy all distributed files into the binary tree (necessary for asciidocs).
 # Then create a dependency between the new and old files.
 foreach (file ${UNBUILT_SOURCES})
@@ -106,13 +95,11 @@ foreach (file ${UNBUILT_SOURCES})
         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${file}
         COMMAND ${CMAKE_COMMAND} 
                 -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${file} ${CMAKE_CURRENT_BINARY_DIR}/${file}
-        MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${file}
-        DEPENDS copy_images
+        MAIN_DEPENDENCY ${file}
         COMMENT "Copying ${file} into binary directory"
     )
 
     list(APPEND UNBUILT_SOURCES_BINARY_PATH "${CMAKE_CURRENT_BINARY_DIR}/${file}")
-#    set(UNBUILT_SOURCES_BINARY_PATH "${UNBUILT_SOURCES_BINARY_PATH} ${CMAKE_CURRENT_BINARY_DIR}/${file}")
 endforeach(file)
 
 foreach (file ${EXTRA_DIST})
@@ -129,19 +116,18 @@ set (ALL_SOURCES
 ###############################################################################
 ###############################################################################
 
-#  This part contains all of the custom commmands for creating the actual
-#  documentation.
+#  create the recipes for building the files
 
 
-set (PDF_ARGUMENTS --icons --icons-dir=./images/icons -a imagesdir=./images)
+set (PDF_ARGUMENTS --icons --icons-dir=./images/icons --resource=${CMAKE_CURRENT_SOURCE_DIR}/images )
 set (HTML_ARGUMENTS --copy --attribute linkcss --attribute stylesdir --attribute disable-javascript --attribute quirks! ${PDF_ARGUMENTS})
 
 add_custom_command(OUTPUT snort_manual.html
     COMMAND ${ASCIIDOC_A2X_EXE} 
         -f xhtml 
         ${HTML_ARGUMENTS} 
-        --resource=${CMAKE_CURRENT_BINARY_DIR} 
-        --destination-dir=${CMAKE_CURRENT_BINARY_DIR} 
+        --resource=${CMAKE_CURRENT_BINARY_DIR}
+        --destination-dir=${CMAKE_CURRENT_BINARY_DIR}
         ${CMAKE_CURRENT_BINARY_DIR}/snort_manual.txt 
     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/snort_manual.txt ${ALL_SOURCES}
     COMMENT "Documents: building snort_manual.html"
@@ -169,7 +155,7 @@ add_custom_command(OUTPUT snort_manual.tgz
         zcf snort_manual.tgz
         ${CMAKE_CURRENT_BINARY_DIR}/snort_manual.chunked
     MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/snort_manual.txt
-    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/images ${ALL_SOURCES}
+    DEPENDS ${ALL_SOURCES}
     COMMENT "Documents: building snort_manual.tgz"
 )
 
@@ -178,9 +164,9 @@ add_custom_command(OUTPUT images.tgz
         zcf images.tgz 
         --exclude callouts 
         --exclude README
-        -C ${CMAKE_CURRENT_BINARY_DIR}/images 
+        -C ${CMAKE_CURRENT_SOURCE_DIR}/images
         .
-    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/images ${ALL_SOURCES}
+    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/images ${ALL_SOURCES}
     COMMENT "Documents: building images.tgz"
 )
 
@@ -188,14 +174,14 @@ add_custom_command(OUTPUT images.tgz
 ###############################################################################
 ###############################################################################
 
-# Finally, the commands to create the manuals, and the command to install the 
-# manuals
+# Finally, the commands to set the manual dependencies and install the
+# built documents
 
 
 add_custom_target(snort_manuals ALL
     DEPENDS ${EXTRA_DIST}
 )
-add_dependencies(snort_manuals snort)
+add_dependencies(snort_manuals snort ${ALL_SOURCES})
 
 
 
index fcecea75ae139715bb30db1c0cc67dc2748a146e..1e972ab0e83032a40bdaa9e1672908ddfde1f1a8 100644 (file)
@@ -23,7 +23,7 @@ include_directories(target_based)
 include_directories(time)
 include_directories(utils)
 
-add_executable(snort
+add_executable( snort
     main.h
     main.cc
 )
@@ -39,12 +39,11 @@ if (STATIC_INSPECTORS)
 endif(STATIC_INSPECTORS)
 
 if (BUILD_UNIT_TESTS)
-    set( UNIT_TESTS_LIBRARIES test)
+    set( UNIT_TESTS_LIBRARIES unit_tests)
     add_subdirectory(test)
 endif( BUILD_UNIT_TESTS)
 
-set_default_visibility_compile_flag(snort)
-target_link_libraries(snort
+target_link_libraries( snort
     main
     target_based
     log
@@ -137,105 +136,51 @@ install(TARGETS snort
 )
 
 ##############################################################################
-#
-#  This is the documents seciton of the cmake file.  Yes, I hate that I am 
-#  putting this stuff in the src directory instead of the doc directory,
-#  but these files are dependent on the Snort executable.  Since complete
-#  platform independence is the goal, these command need a file level
-#  dependcy on snort, which means they need to be here
-#
-#  When creating new files, follow these directions
-#       1) Copy an entire segment (include the set, add_custom_command, 
-#           and add_custom_target pieces)
-#       2) Change the ARGS to create the file you want
-#       3) Add the file name to list of BUILT_SOURCES at the top of 
-#           doc/CMakeLists.txt
-#
+#                                                                            #
+#  This is the documents section of the file.  It needs to be in same        #
+#  directory or subdirectory as snort to create a valid file dependency on   #
+#  snort.  To build another .txt file with a dependcy on snort, add the file #
+#  to the BUILT_SOURCES variable located at the top of doc/CMakeLists.txt.   #
+#  If the new file's name is new_file.txt, cmake will automatcially run the  #
+#  command                                                                   #
+#                                                                            #
+#  >>  snort --help-file_name > file_name.txt                                #
+#                                                                            #
+#  to creat the new file. Notice that the extension is missing in the help   #
+#  command. If the command does not exist, the behavior is undefined but     #
+#  will likely lead to error.                                                #
+#                                                                            #
 ##############################################################################
 
 
-
 if (MAKE_PDF_DOC OR MAKE_HTML_DOC)
 
+    foreach(file ${BUILT_SOURCES})
+        set(TARGET_DIR ${CMAKE_BINARY_DIR})
+        set(output ${TARGET_DIR}/${file})
+        get_filename_component(file_name "${file}" NAME_WE)
 
-    set(TARGET_DIR ${CMAKE_BINARY_DIR})
-
-
-    set(file builtin.txt)
-
-    set(output ${TARGET_DIR}/${file})
-    add_custom_command(
-        OUTPUT ${output}
-        COMMAND snort --markup --help-builtin > ${output}
-        MAIN_DEPENDENCY snort
-        COMMENT "Documents: building ${output}"
-    )
-    get_filename_component(file_name "${file}" NAME_WE)
-    add_custom_target(doc_${file_name} ALL DEPENDS ${output} )
-
-
-    set(file commands.txt)
-
-    set(output ${TARGET_DIR}/${file})
-    add_custom_command(
-        OUTPUT ${output}
-        COMMAND snort  --markup --help-commands > ${output}
-        MAIN_DEPENDENCY snort
-        COMMENT "Documents: building ${output}"
-    )
-    get_filename_component(file_name "${file}" NAME_WE)
-    add_custom_target(doc_${file_name} ALL DEPENDS ${output} )
-
-
-
-    set(file config.txt)
+        add_custom_command(
+            OUTPUT ${output}
+            COMMAND snort --markup --help-${file_name} | sort > ${output}
+            DEPENDS snort
+            COMMENT "Documents: building ${output}"
+        )
+        add_custom_target(doc_${file_name} ALL DEPENDS ${output} )
 
-    set(output ${TARGET_DIR}/${file})
-    add_custom_command(
-        OUTPUT ${output}
-        COMMAND snort --markup --help-config > ${output}
-        MAIN_DEPENDENCY snort
-        COMMENT "Documents: building ${output}"
-    )
-    get_filename_component(file_name "${file}" NAME_WE)
-    add_custom_target(doc_${file_name} ALL DEPENDS ${output})
-
-
-    set(file options.txt)
-
-    set(output ${TARGET_DIR}/${file})
-    add_custom_command(
-        OUTPUT ${output}
-        COMMAND snort --markup --help > ${output}
-        MAIN_DEPENDENCY snort
-        COMMENT "Documents: building ${output}"
-    )
-    get_filename_component(file_name "${file}" NAME_WE)
-    add_custom_target(doc_${file_name} ALL DEPENDS ${output})
-
-
-    set(file gids.txt)
+    endforeach()
 
-    set(output ${TARGET_DIR}/${file})
-    add_custom_command(
-        OUTPUT ${output}
-        COMMAND snort --markup --help-gids > ${output}
-        MAIN_DEPENDENCY snort
-        COMMENT "Documents: building ${output}"
-    )
-    get_filename_component(file_name "${file}" NAME_WE)
-    add_custom_target(doc_${file_name} ALL DEPENDS ${output})
 
 
+    #  version is different since it outputs to standard out.
     set(file version.txt)
 
     set(output ${TARGET_DIR}/${file})
     add_custom_command(
         OUTPUT ${output}
         COMMAND snort -V 2>&1 | grep -v Using > ${output}
-        MAIN_DEPENDENCY snort
+        DEPENDS snort
         COMMENT "Documents: building ${output}"
     )
-    get_filename_component(file_name "${file}" NAME_WE)
-    add_custom_target(doc_${file_name} ALL DEPENDS ${output})
+    add_custom_target(doc_version ALL DEPENDS ${output})
 endif()
index 4433dec447b72032aec98203f7486db432aa6eda..499cbf43b45f2fbda34cf674a3c4dc4f0baa0fd9 100644 (file)
@@ -60,6 +60,7 @@ packet_io/libpacket_io.a \
 helpers/libhelpers.a \
 sfip/libsfip.a \
 sfrt/libsfrt.a \
+protocols/libprotocols.a \
 utils/libutils.a
 
 SUBDIRS = \
index fd87319fe5d0359af748b33eb05e5587fe71345e..8cf13e5561729375c0d17662ff8c91ab5c5a5c9e 100644 (file)
@@ -7,7 +7,6 @@ add_subdirectory(misc)
 
 
 add_library( codecs STATIC
-    decode.h
     decode_module.h
     codec_api.h
     codec_api.cc
@@ -17,6 +16,7 @@ add_library( codecs STATIC
     codec_events.h
     checksum.h
     checksum.cc
+    template.cc   # for development purposes.  Keep the template up to date
 )
 
 
index d2f0d07047fc345b6361c6193ff16edbf68901e1..ff49b8de93a7cec052f4d65acc8c501c520c9125 100644 (file)
@@ -6,9 +6,7 @@ noinst_LIBRARIES += libcodec_utils.a
 libcodecs_a_SOURCES = \
 codec_api.cc \
 codec_api.h \
-decode.h \
 decode_module.h \
-layer.h \
 sf_protocols.h
 
 libcodec_utils_a_SOURCES = \
index 00a5604ea7ded457eb38e6cd8368f3f8c2ff60d3..a020cc3e1ed6964bf4636d2c5cea078fa73096af 100644 (file)
@@ -37,7 +37,7 @@ uint16_t cksum_add(const uint16_t *buf, size_t len, uint32_t cksum)
 
     if (len > 1 )
     {
-        sn = ((len / 2) & 0xF);  // len divided by two mod 16 == len/2 % 16
+        sn = ((len / 2) & 0xF);  // == len/2 % 16
         n = (((len / 2) + 15) / 16) ;  // ceiling of (len / 2) / 16
 
         switch (sn) {
index 5c0370f6b6f285fb7e5c243e9a36d2eb98d28f8d..ef3171d6cad4c2cad078e89ffb66cab9925d2e50 100644 (file)
 #include "config.h"
 #endif
 
-#ifndef WIN32
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <net/if.h>
-#else /* !WIN32 */
-#include <netinet/in_systm.h>
-#ifndef IFNAMSIZ
-#define IFNAMESIZ MAX_ADAPTER_NAME
-#endif /* !IFNAMSIZ */
-#endif /* !WIN32 */
-
+#include <stdint.h>
+#include <stdlib.h>
 
 
 namespace checksum
index 38d16d867016f9fc37ad76ee95e2b530b0bc3071..02f23637691fbf0d291a5df30899ca45a561cdb9 100644 (file)
 
 #include "framework/codec.h"
 
-// root decoders
+// root codecs
 extern const BaseApi* cd_eth;
 extern const BaseApi* cd_raw4;
 extern const BaseApi* cd_raw6;
-extern const BaseApi* cd_null_root;
+extern const BaseApi* cd_null;
 
 
-#ifndef NO_NON_ETHER_DECODER
-
-#endif
-
-// decoders
+// other codecs
 extern const BaseApi* cd_ipv4;
 extern const BaseApi* cd_ipv6;
 extern const BaseApi* cd_icmp4;
@@ -59,12 +55,16 @@ extern const BaseApi* cd_gre;
 extern const BaseApi* cd_gtp;
 extern const BaseApi* cd_hopopts;
 extern const BaseApi* cd_igmp;
+extern const BaseApi* cd_mobility;
 extern const BaseApi* cd_mpls;
 extern const BaseApi* cd_no_next;
+extern const BaseApi* cd_pim;
 extern const BaseApi* cd_pgm;
 extern const BaseApi* cd_pppencap;
-extern const BaseApi* cd_pppoe;
+extern const BaseApi* cd_pppoepkt_disc;
+extern const BaseApi* cd_pppoepkt_sess;
 extern const BaseApi* cd_routing;
+extern const BaseApi* cd_sun_nd;
 extern const BaseApi* cd_swipe;
 extern const BaseApi* cd_teredo;
 extern const BaseApi* cd_transbridge;
@@ -72,6 +72,9 @@ extern const BaseApi* cd_vlan;
 
 #ifndef NO_NON_ETHER_DECODER
 extern const BaseApi* cd_eapol;
+extern const BaseApi* cd_linux_sll;
+extern const BaseApi* cd_tr;
+extern const BaseApi* cd_wlan;
 
 #endif
 
@@ -83,11 +86,8 @@ const BaseApi* codecs[] =
     cd_eth,
     cd_raw4,
     cd_raw6,
-    cd_null_root,
+    cd_null,
 
-#ifndef NO_NON_ETHER_DECODER
-
-#endif
 
     // non root codeccs
     cd_ipv4,
@@ -110,12 +110,16 @@ const BaseApi* codecs[] =
     cd_gtp,
     cd_hopopts,
     cd_igmp,
+    cd_mobility,
     cd_mpls,
     cd_no_next,
+    cd_pim,
     cd_pgm,
     cd_pppencap,
-    cd_pppoe,
+    cd_pppoepkt_disc,
+    cd_pppoepkt_sess,
     cd_routing,
+    cd_sun_nd,
     cd_swipe,
     cd_teredo,
     cd_transbridge,
@@ -123,6 +127,9 @@ const BaseApi* codecs[] =
 
 #ifndef NO_NON_ETHER_DECODER
     cd_eapol,
+    cd_linux_sll,
+    cd_tr,
+    cd_wlan,
 #endif
 
 #endif
index c06b1d2bfe8425b61db9ddcf649296e846a5d7d7..b15ddb444501455809967796bd361b5a69dda795 100644 (file)
@@ -86,7 +86,5 @@ void codec_events::decoder_alert_encapsulated(
 
     p->data = pkt;
     p->dsize = (uint16_t)len;
-
-    p->greh = NULL;
 }
 
diff --git a/src/codecs/decode.h b/src/codecs/decode.h
deleted file mode 100644 (file)
index 9030070..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
-** Copyright (C) 2002-2013 Sourcefire, Inc.
-** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License Version 2 as
-** published by the Free Software Foundation.  You may not use, modify or
-** distribute this program under any other version of the GNU General
-** Public License.
-**
-** 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.
-*/
-
-#ifndef DECODE_H
-#define DECODE_H
-
-/*  I N C L U D E S  **********************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stddef.h>
-#include <sys/types.h>
-#include <string.h>
-
-#ifndef WIN32
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <net/if.h>
-#else /* !WIN32 */
-#include <netinet/in_systm.h>
-#ifndef IFNAMSIZ
-#define IFNAMESIZ MAX_ADAPTER_NAME
-#endif /* !IFNAMSIZ */
-#endif /* !WIN32 */
-
-extern "C" {
-#include <daq.h>
-#include <sfbpf_dlt.h>
-}
-
-#include "snort_types.h"
-#include "protocols/packet.h"
-#include "profiler.h"
-#include "protocols/mpls.h"
-
-
-
-
-
-/*  D E F I N E S  ************************************************************/
-
-#if 0
-#define ETH_DSAP_SNA                  0x08    /* SNA */
-#define ETH_SSAP_SNA                  0x00    /* SNA */
-#define ETH_DSAP_STP                  0x42    /* Spanning Tree Protocol */
-#define ETH_SSAP_STP                  0x42    /* Spanning Tree Protocol */
-#define ETH_DSAP_IP                   0xaa    /* IP */
-#define ETH_SSAP_IP                   0xaa    /* IP */
-
-#define ETH_ORG_CODE_ETHR              0x000000    /* Encapsulated Ethernet */
-#define ETH_ORG_CODE_CDP               0x00000c    /* Cisco Discovery Proto */
-#endif
-
-
-#define DEFAULT_MPLS_PAYLOADTYPE      MPLS_PAYLOADTYPE_IPV4
-#define DEFAULT_LABELCHAIN_LENGTH    -1
-
-
-#define MAX_PORTS 65536
-
-#if 0
-/* ppp header structure
- *
- * Actually, this is the header for RFC1332 Section 3
- * IPCP Configuration Options for sending IP datagrams over a PPP link
- *
- */
-struct ppp_header {
-    unsigned char  address;
-    unsigned char  control;
-    unsigned short protocol;
-};
-
-#ifndef PPP_HDRLEN
-    #define PPP_HDRLEN          sizeof(struct ppp_header)
-#endif
-
-/* otherwise defined in /usr/include/ppp_defs.h */
-#ifndef PPP_MTU
-    #define PPP_MTU                 1500
-#endif
-
-#endif
-
-
-#define IP_OPTMAX               40
-#define IP6_EXTMAX               8
-#define TCP_OPTLENMAX           40 /* (((2^4) - 1) * 4  - TCP_HEADER_LEN) */
-
-
-
-
-
-static inline uint16_t EXTRACT_16BITS(const uint8_t* p)
-{
-    return ntohs(*(uint16_t*)(p));
-}
-
-#ifdef WORDS_MUSTALIGN
-
-#if defined(__GNUC__)
-/* force word-aligned ntohl parameter */
-    static inline uint32_t EXTRACT_32BITS(const uint8_t* p)
-    {
-        uint32_t tmp;
-        memmove(&tmp, p, sizeof(uint32_t));
-        return ntohl(tmp);
-    }
-#endif /* __GNUC__ */
-
-#else
-
-/* allows unaligned ntohl parameter - dies w/SIGBUS on SPARCs */
-    static inline uint32_t EXTRACT_32BITS(const uint8_t* p)
-    {
-        return ntohl(*(uint32_t *)p);
-    }
-#endif /* WORDS_MUSTALIGN */
-
-
-
-const unsigned int ALERTMSG_LENGTH = 256;
-const int16_t  SFTARGET_UNKNOWN_PROTOCOL = -1;
-
-
-
-#endif
-
index 57e182f903a038e5cd6f693b96182d962d6178e3..7e19417edf45f4f88a95a80608bdc7fce72a543b 100644 (file)
@@ -16,10 +16,13 @@ if( STATIC_DECODERS )
         cd_igmp_module.h
         cd_igmp_module.cc
         cd_no_next.cc
+        cd_mobility.cc
+        cd_pim.cc
         cd_pgm.cc
         cd_pgm_module.h
         cd_pgm_module.cc
         cd_routing.cc
+        cd_sun_nd.cc
         cd_swipe.cc
     )
 
@@ -30,9 +33,12 @@ else()
     add_shared_library(cd_gre codecs cd_gre.cc cd_gre_module.h cd_gre_module.cc)
     add_shared_library(cd_hopopts codecs cd_hopopts.cc)
     add_shared_library(cd_igmp codecs cd_igmp.cc cd_igmp_module.h cd_igmp_module.cc)
+    add_shared_library(cd_mobility codecs cd_mobility.cc)
     add_shared_library(cd_no_next codecs cd_no_next.cc)
+    add_shared_library(cd_pim codecs cd_pim.cc)
     add_shared_library(cd_pgm codecs cd_pgm.cc cd_pgm_module.h cd_pgm_module.cc)
     add_shared_library(cd_routing codecs cd_routing.cc)
+    add_shared_library(cd_sun_nd codecs cd_sun_nd.cc)
     add_shared_library(cd_swipe codecs cd_swipe.cc)
 
 endif()
index 10f7fc333279ff88aab511fc25808a7b3fe27a7b..d500b658d8d4d8cd5a1bed07a985c0679d80329f 100644 (file)
@@ -39,11 +39,14 @@ cd_hopopts.cc \
 cd_igmp.cc \
 cd_igmp_module.h \
 cd_igmp_module.cc \
+cd_mobility.cc \
 cd_no_next.cc \
+cd_pim.cc \
 cd_pgm.cc \
 cd_pgm_module.h \
 cd_pgm_module.cc \
 cd_routing.cc \
+cd_sun_nd.cc \
 cd_swipe.cc
 
 
@@ -64,11 +67,26 @@ libcd_gre_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
 libcd_gre_la_LDFLAGS = -export-dynamic -shared
 libcd_gre_la_SOURCES = cd_gre.cc cd_gre_module.h cd_gre_module.cc
 
+ehlib_LTLIBRARIES += libcd_mobility.la
+libcd_mobility_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
+libcd_mobility_la_LDFLAGS = -export-dynamic -shared
+libcd_mobility_la_SOURCES = cd_mobility.cc
+
 ehlib_LTLIBRARIES += libcd_pgm.la
 libcd_pgm_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
 libcd_pgm_la_LDFLAGS = -export-dynamic -shared
 libcd_pgm_la_SOURCES = cd_gre.cc cd_pgm_module.h cd_pgm_module.cc
 
+ehlib_LTLIBRARIES += libcd_pim.la
+libcd_pim_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
+libcd_pim_la_LDFLAGS = -export-dynamic -shared
+libcd_pim_la_SOURCES = cd_pim.cc
+
+ehlib_LTLIBRARIES += libcd_sun_nd.la
+libcd_sun_nd_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
+libcd_sun_nd_la_LDFLAGS = -export-dynamic -shared
+libcd_sun_nd_la_SOURCES = cd_sun_nd.cc
+
 # TODO:  PUT THESE IN THE LIST
 #add_shared_library(cd_dstopts codecs cd_dstopts.cc)
 #add_shared_library(cd_frag codecs cd_frag.cc)
index 72c1aaeac5435507d3b38af6efd1a2808bebbce0..b3bdba9d8ba17c949502d819a90fa95f316ff205 100644 (file)
@@ -31,6 +31,7 @@
 #include "codecs/ip/cd_ah_module.h"
 #include "protocols/protocol_ids.h"
 #include "protocols/ipv6.h"
+#include "codecs/sf_protocols.h"
 
 namespace
 {
@@ -42,15 +43,10 @@ public:
     ~AhCodec(){};
 
 
+    virtual PROTO_ID get_proto_id() { return PROTO_AH; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
-
-
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_AH; };
-    
 };
 
 
index 41d124917ae6b7939f70bafa0b693ba8567d0f95..a1171cfd08a519d6a8ae05e20ec7ca354005bde4 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_AH_NAME "codec_ah"
+#define CD_AH_NAME "cd_ah"
 
 class AhModule : public DecodeModule
 {
index 1afc4d9ff5cf40873b2ca3d0b01c36a91def9997..7a8be291c0f5a07b8b9e0125c93ac41395bf9cd8 100644 (file)
@@ -37,7 +37,7 @@
 namespace
 {
 
-#define CD_DSTOPTS_NAME "codec_ipv6_dstopts"
+#define CD_DSTOPTS_NAME "cd_ipv6_dstopts"
 
 class Ipv6DSTOptsCodec : public Codec
 {
index 96a98f4bed2d99d49bc878d1655cdcde7d49a803..5b0594cbde321de51be5c7705d43daf9e957dd59 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_ESP_NAME "codec_esp"
+#define CD_ESP_NAME "cd_esp"
 
 class EspModule : public DecodeModule
 {
index 922ccfe3fcb34b0ca4b40cd4b7b6b18d54f2e9cd..ab9d3f37ab057e7b2f57d87acd2863e295af9cc9 100644 (file)
@@ -38,7 +38,7 @@
 namespace
 {
 
-#define CD_IPV6_FRAG_NAME "codec_ipv6_frag"
+#define CD_IPV6_FRAG_NAME "cd_ipv6_frag"
 
 class Ipv6FragCodec : public Codec
 {
index 1eb2a2c2d6451a143baa8415b1c2c2692bbaefc4..a7a60db39eb8f3ed90711793ee0245d7d2e0e150 100644 (file)
 // cd_gre.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "framework/codec.h"
 #include "codecs/ip/cd_gre_module.h"
 #include "codecs/codec_events.h"
 #include "protocols/packet.h"
 #include "protocols/protocol_ids.h"
+#include "codecs/sf_protocols.h"
+#include "protocols/gre.h"
 
 namespace
 {
@@ -35,19 +41,14 @@ public:
     GreCodec() : Codec(CD_GRE_NAME){};
     ~GreCodec(){};
 
-
+    virtual PROTO_ID get_proto_id() { return PROTO_GRE; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
-    virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
 
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_GRE; };
 
 };
 
-static const uint16_t GRE_PROT_ID = 47;
 static const uint32_t GRE_HEADER_LEN = 4;
 static const uint32_t GRE_CHKSUM_LEN = 2;
 static const uint32_t GRE_OFFSET_LEN = 2;
@@ -74,7 +75,7 @@ static const uint32_t GRE_V1_ACK_LEN = 4;
 
 void GreCodec::get_protocol_ids(std::vector<uint16_t>& v)
 {
-    v.push_back(GRE_PROT_ID);
+    v.push_back(IPPROTO_ID_GRE);
 }
 
 
@@ -116,32 +117,32 @@ bool GreCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
      * figure out the length
      */
 
-    p->greh = (GREHdr *)raw_pkt;
+    const gre::GREHdr *greh = reinterpret_cast<const gre::GREHdr *>(raw_pkt);
     lyr_len = GRE_HEADER_LEN;
 
-    switch (GRE_VERSION(p->greh))
+    switch (GRE_VERSION(greh))
     {
         case 0x00:
             /* these must not be set */
-            if (GRE_RECUR(p->greh) || GRE_FLAGS(p->greh))
+            if (GRE_RECUR(greh) || GRE_FLAGS(greh))
             {
                 codec_events::decoder_alert_encapsulated(p, DECODE_GRE_INVALID_HEADER,
                                 raw_pkt, len);
                 return false;
             }
 
-            if (GRE_CHKSUM(p->greh) || GRE_ROUTE(p->greh))
+            if (GRE_CHKSUM(greh) || GRE_ROUTE(greh))
                 lyr_len += GRE_CHKSUM_LEN + GRE_OFFSET_LEN;
 
-            if (GRE_KEY(p->greh))
+            if (GRE_KEY(greh))
                 lyr_len += GRE_KEY_LEN;
 
-            if (GRE_SEQ(p->greh))
+            if (GRE_SEQ(greh))
                 lyr_len += GRE_SEQ_LEN;
 
             /* if this flag is set, we need to walk through all of the
              * Source Route Entries */
-            if (GRE_ROUTE(p->greh))
+            if (GRE_ROUTE(greh))
             {
                 uint16_t sre_addrfamily;
                 uint8_t sre_offset;
@@ -177,8 +178,8 @@ bool GreCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
         /* PPTP */
         case 0x01:
             /* these flags should never be present */
-            if (GRE_CHKSUM(p->greh) || GRE_ROUTE(p->greh) || GRE_SSR(p->greh) ||
-                GRE_RECUR(p->greh) || GRE_V1_FLAGS(p->greh))
+            if (GRE_CHKSUM(greh) || GRE_ROUTE(greh) || GRE_SSR(greh) ||
+                GRE_RECUR(greh) || GRE_V1_FLAGS(greh))
             {
                 codec_events::decoder_alert_encapsulated(p, DECODE_GRE_V1_INVALID_HEADER,
                                 raw_pkt, len);
@@ -186,7 +187,7 @@ bool GreCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
             }
 
             /* protocol must be 0x880B - PPP */
-            if (GRE_PROTO(p->greh) != ETHERTYPE_PPP)
+            if (GRE_PROTO(greh) != ETHERTYPE_PPP)
             {
                 codec_events::decoder_alert_encapsulated(p, DECODE_GRE_V1_INVALID_HEADER,
                                 raw_pkt, len);
@@ -194,7 +195,7 @@ bool GreCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
             }
 
             /* this flag should always be present */
-            if (!(GRE_KEY(p->greh)))
+            if (!(GRE_KEY(greh)))
             {
                 codec_events::decoder_alert_encapsulated(p, DECODE_GRE_V1_INVALID_HEADER,
                                 raw_pkt, len);
@@ -203,10 +204,10 @@ bool GreCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
 
             lyr_len += GRE_KEY_LEN;
 
-            if (GRE_SEQ(p->greh))
+            if (GRE_SEQ(greh))
                 lyr_len += GRE_SEQ_LEN;
 
-            if (GRE_V1_ACK(p->greh))
+            if (GRE_V1_ACK(greh))
                 lyr_len += GRE_V1_ACK_LEN;
 
             break;
@@ -224,18 +225,10 @@ bool GreCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
         return false;
     }
 
-    next_prot_id = GRE_PROTO(p->greh);
+    next_prot_id = GRE_PROTO(greh);
     return true;
 }
 
-/******************************************************************
- ******************** E N C O D E R  ******************************
- ******************************************************************/
-
-void GreCodec::format (EncodeFlags, const Packet*, Packet* c, Layer* lyr)
-{
-    c->greh = (GREHdr*)lyr->start;
-}
 
 
 //-------------------------------------------------------------------------
index 626d36cce393c4b548494ce5d0c19b11ec0aa50b..2e0ce889f0ab533ae53bef270b88cdf45ab48cda 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_GRE_NAME "codec_gre"
+#define CD_GRE_NAME "cd_gre"
 
 class GreModule : public DecodeModule
 {
index 00da7c2f4d90d1da2e28838cde63d92ef1850c18..d0e566b2abe7b9a267c1236e313e97b349881e2c 100644 (file)
@@ -36,7 +36,7 @@
 namespace
 {
 
-#define CD_HOPOPTS_NAME "codec_ipv6_hopopts"
+#define CD_HOPOPTS_NAME "cd_ipv6_hopopts"
 
 class Ipv6HopOptsCodec : public Codec
 {
index 28d493afee7bc5761eac857eadc2179b0e82c103..e74b1ccac3832a981db3133af5a5a2909c9442ae 100644 (file)
@@ -38,6 +38,7 @@
 #include "codecs/checksum.h"
 #include "protocols/protocol_ids.h"
 #include "codecs/ip/cd_icmp4_module.h"
+#include "codecs/sf_protocols.h"
 
 
 namespace{
@@ -49,17 +50,13 @@ public:
     Icmp4Codec() : Codec(CD_ICMP4_NAME){};
     ~Icmp4Codec() {};
     
+    virtual PROTO_ID get_proto_id() { return PROTO_ICMP4; };
     virtual void get_protocol_ids(std::vector<uint16_t>&);
     virtual bool decode(const uint8_t* raw_packet, const uint32_t raw_len, 
         Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id);
     virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
     virtual bool update(Packet*, Layer*, uint32_t* len);
     virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
-
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_ICMP4; };
-
 private:
 
     void DecodeICMPEmbeddedIP(const uint8_t *pkt, const uint32_t len, Packet *p);
index 1f4e3bf79a89ec5a5cdaecb7fa3d9ecf67ff5be7..6eb73cd8a443652897c84f919f36c8862c8b8498 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_ICMP4_NAME "codec_icmp4"
+#define CD_ICMP4_NAME "cd_icmp4"
 
 class Icmp4Module : public DecodeModule
 {
index f8efb2528cf5c0f74b01efe9dd8f0463e566f0e8..39e8b4c06bf886561ae9b50a418d09a45d1b87f3 100644 (file)
@@ -34,6 +34,7 @@
 #include "protocols/icmp6.h"
 #include "protocols/icmp4.h"
 #include "codecs/ip/cd_icmp6_module.h"
+#include "codecs/sf_protocols.h"
 
 
 namespace
@@ -46,17 +47,13 @@ public:
     ~Icmp6Codec(){};
 
 
+    virtual PROTO_ID get_proto_id() { return PROTO_ICMP6; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
     virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
     virtual bool update(Packet*, Layer*, uint32_t* len);
     virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
-
-
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_ICMP6; };
     
 };
 
@@ -65,20 +62,14 @@ public:
 } // anonymous namespace
 
 
+static void DecodeICMPEmbeddedIP6(const uint8_t *pkt, const uint32_t len, Packet *p);
+
+
 void Icmp6Codec::get_protocol_ids(std::vector<uint16_t>& v)
 {
     v.push_back(IPPROTO_ICMPV6);
 }
 
-
-
-static void DecodeICMPEmbeddedIP6(const uint8_t *pkt, const uint32_t len, Packet *p);
-
-#if 0
-static unsigned short in_chksum_icmp6(pseudoheader6 *, unsigned short *, int);
-#endif
-
-
 //--------------------------------------------------------------------
 // decode.c::ICMP6
 //--------------------------------------------------------------------
@@ -166,7 +157,7 @@ bool Icmp6Codec::decode(const uint8_t* raw_pkt, const uint32_t len,
             }
             break;
 
-        case ICMP6_BIG:
+        case icmp6::Icmp6Types::BIG:
             if (p->dsize >= sizeof(ICMP6TooBig))
             {
                 ICMP6TooBig *too_big = (ICMP6TooBig *)raw_pkt;
@@ -203,7 +194,7 @@ bool Icmp6Codec::decode(const uint8_t* raw_pkt, const uint32_t len,
                 p->data += 4;
                 p->dsize -= 4;
 
-                if (p->icmp6h->type == ICMP6_UNREACH)
+                if (p->icmp6h->type == icmp6::Icmp6Types::UNREACH)
                 {
                     if (p->icmp6h->code == 2)
                     {
@@ -517,97 +508,6 @@ void Icmp6Codec::format (EncodeFlags, const Packet*, Packet* c, Layer* lyr)
     c->icmp6h = (ICMP6Hdr*)lyr->start;
 }
 
-#if 0
-
-/*
- * CHECKSUM
- */
-
-
-/*
-*  checksum icmp6
-*/
-
-static unsigned short in_chksum_icmp6(pseudoheader6 *ph,
-     unsigned short *w, int blen )
-{
-  uint16_t *h = (uint16_t *)ph;
-  unsigned  short answer=0;
-  unsigned int cksum = 0;
-
-  /* PseudoHeader must have 36 bytes */
-  cksum  = h[0];
-  cksum += h[1];
-  cksum += h[2];
-  cksum += h[3];
-  cksum += h[4];
-  cksum += h[5];
-  cksum += h[6];
-  cksum += h[7];
-  cksum += h[8];
-  cksum += h[9];
-  cksum += h[10];
-  cksum += h[11];
-  cksum += h[12];
-  cksum += h[13];
-  cksum += h[14];
-  cksum += h[15];
-  cksum += h[16];
-  cksum += h[17];
-
-  while(blen >=32)
-  {
-     cksum += w[0];
-     cksum += w[1];
-     cksum += w[2];
-     cksum += w[3];
-     cksum += w[4];
-     cksum += w[5];
-     cksum += w[6];
-     cksum += w[7];
-     cksum += w[8];
-     cksum += w[9];
-     cksum += w[10];
-     cksum += w[11];
-     cksum += w[12];
-     cksum += w[13];
-     cksum += w[14];
-     cksum += w[15];
-     w     += 16;
-     blen  -= 32;
-  }
-
-  while(blen >=8)
-  {
-     cksum += w[0];
-     cksum += w[1];
-     cksum += w[2];
-     cksum += w[3];
-     w     += 4;
-     blen  -= 8;
-  }
-
-  while(blen > 1)
-  {
-     cksum += *w++;
-     blen  -= 2;
-  }
-
-  if( blen == 1 )
-  {
-    *(unsigned char*)(&answer) = (*(unsigned char*)w);
-    cksum += answer;
-  }
-
-  cksum  = (cksum >> 16) + (cksum & 0x0000ffff);
-  cksum += (cksum >> 16);
-
-
-  return (unsigned short)(~cksum);
-}
-#endif
-
-
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
index 42794601c987c8c9f2fd547b502b51c423359d2a..d514765afce4ac18edf6d92c16fc821e54e974fe 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_ICMP6_NAME "codec_icmp6"
+#define CD_ICMP6_NAME "cd_icmp6"
 
 class Icmp6Module : public DecodeModule
 {
index 3c2eefce4d4d7dbedf4a586146109648eaf6457a..b4902b7e58df9e733c07d37b65100eebab3b0550 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_IGMP_NAME "codec_igmp"
+#define CD_IGMP_NAME "cd_igmp"
 
 class IgmpModule : public DecodeModule
 {
index 9088836bbc8bc0c717e249998430f0f3c54ca86e..f935ed9a64dbbe004c41b3262c5af65a45f713bc 100644 (file)
@@ -47,6 +47,7 @@
 #include "main/thread.h"
 #include "stream/stream_api.h"
 #include "codecs/ip/cd_ipv4_module.h"
+#include "codecs/sf_protocols.h"
 
 namespace{
 
@@ -56,6 +57,7 @@ public:
     Ipv4Codec() : Codec(CD_IPV4_NAME){};
     ~Ipv4Codec(){};
 
+    virtual PROTO_ID get_proto_id() { return PROTO_IP4; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
@@ -63,15 +65,11 @@ public:
     virtual bool update(Packet*, Layer*, uint32_t* len);
     virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
 
-    // used in random classes throughout Snort++
-
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_IP4; };
 
 private:
-
-
+    static uint8_t RevTTL (const EncState* enc, uint8_t ttl);
+    static uint8_t FwdTTL (const EncState* enc, uint8_t ttl);
+    static uint8_t GetTTL (const EncState* enc);
     
 };
 
@@ -96,7 +94,7 @@ static void DecodeIPOptions(const uint8_t *start, uint32_t o_len, Packet *p);
  ************  PRIVATE FUNCTIONS ***********
  *******************************************/
 
-static inline uint8_t GetTTL (const EncState* enc)
+uint8_t Ipv4Codec::GetTTL (const EncState* enc)
 {
     char dir;
     uint8_t ttl;
@@ -121,7 +119,7 @@ static inline uint8_t GetTTL (const EncState* enc)
     return ttl;
 }
 
-static inline uint8_t FwdTTL (const EncState* enc, uint8_t ttl)
+uint8_t Ipv4Codec::FwdTTL (const EncState* enc, uint8_t ttl)
 {
     uint8_t new_ttl = GetTTL(enc);
     if ( !new_ttl )
@@ -129,7 +127,7 @@ static inline uint8_t FwdTTL (const EncState* enc, uint8_t ttl)
     return new_ttl;
 }
 
-static inline uint8_t RevTTL (const EncState* enc, uint8_t ttl)
+uint8_t Ipv4Codec::RevTTL (const EncState* enc, uint8_t ttl)
 {
     uint8_t new_ttl = GetTTL(enc);
     if ( !new_ttl )
@@ -380,7 +378,7 @@ bool Ipv4Codec::decode(const uint8_t *raw_pkt, const uint32_t len,
     p->ip_dsize = (u_short) ip_len;
 
     /* See if there are any ip_proto only rules that match */
-    fpEvalIpProtoOnlyRules(snort_conf->ip_proto_only_lists, p);
+    fpEvalIpProtoOnlyRules(snort_conf->ip_proto_only_lists, p, p->iph->ip_proto);
 
     p->proto_bits |= PROTO_BIT__IP;
 
@@ -398,8 +396,8 @@ bool Ipv4Codec::decode(const uint8_t *raw_pkt, const uint32_t len,
 
         if (GET_IPH_PROTO(p) >= MIN_UNASSIGNED_IP_PROTO)
             codec_events::decoder_event(p, DECODE_IP_UNASSIGNED_PROTO);
-
-        next_prot_id = p->iph->ip_proto;
+        else
+            next_prot_id = p->iph->ip_proto;
     }
     else
     {
@@ -411,44 +409,6 @@ bool Ipv4Codec::decode(const uint8_t *raw_pkt, const uint32_t len,
     return true;
 }
 
-
-/* Function: DecodeIPv4Proto
- *
- * Gernalized IPv4 next protocol decoder dispatching.
- *
- * Arguments: proto => IPPROTO value of the next protocol
- *            pkt => ptr to the packet data
- *            len => length from here to the end of the packet
- *            p   => pointer to the packet decode struct
- *
- */
-inline void DecodeIPv4Proto(const uint8_t proto,
-    const uint8_t *pkt, const uint32_t len, Packet *p)
-{
-    switch(proto)
-    {
-
-
-        case IPPROTO_IP_MOBILITY:
-        case IPPROTO_SUN_ND:
-        case IPPROTO_PIM:
-            codec_events::decoder_event(p, DECODE_IP_BAD_PROTO);
-            p->data = pkt;
-            p->dsize = (uint16_t)len;
-            return;
-
-
-        default:
-            if (GET_IPH_PROTO(p) >= MIN_UNASSIGNED_IP_PROTO)
-                codec_events::decoder_event(p, DECODE_IP_UNASSIGNED_PROTO);
-
-            p->data = pkt;
-            p->dsize = (uint16_t)len;
-            return;
-    }
-}
-
-
 //------------------------------------------------------------------
 // decode.c::IP4 misc
 //--------------------------------------------------------------------
@@ -776,7 +736,6 @@ void Ipv4Codec::format(EncodeFlags f, const Packet* p, Packet* c, Layer* lyr)
     sfiph_build(c, c->iph, AF_INET);
 }
 
-
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
index 3d1608678eaafbce61f88ded04506c544297525c..861795aa1bedab5003a50b4abcda346da5b66d58 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_IPV4_NAME "codec_ipv4"
+#define CD_IPV4_NAME "cd_ipv4"
 
 class Ipv4Module : public DecodeModule
 {
index 2e192693ce9d63dfa8c4006050cd307a1446cdf8..c1c9eff246ad1e46375a3e610604030b9d061b15 100644 (file)
@@ -35,6 +35,7 @@
 #include "main/snort.h"
 #include "packet_io/active.h"
 #include "codecs/ip/cd_ipv6_module.h"
+#include "codecs/sf_protocols.h"
 
 namespace
 {
@@ -45,6 +46,7 @@ public:
     Ipv6Codec() : Codec(CD_IPV6_NAME){};
     ~Ipv6Codec(){};
 
+    virtual PROTO_ID get_proto_id() { return PROTO_IP6; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
@@ -52,10 +54,11 @@ public:
     virtual bool update(Packet*, Layer*, uint32_t* len);
     virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
 
+private:
 
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_IP6; };
+    static uint8_t RevTTL (const EncState* enc, uint8_t ttl);
+    static uint8_t FwdTTL (const EncState* enc, uint8_t ttl);
+    static uint8_t GetTTL (const EncState* enc);
 
 };
 
@@ -70,7 +73,7 @@ static inline int CheckTeredoPrefix(ipv6::IP6RawHdr *hdr);
  *************************   PRIVATE FUNCTIONS **********************
  ********************************************************************/
 
-static inline uint8_t GetTTL (const EncState* enc)
+uint8_t Ipv6Codec::GetTTL (const EncState* enc)
 {
     char dir;
     uint8_t ttl;
@@ -95,7 +98,7 @@ static inline uint8_t GetTTL (const EncState* enc)
     return ttl;
 }
 
-static inline uint8_t FwdTTL (const EncState* enc, uint8_t ttl)
+uint8_t Ipv6Codec::FwdTTL (const EncState* enc, uint8_t ttl)
 {
     uint8_t new_ttl = GetTTL(enc);
     if ( !new_ttl )
@@ -103,7 +106,7 @@ static inline uint8_t FwdTTL (const EncState* enc, uint8_t ttl)
     return new_ttl;
 }
 
-static inline uint8_t RevTTL (const EncState* enc, uint8_t ttl)
+uint8_t Ipv6Codec::RevTTL (const EncState* enc, uint8_t ttl)
 {
     uint8_t new_ttl = GetTTL(enc);
     if ( !new_ttl )
@@ -234,8 +237,6 @@ bool Ipv6Codec::decode(const uint8_t *raw_pkt, const uint32_t len,
 
     next_prot_id = GET_IPH_PROTO(p);
     lyr_len = ipv6::hdr_len();
-
-//    DecodeIPV6Extensions(GET_IPH_PROTO(p), raw_pkt + ipv6::hdr_len(), ntohs(p->ip6h->len), p);
     return true;
 
 
index 95c46043ccf7e2d0148eec5e557497733b750e26..ef23eaf088dbfcb88a6a0836e184b08c582012ba 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_IPV6_NAME "codec_ipv6"
+#define CD_IPV6_NAME "cd_ipv6"
 
 class Ipv6Module : public DecodeModule
 {
diff --git a/src/codecs/ip/cd_mobility.cc b/src/codecs/ip/cd_mobility.cc
new file mode 100644 (file)
index 0000000..bf2a844
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+** Copyright (C) 2002-2013 Sourcefire, Inc.
+** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "framework/codec.h"
+#include "codecs/codec_events.h"
+
+
+namespace
+{
+
+// yes, macros are necessary. The API and class constructor require different strings.
+#define CD_MOBILE_NAME "cd_mobility"
+
+class MobilityCodec : public Codec
+{
+public:
+    MobilityCodec() : Codec(CD_MOBILE_NAME){};
+    ~MobilityCodec() {};
+
+
+    virtual void get_protocol_ids(std::vector<uint16_t>&);
+    virtual bool decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+
+};
+
+const uint16_t IPPROTO_ID_MOBILITY = 55;
+
+} // namespace
+
+
+void MobilityCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(IPPROTO_ID_MOBILITY);
+}
+
+bool MobilityCodec::decode(const uint8_t* raw_pkt, const uint32_t raw_len, 
+        Packet* p, uint16_t& /*lyr_len*/, uint16_t& /*next_prot_id*/)
+{
+    codec_events::decoder_event(p, DECODE_IP_BAD_PROTO);
+    p->data = raw_pkt;
+    p->dsize = (uint16_t)raw_len;
+    return true;
+}
+
+
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
+
+static Codec* ctor(Module*)
+{
+    return new MobilityCodec();
+}
+
+static void dtor(Codec *cd)
+{
+    delete cd;
+}
+
+
+static const CodecApi mobility_api =
+{
+    {
+        PT_CODEC,
+        CD_MOBILE_NAME,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr
+    },
+    nullptr,
+    nullptr,
+    nullptr,
+    nullptr,
+    ctor,
+    dtor,
+};
+
+
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+{
+    &mobility_api.base,
+    nullptr
+};
+#else
+const BaseApi* cd_mobility = &mobility_api.base;
+#endif
index 86c35013f2739e5cfa938be6d8d5a04bb026ff7d..8fd9a9cf26f53817f542deea6244c3508873d398 100644 (file)
@@ -37,7 +37,7 @@
 namespace
 {
 
-#define CD_NO_NEXT_NAME "codec_ipv6_no_next"
+#define CD_NO_NEXT_NAME "cd_ipv6_no_next"
 
 class Ipv6NoNextCodec : public Codec
 {
index 09613e7cd078a703cfd136ed649b802a8d0e3ea9..8795c2d153a0dfe196428c230bb072d83f02a144 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_PGM_NAME "codec_pgm"
+#define CD_PGM_NAME "cd_pgm"
 
 class PgmModule : public DecodeModule
 {
diff --git a/src/codecs/ip/cd_pim.cc b/src/codecs/ip/cd_pim.cc
new file mode 100644 (file)
index 0000000..334f84c
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+** Copyright (C) 2002-2013 Sourcefire, Inc.
+** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "framework/codec.h"
+#include "codecs/codec_events.h"
+
+
+namespace
+{
+
+// yes, macros are necessary. The API and class constructor require different strings.
+#define CD_PIM_NAME "cd_pim"
+
+class PimCodec : public Codec
+{
+public:
+    PimCodec() : Codec(CD_PIM_NAME){};
+    ~PimCodec() {};
+
+
+    virtual void get_protocol_ids(std::vector<uint16_t>&);
+    virtual bool decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+
+};
+
+const uint16_t IPPROTO_ID_PIM = 103;
+
+} // namespace
+
+
+void PimCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(IPPROTO_ID_PIM);
+}
+
+bool PimCodec::decode(const uint8_t* raw_pkt, const uint32_t raw_len, 
+        Packet* p, uint16_t& /*lyr_len*/, uint16_t& /*next_prot_id*/)
+{
+    codec_events::decoder_event(p, DECODE_IP_BAD_PROTO);
+    p->data = raw_pkt;
+    p->dsize = (uint16_t)raw_len;
+    return true;
+}
+
+
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
+
+static Codec* ctor(Module*)
+{
+    return new PimCodec();
+}
+
+static void dtor(Codec *cd)
+{
+    delete cd;
+}
+
+
+static const CodecApi pim_api =
+{
+    {
+        PT_CODEC,
+        CD_PIM_NAME,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr
+    },
+    nullptr,
+    nullptr,
+    nullptr,
+    nullptr,
+    ctor,
+    dtor,
+};
+
+
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+{
+    &pim_api.base,
+    nullptr
+};
+#else
+const BaseApi* cd_pim = &pim_api.base;
+#endif
index a1d54f4c1a8ab7d7238e7f9ec8a33aef8ed2cd32..e87d3d8ae16b15c873be7ccc7525b7f584e76ae0 100644 (file)
@@ -37,7 +37,7 @@
 namespace
 {
 
-#define CD_IPV6_ROUTING_NAME "codec_ipv6_routing"
+#define CD_IPV6_ROUTING_NAME "cd_ipv6_routing"
 
 class Ipv6RoutingCodec : public Codec
 {
diff --git a/src/codecs/ip/cd_sun_nd.cc b/src/codecs/ip/cd_sun_nd.cc
new file mode 100644 (file)
index 0000000..1e95706
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+** Copyright (C) 2002-2013 Sourcefire, Inc.
+** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "framework/codec.h"
+#include "codecs/codec_events.h"
+
+
+namespace
+{
+
+// yes, macros are necessary. The API and class constructor require different strings.
+#define CD_SUN_ND_NAME "cd_sun_nd"
+
+class SunNdCodec : public Codec
+{
+public:
+    SunNdCodec() : Codec(CD_SUN_ND_NAME){};
+    ~SunNdCodec() {};
+
+
+    virtual void get_protocol_ids(std::vector<uint16_t>&);
+    virtual bool decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+
+};
+
+const uint16_t IPPROTO_ID_SUN_ND = 77;
+
+} // namespace
+
+
+void SunNdCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(IPPROTO_ID_SUN_ND);
+}
+
+bool SunNdCodec::decode(const uint8_t* raw_pkt, const uint32_t raw_len, 
+        Packet* p, uint16_t& /*lyr_len*/, uint16_t& /*next_prot_id*/)
+{
+    codec_events::decoder_event(p, DECODE_IP_BAD_PROTO);
+    p->data = raw_pkt;
+    p->dsize = (uint16_t)raw_len;
+    return true;
+}
+
+
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
+
+static Codec* ctor(Module*)
+{
+    return new SunNdCodec();
+}
+
+static void dtor(Codec *cd)
+{
+    delete cd;
+}
+
+
+static const CodecApi sun_nd_api =
+{
+    {
+        PT_CODEC,
+        CD_SUN_ND_NAME,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr
+    },
+    nullptr,
+    nullptr,
+    nullptr,
+    nullptr,
+    ctor,
+    dtor,
+};
+
+
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+{
+    &sun_nd_api.base,
+    nullptr
+};
+#else
+const BaseApi* cd_sun_nd = &sun_nd_api.base;
+#endif
index 12cce3415fa196c65d9c09470b54a11b628a0bc7..4f0961446bf41cb96f7ca4fef8aecf03cf8f6685 100644 (file)
@@ -30,7 +30,7 @@
 
 namespace{
 
-#define CD_SWIPE_NAME "codec_swipe"
+#define CD_SWIPE_NAME "cd_swipe"
 
 
 class SwipeCodec : public Codec
index b12a1b1a5c2ba6aa8e6261cdd532af07cf664d55..c2fd3dea4b6e777a697439b58307f0b98b1799cb 100644 (file)
@@ -45,6 +45,7 @@
 #include "protocols/packet.h"
 #include "framework/codec.h"
 #include "codecs/ip/cd_tcp_module.h"
+#include "codecs/sf_protocols.h"
 
 namespace
 {
@@ -59,17 +60,13 @@ public:
     virtual ~TcpCodec(){};
 
 
+    virtual PROTO_ID get_proto_id() { return PROTO_TCP; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &);
     virtual bool encode(EncState*, Buffer* out, const uint8_t *raw_in);
     virtual bool update(Packet*, Layer*, uint32_t* len);
     virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
-
-
-    // DELETE
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_TCP; };
 };
 
 static sfip_var_t *SynToMulticastDstIp = NULL;
@@ -179,18 +176,6 @@ bool TcpCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
             /* calculate the checksum */
             csum = checksum::tcp_cksum((uint16_t *)(p->tcph), len, &ph);
 
-#if 0
-            csum = in_chksum_tcp(&ph, (uint16_t *)(p->tcph), len);
-            uint16_t csum2 = PacketClass::tcp_cksum((uint16_t *)(p->tcph), len, &ph);
-
-            if(csum != csum2)
-            {
-                DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "TCP_CHECKSUM_ERROR!!! -> the two checksum are not equal %hu != %hu\n",
-                                        csum, csum2););
-                uint16_t csum3 = PacketClass::tcp_cksum((uint16_t *)(p->tcph), len, &ph);
-            }
-#endif
-
         }
         /* IPv6 traffic */
         else
@@ -204,20 +189,6 @@ bool TcpCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
 
 
             csum = checksum::tcp_cksum((uint16_t *)(p->tcph), len, &ph6);
-        // TODO::DELETE
-        #if 0
-            csum = in_chksum_tcp6(&ph6, (uint16_t *)(p->tcph), len);
-            uint16_t csum2 = PacketClass::tcp_cksum((uint16_t *)(p->tcph), len, &ph6);
-                DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "HELLO!! -> the two checksum are not equal %hu != %hu\n",
-                                        csum, csum2););
-
-            if(csum != csum2)
-            {
-                DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "TCP_CHECKSUM_ERROR!!! -> the two checksum are not equal %hu != %hu\n",
-                                        csum, csum2););
-                uint16_t csum3 = PacketClass::tcp_cksum((uint16_t *)(p->tcph), len, &ph6);
-            }
-            #endif
         }
 
         if(csum)
index 904cacff96da3cab1433599b0139962c7353735f..49b9b83a63fe99efce84049e5ed1108c369a8ae2 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_TCP_NAME "codec_tcp"
+#define CD_TCP_NAME "cd_tcp"
 
 class TcpModule : public DecodeModule
 {
index 9681fae4081c7bc5d8d51f7f4ce56b4b58cdf3e7..a2f18695ba9a71c7c88bca5532241d7df4bce167 100644 (file)
@@ -45,6 +45,7 @@
 #include "packet_io/active.h"
 #include "codecs/codec_events.h"
 #include "codecs/ip/cd_udp_module.h"
+#include "codecs/sf_protocols.h"
 
 namespace
 {
@@ -56,6 +57,7 @@ public:
     ~UdpCodec(){};
 
 
+    virtual PROTO_ID get_proto_id() { return PROTO_UDP; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
@@ -63,11 +65,6 @@ public:
     virtual bool encode(EncState*, Buffer* out, const uint8_t *raw_in);
     virtual bool update(Packet*, Layer*, uint32_t* len);
     virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
-
-    // DELETE
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_UDP; };
-
     
 };
 
@@ -110,7 +107,7 @@ bool UdpCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
     }
 
     /* set the ptr to the start of the UDP header */
-    p->inner_udph = p->udph = reinterpret_cast<const udp::UDPHdr*>(raw_pkt);
+    p->udph = reinterpret_cast<const udp::UDPHdr*>(raw_pkt);
 
     if (!p->frag_flag)
     {
index 8ccb2d6f00a7c732ba5bc4220f018ba842981269..7b111754519b89a2c2868c3d58643d37da2711ff 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_UDP_NAME "codec_udp"
+#define CD_UDP_NAME "cd_udp"
 
 class UdpModule : public DecodeModule
 {
index c91f051b5c5ee96929cf3e3c85ac6dd64723ba52..8b39e9d104869814b75446d2ad4a5e2269bd1e98 100644 (file)
@@ -23,7 +23,7 @@ if( STATIC_DECODERS )
         cd_vlan_module.cc
     )
 
-    if(ENABLE_NON_ETHER_DECODER)
+    if(ENABLE_NON_ETHER_DECODERS)
         set( PLUGIN_SOURCES
             ${PLUGIN_SOURCES}
             cd_eapol.cc
index d256f0b6ea0dddddf4d571d00085f8e748a029d5..03eea82a86a1d6776d43aaf1c684ba7c545d96aa 100644 (file)
@@ -27,6 +27,9 @@
 #include "framework/codec.h"
 #include "codecs/link/cd_arp_module.h"
 #include "codecs/codec_events.h"
+#include "protocols/protocol_ids.h"
+#include "codecs/sf_protocols.h"
+#include "protocols/arp.h"
 
 namespace
 {
@@ -38,27 +41,22 @@ public:
     ~ArpCodec(){};
 
 
+    virtual PROTO_ID get_proto_id() { return PROTO_ARP; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &);
     
-
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_ARP; };
 };
 
 
-static const uint16_t ETHERNET_TYPE_REVARP = 0x8035;
-static const uint16_t ETHERNET_TYPE_ARP = 0x0806;
 } // anonymous namespace
 
 
 
 void ArpCodec::get_protocol_ids(std::vector<uint16_t>& v)
 {
-    v.push_back(ETHERNET_TYPE_ARP);
-    v.push_back(ETHERNET_TYPE_REVARP);
+    v.push_back(ETHERTYPE_ARP);
+    v.push_back(ETHERTYPE_REVARP);
 }
 
 
@@ -77,11 +75,9 @@ void ArpCodec::get_protocol_ids(std::vector<uint16_t>& v)
  *
  * Returns: void function
  */
-bool ArpCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
+bool ArpCodec::decode(const uint8_t* /*raw_pkt*/, const uint32_t len,
         Packet *p, uint16_t &lyr_len, uint16_t& /* next_prot_id */)
 {
-    p->ah = (EtherARP *) raw_pkt;
-
     if(len < sizeof(EtherARP))
     {
         codec_events::decoder_event(p, DECODE_ARP_TRUNCATED);
@@ -89,7 +85,7 @@ bool ArpCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
     }
 
     p->proto_bits |= PROTO_BIT__ARP;
-    lyr_len = sizeof(*p->ah);
+    lyr_len = sizeof(EtherARP);
     
     return true;
 }
index e73ed775709a5cf9528258cfa008698132e6840c..4f1098d20a6c50f2f9d56f9570f7eb67a3cf43ac 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_ARP_NAME "codec_arp"
+#define CD_ARP_NAME "cd_arp"
 
 class ArpModule : public DecodeModule
 {
index 5a199b92ac5a4fc661bd2ec1bbdc3e9a6dca02bd..b78d201fbcb71e19f776690c96e3bf6b9d0f79ad 100644 (file)
@@ -27,6 +27,8 @@
 #include "framework/codec.h"
 #include "codecs/link/cd_eapol_module.h"
 #include "codecs/codec_events.h"
+#include "protocols/protocol_ids.h"
+#include "protocols/eapol.h"
 
 
 namespace
@@ -46,79 +48,6 @@ public:
     
 };
 
-static const uint16_t ETHERTYPE_EAPOL = 0x888e;
-
-
-#ifndef NO_NON_ETHER_DECODER
-
-/* IEEE 802.1x eapol types */
-#define EAPOL_TYPE_EAP      0x00      /* EAP packet */
-#define EAPOL_TYPE_START    0x01      /* EAPOL start */
-#define EAPOL_TYPE_LOGOFF   0x02      /* EAPOL Logoff */
-#define EAPOL_TYPE_KEY      0x03      /* EAPOL Key */
-#define EAPOL_TYPE_ASF      0x04      /* EAPOL Encapsulated ASF-Alert */
-
-
-#endif // NO_NON_ETHER_DECODER
-
-
-/* Extensible Authentication Protocol Codes RFC 2284*/
-#define EAP_CODE_REQUEST    0x01
-#define EAP_CODE_RESPONSE   0x02
-#define EAP_CODE_SUCCESS    0x03
-#define EAP_CODE_FAILURE    0x04
-/* EAP Types */
-#define EAP_TYPE_IDENTITY   0x01
-#define EAP_TYPE_NOTIFY     0x02
-#define EAP_TYPE_NAK        0x03
-#define EAP_TYPE_MD5        0x04
-#define EAP_TYPE_OTP        0x05
-#define EAP_TYPE_GTC        0x06
-#define EAP_TYPE_TLS        0x0d
-
-
-
-/* Extensible Authentication Protocol Codes RFC 2284*/
-#define EAP_CODE_REQUEST    0x01
-#define EAP_CODE_RESPONSE   0x02
-#define EAP_CODE_SUCCESS    0x03
-#define EAP_CODE_FAILURE    0x04
-/* EAP Types */
-#define EAP_TYPE_IDENTITY   0x01
-#define EAP_TYPE_NOTIFY     0x02
-#define EAP_TYPE_NAK        0x03
-#define EAP_TYPE_MD5        0x04
-#define EAP_TYPE_OTP        0x05
-#define EAP_TYPE_GTC        0x06
-#define EAP_TYPE_TLS        0x0d
-
-
-
-struct EtherEapol
-{
-    uint8_t  version;  /* EAPOL proto version */
-    uint8_t  eaptype;  /* EAPOL Packet type */
-    uint16_t len;  /* Packet body length */
-};
-
-struct EAPHdr
-{
-    uint8_t code;
-    uint8_t id;
-    uint16_t len;
-};
-
-struct EapolKey
-{
-  uint8_t type;
-  uint8_t length[2];
-  uint8_t counter[8];
-  uint8_t iv[16];
-  uint8_t index;
-  uint8_t sig[16];
-};
-
-
 } // namespace
 
 /*************************************************
@@ -138,16 +67,15 @@ struct EapolKey
  */
 void DecodeEAP(const uint8_t * pkt, const uint32_t len, Packet * p)
 {
-    const EAPHdr *eaph = reinterpret_cast<const EAPHdr* pkt>(pkt);
-    p->eaph = (EAPHdr *) pkt;
-    if(len < sizeof(EAPHdr))
+    const eapol::EAPHdr *eaph = reinterpret_cast<const eapol::EAPHdr*>(pkt);
+
+    if(len < sizeof(eapol::EAPHdr))
     {
         codec_events::decoder_event(p, DECODE_EAP_TRUNCATED);
         return;
     }
     if (eaph->code == EAP_CODE_REQUEST ||
             eaph->code == EAP_CODE_RESPONSE) {
-        p->eaptype = pkt + sizeof(EAPHdr);
     }
     return;
 }
@@ -164,10 +92,9 @@ void DecodeEAP(const uint8_t * pkt, const uint32_t len, Packet * p)
  *
  * Returns: void function
  */
-void DecodeEapolKey(const uint8_t * pkt, uint32_t len, Packet * p)
+void DecodeEapolKey(const uint8_t* /*pkt*/, uint32_t len, Packet * p)
 {
-    p->eapolk = (EapolKey *) pkt;
-    if(len < sizeof(EapolKey))
+    if(len < sizeof(eapol::EapolKey))
     {
         codec_events::decoder_event(p, DECODE_EAPKEY_TRUNCATED);
     }
@@ -183,19 +110,19 @@ void DecodeEapolKey(const uint8_t * pkt, uint32_t len, Packet * p)
 bool EapolCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *p, uint16_t & /*lyr_len*/, uint16_t &/*next_prot_id */)
 {
-    p->eplh = (EtherEapol *) raw_pkt;
+    const eapol::EtherEapol* eplh = reinterpret_cast<const eapol::EtherEapol*>(raw_pkt);
 
-    if(len < sizeof(EtherEapol))
+    if(len < sizeof(eapol::EtherEapol))
     {
         codec_events::decoder_event(p, DECODE_EAPOL_TRUNCATED);
         return false;
     }
 
-    if (p->eplh->eaptype == EAPOL_TYPE_EAP) {
-        DecodeEAP(raw_pkt + sizeof(EtherEapol), len - sizeof(EtherEapol), p);
+    if (eplh->eaptype == EAPOL_TYPE_EAP) {
+        DecodeEAP(raw_pkt + sizeof(eapol::EtherEapol), len - sizeof(eapol::EtherEapol), p);
     }
-    else if(p->eplh->eaptype == EAPOL_TYPE_KEY) {
-        DecodeEapolKey(raw_pkt + sizeof(EtherEapol), len - sizeof(EtherEapol), p);
+    else if(eplh->eaptype == EAPOL_TYPE_KEY) {
+        DecodeEapolKey(raw_pkt + sizeof(eapol::EtherEapol), len - sizeof(eapol::EtherEapol), p);
     }
 
     return true;
@@ -238,7 +165,7 @@ static const CodecApi eapol_api =
 {
     {
         PT_CODEC,
-        CD_NAME_EAPOL,
+        CD_EAPOL_NAME,
         CDAPI_PLUGIN_V0,
         0,
         mod_ctor,
index 1d419f89555f31b5868a98a6ac88d631d28f2a89..cbbbc5acbfbd90196c181b8f77b96ce623cc927e 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_EAPOL_NAME "codec_eapol"
+#define CD_EAPOL_NAME "cd_eapol"
 
 class EapolModule : public DecodeModule
 {
index a257d5a52679928a629a217166b56fe2edd40e22..85fffbe9bf7a9beb4b0a77725ea32a1c06cada0f 100644 (file)
@@ -24,6 +24,7 @@
 #include "codecs/link/cd_erspan2_module.h"
 #include "codecs/codec_events.h"
 #include "protocols/protocol_ids.h"
+#include "codecs/sf_protocols.h"
 
 namespace
 {
@@ -34,13 +35,11 @@ public:
     Erspan2Codec() : Codec(CD_ERSPAN2_NAME){};
     ~Erspan2Codec(){};
 
+    virtual PROTO_ID get_proto_id() { return PROTO_ERSPAN; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
     
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_ERSPAN; };
 };
 
 
@@ -54,6 +53,12 @@ struct ERSpanType2Hdr
 const uint16_t ETHERTYPE_ERSPAN_TYPE2 = 0x88be;
 } // namespace
 
+
+static inline uint16_t erspan_version(ERSpanType2Hdr *hdr)
+{
+    return (ntohs(hdr->ver_vlan) & 0xf000) >> 12;
+}
+
 void Erspan2Codec::get_protocol_ids(std::vector<uint16_t>& v)
 {
     v.push_back(ETHERTYPE_ERSPAN_TYPE2);
@@ -96,7 +101,7 @@ bool Erspan2Codec::decode(const uint8_t *raw_pkt, const uint32_t len,
 
     /* Check that this is in fact ERSpan Type 2.
      */
-    if (ERSPAN_VERSION(erSpan2Hdr) != 0x01) /* Type 2 == version 0x01 */
+    if (erspan_version(erSpan2Hdr) != 0x01) /* Type 2 == version 0x01 */
     {
         codec_events::decoder_alert_encapsulated(p, DECODE_ERSPAN_HDR_VERSION_MISMATCH,
                         raw_pkt, len);
index 2ff2f64548a26bfce8b5424951fa209680ea2d42..ec4acf4bd387f3c8246c3581577c85e1ae39fbf2 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_ERSPAN2_NAME "codec_erspan2"
+#define CD_ERSPAN2_NAME "cd_erspan2"
 
 class Erspan2Module : public DecodeModule
 {
index 8392930742761b04a7445269cf7f52c15fe5599a..63dc7224e6154152f0df5819eb66fd4b8890b375 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/link/cd_erspan3_module.h"
 #include "codecs/codec_events.h"
 #include "protocols/protocol_ids.h"
-
+#include "codecs/sf_protocols.h"
 
 namespace
 {
@@ -41,9 +41,7 @@ public:
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
     
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_ERSPAN; };
+    virtual PROTO_ID get_proto_id() { return PROTO_ERSPAN; };
 };
 
 
@@ -61,6 +59,29 @@ struct ERSpanType3Hdr
 const uint16_t ETHERTYPE_ERSPAN_TYPE3 = 0x22eb;
 } // anonymous namespace
 
+static inline uint16_t erspan_version(ERSpanType3Hdr *hdr)
+{
+    return (ntohs(hdr->ver_vlan) & 0xf000) >> 12;
+}
+
+#if 0
+// keeping these functions around for use in further development
+
+static inline uint16_t erspan_vlan(ERSpanType3Hdr *hdr)
+{
+    return ntohs(hdr->ver_vlan) & 0x0fff;
+}
+
+static inline uint16_t erspan_span_id(ERSpanType3Hdr *hdr)
+{
+    return ntohs(hdr->flags_spanId) & 0x03ff;
+}
+
+static inline uint32_t erspan3_timestamp(ERSpanType3Hdr *hdr)
+{
+    return hdr->timestamp;
+}
+#endif
 
 void Erspan3Codec::get_protocol_ids(std::vector<uint16_t>& v)
 {
@@ -105,7 +126,7 @@ bool Erspan3Codec::decode(const uint8_t *raw_pkt, const uint32_t len,
 
     /* Check that this is in fact ERSpan Type 3.
      */
-    if (ERSPAN_VERSION(erSpan3Hdr) != 0x02) /* Type 3 == version 0x02 */
+    if (erspan_version(erSpan3Hdr) != 0x02) /* Type 3 == version 0x02 */
     {
         codec_events::decoder_alert_encapsulated(p, DECODE_ERSPAN_HDR_VERSION_MISMATCH,
                         raw_pkt, len);
index 51f8c8f381acb36702ee51de8ccb900a6f32cf06..f578b9f571a917148d968b2dd457138fbf80a9e6 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_ERSPAN3_NAME "codec_erspan3"
+#define CD_ERSPAN3_NAME "cd_erspan3"
 
 class Erspan3Module : public DecodeModule
 {
index 9a98a7bc1a5261b7091ab75f5c627cc15d5576f0..82a2bfe9d7bf3e522d3433abaf40c2e5fe6c9eb2 100644 (file)
@@ -27,7 +27,7 @@
 namespace
 {
 
-#define CD_ETHLOOPBACK_NAME "codec_ethloopback"
+#define CD_ETHLOOPBACK_NAME "cd_ethloopback"
 
 
 class EthLoopbackCodec : public Codec
index 00d14e450c020dcba716d237d5978d526ffd578d..4224d43e3557e056d2f2a2124127ac038f6bd9f6 100644 (file)
@@ -32,6 +32,7 @@
 #include "protocols/protocol_ids.h"
 #include "protocols/mpls.h"
 #include "codecs/link/cd_mpls_module.h"
+#include "codecs/sf_protocols.h"
 
 namespace
 {
@@ -42,13 +43,11 @@ public:
     MplsCodec() : Codec(CD_MPLS_NAME){};
     ~MplsCodec(){};
 
+    virtual PROTO_ID get_proto_id() { return PROTO_MPLS; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);    
 
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_MPLS; };
 };
 
 
@@ -72,7 +71,7 @@ void MplsCodec::get_protocol_ids(std::vector<uint16_t>& v)
 bool MplsCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
 {
-    uint32_t* tmpMplsHdr;
+    const uint32_t* tmpMplsHdr;
     uint32_t mpls_h;
     uint32_t label;
     lyr_len= 0;
@@ -86,8 +85,7 @@ bool MplsCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
     int iRet = 0;
 
     UpdateMPLSStats(&sfBase, len, Active_PacketWasDropped());
-    tmpMplsHdr = (uint32_t *) raw_pkt;
-    p->mpls = NULL;
+    tmpMplsHdr = (const uint32_t *) raw_pkt;
 
     while (!bos)
     {
@@ -119,7 +117,7 @@ bool MplsCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
             /**
             p->mpls = &(p->mplsHdr);
       **/
-            p->mpls = tmpMplsHdr;
+            p->proto_bits |= PROTO_BIT__MPLS;
             if(!iRet)
             {
                 iRet = ScMplsPayloadType();
@@ -132,6 +130,7 @@ bool MplsCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
         {
             codec_events::decoder_event(p, DECODE_MPLS_LABEL_STACK);
 
+            p->proto_bits &= ~PROTO_BIT__MPLS;
             p->iph = NULL;
             p->family = NO_IP;
             return false;
index cf46002aaee97142fe79284974939c7892318c03..e2eee6f712d2cfac9ff9c96bdbb2d780bb848ef9 100644 (file)
@@ -57,7 +57,7 @@ static const RuleMap mpls_rules[] =
 };
 
 //-------------------------------------------------------------------------
-// rpc module
+// mpls module
 //-------------------------------------------------------------------------
 
 MplsModule::MplsModule() : DecodeModule(CD_MPLS_NAME, mpls_params, mpls_rules)
@@ -87,4 +87,3 @@ bool MplsModule::set(const char*, Value& v, SnortConfig* sc)
     return true;
 }
 
-
index cc64c6bf774a28c2250c4ac30d94ba24bf434c40..8ec811b7ef90ca59e46f01bffa5ceddc8aa9f9c1 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_MPLS_NAME "codec_mpls"
+#define CD_MPLS_NAME "cd_mpls"
 
 class MplsModule : public DecodeModule
 {
index dfd41647d8e91afc17877ada997d67117e99a758..6512667111fe0afb43c8b40295b14ddf6247496c 100644 (file)
 #include "framework/codec.h"
 #include "protocols/protocol_ids.h"
 #include "snort.h"
+#include "codecs/sf_protocols.h"
 
 namespace
 {
 
-#define CD_PPPENCAP_NAME "codec_ppp_encap"
+#define CD_PPPENCAP_NAME "cd_pppencap"
 
 class PppEncap : public Codec
 {
@@ -39,13 +40,10 @@ public:
     PppEncap() : Codec(CD_PPPENCAP_NAME){};
     ~PppEncap(){};
 
+    virtual PROTO_ID get_proto_id() { return PROTO_PPP_ENCAP; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
-
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_PPP_ENCAP; };
     
 };
 
index fd12d1b89ded4f96ae2716ec270deba78b1eaccb..65e26099409d3f21af9421b08cf5bc53f519e4de 100644 (file)
 #include "codecs/link/cd_pppoepkt_module.h"
 #include "codecs/codec_events.h"
 #include "protocols/packet.h"
+#include "codecs/sf_protocols.h"
+#include "protocols/layer.h"
 
 namespace
 {
 
-class PPPoEPktCodec : public Codec
+enum class PppoepktType
 {
-public:
-    PPPoEPktCodec() : Codec(CD_PPPOEPKT_NAME){};
-    ~PPPoEPktCodec(){};
-
+    DISCOVERY,
+    SESSION,
+};
 
-    virtual void get_protocol_ids(std::vector<uint16_t>& v);
-    virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
-        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
-    virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
-    
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_PPPOE; };
+/* PPPoEHdr Header; eth::EtherHdr plus the PPPoE Header */
+struct PPPoEHdr
+{
+    unsigned char ver_type;     /* pppoe version/type */
+    unsigned char code;         /* pppoe code CODE_* */
+    unsigned short session;     /* session id */
+    unsigned short length;      /* payload length */
+                                /* payload follows */
 };
 
+} // namespace
 
-const uint16_t PPPOE_HEADER_LEN = 6;
 
-const uint16_t ETHERNET_TYPE_PPPoE_DISC =  0x8863; /* discovery stage */
-const uint16_t ETHERNET_TYPE_PPPoE_SESS =  0x8864; /* session stage */
+const uint16_t PPPOE_HEADER_LEN = 6;
 
 /* PPPoE types */
 const uint16_t PPPoE_CODE_SESS = 0x00; /* PPPoE session */
@@ -62,7 +62,6 @@ const uint16_t PPPoE_CODE_PADT = 0xa7; /* PPPoE Active Discovery Terminate */
 
 #if 0
 /* PPPoE tag types  -  currently not used*/
-
 const uint16_t PPPoE_TAG_END_OF_LIST = 0x0000;
 const uint16_t PPPoE_TAG_SERVICE_NAME = 0x0101;
 const uint16_t PPPoE_TAG_AC_NAME = 0x0102;
@@ -75,37 +74,13 @@ const uint16_t PPPoE_TAG_AC_SYSTEM_ERROR = 0x0202;
 const uint16_t PPPoE_TAG_GENERIC_ERROR = 0x0203;
 #endif
 
-} // namespace
-
 
-void PPPoEPktCodec::get_protocol_ids(std::vector<uint16_t>& v)
-{
-    v.push_back(ETHERNET_TYPE_PPPoE_DISC);
-    v.push_back(ETHERNET_TYPE_PPPoE_SESS);
-}
-
-
-//--------------------------------------------------------------------
-// decode.c::PPP related
-//--------------------------------------------------------------------
-
-/*
- * Function: DecodePPPoEPkt(Packet *, char *, DAQ_PktHdr_t*, uint8_t*)
- *
- * Purpose: Decode those fun loving ethernet packets, one at a time!
- *
- * Arguments: p => pointer to the decoded packet struct
- *            user => Utility pointer (unused)
- *            pkthdr => ptr to the packet header
- *            pkt => pointer to the real live packet data
- *
- * Returns: void function
- *
- * see http://www.faqs.org/rfcs/rfc2516.html
- *
- */
-bool PPPoEPktCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
-        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
+static inline bool pppoepkt_decode(const uint8_t *raw_pkt,
+                                    const uint32_t len,
+                                    Packet *p,
+                                    PppoepktType ppp_type,
+                                    uint16_t &lyr_len,
+                                    uint16_t &next_prot_id)
 {
     //PPPoE_Tag *ppppoe_tag=0;
     //PPPoE_Tag tag;  /* needed to avoid alignment problems */
@@ -125,29 +100,24 @@ bool PPPoEPktCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
         return false;
     }
 
-    DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "%X   %X\n",
-                *p->eh->ether_src, *p->eh->ether_dst););
 
     /* lay the PPP over ethernet structure over the packet data */
-    p->pppoeh = (PPPoEHdr *)raw_pkt;
+    const PPPoEHdr *pppoeh = reinterpret_cast<const PPPoEHdr*>(raw_pkt);
 
     /* grab out the network type */
-    switch(ntohs(p->eh->ether_type))
+    switch(ppp_type)
     {
-        case ETHERNET_TYPE_PPPoE_DISC:
+        case PppoepktType::DISCOVERY:
             DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "(PPPOE Discovery) "););
             break;
 
-        case ETHERNET_TYPE_PPPoE_SESS:
+        case PppoepktType::SESSION:
             DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "(PPPOE Session) "););
             break;
-
-        default:
-            return false;
     }
 
 #ifdef DEBUG_MSGS
-    switch(p->pppoeh->code)
+    switch(pppoeh->code)
     {
         case PPPoE_CODE_PADI:
             /* The Host sends the PADI packet with the DESTINATION_ADDR set
@@ -248,21 +218,26 @@ bool PPPoEPktCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
             DebugMessage(DEBUG_DECODE, "(Unknown)\n");
             break;
     }
+#else
+    UNUSED(pppoeh);
+    UNUSED(PPPoE_CODE_SESS);
+    UNUSED(PPPoE_CODE_PADI);
+    UNUSED(PPPoE_CODE_PADO);
+    UNUSED(PPPoE_CODE_PADR);
+    UNUSED(PPPoE_CODE_PADS);
+    UNUSED(PPPoE_CODE_PADT);
 #endif
 
-    if (ntohs(p->eh->ether_type) != ETHERNET_TYPE_PPPoE_DISC)
+    if (ppp_type != PppoepktType::DISCOVERY)
     {
-//        PushLayer(PROTO_PPPOE, p, pkt, PPPOE_HEADER_LEN);
-//        DecodePppPktEncapsulated(pkt + PPPOE_HEADER_LEN, len - PPPOE_HEADER_LEN, p);
-
-        // TODO:  Why is this specifically PppPktEncapsulated?
         lyr_len = PPPOE_HEADER_LEN;
-        next_prot_id = ntohs(p->eh->ether_type);
+        next_prot_id = ETHERTYPE_PPP;
         return true;
     }
 
 
-    return false;
+    DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "Returning early on PPPOE discovery packet\n"););
+    return true;
 }
 
 
@@ -270,7 +245,7 @@ bool PPPoEPktCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
  ******************** E N C O D E R  ******************************
  ******************************************************************/
 
-bool PPPoEPktCodec::encode(EncState* enc, Buffer* out, const uint8_t* raw_in)
+static inline bool pppoepkt_encode(EncState* enc, Buffer* out, const uint8_t* raw_in)
 {
     int lyr_len = enc->p->layers[enc->layer-1].length;
 
@@ -287,12 +262,67 @@ bool PPPoEPktCodec::encode(EncState* enc, Buffer* out, const uint8_t* raw_in)
 }
 
 
+/*******************************************************************
+ *******************************************************************
+ *************                  CODECS              ****************
+ *******************************************************************
+ *******************************************************************/
+
+
+
+
+namespace
+{
+
+const uint16_t ETHERNET_TYPE_PPPoE_DISC =  0x8863; /* discovery stage */
+
+#define CD_PPPOEPKT_DISC_NAME "cd_pppoepkt (disc)"
+
+class PPPoEPktDiscCodec : public Codec
+{
+public:
+    PPPoEPktDiscCodec() : Codec(CD_PPPOEPKT_DISC_NAME){};
+    ~PPPoEPktDiscCodec() {};
+
+
+    virtual PROTO_ID get_proto_id() { return PROTO_PPPOE; };
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
+    virtual bool decode(const uint8_t *raw_pkt, const uint32_t len,
+        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+    virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
+};
+
+
+} // namespace
+
+void PPPoEPktDiscCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERNET_TYPE_PPPoE_DISC);
+}
+
+
+bool PPPoEPktDiscCodec::decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
+{
+    return pppoepkt_decode(raw_pkt, raw_len, p, PppoepktType::DISCOVERY,
+        lyr_len, next_prot_id);
+}
+
+bool PPPoEPktDiscCodec::encode(EncState *enc, Buffer* out, const uint8_t* raw_in)
+{
+    return pppoepkt_encode(enc, out, raw_in);
+}
 
 
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
 
+
+// ***  NOTE: THE CODEC HAS A DIFFERENT NAME!
+// However, since the module is creating a rule stub and is NOT
+// used for configurtion, it doesn't matter.  If you want to use the module
+// for configuration, ensure the names are identical before continuing!
 static Module* mod_ctor()
 {
     return new PPPoEPktModule;
@@ -303,44 +333,142 @@ static void mod_dtor(Module* m)
     delete m;
 }
 
-static Codec* ctor(Module *)
+static Codec* disc_ctor(Module*)
 {
-    return new PPPoEPktCodec();
+    return new PPPoEPktDiscCodec();
 }
 
-static void dtor(Codec *cd)
+static void disc_dtor(Codec *cd)
 {
     delete cd;
 }
 
-static const CodecApi pppoe_api =
+
+static const CodecApi pppoepkt_disc_api =
 {
     {
         PT_CODEC,
-        CD_PPPOEPKT_NAME,
+        CD_PPPOEPKT_DISC_NAME,
         CDAPI_PLUGIN_V0,
         0,
         mod_ctor,
         mod_dtor,
     },
-    nullptr, // pinit
-    nullptr, // pterm
-    nullptr, // tinit
-    nullptr, // tterm
-    ctor, // ctor
-    dtor, // dtor
+    nullptr,
+    nullptr,
+    nullptr,
+    nullptr,
+    disc_ctor,
+    disc_dtor,
 };
 
 
 #ifdef BUILDING_SO
 SO_PUBLIC const BaseApi* snort_plugins[] =
 {
-    &pppoe_api.base,
+    &pppoepkt_disc_api.base,
     nullptr
 };
 #else
-const BaseApi* cd_pppoe = &pppoe_api.base;
+const BaseApi* cd_pppoepkt_disc = &pppoepkt_disc_api.base;
 #endif
 
 
 
+/*******************************************************************
+ *******************************************************************
+ *******************************************************************
+ *******************************************************************/
+
+
+
+
+namespace
+{
+
+
+#define CD_PPPOEPKT_SESS_NAME "cd_pppoepkt (sess)"
+const uint16_t ETHERNET_TYPE_PPPoE_SESS =  0x8864; /* session stage */
+
+class PPPoEPktSessCodec : public Codec
+{
+public:
+    PPPoEPktSessCodec() : Codec(CD_PPPOEPKT_SESS_NAME){};
+    ~PPPoEPktSessCodec() {};
+
+
+    virtual PROTO_ID get_proto_id() { return PROTO_PPPOE; };
+    virtual void get_protocol_ids(std::vector<uint16_t>& v);
+    virtual bool decode(const uint8_t *raw_pkt, const uint32_t len,
+        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+    virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
+};
+
+
+} // namespace
+
+void PPPoEPktSessCodec::get_protocol_ids(std::vector<uint16_t>& v)
+{
+    v.push_back(ETHERNET_TYPE_PPPoE_SESS);
+}
+
+
+bool PPPoEPktSessCodec::decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
+{
+    return pppoepkt_decode(raw_pkt, raw_len, p, PppoepktType::SESSION,
+        lyr_len, next_prot_id);
+}
+
+
+
+bool PPPoEPktSessCodec::encode(EncState *enc, Buffer* out, const uint8_t* raw_in)
+{
+    return pppoepkt_encode(enc, out, raw_in);
+}
+
+
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
+
+
+static Codec* sess_ctor(Module*)
+{
+    return new PPPoEPktSessCodec();
+}
+
+static void sess_dtor(Codec *cd)
+{
+    delete cd;
+}
+
+
+static const CodecApi pppoepkt_sess_api =
+{
+    {
+        PT_CODEC,
+        CD_PPPOEPKT_SESS_NAME,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr,
+    nullptr,
+    nullptr,
+    nullptr,
+    sess_ctor,
+    sess_dtor,
+};
+
+
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+{
+    &pppoepkt_sess_api.base,
+    nullptr
+};
+#else
+const BaseApi* cd_pppoepkt_sess = &pppoepkt_sess_api.base;
+#endif
index 25120b2591bf1c3f60528286c704cfa3ec60e44a..c897d627dd272c8fd5b0cddec63d0771f5c474c7 100644 (file)
@@ -35,9 +35,15 @@ static const RuleMap pppoepkt_rules[] =
 };
 
 //-------------------------------------------------------------------------
-// rpc module
+// General PPPoEpkt module.
+//
+//      ***** NOTE: THE CODEC HAS A DIFFERENT NAME!
+//          * Additionally, this module is used for generator a rule stub ONLY!
+//          * If you want to create a module for configuration, you must change the
+//          * names of the correct PPPoEpkt codec
 //-------------------------------------------------------------------------
 
+/// ^^^  READ THE COMMENT!
 PPPoEPktModule::PPPoEPktModule() : DecodeModule(CD_PPPOEPKT_NAME, pppoepkt_params, pppoepkt_rules)
 { }
 
index aa9988c614febf4d054e87ae37a9f753fe08cdd2..3137d4b5e7361cbf1454b2f4efa0ca4b18ee03e8 100644 (file)
 #include "codecs/decode_module.h"
 
 
-#define CD_PPPOEPKT_NAME "codec_pppoepkt"
+/*
+ * NOTE:  This name reflect the file...NOT the Codec!
+ *
+ * Additionally, this module is used for generator a rule stub ONLY!
+ * If you want to create a module for configuration, you must change the
+ * names of the correct PPPoEpkt codec
+ */
+
+#define CD_PPPOEPKT_NAME "cd_pppoepkt"
 
 class PPPoEPktModule : public DecodeModule
 {
index 5e6489554c2fa5b717d62f1b655217a06987f491..ee438f488d1dc7a23bf9777761049c935d0d8004 100644 (file)
@@ -36,7 +36,7 @@
 namespace
 {
 
-#define CD_TRANSBRIDGE_NAME "codec_transbridge"
+#define CD_TRANSBRIDGE_NAME "cd_transbridge"
 
 class TransbridgeCodec : public Codec
 {
@@ -76,23 +76,24 @@ void TransbridgeCodec::get_protocol_ids(std::vector<uint16_t>& v)
  * convention needed to be changed and the stuff at the beginning
  * wasn't needed since we are already deep into the packet
  */
-bool TransbridgeCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
+bool TransbridgeCodec::decode(const uint8_t *raw_pkt, const uint32_t raw_len,
         Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
 {
-    if(len < eth::hdr_len())
+    if(raw_len < eth::hdr_len())
     {
         codec_events::decoder_alert_encapsulated(p, DECODE_GRE_TRANS_DGRAM_LT_TRANSHDR,
-                        raw_pkt, len);
+                        raw_pkt, raw_len);
         return false;
     }
 
     /* The Packet struct's ethernet header will now point to the inner ethernet
      * header of the packet
      */
-    p->eh = (eth::EtherHdr *)raw_pkt;
+    const eth::EtherHdr *eh = reinterpret_cast<const eth::EtherHdr*>(raw_pkt);
 
+    p->proto_bits |= PROTO_BIT__ETH;
     lyr_len = eth::hdr_len();
-    next_prot_id = ntohs(p->eh->ether_type);
+    next_prot_id = ntohs(eh->ether_type);
 
     return true;
 }
index e2de8430f6f121fcc5b17545cda551c3acfbed94..82d43ea5a5cb49c6e14899b5728a77fee062e46d 100644 (file)
@@ -29,6 +29,9 @@
 #include "framework/codec.h"
 #include "codecs/link/cd_vlan_module.h"
 #include "codecs/codec_events.h"
+#include "protocols/vlan.h"
+#include "protocols/protocol_ids.h"
+#include "codecs/sf_protocols.h"
 
 namespace
 {
@@ -39,39 +42,47 @@ public:
     VlanCodec() : Codec(CD_VLAN_NAME){};
     ~VlanCodec(){};
 
+    virtual PROTO_ID get_proto_id() { return PROTO_VLAN; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
-    virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
+};
+
+struct EthLlc
+{
+    uint8_t dsap;
+    uint8_t ssap;
+} ;
 
-    
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_VLAN; };
+
+struct EthLlcOther
+{
+    uint8_t ctrl;
+    uint8_t org_code[3];
+    uint16_t proto_id;
 };
 
 } // namespace
 
-static const uint16_t ETHERNET_TYPE_8021Q = 0x8100;
 static const unsigned int ETHERNET_MAX_LEN_ENCAP = 1518;    /* 802.3 (+LLC) or ether II ? */
 
 
 static inline uint32_t len_vlan_llc_other()
 {
-    return (sizeof(VlanTagHdr) + sizeof(EthLlc) + sizeof(EthLlcOther));
+    return (sizeof(vlan::VlanTagHdr) + sizeof(EthLlc) + sizeof(EthLlcOther));
 }
 
 
 void VlanCodec::get_protocol_ids(std::vector<uint16_t>& v)
 {
-    v.push_back(ETHERNET_TYPE_8021Q);
+    v.push_back(ETHERTYPE_8021Q);
 }
 
 
 bool VlanCodec::decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
 {
-    if(len < sizeof(VlanTagHdr))
+    if(len < sizeof(vlan::VlanTagHdr))
     {
         codec_events::decoder_event(p, DECODE_BAD_VLAN);
 
@@ -81,24 +92,24 @@ bool VlanCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
         return false;
     }
 
-    p->vh = (VlanTagHdr *) raw_pkt;
+    const vlan::VlanTagHdr *vh = reinterpret_cast<const vlan::VlanTagHdr *>(raw_pkt);
 
     DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "Vlan traffic:\n");
                DebugMessage(DEBUG_DECODE, "   Priority: %d(0x%X)\n",
-                            VTH_PRIORITY(p->vh), VTH_PRIORITY(p->vh));
-               DebugMessage(DEBUG_DECODE, "   CFI: %d\n", VTH_CFI(p->vh));
+                            vlan::vth_priority(vh), vlan::vth_priority(vh));
+               DebugMessage(DEBUG_DECODE, "   CFI: %d\n", vlan::vth_cfi(vh));
                DebugMessage(DEBUG_DECODE, "   Vlan ID: %d(0x%04X)\n",
-                            VTH_VLAN(p->vh), VTH_VLAN(p->vh));
+                            vlan::vth_vlan(vh), vlan::vth_vlan(vh));
                DebugMessage(DEBUG_DECODE, "   Vlan Proto: 0x%04X\n",
-                            ntohs(p->vh->vth_proto));
+                            ntohs(vh->vth_proto));
                );
 
     /* check to see if we've got an encapsulated LLC layer
      * http://www.geocities.com/billalexander/ethernet.html
      */
-    if(ntohs(p->vh->vth_proto) <= ETHERNET_MAX_LEN_ENCAP)
+    if(ntohs(vh->vth_proto) <= ETHERNET_MAX_LEN_ENCAP)
     {
-        if(len < sizeof(VlanTagHdr) + sizeof(EthLlc))
+        if(len < sizeof(vlan::VlanTagHdr) + sizeof(EthLlc))
         {
             codec_events::decoder_event(p, DECODE_BAD_VLAN_ETHLLC);
 
@@ -107,15 +118,15 @@ bool VlanCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
             return false;
         }
 
-        p->ehllc = (EthLlc *) (raw_pkt + sizeof(VlanTagHdr));
+        const EthLlc *ehllc = reinterpret_cast<const EthLlc *>(raw_pkt + sizeof(vlan::VlanTagHdr));
 
         DEBUG_WRAP(
                 DebugMessage(DEBUG_DECODE, "LLC Header:\n");
-                DebugMessage(DEBUG_DECODE, "   DSAP: 0x%X\n", p->ehllc->dsap);
-                DebugMessage(DEBUG_DECODE, "   SSAP: 0x%X\n", p->ehllc->ssap);
+                DebugMessage(DEBUG_DECODE, "   DSAP: 0x%X\n", ehllc->dsap);
+                DebugMessage(DEBUG_DECODE, "   SSAP: 0x%X\n", ehllc->ssap);
                 );
 
-        if(p->ehllc->dsap == ETH_DSAP_IP && p->ehllc->ssap == ETH_SSAP_IP)
+        if(ehllc->dsap == ETH_DSAP_IP && ehllc->ssap == ETH_SSAP_IP)
         {
             if ( len < len_vlan_llc_other() )
             {
@@ -127,43 +138,35 @@ bool VlanCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
                 return false;
             }
 
-            p->ehllcother = (EthLlcOther *) (raw_pkt + sizeof(VlanTagHdr) + sizeof(EthLlc));
+            const EthLlcOther *ehllcother = reinterpret_cast<const EthLlcOther *>(raw_pkt + sizeof(vlan::VlanTagHdr) + sizeof(EthLlc));
 
             DEBUG_WRAP(
                     DebugMessage(DEBUG_DECODE, "LLC Other Header:\n");
                     DebugMessage(DEBUG_DECODE, "   CTRL: 0x%X\n",
-                        p->ehllcother->ctrl);
+                        ehllcother->ctrl);
                     DebugMessage(DEBUG_DECODE, "   ORG: 0x%02X%02X%02X\n",
-                        p->ehllcother->org_code[0], p->ehllcother->org_code[1],
-                        p->ehllcother->org_code[2]);
+                        ehllcother->org_code[0], ehllcother->org_code[1],
+                        ehllcother->org_code[2]);
                     DebugMessage(DEBUG_DECODE, "   PROTO: 0x%04X\n",
-                        ntohs(p->ehllcother->proto_id));
+                        ntohs(ehllcother->proto_id));
                     );
 
             lyr_len = len_vlan_llc_other();
-            next_prot_id = ntohs(p->ehllcother->proto_id);
+            next_prot_id = ntohs(ehllcother->proto_id);
         }
     }
     else
     {
-        lyr_len = sizeof(VlanTagHdr);
-        next_prot_id = ntohs(p->vh->vth_proto);
+        lyr_len = sizeof(vlan::VlanTagHdr);
+        next_prot_id = ntohs(vh->vth_proto);
 
     }
 
+    p->proto_bits |= PROTO_BIT__VLAN;
     return true;
 }
 
 
-/*
- * ENCODER
- */
-void VlanCodec::format(EncodeFlags, const Packet* /*p*/, Packet* c, Layer*lyr)
-{
-    c->vh = (VlanTagHdr*)lyr->start;
-}
-
-
 //-------------------------------------------------------------------------
 // api
 //-------------------------------------------------------------------------
@@ -188,7 +191,6 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-
 static const CodecApi vlan_api =
 {
     {
index d4c5e75578ca134d4ac40f30b7dc8c5d6c08c875..2f2e75c16a7c313fc03d9b735a0ca6e2f8d0929d 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_VLAN_NAME "codec_vlan"
+#define CD_VLAN_NAME "cd_vlan"
 
 class VlanModule : public DecodeModule
 {
index 347a5d3517b40d3b586c6a81dc255637f0cc7bfc..70d81ec9ed11743d804f545a44abbc88646290c7 100644 (file)
 #include "config.h"
 #endif
 
-#include "packet.h"
 #include "snort_debug.h"
+#include "main/snort.h"
 #include "framework/codec.h"
-#include "codecs/misc/cd_gtp_module.h"
+#include "protocols/packet.h"
 #include "codecs/codec_events.h"
-#include "snort.h"
+#include "codecs/misc/cd_gtp_module.h"
 #include "protocols/ipv4.h"
 #include "protocols/ipv6.h"
 #include "packet_io/active.h"
-
+#include "codecs/sf_protocols.h"
 #include "protocols/protocol_ids.h"
 
 namespace
@@ -46,20 +46,15 @@ public:
     GtpCodec() : Codec(CD_GTP_NAME){};
     ~GtpCodec(){};
 
+    virtual PROTO_ID get_proto_id() { return PROTO_GTP; };
     virtual void get_protocol_ids(std::vector<uint16_t>& v);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
         Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
     virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
     virtual bool update(Packet*, Layer*, uint32_t* len);
-
-
-    // DELETE from here and below
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_GTP; };    
 };
 
 
-
 /* GTP basic Header  */
 struct GTPHdr
 {
index 2cc2a0012f8083f7d1513aaef7972c05a65b1f35..add09ebe7dcc9aea8e4ea43de3285fb013416606 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_GTP_NAME "codec_gtp"
+#define CD_GTP_NAME "cd_gtp"
 
 class GtpModule : public DecodeModule
 {
index af20c9ba333f02380dd7d1756089f4b312f18ab3..c6b08022053867c37787f9f80b53b764d0af3907 100644 (file)
@@ -40,7 +40,7 @@
 namespace
 {
 
-#define CD_TEREDO_NAME "codec_teredo"
+#define CD_TEREDO_NAME "cd_teredo"
 
 class TeredoCodec : public Codec
 {
index 4d6b6abc8ff5520fb9d843d5165e93da1257df4f..7456d981779237057c9c212af91def3c1a838ad7 100644 (file)
@@ -3,37 +3,27 @@
 include_directories(${PCAP_INCLUDE_DIR})
 
 
-if (ENABLE_NON_ETHER_DECODERS)
-    set( NON_ETHER_DECODERS
-        prot_eap.h
-        prot_eapol.h
-        prot_eapol.cc
-        prot_eapolkey.h
-        prot_eapolkey.cc
-    )
-endif(ENABLE_NON_ETHER_DECODERS)
-
 if (ENABLE_NON_ETHER_DECODERS)
     set(NON_ETHER_DECODERS
-        cd_trk.cc
-        cd_trk_module.h
-        cd_trk_module.cc
-        root_fddi.cc
-        root_linuxsll.cc
-        cd_ieee80211.cc
-        cd_ieee80211_module.h
-        cd_ieee80211_module.cc
-        root_slip.cc
-        root_i4lrawip.cc
-        root_oldpflog.cc
-        root_enc.cc
-        root_ppp.cc
-        root_pflog.cc
-        root_pppserial.cc
-        root_chdlc.cc
-        root_i4lciscoip.cc
-        prot_ipx.cc
-        prot_eap.cc
+        cd_linux_sll.cc
+        cd_tr.cc
+        cd_tr_module.h
+        cd_tr_module.cc
+        cd_wlan.cc
+        cd_wlan_module.h
+        cd_wlan_module.cc
+#        root_fddi.cc
+#        root_slip.cc
+#        root_i4lrawip.cc
+#        root_oldpflog.cc
+#        root_enc.cc
+#        root_ppp.cc
+#        root_pflog.cc
+#        root_pppserial.cc
+#        root_chdlc.cc
+#        root_i4lciscoip.cc
+#        prot_ipx.cc
+#        prot_eap.cc
     )
 endif (ENABLE_NON_ETHER_DECODERS)
 
@@ -44,7 +34,7 @@ add_library(root_codecs STATIC
     cd_eth_module.cc
     cd_raw4.cc
     cd_raw6.cc
-    cd_null_root.cc
+    cd_null.cc
     ${NON_ETHER_DECODERS}
     ${PCAP_INCLUDE_DIR}/pcap.h  # rebuild if a new libpcap is installed
 )
index 88a2c2bffa5eb95dbdeb4a06bf259dc3d644b8b9..359c234899aaf6f56c54f0e5243e55aff795cc95 100644 (file)
@@ -7,40 +7,50 @@ cd_eth_module.h \
 cd_eth_module.cc \
 cd_raw4.cc \
 cd_raw6.cc \
-cd_null_root.cc
+cd_null.cc
 
 
 
 if ENABLE_NON_ETHER_DECODER
 if STATIC_DECODERS
 libroot_codecs_a_SOURCES += \
-cd_trk.cc \
-cd_trk_module.h \
-cd_trk_module.cc \
-root_fddi.cc \
-root_linuxsll.cc \
-cd_ieee80211.cc \
-cd_ieee80211_module.h \
-cd_ieee80211_module.cc \
-root_slip.cc \
-root_i4lrawip.cc \
-root_oldpflog.cc \
-root_enc.cc \
-root_ppp.cc \
-root_pflog.cc \
-root_pppserial.cc \
-root_chdlc.cc \
-root_i4lciscoip.cc
+cd_linux_sll.cc \
+cd_tr.cc \
+cd_tr_module.h \
+cd_tr_module.cc \
+cd_wlan.cc \
+cd_wlan_module.h \
+cd_wlan_module.cc
+#root_fddi.cc \
+#root_slip.cc \
+#root_i4lrawip.cc \
+#root_oldpflog.cc \
+#root_enc.cc \
+#root_ppp.cc \
+#root_pflog.cc \
+#root_pppserial.cc \
+#root_chdlc.cc \
+#root_i4lciscoip.cc
 
 
 
 else
 ehlibdir = $(pkglibdir)/codecs
 
-ehlib_LTLIBRARIES = libcd_trk.la
-libcd_trk_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
-libcd_trk_la_LDFLAGS = -export-dynamic -shared
-libcd_trk_la_SOURCES = cd_trk.cc cd_trk_module.h cd_trk_module.cc
+ehlib_LTLIBRARIES = libcd_tr.la
+libcd_tr_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
+libcd_tr_la_LDFLAGS = -export-dynamic -shared
+libcd_tr_la_SOURCES = cd_tr.cc cd_tr_module.h cd_tr_module.cc
+
+ehlib_LTLIBRARIES += libcd_wlan.la
+libcd_wlan_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
+libcd_wlan_la_LDFLAGS = -export-dynamic -shared
+libcd_wlan_la_SOURCES =  cd_wlan.cc cd_wlan_module.h cd_wlan_module.cc
+
+ehlib_LTLIBRARIES += libcd_linux_sll.la
+libcd_linux_sll_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
+libcd_linux_sll_la_LDFLAGS = -export-dynamic -shared
+libcd_linux_sll_la_SOURCES =  cd_linux_sll.cc
 
 endif
 endif
index 4ccedb3f9cafd4d2351d3cd7fef51d815b9cd0a3..d1c50672fc495d4df6e1fb43294fde84e49e58af 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
 ** Copyright (C) 2002-2013 Sourcefire, Inc.
 ** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
@@ -20,7 +19,6 @@
 */
 
 
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -33,6 +31,7 @@
 #include "protocols/eth.h"
 #include "codecs/codec_events.h"
 #include "managers/packet_manager.h"
+#include "codecs/sf_protocols.h"
 
 namespace
 {
@@ -44,6 +43,7 @@ public:
     ~EthCodec(){};
 
 
+    virtual PROTO_ID get_proto_id() { return PROTO_ETH; };
     virtual void get_protocol_ids(std::vector<uint16_t>&) {};
     virtual void get_data_link_type(std::vector<int>&);
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len, 
@@ -51,14 +51,9 @@ public:
     virtual bool encode(EncState*, Buffer* out, const uint8_t* raw_in);
     virtual bool update(Packet*, Layer*, uint32_t* len);
     virtual void format(EncodeFlags, const Packet* p, Packet* c, Layer*);
-
-    // DELETE
-    #include "codecs/sf_protocols.h"
-    virtual inline PROTO_ID get_proto_id() { return PROTO_ETH; };
-    
 };
 
-} // anonymous
+} // namespace
 
 
 void EthCodec::get_data_link_type(std::vector<int>&v)
@@ -103,24 +98,25 @@ bool EthCodec::decode(const uint8_t *raw_pkt, const uint32_t len,
     }
 
     /* lay the ethernet structure over the packet data */
-    p->eh = reinterpret_cast<const eth::EtherHdr *>(raw_pkt);
+    const eth::EtherHdr *eh = reinterpret_cast<const eth::EtherHdr *>(raw_pkt);
 
     DEBUG_WRAP(
             DebugMessage(DEBUG_DECODE, "%X:%X:%X:%X:%X:%X -> %X:%X:%X:%X:%X:%X\n",
-                p->eh->ether_src[0],
-                p->eh->ether_src[1], p->eh->ether_src[2], p->eh->ether_src[3],
-                p->eh->ether_src[4], p->eh->ether_src[5], p->eh->ether_dst[0],
-                p->eh->ether_dst[1], p->eh->ether_dst[2], p->eh->ether_dst[3],
-                p->eh->ether_dst[4], p->eh->ether_dst[5]);
+                eh->ether_src[0],
+                eh->ether_src[1], eh->ether_src[2], eh->ether_src[3],
+                eh->ether_src[4], eh->ether_src[5], eh->ether_dst[0],
+                eh->ether_dst[1], eh->ether_dst[2], eh->ether_dst[3],
+                eh->ether_dst[4], eh->ether_dst[5]);
             );
     DEBUG_WRAP(
             DebugMessage(DEBUG_DECODE, "type:0x%X len:0x%X\n",
-                ntohs(p->eh->ether_type), p->pkth->pktlen)
+                ntohs(eh->ether_type), p->pkth->pktlen)
             );
 
-    next_prot_id = ntohs(p->eh->ether_type);
+    next_prot_id = ntohs(eh->ether_type);
     if (next_prot_id > eth::min_ethertype() )
     {
+        p->proto_bits |= PROTO_BIT__ETH;
         lyr_len = eth::hdr_len();
         return true;
     }
@@ -192,7 +188,6 @@ bool EthCodec::update (Packet*, Layer* lyr, uint32_t* len)
 void EthCodec::format(EncodeFlags f, const Packet* p, Packet* c, Layer* lyr)
 {
     eth::EtherHdr* ch = (eth::EtherHdr*)lyr->start;
-    c->eh = ch;
 
     if ( reverse(f) )
     {
index e1fef3fdfcad9017e64ffe9db2d85742df586134..15f0e10eb83e7e346634bee34e2480a15153f20e 100644 (file)
@@ -25,7 +25,7 @@
 #include "codecs/decode_module.h"
 
 
-#define CD_ETH_NAME "codec_eth"
+#define CD_ETH_NAME "cd_eth"
 
 class EthModule : public DecodeModule
 {
diff --git a/src/codecs/root/cd_ieee80211.cc b/src/codecs/root/cd_ieee80211.cc
deleted file mode 100644 (file)
index 64abbc6..0000000
+++ /dev/null
@@ -1,229 +0,0 @@
-/* $Id: decode.c,v 1.285 2013-06-29 03:03:00 rcombs Exp $ */
-
-/*
-** Copyright (C) 2002-2013 Sourcefire, Inc.
-** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License Version 2 as
-** published by the Free Software Foundation.  You may not use, modify or
-** distribute this program under any other version of the GNU General
-** Public License.
-**
-** 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.
-*/
-
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "generators.h"
-#include "decode.h"  
-#include "static_include.h"
-#include "log/log.h"
-
-#include "../decoder_includes.h"
-
-
-
-#define MINIMAL_IEEE80211_HEADER_LEN    10    /* Ack frames and others */
-#define IEEE802_11_DATA_HDR_LEN         24    /* Header for data packets */
-
-/*
- * Function: DecodeIEEE80211Pkt(Packet *, char *, DAQ_PktHdr_t*,
- *                               uint8_t*)
- *
- * Purpose: Decode those fun loving wireless LAN packets, one at a time!
- *
- * Arguments: p => pointer to the decoded packet struct
- *            user => Utility pointer (unused)
- *            pkthdr => ptr to the packet header
- *            pkt => pointer to the real live packet data
- *
- * Returns: void function
- */
-void DecodeIEEE80211Pkt(Packet * p, const DAQ_PktHdr_t * pkthdr,
-                        const uint8_t * pkt)
-{
-    uint32_t cap_len = pkthdr->caplen;
-    PROFILE_VARS;
-
-    PREPROC_PROFILE_START(decodePerfStats);
-
-    dc.total_processed++;
-
-    memset(p, 0, PKT_ZERO_LEN);
-
-    p->pkth = pkthdr;
-    p->pkt = pkt;
-
-    DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "Packet!\n"););
-    DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "caplen: %lu    pktlen: %lu\n",
-                (unsigned long)cap_len, (unsigned long)pkthdr->pktlen););
-
-    /* do a little validation */
-    if(cap_len < MINIMAL_IEEE80211_HEADER_LEN)
-    {
-        if (ScLogVerbose())
-        {
-            ErrorMessage("Captured data length < IEEE 802.11 header length! "
-                         "(%d bytes)\n", cap_len);
-        }
-
-        PREPROC_PROFILE_END(decodePerfStats);
-        return;
-    }
-    /* lay the wireless structure over the packet data */
-    p->wifih = (WifiHdr *) pkt;
-
-    DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "%X   %X\n", *p->wifih->addr1,
-                *p->wifih->addr2););
-
-    /* determine frame type */
-    switch(p->wifih->frame_control & 0x00ff)
-    {
-        /* management frames */
-        case WLAN_TYPE_MGMT_ASREQ:
-        case WLAN_TYPE_MGMT_ASRES:
-        case WLAN_TYPE_MGMT_REREQ:
-        case WLAN_TYPE_MGMT_RERES:
-        case WLAN_TYPE_MGMT_PRREQ:
-        case WLAN_TYPE_MGMT_PRRES:
-        case WLAN_TYPE_MGMT_BEACON:
-        case WLAN_TYPE_MGMT_ATIM:
-        case WLAN_TYPE_MGMT_DIS:
-        case WLAN_TYPE_MGMT_AUTH:
-        case WLAN_TYPE_MGMT_DEAUTH:
-            dc.wifi_mgmt++;
-            break;
-
-            /* Control frames */
-        case WLAN_TYPE_CONT_PS:
-        case WLAN_TYPE_CONT_RTS:
-        case WLAN_TYPE_CONT_CTS:
-        case WLAN_TYPE_CONT_ACK:
-        case WLAN_TYPE_CONT_CFE:
-        case WLAN_TYPE_CONT_CFACK:
-            dc.wifi_control++;
-            break;
-            /* Data packets without data */
-        case WLAN_TYPE_DATA_NULL:
-        case WLAN_TYPE_DATA_CFACK:
-        case WLAN_TYPE_DATA_CFPL:
-        case WLAN_TYPE_DATA_ACKPL:
-
-            dc.wifi_data++;
-            break;
-        case WLAN_TYPE_DATA_DTCFACK:
-        case WLAN_TYPE_DATA_DTCFPL:
-        case WLAN_TYPE_DATA_DTACKPL:
-        case WLAN_TYPE_DATA_DATA:
-            dc.wifi_data++;
-
-            if(cap_len < IEEE802_11_DATA_HDR_LEN + sizeof(EthLlc))
-            {
-                codec_events::decoder_event(p, DECODE_BAD_80211_ETHLLC,
-                                DECODE_BAD_80211_ETHLLC_STR);
-
-                PREPROC_PROFILE_END(decodePerfStats);
-                return;
-            }
-
-            p->ehllc = (EthLlc *) (pkt + IEEE802_11_DATA_HDR_LEN);
-
-#ifdef DEBUG_MSGS
-            LogNetData((uint8_t*) p->ehllc, sizeof(EthLlc), NULL);
-
-            printf("LLC Header:\n");
-            printf("   DSAP: 0x%X\n", p->ehllc->dsap);
-            printf("   SSAP: 0x%X\n", p->ehllc->ssap);
-#endif
-
-            if(p->ehllc->dsap == ETH_DSAP_IP && p->ehllc->ssap == ETH_SSAP_IP)
-            {
-                if(cap_len < IEEE802_11_DATA_HDR_LEN +
-                   sizeof(EthLlc) + sizeof(EthLlcOther))
-                {
-                    codec_events::decoder_event(p, DECODE_BAD_80211_OTHER,
-                                    DECODE_BAD_80211_OTHER_STR);
-
-                    PREPROC_PROFILE_END(decodePerfStats);
-                    return;
-                }
-
-                p->ehllcother = (EthLlcOther *) (pkt + IEEE802_11_DATA_HDR_LEN + sizeof(EthLlc));
-#ifdef DEBUG_MSGS
-                LogNetData((uint8_t*)p->ehllcother, sizeof(EthLlcOther), NULL);
-
-                printf("LLC Other Header:\n");
-                printf("   CTRL: 0x%X\n", p->ehllcother->ctrl);
-                printf("   ORG: 0x%02X%02X%02X\n", p->ehllcother->org_code[0],
-                        p->ehllcother->org_code[1], p->ehllcother->org_code[2]);
-                printf("   PROTO: 0x%04X\n", ntohs(p->ehllcother->proto_id));
-#endif
-
-                switch(ntohs(p->ehllcother->proto_id))
-                {
-                    case ETHERNET_TYPE_IP:
-                        DecodeIP(p->pkt + IEEE802_11_DATA_HDR_LEN + sizeof(EthLlc) +
-                                sizeof(EthLlcOther),
-                                cap_len - IEEE802_11_DATA_HDR_LEN - sizeof(EthLlc) -
-                                sizeof(EthLlcOther), p);
-                        PREPROC_PROFILE_END(decodePerfStats);
-                        return;
-
-                    case ETHERNET_TYPE_ARP:
-                    case ETHERNET_TYPE_REVARP:
-                        DecodeARP(p->pkt + IEEE802_11_DATA_HDR_LEN + sizeof(EthLlc) +
-                                sizeof(EthLlcOther),
-                                cap_len - IEEE802_11_DATA_HDR_LEN - sizeof(EthLlc) -
-                                sizeof(EthLlcOther), p);
-                        PREPROC_PROFILE_END(decodePerfStats);
-                        return;
-                    case ETHERNET_TYPE_EAPOL:
-                        DecodeEapol(p->pkt + IEEE802_11_DATA_HDR_LEN + sizeof(EthLlc) +
-                                sizeof(EthLlcOther),
-                                cap_len - IEEE802_11_DATA_HDR_LEN - sizeof(EthLlc) -
-                                sizeof(EthLlcOther), p);
-                        PREPROC_PROFILE_END(decodePerfStats);
-                        return;
-                    case ETHERNET_TYPE_8021Q:
-                        DecodeVlan(p->pkt + IEEE802_11_DATA_HDR_LEN ,
-                                   cap_len - IEEE802_11_DATA_HDR_LEN , p);
-                        PREPROC_PROFILE_END(decodePerfStats);
-                        return;
-
-                    case ETHERNET_TYPE_IPV6:
-                        DecodeIPV6(p->pkt + IEEE802_11_DATA_HDR_LEN,
-                                cap_len - IEEE802_11_DATA_HDR_LEN, p);
-                        PREPROC_PROFILE_END(decodePerfStats);
-                        return;
-
-                    default:
-                        // TBD add decoder drop event for unknown wifi/eth type
-                        dc.other++;
-                        PREPROC_PROFILE_END(decodePerfStats);
-                        return;
-                }
-            }
-            break;
-        default:
-            // TBD add decoder drop event for unknown wlan frame type
-            dc.other++;
-            break;
-    }
-
-    PREPROC_PROFILE_END(decodePerfStats);
-    return;
-}
-
-
diff --git a/src/codecs/root/cd_linux_sll.cc b/src/codecs/root/cd_linux_sll.cc
new file mode 100644 (file)
index 0000000..951704b
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+** Copyright (C) 2002-2013 Sourcefire, Inc.
+** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pcap.h>
+#include "framework/codec.h"
+#include "protocols/linux_sll.h"
+#include "main/snort.h"
+
+
+namespace
+{
+
+#define CD_LINUX_SSL_NAME "cd_linux_sll"
+
+class LinuxSllCodec : public Codec
+{
+public:
+    LinuxSllCodec() : Codec(CD_LINUX_SSL_NAME){};
+    ~LinuxSllCodec() {};
+
+
+    virtual void get_data_link_type(std::vector<int>&);
+    virtual bool decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+};
+
+// Create your own Hdr Struct for this layer!
+struct NameHdr
+{
+    uint8_t ver;
+    uint8_t next_protocol;
+    uint16_t len;
+    // additional or different data
+};
+
+} // namespace
+
+
+void LinuxSllCodec::get_data_link_type(std::vector<int>&v)
+{
+#ifdef DLT_LINUX_SLL
+    v.push_back(DLT_LINUX_SLL);
+#endif
+}
+
+bool LinuxSllCodec::decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet* /*p*/, uint16_t &lyr_len, uint16_t &next_prot_id)
+{
+    /* do a little validation */
+    if(raw_len < SLL_HDR_LEN)
+    {
+        if (ScLogVerbose())
+        {
+            ErrorMessage("Captured data length < SLL header length (your "
+                         "libpcap is broken?)! (%d bytes)\n", raw_len);
+        }
+        return false;
+    }
+    /* lay the ethernet structure over the packet data */
+    const linux_sll::SLLHdr* sllh = reinterpret_cast<const linux_sll::SLLHdr*>(raw_pkt);
+
+    /* grab out the network type */
+    next_prot_id = ntohs(sllh->sll_protocol);
+    lyr_len = SLL_HDR_LEN;
+    return true;
+}
+
+
+
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
+
+static Codec* ctor(Module*)
+{
+    return new LinuxSllCodec();
+}
+
+static void dtor(Codec *cd)
+{
+    delete cd;
+}
+
+
+static const CodecApi linux_ssl_api =
+{
+    {
+        PT_CODEC,
+        CD_LINUX_SSL_NAME,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
+    nullptr,
+    nullptr,
+    nullptr,
+    nullptr,
+    ctor,
+    dtor,
+};
+
+
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+{
+    &linux_ssl_api.base,
+    nullptr
+};
+#else
+const BaseApi* cd_linux_sll = &linux_ssl_api.base;
+#endif
+
similarity index 86%
rename from src/codecs/root/cd_null_root.cc
rename to src/codecs/root/cd_null.cc
index 4fc68fbbe9a6ae212ccaa464d93a56fc65153659..6325ea65ebad5bcde5314670174ab880eff55b71 100644 (file)
 namespace
 {
 
-#define CD_NULL_NAME "codec_null"
+#define CD_NULL_NAME "cd_null"
 
-class NullRootCodec : public Codec
+class NullCodec : public Codec
 {
 public:
-    NullRootCodec() : Codec(CD_NULL_NAME){};
-    ~NullRootCodec() {};
+    NullCodec() : Codec(CD_NULL_NAME){};
+    ~NullCodec() {};
 
 
     virtual bool decode(const uint8_t *raw_pkt, const uint32_t len,
@@ -67,7 +67,7 @@ static const uint16_t NULL_HDRLEN = 4;
  *
  * Returns: void function
  */
-bool NullRootCodec::decode(const uint8_t* /*raw_pkt*/, const uint32_t raw_len, 
+bool NullCodec::decode(const uint8_t* /*raw_pkt*/, const uint32_t raw_len,
         Packet* /*p*/, uint16_t &lyr_len, uint16_t &next_prot_id)
 {
     DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "NULL Packet!\n"); );
@@ -88,7 +88,7 @@ bool NullRootCodec::decode(const uint8_t* /*raw_pkt*/, const uint32_t raw_len,
     return true;
 }
 
-void NullRootCodec::get_data_link_type(std::vector<int>&v)
+void NullCodec::get_data_link_type(std::vector<int>&v)
 {
     v.push_back(DLT_NULL);
 }
@@ -99,7 +99,7 @@ void NullRootCodec::get_data_link_type(std::vector<int>&v)
 
 static Codec* ctor(Module*)
 {
-    return new NullRootCodec();
+    return new NullCodec();
 }
 
 static void dtor(Codec *cd)
@@ -107,7 +107,7 @@ static void dtor(Codec *cd)
     delete cd;
 }
 
-static const CodecApi null_root_api =
+static const CodecApi null_api =
 {
     {
         PT_CODEC,
@@ -129,9 +129,9 @@ static const CodecApi null_root_api =
 #ifdef BUILDING_SO
 SO_PUBLIC const BaseApi* snort_plugins[] =
 {
-    &null_root_api.base,
+    &null_api.base,
     nullptr
 };
 #else
-const BaseApi* cd_null_root = &null_root_api.base;
+const BaseApi* cd_null = &null_api.base;
 #endif
index 0258dd5a439bd8a04103d286394c282b1c670a56..062f843b8684096be795ce21387e98a4b4a895ec 100644 (file)
@@ -32,7 +32,7 @@
 namespace
 {
 
-#define CD_RAW4_NAME "codec_raw4"
+#define CD_RAW4_NAME "cd_raw4"
 
 class Raw4Codec : public Codec
 {
index 6800a1577c6cf7e415ca75b34f203198ae9643d4..38a26232a31021b8e428d80ecb06f74efc4c96d9 100644 (file)
@@ -32,7 +32,7 @@
 namespace
 {
 
-#define CD_RAW6_NAME "codec_raw6"
+#define CD_RAW6_NAME "cd_raw6"
 
 class Raw6Codec : public Codec
 {
similarity index 54%
rename from src/codecs/root/cd_trk.cc
rename to src/codecs/root/cd_tr.cc
index c9ccfa8a8abe7271f2a3d83da8ace04bbe6015c2..1828f24ccda7e7b3425f405fb5e1df7ab1b6818f 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: decode.c,v 1.285 2013-06-29 03:03:00 rcombs Exp $ */
-
 /*
 ** Copyright (C) 2002-2013 Sourcefire, Inc.
 ** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
 #include "config.h"
 #endif
 
-#include "decode.h"
+#include <pcap.h>
+#include "protocols/packet.h"
+#include "protocols/token_ring.h"
+#include "framework/codec.h"
+#include "codecs/codec_events.h"
+#include "codecs/root/cd_tr_module.h"
 
+namespace
+{
 
+class TrCodec : public Codec
+{
+public:
+    TrCodec() : Codec(CD_TR_NAME){};
+    ~TrCodec() {};
 
 
+    virtual void get_data_link_type(std::vector<int>&);
+    virtual bool decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+};
+
 
 // THESE ARE NEVER USED!!
 #define MINIMAL_TOKENRING_HEADER_LEN    22
@@ -39,7 +54,6 @@
 // DELETE FIN
 
 #define TR_ALEN             6        /* octets in an Ethernet header */
-#define IPARP_SAP           0xaa
 
 #define AC                  0x10
 #define LLC_FRAME           0x40
 #define TR_RCF_FRAME2K             0x20
 #define TR_RCF_BROADCAST_MASK      0xC000
 
-/*
- * Function: DecodeTRPkt(Packet *, char *, DAQ_PktHdr_t*, uint8_t*)
- *
- * Purpose: Decode Token Ring packets!
- *
- * Arguments: p=> pointer to decoded packet struct
- *            user => Utility pointer, unused
- *            pkthdr => ptr to the packet header
- *            pkt => pointer to the real live packet data
- *
- * Returns: void function
- */
-void DecodeTRPkt(Packet * p, const DAQ_PktHdr_t * pkthdr, const uint8_t * pkt)
+} // namespace
+
+
+void TrCodec::get_data_link_type(std::vector<int>&v)
 {
-    uint32_t cap_len = pkthdr->caplen;
-    uint32_t dataoff;      /* data offset is variable here */
-    PROFILE_VARS;
+#ifdef DLT_IEEE802
+    v.push_back(DLT_IEEE802);
+#endif
+}
 
-    PREPROC_PROFILE_START(decodePerfStats);
 
-    dc.total_processed++;
+//void DecodeTRPkt(Packet * p, const DAQ_PktHdr_t * pkthdr, const uint8_t * pkt)
+bool TrCodec::decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
+{
 
-    memset(p, 0, PKT_ZERO_LEN);
+    uint32_t cap_len = raw_len;
+    uint32_t dataoff;      /* data offset is variable here */
 
-    p->pkth = pkthdr;
-    p->pkt = pkt;
 
     DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "Packet!\n");
             DebugMessage(DEBUG_DECODE, "caplen: %lu    pktlen: %lu\n",
-                (unsigned long)cap_len,(unsigned long) pkthdr->pktlen);
+                (unsigned long)cap_len,(unsigned long) raw_len);
             );
 
-    if(cap_len < sizeof(Trh_hdr))
+    if(cap_len < sizeof(token_ring::Trh_hdr))
     {
         DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
             "Captured data length < Token Ring header length! "
             "(%d < %d bytes)\n", cap_len, TR_HLEN););
 
-        codec_events::decoder_event(p, DECODE_BAD_TRH, DECODE_BAD_TRH_STR);
-
-        PREPROC_PROFILE_END(decodePerfStats);
-        return;
+        codec_events::decoder_event(p, DECODE_BAD_TRH);
+        return false;
     }
 
     /* lay the tokenring header structure over the packet data */
-    p->trh = (Trh_hdr *) pkt;
+    //const token_ring::Trh_hdr *trh = reinterpret_cast<const token_ring::Trh_hdr *>(raw_pkt);
 
     /*
      * according to rfc 1042:
@@ -117,23 +122,21 @@ void DecodeTRPkt(Packet * p, const DAQ_PktHdr_t * pkthdr, const uint8_t * pkt)
      * first I assume that we have single-ring network with no RIF
      * information presented in frame
      */
-    if(cap_len < (sizeof(Trh_hdr) + sizeof(Trh_llc)))
+    if(cap_len < (sizeof(token_ring::Trh_hdr) + sizeof(token_ring::Trh_llc)))
     {
         DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
             "Captured data length < Token Ring header length! "
             "(%d < %d bytes)\n", cap_len,
-            (sizeof(Trh_hdr) + sizeof(Trh_llc))););
+            (sizeof(token_ring::Trh_hdr) + sizeof(token_ring::Trh_llc))););
 
-        codec_events::decoder_event(p, DECODE_BAD_TR_ETHLLC, DECODE_BAD_TR_ETHLLC_STR);
-
-        PREPROC_PROFILE_END(decodePerfStats);
-        return;
+        codec_events::decoder_event(p, DECODE_BAD_TR_ETHLLC);
+        return false;
     }
 
+    const token_ring::Trh_llc *trhllc =
+        reinterpret_cast<const token_ring::Trh_llc *>(raw_pkt + sizeof(token_ring::Trh_hdr));
 
-    p->trhllc = (Trh_llc *) (pkt + sizeof(Trh_hdr));
-
-    if(p->trhllc->dsap != IPARP_SAP && p->trhllc->ssap != IPARP_SAP)
+    if(trhllc->dsap != IPARP_SAP && trhllc->ssap != IPARP_SAP)
     {
         /*
          * DSAP != SSAP != 0xAA .. either we are having frame which doesn't
@@ -141,44 +144,39 @@ void DecodeTRPkt(Packet * p, const DAQ_PktHdr_t * pkthdr, const uint8_t * pkt)
          * lattest ...
          */
 
-        if(cap_len < (sizeof(Trh_hdr) + sizeof(Trh_llc) + sizeof(Trh_mr)))
+        if(cap_len < (sizeof(token_ring::Trh_hdr) + sizeof(token_ring::Trh_llc) + sizeof(token_ring::Trh_mr)))
         {
             DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
                 "Captured data length < Token Ring header length! "
                 "(%d < %d bytes)\n", cap_len,
-                (sizeof(Trh_hdr) + sizeof(Trh_llc) + sizeof(Trh_mr))););
+                (sizeof(token_ring::Trh_hdr) + sizeof(token_ring::Trh_llc) + sizeof(token_ring::Trh_mr))););
 
-            codec_events::decoder_event(p, DECODE_BAD_TRHMR, DECODE_BAD_TRHMR_STR);
-
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
+            codec_events::decoder_event(p, DECODE_BAD_TRHMR);
+            return false;
         }
 
-        p->trhmr = (Trh_mr *) (pkt + sizeof(Trh_hdr));
+        const token_ring::Trh_mr* trhmr =
+            reinterpret_cast<const token_ring::Trh_mr *>(raw_pkt + sizeof(token_ring::Trh_hdr));
 
 
-        if(cap_len < (sizeof(Trh_hdr) + sizeof(Trh_llc) +
-                      sizeof(Trh_mr) + TRH_MR_LEN(p->trhmr)))
+        if(cap_len < (sizeof(token_ring::Trh_hdr) + sizeof(token_ring::Trh_llc) +
+                      sizeof(token_ring::Trh_mr) + TRH_MR_LEN(trhmr)))
         {
             DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
                 "Captured data length < Token Ring header length! "
                 "(%d < %d bytes)\n", cap_len,
-                (sizeof(Trh_hdr) + sizeof(Trh_llc) + sizeof(Trh_mr))););
-
-            codec_events::decoder_event(p, DECODE_BAD_TR_MR_LEN, DECODE_BAD_TR_MR_LEN_STR);
+                (sizeof(token_ring::Trh_hdr) + sizeof(token_ring::Trh_llc) + sizeof(token_ring::Trh_mr))););
 
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
+            codec_events::decoder_event(p, DECODE_BAD_TR_MR_LEN);
+            return false;
         }
 
-        p->trhllc = (Trh_llc *) (pkt + sizeof(Trh_hdr) + TRH_MR_LEN(p->trhmr));
-        dataoff   = sizeof(Trh_hdr) + TRH_MR_LEN(p->trhmr) + sizeof(Trh_llc);
+        dataoff   = sizeof(token_ring::Trh_hdr) + TRH_MR_LEN(trhmr) + sizeof(token_ring::Trh_llc);
 
     }
     else
     {
-        p->trhllc = (Trh_llc *) (pkt + sizeof(Trh_hdr));
-        dataoff = sizeof(Trh_hdr) + sizeof(Trh_llc);
+        dataoff = sizeof(token_ring::Trh_hdr) + sizeof(token_ring::Trh_llc);
     }
 
     /*
@@ -191,49 +189,72 @@ void DecodeTRPkt(Packet * p, const DAQ_PktHdr_t * pkthdr, const uint8_t * pkt)
      * Assigned Numbers [7] (IP = 2048, ARP = 2054). .. but we would check
      * SSAP and DSAP and assume this would be enough to trust.
      */
-    if(p->trhllc->dsap != IPARP_SAP && p->trhllc->ssap != IPARP_SAP)
+    if(trhllc->dsap != IPARP_SAP && trhllc->ssap != IPARP_SAP)
     {
         DEBUG_WRAP(
                    DebugMessage(DEBUG_DECODE, "DSAP and SSAP arent set to SNAP\n");
                 );
-        p->trhllc = NULL;
-        PREPROC_PROFILE_END(decodePerfStats);
-        return;
+        return false;
     }
 
-    switch(htons(p->trhllc->ethertype))
-    {
-        case ETHERNET_TYPE_IP:
-            DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "Decoding IP\n"););
-            DecodeIP(p->pkt + dataoff, cap_len - dataoff, p);
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-
-        case ETHERNET_TYPE_ARP:
-        case ETHERNET_TYPE_REVARP:
-            DEBUG_WRAP(
-                    DebugMessage(DEBUG_DECODE, "Decoding ARP\n");
-                    );
-            dc.arp++;
-
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-
-        case ETHERNET_TYPE_8021Q:
-            DecodeVlan(p->pkt + dataoff, cap_len - dataoff, p);
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-
-        default:
-            DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "Unknown network protocol: %d\n",
-                        htons(p->trhllc->ethertype)));
-            // TBD add decoder drop event for unknown tr/eth type
-            dc.other++;
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-    }
+    lyr_len = dataoff;
+    next_prot_id = htons(trhllc->ethertype);
+    return true;
+}
 
-    PREPROC_PROFILE_END(decodePerfStats);
-    return;
+
+
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
+
+
+static Module* mod_ctor()
+{
+    return new TrCodecModule;
 }
 
+static void mod_dtor(Module* m)
+{
+    delete m;
+}
+
+static Codec* ctor(Module*)
+{
+    return new TrCodec();
+}
+
+static void dtor(Codec *cd)
+{
+    delete cd;
+}
+
+
+static const CodecApi tr_api =
+{
+    {
+        PT_CODEC,
+        CD_TR_NAME,
+        CDAPI_PLUGIN_V0,
+        0,
+        mod_ctor,
+        mod_dtor
+    },
+    nullptr,
+    nullptr,
+    nullptr,
+    nullptr,
+    ctor,
+    dtor,
+};
+
+
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+{
+    &tr_api.base,
+    nullptr
+};
+#else
+const BaseApi* cd_tr = &tr_api.base;
+#endif
diff --git a/src/codecs/root/cd_tr_module.cc b/src/codecs/root/cd_tr_module.cc
new file mode 100644 (file)
index 0000000..6aa4310
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+// cd_arp_module.cc author Josh Rosenbaum <jrosenba@cisco.com>
+
+#include "codecs/root/cd_tr_module.h"
+
+
+static const Parameter trk_params[] =
+{
+    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
+};
+
+
+static const RuleMap trk_rules[] =
+{
+    { DECODE_BAD_TRH, "(" CD_TR_NAME ") Bad Token Ring Header" },
+    { DECODE_BAD_TR_ETHLLC, "(" CD_TR_NAME ") Bad Token Ring ETHLLC Header" },
+    { DECODE_BAD_TR_MR_LEN, "(" CD_TR_NAME ") Bad Token Ring MRLENHeader" },
+    { DECODE_BAD_TRHMR, "(" CD_TR_NAME ") Bad Token Ring MR Header" },
+    { 0, nullptr }
+};
+
+//-------------------------------------------------------------------------
+// token ring module
+//-------------------------------------------------------------------------
+
+TrCodecModule::TrCodecModule() : DecodeModule(CD_TR_NAME, trk_params, trk_rules)
+{ }
+
+bool TrCodecModule::set(const char*, Value&, SnortConfig*)
+{
+    return true;
+}
similarity index 68%
rename from src/codecs/layer.h
rename to src/codecs/root/cd_tr_module.h
index 0b86f4228c09fa5e277f25856e65ba3858d6629a..fcf5dfe7136f88a27de9978bbfd2799d91c3eeaf 100644 (file)
@@ -1,6 +1,5 @@
 /*
-** Copyright (C) 2002-2013 Sourcefire, Inc.
-** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License Version 2 as
 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
 
-#ifndef LAYER_H 
-#define LAYER_H
+// cd_trk_module.h author Josh Rosenbaum <jrosenba@cisco.com>
 
-#include "codecs/sf_protocols.h"
+#ifndef CD_TRK_MODULE_H
+#define CD_TRK_MODULE_H
 
+#include "codecs/decode_module.h"
 
-struct Layer {
-    uint16_t prot_id;
-    PROTO_ID proto;
-    uint16_t length;
-    uint8_t* start;
-};
 
+#define CD_TR_NAME "cd_tr"
+
+class TrCodecModule : public DecodeModule
+{
+public:
+    TrCodecModule();
+
+    bool set(const char*, Value&, SnortConfig*);
+};
 
 #endif
diff --git a/src/codecs/root/cd_wlan.cc b/src/codecs/root/cd_wlan.cc
new file mode 100644 (file)
index 0000000..9268005
--- /dev/null
@@ -0,0 +1,262 @@
+/*
+** Copyright (C) 2002-2013 Sourcefire, Inc.
+** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pcap.h>
+#include "framework/codec.h"
+#include "codecs/root/cd_wlan_module.h"
+#include "codecs/codec_events.h"
+#include "protocols/wlan.h"
+#include "protocols/protocol_ids.h"
+#include "main/snort.h"
+
+namespace
+{
+
+
+class WlanCodec : public Codec
+{
+public:
+    WlanCodec() : Codec(CD_WLAN_NAME){};
+    ~WlanCodec() {};
+
+
+    virtual bool decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet *, uint16_t &lyr_len, uint16_t &next_prot_id);
+
+    virtual void get_data_link_type(std::vector<int>&);
+
+};
+
+struct EthLlc
+{
+    uint8_t dsap;
+    uint8_t ssap;
+} ;
+
+struct EthLlcOther
+{
+    uint8_t ctrl;
+    uint8_t org_code[3];
+    uint16_t proto_id;
+};
+
+#define MINIMAL_IEEE80211_HEADER_LEN    10    /* Ack frames and others */
+#define IEEE802_11_DATA_HDR_LEN         24    /* Header for data packets */
+
+} // namespace
+
+
+void WlanCodec::get_data_link_type(std::vector<int>&v)
+{
+#ifdef DLT_IEEE802_11
+    v.push_back(DLT_IEEE802_11);
+#endif
+}
+
+bool WlanCodec::decode(const uint8_t *raw_pkt, const uint32_t raw_len,
+        Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
+{
+    uint32_t cap_len = raw_len;
+    // reinterpret the raw data into this codec's data format
+
+
+    DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "Packet!\n"););
+    DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "caplen: %lu    pktlen: %lu\n",
+                (unsigned long)cap_len, (unsigned long)raw_len););
+
+    /* do a little validation */
+    if(cap_len < MINIMAL_IEEE80211_HEADER_LEN)
+    {
+        if (ScLogVerbose())
+        {
+            ErrorMessage("Captured data length < IEEE 802.11 header length! "
+                         "(%d bytes)\n", cap_len);
+        }
+
+        return false;
+    }
+
+    /* lay the wireless structure over the packet data */
+    const wlan::WifiHdr *wifih = reinterpret_cast<const wlan::WifiHdr *>(raw_pkt);
+
+    DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "%X   %X\n", *wifih->addr1,
+                *wifih->addr2););
+
+    /* determine frame type */
+    switch(wifih->frame_control & 0x00ff)
+    {
+        /* management frames */
+        case WLAN_TYPE_MGMT_ASREQ:
+        case WLAN_TYPE_MGMT_ASRES:
+        case WLAN_TYPE_MGMT_REREQ:
+        case WLAN_TYPE_MGMT_RERES:
+        case WLAN_TYPE_MGMT_PRREQ:
+        case WLAN_TYPE_MGMT_PRRES:
+        case WLAN_TYPE_MGMT_BEACON:
+        case WLAN_TYPE_MGMT_ATIM:
+        case WLAN_TYPE_MGMT_DIS:
+        case WLAN_TYPE_MGMT_AUTH:
+        case WLAN_TYPE_MGMT_DEAUTH:
+            break;
+
+            /* Control frames */
+        case WLAN_TYPE_CONT_PS:
+        case WLAN_TYPE_CONT_RTS:
+        case WLAN_TYPE_CONT_CTS:
+        case WLAN_TYPE_CONT_ACK:
+        case WLAN_TYPE_CONT_CFE:
+        case WLAN_TYPE_CONT_CFACK:
+            break;
+            /* Data packets without data */
+        case WLAN_TYPE_DATA_NULL:
+        case WLAN_TYPE_DATA_CFACK:
+        case WLAN_TYPE_DATA_CFPL:
+        case WLAN_TYPE_DATA_ACKPL:
+
+            break;
+        case WLAN_TYPE_DATA_DTCFACK:
+        case WLAN_TYPE_DATA_DTCFPL:
+        case WLAN_TYPE_DATA_DTACKPL:
+        case WLAN_TYPE_DATA_DATA:
+        {
+
+            if(cap_len < IEEE802_11_DATA_HDR_LEN + sizeof(EthLlc))
+            {
+                codec_events::decoder_event(p, DECODE_BAD_80211_ETHLLC);
+                return false;
+            }
+
+            const EthLlc *ehllc = reinterpret_cast<const EthLlc*>(raw_pkt + IEEE802_11_DATA_HDR_LEN);
+
+#ifdef DEBUG_MSGS
+            LogNetData((uint8_t*) ehllc, sizeof(EthLlc), NULL);
+
+            printf("LLC Header:\n");
+            printf("   DSAP: 0x%X\n", ehllc->dsap);
+            printf("   SSAP: 0x%X\n", ehllc->ssap);
+#endif
+
+            if(ehllc->dsap == ETH_DSAP_IP && ehllc->ssap == ETH_SSAP_IP)
+            {
+                if(cap_len < IEEE802_11_DATA_HDR_LEN +
+                   sizeof(EthLlc) + sizeof(EthLlcOther))
+                {
+                    codec_events::decoder_event(p, DECODE_BAD_80211_OTHER);
+                    return false;
+                }
+
+                const EthLlcOther *ehllcother = reinterpret_cast<const EthLlcOther *>(raw_pkt + IEEE802_11_DATA_HDR_LEN + sizeof(EthLlc));
+#ifdef DEBUG_MSGS
+                LogNetData((uint8_t*)ehllcother, sizeof(EthLlcOther), NULL);
+
+                printf("LLC Other Header:\n");
+                printf("   CTRL: 0x%X\n", ehllcother->ctrl);
+                printf("   ORG: 0x%02X%02X%02X\n", ehllcother->org_code[0],
+                        ehllcother->org_code[1], ehllcother->org_code[2]);
+                printf("   PROTO: 0x%04X\n", ntohs(ehllcother->proto_id));
+#endif
+                next_prot_id = ntohs(ehllcother->proto_id);
+
+                switch(ntohs(ehllcother->proto_id))
+                {
+                    case ETHERTYPE_IPV4:
+                    case ETHERTYPE_ARP:
+                    case ETHERTYPE_REVARP:
+                    case ETHERTYPE_EAPOL:
+                        lyr_len = IEEE802_11_DATA_HDR_LEN + sizeof(EthLlc) + sizeof(EthLlcOther);
+
+
+                    case ETHERTYPE_8021Q:
+                    case ETHERTYPE_IPV6:
+                        lyr_len = IEEE802_11_DATA_HDR_LEN;
+                    default:
+                        return false;
+                }
+            }
+            break;
+        }
+        default:
+            break;
+    }
+
+    return true;
+}
+
+
+
+//-------------------------------------------------------------------------
+// api
+//-------------------------------------------------------------------------
+
+static Module* mod_ctor()
+{
+    return new WlanCodecModule;
+}
+
+static void mod_dtor(Module* m)
+{
+    delete m;
+}
+
+static Codec* ctor(Module*)
+{
+    return new WlanCodec();
+}
+
+static void dtor(Codec *cd)
+{
+    delete cd;
+}
+
+
+static const CodecApi wlan_api =
+{
+    {
+        PT_CODEC,
+        CD_WLAN_NAME,
+        CDAPI_PLUGIN_V0,
+        0,
+        mod_ctor,
+        mod_dtor
+    },
+    nullptr,
+    nullptr,
+    nullptr,
+    nullptr,
+    ctor,
+    dtor,
+};
+
+
+#ifdef BUILDING_SO
+SO_PUBLIC const BaseApi* snort_plugins[] =
+{
+    &wlan_api.base,
+    nullptr
+};
+#else
+const BaseApi* cd_wlan = &wlan_api.base;
+#endif
diff --git a/src/codecs/root/cd_wlan_module.cc b/src/codecs/root/cd_wlan_module.cc
new file mode 100644 (file)
index 0000000..6d9cd0a
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+// cd_ieee8021_module.cc author Josh Rosenbaum <jrosenba@cisco.com>
+
+#include "codecs/root/cd_wlan_module.h"
+
+
+static const Parameter wifi_params[] =
+{
+    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
+};
+
+
+static const RuleMap wifi_rules[] =
+{
+    { DECODE_BAD_80211_ETHLLC, "(" CD_WLAN_NAME ") Bad 802.11 LLC header" },
+    { DECODE_BAD_80211_OTHER, "(" CD_WLAN_NAME ") Bad 802.11 Extra LLC Info" },
+    { 0, nullptr }
+};
+
+//-------------------------------------------------------------------------
+// wifi module
+//-------------------------------------------------------------------------
+
+WlanCodecModule::WlanCodecModule() : DecodeModule(CD_WLAN_NAME, wifi_params, wifi_rules)
+{ }
+
+bool WlanCodecModule::set(const char*, Value&, SnortConfig*)
+{
+    return true;
+}
diff --git a/src/codecs/root/cd_wlan_module.h b/src/codecs/root/cd_wlan_module.h
new file mode 100644 (file)
index 0000000..554707b
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+// cd_wlan_module.h author Josh Rosenbaum <jrosenba@cisco.com>
+
+#ifndef CD_WLAN_MODULE_H
+#define CD_WLAN_MODULE_H
+
+#include "codecs/decode_module.h"
+
+
+#define CD_WLAN_NAME "cd_wlan"
+
+class WlanCodecModule : public DecodeModule
+{
+public:
+    WlanCodecModule();
+
+    bool set(const char*, Value&, SnortConfig*);
+};
+
+#endif
index 9fa1918c362032295c66b9c800e1c3db952cbbd6..fd2a040f3b8656dc56efed7699f13327f2cda180 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id: decode.c,v 1.285 2013-06-29 03:03:00 rcombs Exp $ */
-
 /*
 ** Copyright (C) 2002-2013 Sourcefire, Inc.
 ** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
@@ -27,7 +25,7 @@
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 #include "decoder_includes.h"
 
@@ -49,26 +47,28 @@ static const uint16_t ETHERNET_TYPE_IPX = 0x8137;
 void DecodeIPX(const uint8_t*, uint32_t, Packet *p)
 {
     DEBUG_WRAP(DebugMessage(DEBUG_DECODE, "IPX is not supported.\n"););
-
     dc.ipx++;
-
-    if (p->greh != NULL)
-        dc.gre_ipx++;
 }
 
 static const char* name = "ipx_decode";
 
 static const CodecApi ipx_api =
 {
-    { PT_CODEC, name, CDAPI_PLUGIN_V0, 0 },
+    {
+        PT_CODEC,
+        name,
+        CDAPI_PLUGIN_V0,
+        0,
+        nullptr,
+        nullptr,
+    },
     {ETHERNET_TYPE_IPX},  
-    NULL, // pinit
-    NULL, // pterm
-    NULL, // tinit
-    NULL, // tterm
-    NULL, // ctor
-    NULL, // dtor
-    Ipx::Decode,
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
+    ctor, // ctor
+    dtor, // dtor
 };
 
 
index 6a3da239b3b45bd26985d070cc638711c8375a87..891aacd82a9eb18edb096139c9191d0db3a8479c 100644 (file)
@@ -27,7 +27,7 @@
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 
 #include "root_chdlc.h"
index 3a8006afc2ba8e6a51126894c7d7fed1b02ffd04..d7ff85c2bd21c935849f95b0ae4f2f3780990b22 100644 (file)
@@ -27,7 +27,7 @@
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 
 #include "root_enc.h"
index 9cbc5dc67b6426a33fa80b7fd3483dbe67f1f871..ff8086bccefa38efb1b5c530942dcc5ae5d255b6 100644 (file)
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 
 #include "../decoder_includes.h"
 
 
+anonymous
+{
+
+/* FDDI header is always this: -worm5er */
+struct Fddi_hdr
+{
+    uint8_t fc;        /* frame control field */
+    uint8_t daddr[FDDI_ALEN];  /* src address */
+    uint8_t saddr[FDDI_ALEN];  /* dst address */
+}         Fddi_hdr;
+
+/* splitting the llc up because of variable lengths of the LLC -worm5er */
+struct Fddi_llc_saps
+{
+    uint8_t dsap;
+    uint8_t ssap;
+}              Fddi_llc_saps;
+
+/* I've found sna frames have two addition bytes after the llc saps -worm5er */
+struct Fddi_llc_sna
+{
+    uint8_t ctrl_fld[2];
+}             Fddi_llc_sna;
+
+/* I've also found other frames that seem to have only one byte...  We're only
+really intersted in the IP data so, until we want other, I'm going to say
+the data is one byte beyond this frame...  -worm5er */
+struct Fddi_llc_other
+{
+    uint8_t ctrl_fld[1];
+}               Fddi_llc_other;
+
+/* Just like TR the ip/arp data is setup as such: -worm5er */
+struct Fddi_llc_iparp
+{
+    uint8_t ctrl_fld;
+    uint8_t protid[3];
+    uint16_t ethertype;
+}               Fddi_llc_iparp;
+
+} // anonymous
+
 /*
  * Function: DecodeFDDIPkt(Packet *, char *, DAQ_PktHdr_t*, uint8_t*)
  *
@@ -49,16 +91,8 @@ void DecodeFDDIPkt(Packet * p, const DAQ_PktHdr_t * pkthdr, const uint8_t * pkt)
 {
     uint32_t cap_len = pkthdr->caplen;
     uint32_t dataoff = sizeof(Fddi_hdr) + sizeof(Fddi_llc_saps);
-    PROFILE_VARS;
-
-    PREPROC_PROFILE_START(decodePerfStats);
-
-    dc.total_processed++;
 
-    memset(p, 0, PKT_ZERO_LEN);
 
-    p->pkth = pkthdr;
-    p->pkt = pkt;
 
     DEBUG_WRAP(DebugMessage(DEBUG_DECODE,"Packet!\n");
             DebugMessage(DEBUG_DECODE, "caplen: %lu    pktlen: %lu\n",
index 0e8454345d1370b2c7668c366c6c2e652b92e282..314e729b085dccf844ce10a8aed2867c50dac29b 100644 (file)
@@ -27,7 +27,7 @@
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 
 #include "root_i4lciscoip.h"
index 9ba11fb6f946d940cdcf5573f46922743691b6bd..38a9f3ccce09f7096cb1c89976b4d1a4bd1ce458 100644 (file)
@@ -27,7 +27,7 @@
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 
 #include "root_i4lrawip.h"
diff --git a/src/codecs/root/root_linuxsll.cc b/src/codecs/root/root_linuxsll.cc
deleted file mode 100644 (file)
index 3cf38ea..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/* $Id: decode.c,v 1.285 2013-06-29 03:03:00 rcombs Exp $ */
-
-/*
-** Copyright (C) 2002-2013 Sourcefire, Inc.
-** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License Version 2 as
-** published by the Free Software Foundation.  You may not use, modify or
-** distribute this program under any other version of the GNU General
-** Public License.
-**
-** 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.
-*/
-
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "generators.h"
-#include "decode.h"  
-#include "static_include.h"
-
-
-#include "../decoder_includes.h"
-
-
-#ifdef DLT_LINUX_SLL  // WHERE IS THIS DEFINED!!
-
-
-/*
- * Function: DecodeLinuxSLLPkt(Packet *, char *, DAQ_PktHdr_t*, uint8_t*)
- *
- * Purpose: Decode those fun loving LinuxSLL (linux cooked sockets)
- *          packets, one at a time!
- *
- * Arguments: p => pointer to the decoded packet struct
- *            user => Utility pointer (unused)
- *            pkthdr => ptr to the packet header
- *            pkt => pointer to the real live packet data
- *
- * Returns: void function
- */
-
-void DecodeLinuxSLLPkt(Packet * p, const DAQ_PktHdr_t * pkthdr, const uint8_t * pkt)
-{
-    uint32_t cap_len = pkthdr->caplen;
-    PROFILE_VARS;
-
-    PREPROC_PROFILE_START(decodePerfStats);
-
-    dc.total_processed++;
-
-    memset(p, 0, PKT_ZERO_LEN);
-
-    p->pkth = pkthdr;
-    p->pkt = pkt;
-
-    DEBUG_WRAP(DebugMessage(DEBUG_DECODE,"Packet!\n");
-            DebugMessage(DEBUG_DECODE, "caplen: %lu    pktlen: %lu\n",
-                (unsigned long)cap_len, (unsigned long)pkthdr->pktlen););
-
-    /* do a little validation */
-    if(cap_len < SLL_HDR_LEN)
-    {
-        if (ScLogVerbose())
-        {
-            ErrorMessage("Captured data length < SLL header length (your "
-                         "libpcap is broken?)! (%d bytes)\n", cap_len);
-        }
-        PREPROC_PROFILE_END(decodePerfStats);
-        return;
-    }
-    /* lay the ethernet structure over the packet data */
-    p->sllh = (SLLHdr *) pkt;
-
-    /* grab out the network type */
-    switch(ntohs(p->sllh->sll_protocol))
-    {
-        case ETHERNET_TYPE_IP:
-            DEBUG_WRAP(DebugMessage(DEBUG_DECODE,
-                        "IP datagram size calculated to be %lu bytes\n",
-                        (unsigned long)(cap_len - SLL_HDR_LEN)););
-
-            DecodeIP(p->pkt + SLL_HDR_LEN, cap_len - SLL_HDR_LEN, p);
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-
-        case ETHERNET_TYPE_ARP:
-        case ETHERNET_TYPE_REVARP:
-            DecodeARP(p->pkt + SLL_HDR_LEN, cap_len - SLL_HDR_LEN, p);
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-
-        case ETHERNET_TYPE_IPV6:
-            DecodeIPV6(p->pkt + SLL_HDR_LEN, (cap_len - SLL_HDR_LEN), p);
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-
-        case ETHERNET_TYPE_IPX:
-            DecodeIPX(p->pkt + SLL_HDR_LEN, (cap_len - SLL_HDR_LEN), p);
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-
-        case LINUX_SLL_P_802_3:
-            DEBUG_WRAP(DebugMessage(DEBUG_DATALINK,
-                        "Linux SLL P 802.3 is not supported.\n"););
-            // TBD add decoder drop event for unsupported linux sll p 802.3
-            dc.other++;
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-
-        case LINUX_SLL_P_802_2:
-            DEBUG_WRAP(DebugMessage(DEBUG_DATALINK,
-                        "Linux SLL P 802.2 is not supported.\n"););
-            // TBD add decoder drop event for unsupported linux sll p 802.2
-            dc.other++;
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-
-        case ETHERNET_TYPE_8021Q:
-            DecodeVlan(p->pkt + SLL_HDR_LEN, cap_len - SLL_HDR_LEN, p);
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-
-        default:
-            /* shouldn't go here unless pcap library changes again */
-            /* should be a DECODE generated alert */
-            DEBUG_WRAP(DebugMessage(DEBUG_DATALINK,"(Unknown) %X is not supported. "
-                        "(need tcpdump snapshots to test. Please contact us)\n",
-                        p->sllh->sll_protocol););
-            // TBD add decoder drop event for unknown sll encapsulation
-            dc.other++;
-            PREPROC_PROFILE_END(decodePerfStats);
-            return;
-    }
-
-    PREPROC_PROFILE_END(decodePerfStats);
-    return;
-}
-#endif /* DLT_LINUX_SLL */
-
index 34a2f83f4cec2f82fcabf779455de322b6ab2c04..a929ba3daaa6ebe64e0ad88a5b25e2c2aee492df 100644 (file)
@@ -27,7 +27,7 @@
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 
 #include "root_oldpflog.h"
index ebd6f9947e2f729f7131797bb386d25bd823cabe..793dae31aed597a22b806edf3bdb88b31f2618a4 100644 (file)
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 
 #include "root_pflog.h"
 #include "../decoder_includes.h"
 
+namespace
+{
+
+
+/*
+ * Snort supports 3 versions of the OpenBSD pflog header:
+ *
+ * Pflog1_Hdr:  CVS = 1.3,  DLT_OLD_PFLOG = 17,  Length = 28
+ * Pflog2_Hdr:  CVS = 1.8,  DLT_PFLOG     = 117, Length = 48
+ * Pflog3_Hdr:  CVS = 1.12, DLT_PFLOG     = 117, Length = 64
+ * Pflog3_Hdr:  CVS = 1.172, DLT_PFLOG     = 117, Length = 100
+ *
+ * Since they have the same DLT, Pflog{2,3}Hdr are distinguished
+ * by their actual length.  The minimum required length excludes
+ * padding.
+ */
+/* Old OpenBSD pf firewall pflog0 header
+ * (information from pf source in kernel)
+ * the rule, reason, and action codes tell why the firewall dropped it -fleck
+ */
+
+struct Pflog1Hdr
+{
+    uint32_t af;
+    char intf[IFNAMSIZ];
+    int16_t rule;
+    uint16_t reason;
+    uint16_t action;
+    uint16_t dir;
+};
+
+#define PFLOG1_HDRLEN (sizeof(struct _Pflog1_hdr))
+
+/*
+ * Note that on OpenBSD, af type is sa_family_t. On linux, that's an unsigned
+ * short, but on OpenBSD, that's a uint8_t, so we should explicitly use uint8_t
+ * here.  - ronaldo
+ */
+
+#define PFLOG_RULELEN 16
+#define PFLOG_PADLEN  3
+
+struct Pflog2Hdr
+{
+    int8_t   length;
+    uint8_t  af;
+    uint8_t  action;
+    uint8_t  reason;
+    char     ifname[IFNAMSIZ];
+    char     ruleset[PFLOG_RULELEN];
+    uint32_t rulenr;
+    uint32_t subrulenr;
+    uint8_t  dir;
+    uint8_t  pad[PFLOG_PADLEN];
+} ;
+
+#define PFLOG2_HDRLEN (sizeof(struct _Pflog2_hdr))
+#define PFLOG2_HDRMIN (PFLOG2_HDRLEN - PFLOG_PADLEN)
+
+struct Pflog3Hdr
+{
+    int8_t   length;
+    uint8_t  af;
+    uint8_t  action;
+    uint8_t  reason;
+    char     ifname[IFNAMSIZ];
+    char     ruleset[PFLOG_RULELEN];
+    uint32_t rulenr;
+    uint32_t subrulenr;
+    uint32_t uid;
+    uint32_t pid;
+    uint32_t rule_uid;
+    uint32_t rule_pid;
+    uint8_t  dir;
+    uint8_t  pad[PFLOG_PADLEN];
+};
+
+#define PFLOG3_HDRLEN (sizeof(struct _Pflog3_hdr))
+#define PFLOG3_HDRMIN (PFLOG3_HDRLEN - PFLOG_PADLEN)
+
+
+struct Pflog4Hdr
+{
+    uint8_t  length;
+    uint8_t  af;
+    uint8_t  action;
+    uint8_t  reason;
+    char     ifname[IFNAMSIZ];
+    char     ruleset[PFLOG_RULELEN];
+    uint32_t rulenr;
+    uint32_t subrulenr;
+    uint32_t uid;
+    uint32_t pid;
+    uint32_t rule_uid;
+    uint32_t rule_pid;
+    uint8_t  dir;
+    uint8_t  rewritten;
+    uint8_t  pad[2];
+    uint8_t saddr[16];
+    uint8_t daddr[16];
+    uint16_t sport;
+    uint16_t dport;
+};
+
+#define PFLOG4_HDRLEN sizeof(struct _Pflog4_hdr)
+#define PFLOG4_HDRMIN sizeof(struct _Pflog4_hdr)
+
+} // namespace
 
 /*
  * Function: DecodePflog(Packet *, DAQ_PktHdr_t *, uint8_t *)
index 8496a25b4b788f7ed49d23b2ed86ae916b421996..ad93a5d2c9c29c4356b7359f5123768249f1afe2 100644 (file)
@@ -27,7 +27,7 @@
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 
 #include "root_ppp.h"
index e04f6c08e9fd45a1c35316e0ce1ea7901b9b827d..bca0cbdf3e84d03b18b17e0e516cbc873c5e5f66 100644 (file)
@@ -27,7 +27,7 @@
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 
 #include "root_pppserial.h"
index de2359a0b866de0824467a65248d815e783cd100..f1078e5a95902b809d3d6bb895357922e52f6cfd 100644 (file)
@@ -27,7 +27,7 @@
 #endif
 
 #include "generators.h"
-#include "decode.h"  
+#include "protocols/packet.h"  
 #include "static_include.h"
 
 #include "root_slip.h"
index 445db72c35539c218a4316af49d43a129b21fa59..3841fea721050e0cac9a240bcd809e17030073a7 100644 (file)
@@ -80,7 +80,7 @@ void NameCodec::get_protocol_ids(std::vector<uint16_t>& v)
 //    v.push_back(PROTO_TYPE);
 }
 
-bool NameCodec::decode(const uint8_t *raw_pkt, const uint32_t raw_len, 
+bool NameCodec::decode(const uint8_t *raw_pkt, const uint32_t raw_len,
         Packet *p, uint16_t &lyr_len, uint16_t &next_prot_id)
 {
     // reinterpret the raw data into this codec's data format
index a30651f5997d50e43ab5a6d22816dcb78b0f28fc..07ba0f8f73578bb584d013b12645656712941911 100644 (file)
@@ -28,7 +28,7 @@
 #endif
 
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "rules.h"
 #include "treenodes.h"
 #include "parser.h"
index 5fb59f46b031c3a8b101766f01e627ad48afeeec..6713c45de146e6d7e4e82d04ca9ff6aae406b1fa 100644 (file)
@@ -33,7 +33,7 @@
 #endif
 
 #include "snort_types.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "detect.h"
 #include "snort.h"
 #include "snort_debug.h"
index 4634c85a8dc066e9f4c35dc9fc00c4bf5eeef44c..1724f98c311f6aba54a475102c341dff34195592 100644 (file)
@@ -1556,30 +1556,6 @@ int fpEvalPacket(Packet *p)
     return fpEvalHeaderIp(p, ip_proto, omd);
 }
 
-void fpEvalIpProtoOnlyRules(SF_LIST **ip_proto_only_lists, Packet *p)
-{
-    if ((p != NULL) && IPH_IS_VALID(p))
-    {
-        SF_LIST *l = ip_proto_only_lists[GET_IPH_PROTO(p)];
-        OptTreeNode *otn;
-
-        /* If list is NULL, sflist_first returns NULL */
-        for (otn = (OptTreeNode *)sflist_first(l);
-             otn != NULL;
-             otn = (OptTreeNode *)sflist_next(l))
-        {
-            if (fpEvalRTN(getRuntimeRtnFromOtn(otn), p, 0))
-            {
-                if ( SnortEventqAdd(otn) )
-                    pc.queue_limit++;
-
-                if ( pass_action(getRuntimeRtnFromOtn(otn)->type) )
-                    p->packet_flags |= PKT_PASS_RULE;
-            }
-        }
-    }
-}
-
 void fpEvalIpProtoOnlyRules(SF_LIST **ip_proto_only_lists, Packet *p, uint8_t proto_id)
 {
     if ((p != NULL) && IPH_IS_VALID(p))
index eba733ddac16df866ded5a8dd13b2924dc4157c0..5b97beb5e16631d3891d979ebe77e77f17f91483 100644 (file)
@@ -36,7 +36,7 @@
 
 #include "fpcreate.h"
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "sflsq.h"
 #include "time/profiler.h"
 
@@ -103,7 +103,6 @@ void otnx_match_data_init(int);
 void otnx_match_data_term();
 
 int fpAddMatch( OTNX_MATCH_DATA *omd_local, int pLen, OptTreeNode *otn);
-void fpEvalIpProtoOnlyRules(SF_LIST **, Packet *);
 void fpEvalIpProtoOnlyRules(SF_LIST **, Packet *, uint8_t proto_id);
 OptTreeNode * GetOTN(uint32_t gid, uint32_t sid);
 
index 766cf87d89926c7bdc82da83745314d39f03bc0f..ce565e146ff87faef3f4794673e22ba9b50d9dc4 100644 (file)
@@ -30,8 +30,8 @@
 #ifndef PCRM_H
 #define PCRM_H
 
-#include "decode.h"
 #include "bitop.h"
+#include "protocols/packet.h"
 
 typedef void * RULE_PTR;
 
index 15faa0ee2769db08abb37a2d108d374a922c23e8..2ce175367ffedd66e5fe53f0466c20ee9f667742 100644 (file)
@@ -28,7 +28,7 @@
 #include <string.h>
 #include <ctype.h>
 
-#include "decode.h"
+#include "protocols/packet.h"
 #include "rules.h"
 #include "treenodes.h"
 #include "snort_debug.h"
index 7695a3dac82201e04889b683c3217275db79bf90..d0504b0304a2c0235b709f77619a211c99d9989e 100644 (file)
@@ -29,7 +29,7 @@
 #include "rules.h"
 #include "treenodes.h"
 #include "event.h"
-#include "decode.h"
+#include "protocols/packet.h"
 
 
 #define TAG_SESSION   1
index 0e00eb64d8754ed7adf6c9937f6f7aa83e72ac08..7cddfc9b5935f6042d01bd1cb1c6e7a9c2851b37 100644 (file)
@@ -34,7 +34,7 @@
 #include "snort_bounds.h"
 #include "util.h"
 #include "search_engines/str_search.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "detection_util.h"
 
 MimePcre mime_boundary_pcre;
index 0ddf2c18f91c51a2468a52353636e1e15bd94414..3fd5108dfad5c07fe89d5c50bf05e752ebac922d 100644 (file)
@@ -32,7 +32,7 @@
 #include "ipv6_port.h"
 #include "sfxhash.h"
 #include "util.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "packet_io/active.h"
 #include "libs/file_sha256.h"
 
index 474ddc7a919c216eb8adc3596803d2e6f1e7e1ea..6df4933bc58a9369a9d406e865f108a91db0c077 100644 (file)
@@ -27,7 +27,7 @@
 #ifndef FILE_RESUME_BLOCK_H
 #define FILE_RESUME_BLOCK_H
 
-#include "decode.h"
+#include "protocols/packet.h"
 #include "file_api.h"
 
 void file_resume_block_init(void);
index 2162001e8d526c8fad2cfa62e875aff9efc4283c..b84aeb0b6b13cf4f40b8c855cdfa80243cb300c5 100644 (file)
@@ -32,7 +32,7 @@
 /* @ingroup rate_filter
  * @{
  */
-#include "decode.h"
+#include "protocols/packet.h"
 #include "rules.h"
 #include "treenodes.h"
 #include "filters/sfrf.h"
index 95690e22567d9fdf6a1e4788ddd85071b7f21e63..e85309437069f3a91c9d68dac353d95c19793aac 100644 (file)
@@ -17,9 +17,10 @@ add_library ( flow STATIC
     session.h
 )
 
-set_target_properties(flow
-    PROPERTIES
-    COMPILE_FLAGS "-fvisibility=default"
+set_default_visibility_compile_flag(flow)
+
+target_link_libraries(flow
+    protocols
 )
 
 install(FILES ${FLOW_INCLUDES}
index 66aefa7a7945ce19d0ac42f1a1cd59215801f57a..909ba3091e457683fa35df14a6c7486657cc3f55 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef EXPECT_CACHE_H
 #define EXPECT_CACHE_H
 
-#include "decode.h"
+#include "protocols/packet.h"
 #include "ipv6_port.h"
 
 class FlowData;
index 44df859a136d0cb3fd33195688ccd16a6cee00e7..63a3c5d774e479a3f814d828f49291082bacd69b 100644 (file)
@@ -30,7 +30,7 @@
 #include "ips_options/ips_flowbits.h"
 #include "utils/bitop_funcs.h"
 #include "utils/util.h"
-#include "protocols/decode.h"
+#include "protocols/packet.h"
 
 unsigned FlowData:: flow_id = 0;
 
index 802aaee6872a5cea27e9a48b0e8671fb368cdb9d..621eeb3a7301c297583f694c11aa1552aa8089f0 100644 (file)
@@ -34,6 +34,8 @@
 #include "packet_io/sfdaq.h"
 #include "main/binder.h"
 #include "utils/stats.h"
+#include "protocols/layer.h"
+#include "protocols/vlan.h"
 
 FlowControl::FlowControl()
 {
@@ -212,12 +214,12 @@ void FlowControl::set_key(FlowKey* key, const Packet* p)
     uint16_t vlanId;
     uint16_t addressSpaceId;
 
-    if ( p->vh )
-        vlanId = (uint16_t)VTH_VLAN(p->vh);
+    if ( p->proto_bits & PROTO_BIT__VLAN )
+        vlanId = vlan::vth_vlan(layer::get_vlan_layer(p));
     else
         vlanId = 0;
 
-    if ( p->mpls )
+    if ( p->proto_bits & PROTO_BIT__MPLS )
         mplsId = p->mplsHdr.label;
     else
         mplsId = 0;
index 855384593cbb7f40e3dd471873fc48827b20b0db..cbb9127ca6653e80a027e2f318e2121ac6e4f3f8 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 #endif
 
-#include "protocols/decode.h"
+#include "protocols/packet.h"
 #include "snort.h"
 #include "utils/util.h"
 
@@ -117,9 +117,9 @@ inline void FlowKey::init6(
     }
     else if ( proto == IPPROTO_ICMPV6 )
     {
-        if (srcPort == ICMP6_REPLY)
+        if (srcPort == icmp6::Icmp6Types::REPLY)
         {
-            dstPort = ICMP6_ECHO; /* Treat ICMPv6 echo reply the same as request */
+            dstPort = icmp6::Icmp6Types::ECHO; /* Treat ICMPv6 echo reply the same as request */
             srcPort = 0;
         }
         else /* otherwise, every ICMP type gets different key */
index 28b22320fe191da5bcbc95a322cc245434ae2c3f..8eb8371d59ea80a2e9fc9fc50d868a746541de58 100644 (file)
 #define CODEC_H
 
 #include <vector>
+#include <cstdint>
 
 #include "snort_types.h"
 #include "framework/base_api.h"
+#include "codecs/sf_protocols.h"
+#include "protocols/icmp4.h"
 #include "packet.h"
 
-
-// REMOVE WHEN POSSIBLE!!!
-
-
+struct Packet;
 struct Layer;
 
-typedef enum {
-    ENC_TCP_FIN,  ENC_TCP_RST,
-    ENC_UNR_NET,  ENC_UNR_HOST,
-    ENC_UNR_PORT, ENC_UNR_FW,
+enum EncodeType{
+    ENC_TCP_FIN,
+    ENC_TCP_RST,
+    ENC_UNR_NET,
+    ENC_UNR_HOST,
+    ENC_UNR_PORT,
+    ENC_UNR_FW,
     ENC_TCP_PUSH,
     ENC_MAX
-} EncodeType;
-
-#define ENC_FLAG_FWD 0x80000000  // send in forward direction
-#define ENC_FLAG_SEQ 0x40000000  // VAL bits contain seq adj
-#define ENC_FLAG_ID  0x20000000  // use randomized IP ID
-#define ENC_FLAG_NET 0x10000000  // stop after innermost network (ip4/6) layer
-#define ENC_FLAG_DEF 0x08000000  // stop before innermost ip4 opts or ip6 frag header
-#define ENC_FLAG_RAW 0x04000000  // don't encode outer eth header (this is raw ip)
-#define ENC_FLAG_RES 0x03000000  // bits reserved for future use
-#define ENC_FLAG_VAL 0x00FFFFFF  // bits for adjusting seq and/or ack
-const uint8_t MIN_TTL = 64;
-const uint8_t MAX_TTL = 255;
+};
+
 
 typedef uint32_t EncodeFlags;
+const uint32_t ENC_FLAG_FWD = 0x80000000;  // send in forward direction
+const uint32_t ENC_FLAG_SEQ = 0x40000000;  // VAL bits contain seq adj
+const uint32_t ENC_FLAG_ID  = 0x20000000;  // use randomized IP ID
+const uint32_t ENC_FLAG_NET = 0x10000000;  // stop after innermost network (ip4/6) layer
+const uint32_t ENC_FLAG_DEF = 0x08000000;  // stop before innermost ip4 opts or ip6 frag header
+const uint32_t ENC_FLAG_RAW = 0x04000000;  // don't encode outer eth header (this is raw ip)
+const uint32_t ENC_FLAG_RES = 0x03000000;  // bits reserved for future use
+const uint32_t ENC_FLAG_VAL = 0x00FFFFFF;  // bits for adjusting seq and/or ack
+
 
-typedef struct {
+struct EncState{
     EncodeType type;
     EncodeFlags flags;
 
@@ -65,8 +67,7 @@ typedef struct {
     const uint8_t* payLoad;
     uint32_t payLen;
     uint8_t proto;
-
-} EncState;
+};
 
 
 // Copied from dnet/blob.h
@@ -81,22 +82,7 @@ struct Buffer {
 };
 
 
-static inline bool forward(const EncState *e)
-{
-    return e->flags & ENC_FLAG_FWD;
-}
-
-static inline bool reverse(const EncodeFlags f)
-{
-    return !(f & ENC_FLAG_FWD);
-}
-
-static inline uint16_t get_decoded_length(EncState *enc)
-{
-    return enc->p->layers[enc->layer-1].length;
-}
-
-// Update's the buffer to contain an additional 
+// Update's the buffer to contain an additional
 static inline bool update_buffer(Buffer* buf, size_t n)
 {
     if ( buf->end + n > (unsigned int)buf->size )
@@ -110,8 +96,6 @@ static inline bool update_buffer(Buffer* buf, size_t n)
 }
 
 
-
-
 class Codec
 {
 public:
@@ -155,9 +139,8 @@ public:
     virtual bool update(Packet*, Layer*, uint32_t* /*len*/) { return true; };
     // formatter
     virtual void format(EncodeFlags, const Packet* /*orig*/, Packet* /*clone*/, Layer*) {};
-
-    // DELETE
-    virtual inline PROTO_ID get_proto_id() { return PROTO_AH; };
+    // used for backwards compatability.
+    virtual PROTO_ID get_proto_id() { return PROTO_AH; };
 
 
 protected:
@@ -167,12 +150,29 @@ protected:
     };
 
 
-    inline uint8_t buff_diff(Buffer *buf, uint8_t* ho)
+    static inline bool forward(const EncState *e)
+    {
+        return e->flags & ENC_FLAG_FWD;
+    }
+
+    static inline bool reverse(const EncodeFlags f)
+    {
+        return !(f & ENC_FLAG_FWD);
+    }
+
+    static inline uint16_t get_decoded_length(EncState *enc)
+    {
+        return enc->p->layers[enc->layer-1].length;
+    }
+
+
+    static inline uint8_t buff_diff(Buffer *buf, uint8_t* ho)
     {
         return ((uint8_t*)(buf->base+buf->end)-(uint8_t*)ho);
     }
 
-    inline icmp4::IcmpCode get_icmp_code (EncodeType et) {
+    static inline icmp4::IcmpCode get_icmp_code (EncodeType et)
+    {
         switch ( et ) {
             case EncodeType::ENC_UNR_NET:  return icmp4::IcmpCode::NET_UNREACH;
             case EncodeType::ENC_UNR_HOST: return icmp4::IcmpCode::HOST_UNREACH;
@@ -183,6 +183,7 @@ protected:
     }
 
 
+
 private:
     const char* name;
 };
index 91b1dc7bff043009aeaaea4327b95d0a874e79ba..668e0114c9352492c81365b00b2d77cb14d5b360 100644 (file)
@@ -57,7 +57,7 @@ int byte_extract(int endianess, int bytes_to_grab, const uint8_t *ptr,
                  const uint8_t *start, const uint8_t *end,
                  uint32_t *value)
 {
-    if(endianess != LITTLE && endianess != BIG)
+    if(endianess != ENDIAN_LITTLE && endianess != ENDIAN_BIG)
     {
         /* we only support 2 byte formats */
         return -2;
@@ -84,7 +84,7 @@ int byte_extract(int endianess, int bytes_to_grab, const uint8_t *ptr,
             *value =  (*ptr) & 0xFF;
             break;
         case 2:
-            if(endianess == LITTLE)
+            if(endianess == ENDIAN_LITTLE)
             {
                 *value = (*ptr) & 0xFF;
                 *value |= (*(ptr + 1) & 0xFF) << 8;
@@ -96,7 +96,7 @@ int byte_extract(int endianess, int bytes_to_grab, const uint8_t *ptr,
             }
             break;
         case 3:
-            if (endianess == LITTLE)
+            if (endianess == ENDIAN_LITTLE)
             {
                 *value = (*ptr) & 0xFF;
                 *value |= ((*(ptr + 1)) & 0xFF) << 8;
@@ -110,7 +110,7 @@ int byte_extract(int endianess, int bytes_to_grab, const uint8_t *ptr,
             }
             break;
         case 4:
-            if(endianess == LITTLE)
+            if(endianess == ENDIAN_LITTLE)
             {
                 *value = (*ptr) & 0xFF;
                 *value |= ((*(ptr + 1)) & 0xFF) << 8;
@@ -214,7 +214,7 @@ void test_extract(void)
     value3[2] = 0x00;
     value3[3] = 0x00;
 
-    if(byte_extract(BIG, 2, value1, value1, value1 + 2, &ret))
+    if(byte_extract(ENDIAN_BIG, 2, value1, value1, value1 + 2, &ret))
     {
         printf("test 1 failed\n");
     }
@@ -223,7 +223,7 @@ void test_extract(void)
         printf("test 1: value: %x %u\n", ret, ret);
     }
 
-    if(byte_extract(LITTLE, 2, value1, value1, value1 + 2, &ret))
+    if(byte_extract(ENDIAN_LITTLE, 2, value1, value1, value1 + 2, &ret))
     {
         printf("test 2 failed\n");
     }
@@ -233,7 +233,7 @@ void test_extract(void)
     }
 
 
-    if(byte_extract(LITTLE, 2, value1 + 2, value1, value1 + 2, &ret))
+    if(byte_extract(ENDIAN_LITTLE, 2, value1 + 2, value1, value1 + 2, &ret))
     {
         printf("test 3 failed correctly\n");
     }
@@ -243,7 +243,7 @@ void test_extract(void)
     }
 
 
-    if(byte_extract(BIG, 2, value2, value2, value2 + 2, &ret))
+    if(byte_extract(ENDIAN_BIG, 2, value2, value2, value2 + 2, &ret))
     {
         printf("test 1 failed\n");
     }
@@ -252,7 +252,7 @@ void test_extract(void)
         printf("test 1: value: %x %u\n", ret, ret);
     }
 
-    if(byte_extract(LITTLE, 2, value2, value2, value2 + 2, &ret))
+    if(byte_extract(ENDIAN_LITTLE, 2, value2, value2, value2 + 2, &ret))
     {
         printf("test 2 failed\n");
     }
@@ -262,7 +262,7 @@ void test_extract(void)
     }
 
 
-    if(byte_extract(LITTLE, 2, value2 + 2, value2, value2 + 2, &ret))
+    if(byte_extract(ENDIAN_LITTLE, 2, value2 + 2, value2, value2 + 2, &ret))
     {
         printf("test 3 failed correctly\n");
     }
@@ -272,7 +272,7 @@ void test_extract(void)
     }
 
 
-    if(byte_extract(BIG, 4, value3, value3, value3 + 4, &ret))
+    if(byte_extract(ENDIAN_BIG, 4, value3, value3, value3 + 4, &ret))
     {
         printf("test 1 failed\n");
     }
@@ -281,7 +281,7 @@ void test_extract(void)
         printf("test 1: value: %x %u\n", ret, ret);
     }
 
-    if(byte_extract(LITTLE, 4, value3, value3, value3 + 4, &ret))
+    if(byte_extract(ENDIAN_LITTLE, 4, value3, value3, value3 + 4, &ret))
     {
         printf("test 2 failed\n");
     }
@@ -291,7 +291,7 @@ void test_extract(void)
     }
 
 
-    if(byte_extract(LITTLE, 4, value3 + 2, value3, value3 + 4, &ret))
+    if(byte_extract(ENDIAN_LITTLE, 4, value3 + 2, value3, value3 + 4, &ret))
     {
         printf("test 3 failed correctly\n");
     }
@@ -304,7 +304,7 @@ void test_extract(void)
 
     for(i=0;i<10;i++)
     {
-        if(byte_extract(LITTLE, 4, value3 + i, value3, value3 + 4, &ret))
+        if(byte_extract(ENDIAN_LITTLE, 4, value3 + i, value3, value3 + 4, &ret))
         {
             printf("[loop] %d failed correctly\n", i);
         }
index 18fd0e32af66096613eb610de96ce34da5fcb1a0..b2039f839afeadd519d4a89862f78db9abbcc819 100644 (file)
@@ -24,8 +24,8 @@
 #define EXTRACT_H
 
 #define ENDIAN_NONE -1
-#define BIG    0
-#define LITTLE 1
+#define ENDIAN_BIG    0
+#define ENDIAN_LITTLE 1
 #define ENDIAN_FUNC 2
 
 #define PARSELEN 10
index 94cc8c722cadf376279e06f87351826280e3e9e1..d88f7e6387339d7de89d3fd0f2aab8aa218d631d 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "snort_types.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 88bea2fbec8d7be73e90a1c4446acfd2d4970b32..191d13c62bacb56a5d71639d342fdb5424ee2192 100644 (file)
@@ -64,7 +64,7 @@
 #include "snort_bounds.h"
 #include "snort_debug.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "util.h"
 #include "asn1.h"
index 59c93f38e0055c375151508239e5a9c1aa296134..a890ef244886db892161226ccb235fa4cd59dd91 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "snort_types.h"
 #include "snort_bounds.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 3ad4c7b8413707a7f20c05e8c52810c328aba9f0..f6b3183a4f5b8a9b75e52f2a7992910233d55280 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "snort_types.h"
 #include "snort_bounds.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index fa12b7993f7df26c033e9bc45dd9cd5fc0d30420..a385a79ef13fb80236f65418058705312f6b1205 100644 (file)
@@ -471,7 +471,7 @@ static int byte_extract_parse(ByteExtractData *data, char *args)
         else if (strcmp(token, "little") == 0)
         {
             if (data->endianess == ENDIAN_NONE)
-                data->endianess = LITTLE;
+                data->endianess = ENDIAN_LITTLE;
             else
                 ParseError("byte_extract rule option specifies the "
                         "byte order twice. Use only one of 'big', 'little', "
@@ -481,7 +481,7 @@ static int byte_extract_parse(ByteExtractData *data, char *args)
         else if (strcmp(token, "big") == 0)
         {
             if (data->endianess == ENDIAN_NONE)
-                data->endianess = BIG;
+                data->endianess = ENDIAN_BIG;
             else
                 ParseError("byte_extract rule option specifies the "
                         "byte order twice. Use only one of 'big', 'little', "
@@ -565,7 +565,7 @@ static int byte_extract_parse(ByteExtractData *data, char *args)
 
     /* Replace sentinels with defaults */
     if (data->endianess == ENDIAN_NONE)
-        data->endianess = BIG;
+        data->endianess = ENDIAN_BIG;
 
     if (data->data_string_convert_flag && (data->base == 0))
         data->base = 10;
index c4935e0022ab933bb59b85f48c9b3234ab344255..ee6a8a926d6280f7547ce792382f8d4ac575e3d9 100644 (file)
@@ -75,7 +75,7 @@
 #include "snort_types.h"
 #include "snort_bounds.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
@@ -469,12 +469,12 @@ static void byte_jump_parse(char *data, ByteJumpData *idx)
             }
             else if(!strcasecmp(cptr, "little"))
             {
-                idx->endianess = LITTLE;
+                idx->endianess = ENDIAN_LITTLE;
             }
             else if(!strcasecmp(cptr, "big"))
             {
                 /* this is the default */
-                idx->endianess = BIG;
+                idx->endianess = ENDIAN_BIG;
             }
             else if(!strcasecmp(cptr, "hex"))
             {
index 4303bec5e577259624f7453da470127e1ceba507..e06e4aebb4d00836e57d9d04a1646f50b5fe0e12 100644 (file)
@@ -96,7 +96,7 @@
 #include "snort_bounds.h"
 #include "extract.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index cbf23d48882919b4e3f886296da1c551e39d017e..8de2e2a3b8e023a7ca8098d63b412785ea18576c 100644 (file)
@@ -49,7 +49,7 @@
 
 #include "snort_types.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 732fb51a2dbfae7c2498ff6a9398586216c1467c..28c123b84d6b5943c736181dc77472ed76ebe4ea 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "snort_types.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort_debug.h"
 #include "parser.h"
 #include "util.h"
index 5b3516982c332fdf39699247c93f439c3e3362e8..44fc1cf819970f67b4947b4fb4482ce98ee408fb 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "snort_types.h"
 #include "snort_bounds.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index ff234872fe77af3b026be370102b742d539835c2..d90c5341d7a66427aa0e69c0d2ccde6e3f743407 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "snort_types.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 40371a6afe0c82c67bce73006228017c6230b873..050277b8c1d840b11cb50519e05e585d76fe88c9 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "snort_types.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 720f889f0a086940016c9c3ec5590ba9197db2ef..53307f8798a39c7e427d52523290ccf90a9209d9 100644 (file)
@@ -51,7 +51,7 @@
 
 #include "snort_types.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 091eb337ee86586003f5d44e8967a451b96dc0bd..9fd828e29be1c2be6b91832bd7624f43fde1383c 100644 (file)
@@ -54,7 +54,7 @@
 
 #include "snort_types.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index ef44bf6970da9b87bbab913c1e07fbe8e51007ab..576b31b23235a0a098fd186bfa373c5d1aeda64b 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "snort_types.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 00ee5706881e58c4416a021e359ba1d4b8561930..db6fccb254933430e8a7d2adfc825bb192cc896c 100644 (file)
@@ -60,7 +60,7 @@
 #include "snort_types.h"
 #include "snort_bounds.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 2c59aa351659d2b6ce216d62916e15c11c8117b6..108f88d7b6e75566f51ad5bfb4ce64e1ef824ef4 100644 (file)
@@ -51,7 +51,7 @@
 
 #include "snort_types.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
@@ -146,7 +146,7 @@ int IcmpIdOption::eval(Packet *p)
     PREPROC_PROFILE_START(icmpIdPerfStats);
 
     if( (p->icmph->type == ICMP_ECHO || p->icmph->type == ICMP_ECHOREPLY)
-        || ((uint16_t)p->icmph->type == ICMP6_ECHO || (uint16_t)p->icmph->type == ICMP6_REPLY)
+        || ((uint16_t)p->icmph->type == icmp6::Icmp6Types::ECHO || (uint16_t)p->icmph->type == icmp6::Icmp6Types::REPLY)
       )
     {
         /* test the rule ID value against the ICMP extension ID field */
index 88972054b590bbb7b63d23623994c31523ddf7af..d8552922b3f5b75450f357b72dbbe9329e4b43ec 100644 (file)
@@ -50,7 +50,7 @@
 
 #include "snort_types.h"
 #include "detection/treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
@@ -145,7 +145,7 @@ int IcmpSeqOption::eval(Packet *p)
     PREPROC_PROFILE_START(icmpSeqPerfStats);
 
     if( (p->icmph->type == ICMP_ECHO || p->icmph->type == ICMP_ECHOREPLY)
-        || ((uint16_t)p->icmph->type == ICMP6_ECHO || (uint16_t)p->icmph->type == ICMP6_REPLY)
+        || ((uint16_t)p->icmph->type == icmp6::Icmp6Types::ECHO || (uint16_t)p->icmph->type == icmp6::Icmp6Types::REPLY)
       )
     {
         /* test the rule ID value against the ICMP extension ID field */
index cc8f1789c607dbf740120e099934a1cc087b95cc..366eeae1a159259fa678c55cdc43b6853a49c010 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "snort_types.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "util.h"
 #include "snort_debug.h"
index 43cf2e1eff7b6cb3711da5dca64231eebffb3125..95587e574af5cf2240bc68ec7eb3a7b89ccce82e 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "snort_types.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 619dcb1772f6222f6ead28ffca68c7b12256fdda..880a84c510383a1ee4c8d3c3bf1769714fe24325 100644 (file)
@@ -33,7 +33,7 @@
 #include <netdb.h>
 
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 6da7475994ec952c9033bb6ebd0a7adfd55ebc20..fc47f5e060e59f87f59076fe24ae3e191302f0b7 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "snort_types.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index b27f3bae711276fd5c814f58015ae15d31a2c765..ce54eb7d8cd2f24a357991b10bcd7cb20a3aafb1 100644 (file)
@@ -47,7 +47,7 @@
 #include "snort_types.h"
 #include "snort_bounds.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 84cde8b320fdede38876642fa35aac7425b89b5c..b4a80dc4277a28625fa4d12870a64bd60ff948f7 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "snort_types.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 5e6857dac4efa3c4c1313f9ea12ae9a754029d37..091bc592670c6872cb748d591170542d3c58d5af 100644 (file)
@@ -33,7 +33,7 @@
 #include "snort_bounds.h"
 #include "treenodes.h"
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "util.h"
 #include "mstring.h"
index b03466c149079a9b92fe022d7d3536a906616136..44d51484ca2abab29d1f24ef7e563373ddf8879c 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "snort_types.h"
 #include "snort_bounds.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 6006a4f189fac8212c12a11409f10b25ec784b7b..b921171d9b2dd7e87e1596cec32821907e88f004 100644 (file)
@@ -58,7 +58,7 @@
 
 #include "snort_types.h"
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "managers/packet_manager.h"
 #include "detection/detection_defines.h"
 #include "parser.h"
index b041ccfab4d02cd163cdf2e606000e4f8d5ee941..ba0d04a45ddcafc6a2b80285d47ae740eeb70f4a 100644 (file)
@@ -57,7 +57,7 @@
 #include "snort_types.h"
 #include "snort_bounds.h"
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "managers/packet_manager.h"
 #include "detection/detection_defines.h"
 #include "mstring.h"
index ebc2e1d9bc9617e1fcdb2b15d696716a1d2f15b0..44df9474fc1fcdedfd3b00da5d2740bfefdde32c 100644 (file)
@@ -29,7 +29,7 @@
 #include <rpc/rpc.h>
 
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 07645a17d2c8c78e009470962b8f8b244e141cc2..ba78eb1ad30f3d6d087eb2644c0d849acc866838 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "snort_types.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 48f06943fcb7e7c6f2bef0a9dc87ec83bc90e74b..409a4a3a8efc9bd5386aa238ac9a15bff6e43811 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "snort_types.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "util.h"
 #include "snort_debug.h"
index e8c0dcb607a5cc019c49aa4eab2ea93a603dd5d3..041c95fd307b542bd5070f1d5046a08989cfa0a8 100644 (file)
@@ -56,7 +56,7 @@
 #include <string>
 
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 6c72c02c488a7ea960b995469df6728036367e07..86927cc6893c988278fd58d2de66e85db9541460 100644 (file)
@@ -28,7 +28,7 @@
 #include <ctype.h>
 #include <string.h>
 
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index 95487e8bf7662f0a620a123bcc5e37288a784df9..76e20cd045e7dbf900e88c4dd66c8e1efb7fa1b4 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "snort_types.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort_debug.h"
 #include "parser.h"
 #include "util.h"
index b87e139d953bd9e2f4cda15124473baf69920533..9ec6e809bd8d841cb549cc9c833520bbec83d9dc 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "snort_types.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort_debug.h"
 #include "parser.h"
 #include "util.h"
index 38703c91ed81d9672310287b968a614c254ff5f0..73918390060055ec91555fc53b24364efabfa169 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "snort_types.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "util.h"
 #include "snort_debug.h"
index 60592586fcbb864be20a4741ca2c4f6631a846d5..55fba27d4375da8bbb3481aa6bab01ade11a6bb6 100644 (file)
@@ -30,7 +30,7 @@
 #include "snort_types.h"
 #include "snort_bounds.h"
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "ips_content.h"
 #include "snort.h"
index c0cb761fa0ddadaa723eb8178db72fbef4a627ba..1555236e2078377722048da284365b7373e7948e 100644 (file)
@@ -26,4 +26,5 @@ install(FILES ${LOG_INCLUDES}
 
 target_link_libraries(log
     utils
+    protocols
 )
index 2af30745182d31e40f8e3cf6ba30062b0aa15933..fdbd2dc0e2be34b621f83555895b34d6ecf2bc81 100644 (file)
@@ -160,7 +160,7 @@ void snort_print(Packet* p)
         LogIPPkt(text_log, GET_IPH_PROTO((p)), p);
     }
 #ifndef NO_NON_ETHER_DECODER
-    else if (p->ah != NULL)
+    else if (p->proto_bits & PROTO_BIT__ARP)
     {
         log_mutex.lock();
         LogArpHeader(text_log, p);
index 190cc48bc6915542a08a3ff8705ed106045cf286..bb53e3f8ec2df1e3b8376544d76dbdc1dbf6a475 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef LOG_H
 #define LOG_H
 
-#include "decode.h"
+#include "protocols/packet.h"
 
 void CreateTCPFlagString(Packet *, char *);
 
index d01c65e8eb9e692ecfa28e8c1677788b06673f7a..15398c6e36afa4bc5e03354b320f1e65f8ade133 100644 (file)
 #include "snort_debug.h"
 #include "signature.h"
 #include "util_net.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort.h"
 #include "sf_textlog.h"
 #include "snort_bounds.h"
 #include "obfuscation.h"
 #include "detection_util.h"
 #include "packet_io/sfdaq.h"
+#include "protocols/layer.h"
 
 #include "sfip/sf_ip.h"
 
 #include "protocols/ipv6.h"
 #include "protocols/icmp6.h"
 #include "protocols/icmp4.h"
+#include "protocols/gre.h"
+#include "protocols/token_ring.h"
 #include "protocols/wlan.h"
+#include "protocols/linux_sll.h"
+#include "protocols/eapol.h"
 
 #ifdef HAVE_DUMBNET_H
 #include <dumbnet.h>
@@ -122,33 +127,41 @@ void LogPriorityData(TextLog* log, const Event* e, bool doNewLine)
 
 void LogTrHeader(TextLog* log, Packet* p)
 {
+    const token_ring::Trh_hdr* trh =
+        reinterpret_cast<const token_ring::Trh_hdr*>(layer::get_root_layer(p));
 
-    TextLog_Print(log, "%X:%X:%X:%X:%X:%X -> ", p->trh->saddr[0],
-            p->trh->saddr[1], p->trh->saddr[2], p->trh->saddr[3],
-            p->trh->saddr[4], p->trh->saddr[5]);
-    TextLog_Print(log, "%X:%X:%X:%X:%X:%X\n", p->trh->daddr[0],
-            p->trh->daddr[1], p->trh->daddr[2], p->trh->daddr[3],
-            p->trh->daddr[4], p->trh->daddr[5]);
+    TextLog_Print(log, "%X:%X:%X:%X:%X:%X -> ", trh->saddr[0],
+            trh->saddr[1], trh->saddr[2], trh->saddr[3],
+            trh->saddr[4], trh->saddr[5]);
+    TextLog_Print(log, "%X:%X:%X:%X:%X:%X\n", trh->daddr[0],
+            trh->daddr[1], trh->daddr[2], trh->daddr[3],
+            trh->daddr[4], trh->daddr[5]);
+
+    const token_ring::Trh_llc* trhllc =
+        reinterpret_cast<const token_ring::Trh_llc*>(trh + sizeof(*trh));
+
+    TextLog_Print(log, "access control:0x%X frame control:0x%X\n", trh->ac,
+            trh->fc);
 
-    TextLog_Print(log, "access control:0x%X frame control:0x%X\n", p->trh->ac,
-            p->trh->fc);
-    if(!p->trhllc)
-        return;
     TextLog_Print(log, "DSAP: 0x%X SSAP 0x%X protoID: %X%X%X Ethertype: %X\n",
-            p->trhllc->dsap, p->trhllc->ssap, p->trhllc->protid[0],
-            p->trhllc->protid[1], p->trhllc->protid[2], p->trhllc->ethertype);
-    if(p->trhmr)
+            trhllc->dsap, trhllc->ssap, trhllc->protid[0],
+            trhllc->protid[1], trhllc->protid[2], trhllc->ethertype);
+
+
+    const token_ring::Trh_mr* trhmr = token_ring::get_trhmr(trhllc);
+
+    if(trhmr)
     {
         TextLog_Print(log, "RIF structure is present:\n");
         TextLog_Print(log, "bcast: 0x%X length: 0x%X direction: 0x%X largest"
                 "fr. size: 0x%X res: 0x%X\n",
-                TRH_MR_BCAST(p->trhmr), TRH_MR_LEN(p->trhmr),
-        TRH_MR_DIR(p->trhmr), TRH_MR_LF(p->trhmr),
-                TRH_MR_RES(p->trhmr));
+                TRH_MR_BCAST(trhmr), TRH_MR_LEN(trhmr),
+        TRH_MR_DIR(trhmr), TRH_MR_LF(trhmr),
+                TRH_MR_RES(trhmr));
         TextLog_Print(log, "rseg -> %X:%X:%X:%X:%X:%X:%X:%X\n",
-                p->trhmr->rseg[0], p->trhmr->rseg[1], p->trhmr->rseg[2],
-                p->trhmr->rseg[3], p->trhmr->rseg[4], p->trhmr->rseg[5],
-                p->trhmr->rseg[6], p->trhmr->rseg[7]);
+                trhmr->rseg[0], trhmr->rseg[1], trhmr->rseg[2],
+                trhmr->rseg[3], trhmr->rseg[4], trhmr->rseg[5],
+                trhmr->rseg[6], trhmr->rseg[7]);
     }
 }
 #endif  // NO_NON_ETHER_DECODER
@@ -165,18 +178,20 @@ void LogTrHeader(TextLog* log, Packet* p)
  */
 static void LogEthHeader(TextLog* log, Packet* p)
 {
+    const eth::EtherHdr *eh = layer::get_eth_layer(p);
+
     /* src addr */
-    TextLog_Print(log, "%02X:%02X:%02X:%02X:%02X:%02X -> ", p->eh->ether_src[0],
-        p->eh->ether_src[1], p->eh->ether_src[2], p->eh->ether_src[3],
-        p->eh->ether_src[4], p->eh->ether_src[5]);
+    TextLog_Print(log, "%02X:%02X:%02X:%02X:%02X:%02X -> ", eh->ether_src[0],
+        eh->ether_src[1], eh->ether_src[2], eh->ether_src[3],
+        eh->ether_src[4], eh->ether_src[5]);
 
     /* dest addr */
-    TextLog_Print(log, "%02X:%02X:%02X:%02X:%02X:%02X ", p->eh->ether_dst[0],
-        p->eh->ether_dst[1], p->eh->ether_dst[2], p->eh->ether_dst[3],
-        p->eh->ether_dst[4], p->eh->ether_dst[5]);
+    TextLog_Print(log, "%02X:%02X:%02X:%02X:%02X:%02X ", eh->ether_dst[0],
+        eh->ether_dst[1], eh->ether_dst[2], eh->ether_dst[3],
+        eh->ether_dst[4], eh->ether_dst[5]);
 
     /* protocol and pkt size */
-    TextLog_Print(log, "type:0x%X len:0x%X\n", ntohs(p->eh->ether_type),
+    TextLog_Print(log, "type:0x%X len:0x%X\n", ntohs(eh->ether_type),
         p->pkth->pktlen);
 }
 
@@ -189,11 +204,13 @@ static void LogMPLSHeader(TextLog* log, Packet* p)
 
 static void LogGREHeader(TextLog *log, Packet *p)
 {
-    if (p->greh == NULL)
+    const gre::GREHdr *greh = layer::get_gre_layer(p);
+
+    if (greh == NULL)
         return;
 
     TextLog_Print(log, "GRE version:%u flags:0x%02X ether-type:0x%04X\n",
-            GRE_VERSION(p->greh), p->greh->flags, GRE_PROTO(p->greh));
+            GRE_VERSION(greh), greh->flags, GRE_PROTO(greh));
 }
 
 #ifndef NO_NON_ETHER_DECODER
@@ -211,7 +228,10 @@ static void LogGREHeader(TextLog *log, Packet *p)
 #ifdef DLT_LINUX_SLL
 static void LogSLLHeader(TextLog* log, Packet* p)
 {
-    switch (ntohs(p->sllh->sll_pkttype)) {
+    const linux_sll::SLLHdr* sllh =
+        reinterpret_cast<const linux_sll::SLLHdr*>(layer::get_root_layer(p));
+
+    switch (ntohs(sllh->sll_pkttype)) {
         case LINUX_SLL_HOST:
             TextLog_Puts(log, "< ");
             break;
@@ -234,14 +254,14 @@ static void LogSLLHeader(TextLog* log, Packet* p)
 
     /* mac addr */
     TextLog_Print(log, "l/l len: %i l/l type: 0x%X %02X:%02X:%02X:%02X:%02X:%02X\n",
-        htons(p->sllh->sll_halen), ntohs(p->sllh->sll_hatype),
-        p->sllh->sll_addr[0], p->sllh->sll_addr[1], p->sllh->sll_addr[2],
-        p->sllh->sll_addr[3], p->sllh->sll_addr[4], p->sllh->sll_addr[5]);
+        htons(sllh->sll_halen), ntohs(sllh->sll_hatype),
+        sllh->sll_addr[0], sllh->sll_addr[1], sllh->sll_addr[2],
+        sllh->sll_addr[3], sllh->sll_addr[4], sllh->sll_addr[5]);
 
     /* protocol and pkt size */
     TextLog_Print(log, "pkt type:0x%X proto: 0x%X len:0x%X\n",
-        ntohs(p->sllh->sll_pkttype),
-        ntohs(p->sllh->sll_protocol), p->pkth->pktlen);
+        ntohs(sllh->sll_pkttype),
+        ntohs(sllh->sll_protocol), p->pkth->pktlen);
 }
 #endif
 
@@ -257,36 +277,39 @@ static void LogSLLHeader(TextLog* log, Packet* p)
  */
 static void LogWifiHeader(TextLog* log, Packet * p)
 {
+  const wlan::WifiHdr *wifih =
+      reinterpret_cast< const wlan::WifiHdr *>(layer::get_root_layer(p));
+
   /* This assumes we are printing a data packet, could be changed
      to print other types as well */
   const uint8_t *da = NULL, *sa = NULL, *bssid = NULL, *ra = NULL,
     *ta = NULL;
   /* per table 4, IEEE802.11 section 7.2.2 */
-  if ((p->wifih->frame_control & WLAN_FLAG_TODS) &&
-      (p->wifih->frame_control & WLAN_FLAG_FROMDS)) {
-    ra = p->wifih->addr1;
-    ta = p->wifih->addr2;
-    da = p->wifih->addr3;
-    sa = p->wifih->addr4;
+  if ((wifih->frame_control & WLAN_FLAG_TODS) &&
+      (wifih->frame_control & WLAN_FLAG_FROMDS)) {
+    ra = wifih->addr1;
+    ta = wifih->addr2;
+    da = wifih->addr3;
+    sa = wifih->addr4;
   }
-  else if (p->wifih->frame_control & WLAN_FLAG_TODS) {
-    bssid = p->wifih->addr1;
-    sa = p->wifih->addr2;
-    da = p->wifih->addr3;
+  else if (wifih->frame_control & WLAN_FLAG_TODS) {
+    bssid = wifih->addr1;
+    sa = wifih->addr2;
+    da = wifih->addr3;
   }
-  else if (p->wifih->frame_control & WLAN_FLAG_FROMDS) {
-    da = p->wifih->addr1;
-    bssid = p->wifih->addr2;
-    sa = p->wifih->addr3;
+  else if (wifih->frame_control & WLAN_FLAG_FROMDS) {
+    da = wifih->addr1;
+    bssid = wifih->addr2;
+    sa = wifih->addr3;
   }
   else {
-    da = p->wifih->addr1;
-    sa = p->wifih->addr2;
-    bssid = p->wifih->addr3;
+    da = wifih->addr1;
+    sa = wifih->addr2;
+    bssid = wifih->addr3;
   }
 
   /* DO this switch to provide additional info on the type */
-  switch(p->wifih->frame_control & 0x00ff)
+  switch(wifih->frame_control & 0x00ff)
   {
   case WLAN_TYPE_MGMT_BEACON:
     TextLog_Puts(log, "Beacon ");
@@ -357,14 +380,14 @@ static void LogWifiHeader(TextLog* log, Packet * p)
         ra[1], ra[2], ra[3], ra[4], ra[5]);
   }
   TextLog_Puts(log, " Flags:");
-  if (p->wifih->frame_control & WLAN_FLAG_TODS)    TextLog_Puts(log," ToDs");
-  if (p->wifih->frame_control & WLAN_FLAG_TODS)    TextLog_Puts(log," FrDs");
-  if (p->wifih->frame_control & WLAN_FLAG_FRAG)    TextLog_Puts(log," Frag");
-  if (p->wifih->frame_control & WLAN_FLAG_RETRY)   TextLog_Puts(log," Re");
-  if (p->wifih->frame_control & WLAN_FLAG_PWRMGMT) TextLog_Puts(log," Pwr");
-  if (p->wifih->frame_control & WLAN_FLAG_MOREDAT) TextLog_Puts(log," MD");
-  if (p->wifih->frame_control & WLAN_FLAG_WEP)     TextLog_Puts(log," Wep");
-  if (p->wifih->frame_control & WLAN_FLAG_ORDER)   TextLog_Puts(log," Ord");
+  if (wifih->frame_control & WLAN_FLAG_TODS)    TextLog_Puts(log," ToDs");
+  if (wifih->frame_control & WLAN_FLAG_TODS)    TextLog_Puts(log," FrDs");
+  if (wifih->frame_control & WLAN_FLAG_FRAG)    TextLog_Puts(log," Frag");
+  if (wifih->frame_control & WLAN_FLAG_RETRY)   TextLog_Puts(log," Re");
+  if (wifih->frame_control & WLAN_FLAG_PWRMGMT) TextLog_Puts(log," Pwr");
+  if (wifih->frame_control & WLAN_FLAG_MOREDAT) TextLog_Puts(log," MD");
+  if (wifih->frame_control & WLAN_FLAG_WEP)     TextLog_Puts(log," Wep");
+  if (wifih->frame_control & WLAN_FLAG_ORDER)   TextLog_Puts(log," Ord");
   TextLog_NewLine(log);
 }
 #endif  // NO_NON_ETHER_DECODER
@@ -385,23 +408,23 @@ void Log2ndHeader(TextLog* log, Packet* p)
     switch(DAQ_GetBaseProtocol())
     {
         case DLT_EN10MB:        /* Ethernet */
-            if(p && p->eh)
+            if(p && (p->next_layer > 0))
                 LogEthHeader(log, p);
             break;
 #ifndef NO_NON_ETHER_DECODER
 #ifdef DLT_IEEE802_11
         case DLT_IEEE802_11:
-            if(p && p->wifih)
+            if(p && (p->next_layer > 0))
                 LogWifiHeader(log, p);
             break;
 #endif
         case DLT_IEEE802:                /* Token Ring */
-            if(p && p->trh)
+            if(p && (p->next_layer > 0))
                 LogTrHeader(log, p);
             break;
 #ifdef DLT_LINUX_SLL
         case DLT_LINUX_SLL:
-            if (p && p->sllh)
+            if (p && (p->next_layer > 0))
                 LogSLLHeader(log, p);  /* Linux cooked sockets */
             break;
 #endif
@@ -1442,7 +1465,7 @@ void LogNetData (TextLog* log, const uint8_t* data, const int len, Packet *p)
     int next_layer, ip_start, ip_ob_start, ip_ob_end, byte_pos, char_pos;
     int i;
 
-    next_layer = ip_start = byte_pos = char_pos = 0;
+    ip_start = byte_pos = char_pos = 0;
 
     ip_ob_start = ip_ob_end = -1;
 
@@ -1500,8 +1523,6 @@ void LogNetData (TextLog* log, const uint8_t* data, const int len, Packet *p)
     /* loop thru the whole buffer */
     while ( pb < end )
     {
-        i = 0;
-
         if (ScVerboseByteDump())
         {
             TextLog_Print(log, "0x%04X: ", offset);
@@ -1666,7 +1687,7 @@ void LogIPPkt(TextLog* log, int type, Packet * p)
     {
         Log2ndHeader(log, p);
 
-        if ( p->mpls )
+        if ( p->proto_bits & PROTO_BIT__MPLS )
         {
             LogMPLSHeader(log, p);
         }
@@ -1674,8 +1695,7 @@ void LogIPPkt(TextLog* log, int type, Packet * p)
         if ( p->outer_iph )
         {
             LogOuterIPHeader(log, p);
-            if ( p->greh )
-                LogGREHeader(log, p);
+            LogGREHeader(log, p); // checks for valid gre layer before logging
         }
     }
 
@@ -1798,25 +1818,26 @@ void LogArpHeader(TextLog*, Packet*)
  * Returns: void function
  *
  ***************************************************************************/
-static void PrintEapolKey(FILE * fp, Packet * p)
+static void PrintEapolKey(FILE * fp,  const eapol::EapolKey* eapolk)
 {
+
     uint16_t length;
 
-    if(p->eapolk == NULL)
+    if(eapolk == NULL)
     {
         fprintf(fp, "Eapol Key truncated\n");
         return;
     }
     fprintf(fp, "KEY type: ");
-    if (p->eapolk->type == 1) {
+    if (eapolk->type == 1) {
       fprintf(fp, "RC4");
     }
 
-    memcpy(&length, &p->eapolk->length, 2);
+    memcpy(&length, &eapolk->length, 2);
     length = ntohs(length);
     fprintf(fp, " len: %d", length);
-    fprintf(fp, " index: %d ", p->eapolk->index & 0x7F);
-    fprintf(fp, p->eapolk->index & 0x80 ? " unicast\n" : " broadcast\n");
+    fprintf(fp, " index: %d ", eapolk->index & 0x7F);
+    fprintf(fp, eapolk->index & 0x80 ? " unicast\n" : " broadcast\n");
 }
 
 /****************************************************************************
@@ -1830,29 +1851,29 @@ static void PrintEapolKey(FILE * fp, Packet * p)
  * Returns: void function
  *
  ***************************************************************************/
-static void PrintEapolHeader(FILE * fp, Packet * p)
+static void PrintEapolHeader(FILE * fp, const eapol::EtherEapol* eplh)
 {
     fprintf(fp, "EAPOL type: ");
-    switch(p->eplh->eaptype) {
+    switch(eplh->eaptype) {
     case EAPOL_TYPE_EAP:
-      fprintf(fp, "EAP");
-      break;
+        fprintf(fp, "EAP");
+        break;
     case EAPOL_TYPE_START:
-      fprintf(fp, "Start");
-      break;
+        fprintf(fp, "Start");
+        break;
     case EAPOL_TYPE_LOGOFF:
-      fprintf(fp, "Logoff");
-      break;
+        fprintf(fp, "Logoff");
+        break;
     case EAPOL_TYPE_KEY:
-      fprintf(fp, "Key");
-      break;
+        fprintf(fp, "Key");
+        break;
     case EAPOL_TYPE_ASF:
-      fprintf(fp, "ASF Alert");
-      break;
+        fprintf(fp, "ASF Alert");
+        break;
     default:
-      fprintf(fp, "Unknown");
+        fprintf(fp, "Unknown");
     }
-    fprintf(fp, " Len: %d\n", ntohs(p->eplh->len));
+    fprintf(fp, " Len: %d\n", ntohs(eplh->len));
 }
 
 /****************************************************************************
@@ -1866,58 +1887,63 @@ static void PrintEapolHeader(FILE * fp, Packet * p)
  * Returns: void function
  *
  ***************************************************************************/
-static void PrintEAPHeader(FILE * fp, Packet * p)
+static void PrintEAPHeader(FILE * fp, const eapol::EAPHdr* eaph)
 {
+    uint8_t* eaptype = 0;
 
-    if(p->eaph == NULL)
+    if(eaph == NULL)
     {
         fprintf(fp, "EAP header truncated\n");
         return;
     }
     fprintf(fp, "code: ");
-    switch(p->eaph->code) {
+    switch(eaph->code) {
     case EAP_CODE_REQUEST:
-      fprintf(fp, "Req ");
-      break;
+        fprintf(fp, "Req ");
+        eaptype = (uint8_t*) (eaph + sizeof(*eaph));
+        break;
     case EAP_CODE_RESPONSE:
-      fprintf(fp, "Resp");
-      break;
+        fprintf(fp, "Resp");
+        eaptype = (uint8_t*) (eaph + sizeof(*eaph));
+        break;
     case EAP_CODE_SUCCESS:
-      fprintf(fp, "Succ");
-      break;
+        fprintf(fp, "Succ");
+        break;
     case EAP_CODE_FAILURE:
-      fprintf(fp, "Fail");
-      break;
+        fprintf(fp, "Fail");
+        break;
     }
-    fprintf(fp, " id: 0x%x len: %d", p->eaph->id, ntohs(p->eaph->len));
-    if (p->eaptype != NULL) {
-      fprintf(fp, " type: ");
-      switch(*(p->eaptype)) {
-      case EAP_TYPE_IDENTITY:
-    fprintf(fp, "id");
-    break;
-      case EAP_TYPE_NOTIFY:
-    fprintf(fp, "notify");
-    break;
-      case EAP_TYPE_NAK:
-    fprintf(fp, "nak");
-    break;
-      case EAP_TYPE_MD5:
-    fprintf(fp, "md5");
-    break;
-      case EAP_TYPE_OTP:
-    fprintf(fp, "otp");
-    break;
-      case EAP_TYPE_GTC:
-    fprintf(fp, "token");
-    break;
-      case EAP_TYPE_TLS:
-    fprintf(fp, "tls");
-    break;
-      default:
-    fprintf(fp, "undef");
-    break;
-      }
+    fprintf(fp, " id: 0x%x len: %d", eaph->id, ntohs(eaph->len));
+    if (eaptype != NULL)
+    {
+        fprintf(fp, " type: ");
+        switch(*(eaptype))
+        {
+            case EAP_TYPE_IDENTITY:
+            fprintf(fp, "id");
+            break;
+              case EAP_TYPE_NOTIFY:
+            fprintf(fp, "notify");
+            break;
+              case EAP_TYPE_NAK:
+            fprintf(fp, "nak");
+            break;
+              case EAP_TYPE_MD5:
+            fprintf(fp, "md5");
+            break;
+              case EAP_TYPE_OTP:
+            fprintf(fp, "otp");
+            break;
+              case EAP_TYPE_GTC:
+            fprintf(fp, "token");
+            break;
+              case EAP_TYPE_TLS:
+            fprintf(fp, "tls");
+            break;
+              default:
+            fprintf(fp, "undef");
+            break;
+        }
     }
     fprintf(fp, "\n");
 }
@@ -1948,12 +1974,22 @@ void PrintEapolPkt(FILE * fp, Packet * p)
     {
         Print2ndHeader(fp, p);
     }
-    PrintEapolHeader(fp, p);
-    if (p->eplh->eaptype == EAPOL_TYPE_EAP) {
-      PrintEAPHeader(fp, p);
+
+    const eapol::EtherEapol* eplh = layer::get_eapol_layer(p);
+
+    if (eplh)
+    {
+        PrintEapolHeader(fp, eplh);
+        if (eplh->eaptype == EAPOL_TYPE_EAP) {
+            PrintEAPHeader(fp, (const eapol::EAPHdr*) eplh + sizeof(*eplh));
+        }
+        else if (eplh->eaptype == EAPOL_TYPE_KEY) {
+            PrintEapolKey(fp, (const eapol::EapolKey*) eplh + sizeof(*eplh));
+        }
     }
-    else if (p->eplh->eaptype == EAPOL_TYPE_KEY) {
-      PrintEapolKey(fp, p);
+    else
+    {
+        fprintf(fp, "EAP header truncated\n");
     }
 
     /* dump the application layer data */
index dca77f2e9d123c9b001da2a640b652f632efdb6a..d17462c64b873b09a85eb5eab56a74cf8ab9a963 100644 (file)
@@ -31,7 +31,7 @@ extern "C" {
 
 #include "snort_types.h"
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "stream/stream_api.h"
 #include "snort_bounds.h"
 #include "main/thread.h"
index 189ec2a478d5ad61de6e63c223ea4c861a8a584f..d0fb3111154bfc7254a6d551e31f8aec1c0b4ddb 100644 (file)
@@ -10,7 +10,6 @@ set ( PLUGIN_LIST
     alert_csv.cc
     alert_fast.cc
     alert_full.cc
-    alert_sf_socket.cc
     alert_syslog.cc
     alert_test.cc
     alert_unixsock.cc
@@ -20,6 +19,14 @@ set ( PLUGIN_LIST
     unified2_common.h
 )
 
+if( LINUX )
+    set ( PLUGIN_LIST
+        ${PLUGIN_LIST}
+        alert_sf_socket.cc
+    )
+endif()
+
+
 if (STATIC_LOGGERS)
     add_library ( loggers STATIC
         ${LOGGER_SOURCES}
index 2417967a2ca029cd7e075e88bbff5a7968487adf..ac12584da1b7f01c8b0b480ba7942d518d50402e 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "framework/logger.h"
 #include "framework/module.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "mstring.h"
@@ -186,9 +186,13 @@ void CsvLogger::alert(Packet *p, const char *msg, Event *event)
     int num;
     char *type;
     char tcpFlags[9];
+    const eth::EtherHdr *eh = nullptr;
 
     assert(p);
 
+    if (p->proto_bits & PROTO_BIT__ETH)
+        eh = layer::get_eth_layer(p);
+
     // TBD an enum would be an improvement here
     for (num = 0; num < numargs; num++)
     {
@@ -239,30 +243,30 @@ void CsvLogger::alert(Packet *p, const char *msg, Event *event)
         }
         else if (!strcasecmp("eth_src", type))
         {
-            if (p->eh != NULL)
+            if (eh)
             {
-                TextLog_Print(csv_log, "%02X:%02X:%02X:%02X:%02X:%02X", p->eh->ether_src[0],
-                        p->eh->ether_src[1], p->eh->ether_src[2], p->eh->ether_src[3],
-                        p->eh->ether_src[4], p->eh->ether_src[5]);
+                TextLog_Print(csv_log, "%02X:%02X:%02X:%02X:%02X:%02X", eh->ether_src[0],
+                        eh->ether_src[1], eh->ether_src[2], eh->ether_src[3],
+                        eh->ether_src[4], eh->ether_src[5]);
             }
         }
         else if (!strcasecmp("eth_dst", type))
         {
-            if (p->eh != NULL)
+            if (eh)
             {
-                TextLog_Print(csv_log, "%02X:%02X:%02X:%02X:%02X:%02X", p->eh->ether_dst[0],
-                        p->eh->ether_dst[1], p->eh->ether_dst[2], p->eh->ether_dst[3],
-                        p->eh->ether_dst[4], p->eh->ether_dst[5]);
+                TextLog_Print(csv_log, "%02X:%02X:%02X:%02X:%02X:%02X", eh->ether_dst[0],
+                        eh->ether_dst[1], eh->ether_dst[2], eh->ether_dst[3],
+                        eh->ether_dst[4], eh->ether_dst[5]);
             }
         }
         else if (!strcasecmp("eth_type", type))
         {
-            if (p->eh != NULL)
-                TextLog_Print(csv_log, "0x%X", ntohs(p->eh->ether_type));
+            if (eh != NULL)
+                TextLog_Print(csv_log, "0x%X", ntohs(eh->ether_type));
         }
         else if (!strcasecmp("eth_len", type))
         {
-            if (p->eh != NULL)
+            if (eh != NULL)
                 TextLog_Print(csv_log, "0x%X", p->pkth->pktlen);
         }
         else if (!strcasecmp("udp_len", type))
index 2708de16edb3a76b4fb2abebde34149e6832fb3a..1abad5bdde421445c2e345542699829287d2bf40 100644 (file)
@@ -48,7 +48,7 @@
 #include "framework/logger.h"
 #include "framework/module.h"
 #include "event.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort_debug.h"
 #include "parser.h"
 #include "util.h"
@@ -245,7 +245,7 @@ void FastLogger::alert(Packet *p, const char *msg, Event *event)
         if(IPH_IS_VALID(p))
             LogIPPkt(fast_log, GET_IPH_PROTO(p), p);
 #ifndef NO_NON_ETHER_DECODER
-        else if(p->ah)
+        else if(p->proto_bits & PROTO_BIT__ARP)
             LogArpHeader(fast_log, p);
 #endif
     }
index 56a46db42d2a77c8d1afd725c1a18c45b143450d..30cdf083e17828a02ca23eab165793b5829d83bd 100644 (file)
@@ -47,7 +47,7 @@
 #include "framework/logger.h"
 #include "framework/module.h"
 #include "event.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort_debug.h"
 #include "parser.h"
 #include "util.h"
index 86f3248de3c4bee73d8a228922a5b14030fae17c..faaa1329d308a5717c1ea5067d776fb79bd8e000 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "framework/logger.h"
 #include "framework/module.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "detect.h"
 #include "event.h"
 #include "rules.h"
index c96ebe66461efa6125798966a48da27882868c5b..06be0603df1ea1f1c34cdfe3c32653b231fdf7e8 100644 (file)
@@ -32,7 +32,7 @@
 #include "framework/logger.h"
 #include "framework/module.h"
 #include "event.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort_debug.h"
 #include "parser.h"
 #include "util.h"
index a4192509b59240cb3b1f3fccff4799b2ecc0cd87..37e1914bdcd9028a9223043fcfe2eae396c1e8ca 100644 (file)
@@ -36,7 +36,7 @@
 #include "framework/module.h"
 #include "snort_types.h"
 #include "event.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
@@ -58,6 +58,8 @@ struct pcap_pkthdr32
 
 /* this struct is for the alert socket code.... */
 // FIXTHIS alert unix sock supports l2-l3-l4 encapsulations
+
+const unsigned int ALERTMSG_LENGTH = 256;
 struct Alertpkt
 {
     uint8_t alertmsg[ALERTMSG_LENGTH]; /* variable.. */
@@ -155,9 +157,11 @@ static void get_alert_pkt(
     {
         if(p)
         {
-            if (p->eh)
+            if (p->proto_bits & PROTO_BIT__ETH)
             {
-                us.alert.dlthdr=(char *)p->eh-(char *)p->pkt;
+
+                const eth::EtherHdr *eh = layer::get_eth_layer(p);
+                us.alert.dlthdr=(char *)eh-(char *)p->pkt;
             }
 
             /* we don't log any headers besides eth yet */
index 6486d3801f055eb2c7264d9804a154de7491f2e7..0e877ac05dbdbebbbacf6842c68f20aee8875a6c 100644 (file)
@@ -40,7 +40,7 @@ extern "C" {
 
 #include "framework/logger.h"
 #include "framework/module.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "event.h"
 #include "mstring.h"
 #include "parser.h"
index 4ef754aabfe47d79849f4741cbb823ef398791d4..007bcde8ee9c9facd4eaa04cd94c24e9e79874d5 100644 (file)
 
 #include "framework/logger.h"
 #include "framework/module.h"
-#include "decode.h" /* for struct in6_addr -- maybe move to snort_types.h? */
+#include "protocols/packet.h" /* for struct in6_addr -- maybe move to snort_types.h? */
 #include "snort_types.h"
 #include "main/analyzer.h"
-#include "decode.h"
 #include "rules.h"
 #include "treenodes.h"
 #include "util.h"
@@ -63,6 +62,8 @@
 #include "detect.h"
 #include "snort.h"
 #include "stream/stream_api.h"
+#include "protocols/layer.h"
+#include "protocols/vlan.h"
 
 using namespace std;
 
@@ -273,15 +274,15 @@ static void _AlertIP4_v2(Packet *p, const char*, Unified2Config *config, Event *
                 alertdata.dport_icode = htons(p->dp);
             }
 
-            if((p->mpls) && (config->mpls_event_types))
+            if((p->proto_bits & PROTO_BIT__MPLS) && (config->mpls_event_types))
             {
                 alertdata.mpls_label = htonl(p->mplsHdr.label);
             }
             if(config->vlan_event_types)
             {
-                if(p->vh)
+                if(p->proto_bits & PROTO_BIT__VLAN)
                 {
-                    alertdata.vlanId = htons(VTH_VLAN(p->vh));
+                    alertdata.vlanId = htons(vlan::vth_vlan(layer::get_vlan_layer(p)));
                 }
 
                 alertdata.pad2 = htons(p->user_policy_id);
@@ -376,15 +377,15 @@ static void _AlertIP6_v2(Packet *p, const char*, Unified2Config *config, Event *
                 alertdata.dport_icode = htons(p->dp);
             }
 
-            if((p->mpls) && (config->mpls_event_types))
+            if((p->proto_bits & PROTO_BIT__MPLS) && (config->mpls_event_types))
             {
                 alertdata.mpls_label = htonl(p->mplsHdr.label);
             }
             if(config->vlan_event_types)
             {
-                if(p->vh)
+                if(p->proto_bits & PROTO_BIT__VLAN)
                 {
-                    alertdata.vlanId = htons(VTH_VLAN(p->vh));
+                    alertdata.vlanId = htons(vlan::vth_vlan(layer::get_vlan_layer(p)));
                 }
 
                 alertdata.pad2 = htons(p->user_policy_id);
index a67a6a450614f0ee9ef4125740e8ce46cfff80a1..f04eb3900d3956020f5c63d9c2f1cb7398828788 100644 (file)
@@ -22,7 +22,7 @@
 #define ANALYZER_H
 
 #include "snort_types.h"
-#include "decode.h"
+#include "protocols/packet.h"
 
 enum AnalyzerCommand
 {
index 3304738c7aca1db5e4a4cb8dfdef32eb3f994f99..1aecb21f1160e180d3f33bf2a6088a0469d86873 100644 (file)
@@ -54,7 +54,7 @@ using namespace std;
 #include <thread>
 
 #include "helpers/process.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "managers/packet_manager.h"
 #include "packet_io/sfdaq.h"
 #include "packet_io/active.h"
@@ -764,7 +764,7 @@ static void set_policy(Packet*)  // FIX SSN implement based on bindings
 {
    // for now need to just get stream_* inspectors and call appropriately 
 #if 0
-    int vlanId = (p->vh) ? VTH_VLAN(p->vh) : -1;
+    int vlanId = (p->vh) ? vlan::vth_vlan(p->vh) : -1;
     snort_ip_p srcIp = (p->iph) ? GET_SRC_IP((p)) : (snort_ip_p)0;
     snort_ip_p dstIp = (p->iph) ? GET_DST_IP((p)) : (snort_ip_p)0;
 
index 80002bd805e704e828a9f14a1b6809c965e6c8cf..9bce3a96bbb2c6081831f343b358a0888094f389 100644 (file)
 #include <stdio.h>
 
 #include "snort_types.h"
-#include "protocols/decode.h"
 #include "sfip/sf_ipvar.h"
 #include "main/snort_config.h"
 #include "snort_types.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "log/log.h"
 
 SnortConfig* reload_config();
index 3b808f366f5619c1b81323a95f746a57254f0834..d4621d92644a7f6a9a62f3e5f8cdfb700a201670 100644 (file)
 
 namespace
 {
-struct CdGenPegs{
-    PegCount total_processed = 0;
-    PegCount other_codecs = 0;
-    PegCount discards = 0;
-};
 
-std::vector<const char*> gen_peg_names =
-{
-    "total",
-    "other",
-    "discards"
-};
 
 } // anonymous
 
@@ -67,35 +56,39 @@ std::vector<const char*> gen_peg_names =
 THREAD_LOCAL PreprocStats decodePerfStats;
 #endif
 
-
 extern const CodecApi* default_codec;
-
 static const uint16_t max_protocol_id = 65535;
-static std::vector<const CodecApi*> s_codecs;
+static const uint16_t IP_ID_COUNT = 8192;
 
-// when initialization arrays, although the zero is not required
-// the compiler complains about a missing-field-initiliezers
+// the zero initialization is not required but quiets the compiler
+static std::vector<const CodecApi*> s_codecs;
 static std::array<uint8_t, max_protocol_id> s_proto_map{{0}};
 static std::array<Codec*, UINT8_MAX> s_protocols{{0}};
 static THREAD_LOCAL uint8_t grinder = 0;
 
 // Decoding statistics
-static const uint8_t gen_peg_size = 3;  //  reflects size of CdGenPegs
-static const uint8_t stat_offset = gen_peg_size;  // different name to simplify code
-static THREAD_LOCAL std::array<PegCount, 256 + gen_peg_size> s_stats{{0}};
-static std::array<PegCount, 256 + gen_peg_size> g_stats{{0}};
-static THREAD_LOCAL CdGenPegs pkt_cnt;
 
+// this vector reflects the printed names for the statistics
+// before the stat_offset
+static const std::vector<const char*> stat_names =
+{
+    "total",
+    "other",
+    "discards"
+};
 
+static const uint8_t total_processed = 0;
+static const uint8_t other_codecs = 1;
+static const uint8_t discards = 2;
+static const uint8_t stat_offset = 3;
+static THREAD_LOCAL std::array<PegCount, stat_offset + s_protocols.size()> s_stats{{0}};
+static std::array<PegCount, s_stats.size()> g_stats{{0}};
 
 // Encoder Foo
-static Packet *encode_pkt;
-//static THREAD_LOCAL PegCount g_total_rebuilt_pkts = 0;
+static THREAD_LOCAL rand_t* s_rand = NULL;
+static THREAD_LOCAL Packet *encode_pkt;
 static THREAD_LOCAL PegCount total_rebuilt_pkts = 0;
 static THREAD_LOCAL uint8_t* dst_mac = NULL;
-
-static const uint16_t IP_ID_COUNT = 8192;
-static THREAD_LOCAL rand_t* s_rand = NULL;
 static THREAD_LOCAL std::array<uint16_t, IP_ID_COUNT> s_id_pool{{0}};
 static THREAD_LOCAL std::array<uint8_t, Codec::PKT_MAX> s_pkt{{0}};
 
@@ -106,26 +99,6 @@ static THREAD_LOCAL std::array<uint8_t, Codec::PKT_MAX> s_pkt{{0}};
 //-------------------------------------------------------------------------
 
 
-static inline void push_layer(Packet *p,
-                                uint16_t prot_id,
-                                const uint8_t *hdr_start,
-                                uint32_t len)
-{
-    if ( p->next_layer < LAYER_MAX )
-    {
-        Layer& lyr = p->layers[p->next_layer++];
-        lyr.prot_id = prot_id;
-        lyr.start = (uint8_t*)hdr_start;
-        lyr.length = (uint16_t)len;
-    }
-    else
-    {
-        LogMessage("(snort_decoder) WARNING: decoder got too many layers;"
-            " next proto is something.\n");
-    }
-}
-
-
 static inline void push_layer(Packet *p,
                                 uint16_t prot_id,
                                 const uint8_t *hdr_start,
@@ -142,7 +115,7 @@ static inline void push_layer(Packet *p,
     }
     else
     {
-        LogMessage("(snort_decoder) WARNING: decoder got too many layers;"
+        LogMessage("(packet_manager) WARNING: decoder has too many layers;"
             " next proto is something.\n");
     }
 }
@@ -167,7 +140,6 @@ static inline uint8_t* get_inner_ip_hdr(const Packet *p)
     return nullptr;
 }
 
-
 static inline int get_inner_ip_lyr(const Packet *p)
 {
     const Layer *layers = p->layers;
@@ -207,7 +179,6 @@ static inline uint8_t get_codec(const char* keyword)
     return 0;
 }
 
-
 static const uint8_t* encode_packet(
     EncState* enc, const Packet* p, uint32_t* len)
 {
@@ -251,39 +222,28 @@ static const uint8_t* encode_packet(
     return obuf.base + obuf.off;
 }
 
-static void accumulate()
+static inline void accumulate()
 {
     static std::mutex stats_mutex;
-    stats_mutex.lock();
-
-    s_stats[0] = pkt_cnt.total_processed;
-    s_stats[1] = pkt_cnt.other_codecs;
-    s_stats[2] = pkt_cnt.discards;
-
-    // zeroing out the null/default codecs
-    s_stats[3] = 0;
-    s_stats[s_proto_map[FINISHED_DECODE] + stat_offset] = 0;
 
+    stats_mutex.lock();
     sum_stats(&g_stats[0], &s_stats[0], s_stats.size());
-
     stats_mutex.unlock();
 }
 
 static bool api_instantiated(const CodecApi* cd_api)
 {
-    static std::vector<bool> instantiated_api; // all elements initialized to false
-
-    if (instantiated_api.size() != s_codecs.size())
-        instantiated_api.resize(s_codecs.size());
+    // all elements initialize to false
+    static std::vector<bool> instantiated_api(s_codecs.size());
 
-    std::vector<const CodecApi*>::iterator p = std::find(s_codecs.begin(), s_codecs.end(), cd_api);
+    std::vector<const CodecApi*>::iterator p =
+        std::find(s_codecs.begin(), s_codecs.end(), cd_api);
 
     if (p == s_codecs.end())
         FatalError("PacketManager:: should never reach this code!!" \
                     "Cannot find Codec %s's api", cd_api->base.name);
 
     int pos = p - s_codecs.begin();
-
     if(instantiated_api[pos])
         return true;
 
@@ -399,6 +359,9 @@ void PacketManager::thread_init(void)
     if(!grinder)
         FatalError("PacketManager: Unable to find a Codec with data link type %d!!\n", daq_dlt);
 
+    if ( !ScReadMode() || ScPcapShow() )
+        LogMessage("Decoding with %s\n", s_protocols[grinder]->get_name());
+
     // ENCODER initialization
 
 #ifndef VALGRIND_TESTING
@@ -465,7 +428,7 @@ void PacketManager::decode(
 {
     PROFILE_VARS;
     uint16_t prot_id;
-    uint8_t mapped_prot;
+    uint8_t mapped_prot = grinder;
     uint16_t prev_prot_id = FINISHED_DECODE;
     uint16_t len, lyr_len;
 
@@ -476,8 +439,8 @@ void PacketManager::decode(
     p->pkth = pkthdr;
     p->pkt = pkt;
     len = pkthdr->caplen;
-    mapped_prot = grinder;
-    pkt_cnt.total_processed++;
+
+    s_stats[total_processed]++;
 
     // loop until the protocol id is no longer valid
     while(s_protocols[mapped_prot]->decode(pkt, len, p, lyr_len, prot_id))
@@ -502,13 +465,14 @@ void PacketManager::decode(
         }
     }
 
-    // if the final protocol ID is not the null codec
+    // if the final protocol ID is not the default codec, a Codec failed
     if (prev_prot_id != FINISHED_DECODE)
     {
+        // if the codec exists, it failed
         if(s_proto_map[prev_prot_id])
-            pkt_cnt.discards++;
+            s_stats[discards]++;
         else
-            pkt_cnt.other_codecs++;
+            s_stats[other_codecs]++;
     }
 
     s_stats[mapped_prot + stat_offset]++;
@@ -523,12 +487,6 @@ bool PacketManager::has_codec(uint16_t cd_id)
 }
 
 
-
-
-
-
-
-
 //-------------------------------------------------------------------------
 // encoders operate layer by layer:
 //-------------------------------------------------------------------------
@@ -756,13 +714,15 @@ void PacketManager::dump_stats()
 {
     std::vector<const char*> pkt_names;
 
-    for(unsigned int i = 0; i < gen_peg_names.size(); i++)
-        pkt_names.push_back(gen_peg_names[i]);
+    // zero out the default codecs
+    g_stats[3] = 0;
+    g_stats[s_proto_map[FINISHED_DECODE] + stat_offset] = 0;
 
+    for(unsigned int i = 0; i < stat_names.size(); i++)
+        pkt_names.push_back(stat_names[i]);
 
     for(int i = 0; s_protocols[i] != 0; i++)
-        if(s_protocols[i])
-            pkt_names.push_back(s_protocols[i]->get_name());
+        pkt_names.push_back(s_protocols[i]->get_name());
 
     show_percent_stats((PegCount*) &g_stats, &pkt_names[0], (unsigned int) pkt_names.size(),
         "codecs");
index 8d53f4d9ba5395d89817cbb3f1a1248292237c54..60e48b4bd66b467ed38685139e6da70b2d9dedc7 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2013-2013 Sourcefire, Inc.
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License Version 2 as
 #ifndef PACKET_MANAGER_H
 #define PACKET_MANAGER_H
 
-#include "snort_types.h"
+#include <array>
+#include <list>
 #include "framework/codec.h"
 #include "time/profiler.h"
 #include "utils/stats.h"
 #include "snort_config.h"
 
 
-#include <array>
-#include <list>
-
 struct Packet;
 
 //-------------------------------------------------------------------------
 
-/*
- *  E N C O D E R   F O O
- */
-
-// for encodeders
-#include "protocols/packet.h"
-#include "codecs/sf_protocols.h"
-#include "framework/codec.h"
-
-
-
-
-// TODO --> delete this!!
 #ifdef PERF_PROFILING
 extern THREAD_LOCAL PreprocStats decodePerfStats;
 #endif
@@ -57,8 +42,6 @@ extern THREAD_LOCAL PreprocStats decodePerfStats;
 /*
  *  PacketManager class
  */
-
-
 class PacketManager
 {
 public:
index 4ce95b1ac4a338672aef7cceb4e8c6dd4472b932..1ae9192621d2b4c472a8e125d8c8342b4648efe9 100644 (file)
@@ -80,7 +80,7 @@
 #include "snort_types.h"
 #include "snort_debug.h"
 #include "detect.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "event.h"
 #include "parser.h"
 #include "mstring.h"
@@ -91,6 +91,8 @@
 
 #include "arp_module.h"
 #include "framework/inspector.h"
+#include "protocols/layer.h"
+#include "protocols/arp.h"
 
 static const uint8_t bcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
@@ -190,24 +192,29 @@ void ArpSpoof::eval(Packet *p)
 {
     IPMacEntry *ipme;
     PROFILE_VARS;
+    const arp::EtherARP *ah;
+    const eth::EtherHdr *eh;
 
     // preconditions - what we registered for
-    assert(p->eh && p->ah);
+    assert((p->proto_bits & PROTO_BIT__ETH) && (p->proto_bits & PROTO_BIT__ARP));
+
+    ah = layer::get_arp_layer(p);
+    eh = layer::get_eth_layer(p);
 
     /* is the ARP protocol type IP and the ARP hardware type Ethernet? */
-    if ((ntohs(p->ah->ea_hdr.ar_hrd) != 0x0001) ||
-            (ntohs(p->ah->ea_hdr.ar_pro) != ETHERNET_TYPE_IP))
+    if ((ntohs(ah->ea_hdr.ar_hrd) != 0x0001) ||
+            (ntohs(ah->ea_hdr.ar_pro) != ETHERNET_TYPE_IP))
         return;
 
     PREPROC_PROFILE_START(arpPerfStats);
     ++asstats.total_packets;
 
-    switch(ntohs(p->ah->ea_hdr.ar_op))
+    switch(ntohs(ah->ea_hdr.ar_op))
     {
         case ARPOP_REQUEST:
             if (config->check_unicast_arp)
             {
-                if (memcmp((u_char *)p->eh->ether_dst, (u_char *)bcast, 6) != 0)
+                if (memcmp((u_char *)eh->ether_dst, (u_char *)bcast, 6) != 0)
                 {
                     SnortEventqAdd(GID_ARP_SPOOF,
                             ARPSPOOF_UNICAST_ARP_REQUEST);
@@ -216,8 +223,8 @@ void ArpSpoof::eval(Packet *p)
                             "MODNAME: Unicast request\n"););
                 }
             }
-            else if (memcmp((u_char *)p->eh->ether_src,
-                    (u_char *)p->ah->arp_sha, 6) != 0)
+            else if (memcmp((u_char *)eh->ether_src,
+                    (u_char *)ah->arp_sha, 6) != 0)
             {
                 SnortEventqAdd(GID_ARP_SPOOF,
                         ARPSPOOF_ETHERFRAME_ARP_MISMATCH_SRC);
@@ -227,8 +234,8 @@ void ArpSpoof::eval(Packet *p)
             }
             break;
         case ARPOP_REPLY:
-            if (memcmp((u_char *)p->eh->ether_src,
-                    (u_char *)p->ah->arp_sha, 6) != 0)
+            if (memcmp((u_char *)eh->ether_src,
+                    (u_char *)ah->arp_sha, 6) != 0)
             {
                 SnortEventqAdd(GID_ARP_SPOOF,
                         ARPSPOOF_ETHERFRAME_ARP_MISMATCH_SRC);
@@ -236,8 +243,8 @@ void ArpSpoof::eval(Packet *p)
                 DEBUG_WRAP(DebugMessage(DEBUG_PLUGIN,
                         "MODNAME: Ethernet/ARP mismatch reply src\n"););
             }
-            else if (memcmp((u_char *)p->eh->ether_dst,
-                    (u_char *)p->ah->arp_tha, 6) != 0)
+            else if (memcmp((u_char *)eh->ether_dst,
+                    (u_char *)ah->arp_tha, 6) != 0)
             {
                 SnortEventqAdd(GID_ARP_SPOOF,
                         ARPSPOOF_ETHERFRAME_ARP_MISMATCH_DST);
@@ -254,7 +261,7 @@ void ArpSpoof::eval(Packet *p)
         return;
 
     if ((ipme = LookupIPMacEntryByIP(config->ipmel,
-                                     *(uint32_t *)&p->ah->arp_spa)) == NULL)
+                                     *(uint32_t *)&ah->arp_spa)) == NULL)
     {
         DEBUG_WRAP(DebugMessage(DEBUG_PLUGIN,
                 "MODNAME: LookupIPMacEntryByIp returned NULL\n"););
@@ -268,9 +275,9 @@ void ArpSpoof::eval(Packet *p)
         /* If the Ethernet source address or the ARP source hardware address
          * in p doesn't match the MAC address in ipme, then generate an alert
          */
-        if ((memcmp((uint8_t *)p->eh->ether_src,
+        if ((memcmp((uint8_t *)eh->ether_src,
                 (uint8_t *)ipme->mac_addr, 6)) ||
-                (memcmp((uint8_t *)p->ah->arp_sha,
+                (memcmp((uint8_t *)ah->arp_sha,
                 (uint8_t *)ipme->mac_addr, 6)))
         {
             SnortEventqAdd(GID_ARP_SPOOF,
index 1eadef3481ac0eff167cb3211f85bf203e541b8c..83970c3a82f210a785f284da8fb38ecb553d119c 100644 (file)
@@ -278,7 +278,8 @@ static int Norm_ICMP6 (
 {
     ICMPHdr* h = (ICMPHdr*)(p->layers[layer].start);
 
-    if ( ((uint16_t)h->type == ICMP6_ECHO || (uint16_t)h->type == ICMP6_REPLY) &&
+    if ( ((uint16_t)h->type == icmp6::Icmp6Types::ECHO ||
+          (uint16_t)h->type == icmp6::Icmp6Types::REPLY) &&
          (h->code != 0) )
     {
         h->code = static_cast<icmp4::IcmpCode>(0);
index e8be6c0f866e46063df31d09ef9e553efa09ff21..663a174b4b28378776ea138fa26ed961c10d41c0 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef NORM_H
 #define NORM_H
 
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort.h"
 #include "normalize.h"
 
index 346800ce6a3bf715872f2f81826687987aee8a87..a66ac9483994cb9171d551b3e1de8e2cc55b05dd 100644 (file)
@@ -47,7 +47,7 @@
 #include "main/analyzer.h"
 #include "util.h"
 #include "snort_types.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort.h"
 
 THREAD_LOCAL SFBASE sfBase;
index 1443c86d05e51204007da9b82bde63e6ded9f79e..9fe17c17a5a27408416bb362b12580faad61ebc6 100644 (file)
@@ -52,7 +52,8 @@
 #include "perf_event.h"
 #include "snort_types.h"
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
+#include "main/thread.h"
 
 // Perf Flags
 #define SFPERF_BASE             0x00000001
index 50e2b280f15343d4b55aa29d53ad0e7f3c8beade..acf7879c26581e44dd0be3f2f8904e4bf3b880c7 100644 (file)
@@ -36,7 +36,7 @@
 #include "sfprocpidstats.h"
 #include "snort_types.h"
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
 
 #include <time.h>
 #include <stdio.h>
index 21c6d9b779a785ef56d5ed4de0f52bc4c21915cf..fe5d40bc8601bae8edbda063b766d619780da6aa 100644 (file)
@@ -31,7 +31,7 @@
 #include "snort_types.h"
 #include "sfxhash.h"
 #include "ipv6_port.h"
-#include "decode.h"
+#include "protocols/packet.h"
 
 #define SF_MAX_PKT_LEN  9000
 #define SF_MAX_PORT     UINT16_MAX
index 22363cda88c5fd7156e9bea5b7bffc4a95457b1c..39389703d07d43661e152d8660c7424928d63fe9 100644 (file)
@@ -55,7 +55,7 @@
 #include "ps_module.h"
 
 #include "main/analyzer.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "managers/packet_manager.h"
 #include "event.h"
 #include "event_wrapper.h"
index de90bc6e8294369f6fbe0aff4a02fff19f4db3b5..a59ed8a14a75fdd2549fa6e6d727d2d2e8169994 100644 (file)
 #include <sys/types.h>
 
 #include "snort.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "packet_time.h"
 #include "sfxhash.h"
 #include "ipobj.h"
index 297b760ef9daea2c5963a36d9a5f1ba3cdf0e12c..62b448b280678c0c41c6bb7e851e9e808ab51d45 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef ACTIVE_H
 #define ACTIVE_H
 
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort.h"
 #include "managers/packet_manager.h"
 
index 671b768a86cb608afd356a3a28f44def95b853cc..9bf79be0edb25a0832362555fb33d77f9b491ffd 100644 (file)
@@ -55,7 +55,7 @@
 #include "util.h"
 #include "mstring.h"
 #include "detect.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "fpcreate.h"
 #include "tag.h"
 #include "signature.h"
index b40a13c7f48042982a16560a7a00cb222b273a4d..9719f80db0a1f12eb22e8d47f9d864408f8e727c 100644 (file)
@@ -49,7 +49,7 @@
 #include "util.h"
 #include "mstring.h"
 #include "detect.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "fpcreate.h"
 #include "generators.h"
 #include "tag.h"
index 9487832a4656e1f75488da53348df38759f0d033..324c2d609fef50677ce390f09ae2f4091117410d 100644 (file)
@@ -48,7 +48,7 @@
 #include "util.h"
 #include "mstring.h"
 #include "detect.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "fpcreate.h"
 #include "tag.h"
 #include "signature.h"
index 93f41cfd40952b1d68e43facf82c4111fa4d8a6e..b522bf91aa2324a4c10ffdab860f24e7c52fb04e 100644 (file)
@@ -30,7 +30,7 @@
 #include "snort.h"
 #include "rules.h"
 #include "treenodes.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "main/policy.h"
 #include "sflsq.h"
 #include "util.h"
index 7947eca6d42573289cedb2436e9096df66f3b75f..0f7cd4f05ac0c7b30f2b1f701065493474061f59 100644 (file)
@@ -47,7 +47,7 @@
 #include "util.h"
 #include "mstring.h"
 #include "detect.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "fpcreate.h"
 #include "tag.h"
 #include "signature.h"
index 1491ecb6d73440c5a6d1579f38b0e0006028d3ef..22f1afc78e624a66972e18655d3f365d33b1a386 100644 (file)
@@ -1,24 +1,29 @@
 
 set (PROTOCOL_HEADERS
-    ipv4.h
-    tcp.h
-    packet.h
-    ipv6.h
-    udp.h
+    arp.h
+    eapol.h
     eth.h
     icmp4.h
     icmp6.h
+    ipv4.h
+    ipv6.h
     gre.h
-    arp.h
-    wlan.h
-    teredo.h
+    layer.h
+    linux_sll.h
     mpls.h
+    packet.h
     protocol_ids.h
+    tcp.h
+    teredo.h
+    token_ring.h
+    udp.h
+    wlan.h
+    vlan.h
 )
 
 add_library (protocols STATIC
     ${PROTOCOL_HEADERS}
-    ../codecs/template.cc  # CMake complains if we don't compile any files.  so use dummy file.  Linux will remove all of the symbols anyways.
+    layer.cc
 )
 
 install (FILES ${PROTOCOL_HEADERS}
index 08c8f72de14e0d15578bba6335e7ea8cae19b3a1..0e9f1d8898ac8b7bf0701487a17d76e4afe6d241 100644 (file)
@@ -2,25 +2,31 @@ AUTOMAKE_OPTIONS=foreign no-dependencies
 
 x_includedir = $(pkgincludedir)/protocols
 
-x_include_HEADERS = \
-packet.h
+noinst_LIBRARIES = libprotocols.a
 
-EXTRA_DIST = \
+x_include_HEADERS = \
 arp.h \
-decode.h \
-encode.h \
+eapol.h \
 eth.h \
-gre.h \
 icmp4.h \
 icmp6.h \
 ipv4.h \
 ipv6.h \
+gre.h \
+layer.h \
+layer.cc \
 mpls.h \
 protocol_ids.h \
 tcp.h \
 teredo.h \
+token_ring.h \
 udp.h \
-wlan.h
+vlan.h \
+wlan.h \
+packet.h
 
-AM_CXXFLAGS = @AM_CXXFLAGS@
+libprotocols_a_SOURCES = \
+layer.cc
 
+
+AM_CXXFLAGS = @AM_CXXFLAGS@
index 8dd60cc3bbc746d64c76f49d353363a226df8bc3..2c1ff5c360e99489be30aeb5585b3bf72189f564 100644 (file)
 #ifndef ARP_H
 #define ARP_H
 
-namespace arp{
-
-namespace detail{
-
-} // namespace detail
+namespace arp
+{
 
 
 
diff --git a/src/protocols/decode.h b/src/protocols/decode.h
deleted file mode 100644 (file)
index 1e4e846..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "codecs/decode.h"
diff --git a/src/protocols/eapol.h b/src/protocols/eapol.h
new file mode 100644 (file)
index 0000000..554f5c4
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+** Copyright (C) 2002-2013 Sourcefire, Inc.
+** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+
+#ifndef EAPOL_H
+#define EAPOL_H
+
+#ifndef NO_NON_ETHER_DECODER
+
+namespace eapol
+{
+
+struct EtherEapol
+{
+    uint8_t  version;  /* EAPOL proto version */
+    uint8_t  eaptype;  /* EAPOL Packet type */
+    uint16_t len;  /* Packet body length */
+};
+
+struct EAPHdr
+{
+    uint8_t code;
+    uint8_t id;
+    uint16_t len;
+};
+
+struct EapolKey
+{
+  uint8_t type;
+  uint8_t length[2];
+  uint8_t counter[8];
+  uint8_t iv[16];
+  uint8_t index;
+  uint8_t sig[16];
+};
+
+
+/* IEEE 802.1x eapol types */
+#define EAPOL_TYPE_EAP      0x00      /* EAP packet */
+#define EAPOL_TYPE_START    0x01      /* EAPOL start */
+#define EAPOL_TYPE_LOGOFF   0x02      /* EAPOL Logoff */
+#define EAPOL_TYPE_KEY      0x03      /* EAPOL Key */
+#define EAPOL_TYPE_ASF      0x04      /* EAPOL Encapsulated ASF-Alert */
+
+
+
+/* Extensible Authentication Protocol Codes RFC 2284*/
+#define EAP_CODE_REQUEST    0x01
+#define EAP_CODE_RESPONSE   0x02
+#define EAP_CODE_SUCCESS    0x03
+#define EAP_CODE_FAILURE    0x04
+/* EAP Types */
+#define EAP_TYPE_IDENTITY   0x01
+#define EAP_TYPE_NOTIFY     0x02
+#define EAP_TYPE_NAK        0x03
+#define EAP_TYPE_MD5        0x04
+#define EAP_TYPE_OTP        0x05
+#define EAP_TYPE_GTC        0x06
+#define EAP_TYPE_TLS        0x0d
+
+
+
+/* Extensible Authentication Protocol Codes RFC 2284*/
+#define EAP_CODE_REQUEST    0x01
+#define EAP_CODE_RESPONSE   0x02
+#define EAP_CODE_SUCCESS    0x03
+#define EAP_CODE_FAILURE    0x04
+/* EAP Types */
+#define EAP_TYPE_IDENTITY   0x01
+#define EAP_TYPE_NOTIFY     0x02
+#define EAP_TYPE_NAK        0x03
+#define EAP_TYPE_MD5        0x04
+#define EAP_TYPE_OTP        0x05
+#define EAP_TYPE_GTC        0x06
+#define EAP_TYPE_TLS        0x0d
+
+}
+
+#endif /* NO_NON_ETHER_DECODER */
+#endif /* EAPOL_H */
index 0761abc19509f7cc472fb57cf277877a54885525..052d6ef901d13c1274690d50eb2f5a68ea09fe7b 100644 (file)
 
 namespace gre{
 
-namespace detail{
-
-} // namespace detail
-
 /* GRE related stuff */
 struct GREHdr
 {
@@ -40,11 +36,6 @@ struct GREHdr
 
 } // namespace gre
 
-typedef gre::GREHdr GREHdr;
-
-
-
-
 #define GRE_VERSION(x) (x->version & 0x07)
 #define GRE_PROTO(x)   ntohs(x->ether_type)
 
index b7708a7b418c5ca8f7e90210f4f4ad93ab108b3f..967b70688b3291e781f799bcdd0db1b8d44898fd 100644 (file)
@@ -83,7 +83,7 @@ struct ICMP6NodeInfo
 //enum class Icmp6Types : std::uint8_t {
 enum Icmp6Types : std::uint8_t   {
     UNREACH = 1,
-    ICMP6_TYPE_BIG = 2,
+    BIG = 2,
     TIME = 3,
     PARAMS = 4,
     ECHO = 128,
@@ -111,16 +111,10 @@ inline uint16_t hdr_normal_len()
 
 //   Things that should be deleted immediately....which I bet will manage to make it into production
 
-#define ICMP6_UNREACH 1
-#define ICMP6_BIG    2
-#define ICMP6_TIME   3
-#define ICMP6_PARAMS 4
-#define ICMP6_ECHO   128
-#define ICMP6_REPLY  129
-#define ICMP6_SOLICITATION 133
-#define ICMP6_ADVERTISEMENT 134
-#define ICMP6_NODE_INFO_QUERY 139
-#define ICMP6_NODE_INFO_RESPONSE 140
+#if 1
+#define ICMP6_ECHO   icmp6::Icmp6Types::ECHO
+#define ICMP6_REPLY  icmp6::Icmp6Types::REPLY
+#endif
 
 typedef icmp6::ICMP6Hdr ICMP6Hdr;
 typedef icmp6::ICMP6TooBig ICMP6TooBig;
index fa56b696b7a11e8e1208cbdb7f50508de197d71a..e288119e3469a5fd2273bbd6d4edf6d7dcc71a95 100644 (file)
 #define IPV4_H
 
 #include <cstdint>
+
+
+#ifndef WIN32
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#else /* !WIN32 */
+#include <netinet/in_systm.h>
+#ifndef IFNAMSIZ
+#define IFNAMESIZ MAX_ADAPTER_NAME
+#endif /* !IFNAMSIZ */
+#endif /* !WIN32 */
+
 #include "sfip/sfip_t.h"
 #include "protocols/protocol_ids.h" // include ipv4 protocol numbers
 
diff --git a/src/protocols/layer.cc b/src/protocols/layer.cc
new file mode 100644 (file)
index 0000000..4d29af3
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+** Copyright (C) 2007-2013 Sourcefire, Inc.
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+// layer.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+
+#include "protocols/packet.h"
+
+namespace layer
+{
+
+static inline const uint8_t *find_layer(const Layer *lyr,
+                                uint8_t num_layers,
+                                uint16_t prot_id)
+{
+    for(int i = num_layers - 1; i >= 0 ; i--)
+    {
+        if (lyr->prot_id == prot_id)
+            return lyr->start;
+        lyr++;
+    }
+    return nullptr;
+}
+
+static inline const uint8_t *find_layer(const Layer *lyr,
+                                uint8_t num_layers,
+                                uint16_t prot_id1,
+                                uint16_t prot_id2)
+{
+    for(int i = num_layers - 1; i >= 0; i--)
+    {
+        if (lyr->prot_id == prot_id1 ||
+            lyr->prot_id == prot_id2)
+            return lyr->start;
+        lyr++;
+    }
+    return nullptr;
+}
+
+const arp::EtherARP* get_arp_layer(const Packet* p)
+{
+    uint8_t num_layers = p->next_layer;
+    const Layer *lyr = p->layers;
+
+    return reinterpret_cast<const arp::EtherARP*>(
+        find_layer(lyr, num_layers, ETHERTYPE_ARP, ETHERTYPE_REVARP));
+}
+
+const gre::GREHdr* get_gre_layer(const Packet* p)
+{
+    uint8_t num_layers = p->next_layer;
+    const Layer *lyr = p->layers;
+
+    return reinterpret_cast<const gre::GREHdr*>(
+        find_layer(lyr, num_layers, IPPROTO_ID_GRE));
+}
+
+const eapol::EtherEapol* get_eapol_layer(const Packet* p)
+{
+    uint8_t num_layers = p->next_layer;
+    const Layer *lyr = p->layers;
+
+    return reinterpret_cast<const eapol::EtherEapol*>(
+            find_layer(lyr, num_layers, ETHERTYPE_EAPOL));
+}
+
+const vlan::VlanTagHdr* get_vlan_layer(const Packet* p)
+{
+    uint8_t num_layers = p->next_layer;
+    const Layer *lyr = p->layers;
+
+    return reinterpret_cast<const vlan::VlanTagHdr*>(
+        find_layer(lyr, num_layers, ETHERTYPE_8021Q));
+}
+
+const eth::EtherHdr* get_eth_layer(const Packet* p)
+{
+    uint8_t num_layers = p->next_layer;
+    const Layer *lyr = p->layers;
+
+    // First, search for the inner eth layer (transbridging)
+    const eth::EtherHdr* eh = reinterpret_cast<const eth::EtherHdr*>(
+        find_layer(lyr, num_layers, ETHERTYPE_TRANS_ETHER_BRIDGING));
+
+    // if no inner eth layer, assume root layer is eth (callers job to confirm)
+    return eh ? eh : reinterpret_cast<const eth::EtherHdr*>(get_root_layer(p));
+}
+
+const uint8_t* get_root_layer(const Packet* p)
+{
+    // since token ring is the grinder, its the begining of the packet.
+    if (p->next_layer > 0)
+        return p->layers[0].start;
+    return nullptr;
+}
+
+} // namespace layer
diff --git a/src/protocols/layer.h b/src/protocols/layer.h
new file mode 100644 (file)
index 0000000..5bf3e4f
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+** Copyright (C) 2002-2013 Sourcefire, Inc.
+** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+#ifndef LAYER_H 
+#define LAYER_H
+
+#include <cstdint>
+#include "protocols/protocol_ids.h"
+#include "codecs/sf_protocols.h"
+
+
+
+struct Layer {
+    uint16_t prot_id;
+    PROTO_ID proto;
+    uint16_t length;
+    uint8_t* start;
+};
+
+
+// forward declaring relevent structs. Since we're only return a pointer,
+// there is no need for the actual header files
+
+namespace vlan
+{
+struct VlanTagHdr;
+}
+
+namespace arp
+{
+struct EtherARP;
+}
+
+namespace gre
+{
+struct GREHdr;
+}
+
+namespace eapol
+{
+struct EtherEapol;
+}
+
+namespace eth
+{
+struct EtherHdr;
+}
+
+
+// code maintained in header to ensure files to not depend on this library
+namespace layer
+{
+
+
+// signatures. No need to go searching for the correct function
+const arp::EtherARP* get_arp_layer(const Packet*);
+const vlan::VlanTagHdr* get_vlan_layer(const Packet*);
+const gre::GREHdr* get_gre_layer(const Packet*);
+const eapol::EtherEapol* get_eapol_layer(const Packet*);
+const eth::EtherHdr* get_eth_layer(const Packet*);
+const uint8_t* get_root_layer(const Packet*);
+
+
+} // namespace layer
+
+#endif
diff --git a/src/protocols/linux_sll.h b/src/protocols/linux_sll.h
new file mode 100644 (file)
index 0000000..092237f
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+** Copyright (C) 2002-2013 Sourcefire, Inc.
+** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+
+#ifndef LINUX_SLL_H
+#define LINUX_SLL_H
+
+#ifndef NO_NON_ETHER_DECODER
+
+namespace linux_sll
+{
+
+
+/* 'Linux cooked captures' data
+ * (taken from tcpdump source).
+ */
+
+#define SLL_HDR_LEN     16              /* total header length */
+#define SLL_ADDRLEN     8               /* length of address field */
+typedef struct _SLLHdr {
+        uint16_t       sll_pkttype;    /* packet type */
+        uint16_t       sll_hatype;     /* link-layer address type */
+        uint16_t       sll_halen;      /* link-layer address length */
+        uint8_t        sll_addr[SLL_ADDRLEN];  /* link-layer address */
+        uint16_t       sll_protocol;   /* protocol */
+} SLLHdr;
+
+/*
+ * ssl_pkttype values.
+ */
+
+#define LINUX_SLL_HOST          0
+#define LINUX_SLL_BROADCAST     1
+#define LINUX_SLL_MULTICAST     2
+#define LINUX_SLL_OTHERHOST     3
+#define LINUX_SLL_OUTGOING      4
+
+/* ssl protocol values */
+
+#define LINUX_SLL_P_802_3       0x0001  /* Novell 802.3 frames without 802.2 LLC header */
+#define LINUX_SLL_P_802_2       0x0004  /* 802.2 frames (not D/I/X Ethernet) */
+
+
+} // namespace ssl
+
+#endif /* NO_NON_ETHER_DECODER */
+#endif /* LINUX_SLL_H */
index 0d45603b96e47c9a44bfaf222d8c9d6ec4edf2e8..eb078d26851f214a2be25aadb07749fc326f39f3 100644 (file)
@@ -50,8 +50,10 @@ extern "C" {
 #include "sfip/ipv6_port.h"
 #include "sfip/sf_ip.h"
 #include "sfip/sf_iph.h"
+#include "codecs/sf_protocols.h"
 
-#include "codecs/layer.h"
+
+#include "protocols/layer.h"
 #include "protocols/ipv4.h"
 #include "protocols/ipv6.h"
 #include "protocols/tcp.h"
@@ -59,8 +61,6 @@ extern "C" {
 #include "protocols/eth.h"
 #include "protocols/icmp4.h"
 #include "protocols/icmp6.h"
-#include "protocols/arp.h"
-#include "protocols/gre.h"
 #include "protocols/mpls.h"
 
 /*  D E F I N E S  ************************************************************/
@@ -118,7 +118,7 @@ extern "C" {
 
 #define REASSEMBLED_PACKET_FLAGS (PKT_REBUILT_STREAM|PKT_REASSEMBLED_OLD)
 
-typedef enum {
+enum PseudoPacketType{
     PSEUDO_PKT_IP,
     PSEUDO_PKT_TCP,
     PSEUDO_PKT_DCE_RPKT,
@@ -129,7 +129,7 @@ typedef enum {
     PSEUDO_PKT_PS,
     PSEUDO_PKT_SDF,
     PSEUDO_PKT_MAX
-} PseudoPacketType;
+} ;
 
 /* error flags */
 #define PKT_ERR_CKSUM_IP     0x01
@@ -139,298 +139,6 @@ typedef enum {
 #define PKT_ERR_CKSUM_ANY    0x0F
 #define PKT_ERR_BAD_TTL      0x10
 
-/*  D A T A  S T R U C T U R E S  *********************************************/
-class Flow;
-
-#ifndef NO_NON_ETHER_DECODER
-/* Start Token Ring Data Structures */
-
-#ifdef _MSC_VER
-    /* Visual C++ pragma to disable warning messages about nonstandard bit field type */
-    #pragma warning( disable : 4214 )
-#endif
-
-/* LLC structure */
-typedef struct _Trh_llc
-{
-    uint8_t dsap;
-    uint8_t ssap;
-    uint8_t protid[3];
-    uint16_t ethertype;
-}        Trh_llc;
-
-/* RIF structure
- * Linux/tcpdump patch defines tokenring header in dump way, since not
- * every tokenring header with have RIF data... we define it separately, and
- * a bit more split up
- */
-
-#ifdef _MSC_VER
-  /* Visual C++ pragma to disable warning messages about nonstandard bit field type */
-  #pragma warning( disable : 4214 )
-#endif
-
-
-/* These are macros to use the bitlevel accesses in the Trh_Mr header
-
-   they haven't been tested and they aren't used much so here is a
-   listing of what used to be there
-
-   #if defined(WORDS_BIGENDIAN)
-      uint16_t bcast:3, len:5, dir:1, lf:3, res:4;
-   #else
-      uint16_t len:5,         length of RIF field, including RC itself
-      bcast:3,       broadcast indicator
-      res:4,         reserved
-      lf:3,      largest frame size
-      dir:1;         direction
-*/
-
-#define TRH_MR_BCAST(trhmr)  ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0xe000) >> 13)
-#define TRH_MR_LEN(trhmr)    ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x1F00) >> 8)
-#define TRH_MR_DIR(trhmr)    ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x0080) >> 7)
-#define TRH_MR_LF(trhmr)     ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x0070) >> 4)
-#define TRH_MR_RES(trhmr)     ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x000F))
-
-typedef struct _Trh_mr
-{
-    uint16_t bcast_len_dir_lf_res; /* broadcast/res/framesize/direction */
-    uint16_t rseg[8];
-}       Trh_mr;
-#ifdef _MSC_VER
-  /* Visual C++ pragma to enable warning messages about nonstandard bit field type */
-  #pragma warning( default : 4214 )
-#endif
-
-#define TR_ALEN             6        /* octets in an Ethernet header */
-#define FDDI_ALEN           6
-
-typedef struct _Trh_hdr
-{
-    uint8_t ac;        /* access control field */
-    uint8_t fc;        /* frame control field */
-    uint8_t daddr[TR_ALEN];    /* src address */
-    uint8_t saddr[TR_ALEN];    /* dst address */
-}        Trh_hdr;
-
-#ifdef WIN32
-    /* Visual C++ pragma to enable warning messages about nonstandard bit field type */
-    #pragma warning( default : 4214 )
-#endif
-/* End Token Ring Data Structures */
-
-
-/* Start FDDI Data Structures */
-
-/* FDDI header is always this: -worm5er */
-typedef struct _Fddi_hdr
-{
-    uint8_t fc;        /* frame control field */
-    uint8_t daddr[FDDI_ALEN];  /* src address */
-    uint8_t saddr[FDDI_ALEN];  /* dst address */
-}         Fddi_hdr;
-
-/* splitting the llc up because of variable lengths of the LLC -worm5er */
-typedef struct _Fddi_llc_saps
-{
-    uint8_t dsap;
-    uint8_t ssap;
-}              Fddi_llc_saps;
-
-/* I've found sna frames have two addition bytes after the llc saps -worm5er */
-typedef struct _Fddi_llc_sna
-{
-    uint8_t ctrl_fld[2];
-}             Fddi_llc_sna;
-
-/* I've also found other frames that seem to have only one byte...  We're only
-really intersted in the IP data so, until we want other, I'm going to say
-the data is one byte beyond this frame...  -worm5er */
-typedef struct _Fddi_llc_other
-{
-    uint8_t ctrl_fld[1];
-}               Fddi_llc_other;
-
-/* Just like TR the ip/arp data is setup as such: -worm5er */
-typedef struct _Fddi_llc_iparp
-{
-    uint8_t ctrl_fld;
-    uint8_t protid[3];
-    uint16_t ethertype;
-}               Fddi_llc_iparp;
-
-/* End FDDI Data Structures */
-
-
-/* 'Linux cooked captures' data
- * (taken from tcpdump source).
- */
-
-#define SLL_HDR_LEN     16              /* total header length */
-#define SLL_ADDRLEN     8               /* length of address field */
-typedef struct _SLLHdr {
-        uint16_t       sll_pkttype;    /* packet type */
-        uint16_t       sll_hatype;     /* link-layer address type */
-        uint16_t       sll_halen;      /* link-layer address length */
-        uint8_t        sll_addr[SLL_ADDRLEN];  /* link-layer address */
-        uint16_t       sll_protocol;   /* protocol */
-} SLLHdr;
-
-
-/*
- * Snort supports 3 versions of the OpenBSD pflog header:
- *
- * Pflog1_Hdr:  CVS = 1.3,  DLT_OLD_PFLOG = 17,  Length = 28
- * Pflog2_Hdr:  CVS = 1.8,  DLT_PFLOG     = 117, Length = 48
- * Pflog3_Hdr:  CVS = 1.12, DLT_PFLOG     = 117, Length = 64
- * Pflog3_Hdr:  CVS = 1.172, DLT_PFLOG     = 117, Length = 100
- *
- * Since they have the same DLT, Pflog{2,3}Hdr are distinguished
- * by their actual length.  The minimum required length excludes
- * padding.
- */
-/* Old OpenBSD pf firewall pflog0 header
- * (information from pf source in kernel)
- * the rule, reason, and action codes tell why the firewall dropped it -fleck
- */
-
-typedef struct _Pflog1_hdr
-{
-    uint32_t af;
-    char intf[IFNAMSIZ];
-    int16_t rule;
-    uint16_t reason;
-    uint16_t action;
-    uint16_t dir;
-} Pflog1Hdr;
-
-#define PFLOG1_HDRLEN (sizeof(struct _Pflog1_hdr))
-
-/*
- * Note that on OpenBSD, af type is sa_family_t. On linux, that's an unsigned
- * short, but on OpenBSD, that's a uint8_t, so we should explicitly use uint8_t
- * here.  - ronaldo
- */
-
-#define PFLOG_RULELEN 16
-#define PFLOG_PADLEN  3
-
-typedef struct _Pflog2_hdr
-{
-    int8_t   length;
-    uint8_t  af;
-    uint8_t  action;
-    uint8_t  reason;
-    char     ifname[IFNAMSIZ];
-    char     ruleset[PFLOG_RULELEN];
-    uint32_t rulenr;
-    uint32_t subrulenr;
-    uint8_t  dir;
-    uint8_t  pad[PFLOG_PADLEN];
-} Pflog2Hdr;
-
-#define PFLOG2_HDRLEN (sizeof(struct _Pflog2_hdr))
-#define PFLOG2_HDRMIN (PFLOG2_HDRLEN - PFLOG_PADLEN)
-
-typedef struct _Pflog3_hdr
-{
-    int8_t   length;
-    uint8_t  af;
-    uint8_t  action;
-    uint8_t  reason;
-    char     ifname[IFNAMSIZ];
-    char     ruleset[PFLOG_RULELEN];
-    uint32_t rulenr;
-    uint32_t subrulenr;
-    uint32_t uid;
-    uint32_t pid;
-    uint32_t rule_uid;
-    uint32_t rule_pid;
-    uint8_t  dir;
-    uint8_t  pad[PFLOG_PADLEN];
-} Pflog3Hdr;
-
-#define PFLOG3_HDRLEN (sizeof(struct _Pflog3_hdr))
-#define PFLOG3_HDRMIN (PFLOG3_HDRLEN - PFLOG_PADLEN)
-
-
-typedef struct _Pflog4_hdr
-{
-    uint8_t  length;
-    uint8_t  af;
-    uint8_t  action;
-    uint8_t  reason;
-    char     ifname[IFNAMSIZ];
-    char     ruleset[PFLOG_RULELEN];
-    uint32_t rulenr;
-    uint32_t subrulenr;
-    uint32_t uid;
-    uint32_t pid;
-    uint32_t rule_uid;
-    uint32_t rule_pid;
-    uint8_t  dir;
-    uint8_t  rewritten;
-    uint8_t  pad[2];
-    uint8_t saddr[16];
-    uint8_t daddr[16];
-    uint16_t sport;
-    uint16_t dport;
-} Pflog4Hdr;
-
-#define PFLOG4_HDRLEN sizeof(struct _Pflog4_hdr)
-#define PFLOG4_HDRMIN sizeof(struct _Pflog4_hdr)
-
-/*
- * ssl_pkttype values.
- */
-
-#define LINUX_SLL_HOST          0
-#define LINUX_SLL_BROADCAST     1
-#define LINUX_SLL_MULTICAST     2
-#define LINUX_SLL_OTHERHOST     3
-#define LINUX_SLL_OUTGOING      4
-
-/* ssl protocol values */
-
-#define LINUX_SLL_P_802_3       0x0001  /* Novell 802.3 frames without 802.2 LLC header */
-#define LINUX_SLL_P_802_2       0x0004  /* 802.2 frames (not D/I/X Ethernet) */
-#endif  // NO_NON_ETHER_DECODER
-
-
-#ifdef _MSC_VER
-  /* Visual C++ pragma to disable warning messages
-   * about nonstandard bit field type
-   */
-  #pragma warning( disable : 4214 )
-#endif
-
-#define VTH_PRIORITY(vh)  ((ntohs((vh)->vth_pri_cfi_vlan) & 0xe000) >> 13)
-#define VTH_CFI(vh)       ((ntohs((vh)->vth_pri_cfi_vlan) & 0x1000) >> 12)
-#define VTH_VLAN(vh)      ((uint16_t)(ntohs((vh)->vth_pri_cfi_vlan) & 0x0FFF))
-
-typedef struct _VlanTagHdr
-{
-    uint16_t vth_pri_cfi_vlan;
-    uint16_t vth_proto;  /* protocol field... */
-} VlanTagHdr;
-#ifdef _MSC_VER
-  /* Visual C++ pragma to enable warning messages about nonstandard bit field type */
-  #pragma warning( default : 4214 )
-#endif
-
-
-typedef struct _EthLlc
-{
-    uint8_t dsap;
-    uint8_t ssap;
-} EthLlc;
-
-typedef struct _EthLlcOther
-{
-    uint8_t ctrl;
-    uint8_t org_code[3];
-    uint16_t proto_id;
-} EthLlcOther;
 
 /* We must twiddle to align the offset the ethernet header and align
  * the IP header on solaris -- maybe this will work on HPUX too.
@@ -442,142 +150,34 @@ typedef struct _EthLlcOther
 #endif
 
 
-#ifndef NO_NON_ETHER_DECODER
-/*
- *  Wireless Header (IEEE 802.11)
- */
-typedef struct _WifiHdr
-{
-  uint16_t frame_control;
-  uint16_t duration_id;
-  uint8_t  addr1[6];
-  uint8_t  addr2[6];
-  uint8_t  addr3[6];
-  uint16_t seq_control;
-  uint8_t  addr4[6];
-} WifiHdr;
-
-
-struct EtherEapol
-{
-    uint8_t  version;  /* EAPOL proto version */
-    uint8_t  eaptype;  /* EAPOL Packet type */
-    uint16_t len;  /* Packet body length */
-};
-
-struct EAPHdr
-{
-    uint8_t code;
-    uint8_t id;
-    uint16_t len;
-};
-
-struct EapolKey
-{
-  uint8_t type;
-  uint8_t length[2];
-  uint8_t counter[8];
-  uint8_t iv[16];
-  uint8_t index;
-  uint8_t sig[16];
-};
-
-
-#endif  // NO_NON_ETHER_DECODER
-
-
-/* Can't add any fields not in the real header here
-   because of how the decoder uses structure overlaying */
-#ifdef _MSC_VER
-  /* Visual C++ pragma to disable warning messages
-   * about nonstandard bit field type
-   */
-  #pragma warning( disable : 4214 )
-#endif
-
-
-#define NUM_IP_PROTOS 256
-
-
-#ifndef IPPROTO_IP_MOBILITY
-#define IPPROTO_IP_MOBILITY     55
-#endif
-#ifndef IPPROTO_SUN_ND
-#define IPPROTO_SUN_ND          77
-#endif
-#ifndef IPPROTO_PIM
-#define IPPROTO_PIM             103
-#endif
-
-#define IP_OPTMAX               40
-#define TCP_OPTLENMAX           40 /* (((2^4) - 1) * 4  - TCP_HEADER_LEN) */
-const uint32_t IP6_EXTMAX = 8;
-
-
-
-#ifdef _MSC_VER
-  /* Visual C++ pragma to enable warning messages about nonstandard bit field type */
-  #pragma warning( default : 4214 )
-#endif
-
-
-/* Can't add any fields not in the real header here
-   because of how the decoder uses structure overlaying */
-#ifdef _MSC_VER
-  /* Visual C++ pragma to disable warning
-   * messages about nonstandard bit field type
-   */
-  #pragma warning( disable : 4214 )
-#endif
-
-
+/* default mpls flags */
+#define DEFAULT_MPLS_PAYLOADTYPE      MPLS_PAYLOADTYPE_IPV4
+#define DEFAULT_LABELCHAIN_LENGTH    -1
 
-#define ERSPAN_VERSION(x) ((ntohs(x->ver_vlan) & 0xf000) >> 12)
-#define ERSPAN_VLAN(x) (ntohs(x->ver_vlan) & 0x0fff)
-#define ERSPAN_SPAN_ID(x) (ntohs(x->flags_spanId) & 0x03ff)
-#define ERSPAN3_TIMESTAMP(x) (x->timestamp)
+const int32_t MAX_PORTS = 65536;
+const uint16_t NUM_IP_PROTOS = 256;
+const int16_t SFTARGET_UNKNOWN_PROTOCOL = -1;
+const uint8_t IP_OPTMAX = 40;
+const uint8_t TCP_OPTLENMAX = 40; /* (((2^4) - 1) * 4  - TCP_HEADER_LEN) */
+const uint8_t IP6_EXTMAX = 8;
+const uint8_t MIN_TTL = 64;
+const uint8_t MAX_TTL = 255;
 
 
 
-#ifdef _MSC_VER
-  /* Visual C++ pragma to enable warning messages
-   * about nonstandard bit field type
-   */
-  #pragma warning( default : 4214 )
-#endif
-
+/*  D A T A  S T R U C T U R E S  *********************************************/
+class Flow;
 
 
-typedef struct _Options
+struct Options
 {
     uint8_t code;
     uint8_t len; /* length of the data section */
     const uint8_t *data;
-} Options;
-
-
-
-
-/* PPPoEHdr Header; eth::EtherHdr plus the PPPoE Header */
-typedef struct _PPPoEHdr
-{
-    unsigned char ver_type;     /* pppoe version/type */
-    unsigned char code;         /* pppoe code CODE_* */
-    unsigned short session;     /* session id */
-    unsigned short length;      /* payload length */
-                                /* payload follows */
-} PPPoEHdr;
-
-/* PPPoE tag; the payload is a sequence of these */
-typedef struct _PPPoE_Tag
-{
-    unsigned short type;    /* tag type TAG_* */
-    unsigned short length;    /* tag length */
-                            /* payload follows */
-} PPPoE_Tag;
+} ;
 
 
-#define LAYER_MAX  32
+const uint8_t LAYER_MAX = 32;
 
 struct Packet
 {
@@ -589,21 +189,12 @@ struct Packet
     //^^^------------------------------------------------
 
     //vvv-----------------------------
-    EtherARP *ah;
-    const eth::EtherHdr *eh;         /* standard TCP/IP/Ethernet/ARP headers */
-    const VlanTagHdr *vh;
-    EthLlc *ehllc;
-    EthLlcOther *ehllcother;
-    const PPPoEHdr *pppoeh;     /* Encapsulated PPP of Ether header */
-    const GREHdr *greh;
-    uint32_t *mpls;
 
     const IPHdr *iph, *orig_iph;/* and orig. headers for ICMP_*_UNREACH family */
     const IPHdr *inner_iph;     /* if IP-in-IP, this will be the inner IP header */
     const IPHdr *outer_iph;     /* if IP-in-IP, this will be the outer IP header */
     const TCPHdr *tcph, *orig_tcph;
     const udp::UDPHdr *udph, *orig_udph;
-    const udp::UDPHdr *inner_udph;   /* if Teredo + UDP, this will be the inner UDP header */
     const udp::UDPHdr *outer_udph;   /* if Teredo + UDP, this will be the outer UDP header */
     const ICMPHdr *icmph, *orig_icmph;
 
@@ -672,34 +263,6 @@ struct Packet
     uint8_t GTPencapsulated;
     uint8_t next_layer;         /* index into layers for next encap */
 
-#ifndef NO_NON_ETHER_DECODER
-    const Fddi_hdr *fddihdr;    /* FDDI support headers */
-    Fddi_llc_saps *fddisaps;
-    Fddi_llc_sna *fddisna;
-    Fddi_llc_iparp *fddiiparp;
-    Fddi_llc_other *fddiother;
-
-    const Trh_hdr *trh;         /* Token Ring support headers */
-    Trh_llc *trhllc;
-    Trh_mr *trhmr;
-
-    Pflog1Hdr *pf1h;            /* OpenBSD pflog interface header - version 1 */
-    Pflog2Hdr *pf2h;            /* OpenBSD pflog interface header - version 2 */
-    Pflog3Hdr *pf3h;            /* OpenBSD pflog interface header - version 3 */
-    Pflog4Hdr *pf4h;            /* OpenBSD pflog interface header - version 4 */
-
-#ifdef DLT_LINUX_SLL
-    const SLLHdr *sllh;         /* Linux cooked sockets header */
-#endif
-#ifdef DLT_IEEE802_11
-    const WifiHdr *wifih;       /* wireless LAN header */
-#endif
-    const EtherEapol *eplh;     /* 802.1x EAPOL header */
-    const EAPHdr *eaph;
-    const uint8_t *eaptype;
-    EapolKey *eapolk;
-#endif
-
     // nothing after this point is zeroed ...
     ipv4::IpOptions ip_options[IP_OPTMAX];         /* ip options decode structure */
     Options tcp_options[TCP_OPTLENMAX];    /* tcp options decode struct */
@@ -745,6 +308,9 @@ struct Packet
 #define PROTO_BIT__ICMP     0x0010
 #define PROTO_BIT__TEREDO   0x0020
 #define PROTO_BIT__GTP      0x0040
+#define PROTO_BIT__MPLS     0x0080
+#define PROTO_BIT__VLAN     0x0100
+#define PROTO_BIT__ETH      0x0200
 #define PROTO_BIT__OTHER    0x8000
 #define PROTO_BIT__ALL      0xffff
 
@@ -814,5 +380,31 @@ static inline bool is_ip6(const Packet *p)
   return p->family == AF_INET6;
 }
 
+static inline uint16_t EXTRACT_16BITS(const uint8_t* p)
+{
+    return ntohs(*(uint16_t*)(p));
+}
+
+#ifdef WORDS_MUSTALIGN
+
+#if defined(__GNUC__)
+/* force word-aligned ntohl parameter */
+    static inline uint32_t EXTRACT_32BITS(const uint8_t* p)
+    {
+        uint32_t tmp;
+        memmove(&tmp, p, sizeof(uint32_t));
+        return ntohl(tmp);
+    }
+#endif /* __GNUC__ */
+
+#else
+
+/* allows unaligned ntohl parameter - dies w/SIGBUS on SPARCs */
+    static inline uint32_t EXTRACT_32BITS(const uint8_t* p)
+    {
+        return ntohl(*(uint32_t *)p);
+    }
+#endif /* WORDS_MUSTALIGN */
+
 #endif
 
index 3b59ecbae4eb7e0dd9ac3559e60d5aaa65dc46d2..03dce3d0ef9927e2e1c58029187ed29ee436d9ef 100644 (file)
@@ -53,6 +53,7 @@ const uint16_t IPPROTO_ID_IPIP = 4;
 const uint16_t IPPROTO_ID_IPV6 = 41;
 const uint16_t IPPROTO_ID_ROUTING = 43;
 const uint16_t IPPROTO_ID_FRAGMENT = 44;
+const uint16_t IPPROTO_ID_GRE = 47;
 const uint16_t IPPROTO_ID_ESP = 50;
 const uint16_t IPPROTO_ID_AH = 51; // RFC 4302
 const uint16_t IPPROTO_ID_ICMPV6 = 58;
@@ -82,9 +83,13 @@ const uint16_t PROTOCOL_GTP = 0x0102;
 
 const uint16_t ETHERTYPE_TRANS_ETHER_BRIDGING = 0x6558;
 const uint16_t ETHERTYPE_IPV4 = 0x0800;
+const uint16_t ETHERTYPE_REVARP = 0x8035;
+const uint16_t ETHERTYPE_ARP = 0x0806;
+const uint16_t ETHERTYPE_8021Q = 0x8100;
+const uint16_t ETHERTYPE_IPX = 0x8137;
 const uint16_t ETHERTYPE_IPV6 = 0x86dd;
 const uint16_t ETHERTYPE_PPP = 0x880B;
-const uint16_t ETHERTYPE_IPX = 0x8137;
+const uint16_t ETHERTYPE_EAPOL = 0x888e;
 
 
 #endif
diff --git a/src/protocols/token_ring.h b/src/protocols/token_ring.h
new file mode 100644 (file)
index 0000000..5132eb7
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+** Copyright (C) 2002-2013 Sourcefire, Inc.
+** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+
+#ifndef TOKEN_RING_H
+#define TOKEN_RING_H
+
+namespace token_ring{
+
+/* LLC structure */
+struct Trh_llc
+{
+    uint8_t dsap;
+    uint8_t ssap;
+    uint8_t protid[3];
+    uint16_t ethertype;
+} ;
+
+/* RIF structure
+ * Linux/tcpdump patch defines tokenring header in dump way, since not
+ * every tokenring header with have RIF data... we define it separately, and
+ * a bit more split up
+ */
+
+
+/* These are macros to use the bitlevel accesses in the Trh_Mr header
+
+   they haven't been tested and they aren't used much so here is a
+   listing of what used to be there
+
+   #if defined(WORDS_BIGENDIAN)
+      uint16_t bcast:3, len:5, dir:1, lf:3, res:4;
+   #else
+      uint16_t len:5,         length of RIF field, including RC itself
+      bcast:3,       broadcast indicator
+      res:4,         reserved
+      lf:3,      largest frame size
+      dir:1;         direction
+*/
+
+#define TRH_MR_BCAST(trhmr)  ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0xe000) >> 13)
+#define TRH_MR_LEN(trhmr)    ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x1F00) >> 8)
+#define TRH_MR_DIR(trhmr)    ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x0080) >> 7)
+#define TRH_MR_LF(trhmr)     ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x0070) >> 4)
+#define TRH_MR_RES(trhmr)     ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x000F))
+
+struct Trh_mr
+{
+    uint16_t bcast_len_dir_lf_res; /* broadcast/res/framesize/direction */
+    uint16_t rseg[8];
+};
+
+#define TR_ALEN             6        /* octets in an Ethernet header */
+#define FDDI_ALEN           6
+#define IPARP_SAP           0xaa
+
+struct Trh_hdr
+{
+    uint8_t ac;        /* access control field */
+    uint8_t fc;        /* frame control field */
+    uint8_t daddr[TR_ALEN];    /* src address */
+    uint8_t saddr[TR_ALEN];    /* dst address */
+};
+/* End Token Ring Data Structures */
+
+static inline const Trh_mr* get_trhmr(const Trh_llc* llc)
+{
+
+    if(llc->dsap != IPARP_SAP && llc->ssap != IPARP_SAP)
+        return reinterpret_cast<const Trh_mr *>(llc);
+
+    return nullptr;
+}
+
+} // namespace token_ring
+
+#endif
diff --git a/src/protocols/vlan.h b/src/protocols/vlan.h
new file mode 100644 (file)
index 0000000..49227c4
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+** Copyright (C) 2002-2013 Sourcefire, Inc.
+** Copyright (C) 1998-2002 Martin Roesch <roesch@sourcefire.com>
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License Version 2 as
+** published by the Free Software Foundation.  You may not use, modify or
+** distribute this program under any other version of the GNU General
+** Public License.
+**
+** 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.
+*/
+
+
+#ifndef VLAN_H
+#define VLAN_H
+
+namespace vlan
+{
+
+struct VlanTagHdr
+{
+    uint16_t vth_pri_cfi_vlan;
+    uint16_t vth_proto;  /* protocol field... */
+};
+
+
+static inline uint16_t vth_priority(const VlanTagHdr* vh)
+{
+    return (ntohs((vh)->vth_pri_cfi_vlan) & 0xe000) >> 13;
+}
+
+static inline uint16_t vth_cfi(const VlanTagHdr* vh)
+{
+    return (ntohs((vh)->vth_pri_cfi_vlan) & 0x1000) >> 12;
+}
+
+static inline uint16_t vth_vlan(const VlanTagHdr* vh)
+{
+    return ntohs((vh)->vth_pri_cfi_vlan) & 0x0FFF;
+}
+
+} // namespace vlan
+
+#endif
+
index 7677671646405d86550189930b1ac92d58d88346..d0fe5e0cce5ac53b0026cd7af3f73cabb56ff849 100644 (file)
 #ifndef WLAN_H
 #define WLAN_H
 
-#include <cstdint>
+#ifndef NO_NON_ETHER_DECODER
+
+namespace wlan
+{
+
+/*
+ *  Wireless Header (IEEE 802.11)
+ */
+struct WifiHdr
+{
+  uint16_t frame_control;
+  uint16_t duration_id;
+  uint8_t  addr1[6];
+  uint8_t  addr2[6];
+  uint8_t  addr3[6];
+  uint16_t seq_control;
+  uint8_t  addr4[6];
+} ;
 
 
 /* Frame type/subype combinations with version = 0 */
@@ -66,6 +83,9 @@
 #define WLAN_FLAG_WEP       0x4000    /* Wep Enabled  00000010 */
 #define WLAN_FLAG_ORDER     0x8000    /* Strict Order 00000001 */
 
+} // namespace wlan
+
+#endif
 
 #endif
 
index 38e083647b23444ffdcbcac36500190d12c19708..84ecf71c2257905a9b69dc752f490177051ab0ac 100644 (file)
 
 #include "snort_types.h"
 #include "detect.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "event.h"
 #include "parser.h"
 #include "snort_debug.h"
index 1d90c00aa96300ee93d562c93e039f97b9bd3931..ae046c975c3e2aec0d44d1b7310a45f1ad6add58 100644 (file)
@@ -33,8 +33,9 @@
 #define FT_MAIN_H
 
 #include "ftpp_ui_config.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "framework/bits.h"
+#include "time/profiler.h"
 
 #define BUF_SIZE 1024
 
index f4a60a56580c16eadb6bd1ef00bb3d0284b8c23d..63b0c048b7e794de3020e42f410415f2c812ac24 100644 (file)
@@ -24,7 +24,7 @@
 #define FTP_PARSE_H
 
 #include "ftpp_ui_config.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "framework/bits.h"
 
 /*
index 28d632ce053dee86c1909b77fdd18ce737bc8f83..8c71a860b0d2de6efb8200f1391132a6f7efd7a3 100644 (file)
@@ -36,7 +36,7 @@
 #include "snort_types.h"
 #include "sf_ip.h"
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
 
 #define GENERATOR_SPP_FTPP_FTP                     125
 #define GENERATOR_SPP_FTPP_TELNET                  126
index 241a9164cc46458cdb66b1cb94639caf165a435a..2493ca106baf4ce3aa687ffff5467061cf7e4d63 100644 (file)
@@ -44,7 +44,7 @@
 #include "ftpp_ui_config.h"
 #include "ftp_client.h"
 #include "ftp_server.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "file_api/file_api.h"
 #include "stream/stream_api.h"
 #include "flow/flow.h"
index 464fa7fee82da17ee2146435f12b5fe81f95e117..35fd4ad465e9bf48a74e0d8479629120ec65e852 100644 (file)
@@ -39,7 +39,7 @@
 
 #include <sys/types.h>
 
-//#include "decode.h"
+//#include "protocols/packet.h"
 #include "ftpp_ui_config.h"
 #include "ftpp_si.h"
 
index da3769c8ce08304fb8d95c6a1d64b2ab7cb7f77d..ed6c23148855efc8d2792b8b5d1003cfb66f1da9 100644 (file)
@@ -44,7 +44,7 @@
 /* RFC 1184 defines Abort, Suspend, and End of File telnet optinos */
 #define RFC1184
 
-//#include "decode.h"
+//#include "protocols/packet.h"
 #include "ftpp_ui_config.h"
 #include "ftpp_si.h"
 
index 33b374fae24177c57df896d7a3141b44bec1f61f..95a9f08ad01a8a740fd75e165bd72ff23d6929a0 100644 (file)
@@ -62,7 +62,7 @@
 
 #include "snort.h"
 #include "detect.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "event.h"
 #include "generators.h"
 #include "snort_debug.h"
index 65353bb408aa9d0aedca89521535e8721f21b606..1a0d84f7153bb9fb7d46ec2802cdb4da6605ae96 100644 (file)
@@ -27,7 +27,7 @@
 #include "config.h"
 #endif
 
-#include "decode.h"
+#include "protocols/packet.h"
 #include "stream/stream_api.h"
 #include "hi_ui_config.h"
 #include "util_utf.h"
index 19e7fda2199fb565f0b2f892d9a84b8d584fd9d3..ca54493d9dc417cb290069a2f28502fd81d0c5de 100644 (file)
@@ -63,7 +63,7 @@
 
 #include "generators.h"
 #include "hi_events.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort.h"
 #include "stream/stream_api.h"
 #include "snort_debug.h"
index 17cc90920e68498595d7d79d91f078b197e42e19..32b7c65121a968d62407a9b85975851808ff9023 100644 (file)
@@ -45,7 +45,7 @@
 #include "hi_ad.h"
 
 #include "ipv6_port.h"
-#include "decode.h"
+#include "protocols/packet.h"
 
 /*
 **  These are the defines for the different types of
index da36b67262ea4dc741053d428af653b810e930c8..c7daaf40e646df99cd62842bf2d152e40724d195 100644 (file)
@@ -58,7 +58,7 @@ Undefined symbols for architecture x86_64:
 #include <string.h>
 #include <sys/types.h>
 
-#include "decode.h"
+#include "protocols/packet.h"
 #include "snort_debug.h"
 #include "util.h"
 #include "parser.h"
index d7b31984f40b1d7cd87ab541860592d71378c0ea..67711fbfa7161dd7211d73cc853cf55fa6c741c1 100644 (file)
@@ -47,7 +47,7 @@
 #include <string>
 
 #include "rpc_module.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "parser.h"
 #include "snort_debug.h"
 #include "util.h"
index a83e4f0c1d343d494c9d449629b2c1904196db98..323b61813df78f33fd85c2889e0018d9110823c0 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 #endif
 #include <string.h>
-#include "decode.h"
+#include "protocols/packet.h"
 
 #define FAILURE -1
 #define SUCCESS 0
index c380780fd0f0332769d7381c1aa2ab5e4e4843de..e284e28aa042982c55cccf9ea329d0968955686e 100644 (file)
@@ -24,6 +24,7 @@ target_link_libraries( stream
     stream_icmp
     stream_tcp
     stream_udp
+    protocols
 )
 
 install (FILES ${STREAM_INCLUDES}
index 92e110ab5526dbe916e547a6e4684e8936832736..74b6e1d92d2115d41ce142d9a54724f18cbeab31 100644 (file)
@@ -8,3 +8,6 @@ add_library( stream_icmp STATIC
     stream_icmp.h
 )
 
+target_link_libraries( stream_icmp
+    protocols
+)
index 5910b9e2d9a2eaf5c80edd1a655e6e20f0edb43d..682040ff4dc654971e683912b983c5cef97d67ac 100644 (file)
@@ -30,7 +30,7 @@
 #include "icmp_session.h"
 #include "snort_types.h"
 #include "snort_debug.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "mstring.h"
 #include "sfxhash.h"
 #include "util.h"
@@ -40,6 +40,8 @@
 #include "flow/session.h"
 #include "perf_monitor/perf.h"
 #include "profiler.h"
+#include "protocols/layer.h"
+#include "protocols/vlan.h"
 
 static SessionStats gicmpStats;
 static THREAD_LOCAL SessionStats icmpStats;
@@ -135,8 +137,8 @@ static int ProcessIcmpUnreach(Packet *p)
         skey.port_h = sport;
     }
 
-    if (p->vh)
-        skey.vlan_tag = (uint16_t)VTH_VLAN(p->vh);
+    if (p->proto_bits & PROTO_BIT__VLAN)
+        skey.vlan_tag = vlan::vth_vlan(layer::get_vlan_layer(p));
     else
         skey.vlan_tag = 0;
 
index f4d75dcdf2c054c25deb77f55f609feb791338ca..23464d4401a1f9420d6912b564788709462e9979 100644 (file)
@@ -85,7 +85,7 @@
 #include "snort_bounds.h"
 #include "log_text.h"
 #include "detect.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "managers/packet_manager.h"
 #include "event.h"
 #include "util.h"
index 3e46452a0bc3e35270b3a0f376f09775d00bad28..060aee815bcac5abb5f2f98a2b144f634d97bad3 100644 (file)
@@ -45,7 +45,7 @@
 #include "icmp/stream_icmp.h"
 #include "ip/stream_ip.h"
 #include "mstring.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "detect.h"
 #include "generators.h"
 #include "perf_monitor/perf.h"
@@ -54,6 +54,8 @@
 #include "ipv6_port.h"
 #include "ips_options/ips_flowbits.h"
 #include "snort_debug.h"
+#include "protocols/layer.h"
+#include "protocols/vlan.h"
 
 #include "target_based/sftarget_protocol_reference.h"
 #include "target_based/sftarget_hostentry.h"
@@ -119,8 +121,9 @@ void Stream::populate_session_key(Packet *p, FlowKey *key)
         GET_SRC_IP(p), p->sp,
         GET_DST_IP(p), p->dp,
         GET_IPH_PROTO(p),
-        p->vh ? VTH_VLAN(p->vh) : 0,
-        p->mpls ? p->mplsHdr.label : 0,
+        // if the vlan protocol bit is defined, vlan layer gauranteed to exist
+        (p->proto_bits & PROTO_BIT__VLAN) ? vlan::vth_vlan(layer::get_vlan_layer(p)) : 0,
+        (p->proto_bits & PROTO_BIT__MPLS) ? p->mplsHdr.label : 0,
         addressSpaceId);
 }
 
index cb3a21b41d8a7a39fdc6e983ac869d870c66662f..0c92da0644867c2f0cc6354bc798d8aabe483401 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "flow/flow.h"
 #include "stream/stream_api.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "target_based/sftarget_protocol_reference.h"
 #include "framework/bits.h"
 
index b90ee46489dd287c1e00e408cab288e55d9e660c..d47916b2e273cb1f644c6a88021f1770a60f56af 100644 (file)
@@ -68,7 +68,7 @@
 #include "generators.h"
 #include "snort.h"
 #include "time/packet_time.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "managers/packet_manager.h"
 #include "log_text.h"
 #include "packet_io/active.h"
@@ -4401,17 +4401,20 @@ static inline int ValidMacAddress(
 {
     int i, j, ret = 0;
 
-    if (p->eh == NULL)
+    if (!(p->proto_bits & PROTO_BIT__ETH))
         return 0;
 
+    // if flag is set, gauranteed to have an eth layer
+    const eth::EtherHdr *eh = layer::get_eth_layer(p);
+
     for ( i = 0; i < 6; ++i )
     {
-        if ((talker->mac_addr[i] != p->eh->ether_src[i]))
+        if ((talker->mac_addr[i] != eh->ether_src[i]))
             break;
     }
     for ( j = 0; j < 6; ++j )
     {
-        if (listener->mac_addr[j] != p->eh->ether_dst[j])
+        if (listener->mac_addr[j] != eh->ether_dst[j])
             break;
     }
 
@@ -4438,16 +4441,19 @@ static inline void CopyMacAddr(
     int i;
 
     /* Not ethernet based, nothing to do */
-    if (p->eh == NULL)
+    if (!(p->proto_bits & PROTO_BIT__ETH))
         return;
 
+    // if flag is set, gauranteed to have an eth layer
+    const eth::EtherHdr *eh = layer::get_eth_layer(p);
+
     if (dir == FROM_CLIENT)
     {
         /* Client is SRC */
         for (i=0;i<6;i++)
         {
-            tcpssn->client.mac_addr[i] = p->eh->ether_src[i];
-            tcpssn->server.mac_addr[i] = p->eh->ether_dst[i];
+            tcpssn->client.mac_addr[i] = eh->ether_src[i];
+            tcpssn->server.mac_addr[i] = eh->ether_dst[i];
         }
     }
     else
@@ -4455,8 +4461,8 @@ static inline void CopyMacAddr(
         /* Server is SRC */
         for (i=0;i<6;i++)
         {
-            tcpssn->server.mac_addr[i] = p->eh->ether_src[i];
-            tcpssn->client.mac_addr[i] = p->eh->ether_dst[i];
+            tcpssn->server.mac_addr[i] = eh->ether_src[i];
+            tcpssn->client.mac_addr[i] = eh->ether_dst[i];
         }
     }
 }
index fbf5f1c7b246f198889ecd2dfe6ccdc7b602d558..aa3cd0b694d932960f635a007ced94601f85d6c2 100644 (file)
@@ -35,7 +35,7 @@
 #include "mstring.h"
 #include "sfxhash.h"
 #include "util.h"
-#include "decode.h"
+#include "protocols/packet.h"
 #include "flow/flow_control.h"
 #include "flow/session.h"
 #include "rules.h"
index bbd07f23135a89748558488198ae1482f3020c98..a42d3c73f8f2cddc4962c9e7edb7ce8db6992e16 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef SFTARGET_PROTOCOL_REFERENCE_H
 #define SFTARGET_PROTOCOL_REFERENCE_H
 
-#include "decode.h"
+#include "protocols/packet.h"
 #include "util.h"
 #include "sftarget_data.h"
 
index 1fab5dad981e576f36c89c23bb5c3e155fc74b06..dc240aee3d9cc75d2931da7bd97c4dbffb06165f 100644 (file)
 
-if ( TESTING_ENABLED )
+if ( BUILD_UNIT_TESTS )
 
-#find_package(GCOV)
+find_package(CHECK REQUIRED)
+include_directories(${CHECK_INCLUDE_DIR})
+include_directories(${CMAKE_CURRENT_BINARY_DIR})  # for generated files
 
-message ("cmake path = ..${CMAKE_MODULE_PATH}..")
 
-#SET (CHECK_DIR "${CMAKE_MODULE_PATH}")
-find_package(CHECK)
-find_package(GCOV)
-
-
-# build sf_ip_test
-
-
-
-# BUILDING SF_IP_TEST:
-
-
-add_executable (sf_ip_test sf_ip_test.cc)
-add_compile_flags (sf_ip_test "--std=gnu++11 -O0 -Wall -fprofile-arcs -ftest-coverage -DSF_IP_TEST -C ${CMAKE_CURRENT_BINARY_DIR}")
-add_link_flags (sf_ip_test "-g -O0 -Wall -fprofile-arcs -ftest-coverage -DSF_IP_TEST")
-target_link_libraries ( sf_ip_test
-    policy
-    sfrt
-    sfip
-    utils
-    ${CHECK_LIBRARY}
-    ${MATH_LIBRARY}
+#  Generating build_decl.h  Will rebuild every time 'make' is run
+add_custom_target(build_suit_decl ALL
+    COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_list.sh ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}
+    COMMENT "building suite_decl.h"
 )
-
-
-# BUILDING SFTHD_TEST
-
-#add_executable ( sfthd_test
-#    sfthd_test.cc
-#    unit_hacks.cc
-#    unit_hacks.h
-#    ${CMAKE_SOURCE_DIR}/src/filters/sfthd.cc
-#)
-
-#add_compile_flags (sfthd_test "-DSFTHD_TEST")
-#target_link_libraries ( sfthd_test
-#    policy
-#    sfrt
-#    sfip
-#    utils
-#    ${CHECK_LIBRARY}
-#    ${MATH_LIBRARY}
-#)
-
-# BUILDDING SFRF_TEST
-
-#add_executable (sfrf_test
-#    sfrf_test.cc
-#    unit_hacks.cc 
-#    unit_hacks.h 
-#    ${CMAKE_SOURCE_DIR}/src/filters/sfrf.cc
-#)
-#add_compile_flags (sfrf_test "-DSFRF_TEST")
-#target_link_libraries ( sfrf_test
-#    policy
-#    sfrt
-#    sfip
-#    utils
-#    ${CHECK_LIBRARY}
-#    ${MATH_LIBRARY}
-#)
-
-
-# BUILDING SFRF_TEST
-#add_executable ( sfrt_test sfrt_test.cc )
-#target_link_libraries (sfrf_test
-#    policy
-#    sfrt
-#    sfip
-#    utils
-#    ${CHECK_LIBRARY}
-#    ${MATH_LIBRARY}
-#)
-
-
-ADD_CUSTOM_TARGET( check
-    COMMAND "${CMAKE_CURRENT_BINARY_DIR}/sf_ip_test"
-#    COMMAND "${CMAKE_CURRENT_BINARY_DIR}/sfthd_test"
-#    COMMAND "${CMAKE_CURRENT_BINARY_DIR}/sfrf_test"
-#    COMMAND "${CMAKE_CURRENT_BINARY_DIR}/sfrt_test"
-    DEPENDS sf_ip_test
-#            sfthd_test
-#            sfrf_test
-#            sfrt_test
+add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/suite_decl.h
+    COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${CMAKE_CURRENT_BINARY_DIR}/suite_decl.h
+    DEPENDS build_suit_decl
 )
 
 
-
-# BUILDING AND RUNNING GCOV PROJECTS
-
-message ("CHECK_LIBRARY = ${CHECK_LIBRARY}")
-message ("MATH_LIBRARY = ${MATH_LIBRARY}")
-
-
-add_executable ( sf_ip_gcov_prog
-    ../sfip/sf_ip.cc
-    sf_ip_test.cc
+#  Generating suite_list.h  Will rebuild every time 'make' is run
+add_custom_target(build_suite_list ALL
+    COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_decl.sh ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}
+    COMMENT "building suite_list.h"
 )
-include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..")
-add_compile_flags (sf_ip_gcov_prog "--std=gnu++11 -O0 -Wall -fprofile-arcs -ftest-coverage -DSF_IP_TEST -C ${CMAKE_CURRENT_BINARY_DIR}")
-add_link_flags (sf_ip_gcov_prog "-g -O0 -Wall -fprofile-arcs -ftest-coverage -DSF_IP_TEST")
-#CFLAGS="-g -O0 -Wall -W -fprofile-arcs -ftest-coverage"
-#LDFLAGS="-fprofile-arcs -ftest-coverage"
-target_link_libraries ( sf_ip_gcov_prog
-    ${CHECK_LIBRARY}
-    ${MATH_LIBRARY}
+add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/suite_list.h
+    COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${CMAKE_CURRENT_BINARY_DIR}/suite_list.h
+    DEPENDS build_suite_list
 )
 
-message ("current binary directory is ${CMAKE_CURRENT_BINARY_DIR}")
-
-ADD_CUSTOM_TARGET ( sf_ip_gcov
-    COMMAND "${CMAKE_CURRENT_BINARY_DIR}/sf_ip_gcov_prog"
-    COMMAND ${GCOV_EXECUTABLE}
-            -o ${CMAKE_CURRENT_BINARY_DIR} 
-            ${CMAKE_SOURCE_DIR}/src/sfip/sf_ip.cc
-    COMMAND ${GCOV_EXECUTABLE}
-            -o ${CMAKE_CURRENT_BINARY_DIR} 
-            ${CMAKE_CURRENT_SOURCE_DIR}/sf_ip_test.cc
-    DEPENDS sf_ip_gcov_prog
+add_library(unit_tests STATIC
+    ${CMAKE_CURRENT_BINARY_DIR}/suite_decl.h
+    ${CMAKE_CURRENT_BINARY_DIR}/suite_list.h
+    sfip_test.cc
+    sfrf_test.cc
+    sfrt_test.cc
+    sfthd_test.cc
+    unit_test.cc
+    unit_test.h
 )
 
+target_link_libraries(unit_tests
+    ${CHECK_LIBRARIES}
+)
 
-#ADD_CUSTOM_TARGET ( gcov_tests 
-#    DEPENDS sf_ip_gcov
-#            sfthc_gcov
-#            sfrf_gcov
-#            sfrt_gcov
-#)
-
-
-#sf_ip_gcov:
-#      g++ -g -O0 -Wall -fprofile-arcs -ftest-coverage -o sf_ip_test -DSF_IP_TEST -lm -lcheck -I.. ../sf_ip.cc sf_ip_test.cc 
-#      ./sf_ip_test
-#      gcov ../sf_ip.cc
-#      gcov sf_ip_test.cc
-
-#sfthd_gcov:
-#      g++ -g -O0 -Wall -fprofile-arcs -ftest-coverage -o sfthd_test -lm -lcheck -I.. -I../.. sfthd_test.cc ../sfthd.cc $(top_builddir)/src/utils/libutils.a
-#      ./sfthd_test
-#      gcov ../sfthd.cc
-#      gcov sfthd_test.cc
-
-#sfrf_gcov:
-#      g++ -g -O0 -Wall -fprofile-arcs -ftest-coverage -o sfrf_test -lm -lcheck -I.. -I../.. sfrf_test.cc ../sfrf.cc $(top_builddir)/src/utils/libutils.a
-#      ./sfrf_test
-#      gcov ../sfrf.cc
-#      gcov sfrf_test.cc
-       
-#sfrt_gcov:
-#      g++ -g -O0 -Wall -fprofile-arcs -ftest-coverage -o sfrt_test -lm -lcheck -I.. -I../.. sfrt_test.cc ../sfrt.cc 
-#      ./sfrt_test
-#      gcov ../sfrt.cc
-#      gcov sfrt_test.cc
+set_source_files_properties( unit_test.cc PROPERTIES
+    OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/suite_decl.h
+    OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/suite_list.h
+)
 
-endif( TESTING_ENABLED)
+endif()
diff --git a/src/test/build_decl.sh b/src/test/build_decl.sh
new file mode 100755 (executable)
index 0000000..a70289d
--- /dev/null
@@ -0,0 +1,10 @@
+#/bin/bash
+
+SOURCE_DIR=$1
+FILE=$2/suite_decl.h
+
+rm -f $FILE ;
+for f in `grep -whoR --include \*.cc 'TEST_SUITE[^(]*' $SOURCE_DIR` ; do
+    echo "extern Suite* $f();" >> $FILE ;
+done ;
+touch unit_test.cc
diff --git a/src/test/build_list.sh b/src/test/build_list.sh
new file mode 100755 (executable)
index 0000000..865a0ed
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+SOURCE_DIR=$1
+FILE=$2/suite_list.h
+
+rm -f $FILE ;
+for f in `grep -whoR --include \*.cc 'TEST_SUITE[^(]*' $SOURCE_DIR` ; do
+    echo "$f," >> $FILE ;
+done ;
+touch unit_test.cc
index 4395dfccdd9bada1a617115f422578fd81224d7c..8bf98b6a3cad09b9d9518ebed15dc6b2f001cdbf 100644 (file)
@@ -62,7 +62,6 @@
 #include "rules.h"
 #include "treenodes.h"
 #include "treenodes.h"
-#include "decode.h"
 #include "parser.h"
 #include "util.h"
 #include "rules.h"
@@ -74,6 +73,7 @@
 #include "detection/detect.h"
 #include "detection/fpdetect.h"
 #include "actions/actions.h"
+#include "protocols/packet.h"
 
 #ifdef PPM_MGR