interfaces: move to :slaac suffix use, fixing in ifctl #5862

This breaks the new feature in the interim since the router file
read is not yet supposed to read :slaac counterpart since the router
file is still read manually.  Refactor to follow.
This commit is contained in:
Franco Fichtner 2022-07-25 09:56:08 +02:00
parent 3c18be1086
commit 2e2e59c1d8
3 changed files with 52 additions and 27 deletions

View File

@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd July 22, 2022
.Dd July 25, 2022
.Dt IFCTL 8
.Os
.Sh NAME
@ -41,12 +41,22 @@ The
.Nm
utility will display or modify network device related data used by dynamic
connections.
If one of
.Pp
If none of
.Sq Fl c ,
.Sq Fl d
or
.Sq Fl a
are given the current data is returned instead of modifying it.
In this case a special interface suffix
.Sq :slaac
is supported as a fallback option and read if no data file was found
for the exact interface match.
During modification using any option mentioned above, however, the
.Sq :slaac
suffix must be given explicitly through the
.Sq Fl i
parameter.
.Pp
The options are as follows:
.Bl -tag -width ".Fl i Ar interface" -offset indent
@ -70,6 +80,10 @@ Delete the specified data of the selected device.
Select the
.Ar device
to operate on.
Special suffix
.Sq :slaac
given creates a fallback configuration file only to be read
if no exact match for the selected interface exists.
If none was given
.Nm
list the available devices.

View File

@ -58,10 +58,10 @@ while getopts 46a:cdi:lnprsV OPT; do
EX=v6
;;
a)
DO_COMMAND="-a"
DO_CONTENTS="${DO_CONTENTS} ${OPTARG}"
;;
c)
DO_COMMAND="-c"
MD="nameserver prefix router searchdomain"
;;
d)
@ -107,9 +107,11 @@ if [ "${DO_COMMAND}" = "-c" ]; then
# iterate through possible files
for MD in nameserver prefix router searchdomain; do
FILE="/tmp/${IF}_${MD}${EX}"
flush_routes
rm -f ${FILE}
for IFC in ${IF} ${IF}:slaac; do
FILE="/tmp/${IFC}_${MD}${EX}"
flush_routes
rm -f ${FILE}
done
done
exit 0
@ -138,11 +140,22 @@ fi
if [ "${DO_COMMAND}" = "-d" ]; then
flush_routes
rm -f ${FILE}
elif [ "${DO_COMMAND}" = "-a" ]; then
for CONTENT in ${DO_CONTENTS}; do
echo "${CONTENT}" >> ${FILE}
done
fi
for CONTENT in ${DO_CONTENTS}; do
echo "${CONTENT}" >> ${FILE}
done
if [ -n "${DO_COMMAND}${DO_CONTENT}" ]; then
exit 0
fi
if [ ! -f ${FILE} ]; then
# move to :slaac interface suffix if not found
FILE="/tmp/${IF}:slaac_${MD}${EX}"
fi
# if nothing else could be done display data
elif [ -f ${FILE} ]; then
if [ -f ${FILE} ]; then
cat ${FILE}
fi

View File

@ -33,25 +33,16 @@ if [ -z "${2}" ]; then
fi
# ${2} is 'ifname:slaac:[RA-source-address]', where 'ifname' is the
# interface the RA was received on.
# interface the RA was received on. Keep the ":slaac" suffix to create
# an interface fallback configuration handled through ifctl(8) utility.
ifname=${2%%:*}
rasrca=${2##*:slaac:[}
ifname=${2%%:[*}
rasrca=${2##*:[}
rasrca=${rasrca%]}
# XXX replace by exlusive 'ifname:slaac' use and falling back internally in ifctl?
if [ -n "$(/usr/local/sbin/ifctl -i ${ifname} -6r)" ]; then
echo "IPv6 gateway for ${ifname} already exists."
exit 0
fi
# ${1} indicates whether DNS information should be added or deleted.
if [ "${1}" = "-a" ]; then
/usr/local/sbin/ifctl -i ${ifname} -6rd -a ${rasrca}
# XXX stop modifying defaultgw files in scripts
echo ${rasrca} > /tmp/${ifname}_defaultgwv6
# rtsold sends a resolv.conf(5) file to STDIN of this script
while IFS=' ' read -r type value; do
if [ "${type}" = "nameserver" ]; then
@ -71,7 +62,14 @@ if [ "${1}" = "-a" ]; then
/usr/local/sbin/ifctl -i ${ifname} -6nd ${nameservers}
/usr/local/sbin/ifctl -i ${ifname} -6sd ${searchlist}
/usr/local/sbin/configctl -d interface newipv6 ${ifname}
fi
/usr/local/sbin/ifctl -i ${ifname} -6rd -a ${rasrca}
# XXX implement -d as well
# remove slaac suffix here to reload correct interface
/usr/local/sbin/configctl -d interface newipv6 ${ifname%%:slaac}
elif [ "${1}" = "-d" ]; then
/usr/local/sbin/ifctl -i ${ifname} -6nd
/usr/local/sbin/ifctl -i ${ifname} -6sd
# reload DNS since data has been scrubbed
/usr/local/sbin/configctl -d dns reload
fi