-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixups for sticky cookie calculation in case of segmented data #1088
Conversation
I've tried to run this branch, but it still seems to be unstable if cookie value is split between chunks.
|
@ikoveshnikov, |
Ah, yes, shame on me. I should have checked it before posting the comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to merge, but i would like to see additional test for http parser, since sticky cookie module highly relies on its behaviour. Please, also backport the patch to 0.5 release.
tempesta_fw/t/unit/test_tfw_str.c
Outdated
* Cutting out one segment should create a plain string, rather than | ||
* a chunked one with a single segment. | ||
*/ | ||
EXPECT_EQ(TFW_STR_CHUNKN(&out), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't really matter for this particular test, but we have a special macro for plain strings: TFW_STR_PLAIN()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code was modified to use TFW_STR_PLAIN()
.
EXPECT_EQ(TFW_STR_CHUNKN(&out), 0); | ||
|
||
/* Collecting until a stop character. */ | ||
tfw_str_collect_cmp(chunks, chunks + 5, &out, "j"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, also add a case, when stop character couldn't be found at the beginning of a new chunk, so resulting string won't overcome end
limit. This is checked in tests above, but not for the case when stop character is provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
@@ -1100,6 +1100,69 @@ TEST(tfw_str_crc32, plain_compound) | |||
EXPECT_EQ(crc_pln, crc_cmpnd); | |||
} | |||
|
|||
TEST(tfw_str_collect_cmp, collect_chunks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the issue of this PR actually, but can you add one more test for the http parser? Cookie calculations add several requirements for the http parser:
- cookie name starts at a new chunk, and this chunk is marked with
TFW_STR_NAME
flag - cookie value starts at a new chunk, and this chunk is marked with
TFW_STR_VALUE
flag - cookie delimeter character(
;
) starts at a new chunk
This requirements aren't checked anywhere, but http_sess.c
code highly relies on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack. I'll add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to merge, with minor comment.
bzero_fast(out, sizeof(*out)); | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function was intended to collect cookie value in any case (or BUG_ON
must be triggered), so it didn't return value. But now it can return with no value found and caller will not know anything about this. Perhaps it is worth to change it to return true/false
or 0/-ENOENT
; also the similar checks before tfw_str_collect_cmp
calls - looks redundant now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't shake the feeling that it's wrong to add any return value to this function. It has a verb in the name, so by convention should return 0 if there are no errors, and other values otherwise. But this function cannot fail. It's not an error to return empty string if an empty slice was provided. If we add a return value, somebody reading code at the call site will get an impression of error handling, which it is not.
So I think it is good to leave testing for chunk == end
before calling this function. It's a duplication, but I don't think checking should be removed from this function, as it may result in accidental reading outside of allocated memory.
412e3dd
to
43002e2
Compare
Also adds a rare case of empty slice handling.
When data are in multiple chunks, it's necessary to initialize 'tr' at the beginning of every new chunk.
43002e2
to
ed82007
Compare
If request comes in more than one packet, sticky cookie value may be in chunks. The patches handle that case, and also force cookie to be regenerated if inbound cookie was of wrong length.