diff --git a/board/common/qemu/Config.in.in b/board/common/qemu/Config.in.in index 4e9f7c0c..11268ae3 100644 --- a/board/common/qemu/Config.in.in +++ b/board/common/qemu/Config.in.in @@ -189,7 +189,7 @@ config QEMU_CLOCK comment "Networking" choice - prompt "Mode" + prompt "Network Mode" default QEMU_NET_USER config QEMU_NET_NONE @@ -204,6 +204,9 @@ config QEMU_NET_USER config QEMU_NET_TAP bool "TAP" +config QEMU_NET_ROCKER + bool "Rocker" + endchoice config QEMU_NET_MODEL @@ -229,3 +232,8 @@ config QEMU_NET_TAP_N int "Number of TAPs" depends on QEMU_NET_TAP default 1 + +config QEMU_NET_PORTS + int "Number of Rocker switch ports" + depends on QEMU_NET_ROCKER + default 10 diff --git a/board/common/qemu/qemu.sh b/board/common/qemu/qemu.sh index 3813d4b4..4830cb96 100755 --- a/board/common/qemu/qemu.sh +++ b/board/common/qemu/qemu.sh @@ -17,9 +17,10 @@ # # ./qemu.sh -h # +# shellcheck disable=SC3037 # Local variables -imgdir=$(readlink -f $(dirname "$0")) +imgdir=$(readlink -f "$(dirname "$0")") prognm=$(basename "$0") usage() @@ -30,6 +31,7 @@ usage() echo "Options:" echo " -c Run menuconfig to change Qemu settings" echo " -h This help text" + echo " -k Keep generated qemu.run script (name shown at end)" echo echo "Arguments:" echo " ARGS1 Args before the '--' separator are for kernel space" @@ -54,19 +56,20 @@ die() load_qemucfg() { - local tmp=$(mktemp -p /tmp) + tmp=$(mktemp -p /tmp) - grep ^CONFIG_QEMU_ $1 >$tmp - . $tmp - rm $tmp + grep ^CONFIG_QEMU_ "$1" >"$tmp" + # shellcheck disable=SC1090 + . "$tmp" + rm "$tmp" [ "$CONFIG_QEMU_MACHINE" ] || die "Missing QEMU_MACHINE" [ "$CONFIG_QEMU_ROOTFS" ] || die "Missing QEMU_ROOTFS" - [ "$CONFIG_QEMU_KERNEL" -a "$CONFIG_QEMU_BIOS" ] \ + [ -n "$CONFIG_QEMU_KERNEL" ] && [ -n "$CONFIG_QEMU_BIOS" ] \ && die "QEMU_KERNEL conflicts with QEMU_BIOS" - [ ! "$CONFIG_QEMU_KERNEL" -a ! "$CONFIG_QEMU_BIOS" ] \ + [ -z "$CONFIG_QEMU_KERNEL" ] && [ -z "$CONFIG_QEMU_BIOS" ] \ && die "QEMU_KERNEL or QEMU_BIOS must be set" } @@ -93,7 +96,7 @@ append_args() if [ "$CONFIG_QEMU_ROOTFS_INITRD" = "y" ]; then # Size of initrd, rounded up to nearest kb - local size=$((($(stat -c %s $CONFIG_QEMU_ROOTFS) + 1023) >> 10)) + size=$((($(stat -c %s "$CONFIG_QEMU_ROOTFS") + 1023) >> 10)) echo -n "root=/dev/ram0 ramdisk_size=${size} " elif [ "$CONFIG_QEMU_ROOTFS_VSCSI" = "y" ]; then echo -n "root=PARTLABEL=primary " @@ -198,13 +201,24 @@ host_args() net_dev_args() { - local name="e$1" - local mac=$(printf "02:00:00:00:00:%02x" $1) + name="e$1" + mac=$(printf "02:00:00:00:00:%02x" "$1") echo -n "-device $CONFIG_QEMU_NET_MODEL,netdev=$name,mac=$mac " echo "$name $mac" >>"$mactab" } +rocker_port_args() +{ + sw=$1 + port=$2 + name="sw${sw}p${port}" + mac=$(printf "02:00:00:00:%02x:%02x" "$sw" "$port") + + echo -n "-netdev tap,id=$name,ifname=$name,script=no,downscript=no " + echo "$name $mac" >> "$mactab" +} + net_args() { # Infix will pick up this file via fwcfg and install it to /etc @@ -216,14 +230,25 @@ net_args() echo -n "-netdev bridge,id=e1,br=$CONFIG_QEMU_NET_BRIDGE_DEV " net_dev_args 1 elif [ "$CONFIG_QEMU_NET_TAP" = "y" ]; then - for i in $(seq 1 $(($CONFIG_QEMU_NET_TAP_N))); do + for i in $(seq 1 "$CONFIG_QEMU_NET_TAP_N"); do echo -n "-netdev tap,id=e$i,ifname=qtap$i " - net_dev_args $i + net_dev_args "$i" + done + elif [ "$CONFIG_QEMU_NET_ROCKER" = "y" ]; then + sw=sw0 # Only single switch support atm. + echo -n "-device '{\"driver\":\"rocker\", \"name\":\"${sw}\", " + echo -n "\"fp_start_macaddr\":\"02:00:00:00:00:01\", " + echo -n "\"ports\":[" + for i in $(seq 1 "$CONFIG_QEMU_NET_PORTS"); do + [ "$i" -gt 1 ] && echo -n ", " + echo -n "\"${sw}p${i}\"" + done + echo -n "]}' " + for i in $(seq 1 "$CONFIG_QEMU_NET_PORTS"); do + rocker_port_args 0 "$i" done elif [ "$CONFIG_QEMU_NET_USER" = "y" ]; then - local useropts= [ "$CONFIG_QEMU_NET_USER_OPTS" ] && useropts=",$CONFIG_QEMU_NET_USER_OPTS" - echo -n "-netdev user,id=e1${useropts} " net_dev_args 1 else @@ -301,8 +326,7 @@ run_qemu() fi fi - local qemu - read qemu < "$run" + if [ "$CONFIG_QEMU_KERNEL" ]; then + echo "$qemu -append \"$(append_args)\" $*" >> "$run" + else + echo "$qemu $*" >> "$run" + fi + chmod +x "$run" echo "Starting Qemu :: Ctrl-a x -- exit | Ctrl-a c -- toggle console/monitor" line=$(stty -g) stty raw - - if [ "$CONFIG_QEMU_KERNEL" ]; then - $qemu -append "$(append_args)" "$@" - else - $qemu "$@" - fi - + $run stty "$line" + if [ -n "$keep" ]; then + echo "Keeping generated qemu.run script: $run" + else + rm "$run" + fi } dtb_args() @@ -364,7 +398,7 @@ generate_dot() hostports=" qtap1" targetports=" e1" edges="host:qtap1 -- target:e1 [kind=mgmt];" - for tap in $(seq 2 $(($CONFIG_QEMU_NET_TAP_N - 1))); do + for tap in $(seq 2 $((CONFIG_QEMU_NET_TAP_N - 1))); do hostports="$hostports | qtap$tap " targetports="$targetports | e$tap " edges="$edges host:qtap$tap -- target:e$tap;" @@ -404,7 +438,8 @@ menuconfig() exec kconfig-mconf Config.in } -cd $(dirname $(readlink -f "$0")) +scriptdir=$(dirname "$(readlink -f "$0")") +cd "$scriptdir" || (echo "Failed cd to $scriptdir"; exit 1) while [ "$1" != "" ]; do case $1 in @@ -414,6 +449,9 @@ while [ "$1" != "" ]; do -h) usage ;; + -k) + keep=true + ;; *) break esac diff --git a/board/common/rootfs/etc/default/ospfd b/board/common/rootfs/etc/default/ospfd new file mode 100644 index 00000000..38021e3b --- /dev/null +++ b/board/common/rootfs/etc/default/ospfd @@ -0,0 +1,2 @@ +# --log-level debug +OSPFD_ARGS="-A 127.0.0.1 -u frr -g frr -f /etc/frr/ospfd.conf --log syslog" diff --git a/board/common/rootfs/etc/default/zebra b/board/common/rootfs/etc/default/zebra new file mode 100644 index 00000000..5ce4e34c --- /dev/null +++ b/board/common/rootfs/etc/default/zebra @@ -0,0 +1,2 @@ +# --log-level debug +ZEBRA_ARGS="-A 127.0.0.1 -u frr -g frr --log syslog " diff --git a/board/common/rootfs/usr/bin/pager b/board/common/rootfs/usr/bin/pager index d307f92b..d60c8137 100755 --- a/board/common/rootfs/usr/bin/pager +++ b/board/common/rootfs/usr/bin/pager @@ -10,4 +10,6 @@ # This is what leaves the contents of the output on screen. export LESS="-P %f (press h for help or q to quit)" +export LANG=en_US.UTF-8 + less -RISKd -FX "$@" diff --git a/board/common/rootfs/usr/share/udhcpc/default.script b/board/common/rootfs/usr/share/udhcpc/default.script index 1917e790..d5ec337c 100755 --- a/board/common/rootfs/usr/share/udhcpc/default.script +++ b/board/common/rootfs/usr/share/udhcpc/default.script @@ -50,7 +50,7 @@ set_dhcp_routes() # format: dest1/mask gw1 ... destn/mask gwn set -- $staticroutes while [ -n "$1" -a -n "$2" ]; do - log "adding route $1 via $2 dev $interface proto dhcp" + log "adding route $1 via $2 metric $metric tag 100" echo "ip route $1 $2 $metric tag 100" >> "$NEXT" shift 2 done @@ -115,7 +115,7 @@ case "$ACTION" in /usr/sbin/avahi-autoipd -c $interface && /usr/sbin/avahi-autoipd -k $interface fi - if /bin/ip addr add dev $interface $ip/$subnet $BROADCAST proto 5; then + if /bin/ip addr add dev $interface $ip/$subnet $BROADCAST proto dhcp; then echo "$ip" > "$IP_CACHE" fi if [ -n "$ipv6" ] ; then diff --git a/board/x86_64/linux_defconfig b/board/x86_64/linux_defconfig index 5af4113b..25fa755b 100644 --- a/board/x86_64/linux_defconfig +++ b/board/x86_64/linux_defconfig @@ -162,12 +162,14 @@ CONFIG_MPLS=y CONFIG_NET_MPLS_GSO=y CONFIG_MPLS_ROUTING=m CONFIG_MPLS_IPTUNNEL=m +CONFIG_NET_SWITCHDEV=y CONFIG_NET_PKTGEN=y # CONFIG_WIRELESS is not set CONFIG_NET_9P=y CONFIG_NET_9P_VIRTIO=y CONFIG_LWTUNNEL=y CONFIG_PCI=y +CONFIG_PCI_MSI=y CONFIG_UEVENT_HELPER=y CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" CONFIG_DEVTMPFS=y @@ -209,6 +211,7 @@ CONFIG_NET_VRF=y CONFIG_E1000=y CONFIG_NE2K_PCI=y CONFIG_8139CP=y +CONFIG_ROCKER=y # CONFIG_WLAN is not set CONFIG_INPUT_EVDEV=y CONFIG_SERIAL_8250=y diff --git a/package/skeleton-init-finit/skeleton/etc/finit.d/available/frr/ospfd.conf b/package/skeleton-init-finit/skeleton/etc/finit.d/available/frr/ospfd.conf index b7757581..e4652ff1 100644 --- a/package/skeleton-init-finit/skeleton/etc/finit.d/available/frr/ospfd.conf +++ b/package/skeleton-init-finit/skeleton/etc/finit.d/available/frr/ospfd.conf @@ -1 +1,2 @@ -service [2345] log:null ospfd -A 127.0.0.1 -u frr -g frr -f /etc/frr/ospfd.conf -- OSPF daemon +service env:-/etc/default/ospfd \ + [2345] ospfd $OSPFD_ARGS -- OSPF daemon diff --git a/package/skeleton-init-finit/skeleton/etc/finit.d/available/frr/zebra.conf b/package/skeleton-init-finit/skeleton/etc/finit.d/available/frr/zebra.conf index 85aa22fd..45d39484 100644 --- a/package/skeleton-init-finit/skeleton/etc/finit.d/available/frr/zebra.conf +++ b/package/skeleton-init-finit/skeleton/etc/finit.d/available/frr/zebra.conf @@ -1 +1,2 @@ -service [2345] pid:!/run/frr/zebra.pid zebra -A 127.0.0.1 -u frr -g frr -- Zebra routing daemon +service pid:!/run/frr/zebra.pid env:-/etc/default/zebra \ + [2345] zebra $ZEBRA_ARGS -- Zebra routing daemon