| 1 |
<?xml version='1.0'?> |
| 2 |
<?xml-stylesheet type="text/xsl" href="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl"?> |
| 3 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 4 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ |
| 5 |
<!ENTITY % entities SYSTEM "common.ent" > |
| 6 |
%entities; |
| 7 |
]> |
| 8 |
|
| 9 |
<!-- |
| 10 |
SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later |
| 11 |
|
| 12 |
NetworkManager-dispatcher(8) manual page |
| 13 |
|
| 14 |
Copyright 2005 - 2016 Red Hat, Inc. |
| 15 |
Copyright 2005 - 2009 Novell, Inc. |
| 16 |
Copyright 2005 Robert Love |
| 17 |
--> |
| 18 |
|
| 19 |
<refentry id="NetworkManager-dispatcher"> |
| 20 |
<refentryinfo> |
| 21 |
<title>NetworkManager-dispatcher</title> |
| 22 |
<author>NetworkManager developers</author> |
| 23 |
</refentryinfo> |
| 24 |
<refmeta> |
| 25 |
<refentrytitle>NetworkManager-dispatcher</refentrytitle> |
| 26 |
<manvolnum>8</manvolnum> |
| 27 |
<refmiscinfo class="source">NetworkManager-dispatcher</refmiscinfo> |
| 28 |
<refmiscinfo class="manual">Network management daemons</refmiscinfo> |
| 29 |
<refmiscinfo class="version">&NM_VERSION;</refmiscinfo> |
| 30 |
</refmeta> |
| 31 |
|
| 32 |
<refnamediv> |
| 33 |
<refname>NetworkManager-dispatcher</refname> |
| 34 |
<refpurpose>Dispatch user scripts for NetworkManager</refpurpose> |
| 35 |
</refnamediv> |
| 36 |
|
| 37 |
<refsynopsisdiv> |
| 38 |
<cmdsynopsis> |
| 39 |
<command>NetworkManager <arg choice="opt" rep="repeat">OPTIONS</arg></command> |
| 40 |
</cmdsynopsis> |
| 41 |
</refsynopsisdiv> |
| 42 |
|
| 43 |
<refsect1> |
| 44 |
<title>Description</title> |
| 45 |
<para> |
| 46 |
NetworkManager-dispatcher service is a D-Bus activated service that |
| 47 |
runs user provided scripts upon certain changes in NetworkManager. |
| 48 |
</para> |
| 49 |
<para> |
| 50 |
NetworkManager-dispatcher will execute scripts in the |
| 51 |
<filename>/{etc,usr/lib}/NetworkManager/dispatcher.d</filename> |
| 52 |
directory or subdirectories in |
| 53 |
alphabetical order in response to network events. Files in <filename>/etc</filename> |
| 54 |
take precedence over identically-named files in <filename>/usr/lib</filename>. |
| 55 |
Each script should be a regular executable file owned by root. Furthermore, it must |
| 56 |
not be writable by group or other, and not setuid. |
| 57 |
</para> |
| 58 |
<para> |
| 59 |
Each script receives two arguments, the first being the interface name of the |
| 60 |
device an operation just happened on, and second the action. For device actions, |
| 61 |
the interface is the name of the kernel interface suitable for IP configuration. |
| 62 |
Thus it is either VPN_IP_IFACE, DEVICE_IP_IFACE, or DEVICE_IFACE, as applicable. |
| 63 |
For the <varname>hostname</varname> action the device name is always |
| 64 |
<literal>"none"</literal>. For <varname>connectivity-change</varname> and |
| 65 |
<varname>dns-change</varname> it is empty. |
| 66 |
</para> |
| 67 |
<para>The actions are:</para> |
| 68 |
<variablelist class="dispatcher-options"> |
| 69 |
<varlistentry> |
| 70 |
<term><varname>pre-up</varname></term> |
| 71 |
<listitem><para>The interface is connected to the network but is not |
| 72 |
yet fully activated. Scripts acting on this event must be placed or |
| 73 |
symlinked into the <filename>/etc/NetworkManager/dispatcher.d/pre-up.d</filename> |
| 74 |
directory, and NetworkManager will wait for script execution to complete before |
| 75 |
indicating to applications that the interface is fully activated. |
| 76 |
</para></listitem> |
| 77 |
</varlistentry> |
| 78 |
<varlistentry> |
| 79 |
<term><varname>up</varname></term> |
| 80 |
<listitem><para>The interface has been activated.</para></listitem> |
| 81 |
</varlistentry> |
| 82 |
<varlistentry> |
| 83 |
<term><varname>pre-down</varname></term> |
| 84 |
<listitem><para>The interface will be deactivated but has not yet been |
| 85 |
disconnected from the network. Scripts acting on this event must be |
| 86 |
placed or symlinked into the <filename>/etc/NetworkManager/dispatcher.d/pre-down.d</filename> |
| 87 |
directory, and NetworkManager will wait for script execution to complete |
| 88 |
before disconnecting the interface from its network. Note that this |
| 89 |
event is not emitted for forced disconnections, like when carrier is |
| 90 |
lost or a wireless signal fades. It is only emitted when there is |
| 91 |
an opportunity to cleanly handle a network disconnection event. |
| 92 |
</para></listitem> |
| 93 |
</varlistentry> |
| 94 |
<varlistentry> |
| 95 |
<term><varname>down</varname></term> |
| 96 |
<listitem><para> |
| 97 |
The interface has been deactivated. |
| 98 |
</para></listitem> |
| 99 |
</varlistentry> |
| 100 |
<varlistentry> |
| 101 |
<term><varname>vpn-pre-up</varname></term> |
| 102 |
<listitem><para>The VPN is connected to the network but is not yet |
| 103 |
fully activated. Scripts acting on this event must be placed or |
| 104 |
symlinked into the <filename>/etc/NetworkManager/dispatcher.d/pre-up.d</filename> |
| 105 |
directory, and NetworkManager will wait for script execution to complete before |
| 106 |
indicating to applications that the VPN is fully activated. |
| 107 |
</para></listitem> |
| 108 |
</varlistentry> |
| 109 |
<varlistentry> |
| 110 |
<term><varname>vpn-up</varname></term> |
| 111 |
<listitem><para> |
| 112 |
A VPN connection has been activated. |
| 113 |
</para></listitem> |
| 114 |
</varlistentry> |
| 115 |
<varlistentry> |
| 116 |
<term><varname>vpn-pre-down</varname></term> |
| 117 |
<listitem><para>The VPN will be deactivated but has not yet been |
| 118 |
disconnected from the network. Scripts acting on this event must be |
| 119 |
placed or symlinked into the <filename>/etc/NetworkManager/dispatcher.d/pre-down.d</filename> |
| 120 |
directory, and NetworkManager will wait for script execution to complete |
| 121 |
before disconnecting the VPN from its network. Note that this |
| 122 |
event is not emitted for forced disconnections, like when the VPN |
| 123 |
terminates unexpectedly or general connectivity is lost. It is only |
| 124 |
emitted when there is an opportunity to cleanly handle a VPN |
| 125 |
disconnection event. |
| 126 |
</para></listitem> |
| 127 |
</varlistentry> |
| 128 |
<varlistentry> |
| 129 |
<term><varname>vpn-down</varname></term> |
| 130 |
<listitem><para> |
| 131 |
A VPN connection has been deactivated. |
| 132 |
</para></listitem> |
| 133 |
</varlistentry> |
| 134 |
<varlistentry> |
| 135 |
<term><varname>hostname</varname></term> |
| 136 |
<listitem><para> |
| 137 |
The system hostname has been updated. Use gethostname(2) to retrieve it. |
| 138 |
The interface name (first argument) is empty and no environment variable is |
| 139 |
set for this action. |
| 140 |
</para></listitem> |
| 141 |
</varlistentry> |
| 142 |
<varlistentry> |
| 143 |
<term><varname>dhcp4-change</varname></term> |
| 144 |
<listitem><para> |
| 145 |
The DHCPv4 lease has changed (renewed, rebound, etc). |
| 146 |
</para></listitem> |
| 147 |
</varlistentry> |
| 148 |
<varlistentry> |
| 149 |
<term><varname>dhcp6-change</varname></term> |
| 150 |
<listitem><para> |
| 151 |
The DHCPv6 lease has changed (renewed, rebound, etc). |
| 152 |
</para></listitem> |
| 153 |
</varlistentry> |
| 154 |
<varlistentry> |
| 155 |
<term><varname>connectivity-change</varname></term> |
| 156 |
<listitem><para> |
| 157 |
The network connectivity state has changed (no connectivity, went online, etc). |
| 158 |
</para></listitem> |
| 159 |
</varlistentry> |
| 160 |
<varlistentry> |
| 161 |
<term><varname>reapply</varname></term> |
| 162 |
<listitem><para> |
| 163 |
The connection was reapplied on the device. |
| 164 |
</para></listitem> |
| 165 |
</varlistentry> |
| 166 |
<varlistentry> |
| 167 |
<term><varname>dns-change</varname></term> |
| 168 |
<listitem><para> |
| 169 |
The DNS configuration has changed. This action is raised even if |
| 170 |
NetworkManager is configured to not manage resolv.conf (for example, |
| 171 |
via dns=none). In such case, the dispatch script can discover the |
| 172 |
DNS configuration provided by currently active connections by |
| 173 |
looking at file <filename>/run/NetworkManager/resolv.conf</filename> |
| 174 |
</para></listitem> |
| 175 |
</varlistentry> |
| 176 |
<varlistentry> |
| 177 |
<term><varname>device-add</varname></term> |
| 178 |
<listitem> |
| 179 |
<para> |
| 180 |
This action is called when a connection of type <literal>generic</literal> |
| 181 |
has the <literal>generic.device-handler</literal> property set. The property |
| 182 |
indicates the name of a dispatcher script to be executed in directory |
| 183 |
<filename>/{etc,usr/lib}/NetworkManager/dispatcher.d/device</filename>. Note |
| 184 |
that differently from other actions, only one script is executed. |
| 185 |
</para> |
| 186 |
<para> |
| 187 |
The script needs to perform any action needed to create the device |
| 188 |
for the generic connection. On successful termination, the script |
| 189 |
returns zero. Otherwise, it returns a non-zero value to indicate an |
| 190 |
error. The script can return values to NetworkManager by writing to |
| 191 |
standard output; each line should contain a key name followed by the |
| 192 |
equal sign '=' and a key value. The keys understood at the moment |
| 193 |
are: |
| 194 |
<variablelist> |
| 195 |
<varlistentry> |
| 196 |
<term><varname>IFINDEX</varname></term> |
| 197 |
<listitem><para> Indicates the interface index of the interface |
| 198 |
created by the script. This key is required when the script |
| 199 |
succeeds; if it is not set, the activation will fail. The key is |
| 200 |
ignored in case of script failure. </para></listitem> |
| 201 |
</varlistentry> |
| 202 |
<varlistentry> |
| 203 |
<term><varname>ERROR</varname></term> |
| 204 |
<listitem><para> Specifies an error message indicating the cause |
| 205 |
of the script failure. It is ignored when the script succeeds. |
| 206 |
</para></listitem> |
| 207 |
</varlistentry> |
| 208 |
</variablelist> |
| 209 |
Since the dispatcher service captures stdout for parsing those keys, |
| 210 |
anything written to stdout will not appear in the dispatcher service |
| 211 |
journal log. Use stderr if you want to print messages to the journal |
| 212 |
(for example, for debugging). Only the first 8KiB of stdout are |
| 213 |
considered and among those, only the first 64 lines; the rest is |
| 214 |
ignored. |
| 215 |
</para> |
| 216 |
</listitem> |
| 217 |
</varlistentry> |
| 218 |
<varlistentry> |
| 219 |
<term><varname>device-delete</varname></term> |
| 220 |
<listitem> |
| 221 |
<para> |
| 222 |
This action is the counterpart of <literal>device-add</literal> and |
| 223 |
is called to delete the device for a generic connection. All the |
| 224 |
aspects described for <literal>device-add</literal> also apply to |
| 225 |
this action, with the only exception that key |
| 226 |
<varname>IFINDEX</varname> is ignored. It is not necessary to delete |
| 227 |
the kernel link in the handler because NetworkManager already does |
| 228 |
that; therefore the action is useful for any additional cleanup |
| 229 |
needed. |
| 230 |
</para> |
| 231 |
</listitem> |
| 232 |
</varlistentry> |
| 233 |
</variablelist> |
| 234 |
<para> |
| 235 |
The environment contains more information about the interface and the connection. |
| 236 |
The following variables are available for the use in the dispatcher scripts: |
| 237 |
<variablelist class="dispatcher-environment"> |
| 238 |
<varlistentry> |
| 239 |
<term><varname>NM_DISPATCHER_ACTION</varname></term> |
| 240 |
<listitem><para> |
| 241 |
The dispatcher action like "up" or "dhcp4-change", identical to the first |
| 242 |
command line argument. Since NetworkManager 1.12.0. |
| 243 |
</para></listitem> |
| 244 |
</varlistentry> |
| 245 |
<varlistentry> |
| 246 |
<term><varname>CONNECTION_UUID</varname></term> |
| 247 |
<listitem><para> |
| 248 |
The UUID of the connection profile. |
| 249 |
</para></listitem> |
| 250 |
</varlistentry> |
| 251 |
<varlistentry> |
| 252 |
<term><varname>CONNECTION_ID</varname></term> |
| 253 |
<listitem><para> |
| 254 |
The name (ID) of the connection profile. |
| 255 |
</para></listitem> |
| 256 |
</varlistentry> |
| 257 |
<varlistentry> |
| 258 |
<term><varname>CONNECTION_DBUS_PATH</varname></term> |
| 259 |
<listitem><para> |
| 260 |
The NetworkManager D-Bus path of the connection. |
| 261 |
</para></listitem> |
| 262 |
</varlistentry> |
| 263 |
<varlistentry> |
| 264 |
<term><varname>CONNECTION_FILENAME</varname></term> |
| 265 |
<listitem><para> |
| 266 |
The backing file name of the connection profile (if any). |
| 267 |
</para></listitem> |
| 268 |
</varlistentry> |
| 269 |
<varlistentry> |
| 270 |
<term><varname>CONNECTION_EXTERNAL</varname></term> |
| 271 |
<listitem><para> |
| 272 |
If "1", this indicates that the connection describes a |
| 273 |
network configuration created outside of NetworkManager. |
| 274 |
</para></listitem> |
| 275 |
</varlistentry> |
| 276 |
<varlistentry> |
| 277 |
<term><varname>DEVICE_IFACE</varname></term> |
| 278 |
<listitem><para> |
| 279 |
The interface name of the control interface of the device. |
| 280 |
Depending on the device type, this differs from |
| 281 |
<varname>DEVICE_IP_IFACE</varname>. For example for |
| 282 |
ADSL devices, this could be 'atm0' or for WWAN devices |
| 283 |
it might be 'ttyUSB0'. |
| 284 |
</para></listitem> |
| 285 |
</varlistentry> |
| 286 |
<varlistentry> |
| 287 |
<term><varname>DEVICE_IP_IFACE</varname></term> |
| 288 |
<listitem><para> |
| 289 |
The IP interface name of the device. This is the network |
| 290 |
interface on which IP addresses and routes will be configured. |
| 291 |
</para></listitem> |
| 292 |
</varlistentry> |
| 293 |
<varlistentry> |
| 294 |
<term><varname>IP4_ADDRESS_N</varname></term> |
| 295 |
<listitem><para> |
| 296 |
The IPv4 address in the format "address/prefix gateway", where N is a number |
| 297 |
from 0 to (# IPv4 addresses - 1). gateway item in this variable is deprecated, |
| 298 |
use IP4_GATEWAY instead. |
| 299 |
</para></listitem> |
| 300 |
</varlistentry> |
| 301 |
<varlistentry> |
| 302 |
<term><varname>IP4_NUM_ADDRESSES</varname></term> |
| 303 |
<listitem><para> |
| 304 |
The variable contains the number of IPv4 addresses the script may expect. |
| 305 |
</para></listitem> |
| 306 |
</varlistentry> |
| 307 |
<varlistentry> |
| 308 |
<term><varname>IP4_GATEWAY</varname></term> |
| 309 |
<listitem><para> |
| 310 |
The gateway IPv4 address in traditional numbers-and-dots notation. |
| 311 |
</para></listitem> |
| 312 |
</varlistentry> |
| 313 |
<varlistentry> |
| 314 |
<term><varname>IP4_ROUTE_N</varname></term> |
| 315 |
<listitem><para> |
| 316 |
The IPv4 route in the format "address/prefix next-hop metric", where N is a number |
| 317 |
from 0 to (# IPv4 routes - 1). |
| 318 |
</para></listitem> |
| 319 |
</varlistentry> |
| 320 |
<varlistentry> |
| 321 |
<term><varname>IP4_NUM_ROUTES</varname></term> |
| 322 |
<listitem><para> |
| 323 |
The variable contains the number of IPv4 routes the script may expect. |
| 324 |
</para></listitem> |
| 325 |
</varlistentry> |
| 326 |
<varlistentry> |
| 327 |
<term><varname>IP4_NAMESERVERS</varname></term> |
| 328 |
<listitem><para> |
| 329 |
The variable contains a space-separated list of the DNS servers. |
| 330 |
</para></listitem> |
| 331 |
</varlistentry> |
| 332 |
<varlistentry> |
| 333 |
<term><varname>IP4_DOMAINS</varname></term> |
| 334 |
<listitem><para> |
| 335 |
The variable contains a space-separated list of the search domains. |
| 336 |
</para></listitem> |
| 337 |
</varlistentry> |
| 338 |
<varlistentry> |
| 339 |
<term><varname>DHCP4_<dhcp-option-name></varname></term> |
| 340 |
<listitem><para> |
| 341 |
If the connection used DHCP for address configuration, the received DHCP |
| 342 |
configuration is passed in the environment using standard DHCP |
| 343 |
option names, prefixed with "DHCP4_", like "DHCP4_HOST_NAME=foobar". |
| 344 |
</para></listitem> |
| 345 |
</varlistentry> |
| 346 |
<varlistentry> |
| 347 |
<term><varname>IP6_<name> and DHCP6_<name></varname></term> |
| 348 |
<listitem><para> |
| 349 |
The same variables as for IPv4 are available for IPv6, but the prefixes are IP6_ |
| 350 |
and DHCP6_ instead. |
| 351 |
</para></listitem> |
| 352 |
</varlistentry> |
| 353 |
<varlistentry> |
| 354 |
<term><varname>CONNECTIVITY_STATE</varname></term> |
| 355 |
<listitem><para> The network connectivity state, which can |
| 356 |
take the values defined by the NMConnectivityState type, |
| 357 |
from the org.freedesktop.NetworkManager D-Bus API: <literal>UNKNOWN</literal>, |
| 358 |
<literal>NONE</literal>, <literal>PORTAL</literal>, <literal>LIMITED</literal> |
| 359 |
or <literal>FULL</literal>. Note: this variable will only |
| 360 |
be set for connectivity-change actions. |
| 361 |
</para></listitem> |
| 362 |
</varlistentry> |
| 363 |
</variablelist> |
| 364 |
</para> |
| 365 |
<para> |
| 366 |
In case of VPN, VPN_IP_IFACE is set, and IP4_*, IP6_* variables with VPN prefix are |
| 367 |
exported too, like VPN_IP4_ADDRESS_0, VPN_IP4_NUM_ADDRESSES. |
| 368 |
</para> |
| 369 |
<para> |
| 370 |
The content of the <literal>user</literal> setting for the connection |
| 371 |
being activated is also passed via environment variables. Each key is |
| 372 |
stored in a variable with name <literal>CONNECTION_USER_</literal> |
| 373 |
concatenated with the encoding of the key name. The encoding works as |
| 374 |
follows: |
| 375 |
<itemizedlist> |
| 376 |
<listitem> |
| 377 |
<para>lowercase letters become uppercase</para> |
| 378 |
</listitem> |
| 379 |
<listitem> |
| 380 |
<para>uppercase letters are prefixed with an underscore</para> |
| 381 |
</listitem> |
| 382 |
<listitem> |
| 383 |
<para>numbers do not change</para> |
| 384 |
</listitem> |
| 385 |
<listitem> |
| 386 |
<para>a dot is replaced with a double underscore</para> |
| 387 |
</listitem> |
| 388 |
<listitem> |
| 389 |
<para>any other character is encoded with an underscore followed by |
| 390 |
its 3-digit octal representation</para> |
| 391 |
</listitem> |
| 392 |
</itemizedlist> |
| 393 |
For example, key <literal>test.foo-Bar2</literal> is stored in a variable named |
| 394 |
<literal>CONNECTION_USER_TEST__FOO_055_BAR2</literal>. |
| 395 |
</para> |
| 396 |
<para> |
| 397 |
Dispatcher scripts are run one at a time, but asynchronously from the main |
| 398 |
NetworkManager process, and will be killed if they run for too long. If your script |
| 399 |
might take arbitrarily long to complete, you should spawn a child process and have the |
| 400 |
parent return immediately. Scripts that are symbolic links pointing inside the |
| 401 |
<filename>/etc/NetworkManager/dispatcher.d/no-wait.d/</filename> |
| 402 |
directory are run immediately, without |
| 403 |
waiting for the termination of previous scripts, and in parallel. Also beware that |
| 404 |
once a script is queued, it will always be run, even if a later event renders it |
| 405 |
obsolete. (Eg, if an interface goes up, and then back down again quickly, it is |
| 406 |
possible that one or more "up" scripts will be run after the interface has gone down.) |
| 407 |
</para> |
| 408 |
</refsect1> |
| 409 |
|
| 410 |
<refsect1> |
| 411 |
<title>Bugs</title> |
| 412 |
<para> |
| 413 |
Please report any bugs you find in NetworkManager at the |
| 414 |
<ulink url="https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues">NetworkManager issue tracker</ulink>. |
| 415 |
</para> |
| 416 |
</refsect1> |
| 417 |
|
| 418 |
<refsect1> |
| 419 |
<title>See Also</title> |
| 420 |
<para> |
| 421 |
<ulink url="https://networkmanager.dev">NetworkManager home page</ulink>, |
| 422 |
<link linkend='NetworkManager'><citerefentry><refentrytitle>NetworkManager</refentrytitle><manvolnum>8</manvolnum></citerefentry></link>, |
| 423 |
</para> |
| 424 |
</refsect1> |
| 425 |
</refentry> |