All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kovalev, Sergey" <Sergey.Kovalev@emc.com>
To: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: "Dion, Christopher" <Christopher.Dion@emc.com>,
	"Akopyan, Alexander" <Alexander.Akopyan@emc.com>
Subject: [PATCH] ping: ping doesn't work correctly with -m option
Date: Mon, 18 May 2015 12:37:46 +0000	[thread overview]
Message-ID: <7E20C7B36969D643A89BC9AE4BF0F3A422D31D95@MX102CL01.corp.emc.com> (raw)

The "ping" or "ping6" with parameter "-m" doesn't work when "main" and "default" table are empty (or do not have any route to destination IP).
If we don't specify source IP address for the ping, the ping will try to determine the source IP automatically. To do so it creates the probe UDP socket, and try to connect to dst IP on that socket. The connect should make routing decision based on current Linux routing.  If connection succeeded it takes source IP (however it doesn't use it in future indeed). The issue is that PIGN doesn't specify fwmark for that probe socket as a result connection fails with "Network unreachable" error.

--- ./ping.c.origin     2015-05-12 09:01:16.000000000 -0400
+++ ./ping.c    		2015-05-13 07:34:06.000000000 -0400
@@ -107,6 +107,7 @@
 struct sockaddr_in source;
 char *device;
 int pmtudisc = -1;
+extern int mark;


 int
@@ -305,6 +306,12 @@
                                }
                        }
                }
+        if (options & F_MARK) {
+            if (setsockopt(probe_fd, SOL_SOCKET, SO_MARK,
+                        &mark, sizeof(mark)) == -1) {
+                fprintf(stderr, "Warning: Failed to set mark %d\n", mark);
+            }
+        }

                if (settos &&
                    setsockopt(probe_fd, IPPROTO_IP, IP_TOS, (char *)&settos, sizeof(int)) < 0)
--- ./ping6.c.origin    2015-05-12 09:01:16.000000000 -0400
+++ ./ping6.c   		2015-05-13 07:33:39.000000000 -0400
@@ -137,7 +137,7 @@
 int pmtudisc=-1;

 static int icmp_sock;
-
+extern int mark;


 static struct in6_addr in6_anyaddr;
@@ -385,6 +385,12 @@
 #endif
                        }
                }
+        if (options & F_MARK) {
+            if (setsockopt(probe_fd, SOL_SOCKET, SO_MARK,
+                        &mark, sizeof(mark)) == -1) {
+                fprintf(stderr, "Warning: Failed to set mark %d\n", mark);
+            }
+        }
                firsthop.sin6_port = htons(1025);
                if (connect(probe_fd, (struct sockaddr*)&firsthop, sizeof(firsthop)) == -1) {
                        perror("connect");

                 reply	other threads:[~2015-05-18 12:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7E20C7B36969D643A89BC9AE4BF0F3A422D31D95@MX102CL01.corp.emc.com \
    --to=sergey.kovalev@emc.com \
    --cc=Alexander.Akopyan@emc.com \
    --cc=Christopher.Dion@emc.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.