Bug 212272 - w(1): 'w -n' makes bogus DNS queries
Summary: w(1): 'w -n' makes bogus DNS queries
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.0-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-08-30 22:51 UTC by Anton Yuzhaninov
Modified: 2016-09-02 18:37 UTC (History)
1 user (show)

See Also:


Attachments
Path to revert r199655 (1.86 KB, patch)
2016-08-30 22:51 UTC, Anton Yuzhaninov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Yuzhaninov 2016-08-30 22:51:21 UTC
Created attachment 174235 [details]
Path to revert r199655

When tmux is used, utmp file (/var/run/utx.active) contains strings like tmux(1104).%1, tmux(1104).%2 and so on in hostname field.

'w -n' command tries to resolve tmux(PID).%PTS strings, which causes delay and unnecessary load on root DNS servers.

This behavior was introduced in r199655: https://svnweb.freebsd.org/changeset/base/199655

Problems with such behavior:

1. It not exactly matches documentation. Man says about -n flag "Do not attempt to resolve network addresses (normally w interprets addresses and attempts to display them as names)" and says nothing about resolving host to IP.
2. Even if man page will be updated to match current implementation this behavior will be not consistent with other commands: -n for most other commands means "no DNS resolving at all".
3. if tmux (and may be screen) is used, 'w -n' makes bogus DNS queries, which end up on root DNS servers. I hope we don't want next paper like "Analysis of DNS root server bogus queries" to contain paragraph about FreeBSD.

Patch to remove host->IP resolving (revert r199655) with -n is attached (patch against stable/11, but should apply on head).

Another option is to check, that host string to contains only [a-zA-Z0-9_.] before resolving. I don't like it because:
1. pre r199655 'w -n' behavior matches 'w -n' on NetBSD and -n flag in other commands.
2. w.c is already complicated (for the simple task it performs) lets don't make it more complicated
3. If somebody want to see only IP in 'w -n' output it is better to run sshd with -u0 flag, than resolve twice: IP to host in sshd and host to IP in 'w -n' command.
Comment 1 commit-hook freebsd_committer freebsd_triage 2016-09-02 18:28:36 UTC
A commit references this bug:

Author: ume
Date: Fri Sep  2 18:28:14 UTC 2016
New revision: 305289
URL: https://svnweb.freebsd.org/changeset/base/305289

Log:
  When -n is specified, don't make bogus DNS queries.  Instead,
  when -n is specified more than once, hostnames stored in utmp
  are attempted to resolve to display them as network addresses.

  PR:		212272

Changes:
  head/usr.bin/w/w.1
  head/usr.bin/w/w.c
Comment 2 Hajimu UMEMOTO freebsd_committer freebsd_triage 2016-09-02 18:37:19 UTC
I've committed not to make bogus DNS queries when -n is specified.  Instead, when -n is specified more than once, hostnames stored in utmp are attempted to resolve to display them as network addresses.