1
0
mirror of https://github.com/wfjm/w11.git synced 2026-03-10 21:03:26 +00:00

revamp tap and bridge handling [skip ci]

- ip_inspect, ip_create_br: removed
- ip_create_tap: rewritten with 'ip' commands
This commit is contained in:
wfjm
2023-02-12 18:24:47 +01:00
parent 7a72da83d6
commit 95bc9be957
8 changed files with 30 additions and 336 deletions

View File

@@ -29,8 +29,13 @@ software or firmware builds or that the documentation is consistent.
The full set of tests is only run for tagged releases.
### Summary
- revamp tap and bridge handling
### New features
### Changes
- tools changes
- tools/bin
- ip_inspect, ip_create_br: removed
- ip_create_tap: rewritten with 'ip' commands
### Bug Fixes
<!-- --------------------------------------------------------------------- -->

View File

@@ -1,72 +0,0 @@
#!/bin/bash
# $Id: ip_create_br 1172 2019-06-29 07:27:24Z mueller $
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright 2017-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
#
# Revision History:
# Date Rev Version Comment
# 2017-04-14 873 1.0 Initial version
# 2017-03-04 858 0.5 First draft
#
# some preparations
defeif=$(ip_inspect defeif)
if [[ -z $defeif ]]; then
echo "ip_create_br-I: default interface not found"
exit 1
fi
hostaddr=$(ip_inspect addr4 $defeif addr)
hostmask=$(ip_inspect addr4 $defeif mask)
hostbcast=$(ip_inspect addr4 $defeif bcast)
hostdgway=`route -n | grep ^0.0.0.0 |\
gawk -- '{ print $2 }'`
if [[ -z "$hostaddr" || -z "$hostmask" || -z "$hostbcast" || -z "$hostdgway" ]]
then
echo "ip_create_br-E: failed to determine current setup"
exit 1
fi
# echo $defeif
# echo $hostaddr
# echo $hostmask
# echo $hostbcast
# echo $hostdgway
# sanitize PATH, use what sudo has
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
which_ip=$(which ip)
which_ifconfig=$(which ifconfig)
which_brctl=$(which brctl)
which_route=$(which route)
if [[ -z "$which_ip" || -z "$which_ifconfig" ||
-z "$which_brctl" || -z "$which_route" ]]
then
echo "ip_create_br-E: ip, ifconfig, brctl, or route not in PATH"
exit 1
fi
if $which_ifconfig | grep -q "br0\s*Link"
then
echo "ip_create_br-I: Bridge br0 already exists"
exit 1
fi
# print info so that sudo password prompt is expected
if [[ $(id -u) -ne 0 ]] ; then echo "ip_create_br-I: requires sudo" ; fi
sudo $which_brctl addbr br0
sudo $which_brctl addif br0 $defeif
sudo $which_brctl setfd br0 0
sudo $which_ifconfig $defeif 0.0.0.0
sudo $which_ifconfig br0 $hostaddr netmask $hostmask broadcast $hostbcast up
# set the default route to the br0 interface
sudo $which_route add -net 0.0.0.0/0 gw $hostdgway
#
$which_ifconfig br0
$which_route

View File

