From nobody Tue Dec 20 16:23:36 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Nc22065tcz1G3j5; Tue, 20 Dec 2022 16:23:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Nc2205WCBz3LMX; Tue, 20 Dec 2022 16:23:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671553416; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Rbj2lw/QhN3a5WQBNwZbx59tMn1sXltPJSpI/KthG5E=; b=bNcMq9GybxvYfFqztoBdMkrTHjAAUE5HbHXjJlEw3hBGnDTsn0R38ijK4JHEUQVooD0yIY qXEuCMbNXND68aIWWS2gEnFna4sHKEvJtAayaDP9G9RKjiQwV9RcQe9N0Bu5S0kodGVIlU DcKa7i7AaPy3LgM10tW9FQesspIVAnJjTwgtB3SgUyJa6AMH8e5fK9NSXErcnDpUSAzFd2 Cme3F6W/7dNkR5ZiiW9CRKy4iAjI6yrCbe7CkQ9jw1nGftdJYUTD2SODj2co7mpJTd+onk GRN235yOn7s3ym/liPxcf4fgU6tDnmbDcyRsW2voeJ04cHBFBcUKvm4dURff/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671553416; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Rbj2lw/QhN3a5WQBNwZbx59tMn1sXltPJSpI/KthG5E=; b=fCtEWbzwVl8fbNiG2vKIV83gLHn2RshYXWIOOfoZtNqChpJ8tDybUdafNBgUcESAowYQVy aHm0fv99qiswN11NcC81+HO8Ca9nJhjHB4LuIQLXbH6F/PVbQbGeQNJqxwa55UbyJyn2gc thkSLUGcZKgN19WvYharjZ7ySuqNGlWXqwZWi8GT55a/9L6TPhKs9p9wcBgo6HL3P4IUIB dDHe3bIR6XFkoGxFq2Qgm4bMsG3WGetFQlzQ+6s9InIeMRiB0NmaYY7fa0ectonOzfqjXe FGrA6UglQy+LgP1opeVsWnpsMGmtuaodBkThLMi4NxwwIJ8oovaVfZy9pqoNkQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671553416; a=rsa-sha256; cv=none; b=fc2H2+5MQMum/uKrT7FgEK2FRKYJbkdizd0HQsc2dcZEDyA90fwhSVIYedjvxGJB7ItmCu LdddxY/u6RVHqONhSvWTYh+NVsvC/XmmCsWd4U0QFqK7EfuT/RIKPlXQBKSGpeIrObYKe1 E4AMGlCk7fCM+sCjSXpI+ibXVw8wbnPxP/WBFUlJEAJSnRKqBsnnsXwoIpof/kcekAgSgr gTvyDwDRXoQKe9dQBvqWWPHH304vH0cwpW1jkfJSSyuLqYjJ1Svq1MlyEIlJIsm2vp9QIn dtlKpLYvpIBfK+KNRSTc3+YQOZIqzlV0t1R1c8M4rNFY4y6XvRPvZgC2DUoRMw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Nc2204ZQLzhRb; Tue, 20 Dec 2022 16:23:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2BKGNaG6020993; Tue, 20 Dec 2022 16:23:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BKGNaZi020992; Tue, 20 Dec 2022 16:23:36 GMT (envelope-from git) Date: Tue, 20 Dec 2022 16:23:36 GMT Message-Id: <202212201623.2BKGNaZi020992@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Justin Hibbits Subject: git: 177034c44ed1 - main - Update DrvAPI convert script for new KPIs List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhibbits X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 177034c44ed18d99e6cc85dfddd2bb04b41d38ac Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=177034c44ed18d99e6cc85dfddd2bb04b41d38ac commit 177034c44ed18d99e6cc85dfddd2bb04b41d38ac Author: Justin Hibbits AuthorDate: 2022-08-17 20:13:58 +0000 Commit: Justin Hibbits CommitDate: 2022-12-20 16:18:50 +0000 Update DrvAPI convert script for new KPIs Bring the DrvAPI convert script forward from the initial commit to account for the last 8 years of changes to the KPIs. Sponsored by: Juniper Networks, Inc. --- tools/ifnet/convert_drvapi.sh | 242 +++++++++++++++++++----------------------- 1 file changed, 110 insertions(+), 132 deletions(-) diff --git a/tools/ifnet/convert_drvapi.sh b/tools/ifnet/convert_drvapi.sh index dd30c7a229e0..228456dd244d 100755 --- a/tools/ifnet/convert_drvapi.sh +++ b/tools/ifnet/convert_drvapi.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2014 Juniper Networks, Inc. +# Copyright (c) 2014, 2019, 2020 Juniper Networks, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -35,6 +35,8 @@ # Author: Sreekanth Rupavatharam # +MAX_PASSES=100 + if [ $# -lt 1 ] then echo " $0 "; @@ -47,40 +49,24 @@ __ifp__="ifp"; file=$1 rotateCursor() { - case $toggle - in - 1) - printf " \\ " - printf "\b\b" - toggle="2" - ;; - - 2) - printf " | " - printf "\b\b\b" - toggle="3" - ;; - - 3) - printf " / " - printf "\b\b\b" - toggle="4" - ;; - - *) - printf " - " - printf "\b\b\b" - toggle="1" - ;; - esac + case $toggle in + 1) c="\\" ;; + 2) c="|" ;; + 3) c="/" ;; + *) c="-" ;; + esac + toggle=$(((toggle + 1) % 4)) + printf " %s \b\b\b" $c } -handle_set() { # Handle the case where $__ifp__->if_blah = XX; - line=$1 - set=`echo $line| grep "$__ifp__->.* = "` - if [ ! -z "$set" ] +handle_set() { + if echo $line | grep "$__ifp__->.* = " > /dev/null 2>&1 then + if echo $line | grep "\[$__ifp__->.* = " > /dev/null 2>&1; then + # Special case of array[ifp->member] = value + return 1 + fi word=`echo $line | awk -F "if_" ' { print $2 }' | awk -F" =" '{ print $1 }'` value=`echo $line | awk -F "=" '{ print $2 }' | sed -e 's/;//g'` new=`echo if_set$word"\($__ifp__,"$value");"` @@ -93,9 +79,7 @@ handle_set() { } handle_inc() { - line=$1 - inc=`echo $line | grep "$__ifp__->.*++\|++$__ifp__->.*"` - if [ ! -z "$inc" ] + if echo $line | grep "$__ifp__->.*++\|++$__ifp__->.*" > /dev/null 2>&1 then word=`echo $line | awk -F"if_" '{ print $2 }'|awk -F"\+" '{ print $1}'` value=' 1'; @@ -104,14 +88,12 @@ handle_inc() { new=`echo $new | sed -e 's/&/\\\&/'` line=`echo $line| sed -e's/'$old'/'$new'/g'` return 0; - fi + fi return 1; } handle_add() { - line=$1 - add=`echo $line|grep "$__ifp__->.*+= "` - if [ ! -z "$add" ] + if echo $line | grep "$__ifp__->.*+= " > /dev/null 2>&1 then word=`echo $line | awk -F"if_" '{ print $2 }'|awk '{ print $1}'` value=`echo $line | awk -F"=" '{ print $2}' | sed -e 's/;//g'` @@ -126,14 +108,12 @@ handle_add() { } handle_or() { - line=$1 - or=`echo $line|grep "$__ifp__->.*|= "` - if [ ! -z "$or" ] + if echo $line | grep "$__ifp__->.*|= " > /dev/null 2>&1 then - word=`echo $line | awk -F"if_" '{ print $2 }'|awk '{ print $1}'` + word=`echo $line | awk -F"if_" '{ print $2 }'|awk '{ print $1}'` value=`echo $line | awk -F"=" '{ print $2}' | sed -e 's/;//g'` new=`echo if_set${word}bit"($__ifp__,$value, 0);"` - new=`echo $new | sed -e 's/&/\\\&/'` + new=`echo $new | sed -e 's/&/\\\&/'` #line=`echo $line|sed -e 's/&/\\&/'` old=`echo $line|sed -e 's/^[ ]*//'` line=`echo $line| sed -e's/'$old'/'$new'/g'` @@ -144,11 +124,9 @@ handle_or() { } handle_and() { - line=$1 - or=`echo $line|grep "$__ifp__->.*&= "` - if [ ! -z "$or" ] + if echo $line |grep "$__ifp__->.*&= " > /dev/null 2>&1 then - word=`echo $line | awk -F"if_" '{ print $2 }'|awk '{ print $1}'` + word=`echo $line | awk -F"if_" '{ print $2 }'|awk '{ print $1}'` value=`echo $line | awk -F"=" '{ print $2}' | sed -e 's/;//g'` value=`echo $value | sed -e's/~//g'` new=`echo if_set${word}bit"\($__ifp__, 0,$value);"` @@ -162,8 +140,7 @@ handle_and() { } handle_toggle() { - line=$1 - if [ ! -z `echo $line | grep "\^="` ] + if echo $line | grep "\^=" > /dev/null 2>&1 then line=`echo $line | sed -e 's/'"$__ifp__"'->if_\(.*\) ^=\(.*\);/if_toggle\1('"$__ifp__"',\2);/g'` return 0; @@ -174,9 +151,7 @@ handle_toggle() { # XXX - this needs updating handle_misc() { - line=$1 - get=`echo $line | grep "if_capabilities\|if_flags\|if_softc\|if_capenable\|if_mtu\|if_drv_flags"` - if [ ! -z "$get" ] + if echo $line | grep "$__ifp__->\(if_capabilities\|if_flags\|if_softc\|if_capenable\|if_hwassist\|if_mtu\|if_drv_flags\|if_index\|if_alloctype\|if_dname\|if_xname\|if_addr\|if_hw_tsomax\|if_hw_tsomaxsegcount\|if_hw_tsomaxsegsize\)" > /dev/null 2>&1 then word=`echo $line |awk -F"$__ifp__->if_" '{ print $2 }' | \ sed -e's/[^a-zA-Z0-9_]/\@/'|awk -F"\@" '{ print $1}'` @@ -192,31 +167,66 @@ handle_misc() { replace_str () { - line=$1 - orig=$2 - new=$3 - line=`echo $line | sed -e 's/'"$orig"'\(.*\)/'"$new"'\1/g'` - return 0; + orig=$1 + new=$2 + + if echo $line | grep "$orig" > /dev/null 2>&1 + then + line=`echo $line | sed -e "s|$orig|$new|"` + else + return 1 + fi } -# Handle special cases which do not fall under regular patterns handle_special () { - line=$1 - replace_str $line "(\*$__ifp__->if_input)" "if_input" - replace_str $line "if_setinit" "if_setinitfn" - replace_str $line "if_setioctl" "if_setioctlfn" - replace_str $line "if_getdrv_flags" "if_getdrvflags" - replace_str $line "if_setdrv_flagsbit" "if_setdrvflagbits" - replace_str $line "if_setstart" "if_setstartfn" - replace_str $line "if_sethwassistbit" "if_sethwassistbits" - replace_str $line "ifmedia_init" "ifmedia_init_drv" - replace_str $line "IFQ_DRV_IS_EMPTY(&$__ifp__->if_snd)" "if_sendq_empty($__ifp__)" - replace_str $line "IFQ_DRV_PREPEND(&$__ifp__->if_snd" "if_sendq_prepend($__ifp__" - replace_str $line "IFQ_SET_READY(&ifp->if_snd)" "if_setsendqready($__ifp__)" - line=`echo $line | sed -e 's/IFQ_SET_MAXLEN(&'$__ifp__'->if_snd, \(.*\))/if_setsendqlen('$__ifp__', \1)/g'` - line=`echo $line | sed -e 's/IFQ_DRV_DEQUEUE(&'$__ifp__'->if_snd, \(.*\))/\1 = if_dequeue('$__ifp__')/g'` - return 0 + replace_str "(\*$__ifp__->if_input)" "if_input" || \ + replace_str "IFQ_DRV_IS_EMPTY(&$__ifp__->if_snd)" \ + "if_sendq_empty($__ifp__)" || \ + replace_str "IFQ_DRV_PREPEND(&$__ifp__->if_snd" \ + "if_sendq_prepend($__ifp__" || \ + replace_str "IFQ_SET_READY(&$__ifp__->if_snd)" \ + "if_setsendqready($__ifp__)" || \ + replace_str "VLAN_CAPABILITIES($__ifp__)" \ + "if_vlancap($__ifp__)" || \ + replace_str "IFQ_SET_MAXLEN(&$__ifp__->if_snd," \ + "if_setsendqlen($__ifp__," || \ + replace_str "IFQ_DRV_DEQUEUE(&$__ifp__->if_snd, \(.*\))" \ + "\1 = if_dequeue($__ifp__)" + replace_str "$__ifp__->if_vlantrunk != NULL" \ + "if_vlantrunkinuse($__ifp__)" +} + +handle_ifps() { + handle_set || handle_inc || handle_add || handle_or || handle_and || \ + handle_toggle || handle_misc || handle_special +} + +handle_renames () +{ + replace_str "if_setinit(" "if_setinitfn(" || \ + replace_str "if_setioctl(" "if_setioctlfn(" || \ + replace_str "if_setqflush(" "if_setqflushfn(" || \ + replace_str "if_settransmit(" "if_settransmitfn(" || \ + replace_str "if_getdrv_flags(" "if_getdrvflags(" || \ + replace_str "if_setdrv_flagsbit(" "if_setdrvflagbits(" || \ + replace_str "if_setstart(" "if_setstartfn(" || \ + replace_str "if_sethwassistbit(" "if_sethwassistbits(" || \ + replace_str "ifmedia_init(" "ifmedia_init_drv(" +} + +check_ifp() +{ + case "$line" in + *"${__ifp__}->"*) return 0;; # Still an ifp to convert + esac + return 1 +} + +add_failed () +{ + line="$line /* ${FAIL_PAT} */" + return 1 } if [ -e $file.tmp ] @@ -227,69 +237,37 @@ IFS= echo -n "Conversion for $file started, please wait: " FAIL_PAT="XXX - DRVAPI" count=0 -cat $1 | while read -r line +while read -r line do -count=`expr $count + 1` -rotateCursor -pat=`echo $line | grep "$__ifp__->"` -while [ "$pat" != "" ] -do - pat=`echo $line | grep "$__ifp__->"` - if [ ! -z `echo $pat | grep "$FAIL_PAT"` ] - then - break; - fi + rotateCursor - handle_set $line + # There is an ifp, we need to process it + passes=0 + while check_ifp + do + if handle_ifps + then + handle_renames + else + add_failed + break + fi + passes=$((passes + 1)) + if [ $passes -ge $MAX_PASSES ]; then + add_failed + break + fi + done - if [ $? != 0 ] - then - handle_inc $line - fi - - if [ $? != 0 ] - then - handle_add $line - fi - - if [ $? != 0 ] - then - handle_or $line - fi - - if [ $? != 0 ] - then - handle_and $line - fi - - if [ $? != 0 ] - then - handle_toggle $line - fi - - if [ $? != 0 ] - then - handle_misc $line - fi - - if [ $? != 0 ] - then - handle_special $line - fi - - if [ ! -z `echo $line | grep "$__ifp__->"` ] - then - line=`echo $line | sed -e 's:$: \/* '${FAIL_PAT}' *\/:g'` - fi -done - line=`echo "$line" | sed -e 's:VLAN_CAPABILITIES('$__ifp__'):if_vlancap('$__ifp__'):g'` # Replace the ifnet * with if_t - if [ ! -z `echo $line | grep "struct ifnet"` ] - then - line=`echo $line | sed -e 's/struct ifnet[ \t]*\*/if_t /g'` - fi - echo "$line" >> $file.tmp -done + case "$line" in + *"struct ifnet"*) + line=`echo $line | sed -e 's/struct ifnet[ \t]*\*/if_t /g'` ;; + *"IF_LLADDR("*) + line=`echo $line | sed -e 's/IF_LLADDR(/if_getlladdr(/g'` ;; + esac + printf "%s\n" "$line" >> $file.tmp +done < $1 echo "" count=`grep $FAIL_PAT $file.tmp | wc -l` if [ $count -gt 0 ]