Skip to content
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

SS: Proper TCP options #574

Merged
merged 2 commits into from
Jul 13, 2016
Merged

SS: Proper TCP options #574

merged 2 commits into from
Jul 13, 2016

Conversation

milabs
Copy link
Contributor

@milabs milabs commented Jun 29, 2016

This fixes #475

flags |= SS_SEND_F_PASS_SKB;
} else {
/* Add server connection flags */
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, it's better just to leave a comment here and remove an empty branch.
Add server connection flags in an "else{}" branch if necessary.

return CSTR_NEQ;
msg->flags |= TFW_HTTP_CONN_CLOSE;
tfw_http_msg_set_conn(msg, TFW_HTTP_CONN_CLOSE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the patch. tfw_http_msg_conn(msg) doesn't equal to msg->flags & TFW_HTTP_CONN_KA and tfw_http_msg_set_conn(msg, TFW_HTTP_CONN_CLOSE) does more operations than msg->flags |= TFW_HTTP_CONN_CLOSE. Probably in this particular case the statements are equal and performance penalty is invisible, however the change just makes the code bit nicer (meantime msg->flags & TFW_HTTP_CONN_KA says more for me than fw_http_msg_conn(msg)) and this bit nicer doesn't outweight the badnesses.

@krizhanovsky
Copy link
Contributor

"use MSG_MORE to optimize packet size at IP layer" in the original task #475 was mostly about https://github.com/tempesta-tech/linux-4.1-tfw/blob/master/net/ipv4/tcp.c#L688: don't send partial TCP segements, so it's good to implement the option.

@krizhanovsky
Copy link
Contributor

Please, review possible bug in ss_do_close(): the function returns (here and here) after socket reference counter incrementing. So it seems socket descriptor leakage is possible.

IIRC we enter ss_do_close() with zero refcounter of the socket, so we don't need to do sock_put() twice (in inet_csk_destroy_sock() and at below of the function) as standard tcp_close() does it. However, if we return from the function we never reach zero refcounter on following ss_do_close() calls.

@milabs
Copy link
Contributor Author

milabs commented Jul 6, 2016

@krizhanovsky Well, ss_do_close always followed by the sock_put, so I do not see the problem with descriptor leakage you've mentioned. Am I missed something?

flags |= SS_SEND_F_CONN_CLOSE;
if (!(hm->flags & TFW_HTTP_DO_NOT_PASS))
flags |= SS_SEND_F_PASS_SKB;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptual architecture is broken. Connection layer is generic - it lays under HTTP, HTTPS and probably other protocols, so connection.[ch] shouldn't include HTTP stuff, while http.[ch] include connection.h. So firstly the change introduces circular dependency. Secondly it breaks program modules dependency.

I'd say this is HTTP responsibility to set appropriate connection flags. Moreover, tfw_connection_send() is called for server transmissions as well as for client, so there is no sense to introduce the IF construction when the caller knows exactly who it sends data to.

@krizhanovsky
Copy link
Contributor

@milabs , "Well, ss_do_close always followed by the sock_put, so I do not see the problem with descriptor leakage you've mentioned. Am I missed something?"

Oh, I see. Thanks.

@milabs milabs force-pushed the im-issue-475 branch 2 times, most recently from 140c557 to eb44494 Compare July 11, 2016 01:55
@@ -405,6 +402,15 @@ ss_do_close(struct sock *sk)
}
}

#define __ss_sk_close(sk, lock, unlock, drop) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to read code like __ss_sk_close(sk, 1, 1, 1) - what the numbers are? It's hard to remember. Let's introduce defines like __ss_sk_close_locked() or __ss_sk_close_drop_locked().

This change add flags (options) to SS-operations like ss_open() and
ss_close(). At the moment, only the following options have been
implemented (SS_F_SYNC, SS_F_KEEP_SKB and SS_F_CONN_CLOSE), so:

- SS_F_SYNC signals that synchronous operation must be performed;

- SS_F_KEEP_SKB signals to ss_send(), that clones must be used and not
  the originals;

- SS_F_CONN_CLOSE signals, that connection must be closed (droped)
  after the operation;

Using such a flags allows us to reduce amount of arguments for ss_open
and ss_close calls and also it makes it possible to remove unref_data
argument from tfw_connection_send() function.

Also, as the result we've use tfw_cache_add() from where it must be
used and not from the http.c.

Related to #475.
if (req->flags & TFW_HTTP_CONN_CLOSE)
((TfwMsg *)resp)->ss_flags |= SS_F_CONN_CLOSE;
}

Copy link
Contributor

@krizhanovsky krizhanovsky Jul 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functions are used in http.c only, so it seems their place is in http.c.

Do we need the functions at all? E.g. __adjust_req_flags() is just single-line function which doesn't "adjust" flags, but rather set one particular flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__adjust_resp_flags used twice, so it's good to have it as inline. __adjust_req_flags is used only once, but it has the same purpose as previous. I've change their names to __init_resp_ss_flags and __init_req_ss_flags.

@krizhanovsky
Copy link
Contributor

good to merge

@milabs milabs merged commit 5a7a037 into master Jul 13, 2016
@milabs milabs deleted the im-issue-475 branch July 13, 2016 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SS: Proper TCP options
3 participants