Make ping use socket marks properly.
ping and ping6 have an option to set the socket mark on the
sockets they use, but unfortunately they do not use that option
on the sockets they use to determine their local address. Thus,
those checks are incorrect, and can result in ping failing to
run if unmarked sockets have no connectivity.
Change-Id: I2b8c30d314d6723a89d26d636f4f3fd0b9b8c3ac
diff --git a/ping_common.c b/ping_common.c
index 9c0e8f5..d58d3c4 100644
--- a/ping_common.c
+++ b/ping_common.c
@@ -605,6 +605,25 @@
}
}
+void sock_setmark(int icmp_sock) {
+#ifdef SO_MARK
+ if (options & F_MARK) {
+ int ret;
+
+ enable_capability_admin();
+ ret = setsockopt(icmp_sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark));
+ disable_capability_admin();
+
+ if (ret == -1) {
+ /* we probably dont wanna exit since old kernels
+ * dont support mark ..
+ */
+ fprintf(stderr, "Warning: Failed to set mark %d\n", mark);
+ }
+ }
+#endif
+}
+
/* Protocol independent setup and parameter checks. */
void setup(int icmp_sock)
@@ -639,22 +658,8 @@
fprintf(stderr, "Warning: no SO_TIMESTAMP support, falling back to SIOCGSTAMP\n");
}
#endif
-#ifdef SO_MARK
- if (options & F_MARK) {
- int ret;
- enable_capability_admin();
- ret = setsockopt(icmp_sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark));
- disable_capability_admin();
-
- if (ret == -1) {
- /* we probably dont wanna exit since old kernels
- * dont support mark ..
- */
- fprintf(stderr, "Warning: Failed to set mark %d\n", mark);
- }
- }
-#endif
+ sock_setmark(icmp_sock);
/* Set some SNDTIMEO to prevent blocking forever
* on sends, when device is too slow or stalls. Just put limit