]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lib: expose management interface index
authorVincent Bernat <vincent@bernat.ch>
Sat, 27 Jul 2019 15:11:40 +0000 (17:11 +0200)
committerVincent Bernat <vincent@bernat.ch>
Sat, 27 Jul 2019 15:34:16 +0000 (17:34 +0200)
src/client/display.c
src/lib/atoms/mgmt.c
src/lib/lldpctl.h
tests/integration/test_basic.py
tests/integration/test_lldpcli.py

index 312091dec5b96ee308dcbdad9a971cfdad1ff6db..dc130703f61a250c268f20ff5843d273f2f57b7c 100644 (file)
@@ -258,6 +258,8 @@ display_chassis(struct writer* w, lldpctl_atom_t* chassis, int details)
        lldpctl_atom_foreach(mgmts, mgmt) {
                tag_datatag(w, "mgmt-ip", "MgmtIP",
                    lldpctl_atom_get_str(mgmt, lldpctl_k_mgmt_ip));
+               tag_datatag(w, "mgmt-iface", "MgmtIface",
+                   lldpctl_atom_get_str(mgmt, lldpctl_k_mgmt_iface_index));
        }
        lldpctl_atom_dec_ref(mgmts);
 
index 8afb6b07f562b3a7292dc1921fa6bbde9762b91d..702d9457be77d357bd423b790ace3bb653f91b69 100644 (file)
@@ -87,6 +87,21 @@ _lldpctl_atom_free_mgmt(lldpctl_atom_t *atom)
        lldpctl_atom_dec_ref(mgmt->parent);
 }
 
+static long int
+_lldpctl_atom_get_int_mgmt(lldpctl_atom_t *atom, lldpctl_key_t key)
+{
+       struct _lldpctl_atom_mgmt_t *m =
+           (struct _lldpctl_atom_mgmt_t *)atom;
+
+       /* Local and remote port */
+       switch (key) {
+       case lldpctl_k_mgmt_iface_index:
+               return m->mgmt->m_iface;
+       default:
+               return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST);
+       }
+}
+
 static const char*
 _lldpctl_atom_get_str_mgmt(lldpctl_atom_t *atom, lldpctl_key_t key)
 {
@@ -136,6 +151,7 @@ static struct atom_builder mgmt =
        { atom_mgmt, sizeof(struct _lldpctl_atom_mgmt_t),
          .init = _lldpctl_atom_new_mgmt,
          .free = _lldpctl_atom_free_mgmt,
+         .get_int = _lldpctl_atom_get_int_mgmt,
          .get_str = _lldpctl_atom_get_str_mgmt };
 
 ATOM_BUILDER_REGISTER(mgmts_list, 6);
index 53d3c4bc40f5f14799d61f5ab32dfc5689d71f08..c10a83dc6f70289a7f7a294577356438440429da 100644 (file)
@@ -778,6 +778,7 @@ typedef enum {
        lldpctl_k_med_power_val, /**< `(I,W)` LLDP MED power value */
 
        lldpctl_k_mgmt_ip = 3000,       /**< `(S)` IP address */
+       lldpctl_k_mgmt_iface_index = 30001,     /**< `(I)` Interface index */
 
        lldpctl_k_tx_cnt = 4000,        /**< `(I)` tx cnt. Only works for a local port. */
        lldpctl_k_rx_cnt,       /**< `(I)` rx cnt. Only works for a local port. */
index 28c1896f73d6ae892ba750d478391b5760950c7b..6d79020cd0eadd31e3db5549d23ec9adb9540894 100644 (file)
@@ -22,6 +22,7 @@ def test_one_neighbor(lldpd1, lldpd, lldpcli, namespaces):
                        "lldp.eth0.chassis.mac": "00:00:00:00:00:02",
                        "lldp.eth0.chassis.name": "ns-2.example.com",
                        "lldp.eth0.chassis.mgmt-ip": "fe80::200:ff:fe00:2",
+                       "lldp.eth0.chassis.mgmt-iface": "2",
                        "lldp.eth0.chassis.Bridge.enabled": "off",
                        "lldp.eth0.chassis.Wlan.enabled": "off",
                        "lldp.eth0.port.mac": "00:00:00:00:00:02",
@@ -63,6 +64,7 @@ def test_one_interface(lldpd1, lldpd, lldpcli, namespaces):
                        "lldp.eth0.chassis.mac": "00:00:00:00:00:01",
                        "lldp.eth0.chassis.name": "ns-1.example.com",
                        "lldp.eth0.chassis.mgmt-ip": "fe80::200:ff:fe00:1",
+                       "lldp.eth0.chassis.mgmt-iface": "3",
                        "lldp.eth0.chassis.Bridge.enabled": "off",
                        "lldp.eth0.chassis.Wlan.enabled": "off",
                        "lldp.eth0.port.mac": "00:00:00:00:00:01",
@@ -150,6 +152,7 @@ def test_forced_management_address(lldpd1, lldpd, lldpcli, namespaces):
     with namespaces(1):
         out = lldpcli("-f", "keyvalue", "show", "neighbors")
         assert out["lldp.eth0.chassis.mgmt-ip"] == "2001:db8::47"
+        assert out["lldp.eth0.chassis.mgmt-iface"] == "0"
 
 
 def test_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
@@ -162,6 +165,7 @@ def test_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
     with namespaces(1):
         out = lldpcli("-f", "keyvalue", "show", "neighbors")
         assert out["lldp.eth0.chassis.mgmt-ip"] == "172.25.21.47"
+        assert out["lldp.eth0.chassis.mgmt-iface"] == "2"
 
 
 def test_change_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
@@ -176,6 +180,7 @@ def test_change_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
     with namespaces(1):
         out = lldpcli("-f", "keyvalue", "show", "neighbors")
         assert out["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.2"
+        assert out["lldp.eth0.chassis.mgmt-iface"] == "2"
     with namespaces(2):
         ipr.addr('del', index=idx, address="192.168.14.2", mask=24)
         ipr.addr('add', index=idx, address="192.168.14.5", mask=24)
@@ -183,6 +188,7 @@ def test_change_management_address(lldpd1, lldpd, lldpcli, links, namespaces):
     with namespaces(1):
         out = lldpcli("-f", "keyvalue", "show", "neighbors")
         assert out["lldp.eth0.chassis.mgmt-ip"] == "192.168.14.5"
+        assert out["lldp.eth0.chassis.mgmt-iface"] == "2"
 
 
 def test_portid_subtype_ifname(lldpd1, lldpd, lldpcli, namespaces):
index 5502da27e3941bf759bc8ec2635f556eb3505470..8949d6f64eb17717ecea49ac3c77738e95e5e16c 100644 (file)
@@ -26,6 +26,7 @@ Interface:    eth0, via: LLDP, RID: 1, Time: 0 day, 00:00:{seconds}
     SysName:      ns-2.example.com
     SysDescr:     Spectacular GNU/Linux 2016 {uname}
     MgmtIP:       fe80::200:ff:fe00:2
+    MgmtIface:    2
     Capability:   Bridge, off
     Capability:   Router, {router}
     Capability:   Wlan, off
@@ -46,6 +47,7 @@ Interface:    eth0, via: unknown, Time: {time}
     SysName:      ns-1.example.com
     SysDescr:     Spectacular GNU/Linux 2016 {uname}
     MgmtIP:       fe80::200:ff:fe00:1
+    MgmtIface:    3
     Capability:   Bridge, off
     Capability:   Router, {router}
     Capability:   Wlan, off
@@ -110,6 +112,7 @@ def test_text_output(lldpd1, lldpd, lldpcli, namespaces, uname, command,
                   "value": "00:00:00:00:00:02"},
                 "descr": "Spectacular GNU/Linux 2016 {}".format(uname),
                 "mgmt-ip": "fe80::200:ff:fe00:2",
+                "mgmt-iface": "2",
                 "capability": [
                   {"type": "Bridge", "enabled": False},
                   {"type": "Wlan", "enabled": False},]}},
@@ -131,6 +134,7 @@ def test_text_output(lldpd1, lldpd, lldpcli, namespaces, uname, command,
                   "value": "00:00:00:00:00:01"},
                 "descr": "Spectacular GNU/Linux 2016 {}".format(uname),
                 "mgmt-ip": "fe80::200:ff:fe00:1",
+                "mgmt-iface": "3",
                 "capability": [
                   {"type": "Bridge", "enabled": False},
                   {"type": "Wlan", "enabled": False},]}},
