]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: require powerpairs for Dot3 power even when PD
authorVincent Bernat <vincent@bernat.ch>
Fri, 4 Jun 2021 16:51:13 +0000 (18:51 +0200)
committerVincent Bernat <vincent@bernat.ch>
Fri, 4 Jun 2021 16:54:53 +0000 (18:54 +0200)
This reverts commit 7056d802b9c595dd16f1354649bb7ae2f8b8880c. I may
have been hasty in removing this as my understanding is that the PSE
would impose the value to the PD, but it could be the other way
around. Some implementations do not like to have 0 as the value here
and will ignore the whole TLV.

NEWS
src/client/conf-power.c
src/client/display.c
src/client/lldpcli.8.in
src/lib/atoms/dot3.c
tests/integration/test_dot3.py
tests/lldpcli.conf

diff --git a/NEWS b/NEWS
index b9dd1c37983af914d4e3c3c2c3eceb3403b0038e..c53f95a497be16617295081435430f45ac5cc1eb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 lldpd (1.0.12)
   * Fix:
     + Use a dedicated file lock to prevent concurrent changes from lldpcli.
+    + Require/display powerpairs for Dot3 power even when device type is PD.
 
 lldpd (1.0.11)
   * Changes:
index 52a676a8ff20e554fceec5fc56c4b849ee6f9095..ef6f9ccd1c55687e63a0f030c8b06370bef54804 100644 (file)
@@ -121,7 +121,7 @@ cmd_dot3power(struct lldpctl_conn_t *conn, struct writer *w,
                    /* Powerpairs */
                    (what = "power pairs", lldpctl_atom_set_str(dot3_power,
                        lldpctl_k_dot3_power_pairs,
-                       cmdenv_get(env, "powerpairs")?cmdenv_get(env, "powerpairs"):"unknown")) == NULL ||
+                       cmdenv_get(env, "powerpairs"))) == NULL ||
                    /* Class */
                    (what = "power class", cmdenv_get(env, "class")?
                        lldpctl_atom_set_str(dot3_power,
@@ -304,11 +304,10 @@ register_commands_medpow(struct cmd_node *configure_med)
 static int
 cmd_check_env_power(struct cmd_env *env, void *nothing)
 {
-       /* We need type. If we type is PSE, we need powerpairs. If we have
-        * typeat, we also request source, priority, requested and allocated. */
+       /* We need type and powerpair but if we have typeat, we also request
+        * source, priority, requested and allocated. */
        if (!cmdenv_get(env, "device-type")) return 0;
-       if (!strcmp(cmdenv_get(env, "device-type"), "pse") &&
-           !cmdenv_get(env, "powerpairs")) return 0;
+       if (!cmdenv_get(env, "powerpairs")) return 0;
        if (cmdenv_get(env, "typeat")) {
                return (!!cmdenv_get(env, "source") &&
                    !!cmdenv_get(env, "priority") &&
@@ -361,8 +360,8 @@ register_commands_dot3pow(struct cmd_node *configure_dot3)
        /* Power pairs */
        struct cmd_node *powerpairs = commands_new(
                configure_dot3power,
-               "powerpairs", "Which pairs are currently used for power",
-               cmd_check_pse, NULL, "powerpairs");
+               "powerpairs", "Which pairs are currently used for power (mandatory)",
+               cmd_check_type_but_no, NULL, "powerpairs");
        for (lldpctl_map_t *pp_map =
                 lldpctl_key_get_map(lldpctl_k_dot3_power_pairs);
             pp_map->string;
index 7bbe549c826c3193b79f007e45bda3b6fe1a73f3..b21ff028d7647a6253c76e63db8343094f42baeb 100644 (file)
@@ -446,13 +446,10 @@ display_port(struct writer *w, lldpctl_atom_t *port, int details)
                        tag_data(w, lldpctl_atom_get_str(dot3_power,
                                lldpctl_k_dot3_power_devicetype));;
                        tag_end(w);
-                       if (lldpctl_atom_get_int(dot3_power,
-                           lldpctl_k_dot3_power_devicetype) == LLDP_DOT3_POWER_PSE) {
-                               tag_start(w, "pairs", "Power pairs");
-                               tag_data(w, lldpctl_atom_get_str(dot3_power,
-                                   lldpctl_k_dot3_power_pairs));
-                               tag_end(w);
-                       }
+                       tag_start(w, "pairs", "Power pairs");
+                       tag_data(w, lldpctl_atom_get_str(dot3_power,
+                               lldpctl_k_dot3_power_pairs));
+                       tag_end(w);
                        tag_start(w, "class", "Class");
                        tag_data(w, lldpctl_atom_get_str(dot3_power,
                                lldpctl_k_dot3_power_class));
index 6a03b34227cf8c2de78f12204b58ea3394534d10..7649be59c550a63d45d57b4c7e706761960e1f1d 100644 (file)
@@ -922,7 +922,7 @@ Here is an example of use:
 .Op Cd supported
 .Op Cd enabled
 .Op Cd paircontrol
-.Op Cd powerpairs Ar powerpairs
+.Cd powerpairs Ar powerpairs
 .Op Cd class Ar class
 .Op Cd type Ar type Cd source Ar source Cd priority Ar priority Cd requested Ar requested Cd allocated Ar allocated
 .Bd -ragged -offset XXXXXX
index 798659c7206b35ec07d7d64fbc4678c1cacd5dcf..b6b084601750564d19a3a928f6bd993272c298e0 100644 (file)
@@ -48,7 +48,6 @@ static lldpctl_map_t port_dot3_power_pd_source_map[] = {
 static struct atom_map port_dot3_power_pairs_map = {
        .key = lldpctl_k_dot3_power_pairs,
        .map = {
-               { 0,                           "unknown" },
                { LLDP_DOT3_POWERPAIRS_SIGNAL, "signal" },
                { LLDP_DOT3_POWERPAIRS_SPARE,  "spare" },
                { 0, NULL }
@@ -388,7 +387,6 @@ _lldpctl_atom_set_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key,
                }
        case lldpctl_k_dot3_power_pairs:
                switch (value) {
-               case 0:
                case 1:
                case 2:
                        port->p_power.pairs = value;
index 9a4ebdf38794a2c1996b1194c357bcf16d9e4e61..1eb5ee46db34a66e4cf9412bee020988870cc728 100644 (file)
@@ -28,12 +28,13 @@ class TestLldpDot3(object):
           'device-type': 'PSE',
           'pairs': 'spare',
           'class': 'class 3'}),
-        ("pd supported enabled class class-3 type 1 source "
+        ("pd supported enabled powerpairs spare class class-3 type 1 source "
          "pse priority low requested 10000 allocated 15000",
          {'supported': 'yes',
           'enabled': 'yes',
           'paircontrol': 'no',
           'device-type': 'PD',
+          'pairs': 'spare',
           'class': 'class 3',
           'power-type': '1',
           'source': 'Primary power source',
@@ -65,6 +66,7 @@ class TestLldpDot3(object):
             result = lldpcli(
                 *shlex.split("configure dot3 power pd "
                              "supported enabled paircontrol "
+                             "powerpairs spare "
                              "class class-3 "
                              "type 1 source both priority low "
                              "requested 20000 allocated 5000"))
index 8f1df00fec84cc29b91bbb383e7372911b8da042..600235ebed214b62c380f61fb9c7b8bb1962b44f 100644 (file)
@@ -54,7 +54,7 @@ configure med power pd source pse priority high value 5000
 configure ports eth0 med power pd source pse priority high value 5000
 configure dot3 power pse supported enabled paircontrol powerpairs spare class class-3
 configure ports eth0 dot3 power pse supported enabled paircontrol powerpairs spare class class-3
-configure dot3 power pd supported enabled class class-3 type 1 source pse priority low requested 10000 allocated 15000
+configure dot3 power pd supported enabled powerpairs spare class class-3 type 1 source pse priority low requested 10000 allocated 15000
 
 # A convenient way to "test" lldpcli and liblldpctl is to load those commands in lldpcli with valgrind:
 #  libtool execute valgrind --suppressions=../src/client/lldpcli.supp --leak-check=full src/client/lldpcli -c ../tests/lldpcli.conf