-
-
Notifications
You must be signed in to change notification settings - Fork 423
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
Support more upper layer services (many, many, many more) #446
Conversation
printf '//! This file is generated automatically via ./services.sh\n\n' | ||
printf 'use crate::networking::types::protocol::Protocol;\n\n' | ||
printf '#[allow(clippy::too_many_lines, clippy::unnested_or_patterns)]\n' | ||
printf 'pub fn get_service(port_info: (u16, Protocol)) -> String {\n' |
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.
printf 'pub fn get_service(port_info: (u16, Protocol)) -> String {\n' | |
printf 'pub fn get_service(port_info: (u16, Protocol)) -> Option<&'static str> {\n' |
so the caller can decide how they want to represent unknown services and whether they need owned String. If you care about performance you should avoid String allocations.
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.
lgtm
If you do this, you'll have to cut a new release every time you want to change even a single character of any of the service definitions. It will quickly become unsustainable. |
I see your point. Anyway, I don't judge it a priority to update this service list. |
After having long discussed this PR with the Rust community of Reddit, I came to the conclusion that a better strategy is to generate a compile-time, static, perfect hash map for the network services. New PR: #450. |
Warning
This PR was replaced by #450
As requested in #374 and by multiple other users of the application (e.g., #289, #338), this PR adds support for several new upper layer services in addition to the 24 already supported application protocols.
The full list of the new supported services, taken from Nmap, is basically the IANA assigned ports list plus some trojans and worms.
It contains 6438 different services/protocols/trojans/worms.
While I could use a file-lookup approach to resolve the name of a service given a port number and the transport protocol, I decided to create a short bash script that automatically curls the full list of services and generates a Rust file containing a single (very long)
match
expression wrapped in a new method.This strategy may seem a little unconventional but should guarantee
un-matchable
performances (pun intended) in the port-to-service mapping procedure.Since apparently there isn't a way to autofix
clippy::match_same_arms
, the bash script also takes care of merging duplicate branches of thematch
.Fixes #374