Debian Codegraph @

debian/resolved

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 ## Sourced, not exec'ed, but helps syntax highlighting
3 #
4 # Script fragment to make dhclient supply nameserver information to resolved
5 #
6
7 # Tips:
8 # * Be careful about changing the environment since this is sourced
9 # * This script fragment uses bash features
10 # * As of isc-dhcp-client 4.2 the "reason" (for running the script) can be one of the following.
11 # (Listed on man page:) MEDIUM(0) PREINIT(0) BOUND(M) RENEW(M) REBIND(M) REBOOT(M) EXPIRE(D) FAIL(D) RELEASE(D) STOP(D) NBI(-) TIMEOUT(M)
12 # (Also used in master script:) ARPCHECK(0), ARPSEND(0)
13 # (Also used in master script:) PREINIT6(0) BOUND6(M) RENEW6(M) REBIND6(M) DEPREF6(0) EXPIRE6(D) RELEASE6(D) STOP6(D)
14 # (0) = master script does not run make_resolv_conf
15 # (M) = master script runs make_resolv_conf
16 # (D) = master script downs interface
17 # (-) = master script does nothing with this
18
19 if systemctl is-enabled systemd-resolved > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then
20 local mystatedir statedir ifindex
21
22 if [scip-shell system . . `[`. ! "$interface" ] ; then
23 return
24 fi
25 ifindex=$(catscip-shell system . . cat. "/sys/class/net/$interface/ifindex")
26 if [scip-shell system . . `[`. ! "$ifindex" ]; then
27 return
28 fi
29 mystatedir=/run/networkscip-shell filesystem . . `/run/network`.
30 mkdirscip-shell system . . mkdir. -p $mystatedir
31
32 statedir=/run/systemd/resolve/netifscip-shell filesystem . . `/run/systemd/resolve/netif`.
33 mkdirscip-shell system . . mkdir. -p $statedir
34 chownscip-shell system . . chown. systemd-resolve:systemd-resolve $statedir
35
36 local oldstate="$(mktempscip-shell system . . mktemp.)"
37 # ignore errors due to nonexistent file
38 md5sumscip-shell system . . md5sum. "$mystatedir/isc-dhcp-v4-$interface" "$mystatedir/isc-dhcp-v6-$interface" "$mystatedir/ifupdown-inet-$interface" "$mystatedir/ifupdown-inet6-$interface" > "$oldstate" 2> /dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
39
40 case "$reason" in
41 BOUND|RENEW|REBIND|REBOOT|TIMEOUT|BOUND6|RENEW6|REBIND6)
42 if [scip-shell system . . `[`. -n "$new_domain_name_servers" ] ; then
43 catscip-shell system . . cat. <<EOF >"$mystatedir/isc-dhcp-v4-$interface"
44 DNS="$new_domain_name_servers"
45 EOF
46 if [scip-shell system . . `[`. -n "$new_domain_name" ] || [scip-shell system . . `[`. -n "$new_domain_search" ] ; then
47 catscip-shell system . . cat. <<EOF >>"$mystatedir/isc-dhcp-v4-$interface"
48 DOMAINS="$new_domain_search $new_domain_name"
49 EOF
50 fi
51 fi
52 if [scip-shell system . . `[`. -n "$new_dhcp6_name_servers" ] ; then
53 catscip-shell system . . cat. <<EOF >"$mystatedir/isc-dhcp-v6-$interface"
54 DNS6="$new_dhcp6_name_servers"
55 EOF
56 if [scip-shell system . . `[`. -n "$new_dhcp6_domain_search" ] ; then
57 catscip-shell system . . cat. <<EOF >>"$mystatedir/isc-dhcp-v6-$interface"
58 DOMAINS6="$new_dhcp6_domain_search"
59 EOF
60 fi
61 fi
62 ;;
63
64 EXPIRE|FAIL|RELEASE|STOP)
65 rmscip-shell system . . rm. -f "/run/network/isc-dhcp-v4-$interface"
66 ;;
67 EXPIRE6|RELEASE6|STOP6)
68 rmscip-shell system . . rm. -f "/run/network/isc-dhcp-v6-$interface"
69 ;;
70 esac
71
72 local newstate="$(mktempscip-shell system . . mktemp.)"
73 # ignore errors due to nonexistent file
74 md5sumscip-shell system . . md5sum. "$mystatedir/isc-dhcp-v4-$interface" "$mystatedir/isc-dhcp-v6-$interface" "$mystatedir/ifupdown-inet-$interface" "$mystatedir/ifupdown-inet6-$interface" > "$newstate" 2> /dev/nullscip-shell filesystem . . `/dev/null`. || truescip-shell system . . true.
75 if ! cmpscip-shell system . . cmp. --silent "$oldstate" "$newstate" 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
76 local DNS DNS6 DOMAINS DOMAINS6 DEFAULT_ROUTE
77 # v4 first
78 if [scip-shell system . . `[`. -e "$mystatedir/isc-dhcp-v4-$interface" ]; then
79 . "$mystatedir/isc-dhcp-v4-$interface"
80 fi
81 # v4 manual config overrides
82 if [scip-shell system . . `[`. -e "$mystatedir/ifupdown-inet-$interface" ]; then
83 . "$mystatedir/ifupdown-inet-$interface"
84 fi
85 # v6 preffered
86 if [scip-shell system . . `[`. -e "$mystatedir/isc-dhcp-v6-$interface" ]; then
87 . "$mystatedir/isc-dhcp-v6-$interface"
88 fi
89 # v6 manual config overrides
90 if [scip-shell system . . `[`. -e "$mystatedir/ifupdown-inet6-$interface" ]; then
91 . "$mystatedir/ifupdown-inet6-$interface"
92 fi
93 local resolvectl_failed=
94 if [scip-shell system . . `[`. "$DNS" ] || [scip-shell system . . `[`. "$DNS6" ] ; then
95 catscip-shell system . . cat. <<EOF >"$statedir/$ifindex"
96 # This is private data. Do not parse.
97 LLMNR=yes
98 MDNS=no
99 SERVERS=$(echoscip-shell system . . echo. $DNS6 $DNS)
100 DOMAINS=$(echoscip-shell system . . echo. $DOMAINS6 $DOMAINS)
101 EOF
102 if [scip-shell system . . `[`. -n "$DEFAULT_ROUTE" ]; then
103 catscip-shell system . . cat. <<EOF >>"$statedir/$ifindex"
104 DEFAULT_ROUTE=$DEFAULT_ROUTE
105 EOF
106 fi
107 chownscip-shell system . . chown. systemd-resolve:systemd-resolve "$statedir/$ifindex"
108 # In addition to creating the state file (needed if we run before
109 # resolved is started), also feed the information directly to
110 # resolved.
111 if systemctl --quiet is-active systemd-resolved; then
112 resolvectl llmnr "$ifindex" yes || resolvectl_failed=$?
113 resolvectl mdns "$ifindex" no || resolvectl_failed=$?
114 if [scip-shell system . . `[`. "$DOMAINS6" ] || [scip-shell system . . `[`. "$DOMAINS" ]; then
115 resolvectl domain "$ifindex" $DOMAINS6 $DOMAINS || resolvectl_failed=$?
116 else
117 resolvectl domain "$ifindex" "" || resolvectl_failed=$?
118 fi
119 resolvectl dns "$ifindex" $DNS6 $DNS || resolvectl_failed=$?
120 if [scip-shell system . . `[`. "$DEFAULT_ROUTE" ]; then
121 resolvectl default-route "$ifindex" $DEFAULT_ROUTE || resolvectl_failed=$?
122 fi
123 fi
124 else
125 rmscip-shell system . . rm. -f "$statedir/$ifindex"
126 if systemctl --quiet is-active systemd-resolved; then
127 resolvectl revert "$ifindex" || resolvectl_failed=$?
128 fi
129 fi
130
131 # resolved was running, but without dbus, it means state files
132 # will not be read & resolvectl commands failed, restart it
133 if [scip-shell system . . `[`. "$resolvectl_failed" ]; then
134 systemctl try-restart systemd-resolved
135 fi
136 fi
137 rmscip-shell system . . rm. -f "$oldstate" "$newstate"
138 fi