From: Anthony Nandaa <profnandaa@gmail.com>
To: linux-cifs@vger.kernel.org, stfrench@microsoft.com, sfrench@samba.org
Cc: samba-technical@lists.samba.org,
Anthony Nandaa <profnandaa@gmail.com>,
Pavel Shilovsky <pshilovsky@samba.org>
Subject: [PATCH] cifs-utils: smbinfo: add gettconinfo command
Date: Fri, 5 Jul 2024 23:43:52 +0300 [thread overview]
Message-ID: <20240705204352.975013-1-profnandaa@gmail.com> (raw)
As a follow up on the patch on Linux: de4eceab578e
("smb3: allow dumping session and tcon id to improve stats analysis
and debugging") [1]
Add `gettconinfo` command to dump both the TCON Id and Session Id of
a given SMB mount; to help with correlation in cases when multiple
mounts are to the same share.
Example run:
```
./smbinfo gettconinfo /mnt/smb_share
TCON Id: 0x1
Session Id: 0xa40000000001
```
[1] https://github.com/torvalds/linux/commit/de4eceab578ead12a71e5b5588a57e142bbe8ceb
Cc: Pavel Shilovsky <pshilovsky@samba.org>
Cc: Steve French <stfrench@microsoft.com>
Signed-off-by: Anthony Nandaa <profnandaa@gmail.com>
---
smbinfo | 29 +++++++++++++++++++++++++++++
smbinfo.rst | 2 ++
2 files changed, 31 insertions(+)
diff --git a/smbinfo b/smbinfo
index 73c5bb3..3467b0b 100755
--- a/smbinfo
+++ b/smbinfo
@@ -35,6 +35,7 @@ CIFS_QUERY_INFO = 0xc018cf07
CIFS_ENUMERATE_SNAPSHOTS = 0x800ccf06
CIFS_DUMP_KEY = 0xc03acf08
CIFS_DUMP_FULL_KEY = 0xc011cf0a
+CIFS_GET_TCON_INFO = 0x800ccf0c
# large enough input buffer length
INPUT_BUFFER_LENGTH = 16384
@@ -289,6 +290,10 @@ def main():
sap.add_argument("file")
sap.set_defaults(func=cmd_keys)
+ sap = subp.add_parser("gettconinfo", help="Prints TCON Id and Session Id for a cifs file")
+ sap.add_argument("file")
+ sap.set_defaults(func=cmd_gettconinfo)
+
# parse arguments
args = ap.parse_args()
@@ -876,5 +881,29 @@ def cmd_keys(args):
print("ServerIn Key: %s"%bytes_to_hex(kd.server_in_key))
print("ServerOut key: %s"%bytes_to_hex(kd.server_out_key))
+class SmbMntTconInfoStruct:
+ def __init__(self):
+ self.tid = 0
+ self.session_id = 0
+
+ def ioctl(self, fd):
+ buf = bytearray()
+ buf.extend(struct.pack("=IQ", self.tid, self.session_id))
+ fcntl.ioctl(fd, CIFS_GET_TCON_INFO, buf, True)
+ (self.tid, self.session_id) = struct.unpack_from('=IQ', buf, 0)
+
+def cmd_gettconinfo(args):
+ fd = os.open(args.file, os.O_RDONLY)
+ tcon = SmbMntTconInfoStruct()
+
+ try:
+ tcon.ioctl(fd)
+ except Exception as e:
+ print("syscall failed: %s"%e)
+ return False
+
+ print("TCON Id: 0x%x"%tcon.tid)
+ print("Session Id: 0x%x"%tcon.session_id)
+
if __name__ == '__main__':
main()
diff --git a/smbinfo.rst b/smbinfo.rst
index 1acf3c4..17270c5 100644
--- a/smbinfo.rst
+++ b/smbinfo.rst
@@ -96,6 +96,8 @@ COMMAND
the SMB3 traffic of this mount can be decryped e.g. via wireshark
(requires root).
+`gettconinfo`: Prints both the TCON Id and Session Id for a cifs file.
+
*****
NOTES
*****
--
2.34.1
next reply other threads:[~2024-07-05 20:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-05 20:43 Anthony Nandaa [this message]
2024-07-10 19:49 ` [PATCH] cifs-utils: smbinfo: add gettconinfo command Steve French
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240705204352.975013-1-profnandaa@gmail.com \
--to=profnandaa@gmail.com \
--cc=linux-cifs@vger.kernel.org \
--cc=pshilovsky@samba.org \
--cc=samba-technical@lists.samba.org \
--cc=sfrench@samba.org \
--cc=stfrench@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.