@@ -187,6 +191,7 @@ def test_json_output(lldpd1, lldpd, lldpcli, namespaces, uname, command,
                     "name": [{"value": "ns-2.example.com"}],
                     "descr": [{"value": "Spectacular GNU/Linux 2016 {}".format(uname)}],
                     "mgmt-ip": [{"value": "fe80::200:ff:fe00:2"}],
+                    "mgmt-iface": [{"value": "2"}],
                     "capability": [
                         {"type": "Bridge", "enabled": False},
                         {"type": "Wlan", "enabled": False},
@@ -215,6 +220,7 @@ def test_json_output(lldpd1, lldpd, lldpcli, namespaces, uname, command,
                     "name": [{"value": "ns-1.example.com"}],
                     "descr": [{"value": "Spectacular GNU/Linux 2016 {}".format(uname)}],
                     "mgmt-ip": [{"value": "fe80::200:ff:fe00:1"}],
+                    "mgmt-iface": [{"value": "3"}],
                     "capability": [
                         {"type": "Bridge", "enabled": False},
                         {"type": "Wlan", "enabled": False},
@@ -271,6 +277,7 @@ def test_json0_output(lldpd1, lldpd, lldpcli, namespaces, uname, command,
    <name label="SysName">ns-2.example.com</name>
    <descr label="SysDescr">Spectacular GNU/Linux 2016 {uname}</descr>
    <mgmt-ip label="MgmtIP">fe80::200:ff:fe00:2</mgmt-ip>
+   <mgmt-iface label="MgmtIface">2</mgmt-iface>
    <capability label="Capability" type="Bridge" enabled="off"/>
    <capability label="Capability" type="Router" enabled="{router}"/>
    <capability label="Capability" type="Wlan" enabled="off"/>
@@ -293,6 +300,7 @@ def test_json0_output(lldpd1, lldpd, lldpcli, namespaces, uname, command,
    <name label="SysName">ns-1.example.com</name>
    <descr label="SysDescr">Spectacular GNU/Linux 2016 {uname}</descr>
    <mgmt-ip label="MgmtIP">fe80::200:ff:fe00:1</mgmt-ip>
+   <mgmt-iface label="MgmtIface">3</mgmt-iface>
    <capability label="Capability" type="Bridge" enabled="off"/>
    <capability label="Capability" type="Router" enabled="{router}"/>
    <capability label="Capability" type="Wlan" enabled="off"/>