|
| 1 | +#! /bin/sh |
| 2 | +# SPDX-License-Identifier: BSD-3-Clause |
| 3 | +# |
| 4 | +# Copyright (c) 2024, Matthieu Baerts |
| 5 | + |
| 6 | +SCRIPT="$(basename "${0}")" |
| 7 | +VERSION="1" |
| 8 | +PID_IP= |
| 9 | + |
| 10 | +EQ="========================================" |
| 11 | + |
| 12 | +title() { |
| 13 | + printf "\n%s\n%s\n%s\n" "${EQ}" "${*}" "${EQ}" |
| 14 | +} |
| 15 | + |
| 16 | +stdout() { |
| 17 | + printf "\n%s\n" "${*}" |
| 18 | +} |
| 19 | + |
| 20 | +stderr() { |
| 21 | + stdout "${@}" >&2 |
| 22 | +} |
| 23 | + |
| 24 | +cmd() { |
| 25 | + title "${*}" |
| 26 | + "${@}" 2>&1 |
| 27 | +} |
| 28 | + |
| 29 | +start_ip_mptcp_monitor() { |
| 30 | + title "ip mptcp monitor: start" |
| 31 | + ip mptcp monitor 2>&1 & # not using cmd to get the right PID |
| 32 | + PID_IP=$! |
| 33 | + |
| 34 | + sleep 0.1 2>/dev/null || sleep 1 |
| 35 | + |
| 36 | + for _ in $(seq 20); do |
| 37 | + out="$(ss -f netlink -H "src = rtnl:${PID_IP}" 2>/dev/null)" || break |
| 38 | + [ "$(echo "${out}" | wc -l)" != 0 ] && return 0 |
| 39 | + |
| 40 | + sleep 0.1 2>/dev/null || break |
| 41 | + done |
| 42 | + |
| 43 | + if [ ! -d "/proc/${PID_IP}" ]; then |
| 44 | + stdout "ip monitor has been killed" |
| 45 | + return 1 |
| 46 | + fi |
| 47 | +} |
| 48 | + |
| 49 | +stop_ip_mptcp_monitor() { |
| 50 | + title "ip mptcp monitor: stop" |
| 51 | + |
| 52 | + if [ -n "${PID_IP}" ] && [ -d "/proc/${PID_IP}" ]; then |
| 53 | + kill "${PID_IP}" |
| 54 | + fi |
| 55 | +} |
| 56 | + |
| 57 | +collect_data_pre() { |
| 58 | + stdout "${SCRIPT}: version ${VERSION}" |
| 59 | + |
| 60 | + if [ "$(id -u)" != 0 ]; then |
| 61 | + stderr "This script is not executed as root, not all info can be collected." |
| 62 | + stderr "Press Enter to continue, Ctrl+C to stop" |
| 63 | + read -r _ |
| 64 | + fi |
| 65 | + |
| 66 | + cmd sysctl net.mptcp |
| 67 | + cmd ip mptcp endpoint show |
| 68 | + cmd ip mptcp limits show |
| 69 | +} |
| 70 | + |
| 71 | +collect_data_post() { |
| 72 | + cmd ss -ManiH |
| 73 | + cmd nstat |
| 74 | +} |
| 75 | + |
| 76 | +collect_data() { |
| 77 | + collect_data_pre |
| 78 | + collect_data_post |
| 79 | +} |
| 80 | + |
| 81 | +collect_data_repro() { |
| 82 | + collect_data_pre |
| 83 | + |
| 84 | + cmd ss -ManiH |
| 85 | + nstat -n 2>&1 |
| 86 | + start_ip_mptcp_monitor |
| 87 | + |
| 88 | + stderr "Please reproduce the issue now, then press the Enter key when it is done." |
| 89 | + read -r _ |
| 90 | + |
| 91 | + collect_data_post |
| 92 | + stop_ip_mptcp_monitor |
| 93 | +} |
| 94 | + |
| 95 | +version() { |
| 96 | + printf "%s: version %s\n" "${SCRIPT}" ${VERSION} |
| 97 | +} |
| 98 | + |
| 99 | +usage() { |
| 100 | + version |
| 101 | + printf "\n" |
| 102 | + printf " -c | --collect Collect info and exit.\n" |
| 103 | + printf " -r | --reproduce Collect info, start monitor, wait for user and exit.\n" |
| 104 | + printf " -h | --help Show this and exit.\n" |
| 105 | + printf " -v | --version Show the version and exit.\n" |
| 106 | + printf "\n" |
| 107 | + printf "Please check https://mptcp.dev website for more info.\n" |
| 108 | +} |
| 109 | + |
| 110 | +case "${1}" in |
| 111 | + "-c" | "--collect") |
| 112 | + collect_data |
| 113 | + ;; |
| 114 | + "-r" | "--reproduce") |
| 115 | + collect_data_repro |
| 116 | + ;; |
| 117 | + "-h" | "--help") |
| 118 | + usage |
| 119 | + ;; |
| 120 | + "-v" | "--version") |
| 121 | + version |
| 122 | + ;; |
| 123 | + *) |
| 124 | + usage >&2 |
| 125 | + exit 1 |
| 126 | + ;; |
| 127 | +esac |
| 128 | + |
| 129 | +exit 0 |
0 commit comments