Project

General

Profile

Feature #488 » 0002-Convert-to-atomic-and-disable-check-on-HTP-config-ch.patch

Eric Leblond, 08/15/2012 10:52 AM

View differences:

src/app-layer-htp.c
95 95
static uint64_t htp_state_memcnt = 0;
96 96
#endif
97 97

  
98
/** part of the engine needs the request body (e.g. http_client_body keyword) */
99
uint8_t need_htp_request_body = 0;
100
/** part of the engine needs the request body multipart header (e.g. filename
101
 *  and / or fileext keywords) */
102
uint8_t need_htp_request_multipart_hdr = 0;
103
/** part of the engine needs the request file (e.g. log-file module) */
104
uint8_t need_htp_request_file = 0;
105
/** part of the engine needs the request body (e.g. file_data keyword) */
106
uint8_t need_htp_response_body = 0;
107

  
108 98
SCEnumCharMap http_decoder_event_table[ ] = {
109 99
    { "UNKNOWN_ERROR",
110 100
        HTTP_DECODER_EVENT_UNKNOWN_ERROR},
......
356 346
void AppLayerHtpEnableRequestBodyCallback(void)
357 347
{
358 348
    SCEnter();
359
    need_htp_request_body = 1;
349

  
350
    SC_ATOMIC_OR(htp_need, HTP_REQUEST_BODY);
360 351
    SCReturn;
361 352
}
362 353

  
......
368 359
void AppLayerHtpEnableResponseBodyCallback(void)
369 360
{
370 361
    SCEnter();
371
    need_htp_response_body = 1;
362

  
363
    SC_ATOMIC_OR(htp_need, HTP_RESPONSE_BODY);
372 364
    SCReturn;
373 365
}
374 366

  
......
382 374
    SCEnter();
383 375
    AppLayerHtpEnableRequestBodyCallback();
384 376

  
385
    need_htp_request_multipart_hdr = 1;
377
    SC_ATOMIC_OR(htp_need, HTP_REQUEST_MULTIPART);
386 378
    SCReturn;
387 379
}
388 380

  
......
399 391
    AppLayerHtpEnableRequestBodyCallback();
400 392
    AppLayerHtpEnableResponseBodyCallback();
401 393

  
402
    need_htp_request_file = 1;
394
    SC_ATOMIC_OR(htp_need, HTP_REQUEST_FILE);
403 395
    SCReturn;
404 396
}
405 397

  
......
1754 1746
{
1755 1747
    SCEnter();
1756 1748

  
1757
    if (need_htp_request_body == 0)
1749
    if (SC_ATOMIC_GET(htp_need) & HTP_REQUEST_BODY)
1758 1750
        SCReturnInt(HOOK_OK);
1759 1751

  
1760 1752
#ifdef PRINT
......
1877 1869
{
1878 1870
    SCEnter();
1879 1871

  
1880
    if (need_htp_response_body == 0)
1872

  
1873
    if (SC_ATOMIC_GET(htp_need) & HTP_RESPONSE_BODY)
1881 1874
        SCReturnInt(HOOK_OK);
1882 1875

  
1883 1876
    HtpState *hstate = (HtpState *)d->tx->connp->user_data;
......
2420 2413
    AppLayerRegisterProto(proto_name, ALPROTO_HTTP, STREAM_TOCLIENT,
2421 2414
                          HTPHandleResponseData);
2422 2415

  
2416
    SC_ATOMIC_INIT(htp_need);
2423 2417
    HTPConfigure();
2424 2418
    SCReturn;
2425 2419
}
src/app-layer-htp.h
204 204
} HtpState;
205 205

  
206 206
/** part of the engine needs the request body (e.g. http_client_body keyword) */
207
extern uint8_t need_htp_request_body;
207
#define HTP_REQUEST_BODY        1 << 0
208 208
/** part of the engine needs the request body multipart header (e.g. filename
209 209
 *  and / or fileext keywords) */
210
extern uint8_t need_htp_request_multipart_hdr;
210
#define HTP_REQUEST_MULTIPART   1 << 1
211 211
/** part of the engine needs the request file (e.g. log-file module) */
212
extern uint8_t need_htp_request_file;
212
#define HTP_REQUEST_FILE        1 << 2
213 213
/** part of the engine needs the request body (e.g. file_data keyword) */
214
extern uint8_t need_htp_response_body;
214
#define HTP_RESPONSE_BODY       1 << 3
215

  
216
SC_ATOMIC_DECLARE(uint32_t, htp_need);
215 217

  
216 218
void RegisterHTPParsers(void);
217 219
void HTPParserRegisterTests(void);
src/detect-engine.c
126 126
        exit(EXIT_FAILURE);
127 127
    }
128 128

  
129
    uint8_t local_need_htp_request_body = need_htp_request_body;
130
    uint8_t local_need_htp_request_multipart_hdr = need_htp_request_multipart_hdr;
131
    uint8_t local_need_htp_request_file = need_htp_request_file;
132
    uint8_t local_need_htp_response_body = need_htp_response_body;
133

  
134 129
    if (SigLoadSignatures(de_ctx, NULL, FALSE) < 0) {
135 130
        SCLogError(SC_ERR_NO_RULES_LOADED, "Loading signatures failed.");
136 131
        if (de_ctx->failure_fatal)
137 132
            exit(EXIT_FAILURE);
138 133
    }
139 134

  
140
    if (local_need_htp_request_body != need_htp_request_body ||
141
        local_need_htp_request_multipart_hdr != need_htp_request_multipart_hdr ||
142
        local_need_htp_request_file != need_htp_request_file ||
143
        local_need_htp_response_body != need_htp_response_body) {
144
        SCLogInfo("===== New ruleset requires enabling htp features that "
145
                  "can't be enabled at runtime.  You will have to restart "
146
                  "engine to load the new ruleset =====");
147
        DetectEngineCtxFree(de_ctx);
148
        UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2);
149

  
150
        TmThreadsSetFlag(tv_local, THV_CLOSED);
151

  
152
        pthread_exit(NULL);
153
    }
154

  
155 135
    SCThresholdConfInitContext(de_ctx, NULL);
156 136

  
157 137
    /* start the process of swapping detect threads ctxs */
158
- 
(4-4/4)