]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce TripleSampling= option in CAN section
authorClemens Gruber <clemens.gruber@pqgruber.com>
Mon, 11 Mar 2019 14:25:20 +0000 (15:25 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 11 Mar 2019 16:15:47 +0000 (17:15 +0100)
When enabled, three samples are used to determine the value of a
received bit by majority rule.

This patch adds support for the TripleSampling= option in the [CAN]
section of .network files.

man/systemd.network.xml
src/libsystemd/sd-netlink/netlink-types.c
src/network/networkd-link.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h
test/fuzz/fuzz-network-parser/directives.network

index 4fa2d1dc48f3e05969fba35e3bb781d1ae2da038..1a3d24aa7633144e1a28984b6bbdd97ec0af8e2a 100644 (file)
             automatic restart off. By default automatic restart is disabled.</para>
           </listitem>
         </varlistentry>
+        <varlistentry>
+          <term><varname>TripleSampling=</varname></term>
+          <listitem>
+            <para>Takes a boolean. When <literal>yes</literal>, three samples (instead of one) are used to determine
+            the value of a received bit by majority rule. When unset, the kernel's default will be used.</para>
+          </listitem>
+        </varlistentry>
       </variablelist>
   </refsect1>
 
index 5ef2ba37809fcc10473f0392df5f3936a0268bbb..803de54712a0099107aed8ca4df2660fce21d113 100644 (file)
@@ -308,6 +308,7 @@ static const NLType rtnl_link_info_data_geneve_types[] = {
 static const NLType rtnl_link_info_data_can_types[] = {
         [IFLA_CAN_BITTIMING]            = { .size = sizeof(struct can_bittiming) },
         [IFLA_CAN_RESTART_MS]           = { .type = NETLINK_TYPE_U32 },
+        [IFLA_CAN_CTRLMODE]             = { .size = sizeof(struct can_ctrlmode) },
 };
 
 /* these strings must match the .kind entries in the kernel */
index 9e3cd71a095896f415afd8a64b2acfb7083364c0..de112a2ef80bf69ea5c0fcc0f0b1369eafafebbe 100644 (file)
@@ -2163,6 +2163,19 @@ static int link_set_can(Link *link) {
                         return log_link_error_errno(link, r, "Could not append IFLA_CAN_RESTART_MS attribute: %m");
         }
 
+        if (link->network->can_triple_sampling >= 0) {
+                struct can_ctrlmode cm = {
+                        .mask = CAN_CTRLMODE_3_SAMPLES,
+                        .flags = link->network->can_triple_sampling ? CAN_CTRLMODE_3_SAMPLES : 0,
+                };
+
+                log_link_debug(link, "%sabling triple-sampling", link->network->can_triple_sampling ? "En" : "Dis");
+
+                r = sd_netlink_message_append_data(m, IFLA_CAN_CTRLMODE, &cm, sizeof(cm));
+                if (r < 0)
+                        return log_link_error_errno(link, r, "Could not append IFLA_CAN_CTRLMODE attribute: %m");
+        }
+
         r = sd_netlink_message_close_container(m);
         if (r < 0)
                 return log_link_error_errno(link, r, "Failed to close netlink container: %m");
index 7888bdf07af270140600abf67c03a12bc2cab9c4..51123d12ef0cacd1751b55cd7f3e6d15db6beb90 100644 (file)
@@ -195,6 +195,7 @@ IPv6Prefix.PreferredLifetimeSec,        config_parse_prefix_lifetime,
 CAN.BitRate,                            config_parse_si_size,                           0,                             offsetof(Network, can_bitrate)
 CAN.SamplePoint,                        config_parse_permille,                          0,                             offsetof(Network, can_sample_point)
 CAN.RestartSec,                         config_parse_sec,                               0,                             offsetof(Network, can_restart_us)
+CAN.TripleSampling,                     config_parse_tristate,                          0,                             offsetof(Network, can_triple_sampling)
 /* backwards compatibility: do not add new entries to this section */
 Network.IPv4LL,                         config_parse_ipv4ll,                            0,                             offsetof(Network, link_local)
 DHCPv4.UseDNS,                          config_parse_bool,                              0,                             offsetof(Network, dhcp_use_dns)
index ab4e90543c3a67e3101a9693db5f6c9b190e2f40..5f12df907afe9afcc8127c89fa2f49b44fac116f 100644 (file)
@@ -428,6 +428,8 @@ int network_load_one(Manager *manager, const char *filename) {
                 .ipv6_accept_ra_use_onlink_prefix = true,
                 .ipv6_accept_ra_route_table = RT_TABLE_MAIN,
                 .ipv6_accept_ra_route_table_set = false,
+
+                .can_triple_sampling = -1,
         };
 
         r = config_parse_many(filename, NETWORK_DIRS, dropin_dirname,
index 63d0328750f37e85acf89f1c649c1f2dd01cc11a..2f7b6133fd506a3ebdda3b0d6f8cbeb7b2adbb02 100644 (file)
@@ -202,6 +202,7 @@ struct Network {
         size_t can_bitrate;
         unsigned can_sample_point;
         usec_t can_restart_us;
+        int can_triple_sampling;
 
         AddressFamilyBoolean ip_forward;
         bool ip_masquerade;
index d77c6989cddf56980c1fc7252859b3e23a125df7..9a60eb712df2ce2fcdb85ce26431412b9a399cd2 100644 (file)
@@ -132,6 +132,7 @@ PVID=
 SamplePoint=
 BitRate=
 RestartSec=
+TripleSampling=
 [Address]
 DuplicateAddressDetection=
 AutoJoin=