1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
diff --git a/driver/ppm_flag_helpers.h b/driver/ppm_flag_helpers.h
index d47ecc2..751a869 100644
--- a/driver/ppm_flag_helpers.h
+++ b/driver/ppm_flag_helpers.h
@@ -976,49 +976,20 @@ static __always_inline uint8_t sockopt_optname_to_scap(int level, int optname) {
return PPM_SOCKOPT_SO_RCVLOWAT;
#endif
#ifdef SO_SNDLOWAT
case SO_SNDLOWAT:
return PPM_SOCKOPT_SO_SNDLOWAT;
#endif
-/* We use this workaround to avoid 2 switch cases with the same value.
- * An `elif` approach is not enough if `SO_RCVTIMEO` is not defined.
- * In this case we have only `SO_RCVTIMEO_OLD` and `SO_RCVTIMEO_NEW` so
- * we couldn't be able to detect the right flag value, for example:
- * `SO_RCVTIMEO_OLD` is defined so we compile only this branch, but
- * actual value of `SO_RCVTIMEO` is `SO_RCVTIMEO_NEW`.
- * https://github.com/torvalds/linux/commit/a9beb86ae6e55bd92f38453c8623de60b8e5a308
- */
#ifdef SO_RCVTIMEO
case SO_RCVTIMEO:
return PPM_SOCKOPT_SO_RCVTIMEO;
#endif
-#if(defined(SO_RCVTIMEO_OLD) && !defined(SO_RCVTIMEO)) || \
- (defined(SO_RCVTIMEO_OLD) && (SO_RCVTIMEO_OLD != SO_RCVTIMEO))
- case SO_RCVTIMEO_OLD:
- return PPM_SOCKOPT_SO_RCVTIMEO;
-#endif
-#if(defined(SO_RCVTIMEO_NEW) && !defined(SO_RCVTIMEO)) || \
- (defined(SO_RCVTIMEO_NEW) && (SO_RCVTIMEO_NEW != SO_RCVTIMEO))
- case SO_RCVTIMEO_NEW:
- return PPM_SOCKOPT_SO_RCVTIMEO;
-#endif
-/* Look at `SO_RCVTIMEO` */
#ifdef SO_SNDTIMEO
case SO_SNDTIMEO:
return PPM_SOCKOPT_SO_SNDTIMEO;
#endif
-#if(defined(SO_SNDTIMEO_OLD) && !defined(SO_SNDTIMEO)) || \
- (defined(SO_SNDTIMEO_OLD) && (SO_SNDTIMEO_OLD != SO_SNDTIMEO))
- case SO_SNDTIMEO_OLD:
- return PPM_SOCKOPT_SO_SNDTIMEO;
-#endif
-#if(defined(SO_SNDTIMEO_NEW) && !defined(SO_SNDTIMEO)) || \
- (defined(SO_SNDTIMEO_NEW) && (SO_SNDTIMEO_NEW != SO_SNDTIMEO))
- case SO_SNDTIMEO_NEW:
- return PPM_SOCKOPT_SO_SNDTIMEO;
-#endif
#ifdef SO_SECURITY_AUTHENTICATION
case SO_SECURITY_AUTHENTICATION:
return PPM_SOCKOPT_SO_SECURITY_AUTHENTICATION;
#endif
#ifdef SO_SECURITY_ENCRYPTION_TRANSPORT
case SO_SECURITY_ENCRYPTION_TRANSPORT:
@@ -1142,20 +1113,56 @@ static __always_inline uint8_t sockopt_optname_to_scap(int level, int optname) {
// Basically, when labels values are similar AND the switch has many labels,
// compiler tends to build a jump table as optimization.
// This breaks with eBPF, and in our Makefile we already have the -fno-jump-tables;
// most probably clang5 had some kind of bug that caused -O2 mode to still use jump tables.
// Let's add a "very distant" label value to forcefully disable jump table.
//
- // DO NOT merge with below default case
- // otherwise this label will be skipped by compiler.
- ASSERT(false);
- return PPM_SOCKOPT_UNKNOWN;
+ // DO NOT merge with below default case
+ // otherwise this label will be skipped by compiler.
+ ASSERT(false);
+ return PPM_SOCKOPT_UNKNOWN;
#endif
- default:
- ASSERT(false);
- return PPM_SOCKOPT_UNKNOWN;
+ default:
+
+ /* We use this workaround to avoid 2 switch cases with the same value.
+ * An `elif` approach is not enough if `SO_RCVTIMEO` is not defined.
+ * In this case we have only `SO_RCVTIMEO_OLD` and `SO_RCVTIMEO_NEW` so
+ * we couldn't be able to detect the right flag value, for example:
+ * `SO_RCVTIMEO_OLD` is defined so we compile only this branch, but
+ * actual value of `SO_RCVTIMEO` is `SO_RCVTIMEO_NEW`.
+ *
+ * As an added wrinkle, on i686 SO_RCVTIMEO and SO_SNDTIMEO
+ * are not constants interpretable by the preprocessor:
+ * SO_RCVTIMEO is (sizeof(time_t) == sizeof(__kernel_long_t)
+ * ? 20 : 66). So we cannot use the preprocessor to check
+ * for equality. So we don't handle these in the switch(),
+ * and let if() statements handle it.
+ *
+ * https://github.com/torvalds/linux/commit/a9beb86ae6e55bd92f38453c8623de60b8e5a308
+ */
+ if(
+#if defined(SO_RCVTIMEO_OLD)
+ optname == SO_RCVTIMEO_OLD ||
+#endif
+#if defined(SO_RCVTIMEO_NEW)
+ optname == SO_RCVTIMEO_NEW ||
+#endif
+ 0 )
+ return PPM_SOCKOPT_SO_RCVTIMEO;
+ if(
+#if defined(SO_SNDTIMEO_OLD)
+ optname == SO_SNDTIMEO_OLD ||
+#endif
+#if defined(SO_SNDTIMEO_NEW)
+ optname == SO_SNDTIMEO_NEW ||
+#endif
+ 0 )
+ return PPM_SOCKOPT_SO_SNDTIMEO;
+
+ ASSERT(false);
+ return PPM_SOCKOPT_UNKNOWN;
}
}
/* XXX this is very basic for the moment, we'll need to improve it */
static __always_inline uint16_t poll_events_to_scap(short revents) {
uint16_t res = 0;
|