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

Network stack cleanup #8723

Closed
7 tasks done
tbursztyka opened this issue Jul 4, 2018 · 7 comments
Closed
7 tasks done

Network stack cleanup #8723

tbursztyka opened this issue Jul 4, 2018 · 7 comments
Assignees
Labels
area: Networking Enhancement Changes/Updates/Additions to existing features

Comments

@tbursztyka
Copy link
Collaborator

tbursztyka commented Jul 4, 2018

Current code base would need serious cleanup/optimization. Current status shows duplicates, un-proper modularization, under optimized data storage/lookup, naming issues etc...

What should be done:

  • Keep each specific part into their own C file (i.e.: ipv4, ipv6, etc...).
    . For instance, icmpv4 redo in its code what ipv4 does already.
  • Factorize as much as possible
  • Reduce #ifdefs usage inside functions
    . Use IS_ENABLED()
    . Move CONFIG_* conditioned code to own function
  • Naming convention
    .When it is a public function net_<domain><...>()
    .When it is a private function <domain>
    <...>()
  • de-clutter: if/for/while... imbrication. (The Linux rule of 3 maximum is nice), if functions are way too big, isolate logical blocks in dedicated functions etc...

Areas:

@tbursztyka
Copy link
Collaborator Author

@jukkar, @rveerama1, @ozhuraki, @pfalcon, whoever else is interested.

@nashif nashif added the Enhancement Changes/Updates/Additions to existing features label Jul 4, 2018
@pfalcon
Copy link
Contributor

pfalcon commented Aug 22, 2018

Here's my 2 cents of proposed cleanup: I hate these things:

tcp.c:NET_CONN_CB(tcp_established)
tcp.c:NET_CONN_CB(tcp_synack_received)
tcp.c:NET_CONN_CB(tcp_syn_rcvd)

It obfuscates the fact that it's function (so, e.g. if you search for "tcp_established(", you'll get nothing), and completely hides the function parameter list. And all this for what?:

        static enum net_verdict name(struct net_conn *conn,       \
                                     struct net_pkt *pkt,         \
                                     void *user_data)             \
        {                                                         \
                enum net_verdict result;                          \
                                                                  \
                net_context_ref(user_data);                       \
                result = _##name(conn, pkt, user_data);           \
                net_context_unref(user_data);                     \
                return result;                                    \
        }                                  

As we have 3 occurrences of this stuff, we could just expand that macro to literal code, and won't lose much. But it's actually more than that - I don't think all that wrapping is actually necessary. Just think what it does - it extends context lifetime until the end of wrapper function. But the wrapper function doesn't use context in any way after the wrappee returns, so this extending is completely useless! It only adds confusion on the source level and extra callframe on the stack.

@pfalcon
Copy link
Contributor

pfalcon commented Aug 22, 2018

@jukkar , @tbursztyka : Can you assess the proposal in previous comment please?

@pfalcon
Copy link
Contributor

pfalcon commented Aug 22, 2018

It obfuscates the fact that it's function (so, e.g. if you search for "tcp_established(", you'll get nothing), and completely hides the function parameter list.

#9564 tries to alleviate at least the concerns above, with the code comments.

@pfalcon
Copy link
Contributor

pfalcon commented Aug 22, 2018

Overall, TCP is the most atrocious part of the stack code. #8726 doesn't pay it good attention. I've created #9570 to discuss the real guts of it.

pfalcon added a commit to pfalcon/zephyr that referenced this issue Aug 22, 2018
1. Where we calculate max size, name variable (preprocessor define)
correspondingly.
2. Calling TCP/UDP an "app protocol" is original, use "next protocol"
terminology of IPv6.
3. As headers go as IP, then "next", order calculations that way too.
4. Add more comments.

Addresses: zephyrproject-rtos#8723

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
pfalcon added a commit to pfalcon/zephyr that referenced this issue Aug 22, 2018
This function has absolutely nothing to do with net_context.

Addresses: zephyrproject-rtos#8723

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
nashif pushed a commit that referenced this issue Aug 25, 2018
1. Where we calculate max size, name variable (preprocessor define)
correspondingly.
2. Calling TCP/UDP an "app protocol" is original, use "next protocol"
terminology of IPv6.
3. As headers go as IP, then "next", order calculations that way too.
4. Add more comments.

Addresses: #8723

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
nashif pushed a commit that referenced this issue Aug 25, 2018
This function has absolutely nothing to do with net_context.

Addresses: #8723

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
pfalcon added a commit to pfalcon/zephyr that referenced this issue Aug 29, 2018
NET_CONN_CB() functional macro hides the parameters a function takes
and its return type. In zephyrproject-rtos#8723, it's proposed to remove that macro
altogether. Until that proposal is reviewed, at least provide real
protype in code comments to help people who read/analyze the code.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
nashif pushed a commit that referenced this issue Aug 29, 2018
NET_CONN_CB() functional macro hides the parameters a function takes
and its return type. In #8723, it's proposed to remove that macro
altogether. Until that proposal is reviewed, at least provide real
protype in code comments to help people who read/analyze the code.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
@nashif nashif removed this from the v1.13.0 milestone Sep 3, 2018
@tbursztyka
Copy link
Collaborator Author

edited: removed the TCP cleanup tasks.

@tbursztyka tbursztyka self-assigned this Apr 25, 2019
@tbursztyka
Copy link
Collaborator Author

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking Enhancement Changes/Updates/Additions to existing features
Projects
None yet
Development

No branches or pull requests

3 participants