@@ -1,144 +0,0 @@
#!/usr/bin/perl -w
# $Id: ip_inspect 1172 2019-06-29 07:27:24Z mueller $
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright 2017-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
#
# Revision History:
# Date Rev Version Comment
# 2018-12-18 1089 0.1.1 add and use bailout
# 2017-04-08 872 0.1 First draft
#
use 5.14.0; # require Perl 5.14 or higher
use strict; # require strict checking
use Getopt::Long;
my %opts = ();
GetOptions(\%opts,
)
or bailout("bad command options");
autoflush STDOUT 1 if (-p STDOUT); # autoflush if output into pipe
my $cmd = shift @ARGV;
bailout("missing command; use 'ip_inspect help'") unless (defined $cmd);
if ($cmd eq "help") {
print_usage();
} elsif ($cmd eq "defeif") {
do_defeif();
} elsif ($cmd eq "addr4") {
do_addr4();
} elsif ($cmd eq "defroute") {
do_defroute();
} else {
bailout("invalid command '$cmd'");
}
exit 0;
#-------------------------------------------------------------------------------
sub do_defeif {
my @devs;
open (IPRES, "ip link show|") or bailout("failed to call ip");
while (<IPRES>) {
chomp;
next unless m|^\d+:\s*(\w+):|;
my $dev = $1;
next unless $dev =~ m/^(en|eth)/;
push @devs,$dev;
}
close (IPRES);
bailout("failed to detect default device") if (scalar(@devs) == 0);
if (scalar(@devs) > 1) {
my $devstr = join ',',@devs;
bailout("multiple ethernet interfaces '$devstr'");
}
print "$devs[0]\n";
return;
}
#-------------------------------------------------------------------------------
sub do_addr4 {
my $dev = shift @ARGV;
my $fld = shift @ARGV;
bailout("missing device or field") unless (defined $dev && defined $fld);
my $addr;
my $size;
my $bcast;
open (IPRES, "ip addr show dev $dev|") or bailout("failed to call ip");
while (<IPRES>) {
chomp;
next unless m|^\s+inet\s+([0-9.]+)/(\d+)\s+brd\s+([0-9.]+)|;
$addr = $1;
$size = $2;
$bcast = $3;
}
close (IPRES);
if ($fld eq "addr") {
print "$addr\n";
} elsif ($fld eq "addrm") {
print "$addr/$size\n";
} elsif ($fld eq "mask") {
my $mask = size2mask($size);
print "$mask\n";
} elsif ($fld eq "bcast") {
print "$bcast\n";
} else {
bailout("invalid field '$fld'");
}
return;
}
#-------------------------------------------------------------------------------
sub do_defroute {
open (IPRES, "ip route show|") or bailout("failed to call ip");
while (<IPRES>) {
chomp;
if (m|^default via\s+([0-9.]+)|) {
close (IPRES);
print "$1\n";
return;
}
}
bailout("failed to find default route");
}
#-------------------------------------------------------------------------------
sub size2mask {
my ($size) = @_;
my $bmask = ('1' x $size) . ('0' x (32-$size));
my $dmask = oct("0b".substr($bmask, 0,8)) . '.' .
oct("0b".substr($bmask, 8,8)) . '.' .
oct("0b".substr($bmask,16,8)) . '.' .
oct("0b".substr($bmask,24,8));
return $dmask;
}
#-------------------------------------------------------------------------------
sub bailout {
my ($msg) = @_;
print STDERR "ip_inspect-F: $msg\n";
exit 1;
}
#-------------------------------------------------------------------------------
sub print_usage {
print "usage: ip_inspect <command> <args>\n";
print " ip_inspect defeif # get default eth interface\n";
print " ip_inspect addr4 <if> addrm # get ip4 addr/mask\n";
print " ip_inspect addr4 <if> addr # get ip4 bare addr\n";
print " ip_inspect addr4 <if> mask # get ip4 subnet mask\n";
print " ip_inspect addr4 <if> bcast # get ip4 bcast addr\n";
print " ip_inspect defroute # get default route\n";
return;
}

View File

@@ -1,42 +0,0 @@
.\" -*- nroff -*-
.\" $Id: ip_create_br.1 1237 2022-05-15 07:51:47Z mueller $
.\" SPDX-License-Identifier: GPL-3.0-or-later
.\" Copyright 2017-2022 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
.\"
.\" ------------------------------------------------------------------
.
.TH IP_CREATE_BR 1 2017-04-14 "Retro Project" "Retro Project Manual"
.\" ------------------------------------------------------------------
.SH NAME
ip_create_br \- create bridge and re-connect ethernet interface
.\" ------------------------------------------------------------------
.SH SYNOPSIS
.
.SY ip_create_br
.YS
.
.\" ------------------------------------------------------------------
.SH DESCRIPTION
This script expects a default single Ethernet interface setup, creates
a bridge named 'br0', and re-connects the Ethernet interface to this bridge.
The script bails out gracefully in case 'br0' already exists. In not, it
determines the name of the Ethernet interface, accepting both old 'eth*' and
new 'en*' naming, and verifies that it is a single Ethernet configuration.
Then it creates a bridge device named 'br0' and re-connects the physical
Ethernet interface to the bridge, preserving all IP addresses and routes.
This script is part of setting up tap devices with \fBip_create_tap\fR(1)
but can be used independently.
The script should be started as a normal user, but uses \fBsudo\fR(8) to
execute privileged commands, and might therefore ask for the user password.
.
.\" ------------------------------------------------------------------
.SH "SEE ALSO"
.BR ip_create_tap (1)
.\" ------------------------------------------------------------------
.SH AUTHOR
Walter F.J. Mueller <W.F.J.Mueller@gsi.de>

View File

