@@ -64,30 +64,96 @@ translator node_connection_t <node_dtrace_connection_t *nc> {
6464 & ((node_dtrace_connection64_t * )nc )-> buffered , sizeof (int32_t ));
6565};
6666
67+ typedef struct {
68+ uint32_t version ;
69+ } node_dtrace_http_request_t ;
70+
6771typedef struct {
6872 uint32_t url ;
6973 uint32_t method ;
70- } node_dtrace_http_request_t ;
74+ } node_dtrace_http_request_v0_t ;
75+
76+ typedef struct {
77+ uint32_t version ;
78+ uint32_t url ;
79+ uint32_t method ;
80+ uint32_t forwardedFor ;
81+ } node_dtrace_http_request_v1_t ;
7182
7283typedef struct {
7384 uint64_t url ;
7485 uint64_t method ;
75- } node_dtrace_http_request64_t ;
86+ } node_dtrace_http_request64_v0_t ;
87+
88+ typedef struct {
89+ uint32_t version ;
90+ uint32_t pad ;
91+ uint64_t url ;
92+ uint64_t method ;
93+ uint64_t forwardedFor ;
94+ } node_dtrace_http_request64_v1_t ;
7695
7796typedef struct {
7897 string url ;
7998 string method ;
99+ string forwardedFor ;
80100} node_http_request_t ;
81101
102+ /*
103+ * This translator is even filthier than usual owing to our attempts to
104+ * maintain backwards compatibility. Previous versions of node used an
105+ * http_request struct that had fields for "url" and "method". The current
106+ * version also provides a "forwardedFor" field. To distinguish the binary
107+ * representations of these structs, the new version also prepends a "version"
108+ * member (where the old one has a "url" pointer). So each field that we're
109+ * translating below first switches on the value of this "version" field: if
110+ * it's larger than 4096, we know we must be looking at the "url" pointer of
111+ * the older structure version. Otherwise, we must be looking at the new
112+ * version. Besides this, we have the usual switch based on the userland
113+ * process data model. This would all be simpler with macros, but those aren't
114+ * available in delivered D library files since that would make DTrace
115+ * dependent on cpp, which isn't always available.
116+ */
82117translator node_http_request_t < node_dtrace_http_request_t * nd > {
83- url = curpsinfo -> pr_dmodel == PR_MODEL_ILP32 ?
84- copyinstr ((uintptr_t )* (uint32_t * )copyin ((uintptr_t )& nd -> url ,
85- sizeof (int32_t ))) :
86- copyinstr ((uintptr_t )* (uint64_t * )copyin ((uintptr_t )
87- & ((node_dtrace_http_request64_t * )nd )-> url , sizeof (int64_t ))) ;
88- method = curpsinfo -> pr_dmodel == PR_MODEL_ILP32 ?
89- copyinstr ((uintptr_t )* (uint32_t * )copyin ((uintptr_t )& nd -> method ,
90- sizeof (int32_t ))) :
91- copyinstr ((uintptr_t )* (uint64_t * )copyin ((uintptr_t )
92- & ((node_dtrace_http_request64_t * )nd )-> method , sizeof (int64_t )));
118+ url = (* (uint32_t * )copyin ((uintptr_t )& nd -> version , sizeof (uint32_t ))) >= 4096 ?
119+ (curpsinfo -> pr_dmodel == PR_MODEL_ILP32 ?
120+ copyinstr (* (uint32_t * )copyin ((uintptr_t )
121+ & ((node_dtrace_http_request_v0_t * )nd )-> url ,
122+ sizeof (uint32_t ))) :
123+ copyinstr (* (uint64_t * )copyin ((uintptr_t )
124+ & ((node_dtrace_http_request64_v0_t * )nd )-> url ,
125+ sizeof (uint64_t )))) :
126+ (curpsinfo -> pr_dmodel == PR_MODEL_ILP32 ?
127+ copyinstr (* (uint32_t * )copyin ((uintptr_t )
128+ & ((node_dtrace_http_request_v1_t * )nd )-> url ,
129+ sizeof (uint32_t ))) :
130+ copyinstr (* (uint64_t * )copyin ((uintptr_t )
131+ & ((node_dtrace_http_request64_v1_t * )nd )-> url ,
132+ sizeof (uint64_t )))) ;
133+
134+ method = (* (uint32_t * )copyin ((uintptr_t )& nd -> version , sizeof (uint32_t ))) >= 4096 ?
135+ (curpsinfo -> pr_dmodel == PR_MODEL_ILP32 ?
136+ copyinstr (* (uint32_t * )copyin ((uintptr_t )
137+ & ((node_dtrace_http_request_v0_t * )nd )-> method ,
138+ sizeof (uint32_t ))) :
139+ copyinstr (* (uint64_t * )copyin ((uintptr_t )
140+ & ((node_dtrace_http_request64_v0_t * )nd )-> method ,
141+ sizeof (uint64_t )))) :
142+ (curpsinfo -> pr_dmodel == PR_MODEL_ILP32 ?
143+ copyinstr (* (uint32_t * )copyin ((uintptr_t )
144+ & ((node_dtrace_http_request_v1_t * )nd )-> method ,
145+ sizeof (uint32_t ))) :
146+ copyinstr (* (uint64_t * )copyin ((uintptr_t )
147+ & ((node_dtrace_http_request64_v1_t * )nd )-> method ,
148+ sizeof (uint64_t ))));
149+
150+ forwardedFor = (* (uint32_t * )
151+ copyin ((uintptr_t )& nd -> version , sizeof (uint32_t ))) >= 4096 ? "" :
152+ (curpsinfo -> pr_dmodel == PR_MODEL_ILP32 ?
153+ copyinstr (* (uint32_t * )copyin ((uintptr_t )
154+ & ((node_dtrace_http_request_v1_t * )nd )-> forwardedFor ,
155+ sizeof (uint32_t ))) :
156+ copyinstr (* (uint64_t * )copyin ((uintptr_t )
157+ & ((node_dtrace_http_request64_v1_t * )nd )-> forwardedFor ,
158+ sizeof (uint64_t ))));
93159};
0 commit comments