]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #4123 from keszybz/network-file-dropins
authorMartin Pitt <martin.pitt@ubuntu.com>
Sat, 17 Sep 2016 08:00:19 +0000 (10:00 +0200)
committerGitHub <noreply@github.com>
Sat, 17 Sep 2016 08:00:19 +0000 (10:00 +0200)
Network file dropins

1  2 
man/systemd.netdev.xml
src/journal-remote/journal-remote.c
src/network/networkd-netdev.c
src/network/networkd-network.c

diff --combined man/systemd.netdev.xml
index 78f0e25a6f10ddd601a52232145a54d41c7dcbb7,585b924e3d991e05d20a9cc52541a3c170157ffa..c8b5a057f8d2f42e082d88140f3fcb275dde4645
      <citerefentry><refentrytitle>systemd-networkd</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
      </para>
  
-     <para>Virtual Network Device files must have the extension
-     <filename>.netdev</filename>; other extensions are ignored.
-     Virtual network devices are created as soon as networkd is
-     started. If a netdev with the specified name already exists,
-     networkd will use that as-is rather than create its own. Note that
-     the settings of the pre-existing netdev will not be changed by
+     <para>The main Virtual Network Device file must have the extension <filename>.netdev</filename>;
+     other extensions are ignored. Virtual network devices are created as soon as networkd is
+     started. If a netdev with the specified name already exists, networkd will use that as-is rather
+     than create its own. Note that the settings of the pre-existing netdev will not be changed by
      networkd.</para>
  
-     <para>The <filename>.netdev</filename> files are read from the
-     files located in the system network directory
-     <filename>/usr/lib/systemd/network</filename>, the volatile
-     runtime network directory
-     <filename>/run/systemd/network</filename> and the local
-     administration network directory
-     <filename>/etc/systemd/network</filename>. All configuration files
-     are collectively sorted and processed in lexical order, regardless
-     of the directories in which they live. However, files with
-     identical filenames replace each other. Files in
-     <filename>/etc</filename> have the highest priority, files in
-     <filename>/run</filename> take precedence over files with the same
-     name in <filename>/usr/lib</filename>. This can be used to
-     override a system-supplied configuration file with a local file if
-     needed. As a special case, an empty file (file size 0) or symlink
-     with the same name pointing to <filename>/dev/null</filename>
-     disables the configuration file entirely (it is "masked").</para>
+     <para>The <filename>.netdev</filename> files are read from the files located in the system
+     network directory <filename>/usr/lib/systemd/network</filename>, the volatile runtime network
+     directory <filename>/run/systemd/network</filename> and the local administration network
+     directory <filename>/etc/systemd/network</filename>. All configuration files are collectively
+     sorted and processed in lexical order, regardless of the directories in which they live.
+     However, files with identical filenames replace each other. Files in <filename>/etc</filename>
+     have the highest priority, files in <filename>/run</filename> take precedence over files with
+     the same name in <filename>/usr/lib</filename>. This can be used to override a system-supplied
+     configuration file with a local file if needed. As a special case, an empty file (file size 0)
+     or symlink with the same name pointing to <filename>/dev/null</filename> disables the
+     configuration file entirely (it is "masked").</para>
+     <para>Along with the netdev file <filename>foo.netdev</filename>, a "drop-in" directory
+     <filename>foo.netdev.d/</filename> may exist. All files with the suffix <literal>.conf</literal>
+     from this directory will be parsed after the file itself is parsed. This is useful to alter or
+     add configuration settings, without having to modify the main configuration file. Each drop-in
+     file must have appropriate section headers.</para>
+     <para>In addition to <filename>/etc/systemd/network</filename>, drop-in <literal>.d</literal>
+     directories can be placed in <filename>/usr/lib/systemd/network</filename> or
+     <filename>/run/systemd/network</filename> directories. Drop-in files in
+     <filename>/etc</filename> take precedence over those in <filename>/run</filename> which in turn
+     take precedence over those in <filename>/usr/lib</filename>. Drop-in files under any of these
+     directories take precedence over the main netdev file wherever located. (Of course, since
+     <filename>/run</filename> is temporary and <filename>/usr/lib</filename> is for vendors, it is
+     unlikely drop-ins should be used in either of those places.)</para>
    </refsect1>
  
    <refsect1>
            <entry>A virtual extensible LAN (vxlan), for connecting Cloud computing deployments.</entry></row>
  
            <row><entry><varname>vrf</varname></entry>
 -            <entry>A Virtual Routing and Forwarding (<ulink url="https://www.kernel.org/doc/Documentation/networking/vrf.txt">VRF</ulink>) interface to create separate routing and forwarding domains.</entry></row>
 +          <entry>A Virtual Routing and Forwarding (<ulink url="https://www.kernel.org/doc/Documentation/networking/vrf.txt">VRF</ulink>) interface to create separate routing and forwarding domains.</entry></row>
 +
 +          <row><entry><varname>vcan</varname></entry>
 +          <entry>The virtual CAN driver (vcan). Similar to the network loopback devices,
 +          vcan offers a virtual local CAN interface.</entry></row>
  
          </tbody>
        </tgroup>
