-
Notifications
You must be signed in to change notification settings - Fork 25
Add dp_session_query function #8
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
Open
dungmv56
wants to merge
1
commit into
danos:master
Choose a base branch
from
dungmv56:dp_query
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2021, SafePoint <info@safepoint.vn>. All rights reserved. | ||
| * Copyright (c) 2017-2021, AT&T Intellectual Property. All rights reserved. | ||
| * Copyright (c) 2017 by Brocade Communications Systems, Inc. | ||
| * All rights reserved. | ||
|
|
@@ -1943,7 +1944,7 @@ int session_npf_pack_restore(struct npf_pack_dp_session *pds, | |
| s->se_flags = SESSION_INSERTED; | ||
|
|
||
| rc = session_npf_pack_stats_restore(s, stats); | ||
| if (rc) | ||
| if (rc) | ||
| goto error; | ||
|
|
||
| *session = s; | ||
|
|
@@ -2033,3 +2034,79 @@ uint64_t dp_session_unique_id(const struct session *session) | |
| return 0; | ||
| return session->se_id; | ||
| } | ||
|
|
||
| /* walk function for query features */ | ||
| static int se_feature_query(struct session *s, struct session_feature *sf, | ||
| void *data) | ||
| { | ||
| struct dp_session_info *info = data; | ||
|
|
||
| if (sf->sf_ops && sf->sf_ops->query) | ||
| sf->sf_ops->query(info, s, sf); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| int dp_session_query(struct session *s, enum dp_session_attr query, | ||
| struct dp_session_info *info) | ||
| { | ||
| if (!s) | ||
| return -1; | ||
|
|
||
| info->se_id = s->se_id; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| if (query & SESSION_ATTR_PROTOCOL) { | ||
| info->se_protocol = s->se_protocol; | ||
| info->se_protocol_state = s->se_protocol_state; | ||
| } | ||
| if (query & SESSION_ATTR_BYTES_IN) | ||
| info->se_bytes_in = rte_atomic64_read(&s->se_bytes_in); | ||
| if (query & SESSION_ATTR_PKTS_IN) | ||
| info->se_pkts_in = rte_atomic64_read(&s->se_pkts_in); | ||
| if (query & SESSION_ATTR_CREATE_TIME) | ||
| info->se_create_time = s->se_create_time; | ||
| if (query & SESSION_ATTR_BYTES_OUT) | ||
| info->se_bytes_out = rte_atomic64_read(&s->se_bytes_out); | ||
| if (query & SESSION_ATTR_PKTS_OUT) | ||
| info->se_pkts_out = rte_atomic64_read(&s->se_pkts_out); | ||
|
|
||
| if (query & SESSION_ATTR_SENTRY) { | ||
| const void *saddr; | ||
| const void *daddr; | ||
| uint32_t if_index; | ||
| uint16_t sid; | ||
| uint16_t did; | ||
|
|
||
| struct sentry *sen = rcu_dereference(s->se_sen); | ||
| if (sen) { | ||
| session_sentry_extract(sen, &if_index, &info->se_af, | ||
| &saddr, &sid, &daddr, &did); | ||
|
|
||
| if (query & SESSION_ATTR_L4_SRC_PORT) | ||
| info->se_src_port = sid; | ||
| if (query & SESSION_ATTR_IPV4_SRC_ADDR) | ||
| info->se_src_addr = *(uint32_t *)saddr; | ||
| if (query & SESSION_ATTR_L4_DST_PORT) | ||
| info->se_dst_port = did; | ||
| if (query & SESSION_ATTR_IPV4_DST_ADDR) | ||
| info->se_dst_addr = *(uint32_t *)daddr; | ||
| if (query & SESSION_ATTR_IF_NAME) | ||
| info->se_ifname = | ||
| ifnet_indextoname_safe(if_index); | ||
| } | ||
| } | ||
|
|
||
| if (query & SESSION_ATTR_DPI) { | ||
| info->query = query; | ||
|
|
||
| /* set default value in case no info found */ | ||
| info->se_app_name = NULL; | ||
| info->se_app_proto = NULL; | ||
| info->se_app_type = NULL; | ||
|
|
||
| session_feature_walk_session(s, SESSION_FEATURE_ALL, | ||
| se_feature_query, info); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is the need to request specific attrs due to the plugin directly outputting the returned JSON?
The plugin should retrieve the necessary attrs from the JSON and format them into a suitable table.
Therefore it should not matter if additional attrs are returned.
The dataplane could return all of the attrs, and the plugin only output the relevant values.
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.
The plugin registers a session_watch to hook when session state or stats changed. This was called from dataplane forwarding path and I try to keep plugin not affect forwarding performance as much as possible.
I see that returning all attrs from dataplane make easier for adding new attributes but I afraid it could affect performance. That why I added a query as parameter.