{"id":2227080,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2227080/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/patch/20260423082003.28493-1-wegao@suse.com/","project":{"id":59,"url":"http://patchwork.ozlabs.org/api/1.1/projects/59/?format=json","name":"Linux Test Project development","link_name":"ltp","list_id":"ltp.lists.linux.it","list_email":"ltp@lists.linux.it","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260423082003.28493-1-wegao@suse.com>","date":"2026-04-23T08:20:01","name":"[v1] ns-tools: Restore ns-icmpv4_sender","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"a7c13dbd6a52c74184c04536552885f41cf06509","submitter":{"id":85577,"url":"http://patchwork.ozlabs.org/api/1.1/people/85577/?format=json","name":"Wei Gao","email":"wegao@suse.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/ltp/patch/20260423082003.28493-1-wegao@suse.com/mbox/","series":[{"id":501158,"url":"http://patchwork.ozlabs.org/api/1.1/series/501158/?format=json","web_url":"http://patchwork.ozlabs.org/project/ltp/list/?series=501158","date":"2026-04-23T08:20:01","name":"[v1] ns-tools: Restore ns-icmpv4_sender","version":1,"mbox":"http://patchwork.ozlabs.org/series/501158/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2227080/comments/","check":"fail","checks":"http://patchwork.ozlabs.org/api/patches/2227080/checks/","tags":{},"headers":{"Return-Path":"<ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>","X-Original-To":["incoming@patchwork.ozlabs.org","ltp@lists.linux.it"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","ltp@picard.linux.it"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=lists.linux.it header.i=@lists.linux.it\n header.a=rsa-sha256 header.s=picard header.b=Bv29w8Cz;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256\n header.s=google header.b=cjK37uKB;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it\n (client-ip=2001:1418:10:5::2; helo=picard.linux.it;\n envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it;\n receiver=patchwork.ozlabs.org)"],"Received":["from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g1TYG6pjyz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 18:20:17 +1000 (AEST)","from picard.linux.it (localhost [IPv6:::1])\n\tby picard.linux.it (Postfix) with ESMTP id 44BCF3E2D77\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 10:20:15 +0200 (CEST)","from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it\n [IPv6:2001:4b78:1:20::3])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n (No client certificate requested)\n by picard.linux.it (Postfix) with ESMTPS id E1D5F3E18DC\n for <ltp@lists.linux.it>; Thu, 23 Apr 2026 10:20:11 +0200 (CEST)","from mail-wr1-x429.google.com (mail-wr1-x429.google.com\n [IPv6:2a00:1450:4864:20::429])\n (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 706C01A0091B\n for <ltp@lists.linux.it>; Thu, 23 Apr 2026 10:20:10 +0200 (CEST)","by mail-wr1-x429.google.com with SMTP id\n ffacd0b85a97d-43d74086e5bso6203746f8f.0\n for <ltp@lists.linux.it>; Thu, 23 Apr 2026 01:20:10 -0700 (PDT)","from localhost ([2a07:de40:b240:0:2ad6:ed42:2ad6:ed42])\n by smtp.gmail.com with UTF8SMTPSA id\n ffacd0b85a97d-43fe4cb1249sm48034582f8f.5.2026.04.23.01.20.08\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 23 Apr 2026 01:20:08 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it;\n i=@lists.linux.it; q=dns/txt; s=picard; t=1776932415; h=to : date :\n message-id : mime-version : subject : list-id : list-unsubscribe :\n list-archive : list-post : list-help : list-subscribe : from :\n reply-to : content-type : content-transfer-encoding : sender : from;\n bh=1Y4iNy6HMRVlaqcb4Yz7+DM+CEikuGbk5HTOukdbftA=;\n b=Bv29w8CzqH2e2fES5YYD0PqL9ZXgJsP5Bwfw+zyM7pprBW7e2AL+ix89fCRGN57Wu0Alb\n K7eR0bofVOoGlNeOsPd/ZizCR+VyPWbOQy1PJVRgOQZLXdCraf6Yqc4FwNRkcAXDOhLqNbd\n xn2fdlKkvlVqeIHhrnOeWK1GCyCo8h0=","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=suse.com; s=google; t=1776932409; x=1777537209; darn=lists.linux.it;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:from:to:cc:subject:date:message-id:reply-to;\n bh=8IyhkRP2GH/Q4mWr1xOz5R01an2p4E0XlYfmHinv4Bw=;\n b=cjK37uKBg/nlPBp0PPJ/8c8sTryGQL1sFo7KuuKPsJr0pMFRUwZPubWJWDEW7LW1y/\n 6dCQcG96v2+uyKK/HVFng3Sg8lOx4zyOHsTwWHvQ4CHMnoswvKu7+zgUKVX2xUFdSkA/\n 8bbcUGr9mC6ffLBoJfNLMGlWD04CvqmwDR2LJq2oUTQd/CyThZiYUDNc59Hw2fYZWjzS\n Yj6sYefWSzIzSFPC0YLh6qW1j3TRYocZkbZ9yItpaZfTwYoMZuh4AekhTwLEAOsvkVi0\n L13Q58GRwG1uwBe+pnODG43YDWKZsGmzYnNdBxpTYF+sbzW97hqRbqwxk2wO8ixLFUWh\n mG4w=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776932409; x=1777537209;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=8IyhkRP2GH/Q4mWr1xOz5R01an2p4E0XlYfmHinv4Bw=;\n b=QxY4d3Ja22hhEcdrP1NoLfYE1FQoIhX3VffqK1U1G4Q4ibgbtDOpT3Ra0XA2wbV7t2\n gNpeVi7tA1mWjm1F2t+1LwS4to1N3du7ynqqNrRVAKZADPGFP9JJR09UHRqRcJCg340e\n vIrgliUxZ4b/Cy2l8OV+/UUnWpCFJKnsrpnjcjE6Lwv5uYWuJ+9iktJ06fuxYIaBUy0h\n tlHnUloZcPPoVdQ8QPaSt5VUfLoEftnn3wZ1JkjA5xWzNsLYgNZX9Y/YxDqi+OU4nYJ3\n YNE2UMQGXpc0ftsuSwSV/eCTCpop9eCMM9n5yp2SgvzB3PVmDr4CQRDX7cfG3FHIiLQx\n MHgw==","X-Gm-Message-State":"AOJu0YyAlZWaQQGphfivZkhDIcEP06xurEreN39DvptsYXILRD+xQhQR\n naUB3kU96tkwcJ2flmixi0wS3o6vBZYqs5kB1SkgMaAEH8M1TZy2RmvqEoBi4M6f+Pc2E2znlDQ\n gDI4=","X-Gm-Gg":"AeBDietjAlVAjhOQYW5slt1IJh/gh72D6WeUxh+rFFu4RgfkcwZnxj487t0nKH1i7qc\n IIcCVzjXqZ4/mmHGZ131KuObUDUiIKZq5f+rNwpIe8R8K9x+UdQM3HN3Lerr4jteTSx4heWCJFJ\n D/Tk74s5hWFBA7fH6vLr0A9rHIgbNsxHw51YEVjh3nq2f4d+XH/h5NlwVfoy71wkVlu5s3vqPmw\n heOpz2waJJkIJO/gwTILmegEZ5y5//yjcGWfbNAU7CpHOIXBMj7BDG6+RvsXxChz6utnilEnPYB\n 8OzXYuHNT1OUZ4TOWk3CZ0rGX5VliYCVge9ZzNJtKDwu9DHaCM/FXEf0df7egTaTpRQAKRPzH+G\n IZtBpDTle3GqdiNrpdnpk3RLozAjOS85nK4v3lnA/I0++3rN3k2tE+OfmZ+lm5A3eJ2j/UfmT3W\n 9/R8d4ZGC/w6RhSmirhsuhig==","X-Received":"by 2002:a05:6000:40cb:b0:43e:aa43:243 with SMTP id\n ffacd0b85a97d-43fe3e24eaamr40568923f8f.43.1776932409407;\n Thu, 23 Apr 2026 01:20:09 -0700 (PDT)","To":"ltp@lists.linux.it","Date":"Thu, 23 Apr 2026 08:20:01 +0000","Message-ID":"<20260423082003.28493-1-wegao@suse.com>","X-Mailer":"git-send-email 2.43.0","MIME-Version":"1.0","X-Spam-Status":"No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID,\n DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no\n autolearn=disabled version=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on in-3.smtp.seeweb.it","X-Virus-Scanned":"clamav-milter 1.0.9 at in-3.smtp.seeweb.it","X-Virus-Status":"Clean","Subject":"[LTP] [PATCH v1] ns-tools: Restore ns-icmpv4_sender","X-BeenThere":"ltp@lists.linux.it","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"Linux Test Project <ltp.lists.linux.it>","List-Unsubscribe":"<https://lists.linux.it/options/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=unsubscribe>","List-Archive":"<http://lists.linux.it/pipermail/ltp/>","List-Post":"<mailto:ltp@lists.linux.it>","List-Help":"<mailto:ltp-request@lists.linux.it?subject=help>","List-Subscribe":"<https://lists.linux.it/listinfo/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=subscribe>","From":"Wei Gao via ltp <ltp@lists.linux.it>","Reply-To":"Wei Gao <wegao@suse.com>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it","Sender":"\"ltp\" <ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>"},"content":"Commit 19c9b694c6b (\"ns-tools: Remove unused tools\") removed\nns-icmpv4_sender.c, assuming it was unused. However, it is still\nrequired by broken_ip tests (e.g. broken_ip4-version, broken_ip4-ihl),\nwhich were not removed.\n\nRestore ns-icmpv4_sender.c and update Makefile, .gitignore and\n00_Descriptions.txt accordingly.\n\nFixes: 19c9b694c6b (\"ns-tools: Remove unused tools\")\nSigned-off-by: Wei Gao <wegao@suse.com>\n---\n testcases/network/.gitignore                  |   1 +\n .../stress/ns-tools/00_Descriptions.txt       |   4 +\n testcases/network/stress/ns-tools/Makefile    |   2 +-\n .../stress/ns-tools/ns-icmpv4_sender.c        | 622 ++++++++++++++++++\n 4 files changed, 628 insertions(+), 1 deletion(-)\n create mode 100644 testcases/network/stress/ns-tools/ns-icmpv4_sender.c","diff":"diff --git a/testcases/network/.gitignore b/testcases/network/.gitignore\nindex 00b73161c..3ebb6e33c 100644\n--- a/testcases/network/.gitignore\n+++ b/testcases/network/.gitignore\n@@ -26,6 +26,7 @@\n /sockets/ltpServer\n /sockets/vsock01\n /stress/ns-tools/ns-icmp_redirector\n+/stress/ns-tools/ns-icmpv4_sender\n /stress/ns-tools/ns-icmpv6_sender\n /stress/ns-tools/ns-igmp_querier\n /stress/ns-tools/ns-mcast_join\ndiff --git a/testcases/network/stress/ns-tools/00_Descriptions.txt b/testcases/network/stress/ns-tools/00_Descriptions.txt\nindex 56a221b71..b0fb2188c 100644\n--- a/testcases/network/stress/ns-tools/00_Descriptions.txt\n+++ b/testcases/network/stress/ns-tools/00_Descriptions.txt\n@@ -10,6 +10,10 @@ ns-icmp_redirector (binary)\n \tgateway. When the utility receives the packet from the host\n \tunder test. This utility reply ICMP redirect message.\n \n+ns-icmpv4_sender (binary)\n+\tICMPv4 echo request sender.\n+\tThis utility is also able to set illegal information in the IP header\n+\n ns-icmpv6_sender (binary)\n \tICMPv6 message (Echo request / MLDv2 query) sender.\n \tThis utility is also able to set illegal information in the IP header\ndiff --git a/testcases/network/stress/ns-tools/Makefile b/testcases/network/stress/ns-tools/Makefile\nindex b20b11b04..6a1d27242 100644\n--- a/testcases/network/stress/ns-tools/Makefile\n+++ b/testcases/network/stress/ns-tools/Makefile\n@@ -6,7 +6,7 @@ top_srcdir\t\t?= ../../../..\n \n include $(top_srcdir)/include/mk/env_pre.mk\n \n-INSTALL_TARGETS\t\t:= create_file tst_net_stress.sh\n+INSTALL_TARGETS\t\t:= create_file tst_net_stress.sh ns-icmpv4_sender\n \n FILTER_OUT_MAKE_TARGETS\t:= ns-common\n \ndiff --git a/testcases/network/stress/ns-tools/ns-icmpv4_sender.c b/testcases/network/stress/ns-tools/ns-icmpv4_sender.c\nnew file mode 100644\nindex 000000000..f51ad5f56\n--- /dev/null\n+++ b/testcases/network/stress/ns-tools/ns-icmpv4_sender.c\n@@ -0,0 +1,622 @@\n+/******************************************************************************/\n+/*                                                                            */\n+/*   Copyright (c) International Business Machines  Corp., 2006               */\n+/*                                                                            */\n+/*   This program is free software;  you can redistribute it and/or modify    */\n+/*   it under the terms of the GNU General Public License as published by     */\n+/*   the Free Software Foundation; either version 2 of the License, or        */\n+/*   (at your option) any later version.                                      */\n+/*                                                                            */\n+/*   This program is distributed in the hope that it will be useful,          */\n+/*   but WITHOUT ANY WARRANTY;  without even the implied warranty of          */\n+/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                */\n+/*   the GNU General Public License for more details.                         */\n+/*                                                                            */\n+/*   You should have received a copy of the GNU General Public License        */\n+/*   along with this program;  if not, write to the Free Software             */\n+/*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA  */\n+/*                                                                            */\n+/******************************************************************************/\n+\n+/*\n+ * File:\n+ *\tns-icmpv4_sender.c\n+ *\n+ * Description:\n+ *\tThis is ICMPv4 echo request sender.\n+ *\tThis utility is also able to set illegal information in the IP header\n+ *\n+ * Author:\n+ *\tMitsuru Chinen <mitch@jp.ibm.com>\n+ *\n+ * History:\n+ *\tMar 5 2006 - Created (Mitsuru Chinen)\n+ *---------------------------------------------------------------------------*/\n+\n+/*\n+ * Header Files\n+ */\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <errno.h>\n+#include <netdb.h>\n+#include <signal.h>\n+#include <time.h>\n+#include <unistd.h>\n+#include <sys/ioctl.h>\n+#include <sys/socket.h>\n+#include <arpa/inet.h>\n+#include <net/ethernet.h>\n+#include <net/if_arp.h>\n+\n+#include \"ns-traffic.h\"\n+\n+/*\n+ * Structure Definitions\n+ */\n+struct icmpv4_fake {\n+\tstruct ip4_datagram pkt;\n+\tchar *src_ifname;\n+\tstruct sockaddr_ll saddr_ll;\n+\tstruct sockaddr_ll daddr_ll;\n+\tstruct in_addr saddr;\n+\tstruct in_addr daddr;\n+\tunsigned short int pkt_size;\n+\tunsigned short int data_size;\n+\tdouble timeout;\n+\n+\tu_int16_t fake_flag;\n+};\n+\n+/*\n+ * Gloval variables\n+ */\n+char *program_name;\t\t/* program name */\n+struct sigaction handler;\t/* Behavior for a signal */\n+int catch_sighup;\t\t/* When catch the SIGHUP, set to non-zero */\n+\n+/*\n+ * Function: usage()\n+ *\n+ * Descripton:\n+ *  Print the usage of this program. Then, terminate this program with\n+ *  the specified exit value.\n+ *\n+ * Argument:\n+ *  exit_value:\texit value\n+ *\n+ * Return value:\n+ *  This function does not return.\n+ */\n+void usage(char *program_name, int exit_value)\n+{\n+\tFILE *stream = stdout;\t/* stream where the usage is output */\n+\n+\tif (exit_value == EXIT_FAILURE)\n+\t\tstream = stderr;\n+\n+\tfprintf(stream, \"%s [OPTION]\\n\"\n+\t\t\"\\t-I if_name\\tInterface name of the source host\\n\"\n+\t\t\"\\t-S ip_addr\\tIPv4 address of the source host\\n\"\n+\t\t\"\\t-M mac_addr\\tMAC address of the destination host\\n\"\n+\t\t\"\\t-D ip_addr\\tIPv4 address of the destination host\\n\"\n+\t\t\"\\t-s packetsize\\tnumber of data bytes (exclude header)\\n\"\n+\t\t\"\\t-t value\\ttimeout [sec]\\n\"\n+\t\t\"\\t-d\\t\\tdisplay debug informations\\n\"\n+\t\t\"\\t-h\\t\\tdisplay this usage\\n\"\n+\t\t\"\\n\"\n+\t\t\"\\t[options for fake]\\n\"\n+\t\t\"\\t  -c\\tbreak checksum\\n\"\n+\t\t\"\\t  -f\\tbreak fragment information\\n\"\n+\t\t\"\\t  -i\\tbreak IPv4 destination address\\n\"\n+\t\t\"\\t  -l\\tbreak header length\\n\"\n+\t\t\"\\t  -L\\tbreak total length\\n\"\n+\t\t\"\\t  -p\\tbreak protocol number\\n\"\n+\t\t\"\\t  -v\\tbreak IP version\\n\", program_name);\n+\texit(exit_value);\n+}\n+\n+/*\n+ * Function: set_signal_flag()\n+ *\n+ * Description:\n+ *  This function sets global variables accordig to signal\n+ *\n+ * Argument:\n+ *  type: type of signal\n+ *\n+ * Return value:\n+ *  None\n+ */\n+void set_signal_flag(int type)\n+{\n+\tif (debug)\n+\t\tfprintf(stderr, \"Catch signal. type is %d\\n\", type);\n+\n+\tswitch (type) {\n+\tcase SIGHUP:\n+\t\tcatch_sighup = 1;\n+\t\thandler.sa_handler = SIG_IGN;\n+\t\tif (sigaction(type, &handler, NULL) < 0)\n+\t\t\tfatal_error(\"sigaction()\");\n+\t\tbreak;\n+\n+\tdefault:\n+\t\tfprintf(stderr, \"Unexpected signal (%d) is caught\\n\", type);\n+\t\texit(EXIT_FAILURE);\n+\t}\n+}\n+\n+/*\n+ * Function: parse_options()\n+ *\n+ * Description:\n+ *  This function parse the options, then modify the fake icmp data\n+ *\n+ * Argument:\n+ *   argc:  the number of argument\n+ *   argv:  arguments\n+ *  fake_p: pointer to data of fake icmp data to modify\n+ *\n+ * Return value:\n+ *  None\n+ */\n+void parse_options(int argc, char *argv[], struct icmpv4_fake *fake_p)\n+{\n+\tint optc;\t\t/* option */\n+\tunsigned long opt_ul;\t/* option value in unsigned long */\n+\tdouble opt_d;\t\t/* option value in double */\n+\tstruct in_addr opt_addr;\t/* option value in struct in_addr */\n+\tstruct sockaddr_ll opt_addr_ll;\t/* option value in struct sockaddr_ll */\n+\tint is_specified_src_ifname = 0;\n+\tint is_specified_saddr = 0;\n+\tint is_specified_daddr_ll = 0;\n+\tint is_specified_daddr = 0;\n+\n+\twhile ((optc = getopt(argc, argv, \"I:S:M:D:s:t:dhcfilLpv\")) != EOF) {\n+\t\tswitch (optc) {\n+\t\tcase 'I':\n+\t\t\tfake_p->src_ifname = strdup(optarg);\n+\t\t\tif (fake_p->src_ifname == NULL)\n+\t\t\t\tfatal_error(\"strdup() failed.\");\n+\t\t\tis_specified_src_ifname = 1;\n+\t\t\tbreak;\n+\n+\t\tcase 'S':\n+\t\t\tif (inet_pton(AF_INET, optarg, &opt_addr) <= 0) {\n+\t\t\t\tfprintf(stderr, \"Source address is wrong\\n\");\n+\t\t\t\tusage(program_name, EXIT_FAILURE);\n+\t\t\t}\n+\t\t\tfake_p->saddr = opt_addr;\n+\t\t\tis_specified_saddr = 1;\n+\t\t\tbreak;\n+\n+\t\tcase 'M':\n+\t\t\tif (eth_pton(AF_INET, optarg, &opt_addr_ll)) {\n+\t\t\t\tfprintf(stderr,\n+\t\t\t\t\t\"Destination MAC address is wrong\\n\");\n+\t\t\t\tusage(program_name, EXIT_FAILURE);\n+\t\t\t}\n+\t\t\tfake_p->daddr_ll = opt_addr_ll;\n+\t\t\tis_specified_daddr_ll = 1;\n+\t\t\tbreak;\n+\n+\t\tcase 'D':\n+\t\t\tif (inet_pton(AF_INET, optarg, &opt_addr) <= 0) {\n+\t\t\t\tfprintf(stderr,\n+\t\t\t\t\t\"Destination address is wrong\\n\");\n+\t\t\t\tusage(program_name, EXIT_FAILURE);\n+\t\t\t}\n+\t\t\tfake_p->daddr = opt_addr;\n+\t\t\tis_specified_daddr = 1;\n+\t\t\tbreak;\n+\n+\t\tcase 's':\n+\t\t\topt_ul = strtoul(optarg, NULL, 0);\n+\t\t\tif (opt_ul > ICMPV4_DATA_MAXSIZE) {\n+\t\t\t\tfprintf(stderr,\n+\t\t\t\t\t\"Data size sholud be less than %d\\n\",\n+\t\t\t\t\tICMPV4_DATA_MAXSIZE + 1);\n+\t\t\t\tusage(program_name, EXIT_FAILURE);\n+\t\t\t}\n+\t\t\tfake_p->data_size = opt_ul;\n+\t\t\tbreak;\n+\n+\t\tcase 't':\n+\t\t\topt_d = strtod(optarg, NULL);\n+\t\t\tif (opt_d < 0.0) {\n+\t\t\t\tfprintf(stderr,\n+\t\t\t\t\t\"Timeout should be positive value\\n\");\n+\t\t\t\tusage(program_name, EXIT_FAILURE);\n+\t\t\t}\n+\t\t\tfake_p->timeout = opt_d;\n+\t\t\tbreak;\n+\n+\t\tcase 'd':\n+\t\t\tdebug = 1;\n+\t\t\tbreak;\n+\n+\t\tcase 'h':\n+\t\t\tusage(program_name, EXIT_SUCCESS);\n+\t\t\tbreak;\n+\n+\t\t\t/* Options for fake */\n+\t\tcase 'c':\n+\t\t\tfake_p->fake_flag |= FAKE_CHECK;\n+\t\t\tbreak;\n+\n+\t\tcase 'f':\n+\t\t\tfake_p->fake_flag |= FAKE_FRAGMENT;\n+\t\t\tbreak;\n+\n+\t\tcase 'i':\n+\t\t\tfake_p->fake_flag |= FAKE_DADDR;\n+\t\t\tbreak;\n+\n+\t\tcase 'l':\n+\t\t\tfake_p->fake_flag |= FAKE_IHL;\n+\t\t\tbreak;\n+\n+\t\tcase 'L':\n+\t\t\tfake_p->fake_flag |= FAKE_TOT_LEN;\n+\t\t\tbreak;\n+\n+\t\tcase 'p':\n+\t\t\tfake_p->fake_flag |= FAKE_PROTOCOL;\n+\t\t\tbreak;\n+\n+\t\tcase 'v':\n+\t\t\tfake_p->fake_flag |= FAKE_VERSION;\n+\t\t\tbreak;\n+\n+\t\tdefault:\n+\t\t\tusage(program_name, EXIT_FAILURE);\n+\t\t}\n+\t}\n+\n+\tif (!is_specified_src_ifname) {\n+\t\tfprintf(stderr,\n+\t\t\t\"Interface name of the source host is not specified\\n\");\n+\t\tusage(program_name, EXIT_FAILURE);\n+\t}\n+\n+\tif (!is_specified_saddr) {\n+\t\tfprintf(stderr, \"Source IP address is not specified\\n\");\n+\t\tusage(program_name, EXIT_FAILURE);\n+\t}\n+\n+\tif (!is_specified_daddr_ll) {\n+\t\tfprintf(stderr, \"Destination MAC address is not specified\\n\");\n+\t\tusage(program_name, EXIT_FAILURE);\n+\t}\n+\n+\tif (!is_specified_daddr) {\n+\t\tfprintf(stderr, \"Destination IP address is not specified\\n\");\n+\t\tusage(program_name, EXIT_FAILURE);\n+\t}\n+}\n+\n+/*\n+ * Function: complete_eth_addrs()\n+ *\n+ * Description:\n+ *  This function sets the source and destination ethernet address completely\n+ *\n+ * Argument:\n+ *  fake_p: pointer to data of fake icmp structure\n+ *\n+ * Return value:\n+ *  None\n+ *\n+ */\n+void complete_eth_addrs(struct icmpv4_fake *fake_p)\n+{\n+\tint sock_fd;\t\t/* Socket for ioctl() */\n+\tstruct ifreq ifinfo;\t/* Interface information */\n+\n+\tif ((sock_fd = socket(AF_PACKET, SOCK_DGRAM, 0)) < 0)\n+\t\tfatal_error(\"socket()\");\n+\n+\t/* Source */\n+\tfake_p->saddr_ll.sll_family = AF_PACKET;\t/* Always AF_PACKET */\n+\tfake_p->saddr_ll.sll_protocol = htons(ETH_P_IP);\t/* IPv4 */\n+\tfake_p->saddr_ll.sll_hatype = ARPHRD_ETHER;\t/* Header type */\n+\tfake_p->saddr_ll.sll_pkttype = PACKET_HOST;\t/* Packet type */\n+\tfake_p->saddr_ll.sll_halen = ETH_ALEN;\t/* Length of address */\n+\n+\t/* Get the MAC address of the interface at source host */\n+\tget_ifinfo(&ifinfo, sock_fd, fake_p->src_ifname, SIOCGIFHWADDR);\n+\tmemcpy(fake_p->saddr_ll.sll_addr, ifinfo.ifr_hwaddr.sa_data, ETH_ALEN);\n+\n+\t/* Get the interface index */\n+\tget_ifinfo(&ifinfo, sock_fd, fake_p->src_ifname, SIOCGIFINDEX);\n+\tfake_p->saddr_ll.sll_ifindex = ifinfo.ifr_ifindex;\n+\tfake_p->daddr_ll.sll_ifindex = ifinfo.ifr_ifindex;\n+\n+\tclose(sock_fd);\n+}\n+\n+/*\n+ * Function: create_clean_packet()\n+ *\n+ * Description:\n+ *  This function creates icmpv4 packet without any fakes\n+ *\n+ * Argument:\n+ *  fake_p: pointer to data of fake icmp structure\n+ *\n+ * Return value:\n+ *  None\n+ */\n+void create_clean_packet(struct icmpv4_fake *fake_p)\n+{\n+\tstruct ip4_datagram pkt;\t/* sending IPv4 packet */\n+\tstruct icmp4_segment *icmp_p;\t/* ICMPv4 part of sending packet */\n+\tunsigned short int pkt_size;\n+\n+\tmemset(&pkt, '\\0', sizeof(struct ip4_datagram));\n+\tpkt_size = sizeof(struct iphdr)\t/* IP header */\n+\t    +sizeof(struct icmphdr)\t/* ICMP header */\n+\t    +fake_p->data_size;\t/* ICMP payload */\n+\n+\ticmp_p = (struct icmp4_segment *)&(pkt.payload);\n+\n+\t/* IPv4 Header */\n+\tpkt.hdr.version = 4;\n+\tpkt.hdr.ihl = sizeof(struct iphdr) / 4;\n+\tpkt.hdr.tos = 0;\n+\tpkt.hdr.tot_len = htons(pkt_size);\n+\tpkt.hdr.id = htons(IPV4_PACKET_ID);\n+\tpkt.hdr.frag_off = htons(IPV4_DEFAULT_FLAG);\n+\tpkt.hdr.ttl = IPV4_DEFAULT_TTL;\n+\tpkt.hdr.protocol = IPPROTO_ICMP;\n+\tpkt.hdr.check = 0;\t/* Calculate later */\n+\tpkt.hdr.saddr = fake_p->saddr.s_addr;\n+\tpkt.hdr.daddr = fake_p->daddr.s_addr;\n+\n+\t/* ICMPv4 Header */\n+\ticmp_p->hdr.type = ICMP_ECHO;\n+\ticmp_p->hdr.code = 0;\n+\ticmp_p->hdr.checksum = 0;\t/* Calculate later */\n+\ticmp_p->hdr.un.echo.id = htons(ICMP_ECHO_ID);\n+\ticmp_p->hdr.un.echo.sequence = htons(1);\n+\n+\t/* ICMPv4 Payload */\n+\tfill_payload(icmp_p->data, fake_p->data_size);\n+\n+\t/* Calcualte checksums */\n+\tpkt.hdr.check = calc_checksum((u_int16_t *) (&pkt.hdr),\n+\t\t\t\t      sizeof(struct iphdr));\n+\ticmp_p->hdr.checksum = calc_checksum((u_int16_t *) icmp_p,\n+\t\t\t\t\t     sizeof(struct icmphdr) +\n+\t\t\t\t\t     fake_p->data_size);\n+\n+\t/* Store the clean packet data */\n+\tfake_p->pkt = pkt;\n+\tfake_p->pkt_size = pkt_size;\n+}\n+\n+/*\n+ * Function: thrust_fakes()\n+ *\n+ * Description:\n+ *  This function thrust fake information to the icmp packet\n+ *\n+ * Argument:\n+ *     pkt   : Payload of the Ethernet frame (Namely, IPv6 packet\n+ *  fake_flag: Flag which represents what information would be faked\n+ *\n+ * Return value:\n+ *  None\n+ */\n+void thrust_fakes(struct ip4_datagram *pkt, u_int16_t fake_flag)\n+{\n+\tint rand_val;\n+\tsize_t bitsize;\n+\tu_int32_t seed;\n+\n+\tif (debug)\n+\t\tfprintf(stderr, \"fake_flag = %2x\\n\", fake_flag);\n+\n+\tif (fake_flag & FAKE_VERSION) {\t/* version */\n+\t\tbitsize = 4;\n+\t\tseed = bit_change_seed(bitsize, 1);\n+\t\tpkt->hdr.version ^= seed;\n+\t}\n+\n+\tif (fake_flag & FAKE_IHL) {\t/* header length */\n+\t\tbitsize = 4;\n+\t\tseed = bit_change_seed(bitsize, 1);\n+\t\tpkt->hdr.ihl ^= seed;\n+\t}\n+\n+\tif (fake_flag & FAKE_TOT_LEN) {\t/* total length */\n+\t\tbitsize = sizeof(pkt->hdr.tot_len) * 8;\n+\t\tseed = bit_change_seed(bitsize, bitsize / 8);\n+\t\tpkt->hdr.tot_len ^= seed;\n+\t}\n+\n+\tif (fake_flag & FAKE_FRAGMENT) {\t/* fragment information */\n+\t\t/* Set reserved flag */\n+\t\trand_val = rand() / ((RAND_MAX + 1U) / 16);\n+\t\tif (!rand_val) {\n+\t\t\tif (debug)\n+\t\t\t\tfprintf(stderr, \"Up reserved bit\\n\");\n+\t\t\tpkt->hdr.frag_off |= htonl(0x80000000);\n+\t\t}\n+\n+\t\t/* Set more fragments flag */\n+\t\trand_val = rand() / ((RAND_MAX + 1U) / 3);\n+\t\tif (!rand_val) {\n+\t\t\tif (debug)\n+\t\t\t\tfprintf(stderr, \"Set more fragments flag\\n\");\n+\t\t\tpkt->hdr.frag_off |= htons(0x2000);\n+\t\t}\n+\n+\t\t/* Unset unfragmented flag */\n+\t\trand_val = rand() / ((RAND_MAX + 1U) / 3);\n+\t\tif (!rand_val) {\n+\t\t\tif (debug)\n+\t\t\t\tfprintf(stderr, \"Unset unfragmented flag\\n\");\n+\t\t\tpkt->hdr.frag_off &= htons(0xbfff);\n+\t\t}\n+\n+\t\t/* Set fragment offset */\n+\t\trand_val = rand() / ((RAND_MAX + 1U) / 3);\n+\t\tif (!rand_val) {\n+\t\t\tbitsize = 13;\n+\t\t\tseed = bit_change_seed(bitsize, 0);\n+\t\t\tif (debug)\n+\t\t\t\tfprintf(stderr, \"Set fragment offset %02x\\n\",\n+\t\t\t\t\tseed);\n+\t\t\tpkt->hdr.frag_off |= htons(seed);\n+\t\t}\n+\t}\n+\n+\tif (fake_flag & FAKE_PROTOCOL) {\t/* protocol */\n+\t\trand_val = rand() / ((RAND_MAX + 1U) / 5);\n+\t\tswitch (rand_val) {\n+\t\tcase 1:\n+\t\tcase 2:\n+\t\t\tif (debug)\n+\t\t\t\tfprintf(stderr, \"Bit reverse\\n\");\n+\t\t\tbitsize = sizeof(pkt->hdr.protocol) * 8;\n+\t\t\tseed = bit_change_seed(bitsize, 0);\n+\t\t\tpkt->hdr.protocol ^= seed;\n+\t\t\tbreak;\n+\n+\t\tcase 3:\n+\t\tcase 4:\n+\t\t\tif (debug)\n+\t\t\t\tfprintf(stderr, \"Unknown Protocol\\n\");\n+\t\t\tif (rand_val) {\n+\t\t\t\tint number;\n+\t\t\t\tint counter;\n+\t\t\t\tfor (counter = 0; counter <= 0xff; counter++) {\n+\t\t\t\t\tnumber =\n+\t\t\t\t\t    rand() / ((RAND_MAX + 1U) / 0x100);\n+\t\t\t\t\tif (getprotobynumber(number) == NULL) {\n+\t\t\t\t\t\tpkt->hdr.protocol = number;\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tbreak;\n+\n+\t\tdefault:\n+\t\t\tif (debug)\n+\t\t\t\tfprintf(stderr, \"Do nothing\\n\");\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (fake_flag & FAKE_DADDR) {\t/* destination address */\n+\t\tbitsize = sizeof(pkt->hdr.daddr) * 8;\n+\t\tseed = bit_change_seed(bitsize, bitsize / 8);\n+\t\tpkt->hdr.daddr ^= seed;\n+\t}\n+\n+\t/* Recalculate checksum once */\n+\tpkt->hdr.check = 0;\n+\tpkt->hdr.check =\n+\t    calc_checksum((u_int16_t *) & (pkt->hdr), sizeof(struct iphdr));\n+\n+\tif (fake_flag & FAKE_CHECK) {\t/* checksum */\n+\t\tbitsize = sizeof(pkt->hdr.check) * 8;\n+\t\tseed = bit_change_seed(bitsize, bitsize / 8);\n+\t\tpkt->hdr.check ^= seed;\n+\t}\n+}\n+\n+/*\n+ * Function: send_packet()\n+ *\n+ * Description:\n+ *  This function sends icmpv4 packet\n+ *\n+ * Argument:\n+ *  fake_p: pointer to data of fake icmp structure\n+ *\n+ * Return value:\n+ *  None\n+ */\n+void send_packets(struct icmpv4_fake *fake_p)\n+{\n+\tint sock_fd;\n+\tint retval;\n+\tstruct ip4_datagram pkt;\n+\tdouble start_time;\n+\n+\t/* Open a socket */\n+\tsock_fd = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));\n+\tif (sock_fd < 0)\n+\t\tfatal_error(\"socket()\");\n+\n+\t/* Bind the socket to the physical address */\n+\tretval = bind(sock_fd, (struct sockaddr *)&(fake_p->saddr_ll),\n+\t\t      sizeof(struct sockaddr_ll));\n+\tif (retval < 0)\n+\t\tfatal_error(\"bind()\");\n+\n+\t/* Set singal hander for SIGHUP */\n+\thandler.sa_handler = set_signal_flag;\n+\thandler.sa_flags = 0;\n+\tif (sigfillset(&handler.sa_mask) < 0)\n+\t\tfatal_error(\"sigfillset()\");\n+\tif (sigaction(SIGHUP, &handler, NULL) < 0)\n+\t\tfatal_error(\"sigfillset()\");\n+\n+\t/*\n+\t * loop for sending packets\n+\t */\n+\tpkt = fake_p->pkt;\n+\tstart_time = time(NULL);\n+\n+\tfor (;;) {\n+\t\tif (fake_p->fake_flag) {\n+\t\t\tpkt = fake_p->pkt;\n+\t\t\tthrust_fakes(&pkt, fake_p->fake_flag);\n+\t\t}\n+\n+\t\tretval = sendto(sock_fd, &pkt, fake_p->pkt_size, 0,\n+\t\t\t\t(struct sockaddr *)&(fake_p->daddr_ll),\n+\t\t\t\tsizeof(struct sockaddr_ll));\n+\t\tif (retval < 0)\n+\t\t\tfatal_error(\"sendto()\");\n+\n+\t\tif (fake_p->timeout)\t/* timeout */\n+\t\t\tif (fake_p->timeout < difftime(time(NULL), start_time))\n+\t\t\t\tbreak;\n+\n+\t\tif (catch_sighup)\t/* catch SIGHUP */\n+\t\t\tbreak;\n+\t}\n+\n+\t/* Close the socket */\n+\tclose(sock_fd);\n+}\n+\n+/*\n+ *\n+ *  Function: main()\n+ *\n+ */\n+int main(int argc, char *argv[])\n+{\n+\tstruct icmpv4_fake fake_data;\n+\n+\tdebug = 0;\n+\tprogram_name = strdup(argv[0]);\n+\tsrand(getpid());\n+\n+\tmemset(&fake_data, '\\0', sizeof(struct icmpv4_fake));\n+\tparse_options(argc, argv, &fake_data);\n+\n+\tcomplete_eth_addrs(&fake_data);\n+\tcreate_clean_packet(&fake_data);\n+\n+\tsend_packets(&fake_data);\n+\n+\texit(EXIT_SUCCESS);\n+}\n","prefixes":["v1"]}