index aebc4cafb4965e25eb4ca63d25d6be607de60ec7,220c71754ac1dd890a75f8d7c636871f2583ef1e..a9009cfefeb16502272b6b17718c4d0ed5305619
@@@ -524,12 -524,13 +524,12 @@@ static int process_http_upload
                          log_warning("Failed to process data for connection %p", connection);
                          if (r == -E2BIG)
                                  return mhd_respondf(connection,
 -                                                    MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
 -                                                    "Entry is too large, maximum is %u bytes.\n",
 -                                                    DATA_SIZE_MAX);
 +                                                    r, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
 +                                                    "Entry is too large, maximum is " STRINGIFY(DATA_SIZE_MAX) " bytes.");
                          else
                                  return mhd_respondf(connection,
 -                                                    MHD_HTTP_UNPROCESSABLE_ENTITY,
 -                                                    "Processing failed: %s.", strerror(-r));
 +                                                    r, MHD_HTTP_UNPROCESSABLE_ENTITY,
 +                                                    "Processing failed: %m.");
                  }
          }
  
  
          remaining = source_non_empty(source);
          if (remaining > 0) {
 -                log_warning("Premature EOFbyte. %zu bytes lost.", remaining);
 -                return mhd_respondf(connection, MHD_HTTP_EXPECTATION_FAILED,
 +                log_warning("Premature EOF byte. %zu bytes lost.", remaining);
 +                return mhd_respondf(connection,
 +                                    0, MHD_HTTP_EXPECTATION_FAILED,
                                      "Premature EOF. %zu bytes of trailing data not processed.",
                                      remaining);
          }
  
 -        return mhd_respond(connection, MHD_HTTP_ACCEPTED, "OK.\n");
 +        return mhd_respond(connection, MHD_HTTP_ACCEPTED, "OK.");
  };
  
  static int request_handler(
                                             *connection_cls);
  
          if (!streq(method, "POST"))
 -                return mhd_respond(connection, MHD_HTTP_NOT_ACCEPTABLE,
 -                                   "Unsupported method.\n");
 +                return mhd_respond(connection, MHD_HTTP_NOT_ACCEPTABLE, "Unsupported method.");
  
          if (!streq(url, "/upload"))
 -                return mhd_respond(connection, MHD_HTTP_NOT_FOUND,
 -                                   "Not found.\n");
 +                return mhd_respond(connection, MHD_HTTP_NOT_FOUND, "Not found.");
  
          header = MHD_lookup_connection_value(connection,
                                               MHD_HEADER_KIND, "Content-Type");
          if (!header || !streq(header, "application/vnd.fdo.journal"))
                  return mhd_respond(connection, MHD_HTTP_UNSUPPORTED_MEDIA_TYPE,
 -                                   "Content-Type: application/vnd.fdo.journal"
 -                                   " is required.\n");
 +                                   "Content-Type: application/vnd.fdo.journal is required.");
  
          {
                  const union MHD_ConnectionInfo *ci;
                  if (!ci) {
                          log_error("MHD_get_connection_info failed: cannot get remote fd");
                          return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
 -                                           "Cannot check remote address");
 +                                           "Cannot check remote address.");
                  }
  
                  fd = ci->connect_fd;
                  r = getpeername_pretty(fd, false, &hostname);
                  if (r < 0)
                          return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
 -                                           "Cannot check remote hostname");
 +                                           "Cannot check remote hostname.");
          }
  
          assert(hostname);
          if (r == -ENOMEM)
                  return respond_oom(connection);
          else if (r < 0)
 -                return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
 -                                   strerror(-r));
 +                return mhd_respondf(connection, r, MHD_HTTP_INTERNAL_SERVER_ERROR, "%m");
  
          hostname = NULL;
          return MHD_YES;
@@@ -1194,7 -1198,7 +1194,7 @@@ static int parse_config(void) 
                  { "Remote",  "TrustedCertificateFile", config_parse_path,             0, &arg_trust      },
                  {}};
  
-         return config_parse_many(PKGSYSCONFDIR "/journal-remote.conf",
+         return config_parse_many_nulstr(PKGSYSCONFDIR "/journal-remote.conf",
                                   CONF_PATHS_NULSTR("systemd/journal-remote.conf.d"),
                                   "Remote\0", config_item_table_lookup, items,
                                   false, NULL);
index 897de9bde5a7d9488b265d3bf6f64bb0db33e670,ece4ea2e646b340646581409b7072c430daccc08..a210ba1242758197fc29fff4f8781de4ca44b363
@@@ -34,6 -34,7 +34,6 @@@
  #include "string-util.h"
  
  const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX] = {
 -
          [NETDEV_KIND_BRIDGE] = &bridge_vtable,
          [NETDEV_KIND_BOND] = &bond_vtable,
          [NETDEV_KIND_VLAN] = &vlan_vtable,
@@@ -55,7 -56,7 +55,7 @@@
          [NETDEV_KIND_TAP] = &tap_vtable,
          [NETDEV_KIND_IP6TNL] = &ip6tnl_vtable,
          [NETDEV_KIND_VRF] = &vrf_vtable,
 -
 +        [NETDEV_KIND_VCAN] = &vcan_vtable,
  };
  
  static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
