Page MenuHomeFreeBSD

netgraph: optionally print node id of newly created node
Needs ReviewPublic

Authored by dave_freedave.net on Tue, Mar 18, 6:06 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Much like ifconfig(8) cloning you can now easily capture the newly created node:

# nge=$(ngctl mkpeer -i br0: eiface link ether)

This is a quality of life improvement for mkpeer and if I did it right it should be 100% backward compatible.

Not every node will get a name automatically, it isn't required. But every node has an ID and you can use that ID in place of the name with ngctl(8). The usual netgraph naming oddity of ':' on the end is requied, but '[' + ID + ']' can be used anywhere a name would have been necessary.

Test Plan

There are some edge cases like loading of netgraph modules we also need to verify still works. Start simple by making sure there are none loaded and look at new help (NOTE I had to change the XXXXXXX from what it was as its a key to phabricator and it complains):

# kldstat | grep ng_
# ngctl help mkpeer
usage:    mkpeer [-i] [path] <type> <hook> <peerhook>
XXXXXXX:  Create and connect a new node to the node at "path"
Description:
  The mkpeer command atomically creates a new node of type "type"
  and connects it to the node at "path". The hooks used for the
  connection are "hook" on the original node and "peerhook" on
  the new node. If the -i flag is given, return the node ID as a
  string that can be used to reference the node. If "path" is
  omitted then "." is assumed.
# kldstat | grep ng_
 8    1 0xffffffff83014000     38f0 ng_socket.ko

So far so good. But this change needs to be 100% optional and not effect existing scripts that do not use -i.
The first one is when the [path] is omitted it should assume . like before:

# ngctl
...
+ mkpeer bridge b link
+ name .:b br0
+ msg br0: setpersistent
+ show br0:
  Name: br0             Type: bridge          ID: 00000005   Num hooks: 1
  Local hook      Peer name       Peer type    Peer ID         Peer hook
  ----------      ---------       ---------    -------         ---------
  link0           ngctl87479      socket       00000004        b
+ ^D
# kldstat | grep ng_
 8    1 0xffffffff83014000     38f0 ng_socket.ko
10    1 0xffffffff83024000     3230 ng_bridge.ko

That worked now lets provide the path and try our new option:

# nge=$(ngctl mkpeer -i br0: eiface link ether)
# echo $nge
[00000008]
# ngctl show ${nge}:
  Name: ngeth0          Type: eiface          ID: 00000008   Num hooks: 1
  Local hook      Peer name       Peer type    Peer ID         Peer hook
  ----------      ---------       ---------    -------         ---------
  ether           br0             bridge       00000005        link0
# kldstat | grep ng_
 8    1 0xffffffff83014000     38f0 ng_socket.ko
10    1 0xffffffff83024000     3230 ng_bridge.ko
11    1 0xffffffff83028000     2238 ng_eiface.ko

That also shows why I am made this change, it makes capturing the new node to use later in scripts trivial. Especially useful when paired with D44615 and not caring what the [up]link number is on a bridge.

Technically not providing . is the same as providing it, but just to be sure and to make sure module loading continues to work lets do one more. Be warned on default build of current you are going to get a bunch of debug output on the netgraph socket. But it is still worth doing the create/name dance to verify it still works.

# ngctl shutdown ${nge}:
# kldunload ng_eiface.ko
# ngctl
...
+ mkpeer . eiface e ether
+ name .:e e0
+ ^D
# ngctl show e0:
  Name: e0              Type: eiface          ID: 0000000c   Num hooks: 0
# kldstat | grep ng_
kldstat | grep ng_
 8    1 0xffffffff83014000     38f0 ng_socket.ko
10    1 0xffffffff83024000     3230 ng_bridge.ko
11    1 0xffffffff83028000     2238 ng_eiface.ko

Obviously that last one leaves the ng_eiface(4) with 0 hooks as it was connected to our control socket for ngctl and that goes away when we exit with CTRL-D.

Finally run regression tests:

# cd /usr/test
# kyua test sys/netgraph/basic
...
5/5 passed (0 broken, 0 failed, 0 skipped)
# kyua test sys/netgraph/bridge
...
7/7 passed (0 broken, 0 failed, 0 skipped)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Argh! I thought I could create without it bothering anybody. I was going to discuss it first to make sure I didn't mess with something I'm not supposed to and thought a handy link here would make that easier. But I guess its up and Gleb is probably who I was going to ask.

This should be very low priority for anybody to review.