From 5bf19f8b5789476ce0cbee1ef587af42e5ce4003 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 12 Jan 2024 17:32:45 +0100 Subject: [PATCH] DEV: h2: add support for multiple flags in mkhdr The mkhdr script did not support passing multiple flags at once using symbolic names. That's now done. --- dev/h2/mkhdr.sh | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/dev/h2/mkhdr.sh b/dev/h2/mkhdr.sh index 05b497a2d2..c77eb3dd40 100755 --- a/dev/h2/mkhdr.sh +++ b/dev/h2/mkhdr.sh @@ -4,7 +4,7 @@ # All fields are optional. 0 assumed when absent. USAGE=\ -"Usage: %s [-l ] [-t ] [-f ] [-i ] [ -d ] +"Usage: %s [-l ] [-t ] [-f [,...]] [-i ] [ -d ] [ -e ]* [ -r raw ] [ -h | --help ] > hdr.bin Numbers are decimal or 0xhex. Not set=0. If is passed, it points to a file that is read and chunked into frames of bytes. -e @@ -53,7 +53,7 @@ mkframe() { local T="${2:-0}" local F="${3:-0}" local I="${4:-0}" - local t f + local t f f2 f3 # get the first match in this order for t in DATA:0x00 HEADERS:0x01 RST_STREAM:0x03 SETTINGS:0x04 PING:0x06 \ @@ -71,17 +71,37 @@ mkframe() { die fi - # get the first match in this order - for f in ES:0x01 EH:0x04 PAD:0x08 PRIO:0x20; do - if [ -z "${f##${F^^*}*}" ]; then - F="${f##*:}" + # get the first match in this order, for each entry delimited by ','. + # E.g.: "-f ES,EH" + f2=${F^^*}; F=0 + + while [ -n "$f2" ]; do + f3="${f2%%,*}" + tmp="" + for f in ES:0x01 EH:0x04 PAD:0x08 PRIO:0x20; do + if [ -n "$f3" -a -z "${f##${f3}*}" ]; then + tmp="${f#*:}" + break + fi + done + + if [ -n "$tmp" ]; then + F=$(( F | tmp )) + f2="${f2#$f3}" + f2="${f2#,}" + elif [ -z "${f3##[X0-9A-F]*}" ]; then + F=$(( F | f3 )) + f2="${f2#$f3}" + f2="${f2#,}" + else + echo "Unknown flag(s) '$f3'" >&2 + usage "${0##*}" + die fi done - if [ -n "${F##[0-9]*}" ]; then - echo "Unknown type '$T'" >&2 - usage "${0##*}" - die + if [ -n "$f2" ]; then + F="${f2} | ${F}" fi L=$(( L )); T=$(( T )); F=$(( F )); I=$(( I ))