diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2015-09-22 15:19:42 +0200 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2015-09-22 15:19:42 +0200 |
commit | 9ef61f2e4802abdb4a2853a82126420b1e77b419 (patch) | |
tree | d4bb3f57e4b6828b9e8be1748a3dd2899481de63 | |
parent | 8955cf0a4586010f913bb7e0f8d05f1fc116c246 (diff) |
sd-lldp: hide internal details
Currently, sd-lldp.h exports "UPDATE_INFO".. and defines it to a magic
constant '10'. This is completely bogus, so fix it to follow our coding
standards:
- Prefix exported symbols by SD_LLDP_*
- Define a separate event-enum for event types
- Translate internal state to external event-types
-rw-r--r-- | src/libsystemd-network/sd-lldp.c | 12 | ||||
-rw-r--r-- | src/network/networkd-link.c | 15 | ||||
-rw-r--r-- | src/systemd/sd-lldp.h | 8 |
3 files changed, 22 insertions, 13 deletions
diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c index 574e04b541..17512884f5 100644 --- a/src/libsystemd-network/sd-lldp.c +++ b/src/libsystemd-network/sd-lldp.c @@ -366,10 +366,16 @@ static void lldp_set_state(sd_lldp *lldp, LLDPAgentRXState state) { } static void lldp_run_state_machine(sd_lldp *lldp) { + if (!lldp->cb) + return; - if (lldp->rx_state == LLDP_AGENT_RX_UPDATE_INFO) - if (lldp->cb) - lldp->cb(lldp, LLDP_AGENT_RX_UPDATE_INFO, lldp->userdata); + switch (lldp->rx_state) { + case LLDP_AGENT_RX_UPDATE_INFO: + lldp->cb(lldp, SD_LLDP_EVENT_UPDATE_INFO, lldp->userdata); + break; + default: + break; + } } /* 10.5.5.2.1 mibDeleteObjects () diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 215c47b8af..86f1c3bb1a 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1112,13 +1112,16 @@ static void lldp_handler(sd_lldp *lldp, int event, void *userdata) { assert(link->network); assert(link->manager); - if (event != UPDATE_INFO) - return; - - r = sd_lldp_save(link->lldp, link->lldp_file); - if (r < 0) - log_link_warning_errno(link, r, "Could not save LLDP: %m"); + switch (event) { + case SD_LLDP_EVENT_UPDATE_INFO: + r = sd_lldp_save(link->lldp, link->lldp_file); + if (r < 0) + log_link_warning_errno(link, r, "Could not save LLDP: %m"); + break; + default: + break; + } } static int link_acquire_conf(Link *link) { diff --git a/src/systemd/sd-lldp.h b/src/systemd/sd-lldp.h index 09551d4a1a..0680e526b0 100644 --- a/src/systemd/sd-lldp.h +++ b/src/systemd/sd-lldp.h @@ -24,14 +24,14 @@ #include "sd-event.h" +enum { + SD_LLDP_EVENT_UPDATE_INFO = 0, +}; + typedef struct sd_lldp sd_lldp; typedef void (*sd_lldp_cb_t)(sd_lldp *lldp, int event, void *userdata); -enum { - UPDATE_INFO = 10, -}; - int sd_lldp_new(int ifindex, const char *ifname, const struct ether_addr *mac, sd_lldp **ret); void sd_lldp_free(sd_lldp *lldp); |