@@@ -80,7 -81,7 +80,7 @@@
          [NETDEV_KIND_TAP] = "tap",
          [NETDEV_KIND_IP6TNL] = "ip6tnl",
          [NETDEV_KIND_VRF] = "vrf",
 -
 +        [NETDEV_KIND_VCAN] = "vcan",
  };
  
  DEFINE_STRING_TABLE_LOOKUP(netdev_kind, NetDevKind);
@@@ -515,7 -516,7 +515,7 @@@ static int netdev_create(NetDev *netdev
  
                  r = sd_netlink_message_close_container(m);
                  if (r < 0)
 -                        return log_netdev_error_errno(netdev, r, "Could not append IFLA_LINKINFO attribute: %m");
 +                        return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m");
  
                  r = sd_netlink_message_close_container(m);
                  if (r < 0)
@@@ -576,6 -577,7 +576,7 @@@ static int netdev_load_one(Manager *man
          _cleanup_netdev_unref_ NetDev *netdev = NULL;
          _cleanup_free_ NetDev *netdev_raw = NULL;
          _cleanup_fclose_ FILE *file = NULL;
+         const char *dropin_dirname;
          int r;
  
          assert(manager);
                  return log_oom();
  
          netdev_raw->kind = _NETDEV_KIND_INVALID;
+         dropin_dirname = strjoina(basename(filename), ".d");
  
-         r = config_parse(NULL, filename, file,
-                          "Match\0NetDev\0",
-                          config_item_perf_lookup, network_netdev_gperf_lookup,
-                          true, false, true, netdev_raw);
+         r = config_parse_many(filename, network_dirs, dropin_dirname,
+                               "Match\0NetDev\0",
+                               config_item_perf_lookup, network_netdev_gperf_lookup,
+                               true, netdev_raw);
          if (r < 0)
                  return r;
  
                  return 0;
  
          if (netdev_raw->kind == _NETDEV_KIND_INVALID) {
-                 log_warning("NetDev with invalid Kind configured in %s. Ignoring", filename);
+                 log_warning("NetDev has no Kind configured in %s. Ignoring", filename);
                  return 0;
          }
  
index 91e51e9124cf2b4bf86089005451d485ab4226a2,58e19e542a058f317a2ac1c0caa0c883e56eade1..313abca7626c590ab69fd682c1c4bb416c637d35
@@@ -40,6 -40,7 +40,7 @@@ static int network_load_one(Manager *ma
          _cleanup_network_free_ Network *network = NULL;
          _cleanup_fclose_ FILE *file = NULL;
          char *d;
+         const char *dropin_dirname;
          Route *route;
          Address *address;
          int r;
          network->arp = -1;
          network->ipv6_accept_ra_use_dns = true;
  
-         r = config_parse(NULL, filename, file,
-                          "Match\0"
-                          "Link\0"
-                          "Network\0"
-                          "Address\0"
-                          "Route\0"
-                          "DHCP\0"
-                          "DHCPv4\0" /* compat */
-                          "DHCPServer\0"
-                          "IPv6AcceptRA\0"
-                          "Bridge\0"
-                          "BridgeFDB\0"
-                          "BridgeVLAN\0",
-                          config_item_perf_lookup, network_network_gperf_lookup,
-                          false, false, true, network);
+         dropin_dirname = strjoina(network->name, ".network.d");
+         r = config_parse_many(filename, network_dirs, dropin_dirname,
+                               "Match\0"
+                               "Link\0"
+                               "Network\0"
+                               "Address\0"
+                               "Route\0"
+                               "DHCP\0"
+                               "DHCPv4\0" /* compat */
+                               "DHCPServer\0"
+                               "IPv6AcceptRA\0"
+                               "Bridge\0"
+                               "BridgeFDB\0"
+                               "BridgeVLAN\0",
+                               config_item_perf_lookup, network_network_gperf_lookup,
+                               false, network);
          if (r < 0)
                  return r;
  
@@@ -479,10 -482,9 +482,10 @@@ int config_parse_netdev(const char *uni
          case NETDEV_KIND_MACVTAP:
          case NETDEV_KIND_IPVLAN:
          case NETDEV_KIND_VXLAN:
 +        case NETDEV_KIND_VCAN:
                  r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev);
                  if (r < 0) {
 -                        log_syntax(unit, LOG_ERR, filename, line, r, "Can not add VLAN '%s' to network: %m", rvalue);
 +                        log_syntax(unit, LOG_ERR, filename, line, r, "Can not add NetDev '%s' to network: %m", rvalue);
                          return 0;
                  }