sd-netlink: don't export internal type-system details
authorDavid Herrmann <dh.herrmann@gmail.com>
Wed, 24 Jun 2015 11:27:34 +0000 (13:27 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Wed, 24 Jun 2015 11:46:15 +0000 (13:46 +0200)
The kernel bonding layer allows passing an array of ARP IP targets as
bond-configuration. Due to the weird implementation of arrays in netlink
(which we haven't figure out a generic way to support, yet), we usually
hard-code the supported array-sizes. However, this should not be exported
from sd-netlink.

Instead, make sure the caller just uses it's current hack of enumerating
the types, and the sd-netlink core will have it's own list of supported
array-sizes (to be removed in future extensions, btw!). If either does not
match, we will just return a normal error.

Note that we provide 2 constants for ARP_IP_TARGETS_MAX now. However, both
have very different reasons:
 - the constant in netdev-bond.c is used to warn the user that the given
   number of targets might not be supported by the kernel (even though the
   kernel might increase that number at _any_ time)
 - the constant in sd-netlink is solely used due to us missing a proper
   array implementation. Once that's supported in the type-system, it can
   be removed without notice

Last but not least, this patch turns the log_error() into a log_warning().
Given that the previous condition was off-by-one, anyway, it never hit at
the right time. Thus, it was probably of no real use.

src/libsystemd/sd-netlink/netlink-types.c
src/libsystemd/sd-netlink/netlink-types.h
src/network/networkd-netdev-bond.c
src/network/networkd-netdev-bond.h

index 40548dc..74ac2ab 100644 (file)
 #include "netlink-types.h"
 #include "missing.h"
 
+/* Maximum ARP IP target defined in kernel */
+#define BOND_MAX_ARP_TARGETS    16
+
+typedef enum {
+        BOND_ARP_TARGETS_0,
+        BOND_ARP_TARGETS_1,
+        BOND_ARP_TARGETS_2,
+        BOND_ARP_TARGETS_3,
+        BOND_ARP_TARGETS_4,
+        BOND_ARP_TARGETS_5,
+        BOND_ARP_TARGETS_6,
+        BOND_ARP_TARGETS_7,
+        BOND_ARP_TARGETS_8,
+        BOND_ARP_TARGETS_9,
+        BOND_ARP_TARGETS_10,
+        BOND_ARP_TARGETS_11,
+        BOND_ARP_TARGETS_12,
+        BOND_ARP_TARGETS_13,
+        BOND_ARP_TARGETS_14,
+        BOND_ARP_TARGETS_MAX = BOND_MAX_ARP_TARGETS,
+} BondArpTargets;
+
 struct NLType {
         uint16_t type;
         size_t size;
index b1ef7af..a210163 100644 (file)
@@ -90,25 +90,3 @@ typedef enum NLUnionLinkInfoData {
 
 const char *nl_union_link_info_data_to_string(NLUnionLinkInfoData p) _const_;
 NLUnionLinkInfoData nl_union_link_info_data_from_string(const char *p) _pure_;
-
-/* Maximum ARP IP target defined in kernel */
-#define BOND_MAX_ARP_TARGETS    16
-
-typedef enum BondArpTargets {
-        BOND_ARP_TARGETS_0,
-        BOND_ARP_TARGETS_1,
-        BOND_ARP_TARGETS_2,
-        BOND_ARP_TARGETS_3,
-        BOND_ARP_TARGETS_4,
-        BOND_ARP_TARGETS_5,
-        BOND_ARP_TARGETS_6,
-        BOND_ARP_TARGETS_7,
-        BOND_ARP_TARGETS_8,
-        BOND_ARP_TARGETS_9,
-        BOND_ARP_TARGETS_10,
-        BOND_ARP_TARGETS_11,
-        BOND_ARP_TARGETS_12,
-        BOND_ARP_TARGETS_13,
-        BOND_ARP_TARGETS_14,
-        BOND_ARP_TARGETS_MAX = BOND_MAX_ARP_TARGETS,
-} BondArpTargets;
index 6336ff5..a60034d 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "conf-parser.h"
 #include "sd-netlink.h"
-#include "netlink-types.h"
 #include "networkd-netdev-bond.h"
 #include "missing.h"
 
@@ -372,11 +371,11 @@ int config_parse_arp_ip_target_address(const char *unit,
                 b->n_arp_ip_targets ++;
 
                 buffer = NULL;
-
-                if (b->n_arp_ip_targets > BOND_ARP_TARGETS_MAX)
-                        break;
         }
 
+        if (b->n_arp_ip_targets > NETDEV_BOND_ARP_TARGETS_MAX)
+                log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "More than the maximum number of kernel-supported ARP ip targets specified: %d > %d", b->n_arp_ip_targets, NETDEV_BOND_ARP_TARGETS_MAX);
+
         return 0;
 }
 
index 32d1702..9991fa7 100644 (file)
@@ -25,6 +25,12 @@ typedef struct Bond Bond;
 
 #include "networkd-netdev.h"
 
+/*
+ * Maximum number of targets supported by the kernel for a single
+ * bond netdev.
+ */
+#define NETDEV_BOND_ARP_TARGETS_MAX 16
+
 typedef enum BondMode {
         NETDEV_BOND_MODE_BALANCE_RR,
         NETDEV_BOND_MODE_ACTIVE_BACKUP,