ifupdown resolved script has typo

Bug #2017840 reported by CH
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ifupdown (Ubuntu)
New
Undecided
Unassigned

Bug Description

This error happens when you try to run ifup or ifdown:

```
# ifdown enp3s0
/etc/network/if-down.d/resolved: 12: mystatedir: not found

# ifup enp3s0
/etc/network/if-up.d/resolved: 12: mystatedir: not found
```

Here's the first 12 lines of those scripts:
```
# head -n 12 /etc/network/if-up.d/resolved

#!/bin/sh
#
# Script fragment to make ifupdown supply DNS infromation to resolved
#

case "$ADDRFAM" in
    inet|inet6) : ;;
    *) exit 0 ;;
esac

if systemctl is-enabled systemd-resolved > /dev/null 2>&1; then
    mystatedir statedir ifindex interface
```

I'm thinking that the word `local` used to appear before `mystatedir` on line 12, but that was when it was a function. When it was converted back from being a function, the 'local' keyword was removed, but the variables remained.

Either make it into a function again, or delete line 12.

CH (pdragon99)
description: updated
CH (pdragon99)
description: updated
Revision history for this message
CH (pdragon99) wrote (last edit ):

There's another similar typo in the /etc/network/if-up.d/resolved script, on line 71:
```
    if ! cmp --silent "$oldstate" "$newstate" 2>/dev/null; then
        DNS DNS6 DOMAINS DOMAINS6 DEFAULT_ROUTE
        # v4 first
```
Comment it out, as it's not valid code.

Also, on lines 40-45, there's this:
```
    DNS=DNS
    DOMAINS=DOMAINS
    if [ "$ADDRFAM" = "inet6" ]; then
        DNS=DNS6
        DOMAINS=DOMAINS6
    fi
```
Which ends up writing this on lines 94-95:
```
SERVERS=$(echo $DNS6 $DNS)
DOMAINS=$(echo $DOMAINS6 $DOMAINS)
```
Generating this:
```
# cat /run/systemd/resolve/netif/3

# This is private data. Do not parse.
LLMNR=yes
MDNS=no
SERVERS=DNS
DOMAINS=DOMAINS
```
And ultimately ending up here:
```
# grep ^search /etc/resolv.conf

search example.org DOMAINS
```

Revision history for this message
CH (pdragon99) wrote (last edit ):

Oh, and when you run `ifup enp3s0` by hand, you get this error:
```
# ifup enp3s0

ifup: interface enp3s0 already configured

# ifdown enp3s0

# ifup enp3s0

mkdir: missing operand
Try 'mkdir --help' for more information.
```

It looks like this error is from line 26 of /etc/network/if-up.d/resolved:
```
    if [ ! "$ifindex" ]; then
        return
    fi
    # mystatedir=/run/network
    mkdir -p $mystatedir

    statedir=/run/systemd/resolve/netif
    mkdir -p $statedir
    chown systemd-resolve:systemd-resolve $statedir
```
Not sure why mystatedir is commented out, but it looks like that's what's wrong this time.

Revision history for this message
CH (pdragon99) wrote :

Whoops, found another bug:

```
# ifup enp2s0

/etc/network/if-up.d/resolved: 1: /run/network/ifupdown-inet-enp2s0: DNS=1.1.1.1: not found
/etc/network/if-up.d/resolved: 2: /run/network/ifupdown-inet-enp2s0: DOMAINS=example.org: not found
Failed to parse DNS server address: DNS
Failed to set DNS configuration: Invalid argument

# cat /run/network/ifupdown-inet-enp2s0

"DNS"="1.1.1.1"
"DOMAINS"="example.org"
```

And that comes from lines 47-51 of /etc/network/if-up.d/resolved:
```
    if [ -n "$NEW_DNS" ]; then
        cat <<EOF >"$mystatedir/ifupdown-${ADDRFAM}-$interface"
"$DNS"="$NEW_DNS"
EOF
        if [ -n "$NEW_DOMAINS" ]; then
            cat <<EOF >>"$mystatedir/ifupdown-${ADDRFAM}-$interface"
"$DOMAINS"="$NEW_DOMAINS"
EOF
```
Basically, the double-quotes around "$DNS" and "$DOMAINS" shouldn't be there, because it's a here-doc.

But this reveals another bug: the variable $DOMAINS is used to hold either "DOMAINS" or "DOMAINS6" in lines 41 or 44, but the actual search domains in line 95.

Has this code ever worked?

Revision history for this message
CH (pdragon99) wrote (last edit ):

My apologies, I neglected to specify these details:

OS: Ubuntu 22.04.2 LTS
Package: ifupdown
Version: 0.8.36+nmu1ubuntu3

It's the latest version of ifupdown for Ubuntu 22.04.2 LTS.

There's a 0.8.36+nmu1ubuntu4 version for later versions of Ubuntu.

affects: systemd (Ubuntu) → ifupdown (Ubuntu)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.