src/net: rename action scripts as per review

Naming the actions after their executing entity, e.g., foo.sh when it is
executed by /bin/sh, is a tried and true paradigm.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-04-20 21:14:54 +02:00
committed by Tobias Waldekranz
parent 47c3448774
commit 6eb6324477
3 changed files with 55 additions and 47 deletions
+23 -23
View File
@@ -25,7 +25,7 @@ The setup we start with and later move `eth4` from `lag0` to `br0`.
eth4 eth5
Consider the case when `next` contains `0`, net reads all interfaces, in
dependency order, from `/run/net/0/` running all `cmd.init` scripts.
dependency order, from `/run/net/0/` running all `init.cmd` scripts.
When done, it writes `0` to the file `/run/net/gen` and then removes the
`next` file to confirm the generation has been activated.
@@ -38,10 +38,10 @@ When done, it writes `0` to the file `/run/net/gen` and then removes the
| | |-- eth2 -> ../../eth2
| | |-- eth3 -> ../../eth3
| | `-- lag0 -> ../../lag0
| `-- ip.init
| `-- init.ip
|-- eth0/
| |-- deps/
| `-- ip.init
| `-- init.ip
|-- ethX/
| |-- ...
: :
@@ -49,11 +49,11 @@ When done, it writes `0` to the file `/run/net/gen` and then removes the
| |-- deps/
| | |-- eth4 -> ../../eth4
| | `-- eth5 -> ../../eth5
| `-- ip.init
| `-- init.ip
`-- vlan1/
|-- deps/
| `-- br0 -> ../../br0
`-- ip.init
`-- init.ip
The `deps/` sub-directory for each of the interfaces contains symlinks
to any interfaces this interface may depend on. I.e., those interfaces
@@ -75,16 +75,16 @@ and generate the `next` generation. However, as mentioned previously,
when moving leaves between parents we must do so in the dependency order
of the current generation.
So, the user (sysrepo) needs to add `cmd.exit` scripts in the current
tree for every leaf that leaves a parent, and `cmd.init` scripts for
So, the user (sysrepo) needs to add `exit.cmd` scripts in the current
tree for every leaf that leaves a parent, and `init.cmd` scripts for
leaves that are new or added to parents in the next generation.
In our example, interface `eth4` is moved from `lag0` to `br0`, so we
need to run `eth4/ip.exit` in the current generation first to remove
`eth4` from `lag0` before its `ip.init` script in the next generation
need to run `eth4/exit.ip` in the current generation first to remove
`eth4` from `lag0` before its `init.ip` script in the next generation
sets `eth4` as a bridge member instead.
We traverse the current generation and execute all `cmd.exit` scripts:
We traverse the current generation and execute all `exit.cmd` scripts:
/run/net/<GEN>/
|-- br0/
@@ -93,25 +93,25 @@ We traverse the current generation and execute all `cmd.exit` scripts:
| | |-- eth2 -> ../../eth2
| | |-- eth3 -> ../../eth3
| | `-- lag0 -> ../../lag0
| `-- ip.init
| `-- init.ip
|-- eth0/
| |-- deps/
| `-- ip.init
| `-- init.ip
|-- eth4/
| |-- deps/
| |-- ip.exit
| `-- ip.init
| |-- exit.ip
| `-- init.ip
|-- lag0/
| |-- deps/
| | |-- eth4 -> ../../eth4
| | `-- eth5 -> ../../eth5
| `-- ip.init
| `-- init.ip
`-- vlan1/
|-- deps/
| `-- br0 -> ../../br0
`-- ip.init
`-- init.ip
Now we can run all the `cmd.init` scripts in the next generation:
Now we can run all the `init.cmd` scripts in the next generation:
/run/net/<GEN+1>/
|-- br0/
@@ -121,24 +121,24 @@ Now we can run all the `cmd.init` scripts in the next generation:
| | |-- eth3 -> ../../eth3
| | |-- eth4 -> ../../eth4
| | `-- lag0 -> ../../lag0
| `-- ip.init
| `-- init.ip
|-- eth0/
| |-- deps/
| `-- ip.init
| `-- init.ip
|-- eth4/
| |-- deps/
| `-- ip.init
| `-- init.ip
|-- lag0/
| |-- deps/
| | `-- eth5 -> ../../eth5
| `-- ip.init
| `-- init.ip
`-- vlan1/
|-- deps/
| `-- br0 -> ../../br0
`-- ip.init
`-- init.ip
When there are no changes compared to the previous generation, the
`cmd.init` scripts can be empty. The existence of an `ip.init` script,
`init.cmd` scripts can be empty. The existence of an `init.ip` script,
however, means that it is allowed to be brought up on `net up`. The
existence of a directory (named after an interface) means the interface
should be brought down on `net down`. Doing `net up ifname` is a subset
+18 -9
View File
@@ -127,14 +127,23 @@ static int pipeit(FILE *pp, const char *action)
static int run(const char *action)
{
char *ptr;
int rc;
if (strstr(action, "/ip.") || strstr(action, "/lag."))
ptr = strrchr(action, '.');
if (!ptr) {
warnx("invalid action script: '%s'", action);
return 0;
}
if (strcmp(action, ".ip"))
return pipeit(ip, action);
if (strstr(action, "/bridge."))
if (strcmp(action, ".bridge"))
return pipeit(bridge, action);
/* ethool does not support batch mode (yet) */
/* other actions are plain shell scripts (.sh) */
log("running %s ...", action);
rc = systemf("%s", action);
if (rc)
warn("failed %s, rc %d", action, rc);
@@ -237,9 +246,9 @@ static int deactivate(const char *net, char *gen)
{
char path[strlen(net) + strlen(gen) + 5 + IFNAMSIZ];
char *action[] = {
"bridge.exit",
"ip.exit",
"ethtool.exit",
"exit.bridge",
"exit.ip",
"exit-ethtool.sh",
};
int rc = 0;
@@ -254,9 +263,9 @@ static int activate(const char *net, char *gen)
{
char path[strlen(net) + strlen(gen) + 5 + IFNAMSIZ];
char *action[] = {
"ethtool.init",
"ip.init",
"bridge.init",
"init-ethtool.sh",
"init.ip",
"init.bridge",
};
int rc = 0;
+14 -15
View File
@@ -44,30 +44,29 @@ mkdir -p $NET_DIR/0/eth3/deps
mkdir -p $NET_DIR/0/eth4/deps
mkdir -p $NET_DIR/0/eth5/deps
gensh $NET_DIR/0/eth0/ip.init
gensh $NET_DIR/0/eth1/ip.init
gensh $NET_DIR/0/eth2/ip.init
gensh $NET_DIR/0/eth3/ip.init
gensh $NET_DIR/0/eth4/ip.init
gensh $NET_DIR/0/eth5/ip.init
gensh $NET_DIR/0/eth0/init.ip
gensh $NET_DIR/0/eth1/init.ip
gensh $NET_DIR/0/eth2/init.ip
gensh $NET_DIR/0/eth3/init.ip
gensh $NET_DIR/0/eth4/init.ip
gensh $NET_DIR/0/eth5/init.ip
mkdir -p $NET_DIR/0/lag0/deps
ln -sf ../../eth4 $NET_DIR/0/lag0/deps/
ln -sf ../../eth5 $NET_DIR/0/lag0/deps/
gensh $NET_DIR/0/lag0/lag.init
gensh $NET_DIR/0/lag0/ip.init
gensh $NET_DIR/0/lag0/init.ip
mkdir -p $NET_DIR/0/br0/deps
ln -sf ../../eth1 $NET_DIR/0/br0/deps/
ln -sf ../../eth2 $NET_DIR/0/br0/deps/
ln -sf ../../eth3 $NET_DIR/0/br0/deps/
ln -sf ../../lag0 $NET_DIR/0/br0/deps/
gensh $NET_DIR/0/br0/bridge.init
gensh $NET_DIR/0/br0/ip.init
gensh $NET_DIR/0/br0/init.bridge
gensh $NET_DIR/0/br0/init.ip
mkdir -p $NET_DIR/0/vlan1/deps
ln -sf ../../br0 $NET_DIR/0/vlan1/deps/
gensh $NET_DIR/0/vlan1/ip.init
gensh $NET_DIR/0/vlan1/init.ip
check "initial startup, gen 0"
cat $NET_DIR/0/rdeps
@@ -94,8 +93,8 @@ ln -sf ../../eth4 $NET_DIR/1/br0/deps/
mkdir -p $NET_DIR/1/vlan1/deps
ln -sf ../../br0 $NET_DIR/1/vlan1/deps/
gensh $NET_DIR/0/eth4/ip.exit
gensh $NET_DIR/1/eth4/ip.init
gensh $NET_DIR/0/eth4/exit.ip
gensh $NET_DIR/1/eth4/init.ip
echo 1 > $NET_DIR/next
check "move eth4 from lag0 to br0"
@@ -114,8 +113,8 @@ mkdir -p $NET_DIR/2/eth5/deps
mkdir -p $NET_DIR/2/lag0/deps
ln -sf ../../eth5 $NET_DIR/2/lag0/deps/
gensh $NET_DIR/1/vlan1/ip.exit
gensh $NET_DIR/1/br0/ip.exit
gensh $NET_DIR/1/vlan1/exit.ip
gensh $NET_DIR/1/br0/exit.ip
echo 2 > $NET_DIR/next
check "delete vlan1 and br0"