Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5503991
src/net: ovarhaul script naming ip-link.up/ip-addr.up -> ip.init etc
troglobit Apr 12, 2023
aec2001
src/net: new test, also drop lo and use same interfaces as in figure
troglobit Apr 13, 2023
5ce2e57
src/net: calculate and run teardown in reverse dependency order
troglobit Apr 13, 2023
55bb9fc
src/net: rename action scripts as per review
troglobit Apr 13, 2023
3fa31f0
src/net: fix bug in test, lag0 remains a dep for br0 even in gen 1
troglobit Apr 13, 2023
795a796
src/net: fix bug in savedep(), trashed interface path argument
troglobit Apr 13, 2023
36ee937
src/net: minor cleanup
troglobit Apr 13, 2023
c2cea4d
src/net: refactor filtering of forbidden names
troglobit Apr 13, 2023
6540405
src/net: add commands; do, up/down with optional ifname(s)
troglobit Apr 14, 2023
aa31ada
src/net: add support for acting as a multicall binary (ifup/ifdown)
troglobit Apr 17, 2023
dbc3f5e
src/net: refactor, reuse existing linked list also for 'do' command
troglobit Apr 17, 2023
a3abeca
src/net: 'do' is a reserved keyword in shell scripts add 'apply' too
troglobit Apr 18, 2023
1950ff2
src/net: increased debugging of basics
troglobit Apr 18, 2023
920f026
src/net: first automated test case, run with unshare
troglobit Apr 18, 2023
e907649
src/net: convert to GNU Configure & Build system
troglobit Apr 18, 2023
bde33d3
src/net: refactor test into lib.sh and <test>.sh
troglobit Apr 18, 2023
677c0ca
src/net: finalize first test, three indep ifaces in two generations
troglobit Apr 18, 2023
5d4c12d
src/net: fix bugs in 'net up|down' uncovered by first test
troglobit Apr 18, 2023
26c972a
src/net: install tests to target /usr/share/net
troglobit Apr 18, 2023
34689ea
src/net: new test, basic bridge
troglobit Apr 18, 2023
2cef92d
src/net: factor out pipe identification and debug each piped command
troglobit Apr 19, 2023
49a4e72
src/net: must close each pipe before exectuing the next pipe action
troglobit Apr 19, 2023
e237d8e
src/net: fix interface creation/attach order in generation generator
troglobit Apr 19, 2023
da1be7a
src/net: new test, advanced bridge with lag and a top VLAN interface
troglobit Apr 19, 2023
c8a3800
src/net: rename helper fn create_ng -> init_next_gen
troglobit Apr 19, 2023
44ac515
src/net: silence noisy "skipping" debug logs for missing scripts
troglobit Apr 20, 2023
5b0599a
src/net: test; factor out state file creation from create_iface()
troglobit Apr 20, 2023
6ccf564
src/net: update basic bridge test with new create_bridge() API
troglobit Apr 20, 2023
91b3cc8
src/net: add test to verify moving port from lag to bridge
troglobit Apr 20, 2023
ec36522
src/net: let init_next_gen init new generation with ifaces
troglobit Apr 20, 2023
ed7950d
src/net: finalize bridge-lag.sh test, add step remove; vlan1 and br0
troglobit Apr 20, 2023
7349c8d
src/net: add missing deps when moving between generations
troglobit Apr 20, 2023
d741483
package/confd: update package dependencies
troglobit Apr 20, 2023
629831f
package/net: new package
troglobit Apr 20, 2023
77cbaa6
package/net: depends also on iproute2
troglobit Apr 20, 2023
4c818c7
src/net: update docs with new admin-state control file
troglobit Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configs/aarch64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ BR2_PACKAGE_FINIT_PLUGIN_TTY=y
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
BR2_PACKAGE_IFUPDOWN_NG=y
BR2_PACKAGE_KLINFIX=y
BR2_PACKAGE_NET=y
BR2_PACKAGE_P_NET=y
BR2_PACKAGE_P_NET_MAX_SUBSLOTS=12
BR2_PACKAGE_P_NET_MAX_PHYSICAL_PORTS=10
Expand Down
1 change: 1 addition & 0 deletions configs/amd64_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ BR2_PACKAGE_FINIT_PLUGIN_TTY=y
BR2_PACKAGE_FINIT_PLUGIN_URANDOM=y
BR2_PACKAGE_IFUPDOWN_NG=y
BR2_PACKAGE_KLINFIX=y
BR2_PACKAGE_NET=y
BR2_PACKAGE_P_NET=y
BR2_PACKAGE_P_NET_MAX_SUBSLOTS=12
BR2_PACKAGE_P_NET_MAX_PHYSICAL_PORTS=10
Expand Down
1 change: 1 addition & 0 deletions package/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source "$BR2_EXTERNAL_INFIX_PATH/package/klinfix/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/klish/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/klish-plugin-sysrepo/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/mdnsd/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/net/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/osal/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/p-net/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/profeth/Config.in"
Expand Down
5 changes: 3 additions & 2 deletions package/confd/Config.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
config BR2_PACKAGE_CONFD
bool "confd"
select BR2_PACKAGE_SYSREPO
select BR2_PACKAGE_NETOPEER2
select BR2_PACKAGE_AUGEAS
select BR2_PACKAGE_JANSSON
select BR2_PACKAGE_LIBITE
select BR2_PACKAGE_NETOPEER2
select BR2_PACKAGE_SYSREPO
help
A plugin to sysrepo that provides the core YANG models used to
manage an Infix based system. Configuration can be done using
Expand Down
2 changes: 1 addition & 1 deletion package/confd/confd.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CONFD_VERSION = 1.0
CONFD_LICENSE = BSD-3-Clause
CONFD_SITE_METHOD = local
CONFD_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/confd
CONFD_DEPENDENCIES = augeas sysrepo
CONFD_DEPENDENCIES = augeas jansson libite sysrepo
CONFD_AUTORECONF = YES

