Skip to content

Commit 39b4101

Browse files
committed
common: has-quirk: Add support for matching based on "ethtool -i"
In addition to matching on interface names, add support for matching on ethtool information. Example: { "@ethtool:driver=st_gmac": { "broken-mqprio": true } } This would mark any interface using the "st_gmac" driver as having a broken mqprio implementation. Whereas this: { "@ethtool:driver=st_gmac;bus-info:30bf0000.ethernet": { "broken-mqprio": true } } Only matches an st_gmac-backed interface at the specified location. As matching becomes more complicated, use the shell implementation from confd as well, to make sure that they are always in agreement.
1 parent 7c01919 commit 39b4101

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed
Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
3+
IFQUIRKSFILE=${IFQUIRKSFILE:-/etc/product/interface-quirks.json}
4+
25
if [ $# -lt 2 ]; then
36
echo "usage: $0 <quirk-name> <ifname>"
47
exit 1
58
fi
9+
610
quirk=$1
711
ifname=$2
8-
if [ -f "/etc/product/interface-quirks.json" ]; then
9-
echo "$(jq -r --arg iface "$ifname" --arg quirk "$quirk" '.[$iface][$quirk] // "false"' /etc/product/interface-quirks.json)"
10-
else
11-
echo "false"
12-
fi
12+
13+
[ -f "$IFQUIRKSFILE" ] || { echo false && exit; }
14+
15+
match()
16+
{
17+
jq -e \
18+
--arg quirk "$quirk" --arg pattern "$1" \
19+
'.[$pattern][$quirk]' "$IFQUIRKSFILE" >/dev/null || return
20+
21+
echo true
22+
exit 0
23+
}
24+
25+
ethtoolmatch()
26+
{
27+
local pattern="${1#@ethtool:}"
28+
29+
grep -qFxvf \
30+
<(ethtool -i "$ifname") \
31+
<(echo -n "$pattern" | awk -v FS="=" -v RS=";" '{ printf("%s: %s\n", $1, $2); }') \
32+
&& return
33+
34+
match "@ethtool:$pattern"
35+
}
36+
37+
38+
for pattern in $(jq -r 'keys[]' "$IFQUIRKSFILE"); do
39+
case "$pattern" in
40+
@ethtool:*)
41+
ethtoolmatch "$pattern"
42+
;;
43+
"$ifname")
44+
match "$ifname"
45+
;;
46+
esac
47+
done
48+
49+
echo "false"

src/confd/src/ietf-interfaces.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,8 @@
1717

1818
bool iface_has_quirk(const char *ifname, const char *quirkname)
1919
{
20-
struct json_t *iface, *quirk;
21-
22-
if (!confd.ifquirks)
23-
return false;
24-
25-
iface = json_object_get(confd.ifquirks, ifname);
26-
if (!iface)
27-
return false;
28-
29-
quirk = json_object_get(iface, quirkname);
30-
31-
return quirk ? json_is_true(quirk) : false;
20+
return systemf("[ $(/usr/libexec/infix/has-quirk %s %s) = true ]",
21+
quirkname, ifname) == 0;
3222
}
3323

3424
static bool iface_is_phys(const char *ifname)

0 commit comments

Comments
 (0)