Skip to content

Commit

Permalink
fix check mptcp conn
Browse files Browse the repository at this point in the history
  • Loading branch information
CrapsDorian committed Mar 28, 2024
1 parent 83b120a commit 5b5bd2f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions flask_app/app.py
Expand Up @@ -19,18 +19,20 @@ def mptcp_status_page():
port = request.environ.get('REMOTE_PORT')

try:
conn = check_output(["ss", "-Mtn", "src", f"{addr}", "sport", f"{port}"]).decode("ascii")
if (conn == ""):
conn_without_header = check_output(["ss", "-MtnH", "src", f"{addr}", "sport", f"{port}"]).decode("ascii")
conn_without_header = "\n".join(conn_without_header.split("\n")[1:])
if (conn_without_header == ""):
pass

This comment has been minimized.

Copy link
@matttbe

matttbe Mar 28, 2024

@CrapsDorian that's not normal, it should be treated as an error.

I think we should handle 4 cases:

  • we found the connection and it is in MPTCP
  • we found the connection, but it is in TCP
  • we didn't find the connection: error
  • internal error: bug in the code, etc.

if list(filter(None, conn.split(' ')))[0] == "mptcp":
filtered_list = list(filter(None, conn_without_header.split(' ')))
if filtered_list and filtered_list[0] == "mptcp":
state_message = 'Established'
state_class = 'success'
else:
state_message = 'Not Established'
state_class = 'fail'
except Exception as e:
state_message = '[error]'
state_message = '[error: ' + str(e) + ']'
state_class = 'error'

return render_template('index.html', state_message=state_message, state_class=state_class)
Expand Down

0 comments on commit 5b5bd2f

Please sign in to comment.