define CONFD_INSTALL_EXTRA
Expand Down
6 changes: 6 additions & 0 deletions package/net/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config BR2_PACKAGE_NET
bool "net"
select BR2_PACKAGE_IPROUTE2
select BR2_PACKAGE_LIBITE
help
Handles transitions between network states.
19 changes: 19 additions & 0 deletions package/net/net.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
################################################################################
#
# net
#
################################################################################

NET_VERSION = 1.0
NET_LICENSE = ISC
NET_SITE_METHOD = local
NET_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/net
NET_DEPENDENCIES = libite
NET_AUTORECONF = YES

define NET_INSTALL_EXTRA
chmod +x $(TARGET_DIR)/usr/share/net/*.sh
endef
NET_TARGET_FINALIZE_HOOKS += NET_INSTALL_EXTRA

$(eval $(autotools-package))
11 changes: 11 additions & 0 deletions src/net/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
*.o
*.log
*.trs
net
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
aux/
config.*
configure
src/.deps/
stamp-h1
19 changes: 19 additions & 0 deletions src/net/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2023 The KernelKit Authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
14 changes: 0 additions & 14 deletions src/net/Makefile

This file was deleted.

4 changes: 4 additions & 0 deletions src/net/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SUBDIRS = src test
DISTCLEANFILES = *~ *.d
ACLOCAL_AMFLAGS = -I m4

103 changes: 56 additions & 47 deletions src/net/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Concept Overview
----------------

net applies a configuration from `/run/net/next`, where `next` is a file
that holds the number of the current generation. It is up to the user,
that holds the number of the next net generation. It is up to the user,
i.e., sysrepo, to create the below tree structure with commands to run.

The setup we start with and later move `eth4` from `lag0` to `br0`.
Expand All @@ -25,43 +25,39 @@ 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 `ip-link` and `ip-addr`
commands. When done, it writes `0` to the file `/run/net/gen` and then
removes the `next` file to confirm the generation has been activated.
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.

**Note:** it is currently up to the user to remove any old generation.

/run/net/0/
|-- lo/
| |-- deps/
| |-- ip-link.up
| `-- ip-addr.up
|-- br0/
| |-- deps/
| | |-- eth1 -> ../../eth1
| | |-- eth2 -> ../../eth2
| | |-- eth3 -> ../../eth3
| | `-- lag0 -> ../../lag0
| |-- ip-link.up
| `-- ip-addr.up
| |-- admin-state
| `-- init.ip
|-- eth0/
| |-- deps/
| |-- ip-link.up
| `-- ip-addr.up
| |-- admin-state
| `-- init.ip
|-- ethX/
| |-- ...
: :
|-- lag0/
| |-- deps/
| | |-- eth4 -> ../../eth4
| | `-- eth5 -> ../../eth5
| |-- ip-link.up
| `-- ip-addr.up
| |-- admin-state
| `-- init.ip
`-- vlan1/
|-- deps/
| `-- br0 -> ../../br0
|-- ip-link.up
`-- ip-addr.up
|-- admin-state
`-- 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
Expand All @@ -70,7 +66,7 @@ are evaluated first.
Essentially, all leaves must be set up before their parents. Moving a
leaf from one parent to another, e.g., from lag0 to br0, is tricky, it
involves traversing the previous dependency order when removing leaves,
and traversing the next dependency order when addning, see next section
and traversing the next dependency order when adding, see next section
for an example.


Expand All @@ -83,76 +79,89 @@ 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 `.dn` scripts in the current tree,
and `.up` scripts in the next.
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-link.dn` in the current generation first to remove
`eth4` from `lag0` before its `ip-link.up` 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 `.dn` scripts:
We traverse the current generation and execute all `exit.cmd` scripts:

/run/net/<GEN>/
|-- lo/
| `-- deps/
|-- br0/
| |-- deps/
| | |-- eth1 -> ../../eth1
| | |-- eth2 -> ../../eth2
| | |-- eth3 -> ../../eth3
| | `-- lag0 -> ../../lag0
| `-- ip-link.up
| |-- admin-state
| `-- init.ip
|-- eth0/
| |-- deps/
| |-- ip-link.up
| `-- ip-addr.up
| |-- admin-state
| `-- init.ip
|-- eth4/
| |-- deps/
| |-- ip-link.dn
| `-- ip-link.up
| |-- admin-state
| |-- exit.ip
| `-- init.ip
|-- lag0/
| |-- deps/
| | |-- eth4 -> ../../eth4
| | `-- eth5 -> ../../eth5
| `-- ip-link.up
| |-- admin-state
| `-- init.ip
`-- vlan1/
|-- deps/
| `-- br0 -> ../../br0
|-- ip-link.up
`-- ip-addr.up
|-- admin-state
`-- init.ip

Now we can run all the `.up` scripts in the next generation:
Now we can run all the `init.cmd` scripts in the next generation:

/run/net/<GEN+1>/
|-- lo/
| |-- deps/
| |-- ip-link.up
| `-- ip-addr.up
|-- br0/
| |-- deps/
| | |-- eth1 -> ../../eth1
| | |-- eth2 -> ../../eth2
| | |-- eth3 -> ../../eth3
| | |-- eth4 -> ../../eth4
| | `-- lag0 -> ../../lag0
| `-- ip-link.up
| |-- admin-state
| `-- init.ip
|-- eth0/
| |-- deps/
| |-- ip-link.up
| `-- ip-addr.up
| |-- admin-state
| `-- init.ip
|-- eth4/
| |-- deps/
| |-- ip-link.dn
| `-- ip-link.up
| |-- admin-state
| `-- init.ip
|-- lag0/
| |-- deps/
| | `-- eth5 -> ../../eth5
| `-- ip-link.up
| |-- admin-state
| `-- init.ip
`-- vlan1/
|-- deps/
| `-- br0 -> ../../br0
|-- ip-link.up
`-- ip-addr.up


|-- admin-state
`-- init.ip

When there are no changes compared to the previous generation, the base
structure with deps need to remain intact, but there's no need for any
`init.cmd` scripts. However, for the purpose of supporting the commands
`net down` and `net up`, the user must have an `admin-state` file per
interface which must contain one of:

- disabled
- up
- down

This describes the state which the user's last `init.ip` or `exit.ip`
command, or the `net [up | down]` action, left the interface in. When
the `disabled` keyword is used it means the net tool is not allowed to
apply any `up` or `down` action on the interface.
3 changes: 3 additions & 0 deletions src/net/autogen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

autoreconf -W portability -vifm
40 changes: 40 additions & 0 deletions src/net/configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
AC_PREREQ(2.61)
AC_INIT([net], [1.0], [https://github.com/kernelkit/infix/issues])
AC_CONFIG_AUX_DIR(aux)
AM_INIT_AUTOMAKE([1.11 foreign])
AM_SILENT_RULES([yes])

AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile src/Makefile test/Makefile])
AC_CONFIG_MACRO_DIR([m4])

AC_PROG_CC
AC_PROG_INSTALL

# Check for pkg-config first, warn if it's not installed
PKG_PROG_PKG_CONFIG
PKG_CHECK_MODULES([libite], [libite >= 2.5.0])

AC_OUTPUT

SYSCONFDIR=`eval echo $sysconfdir`
RUNSTATEDIR=`eval echo $runstatedir`
RUNSTATEDIR=`eval echo $RUNSTATEDIR`
cat <<EOF

------------------ Summary ------------------
$PACKAGE_NAME version $PACKAGE_VERSION
Prefix.........: $prefix
Sysconfdir.....: $SYSCONFDIR
Runstatedir....: $RUNSTATEDIR
C Compiler.....: $CC $CFLAGS $CPPFLAGS $LDFLAGS $LIBS

------------- Compiler version --------------
$($CC --version || true)
---------------------------------------------

Check the above options and compile with:
${MAKE-make}

EOF
Loading