@@ -1,11 +1,11 @@
.\" -*- nroff -*-
.\" $Id: ip_create_tap.1 1237 2022-05-15 07:51:47Z mueller $
.\" $Id: ip_create_tap.1 1372 2023-02-12 17:18:38Z mueller $
.\" SPDX-License-Identifier: GPL-3.0-or-later
.\" Copyright 2017-2022 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
.\" Copyright 2017-2023 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
.\"
.\" ------------------------------------------------------------------
.
.TH IP_CREATE_TAP 1 2017-04-14 "Retro Project" "Retro Project Manual"
.TH IP_CREATE_TAP 1 2023-02-12 "Retro Project" "Retro Project Manual"
.\" ------------------------------------------------------------------
.SH NAME
ip_create_tap \- add a user-mode tap device to a bridge
@@ -13,28 +13,29 @@ ip_create_tap \- add a user-mode tap device to a bridge
.SH SYNOPSIS
.
.SY ip_create_tap
.OP \-dry
.RI [ TAPNAME ]
.RI [ BRIDGENAME ]
.YS
.
.\" ------------------------------------------------------------------
.SH DESCRIPTION
This script adds user-mode a tap device to a bridge and creates the bridge
in case it doesn't exist already.
This script adds a tap device, named \fITAPNAME\fP or 'tap0' by default,
to a bridge, named \fIBRIDGENAME\fP or 'br0' by default.
The script first checks whether 'br0' exists, if not \fBip_create_br\fR(1)
is executed. Then a tap device is created, named \fITAPNAME\fP or 'tap0'
by default. The tap device will be accessible to the user which executes
the script. Finally, the created tap device is connected to bridge 'br0'.
The script first checks whether the tap device already exists and exits
if it does. Next, the script first checks whether the bridge exists and
exits with an error if not. Then, a tap device is created.
The tap device will be accessible to the user which executes the script.
Finally, the created tap device is connected to the bridge.
The script should be started as a normal user, but uses \fBsudo\fR(8) to
If the \fB\-dry\fP option is specified, the generated commands are only
printed and not executed.
The script should be run as a normal user. It uses \fBsudo\fR(8) to
execute privileged commands, and might therefore ask for the user password.
.
.\" ------------------------------------------------------------------
.SH "SEE ALSO"
.BR ip_create_br (1)
.\" ------------------------------------------------------------------
.SH AUTHOR
Walter F.J. Mueller <W.F.J.Mueller@gsi.de>

View File

@@ -1,49 +0,0 @@
.\" -*- nroff -*-
.\" $Id: ip_inspect.1 1237 2022-05-15 07:51:47Z mueller $
.\" SPDX-License-Identifier: GPL-3.0-or-later
.\" Copyright 2022- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
.\"
.\" ------------------------------------------------------------------
.
.TH IP_INSPECT 2018-12-18 "Retro Project" "Retro Project Manual"
.\" ------------------------------------------------------------------
.SH NAME
ip_inspect \- inquire individual network object properties
.\" ------------------------------------------------------------------
.SH SYNOPSIS
.
.SY ip_inspect defeif
.SY ip_inspect defroute
.SY ip_inspect addr4
.I LINK
addrm | addr | mask | bcast
.SY ip_inspect help
.YS
.
.\" ------------------------------------------------------------------
.SH DESCRIPTION
\fB\ip_inspect\fP inquire individual network object properties from \fBip\fP(1).
Currently implemented properties are:
.IP "\fBip_inspect defeif\fR"
returns default ethernet interface (e.g. "enp2s0")
.\" ----------------------------------------------
.IP "\fBip_inspect defroute\fR"
returns default route
.\" ----------------------------------------------
.IP "\fBip_inspect addr4 \fILINK\fP addrm\fR"
returns ip4 address/mask for interface \fILINK\fP (e.g. "192.168.178.20/24")
.\" ----------------------------------------------
.IP "\fBip_inspect addr4 \fILINK\fP addr\fR"
returns ip4 address for interface \fILINK\fP (e.g. "192.168.178.20")
.\" ----------------------------------------------
.IP "\fBip_inspect addr4 \fILINK\fP mask\fR"
returns ip4 address mask for interface \fILINK\fP (e.g. "255.255.255.0")
.\" ----------------------------------------------
.IP "\fBip_inspect addr4 \fILINK\fP bcast\fR"
returns ip4 broadcast address for interface \fILINK\fP (e.g. "192.168.178.255")
.\" ------------------------------------------------------------------
.
.SH AUTHOR
Walter F.J. Mueller <W.F.J.Mueller@gsi.de>

View File

@@ -110,7 +110,7 @@ Download, unpack and copy the disk images (*.dsk), e.g.
Now the system is in multi-user mode, daemons running. You can explore
the system, e.g. with a `pstat -T` or a `mount` command.
The second DL11 and the first four DZ11 lines can me activated too.
The second DL11 and the first four DZ11 lines can be activated too.
Also simple networking via SLIP and a DZ11 line, for details see
[using SLIP with 211bsd](../doc/211bsd_slip.md).

View File

@@ -8,22 +8,17 @@ with the Linux host as well as with any other node.
### Setup of _tap_ and _bridge_
The _tap_ device should be created such that it is accessible by the
account under with _ti_w11_ executes. This way only setting up _tap_
and _bridge_ require root access, but not subsequent usage.
account under with _ti_w11_ executes. This way only setting up the _tap_
device require root access, but not subsequent usage.
Two support scripts help in the set up
A support script
```
ip_create_br
ip_create_tap [tap-name] [bridge-name]
```
creates a bridge named _br0_ and re-connects the physical ethernet interface.
The script works on a PC with a single physical Ethernet interface.
```
ip_create_tap [tap-name]
```
add a user-mode _tap_ device to the bridge _br0_. If the bridge doesn't exist
`ip_create_br` is called. If no name is given _tap0_ is used.
creates a new _tap_ device and connects it to an already existing _bridge_.
If no names are given _tap0_ and _br0_ are used, respectively.
The _tap_ device will be accessible by the account that executes the
`ip_create_tap` command.
### Used MAC addresses
The MAC addresses used by w11a are