Page MenuHomeFreeBSD

Introduce ifconfig -a -[gG] groupname
ClosedPublic

Authored by eugen_grosbein.net on May 27 2020, 1:20 PM.

Details

Summary

Currently "ifconfig -a" command listing status of network interfaces may be accomplished with flags -d or -u to limit the list to interfaces that are down or up.

This change allows it to filter the list by name of interface group with additional flag -g groupname (or -G groupname to negate condition). Note this is different from "ifconfig -g groupname" that shows interface names only and that behaviour is not affected with the change.

groupname may contain shell patterns. Both -g and -G flags may be specified same time to apply both filters.

Test Plan

Examples:

to exclude loopback from the list: ifconfig -a -G lo
to show vlan interfaces only: ifconfig -a -g vlan
to show tap interfaces that are up: ifconfig -aug tap

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Fix misprint that somehow passed testing.

Comment about caret escaping in a popular shell...

sbin/ifconfig/ifconfig.8
2925 ↗(On Diff #72328)

Sure the ^ is a special symbol with a very popular shell: zsh.
For example, I need to escape it every time I do an MFC like this:
$ svn merge -c r<revisionfromhead> \^/head/ stable/12

sbin/ifconfig/ifconfig.8
2925 ↗(On Diff #72328)

Can you suggest another symbol that whould be suitable to zsh too? I don't have zsh to check.

Link to zshexpn with zsh-specific chars.

sbin/ifconfig/ifconfig.8
2925 ↗(On Diff #72328)

The zshexpn man page lists all the expansion characters in the "Word Designators" section. Everything that's not listed there should be fine.

sbin/ifconfig/ifconfig.8
2925 ↗(On Diff #72328)

Which character would you personally like to use?

sbin/ifconfig/ifconfig.8
2925 ↗(On Diff #72328)

Maybe @ or #? The @ could be a mnemonic for "list me all AT this interface group".

sbin/ifconfig/ifconfig.8
2925 ↗(On Diff #72328)

As far as I know, # begins a commentary in any shell so it would require escaping too. The symbol @ may be suitable if we don't care that it would require escaping in Perl code running shell command.

I see only two other symbols that could also do it, a colon (:) or slash (/). I think we need more opinions.

You can just use another option name to specify excludes.

In D25029#551705, @ae wrote:

You can just use another option name to specify excludes.

Good point, -G would do it for negation.

In D25029#551705, @ae wrote:

You can just use another option name to specify excludes.

Good point, -G would do it for negation.

+1 for "-G"
Usually negation in a´shell arguments is prefixed by "!", which needs to be escaped.
"^" does look like an regex starting point and will cause confusion: "Why is '-g la.*2[345]' not working?"

"^" does look like an regex starting point and will cause confusion: "Why is '-g la.*2[345]' not working?"

You gave me an idea to use fnmatch() instead of strcmp for matching against group name. Thanks!

eugen_grosbein.net retitled this revision from Introduce ifconfig -a -g groupname to Introduce ifconfig -a -[gG] groupname.
eugen_grosbein.net edited the test plan for this revision. (Show Details)

Do not use prefix to negate condition. Instead, use new flag -G and allow user to specify both -g and -G same time.

Fix case when none of -g nor -G is specified that was broken with addition of second option.

If I understand correctly

ifconfig -a -g lagg -G lagg*1

will match all lagg interfaces besides those ending in 1.

But

ifconfig -a -g lagg -g vlan

will match vlan interfaces only.

Correct?

Add explicit note to the manual page that additional options -g override previous ones, same for -G.

If I understand correctly

ifconfig -a -g lagg -G lagg*1

will match all lagg interfaces besides those ending in 1.

But

ifconfig -a -g lagg -g vlan

will match vlan interfaces only.

Correct?

Yes. I've updated change to the manual page with explicit note.

I'm going to commit this soon unless an objection is raised.

I'd like to hear something from manpages about syntax and wording.

Small wording fixes in the man page.

ifconfig.8
2923 ↗(On Diff #72567)

s/of specified/of the specified/
same below

2933 ↗(On Diff #72567)

s/later overrides/later ones override/
s/one/ones/

3062 ↗(On Diff #72567)

s/loopack/loopback/

Correct wording in the manual page.

OK from manpages. Ready to go. Thanks for having this constructive review!

This revision was not accepted when it landed; it landed in state Needs Review.Jun 4 2020, 2:45 PM
This revision was automatically updated to reflect the committed changes.