From 8b5496481a187a84e4b6df1207faf516af01fbf0 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 6 Nov 2022 12:39:50 +0100 Subject: [PATCH] build: reformat code --- src/client/client.h | 101 +- src/client/commands.c | 286 ++-- src/client/conf-dot3.c | 10 +- src/client/conf-inv.c | 256 ++-- src/client/conf-lldp.c | 632 ++++---- src/client/conf-med.c | 475 +++--- src/client/conf-power.c | 376 ++--- src/client/conf-system.c | 519 +++---- src/client/conf.c | 14 +- src/client/display.c | 530 +++---- src/client/json_writer.c | 130 +- src/client/kv_writer.c | 33 +- src/client/lldpcli.c | 197 ++- src/client/misc.c | 13 +- src/client/show.c | 223 ++- src/client/text_writer.c | 52 +- src/client/tokenizer.c | 45 +- src/client/utf8.c | 74 +- src/client/writer.h | 29 +- src/client/xml_writer.c | 75 +- src/compat/asprintf.c | 13 +- src/compat/compat.h | 14 +- src/compat/daemon.c | 9 +- src/compat/getline.c | 29 +- src/compat/malloc.c | 2 +- src/compat/strlcpy.c | 8 +- src/compat/strndup.c | 4 +- src/compat/strnlen.c | 2 +- src/compat/strtonum.c | 23 +- src/compat/vsyslog.c | 3 +- src/ctl.c | 38 +- src/ctl.h | 40 +- src/daemon/agent.c | 1672 ++++++++++----------- src/daemon/agent.h | 34 +- src/daemon/agent_priv.c | 113 +- src/daemon/bitmap.c | 6 +- src/daemon/client.c | 220 +-- src/daemon/dmi-dummy.c | 12 +- src/daemon/dmi-freebsd.c | 35 +- src/daemon/dmi-linux.c | 38 +- src/daemon/dmi-openbsd.c | 25 +- src/daemon/dmi-osx.c | 33 +- src/daemon/event.c | 297 ++-- src/daemon/forward-bsd.c | 13 +- src/daemon/forward-linux.c | 12 +- src/daemon/forward-solaris.c | 3 +- src/daemon/frame.c | 9 +- src/daemon/frame.h | 123 +- src/daemon/interfaces-bpf.c | 38 +- src/daemon/interfaces-bsd.c | 467 +++--- src/daemon/interfaces-linux.c | 496 +++--- src/daemon/interfaces-solaris.c | 56 +- src/daemon/interfaces.c | 353 ++--- src/daemon/lldp-tlv.h | 101 +- src/daemon/lldpd.c | 818 +++++----- src/daemon/lldpd.h | 385 +++-- src/daemon/netlink.c | 324 ++-- src/daemon/pattern.c | 9 +- src/daemon/priv-bsd.c | 62 +- src/daemon/priv-linux.c | 118 +- src/daemon/priv-seccomp.c | 62 +- src/daemon/priv.c | 213 ++- src/daemon/privsep.c | 8 +- src/daemon/privsep_fd.c | 13 +- src/daemon/privsep_io.c | 15 +- src/daemon/protocols/cdp.c | 511 +++---- src/daemon/protocols/cdp.h | 57 +- src/daemon/protocols/edp.c | 352 +++-- src/daemon/protocols/edp.h | 24 +- src/daemon/protocols/lldp.c | 827 +++++----- src/daemon/protocols/sonmp.c | 449 +++--- src/daemon/protocols/sonmp.h | 12 +- src/daemon/trace.h | 10 +- src/lib/atom.c | 247 ++- src/lib/atom.h | 144 +- src/lib/atoms/chassis.c | 146 +- src/lib/atoms/config.c | 148 +- src/lib/atoms/custom.c | 94 +- src/lib/atoms/dot1.c | 149 +- src/lib/atoms/dot3.c | 104 +- src/lib/atoms/interface.c | 42 +- src/lib/atoms/med.c | 368 +++-- src/lib/atoms/mgmt.c | 58 +- src/lib/atoms/port.c | 685 +++++---- src/lib/connection.c | 79 +- src/lib/errors.c | 46 +- src/lib/fixedpoint.c | 85 +- src/lib/fixedpoint.h | 6 +- src/lib/helpers.c | 8 +- src/lib/helpers.h | 1 - src/lib/lldpctl.h | 374 +++-- src/lldp-const.h | 551 +++---- src/lldpd-structs.c | 50 +- src/lldpd-structs.h | 457 +++--- src/log.c | 107 +- src/log.h | 22 +- src/marshal.c | 167 +- src/marshal.h | 167 +- src/version.c | 45 +- tests/check-compat.h | 18 +- tests/check_bitmap.c | 11 +- tests/check_cdp.c | 585 ++++--- tests/check_edp.c | 633 ++++---- tests/check_fixedpoint.c | 86 +- tests/check_lldp.c | 602 ++++---- tests/check_marshal.c | 122 +- tests/check_pattern.c | 27 +- tests/check_snmp.c | 1110 +++++++------- tests/check_sonmp.c | 92 +- tests/common.c | 19 +- tests/common.h | 8 +- tests/decode.c | 136 +- tests/integration/conftest.py | 6 +- tests/integration/fixtures/namespaces.py | 106 +- tests/integration/fixtures/network.py | 92 +- tests/integration/fixtures/programs.py | 406 ++--- tests/integration/test_basic.py | 276 ++-- tests/integration/test_configinventory.py | 90 +- tests/integration/test_custom.py | 161 +- tests/integration/test_dot1.py | 29 +- tests/integration/test_dot3.py | 114 +- tests/integration/test_interfaces.py | 352 ++--- tests/integration/test_lldpcli.py | 836 ++++++----- tests/integration/test_med.py | 224 +-- tests/integration/test_pcap.py | 157 +- tests/integration/test_protocols.py | 32 +- tests/integration/test_snmp.py | 23 +- tests/pcap-hdr.h | 22 +- 128 files changed, 11461 insertions(+), 11944 deletions(-) diff --git a/src/client/client.h b/src/client/client.h index 78a074e2..2b2a6a78 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -30,10 +30,10 @@ #include "writer.h" #ifdef HAVE_ADDRESS_SANITIZER -# include -# define SUPPRESS_LEAK(x) __lsan_ignore_object(x) +# include +# define SUPPRESS_LEAK(x) __lsan_ignore_object(x) #else -# define SUPPRESS_LEAK(x) +# define SUPPRESS_LEAK(x) #endif /* Readline stuff */ @@ -46,9 +46,9 @@ extern char *readline(); extern char *rl_line_buffer; extern int rl_point; -extern int rl_insert_text(const char*); +extern int rl_insert_text(const char *); extern void rl_forced_update_display(void); -extern int rl_bind_key(int, int(*f)(int, int)); +extern int rl_bind_key(int, int (*f)(int, int)); # endif #endif #ifdef HAVE_READLINE_HISTORY @@ -57,7 +57,7 @@ extern int rl_bind_key(int, int(*f)(int, int)); # elif defined(HAVE_HISTORY_H) # include # else -extern void add_history (); +extern void add_history(); # endif #endif #undef NEWLINE @@ -69,75 +69,60 @@ extern const char *ctlname; struct cmd_node; struct cmd_env; struct cmd_node *commands_root(void); -struct cmd_node *commands_new( - struct cmd_node *, - const char *, - const char *, - int(*validate)(struct cmd_env*, void *), - int(*execute)(struct lldpctl_conn_t*, struct writer*, - struct cmd_env*, void *), - void *); -struct cmd_node* commands_privileged(struct cmd_node *); -struct cmd_node* commands_lock(struct cmd_node *); -struct cmd_node* commands_hidden(struct cmd_node *); +struct cmd_node *commands_new(struct cmd_node *, const char *, const char *, + int (*validate)(struct cmd_env *, void *), + int (*execute)(struct lldpctl_conn_t *, struct writer *, struct cmd_env *, void *), + void *); +struct cmd_node *commands_privileged(struct cmd_node *); +struct cmd_node *commands_lock(struct cmd_node *); +struct cmd_node *commands_hidden(struct cmd_node *); void commands_free(struct cmd_node *); -const char *cmdenv_arg(struct cmd_env*); -const char *cmdenv_get(struct cmd_env*, const char*); -int cmdenv_put(struct cmd_env*, const char*, const char*); -int cmdenv_pop(struct cmd_env*, int); -int commands_execute(struct lldpctl_conn_t *, struct writer *, - struct cmd_node *, int, const char **, int); -char *commands_complete(struct cmd_node *, int, const char **, - int, int); +const char *cmdenv_arg(struct cmd_env *); +const char *cmdenv_get(struct cmd_env *, const char *); +int cmdenv_put(struct cmd_env *, const char *, const char *); +int cmdenv_pop(struct cmd_env *, int); +int commands_execute(struct lldpctl_conn_t *, struct writer *, struct cmd_node *, int, + const char **, int); +char *commands_complete(struct cmd_node *, int, const char **, int, int); /* helpers */ int cmd_check_no_env(struct cmd_env *, void *); int cmd_check_env(struct cmd_env *, void *); -int cmd_store_env(struct lldpctl_conn_t *, struct writer *, - struct cmd_env *, void *); -int cmd_store_env_and_pop(struct lldpctl_conn_t *, struct writer *, - struct cmd_env *, void *); -int cmd_store_env_value(struct lldpctl_conn_t *, struct writer *, - struct cmd_env *, void *); +int cmd_store_env(struct lldpctl_conn_t *, struct writer *, struct cmd_env *, void *); +int cmd_store_env_and_pop(struct lldpctl_conn_t *, struct writer *, struct cmd_env *, + void *); +int cmd_store_env_value(struct lldpctl_conn_t *, struct writer *, struct cmd_env *, + void *); int cmd_store_env_value_and_pop(struct lldpctl_conn_t *, struct writer *, struct cmd_env *, void *); int cmd_store_env_value_and_pop2(struct lldpctl_conn_t *, struct writer *, struct cmd_env *, void *); int cmd_store_env_value_and_pop3(struct lldpctl_conn_t *, struct writer *, struct cmd_env *, void *); -int cmd_store_something_env_value_and_pop2(const char *, struct cmd_env *, - void *); -int cmd_store_something_env_value(const char *, struct cmd_env *, - void *); -lldpctl_atom_t* cmd_iterate_on_interfaces(struct lldpctl_conn_t *, - struct cmd_env *); -lldpctl_atom_t* cmd_iterate_on_ports(struct lldpctl_conn_t *, - struct cmd_env *, const char **); +int cmd_store_something_env_value_and_pop2(const char *, struct cmd_env *, void *); +int cmd_store_something_env_value(const char *, struct cmd_env *, void *); +lldpctl_atom_t *cmd_iterate_on_interfaces(struct lldpctl_conn_t *, struct cmd_env *); +lldpctl_atom_t *cmd_iterate_on_ports(struct lldpctl_conn_t *, struct cmd_env *, + const char **); void cmd_restrict_ports(struct cmd_node *); void cmd_restrict_protocol(struct cmd_node *); /* misc.c */ int contains(const char *, const char *); -char* totag(const char *); +char *totag(const char *); /* display.c */ -#define DISPLAY_BRIEF 1 -#define DISPLAY_NORMAL 2 +#define DISPLAY_BRIEF 1 +#define DISPLAY_NORMAL 2 #define DISPLAY_DETAILS 3 -void display_interfaces(lldpctl_conn_t *, struct writer *, - struct cmd_env *, int, int); -void display_interface(lldpctl_conn_t *, struct writer *, int, - lldpctl_atom_t *, lldpctl_atom_t *, int, int); -void display_local_chassis(lldpctl_conn_t *, struct writer *, - struct cmd_env *, int); +void display_interfaces(lldpctl_conn_t *, struct writer *, struct cmd_env *, int, int); +void display_interface(lldpctl_conn_t *, struct writer *, int, lldpctl_atom_t *, + lldpctl_atom_t *, int, int); +void display_local_chassis(lldpctl_conn_t *, struct writer *, struct cmd_env *, int); void display_configuration(lldpctl_conn_t *, struct writer *); -void display_interfaces_stats(lldpctl_conn_t *, struct writer *, - struct cmd_env *); -void display_interface_stats(lldpctl_conn_t *, struct writer *, - lldpctl_atom_t *); -void display_local_interfaces(lldpctl_conn_t *, struct writer *, - struct cmd_env *, int, int); - - +void display_interfaces_stats(lldpctl_conn_t *, struct writer *, struct cmd_env *); +void display_interface_stats(lldpctl_conn_t *, struct writer *, lldpctl_atom_t *); +void display_local_interfaces(lldpctl_conn_t *, struct writer *, struct cmd_env *, int, + int); /* show.c */ void register_commands_show(struct cmd_node *); @@ -154,7 +139,7 @@ void register_commands_medpow(struct cmd_node *); void register_commands_dot3pow(struct cmd_node *); /* tokenizer.c */ -int tokenize_line(const char*, int*, char***); -void tokenize_free(int, char**); +int tokenize_line(const char *, int *, char ***); +void tokenize_free(int, char **); #endif diff --git a/src/client/commands.c b/src/client/commands.c index e6bd349e..4766c880 100644 --- a/src/client/commands.c +++ b/src/client/commands.c @@ -52,9 +52,9 @@ struct cmd_env_stack { struct cmd_env { TAILQ_HEAD(, cmd_env_el) elements; /**< List of environment variables */ TAILQ_HEAD(, cmd_env_stack) stack; /**< Stack */ - int argc; /**< Number of argument in the command */ - int argp; /**< Current argument */ - const char **argv; /**< Arguments */ + int argc; /**< Number of argument in the command */ + int argp; /**< Current argument */ + const char **argv; /**< Arguments */ }; /** @@ -71,24 +71,24 @@ struct cmd_env { struct cmd_node { TAILQ_ENTRY(cmd_node) next; /**< Next sibling */ - const char *token; /**< Token to enter this cnode */ - const char *doc; /**< Documentation string */ - int privileged; /**< Privileged command? */ - int lock; /**< Lock required for execution? */ - int hidden; /**< Hidden command? */ + const char *token; /**< Token to enter this cnode */ + const char *doc; /**< Documentation string */ + int privileged; /**< Privileged command? */ + int lock; /**< Lock required for execution? */ + int hidden; /**< Hidden command? */ /** * Function validating entry in this node. Can be @c NULL. */ - int(*validate)(struct cmd_env*, void *); + int (*validate)(struct cmd_env *, void *); /** * Function to execute when entering this node. May be @c NULL. * * This function can alter the environment */ - int(*execute)(struct lldpctl_conn_t*, struct writer*, - struct cmd_env*, void *); - void *arg; /**< Magic argument for the previous two functions */ + int (*execute)(struct lldpctl_conn_t *, struct writer *, struct cmd_env *, + void *); + void *arg; /**< Magic argument for the previous two functions */ /* List of possible subentries */ TAILQ_HEAD(, cmd_node) subentries; /* List of subnodes */ @@ -99,7 +99,7 @@ struct cmd_node { * * @return the root node. */ -struct cmd_node* +struct cmd_node * commands_root(void) { struct cmd_node *new = calloc(1, sizeof(struct cmd_node)); @@ -116,7 +116,7 @@ commands_root(void) * * The node is modified. It is returned to ease chaining. */ -struct cmd_node* +struct cmd_node * commands_privileged(struct cmd_node *node) { if (node) node->privileged = 1; @@ -131,7 +131,7 @@ commands_privileged(struct cmd_node *node) * * The node is modified. It is returned to ease chaining. */ -struct cmd_node* +struct cmd_node * commands_lock(struct cmd_node *node) { if (node) node->lock = 1; @@ -146,7 +146,7 @@ commands_lock(struct cmd_node *node) * * The node is modified. It is returned to ease chaining. */ -struct cmd_node* +struct cmd_node * commands_hidden(struct cmd_node *node) { if (node) node->hidden = 1; @@ -164,17 +164,14 @@ commands_hidden(struct cmd_node *node) * @param arg Magic argument for precedent functions. * @return the newly created node */ -struct cmd_node* -commands_new(struct cmd_node *root, - const char *token, const char *doc, - int(*validate)(struct cmd_env*, void *), - int(*execute)(struct lldpctl_conn_t*, struct writer*, - struct cmd_env*, void *), +struct cmd_node * +commands_new(struct cmd_node *root, const char *token, const char *doc, + int (*validate)(struct cmd_env *, void *), + int (*execute)(struct lldpctl_conn_t *, struct writer *, struct cmd_env *, void *), void *arg) { struct cmd_node *new = calloc(1, sizeof(struct cmd_node)); - if (new == NULL) - fatalx("lldpctl", "out of memory"); + if (new == NULL) fatalx("lldpctl", "out of memory"); new->token = token; new->doc = doc; new->validate = validate; @@ -210,13 +207,11 @@ commands_free(struct cmd_node *root) * @param env The environment. * @return current argument. */ -const char* +const char * cmdenv_arg(struct cmd_env *env) { - if (env->argp < env->argc) - return env->argv[env->argp]; - if (env->argp == env->argc) - return NEWLINE; + if (env->argp < env->argc) return env->argv[env->argp]; + if (env->argp == env->argc) return NEWLINE; return NULL; } @@ -228,13 +223,12 @@ cmdenv_arg(struct cmd_env *env) * @return @c NULL if not found or the requested value otherwise. If no value is * associated, return the key. */ -const char* +const char * cmdenv_get(struct cmd_env *env, const char *key) { struct cmd_env_el *el; - TAILQ_FOREACH(el, &env->elements, next) - if (!strcmp(el->key, key)) - return el->value ? el->value : el->key; + TAILQ_FOREACH (el, &env->elements, next) + if (!strcmp(el->key, key)) return el->value ? el->value : el->key; return NULL; } @@ -247,12 +241,12 @@ cmdenv_get(struct cmd_env *env, const char *key) * @return 0 on success, -1 otherwise. */ int -cmdenv_put(struct cmd_env *env, - const char *key, const char *value) +cmdenv_put(struct cmd_env *env, const char *key, const char *value) { struct cmd_env_el *el = malloc(sizeof(struct cmd_env_el)); if (el == NULL) { - log_warn("lldpctl", "unable to allocate memory for new environment variable"); + log_warn("lldpctl", + "unable to allocate memory for new environment variable"); return -1; } el->key = key; @@ -280,8 +274,7 @@ cmdenv_pop(struct cmd_env *env, int n) return -1; } struct cmd_env_stack *first = TAILQ_FIRST(&env->stack); - TAILQ_REMOVE(&env->stack, - first, next); + TAILQ_REMOVE(&env->stack, first, next); free(first); } return 0; @@ -313,7 +306,7 @@ cmdenv_push(struct cmd_env *env, struct cmd_node *node) * @param env The environment. * @return the top element or @c NULL is the stack is empty. */ -static struct cmd_node* +static struct cmd_node * cmdenv_top(struct cmd_env *env) { if (TAILQ_EMPTY(&env->stack)) return NULL; @@ -328,7 +321,8 @@ cmdenv_top(struct cmd_env *env) static void cmdenv_free(struct cmd_env *env) { - while (!TAILQ_EMPTY(&env->stack)) cmdenv_pop(env, 1); + while (!TAILQ_EMPTY(&env->stack)) + cmdenv_pop(env, 1); struct cmd_env_el *first; while (!TAILQ_EMPTY(&env->elements)) { @@ -354,38 +348,35 @@ struct candidate_word { * @param argc Number of arguments. * @param argv Array of arguments. * @param word Completed word. Or NULL when no completion is required. - * @param all When completing, display possible completions even if only one choice is possible. + * @param all When completing, display possible completions even if only one choice + * is possible. * @param priv Is the current user privileged? * @return 0 on success, -1 otherwise. */ static int -_commands_execute(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_node *root, int argc, const char **argv, - char **word, int all, int priv) +_commands_execute(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_node *root, + int argc, const char **argv, char **word, int all, int priv) { int n, rc = 0, completion = (word != NULL); - int help = 0; /* Are we asking for help? */ - int complete = 0; /* Are we asking for possible completions? */ - int needlock = 0; /* Do we need a lock? */ - struct cmd_env env = { - .elements = TAILQ_HEAD_INITIALIZER(env.elements), + int help = 0; /* Are we asking for help? */ + int complete = 0; /* Are we asking for possible completions? */ + int needlock = 0; /* Do we need a lock? */ + struct cmd_env env = { .elements = TAILQ_HEAD_INITIALIZER(env.elements), .stack = TAILQ_HEAD_INITIALIZER(env.stack), .argc = argc, .argv = argv, - .argp = 0 - }; + .argp = 0 }; static int lockfd = -1; - static char *lockname = NULL; /* Name of lockfile */ + static char *lockname = NULL; /* Name of lockfile */ cmdenv_push(&env, root); if (!completion) for (n = 0; n < argc; n++) log_debug("lldpctl", "argument %02d: `%s`", n, argv[n]); if (completion) *word = NULL; -#define CAN_EXECUTE(candidate) \ - ((!candidate->privileged || priv || complete) && \ - (!candidate->validate || \ - candidate->validate(&env, candidate->arg) == 1)) +#define CAN_EXECUTE(candidate) \ + ((!candidate->privileged || priv || complete) && \ + (!candidate->validate || candidate->validate(&env, candidate->arg) == 1)) /* When completion is in progress, we use the same algorithm than for * execution until we reach the cursor position. */ @@ -397,15 +388,14 @@ _commands_execute(struct lldpctl_conn_t *conn, struct writer *w, } struct cmd_node *candidate, *best = NULL; - const char *token = (env.argp < env.argc) ? env.argv[env.argp] : - (env.argp == env.argc && !help && !complete) ? NEWLINE : NULL; - if (token == NULL || - (completion && env.argp == env.argc - 1)) - goto end; + const char *token = (env.argp < env.argc) ? env.argv[env.argp] : + (env.argp == env.argc && !help && !complete) ? NEWLINE : + NULL; + if (token == NULL || (completion && env.argp == env.argc - 1)) goto end; if (!completion) - log_debug("lldpctl", "process argument %02d: `%s`", - env.argp, token); - TAILQ_FOREACH(candidate, ¤t->subentries, next) { + log_debug("lldpctl", "process argument %02d: `%s`", env.argp, + token); + TAILQ_FOREACH (candidate, ¤t->subentries, next) { if (candidate->token && !strncmp(candidate->token, token, strlen(token)) && CAN_EXECUTE(candidate)) { @@ -416,11 +406,14 @@ _commands_execute(struct lldpctl_conn_t *conn, struct writer *w, needlock = needlock || candidate->lock; break; } - if (!best) best = candidate; + if (!best) + best = candidate; else { if (!completion) - log_warnx("lldpctl", "ambiguous token: %s (%s or %s)", - token, candidate->token, best->token); + log_warnx("lldpctl", + "ambiguous token: %s (%s or %s)", + token, candidate->token, + best->token); rc = -1; goto end; } @@ -428,9 +421,8 @@ _commands_execute(struct lldpctl_conn_t *conn, struct writer *w, } if (!best) { /* Take first that validate */ - TAILQ_FOREACH(candidate, ¤t->subentries, next) { - if (!candidate->token && - CAN_EXECUTE(candidate)) { + TAILQ_FOREACH (candidate, ¤t->subentries, next) { + if (!candidate->token && CAN_EXECUTE(candidate)) { best = candidate; needlock = needlock || candidate->lock; break; @@ -440,7 +432,8 @@ _commands_execute(struct lldpctl_conn_t *conn, struct writer *w, if (!best && env.argp == env.argc) goto end; if (!best) { if (!completion) - log_warnx("lldpctl", "unknown command from argument %d: `%s`", + log_warnx("lldpctl", + "unknown command from argument %d: `%s`", env.argp + 1, token); rc = -1; goto end; @@ -452,31 +445,36 @@ _commands_execute(struct lldpctl_conn_t *conn, struct writer *w, if (needlock) { if (lockfd == -1) { if (lockname == NULL && - asprintf(&lockname, "%s.lock", - ctlname) == -1) { + asprintf(&lockname, "%s.lock", ctlname) == + -1) { log_warnx("lldpctl", "not enough memory to build lock filename"); rc = -1; goto end; } - log_debug("lldpctl", "open %s for locking", lockname); + log_debug("lldpctl", "open %s for locking", + lockname); if ((lockfd = open(lockname, O_RDWR)) == -1) { - log_warn("lldpctl", "cannot open lock %s", lockname); + log_warn("lldpctl", + "cannot open lock %s", lockname); rc = -1; goto end; } } if (lockf(lockfd, F_LOCK, 0) == -1) { - log_warn("lldpctl", "cannot get lock on %s", lockname); + log_warn("lldpctl", "cannot get lock on %s", + lockname); rc = -1; - close(lockfd); lockfd = -1; + close(lockfd); + lockfd = -1; goto end; } } rc = best->execute(conn, w, &env, best->arg) != 1 ? -1 : rc; if (needlock && lockf(lockfd, F_ULOCK, 0) == -1) { log_warn("lldpctl", "cannot unlock %s", lockname); - close(lockfd); lockfd = -1; + close(lockfd); + lockfd = -1; } if (rc == -1) goto end; } @@ -496,10 +494,11 @@ end: TAILQ_INIT(&words); current = cmdenv_top(&env); if (!TAILQ_EMPTY(¤t->subentries)) { - TAILQ_FOREACH(candidate, ¤t->subentries, next) { + TAILQ_FOREACH (candidate, ¤t->subentries, next) { if ((!candidate->token || help || complete || - !strncmp(env.argv[env.argc - 1], candidate->token, - strlen(env.argv[env.argc -1 ]))) && + !strncmp(env.argv[env.argc - 1], + candidate->token, + strlen(env.argv[env.argc - 1]))) && CAN_EXECUTE(candidate)) { struct candidate_word *cword = malloc(sizeof(struct candidate_word)); @@ -517,17 +516,19 @@ end: /* Search if there is a common prefix, then return it. */ char prefix[maxl + 2]; /* Extra space may be added at the end */ struct candidate_word *cword, *cword_next; - memset(prefix, 0, maxl+2); + memset(prefix, 0, maxl + 2); for (size_t n = 0; n < maxl; n++) { int c = 1; /* Set to 0 to exit outer loop */ - TAILQ_FOREACH(cword, &words, next) { + TAILQ_FOREACH (cword, &words, next) { c = 0; if (cword->hidden) continue; if (cword->word == NULL) break; if (!strcmp(cword->word, NEWLINE)) break; if (strlen(cword->word) == n) break; - if (prefix[n] == '\0') prefix[n] = cword->word[n]; - else if (prefix[n] != cword->word[n]) break; + if (prefix[n] == '\0') + prefix[n] = cword->word[n]; + else if (prefix[n] != cword->word[n]) + break; c = 1; } if (c == 0) { @@ -539,9 +540,10 @@ end: * just return it as is. */ if (!all && !help && !complete && strcmp(prefix, NEWLINE) && strlen(prefix) > 0 && - strlen(env.argv[env.argc-1]) < strlen(prefix)) { - TAILQ_FOREACH(cword, &words, next) { - if (cword->word && !strcmp(prefix, cword->word)) { + strlen(env.argv[env.argc - 1]) < strlen(prefix)) { + TAILQ_FOREACH (cword, &words, next) { + if (cword->word && + !strcmp(prefix, cword->word)) { prefix[strlen(prefix)] = ' '; break; } @@ -552,23 +554,24 @@ end: if (!complete) fprintf(stderr, "\n-- \033[1;34m%s\033[0m\n", current->doc ? current->doc : "Help"); - TAILQ_FOREACH(cword, &words, next) { + TAILQ_FOREACH (cword, &words, next) { if (cword->hidden) continue; char fmt[100]; if (!complete) { snprintf(fmt, sizeof(fmt), - "%s%%%ds%s %%s\n", - "\033[1m", (int)maxl, "\033[0m"); + "%s%%%ds%s %%s\n", "\033[1m", + (int)maxl, "\033[0m"); fprintf(stderr, fmt, cword->word ? cword->word : "WORD", - cword->doc ? cword->doc : "..."); + cword->doc ? cword->doc : "..."); } else { - if (!cword->word || !strcmp(cword->word, NEWLINE)) + if (!cword->word || + !strcmp(cword->word, NEWLINE)) continue; fprintf(stdout, "%s %s\n", cword->word ? cword->word : "WORD", - cword->doc ? cword->doc : "..."); + cword->doc ? cword->doc : "..."); } } } @@ -588,12 +591,12 @@ end: * Complete the given command. */ char * -commands_complete(struct cmd_node *root, int argc, const char **argv, - int all, int privileged) +commands_complete(struct cmd_node *root, int argc, const char **argv, int all, + int privileged) { char *word = NULL; - if (_commands_execute(NULL, NULL, root, argc, argv, - &word, all, privileged) == 0) + if (_commands_execute(NULL, NULL, root, argc, argv, &word, all, privileged) == + 0) return word; return NULL; } @@ -602,8 +605,8 @@ commands_complete(struct cmd_node *root, int argc, const char **argv, * Execute the given commands. */ int -commands_execute(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_node *root, int argc, const char **argv, int privileged) +commands_execute(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_node *root, + int argc, const char **argv, int privileged) { return _commands_execute(conn, w, root, argc, argv, NULL, 0, privileged); } @@ -618,7 +621,7 @@ commands_execute(struct lldpctl_conn_t *conn, struct writer *w, int cmd_check_no_env(struct cmd_env *env, void *key) { - return cmdenv_get(env, (const char*)key) == NULL; + return cmdenv_get(env, (const char *)key) == NULL; } /** @@ -634,11 +637,13 @@ cmd_check_env(struct cmd_env *env, void *key) struct cmd_env_el *el; const char *list = key; int count = 0; - TAILQ_FOREACH(el, &env->elements, next) { - if (contains(list, el->key)) - count++; + TAILQ_FOREACH (el, &env->elements, next) { + if (contains(list, el->key)) count++; + } + while ((list = strchr(list, ','))) { + list++; + count--; } - while ((list = strchr(list, ','))) { list++; count--; } return (count == 1); } @@ -652,8 +657,8 @@ cmd_check_env(struct cmd_env *env, void *key) * @return 1 if the key was stored */ int -cmd_store_env(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *key) +cmd_store_env(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *key) { return cmdenv_put(env, key, NULL) != -1; } @@ -671,8 +676,7 @@ int cmd_store_env_and_pop(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *key) { - return (cmd_store_env(conn, w, env, key) != -1 && - cmdenv_pop(env, 1) != -1); + return (cmd_store_env(conn, w, env, key) != -1 && cmdenv_pop(env, 1) != -1); } /** @@ -689,19 +693,19 @@ int cmd_store_env_value_and_pop(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *key) { - return (cmdenv_put(env, key, cmdenv_arg(env)) != -1 && - cmdenv_pop(env, 1) != -1); + return ( + cmdenv_put(env, key, cmdenv_arg(env)) != -1 && cmdenv_pop(env, 1) != -1); } int cmd_store_env_value_and_pop2(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *key) { - return (cmdenv_put(env, key, cmdenv_arg(env)) != -1 && - cmdenv_pop(env, 2) != -1); + return ( + cmdenv_put(env, key, cmdenv_arg(env)) != -1 && cmdenv_pop(env, 2) != -1); } int -cmd_store_env_value(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *key) +cmd_store_env_value(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *key) { return (cmdenv_put(env, key, cmdenv_arg(env)) != -1); } @@ -709,19 +713,17 @@ int cmd_store_env_value_and_pop3(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *key) { - return (cmdenv_put(env, key, cmdenv_arg(env)) != -1 && - cmdenv_pop(env, 3) != -1); + return ( + cmdenv_put(env, key, cmdenv_arg(env)) != -1 && cmdenv_pop(env, 3) != -1); } int -cmd_store_something_env_value_and_pop2(const char *what, - struct cmd_env *env, void *value) +cmd_store_something_env_value_and_pop2(const char *what, struct cmd_env *env, + void *value) { - return (cmdenv_put(env, what, value) != -1 && - cmdenv_pop(env, 2) != -1); + return (cmdenv_put(env, what, value) != -1 && cmdenv_pop(env, 2) != -1); } int -cmd_store_something_env_value(const char *what, - struct cmd_env *env, void *value) +cmd_store_something_env_value(const char *what, struct cmd_env *env, void *value) { return (cmdenv_put(env, what, value) != -1); } @@ -738,7 +740,7 @@ cmd_store_something_env_value(const char *what, * @return The next interface in the set of ports (or in all ports if no `ports` * variable is present in the environment) */ -lldpctl_atom_t* +lldpctl_atom_t * cmd_iterate_on_interfaces(struct lldpctl_conn_t *conn, struct cmd_env *env) { static lldpctl_atom_iter_t *iter = NULL; @@ -750,7 +752,8 @@ cmd_iterate_on_interfaces(struct lldpctl_conn_t *conn, struct cmd_env *env) if (iter == NULL) { iface_list = lldpctl_get_interfaces(conn); if (!iface_list) { - log_warnx("lldpctl", "not able to get the list of interfaces. %s", + log_warnx("lldpctl", + "not able to get the list of interfaces. %s", lldpctl_last_strerror(conn)); return NULL; } @@ -769,7 +772,8 @@ cmd_iterate_on_interfaces(struct lldpctl_conn_t *conn, struct cmd_env *env) } iface = lldpctl_atom_iter_value(iface_list, iter); - } while (interfaces && !contains(interfaces, + } while (interfaces && + !contains(interfaces, lldpctl_atom_get_str(iface, lldpctl_k_interface_name))); return iface; @@ -790,8 +794,9 @@ cmd_iterate_on_interfaces(struct lldpctl_conn_t *conn, struct cmd_env *env) * variable is present in the environment), including the default port * if no `ports` variable is present in the environment. */ -lldpctl_atom_t* -cmd_iterate_on_ports(struct lldpctl_conn_t *conn, struct cmd_env *env, const char **name) +lldpctl_atom_t * +cmd_iterate_on_ports(struct lldpctl_conn_t *conn, struct cmd_env *env, + const char **name) { static int put_default = 0; static lldpctl_atom_t *last_port = NULL; @@ -828,14 +833,11 @@ void cmd_restrict_ports(struct cmd_node *root) { /* Restrict to some ports. */ - commands_new( - commands_new(root, - "ports", - "Restrict configuration to some ports", - cmd_check_no_env, NULL, "ports"), - NULL, - "Restrict configuration to the specified ports (comma-separated list)", - NULL, cmd_store_env_value_and_pop2, "ports"); + commands_new(commands_new(root, "ports", "Restrict configuration to some ports", + cmd_check_no_env, NULL, "ports"), + NULL, + "Restrict configuration to the specified ports (comma-separated list)", + NULL, cmd_store_env_value_and_pop2, "ports"); } /** @@ -845,12 +847,8 @@ void cmd_restrict_protocol(struct cmd_node *root) { /* Restrict to some ports. */ - commands_new( - commands_new(root, - "protocol", - "Restrict to specific protocol", - cmd_check_no_env, NULL, "protocol"), - NULL, - "Restrict display to the specified protocol", - NULL, cmd_store_env_value_and_pop2, "protocol"); + commands_new(commands_new(root, "protocol", "Restrict to specific protocol", + cmd_check_no_env, NULL, "protocol"), + NULL, "Restrict display to the specified protocol", NULL, + cmd_store_env_value_and_pop2, "protocol"); } diff --git a/src/client/conf-dot3.c b/src/client/conf-dot3.c index a71aa7aa..e90b60d8 100644 --- a/src/client/conf-dot3.c +++ b/src/client/conf-dot3.c @@ -27,13 +27,9 @@ void register_commands_configure_dot3(struct cmd_node *configure) { - if (lldpctl_key_get_map( - lldpctl_k_dot3_power_class)[0].string == NULL) - return; + if (lldpctl_key_get_map(lldpctl_k_dot3_power_class)[0].string == NULL) return; - struct cmd_node *configure_dot3 = commands_new( - configure, - "dot3", "Dot3 configuration", - NULL, NULL, NULL); + struct cmd_node *configure_dot3 = + commands_new(configure, "dot3", "Dot3 configuration", NULL, NULL, NULL); register_commands_dot3pow(configure_dot3); } diff --git a/src/client/conf-inv.c b/src/client/conf-inv.c index 6b043f21..9cc5b681 100644 --- a/src/client/conf-inv.c +++ b/src/client/conf-inv.c @@ -11,8 +11,8 @@ #include "../log.h" static int -cmd_inventory(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_inventory(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "configure inventory information"); @@ -26,33 +26,26 @@ cmd_inventory(struct lldpctl_conn_t *conn, struct writer *w, char *action = arg; if ((!strcmp(action, "hardware-revision") && - (lldpctl_atom_set_str(chassis, - lldpctl_k_chassis_med_inventory_hw, - cmdenv_get(env, "hardware-revision")) == NULL)) || + (lldpctl_atom_set_str(chassis, lldpctl_k_chassis_med_inventory_hw, + cmdenv_get(env, "hardware-revision")) == NULL)) || (!strcmp(action, "software-revision") && - (lldpctl_atom_set_str(chassis, - lldpctl_k_chassis_med_inventory_sw, - cmdenv_get(env, "software-revision")) == NULL)) || + (lldpctl_atom_set_str(chassis, lldpctl_k_chassis_med_inventory_sw, + cmdenv_get(env, "software-revision")) == NULL)) || (!strcmp(action, "firmware-revision") && - (lldpctl_atom_set_str(chassis, - lldpctl_k_chassis_med_inventory_fw, - cmdenv_get(env, "firmware-revision")) == NULL)) || + (lldpctl_atom_set_str(chassis, lldpctl_k_chassis_med_inventory_fw, + cmdenv_get(env, "firmware-revision")) == NULL)) || (!strcmp(action, "serial-number") && - (lldpctl_atom_set_str(chassis, - lldpctl_k_chassis_med_inventory_sn, - cmdenv_get(env, "serial-number")) == NULL)) || + (lldpctl_atom_set_str(chassis, lldpctl_k_chassis_med_inventory_sn, + cmdenv_get(env, "serial-number")) == NULL)) || (!strcmp(action, "manufacturer") && - (lldpctl_atom_set_str(chassis, - lldpctl_k_chassis_med_inventory_manuf, - cmdenv_get(env, "manufacturer")) == NULL)) || + (lldpctl_atom_set_str(chassis, lldpctl_k_chassis_med_inventory_manuf, + cmdenv_get(env, "manufacturer")) == NULL)) || (!strcmp(action, "model") && - (lldpctl_atom_set_str(chassis, - lldpctl_k_chassis_med_inventory_model, - cmdenv_get(env, "model")) == NULL)) || + (lldpctl_atom_set_str(chassis, lldpctl_k_chassis_med_inventory_model, + cmdenv_get(env, "model")) == NULL)) || (!strcmp(action, "asset") && - (lldpctl_atom_set_str(chassis, - lldpctl_k_chassis_med_inventory_asset, - cmdenv_get(env, "asset")) == NULL))) { + (lldpctl_atom_set_str(chassis, lldpctl_k_chassis_med_inventory_asset, + cmdenv_get(env, "asset")) == NULL))) { log_warnx("lldpctl", "Unable to setup inventory. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(chassis); @@ -71,124 +64,82 @@ cmd_inventory(struct lldpctl_conn_t *conn, struct writer *w, static void register_commands_inv(struct cmd_node *configure_inv, struct cmd_node *unconfigure_inv) { - commands_new( - commands_new( - commands_new(configure_inv, - "hardware-revision", "Set hardware-revision string", - NULL, NULL, NULL), - NULL, "Inventory hardware-revision string", - NULL, cmd_store_env_value, "hardware-revision"), - NEWLINE, "Set hardware-revision string", - NULL, cmd_inventory, "hardware-revision"); - - commands_new( - commands_new(unconfigure_inv, - "hardware-revision", "Unset hardware-revision string", - NULL, NULL, NULL), - NEWLINE, "Unset hardware-revision string", - NULL, cmd_inventory, "hardware-revision"); - - commands_new( - commands_new( - commands_new(configure_inv, - "software-revision", "Set software-revision string", - NULL, NULL, NULL), - NULL, "Inventory software-revision string", - NULL, cmd_store_env_value, "software-revision"), - NEWLINE, "Set software-revision string", - NULL, cmd_inventory, "software-revision"); - - commands_new( - commands_new(unconfigure_inv, - "software-revision", "Unset software-revision string", - NULL, NULL, NULL), - NEWLINE, "Unset software-revision string", - NULL, cmd_inventory, "software-revision"); - - commands_new( - commands_new( - commands_new(configure_inv, - "firmware-revision", "Set firmware-revision string", - NULL, NULL, NULL), - NULL, "Inventory firmware-revision string", - NULL, cmd_store_env_value, "firmware-revision"), - NEWLINE, "Set firmware-revision string", - NULL, cmd_inventory, "firmware-revision"); - - commands_new( - commands_new(unconfigure_inv, - "firmware-revision", "Unset firmware-revision string", - NULL, NULL, NULL), - NEWLINE, "Unset firmware-revision string", - NULL, cmd_inventory, "firmware-revision"); - - commands_new( - commands_new( - commands_new(configure_inv, - "serial-number", "Set serial-number string", - NULL, NULL, NULL), - NULL, "Inventory serial-number string", - NULL, cmd_store_env_value, "serial-number"), - NEWLINE, "Set serial-number string", - NULL, cmd_inventory, "serial-number"); - - commands_new( - commands_new(unconfigure_inv, - "serial-number", "Unset serial-number string", - NULL, NULL, NULL), - NEWLINE, "Unset serial-number string", - NULL, cmd_inventory, "serial-number"); - - commands_new( - commands_new( - commands_new(configure_inv, - "manufacturer", "Set manufacturer string", - NULL, NULL, NULL), - NULL, "Inventory manufacturer string", - NULL, cmd_store_env_value, "manufacturer"), - NEWLINE, "Set manufacturer string", - NULL, cmd_inventory, "manufacturer"); - - commands_new( - commands_new(unconfigure_inv, - "manufacturer", "Unset manufacturer string", - NULL, NULL, NULL), - NEWLINE, "Unset manufacturer string", - NULL, cmd_inventory, "manufacturer"); - - commands_new( - commands_new( - commands_new(configure_inv, - "model", "Set model string", - NULL, NULL, NULL), - NULL, "Inventory model string", - NULL, cmd_store_env_value, "model"), - NEWLINE, "Set model string", - NULL, cmd_inventory, "model"); - - commands_new( - commands_new(unconfigure_inv, - "model", "Unset model string", - NULL, NULL, NULL), - NEWLINE, "Unset model string", - NULL, cmd_inventory, "model"); - - commands_new( - commands_new( - commands_new(configure_inv, - "asset", "Set asset string", - NULL, NULL, NULL), - NULL, "Inventory asset string", - NULL, cmd_store_env_value, "asset"), - NEWLINE, "Set asset string", - NULL, cmd_inventory, "asset"); - - commands_new( - commands_new(unconfigure_inv, - "asset", "Unset asset string", - NULL, NULL, NULL), - NEWLINE, "Unset asset string", - NULL, cmd_inventory, "asset"); + commands_new(commands_new(commands_new(configure_inv, "hardware-revision", + "Set hardware-revision string", NULL, NULL, NULL), + NULL, "Inventory hardware-revision string", NULL, + cmd_store_env_value, "hardware-revision"), + NEWLINE, "Set hardware-revision string", NULL, cmd_inventory, + "hardware-revision"); + + commands_new(commands_new(unconfigure_inv, "hardware-revision", + "Unset hardware-revision string", NULL, NULL, NULL), + NEWLINE, "Unset hardware-revision string", NULL, cmd_inventory, + "hardware-revision"); + + commands_new(commands_new(commands_new(configure_inv, "software-revision", + "Set software-revision string", NULL, NULL, NULL), + NULL, "Inventory software-revision string", NULL, + cmd_store_env_value, "software-revision"), + NEWLINE, "Set software-revision string", NULL, cmd_inventory, + "software-revision"); + + commands_new(commands_new(unconfigure_inv, "software-revision", + "Unset software-revision string", NULL, NULL, NULL), + NEWLINE, "Unset software-revision string", NULL, cmd_inventory, + "software-revision"); + + commands_new(commands_new(commands_new(configure_inv, "firmware-revision", + "Set firmware-revision string", NULL, NULL, NULL), + NULL, "Inventory firmware-revision string", NULL, + cmd_store_env_value, "firmware-revision"), + NEWLINE, "Set firmware-revision string", NULL, cmd_inventory, + "firmware-revision"); + + commands_new(commands_new(unconfigure_inv, "firmware-revision", + "Unset firmware-revision string", NULL, NULL, NULL), + NEWLINE, "Unset firmware-revision string", NULL, cmd_inventory, + "firmware-revision"); + + commands_new(commands_new(commands_new(configure_inv, "serial-number", + "Set serial-number string", NULL, NULL, NULL), + NULL, "Inventory serial-number string", NULL, + cmd_store_env_value, "serial-number"), + NEWLINE, "Set serial-number string", NULL, cmd_inventory, "serial-number"); + + commands_new(commands_new(unconfigure_inv, "serial-number", + "Unset serial-number string", NULL, NULL, NULL), + NEWLINE, "Unset serial-number string", NULL, cmd_inventory, + "serial-number"); + + commands_new(commands_new(commands_new(configure_inv, "manufacturer", + "Set manufacturer string", NULL, NULL, NULL), + NULL, "Inventory manufacturer string", NULL, + cmd_store_env_value, "manufacturer"), + NEWLINE, "Set manufacturer string", NULL, cmd_inventory, "manufacturer"); + + commands_new(commands_new(unconfigure_inv, "manufacturer", + "Unset manufacturer string", NULL, NULL, NULL), + NEWLINE, "Unset manufacturer string", NULL, cmd_inventory, "manufacturer"); + + commands_new(commands_new(commands_new(configure_inv, "model", + "Set model string", NULL, NULL, NULL), + NULL, "Inventory model string", NULL, cmd_store_env_value, + "model"), + NEWLINE, "Set model string", NULL, cmd_inventory, "model"); + + commands_new(commands_new(unconfigure_inv, "model", "Unset model string", NULL, + NULL, NULL), + NEWLINE, "Unset model string", NULL, cmd_inventory, "model"); + + commands_new(commands_new(commands_new(configure_inv, "asset", + "Set asset string", NULL, NULL, NULL), + NULL, "Inventory asset string", NULL, cmd_store_env_value, + "asset"), + NEWLINE, "Set asset string", NULL, cmd_inventory, "asset"); + + commands_new(commands_new(unconfigure_inv, "asset", "Unset asset string", NULL, + NULL, NULL), + NEWLINE, "Unset asset string", NULL, cmd_inventory, "asset"); } /** @@ -196,20 +147,15 @@ register_commands_inv(struct cmd_node *configure_inv, struct cmd_node *unconfigu * */ void -register_commands_configure_inventory(struct cmd_node *configure, struct cmd_node *unconfigure) { - if(lldpctl_key_get_map( - lldpctl_k_med_policy_type)[0].value <= 0) - return; - - struct cmd_node *configure_inv = commands_new( - configure, - "inventory", "Inventory configuration", - NULL, NULL, NULL); - struct cmd_node *unconfigure_inv = commands_new( - unconfigure, - "inventory", "Inventory configuration", - NULL, NULL, NULL); +register_commands_configure_inventory(struct cmd_node *configure, + struct cmd_node *unconfigure) +{ + if (lldpctl_key_get_map(lldpctl_k_med_policy_type)[0].value <= 0) return; + + struct cmd_node *configure_inv = commands_new(configure, "inventory", + "Inventory configuration", NULL, NULL, NULL); + struct cmd_node *unconfigure_inv = commands_new(unconfigure, "inventory", + "Inventory configuration", NULL, NULL, NULL); register_commands_inv(configure_inv, unconfigure_inv); } - diff --git a/src/client/conf-lldp.c b/src/client/conf-lldp.c index 4e497378..68dd3f34 100644 --- a/src/client/conf-lldp.c +++ b/src/client/conf-lldp.c @@ -23,8 +23,8 @@ #include "../log.h" static int -cmd_txdelay(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_txdelay(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { const char *interval; char interval_ms[8]; /* less than 2.5 hours */ @@ -45,11 +45,11 @@ cmd_txdelay(struct lldpctl_conn_t *conn, struct writer *w, if (interval) { arglen = strlen(interval); /* room for "ms" in interval, room for interval in interval_ms */ - if (arglen >= 2 && arglen-2 < sizeof(interval_ms) && - strcmp("ms", interval+arglen-2) == 0) { + if (arglen >= 2 && arglen - 2 < sizeof(interval_ms) && + strcmp("ms", interval + arglen - 2) == 0) { /* remove "ms" suffix */ - memcpy(interval_ms, interval, arglen-2); - interval_ms[arglen-2] = '\0'; + memcpy(interval_ms, interval, arglen - 2); + interval_ms[arglen - 2] = '\0'; /* substitute key and value */ key = lldpctl_k_config_tx_interval_ms; interval = interval_ms; @@ -67,8 +67,8 @@ cmd_txdelay(struct lldpctl_conn_t *conn, struct writer *w, } static int -cmd_txhold(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_txhold(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "set transmit hold"); @@ -78,21 +78,22 @@ cmd_txhold(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_last_strerror(conn)); return 0; } - if (lldpctl_atom_set_str(config, - lldpctl_k_config_tx_hold, cmdenv_get(env, "tx-hold")) == NULL) { + if (lldpctl_atom_set_str(config, lldpctl_k_config_tx_hold, + cmdenv_get(env, "tx-hold")) == NULL) { log_warnx("lldpctl", "unable to set transmit hold. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } - log_info("lldpctl", "transmit hold set to new value %s", cmdenv_get(env, "tx-hold")); + log_info("lldpctl", "transmit hold set to new value %s", + cmdenv_get(env, "tx-hold")); lldpctl_atom_dec_ref(config); return 1; } static int -cmd_status(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_status(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { lldpctl_atom_t *port; const char *name; @@ -107,8 +108,10 @@ cmd_status(struct lldpctl_conn_t *conn, struct writer *w, while ((port = cmd_iterate_on_ports(conn, env, &name))) { if (lldpctl_atom_set_str(port, lldpctl_k_port_status, status) == NULL) { - log_warnx("lldpctl", "unable to set LLDP status for %s." - " %s", name, lldpctl_last_strerror(conn)); + log_warnx("lldpctl", + "unable to set LLDP status for %s." + " %s", + name, lldpctl_last_strerror(conn)); } } @@ -116,8 +119,8 @@ cmd_status(struct lldpctl_conn_t *conn, struct writer *w, } static int -cmd_agent_type(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_agent_type(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { const char *str = arg; int value = -1; @@ -126,14 +129,13 @@ cmd_agent_type(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_atom_t *config = lldpctl_get_configuration(conn); if (config == NULL) { - log_warnx("lldpctl", - "unable to get configuration from lldpd. %s", - lldpctl_last_strerror(conn)); + log_warnx("lldpctl", "unable to get configuration from lldpd. %s", + lldpctl_last_strerror(conn)); return 0; } for (lldpctl_map_t *b_map = - lldpctl_key_get_map(lldpctl_k_config_lldp_agent_type); + lldpctl_key_get_map(lldpctl_k_config_lldp_agent_type); b_map->string; b_map++) { if (!strcmp(b_map->string, str)) { value = b_map->value; @@ -147,10 +149,12 @@ cmd_agent_type(struct lldpctl_conn_t *conn, struct writer *w, return 0; } - if (lldpctl_atom_set_int(config, - lldpctl_k_config_lldp_agent_type, value) == NULL) { - log_warnx("lldpctl", "unable to set LLDP agent type." - " %s", lldpctl_last_strerror(conn)); + if (lldpctl_atom_set_int(config, lldpctl_k_config_lldp_agent_type, value) == + NULL) { + log_warnx("lldpctl", + "unable to set LLDP agent type." + " %s", + lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } @@ -163,14 +167,15 @@ cmd_agent_type(struct lldpctl_conn_t *conn, struct writer *w, static int cmd_portid_type_local(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) + struct cmd_env *env, void *arg) { lldpctl_atom_t *port; const char *name; const char *id = cmdenv_get(env, "port-id"); const char *descr = cmdenv_get(env, "port-descr"); - log_debug("lldpctl", "lldp PortID TLV Subtype Local port-id '%s' port-descr '%s'", id, descr); + log_debug("lldpctl", + "lldp PortID TLV Subtype Local port-id '%s' port-descr '%s'", id, descr); if (!id || !strlen(id)) { log_warnx("lldpctl", "no id specified"); @@ -179,12 +184,17 @@ cmd_portid_type_local(struct lldpctl_conn_t *conn, struct writer *w, while ((port = cmd_iterate_on_ports(conn, env, &name))) { if (lldpctl_atom_set_str(port, lldpctl_k_port_id, id) == NULL) { - log_warnx("lldpctl", "unable to set LLDP PortID for %s." - " %s", name, lldpctl_last_strerror(conn)); + log_warnx("lldpctl", + "unable to set LLDP PortID for %s." + " %s", + name, lldpctl_last_strerror(conn)); } - if (descr && lldpctl_atom_set_str(port, lldpctl_k_port_descr, descr) == NULL) { - log_warnx("lldpctl", "unable to set LLDP Port Description for %s." - " %s", name, lldpctl_last_strerror(conn)); + if (descr && + lldpctl_atom_set_str(port, lldpctl_k_port_descr, descr) == NULL) { + log_warnx("lldpctl", + "unable to set LLDP Port Description for %s." + " %s", + name, lldpctl_last_strerror(conn)); } } @@ -192,8 +202,8 @@ cmd_portid_type_local(struct lldpctl_conn_t *conn, struct writer *w, } static int -cmd_port_descr(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_port_descr(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { lldpctl_atom_t *port; const char *name; @@ -202,9 +212,12 @@ cmd_port_descr(struct lldpctl_conn_t *conn, struct writer *w, log_debug("lldpctl", "lldp port-descr '%s'", descr); while ((port = cmd_iterate_on_ports(conn, env, &name))) { - if (descr && lldpctl_atom_set_str(port, lldpctl_k_port_descr, descr) == NULL) { - log_warnx("lldpctl", "unable to set LLDP Port Description for %s." - " %s", name, lldpctl_last_strerror(conn)); + if (descr && + lldpctl_atom_set_str(port, lldpctl_k_port_descr, descr) == NULL) { + log_warnx("lldpctl", + "unable to set LLDP Port Description for %s." + " %s", + name, lldpctl_last_strerror(conn)); } } @@ -212,8 +225,8 @@ cmd_port_descr(struct lldpctl_conn_t *conn, struct writer *w, } static int -cmd_portid_type(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_portid_type(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { char *value_str; int value = -1; @@ -222,15 +235,14 @@ cmd_portid_type(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_atom_t *config = lldpctl_get_configuration(conn); if (config == NULL) { - log_warnx("lldpctl", - "unable to get configuration from lldpd. %s", - lldpctl_last_strerror(conn)); + log_warnx("lldpctl", "unable to get configuration from lldpd. %s", + lldpctl_last_strerror(conn)); return 0; } value_str = arg; for (lldpctl_map_t *b_map = - lldpctl_key_get_map(lldpctl_k_config_lldp_portid_type); + lldpctl_key_get_map(lldpctl_k_config_lldp_portid_type); b_map->string; b_map++) { if (!strcmp(b_map->string, value_str)) { value = b_map->value; @@ -244,10 +256,12 @@ cmd_portid_type(struct lldpctl_conn_t *conn, struct writer *w, return 0; } - if (lldpctl_atom_set_int(config, - lldpctl_k_config_lldp_portid_type, value) == NULL) { - log_warnx("lldpctl", "unable to set LLDP PortID type." - " %s", lldpctl_last_strerror(conn)); + if (lldpctl_atom_set_int(config, lldpctl_k_config_lldp_portid_type, value) == + NULL) { + log_warnx("lldpctl", + "unable to set LLDP PortID type." + " %s", + lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } @@ -262,7 +276,8 @@ static int cmd_chassis_cap_advertise(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *arg) { - log_debug("lldpctl", "lldp capabilities-advertisements %s", arg?"enable":"disable"); + log_debug("lldpctl", "lldp capabilities-advertisements %s", + arg ? "enable" : "disable"); lldpctl_atom_t *config = lldpctl_get_configuration(conn); if (config == NULL) { @@ -270,17 +285,16 @@ cmd_chassis_cap_advertise(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_last_strerror(conn)); return 0; } - if (lldpctl_atom_set_int(config, - lldpctl_k_config_chassis_cap_advertise, - arg?1:0) == NULL) { - log_warnx("lldpctl", "unable to %s chassis capabilities advertisement: %s", - arg?"enable":"disable", - lldpctl_last_strerror(conn)); + if (lldpctl_atom_set_int(config, lldpctl_k_config_chassis_cap_advertise, + arg ? 1 : 0) == NULL) { + log_warnx("lldpctl", + "unable to %s chassis capabilities advertisement: %s", + arg ? "enable" : "disable", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } log_info("lldpctl", "chassis capabilities advertisement %s", - arg?"enabled":"disabled"); + arg ? "enabled" : "disabled"); lldpctl_atom_dec_ref(config); return 1; } @@ -290,7 +304,8 @@ static int cmd_chassis_mgmt_advertise(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *arg) { - log_debug("lldpctl", "lldp management-addresses-advertisements %s", arg?"enable":"disable"); + log_debug("lldpctl", "lldp management-addresses-advertisements %s", + arg ? "enable" : "disable"); lldpctl_atom_t *config = lldpctl_get_configuration(conn); if (config == NULL) { @@ -298,24 +313,23 @@ cmd_chassis_mgmt_advertise(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_last_strerror(conn)); return 0; } - if (lldpctl_atom_set_int(config, - lldpctl_k_config_chassis_mgmt_advertise, - arg?1:0) == NULL) { - log_warnx("lldpctl", "unable to %s management addresses advertisement: %s", - arg?"enable":"disable", - lldpctl_last_strerror(conn)); + if (lldpctl_atom_set_int(config, lldpctl_k_config_chassis_mgmt_advertise, + arg ? 1 : 0) == NULL) { + log_warnx("lldpctl", + "unable to %s management addresses advertisement: %s", + arg ? "enable" : "disable", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } log_info("lldpctl", "management addresses advertisement %s", - arg?"enabled":"disabled"); + arg ? "enabled" : "disabled"); lldpctl_atom_dec_ref(config); return 1; } static int -cmd_vlan_tx(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_vlan_tx(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { lldpctl_atom_t *port; const char *name; @@ -330,10 +344,12 @@ cmd_vlan_tx(struct lldpctl_conn_t *conn, struct writer *w, int vlan_tag = -1; if (!arg) - log_debug("lldpctl", "lldp disable VLAN tagging of transmitted LLDP frames"); + log_debug("lldpctl", + "lldp disable VLAN tagging of transmitted LLDP frames"); else - log_debug("lldpctl", "lldp enable VLAN tagging of transmitted LLDP frames with VLAN ID: '%s', Priority: '%s', DEI: '%s'", - vlan_id, vlan_prio, vlan_dei); + log_debug("lldpctl", + "lldp enable VLAN tagging of transmitted LLDP frames with VLAN ID: '%s', Priority: '%s', DEI: '%s'", + vlan_id, vlan_prio, vlan_dei); if (arg) { if (!vlan_id || !strlen(vlan_id)) { @@ -344,13 +360,14 @@ cmd_vlan_tx(struct lldpctl_conn_t *conn, struct writer *w, vlan_id_int = strtonum(vlan_id, 0, 4094, &errstr); if (errstr != NULL) { log_warnx("lldpctl", "invalid VLAN ID for TX `%s': %s", - vlan_id, errstr); + vlan_id, errstr); return 0; } } if (!vlan_prio || !strlen(vlan_prio)) { - log_warnx("lldpctl", "no VLAN priority for TX specified, using default (0)"); + log_warnx("lldpctl", + "no VLAN priority for TX specified, using default (0)"); /* Use default priority */ vlan_prio_int = 0; } else { @@ -358,34 +375,38 @@ cmd_vlan_tx(struct lldpctl_conn_t *conn, struct writer *w, vlan_prio_int = strtonum(vlan_prio, 0, 7, &errstr); if (errstr != NULL) { log_warnx("lldpctl", "invalid VLAN piority `%s': %s", - vlan_prio, errstr); + vlan_prio, errstr); return 0; } } if (!vlan_dei || !strlen(vlan_dei)) { - log_warnx("lldpctl", "no VLAN Drop eligible indicator (DEI) for TX specified, using default (0)"); + log_warnx("lldpctl", + "no VLAN Drop eligible indicator (DEI) for TX specified, using default (0)"); /* Use default priority */ vlan_dei_int = 0; } else { const char *errstr; vlan_dei_int = strtonum(vlan_dei, 0, 1, &errstr); if (errstr != NULL) { - log_warnx("lldpctl", "invalid VLAN Drop eligible indicator (DEI) `%s': %s", - vlan_dei, errstr); + log_warnx("lldpctl", + "invalid VLAN Drop eligible indicator (DEI) `%s': %s", + vlan_dei, errstr); return 0; } } /* Priority(3bits) | DEI(1bit) | VID(12bits) */ vlan_tag = ((vlan_prio_int & 0x7) << 13) | - ((vlan_dei_int & 0x1) << 12) | - (vlan_id_int & 0xfff); + ((vlan_dei_int & 0x1) << 12) | (vlan_id_int & 0xfff); } while ((port = cmd_iterate_on_ports(conn, env, &name))) { - if (lldpctl_atom_set_int(port, lldpctl_k_port_vlan_tx, vlan_tag) == NULL) { - log_warnx("lldpctl", "unable to set VLAN TX config on %s." - " %s", name, lldpctl_last_strerror(conn)); + if (lldpctl_atom_set_int(port, lldpctl_k_port_vlan_tx, vlan_tag) == + NULL) { + log_warnx("lldpctl", + "unable to set VLAN TX config on %s." + " %s", + name, lldpctl_last_strerror(conn)); } } @@ -394,8 +415,8 @@ cmd_vlan_tx(struct lldpctl_conn_t *conn, struct writer *w, #ifdef ENABLE_CUSTOM static int -cmd_custom_tlv_set(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_custom_tlv_set(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { lldpctl_atom_t *port; const char *s; @@ -406,18 +427,16 @@ cmd_custom_tlv_set(struct lldpctl_conn_t *conn, struct writer *w, uint16_t subtype = 0; char *op = "add"; - if (!arg || !strcmp(arg, "remove")) - op = "remove"; + if (!arg || !strcmp(arg, "remove")) op = "remove"; log_debug("lldpctl", "lldp custom-tlv(s) %s", op); - if (!arg) - goto set; + if (!arg) goto set; s = cmdenv_get(env, "oui"); - if (!s || ( - sscanf(s, "%02hhx,%02hhx,%02hhx", &oui[0], &oui[1], &oui[2]) != 3 && - sscanf(s, "%02hhX,%02hhX,%02hhX", &oui[0], &oui[1], &oui[2]) != 3) ) { + if (!s || + (sscanf(s, "%02hhx,%02hhx,%02hhx", &oui[0], &oui[1], &oui[2]) != 3 && + sscanf(s, "%02hhX,%02hhX,%02hhX", &oui[0], &oui[1], &oui[2]) != 3)) { log_warnx("lldpctl", "invalid OUI value '%s'", s); return 0; } @@ -430,8 +449,8 @@ cmd_custom_tlv_set(struct lldpctl_conn_t *conn, struct writer *w, const char *errstr; subtype = strtonum(s, 0, 255, &errstr); if (errstr != NULL) { - log_warnx("lldpctl", "invalid subtype value `%s': %s", - s, errstr); + log_warnx("lldpctl", "invalid subtype value `%s': %s", s, + errstr); return 0; } } @@ -446,8 +465,7 @@ cmd_custom_tlv_set(struct lldpctl_conn_t *conn, struct writer *w, if (sscanf(token, "%02hhx", &oui_info[oui_info_len]) == 1 || sscanf(token, "%02hhX", &oui_info[oui_info_len]) == 1) oui_info_len++; - if (oui_info_len >= sizeof(oui_info)) - break; + if (oui_info_len >= sizeof(oui_info)) break; token = strtok(NULL, delim); } free(s_copy); @@ -462,18 +480,25 @@ set: lldpctl_atom_t *custom_tlvs; if (!arg) { lldpctl_atom_set(port, lldpctl_k_custom_tlvs_clear, NULL); - } else if (!(custom_tlvs = lldpctl_atom_get(port, lldpctl_k_custom_tlvs))) { - log_warnx("lldpctl", "unable to get custom TLVs for port %s", name); + } else if (!(custom_tlvs = + lldpctl_atom_get(port, lldpctl_k_custom_tlvs))) { + log_warnx("lldpctl", "unable to get custom TLVs for port %s", + name); } else { lldpctl_atom_t *tlv = lldpctl_atom_create(custom_tlvs); if (!tlv) { - log_warnx("lldpctl", "unable to create new custom TLV for port %s", + log_warnx("lldpctl", + "unable to create new custom TLV for port %s", name); } else { /* Configure custom TLV */ - lldpctl_atom_set_buffer(tlv, lldpctl_k_custom_tlv_oui, oui, sizeof(oui)); - lldpctl_atom_set_int(tlv, lldpctl_k_custom_tlv_oui_subtype, subtype); - lldpctl_atom_set_buffer(tlv, lldpctl_k_custom_tlv_oui_info_string, oui_info, oui_info_len); + lldpctl_atom_set_buffer(tlv, lldpctl_k_custom_tlv_oui, + oui, sizeof(oui)); + lldpctl_atom_set_int(tlv, + lldpctl_k_custom_tlv_oui_subtype, subtype); + lldpctl_atom_set_buffer(tlv, + lldpctl_k_custom_tlv_oui_info_string, oui_info, + oui_info_len); lldpctl_atom_set_str(tlv, lldpctl_k_custom_tlv_op, op); /* Assign it to port */ @@ -508,84 +533,65 @@ cmd_check_no_replace_env(struct cmd_env *env, void *arg) void register_commands_configure_lldp_custom_tlvs(struct cmd_node *configure_lldp, - struct cmd_node *unconfigure_lldp) + struct cmd_node *unconfigure_lldp) { struct cmd_node *configure_custom_tlvs; struct cmd_node *unconfigure_custom_tlvs; struct cmd_node *configure_custom_tlvs_basic; struct cmd_node *unconfigure_custom_tlvs_basic; - configure_custom_tlvs = - commands_new(configure_lldp, - "custom-tlv", - "Add custom TLV(s) to be broadcast on ports", - NULL, NULL, NULL); - - unconfigure_custom_tlvs = - commands_new(unconfigure_lldp, - "custom-tlv", - "Remove ALL custom TLV(s)", - NULL, NULL, NULL); - - commands_new(unconfigure_custom_tlvs, - NEWLINE, "Remove ALL custom TLV", - NULL, cmd_custom_tlv_set, NULL); - - commands_new(configure_custom_tlvs, - "add", "Add custom TLV", - cmd_check_no_replace_env, cmd_store_env_and_pop, "add"); - commands_new(configure_custom_tlvs, - "replace", "Replace custom TLV", - cmd_check_no_add_env, cmd_store_env_and_pop, "replace"); + configure_custom_tlvs = commands_new(configure_lldp, "custom-tlv", + "Add custom TLV(s) to be broadcast on ports", NULL, NULL, NULL); + + unconfigure_custom_tlvs = commands_new(unconfigure_lldp, "custom-tlv", + "Remove ALL custom TLV(s)", NULL, NULL, NULL); + + commands_new(unconfigure_custom_tlvs, NEWLINE, "Remove ALL custom TLV", NULL, + cmd_custom_tlv_set, NULL); + + commands_new(configure_custom_tlvs, "add", "Add custom TLV", + cmd_check_no_replace_env, cmd_store_env_and_pop, "add"); + commands_new(configure_custom_tlvs, "replace", "Replace custom TLV", + cmd_check_no_add_env, cmd_store_env_and_pop, "replace"); /* Basic form: 'configure lldp custom-tlv oui 11,22,33 subtype 44' */ - configure_custom_tlvs_basic = - commands_new( - commands_new( - commands_new( - commands_new(configure_custom_tlvs, - "oui", "Organizationally Unique Identifier", - NULL, NULL, NULL), - NULL, "Organizationally Unique Identifier", - NULL, cmd_store_env_value, "oui"), - "subtype", "Organizationally Defined Subtype", - NULL, NULL, NULL), - NULL, "Organizationally Defined Subtype", - NULL, cmd_store_env_value, "subtype"); - - commands_new(configure_custom_tlvs_basic, - NEWLINE, "Add custom TLV(s) to be broadcast on ports", - NULL, cmd_custom_tlv_set, "enable"); + configure_custom_tlvs_basic = commands_new( + commands_new(commands_new(commands_new(configure_custom_tlvs, "oui", + "Organizationally Unique Identifier", NULL, + NULL, NULL), + NULL, "Organizationally Unique Identifier", NULL, + cmd_store_env_value, "oui"), + "subtype", "Organizationally Defined Subtype", NULL, NULL, NULL), + NULL, "Organizationally Defined Subtype", NULL, cmd_store_env_value, + "subtype"); + + commands_new(configure_custom_tlvs_basic, NEWLINE, + "Add custom TLV(s) to be broadcast on ports", NULL, cmd_custom_tlv_set, + "enable"); /* Basic form: 'unconfigure lldp custom-tlv oui 11,22,33 subtype 44' */ - unconfigure_custom_tlvs_basic = - commands_new( - commands_new( - commands_new( - commands_new(unconfigure_custom_tlvs, - "oui", "Organizationally Unique Identifier", - NULL, NULL, NULL), - NULL, "Organizationally Unique Identifier", - NULL, cmd_store_env_value, "oui"), - "subtype", "Organizationally Defined Subtype", - NULL, NULL, NULL), - NULL, "Organizationally Defined Subtype", - NULL, cmd_store_env_value, "subtype"); - - commands_new(unconfigure_custom_tlvs_basic, - NEWLINE, "Remove specific custom TLV", - NULL, cmd_custom_tlv_set, "remove"); - - /* Extended form: 'configure custom-tlv lldp oui 11,22,33 subtype 44 oui-info 55,66,77,...' */ - commands_new( - commands_new( - commands_new(configure_custom_tlvs_basic, - "oui-info", "Organizationally Unique Identifier", - NULL, NULL, NULL), - NULL, "OUI Info String", - NULL, cmd_store_env_value, "oui-info"), - NEWLINE, "Add custom TLV(s) to be broadcast on ports", - NULL, cmd_custom_tlv_set, "enable"); + unconfigure_custom_tlvs_basic = commands_new( + commands_new(commands_new(commands_new(unconfigure_custom_tlvs, "oui", + "Organizationally Unique Identifier", NULL, + NULL, NULL), + NULL, "Organizationally Unique Identifier", NULL, + cmd_store_env_value, "oui"), + "subtype", "Organizationally Defined Subtype", NULL, NULL, NULL), + NULL, "Organizationally Defined Subtype", NULL, cmd_store_env_value, + "subtype"); + + commands_new(unconfigure_custom_tlvs_basic, NEWLINE, + "Remove specific custom TLV", NULL, cmd_custom_tlv_set, "remove"); + + /* Extended form: 'configure custom-tlv lldp oui 11,22,33 subtype 44 oui-info + * 55,66,77,...' */ + commands_new(commands_new(commands_new(configure_custom_tlvs_basic, "oui-info", + "Organizationally Unique Identifier", NULL, NULL, + NULL), + NULL, "OUI Info String", NULL, cmd_store_env_value, + "oui-info"), + NEWLINE, "Add custom TLV(s) to be broadcast on ports", NULL, + cmd_custom_tlv_set, "enable"); } #endif /* ENABLE_CUSTOM */ @@ -606,209 +612,149 @@ void register_commands_configure_lldp(struct cmd_node *configure, struct cmd_node *unconfigure) { - struct cmd_node *configure_lldp = commands_new( - configure, - "lldp", "LLDP configuration", - NULL, NULL, NULL); - struct cmd_node *unconfigure_lldp = commands_new( - unconfigure, - "lldp", "LLDP configuration", - NULL, NULL, NULL); - - commands_new( - commands_new( - commands_new(configure_lldp, - "tx-interval", "Set LLDP transmit delay", - cmd_check_no_env, NULL, "ports"), - NULL, "LLDP transmit in seconds or ms in milliseconds", - NULL, cmd_store_env_value, "tx-interval"), - NEWLINE, "Set LLDP transmit delay", - NULL, cmd_txdelay, NULL); - - commands_new( - commands_new( - commands_new(configure_lldp, - "tx-hold", "Set LLDP transmit hold", - cmd_check_no_env, NULL, "ports"), - NULL, "LLDP transmit hold in seconds", - NULL, cmd_store_env_value, "tx-hold"), - NEWLINE, "Set LLDP transmit hold", - NULL, cmd_txhold, NULL); - - struct cmd_node *status = commands_new(configure_lldp, - "status", "Set administrative status", - NULL, NULL, NULL); - - for (lldpctl_map_t *status_map = - lldpctl_key_get_map(lldpctl_k_port_status); - status_map->string; - status_map++) { + struct cmd_node *configure_lldp = + commands_new(configure, "lldp", "LLDP configuration", NULL, NULL, NULL); + struct cmd_node *unconfigure_lldp = + commands_new(unconfigure, "lldp", "LLDP configuration", NULL, NULL, NULL); + + commands_new( + commands_new(commands_new(configure_lldp, "tx-interval", + "Set LLDP transmit delay", cmd_check_no_env, NULL, + "ports"), + NULL, "LLDP transmit in seconds or ms in milliseconds", + NULL, cmd_store_env_value, "tx-interval"), + NEWLINE, "Set LLDP transmit delay", NULL, cmd_txdelay, NULL); + + commands_new(commands_new(commands_new(configure_lldp, "tx-hold", + "Set LLDP transmit hold", cmd_check_no_env, NULL, + "ports"), + NULL, "LLDP transmit hold in seconds", NULL, + cmd_store_env_value, "tx-hold"), + NEWLINE, "Set LLDP transmit hold", NULL, cmd_txhold, NULL); + + struct cmd_node *status = commands_new(configure_lldp, "status", + "Set administrative status", NULL, NULL, NULL); + + for (lldpctl_map_t *status_map = lldpctl_key_get_map(lldpctl_k_port_status); + status_map->string; status_map++) { const char *tag = strdup(totag(status_map->string)); SUPPRESS_LEAK(tag); - commands_new( - commands_new(status, - tag, - status_map->string, - NULL, cmd_store_status_env_value, status_map->string), - NEWLINE, "Set port administrative status", - NULL, cmd_status, NULL); + commands_new(commands_new(status, tag, status_map->string, NULL, + cmd_store_status_env_value, status_map->string), + NEWLINE, "Set port administrative status", NULL, cmd_status, NULL); } /* Configure the various agent type we can configure. */ - struct cmd_node *configure_lldp_agent_type = commands_new( - configure_lldp, - "agent-type", - "LLDP agent type", - NULL, NULL, NULL); + struct cmd_node *configure_lldp_agent_type = commands_new(configure_lldp, + "agent-type", "LLDP agent type", NULL, NULL, NULL); for (lldpctl_map_t *b_map = lldpctl_key_get_map(lldpctl_k_config_lldp_agent_type); b_map->string; b_map++) { const char *tag = strdup(totag(b_map->string)); SUPPRESS_LEAK(tag); - commands_new( - commands_new(configure_lldp_agent_type, - tag, - b_map->string, - NULL, NULL, NULL), - NEWLINE, "Set LLDP agent type", - NULL, cmd_agent_type, b_map->string); + commands_new(commands_new(configure_lldp_agent_type, tag, b_map->string, + NULL, NULL, NULL), + NEWLINE, "Set LLDP agent type", NULL, cmd_agent_type, + b_map->string); } /* Now handle the various portid subtypes we can configure. */ - struct cmd_node *configure_lldp_portid_type = commands_new( - configure_lldp, - "portidsubtype", "LLDP PortID TLV Subtype", - NULL, NULL, NULL); + struct cmd_node *configure_lldp_portid_type = commands_new(configure_lldp, + "portidsubtype", "LLDP PortID TLV Subtype", NULL, NULL, NULL); for (lldpctl_map_t *b_map = lldpctl_key_get_map(lldpctl_k_config_lldp_portid_type); b_map->string; b_map++) { if (!strcmp(b_map->string, "ifname")) { - commands_new( - commands_new(configure_lldp_portid_type, - b_map->string, "Interface Name", - cmd_check_no_env, NULL, "ports"), - NEWLINE, NULL, - NULL, cmd_portid_type, - b_map->string); + commands_new(commands_new(configure_lldp_portid_type, + b_map->string, "Interface Name", + cmd_check_no_env, NULL, "ports"), + NEWLINE, NULL, NULL, cmd_portid_type, b_map->string); } else if (!strcmp(b_map->string, "local")) { - struct cmd_node *port_id = commands_new( - commands_new(configure_lldp_portid_type, - b_map->string, "Local", - NULL, NULL, NULL), - NULL, "Port ID", - NULL, cmd_store_env_value, "port-id"); - commands_new(port_id, - NEWLINE, "Set local port ID", - NULL, cmd_portid_type_local, - b_map->string); - commands_new( - commands_new( - commands_new(port_id, - "description", - "Also set port description", - NULL, NULL, NULL), - NULL, "Port description", - NULL, cmd_store_env_value, "port-descr"), - NEWLINE, "Set local port ID and description", - NULL, cmd_portid_type_local, NULL); + struct cmd_node *port_id = + commands_new(commands_new(configure_lldp_portid_type, + b_map->string, "Local", NULL, NULL, NULL), + NULL, "Port ID", NULL, cmd_store_env_value, "port-id"); + commands_new(port_id, NEWLINE, "Set local port ID", NULL, + cmd_portid_type_local, b_map->string); + commands_new(commands_new(commands_new(port_id, "description", + "Also set port description", NULL, + NULL, NULL), + NULL, "Port description", NULL, + cmd_store_env_value, "port-descr"), + NEWLINE, "Set local port ID and description", NULL, + cmd_portid_type_local, NULL); } else if (!strcmp(b_map->string, "macaddress")) { - commands_new( - commands_new(configure_lldp_portid_type, - b_map->string, "MAC Address", - cmd_check_no_env, NULL, "ports"), - NEWLINE, NULL, - NULL, cmd_portid_type, - b_map->string); + commands_new(commands_new(configure_lldp_portid_type, + b_map->string, "MAC Address", cmd_check_no_env, + NULL, "ports"), + NEWLINE, NULL, NULL, cmd_portid_type, b_map->string); } } - commands_new( - commands_new( - commands_new(configure_lldp, - "portdescription", - "Port Description", - NULL, NULL, NULL), - NULL, "Port description", - NULL, cmd_store_env_value, "port-descr"), - NEWLINE, "Set port description", - NULL, cmd_port_descr, NULL); - - commands_new( - commands_new(configure_lldp, - "capabilities-advertisements", - "Enable chassis capabilities advertisement", - cmd_check_no_env, NULL, "ports"), - NEWLINE, "Enable chassis capabilities advertisement", - NULL, cmd_chassis_cap_advertise, "enable"); - commands_new( - commands_new(unconfigure_lldp, - "capabilities-advertisements", - "Don't enable chassis capabilities advertisement", - cmd_check_no_env, NULL, "ports"), - NEWLINE, "Don't enable chassis capabilities advertisement", - NULL, cmd_chassis_cap_advertise, NULL); - - commands_new( - commands_new(configure_lldp, - "management-addresses-advertisements", - "Enable management addresses advertisement", - cmd_check_no_env, NULL, "ports"), - NEWLINE, "Enable management addresses advertisement", - NULL, cmd_chassis_mgmt_advertise, "enable"); - commands_new( - commands_new(unconfigure_lldp, - "management-addresses-advertisements", - "Don't enable management addresses advertisement", - cmd_check_no_env, NULL, "ports"), - NEWLINE, "Don't enable management addresses advertisement", - NULL, cmd_chassis_mgmt_advertise, NULL); - - struct cmd_node *vlan_tx = commands_new( - commands_new(configure_lldp, - "vlan-tx", - "Send LLDP frames with a VLAN tag", - NULL, NULL, NULL), - NULL, "VLAN ID (0-4094)", - NULL, cmd_store_env_value, "vlan-tx-id"); - - struct cmd_node *vlan_tx_prio = commands_new( - commands_new(vlan_tx, - "priority", - "Also set a priority in a VLAN tag (default 0)", - NULL, NULL, NULL), - NULL, "Priority to be included in a VLAN tag (0-7)", - NULL, cmd_store_env_value, "vlan-tx-prio"); - - commands_new(vlan_tx, - NEWLINE, "Enable VLAN tagging of transmitted LLDP frames", - NULL, cmd_vlan_tx, - "enable"); - - commands_new( - vlan_tx_prio, - NEWLINE, "Set VLAN ID and priority for transmitted frames", - NULL, cmd_vlan_tx, "enable"); + commands_new(commands_new(commands_new(configure_lldp, "portdescription", + "Port Description", NULL, NULL, NULL), + NULL, "Port description", NULL, cmd_store_env_value, + "port-descr"), + NEWLINE, "Set port description", NULL, cmd_port_descr, NULL); + + commands_new(commands_new(configure_lldp, "capabilities-advertisements", + "Enable chassis capabilities advertisement", cmd_check_no_env, + NULL, "ports"), + NEWLINE, "Enable chassis capabilities advertisement", NULL, + cmd_chassis_cap_advertise, "enable"); + commands_new(commands_new(unconfigure_lldp, "capabilities-advertisements", + "Don't enable chassis capabilities advertisement", + cmd_check_no_env, NULL, "ports"), + NEWLINE, "Don't enable chassis capabilities advertisement", NULL, + cmd_chassis_cap_advertise, NULL); + + commands_new(commands_new(configure_lldp, "management-addresses-advertisements", + "Enable management addresses advertisement", cmd_check_no_env, + NULL, "ports"), + NEWLINE, "Enable management addresses advertisement", NULL, + cmd_chassis_mgmt_advertise, "enable"); + commands_new(commands_new(unconfigure_lldp, + "management-addresses-advertisements", + "Don't enable management addresses advertisement", + cmd_check_no_env, NULL, "ports"), + NEWLINE, "Don't enable management addresses advertisement", NULL, + cmd_chassis_mgmt_advertise, NULL); + + struct cmd_node *vlan_tx = + commands_new(commands_new(configure_lldp, "vlan-tx", + "Send LLDP frames with a VLAN tag", NULL, NULL, NULL), + NULL, "VLAN ID (0-4094)", NULL, cmd_store_env_value, "vlan-tx-id"); + + struct cmd_node *vlan_tx_prio = + commands_new(commands_new(vlan_tx, "priority", + "Also set a priority in a VLAN tag (default 0)", NULL, + NULL, NULL), + NULL, "Priority to be included in a VLAN tag (0-7)", NULL, + cmd_store_env_value, "vlan-tx-prio"); + + commands_new(vlan_tx, NEWLINE, "Enable VLAN tagging of transmitted LLDP frames", + NULL, cmd_vlan_tx, "enable"); + + commands_new(vlan_tx_prio, NEWLINE, + "Set VLAN ID and priority for transmitted frames", NULL, cmd_vlan_tx, + "enable"); commands_new( - commands_new( - commands_new(vlan_tx_prio, - "dei", - "Also set a Drop eligible indicator (DEI) in a VLAN tag (default 0)", - NULL, NULL, NULL), - NULL, "Drop eligible indicator (DEI) in a VLAN tag (0-don't drop; 1-drop)", - NULL, cmd_store_env_value, "vlan-tx-dei"), - NEWLINE, "Set VLAN ID, priority and DEI for transmitted frames", - NULL, cmd_vlan_tx, "enable"); - - commands_new( - commands_new(unconfigure_lldp, - "vlan-tx", - "Send LLDP frames without VLAN tag", + commands_new( + commands_new(vlan_tx_prio, "dei", + "Also set a Drop eligible indicator (DEI) in a VLAN tag (default 0)", NULL, NULL, NULL), - NEWLINE, "Disable VLAN tagging of transmitted LLDP frames", - NULL, cmd_vlan_tx, NULL); - + NULL, + "Drop eligible indicator (DEI) in a VLAN tag (0-don't drop; 1-drop)", + NULL, cmd_store_env_value, "vlan-tx-dei"), + NEWLINE, "Set VLAN ID, priority and DEI for transmitted frames", NULL, + cmd_vlan_tx, "enable"); + + commands_new(commands_new(unconfigure_lldp, "vlan-tx", + "Send LLDP frames without VLAN tag", NULL, NULL, NULL), + NEWLINE, "Disable VLAN tagging of transmitted LLDP frames", NULL, + cmd_vlan_tx, NULL); #ifdef ENABLE_CUSTOM register_commands_configure_lldp_custom_tlvs(configure_lldp, unconfigure_lldp); diff --git a/src/client/conf-med.c b/src/client/conf-med.c index 180272a8..dff7ab91 100644 --- a/src/client/conf-med.c +++ b/src/client/conf-med.c @@ -22,8 +22,7 @@ #include "../log.h" static int -_cmd_medlocation(struct lldpctl_conn_t *conn, - struct cmd_env *env, int format) +_cmd_medlocation(struct lldpctl_conn_t *conn, struct cmd_env *env, int format) { lldpctl_atom_t *port; const char *name; @@ -34,7 +33,8 @@ _cmd_medlocation(struct lldpctl_conn_t *conn, med_locations = lldpctl_atom_get(port, lldpctl_k_port_med_locations); if (med_locations == NULL) { - log_warnx("lldpctl", "unable to set LLDP-MED location: support seems unavailable"); + log_warnx("lldpctl", + "unable to set LLDP-MED location: support seems unavailable"); continue; /* Iterator needs to be run until end */ } @@ -44,36 +44,43 @@ _cmd_medlocation(struct lldpctl_conn_t *conn, switch (format) { case LLDP_MED_LOCFORMAT_COORD: - if ((what = "format", lldpctl_atom_set_int(med_location, - lldpctl_k_med_location_format, - format)) == NULL || - (what = "latitude", lldpctl_atom_set_str(med_location, - lldpctl_k_med_location_latitude, - cmdenv_get(env, "latitude"))) == NULL || - (what = "longitude", lldpctl_atom_set_str(med_location, - lldpctl_k_med_location_longitude, - cmdenv_get(env, "longitude"))) == NULL || - (what = "altitude", lldpctl_atom_set_str(med_location, - lldpctl_k_med_location_altitude, - cmdenv_get(env, "altitude"))) == NULL || - (what = "altitude unit", lldpctl_atom_set_str(med_location, - lldpctl_k_med_location_altitude_unit, - cmdenv_get(env, "altitude-unit"))) == NULL || - (what = "datum", lldpctl_atom_set_str(med_location, - lldpctl_k_med_location_geoid, - cmdenv_get(env, "datum"))) == NULL) + if ((what = "format", + lldpctl_atom_set_int(med_location, + lldpctl_k_med_location_format, format)) == NULL || + (what = "latitude", + lldpctl_atom_set_str(med_location, + lldpctl_k_med_location_latitude, + cmdenv_get(env, "latitude"))) == NULL || + (what = "longitude", + lldpctl_atom_set_str(med_location, + lldpctl_k_med_location_longitude, + cmdenv_get(env, "longitude"))) == NULL || + (what = "altitude", + lldpctl_atom_set_str(med_location, + lldpctl_k_med_location_altitude, + cmdenv_get(env, "altitude"))) == NULL || + (what = "altitude unit", + lldpctl_atom_set_str(med_location, + lldpctl_k_med_location_altitude_unit, + cmdenv_get(env, "altitude-unit"))) == NULL || + (what = "datum", + lldpctl_atom_set_str(med_location, + lldpctl_k_med_location_geoid, + cmdenv_get(env, "datum"))) == NULL) log_warnx("lldpctl", "unable to set LLDP MED location value for %s on %s. %s.", what, name, lldpctl_last_strerror(conn)); - else ok = 1; + else + ok = 1; break; case LLDP_MED_LOCFORMAT_CIVIC: - if ((what = "format", lldpctl_atom_set_int(med_location, - lldpctl_k_med_location_format, - format)) == NULL || - (what = "country", lldpctl_atom_set_str(med_location, - lldpctl_k_med_location_country, - cmdenv_get(env, "country"))) == NULL) { + if ((what = "format", + lldpctl_atom_set_int(med_location, + lldpctl_k_med_location_format, format)) == NULL || + (what = "country", + lldpctl_atom_set_str(med_location, + lldpctl_k_med_location_country, + cmdenv_get(env, "country"))) == NULL) { log_warnx("lldpctl", "unable to set LLDP MED location value for %s on %s. %s.", what, name, lldpctl_last_strerror(conn)); @@ -82,27 +89,29 @@ _cmd_medlocation(struct lldpctl_conn_t *conn, ok = 1; for (lldpctl_map_t *addr_map = lldpctl_key_get_map(lldpctl_k_med_civicaddress_type); - addr_map->string; - addr_map++) { + addr_map->string; addr_map++) { lldpctl_atom_t *cael, *caels; const char *value = cmdenv_get(env, addr_map->string); if (!value) continue; - caels = lldpctl_atom_get(med_location, lldpctl_k_med_location_ca_elements); + caels = lldpctl_atom_get(med_location, + lldpctl_k_med_location_ca_elements); cael = lldpctl_atom_create(caels); - if (lldpctl_atom_set_str(cael, lldpctl_k_med_civicaddress_type, + if (lldpctl_atom_set_str(cael, + lldpctl_k_med_civicaddress_type, addr_map->string) == NULL || - lldpctl_atom_set_str(cael, lldpctl_k_med_civicaddress_value, + lldpctl_atom_set_str(cael, + lldpctl_k_med_civicaddress_value, value) == NULL || lldpctl_atom_set(med_location, lldpctl_k_med_location_ca_elements, cael) == NULL) { - log_warnx("lldpctl", - "unable to add a civic address element `%s`. %s", - addr_map->string, - lldpctl_last_strerror(conn)); - ok = 0; + log_warnx("lldpctl", + "unable to add a civic address element `%s`. %s", + addr_map->string, + lldpctl_last_strerror(conn)); + ok = 0; } lldpctl_atom_dec_ref(cael); @@ -114,20 +123,24 @@ _cmd_medlocation(struct lldpctl_conn_t *conn, if (lldpctl_atom_set_int(med_location, lldpctl_k_med_location_format, format) == NULL || lldpctl_atom_set_str(med_location, - lldpctl_k_med_location_elin, cmdenv_get(env, "elin")) == NULL) - log_warnx("lldpctl", "unable to set LLDP MED location on %s. %s", - name, lldpctl_last_strerror(conn)); - else ok = 1; + lldpctl_k_med_location_elin, + cmdenv_get(env, "elin")) == NULL) + log_warnx("lldpctl", + "unable to set LLDP MED location on %s. %s", name, + lldpctl_last_strerror(conn)); + else + ok = 1; break; } if (ok) { if (lldpctl_atom_set(port, lldpctl_k_port_med_locations, med_location) == NULL) { - log_warnx("lldpctl", "unable to set LLDP MED location on %s. %s.", - name, lldpctl_last_strerror(conn)); + log_warnx("lldpctl", + "unable to set LLDP MED location on %s. %s.", name, + lldpctl_last_strerror(conn)); } else - log_info("lldpctl", "LLDP-MED location has been set for port %s", - name); + log_info("lldpctl", + "LLDP-MED location has been set for port %s", name); } lldpctl_atom_dec_ref(med_location); @@ -153,28 +166,30 @@ cmd_medlocation_address(struct lldpctl_conn_t *conn, struct writer *w, } static int -cmd_medlocation_elin(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_medlocation_elin(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "set MED location ELIN"); return _cmd_medlocation(conn, env, LLDP_MED_LOCFORMAT_ELIN); } static int -cmd_medpolicy(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_medpolicy(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "set MED policy"); lldpctl_atom_t *iface; while ((iface = cmd_iterate_on_interfaces(conn, env))) { - const char *name = lldpctl_atom_get_str(iface, lldpctl_k_interface_name); + const char *name = + lldpctl_atom_get_str(iface, lldpctl_k_interface_name); lldpctl_atom_t *port = lldpctl_get_port(iface); lldpctl_atom_t *med_policy = NULL, *med_policies = NULL; const char *what = NULL; med_policies = lldpctl_atom_get(port, lldpctl_k_port_med_policies); if (med_policies == NULL) { - log_warnx("lldpctl", "unable to set LLDP-MED policies: support seems unavailable"); + log_warnx("lldpctl", + "unable to set LLDP-MED policies: support seems unavailable"); goto end; } @@ -182,49 +197,46 @@ cmd_medpolicy(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_atom_iter_next(med_policies, lldpctl_atom_iter(med_policies))); - if ((what = "application", lldpctl_atom_set_str(med_policy, - lldpctl_k_med_policy_type, + if ((what = "application", + lldpctl_atom_set_str(med_policy, lldpctl_k_med_policy_type, cmdenv_get(env, "application"))) == NULL || - (what = "unknown flag", lldpctl_atom_set_int(med_policy, - lldpctl_k_med_policy_unknown, - cmdenv_get(env, "unknown")?1:0)) == NULL || - (what = "tagged flag", lldpctl_atom_set_int(med_policy, - lldpctl_k_med_policy_tagged, - cmdenv_get(env, "tagged")?1:0)) == NULL || + (what = "unknown flag", + lldpctl_atom_set_int(med_policy, lldpctl_k_med_policy_unknown, + cmdenv_get(env, "unknown") ? 1 : 0)) == NULL || + (what = "tagged flag", + lldpctl_atom_set_int(med_policy, lldpctl_k_med_policy_tagged, + cmdenv_get(env, "tagged") ? 1 : 0)) == NULL || (what = "vlan", - cmdenv_get(env, "vlan")? - lldpctl_atom_set_str(med_policy, - lldpctl_k_med_policy_vid, - cmdenv_get(env, "vlan")): - lldpctl_atom_set_int(med_policy, - lldpctl_k_med_policy_vid, 0)) == NULL || + cmdenv_get(env, "vlan") ? + lldpctl_atom_set_str(med_policy, lldpctl_k_med_policy_vid, + cmdenv_get(env, "vlan")) : + lldpctl_atom_set_int(med_policy, lldpctl_k_med_policy_vid, + 0)) == NULL || (what = "priority", - cmdenv_get(env, "priority")? - lldpctl_atom_set_str(med_policy, - lldpctl_k_med_policy_priority, - cmdenv_get(env, "priority")): - lldpctl_atom_set_int(med_policy, - lldpctl_k_med_policy_priority, - 0)) == NULL || + cmdenv_get(env, "priority") ? + lldpctl_atom_set_str(med_policy, + lldpctl_k_med_policy_priority, + cmdenv_get(env, "priority")) : + lldpctl_atom_set_int(med_policy, + lldpctl_k_med_policy_priority, 0)) == NULL || (what = "dscp", - cmdenv_get(env, "dscp")? - lldpctl_atom_set_str(med_policy, - lldpctl_k_med_policy_dscp, - cmdenv_get(env, "dscp")): - lldpctl_atom_set_int(med_policy, - lldpctl_k_med_policy_dscp, - 0)) == NULL) + cmdenv_get(env, "dscp") ? + lldpctl_atom_set_str(med_policy, lldpctl_k_med_policy_dscp, + cmdenv_get(env, "dscp")) : + lldpctl_atom_set_int(med_policy, lldpctl_k_med_policy_dscp, + 0)) == NULL) log_warnx("lldpctl", "unable to set LLDP MED policy value for %s on %s. %s.", what, name, lldpctl_last_strerror(conn)); else { if (lldpctl_atom_set(port, lldpctl_k_port_med_policies, med_policy) == NULL) { - log_warnx("lldpctl", "unable to set LLDP MED policy on %s. %s.", - name, lldpctl_last_strerror(conn)); + log_warnx("lldpctl", + "unable to set LLDP MED policy on %s. %s.", name, + lldpctl_last_strerror(conn)); } else - log_info("lldpctl", "LLDP-MED policy has been set for port %s", - name); + log_info("lldpctl", + "LLDP-MED policy has been set for port %s", name); } end: @@ -242,51 +254,36 @@ static void register_commands_medloc_coord(struct cmd_node *configure_medlocation) { /* MED location coordinate (set) */ - struct cmd_node *configure_medloc_coord = commands_new( - configure_medlocation, - "coordinate", "MED location coordinate configuration", - NULL, NULL, NULL); - commands_new(configure_medloc_coord, - NEWLINE, "Configure MED location coordinates", - cmd_check_env, cmd_medlocation_coordinate, + struct cmd_node *configure_medloc_coord = commands_new(configure_medlocation, + "coordinate", "MED location coordinate configuration", NULL, NULL, NULL); + commands_new(configure_medloc_coord, NEWLINE, + "Configure MED location coordinates", cmd_check_env, + cmd_medlocation_coordinate, "latitude,longitude,altitude,altitude-unit,datum"); - commands_new( - commands_new( - configure_medloc_coord, - "latitude", "Specify latitude", - cmd_check_no_env, NULL, "latitude"), - NULL, "Latitude as xx.yyyyN or xx.yyyyS", - NULL, cmd_store_env_value_and_pop2, "latitude"); - commands_new( - commands_new( - configure_medloc_coord, - "longitude", "Specify longitude", - cmd_check_no_env, NULL, "longitude"), - NULL, "Longitude as xx.yyyyE or xx.yyyyW", - NULL, cmd_store_env_value_and_pop2, "longitude"); - struct cmd_node *altitude = commands_new( - commands_new( - configure_medloc_coord, - "altitude", "Specify altitude", - cmd_check_no_env, NULL, "altitude"), - NULL, "Altitude", - NULL, cmd_store_env_value, "altitude"); - commands_new(altitude, - "m", "meters", - NULL, cmd_store_env_value_and_pop3, "altitude-unit"); - commands_new(altitude, - "f", "floors", - NULL, cmd_store_env_value_and_pop3, "altitude-unit"); - - struct cmd_node *datum = commands_new(configure_medloc_coord, - "datum", "Specify datum", - cmd_check_no_env, NULL, "datum"); + commands_new(commands_new(configure_medloc_coord, "latitude", + "Specify latitude", cmd_check_no_env, NULL, "latitude"), + NULL, "Latitude as xx.yyyyN or xx.yyyyS", NULL, + cmd_store_env_value_and_pop2, "latitude"); + commands_new(commands_new(configure_medloc_coord, "longitude", + "Specify longitude", cmd_check_no_env, NULL, "longitude"), + NULL, "Longitude as xx.yyyyE or xx.yyyyW", NULL, + cmd_store_env_value_and_pop2, "longitude"); + struct cmd_node *altitude = + commands_new(commands_new(configure_medloc_coord, "altitude", + "Specify altitude", cmd_check_no_env, NULL, "altitude"), + NULL, "Altitude", NULL, cmd_store_env_value, "altitude"); + commands_new(altitude, "m", "meters", NULL, cmd_store_env_value_and_pop3, + "altitude-unit"); + commands_new(altitude, "f", "floors", NULL, cmd_store_env_value_and_pop3, + "altitude-unit"); + + struct cmd_node *datum = commands_new(configure_medloc_coord, "datum", + "Specify datum", cmd_check_no_env, NULL, "datum"); for (lldpctl_map_t *datum_map = lldpctl_key_get_map(lldpctl_k_med_location_geoid); - datum_map->string; - datum_map++) - commands_new(datum, datum_map->string, NULL, - NULL, cmd_store_env_value_and_pop2, "datum"); + datum_map->string; datum_map++) + commands_new(datum, datum_map->string, NULL, NULL, + cmd_store_env_value_and_pop2, "datum"); } /** @@ -296,39 +293,28 @@ static void register_commands_medloc_addr(struct cmd_node *configure_medlocation) { /* MED location address (set) */ - struct cmd_node *configure_medloc_addr = commands_new( - configure_medlocation, - "address", "MED location address configuration", - NULL, NULL, NULL); - commands_new(configure_medloc_addr, - NEWLINE, "Configure MED location address", - cmd_check_env, cmd_medlocation_address, - "country"); + struct cmd_node *configure_medloc_addr = commands_new(configure_medlocation, + "address", "MED location address configuration", NULL, NULL, NULL); + commands_new(configure_medloc_addr, NEWLINE, "Configure MED location address", + cmd_check_env, cmd_medlocation_address, "country"); /* Country */ - commands_new( - commands_new( - configure_medloc_addr, - "country", "Specify country (mandatory)", - cmd_check_no_env, NULL, "country"), - NULL, "Country as a two-letter code", - NULL, cmd_store_env_value_and_pop2, "country"); + commands_new(commands_new(configure_medloc_addr, "country", + "Specify country (mandatory)", cmd_check_no_env, NULL, + "country"), + NULL, "Country as a two-letter code", NULL, cmd_store_env_value_and_pop2, + "country"); /* Other fields */ for (lldpctl_map_t *addr_map = lldpctl_key_get_map(lldpctl_k_med_civicaddress_type); - addr_map->string; - addr_map++) { + addr_map->string; addr_map++) { const char *tag = strdup(totag(addr_map->string)); SUPPRESS_LEAK(tag); - commands_new( - commands_new( - configure_medloc_addr, - tag, - addr_map->string, - cmd_check_no_env, NULL, addr_map->string), - NULL, addr_map->string, - NULL, cmd_store_env_value_and_pop2, addr_map->string); + commands_new(commands_new(configure_medloc_addr, tag, addr_map->string, + cmd_check_no_env, NULL, addr_map->string), + NULL, addr_map->string, NULL, cmd_store_env_value_and_pop2, + addr_map->string); } } @@ -339,16 +325,11 @@ static void register_commands_medloc_elin(struct cmd_node *configure_medlocation) { /* MED location elin (set) */ - commands_new( - commands_new( - commands_new( - configure_medlocation, - "elin", "MED location ELIN configuration", - NULL, NULL, NULL), - NULL, "ELIN number", - NULL, cmd_store_env_value, "elin"), - NEWLINE, "Set MED location ELIN number", - NULL, cmd_medlocation_elin, NULL); + commands_new(commands_new(commands_new(configure_medlocation, "elin", + "MED location ELIN configuration", NULL, NULL, + NULL), + NULL, "ELIN number", NULL, cmd_store_env_value, "elin"), + NEWLINE, "Set MED location ELIN number", NULL, cmd_medlocation_elin, NULL); } /** @@ -357,10 +338,8 @@ register_commands_medloc_elin(struct cmd_node *configure_medlocation) static void register_commands_medloc(struct cmd_node *configure_med) { - struct cmd_node *configure_medlocation = commands_new( - configure_med, - "location", "MED location configuration", - NULL, NULL, NULL); + struct cmd_node *configure_medlocation = commands_new(configure_med, "location", + "MED location configuration", NULL, NULL, NULL); register_commands_medloc_coord(configure_medlocation); register_commands_medloc_addr(configure_medlocation); @@ -394,80 +373,52 @@ cmd_store_prio_env_value_and_pop2(struct lldpctl_conn_t *conn, struct writer *w, static void register_commands_medpol(struct cmd_node *configure_med) { - struct cmd_node *configure_medpolicy = commands_new( - configure_med, - "policy", "MED policy configuration", - NULL, NULL, NULL); + struct cmd_node *configure_medpolicy = commands_new(configure_med, "policy", + "MED policy configuration", NULL, NULL, NULL); - commands_new( - configure_medpolicy, - NEWLINE, "Apply new MED policy", - cmd_check_env, cmd_medpolicy, "application"); + commands_new(configure_medpolicy, NEWLINE, "Apply new MED policy", + cmd_check_env, cmd_medpolicy, "application"); /* Application */ struct cmd_node *configure_application = - commands_new( - configure_medpolicy, - "application", "MED policy application", - cmd_check_no_env, NULL, "application"); - - for (lldpctl_map_t *pol_map = - lldpctl_key_get_map(lldpctl_k_med_policy_type); - pol_map->string; - pol_map++) { + commands_new(configure_medpolicy, "application", "MED policy application", + cmd_check_no_env, NULL, "application"); + + for (lldpctl_map_t *pol_map = lldpctl_key_get_map(lldpctl_k_med_policy_type); + pol_map->string; pol_map++) { char *tag = strdup(totag(pol_map->string)); SUPPRESS_LEAK(tag); - commands_new( - configure_application, - tag, - pol_map->string, - NULL, cmd_store_app_env_value_and_pop2, pol_map->string); + commands_new(configure_application, tag, pol_map->string, NULL, + cmd_store_app_env_value_and_pop2, pol_map->string); } /* Remaining keywords */ - commands_new( - configure_medpolicy, - "unknown", "Set unknown flag", - cmd_check_application_but_no, cmd_store_env_and_pop, "unknown"); - commands_new( - configure_medpolicy, - "tagged", "Set tagged flag", - cmd_check_application_but_no, cmd_store_env_and_pop, "tagged"); - commands_new( - commands_new( - configure_medpolicy, - "vlan", "VLAN advertising", - cmd_check_application_but_no, NULL, "vlan"), - NULL, "VLAN ID to advertise", - NULL, cmd_store_env_value_and_pop2, "vlan"); - commands_new( - commands_new( - configure_medpolicy, - "dscp", "DiffServ advertising", - cmd_check_application_but_no, NULL, "dscp"), - NULL, "DSCP value to advertise (between 0 and 63)", - NULL, cmd_store_env_value_and_pop2, "dscp"); - struct cmd_node *priority = - commands_new( - configure_medpolicy, - "priority", "MED policy priority", - cmd_check_application_but_no, NULL, "priority"); + commands_new(configure_medpolicy, "unknown", "Set unknown flag", + cmd_check_application_but_no, cmd_store_env_and_pop, "unknown"); + commands_new(configure_medpolicy, "tagged", "Set tagged flag", + cmd_check_application_but_no, cmd_store_env_and_pop, "tagged"); + commands_new(commands_new(configure_medpolicy, "vlan", "VLAN advertising", + cmd_check_application_but_no, NULL, "vlan"), + NULL, "VLAN ID to advertise", NULL, cmd_store_env_value_and_pop2, "vlan"); + commands_new(commands_new(configure_medpolicy, "dscp", "DiffServ advertising", + cmd_check_application_but_no, NULL, "dscp"), + NULL, "DSCP value to advertise (between 0 and 63)", NULL, + cmd_store_env_value_and_pop2, "dscp"); + struct cmd_node *priority = commands_new(configure_medpolicy, "priority", + "MED policy priority", cmd_check_application_but_no, NULL, "priority"); for (lldpctl_map_t *prio_map = lldpctl_key_get_map(lldpctl_k_med_policy_priority); - prio_map->string; - prio_map++) { + prio_map->string; prio_map++) { char *tag = strdup(totag(prio_map->string)); SUPPRESS_LEAK(tag); - commands_new( - priority, - tag, prio_map->string, - NULL, cmd_store_prio_env_value_and_pop2, prio_map->string); + commands_new(priority, tag, prio_map->string, NULL, + cmd_store_prio_env_value_and_pop2, prio_map->string); } } static int -cmd_faststart(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_faststart(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "configure fast interval support"); @@ -480,15 +431,14 @@ cmd_faststart(struct lldpctl_conn_t *conn, struct writer *w, char *action = arg; if ((!strcmp(action, "enable") && - (lldpctl_atom_set_int(config, - lldpctl_k_config_fast_start_enabled, 1) == NULL)) || + (lldpctl_atom_set_int(config, lldpctl_k_config_fast_start_enabled, 1) == + NULL)) || (!strcmp(action, "disable") && - (lldpctl_atom_set_int(config, - lldpctl_k_config_fast_start_enabled, 0) == NULL)) || + (lldpctl_atom_set_int(config, lldpctl_k_config_fast_start_enabled, 0) == + NULL)) || (!strcmp(action, "delay") && - (lldpctl_atom_set_str(config, - lldpctl_k_config_fast_start_interval, - cmdenv_get(env, "tx-interval")) == NULL))) { + (lldpctl_atom_set_str(config, lldpctl_k_config_fast_start_interval, + cmdenv_get(env, "tx-interval")) == NULL))) { log_warnx("lldpctl", "unable to setup fast start. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); @@ -505,63 +455,42 @@ cmd_faststart(struct lldpctl_conn_t *conn, struct writer *w, static void register_commands_medfast(struct cmd_node *med, struct cmd_node *nomed) { - struct cmd_node *configure_fast = commands_new( - med, - "fast-start", "Fast start configuration", - cmd_check_no_env, NULL, "ports"); - struct cmd_node *unconfigure_fast = commands_new( - nomed, - "fast-start", "Fast start configuration", - cmd_check_no_env, NULL, "ports"); + struct cmd_node *configure_fast = commands_new(med, "fast-start", + "Fast start configuration", cmd_check_no_env, NULL, "ports"); + struct cmd_node *unconfigure_fast = commands_new(nomed, "fast-start", + "Fast start configuration", cmd_check_no_env, NULL, "ports"); /* Enable */ - commands_new( - commands_new( - configure_fast, - "enable", "Enable fast start", - NULL, NULL, NULL), - NEWLINE, "Enable fast start", - NULL, cmd_faststart, "enable"); + commands_new(commands_new(configure_fast, "enable", "Enable fast start", NULL, + NULL, NULL), + NEWLINE, "Enable fast start", NULL, cmd_faststart, "enable"); /* Set TX delay */ - commands_new( - commands_new( - commands_new(configure_fast, - "tx-interval", "Set LLDP fast transmit delay", - NULL, NULL, NULL), - NULL, "LLDP fast transmit delay in seconds", - NULL, cmd_store_env_value, "tx-interval"), - NEWLINE, "Set LLDP fast transmit delay", - NULL, cmd_faststart, "delay"); + commands_new(commands_new(commands_new(configure_fast, "tx-interval", + "Set LLDP fast transmit delay", NULL, NULL, NULL), + NULL, "LLDP fast transmit delay in seconds", NULL, + cmd_store_env_value, "tx-interval"), + NEWLINE, "Set LLDP fast transmit delay", NULL, cmd_faststart, "delay"); /* Disable */ - commands_new( - commands_new( - unconfigure_fast, - NEWLINE, "Disable fast start", - NULL, cmd_faststart, "disable"), - NEWLINE, "Disable fast start", - NULL, cmd_faststart, "disable"); + commands_new(commands_new(unconfigure_fast, NEWLINE, "Disable fast start", NULL, + cmd_faststart, "disable"), + NEWLINE, "Disable fast start", NULL, cmd_faststart, "disable"); } /** * Register "configure med *" */ void -register_commands_configure_med(struct cmd_node *configure, struct cmd_node *unconfigure) +register_commands_configure_med(struct cmd_node *configure, + struct cmd_node *unconfigure) { - if (lldpctl_key_get_map( - lldpctl_k_med_policy_type)[0].string == NULL) - return; - - struct cmd_node *configure_med = commands_new( - configure, - "med", "MED configuration", - NULL, NULL, NULL); - struct cmd_node *unconfigure_med = commands_new( - unconfigure, - "med", "MED configuration", - NULL, NULL, NULL); + if (lldpctl_key_get_map(lldpctl_k_med_policy_type)[0].string == NULL) return; + + struct cmd_node *configure_med = + commands_new(configure, "med", "MED configuration", NULL, NULL, NULL); + struct cmd_node *unconfigure_med = + commands_new(unconfigure, "med", "MED configuration", NULL, NULL, NULL); register_commands_medloc(configure_med); register_commands_medpol(configure_med); diff --git a/src/client/conf-power.c b/src/client/conf-power.c index ef6f9ccd..38f25361 100644 --- a/src/client/conf-power.c +++ b/src/client/conf-power.c @@ -22,8 +22,8 @@ #include "../log.h" static int -cmd_medpower(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_medpower(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "set MED power"); lldpctl_atom_t *port; @@ -34,33 +34,35 @@ cmd_medpower(struct lldpctl_conn_t *conn, struct writer *w, med_power = lldpctl_atom_get(port, lldpctl_k_port_med_power); if (med_power == NULL) { - log_warnx("lldpctl", "unable to set LLDP-MED power: support seems unavailable"); + log_warnx("lldpctl", + "unable to set LLDP-MED power: support seems unavailable"); continue; /* Need to finish the loop */ } - if ((what = "device type", lldpctl_atom_set_str(med_power, - lldpctl_k_med_power_type, + if ((what = "device type", + lldpctl_atom_set_str(med_power, lldpctl_k_med_power_type, cmdenv_get(env, "device-type"))) == NULL || - (what = "power source", lldpctl_atom_set_str(med_power, - lldpctl_k_med_power_source, - cmdenv_get(env, "source"))) == NULL || - (what = "power priority", lldpctl_atom_set_str(med_power, - lldpctl_k_med_power_priority, - cmdenv_get(env, "priority"))) == NULL || - (what = "power value", lldpctl_atom_set_str(med_power, - lldpctl_k_med_power_val, - cmdenv_get(env, "value"))) == NULL) + (what = "power source", + lldpctl_atom_set_str(med_power, lldpctl_k_med_power_source, + cmdenv_get(env, "source"))) == NULL || + (what = "power priority", + lldpctl_atom_set_str(med_power, lldpctl_k_med_power_priority, + cmdenv_get(env, "priority"))) == NULL || + (what = "power value", + lldpctl_atom_set_str(med_power, lldpctl_k_med_power_val, + cmdenv_get(env, "value"))) == NULL) log_warnx("lldpctl", "unable to set LLDP MED power value for %s on %s. %s.", what, name, lldpctl_last_strerror(conn)); else { if (lldpctl_atom_set(port, lldpctl_k_port_med_power, med_power) == NULL) { - log_warnx("lldpctl", "unable to set LLDP MED power on %s. %s.", - name, lldpctl_last_strerror(conn)); + log_warnx("lldpctl", + "unable to set LLDP MED power on %s. %s.", name, + lldpctl_last_strerror(conn)); } else - log_info("lldpctl", "LLDP-MED power has been set for port %s", - name); + log_info("lldpctl", + "LLDP-MED power has been set for port %s", name); } lldpctl_atom_dec_ref(med_power); @@ -88,8 +90,8 @@ cmd_store_prio_env_value_and_pop2(struct lldpctl_conn_t *conn, struct writer *w, } static int -cmd_dot3power(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_dot3power(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "set dot3 power"); lldpctl_atom_t *port; @@ -101,36 +103,40 @@ cmd_dot3power(struct lldpctl_conn_t *conn, struct writer *w, dot3_power = lldpctl_atom_get(port, lldpctl_k_port_dot3_power); if (dot3_power == NULL) { - log_warnx("lldpctl", "unable to set Dot3 power: support seems unavailable"); + log_warnx("lldpctl", + "unable to set Dot3 power: support seems unavailable"); continue; /* Need to finish the loop */ } - if ((what = "device type", lldpctl_atom_set_str(dot3_power, + if ((what = "device type", + lldpctl_atom_set_str(dot3_power, lldpctl_k_dot3_power_devicetype, cmdenv_get(env, "device-type"))) == NULL || /* Flags */ - (what = "supported flag", lldpctl_atom_set_int(dot3_power, - lldpctl_k_dot3_power_supported, - cmdenv_get(env, "supported")?1:0)) == NULL || - (what = "enabled flag", lldpctl_atom_set_int(dot3_power, - lldpctl_k_dot3_power_enabled, - cmdenv_get(env, "enabled")?1:0)) == NULL || - (what = "paircontrol flag", lldpctl_atom_set_int(dot3_power, - lldpctl_k_dot3_power_paircontrol, - cmdenv_get(env, "paircontrol")?1:0)) == NULL || + (what = "supported flag", + lldpctl_atom_set_int(dot3_power, lldpctl_k_dot3_power_supported, + cmdenv_get(env, "supported") ? 1 : 0)) == NULL || + (what = "enabled flag", + lldpctl_atom_set_int(dot3_power, lldpctl_k_dot3_power_enabled, + cmdenv_get(env, "enabled") ? 1 : 0)) == NULL || + (what = "paircontrol flag", + lldpctl_atom_set_int(dot3_power, + lldpctl_k_dot3_power_paircontrol, + cmdenv_get(env, "paircontrol") ? 1 : 0)) == NULL || /* Powerpairs */ - (what = "power pairs", lldpctl_atom_set_str(dot3_power, - lldpctl_k_dot3_power_pairs, - cmdenv_get(env, "powerpairs"))) == NULL || + (what = "power pairs", + lldpctl_atom_set_str(dot3_power, lldpctl_k_dot3_power_pairs, + cmdenv_get(env, "powerpairs"))) == NULL || /* Class */ - (what = "power class", cmdenv_get(env, "class")? - lldpctl_atom_set_str(dot3_power, - lldpctl_k_dot3_power_class, - cmdenv_get(env, "class")): - lldpctl_atom_set_int(dot3_power, - lldpctl_k_dot3_power_class, 0)) == NULL || - (what = "802.3at type", lldpctl_atom_set_int(dot3_power, - lldpctl_k_dot3_power_type, 0)) == NULL) { + (what = "power class", + cmdenv_get(env, "class") ? + lldpctl_atom_set_str(dot3_power, lldpctl_k_dot3_power_class, + cmdenv_get(env, "class")) : + lldpctl_atom_set_int(dot3_power, lldpctl_k_dot3_power_class, + 0)) == NULL || + (what = "802.3at type", + lldpctl_atom_set_int(dot3_power, lldpctl_k_dot3_power_type, + 0)) == NULL) { log_warnx("lldpctl", "unable to set LLDP Dot3 power value for %s on %s. %s.", what, name, lldpctl_last_strerror(conn)); @@ -138,27 +144,37 @@ cmd_dot3power(struct lldpctl_conn_t *conn, struct writer *w, } else if (cmdenv_get(env, "typeat")) { int typeat = cmdenv_get(env, "typeat")[0] - '0'; const char *source = cmdenv_get(env, "source"); - if ((what = "802.3at type", lldpctl_atom_set_int(dot3_power, - lldpctl_k_dot3_power_type, - typeat)) == NULL || - (what = "source", lldpctl_atom_set_int(dot3_power, - lldpctl_k_dot3_power_source, - (!strcmp(source, "primary"))?LLDP_DOT3_POWER_SOURCE_PRIMARY: - (!strcmp(source, "backup"))? LLDP_DOT3_POWER_SOURCE_BACKUP: - (!strcmp(source, "pse"))? LLDP_DOT3_POWER_SOURCE_PSE: - (!strcmp(source, "local"))? LLDP_DOT3_POWER_SOURCE_LOCAL: - (!strcmp(source, "both"))? LLDP_DOT3_POWER_SOURCE_BOTH: - LLDP_DOT3_POWER_SOURCE_UNKNOWN)) == NULL || - (what = "priority", lldpctl_atom_set_str(dot3_power, - lldpctl_k_dot3_power_priority, - cmdenv_get(env, "priority"))) == NULL || - (what = "requested power", lldpctl_atom_set_str(dot3_power, - lldpctl_k_dot3_power_requested, - cmdenv_get(env, "requested"))) == NULL || - (what = "allocated power", lldpctl_atom_set_str(dot3_power, - lldpctl_k_dot3_power_allocated, - cmdenv_get(env, "allocated"))) == NULL) { - log_warnx("lldpctl", "unable to set LLDP Dot3 power value for %s on %s. %s.", + if ((what = "802.3at type", + lldpctl_atom_set_int(dot3_power, + lldpctl_k_dot3_power_type, typeat)) == NULL || + (what = "source", + lldpctl_atom_set_int(dot3_power, + lldpctl_k_dot3_power_source, + (!strcmp(source, "primary")) ? + LLDP_DOT3_POWER_SOURCE_PRIMARY : + (!strcmp(source, "backup")) ? + LLDP_DOT3_POWER_SOURCE_BACKUP : + (!strcmp(source, "pse")) ? + LLDP_DOT3_POWER_SOURCE_PSE : + (!strcmp(source, "local")) ? + LLDP_DOT3_POWER_SOURCE_LOCAL : + (!strcmp(source, "both")) ? + LLDP_DOT3_POWER_SOURCE_BOTH : + LLDP_DOT3_POWER_SOURCE_UNKNOWN)) == NULL || + (what = "priority", + lldpctl_atom_set_str(dot3_power, + lldpctl_k_dot3_power_priority, + cmdenv_get(env, "priority"))) == NULL || + (what = "requested power", + lldpctl_atom_set_str(dot3_power, + lldpctl_k_dot3_power_requested, + cmdenv_get(env, "requested"))) == NULL || + (what = "allocated power", + lldpctl_atom_set_str(dot3_power, + lldpctl_k_dot3_power_allocated, + cmdenv_get(env, "allocated"))) == NULL) { + log_warnx("lldpctl", + "unable to set LLDP Dot3 power value for %s on %s. %s.", what, name, lldpctl_last_strerror(conn)); ok = 0; } @@ -166,11 +182,12 @@ cmd_dot3power(struct lldpctl_conn_t *conn, struct writer *w, if (ok) { if (lldpctl_atom_set(port, lldpctl_k_port_dot3_power, dot3_power) == NULL) { - log_warnx("lldpctl", "unable to set LLDP Dot3 power on %s. %s.", - name, lldpctl_last_strerror(conn)); + log_warnx("lldpctl", + "unable to set LLDP Dot3 power on %s. %s.", name, + lldpctl_last_strerror(conn)); } else - log_info("lldpctl", "LLDP Dot3 power has been set for port %s", - name); + log_info("lldpctl", + "LLDP Dot3 power has been set for port %s", name); } lldpctl_atom_dec_ref(dot3_power); @@ -215,40 +232,29 @@ cmd_check_pd(struct cmd_env *env, void *arg) static void register_commands_pow_source(struct cmd_node *source) { - commands_new(source, - "unknown", "Unknown power source", - NULL, cmd_store_env_value_and_pop2, "source"); - commands_new(source, - "primary", "Primary power source", - cmd_check_pse, cmd_store_env_value_and_pop2, "source"); - commands_new(source, - "backup", "Backup power source", - cmd_check_pse, cmd_store_env_value_and_pop2, "source"); - commands_new(source, - "pse", "Power source is PSE", - cmd_check_pd, cmd_store_env_value_and_pop2, "source"); - commands_new(source, - "local", "Local power source", - cmd_check_pd, cmd_store_env_value_and_pop2, "source"); - commands_new(source, - "both", "Both PSE and local source available", + commands_new(source, "unknown", "Unknown power source", NULL, + cmd_store_env_value_and_pop2, "source"); + commands_new(source, "primary", "Primary power source", cmd_check_pse, + cmd_store_env_value_and_pop2, "source"); + commands_new(source, "backup", "Backup power source", cmd_check_pse, + cmd_store_env_value_and_pop2, "source"); + commands_new(source, "pse", "Power source is PSE", cmd_check_pd, + cmd_store_env_value_and_pop2, "source"); + commands_new(source, "local", "Local power source", cmd_check_pd, + cmd_store_env_value_and_pop2, "source"); + commands_new(source, "both", "Both PSE and local source available", cmd_check_pd, cmd_store_env_value_and_pop2, "source"); } static void register_commands_pow_priority(struct cmd_node *priority, int key) { - for (lldpctl_map_t *prio_map = - lldpctl_key_get_map(key); - prio_map->string; + for (lldpctl_map_t *prio_map = lldpctl_key_get_map(key); prio_map->string; prio_map++) { char *tag = strdup(totag(prio_map->string)); SUPPRESS_LEAK(tag); - commands_new( - priority, - tag, - prio_map->string, - NULL, cmd_store_prio_env_value_and_pop2, prio_map->string); + commands_new(priority, tag, prio_map->string, NULL, + cmd_store_prio_env_value_and_pop2, prio_map->string); } } @@ -258,47 +264,33 @@ register_commands_pow_priority(struct cmd_node *priority, int key) void register_commands_medpow(struct cmd_node *configure_med) { - struct cmd_node *configure_medpower = commands_new( - configure_med, - "power", "MED power configuration", - NULL, NULL, NULL); + struct cmd_node *configure_medpower = commands_new(configure_med, "power", + "MED power configuration", NULL, NULL, NULL); - commands_new( - configure_medpower, - NEWLINE, "Apply new MED power configuration", - cmd_check_env, cmd_medpower, "device-type,source,priority,value"); + commands_new(configure_medpower, NEWLINE, "Apply new MED power configuration", + cmd_check_env, cmd_medpower, "device-type,source,priority,value"); /* Type: PSE or PD */ - commands_new( - configure_medpower, - "pd", "MED power consumer", - cmd_check_no_env, cmd_store_env_value_and_pop, "device-type"); - commands_new( - configure_medpower, - "pse", "MED power provider", - cmd_check_no_env, cmd_store_env_value_and_pop, "device-type"); + commands_new(configure_medpower, "pd", "MED power consumer", cmd_check_no_env, + cmd_store_env_value_and_pop, "device-type"); + commands_new(configure_medpower, "pse", "MED power provider", cmd_check_no_env, + cmd_store_env_value_and_pop, "device-type"); /* Source */ - struct cmd_node *source = commands_new( - configure_medpower, - "source", "MED power source", - cmd_check_type_but_no, NULL, "source"); + struct cmd_node *source = commands_new(configure_medpower, "source", + "MED power source", cmd_check_type_but_no, NULL, "source"); register_commands_pow_source(source); /* Priority */ - struct cmd_node *priority = commands_new( - configure_medpower, - "priority", "MED power priority", - cmd_check_type_but_no, NULL, "priority"); + struct cmd_node *priority = commands_new(configure_medpower, "priority", + "MED power priority", cmd_check_type_but_no, NULL, "priority"); register_commands_pow_priority(priority, lldpctl_k_med_power_priority); /* Value */ - commands_new( - commands_new(configure_medpower, - "value", "MED power value", - cmd_check_type_but_no, NULL, "value"), - NULL, "MED power value in milliwatts", - NULL, cmd_store_env_value_and_pop2, "value"); + commands_new(commands_new(configure_medpower, "value", "MED power value", + cmd_check_type_but_no, NULL, "value"), + NULL, "MED power value in milliwatts", NULL, cmd_store_env_value_and_pop2, + "value"); } static int @@ -309,10 +301,8 @@ cmd_check_env_power(struct cmd_env *env, void *nothing) if (!cmdenv_get(env, "device-type")) return 0; if (!cmdenv_get(env, "powerpairs")) return 0; if (cmdenv_get(env, "typeat")) { - return (!!cmdenv_get(env, "source") && - !!cmdenv_get(env, "priority") && - !!cmdenv_get(env, "requested") && - !!cmdenv_get(env, "allocated")); + return (!!cmdenv_get(env, "source") && !!cmdenv_get(env, "priority") && + !!cmdenv_get(env, "requested") && !!cmdenv_get(env, "allocated")); } return 1; } @@ -323,111 +313,77 @@ cmd_check_env_power(struct cmd_env *env, void *nothing) void register_commands_dot3pow(struct cmd_node *configure_dot3) { - struct cmd_node *configure_dot3power = commands_new( - configure_dot3, - "power", "Dot3 power configuration", - NULL, NULL, NULL); + struct cmd_node *configure_dot3power = commands_new(configure_dot3, "power", + "Dot3 power configuration", NULL, NULL, NULL); - commands_new( - configure_dot3power, - NEWLINE, "Apply new Dot3 power configuration", - cmd_check_env_power, cmd_dot3power, NULL); + commands_new(configure_dot3power, NEWLINE, "Apply new Dot3 power configuration", + cmd_check_env_power, cmd_dot3power, NULL); /* Type: PSE or PD */ - commands_new( - configure_dot3power, - "pd", "Dot3 power consumer", - cmd_check_no_env, cmd_store_env_value_and_pop, "device-type"); - commands_new( - configure_dot3power, - "pse", "Dot3 power provider", - cmd_check_no_env, cmd_store_env_value_and_pop, "device-type"); + commands_new(configure_dot3power, "pd", "Dot3 power consumer", cmd_check_no_env, + cmd_store_env_value_and_pop, "device-type"); + commands_new(configure_dot3power, "pse", "Dot3 power provider", + cmd_check_no_env, cmd_store_env_value_and_pop, "device-type"); /* Flags */ - commands_new( - configure_dot3power, - "supported", "MDI power support present", - cmd_check_type_but_no, cmd_store_env_and_pop, "supported"); - commands_new( - configure_dot3power, - "enabled", "MDI power support enabled", - cmd_check_type_but_no, cmd_store_env_and_pop, "enabled"); - commands_new( - configure_dot3power, - "paircontrol", "MDI power pair can be selected", - cmd_check_type_but_no, cmd_store_env_and_pop, "paircontrol"); + commands_new(configure_dot3power, "supported", "MDI power support present", + cmd_check_type_but_no, cmd_store_env_and_pop, "supported"); + commands_new(configure_dot3power, "enabled", "MDI power support enabled", + cmd_check_type_but_no, cmd_store_env_and_pop, "enabled"); + commands_new(configure_dot3power, "paircontrol", + "MDI power pair can be selected", cmd_check_type_but_no, + cmd_store_env_and_pop, "paircontrol"); /* Power pairs */ - struct cmd_node *powerpairs = commands_new( - configure_dot3power, - "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; - pp_map++) { - commands_new( - powerpairs, - pp_map->string, - pp_map->string, - NULL, cmd_store_powerpairs_env_value_and_pop2, pp_map->string); + struct cmd_node *powerpairs = commands_new(configure_dot3power, "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; pp_map++) { + commands_new(powerpairs, pp_map->string, pp_map->string, NULL, + cmd_store_powerpairs_env_value_and_pop2, pp_map->string); } /* Class */ - struct cmd_node *class = commands_new( - configure_dot3power, - "class", "Power class", - cmd_check_type_but_no, NULL, "class"); - for (lldpctl_map_t *class_map = - lldpctl_key_get_map(lldpctl_k_dot3_power_class); - class_map->string; - class_map++) { + struct cmd_node *class = commands_new(configure_dot3power, "class", + "Power class", cmd_check_type_but_no, NULL, "class"); + for (lldpctl_map_t *class_map = lldpctl_key_get_map(lldpctl_k_dot3_power_class); + class_map->string; class_map++) { const char *tag = strdup(totag(class_map->string)); SUPPRESS_LEAK(tag); - commands_new( - class, - tag, - class_map->string, - NULL, cmd_store_class_env_value_and_pop2, class_map->string); + commands_new(class, tag, class_map->string, NULL, + cmd_store_class_env_value_and_pop2, class_map->string); } /* 802.3at type */ - struct cmd_node *typeat = commands_new( - configure_dot3power, - "type", "802.3at device type", - cmd_check_type_but_no, NULL, "typeat"); - commands_new(typeat, - "1", "802.3at type 1", - NULL, cmd_store_env_value_and_pop2, "typeat"); - commands_new(typeat, - "2", "802.3at type 2", - NULL, cmd_store_env_value_and_pop2, "typeat"); + struct cmd_node *typeat = commands_new(configure_dot3power, "type", + "802.3at device type", cmd_check_type_but_no, NULL, "typeat"); + commands_new(typeat, "1", "802.3at type 1", NULL, cmd_store_env_value_and_pop2, + "typeat"); + commands_new(typeat, "2", "802.3at type 2", NULL, cmd_store_env_value_and_pop2, + "typeat"); /* Source */ - struct cmd_node *source = commands_new( - configure_dot3power, - "source", "802.3at dot3 power source (mandatory)", - cmd_check_typeat_but_no, NULL, "source"); + struct cmd_node *source = commands_new(configure_dot3power, "source", + "802.3at dot3 power source (mandatory)", cmd_check_typeat_but_no, NULL, + "source"); register_commands_pow_source(source); /* Priority */ - struct cmd_node *priority = commands_new( - configure_dot3power, - "priority", "802.3at dot3 power priority (mandatory)", - cmd_check_typeat_but_no, NULL, "priority"); + struct cmd_node *priority = commands_new(configure_dot3power, "priority", + "802.3at dot3 power priority (mandatory)", cmd_check_typeat_but_no, NULL, + "priority"); register_commands_pow_priority(priority, lldpctl_k_dot3_power_priority); /* Values */ - commands_new( - commands_new(configure_dot3power, - "requested", "802.3at dot3 power value requested (mandatory)", - cmd_check_typeat_but_no, NULL, "requested"), - NULL, "802.3at power value requested in milliwatts", - NULL, cmd_store_env_value_and_pop2, "requested"); - commands_new( - commands_new(configure_dot3power, - "allocated", "802.3at dot3 power value allocated (mandatory)", - cmd_check_typeat_but_no, NULL, "allocated"), - NULL, "802.3at power value allocated in milliwatts", - NULL, cmd_store_env_value_and_pop2, "allocated"); + commands_new(commands_new(configure_dot3power, "requested", + "802.3at dot3 power value requested (mandatory)", + cmd_check_typeat_but_no, NULL, "requested"), + NULL, "802.3at power value requested in milliwatts", NULL, + cmd_store_env_value_and_pop2, "requested"); + commands_new(commands_new(configure_dot3power, "allocated", + "802.3at dot3 power value allocated (mandatory)", + cmd_check_typeat_but_no, NULL, "allocated"), + NULL, "802.3at power value allocated in milliwatts", NULL, + cmd_store_env_value_and_pop2, "allocated"); } diff --git a/src/client/conf-system.c b/src/client/conf-system.c index b91e95d3..554f6fc2 100644 --- a/src/client/conf-system.c +++ b/src/client/conf-system.c @@ -23,8 +23,8 @@ #include "../log.h" static int -cmd_iface_pattern(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_iface_pattern(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "set iface pattern"); @@ -36,16 +36,15 @@ cmd_iface_pattern(struct lldpctl_conn_t *conn, struct writer *w, } const char *value = cmdenv_get(env, "iface-pattern"); - if (lldpctl_atom_set_str(config, - lldpctl_k_config_iface_pattern, - value) == NULL) { + if (lldpctl_atom_set_str(config, lldpctl_k_config_iface_pattern, value) == + NULL) { log_warnx("lldpctl", "unable to set iface-pattern. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } log_info("lldpctl", "iface-pattern set to new value %s", - value?value:"(none)"); + value ? value : "(none)"); lldpctl_atom_dec_ref(config); return 1; } @@ -64,23 +63,22 @@ cmd_perm_iface_pattern(struct lldpctl_conn_t *conn, struct writer *w, } const char *value = cmdenv_get(env, "iface-pattern"); - if (lldpctl_atom_set_str(config, - lldpctl_k_config_perm_iface_pattern, - value) == NULL) { + if (lldpctl_atom_set_str(config, lldpctl_k_config_perm_iface_pattern, value) == + NULL) { log_warnx("lldpctl", "unable to set permanent iface pattern. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } log_info("lldpctl", "permanent iface pattern set to new value %s", - value?value:"(none)"); + value ? value : "(none)"); lldpctl_atom_dec_ref(config); return 1; } static int -cmd_iface_promisc(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_iface_promisc(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { lldpctl_atom_t *config = lldpctl_get_configuration(conn); if (config == NULL) { @@ -88,17 +86,15 @@ cmd_iface_promisc(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_last_strerror(conn)); return 0; } - if (lldpctl_atom_set_int(config, - lldpctl_k_config_iface_promisc, - arg?1:0) == NULL) { + if (lldpctl_atom_set_int(config, lldpctl_k_config_iface_promisc, arg ? 1 : 0) == + NULL) { log_warnx("lldpctl", "unable to %s promiscuous mode: %s", - arg?"enable":"disable", - lldpctl_last_strerror(conn)); + arg ? "enable" : "disable", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } log_info("lldpctl", "interface promiscuous mode %s", - arg?"enabled":"disabled"); + arg ? "enabled" : "disabled"); lldpctl_atom_dec_ref(config); return 1; } @@ -124,7 +120,7 @@ cmd_system_description(struct lldpctl_conn_t *conn, struct writer *w, return 0; } if (lldpctl_atom_set_str(config, - platform?lldpctl_k_config_platform:lldpctl_k_config_description, + platform ? lldpctl_k_config_platform : lldpctl_k_config_description, value) == NULL) { log_warnx("lldpctl", "unable to set description. %s", lldpctl_last_strerror(conn)); @@ -132,14 +128,14 @@ cmd_system_description(struct lldpctl_conn_t *conn, struct writer *w, return 0; } log_info("lldpctl", "description set to new value %s", - value?value:"(none)"); + value ? value : "(none)"); lldpctl_atom_dec_ref(config); return 1; } static int -cmd_system_chassisid(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_system_chassisid(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { const char *value; value = cmdenv_get(env, "description"); @@ -150,23 +146,20 @@ cmd_system_chassisid(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_last_strerror(conn)); return 0; } - if (lldpctl_atom_set_str(config, - lldpctl_k_config_cid_string, - value) == NULL) { + if (lldpctl_atom_set_str(config, lldpctl_k_config_cid_string, value) == NULL) { log_warnx("lldpctl", "unable to set chassis ID. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } - log_info("lldpctl", "chassis ID set to new value %s", - value?value:"(none)"); + log_info("lldpctl", "chassis ID set to new value %s", value ? value : "(none)"); lldpctl_atom_dec_ref(config); return 1; } static int -cmd_management(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_management(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "set management pattern"); @@ -178,22 +171,22 @@ cmd_management(struct lldpctl_conn_t *conn, struct writer *w, } const char *value = cmdenv_get(env, "management-pattern"); - if (lldpctl_atom_set_str(config, - lldpctl_k_config_mgmt_pattern, value) == NULL) { + if (lldpctl_atom_set_str(config, lldpctl_k_config_mgmt_pattern, value) == + NULL) { log_warnx("lldpctl", "unable to set management pattern. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } log_info("lldpctl", "management pattern set to new value %s", - value?value:"(none)"); + value ? value : "(none)"); lldpctl_atom_dec_ref(config); return 1; } static int -cmd_hostname(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_hostname(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { struct utsname un; log_debug("lldpctl", "set system name"); @@ -214,22 +207,21 @@ cmd_hostname(struct lldpctl_conn_t *conn, struct writer *w, } value = un.nodename; } - if (lldpctl_atom_set_str(config, - lldpctl_k_config_hostname, value) == NULL) { + if (lldpctl_atom_set_str(config, lldpctl_k_config_hostname, value) == NULL) { log_warnx("lldpctl", "unable to set system name. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } log_info("lldpctl", "system name set to new value %s", - value?value:"(none)"); + value ? value : "(none)"); lldpctl_atom_dec_ref(config); return 1; } static int -cmd_capability(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_capability(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "set capabilities"); @@ -248,7 +240,8 @@ cmd_capability(struct lldpctl_conn_t *conn, struct writer *w, if (s) { chassis = lldpctl_get_local_chassis(conn); if (chassis == NULL) { - log_warnx("lldpctl", "unable to get local chassis from lldpd. %s", + log_warnx("lldpctl", + "unable to get local chassis from lldpd. %s", lldpctl_last_strerror(conn)); goto cmd_capability_end; } @@ -274,19 +267,24 @@ cmd_capability(struct lldpctl_conn_t *conn, struct writer *w, } else if (!strcmp(token, "station")) { value |= LLDP_CAP_STATION; } else { - log_warnx("lldpctl", "capability %s not found", token); + log_warnx("lldpctl", "capability %s not found", + token); } token = strtok(NULL, delim); } free(s_copy); - if (lldpctl_atom_set_int(chassis, lldpctl_k_chassis_cap_enabled, value) == NULL) { - log_warnx("lldpctl", "unable to set system capabilities. %s", + if (lldpctl_atom_set_int(chassis, lldpctl_k_chassis_cap_enabled, + value) == NULL) { + log_warnx("lldpctl", + "unable to set system capabilities. %s", lldpctl_last_strerror(conn)); goto cmd_capability_end; } - if (lldpctl_atom_set_int(config, lldpctl_k_config_chassis_cap_override, 1) == NULL) { - log_warnx("lldpctl", "unable to set system capabilities override. %s", + if (lldpctl_atom_set_int(config, + lldpctl_k_config_chassis_cap_override, 1) == NULL) { + log_warnx("lldpctl", + "unable to set system capabilities override. %s", lldpctl_last_strerror(conn)); goto cmd_capability_end; } @@ -294,15 +292,17 @@ cmd_capability(struct lldpctl_conn_t *conn, struct writer *w, value); } } else { - if (lldpctl_atom_set_int(config, lldpctl_k_config_chassis_cap_override, 0) == NULL) { - log_warnx("lldpctl", "unable to set system capabilities to not override. %s", + if (lldpctl_atom_set_int(config, lldpctl_k_config_chassis_cap_override, + 0) == NULL) { + log_warnx("lldpctl", + "unable to set system capabilities to not override. %s", lldpctl_last_strerror(conn)); goto cmd_capability_end; } } ret = 1; - cmd_capability_end: +cmd_capability_end: lldpctl_atom_dec_ref(chassis); lldpctl_atom_dec_ref(config); return ret; @@ -318,17 +318,15 @@ cmd_update_descriptions(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_last_strerror(conn)); return 0; } - if (lldpctl_atom_set_int(config, - lldpctl_k_config_ifdescr_update, - arg?1:0) == NULL) { + if (lldpctl_atom_set_int(config, lldpctl_k_config_ifdescr_update, + arg ? 1 : 0) == NULL) { log_warnx("lldpctl", "unable to %s interface description update: %s", - arg?"enable":"disable", - lldpctl_last_strerror(conn)); + arg ? "enable" : "disable", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } log_info("lldpctl", "interface description update %s", - arg?"enabled":"disabled"); + arg ? "enabled" : "disabled"); lldpctl_atom_dec_ref(config); return 1; } @@ -344,16 +342,15 @@ cmd_bondslave_srcmac_type(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_atom_t *config = lldpctl_get_configuration(conn); if (config == NULL) { - log_warnx("lldpctl", - "unable to get configuration from lldpd. %s", - lldpctl_last_strerror(conn)); + log_warnx("lldpctl", "unable to get configuration from lldpd. %s", + lldpctl_last_strerror(conn)); return 0; } value_str = arg; for (lldpctl_map_t *b_map = - lldpctl_key_get_map(lldpctl_k_config_bond_slave_src_mac_type); - b_map->string; b_map++) { + lldpctl_key_get_map(lldpctl_k_config_bond_slave_src_mac_type); + b_map->string; b_map++) { if (!strcmp(b_map->string, value_str)) { value = b_map->value; break; @@ -366,24 +363,25 @@ cmd_bondslave_srcmac_type(struct lldpctl_conn_t *conn, struct writer *w, return 0; } - if (lldpctl_atom_set_int(config, - lldpctl_k_config_bond_slave_src_mac_type, value) == NULL) { - log_warnx("lldpctl", "unable to set bond slave src mac type." - " %s", lldpctl_last_strerror(conn)); + if (lldpctl_atom_set_int(config, lldpctl_k_config_bond_slave_src_mac_type, + value) == NULL) { + log_warnx("lldpctl", + "unable to set bond slave src mac type." + " %s", + lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } - log_info("lldpctl", "bond slave src mac set to new value: %s", - value_str); + log_info("lldpctl", "bond slave src mac set to new value: %s", value_str); lldpctl_atom_dec_ref(config); return 1; } static int -cmd_maxneighs(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_maxneighs(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "set maximum neighbors"); @@ -393,14 +391,15 @@ cmd_maxneighs(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_last_strerror(conn)); return 0; } - if (lldpctl_atom_set_str(config, - lldpctl_k_config_max_neighbors, cmdenv_get(env, "max-neighbors")) == NULL) { + if (lldpctl_atom_set_str(config, lldpctl_k_config_max_neighbors, + cmdenv_get(env, "max-neighbors")) == NULL) { log_warnx("lldpctl", "unable to set maximum of neighbors. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } - log_info("lldpctl", "maximum neighbors set to new value %s", cmdenv_get(env, "max-neighbors")); + log_info("lldpctl", "maximum neighbors set to new value %s", + cmdenv_get(env, "max-neighbors")); lldpctl_atom_dec_ref(config); return 1; } @@ -412,47 +411,37 @@ static void register_commands_srcmac_type(struct cmd_node *configure) { struct cmd_node *bond_slave_src_mac_type = - commands_new(configure, - "bond-slave-src-mac-type", - "Set LLDP bond slave source MAC type", - NULL, NULL, NULL); + commands_new(configure, "bond-slave-src-mac-type", + "Set LLDP bond slave source MAC type", NULL, NULL, NULL); for (lldpctl_map_t *b_map = - lldpctl_key_get_map(lldpctl_k_config_bond_slave_src_mac_type); - b_map->string; b_map++) { + lldpctl_key_get_map(lldpctl_k_config_bond_slave_src_mac_type); + b_map->string; b_map++) { if (!strcmp(b_map->string, "real")) { - commands_new( - commands_new(bond_slave_src_mac_type, - b_map->string, "Real mac", - NULL, NULL, NULL), - NEWLINE, NULL, - NULL, cmd_bondslave_srcmac_type, - b_map->string); + commands_new(commands_new(bond_slave_src_mac_type, + b_map->string, "Real mac", NULL, NULL, NULL), + NEWLINE, NULL, NULL, cmd_bondslave_srcmac_type, + b_map->string); } else if (!strcmp(b_map->string, "zero")) { - commands_new( - commands_new(bond_slave_src_mac_type, - b_map->string, "All zero mac", - NULL, NULL, NULL), - NEWLINE, NULL, - NULL, cmd_bondslave_srcmac_type, - b_map->string); + commands_new(commands_new(bond_slave_src_mac_type, + b_map->string, "All zero mac", NULL, NULL, + NULL), + NEWLINE, NULL, NULL, cmd_bondslave_srcmac_type, + b_map->string); } else if (!strcmp(b_map->string, "fixed")) { - commands_new( - commands_new(bond_slave_src_mac_type, - b_map->string, "Fixed value (3Com card)", - NULL, NULL, NULL), - NEWLINE, NULL, - NULL, cmd_bondslave_srcmac_type, - b_map->string); + commands_new(commands_new(bond_slave_src_mac_type, + b_map->string, "Fixed value (3Com card)", NULL, + NULL, NULL), + NEWLINE, NULL, NULL, cmd_bondslave_srcmac_type, + b_map->string); } else if (!strcmp(b_map->string, "local")) { - commands_new( - commands_new(bond_slave_src_mac_type, - b_map->string, "Real Mac with locally " - "administered bit set", - NULL, NULL, NULL), - NEWLINE, NULL, - NULL, cmd_bondslave_srcmac_type, - b_map->string); + commands_new(commands_new(bond_slave_src_mac_type, + b_map->string, + "Real Mac with locally " + "administered bit set", + NULL, NULL, NULL), + NEWLINE, NULL, NULL, cmd_bondslave_srcmac_type, + b_map->string); } } } @@ -460,33 +449,24 @@ register_commands_srcmac_type(struct cmd_node *configure) static void register_commands_capabilities(struct cmd_node *configure, struct cmd_node *unconfigure) { - struct cmd_node *configure_capability = commands_new( - configure, - "capabilities", "Capabilities configuration", - cmd_check_no_env, NULL, "ports"); - struct cmd_node *unconfigure_capability = commands_new( - unconfigure, - "capabilities", "Capabilities configuration", - cmd_check_no_env, NULL, "ports"); + struct cmd_node *configure_capability = commands_new(configure, "capabilities", + "Capabilities configuration", cmd_check_no_env, NULL, "ports"); + struct cmd_node *unconfigure_capability = + commands_new(unconfigure, "capabilities", "Capabilities configuration", + cmd_check_no_env, NULL, "ports"); /* Override */ - commands_new( - commands_new( - commands_new(configure_capability, - "enabled", "Override capabilities", - NULL, NULL, NULL), - NULL, " Set of capabilities separated by commas", - NULL, cmd_store_env_value, "capabilities"), - NEWLINE, "Override capabilities", - NULL, cmd_capability, "configure"); + commands_new(commands_new(commands_new(configure_capability, "enabled", + "Override capabilities", NULL, NULL, NULL), + NULL, " Set of capabilities separated by commas", NULL, + cmd_store_env_value, "capabilities"), + NEWLINE, "Override capabilities", NULL, cmd_capability, "configure"); /* Do not override */ - commands_new( - commands_new(unconfigure_capability, - "enabled", "Do not override capabilities", - NULL, NULL, NULL), - NEWLINE, "Do not override capabilities", - NULL, cmd_capability, "unconfigure"); + commands_new(commands_new(unconfigure_capability, "enabled", + "Do not override capabilities", NULL, NULL, NULL), + NEWLINE, "Do not override capabilities", NULL, cmd_capability, + "unconfigure"); } /** @@ -498,184 +478,123 @@ void register_commands_configure_system(struct cmd_node *configure, struct cmd_node *unconfigure) { - struct cmd_node *configure_system = commands_new( - configure, - "system", "System configuration", - cmd_check_no_env, NULL, "ports"); - struct cmd_node *unconfigure_system = commands_new( - unconfigure, - "system", "System configuration", - cmd_check_no_env, NULL, "ports"); - struct cmd_node *configure_interface = commands_new( - configure_system, - "interface", "Interface related items", - NULL, NULL, NULL); - struct cmd_node *unconfigure_interface = commands_new( - unconfigure_system, - "interface", "Interface related items", - NULL, NULL, NULL); - - commands_new( - commands_new( - commands_new(configure_system, - "description", "Override chassis description", - NULL, NULL, NULL), - NULL, "Chassis description", - NULL, cmd_store_env_value, "description"), - NEWLINE, "Override chassis description", - NULL, cmd_system_description, "system"); - commands_new( - commands_new(unconfigure_system, - "description", "Don't override chassis description", - NULL, NULL, NULL), - NEWLINE, "Don't override chassis description", - NULL, cmd_system_description, "system"); - - commands_new( - commands_new( - commands_new(configure_system, - "chassisid", "Override chassis ID", - NULL, NULL, NULL), - NULL, "Chassis ID", - NULL, cmd_store_env_value, "description"), - NEWLINE, "Override chassis ID", - NULL, cmd_system_chassisid, "system"); - commands_new( - commands_new(unconfigure_system, - "chassisid", "Don't override chassis ID", - NULL, NULL, NULL), - NEWLINE, "Don't override chassis ID", - NULL, cmd_system_chassisid, "system"); + struct cmd_node *configure_system = commands_new(configure, "system", + "System configuration", cmd_check_no_env, NULL, "ports"); + struct cmd_node *unconfigure_system = commands_new(unconfigure, "system", + "System configuration", cmd_check_no_env, NULL, "ports"); + struct cmd_node *configure_interface = commands_new(configure_system, + "interface", "Interface related items", NULL, NULL, NULL); + struct cmd_node *unconfigure_interface = commands_new(unconfigure_system, + "interface", "Interface related items", NULL, NULL, NULL); + + commands_new(commands_new(commands_new(configure_system, "description", + "Override chassis description", NULL, NULL, NULL), + NULL, "Chassis description", NULL, cmd_store_env_value, + "description"), + NEWLINE, "Override chassis description", NULL, cmd_system_description, + "system"); + commands_new(commands_new(unconfigure_system, "description", + "Don't override chassis description", NULL, NULL, NULL), + NEWLINE, "Don't override chassis description", NULL, cmd_system_description, + "system"); + + commands_new(commands_new(commands_new(configure_system, "chassisid", + "Override chassis ID", NULL, NULL, NULL), + NULL, "Chassis ID", NULL, cmd_store_env_value, "description"), + NEWLINE, "Override chassis ID", NULL, cmd_system_chassisid, "system"); + commands_new(commands_new(unconfigure_system, "chassisid", + "Don't override chassis ID", NULL, NULL, NULL), + NEWLINE, "Don't override chassis ID", NULL, cmd_system_chassisid, "system"); + + commands_new(commands_new(commands_new(configure_system, "platform", + "Override platform description", NULL, NULL, + NULL), + NULL, "Platform description (CDP)", NULL, cmd_store_env_value, + "platform"), + NEWLINE, "Override platform description", NULL, cmd_system_description, + "platform"); + commands_new(commands_new(unconfigure_system, "platform", + "Don't override platform description", NULL, NULL, NULL), + NEWLINE, "Don't override platform description", NULL, + cmd_system_description, "platform"); + + commands_new(commands_new(commands_new(configure_system, "hostname", + "Override system name", NULL, NULL, NULL), + NULL, "System name", NULL, cmd_store_env_value, "hostname"), + NEWLINE, "Override system name", NULL, cmd_hostname, NULL); + commands_new(commands_new(unconfigure_system, "hostname", + "Don't override system name", NULL, NULL, NULL), + NEWLINE, "Don't override system name", NULL, cmd_hostname, NULL); + + commands_new(commands_new(commands_new(configure_system, "max-neighbors", + "Set maximum number of neighbors per port", + cmd_check_no_env, NULL, "ports"), + NULL, "Maximum number of neighbors", NULL, cmd_store_env_value, + "max-neighbors"), + NEWLINE, "Set maximum number of neighbors per port", NULL, cmd_maxneighs, + NULL); commands_new( - commands_new( - commands_new(configure_system, - "platform", "Override platform description", - NULL, NULL, NULL), - NULL, "Platform description (CDP)", - NULL, cmd_store_env_value, "platform"), - NEWLINE, "Override platform description", - NULL, cmd_system_description, "platform"); + commands_new(commands_new(commands_new(commands_new(configure_system, "ip", + "IP related options", NULL, NULL, + NULL), + "management", "IP management related options", + NULL, NULL, NULL), + "pattern", "Set IP management pattern", NULL, NULL, NULL), + NULL, "IP management pattern (comma-separated list of wildcards)", NULL, + cmd_store_env_value, "management-pattern"), + NEWLINE, "Set IP management pattern", NULL, cmd_management, NULL); commands_new( - commands_new(unconfigure_system, - "platform", "Don't override platform description", - NULL, NULL, NULL), - NEWLINE, "Don't override platform description", - NULL, cmd_system_description, "platform"); + commands_new(commands_new(commands_new(unconfigure_system, "ip", + "IP related options", NULL, NULL, NULL), + "management", "IP management related options", NULL, NULL, + NULL), + "pattern", "Delete any IP management pattern", NULL, NULL, NULL), + NEWLINE, "Delete any IP management pattern", NULL, cmd_management, NULL); + + commands_new(commands_new(commands_new(configure_interface, "pattern", + "Set active interface pattern", NULL, NULL, NULL), + NULL, "Interface pattern (comma-separated list of wildcards)", + NULL, cmd_store_env_value, "iface-pattern"), + NEWLINE, "Set active interface pattern", NULL, cmd_iface_pattern, NULL); + commands_new(commands_new(unconfigure_interface, "pattern", + "Delete any interface pattern", NULL, NULL, NULL), + NEWLINE, "Clear interface pattern", NULL, cmd_iface_pattern, NULL); commands_new( - commands_new( - commands_new(configure_system, - "hostname", "Override system name", - NULL, NULL, NULL), - NULL, "System name", - NULL, cmd_store_env_value, "hostname"), - NEWLINE, "Override system name", - NULL, cmd_hostname, NULL); - commands_new( - commands_new(unconfigure_system, - "hostname", "Don't override system name", - NULL, NULL, NULL), - NEWLINE, "Don't override system name", - NULL, cmd_hostname, NULL); - - commands_new( - commands_new( - commands_new(configure_system, - "max-neighbors", "Set maximum number of neighbors per port", - cmd_check_no_env, NULL, "ports"), - NULL, "Maximum number of neighbors", - NULL, cmd_store_env_value, "max-neighbors"), - NEWLINE, "Set maximum number of neighbors per port", - NULL, cmd_maxneighs, NULL); - - commands_new( - commands_new( - commands_new( - commands_new( - commands_new(configure_system, - "ip", "IP related options", - NULL, NULL, NULL), - "management", "IP management related options", - NULL, NULL, NULL), - "pattern", "Set IP management pattern", - NULL, NULL, NULL), - NULL, "IP management pattern (comma-separated list of wildcards)", - NULL, cmd_store_env_value, "management-pattern"), - NEWLINE, "Set IP management pattern", - NULL, cmd_management, NULL); - commands_new( - commands_new( - commands_new( - commands_new(unconfigure_system, - "ip", "IP related options", - NULL, NULL, NULL), - "management", "IP management related options", - NULL, NULL, NULL), - "pattern", "Delete any IP management pattern", - NULL, NULL, NULL), - NEWLINE, "Delete any IP management pattern", - NULL, cmd_management, NULL); - - commands_new( - commands_new( - commands_new(configure_interface, - "pattern", "Set active interface pattern", - NULL, NULL, NULL), - NULL, "Interface pattern (comma-separated list of wildcards)", - NULL, cmd_store_env_value, "iface-pattern"), - NEWLINE, "Set active interface pattern", - NULL, cmd_iface_pattern, NULL); - commands_new( - commands_new(unconfigure_interface, - "pattern", "Delete any interface pattern", - NULL, NULL, NULL), - NEWLINE, "Clear interface pattern", - NULL, cmd_iface_pattern, NULL); - - commands_new( - commands_new( - commands_new(configure_interface, - "permanent", "Set permanent interface pattern", - NULL, NULL, NULL), - NULL, "Permanent interface pattern (comma-separated list of wildcards)", - NULL, cmd_store_env_value, "iface-pattern"), - NEWLINE, "Set permanent interface pattern", - NULL, cmd_perm_iface_pattern, NULL); - commands_new( - commands_new(unconfigure_interface, - "permanent", "Clear permanent interface pattern", - NULL, NULL, NULL), - NEWLINE, "Delete any interface pattern", - NULL, cmd_perm_iface_pattern, NULL); - - commands_new( - commands_new(configure_interface, - "description", "Update interface descriptions with neighbor name", - NULL, NULL, NULL), - NEWLINE, "Update interface descriptions with neighbor name", - NULL, cmd_update_descriptions, "enable"); - commands_new( - commands_new(unconfigure_interface, - "description", "Don't update interface descriptions with neighbor name", - NULL, NULL, NULL), - NEWLINE, "Don't update interface descriptions with neighbor name", - NULL, cmd_update_descriptions, NULL); - - commands_new( - commands_new(configure_interface, - "promiscuous", "Enable promiscuous mode on managed interfaces", - NULL, NULL, NULL), - NEWLINE, "Enable promiscuous mode on managed interfaces", - NULL, cmd_iface_promisc, "enable"); - commands_new( - commands_new(unconfigure_interface, - "promiscuous", "Don't enable promiscuous mode on managed interfaces", - NULL, NULL, NULL), - NEWLINE, "Don't enable promiscuous mode on managed interfaces", - NULL, cmd_iface_promisc, NULL); + commands_new(commands_new(configure_interface, "permanent", + "Set permanent interface pattern", NULL, NULL, NULL), + NULL, "Permanent interface pattern (comma-separated list of wildcards)", + NULL, cmd_store_env_value, "iface-pattern"), + NEWLINE, "Set permanent interface pattern", NULL, cmd_perm_iface_pattern, + NULL); + commands_new(commands_new(unconfigure_interface, "permanent", + "Clear permanent interface pattern", NULL, NULL, NULL), + NEWLINE, "Delete any interface pattern", NULL, cmd_perm_iface_pattern, + NULL); + + commands_new(commands_new(configure_interface, "description", + "Update interface descriptions with neighbor name", NULL, NULL, + NULL), + NEWLINE, "Update interface descriptions with neighbor name", NULL, + cmd_update_descriptions, "enable"); + commands_new(commands_new(unconfigure_interface, "description", + "Don't update interface descriptions with neighbor name", NULL, + NULL, NULL), + NEWLINE, "Don't update interface descriptions with neighbor name", NULL, + cmd_update_descriptions, NULL); + + commands_new(commands_new(configure_interface, "promiscuous", + "Enable promiscuous mode on managed interfaces", NULL, NULL, + NULL), + NEWLINE, "Enable promiscuous mode on managed interfaces", NULL, + cmd_iface_promisc, "enable"); + commands_new(commands_new(unconfigure_interface, "promiscuous", + "Don't enable promiscuous mode on managed interfaces", NULL, + NULL, NULL), + NEWLINE, "Don't enable promiscuous mode on managed interfaces", NULL, + cmd_iface_promisc, NULL); register_commands_capabilities(configure_system, unconfigure_system); register_commands_srcmac_type(configure_system); } - diff --git a/src/client/conf.c b/src/client/conf.c index 72688b2a..7bbb1f9c 100644 --- a/src/client/conf.c +++ b/src/client/conf.c @@ -27,16 +27,10 @@ void register_commands_configure(struct cmd_node *root) { - struct cmd_node *configure = commands_new( - root, - "configure", - "Change system settings", - NULL, NULL, NULL); - struct cmd_node *unconfigure = commands_new( - root, - "unconfigure", - "Unconfigure system settings", - NULL, NULL, NULL); + struct cmd_node *configure = + commands_new(root, "configure", "Change system settings", NULL, NULL, NULL); + struct cmd_node *unconfigure = commands_new(root, "unconfigure", + "Unconfigure system settings", NULL, NULL, NULL); commands_privileged(commands_lock(configure)); commands_privileged(commands_lock(unconfigure)); cmd_restrict_ports(configure); diff --git a/src/client/display.c b/src/client/display.c index 8465d2db..c59c4788 100644 --- a/src/client/display.c +++ b/src/client/display.c @@ -31,15 +31,17 @@ #include "client.h" static void -display_cap(struct writer * w, lldpctl_atom_t *chassis, u_int8_t bit, char *symbol) +display_cap(struct writer *w, lldpctl_atom_t *chassis, u_int8_t bit, char *symbol) { if (lldpctl_atom_get_int(chassis, lldpctl_k_chassis_cap_available) & bit) { tag_start(w, "capability", "Capability"); - tag_attr (w, "type", "", symbol ); - tag_attr (w, "enabled", "", - (lldpctl_atom_get_int(chassis, lldpctl_k_chassis_cap_enabled) & bit)? - "on":"off"); - tag_end (w); + tag_attr(w, "type", "", symbol); + tag_attr(w, "enabled", "", + (lldpctl_atom_get_int(chassis, lldpctl_k_chassis_cap_enabled) & + bit) ? + "on" : + "off"); + tag_end(w); } } @@ -65,8 +67,7 @@ display_med(struct writer *w, lldpctl_atom_t *port, lldpctl_atom_t *chassis) long int cap = lldpctl_atom_get_int(chassis, lldpctl_k_chassis_med_cap); const char *type; - if (lldpctl_atom_get_int(chassis, lldpctl_k_chassis_med_type) <= 0) - return; + if (lldpctl_atom_get_int(chassis, lldpctl_k_chassis_med_type) <= 0) return; tag_start(w, "lldp-med", "LLDP-MED"); @@ -82,20 +83,23 @@ display_med(struct writer *w, lldpctl_atom_t *port, lldpctl_atom_t *chassis) /* LLDP MED policies */ medpolicies = lldpctl_atom_get(port, lldpctl_k_port_med_policies); - lldpctl_atom_foreach(medpolicies, medpolicy) { - if (lldpctl_atom_get_int(medpolicy, - lldpctl_k_med_policy_type) <= 0) continue; + lldpctl_atom_foreach(medpolicies, medpolicy) + { + if (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_type) <= 0) + continue; tag_start(w, "policy", "LLDP-MED Network Policy for"); - tag_attr(w, "apptype", "", lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_type)); + tag_attr(w, "apptype", "", + lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_type)); tag_attr(w, "defined", "Defined", - (lldpctl_atom_get_int(medpolicy, - lldpctl_k_med_policy_unknown) > 0)?"no":"yes"); - - if (lldpctl_atom_get_int(medpolicy, - lldpctl_k_med_policy_tagged) > 0) { - int vid = lldpctl_atom_get_int(medpolicy, - lldpctl_k_med_policy_vid); + (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_unknown) > + 0) ? + "no" : + "yes"); + + if (lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_tagged) > 0) { + int vid = + lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_vid); tag_start(w, "vlan", "VLAN"); if (vid == 0) { tag_attr(w, "vid", "", "priority"); @@ -110,16 +114,14 @@ display_med(struct writer *w, lldpctl_atom_t *port, lldpctl_atom_t *chassis) } tag_datatag(w, "priority", "Priority", - lldpctl_atom_get_str(medpolicy, - lldpctl_k_med_policy_priority)); + lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_priority)); /* Also give a numeric value */ - int pcp = lldpctl_atom_get_int(medpolicy, - lldpctl_k_med_policy_priority); + int pcp = + lldpctl_atom_get_int(medpolicy, lldpctl_k_med_policy_priority); char spcp[2] = { pcp + '0', '\0' }; tag_datatag(w, "pcp", "PCP", spcp); tag_datatag(w, "dscp", "DSCP Value", - lldpctl_atom_get_str(medpolicy, - lldpctl_k_med_policy_dscp)); + lldpctl_atom_get_str(medpolicy, lldpctl_k_med_policy_dscp)); tag_end(w); } @@ -127,14 +129,14 @@ display_med(struct writer *w, lldpctl_atom_t *port, lldpctl_atom_t *chassis) /* LLDP MED locations */ medlocations = lldpctl_atom_get(port, lldpctl_k_port_med_locations); - lldpctl_atom_foreach(medlocations, medlocation) { - int format = lldpctl_atom_get_int(medlocation, - lldpctl_k_med_location_format); + lldpctl_atom_foreach(medlocations, medlocation) + { + int format = + lldpctl_atom_get_int(medlocation, lldpctl_k_med_location_format); if (format <= 0) continue; tag_start(w, "location", "LLDP-MED Location Identification"); tag_attr(w, "type", "Type", - lldpctl_atom_get_str(medlocation, - lldpctl_k_med_location_format)); + lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_format)); switch (format) { case LLDP_MED_LOCFORMAT_COORD: @@ -148,9 +150,11 @@ display_med(struct writer *w, lldpctl_atom_t *port, lldpctl_atom_t *chassis) lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_longitude)); tag_start(w, "altitude", "Altitude"); - tag_attr(w, "unit", "", lldpctl_atom_get_str(medlocation, + tag_attr(w, "unit", "", + lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_altitude_unit)); - tag_data(w, lldpctl_atom_get_str(medlocation, + tag_data(w, + lldpctl_atom_get_str(medlocation, lldpctl_k_med_location_altitude)); tag_end(w); break; @@ -160,7 +164,8 @@ display_med(struct writer *w, lldpctl_atom_t *port, lldpctl_atom_t *chassis) lldpctl_k_med_location_country)); caelements = lldpctl_atom_get(medlocation, lldpctl_k_med_location_ca_elements); - lldpctl_atom_foreach(caelements, caelement) { + lldpctl_atom_foreach(caelements, caelement) + { type = lldpctl_atom_get_str(caelement, lldpctl_k_med_civicaddress_type); tag_datatag(w, totag(type), type, @@ -183,7 +188,7 @@ display_med(struct writer *w, lldpctl_atom_t *port, lldpctl_atom_t *chassis) /* LLDP MED power */ medpower = lldpctl_atom_get(port, lldpctl_k_port_med_power); if (lldpctl_atom_get_int(medpower, lldpctl_k_med_power_type) > 0) { - tag_start(w, "poe", "Extended Power-over-Ethernet"); + tag_start(w, "poe", "Extended Power-over-Ethernet"); tag_datatag(w, "device-type", "Power Type & Source", lldpctl_atom_get_str(medpower, lldpctl_k_med_power_type)); @@ -200,22 +205,21 @@ display_med(struct writer *w, lldpctl_atom_t *port, lldpctl_atom_t *chassis) /* LLDP MED inventory */ do { - const char *hw = lldpctl_atom_get_str(chassis, - lldpctl_k_chassis_med_inventory_hw); - const char *sw = lldpctl_atom_get_str(chassis, - lldpctl_k_chassis_med_inventory_sw); - const char *fw = lldpctl_atom_get_str(chassis, - lldpctl_k_chassis_med_inventory_fw); - const char *sn = lldpctl_atom_get_str(chassis, - lldpctl_k_chassis_med_inventory_sn); + const char *hw = + lldpctl_atom_get_str(chassis, lldpctl_k_chassis_med_inventory_hw); + const char *sw = + lldpctl_atom_get_str(chassis, lldpctl_k_chassis_med_inventory_sw); + const char *fw = + lldpctl_atom_get_str(chassis, lldpctl_k_chassis_med_inventory_fw); + const char *sn = + lldpctl_atom_get_str(chassis, lldpctl_k_chassis_med_inventory_sn); const char *manuf = lldpctl_atom_get_str(chassis, lldpctl_k_chassis_med_inventory_manuf); const char *model = lldpctl_atom_get_str(chassis, lldpctl_k_chassis_med_inventory_model); const char *asset = lldpctl_atom_get_str(chassis, lldpctl_k_chassis_med_inventory_asset); - if (!(hw || sw || fw || sn || - manuf || model || asset)) break; + if (!(hw || sw || fw || sn || manuf || model || asset)) break; tag_start(w, "inventory", "Inventory"); tag_datatag(w, "hardware", "Hardware Revision", hw); @@ -226,23 +230,21 @@ display_med(struct writer *w, lldpctl_atom_t *port, lldpctl_atom_t *chassis) tag_datatag(w, "model", "Model", model); tag_datatag(w, "asset", "Asset ID", asset); tag_end(w); - } while(0); + } while (0); tag_end(w); } static void -display_chassis(struct writer* w, lldpctl_atom_t* chassis, int details) +display_chassis(struct writer *w, lldpctl_atom_t *chassis, int details) { lldpctl_atom_t *mgmts, *mgmt; tag_start(w, "chassis", "Chassis"); tag_start(w, "id", "ChassisID"); - tag_attr (w, "type", "", - lldpctl_atom_get_str(chassis, - lldpctl_k_chassis_id_subtype)); - tag_data(w, lldpctl_atom_get_str(chassis, - lldpctl_k_chassis_id)); + tag_attr(w, "type", "", + lldpctl_atom_get_str(chassis, lldpctl_k_chassis_id_subtype)); + tag_data(w, lldpctl_atom_get_str(chassis, lldpctl_k_chassis_id)); tag_end(w); tag_datatag(w, "name", "SysName", lldpctl_atom_get_str(chassis, lldpctl_k_chassis_name)); @@ -255,7 +257,8 @@ display_chassis(struct writer* w, lldpctl_atom_t* chassis, int details) /* Management addresses */ mgmts = lldpctl_atom_get(chassis, lldpctl_k_chassis_mgmt); - lldpctl_atom_foreach(mgmts, mgmt) { + lldpctl_atom_foreach(mgmts, mgmt) + { tag_datatag(w, "mgmt-ip", "MgmtIP", lldpctl_atom_get_str(mgmt, lldpctl_k_mgmt_ip)); if (lldpctl_atom_get_int(mgmt, lldpctl_k_mgmt_iface_index)) @@ -278,7 +281,7 @@ display_chassis(struct writer* w, lldpctl_atom_t* chassis, int details) } static void -display_custom_tlvs(struct writer* w, lldpctl_atom_t* neighbor) +display_custom_tlvs(struct writer *w, lldpctl_atom_t *neighbor) { lldpctl_atom_t *custom_list, *custom; int have_custom_tlvs = 0; @@ -287,7 +290,8 @@ display_custom_tlvs(struct writer* w, lldpctl_atom_t* neighbor) char buf[1600]; /* should be enough for printing */ custom_list = lldpctl_atom_get(neighbor, lldpctl_k_custom_tlvs); - lldpctl_atom_foreach(custom_list, custom) { + lldpctl_atom_foreach(custom_list, custom) + { /* This tag gets added only once, if there are any custom TLVs */ if (!have_custom_tlvs) { tag_start(w, "unknown-tlvs", "Unknown TLVs"); @@ -296,48 +300,46 @@ display_custom_tlvs(struct writer* w, lldpctl_atom_t* neighbor) len = 0; oui = lldpctl_atom_get_buffer(custom, lldpctl_k_custom_tlv_oui, &len); len = 0; - oui_info = lldpctl_atom_get_buffer(custom, lldpctl_k_custom_tlv_oui_info_string, &len); - if (!oui) - continue; + oui_info = lldpctl_atom_get_buffer(custom, + lldpctl_k_custom_tlv_oui_info_string, &len); + if (!oui) continue; tag_start(w, "unknown-tlv", "TLV"); /* Add OUI as attribute */ snprintf(buf, sizeof(buf), "%02X,%02X,%02X", oui[0], oui[1], oui[2]); tag_attr(w, "oui", "OUI", buf); snprintf(buf, sizeof(buf), "%d", - (int)lldpctl_atom_get_int(custom, lldpctl_k_custom_tlv_oui_subtype)); + (int)lldpctl_atom_get_int(custom, + lldpctl_k_custom_tlv_oui_subtype)); tag_attr(w, "subtype", "SubType", buf); snprintf(buf, sizeof(buf), "%d", (int)len); tag_attr(w, "len", "Len", buf); if (len > 0) { - for (slen=0, i=0; i < len; ++i) - slen += snprintf(buf + slen, sizeof(buf) > slen ? sizeof(buf) - slen : 0, - "%02X%s", oui_info[i], ((i < len - 1) ? "," : "")); + for (slen = 0, i = 0; i < len; ++i) + slen += snprintf(buf + slen, + sizeof(buf) > slen ? sizeof(buf) - slen : 0, + "%02X%s", oui_info[i], ((i < len - 1) ? "," : "")); tag_data(w, buf); } tag_end(w); } lldpctl_atom_dec_ref(custom_list); - if (have_custom_tlvs) - tag_end(w); + if (have_custom_tlvs) tag_end(w); } - static void -display_autoneg(struct writer * w, int advertised, int bithd, int bitfd, char *desc) +display_autoneg(struct writer *w, int advertised, int bithd, int bitfd, char *desc) { - if (!((advertised & bithd) || - (advertised & bitfd))) - return; + if (!((advertised & bithd) || (advertised & bitfd))) return; tag_start(w, "advertised", "Adv"); tag_attr(w, "type", "", desc); if (bitfd != bithd) { - tag_attr(w, "hd", "HD", (advertised & bithd)?"yes":"no"); - tag_attr(w, "fd", "FD", (advertised & bitfd)?"yes":"no"); + tag_attr(w, "hd", "HD", (advertised & bithd) ? "yes" : "no"); + tag_attr(w, "fd", "FD", (advertised & bitfd) ? "yes" : "no"); } - tag_end (w); + tag_end(w); } static void @@ -348,8 +350,7 @@ display_port(struct writer *w, lldpctl_atom_t *port, int details) tag_start(w, "port", "Port"); tag_start(w, "id", "PortID"); - tag_attr (w, "type", "", - lldpctl_atom_get_str(port, lldpctl_k_port_id_subtype)); + tag_attr(w, "type", "", lldpctl_atom_get_str(port, lldpctl_k_port_id_subtype)); tag_data(w, lldpctl_atom_get_str(port, lldpctl_k_port_id)); tag_end(w); @@ -359,16 +360,15 @@ display_port(struct writer *w, lldpctl_atom_t *port, int details) if ((vlan_tx_tag = lldpctl_atom_get_int(port, lldpctl_k_port_vlan_tx)) != -1) { tag_start(w, "vlanTX", "VlanTX"); snprintf(buf, sizeof(buf), "%d", vlan_tx_tag & 0xfff); - tag_attr (w, "id", "VID", buf); + tag_attr(w, "id", "VID", buf); snprintf(buf, sizeof(buf), "%d", (vlan_tx_tag >> 13) & 0x7); - tag_attr (w, "prio", "Prio", buf); + tag_attr(w, "prio", "Prio", buf); snprintf(buf, sizeof(buf), "%d", (vlan_tx_tag >> 12) & 0x1); - tag_attr (w, "dei", "DEI", buf); + tag_attr(w, "dei", "DEI", buf); tag_end(w); } - if (details && - lldpctl_atom_get_int(port, lldpctl_k_port_ttl) > 0) + if (details && lldpctl_atom_get_int(port, lldpctl_k_port_ttl) > 0) tag_datatag(w, "ttl", "TTL", lldpctl_atom_get_str(port, lldpctl_k_port_ttl)); @@ -380,163 +380,189 @@ display_port(struct writer *w, lldpctl_atom_t *port, int details) lldpctl_atom_get_str(port, lldpctl_k_port_dot3_aggregid)); long int autoneg_support, autoneg_enabled, autoneg_advertised, mautype; - autoneg_support = lldpctl_atom_get_int(port, - lldpctl_k_port_dot3_autoneg_support); - autoneg_enabled = lldpctl_atom_get_int(port, - lldpctl_k_port_dot3_autoneg_enabled); - autoneg_advertised = lldpctl_atom_get_int(port, - lldpctl_k_port_dot3_autoneg_advertised); + autoneg_support = + lldpctl_atom_get_int(port, lldpctl_k_port_dot3_autoneg_support); + autoneg_enabled = + lldpctl_atom_get_int(port, lldpctl_k_port_dot3_autoneg_enabled); + autoneg_advertised = + lldpctl_atom_get_int(port, lldpctl_k_port_dot3_autoneg_advertised); mautype = lldpctl_atom_get_int(port, lldpctl_k_port_dot3_mautype); if (autoneg_support > 0 || autoneg_enabled > 0 || mautype > 0) { tag_start(w, "auto-negotiation", "PMD autoneg"); - tag_attr (w, "supported", "supported", - (autoneg_support > 0)?"yes":"no"); - tag_attr (w, "enabled", "enabled", - (autoneg_enabled > 0)?"yes":"no"); + tag_attr(w, "supported", "supported", + (autoneg_support > 0) ? "yes" : "no"); + tag_attr(w, "enabled", "enabled", + (autoneg_enabled > 0) ? "yes" : "no"); if (autoneg_enabled > 0) { - if (autoneg_advertised < 0) - autoneg_advertised = 0; + if (autoneg_advertised < 0) autoneg_advertised = 0; display_autoneg(w, autoneg_advertised, LLDP_DOT3_LINK_AUTONEG_10BASE_T, - LLDP_DOT3_LINK_AUTONEG_10BASET_FD, - "10Base-T"); + LLDP_DOT3_LINK_AUTONEG_10BASET_FD, "10Base-T"); display_autoneg(w, autoneg_advertised, LLDP_DOT3_LINK_AUTONEG_100BASE_TX, - LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD, - "100Base-TX"); + LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD, "100Base-TX"); display_autoneg(w, autoneg_advertised, LLDP_DOT3_LINK_AUTONEG_100BASE_T2, - LLDP_DOT3_LINK_AUTONEG_100BASE_T2FD, - "100Base-T2"); + LLDP_DOT3_LINK_AUTONEG_100BASE_T2FD, "100Base-T2"); display_autoneg(w, autoneg_advertised, LLDP_DOT3_LINK_AUTONEG_100BASE_T4, - LLDP_DOT3_LINK_AUTONEG_100BASE_T4, - "100Base-T4"); + LLDP_DOT3_LINK_AUTONEG_100BASE_T4, "100Base-T4"); display_autoneg(w, autoneg_advertised, LLDP_DOT3_LINK_AUTONEG_1000BASE_X, - LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD, - "1000Base-X"); + LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD, "1000Base-X"); display_autoneg(w, autoneg_advertised, LLDP_DOT3_LINK_AUTONEG_1000BASE_T, - LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD, - "1000Base-T"); + LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD, "1000Base-T"); } tag_datatag(w, "current", "MAU oper type", lldpctl_atom_get_str(port, lldpctl_k_port_dot3_mautype)); tag_end(w); } - lldpctl_atom_t *dot3_power = lldpctl_atom_get(port, - lldpctl_k_port_dot3_power); - int devicetype = lldpctl_atom_get_int(dot3_power, - lldpctl_k_dot3_power_devicetype); + lldpctl_atom_t *dot3_power = + lldpctl_atom_get(port, lldpctl_k_port_dot3_power); + int devicetype = + lldpctl_atom_get_int(dot3_power, lldpctl_k_dot3_power_devicetype); if (devicetype > 0) { tag_start(w, "power", "MDI Power"); tag_attr(w, "supported", "supported", (lldpctl_atom_get_int(dot3_power, - lldpctl_k_dot3_power_supported) > 0)?"yes":"no"); + lldpctl_k_dot3_power_supported) > 0) ? + "yes" : + "no"); tag_attr(w, "enabled", "enabled", (lldpctl_atom_get_int(dot3_power, - lldpctl_k_dot3_power_enabled) > 0)?"yes":"no"); + lldpctl_k_dot3_power_enabled) > 0) ? + "yes" : + "no"); tag_attr(w, "paircontrol", "pair control", (lldpctl_atom_get_int(dot3_power, - lldpctl_k_dot3_power_paircontrol) > 0)?"yes":"no"); + lldpctl_k_dot3_power_paircontrol) > 0) ? + "yes" : + "no"); tag_start(w, "device-type", "Device type"); - tag_data(w, lldpctl_atom_get_str(dot3_power, - lldpctl_k_dot3_power_devicetype));; + tag_data(w, + lldpctl_atom_get_str(dot3_power, + lldpctl_k_dot3_power_devicetype)); + ; tag_end(w); tag_start(w, "pairs", "Power pairs"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + 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, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_class)); tag_end(w); /* 802.3at */ if (lldpctl_atom_get_int(dot3_power, - lldpctl_k_dot3_power_type) > LLDP_DOT3_POWER_8023AT_OFF) { + lldpctl_k_dot3_power_type) > + LLDP_DOT3_POWER_8023AT_OFF) { tag_start(w, "power-type", "Power type"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_type)); tag_end(w); tag_start(w, "source", "Power Source"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_source)); tag_end(w); tag_start(w, "priority", "Power Priority"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_priority)); tag_end(w); tag_start(w, "requested", "PD requested power Value"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_requested)); tag_end(w); tag_start(w, "allocated", "PSE allocated power Value"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_allocated)); tag_end(w); } /* 802.3bt */ if (lldpctl_atom_get_int(dot3_power, - lldpctl_k_dot3_power_type_ext) > LLDP_DOT3_POWER_8023BT_OFF) { + lldpctl_k_dot3_power_type_ext) > + LLDP_DOT3_POWER_8023BT_OFF) { tag_start(w, "requested-a", "Requested mode A"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_requested_a)); tag_end(w); tag_start(w, "requested-b", "Requested mode B"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_requested_b)); tag_end(w); tag_start(w, "allocated-a", "Allocated alternative A"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_allocated_a)); tag_end(w); tag_start(w, "allocated-b", "Allocated alternative B"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_allocated_b)); tag_end(w); - tag_start(w, "pse-powering-status", "PSE powering status"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_start(w, "pse-powering-status", + "PSE powering status"); + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_pse_status)); tag_end(w); - tag_start(w, "pd-powering-status", "PD powering status"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_start(w, "pd-powering-status", + "PD powering status"); + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_pd_status)); tag_end(w); tag_start(w, "power-pairs-ext", "Power pairs extra"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_pse_pairs_ext)); tag_end(w); tag_start(w, "power-class-ext-a", "Class extra A"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_class_a)); tag_end(w); tag_start(w, "power-class-ext-b", "Class extra B"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_class_b)); tag_end(w); tag_start(w, "power-class-ext", "Class extra"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_class_ext)); tag_end(w); tag_start(w, "power-type-ext", "Power type extra"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_type_ext)); tag_end(w); tag_start(w, "pd-load", "PD load"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_pd_load)); tag_end(w); - tag_start(w, "max-power", "PSE maximum available power"); - tag_data(w, lldpctl_atom_get_str(dot3_power, + tag_start(w, "max-power", + "PSE maximum available power"); + tag_data(w, + lldpctl_atom_get_str(dot3_power, lldpctl_k_dot3_power_pse_max)); tag_end(w); } @@ -565,7 +591,8 @@ display_local_ttl(struct writer *w, lldpctl_conn_t *conn, int details) } tx_hold = lldpctl_atom_get_int(configuration, lldpctl_k_config_tx_hold); - tx_interval = lldpctl_atom_get_int(configuration, lldpctl_k_config_tx_interval_ms); + tx_interval = + lldpctl_atom_get_int(configuration, lldpctl_k_config_tx_interval_ms); tx_interval = (tx_interval * tx_hold + 999) / 1000; @@ -589,13 +616,12 @@ display_vlans(struct writer *w, lldpctl_atom_t *port) int foundpvid = 0; int pvid, vid; - pvid = lldpctl_atom_get_int(port, - lldpctl_k_port_vlan_pvid); + pvid = lldpctl_atom_get_int(port, lldpctl_k_port_vlan_pvid); vlans = lldpctl_atom_get(port, lldpctl_k_port_vlans); - lldpctl_atom_foreach(vlans, vlan) { - vid = lldpctl_atom_get_int(vlan, - lldpctl_k_vlan_id); + lldpctl_atom_foreach(vlans, vlan) + { + vid = lldpctl_atom_get_int(vlan, lldpctl_k_vlan_id); tag_start(w, "vlan", "VLAN"); tag_attr(w, "vlan-id", "", @@ -606,8 +632,7 @@ display_vlans(struct writer *w, lldpctl_atom_t *port) } else { tag_attr(w, "pvid", "pvid", "no"); } - tag_data(w, lldpctl_atom_get_str(vlan, - lldpctl_k_vlan_name)); + tag_data(w, lldpctl_atom_get_str(vlan, lldpctl_k_vlan_name)); tag_end(w); } lldpctl_atom_dec_ref(vlans); @@ -615,8 +640,7 @@ display_vlans(struct writer *w, lldpctl_atom_t *port) if (!foundpvid && pvid > 0) { tag_start(w, "vlan", "VLAN"); tag_attr(w, "vlan-id", "", - lldpctl_atom_get_str(port, - lldpctl_k_port_vlan_pvid)); + lldpctl_atom_get_str(port, lldpctl_k_port_vlan_pvid)); tag_attr(w, "pvid", "pvid", "yes"); tag_end(w); } @@ -627,19 +651,17 @@ display_ppvids(struct writer *w, lldpctl_atom_t *port) { lldpctl_atom_t *ppvids, *ppvid; ppvids = lldpctl_atom_get(port, lldpctl_k_port_ppvids); - lldpctl_atom_foreach(ppvids, ppvid) { - int status = lldpctl_atom_get_int(ppvid, - lldpctl_k_ppvid_status); + lldpctl_atom_foreach(ppvids, ppvid) + { + int status = lldpctl_atom_get_int(ppvid, lldpctl_k_ppvid_status); tag_start(w, "ppvid", "PPVID"); - if (lldpctl_atom_get_int(ppvid, - lldpctl_k_ppvid_id) > 0) + if (lldpctl_atom_get_int(ppvid, lldpctl_k_ppvid_id) > 0) tag_attr(w, "value", "", - lldpctl_atom_get_str(ppvid, - lldpctl_k_ppvid_id)); + lldpctl_atom_get_str(ppvid, lldpctl_k_ppvid_id)); tag_attr(w, "supported", "supported", - (status & LLDP_PPVID_CAP_SUPPORTED)?"yes":"no"); + (status & LLDP_PPVID_CAP_SUPPORTED) ? "yes" : "no"); tag_attr(w, "enabled", "enabled", - (status & LLDP_PPVID_CAP_ENABLED)?"yes":"no"); + (status & LLDP_PPVID_CAP_ENABLED) ? "yes" : "no"); tag_end(w); } lldpctl_atom_dec_ref(ppvids); @@ -650,34 +672,30 @@ display_pids(struct writer *w, lldpctl_atom_t *port) { lldpctl_atom_t *pids, *pid; pids = lldpctl_atom_get(port, lldpctl_k_port_pis); - lldpctl_atom_foreach(pids, pid) { + lldpctl_atom_foreach(pids, pid) + { const char *pi = lldpctl_atom_get_str(pid, lldpctl_k_pi_id); - if (pi && strlen(pi) > 0) - tag_datatag(w, "pi", "PI", pi); + if (pi && strlen(pi) > 0) tag_datatag(w, "pi", "PI", pi); } lldpctl_atom_dec_ref(pids); } -static const char* +static const char * display_age(time_t lastchange) { static char sage[30]; int age = (int)(time(NULL) - lastchange); - if (snprintf(sage, sizeof(sage), - "%d day%s, %02d:%02d:%02d", - age / (60*60*24), - (age / (60*60*24) > 1)?"s":"", - (age / (60*60)) % 24, - (age / 60) % 60, - age % 60) >= sizeof(sage)) + if (snprintf(sage, sizeof(sage), "%d day%s, %02d:%02d:%02d", + age / (60 * 60 * 24), (age / (60 * 60 * 24) > 1) ? "s" : "", + (age / (60 * 60)) % 24, (age / 60) % 60, age % 60) >= sizeof(sage)) return "too much"; else return sage; } void -display_local_chassis(lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, int details) +display_local_chassis(lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + int details) { tag_start(w, "local-chassis", "Local chassis"); @@ -697,31 +715,29 @@ display_interface(lldpctl_conn_t *conn, struct writer *w, int hidden, { int local = 0; - if (!hidden && - lldpctl_atom_get_int(port, lldpctl_k_port_hidden)) - return; + if (!hidden && lldpctl_atom_get_int(port, lldpctl_k_port_hidden)) return; /* user might have specified protocol to filter on display */ if ((protocol != LLDPD_MODE_MAX) && (protocol != lldpctl_atom_get_int(port, lldpctl_k_port_protocol))) - return; + return; /* Infer local / remote port from the port index (remote == 0) */ - local = lldpctl_atom_get_int(port, lldpctl_k_port_index)>0?1:0; + local = lldpctl_atom_get_int(port, lldpctl_k_port_index) > 0 ? 1 : 0; lldpctl_atom_t *chassis = lldpctl_atom_get(port, lldpctl_k_port_chassis); tag_start(w, "interface", "Interface"); - tag_attr(w, "name", "", - lldpctl_atom_get_str(iface, lldpctl_k_interface_name)); + tag_attr(w, "name", "", lldpctl_atom_get_str(iface, lldpctl_k_interface_name)); if (!local) { - tag_attr(w, "via" , "via", + tag_attr(w, "via", "via", lldpctl_atom_get_str(port, lldpctl_k_port_protocol)); if (details > DISPLAY_BRIEF) { - tag_attr(w, "rid" , "RID", + tag_attr(w, "rid", "RID", lldpctl_atom_get_str(chassis, lldpctl_k_chassis_index)); - tag_attr(w, "age" , "Time", - display_age(lldpctl_atom_get_int(port, lldpctl_k_port_age))); + tag_attr(w, "age", "Time", + display_age( + lldpctl_atom_get_int(port, lldpctl_k_port_age))); } } else { tag_datatag(w, "status", "Administrative status", @@ -730,8 +746,7 @@ display_interface(lldpctl_conn_t *conn, struct writer *w, int hidden, display_chassis(w, chassis, details); display_port(w, port, details); - if (details && local && conn) - display_local_ttl(w, conn, details); + if (details && local && conn) display_local_ttl(w, conn, details); if (details == DISPLAY_DETAILS) { display_vlans(w, port); display_ppvids(w, port); @@ -756,8 +771,7 @@ display_interface(lldpctl_conn_t *conn, struct writer *w, int hidden, * @param details Level of details we need (DISPLAY_*). */ void -display_interfaces(lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, +display_interfaces(lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, int hidden, int details) { lldpctl_atom_t *iface; @@ -773,8 +787,7 @@ display_interfaces(lldpctl_conn_t *conn, struct writer *w, protocol = 0; for (lldpctl_map_t *protocol_map = lldpctl_key_get_map(lldpctl_k_port_protocol); - protocol_map->string; - protocol_map++) { + protocol_map->string; protocol_map++) { if (!strcasecmp(proto_str, protocol_map->string)) { protocol = protocol_map->value; break; @@ -787,10 +800,12 @@ display_interfaces(lldpctl_conn_t *conn, struct writer *w, lldpctl_atom_t *port; lldpctl_atom_t *neighbors; lldpctl_atom_t *neighbor; - port = lldpctl_get_port(iface); + port = lldpctl_get_port(iface); neighbors = lldpctl_atom_get(port, lldpctl_k_port_neighbors); - lldpctl_atom_foreach(neighbors, neighbor) { - display_interface(conn, w, hidden, iface, neighbor, details, protocol); + lldpctl_atom_foreach(neighbors, neighbor) + { + display_interface(conn, w, hidden, iface, neighbor, details, + protocol); } lldpctl_atom_dec_ref(neighbors); lldpctl_atom_dec_ref(port); @@ -798,7 +813,6 @@ display_interfaces(lldpctl_conn_t *conn, struct writer *w, tag_end(w); } - /** * Display information about local interfaces. * @@ -809,8 +823,7 @@ display_interfaces(lldpctl_conn_t *conn, struct writer *w, * @param details Level of details we need (DISPLAY_*). */ void -display_local_interfaces(lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, +display_local_interfaces(lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, int hidden, int details) { lldpctl_atom_t *iface; @@ -824,11 +837,11 @@ display_local_interfaces(lldpctl_conn_t *conn, struct writer *w, lldpctl_atom_dec_ref(port); } tag_end(w); - } +} void display_stat(struct writer *w, const char *tag, const char *descr, - long unsigned int cnt) + long unsigned int cnt) { char buf[20] = {}; @@ -839,37 +852,29 @@ display_stat(struct writer *w, const char *tag, const char *descr, } void -display_interface_stats(lldpctl_conn_t *conn, struct writer *w, - lldpctl_atom_t *port) +display_interface_stats(lldpctl_conn_t *conn, struct writer *w, lldpctl_atom_t *port) { tag_start(w, "interface", "Interface"); - tag_attr(w, "name", "", - lldpctl_atom_get_str(port, lldpctl_k_port_name)); + tag_attr(w, "name", "", lldpctl_atom_get_str(port, lldpctl_k_port_name)); display_stat(w, "tx", "Transmitted", - lldpctl_atom_get_int(port, lldpctl_k_tx_cnt)); - display_stat(w, "rx", "Received", - lldpctl_atom_get_int(port, lldpctl_k_rx_cnt)); + lldpctl_atom_get_int(port, lldpctl_k_tx_cnt)); + display_stat(w, "rx", "Received", lldpctl_atom_get_int(port, lldpctl_k_rx_cnt)); display_stat(w, "rx_discarded_cnt", "Discarded", - lldpctl_atom_get_int(port, - lldpctl_k_rx_discarded_cnt)); + lldpctl_atom_get_int(port, lldpctl_k_rx_discarded_cnt)); display_stat(w, "rx_unrecognized_cnt", "Unrecognized", - lldpctl_atom_get_int(port, - lldpctl_k_rx_unrecognized_cnt)); + lldpctl_atom_get_int(port, lldpctl_k_rx_unrecognized_cnt)); display_stat(w, "ageout_cnt", "Ageout", - lldpctl_atom_get_int(port, - lldpctl_k_ageout_cnt)); + lldpctl_atom_get_int(port, lldpctl_k_ageout_cnt)); display_stat(w, "insert_cnt", "Inserted", - lldpctl_atom_get_int(port, - lldpctl_k_insert_cnt)); + lldpctl_atom_get_int(port, lldpctl_k_insert_cnt)); display_stat(w, "delete_cnt", "Deleted", - lldpctl_atom_get_int(port, - lldpctl_k_delete_cnt)); + lldpctl_atom_get_int(port, lldpctl_k_delete_cnt)); tag_end(w); } @@ -882,8 +887,7 @@ display_interface_stats(lldpctl_conn_t *conn, struct writer *w, * @param env Environment from which we may find the list of ports. */ void -display_interfaces_stats(lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env) +display_interfaces_stats(lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env) { lldpctl_atom_t *iface; int summary = 0; @@ -895,31 +899,27 @@ display_interfaces_stats(lldpctl_conn_t *conn, struct writer *w, u_int64_t h_insert_cnt = 0; u_int64_t h_delete_cnt = 0; - if (cmdenv_get(env, "summary")) - summary = 1; + if (cmdenv_get(env, "summary")) summary = 1; - tag_start(w, "lldp", (summary ? "LLDP Global statistics" : - "LLDP statistics")); + tag_start(w, "lldp", (summary ? "LLDP Global statistics" : "LLDP statistics")); while ((iface = cmd_iterate_on_interfaces(conn, env))) { lldpctl_atom_t *port; - port = lldpctl_get_port(iface); + port = lldpctl_get_port(iface); if (!summary) display_interface_stats(conn, w, port); else { - h_tx_cnt += lldpctl_atom_get_int(port, - lldpctl_k_tx_cnt); - h_rx_cnt += lldpctl_atom_get_int(port, - lldpctl_k_rx_cnt); - h_rx_discarded_cnt += lldpctl_atom_get_int(port, - lldpctl_k_rx_discarded_cnt); - h_rx_unrecognized_cnt += lldpctl_atom_get_int(port, - lldpctl_k_rx_unrecognized_cnt); - h_ageout_cnt += lldpctl_atom_get_int(port, - lldpctl_k_ageout_cnt); - h_insert_cnt += lldpctl_atom_get_int(port, - lldpctl_k_insert_cnt); - h_delete_cnt += lldpctl_atom_get_int(port, - lldpctl_k_delete_cnt); + h_tx_cnt += lldpctl_atom_get_int(port, lldpctl_k_tx_cnt); + h_rx_cnt += lldpctl_atom_get_int(port, lldpctl_k_rx_cnt); + h_rx_discarded_cnt += + lldpctl_atom_get_int(port, lldpctl_k_rx_discarded_cnt); + h_rx_unrecognized_cnt += + lldpctl_atom_get_int(port, lldpctl_k_rx_unrecognized_cnt); + h_ageout_cnt += + lldpctl_atom_get_int(port, lldpctl_k_ageout_cnt); + h_insert_cnt += + lldpctl_atom_get_int(port, lldpctl_k_insert_cnt); + h_delete_cnt += + lldpctl_atom_get_int(port, lldpctl_k_delete_cnt); } lldpctl_atom_dec_ref(port); } @@ -928,11 +928,10 @@ display_interfaces_stats(lldpctl_conn_t *conn, struct writer *w, tag_start(w, "summary", "Summary of stats"); display_stat(w, "tx", "Transmitted", h_tx_cnt); display_stat(w, "rx", "Received", h_rx_cnt); - display_stat(w, "rx_discarded_cnt", "Discarded", - h_rx_discarded_cnt); + display_stat(w, "rx_discarded_cnt", "Discarded", h_rx_discarded_cnt); display_stat(w, "rx_unrecognized_cnt", "Unrecognized", - h_rx_unrecognized_cnt); + h_rx_unrecognized_cnt); display_stat(w, "ageout_cnt", "Ageout", h_ageout_cnt); @@ -945,7 +944,8 @@ display_interfaces_stats(lldpctl_conn_t *conn, struct writer *w, } static const char * -N(const char *str) { +N(const char *str) +{ if (str == NULL || strlen(str) == 0) return "(none)"; return str; } @@ -974,14 +974,15 @@ display_configuration(lldpctl_conn_t *conn, struct writer *w) tag_datatag(w, "max-neighbors", "Maximum number of neighbors", lldpctl_atom_get_str(configuration, lldpctl_k_config_max_neighbors)); tag_datatag(w, "rx-only", "Receive mode", - lldpctl_atom_get_int(configuration, lldpctl_k_config_receiveonly)? - "yes":"no"); + lldpctl_atom_get_int(configuration, lldpctl_k_config_receiveonly) ? "yes" : + "no"); tag_datatag(w, "mgmt-pattern", "Pattern for management addresses", N(lldpctl_atom_get_str(configuration, lldpctl_k_config_mgmt_pattern))); tag_datatag(w, "iface-pattern", "Interface pattern", N(lldpctl_atom_get_str(configuration, lldpctl_k_config_iface_pattern))); tag_datatag(w, "perm-iface-pattern", "Permanent interface pattern", - N(lldpctl_atom_get_str(configuration, lldpctl_k_config_perm_iface_pattern))); + N(lldpctl_atom_get_str(configuration, + lldpctl_k_config_perm_iface_pattern))); tag_datatag(w, "cid-pattern", "Interface pattern for chassis ID", N(lldpctl_atom_get_str(configuration, lldpctl_k_config_cid_pattern))); tag_datatag(w, "cid-string", "Override chassis ID with", @@ -993,37 +994,42 @@ display_configuration(lldpctl_conn_t *conn, struct writer *w) tag_datatag(w, "hostname", "Override system name with", N(lldpctl_atom_get_str(configuration, lldpctl_k_config_hostname))); tag_datatag(w, "capabilities", "Override system capabilities", - lldpctl_atom_get_int(configuration, lldpctl_k_config_chassis_cap_override)? - "yes":"no"); + lldpctl_atom_get_int(configuration, lldpctl_k_config_chassis_cap_override) ? + "yes" : + "no"); tag_datatag(w, "advertise-version", "Advertise version", - lldpctl_atom_get_int(configuration, lldpctl_k_config_advertise_version)? - "yes":"no"); + lldpctl_atom_get_int(configuration, lldpctl_k_config_advertise_version) ? + "yes" : + "no"); tag_datatag(w, "ifdescr-update", "Update interface descriptions", - lldpctl_atom_get_int(configuration, lldpctl_k_config_ifdescr_update)? - "yes":"no"); + lldpctl_atom_get_int(configuration, lldpctl_k_config_ifdescr_update) ? + "yes" : + "no"); tag_datatag(w, "iface-promisc", "Promiscuous mode on managed interfaces", - lldpctl_atom_get_int(configuration, lldpctl_k_config_iface_promisc)? - "yes":"no"); + lldpctl_atom_get_int(configuration, lldpctl_k_config_iface_promisc) ? + "yes" : + "no"); tag_datatag(w, "lldpmed-no-inventory", "Disable LLDP-MED inventory", - (lldpctl_atom_get_int(configuration, lldpctl_k_config_lldpmed_noinventory) == 0)? - "no":"yes"); + (lldpctl_atom_get_int(configuration, + lldpctl_k_config_lldpmed_noinventory) == 0) ? + "no" : + "yes"); tag_datatag(w, "lldpmed-faststart", "LLDP-MED fast start mechanism", - (lldpctl_atom_get_int(configuration, lldpctl_k_config_fast_start_enabled) == 0)? - "no":"yes"); + (lldpctl_atom_get_int(configuration, lldpctl_k_config_fast_start_enabled) == + 0) ? + "no" : + "yes"); tag_datatag(w, "lldpmed-faststart-interval", "LLDP-MED fast start interval", - N(lldpctl_atom_get_str(configuration, lldpctl_k_config_fast_start_interval))); + N(lldpctl_atom_get_str(configuration, + lldpctl_k_config_fast_start_interval))); tag_datatag(w, "bond-slave-src-mac-type", - "Source MAC for LLDP frames on bond slaves", - lldpctl_atom_get_str(configuration, - lldpctl_k_config_bond_slave_src_mac_type)); - tag_datatag(w, "lldp-portid-type", - "Port ID TLV subtype for LLDP frames", - lldpctl_atom_get_str(configuration, - lldpctl_k_config_lldp_portid_type)); - tag_datatag(w, "lldp-agent-type", - "Agent type", - lldpctl_atom_get_str(configuration, - lldpctl_k_config_lldp_agent_type)); + "Source MAC for LLDP frames on bond slaves", + lldpctl_atom_get_str(configuration, + lldpctl_k_config_bond_slave_src_mac_type)); + tag_datatag(w, "lldp-portid-type", "Port ID TLV subtype for LLDP frames", + lldpctl_atom_get_str(configuration, lldpctl_k_config_lldp_portid_type)); + tag_datatag(w, "lldp-agent-type", "Agent type", + lldpctl_atom_get_str(configuration, lldpctl_k_config_lldp_agent_type)); tag_end(w); tag_end(w); diff --git a/src/client/json_writer.c b/src/client/json_writer.c index 1a4552f0..dc6665ad 100644 --- a/src/client/json_writer.c +++ b/src/client/json_writer.c @@ -28,12 +28,7 @@ #include "../compat/compat.h" #include "../log.h" -enum tag { - STRING, - BOOL, - ARRAY, - OBJECT -}; +enum tag { STRING, BOOL, ARRAY, OBJECT }; struct element { struct element *parent; /* Parent (if any) */ @@ -41,8 +36,8 @@ struct element { char *key; /* Key if parent is an object */ enum tag tag; /* Kind of element */ union { - char *string; /* STRING */ - int boolean; /* BOOL */ + char *string; /* STRING */ + int boolean; /* BOOL */ TAILQ_HEAD(, element) children; /* ARRAY or OBJECT */ }; }; @@ -56,13 +51,13 @@ struct json_writer_private { /* Create a new element. If a parent is provided, it will also be attached to * the parent. */ -static struct element* +static struct element * json_element_new(struct element *parent, const char *key, enum tag tag) { struct element *child = malloc(sizeof(*child)); if (child == NULL) fatal(NULL, NULL); child->parent = parent; - child->key = key?strdup(key):NULL; + child->key = key ? strdup(key) : NULL; child->tag = tag; TAILQ_INIT(&child->children); if (parent) TAILQ_INSERT_TAIL(&parent->children, child, next); @@ -82,9 +77,7 @@ json_element_free(struct element *current) break; case ARRAY: case OBJECT: - for (el = TAILQ_FIRST(¤t->children); - el != NULL; - el = el_next) { + for (el = TAILQ_FIRST(¤t->children); el != NULL; el = el_next) { el_next = TAILQ_NEXT(el, next); json_element_free(el); TAILQ_REMOVE(¤t->children, el, next); @@ -110,13 +103,34 @@ json_string_dump(FILE *fh, const char *s) unsigned int c = *s; size_t len; switch (c) { - case '"': fprintf(fh, "\\\""); s++; break; - case '\\': fprintf(fh, "\\\\"); s++; break; - case '\b': fprintf(fh, "\\b"); s++; break; - case '\f': fprintf(fh, "\\f"); s++; break; - case '\n': fprintf(fh, "\\n"); s++; break; - case '\r': fprintf(fh, "\\r"); s++; break; - case '\t': fprintf(fh, "\\t"); s++; break; + case '"': + fprintf(fh, "\\\""); + s++; + break; + case '\\': + fprintf(fh, "\\\\"); + s++; + break; + case '\b': + fprintf(fh, "\\b"); + s++; + break; + case '\f': + fprintf(fh, "\\f"); + s++; + break; + case '\n': + fprintf(fh, "\\n"); + s++; + break; + case '\r': + fprintf(fh, "\\r"); + s++; + break; + case '\t': + fprintf(fh, "\\t"); + s++; + break; default: len = utf8_validate_cz(s); if (len == 0) { @@ -130,7 +144,8 @@ json_string_dump(FILE *fh, const char *s) s++; } else { /* UTF-8, write as is */ - while (len--) fprintf(fh, "%c", *s++); + while (len--) + fprintf(fh, "%c", *s++); } break; } @@ -149,21 +164,18 @@ json_element_dump(FILE *fh, struct element *current, int indent) json_string_dump(fh, current->string); break; case BOOL: - fprintf(fh, current->boolean?"true":"false"); + fprintf(fh, current->boolean ? "true" : "false"); break; case ARRAY: case OBJECT: - fprintf(fh, "%c\n%*s", pairs[(current->tag == ARRAY)][0], - indent + 2, ""); - TAILQ_FOREACH(el, ¤t->children, next) { - if (current->tag == OBJECT) - fprintf(fh, "\"%s\": ", el->key); + fprintf(fh, "%c\n%*s", pairs[(current->tag == ARRAY)][0], indent + 2, + ""); + TAILQ_FOREACH (el, ¤t->children, next) { + if (current->tag == OBJECT) fprintf(fh, "\"%s\": ", el->key); json_element_dump(fh, el, indent + 2); - if (TAILQ_NEXT(el, next)) - fprintf(fh, ",\n%*s", indent + 2, ""); + if (TAILQ_NEXT(el, next)) fprintf(fh, ",\n%*s", indent + 2, ""); } - fprintf(fh, "\n%*c", indent + 1, - pairs[(current->tag == ARRAY)][1]); + fprintf(fh, "\n%*c", indent + 1, pairs[(current->tag == ARRAY)][1]); break; } } @@ -176,19 +188,17 @@ json_dump(struct json_writer_private *p) } static void -json_start(struct writer *w, const char *tag, - const char *descr) +json_start(struct writer *w, const char *tag, const char *descr) { struct json_writer_private *p = w->priv; struct element *child; struct element *new; /* Look for the tag in the current object. */ - TAILQ_FOREACH(child, &p->current->children, next) { + TAILQ_FOREACH (child, &p->current->children, next) { if (!strcmp(child->key, tag)) break; } - if (!child) - child = json_element_new(p->current, tag, ARRAY); + if (!child) child = json_element_new(p->current, tag, ARRAY); /* Queue the new element. */ new = json_element_new(child, NULL, OBJECT); @@ -196,8 +206,7 @@ json_start(struct writer *w, const char *tag, } static void -json_attr(struct writer *w, const char *tag, - const char *descr, const char *value) +json_attr(struct writer *w, const char *tag, const char *descr, const char *value) { struct json_writer_private *p = w->priv; struct element *new = json_element_new(p->current, tag, STRING); @@ -208,7 +217,7 @@ json_attr(struct writer *w, const char *tag, new->tag = BOOL; new->boolean = 0; } else { - new->string = strdup(value?value:""); + new->string = strdup(value ? value : ""); } } @@ -217,7 +226,7 @@ json_data(struct writer *w, const char *data) { struct json_writer_private *p = w->priv; struct element *new = json_element_new(p->current, "value", STRING); - new->string = strdup(data?data:""); + new->string = strdup(data ? data : ""); } /* When an array has only one member, just remove the array. When an object has @@ -240,8 +249,7 @@ json_element_cleanup(struct element *el) /* If array with one element, steal the content. Object with only one * value whose key is "value", steal the content. */ if ((el->tag == ARRAY || el->tag == OBJECT) && - (child = TAILQ_FIRST(&el->children)) && - !TAILQ_NEXT(child, next) && + (child = TAILQ_FIRST(&el->children)) && !TAILQ_NEXT(child, next) && (el->tag == ARRAY || !strcmp(child->key, "value"))) { free(child->key); child->key = el->key; @@ -255,9 +263,7 @@ json_element_cleanup(struct element *el) /* Other kind of arrays, recursively clean */ if (el->tag == ARRAY) { - for (child = TAILQ_FIRST(&el->children); - child; - child = child_next) { + for (child = TAILQ_FIRST(&el->children); child; child = child_next) { child_next = TAILQ_NEXT(child, next); json_element_cleanup(child); } @@ -269,19 +275,14 @@ json_element_cleanup(struct element *el) * one. */ if (el->tag == OBJECT) { struct element *name_child = NULL; - for (child = TAILQ_FIRST(&el->children); - child; - child = child_next) { + for (child = TAILQ_FIRST(&el->children); child; child = child_next) { child_next = TAILQ_NEXT(child, next); json_element_cleanup(child); } /* Redo a check to find if we have a "name" key now */ - for (child = TAILQ_FIRST(&el->children); - child; - child = child_next) { + for (child = TAILQ_FIRST(&el->children); child; child = child_next) { child_next = TAILQ_NEXT(child, next); - if (!strcmp(child->key, "name") && - child->tag == STRING) { + if (!strcmp(child->key, "name") && child->tag == STRING) { name_child = child; } } @@ -311,15 +312,15 @@ json_element_cleanup(struct element *el) static void json_cleanup(struct json_writer_private *p) { - if (p->variant != 0) - json_element_cleanup(p->root); + if (p->variant != 0) json_element_cleanup(p->root); } static void json_end(struct writer *w) { struct json_writer_private *p = w->priv; - while ((p->current = p->current->parent) != NULL && p->current->tag != OBJECT); + while ((p->current = p->current->parent) != NULL && p->current->tag != OBJECT) + ; if (p->current == NULL) { fatalx("lldpctl", "unbalanced tags"); return; @@ -330,7 +331,7 @@ json_end(struct writer *w) json_cleanup(p); json_dump(p); json_free(p); - fprintf(p->fh,"\n"); + fprintf(p->fh, "\n"); fflush(p->fh); p->root = p->current = json_element_new(NULL, NULL, OBJECT); } @@ -340,14 +341,13 @@ static void json_finish(struct writer *w) { struct json_writer_private *p = w->priv; - if (p->current != p->root) - log_warnx("lldpctl", "unbalanced tags"); + if (p->current != p->root) log_warnx("lldpctl", "unbalanced tags"); json_free(p); free(p); free(w); } -struct writer* +struct writer * json_init(FILE *fh, int variant) { struct writer *result; @@ -363,11 +363,11 @@ json_init(FILE *fh, int variant) result = malloc(sizeof(*result)); if (result == NULL) fatal(NULL, NULL); - result->priv = priv; - result->start = json_start; - result->attr = json_attr; - result->data = json_data; - result->end = json_end; + result->priv = priv; + result->start = json_start; + result->attr = json_attr; + result->data = json_data; + result->end = json_end; result->finish = json_finish; return result; diff --git a/src/client/kv_writer.c b/src/client/kv_writer.c index 68a50adf..96edfdef 100644 --- a/src/client/kv_writer.c +++ b/src/client/kv_writer.c @@ -26,24 +26,23 @@ #define SEP '.' struct kv_writer_private { - FILE * fh; - char * prefix; + FILE *fh; + char *prefix; }; void -kv_start(struct writer *w , const char *tag, const char *descr) +kv_start(struct writer *w, const char *tag, const char *descr) { struct kv_writer_private *p = w->priv; char *newprefix; int s; s = strlen(p->prefix) + 1 + strlen(tag); - if ((newprefix = malloc(s+1)) == NULL) - fatal(NULL, NULL); + if ((newprefix = malloc(s + 1)) == NULL) fatal(NULL, NULL); if (strlen(p->prefix) > 0) - snprintf(newprefix, s+1, "%s\1%s", p->prefix, tag); + snprintf(newprefix, s + 1, "%s\1%s", p->prefix, tag); else - snprintf(newprefix, s+1, "%s", tag); + snprintf(newprefix, s + 1, "%s", tag); free(p->prefix); p->prefix = newprefix; } @@ -53,7 +52,7 @@ kv_data(struct writer *w, const char *data) { struct kv_writer_private *p = w->priv; char *key = strdup(p->prefix); - char *value = data?strdup(data):NULL; + char *value = data ? strdup(data) : NULL; char *dot, *nl; if (!key) fatal(NULL, NULL); while ((dot = strchr(key, '\1')) != NULL) @@ -65,7 +64,7 @@ kv_data(struct writer *w, const char *data) nl++; } } - fprintf(p->fh, "%s=%s\n", key, value?value:""); + fprintf(p->fh, "%s=%s\n", key, value ? value : ""); free(key); free(value); } @@ -116,21 +115,19 @@ kv_init(FILE *fh) struct writer *result; struct kv_writer_private *priv; - if ((priv = malloc(sizeof(*priv))) == NULL) - fatal(NULL, NULL); + if ((priv = malloc(sizeof(*priv))) == NULL) fatal(NULL, NULL); priv->fh = fh; priv->prefix = strdup(""); - if ((result = malloc(sizeof(struct writer))) == NULL) - fatal(NULL, NULL); + if ((result = malloc(sizeof(struct writer))) == NULL) fatal(NULL, NULL); - result->priv = priv; + result->priv = priv; result->start = kv_start; - result->attr = kv_attr; - result->data = kv_data; - result->end = kv_end; - result->finish= kv_finish; + result->attr = kv_attr; + result->data = kv_data; + result->end = kv_end; + result->finish = kv_finish; return result; } diff --git a/src/client/lldpcli.c b/src/client/lldpcli.c index 3af19204..c54b6591 100644 --- a/src/client/lldpcli.c +++ b/src/client/lldpcli.c @@ -15,7 +15,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - #include #include #include @@ -35,9 +34,9 @@ #include "client.h" #ifdef HAVE___PROGNAME -extern const char *__progname; +extern const char *__progname; #else -# define __progname "lldpcli" +# define __progname "lldpcli" #endif /* Global for completion */ @@ -55,7 +54,7 @@ is_lldpctl(const char *name) last_result = (!strcmp(bname, "lldpctl")); free(basec); } - return (last_result == -1)?0:last_result; + return (last_result == -1) ? 0 : last_result; } static void @@ -67,8 +66,10 @@ usage() fprintf(stderr, "\n"); fprintf(stderr, "-d Enable more debugging information.\n"); - fprintf(stderr, "-u socket Specify the Unix-domain socket used for communication with lldpd(8).\n"); - fprintf(stderr, "-f format Choose output format (plain, keyvalue, json, json0" + fprintf(stderr, + "-u socket Specify the Unix-domain socket used for communication with lldpd(8).\n"); + fprintf(stderr, + "-f format Choose output format (plain, keyvalue, json, json0" #if defined USE_XML ", xml" #endif @@ -88,17 +89,16 @@ is_privileged() /* Check we can access the control socket with read/write * privileges. The `access()` function uses the real UID and real GID, * therefore we don't have to mangle with our identity. */ - return (ctlname && access(ctlname, R_OK|W_OK) == 0); + return (ctlname && access(ctlname, R_OK | W_OK) == 0); } -static char* +static char * prompt() { #define CESC "\033" int privileged = is_privileged(); if (isatty(STDIN_FILENO)) { - if (privileged) - return "[lldpcli] # "; + if (privileged) return "[lldpcli] # "; return "[lldpcli] $ "; } return ""; @@ -109,8 +109,7 @@ static int must_exit = 0; * Exit the interpreter. */ static int -cmd_exit(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_exit(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *arg) { log_info("lldpctl", "quit lldpcli"); must_exit = 1; @@ -121,8 +120,8 @@ cmd_exit(struct lldpctl_conn_t *conn, struct writer *w, * Send an "update" request. */ static int -cmd_update(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_update(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_info("lldpctl", "ask for global update"); @@ -132,9 +131,9 @@ cmd_update(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_last_strerror(conn)); return 0; } - if (lldpctl_atom_set_int(config, - lldpctl_k_config_tx_interval, -1) == NULL) { - log_warnx("lldpctl", "unable to ask lldpd for immediate retransmission. %s", + if (lldpctl_atom_set_int(config, lldpctl_k_config_tx_interval, -1) == NULL) { + log_warnx("lldpctl", + "unable to ask lldpd for immediate retransmission. %s", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; @@ -162,37 +161,36 @@ cmd_pause_resume(lldpctl_conn_t *conn, int pause) } if (lldpctl_atom_get_int(config, lldpctl_k_config_paused) == pause) { log_debug("lldpctl", "lldpd is already %s", - pause?"paused":"resumed"); + pause ? "paused" : "resumed"); lldpctl_atom_dec_ref(config); return 1; } - if (lldpctl_atom_set_int(config, - lldpctl_k_config_paused, pause) == NULL) { + if (lldpctl_atom_set_int(config, lldpctl_k_config_paused, pause) == NULL) { log_warnx("lldpctl", "unable to ask lldpd to %s operations. %s", - pause?"pause":"resume", - lldpctl_last_strerror(conn)); + pause ? "pause" : "resume", lldpctl_last_strerror(conn)); lldpctl_atom_dec_ref(config); return 0; } - log_info("lldpctl", "lldpd should %s operations", - pause?"pause":"resume"); + log_info("lldpctl", "lldpd should %s operations", pause ? "pause" : "resume"); lldpctl_atom_dec_ref(config); return 1; } static int -cmd_pause(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) { - (void)w; (void)env; +cmd_pause(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *arg) +{ + (void)w; + (void)env; return cmd_pause_resume(conn, 1); } static int -cmd_resume(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) { - (void)w; (void)env; +cmd_resume(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) +{ + (void)w; + (void)env; return cmd_pause_resume(conn, 0); } - #ifdef HAVE_LIBREADLINE static int _cmd_complete(int all) @@ -204,24 +202,24 @@ _cmd_complete(int all) char *line = malloc(len + 2); if (!line) return -1; strlcpy(line, rl_line_buffer, len + 2); - line[rl_point] = 2; /* empty character, will force a word */ - line[rl_point+1] = 0; + line[rl_point] = 2; /* empty character, will force a word */ + line[rl_point + 1] = 0; - if (tokenize_line(line, &argc, &argv) != 0) - goto end; + if (tokenize_line(line, &argc, &argv) != 0) goto end; - char *compl = commands_complete(root, argc, (const char **)argv, all, is_privileged()); - if (compl && strlen(argv[argc-1]) < strlen(compl)) { - if (rl_insert_text(compl + strlen(argv[argc-1])) < 0) { - free(compl); + char *compl = + commands_complete(root, argc, (const char **)argv, all, is_privileged()); + if (compl &&strlen(argv[argc - 1]) < strlen(compl )) { + if (rl_insert_text(compl +strlen(argv[argc - 1])) < 0) { + free(compl ); goto end; } - free(compl); + free(compl ); rc = 0; goto end; } /* No completion or several completion available. */ - free(compl); + free(compl ); fprintf(stderr, "\n"); rl_forced_update_display(); rc = 0; @@ -243,14 +241,13 @@ cmd_help(int count, int ch) return _cmd_complete(1); } #else -static char* +static char * readline(const char *p) { static char line[2048]; fprintf(stderr, "%s", p); fflush(stderr); - if (fgets(line, sizeof(line) - 2, stdin) == NULL) - return NULL; + if (fgets(line, sizeof(line) - 2, stdin) == NULL) return NULL; return strdup(line); } #endif @@ -270,12 +267,17 @@ cmd_exec(lldpctl_conn_t *conn, const char *fmt, int argc, const char **argv) /* Init output formatter */ struct writer *w; - if (strcmp(fmt, "plain") == 0) w = txt_init(stdout); - else if (strcmp(fmt, "keyvalue") == 0) w = kv_init(stdout); - else if (strcmp(fmt, "json") == 0) w = json_init(stdout, 1); - else if (strcmp(fmt, "json0") == 0) w = json_init(stdout, 0); + if (strcmp(fmt, "plain") == 0) + w = txt_init(stdout); + else if (strcmp(fmt, "keyvalue") == 0) + w = kv_init(stdout); + else if (strcmp(fmt, "json") == 0) + w = json_init(stdout, 1); + else if (strcmp(fmt, "json0") == 0) + w = json_init(stdout, 0); #ifdef USE_XML - else if (strcmp(fmt, "xml") == 0) w = xml_init(stdout); + else if (strcmp(fmt, "xml") == 0) + w = xml_init(stdout); #endif else { log_warnx("lldpctl", "unknown output format \"%s\"", fmt); @@ -283,8 +285,7 @@ cmd_exec(lldpctl_conn_t *conn, const char *fmt, int argc, const char **argv) } /* Execute command */ - int rc = commands_execute(conn, w, - root, argc, argv, is_privileged()); + int rc = commands_execute(conn, w, root, argc, argv, is_privileged()); if (rc != 0) { log_info("lldpctl", "an error occurred while executing last command"); w->finish(w); @@ -305,7 +306,8 @@ cmd_exec(lldpctl_conn_t *conn, const char *fmt, int argc, const char **argv) static int parse_and_exec(lldpctl_conn_t *conn, const char *fmt, const char *line) { - int cargc = 0; char **cargv = NULL; + int cargc = 0; + char **cargv = NULL; int n; log_debug("lldpctl", "tokenize command line"); n = tokenize_line(line, &cargc, &cargv); @@ -317,39 +319,37 @@ parse_and_exec(lldpctl_conn_t *conn, const char *fmt, const char *line) log_warnx("lldpctl", "unmatched quotes"); return -1; } - if (cargc != 0) - n = cmd_exec(conn, fmt, cargc, (const char **)cargv); + if (cargc != 0) n = cmd_exec(conn, fmt, cargc, (const char **)cargv); tokenize_free(cargc, cargv); - return (cargc == 0)?0: - (n == 0)?-1: - 1; + return (cargc == 0) ? 0 : (n == 0) ? -1 : 1; } -static struct cmd_node* +static struct cmd_node * register_commands() { root = commands_root(); register_commands_show(root); register_commands_watch(root); - commands_privileged(commands_new( - commands_new(root, "update", "Update information and send LLDPU on all ports", - NULL, NULL, NULL), - NEWLINE, "Update information and send LLDPU on all ports", - NULL, cmd_update, NULL)); + commands_privileged( + commands_new(commands_new(root, "update", + "Update information and send LLDPU on all ports", NULL, + NULL, NULL), + NEWLINE, "Update information and send LLDPU on all ports", NULL, + cmd_update, NULL)); register_commands_configure(root); - commands_hidden(commands_new(root, "complete", "Get possible completions from a given command", - NULL, cmd_store_env_and_pop, "complete")); - commands_new(root, "help", "Get help on a possible command", - NULL, cmd_store_env_and_pop, "help"); - commands_new( - commands_new(root, "pause", "Pause lldpd operations", NULL, NULL, NULL), - NEWLINE, "Pause lldpd operations", NULL, cmd_pause, NULL); - commands_new( - commands_new(root, "resume", "Resume lldpd operations", NULL, NULL, NULL), - NEWLINE, "Resume lldpd operations", NULL, cmd_resume, NULL); - commands_new( - commands_new(root, "exit", "Exit interpreter", NULL, NULL, NULL), - NEWLINE, "Exit interpreter", NULL, cmd_exit, NULL); + commands_hidden(commands_new(root, "complete", + "Get possible completions from a given command", NULL, + cmd_store_env_and_pop, "complete")); + commands_new(root, "help", "Get help on a possible command", NULL, + cmd_store_env_and_pop, "help"); + commands_new(commands_new(root, "pause", "Pause lldpd operations", NULL, NULL, + NULL), + NEWLINE, "Pause lldpd operations", NULL, cmd_pause, NULL); + commands_new(commands_new(root, "resume", "Resume lldpd operations", NULL, NULL, + NULL), + NEWLINE, "Resume lldpd operations", NULL, cmd_resume, NULL); + commands_new(commands_new(root, "exit", "Exit interpreter", NULL, NULL, NULL), + NEWLINE, "Exit interpreter", NULL, cmd_exit, NULL); return root; } @@ -379,11 +379,11 @@ input_append(const char *arg, struct inputs *inputs, int acceptdir, int warn) struct stat statbuf; if (stat(arg, &statbuf) == -1) { if (warn) { - log_warn("lldpctl", "cannot find configuration file/directory %s", - arg); + log_warn("lldpctl", + "cannot find configuration file/directory %s", arg); } else { - log_debug("lldpctl", "cannot find configuration file/directory %s", - arg); + log_debug("lldpctl", + "cannot find configuration file/directory %s", arg); } return; } @@ -391,8 +391,7 @@ input_append(const char *arg, struct inputs *inputs, int acceptdir, int warn) if (!S_ISDIR(statbuf.st_mode)) { struct input *input = malloc(sizeof(struct input)); if (!input) { - log_warn("lldpctl", "not enough memory to process %s", - arg); + log_warn("lldpctl", "not enough memory to process %s", arg); return; } log_debug("lldpctl", "input: %s", arg); @@ -401,19 +400,17 @@ input_append(const char *arg, struct inputs *inputs, int acceptdir, int warn) return; } if (!acceptdir) { - log_debug("lldpctl", "skip directory %s", - arg); + log_debug("lldpctl", "skip directory %s", arg); return; } struct dirent **namelist = NULL; - int n = scandir(arg, &namelist, filter, alphasort); + int n = scandir(arg, &namelist, filter, alphasort); if (n < 0) { - log_warnx("lldpctl", "unable to read directory %s", - arg); + log_warnx("lldpctl", "unable to read directory %s", arg); return; } - for (int i=0; i < n; i++) { + for (int i = 0; i < n; i++) { char *fullname; if (asprintf(&fullname, "%s/%s", arg, namelist[i]->d_name) != -1) { input_append(fullname, inputs, 0, 1); @@ -430,7 +427,7 @@ main(int argc, char *argv[]) int ch, debug = 0, use_syslog = 0, rc = EXIT_FAILURE; const char *fmt = "plain"; lldpctl_conn_t *conn = NULL; - const char *options = is_lldpctl(argv[0])?"hdvf:u:":"hdsvf:c:C:u:"; + const char *options = is_lldpctl(argv[0]) ? "hdvf:u:" : "hdsvf:c:C:u:"; lldpctl_atom_t *configuration; int gotinputs = 0, version = 0; @@ -522,7 +519,8 @@ main(int argc, char *argv[]) size_t n; ssize_t len; char *line; - while (line = NULL, len = 0, (len = getline(&line, &n, file)) > 0) { + while (line = NULL, len = 0, + (len = getline(&line, &n, file)) > 0) { if (line[len - 1] == '\n') { line[len - 1] = '\0'; parse_and_exec(conn, fmt, line); @@ -532,8 +530,7 @@ main(int argc, char *argv[]) free(line); fclose(file); } else { - log_warn("lldpctl", "unable to open %s", - first->name); + log_warn("lldpctl", "unable to open %s", first->name); } TAILQ_REMOVE(&inputs, first, next); free(first->name); @@ -545,10 +542,10 @@ main(int argc, char *argv[]) char *line = NULL; for (int i = optind; i < argc; i++) { char *prev = line; - if (asprintf(&line, "%s%s%s", - prev?prev:"show neigh ports ", argv[i], - (i == argc - 1)?" details":",") == -1) { - log_warnx("lldpctl", "not enough memory to build list of interfaces"); + if (asprintf(&line, "%s%s%s", prev ? prev : "show neigh ports ", + argv[i], (i == argc - 1) ? " details" : ",") == -1) { + log_warnx("lldpctl", + "not enough memory to build list of interfaces"); free(prev); goto end; } @@ -559,8 +556,7 @@ main(int argc, char *argv[]) goto end; } log_debug("lldpctl", "execute %s", line); - if (parse_and_exec(conn, fmt, line) != -1) - rc = EXIT_SUCCESS; + if (parse_and_exec(conn, fmt, line) != -1) rc = EXIT_SUCCESS; free(line); goto end; } @@ -571,8 +567,7 @@ main(int argc, char *argv[]) int cargc; cargv = &((const char **)argv)[optind]; cargc = argc - optind; - if (cmd_exec(conn, fmt, cargc, cargv) == 1) - rc = EXIT_SUCCESS; + if (cmd_exec(conn, fmt, cargc, cargv) == 1) rc = EXIT_SUCCESS; goto end; } @@ -583,7 +578,7 @@ main(int argc, char *argv[]) /* Interactive session */ #ifdef HAVE_LIBREADLINE - rl_bind_key('?', cmd_help); + rl_bind_key('?', cmd_help); rl_bind_key('\t', cmd_complete); #endif char *line = NULL; diff --git a/src/client/misc.c b/src/client/misc.c index c6ce9caa..3b06a121 100644 --- a/src/client/misc.c +++ b/src/client/misc.c @@ -49,19 +49,24 @@ contains(const char *list, const char *element) * @param value String to transform to a tag. * @return The tagged value or the string "none" if @c value is @c NULL */ -char* +char * totag(const char *value) { int i; static char *result = NULL; - free(result); result = NULL; + free(result); + result = NULL; if (!value) return "none"; result = calloc(1, strlen(value) + 1); if (!result) return "none"; for (i = 0; i < strlen(value); i++) { switch (value[i]) { - case ' ': result[i] = '-'; break; - default: result[i] = tolower((int)value[i]); break; + case ' ': + result[i] = '-'; + break; + default: + result[i] = tolower((int)value[i]); + break; } } return result; diff --git a/src/client/show.c b/src/client/show.c index 139a3cb3..fdbbae10 100644 --- a/src/client/show.c +++ b/src/client/show.c @@ -29,21 +29,22 @@ * - C{detailed} for a detailed overview */ static int -cmd_show_neighbors(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_show_neighbors(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "show neighbors data (%s) %s hidden neighbors", - cmdenv_get(env, "summary")?"summary": - cmdenv_get(env, "detailed")?"detailed": - "normal", cmdenv_get(env, "hidden")?"with":"without"); + cmdenv_get(env, "summary") ? "summary" : + cmdenv_get(env, "detailed") ? "detailed" : + "normal", + cmdenv_get(env, "hidden") ? "with" : "without"); if (cmdenv_get(env, "ports")) log_debug("lldpctl", "restrict to the following ports: %s", cmdenv_get(env, "ports")); display_interfaces(conn, w, env, !!cmdenv_get(env, "hidden"), - cmdenv_get(env, "summary")?DISPLAY_BRIEF: - cmdenv_get(env, "detailed")?DISPLAY_DETAILS: - DISPLAY_NORMAL); + cmdenv_get(env, "summary") ? DISPLAY_BRIEF : + cmdenv_get(env, "detailed") ? DISPLAY_DETAILS : + DISPLAY_NORMAL); return 1; } @@ -58,21 +59,22 @@ cmd_show_neighbors(struct lldpctl_conn_t *conn, struct writer *w, * - C{detailed} for a detailed overview */ static int -cmd_show_interfaces(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_show_interfaces(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "show interfaces data (%s) %s hidden interfaces", - cmdenv_get(env, "summary")?"summary": - cmdenv_get(env, "detailed")?"detailed": - "normal", cmdenv_get(env, "hidden")?"with":"without"); + cmdenv_get(env, "summary") ? "summary" : + cmdenv_get(env, "detailed") ? "detailed" : + "normal", + cmdenv_get(env, "hidden") ? "with" : "without"); if (cmdenv_get(env, "ports")) log_debug("lldpctl", "restrict to the following ports: %s", cmdenv_get(env, "ports")); display_local_interfaces(conn, w, env, !!cmdenv_get(env, "hidden"), - cmdenv_get(env, "summary")?DISPLAY_BRIEF: - cmdenv_get(env, "detailed")?DISPLAY_DETAILS: - DISPLAY_NORMAL); + cmdenv_get(env, "summary") ? DISPLAY_BRIEF : + cmdenv_get(env, "detailed") ? DISPLAY_DETAILS : + DISPLAY_NORMAL); return 1; } @@ -85,18 +87,18 @@ cmd_show_interfaces(struct lldpctl_conn_t *conn, struct writer *w, * - C{detailed} for a detailed overview */ static int -cmd_show_chassis(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_show_chassis(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { log_debug("lldpctl", "show chassis data (%s)", - cmdenv_get(env, "summary")?"summary": - cmdenv_get(env, "detailed")?"detailed": - "normal"); + cmdenv_get(env, "summary") ? "summary" : + cmdenv_get(env, "detailed") ? "detailed" : + "normal"); display_local_chassis(conn, w, env, - cmdenv_get(env, "summary")?DISPLAY_BRIEF: - cmdenv_get(env, "detailed")?DISPLAY_DETAILS: - DISPLAY_NORMAL); + cmdenv_get(env, "summary") ? DISPLAY_BRIEF : + cmdenv_get(env, "detailed") ? DISPLAY_DETAILS : + DISPLAY_NORMAL); return 1; } @@ -154,9 +156,7 @@ struct watcharg { * Callback for the next function to display a new neighbor. */ static void -watchcb(lldpctl_change_t type, - lldpctl_atom_t *interface, - lldpctl_atom_t *neighbor, +watchcb(lldpctl_change_t type, lldpctl_atom_t *interface, lldpctl_atom_t *neighbor, void *data) { struct watcharg *wa = data; @@ -166,8 +166,9 @@ watchcb(lldpctl_change_t type, const char *proto_str; int protocol = LLDPD_MODE_MAX; - if (interfaces && !contains(interfaces, lldpctl_atom_get_str(interface, - lldpctl_k_interface_name))) + if (interfaces && + !contains(interfaces, + lldpctl_atom_get_str(interface, lldpctl_k_interface_name))) return; /* user might have specified protocol to filter display results */ @@ -176,11 +177,10 @@ watchcb(lldpctl_change_t type, if (proto_str) { log_debug("display", "filter protocol: %s ", proto_str); - protocol = 0; /* unsupported */ + protocol = 0; /* unsupported */ for (lldpctl_map_t *protocol_map = lldpctl_key_get_map(lldpctl_k_port_protocol); - protocol_map->string; - protocol_map++) { + protocol_map->string; protocol_map++) { if (!strcasecmp(proto_str, protocol_map->string)) { protocol = protocol_map->value; break; @@ -198,12 +198,14 @@ watchcb(lldpctl_change_t type, case lldpctl_c_added: tag_start(w, "lldp-added", "LLDP neighbor added"); break; - default: return; + default: + return; } display_interface(NULL, w, 1, interface, neighbor, - cmdenv_get(env, "summary")?DISPLAY_BRIEF: - cmdenv_get(env, "detailed")?DISPLAY_DETAILS: - DISPLAY_NORMAL, protocol); + cmdenv_get(env, "summary") ? DISPLAY_BRIEF : + cmdenv_get(env, "detailed") ? DISPLAY_DETAILS : + DISPLAY_NORMAL, + protocol); tag_end(w); wa->nb++; } @@ -212,14 +214,10 @@ watchcb(lldpctl_change_t type, * Watch for neighbor changes. */ static int -cmd_watch_neighbors(struct lldpctl_conn_t *conn, struct writer *w, - struct cmd_env *env, void *arg) +cmd_watch_neighbors(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, + void *arg) { - struct watcharg wa = { - .env = env, - .w = w, - .nb = 0 - }; + struct watcharg wa = { .env = env, .w = w, .nb = 0 }; const char *limit_str = cmdenv_get(env, "limit"); size_t limit = 0; @@ -244,8 +242,7 @@ cmd_watch_neighbors(struct lldpctl_conn_t *conn, struct writer *w, lldpctl_last_strerror(conn)); return 0; } - if (limit > 0 && wa.nb >= limit) - return 1; + if (limit > 0 && wa.nb >= limit) return 1; } return 0; } @@ -257,24 +254,18 @@ void register_common_commands(struct cmd_node *root, int neighbor) { /* With more details */ - commands_new(root, - "details", - "With more details", + commands_new(root, "details", "With more details", cmd_check_no_detailed_nor_summary, cmd_store_env_and_pop, "detailed"); /* With less details */ - commands_new(root, - "summary", - "With less details", + commands_new(root, "summary", "With less details", cmd_check_no_detailed_nor_summary, cmd_store_env_and_pop, "summary"); if (!neighbor) return; /* With hidden neighbors */ - commands_new(root, - "hidden", - "Include hidden neighbors", - cmd_check_no_env, cmd_store_env_and_pop, "hidden"); + commands_new(root, "hidden", "Include hidden neighbors", cmd_check_no_env, + cmd_store_env_and_pop, "hidden"); /* Some specific port */ cmd_restrict_ports(root); @@ -289,10 +280,8 @@ register_common_commands(struct cmd_node *root, int neighbor) void register_summary_command(struct cmd_node *root) { - commands_new(root, - "summary", - "With less details", - cmd_check_no_detailed_nor_summary, cmd_store_env_and_pop, "summary"); + commands_new(root, "summary", "With less details", + cmd_check_no_detailed_nor_summary, cmd_store_env_and_pop, "summary"); } /** @@ -303,86 +292,53 @@ register_summary_command(struct cmd_node *root) void register_commands_show(struct cmd_node *root) { - struct cmd_node *show = commands_new( - root, - "show", - "Show running system information", - NULL, NULL, NULL); - struct cmd_node *neighbors = commands_new( - show, - "neighbors", - "Show neighbors data", - NULL, NULL, NULL); - - struct cmd_node *interfaces = commands_new( - show, - "interfaces", - "Show interfaces data", - NULL, NULL, NULL); - - struct cmd_node *chassis = commands_new( - show, - "chassis", - "Show local chassis data", - NULL, NULL, NULL); - - struct cmd_node *stats = commands_new( - show, - "statistics", - "Show statistics", - NULL, NULL, NULL); + struct cmd_node *show = commands_new(root, "show", + "Show running system information", NULL, NULL, NULL); + struct cmd_node *neighbors = + commands_new(show, "neighbors", "Show neighbors data", NULL, NULL, NULL); + + struct cmd_node *interfaces = + commands_new(show, "interfaces", "Show interfaces data", NULL, NULL, NULL); + + struct cmd_node *chassis = + commands_new(show, "chassis", "Show local chassis data", NULL, NULL, NULL); + + struct cmd_node *stats = + commands_new(show, "statistics", "Show statistics", NULL, NULL, NULL); /* Neighbors data */ - commands_new(neighbors, - NEWLINE, - "Show neighbors data", - NULL, cmd_show_neighbors, NULL); + commands_new(neighbors, NEWLINE, "Show neighbors data", NULL, + cmd_show_neighbors, NULL); register_common_commands(neighbors, 1); /* Interfaces data */ - commands_new(interfaces, - NEWLINE, - "Show interfaces data", - NULL, cmd_show_interfaces, NULL); + commands_new(interfaces, NEWLINE, "Show interfaces data", NULL, + cmd_show_interfaces, NULL); cmd_restrict_ports(interfaces); register_common_commands(interfaces, 0); /* Chassis data */ - commands_new(chassis, - NEWLINE, - "Show local chassis data", - NULL, cmd_show_chassis, NULL); + commands_new(chassis, NEWLINE, "Show local chassis data", NULL, + cmd_show_chassis, NULL); register_common_commands(chassis, 0); /* Stats data */ - commands_new(stats, - NEWLINE, - "Show stats data", - NULL, cmd_show_interface_stats, NULL); + commands_new(stats, NEWLINE, "Show stats data", NULL, cmd_show_interface_stats, + NULL); cmd_restrict_ports(stats); register_summary_command(stats); /* Register "show configuration" and "show running-configuration" */ - commands_new( - commands_new(show, - "configuration", - "Show running configuration", - NULL, NULL, NULL), - NEWLINE, - "Show running configuration", - NULL, cmd_show_configuration, NULL); - commands_new( - commands_new(show, - "running-configuration", - "Show running configuration", - NULL, NULL, NULL), - NEWLINE, - "Show running configuration", - NULL, cmd_show_configuration, NULL); + commands_new(commands_new(show, "configuration", "Show running configuration", + NULL, NULL, NULL), + NEWLINE, "Show running configuration", NULL, cmd_show_configuration, NULL); + commands_new(commands_new(show, "running-configuration", + "Show running configuration", NULL, NULL, NULL), + NEWLINE, "Show running configuration", NULL, cmd_show_configuration, NULL); } /** @@ -393,25 +349,16 @@ register_commands_show(struct cmd_node *root) void register_commands_watch(struct cmd_node *root) { - struct cmd_node *watch = commands_new( - root, - "watch", - "Monitor neighbor changes", - NULL, NULL, NULL); - - commands_new(watch, - NEWLINE, - "Monitor neighbors change", - NULL, cmd_watch_neighbors, NULL); - - commands_new( - commands_new(watch, - "limit", - "Don't show more than X events", - cmd_check_no_env, NULL, "limit"), - NULL, - "Stop after getting X events", - NULL, cmd_store_env_value_and_pop2, "limit"); + struct cmd_node *watch = + commands_new(root, "watch", "Monitor neighbor changes", NULL, NULL, NULL); + + commands_new(watch, NEWLINE, "Monitor neighbors change", NULL, + cmd_watch_neighbors, NULL); + + commands_new(commands_new(watch, "limit", "Don't show more than X events", + cmd_check_no_env, NULL, "limit"), + NULL, "Stop after getting X events", NULL, cmd_store_env_value_and_pop2, + "limit"); register_common_commands(watch, 1); } diff --git a/src/client/text_writer.c b/src/client/text_writer.c index 02e97a47..46664d09 100644 --- a/src/client/text_writer.c +++ b/src/client/text_writer.c @@ -22,16 +22,18 @@ #include "writer.h" #include "../log.h" -static char sep[] = "-------------------------------------------------------------------------------"; +static char sep[] = + "-------------------------------------------------------------------------------"; struct txt_writer_private { - FILE * fh; - int level; - int attrs; + FILE *fh; + int level; + int attrs; }; static void -txt_start(struct writer *w , const char *tag, const char *descr) { +txt_start(struct writer *w, const char *tag, const char *descr) +{ struct txt_writer_private *p = w->priv; int i = 0; char buf[128]; @@ -49,34 +51,37 @@ txt_start(struct writer *w , const char *tag, const char *descr) { snprintf(buf, sizeof(buf), "%s:", descr); fprintf(p->fh, "%-13s", buf); - if (p->level == 0) - fprintf(p->fh, "\n%s", sep); + if (p->level == 0) fprintf(p->fh, "\n%s", sep); p->level++; p->attrs = 0; } static void -txt_attr(struct writer *w, const char *tag, const char *descr, const char *value) { +txt_attr(struct writer *w, const char *tag, const char *descr, const char *value) +{ struct txt_writer_private *p = w->priv; if (descr == NULL || strlen(descr) == 0) { - fprintf(p->fh, "%s%s", (p->attrs > 0 ? ", " : " "), value?value:"(none)"); + fprintf(p->fh, "%s%s", (p->attrs > 0 ? ", " : " "), + value ? value : "(none)"); } else { - fprintf(p->fh, "%s%s: %s", (p->attrs > 0 ? ", " : " "), descr, value?value:"(none)"); + fprintf(p->fh, "%s%s: %s", (p->attrs > 0 ? ", " : " "), descr, + value ? value : "(none)"); } p->attrs++; } static void -txt_data(struct writer *w, const char *data) { +txt_data(struct writer *w, const char *data) +{ struct txt_writer_private *p = w->priv; char *nl, *begin; - char *v = begin = data?strdup(data):NULL; + char *v = begin = data ? strdup(data) : NULL; if (v == NULL) { - fprintf(p->fh, " %s", data?data:"(none)"); + fprintf(p->fh, " %s", data ? data : "(none)"); return; } @@ -98,7 +103,8 @@ txt_data(struct writer *w, const char *data) { } static void -txt_end(struct writer *w) { +txt_end(struct writer *w) +{ struct txt_writer_private *p = w->priv; p->level--; @@ -109,7 +115,8 @@ txt_end(struct writer *w) { } static void -txt_finish(struct writer *w) { +txt_finish(struct writer *w) +{ struct txt_writer_private *p = w->priv; fprintf(p->fh, "\n"); @@ -120,8 +127,9 @@ txt_finish(struct writer *w) { free(w); } -struct writer* -txt_init(FILE* fh) { +struct writer * +txt_init(FILE *fh) +{ struct writer *result; struct txt_writer_private *priv; @@ -143,12 +151,12 @@ txt_init(FILE* fh) { return NULL; } - result->priv = priv; + result->priv = priv; result->start = txt_start; - result->attr = txt_attr; - result->data = txt_data; - result->end = txt_end; - result->finish= txt_finish; + result->attr = txt_attr; + result->data = txt_data; + result->end = txt_end; + result->finish = txt_finish; return result; } diff --git a/src/client/tokenizer.c b/src/client/tokenizer.c index 234091f7..6d3ddaa7 100644 --- a/src/client/tokenizer.c +++ b/src/client/tokenizer.c @@ -30,22 +30,22 @@ int tokenize_line(const char *line, int *argc, char ***argv) { - int iargc = 0; char **iargv = NULL; - char *ifs = " \n\t"; - char *quotes = "'\""; + int iargc = 0; + char **iargv = NULL; + char *ifs = " \n\t"; + char *quotes = "'\""; char *escapes = "\\"; - char empty = 2; /* Empty character, will be removed from output - * but will mark a word. */ + char empty = 2; /* Empty character, will be removed from output + * but will mark a word. */ /* Escape handle. Also escape quoted characters. */ int escaped = 0; int ipos = 0; char quote = 0; - char input[2*strlen(line) + 3]; /* 3 = 2 for '\n ' and 1 for \0 */ - memset(input, 0, 2*strlen(line) + 3); + char input[2 * strlen(line) + 3]; /* 3 = 2 for '\n ' and 1 for \0 */ + memset(input, 0, 2 * strlen(line) + 3); for (int pos = 0; line[pos]; pos++) { - if (line[pos] == '#' && !escaped && !quote) - break; + if (line[pos] == '#' && !escaped && !quote) break; if (!escaped && strchr(escapes, line[pos])) escaped = 1; else if (!escaped && strchr(quotes, line[pos]) && !quote) { @@ -56,7 +56,7 @@ tokenize_line(const char *line, int *argc, char ***argv) quote = 0; else { input[ipos++] = line[pos]; - input[ipos++] = (escaped || quote)?'!':' '; + input[ipos++] = (escaped || quote) ? '!' : ' '; escaped = 0; } } @@ -66,10 +66,10 @@ tokenize_line(const char *line, int *argc, char ***argv) input[ipos++] = ' '; /* Tokenize, we don't have to handle quotes anymore */ - int wbegin = -1; /* Offset of the beginning of the current word */ + int wbegin = -1; /* Offset of the beginning of the current word */ -#define CURRENT (input[2*pos]) -#define ESCAPED (input[2*pos+1] != ' ') +#define CURRENT (input[2 * pos]) +#define ESCAPED (input[2 * pos + 1] != ' ') for (int pos = 0; CURRENT; pos++) { if (wbegin == -1) { if (!ESCAPED && strchr(ifs, CURRENT)) @@ -79,25 +79,22 @@ tokenize_line(const char *line, int *argc, char ***argv) wbegin = pos; continue; } - if (ESCAPED || !strchr(ifs, CURRENT)) - /* Regular character in a word. */ + if (ESCAPED || !strchr(ifs, CURRENT)) /* Regular character in a word. */ continue; /* End of word. */ char *word = calloc(1, pos - wbegin + 1); if (!word) goto error; - int i,j; - for (i = wbegin, j = 0; - i != pos; - i++) - if (input[2*i] != empty) word[j++] = input[2*i]; - char **nargv = realloc(iargv, sizeof(char*) * (iargc + 1)); + int i, j; + for (i = wbegin, j = 0; i != pos; i++) + if (input[2 * i] != empty) word[j++] = input[2 * i]; + char **nargv = realloc(iargv, sizeof(char *) * (iargc + 1)); if (!nargv) { free(word); goto error; } nargv[iargc++] = word; - iargv = nargv; + iargv = nargv; wbegin = -1; } @@ -113,7 +110,7 @@ error: void tokenize_free(int argc, char **argv) { - while (argc) free(argv[--argc]); + while (argc) + free(argv[--argc]); free(argv); } - diff --git a/src/client/utf8.c b/src/client/utf8.c index 21076393..2b78364e 100644 --- a/src/client/utf8.c +++ b/src/client/utf8.c @@ -46,54 +46,44 @@ size_t utf8_validate_cz(const char *s) { - unsigned char c = *s++; + unsigned char c = *s++; - if (c <= 0x7F) { /* 00..7F */ - return 1; - } else if (c <= 0xC1) { /* 80..C1 */ - /* Disallow overlong 2-byte sequence. */ - return 0; - } else if (c <= 0xDF) { /* C2..DF */ - /* Make sure subsequent byte is in the range 0x80..0xBF. */ - if (((unsigned char)*s++ & 0xC0) != 0x80) - return 0; + if (c <= 0x7F) { /* 00..7F */ + return 1; + } else if (c <= 0xC1) { /* 80..C1 */ + /* Disallow overlong 2-byte sequence. */ + return 0; + } else if (c <= 0xDF) { /* C2..DF */ + /* Make sure subsequent byte is in the range 0x80..0xBF. */ + if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; - return 2; - } else if (c <= 0xEF) { /* E0..EF */ - /* Disallow overlong 3-byte sequence. */ - if (c == 0xE0 && (unsigned char)*s < 0xA0) - return 0; + return 2; + } else if (c <= 0xEF) { /* E0..EF */ + /* Disallow overlong 3-byte sequence. */ + if (c == 0xE0 && (unsigned char)*s < 0xA0) return 0; - /* Disallow U+D800..U+DFFF. */ - if (c == 0xED && (unsigned char)*s > 0x9F) - return 0; + /* Disallow U+D800..U+DFFF. */ + if (c == 0xED && (unsigned char)*s > 0x9F) return 0; - /* Make sure subsequent bytes are in the range 0x80..0xBF. */ - if (((unsigned char)*s++ & 0xC0) != 0x80) - return 0; - if (((unsigned char)*s++ & 0xC0) != 0x80) - return 0; + /* Make sure subsequent bytes are in the range 0x80..0xBF. */ + if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; + if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; - return 3; - } else if (c <= 0xF4) { /* F0..F4 */ - /* Disallow overlong 4-byte sequence. */ - if (c == 0xF0 && (unsigned char)*s < 0x90) - return 0; + return 3; + } else if (c <= 0xF4) { /* F0..F4 */ + /* Disallow overlong 4-byte sequence. */ + if (c == 0xF0 && (unsigned char)*s < 0x90) return 0; - /* Disallow codepoints beyond U+10FFFF. */ - if (c == 0xF4 && (unsigned char)*s > 0x8F) - return 0; + /* Disallow codepoints beyond U+10FFFF. */ + if (c == 0xF4 && (unsigned char)*s > 0x8F) return 0; - /* Make sure subsequent bytes are in the range 0x80..0xBF. */ - if (((unsigned char)*s++ & 0xC0) != 0x80) - return 0; - if (((unsigned char)*s++ & 0xC0) != 0x80) - return 0; - if (((unsigned char)*s++ & 0xC0) != 0x80) - return 0; + /* Make sure subsequent bytes are in the range 0x80..0xBF. */ + if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; + if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; + if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; - return 4; - } else { /* F5..FF */ - return 0; - } + return 4; + } else { /* F5..FF */ + return 0; + } } diff --git a/src/client/writer.h b/src/client/writer.h index e15b30e3..650a9757 100644 --- a/src/client/writer.h +++ b/src/client/writer.h @@ -21,19 +21,26 @@ #include struct writer { - void * priv; - void (*start)(struct writer *, const char * tag, const char * descr); - void (*attr)(struct writer *, const char * tag, const char * descr, const char * value); - void (*data)(struct writer *, const char * data); - void (*end)(struct writer *); - void (*finish)(struct writer *); + void *priv; + void (*start)(struct writer *, const char *tag, const char *descr); + void (*attr)(struct writer *, const char *tag, const char *descr, + const char *value); + void (*data)(struct writer *, const char *data); + void (*end)(struct writer *); + void (*finish)(struct writer *); }; -#define tag_start(w,...) w->start(w,## __VA_ARGS__) -#define tag_attr(w,...) w->attr(w,## __VA_ARGS__) -#define tag_data(w,...) w->data(w,## __VA_ARGS__) -#define tag_end(w,...) w->end(w,## __VA_ARGS__) -#define tag_datatag(w,t,d,v) do { if ((v) == NULL) break; w->start(w,t,d); w->data(w,v); w->end(w); } while(0); +#define tag_start(w, ...) w->start(w, ##__VA_ARGS__) +#define tag_attr(w, ...) w->attr(w, ##__VA_ARGS__) +#define tag_data(w, ...) w->data(w, ##__VA_ARGS__) +#define tag_end(w, ...) w->end(w, ##__VA_ARGS__) +#define tag_datatag(w, t, d, v) \ + do { \ + if ((v) == NULL) break; \ + w->start(w, t, d); \ + w->data(w, v); \ + w->end(w); \ + } while (0); extern struct writer *txt_init(FILE *); extern struct writer *kv_init(FILE *); diff --git a/src/client/xml_writer.c b/src/client/xml_writer.c index 15638845..f6a77a16 100644 --- a/src/client/xml_writer.c +++ b/src/client/xml_writer.c @@ -20,13 +20,13 @@ #include #if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdocumentation" +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdocumentation" #endif #include #include #if defined(__clang__) -#pragma clang diagnostic pop +# pragma clang diagnostic pop #endif #include "writer.h" @@ -39,58 +39,70 @@ struct xml_writer_private { xmlDocPtr doc; }; -void xml_new_writer(struct xml_writer_private *priv) +void +xml_new_writer(struct xml_writer_private *priv) { priv->xw = xmlNewTextWriterDoc(&(priv->doc), 0); - if (!priv->xw) - fatalx("lldpctl", "cannot create xml writer"); + if (!priv->xw) fatalx("lldpctl", "cannot create xml writer"); xmlTextWriterSetIndent(priv->xw, 4); - if (xmlTextWriterStartDocument(priv->xw, NULL, "UTF-8", NULL) < 0 ) + if (xmlTextWriterStartDocument(priv->xw, NULL, "UTF-8", NULL) < 0) fatalx("lldpctl", "cannot start xml document"); } -void xml_start(struct writer *w , const char *tag, const char *descr ) { +void +xml_start(struct writer *w, const char *tag, const char *descr) +{ struct xml_writer_private *p = w->priv; - if (p->depth == 0) - xml_new_writer(p); + if (p->depth == 0) xml_new_writer(p); if (xmlTextWriterStartElement(p->xw, BAD_CAST tag) < 0) log_warnx("lldpctl", "cannot start '%s' element", tag); if (descr && (strlen(descr) > 0)) { - if (xmlTextWriterWriteFormatAttribute(p->xw, BAD_CAST "label", "%s", descr) < 0) - log_warnx("lldpctl", "cannot add attribute 'label' to element %s", tag); + if (xmlTextWriterWriteFormatAttribute(p->xw, BAD_CAST "label", "%s", + descr) < 0) + log_warnx("lldpctl", + "cannot add attribute 'label' to element %s", tag); } p->depth++; } -void xml_attr(struct writer *w, const char *tag, const char *descr, const char *value ) { +void +xml_attr(struct writer *w, const char *tag, const char *descr, const char *value) +{ struct xml_writer_private *p = w->priv; - if (xmlTextWriterWriteFormatAttribute(p->xw, BAD_CAST tag, "%s", value?value:"") < 0) - log_warnx("lldpctl", "cannot add attribute %s with value %s", tag, value?value:"(none)"); + if (xmlTextWriterWriteFormatAttribute(p->xw, BAD_CAST tag, "%s", + value ? value : "") < 0) + log_warnx("lldpctl", "cannot add attribute %s with value %s", tag, + value ? value : "(none)"); } -void xml_data(struct writer *w, const char *data) { +void +xml_data(struct writer *w, const char *data) +{ struct xml_writer_private *p = w->priv; - if (xmlTextWriterWriteString(p->xw, BAD_CAST (data?data:"")) < 0 ) - log_warnx("lldpctl", "cannot add '%s' as data to element", data?data:"(none)"); + if (xmlTextWriterWriteString(p->xw, BAD_CAST(data ? data : "")) < 0) + log_warnx("lldpctl", "cannot add '%s' as data to element", + data ? data : "(none)"); } -void xml_end(struct writer *w) { +void +xml_end(struct writer *w) +{ struct xml_writer_private *p = w->priv; - if (xmlTextWriterEndElement(p->xw) < 0 ) + if (xmlTextWriterEndElement(p->xw) < 0) log_warnx("lldpctl", "cannot end element"); if (--p->depth == 0) { int failed = 0; - if (xmlTextWriterEndDocument(p->xw) < 0 ) { + if (xmlTextWriterEndDocument(p->xw) < 0) { log_warnx("lldpctl", "cannot finish document"); failed = 1; } @@ -104,7 +116,9 @@ void xml_end(struct writer *w) { } } -void xml_finish(struct writer *w) { +void +xml_finish(struct writer *w) +{ struct xml_writer_private *p = w->priv; if (p->depth != 0) { log_warnx("lldpctl", "unbalanced tags"); @@ -115,7 +129,9 @@ void xml_finish(struct writer *w) { free(w); } -struct writer *xml_init(FILE *fh) { +struct writer * +xml_init(FILE *fh) +{ struct writer *result; struct xml_writer_private *priv; @@ -129,15 +145,14 @@ struct writer *xml_init(FILE *fh) { priv->depth = 0; result = malloc(sizeof(struct writer)); - if (!result) - fatalx("lldpctl", "out of memory"); + if (!result) fatalx("lldpctl", "out of memory"); - result->priv = priv; + result->priv = priv; result->start = xml_start; - result->attr = xml_attr; - result->data = xml_data; - result->end = xml_end; - result->finish= xml_finish; + result->attr = xml_attr; + result->data = xml_data; + result->end = xml_end; + result->finish = xml_finish; return result; } diff --git a/src/compat/asprintf.c b/src/compat/asprintf.c index 1bc5d7ff..e92e0e91 100644 --- a/src/compat/asprintf.c +++ b/src/compat/asprintf.c @@ -23,9 +23,10 @@ #include #include -#define INIT_SZ 128 +#define INIT_SZ 128 -int vasprintf(char **str, const char *fmt, va_list ap) +int +vasprintf(char **str, const char *fmt, va_list ap) { int ret = -1; va_list ap2; @@ -33,8 +34,7 @@ int vasprintf(char **str, const char *fmt, va_list ap) size_t len; va_copy(ap2, ap); - if ((string = malloc(INIT_SZ)) == NULL) - goto fail; + if ((string = malloc(INIT_SZ)) == NULL) goto fail; ret = vsnprintf(string, INIT_SZ, fmt, ap2); if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */ @@ -42,7 +42,7 @@ int vasprintf(char **str, const char *fmt, va_list ap) } else if (ret == INT_MAX || ret < 0) { /* Bad length */ free(string); goto fail; - } else { /* bigger than initial, realloc allowing for nul */ + } else { /* bigger than initial, realloc allowing for nul */ len = (size_t)ret + 1; if ((newstr = realloc(string, len)) == NULL) { free(string); @@ -69,7 +69,8 @@ fail: return (-1); } -int asprintf(char **str, const char *fmt, ...) +int +asprintf(char **str, const char *fmt, ...) { va_list ap; int ret; diff --git a/src/compat/compat.h b/src/compat/compat.h index 3994265f..91ff4ade 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -46,12 +46,12 @@ #undef getopt #if !HAVE_ASPRINTF -int vasprintf(char **, const char *, va_list) __attribute__ ((format (printf, 2, 0))); -int asprintf (char **, const char *, ...) __attribute__ ((format (printf, 2, 3))); +int vasprintf(char **, const char *, va_list) __attribute__((format(printf, 2, 0))); +int asprintf(char **, const char *, ...) __attribute__((format(printf, 2, 3))); #endif #if !HAVE_VSYSLOG -void vsyslog(int, const char *, va_list) __attribute__ ((format (printf, 2, 0))); +void vsyslog(int, const char *, va_list) __attribute__((format(printf, 2, 0))); #endif #if !HAVE_DAEMON @@ -59,15 +59,15 @@ int daemon(int, int); #endif #if !HAVE_STRLCPY -size_t strlcpy(char *, const char *, size_t); +size_t strlcpy(char *, const char *, size_t); #endif #if !HAVE_STRNLEN -size_t strnlen(const char *, size_t); +size_t strnlen(const char *, size_t); #endif #if !HAVE_STRNDUP -char *strndup(const char *, size_t); +char *strndup(const char *, size_t); #endif #if !HAVE_STRTONUM @@ -79,7 +79,7 @@ ssize_t getline(char **, size_t *, FILE *); #endif #if !HAVE_SETPROCTITLE -void setproctitle(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); +void setproctitle(const char *fmt, ...) __attribute__((format(printf, 1, 2))); #endif #if !HAVE_MALLOC diff --git a/src/compat/daemon.c b/src/compat/daemon.c index cf7f81d5..4452fd96 100644 --- a/src/compat/daemon.c +++ b/src/compat/daemon.c @@ -49,11 +49,9 @@ daemon(int nochdir, int noclose) _exit(0); } - if (setsid() == -1) - return (-1); + if (setsid() == -1) return (-1); - if (!nochdir) - (void)chdir("/"); + if (!nochdir) (void)chdir("/"); /* coverity[resource_leak] fd may be leaked if < 2, it's expected */ @@ -61,8 +59,7 @@ daemon(int nochdir, int noclose) (void)dup2(fd, STDIN_FILENO); (void)dup2(fd, STDOUT_FILENO); (void)dup2(fd, STDERR_FILENO); - if (fd > 2) - (void)close (fd); + if (fd > 2) (void)close(fd); } return (0); } diff --git a/src/compat/getline.c b/src/compat/getline.c index 2e11f23b..beb2d7df 100644 --- a/src/compat/getline.c +++ b/src/compat/getline.c @@ -26,7 +26,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* Several modifications to make the code more portable (and less robust and far less efficient) */ +/* Several modifications to make the code more portable (and less robust and far less + * efficient) */ #include #include @@ -39,8 +40,7 @@ #define MINBUF 128 static ssize_t -___getdelim(char **buf, size_t *buflen, - int sep, FILE *fp) +___getdelim(char **buf, size_t *buflen, int sep, FILE *fp) { int p; size_t len = 0, newlen; @@ -52,15 +52,12 @@ ___getdelim(char **buf, size_t *buflen, } /* If buf is NULL, we have to assume a size of zero */ - if (*buf == NULL) - *buflen = 0; + if (*buf == NULL) *buflen = 0; do { p = fgetc(fp); - if (ferror(fp)) - return -1; - if (p == EOF) - break; + if (ferror(fp)) return -1; + if (p == EOF) break; /* Ensure we can handle it */ if (len > SSIZE_MAX) { @@ -69,9 +66,8 @@ ___getdelim(char **buf, size_t *buflen, } newlen = len + 2; /* reserve space for NUL terminator */ if (newlen > *buflen) { - if (newlen < MINBUF) - newlen = MINBUF; -#define powerof2(x) ((((x)-1)&(x))==0) + if (newlen < MINBUF) newlen = MINBUF; +#define powerof2(x) ((((x)-1) & (x)) == 0) if (!powerof2(newlen)) { /* Grow the buffer to the next power of 2 */ newlen--; @@ -87,8 +83,7 @@ ___getdelim(char **buf, size_t *buflen, } newb = realloc(*buf, newlen); - if (newb == NULL) - return -1; + if (newb == NULL) return -1; *buf = newb; *buflen = newlen; } @@ -97,11 +92,9 @@ ___getdelim(char **buf, size_t *buflen, } while (p != sep); /* POSIX demands we return -1 on EOF. */ - if (len == 0) - return -1; + if (len == 0) return -1; - if (*buf != NULL) - (*buf)[len] = '\0'; + if (*buf != NULL) (*buf)[len] = '\0'; return (ssize_t)len; } diff --git a/src/compat/malloc.c b/src/compat/malloc.c index 5b97294d..7930282b 100644 --- a/src/compat/malloc.c +++ b/src/compat/malloc.c @@ -11,5 +11,5 @@ void * rpl_malloc(size_t n) { if (n == 0) n = 1; - return malloc (n); + return malloc(n); } diff --git a/src/compat/strlcpy.c b/src/compat/strlcpy.c index f5f135af..669b90e1 100644 --- a/src/compat/strlcpy.c +++ b/src/compat/strlcpy.c @@ -35,18 +35,16 @@ strlcpy(char *dst, const char *src, size_t siz) /* Copy as many bytes as will fit */ if (n != 0) { while (--n != 0) { - if ((*d++ = *s++) == '\0') - break; + if ((*d++ = *s++) == '\0') break; } } /* Not enough room in dst, add NUL and traverse rest of src */ if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ + if (siz != 0) *d = '\0'; /* NUL-terminate dst */ while (*s++) ; } - return(s - src - 1); /* count does not include NUL */ + return (s - src - 1); /* count does not include NUL */ } diff --git a/src/compat/strndup.c b/src/compat/strndup.c index 9b57d4b7..bc5b8213 100644 --- a/src/compat/strndup.c +++ b/src/compat/strndup.c @@ -6,13 +6,13 @@ /* * Similar to `strdup()` but copies at most n bytes. */ -char* +char * strndup(const char *string, size_t maxlen) { char *result; /* We may use `strnlen()` but it may be unavailable. */ const char *end = memchr(string, '\0', maxlen); - size_t len = end?(size_t)(end - string):maxlen; + size_t len = end ? (size_t)(end - string) : maxlen; result = malloc(len + 1); if (!result) return 0; diff --git a/src/compat/strnlen.c b/src/compat/strnlen.c index 8bc3525c..9da0fe57 100644 --- a/src/compat/strnlen.c +++ b/src/compat/strnlen.c @@ -10,5 +10,5 @@ size_t strnlen(const char *string, size_t maxlen) { const char *end = memchr(string, '\0', maxlen); - return end?(size_t)(end - string):maxlen; + return end ? (size_t)(end - string) : maxlen; } diff --git a/src/compat/strtonum.c b/src/compat/strtonum.c index 547f39af..78aa8051 100644 --- a/src/compat/strtonum.c +++ b/src/compat/strtonum.c @@ -23,13 +23,12 @@ #include #include -#define INVALID 1 -#define TOOSMALL 2 -#define TOOLARGE 3 +#define INVALID 1 +#define TOOSMALL 2 +#define TOOLARGE 3 long long -strtonum(const char *numstr, long long minval, long long maxval, - const char **errstrp) +strtonum(const char *numstr, long long minval, long long maxval, const char **errstrp) { long long ll = 0; int error = 0; @@ -38,10 +37,10 @@ strtonum(const char *numstr, long long minval, long long maxval, const char *errstr; int err; } ev[4] = { - { NULL, 0 }, - { "invalid", EINVAL }, - { "too small", ERANGE }, - { "too large", ERANGE }, + { NULL, 0 }, + { "invalid", EINVAL }, + { "too small", ERANGE }, + { "too large", ERANGE }, }; ev[0].err = errno; @@ -57,11 +56,9 @@ strtonum(const char *numstr, long long minval, long long maxval, else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) error = TOOLARGE; } - if (errstrp != NULL) - *errstrp = ev[error].errstr; + if (errstrp != NULL) *errstrp = ev[error].errstr; errno = ev[error].err; - if (error) - ll = 0; + if (error) ll = 0; return (ll); } diff --git a/src/compat/vsyslog.c b/src/compat/vsyslog.c index be59210a..a3209cb2 100644 --- a/src/compat/vsyslog.c +++ b/src/compat/vsyslog.c @@ -6,7 +6,8 @@ /* vsyslog() doesn't exist on HP-UX */ void -vsyslog(int facility, const char *format, va_list ap) { +vsyslog(int facility, const char *format, va_list ap) +{ char *msg = NULL; if (vasprintf(&msg, format, ap) == -1) { return; diff --git a/src/ctl.c b/src/ctl.c index a347908e..f9473a26 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -44,8 +44,7 @@ ctl_create(const char *name) log_debug("control", "create control socket %s", name); - if ((s = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) - return -1; + if ((s = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) return -1; if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1) { close(s); return -1; @@ -53,13 +52,17 @@ ctl_create(const char *name) su.sun_family = AF_UNIX; strlcpy(su.sun_path, name, sizeof(su.sun_path)); if (bind(s, (struct sockaddr *)&su, sizeof(struct sockaddr_un)) == -1) { - rc = errno; close(s); errno = rc; + rc = errno; + close(s); + errno = rc; return -1; } log_debug("control", "listen to control socket %s", name); if (listen(s, 5) == -1) { - rc = errno; close(s); errno = rc; + rc = errno; + close(s); + errno = rc; log_debug("control", "cannot listen to control socket %s", name); return -1; } @@ -81,15 +84,15 @@ ctl_connect(const char *name) log_debug("control", "connect to control socket %s", name); - if ((s = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) - return -1; + if ((s = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) return -1; su.sun_family = AF_UNIX; strlcpy(su.sun_path, name, sizeof(su.sun_path)); if (connect(s, (struct sockaddr *)&su, sizeof(struct sockaddr_un)) == -1) { rc = errno; log_warn("control", "unable to connect to socket %s", name); close(s); - errno = rc; return -1; + errno = rc; + return -1; } return s; } @@ -103,8 +106,7 @@ void ctl_cleanup(const char *name) { log_debug("control", "cleanup control socket"); - if (unlink(name) == -1) - log_warn("control", "unable to unlink %s", name); + if (unlink(name) == -1) log_warn("control", "unable to unlink %s", name); } /** @@ -126,8 +128,7 @@ ctl_cleanup(const char *name) */ int ctl_msg_send_unserialized(uint8_t **output_buffer, size_t *output_len, - enum hmsg_type type, - void *t, struct marshal_info *mi) + enum hmsg_type type, void *t, struct marshal_info *mi) { ssize_t len = 0, newlen; void *buffer = NULL; @@ -166,7 +167,8 @@ ctl_msg_send_unserialized(uint8_t **output_buffer, size_t *output_len, hdr.len = len; memcpy(*output_buffer + *output_len, &hdr, sizeof(struct hmsg_header)); if (t) - memcpy(*output_buffer + *output_len + sizeof(struct hmsg_header), buffer, len); + memcpy(*output_buffer + *output_len + sizeof(struct hmsg_header), + buffer, len); *output_len += newlen; free(buffer); return 0; @@ -200,14 +202,12 @@ ctl_msg_send_unserialized(uint8_t **output_buffer, size_t *output_len, */ size_t ctl_msg_recv_unserialized(uint8_t **input_buffer, size_t *input_len, - enum hmsg_type expected_type, - void **t, struct marshal_info *mi) + enum hmsg_type expected_type, void **t, struct marshal_info *mi) { struct hmsg_header hdr; int rc = -1; - if (*input_buffer == NULL || - *input_len < sizeof(struct hmsg_header)) { + if (*input_buffer == NULL || *input_len < sizeof(struct hmsg_header)) { /* Not enough data. */ return sizeof(struct hmsg_header) - *input_len; } @@ -228,7 +228,8 @@ ctl_msg_recv_unserialized(uint8_t **input_buffer, size_t *input_len, } if (hdr.type != expected_type) { if (expected_type == NOTIFICATION) return -1; - log_warnx("control", "incorrect received message type (expected: %d, received: %d)", + log_warnx("control", + "incorrect received message type (expected: %d, received: %d)", expected_type, hdr.type); goto end; } @@ -255,7 +256,6 @@ end: *input_buffer = NULL; } else memmove(*input_buffer, - *input_buffer + sizeof(struct hmsg_header) + hdr.len, - *input_len); + *input_buffer + sizeof(struct hmsg_header) + hdr.len, *input_len); return rc; } diff --git a/src/ctl.h b/src/ctl.h index 7cb4ced9..7e5b076c 100644 --- a/src/ctl.h +++ b/src/ctl.h @@ -27,16 +27,16 @@ enum hmsg_type { NONE, - GET_CONFIG, /* Get global configuration */ - SET_CONFIG, /* Change global configuration */ - GET_INTERFACES, /* Get list of interfaces */ - SET_CHASSIS, /* Set local chassis */ - GET_CHASSIS, /* Get local chassis */ - GET_INTERFACE, /* Get all information related to an interface */ - GET_DEFAULT_PORT, /* Get all information related to default port */ - SET_PORT, /* Set port-related information (location, power, policy) */ - SUBSCRIBE, /* Subscribe to neighbor changes */ - NOTIFICATION, /* Notification message (sent by lldpd!) */ + GET_CONFIG, /* Get global configuration */ + SET_CONFIG, /* Change global configuration */ + GET_INTERFACES, /* Get list of interfaces */ + SET_CHASSIS, /* Set local chassis */ + GET_CHASSIS, /* Get local chassis */ + GET_INTERFACE, /* Get all information related to an interface */ + GET_DEFAULT_PORT, /* Get all information related to default port */ + SET_PORT, /* Set port-related information (location, power, policy) */ + SUBSCRIBE, /* Subscribe to neighbor changes */ + NOTIFICATION, /* Notification message (sent by lldpd!) */ }; /** Header for the control protocol. @@ -47,20 +47,18 @@ enum hmsg_type { */ struct hmsg_header { enum hmsg_type type; - size_t len; + size_t len; }; -#define HMSG_MAX_SIZE (1<<19) +#define HMSG_MAX_SIZE (1 << 19) /* ctl.c */ -int ctl_create(const char *); -int ctl_connect(const char *); -void ctl_cleanup(const char *); +int ctl_create(const char *); +int ctl_connect(const char *); +void ctl_cleanup(const char *); -int ctl_msg_send_unserialized(uint8_t **, size_t *, - enum hmsg_type, - void *, struct marshal_info *); -size_t ctl_msg_recv_unserialized(uint8_t **, size_t *, - enum hmsg_type, - void **, struct marshal_info *); +int ctl_msg_send_unserialized(uint8_t **, size_t *, enum hmsg_type, void *, + struct marshal_info *); +size_t ctl_msg_recv_unserialized(uint8_t **, size_t *, enum hmsg_type, void **, + struct marshal_info *); #endif diff --git a/src/daemon/agent.c b/src/daemon/agent.c index 2fd1a4a9..fa10ebfe 100644 --- a/src/daemon/agent.c +++ b/src/daemon/agent.c @@ -22,11 +22,10 @@ #include "agent.h" #if HAVE_NET_SNMP_AGENT_UTIL_FUNCS_H -#include +# include #else /* The above header may be buggy. We just need this function. */ -int header_generic(struct variable *, oid *, size_t *, int, - size_t *, WriteMethod **); +int header_generic(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **); #endif /* For net-snmp */ @@ -41,11 +40,11 @@ struct lldpd *agent_scfg; static uint8_t swap_bits(uint8_t n) { - n = ((n&0xF0) >>4 ) | ( (n&0x0F) <<4); - n = ((n&0xCC) >>2 ) | ( (n&0x33) <<2); - n = ((n&0xAA) >>1 ) | ( (n&0x55) <<1); + n = ((n & 0xF0) >> 4) | ((n & 0x0F) << 4); + n = ((n & 0xCC) >> 2) | ((n & 0x33) << 2); + n = ((n & 0xAA) >> 1) | ((n & 0x55) << 1); - return n; + return n; }; extern struct timeval starttime; @@ -53,7 +52,7 @@ static long int lastchange(struct lldpd_port *port) { if (port->p_lastchange > starttime.tv_sec) - return (port->p_lastchange - starttime.tv_sec)*100; + return (port->p_lastchange - starttime.tv_sec) * 100; return 0; } @@ -63,25 +62,25 @@ lastchange(struct lldpd_port *port) */ struct header_index { struct variable *vp; - oid *name; /* Requested/returned OID */ - size_t *length; /* Length of above OID */ - int exact; - oid best[MAX_OID_LEN]; /* Best OID */ - size_t best_len; /* Best OID length */ - void *entity; /* Best entity */ + oid *name; /* Requested/returned OID */ + size_t *length; /* Length of above OID */ + int exact; + oid best[MAX_OID_LEN]; /* Best OID */ + size_t best_len; /* Best OID length */ + void *entity; /* Best entity */ }; static struct header_index header_idx; static int -header_index_init(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +header_index_init(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { /* If the requested OID name is less than OID prefix we handle, adjust it to our prefix. */ - if ((snmp_oid_compare(name, *length, vp->name, vp->namelen)) < 0) { - memcpy(name, vp->name, sizeof(oid) * vp->namelen); - *length = vp->namelen; - } + if ((snmp_oid_compare(name, *length, vp->name, vp->namelen)) < 0) { + memcpy(name, vp->name, sizeof(oid) * vp->namelen); + *length = vp->namelen; + } /* Now, we can only handle OID matching our prefix. Those two tests are not really necessary since NetSNMP won't give us OID "above" our prefix. But this makes unit tests @@ -89,7 +88,7 @@ header_index_init(struct variable *vp, oid *name, size_t *length, if (*length < vp->namelen) return 0; if (memcmp(name, vp->name, vp->namelen * sizeof(oid))) return 0; - if(write_method != NULL) *write_method = 0; + if (write_method != NULL) *write_method = 0; *var_len = sizeof(long); /* Initialize our header index structure */ @@ -105,59 +104,53 @@ header_index_init(struct variable *vp, oid *name, size_t *length, static int header_index_add(oid *index, size_t len, void *entity) { - int result; - oid *target; - size_t target_len; + int result; + oid *target; + size_t target_len; - target = header_idx.name + header_idx.vp->namelen; - target_len = *header_idx.length - header_idx.vp->namelen; + target = header_idx.name + header_idx.vp->namelen; + target_len = *header_idx.length - header_idx.vp->namelen; if ((result = snmp_oid_compare(index, len, target, target_len)) < 0) - return 0; /* Too small. */ - if (result == 0) - return header_idx.exact; + return 0; /* Too small. */ + if (result == 0) return header_idx.exact; if (header_idx.best_len == 0 || - (snmp_oid_compare(index, len, - header_idx.best, - header_idx.best_len) < 0)) { + (snmp_oid_compare(index, len, header_idx.best, header_idx.best_len) < 0)) { memcpy(header_idx.best, index, sizeof(oid) * len); header_idx.best_len = len; header_idx.entity = entity; } - return 0; /* No best match yet. */ + return 0; /* No best match yet. */ } -void* +void * header_index_best() { - if (header_idx.entity == NULL) - return NULL; - if (header_idx.exact) - return NULL; - memcpy(header_idx.name + header_idx.vp->namelen, - header_idx.best, sizeof(oid) * header_idx.best_len); + if (header_idx.entity == NULL) return NULL; + if (header_idx.exact) return NULL; + memcpy(header_idx.name + header_idx.vp->namelen, header_idx.best, + sizeof(oid) * header_idx.best_len); *header_idx.length = header_idx.vp->namelen + header_idx.best_len; return header_idx.entity; } /* ----------------------------- */ -static struct lldpd_hardware* -header_portindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static struct lldpd_hardware * +header_portindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_hardware *hardware; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { oid index[1] = { hardware->h_ifindex }; - if (header_index_add(index, 1, - hardware)) - return hardware; + if (header_index_add(index, 1, hardware)) return hardware; } return header_index_best(); } #ifdef ENABLE_LLDPMED -static struct lldpd_med_policy* +static struct lldpd_med_policy * header_pmedindexed_policy_table(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { @@ -165,22 +158,22 @@ header_pmedindexed_policy_table(struct variable *vp, oid *name, size_t *length, int i; oid index[2]; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { for (i = 0; i < LLDP_MED_APPTYPE_LAST; i++) { - if (hardware->h_lport.p_med_policy[i].type != i+1) - continue; + if (hardware->h_lport.p_med_policy[i].type != i + 1) continue; index[0] = hardware->h_ifindex; index[1] = i + 1; if (header_index_add(index, 2, - &hardware->h_lport.p_med_policy[i])) + &hardware->h_lport.p_med_policy[i])) return &hardware->h_lport.p_med_policy[i]; } } return header_index_best(); } -static struct lldpd_med_loc* +static struct lldpd_med_loc * header_pmedindexed_location_table(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { @@ -188,15 +181,16 @@ header_pmedindexed_location_table(struct variable *vp, oid *name, size_t *length int i; oid index[2]; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { for (i = 0; i < LLDP_MED_LOCFORMAT_LAST; i++) { - if (hardware->h_lport.p_med_location[i].format != i+1) + if (hardware->h_lport.p_med_location[i].format != i + 1) continue; index[0] = hardware->h_ifindex; index[1] = i + 2; if (header_index_add(index, 2, - &hardware->h_lport.p_med_location[i])) + &hardware->h_lport.p_med_location[i])) return &hardware->h_lport.p_med_location[i]; } } @@ -204,18 +198,18 @@ header_pmedindexed_location_table(struct variable *vp, oid *name, size_t *length } #endif -static struct lldpd_port* -header_tprindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method, - int withmed) +static struct lldpd_port * +header_tprindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method, int withmed) { struct lldpd_hardware *hardware; struct lldpd_port *port; oid index[3]; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (SMART_HIDDEN(port)) continue; #ifdef ENABLE_LLDPMED if (withmed && !port->p_chassis->c_med_cap_available) continue; @@ -223,68 +217,75 @@ header_tprindexed_table(struct variable *vp, oid *name, size_t *length, index[0] = lastchange(port); index[1] = hardware->h_ifindex; index[2] = port->p_chassis->c_index; - if (header_index_add(index, 3, - port)) - return port; + if (header_index_add(index, 3, port)) return port; } } return header_index_best(); } -static struct lldpd_mgmt* -header_ipindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static struct lldpd_mgmt * +header_ipindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_chassis *chassis = LOCAL_CHASSIS(scfg); struct lldpd_mgmt *mgmt; oid index[2 + 16]; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(mgmt, &chassis->c_mgmt, m_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (mgmt, &chassis->c_mgmt, m_entries) { int i; switch (mgmt->m_family) { - case LLDPD_AF_IPV4: index[0] = 1; break; - case LLDPD_AF_IPV6: index[0] = 2; break; - default: assert(0); + case LLDPD_AF_IPV4: + index[0] = 1; + break; + case LLDPD_AF_IPV6: + index[0] = 2; + break; + default: + assert(0); } index[1] = mgmt->m_addrsize; - if (index[1] > sizeof(index) - 2) - continue; /* Odd... */ + if (index[1] > sizeof(index) - 2) continue; /* Odd... */ for (i = 0; i < index[1]; i++) index[i + 2] = mgmt->m_addr.octets[i]; - if (header_index_add(index, 2 + index[1], mgmt)) - return mgmt; + if (header_index_add(index, 2 + index[1], mgmt)) return mgmt; } return header_index_best(); } -static struct lldpd_mgmt* -header_tpripindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static struct lldpd_mgmt * +header_tpripindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_hardware *hardware; struct lldpd_port *port; struct lldpd_mgmt *mgmt; oid index[5 + 16]; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (SMART_HIDDEN(port)) continue; - TAILQ_FOREACH(mgmt, &port->p_chassis->c_mgmt, m_entries) { + TAILQ_FOREACH (mgmt, &port->p_chassis->c_mgmt, m_entries) { int i; index[0] = lastchange(port); index[1] = hardware->h_ifindex; index[2] = port->p_chassis->c_index; switch (mgmt->m_family) { - case LLDPD_AF_IPV4: index[3] = 1; break; - case LLDPD_AF_IPV6: index[3] = 2; break; - default: assert(0); + case LLDPD_AF_IPV4: + index[3] = 1; + break; + case LLDPD_AF_IPV6: + index[3] = 2; + break; + default: + assert(0); } index[4] = mgmt->m_addrsize; - if (index[4] > sizeof(index) - 5) - continue; /* Odd... */ + if (index[4] > sizeof(index) - 5) continue; /* Odd... */ for (i = 0; i < index[4]; i++) index[i + 5] = mgmt->m_addr.octets[i]; if (header_index_add(index, 5 + index[4], mgmt)) @@ -296,9 +297,9 @@ header_tpripindexed_table(struct variable *vp, oid *name, size_t *length, } #ifdef ENABLE_CUSTOM -static struct lldpd_custom* -header_tprcustomindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static struct lldpd_custom * +header_tprcustomindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_hardware *hardware; struct lldpd_port *port; @@ -306,12 +307,13 @@ header_tprcustomindexed_table(struct variable *vp, oid *name, size_t *length, oid index[8]; oid idx; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (SMART_HIDDEN(port)) continue; idx = 1; - TAILQ_FOREACH(custom, &port->p_custom_list, next) { + TAILQ_FOREACH (custom, &port->p_custom_list, next) { index[0] = lastchange(port); index[1] = hardware->h_ifindex; index[2] = port->p_chassis->c_index; @@ -320,8 +322,7 @@ header_tprcustomindexed_table(struct variable *vp, oid *name, size_t *length, index[5] = custom->oui[2]; index[6] = custom->subtype; index[7] = idx++; - if (header_index_add(index, 8, custom)) - return custom; + if (header_index_add(index, 8, custom)) return custom; } } } @@ -330,50 +331,47 @@ header_tprcustomindexed_table(struct variable *vp, oid *name, size_t *length, #endif #ifdef ENABLE_LLDPMED -#define TPR_VARIANT_MED_POLICY 2 -#define TPR_VARIANT_MED_LOCATION 3 -static void* -header_tprmedindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method, int variant) +# define TPR_VARIANT_MED_POLICY 2 +# define TPR_VARIANT_MED_LOCATION 3 +static void * +header_tprmedindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method, int variant) { struct lldpd_hardware *hardware; struct lldpd_port *port; int j; oid index[4]; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (SMART_HIDDEN(port)) continue; if (!port->p_chassis->c_med_cap_available) continue; switch (variant) { case TPR_VARIANT_MED_POLICY: - for (j = 0; - j < LLDP_MED_APPTYPE_LAST; - j++) { - if (port->p_med_policy[j].type != j+1) + for (j = 0; j < LLDP_MED_APPTYPE_LAST; j++) { + if (port->p_med_policy[j].type != j + 1) continue; index[0] = lastchange(port); index[1] = hardware->h_ifindex; index[2] = port->p_chassis->c_index; - index[3] = j+1; + index[3] = j + 1; if (header_index_add(index, 4, - &port->p_med_policy[j])) + &port->p_med_policy[j])) return &port->p_med_policy[j]; } break; case TPR_VARIANT_MED_LOCATION: - for (j = 0; - j < LLDP_MED_LOCFORMAT_LAST; - j++) { - if (port->p_med_location[j].format != j+1) + for (j = 0; j < LLDP_MED_LOCFORMAT_LAST; j++) { + if (port->p_med_location[j].format != j + 1) continue; index[0] = lastchange(port); index[1] = hardware->h_ifindex; index[2] = port->p_chassis->c_index; - index[3] = j+2; + index[3] = j + 2; if (header_index_add(index, 4, - &port->p_med_location[j])) + &port->p_med_location[j])) return &port->p_med_location[j]; } break; @@ -385,140 +383,128 @@ header_tprmedindexed_table(struct variable *vp, oid *name, size_t *length, #endif #ifdef ENABLE_DOT1 -static struct lldpd_vlan* -header_pvindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static struct lldpd_vlan * +header_pvindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_hardware *hardware; - struct lldpd_vlan *vlan; + struct lldpd_vlan *vlan; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - TAILQ_FOREACH(vlan, &hardware->h_lport.p_vlans, v_entries) { - oid index[2] = { hardware->h_ifindex, - vlan->v_vid }; - if (header_index_add(index, 2, vlan)) - return vlan; + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + TAILQ_FOREACH (vlan, &hardware->h_lport.p_vlans, v_entries) { + oid index[2] = { hardware->h_ifindex, vlan->v_vid }; + if (header_index_add(index, 2, vlan)) return vlan; } } return header_index_best(); } -static struct lldpd_vlan* -header_tprvindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static struct lldpd_vlan * +header_tprvindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_hardware *hardware; struct lldpd_port *port; - struct lldpd_vlan *vlan; + struct lldpd_vlan *vlan; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (SMART_HIDDEN(port)) continue; - TAILQ_FOREACH(vlan, &port->p_vlans, v_entries) { - oid index[4] = { lastchange(port), - hardware->h_ifindex, - port->p_chassis->c_index, - vlan->v_vid }; - if (header_index_add(index, 4, - vlan)) - return vlan; + TAILQ_FOREACH (vlan, &port->p_vlans, v_entries) { + oid index[4] = { lastchange(port), hardware->h_ifindex, + port->p_chassis->c_index, vlan->v_vid }; + if (header_index_add(index, 4, vlan)) return vlan; } } } return header_index_best(); } -static struct lldpd_ppvid* -header_pppvidindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static struct lldpd_ppvid * +header_pppvidindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_hardware *hardware; - struct lldpd_ppvid *ppvid; + struct lldpd_ppvid *ppvid; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - TAILQ_FOREACH(ppvid, &hardware->h_lport.p_ppvids, p_entries) { - oid index[2] = { hardware->h_ifindex, - ppvid->p_ppvid }; - if (header_index_add(index, 2, - ppvid)) - return ppvid; + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + TAILQ_FOREACH (ppvid, &hardware->h_lport.p_ppvids, p_entries) { + oid index[2] = { hardware->h_ifindex, ppvid->p_ppvid }; + if (header_index_add(index, 2, ppvid)) return ppvid; } } return header_index_best(); } -static struct lldpd_ppvid* -header_tprppvidindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static struct lldpd_ppvid * +header_tprppvidindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_hardware *hardware; struct lldpd_port *port; - struct lldpd_ppvid *ppvid; + struct lldpd_ppvid *ppvid; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (SMART_HIDDEN(port)) continue; - TAILQ_FOREACH(ppvid, &port->p_ppvids, p_entries) { - oid index[4] = { lastchange(port), - hardware->h_ifindex, - port->p_chassis->c_index, - ppvid->p_ppvid }; - if (header_index_add(index, 4, - ppvid)) - return ppvid; - } + TAILQ_FOREACH (ppvid, &port->p_ppvids, p_entries) { + oid index[4] = { lastchange(port), hardware->h_ifindex, + port->p_chassis->c_index, ppvid->p_ppvid }; + if (header_index_add(index, 4, ppvid)) return ppvid; + } } } return header_index_best(); } -static struct lldpd_pi* -header_ppiindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static struct lldpd_pi * +header_ppiindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_hardware *hardware; - struct lldpd_pi *pi; + struct lldpd_pi *pi; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - TAILQ_FOREACH(pi, &hardware->h_lport.p_pids, p_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + TAILQ_FOREACH (pi, &hardware->h_lport.p_pids, p_entries) { oid index[2] = { hardware->h_ifindex, - frame_checksum((const u_char*)pi->p_pi, - pi->p_pi_len, 0) }; - if (header_index_add(index, 2, - pi)) - return pi; + frame_checksum((const u_char *)pi->p_pi, pi->p_pi_len, + 0) }; + if (header_index_add(index, 2, pi)) return pi; } } return header_index_best(); } -static struct lldpd_pi* -header_tprpiindexed_table(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static struct lldpd_pi * +header_tprpiindexed_table(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_hardware *hardware; struct lldpd_port *port; - struct lldpd_pi *pi; + struct lldpd_pi *pi; - if (!header_index_init(vp, name, length, exact, var_len, write_method)) return NULL; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + if (!header_index_init(vp, name, length, exact, var_len, write_method)) + return NULL; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (SMART_HIDDEN(port)) continue; - TAILQ_FOREACH(pi, &port->p_pids, p_entries) { - oid index[4] = { lastchange(port), - hardware->h_ifindex, - port->p_chassis->c_index, - frame_checksum((const u_char *)pi->p_pi, - pi->p_pi_len, 0) }; - if (header_index_add(index, 4, - pi)) - return pi; - } + TAILQ_FOREACH (pi, &port->p_pids, p_entries) { + oid index[4] = { lastchange(port), hardware->h_ifindex, + port->p_chassis->c_index, + frame_checksum((const u_char *)pi->p_pi, + pi->p_pi_len, 0) }; + if (header_index_add(index, 4, pi)) return pi; + } } } return header_index_best(); @@ -577,10 +563,10 @@ header_tprpiindexed_table(struct variable *vp, oid *name, size_t *length, /* Vlans */ #define LLDP_SNMP_DOT1_VLANNAME 1 /* Protocol VLAN IDs */ -#define LLDP_SNMP_DOT1_PPVLAN_SUPPORTED 2 -#define LLDP_SNMP_DOT1_PPVLAN_ENABLED 3 +#define LLDP_SNMP_DOT1_PPVLAN_SUPPORTED 2 +#define LLDP_SNMP_DOT1_PPVLAN_ENABLED 3 /* Protocol Identity */ -#define LLDP_SNMP_DOT1_PI 1 +#define LLDP_SNMP_DOT1_PI 1 /* Management address */ #define LLDP_SNMP_ADDR_LEN 1 #define LLDP_SNMP_ADDR_IFSUBTYPE 2 @@ -617,29 +603,26 @@ header_tprpiindexed_table(struct variable *vp, oid *name, size_t *length, is finally not returned (for example, when the associated data is not available). In this case, we retry the function with the next OID. */ -#define TRYNEXT(X) \ - do { \ - if (!exact && (name[*length-1] < MAX_SUBID)) \ - return X(vp, name, length, \ - exact, var_len, write_method); \ - return NULL; \ - } while (0) - - -static u_char* -agent_h_scalars(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +#define TRYNEXT(X) \ + do { \ + if (!exact && (name[*length - 1] < MAX_SUBID)) \ + return X(vp, name, length, exact, var_len, write_method); \ + return NULL; \ + } while (0) + +static u_char * +agent_h_scalars(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { static unsigned long long_ret; struct lldpd_hardware *hardware; struct lldpd_port *port; - if (header_generic(vp, name, length, exact, var_len, write_method)) - return NULL; + if (header_generic(vp, name, length, exact, var_len, write_method)) return NULL; switch (vp->magic) { case LLDP_SNMP_TXINTERVAL: - long_ret = (scfg->g_config.c_tx_interval+999) / 1000; + long_ret = (scfg->g_config.c_tx_interval + 999) / 1000; return (u_char *)&long_ret; case LLDP_SNMP_TXMULTIPLIER: long_ret = scfg->g_config.c_tx_hold; @@ -655,40 +638,41 @@ agent_h_scalars(struct variable *vp, oid *name, size_t *length, return (u_char *)&long_ret; case LLDP_SNMP_LASTUPDATE: long_ret = 0; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - /* Check if the last removal of a remote port on this local port was the last change. */ + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + /* Check if the last removal of a remote port on this local port + * was the last change. */ if (hardware->h_lport.p_lastremove > long_ret) long_ret = hardware->h_lport.p_lastremove; - /* Check if any change on the existing remote ports was the last change. */ - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + /* Check if any change on the existing remote ports was the last + * change. */ + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (SMART_HIDDEN(port)) continue; if (port->p_lastchange > long_ret) long_ret = port->p_lastchange; } } - if (long_ret) - long_ret = (long_ret - starttime.tv_sec) * 100; + if (long_ret) long_ret = (long_ret - starttime.tv_sec) * 100; return (u_char *)&long_ret; case LLDP_SNMP_STATS_INSERTS: /* We assume this is equal to valid frames received on all ports */ long_ret = 0; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) - long_ret += hardware->h_insert_cnt; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) + long_ret += hardware->h_insert_cnt; return (u_char *)&long_ret; case LLDP_SNMP_STATS_AGEOUTS: long_ret = 0; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) - long_ret += hardware->h_ageout_cnt; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) + long_ret += hardware->h_ageout_cnt; return (u_char *)&long_ret; case LLDP_SNMP_STATS_DELETES: long_ret = 0; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) - long_ret += hardware->h_delete_cnt; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) + long_ret += hardware->h_delete_cnt; return (u_char *)&long_ret; case LLDP_SNMP_STATS_DROPS: long_ret = 0; - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) - long_ret += hardware->h_drop_cnt; + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) + long_ret += hardware->h_drop_cnt; return (u_char *)&long_ret; default: break; @@ -697,7 +681,7 @@ agent_h_scalars(struct variable *vp, oid *name, size_t *length, } #ifdef ENABLE_LLDPMED -static u_char* +static u_char * agent_v_med_power(struct variable *vp, size_t *var_len, struct lldpd_med_power *power) { static unsigned long long_ret; @@ -706,11 +690,14 @@ agent_v_med_power(struct variable *vp, size_t *var_len, struct lldpd_med_power * case LLDP_SNMP_MED_POE_DEVICETYPE: switch (power->devicetype) { case LLDP_MED_POW_TYPE_PSE: - long_ret = 2; break; + long_ret = 2; + break; case LLDP_MED_POW_TYPE_PD: - long_ret = 3; break; + long_ret = 3; + break; case 0: - long_ret = 4; break; + long_ret = 4; + break; default: long_ret = 1; } @@ -718,23 +705,22 @@ agent_v_med_power(struct variable *vp, size_t *var_len, struct lldpd_med_power * case LLDP_SNMP_MED_POE_PSE_POWERVAL: case LLDP_SNMP_MED_POE_PD_POWERVAL: if (((vp->magic == LLDP_SNMP_MED_POE_PSE_POWERVAL) && - (power->devicetype == - LLDP_MED_POW_TYPE_PSE)) || + (power->devicetype == LLDP_MED_POW_TYPE_PSE)) || ((vp->magic == LLDP_SNMP_MED_POE_PD_POWERVAL) && - (power->devicetype == - LLDP_MED_POW_TYPE_PD))) { + (power->devicetype == LLDP_MED_POW_TYPE_PD))) { long_ret = power->val; return (u_char *)&long_ret; } break; case LLDP_SNMP_MED_POE_PSE_POWERSOURCE: - if (power->devicetype == - LLDP_MED_POW_TYPE_PSE) { + if (power->devicetype == LLDP_MED_POW_TYPE_PSE) { switch (power->source) { case LLDP_MED_POW_SOURCE_PRIMARY: - long_ret = 2; break; + long_ret = 2; + break; case LLDP_MED_POW_SOURCE_BACKUP: - long_ret = 3; break; + long_ret = 3; + break; default: long_ret = 1; } @@ -742,15 +728,17 @@ agent_v_med_power(struct variable *vp, size_t *var_len, struct lldpd_med_power * } break; case LLDP_SNMP_MED_POE_PD_POWERSOURCE: - if (power->devicetype == - LLDP_MED_POW_TYPE_PD) { + if (power->devicetype == LLDP_MED_POW_TYPE_PD) { switch (power->source) { case LLDP_MED_POW_SOURCE_PSE: - long_ret = 2; break; + long_ret = 2; + break; case LLDP_MED_POW_SOURCE_LOCAL: - long_ret = 3; break; + long_ret = 3; + break; case LLDP_MED_POW_SOURCE_BOTH: - long_ret = 4; break; + long_ret = 4; + break; default: long_ret = 1; } @@ -760,18 +748,19 @@ agent_v_med_power(struct variable *vp, size_t *var_len, struct lldpd_med_power * case LLDP_SNMP_MED_POE_PSE_POWERPRIORITY: case LLDP_SNMP_MED_POE_PD_POWERPRIORITY: if (((vp->magic == LLDP_SNMP_MED_POE_PSE_POWERPRIORITY) && - (power->devicetype == - LLDP_MED_POW_TYPE_PSE)) || + (power->devicetype == LLDP_MED_POW_TYPE_PSE)) || ((vp->magic == LLDP_SNMP_MED_POE_PD_POWERPRIORITY) && - (power->devicetype == - LLDP_MED_POW_TYPE_PD))) { + (power->devicetype == LLDP_MED_POW_TYPE_PD))) { switch (power->priority) { case LLDP_MED_POW_PRIO_CRITICAL: - long_ret = 2; break; + long_ret = 2; + break; case LLDP_MED_POW_PRIO_HIGH: - long_ret = 3; break; + long_ret = 3; + break; case LLDP_MED_POW_PRIO_LOW: - long_ret = 4; break; + long_ret = 4; + break; default: long_ret = 1; } @@ -782,32 +771,29 @@ agent_v_med_power(struct variable *vp, size_t *var_len, struct lldpd_med_power * return NULL; } -static u_char* -agent_h_local_med_power(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_local_med_power(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_med_power *power = NULL; - struct lldpd_hardware *hardware; - int pse = 0; + struct lldpd_hardware *hardware; + int pse = 0; - if (!LOCAL_CHASSIS(scfg)->c_med_cap_available) - return NULL; - if (header_generic(vp, name, length, exact, var_len, write_method)) - return NULL; + if (!LOCAL_CHASSIS(scfg)->c_med_cap_available) return NULL; + if (header_generic(vp, name, length, exact, var_len, write_method)) return NULL; /* LLDP-MED requires only one device type for all ports. Moreover, a PSE can only have one power source. At least, all PD values are global and not per-port. We try to do our best. For device type, we decide on the number of PD/PSE ports. */ - TAILQ_FOREACH(hardware, &scfg->g_hardware, h_entries) { - if (hardware->h_lport.p_med_power.devicetype == - LLDP_MED_POW_TYPE_PSE) { + TAILQ_FOREACH (hardware, &scfg->g_hardware, h_entries) { + if (hardware->h_lport.p_med_power.devicetype == LLDP_MED_POW_TYPE_PSE) { pse++; if (pse == 1) /* Take this port as a reference */ power = &hardware->h_lport.p_med_power; } else if (hardware->h_lport.p_med_power.devicetype == - LLDP_MED_POW_TYPE_PD) { + LLDP_MED_POW_TYPE_PD) { pse--; if (pse == -1) /* Take this one instead */ power = &hardware->h_lport.p_med_power; @@ -815,38 +801,35 @@ agent_h_local_med_power(struct variable *vp, oid *name, size_t *length, } if (power) { u_char *a; - if ((a = agent_v_med_power(vp, var_len, power)) != NULL) - return a; + if ((a = agent_v_med_power(vp, var_len, power)) != NULL) return a; } TRYNEXT(agent_h_local_med_power); } -static u_char* -agent_h_remote_med_power(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_med_power(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_port *port; u_char *a; - if ((port = header_tprindexed_table(vp, name, length, - exact, var_len, write_method, 1)) == NULL) + if ((port = header_tprindexed_table(vp, name, length, exact, var_len, + write_method, 1)) == NULL) return NULL; - if ((a = agent_v_med_power(vp, var_len, &port->p_med_power)) != NULL) - return a; + if ((a = agent_v_med_power(vp, var_len, &port->p_med_power)) != NULL) return a; TRYNEXT(agent_h_remote_med_power); } -static u_char* -agent_v_med(struct variable *vp, size_t *var_len, - struct lldpd_chassis *chassis, - struct lldpd_port *port) +static u_char * +agent_v_med(struct variable *vp, size_t *var_len, struct lldpd_chassis *chassis, + struct lldpd_port *port) { - static unsigned long long_ret; + static unsigned long long_ret; static uint8_t bit; switch (vp->magic) { - case LLDP_SNMP_MED_CLASS: - long_ret = chassis->c_med_type; + case LLDP_SNMP_MED_CLASS: + long_ret = chassis->c_med_type; return (u_char *)&long_ret; case LLDP_SNMP_MED_CAP_AVAILABLE: *var_len = 1; @@ -858,77 +841,61 @@ agent_v_med(struct variable *vp, size_t *var_len, bit = swap_bits(port->p_med_cap_enabled); return (u_char *)&bit; -#define LLDP_H_MED(magic, variable) \ - case magic: \ - if (chassis->variable) { \ - *var_len = strlen( \ - chassis->variable); \ - return (u_char *) \ - chassis->variable; \ - } \ - break - - LLDP_H_MED(LLDP_SNMP_MED_HW, - c_med_hw); - LLDP_H_MED(LLDP_SNMP_MED_SW, - c_med_sw); - LLDP_H_MED(LLDP_SNMP_MED_FW, - c_med_fw); - LLDP_H_MED(LLDP_SNMP_MED_SN, - c_med_sn); - LLDP_H_MED(LLDP_SNMP_MED_MANUF, - c_med_manuf); - LLDP_H_MED(LLDP_SNMP_MED_MODEL, - c_med_model); - LLDP_H_MED(LLDP_SNMP_MED_ASSET, - c_med_asset); - - } +# define LLDP_H_MED(magic, variable) \ + case magic: \ + if (chassis->variable) { \ + *var_len = strlen(chassis->variable); \ + return (u_char *)chassis->variable; \ + } \ + break + + LLDP_H_MED(LLDP_SNMP_MED_HW, c_med_hw); + LLDP_H_MED(LLDP_SNMP_MED_SW, c_med_sw); + LLDP_H_MED(LLDP_SNMP_MED_FW, c_med_fw); + LLDP_H_MED(LLDP_SNMP_MED_SN, c_med_sn); + LLDP_H_MED(LLDP_SNMP_MED_MANUF, c_med_manuf); + LLDP_H_MED(LLDP_SNMP_MED_MODEL, c_med_model); + LLDP_H_MED(LLDP_SNMP_MED_ASSET, c_med_asset); + } return NULL; } -static u_char* -agent_h_local_med(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_local_med(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { u_char *a; - if (!LOCAL_CHASSIS(scfg)->c_med_cap_available) - return NULL; - if (header_generic(vp, name, length, exact, var_len, write_method)) - return NULL; + if (!LOCAL_CHASSIS(scfg)->c_med_cap_available) return NULL; + if (header_generic(vp, name, length, exact, var_len, write_method)) return NULL; - if ((a = agent_v_med(vp, var_len, - LOCAL_CHASSIS(scfg), NULL)) != NULL) - return a; + if ((a = agent_v_med(vp, var_len, LOCAL_CHASSIS(scfg), NULL)) != NULL) return a; TRYNEXT(agent_h_local_med); } -static u_char* -agent_h_remote_med(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_med(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_port *port; u_char *a; - if ((port = header_tprindexed_table(vp, name, length, - exact, var_len, write_method, 1)) == NULL) + if ((port = header_tprindexed_table(vp, name, length, exact, var_len, + write_method, 1)) == NULL) return NULL; - if ((a = agent_v_med(vp, var_len, - port->p_chassis, port)) != NULL) - return a; + if ((a = agent_v_med(vp, var_len, port->p_chassis, port)) != NULL) return a; TRYNEXT(agent_h_remote_med); } -static u_char* +static u_char * agent_v_med_policy(struct variable *vp, size_t *var_len, - struct lldpd_med_policy *policy) + struct lldpd_med_policy *policy) { - static unsigned long long_ret; + static unsigned long long_ret; switch (vp->magic) { - case LLDP_SNMP_MED_POLICY_VID: - long_ret = policy->vid; + case LLDP_SNMP_MED_POLICY_VID: + long_ret = policy->vid; return (u_char *)&long_ret; case LLDP_SNMP_MED_POLICY_PRIO: long_ret = policy->priority; @@ -937,88 +904,88 @@ agent_v_med_policy(struct variable *vp, size_t *var_len, long_ret = policy->dscp; return (u_char *)&long_ret; case LLDP_SNMP_MED_POLICY_UNKNOWN: - long_ret = policy->unknown?1:2; + long_ret = policy->unknown ? 1 : 2; return (u_char *)&long_ret; case LLDP_SNMP_MED_POLICY_TAGGED: - long_ret = policy->tagged?1:2; + long_ret = policy->tagged ? 1 : 2; return (u_char *)&long_ret; default: return NULL; - } + } } -static u_char* -agent_h_remote_med_policy(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_med_policy(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_med_policy *policy; - if ((policy = (struct lldpd_med_policy *)header_tprmedindexed_table(vp, name, length, - exact, var_len, write_method, TPR_VARIANT_MED_POLICY)) == NULL) + if ((policy = (struct lldpd_med_policy *)header_tprmedindexed_table(vp, name, + length, exact, var_len, write_method, TPR_VARIANT_MED_POLICY)) == NULL) return NULL; return agent_v_med_policy(vp, var_len, policy); } -static u_char* -agent_h_local_med_policy(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_local_med_policy(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_med_policy *policy; - if ((policy = (struct lldpd_med_policy *)header_pmedindexed_policy_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((policy = (struct lldpd_med_policy *)header_pmedindexed_policy_table(vp, + name, length, exact, var_len, write_method)) == NULL) return NULL; return agent_v_med_policy(vp, var_len, policy); } -static u_char* +static u_char * agent_v_med_location(struct variable *vp, size_t *var_len, - struct lldpd_med_loc *location) + struct lldpd_med_loc *location) { switch (vp->magic) { - case LLDP_SNMP_MED_LOCATION: + case LLDP_SNMP_MED_LOCATION: *var_len = location->data_len; return (u_char *)location->data; default: return NULL; - } + } } -static u_char* -agent_h_remote_med_location(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_med_location(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_med_loc *location; - if ((location = (struct lldpd_med_loc *)header_tprmedindexed_table(vp, name, length, - exact, var_len, write_method, TPR_VARIANT_MED_LOCATION)) == NULL) + if ((location = (struct lldpd_med_loc *)header_tprmedindexed_table(vp, name, + length, exact, var_len, write_method, TPR_VARIANT_MED_LOCATION)) == + NULL) return NULL; return agent_v_med_location(vp, var_len, location); } -static u_char* -agent_h_local_med_location(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_local_med_location(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_med_loc *location; - if ((location = (struct lldpd_med_loc *)header_pmedindexed_location_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((location = (struct lldpd_med_loc *)header_pmedindexed_location_table(vp, + name, length, exact, var_len, write_method)) == NULL) return NULL; return agent_v_med_location(vp, var_len, location); } #endif -static u_char* -agent_v_chassis(struct variable *vp, size_t *var_len, - struct lldpd_chassis *chassis) +static u_char * +agent_v_chassis(struct variable *vp, size_t *var_len, struct lldpd_chassis *chassis) { static uint8_t bit; - static unsigned long long_ret; + static unsigned long long_ret; switch (vp->magic) { case LLDP_SNMP_CIDSUBTYPE: - long_ret = chassis->c_id_subtype; + long_ret = chassis->c_id_subtype; return (u_char *)&long_ret; case LLDP_SNMP_CID: *var_len = chassis->c_id_len; @@ -1041,61 +1008,58 @@ agent_v_chassis(struct variable *vp, size_t *var_len, return (u_char *)&bit; default: break; - } + } return NULL; } -static u_char* -agent_h_local_chassis(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_local_chassis(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { u_char *a; - if (header_generic(vp, name, length, exact, var_len, write_method)) - return NULL; + if (header_generic(vp, name, length, exact, var_len, write_method)) return NULL; - if ((a = agent_v_chassis(vp, var_len, LOCAL_CHASSIS(scfg))) != NULL) - return a; + if ((a = agent_v_chassis(vp, var_len, LOCAL_CHASSIS(scfg))) != NULL) return a; TRYNEXT(agent_h_local_chassis); } -static u_char* -agent_h_remote_chassis(struct variable *vp, oid*name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_chassis(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_port *port; u_char *a; - if ((port = header_tprindexed_table(vp, name, length, - exact, var_len, write_method, 0)) == NULL) + if ((port = header_tprindexed_table(vp, name, length, exact, var_len, + write_method, 0)) == NULL) return NULL; - if ((a = agent_v_chassis(vp, var_len, port->p_chassis)) != NULL) - return a; + if ((a = agent_v_chassis(vp, var_len, port->p_chassis)) != NULL) return a; TRYNEXT(agent_h_remote_chassis); } -static u_char* -agent_h_stats(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_stats(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { static unsigned long long_ret; struct lldpd_hardware *hardware; - if ((hardware = header_portindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((hardware = header_portindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; switch (vp->magic) { case LLDP_SNMP_STATS_TX: - long_ret = hardware->h_tx_cnt; - return (u_char *)&long_ret; + long_ret = hardware->h_tx_cnt; + return (u_char *)&long_ret; case LLDP_SNMP_STATS_RX: - long_ret = hardware->h_rx_cnt; + long_ret = hardware->h_rx_cnt; return (u_char *)&long_ret; case LLDP_SNMP_STATS_RX_DISCARDED: case LLDP_SNMP_STATS_RX_ERRORS: /* We discard only frame with errors. Therefore, the two values * are equal */ - long_ret = hardware->h_rx_discarded_cnt; + long_ret = hardware->h_rx_discarded_cnt; return (u_char *)&long_ret; case LLDP_SNMP_STATS_RX_TLVDISCARDED: case LLDP_SNMP_STATS_RX_TLVUNRECOGNIZED: @@ -1104,15 +1068,15 @@ agent_h_stats(struct variable *vp, oid *name, size_t *length, long_ret = hardware->h_rx_unrecognized_cnt; return (u_char *)&long_ret; case LLDP_SNMP_STATS_RX_AGEOUTS: - long_ret = hardware->h_ageout_cnt; + long_ret = hardware->h_ageout_cnt; return (u_char *)&long_ret; default: return NULL; - } + } } #ifdef ENABLE_DOT1 -static u_char* +static u_char * agent_v_vlan(struct variable *vp, size_t *var_len, struct lldpd_vlan *vlan) { switch (vp->magic) { @@ -1121,76 +1085,76 @@ agent_v_vlan(struct variable *vp, size_t *var_len, struct lldpd_vlan *vlan) return (u_char *)vlan->v_name; default: return NULL; - } + } } -static u_char* -agent_h_local_vlan(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_local_vlan(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_vlan *vlan; - if ((vlan = header_pvindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((vlan = header_pvindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; return agent_v_vlan(vp, var_len, vlan); } -static u_char* -agent_h_remote_vlan(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_vlan(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_vlan *vlan; - if ((vlan = header_tprvindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((vlan = header_tprvindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; return agent_v_vlan(vp, var_len, vlan); } -static u_char* +static u_char * agent_v_ppvid(struct variable *vp, size_t *var_len, struct lldpd_ppvid *ppvid) { static unsigned long long_ret; switch (vp->magic) { case LLDP_SNMP_DOT1_PPVLAN_SUPPORTED: - long_ret = (ppvid->p_cap_status & LLDP_PPVID_CAP_SUPPORTED)?1:2; + long_ret = (ppvid->p_cap_status & LLDP_PPVID_CAP_SUPPORTED) ? 1 : 2; return (u_char *)&long_ret; case LLDP_SNMP_DOT1_PPVLAN_ENABLED: - long_ret = (ppvid->p_cap_status & LLDP_PPVID_CAP_ENABLED)?1:2; + long_ret = (ppvid->p_cap_status & LLDP_PPVID_CAP_ENABLED) ? 1 : 2; return (u_char *)&long_ret; default: return NULL; - } + } } -static u_char* -agent_h_local_ppvid(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_local_ppvid(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_ppvid *ppvid; - if ((ppvid = header_pppvidindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((ppvid = header_pppvidindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; return agent_v_ppvid(vp, var_len, ppvid); } -static u_char* -agent_h_remote_ppvid(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_ppvid(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_ppvid *ppvid; - if ((ppvid = header_tprppvidindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((ppvid = header_tprppvidindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; return agent_v_ppvid(vp, var_len, ppvid); } -static u_char* +static u_char * agent_v_pi(struct variable *vp, size_t *var_len, struct lldpd_pi *pi) { switch (vp->magic) { @@ -1199,76 +1163,76 @@ agent_v_pi(struct variable *vp, size_t *var_len, struct lldpd_pi *pi) return (u_char *)pi->p_pi; default: return NULL; - } + } } -static u_char* -agent_h_local_pi(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_local_pi(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_pi *pi; - if ((pi = header_ppiindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((pi = header_ppiindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; return agent_v_pi(vp, var_len, pi); } -static u_char* -agent_h_remote_pi(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_pi(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_pi *pi; - if ((pi = header_tprpiindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((pi = header_tprpiindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; return agent_v_pi(vp, var_len, pi); } #endif -static u_char* +static u_char * agent_v_port(struct variable *vp, size_t *var_len, struct lldpd_port *port) { #ifdef ENABLE_DOT3 static uint16_t short_ret; static uint8_t bit; #endif - static unsigned long long_ret; + static unsigned long long_ret; switch (vp->magic) { - case LLDP_SNMP_PIDSUBTYPE: - long_ret = port->p_id_subtype; + case LLDP_SNMP_PIDSUBTYPE: + long_ret = port->p_id_subtype; return (u_char *)&long_ret; - case LLDP_SNMP_PID: + case LLDP_SNMP_PID: *var_len = port->p_id_len; return (u_char *)port->p_id; - case LLDP_SNMP_PORTDESC: + case LLDP_SNMP_PORTDESC: if (!port->p_descr || *port->p_descr == '\0') break; *var_len = strlen(port->p_descr); return (u_char *)port->p_descr; #ifdef ENABLE_DOT3 - case LLDP_SNMP_DOT3_AUTONEG_SUPPORT: - long_ret = 2 - port->p_macphy.autoneg_support; - return (u_char *)&long_ret; - case LLDP_SNMP_DOT3_AUTONEG_ENABLED: - long_ret = 2 - port->p_macphy.autoneg_enabled; - return (u_char *)&long_ret; - case LLDP_SNMP_DOT3_AUTONEG_ADVERTISED: - *var_len = 2; + case LLDP_SNMP_DOT3_AUTONEG_SUPPORT: + long_ret = 2 - port->p_macphy.autoneg_support; + return (u_char *)&long_ret; + case LLDP_SNMP_DOT3_AUTONEG_ENABLED: + long_ret = 2 - port->p_macphy.autoneg_enabled; + return (u_char *)&long_ret; + case LLDP_SNMP_DOT3_AUTONEG_ADVERTISED: + *var_len = 2; short_ret = htons(port->p_macphy.autoneg_advertised); - return (u_char *)&short_ret; - case LLDP_SNMP_DOT3_AUTONEG_MAU: - long_ret = port->p_macphy.mau_type; - return (u_char *)&long_ret; - case LLDP_SNMP_DOT3_AGG_STATUS: - bit = swap_bits((port->p_aggregid > 0) ? 3 : 0); - *var_len = 1; - return (u_char *)&bit; - case LLDP_SNMP_DOT3_AGG_ID: - long_ret = port->p_aggregid; - return (u_char *)&long_ret; - case LLDP_SNMP_DOT3_MFS: + return (u_char *)&short_ret; + case LLDP_SNMP_DOT3_AUTONEG_MAU: + long_ret = port->p_macphy.mau_type; + return (u_char *)&long_ret; + case LLDP_SNMP_DOT3_AGG_STATUS: + bit = swap_bits((port->p_aggregid > 0) ? 3 : 0); + *var_len = 1; + return (u_char *)&bit; + case LLDP_SNMP_DOT3_AGG_ID: + long_ret = port->p_aggregid; + return (u_char *)&long_ret; + case LLDP_SNMP_DOT3_MFS: if (port->p_mfs) { long_ret = port->p_mfs; return (u_char *)&long_ret; @@ -1276,25 +1240,26 @@ agent_v_port(struct variable *vp, size_t *var_len, struct lldpd_port *port) break; case LLDP_SNMP_DOT3_POWER_DEVICETYPE: if (port->p_power.devicetype) { - long_ret = (port->p_power.devicetype == LLDP_DOT3_POWER_PSE)?1:2; + long_ret = + (port->p_power.devicetype == LLDP_DOT3_POWER_PSE) ? 1 : 2; return (u_char *)&long_ret; } break; case LLDP_SNMP_DOT3_POWER_SUPPORT: if (port->p_power.devicetype) { - long_ret = (port->p_power.supported)?1:2; + long_ret = (port->p_power.supported) ? 1 : 2; return (u_char *)&long_ret; } break; case LLDP_SNMP_DOT3_POWER_ENABLED: if (port->p_power.devicetype) { - long_ret = (port->p_power.enabled)?1:2; + long_ret = (port->p_power.enabled) ? 1 : 2; return (u_char *)&long_ret; } break; case LLDP_SNMP_DOT3_POWER_PAIRCONTROL: if (port->p_power.devicetype) { - long_ret = (port->p_power.paircontrol)?1:2; + long_ret = (port->p_power.paircontrol) ? 1 : 2; return (u_char *)&long_ret; } break; @@ -1315,9 +1280,12 @@ agent_v_port(struct variable *vp, size_t *var_len, struct lldpd_port *port) port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) { *var_len = 1; bit = (((port->p_power.powertype == - LLDP_DOT3_POWER_8023AT_TYPE1)?0:1) << 7) | - (((port->p_power.devicetype == - LLDP_DOT3_POWER_PSE)?0:1) << 6); + LLDP_DOT3_POWER_8023AT_TYPE1) ? + 0 : + 1) + << 7) | + (((port->p_power.devicetype == LLDP_DOT3_POWER_PSE) ? 0 : 1) + << 6); return (u_char *)&bit; } break; @@ -1325,7 +1293,7 @@ agent_v_port(struct variable *vp, size_t *var_len, struct lldpd_port *port) if (port->p_power.devicetype && port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) { *var_len = 1; - bit = swap_bits(port->p_power.source%(1<<2)); + bit = swap_bits(port->p_power.source % (1 << 2)); return (u_char *)&bit; } break; @@ -1353,121 +1321,119 @@ agent_v_port(struct variable *vp, size_t *var_len, struct lldpd_port *port) break; #endif #ifdef ENABLE_DOT1 - case LLDP_SNMP_DOT1_PVID: - long_ret = port->p_pvid; - return (u_char *)&long_ret; + case LLDP_SNMP_DOT1_PVID: + long_ret = port->p_pvid; + return (u_char *)&long_ret; #endif default: break; - } + } return NULL; } -static u_char* -agent_h_remote_port(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_port(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_port *port; u_char *a; - if ((port = header_tprindexed_table(vp, name, length, - exact, var_len, write_method, 0)) == NULL) + if ((port = header_tprindexed_table(vp, name, length, exact, var_len, + write_method, 0)) == NULL) return NULL; - if ((a = agent_v_port(vp, var_len, port)) != NULL) - return a; + if ((a = agent_v_port(vp, var_len, port)) != NULL) return a; TRYNEXT(agent_h_remote_port); } -static u_char* -agent_h_local_port(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_local_port(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_hardware *hardware; u_char *a; - if ((hardware = header_portindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((hardware = header_portindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; - if ((a = agent_v_port(vp, var_len, &hardware->h_lport)) != NULL) - return a; + if ((a = agent_v_port(vp, var_len, &hardware->h_lport)) != NULL) return a; TRYNEXT(agent_h_local_port); } -static u_char* +static u_char * agent_v_management(struct variable *vp, size_t *var_len, struct lldpd_mgmt *mgmt) { - static unsigned long int long_ret; - static oid zeroDotZero[2] = {0, 0}; + static unsigned long int long_ret; + static oid zeroDotZero[2] = { 0, 0 }; switch (vp->magic) { - case LLDP_SNMP_ADDR_LEN: - long_ret = mgmt->m_addrsize + 1; - return (u_char*)&long_ret; - case LLDP_SNMP_ADDR_IFSUBTYPE: - if (mgmt->m_iface != 0) - long_ret = LLDP_MGMT_IFACE_IFINDEX; - else - long_ret = 1; - return (u_char*)&long_ret; - case LLDP_SNMP_ADDR_IFID: - long_ret = mgmt->m_iface; - return (u_char*)&long_ret; - case LLDP_SNMP_ADDR_OID: - *var_len = sizeof(zeroDotZero); - return (u_char*)zeroDotZero; + case LLDP_SNMP_ADDR_LEN: + long_ret = mgmt->m_addrsize + 1; + return (u_char *)&long_ret; + case LLDP_SNMP_ADDR_IFSUBTYPE: + if (mgmt->m_iface != 0) + long_ret = LLDP_MGMT_IFACE_IFINDEX; + else + long_ret = 1; + return (u_char *)&long_ret; + case LLDP_SNMP_ADDR_IFID: + long_ret = mgmt->m_iface; + return (u_char *)&long_ret; + case LLDP_SNMP_ADDR_OID: + *var_len = sizeof(zeroDotZero); + return (u_char *)zeroDotZero; default: return NULL; - } + } } -static u_char* -agent_h_local_management(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_local_management(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_mgmt *mgmt; - if ((mgmt = header_ipindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((mgmt = header_ipindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; return agent_v_management(vp, var_len, mgmt); } -static u_char* -agent_h_remote_management(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_management(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_mgmt *mgmt; - if ((mgmt = header_tpripindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((mgmt = header_tpripindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; - return agent_v_management(vp, var_len, mgmt); + return agent_v_management(vp, var_len, mgmt); } #ifdef ENABLE_CUSTOM -static u_char* +static u_char * agent_v_custom(struct variable *vp, size_t *var_len, struct lldpd_custom *custom) { switch (vp->magic) { - case LLDP_SNMP_ORG_DEF_INFO: + case LLDP_SNMP_ORG_DEF_INFO: *var_len = custom->oui_info_len; return (u_char *)custom->oui_info; default: return NULL; - } + } } -static u_char* -agent_h_remote_custom(struct variable *vp, oid *name, size_t *length, - int exact, size_t *var_len, WriteMethod **write_method) +static u_char * +agent_h_remote_custom(struct variable *vp, oid *name, size_t *length, int exact, + size_t *var_len, WriteMethod **write_method) { struct lldpd_custom *custom; - if ((custom = header_tprcustomindexed_table(vp, name, length, - exact, var_len, write_method)) == NULL) + if ((custom = header_tprcustomindexed_table(vp, name, length, exact, var_len, + write_method)) == NULL) return NULL; - return agent_v_custom(vp, var_len, custom); + return agent_v_custom(vp, var_len, custom); } #endif @@ -1486,266 +1452,290 @@ agent_h_remote_custom(struct variable *vp, oid *name, size_t *length, /* For testing purposes, keep this structure ordered by increasing OID! */ struct variable8 agent_lldp_vars[] = { /* Scalars */ - {LLDP_SNMP_TXINTERVAL, ASN_INTEGER, RONLY, agent_h_scalars, 3, {1, 1, 1}}, - {LLDP_SNMP_TXMULTIPLIER, ASN_INTEGER, RONLY, agent_h_scalars, 3, {1, 1, 2}}, - {LLDP_SNMP_REINITDELAY, ASN_INTEGER, RONLY, agent_h_scalars, 3, {1, 1, 3}}, - {LLDP_SNMP_TXDELAY, ASN_INTEGER, RONLY, agent_h_scalars, 3, {1, 1, 4}}, - {LLDP_SNMP_NOTIFICATION, ASN_INTEGER, RONLY, agent_h_scalars, 3, {1, 1, 5}}, - {LLDP_SNMP_LASTUPDATE, ASN_TIMETICKS, RONLY, agent_h_scalars, 3, {1, 2, 1}}, - {LLDP_SNMP_STATS_INSERTS, ASN_GAUGE, RONLY, agent_h_scalars, 3, {1, 2, 2}}, - {LLDP_SNMP_STATS_DELETES, ASN_GAUGE, RONLY, agent_h_scalars, 3, {1, 2, 3}}, - {LLDP_SNMP_STATS_DROPS, ASN_GAUGE, RONLY, agent_h_scalars, 3, {1, 2, 4}}, - {LLDP_SNMP_STATS_AGEOUTS, ASN_GAUGE, RONLY, agent_h_scalars, 3, {1, 2, 5}}, + { LLDP_SNMP_TXINTERVAL, ASN_INTEGER, RONLY, agent_h_scalars, 3, { 1, 1, 1 } }, + { LLDP_SNMP_TXMULTIPLIER, ASN_INTEGER, RONLY, agent_h_scalars, 3, { 1, 1, 2 } }, + { LLDP_SNMP_REINITDELAY, ASN_INTEGER, RONLY, agent_h_scalars, 3, { 1, 1, 3 } }, + { LLDP_SNMP_TXDELAY, ASN_INTEGER, RONLY, agent_h_scalars, 3, { 1, 1, 4 } }, + { LLDP_SNMP_NOTIFICATION, ASN_INTEGER, RONLY, agent_h_scalars, 3, { 1, 1, 5 } }, + { LLDP_SNMP_LASTUPDATE, ASN_TIMETICKS, RONLY, agent_h_scalars, 3, { 1, 2, 1 } }, + { LLDP_SNMP_STATS_INSERTS, ASN_GAUGE, RONLY, agent_h_scalars, 3, { 1, 2, 2 } }, + { LLDP_SNMP_STATS_DELETES, ASN_GAUGE, RONLY, agent_h_scalars, 3, { 1, 2, 3 } }, + { LLDP_SNMP_STATS_DROPS, ASN_GAUGE, RONLY, agent_h_scalars, 3, { 1, 2, 4 } }, + { LLDP_SNMP_STATS_AGEOUTS, ASN_GAUGE, RONLY, agent_h_scalars, 3, { 1, 2, 5 } }, /* Stats */ - {LLDP_SNMP_STATS_TX, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 6, 1, 2}}, - {LLDP_SNMP_STATS_RX_DISCARDED, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 2}}, - {LLDP_SNMP_STATS_RX_ERRORS, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 3}}, - {LLDP_SNMP_STATS_RX, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 4}}, - {LLDP_SNMP_STATS_RX_TLVDISCARDED, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 5}}, - {LLDP_SNMP_STATS_RX_TLVUNRECOGNIZED, ASN_COUNTER, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 6}}, - {LLDP_SNMP_STATS_RX_AGEOUTS, ASN_GAUGE, RONLY, agent_h_stats, 5, {1, 2, 7, 1, 7}}, + { LLDP_SNMP_STATS_TX, ASN_COUNTER, RONLY, agent_h_stats, 5, { 1, 2, 6, 1, 2 } }, + { LLDP_SNMP_STATS_RX_DISCARDED, ASN_COUNTER, RONLY, agent_h_stats, 5, + { 1, 2, 7, 1, 2 } }, + { LLDP_SNMP_STATS_RX_ERRORS, ASN_COUNTER, RONLY, agent_h_stats, 5, + { 1, 2, 7, 1, 3 } }, + { LLDP_SNMP_STATS_RX, ASN_COUNTER, RONLY, agent_h_stats, 5, { 1, 2, 7, 1, 4 } }, + { LLDP_SNMP_STATS_RX_TLVDISCARDED, ASN_COUNTER, RONLY, agent_h_stats, 5, + { 1, 2, 7, 1, 5 } }, + { LLDP_SNMP_STATS_RX_TLVUNRECOGNIZED, ASN_COUNTER, RONLY, agent_h_stats, 5, + { 1, 2, 7, 1, 6 } }, + { LLDP_SNMP_STATS_RX_AGEOUTS, ASN_GAUGE, RONLY, agent_h_stats, 5, + { 1, 2, 7, 1, 7 } }, /* Local chassis */ - {LLDP_SNMP_CIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_chassis, 3, {1, 3, 1}}, - {LLDP_SNMP_CID, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, {1, 3, 2}}, - {LLDP_SNMP_SYSNAME, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, {1, 3, 3}}, - {LLDP_SNMP_SYSDESCR, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, {1, 3, 4}}, - {LLDP_SNMP_SYSCAP_SUP, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, {1, 3, 5}}, - {LLDP_SNMP_SYSCAP_ENA, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, {1, 3, 6}}, + { LLDP_SNMP_CIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_chassis, 3, + { 1, 3, 1 } }, + { LLDP_SNMP_CID, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, { 1, 3, 2 } }, + { LLDP_SNMP_SYSNAME, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, + { 1, 3, 3 } }, + { LLDP_SNMP_SYSDESCR, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, + { 1, 3, 4 } }, + { LLDP_SNMP_SYSCAP_SUP, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, + { 1, 3, 5 } }, + { LLDP_SNMP_SYSCAP_ENA, ASN_OCTET_STR, RONLY, agent_h_local_chassis, 3, + { 1, 3, 6 } }, /* Local ports */ - {LLDP_SNMP_PIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_port, 5, {1, 3, 7, 1, 2}}, - {LLDP_SNMP_PID, ASN_OCTET_STR, RONLY, agent_h_local_port, 5, {1, 3, 7, 1, 3}}, - {LLDP_SNMP_PORTDESC, ASN_OCTET_STR, RONLY, agent_h_local_port, 5, {1, 3, 7, 1, 4}}, - /* Local management address */ - {LLDP_SNMP_ADDR_LEN, ASN_INTEGER, RONLY, agent_h_local_management, 5, - {1, 3, 8, 1, 3}}, - {LLDP_SNMP_ADDR_IFSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_management, 5, - {1, 3, 8, 1, 4}}, - {LLDP_SNMP_ADDR_IFID, ASN_INTEGER, RONLY, agent_h_local_management, 5, - {1, 3, 8, 1, 5}}, - {LLDP_SNMP_ADDR_OID, ASN_OBJECT_ID, RONLY, agent_h_local_management, 5, - {1, 3, 8, 1, 6}}, - /* Remote ports */ - {LLDP_SNMP_CIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 4}}, - {LLDP_SNMP_CID, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 5}}, - {LLDP_SNMP_PIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 6}}, - {LLDP_SNMP_PID, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 7}}, - {LLDP_SNMP_PORTDESC, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5, {1, 4, 1, 1, 8}}, - {LLDP_SNMP_SYSNAME, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 9}}, - {LLDP_SNMP_SYSDESCR, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 10}}, - {LLDP_SNMP_SYSCAP_SUP, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 11}}, - {LLDP_SNMP_SYSCAP_ENA, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, {1, 4, 1, 1, 12}}, + { LLDP_SNMP_PIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_port, 5, + { 1, 3, 7, 1, 2 } }, + { LLDP_SNMP_PID, ASN_OCTET_STR, RONLY, agent_h_local_port, 5, + { 1, 3, 7, 1, 3 } }, + { LLDP_SNMP_PORTDESC, ASN_OCTET_STR, RONLY, agent_h_local_port, 5, + { 1, 3, 7, 1, 4 } }, + /* Local management address */ + { LLDP_SNMP_ADDR_LEN, ASN_INTEGER, RONLY, agent_h_local_management, 5, + { 1, 3, 8, 1, 3 } }, + { LLDP_SNMP_ADDR_IFSUBTYPE, ASN_INTEGER, RONLY, agent_h_local_management, 5, + { 1, 3, 8, 1, 4 } }, + { LLDP_SNMP_ADDR_IFID, ASN_INTEGER, RONLY, agent_h_local_management, 5, + { 1, 3, 8, 1, 5 } }, + { LLDP_SNMP_ADDR_OID, ASN_OBJECT_ID, RONLY, agent_h_local_management, 5, + { 1, 3, 8, 1, 6 } }, + /* Remote ports */ + { LLDP_SNMP_CIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_chassis, 5, + { 1, 4, 1, 1, 4 } }, + { LLDP_SNMP_CID, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, + { 1, 4, 1, 1, 5 } }, + { LLDP_SNMP_PIDSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_port, 5, + { 1, 4, 1, 1, 6 } }, + { LLDP_SNMP_PID, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5, + { 1, 4, 1, 1, 7 } }, + { LLDP_SNMP_PORTDESC, ASN_OCTET_STR, RONLY, agent_h_remote_port, 5, + { 1, 4, 1, 1, 8 } }, + { LLDP_SNMP_SYSNAME, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, + { 1, 4, 1, 1, 9 } }, + { LLDP_SNMP_SYSDESCR, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, + { 1, 4, 1, 1, 10 } }, + { LLDP_SNMP_SYSCAP_SUP, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, + { 1, 4, 1, 1, 11 } }, + { LLDP_SNMP_SYSCAP_ENA, ASN_OCTET_STR, RONLY, agent_h_remote_chassis, 5, + { 1, 4, 1, 1, 12 } }, /* Remote management address */ - {LLDP_SNMP_ADDR_IFSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_management, 5, - {1, 4, 2, 1, 3}}, - {LLDP_SNMP_ADDR_IFID, ASN_INTEGER, RONLY, agent_h_remote_management, 5, - {1, 4, 2, 1, 4}}, - {LLDP_SNMP_ADDR_OID, ASN_OBJECT_ID, RONLY, agent_h_remote_management, 5, - {1, 4, 2, 1, 5}}, + { LLDP_SNMP_ADDR_IFSUBTYPE, ASN_INTEGER, RONLY, agent_h_remote_management, 5, + { 1, 4, 2, 1, 3 } }, + { LLDP_SNMP_ADDR_IFID, ASN_INTEGER, RONLY, agent_h_remote_management, 5, + { 1, 4, 2, 1, 4 } }, + { LLDP_SNMP_ADDR_OID, ASN_OBJECT_ID, RONLY, agent_h_remote_management, 5, + { 1, 4, 2, 1, 5 } }, #ifdef ENABLE_CUSTOM /* Custom TLVs */ - {LLDP_SNMP_ORG_DEF_INFO, ASN_OCTET_STR, RONLY, agent_h_remote_custom, 5, - {1, 4, 4, 1, 4}}, + { LLDP_SNMP_ORG_DEF_INFO, ASN_OCTET_STR, RONLY, agent_h_remote_custom, 5, + { 1, 4, 4, 1, 4 } }, #endif #ifdef ENABLE_DOT3 /* Dot3, local ports */ - {LLDP_SNMP_DOT3_AUTONEG_SUPPORT, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 1, 1, 1}}, - {LLDP_SNMP_DOT3_AUTONEG_ENABLED, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 1, 1, 2}}, - {LLDP_SNMP_DOT3_AUTONEG_ADVERTISED, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 1, 1, 3}}, - {LLDP_SNMP_DOT3_AUTONEG_MAU, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 1, 1, 4}}, - {LLDP_SNMP_DOT3_POWER_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 1}}, - {LLDP_SNMP_DOT3_POWER_SUPPORT, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 2}}, - {LLDP_SNMP_DOT3_POWER_ENABLED, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 3}}, - {LLDP_SNMP_DOT3_POWER_PAIRCONTROL, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 4}}, - {LLDP_SNMP_DOT3_POWER_PAIRS, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 5}}, - {LLDP_SNMP_DOT3_POWER_CLASS, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 6}}, - {LLDP_SNMP_DOT3_POWER_TYPE, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 7}}, - {LLDP_SNMP_DOT3_POWER_SOURCE, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 8}}, - {LLDP_SNMP_DOT3_POWER_PRIORITY, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 9}}, - {LLDP_SNMP_DOT3_POWER_REQUESTED, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 10}}, - {LLDP_SNMP_DOT3_POWER_ALLOCATED, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 2, 1, 11}}, - {LLDP_SNMP_DOT3_AGG_STATUS, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 3, 1, 1}}, - {LLDP_SNMP_DOT3_AGG_ID, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 3, 1, 2}}, - {LLDP_SNMP_DOT3_MFS, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 4623, 1, 2, 4, 1, 1}}, + { LLDP_SNMP_DOT3_AUTONEG_SUPPORT, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 1, 1, 1 } }, + { LLDP_SNMP_DOT3_AUTONEG_ENABLED, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 1, 1, 2 } }, + { LLDP_SNMP_DOT3_AUTONEG_ADVERTISED, ASN_OCTET_STR, RONLY, agent_h_local_port, + 8, { 1, 5, 4623, 1, 2, 1, 1, 3 } }, + { LLDP_SNMP_DOT3_AUTONEG_MAU, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 1, 1, 4 } }, + { LLDP_SNMP_DOT3_POWER_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 1 } }, + { LLDP_SNMP_DOT3_POWER_SUPPORT, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 2 } }, + { LLDP_SNMP_DOT3_POWER_ENABLED, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 3 } }, + { LLDP_SNMP_DOT3_POWER_PAIRCONTROL, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 4 } }, + { LLDP_SNMP_DOT3_POWER_PAIRS, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 5 } }, + { LLDP_SNMP_DOT3_POWER_CLASS, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 6 } }, + { LLDP_SNMP_DOT3_POWER_TYPE, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 7 } }, + { LLDP_SNMP_DOT3_POWER_SOURCE, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 8 } }, + { LLDP_SNMP_DOT3_POWER_PRIORITY, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 9 } }, + { LLDP_SNMP_DOT3_POWER_REQUESTED, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 10 } }, + { LLDP_SNMP_DOT3_POWER_ALLOCATED, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 2, 1, 11 } }, + { LLDP_SNMP_DOT3_AGG_STATUS, ASN_OCTET_STR, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 3, 1, 1 } }, + { LLDP_SNMP_DOT3_AGG_ID, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 3, 1, 2 } }, + { LLDP_SNMP_DOT3_MFS, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 4623, 1, 2, 4, 1, 1 } }, #endif - /* Dot3, remote ports */ +/* Dot3, remote ports */ #ifdef ENABLE_DOT3 - {LLDP_SNMP_DOT3_AUTONEG_SUPPORT, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 1, 1, 1}}, - {LLDP_SNMP_DOT3_AUTONEG_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 1, 1, 2}}, - {LLDP_SNMP_DOT3_AUTONEG_ADVERTISED, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 1, 1, 3}}, - {LLDP_SNMP_DOT3_AUTONEG_MAU, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 1, 1, 4}}, - {LLDP_SNMP_DOT3_POWER_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 1}}, - {LLDP_SNMP_DOT3_POWER_SUPPORT, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 2}}, - {LLDP_SNMP_DOT3_POWER_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 3}}, - {LLDP_SNMP_DOT3_POWER_PAIRCONTROL, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 4}}, - {LLDP_SNMP_DOT3_POWER_PAIRS, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 5}}, - {LLDP_SNMP_DOT3_POWER_CLASS, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 6}}, - {LLDP_SNMP_DOT3_POWER_TYPE, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 7}}, - {LLDP_SNMP_DOT3_POWER_SOURCE, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 8}}, - {LLDP_SNMP_DOT3_POWER_PRIORITY, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 9}}, - {LLDP_SNMP_DOT3_POWER_REQUESTED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 10}}, - {LLDP_SNMP_DOT3_POWER_ALLOCATED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 2, 1, 11}}, - {LLDP_SNMP_DOT3_AGG_STATUS, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 3, 1, 1}}, - {LLDP_SNMP_DOT3_AGG_ID, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 3, 1, 2}}, - {LLDP_SNMP_DOT3_MFS, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 4623, 1, 3, 4, 1, 1}}, + { LLDP_SNMP_DOT3_AUTONEG_SUPPORT, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 1, 1, 1 } }, + { LLDP_SNMP_DOT3_AUTONEG_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 1, 1, 2 } }, + { LLDP_SNMP_DOT3_AUTONEG_ADVERTISED, ASN_OCTET_STR, RONLY, agent_h_remote_port, + 8, { 1, 5, 4623, 1, 3, 1, 1, 3 } }, + { LLDP_SNMP_DOT3_AUTONEG_MAU, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 1, 1, 4 } }, + { LLDP_SNMP_DOT3_POWER_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 1 } }, + { LLDP_SNMP_DOT3_POWER_SUPPORT, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 2 } }, + { LLDP_SNMP_DOT3_POWER_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 3 } }, + { LLDP_SNMP_DOT3_POWER_PAIRCONTROL, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 4 } }, + { LLDP_SNMP_DOT3_POWER_PAIRS, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 5 } }, + { LLDP_SNMP_DOT3_POWER_CLASS, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 6 } }, + { LLDP_SNMP_DOT3_POWER_TYPE, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 7 } }, + { LLDP_SNMP_DOT3_POWER_SOURCE, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 8 } }, + { LLDP_SNMP_DOT3_POWER_PRIORITY, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 9 } }, + { LLDP_SNMP_DOT3_POWER_REQUESTED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 10 } }, + { LLDP_SNMP_DOT3_POWER_ALLOCATED, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 2, 1, 11 } }, + { LLDP_SNMP_DOT3_AGG_STATUS, ASN_OCTET_STR, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 3, 1, 1 } }, + { LLDP_SNMP_DOT3_AGG_ID, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 3, 1, 2 } }, + { LLDP_SNMP_DOT3_MFS, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 4623, 1, 3, 4, 1, 1 } }, #endif #ifdef ENABLE_LLDPMED /* LLDP-MED local */ - {LLDP_SNMP_MED_CLASS, ASN_INTEGER, RONLY, agent_h_local_med, 6, - {1, 5, 4795, 1, 1, 1}}, - {LLDP_SNMP_MED_POLICY_VID, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, - {1, 5, 4795, 1, 2, 1, 1, 2}}, - {LLDP_SNMP_MED_POLICY_PRIO, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, - {1, 5, 4795, 1, 2, 1, 1, 3}}, - {LLDP_SNMP_MED_POLICY_DSCP, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, - {1, 5, 4795, 1, 2, 1, 1, 4}}, - {LLDP_SNMP_MED_POLICY_UNKNOWN, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, - {1, 5, 4795, 1, 2, 1, 1, 5}}, - {LLDP_SNMP_MED_POLICY_TAGGED, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, - {1, 5, 4795, 1, 2, 1, 1, 6}}, - {LLDP_SNMP_MED_HW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, - {1, 5, 4795, 1, 2, 2}}, - {LLDP_SNMP_MED_FW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, - {1, 5, 4795, 1, 2, 3}}, - {LLDP_SNMP_MED_SW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, - {1, 5, 4795, 1, 2, 4}}, - {LLDP_SNMP_MED_SN, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, - {1, 5, 4795, 1, 2, 5}}, - {LLDP_SNMP_MED_MANUF, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, - {1, 5, 4795, 1, 2, 6}}, - {LLDP_SNMP_MED_MODEL, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, - {1, 5, 4795, 1, 2, 7}}, - {LLDP_SNMP_MED_ASSET, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, - {1, 5, 4795, 1, 2, 8}}, - {LLDP_SNMP_MED_LOCATION, ASN_OCTET_STR, RONLY, agent_h_local_med_location, 8, - {1, 5, 4795, 1, 2, 9, 1, 2}}, - {LLDP_SNMP_MED_POE_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_local_med_power, 6, - {1, 5, 4795, 1, 2, 10}}, - {LLDP_SNMP_MED_POE_PSE_POWERVAL, ASN_GAUGE, RONLY, agent_h_local_med_power, 8, - {1, 5, 4795, 1, 2, 11, 1, 1}}, - {LLDP_SNMP_MED_POE_PSE_POWERPRIORITY, ASN_INTEGER, RONLY, agent_h_local_med_power, 8, - {1, 5, 4795, 1, 2, 11, 1, 2}}, - {LLDP_SNMP_MED_POE_PSE_POWERSOURCE, ASN_INTEGER, RONLY, agent_h_local_med_power, 6, - {1, 5, 4795, 1, 2, 12}}, - {LLDP_SNMP_MED_POE_PD_POWERVAL, ASN_GAUGE, RONLY, agent_h_local_med_power, 6, - {1, 5, 4795, 1, 2, 13}}, - {LLDP_SNMP_MED_POE_PD_POWERSOURCE, ASN_INTEGER, RONLY, agent_h_local_med_power, 6, - {1, 5, 4795, 1, 2, 14}}, - {LLDP_SNMP_MED_POE_PD_POWERPRIORITY, ASN_INTEGER, RONLY, agent_h_local_med_power, 6, - {1, 5, 4795, 1, 2, 15}}, + { LLDP_SNMP_MED_CLASS, ASN_INTEGER, RONLY, agent_h_local_med, 6, + { 1, 5, 4795, 1, 1, 1 } }, + { LLDP_SNMP_MED_POLICY_VID, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, + { 1, 5, 4795, 1, 2, 1, 1, 2 } }, + { LLDP_SNMP_MED_POLICY_PRIO, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, + { 1, 5, 4795, 1, 2, 1, 1, 3 } }, + { LLDP_SNMP_MED_POLICY_DSCP, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, + { 1, 5, 4795, 1, 2, 1, 1, 4 } }, + { LLDP_SNMP_MED_POLICY_UNKNOWN, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, + { 1, 5, 4795, 1, 2, 1, 1, 5 } }, + { LLDP_SNMP_MED_POLICY_TAGGED, ASN_INTEGER, RONLY, agent_h_local_med_policy, 8, + { 1, 5, 4795, 1, 2, 1, 1, 6 } }, + { LLDP_SNMP_MED_HW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, + { 1, 5, 4795, 1, 2, 2 } }, + { LLDP_SNMP_MED_FW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, + { 1, 5, 4795, 1, 2, 3 } }, + { LLDP_SNMP_MED_SW, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, + { 1, 5, 4795, 1, 2, 4 } }, + { LLDP_SNMP_MED_SN, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, + { 1, 5, 4795, 1, 2, 5 } }, + { LLDP_SNMP_MED_MANUF, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, + { 1, 5, 4795, 1, 2, 6 } }, + { LLDP_SNMP_MED_MODEL, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, + { 1, 5, 4795, 1, 2, 7 } }, + { LLDP_SNMP_MED_ASSET, ASN_OCTET_STR, RONLY, agent_h_local_med, 6, + { 1, 5, 4795, 1, 2, 8 } }, + { LLDP_SNMP_MED_LOCATION, ASN_OCTET_STR, RONLY, agent_h_local_med_location, 8, + { 1, 5, 4795, 1, 2, 9, 1, 2 } }, + { LLDP_SNMP_MED_POE_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_local_med_power, 6, + { 1, 5, 4795, 1, 2, 10 } }, + { LLDP_SNMP_MED_POE_PSE_POWERVAL, ASN_GAUGE, RONLY, agent_h_local_med_power, 8, + { 1, 5, 4795, 1, 2, 11, 1, 1 } }, + { LLDP_SNMP_MED_POE_PSE_POWERPRIORITY, ASN_INTEGER, RONLY, + agent_h_local_med_power, 8, { 1, 5, 4795, 1, 2, 11, 1, 2 } }, + { LLDP_SNMP_MED_POE_PSE_POWERSOURCE, ASN_INTEGER, RONLY, + agent_h_local_med_power, 6, { 1, 5, 4795, 1, 2, 12 } }, + { LLDP_SNMP_MED_POE_PD_POWERVAL, ASN_GAUGE, RONLY, agent_h_local_med_power, 6, + { 1, 5, 4795, 1, 2, 13 } }, + { LLDP_SNMP_MED_POE_PD_POWERSOURCE, ASN_INTEGER, RONLY, agent_h_local_med_power, + 6, { 1, 5, 4795, 1, 2, 14 } }, + { LLDP_SNMP_MED_POE_PD_POWERPRIORITY, ASN_INTEGER, RONLY, + agent_h_local_med_power, 6, { 1, 5, 4795, 1, 2, 15 } }, /* LLDP-MED remote */ - {LLDP_SNMP_MED_CAP_AVAILABLE, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, - {1, 5, 4795, 1, 3, 1, 1, 1}}, - {LLDP_SNMP_MED_CAP_ENABLED, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, - {1, 5, 4795, 1, 3, 1, 1, 2}}, - {LLDP_SNMP_MED_CLASS, ASN_INTEGER, RONLY, agent_h_remote_med, 8, - {1, 5, 4795, 1, 3, 1, 1, 3}}, - {LLDP_SNMP_MED_POLICY_VID, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, - {1, 5, 4795, 1, 3, 2, 1, 2}}, - {LLDP_SNMP_MED_POLICY_PRIO, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, - {1, 5, 4795, 1, 3, 2, 1, 3}}, - {LLDP_SNMP_MED_POLICY_DSCP, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, - {1, 5, 4795, 1, 3, 2, 1, 4}}, - {LLDP_SNMP_MED_POLICY_UNKNOWN, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, - {1, 5, 4795, 1, 3, 2, 1, 5}}, - {LLDP_SNMP_MED_POLICY_TAGGED, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, - {1, 5, 4795, 1, 3, 2, 1, 6}}, - {LLDP_SNMP_MED_HW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, - {1, 5, 4795, 1, 3, 3, 1, 1}}, - {LLDP_SNMP_MED_FW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, - {1, 5, 4795, 1, 3, 3, 1, 2}}, - {LLDP_SNMP_MED_SW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, - {1, 5, 4795, 1, 3, 3, 1, 3}}, - {LLDP_SNMP_MED_SN, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, - {1, 5, 4795, 1, 3, 3, 1, 4}}, - {LLDP_SNMP_MED_MANUF, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, - {1, 5, 4795, 1, 3, 3, 1, 5}}, - {LLDP_SNMP_MED_MODEL, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, - {1, 5, 4795, 1, 3, 3, 1, 6}}, - {LLDP_SNMP_MED_ASSET, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, - {1, 5, 4795, 1, 3, 3, 1, 7}}, - {LLDP_SNMP_MED_LOCATION, ASN_OCTET_STR, RONLY, agent_h_remote_med_location, 8, - {1, 5, 4795, 1, 3, 4, 1, 2}}, - {LLDP_SNMP_MED_POE_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, - {1, 5, 4795, 1, 3, 5, 1, 1}}, - {LLDP_SNMP_MED_POE_PSE_POWERVAL, ASN_GAUGE, RONLY, agent_h_remote_med_power, 8, - {1, 5, 4795, 1, 3, 6, 1, 1}}, - {LLDP_SNMP_MED_POE_PSE_POWERSOURCE, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, - {1, 5, 4795, 1, 3, 6, 1, 2}}, - {LLDP_SNMP_MED_POE_PSE_POWERPRIORITY, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, - {1, 5, 4795, 1, 3, 6, 1, 3}}, - {LLDP_SNMP_MED_POE_PD_POWERVAL, ASN_GAUGE, RONLY, agent_h_remote_med_power, 8, - {1, 5, 4795, 1, 3, 7, 1, 1}}, - {LLDP_SNMP_MED_POE_PD_POWERSOURCE, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, - {1, 5, 4795, 1, 3, 7, 1, 2}}, - {LLDP_SNMP_MED_POE_PD_POWERPRIORITY, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, - {1, 5, 4795, 1, 3, 7, 1, 3}}, + { LLDP_SNMP_MED_CAP_AVAILABLE, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, + { 1, 5, 4795, 1, 3, 1, 1, 1 } }, + { LLDP_SNMP_MED_CAP_ENABLED, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, + { 1, 5, 4795, 1, 3, 1, 1, 2 } }, + { LLDP_SNMP_MED_CLASS, ASN_INTEGER, RONLY, agent_h_remote_med, 8, + { 1, 5, 4795, 1, 3, 1, 1, 3 } }, + { LLDP_SNMP_MED_POLICY_VID, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, + { 1, 5, 4795, 1, 3, 2, 1, 2 } }, + { LLDP_SNMP_MED_POLICY_PRIO, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, + { 1, 5, 4795, 1, 3, 2, 1, 3 } }, + { LLDP_SNMP_MED_POLICY_DSCP, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, + { 1, 5, 4795, 1, 3, 2, 1, 4 } }, + { LLDP_SNMP_MED_POLICY_UNKNOWN, ASN_INTEGER, RONLY, agent_h_remote_med_policy, + 8, { 1, 5, 4795, 1, 3, 2, 1, 5 } }, + { LLDP_SNMP_MED_POLICY_TAGGED, ASN_INTEGER, RONLY, agent_h_remote_med_policy, 8, + { 1, 5, 4795, 1, 3, 2, 1, 6 } }, + { LLDP_SNMP_MED_HW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, + { 1, 5, 4795, 1, 3, 3, 1, 1 } }, + { LLDP_SNMP_MED_FW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, + { 1, 5, 4795, 1, 3, 3, 1, 2 } }, + { LLDP_SNMP_MED_SW, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, + { 1, 5, 4795, 1, 3, 3, 1, 3 } }, + { LLDP_SNMP_MED_SN, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, + { 1, 5, 4795, 1, 3, 3, 1, 4 } }, + { LLDP_SNMP_MED_MANUF, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, + { 1, 5, 4795, 1, 3, 3, 1, 5 } }, + { LLDP_SNMP_MED_MODEL, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, + { 1, 5, 4795, 1, 3, 3, 1, 6 } }, + { LLDP_SNMP_MED_ASSET, ASN_OCTET_STR, RONLY, agent_h_remote_med, 8, + { 1, 5, 4795, 1, 3, 3, 1, 7 } }, + { LLDP_SNMP_MED_LOCATION, ASN_OCTET_STR, RONLY, agent_h_remote_med_location, 8, + { 1, 5, 4795, 1, 3, 4, 1, 2 } }, + { LLDP_SNMP_MED_POE_DEVICETYPE, ASN_INTEGER, RONLY, agent_h_remote_med_power, 8, + { 1, 5, 4795, 1, 3, 5, 1, 1 } }, + { LLDP_SNMP_MED_POE_PSE_POWERVAL, ASN_GAUGE, RONLY, agent_h_remote_med_power, 8, + { 1, 5, 4795, 1, 3, 6, 1, 1 } }, + { LLDP_SNMP_MED_POE_PSE_POWERSOURCE, ASN_INTEGER, RONLY, + agent_h_remote_med_power, 8, { 1, 5, 4795, 1, 3, 6, 1, 2 } }, + { LLDP_SNMP_MED_POE_PSE_POWERPRIORITY, ASN_INTEGER, RONLY, + agent_h_remote_med_power, 8, { 1, 5, 4795, 1, 3, 6, 1, 3 } }, + { LLDP_SNMP_MED_POE_PD_POWERVAL, ASN_GAUGE, RONLY, agent_h_remote_med_power, 8, + { 1, 5, 4795, 1, 3, 7, 1, 1 } }, + { LLDP_SNMP_MED_POE_PD_POWERSOURCE, ASN_INTEGER, RONLY, + agent_h_remote_med_power, 8, { 1, 5, 4795, 1, 3, 7, 1, 2 } }, + { LLDP_SNMP_MED_POE_PD_POWERPRIORITY, ASN_INTEGER, RONLY, + agent_h_remote_med_power, 8, { 1, 5, 4795, 1, 3, 7, 1, 3 } }, #endif - /* Dot1, local and remote ports */ +/* Dot1, local and remote ports */ #ifdef ENABLE_DOT1 - {LLDP_SNMP_DOT1_PVID, ASN_INTEGER, RONLY, agent_h_local_port, 8, - {1, 5, 32962, 1, 2, 1, 1, 1}}, - {LLDP_SNMP_DOT1_PPVLAN_SUPPORTED, ASN_INTEGER, RONLY, agent_h_local_ppvid, 8, - {1, 5, 32962, 1, 2, 2, 1, 2}}, - {LLDP_SNMP_DOT1_PPVLAN_ENABLED, ASN_INTEGER, RONLY, agent_h_local_ppvid, 8, - {1, 5, 32962, 1, 2, 2, 1, 3}}, - {LLDP_SNMP_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_local_vlan, 8, - {1, 5, 32962, 1, 2, 3, 1, 2}}, - {LLDP_SNMP_DOT1_PI, ASN_OCTET_STR, RONLY, agent_h_local_pi, 8, - {1, 5, 32962, 1, 2, 4, 1, 2}}, + { LLDP_SNMP_DOT1_PVID, ASN_INTEGER, RONLY, agent_h_local_port, 8, + { 1, 5, 32962, 1, 2, 1, 1, 1 } }, + { LLDP_SNMP_DOT1_PPVLAN_SUPPORTED, ASN_INTEGER, RONLY, agent_h_local_ppvid, 8, + { 1, 5, 32962, 1, 2, 2, 1, 2 } }, + { LLDP_SNMP_DOT1_PPVLAN_ENABLED, ASN_INTEGER, RONLY, agent_h_local_ppvid, 8, + { 1, 5, 32962, 1, 2, 2, 1, 3 } }, + { LLDP_SNMP_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_local_vlan, 8, + { 1, 5, 32962, 1, 2, 3, 1, 2 } }, + { LLDP_SNMP_DOT1_PI, ASN_OCTET_STR, RONLY, agent_h_local_pi, 8, + { 1, 5, 32962, 1, 2, 4, 1, 2 } }, #endif #ifdef ENABLE_DOT1 - {LLDP_SNMP_DOT1_PVID, ASN_INTEGER, RONLY, agent_h_remote_port, 8, - {1, 5, 32962, 1, 3, 1, 1, 1}}, - {LLDP_SNMP_DOT1_PPVLAN_SUPPORTED, ASN_INTEGER, RONLY, agent_h_remote_ppvid, 8, - {1, 5, 32962, 1, 3, 2, 1, 2}}, - {LLDP_SNMP_DOT1_PPVLAN_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_ppvid, 8, - {1, 5, 32962, 1, 3, 2, 1, 3}}, - /* Remote vlans */ - {LLDP_SNMP_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_remote_vlan, 8, - {1, 5, 32962, 1, 3, 3, 1, 2}}, + { LLDP_SNMP_DOT1_PVID, ASN_INTEGER, RONLY, agent_h_remote_port, 8, + { 1, 5, 32962, 1, 3, 1, 1, 1 } }, + { LLDP_SNMP_DOT1_PPVLAN_SUPPORTED, ASN_INTEGER, RONLY, agent_h_remote_ppvid, 8, + { 1, 5, 32962, 1, 3, 2, 1, 2 } }, + { LLDP_SNMP_DOT1_PPVLAN_ENABLED, ASN_INTEGER, RONLY, agent_h_remote_ppvid, 8, + { 1, 5, 32962, 1, 3, 2, 1, 3 } }, + /* Remote vlans */ + { LLDP_SNMP_DOT1_VLANNAME, ASN_OCTET_STR, RONLY, agent_h_remote_vlan, 8, + { 1, 5, 32962, 1, 3, 3, 1, 2 } }, /* Protocol identity */ - {LLDP_SNMP_DOT1_PI, ASN_OCTET_STR, RONLY, agent_h_remote_pi, 8, - {1, 5, 32962, 1, 3, 4, 1, 2}}, + { LLDP_SNMP_DOT1_PI, ASN_OCTET_STR, RONLY, agent_h_remote_pi, 8, + { 1, 5, 32962, 1, 3, 4, 1, 2 } }, #endif }; -size_t agent_lldp_vars_size(void) { - return sizeof(agent_lldp_vars)/sizeof(struct variable8); +size_t +agent_lldp_vars_size(void) +{ + return sizeof(agent_lldp_vars) / sizeof(struct variable8); } /** @@ -1756,8 +1746,7 @@ size_t agent_lldp_vars_size(void) { * @param rport Changed remote port */ void -agent_notify(struct lldpd_hardware *hardware, int type, - struct lldpd_port *rport) +agent_notify(struct lldpd_hardware *hardware, int type, struct lldpd_port *rport) { struct lldpd_hardware *h; @@ -1769,33 +1758,30 @@ agent_notify(struct lldpd_hardware *hardware, int type, size_t objid_snmptrap_len = OID_LENGTH(objid_snmptrap); /* Other OID */ - oid inserts_oid[] = { LLDP_OID, 1, 2, 2 }; + oid inserts_oid[] = { LLDP_OID, 1, 2, 2 }; size_t inserts_oid_len = OID_LENGTH(inserts_oid); unsigned long inserts = 0; - oid deletes_oid[] = { LLDP_OID, 1, 2, 3 }; + oid deletes_oid[] = { LLDP_OID, 1, 2, 3 }; size_t deletes_oid_len = OID_LENGTH(deletes_oid); unsigned long deletes = 0; - oid drops_oid[] = { LLDP_OID, 1, 2, 4 }; + oid drops_oid[] = { LLDP_OID, 1, 2, 4 }; size_t drops_oid_len = OID_LENGTH(drops_oid); unsigned long drops = 0; - oid ageouts_oid[] = { LLDP_OID, 1, 2, 5 }; + oid ageouts_oid[] = { LLDP_OID, 1, 2, 5 }; size_t ageouts_oid_len = OID_LENGTH(ageouts_oid); unsigned long ageouts = 0; /* We also add some extra. Easy ones. */ - oid locport_oid[] = { LLDP_OID, 1, 3, 7, 1, 4, - hardware->h_ifindex }; + oid locport_oid[] = { LLDP_OID, 1, 3, 7, 1, 4, hardware->h_ifindex }; size_t locport_oid_len = OID_LENGTH(locport_oid); - oid sysname_oid[] = { LLDP_OID, 1, 4, 1, 1, 9, - lastchange(rport), hardware->h_ifindex, - rport->p_chassis->c_index }; + oid sysname_oid[] = { LLDP_OID, 1, 4, 1, 1, 9, lastchange(rport), + hardware->h_ifindex, rport->p_chassis->c_index }; size_t sysname_oid_len = OID_LENGTH(sysname_oid); - oid portdescr_oid[] = { LLDP_OID, 1, 4, 1, 1, 8, - lastchange(rport), hardware->h_ifindex, - rport->p_chassis->c_index }; + oid portdescr_oid[] = { LLDP_OID, 1, 4, 1, 1, 8, lastchange(rport), + hardware->h_ifindex, rport->p_chassis->c_index }; size_t portdescr_oid_len = OID_LENGTH(portdescr_oid); netsnmp_variable_list *notification_vars = NULL; @@ -1817,91 +1803,89 @@ agent_notify(struct lldpd_hardware *hardware, int type, break; } - TAILQ_FOREACH(h, &hardware->h_cfg->g_hardware, h_entries) { + TAILQ_FOREACH (h, &hardware->h_cfg->g_hardware, h_entries) { inserts += h->h_insert_cnt; deletes += h->h_delete_cnt; ageouts += h->h_ageout_cnt; - drops += h->h_drop_cnt; + drops += h->h_drop_cnt; } /* snmpTrapOID */ - snmp_varlist_add_variable(¬ification_vars, - objid_snmptrap, objid_snmptrap_len, - ASN_OBJECT_ID, - (u_char *) notification_oid, + snmp_varlist_add_variable(¬ification_vars, objid_snmptrap, + objid_snmptrap_len, ASN_OBJECT_ID, (u_char *)notification_oid, notification_oid_len * sizeof(oid)); - snmp_varlist_add_variable(¬ification_vars, - inserts_oid, inserts_oid_len, - ASN_GAUGE, - (u_char *)&inserts, - sizeof(inserts)); - snmp_varlist_add_variable(¬ification_vars, - deletes_oid, deletes_oid_len, - ASN_GAUGE, - (u_char *)&deletes, - sizeof(inserts)); - snmp_varlist_add_variable(¬ification_vars, - drops_oid, drops_oid_len, - ASN_GAUGE, - (u_char *)&drops, - sizeof(drops)); - snmp_varlist_add_variable(¬ification_vars, - ageouts_oid, ageouts_oid_len, - ASN_GAUGE, - (u_char *)&ageouts, - sizeof(ageouts)); + snmp_varlist_add_variable(¬ification_vars, inserts_oid, inserts_oid_len, + ASN_GAUGE, (u_char *)&inserts, sizeof(inserts)); + snmp_varlist_add_variable(¬ification_vars, deletes_oid, deletes_oid_len, + ASN_GAUGE, (u_char *)&deletes, sizeof(inserts)); + snmp_varlist_add_variable(¬ification_vars, drops_oid, drops_oid_len, + ASN_GAUGE, (u_char *)&drops, sizeof(drops)); + snmp_varlist_add_variable(¬ification_vars, ageouts_oid, ageouts_oid_len, + ASN_GAUGE, (u_char *)&ageouts, sizeof(ageouts)); if (type != NEIGHBOR_CHANGE_DELETED) { - snmp_varlist_add_variable(¬ification_vars, - locport_oid, locport_oid_len, - ASN_OCTET_STR, - (u_char *)hardware->h_ifname, + snmp_varlist_add_variable(¬ification_vars, locport_oid, + locport_oid_len, ASN_OCTET_STR, (u_char *)hardware->h_ifname, strnlen(hardware->h_ifname, IFNAMSIZ)); if (rport->p_chassis->c_name && *rport->p_chassis->c_name != '\0') { - snmp_varlist_add_variable(¬ification_vars, - sysname_oid, sysname_oid_len, - ASN_OCTET_STR, + snmp_varlist_add_variable(¬ification_vars, sysname_oid, + sysname_oid_len, ASN_OCTET_STR, (u_char *)rport->p_chassis->c_name, strlen(rport->p_chassis->c_name)); } if (rport->p_descr) { - snmp_varlist_add_variable(¬ification_vars, - portdescr_oid, portdescr_oid_len, - ASN_OCTET_STR, - (u_char *)rport->p_descr, + snmp_varlist_add_variable(¬ification_vars, portdescr_oid, + portdescr_oid_len, ASN_OCTET_STR, (u_char *)rport->p_descr, strlen(rport->p_descr)); } } - log_debug("snmp", "sending SNMP trap (%ld, %ld, %ld)", - inserts, deletes, ageouts); + log_debug("snmp", "sending SNMP trap (%ld, %ld, %ld)", inserts, deletes, + ageouts); send_v2trap(notification_vars); snmp_free_varbind(notification_vars); } - /* Logging NetSNMP messages */ static int -agent_log_callback(int major, int minor, - void *serverarg, void *clientarg) { - struct snmp_log_message *slm = (struct snmp_log_message *)serverarg; - char *msg = strdup(slm->msg); - (void)major; (void)minor; (void)clientarg; - - if (msg && msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = '\0'; - switch (slm->priority) { - case LOG_EMERG: log_warnx("libsnmp", "%s", msg?msg:slm->msg); break; - case LOG_ALERT: log_warnx("libsnmp", "%s", msg?msg:slm->msg); break; - case LOG_CRIT: log_warnx("libsnmp", "%s", msg?msg:slm->msg); break; - case LOG_ERR: log_warnx("libsnmp", "%s", msg?msg:slm->msg); break; - case LOG_WARNING: log_warnx("libsnmp", "%s", msg?msg:slm->msg); break; - case LOG_NOTICE: log_info ("libsnmp", "%s", msg?msg:slm->msg); break; - case LOG_INFO: log_info ("libsnmp", "%s", msg?msg:slm->msg); break; - case LOG_DEBUG: log_debug("libsnmp", "%s", msg?msg:slm->msg); break; - } - free(msg); - return SNMP_ERR_NOERROR; +agent_log_callback(int major, int minor, void *serverarg, void *clientarg) +{ + struct snmp_log_message *slm = (struct snmp_log_message *)serverarg; + char *msg = strdup(slm->msg); + (void)major; + (void)minor; + (void)clientarg; + + if (msg && msg[strlen(msg) - 1] == '\n') msg[strlen(msg) - 1] = '\0'; + switch (slm->priority) { + case LOG_EMERG: + log_warnx("libsnmp", "%s", msg ? msg : slm->msg); + break; + case LOG_ALERT: + log_warnx("libsnmp", "%s", msg ? msg : slm->msg); + break; + case LOG_CRIT: + log_warnx("libsnmp", "%s", msg ? msg : slm->msg); + break; + case LOG_ERR: + log_warnx("libsnmp", "%s", msg ? msg : slm->msg); + break; + case LOG_WARNING: + log_warnx("libsnmp", "%s", msg ? msg : slm->msg); + break; + case LOG_NOTICE: + log_info("libsnmp", "%s", msg ? msg : slm->msg); + break; + case LOG_INFO: + log_info("libsnmp", "%s", msg ? msg : slm->msg); + break; + case LOG_DEBUG: + log_debug("libsnmp", "%s", msg ? msg : slm->msg); + break; + } + free(msg); + return SNMP_ERR_NOERROR; } void @@ -1915,16 +1899,14 @@ agent_init(struct lldpd *cfg, const char *agentx) log_debug("snmp", "enable logging"); snmp_disable_log(); snmp_enable_calllog(); - snmp_register_callback(SNMP_CALLBACK_LIBRARY, - SNMP_CALLBACK_LOGGING, - agent_log_callback, - NULL); + snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_LOGGING, + agent_log_callback, NULL); scfg = cfg; /* We are chrooted, we don't want to handle persistent states */ - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, - NETSNMP_DS_LIB_DONT_PERSIST_STATE, TRUE); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PERSIST_STATE, + TRUE); /* Do not load any MIB */ setenv("MIBS", "", 1); setenv("MIBDIRS", "/dev/null", 1); @@ -1937,14 +1919,14 @@ agent_init(struct lldpd *cfg, const char *agentx) if (agentx) netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, - NETSNMP_DS_AGENT_X_SOCKET, agentx); + NETSNMP_DS_AGENT_X_SOCKET, agentx); init_agent("lldpAgent"); REGISTER_MIB("lldp", agent_lldp_vars, variable8, lldp_oid); init_snmp("lldpAgent"); log_debug("snmp", "register to sysORTable"); if ((rc = register_sysORTable(lldp_oid, OID_LENGTH(lldp_oid), - "lldpMIB implementation by lldpd")) != 0) + "lldpMIB implementation by lldpd")) != 0) log_warnx("snmp", "unable to register to sysORTable (%d)", rc); } diff --git a/src/daemon/agent.h b/src/daemon/agent.h index 8f101bd0..b498aebd 100644 --- a/src/daemon/agent.h +++ b/src/daemon/agent.h @@ -1,19 +1,19 @@ /* -*- mode: c; c-file-style: "openbsd" -*- */ /* -* Copyright (c) 2008 Vincent Bernat -* -* Permission to use, copy, modify, and/or distribute this software for any -* purpose with or without fee is hereby granted, provided that the above -* copyright notice and this permission notice appear in all copies. -* -* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ + * Copyright (c) 2008 Vincent Bernat + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ #ifndef _AGENT_H #define _AGENT_H @@ -24,12 +24,12 @@ #include #ifndef RONLY -#define RONLY NETSNMP_OLDAPI_RONLY +# define RONLY NETSNMP_OLDAPI_RONLY #endif -#define LLDP_OID 1, 0, 8802, 1, 1, 2 +#define LLDP_OID 1, 0, 8802, 1, 1, 2 #define SNMPTRAP_OID 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 -static oid lldp_oid[] = {LLDP_OID}; +static oid lldp_oid[] = { LLDP_OID }; size_t agent_lldp_vars_size(void); #endif diff --git a/src/daemon/agent_priv.c b/src/daemon/agent_priv.c index 2f9d8da2..eca4806b 100644 --- a/src/daemon/agent_priv.c +++ b/src/daemon/agent_priv.c @@ -27,22 +27,24 @@ #include #ifdef ENABLE_PRIVSEP -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include -#ifdef ASN_PRIV_STOP +# ifdef ASN_PRIV_STOP /* NetSNMP 5.8+ */ -#define F_SEND_SIGNATURE netsnmp_transport *t, const void *buf, int size, void **opaque, int *olength -#define F_FMTADDR_SIGNATURE netsnmp_transport *t, const void *data, int len -#define F_FROM_OSTRING_SIGNATURE const void* o, size_t o_len, int local -#else -#define F_SEND_SIGNATURE netsnmp_transport *t, void *buf, int size, void **opaque, int *olength -#define F_FMTADDR_SIGNATURE netsnmp_transport *t, void *data, int len -#define F_FROM_OSTRING_SIGNATURE const u_char* o, size_t o_len, int local -#endif +# define F_SEND_SIGNATURE \ + netsnmp_transport *t, const void *buf, int size, void **opaque, int *olength +# define F_FMTADDR_SIGNATURE netsnmp_transport *t, const void *data, int len +# define F_FROM_OSTRING_SIGNATURE const void *o, size_t o_len, int local +# else +# define F_SEND_SIGNATURE \ + netsnmp_transport *t, void *buf, int size, void **opaque, int *olength +# define F_FMTADDR_SIGNATURE netsnmp_transport *t, void *data, int len +# define F_FROM_OSTRING_SIGNATURE const u_char *o, size_t o_len, int local +# endif static oid netsnmp_unix[] = { TRANSPORT_DOMAIN_LOCAL }; static netsnmp_tdomain unixDomain; @@ -55,30 +57,27 @@ agent_priv_unix_fmtaddr(F_FMTADDR_SIGNATURE) } static int -agent_priv_unix_recv(netsnmp_transport *t, void *buf, int size, - void **opaque, int *olength) +agent_priv_unix_recv(netsnmp_transport *t, void *buf, int size, void **opaque, + int *olength) { int rc = -1; - socklen_t tolen = sizeof(struct sockaddr_un); + socklen_t tolen = sizeof(struct sockaddr_un); struct sockaddr *to = NULL; - if (t == NULL || t->sock < 0) - goto recv_error; + if (t == NULL || t->sock < 0) goto recv_error; to = (struct sockaddr *)calloc(1, sizeof(struct sockaddr_un)); - if (to == NULL) - goto recv_error; - if (getsockname(t->sock, to, &tolen) != 0) - goto recv_error; + if (to == NULL) goto recv_error; + if (getsockname(t->sock, to, &tolen) != 0) goto recv_error; while (rc < 0) { rc = recv(t->sock, buf, size, 0); - /* TODO: handle the (unlikely) case where we get EAGAIN or EWOULDBLOCK */ + /* TODO: handle the (unlikely) case where we get EAGAIN or EWOULDBLOCK + */ if (rc < 0 && errno != EINTR) { - log_warn("snmp", "unable to receive from fd %d", - t->sock); + log_warn("snmp", "unable to receive from fd %d", t->sock); goto recv_error; } } - *opaque = (void*)to; + *opaque = (void *)to; *olength = sizeof(struct sockaddr_un); return rc; @@ -89,17 +88,15 @@ recv_error: return -1; } -#define AGENT_WRITE_TIMEOUT 2000 +# define AGENT_WRITE_TIMEOUT 2000 static int agent_priv_unix_send(F_SEND_SIGNATURE) { int rc = -1; if (t != NULL && t->sock >= 0) { - struct pollfd sagentx = { - .fd = t->sock, - .events = POLLOUT | POLLERR | POLLHUP - }; + struct pollfd sagentx = { .fd = t->sock, + .events = POLLOUT | POLLERR | POLLHUP }; while (rc < 0) { rc = poll(&sagentx, 1, AGENT_WRITE_TIMEOUT); if (rc == 0) { @@ -112,8 +109,7 @@ agent_priv_unix_send(F_SEND_SIGNATURE) /* We can either write or have an error somewhere */ rc = send(t->sock, buf, size, 0); if (rc < 0) { - if (errno == EAGAIN || - errno == EWOULDBLOCK || + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) /* Let's retry */ continue; @@ -157,30 +153,26 @@ agent_priv_unix_accept(netsnmp_transport *t) static netsnmp_transport * agent_priv_unix_transport(const char *string, int len, int local) { - struct sockaddr_un addr = { - .sun_family = AF_UNIX - }; + struct sockaddr_un addr = { .sun_family = AF_UNIX }; netsnmp_transport *t = NULL; if (local) { log_warnx("snmp", "should not have been called for local transport"); return NULL; } - if (!string) - return NULL; + if (!string) return NULL; if (len >= sizeof(addr.sun_path) || - strlcpy(addr.sun_path, string, sizeof(addr.sun_path)) >= sizeof(addr.sun_path)) { + strlcpy(addr.sun_path, string, sizeof(addr.sun_path)) >= + sizeof(addr.sun_path)) { log_warnx("snmp", "path too long for Unix domain transport"); return NULL; } - if ((t = (netsnmp_transport *) - calloc(1, sizeof(netsnmp_transport))) == NULL) + if ((t = (netsnmp_transport *)calloc(1, sizeof(netsnmp_transport))) == NULL) return NULL; t->domain = netsnmp_unix; - t->domain_length = - sizeof(netsnmp_unix) / sizeof(netsnmp_unix[0]); + t->domain_length = sizeof(netsnmp_unix) / sizeof(netsnmp_unix[0]); if ((t->sock = priv_snmp_socket(&addr)) < 0) { netsnmp_transport_free(t); @@ -189,8 +181,7 @@ agent_priv_unix_transport(const char *string, int len, int local) t->flags = NETSNMP_TRANSPORT_FLAG_STREAM; - if ((t->remote = (u_char *) - calloc(1, strlen(addr.sun_path) + 1)) == NULL) { + if ((t->remote = (u_char *)calloc(1, strlen(addr.sun_path) + 1)) == NULL) { agent_priv_unix_close(t); netsnmp_transport_free(t); return NULL; @@ -199,34 +190,34 @@ agent_priv_unix_transport(const char *string, int len, int local) t->remote_length = strlen(addr.sun_path); t->msgMaxSize = 0x7fffffff; - t->f_recv = agent_priv_unix_recv; - t->f_send = agent_priv_unix_send; - t->f_close = agent_priv_unix_close; - t->f_accept = agent_priv_unix_accept; - t->f_fmtaddr = agent_priv_unix_fmtaddr; + t->f_recv = agent_priv_unix_recv; + t->f_send = agent_priv_unix_send; + t->f_close = agent_priv_unix_close; + t->f_accept = agent_priv_unix_accept; + t->f_fmtaddr = agent_priv_unix_fmtaddr; return t; } -#if HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW +# if HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW netsnmp_transport * -agent_priv_unix_create_tstring_new(const char *string, int local, const char *default_target) +agent_priv_unix_create_tstring_new(const char *string, int local, + const char *default_target) { - if ((!string || *string == '\0') && default_target && - *default_target != '\0') { + if ((!string || *string == '\0') && default_target && *default_target != '\0') { string = default_target; } if (!string) return NULL; return agent_priv_unix_transport(string, strlen(string), local); } -#else +# else netsnmp_transport * agent_priv_unix_create_tstring(const char *string, int local) { if (!string) return NULL; return agent_priv_unix_transport(string, strlen(string), local); } -#endif +# endif static netsnmp_transport * agent_priv_unix_create_ostring(F_FROM_OSTRING_SIGNATURE) @@ -239,13 +230,13 @@ agent_priv_register_domain() { unixDomain.name = netsnmp_unix; unixDomain.name_length = sizeof(netsnmp_unix) / sizeof(oid); - unixDomain.prefix = (const char**)calloc(2, sizeof(char *)); + unixDomain.prefix = (const char **)calloc(2, sizeof(char *)); unixDomain.prefix[0] = "unix"; -#if HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW +# if HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW unixDomain.f_create_from_tstring_new = agent_priv_unix_create_tstring_new; -#else +# else unixDomain.f_create_from_tstring = agent_priv_unix_create_tstring; -#endif +# endif unixDomain.f_create_from_ostring = agent_priv_unix_create_ostring; netsnmp_tdomain_register(&unixDomain); } diff --git a/src/daemon/bitmap.c b/src/daemon/bitmap.c index d6e4caa3..c7a6330b 100644 --- a/src/daemon/bitmap.c +++ b/src/daemon/bitmap.c @@ -25,8 +25,7 @@ void bitmap_set(uint32_t *bmap, uint16_t vlan_id) { - if (vlan_id < MAX_VLAN) - bmap[vlan_id / 32] |= (((uint32_t) 1) << (vlan_id % 32)); + if (vlan_id < MAX_VLAN) bmap[vlan_id / 32] |= (((uint32_t)1) << (vlan_id % 32)); } /* @@ -38,8 +37,7 @@ bitmap_isempty(uint32_t *bmap) int i; for (i = 0; i < VLAN_BITMAP_LEN; i++) { - if (bmap[i] != 0) - return 0; + if (bmap[i] != 0) return 0; } return 1; diff --git a/src/daemon/client.c b/src/daemon/client.c index 654dbefd..d9d907fd 100644 --- a/src/daemon/client.c +++ b/src/daemon/client.c @@ -21,8 +21,8 @@ #include static ssize_t -client_handle_none(struct lldpd *cfg, enum hmsg_type *type, - void *input, int input_len, void **output, int *subscribed) +client_handle_none(struct lldpd *cfg, enum hmsg_type *type, void *input, int input_len, + void **output, int *subscribed) { log_info("rpc", "received noop request from client"); *type = NONE; @@ -31,8 +31,8 @@ client_handle_none(struct lldpd *cfg, enum hmsg_type *type, /* Return the global configuration */ static ssize_t -client_handle_get_configuration(struct lldpd *cfg, enum hmsg_type *type, - void *input, int input_len, void **output, int *subscribed) +client_handle_get_configuration(struct lldpd *cfg, enum hmsg_type *type, void *input, + int input_len, void **output, int *subscribed) { ssize_t output_len; log_debug("rpc", "client requested configuration"); @@ -44,7 +44,7 @@ client_handle_get_configuration(struct lldpd *cfg, enum hmsg_type *type, return output_len; } -static char* +static char * xstrdup(const char *str) { if (!str) return NULL; @@ -53,8 +53,8 @@ xstrdup(const char *str) /* Change the global configuration */ static ssize_t -client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, - void *input, int input_len, void **output, int *subscribed) +client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, void *input, + int input_len, void **output, int *subscribed) { struct lldpd_config *config; @@ -66,8 +66,9 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, } #define CHANGED(w) (config->w != cfg->g_config.w) -#define CHANGED_STR(w) (!(config->w == cfg->g_config.w || \ - (config->w && cfg->g_config.w && !strcmp(config->w, cfg->g_config.w)))) +#define CHANGED_STR(w) \ + (!(config->w == cfg->g_config.w || \ + (config->w && cfg->g_config.w && !strcmp(config->w, cfg->g_config.w)))) /* What needs to be done? Transmit delay? */ if (CHANGED(c_tx_interval) && config->c_tx_interval != 0) { @@ -77,8 +78,8 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, log_debug("rpc", "client change transmit interval to %d ms", config->c_tx_interval); cfg->g_config.c_tx_interval = config->c_tx_interval; - cfg->g_config.c_ttl = cfg->g_config.c_tx_interval * - cfg->g_config.c_tx_hold; + cfg->g_config.c_ttl = + cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold; cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000; } levent_send_now(cfg); @@ -87,8 +88,8 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, log_debug("rpc", "client change transmit hold to %d", config->c_tx_hold); cfg->g_config.c_tx_hold = config->c_tx_hold; - cfg->g_config.c_ttl = cfg->g_config.c_tx_interval * - cfg->g_config.c_tx_hold; + cfg->g_config.c_ttl = + cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold; cfg->g_config.c_ttl = (cfg->g_config.c_ttl + 999) / 1000; } if (CHANGED(c_max_neighbors) && config->c_max_neighbors > 0) { @@ -115,7 +116,7 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, /* Pause/resume */ if (CHANGED(c_paused)) { log_debug("rpc", "client asked to %s lldpd", - config->c_paused?"pause":"resume"); + config->c_paused ? "pause" : "resume"); cfg->g_config.c_paused = config->c_paused; levent_send_now(cfg); } @@ -124,38 +125,38 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, if (CHANGED(c_enable_fast_start)) { cfg->g_config.c_enable_fast_start = config->c_enable_fast_start; log_debug("rpc", "client asked to %s fast start", - cfg->g_config.c_enable_fast_start?"enable":"disable"); + cfg->g_config.c_enable_fast_start ? "enable" : "disable"); } - if (CHANGED(c_tx_fast_interval) && - config->c_tx_fast_interval > 0) { - log_debug("rpc", "change fast interval to %d", config->c_tx_fast_interval); + if (CHANGED(c_tx_fast_interval) && config->c_tx_fast_interval > 0) { + log_debug("rpc", "change fast interval to %d", + config->c_tx_fast_interval); cfg->g_config.c_tx_fast_interval = config->c_tx_fast_interval; } #endif if (CHANGED_STR(c_iface_pattern)) { log_debug("rpc", "change interface pattern to %s", - config->c_iface_pattern?config->c_iface_pattern:"(NULL)"); + config->c_iface_pattern ? config->c_iface_pattern : "(NULL)"); free(cfg->g_config.c_iface_pattern); cfg->g_config.c_iface_pattern = xstrdup(config->c_iface_pattern); levent_update_now(cfg); } if (CHANGED_STR(c_perm_ifaces)) { log_debug("rpc", "change permanent interface pattern to %s", - config->c_perm_ifaces?config->c_perm_ifaces:"(NULL)"); + config->c_perm_ifaces ? config->c_perm_ifaces : "(NULL)"); free(cfg->g_config.c_perm_ifaces); cfg->g_config.c_perm_ifaces = xstrdup(config->c_perm_ifaces); levent_update_now(cfg); } if (CHANGED_STR(c_mgmt_pattern)) { log_debug("rpc", "change management pattern to %s", - config->c_mgmt_pattern?config->c_mgmt_pattern:"(NULL)"); + config->c_mgmt_pattern ? config->c_mgmt_pattern : "(NULL)"); free(cfg->g_config.c_mgmt_pattern); cfg->g_config.c_mgmt_pattern = xstrdup(config->c_mgmt_pattern); levent_update_now(cfg); } if (CHANGED_STR(c_cid_string)) { log_debug("rpc", "change chassis ID string to %s", - config->c_cid_string?config->c_cid_string:"(NULL)"); + config->c_cid_string ? config->c_cid_string : "(NULL)"); free(cfg->g_config.c_cid_string); cfg->g_config.c_cid_string = xstrdup(config->c_cid_string); free(LOCAL_CHASSIS(cfg)->c_id); @@ -165,7 +166,7 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, } if (CHANGED_STR(c_description)) { log_debug("rpc", "change chassis description to %s", - config->c_description?config->c_description:"(NULL)"); + config->c_description ? config->c_description : "(NULL)"); free(cfg->g_config.c_description); cfg->g_config.c_description = xstrdup(config->c_description); lldpd_update_localchassis(cfg); @@ -173,7 +174,7 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, } if (CHANGED_STR(c_platform)) { log_debug("rpc", "change platform description to %s", - config->c_platform?config->c_platform:"(NULL)"); + config->c_platform ? config->c_platform : "(NULL)"); free(cfg->g_config.c_platform); cfg->g_config.c_platform = xstrdup(config->c_platform); lldpd_update_localchassis(cfg); @@ -181,47 +182,48 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, } if (CHANGED_STR(c_hostname)) { log_debug("rpc", "change system name to %s", - config->c_hostname?config->c_hostname:"(NULL)"); + config->c_hostname ? config->c_hostname : "(NULL)"); free(cfg->g_config.c_hostname); cfg->g_config.c_hostname = xstrdup(config->c_hostname); lldpd_update_localchassis(cfg); levent_update_now(cfg); } if (CHANGED(c_set_ifdescr)) { - log_debug("rpc", "%s setting of interface description based on discovered neighbors", - config->c_set_ifdescr?"enable":"disable"); + log_debug("rpc", + "%s setting of interface description based on discovered neighbors", + config->c_set_ifdescr ? "enable" : "disable"); cfg->g_config.c_set_ifdescr = config->c_set_ifdescr; levent_update_now(cfg); } if (CHANGED(c_promisc)) { log_debug("rpc", "%s promiscuous mode on managed interfaces", - config->c_promisc?"enable":"disable"); + config->c_promisc ? "enable" : "disable"); cfg->g_config.c_promisc = config->c_promisc; levent_update_now(cfg); } if (CHANGED(c_cap_advertise)) { log_debug("rpc", "%s chassis capabilities advertisement", - config->c_cap_advertise?"enable":"disable"); + config->c_cap_advertise ? "enable" : "disable"); cfg->g_config.c_cap_advertise = config->c_cap_advertise; levent_update_now(cfg); } if (CHANGED(c_cap_override)) { log_debug("rpc", "%s chassis capabilities override", - config->c_cap_override?"enable":"disable"); + config->c_cap_override ? "enable" : "disable"); cfg->g_config.c_cap_override = config->c_cap_override; levent_update_now(cfg); } if (CHANGED(c_mgmt_advertise)) { log_debug("rpc", "%s management addresses advertisement", - config->c_mgmt_advertise?"enable":"disable"); + config->c_mgmt_advertise ? "enable" : "disable"); cfg->g_config.c_mgmt_advertise = config->c_mgmt_advertise; levent_update_now(cfg); } if (CHANGED(c_bond_slave_src_mac_type)) { if (config->c_bond_slave_src_mac_type > - LLDP_BOND_SLAVE_SRC_MAC_TYPE_UNKNOWN && + LLDP_BOND_SLAVE_SRC_MAC_TYPE_UNKNOWN && config->c_bond_slave_src_mac_type <= - LLDP_BOND_SLAVE_SRC_MAC_TYPE_MAX) { + LLDP_BOND_SLAVE_SRC_MAC_TYPE_MAX) { log_debug("rpc", "change bond src mac type to %d", config->c_bond_slave_src_mac_type); cfg->g_config.c_bond_slave_src_mac_type = @@ -243,8 +245,8 @@ client_handle_set_configuration(struct lldpd *cfg, enum hmsg_type *type, Output: list of interface names (lldpd_interface_list) */ static ssize_t -client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, - void *input, int input_len, void **output, int *subscribed) +client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, void *input, + int input_len, void **output, int *subscribed) { struct lldpd_interface *iff, *iff_next; struct lldpd_hardware *hardware; @@ -255,9 +257,9 @@ client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, log_debug("rpc", "client request the list of interfaces"); TAILQ_INIT(&ifs); - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { - if ((iff = (struct lldpd_interface*)malloc(sizeof( - struct lldpd_interface))) == NULL) + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { + if ((iff = (struct lldpd_interface *)malloc( + sizeof(struct lldpd_interface))) == NULL) fatal("rpc", NULL); iff->name = hardware->h_ifname; TAILQ_INSERT_TAIL(&ifs, iff, next); @@ -270,9 +272,7 @@ client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, } /* Free the temporary list */ - for (iff = TAILQ_FIRST(&ifs); - iff != NULL; - iff = iff_next) { + for (iff = TAILQ_FIRST(&ifs); iff != NULL; iff = iff_next) { iff_next = TAILQ_NEXT(iff, next); TAILQ_REMOVE(&ifs, iff, next); free(iff); @@ -287,8 +287,8 @@ client_handle_get_interfaces(struct lldpd *cfg, enum hmsg_type *type, * Output: updated chassis object */ static ssize_t -client_handle_set_local_chassis(struct lldpd *cfg, enum hmsg_type *type, - void *input, int input_len, void **output, int *subscribed) +client_handle_set_local_chassis(struct lldpd *cfg, enum hmsg_type *type, void *input, + int input_len, void **output, int *subscribed) { struct lldpd_chassis *chassis = NULL; struct lldpd_chassis *local_chassis = NULL; @@ -306,7 +306,8 @@ client_handle_set_local_chassis(struct lldpd *cfg, enum hmsg_type *type, #ifdef ENABLE_LLDPMED free(local_chassis->c_med_hw); - local_chassis->c_med_hw = (!chassis->c_med_hw) ? dmi_hw() : strdup(chassis->c_med_hw); + local_chassis->c_med_hw = + (!chassis->c_med_hw) ? dmi_hw() : strdup(chassis->c_med_hw); // Follows lldpd.c - only set sw if advertising is enabled if (cfg->g_config.c_advertise_version) { @@ -314,7 +315,8 @@ client_handle_set_local_chassis(struct lldpd *cfg, enum hmsg_type *type, if (!chassis->c_med_sw) { if (uname(&un) < 0) { - log_warn("rpc", "Could not get default uname. Will continue anyway."); + log_warn("rpc", + "Could not get default uname. Will continue anyway."); local_chassis->c_med_sw = NULL; } else { local_chassis->c_med_sw = strdup(un.release); @@ -325,24 +327,30 @@ client_handle_set_local_chassis(struct lldpd *cfg, enum hmsg_type *type, } free(local_chassis->c_med_fw); - local_chassis->c_med_fw = (!chassis->c_med_fw) ? dmi_fw() : strdup(chassis->c_med_fw); + local_chassis->c_med_fw = + (!chassis->c_med_fw) ? dmi_fw() : strdup(chassis->c_med_fw); free(local_chassis->c_med_sn); - local_chassis->c_med_sn = (!chassis->c_med_sn) ? dmi_sn() : strdup(chassis->c_med_sn); + local_chassis->c_med_sn = + (!chassis->c_med_sn) ? dmi_sn() : strdup(chassis->c_med_sn); free(local_chassis->c_med_manuf); - local_chassis->c_med_manuf = (!chassis->c_med_manuf) ? dmi_manuf() : strdup(chassis->c_med_manuf); + local_chassis->c_med_manuf = + (!chassis->c_med_manuf) ? dmi_manuf() : strdup(chassis->c_med_manuf); free(local_chassis->c_med_model); - local_chassis->c_med_model = (!chassis->c_med_model) ? dmi_model() : strdup(chassis->c_med_model); + local_chassis->c_med_model = + (!chassis->c_med_model) ? dmi_model() : strdup(chassis->c_med_model); free(local_chassis->c_med_asset); - local_chassis->c_med_asset = (!chassis->c_med_asset) ? dmi_asset() : strdup(chassis->c_med_asset); + local_chassis->c_med_asset = + (!chassis->c_med_asset) ? dmi_asset() : strdup(chassis->c_med_asset); #endif - if(chassis->c_cap_enabled != local_chassis->c_cap_enabled){ + if (chassis->c_cap_enabled != local_chassis->c_cap_enabled) { local_chassis->c_cap_enabled = chassis->c_cap_enabled; - log_debug("rpc", "change capabilities enabled to: %d", local_chassis->c_cap_enabled); + log_debug("rpc", "change capabilities enabled to: %d", + local_chassis->c_cap_enabled); } #ifdef ENABLE_LLDPMED @@ -371,8 +379,8 @@ client_handle_set_local_chassis(struct lldpd *cfg, enum hmsg_type *type, Output: local chassis (lldpd_chassis) */ static ssize_t -client_handle_get_local_chassis(struct lldpd *cfg, enum hmsg_type *type, - void *input, int input_len, void **output, int *subscribed) +client_handle_get_local_chassis(struct lldpd *cfg, enum hmsg_type *type, void *input, + int input_len, void **output, int *subscribed) { struct lldpd_chassis *chassis = LOCAL_CHASSIS(cfg); ssize_t output_len; @@ -392,8 +400,8 @@ client_handle_get_local_chassis(struct lldpd *cfg, enum hmsg_type *type, Output: Information about the interface (lldpd_hardware) */ static ssize_t -client_handle_get_interface(struct lldpd *cfg, enum hmsg_type *type, - void *input, int input_len, void **output, int *subscribed) +client_handle_get_interface(struct lldpd *cfg, enum hmsg_type *type, void *input, + int input_len, void **output, int *subscribed) { char *name; struct lldpd_hardware *hardware; @@ -408,7 +416,7 @@ client_handle_get_interface(struct lldpd *cfg, enum hmsg_type *type, /* Search appropriate hardware */ log_debug("rpc", "client request interface %s", name); - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) if (!strcmp(hardware->h_ifname, name)) { ssize_t output_len = lldpd_hardware_serialize(hardware, output); free(name); @@ -430,8 +438,8 @@ client_handle_get_interface(struct lldpd *cfg, enum hmsg_type *type, Output: Information about the interface (lldpd_hardware) */ static ssize_t -client_handle_get_default_port(struct lldpd *cfg, enum hmsg_type *type, - void *input, int input_len, void **output, int *subscribed) +client_handle_get_default_port(struct lldpd *cfg, enum hmsg_type *type, void *input, + int input_len, void **output, int *subscribed) { log_debug("rpc", "client request the default local port"); ssize_t output_len = lldpd_port_serialize(cfg->g_default_local_port, output); @@ -443,8 +451,8 @@ client_handle_get_default_port(struct lldpd *cfg, enum hmsg_type *type, } static int -_client_handle_set_port(struct lldpd *cfg, - struct lldpd_port *port, struct lldpd_port_set *set) +_client_handle_set_port(struct lldpd *cfg, struct lldpd_port *port, + struct lldpd_port_set *set) { #ifdef ENABLE_LLDPMED struct lldpd_med_loc *loc = NULL; @@ -495,8 +503,8 @@ _client_handle_set_port(struct lldpd *cfg, set->med_policy->type); return -1; } - memcpy(&port->p_med_policy[set->med_policy->type - 1], - set->med_policy, sizeof(struct lldpd_med_policy)); + memcpy(&port->p_med_policy[set->med_policy->type - 1], set->med_policy, + sizeof(struct lldpd_med_policy)); port->p_med_cap_enabled |= LLDP_MED_CAP_POLICY; } if (set->med_location && set->med_location->format > 0) { @@ -507,8 +515,7 @@ _client_handle_set_port(struct lldpd *cfg, set->med_location->format); return -1; } - loc = \ - &port->p_med_location[set->med_location->format - 1]; + loc = &port->p_med_location[set->med_location->format - 1]; free(loc->data); memcpy(loc, set->med_location, sizeof(struct lldpd_med_loc)); if (!loc->data || !(newdata = malloc(loc->data_len))) loc->data_len = 0; @@ -545,14 +552,13 @@ _client_handle_set_port(struct lldpd *cfg, lldpd_custom_list_cleanup(port); } else { if (set->custom) { - log_info("rpc", "custom TLV op %s oui %02x:%02x:%02x subtype %x", - (set->custom_tlv_op == CUSTOM_TLV_REMOVE)?"remove": - (set->custom_tlv_op == CUSTOM_TLV_ADD)?"add": - "replace", - set->custom->oui[0], - set->custom->oui[1], - set->custom->oui[2], - set->custom->subtype); + log_info("rpc", + "custom TLV op %s oui %02x:%02x:%02x subtype %x", + (set->custom_tlv_op == CUSTOM_TLV_REMOVE) ? "remove" : + (set->custom_tlv_op == CUSTOM_TLV_ADD) ? "add" : + "replace", + set->custom->oui[0], set->custom->oui[1], + set->custom->oui[2], set->custom->subtype); switch (set->custom_tlv_op) { case CUSTOM_TLV_REMOVE: lldpd_custom_tlv_cleanup(port, set->custom); @@ -577,8 +583,8 @@ _client_handle_set_port(struct lldpd *cfg, Output: nothing */ static ssize_t -client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, - void *input, int input_len, void **output, int *subscribed) +client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, void *input, + int input_len, void **output, int *subscribed) { int ret = 0; struct lldpd_port_set *set = NULL; @@ -601,21 +607,21 @@ client_handle_set_port(struct lldpd *cfg, enum hmsg_type *type, ret = 1; } else { log_debug("rpc", "client request change to port %s", set->ifname); - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { - if (!strcmp(hardware->h_ifname, set->ifname)) { - struct lldpd_port *port = &hardware->h_lport; - if (_client_handle_set_port(cfg, port, set) == -1) - goto set_port_finished; - ret = 1; - break; - } + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { + if (!strcmp(hardware->h_ifname, set->ifname)) { + struct lldpd_port *port = &hardware->h_lport; + if (_client_handle_set_port(cfg, port, set) == -1) + goto set_port_finished; + ret = 1; + break; + } } } if (ret == 0) log_warn("rpc", "no interface %s found", set->ifname); else - levent_update_now(cfg); + levent_update_now(cfg); set_port_finished: if (!ret) *type = NONE; @@ -643,8 +649,8 @@ set_port_finished: /* Register subscribtion to neighbor changes */ static ssize_t -client_handle_subscribe(struct lldpd *cfg, enum hmsg_type *type, - void *input, int input_len, void **output, int *subscribed) +client_handle_subscribe(struct lldpd *cfg, enum hmsg_type *type, void *input, + int input_len, void **output, int *subscribed) { log_debug("rpc", "client subscribe to changes"); *subscribed = 1; @@ -654,47 +660,41 @@ client_handle_subscribe(struct lldpd *cfg, enum hmsg_type *type, struct client_handle { enum hmsg_type type; const char *name; - ssize_t (*handle)(struct lldpd*, enum hmsg_type *, - void *, int, void **, int *); + ssize_t ( + *handle)(struct lldpd *, enum hmsg_type *, void *, int, void **, int *); }; -static struct client_handle client_handles[] = { - { NONE, "None", client_handle_none }, - { GET_CONFIG, "Get configuration", client_handle_get_configuration }, - { SET_CONFIG, "Set configuration", client_handle_set_configuration }, - { GET_INTERFACES, "Get interfaces", client_handle_get_interfaces }, - { GET_INTERFACE, "Get interface", client_handle_get_interface }, - { GET_DEFAULT_PORT, "Get default port", client_handle_get_default_port }, - { SET_CHASSIS, "Set local chassis", client_handle_set_local_chassis }, - { GET_CHASSIS, "Get local chassis", client_handle_get_local_chassis }, - { SET_PORT, "Set port", client_handle_set_port }, - { SUBSCRIBE, "Subscribe", client_handle_subscribe }, - { 0, NULL } }; +static struct client_handle client_handles[] = { { NONE, "None", client_handle_none }, + { GET_CONFIG, "Get configuration", client_handle_get_configuration }, + { SET_CONFIG, "Set configuration", client_handle_set_configuration }, + { GET_INTERFACES, "Get interfaces", client_handle_get_interfaces }, + { GET_INTERFACE, "Get interface", client_handle_get_interface }, + { GET_DEFAULT_PORT, "Get default port", client_handle_get_default_port }, + { SET_CHASSIS, "Set local chassis", client_handle_set_local_chassis }, + { GET_CHASSIS, "Get local chassis", client_handle_get_local_chassis }, + { SET_PORT, "Set port", client_handle_set_port }, + { SUBSCRIBE, "Subscribe", client_handle_subscribe }, { 0, NULL } }; int -client_handle_client(struct lldpd *cfg, - ssize_t(*send)(void *, int, void *, size_t), - void *out, - enum hmsg_type type, void *buffer, size_t n, - int *subscribed) +client_handle_client(struct lldpd *cfg, ssize_t (*send)(void *, int, void *, size_t), + void *out, enum hmsg_type type, void *buffer, size_t n, int *subscribed) { struct client_handle *ch; - void *answer; ssize_t len, sent; + void *answer; + ssize_t len, sent; log_debug("rpc", "handle client request"); for (ch = client_handles; ch->handle != NULL; ch++) { if (ch->type == type) { TRACE(LLDPD_CLIENT_REQUEST(ch->name)); answer = NULL; - len = ch->handle(cfg, &type, buffer, n, &answer, - subscribed); + len = ch->handle(cfg, &type, buffer, n, &answer, subscribed); sent = send(out, type, answer, len); free(answer); return sent; } } - log_warnx("rpc", "unknown message request (%d) received", - type); + log_warnx("rpc", "unknown message request (%d) received", type); return -1; } diff --git a/src/daemon/dmi-dummy.c b/src/daemon/dmi-dummy.c index 65a68b89..2954d50f 100644 --- a/src/daemon/dmi-dummy.c +++ b/src/daemon/dmi-dummy.c @@ -19,37 +19,37 @@ #ifdef ENABLE_LLDPMED -char* +char * dmi_hw() { return NULL; } -char* +char * dmi_fw() { return NULL; } -char* +char * dmi_sn() { return NULL; } -char* +char * dmi_manuf() { return NULL; } -char* +char * dmi_model() { return NULL; } -char* +char * dmi_asset() { return NULL; diff --git a/src/daemon/dmi-freebsd.c b/src/daemon/dmi-freebsd.c index 7c4a0afb..f20b71b9 100644 --- a/src/daemon/dmi-freebsd.c +++ b/src/daemon/dmi-freebsd.c @@ -20,17 +20,17 @@ #include #ifdef ENABLE_LLDPMED - /* Fill in inventory stuff: - - hardware version: smbios.system.version - - firmware version: smbios.bios.version - - software version: `uname -r` - - serial number: smbios.system.serial - - manufacturer: smbios.system.maker - - model: smbios.system.product - - asset: smbios.chassis.tag - */ +/* Fill in inventory stuff: + - hardware version: smbios.system.version + - firmware version: smbios.bios.version + - software version: `uname -r` + - serial number: smbios.system.serial + - manufacturer: smbios.system.maker + - model: smbios.system.product + - asset: smbios.chassis.tag +*/ -static char* +static char * dmi_get(char *file) { char buffer[100] = {}; @@ -40,42 +40,41 @@ dmi_get(char *file) log_debug("localchassis", "cannot get %s", file); return NULL; } - if (strlen(buffer)) - return strdup(buffer); + if (strlen(buffer)) return strdup(buffer); return NULL; } -char* +char * dmi_hw() { return dmi_get("smbios.system.version"); } -char* +char * dmi_fw() { return dmi_get("smbios.bios.version"); } -char* +char * dmi_sn() { return dmi_get("smbios.system.serial"); } -char* +char * dmi_manuf() { return dmi_get("smbios.system.maker"); } -char* +char * dmi_model() { return dmi_get("smibios.system.product"); } -char* +char * dmi_asset() { return dmi_get("smibios.chassis.tag"); diff --git a/src/daemon/dmi-linux.c b/src/daemon/dmi-linux.c index 6e1857ef..6a194136 100644 --- a/src/daemon/dmi-linux.c +++ b/src/daemon/dmi-linux.c @@ -19,17 +19,17 @@ #include #ifdef ENABLE_LLDPMED - /* Fill in inventory stuff: - - hardware version: /sys/class/dmi/id/product_version - - firmware version: /sys/class/dmi/id/bios_version - - software version: `uname -r` - - serial number: /sys/class/dmi/id/product_serial - - manufacturer: /sys/class/dmi/id/sys_vendor - - model: /sys/class/dmi/id/product_name - - asset: /sys/class/dmi/id/chassis_asset_tag - */ +/* Fill in inventory stuff: + - hardware version: /sys/class/dmi/id/product_version + - firmware version: /sys/class/dmi/id/bios_version + - software version: `uname -r` + - serial number: /sys/class/dmi/id/product_serial + - manufacturer: /sys/class/dmi/id/sys_vendor + - model: /sys/class/dmi/id/product_name + - asset: /sys/class/dmi/id/chassis_asset_tag +*/ -static char* +static char * dmi_get(char *file) { int dmi, s; @@ -47,44 +47,42 @@ dmi_get(char *file) } close(dmi); buffer[sizeof(buffer) - 1] = '\0'; - if ((s > 0) && (buffer[s-1] == '\n')) - buffer[s-1] = '\0'; - if (strlen(buffer)) - return strdup(buffer); + if ((s > 0) && (buffer[s - 1] == '\n')) buffer[s - 1] = '\0'; + if (strlen(buffer)) return strdup(buffer); return NULL; } -char* +char * dmi_hw() { return dmi_get(SYSFS_CLASS_DMI "product_version"); } -char* +char * dmi_fw() { return dmi_get(SYSFS_CLASS_DMI "bios_version"); } -char* +char * dmi_sn() { return dmi_get(SYSFS_CLASS_DMI "product_serial"); } -char* +char * dmi_manuf() { return dmi_get(SYSFS_CLASS_DMI "sys_vendor"); } -char* +char * dmi_model() { return dmi_get(SYSFS_CLASS_DMI "product_name"); } -char* +char * dmi_asset() { return dmi_get(SYSFS_CLASS_DMI "chassis_asset_tag"); diff --git a/src/daemon/dmi-openbsd.c b/src/daemon/dmi-openbsd.c index a2b9556b..3389add5 100644 --- a/src/daemon/dmi-openbsd.c +++ b/src/daemon/dmi-openbsd.c @@ -21,56 +21,51 @@ #ifdef ENABLE_LLDPMED -char* +char * dmi_get(int what, const char *descr) { char result[100] = {}; size_t len = sizeof(result) - 1; - int mib[2] = { - CTL_HW, - what - }; + int mib[2] = { CTL_HW, what }; if (sysctl(mib, 2, result, &len, NULL, 0) == -1) { - log_debug("localchassis", "cannot get %s", - descr); + log_debug("localchassis", "cannot get %s", descr); return NULL; } - log_debug("localchassis", "got `%s` for %s", - result, descr); + log_debug("localchassis", "got `%s` for %s", result, descr); return strdup(result); } -char* +char * dmi_hw() { return dmi_get(HW_VERSION, "hardware revision"); } -char* +char * dmi_fw() { return NULL; } -char* +char * dmi_sn() { return dmi_get(HW_SERIALNO, "serial number"); } -char* +char * dmi_manuf() { return dmi_get(HW_VENDOR, "hardware vendor"); } -char* +char * dmi_model() { return dmi_get(HW_PRODUCT, "hardware product"); } -char* +char * dmi_asset() { return dmi_get(HW_UUID, "hardware UUID"); diff --git a/src/daemon/dmi-osx.c b/src/daemon/dmi-osx.c index 65d476d0..cde86768 100644 --- a/src/daemon/dmi-osx.c +++ b/src/daemon/dmi-osx.c @@ -21,7 +21,7 @@ #include #ifdef ENABLE_LLDPMED -static char* +static char * dmi_get(const char *classname, CFStringRef property) { char *result = NULL; @@ -37,29 +37,32 @@ dmi_get(const char *classname, CFStringRef property) service = IOServiceGetMatchingService(kIOMasterPortDefault, matching); if (!service) { log_warnx("localchassis", "cannot get matching %s class from registry", - classname); + classname); goto end; } - cfres = IORegistryEntryCreateCFProperty(service, property, - kCFAllocatorDefault, kNilOptions); + cfres = IORegistryEntryCreateCFProperty(service, property, kCFAllocatorDefault, + kNilOptions); if (!cfres) { - log_debug("localchassis", "cannot find property %s in class %s in registry", + log_debug("localchassis", + "cannot find property %s in class %s in registry", CFStringGetCStringPtr(property, kCFStringEncodingMacRoman), classname); goto end; } if (CFGetTypeID(cfres) == CFStringGetTypeID()) - result = strdup(CFStringGetCStringPtr((CFStringRef)cfres, kCFStringEncodingMacRoman)); + result = strdup(CFStringGetCStringPtr((CFStringRef)cfres, + kCFStringEncodingMacRoman)); else if (CFGetTypeID(cfres) == CFDataGetTypeID()) { /* OK, we know this is a string. */ result = calloc(1, CFDataGetLength((CFDataRef)cfres) + 1); if (!result) goto end; memcpy(result, CFDataGetBytePtr((CFDataRef)cfres), CFDataGetLength((CFDataRef)cfres)); - } else log_debug("localchassis", "unknown type for property %s in class %s", - CFStringGetCStringPtr(property, kCFStringEncodingMacRoman), - classname); + } else + log_debug("localchassis", "unknown type for property %s in class %s", + CFStringGetCStringPtr(property, kCFStringEncodingMacRoman), + classname); end: if (cfres) CFRelease(cfres); @@ -67,38 +70,38 @@ end: return result; } -char* +char * dmi_hw() { return dmi_get("IOPlatformExpertDevice", CFSTR("version")); } -char* +char * dmi_fw() { /* Dunno where it is. Maybe in SMC? */ return NULL; } -char* +char * dmi_sn() { return dmi_get("IOPlatformExpertDevice", CFSTR("IOPlatformSerialNumber")); } -char* +char * dmi_manuf() { return dmi_get("IOPlatformExpertDevice", CFSTR("manufacturer")); } -char* +char * dmi_model() { return dmi_get("IOPlatformExpertDevice", CFSTR("model")); } -char* +char * dmi_asset() { return dmi_get("IOPlatformExpertDevice", CFSTR("board-id")); diff --git a/src/daemon/event.c b/src/daemon/event.c index 635cc3f1..971500f2 100644 --- a/src/daemon/event.c +++ b/src/daemon/event.c @@ -24,14 +24,14 @@ #include #include #if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdocumentation" +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdocumentation" #endif #include #include #include #if defined(__clang__) -#pragma clang diagnostic pop +# pragma clang diagnostic pop #endif #define EVENT_BUFFER 1024 @@ -40,10 +40,18 @@ static void levent_log_cb(int severity, const char *msg) { switch (severity) { - case _EVENT_LOG_DEBUG: log_debug("libevent", "%s", msg); break; - case _EVENT_LOG_MSG: log_info ("libevent", "%s", msg); break; - case _EVENT_LOG_WARN: log_warnx("libevent", "%s", msg); break; - case _EVENT_LOG_ERR: log_warnx("libevent", "%s", msg); break; + case _EVENT_LOG_DEBUG: + log_debug("libevent", "%s", msg); + break; + case _EVENT_LOG_MSG: + log_info("libevent", "%s", msg); + break; + case _EVENT_LOG_WARN: + log_warnx("libevent", "%s", msg); + break; + case _EVENT_LOG_ERR: + log_warnx("libevent", "%s", msg); + break; } } @@ -53,29 +61,29 @@ struct lldpd_events { }; TAILQ_HEAD(ev_l, lldpd_events); -#define levent_snmp_fds(cfg) ((struct ev_l*)(cfg)->g_snmp_fds) -#define levent_hardware_fds(hardware) ((struct ev_l*)(hardware)->h_recv) +#define levent_snmp_fds(cfg) ((struct ev_l *)(cfg)->g_snmp_fds) +#define levent_hardware_fds(hardware) ((struct ev_l *)(hardware)->h_recv) #ifdef USE_SNMP -#include -#include -#include -#include +# include +# include +# include +# include /* Compatibility with older versions of NetSNMP */ -#ifndef HAVE_SNMP_SELECT_INFO2 -# define netsnmp_large_fd_set fd_set -# define snmp_read2 snmp_read -# define snmp_select_info2 snmp_select_info -# define netsnmp_large_fd_set_init(...) -# define netsnmp_large_fd_set_cleanup(...) -# define NETSNMP_LARGE_FD_SET FD_SET -# define NETSNMP_LARGE_FD_CLR FD_CLR -# define NETSNMP_LARGE_FD_ZERO FD_ZERO -# define NETSNMP_LARGE_FD_ISSET FD_ISSET -#else -# include -#endif +# ifndef HAVE_SNMP_SELECT_INFO2 +# define netsnmp_large_fd_set fd_set +# define snmp_read2 snmp_read +# define snmp_select_info2 snmp_select_info +# define netsnmp_large_fd_set_init(...) +# define netsnmp_large_fd_set_cleanup(...) +# define NETSNMP_LARGE_FD_SET FD_SET +# define NETSNMP_LARGE_FD_CLR FD_CLR +# define NETSNMP_LARGE_FD_ZERO FD_ZERO +# define NETSNMP_LARGE_FD_ISSET FD_ISSET +# else +# include +# endif static void levent_snmp_update(struct lldpd *); @@ -107,7 +115,8 @@ static void levent_snmp_timeout(evutil_socket_t fd, short what, void *arg) { struct lldpd *cfg = arg; - (void)what; (void)fd; + (void)what; + (void)fd; snmp_timeout(); run_alarms(); levent_snmp_update(cfg); @@ -132,10 +141,8 @@ levent_snmp_add_fd(struct lldpd *cfg, int fd) return; } levent_make_socket_nonblocking(fd); - if ((snmpfd->ev = event_new(base, fd, - EV_READ | EV_PERSIST, - levent_snmp_read, - cfg)) == NULL) { + if ((snmpfd->ev = event_new(base, fd, EV_READ | EV_PERSIST, levent_snmp_read, + cfg)) == NULL) { log_warnx("event", "unable to allocate a new SNMP event for FD %d", fd); free(snmpfd); return; @@ -180,14 +187,12 @@ levent_snmp_update(struct lldpd *cfg) netsnmp_large_fd_set fdset; netsnmp_large_fd_set_init(&fdset, FD_SETSIZE); - NETSNMP_LARGE_FD_ZERO(&fdset); + NETSNMP_LARGE_FD_ZERO(&fdset); snmp_select_info2(&maxfd, &fdset, &timeout, &block); /* We need to untrack any event whose FD is not in `fdset` anymore */ - for (snmpfd = TAILQ_FIRST(levent_snmp_fds(cfg)); - snmpfd; - snmpfd = snmpfd_next) { + for (snmpfd = TAILQ_FIRST(levent_snmp_fds(cfg)); snmpfd; snmpfd = snmpfd_next) { snmpfd_next = TAILQ_NEXT(snmpfd, next); if (event_get_fd(snmpfd->ev) >= maxfd || (!NETSNMP_LARGE_FD_ISSET(event_get_fd(snmpfd->ev), &fdset))) { @@ -210,13 +215,14 @@ levent_snmp_update(struct lldpd *cfg) } current += added; if (howmany != current) { - log_debug("event", "added %d events, removed %d events, total of %d events", - added, removed, current); + log_debug("event", + "added %d events, removed %d events, total of %d events", added, + removed, current); howmany = current; } /* If needed, handle timeout */ - if (evtimer_add(cfg->g_snmp_timeout, block?NULL:&timeout) == -1) + if (evtimer_add(cfg->g_snmp_timeout, block ? NULL : &timeout) == -1) log_warnx("event", "unable to schedule timeout function for SNMP"); netsnmp_large_fd_set_cleanup(&fdset); @@ -227,7 +233,7 @@ struct lldpd_one_client { TAILQ_ENTRY(lldpd_one_client) next; struct lldpd *cfg; struct bufferevent *bev; - int subscribed; /* Is this client subscribed to changes? */ + int subscribed; /* Is this client subscribed to changes? */ }; TAILQ_HEAD(, lldpd_one_client) lldpd_clients; @@ -245,9 +251,7 @@ static void levent_ctl_close_clients() { struct lldpd_one_client *client, *client_next; - for (client = TAILQ_FIRST(&lldpd_clients); - client; - client = client_next) { + for (client = TAILQ_FIRST(&lldpd_clients); client; client = client_next) { client_next = TAILQ_NEXT(client, next); levent_ctl_free_client(client); } @@ -273,19 +277,15 @@ void levent_ctl_notify(char *ifname, int state, struct lldpd_port *neighbor) { struct lldpd_one_client *client, *client_next; - struct lldpd_neighbor_change neigh = { - .ifname = ifname, - .state = state, - .neighbor = neighbor - }; + struct lldpd_neighbor_change neigh = { .ifname = ifname, + .state = state, + .neighbor = neighbor }; void *output = NULL; ssize_t output_len = 0; /* Don't use TAILQ_FOREACH, the client may be deleted in case of errors. */ log_debug("control", "notify clients of neighbor changes"); - for (client = TAILQ_FIRST(&lldpd_clients); - client; - client = client_next) { + for (client = TAILQ_FIRST(&lldpd_clients); client; client = client_next) { client_next = TAILQ_NEXT(client, next); if (!client->subscribed) continue; @@ -295,14 +295,14 @@ levent_ctl_notify(char *ifname, int state, struct lldpd_port *neighbor) TAILQ_ENTRY(lldpd_port) backup_p_entries; memcpy(&backup_p_entries, &neighbor->p_entries, sizeof(backup_p_entries)); - memset(&neighbor->p_entries, 0, - sizeof(backup_p_entries)); + memset(&neighbor->p_entries, 0, sizeof(backup_p_entries)); output_len = lldpd_neighbor_change_serialize(&neigh, &output); memcpy(&neighbor->p_entries, &backup_p_entries, sizeof(backup_p_entries)); if (output_len <= 0) { - log_warnx("event", "unable to serialize changed neighbor"); + log_warnx("event", + "unable to serialize changed neighbor"); return; } } @@ -325,15 +325,14 @@ levent_ctl_recv(struct bufferevent *bev, void *ptr) { struct lldpd_one_client *client = ptr; struct evbuffer *buffer = bufferevent_get_input(bev); - size_t buffer_len = evbuffer_get_length(buffer); + size_t buffer_len = evbuffer_get_length(buffer); struct hmsg_header hdr; void *data = NULL; log_debug("control", "receive data on Unix socket"); - if (buffer_len < sizeof(struct hmsg_header)) - return; /* Not enough data yet */ - if (evbuffer_copyout(buffer, &hdr, - sizeof(struct hmsg_header)) != sizeof(struct hmsg_header)) { + if (buffer_len < sizeof(struct hmsg_header)) return; /* Not enough data yet */ + if (evbuffer_copyout(buffer, &hdr, sizeof(struct hmsg_header)) != + sizeof(struct hmsg_header)) { log_warnx("event", "not able to read header"); return; } @@ -343,7 +342,7 @@ levent_ctl_recv(struct bufferevent *bev, void *ptr) } if (buffer_len < hdr.len + sizeof(struct hmsg_header)) - return; /* Not enough data yet */ + return; /* Not enough data yet */ if (hdr.len > 0 && (data = malloc(hdr.len)) == NULL) { log_warnx("event", "not enough memory"); goto recv_error; @@ -354,10 +353,9 @@ levent_ctl_recv(struct bufferevent *bev, void *ptr) /* Currently, we should not receive notification acknowledgment. But if * we receive one, we can discard it. */ if (hdr.len == 0 && hdr.type == NOTIFICATION) return; - if (client_handle_client(client->cfg, - levent_ctl_send_cb, client, - hdr.type, data, hdr.len, - &client->subscribed) == -1) goto recv_error; + if (client_handle_client(client->cfg, levent_ctl_send_cb, client, hdr.type, + data, hdr.len, &client->subscribed) == -1) + goto recv_error; free(data); return; @@ -403,14 +401,13 @@ levent_ctl_accept(evutil_socket_t fd, short what, void *arg) levent_make_socket_nonblocking(s); TAILQ_INSERT_TAIL(&lldpd_clients, client, next); if ((client->bev = bufferevent_socket_new(cfg->g_base, s, - BEV_OPT_CLOSE_ON_FREE)) == NULL) { - log_warnx("event", "unable to allocate a new buffer event for new client"); + BEV_OPT_CLOSE_ON_FREE)) == NULL) { + log_warnx("event", + "unable to allocate a new buffer event for new client"); close(s); goto accept_failed; } - bufferevent_setcb(client->bev, - levent_ctl_recv, NULL, levent_ctl_event, - client); + bufferevent_setcb(client->bev, levent_ctl_recv, NULL, levent_ctl_event, client); bufferevent_enable(client->bev, EV_READ | EV_WRITE); log_debug("event", "new client accepted"); /* coverity[leaked_handle] @@ -431,13 +428,13 @@ levent_priv(evutil_socket_t fd, short what, void *arg) /* Check if we have some data available. We need to pass the socket in * non-blocking mode to be able to run the check without disruption. */ levent_make_socket_nonblocking(fd); - n = read(fd, &one, 1); err = errno; + n = read(fd, &one, 1); + err = errno; levent_make_socket_blocking(fd); switch (n) { case -1: - if (err == EAGAIN || err == EWOULDBLOCK) - /* No data, all good */ + if (err == EAGAIN || err == EWOULDBLOCK) /* No data, all good */ return; log_warnx("event", "unable to poll monitor process, exit"); break; @@ -449,7 +446,8 @@ levent_priv(evutil_socket_t fd, short what, void *arg) * monitor. It would be safer to request 0 byte, but some OS * (illumos) seem to take the shortcut that by asking 0 byte, * we can just return 0 byte. */ - log_warnx("event", "received unexpected data from monitor process, exit"); + log_warnx("event", + "received unexpected data from monitor process, exit"); break; } event_base_loopbreak(base); @@ -459,7 +457,8 @@ static void levent_dump(evutil_socket_t fd, short what, void *arg) { struct event_base *base = arg; - (void)fd; (void)what; + (void)fd; + (void)what; log_debug("event", "dumping all events"); event_base_dump_events(base, stderr); } @@ -467,7 +466,8 @@ static void levent_stop(evutil_socket_t fd, short what, void *arg) { struct event_base *base = arg; - (void)fd; (void)what; + (void)fd; + (void)what; event_base_loopbreak(base); } @@ -478,12 +478,11 @@ levent_update_and_send(evutil_socket_t fd, short what, void *arg) struct timeval tv; long interval_ms = cfg->g_config.c_tx_interval; - (void)fd; (void)what; + (void)fd; + (void)what; lldpd_loop(cfg); - if (cfg->g_iface_event != NULL) - interval_ms *= 20; - if (interval_ms < 30000) - interval_ms = 30000; + if (cfg->g_iface_event != NULL) interval_ms *= 20; + if (interval_ms < 30000) interval_ms = 30000; tv.tv_sec = interval_ms / 1000; tv.tv_usec = (interval_ms % 1000) * 1000; event_add(cfg->g_main_loop, &tv); @@ -492,15 +491,14 @@ levent_update_and_send(evutil_socket_t fd, short what, void *arg) void levent_update_now(struct lldpd *cfg) { - if (cfg->g_main_loop) - event_active(cfg->g_main_loop, EV_TIMEOUT, 1); + if (cfg->g_main_loop) event_active(cfg->g_main_loop, EV_TIMEOUT, 1); } void levent_send_now(struct lldpd *cfg) { struct lldpd_hardware *hardware; - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { if (hardware->h_timer) event_active(hardware->h_timer, EV_TIMEOUT, 1); else @@ -517,21 +515,18 @@ levent_init(struct lldpd *cfg) event_set_log_callback(levent_log_cb); if (!(cfg->g_base = event_base_new())) fatalx("event", "unable to create a new libevent base"); - log_info("event", "libevent %s initialized with %s method", - event_get_version(), - event_base_get_method(cfg->g_base)); + log_info("event", "libevent %s initialized with %s method", event_get_version(), + event_base_get_method(cfg->g_base)); /* Setup SNMP */ #ifdef USE_SNMP if (cfg->g_snmp) { agent_init(cfg, cfg->g_snmp_agentx); - cfg->g_snmp_timeout = evtimer_new(cfg->g_base, - levent_snmp_timeout, - cfg); + cfg->g_snmp_timeout = + evtimer_new(cfg->g_base, levent_snmp_timeout, cfg); if (!cfg->g_snmp_timeout) fatalx("event", "unable to setup timeout function for SNMP"); - if ((cfg->g_snmp_fds = - malloc(sizeof(struct ev_l))) == NULL) + if ((cfg->g_snmp_fds = malloc(sizeof(struct ev_l))) == NULL) fatalx("event", "unable to allocate memory for SNMP events"); TAILQ_INIT(levent_snmp_fds(cfg)); } @@ -539,9 +534,8 @@ levent_init(struct lldpd *cfg) /* Setup loop that will run every X seconds. */ log_debug("event", "register loop timer"); - if (!(cfg->g_main_loop = event_new(cfg->g_base, -1, 0, - levent_update_and_send, - cfg))) + if (!(cfg->g_main_loop = + event_new(cfg->g_base, -1, 0, levent_update_and_send, cfg))) fatalx("event", "unable to setup main timer"); event_active(cfg->g_main_loop, EV_TIMEOUT, 1); @@ -550,8 +544,8 @@ levent_init(struct lldpd *cfg) log_debug("event", "register Unix socket"); TAILQ_INIT(&lldpd_clients); levent_make_socket_nonblocking(cfg->g_ctl); - if ((ctl_event = event_new(cfg->g_base, cfg->g_ctl, - EV_READ|EV_PERSIST, levent_ctl_accept, cfg)) == NULL) + if ((ctl_event = event_new(cfg->g_base, cfg->g_ctl, EV_READ | EV_PERSIST, + levent_ctl_accept, cfg)) == NULL) fatalx("event", "unable to setup control socket event"); event_add(ctl_event, NULL); @@ -559,20 +553,16 @@ levent_init(struct lldpd *cfg) struct event *monitor_event; log_debug("event", "monitor the monitor process"); if ((monitor_event = event_new(cfg->g_base, priv_fd(PRIV_UNPRIVILEGED), - EV_READ|EV_PERSIST, levent_priv, cfg->g_base)) == NULL) + EV_READ | EV_PERSIST, levent_priv, cfg->g_base)) == NULL) fatalx("event", "unable to monitor monitor process"); event_add(monitor_event, NULL); /* Signals */ log_debug("event", "register signals"); - evsignal_add(evsignal_new(cfg->g_base, SIGUSR1, - levent_dump, cfg->g_base), + evsignal_add(evsignal_new(cfg->g_base, SIGUSR1, levent_dump, cfg->g_base), NULL); - evsignal_add(evsignal_new(cfg->g_base, SIGINT, - levent_stop, cfg->g_base), - NULL); - evsignal_add(evsignal_new(cfg->g_base, SIGTERM, - levent_stop, cfg->g_base), + evsignal_add(evsignal_new(cfg->g_base, SIGINT, levent_stop, cfg->g_base), NULL); + evsignal_add(evsignal_new(cfg->g_base, SIGTERM, levent_stop, cfg->g_base), NULL); } @@ -594,12 +584,10 @@ levent_loop(struct lldpd *cfg) break; } while (event_base_loop(cfg->g_base, EVLOOP_ONCE) == 0); - if (cfg->g_iface_timer_event != NULL) - event_free(cfg->g_iface_timer_event); + if (cfg->g_iface_timer_event != NULL) event_free(cfg->g_iface_timer_event); #ifdef USE_SNMP - if (cfg->g_snmp) - agent_shutdown(); + if (cfg->g_snmp) agent_shutdown(); #endif /* USE_SNMP */ levent_ctl_close_clients(); @@ -609,10 +597,8 @@ levent_loop(struct lldpd *cfg) void levent_shutdown(struct lldpd *cfg) { - if (cfg->g_iface_event) - event_free(cfg->g_iface_event); - if (cfg->g_cleanup_timer) - event_free(cfg->g_cleanup_timer); + if (cfg->g_iface_event) event_free(cfg->g_iface_event); + if (cfg->g_cleanup_timer) event_free(cfg->g_cleanup_timer); event_base_free(cfg->g_base); } @@ -622,8 +608,7 @@ levent_hardware_recv(evutil_socket_t fd, short what, void *arg) struct lldpd_hardware *hardware = arg; struct lldpd *cfg = hardware->h_cfg; (void)what; - log_debug("event", "received something for %s", - hardware->h_ifname); + log_debug("event", "received something for %s", hardware->h_ifname); lldpd_recv(cfg, hardware, fd); levent_schedule_cleanup(cfg); } @@ -632,8 +617,7 @@ void levent_hardware_init(struct lldpd_hardware *hardware) { log_debug("event", "initialize events for %s", hardware->h_ifname); - if ((hardware->h_recv = - malloc(sizeof(struct ev_l))) == NULL) { + if ((hardware->h_recv = malloc(sizeof(struct ev_l))) == NULL) { log_warnx("event", "unable to allocate memory for %s", hardware->h_ifname); return; @@ -654,18 +638,16 @@ levent_hardware_add_fd(struct lldpd_hardware *hardware, int fd) return; } levent_make_socket_nonblocking(fd); - if ((hfd->ev = event_new(hardware->h_cfg->g_base, fd, - EV_READ | EV_PERSIST, - levent_hardware_recv, - hardware)) == NULL) { + if ((hfd->ev = event_new(hardware->h_cfg->g_base, fd, EV_READ | EV_PERSIST, + levent_hardware_recv, hardware)) == NULL) { log_warnx("event", "unable to allocate a new event for %s", - hardware->h_ifname); + hardware->h_ifname); free(hfd); return; } if (event_add(hfd->ev, NULL) == -1) { log_warnx("event", "unable to schedule new event for %s", - hardware->h_ifname); + hardware->h_ifname); event_free(hfd->ev); free(hfd); return; @@ -684,9 +666,7 @@ levent_hardware_release(struct lldpd_hardware *hardware) if (!hardware->h_recv) return; log_debug("event", "release events for %s", hardware->h_ifname); - for (ev = TAILQ_FIRST(levent_hardware_fds(hardware)); - ev; - ev = ev_next) { + for (ev = TAILQ_FIRST(levent_hardware_fds(hardware)); ev; ev = ev_next) { ev_next = TAILQ_NEXT(ev, next); /* We may close several time the same FD. This is harmless. */ close(event_get_fd(ev->ev)); @@ -701,8 +681,7 @@ static void levent_iface_trigger(evutil_socket_t fd, short what, void *arg) { struct lldpd *cfg = arg; - log_debug("event", - "triggering update of all interfaces"); + log_debug("event", "triggering update of all interfaces"); lldpd_update_localports(cfg); } @@ -717,9 +696,7 @@ levent_iface_recv(evutil_socket_t fd, short what, void *arg) /* Discard the message */ while (1) { n = read(fd, buffer, sizeof(buffer)); - if (n == -1 && - (errno == EWOULDBLOCK || - errno == EAGAIN)) break; + if (n == -1 && (errno == EWOULDBLOCK || errno == EAGAIN)) break; if (n == -1) { log_warn("event", "unable to receive interface change notification message"); @@ -737,21 +714,20 @@ levent_iface_recv(evutil_socket_t fd, short what, void *arg) /* Schedule local port update. We don't run it right away because we may * receive a batch of events like this. */ - struct timeval one_sec = {1, 0}; + struct timeval one_sec = { 1, 0 }; TRACE(LLDPD_INTERFACES_NOTIFICATION()); log_debug("event", "received notification change, schedule an update of all interfaces in one second"); if (cfg->g_iface_timer_event == NULL) { if ((cfg->g_iface_timer_event = evtimer_new(cfg->g_base, - levent_iface_trigger, cfg)) == NULL) { + levent_iface_trigger, cfg)) == NULL) { log_warnx("event", "unable to create a new event to trigger interface update"); return; } } if (evtimer_add(cfg->g_iface_timer_event, &one_sec) == -1) { - log_warnx("event", - "unable to schedule interface updates"); + log_warnx("event", "unable to schedule interface updates"); return; } } @@ -759,19 +735,17 @@ levent_iface_recv(evutil_socket_t fd, short what, void *arg) int levent_iface_subscribe(struct lldpd *cfg, int socket) { - log_debug("event", "subscribe to interface changes from socket %d", - socket); + log_debug("event", "subscribe to interface changes from socket %d", socket); levent_make_socket_nonblocking(socket); - cfg->g_iface_event = event_new(cfg->g_base, socket, - EV_READ | EV_PERSIST, levent_iface_recv, cfg); + cfg->g_iface_event = event_new(cfg->g_base, socket, EV_READ | EV_PERSIST, + levent_iface_recv, cfg); if (cfg->g_iface_event == NULL) { log_warnx("event", "unable to allocate a new event for interface changes"); return -1; } if (event_add(cfg->g_iface_event, NULL) == -1) { - log_warnx("event", - "unable to schedule new interface changes event"); + log_warnx("event", "unable to schedule new interface changes event"); event_free(cfg->g_iface_event); cfg->g_iface_event = NULL; return -1; @@ -795,8 +769,7 @@ levent_schedule_cleanup(struct lldpd *cfg) } cfg->g_cleanup_timer = evtimer_new(cfg->g_base, levent_trigger_cleanup, cfg); if (cfg->g_cleanup_timer == NULL) { - log_warnx("event", - "unable to allocate a new event for cleanup tasks"); + log_warnx("event", "unable to allocate a new event for cleanup tasks"); return; } @@ -806,28 +779,24 @@ levent_schedule_cleanup(struct lldpd *cfg) time_t next; struct lldpd_hardware *hardware; struct lldpd_port *port; - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (now >= port->p_lastupdate + port->p_ttl) { tv.tv_sec = 0; - log_debug("event", "immediate cleanup on port %s (%lld, %d, %lld)", - hardware->h_ifname, - (long long)now, - port->p_ttl, + log_debug("event", + "immediate cleanup on port %s (%lld, %d, %lld)", + hardware->h_ifname, (long long)now, port->p_ttl, (long long)port->p_lastupdate); break; } next = port->p_ttl - (now - port->p_lastupdate); - if (next < tv.tv_sec) - tv.tv_sec = next; + if (next < tv.tv_sec) tv.tv_sec = next; } } - log_debug("event", "next cleanup in %ld seconds", - (long)tv.tv_sec); + log_debug("event", "next cleanup in %ld seconds", (long)tv.tv_sec); if (event_add(cfg->g_cleanup_timer, &tv) == -1) { - log_warnx("event", - "unable to schedule cleanup task"); + log_warnx("event", "unable to schedule cleanup task"); event_free(cfg->g_cleanup_timer); cfg->g_cleanup_timer = NULL; return; @@ -840,13 +809,11 @@ levent_send_pdu(evutil_socket_t fd, short what, void *arg) struct lldpd_hardware *hardware = arg; int tx_interval = hardware->h_cfg->g_config.c_tx_interval; - log_debug("event", "trigger sending PDU for port %s", - hardware->h_ifname); + log_debug("event", "trigger sending PDU for port %s", hardware->h_ifname); lldpd_send(hardware); #ifdef ENABLE_LLDPMED - if (hardware->h_tx_fast > 0) - hardware->h_tx_fast--; + if (hardware->h_tx_fast > 0) hardware->h_tx_fast--; if (hardware->h_tx_fast > 0) tx_interval = hardware->h_cfg->g_config.c_tx_fast_interval * 1000; @@ -867,11 +834,10 @@ levent_send_pdu(evutil_socket_t fd, short what, void *arg) void levent_schedule_pdu(struct lldpd_hardware *hardware) { - log_debug("event", "schedule sending PDU on %s", - hardware->h_ifname); + log_debug("event", "schedule sending PDU on %s", hardware->h_ifname); if (hardware->h_timer == NULL) { - hardware->h_timer = evtimer_new(hardware->h_cfg->g_base, - levent_send_pdu, hardware); + hardware->h_timer = + evtimer_new(hardware->h_cfg->g_base, levent_send_pdu, hardware); if (hardware->h_timer == NULL) { log_warnx("event", "unable to schedule PDU sending for port %s", hardware->h_ifname); @@ -929,17 +895,14 @@ levent_recv_error(int fd, const char *source) do { ssize_t n; char buf[1024] = {}; - struct msghdr msg = { - .msg_control = buf, - .msg_controllen = sizeof(buf) - }; + struct msghdr msg = { .msg_control = buf, + .msg_controllen = sizeof(buf) }; if ((n = recvmsg(fd, &msg, MSG_ERRQUEUE | MSG_DONTWAIT)) <= 0) { return; } struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); if (cmsg == NULL) - log_warnx("event", "received unknown error on %s", - source); + log_warnx("event", "received unknown error on %s", source); else log_warnx("event", "received error (level=%d/type=%d) on %s", cmsg->cmsg_level, cmsg->cmsg_type, source); diff --git a/src/daemon/forward-bsd.c b/src/daemon/forward-bsd.c index e22a45d5..1f930de1 100644 --- a/src/daemon/forward-bsd.c +++ b/src/daemon/forward-bsd.c @@ -21,16 +21,11 @@ #include int -interfaces_routing_enabled(struct lldpd *cfg) { +interfaces_routing_enabled(struct lldpd *cfg) +{ (void)cfg; - int n, mib[4] = { - CTL_NET, - PF_INET, - IPPROTO_IP, - IPCTL_FORWARDING - }; + int n, mib[4] = { CTL_NET, PF_INET, IPPROTO_IP, IPCTL_FORWARDING }; size_t len = sizeof(int); - if (sysctl(mib, 4, &n, &len, NULL, 0) != -1) - return (n == 1); + if (sysctl(mib, 4, &n, &len, NULL, 0) != -1) return (n == 1); return -1; } diff --git a/src/daemon/forward-linux.c b/src/daemon/forward-linux.c index db563bdc..eda5dbec 100644 --- a/src/daemon/forward-linux.c +++ b/src/daemon/forward-linux.c @@ -33,18 +33,17 @@ ip_forwarding_enabled(int af) else return -1; - if ((fd = priv_open(fname)) < 0) - return -1; + if ((fd = priv_open(fname)) < 0) return -1; - if (read(fd, &status, 1) == 1) - rc = (status == '1'); + if (read(fd, &status, 1) == 1) rc = (status == '1'); close(fd); return rc; } int -interfaces_routing_enabled(struct lldpd *cfg) { +interfaces_routing_enabled(struct lldpd *cfg) +{ (void)cfg; int rc; @@ -54,8 +53,7 @@ interfaces_routing_enabled(struct lldpd *cfg) { * In case of error also stop the execution right away. * If IPv4 forwarding is disabled we'll check the IPv6 status. */ - if (rc != 0) - return rc; + if (rc != 0) return rc; return ip_forwarding_enabled(LLDPD_AF_IPV6); } diff --git a/src/daemon/forward-solaris.c b/src/daemon/forward-solaris.c index 22e323fa..b44a110a 100644 --- a/src/daemon/forward-solaris.c +++ b/src/daemon/forward-solaris.c @@ -18,7 +18,8 @@ #include "lldpd.h" int -interfaces_routing_enabled(struct lldpd *cfg) { +interfaces_routing_enabled(struct lldpd *cfg) +{ /* Dunno how to get this for Solaris. See the commit introducing Solaris support (maybe c3e340b6be8add4eb3a41882847a96e66793e82c) for a solution which does not work in a chroot. */ diff --git a/src/daemon/frame.c b/src/daemon/frame.c index a440764e..adc46297 100644 --- a/src/daemon/frame.c +++ b/src/daemon/frame.c @@ -30,8 +30,7 @@ frame_checksum(const u_char *cp, int len, int cisco) sum += *cp++ << 8; sum += *cp++; } - if ((oddbyte = len & 1) != 0) - v = *cp; + if ((oddbyte = len & 1) != 0) v = *cp; /* The remaining byte seems to be handled oddly by Cisco. From function * dissect_cdp() in wireshark. 2014/6/14,zhengy@yealink.com: @@ -61,7 +60,7 @@ frame_checksum(const u_char *cp, int len, int cisco) } } - sum = (sum >> 16) + (sum & 0xffff); - sum += sum >> 16; - return (0xffff & ~sum); + sum = (sum >> 16) + (sum & 0xffff); + sum += sum >> 16; + return (0xffff & ~sum); } diff --git a/src/daemon/frame.h b/src/daemon/frame.h index eea77aec..714de09f 100644 --- a/src/daemon/frame.h +++ b/src/daemon/frame.h @@ -33,107 +33,70 @@ static union { * author of those macros, Michael Chapman, has relicensed those macros under * the ISC license. */ -#define POKE(value, type, func) \ - ((length >= sizeof(type)) && \ - ( \ - type = func(value), \ - memcpy(pos, &type, sizeof(type)), \ - length -= sizeof(type), \ - pos += sizeof(type), \ - 1 \ - )) +#define POKE(value, type, func) \ + ((length >= sizeof(type)) && \ + (type = func(value), memcpy(pos, &type, sizeof(type)), length -= sizeof(type), \ + pos += sizeof(type), 1)) #define POKE_UINT8(value) POKE(value, types.f_uint8, ) #define POKE_UINT16(value) POKE(value, types.f_uint16, htons) #define POKE_UINT32(value) POKE(value, types.f_uint32, htonl) -#define POKE_BYTES(value, bytes) \ - ((length >= (bytes)) && \ - ( \ - memcpy(pos, value, bytes), \ - length -= (bytes), \ - pos += (bytes), \ - 1 \ - )) -#define POKE_SAVE(where) \ - (where = pos, 1) -#define POKE_RESTORE(where) \ - do { \ - if ((where) > pos) \ - length -= ((where) - pos); \ - else \ - length += (pos - (where)); \ - pos = (where); \ - } while(0) +#define POKE_BYTES(value, bytes) \ + ((length >= (bytes)) && \ + (memcpy(pos, value, bytes), length -= (bytes), pos += (bytes), 1)) +#define POKE_SAVE(where) (where = pos, 1) +#define POKE_RESTORE(where) \ + do { \ + if ((where) > pos) \ + length -= ((where)-pos); \ + else \ + length += (pos - (where)); \ + pos = (where); \ + } while (0) /* This set of macro are used to parse packets. The same variable as for POKE_* * are used. There is no check on boundaries. */ -#define PEEK(type, func) \ - ( \ - memcpy(&type, pos, sizeof(type)), \ - length -= sizeof(type), \ - pos += sizeof(type), \ - func(type) \ - ) +#define PEEK(type, func) \ + (memcpy(&type, pos, sizeof(type)), length -= sizeof(type), pos += sizeof(type), \ + func(type)) #define PEEK_UINT8 PEEK(types.f_uint8, ) #define PEEK_UINT16 PEEK(types.f_uint16, ntohs) #define PEEK_UINT32 PEEK(types.f_uint32, ntohl) -#define PEEK_BYTES(value, bytes) \ - do { \ - memcpy(value, pos, bytes); \ - length -= (bytes); \ - pos += (bytes); \ - } while (0) -#define PEEK_DISCARD(bytes) \ - do { \ - length -= (bytes); \ - pos += (bytes); \ - } while (0) +#define PEEK_BYTES(value, bytes) \ + do { \ + memcpy(value, pos, bytes); \ + length -= (bytes); \ + pos += (bytes); \ + } while (0) +#define PEEK_DISCARD(bytes) \ + do { \ + length -= (bytes); \ + pos += (bytes); \ + } while (0) #define PEEK_DISCARD_UINT8 PEEK_DISCARD(1) #define PEEK_DISCARD_UINT16 PEEK_DISCARD(2) #define PEEK_DISCARD_UINT32 PEEK_DISCARD(4) -#define PEEK_CMP(value, bytes) \ - (length -= (bytes), \ - pos += (bytes), \ - memcmp(pos-bytes, value, bytes)) +#define PEEK_CMP(value, bytes) \ + (length -= (bytes), pos += (bytes), memcmp(pos - bytes, value, bytes)) #define PEEK_SAVE POKE_SAVE #define PEEK_RESTORE POKE_RESTORE /* LLDP specific. We need a `tlv' pointer. */ -#define POKE_START_LLDP_TLV(type) \ - ( \ - tlv = pos, \ - POKE_UINT16(type << 9) \ - ) -#define POKE_END_LLDP_TLV \ - ( \ - memcpy(&types.f_uint16, tlv, sizeof(uint16_t)), \ - types.f_uint16 |= htons((pos - (tlv + 2)) & 0x01ff), \ - memcpy(tlv, &types.f_uint16, sizeof(uint16_t)), \ - 1 \ - ) +#define POKE_START_LLDP_TLV(type) (tlv = pos, POKE_UINT16(type << 9)) +#define POKE_END_LLDP_TLV \ + (memcpy(&types.f_uint16, tlv, sizeof(uint16_t)), \ + types.f_uint16 |= htons((pos - (tlv + 2)) & 0x01ff), \ + memcpy(tlv, &types.f_uint16, sizeof(uint16_t)), 1) /* Same for CDP */ -#define POKE_START_CDP_TLV(type) \ - ( \ - (void)POKE_UINT16(type), \ - tlv = pos, \ - POKE_UINT16(0) \ - ) -#define POKE_END_CDP_TLV \ - ( \ - types.f_uint16 = htons(pos - tlv + 2), \ - memcpy(tlv, &types.f_uint16, sizeof(uint16_t)), \ - 1 \ - ) +#define POKE_START_CDP_TLV(type) ((void)POKE_UINT16(type), tlv = pos, POKE_UINT16(0)) +#define POKE_END_CDP_TLV \ + (types.f_uint16 = htons(pos - tlv + 2), \ + memcpy(tlv, &types.f_uint16, sizeof(uint16_t)), 1) /* Same for EDP */ -#define POKE_START_EDP_TLV(type) \ - ( \ - (void)POKE_UINT8(EDP_TLV_MARKER), \ - (void)POKE_UINT8(type), \ - tlv = pos, \ - POKE_UINT16(0) \ - ) +#define POKE_START_EDP_TLV(type) \ + ((void)POKE_UINT8(EDP_TLV_MARKER), (void)POKE_UINT8(type), tlv = pos, POKE_UINT16(0)) #define POKE_END_EDP_TLV POKE_END_CDP_TLV #endif /* _FRAME_H */ diff --git a/src/daemon/interfaces-bpf.c b/src/daemon/interfaces-bpf.c index 5237ee75..2091eafb 100644 --- a/src/daemon/interfaces-bpf.c +++ b/src/daemon/interfaces-bpf.c @@ -21,28 +21,25 @@ #include struct bpf_buffer { - size_t len; /* Total length of the buffer */ + size_t len; /* Total length of the buffer */ struct bpf_hdr data[0]; }; int -ifbpf_phys_init(struct lldpd *cfg, - struct lldpd_hardware *hardware) +ifbpf_phys_init(struct lldpd *cfg, struct lldpd_hardware *hardware) { struct bpf_buffer *buffer = NULL; int fd = -1; - log_debug("interfaces", "initialize ethernet device %s", - hardware->h_ifname); + log_debug("interfaces", "initialize ethernet device %s", hardware->h_ifname); if ((fd = priv_iface_init(hardware->h_ifindex, hardware->h_ifname)) == -1) return -1; /* Allocate receive buffer */ - hardware->h_data = buffer = - malloc(ETHER_MAX_LEN + BPF_WORDALIGN(sizeof(struct bpf_hdr)) + sizeof(struct bpf_buffer)); + hardware->h_data = buffer = malloc(ETHER_MAX_LEN + + BPF_WORDALIGN(sizeof(struct bpf_hdr)) + sizeof(struct bpf_buffer)); if (buffer == NULL) { - log_warn("interfaces", - "unable to allocate buffer space for BPF on %s", + log_warn("interfaces", "unable to allocate buffer space for BPF on %s", hardware->h_ifname); goto end; } @@ -67,19 +64,17 @@ end: /* Ethernet send/receive through BPF */ static int -ifbpf_eth_send(struct lldpd *cfg, struct lldpd_hardware *hardware, - char *buffer, size_t size) +ifbpf_eth_send(struct lldpd *cfg, struct lldpd_hardware *hardware, char *buffer, + size_t size) { log_debug("interfaces", "send PDU to ethernet device %s (fd=%d)", hardware->h_ifname, hardware->h_sendfd); - return write(hardware->h_sendfd, - buffer, size); + return write(hardware->h_sendfd, buffer, size); } static int -ifbpf_eth_recv(struct lldpd *cfg, - struct lldpd_hardware *hardware, - int fd, char *buffer, size_t size) +ifbpf_eth_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, int fd, char *buffer, + size_t size) { struct bpf_buffer *bpfbuf = hardware->h_data; struct bpf_hdr *bh; @@ -90,7 +85,8 @@ ifbpf_eth_recv(struct lldpd *cfg, * this is correct. */ if (read(fd, bpfbuf->data, bpfbuf->len) == -1) { if (errno == ENETDOWN) { - log_debug("interfaces", "error while receiving frame on %s (network down)", + log_debug("interfaces", + "error while receiving frame on %s (network down)", hardware->h_ifname); } else { log_warn("interfaces", "error while receiving frame on %s", @@ -99,9 +95,8 @@ ifbpf_eth_recv(struct lldpd *cfg, } return -1; } - bh = (struct bpf_hdr*)bpfbuf->data; - if (bh->bh_caplen < size) - size = bh->bh_caplen; + bh = (struct bpf_hdr *)bpfbuf->data; + if (bh->bh_caplen < size) size = bh->bh_caplen; memcpy(buffer, (char *)bpfbuf->data + bh->bh_hdrlen, size); return size; @@ -110,8 +105,7 @@ ifbpf_eth_recv(struct lldpd *cfg, static int ifbpf_eth_close(struct lldpd *cfg, struct lldpd_hardware *hardware) { - log_debug("interfaces", "close ethernet device %s", - hardware->h_ifname); + log_debug("interfaces", "close ethernet device %s", hardware->h_ifname); interfaces_setup_multicast(cfg, hardware->h_ifname, 1); return 0; } diff --git a/src/daemon/interfaces-bsd.c b/src/daemon/interfaces-bsd.c index d7d9c6c0..35e6f404 100644 --- a/src/daemon/interfaces-bsd.c +++ b/src/daemon/interfaces-bsd.c @@ -29,54 +29,52 @@ #include #include #if defined HOST_OS_FREEBSD -# include -# include -# include +# include +# include +# include #elif defined HOST_OS_DRAGONFLY -# include -# include +# include +# include #elif defined HOST_OS_OPENBSD -# include -# include -# include +# include +# include +# include #elif defined HOST_OS_NETBSD -# include -# include -# include +# include +# include +# include #elif defined HOST_OS_OSX -# include -# include -# include +# include +# include +# include #endif #ifndef IFDESCRSIZE -#define IFDESCRSIZE 64 +# define IFDESCRSIZE 64 #endif static int -ifbsd_check_wireless(struct lldpd *cfg, - struct ifaddrs *ifaddr, +ifbsd_check_wireless(struct lldpd *cfg, struct ifaddrs *ifaddr, struct interfaces_device *iface) { - struct ifmediareq ifmr = {}; - strlcpy(ifmr.ifm_name, iface->name, sizeof(ifmr.ifm_name)); - if (ioctl(cfg->g_sock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0 || - IFM_TYPE(ifmr.ifm_current) != IFM_IEEE80211) - return 0; /* Not wireless either */ - iface->type |= IFACE_WIRELESS_T | IFACE_PHYSICAL_T; - return 0; + struct ifmediareq ifmr = {}; + strlcpy(ifmr.ifm_name, iface->name, sizeof(ifmr.ifm_name)); + if (ioctl(cfg->g_sock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0 || + IFM_TYPE(ifmr.ifm_current) != IFM_IEEE80211) + return 0; /* Not wireless either */ + iface->type |= IFACE_WIRELESS_T | IFACE_PHYSICAL_T; + return 0; } static void -ifbsd_check_bridge(struct lldpd *cfg, - struct interfaces_device_list *interfaces, +ifbsd_check_bridge(struct lldpd *cfg, struct interfaces_device_list *interfaces, struct interfaces_device *master) { static size_t ifbic_len = 64; struct ifbreq *req = NULL; struct ifbifconf bifc = {}; - retry_alloc: +retry_alloc: if ((req = realloc(req, ifbic_len)) == NULL) { log_warn("interfaces", "unable to allocate memory to query bridge %s", master->name); @@ -86,28 +84,25 @@ ifbsd_check_bridge(struct lldpd *cfg, bifc.ifbic_len = ifbic_len; bifc.ifbic_req = req; -#if defined HOST_OS_FREEBSD || defined HOST_OS_NETBSD || defined HOST_OS_OSX || defined HOST_OS_DRAGONFLY - struct ifdrv ifd = { - .ifd_cmd = BRDGGIFS, +#if defined HOST_OS_FREEBSD || defined HOST_OS_NETBSD || defined HOST_OS_OSX || \ + defined HOST_OS_DRAGONFLY + struct ifdrv ifd = { .ifd_cmd = BRDGGIFS, .ifd_len = sizeof(bifc), - .ifd_data = &bifc - }; + .ifd_data = &bifc }; strlcpy(ifd.ifd_name, master->name, sizeof(ifd.ifd_name)); if (ioctl(cfg->g_sock, SIOCGDRVSPEC, (caddr_t)&ifd) < 0) { - log_debug("interfaces", - "%s is not a bridge", master->name); + log_debug("interfaces", "%s is not a bridge", master->name); return; } #elif defined HOST_OS_OPENBSD strlcpy(bifc.ifbic_name, master->name, sizeof(bifc.ifbic_name)); if (ioctl(cfg->g_sock, SIOCBRDGIFS, (caddr_t)&bifc) < 0) { - log_debug("interfaces", - "%s is not a bridge", master->name); + log_debug("interfaces", "%s is not a bridge", master->name); return; } #else -# error Unsupported OS +# error Unsupported OS #endif if (bifc.ifbic_len >= ifbic_len) { ifbic_len = bifc.ifbic_len + 1; @@ -115,77 +110,63 @@ ifbsd_check_bridge(struct lldpd *cfg, } for (int i = 0; i < bifc.ifbic_len / sizeof(*req); i++) { struct interfaces_device *slave = - interfaces_nametointerface(interfaces, - req[i].ifbr_ifsname); + interfaces_nametointerface(interfaces, req[i].ifbr_ifsname); if (slave == NULL) { log_warnx("interfaces", "%s should be bridged to %s but we don't know %s", req[i].ifbr_ifsname, master->name, req[i].ifbr_ifsname); continue; } - log_debug("interfaces", - "%s is bridged to %s", - slave->name, master->name); + log_debug("interfaces", "%s is bridged to %s", slave->name, + master->name); slave->upper = master; } master->type |= IFACE_BRIDGE_T; } static void -ifbsd_check_bond(struct lldpd *cfg, - struct interfaces_device_list *interfaces, +ifbsd_check_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces, struct interfaces_device *master) { #if defined HOST_OS_OPENBSD /* OpenBSD is the same as FreeBSD, just lagg->trunk */ -# define lagg_reqport trunk_reqport -# define lagg_reqall trunk_reqall -# define SIOCGLAGG SIOCGTRUNK -# define LAGG_MAX_PORTS TRUNK_MAX_PORTS +# define lagg_reqport trunk_reqport +# define lagg_reqall trunk_reqall +# define SIOCGLAGG SIOCGTRUNK +# define LAGG_MAX_PORTS TRUNK_MAX_PORTS #endif #if defined HOST_OS_OPENBSD || defined HOST_OS_FREEBSD struct lagg_reqport rpbuf[LAGG_MAX_PORTS]; - struct lagg_reqall ra = { - .ra_size = sizeof(rpbuf), - .ra_port = rpbuf - }; + struct lagg_reqall ra = { .ra_size = sizeof(rpbuf), .ra_port = rpbuf }; strlcpy(ra.ra_ifname, master->name, IFNAMSIZ); if (ioctl(cfg->g_sock, SIOCGLAGG, (caddr_t)&ra) < 0) { - log_debug("interfaces", - "%s is not a bond", master->name); + log_debug("interfaces", "%s is not a bond", master->name); return; } for (int i = 0; i < ra.ra_ports; i++) { struct interfaces_device *slave; - slave = interfaces_nametointerface(interfaces, - rpbuf[i].rp_portname); + slave = interfaces_nametointerface(interfaces, rpbuf[i].rp_portname); if (slave == NULL) { log_warnx("interfaces", "%s should be enslaved to %s but we don't know %s", - rpbuf[i].rp_portname, master->name, - rpbuf[i].rp_portname); + rpbuf[i].rp_portname, master->name, rpbuf[i].rp_portname); continue; } - log_debug("interfaces", - "%s is enslaved to bond %s", - slave->name, master->name); + log_debug("interfaces", "%s is enslaved to bond %s", slave->name, + master->name); slave->upper = master; } master->type |= IFACE_BOND_T; #elif defined HOST_OS_NETBSD /* No max, we consider a maximum of 24 ports */ - char buf[sizeof(struct agrportinfo)*24] = {}; + char buf[sizeof(struct agrportinfo) * 24] = {}; size_t buflen = sizeof(buf); - struct agrreq ar = { - .ar_version = AGRREQ_VERSION, + struct agrreq ar = { .ar_version = AGRREQ_VERSION, .ar_cmd = AGRCMD_PORTLIST, .ar_buf = buf, - .ar_buflen = buflen - }; - struct ifreq ifr = { - .ifr_data = &ar - }; + .ar_buflen = buflen }; + struct ifreq ifr = { .ifr_data = &ar }; struct agrportlist *apl = (void *)buf; struct agrportinfo *api = (void *)(apl + 1); strlcpy(ifr.ifr_name, master->name, sizeof(ifr.ifr_name)); @@ -195,77 +176,66 @@ ifbsd_check_bond(struct lldpd *cfg, "%s is a too big aggregate. Please, report the problem", master->name); } else { - log_debug("interfaces", - "%s is not an aggregate", master->name); + log_debug("interfaces", "%s is not an aggregate", master->name); } return; } for (int i = 0; i < apl->apl_nports; i++, api++) { struct interfaces_device *slave; - slave = interfaces_nametointerface(interfaces, - api->api_ifname); + slave = interfaces_nametointerface(interfaces, api->api_ifname); if (slave == NULL) { log_warnx("interfaces", "%s should be enslaved to %s but we don't know %s", api->api_ifname, master->name, api->api_ifname); continue; } - log_debug("interfaces", - "%s is enslaved to bond %s", - slave->name, master->name); + log_debug("interfaces", "%s is enslaved to bond %s", slave->name, + master->name); slave->upper = master; } master->type |= IFACE_BOND_T; #elif defined HOST_OS_OSX - struct if_bond_req ibr = { - .ibr_op = IF_BOND_OP_GET_STATUS, + struct if_bond_req ibr = { .ibr_op = IF_BOND_OP_GET_STATUS, .ibr_ibru = { - .ibru_status = { .ibsr_version = IF_BOND_STATUS_REQ_VERSION } - } - }; - struct ifreq ifr = { - .ifr_data = (caddr_t)&ibr - }; + .ibru_status = { .ibsr_version = IF_BOND_STATUS_REQ_VERSION } } }; + struct ifreq ifr = { .ifr_data = (caddr_t)&ibr }; strlcpy(ifr.ifr_name, master->name, sizeof(ifr.ifr_name)); if (ioctl(cfg->g_sock, SIOCGIFBOND, (caddr_t)&ifr) < 0) { - log_debug("interfaces", - "%s is not an aggregate", master->name); + log_debug("interfaces", "%s is not an aggregate", master->name); return; } master->type |= IFACE_BOND_T; if (ibr.ibr_ibru.ibru_status.ibsr_total == 0) { - log_debug("interfaces", "no members for bond %s", - master->name); + log_debug("interfaces", "no members for bond %s", master->name); return; } struct if_bond_status_req *ibsr_p = &ibr.ibr_ibru.ibru_status; ibsr_p->ibsr_buffer = - malloc(sizeof(struct if_bond_status)*ibsr_p->ibsr_total); + malloc(sizeof(struct if_bond_status) * ibsr_p->ibsr_total); if (ibsr_p->ibsr_buffer == NULL) { log_warnx("interfaces", "not enough memory to check bond members"); return; } ibsr_p->ibsr_count = ibsr_p->ibsr_total; if (ioctl(cfg->g_sock, SIOCGIFBOND, (caddr_t)&ifr) < 0) { - log_warn("interfaces", - "unable to get members for bond %s", master->name); + log_warn("interfaces", "unable to get members for bond %s", + master->name); goto end; } struct if_bond_status *ibs_p = (struct if_bond_status *)ibsr_p->ibsr_buffer; for (int i = 0; i < ibsr_p->ibsr_total; i++, ibs_p++) { struct interfaces_device *slave; - slave = interfaces_nametointerface(interfaces, - ibs_p->ibs_if_name); + slave = interfaces_nametointerface(interfaces, ibs_p->ibs_if_name); if (slave == NULL) { log_warnx("interfaces", "%s should be enslaved to %s but we don't know %s", ibs_p->ibs_if_name, master->name, ibs_p->ibs_if_name); continue; } - log_debug("interfaces", "%s is enslaved to bond %s", - slave->name, master->name); + log_debug("interfaces", "%s is enslaved to bond %s", slave->name, + master->name); slave->upper = master; } end: @@ -273,67 +243,57 @@ end: #elif defined HOST_OS_DRAGONFLY log_debug("interfaces", "DragonFly BSD does not support link aggregation"); #else -# error Unsupported OS +# error Unsupported OS #endif } static void -ifbsd_check_vlan(struct lldpd *cfg, - struct interfaces_device_list *interfaces, +ifbsd_check_vlan(struct lldpd *cfg, struct interfaces_device_list *interfaces, struct interfaces_device *vlan) { struct interfaces_device *lower; struct vlanreq vreq = {}; - struct ifreq ifr = { - .ifr_data = (caddr_t)&vreq - }; + struct ifreq ifr = { .ifr_data = (caddr_t)&vreq }; strlcpy(ifr.ifr_name, vlan->name, sizeof(ifr.ifr_name)); if (ioctl(cfg->g_sock, SIOCGETVLAN, (caddr_t)&ifr) < 0) { - log_debug("interfaces", - "%s is not a VLAN", vlan->name); + log_debug("interfaces", "%s is not a VLAN", vlan->name); return; } if (strlen(vreq.vlr_parent) == 0) { - log_debug("interfaces", - "%s is a VLAN but has no lower interface", + log_debug("interfaces", "%s is a VLAN but has no lower interface", vlan->name); vlan->lower = NULL; vlan->type |= IFACE_VLAN_T; return; } - lower = interfaces_nametointerface(interfaces, - vreq.vlr_parent); + lower = interfaces_nametointerface(interfaces, vreq.vlr_parent); if (lower == NULL) { log_warnx("interfaces", - "%s should be a VLAN of %s but %s does not exist", - vlan->name, vreq.vlr_parent, vreq.vlr_parent); + "%s should be a VLAN of %s but %s does not exist", vlan->name, + vreq.vlr_parent, vreq.vlr_parent); return; } - log_debug("interfaces", - "%s is VLAN %d of %s", - vlan->name, vreq.vlr_tag, lower->name); + log_debug("interfaces", "%s is VLAN %d of %s", vlan->name, vreq.vlr_tag, + lower->name); vlan->lower = lower; bitmap_set(vlan->vlan_bmap, vreq.vlr_tag); vlan->type |= IFACE_VLAN_T; } static void -ifbsd_check_physical(struct lldpd *cfg, - struct interfaces_device_list *interfaces, +ifbsd_check_physical(struct lldpd *cfg, struct interfaces_device_list *interfaces, struct interfaces_device *iface) { - if (iface->type & (IFACE_VLAN_T| - IFACE_BOND_T|IFACE_BRIDGE_T|IFACE_PHYSICAL_T)) + if (iface->type & + (IFACE_VLAN_T | IFACE_BOND_T | IFACE_BRIDGE_T | IFACE_PHYSICAL_T)) return; - if (!(iface->flags & (IFF_MULTICAST|IFF_BROADCAST))) { - log_debug("interfaces", "skip %s: not able to do multicast nor broadcast", - iface->name); + if (!(iface->flags & (IFF_MULTICAST | IFF_BROADCAST))) { + log_debug("interfaces", + "skip %s: not able to do multicast nor broadcast", iface->name); return; } - log_debug("interfaces", - "%s is a physical interface", - iface->name); + log_debug("interfaces", "%s is a physical interface", iface->name); iface->type |= IFACE_PHYSICAL_T; } @@ -342,18 +302,16 @@ ifbsd_check_physical(struct lldpd *cfg, * See: https://github.com/lldpd/lldpd/issues/61 */ static void -ifbsd_denylist(struct lldpd *cfg, - struct interfaces_device_list *interfaces) +ifbsd_denylist(struct lldpd *cfg, struct interfaces_device_list *interfaces) { #ifdef HOST_OS_OSX struct interfaces_device *iface = NULL; - TAILQ_FOREACH(iface, interfaces, next) { + TAILQ_FOREACH (iface, interfaces, next) { int i; if (strncmp(iface->name, "p2p", 3)) continue; if (strlen(iface->name) < 4) continue; - for (i = 3; - iface->name[i] != '\0' && isdigit(iface->name[i]); - i++); + for (i = 3; iface->name[i] != '\0' && isdigit(iface->name[i]); i++) + ; if (iface->name[i] == '\0') { log_debug("interfaces", "skip %s: AirDrop interface", iface->name); @@ -363,14 +321,13 @@ ifbsd_denylist(struct lldpd *cfg, #endif } -static struct interfaces_device* -ifbsd_extract_device(struct lldpd *cfg, - struct ifaddrs *ifaddr) +static struct interfaces_device * +ifbsd_extract_device(struct lldpd *cfg, struct ifaddrs *ifaddr) { struct interfaces_device *iface = NULL; - struct sockaddr_dl *saddrdl = ALIGNED_CAST(struct sockaddr_dl*, ifaddr->ifa_addr); - if ((saddrdl->sdl_type != IFT_BRIDGE) && - (saddrdl->sdl_type != IFT_L2VLAN) && + struct sockaddr_dl *saddrdl = + ALIGNED_CAST(struct sockaddr_dl *, ifaddr->ifa_addr); + if ((saddrdl->sdl_type != IFT_BRIDGE) && (saddrdl->sdl_type != IFT_L2VLAN) && (saddrdl->sdl_type != IFT_ETHER)) { log_debug("interfaces", "skip %s: not an ethernet device (%d)", ifaddr->ifa_name, saddrdl->sdl_type); @@ -388,31 +345,26 @@ ifbsd_extract_device(struct lldpd *cfg, /* MAC address */ iface->address = malloc(ETHER_ADDR_LEN); - if (iface->address) - memcpy(iface->address, LLADDR(saddrdl), ETHER_ADDR_LEN); + if (iface->address) memcpy(iface->address, LLADDR(saddrdl), ETHER_ADDR_LEN); - /* Grab description */ + /* Grab description */ #ifdef SIOCGIFDESCR -#if defined HOST_OS_FREEBSD || defined HOST_OS_OPENBSD +# if defined HOST_OS_FREEBSD || defined HOST_OS_OPENBSD iface->alias = malloc(IFDESCRSIZE); if (iface->alias) { -#if defined HOST_OS_FREEBSD - struct ifreq ifr = { - .ifr_buffer = { .buffer = iface->alias, - .length = IFDESCRSIZE } - }; -#else - struct ifreq ifr = { - .ifr_data = (caddr_t)iface->alias - }; -#endif +# if defined HOST_OS_FREEBSD + struct ifreq ifr = { .ifr_buffer = { .buffer = iface->alias, + .length = IFDESCRSIZE } }; +# else + struct ifreq ifr = { .ifr_data = (caddr_t)iface->alias }; +# endif strlcpy(ifr.ifr_name, ifaddr->ifa_name, sizeof(ifr.ifr_name)); if (ioctl(cfg->g_sock, SIOCGIFDESCR, (caddr_t)&ifr) < 0) { free(iface->alias); iface->alias = NULL; } } -#endif +# endif #endif /* SIOCGIFDESCR */ if (ifbsd_check_wireless(cfg, ifaddr, iface) == -1) { @@ -424,10 +376,8 @@ ifbsd_extract_device(struct lldpd *cfg, } static void -ifbsd_extract(struct lldpd *cfg, - struct interfaces_device_list *interfaces, - struct interfaces_address_list *addresses, - struct ifaddrs *ifaddr) +ifbsd_extract(struct lldpd *cfg, struct interfaces_device_list *interfaces, + struct interfaces_address_list *addresses, struct ifaddrs *ifaddr) { struct interfaces_address *address = NULL; struct interfaces_device *device = NULL; @@ -435,13 +385,13 @@ ifbsd_extract(struct lldpd *cfg, if (!ifaddr->ifa_addr) return; switch (ifaddr->ifa_addr->sa_family) { case AF_LINK: - log_debug("interfaces", - "grabbing information on interface %s", + log_debug("interfaces", "grabbing information on interface %s", ifaddr->ifa_name); device = ifbsd_extract_device(cfg, ifaddr); if (device) { #if defined HOST_OS_OPENBSD - /* On OpenBSD, the interface can have IFF_RUNNING but be down. */ + /* On OpenBSD, the interface can have IFF_RUNNING but be down. + */ struct if_data *ifdata; ifdata = ifaddr->ifa_data; if (!LINK_STATE_IS_UP(ifdata->ifi_link_state)) @@ -452,9 +402,7 @@ ifbsd_extract(struct lldpd *cfg, break; case AF_INET: case AF_INET6: - log_debug("interfaces", - "got an IP address on %s", - ifaddr->ifa_name); + log_debug("interfaces", "got an IP address on %s", ifaddr->ifa_name); address = malloc(sizeof(struct interfaces_address)); if (address == NULL) { log_warn("interfaces", @@ -464,126 +412,94 @@ ifbsd_extract(struct lldpd *cfg, } address->flags = ifaddr->ifa_flags; address->index = if_nametoindex(ifaddr->ifa_name); - memcpy(&address->address, - ifaddr->ifa_addr, - (ifaddr->ifa_addr->sa_family == AF_INET)? - sizeof(struct sockaddr_in): - sizeof(struct sockaddr_in6)); + memcpy(&address->address, ifaddr->ifa_addr, + (ifaddr->ifa_addr->sa_family == AF_INET) ? + sizeof(struct sockaddr_in) : + sizeof(struct sockaddr_in6)); TAILQ_INSERT_TAIL(addresses, address, next); break; default: - log_debug("interfaces", "unhandled family %d for interface %s", - ifaddr->ifa_addr->sa_family, - ifaddr->ifa_name); + log_debug("interfaces", "unhandled family %d for interface %s", + ifaddr->ifa_addr->sa_family, ifaddr->ifa_name); } } static void -ifbsd_macphy(struct lldpd *cfg, - struct lldpd_hardware *hardware) +ifbsd_macphy(struct lldpd *cfg, struct lldpd_hardware *hardware) { #ifdef ENABLE_DOT3 struct ifmediareq ifmr = {}; -#ifdef HAVE_TYPEOF +# ifdef HAVE_TYPEOF typeof(ifmr.ifm_ulist[0]) media_list[32] = {}; -#else +# else int media_list[32] = {}; -#endif +# endif ifmr.ifm_ulist = media_list; ifmr.ifm_count = 32; struct lldpd_port *port = &hardware->h_lport; unsigned int duplex; unsigned int media; int advertised_ifmedia_to_rfc3636[][3] = { - {IFM_10_T, - LLDP_DOT3_LINK_AUTONEG_10BASE_T, - LLDP_DOT3_LINK_AUTONEG_10BASET_FD}, - {IFM_10_STP, - LLDP_DOT3_LINK_AUTONEG_10BASE_T, - LLDP_DOT3_LINK_AUTONEG_10BASET_FD}, - {IFM_100_TX, - LLDP_DOT3_LINK_AUTONEG_100BASE_TX, - LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD}, - {IFM_100_T4, - LLDP_DOT3_LINK_AUTONEG_100BASE_T4, - LLDP_DOT3_LINK_AUTONEG_100BASE_T4}, - {IFM_100_T2, - LLDP_DOT3_LINK_AUTONEG_100BASE_T2, - LLDP_DOT3_LINK_AUTONEG_100BASE_T2FD}, - {IFM_1000_SX, - LLDP_DOT3_LINK_AUTONEG_1000BASE_X, - LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD}, - {IFM_1000_LX, - LLDP_DOT3_LINK_AUTONEG_1000BASE_X, - LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD}, - {IFM_1000_CX, - LLDP_DOT3_LINK_AUTONEG_1000BASE_X, - LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD}, - {IFM_1000_T, - LLDP_DOT3_LINK_AUTONEG_1000BASE_T, - LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD}, - {0, 0, 0} + { IFM_10_T, LLDP_DOT3_LINK_AUTONEG_10BASE_T, + LLDP_DOT3_LINK_AUTONEG_10BASET_FD }, + { IFM_10_STP, LLDP_DOT3_LINK_AUTONEG_10BASE_T, + LLDP_DOT3_LINK_AUTONEG_10BASET_FD }, + { IFM_100_TX, LLDP_DOT3_LINK_AUTONEG_100BASE_TX, + LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD }, + { IFM_100_T4, LLDP_DOT3_LINK_AUTONEG_100BASE_T4, + LLDP_DOT3_LINK_AUTONEG_100BASE_T4 }, + { IFM_100_T2, LLDP_DOT3_LINK_AUTONEG_100BASE_T2, + LLDP_DOT3_LINK_AUTONEG_100BASE_T2FD }, + { IFM_1000_SX, LLDP_DOT3_LINK_AUTONEG_1000BASE_X, + LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD }, + { IFM_1000_LX, LLDP_DOT3_LINK_AUTONEG_1000BASE_X, + LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD }, + { IFM_1000_CX, LLDP_DOT3_LINK_AUTONEG_1000BASE_X, + LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD }, + { IFM_1000_T, LLDP_DOT3_LINK_AUTONEG_1000BASE_T, + LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD }, + { 0, 0, 0 } }; - int current_ifmedia_to_rfc3636[][3] = { - {IFM_10_T, - LLDP_DOT3_MAU_10BASETHD, LLDP_DOT3_MAU_10BASETFD}, - {IFM_10_STP, - LLDP_DOT3_MAU_10BASETHD, LLDP_DOT3_MAU_10BASETFD}, - {IFM_10_2, - LLDP_DOT3_MAU_10BASE2, LLDP_DOT3_MAU_10BASE2}, - {IFM_10_5, - LLDP_DOT3_MAU_10BASE5, LLDP_DOT3_MAU_10BASE5}, - {IFM_100_TX, - LLDP_DOT3_MAU_100BASETXHD, LLDP_DOT3_MAU_100BASETXFD}, - {IFM_100_FX, - LLDP_DOT3_MAU_100BASEFXHD, LLDP_DOT3_MAU_100BASEFXFD}, - {IFM_100_T2, - LLDP_DOT3_MAU_100BASET2HD, LLDP_DOT3_MAU_100BASET2FD}, - {IFM_1000_SX, - LLDP_DOT3_MAU_1000BASESXHD, LLDP_DOT3_MAU_1000BASESXFD}, - {IFM_10_FL, - LLDP_DOT3_MAU_10BASEFLHD, LLDP_DOT3_MAU_10BASEFLFD }, - {IFM_1000_LX, - LLDP_DOT3_MAU_1000BASELXHD, LLDP_DOT3_MAU_1000BASELXFD}, - {IFM_1000_CX, - LLDP_DOT3_MAU_1000BASECXHD, LLDP_DOT3_MAU_1000BASECXFD}, - {IFM_1000_T, - LLDP_DOT3_MAU_1000BASETHD, LLDP_DOT3_MAU_1000BASETFD }, - {IFM_10G_LR, - LLDP_DOT3_MAU_10GIGBASELR, LLDP_DOT3_MAU_10GIGBASELR}, - {IFM_10G_SR, - LLDP_DOT3_MAU_10GIGBASESR, LLDP_DOT3_MAU_10GIGBASESR}, - {IFM_10G_CX4, - LLDP_DOT3_MAU_10GIGBASELX4, LLDP_DOT3_MAU_10GIGBASELX4}, -#ifdef IFM_10G_T - {IFM_10G_T, - LLDP_DOT3_MAU_10GIGBASECX4, LLDP_DOT3_MAU_10GIGBASECX4}, -#endif -#ifdef IFM_10G_TWINAX - {IFM_10G_TWINAX, - LLDP_DOT3_MAU_10GIGBASECX4, LLDP_DOT3_MAU_10GIGBASECX4}, -#endif -#ifdef IFM_10G_TWINAX_LONG - {IFM_10G_TWINAX_LONG, - LLDP_DOT3_MAU_10GIGBASECX4, LLDP_DOT3_MAU_10GIGBASECX4}, -#endif -#ifdef IFM_10G_LRM - {IFM_10G_LRM, - LLDP_DOT3_MAU_10GIGBASELR, LLDP_DOT3_MAU_10GIGBASELR}, -#endif -#ifdef IFM_10G_SFP_CU - {IFM_10G_SFP_CU, - LLDP_DOT3_MAU_10GIGBASECX4, LLDP_DOT3_MAU_10GIGBASECX4}, -#endif - {0, 0, 0} - }; - - log_debug("interfaces", "get MAC/phy for %s", - hardware->h_ifname); + int current_ifmedia_to_rfc3636[][3] = { { IFM_10_T, LLDP_DOT3_MAU_10BASETHD, + LLDP_DOT3_MAU_10BASETFD }, + { IFM_10_STP, LLDP_DOT3_MAU_10BASETHD, LLDP_DOT3_MAU_10BASETFD }, + { IFM_10_2, LLDP_DOT3_MAU_10BASE2, LLDP_DOT3_MAU_10BASE2 }, + { IFM_10_5, LLDP_DOT3_MAU_10BASE5, LLDP_DOT3_MAU_10BASE5 }, + { IFM_100_TX, LLDP_DOT3_MAU_100BASETXHD, LLDP_DOT3_MAU_100BASETXFD }, + { IFM_100_FX, LLDP_DOT3_MAU_100BASEFXHD, LLDP_DOT3_MAU_100BASEFXFD }, + { IFM_100_T2, LLDP_DOT3_MAU_100BASET2HD, LLDP_DOT3_MAU_100BASET2FD }, + { IFM_1000_SX, LLDP_DOT3_MAU_1000BASESXHD, LLDP_DOT3_MAU_1000BASESXFD }, + { IFM_10_FL, LLDP_DOT3_MAU_10BASEFLHD, LLDP_DOT3_MAU_10BASEFLFD }, + { IFM_1000_LX, LLDP_DOT3_MAU_1000BASELXHD, LLDP_DOT3_MAU_1000BASELXFD }, + { IFM_1000_CX, LLDP_DOT3_MAU_1000BASECXHD, LLDP_DOT3_MAU_1000BASECXFD }, + { IFM_1000_T, LLDP_DOT3_MAU_1000BASETHD, LLDP_DOT3_MAU_1000BASETFD }, + { IFM_10G_LR, LLDP_DOT3_MAU_10GIGBASELR, LLDP_DOT3_MAU_10GIGBASELR }, + { IFM_10G_SR, LLDP_DOT3_MAU_10GIGBASESR, LLDP_DOT3_MAU_10GIGBASESR }, + { IFM_10G_CX4, LLDP_DOT3_MAU_10GIGBASELX4, LLDP_DOT3_MAU_10GIGBASELX4 }, +# ifdef IFM_10G_T + { IFM_10G_T, LLDP_DOT3_MAU_10GIGBASECX4, LLDP_DOT3_MAU_10GIGBASECX4 }, +# endif +# ifdef IFM_10G_TWINAX + { IFM_10G_TWINAX, LLDP_DOT3_MAU_10GIGBASECX4, + LLDP_DOT3_MAU_10GIGBASECX4 }, +# endif +# ifdef IFM_10G_TWINAX_LONG + { IFM_10G_TWINAX_LONG, LLDP_DOT3_MAU_10GIGBASECX4, + LLDP_DOT3_MAU_10GIGBASECX4 }, +# endif +# ifdef IFM_10G_LRM + { IFM_10G_LRM, LLDP_DOT3_MAU_10GIGBASELR, LLDP_DOT3_MAU_10GIGBASELR }, +# endif +# ifdef IFM_10G_SFP_CU + { IFM_10G_SFP_CU, LLDP_DOT3_MAU_10GIGBASECX4, + LLDP_DOT3_MAU_10GIGBASECX4 }, +# endif + { 0, 0, 0 } }; + + log_debug("interfaces", "get MAC/phy for %s", hardware->h_ifname); strlcpy(ifmr.ifm_name, hardware->h_ifname, sizeof(ifmr.ifm_name)); if (ioctl(cfg->g_sock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { - log_debug("interfaces", - "unable to get media information from %s", + log_debug("interfaces", "unable to get media information from %s", hardware->h_ifname); return; } @@ -594,8 +510,7 @@ ifbsd_macphy(struct lldpd *cfg, return; } if ((ifmr.ifm_status & IFM_ACTIVE) == 0) { - log_debug("interfaces", - "interface %s is now down, skip", + log_debug("interfaces", "interface %s is now down, skip", hardware->h_ifname); return; } @@ -604,12 +519,10 @@ ifbsd_macphy(struct lldpd *cfg, hardware->h_ifname); return; } - port->p_macphy.autoneg_support = - port->p_macphy.autoneg_enabled = 0; + port->p_macphy.autoneg_support = port->p_macphy.autoneg_enabled = 0; for (int m = 0; m < ifmr.ifm_count; m++) { media = IFM_SUBTYPE(ifmr.ifm_ulist[m]); - duplex = !!(IFM_OPTIONS(ifmr.ifm_ulist[m]) & - IFM_FDX); + duplex = !!(IFM_OPTIONS(ifmr.ifm_ulist[m]) & IFM_FDX); if (media == IFM_AUTO) { port->p_macphy.autoneg_support = 1; port->p_macphy.autoneg_enabled = @@ -626,8 +539,9 @@ ifbsd_macphy(struct lldpd *cfg, break; } } - if (!found) port->p_macphy.autoneg_advertised |= \ - LLDP_DOT3_LINK_AUTONEG_OTHER; + if (!found) + port->p_macphy.autoneg_advertised |= + LLDP_DOT3_LINK_AUTONEG_OTHER; } port->p_macphy.mau_type = 0; @@ -666,13 +580,11 @@ interfaces_update(struct lldpd *cfg) goto end; } - for (ifaddr = ifaddrs; - ifaddr != NULL; - ifaddr = ifaddr->ifa_next) { + for (ifaddr = ifaddrs; ifaddr != NULL; ifaddr = ifaddr->ifa_next) { ifbsd_extract(cfg, interfaces, addresses, ifaddr); } /* Link interfaces together if needed */ - TAILQ_FOREACH(iface, interfaces, next) { + TAILQ_FOREACH (iface, interfaces, next) { ifbsd_check_bridge(cfg, interfaces, iface); ifbsd_check_bond(cfg, interfaces, iface); ifbsd_check_vlan(cfg, interfaces, iface); @@ -681,8 +593,7 @@ interfaces_update(struct lldpd *cfg) ifbsd_denylist(cfg, interfaces); interfaces_helper_allowlist(cfg, interfaces); - interfaces_helper_physical(cfg, interfaces, - &bpf_ops, ifbpf_phys_init); + interfaces_helper_physical(cfg, interfaces, &bpf_ops, ifbpf_phys_init); #ifdef ENABLE_DOT1 interfaces_helper_vlan(cfg, interfaces); #endif @@ -690,7 +601,7 @@ interfaces_update(struct lldpd *cfg) interfaces_helper_chassis(cfg, interfaces); /* Mac/PHY */ - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { if (!hardware->h_flags) continue; ifbsd_macphy(cfg, hardware); interfaces_helper_promisc(cfg, hardware); @@ -707,13 +618,13 @@ interfaces_update(struct lldpd *cfg) #ifdef ROUTE_MSGFILTER unsigned int rtfilter; rtfilter = ROUTE_FILTER(RTM_IFINFO); - if (setsockopt(s, PF_ROUTE, ROUTE_MSGFILTER, - &rtfilter, sizeof(rtfilter)) == -1) - log_warn("interfaces", "unable to set filter for interface updates"); + if (setsockopt(s, PF_ROUTE, ROUTE_MSGFILTER, &rtfilter, + sizeof(rtfilter)) == -1) + log_warn("interfaces", + "unable to set filter for interface updates"); #endif - if (levent_iface_subscribe(cfg, s) == -1) - close(s); + if (levent_iface_subscribe(cfg, s) == -1) close(s); } end: diff --git a/src/daemon/interfaces-linux.c b/src/daemon/interfaces-linux.c index da0df7f1..792b9893 100644 --- a/src/daemon/interfaces-linux.c +++ b/src/daemon/interfaces-linux.c @@ -23,8 +23,8 @@ #include #include #if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdocumentation" +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdocumentation" #endif #include #include @@ -35,7 +35,7 @@ #include #include #if defined(__clang__) -#pragma clang diagnostic pop +# pragma clang diagnostic pop #endif #define SYSFS_PATH_MAX 256 @@ -47,8 +47,7 @@ iflinux_eth_init(struct lldpd *cfg, struct lldpd_hardware *hardware) { int fd; - log_debug("interfaces", "initialize ethernet device %s", - hardware->h_ifname); + log_debug("interfaces", "initialize ethernet device %s", hardware->h_ifname); if ((fd = priv_iface_init(hardware->h_ifindex, hardware->h_ifname)) == -1) return -1; hardware->h_sendfd = fd; /* Send */ @@ -63,18 +62,16 @@ iflinux_eth_init(struct lldpd *cfg, struct lldpd_hardware *hardware) /* Generic ethernet send/receive */ static int -iflinux_eth_send(struct lldpd *cfg, struct lldpd_hardware *hardware, - char *buffer, size_t size) +iflinux_eth_send(struct lldpd *cfg, struct lldpd_hardware *hardware, char *buffer, + size_t size) { log_debug("interfaces", "send PDU to ethernet device %s (fd=%d)", hardware->h_ifname, hardware->h_sendfd); - return write(hardware->h_sendfd, - buffer, size); + return write(hardware->h_sendfd, buffer, size); } static int -iflinux_generic_recv(struct lldpd_hardware *hardware, - int fd, char *buffer, size_t size, +iflinux_generic_recv(struct lldpd_hardware *hardware, int fd, char *buffer, size_t size, struct sockaddr_ll *from) { int n, retry = 0; @@ -83,33 +80,34 @@ iflinux_generic_recv(struct lldpd_hardware *hardware, retry: fromlen = sizeof(*from); memset(from, 0, fromlen); - if ((n = recvfrom(fd, buffer, size, 0, - (struct sockaddr *)from, - &fromlen)) == -1) { + if ((n = recvfrom(fd, buffer, size, 0, (struct sockaddr *)from, &fromlen)) == + -1) { if (errno == EAGAIN && retry == 0) { - /* There may be an error queued in the socket. Clear it and retry. */ + /* There may be an error queued in the socket. Clear it and + * retry. */ levent_recv_error(fd, hardware->h_ifname); retry++; goto retry; } if (errno == ENETDOWN) { - log_debug("interfaces", "error while receiving frame on %s (network down)", + log_debug("interfaces", + "error while receiving frame on %s (network down)", hardware->h_ifname); } else { - log_warn("interfaces", "error while receiving frame on %s (retry: %d)", + log_warn("interfaces", + "error while receiving frame on %s (retry: %d)", hardware->h_ifname, retry); hardware->h_rx_discarded_cnt++; } return -1; } - if (from->sll_pkttype == PACKET_OUTGOING) - return -1; + if (from->sll_pkttype == PACKET_OUTGOING) return -1; return n; } static int -iflinux_eth_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, - int fd, char *buffer, size_t size) +iflinux_eth_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, int fd, + char *buffer, size_t size) { int n; struct sockaddr_ll from; @@ -124,8 +122,7 @@ iflinux_eth_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, static int iflinux_eth_close(struct lldpd *cfg, struct lldpd_hardware *hardware) { - log_debug("interfaces", "close ethernet device %s", - hardware->h_ifname); + log_debug("interfaces", "close ethernet device %s", hardware->h_ifname); interfaces_setup_multicast(cfg, hardware->h_ifname, 1); return 0; } @@ -137,8 +134,7 @@ static struct lldpd_ops eth_ops = { }; static int -iflinux_is_bridge(struct lldpd *cfg, - struct interfaces_device_list *interfaces, +iflinux_is_bridge(struct lldpd *cfg, struct interfaces_device_list *interfaces, struct interfaces_device *iface) { #ifdef ENABLE_OLDIES @@ -146,26 +142,22 @@ iflinux_is_bridge(struct lldpd *cfg, char path[SYSFS_PATH_MAX]; int f; - if ((snprintf(path, SYSFS_PATH_MAX, - SYSFS_CLASS_NET "%s/" SYSFS_BRIDGE_FDB, - iface->name)) >= SYSFS_PATH_MAX) + if ((snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/" SYSFS_BRIDGE_FDB, + iface->name)) >= SYSFS_PATH_MAX) log_warnx("interfaces", "path truncated"); - if ((f = priv_open(path)) < 0) - return 0; + if ((f = priv_open(path)) < 0) return 0; close(f); /* Also grab all ports */ - TAILQ_FOREACH(port, interfaces, next) { + TAILQ_FOREACH (port, interfaces, next) { if (port->upper) continue; if (snprintf(path, SYSFS_PATH_MAX, SYSFS_CLASS_NET "%s/" SYSFS_BRIDGE_PORT_SUBDIR "/%s/port_no", iface->name, port->name) >= SYSFS_PATH_MAX) log_warnx("interfaces", "path truncated"); - if ((f = priv_open(path)) < 0) - continue; - log_debug("interfaces", - "port %s is bridged to %s", - port->name, iface->name); + if ((f = priv_open(path)) < 0) continue; + log_debug("interfaces", "port %s is bridged to %s", port->name, + iface->name); port->upper = iface; close(f); } @@ -177,8 +169,7 @@ iflinux_is_bridge(struct lldpd *cfg, } static int -iflinux_is_vlan(struct lldpd *cfg, - struct interfaces_device_list *interfaces, +iflinux_is_vlan(struct lldpd *cfg, struct interfaces_device_list *interfaces, struct interfaces_device *iface) { #ifdef ENABLE_OLDIES @@ -191,8 +182,7 @@ iflinux_is_vlan(struct lldpd *cfg, interfaces_nametointerface(interfaces, ifv.u.device2); if (!lower) { log_debug("interfaces", - "unable to find lower interface for VLAN %s", - iface->name); + "unable to find lower interface for VLAN %s", iface->name); return 0; } @@ -200,8 +190,7 @@ iflinux_is_vlan(struct lldpd *cfg, ifv.cmd = GET_VLAN_VID_CMD; strlcpy(ifv.device1, iface->name, sizeof(ifv.device1)); if (ioctl(cfg->g_sock, SIOCGIFVLAN, &ifv) < 0) { - log_debug("interfaces", - "unable to find VID for VLAN %s", + log_debug("interfaces", "unable to find VID for VLAN %s", iface->name); return 0; } @@ -215,8 +204,7 @@ iflinux_is_vlan(struct lldpd *cfg, } static int -iflinux_is_bond(struct lldpd *cfg, - struct interfaces_device_list *interfaces, +iflinux_is_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces, struct interfaces_device *master) { #ifdef ENABLE_OLDIES @@ -245,8 +233,8 @@ iflinux_is_bond(struct lldpd *cfg, if (slave == NULL) continue; if (slave->upper) continue; log_debug("interfaces", - "interface %s is enslaved to %s", - slave->name, master->name); + "interface %s is enslaved to %s", slave->name, + master->name); slave->upper = master; } } @@ -263,12 +251,12 @@ iflinux_is_bond(struct lldpd *cfg, */ static int iflinux_get_permanent_mac_ethtool(struct lldpd *cfg, - struct interfaces_device_list *interfaces, - struct interfaces_device *iface) + struct interfaces_device_list *interfaces, struct interfaces_device *iface) { int ret = -1; struct ifreq ifr = {}; - struct ethtool_perm_addr *epaddr = calloc(sizeof(struct ethtool_perm_addr) + ETHER_ADDR_LEN, 1); + struct ethtool_perm_addr *epaddr = + calloc(sizeof(struct ethtool_perm_addr) + ETHER_ADDR_LEN, 1); if (epaddr == NULL) goto end; strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name)); @@ -285,22 +273,18 @@ iflinux_get_permanent_mac_ethtool(struct lldpd *cfg, goto end; } if (errno != EPERM) - log_warn("interfaces", "cannot get permanent MAC address for %s", - iface->name); + log_warn("interfaces", + "cannot get permanent MAC address for %s", iface->name); goto end; } - if (epaddr->data[0] != 0 || - epaddr->data[1] != 0 || - epaddr->data[2] != 0 || - epaddr->data[3] != 0 || - epaddr->data[4] != 0 || - epaddr->data[5] != 0) { + if (epaddr->data[0] != 0 || epaddr->data[1] != 0 || epaddr->data[2] != 0 || + epaddr->data[3] != 0 || epaddr->data[4] != 0 || epaddr->data[5] != 0) { memcpy(iface->address, epaddr->data, ETHER_ADDR_LEN); ret = 0; goto end; } log_debug("interfaces", "cannot get permanent MAC for %s (all 0)", iface->name); - end: +end: free(epaddr); return ret; } @@ -310,8 +294,7 @@ iflinux_get_permanent_mac_ethtool(struct lldpd *cfg, */ static void iflinux_get_permanent_mac_bond(struct lldpd *cfg, - struct interfaces_device_list *interfaces, - struct interfaces_device *iface) + struct interfaces_device_list *interfaces, struct interfaces_device *iface) { struct interfaces_device *master = iface->upper; int f, state = 0; @@ -323,8 +306,8 @@ iflinux_get_permanent_mac_bond(struct lldpd *cfg, char line[100]; /* We have a bond, we need to query it to get real MAC addresses */ - if (snprintf(path, SYSFS_PATH_MAX, "/proc/net/bonding/%s", - master->name) >= SYSFS_PATH_MAX) { + if (snprintf(path, SYSFS_PATH_MAX, "/proc/net/bonding/%s", master->name) >= + SYSFS_PATH_MAX) { log_warnx("interfaces", "path truncated"); return; } @@ -337,8 +320,7 @@ iflinux_get_permanent_mac_bond(struct lldpd *cfg, f = priv_open(path); } if (f < 0) { - log_warnx("interfaces", - "unable to get permanent MAC address for %s", + log_warnx("interfaces", "unable to get permanent MAC address for %s", iface->name); return; } @@ -358,29 +340,26 @@ iflinux_get_permanent_mac_bond(struct lldpd *cfg, switch (state) { case 0: if (strncmp(line, slaveif, strlen(slaveif)) == 0) { - if (line[strlen(line)-1] == '\n') - line[strlen(line)-1] = '\0'; - if (strcmp(iface->name, - line + strlen(slaveif)) == 0) + if (line[strlen(line) - 1] == '\n') + line[strlen(line) - 1] = '\0'; + if (strcmp(iface->name, line + strlen(slaveif)) == 0) state++; } break; case 1: if (strncmp(line, hwaddr, strlen(hwaddr)) == 0) { - if (line[strlen(line)-1] == '\n') - line[strlen(line)-1] = '\0'; + if (line[strlen(line) - 1] == '\n') + line[strlen(line) - 1] = '\0'; if (sscanf(line + strlen(hwaddr), "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", - &mac[0], &mac[1], &mac[2], - &mac[3], &mac[4], &mac[5]) != - ETHER_ADDR_LEN) { + &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], + &mac[5]) != ETHER_ADDR_LEN) { log_warn("interfaces", "unable to parse %s", line + strlen(hwaddr)); fclose(netbond); return; } - memcpy(iface->address, mac, - ETHER_ADDR_LEN); + memcpy(iface->address, mac, ETHER_ADDR_LEN); fclose(netbond); return; } @@ -396,14 +375,12 @@ iflinux_get_permanent_mac_bond(struct lldpd *cfg, * Get permanent MAC. */ static void -iflinux_get_permanent_mac(struct lldpd *cfg, - struct interfaces_device_list *interfaces, +iflinux_get_permanent_mac(struct lldpd *cfg, struct interfaces_device_list *interfaces, struct interfaces_device *iface) { struct interfaces_device *master = iface->upper; - if (master == NULL || master->type != IFACE_BOND_T) - return; + if (master == NULL || master->type != IFACE_BOND_T) return; if (iflinux_get_permanent_mac_ethtool(cfg, interfaces, iface) == -1 && (master->driver == NULL || !strcmp(master->driver, "bonding"))) /* Fallback to old method for a bond */ @@ -411,9 +388,9 @@ iflinux_get_permanent_mac(struct lldpd *cfg, } #ifdef ENABLE_DOT3 -#define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX) -#define ETHTOOL_DECLARE_LINK_MODE_MASK(name) \ - uint32_t name[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32] +# define ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 (SCHAR_MAX) +# define ETHTOOL_DECLARE_LINK_MODE_MASK(name) \ + uint32_t name[ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32] struct ethtool_link_usettings { struct ethtool_link_settings base; @@ -427,32 +404,29 @@ struct ethtool_link_usettings { static int iflinux_ethtool_link_mode_test_bit(unsigned int nr, const uint32_t *mask) { - if (nr >= 32 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32) - return 0; + if (nr >= 32 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32) return 0; return !!(mask[nr / 32] & (1 << (nr % 32))); } static void iflinux_ethtool_link_mode_unset_bit(unsigned int nr, uint32_t *mask) { - if (nr >= 32 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32) - return; + if (nr >= 32 * ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32) return; mask[nr / 32] &= ~(1 << (nr % 32)); } static int iflinux_ethtool_link_mode_is_empty(const uint32_t *mask) { - for (unsigned int i = 0; - i < ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32; - ++i) { - if (mask[i] != 0) - return 0; + for (unsigned int i = 0; i < ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32; ++i) { + if (mask[i] != 0) return 0; } return 1; } static int -iflinux_ethtool_glink(struct lldpd *cfg, const char *ifname, struct ethtool_link_usettings *uset) { +iflinux_ethtool_glink(struct lldpd *cfg, const char *ifname, + struct ethtool_link_usettings *uset) +{ int rc; /* Try with ETHTOOL_GLINKSETTINGS first */ @@ -472,7 +446,8 @@ iflinux_ethtool_glink(struct lldpd *cfg, const char *ifname, struct ethtool_link rc = ioctl(cfg->g_sock, SIOCETHTOOL, &ifr); if (rc == 0) { nwords = -ecmd.req.link_mode_masks_nwords; - log_debug("interfaces", "glinksettings nwords is %" PRId8, nwords); + log_debug("interfaces", "glinksettings nwords is %" PRId8, + nwords); } else { static int once = 0; if (errno == EPERM && !once) { @@ -492,8 +467,8 @@ iflinux_ethtool_glink(struct lldpd *cfg, const char *ifname, struct ethtool_link ifr.ifr_data = (caddr_t)&ecmd; rc = ioctl(cfg->g_sock, SIOCETHTOOL, &ifr); if (rc == 0) { - log_debug("interfaces", "got ethtool results for %s with GLINKSETTINGS", - ifname); + log_debug("interfaces", + "got ethtool results for %s with GLINKSETTINGS", ifname); memcpy(&uset->base, &ecmd.req, sizeof(uset->base)); unsigned int u32_offs = 0; memcpy(uset->link_modes.supported, @@ -519,8 +494,7 @@ iflinux_ethtool_glink(struct lldpd *cfg, const char *ifname, struct ethtool_link rc = ioctl(cfg->g_sock, SIOCETHTOOL, &ifr); if (rc == 0) { /* Do a partial copy (only what we need) */ - log_debug("interfaces", "got ethtool results for %s with GSET", - ifname); + log_debug("interfaces", "got ethtool results for %s with GSET", ifname); memset(uset, 0, sizeof(*uset)); uset->base.cmd = ETHTOOL_GSET; uset->base.link_mode_masks_nwords = 1; @@ -553,71 +527,102 @@ iflinux_macphy(struct lldpd *cfg, struct lldpd_hardware *hardware) struct lldpd_port *port = &hardware->h_lport; int j; int advertised_ethtool_to_rfc3636[][2] = { - {ETHTOOL_LINK_MODE_10baseT_Half_BIT, LLDP_DOT3_LINK_AUTONEG_10BASE_T}, - {ETHTOOL_LINK_MODE_10baseT_Full_BIT, LLDP_DOT3_LINK_AUTONEG_10BASET_FD}, - {ETHTOOL_LINK_MODE_100baseT_Half_BIT, LLDP_DOT3_LINK_AUTONEG_100BASE_TX}, - {ETHTOOL_LINK_MODE_100baseT_Full_BIT, LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD}, - {ETHTOOL_LINK_MODE_1000baseT_Half_BIT, LLDP_DOT3_LINK_AUTONEG_1000BASE_T}, - {ETHTOOL_LINK_MODE_1000baseT_Full_BIT, LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD}, - {ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD}, - {ETHTOOL_LINK_MODE_Pause_BIT, LLDP_DOT3_LINK_AUTONEG_FDX_PAUSE}, - {ETHTOOL_LINK_MODE_Asym_Pause_BIT, LLDP_DOT3_LINK_AUTONEG_FDX_APAUSE}, - {-1, 0}}; + { ETHTOOL_LINK_MODE_10baseT_Half_BIT, LLDP_DOT3_LINK_AUTONEG_10BASE_T }, + { ETHTOOL_LINK_MODE_10baseT_Full_BIT, + LLDP_DOT3_LINK_AUTONEG_10BASET_FD }, + { ETHTOOL_LINK_MODE_100baseT_Half_BIT, + LLDP_DOT3_LINK_AUTONEG_100BASE_TX }, + { ETHTOOL_LINK_MODE_100baseT_Full_BIT, + LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD }, + { ETHTOOL_LINK_MODE_1000baseT_Half_BIT, + LLDP_DOT3_LINK_AUTONEG_1000BASE_T }, + { ETHTOOL_LINK_MODE_1000baseT_Full_BIT, + LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD }, + { ETHTOOL_LINK_MODE_1000baseKX_Full_BIT, + LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD }, + { ETHTOOL_LINK_MODE_Pause_BIT, LLDP_DOT3_LINK_AUTONEG_FDX_PAUSE }, + { ETHTOOL_LINK_MODE_Asym_Pause_BIT, LLDP_DOT3_LINK_AUTONEG_FDX_APAUSE }, + { -1, 0 } + }; log_debug("interfaces", "ask ethtool for the appropriate MAC/PHY for %s", hardware->h_ifname); if (iflinux_ethtool_glink(cfg, hardware->h_ifname, &uset) == 0) { - port->p_macphy.autoneg_support = iflinux_ethtool_link_mode_test_bit( - ETHTOOL_LINK_MODE_Autoneg_BIT, uset.link_modes.supported); - port->p_macphy.autoneg_enabled = (uset.base.autoneg == AUTONEG_DISABLE) ? 0 : 1; - for (j=0; advertised_ethtool_to_rfc3636[j][0] >= 0; j++) { + port->p_macphy.autoneg_support = + iflinux_ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, + uset.link_modes.supported); + port->p_macphy.autoneg_enabled = + (uset.base.autoneg == AUTONEG_DISABLE) ? 0 : 1; + for (j = 0; advertised_ethtool_to_rfc3636[j][0] >= 0; j++) { if (iflinux_ethtool_link_mode_test_bit( - advertised_ethtool_to_rfc3636[j][0], - uset.link_modes.advertising)) { + advertised_ethtool_to_rfc3636[j][0], + uset.link_modes.advertising)) { port->p_macphy.autoneg_advertised |= advertised_ethtool_to_rfc3636[j][1]; iflinux_ethtool_link_mode_unset_bit( - advertised_ethtool_to_rfc3636[j][0], - uset.link_modes.advertising); + advertised_ethtool_to_rfc3636[j][0], + uset.link_modes.advertising); } } - iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, uset.link_modes.advertising); - iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_TP_BIT, uset.link_modes.advertising); - iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_AUI_BIT, uset.link_modes.advertising); - iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_MII_BIT, uset.link_modes.advertising); - iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, uset.link_modes.advertising); - iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_BNC_BIT, uset.link_modes.advertising); - iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Pause_BIT, uset.link_modes.advertising); - iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, uset.link_modes.advertising); - iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Backplane_BIT, uset.link_modes.advertising); + iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, + uset.link_modes.advertising); + iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_TP_BIT, + uset.link_modes.advertising); + iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_AUI_BIT, + uset.link_modes.advertising); + iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_MII_BIT, + uset.link_modes.advertising); + iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, + uset.link_modes.advertising); + iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_BNC_BIT, + uset.link_modes.advertising); + iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Pause_BIT, + uset.link_modes.advertising); + iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, + uset.link_modes.advertising); + iflinux_ethtool_link_mode_unset_bit(ETHTOOL_LINK_MODE_Backplane_BIT, + uset.link_modes.advertising); if (!iflinux_ethtool_link_mode_is_empty(uset.link_modes.advertising)) { - port->p_macphy.autoneg_advertised |= LLDP_DOT3_LINK_AUTONEG_OTHER; + port->p_macphy.autoneg_advertised |= + LLDP_DOT3_LINK_AUTONEG_OTHER; } switch (uset.base.speed) { case SPEED_10: - port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ? \ - LLDP_DOT3_MAU_10BASETFD : LLDP_DOT3_MAU_10BASETHD; - if (uset.base.port == PORT_BNC) port->p_macphy.mau_type = LLDP_DOT3_MAU_10BASE2; + port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ? + LLDP_DOT3_MAU_10BASETFD : + LLDP_DOT3_MAU_10BASETHD; + if (uset.base.port == PORT_BNC) + port->p_macphy.mau_type = LLDP_DOT3_MAU_10BASE2; if (uset.base.port == PORT_FIBRE) - port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ? \ - LLDP_DOT3_MAU_10BASEFLFD : LLDP_DOT3_MAU_10BASEFLHD; + port->p_macphy.mau_type = + (uset.base.duplex == DUPLEX_FULL) ? + LLDP_DOT3_MAU_10BASEFLFD : + LLDP_DOT3_MAU_10BASEFLHD; break; case SPEED_100: - port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ? \ - LLDP_DOT3_MAU_100BASETXFD : LLDP_DOT3_MAU_100BASETXHD; + port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ? + LLDP_DOT3_MAU_100BASETXFD : + LLDP_DOT3_MAU_100BASETXHD; if (uset.base.port == PORT_BNC) - port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ? \ - LLDP_DOT3_MAU_100BASET2FD : LLDP_DOT3_MAU_100BASET2HD; + port->p_macphy.mau_type = + (uset.base.duplex == DUPLEX_FULL) ? + LLDP_DOT3_MAU_100BASET2FD : + LLDP_DOT3_MAU_100BASET2HD; if (uset.base.port == PORT_FIBRE) - port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ? \ - LLDP_DOT3_MAU_100BASEFXFD : LLDP_DOT3_MAU_100BASEFXHD; + port->p_macphy.mau_type = + (uset.base.duplex == DUPLEX_FULL) ? + LLDP_DOT3_MAU_100BASEFXFD : + LLDP_DOT3_MAU_100BASEFXHD; break; case SPEED_1000: - port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ? \ - LLDP_DOT3_MAU_1000BASETFD : LLDP_DOT3_MAU_1000BASETHD; + port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ? + LLDP_DOT3_MAU_1000BASETFD : + LLDP_DOT3_MAU_1000BASETHD; if (uset.base.port == PORT_FIBRE) - port->p_macphy.mau_type = (uset.base.duplex == DUPLEX_FULL) ? \ - LLDP_DOT3_MAU_1000BASEXFD : LLDP_DOT3_MAU_1000BASEXHD; + port->p_macphy.mau_type = + (uset.base.duplex == DUPLEX_FULL) ? + LLDP_DOT3_MAU_1000BASEXFD : + LLDP_DOT3_MAU_1000BASEXHD; break; case SPEED_2500: port->p_macphy.mau_type = LLDP_DOT3_MAU_2P5GIGT; @@ -629,11 +634,9 @@ iflinux_macphy(struct lldpd *cfg, struct lldpd_hardware *hardware) // Distinguish between RJ45 BaseT, DAC BaseCX4, or Fibre BaseLR if (uset.base.port == PORT_TP) { port->p_macphy.mau_type = LLDP_DOT3_MAU_10GBASET; - } - else if (uset.base.port == PORT_FIBRE) { + } else if (uset.base.port == PORT_FIBRE) { port->p_macphy.mau_type = LLDP_DOT3_MAU_10GIGBASELR; - } - else if (uset.base.port == PORT_DA) { + } else if (uset.base.port == PORT_DA) { port->p_macphy.mau_type = LLDP_DOT3_MAU_10GIGBASECX4; } break; @@ -641,45 +644,46 @@ iflinux_macphy(struct lldpd *cfg, struct lldpd_hardware *hardware) // Distinguish between RJ45 BaseT, DAC BaseCR, or Fibre BaseLR if (uset.base.port == PORT_TP) { port->p_macphy.mau_type = LLDP_DOT3_MAU_25GBASET; - } - else if (uset.base.port == PORT_FIBRE) { + } else if (uset.base.port == PORT_FIBRE) { port->p_macphy.mau_type = LLDP_DOT3_MAU_25GBASELR; - } - else if (uset.base.port == PORT_DA) { + } else if (uset.base.port == PORT_DA) { port->p_macphy.mau_type = LLDP_DOT3_MAU_25GBASECR; } break; case SPEED_40000: // Same kind of approximation. - port->p_macphy.mau_type = (uset.base.port == PORT_FIBRE) ? \ - LLDP_DOT3_MAU_40GBASELR4 : LLDP_DOT3_MAU_40GBASECR4; + port->p_macphy.mau_type = (uset.base.port == PORT_FIBRE) ? + LLDP_DOT3_MAU_40GBASELR4 : + LLDP_DOT3_MAU_40GBASECR4; break; case SPEED_50000: // Same kind of approximation. - port->p_macphy.mau_type = (uset.base.port == PORT_FIBRE) ? \ - LLDP_DOT3_MAU_50GBASELR : LLDP_DOT3_MAU_50GBASECR; + port->p_macphy.mau_type = (uset.base.port == PORT_FIBRE) ? + LLDP_DOT3_MAU_50GBASELR : + LLDP_DOT3_MAU_50GBASECR; break; case SPEED_100000: // Ditto - port->p_macphy.mau_type = (uset.base.port == PORT_FIBRE) ? \ - LLDP_DOT3_MAU_100GBASELR4 : LLDP_DOT3_MAU_100GBASECR4; + port->p_macphy.mau_type = (uset.base.port == PORT_FIBRE) ? + LLDP_DOT3_MAU_100GBASELR4 : + LLDP_DOT3_MAU_100GBASECR4; break; } - if (uset.base.port == PORT_AUI) port->p_macphy.mau_type = LLDP_DOT3_MAU_AUI; + if (uset.base.port == PORT_AUI) + port->p_macphy.mau_type = LLDP_DOT3_MAU_AUI; } } -#else /* ENABLE_DOT3 */ +#else /* ENABLE_DOT3 */ static void iflinux_macphy(struct lldpd *cfg, struct lldpd_hardware *hardware) { } #endif /* ENABLE_DOT3 */ - #ifdef ENABLE_OLDIES struct bond_master { char name[IFNAMSIZ]; - int index; + int index; }; static int @@ -691,12 +695,10 @@ iface_bond_init(struct lldpd *cfg, struct lldpd_hardware *hardware) if (!master) return -1; - log_debug("interfaces", "initialize enslaved device %s", - hardware->h_ifname); + log_debug("interfaces", "initialize enslaved device %s", hardware->h_ifname); /* First, we get a socket to the raw physical interface */ - if ((fd = priv_iface_init(hardware->h_ifindex, - hardware->h_ifname)) == -1) + if ((fd = priv_iface_init(hardware->h_ifindex, hardware->h_ifname)) == -1) return -1; hardware->h_sendfd = fd; interfaces_setup_multicast(cfg, hardware->h_ifname, 0); @@ -712,9 +714,9 @@ iface_bond_init(struct lldpd *cfg, struct lldpd_hardware *hardware) * to bond device. We use setsockopt() PACKET_ORIGDEV to get * physical device instead of bond device (works with >= * 2.6.24). */ - if (setsockopt(fd, SOL_PACKET, - PACKET_ORIGDEV, &un, sizeof(un)) == -1) { - log_info("interfaces", "unable to setsockopt for master bonding device of %s. " + if (setsockopt(fd, SOL_PACKET, PACKET_ORIGDEV, &un, sizeof(un)) == -1) { + log_info("interfaces", + "unable to setsockopt for master bonding device of %s. " "You will get inaccurate results", hardware->h_ifname); } @@ -723,15 +725,13 @@ iface_bond_init(struct lldpd *cfg, struct lldpd_hardware *hardware) levent_hardware_add_fd(hardware, hardware->h_sendfd); levent_hardware_add_fd(hardware, fd); log_debug("interfaces", "interface %s initialized (fd=%d,master=%s[%d])", - hardware->h_ifname, - hardware->h_sendfd, - master->name, fd); + hardware->h_ifname, hardware->h_sendfd, master->name, fd); return 0; } static int -iface_bond_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, - int fd, char *buffer, size_t size) +iface_bond_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, int fd, + char *buffer, size_t size) { int n; struct sockaddr_ll from; @@ -741,29 +741,27 @@ iface_bond_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, hardware->h_ifname); if ((n = iflinux_generic_recv(hardware, fd, buffer, size, &from)) == -1) return -1; - if (fd == hardware->h_sendfd) - /* We received this on the physical interface. */ + if (fd == hardware->h_sendfd) /* We received this on the physical interface. */ return n; /* We received this on the bonding interface. Is it really for us? */ - if (from.sll_ifindex == hardware->h_ifindex) - /* This is for us */ + if (from.sll_ifindex == hardware->h_ifindex) /* This is for us */ return n; if (from.sll_ifindex == master->index) /* We don't know from which physical interface it comes (kernel * < 2.6.24). In doubt, this is for us. */ return n; - return -1; /* Not for us */ + return -1; /* Not for us */ } static int iface_bond_close(struct lldpd *cfg, struct lldpd_hardware *hardware) { struct bond_master *master = hardware->h_data; - log_debug("interfaces", "closing enslaved device %s", - hardware->h_ifname); + log_debug("interfaces", "closing enslaved device %s", hardware->h_ifname); interfaces_setup_multicast(cfg, hardware->h_ifname, 1); interfaces_setup_multicast(cfg, master->name, 1); - free(hardware->h_data); hardware->h_data = NULL; + free(hardware->h_data); + hardware->h_data = NULL; return 0; } @@ -781,23 +779,22 @@ iflinux_handle_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces struct lldpd_hardware *hardware; struct bond_master *bmaster; int created; - TAILQ_FOREACH(iface, interfaces, next) { + TAILQ_FOREACH (iface, interfaces, next) { if (!(iface->type & IFACE_PHYSICAL_T)) continue; if (iface->ignore) continue; if (!iface->upper || !(iface->upper->type & IFACE_BOND_T)) continue; master = iface->upper; - log_debug("interfaces", "%s is an acceptable enslaved device (master=%s)", - iface->name, master->name); + log_debug("interfaces", + "%s is an acceptable enslaved device (master=%s)", iface->name, + master->name); created = 0; - if ((hardware = lldpd_get_hardware(cfg, - iface->name, - iface->index)) == NULL) { - if ((hardware = lldpd_alloc_hardware(cfg, - iface->name, - iface->index)) == NULL) { - log_warnx("interfaces", "Unable to allocate space for %s", - iface->name); + if ((hardware = lldpd_get_hardware(cfg, iface->name, iface->index)) == + NULL) { + if ((hardware = lldpd_alloc_hardware(cfg, iface->name, + iface->index)) == NULL) { + log_warnx("interfaces", + "Unable to allocate space for %s", iface->name); continue; } created = 1; @@ -813,13 +810,15 @@ iflinux_handle_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces levent_hardware_release(hardware); levent_hardware_init(hardware); } - bmaster = hardware->h_data = calloc(1, sizeof(struct bond_master)); + bmaster = hardware->h_data = + calloc(1, sizeof(struct bond_master)); if (!bmaster) { log_warn("interfaces", "not enough memory"); lldpd_hardware_cleanup(cfg, hardware); continue; } - } else bmaster = hardware->h_data; + } else + bmaster = hardware->h_data; bmaster->index = master->index; strlcpy(bmaster->name, master->name, IFNAMSIZ); if (hardware->h_ops != &bond_ops || hardware->h_ifindex_changed) { @@ -847,9 +846,9 @@ iflinux_handle_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces interfaces_helper_port_name_desc(cfg, hardware, iface); /* Fill additional info */ -#ifdef ENABLE_DOT3 +# ifdef ENABLE_DOT3 hardware->h_lport.p_aggregid = master->index; -#endif +# endif hardware->h_mtu = iface->mtu ? iface->mtu : 1500; } } @@ -857,40 +856,33 @@ iflinux_handle_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces /* Query each interface to get the appropriate driver */ static void -iflinux_add_driver(struct lldpd *cfg, - struct interfaces_device_list *interfaces) +iflinux_add_driver(struct lldpd *cfg, struct interfaces_device_list *interfaces) { struct interfaces_device *iface; - TAILQ_FOREACH(iface, interfaces, next) { - struct ethtool_drvinfo ethc = { - .cmd = ETHTOOL_GDRVINFO - }; - struct ifreq ifr = { - .ifr_data = (caddr_t)ðc - }; + TAILQ_FOREACH (iface, interfaces, next) { + struct ethtool_drvinfo ethc = { .cmd = ETHTOOL_GDRVINFO }; + struct ifreq ifr = { .ifr_data = (caddr_t)ðc }; if (iface->driver) continue; strlcpy(ifr.ifr_name, iface->name, IFNAMSIZ); if (ioctl(cfg->g_sock, SIOCETHTOOL, &ifr) == 0) { iface->driver = strdup(ethc.driver); - log_debug("interfaces", "driver for %s is `%s`", - iface->name, iface->driver); + log_debug("interfaces", "driver for %s is `%s`", iface->name, + iface->driver); } } } /* Query each interface to see if it is a wireless one */ static void -iflinux_add_wireless(struct lldpd *cfg, - struct interfaces_device_list *interfaces) +iflinux_add_wireless(struct lldpd *cfg, struct interfaces_device_list *interfaces) { struct interfaces_device *iface; - TAILQ_FOREACH(iface, interfaces, next) { + TAILQ_FOREACH (iface, interfaces, next) { struct iwreq iwr = {}; strlcpy(iwr.ifr_name, iface->name, IFNAMSIZ); if (ioctl(cfg->g_sock, SIOCGIWNAME, &iwr) >= 0) { - log_debug("interfaces", "%s is wireless", - iface->name); + log_debug("interfaces", "%s is wireless", iface->name); iface->type |= IFACE_WIRELESS_T | IFACE_PHYSICAL_T; } } @@ -898,18 +890,16 @@ iflinux_add_wireless(struct lldpd *cfg, /* Query each interface to see if it is a bridge */ static void -iflinux_add_bridge(struct lldpd *cfg, - struct interfaces_device_list *interfaces) +iflinux_add_bridge(struct lldpd *cfg, struct interfaces_device_list *interfaces) { struct interfaces_device *iface; - TAILQ_FOREACH(iface, interfaces, next) { - if (iface->type & (IFACE_PHYSICAL_T| - IFACE_VLAN_T|IFACE_BOND_T|IFACE_BRIDGE_T)) + TAILQ_FOREACH (iface, interfaces, next) { + if (iface->type & + (IFACE_PHYSICAL_T | IFACE_VLAN_T | IFACE_BOND_T | IFACE_BRIDGE_T)) continue; if (iflinux_is_bridge(cfg, interfaces, iface)) { - log_debug("interfaces", - "interface %s is a bridge", + log_debug("interfaces", "interface %s is a bridge", iface->name); iface->type |= IFACE_BRIDGE_T; } @@ -918,19 +908,16 @@ iflinux_add_bridge(struct lldpd *cfg, /* Query each interface to see if it is a bond */ static void -iflinux_add_bond(struct lldpd *cfg, - struct interfaces_device_list *interfaces) +iflinux_add_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces) { struct interfaces_device *iface; - TAILQ_FOREACH(iface, interfaces, next) { - if (iface->type & (IFACE_PHYSICAL_T|IFACE_VLAN_T| - IFACE_BOND_T|IFACE_BRIDGE_T)) + TAILQ_FOREACH (iface, interfaces, next) { + if (iface->type & + (IFACE_PHYSICAL_T | IFACE_VLAN_T | IFACE_BOND_T | IFACE_BRIDGE_T)) continue; if (iflinux_is_bond(cfg, interfaces, iface)) { - log_debug("interfaces", - "interface %s is a bond", - iface->name); + log_debug("interfaces", "interface %s is a bond", iface->name); iface->type |= IFACE_BOND_T; } } @@ -938,48 +925,40 @@ iflinux_add_bond(struct lldpd *cfg, /* Query each interface to see if it is a vlan */ static void -iflinux_add_vlan(struct lldpd *cfg, - struct interfaces_device_list *interfaces) +iflinux_add_vlan(struct lldpd *cfg, struct interfaces_device_list *interfaces) { struct interfaces_device *iface; - TAILQ_FOREACH(iface, interfaces, next) { - if (iface->type & (IFACE_PHYSICAL_T|IFACE_VLAN_T| - IFACE_BOND_T|IFACE_BRIDGE_T)) + TAILQ_FOREACH (iface, interfaces, next) { + if (iface->type & + (IFACE_PHYSICAL_T | IFACE_VLAN_T | IFACE_BOND_T | IFACE_BRIDGE_T)) continue; if (iflinux_is_vlan(cfg, interfaces, iface)) { - log_debug("interfaces", - "interface %s is a VLAN", - iface->name); + log_debug("interfaces", "interface %s is a VLAN", iface->name); iface->type |= IFACE_VLAN_T; } } } static void -iflinux_add_physical(struct lldpd *cfg, - struct interfaces_device_list *interfaces) +iflinux_add_physical(struct lldpd *cfg, struct interfaces_device_list *interfaces) { struct interfaces_device *iface; /* Deny some drivers */ - const char * const *rif; - const char * const denied_drivers[] = { - "cdc_mbim", - "vxlan", - NULL - }; + const char *const *rif; + const char *const denied_drivers[] = { "cdc_mbim", "vxlan", NULL }; - TAILQ_FOREACH(iface, interfaces, next) { - if (iface->type & (IFACE_VLAN_T| - IFACE_BOND_T|IFACE_BRIDGE_T)) + TAILQ_FOREACH (iface, interfaces, next) { + if (iface->type & (IFACE_VLAN_T | IFACE_BOND_T | IFACE_BRIDGE_T)) continue; iface->type &= ~IFACE_PHYSICAL_T; /* We request that the interface is able to do either multicast * or broadcast to be able to send discovery frames. */ - if (!(iface->flags & (IFF_MULTICAST|IFF_BROADCAST))) { - log_debug("interfaces", "skip %s: not able to do multicast nor broadcast", + if (!(iface->flags & (IFF_MULTICAST | IFF_BROADCAST))) { + log_debug("interfaces", + "skip %s: not able to do multicast nor broadcast", iface->name); continue; } @@ -989,8 +968,8 @@ iflinux_add_physical(struct lldpd *cfg, int skip = 0; for (rif = denied_drivers; *rif; rif++) { if (strcmp(iface->driver, *rif) == 0) { - log_debug("interfaces", "skip %s: denied driver", - iface->name); + log_debug("interfaces", + "skip %s: denied driver", iface->name); skip = 1; break; } @@ -999,18 +978,21 @@ iflinux_add_physical(struct lldpd *cfg, } /* If the interface is linked to another one, skip it too. */ - if (iface->lower && (!iface->driver || (strcmp(iface->driver, "veth") && strcmp(iface->driver, "dsa")))) { - log_debug("interfaces", "skip %s: there is a lower interface (%s)", - iface->name, iface->lower->name); + if (iface->lower && + (!iface->driver || + (strcmp(iface->driver, "veth") && + strcmp(iface->driver, "dsa")))) { + log_debug("interfaces", + "skip %s: there is a lower interface (%s)", iface->name, + iface->lower->name); continue; } - /* Get the real MAC address (for example, if the interface is enslaved) */ + /* Get the real MAC address (for example, if the interface is enslaved) + */ iflinux_get_permanent_mac(cfg, interfaces, iface); - log_debug("interfaces", - "%s is a physical interface", - iface->name); + log_debug("interfaces", "%s is a physical interface", iface->name); iface->type |= IFACE_PHYSICAL_T; } } @@ -1042,9 +1024,7 @@ interfaces_update(struct lldpd *cfg) #ifdef ENABLE_OLDIES iflinux_handle_bond(cfg, interfaces); #endif - interfaces_helper_physical(cfg, interfaces, - ð_ops, - iflinux_eth_init); + interfaces_helper_physical(cfg, interfaces, ð_ops, iflinux_eth_init); #ifdef ENABLE_DOT1 interfaces_helper_vlan(cfg, interfaces); #endif @@ -1052,7 +1032,7 @@ interfaces_update(struct lldpd *cfg) interfaces_helper_chassis(cfg, interfaces); /* Mac/PHY */ - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { if (!hardware->h_flags) continue; iflinux_macphy(cfg, hardware); interfaces_helper_promisc(cfg, hardware); diff --git a/src/daemon/interfaces-solaris.c b/src/daemon/interfaces-solaris.c index fd61d388..5e3ae3cf 100644 --- a/src/daemon/interfaces-solaris.c +++ b/src/daemon/interfaces-solaris.c @@ -29,10 +29,9 @@ */ static void -ifsolaris_extract(struct lldpd *cfg, - struct interfaces_device_list *interfaces, - struct interfaces_address_list *addresses, - struct lifreq *lifr) { +ifsolaris_extract(struct lldpd *cfg, struct interfaces_device_list *interfaces, + struct interfaces_address_list *addresses, struct lifreq *lifr) +{ int flags = 0; int index = 0; struct interfaces_address *address = NULL; @@ -44,34 +43,29 @@ ifsolaris_extract(struct lldpd *cfg, /* Flags */ if (ioctl(cfg->g_sock, SIOCGLIFFLAGS, (caddr_t)&lifrl) < 0) { - log_warn("interfaces", "unable to get flags for %s", - lifrl.lifr_name); + log_warn("interfaces", "unable to get flags for %s", lifrl.lifr_name); return; } flags = lifrl.lifr_flags; /* Index */ if (ioctl(cfg->g_sock, SIOCGLIFINDEX, (caddr_t)&lifrl) < 0) { - log_warn("interfaces", "unable to get index for %s", - lifrl.lifr_name); + log_warn("interfaces", "unable to get index for %s", lifrl.lifr_name); return; } index = lifrl.lifr_index; /* Record the address */ if ((address = malloc(sizeof(struct interfaces_address))) == NULL) { - log_warn("interfaces", - "not enough memory for a new IP address on %s", + log_warn("interfaces", "not enough memory for a new IP address on %s", lifrl.lifr_name); return; } address->flags = flags; address->index = index; - memcpy(&address->address, - &lifr->lifr_addr, - (lifr_af == AF_INET)? - sizeof(struct sockaddr_in): - sizeof(struct sockaddr_in6)); + memcpy(&address->address, &lifr->lifr_addr, + (lifr_af == AF_INET) ? sizeof(struct sockaddr_in) : + sizeof(struct sockaddr_in6)); TAILQ_INSERT_TAIL(addresses, address, next); /* Hardware address */ @@ -80,7 +74,7 @@ ifsolaris_extract(struct lldpd *cfg, lifrl.lifr_name); return; } - struct sockaddr_dl *saddrdl = (struct sockaddr_dl*)&lifrl.lifr_addr; + struct sockaddr_dl *saddrdl = (struct sockaddr_dl *)&lifrl.lifr_addr; if (saddrdl->sdl_type != 4) { log_debug("interfaces", "skip %s: not an ethernet device (%d)", lifrl.lifr_name, saddrdl->sdl_type); @@ -99,21 +93,21 @@ ifsolaris_extract(struct lldpd *cfg, device->index = index; device->type = IFACE_PHYSICAL_T; device->address = malloc(ETHER_ADDR_LEN); - if (device->address) - memcpy(device->address, LLADDR(saddrdl), ETHER_ADDR_LEN); + if (device->address) memcpy(device->address, LLADDR(saddrdl), ETHER_ADDR_LEN); /* MTU */ if (ioctl(cfg->g_sock, SIOCGLIFMTU, (caddr_t)&lifrl) < 0) { - log_debug("interfaces", "unable to get MTU for %s", - lifrl.lifr_name); - } else device->mtu = lifrl.lifr_mtu; + log_debug("interfaces", "unable to get MTU for %s", lifrl.lifr_name); + } else + device->mtu = lifrl.lifr_mtu; TAILQ_INSERT_TAIL(interfaces, device, next); } extern struct lldpd_ops bpf_ops; void -interfaces_update(struct lldpd *cfg) { +interfaces_update(struct lldpd *cfg) +{ struct lldpd_hardware *hardware; caddr_t buffer = NULL; struct interfaces_device_list *interfaces; @@ -127,10 +121,7 @@ interfaces_update(struct lldpd *cfg) { TAILQ_INIT(interfaces); TAILQ_INIT(addresses); - struct lifnum lifn = { - .lifn_family = AF_UNSPEC, - .lifn_flags = LIFC_ENABLED - }; + struct lifnum lifn = { .lifn_family = AF_UNSPEC, .lifn_flags = LIFC_ENABLED }; if (ioctl(cfg->g_sock, SIOCGLIFNUM, &lifn) < 0) { log_warn("interfaces", "unable to get the number of interfaces"); goto end; @@ -142,18 +133,16 @@ interfaces_update(struct lldpd *cfg) { goto end; } - struct lifconf lifc = { - .lifc_family = AF_UNSPEC, + struct lifconf lifc = { .lifc_family = AF_UNSPEC, .lifc_flags = LIFC_ENABLED, .lifc_len = bufsize, - .lifc_buf = buffer - }; + .lifc_buf = buffer }; if (ioctl(cfg->g_sock, SIOCGLIFCONF, (char *)&lifc) < 0) { log_warn("interfaces", "unable to get the network interfaces"); goto end; } - int num = lifc.lifc_len / sizeof (struct lifreq); + int num = lifc.lifc_len / sizeof(struct lifreq); if (num > lifn.lifn_count) num = lifn.lifn_count; log_debug("interfaces", "got %d interfaces", num); @@ -162,13 +151,12 @@ interfaces_update(struct lldpd *cfg) { ifsolaris_extract(cfg, interfaces, addresses, lifrp); interfaces_helper_allowlist(cfg, interfaces); - interfaces_helper_physical(cfg, interfaces, - &bpf_ops, ifbpf_phys_init); + interfaces_helper_physical(cfg, interfaces, &bpf_ops, ifbpf_phys_init); interfaces_helper_mgmt(cfg, addresses, interfaces); interfaces_helper_chassis(cfg, interfaces); /* Mac/PHY */ - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { if (!hardware->h_flags) continue; /* TODO: mac/phy for Solaris */ interfaces_helper_promisc(cfg, hardware); diff --git a/src/daemon/interfaces.c b/src/daemon/interfaces.c index ae810031..c1179d9c 100644 --- a/src/daemon/interfaces.c +++ b/src/daemon/interfaces.c @@ -28,10 +28,14 @@ static int lldpd_af(int af) { switch (af) { - case LLDPD_AF_IPV4: return AF_INET; - case LLDPD_AF_IPV6: return AF_INET6; - case LLDPD_AF_LAST: return AF_MAX; - default: return AF_UNSPEC; + case LLDPD_AF_IPV4: + return AF_INET; + case LLDPD_AF_IPV6: + return AF_INET6; + case LLDPD_AF_LAST: + return AF_MAX; + default: + return AF_UNSPEC; } } @@ -40,8 +44,7 @@ lldpd_af(int af) * Enable multicast on the given interface. */ void -interfaces_setup_multicast(struct lldpd *cfg, const char *name, - int remove) +interfaces_setup_multicast(struct lldpd *cfg, const char *name, int remove) { int rc; size_t i, j; @@ -50,8 +53,8 @@ interfaces_setup_multicast(struct lldpd *cfg, const char *name, for (i = 0; cfg->g_protocols[i].mode != 0; i++) { if (!cfg->g_protocols[i].enabled) continue; - for (j = 0; - j < sizeof(cfg->g_protocols[0].mac)/sizeof(cfg->g_protocols[0].mac[0]); + for (j = 0; j < sizeof(cfg->g_protocols[0].mac) / + sizeof(cfg->g_protocols[0].mac[0]); j++) { mac = cfg->g_protocols[i].mac[j]; if (memcmp(mac, zero, ETHER_ADDR_LEN) == 0) break; @@ -60,9 +63,9 @@ interfaces_setup_multicast(struct lldpd *cfg, const char *name, if (errno != ENOENT) log_debug("interfaces", "unable to %s %s address to multicast filter for %s (%s)", - (remove)?"delete":"add", - cfg->g_protocols[i].name, - name, strerror(rc)); + (remove) ? "delete" : "add", + cfg->g_protocols[i].name, name, + strerror(rc)); } } } @@ -94,9 +97,7 @@ interfaces_free_devices(struct interfaces_device_list *ifs) { struct interfaces_device *iff, *iff_next; if (!ifs) return; - for (iff = TAILQ_FIRST(ifs); - iff != NULL; - iff = iff_next) { + for (iff = TAILQ_FIRST(ifs); iff != NULL; iff = iff_next) { iff_next = TAILQ_NEXT(iff, next); interfaces_free_device(iff); } @@ -124,9 +125,7 @@ interfaces_free_addresses(struct interfaces_address_list *ifaddrs) { struct interfaces_address *ifa, *ifa_next; if (!ifaddrs) return; - for (ifa = TAILQ_FIRST(ifaddrs); - ifa != NULL; - ifa = ifa_next) { + for (ifa = TAILQ_FIRST(ifaddrs); ifa != NULL; ifa = ifa_next) { ifa_next = TAILQ_NEXT(ifa, next); interfaces_free_address(ifa); } @@ -140,17 +139,15 @@ interfaces_free_addresses(struct interfaces_address_list *ifaddrs) * @param device Name of the device we search for * @return The interface or NULL if not found */ -struct interfaces_device* +struct interfaces_device * interfaces_nametointerface(struct interfaces_device_list *interfaces, const char *device) { struct interfaces_device *iface; - TAILQ_FOREACH(iface, interfaces, next) { - if (!strncmp(iface->name, device, IFNAMSIZ)) - return iface; + TAILQ_FOREACH (iface, interfaces, next) { + if (!strncmp(iface->name, device, IFNAMSIZ)) return iface; } - log_debug("interfaces", "cannot get interface for index %s", - device); + log_debug("interfaces", "cannot get interface for index %s", device); return NULL; } @@ -161,17 +158,14 @@ interfaces_nametointerface(struct interfaces_device_list *interfaces, * @param index Index of the device we search for * @return The interface or NULL if not found */ -struct interfaces_device* -interfaces_indextointerface(struct interfaces_device_list *interfaces, - int index) +struct interfaces_device * +interfaces_indextointerface(struct interfaces_device_list *interfaces, int index) { struct interfaces_device *iface; - TAILQ_FOREACH(iface, interfaces, next) { - if (iface->index == index) - return iface; + TAILQ_FOREACH (iface, interfaces, next) { + if (iface->index == index) return iface; } - log_debug("interfaces", "cannot get interface for index %d", - index); + log_debug("interfaces", "cannot get interface for index %d", index); return NULL; } @@ -181,10 +175,9 @@ interfaces_helper_allowlist(struct lldpd *cfg, { struct interfaces_device *iface; - if (!cfg->g_config.c_iface_pattern) - return; + if (!cfg->g_config.c_iface_pattern) return; - TAILQ_FOREACH(iface, interfaces, next) { + TAILQ_FOREACH (iface, interfaces, next) { int m = pattern_match(iface->name, cfg->g_config.c_iface_pattern, 0); switch (m) { case PATTERN_MATCH_DENIED: @@ -192,7 +185,8 @@ interfaces_helper_allowlist(struct lldpd *cfg, iface->ignore = 1; continue; case PATTERN_MATCH_ALLOWED_EXACT: - log_debug("interfaces", "allow %s (consider it as a physical interface)", + log_debug("interfaces", + "allow %s (consider it as a physical interface)", iface->name); iface->type |= IFACE_PHYSICAL_T; continue; @@ -202,8 +196,7 @@ interfaces_helper_allowlist(struct lldpd *cfg, #ifdef ENABLE_DOT1 static void -iface_append_vlan(struct lldpd *cfg, - struct interfaces_device *vlan, +iface_append_vlan(struct lldpd *cfg, struct interfaces_device *vlan, struct interfaces_device *lower) { struct lldpd_hardware *hardware = @@ -214,43 +207,37 @@ iface_append_vlan(struct lldpd *cfg, uint16_t vlan_id; if (hardware == NULL) { - log_debug("interfaces", - "cannot find real interface %s for VLAN %s", + log_debug("interfaces", "cannot find real interface %s for VLAN %s", lower->name, vlan->name); return; } port = &hardware->h_lport; for (int i = 0; (i < VLAN_BITMAP_LEN); i++) { - if (vlan->vlan_bmap[i] == 0) - continue; + if (vlan->vlan_bmap[i] == 0) continue; for (unsigned bit = 0; bit < 32; bit++) { uint32_t mask = 1L << bit; - if (!(vlan->vlan_bmap[i] & mask)) - continue; + if (!(vlan->vlan_bmap[i] & mask)) continue; vlan_id = (i * 32) + bit; - if (asprintf(&name, "vlan%d", vlan_id) == -1) - return; + if (asprintf(&name, "vlan%d", vlan_id) == -1) return; /* Check if the VLAN is already here. */ - TAILQ_FOREACH(v, &port->p_vlans, v_entries) + TAILQ_FOREACH (v, &port->p_vlans, v_entries) if (strncmp(name, v->v_name, IFNAMSIZ) == 0) { free(name); return; } - if ((v = (struct lldpd_vlan *) - calloc(1, sizeof(struct lldpd_vlan))) == NULL) { + if ((v = (struct lldpd_vlan *)calloc(1, + sizeof(struct lldpd_vlan))) == NULL) { free(name); return; } v->v_name = name; v->v_vid = vlan_id; - if (vlan->pvid) - port->p_pvid = vlan->pvid; - log_debug("interfaces", "append VLAN %s for %s", - v->v_name, - hardware->h_ifname); + if (vlan->pvid) port->p_pvid = vlan->pvid; + log_debug("interfaces", "append VLAN %s for %s", v->v_name, + hardware->h_ifname); TAILQ_INSERT_TAIL(&port->p_vlans, v, v_entries); } } @@ -266,11 +253,8 @@ iface_append_vlan(struct lldpd *cfg, * Initially, upper == vlan. This function will be called recursively. */ static void -iface_append_vlan_to_lower(struct lldpd *cfg, - struct interfaces_device_list *interfaces, - struct interfaces_device *vlan, - struct interfaces_device *upper, - int depth) +iface_append_vlan_to_lower(struct lldpd *cfg, struct interfaces_device_list *interfaces, + struct interfaces_device *vlan, struct interfaces_device *upper, int depth) { if (depth > 5) { log_warnx("interfaces", @@ -281,62 +265,57 @@ iface_append_vlan_to_lower(struct lldpd *cfg, depth++; struct interfaces_device *lower; log_debug("interfaces", - "looking to apply VLAN %s to physical interface behind %s", - vlan->name, upper->name); + "looking to apply VLAN %s to physical interface behind %s", vlan->name, + upper->name); /* Some bridges managed VLAN internally, skip them. */ if (upper->type & IFACE_BRIDGE_VLAN_T) { - log_debug("interfaces", "VLAN %s ignored for VLAN-aware bridge interface %s", - vlan->name, upper->name); + log_debug("interfaces", + "VLAN %s ignored for VLAN-aware bridge interface %s", vlan->name, + upper->name); return; } /* Easy: check if we have a lower interface. */ if (upper->lower) { - log_debug("interfaces", "VLAN %s on lower interface %s", - vlan->name, upper->name); - iface_append_vlan_to_lower(cfg, - interfaces, vlan, - upper->lower, - depth); + log_debug("interfaces", "VLAN %s on lower interface %s", vlan->name, + upper->name); + iface_append_vlan_to_lower(cfg, interfaces, vlan, upper->lower, depth); return; } /* Other easy case, we have a physical interface. */ if (upper->type & IFACE_PHYSICAL_T) { - log_debug("interfaces", "VLAN %s on physical interface %s", - vlan->name, upper->name); + log_debug("interfaces", "VLAN %s on physical interface %s", vlan->name, + upper->name); iface_append_vlan(cfg, vlan, upper); return; } /* We can now search for interfaces that have our interface as an upper * interface. */ - TAILQ_FOREACH(lower, interfaces, next) { + TAILQ_FOREACH (lower, interfaces, next) { if (lower->upper != upper) continue; - log_debug("interfaces", "VLAN %s on lower interface %s", - vlan->name, upper->name); - iface_append_vlan_to_lower(cfg, - interfaces, vlan, lower, depth); + log_debug("interfaces", "VLAN %s on lower interface %s", vlan->name, + upper->name); + iface_append_vlan_to_lower(cfg, interfaces, vlan, lower, depth); } } void -interfaces_helper_vlan(struct lldpd *cfg, - struct interfaces_device_list *interfaces) +interfaces_helper_vlan(struct lldpd *cfg, struct interfaces_device_list *interfaces) { struct interfaces_device *iface; - TAILQ_FOREACH(iface, interfaces, next) { + TAILQ_FOREACH (iface, interfaces, next) { if (!(iface->type & IFACE_VLAN_T) && bitmap_isempty(iface->vlan_bmap)) continue; /* We need to find the physical interfaces of this vlan, through bonds and bridges. */ - log_debug("interfaces", "search physical interface for VLAN interface %s", - iface->name); - iface_append_vlan_to_lower(cfg, interfaces, - iface, iface, 0); + log_debug("interfaces", + "search physical interface for VLAN interface %s", iface->name); + iface_append_vlan_to_lower(cfg, interfaces, iface, iface, 0); } } #endif @@ -344,18 +323,17 @@ interfaces_helper_vlan(struct lldpd *cfg, /* Fill out chassis ID if not already done. Only physical interfaces are * considered. */ void -interfaces_helper_chassis(struct lldpd *cfg, - struct interfaces_device_list *interfaces) +interfaces_helper_chassis(struct lldpd *cfg, struct interfaces_device_list *interfaces) { struct interfaces_device *iface; struct lldpd_hardware *hardware; char *name = NULL; - static u_int8_t zero_mac[] = {0, 0, 0, 0, 0, 0}; + static u_int8_t zero_mac[] = { 0, 0, 0, 0, 0, 0 }; if (!cfg->g_config.c_cap_override) { LOCAL_CHASSIS(cfg)->c_cap_enabled &= ~(LLDP_CAP_BRIDGE | LLDP_CAP_WLAN | LLDP_CAP_STATION); - TAILQ_FOREACH(iface, interfaces, next) { + TAILQ_FOREACH (iface, interfaces, next) { if (iface->type & IFACE_BRIDGE_T) LOCAL_CHASSIS(cfg)->c_cap_enabled |= LLDP_CAP_BRIDGE; if (iface->type & IFACE_WIRELESS_T) @@ -370,18 +348,18 @@ interfaces_helper_chassis(struct lldpd *cfg, * it's set to a local address equal to the user-provided * configuration. */ if ((LOCAL_CHASSIS(cfg)->c_id != NULL && - LOCAL_CHASSIS(cfg)->c_id_subtype == LLDP_CHASSISID_SUBTYPE_LLADDR) || + LOCAL_CHASSIS(cfg)->c_id_subtype == LLDP_CHASSISID_SUBTYPE_LLADDR) || cfg->g_config.c_cid_string != NULL) - return; /* We already have one */ + return; /* We already have one */ - TAILQ_FOREACH(iface, interfaces, next) { + TAILQ_FOREACH (iface, interfaces, next) { if (!(iface->type & IFACE_PHYSICAL_T)) continue; if (cfg->g_config.c_cid_pattern && - !pattern_match(iface->name, cfg->g_config.c_cid_pattern, 0)) continue; + !pattern_match(iface->name, cfg->g_config.c_cid_pattern, 0)) + continue; - if ((hardware = lldpd_get_hardware(cfg, - iface->name, - iface->index)) == NULL) + if ((hardware = lldpd_get_hardware(cfg, iface->name, iface->index)) == + NULL) /* That's odd. Let's skip. */ continue; if (memcmp(hardware->h_lladdr, zero_mac, ETHER_ADDR_LEN) == 0) @@ -409,10 +387,10 @@ interfaces_helper_chassis(struct lldpd *cfg, #undef IN_IS_ADDR_LINKLOCAL #define IN_IS_ADDR_LINKLOCAL(a) (((a)->s_addr & htonl(0xffff0000)) == htonl(0xa9fe0000)) #undef IN_IS_ADDR_GLOBAL -#define IN_IS_ADDR_GLOBAL(a) (!IN_IS_ADDR_LOOPBACK(a) && !IN_IS_ADDR_ANY(a) && !IN_IS_ADDR_LINKLOCAL(a)) +#define IN_IS_ADDR_GLOBAL(a) \ + (!IN_IS_ADDR_LOOPBACK(a) && !IN_IS_ADDR_ANY(a) && !IN_IS_ADDR_LINKLOCAL(a)) #undef IN6_IS_ADDR_GLOBAL -#define IN6_IS_ADDR_GLOBAL(a) \ - (!IN6_IS_ADDR_LOOPBACK(a) && !IN6_IS_ADDR_LINKLOCAL(a)) +#define IN6_IS_ADDR_GLOBAL(a) (!IN6_IS_ADDR_LOOPBACK(a) && !IN6_IS_ADDR_LINKLOCAL(a)) /* Add management addresses for the given family. We only take one of each address family, unless a pattern is provided and is not all negative. For @@ -420,10 +398,8 @@ interfaces_helper_chassis(struct lldpd *cfg, address not matching 10.*. */ static int -interfaces_helper_mgmt_for_af(struct lldpd *cfg, - int af, - struct interfaces_address_list *addrs, - struct interfaces_device_list *interfaces, +interfaces_helper_mgmt_for_af(struct lldpd *cfg, int af, + struct interfaces_address_list *addrs, struct interfaces_device_list *interfaces, int global, int allnegative) { struct interfaces_address *addr; @@ -434,62 +410,64 @@ interfaces_helper_mgmt_for_af(struct lldpd *cfg, union lldpd_address in_addr; size_t in_addr_size; - TAILQ_FOREACH(addr, addrs, next) { - if (addr->address.ss_family != lldpd_af(af)) - continue; + TAILQ_FOREACH (addr, addrs, next) { + if (addr->address.ss_family != lldpd_af(af)) continue; switch (af) { case LLDPD_AF_IPV4: in_addr_size = sizeof(struct in_addr); - memcpy(&in_addr, &((struct sockaddr_in *)&addr->address)->sin_addr, + memcpy(&in_addr, + &((struct sockaddr_in *)&addr->address)->sin_addr, in_addr_size); if (global) { - if (!IN_IS_ADDR_GLOBAL(&in_addr.inet)) - continue; + if (!IN_IS_ADDR_GLOBAL(&in_addr.inet)) continue; } else { - if (!IN_IS_ADDR_LINKLOCAL(&in_addr.inet)) - continue; + if (!IN_IS_ADDR_LINKLOCAL(&in_addr.inet)) continue; } break; case LLDPD_AF_IPV6: in_addr_size = sizeof(struct in6_addr); - memcpy(&in_addr, &((struct sockaddr_in6 *)&addr->address)->sin6_addr, + memcpy(&in_addr, + &((struct sockaddr_in6 *)&addr->address)->sin6_addr, in_addr_size); if (global) { - if (!IN6_IS_ADDR_GLOBAL(&in_addr.inet6)) - continue; + if (!IN6_IS_ADDR_GLOBAL(&in_addr.inet6)) continue; } else { - if (!IN6_IS_ADDR_LINKLOCAL(&in_addr.inet6)) - continue; + if (!IN6_IS_ADDR_LINKLOCAL(&in_addr.inet6)) continue; } break; default: assert(0); continue; } - if (inet_ntop(lldpd_af(af), &in_addr, - addrstrbuf, sizeof(addrstrbuf)) == NULL) { - log_warn("interfaces", "unable to convert IP address to a string"); + if (inet_ntop(lldpd_af(af), &in_addr, addrstrbuf, sizeof(addrstrbuf)) == + NULL) { + log_warn("interfaces", + "unable to convert IP address to a string"); continue; } if (cfg->g_config.c_mgmt_pattern == NULL || /* Match on IP address */ - pattern_match(addrstrbuf, cfg->g_config.c_mgmt_pattern, allnegative) || + pattern_match(addrstrbuf, cfg->g_config.c_mgmt_pattern, + allnegative) || /* Match on interface name */ ((device = interfaces_indextointerface(interfaces, addr->index)) && - pattern_match(device->name, cfg->g_config.c_mgmt_pattern, allnegative))) { - mgmt = lldpd_alloc_mgmt(af, &in_addr, in_addr_size, - addr->index); + pattern_match(device->name, cfg->g_config.c_mgmt_pattern, + allnegative))) { + mgmt = + lldpd_alloc_mgmt(af, &in_addr, in_addr_size, addr->index); if (mgmt == NULL) { assert(errno == ENOMEM); /* anything else is a bug */ log_warn("interfaces", "out of memory error"); return found; } - log_debug("interfaces", "add management address %s", addrstrbuf); + log_debug("interfaces", "add management address %s", + addrstrbuf); TAILQ_INSERT_TAIL(&LOCAL_CHASSIS(cfg)->c_mgmt, mgmt, m_entries); found = 1; - /* Don't take additional address if the pattern is all negative. */ + /* Don't take additional address if the pattern is all negative. + */ if (allnegative) break; } } @@ -501,8 +479,7 @@ interfaces_helper_mgmt_for_af(struct lldpd *cfg, really handle interface related information (management address is attached to the local chassis). */ void -interfaces_helper_mgmt(struct lldpd *cfg, - struct interfaces_address_list *addrs, +interfaces_helper_mgmt(struct lldpd *cfg, struct interfaces_address_list *addrs, struct interfaces_device_list *interfaces) { int allnegative = 0; @@ -510,8 +487,7 @@ interfaces_helper_mgmt(struct lldpd *cfg, const char *pattern = cfg->g_config.c_mgmt_pattern; lldpd_chassis_mgmt_cleanup(LOCAL_CHASSIS(cfg)); - if (!cfg->g_config.c_mgmt_advertise) - return; + if (!cfg->g_config.c_mgmt_advertise) return; /* Is the pattern provided an actual IP address? */ if (pattern && strpbrk(pattern, "!,*?") == NULL) { @@ -520,38 +496,43 @@ interfaces_helper_mgmt(struct lldpd *cfg, struct lldpd_mgmt *mgmt; struct interfaces_address *ifaddr; - for (af = LLDPD_AF_UNSPEC + 1; - af != LLDPD_AF_LAST; af++) { + for (af = LLDPD_AF_UNSPEC + 1; af != LLDPD_AF_LAST; af++) { switch (af) { - case LLDPD_AF_IPV4: addr_size = sizeof(struct in_addr); break; - case LLDPD_AF_IPV6: addr_size = sizeof(struct in6_addr); break; - default: assert(0); - } - if (inet_pton(lldpd_af(af), pattern, addr) == 1) + case LLDPD_AF_IPV4: + addr_size = sizeof(struct in_addr); break; + case LLDPD_AF_IPV6: + addr_size = sizeof(struct in6_addr); + break; + default: + assert(0); + } + if (inet_pton(lldpd_af(af), pattern, addr) == 1) break; } if (af != LLDPD_AF_LAST) { /* Try to get the index if possible. */ - TAILQ_FOREACH(ifaddr, addrs, next) { - if (ifaddr->address.ss_family != lldpd_af(af)) - continue; + TAILQ_FOREACH (ifaddr, addrs, next) { + if (ifaddr->address.ss_family != lldpd_af(af)) continue; if (LLDPD_AF_IPV4 == af) { struct sockaddr_in *sa_sin; sa_sin = (struct sockaddr_in *)&ifaddr->address; - if (0 == memcmp(addr, - &(sa_sin->sin_addr), - addr_size)) + if (0 == + memcmp(addr, &(sa_sin->sin_addr), + addr_size)) break; - } - else if (LLDPD_AF_IPV6 == af) { - if (0 == memcmp(addr, - &((struct sockaddr_in6 *)&ifaddr->address)->sin6_addr, - addr_size)) + } else if (LLDPD_AF_IPV6 == af) { + if (0 == + memcmp(addr, + &((struct sockaddr_in6 *)&ifaddr + ->address) + ->sin6_addr, + addr_size)) break; } } - mgmt = lldpd_alloc_mgmt(af, addr, addr_size, ifaddr ? ifaddr->index : 0); + mgmt = lldpd_alloc_mgmt(af, addr, addr_size, + ifaddr ? ifaddr->index : 0); if (mgmt == NULL) { log_warn("interfaces", "out of memory error"); return; @@ -565,27 +546,29 @@ interfaces_helper_mgmt(struct lldpd *cfg, } /* Is the pattern provided all negative? */ - if (pattern == NULL) allnegative = 1; + if (pattern == NULL) + allnegative = 1; else if (pattern[0] == '!') { /* If each comma is followed by '!', its an all negative pattern */ const char *sep = pattern; - while ((sep = strchr(sep, ',')) && - (*(++sep) == '!')); + while ((sep = strchr(sep, ',')) && (*(++sep) == '!')) + ; if (sep == NULL) allnegative = 1; } /* Find management addresses */ for (af = LLDPD_AF_UNSPEC + 1; af != LLDPD_AF_LAST; af++) { - (void)(interfaces_helper_mgmt_for_af(cfg, af, addrs, interfaces, 1, allnegative) || - interfaces_helper_mgmt_for_af(cfg, af, addrs, interfaces, 0, allnegative)); + (void)(interfaces_helper_mgmt_for_af(cfg, af, addrs, interfaces, 1, + allnegative) || + interfaces_helper_mgmt_for_af(cfg, af, addrs, interfaces, 0, + allnegative)); } } /* Fill up port name and description */ void -interfaces_helper_port_name_desc(struct lldpd *cfg, - struct lldpd_hardware *hardware, +interfaces_helper_port_name_desc(struct lldpd *cfg, struct lldpd_hardware *hardware, struct interfaces_device *iface) { struct lldpd_port *port = &hardware->h_lport; @@ -593,9 +576,8 @@ interfaces_helper_port_name_desc(struct lldpd *cfg, /* We need to set the portid to what the client configured. This can be done from the CLI. */ - int has_alias = (iface->alias != NULL - && strlen(iface->alias) != 0 - && strncmp("lldpd: ", iface->alias, 7)); + int has_alias = (iface->alias != NULL && strlen(iface->alias) != 0 && + strncmp("lldpd: ", iface->alias, 7)); int portid_type = cfg->g_config.c_lldp_portid_type; if (portid_type == LLDP_PORTID_SUBTYPE_IFNAME || (portid_type == LLDP_PORTID_SUBTYPE_UNKNOWN && has_alias) || @@ -647,44 +629,38 @@ interfaces_helper_port_name_desc(struct lldpd *cfg, } void -interfaces_helper_add_hardware(struct lldpd *cfg, - struct lldpd_hardware *hardware) +interfaces_helper_add_hardware(struct lldpd *cfg, struct lldpd_hardware *hardware) { TRACE(LLDPD_INTERFACES_NEW(hardware->h_ifname)); TAILQ_INSERT_TAIL(&cfg->g_hardware, hardware, h_entries); } void -interfaces_helper_physical(struct lldpd *cfg, - struct interfaces_device_list *interfaces, - struct lldpd_ops *ops, - int(*init)(struct lldpd *, struct lldpd_hardware *)) +interfaces_helper_physical(struct lldpd *cfg, struct interfaces_device_list *interfaces, + struct lldpd_ops *ops, int (*init)(struct lldpd *, struct lldpd_hardware *)) { struct interfaces_device *iface; struct lldpd_hardware *hardware; int created; - TAILQ_FOREACH(iface, interfaces, next) { + TAILQ_FOREACH (iface, interfaces, next) { if (!(iface->type & IFACE_PHYSICAL_T)) continue; if (iface->ignore) continue; log_debug("interfaces", "%s is an acceptable ethernet device", iface->name); created = 0; - if ((hardware = lldpd_get_hardware(cfg, - iface->name, - iface->index)) == NULL) { - if ((hardware = lldpd_alloc_hardware(cfg, - iface->name, - iface->index)) == NULL) { - log_warnx("interfaces", "Unable to allocate space for %s", - iface->name); + if ((hardware = lldpd_get_hardware(cfg, iface->name, iface->index)) == + NULL) { + if ((hardware = lldpd_alloc_hardware(cfg, iface->name, + iface->index)) == NULL) { + log_warnx("interfaces", + "Unable to allocate space for %s", iface->name); continue; } created = 1; } - if (hardware->h_flags) - continue; + if (hardware->h_flags) continue; if (hardware->h_ops != ops || hardware->h_ifindex_changed) { if (!created) { log_debug("interfaces", @@ -697,26 +673,25 @@ interfaces_helper_physical(struct lldpd *cfg, } } if (init(cfg, hardware) != 0) { - log_warnx("interfaces", - "unable to initialize %s", + log_warnx("interfaces", "unable to initialize %s", hardware->h_ifname); lldpd_hardware_cleanup(cfg, hardware); continue; } hardware->h_ops = ops; - hardware->h_mangle = (iface->upper && - iface->upper->type & IFACE_BOND_T); + hardware->h_mangle = + (iface->upper && iface->upper->type & IFACE_BOND_T); } if (created) interfaces_helper_add_hardware(cfg, hardware); else lldpd_port_cleanup(&hardware->h_lport, 0); - hardware->h_flags = iface->flags; /* Should be non-zero */ - iface->ignore = 1; /* Future handlers - don't have to - care about this - interface. */ + hardware->h_flags = iface->flags; /* Should be non-zero */ + iface->ignore = 1; /* Future handlers + don't have to + care about this + interface. */ /* Get local address */ memcpy(&hardware->h_lladdr, iface->address, ETHER_ADDR_LEN); @@ -737,13 +712,11 @@ interfaces_helper_physical(struct lldpd *cfg, } void -interfaces_helper_promisc(struct lldpd *cfg, - struct lldpd_hardware *hardware) +interfaces_helper_promisc(struct lldpd *cfg, struct lldpd_hardware *hardware) { if (!cfg->g_config.c_promisc) return; if (priv_iface_promisc(hardware->h_ifname) != 0) { - log_warnx("interfaces", - "unable to enable promiscuous mode for %s", + log_warnx("interfaces", "unable to enable promiscuous mode for %s", hardware->h_ifname); } } @@ -757,20 +730,18 @@ interfaces_helper_promisc(struct lldpd *cfg, * something like that. */ int -interfaces_send_helper(struct lldpd *cfg, - struct lldpd_hardware *hardware, - char *buffer, size_t size) +interfaces_send_helper(struct lldpd *cfg, struct lldpd_hardware *hardware, char *buffer, + size_t size) { if (size < 2 * ETHER_ADDR_LEN) { - log_warnx("interfaces", - "packet to send on %s is too small!", + log_warnx("interfaces", "packet to send on %s is too small!", hardware->h_ifname); return 0; } if (hardware->h_mangle) { #define MAC_UL_ADMINISTERED_BIT_MASK 0x02 char *src_mac = buffer + ETHER_ADDR_LEN; - char arbitrary[] = { 0x00, 0x60, 0x08, 0x69, 0x97, 0xef}; + char arbitrary[] = { 0x00, 0x60, 0x08, 0x69, 0x97, 0xef }; switch (cfg->g_config.c_bond_slave_src_mac_type) { case LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED: diff --git a/src/daemon/lldp-tlv.h b/src/daemon/lldp-tlv.h index a8016bbf..a9bf7cf7 100644 --- a/src/daemon/lldp-tlv.h +++ b/src/daemon/lldp-tlv.h @@ -18,45 +18,66 @@ #ifndef _LLDP_TLV_H #define _LLDP_TLV_H -#define LLDP_ADDR_NEAREST_BRIDGE {0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e} -#define LLDP_ADDR_NEAREST_NONTPMR_BRIDGE {0x01, 0x80, 0xc2, 0x00, 0x00, 0x03} -#define LLDP_ADDR_NEAREST_CUSTOMER_BRIDGE {0x01, 0x80, 0xc2, 0x00, 0x00, 0x00} - -#define LLDP_TLV_END 0 -#define LLDP_TLV_CHASSIS_ID 1 -#define LLDP_TLV_PORT_ID 2 -#define LLDP_TLV_TTL 3 -#define LLDP_TLV_PORT_DESCR 4 -#define LLDP_TLV_SYSTEM_NAME 5 -#define LLDP_TLV_SYSTEM_DESCR 6 -#define LLDP_TLV_SYSTEM_CAP 7 -#define LLDP_TLV_MGMT_ADDR 8 - -#define LLDP_TLV_ORG_DOT1 {0x00, 0x80, 0xc2} -#define LLDP_TLV_ORG_DOT3 {0x00, 0x12, 0x0f} -#define LLDP_TLV_ORG_MED {0x00, 0x12, 0xbb} -#define LLDP_TLV_ORG_DCBX {0x00, 0x1b, 0x21} - -#define LLDP_TLV_DOT1_PVID 1 -#define LLDP_TLV_DOT1_PPVID 2 -#define LLDP_TLV_DOT1_VLANNAME 3 -#define LLDP_TLV_DOT1_PI 4 - -#define LLDP_TLV_DOT3_MAC 1 -#define LLDP_TLV_DOT3_POWER 2 -#define LLDP_TLV_DOT3_LA 3 -#define LLDP_TLV_DOT3_MFS 4 - -#define LLDP_TLV_MED_CAP 1 -#define LLDP_TLV_MED_POLICY 2 -#define LLDP_TLV_MED_LOCATION 3 -#define LLDP_TLV_MED_MDI 4 -#define LLDP_TLV_MED_IV_HW 5 -#define LLDP_TLV_MED_IV_FW 6 -#define LLDP_TLV_MED_IV_SW 7 -#define LLDP_TLV_MED_IV_SN 8 -#define LLDP_TLV_MED_IV_MANUF 9 -#define LLDP_TLV_MED_IV_MODEL 10 -#define LLDP_TLV_MED_IV_ASSET 11 +#define LLDP_ADDR_NEAREST_BRIDGE \ + { \ + 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e \ + } +#define LLDP_ADDR_NEAREST_NONTPMR_BRIDGE \ + { \ + 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 \ + } +#define LLDP_ADDR_NEAREST_CUSTOMER_BRIDGE \ + { \ + 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 \ + } + +#define LLDP_TLV_END 0 +#define LLDP_TLV_CHASSIS_ID 1 +#define LLDP_TLV_PORT_ID 2 +#define LLDP_TLV_TTL 3 +#define LLDP_TLV_PORT_DESCR 4 +#define LLDP_TLV_SYSTEM_NAME 5 +#define LLDP_TLV_SYSTEM_DESCR 6 +#define LLDP_TLV_SYSTEM_CAP 7 +#define LLDP_TLV_MGMT_ADDR 8 + +#define LLDP_TLV_ORG_DOT1 \ + { \ + 0x00, 0x80, 0xc2 \ + } +#define LLDP_TLV_ORG_DOT3 \ + { \ + 0x00, 0x12, 0x0f \ + } +#define LLDP_TLV_ORG_MED \ + { \ + 0x00, 0x12, 0xbb \ + } +#define LLDP_TLV_ORG_DCBX \ + { \ + 0x00, 0x1b, 0x21 \ + } + +#define LLDP_TLV_DOT1_PVID 1 +#define LLDP_TLV_DOT1_PPVID 2 +#define LLDP_TLV_DOT1_VLANNAME 3 +#define LLDP_TLV_DOT1_PI 4 + +#define LLDP_TLV_DOT3_MAC 1 +#define LLDP_TLV_DOT3_POWER 2 +#define LLDP_TLV_DOT3_LA 3 +#define LLDP_TLV_DOT3_MFS 4 + +#define LLDP_TLV_MED_CAP 1 +#define LLDP_TLV_MED_POLICY 2 +#define LLDP_TLV_MED_LOCATION 3 +#define LLDP_TLV_MED_MDI 4 +#define LLDP_TLV_MED_IV_HW 5 +#define LLDP_TLV_MED_IV_FW 6 +#define LLDP_TLV_MED_IV_SW 7 +#define LLDP_TLV_MED_IV_SN 8 +#define LLDP_TLV_MED_IV_MANUF 9 +#define LLDP_TLV_MED_IV_MODEL 10 +#define LLDP_TLV_MED_IV_ASSET 11 #endif diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index d64cf5ff..c7f1082f 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -41,47 +41,44 @@ #include #if HAVE_VFORK_H -# include +# include #endif #if HAVE_WORKING_FORK -# define vfork fork +# define vfork fork #endif -static void usage(void); +static void usage(void); -static struct protocol protos[] = -{ +static struct protocol protos[] = { { LLDPD_MODE_LLDP, 1, "LLDP", 'l', lldp_send, lldp_decode, NULL, - { LLDP_ADDR_NEAREST_BRIDGE, - LLDP_ADDR_NEAREST_NONTPMR_BRIDGE, - LLDP_ADDR_NEAREST_CUSTOMER_BRIDGE } }, + { LLDP_ADDR_NEAREST_BRIDGE, LLDP_ADDR_NEAREST_NONTPMR_BRIDGE, + LLDP_ADDR_NEAREST_CUSTOMER_BRIDGE } }, #ifdef ENABLE_CDP { LLDPD_MODE_CDPV1, 0, "CDPv1", 'c', cdpv1_send, cdp_decode, cdpv1_guess, - { CDP_MULTICAST_ADDR } }, + { CDP_MULTICAST_ADDR } }, { LLDPD_MODE_CDPV2, 0, "CDPv2", 'c', cdpv2_send, cdp_decode, cdpv2_guess, - { CDP_MULTICAST_ADDR } }, + { CDP_MULTICAST_ADDR } }, #endif #ifdef ENABLE_SONMP { LLDPD_MODE_SONMP, 0, "SONMP", 's', sonmp_send, sonmp_decode, NULL, - { SONMP_MULTICAST_ADDR } }, + { SONMP_MULTICAST_ADDR } }, #endif #ifdef ENABLE_EDP { LLDPD_MODE_EDP, 0, "EDP", 'e', edp_send, edp_decode, NULL, - { EDP_MULTICAST_ADDR } }, + { EDP_MULTICAST_ADDR } }, #endif #ifdef ENABLE_FDP { LLDPD_MODE_FDP, 0, "FDP", 'f', fdp_send, cdp_decode, NULL, - { FDP_MULTICAST_ADDR } }, + { FDP_MULTICAST_ADDR } }, #endif - { 0, 0, "any", ' ', NULL, NULL, NULL, - { { 0, 0, 0, 0, 0, 0 } } } + { 0, 0, "any", ' ', NULL, NULL, NULL, { { 0, 0, 0, 0, 0, 0 } } } }; -static char **saved_argv; +static char **saved_argv; #ifdef HAVE___PROGNAME -extern const char *__progname; +extern const char *__progname; #else -# define __progname "lldpd" +# define __progname "lldpd" #endif static void @@ -95,18 +92,24 @@ usage(void) fprintf(stderr, "-d Do not daemonize.\n"); fprintf(stderr, "-r Receive-only mode\n"); fprintf(stderr, "-i Disable LLDP-MED inventory TLV transmission.\n"); - fprintf(stderr, "-k Disable advertising of kernel release, version, machine.\n"); + fprintf(stderr, + "-k Disable advertising of kernel release, version, machine.\n"); fprintf(stderr, "-S descr Override the default system description.\n"); fprintf(stderr, "-P name Override the default hardware platform.\n"); - fprintf(stderr, "-m IP Specify the IP management addresses of this system.\n"); - fprintf(stderr, "-u file Specify the Unix-domain socket used for communication with lldpctl(8).\n"); - fprintf(stderr, "-H mode Specify the behaviour when detecting multiple neighbors.\n"); + fprintf(stderr, + "-m IP Specify the IP management addresses of this system.\n"); + fprintf(stderr, + "-u file Specify the Unix-domain socket used for communication with lldpctl(8).\n"); + fprintf(stderr, + "-H mode Specify the behaviour when detecting multiple neighbors.\n"); fprintf(stderr, "-I iface Limit interfaces to use.\n"); fprintf(stderr, "-C iface Limit interfaces to use for computing chassis ID.\n"); fprintf(stderr, "-L path Override path for lldpcli command.\n"); - fprintf(stderr, "-O file Override default configuration locations processed by lldpcli(8) at start.\n"); + fprintf(stderr, + "-O file Override default configuration locations processed by lldpcli(8) at start.\n"); #ifdef ENABLE_LLDPMED - fprintf(stderr, "-M class Enable emission of LLDP-MED frame. 'class' should be one of:\n"); + fprintf(stderr, + "-M class Enable emission of LLDP-MED frame. 'class' should be one of:\n"); fprintf(stderr, " 1 Generic Endpoint (Class I)\n"); fprintf(stderr, " 2 Media Endpoint (Class II)\n"); fprintf(stderr, " 3 Communication Device Endpoints (Class III)\n"); @@ -118,20 +121,21 @@ usage(void) #endif fprintf(stderr, "\n"); -#if defined ENABLE_CDP || defined ENABLE_EDP || defined ENABLE_FDP || defined ENABLE_SONMP +#if defined ENABLE_CDP || defined ENABLE_EDP || defined ENABLE_FDP || \ + defined ENABLE_SONMP fprintf(stderr, "Additional protocol support.\n"); -#ifdef ENABLE_CDP +# ifdef ENABLE_CDP fprintf(stderr, "-c Enable the support of CDP protocol. (Cisco)\n"); -#endif -#ifdef ENABLE_EDP +# endif +# ifdef ENABLE_EDP fprintf(stderr, "-e Enable the support of EDP protocol. (Extreme)\n"); -#endif -#ifdef ENABLE_FDP +# endif +# ifdef ENABLE_FDP fprintf(stderr, "-f Enable the support of FDP protocol. (Foundry)\n"); -#endif -#ifdef ENABLE_SONMP +# endif +# ifdef ENABLE_SONMP fprintf(stderr, "-s Enable the support of SONMP protocol. (Nortel)\n"); -#endif +# endif fprintf(stderr, "\n"); #endif @@ -144,20 +148,21 @@ struct lldpd_hardware * lldpd_get_hardware(struct lldpd *cfg, char *name, int index) { struct lldpd_hardware *hardware; - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { if (strcmp(hardware->h_ifname, name) == 0) { if (hardware->h_flags == 0) { if (hardware->h_ifindex != 0 && hardware->h_ifindex != index) { - log_debug("interfaces", "%s changed index: from %d to %d", - hardware->h_ifname, hardware->h_ifindex, index); + log_debug("interfaces", + "%s changed index: from %d to %d", + hardware->h_ifname, hardware->h_ifindex, + index); hardware->h_ifindex_changed = 1; } hardware->h_ifindex = index; break; } - if (hardware->h_ifindex == index) - break; + if (hardware->h_ifindex == index) break; } } return hardware; @@ -172,8 +177,7 @@ lldpd_alloc_default_local_port(struct lldpd *cfg) { struct lldpd_port *port; - if ((port = (struct lldpd_port *) - calloc(1, sizeof(struct lldpd_port))) == NULL) + if ((port = (struct lldpd_port *)calloc(1, sizeof(struct lldpd_port))) == NULL) fatal("main", NULL); #ifdef ENABLE_DOT1 @@ -197,7 +201,7 @@ lldpd_clone_port(struct lldpd_port *destination, struct lldpd_port *source) u_int8_t *output = NULL; ssize_t output_len; struct lldpd_port *cloned = NULL; - output_len = lldpd_port_serialize(source, (void**)&output); + output_len = lldpd_port_serialize(source, (void **)&output); if (output_len == -1 || lldpd_port_unserialize(output, output_len, &cloned) <= 0) { log_warnx("alloc", "unable to clone default port"); @@ -225,8 +229,8 @@ lldpd_alloc_hardware(struct lldpd *cfg, char *name, int index) log_debug("alloc", "allocate a new local port (%s)", name); - if ((hardware = (struct lldpd_hardware *) - calloc(1, sizeof(struct lldpd_hardware))) == NULL) + if ((hardware = (struct lldpd_hardware *)calloc(1, + sizeof(struct lldpd_hardware))) == NULL) return NULL; /* Clone default local port */ @@ -302,30 +306,27 @@ lldpd_display_neighbors(struct lldpd *cfg) { if (!cfg->g_config.c_set_ifdescr) return; struct lldpd_hardware *hardware; - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { struct lldpd_port *port; char *description; const char *neighbor = NULL; unsigned neighbors = 0; - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (SMART_HIDDEN(port)) continue; neighbors++; neighbor = port->p_chassis->c_name; } if (neighbors == 0) - priv_iface_description(hardware->h_ifname, - ""); + priv_iface_description(hardware->h_ifname, ""); else if (neighbors == 1 && neighbor && *neighbor != '\0') { - if (asprintf(&description, "%s", - neighbor) != -1) { + if (asprintf(&description, "%s", neighbor) != -1) { priv_iface_description(hardware->h_ifname, description); free(description); } } else { - if (asprintf(&description, "%d neighbor%s", - neighbors, (neighbors > 1)?"s":"") != -1) { - priv_iface_description(hardware->h_ifname, - description); + if (asprintf(&description, "%d neighbor%s", neighbors, + (neighbors > 1) ? "s" : "") != -1) { + priv_iface_description(hardware->h_ifname, description); free(description); } } @@ -339,7 +340,7 @@ lldpd_count_neighbors(struct lldpd *cfg) struct lldpd_chassis *chassis; const char *neighbor; unsigned neighbors = 0; - TAILQ_FOREACH(chassis, &cfg->g_chassis, c_entries) { + TAILQ_FOREACH (chassis, &cfg->g_chassis, c_entries) { neighbors++; neighbor = chassis->c_name; } @@ -349,21 +350,17 @@ lldpd_count_neighbors(struct lldpd *cfg) else if (neighbors == 1 && neighbor && *neighbor != '\0') setproctitle("connected to %s.", neighbor); else - setproctitle("%d neighbor%s.", neighbors, - (neighbors > 1)?"s":""); + setproctitle("%d neighbor%s.", neighbors, (neighbors > 1) ? "s" : ""); #endif lldpd_display_neighbors(cfg); } static void -notify_clients_deletion(struct lldpd_hardware *hardware, - struct lldpd_port *rport) +notify_clients_deletion(struct lldpd_hardware *hardware, struct lldpd_port *rport) { - TRACE(LLDPD_NEIGHBOR_DELETE(hardware->h_ifname, - rport->p_chassis->c_name, - rport->p_descr)); - levent_ctl_notify(hardware->h_ifname, NEIGHBOR_CHANGE_DELETED, - rport); + TRACE(LLDPD_NEIGHBOR_DELETE(hardware->h_ifname, rport->p_chassis->c_name, + rport->p_descr)); + levent_ctl_notify(hardware->h_ifname, NEIGHBOR_CHANGE_DELETED, rport); #ifdef USE_SNMP agent_notify(hardware, NEIGHBOR_CHANGE_DELETED, rport); #endif @@ -374,7 +371,7 @@ lldpd_reset_timer(struct lldpd *cfg) { /* Reset timer for ports that have been changed. */ struct lldpd_hardware *hardware; - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { /* We keep a flat copy of the local port to see if there is any * change. To do this, we zero out fields that are not * significant, marshal the port, then restore. */ @@ -388,7 +385,7 @@ lldpd_reset_timer(struct lldpd *cfg) /* coverity[sizeof_mismatch] We intentionally partially memset port */ memset(port, 0, sizeof(save)); - output_len = lldpd_port_serialize(port, (void**)&output); + output_len = lldpd_port_serialize(port, (void **)&output); memcpy(port, save, sizeof(save)); if (output_len == -1) { log_warnx("localchassis", @@ -398,12 +395,10 @@ lldpd_reset_timer(struct lldpd *cfg) } /* Compare with the previous value */ - if (!hardware->h_ifindex_changed && - hardware->h_lport_previous && + if (!hardware->h_ifindex_changed && hardware->h_lport_previous && output_len == hardware->h_lport_previous_len && !memcmp(output, hardware->h_lport_previous, output_len)) { - log_debug("localchassis", - "no change detected for port %s", + log_debug("localchassis", "no change detected for port %s", hardware->h_ifname); } else { log_debug("localchassis", @@ -426,8 +421,7 @@ lldpd_all_chassis_cleanup(struct lldpd *cfg) struct lldpd_chassis *chassis, *chassis_next; log_debug("localchassis", "cleanup all chassis"); - for (chassis = TAILQ_FIRST(&cfg->g_chassis); chassis; - chassis = chassis_next) { + for (chassis = TAILQ_FIRST(&cfg->g_chassis); chassis; chassis = chassis_next) { chassis_next = TAILQ_NEXT(chassis, c_entries); if (chassis->c_refcount == 0) { TAILQ_REMOVE(&cfg->g_chassis, chassis, c_entries); @@ -447,23 +441,27 @@ lldpd_cleanup(struct lldpd *cfg) hardware = hardware_next) { hardware_next = TAILQ_NEXT(hardware, h_entries); if (!hardware->h_flags) { - int m = cfg->g_config.c_perm_ifaces? - pattern_match(hardware->h_ifname, cfg->g_config.c_perm_ifaces, 0): + int m = cfg->g_config.c_perm_ifaces ? + pattern_match(hardware->h_ifname, + cfg->g_config.c_perm_ifaces, 0) : 0; switch (m) { case PATTERN_MATCH_DENIED: - log_debug("localchassis", "delete non-permanent interface %s", + log_debug("localchassis", + "delete non-permanent interface %s", hardware->h_ifname); TRACE(LLDPD_INTERFACES_DELETE(hardware->h_ifname)); TAILQ_REMOVE(&cfg->g_hardware, hardware, h_entries); - lldpd_remote_cleanup(hardware, notify_clients_deletion, 1); + lldpd_remote_cleanup(hardware, notify_clients_deletion, + 1); lldpd_hardware_cleanup(cfg, hardware); break; case PATTERN_MATCH_ALLOWED: case PATTERN_MATCH_ALLOWED_EXACT: log_debug("localchassis", "do not delete %s, permanent", hardware->h_ifname); - lldpd_remote_cleanup(hardware, notify_clients_deletion, 1); + lldpd_remote_cleanup(hardware, notify_clients_deletion, + 1); break; } } else { @@ -480,8 +478,8 @@ lldpd_cleanup(struct lldpd *cfg) /* Update chassis `ochassis' with values from `chassis'. The later one is not expected to be part of a list! It will also be wiped from memory. */ static void -lldpd_move_chassis(struct lldpd_chassis *ochassis, - struct lldpd_chassis *chassis) { +lldpd_move_chassis(struct lldpd_chassis *ochassis, struct lldpd_chassis *chassis) +{ struct lldpd_mgmt *mgmt, *mgmt_next; /* We want to keep refcount, index and list stuff from the current @@ -489,8 +487,7 @@ lldpd_move_chassis(struct lldpd_chassis *ochassis, TAILQ_ENTRY(lldpd_chassis) entries; int refcount = ochassis->c_refcount; int index = ochassis->c_index; - memcpy(&entries, &ochassis->c_entries, - sizeof(entries)); + memcpy(&entries, &ochassis->c_entries, sizeof(entries)); lldpd_chassis_cleanup(ochassis, 0); /* Make the copy. */ @@ -500,9 +497,7 @@ lldpd_move_chassis(struct lldpd_chassis *ochassis, TAILQ_INIT(&ochassis->c_mgmt); /* Copy of management addresses */ - for (mgmt = TAILQ_FIRST(&chassis->c_mgmt); - mgmt != NULL; - mgmt = mgmt_next) { + for (mgmt = TAILQ_FIRST(&chassis->c_mgmt); mgmt != NULL; mgmt = mgmt_next) { mgmt_next = TAILQ_NEXT(mgmt, m_entries); TAILQ_REMOVE(&chassis->c_mgmt, mgmt, m_entries); TAILQ_INSERT_TAIL(&ochassis->c_mgmt, mgmt, m_entries); @@ -521,24 +516,25 @@ static int lldpd_guess_type(struct lldpd *cfg, char *frame, int s) { size_t i, j; - if (s < ETHER_ADDR_LEN) - return -1; + if (s < ETHER_ADDR_LEN) return -1; for (i = 0; cfg->g_protocols[i].mode != 0; i++) { - if (!cfg->g_protocols[i].enabled) - continue; + if (!cfg->g_protocols[i].enabled) continue; if (cfg->g_protocols[i].guess == NULL) { - for (j = 0; - j < sizeof(cfg->g_protocols[0].mac)/sizeof(cfg->g_protocols[0].mac[0]); + for (j = 0; j < sizeof(cfg->g_protocols[0].mac) / + sizeof(cfg->g_protocols[0].mac[0]); j++) { - if (memcmp(frame, cfg->g_protocols[i].mac[j], ETHER_ADDR_LEN) == 0) { - log_debug("decode", "guessed protocol is %s (from MAC address)", + if (memcmp(frame, cfg->g_protocols[i].mac[j], + ETHER_ADDR_LEN) == 0) { + log_debug("decode", + "guessed protocol is %s (from MAC address)", cfg->g_protocols[i].name); return cfg->g_protocols[i].mode; } } } else { if (cfg->g_protocols[i].guess(frame, s)) { - log_debug("decode", "guessed protocol is %s (from detector function)", + log_debug("decode", + "guessed protocol is %s (from detector function)", cfg->g_protocols[i].name); return cfg->g_protocols[i].mode; } @@ -548,16 +544,14 @@ lldpd_guess_type(struct lldpd *cfg, char *frame, int s) } static void -lldpd_decode(struct lldpd *cfg, char *frame, int s, - struct lldpd_hardware *hardware) +lldpd_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardware) { int i; struct lldpd_chassis *chassis, *ochassis = NULL; struct lldpd_port *port, *oport = NULL, *aport; int guess = LLDPD_MODE_LLDP; - log_debug("decode", "decode a received frame on %s", - hardware->h_ifname); + log_debug("decode", "decode a received frame on %s", hardware->h_ifname); if (s < sizeof(struct ether_header) + 4) { /* Too short, just discard it */ @@ -571,13 +565,13 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, if (eheader.ether_type == htons(ETHERTYPE_VLAN)) { /* VLAN decapsulation means to shift 4 bytes left the frame from * offset 2*ETHER_ADDR_LEN */ - memmove(frame + 2*ETHER_ADDR_LEN, frame + 2*ETHER_ADDR_LEN + 4, s - 2*ETHER_ADDR_LEN); + memmove(frame + 2 * ETHER_ADDR_LEN, frame + 2 * ETHER_ADDR_LEN + 4, + s - 2 * ETHER_ADDR_LEN); s -= 4; } - TAILQ_FOREACH(oport, &hardware->h_rports, p_entries) { - if ((oport->p_lastframe != NULL) && - (oport->p_lastframe->size == s) && + TAILQ_FOREACH (oport, &hardware->h_rports, p_entries) { + if ((oport->p_lastframe != NULL) && (oport->p_lastframe->size == s) && (memcmp(oport->p_lastframe->frame, frame, s) == 0)) { /* Already received the same frame */ log_debug("decode", "duplicate frame, no need to decode"); @@ -587,15 +581,15 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, } guess = lldpd_guess_type(cfg, frame, s); - for (i=0; cfg->g_protocols[i].mode != 0; i++) { - if (!cfg->g_protocols[i].enabled) - continue; + for (i = 0; cfg->g_protocols[i].mode != 0; i++) { + if (!cfg->g_protocols[i].enabled) continue; if (cfg->g_protocols[i].mode == guess) { log_debug("decode", "using decode function for %s protocol", cfg->g_protocols[i].name); - if (cfg->g_protocols[i].decode(cfg, frame, - s, hardware, &chassis, &port) == -1) { - log_debug("decode", "function for %s protocol did not decode this frame", + if (cfg->g_protocols[i].decode(cfg, frame, s, hardware, + &chassis, &port) == -1) { + log_debug("decode", + "function for %s protocol did not decode this frame", cfg->g_protocols[i].name); hardware->h_rx_discarded_cnt++; return; @@ -603,23 +597,20 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, chassis->c_protocol = port->p_protocol = cfg->g_protocols[i].mode; break; - } + } } if (cfg->g_protocols[i].mode == 0) { log_debug("decode", "unable to guess frame type on %s", hardware->h_ifname); return; } - TRACE(LLDPD_FRAME_DECODED( - hardware->h_ifname, - cfg->g_protocols[i].name, - chassis->c_name, - port->p_descr)); + TRACE(LLDPD_FRAME_DECODED(hardware->h_ifname, cfg->g_protocols[i].name, + chassis->c_name, port->p_descr)); /* Do we already have the same MSAP somewhere? */ int count = 0; log_debug("decode", "search for the same MSAP"); - TAILQ_FOREACH(oport, &hardware->h_rports, p_entries) { + TAILQ_FOREACH (oport, &hardware->h_rports, p_entries) { if (port->p_protocol == oport->p_protocol) { count++; if ((port->p_id_subtype == oport->p_id_subtype) && @@ -628,7 +619,7 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, (chassis->c_id_subtype == oport->p_chassis->c_id_subtype) && (chassis->c_id_len == oport->p_chassis->c_id_len) && (memcmp(chassis->c_id, oport->p_chassis->c_id, - chassis->c_id_len) == 0)) { + chassis->c_id_len) == 0)) { ochassis = oport->p_chassis; log_debug("decode", "MSAP is already known"); break; @@ -637,32 +628,31 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, } /* Do we have room for a new MSAP? */ if (!oport && cfg->g_config.c_max_neighbors) { - if (count == (cfg->g_config.c_max_neighbors - 1)) { - log_debug("decode", - "max neighbors %d reached for port %s, " - "dropping any new ones silently", - cfg->g_config.c_max_neighbors, - hardware->h_ifname); - } else if (count > cfg->g_config.c_max_neighbors - 1) { - log_debug("decode", - "too many neighbors for port %s, drop this new one", - hardware->h_ifname); - lldpd_port_cleanup(port, 1); - lldpd_chassis_cleanup(chassis, 1); - free(port); - return; - } + if (count == (cfg->g_config.c_max_neighbors - 1)) { + log_debug("decode", + "max neighbors %d reached for port %s, " + "dropping any new ones silently", + cfg->g_config.c_max_neighbors, hardware->h_ifname); + } else if (count > cfg->g_config.c_max_neighbors - 1) { + log_debug("decode", + "too many neighbors for port %s, drop this new one", + hardware->h_ifname); + lldpd_port_cleanup(port, 1); + lldpd_chassis_cleanup(chassis, 1); + free(port); + return; + } } /* No, but do we already know the system? */ if (!oport) { log_debug("decode", "MSAP is unknown, search for the chassis"); - TAILQ_FOREACH(ochassis, &cfg->g_chassis, c_entries) { + TAILQ_FOREACH (ochassis, &cfg->g_chassis, c_entries) { if ((chassis->c_protocol == ochassis->c_protocol) && (chassis->c_id_subtype == ochassis->c_id_subtype) && (chassis->c_id_len == ochassis->c_id_len) && - (memcmp(chassis->c_id, ochassis->c_id, - chassis->c_id_len) == 0)) - break; + (memcmp(chassis->c_id, ochassis->c_id, chassis->c_id_len) == + 0)) + break; } } @@ -688,13 +678,15 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, chassis->c_index = ++cfg->g_lastrid; chassis->c_refcount = 0; TAILQ_INSERT_TAIL(&cfg->g_chassis, chassis, c_entries); - i = 0; TAILQ_FOREACH(ochassis, &cfg->g_chassis, c_entries) i++; + i = 0; + TAILQ_FOREACH (ochassis, &cfg->g_chassis, c_entries) + i++; log_debug("decode", "%d different systems are known", i); } /* Add port */ port->p_lastchange = port->p_lastupdate = time(NULL); - if ((port->p_lastframe = (struct lldpd_frame *)malloc(s + - sizeof(struct lldpd_frame))) != NULL) { + if ((port->p_lastframe = (struct lldpd_frame *)malloc( + s + sizeof(struct lldpd_frame))) != NULL) { port->p_lastframe->size = s; memcpy(port->p_lastframe->frame, frame, s); } @@ -703,12 +695,12 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, port->p_chassis->c_refcount++; /* Several cases are possible : 1. chassis is new, its refcount was 0. It is now attached - to this port, its refcount is 1. + to this port, its refcount is 1. 2. chassis already exists and was attached to another - port, we increase its refcount accordingly. + port, we increase its refcount accordingly. 3. chassis already exists and was attached to the same - port, its refcount was decreased with - lldpd_port_cleanup() and is now increased again. + port, its refcount was decreased with + lldpd_port_cleanup() and is now increased again. In all cases, if the port already existed, it has been freed with lldpd_port_cleanup() and therefore, the refcount @@ -717,30 +709,24 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, i = 0; /* coverity[use_after_free] TAILQ_REMOVE does the right thing */ - TAILQ_FOREACH(aport, &hardware->h_rports, p_entries) + TAILQ_FOREACH (aport, &hardware->h_rports, p_entries) i++; - log_debug("decode", "%d neighbors for %s", i, - hardware->h_ifname); + log_debug("decode", "%d neighbors for %s", i, hardware->h_ifname); if (!oport) hardware->h_insert_cnt++; /* Notify */ - log_debug("decode", "send notifications for changes on %s", - hardware->h_ifname); + log_debug("decode", "send notifications for changes on %s", hardware->h_ifname); if (oport) { - TRACE(LLDPD_NEIGHBOR_UPDATE(hardware->h_ifname, - chassis->c_name, - port->p_descr, - i)); + TRACE(LLDPD_NEIGHBOR_UPDATE(hardware->h_ifname, chassis->c_name, + port->p_descr, i)); levent_ctl_notify(hardware->h_ifname, NEIGHBOR_CHANGE_UPDATED, port); #ifdef USE_SNMP agent_notify(hardware, NEIGHBOR_CHANGE_UPDATED, port); #endif } else { - TRACE(LLDPD_NEIGHBOR_NEW(hardware->h_ifname, - chassis->c_name, - port->p_descr, - i)); + TRACE(LLDPD_NEIGHBOR_NEW(hardware->h_ifname, chassis->c_name, + port->p_descr, i)); levent_ctl_notify(hardware->h_ifname, NEIGHBOR_CHANGE_ADDED, port); #ifdef USE_SNMP agent_notify(hardware, NEIGHBOR_CHANGE_ADDED, port); @@ -752,8 +738,10 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, /* New neighbor, fast start */ if (hardware->h_cfg->g_config.c_enable_fast_start && !hardware->h_tx_fast) { - log_debug("decode", "%s: entering fast start due to " - "new neighbor", hardware->h_ifname); + log_debug("decode", + "%s: entering fast start due to " + "new neighbor", + hardware->h_ifname); hardware->h_tx_fast = hardware->h_cfg->g_config.c_tx_fast_init; } @@ -768,7 +756,8 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, called once. It return NULL if any problem happens. Otherwise, this is a statically allocated buffer. The result includes the trailing \n */ static char * -lldpd_get_lsb_release() { +lldpd_get_lsb_release() +{ static char release[1024]; char *const command[] = { "lsb_release", "-s", "-d", NULL }; int pid, status, devnull, count; @@ -804,10 +793,10 @@ lldpd_get_lsb_release() { close(pipefd[1]); count = 0; do { - status = read(pipefd[0], release+count, sizeof(release)-count); + status = + read(pipefd[0], release + count, sizeof(release) - count); if ((status == -1) && (errno == EINTR)) continue; - if (status > 0) - count += status; + if (status > 0) count += status; } while (count < sizeof(release) && (status > 0)); if (status < 0) { log_info("localchassis", "unable to read from lsb_release"); @@ -822,14 +811,15 @@ lldpd_get_lsb_release() { return NULL; } status = -1; - if (waitpid(pid, &status, 0) != pid) - return NULL; + if (waitpid(pid, &status, 0) != pid) return NULL; if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) { - log_info("localchassis", "lsb_release information not available"); + log_info("localchassis", + "lsb_release information not available"); return NULL; } if (!count) { - log_info("localchassis", "lsb_release returned an empty string"); + log_info("localchassis", + "lsb_release returned an empty string"); return NULL; } release[count] = '\0'; @@ -841,7 +831,8 @@ lldpd_get_lsb_release() { /* Same like lldpd_get_lsb_release but reads /etc/os-release for PRETTY_NAME=. */ static char * -lldpd_get_os_release() { +lldpd_get_os_release() +{ static char release[1024]; char line[1024]; char *key, *val; @@ -872,30 +863,29 @@ lldpd_get_os_release() { /* Remove trailing newline and all " in the string. */ ptr1 = release + strlen(release) - 1; - while (ptr1 != release && - ((*ptr1 == '"') || (*ptr1 == '\n'))) { + while (ptr1 != release && ((*ptr1 == '"') || (*ptr1 == '\n'))) { *ptr1 = '\0'; ptr1--; } - if (release[0] == '"') - return release+1; + if (release[0] == '"') return release + 1; return release; } static void -lldpd_hide_ports(struct lldpd *cfg, struct lldpd_hardware *hardware, int mask) { +lldpd_hide_ports(struct lldpd *cfg, struct lldpd_hardware *hardware, int mask) +{ struct lldpd_port *port; - int protocols[LLDPD_MODE_MAX+1]; + int protocols[LLDPD_MODE_MAX + 1]; char buffer[256]; int i, j, k, found; unsigned int min; - log_debug("smartfilter", "apply smart filter for port %s", - hardware->h_ifname); + log_debug("smartfilter", "apply smart filter for port %s", hardware->h_ifname); /* Compute the number of occurrences of each protocol */ - for (i = 0; i <= LLDPD_MODE_MAX; i++) protocols[i] = 0; - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) + for (i = 0; i <= LLDPD_MODE_MAX; i++) + protocols[i] = 0; + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) protocols[port->p_protocol]++; /* Turn the protocols[] array into an array of @@ -903,8 +893,7 @@ lldpd_hide_ports(struct lldpd *cfg, struct lldpd_hardware *hardware, int mask) { means disabled. */ min = (unsigned int)-1; for (i = 0; i <= LLDPD_MODE_MAX; i++) - if (protocols[i] && (protocols[i] < min)) - min = protocols[i]; + if (protocols[i] && (protocols[i] < min)) min = protocols[i]; found = 0; for (i = 0; i <= LLDPD_MODE_MAX; i++) if ((protocols[i] == min) && !found) { @@ -914,65 +903,65 @@ lldpd_hide_ports(struct lldpd *cfg, struct lldpd_hardware *hardware, int mask) { (SMART_OUTGOING_ONE_PROTO | SMART_INCOMING_ONE_PROTO)) found = 1; protocols[i] = 1; - } else protocols[i] = 0; + } else + protocols[i] = 0; /* We set the p_hidden flag to 1 if the protocol is disabled */ - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (mask == SMART_OUTGOING) - port->p_hidden_out = protocols[port->p_protocol]?0:1; + port->p_hidden_out = protocols[port->p_protocol] ? 0 : 1; else - port->p_hidden_in = protocols[port->p_protocol]?0:1; + port->p_hidden_in = protocols[port->p_protocol] ? 0 : 1; } /* If we want only one neighbor, we take the first one */ if (cfg->g_config.c_smart & mask & (SMART_OUTGOING_ONE_NEIGH | SMART_INCOMING_ONE_NEIGH)) { found = 0; - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (mask == SMART_OUTGOING) { if (found) port->p_hidden_out = 1; - if (!port->p_hidden_out) - found = 1; + if (!port->p_hidden_out) found = 1; } if (mask == SMART_INCOMING) { if (found) port->p_hidden_in = 1; - if (!port->p_hidden_in) - found = 1; + if (!port->p_hidden_in) found = 1; } } } /* Print a debug message summarizing the operation */ - for (i = 0; i <= LLDPD_MODE_MAX; i++) protocols[i] = 0; + for (i = 0; i <= LLDPD_MODE_MAX; i++) + protocols[i] = 0; k = j = 0; - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { if (!(((mask == SMART_OUTGOING) && port->p_hidden_out) || - ((mask == SMART_INCOMING) && port->p_hidden_in))) { + ((mask == SMART_INCOMING) && port->p_hidden_in))) { k++; protocols[port->p_protocol] = 1; } j++; } buffer[0] = '\0'; - for (i=0; cfg->g_protocols[i].mode != 0; i++) { - if (cfg->g_protocols[i].enabled && protocols[cfg->g_protocols[i].mode]) { - if (strlen(buffer) + - strlen(cfg->g_protocols[i].name) + 3 > sizeof(buffer)) { + for (i = 0; cfg->g_protocols[i].mode != 0; i++) { + if (cfg->g_protocols[i].enabled && + protocols[cfg->g_protocols[i].mode]) { + if (strlen(buffer) + strlen(cfg->g_protocols[i].name) + 3 > + sizeof(buffer)) { /* Unlikely, our buffer is too small */ memcpy(buffer + sizeof(buffer) - 4, "...", 4); break; } - if (buffer[0]) - strncat(buffer, ", ", 2); - strncat(buffer, cfg->g_protocols[i].name, strlen(cfg->g_protocols[i].name)); + if (buffer[0]) strncat(buffer, ", ", 2); + strncat(buffer, cfg->g_protocols[i].name, + strlen(cfg->g_protocols[i].name)); } } log_debug("smartfilter", "%s: %s: %d visible neighbors (out of %d)", - hardware->h_ifname, - (mask == SMART_OUTGOING)?"out filter":"in filter", + hardware->h_ifname, (mask == SMART_OUTGOING) ? "out filter" : "in filter", k, j); - log_debug("smartfilter", "%s: protocols: %s", - hardware->h_ifname, buffer[0]?buffer:"(none)"); + log_debug("smartfilter", "%s: protocols: %s", hardware->h_ifname, + buffer[0] ? buffer : "(none)"); } /* Hide unwanted ports depending on smart mode set by the user */ @@ -981,10 +970,9 @@ lldpd_hide_all(struct lldpd *cfg) { struct lldpd_hardware *hardware; - if (!cfg->g_config.c_smart) - return; + if (!cfg->g_config.c_smart) return; log_debug("smartfilter", "apply smart filter results on all ports"); - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) { if (cfg->g_config.c_smart & SMART_INCOMING_FILTER) lldpd_hide_ports(cfg, hardware, SMART_INCOMING); if (cfg->g_config.c_smart & SMART_OUTGOING_FILTER) @@ -1000,36 +988,40 @@ lldpd_dot3_power_pd_pse(struct lldpd_hardware *hardware) #ifdef ENABLE_DOT3 struct lldpd_port *port, *selected_port = NULL; /* Are we a PD device? */ - if (hardware->h_lport.p_power.devicetype != LLDP_DOT3_POWER_PD) - return; - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { - if (port->p_hidden_in) - continue; + if (hardware->h_lport.p_power.devicetype != LLDP_DOT3_POWER_PD) return; + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { + if (port->p_hidden_in) continue; - if (port->p_protocol != LLDPD_MODE_LLDP && port->p_protocol != LLDPD_MODE_CDPV2) + if (port->p_protocol != LLDPD_MODE_LLDP && + port->p_protocol != LLDPD_MODE_CDPV2) continue; - if (port->p_power.devicetype != LLDP_DOT3_POWER_PSE) - continue; + if (port->p_power.devicetype != LLDP_DOT3_POWER_PSE) continue; if (!selected_port || port->p_lastupdate > selected_port->p_lastupdate) selected_port = port; } - if (selected_port && selected_port->p_power.allocated != hardware->h_lport.p_power.allocated) { - log_info("receive", "for %s, PSE told us allocated is now %d instead of %d", - hardware->h_ifname, - selected_port->p_power.allocated, + if (selected_port && + selected_port->p_power.allocated != hardware->h_lport.p_power.allocated) { + log_info("receive", + "for %s, PSE told us allocated is now %d instead of %d", + hardware->h_ifname, selected_port->p_power.allocated, hardware->h_lport.p_power.allocated); hardware->h_lport.p_power.allocated = selected_port->p_power.allocated; - hardware->h_lport.p_power.allocated_a = selected_port->p_power.allocated_a; - hardware->h_lport.p_power.allocated_b = selected_port->p_power.allocated_b; + hardware->h_lport.p_power.allocated_a = + selected_port->p_power.allocated_a; + hardware->h_lport.p_power.allocated_b = + selected_port->p_power.allocated_b; levent_schedule_pdu(hardware); } -#ifdef ENABLE_CDP - if (selected_port && selected_port->p_cdp_power.management_id != hardware->h_lport.p_cdp_power.management_id) { - hardware->h_lport.p_cdp_power.management_id = selected_port->p_cdp_power.management_id; +# ifdef ENABLE_CDP + if (selected_port && + selected_port->p_cdp_power.management_id != + hardware->h_lport.p_cdp_power.management_id) { + hardware->h_lport.p_cdp_power.management_id = + selected_port->p_cdp_power.management_id; } -#endif +# endif #endif } @@ -1039,15 +1031,13 @@ lldpd_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, int fd) { char *buffer = NULL; int n; - log_debug("receive", "receive a frame on %s", - hardware->h_ifname); + log_debug("receive", "receive a frame on %s", hardware->h_ifname); if ((buffer = (char *)malloc(hardware->h_mtu)) == NULL) { log_warn("receive", "failed to alloc reception buffer"); return; } - if ((n = hardware->h_ops->recv(cfg, hardware, - fd, buffer, - hardware->h_mtu)) == -1) { + if ((n = hardware->h_ops->recv(cfg, hardware, fd, buffer, hardware->h_mtu)) == + -1) { log_debug("receive", "discard frame received on %s", hardware->h_ifname); free(buffer); @@ -1061,13 +1051,12 @@ lldpd_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, int fd) } if (cfg->g_config.c_paused) { log_debug("receive", "paused, ignore the frame on %s", - hardware->h_ifname); + hardware->h_ifname); free(buffer); return; } hardware->h_rx_cnt++; - log_debug("receive", "decode received frame on %s", - hardware->h_ifname); + log_debug("receive", "decode received frame on %s", hardware->h_ifname); TRACE(LLDPD_FRAME_RECEIVED(hardware->h_ifname, buffer, (size_t)n)); lldpd_decode(cfg, buffer, n, hardware); lldpd_hide_all(cfg); /* Immediatly hide */ @@ -1082,8 +1071,7 @@ lldpd_send_shutdown(struct lldpd_hardware *hardware) struct lldpd *cfg = hardware->h_cfg; if (cfg->g_config.c_receiveonly || cfg->g_config.c_paused) return; if (hardware->h_lport.p_disable_tx) return; - if ((hardware->h_flags & IFF_RUNNING) == 0) - return; + if ((hardware->h_flags & IFF_RUNNING) == 0) return; /* It's safe to call `lldp_send_shutdown()` because shutdown LLDPU will * only be emitted if LLDP was sent on that port. */ @@ -1101,14 +1089,12 @@ lldpd_send(struct lldpd_hardware *hardware) if (cfg->g_config.c_receiveonly || cfg->g_config.c_paused) return; if (hardware->h_lport.p_disable_tx) return; - if ((hardware->h_flags & IFF_RUNNING) == 0) - return; + if ((hardware->h_flags & IFF_RUNNING) == 0) return; log_debug("send", "send PDU on %s", hardware->h_ifname); sent = 0; - for (i=0; cfg->g_protocols[i].mode != 0; i++) { - if (!cfg->g_protocols[i].enabled) - continue; + for (i = 0; cfg->g_protocols[i].mode != 0; i++) { + if (!cfg->g_protocols[i].enabled) continue; /* We send only if we have at least one remote system * speaking this protocol or if the protocol is forced */ if (cfg->g_protocols[i].enabled > 1) { @@ -1116,20 +1102,16 @@ lldpd_send(struct lldpd_hardware *hardware) sent++; continue; } - TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + TAILQ_FOREACH (port, &hardware->h_rports, p_entries) { /* If this remote port is disabled, we don't * consider it */ - if (port->p_hidden_out) - continue; - if (port->p_protocol == - cfg->g_protocols[i].mode) { + if (port->p_hidden_out) continue; + if (port->p_protocol == cfg->g_protocols[i].mode) { TRACE(LLDPD_FRAME_SEND(hardware->h_ifname, - cfg->g_protocols[i].name)); + cfg->g_protocols[i].name)); log_debug("send", "send PDU on %s with protocol %s", - hardware->h_ifname, - cfg->g_protocols[i].name); - cfg->g_protocols[i].send(cfg, - hardware); + hardware->h_ifname, cfg->g_protocols[i].name); + cfg->g_protocols[i].send(cfg, hardware); hardware->h_lport.p_protocol = cfg->g_protocols[i].mode; sent++; break; @@ -1143,11 +1125,10 @@ lldpd_send(struct lldpd_hardware *hardware) for (i = 0; cfg->g_protocols[i].mode != 0; i++) { if (!cfg->g_protocols[i].enabled) continue; TRACE(LLDPD_FRAME_SEND(hardware->h_ifname, - cfg->g_protocols[i].name)); + cfg->g_protocols[i].name)); log_debug("send", "fallback to protocol %s for %s", cfg->g_protocols[i].name, hardware->h_ifname); - cfg->g_protocols[i].send(cfg, - hardware); + cfg->g_protocols[i].send(cfg, hardware); break; } if (cfg->g_protocols[i].mode == 0) @@ -1186,8 +1167,7 @@ lldpd_routing_enabled(struct lldpd *cfg) { int routing; - if ((LOCAL_CHASSIS(cfg)->c_cap_available & LLDP_CAP_ROUTER) == 0) - return 0; + if ((LOCAL_CHASSIS(cfg)->c_cap_available & LLDP_CAP_ROUTER) == 0) return 0; if ((routing = interfaces_routing_enabled(cfg)) == -1) { log_debug("localchassis", "unable to check if routing is enabled"); @@ -1206,10 +1186,10 @@ lldpd_update_localchassis(struct lldpd *cfg) assert(LOCAL_CHASSIS(cfg) != NULL); /* Set system name and description */ - if (uname(&un) < 0) - fatal("localchassis", "failed to get system information"); + if (uname(&un) < 0) fatal("localchassis", "failed to get system information"); if (cfg->g_config.c_hostname) { - log_debug("localchassis", "use overridden system name `%s`", cfg->g_config.c_hostname); + log_debug("localchassis", "use overridden system name `%s`", + cfg->g_config.c_hostname); hp = cfg->g_config.c_hostname; } else { if ((hp = priv_gethostname()) == NULL) @@ -1219,33 +1199,37 @@ lldpd_update_localchassis(struct lldpd *cfg) free(LOCAL_CHASSIS(cfg)->c_descr); if ((LOCAL_CHASSIS(cfg)->c_name = strdup(hp)) == NULL) fatal("localchassis", NULL); - if (cfg->g_config.c_description) { - log_debug("localchassis", "use overridden description `%s`", cfg->g_config.c_description); - if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s", + if (cfg->g_config.c_description) { + log_debug("localchassis", "use overridden description `%s`", + cfg->g_config.c_description); + if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s", cfg->g_config.c_description) == -1) fatal("localchassis", "failed to set full system description"); - } else { - if (cfg->g_config.c_advertise_version) { + } else { + if (cfg->g_config.c_advertise_version) { log_debug("localchassis", "advertise system version"); - if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s %s %s %s %s", - cfg->g_lsb_release?cfg->g_lsb_release:"", - un.sysname, un.release, un.version, un.machine) - == -1) - fatal("localchassis", "failed to set full system description"); - } else { + if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s %s %s %s %s", + cfg->g_lsb_release ? cfg->g_lsb_release : "", + un.sysname, un.release, un.version, un.machine) == -1) + fatal("localchassis", + "failed to set full system description"); + } else { log_debug("localchassis", "do not advertise system version"); - if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s", - cfg->g_lsb_release?cfg->g_lsb_release:un.sysname) == -1) - fatal("localchassis", "failed to set minimal system description"); - } - } + if (asprintf(&LOCAL_CHASSIS(cfg)->c_descr, "%s", + cfg->g_lsb_release ? cfg->g_lsb_release : un.sysname) == + -1) + fatal("localchassis", + "failed to set minimal system description"); + } + } if (cfg->g_config.c_platform == NULL) cfg->g_config.c_platform = strdup(un.sysname); if (!cfg->g_config.c_cap_override) { /* Check routing */ if (lldpd_routing_enabled(cfg)) { - log_debug("localchassis", "routing is enabled, enable router capability"); + log_debug("localchassis", + "routing is enabled, enable router capability"); LOCAL_CHASSIS(cfg)->c_cap_enabled |= LLDP_CAP_ROUTER; } else LOCAL_CHASSIS(cfg)->c_cap_enabled &= ~LLDP_CAP_ROUTER; @@ -1275,7 +1259,8 @@ lldpd_update_localchassis(struct lldpd *cfg) LOCAL_CHASSIS(cfg)->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL; } if (LOCAL_CHASSIS(cfg)->c_id == NULL) { - log_debug("localchassis", "no chassis ID is currently set, use chassis name"); + log_debug("localchassis", + "no chassis ID is currently set, use chassis name"); if (!(LOCAL_CHASSIS(cfg)->c_id = strdup(LOCAL_CHASSIS(cfg)->c_name))) fatal("localchassis", NULL); LOCAL_CHASSIS(cfg)->c_id_len = strlen(LOCAL_CHASSIS(cfg)->c_name); @@ -1293,8 +1278,8 @@ lldpd_update_localports(struct lldpd *cfg) /* h_flags is set to 0 for each port. If the port is updated, h_flags * will be set to a non-zero value. This will allow us to clean up any * non up-to-date port */ - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) - hardware->h_flags = 0; + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) + hardware->h_flags = 0; TRACE(LLDPD_INTERFACES_UPDATE()); interfaces_update(cfg); @@ -1310,8 +1295,7 @@ lldpd_loop(struct lldpd *cfg) 2. Update local chassis information */ log_debug("loop", "start new loop"); - if(!cfg->g_config.c_cap_override) - LOCAL_CHASSIS(cfg)->c_cap_enabled = 0; + if (!cfg->g_config.c_cap_override) LOCAL_CHASSIS(cfg)->c_cap_enabled = 0; /* Information for local ports is triggered even when it is possible to * update them on some other event because we want to refresh them if we * missed something. */ @@ -1329,7 +1313,7 @@ lldpd_exit(struct lldpd *cfg) struct lldpd_hardware *hardware, *hardware_next; log_debug("main", "exit lldpd"); - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) + TAILQ_FOREACH (hardware, &cfg->g_hardware, h_entries) lldpd_send_shutdown(hardware); if (asprintf(&lockname, "%s.lock", cfg->g_ctlname) != -1) { @@ -1360,7 +1344,8 @@ lldpd_exit(struct lldpd *cfg) * @return PID of running lldpcli or -1 if error. */ static pid_t -lldpd_configure(int use_syslog, int debug, const char *path, const char *ctlname, const char *config_path) +lldpd_configure(int use_syslog, int debug, const char *path, const char *ctlname, + const char *config_path) { pid_t lldpcli = vfork(); int devnull; @@ -1374,7 +1359,8 @@ lldpd_configure(int use_syslog, int debug, const char *path, const char *ctlname /* debug = 2 -> -sddd */ memset(sdebug, 'd', sizeof(sdebug)); sdebug[debug + 3] = '\0'; - sdebug[0] = '-'; sdebug[1] = 's'; + sdebug[0] = '-'; + sdebug[1] = 's'; } log_debug("main", "invoke %s %s", path, sdebug); @@ -1385,27 +1371,22 @@ lldpd_configure(int use_syslog, int debug, const char *path, const char *ctlname case 0: /* Child, exec lldpcli */ if ((devnull = open("/dev/null", O_RDWR, 0)) != -1) { - dup2(devnull, STDIN_FILENO); - dup2(devnull, STDOUT_FILENO); + dup2(devnull, STDIN_FILENO); + dup2(devnull, STDOUT_FILENO); if (devnull > 2) close(devnull); if (config_path) { - execl(path, "lldpcli", sdebug, - "-u", ctlname, - "-C", config_path, - "resume", - (char *)NULL); + execl(path, "lldpcli", sdebug, "-u", ctlname, "-C", + config_path, "resume", (char *)NULL); } else { - execl(path, "lldpcli", sdebug, - "-u", ctlname, - "-C", SYSCONFDIR "/lldpd.conf", - "-C", SYSCONFDIR "/lldpd.d", - "resume", - (char *)NULL); + execl(path, "lldpcli", sdebug, "-u", ctlname, "-C", + SYSCONFDIR "/lldpd.conf", "-C", + SYSCONFDIR "/lldpd.d", "resume", (char *)NULL); } log_warn("main", "unable to execute %s", path); - log_warnx("main", "configuration is incomplete, lldpd needs to be unpaused"); + log_warnx("main", + "configuration is incomplete, lldpd needs to be unpaused"); } _exit(127); break; @@ -1417,41 +1398,52 @@ lldpd_configure(int use_syslog, int debug, const char *path, const char *ctlname return -1; } -struct intint { int a; int b; }; -static const struct intint filters[] = { - { 0, 0 }, - { 1, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | - SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_PROTO }, - { 2, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO }, - { 3, SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_PROTO }, - { 4, SMART_INCOMING_FILTER | SMART_OUTGOING_FILTER }, - { 5, SMART_INCOMING_FILTER }, - { 6, SMART_OUTGOING_FILTER }, - { 7, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_INCOMING_ONE_NEIGH | - SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_PROTO }, - { 8, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_INCOMING_ONE_NEIGH }, - { 9, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH | - SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_PROTO }, +struct intint { + int a; + int b; +}; +static const struct intint filters[] = { { 0, 0 }, + { 1, + SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_OUTGOING_FILTER | + SMART_OUTGOING_ONE_PROTO }, + { 2, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO }, + { 3, SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_PROTO }, + { 4, SMART_INCOMING_FILTER | SMART_OUTGOING_FILTER }, + { 5, SMART_INCOMING_FILTER }, { 6, SMART_OUTGOING_FILTER }, + { 7, + SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | + SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER | + SMART_OUTGOING_ONE_PROTO }, + { 8, + SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | + SMART_INCOMING_ONE_NEIGH }, + { 9, + SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER | + SMART_OUTGOING_ONE_PROTO }, { 10, SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_NEIGH }, { 11, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH }, - { 12, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH | - SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_NEIGH }, - { 13, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH | - SMART_OUTGOING_FILTER }, - { 14, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | - SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_NEIGH }, - { 15, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | - SMART_OUTGOING_FILTER }, - { 16, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_INCOMING_ONE_NEIGH | - SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_NEIGH }, - { 17, SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_INCOMING_ONE_NEIGH | - SMART_OUTGOING_FILTER }, - { 18, SMART_INCOMING_FILTER | - SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_NEIGH }, - { 19, SMART_INCOMING_FILTER | - SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_PROTO }, - { -1, 0 } -}; + { 12, + SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER | + SMART_OUTGOING_ONE_NEIGH }, + { 13, + SMART_INCOMING_FILTER | SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER }, + { 14, + SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_OUTGOING_FILTER | + SMART_OUTGOING_ONE_NEIGH }, + { 15, + SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_OUTGOING_FILTER }, + { 16, + SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | + SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER | + SMART_OUTGOING_ONE_NEIGH }, + { 17, + SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | + SMART_INCOMING_ONE_NEIGH | SMART_OUTGOING_FILTER }, + { 18, + SMART_INCOMING_FILTER | SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_NEIGH }, + { 19, + SMART_INCOMING_FILTER | SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_PROTO }, + { -1, 0 } }; #ifndef HOST_OS_OSX /** @@ -1460,12 +1452,10 @@ static const struct intint filters[] = { static int lldpd_started_by_systemd() { -#ifdef HOST_OS_LINUX +# ifdef HOST_OS_LINUX int fd = -1; const char *notifysocket = getenv("NOTIFY_SOCKET"); - if (!notifysocket || - !strchr("@/", notifysocket[0]) || - strlen(notifysocket) < 2) + if (!notifysocket || !strchr("@/", notifysocket[0]) || strlen(notifysocket) < 2) return 0; log_debug("main", "running with systemd, don't fork but signal ready"); @@ -1479,16 +1469,12 @@ lldpd_started_by_systemd() strlcpy(su.sun_path, notifysocket, sizeof(su.sun_path)); if (notifysocket[0] == '@') su.sun_path[0] = 0; - struct iovec iov = { - .iov_base = "READY=1", - .iov_len = strlen("READY=1") - }; - struct msghdr hdr = { - .msg_name = &su, - .msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(notifysocket), + struct iovec iov = { .iov_base = "READY=1", .iov_len = strlen("READY=1") }; + struct msghdr hdr = { .msg_name = &su, + .msg_namelen = + offsetof(struct sockaddr_un, sun_path) + strlen(notifysocket), .msg_iov = &iov, - .msg_iovlen = 1 - }; + .msg_iovlen = 1 }; unsetenv("NOTIFY_SOCKET"); if (sendmsg(fd, &hdr, MSG_NOSIGNAL) < 0) { log_warn("main", "unable to send notification to systemd"); @@ -1497,9 +1483,9 @@ lldpd_started_by_systemd() } close(fd); return 1; -#else +# else return 0; -#endif +# endif } #endif @@ -1531,14 +1517,18 @@ version_check(void) version_min[2] > version_cur[2])) { log_warnx("lldpd", "minimal kernel version required is %s, got %s", MIN_LINUX_KERNEL_VERSION, uts.release); - log_warnx("lldpd", "lldpd may be unable to detect bonds and bridges correctly"); -#ifndef ENABLE_OLDIES + log_warnx("lldpd", + "lldpd may be unable to detect bonds and bridges correctly"); +# ifndef ENABLE_OLDIES log_warnx("lldpd", "consider recompiling with --enable-oldies option"); -#endif +# endif } } #else -static void version_check(void) {} +static void +version_check(void) +{ +} #endif int @@ -1550,7 +1540,7 @@ lldpd_main(int argc, char *argv[], char *envp[]) const char *errstr; #ifdef USE_SNMP int snmp = 0; - const char *agentx = NULL; /* AgentX socket */ + const char *agentx = NULL; /* AgentX socket */ #endif const char *ctlname = NULL; char *mgmtp = NULL; @@ -1559,8 +1549,8 @@ lldpd_main(int argc, char *argv[], char *envp[]) /* We do not want more options here. Please add them in lldpcli instead * unless there is a very good reason. Most command-line options will * get deprecated at some point. */ - char *popt, opts[] = - "H:vhkrdD:p:xX:m:u:4:6:I:C:p:M:P:S:iL:O:@ "; + char *popt, + opts[] = "H:vhkrdD:p:xX:m:u:4:6:I:C:p:M:P:S:iL:O:@ "; int i, found, advertise_version = 1; #ifdef ENABLE_LLDPMED int lldpmed = 0, noinventory = 0; @@ -1594,9 +1584,7 @@ lldpd_main(int argc, char *argv[], char *envp[]) * Get and parse command line options */ if ((popt = strchr(opts, '@')) != NULL) { - for (i=0; - protos[i].mode != 0 && *popt != '\0'; - i++) + for (i = 0; protos[i].mode != 0 && *popt != '\0'; i++) *(popt++) = protos[i].arg; *popt = '\0'; } @@ -1654,8 +1642,10 @@ lldpd_main(int argc, char *argv[], char *envp[]) cidp = strdup(optarg); break; case 'L': - if (strlen(optarg)) lldpcli = optarg; - else lldpcli = NULL; + if (strlen(optarg)) + lldpcli = optarg; + else + lldpcli = NULL; break; case 'k': advertise_version = 0; @@ -1664,7 +1654,8 @@ lldpd_main(int argc, char *argv[], char *envp[]) case 'M': lldpmed = strtonum(optarg, 1, 4, &errstr); if (errstr) { - fprintf(stderr, "-M requires an argument between 1 and 4\n"); + fprintf(stderr, + "-M requires an argument between 1 and 4\n"); usage(); } break; @@ -1697,13 +1688,13 @@ lldpd_main(int argc, char *argv[], char *envp[]) usage(); #endif break; - case 'S': + case 'S': if (descr_override) { fprintf(stderr, "-S can only be used once\n"); usage(); } - descr_override = strdup(optarg); - break; + descr_override = strdup(optarg); + break; case 'P': if (platform_override) { fprintf(stderr, "-P can only be used once\n"); @@ -1712,11 +1703,12 @@ lldpd_main(int argc, char *argv[], char *envp[]) platform_override = strdup(optarg); break; case 'H': - smart = strtonum(optarg, 0, sizeof(filters)/sizeof(filters[0]), - &errstr); + smart = strtonum(optarg, 0, + sizeof(filters) / sizeof(filters[0]), &errstr); if (errstr) { - fprintf(stderr, "-H requires an int between 0 and %zu\n", - sizeof(filters)/sizeof(filters[0])); + fprintf(stderr, + "-H requires an int between 0 and %zu\n", + sizeof(filters) / sizeof(filters[0])); usage(); } break; @@ -1729,14 +1721,13 @@ lldpd_main(int argc, char *argv[], char *envp[]) break; default: found = 0; - for (i=0; protos[i].mode != 0; i++) { + for (i = 0; protos[i].mode != 0; i++) { if (ch == protos[i].arg) { found = 1; protos[i].enabled++; } } - if (!found) - usage(); + if (!found) usage(); } } @@ -1748,7 +1739,8 @@ lldpd_main(int argc, char *argv[], char *envp[]) if (ctlname == NULL) ctlname = LLDPD_CTL_SOCKET; /* Set correct smart mode */ - for (i=0; (filters[i].a != -1) && (filters[i].a != smart); i++); + for (i = 0; (filters[i].a != -1) && (filters[i].a != smart); i++) + ; if (filters[i].a == -1) { fprintf(stderr, "Incorrect mode for -H\n"); usage(); @@ -1756,7 +1748,7 @@ lldpd_main(int argc, char *argv[], char *envp[]) smart = filters[i].b; log_init(use_syslog, debug, __progname); - tzset(); /* Get timezone info before chroot */ + tzset(); /* Get timezone info before chroot */ if (use_syslog && daemonize) { /* So, we use syslog and we daemonize (or we are started by * systemd). No need to continue writing to stdout. */ @@ -1776,10 +1768,14 @@ lldpd_main(int argc, char *argv[], char *envp[]) /* Grab uid and gid to use for priv sep */ #ifdef ENABLE_PRIVSEP if ((user = getpwnam(PRIVSEP_USER)) == NULL) - fatalx("main", "no " PRIVSEP_USER " user for privilege separation, please create it"); + fatalx("main", + "no " PRIVSEP_USER + " user for privilege separation, please create it"); uid = user->pw_uid; if ((group = getgrnam(PRIVSEP_GROUP)) == NULL) - fatalx("main", "no " PRIVSEP_GROUP " group for privilege separation, please create it"); + fatalx("main", + "no " PRIVSEP_GROUP + " group for privilege separation, please create it"); gid = group->gr_gid; #endif @@ -1790,20 +1786,24 @@ lldpd_main(int argc, char *argv[], char *envp[]) if (retry-- && errno == EADDRINUSE) { /* Check if a daemon is really listening */ int tfd; - log_info("main", "unable to create control socket because it already exists"); + log_info("main", + "unable to create control socket because it already exists"); log_info("main", "check if another instance is running"); if ((tfd = ctl_connect(ctlname)) != -1) { /* Another instance is running */ close(tfd); - log_warnx("main", "another instance is running, please stop it"); + log_warnx("main", + "another instance is running, please stop it"); fatalx("main", "giving up"); } else if (errno == ECONNREFUSED) { /* Nobody is listening */ - log_info("main", "old control socket is present, clean it"); + log_info("main", + "old control socket is present, clean it"); ctl_cleanup(ctlname); continue; } - log_warn("main", "cannot determine if another daemon is already running"); + log_warn("main", + "cannot determine if another daemon is already running"); fatalx("main", "giving up"); } log_warn("main", "unable to create control socket at %s", ctlname); @@ -1812,9 +1812,8 @@ lldpd_main(int argc, char *argv[], char *envp[]) #ifdef ENABLE_PRIVSEP if (chown(ctlname, uid, gid) == -1) log_warn("main", "unable to chown control socket"); - if (chmod(ctlname, - S_IRUSR | S_IWUSR | S_IXUSR | - S_IRGRP | S_IWGRP | S_IXGRP) == -1) + if (chmod(ctlname, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP) == + -1) log_warn("main", "unable to chmod control socket"); #endif @@ -1823,15 +1822,14 @@ lldpd_main(int argc, char *argv[], char *envp[]) int fd; if (asprintf(&lockname, "%s.lock", ctlname) == -1) fatal("main", "cannot build lock name"); - if ((fd = open(lockname, O_CREAT|O_RDWR, 0000)) == -1) + if ((fd = open(lockname, O_CREAT | O_RDWR, 0000)) == -1) fatal("main", "cannot create lock file for control socket"); close(fd); #ifdef ENABLE_PRIVSEP if (chown(lockname, uid, gid) == -1) log_warn("main", "unable to chown control socket lock"); if (chmod(lockname, - S_IRUSR | S_IWUSR | S_IXUSR | - S_IRGRP | S_IWGRP | S_IXGRP) == -1) + S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP) == -1) log_warn("main", "unable to chmod control socket lock"); #endif free(lockname); @@ -1848,17 +1846,18 @@ lldpd_main(int argc, char *argv[], char *envp[]) int pid; char *spid; log_debug("main", "going into background"); - if (daemon(0, 1) != 0) - fatal("main", "failed to detach daemon"); - if ((pid = open(pidfile, - O_TRUNC | O_CREAT | O_WRONLY, 0666)) == -1) - fatal("main", "unable to open pid file " LLDPD_PID_FILE + if (daemon(0, 1) != 0) fatal("main", "failed to detach daemon"); + if ((pid = open(pidfile, O_TRUNC | O_CREAT | O_WRONLY, 0666)) == -1) + fatal("main", + "unable to open pid file " LLDPD_PID_FILE " (or the specified one)"); if (asprintf(&spid, "%d\n", getpid()) == -1) - fatal("main", "unable to create pid file " LLDPD_PID_FILE + fatal("main", + "unable to create pid file " LLDPD_PID_FILE " (or the specified one)"); if (write(pid, spid, strlen(spid)) == -1) - fatal("main", "unable to write pid file " LLDPD_PID_FILE + fatal("main", + "unable to write pid file " LLDPD_PID_FILE " (or the specified one)"); free(spid); close(pid); @@ -1868,11 +1867,14 @@ lldpd_main(int argc, char *argv[], char *envp[]) /* Configuration with lldpcli */ if (lldpcli) { if (!config_file) { - log_debug("main", "invoking lldpcli for default configuration locations"); + log_debug("main", + "invoking lldpcli for default configuration locations"); } else { - log_debug("main", "invoking lldpcli for user supplied configuration location"); + log_debug("main", + "invoking lldpcli for user supplied configuration location"); } - if (lldpd_configure(use_syslog, debug, lldpcli, ctlname, config_file) == -1) + if (lldpd_configure(use_syslog, debug, lldpcli, ctlname, config_file) == + -1) fatal("main", "unable to spawn lldpcli"); } @@ -1892,8 +1894,7 @@ lldpd_main(int argc, char *argv[], char *envp[]) #endif /* Initialization of global configuration */ - if ((cfg = (struct lldpd *) - calloc(1, sizeof(struct lldpd))) == NULL) + if ((cfg = (struct lldpd *)calloc(1, sizeof(struct lldpd))) == NULL) fatal("main", NULL); lldpd_alloc_default_local_port(cfg); @@ -1903,8 +1904,7 @@ lldpd_main(int argc, char *argv[], char *envp[]) cfg->g_config.c_cid_pattern = cidp; cfg->g_config.c_iface_pattern = interfaces; cfg->g_config.c_smart = smart; - if (lldpcli) - cfg->g_config.c_paused = 1; + if (lldpcli) cfg->g_config.c_paused = 1; cfg->g_config.c_receiveonly = receiveonly; cfg->g_config.c_tx_interval = LLDPD_TX_INTERVAL * 1000; cfg->g_config.c_tx_hold = LLDPD_TX_HOLD; @@ -1920,7 +1920,7 @@ lldpd_main(int argc, char *argv[], char *envp[]) cfg->g_snmp = snmp; cfg->g_snmp_agentx = agentx; #endif /* USE_SNMP */ - cfg->g_config.c_bond_slave_src_mac_type = \ + cfg->g_config.c_bond_slave_src_mac_type = LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED; /* Get ioctl socket */ @@ -1929,25 +1929,23 @@ lldpd_main(int argc, char *argv[], char *envp[]) fatal("main", "failed to get ioctl socket"); /* Description */ - if (!(cfg->g_config.c_advertise_version = advertise_version) && - lsb_release && lsb_release[strlen(lsb_release) - 1] == '\n') + if (!(cfg->g_config.c_advertise_version = advertise_version) && lsb_release && + lsb_release[strlen(lsb_release) - 1] == '\n') lsb_release[strlen(lsb_release) - 1] = '\0'; cfg->g_lsb_release = lsb_release; - if (descr_override) - cfg->g_config.c_description = descr_override; + if (descr_override) cfg->g_config.c_description = descr_override; - if (platform_override) - cfg->g_config.c_platform = platform_override; + if (platform_override) cfg->g_config.c_platform = platform_override; /* Set system capabilities */ log_debug("main", "set system capabilities"); - if ((lchassis = (struct lldpd_chassis*) - calloc(1, sizeof(struct lldpd_chassis))) == NULL) + if ((lchassis = (struct lldpd_chassis *)calloc(1, + sizeof(struct lldpd_chassis))) == NULL) fatal("localchassis", NULL); cfg->g_config.c_cap_advertise = 1; cfg->g_config.c_cap_override = 0; - lchassis->c_cap_available = LLDP_CAP_BRIDGE | LLDP_CAP_WLAN | - LLDP_CAP_ROUTER | LLDP_CAP_STATION; + lchassis->c_cap_available = + LLDP_CAP_BRIDGE | LLDP_CAP_WLAN | LLDP_CAP_ROUTER | LLDP_CAP_STATION; cfg->g_config.c_mgmt_advertise = 1; TAILQ_INIT(&lchassis->c_mgmt); #ifdef ENABLE_LLDPMED @@ -1955,9 +1953,9 @@ lldpd_main(int argc, char *argv[], char *envp[]) if (lldpmed == LLDP_MED_CLASS_III) lchassis->c_cap_available |= LLDP_CAP_TELEPHONE; lchassis->c_med_type = lldpmed; - lchassis->c_med_cap_available = LLDP_MED_CAP_CAP | - LLDP_MED_CAP_IV | LLDP_MED_CAP_LOCATION | - LLDP_MED_CAP_POLICY | LLDP_MED_CAP_MDI_PSE | LLDP_MED_CAP_MDI_PD; + lchassis->c_med_cap_available = LLDP_MED_CAP_CAP | LLDP_MED_CAP_IV | + LLDP_MED_CAP_LOCATION | LLDP_MED_CAP_POLICY | LLDP_MED_CAP_MDI_PSE | + LLDP_MED_CAP_MDI_PD; cfg->g_config.c_noinventory = noinventory; } else cfg->g_config.c_noinventory = 1; @@ -1965,11 +1963,10 @@ lldpd_main(int argc, char *argv[], char *envp[]) log_debug("main", "initialize protocols"); cfg->g_protocols = protos; - for (i=0; protos[i].mode != 0; i++) { + for (i = 0; protos[i].mode != 0; i++) { /* With -ll, disable LLDP */ - if (protos[i].mode == LLDPD_MODE_LLDP) - protos[i].enabled %= 3; + if (protos[i].mode == LLDPD_MODE_LLDP) protos[i].enabled %= 3; /* With -ccc force CDPV2, enable CDPV1 */ if (protos[i].mode == LLDPD_MODE_CDPV1 && protos[i].enabled == 3) { protos[i].enabled = 1; @@ -1990,12 +1987,13 @@ lldpd_main(int argc, char *argv[], char *envp[]) } if (protos[i].enabled > 1) - log_info("main", "protocol %s enabled and forced", protos[i].name); + log_info("main", "protocol %s enabled and forced", + protos[i].name); else if (protos[i].enabled) log_info("main", "protocol %s enabled", protos[i].name); else log_info("main", "protocol %s disabled", protos[i].name); - } + } TAILQ_INIT(&cfg->g_hardware); TAILQ_INIT(&cfg->g_chassis); diff --git a/src/daemon/lldpd.h b/src/daemon/lldpd.h index dac54509..b8952945 100644 --- a/src/daemon/lldpd.h +++ b/src/daemon/lldpd.h @@ -23,9 +23,9 @@ #endif #ifdef HAVE_VALGRIND_VALGRIND_H -# include +# include #else -# define RUNNING_ON_VALGRIND 0 +# define RUNNING_ON_VALGRIND 0 #endif #include @@ -50,8 +50,6 @@ # include "protocols/edp.h" #endif - - #include "../compat/compat.h" #include "../marshal.h" #include "../log.h" @@ -63,34 +61,37 @@ struct event; struct event_base; -#define PROCFS_SYS_NET "/proc/sys/net/" +#define PROCFS_SYS_NET "/proc/sys/net/" #define SYSFS_CLASS_NET "/sys/class/net/" #define SYSFS_CLASS_DMI "/sys/class/dmi/id/" -#define LLDPD_TX_INTERVAL 30 -#define LLDPD_TX_HOLD 4 -#define LLDPD_TTL LLDPD_TX_INTERVAL * LLDPD_TX_HOLD -#define LLDPD_TX_MSGDELAY 1 -#define LLDPD_MAX_NEIGHBORS 32 -#define LLDPD_FAST_TX_INTERVAL 1 -#define LLDPD_FAST_INIT 4 +#define LLDPD_TX_INTERVAL 30 +#define LLDPD_TX_HOLD 4 +#define LLDPD_TTL LLDPD_TX_INTERVAL *LLDPD_TX_HOLD +#define LLDPD_TX_MSGDELAY 1 +#define LLDPD_MAX_NEIGHBORS 32 +#define LLDPD_FAST_TX_INTERVAL 1 +#define LLDPD_FAST_INIT 4 #define USING_AGENTX_SUBAGENT_MODULE 1 #define PROTO_SEND_SIG struct lldpd *, struct lldpd_hardware * -#define PROTO_DECODE_SIG struct lldpd *, char *, int, struct lldpd_hardware *, struct lldpd_chassis **, struct lldpd_port ** +#define PROTO_DECODE_SIG \ + struct lldpd *, char *, int, struct lldpd_hardware *, struct lldpd_chassis **, \ + struct lldpd_port ** #define PROTO_GUESS_SIG char *, int -#define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR)) +#define ALIGNED_CAST(TYPE, ATTR) ((TYPE)(void *)(ATTR)) struct protocol { - int mode; /* > 0 mode identifier (unique per protocol) */ - int enabled; /* Is this protocol enabled? */ - char *name; /* Name of protocol */ - char arg; /* Argument to enable this protocol */ - int(*send)(PROTO_SEND_SIG); /* How to send a frame */ - int(*decode)(PROTO_DECODE_SIG); /* How to decode a frame */ - int(*guess)(PROTO_GUESS_SIG); /* Can be NULL, use MAC address in this case */ - u_int8_t mac[3][ETHER_ADDR_LEN]; /* Destination MAC addresses used by this protocol */ + int mode; /* > 0 mode identifier (unique per protocol) */ + int enabled; /* Is this protocol enabled? */ + char *name; /* Name of protocol */ + char arg; /* Argument to enable this protocol */ + int (*send)(PROTO_SEND_SIG); /* How to send a frame */ + int (*decode)(PROTO_DECODE_SIG); /* How to decode a frame */ + int (*guess)(PROTO_GUESS_SIG); /* Can be NULL, use MAC address in this case */ + u_int8_t mac[3][ETHER_ADDR_LEN]; /* Destination MAC addresses used by this + protocol */ }; #define SMART_HIDDEN(port) (port->p_hidden_in) @@ -98,122 +99,119 @@ struct protocol { struct lldpd; /* lldpd.c */ -struct lldpd_hardware *lldpd_get_hardware(struct lldpd *, - char *, int); -struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, char *, int); -void lldpd_hardware_cleanup(struct lldpd*, struct lldpd_hardware *); -struct lldpd_mgmt *lldpd_alloc_mgmt(int family, void *addr, size_t addrsize, u_int32_t iface); -void lldpd_recv(struct lldpd *, struct lldpd_hardware *, int); -void lldpd_send(struct lldpd_hardware *); -void lldpd_loop(struct lldpd *); -int lldpd_main(int, char **, char **); -void lldpd_update_localports(struct lldpd *); -void lldpd_update_localchassis(struct lldpd *); -void lldpd_cleanup(struct lldpd *); +struct lldpd_hardware *lldpd_get_hardware(struct lldpd *, char *, int); +struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, char *, int); +void lldpd_hardware_cleanup(struct lldpd *, struct lldpd_hardware *); +struct lldpd_mgmt *lldpd_alloc_mgmt(int family, void *addr, size_t addrsize, + u_int32_t iface); +void lldpd_recv(struct lldpd *, struct lldpd_hardware *, int); +void lldpd_send(struct lldpd_hardware *); +void lldpd_loop(struct lldpd *); +int lldpd_main(int, char **, char **); +void lldpd_update_localports(struct lldpd *); +void lldpd_update_localchassis(struct lldpd *); +void lldpd_cleanup(struct lldpd *); /* frame.c */ u_int16_t frame_checksum(const u_int8_t *, int, int); /* event.c */ -void levent_loop(struct lldpd *); -void levent_shutdown(struct lldpd *); -void levent_hardware_init(struct lldpd_hardware *); -void levent_hardware_add_fd(struct lldpd_hardware *, int); -void levent_hardware_release(struct lldpd_hardware *); -void levent_ctl_notify(char *, int, struct lldpd_port *); -void levent_send_now(struct lldpd *); -void levent_update_now(struct lldpd *); -int levent_iface_subscribe(struct lldpd *, int); -void levent_schedule_pdu(struct lldpd_hardware *); -void levent_schedule_cleanup(struct lldpd *); -int levent_make_socket_nonblocking(int); -int levent_make_socket_blocking(int); +void levent_loop(struct lldpd *); +void levent_shutdown(struct lldpd *); +void levent_hardware_init(struct lldpd_hardware *); +void levent_hardware_add_fd(struct lldpd_hardware *, int); +void levent_hardware_release(struct lldpd_hardware *); +void levent_ctl_notify(char *, int, struct lldpd_port *); +void levent_send_now(struct lldpd *); +void levent_update_now(struct lldpd *); +int levent_iface_subscribe(struct lldpd *, int); +void levent_schedule_pdu(struct lldpd_hardware *); +void levent_schedule_cleanup(struct lldpd *); +int levent_make_socket_nonblocking(int); +int levent_make_socket_blocking(int); #ifdef HOST_OS_LINUX -void levent_recv_error(int, const char*); +void levent_recv_error(int, const char *); #endif /* lldp.c */ -int lldp_send_shutdown(PROTO_SEND_SIG); -int lldp_send(PROTO_SEND_SIG); -int lldp_decode(PROTO_DECODE_SIG); +int lldp_send_shutdown(PROTO_SEND_SIG); +int lldp_send(PROTO_SEND_SIG); +int lldp_decode(PROTO_DECODE_SIG); /* cdp.c */ #ifdef ENABLE_CDP -int cdpv1_send(PROTO_SEND_SIG); -int cdpv2_send(PROTO_SEND_SIG); -int cdpv1_guess(PROTO_GUESS_SIG); -int cdpv2_guess(PROTO_GUESS_SIG); +int cdpv1_send(PROTO_SEND_SIG); +int cdpv2_send(PROTO_SEND_SIG); +int cdpv1_guess(PROTO_GUESS_SIG); +int cdpv2_guess(PROTO_GUESS_SIG); #endif #if defined ENABLE_CDP || defined ENABLE_FDP -int cdp_decode(PROTO_DECODE_SIG); +int cdp_decode(PROTO_DECODE_SIG); #endif #ifdef ENABLE_FDP -int fdp_send(PROTO_SEND_SIG); +int fdp_send(PROTO_SEND_SIG); #endif #ifdef ENABLE_SONMP /* sonmp.c */ -int sonmp_send(PROTO_SEND_SIG); -int sonmp_decode(PROTO_DECODE_SIG); +int sonmp_send(PROTO_SEND_SIG); +int sonmp_decode(PROTO_DECODE_SIG); #endif #ifdef ENABLE_EDP /* edp.c */ -int edp_send(PROTO_SEND_SIG); -int edp_decode(PROTO_DECODE_SIG); +int edp_send(PROTO_SEND_SIG); +int edp_decode(PROTO_DECODE_SIG); #endif /* dmi.c */ #ifdef ENABLE_LLDPMED -char *dmi_hw(void); -char *dmi_fw(void); -char *dmi_sn(void); -char *dmi_manuf(void); -char *dmi_model(void); -char *dmi_asset(void); +char *dmi_hw(void); +char *dmi_fw(void); +char *dmi_sn(void); +char *dmi_manuf(void); +char *dmi_model(void); +char *dmi_asset(void); #endif #ifdef USE_SNMP /* agent.c */ -void agent_shutdown(void); -void agent_init(struct lldpd *, const char *); -void agent_notify(struct lldpd_hardware *, int, struct lldpd_port *); +void agent_shutdown(void); +void agent_init(struct lldpd *, const char *); +void agent_notify(struct lldpd_hardware *, int, struct lldpd_port *); #endif #ifdef ENABLE_PRIVSEP /* agent_priv.c */ -void agent_priv_register_domain(void); +void agent_priv_register_domain(void); #endif /* client.c */ -int -client_handle_client(struct lldpd *cfg, - ssize_t(*send)(void *, int, void *, size_t), - void *, - enum hmsg_type type, void *buffer, size_t n, - int*); +int client_handle_client(struct lldpd *cfg, + ssize_t (*send)(void *, int, void *, size_t), void *, enum hmsg_type type, + void *buffer, size_t n, int *); /* priv.c */ #ifdef ENABLE_PRIVSEP -void priv_init(const char*, int, uid_t, gid_t); +void priv_init(const char *, int, uid_t, gid_t); #else -void priv_init(void); +void priv_init(void); #endif -void priv_wait(void); -void priv_ctl_cleanup(const char *ctlname); -char *priv_gethostname(void); +void priv_wait(void); +void priv_ctl_cleanup(const char *ctlname); +char *priv_gethostname(void); #ifdef HOST_OS_LINUX -int priv_open(char*); -void asroot_open(void); +int priv_open(char *); +void asroot_open(void); #endif -int priv_iface_init(int, char *); -int asroot_iface_init_os(int, char *, int *); -int priv_iface_multicast(const char *, const u_int8_t *, int); -int priv_iface_description(const char *, const char *); -int asroot_iface_description_os(const char *, const char *); -int priv_iface_promisc(const char*); -int asroot_iface_promisc_os(const char *); -int priv_snmp_socket(struct sockaddr_un *); +int priv_iface_init(int, char *); +int asroot_iface_init_os(int, char *, int *); +int priv_iface_multicast(const char *, const u_int8_t *, int); +int priv_iface_description(const char *, const char *); +int asroot_iface_description_os(const char *, const char *); +int priv_iface_promisc(const char *); +int asroot_iface_promisc_os(const char *); +int priv_snmp_socket(struct sockaddr_un *); enum priv_cmd { PRIV_PING, @@ -233,18 +231,15 @@ int priv_seccomp_init(int, int); #endif /* privsep_io.c */ -enum priv_context { - PRIV_PRIVILEGED, - PRIV_UNPRIVILEGED -}; -int may_read(enum priv_context, void *, size_t); -void must_read(enum priv_context, void *, size_t); -void must_write(enum priv_context, const void *, size_t); -void priv_privileged_fd(int); -void priv_unprivileged_fd(int); -int priv_fd(enum priv_context); -int receive_fd(enum priv_context); -void send_fd(enum priv_context, int); +enum priv_context { PRIV_PRIVILEGED, PRIV_UNPRIVILEGED }; +int may_read(enum priv_context, void *, size_t); +void must_read(enum priv_context, void *, size_t); +void must_write(enum priv_context, const void *, size_t); +void priv_privileged_fd(int); +void priv_unprivileged_fd(int); +int priv_fd(enum priv_context); +int receive_fd(enum priv_context); +void send_fd(enum priv_context, int); /* interfaces-*.c */ @@ -258,82 +253,72 @@ void send_fd(enum priv_context, int); first byte is 1. if not, this can only be an EDP packet: tcpdump -dd "(ether[0] & 1 = 1 and - ((ether proto 0x88cc and (ether dst 01:80:c2:00:00:0e or - ether dst 01:80:c2:00:00:03 or - ether dst 01:80:c2:00:00:00)) or - (ether dst 01:e0:52:cc:cc:cc) or - (ether dst 01:00:0c:cc:cc:cc) or - (ether dst 01:00:81:00:01:00))) or - (ether dst 00:e0:2b:00:00:00)" + ((ether proto 0x88cc and (ether dst 01:80:c2:00:00:0e or + ether dst 01:80:c2:00:00:03 or + ether dst 01:80:c2:00:00:00)) or + (ether dst 01:e0:52:cc:cc:cc) or + (ether dst 01:00:0c:cc:cc:cc) or + (ether dst 01:00:81:00:01:00))) or + (ether dst 00:e0:2b:00:00:00)" */ #ifndef ETH_P_LLDP -# define ETH_P_LLDP 0x88cc +# define ETH_P_LLDP 0x88cc #endif -#define LLDPD_FILTER_F \ - { 0x30, 0, 0, 0x00000000 }, \ - { 0x54, 0, 0, 0x00000001 }, \ - { 0x15, 0, 16, 0x00000001 }, \ - { 0x28, 0, 0, 0x0000000c }, \ - { 0x15, 0, 6, ETH_P_LLDP }, \ - { 0x20, 0, 0, 0x00000002 }, \ - { 0x15, 2, 0, 0xc200000e }, \ - { 0x15, 1, 0, 0xc2000003 }, \ - { 0x15, 0, 2, 0xc2000000 }, \ - { 0x28, 0, 0, 0x00000000 }, \ - { 0x15, 12, 13, 0x00000180 }, \ - { 0x20, 0, 0, 0x00000002 }, \ - { 0x15, 0, 2, 0x52cccccc }, \ - { 0x28, 0, 0, 0x00000000 }, \ - { 0x15, 8, 9, 0x000001e0 }, \ - { 0x15, 1, 0, 0x0ccccccc }, \ - { 0x15, 0, 2, 0x81000100 }, \ - { 0x28, 0, 0, 0x00000000 }, \ - { 0x15, 4, 5, 0x00000100 }, \ - { 0x20, 0, 0, 0x00000002 }, \ - { 0x15, 0, 3, 0x2b000000 }, \ - { 0x28, 0, 0, 0x00000000 }, \ - { 0x15, 0, 1, 0x000000e0 }, \ - { 0x6, 0, 0, 0x00040000 }, \ - { 0x6, 0, 0, 0x00000000 } +#define LLDPD_FILTER_F \ + { 0x30, 0, 0, 0x00000000 }, { 0x54, 0, 0, 0x00000001 }, { 0x15, 0, 16, 0x00000001 }, \ + { 0x28, 0, 0, 0x0000000c }, { 0x15, 0, 6, ETH_P_LLDP }, \ + { 0x20, 0, 0, 0x00000002 }, { 0x15, 2, 0, 0xc200000e }, \ + { 0x15, 1, 0, 0xc2000003 }, { 0x15, 0, 2, 0xc2000000 }, \ + { 0x28, 0, 0, 0x00000000 }, { 0x15, 12, 13, 0x00000180 }, \ + { 0x20, 0, 0, 0x00000002 }, { 0x15, 0, 2, 0x52cccccc }, \ + { 0x28, 0, 0, 0x00000000 }, { 0x15, 8, 9, 0x000001e0 }, \ + { 0x15, 1, 0, 0x0ccccccc }, { 0x15, 0, 2, 0x81000100 }, \ + { 0x28, 0, 0, 0x00000000 }, { 0x15, 4, 5, 0x00000100 }, \ + { 0x20, 0, 0, 0x00000002 }, { 0x15, 0, 3, 0x2b000000 }, \ + { 0x28, 0, 0, 0x00000000 }, { 0x15, 0, 1, 0x000000e0 }, \ + { 0x6, 0, 0, 0x00040000 }, \ + { \ + 0x6, 0, 0, 0x00000000 \ + } /* This function is responsible to refresh information about interfaces. It is * OS specific but should be present for each OS. It can use the functions in * `interfaces.c` as helper by providing a list of OS-independent interface * devices. */ -void interfaces_update(struct lldpd *); +void interfaces_update(struct lldpd *); /* interfaces.c */ /* An interface cannot be both physical and (bridge or bond or vlan) */ -#define IFACE_PHYSICAL_T (1 << 0) /* Physical interface */ -#define IFACE_BRIDGE_T (1 << 1) /* Bridge interface */ -#define IFACE_BOND_T (1 << 2) /* Bond interface */ -#define IFACE_VLAN_T (1 << 3) /* VLAN interface */ -#define IFACE_WIRELESS_T (1 << 4) /* Wireless interface */ +#define IFACE_PHYSICAL_T (1 << 0) /* Physical interface */ +#define IFACE_BRIDGE_T (1 << 1) /* Bridge interface */ +#define IFACE_BOND_T (1 << 2) /* Bond interface */ +#define IFACE_VLAN_T (1 << 3) /* VLAN interface */ +#define IFACE_WIRELESS_T (1 << 4) /* Wireless interface */ #define IFACE_BRIDGE_VLAN_T (1 << 5) /* Bridge-aware VLAN interface */ #define MAX_VLAN 4096 #define VLAN_BITMAP_LEN (MAX_VLAN / 32) struct interfaces_device { TAILQ_ENTRY(interfaces_device) next; - int ignore; /* Ignore this interface */ - int index; /* Index */ - char *name; /* Name */ - char *alias; /* Alias */ - char *address; /* MAC address */ - char *driver; /* Driver */ - int flags; /* Flags (IFF_*) */ - int mtu; /* MTU */ - int type; /* Type (see IFACE_*_T) */ - uint32_t vlan_bmap[VLAN_BITMAP_LEN]; /* If a VLAN, what are the VLAN ID? */ - int pvid; /* If a VLAN, what is the default VLAN? */ + int ignore; /* Ignore this interface */ + int index; /* Index */ + char *name; /* Name */ + char *alias; /* Alias */ + char *address; /* MAC address */ + char *driver; /* Driver */ + int flags; /* Flags (IFF_*) */ + int mtu; /* MTU */ + int type; /* Type (see IFACE_*_T) */ + uint32_t vlan_bmap[VLAN_BITMAP_LEN]; /* If a VLAN, what are the VLAN ID? */ + int pvid; /* If a VLAN, what is the default VLAN? */ struct interfaces_device *lower; /* Lower interface (for a VLAN for example) */ struct interfaces_device *upper; /* Upper interface (for a bridge or a bond) */ /* The following are OS specific. Should be static (no free function) */ #ifdef HOST_OS_LINUX - int lower_idx; /* Index to lower interface */ - int upper_idx; /* Index to upper interface */ + int lower_idx; /* Index to lower interface */ + int upper_idx; /* Index to upper interface */ #endif }; struct interfaces_address { @@ -345,43 +330,31 @@ struct interfaces_address { /* The following are OS specific. */ /* Nothing yet. */ }; -TAILQ_HEAD(interfaces_device_list, interfaces_device); +TAILQ_HEAD(interfaces_device_list, interfaces_device); TAILQ_HEAD(interfaces_address_list, interfaces_address); void interfaces_free_device(struct interfaces_device *); void interfaces_free_address(struct interfaces_address *); void interfaces_free_devices(struct interfaces_device_list *); void interfaces_free_addresses(struct interfaces_address_list *); -struct interfaces_device* interfaces_indextointerface( - struct interfaces_device_list *, - int); -struct interfaces_device* interfaces_nametointerface( - struct interfaces_device_list *, - const char *); - -void interfaces_helper_promisc(struct lldpd *, - struct lldpd_hardware *); -void interfaces_helper_allowlist(struct lldpd *, - struct interfaces_device_list *); -void interfaces_helper_chassis(struct lldpd *, - struct interfaces_device_list *); -void interfaces_helper_add_hardware(struct lldpd *, - struct lldpd_hardware *); -void interfaces_helper_physical(struct lldpd *, - struct interfaces_device_list *, - struct lldpd_ops *, - int(*init)(struct lldpd *, struct lldpd_hardware *)); -void interfaces_helper_port_name_desc(struct lldpd *, - struct lldpd_hardware *, +struct interfaces_device *interfaces_indextointerface(struct interfaces_device_list *, + int); +struct interfaces_device *interfaces_nametointerface(struct interfaces_device_list *, + const char *); + +void interfaces_helper_promisc(struct lldpd *, struct lldpd_hardware *); +void interfaces_helper_allowlist(struct lldpd *, struct interfaces_device_list *); +void interfaces_helper_chassis(struct lldpd *, struct interfaces_device_list *); +void interfaces_helper_add_hardware(struct lldpd *, struct lldpd_hardware *); +void interfaces_helper_physical(struct lldpd *, struct interfaces_device_list *, + struct lldpd_ops *, int (*init)(struct lldpd *, struct lldpd_hardware *)); +void interfaces_helper_port_name_desc(struct lldpd *, struct lldpd_hardware *, struct interfaces_device *); -void interfaces_helper_mgmt(struct lldpd *, - struct interfaces_address_list *, +void interfaces_helper_mgmt(struct lldpd *, struct interfaces_address_list *, struct interfaces_device_list *); #ifdef ENABLE_DOT1 -void interfaces_helper_vlan(struct lldpd *, - struct interfaces_device_list *); +void interfaces_helper_vlan(struct lldpd *, struct interfaces_device_list *); #endif -int interfaces_send_helper(struct lldpd *, - struct lldpd_hardware *, char *, size_t); +int interfaces_send_helper(struct lldpd *, struct lldpd_hardware *, char *, size_t); void interfaces_setup_multicast(struct lldpd *, const char *, int); int interfaces_routing_enabled(struct lldpd *); @@ -389,7 +362,7 @@ void interfaces_cleanup(struct lldpd *); #ifdef HOST_OS_LINUX /* netlink.c */ -struct interfaces_device_list *netlink_get_interfaces(struct lldpd *); +struct interfaces_device_list *netlink_get_interfaces(struct lldpd *); struct interfaces_address_list *netlink_get_addresses(struct lldpd *); void netlink_cleanup(struct lldpd *); struct lldpd_netlink; @@ -414,38 +387,40 @@ int bitmap_isempty(uint32_t *bmap); unsigned int bitmap_numbits(uint32_t *bmap); struct lldpd { - int g_sock; - struct event_base *g_base; + int g_sock; + struct event_base *g_base; #ifdef USE_SNMP #endif - struct lldpd_config g_config; + struct lldpd_config g_config; - struct protocol *g_protocols; - int g_lastrid; - struct event *g_main_loop; - struct event *g_cleanup_timer; + struct protocol *g_protocols; + int g_lastrid; + struct event *g_main_loop; + struct event *g_cleanup_timer; #ifdef USE_SNMP - int g_snmp; - struct event *g_snmp_timeout; - void *g_snmp_fds; - const char *g_snmp_agentx; + int g_snmp; + struct event *g_snmp_timeout; + void *g_snmp_fds; + const char *g_snmp_agentx; #endif /* USE_SNMP */ /* Unix socket handling */ - const char *g_ctlname; - int g_ctl; - struct event *g_iface_event; /* Triggered when there is an interface change */ - struct event *g_iface_timer_event; /* Triggered one second after last interface change */ - void(*g_iface_cb)(struct lldpd *); /* Called when there is an interface change */ + const char *g_ctlname; + int g_ctl; + struct event *g_iface_event; /* Triggered when there is an interface change */ + struct event + *g_iface_timer_event; /* Triggered one second after last interface change */ + void (*g_iface_cb)( + struct lldpd *); /* Called when there is an interface change */ - char *g_lsb_release; + char *g_lsb_release; #ifdef HOST_OS_LINUX - struct lldpd_netlink *g_netlink; + struct lldpd_netlink *g_netlink; #endif - struct lldpd_port *g_default_local_port; + struct lldpd_port *g_default_local_port; #define LOCAL_CHASSIS(cfg) ((struct lldpd_chassis *)(TAILQ_FIRST(&cfg->g_chassis))) TAILQ_HEAD(, lldpd_chassis) g_chassis; TAILQ_HEAD(, lldpd_hardware) g_hardware; diff --git a/src/daemon/netlink.c b/src/daemon/netlink.c index 4ced007a..55f9b661 100644 --- a/src/daemon/netlink.c +++ b/src/daemon/netlink.c @@ -33,7 +33,7 @@ struct netlink_req { struct nlmsghdr hdr; struct ifinfomsg ifm; /* attribute has to be NLMSG aligned */ - struct rtattr ext_req __attribute__ ((aligned(NLMSG_ALIGNTO))); + struct rtattr ext_req __attribute__((aligned(NLMSG_ALIGNTO))); __u32 ext_filter_mask; }; @@ -58,7 +58,8 @@ netlink_socket_set_buffer_size(int s, int optname, const char *optname_str, int socklen_t size = sizeof(int); int got = 0; - if (bufsize > 0 && setsockopt(s, SOL_SOCKET, optname, &bufsize, sizeof(bufsize)) < 0) { + if (bufsize > 0 && + setsockopt(s, SOL_SOCKET, optname, &bufsize, sizeof(bufsize)) < 0) { log_warn("netlink", "unable to set %s to '%d'", optname_str, bufsize); return -1; } @@ -73,8 +74,10 @@ netlink_socket_set_buffer_size(int s, int optname, const char *optname_str, int return -1; } if (bufsize > 0 && got < bufsize) { - log_warnx("netlink", "tried to set %s to '%d' " - "but got '%d'", optname_str, bufsize, got); + log_warnx("netlink", + "tried to set %s to '%d' " + "but got '%d'", + optname_str, bufsize, got); return -2; } @@ -94,11 +97,9 @@ static int netlink_connect(struct lldpd *cfg, int protocol, unsigned groups) { int s; - struct sockaddr_nl local = { - .nl_family = AF_NETLINK, + struct sockaddr_nl local = { .nl_family = AF_NETLINK, .nl_pid = 0, - .nl_groups = groups - }; + .nl_groups = groups }; /* Open Netlink socket */ log_debug("netlink", "opening netlink socket"); @@ -108,22 +109,27 @@ netlink_connect(struct lldpd *cfg, int protocol, unsigned groups) return -1; } if (NETLINK_SEND_BUFSIZE && - netlink_socket_set_buffer_size(s, - SO_SNDBUF, "SO_SNDBUF", NETLINK_SEND_BUFSIZE) == -1) { + netlink_socket_set_buffer_size(s, SO_SNDBUF, "SO_SNDBUF", + NETLINK_SEND_BUFSIZE) == -1) { close(s); return -1; } - int rc = netlink_socket_set_buffer_size(s, - SO_RCVBUF, "SO_RCVBUF", NETLINK_RECEIVE_BUFSIZE); + int rc = netlink_socket_set_buffer_size(s, SO_RCVBUF, "SO_RCVBUF", + NETLINK_RECEIVE_BUFSIZE); switch (rc) { case -1: close(s); return -1; - case -2: cfg->g_netlink->nl_socket_recv_size = 0; break; - default: cfg->g_netlink->nl_socket_recv_size = rc; break; + case -2: + cfg->g_netlink->nl_socket_recv_size = 0; + break; + default: + cfg->g_netlink->nl_socket_recv_size = rc; + break; } - if (groups && bind(s, (struct sockaddr *)&local, sizeof(struct sockaddr_nl)) < 0) { + if (groups && + bind(s, (struct sockaddr *)&local, sizeof(struct sockaddr_nl)) < 0) { log_warn("netlink", "unable to bind netlink socket"); close(s); return -1; @@ -146,26 +152,19 @@ netlink_connect(struct lldpd *cfg, int protocol, unsigned groups) static int netlink_send(int s, int type, int family, int seq) { - struct netlink_req req = { - .hdr = { - .nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)), - .nlmsg_type = type, - .nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP, - .nlmsg_seq = seq, - .nlmsg_pid = getpid() }, - .ifm = { .ifi_family = family } - }; - struct iovec iov = { - .iov_base = &req, - .iov_len = req.hdr.nlmsg_len - }; + struct netlink_req req = { .hdr = { .nlmsg_len = + NLMSG_LENGTH(sizeof(struct ifinfomsg)), + .nlmsg_type = type, + .nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP, + .nlmsg_seq = seq, + .nlmsg_pid = getpid() }, + .ifm = { .ifi_family = family } }; + struct iovec iov = { .iov_base = &req, .iov_len = req.hdr.nlmsg_len }; struct sockaddr_nl peer = { .nl_family = AF_NETLINK }; - struct msghdr rtnl_msg = { - .msg_iov = &iov, + struct msghdr rtnl_msg = { .msg_iov = &iov, .msg_iovlen = 1, .msg_name = &peer, - .msg_namelen = sizeof(struct sockaddr_nl) - }; + .msg_namelen = sizeof(struct sockaddr_nl) }; if (family == AF_BRIDGE) { unsigned int len = RTA_LENGTH(sizeof(__u32)); @@ -194,7 +193,7 @@ netlink_parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) while (RTA_OK(rta, len)) { if ((rta->rta_type <= max) && (!tb[rta->rta_type])) tb[rta->rta_type] = rta; - rta = RTA_NEXT(rta,len); + rta = RTA_NEXT(rta, len); } } @@ -208,7 +207,7 @@ netlink_parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) static void netlink_parse_linkinfo(struct interfaces_device *iff, struct rtattr *rta, int len) { - struct rtattr *link_info_attrs[IFLA_INFO_MAX+1] = {}; + struct rtattr *link_info_attrs[IFLA_INFO_MAX + 1] = {}; char *kind = NULL; uint16_t vlan_id; @@ -238,13 +237,14 @@ netlink_parse_linkinfo(struct interfaces_device *iff, struct rtattr *rta, int le } if (kind && !strcmp(kind, "vlan") && link_info_attrs[IFLA_INFO_DATA]) { - struct rtattr *vlan_link_info_data_attrs[IFLA_VLAN_MAX+1] = {}; + struct rtattr *vlan_link_info_data_attrs[IFLA_VLAN_MAX + 1] = {}; netlink_parse_rtattr(vlan_link_info_data_attrs, IFLA_VLAN_MAX, RTA_DATA(link_info_attrs[IFLA_INFO_DATA]), RTA_PAYLOAD(link_info_attrs[IFLA_INFO_DATA])); if (vlan_link_info_data_attrs[IFLA_VLAN_ID]) { - vlan_id = *(uint16_t *)RTA_DATA(vlan_link_info_data_attrs[IFLA_VLAN_ID]); + vlan_id = *(uint16_t *)RTA_DATA( + vlan_link_info_data_attrs[IFLA_VLAN_ID]); bitmap_set(iff->vlan_bmap, vlan_id); log_debug("netlink", "VLAN ID for interface %s is %d", iff->name, vlan_id); @@ -252,13 +252,14 @@ netlink_parse_linkinfo(struct interfaces_device *iff, struct rtattr *rta, int le } if (kind && !strcmp(kind, "bridge") && link_info_attrs[IFLA_INFO_DATA]) { - struct rtattr *bridge_link_info_data_attrs[IFLA_BR_MAX+1] = {}; + struct rtattr *bridge_link_info_data_attrs[IFLA_BR_MAX + 1] = {}; netlink_parse_rtattr(bridge_link_info_data_attrs, IFLA_BR_MAX, RTA_DATA(link_info_attrs[IFLA_INFO_DATA]), RTA_PAYLOAD(link_info_attrs[IFLA_INFO_DATA])); if (bridge_link_info_data_attrs[IFLA_BR_VLAN_FILTERING] && - *(uint8_t *)RTA_DATA(bridge_link_info_data_attrs[IFLA_BR_VLAN_FILTERING]) > 0) { + *(uint8_t *)RTA_DATA( + bridge_link_info_data_attrs[IFLA_BR_VLAN_FILTERING]) > 0) { iff->type |= IFACE_BRIDGE_VLAN_T; } } @@ -285,20 +286,23 @@ netlink_parse_afspec(struct interfaces_device *iff, struct rtattr *rta, int len) vinfo->vid, iff->name ? iff->name : "(unknown)"); bitmap_set(iff->vlan_bmap, vinfo->vid); - if (vinfo->flags & (BRIDGE_VLAN_INFO_PVID | BRIDGE_VLAN_INFO_UNTAGGED)) + if (vinfo->flags & + (BRIDGE_VLAN_INFO_PVID | BRIDGE_VLAN_INFO_UNTAGGED)) iff->pvid = vinfo->vid; break; default: - log_debug("netlink", "unknown afspec attribute type %d for iface %s", + log_debug("netlink", + "unknown afspec attribute type %d for iface %s", rta->rta_type, iff->name ? iff->name : "(unknown)"); break; } rta = RTA_NEXT(rta, len); } /* All enbridged interfaces will have VLAN 1 by default, ignore it */ - if (iff->vlan_bmap[0] == 2 && (bitmap_numbits(iff->vlan_bmap) == 1) - && iff->pvid == 1) { - log_debug("netlink", "found only default VLAN 1 on interface %s, removing", + if (iff->vlan_bmap[0] == 2 && (bitmap_numbits(iff->vlan_bmap) == 1) && + iff->pvid == 1) { + log_debug("netlink", + "found only default VLAN 1 on interface %s, removing", iff->name ? iff->name : "(unknown)"); iff->vlan_bmap[0] = iff->pvid = 0; } @@ -312,8 +316,7 @@ netlink_parse_afspec(struct interfaces_device *iff, struct rtattr *rta, int len) * return 0 if the interface is worth it, -1 otherwise */ static int -netlink_parse_link(struct nlmsghdr *msg, - struct interfaces_device *iff) +netlink_parse_link(struct nlmsghdr *msg, struct interfaces_device *iff) { struct ifinfomsg *ifi; struct rtattr *attribute; @@ -332,10 +335,9 @@ netlink_parse_link(struct nlmsghdr *msg, iff->lower_idx = -1; iff->upper_idx = -1; - for (attribute = IFLA_RTA(ifi); - RTA_OK(attribute, len); + for (attribute = IFLA_RTA(ifi); RTA_OK(attribute, len); attribute = RTA_NEXT(attribute, len)) { - switch(attribute->rta_type) { + switch (attribute->rta_type) { case IFLA_IFNAME: /* Interface name */ iff->name = strdup(RTA_DATA(attribute)); @@ -348,48 +350,57 @@ netlink_parse_link(struct nlmsghdr *msg, /* Interface MAC address */ iff->address = malloc(RTA_PAYLOAD(attribute)); if (iff->address) - memcpy(iff->address, RTA_DATA(attribute), RTA_PAYLOAD(attribute)); + memcpy(iff->address, RTA_DATA(attribute), + RTA_PAYLOAD(attribute)); break; case IFLA_LINK: /* Index of "lower" interface */ if (iff->lower_idx == -1) { - iff->lower_idx = *(int*)RTA_DATA(attribute); + iff->lower_idx = *(int *)RTA_DATA(attribute); log_debug("netlink", "attribute IFLA_LINK for %s: %d", - iff->name ? iff->name : "(unknown)", iff->lower_idx); + iff->name ? iff->name : "(unknown)", + iff->lower_idx); } else { - log_debug("netlink", "attribute IFLA_LINK for %s: %d (ignored)", - iff->name ? iff->name : "(unknown)", iff->lower_idx); + log_debug("netlink", + "attribute IFLA_LINK for %s: %d (ignored)", + iff->name ? iff->name : "(unknown)", + iff->lower_idx); } break; case IFLA_LINK_NETNSID: /* Is the lower interface into another namesapce? */ iff->lower_idx = -2; - log_debug("netlink", "attribute IFLA_LINK_NETNSID received for %s", + log_debug("netlink", + "attribute IFLA_LINK_NETNSID received for %s", iff->name ? iff->name : "(unknown)"); break; case IFLA_MASTER: /* Index of master interface */ - iff->upper_idx = *(int*)RTA_DATA(attribute); + iff->upper_idx = *(int *)RTA_DATA(attribute); break; case IFLA_MTU: /* Maximum Transmission Unit */ - iff->mtu = *(int*)RTA_DATA(attribute); + iff->mtu = *(int *)RTA_DATA(attribute); break; case IFLA_LINKINFO: - netlink_parse_linkinfo(iff, RTA_DATA(attribute), RTA_PAYLOAD(attribute)); + netlink_parse_linkinfo(iff, RTA_DATA(attribute), + RTA_PAYLOAD(attribute)); break; case IFLA_AF_SPEC: if (ifi->ifi_family != AF_BRIDGE) break; - netlink_parse_afspec(iff, RTA_DATA(attribute), RTA_PAYLOAD(attribute)); + netlink_parse_afspec(iff, RTA_DATA(attribute), + RTA_PAYLOAD(attribute)); break; default: - log_debug("netlink", "unhandled link attribute type %d for iface %s", + log_debug("netlink", + "unhandled link attribute type %d for iface %s", attribute->rta_type, iff->name ? iff->name : "(unknown)"); break; } } if (!iff->name || !iff->address) { - log_debug("netlink", "interface %d does not have a name or an address, skip", + log_debug("netlink", + "interface %d does not have a name or an address, skip", iff->index); return -1; } @@ -399,18 +410,18 @@ netlink_parse_link(struct nlmsghdr *msg, * and we don't want to miss it. */ iff->flags &= ~IFF_SLAVE; } - if (iff->lower_idx == -2) - iff->lower_idx = -1; + if (iff->lower_idx == -2) iff->lower_idx = -1; - if (ifi->ifi_family == AF_BRIDGE && msg->nlmsg_type == RTM_DELLINK && iff->upper_idx != -1) { - log_debug("netlink", "removal of %s from bridge %d", - iff->name, iff->upper_idx); + if (ifi->ifi_family == AF_BRIDGE && msg->nlmsg_type == RTM_DELLINK && + iff->upper_idx != -1) { + log_debug("netlink", "removal of %s from bridge %d", iff->name, + iff->upper_idx); msg->nlmsg_type = RTM_NEWLINK; iff->upper_idx = -1; } - log_debug("netlink", "parsed link %d (%s, flags: %d)", - iff->index, iff->name, iff->flags); + log_debug("netlink", "parsed link %d (%s, flags: %d)", iff->index, iff->name, + iff->flags); return 0; } @@ -422,8 +433,7 @@ netlink_parse_link(struct nlmsghdr *msg, * return 0 if the address is worth it, -1 otherwise */ static int -netlink_parse_address(struct nlmsghdr *msg, - struct interfaces_address *ifa) +netlink_parse_address(struct nlmsghdr *msg, struct interfaces_address *ifa) { struct ifaddrmsg *ifi; struct rtattr *attribute; @@ -435,17 +445,17 @@ netlink_parse_address(struct nlmsghdr *msg, ifa->flags = ifi->ifa_flags; switch (ifi->ifa_family) { case AF_INET: - case AF_INET6: break; + case AF_INET6: + break; default: log_debug("netlink", "got a non IP address on if %d (family: %d)", ifa->index, ifi->ifa_family); return -1; } - for (attribute = IFA_RTA(ifi); - RTA_OK(attribute, len); + for (attribute = IFA_RTA(ifi); RTA_OK(attribute, len); attribute = RTA_NEXT(attribute, len)) { - switch(attribute->rta_type) { + switch (attribute->rta_type) { case IFA_ADDRESS: /* Address */ if (ifi->ifa_family == AF_INET) { @@ -461,18 +471,19 @@ netlink_parse_address(struct nlmsghdr *msg, ip6.sin6_family = AF_INET6; memcpy(&ip6.sin6_addr, RTA_DATA(attribute), sizeof(struct in6_addr)); - memcpy(&ifa->address, &ip6, sizeof(struct sockaddr_in6)); + memcpy(&ifa->address, &ip6, + sizeof(struct sockaddr_in6)); } break; default: - log_debug("netlink", "unhandled address attribute type %d for iface %d", + log_debug("netlink", + "unhandled address attribute type %d for iface %d", attribute->rta_type, ifa->index); break; } } if (ifa->address.ss_family == AF_UNSPEC) { - log_debug("netlink", "no IP for interface %d", - ifa->index); + log_debug("netlink", "no IP for interface %d", ifa->index); return -1; } return 0; @@ -495,14 +506,12 @@ netlink_merge(struct interfaces_device *old, struct interfaces_device *new) new->address = old->address; old->address = NULL; } - if (new->mtu == 0) - new->mtu = old->mtu; - if (new->type == 0) - new->type = old->type; + if (new->mtu == 0) new->mtu = old->mtu; + if (new->type == 0) new->type = old->type; if (bitmap_isempty(new->vlan_bmap) && new->type == IFACE_VLAN_T) memcpy((void *)new->vlan_bmap, (void *)old->vlan_bmap, - sizeof(uint32_t) * VLAN_BITMAP_LEN); + sizeof(uint32_t) * VLAN_BITMAP_LEN); /* It's not possible for lower link to change */ new->lower_idx = old->lower_idx; @@ -516,8 +525,7 @@ netlink_merge(struct interfaces_device *old, struct interfaces_device *new) * @return 0 on success, -1 on error */ static int -netlink_recv(struct lldpd *cfg, - struct interfaces_device_list *ifs, +netlink_recv(struct lldpd *cfg, struct interfaces_device_list *ifs, struct interfaces_address_list *ifas) { int end = 0, ret = 0, flags, retry = 0; @@ -542,14 +550,12 @@ netlink_recv(struct lldpd *cfg, ssize_t len; struct nlmsghdr *msg; struct sockaddr_nl peer = { .nl_family = AF_NETLINK }; - struct msghdr rtnl_reply = { - .msg_iov = &iov, + struct msghdr rtnl_reply = { .msg_iov = &iov, .msg_iovlen = 1, .msg_name = &peer, - .msg_namelen = sizeof(struct sockaddr_nl) - }; + .msg_namelen = sizeof(struct sockaddr_nl) }; flags = MSG_PEEK | MSG_TRUNC; -retry: + retry: len = recvmsg(s, &rtnl_reply, flags); if (len == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { @@ -557,21 +563,21 @@ retry: levent_recv_error(s, "netlink socket"); goto retry; } - log_warnx("netlink", "should have received something, but didn't"); + log_warnx("netlink", + "should have received something, but didn't"); ret = 0; goto out; } int rsize = cfg->g_netlink->nl_socket_recv_size; - if (errno == ENOBUFS && - rsize > 0 && rsize < NETLINK_MAX_RECEIVE_BUFSIZE) { + if (errno == ENOBUFS && rsize > 0 && + rsize < NETLINK_MAX_RECEIVE_BUFSIZE) { /* Try to increase buffer size */ rsize *= 2; if (rsize > NETLINK_MAX_RECEIVE_BUFSIZE) { rsize = NETLINK_MAX_RECEIVE_BUFSIZE; } - int rc = netlink_socket_set_buffer_size(s, - SO_RCVBUF, "SO_RCVBUF", - rsize); + int rc = netlink_socket_set_buffer_size(s, SO_RCVBUF, + "SO_RCVBUF", rsize); if (rc < 0) cfg->g_netlink->nl_socket_recv_size = 0; else @@ -618,11 +624,9 @@ retry: goto retry; } - for (msg = (struct nlmsghdr*)(void*)(iov.iov_base); - NLMSG_OK(msg, len); - msg = NLMSG_NEXT(msg, len)) { - if (!(msg->nlmsg_flags & NLM_F_MULTI)) - end = 1; + for (msg = (struct nlmsghdr *)(void *)(iov.iov_base); + NLMSG_OK(msg, len); msg = NLMSG_NEXT(msg, len)) { + if (!(msg->nlmsg_flags & NLM_F_MULTI)) end = 1; switch (msg->nlmsg_type) { case NLMSG_DONE: log_debug("netlink", "received done message"); @@ -634,25 +638,32 @@ retry: log_debug("netlink", "received link information"); ifdnew = calloc(1, sizeof(struct interfaces_device)); if (ifdnew == NULL) { - log_warn("netlink", "not enough memory for another interface, give up what we have"); + log_warn("netlink", + "not enough memory for another interface, give up what we have"); goto end; } if (netlink_parse_link(msg, ifdnew) == 0) { - /* We need to find if we already have this interface */ - TAILQ_FOREACH(ifdold, ifs, next) { - if (ifdold->index == ifdnew->index) break; + /* We need to find if we already have this + * interface */ + TAILQ_FOREACH (ifdold, ifs, next) { + if (ifdold->index == ifdnew->index) + break; } if (msg->nlmsg_type == RTM_NEWLINK) { if (ifdold == NULL) { - log_debug("netlink", "interface %s is new", + log_debug("netlink", + "interface %s is new", ifdnew->name); - TAILQ_INSERT_TAIL(ifs, ifdnew, next); + TAILQ_INSERT_TAIL(ifs, ifdnew, + next); } else { - log_debug("netlink", "interface %s/%s is updated", + log_debug("netlink", + "interface %s/%s is updated", ifdold->name, ifdnew->name); netlink_merge(ifdold, ifdnew); - TAILQ_INSERT_AFTER(ifs, ifdold, ifdnew, next); + TAILQ_INSERT_AFTER(ifs, ifdold, + ifdnew, next); TAILQ_REMOVE(ifs, ifdold, next); interfaces_free_device(ifdold); } @@ -662,7 +673,8 @@ retry: "removal request for %s, but no knowledge of it", ifdnew->name); } else { - log_debug("netlink", "interface %s is to be removed", + log_debug("netlink", + "interface %s is to be removed", ifdold->name); TAILQ_REMOVE(ifs, ifdold, next); interfaces_free_device(ifdold); @@ -680,7 +692,8 @@ retry: log_debug("netlink", "received address information"); ifanew = calloc(1, sizeof(struct interfaces_address)); if (ifanew == NULL) { - log_warn("netlink", "not enough memory for another address, give what we have"); + log_warn("netlink", + "not enough memory for another address, give what we have"); goto end; } if (netlink_parse_address(msg, ifanew) == 0) { @@ -689,28 +702,37 @@ retry: interfaces_free_address(ifanew); break; } - TAILQ_FOREACH(ifaold, ifas, next) { + TAILQ_FOREACH (ifaold, ifas, next) { if ((ifaold->index == ifanew->index) && - !memcmp(&ifaold->address, &ifanew->address, - sizeof(ifaold->address))) break; + !memcmp(&ifaold->address, + &ifanew->address, + sizeof(ifaold->address))) + break; } - if (getnameinfo((struct sockaddr *)&ifanew->address, - sizeof(ifanew->address), - addr, sizeof(addr), - NULL, 0, NI_NUMERICHOST) != 0) { - strlcpy(addr, "(unknown)", sizeof(addr)); + if (getnameinfo( + (struct sockaddr *)&ifanew->address, + sizeof(ifanew->address), addr, + sizeof(addr), NULL, 0, + NI_NUMERICHOST) != 0) { + strlcpy(addr, "(unknown)", + sizeof(addr)); } if (msg->nlmsg_type == RTM_NEWADDR) { if (ifaold == NULL) { - log_debug("netlink", "new address %s%%%d", - addr, ifanew->index); - TAILQ_INSERT_TAIL(ifas, ifanew, next); + log_debug("netlink", + "new address %s%%%d", addr, + ifanew->index); + TAILQ_INSERT_TAIL(ifas, ifanew, + next); } else { - log_debug("netlink", "updated address %s%%%d", + log_debug("netlink", + "updated address %s%%%d", addr, ifaold->index); - TAILQ_INSERT_AFTER(ifas, ifaold, ifanew, next); - TAILQ_REMOVE(ifas, ifaold, next); + TAILQ_INSERT_AFTER(ifas, ifaold, + ifanew, next); + TAILQ_REMOVE(ifas, ifaold, + next); interfaces_free_address(ifaold); } } else { @@ -719,9 +741,11 @@ retry: "removal request for address of %s%%%d, but no knowledge of it", addr, ifanew->index); } else { - log_debug("netlink", "address %s%%%d is to be removed", + log_debug("netlink", + "address %s%%%d is to be removed", addr, ifaold->index); - TAILQ_REMOVE(ifas, ifaold, next); + TAILQ_REMOVE(ifas, ifaold, + next); interfaces_free_address(ifaold); } interfaces_free_address(ifanew); @@ -741,9 +765,10 @@ end: if (link_update) { /* Fill out lower/upper */ struct interfaces_device *iface1, *iface2; - TAILQ_FOREACH(iface1, ifs, next) { - if (iface1->upper_idx != -1 && iface1->upper_idx != iface1->index) { - TAILQ_FOREACH(iface2, ifs, next) { + TAILQ_FOREACH (iface1, ifs, next) { + if (iface1->upper_idx != -1 && + iface1->upper_idx != iface1->index) { + TAILQ_FOREACH (iface2, ifs, next) { if (iface1->upper_idx == iface2->index) { log_debug("netlink", "upper interface for %s is %s", @@ -752,13 +777,13 @@ end: break; } } - if (iface2 == NULL) - iface1->upper = NULL; + if (iface2 == NULL) iface1->upper = NULL; } else { iface1->upper = NULL; } - if (iface1->lower_idx != -1 && iface1->lower_idx != iface1->index) { - TAILQ_FOREACH(iface2, ifs, next) { + if (iface1->lower_idx != -1 && + iface1->lower_idx != iface1->index) { + TAILQ_FOREACH (iface2, ifs, next) { if (iface1->lower_idx == iface2->index) { /* Workaround a bug introduced * in Linux 4.1: a pair of veth @@ -768,12 +793,12 @@ end: * updated, we will loose the * information about the * loop. */ - if (iface2->lower_idx == iface1->index) { + if (iface2->lower_idx == + iface1->index) { iface1->lower = NULL; log_debug("netlink", "link loop detected between %s(%d) and %s(%d)", - iface1->name, - iface1->index, + iface1->name, iface1->index, iface2->name, iface2->index); } else { @@ -826,11 +851,8 @@ netlink_subscribe_changes(struct lldpd *cfg) static void netlink_change_cb(struct lldpd *cfg) { - if (cfg->g_netlink == NULL) - return; - netlink_recv(cfg, - cfg->g_netlink->devices, - cfg->g_netlink->addresses); + if (cfg->g_netlink == NULL) return; + netlink_recv(cfg, cfg->g_netlink->devices, cfg->g_netlink->addresses); } /** @@ -857,8 +879,7 @@ netlink_initialize(struct lldpd *cfg) /* Connect to netlink (by requesting to get notified on updates) and * request updated information right now */ - if (netlink_subscribe_changes(cfg) == -1) - goto end; + if (netlink_subscribe_changes(cfg) == -1) goto end; struct interfaces_address_list *ifaddrs = cfg->g_netlink->addresses = malloc(sizeof(struct interfaces_address_list)); @@ -884,10 +905,12 @@ netlink_initialize(struct lldpd *cfg) netlink_recv(cfg, ifs, NULL); #ifdef ENABLE_DOT1 /* If we have a bridge, search for VLAN-aware bridges */ - TAILQ_FOREACH(iff, ifs, next) { + TAILQ_FOREACH (iff, ifs, next) { if (iff->type & IFACE_BRIDGE_T) { - log_debug("netlink", "interface %s is a bridge, check for VLANs", iff->name); - if (netlink_send(cfg->g_netlink->nl_socket, RTM_GETLINK, AF_BRIDGE, 3) == -1) + log_debug("netlink", + "interface %s is a bridge, check for VLANs", iff->name); + if (netlink_send(cfg->g_netlink->nl_socket, RTM_GETLINK, + AF_BRIDGE, 3) == -1) goto end; netlink_recv(cfg, ifs, NULL); break; @@ -914,8 +937,7 @@ void netlink_cleanup(struct lldpd *cfg) { if (cfg->g_netlink == NULL) return; - if (cfg->g_netlink->nl_socket != -1) - close(cfg->g_netlink->nl_socket); + if (cfg->g_netlink->nl_socket != -1) close(cfg->g_netlink->nl_socket); interfaces_free_devices(cfg->g_netlink->devices); interfaces_free_addresses(cfg->g_netlink->addresses); @@ -928,12 +950,12 @@ netlink_cleanup(struct lldpd *cfg) * * @return a list of interfaces. */ -struct interfaces_device_list* +struct interfaces_device_list * netlink_get_interfaces(struct lldpd *cfg) { if (netlink_initialize(cfg) == -1) return NULL; struct interfaces_device *ifd; - TAILQ_FOREACH(ifd, cfg->g_netlink->devices, next) { + TAILQ_FOREACH (ifd, cfg->g_netlink->devices, next) { ifd->ignore = 0; } return cfg->g_netlink->devices; @@ -944,7 +966,7 @@ netlink_get_interfaces(struct lldpd *cfg) * * @return a list of addresses. */ -struct interfaces_address_list* +struct interfaces_address_list * netlink_get_addresses(struct lldpd *cfg) { if (netlink_initialize(cfg) == -1) return NULL; diff --git a/src/daemon/pattern.c b/src/daemon/pattern.c index 27c56f83..0f9885d2 100644 --- a/src/daemon/pattern.c +++ b/src/daemon/pattern.c @@ -53,18 +53,17 @@ pattern_match(char *string, char *patterns, int found) return PATTERN_MATCH_DENIED; } - for (pattern = strtok(patterns, ","); - pattern != NULL; + for (pattern = strtok(patterns, ","); pattern != NULL; pattern = strtok(NULL, ",")) { if ((pattern[0] == '!') && (pattern[1] == '!') && (fnmatch(pattern + 2, string, 0) == 0)) { /* Allowed. No need to search further. */ found = (strcmp(pattern + 2, string)) ? - PATTERN_MATCH_ALLOWED : PATTERN_MATCH_ALLOWED_EXACT; + PATTERN_MATCH_ALLOWED : + PATTERN_MATCH_ALLOWED_EXACT; break; } - if ((pattern[0] == '!') && - (fnmatch(pattern + 1, string, 0) == 0)) { + if ((pattern[0] == '!') && (fnmatch(pattern + 1, string, 0) == 0)) { denied = 1; found = PATTERN_MATCH_DENIED; } else if (!denied && fnmatch(pattern, string, 0) == 0) { diff --git a/src/daemon/priv-bsd.c b/src/daemon/priv-bsd.c index f32f990c..61f332a5 100644 --- a/src/daemon/priv-bsd.c +++ b/src/daemon/priv-bsd.c @@ -32,10 +32,8 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) int enable, required, rc; struct bpf_insn filter[] = { LLDPD_FILTER_F }; struct ifreq ifr = { .ifr_name = {} }; - struct bpf_program fprog = { - .bf_insns = filter, - .bf_len = sizeof(filter)/sizeof(struct bpf_insn) - }; + struct bpf_program fprog = { .bf_insns = filter, + .bf_len = sizeof(filter) / sizeof(struct bpf_insn) }; #ifndef HOST_OS_SOLARIS int n = 0; @@ -57,8 +55,7 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) required = ETHER_MAX_LEN + BPF_WORDALIGN(sizeof(struct bpf_hdr)); if (ioctl(*fd, BIOCSBLEN, (caddr_t)&required) < 0) { rc = errno; - log_warn("privsep", - "unable to set receive buffer size for BPF on %s", + log_warn("privsep", "unable to set receive buffer size for BPF on %s", name); return rc; } @@ -67,8 +64,7 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) strlcpy(ifr.ifr_name, name, IFNAMSIZ); if (ioctl(*fd, BIOCSETIF, (caddr_t)&ifr) < 0) { rc = errno; - log_warn("privsep", "failed to bind interface %s to BPF", - name); + log_warn("privsep", "failed to bind interface %s to BPF", name); return rc; } @@ -76,8 +72,7 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) enable = 1; if (ioctl(*fd, BIOCIMMEDIATE, (caddr_t)&enable) < 0) { rc = errno; - log_warn("privsep", "unable to disable buffering for %s", - name); + log_warn("privsep", "unable to disable buffering for %s", name); return rc; } @@ -85,8 +80,7 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) enable = 1; if (ioctl(*fd, BIOCSHDRCMPLT, (caddr_t)&enable) < 0) { rc = errno; - log_warn("privsep", - "unable to set the `header complete` flag for %s", + log_warn("privsep", "unable to set the `header complete` flag for %s", name); return rc; } @@ -102,24 +96,21 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) { rc = errno; log_warn("privsep", - "unable to set packet direction for BPF filter on %s", - name); + "unable to set packet direction for BPF filter on %s", name); return rc; } /* Install read filter */ if (ioctl(*fd, BIOCSETF, (caddr_t)&fprog) < 0) { rc = errno; - log_warn("privsep", "unable to setup BPF filter for %s", - name); + log_warn("privsep", "unable to setup BPF filter for %s", name); return rc; } #ifdef BIOCSETWF /* Install write filter (optional) */ if (ioctl(*fd, BIOCSETWF, (caddr_t)&fprog) < 0) { rc = errno; - log_info("privsep", "unable to setup write BPF filter for %s", - name); + log_info("privsep", "unable to setup write BPF filter for %s", name); return rc; } #endif @@ -130,8 +121,7 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) levent_make_socket_nonblocking(*fd); if (ioctl(*fd, BIOCLOCK, (caddr_t)&enable) < 0) { rc = errno; - log_info("privsep", "unable to lock BPF interface %s", - name); + log_info("privsep", "unable to lock BPF interface %s", name); return rc; } #endif @@ -142,19 +132,14 @@ int asroot_iface_description_os(const char *name, const char *description) { #ifdef IFDESCRSIZE -#if defined HOST_OS_FREEBSD || defined HOST_OS_OPENBSD +# if defined HOST_OS_FREEBSD || defined HOST_OS_OPENBSD char descr[IFDESCRSIZE]; int rc, sock = -1; -#if defined HOST_OS_FREEBSD - struct ifreq ifr = { - .ifr_buffer = { .buffer = descr, - .length = IFDESCRSIZE } - }; -#else - struct ifreq ifr = { - .ifr_data = (caddr_t)descr - }; -#endif +# if defined HOST_OS_FREEBSD + struct ifreq ifr = { .ifr_buffer = { .buffer = descr, .length = IFDESCRSIZE } }; +# else + struct ifreq ifr = { .ifr_data = (caddr_t)descr }; +# endif strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == 1) { rc = errno; @@ -165,8 +150,7 @@ asroot_iface_description_os(const char *name, const char *description) /* No neighbor, try to append "was" to the current description */ if (ioctl(sock, SIOCGIFDESCR, (caddr_t)&ifr) < 0) { rc = errno; - log_warnx("privsep", "unable to get description of %s", - name); + log_warnx("privsep", "unable to get description of %s", name); close(sock); return rc; } @@ -177,8 +161,7 @@ asroot_iface_description_os(const char *name, const char *description) return 0; } else { /* Append was */ - memmove(descr + 11, descr + 7, - sizeof(descr) - 11); + memmove(descr + 11, descr + 7, sizeof(descr) - 11); memcpy(descr, "lldpd: was ", 11); } } else { @@ -187,19 +170,18 @@ asroot_iface_description_os(const char *name, const char *description) } } else snprintf(descr, sizeof(descr), "lldpd: connected to %s", description); -#if defined HOST_OS_FREEBSD +# if defined HOST_OS_FREEBSD ift.ifr_buffer.length = strlen(descr); -#endif +# endif if (ioctl(sock, SIOCSIFDESCR, (caddr_t)&ifr) < 0) { rc = errno; - log_warnx("privsep", "unable to set description of %s", - name); + log_warnx("privsep", "unable to set description of %s", name); close(sock); return rc; } close(sock); return 0; -#endif +# endif #endif /* IFDESCRSIZE */ static int once = 0; if (!once) { diff --git a/src/daemon/priv-linux.c b/src/daemon/priv-linux.c index 36a4039c..56488328 100644 --- a/src/daemon/priv-linux.c +++ b/src/daemon/priv-linux.c @@ -28,15 +28,15 @@ #include #include /* For sockaddr_ll */ #if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdocumentation" +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdocumentation" #endif -#include /* For BPF filtering */ +#include /* For BPF filtering */ #include #include #include #if defined(__clang__) -#pragma clang diagnostic pop +# pragma clang diagnostic pop #endif /* Defined in linux/pkt_sched.h */ @@ -56,48 +56,38 @@ priv_open(char *file) must_write(PRIV_UNPRIVILEGED, file, len); priv_wait(); must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int)); - if (rc == -1) - return rc; + if (rc == -1) return rc; return receive_fd(PRIV_UNPRIVILEGED); } void asroot_open() { - const char* authorized[] = { - PROCFS_SYS_NET "ipv4/ip_forward", + const char *authorized[] = { PROCFS_SYS_NET "ipv4/ip_forward", PROCFS_SYS_NET "ipv6/conf/all/forwarding", - "/proc/net/bonding/[^.][^/]*", - "/proc/self/net/bonding/[^.][^/]*", + "/proc/net/bonding/[^.][^/]*", "/proc/self/net/bonding/[^.][^/]*", #ifdef ENABLE_OLDIES SYSFS_CLASS_NET "[^.][^/]*/brforward", SYSFS_CLASS_NET "[^.][^/]*/brport", SYSFS_CLASS_NET "[^.][^/]*/brif/[^.][^/]*/port_no", #endif - SYSFS_CLASS_DMI "product_version", - SYSFS_CLASS_DMI "product_serial", - SYSFS_CLASS_DMI "product_name", - SYSFS_CLASS_DMI "bios_version", - SYSFS_CLASS_DMI "sys_vendor", - SYSFS_CLASS_DMI "chassis_asset_tag", - NULL - }; + SYSFS_CLASS_DMI "product_version", SYSFS_CLASS_DMI "product_serial", + SYSFS_CLASS_DMI "product_name", SYSFS_CLASS_DMI "bios_version", + SYSFS_CLASS_DMI "sys_vendor", SYSFS_CLASS_DMI "chassis_asset_tag", + NULL }; const char **f; char *file; int fd, len, rc; regex_t preg; must_read(PRIV_PRIVILEGED, &len, sizeof(len)); - if (len < 0 || len > PATH_MAX) - fatalx("privsep", "too large value requested"); - if ((file = (char *)malloc(len + 1)) == NULL) - fatal("privsep", NULL); + if (len < 0 || len > PATH_MAX) fatalx("privsep", "too large value requested"); + if ((file = (char *)malloc(len + 1)) == NULL) fatal("privsep", NULL); must_read(PRIV_PRIVILEGED, file, len); file[len] = '\0'; - for (f=authorized; *f != NULL; f++) { - if (regcomp(&preg, *f, REG_NOSUB) != 0) - /* Should not happen */ + for (f = authorized; *f != NULL; f++) { + if (regcomp(&preg, *f, REG_NOSUB) != 0) /* Should not happen */ fatal("privsep", "unable to compile a regex"); if (regexec(&preg, file, 0, NULL, 0) == 0) { regfree(&preg); @@ -133,12 +123,8 @@ asroot_iface_init_quirks(int ifindex, char *name) int fd = -1; /* Check driver. */ - struct ethtool_drvinfo ethc = { - .cmd = ETHTOOL_GDRVINFO - }; - struct ifreq ifr = { - .ifr_data = (caddr_t)ðc - }; + struct ethtool_drvinfo ethc = { .cmd = ETHTOOL_GDRVINFO }; + struct ifreq ifr = { .ifr_data = (caddr_t)ðc }; if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { log_warn("privsep", "unable to open a socket"); goto end; @@ -150,8 +136,7 @@ asroot_iface_init_quirks(int ifindex, char *name) goto end; } log_info("interfaces", - "i40e driver detected for %s, disabling LLDP in firmware", - name); + "i40e driver detected for %s, disabling LLDP in firmware", name); /* We assume debugfs is mounted. Otherwise, we would need to check if it * is mounted, then unshare a new mount namespace, mount it, issues the @@ -168,10 +153,9 @@ asroot_iface_init_quirks(int ifindex, char *name) */ char command[] = "lldp stop"; - char sysfs_path[SYSFS_PATH_MAX+1]; - if (snprintf(sysfs_path, SYSFS_PATH_MAX, - "/sys/kernel/debug/i40e/%.*s/command", - (int)sizeof(ethc.bus_info), ethc.bus_info) >= SYSFS_PATH_MAX) { + char sysfs_path[SYSFS_PATH_MAX + 1]; + if (snprintf(sysfs_path, SYSFS_PATH_MAX, "/sys/kernel/debug/i40e/%.*s/command", + (int)sizeof(ethc.bus_info), ethc.bus_info) >= SYSFS_PATH_MAX) { log_warnx("interfaces", "path truncated"); goto end; } @@ -184,14 +168,12 @@ asroot_iface_init_quirks(int ifindex, char *name) goto end; } log_warn("interfaces", - "cannot open %s to disable LLDP in firmware for %s", - sysfs_path, name); + "cannot open %s to disable LLDP in firmware for %s", sysfs_path, + name); goto end; } if (write(fd, command, sizeof(command) - 1) == -1) { - log_warn("interfaces", - "cannot disable LLDP in firmware for %s", - name); + log_warn("interfaces", "cannot disable LLDP in firmware for %s", name); goto end; } end: @@ -204,20 +186,15 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) { int rc; /* Open listening socket to receive/send frames */ - if ((*fd = socket(PF_PACKET, SOCK_RAW, - htons(ETH_P_ALL))) < 0) { + if ((*fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { rc = errno; return rc; } - struct sockaddr_ll sa = { - .sll_family = AF_PACKET, - .sll_ifindex = ifindex - }; - if (bind(*fd, (struct sockaddr*)&sa, sizeof(sa)) < 0) { + struct sockaddr_ll sa = { .sll_family = AF_PACKET, .sll_ifindex = ifindex }; + if (bind(*fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { rc = errno; - log_warn("privsep", - "unable to bind to raw socket for interface %s", + log_warn("privsep", "unable to bind to raw socket for interface %s", name); return rc; } @@ -225,12 +202,9 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) /* Set filter */ log_debug("privsep", "set BPF filter for %s", name); static struct sock_filter lldpd_filter_f[] = { LLDPD_FILTER_F }; - struct sock_fprog prog = { - .filter = lldpd_filter_f, - .len = sizeof(lldpd_filter_f) / sizeof(struct sock_filter) - }; - if (setsockopt(*fd, SOL_SOCKET, SO_ATTACH_FILTER, - &prog, sizeof(prog)) < 0) { + struct sock_fprog prog = { .filter = lldpd_filter_f, + .len = sizeof(lldpd_filter_f) / sizeof(struct sock_filter) }; + if (setsockopt(*fd, SOL_SOCKET, SO_ATTACH_FILTER, &prog, sizeof(prog)) < 0) { rc = errno; log_warn("privsep", "unable to change filter for %s", name); return rc; @@ -248,8 +222,7 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) #ifdef SO_LOCK_FILTER int lock = 1; - if (setsockopt(*fd, SOL_SOCKET, SO_LOCK_FILTER, - &lock, sizeof(lock)) < 0) { + if (setsockopt(*fd, SOL_SOCKET, SO_LOCK_FILTER, &lock, sizeof(lock)) < 0) { if (errno != ENOPROTOOPT) { rc = errno; log_warn("privsep", "unable to lock filter for %s", name); @@ -259,8 +232,8 @@ asroot_iface_init_os(int ifindex, char *name, int *fd) #endif #ifdef PACKET_IGNORE_OUTGOING int ignore = 1; - if (setsockopt(*fd, SOL_PACKET, PACKET_IGNORE_OUTGOING, - &ignore, sizeof(ignore)) < 0) { + if (setsockopt(*fd, SOL_PACKET, PACKET_IGNORE_OUTGOING, &ignore, + sizeof(ignore)) < 0) { if (errno != ENOPROTOOPT) { rc = errno; log_warn("privsep", @@ -282,7 +255,7 @@ asroot_iface_description_os(const char *name, const char *description) * process. Just write to /sys/class/net/XXXX/ifalias. */ char *file; #ifndef IFALIASZ -# define IFALIASZ 256 +# define IFALIASZ 256 #endif char descr[IFALIASZ]; FILE *fp; @@ -292,7 +265,8 @@ asroot_iface_description_os(const char *name, const char *description) return -1; } if (asprintf(&file, SYSFS_CLASS_NET "%s/ifalias", name) == -1) { - log_warn("privsep", "unable to allocate memory for setting description"); + log_warn("privsep", + "unable to allocate memory for setting description"); return -1; } if ((fp = fopen(file, "r+")) == NULL) { @@ -303,8 +277,7 @@ asroot_iface_description_os(const char *name, const char *description) return rc; } free(file); - if (strlen(description) == 0 && - fgets(descr, sizeof(descr), fp) != NULL) { + if (strlen(description) == 0 && fgets(descr, sizeof(descr), fp) != NULL) { if (strncmp(descr, "lldpd: ", 7) == 0) { if (strncmp(descr + 7, "was ", 4) == 0) { /* Already has an old neighbor */ @@ -312,8 +285,7 @@ asroot_iface_description_os(const char *name, const char *description) return 0; } else { /* Append was */ - memmove(descr + 11, descr + 7, - sizeof(descr) - 11); + memmove(descr + 11, descr + 7, sizeof(descr) - 11); memcpy(descr, "lldpd: was ", 11); } } else { @@ -323,8 +295,7 @@ asroot_iface_description_os(const char *name, const char *description) } else snprintf(descr, sizeof(descr), "lldpd: connected to %s", description); if (fputs(descr, fp) == EOF) { - log_debug("privsep", "cannot set interface description for %s", - name); + log_debug("privsep", "cannot set interface description for %s", name); fclose(fp); return -1; } @@ -336,8 +307,7 @@ int asroot_iface_promisc_os(const char *name) { int s, rc; - if ((s = socket(PF_PACKET, SOCK_RAW, - htons(ETH_P_ALL))) < 0) { + if ((s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { rc = errno; log_warn("privsep", "unable to open raw socket"); return rc; @@ -348,8 +318,7 @@ asroot_iface_promisc_os(const char *name) if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) { rc = errno; - log_warn("privsep", "unable to get interface flags for %s", - name); + log_warn("privsep", "unable to get interface flags for %s", name); close(s); return rc; } @@ -361,8 +330,7 @@ asroot_iface_promisc_os(const char *name) ifr.ifr_flags |= IFF_PROMISC; if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) { rc = errno; - log_warn("privsep", "unable to set promisc mode for %s", - name); + log_warn("privsep", "unable to set promisc mode for %s", name); close(s); return rc; } diff --git a/src/daemon/priv-seccomp.c b/src/daemon/priv-seccomp.c index 3f78e61f..8322cb28 100644 --- a/src/daemon/priv-seccomp.c +++ b/src/daemon/priv-seccomp.c @@ -25,19 +25,19 @@ #include #ifndef SYS_SECCOMP -# define SYS_SECCOMP 1 +# define SYS_SECCOMP 1 #endif #if defined(__i386__) -# define REG_SYSCALL REG_EAX -# define ARCH_NR AUDIT_ARCH_I386 +# define REG_SYSCALL REG_EAX +# define ARCH_NR AUDIT_ARCH_I386 #elif defined(__x86_64__) -# define REG_SYSCALL REG_RAX -# define ARCH_NR AUDIT_ARCH_X86_64 +# define REG_SYSCALL REG_RAX +# define ARCH_NR AUDIT_ARCH_X86_64 #else -# error "Platform does not support seccomp filter yet" -# define REG_SYSCALL 0 -# define ARCH_NR 0 +# error "Platform does not support seccomp filter yet" +# define REG_SYSCALL 0 +# define ARCH_NR 0 #endif /* If there is no privilege separation, seccomp is currently useless */ @@ -60,21 +60,18 @@ priv_seccomp_trap_handler(int signal, siginfo_t *info, void *vctx) ucontext_t *ctx = (ucontext_t *)(vctx); unsigned int syscall; - if (trapped) - _exit(161); /* Avoid loops */ + if (trapped) _exit(161); /* Avoid loops */ /* Get details */ - if (info->si_code != SYS_SECCOMP) - return; - if (!ctx) - _exit(161); + if (info->si_code != SYS_SECCOMP) return; + if (!ctx) _exit(161); syscall = ctx->uc_mcontext.gregs[REG_SYSCALL]; trapped = 1; /* Log them. Technically, `log_warnx()` is not signal safe, but we are * unlikely to reenter here. */ log_warnx("seccomp", "invalid syscall attempted: %s(%d)", - (syscall < sizeof(syscall_names))?syscall_names[syscall]:"unknown", + (syscall < sizeof(syscall_names)) ? syscall_names[syscall] : "unknown", syscall); /* Kill children and exit */ @@ -102,10 +99,8 @@ priv_seccomp_trap_install() signal_handler.sa_sigaction = &priv_seccomp_trap_handler; signal_handler.sa_flags = SA_SIGINFO; - if (sigaction(SIGSYS, &signal_handler, NULL) < 0) - return -errno; - if (sigprocmask(SIG_UNBLOCK, &signal_mask, NULL)) - return -errno; + if (sigaction(SIGSYS, &signal_handler, NULL) < 0) return -errno; + if (sigprocmask(SIG_UNBLOCK, &signal_mask, NULL)) return -errno; return 0; } @@ -135,10 +130,10 @@ priv_seccomp_init(int remote, int child) goto failure_scmp; } - if ((rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, - SCMP_SYS(read), 1, SCMP_CMP(0, SCMP_CMP_EQ, remote))) < 0 || - (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, - SCMP_SYS(write), 1, SCMP_CMP(0, SCMP_CMP_EQ, remote))) < 0) { + if ((rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 1, + SCMP_CMP(0, SCMP_CMP_EQ, remote))) < 0 || + (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 1, + SCMP_CMP(0, SCMP_CMP_EQ, remote))) < 0) { errno = -rc; log_warn("seccomp", "unable to allow read/write on remote socket"); goto failure_scmp; @@ -146,7 +141,8 @@ priv_seccomp_init(int remote, int child) /* We are far more generic from here. */ if ((rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0)) < 0 || - (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0)) < 0 || /* write needed for */ + (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0)) < + 0 || /* write needed for */ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(open), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(openat), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(lseek), 0)) < 0 || @@ -155,7 +151,8 @@ priv_seccomp_init(int remote, int child) (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(socket), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(bind), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(setsockopt), 0)) < 0 || - (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockname), 0)) < 0 || + (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockname), 0)) < + 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(uname), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(unlink), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(ioctl), 0)) < 0 || @@ -163,9 +160,11 @@ priv_seccomp_init(int remote, int child) (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(sendmmsg), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(wait4), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(stat), 0)) < 0 || - (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(brk), 0)) < 0 || /* brk needed for newer libc */ + (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(brk), 0)) < + 0 || /* brk needed for newer libc */ (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getpid), 0)) < 0 || - (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigreturn), 0)) < 0 || + (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigreturn), 0)) < + 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(sendto), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(poll), 0)) < 0 || @@ -174,12 +173,15 @@ priv_seccomp_init(int remote, int child) (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(readv), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mprotect), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(sendmmsg), 0)) < 0 || - (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(clock_gettime), 0)) < 0 || - (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(gettimeofday), 0)) < 0 || + (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(clock_gettime), 0)) < + 0 || + (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(gettimeofday), 0)) < + 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(newfstatat), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(pread64), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(access), 0)) < 0 || - (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigprocmask), 0)) < 0 || + (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(rt_sigprocmask), 0)) < + 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(getsockopt), 0)) < 0 || (rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(ppoll), 0)) < 0 || /* The following are for resolving addresses */ diff --git a/src/daemon/priv.c b/src/daemon/priv.c index e13604a9..389af411 100644 --- a/src/daemon/priv.c +++ b/src/daemon/priv.c @@ -39,15 +39,15 @@ #include #ifdef HAVE_LINUX_CAPABILITIES -#include -#include +# include +# include #endif #if defined HOST_OS_FREEBSD || defined HOST_OS_OSX || defined HOST_OS_DRAGONFLY -# include +# include #endif #if defined HOST_OS_SOLARIS -# include +# include #endif /* Use resolv.h */ @@ -69,11 +69,11 @@ /* Bionic has res_init() but it's not in any header */ #if defined HAVE_RES_INIT && defined __BIONIC__ -int res_init (void); +int res_init(void); #endif #ifdef ENABLE_PRIVSEP -static int monitored = -1; /* Child */ +static int monitored = -1; /* Child */ #endif /* Proxies */ @@ -111,16 +111,13 @@ priv_gethostname() must_write(PRIV_UNPRIVILEGED, &cmd, sizeof(enum priv_cmd)); priv_wait(); must_read(PRIV_UNPRIVILEGED, &len, sizeof(int)); - if (len < 0 || len > 255) - fatalx("privsep", "too large value requested"); - if ((buf = (char*)realloc(buf, len+1)) == NULL) - fatal("privsep", NULL); + if (len < 0 || len > 255) fatalx("privsep", "too large value requested"); + if ((buf = (char *)realloc(buf, len + 1)) == NULL) fatal("privsep", NULL); must_read(PRIV_UNPRIVILEGED, buf, len); buf[len] = '\0'; return buf; } - int priv_iface_init(int index, char *iface) { @@ -187,8 +184,7 @@ priv_snmp_socket(struct sockaddr_un *addr) must_write(PRIV_UNPRIVILEGED, addr, sizeof(struct sockaddr_un)); priv_wait(); must_read(PRIV_UNPRIVILEGED, &rc, sizeof(int)); - if (rc < 0) - return rc; + if (rc < 0) return rc; return receive_fd(PRIV_UNPRIVILEGED); } @@ -207,10 +203,8 @@ asroot_ctl_cleanup() int rc = 0; must_read(PRIV_PRIVILEGED, &len, sizeof(int)); - if (len < 0 || len > PATH_MAX) - fatalx("privsep", "too large value requested"); - if ((ctlname = (char*)malloc(len+1)) == NULL) - fatal("privsep", NULL); + if (len < 0 || len > PATH_MAX) fatalx("privsep", "too large value requested"); + if ((ctlname = (char *)malloc(len + 1)) == NULL) fatal("privsep", NULL); must_read(PRIV_PRIVILEGED, ctlname, len); ctlname[len] = 0; @@ -226,27 +220,24 @@ static void asroot_gethostname() { struct utsname un; - struct addrinfo hints = { - .ai_flags = AI_CANONNAME - }; + struct addrinfo hints = { .ai_flags = AI_CANONNAME }; struct addrinfo *res; int len; - if (uname(&un) < 0) - fatal("privsep", "failed to get system information"); + if (uname(&un) < 0) fatal("privsep", "failed to get system information"); if (getaddrinfo(un.nodename, NULL, &hints, &res) != 0) { log_info("privsep", "unable to get system name"); #ifdef HAVE_RES_INIT res_init(); #endif - len = strlen(un.nodename); - must_write(PRIV_PRIVILEGED, &len, sizeof(int)); - must_write(PRIV_PRIVILEGED, un.nodename, len); - } else { - len = strlen(res->ai_canonname); - must_write(PRIV_PRIVILEGED, &len, sizeof(int)); - must_write(PRIV_PRIVILEGED, res->ai_canonname, len); + len = strlen(un.nodename); + must_write(PRIV_PRIVILEGED, &len, sizeof(int)); + must_write(PRIV_PRIVILEGED, un.nodename, len); + } else { + len = strlen(res->ai_canonname); + must_write(PRIV_PRIVILEGED, &len, sizeof(int)); + must_write(PRIV_PRIVILEGED, res->ai_canonname, len); freeaddrinfo(res); - } + } } static void @@ -262,7 +253,7 @@ asroot_iface_init() TRACE(LLDPD_PRIV_INTERFACE_INIT(name)); rc = asroot_iface_init_os(ifindex, name, &fd); must_write(PRIV_PRIVILEGED, &rc, sizeof(rc)); - if (rc == 0 && fd >=0) send_fd(PRIV_PRIVILEGED, fd); + if (rc == 0 && fd >= 0) send_fd(PRIV_PRIVILEGED, fd); if (fd >= 0) close(fd); } @@ -286,19 +277,19 @@ asroot_iface_multicast() must_read(PRIV_PRIVILEGED, LLADDR(dlp), ETHER_ADDR_LEN); #elif defined HOST_OS_OPENBSD || defined HOST_OS_NETBSD || defined HOST_OS_SOLARIS struct sockaddr *sap = (struct sockaddr *)&ifr.ifr_addr; -#if ! defined HOST_OS_SOLARIS +# if !defined HOST_OS_SOLARIS sap->sa_len = sizeof(struct sockaddr); -#endif +# endif sap->sa_family = AF_UNSPEC; must_read(PRIV_PRIVILEGED, sap->sa_data, ETHER_ADDR_LEN); #else -#error Unsupported OS +# error Unsupported OS #endif must_read(PRIV_PRIVILEGED, &add, sizeof(int)); if (((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) || - ((ioctl(sock, (add)?SIOCADDMULTI:SIOCDELMULTI, - &ifr) < 0) && (errno != EADDRINUSE))) + ((ioctl(sock, (add) ? SIOCADDMULTI : SIOCDELMULTI, &ifr) < 0) && + (errno != EADDRINUSE))) rc = errno; if (sock != -1) close(sock); @@ -314,10 +305,8 @@ asroot_iface_description() must_read(PRIV_PRIVILEGED, &name, sizeof(name)); name[sizeof(name) - 1] = '\0'; must_read(PRIV_PRIVILEGED, &len, sizeof(int)); - if (len < 0 || len > PATH_MAX) - fatalx("privsep", "too large value requested"); - if ((description = (char*)malloc(len+1)) == NULL) - fatal("privsep", NULL); + if (len < 0 || len > PATH_MAX) fatalx("privsep", "too large value requested"); + if ((description = (char *)malloc(len + 1)) == NULL) fatal("privsep", NULL); must_read(PRIV_PRIVILEGED, description, len); description[len] = 0; @@ -355,28 +344,28 @@ asroot_snmp_socket() must_read(PRIV_PRIVILEGED, &bogus, sizeof(struct sockaddr_un)); if (addr->sun_family != AF_UNIX) fatal("privsep", "someone is trying to trick me"); - addr->sun_path[sizeof(addr->sun_path)-1] = '\0'; + addr->sun_path[sizeof(addr->sun_path) - 1] = '\0'; if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { log_warn("privsep", "cannot open socket"); must_write(PRIV_PRIVILEGED, &sock, sizeof(int)); return; } - if ((rc = connect(sock, (struct sockaddr *) addr, - sizeof(struct sockaddr_un))) != 0) { - log_info("privsep", "cannot connect to %s: %s", - addr->sun_path, strerror(errno)); + if ((rc = connect(sock, (struct sockaddr *)addr, sizeof(struct sockaddr_un))) != + 0) { + log_info("privsep", "cannot connect to %s: %s", addr->sun_path, + strerror(errno)); close(sock); rc = -1; must_write(PRIV_PRIVILEGED, &rc, sizeof(int)); return; - } + } int flags; if ((flags = fcntl(sock, F_GETFL, NULL)) < 0 || fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) { log_warn("privsep", "cannot set sock %s to non-block : %s", - addr->sun_path, strerror(errno)); + addr->sun_path, strerror(errno)); close(sock); rc = -1; @@ -391,23 +380,20 @@ asroot_snmp_socket() struct dispatch_actions { enum priv_cmd msg; - void(*function)(void); + void (*function)(void); }; -static struct dispatch_actions actions[] = { - {PRIV_PING, asroot_ping}, - {PRIV_DELETE_CTL_SOCKET, asroot_ctl_cleanup}, - {PRIV_GET_HOSTNAME, asroot_gethostname}, +static struct dispatch_actions actions[] = { { PRIV_PING, asroot_ping }, + { PRIV_DELETE_CTL_SOCKET, asroot_ctl_cleanup }, + { PRIV_GET_HOSTNAME, asroot_gethostname }, #ifdef HOST_OS_LINUX - {PRIV_OPEN, asroot_open}, + { PRIV_OPEN, asroot_open }, #endif - {PRIV_IFACE_INIT, asroot_iface_init}, - {PRIV_IFACE_MULTICAST, asroot_iface_multicast}, - {PRIV_IFACE_DESCRIPTION, asroot_iface_description}, - {PRIV_IFACE_PROMISC, asroot_iface_promisc}, - {PRIV_SNMP_SOCKET, asroot_snmp_socket}, - {-1, NULL} -}; + { PRIV_IFACE_INIT, asroot_iface_init }, + { PRIV_IFACE_MULTICAST, asroot_iface_multicast }, + { PRIV_IFACE_DESCRIPTION, asroot_iface_description }, + { PRIV_IFACE_PROMISC, asroot_iface_promisc }, + { PRIV_SNMP_SOCKET, asroot_snmp_socket }, { -1, NULL } }; /* Main loop, run as root */ static void @@ -418,10 +404,10 @@ priv_loop(int privileged, int once) #ifdef ENABLE_PRIVSEP setproctitle("monitor."); -#ifdef USE_SECCOMP +# ifdef USE_SECCOMP if (priv_seccomp_init(privileged, monitored) != 0) - fatal("privsep", "cannot continue without seccomp setup"); -#endif + fatal("privsep", "cannot continue without seccomp setup"); +# endif #endif while (!may_read(PRIV_PRIVILEGED, &cmd, sizeof(enum priv_cmd))) { log_debug("privsep", "received command %d", cmd); @@ -431,8 +417,7 @@ priv_loop(int privileged, int once) break; } } - if (a->function == NULL) - fatalx("privsep", "bogus message received"); + if (a->function == NULL) fatalx("privsep", "bogus message received"); if (once) break; } } @@ -441,17 +426,18 @@ priv_loop(int privileged, int once) * the other case, it should be called when we wait an action from the * privileged side. */ void -priv_wait() { +priv_wait() +{ #ifndef ENABLE_PRIVSEP /* We have no remote process on the other side. Let's emulate it. */ priv_loop(0, 1); #endif } - #ifdef ENABLE_PRIVSEP static void -priv_exit_rc_status(int rc, int status) { +priv_exit_rc_status(int rc, int status) +{ switch (rc) { case 0: /* kill child */ @@ -496,8 +482,7 @@ static void sig_pass_to_chld(int sig) { int oerrno = errno; - if (monitored != -1) - kill(monitored, sig); + if (monitored != -1) kill(monitored, sig); errno = oerrno; } @@ -519,7 +504,8 @@ sig_chld(int sig) } /* Create a subdirectory and check if it's here. */ -static int _mkdir(const char *pathname, mode_t mode) +static int +_mkdir(const char *pathname, mode_t mode) { int save_errno; if (mkdir(pathname, mode) == 0 || errno == EEXIST) { @@ -540,9 +526,10 @@ static int _mkdir(const char *pathname, mode_t mode) } /* Create a directory recursively. */ -static int mkdir_p(const char *pathname, mode_t mode) +static int +mkdir_p(const char *pathname, mode_t mode) { - char path[PATH_MAX+1]; + char path[PATH_MAX + 1]; char *current; if (strlcpy(path, pathname, sizeof(path)) >= sizeof(path)) { @@ -554,18 +541,16 @@ static int mkdir_p(const char *pathname, mode_t mode) for (current = path + 1; *current; current++) { if (*current != '/') continue; *current = '\0'; - if (_mkdir(path, mode) != 0) - return -1; + if (_mkdir(path, mode) != 0) return -1; *current = '/'; } - if (_mkdir(path, mode) != 0) - return -1; + if (_mkdir(path, mode) != 0) return -1; return 0; } /* Initialization */ -#define LOCALTIME "/etc/localtime" +# define LOCALTIME "/etc/localtime" static void priv_setup_chroot(const char *chrootdir) { @@ -577,12 +562,10 @@ priv_setup_chroot(const char *chrootdir) /* Check if /etc/localtime exists in chroot or outside chroot */ char path[1024]; int source = -1, destination = -1; - if (snprintf(path, sizeof(path), - "%s" LOCALTIME, chrootdir) >= sizeof(path)) + if (snprintf(path, sizeof(path), "%s" LOCALTIME, chrootdir) >= sizeof(path)) return; if ((source = open(LOCALTIME, O_RDONLY)) == -1) { - if (errno == ENOENT) - return; + if (errno == ENOENT) return; log_warn("privsep", "cannot read " LOCALTIME); return; } @@ -591,8 +574,7 @@ priv_setup_chroot(const char *chrootdir) path[strlen(chrootdir) + 4] = '\0'; if (mkdir(path, 0755) == -1) { if (errno != EEXIST) { - log_warn("privsep", "unable to create %s directory", - path); + log_warn("privsep", "unable to create %s directory", path); close(source); return; } @@ -603,10 +585,9 @@ priv_setup_chroot(const char *chrootdir) char buffer[1024]; ssize_t n; mode_t old = umask(S_IWGRP | S_IWOTH); - if ((destination = open(path, - O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0666)) == -1) { - if (errno != EEXIST) - log_warn("privsep", "cannot create %s", path); + if ((destination = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0666)) == + -1) { + if (errno != EEXIST) log_warn("privsep", "cannot create %s", path); close(source); umask(old); return; @@ -645,7 +626,8 @@ static void sig_chld(int sig) { int status = 0; - while (waitpid(-1, &status, WNOHANG) > 0); + while (waitpid(-1, &status, WNOHANG) > 0) + ; } #endif @@ -657,20 +639,15 @@ priv_drop(uid_t uid, gid_t gid) gidset[0] = gid; log_debug("privsep", "dropping privileges"); #ifdef HAVE_SETRESGID - if (setresgid(gid, gid, gid) == -1) - fatal("privsep", "setresgid() failed"); + if (setresgid(gid, gid, gid) == -1) fatal("privsep", "setresgid() failed"); #else - if (setregid(gid, gid) == -1) - fatal("privsep", "setregid() failed"); + if (setregid(gid, gid) == -1) fatal("privsep", "setregid() failed"); #endif - if (setgroups(1, gidset) == -1) - fatal("privsep", "setgroups() failed"); + if (setgroups(1, gidset) == -1) fatal("privsep", "setgroups() failed"); #ifdef HAVE_SETRESUID - if (setresuid(uid, uid, uid) == -1) - fatal("privsep", "setresuid() failed"); + if (setresuid(uid, uid, uid) == -1) fatal("privsep", "setresuid() failed"); #else - if (setreuid(uid, uid) == -1) - fatal("privsep", "setreuid() failed"); + if (setreuid(uid, uid) == -1) fatal("privsep", "setreuid() failed"); #endif } @@ -683,11 +660,13 @@ priv_caps(uid_t uid, gid_t gid) "cap_dac_override,cap_net_raw,cap_net_admin,cap_setuid,cap_setgid=pe", "cap_dac_override,cap_net_raw,cap_net_admin=pe" }; - log_debug("privsep", "getting CAP_NET_RAW/ADMIN and CAP_DAC_OVERRIDE privilege"); + log_debug("privsep", + "getting CAP_NET_RAW/ADMIN and CAP_DAC_OVERRIDE privilege"); if (!(caps = cap_from_text(caps_strings[0]))) fatal("privsep", "unable to convert caps"); if (cap_set_proc(caps) == -1) { - log_warn("privsep", "unable to drop privileges, monitor running as root"); + log_warn("privsep", + "unable to drop privileges, monitor running as root"); cap_free(caps); return; } @@ -729,8 +708,7 @@ priv_init(void) #ifdef ENABLE_PRIVSEP /* Spawn off monitor */ - if ((monitored = fork()) < 0) - fatal("privsep", "unable to fork monitor"); + if ((monitored = fork()) < 0) fatal("privsep", "unable to fork monitor"); switch (monitored) { case 0: /* We are in the children, drop privileges */ @@ -740,8 +718,7 @@ priv_init(void) priv_setup_chroot(chrootdir); if (chroot(chrootdir) == -1) fatal("privsep", "unable to chroot"); - if (chdir("/") != 0) - fatal("privsep", "unable to chdir"); + if (chdir("/") != 0) fatal("privsep", "unable to chdir"); priv_drop(uid, gid); } close(pair[1]); @@ -757,31 +734,25 @@ priv_init(void) priv_caps(uid, gid); /* Install signal handlers */ - const struct sigaction pass_to_child = { - .sa_handler = sig_pass_to_chld, - .sa_flags = SA_RESTART - }; + const struct sigaction pass_to_child = { .sa_handler = sig_pass_to_chld, + .sa_flags = SA_RESTART }; sigaction(SIGALRM, &pass_to_child, NULL); sigaction(SIGTERM, &pass_to_child, NULL); - sigaction(SIGHUP, &pass_to_child, NULL); - sigaction(SIGINT, &pass_to_child, NULL); + sigaction(SIGHUP, &pass_to_child, NULL); + sigaction(SIGINT, &pass_to_child, NULL); sigaction(SIGQUIT, &pass_to_child, NULL); - const struct sigaction child = { - .sa_handler = sig_chld, - .sa_flags = SA_RESTART - }; + const struct sigaction child = { .sa_handler = sig_chld, + .sa_flags = SA_RESTART }; sigaction(SIGCHLD, &child, NULL); - sig_chld(0); /* Reap already dead children */ + sig_chld(0); /* Reap already dead children */ priv_loop(pair[1], 0); exit(0); } #else - const struct sigaction child = { - .sa_handler = sig_chld, - .sa_flags = SA_RESTART - }; + const struct sigaction child = { .sa_handler = sig_chld, + .sa_flags = SA_RESTART }; sigaction(SIGCHLD, &child, NULL); - sig_chld(0); /* Reap already dead children */ + sig_chld(0); /* Reap already dead children */ log_warnx("priv", "no privilege separation available"); priv_ping(); #endif diff --git a/src/daemon/privsep.c b/src/daemon/privsep.c index 068cb5c3..04c49a94 100644 --- a/src/daemon/privsep.c +++ b/src/daemon/privsep.c @@ -17,8 +17,10 @@ int priv_fd(enum priv_context ctx) { switch (ctx) { - case PRIV_PRIVILEGED: return privileged; - case PRIV_UNPRIVILEGED: return unprivileged; + case PRIV_PRIVILEGED: + return privileged; + case PRIV_UNPRIVILEGED: + return unprivileged; } - return -1; /* Not possible */ + return -1; /* Not possible */ } diff --git a/src/daemon/privsep_fd.c b/src/daemon/privsep_fd.c index ab2d9a6c..fa986634 100644 --- a/src/daemon/privsep_fd.c +++ b/src/daemon/privsep_fd.c @@ -83,8 +83,7 @@ send_fd(enum priv_context ctx, int fd) if ((n = sendmsg(priv_fd(ctx), &msg, 0)) == -1) log_warn("privsep", "sendmsg(%d)", priv_fd(ctx)); if (n != sizeof(int)) - log_warnx("privsep", "sendmsg: expected sent 1 got %ld", - (long)n); + log_warnx("privsep", "sendmsg: expected sent 1 got %ld", (long)n); } int @@ -109,11 +108,9 @@ receive_fd(enum priv_context ctx) msg.msg_control = &cmsgbuf.buf; msg.msg_controllen = sizeof(cmsgbuf.buf); - if ((n = recvmsg(priv_fd(ctx), &msg, 0)) == -1) - log_warn("privsep", "recvmsg"); + if ((n = recvmsg(priv_fd(ctx), &msg, 0)) == -1) log_warn("privsep", "recvmsg"); if (n != sizeof(int)) - log_warnx("privsep", "recvmsg: expected received 1 got %ld", - (long)n); + log_warnx("privsep", "recvmsg: expected received 1 got %ld", (long)n); if (result == 0) { cmsg = CMSG_FIRSTHDR(&msg); if (cmsg == NULL) { @@ -121,8 +118,8 @@ receive_fd(enum priv_context ctx) return -1; } if (cmsg->cmsg_type != SCM_RIGHTS) - log_warnx("privsep", "expected type %d got %d", - SCM_RIGHTS, cmsg->cmsg_type); + log_warnx("privsep", "expected type %d got %d", SCM_RIGHTS, + cmsg->cmsg_type); memcpy(&fd, CMSG_DATA(cmsg), sizeof(int)); return fd; } else { diff --git a/src/daemon/privsep_io.c b/src/daemon/privsep_io.c index 5b46531c..9d0923ab 100644 --- a/src/daemon/privsep_io.c +++ b/src/daemon/privsep_io.c @@ -44,8 +44,7 @@ may_read(enum priv_context ctx, void *buf, size_t n) res = read(priv_fd(ctx), s + pos, n - pos); switch (res) { case -1: - if (errno == EINTR || errno == EAGAIN) - continue; + if (errno == EINTR || errno == EAGAIN) continue; return 1; case 0: return 1; @@ -68,10 +67,10 @@ must_read(enum priv_context ctx, void *buf, size_t n) res = read(priv_fd(ctx), s + pos, n - pos); switch (res) { case -1: - if (errno == EINTR || errno == EAGAIN) - continue; + if (errno == EINTR || errno == EAGAIN) continue; + _exit(0); + case 0: _exit(0); - case 0: _exit(0); default: pos += res; } @@ -90,10 +89,10 @@ must_write(enum priv_context ctx, const void *buf, size_t n) res = write(priv_fd(ctx), s + pos, n - pos); switch (res) { case -1: - if (errno == EINTR || errno == EAGAIN) - continue; + if (errno == EINTR || errno == EAGAIN) continue; + _exit(0); + case 0: _exit(0); - case 0: _exit(0); default: pos += res; } diff --git a/src/daemon/protocols/cdp.c b/src/daemon/protocols/cdp.c index 06da59ec..8a1be863 100644 --- a/src/daemon/protocols/cdp.c +++ b/src/daemon/protocols/cdp.c @@ -24,22 +24,21 @@ * account the loss in the PoE cable. This is done by the switch automatically * if lldp is used as the protocol. */ -#define CDP_CLASS_3_MAX_PSE_POE 154 /* 15.4W Max PoE at PSE class 3 */ -#define CDP_SWTICH_DEFAULT_POE_PD 130 /* 13.W default PoE at PD */ -#define CDP_SWTICH_DEFAULT_POE_PSE 154 /* 15.4W default PoE at PSE */ -#define CDP_SWITCH_POE_CLASS_4_OFFSET 45 /* 4.5W max loss from cable */ -#define CDP_SWITCH_POE_CLASS_3_OFFSET 24 /* 2.4W max loss from cable */ +#define CDP_CLASS_3_MAX_PSE_POE 154 /* 15.4W Max PoE at PSE class 3 */ +#define CDP_SWTICH_DEFAULT_POE_PD 130 /* 13.W default PoE at PD */ +#define CDP_SWTICH_DEFAULT_POE_PSE 154 /* 15.4W default PoE at PSE */ +#define CDP_SWITCH_POE_CLASS_4_OFFSET 45 /* 4.5W max loss from cable */ +#define CDP_SWITCH_POE_CLASS_3_OFFSET 24 /* 2.4W max loss from cable */ #if defined ENABLE_CDP || defined ENABLE_FDP -#include -#include -#include -#include +# include +# include +# include +# include static int -cdp_send(struct lldpd *global, - struct lldpd_hardware *hardware, int version) +cdp_send(struct lldpd *global, struct lldpd_hardware *hardware, int version) { const char *platform = "Unknown"; struct lldpd_chassis *chassis; @@ -47,9 +46,9 @@ cdp_send(struct lldpd *global, struct lldpd_port *port; u_int8_t mcastaddr[] = CDP_MULTICAST_ADDR; u_int8_t llcorg[] = LLC_ORG_CISCO; -#ifdef ENABLE_FDP +# ifdef ENABLE_FDP char *capstr; -#endif +# endif u_int16_t checksum; int length, i; u_int32_t cap; @@ -61,7 +60,7 @@ cdp_send(struct lldpd *global, port = &(hardware->h_lport); chassis = port->p_chassis; -#ifdef ENABLE_FDP +# ifdef ENABLE_FDP if (version == 0) { /* With FDP, change multicast address and LLC PID */ const u_int8_t fdpmcastaddr[] = FDP_MULTICAST_ADDR; @@ -69,46 +68,37 @@ cdp_send(struct lldpd *global, memcpy(mcastaddr, fdpmcastaddr, sizeof(mcastaddr)); memcpy(llcorg, fdpllcorg, sizeof(llcorg)); } -#endif +# endif length = hardware->h_mtu; - if ((packet = (u_int8_t*)calloc(1, length)) == NULL) - return ENOMEM; + if ((packet = (u_int8_t *)calloc(1, length)) == NULL) return ENOMEM; pos = packet; /* Ethernet header */ - if (!( - POKE_BYTES(mcastaddr, sizeof(mcastaddr)) && - POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) && - POKE_SAVE(pos_len_eh) && /* We compute the len later */ - POKE_UINT16(0))) + if (!(POKE_BYTES(mcastaddr, sizeof(mcastaddr)) && + POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) && + POKE_SAVE(pos_len_eh) && /* We compute the len later */ + POKE_UINT16(0))) goto toobig; /* LLC */ - if (!( - POKE_SAVE(pos_llc) && - POKE_UINT8(0xaa) && /* SSAP */ - POKE_UINT8(0xaa) && /* DSAP */ - POKE_UINT8(0x03) && /* Control field */ - POKE_BYTES(llcorg, sizeof(llcorg)) && - POKE_UINT16(LLC_PID_CDP))) + if (!(POKE_SAVE(pos_llc) && POKE_UINT8(0xaa) && /* SSAP */ + POKE_UINT8(0xaa) && /* DSAP */ + POKE_UINT8(0x03) && /* Control field */ + POKE_BYTES(llcorg, sizeof(llcorg)) && POKE_UINT16(LLC_PID_CDP))) goto toobig; /* CDP header */ - if (!( - POKE_SAVE(pos_cdp) && - POKE_UINT8((version == 0)?1:version) && - POKE_UINT8(global?global->g_config.c_ttl:180) && - POKE_SAVE(pos_checksum) && /* Save checksum position */ - POKE_UINT16(0))) + if (!(POKE_SAVE(pos_cdp) && POKE_UINT8((version == 0) ? 1 : version) && + POKE_UINT8(global ? global->g_config.c_ttl : 180) && + POKE_SAVE(pos_checksum) && /* Save checksum position */ + POKE_UINT16(0))) goto toobig; /* Chassis ID */ - const char *chassis_name = chassis->c_name?chassis->c_name:""; - if (!( - POKE_START_CDP_TLV(CDP_TLV_CHASSIS) && - POKE_BYTES(chassis_name, strlen(chassis_name)) && - POKE_END_CDP_TLV)) + const char *chassis_name = chassis->c_name ? chassis->c_name : ""; + if (!(POKE_START_CDP_TLV(CDP_TLV_CHASSIS) && + POKE_BYTES(chassis_name, strlen(chassis_name)) && POKE_END_CDP_TLV)) goto toobig; /* Adresses */ @@ -120,52 +110,45 @@ cdp_send(struct lldpd *global, * 0x0800 is the Ethernet protocol type for IPv4. Therefore, * we support only IPv4. */ i = 0; - TAILQ_FOREACH(mgmt, &chassis->c_mgmt, m_entries) + TAILQ_FOREACH (mgmt, &chassis->c_mgmt, m_entries) if (mgmt->m_family == LLDPD_AF_IPV4) i++; if (i > 0) { - if (!( - POKE_START_CDP_TLV(CDP_TLV_ADDRESSES) && - POKE_UINT32(i))) + if (!(POKE_START_CDP_TLV(CDP_TLV_ADDRESSES) && POKE_UINT32(i))) goto toobig; - TAILQ_FOREACH(mgmt, &chassis->c_mgmt, m_entries) { + TAILQ_FOREACH (mgmt, &chassis->c_mgmt, m_entries) { switch (mgmt->m_family) { case LLDPD_AF_IPV4: - if (!( - POKE_UINT8(1) && /* Type: NLPID */ - POKE_UINT8(1) && /* Length: 1 */ - POKE_UINT8(CDP_ADDRESS_PROTO_IP) && /* IP */ - POKE_UINT16(sizeof(struct in_addr)) && /* Address length */ - POKE_BYTES(&mgmt->m_addr, sizeof(struct in_addr)))) + if (!(POKE_UINT8(1) && /* Type: NLPID */ + POKE_UINT8(1) && /* Length: 1 */ + POKE_UINT8(CDP_ADDRESS_PROTO_IP) && /* IP */ + POKE_UINT16(sizeof( + struct in_addr)) && /* Address length */ + POKE_BYTES(&mgmt->m_addr, + sizeof(struct in_addr)))) goto toobig; break; } } - if (!(POKE_END_CDP_TLV)) - goto toobig; + if (!(POKE_END_CDP_TLV)) goto toobig; } /* Port ID */ - const char *port_descr = hardware->h_lport.p_descr?hardware->h_lport.p_descr:""; - if (!( - POKE_START_CDP_TLV(CDP_TLV_PORT) && - POKE_BYTES(port_descr, strlen(port_descr)) && - POKE_END_CDP_TLV)) + const char *port_descr = + hardware->h_lport.p_descr ? hardware->h_lport.p_descr : ""; + if (!(POKE_START_CDP_TLV(CDP_TLV_PORT) && + POKE_BYTES(port_descr, strlen(port_descr)) && POKE_END_CDP_TLV)) goto toobig; /* Capabilities */ if (version != 0) { cap = 0; - if (chassis->c_cap_enabled & LLDP_CAP_ROUTER) - cap |= CDP_CAP_ROUTER; - if (chassis->c_cap_enabled & LLDP_CAP_BRIDGE) - cap |= CDP_CAP_SWITCH; + if (chassis->c_cap_enabled & LLDP_CAP_ROUTER) cap |= CDP_CAP_ROUTER; + if (chassis->c_cap_enabled & LLDP_CAP_BRIDGE) cap |= CDP_CAP_SWITCH; cap |= CDP_CAP_HOST; - if (!( - POKE_START_CDP_TLV(CDP_TLV_CAPABILITIES) && - POKE_UINT32(cap) && - POKE_END_CDP_TLV)) + if (!(POKE_START_CDP_TLV(CDP_TLV_CAPABILITIES) && POKE_UINT32(cap) && + POKE_END_CDP_TLV)) goto toobig; -#ifdef ENABLE_FDP +# ifdef ENABLE_FDP } else { /* With FDP, it seems that a string is used in place of an int */ if (chassis->c_cap_enabled & LLDP_CAP_ROUTER) @@ -176,70 +159,63 @@ cdp_send(struct lldpd *global, capstr = "Bridge"; else capstr = "Host"; - if (!( - POKE_START_CDP_TLV(CDP_TLV_CAPABILITIES) && - POKE_BYTES(capstr, strlen(capstr)) && - POKE_END_CDP_TLV)) + if (!(POKE_START_CDP_TLV(CDP_TLV_CAPABILITIES) && + POKE_BYTES(capstr, strlen(capstr)) && POKE_END_CDP_TLV)) goto toobig; -#endif +# endif } /* Native VLAN */ -#ifdef ENABLE_DOT1 - if (version >=2 && hardware->h_lport.p_pvid != 0) { - if (!( - POKE_START_CDP_TLV(CDP_TLV_NATIVEVLAN) && - POKE_UINT16(hardware->h_lport.p_pvid) && - POKE_END_CDP_TLV)) +# ifdef ENABLE_DOT1 + if (version >= 2 && hardware->h_lport.p_pvid != 0) { + if (!(POKE_START_CDP_TLV(CDP_TLV_NATIVEVLAN) && + POKE_UINT16(hardware->h_lport.p_pvid) && POKE_END_CDP_TLV)) goto toobig; } -#endif +# endif /* Software version */ - const char * chassis_descr = chassis->c_descr?chassis->c_descr:""; - if (!( - POKE_START_CDP_TLV(CDP_TLV_SOFTWARE) && - POKE_BYTES(chassis_descr, strlen(chassis_descr)) && - POKE_END_CDP_TLV)) + const char *chassis_descr = chassis->c_descr ? chassis->c_descr : ""; + if (!(POKE_START_CDP_TLV(CDP_TLV_SOFTWARE) && + POKE_BYTES(chassis_descr, strlen(chassis_descr)) && POKE_END_CDP_TLV)) goto toobig; /* Platform */ - if (global && global->g_config.c_platform) platform = global->g_config.c_platform; + if (global && global->g_config.c_platform) + platform = global->g_config.c_platform; - if (!( - POKE_START_CDP_TLV(CDP_TLV_PLATFORM) && - POKE_BYTES(platform, strlen(platform)) && - POKE_END_CDP_TLV)) + if (!(POKE_START_CDP_TLV(CDP_TLV_PLATFORM) && + POKE_BYTES(platform, strlen(platform)) && POKE_END_CDP_TLV)) goto toobig; -#ifdef ENABLE_DOT3 - if ((version >= 2) && - (port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) && +# ifdef ENABLE_DOT3 + if ((version >= 2) && (port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) && (port->p_power.devicetype == LLDP_DOT3_POWER_PD) && - (port->p_power.requested > 0) && - (port->p_power.requested <= 655)) { + (port->p_power.requested > 0) && (port->p_power.requested <= 655)) { u_int16_t requested; u_int16_t consumption; if (port->p_power.requested != port->p_power.allocated) { port->p_cdp_power.request_id++; - log_debug("cdp", "requested: %d, allocated:%d", port->p_power.requested, port->p_power.allocated); + log_debug("cdp", "requested: %d, allocated:%d", + port->p_power.requested, port->p_power.allocated); } - consumption = port->p_power.allocated ? port->p_power.allocated : CDP_SWTICH_DEFAULT_POE_PD; + consumption = port->p_power.allocated ? port->p_power.allocated : + CDP_SWTICH_DEFAULT_POE_PD; if (consumption > 130) { consumption += CDP_SWITCH_POE_CLASS_4_OFFSET; } else { consumption += CDP_SWITCH_POE_CLASS_3_OFFSET; } if (port->p_power.requested > 130) { /* Class 4 */ - requested = port->p_power.requested + CDP_SWITCH_POE_CLASS_4_OFFSET; + requested = + port->p_power.requested + CDP_SWITCH_POE_CLASS_4_OFFSET; } else { /* Class 3 */ - requested = port->p_power.requested + CDP_SWITCH_POE_CLASS_3_OFFSET; + requested = + port->p_power.requested + CDP_SWITCH_POE_CLASS_3_OFFSET; } - if (!( - POKE_START_CDP_TLV(CDP_TLV_POWER_CONSUMPTION) && - POKE_UINT16(consumption * 100) && - POKE_END_CDP_TLV)) + if (!(POKE_START_CDP_TLV(CDP_TLV_POWER_CONSUMPTION) && + POKE_UINT16(consumption * 100) && POKE_END_CDP_TLV)) goto toobig; /* Avoid request id 0 from overflow */ if (!port->p_cdp_power.request_id) { @@ -248,28 +224,22 @@ cdp_send(struct lldpd *global, if (!port->p_cdp_power.management_id) { port->p_cdp_power.management_id = 1; } - if (!( - POKE_START_CDP_TLV(CDP_TLV_POWER_REQUESTED) && - POKE_UINT16(port->p_cdp_power.request_id) && - POKE_UINT16(port->p_cdp_power.management_id) && - POKE_UINT32(requested * 100) && - POKE_END_CDP_TLV)) + if (!(POKE_START_CDP_TLV(CDP_TLV_POWER_REQUESTED) && + POKE_UINT16(port->p_cdp_power.request_id) && + POKE_UINT16(port->p_cdp_power.management_id) && + POKE_UINT32(requested * 100) && POKE_END_CDP_TLV)) goto toobig; } -#elif defined ENABLE_LLDPMED +# elif defined ENABLE_LLDPMED /* Power use */ - if ((version >= 2) && - port->p_med_cap_enabled && + if ((version >= 2) && port->p_med_cap_enabled && (port->p_med_power.source != LLDP_MED_POW_SOURCE_LOCAL) && - (port->p_med_power.val > 0) && - (port->p_med_power.val <= 655)) { - if (!( - POKE_START_CDP_TLV(CDP_TLV_POWER_CONSUMPTION) && - POKE_UINT16(port->p_med_power.val * 100) && - POKE_END_CDP_TLV)) + (port->p_med_power.val > 0) && (port->p_med_power.val <= 655)) { + if (!(POKE_START_CDP_TLV(CDP_TLV_POWER_CONSUMPTION) && + POKE_UINT16(port->p_med_power.val * 100) && POKE_END_CDP_TLV)) goto toobig; } -#endif +# endif (void)POKE_SAVE(end); @@ -280,10 +250,10 @@ cdp_send(struct lldpd *global, POKE_RESTORE(pos_checksum); if (!(POKE_UINT16(checksum))) goto toobig; - if (interfaces_send_helper(global, hardware, - (char *)packet, end - packet) == -1) { + if (interfaces_send_helper(global, hardware, (char *)packet, end - packet) == + -1) { log_warn("cdp", "unable to send packet on real device for %s", - hardware->h_ifname); + hardware->h_ifname); free(packet); return ENETDOWN; } @@ -292,45 +262,45 @@ cdp_send(struct lldpd *global, free(packet); return 0; - toobig: +toobig: free(packet); return -1; } -#define CHECK_TLV_SIZE(x, name) \ - do { if (tlv_len < (x)) { \ - log_warnx("cdp", name " CDP/FDP TLV too short received on %s", \ - hardware->h_ifname); \ - goto malformed; \ - } } while (0) +# define CHECK_TLV_SIZE(x, name) \ + do { \ + if (tlv_len < (x)) { \ + log_warnx("cdp", name " CDP/FDP TLV too short received on %s", \ + hardware->h_ifname); \ + goto malformed; \ + } \ + } while (0) /* cdp_decode also decodes FDP */ int -cdp_decode(struct lldpd *cfg, char *frame, int s, - struct lldpd_hardware *hardware, +cdp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardware, struct lldpd_chassis **newchassis, struct lldpd_port **newport) { struct lldpd_chassis *chassis; struct lldpd_port *port; struct lldpd_mgmt *mgmt; struct in_addr addr; -#if 0 +# if 0 u_int16_t cksum; -#endif +# endif u_int8_t *software = NULL, *platform = NULL; int software_len = 0, platform_len = 0, proto, version, nb, caps; const unsigned char cdpaddr[] = CDP_MULTICAST_ADDR; -#ifdef ENABLE_FDP +# ifdef ENABLE_FDP const unsigned char fdpaddr[] = CDP_MULTICAST_ADDR; int fdp = 0; -#endif +# endif u_int8_t *pos, *tlv, *pos_address, *pos_next_address; int length, len_eth, tlv_type, tlv_len, addresses_len, address_len; -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 struct lldpd_vlan *vlan; -#endif +# endif - log_debug("cdp", "decode CDP frame received on %s", - hardware->h_ifname); + log_debug("cdp", "decode CDP frame received on %s", hardware->h_ifname); if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) { log_warn("cdp", "failed to allocate remote chassis"); @@ -342,34 +312,36 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, free(chassis); return -1; } -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 TAILQ_INIT(&port->p_vlans); -#endif +# endif length = s; - pos = (u_int8_t*)frame; + pos = (u_int8_t *)frame; - if (length < 2*ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ + - 8 /* LLC */ + 4 /* CDP header */) { - log_warn("cdp", "too short CDP/FDP frame received on %s", hardware->h_ifname); + if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ + + 8 /* LLC */ + 4 /* CDP header */) { + log_warn("cdp", "too short CDP/FDP frame received on %s", + hardware->h_ifname); goto malformed; } if (PEEK_CMP(cdpaddr, sizeof(cdpaddr)) != 0) { -#ifdef ENABLE_FDP - PEEK_RESTORE((u_int8_t*)frame); +# ifdef ENABLE_FDP + PEEK_RESTORE((u_int8_t *)frame); if (PEEK_CMP(fdpaddr, sizeof(fdpaddr)) != 0) fdp = 1; else { -#endif - log_info("cdp", "frame not targeted at CDP/FDP multicast address received on %s", +# endif + log_info("cdp", + "frame not targeted at CDP/FDP multicast address received on %s", hardware->h_ifname); goto malformed; -#ifdef ENABLE_FDP +# ifdef ENABLE_FDP } -#endif +# endif } - PEEK_DISCARD(ETHER_ADDR_LEN); /* Don't care of source address */ + PEEK_DISCARD(ETHER_ADDR_LEN); /* Don't care of source address */ len_eth = PEEK_UINT16; if (len_eth > length) { log_warnx("cdp", "incorrect 802.3 frame size reported on %s", @@ -380,50 +352,49 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, /* This is the correct length of the CDP + LLC packets */ length = len_eth; - PEEK_DISCARD(6); /* Skip beginning of LLC */ + PEEK_DISCARD(6); /* Skip beginning of LLC */ proto = PEEK_UINT16; if (proto != LLC_PID_CDP) { - if ((proto != LLC_PID_DRIP) && - (proto != LLC_PID_PAGP) && - (proto != LLC_PID_PVSTP) && - (proto != LLC_PID_UDLD) && - (proto != LLC_PID_VTP) && - (proto != LLC_PID_DTP) && + if ((proto != LLC_PID_DRIP) && (proto != LLC_PID_PAGP) && + (proto != LLC_PID_PVSTP) && (proto != LLC_PID_UDLD) && + (proto != LLC_PID_VTP) && (proto != LLC_PID_DTP) && (proto != LLC_PID_STP)) log_debug("cdp", "incorrect LLC protocol ID received on %s", hardware->h_ifname); goto malformed; } -#if 0 +# if 0 /* Check checksum */ cksum = frame_checksum(pos, len_eth - 8, -#ifdef ENABLE_FDP +# ifdef ENABLE_FDP !fdp /* fdp = 0 -> cisco checksum */ -#else +# else 1 /* cisco checksum */ -#endif +# endif ); if (cksum != 0) { log_info("cdp", "incorrect CDP/FDP checksum for frame received on %s (%d)", hardware->h_ifname, cksum); goto malformed; } -#endif +# endif /* Check version */ version = PEEK_UINT8; if ((version != 1) && (version != 2)) { - log_warnx("cdp", "incorrect CDP/FDP version (%d) for frame received on %s", - version, hardware->h_ifname); + log_warnx("cdp", + "incorrect CDP/FDP version (%d) for frame received on %s", version, + hardware->h_ifname); goto malformed; } port->p_ttl = PEEK_UINT8; /* TTL */ - PEEK_DISCARD_UINT16; /* Checksum, already checked */ + PEEK_DISCARD_UINT16; /* Checksum, already checked */ while (length) { if (length < 4) { - log_warnx("cdp", "CDP/FDP TLV header is too large for " + log_warnx("cdp", + "CDP/FDP TLV header is too large for " "frame received on %s", hardware->h_ifname); goto malformed; @@ -433,7 +404,8 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, (void)PEEK_SAVE(tlv); if ((tlv_len < 0) || (length < tlv_len)) { - log_warnx("cdp", "incorrect size in CDP/FDP TLV header for frame " + log_warnx("cdp", + "incorrect size in CDP/FDP TLV header for frame " "received on %s", hardware->h_ifname); goto malformed; @@ -441,15 +413,18 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, switch (tlv_type) { case CDP_TLV_CHASSIS: free(chassis->c_name); - if ((chassis->c_name = (char *)calloc(1, tlv_len + 1)) == NULL) { - log_warn("cdp", "unable to allocate memory for chassis name"); + if ((chassis->c_name = (char *)calloc(1, tlv_len + 1)) == + NULL) { + log_warn("cdp", + "unable to allocate memory for chassis name"); goto malformed; } PEEK_BYTES(chassis->c_name, tlv_len); chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL; free(chassis->c_id); if ((chassis->c_id = (char *)malloc(tlv_len)) == NULL) { - log_warn("cdp", "unable to allocate memory for chassis ID"); + log_warn("cdp", + "unable to allocate memory for chassis ID"); goto malformed; } memcpy(chassis->c_id, chassis->c_name, tlv_len); @@ -462,26 +437,32 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, (void)PEEK_SAVE(pos_address); /* We first try to get the real length of the packet */ if (addresses_len < 2) { - log_warn("cdp", "too short address subframe " - "received on %s", - hardware->h_ifname); + log_warn("cdp", + "too short address subframe " + "received on %s", + hardware->h_ifname); goto malformed; } - PEEK_DISCARD_UINT8; addresses_len--; - address_len = PEEK_UINT8; addresses_len--; + PEEK_DISCARD_UINT8; + addresses_len--; + address_len = PEEK_UINT8; + addresses_len--; if (addresses_len < address_len + 2) { - log_warn("cdp", "too short address subframe " - "received on %s", - hardware->h_ifname); + log_warn("cdp", + "too short address subframe " + "received on %s", + hardware->h_ifname); goto malformed; } PEEK_DISCARD(address_len); addresses_len -= address_len; - address_len = PEEK_UINT16; addresses_len -= 2; + address_len = PEEK_UINT16; + addresses_len -= 2; if (addresses_len < address_len) { - log_warn("cdp", "too short address subframe " - "received on %s", - hardware->h_ifname); + log_warn("cdp", + "too short address subframe " + "received on %s", + hardware->h_ifname); goto malformed; } PEEK_DISCARD(address_len); @@ -492,20 +473,21 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, if ((PEEK_UINT8 == 1) && (PEEK_UINT8 == 1) && (PEEK_UINT8 == CDP_ADDRESS_PROTO_IP) && (PEEK_UINT16 == sizeof(struct in_addr))) { - PEEK_BYTES(&addr, sizeof(struct in_addr)); - mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr, - sizeof(struct in_addr), 0); - if (mgmt == NULL) { - if (errno == ENOMEM) - log_warn("cdp", - "unable to allocate memory for management address"); - else - log_warn("cdp", - "too large management address received on %s", - hardware->h_ifname); - goto malformed; - } - TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries); + PEEK_BYTES(&addr, sizeof(struct in_addr)); + mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr, + sizeof(struct in_addr), 0); + if (mgmt == NULL) { + if (errno == ENOMEM) + log_warn("cdp", + "unable to allocate memory for management address"); + else + log_warn("cdp", + "too large management address received on %s", + hardware->h_ifname); + goto malformed; + } + TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, + m_entries); } /* Go to the end of the address */ PEEK_RESTORE(pos_next_address); @@ -518,41 +500,42 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, } free(port->p_descr); if ((port->p_descr = (char *)calloc(1, tlv_len + 1)) == NULL) { - log_warn("cdp", "unable to allocate memory for port description"); + log_warn("cdp", + "unable to allocate memory for port description"); goto malformed; } PEEK_BYTES(port->p_descr, tlv_len); port->p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME; free(port->p_id); - if ((port->p_id = (char *)calloc(1, tlv_len)) == NULL) { - log_warn("cdp", "unable to allocate memory for port ID"); + if ((port->p_id = (char *)calloc(1, tlv_len)) == NULL) { + log_warn("cdp", + "unable to allocate memory for port ID"); goto malformed; } memcpy(port->p_id, port->p_descr, tlv_len); port->p_id_len = tlv_len; break; case CDP_TLV_CAPABILITIES: -#ifdef ENABLE_FDP +# ifdef ENABLE_FDP if (fdp) { /* Capabilities are string with FDP */ - if (!strncmp("Router", (char*)pos, tlv_len)) + if (!strncmp("Router", (char *)pos, tlv_len)) chassis->c_cap_enabled = LLDP_CAP_ROUTER; - else if (!strncmp("Switch", (char*)pos, tlv_len)) + else if (!strncmp("Switch", (char *)pos, tlv_len)) chassis->c_cap_enabled = LLDP_CAP_BRIDGE; - else if (!strncmp("Bridge", (char*)pos, tlv_len)) + else if (!strncmp("Bridge", (char *)pos, tlv_len)) chassis->c_cap_enabled = LLDP_CAP_REPEATER; else chassis->c_cap_enabled = LLDP_CAP_STATION; chassis->c_cap_available = chassis->c_cap_enabled; break; } -#endif +# endif CHECK_TLV_SIZE(4, "Capabilities"); caps = PEEK_UINT32; if (caps & CDP_CAP_ROUTER) chassis->c_cap_enabled |= LLDP_CAP_ROUTER; - if (caps & 0x0e) - chassis->c_cap_enabled |= LLDP_CAP_BRIDGE; + if (caps & 0x0e) chassis->c_cap_enabled |= LLDP_CAP_BRIDGE; if (chassis->c_cap_enabled == 0) chassis->c_cap_enabled = LLDP_CAP_STATION; chassis->c_cap_available = chassis->c_cap_enabled; @@ -565,30 +548,31 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, platform_len = tlv_len; (void)PEEK_SAVE(platform); break; -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 case CDP_TLV_NATIVEVLAN: CHECK_TLV_SIZE(2, "Native VLAN"); if ((vlan = (struct lldpd_vlan *)calloc(1, - sizeof(struct lldpd_vlan))) == NULL) { - log_warn("cdp", "unable to alloc vlan " - "structure for " - "tlv received on %s", - hardware->h_ifname); + sizeof(struct lldpd_vlan))) == NULL) { + log_warn("cdp", + "unable to alloc vlan " + "structure for " + "tlv received on %s", + hardware->h_ifname); goto malformed; } vlan->v_vid = port->p_pvid = PEEK_UINT16; if (asprintf(&vlan->v_name, "VLAN #%d", vlan->v_vid) == -1) { - log_warn("cdp", "unable to alloc VLAN name for " - "TLV received on %s", - hardware->h_ifname); + log_warn("cdp", + "unable to alloc VLAN name for " + "TLV received on %s", + hardware->h_ifname); free(vlan); goto malformed; } - TAILQ_INSERT_TAIL(&port->p_vlans, - vlan, v_entries); + TAILQ_INSERT_TAIL(&port->p_vlans, vlan, v_entries); break; -#endif -#ifdef ENABLE_DOT3 +# endif +# ifdef ENABLE_DOT3 case CDP_TLV_POWER_AVAILABLE: CHECK_TLV_SIZE(12, "Power Available"); /* check if it is a respone to a request id */ @@ -600,18 +584,23 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, port->p_power.enabled = 1; port->p_power.devicetype = LLDP_DOT3_POWER_PSE; port->p_power.powertype = LLDP_DOT3_POWER_8023AT_TYPE2; - log_debug("cdp", "Allocated power %d00", port->p_power.allocated); + log_debug("cdp", "Allocated power %d00", + port->p_power.allocated); if (port->p_power.allocated > CDP_CLASS_3_MAX_PSE_POE) { - port->p_power.allocated -= CDP_SWITCH_POE_CLASS_4_OFFSET; - } else if (port->p_power.allocated > CDP_SWITCH_POE_CLASS_3_OFFSET ) { - port->p_power.allocated -= CDP_SWITCH_POE_CLASS_3_OFFSET; + port->p_power.allocated -= + CDP_SWITCH_POE_CLASS_4_OFFSET; + } else if (port->p_power.allocated > + CDP_SWITCH_POE_CLASS_3_OFFSET) { + port->p_power.allocated -= + CDP_SWITCH_POE_CLASS_3_OFFSET; } else { port->p_power.allocated = 0; } - port->p_power.requested = hardware->h_lport.p_power.requested; + port->p_power.requested = + hardware->h_lport.p_power.requested; } break; -#endif +# endif default: log_debug("cdp", "unknown CDP/FDP TLV type (%d) received on %s", ntohs(tlv_type), hardware->h_ifname); @@ -620,41 +609,40 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, PEEK_DISCARD(tlv + tlv_len - pos); } if (!software && platform) { - if ((chassis->c_descr = (char *)calloc(1, - platform_len + 1)) == NULL) { - log_warn("cdp", "unable to allocate memory for chassis description"); + if ((chassis->c_descr = (char *)calloc(1, platform_len + 1)) == NULL) { + log_warn("cdp", + "unable to allocate memory for chassis description"); goto malformed; } memcpy(chassis->c_descr, platform, platform_len); } else if (software && !platform) { - if ((chassis->c_descr = (char *)calloc(1, - software_len + 1)) == NULL) { - log_warn("cdp", "unable to allocate memory for chassis description"); + if ((chassis->c_descr = (char *)calloc(1, software_len + 1)) == NULL) { + log_warn("cdp", + "unable to allocate memory for chassis description"); goto malformed; } memcpy(chassis->c_descr, software, software_len); } else if (software && platform) { -#define CONCAT_PLATFORM " running on\n" +# define CONCAT_PLATFORM " running on\n" if ((chassis->c_descr = (char *)calloc(1, - software_len + platform_len + - strlen(CONCAT_PLATFORM) + 1)) == NULL) { - log_warn("cdp", "unable to allocate memory for chassis description"); + software_len + platform_len + strlen(CONCAT_PLATFORM) + 1)) == + NULL) { + log_warn("cdp", + "unable to allocate memory for chassis description"); goto malformed; } memcpy(chassis->c_descr, platform, platform_len); - memcpy(chassis->c_descr + platform_len, - CONCAT_PLATFORM, strlen(CONCAT_PLATFORM)); + memcpy(chassis->c_descr + platform_len, CONCAT_PLATFORM, + strlen(CONCAT_PLATFORM)); memcpy(chassis->c_descr + platform_len + strlen(CONCAT_PLATFORM), software, software_len); } - if ((chassis->c_id == NULL) || - (port->p_id == NULL) || - (chassis->c_name == NULL) || - (chassis->c_descr == NULL) || - (port->p_descr == NULL) || - (port->p_ttl == 0) || + if ((chassis->c_id == NULL) || (port->p_id == NULL) || + (chassis->c_name == NULL) || (chassis->c_descr == NULL) || + (port->p_descr == NULL) || (port->p_ttl == 0) || (chassis->c_cap_enabled == 0)) { - log_warnx("cdp", "some mandatory CDP/FDP tlv are missing for frame received on %s", + log_warnx("cdp", + "some mandatory CDP/FDP tlv are missing for frame received on %s", hardware->h_ifname); goto malformed; } @@ -669,43 +657,40 @@ malformed: return -1; } -#ifdef ENABLE_CDP +# ifdef ENABLE_CDP int -cdpv1_send(struct lldpd *global, - struct lldpd_hardware *hardware) +cdpv1_send(struct lldpd *global, struct lldpd_hardware *hardware) { return cdp_send(global, hardware, 1); } int -cdpv2_send(struct lldpd *global, - struct lldpd_hardware *hardware) +cdpv2_send(struct lldpd *global, struct lldpd_hardware *hardware) { return cdp_send(global, hardware, 2); } -#endif +# endif -#ifdef ENABLE_FDP +# ifdef ENABLE_FDP int -fdp_send(struct lldpd *global, - struct lldpd_hardware *hardware) +fdp_send(struct lldpd *global, struct lldpd_hardware *hardware) { return cdp_send(global, hardware, 0); } -#endif +# endif -#ifdef ENABLE_CDP +# ifdef ENABLE_CDP static int cdp_guess(char *pos, int length, int version) { const u_int8_t mcastaddr[] = CDP_MULTICAST_ADDR; - if (length < 2*ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ + - 8 /* LLC */ + 4 /* CDP header */) - return 0; - if (PEEK_CMP(mcastaddr, ETHER_ADDR_LEN) != 0) + if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ + + 8 /* LLC */ + 4 /* CDP header */) return 0; - PEEK_DISCARD(ETHER_ADDR_LEN); PEEK_DISCARD_UINT16; /* Ethernet */ - PEEK_DISCARD(8); /* LLC */ + if (PEEK_CMP(mcastaddr, ETHER_ADDR_LEN) != 0) return 0; + PEEK_DISCARD(ETHER_ADDR_LEN); + PEEK_DISCARD_UINT16; /* Ethernet */ + PEEK_DISCARD(8); /* LLC */ return (PEEK_UINT8 == version); } @@ -720,6 +705,6 @@ cdpv2_guess(char *frame, int len) { return cdp_guess(frame, len, 2); } -#endif +# endif #endif /* defined (ENABLE_CDP) || defined (ENABLE_FDP) */ diff --git a/src/daemon/protocols/cdp.h b/src/daemon/protocols/cdp.h index 73f127cd..f83ffef6 100644 --- a/src/daemon/protocols/cdp.h +++ b/src/daemon/protocols/cdp.h @@ -18,14 +18,22 @@ #ifndef _CDP_H #define _CDP_H -#define CDP_MULTICAST_ADDR { \ - 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc \ -} -#define FDP_MULTICAST_ADDR { \ - 0x01, 0xe0, 0x52, 0xcc, 0xcc, 0xcc, \ -} -#define LLC_ORG_CISCO { 0x00, 0x00, 0x0c } -#define LLC_ORG_FOUNDRY { 0x00, 0xe0, 0x52 } +#define CDP_MULTICAST_ADDR \ + { \ + 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc \ + } +#define FDP_MULTICAST_ADDR \ + { \ + 0x01, 0xe0, 0x52, 0xcc, 0xcc, 0xcc, \ + } +#define LLC_ORG_CISCO \ + { \ + 0x00, 0x00, 0x0c \ + } +#define LLC_ORG_FOUNDRY \ + { \ + 0x00, 0xe0, 0x52 \ + } #define LLC_PID_CDP 0x2000 /* Other protocols */ #define LLC_PID_DRIP 0x102 @@ -37,27 +45,26 @@ #define LLC_PID_STP 0x200a enum { - CDP_TLV_CHASSIS = 1, - CDP_TLV_ADDRESSES = 2, - CDP_TLV_PORT = 3, - CDP_TLV_CAPABILITIES = 4, - CDP_TLV_SOFTWARE = 5, - CDP_TLV_PLATFORM = 6, - CDP_TLV_NATIVEVLAN = 10, - CDP_TLV_POWER_CONSUMPTION = 0x10, - CDP_TLV_POWER_REQUESTED = 0x19, - CDP_TLV_POWER_AVAILABLE = 0x1A + CDP_TLV_CHASSIS = 1, + CDP_TLV_ADDRESSES = 2, + CDP_TLV_PORT = 3, + CDP_TLV_CAPABILITIES = 4, + CDP_TLV_SOFTWARE = 5, + CDP_TLV_PLATFORM = 6, + CDP_TLV_NATIVEVLAN = 10, + CDP_TLV_POWER_CONSUMPTION = 0x10, + CDP_TLV_POWER_REQUESTED = 0x19, + CDP_TLV_POWER_AVAILABLE = 0x1A }; #define CDP_ADDRESS_PROTO_IP 0xcc -#define CDP_CAP_ROUTER 0x01 +#define CDP_CAP_ROUTER 0x01 #define CDP_CAP_TRANSPARENT_BRIDGE 0x02 -#define CDP_CAP_SOURCE_BRIDGE 0x04 -#define CDP_CAP_SWITCH 0x08 -#define CDP_CAP_HOST 0x10 -#define CDP_CAP_IGMP 0x20 -#define CDP_CAP_REPEATER 0x40 +#define CDP_CAP_SOURCE_BRIDGE 0x04 +#define CDP_CAP_SWITCH 0x08 +#define CDP_CAP_HOST 0x10 +#define CDP_CAP_IGMP 0x20 +#define CDP_CAP_REPEATER 0x40 #endif /* _CDP_H */ - diff --git a/src/daemon/protocols/edp.c b/src/daemon/protocols/edp.c index 0c9b05c8..35ae912d 100644 --- a/src/daemon/protocols/edp.c +++ b/src/daemon/protocols/edp.c @@ -20,114 +20,106 @@ #ifdef ENABLE_EDP -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include static int seq = 0; int -edp_send(struct lldpd *global, - struct lldpd_hardware *hardware) +edp_send(struct lldpd *global, struct lldpd_hardware *hardware) { const u_int8_t mcastaddr[] = EDP_MULTICAST_ADDR; const u_int8_t llcorg[] = LLC_ORG_EXTREME; struct lldpd_chassis *chassis; int length, i, v; - u_int8_t *packet, *pos, *pos_llc, *pos_len_eh, *pos_len_edp, *pos_edp, *tlv, *end; + u_int8_t *packet, *pos, *pos_llc, *pos_len_eh, *pos_len_edp, *pos_edp, *tlv, + *end; u_int16_t checksum; -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 struct lldpd_vlan *vlan; unsigned int state = 0; -#endif - u_int8_t edp_fakeversion[] = {7, 6, 4, 99}; +# endif + u_int8_t edp_fakeversion[] = { 7, 6, 4, 99 }; /* Subsequent XXX can be replaced by other values. We place them here to ensure the position of "" to be a bit invariant with version changes. */ - char *deviceslot[] = { "eth", "veth", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "", NULL }; + char *deviceslot[] = { "eth", "veth", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", + "", NULL }; log_debug("edp", "send EDP frame on port %s", hardware->h_ifname); chassis = hardware->h_lport.p_chassis; -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 while (state != 2) { -#endif +# endif length = hardware->h_mtu; - if ((packet = (u_int8_t*)calloc(1, length)) == NULL) - return ENOMEM; + if ((packet = (u_int8_t *)calloc(1, length)) == NULL) return ENOMEM; pos = packet; v = 0; /* Ethernet header */ - if (!( - POKE_BYTES(mcastaddr, sizeof(mcastaddr)) && - POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) && - POKE_SAVE(pos_len_eh) && /* We compute the len later */ - POKE_UINT16(0))) + if (!(POKE_BYTES(mcastaddr, sizeof(mcastaddr)) && + POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) && + POKE_SAVE(pos_len_eh) && /* We compute the len later */ + POKE_UINT16(0))) goto toobig; /* LLC */ - if (!( - POKE_SAVE(pos_llc) && /* We need to save our + if (!(POKE_SAVE(pos_llc) && /* We need to save our current position to compute ethernet len */ - /* SSAP and DSAP */ - POKE_UINT8(0xaa) && POKE_UINT8(0xaa) && - /* Control field */ - POKE_UINT8(0x03) && - /* ORG */ - POKE_BYTES(llcorg, sizeof(llcorg)) && - POKE_UINT16(LLC_PID_EDP))) + /* SSAP and DSAP */ + POKE_UINT8(0xaa) && POKE_UINT8(0xaa) && + /* Control field */ + POKE_UINT8(0x03) && + /* ORG */ + POKE_BYTES(llcorg, sizeof(llcorg)) && POKE_UINT16(LLC_PID_EDP))) goto toobig; /* EDP header */ if ((chassis->c_id_len != ETHER_ADDR_LEN) || (chassis->c_id_subtype != LLDP_CHASSISID_SUBTYPE_LLADDR)) { - log_warnx("edp", "local chassis does not use MAC address as chassis ID!?"); + log_warnx("edp", + "local chassis does not use MAC address as chassis ID!?"); free(packet); return EINVAL; } - if (!( - POKE_SAVE(pos_edp) && /* Save the start of EDP frame */ - POKE_UINT8(1) && POKE_UINT8(0) && - POKE_SAVE(pos_len_edp) && /* We compute the len - and the checksum - later */ - POKE_UINT32(0) && /* Len + Checksum */ - POKE_UINT16(seq) && - POKE_UINT16(0) && - POKE_BYTES(chassis->c_id, ETHER_ADDR_LEN))) + if (!(POKE_SAVE(pos_edp) && /* Save the start of EDP frame */ + POKE_UINT8(1) && POKE_UINT8(0) && + POKE_SAVE(pos_len_edp) && /* We compute the len + and the checksum + later */ + POKE_UINT32(0) && /* Len + Checksum */ + POKE_UINT16(seq) && POKE_UINT16(0) && + POKE_BYTES(chassis->c_id, ETHER_ADDR_LEN))) goto toobig; seq++; -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 switch (state) { case 0: -#endif +# endif /* Display TLV */ - if (!( - POKE_START_EDP_TLV(EDP_TLV_DISPLAY) && - POKE_BYTES(chassis->c_name, strlen(chassis->c_name)) && - POKE_UINT8(0) && /* Add a NULL character - for better - compatibility */ - POKE_END_EDP_TLV)) + if (!(POKE_START_EDP_TLV(EDP_TLV_DISPLAY) && + POKE_BYTES(chassis->c_name, strlen(chassis->c_name)) && + POKE_UINT8(0) && /* Add a NULL character + for better + compatibility */ + POKE_END_EDP_TLV)) goto toobig; /* Info TLV */ - if (!( - POKE_START_EDP_TLV(EDP_TLV_INFO))) - goto toobig; + if (!(POKE_START_EDP_TLV(EDP_TLV_INFO))) goto toobig; /* We try to emulate the slot thing */ - for (i=0; deviceslot[i] != NULL; i++) { + for (i = 0; deviceslot[i] != NULL; i++) { if (strncmp(hardware->h_ifname, deviceslot[i], strlen(deviceslot[i])) == 0) { - if (!( - POKE_UINT16(i) && - POKE_UINT16(atoi(hardware->h_ifname + - strlen(deviceslot[i]))))) + if (!(POKE_UINT16(i) && + POKE_UINT16(atoi(hardware->h_ifname + + strlen(deviceslot[i]))))) goto toobig; break; } @@ -135,41 +127,36 @@ edp_send(struct lldpd *global, /* If we don't find a "slot", we say that the interface is in slot 8 */ if (deviceslot[i] == NULL) { - if (!( - POKE_UINT16(8) && - POKE_UINT16(hardware->h_ifindex))) + if (!(POKE_UINT16(8) && + POKE_UINT16(hardware->h_ifindex))) goto toobig; } - if (!( - POKE_UINT16(0) && /* vchassis */ - POKE_UINT32(0) && POKE_UINT16(0) && /* Reserved */ - /* Version */ - POKE_BYTES(edp_fakeversion, sizeof(edp_fakeversion)) && - /* Connections, we say that we won't - have more interfaces than this - mask. */ - POKE_UINT32(0xffffffff) && - POKE_UINT32(0) && POKE_UINT32(0) && POKE_UINT32(0) && - POKE_END_EDP_TLV)) + if (!(POKE_UINT16(0) && /* vchassis */ + POKE_UINT32(0) && POKE_UINT16(0) && /* Reserved */ + /* Version */ + POKE_BYTES(edp_fakeversion, sizeof(edp_fakeversion)) && + /* Connections, we say that we won't + have more interfaces than this + mask. */ + POKE_UINT32(0xffffffff) && POKE_UINT32(0) && + POKE_UINT32(0) && POKE_UINT32(0) && POKE_END_EDP_TLV)) goto toobig; -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 break; case 1: - TAILQ_FOREACH(vlan, &hardware->h_lport.p_vlans, - v_entries) { + TAILQ_FOREACH (vlan, &hardware->h_lport.p_vlans, v_entries) { v++; - if (!( - POKE_START_EDP_TLV(EDP_TLV_VLAN) && - POKE_UINT8(0) && /* Flags: no IP address */ - POKE_UINT8(0) && /* Reserved */ - POKE_UINT16(vlan->v_vid) && - POKE_UINT32(0) && /* Reserved */ - POKE_UINT32(0) && /* IP address */ - /* VLAN name */ - POKE_BYTES(vlan->v_name, strlen(vlan->v_name)) && - POKE_UINT8(0) && - POKE_END_EDP_TLV)) + if (!(POKE_START_EDP_TLV(EDP_TLV_VLAN) && + POKE_UINT8(0) && /* Flags: no IP address */ + POKE_UINT8(0) && /* Reserved */ + POKE_UINT16(vlan->v_vid) && + POKE_UINT32(0) && /* Reserved */ + POKE_UINT32(0) && /* IP address */ + /* VLAN name */ + POKE_BYTES(vlan->v_name, + strlen(vlan->v_name)) && + POKE_UINT8(0) && POKE_END_EDP_TLV)) goto toobig; } break; @@ -180,13 +167,11 @@ edp_send(struct lldpd *global, free(packet); break; } -#endif - +# endif + /* Null TLV */ - if (!( - POKE_START_EDP_TLV(EDP_TLV_NULL) && - POKE_END_EDP_TLV && - POKE_SAVE(end))) + if (!(POKE_START_EDP_TLV(EDP_TLV_NULL) && POKE_END_EDP_TLV && + POKE_SAVE(end))) goto toobig; /* Compute len and checksum */ @@ -199,8 +184,8 @@ edp_send(struct lldpd *global, checksum = frame_checksum(pos_edp, v, 0); if (!(POKE_UINT16(checksum))) goto toobig; - if (interfaces_send_helper(global, hardware, - (char *)packet, end - packet) == -1) { + if (interfaces_send_helper(global, hardware, (char *)packet, + end - packet) == -1) { log_warn("edp", "unable to send packet on real device for %s", hardware->h_ifname); free(packet); @@ -208,48 +193,48 @@ edp_send(struct lldpd *global, } free(packet); -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 state++; } -#endif +# endif hardware->h_tx_cnt++; return 0; - toobig: +toobig: free(packet); return E2BIG; } -#define CHECK_TLV_SIZE(x, name) \ - do { if (tlv_len < (x)) { \ - log_warnx("edp", name " EDP TLV too short received on %s", \ - hardware->h_ifname); \ - goto malformed; \ - } } while (0) +# define CHECK_TLV_SIZE(x, name) \ + do { \ + if (tlv_len < (x)) { \ + log_warnx("edp", name " EDP TLV too short received on %s", \ + hardware->h_ifname); \ + goto malformed; \ + } \ + } while (0) int -edp_decode(struct lldpd *cfg, char *frame, int s, - struct lldpd_hardware *hardware, +edp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardware, struct lldpd_chassis **newchassis, struct lldpd_port **newport) { struct lldpd_chassis *chassis; struct lldpd_port *port; -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 struct lldpd_mgmt *mgmt, *mgmt_next, *m; struct lldpd_vlan *lvlan = NULL, *lvlan_next; -#endif +# endif const unsigned char edpaddr[] = EDP_MULTICAST_ADDR; int length, gotend = 0, gotvlans = 0, edp_len, tlv_len, tlv_type; int edp_port, edp_slot; u_int8_t *pos, *pos_edp, *tlv; u_int8_t version[4]; -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 struct in_addr address; struct lldpd_port *oport; -#endif +# endif - log_debug("edp", "decode EDP frame on port %s", - hardware->h_ifname); + log_debug("edp", "decode EDP frame on port %s", hardware->h_ifname); if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) { log_warn("edp", "failed to allocate remote chassis"); @@ -261,26 +246,29 @@ edp_decode(struct lldpd *cfg, char *frame, int s, free(chassis); return -1; } -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 TAILQ_INIT(&port->p_vlans); -#endif +# endif length = s; - pos = (u_int8_t*)frame; + pos = (u_int8_t *)frame; - if (length < 2*ETHER_ADDR_LEN + sizeof(u_int16_t) + 8 /* LLC */ + - 10 + ETHER_ADDR_LEN /* EDP header */) { - log_warnx("edp", "too short EDP frame received on %s", hardware->h_ifname); + if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t) + 8 /* LLC */ + 10 + + ETHER_ADDR_LEN /* EDP header */) { + log_warnx("edp", "too short EDP frame received on %s", + hardware->h_ifname); goto malformed; } if (PEEK_CMP(edpaddr, sizeof(edpaddr)) != 0) { - log_info("edp", "frame not targeted at EDP multicast address received on %s", + log_info("edp", + "frame not targeted at EDP multicast address received on %s", hardware->h_ifname); goto malformed; } - PEEK_DISCARD(ETHER_ADDR_LEN); PEEK_DISCARD_UINT16; - PEEK_DISCARD(6); /* LLC: DSAP + SSAP + control + org */ + PEEK_DISCARD(ETHER_ADDR_LEN); + PEEK_DISCARD_UINT16; + PEEK_DISCARD(6); /* LLC: DSAP + SSAP + control + org */ if (PEEK_UINT16 != LLC_PID_EDP) { log_debug("edp", "incorrect LLC protocol ID received on %s", hardware->h_ifname); @@ -293,11 +281,11 @@ edp_decode(struct lldpd *cfg, char *frame, int s, hardware->h_ifname); goto malformed; } - PEEK_DISCARD_UINT8; /* Reserved */ + PEEK_DISCARD_UINT8; /* Reserved */ edp_len = PEEK_UINT16; PEEK_DISCARD_UINT16; /* Checksum */ PEEK_DISCARD_UINT16; /* Sequence */ - if (PEEK_UINT16 != 0) { /* ID Type = 0 = MAC */ + if (PEEK_UINT16 != 0) { /* ID Type = 0 = MAC */ log_warnx("edp", "incorrect device id type for frame received on %s", hardware->h_ifname); goto malformed; @@ -307,7 +295,7 @@ edp_decode(struct lldpd *cfg, char *frame, int s, hardware->h_ifname); goto malformed; } - port->p_ttl = cfg?cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold:0; + port->p_ttl = cfg ? cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold : 0; port->p_ttl = (port->p_ttl + 999) / 1000; chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; chassis->c_id_len = ETHER_ADDR_LEN; @@ -326,13 +314,15 @@ edp_decode(struct lldpd *cfg, char *frame, int s, while (length && !gotend) { if (length < 4) { - log_warnx("edp", "EDP TLV header is too large for " + log_warnx("edp", + "EDP TLV header is too large for " "frame received on %s", hardware->h_ifname); goto malformed; } if (PEEK_UINT8 != EDP_TLV_MARKER) { - log_warnx("edp", "incorrect marker starting EDP TLV header for frame " + log_warnx("edp", + "incorrect marker starting EDP TLV header for frame " "received on %s", hardware->h_ifname); goto malformed; @@ -341,7 +331,8 @@ edp_decode(struct lldpd *cfg, char *frame, int s, tlv_len = PEEK_UINT16 - 4; (void)PEEK_SAVE(tlv); if ((tlv_len < 0) || (tlv_len > length)) { - log_debug("edp", "incorrect size in EDP TLV header for frame " + log_debug("edp", + "incorrect size in EDP TLV header for frame " "received on %s", hardware->h_ifname); /* Some poor old Extreme Summit are quite bogus */ @@ -352,17 +343,20 @@ edp_decode(struct lldpd *cfg, char *frame, int s, case EDP_TLV_INFO: CHECK_TLV_SIZE(32, "Info"); port->p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME; - edp_slot = PEEK_UINT16; edp_port = PEEK_UINT16; - if (asprintf(&port->p_id, "%d/%d", - edp_slot + 1, edp_port + 1) == -1) { - log_warn("edp", "unable to allocate memory for " + edp_slot = PEEK_UINT16; + edp_port = PEEK_UINT16; + if (asprintf(&port->p_id, "%d/%d", edp_slot + 1, + edp_port + 1) == -1) { + log_warn("edp", + "unable to allocate memory for " "port ID"); goto malformed; } port->p_id_len = strlen(port->p_id); - if (asprintf(&port->p_descr, "Slot %d / Port %d", - edp_slot + 1, edp_port + 1) == -1) { - log_warn("edp", "unable to allocate memory for " + if (asprintf(&port->p_descr, "Slot %d / Port %d", edp_slot + 1, + edp_port + 1) == -1) { + log_warn("edp", + "unable to allocate memory for " "port description"); goto malformed; } @@ -370,18 +364,20 @@ edp_decode(struct lldpd *cfg, char *frame, int s, PEEK_DISCARD(6); /* Reserved */ PEEK_BYTES(version, 4); if (asprintf(&chassis->c_descr, - "EDP enabled device, version %d.%d.%d.%d", - version[0], version[1], - version[2], version[3]) == -1) { - log_warn("edp", "unable to allocate memory for " + "EDP enabled device, version %d.%d.%d.%d", version[0], + version[1], version[2], version[3]) == -1) { + log_warn("edp", + "unable to allocate memory for " "chassis description"); goto malformed; } break; case EDP_TLV_DISPLAY: free(chassis->c_name); - if ((chassis->c_name = (char *)calloc(1, tlv_len + 1)) == NULL) { - log_warn("edp", "unable to allocate memory for chassis " + if ((chassis->c_name = (char *)calloc(1, tlv_len + 1)) == + NULL) { + log_warn("edp", + "unable to allocate memory for chassis " "name"); goto malformed; } @@ -390,7 +386,8 @@ edp_decode(struct lldpd *cfg, char *frame, int s, break; case EDP_TLV_NULL: if (tlv_len != 0) { - log_warnx("edp", "null tlv with incorrect size in frame " + log_warnx("edp", + "null tlv with incorrect size in frame " "received on %s", hardware->h_ifname); goto malformed; @@ -401,21 +398,21 @@ edp_decode(struct lldpd *cfg, char *frame, int s, gotend = 1; break; case EDP_TLV_VLAN: -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 CHECK_TLV_SIZE(12, "VLAN"); if ((lvlan = (struct lldpd_vlan *)calloc(1, - sizeof(struct lldpd_vlan))) == NULL) { + sizeof(struct lldpd_vlan))) == NULL) { log_warn("edp", "unable to allocate vlan"); goto malformed; } - PEEK_DISCARD_UINT16; /* Flags + reserved */ + PEEK_DISCARD_UINT16; /* Flags + reserved */ lvlan->v_vid = PEEK_UINT16; /* VID */ PEEK_DISCARD(4); /* Reserved */ PEEK_BYTES(&address, sizeof(address)); if (address.s_addr != INADDR_ANY) { - mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &address, - sizeof(struct in_addr), 0); + mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &address, + sizeof(struct in_addr), 0); if (mgmt == NULL) { log_warn("edp", "Out of memory"); goto malformed; @@ -423,17 +420,16 @@ edp_decode(struct lldpd *cfg, char *frame, int s, TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries); } - if ((lvlan->v_name = (char *)calloc(1, - tlv_len + 1 - 12)) == NULL) { + if ((lvlan->v_name = (char *)calloc(1, tlv_len + 1 - 12)) == + NULL) { log_warn("edp", "unable to allocate vlan name"); goto malformed; } PEEK_BYTES(lvlan->v_name, tlv_len - 12); - TAILQ_INSERT_TAIL(&port->p_vlans, - lvlan, v_entries); + TAILQ_INSERT_TAIL(&port->p_vlans, lvlan, v_entries); lvlan = NULL; -#endif +# endif gotvlans = 1; break; default: @@ -443,58 +439,56 @@ edp_decode(struct lldpd *cfg, char *frame, int s, } PEEK_DISCARD(tlv + tlv_len - pos); } - if ((chassis->c_id == NULL) || - (port->p_id == NULL) || - (chassis->c_name == NULL) || - (chassis->c_descr == NULL) || - (port->p_descr == NULL) || - (gotend == 0)) { -#ifdef ENABLE_DOT1 + if ((chassis->c_id == NULL) || (port->p_id == NULL) || + (chassis->c_name == NULL) || (chassis->c_descr == NULL) || + (port->p_descr == NULL) || (gotend == 0)) { +# ifdef ENABLE_DOT1 if (gotvlans && gotend) { /* VLAN can be sent in a separate frames. We need to add * those vlans to an existing port */ - TAILQ_FOREACH(oport, &hardware->h_rports, p_entries) { + TAILQ_FOREACH (oport, &hardware->h_rports, p_entries) { if (!((oport->p_protocol == LLDPD_MODE_EDP) && (oport->p_chassis->c_id_subtype == chassis->c_id_subtype) && - (oport->p_chassis->c_id_len == chassis->c_id_len) && + (oport->p_chassis->c_id_len == + chassis->c_id_len) && (memcmp(oport->p_chassis->c_id, chassis->c_id, - chassis->c_id_len) == 0))) + chassis->c_id_len) == 0))) continue; /* We attach the VLANs to the found port */ lldpd_vlan_cleanup(oport); - for (lvlan = TAILQ_FIRST(&port->p_vlans); - lvlan != NULL; + for (lvlan = TAILQ_FIRST(&port->p_vlans); lvlan != NULL; lvlan = lvlan_next) { lvlan_next = TAILQ_NEXT(lvlan, v_entries); TAILQ_REMOVE(&port->p_vlans, lvlan, v_entries); - TAILQ_INSERT_TAIL(&oport->p_vlans, - lvlan, v_entries); + TAILQ_INSERT_TAIL(&oport->p_vlans, lvlan, + v_entries); } /* And the IP addresses */ - for (mgmt = TAILQ_FIRST(&chassis->c_mgmt); - mgmt != NULL; + for (mgmt = TAILQ_FIRST(&chassis->c_mgmt); mgmt != NULL; mgmt = mgmt_next) { mgmt_next = TAILQ_NEXT(mgmt, m_entries); TAILQ_REMOVE(&chassis->c_mgmt, mgmt, m_entries); /* Don't add an address that already exists! */ - TAILQ_FOREACH(m, &chassis->c_mgmt, m_entries) - if (m->m_family == mgmt->m_family && - !memcmp(&m->m_addr, &mgmt->m_addr, - sizeof(m->m_addr))) break; + TAILQ_FOREACH (m, &chassis->c_mgmt, m_entries) + if (m->m_family == mgmt->m_family && + !memcmp(&m->m_addr, &mgmt->m_addr, + sizeof(m->m_addr))) + break; if (m == NULL) - TAILQ_INSERT_TAIL(&oport->p_chassis->c_mgmt, - mgmt, m_entries); + TAILQ_INSERT_TAIL( + &oport->p_chassis->c_mgmt, mgmt, + m_entries); } } /* We discard the remaining frame */ goto malformed; } -#else - if (gotvlans) - goto malformed; -#endif - log_warnx("edp", "some mandatory tlv are missing for frame received on %s", +# else + if (gotvlans) goto malformed; +# endif + log_warnx("edp", + "some mandatory tlv are missing for frame received on %s", hardware->h_ifname); goto malformed; } @@ -503,9 +497,9 @@ edp_decode(struct lldpd *cfg, char *frame, int s, return 1; malformed: -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 free(lvlan); -#endif +# endif lldpd_chassis_cleanup(chassis, 1); lldpd_port_cleanup(port, 1); free(port); diff --git a/src/daemon/protocols/edp.h b/src/daemon/protocols/edp.h index e3cb7382..f4ee183c 100644 --- a/src/daemon/protocols/edp.h +++ b/src/daemon/protocols/edp.h @@ -18,20 +18,24 @@ #ifndef _EDP_H #define _EDP_H -#define EDP_MULTICAST_ADDR { \ - 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00 \ -} -#define LLC_ORG_EXTREME { 0x00, 0xe0, 0x2b } +#define EDP_MULTICAST_ADDR \ + { \ + 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00 \ + } +#define LLC_ORG_EXTREME \ + { \ + 0x00, 0xe0, 0x2b \ + } #define LLC_PID_EDP 0x00bb -#define EDP_TLV_MARKER 0x99 +#define EDP_TLV_MARKER 0x99 enum { - EDP_TLV_NULL = 0, - EDP_TLV_DISPLAY = 1, - EDP_TLV_INFO = 2, - EDP_TLV_VLAN = 5, - EDP_TLV_ESRP = 8, + EDP_TLV_NULL = 0, + EDP_TLV_DISPLAY = 1, + EDP_TLV_INFO = 2, + EDP_TLV_VLAN = 5, + EDP_TLV_ESRP = 8, }; #endif /* _EDP_H */ diff --git a/src/daemon/protocols/lldp.c b/src/daemon/protocols/lldp.c index 032f28e7..4f689a0c 100644 --- a/src/daemon/protocols/lldp.c +++ b/src/daemon/protocols/lldp.c @@ -51,16 +51,10 @@ lldpd_af_from_lldp_proto(int proto) } } -static int _lldp_send(struct lldpd *global, - struct lldpd_hardware *hardware, - u_int8_t c_id_subtype, - char *c_id, - int c_id_len, - u_int8_t p_id_subtype, - char *p_id, - int p_id_len, - int shutdown, - int without_vlans) +static int +_lldp_send(struct lldpd *global, struct lldpd_hardware *hardware, u_int8_t c_id_subtype, + char *c_id, int c_id_len, u_int8_t p_id_subtype, char *p_id, int p_id_len, + int shutdown, int without_vlans) { struct lldpd_port *port; struct lldpd_chassis *chassis; @@ -94,278 +88,248 @@ static int _lldp_send(struct lldpd *global, port = &hardware->h_lport; chassis = port->p_chassis; length = hardware->h_mtu; - if ((packet = (u_int8_t*)calloc(1, length)) == NULL) - return ENOMEM; + if ((packet = (u_int8_t *)calloc(1, length)) == NULL) return ENOMEM; pos = packet; /* Ethernet header */ switch (global->g_config.c_lldp_agent_type) { - case LLDP_AGENT_TYPE_NEAREST_NONTPMR_BRIDGE: mcastaddr = mcastaddr_nontpmr; break; - case LLDP_AGENT_TYPE_NEAREST_CUSTOMER_BRIDGE: mcastaddr = mcastaddr_customer; break; + case LLDP_AGENT_TYPE_NEAREST_NONTPMR_BRIDGE: + mcastaddr = mcastaddr_nontpmr; + break; + case LLDP_AGENT_TYPE_NEAREST_CUSTOMER_BRIDGE: + mcastaddr = mcastaddr_customer; + break; case LLDP_AGENT_TYPE_NEAREST_BRIDGE: - default: mcastaddr = mcastaddr_regular; break; + default: + mcastaddr = mcastaddr_regular; + break; } if (!( - /* LLDP multicast address */ - POKE_BYTES(mcastaddr, ETHER_ADDR_LEN) && - /* Source MAC address */ - POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN))) + /* LLDP multicast address */ + POKE_BYTES(mcastaddr, ETHER_ADDR_LEN) && + /* Source MAC address */ + POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN))) goto toobig; /* Insert VLAN tag if needed */ if (port->p_vlan_tx_enabled) { if (!( - /* VLAN ethertype */ - POKE_UINT16(ETHERTYPE_VLAN) && - /* VLAN Tag Control Information (TCI) */ - /* Priority(3bits) | DEI(1bit) | VID(12bit) */ - POKE_UINT16(port->p_vlan_tx_tag))) + /* VLAN ethertype */ + POKE_UINT16(ETHERTYPE_VLAN) && + /* VLAN Tag Control Information (TCI) */ + /* Priority(3bits) | DEI(1bit) | VID(12bit) */ + POKE_UINT16(port->p_vlan_tx_tag))) goto toobig; } if (!( - /* LLDP frame */ - POKE_UINT16(ETH_P_LLDP))) + /* LLDP frame */ + POKE_UINT16(ETH_P_LLDP))) goto toobig; /* Chassis ID */ - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_CHASSIS_ID) && - POKE_UINT8(c_id_subtype) && - POKE_BYTES(c_id, c_id_len) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_CHASSIS_ID) && POKE_UINT8(c_id_subtype) && + POKE_BYTES(c_id, c_id_len) && POKE_END_LLDP_TLV)) goto toobig; /* Port ID */ - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_PORT_ID) && - POKE_UINT8(p_id_subtype) && - POKE_BYTES(p_id, p_id_len) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_PORT_ID) && POKE_UINT8(p_id_subtype) && + POKE_BYTES(p_id, p_id_len) && POKE_END_LLDP_TLV)) goto toobig; /* Time to live */ - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_TTL) && - POKE_UINT16(shutdown?0:(global?global->g_config.c_ttl:180)) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_TTL) && + POKE_UINT16(shutdown ? 0 : (global ? global->g_config.c_ttl : 180)) && + POKE_END_LLDP_TLV)) goto toobig; - if (shutdown) - goto end; + if (shutdown) goto end; /* System name */ if (chassis->c_name && *chassis->c_name != '\0') { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_SYSTEM_NAME) && - POKE_BYTES(chassis->c_name, strlen(chassis->c_name)) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_SYSTEM_NAME) && + POKE_BYTES(chassis->c_name, strlen(chassis->c_name)) && + POKE_END_LLDP_TLV)) goto toobig; } /* System description (skip it if empty) */ if (chassis->c_descr && *chassis->c_descr != '\0') { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_SYSTEM_DESCR) && - POKE_BYTES(chassis->c_descr, strlen(chassis->c_descr)) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_SYSTEM_DESCR) && + POKE_BYTES(chassis->c_descr, strlen(chassis->c_descr)) && + POKE_END_LLDP_TLV)) goto toobig; } /* System capabilities */ if (global->g_config.c_cap_advertise && chassis->c_cap_available) { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_SYSTEM_CAP) && - POKE_UINT16(chassis->c_cap_available) && - POKE_UINT16(chassis->c_cap_enabled) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_SYSTEM_CAP) && + POKE_UINT16(chassis->c_cap_available) && + POKE_UINT16(chassis->c_cap_enabled) && POKE_END_LLDP_TLV)) goto toobig; } /* Management addresses */ - TAILQ_FOREACH(mgmt, &chassis->c_mgmt, m_entries) { + TAILQ_FOREACH (mgmt, &chassis->c_mgmt, m_entries) { proto = lldpd_af_to_lldp_proto(mgmt->m_family); if (proto == LLDP_MGMT_ADDR_NONE) continue; - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_MGMT_ADDR) && - /* Size of the address, including its type */ - POKE_UINT8(mgmt->m_addrsize + 1) && - POKE_UINT8(proto) && - POKE_BYTES(&mgmt->m_addr, mgmt->m_addrsize))) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_MGMT_ADDR) && + /* Size of the address, including its type */ + POKE_UINT8(mgmt->m_addrsize + 1) && POKE_UINT8(proto) && + POKE_BYTES(&mgmt->m_addr, mgmt->m_addrsize))) goto toobig; /* Interface port type, OID */ if (mgmt->m_iface == 0) { if (!( - /* We don't know the management interface */ - POKE_UINT8(LLDP_MGMT_IFACE_UNKNOWN) && - POKE_UINT32(0))) + /* We don't know the management interface */ + POKE_UINT8(LLDP_MGMT_IFACE_UNKNOWN) && POKE_UINT32(0))) goto toobig; } else { if (!( - /* We have the index of the management interface */ - POKE_UINT8(LLDP_MGMT_IFACE_IFINDEX) && - POKE_UINT32(mgmt->m_iface))) + /* We have the index of the management interface */ + POKE_UINT8(LLDP_MGMT_IFACE_IFINDEX) && + POKE_UINT32(mgmt->m_iface))) goto toobig; } if (!( - /* We don't provide an OID for management */ - POKE_UINT8(0) && - POKE_END_LLDP_TLV)) + /* We don't provide an OID for management */ + POKE_UINT8(0) && POKE_END_LLDP_TLV)) goto toobig; } /* Port description */ if (port->p_descr && *port->p_descr != '\0') { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_PORT_DESCR) && - POKE_BYTES(port->p_descr, strlen(port->p_descr)) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_PORT_DESCR) && + POKE_BYTES(port->p_descr, strlen(port->p_descr)) && + POKE_END_LLDP_TLV)) goto toobig; } #ifdef ENABLE_DOT1 /* Port VLAN ID */ - if(port->p_pvid != 0) { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(dot1, sizeof(dot1)) && - POKE_UINT8(LLDP_TLV_DOT1_PVID) && - POKE_UINT16(port->p_pvid) && - POKE_END_LLDP_TLV)) { - goto toobig; + if (port->p_pvid != 0) { + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && + POKE_BYTES(dot1, sizeof(dot1)) && + POKE_UINT8(LLDP_TLV_DOT1_PVID) && POKE_UINT16(port->p_pvid) && + POKE_END_LLDP_TLV)) { + goto toobig; } } /* Port and Protocol VLAN IDs */ - TAILQ_FOREACH(ppvid, &port->p_ppvids, p_entries) { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(dot1, sizeof(dot1)) && - POKE_UINT8(LLDP_TLV_DOT1_PPVID) && - POKE_UINT8(ppvid->p_cap_status) && - POKE_UINT16(ppvid->p_ppvid) && - POKE_END_LLDP_TLV)) { + TAILQ_FOREACH (ppvid, &port->p_ppvids, p_entries) { + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && + POKE_BYTES(dot1, sizeof(dot1)) && + POKE_UINT8(LLDP_TLV_DOT1_PPVID) && + POKE_UINT8(ppvid->p_cap_status) && + POKE_UINT16(ppvid->p_ppvid) && POKE_END_LLDP_TLV)) { goto toobig; } } /* VLANs */ if (!without_vlans) { - TAILQ_FOREACH(vlan, &port->p_vlans, v_entries) { + TAILQ_FOREACH (vlan, &port->p_vlans, v_entries) { vlans++; - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(dot1, sizeof(dot1)) && - POKE_UINT8(LLDP_TLV_DOT1_VLANNAME) && - POKE_UINT16(vlan->v_vid) && - POKE_UINT8(strlen(vlan->v_name)) && - POKE_BYTES(vlan->v_name, strlen(vlan->v_name)) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && + POKE_BYTES(dot1, sizeof(dot1)) && + POKE_UINT8(LLDP_TLV_DOT1_VLANNAME) && + POKE_UINT16(vlan->v_vid) && + POKE_UINT8(strlen(vlan->v_name)) && + POKE_BYTES(vlan->v_name, strlen(vlan->v_name)) && + POKE_END_LLDP_TLV)) goto toobig; } } /* Protocol Identities */ - TAILQ_FOREACH(pi, &port->p_pids, p_entries) { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(dot1, sizeof(dot1)) && - POKE_UINT8(LLDP_TLV_DOT1_PI) && - POKE_UINT8(pi->p_pi_len) && - POKE_BYTES(pi->p_pi, pi->p_pi_len) && - POKE_END_LLDP_TLV)) + TAILQ_FOREACH (pi, &port->p_pids, p_entries) { + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && + POKE_BYTES(dot1, sizeof(dot1)) && + POKE_UINT8(LLDP_TLV_DOT1_PI) && POKE_UINT8(pi->p_pi_len) && + POKE_BYTES(pi->p_pi, pi->p_pi_len) && POKE_END_LLDP_TLV)) goto toobig; } #endif #ifdef ENABLE_DOT3 /* Aggregation status */ - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(dot3, sizeof(dot3)) && - POKE_UINT8(LLDP_TLV_DOT3_LA) && - /* Bit 0 = capability ; Bit 1 = status */ - POKE_UINT8((port->p_aggregid) ? 3:1) && - POKE_UINT32(port->p_aggregid) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && POKE_BYTES(dot3, sizeof(dot3)) && + POKE_UINT8(LLDP_TLV_DOT3_LA) && + /* Bit 0 = capability ; Bit 1 = status */ + POKE_UINT8((port->p_aggregid) ? 3 : 1) && + POKE_UINT32(port->p_aggregid) && POKE_END_LLDP_TLV)) goto toobig; /* MAC/PHY */ - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(dot3, sizeof(dot3)) && - POKE_UINT8(LLDP_TLV_DOT3_MAC) && - POKE_UINT8(port->p_macphy.autoneg_support | - (port->p_macphy.autoneg_enabled << 1)) && - POKE_UINT16(port->p_macphy.autoneg_advertised) && - POKE_UINT16(port->p_macphy.mau_type) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && POKE_BYTES(dot3, sizeof(dot3)) && + POKE_UINT8(LLDP_TLV_DOT3_MAC) && + POKE_UINT8(port->p_macphy.autoneg_support | + (port->p_macphy.autoneg_enabled << 1)) && + POKE_UINT16(port->p_macphy.autoneg_advertised) && + POKE_UINT16(port->p_macphy.mau_type) && POKE_END_LLDP_TLV)) goto toobig; /* MFS */ if (port->p_mfs) { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(dot3, sizeof(dot3)) && - POKE_UINT8(LLDP_TLV_DOT3_MFS) && - POKE_UINT16(port->p_mfs) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && + POKE_BYTES(dot3, sizeof(dot3)) && + POKE_UINT8(LLDP_TLV_DOT3_MFS) && POKE_UINT16(port->p_mfs) && + POKE_END_LLDP_TLV)) goto toobig; } /* Power */ if (port->p_power.devicetype) { - if (!( - (port->p_power.type_ext != LLDP_DOT3_POWER_8023BT_OFF ? - (tlv = pos, POKE_UINT16((LLDP_TLV_ORG << 9) | (0x1d))): - POKE_START_LLDP_TLV(LLDP_TLV_ORG)) && - POKE_BYTES(dot3, sizeof(dot3)) && - POKE_UINT8(LLDP_TLV_DOT3_POWER) && - POKE_UINT8(( - (((2 - port->p_power.devicetype) %(1<< 1))<<0) | - (( port->p_power.supported %(1<< 1))<<1) | - (( port->p_power.enabled %(1<< 1))<<2) | - (( port->p_power.paircontrol %(1<< 1))<<3))) && - POKE_UINT8(port->p_power.pairs) && - POKE_UINT8(port->p_power.class))) + if (!((port->p_power.type_ext != LLDP_DOT3_POWER_8023BT_OFF ? + (tlv = pos, POKE_UINT16((LLDP_TLV_ORG << 9) | (0x1d))) : + POKE_START_LLDP_TLV(LLDP_TLV_ORG)) && + POKE_BYTES(dot3, sizeof(dot3)) && + POKE_UINT8(LLDP_TLV_DOT3_POWER) && + POKE_UINT8(((((2 - port->p_power.devicetype) % (1 << 1)) << 0) | + ((port->p_power.supported % (1 << 1)) << 1) | + ((port->p_power.enabled % (1 << 1)) << 2) | + ((port->p_power.paircontrol % (1 << 1)) << 3))) && + POKE_UINT8(port->p_power.pairs) && + POKE_UINT8(port->p_power.class))) goto toobig; /* 802.3at */ if (port->p_power.powertype != LLDP_DOT3_POWER_8023AT_OFF) { - if (!( - POKE_UINT8(((((port->p_power.powertype == - LLDP_DOT3_POWER_8023AT_TYPE1)?1:0) << 7) | - (((port->p_power.devicetype == - LLDP_DOT3_POWER_PSE)?0:1) << 6) | - ((port->p_power.source %(1<< 2))<<4) | - ((port->p_power.pd_4pid %(1 << 1))<<2) | - ((port->p_power.priority %(1<< 2))<<0))) && - POKE_UINT16(port->p_power.requested) && - POKE_UINT16(port->p_power.allocated))) + if (!(POKE_UINT8(((((port->p_power.powertype == + LLDP_DOT3_POWER_8023AT_TYPE1) ? + 1 : + 0) + << 7) | + (((port->p_power.devicetype == LLDP_DOT3_POWER_PSE) ? + 0 : + 1) + << 6) | + ((port->p_power.source % (1 << 2)) << 4) | + ((port->p_power.pd_4pid % (1 << 1)) << 2) | + ((port->p_power.priority % (1 << 2)) << 0))) && + POKE_UINT16(port->p_power.requested) && + POKE_UINT16(port->p_power.allocated))) goto toobig; } if (port->p_power.type_ext != LLDP_DOT3_POWER_8023BT_OFF) { - if (!( - POKE_UINT16(port->p_power.requested_a) && - POKE_UINT16(port->p_power.requested_b) && - POKE_UINT16(port->p_power.allocated_a) && - POKE_UINT16(port->p_power.allocated_b) && - POKE_UINT16(( - (port->p_power.pse_status << 14) | - (port->p_power.pd_status << 12) | - (port->p_power.pse_pairs_ext << 10) | - (port->p_power.class_a << 7) | - (port->p_power.class_b << 4) | - (port->p_power.class_ext << 0))) && - POKE_UINT8( - /* Adjust by -1 to enable 0 to mean no 802.3bt support */ - ((port->p_power.type_ext -1) << 1) | - (port->p_power.pd_load << 0)) && - POKE_UINT16(port->p_power.pse_max) && - /* Send 0 for autoclass and power down requests */ - POKE_UINT8(0) && - POKE_UINT16(0) && - POKE_UINT8(0))) - goto toobig; + if (!(POKE_UINT16(port->p_power.requested_a) && + POKE_UINT16(port->p_power.requested_b) && + POKE_UINT16(port->p_power.allocated_a) && + POKE_UINT16(port->p_power.allocated_b) && + POKE_UINT16(((port->p_power.pse_status << 14) | + (port->p_power.pd_status << 12) | + (port->p_power.pse_pairs_ext << 10) | + (port->p_power.class_a << 7) | + (port->p_power.class_b << 4) | + (port->p_power.class_ext << 0))) && + POKE_UINT8( + /* Adjust by -1 to enable 0 to mean no 802.3bt + support */ + ((port->p_power.type_ext - 1) << 1) | + (port->p_power.pd_load << 0)) && + POKE_UINT16(port->p_power.pse_max) && + /* Send 0 for autoclass and power down requests */ + POKE_UINT8(0) && POKE_UINT16(0) && POKE_UINT8(0))) + goto toobig; } - if (!(POKE_END_LLDP_TLV)) - goto toobig; + if (!(POKE_END_LLDP_TLV)) goto toobig; } #endif @@ -373,57 +337,44 @@ static int _lldp_send(struct lldpd *global, if (port->p_med_cap_enabled) { /* LLDP-MED cap */ if (port->p_med_cap_enabled & LLDP_MED_CAP_CAP) { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(med, sizeof(med)) && - POKE_UINT8(LLDP_TLV_MED_CAP) && - POKE_UINT16(chassis->c_med_cap_available) && - POKE_UINT8(chassis->c_med_type) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && + POKE_BYTES(med, sizeof(med)) && + POKE_UINT8(LLDP_TLV_MED_CAP) && + POKE_UINT16(chassis->c_med_cap_available) && + POKE_UINT8(chassis->c_med_type) && POKE_END_LLDP_TLV)) goto toobig; } /* LLDP-MED inventory */ -#define LLDP_INVENTORY(value, subtype) \ - if (value) { \ - if (!( \ - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && \ - POKE_BYTES(med, sizeof(med)) && \ - POKE_UINT8(subtype) && \ - POKE_BYTES(value, \ - (strlen(value)>32)?32:strlen(value)) && \ - POKE_END_LLDP_TLV)) \ - goto toobig; \ - } +# define LLDP_INVENTORY(value, subtype) \ + if (value) { \ + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && POKE_BYTES(med, sizeof(med)) && \ + POKE_UINT8(subtype) && \ + POKE_BYTES(value, (strlen(value) > 32) ? 32 : strlen(value)) && \ + POKE_END_LLDP_TLV)) \ + goto toobig; \ + } if (port->p_med_cap_enabled & LLDP_MED_CAP_IV) { - LLDP_INVENTORY(chassis->c_med_hw, - LLDP_TLV_MED_IV_HW); - LLDP_INVENTORY(chassis->c_med_fw, - LLDP_TLV_MED_IV_FW); - LLDP_INVENTORY(chassis->c_med_sw, - LLDP_TLV_MED_IV_SW); - LLDP_INVENTORY(chassis->c_med_sn, - LLDP_TLV_MED_IV_SN); - LLDP_INVENTORY(chassis->c_med_manuf, - LLDP_TLV_MED_IV_MANUF); - LLDP_INVENTORY(chassis->c_med_model, - LLDP_TLV_MED_IV_MODEL); - LLDP_INVENTORY(chassis->c_med_asset, - LLDP_TLV_MED_IV_ASSET); + LLDP_INVENTORY(chassis->c_med_hw, LLDP_TLV_MED_IV_HW); + LLDP_INVENTORY(chassis->c_med_fw, LLDP_TLV_MED_IV_FW); + LLDP_INVENTORY(chassis->c_med_sw, LLDP_TLV_MED_IV_SW); + LLDP_INVENTORY(chassis->c_med_sn, LLDP_TLV_MED_IV_SN); + LLDP_INVENTORY(chassis->c_med_manuf, LLDP_TLV_MED_IV_MANUF); + LLDP_INVENTORY(chassis->c_med_model, LLDP_TLV_MED_IV_MODEL); + LLDP_INVENTORY(chassis->c_med_asset, LLDP_TLV_MED_IV_ASSET); } /* LLDP-MED location */ for (i = 0; i < LLDP_MED_LOCFORMAT_LAST; i++) { if (port->p_med_location[i].format == i + 1) { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(med, sizeof(med)) && - POKE_UINT8(LLDP_TLV_MED_LOCATION) && - POKE_UINT8(port->p_med_location[i].format) && - POKE_BYTES(port->p_med_location[i].data, - port->p_med_location[i].data_len) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && + POKE_BYTES(med, sizeof(med)) && + POKE_UINT8(LLDP_TLV_MED_LOCATION) && + POKE_UINT8(port->p_med_location[i].format) && + POKE_BYTES(port->p_med_location[i].data, + port->p_med_location[i].data_len) && + POKE_END_LLDP_TLV)) goto toobig; } } @@ -431,19 +382,25 @@ static int _lldp_send(struct lldpd *global, /* LLDP-MED network policy */ for (i = 0; i < LLDP_MED_APPTYPE_LAST; i++) { if (port->p_med_policy[i].type == i + 1) { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(med, sizeof(med)) && - POKE_UINT8(LLDP_TLV_MED_POLICY) && - POKE_UINT32(( - ((port->p_med_policy[i].type %(1<< 8))<<24) | - ((port->p_med_policy[i].unknown %(1<< 1))<<23) | - ((port->p_med_policy[i].tagged %(1<< 1))<<22) | - /*((0 %(1<< 1))<<21) |*/ - ((port->p_med_policy[i].vid %(1<<12))<< 9) | - ((port->p_med_policy[i].priority %(1<< 3))<< 6) | - ((port->p_med_policy[i].dscp %(1<< 6))<< 0) )) && - POKE_END_LLDP_TLV)) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && + POKE_BYTES(med, sizeof(med)) && + POKE_UINT8(LLDP_TLV_MED_POLICY) && + POKE_UINT32(( + ((port->p_med_policy[i].type % (1 << 8)) + << 24) | + ((port->p_med_policy[i].unknown % (1 << 1)) + << 23) | + ((port->p_med_policy[i].tagged % (1 << 1)) + << 22) | + /*((0 %(1<< + 1))<<21) |*/ + ((port->p_med_policy[i].vid % (1 << 12)) + << 9) | + ((port->p_med_policy[i].priority % (1 << 3)) + << 6) | + ((port->p_med_policy[i].dscp % (1 << 6)) + << 0))) && + POKE_END_LLDP_TLV)) goto toobig; } } @@ -452,64 +409,73 @@ static int _lldp_send(struct lldpd *global, if ((port->p_med_power.devicetype == LLDP_MED_POW_TYPE_PSE) || (port->p_med_power.devicetype == LLDP_MED_POW_TYPE_PD)) { int devicetype = 0, source = 0; - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(med, sizeof(med)) && - POKE_UINT8(LLDP_TLV_MED_MDI))) + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && + POKE_BYTES(med, sizeof(med)) && + POKE_UINT8(LLDP_TLV_MED_MDI))) goto toobig; switch (port->p_med_power.devicetype) { case LLDP_MED_POW_TYPE_PSE: devicetype = 0; switch (port->p_med_power.source) { - case LLDP_MED_POW_SOURCE_PRIMARY: source = 1; break; - case LLDP_MED_POW_SOURCE_BACKUP: source = 2; break; - case LLDP_MED_POW_SOURCE_RESERVED: source = 3; break; - default: source = 0; break; + case LLDP_MED_POW_SOURCE_PRIMARY: + source = 1; + break; + case LLDP_MED_POW_SOURCE_BACKUP: + source = 2; + break; + case LLDP_MED_POW_SOURCE_RESERVED: + source = 3; + break; + default: + source = 0; + break; } break; case LLDP_MED_POW_TYPE_PD: devicetype = 1; switch (port->p_med_power.source) { - case LLDP_MED_POW_SOURCE_PSE: source = 1; break; - case LLDP_MED_POW_SOURCE_LOCAL: source = 2; break; - case LLDP_MED_POW_SOURCE_BOTH: source = 3; break; - default: source = 0; break; + case LLDP_MED_POW_SOURCE_PSE: + source = 1; + break; + case LLDP_MED_POW_SOURCE_LOCAL: + source = 2; + break; + case LLDP_MED_POW_SOURCE_BOTH: + source = 3; + break; + default: + source = 0; + break; } break; } - if (!( - POKE_UINT8(( - ((devicetype %(1<< 2))<<6) | - ((source %(1<< 2))<<4) | - ((port->p_med_power.priority %(1<< 4))<<0) )) && - POKE_UINT16(port->p_med_power.val) && - POKE_END_LLDP_TLV)) + if (!(POKE_UINT8((((devicetype % (1 << 2)) << 6) | + ((source % (1 << 2)) << 4) | + ((port->p_med_power.priority % (1 << 4)) << 0))) && + POKE_UINT16(port->p_med_power.val) && + POKE_END_LLDP_TLV)) goto toobig; } } #endif #ifdef ENABLE_CUSTOM - TAILQ_FOREACH(custom, &port->p_custom_list, next) { - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_ORG) && - POKE_BYTES(custom->oui, sizeof(custom->oui)) && - POKE_UINT8(custom->subtype) && - POKE_BYTES(custom->oui_info, custom->oui_info_len) && - POKE_END_LLDP_TLV)) + TAILQ_FOREACH (custom, &port->p_custom_list, next) { + if (!(POKE_START_LLDP_TLV(LLDP_TLV_ORG) && + POKE_BYTES(custom->oui, sizeof(custom->oui)) && + POKE_UINT8(custom->subtype) && + POKE_BYTES(custom->oui_info, custom->oui_info_len) && + POKE_END_LLDP_TLV)) goto toobig; } #endif end: /* END */ - if (!( - POKE_START_LLDP_TLV(LLDP_TLV_END) && - POKE_END_LLDP_TLV)) - goto toobig; + if (!(POKE_START_LLDP_TLV(LLDP_TLV_END) && POKE_END_LLDP_TLV)) goto toobig; - if (interfaces_send_helper(global, hardware, - (char *)packet, pos - packet) == -1) { + if (interfaces_send_helper(global, hardware, (char *)packet, pos - packet) == + -1) { log_warn("lldp", "unable to send packet on real device for %s", hardware->h_ifname); free(packet); @@ -519,18 +485,20 @@ end: hardware->h_tx_cnt++; /* We assume that LLDP frame is the reference */ - if (!shutdown && (frame = (struct lldpd_frame*)malloc( - sizeof(int) + pos - packet)) != NULL) { + if (!shutdown && + (frame = (struct lldpd_frame *)malloc(sizeof(int) + pos - packet)) != + NULL) { frame->size = pos - packet; memcpy(&frame->frame, packet, frame->size); if ((hardware->h_lport.p_lastframe == NULL) || (hardware->h_lport.p_lastframe->size != frame->size) || (memcmp(hardware->h_lport.p_lastframe->frame, frame->frame, - frame->size) != 0)) { + frame->size) != 0)) { free(hardware->h_lport.p_lastframe); hardware->h_lport.p_lastframe = frame; hardware->h_lport.p_lastchange = time(NULL); - } else free(frame); + } else + free(frame); } free(packet); @@ -540,42 +508,29 @@ toobig: free(packet); if (vlans > 0 && !without_vlans) { /* Retry without VLANs */ - return _lldp_send(global, - hardware, - c_id_subtype, - c_id, - c_id_len, - p_id_subtype, - p_id, - p_id_len, - shutdown, - 1); + return _lldp_send(global, hardware, c_id_subtype, c_id, c_id_len, + p_id_subtype, p_id, p_id_len, shutdown, 1); } - log_info("lldp", "Cannot send LLDP packet for %s, too big message", hardware->h_ifname); + log_info("lldp", "Cannot send LLDP packet for %s, too big message", + hardware->h_ifname); return E2BIG; } /* Send a shutdown LLDPDU. */ int -lldp_send_shutdown(struct lldpd *global, - struct lldpd_hardware *hardware) +lldp_send_shutdown(struct lldpd *global, struct lldpd_hardware *hardware) { if (hardware->h_lchassis_previous_id == NULL || hardware->h_lport_previous_id == NULL) return 0; - return _lldp_send(global, hardware, - hardware->h_lchassis_previous_id_subtype, - hardware->h_lchassis_previous_id, - hardware->h_lchassis_previous_id_len, - hardware->h_lport_previous_id_subtype, - hardware->h_lport_previous_id, - hardware->h_lport_previous_id_len, - 1, 0); + return _lldp_send(global, hardware, hardware->h_lchassis_previous_id_subtype, + hardware->h_lchassis_previous_id, hardware->h_lchassis_previous_id_len, + hardware->h_lport_previous_id_subtype, hardware->h_lport_previous_id, + hardware->h_lport_previous_id_len, 1, 0); } int -lldp_send(struct lldpd *global, - struct lldpd_hardware *hardware) +lldp_send(struct lldpd *global, struct lldpd_hardware *hardware) { struct lldpd_port *port = &hardware->h_lport; struct lldpd_chassis *chassis = port->p_chassis; @@ -588,27 +543,20 @@ lldp_send(struct lldpd *global, hardware->h_lchassis_previous_id_len != chassis->c_id_len || hardware->h_lport_previous_id_subtype != port->p_id_subtype || hardware->h_lport_previous_id_len != port->p_id_len || - memcmp(hardware->h_lchassis_previous_id, - chassis->c_id, chassis->c_id_len) || - memcmp(hardware->h_lport_previous_id, - port->p_id, port->p_id_len))) { - log_info("lldp", "MSAP has changed for port %s, sending a shutdown LLDPDU", + memcmp(hardware->h_lchassis_previous_id, chassis->c_id, + chassis->c_id_len) || + memcmp(hardware->h_lport_previous_id, port->p_id, port->p_id_len))) { + log_info("lldp", + "MSAP has changed for port %s, sending a shutdown LLDPDU", hardware->h_ifname); - if ((ret = lldp_send_shutdown(global, hardware)) != 0) - return ret; + if ((ret = lldp_send_shutdown(global, hardware)) != 0) return ret; } - log_debug("lldp", "send LLDP PDU to %s", - hardware->h_ifname); + log_debug("lldp", "send LLDP PDU to %s", hardware->h_ifname); - if ((ret = _lldp_send(global, hardware, - chassis->c_id_subtype, - chassis->c_id, - chassis->c_id_len, - port->p_id_subtype, - port->p_id, - port->p_id_len, - 0, 0)) != 0) + if ((ret = _lldp_send(global, hardware, chassis->c_id_subtype, chassis->c_id, + chassis->c_id_len, port->p_id_subtype, port->p_id, port->p_id_len, 0, + 0)) != 0) return ret; /* Record current chassis and port ID */ @@ -622,28 +570,28 @@ lldp_send(struct lldpd *global, hardware->h_lport_previous_id_subtype = port->p_id_subtype; hardware->h_lport_previous_id_len = port->p_id_len; if ((hardware->h_lport_previous_id = malloc(port->p_id_len)) != NULL) - memcpy(hardware->h_lport_previous_id, port->p_id, - port->p_id_len); + memcpy(hardware->h_lport_previous_id, port->p_id, port->p_id_len); return 0; } -#define CHECK_TLV_SIZE(x, name) \ - do { if (tlv_size < (x)) { \ - log_warnx("lldp", name " TLV too short received on %s", \ - hardware->h_ifname); \ - goto malformed; \ - } } while (0) -#define CHECK_TLV_MAX_SIZE(x, name) \ - do { if (tlv_size > (x)) { \ - log_warnx("lldp", name " TLV too large received on %s", \ - hardware->h_ifname); \ - goto malformed; \ - } } while (0) +#define CHECK_TLV_SIZE(x, name) \ + do { \ + if (tlv_size < (x)) { \ + log_warnx("lldp", name " TLV too short received on %s", hardware->h_ifname); \ + goto malformed; \ + } \ + } while (0) +#define CHECK_TLV_MAX_SIZE(x, name) \ + do { \ + if (tlv_size > (x)) { \ + log_warnx("lldp", name " TLV too large received on %s", hardware->h_ifname); \ + goto malformed; \ + } \ + } while (0) int -lldp_decode(struct lldpd *cfg, char *frame, int s, - struct lldpd_hardware *hardware, +lldp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardware, struct lldpd_chassis **newchassis, struct lldpd_port **newport) { struct lldpd_chassis *chassis; @@ -674,8 +622,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_custom *custom = NULL; #endif - log_debug("lldp", "receive LLDP PDU on %s", - hardware->h_ifname); + log_debug("lldp", "receive LLDP PDU on %s", hardware->h_ifname); if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) { log_warn("lldp", "failed to allocate remote chassis"); @@ -697,24 +644,26 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, #endif length = s; - pos = (u_int8_t*)frame; + pos = (u_int8_t *)frame; - if (length < 2*ETHER_ADDR_LEN + sizeof(u_int16_t)) { + if (length < 2 * ETHER_ADDR_LEN + sizeof(u_int16_t)) { log_warnx("lldp", "too short frame received on %s", hardware->h_ifname); goto malformed; } PEEK_BYTES(lldpaddr, ETHER_ADDR_LEN); - if (memcmp(lldpaddr, (const char [])LLDP_ADDR_NEAREST_BRIDGE, ETHER_ADDR_LEN) && - memcmp(lldpaddr, (const char [])LLDP_ADDR_NEAREST_NONTPMR_BRIDGE, ETHER_ADDR_LEN) && - memcmp(lldpaddr, (const char [])LLDP_ADDR_NEAREST_CUSTOMER_BRIDGE, ETHER_ADDR_LEN)) { - log_info("lldp", "frame not targeted at LLDP multicast address received on %s", + if (memcmp(lldpaddr, (const char[])LLDP_ADDR_NEAREST_BRIDGE, ETHER_ADDR_LEN) && + memcmp(lldpaddr, (const char[])LLDP_ADDR_NEAREST_NONTPMR_BRIDGE, + ETHER_ADDR_LEN) && + memcmp(lldpaddr, (const char[])LLDP_ADDR_NEAREST_CUSTOMER_BRIDGE, + ETHER_ADDR_LEN)) { + log_info("lldp", + "frame not targeted at LLDP multicast address received on %s", hardware->h_ifname); goto malformed; } - PEEK_DISCARD(ETHER_ADDR_LEN); /* Skip source address */ + PEEK_DISCARD(ETHER_ADDR_LEN); /* Skip source address */ if (PEEK_UINT16 != ETH_P_LLDP) { - log_info("lldp", "non LLDP frame received on %s", - hardware->h_ifname); + log_info("lldp", "non LLDP frame received on %s", hardware->h_ifname); goto malformed; } @@ -738,21 +687,24 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, switch (tlv_type) { case LLDP_TLV_CHASSIS_ID: if (tlv_count != 1) { - log_warnx("lldp", "first TLV should be a chassis ID on %s, not %d", + log_warnx("lldp", + "first TLV should be a chassis ID on %s, not %d", hardware->h_ifname, tlv_type); goto malformed; } break; case LLDP_TLV_PORT_ID: if (tlv_count != 2) { - log_warnx("lldp", "second TLV should be a port ID on %s, not %d", + log_warnx("lldp", + "second TLV should be a port ID on %s, not %d", hardware->h_ifname, tlv_type); goto malformed; } break; case LLDP_TLV_TTL: if (tlv_count != 3) { - log_warnx("lldp", "third TLV should be a TTL on %s, not %d", + log_warnx("lldp", + "third TLV should be a TTL on %s, not %d", hardware->h_ifname, tlv_type); goto malformed; } @@ -762,7 +714,8 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, switch (tlv_type) { case LLDP_TLV_END: if (tlv_size != 0) { - log_warnx("lldp", "lldp end received with size not null on %s", + log_warnx("lldp", + "lldp end received with size not null on %s", hardware->h_ifname); goto malformed; } @@ -777,12 +730,14 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, CHECK_TLV_MAX_SIZE(256, "Port/Chassis Id"); tlv_subtype = PEEK_UINT8; if ((tlv_subtype == 0) || (tlv_subtype > 7)) { - log_warnx("lldp", "unknown subtype for tlv id received on %s", + log_warnx("lldp", + "unknown subtype for tlv id received on %s", hardware->h_ifname); goto malformed; } if ((b = (char *)calloc(1, tlv_size - 1)) == NULL) { - log_warn("lldp", "unable to allocate memory for id tlv " + log_warn("lldp", + "unable to allocate memory for id tlv " "received on %s", hardware->h_ifname); goto malformed; @@ -790,7 +745,8 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, PEEK_BYTES(b, tlv_size - 1); if (tlv_type == LLDP_TLV_PORT_ID) { if (port->p_id != NULL) { - log_warnx("lldp", "Port ID TLV received twice on %s", + log_warnx("lldp", + "Port ID TLV received twice on %s", hardware->h_ifname); free(b); goto malformed; @@ -800,7 +756,8 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, port->p_id_len = tlv_size - 1; } else { if (chassis->c_id != NULL) { - log_warnx("lldp", "Chassis ID TLV received twice on %s", + log_warnx("lldp", + "Chassis ID TLV received twice on %s", hardware->h_ifname); free(b); goto malformed; @@ -829,7 +786,8 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, break; } if ((b = (char *)calloc(1, tlv_size + 1)) == NULL) { - log_warn("lldp", "unable to allocate memory for string tlv " + log_warn("lldp", + "unable to allocate memory for string tlv " "received on %s", hardware->h_ifname); goto malformed; @@ -877,8 +835,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, iface_number = PEEK_UINT32; af = lldpd_af_from_lldp_proto(addr_family); - if (af == LLDPD_AF_UNSPEC) - break; + if (af == LLDPD_AF_UNSPEC) break; if (iface_subtype == LLDP_MGMT_IFACE_IFINDEX) iface = iface_number; else @@ -886,11 +843,14 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, mgmt = lldpd_alloc_mgmt(af, addr_ptr, addr_length, iface); if (mgmt == NULL) { if (errno == ENOMEM) - log_warn("lldp", "unable to allocate memory " + log_warn("lldp", + "unable to allocate memory " "for management address"); else - log_warn("lldp", "too large management address " - "received on %s", hardware->h_ifname); + log_warn("lldp", + "too large management address " + "received on %s", + hardware->h_ifname); goto malformed; } TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries); @@ -909,8 +869,9 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, case LLDP_TLV_DOT1_VLANNAME: CHECK_TLV_SIZE(7, "VLAN"); if ((vlan = (struct lldpd_vlan *)calloc(1, - sizeof(struct lldpd_vlan))) == NULL) { - log_warn("lldp", "unable to alloc vlan " + sizeof(struct lldpd_vlan))) == NULL) { + log_warn("lldp", + "unable to alloc vlan " "structure for " "tlv received on %s", hardware->h_ifname); @@ -919,16 +880,17 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, vlan->v_vid = PEEK_UINT16; vlan_len = PEEK_UINT8; CHECK_TLV_SIZE(7 + vlan_len, "VLAN"); - if ((vlan->v_name = - (char *)calloc(1, vlan_len + 1)) == NULL) { - log_warn("lldp", "unable to alloc vlan name for " + if ((vlan->v_name = (char *)calloc(1, + vlan_len + 1)) == NULL) { + log_warn("lldp", + "unable to alloc vlan name for " "tlv received on %s", hardware->h_ifname); goto malformed; } PEEK_BYTES(vlan->v_name, vlan_len); - TAILQ_INSERT_TAIL(&port->p_vlans, - vlan, v_entries); + TAILQ_INSERT_TAIL(&port->p_vlans, vlan, + v_entries); vlan = NULL; break; case LLDP_TLV_DOT1_PVID: @@ -939,34 +901,36 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, CHECK_TLV_SIZE(7, "PPVID"); /* validation needed */ /* PPVID has to be unique if more than - one PPVID TLVs are received - + one PPVID TLVs are received - discard if duplicate */ - /* if support bit is not set and + /* if support bit is not set and enabled bit is set - PPVID TLV is considered error and discarded */ /* if PPVID > 4096 - bad and discard */ if ((ppvid = (struct lldpd_ppvid *)calloc(1, - sizeof(struct lldpd_ppvid))) == NULL) { - log_warn("lldp", "unable to alloc ppvid " + sizeof(struct lldpd_ppvid))) == NULL) { + log_warn("lldp", + "unable to alloc ppvid " "structure for " "tlv received on %s", hardware->h_ifname); goto malformed; } ppvid->p_cap_status = PEEK_UINT8; - ppvid->p_ppvid = PEEK_UINT16; - TAILQ_INSERT_TAIL(&port->p_ppvids, - ppvid, p_entries); + ppvid->p_ppvid = PEEK_UINT16; + TAILQ_INSERT_TAIL(&port->p_ppvids, ppvid, + p_entries); break; case LLDP_TLV_DOT1_PI: /* validation needed */ - /* PI has to be unique if more than + /* PI has to be unique if more than one PI TLVs are received - discard if duplicate ?? */ CHECK_TLV_SIZE(5, "PI"); if ((pi = (struct lldpd_pi *)calloc(1, - sizeof(struct lldpd_pi))) == NULL) { - log_warn("lldp", "unable to alloc PI " + sizeof(struct lldpd_pi))) == NULL) { + log_warn("lldp", + "unable to alloc PI " "structure for " "tlv received on %s", hardware->h_ifname); @@ -974,16 +938,16 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, } pi->p_pi_len = PEEK_UINT8; CHECK_TLV_SIZE(5 + pi->p_pi_len, "PI"); - if ((pi->p_pi = - (char *)calloc(1, pi->p_pi_len)) == NULL) { - log_warn("lldp", "unable to alloc pid name for " + if ((pi->p_pi = (char *)calloc(1, + pi->p_pi_len)) == NULL) { + log_warn("lldp", + "unable to alloc pid name for " "tlv received on %s", hardware->h_ifname); goto malformed; } PEEK_BYTES(pi->p_pi, pi->p_pi_len); - TAILQ_INSERT_TAIL(&port->p_pids, - pi, p_entries); + TAILQ_INSERT_TAIL(&port->p_pids, pi, p_entries); pi = NULL; break; default: @@ -1004,8 +968,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, (port->p_macphy.autoneg_support & 0x2) >> 1; port->p_macphy.autoneg_support = port->p_macphy.autoneg_support & 0x1; - port->p_macphy.autoneg_advertised = - PEEK_UINT16; + port->p_macphy.autoneg_advertised = PEEK_UINT16; port->p_macphy.mau_type = PEEK_UINT16; break; case LLDP_TLV_DOT3_LA: @@ -1021,26 +984,31 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, CHECK_TLV_SIZE(7, "Power"); port->p_power.devicetype = PEEK_UINT8; port->p_power.supported = - (port->p_power.devicetype & 0x2) >> 1; + (port->p_power.devicetype & 0x2) >> 1; port->p_power.enabled = - (port->p_power.devicetype & 0x4) >> 2; + (port->p_power.devicetype & 0x4) >> 2; port->p_power.paircontrol = - (port->p_power.devicetype & 0x8) >> 3; + (port->p_power.devicetype & 0x8) >> 3; port->p_power.devicetype = - (port->p_power.devicetype & 0x1)? - LLDP_DOT3_POWER_PSE:LLDP_DOT3_POWER_PD; + (port->p_power.devicetype & 0x1) ? + LLDP_DOT3_POWER_PSE : + LLDP_DOT3_POWER_PD; port->p_power.pairs = PEEK_UINT8; port->p_power.class = PEEK_UINT8; /* 802.3at? */ if (tlv_size >= 12) { port->p_power.powertype = PEEK_UINT8; port->p_power.source = - (port->p_power.powertype & (1<<5 | 1<<4)) >> 4; + (port->p_power.powertype & + (1 << 5 | 1 << 4)) >> + 4; port->p_power.priority = - (port->p_power.powertype & (1<<1 | 1<<0)); + (port->p_power.powertype & + (1 << 1 | 1 << 0)); port->p_power.powertype = - (port->p_power.powertype & (1<<7))? - LLDP_DOT3_POWER_8023AT_TYPE1: + (port->p_power.powertype & + (1 << 7)) ? + LLDP_DOT3_POWER_8023AT_TYPE1 : LLDP_DOT3_POWER_8023AT_TYPE2; port->p_power.requested = PEEK_UINT16; port->p_power.allocated = PEEK_UINT16; @@ -1055,22 +1023,34 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, port->p_power.allocated_b = PEEK_UINT16; port->p_power.pse_status = PEEK_UINT16; port->p_power.pd_status = - (port->p_power.pse_status & (1<<13 | 1<<12)) >> 12; + (port->p_power.pse_status & + (1 << 13 | 1 << 12)) >> + 12; port->p_power.pse_pairs_ext = - (port->p_power.pse_status & (1<<11 | 1<<10)) >> 10; + (port->p_power.pse_status & + (1 << 11 | 1 << 10)) >> + 10; port->p_power.class_a = - (port->p_power.pse_status & (1<<9 | 1<<8 | 1<<7)) >> 7; + (port->p_power.pse_status & + (1 << 9 | 1 << 8 | 1 << 7)) >> + 7; port->p_power.class_b = - (port->p_power.pse_status & (1<<6 | 1<<5 | 1<<4)) >> 4; + (port->p_power.pse_status & + (1 << 6 | 1 << 5 | 1 << 4)) >> + 4; port->p_power.class_ext = (port->p_power.pse_status & 0xf); port->p_power.pse_status = - (port->p_power.pse_status & (1<<15 | 1<<14)) >> 14; + (port->p_power.pse_status & + (1 << 15 | 1 << 14)) >> + 14; port->p_power.type_ext = PEEK_UINT8; port->p_power.pd_load = (port->p_power.type_ext & 0x1); port->p_power.type_ext = - ((port->p_power.type_ext & (1<<3 | 1<<2 | 1<<1)) + 1); + ((port->p_power.type_ext & + (1 << 3 | 1 << 2 | 1 << 1)) + + 1); port->p_power.pse_max = PEEK_UINT16; } else { port->p_power.type_ext = @@ -1096,18 +1076,17 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, CHECK_TLV_SIZE(7, "LLDP-MED capabilities"); chassis->c_med_cap_available = PEEK_UINT16; chassis->c_med_type = PEEK_UINT8; - port->p_med_cap_enabled |= - LLDP_MED_CAP_CAP; + port->p_med_cap_enabled |= LLDP_MED_CAP_CAP; break; case LLDP_TLV_MED_POLICY: CHECK_TLV_SIZE(8, "LLDP-MED policy"); policy = PEEK_UINT32; if (((policy >> 24) < 1) || ((policy >> 24) > LLDP_MED_APPTYPE_LAST)) { - log_info("lldp", "unknown policy field %d " + log_info("lldp", + "unknown policy field %d " "received on %s", - policy, - hardware->h_ifname); + policy, hardware->h_ifname); break; } port->p_med_policy[(policy >> 24) - 1].type = @@ -1118,37 +1097,41 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, ((policy & 0x400000) != 0); port->p_med_policy[(policy >> 24) - 1].vid = (policy & 0x001FFE00) >> 9; - port->p_med_policy[(policy >> 24) - 1].priority = - (policy & 0x1C0) >> 6; + port->p_med_policy[(policy >> 24) - 1] + .priority = (policy & 0x1C0) >> 6; port->p_med_policy[(policy >> 24) - 1].dscp = policy & 0x3F; - port->p_med_cap_enabled |= - LLDP_MED_CAP_POLICY; + port->p_med_cap_enabled |= LLDP_MED_CAP_POLICY; break; case LLDP_TLV_MED_LOCATION: CHECK_TLV_SIZE(5, "LLDP-MED Location"); loctype = PEEK_UINT8; if ((loctype < 1) || (loctype > LLDP_MED_LOCFORMAT_LAST)) { - log_info("lldp", "unknown location type " + log_info("lldp", + "unknown location type " "received on %s", hardware->h_ifname); break; } free(port->p_med_location[loctype - 1].data); if ((port->p_med_location[loctype - 1].data = - (char*)malloc(tlv_size - 5)) == NULL) { - log_warn("lldp", "unable to allocate memory " + (char *)malloc(tlv_size - 5)) == + NULL) { + log_warn("lldp", + "unable to allocate memory " "for LLDP-MED location for " "frame received on %s", hardware->h_ifname); goto malformed; } - PEEK_BYTES(port->p_med_location[loctype - 1].data, + PEEK_BYTES( + port->p_med_location[loctype - 1].data, tlv_size - 5); port->p_med_location[loctype - 1].data_len = tlv_size - 5; - port->p_med_location[loctype - 1].format = loctype; + port->p_med_location[loctype - 1].format = + loctype; port->p_med_cap_enabled |= LLDP_MED_CAP_LOCATION; break; @@ -1157,7 +1140,8 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, power = PEEK_UINT8; switch (power & 0xC0) { case 0x0: - port->p_med_power.devicetype = LLDP_MED_POW_TYPE_PSE; + port->p_med_power.devicetype = + LLDP_MED_POW_TYPE_PSE; port->p_med_cap_enabled |= LLDP_MED_CAP_MDI_PSE; switch (power & 0x30) { @@ -1179,7 +1163,8 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, } break; case 0x40: - port->p_med_power.devicetype = LLDP_MED_POW_TYPE_PD; + port->p_med_power.devicetype = + LLDP_MED_POW_TYPE_PD; port->p_med_cap_enabled |= LLDP_MED_CAP_MDI_PD; switch (power & 0x30) { @@ -1222,9 +1207,10 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, if (tlv_size <= 4) b = NULL; else { - if ((b = (char*)malloc(tlv_size - 3)) == - NULL) { - log_warn("lldp", "unable to allocate " + if ((b = (char *)malloc( + tlv_size - 3)) == NULL) { + log_warn("lldp", + "unable to allocate " "memory for LLDP-MED " "inventory for frame " "received on %s", @@ -1268,8 +1254,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, free(b); break; } - port->p_med_cap_enabled |= - LLDP_MED_CAP_IV; + port->p_med_cap_enabled |= LLDP_MED_CAP_IV; break; default: /* Unknown LLDP MED, ignore it */ @@ -1277,19 +1262,21 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, } #endif /* ENABLE_LLDPMED */ } else if (memcmp(dcbx, orgid, sizeof(orgid)) == 0) { - log_debug("lldp", "unsupported DCBX tlv received on %s - ignore", + log_debug("lldp", + "unsupported DCBX tlv received on %s - ignore", hardware->h_ifname); unrecognized = 1; } else { - log_debug("lldp", "unknown org tlv [%02x:%02x:%02x] received on %s", - orgid[0], orgid[1], orgid[2], - hardware->h_ifname); + log_debug("lldp", + "unknown org tlv [%02x:%02x:%02x] received on %s", + orgid[0], orgid[1], orgid[2], hardware->h_ifname); unrecognized = 1; } if (unrecognized) { hardware->h_rx_unrecognized_cnt++; #ifdef ENABLE_CUSTOM - custom = (struct lldpd_custom*)calloc(1, sizeof(struct lldpd_custom)); + custom = (struct lldpd_custom *)calloc(1, + sizeof(struct lldpd_custom)); if (!custom) { log_warn("lldp", "unable to allocate memory for custom TLV"); @@ -1305,7 +1292,8 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, "unable to allocate memory for custom TLV data"); goto malformed; } - PEEK_BYTES(custom->oui_info, custom->oui_info_len); + PEEK_BYTES(custom->oui_info, + custom->oui_info_len); } TAILQ_INSERT_TAIL(&port->p_custom_list, custom, next); custom = NULL; @@ -1313,8 +1301,8 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, } break; default: - log_warnx("lldp", "unknown tlv (%d) received on %s", - tlv_type, hardware->h_ifname); + log_warnx("lldp", "unknown tlv (%d) received on %s", tlv_type, + hardware->h_ifname); hardware->h_rx_unrecognized_cnt++; break; } @@ -1326,11 +1314,10 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, } /* Some random check */ - if ((chassis->c_id == NULL) || - (port->p_id == NULL) || - (!ttl_received) || + if ((chassis->c_id == NULL) || (port->p_id == NULL) || (!ttl_received) || (gotend == 0)) { - log_warnx("lldp", "some mandatory tlv are missing for frame received on %s", + log_warnx("lldp", + "some mandatory tlv are missing for frame received on %s", hardware->h_ifname); goto malformed; } diff --git a/src/daemon/protocols/sonmp.c b/src/daemon/protocols/sonmp.c index f8f12469..9f4c4909 100644 --- a/src/daemon/protocols/sonmp.c +++ b/src/daemon/protocols/sonmp.c @@ -20,169 +20,168 @@ #ifdef ENABLE_SONMP -#include -#include -#include -#include +# include +# include +# include +# include static struct sonmp_chassis sonmp_chassis_types[] = { - {1, "unknown (via SONMP)"}, - {2, "Nortel 3000"}, - {3, "Nortel 3030"}, - {4, "Nortel 2310"}, - {5, "Nortel 2810"}, - {6, "Nortel 2912"}, - {7, "Nortel 2914"}, - {8, "Nortel 271x"}, - {9, "Nortel 2813"}, - {10, "Nortel 2814"}, - {11, "Nortel 2915"}, - {12, "Nortel 5000"}, - {13, "Nortel 2813SA"}, - {14, "Nortel 2814SA"}, - {15, "Nortel 810M"}, - {16, "Nortel EtherCell"}, - {17, "Nortel 5005"}, - {18, "Alcatel Ethernet workgroup conc."}, - {20, "Nortel 2715SA"}, - {21, "Nortel 2486"}, - {22, "Nortel 28000 series"}, - {23, "Nortel 23000 series"}, - {24, "Nortel 5DN00x series"}, - {25, "BayStack Ethernet"}, - {26, "Nortel 23100 series"}, - {27, "Nortel 100Base-T Hub"}, - {28, "Nortel 3000 Fast Ethernet"}, - {29, "Nortel Orion switch"}, - {30, "unknown"}, - {31, "Nortel DDS "}, - {32, "Nortel Centillion"}, - {33, "Nortel Centillion"}, - {34, "Nortel Centillion"}, - {35, "BayStack 301"}, - {36, "BayStack TokenRing Hub"}, - {37, "Nortel FVC Multimedia Switch"}, - {38, "Nortel Switch Node"}, - {39, "BayStack 302 Switch"}, - {40, "BayStack 350 Switch"}, - {41, "BayStack 150 Ethernet Hub"}, - {42, "Nortel Centillion 50N switch"}, - {43, "Nortel Centillion 50T switch"}, - {44, "BayStack 303 and 304 Switches"}, - {45, "BayStack 200 Ethernet Hub"}, - {46, "BayStack 250 10/100 Ethernet Hub"}, - {48, "BayStack 450 10/100/1000 Switches"}, - {49, "BayStack 410 10/100 Switches"}, - {50, "Nortel Ethernet Routing 1200 L3 Switch"}, - {51, "Nortel Ethernet Routing 1250 L3 Switch"}, - {52, "Nortel Ethernet Routing 1100 L3 Switch"}, - {53, "Nortel Ethernet Routing 1150 L3 Switch"}, - {54, "Nortel Ethernet Routing 1050 L3 Switch"}, - {55, "Nortel Ethernet Routing 1051 L3 Switch"}, - {56, "Nortel Ethernet Routing 8610 L3 Switch"}, - {57, "Nortel Ethernet Routing 8606 L3 Switch"}, - {58, "Nortel Ethernet Routing Switch 8010"}, - {59, "Nortel Ethernet Routing Switch 8006"}, - {60, "BayStack 670 wireless access point"}, - {61, "Nortel Ethernet Routing Switch 740 "}, - {62, "Nortel Ethernet Routing Switch 750 "}, - {63, "Nortel Ethernet Routing Switch 790"}, - {64, "Nortel Business Policy Switch 2000 10/100 Switches"}, - {65, "Nortel Ethernet Routing 8110 L2 Switch"}, - {66, "Nortel Ethernet Routing 8106 L2 Switch"}, - {67, "BayStack 3580 Gig Switch"}, - {68, "BayStack 10 Power Supply Unit"}, - {69, "BayStack 420 10/100 Switch"}, - {70, "OPTera Metro 1200 Ethernet Service Module"}, - {71, "Nortel Ethernet Routing Switch 8010co"}, - {72, "Nortel Ethernet Routing 8610co L3 switch"}, - {73, "Nortel Ethernet Routing 8110co L2 switch"}, - {74, "Nortel Ethernet Routing 8003"}, - {75, "Nortel Ethernet Routing 8603 L3 switch"}, - {76, "Nortel Ethernet Routing 8103 L2 switch"}, - {77, "BayStack 380 10/100/1000 Switch"}, - {78, "Nortel Ethernet Switch 470-48T"}, - {79, "OPTera Metro 1450 Ethernet Service Module"}, - {80, "OPTera Metro 1400 Ethernet Service Module"}, - {81, "Alteon Switch Family"}, - {82, "Ethernet Switch 460-24T-PWR"}, - {83, "OPTera Metro 8010 OPM L2 Switch"}, - {84, "OPTera Metro 8010co OPM L2 Switch"}, - {85, "OPTera Metro 8006 OPM L2 Switch"}, - {86, "OPTera Metro 8003 OPM L2 Switch"}, - {87, "Alteon 180e"}, - {88, "Alteon AD3"}, - {89, "Alteon 184"}, - {90, "Alteon AD4"}, - {91, "Nortel Ethernet Routing 1424 L3 switch"}, - {92, "Nortel Ethernet Routing 1648 L3 switch"}, - {93, "Nortel Ethernet Routing 1612 L3 switch"}, - {94, "Nortel Ethernet Routing 1624 L3 switch "}, - {95, "BayStack 380-24F Fiber 1000 Switch"}, - {96, "Nortel Ethernet Routing Switch 5510-24T"}, - {97, "Nortel Ethernet Routing Switch 5510-48T"}, - {98, "Nortel Ethernet Switch 470-24T"}, - {99, "Nortel Networks Wireless LAN Access Point 2220"}, - {100, "Ethernet Routing RBS 2402 L3 switch"}, - {101, "Alteon Application Switch 2424 "}, - {102, "Alteon Application Switch 2224 "}, - {103, "Alteon Application Switch 2208 "}, - {104, "Alteon Application Switch 2216"}, - {105, "Alteon Application Switch 3408"}, - {106, "Alteon Application Switch 3416"}, - {107, "Nortel Networks Wireless LAN SecuritySwitch 2250"}, - {108, "Ethernet Switch 425-48T"}, - {109, "Ethernet Switch 425-24T"}, - {110, "Nortel Networks Wireless LAN Access Point 2221"}, - {111, "Nortel Metro Ethernet Service Unit 24-T SPF switch"}, - {112, "Nortel Metro Ethernet Service Unit 24-T LX DC switch"}, - {113, "Nortel Ethernet Routing Switch 8300 10-slot chassis"}, - {114, "Nortel Ethernet Routing Switch 8300 6-slot chassis"}, - {115, "Nortel Ethernet Routing Switch 5520-24T-PWR"}, - {116, "Nortel Ethernet Routing Switch 5520-48T-PWR"}, - {117, "Nortel Networks VPN Gateway 3050"}, - {118, "Alteon SSL 310 10/100"}, - {119, "Alteon SSL 310 10/100 Fiber"}, - {120, "Alteon SSL 310 10/100 FIPS"}, - {121, "Alteon SSL 410 10/100/1000"}, - {122, "Alteon SSL 410 10/100/1000 Fiber"}, - {123, "Alteon Application Switch 2424-SSL"}, - {124, "Nortel Ethernet Switch 325-24T"}, - {125, "Nortel Ethernet Switch 325-24G"}, - {126, "Nortel Networks Wireless LAN Access Point 2225"}, - {127, "Nortel Networks Wireless LAN SecuritySwitch 2270"}, - {128, "Nortel 24-port Ethernet Switch 470-24T-PWR"}, - {129, "Nortel 48-port Ethernet Switch 470-48T-PWR"}, - {130, "Nortel Ethernet Routing Switch 5530-24TFD"}, - {131, "Nortel Ethernet Switch 3510-24T"}, - {132, "Nortel Metro Ethernet Service Unit 12G AC L3 switch"}, - {133, "Nortel Metro Ethernet Service Unit 12G DC L3 switch"}, - {134, "Nortel Secure Access Switch"}, - {135, "Networks VPN Gateway 3070"}, - {136, "OPTera Metro 3500"}, - {137, "SMB BES 1010 24T"}, - {138, "SMB BES 1010 48T"}, - {139, "SMB BES 1020 24T PWR"}, - {140, "SMB BES 1020 48T PWR"}, - {141, "SMB BES 2010 24T"}, - {142, "SMB BES 2010 48T"}, - {143, "SMB BES 2020 24T PWR"}, - {144, "SMB BES 2020 48T PWR"}, - {145, "SMB BES 110 24T"}, - {146, "SMB BES 110 48T"}, - {147, "SMB BES 120 24T PWR"}, - {148, "SMB BES 120 48T PWR"}, - {149, "SMB BES 210 24T"}, - {150, "SMB BES 210 48T"}, - {151, "SMB BES 220 24T PWR"}, - {152, "SMB BES 220 48T PWR"}, - {153, "OME 6500"}, - {0, "unknown (via SONMP)"}, + { 1, "unknown (via SONMP)" }, + { 2, "Nortel 3000" }, + { 3, "Nortel 3030" }, + { 4, "Nortel 2310" }, + { 5, "Nortel 2810" }, + { 6, "Nortel 2912" }, + { 7, "Nortel 2914" }, + { 8, "Nortel 271x" }, + { 9, "Nortel 2813" }, + { 10, "Nortel 2814" }, + { 11, "Nortel 2915" }, + { 12, "Nortel 5000" }, + { 13, "Nortel 2813SA" }, + { 14, "Nortel 2814SA" }, + { 15, "Nortel 810M" }, + { 16, "Nortel EtherCell" }, + { 17, "Nortel 5005" }, + { 18, "Alcatel Ethernet workgroup conc." }, + { 20, "Nortel 2715SA" }, + { 21, "Nortel 2486" }, + { 22, "Nortel 28000 series" }, + { 23, "Nortel 23000 series" }, + { 24, "Nortel 5DN00x series" }, + { 25, "BayStack Ethernet" }, + { 26, "Nortel 23100 series" }, + { 27, "Nortel 100Base-T Hub" }, + { 28, "Nortel 3000 Fast Ethernet" }, + { 29, "Nortel Orion switch" }, + { 30, "unknown" }, + { 31, "Nortel DDS " }, + { 32, "Nortel Centillion" }, + { 33, "Nortel Centillion" }, + { 34, "Nortel Centillion" }, + { 35, "BayStack 301" }, + { 36, "BayStack TokenRing Hub" }, + { 37, "Nortel FVC Multimedia Switch" }, + { 38, "Nortel Switch Node" }, + { 39, "BayStack 302 Switch" }, + { 40, "BayStack 350 Switch" }, + { 41, "BayStack 150 Ethernet Hub" }, + { 42, "Nortel Centillion 50N switch" }, + { 43, "Nortel Centillion 50T switch" }, + { 44, "BayStack 303 and 304 Switches" }, + { 45, "BayStack 200 Ethernet Hub" }, + { 46, "BayStack 250 10/100 Ethernet Hub" }, + { 48, "BayStack 450 10/100/1000 Switches" }, + { 49, "BayStack 410 10/100 Switches" }, + { 50, "Nortel Ethernet Routing 1200 L3 Switch" }, + { 51, "Nortel Ethernet Routing 1250 L3 Switch" }, + { 52, "Nortel Ethernet Routing 1100 L3 Switch" }, + { 53, "Nortel Ethernet Routing 1150 L3 Switch" }, + { 54, "Nortel Ethernet Routing 1050 L3 Switch" }, + { 55, "Nortel Ethernet Routing 1051 L3 Switch" }, + { 56, "Nortel Ethernet Routing 8610 L3 Switch" }, + { 57, "Nortel Ethernet Routing 8606 L3 Switch" }, + { 58, "Nortel Ethernet Routing Switch 8010" }, + { 59, "Nortel Ethernet Routing Switch 8006" }, + { 60, "BayStack 670 wireless access point" }, + { 61, "Nortel Ethernet Routing Switch 740 " }, + { 62, "Nortel Ethernet Routing Switch 750 " }, + { 63, "Nortel Ethernet Routing Switch 790" }, + { 64, "Nortel Business Policy Switch 2000 10/100 Switches" }, + { 65, "Nortel Ethernet Routing 8110 L2 Switch" }, + { 66, "Nortel Ethernet Routing 8106 L2 Switch" }, + { 67, "BayStack 3580 Gig Switch" }, + { 68, "BayStack 10 Power Supply Unit" }, + { 69, "BayStack 420 10/100 Switch" }, + { 70, "OPTera Metro 1200 Ethernet Service Module" }, + { 71, "Nortel Ethernet Routing Switch 8010co" }, + { 72, "Nortel Ethernet Routing 8610co L3 switch" }, + { 73, "Nortel Ethernet Routing 8110co L2 switch" }, + { 74, "Nortel Ethernet Routing 8003" }, + { 75, "Nortel Ethernet Routing 8603 L3 switch" }, + { 76, "Nortel Ethernet Routing 8103 L2 switch" }, + { 77, "BayStack 380 10/100/1000 Switch" }, + { 78, "Nortel Ethernet Switch 470-48T" }, + { 79, "OPTera Metro 1450 Ethernet Service Module" }, + { 80, "OPTera Metro 1400 Ethernet Service Module" }, + { 81, "Alteon Switch Family" }, + { 82, "Ethernet Switch 460-24T-PWR" }, + { 83, "OPTera Metro 8010 OPM L2 Switch" }, + { 84, "OPTera Metro 8010co OPM L2 Switch" }, + { 85, "OPTera Metro 8006 OPM L2 Switch" }, + { 86, "OPTera Metro 8003 OPM L2 Switch" }, + { 87, "Alteon 180e" }, + { 88, "Alteon AD3" }, + { 89, "Alteon 184" }, + { 90, "Alteon AD4" }, + { 91, "Nortel Ethernet Routing 1424 L3 switch" }, + { 92, "Nortel Ethernet Routing 1648 L3 switch" }, + { 93, "Nortel Ethernet Routing 1612 L3 switch" }, + { 94, "Nortel Ethernet Routing 1624 L3 switch " }, + { 95, "BayStack 380-24F Fiber 1000 Switch" }, + { 96, "Nortel Ethernet Routing Switch 5510-24T" }, + { 97, "Nortel Ethernet Routing Switch 5510-48T" }, + { 98, "Nortel Ethernet Switch 470-24T" }, + { 99, "Nortel Networks Wireless LAN Access Point 2220" }, + { 100, "Ethernet Routing RBS 2402 L3 switch" }, + { 101, "Alteon Application Switch 2424 " }, + { 102, "Alteon Application Switch 2224 " }, + { 103, "Alteon Application Switch 2208 " }, + { 104, "Alteon Application Switch 2216" }, + { 105, "Alteon Application Switch 3408" }, + { 106, "Alteon Application Switch 3416" }, + { 107, "Nortel Networks Wireless LAN SecuritySwitch 2250" }, + { 108, "Ethernet Switch 425-48T" }, + { 109, "Ethernet Switch 425-24T" }, + { 110, "Nortel Networks Wireless LAN Access Point 2221" }, + { 111, "Nortel Metro Ethernet Service Unit 24-T SPF switch" }, + { 112, "Nortel Metro Ethernet Service Unit 24-T LX DC switch" }, + { 113, "Nortel Ethernet Routing Switch 8300 10-slot chassis" }, + { 114, "Nortel Ethernet Routing Switch 8300 6-slot chassis" }, + { 115, "Nortel Ethernet Routing Switch 5520-24T-PWR" }, + { 116, "Nortel Ethernet Routing Switch 5520-48T-PWR" }, + { 117, "Nortel Networks VPN Gateway 3050" }, + { 118, "Alteon SSL 310 10/100" }, + { 119, "Alteon SSL 310 10/100 Fiber" }, + { 120, "Alteon SSL 310 10/100 FIPS" }, + { 121, "Alteon SSL 410 10/100/1000" }, + { 122, "Alteon SSL 410 10/100/1000 Fiber" }, + { 123, "Alteon Application Switch 2424-SSL" }, + { 124, "Nortel Ethernet Switch 325-24T" }, + { 125, "Nortel Ethernet Switch 325-24G" }, + { 126, "Nortel Networks Wireless LAN Access Point 2225" }, + { 127, "Nortel Networks Wireless LAN SecuritySwitch 2270" }, + { 128, "Nortel 24-port Ethernet Switch 470-24T-PWR" }, + { 129, "Nortel 48-port Ethernet Switch 470-48T-PWR" }, + { 130, "Nortel Ethernet Routing Switch 5530-24TFD" }, + { 131, "Nortel Ethernet Switch 3510-24T" }, + { 132, "Nortel Metro Ethernet Service Unit 12G AC L3 switch" }, + { 133, "Nortel Metro Ethernet Service Unit 12G DC L3 switch" }, + { 134, "Nortel Secure Access Switch" }, + { 135, "Networks VPN Gateway 3070" }, + { 136, "OPTera Metro 3500" }, + { 137, "SMB BES 1010 24T" }, + { 138, "SMB BES 1010 48T" }, + { 139, "SMB BES 1020 24T PWR" }, + { 140, "SMB BES 1020 48T PWR" }, + { 141, "SMB BES 2010 24T" }, + { 142, "SMB BES 2010 48T" }, + { 143, "SMB BES 2020 24T PWR" }, + { 144, "SMB BES 2020 48T PWR" }, + { 145, "SMB BES 110 24T" }, + { 146, "SMB BES 110 48T" }, + { 147, "SMB BES 120 24T PWR" }, + { 148, "SMB BES 120 48T PWR" }, + { 149, "SMB BES 210 24T" }, + { 150, "SMB BES 210 48T" }, + { 151, "SMB BES 220 24T PWR" }, + { 152, "SMB BES 220 48T PWR" }, + { 153, "OME 6500" }, + { 0, "unknown (via SONMP)" }, }; int -sonmp_send(struct lldpd *global, - struct lldpd_hardware *hardware) +sonmp_send(struct lldpd *global, struct lldpd_hardware *hardware) { const u_int8_t mcastaddr[] = SONMP_MULTICAST_ADDR; const u_int8_t llcorg[] = LLC_ORG_NORTEL; @@ -192,41 +191,38 @@ sonmp_send(struct lldpd *global, int length; struct in_addr address; - log_debug("sonmp", "send SONMP PDU to %s", - hardware->h_ifname); + log_debug("sonmp", "send SONMP PDU to %s", hardware->h_ifname); chassis = hardware->h_lport.p_chassis; length = hardware->h_mtu; - if ((packet = (u_int8_t*)calloc(1, length)) == NULL) - return ENOMEM; + if ((packet = (u_int8_t *)calloc(1, length)) == NULL) return ENOMEM; pos = packet; /* Ethernet header */ if (!( - /* SONMP multicast address as target */ - POKE_BYTES(mcastaddr, sizeof(mcastaddr)) && - /* Source MAC addresss */ - POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) && - /* SONMP frame is of fixed size */ - POKE_UINT16(SONMP_SIZE))) + /* SONMP multicast address as target */ + POKE_BYTES(mcastaddr, sizeof(mcastaddr)) && + /* Source MAC addresss */ + POKE_BYTES(&hardware->h_lladdr, ETHER_ADDR_LEN) && + /* SONMP frame is of fixed size */ + POKE_UINT16(SONMP_SIZE))) goto toobig; /* LLC header */ if (!( - /* DSAP and SSAP */ - POKE_UINT8(0xaa) && POKE_UINT8(0xaa) && - /* Control field */ - POKE_UINT8(0x03) && - /* ORG */ - POKE_BYTES(llcorg, sizeof(llcorg)) && - POKE_SAVE(pos_pid) && /* We will modify PID later to - create a new frame */ - POKE_UINT16(LLC_PID_SONMP_HELLO))) + /* DSAP and SSAP */ + POKE_UINT8(0xaa) && POKE_UINT8(0xaa) && + /* Control field */ + POKE_UINT8(0x03) && + /* ORG */ + POKE_BYTES(llcorg, sizeof(llcorg)) && + POKE_SAVE(pos_pid) && /* We will modify PID later to + create a new frame */ + POKE_UINT16(LLC_PID_SONMP_HELLO))) goto toobig; - address.s_addr = htonl(INADDR_ANY); - TAILQ_FOREACH(mgmt, &chassis->c_mgmt, m_entries) { + TAILQ_FOREACH (mgmt, &chassis->c_mgmt, m_entries) { if (mgmt->m_family == LLDPD_AF_IPV4) { address.s_addr = mgmt->m_addr.inet.s_addr; } @@ -235,37 +231,37 @@ sonmp_send(struct lldpd *global, /* SONMP */ if (!( - /* Our IP address */ - POKE_BYTES(&address, sizeof(struct in_addr)) && - /* Segment on three bytes, we don't have slots, so we - skip the first two bytes */ - POKE_UINT16(0) && - POKE_UINT8(hardware->h_ifindex) && - POKE_UINT8(1) && /* Chassis: Other */ - POKE_UINT8(12) && /* Back: Ethernet, Fast Ethernet and Gigabit */ - POKE_UINT8(SONMP_TOPOLOGY_NEW) && /* Should work. We have no state */ - POKE_UINT8(1) && /* Links: Dunno what it is */ - POKE_SAVE(end))) + /* Our IP address */ + POKE_BYTES(&address, sizeof(struct in_addr)) && + /* Segment on three bytes, we don't have slots, so we + skip the first two bytes */ + POKE_UINT16(0) && POKE_UINT8(hardware->h_ifindex) && + POKE_UINT8(1) && /* Chassis: Other */ + POKE_UINT8(12) && /* Back: Ethernet, Fast Ethernet and Gigabit */ + POKE_UINT8(SONMP_TOPOLOGY_NEW) && /* Should work. We have no state */ + POKE_UINT8(1) && /* Links: Dunno what it is */ + POKE_SAVE(end))) goto toobig; - - if (interfaces_send_helper(global, hardware, - (char *)packet, end - packet) == -1) { + + if (interfaces_send_helper(global, hardware, (char *)packet, end - packet) == + -1) { log_warn("sonmp", "unable to send packet on real device for %s", - hardware->h_ifname); + hardware->h_ifname); free(packet); return ENETDOWN; } - POKE_RESTORE(pos_pid); /* Modify LLC PID */ + POKE_RESTORE(pos_pid); /* Modify LLC PID */ (void)POKE_UINT16(LLC_PID_SONMP_FLATNET); - POKE_RESTORE(packet); /* Go to the beginning */ + POKE_RESTORE(packet); /* Go to the beginning */ PEEK_DISCARD(ETHER_ADDR_LEN - 1); /* Modify the last byte of the MAC address */ (void)POKE_UINT8(1); - if (interfaces_send_helper(global, hardware, - (char *)packet, end - packet) == -1) { - log_warn("sonmp", "unable to send second SONMP packet on real device for %s", - hardware->h_ifname); + if (interfaces_send_helper(global, hardware, (char *)packet, end - packet) == + -1) { + log_warn("sonmp", + "unable to send second SONMP packet on real device for %s", + hardware->h_ifname); free(packet); return ENETDOWN; } @@ -273,14 +269,13 @@ sonmp_send(struct lldpd *global, free(packet); hardware->h_tx_cnt++; return 0; - toobig: +toobig: free(packet); return -1; } int -sonmp_decode(struct lldpd *cfg, char *frame, int s, - struct lldpd_hardware *hardware, +sonmp_decode(struct lldpd *cfg, char *frame, int s, struct lldpd_hardware *hardware, struct lldpd_chassis **newchassis, struct lldpd_port **newport) { const u_int8_t mcastaddr[] = SONMP_MULTICAST_ADDR; @@ -292,8 +287,7 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, u_int8_t seg[3], rchassis; struct in_addr address; - log_debug("sonmp", "decode SONMP PDU from %s", - hardware->h_ifname); + log_debug("sonmp", "decode SONMP PDU from %s", hardware->h_ifname); if ((chassis = calloc(1, sizeof(struct lldpd_chassis))) == NULL) { log_warn("sonmp", "failed to allocate remote chassis"); @@ -305,14 +299,15 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, free(chassis); return -1; } -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 TAILQ_INIT(&port->p_vlans); -#endif +# endif length = s; - pos = (u_int8_t*)frame; - if (length < SONMP_SIZE + 2*ETHER_ADDR_LEN + sizeof(u_int16_t)) { - log_warnx("sonmp", "too short SONMP frame received on %s", hardware->h_ifname); + pos = (u_int8_t *)frame; + if (length < SONMP_SIZE + 2 * ETHER_ADDR_LEN + sizeof(u_int16_t)) { + log_warnx("sonmp", "too short SONMP frame received on %s", + hardware->h_ifname); goto malformed; } if (PEEK_CMP(mcastaddr, sizeof(mcastaddr)) != 0) @@ -320,7 +315,8 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, * them. */ goto malformed; /* We skip to LLC PID */ - PEEK_DISCARD(ETHER_ADDR_LEN); PEEK_DISCARD_UINT16; + PEEK_DISCARD(ETHER_ADDR_LEN); + PEEK_DISCARD_UINT16; PEEK_DISCARD(6); if (PEEK_UINT16 != LLC_PID_SONMP_HELLO) { log_debug("sonmp", "incorrect LLC protocol ID received for SONMP on %s", @@ -331,7 +327,7 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_ADDR; if ((chassis->c_id = calloc(1, sizeof(struct in_addr) + 1)) == NULL) { log_warn("sonmp", "unable to allocate memory for chassis id on %s", - hardware->h_ifname); + hardware->h_ifname); goto malformed; } chassis->c_id_len = sizeof(struct in_addr) + 1; @@ -345,12 +341,11 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, } PEEK_BYTES(seg, sizeof(seg)); rchassis = PEEK_UINT8; - for (i=0; sonmp_chassis_types[i].type != 0; i++) { - if (sonmp_chassis_types[i].type == rchassis) - break; + for (i = 0; sonmp_chassis_types[i].type != 0; i++) { + if (sonmp_chassis_types[i].type == rchassis) break; } - if (asprintf(&chassis->c_descr, "%s", - sonmp_chassis_types[i].description) == -1) { + if (asprintf(&chassis->c_descr, "%s", sonmp_chassis_types[i].description) == + -1) { log_warnx("sonmp", "unable to write chassis description for %s", hardware->h_ifname); goto malformed; @@ -358,20 +353,20 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &address, sizeof(struct in_addr), 0); if (mgmt == NULL) { if (errno == ENOMEM) - log_warn("sonmp", "unable to allocate memory for management address"); + log_warn("sonmp", + "unable to allocate memory for management address"); else log_warn("sonmp", "too large management address received on %s", hardware->h_ifname); goto malformed; } TAILQ_INSERT_TAIL(&chassis->c_mgmt, mgmt, m_entries); - port->p_ttl = cfg?(cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold): - LLDPD_TTL; + port->p_ttl = + cfg ? (cfg->g_config.c_tx_interval * cfg->g_config.c_tx_hold) : LLDPD_TTL; port->p_ttl = (port->p_ttl + 999) / 1000; port->p_id_subtype = LLDP_PORTID_SUBTYPE_LOCAL; - if (asprintf(&port->p_id, "%02x-%02x-%02x", - seg[0], seg[1], seg[2]) == -1) { + if (asprintf(&port->p_id, "%02x-%02x-%02x", seg[0], seg[1], seg[2]) == -1) { log_warn("sonmp", "unable to allocate memory for port id on %s", hardware->h_ifname); goto malformed; @@ -380,22 +375,20 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, /* Port description depend on the number of segments */ if ((seg[0] == 0) && (seg[1] == 0)) { - if (asprintf(&port->p_descr, "port %d", - seg[2]) == -1) { + if (asprintf(&port->p_descr, "port %d", seg[2]) == -1) { log_warnx("sonmp", "unable to write port description for %s", hardware->h_ifname); goto malformed; } } else if (seg[0] == 0) { - if (asprintf(&port->p_descr, "port %d/%d", - seg[1], seg[2]) == -1) { + if (asprintf(&port->p_descr, "port %d/%d", seg[1], seg[2]) == -1) { log_warnx("sonmp", "unable to write port description for %s", hardware->h_ifname); goto malformed; } } else { - if (asprintf(&port->p_descr, "port %x:%x:%x", - seg[0], seg[1], seg[2]) == -1) { + if (asprintf(&port->p_descr, "port %x:%x:%x", seg[0], seg[1], seg[2]) == + -1) { log_warnx("sonmp", "unable to write port description for %s", hardware->h_ifname); goto malformed; diff --git a/src/daemon/protocols/sonmp.h b/src/daemon/protocols/sonmp.h index ff7a720f..b90d066b 100644 --- a/src/daemon/protocols/sonmp.h +++ b/src/daemon/protocols/sonmp.h @@ -18,10 +18,14 @@ #ifndef _SONMP_H #define _SONMP_H -#define SONMP_MULTICAST_ADDR { \ - 0x01, 0x00, 0x81, 0x00, 0x01, 0x00 \ -} -#define LLC_ORG_NORTEL { 0x00, 0x00, 0x81 } +#define SONMP_MULTICAST_ADDR \ + { \ + 0x01, 0x00, 0x81, 0x00, 0x01, 0x00 \ + } +#define LLC_ORG_NORTEL \ + { \ + 0x00, 0x00, 0x81 \ + } #define LLC_PID_SONMP_HELLO 0x01a2 #define LLC_PID_SONMP_FLATNET 0x01a1 #define SONMP_SIZE 19 diff --git a/src/daemon/trace.h b/src/daemon/trace.h index d4b48464..2e7c482c 100644 --- a/src/daemon/trace.h +++ b/src/daemon/trace.h @@ -1,8 +1,8 @@ #ifdef ENABLE_DTRACE -# include "probes.h" -# define TRACE(probe) probe -# define TRACE_ENABLED(probe) probe ## _ENABLED() +# include "probes.h" +# define TRACE(probe) probe +# define TRACE_ENABLED(probe) probe##_ENABLED() #else -# define TRACE(probe) -# define TRACE_ENABLED(probe) (0) +# define TRACE(probe) +# define TRACE_ENABLED(probe) (0) #endif diff --git a/src/lib/atom.c b/src/lib/atom.c index 55a1b679..04011d44 100644 --- a/src/lib/atom.c +++ b/src/lib/atom.c @@ -24,19 +24,17 @@ #include "../marshal.h" #include "../ctl.h" -lldpctl_conn_t* +lldpctl_conn_t * lldpctl_atom_get_connection(lldpctl_atom_t *atom) { - if (atom) - return atom->conn; + if (atom) return atom->conn; return NULL; } void lldpctl_atom_inc_ref(lldpctl_atom_t *atom) { - if (atom) - atom->count++; + if (atom) atom->count++; } void @@ -44,12 +42,10 @@ lldpctl_atom_dec_ref(lldpctl_atom_t *atom) { struct atom_buffer *buffer, *buffer_next; if (atom && (--atom->count == 0)) { - if (atom->free) - atom->free(atom); + if (atom->free) atom->free(atom); /* Remove special allocated buffers */ - for (buffer = TAILQ_FIRST(&atom->buffers); - buffer; + for (buffer = TAILQ_FIRST(&atom->buffers); buffer; buffer = buffer_next) { buffer_next = TAILQ_NEXT(buffer, next); free(buffer); @@ -59,7 +55,7 @@ lldpctl_atom_dec_ref(lldpctl_atom_t *atom) } } -lldpctl_atom_t* +lldpctl_atom_t * lldpctl_atom_get(lldpctl_atom_t *atom, lldpctl_key_t key) { if (atom == NULL) return NULL; @@ -72,9 +68,8 @@ lldpctl_atom_get(lldpctl_atom_t *atom, lldpctl_key_t key) return atom->get(atom, key); } -lldpctl_atom_t* -lldpctl_atom_set(lldpctl_atom_t *atom, lldpctl_key_t key, - lldpctl_atom_t *value) +lldpctl_atom_t * +lldpctl_atom_set(lldpctl_atom_t *atom, lldpctl_key_t key, lldpctl_atom_t *value) { if (atom == NULL) return NULL; RESET_ERROR(atom->conn); @@ -86,7 +81,7 @@ lldpctl_atom_set(lldpctl_atom_t *atom, lldpctl_key_t key, return atom->set(atom, key, value); } -const char* +const char * lldpctl_atom_get_str(lldpctl_atom_t *atom, lldpctl_key_t key) { char *strresult = NULL; @@ -112,9 +107,9 @@ lldpctl_atom_get_str(lldpctl_atom_t *atom, lldpctl_key_t key) strresult = _lldpctl_alloc_in_atom(atom, 21); if (!strresult) return NULL; n1 = snprintf(strresult, 21, "%ld", intresult); - if (n1 > -1 && n1 < 21) - return strresult; - SET_ERROR(atom->conn, LLDPCTL_ERR_NOMEM); /* Not really true... */ + if (n1 > -1 && n1 < 21) return strresult; + SET_ERROR(atom->conn, + LLDPCTL_ERR_NOMEM); /* Not really true... */ return NULL; } } @@ -132,9 +127,8 @@ lldpctl_atom_get_str(lldpctl_atom_t *atom, lldpctl_key_t key) return NULL; } -lldpctl_atom_t* -lldpctl_atom_set_str(lldpctl_atom_t *atom, lldpctl_key_t key, - const char *value) +lldpctl_atom_t * +lldpctl_atom_set_str(lldpctl_atom_t *atom, lldpctl_key_t key, const char *value) { lldpctl_atom_t *result = NULL; const char *errstr; @@ -171,7 +165,8 @@ lldpctl_atom_set_str(lldpctl_atom_t *atom, lldpctl_key_t key, RESET_ERROR(atom->conn); if (atom->set_buffer != NULL) { - result = atom->set_buffer(atom, key, (u_int8_t*)value, value?strlen(value):0); + result = atom->set_buffer(atom, key, (u_int8_t *)value, + value ? strlen(value) : 0); if (result) return result; if (lldpctl_last_error(atom->conn) != LLDPCTL_ERR_NOT_EXIST && lldpctl_last_error(atom->conn) != LLDPCTL_ERR_BAD_VALUE) @@ -179,13 +174,12 @@ lldpctl_atom_set_str(lldpctl_atom_t *atom, lldpctl_key_t key, bad = bad || (lldpctl_last_error(atom->conn) == LLDPCTL_ERR_BAD_VALUE); } - SET_ERROR(atom->conn, bad?LLDPCTL_ERR_BAD_VALUE:LLDPCTL_ERR_NOT_EXIST); + SET_ERROR(atom->conn, bad ? LLDPCTL_ERR_BAD_VALUE : LLDPCTL_ERR_NOT_EXIST); return NULL; } -const u_int8_t* -lldpctl_atom_get_buffer(lldpctl_atom_t *atom, lldpctl_key_t key, - size_t *length) +const u_int8_t * +lldpctl_atom_get_buffer(lldpctl_atom_t *atom, lldpctl_key_t key, size_t *length) { if (atom == NULL) return NULL; RESET_ERROR(atom->conn); @@ -197,9 +191,9 @@ lldpctl_atom_get_buffer(lldpctl_atom_t *atom, lldpctl_key_t key, return atom->get_buffer(atom, key, length); } -lldpctl_atom_t* -lldpctl_atom_set_buffer(lldpctl_atom_t *atom, lldpctl_key_t key, - const u_int8_t* value, size_t length) +lldpctl_atom_t * +lldpctl_atom_set_buffer(lldpctl_atom_t *atom, lldpctl_key_t key, const u_int8_t *value, + size_t length) { if (atom == NULL) return NULL; RESET_ERROR(atom->conn); @@ -217,14 +211,12 @@ lldpctl_atom_get_int(lldpctl_atom_t *atom, lldpctl_key_t key) if (atom == NULL) return LLDPCTL_ERR_NOT_EXIST; RESET_ERROR(atom->conn); - if (atom->get_int == NULL) - return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); + if (atom->get_int == NULL) return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); return atom->get_int(atom, key); } -lldpctl_atom_t* -lldpctl_atom_set_int(lldpctl_atom_t *atom, lldpctl_key_t key, - long int value) +lldpctl_atom_t * +lldpctl_atom_set_int(lldpctl_atom_t *atom, lldpctl_key_t key, long int value) { if (atom == NULL) return NULL; RESET_ERROR(atom->conn); @@ -236,7 +228,7 @@ lldpctl_atom_set_int(lldpctl_atom_t *atom, lldpctl_key_t key, return atom->set_int(atom, key, value); } -lldpctl_atom_iter_t* +lldpctl_atom_iter_t * lldpctl_atom_iter(lldpctl_atom_t *atom) { if (atom == NULL) return NULL; @@ -249,7 +241,7 @@ lldpctl_atom_iter(lldpctl_atom_t *atom) return atom->iter(atom); } -lldpctl_atom_iter_t* +lldpctl_atom_iter_t * lldpctl_atom_iter_next(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { if (atom == NULL) return NULL; @@ -262,8 +254,8 @@ lldpctl_atom_iter_next(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) return atom->next(atom, iter); } -lldpctl_atom_t* -lldpctl_atom_iter_value(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) +lldpctl_atom_t * +lldpctl_atom_iter_value(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { if (atom == NULL) return NULL; RESET_ERROR(atom->conn); @@ -275,7 +267,7 @@ lldpctl_atom_iter_value(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) return atom->value(atom, iter); } -lldpctl_atom_t* +lldpctl_atom_t * lldpctl_atom_create(lldpctl_atom_t *atom) { if (atom == NULL) return NULL; @@ -306,11 +298,9 @@ lldpctl_atom_create(lldpctl_atom_t *atom) * state_recv and in the two later cases, the provided @c state_data must match. */ int -_lldpctl_do_something(lldpctl_conn_t *conn, - int state_send, int state_recv, const char *state_data, - enum hmsg_type type, - void *to_send, struct marshal_info *mi_send, - void **to_recv, struct marshal_info *mi_recv) +_lldpctl_do_something(lldpctl_conn_t *conn, int state_send, int state_recv, + const char *state_data, enum hmsg_type type, void *to_send, + struct marshal_info *mi_send, void **to_recv, struct marshal_info *mi_recv) { ssize_t rc; @@ -321,8 +311,8 @@ _lldpctl_do_something(lldpctl_conn_t *conn, if (conn->state == CONN_STATE_IDLE) { /* We need to build the message to send, then send * it. */ - if (ctl_msg_send_unserialized(&conn->output_buffer, &conn->output_buffer_len, - type, to_send, mi_send) != 0) + if (ctl_msg_send_unserialized(&conn->output_buffer, + &conn->output_buffer_len, type, to_send, mi_send) != 0) return SET_ERROR(conn, LLDPCTL_ERR_SERIALIZATION); conn->state = state_send; if (state_data) @@ -331,26 +321,24 @@ _lldpctl_do_something(lldpctl_conn_t *conn, conn->state_data[0] = 0; } if (conn->state == state_send && - (state_data == NULL || !strncmp(conn->state_data, state_data, sizeof(conn->state_data) - 1))) { + (state_data == NULL || + !strncmp(conn->state_data, state_data, sizeof(conn->state_data) - 1))) { /* We need to send the currently built message */ rc = lldpctl_send(conn); - if (rc < 0) - return SET_ERROR(conn, rc); + if (rc < 0) return SET_ERROR(conn, rc); conn->state = state_recv; } if (conn->state == state_recv && - (state_data == NULL || !strncmp(conn->state_data, state_data, sizeof(conn->state_data) - 1))) { + (state_data == NULL || + !strncmp(conn->state_data, state_data, sizeof(conn->state_data) - 1))) { /* We need to receive the answer */ while ((rc = ctl_msg_recv_unserialized(&conn->input_buffer, - &conn->input_buffer_len, - type, to_recv, mi_recv)) > 0) { + &conn->input_buffer_len, type, to_recv, mi_recv)) > 0) { /* We need more bytes */ rc = _lldpctl_needs(conn, rc); - if (rc < 0) - return SET_ERROR(conn, rc); + if (rc < 0) return SET_ERROR(conn, rc); } - if (rc < 0) - return SET_ERROR(conn, LLDPCTL_ERR_SERIALIZATION); + if (rc < 0) return SET_ERROR(conn, LLDPCTL_ERR_SERIALIZATION); /* rc == 0 */ conn->state = CONN_STATE_IDLE; conn->state_data[0] = 0; @@ -359,19 +347,15 @@ _lldpctl_do_something(lldpctl_conn_t *conn, return SET_ERROR(conn, LLDPCTL_ERR_INVALID_STATE); } - int -lldpctl_watch_callback(lldpctl_conn_t *conn, - lldpctl_change_callback cb, - void *data) +lldpctl_watch_callback(lldpctl_conn_t *conn, lldpctl_change_callback cb, void *data) { int rc; RESET_ERROR(conn); - rc = _lldpctl_do_something(conn, - CONN_STATE_SET_WATCH_SEND, CONN_STATE_SET_WATCH_RECV, NULL, - SUBSCRIBE, NULL, NULL, NULL, NULL); + rc = _lldpctl_do_something(conn, CONN_STATE_SET_WATCH_SEND, + CONN_STATE_SET_WATCH_RECV, NULL, SUBSCRIBE, NULL, NULL, NULL, NULL); if (rc == 0) { conn->watch_cb = cb; conn->watch_data = data; @@ -381,17 +365,14 @@ lldpctl_watch_callback(lldpctl_conn_t *conn, } int -lldpctl_watch_callback2(lldpctl_conn_t *conn, - lldpctl_change_callback2 cb, - void *data) +lldpctl_watch_callback2(lldpctl_conn_t *conn, lldpctl_change_callback2 cb, void *data) { int rc; RESET_ERROR(conn); - rc = _lldpctl_do_something(conn, - CONN_STATE_SET_WATCH_SEND, CONN_STATE_SET_WATCH_RECV, NULL, - SUBSCRIBE, NULL, NULL, NULL, NULL); + rc = _lldpctl_do_something(conn, CONN_STATE_SET_WATCH_SEND, + CONN_STATE_SET_WATCH_RECV, NULL, SUBSCRIBE, NULL, NULL, NULL, NULL); if (rc == 0) { conn->watch_cb2 = cb; conn->watch_data = data; @@ -413,15 +394,14 @@ lldpctl_watch(lldpctl_conn_t *conn) conn->watch_triggered = 0; while (!conn->watch_triggered) { rc = _lldpctl_needs(conn, 1); - if (rc < 0) - return SET_ERROR(conn, rc); + if (rc < 0) return SET_ERROR(conn, rc); } RESET_ERROR(conn); return 0; } -lldpctl_atom_t* +lldpctl_atom_t * lldpctl_get_configuration(lldpctl_conn_t *conn) { int rc; @@ -430,11 +410,9 @@ lldpctl_get_configuration(lldpctl_conn_t *conn) RESET_ERROR(conn); - rc = _lldpctl_do_something(conn, - CONN_STATE_GET_CONFIG_SEND, CONN_STATE_GET_CONFIG_RECV, NULL, - GET_CONFIG, - NULL, NULL, - &p, &MARSHAL_INFO(lldpd_config)); + rc = _lldpctl_do_something(conn, CONN_STATE_GET_CONFIG_SEND, + CONN_STATE_GET_CONFIG_RECV, NULL, GET_CONFIG, NULL, NULL, &p, + &MARSHAL_INFO(lldpd_config)); if (rc == 0) { config = p; return _lldpctl_new_atom(conn, atom_config, config); @@ -442,7 +420,7 @@ lldpctl_get_configuration(lldpctl_conn_t *conn) return NULL; } -lldpctl_atom_t* +lldpctl_atom_t * lldpctl_get_interfaces(lldpctl_conn_t *conn) { struct lldpd_interface_list *ifs; @@ -451,11 +429,9 @@ lldpctl_get_interfaces(lldpctl_conn_t *conn) RESET_ERROR(conn); - rc = _lldpctl_do_something(conn, - CONN_STATE_GET_INTERFACES_SEND, CONN_STATE_GET_INTERFACES_RECV, NULL, - GET_INTERFACES, - NULL, NULL, - &p, &MARSHAL_INFO(lldpd_interface_list)); + rc = _lldpctl_do_something(conn, CONN_STATE_GET_INTERFACES_SEND, + CONN_STATE_GET_INTERFACES_RECV, NULL, GET_INTERFACES, NULL, NULL, &p, + &MARSHAL_INFO(lldpd_interface_list)); if (rc == 0) { ifs = p; return _lldpctl_new_atom(conn, atom_interfaces_list, ifs); @@ -463,7 +439,7 @@ lldpctl_get_interfaces(lldpctl_conn_t *conn) return NULL; } -lldpctl_atom_t* +lldpctl_atom_t * lldpctl_get_local_chassis(lldpctl_conn_t *conn) { struct lldpd_chassis *chassis; @@ -472,11 +448,9 @@ lldpctl_get_local_chassis(lldpctl_conn_t *conn) RESET_ERROR(conn); - rc = _lldpctl_do_something(conn, - CONN_STATE_GET_CHASSIS_SEND, CONN_STATE_GET_CHASSIS_RECV, NULL, - GET_CHASSIS, - NULL, NULL, - &p, &MARSHAL_INFO(lldpd_chassis)); + rc = _lldpctl_do_something(conn, CONN_STATE_GET_CHASSIS_SEND, + CONN_STATE_GET_CHASSIS_RECV, NULL, GET_CHASSIS, NULL, NULL, &p, + &MARSHAL_INFO(lldpd_chassis)); if (rc == 0) { chassis = p; return _lldpctl_new_atom(conn, atom_chassis, chassis, NULL, 0); @@ -484,7 +458,7 @@ lldpctl_get_local_chassis(lldpctl_conn_t *conn) return NULL; } -lldpctl_atom_t* +lldpctl_atom_t * lldpctl_get_port(lldpctl_atom_t *atom) { int rc; @@ -500,19 +474,18 @@ lldpctl_get_port(lldpctl_atom_t *atom) SET_ERROR(conn, LLDPCTL_ERR_INCORRECT_ATOM_TYPE); return NULL; } - rc = _lldpctl_do_something(conn, - CONN_STATE_GET_PORT_SEND, CONN_STATE_GET_PORT_RECV, iface->name, - GET_INTERFACE, (void*)iface->name, &MARSHAL_INFO(string), - &p, &MARSHAL_INFO(lldpd_hardware)); + rc = _lldpctl_do_something(conn, CONN_STATE_GET_PORT_SEND, + CONN_STATE_GET_PORT_RECV, iface->name, GET_INTERFACE, (void *)iface->name, + &MARSHAL_INFO(string), &p, &MARSHAL_INFO(lldpd_hardware)); if (rc == 0) { hardware = p; - return _lldpctl_new_atom(conn, atom_port, 1, - hardware, &hardware->h_lport, NULL); + return _lldpctl_new_atom(conn, atom_port, 1, hardware, + &hardware->h_lport, NULL); } return NULL; } -lldpctl_atom_t* +lldpctl_atom_t * lldpctl_get_default_port(lldpctl_conn_t *conn) { struct lldpd_port *port; @@ -521,10 +494,9 @@ lldpctl_get_default_port(lldpctl_conn_t *conn) RESET_ERROR(conn); - rc = _lldpctl_do_something(conn, - CONN_STATE_GET_DEFAULT_PORT_SEND, CONN_STATE_GET_DEFAULT_PORT_RECV, "", - GET_DEFAULT_PORT, NULL, NULL, - &p, &MARSHAL_INFO(lldpd_port)); + rc = _lldpctl_do_something(conn, CONN_STATE_GET_DEFAULT_PORT_SEND, + CONN_STATE_GET_DEFAULT_PORT_RECV, "", GET_DEFAULT_PORT, NULL, NULL, &p, + &MARSHAL_INFO(lldpd_port)); if (rc == 0) { port = p; return _lldpctl_new_atom(conn, atom_port, 1, NULL, port, NULL); @@ -532,28 +504,26 @@ lldpctl_get_default_port(lldpctl_conn_t *conn) return NULL; } -static lldpctl_map_t empty_map[] = {{ 0, NULL }}; +static lldpctl_map_t empty_map[] = { { 0, NULL } }; -static struct atom_map atom_map_list = { - .next = NULL -}; +static struct atom_map atom_map_list = { .next = NULL }; -lldpctl_map_t* +lldpctl_map_t * lldpctl_key_get_map(lldpctl_key_t key) { init_atom_map(); struct atom_map *map; - for (map = atom_map_list.next; map ; map = map->next) { - if (map->key == key) - return map->map; + for (map = atom_map_list.next; map; map = map->next) { + if (map->key == key) return map->map; } return empty_map; } -void atom_map_register(struct atom_map *map, int prio) +void +atom_map_register(struct atom_map *map, int prio) { (void)prio; - struct atom_map* iter = &atom_map_list; + struct atom_map *iter = &atom_map_list; while (iter->next) iter = iter->next; @@ -561,14 +531,13 @@ void atom_map_register(struct atom_map *map, int prio) iter->next = map; } -static struct atom_builder atom_builder_list = { - .nextb = NULL -}; +static struct atom_builder atom_builder_list = { .nextb = NULL }; -void atom_builder_register(struct atom_builder *builder, int prio) +void +atom_builder_register(struct atom_builder *builder, int prio) { (void)prio; - struct atom_builder* iter = &atom_builder_list; + struct atom_builder *iter = &atom_builder_list; while (iter->nextb) iter = iter->nextb; @@ -576,14 +545,14 @@ void atom_builder_register(struct atom_builder *builder, int prio) iter->nextb = builder; } -lldpctl_atom_t* +lldpctl_atom_t * _lldpctl_new_atom(lldpctl_conn_t *conn, atom_t type, ...) { init_atom_builder(); struct atom_builder *builder; struct lldpctl_atom_t *atom; va_list(ap); - for (builder = atom_builder_list.nextb; builder ; builder = builder->nextb) { + for (builder = atom_builder_list.nextb; builder; builder = builder->nextb) { if (builder->type != type) continue; atom = calloc(1, builder->size); if (atom == NULL) { @@ -591,25 +560,25 @@ _lldpctl_new_atom(lldpctl_conn_t *conn, atom_t type, ...) return NULL; } atom->count = 1; - atom->type = type; - atom->conn = conn; + atom->type = type; + atom->conn = conn; TAILQ_INIT(&atom->buffers); - atom->free = builder->free; + atom->free = builder->free; - atom->iter = builder->iter; - atom->next = builder->next; + atom->iter = builder->iter; + atom->next = builder->next; atom->value = builder->value; - atom->get = builder->get; - atom->get_str = builder->get_str; - atom->get_buffer= builder->get_buffer; - atom->get_int = builder->get_int; + atom->get = builder->get; + atom->get_str = builder->get_str; + atom->get_buffer = builder->get_buffer; + atom->get_int = builder->get_int; - atom->set = builder->set; - atom->set_str = builder->set_str; - atom->set_buffer= builder->set_buffer; - atom->set_int = builder->set_int; - atom->create = builder->create; + atom->set = builder->set; + atom->set_str = builder->set_str; + atom->set_buffer = builder->set_buffer; + atom->set_int = builder->set_int; + atom->create = builder->create; va_start(ap, type); if (builder->init && builder->init(atom, ap) == 0) { @@ -636,7 +605,7 @@ _lldpctl_new_atom(lldpctl_conn_t *conn, atom_t type, ...) * @param size Size of the allocated area. * @return Pointer to the buffer or @c NULL if allocation fails. */ -void* +void * _lldpctl_alloc_in_atom(lldpctl_atom_t *atom, size_t size) { struct atom_buffer *buffer; @@ -661,10 +630,9 @@ _lldpctl_alloc_in_atom(lldpctl_atom_t *atom, size_t size) * @param max Maximum number of bytes to dump. Can be 0 if no maximum. * @return A string representing the dump of the buffer or @c NULL if error. */ -const char* -_lldpctl_dump_in_atom(lldpctl_atom_t *atom, - const uint8_t *input, size_t size, - char sep, size_t max) +const char * +_lldpctl_dump_in_atom(lldpctl_atom_t *atom, const uint8_t *input, size_t size, char sep, + size_t max) { static const char truncation[] = "[...]"; size_t i, len; @@ -675,14 +643,13 @@ _lldpctl_dump_in_atom(lldpctl_atom_t *atom, else len = size * 3 + 1; - if ((buffer = _lldpctl_alloc_in_atom(atom, len)) == NULL) - return NULL; + if ((buffer = _lldpctl_alloc_in_atom(atom, len)) == NULL) return NULL; for (i = 0; (i < size) && (max == 0 || i < max); i++) - snprintf(buffer + i * 3, 4, "%02x%c", *(u_int8_t*)(input + i), sep); + snprintf(buffer + i * 3, 4, "%02x%c", *(u_int8_t *)(input + i), sep); if (max > 0 && size > max) snprintf(buffer + i * 3, sizeof(truncation) + 1, "%s", truncation); else - *(buffer + i*3 - 1) = 0; + *(buffer + i * 3 - 1) = 0; return buffer; } diff --git a/src/lib/atom.h b/src/lib/atom.h index 66bf692a..c79b9373 100644 --- a/src/lib/atom.h +++ b/src/lib/atom.h @@ -37,34 +37,34 @@ struct lldpctl_conn_t { size_t input_buffer_len; size_t output_buffer_len; -#define CONN_STATE_IDLE 0 -#define CONN_STATE_GET_INTERFACES_SEND 1 -#define CONN_STATE_GET_INTERFACES_RECV 2 -#define CONN_STATE_GET_PORT_SEND 3 -#define CONN_STATE_GET_PORT_RECV 4 -#define CONN_STATE_SET_PORT_SEND 5 -#define CONN_STATE_SET_PORT_RECV 6 -#define CONN_STATE_SET_WATCH_SEND 7 -#define CONN_STATE_SET_WATCH_RECV 8 -#define CONN_STATE_GET_CONFIG_SEND 9 -#define CONN_STATE_GET_CONFIG_RECV 10 -#define CONN_STATE_SET_CONFIG_SEND 11 -#define CONN_STATE_SET_CONFIG_RECV 12 -#define CONN_STATE_GET_CHASSIS_SEND 13 -#define CONN_STATE_GET_CHASSIS_RECV 14 +#define CONN_STATE_IDLE 0 +#define CONN_STATE_GET_INTERFACES_SEND 1 +#define CONN_STATE_GET_INTERFACES_RECV 2 +#define CONN_STATE_GET_PORT_SEND 3 +#define CONN_STATE_GET_PORT_RECV 4 +#define CONN_STATE_SET_PORT_SEND 5 +#define CONN_STATE_SET_PORT_RECV 6 +#define CONN_STATE_SET_WATCH_SEND 7 +#define CONN_STATE_SET_WATCH_RECV 8 +#define CONN_STATE_GET_CONFIG_SEND 9 +#define CONN_STATE_GET_CONFIG_RECV 10 +#define CONN_STATE_SET_CONFIG_SEND 11 +#define CONN_STATE_SET_CONFIG_RECV 12 +#define CONN_STATE_GET_CHASSIS_SEND 13 +#define CONN_STATE_GET_CHASSIS_RECV 14 #define CONN_STATE_GET_DEFAULT_PORT_SEND 15 #define CONN_STATE_GET_DEFAULT_PORT_RECV 16 -#define CONN_STATE_WATCHING 17 -#define CONN_STATE_SET_CHASSIS_SEND 18 -#define CONN_STATE_SET_CHASSIS_RECV 19 +#define CONN_STATE_WATCHING 17 +#define CONN_STATE_SET_CHASSIS_SEND 18 +#define CONN_STATE_SET_CHASSIS_RECV 19 - int state; /* Current state */ + int state; /* Current state */ /* Data attached to the state. It is used to check that we are using the * same data as a previous call until the state machine goes to * CONN_STATE_IDLE. */ char state_data[IFNAMSIZ + 64]; /* Error handling */ - lldpctl_error_t error; /* Last error */ + lldpctl_error_t error; /* Last error */ /* Handling notifications */ lldpctl_change_callback watch_cb; @@ -75,20 +75,17 @@ struct lldpctl_conn_t { /* User data for synchronous callbacks. */ struct lldpctl_conn_sync_t { - int fd; /* File descriptor to the socket. */ + int fd; /* File descriptor to the socket. */ }; ssize_t _lldpctl_needs(lldpctl_conn_t *lldpctl, size_t length); -int _lldpctl_do_something(lldpctl_conn_t *conn, - int state_send, int state_recv, const char *state_data, - enum hmsg_type type, - void *to_send, struct marshal_info *mi_send, - void **to_recv, struct marshal_info *mi_recv); +int _lldpctl_do_something(lldpctl_conn_t *conn, int state_send, int state_recv, + const char *state_data, enum hmsg_type type, void *to_send, + struct marshal_info *mi_send, void **to_recv, struct marshal_info *mi_recv); /* errors.c */ -#define SET_ERROR(conn, x) ((conn)->error = x) -#define RESET_ERROR(conn) SET_ERROR((conn), LLDPCTL_NO_ERROR) - +#define SET_ERROR(conn, x) ((conn)->error = x) +#define RESET_ERROR(conn) SET_ERROR((conn), LLDPCTL_NO_ERROR) /* atom.c and atom-private.c */ typedef enum { @@ -127,7 +124,8 @@ typedef enum { } atom_t; void *_lldpctl_alloc_in_atom(lldpctl_atom_t *, size_t); -const char *_lldpctl_dump_in_atom(lldpctl_atom_t *, const uint8_t *, size_t, char, size_t); +const char *_lldpctl_dump_in_atom(lldpctl_atom_t *, const uint8_t *, size_t, char, + size_t); struct atom_buffer { TAILQ_ENTRY(atom_buffer) next; @@ -141,23 +139,24 @@ struct lldpctl_atom_t { TAILQ_HEAD(, atom_buffer) buffers; /* List of buffers */ /* Destructor */ - void (*free)(lldpctl_atom_t *); + void (*free)(lldpctl_atom_t *); /* Iterators */ lldpctl_atom_iter_t *(*iter)(lldpctl_atom_t *); lldpctl_atom_iter_t *(*next)(lldpctl_atom_t *, lldpctl_atom_iter_t *); - lldpctl_atom_t *(*value)(lldpctl_atom_t *, lldpctl_atom_iter_t *); + lldpctl_atom_t *(*value)(lldpctl_atom_t *, lldpctl_atom_iter_t *); /* Getters */ lldpctl_atom_t *(*get)(lldpctl_atom_t *, lldpctl_key_t); - const char *(*get_str)(lldpctl_atom_t *, lldpctl_key_t); + const char *(*get_str)(lldpctl_atom_t *, lldpctl_key_t); const u_int8_t *(*get_buffer)(lldpctl_atom_t *, lldpctl_key_t, size_t *); - long int (*get_int)(lldpctl_atom_t *, lldpctl_key_t); + long int (*get_int)(lldpctl_atom_t *, lldpctl_key_t); /* Setters */ lldpctl_atom_t *(*set)(lldpctl_atom_t *, lldpctl_key_t, lldpctl_atom_t *); lldpctl_atom_t *(*set_str)(lldpctl_atom_t *, lldpctl_key_t, const char *); - lldpctl_atom_t *(*set_buffer)(lldpctl_atom_t *, lldpctl_key_t, const u_int8_t *, size_t); + lldpctl_atom_t *( + *set_buffer)(lldpctl_atom_t *, lldpctl_key_t, const u_int8_t *, size_t); lldpctl_atom_t *(*set_int)(lldpctl_atom_t *, lldpctl_key_t, long int); lldpctl_atom_t *(*create)(lldpctl_atom_t *); }; @@ -180,17 +179,18 @@ struct _lldpctl_atom_interface_t { struct _lldpctl_atom_chassis_t { lldpctl_atom_t base; struct lldpd_chassis *chassis; - struct _lldpctl_atom_port_t *parent; /* Optional: parent of this atom (owning our reference) */ - int embedded; /* This atom is "embedded" (not refcounted) */ + struct _lldpctl_atom_port_t + *parent; /* Optional: parent of this atom (owning our reference) */ + int embedded; /* This atom is "embedded" (not refcounted) */ }; struct _lldpctl_atom_port_t { lldpctl_atom_t base; - int local; /* Local or remote port? */ - struct lldpd_hardware *hardware; /* Local port only (but optional) */ - struct lldpd_port *port; /* Local and remote */ + int local; /* Local or remote port? */ + struct lldpd_hardware *hardware; /* Local port only (but optional) */ + struct lldpd_port *port; /* Local and remote */ struct _lldpctl_atom_port_t *parent; /* Local port if we are a remote port */ - lldpctl_atom_t *chassis; /* Internal atom for chassis */ + lldpctl_atom_t *chassis; /* Internal atom for chassis */ }; /* Can represent any simple list holding just a reference to a port. */ @@ -262,7 +262,7 @@ struct _lldpctl_atom_med_caelement_t { struct _lldpctl_atom_med_location_t *parent; int type; uint8_t *value; - size_t len; + size_t len; }; struct _lldpctl_atom_med_power_t { @@ -291,38 +291,52 @@ struct lldpctl_atom_t *_lldpctl_new_atom(lldpctl_conn_t *conn, atom_t type, ...) struct atom_map { int key; struct atom_map *next; - lldpctl_map_t map[]; + lldpctl_map_t map[]; }; void atom_map_register(struct atom_map *map, int); void init_atom_map(void); -#define ATOM_MAP_REGISTER(NAME, PRIO) void init_atom_map_ ## NAME() { atom_map_register(& NAME, PRIO); } +#define ATOM_MAP_REGISTER(NAME, PRIO) \ + void init_atom_map_##NAME() \ + { \ + atom_map_register(&NAME, PRIO); \ + } struct atom_builder { - atom_t type; /* Atom type */ - size_t size; /* Size of structure to allocate */ - int (*init)(lldpctl_atom_t *, va_list); /* Optional additional init steps */ - void (*free)(lldpctl_atom_t *); /* Optional deallocation steps */ - - lldpctl_atom_iter_t* (*iter)(lldpctl_atom_t *); /* Optional, return an iterator for this object */ - lldpctl_atom_iter_t* (*next)(lldpctl_atom_t *, lldpctl_atom_iter_t *); /* Return the next object for the provided iterator */ - lldpctl_atom_t* (*value)(lldpctl_atom_t *, lldpctl_atom_iter_t *); /* Return the current object for the provided iterator */ - - lldpctl_atom_t* (*get)(lldpctl_atom_t *, lldpctl_key_t); - const char* (*get_str)(lldpctl_atom_t *, lldpctl_key_t); - const u_int8_t* (*get_buffer)(lldpctl_atom_t *, lldpctl_key_t, size_t *); - long int (*get_int)(lldpctl_atom_t *, lldpctl_key_t); - - lldpctl_atom_t* (*set)(lldpctl_atom_t *, lldpctl_key_t, lldpctl_atom_t *); - lldpctl_atom_t* (*set_str)(lldpctl_atom_t *, lldpctl_key_t, const char *); - lldpctl_atom_t* (*set_buffer)(lldpctl_atom_t *, lldpctl_key_t, const u_int8_t *, size_t); - lldpctl_atom_t* (*set_int)(lldpctl_atom_t *, lldpctl_key_t, long int); - lldpctl_atom_t* (*create)(lldpctl_atom_t *); - struct atom_builder *nextb; + atom_t type; /* Atom type */ + size_t size; /* Size of structure to allocate */ + int (*init)(lldpctl_atom_t *, va_list); /* Optional additional init steps */ + void (*free)(lldpctl_atom_t *); /* Optional deallocation steps */ + + lldpctl_atom_iter_t *(*iter)( + lldpctl_atom_t *); /* Optional, return an iterator for this object */ + lldpctl_atom_iter_t *(*next)(lldpctl_atom_t *, + lldpctl_atom_iter_t + *); /* Return the next object for the provided iterator */ + lldpctl_atom_t *(*value)(lldpctl_atom_t *, + lldpctl_atom_iter_t + *); /* Return the current object for the provided iterator */ + + lldpctl_atom_t *(*get)(lldpctl_atom_t *, lldpctl_key_t); + const char *(*get_str)(lldpctl_atom_t *, lldpctl_key_t); + const u_int8_t *(*get_buffer)(lldpctl_atom_t *, lldpctl_key_t, size_t *); + long int (*get_int)(lldpctl_atom_t *, lldpctl_key_t); + + lldpctl_atom_t *(*set)(lldpctl_atom_t *, lldpctl_key_t, lldpctl_atom_t *); + lldpctl_atom_t *(*set_str)(lldpctl_atom_t *, lldpctl_key_t, const char *); + lldpctl_atom_t *( + *set_buffer)(lldpctl_atom_t *, lldpctl_key_t, const u_int8_t *, size_t); + lldpctl_atom_t *(*set_int)(lldpctl_atom_t *, lldpctl_key_t, long int); + lldpctl_atom_t *(*create)(lldpctl_atom_t *); + struct atom_builder *nextb; }; void atom_builder_register(struct atom_builder *builder, int); void init_atom_builder(void); -#define ATOM_BUILDER_REGISTER(NAME, PRIO) void init_atom_builder_ ## NAME() { atom_builder_register(& NAME, PRIO); } +#define ATOM_BUILDER_REGISTER(NAME, PRIO) \ + void init_atom_builder_##NAME() \ + { \ + atom_builder_register(&NAME, PRIO); \ + } diff --git a/src/lib/atoms/chassis.c b/src/lib/atoms/chassis.c index 4ef72a51..e03d0ab4 100644 --- a/src/lib/atoms/chassis.c +++ b/src/lib/atoms/chassis.c @@ -26,22 +26,22 @@ #include "../helpers.h" static lldpctl_map_t chassis_id_subtype_map[] = { - { LLDP_CHASSISID_SUBTYPE_IFNAME, "ifname"}, + { LLDP_CHASSISID_SUBTYPE_IFNAME, "ifname" }, { LLDP_CHASSISID_SUBTYPE_IFALIAS, "ifalias" }, - { LLDP_CHASSISID_SUBTYPE_LOCAL, "local" }, - { LLDP_CHASSISID_SUBTYPE_LLADDR, "mac" }, - { LLDP_CHASSISID_SUBTYPE_ADDR, "ip" }, - { LLDP_CHASSISID_SUBTYPE_PORT, "unhandled" }, + { LLDP_CHASSISID_SUBTYPE_LOCAL, "local" }, + { LLDP_CHASSISID_SUBTYPE_LLADDR, "mac" }, + { LLDP_CHASSISID_SUBTYPE_ADDR, "ip" }, + { LLDP_CHASSISID_SUBTYPE_PORT, "unhandled" }, { LLDP_CHASSISID_SUBTYPE_CHASSIS, "unhandled" }, - { 0, NULL}, + { 0, NULL }, }; #ifdef ENABLE_LLDPMED static lldpctl_map_t chassis_med_type_map[] = { - { LLDP_MED_CLASS_I, "Generic Endpoint (Class I)" }, - { LLDP_MED_CLASS_II, "Media Endpoint (Class II)" }, - { LLDP_MED_CLASS_III, "Communication Device Endpoint (Class III)" }, + { LLDP_MED_CLASS_I, "Generic Endpoint (Class I)" }, + { LLDP_MED_CLASS_II, "Media Endpoint (Class II)" }, + { LLDP_MED_CLASS_III, "Communication Device Endpoint (Class III)" }, { LLDP_MED_NETWORK_DEVICE, "Network Connectivity Device" }, { 0, NULL }, }; @@ -51,21 +51,19 @@ static lldpctl_map_t chassis_med_type_map[] = { static int _lldpctl_atom_new_chassis(lldpctl_atom_t *atom, va_list ap) { - struct _lldpctl_atom_chassis_t *p = - (struct _lldpctl_atom_chassis_t *)atom; - p->chassis = va_arg(ap, struct lldpd_chassis*); - p->parent = va_arg(ap, struct _lldpctl_atom_port_t*); + struct _lldpctl_atom_chassis_t *p = (struct _lldpctl_atom_chassis_t *)atom; + p->chassis = va_arg(ap, struct lldpd_chassis *); + p->parent = va_arg(ap, struct _lldpctl_atom_port_t *); p->embedded = va_arg(ap, int); if (p->parent && !p->embedded) - lldpctl_atom_inc_ref((lldpctl_atom_t*)p->parent); + lldpctl_atom_inc_ref((lldpctl_atom_t *)p->parent); return 1; } static void _lldpctl_atom_free_chassis(lldpctl_atom_t *atom) { - struct _lldpctl_atom_chassis_t *p = - (struct _lldpctl_atom_chassis_t *)atom; + struct _lldpctl_atom_chassis_t *p = (struct _lldpctl_atom_chassis_t *)atom; /* When we have a parent, the chassis structure is in fact part of the * parent, just decrement the reference count of the parent. Otherwise, * we need to free the whole chassis. When embedded, we don't alter the @@ -73,25 +71,22 @@ _lldpctl_atom_free_chassis(lldpctl_atom_t *atom) * increase the reference count of this atom. See * `_lldpctl_atom_get_atom_chassis' for how to handle that. */ if (p->parent) { - if (!p->embedded) - lldpctl_atom_dec_ref((lldpctl_atom_t*)p->parent); + if (!p->embedded) lldpctl_atom_dec_ref((lldpctl_atom_t *)p->parent); } else lldpd_chassis_cleanup(p->chassis, 1); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_get_atom_chassis(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_chassis_t *p = - (struct _lldpctl_atom_chassis_t *)atom; + struct _lldpctl_atom_chassis_t *p = (struct _lldpctl_atom_chassis_t *)atom; struct lldpd_chassis *chassis = p->chassis; switch (key) { case lldpctl_k_chassis_mgmt: return _lldpctl_new_atom(atom->conn, atom_mgmts_list, - (p->parent && p->embedded)? - (lldpctl_atom_t *)p->parent: - (lldpctl_atom_t *)p, + (p->parent && p->embedded) ? (lldpctl_atom_t *)p->parent : + (lldpctl_atom_t *)p, chassis); default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); @@ -100,12 +95,11 @@ _lldpctl_atom_get_atom_chassis(lldpctl_atom_t *atom, lldpctl_key_t key) } #ifdef ENABLE_LLDPMED -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_str_chassis(lldpctl_atom_t *atom, lldpctl_key_t key, const char *value) { - struct _lldpctl_atom_chassis_t *p = - (struct _lldpctl_atom_chassis_t *) atom; + struct _lldpctl_atom_chassis_t *p = (struct _lldpctl_atom_chassis_t *)atom; struct lldpd_chassis *chassis = p->chassis; char *canary = NULL; @@ -151,26 +145,23 @@ _lldpctl_atom_set_str_chassis(lldpctl_atom_t *atom, lldpctl_key_t key, return NULL; } - rc = _lldpctl_do_something(atom->conn, - CONN_STATE_SET_CHASSIS_SEND, CONN_STATE_SET_CHASSIS_RECV, - canary, - SET_CHASSIS, chassis, &MARSHAL_INFO(lldpd_chassis), - NULL, NULL); + rc = _lldpctl_do_something(atom->conn, CONN_STATE_SET_CHASSIS_SEND, + CONN_STATE_SET_CHASSIS_RECV, canary, SET_CHASSIS, chassis, + &MARSHAL_INFO(lldpd_chassis), NULL, NULL); free(canary); - if (rc == 0) - return atom; + if (rc == 0) return atom; return NULL; } #endif /* ENABLE_LLDPMED */ -static const char* +static const char * _lldpctl_atom_get_str_chassis(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_chassis_t *p = - (struct _lldpctl_atom_chassis_t *)atom; + struct _lldpctl_atom_chassis_t *p = (struct _lldpctl_atom_chassis_t *)atom; struct lldpd_chassis *chassis = p->chassis; - char *ipaddress = NULL; size_t len; + char *ipaddress = NULL; + size_t len; /* Local and remote port */ switch (key) { @@ -184,20 +175,25 @@ _lldpctl_atom_get_str_chassis(lldpctl_atom_t *atom, lldpctl_key_t key) case LLDP_CHASSISID_SUBTYPE_LOCAL: return chassis->c_id; case LLDP_CHASSISID_SUBTYPE_LLADDR: - return _lldpctl_dump_in_atom(atom, - (uint8_t*)chassis->c_id, chassis->c_id_len, - ':', 0); + return _lldpctl_dump_in_atom(atom, (uint8_t *)chassis->c_id, + chassis->c_id_len, ':', 0); case LLDP_CHASSISID_SUBTYPE_ADDR: switch (chassis->c_id[0]) { - case LLDP_MGMT_ADDR_IP4: len = INET_ADDRSTRLEN + 1; break; - case LLDP_MGMT_ADDR_IP6: len = INET6_ADDRSTRLEN + 1; break; - default: len = 0; + case LLDP_MGMT_ADDR_IP4: + len = INET_ADDRSTRLEN + 1; + break; + case LLDP_MGMT_ADDR_IP6: + len = INET6_ADDRSTRLEN + 1; + break; + default: + len = 0; } if (len > 0) { ipaddress = _lldpctl_alloc_in_atom(atom, len); if (!ipaddress) return NULL; - if (inet_ntop((chassis->c_id[0] == LLDP_MGMT_ADDR_IP4)? - AF_INET:AF_INET6, + if (inet_ntop((chassis->c_id[0] == LLDP_MGMT_ADDR_IP4) ? + AF_INET : + AF_INET6, &chassis->c_id[1], ipaddress, len) == NULL) break; return ipaddress; @@ -206,8 +202,10 @@ _lldpctl_atom_get_str_chassis(lldpctl_atom_t *atom, lldpctl_key_t key) } SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); return NULL; - case lldpctl_k_chassis_name: return chassis->c_name; - case lldpctl_k_chassis_descr: return chassis->c_descr; + case lldpctl_k_chassis_name: + return chassis->c_name; + case lldpctl_k_chassis_descr: + return chassis->c_descr; #ifdef ENABLE_LLDPMED case lldpctl_k_chassis_med_type: @@ -234,20 +232,19 @@ _lldpctl_atom_get_str_chassis(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* -_lldpctl_atom_set_int_chassis(lldpctl_atom_t *atom, lldpctl_key_t key, - long int value) +static lldpctl_atom_t * +_lldpctl_atom_set_int_chassis(lldpctl_atom_t *atom, lldpctl_key_t key, long int value) { int rc; char *canary = NULL; - struct _lldpctl_atom_chassis_t *c = - (struct _lldpctl_atom_chassis_t *) atom; + struct _lldpctl_atom_chassis_t *c = (struct _lldpctl_atom_chassis_t *)atom; struct lldpd_chassis chassis; memcpy(&chassis, c->chassis, sizeof(struct lldpd_chassis)); switch (key) { case lldpctl_k_chassis_cap_enabled: - chassis.c_cap_enabled = c->chassis->c_cap_enabled = chassis.c_cap_available & value; + chassis.c_cap_enabled = c->chassis->c_cap_enabled = + chassis.c_cap_available & value; break; default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); @@ -259,11 +256,9 @@ _lldpctl_atom_set_int_chassis(lldpctl_atom_t *atom, lldpctl_key_t key, return NULL; } - rc = _lldpctl_do_something(atom->conn, - CONN_STATE_SET_CHASSIS_SEND, CONN_STATE_SET_CHASSIS_RECV, - canary, - SET_CHASSIS, &chassis, &MARSHAL_INFO(lldpd_chassis), - NULL, NULL); + rc = _lldpctl_do_something(atom->conn, CONN_STATE_SET_CHASSIS_SEND, + CONN_STATE_SET_CHASSIS_RECV, canary, SET_CHASSIS, &chassis, + &MARSHAL_INFO(lldpd_chassis), NULL, NULL); free(canary); if (rc == 0) return atom; @@ -273,8 +268,7 @@ _lldpctl_atom_set_int_chassis(lldpctl_atom_t *atom, lldpctl_key_t key, static long int _lldpctl_atom_get_int_chassis(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_chassis_t *p = - (struct _lldpctl_atom_chassis_t *)atom; + struct _lldpctl_atom_chassis_t *p = (struct _lldpctl_atom_chassis_t *)atom; struct lldpd_chassis *chassis = p->chassis; /* Local and remote port */ @@ -299,35 +293,35 @@ _lldpctl_atom_get_int_chassis(lldpctl_atom_t *atom, lldpctl_key_t key) return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); } -static const uint8_t* +static const uint8_t * _lldpctl_atom_get_buf_chassis(lldpctl_atom_t *atom, lldpctl_key_t key, size_t *n) { - struct _lldpctl_atom_chassis_t *p = - (struct _lldpctl_atom_chassis_t *)atom; + struct _lldpctl_atom_chassis_t *p = (struct _lldpctl_atom_chassis_t *)atom; struct lldpd_chassis *chassis = p->chassis; switch (key) { case lldpctl_k_chassis_id: *n = chassis->c_id_len; - return (uint8_t*)chassis->c_id; + return (uint8_t *)chassis->c_id; default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); return NULL; } } -static struct atom_builder chassis = - { atom_chassis, sizeof(struct _lldpctl_atom_chassis_t), - .init = _lldpctl_atom_new_chassis, - .free = _lldpctl_atom_free_chassis, - .get = _lldpctl_atom_get_atom_chassis, - .get_str = _lldpctl_atom_get_str_chassis, - .get_int = _lldpctl_atom_get_int_chassis, - .set_int = _lldpctl_atom_set_int_chassis, - .get_buffer = _lldpctl_atom_get_buf_chassis, +static struct atom_builder chassis = { + atom_chassis, + sizeof(struct _lldpctl_atom_chassis_t), + .init = _lldpctl_atom_new_chassis, + .free = _lldpctl_atom_free_chassis, + .get = _lldpctl_atom_get_atom_chassis, + .get_str = _lldpctl_atom_get_str_chassis, + .get_int = _lldpctl_atom_get_int_chassis, + .set_int = _lldpctl_atom_set_int_chassis, + .get_buffer = _lldpctl_atom_get_buf_chassis, #ifdef ENABLE_LLDPMED - .set_str = _lldpctl_atom_set_str_chassis, + .set_str = _lldpctl_atom_set_str_chassis, #endif - }; +}; ATOM_BUILDER_REGISTER(chassis, 3); diff --git a/src/lib/atoms/config.c b/src/lib/atoms/config.c index 675e6f62..8a4af2e8 100644 --- a/src/lib/atoms/config.c +++ b/src/lib/atoms/config.c @@ -57,14 +57,13 @@ static struct atom_map lldp_agent_map = { }; ATOM_MAP_REGISTER(bond_slave_src_mac_map, 1); -ATOM_MAP_REGISTER(lldp_portid_map, 2); -ATOM_MAP_REGISTER(lldp_agent_map, 3); +ATOM_MAP_REGISTER(lldp_portid_map, 2); +ATOM_MAP_REGISTER(lldp_agent_map, 3); static int _lldpctl_atom_new_config(lldpctl_atom_t *atom, va_list ap) { - struct _lldpctl_atom_config_t *c = - (struct _lldpctl_atom_config_t *)atom; + struct _lldpctl_atom_config_t *c = (struct _lldpctl_atom_config_t *)atom; c->config = va_arg(ap, struct lldpd_config *); return 1; } @@ -72,55 +71,59 @@ _lldpctl_atom_new_config(lldpctl_atom_t *atom, va_list ap) static void _lldpctl_atom_free_config(lldpctl_atom_t *atom) { - struct _lldpctl_atom_config_t *c = - (struct _lldpctl_atom_config_t *)atom; + struct _lldpctl_atom_config_t *c = (struct _lldpctl_atom_config_t *)atom; lldpd_config_cleanup(c->config); free(c->config); } -static const char* +static const char * _lldpctl_atom_get_str_config(lldpctl_atom_t *atom, lldpctl_key_t key) { char *res = NULL; - struct _lldpctl_atom_config_t *c = - (struct _lldpctl_atom_config_t *)atom; + struct _lldpctl_atom_config_t *c = (struct _lldpctl_atom_config_t *)atom; switch (key) { case lldpctl_k_config_mgmt_pattern: - res = c->config->c_mgmt_pattern; break; + res = c->config->c_mgmt_pattern; + break; case lldpctl_k_config_iface_pattern: - res = c->config->c_iface_pattern; break; + res = c->config->c_iface_pattern; + break; case lldpctl_k_config_perm_iface_pattern: - res = c->config->c_perm_ifaces; break; + res = c->config->c_perm_ifaces; + break; case lldpctl_k_config_cid_pattern: - res = c->config->c_cid_pattern; break; + res = c->config->c_cid_pattern; + break; case lldpctl_k_config_cid_string: - res = c->config->c_cid_string; break; + res = c->config->c_cid_string; + break; case lldpctl_k_config_description: - res = c->config->c_description; break; + res = c->config->c_description; + break; case lldpctl_k_config_platform: - res = c->config->c_platform; break; + res = c->config->c_platform; + break; case lldpctl_k_config_hostname: - res = c->config->c_hostname; break; + res = c->config->c_hostname; + break; case lldpctl_k_config_bond_slave_src_mac_type: return map_lookup(bond_slave_src_mac_map.map, - c->config->c_bond_slave_src_mac_type); + c->config->c_bond_slave_src_mac_type); case lldpctl_k_config_lldp_portid_type: - return map_lookup(lldp_portid_map.map, - c->config->c_lldp_portid_type); + return map_lookup(lldp_portid_map.map, c->config->c_lldp_portid_type); case lldpctl_k_config_lldp_agent_type: - return map_lookup(lldp_agent_map.map, - c->config->c_lldp_agent_type); + return map_lookup(lldp_agent_map.map, c->config->c_lldp_agent_type); default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); return NULL; } - return res?res:""; + return res ? res : ""; } -static struct _lldpctl_atom_config_t* -__lldpctl_atom_set_str_config(struct _lldpctl_atom_config_t *c, - char **local, char **global, - const char *value) { +static struct _lldpctl_atom_config_t * +__lldpctl_atom_set_str_config(struct _lldpctl_atom_config_t *c, char **local, + char **global, const char *value) +{ if (value) { char *aval = NULL; size_t len = strlen(value) + 1; @@ -128,7 +131,8 @@ __lldpctl_atom_set_str_config(struct _lldpctl_atom_config_t *c, if (!aval) return NULL; memcpy(aval, value, len); *local = aval; - free(*global); *global = strdup(aval); + free(*global); + *global = strdup(aval); } else { free(*global); *local = *global = NULL; @@ -136,12 +140,10 @@ __lldpctl_atom_set_str_config(struct _lldpctl_atom_config_t *c, return c; } -static lldpctl_atom_t* -_lldpctl_atom_set_str_config(lldpctl_atom_t *atom, lldpctl_key_t key, - const char *value) +static lldpctl_atom_t * +_lldpctl_atom_set_str_config(lldpctl_atom_t *atom, lldpctl_key_t key, const char *value) { - struct _lldpctl_atom_config_t *c = - (struct _lldpctl_atom_config_t *)atom; + struct _lldpctl_atom_config_t *c = (struct _lldpctl_atom_config_t *)atom; struct lldpd_config config; memcpy(&config, c->config, sizeof(struct lldpd_config)); char *canary = NULL; @@ -149,45 +151,38 @@ _lldpctl_atom_set_str_config(lldpctl_atom_t *atom, lldpctl_key_t key, switch (key) { case lldpctl_k_config_perm_iface_pattern: - if (!__lldpctl_atom_set_str_config(c, - &config.c_perm_ifaces, &c->config->c_perm_ifaces, - value)) + if (!__lldpctl_atom_set_str_config(c, &config.c_perm_ifaces, + &c->config->c_perm_ifaces, value)) return NULL; break; case lldpctl_k_config_iface_pattern: - if (!__lldpctl_atom_set_str_config(c, - &config.c_iface_pattern, &c->config->c_iface_pattern, - value)) + if (!__lldpctl_atom_set_str_config(c, &config.c_iface_pattern, + &c->config->c_iface_pattern, value)) return NULL; break; case lldpctl_k_config_mgmt_pattern: - if (!__lldpctl_atom_set_str_config(c, - &config.c_mgmt_pattern, &c->config->c_mgmt_pattern, - value)) + if (!__lldpctl_atom_set_str_config(c, &config.c_mgmt_pattern, + &c->config->c_mgmt_pattern, value)) return NULL; break; case lldpctl_k_config_cid_string: - if (!__lldpctl_atom_set_str_config(c, - &config.c_cid_string, &c->config->c_cid_string, - value)) + if (!__lldpctl_atom_set_str_config(c, &config.c_cid_string, + &c->config->c_cid_string, value)) return NULL; break; case lldpctl_k_config_description: - if (!__lldpctl_atom_set_str_config(c, - &config.c_description, &c->config->c_description, - value)) + if (!__lldpctl_atom_set_str_config(c, &config.c_description, + &c->config->c_description, value)) return NULL; break; case lldpctl_k_config_platform: - if (!__lldpctl_atom_set_str_config(c, - &config.c_platform, &c->config->c_platform, - value)) + if (!__lldpctl_atom_set_str_config(c, &config.c_platform, + &c->config->c_platform, value)) return NULL; break; case lldpctl_k_config_hostname: - if (!__lldpctl_atom_set_str_config(c, - &config.c_hostname, &c->config->c_hostname, - value)) + if (!__lldpctl_atom_set_str_config(c, &config.c_hostname, + &c->config->c_hostname, value)) return NULL; break; default: @@ -195,15 +190,13 @@ _lldpctl_atom_set_str_config(lldpctl_atom_t *atom, lldpctl_key_t key, return NULL; } - if (asprintf(&canary, "%d%s", key, value?value:"(NULL)") == -1) { + if (asprintf(&canary, "%d%s", key, value ? value : "(NULL)") == -1) { SET_ERROR(atom->conn, LLDPCTL_ERR_NOMEM); return NULL; } - rc = _lldpctl_do_something(atom->conn, - CONN_STATE_SET_CONFIG_SEND, CONN_STATE_SET_CONFIG_RECV, - canary, - SET_CONFIG, &config, &MARSHAL_INFO(lldpd_config), - NULL, NULL); + rc = _lldpctl_do_something(atom->conn, CONN_STATE_SET_CONFIG_SEND, + CONN_STATE_SET_CONFIG_RECV, canary, SET_CONFIG, &config, + &MARSHAL_INFO(lldpd_config), NULL, NULL); free(canary); if (rc == 0) return atom; @@ -215,13 +208,12 @@ _lldpctl_atom_set_str_config(lldpctl_atom_t *atom, lldpctl_key_t key, static long int _lldpctl_atom_get_int_config(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_config_t *c = - (struct _lldpctl_atom_config_t *)atom; + struct _lldpctl_atom_config_t *c = (struct _lldpctl_atom_config_t *)atom; switch (key) { case lldpctl_k_config_paused: return c->config->c_paused; case lldpctl_k_config_tx_interval: - return (c->config->c_tx_interval+999)/1000; /* s units */ + return (c->config->c_tx_interval + 999) / 1000; /* s units */ case lldpctl_k_config_tx_interval_ms: return c->config->c_tx_interval; /* ms units */ case lldpctl_k_config_receiveonly: @@ -255,14 +247,12 @@ _lldpctl_atom_get_int_config(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* -_lldpctl_atom_set_int_config(lldpctl_atom_t *atom, lldpctl_key_t key, - long int value) +static lldpctl_atom_t * +_lldpctl_atom_set_int_config(lldpctl_atom_t *atom, lldpctl_key_t key, long int value) { int rc; char *canary = NULL; - struct _lldpctl_atom_config_t *c = - (struct _lldpctl_atom_config_t *)atom; + struct _lldpctl_atom_config_t *c = (struct _lldpctl_atom_config_t *)atom; struct lldpd_config config; memcpy(&config, c->config, sizeof(struct lldpd_config)); @@ -330,23 +320,19 @@ _lldpctl_atom_set_int_config(lldpctl_atom_t *atom, lldpctl_key_t key, SET_ERROR(atom->conn, LLDPCTL_ERR_NOMEM); return NULL; } - rc = _lldpctl_do_something(atom->conn, - CONN_STATE_SET_CONFIG_SEND, CONN_STATE_SET_CONFIG_RECV, - canary, - SET_CONFIG, &config, &MARSHAL_INFO(lldpd_config), - NULL, NULL); + rc = _lldpctl_do_something(atom->conn, CONN_STATE_SET_CONFIG_SEND, + CONN_STATE_SET_CONFIG_RECV, canary, SET_CONFIG, &config, + &MARSHAL_INFO(lldpd_config), NULL, NULL); free(canary); if (rc == 0) return atom; return NULL; } -static struct atom_builder config = - { atom_config, sizeof(struct _lldpctl_atom_config_t), - .init = _lldpctl_atom_new_config, - .free = _lldpctl_atom_free_config, - .get_str = _lldpctl_atom_get_str_config, - .set_str = _lldpctl_atom_set_str_config, - .get_int = _lldpctl_atom_get_int_config, - .set_int = _lldpctl_atom_set_int_config }; +static struct atom_builder config = { atom_config, + sizeof(struct _lldpctl_atom_config_t), .init = _lldpctl_atom_new_config, + .free = _lldpctl_atom_free_config, .get_str = _lldpctl_atom_get_str_config, + .set_str = _lldpctl_atom_set_str_config, + .get_int = _lldpctl_atom_get_int_config, + .set_int = _lldpctl_atom_set_int_config }; ATOM_BUILDER_REGISTER(config, 1); diff --git a/src/lib/atoms/custom.c b/src/lib/atoms/custom.c index 457a047d..ffa5b039 100644 --- a/src/lib/atoms/custom.c +++ b/src/lib/atoms/custom.c @@ -28,32 +28,32 @@ #ifdef ENABLE_CUSTOM -#define min(x,y) ( (x > y) ? y : x ) +# define min(x, y) ((x > y) ? y : x) -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_iter_custom_list(lldpctl_atom_t *atom) { struct _lldpctl_atom_custom_list_t *custom = (struct _lldpctl_atom_custom_list_t *)atom; - return (lldpctl_atom_iter_t*)TAILQ_FIRST(&custom->parent->port->p_custom_list); + return (lldpctl_atom_iter_t *)TAILQ_FIRST(&custom->parent->port->p_custom_list); } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_next_custom_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { - return (lldpctl_atom_iter_t*)TAILQ_NEXT((struct lldpd_custom *)iter, next); + return (lldpctl_atom_iter_t *)TAILQ_NEXT((struct lldpd_custom *)iter, next); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_value_custom_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct _lldpctl_atom_custom_list_t *custom = (struct _lldpctl_atom_custom_list_t *)atom; - struct lldpd_custom *tlv = (struct lldpd_custom *) iter; + struct lldpd_custom *tlv = (struct lldpd_custom *)iter; return _lldpctl_new_atom(atom->conn, atom_custom, custom->parent, tlv); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_create_custom_list(lldpctl_atom_t *atom) { struct _lldpctl_atom_custom_list_t *custom = @@ -61,19 +61,17 @@ _lldpctl_atom_create_custom_list(lldpctl_atom_t *atom) struct lldpd_custom *tlv; tlv = _lldpctl_alloc_in_atom(atom, sizeof(struct lldpd_custom)); - if (!tlv) - return NULL; + if (!tlv) return NULL; return _lldpctl_new_atom(atom->conn, atom_custom, custom->parent, tlv); } static int _lldpctl_atom_new_custom(lldpctl_atom_t *atom, va_list ap) { - struct _lldpctl_atom_custom_t *custom = - (struct _lldpctl_atom_custom_t *)atom; + struct _lldpctl_atom_custom_t *custom = (struct _lldpctl_atom_custom_t *)atom; custom->parent = va_arg(ap, struct _lldpctl_atom_port_t *); - custom->tlv = va_arg(ap, struct lldpd_custom *); + custom->tlv = va_arg(ap, struct lldpd_custom *); lldpctl_atom_inc_ref((lldpctl_atom_t *)custom->parent); return 1; } @@ -81,16 +79,14 @@ _lldpctl_atom_new_custom(lldpctl_atom_t *atom, va_list ap) static void _lldpctl_atom_free_custom(lldpctl_atom_t *atom) { - struct _lldpctl_atom_custom_t *custom = - (struct _lldpctl_atom_custom_t *)atom; + struct _lldpctl_atom_custom_t *custom = (struct _lldpctl_atom_custom_t *)atom; lldpctl_atom_dec_ref((lldpctl_atom_t *)custom->parent); } static long int _lldpctl_atom_get_int_custom(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_custom_t *custom = - (struct _lldpctl_atom_custom_t *)atom; + struct _lldpctl_atom_custom_t *custom = (struct _lldpctl_atom_custom_t *)atom; switch (key) { case lldpctl_k_custom_tlv_oui_subtype: @@ -100,15 +96,12 @@ _lldpctl_atom_get_int_custom(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* -_lldpctl_atom_set_str_custom(lldpctl_atom_t *atom, lldpctl_key_t key, - const char *value) +static lldpctl_atom_t * +_lldpctl_atom_set_str_custom(lldpctl_atom_t *atom, lldpctl_key_t key, const char *value) { - struct _lldpctl_atom_custom_t *custom = - (struct _lldpctl_atom_custom_t *)atom; + struct _lldpctl_atom_custom_t *custom = (struct _lldpctl_atom_custom_t *)atom; - if (!value || !strlen(value)) - return NULL; + if (!value || !strlen(value)) return NULL; /* Only local port can be modified */ if (!custom->parent->local) { @@ -134,12 +127,10 @@ _lldpctl_atom_set_str_custom(lldpctl_atom_t *atom, lldpctl_key_t key, return NULL; } -static lldpctl_atom_t* -_lldpctl_atom_set_int_custom(lldpctl_atom_t *atom, lldpctl_key_t key, - long int value) +static lldpctl_atom_t * +_lldpctl_atom_set_int_custom(lldpctl_atom_t *atom, lldpctl_key_t key, long int value) { - struct _lldpctl_atom_custom_t *custom = - (struct _lldpctl_atom_custom_t *)atom; + struct _lldpctl_atom_custom_t *custom = (struct _lldpctl_atom_custom_t *)atom; /* Only local port can be modified */ if (!custom->parent->local) { @@ -161,11 +152,10 @@ bad: return NULL; } -static const uint8_t* +static const uint8_t * _lldpctl_atom_get_buffer_custom(lldpctl_atom_t *atom, lldpctl_key_t key, size_t *n) { - struct _lldpctl_atom_custom_t *custom = - (struct _lldpctl_atom_custom_t *)atom; + struct _lldpctl_atom_custom_t *custom = (struct _lldpctl_atom_custom_t *)atom; switch (key) { case lldpctl_k_custom_tlv_oui: @@ -180,12 +170,11 @@ _lldpctl_atom_get_buffer_custom(lldpctl_atom_t *atom, lldpctl_key_t key, size_t } } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_buffer_custom(lldpctl_atom_t *atom, lldpctl_key_t key, const u_int8_t *buf, size_t n) { - struct _lldpctl_atom_custom_t *custom = - (struct _lldpctl_atom_custom_t *)atom; + struct _lldpctl_atom_custom_t *custom = (struct _lldpctl_atom_custom_t *)atom; /* Only local port can be modified */ if (!custom->parent->local) { @@ -216,27 +205,22 @@ _lldpctl_atom_set_buffer_custom(lldpctl_atom_t *atom, lldpctl_key_t key, } } -static struct atom_builder custom_list = - { atom_custom_list, sizeof(struct _lldpctl_atom_any_list_t), - .init = _lldpctl_atom_new_any_list, - .free = _lldpctl_atom_free_any_list, - .iter = _lldpctl_atom_iter_custom_list, - .next = _lldpctl_atom_next_custom_list, - .value = _lldpctl_atom_value_custom_list, - .create = _lldpctl_atom_create_custom_list }; - -static struct atom_builder custom = - { atom_custom, sizeof(struct _lldpctl_atom_custom_t), - .init = _lldpctl_atom_new_custom, - .free = _lldpctl_atom_free_custom, - .get_int = _lldpctl_atom_get_int_custom, - .set_int = _lldpctl_atom_set_int_custom, - .set_str = _lldpctl_atom_set_str_custom, - .get_buffer = _lldpctl_atom_get_buffer_custom, - .set_buffer = _lldpctl_atom_set_buffer_custom }; +static struct atom_builder custom_list = { atom_custom_list, + sizeof(struct _lldpctl_atom_any_list_t), .init = _lldpctl_atom_new_any_list, + .free = _lldpctl_atom_free_any_list, .iter = _lldpctl_atom_iter_custom_list, + .next = _lldpctl_atom_next_custom_list, + .value = _lldpctl_atom_value_custom_list, + .create = _lldpctl_atom_create_custom_list }; + +static struct atom_builder custom = { atom_custom, + sizeof(struct _lldpctl_atom_custom_t), .init = _lldpctl_atom_new_custom, + .free = _lldpctl_atom_free_custom, .get_int = _lldpctl_atom_get_int_custom, + .set_int = _lldpctl_atom_set_int_custom, + .set_str = _lldpctl_atom_set_str_custom, + .get_buffer = _lldpctl_atom_get_buffer_custom, + .set_buffer = _lldpctl_atom_set_buffer_custom }; ATOM_BUILDER_REGISTER(custom_list, 22); -ATOM_BUILDER_REGISTER(custom, 23); +ATOM_BUILDER_REGISTER(custom, 23); #endif /* ENABLE_CUSTOM */ - diff --git a/src/lib/atoms/dot1.c b/src/lib/atoms/dot1.c index 66f76f5f..c2feda04 100644 --- a/src/lib/atoms/dot1.c +++ b/src/lib/atoms/dot1.c @@ -27,22 +27,22 @@ #ifdef ENABLE_DOT1 -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_iter_vlans_list(lldpctl_atom_t *atom) { struct _lldpctl_atom_any_list_t *vlist = (struct _lldpctl_atom_any_list_t *)atom; - return (lldpctl_atom_iter_t*)TAILQ_FIRST(&vlist->parent->port->p_vlans); + return (lldpctl_atom_iter_t *)TAILQ_FIRST(&vlist->parent->port->p_vlans); } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_next_vlans_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct lldpd_vlan *vlan = (struct lldpd_vlan *)iter; - return (lldpctl_atom_iter_t*)TAILQ_NEXT(vlan, v_entries); + return (lldpctl_atom_iter_t *)TAILQ_NEXT(vlan, v_entries); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_value_vlans_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct _lldpctl_atom_any_list_t *vlist = @@ -54,8 +54,7 @@ _lldpctl_atom_value_vlans_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) static int _lldpctl_atom_new_vlan(lldpctl_atom_t *atom, va_list ap) { - struct _lldpctl_atom_vlan_t *vlan = - (struct _lldpctl_atom_vlan_t *)atom; + struct _lldpctl_atom_vlan_t *vlan = (struct _lldpctl_atom_vlan_t *)atom; vlan->parent = va_arg(ap, struct _lldpctl_atom_port_t *); vlan->vlan = va_arg(ap, struct lldpd_vlan *); lldpctl_atom_inc_ref((lldpctl_atom_t *)vlan->parent); @@ -65,16 +64,14 @@ _lldpctl_atom_new_vlan(lldpctl_atom_t *atom, va_list ap) static void _lldpctl_atom_free_vlan(lldpctl_atom_t *atom) { - struct _lldpctl_atom_vlan_t *vlan = - (struct _lldpctl_atom_vlan_t *)atom; + struct _lldpctl_atom_vlan_t *vlan = (struct _lldpctl_atom_vlan_t *)atom; lldpctl_atom_dec_ref((lldpctl_atom_t *)vlan->parent); } -static const char* +static const char * _lldpctl_atom_get_str_vlan(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_vlan_t *m = - (struct _lldpctl_atom_vlan_t *)atom; + struct _lldpctl_atom_vlan_t *m = (struct _lldpctl_atom_vlan_t *)atom; /* Local and remote port */ switch (key) { @@ -89,8 +86,7 @@ _lldpctl_atom_get_str_vlan(lldpctl_atom_t *atom, lldpctl_key_t key) static long int _lldpctl_atom_get_int_vlan(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_vlan_t *m = - (struct _lldpctl_atom_vlan_t *)atom; + struct _lldpctl_atom_vlan_t *m = (struct _lldpctl_atom_vlan_t *)atom; /* Local and remote port */ switch (key) { @@ -101,22 +97,22 @@ _lldpctl_atom_get_int_vlan(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_iter_ppvids_list(lldpctl_atom_t *atom) { struct _lldpctl_atom_any_list_t *vlist = (struct _lldpctl_atom_any_list_t *)atom; - return (lldpctl_atom_iter_t*)TAILQ_FIRST(&vlist->parent->port->p_ppvids); + return (lldpctl_atom_iter_t *)TAILQ_FIRST(&vlist->parent->port->p_ppvids); } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_next_ppvids_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct lldpd_ppvid *ppvid = (struct lldpd_ppvid *)iter; - return (lldpctl_atom_iter_t*)TAILQ_NEXT(ppvid, p_entries); + return (lldpctl_atom_iter_t *)TAILQ_NEXT(ppvid, p_entries); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_value_ppvids_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct _lldpctl_atom_any_list_t *vlist = @@ -128,8 +124,7 @@ _lldpctl_atom_value_ppvids_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) static int _lldpctl_atom_new_ppvid(lldpctl_atom_t *atom, va_list ap) { - struct _lldpctl_atom_ppvid_t *ppvid = - (struct _lldpctl_atom_ppvid_t *)atom; + struct _lldpctl_atom_ppvid_t *ppvid = (struct _lldpctl_atom_ppvid_t *)atom; ppvid->parent = va_arg(ap, struct _lldpctl_atom_port_t *); ppvid->ppvid = va_arg(ap, struct lldpd_ppvid *); lldpctl_atom_inc_ref((lldpctl_atom_t *)ppvid->parent); @@ -139,16 +134,14 @@ _lldpctl_atom_new_ppvid(lldpctl_atom_t *atom, va_list ap) static void _lldpctl_atom_free_ppvid(lldpctl_atom_t *atom) { - struct _lldpctl_atom_ppvid_t *ppvid = - (struct _lldpctl_atom_ppvid_t *)atom; + struct _lldpctl_atom_ppvid_t *ppvid = (struct _lldpctl_atom_ppvid_t *)atom; lldpctl_atom_dec_ref((lldpctl_atom_t *)ppvid->parent); } static long int _lldpctl_atom_get_int_ppvid(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_ppvid_t *m = - (struct _lldpctl_atom_ppvid_t *)atom; + struct _lldpctl_atom_ppvid_t *m = (struct _lldpctl_atom_ppvid_t *)atom; /* Local and remote port */ switch (key) { @@ -161,22 +154,22 @@ _lldpctl_atom_get_int_ppvid(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_iter_pis_list(lldpctl_atom_t *atom) { struct _lldpctl_atom_any_list_t *vlist = (struct _lldpctl_atom_any_list_t *)atom; - return (lldpctl_atom_iter_t*)TAILQ_FIRST(&vlist->parent->port->p_pids); + return (lldpctl_atom_iter_t *)TAILQ_FIRST(&vlist->parent->port->p_pids); } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_next_pis_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct lldpd_pi *pi = (struct lldpd_pi *)iter; - return (lldpctl_atom_iter_t*)TAILQ_NEXT(pi, p_entries); + return (lldpctl_atom_iter_t *)TAILQ_NEXT(pi, p_entries); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_value_pis_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct _lldpctl_atom_any_list_t *vlist = @@ -188,8 +181,7 @@ _lldpctl_atom_value_pis_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) static int _lldpctl_atom_new_pi(lldpctl_atom_t *atom, va_list ap) { - struct _lldpctl_atom_pi_t *pi = - (struct _lldpctl_atom_pi_t *)atom; + struct _lldpctl_atom_pi_t *pi = (struct _lldpctl_atom_pi_t *)atom; pi->parent = va_arg(ap, struct _lldpctl_atom_port_t *); pi->pi = va_arg(ap, struct lldpd_pi *); lldpctl_atom_inc_ref((lldpctl_atom_t *)pi->parent); @@ -199,77 +191,60 @@ _lldpctl_atom_new_pi(lldpctl_atom_t *atom, va_list ap) static void _lldpctl_atom_free_pi(lldpctl_atom_t *atom) { - struct _lldpctl_atom_pi_t *pi = - (struct _lldpctl_atom_pi_t *)atom; + struct _lldpctl_atom_pi_t *pi = (struct _lldpctl_atom_pi_t *)atom; lldpctl_atom_dec_ref((lldpctl_atom_t *)pi->parent); } -static const uint8_t* +static const uint8_t * _lldpctl_atom_get_buf_pi(lldpctl_atom_t *atom, lldpctl_key_t key, size_t *n) { - struct _lldpctl_atom_pi_t *m = - (struct _lldpctl_atom_pi_t *)atom; + struct _lldpctl_atom_pi_t *m = (struct _lldpctl_atom_pi_t *)atom; /* Local and remote port */ switch (key) { case lldpctl_k_pi_id: *n = m->pi->p_pi_len; - return (const uint8_t*)m->pi->p_pi; + return (const uint8_t *)m->pi->p_pi; default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); return NULL; } } -static struct atom_builder vlans_list = - { atom_vlans_list, sizeof(struct _lldpctl_atom_any_list_t), - .init = _lldpctl_atom_new_any_list, - .free = _lldpctl_atom_free_any_list, - .iter = _lldpctl_atom_iter_vlans_list, - .next = _lldpctl_atom_next_vlans_list, - .value = _lldpctl_atom_value_vlans_list }; - -static struct atom_builder vlan = - { atom_vlan, sizeof(struct _lldpctl_atom_vlan_t), - .init = _lldpctl_atom_new_vlan, - .free = _lldpctl_atom_free_vlan, - .get_str = _lldpctl_atom_get_str_vlan, - .get_int = _lldpctl_atom_get_int_vlan }; - -static struct atom_builder ppvids_list = - { atom_ppvids_list, sizeof(struct _lldpctl_atom_any_list_t), - .init = _lldpctl_atom_new_any_list, - .free = _lldpctl_atom_free_any_list, - .iter = _lldpctl_atom_iter_ppvids_list, - .next = _lldpctl_atom_next_ppvids_list, - .value = _lldpctl_atom_value_ppvids_list }; - -static struct atom_builder ppvid = - { atom_ppvid, sizeof(struct _lldpctl_atom_ppvid_t), - .init = _lldpctl_atom_new_ppvid, - .free = _lldpctl_atom_free_ppvid, - .get_int = _lldpctl_atom_get_int_ppvid }; - -static struct atom_builder pis_list = - { atom_pis_list, sizeof(struct _lldpctl_atom_any_list_t), - .init = _lldpctl_atom_new_any_list, - .free = _lldpctl_atom_free_any_list, - .iter = _lldpctl_atom_iter_pis_list, - .next = _lldpctl_atom_next_pis_list, - .value = _lldpctl_atom_value_pis_list }; - -static struct atom_builder pi = - { atom_pi, sizeof(struct _lldpctl_atom_pi_t), - .init = _lldpctl_atom_new_pi, - .free = _lldpctl_atom_free_pi, - .get_buffer = _lldpctl_atom_get_buf_pi }; - -ATOM_BUILDER_REGISTER(vlans_list, 9); -ATOM_BUILDER_REGISTER(vlan, 10); +static struct atom_builder vlans_list = { atom_vlans_list, + sizeof(struct _lldpctl_atom_any_list_t), .init = _lldpctl_atom_new_any_list, + .free = _lldpctl_atom_free_any_list, .iter = _lldpctl_atom_iter_vlans_list, + .next = _lldpctl_atom_next_vlans_list, + .value = _lldpctl_atom_value_vlans_list }; + +static struct atom_builder vlan = { atom_vlan, sizeof(struct _lldpctl_atom_vlan_t), + .init = _lldpctl_atom_new_vlan, .free = _lldpctl_atom_free_vlan, + .get_str = _lldpctl_atom_get_str_vlan, .get_int = _lldpctl_atom_get_int_vlan }; + +static struct atom_builder ppvids_list = { atom_ppvids_list, + sizeof(struct _lldpctl_atom_any_list_t), .init = _lldpctl_atom_new_any_list, + .free = _lldpctl_atom_free_any_list, .iter = _lldpctl_atom_iter_ppvids_list, + .next = _lldpctl_atom_next_ppvids_list, + .value = _lldpctl_atom_value_ppvids_list }; + +static struct atom_builder ppvid = { atom_ppvid, sizeof(struct _lldpctl_atom_ppvid_t), + .init = _lldpctl_atom_new_ppvid, .free = _lldpctl_atom_free_ppvid, + .get_int = _lldpctl_atom_get_int_ppvid }; + +static struct atom_builder pis_list = { atom_pis_list, + sizeof(struct _lldpctl_atom_any_list_t), .init = _lldpctl_atom_new_any_list, + .free = _lldpctl_atom_free_any_list, .iter = _lldpctl_atom_iter_pis_list, + .next = _lldpctl_atom_next_pis_list, .value = _lldpctl_atom_value_pis_list }; + +static struct atom_builder pi = { atom_pi, sizeof(struct _lldpctl_atom_pi_t), + .init = _lldpctl_atom_new_pi, .free = _lldpctl_atom_free_pi, + .get_buffer = _lldpctl_atom_get_buf_pi }; + +ATOM_BUILDER_REGISTER(vlans_list, 9); +ATOM_BUILDER_REGISTER(vlan, 10); ATOM_BUILDER_REGISTER(ppvids_list, 11); -ATOM_BUILDER_REGISTER(ppvid, 12); -ATOM_BUILDER_REGISTER(pis_list, 13); -ATOM_BUILDER_REGISTER(pi, 14); +ATOM_BUILDER_REGISTER(ppvid, 12); +ATOM_BUILDER_REGISTER(pis_list, 13); +ATOM_BUILDER_REGISTER(pi, 14); #endif - diff --git a/src/lib/atoms/dot3.c b/src/lib/atoms/dot3.c index b6b08460..b6347b73 100644 --- a/src/lib/atoms/dot3.c +++ b/src/lib/atoms/dot3.c @@ -28,42 +28,28 @@ #ifdef ENABLE_DOT3 static lldpctl_map_t port_dot3_power_devicetype_map[] = { - { LLDP_DOT3_POWER_PSE, "PSE" }, - { LLDP_DOT3_POWER_PD, "PD" }, - { 0, NULL } + { LLDP_DOT3_POWER_PSE, "PSE" }, { LLDP_DOT3_POWER_PD, "PD" }, { 0, NULL } }; -static lldpctl_map_t port_dot3_power_pse_source_map[] = { - { LLDP_DOT3_POWER_SOURCE_BOTH, "PSE + Local" }, - { LLDP_DOT3_POWER_SOURCE_PSE, "PSE" }, - { 0, NULL } -}; +static lldpctl_map_t port_dot3_power_pse_source_map[] = { { LLDP_DOT3_POWER_SOURCE_BOTH, + "PSE + Local" }, + { LLDP_DOT3_POWER_SOURCE_PSE, "PSE" }, { 0, NULL } }; static lldpctl_map_t port_dot3_power_pd_source_map[] = { { LLDP_DOT3_POWER_SOURCE_BACKUP, "Backup source" }, - { LLDP_DOT3_POWER_SOURCE_PRIMARY, "Primary power source" }, - { 0, NULL } + { LLDP_DOT3_POWER_SOURCE_PRIMARY, "Primary power source" }, { 0, NULL } }; static struct atom_map port_dot3_power_pairs_map = { .key = lldpctl_k_dot3_power_pairs, - .map = { - { LLDP_DOT3_POWERPAIRS_SIGNAL, "signal" }, - { LLDP_DOT3_POWERPAIRS_SPARE, "spare" }, - { 0, NULL } - }, + .map = { { LLDP_DOT3_POWERPAIRS_SIGNAL, "signal" }, + { LLDP_DOT3_POWERPAIRS_SPARE, "spare" }, { 0, NULL } }, }; static struct atom_map port_dot3_power_class_map = { .key = lldpctl_k_dot3_power_class, - .map = { - { 1, "class 0" }, - { 2, "class 1" }, - { 3, "class 2" }, - { 4, "class 3" }, - { 5, "class 4" }, - { 0, NULL } - }, + .map = { { 1, "class 0" }, { 2, "class 1" }, { 3, "class 2" }, { 4, "class 3" }, + { 5, "class 4" }, { 0, NULL } }, }; static struct atom_map port_dot3_power_priority_map = { @@ -190,9 +176,8 @@ static struct atom_map port_dot3_power_pd_load_map = { }, }; - -ATOM_MAP_REGISTER(port_dot3_power_pairs_map, 4); -ATOM_MAP_REGISTER(port_dot3_power_class_map, 5); +ATOM_MAP_REGISTER(port_dot3_power_pairs_map, 4); +ATOM_MAP_REGISTER(port_dot3_power_class_map, 5); ATOM_MAP_REGISTER(port_dot3_power_priority_map, 6); static int @@ -213,12 +198,12 @@ _lldpctl_atom_free_dot3_power(lldpctl_atom_t *atom) lldpctl_atom_dec_ref((lldpctl_atom_t *)dpow->parent); } -static const char* +static const char * _lldpctl_atom_get_str_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key) { struct _lldpctl_atom_dot3_power_t *dpow = (struct _lldpctl_atom_dot3_power_t *)atom; - struct lldpd_port *port = dpow->parent->port; + struct lldpd_port *port = dpow->parent->port; /* Local and remote port */ switch (key) { @@ -226,15 +211,13 @@ _lldpctl_atom_get_str_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key) return map_lookup(port_dot3_power_devicetype_map, port->p_power.devicetype); case lldpctl_k_dot3_power_pairs: - return map_lookup(port_dot3_power_pairs_map.map, - port->p_power.pairs); + return map_lookup(port_dot3_power_pairs_map.map, port->p_power.pairs); case lldpctl_k_dot3_power_class: - return map_lookup(port_dot3_power_class_map.map, - port->p_power.class); + return map_lookup(port_dot3_power_class_map.map, port->p_power.class); case lldpctl_k_dot3_power_source: - return map_lookup((port->p_power.devicetype == LLDP_DOT3_POWER_PSE)? - port_dot3_power_pse_source_map: - port_dot3_power_pd_source_map, + return map_lookup((port->p_power.devicetype == LLDP_DOT3_POWER_PSE) ? + port_dot3_power_pse_source_map : + port_dot3_power_pd_source_map, port->p_power.source); case lldpctl_k_dot3_power_priority: return map_lookup(port_dot3_power_priority_map.map, @@ -277,7 +260,7 @@ _lldpctl_atom_get_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key) { struct _lldpctl_atom_dot3_power_t *dpow = (struct _lldpctl_atom_dot3_power_t *)atom; - struct lldpd_port *port = dpow->parent->port; + struct lldpd_port *port = dpow->parent->port; /* Local and remote port */ switch (key) { @@ -337,7 +320,7 @@ _lldpctl_atom_get_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key, long int value) { @@ -354,12 +337,13 @@ _lldpctl_atom_set_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key, switch (key) { case lldpctl_k_dot3_power_devicetype: switch (value) { - case 0: /* Disabling */ + case 0: /* Disabling */ case LLDP_DOT3_POWER_PSE: case LLDP_DOT3_POWER_PD: port->p_power.devicetype = value; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_dot3_power_supported: switch (value) { @@ -367,7 +351,8 @@ _lldpctl_atom_set_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key, case 1: port->p_power.supported = value; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_dot3_power_enabled: switch (value) { @@ -375,7 +360,8 @@ _lldpctl_atom_set_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key, case 1: port->p_power.enabled = value; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_dot3_power_paircontrol: switch (value) { @@ -383,7 +369,8 @@ _lldpctl_atom_set_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key, case 1: port->p_power.paircontrol = value; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_dot3_power_pairs: switch (value) { @@ -391,11 +378,11 @@ _lldpctl_atom_set_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key, case 2: port->p_power.pairs = value; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_dot3_power_class: - if (value < 0 || value > 5) - goto bad; + if (value < 0 || value > 5) goto bad; port->p_power.class = value; return atom; case lldpctl_k_dot3_power_type: @@ -405,11 +392,11 @@ _lldpctl_atom_set_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key, case LLDP_DOT3_POWER_8023AT_OFF: port->p_power.powertype = value; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_dot3_power_source: - if (value < 0 || value > 3) - goto bad; + if (value < 0 || value > 3) goto bad; port->p_power.source = value; return atom; case lldpctl_k_dot3_power_priority: @@ -420,7 +407,8 @@ _lldpctl_atom_set_int_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key, case LLDP_DOT3_POWER_PRIO_LOW: port->p_power.priority = value; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_dot3_power_allocated: if (value < 0) goto bad; @@ -484,7 +472,7 @@ bad: return NULL; } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_str_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key, const char *value) { @@ -507,16 +495,14 @@ _lldpctl_atom_set_str_dot3_power(lldpctl_atom_t *atom, lldpctl_key_t key, } } -static struct atom_builder dot3_power = - { atom_dot3_power, sizeof(struct _lldpctl_atom_dot3_power_t), - .init = _lldpctl_atom_new_dot3_power, - .free = _lldpctl_atom_free_dot3_power, - .get_int = _lldpctl_atom_get_int_dot3_power, - .set_int = _lldpctl_atom_set_int_dot3_power, - .get_str = _lldpctl_atom_get_str_dot3_power, - .set_str = _lldpctl_atom_set_str_dot3_power }; +static struct atom_builder dot3_power = { atom_dot3_power, + sizeof(struct _lldpctl_atom_dot3_power_t), .init = _lldpctl_atom_new_dot3_power, + .free = _lldpctl_atom_free_dot3_power, + .get_int = _lldpctl_atom_get_int_dot3_power, + .set_int = _lldpctl_atom_set_int_dot3_power, + .get_str = _lldpctl_atom_get_str_dot3_power, + .set_str = _lldpctl_atom_set_str_dot3_power }; ATOM_BUILDER_REGISTER(dot3_power, 8); #endif - diff --git a/src/lib/atoms/interface.c b/src/lib/atoms/interface.c index 54a040d8..95cae3a7 100644 --- a/src/lib/atoms/interface.c +++ b/src/lib/atoms/interface.c @@ -40,9 +40,7 @@ _lldpctl_atom_free_interfaces_list(lldpctl_atom_t *atom) struct _lldpctl_atom_interfaces_list_t *iflist = (struct _lldpctl_atom_interfaces_list_t *)atom; struct lldpd_interface *iface, *iface_next; - for (iface = TAILQ_FIRST(iflist->ifs); - iface != NULL; - iface = iface_next) { + for (iface = TAILQ_FIRST(iflist->ifs); iface != NULL; iface = iface_next) { /* Don't TAILQ_REMOVE, this is not a real list! */ iface_next = TAILQ_NEXT(iface, next); free(iface->name); @@ -51,21 +49,21 @@ _lldpctl_atom_free_interfaces_list(lldpctl_atom_t *atom) free(iflist->ifs); } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_iter_interfaces_list(lldpctl_atom_t *atom) { struct _lldpctl_atom_interfaces_list_t *iflist = (struct _lldpctl_atom_interfaces_list_t *)atom; - return (lldpctl_atom_iter_t*)TAILQ_FIRST(iflist->ifs); + return (lldpctl_atom_iter_t *)TAILQ_FIRST(iflist->ifs); } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_next_interfaces_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { - return (lldpctl_atom_iter_t*)TAILQ_NEXT((struct lldpd_interface *)iter, next); + return (lldpctl_atom_iter_t *)TAILQ_NEXT((struct lldpd_interface *)iter, next); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_value_interfaces_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct lldpd_interface *iface = (struct lldpd_interface *)iter; @@ -89,7 +87,7 @@ _lldpctl_atom_free_interface(lldpctl_atom_t *atom) free(port->name); } -static const char* +static const char * _lldpctl_atom_get_str_interface(lldpctl_atom_t *atom, lldpctl_key_t key) { struct _lldpctl_atom_interface_t *port = @@ -103,20 +101,18 @@ _lldpctl_atom_get_str_interface(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static struct atom_builder interfaces_list = - { atom_interfaces_list, sizeof(struct _lldpctl_atom_interfaces_list_t), - .init = _lldpctl_atom_new_interfaces_list, - .free = _lldpctl_atom_free_interfaces_list, - .iter = _lldpctl_atom_iter_interfaces_list, - .next = _lldpctl_atom_next_interfaces_list, - .value = _lldpctl_atom_value_interfaces_list }; +static struct atom_builder interfaces_list = { atom_interfaces_list, + sizeof(struct _lldpctl_atom_interfaces_list_t), + .init = _lldpctl_atom_new_interfaces_list, + .free = _lldpctl_atom_free_interfaces_list, + .iter = _lldpctl_atom_iter_interfaces_list, + .next = _lldpctl_atom_next_interfaces_list, + .value = _lldpctl_atom_value_interfaces_list }; -static struct atom_builder interface = - { atom_interface, sizeof(struct _lldpctl_atom_interface_t), - .init = _lldpctl_atom_new_interface, - .free = _lldpctl_atom_free_interface, - .get_str = _lldpctl_atom_get_str_interface }; +static struct atom_builder interface = { atom_interface, + sizeof(struct _lldpctl_atom_interface_t), .init = _lldpctl_atom_new_interface, + .free = _lldpctl_atom_free_interface, + .get_str = _lldpctl_atom_get_str_interface }; ATOM_BUILDER_REGISTER(interfaces_list, 2); -ATOM_BUILDER_REGISTER(interface, 3); - +ATOM_BUILDER_REGISTER(interface, 3); diff --git a/src/lib/atoms/med.c b/src/lib/atoms/med.c index 1ebafc5b..c1e32341 100644 --- a/src/lib/atoms/med.c +++ b/src/lib/atoms/med.c @@ -37,26 +37,26 @@ static lldpctl_map_t port_med_location_map[] = { static lldpctl_map_t port_med_pow_devicetype_map[] = { { LLDP_MED_POW_TYPE_PSE, "PSE" }, - { LLDP_MED_POW_TYPE_PD, "PD" }, + { LLDP_MED_POW_TYPE_PD, "PD" }, { 0, NULL }, }; static lldpctl_map_t port_med_pow_source_map[] = { { LLDP_MED_POW_SOURCE_PRIMARY, "Primary Power Source" }, - { LLDP_MED_POW_SOURCE_BACKUP, "Backup Power Source / Power Conservation Mode" }, - { LLDP_MED_POW_SOURCE_PSE, "PSE" }, - { LLDP_MED_POW_SOURCE_LOCAL, "Local"}, - { LLDP_MED_POW_SOURCE_BOTH, "PSE + Local"}, + { LLDP_MED_POW_SOURCE_BACKUP, "Backup Power Source / Power Conservation Mode" }, + { LLDP_MED_POW_SOURCE_PSE, "PSE" }, + { LLDP_MED_POW_SOURCE_LOCAL, "Local" }, + { LLDP_MED_POW_SOURCE_BOTH, "PSE + Local" }, { 0, NULL }, }; static lldpctl_map_t port_med_pow_source_map2[] = { - { 0, "unknown" }, + { 0, "unknown" }, { LLDP_MED_POW_SOURCE_PRIMARY, "primary" }, - { LLDP_MED_POW_SOURCE_BACKUP, "backup" }, - { LLDP_MED_POW_SOURCE_PSE, "pse" }, - { LLDP_MED_POW_SOURCE_LOCAL, "local" }, - { LLDP_MED_POW_SOURCE_BOTH, "both" }, + { LLDP_MED_POW_SOURCE_BACKUP, "backup" }, + { LLDP_MED_POW_SOURCE_PSE, "pse" }, + { LLDP_MED_POW_SOURCE_LOCAL, "local" }, + { LLDP_MED_POW_SOURCE_BOTH, "both" }, { 0, NULL }, }; @@ -99,20 +99,18 @@ static struct atom_map civic_address_type_map = { }, }; -static struct atom_map port_med_policy_map = { - .key = lldpctl_k_med_policy_type, +static struct atom_map port_med_policy_map = { .key = lldpctl_k_med_policy_type, .map = { - { LLDP_MED_APPTYPE_VOICE , "Voice"}, - { LLDP_MED_APPTYPE_VOICESIGNAL, "Voice Signaling"}, - { LLDP_MED_APPTYPE_GUESTVOICE, "Guest Voice"}, - { LLDP_MED_APPTYPE_GUESTVOICESIGNAL, "Guest Voice Signaling"}, - { LLDP_MED_APPTYPE_SOFTPHONEVOICE, "Softphone Voice"}, - { LLDP_MED_APPTYPE_VIDEOCONFERENCE, "Video Conferencing"}, - { LLDP_MED_APPTYPE_VIDEOSTREAM, "Streaming Video"}, - { LLDP_MED_APPTYPE_VIDEOSIGNAL, "Video Signaling"}, - { 0, NULL }, - } -}; + { LLDP_MED_APPTYPE_VOICE, "Voice" }, + { LLDP_MED_APPTYPE_VOICESIGNAL, "Voice Signaling" }, + { LLDP_MED_APPTYPE_GUESTVOICE, "Guest Voice" }, + { LLDP_MED_APPTYPE_GUESTVOICESIGNAL, "Guest Voice Signaling" }, + { LLDP_MED_APPTYPE_SOFTPHONEVOICE, "Softphone Voice" }, + { LLDP_MED_APPTYPE_VIDEOCONFERENCE, "Video Conferencing" }, + { LLDP_MED_APPTYPE_VIDEOSTREAM, "Streaming Video" }, + { LLDP_MED_APPTYPE_VIDEOSIGNAL, "Video Signaling" }, + { 0, NULL }, + } }; static struct atom_map port_med_policy_prio_map = { .key = lldpctl_k_med_policy_priority, @@ -140,13 +138,13 @@ static struct atom_map port_med_pow_priority_map = { }, }; -ATOM_MAP_REGISTER(port_med_geoid_map, 7); -ATOM_MAP_REGISTER(civic_address_type_map, 8); -ATOM_MAP_REGISTER(port_med_policy_map, 9); -ATOM_MAP_REGISTER(port_med_policy_prio_map, 10); +ATOM_MAP_REGISTER(port_med_geoid_map, 7); +ATOM_MAP_REGISTER(civic_address_type_map, 8); +ATOM_MAP_REGISTER(port_med_policy_map, 9); +ATOM_MAP_REGISTER(port_med_policy_prio_map, 10); ATOM_MAP_REGISTER(port_med_pow_priority_map, 11); -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_iter_med_policies_list(lldpctl_atom_t *atom) { int i; @@ -154,18 +152,18 @@ _lldpctl_atom_iter_med_policies_list(lldpctl_atom_t *atom) (struct _lldpctl_atom_any_list_t *)atom; for (i = 0; i < LLDP_MED_APPTYPE_LAST; i++) vlist->parent->port->p_med_policy[i].index = i; - return (lldpctl_atom_iter_t*)&vlist->parent->port->p_med_policy[0]; + return (lldpctl_atom_iter_t *)&vlist->parent->port->p_med_policy[0]; } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_next_med_policies_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct lldpd_med_policy *policy = (struct lldpd_med_policy *)iter; if (policy->index == LLDP_MED_APPTYPE_LAST - 1) return NULL; - return (lldpctl_atom_iter_t*)(++policy); + return (lldpctl_atom_iter_t *)(++policy); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_value_med_policies_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct _lldpctl_atom_any_list_t *vlist = @@ -218,7 +216,7 @@ _lldpctl_atom_get_int_med_policy(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_int_med_policy(lldpctl_atom_t *atom, lldpctl_key_t key, long int value) { @@ -271,7 +269,7 @@ bad: return NULL; } -static const char* +static const char * _lldpctl_atom_get_str_med_policy(lldpctl_atom_t *atom, lldpctl_key_t key) { struct _lldpctl_atom_med_policy_t *m = @@ -289,7 +287,7 @@ _lldpctl_atom_get_str_med_policy(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_str_med_policy(lldpctl_atom_t *atom, lldpctl_key_t key, const char *value) { @@ -307,7 +305,7 @@ _lldpctl_atom_set_str_med_policy(lldpctl_atom_t *atom, lldpctl_key_t key, } } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_iter_med_locations_list(lldpctl_atom_t *atom) { int i; @@ -315,24 +313,25 @@ _lldpctl_atom_iter_med_locations_list(lldpctl_atom_t *atom) (struct _lldpctl_atom_any_list_t *)atom; for (i = 0; i < LLDP_MED_LOCFORMAT_LAST; i++) vlist->parent->port->p_med_location[i].index = i; - return (lldpctl_atom_iter_t*)&vlist->parent->port->p_med_location[0]; + return (lldpctl_atom_iter_t *)&vlist->parent->port->p_med_location[0]; } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_next_med_locations_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct lldpd_med_loc *location = (struct lldpd_med_loc *)iter; if (location->index == LLDP_MED_LOCFORMAT_LAST - 1) return NULL; - return (lldpctl_atom_iter_t*)(++location); + return (lldpctl_atom_iter_t *)(++location); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_value_med_locations_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct _lldpctl_atom_any_list_t *vlist = (struct _lldpctl_atom_any_list_t *)atom; struct lldpd_med_loc *location = (struct lldpd_med_loc *)iter; - return _lldpctl_new_atom(atom->conn, atom_med_location, vlist->parent, location); + return _lldpctl_new_atom(atom->conn, atom_med_location, vlist->parent, + location); } static int @@ -369,8 +368,8 @@ _lldpctl_atom_get_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key) return LLDP_MED_LOCFORMAT_COORD; case LLDP_MED_LOCFORMAT_CIVIC: if ((m->location->data_len < 3) || - (m->location->data_len - 1 < - m->location->data[0])) break; + (m->location->data_len - 1 < m->location->data[0])) + break; return LLDP_MED_LOCFORMAT_CIVIC; case LLDP_MED_LOCFORMAT_ELIN: return LLDP_MED_LOCFORMAT_ELIN; @@ -391,7 +390,7 @@ _lldpctl_atom_get_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, long int value) { @@ -407,7 +406,7 @@ _lldpctl_atom_set_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, switch (key) { case lldpctl_k_med_location_format: switch (value) { - case 0: /* Disabling */ + case 0: /* Disabling */ case LLDP_MED_LOCFORMAT_COORD: mloc->location->format = value; free(mloc->location->data); @@ -440,11 +439,13 @@ _lldpctl_atom_set_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, mloc->location->data = NULL; mloc->location->data_len = 0; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_med_location_geoid: if (mloc->location->format != LLDP_MED_LOCFORMAT_COORD) goto bad; - if (mloc->location->data == NULL || mloc->location->data_len != 16) goto bad; + if (mloc->location->data == NULL || mloc->location->data_len != 16) + goto bad; switch (value) { case 0: case LLDP_MED_LOCATION_GEOID_WGS84: @@ -452,11 +453,13 @@ _lldpctl_atom_set_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, case LLDP_MED_LOCATION_GEOID_NAD83_MLLW: mloc->location->data[15] = value; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_med_location_altitude_unit: if (mloc->location->format != LLDP_MED_LOCFORMAT_COORD) goto bad; - if (mloc->location->data == NULL || mloc->location->data_len != 16) goto bad; + if (mloc->location->data == NULL || mloc->location->data_len != 16) + goto bad; switch (value) { case 0: case LLDP_MED_LOCATION_ALTITUDE_UNIT_METER: @@ -464,7 +467,8 @@ _lldpctl_atom_set_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, mloc->location->data[10] &= 0x0f; mloc->location->data[10] |= value << 4; return atom; - default: goto bad; + default: + goto bad; } default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); @@ -475,15 +479,14 @@ _lldpctl_atom_set_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, bad: SET_ERROR(atom->conn, LLDPCTL_ERR_BAD_VALUE); return NULL; - } -static const char* -read_fixed_precision(lldpctl_atom_t *atom, - char *buffer, unsigned shift, +static const char * +read_fixed_precision(lldpctl_atom_t *atom, char *buffer, unsigned shift, unsigned intbits, unsigned fltbits, const char *suffix) { - struct fp_number fp = fp_buftofp((unsigned char*)buffer, intbits, fltbits, shift); + struct fp_number fp = + fp_buftofp((unsigned char *)buffer, intbits, fltbits, shift); char *result = fp_fptostr(fp, suffix); if (result == NULL) { SET_ERROR(atom->conn, LLDPCTL_ERR_NOMEM); @@ -501,7 +504,7 @@ read_fixed_precision(lldpctl_atom_t *atom, return stored; } -static const char* +static const char * _lldpctl_atom_get_str_med_location(lldpctl_atom_t *atom, lldpctl_key_t key) { struct _lldpctl_atom_med_location_t *m = @@ -514,20 +517,16 @@ _lldpctl_atom_get_str_med_location(lldpctl_atom_t *atom, lldpctl_key_t key) return map_lookup(port_med_location_map, m->location->format); case lldpctl_k_med_location_geoid: if (m->location->format != LLDP_MED_LOCFORMAT_COORD) break; - return map_lookup(port_med_geoid_map.map, - m->location->data[15]); + return map_lookup(port_med_geoid_map.map, m->location->data[15]); case lldpctl_k_med_location_latitude: if (m->location->format != LLDP_MED_LOCFORMAT_COORD) break; - return read_fixed_precision(atom, m->location->data, - 0, 9, 25, "NS"); + return read_fixed_precision(atom, m->location->data, 0, 9, 25, "NS"); case lldpctl_k_med_location_longitude: if (m->location->format != LLDP_MED_LOCFORMAT_COORD) break; - return read_fixed_precision(atom, m->location->data, - 40, 9, 25, "EW"); + return read_fixed_precision(atom, m->location->data, 40, 9, 25, "EW"); case lldpctl_k_med_location_altitude: if (m->location->format != LLDP_MED_LOCFORMAT_COORD) break; - return read_fixed_precision(atom, m->location->data, - 84, 22, 8, NULL); + return read_fixed_precision(atom, m->location->data, 84, 22, 8, NULL); case lldpctl_k_med_location_altitude_unit: if (m->location->format != LLDP_MED_LOCFORMAT_COORD) break; switch (m->location->data[10] & 0xf0) { @@ -559,7 +558,7 @@ _lldpctl_atom_get_str_med_location(lldpctl_atom_t *atom, lldpctl_key_t key) return NULL; } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_str_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, const char *value) { @@ -577,44 +576,51 @@ _lldpctl_atom_set_str_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, switch (key) { case lldpctl_k_med_location_latitude: if (mloc->location->format != LLDP_MED_LOCFORMAT_COORD) goto bad; - if (mloc->location->data == NULL || mloc->location->data_len != 16) goto bad; + if (mloc->location->data == NULL || mloc->location->data_len != 16) + goto bad; if (value) fp = fp_strtofp(value, &end, 9, 25); if (!end) goto bad; if (end && *end != '\0') { - if (*(end+1) != '\0') goto bad; - if (*end == 'S') fp = fp_negate(fp); - else if (*end != 'N') goto bad; + if (*(end + 1) != '\0') goto bad; + if (*end == 'S') + fp = fp_negate(fp); + else if (*end != 'N') + goto bad; } - fp_fptobuf(fp, (unsigned char*)mloc->location->data, 0); + fp_fptobuf(fp, (unsigned char *)mloc->location->data, 0); return atom; case lldpctl_k_med_location_longitude: if (mloc->location->format != LLDP_MED_LOCFORMAT_COORD) goto bad; - if (mloc->location->data == NULL || mloc->location->data_len != 16) goto bad; + if (mloc->location->data == NULL || mloc->location->data_len != 16) + goto bad; if (value) fp = fp_strtofp(value, &end, 9, 25); if (!end) goto bad; if (end && *end != '\0') { - if (*(end+1) != '\0') goto bad; - if (*end == 'W') fp = fp_negate(fp); - else if (*end != 'E') goto bad; + if (*(end + 1) != '\0') goto bad; + if (*end == 'W') + fp = fp_negate(fp); + else if (*end != 'E') + goto bad; } - fp_fptobuf(fp, (unsigned char*)mloc->location->data, 40); + fp_fptobuf(fp, (unsigned char *)mloc->location->data, 40); return atom; case lldpctl_k_med_location_altitude: if (mloc->location->format != LLDP_MED_LOCFORMAT_COORD) goto bad; - if (mloc->location->data == NULL || mloc->location->data_len != 16) goto bad; + if (mloc->location->data == NULL || mloc->location->data_len != 16) + goto bad; if (value) fp = fp_strtofp(value, &end, 22, 8); if (!end || *end != '\0') goto bad; - fp_fptobuf(fp, (unsigned char*)mloc->location->data, 84); + fp_fptobuf(fp, (unsigned char *)mloc->location->data, 84); return atom; case lldpctl_k_med_location_altitude_unit: if (!value) goto bad; if (mloc->location->format != LLDP_MED_LOCFORMAT_COORD) goto bad; - if (mloc->location->data == NULL || mloc->location->data_len != 16) goto bad; + if (mloc->location->data == NULL || mloc->location->data_len != 16) + goto bad; if (!strcmp(value, "m")) return _lldpctl_atom_set_int_med_location(atom, key, LLDP_MED_LOCATION_ALTITUDE_UNIT_METER); - if (!strcmp(value, "f") || - (!strcmp(value, "floor"))) + if (!strcmp(value, "f") || (!strcmp(value, "floor"))) return _lldpctl_atom_set_int_med_location(atom, key, LLDP_MED_LOCATION_ALTITUDE_UNIT_FLOOR); goto bad; @@ -624,7 +630,8 @@ _lldpctl_atom_set_str_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, map_reverse_lookup(port_med_geoid_map.map, value)); case lldpctl_k_med_location_country: if (mloc->location->format != LLDP_MED_LOCFORMAT_CIVIC) goto bad; - if (mloc->location->data == NULL || mloc->location->data_len < 3) goto bad; + if (mloc->location->data == NULL || mloc->location->data_len < 3) + goto bad; if (!value || strlen(value) != 2) goto bad; memcpy(mloc->location->data + 2, value, 2); return atom; @@ -639,8 +646,7 @@ _lldpctl_atom_set_str_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, return NULL; } mloc->location->data_len = strlen(value); - memcpy(mloc->location->data, value, - mloc->location->data_len); + memcpy(mloc->location->data, value, mloc->location->data_len); return atom; default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); @@ -651,10 +657,9 @@ _lldpctl_atom_set_str_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, bad: SET_ERROR(atom->conn, LLDPCTL_ERR_BAD_VALUE); return NULL; - } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_get_atom_med_location(lldpctl_atom_t *atom, lldpctl_key_t key) { struct _lldpctl_atom_med_location_t *m = @@ -674,7 +679,7 @@ _lldpctl_atom_get_atom_med_location(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_atom_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, lldpctl_atom_t *value) { @@ -711,7 +716,7 @@ _lldpctl_atom_set_atom_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, memcpy(new + m->location->data_len + 2, el->value, el->len); new[0] += 2 + el->len; free(m->location->data); - m->location->data = (char*)new; + m->location->data = (char *)new; m->location->data_len += 2 + el->len; return atom; default: @@ -728,22 +733,22 @@ struct ca_iter { size_t data_len; }; -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_iter_med_caelements_list(lldpctl_atom_t *atom) { struct _lldpctl_atom_med_caelements_list_t *plist = (struct _lldpctl_atom_med_caelements_list_t *)atom; struct ca_iter *iter; if (plist->parent->location->data_len < 4 || - *(uint8_t*)plist->parent->location->data < 3 || + *(uint8_t *)plist->parent->location->data < 3 || !(iter = _lldpctl_alloc_in_atom(atom, sizeof(struct ca_iter)))) return NULL; - iter->data = (uint8_t*)plist->parent->location->data + 4; - iter->data_len = *(uint8_t*)plist->parent->location->data - 3; - return (lldpctl_atom_iter_t*)iter; + iter->data = (uint8_t *)plist->parent->location->data + 4; + iter->data_len = *(uint8_t *)plist->parent->location->data - 3; + return (lldpctl_atom_iter_t *)iter; } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_next_med_caelements_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct ca_iter *cai = (struct ca_iter *)iter; @@ -753,10 +758,10 @@ _lldpctl_atom_next_med_caelements_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t if (cai->data_len < 2 + len) return NULL; cai->data += 2 + len; cai->data_len -= 2 + len; - return (lldpctl_atom_iter_t*)cai; + return (lldpctl_atom_iter_t *)cai; } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_value_med_caelements_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct _lldpctl_atom_med_caelements_list_t *plist = @@ -770,13 +775,13 @@ _lldpctl_atom_value_med_caelements_list(lldpctl_atom_t *atom, lldpctl_atom_iter_ (int)*cai->data, cai->data + 2, len); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_create_med_caelements_list(lldpctl_atom_t *atom) { struct _lldpctl_atom_med_caelements_list_t *plist = (struct _lldpctl_atom_med_caelements_list_t *)atom; - return _lldpctl_new_atom(atom->conn, atom_med_caelement, plist->parent, - -1, NULL, 0); + return _lldpctl_new_atom(atom->conn, atom_med_caelement, plist->parent, -1, + NULL, 0); } static int @@ -785,9 +790,9 @@ _lldpctl_atom_new_med_caelement(lldpctl_atom_t *atom, va_list ap) struct _lldpctl_atom_med_caelement_t *el = (struct _lldpctl_atom_med_caelement_t *)atom; el->parent = va_arg(ap, struct _lldpctl_atom_med_location_t *); - el->type = va_arg(ap, int); - el->value = va_arg(ap, uint8_t*); - el->len = va_arg(ap, size_t); + el->type = va_arg(ap, int); + el->value = va_arg(ap, uint8_t *); + el->len = va_arg(ap, size_t); lldpctl_atom_inc_ref((lldpctl_atom_t *)el->parent); return 1; } @@ -814,7 +819,7 @@ _lldpctl_atom_get_int_med_caelement(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_int_med_caelement(lldpctl_atom_t *atom, lldpctl_key_t key, long int value) { @@ -843,7 +848,7 @@ bad: return NULL; } -static const char* +static const char * _lldpctl_atom_get_str_med_caelement(lldpctl_atom_t *atom, lldpctl_key_t key) { char *value = NULL; @@ -865,7 +870,7 @@ _lldpctl_atom_get_str_med_caelement(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_str_med_caelement(lldpctl_atom_t *atom, lldpctl_key_t key, const char *value) { @@ -886,7 +891,7 @@ _lldpctl_atom_set_str_med_caelement(lldpctl_atom_t *atom, lldpctl_key_t key, if (len > 251) goto bad; el->value = _lldpctl_alloc_in_atom(atom, len); if (el->value == NULL) return NULL; - strlcpy((char*)el->value, value, len); + strlcpy((char *)el->value, value, len); el->len = strlen(value); return atom; case lldpctl_k_med_civicaddress_type: @@ -921,7 +926,7 @@ _lldpctl_atom_free_med_power(lldpctl_atom_t *atom) lldpctl_atom_dec_ref((lldpctl_atom_t *)mpow->parent); } -static const char* +static const char * _lldpctl_atom_get_str_med_power(lldpctl_atom_t *atom, lldpctl_key_t key) { struct _lldpctl_atom_med_power_t *mpow = @@ -934,8 +939,7 @@ _lldpctl_atom_get_str_med_power(lldpctl_atom_t *atom, lldpctl_key_t key) return map_lookup(port_med_pow_devicetype_map, port->p_med_power.devicetype); case lldpctl_k_med_power_source: - return map_lookup(port_med_pow_source_map, - port->p_med_power.source); + return map_lookup(port_med_pow_source_map, port->p_med_power.source); case lldpctl_k_med_power_priority: return map_lookup(port_med_pow_priority_map.map, port->p_med_power.priority); @@ -950,7 +954,7 @@ _lldpctl_atom_get_int_med_power(lldpctl_atom_t *atom, lldpctl_key_t key) { struct _lldpctl_atom_med_power_t *dpow = (struct _lldpctl_atom_med_power_t *)atom; - struct lldpd_port *port = dpow->parent->port; + struct lldpd_port *port = dpow->parent->port; /* Local and remote port */ switch (key) { @@ -967,9 +971,8 @@ _lldpctl_atom_get_int_med_power(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* -_lldpctl_atom_set_int_med_power(lldpctl_atom_t *atom, lldpctl_key_t key, - long int value) +static lldpctl_atom_t * +_lldpctl_atom_set_int_med_power(lldpctl_atom_t *atom, lldpctl_key_t key, long int value) { struct _lldpctl_atom_med_power_t *dpow = (struct _lldpctl_atom_med_power_t *)atom; @@ -989,7 +992,8 @@ _lldpctl_atom_set_int_med_power(lldpctl_atom_t *atom, lldpctl_key_t key, case LLDP_MED_POW_TYPE_PD: port->p_med_power.devicetype = value; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_med_power_source: switch (value) { @@ -1009,7 +1013,8 @@ _lldpctl_atom_set_int_med_power(lldpctl_atom_t *atom, lldpctl_key_t key, case LLDP_MED_POW_SOURCE_UNKNOWN: port->p_med_power.source = value; return atom; - default: goto bad; + default: + goto bad; } case lldpctl_k_med_power_priority: if (value < 0 || value > 3) goto bad; @@ -1030,7 +1035,7 @@ bad: return NULL; } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_set_str_med_power(lldpctl_atom_t *atom, lldpctl_key_t key, const char *value) { @@ -1050,76 +1055,69 @@ _lldpctl_atom_set_str_med_power(lldpctl_atom_t *atom, lldpctl_key_t key, } } -static struct atom_builder med_policies_list = - { atom_med_policies_list, sizeof(struct _lldpctl_atom_any_list_t), - .init = _lldpctl_atom_new_any_list, - .free = _lldpctl_atom_free_any_list, - .iter = _lldpctl_atom_iter_med_policies_list, - .next = _lldpctl_atom_next_med_policies_list, - .value = _lldpctl_atom_value_med_policies_list }; - -static struct atom_builder med_policy = - { atom_med_policy, sizeof(struct _lldpctl_atom_med_policy_t), - .init = _lldpctl_atom_new_med_policy, - .free = _lldpctl_atom_free_med_policy, - .get_int = _lldpctl_atom_get_int_med_policy, - .set_int = _lldpctl_atom_set_int_med_policy, - .get_str = _lldpctl_atom_get_str_med_policy, - .set_str = _lldpctl_atom_set_str_med_policy }; - -static struct atom_builder med_locations_list = - { atom_med_locations_list, sizeof(struct _lldpctl_atom_any_list_t), - .init = _lldpctl_atom_new_any_list, - .free = _lldpctl_atom_free_any_list, - .iter = _lldpctl_atom_iter_med_locations_list, - .next = _lldpctl_atom_next_med_locations_list, - .value = _lldpctl_atom_value_med_locations_list }; - -static struct atom_builder med_location = - { atom_med_location, sizeof(struct _lldpctl_atom_med_location_t), - .init = _lldpctl_atom_new_med_location, - .free = _lldpctl_atom_free_med_location, - .get = _lldpctl_atom_get_atom_med_location, - .set = _lldpctl_atom_set_atom_med_location, - .get_int = _lldpctl_atom_get_int_med_location, - .set_int = _lldpctl_atom_set_int_med_location, - .get_str = _lldpctl_atom_get_str_med_location, - .set_str = _lldpctl_atom_set_str_med_location }; - -static struct atom_builder med_caelements_list = - { atom_med_caelements_list, sizeof(struct _lldpctl_atom_med_caelements_list_t), - .init = _lldpctl_atom_new_any_list, - .free = _lldpctl_atom_free_any_list, - .iter = _lldpctl_atom_iter_med_caelements_list, - .next = _lldpctl_atom_next_med_caelements_list, - .value = _lldpctl_atom_value_med_caelements_list, - .create = _lldpctl_atom_create_med_caelements_list }; - -static struct atom_builder med_caelement = - { atom_med_caelement, sizeof(struct _lldpctl_atom_med_caelement_t), - .init = _lldpctl_atom_new_med_caelement, - .free = _lldpctl_atom_free_med_caelement, - .get_int = _lldpctl_atom_get_int_med_caelement, - .set_int = _lldpctl_atom_set_int_med_caelement, - .get_str = _lldpctl_atom_get_str_med_caelement, - .set_str = _lldpctl_atom_set_str_med_caelement }; - -static struct atom_builder med_power = - { atom_med_power, sizeof(struct _lldpctl_atom_med_power_t), - .init = _lldpctl_atom_new_med_power, - .free = _lldpctl_atom_free_med_power, - .get_int = _lldpctl_atom_get_int_med_power, - .set_int = _lldpctl_atom_set_int_med_power, - .get_str = _lldpctl_atom_get_str_med_power, - .set_str = _lldpctl_atom_set_str_med_power }; - -ATOM_BUILDER_REGISTER(med_policies_list, 15); -ATOM_BUILDER_REGISTER(med_policy, 16); -ATOM_BUILDER_REGISTER(med_locations_list, 17); -ATOM_BUILDER_REGISTER(med_location, 18); +static struct atom_builder med_policies_list = { atom_med_policies_list, + sizeof(struct _lldpctl_atom_any_list_t), .init = _lldpctl_atom_new_any_list, + .free = _lldpctl_atom_free_any_list, + .iter = _lldpctl_atom_iter_med_policies_list, + .next = _lldpctl_atom_next_med_policies_list, + .value = _lldpctl_atom_value_med_policies_list }; + +static struct atom_builder med_policy = { atom_med_policy, + sizeof(struct _lldpctl_atom_med_policy_t), .init = _lldpctl_atom_new_med_policy, + .free = _lldpctl_atom_free_med_policy, + .get_int = _lldpctl_atom_get_int_med_policy, + .set_int = _lldpctl_atom_set_int_med_policy, + .get_str = _lldpctl_atom_get_str_med_policy, + .set_str = _lldpctl_atom_set_str_med_policy }; + +static struct atom_builder med_locations_list = { atom_med_locations_list, + sizeof(struct _lldpctl_atom_any_list_t), .init = _lldpctl_atom_new_any_list, + .free = _lldpctl_atom_free_any_list, + .iter = _lldpctl_atom_iter_med_locations_list, + .next = _lldpctl_atom_next_med_locations_list, + .value = _lldpctl_atom_value_med_locations_list }; + +static struct atom_builder med_location = { atom_med_location, + sizeof(struct _lldpctl_atom_med_location_t), + .init = _lldpctl_atom_new_med_location, .free = _lldpctl_atom_free_med_location, + .get = _lldpctl_atom_get_atom_med_location, + .set = _lldpctl_atom_set_atom_med_location, + .get_int = _lldpctl_atom_get_int_med_location, + .set_int = _lldpctl_atom_set_int_med_location, + .get_str = _lldpctl_atom_get_str_med_location, + .set_str = _lldpctl_atom_set_str_med_location }; + +static struct atom_builder med_caelements_list = { atom_med_caelements_list, + sizeof(struct _lldpctl_atom_med_caelements_list_t), + .init = _lldpctl_atom_new_any_list, .free = _lldpctl_atom_free_any_list, + .iter = _lldpctl_atom_iter_med_caelements_list, + .next = _lldpctl_atom_next_med_caelements_list, + .value = _lldpctl_atom_value_med_caelements_list, + .create = _lldpctl_atom_create_med_caelements_list }; + +static struct atom_builder med_caelement = { atom_med_caelement, + sizeof(struct _lldpctl_atom_med_caelement_t), + .init = _lldpctl_atom_new_med_caelement, + .free = _lldpctl_atom_free_med_caelement, + .get_int = _lldpctl_atom_get_int_med_caelement, + .set_int = _lldpctl_atom_set_int_med_caelement, + .get_str = _lldpctl_atom_get_str_med_caelement, + .set_str = _lldpctl_atom_set_str_med_caelement }; + +static struct atom_builder med_power = { atom_med_power, + sizeof(struct _lldpctl_atom_med_power_t), .init = _lldpctl_atom_new_med_power, + .free = _lldpctl_atom_free_med_power, + .get_int = _lldpctl_atom_get_int_med_power, + .set_int = _lldpctl_atom_set_int_med_power, + .get_str = _lldpctl_atom_get_str_med_power, + .set_str = _lldpctl_atom_set_str_med_power }; + +ATOM_BUILDER_REGISTER(med_policies_list, 15); +ATOM_BUILDER_REGISTER(med_policy, 16); +ATOM_BUILDER_REGISTER(med_locations_list, 17); +ATOM_BUILDER_REGISTER(med_location, 18); ATOM_BUILDER_REGISTER(med_caelements_list, 19); -ATOM_BUILDER_REGISTER(med_caelement, 20); -ATOM_BUILDER_REGISTER(med_power, 21); +ATOM_BUILDER_REGISTER(med_caelement, 20); +ATOM_BUILDER_REGISTER(med_power, 21); #endif - diff --git a/src/lib/atoms/mgmt.c b/src/lib/atoms/mgmt.c index 3d3ec9b8..095de764 100644 --- a/src/lib/atoms/mgmt.c +++ b/src/lib/atoms/mgmt.c @@ -44,22 +44,22 @@ _lldpctl_atom_free_mgmts_list(lldpctl_atom_t *atom) lldpctl_atom_dec_ref(plist->parent); } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_iter_mgmts_list(lldpctl_atom_t *atom) { struct _lldpctl_atom_mgmts_list_t *plist = (struct _lldpctl_atom_mgmts_list_t *)atom; - return (lldpctl_atom_iter_t*)TAILQ_FIRST(&plist->chassis->c_mgmt); + return (lldpctl_atom_iter_t *)TAILQ_FIRST(&plist->chassis->c_mgmt); } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_next_mgmts_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct lldpd_mgmt *mgmt = (struct lldpd_mgmt *)iter; - return (lldpctl_atom_iter_t*)TAILQ_NEXT(mgmt, m_entries); + return (lldpctl_atom_iter_t *)TAILQ_NEXT(mgmt, m_entries); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_value_mgmts_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct _lldpctl_atom_mgmts_list_t *plist = @@ -71,8 +71,7 @@ _lldpctl_atom_value_mgmts_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) static int _lldpctl_atom_new_mgmt(lldpctl_atom_t *atom, va_list ap) { - struct _lldpctl_atom_mgmt_t *mgmt = - (struct _lldpctl_atom_mgmt_t *)atom; + struct _lldpctl_atom_mgmt_t *mgmt = (struct _lldpctl_atom_mgmt_t *)atom; mgmt->parent = va_arg(ap, lldpctl_atom_t *); mgmt->mgmt = va_arg(ap, struct lldpd_mgmt *); lldpctl_atom_inc_ref(mgmt->parent); @@ -82,16 +81,14 @@ _lldpctl_atom_new_mgmt(lldpctl_atom_t *atom, va_list ap) static void _lldpctl_atom_free_mgmt(lldpctl_atom_t *atom) { - struct _lldpctl_atom_mgmt_t *mgmt = - (struct _lldpctl_atom_mgmt_t *)atom; + struct _lldpctl_atom_mgmt_t *mgmt = (struct _lldpctl_atom_mgmt_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; + struct _lldpctl_atom_mgmt_t *m = (struct _lldpctl_atom_mgmt_t *)atom; /* Local and remote port */ switch (key) { @@ -102,13 +99,13 @@ _lldpctl_atom_get_int_mgmt(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static const char* +static const char * _lldpctl_atom_get_str_mgmt(lldpctl_atom_t *atom, lldpctl_key_t key) { char *ipaddress = NULL; - size_t len; int af; - struct _lldpctl_atom_mgmt_t *m = - (struct _lldpctl_atom_mgmt_t *)atom; + size_t len; + int af; + struct _lldpctl_atom_mgmt_t *m = (struct _lldpctl_atom_mgmt_t *)atom; /* Local and remote port */ switch (key) { @@ -116,7 +113,7 @@ _lldpctl_atom_get_str_mgmt(lldpctl_atom_t *atom, lldpctl_key_t key) switch (m->mgmt->m_family) { case LLDPD_AF_IPV4: len = INET_ADDRSTRLEN + 1; - af = AF_INET; + af = AF_INET; break; case LLDPD_AF_IPV6: len = INET6_ADDRSTRLEN + 1; @@ -128,8 +125,7 @@ _lldpctl_atom_get_str_mgmt(lldpctl_atom_t *atom, lldpctl_key_t key) if (len == 0) break; ipaddress = _lldpctl_alloc_in_atom(atom, len); if (!ipaddress) return NULL; - if (inet_ntop(af, &m->mgmt->m_addr, ipaddress, len) == NULL) - break; + if (inet_ntop(af, &m->mgmt->m_addr, ipaddress, len) == NULL) break; return ipaddress; default: SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); @@ -139,21 +135,15 @@ _lldpctl_atom_get_str_mgmt(lldpctl_atom_t *atom, lldpctl_key_t key) return NULL; } -static struct atom_builder mgmts_list = - { atom_mgmts_list, sizeof(struct _lldpctl_atom_mgmts_list_t), - .init = _lldpctl_atom_new_mgmts_list, - .free = _lldpctl_atom_free_mgmts_list, - .iter = _lldpctl_atom_iter_mgmts_list, - .next = _lldpctl_atom_next_mgmts_list, - .value = _lldpctl_atom_value_mgmts_list }; - -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 }; +static struct atom_builder mgmts_list = { atom_mgmts_list, + sizeof(struct _lldpctl_atom_mgmts_list_t), .init = _lldpctl_atom_new_mgmts_list, + .free = _lldpctl_atom_free_mgmts_list, .iter = _lldpctl_atom_iter_mgmts_list, + .next = _lldpctl_atom_next_mgmts_list, + .value = _lldpctl_atom_value_mgmts_list }; -ATOM_BUILDER_REGISTER(mgmts_list, 6); -ATOM_BUILDER_REGISTER(mgmt, 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); +ATOM_BUILDER_REGISTER(mgmt, 7); diff --git a/src/lib/atoms/port.c b/src/lib/atoms/port.c index 9266898b..25859bdb 100644 --- a/src/lib/atoms/port.c +++ b/src/lib/atoms/port.c @@ -25,211 +25,322 @@ #include "../atom.h" #include "../helpers.h" -static struct atom_map lldpd_protocol_map = { - .key = lldpctl_k_port_protocol, +static struct atom_map lldpd_protocol_map = { .key = lldpctl_k_port_protocol, .map = { - { LLDPD_MODE_LLDP, "LLDP" }, - { LLDPD_MODE_CDPV1, "CDPv1"}, - { LLDPD_MODE_CDPV2, "CDPv2"}, - { LLDPD_MODE_EDP, "EDP" }, - { LLDPD_MODE_FDP, "FDP"}, - { LLDPD_MODE_SONMP, "SONMP"}, - { 0, NULL }, - } -}; + { LLDPD_MODE_LLDP, "LLDP" }, + { LLDPD_MODE_CDPV1, "CDPv1" }, + { LLDPD_MODE_CDPV2, "CDPv2" }, + { LLDPD_MODE_EDP, "EDP" }, + { LLDPD_MODE_FDP, "FDP" }, + { LLDPD_MODE_SONMP, "SONMP" }, + { 0, NULL }, + } }; ATOM_MAP_REGISTER(lldpd_protocol_map, 3); static lldpctl_map_t port_id_subtype_map[] = { - { LLDP_PORTID_SUBTYPE_IFNAME, "ifname"}, - { LLDP_PORTID_SUBTYPE_IFALIAS, "ifalias" }, - { LLDP_PORTID_SUBTYPE_LOCAL, "local" }, - { LLDP_PORTID_SUBTYPE_LLADDR, "mac" }, - { LLDP_PORTID_SUBTYPE_ADDR, "ip" }, - { LLDP_PORTID_SUBTYPE_PORT, "unhandled" }, + { LLDP_PORTID_SUBTYPE_IFNAME, "ifname" }, + { LLDP_PORTID_SUBTYPE_IFALIAS, "ifalias" }, + { LLDP_PORTID_SUBTYPE_LOCAL, "local" }, + { LLDP_PORTID_SUBTYPE_LLADDR, "mac" }, + { LLDP_PORTID_SUBTYPE_ADDR, "ip" }, + { LLDP_PORTID_SUBTYPE_PORT, "unhandled" }, { LLDP_PORTID_SUBTYPE_AGENTCID, "unhandled" }, - { 0, NULL}, + { 0, NULL }, }; -static struct atom_map port_status_map = { - .key = lldpctl_k_port_status, +static struct atom_map port_status_map = { .key = lldpctl_k_port_status, .map = { - { LLDPD_RXTX_TXONLY, "TX only" }, - { LLDPD_RXTX_RXONLY, "RX only" }, - { LLDPD_RXTX_DISABLED, "disabled" }, - { LLDPD_RXTX_BOTH, "RX and TX" }, - { 0, NULL }, - } -}; + { LLDPD_RXTX_TXONLY, "TX only" }, + { LLDPD_RXTX_RXONLY, "RX only" }, + { LLDPD_RXTX_DISABLED, "disabled" }, + { LLDPD_RXTX_BOTH, "RX and TX" }, + { 0, NULL }, + } }; ATOM_MAP_REGISTER(port_status_map, 3); #ifdef ENABLE_DOT3 static lldpctl_map_t operational_mau_type_values[] = { - { LLDP_DOT3_MAU_AUI, "AUI - No internal MAU, view from AUI" }, - { LLDP_DOT3_MAU_10BASE5, "10Base5 - Thick coax MAU" }, - { LLDP_DOT3_MAU_FOIRL, "Foirl - FOIRL MAU" }, - { LLDP_DOT3_MAU_10BASE2, "10Base2 - Thin coax MAU" }, - { LLDP_DOT3_MAU_10BASET, "10BaseT - UTP MAU" }, - { LLDP_DOT3_MAU_10BASEFP, "10BaseFP - Passive fiber MAU" }, - { LLDP_DOT3_MAU_10BASEFB, "10BaseFB - Sync fiber MAU" }, - { LLDP_DOT3_MAU_10BASEFL, "10BaseFL - Async fiber MAU" }, - { LLDP_DOT3_MAU_10BROAD36, "10Broad36 - Broadband DTE MAU" }, - { LLDP_DOT3_MAU_10BASETHD, "10BaseTHD - UTP MAU, half duplex mode" }, - { LLDP_DOT3_MAU_10BASETFD, "10BaseTFD - UTP MAU, full duplex mode" }, - { LLDP_DOT3_MAU_10BASEFLHD, "10BaseFLHD - Async fiber MAU, half duplex mode" }, - { LLDP_DOT3_MAU_10BASEFLFD, "10BaseFLDF - Async fiber MAU, full duplex mode" }, - { LLDP_DOT3_MAU_100BASET4, "100BaseT4 - 4 pair category 3 UTP" }, - { LLDP_DOT3_MAU_100BASETXHD, "100BaseTXHD - 2 pair category 5 UTP, half duplex mode" }, - { LLDP_DOT3_MAU_100BASETXFD, "100BaseTXFD - 2 pair category 5 UTP, full duplex mode" }, - { LLDP_DOT3_MAU_100BASEFXHD, "100BaseFXHD - X fiber over PMT, half duplex mode" }, - { LLDP_DOT3_MAU_100BASEFXFD, "100BaseFXFD - X fiber over PMT, full duplex mode" }, - { LLDP_DOT3_MAU_100BASET2HD, "100BaseT2HD - 2 pair category 3 UTP, half duplex mode" }, - { LLDP_DOT3_MAU_100BASET2FD, "100BaseT2FD - 2 pair category 3 UTP, full duplex mode" }, - { LLDP_DOT3_MAU_1000BASEXHD, "1000BaseXHD - PCS/PMA, unknown PMD, half duplex mode" }, - { LLDP_DOT3_MAU_1000BASEXFD, "1000BaseXFD - PCS/PMA, unknown PMD, full duplex mode" }, - { LLDP_DOT3_MAU_1000BASELXHD, "1000BaseLXHD - Fiber over long-wavelength laser, half duplex mode" }, - { LLDP_DOT3_MAU_1000BASELXFD, "1000BaseLXFD - Fiber over long-wavelength laser, full duplex mode" }, - { LLDP_DOT3_MAU_1000BASESXHD, "1000BaseSXHD - Fiber over short-wavelength laser, half duplex mode" }, - { LLDP_DOT3_MAU_1000BASESXFD, "1000BaseSXFD - Fiber over short-wavelength laser, full duplex mode" }, - { LLDP_DOT3_MAU_1000BASECXHD, "1000BaseCXHD - Copper over 150-Ohm balanced cable, half duplex mode" }, - { LLDP_DOT3_MAU_1000BASECXFD, "1000BaseCXFD - Copper over 150-Ohm balanced cable, full duplex mode" }, - { LLDP_DOT3_MAU_1000BASETHD, "1000BaseTHD - Four-pair Category 5 UTP, half duplex mode" }, - { LLDP_DOT3_MAU_1000BASETFD, "1000BaseTFD - Four-pair Category 5 UTP, full duplex mode" }, - { LLDP_DOT3_MAU_10GIGBASEX, "10GigBaseX - X PCS/PMA, unknown PMD." }, - { LLDP_DOT3_MAU_10GIGBASELX4, "10GigBaseLX4 - X fiber over WWDM optics" }, - { LLDP_DOT3_MAU_10GIGBASER, "10GigBaseR - R PCS/PMA, unknown PMD." }, - { LLDP_DOT3_MAU_10GIGBASEER, "10GigBaseER - R fiber over 1550 nm optics" }, - { LLDP_DOT3_MAU_10GIGBASELR, "10GigBaseLR - R fiber over 1310 nm optics" }, - { LLDP_DOT3_MAU_10GIGBASESR, "10GigBaseSR - R fiber over 850 nm optics" }, - { LLDP_DOT3_MAU_10GIGBASEW, "10GigBaseW - W PCS/PMA, unknown PMD." }, - { LLDP_DOT3_MAU_10GIGBASEEW, "10GigBaseEW - W fiber over 1550 nm optics" }, - { LLDP_DOT3_MAU_10GIGBASELW, "10GigBaseLW - W fiber over 1310 nm optics" }, - { LLDP_DOT3_MAU_10GIGBASESW, "10GigBaseSW - W fiber over 850 nm optics" }, - { LLDP_DOT3_MAU_10GIGBASECX4, "10GigBaseCX4 - X copper over 8 pair 100-Ohm balanced cable" }, - { LLDP_DOT3_MAU_2BASETL, "2BaseTL - Voice grade UTP copper, up to 2700m, optional PAF" }, - { LLDP_DOT3_MAU_10PASSTS, "10PassTS - Voice grade UTP copper, up to 750m, optional PAF" }, - { LLDP_DOT3_MAU_100BASEBX10D, "100BaseBX10D - One single-mode fiber OLT, long wavelength, 10km" }, - { LLDP_DOT3_MAU_100BASEBX10U, "100BaseBX10U - One single-mode fiber ONU, long wavelength, 10km" }, - { LLDP_DOT3_MAU_100BASELX10, "100BaseLX10 - Two single-mode fibers, long wavelength, 10km" }, - { LLDP_DOT3_MAU_1000BASEBX10D, "1000BaseBX10D - One single-mode fiber OLT, long wavelength, 10km" }, - { LLDP_DOT3_MAU_1000BASEBX10U, "1000BaseBX10U - One single-mode fiber ONU, long wavelength, 10km" }, - { LLDP_DOT3_MAU_1000BASELX10, "1000BaseLX10 - Two sigle-mode fiber, long wavelength, 10km" }, - { LLDP_DOT3_MAU_1000BASEPX10D, "1000BasePX10D - One single-mode fiber EPON OLT, 10km" }, - { LLDP_DOT3_MAU_1000BASEPX10U, "1000BasePX10U - One single-mode fiber EPON ONU, 10km" }, - { LLDP_DOT3_MAU_1000BASEPX20D, "1000BasePX20D - One single-mode fiber EPON OLT, 20km" }, - { LLDP_DOT3_MAU_1000BASEPX20U, "1000BasePX20U - One single-mode fiber EPON ONU, 20km" }, - { LLDP_DOT3_MAU_10GBASET, "10GbaseT - Four-pair Category 6A or better, full duplex mode only" }, - { LLDP_DOT3_MAU_10GBASELRM, "10GbaseLRM - R multimode fiber over 1310 nm optics" }, - { LLDP_DOT3_MAU_1000BASEKX, "1000baseKX - X backplane, full duplex mode only" }, - { LLDP_DOT3_MAU_10GBASEKX4, "10GbaseKX4 - 4 lane X backplane, full duplex mode only" }, - { LLDP_DOT3_MAU_10GBASEKR, "10GbaseKR - R backplane, full duplex mode only" }, - { LLDP_DOT3_MAU_10G1GBASEPRXD1, "10G1GbasePRXD1 - One single-mode fiber asymmetric-rate EPON OLT, low power budget (PRX10)" }, - { LLDP_DOT3_MAU_10G1GBASEPRXD2, "10G1GbasePRXD2 - One single-mode fiber asymmetric-rate EPON OLT, medium power budget (PRX20)" }, - { LLDP_DOT3_MAU_10G1GBASEPRXD3, "10G1GbasePRXD3 - One single-mode fiber asymmetric-rate EPON OLT, high power budget (PRX30)" }, - { LLDP_DOT3_MAU_10G1GBASEPRXU1, "10G1GbasePRXU1 - One single-mode fiber asymmetric-rate EPON ONU, low power budget (PRX10)" }, - { LLDP_DOT3_MAU_10G1GBASEPRXU2, "10G1GbasePRXU2 - One single-mode fiber asymmetric-rate EPON ONU, medium power budget (PRX20)" }, - { LLDP_DOT3_MAU_10G1GBASEPRXU3, "10G1GbasePRXU3 - One single-mode fiber asymmetric-rate EPON ONU, high power budget (PRX30)" }, - { LLDP_DOT3_MAU_10GBASEPRD1, "10GbasePRD1 - One single-mode fiber symmetric-rate EPON OLT, low power budget (PR10)" }, - { LLDP_DOT3_MAU_10GBASEPRD2, "10GbasePRD2 - One single-mode fiber symmetric-rate EPON OLT, medium power budget (PR20)" }, - { LLDP_DOT3_MAU_10GBASEPRD3, "10GbasePRD3 - One single-mode fiber symmetric-rate EPON OLT, high power budget (PR30)" }, - { LLDP_DOT3_MAU_10GBASEPRU1, "10GbasePRU1 - One single-mode fiber symmetric-rate EPON ONU, low and medium power budget" }, - { LLDP_DOT3_MAU_10GBASEPRU3, "10GbasePRU3 - One single-mode fiber symmetric-rate EPON ONU, high power budget (PR30)" }, - { LLDP_DOT3_MAU_40GBASEKR4, "40GbaseKR4 - 40GBASE-R PCS/PMA over an electrical backplane" }, - { LLDP_DOT3_MAU_40GBASECR4, "40GbaseCR4 - 40GBASE-R PCS/PMA over 4 lane shielded copper balanced cable" }, - { LLDP_DOT3_MAU_40GBASESR4, "40GbaseSR4 - 40GBASE-R PCS/PMA over 4 lane multimode fiber" }, - { LLDP_DOT3_MAU_40GBASEFR, "40GbaseFR - 40GBASE-R PCS/PMA over single mode fiber" }, - { LLDP_DOT3_MAU_40GBASELR4, "40GbaseLR4 - 40GBASE-R PCS/PMA over 4 WDM lane single mode fiber" }, - { LLDP_DOT3_MAU_100GBASECR10, "100GbaseCR10 - 100GBASE-R PCS/PMA over 10 lane shielded copper balanced cable" }, - { LLDP_DOT3_MAU_100GBASESR10, "100GbaseSR10 - 100GBASE-R PCS/PMA over 10 lane multimode fiber" }, - { LLDP_DOT3_MAU_100GBASELR4, "100GbaseLR4 - 100GBASE-R PCS/PMA over 4 WDM lane single mode fiber, long reach" }, - { LLDP_DOT3_MAU_100GBASEER4, "100GbaseER4 - 100GBASE-R PCS/PMA over 4 WDM lane single mode fiber PMD, extended reach" }, - { LLDP_DOT3_MAU_1000BASET1, "1000baseT1 - 1000BASE-T1 single balanced twisted-pair copper cabling PHY" }, - { LLDP_DOT3_MAU_1000BASEPX30D, "1000basePX30D - One single-mode fiber EPON OLT, 20km, 1:32 split ratio" }, - { LLDP_DOT3_MAU_1000BASEPX30U, "1000basePX30U - One single-mode fiber EPON ONU, 20km, 1:32 split ratio" }, - { LLDP_DOT3_MAU_1000BASEPX40D, "1000basePX40D - One single-mode fiber EPON OLT, 20km, 1:64 split ratio" }, - { LLDP_DOT3_MAU_1000BASEPX40U, "1000basePX40U - One single-mode fiber EPON ONU, 20km, 1:64 split ratio" }, - { LLDP_DOT3_MAU_10G1GBASEPRXD4, "10G1GbasePRXD4 - One single-mode fiber asymmetric-rate EPON OLT, supporting extended power budget (PRX40)" }, - { LLDP_DOT3_MAU_10G1GBASEPRXU4, "10G1GbasePRXU4 - One single-mode fiber asymmetric-rate EPON ONU, supporting extended power budget (PRX40)" }, - { LLDP_DOT3_MAU_10GBASEPRD4, "10GbasePRD4 - One single-mode fiber symmetric-rate EPON OLT, supporting extended power budget (PR40)" }, - { LLDP_DOT3_MAU_10GBASEPRU4, "10GbasePRU4 - One single-mode fiber symmetric-rate EPON ONU, supporting extended power budget (PR40)" }, - { LLDP_DOT3_MAU_25GBASECR, "25GbaseCR - 25GBASE-R PCS/PMA over shielded balanced copper cable" }, - { LLDP_DOT3_MAU_25GBASECRS, "25GbaseCRS - 25GBASE-R PCS/PMA over shielded balanced copper cable without RS-FEC" }, - { LLDP_DOT3_MAU_25GBASEKR, "25GbaseKR - 25GBASE-R PCS/PMA over an electrical backplane" }, - { LLDP_DOT3_MAU_25GBASEKRS, "25GbaseKRS - 25GBASE-R PCS/PMA over an electrical backplane without RS-FEC" }, - { LLDP_DOT3_MAU_25GBASER, "25GbaseR - 25GBASE-R PCS/PMA over undefined PMD" }, - { LLDP_DOT3_MAU_25GBASESR, "25GbaseSR - 25GBASE-R PCS/PMA over multimode fiber" }, - { LLDP_DOT3_MAU_25GBASET, "25GbaseT - Four-pair twisted-pair balanced copper cabling" }, - { LLDP_DOT3_MAU_40GBASEER4, "40GbaseER4 - 40GBASE-R PCS/PMA over 4 WDM lane single mode fiber" }, - { LLDP_DOT3_MAU_40GBASER, "40GbaseR - 40GBASE-R PCS as over undefined PMA/PMD" }, - { LLDP_DOT3_MAU_40GBASET, "40GbaseT - Four-pair twisted-pair balanced copper cabling" }, - { LLDP_DOT3_MAU_100GBASECR4, "100GbaseCR4 - 100GBASE-R PCS/PMA over 4 lane shielded copper balanced cable" }, - { LLDP_DOT3_MAU_100GBASEKR4, "100GbaseKR4 - 100GBASE-R PCS/PMA over an electrical backplane" }, - { LLDP_DOT3_MAU_100GBASEKP4, "100GbaseKP4 - 100GBASE-P PCS/PMA over an electrical backplane PMD" }, - { LLDP_DOT3_MAU_100GBASER, "100GbaseR - 100GBASE-R Multi-lane PCS over undefined PMA/PMD" }, - { LLDP_DOT3_MAU_100GBASESR4, "100GbaseSR4 - 100GBASE-R PCS/PMA over 4 lane multimode fiber" }, - { LLDP_DOT3_MAU_2P5GIGT, "2p5GigT - 2.5GBASE-T Four-pair twisted-pair balanced copper cabling PHY" }, - { LLDP_DOT3_MAU_5GIGT, "5GigT - 5GBASE-T Four-pair twisted-pair balanced copper cabling PHY" }, - { LLDP_DOT3_MAU_100BASET1, "100baseT1 - 100BASE-T1 Single balanced twisted-pair copper cabling PHY" }, - { LLDP_DOT3_MAU_1000BASERHA, "1000baseRHA - 1000BASE-RHA Plastic optical fiber PHY" }, - { LLDP_DOT3_MAU_1000BASERHB, "1000baseRHB - 1000BASE-RHB Plastic optical fiber PHY" }, - { LLDP_DOT3_MAU_1000BASERHC, "1000baseRHC - 1000BASE-RHC Plastic optical fiber PHY" }, - { LLDP_DOT3_MAU_2P5GBASEKX, "2p5GbaseKX - 2.5GBASE-X PMD over an electrical backplane" }, - { LLDP_DOT3_MAU_2P5GBASEX, "2p5GbaseX - 2.5GBASE-X PCS/PMA over undefined PMD" }, - { LLDP_DOT3_MAU_5GBASEKR, "5GbaseKR - 5GBASE-KR PMD over an electrical backplane" }, - { LLDP_DOT3_MAU_5GBASER, "5GbaseR - 5GBASE-R PCS/PMA over undefined PMD" }, - { LLDP_DOT3_MAU_10GPASSXR, "10GpassXR - Coax cable distribution network PHY continuous downstream/burst mode upstream PHY" }, - { LLDP_DOT3_MAU_25GBASELR, "25GbaseLR - 25GBASE-R PCS/PMA over single-mode fiber PMD, with long reach" }, - { LLDP_DOT3_MAU_25GBASEER, "25GbaseER - 25GBASE-R PCS/PMA over single-mode fiber PMD, with extended reach" }, - { LLDP_DOT3_MAU_50GBASER, "50GbaseR - 50GBASE-R Multi-lane PCS over undefined PMA/PMD" }, - { LLDP_DOT3_MAU_50GBASECR, "50GbaseCR - 50GBASE-R PCS/PMA over shielded copper balanced cable PMD" }, - { LLDP_DOT3_MAU_50GBASEKR, "50GbaseKR - 50GBASE-R PCS/PMA over an electrical backplane PMD" }, - { LLDP_DOT3_MAU_50GBASESR, "50GbaseSR - 50GBASE-R PCS/PMA over multimode fiber PMD" }, - { LLDP_DOT3_MAU_50GBASEFR, "50GbaseFR - 50GBASE-R PCS/PMA over single mode fiber PMD with reach up to at least 2 km" }, - { LLDP_DOT3_MAU_50GBASELR, "50GbaseLR - 50GBASE-R PCS/PMA over single mode fiber PMD with reach up to at least 10 km" }, - { LLDP_DOT3_MAU_50GBASEER, "50GbaseER - 50GBASE-R PCS/PMA over single-mode fiber PMD with reach up to at least 40 km" }, - { LLDP_DOT3_MAU_100GBASECR2, "100GbaseCR2 - 100GBASE-R PCS/PMA over 2 lane shielded copper balanced cable PMD" }, - { LLDP_DOT3_MAU_100GBASEKR2, "100GbaseKR2 - 100GBASE-R PCS/PMA over an electrical backplane PMD" }, - { LLDP_DOT3_MAU_100GBASESR2, "100GbaseSR2 - 100GBASE-R PCS/PMA over 2 lane multimode fiber PMD" }, - { LLDP_DOT3_MAU_100GBASEDR, "100GbaseDR - 100GBASE-R PCS/PMA over single mode fiber PMD" }, - { LLDP_DOT3_MAU_200GBASER, "200GbaseR - 200GBASE-R Multi-lane PCS over undefined PMA/PMD" }, - { LLDP_DOT3_MAU_200GBASEDR4, "200GbaseDR4 - 200GBASE-R PCS/PMA over 4-lane single-mode fiber PMD" }, - { LLDP_DOT3_MAU_200GBASEFR4, "200GbaseFR4 - 200GBASE-R PCS/PMA over 4 WDM lane single-mode fiber PMD with reach up to at least 2 km" }, - { LLDP_DOT3_MAU_200GBASELR4, "200GbaseLR4 - 200GBASE-R PCS/PMA over 4 WDM lane single-mode fiber PMD with reach up to at least 10 km" }, - { LLDP_DOT3_MAU_200GBASECR4, "200GbaseCR4 - 200GBASE-R PCS/PMA over 4 lane shielded copper balanced cable PMD" }, - { LLDP_DOT3_MAU_200GBASEKR4, "200GbaseKR4 - 200GBASE-R PCS/PMA over an electrical backplane PMD" }, - { LLDP_DOT3_MAU_200GBASESR4, "200GbaseSR4 - 200GBASE-R PCS/PMA over 4 lane multimode fiber PMD" }, - { LLDP_DOT3_MAU_200GBASEER4, "200GbaseER4 - 200GBASE-R PCS/PMA over 4 WDM lane single-mode fiber PMD with reach up to at least 40 km" }, - { LLDP_DOT3_MAU_400GBASER, "400GbaseR - 400GBASE-R Multi-lane PCS over undefined PMA/PMD" }, - { LLDP_DOT3_MAU_400GBASESR16, "400GbaseSR16 - 400GBASE-R PCS/PMA over 16-lane multimode fiber PMD" }, - { LLDP_DOT3_MAU_400GBASEDR4, "400GbaseDR4 - 400GBASE-R PCS/PMA over 4-lane single-mode fiber PMD" }, - { LLDP_DOT3_MAU_400GBASEFR8, "400GbaseFR8 - 400GBASE-R PCS/PMA over 8 WDM lane single-mode fiber PMD with reach up to at least 2 km" }, - { LLDP_DOT3_MAU_400GBASELR8, "400GbaseLR8 - 400GBASE-R PCS/PMA over 8 WDM lane single-mode fiber PMD with reach up to at least 10 km" }, - { LLDP_DOT3_MAU_400GBASEER8, "400GbaseER8 - 400GBASE-R PCS/PMA over 8 WDM lane single-mode fiber PMD with reach up to at least 40 km" }, - { LLDP_DOT3_MAU_10BASET1L, "10baseT1L - 10BASE-T1L Single balanced pair PHY" }, - { LLDP_DOT3_MAU_10BASET1SHD, "10baseT1SHD - 10BASE-T1S Single balanced pair PHY, half duplex mode" }, - { LLDP_DOT3_MAU_10BASET1SMD, "10baseT1SMD - 10BASE-T1S Single balanced pair PHY, multidrop mode" }, - { LLDP_DOT3_MAU_10BASET1SFD, "10baseT1SFD - 10BASE-T1S Single balanced pair PHY, full duplex mode" }, + { LLDP_DOT3_MAU_AUI, "AUI - No internal MAU, view from AUI" }, + { LLDP_DOT3_MAU_10BASE5, "10Base5 - Thick coax MAU" }, + { LLDP_DOT3_MAU_FOIRL, "Foirl - FOIRL MAU" }, + { LLDP_DOT3_MAU_10BASE2, "10Base2 - Thin coax MAU" }, + { LLDP_DOT3_MAU_10BASET, "10BaseT - UTP MAU" }, + { LLDP_DOT3_MAU_10BASEFP, "10BaseFP - Passive fiber MAU" }, + { LLDP_DOT3_MAU_10BASEFB, "10BaseFB - Sync fiber MAU" }, + { LLDP_DOT3_MAU_10BASEFL, "10BaseFL - Async fiber MAU" }, + { LLDP_DOT3_MAU_10BROAD36, "10Broad36 - Broadband DTE MAU" }, + { LLDP_DOT3_MAU_10BASETHD, "10BaseTHD - UTP MAU, half duplex mode" }, + { LLDP_DOT3_MAU_10BASETFD, "10BaseTFD - UTP MAU, full duplex mode" }, + { LLDP_DOT3_MAU_10BASEFLHD, "10BaseFLHD - Async fiber MAU, half duplex mode" }, + { LLDP_DOT3_MAU_10BASEFLFD, "10BaseFLDF - Async fiber MAU, full duplex mode" }, + { LLDP_DOT3_MAU_100BASET4, "100BaseT4 - 4 pair category 3 UTP" }, + { LLDP_DOT3_MAU_100BASETXHD, + "100BaseTXHD - 2 pair category 5 UTP, half duplex mode" }, + { LLDP_DOT3_MAU_100BASETXFD, + "100BaseTXFD - 2 pair category 5 UTP, full duplex mode" }, + { LLDP_DOT3_MAU_100BASEFXHD, + "100BaseFXHD - X fiber over PMT, half duplex mode" }, + { LLDP_DOT3_MAU_100BASEFXFD, + "100BaseFXFD - X fiber over PMT, full duplex mode" }, + { LLDP_DOT3_MAU_100BASET2HD, + "100BaseT2HD - 2 pair category 3 UTP, half duplex mode" }, + { LLDP_DOT3_MAU_100BASET2FD, + "100BaseT2FD - 2 pair category 3 UTP, full duplex mode" }, + { LLDP_DOT3_MAU_1000BASEXHD, + "1000BaseXHD - PCS/PMA, unknown PMD, half duplex mode" }, + { LLDP_DOT3_MAU_1000BASEXFD, + "1000BaseXFD - PCS/PMA, unknown PMD, full duplex mode" }, + { LLDP_DOT3_MAU_1000BASELXHD, + "1000BaseLXHD - Fiber over long-wavelength laser, half duplex mode" }, + { LLDP_DOT3_MAU_1000BASELXFD, + "1000BaseLXFD - Fiber over long-wavelength laser, full duplex mode" }, + { LLDP_DOT3_MAU_1000BASESXHD, + "1000BaseSXHD - Fiber over short-wavelength laser, half duplex mode" }, + { LLDP_DOT3_MAU_1000BASESXFD, + "1000BaseSXFD - Fiber over short-wavelength laser, full duplex mode" }, + { LLDP_DOT3_MAU_1000BASECXHD, + "1000BaseCXHD - Copper over 150-Ohm balanced cable, half duplex mode" }, + { LLDP_DOT3_MAU_1000BASECXFD, + "1000BaseCXFD - Copper over 150-Ohm balanced cable, full duplex mode" }, + { LLDP_DOT3_MAU_1000BASETHD, + "1000BaseTHD - Four-pair Category 5 UTP, half duplex mode" }, + { LLDP_DOT3_MAU_1000BASETFD, + "1000BaseTFD - Four-pair Category 5 UTP, full duplex mode" }, + { LLDP_DOT3_MAU_10GIGBASEX, "10GigBaseX - X PCS/PMA, unknown PMD." }, + { LLDP_DOT3_MAU_10GIGBASELX4, "10GigBaseLX4 - X fiber over WWDM optics" }, + { LLDP_DOT3_MAU_10GIGBASER, "10GigBaseR - R PCS/PMA, unknown PMD." }, + { LLDP_DOT3_MAU_10GIGBASEER, "10GigBaseER - R fiber over 1550 nm optics" }, + { LLDP_DOT3_MAU_10GIGBASELR, "10GigBaseLR - R fiber over 1310 nm optics" }, + { LLDP_DOT3_MAU_10GIGBASESR, "10GigBaseSR - R fiber over 850 nm optics" }, + { LLDP_DOT3_MAU_10GIGBASEW, "10GigBaseW - W PCS/PMA, unknown PMD." }, + { LLDP_DOT3_MAU_10GIGBASEEW, "10GigBaseEW - W fiber over 1550 nm optics" }, + { LLDP_DOT3_MAU_10GIGBASELW, "10GigBaseLW - W fiber over 1310 nm optics" }, + { LLDP_DOT3_MAU_10GIGBASESW, "10GigBaseSW - W fiber over 850 nm optics" }, + { LLDP_DOT3_MAU_10GIGBASECX4, + "10GigBaseCX4 - X copper over 8 pair 100-Ohm balanced cable" }, + { LLDP_DOT3_MAU_2BASETL, + "2BaseTL - Voice grade UTP copper, up to 2700m, optional PAF" }, + { LLDP_DOT3_MAU_10PASSTS, + "10PassTS - Voice grade UTP copper, up to 750m, optional PAF" }, + { LLDP_DOT3_MAU_100BASEBX10D, + "100BaseBX10D - One single-mode fiber OLT, long wavelength, 10km" }, + { LLDP_DOT3_MAU_100BASEBX10U, + "100BaseBX10U - One single-mode fiber ONU, long wavelength, 10km" }, + { LLDP_DOT3_MAU_100BASELX10, + "100BaseLX10 - Two single-mode fibers, long wavelength, 10km" }, + { LLDP_DOT3_MAU_1000BASEBX10D, + "1000BaseBX10D - One single-mode fiber OLT, long wavelength, 10km" }, + { LLDP_DOT3_MAU_1000BASEBX10U, + "1000BaseBX10U - One single-mode fiber ONU, long wavelength, 10km" }, + { LLDP_DOT3_MAU_1000BASELX10, + "1000BaseLX10 - Two sigle-mode fiber, long wavelength, 10km" }, + { LLDP_DOT3_MAU_1000BASEPX10D, + "1000BasePX10D - One single-mode fiber EPON OLT, 10km" }, + { LLDP_DOT3_MAU_1000BASEPX10U, + "1000BasePX10U - One single-mode fiber EPON ONU, 10km" }, + { LLDP_DOT3_MAU_1000BASEPX20D, + "1000BasePX20D - One single-mode fiber EPON OLT, 20km" }, + { LLDP_DOT3_MAU_1000BASEPX20U, + "1000BasePX20U - One single-mode fiber EPON ONU, 20km" }, + { LLDP_DOT3_MAU_10GBASET, + "10GbaseT - Four-pair Category 6A or better, full duplex mode only" }, + { LLDP_DOT3_MAU_10GBASELRM, + "10GbaseLRM - R multimode fiber over 1310 nm optics" }, + { LLDP_DOT3_MAU_1000BASEKX, "1000baseKX - X backplane, full duplex mode only" }, + { LLDP_DOT3_MAU_10GBASEKX4, + "10GbaseKX4 - 4 lane X backplane, full duplex mode only" }, + { LLDP_DOT3_MAU_10GBASEKR, "10GbaseKR - R backplane, full duplex mode only" }, + { LLDP_DOT3_MAU_10G1GBASEPRXD1, + "10G1GbasePRXD1 - One single-mode fiber asymmetric-rate EPON OLT, low power budget (PRX10)" }, + { LLDP_DOT3_MAU_10G1GBASEPRXD2, + "10G1GbasePRXD2 - One single-mode fiber asymmetric-rate EPON OLT, medium power budget (PRX20)" }, + { LLDP_DOT3_MAU_10G1GBASEPRXD3, + "10G1GbasePRXD3 - One single-mode fiber asymmetric-rate EPON OLT, high power budget (PRX30)" }, + { LLDP_DOT3_MAU_10G1GBASEPRXU1, + "10G1GbasePRXU1 - One single-mode fiber asymmetric-rate EPON ONU, low power budget (PRX10)" }, + { LLDP_DOT3_MAU_10G1GBASEPRXU2, + "10G1GbasePRXU2 - One single-mode fiber asymmetric-rate EPON ONU, medium power budget (PRX20)" }, + { LLDP_DOT3_MAU_10G1GBASEPRXU3, + "10G1GbasePRXU3 - One single-mode fiber asymmetric-rate EPON ONU, high power budget (PRX30)" }, + { LLDP_DOT3_MAU_10GBASEPRD1, + "10GbasePRD1 - One single-mode fiber symmetric-rate EPON OLT, low power budget (PR10)" }, + { LLDP_DOT3_MAU_10GBASEPRD2, + "10GbasePRD2 - One single-mode fiber symmetric-rate EPON OLT, medium power budget (PR20)" }, + { LLDP_DOT3_MAU_10GBASEPRD3, + "10GbasePRD3 - One single-mode fiber symmetric-rate EPON OLT, high power budget (PR30)" }, + { LLDP_DOT3_MAU_10GBASEPRU1, + "10GbasePRU1 - One single-mode fiber symmetric-rate EPON ONU, low and medium power budget" }, + { LLDP_DOT3_MAU_10GBASEPRU3, + "10GbasePRU3 - One single-mode fiber symmetric-rate EPON ONU, high power budget (PR30)" }, + { LLDP_DOT3_MAU_40GBASEKR4, + "40GbaseKR4 - 40GBASE-R PCS/PMA over an electrical backplane" }, + { LLDP_DOT3_MAU_40GBASECR4, + "40GbaseCR4 - 40GBASE-R PCS/PMA over 4 lane shielded copper balanced cable" }, + { LLDP_DOT3_MAU_40GBASESR4, + "40GbaseSR4 - 40GBASE-R PCS/PMA over 4 lane multimode fiber" }, + { LLDP_DOT3_MAU_40GBASEFR, + "40GbaseFR - 40GBASE-R PCS/PMA over single mode fiber" }, + { LLDP_DOT3_MAU_40GBASELR4, + "40GbaseLR4 - 40GBASE-R PCS/PMA over 4 WDM lane single mode fiber" }, + { LLDP_DOT3_MAU_100GBASECR10, + "100GbaseCR10 - 100GBASE-R PCS/PMA over 10 lane shielded copper balanced cable" }, + { LLDP_DOT3_MAU_100GBASESR10, + "100GbaseSR10 - 100GBASE-R PCS/PMA over 10 lane multimode fiber" }, + { LLDP_DOT3_MAU_100GBASELR4, + "100GbaseLR4 - 100GBASE-R PCS/PMA over 4 WDM lane single mode fiber, long reach" }, + { LLDP_DOT3_MAU_100GBASEER4, + "100GbaseER4 - 100GBASE-R PCS/PMA over 4 WDM lane single mode fiber PMD, extended reach" }, + { LLDP_DOT3_MAU_1000BASET1, + "1000baseT1 - 1000BASE-T1 single balanced twisted-pair copper cabling PHY" }, + { LLDP_DOT3_MAU_1000BASEPX30D, + "1000basePX30D - One single-mode fiber EPON OLT, 20km, 1:32 split ratio" }, + { LLDP_DOT3_MAU_1000BASEPX30U, + "1000basePX30U - One single-mode fiber EPON ONU, 20km, 1:32 split ratio" }, + { LLDP_DOT3_MAU_1000BASEPX40D, + "1000basePX40D - One single-mode fiber EPON OLT, 20km, 1:64 split ratio" }, + { LLDP_DOT3_MAU_1000BASEPX40U, + "1000basePX40U - One single-mode fiber EPON ONU, 20km, 1:64 split ratio" }, + { LLDP_DOT3_MAU_10G1GBASEPRXD4, + "10G1GbasePRXD4 - One single-mode fiber asymmetric-rate EPON OLT, supporting extended power budget (PRX40)" }, + { LLDP_DOT3_MAU_10G1GBASEPRXU4, + "10G1GbasePRXU4 - One single-mode fiber asymmetric-rate EPON ONU, supporting extended power budget (PRX40)" }, + { LLDP_DOT3_MAU_10GBASEPRD4, + "10GbasePRD4 - One single-mode fiber symmetric-rate EPON OLT, supporting extended power budget (PR40)" }, + { LLDP_DOT3_MAU_10GBASEPRU4, + "10GbasePRU4 - One single-mode fiber symmetric-rate EPON ONU, supporting extended power budget (PR40)" }, + { LLDP_DOT3_MAU_25GBASECR, + "25GbaseCR - 25GBASE-R PCS/PMA over shielded balanced copper cable" }, + { LLDP_DOT3_MAU_25GBASECRS, + "25GbaseCRS - 25GBASE-R PCS/PMA over shielded balanced copper cable without RS-FEC" }, + { LLDP_DOT3_MAU_25GBASEKR, + "25GbaseKR - 25GBASE-R PCS/PMA over an electrical backplane" }, + { LLDP_DOT3_MAU_25GBASEKRS, + "25GbaseKRS - 25GBASE-R PCS/PMA over an electrical backplane without RS-FEC" }, + { LLDP_DOT3_MAU_25GBASER, "25GbaseR - 25GBASE-R PCS/PMA over undefined PMD" }, + { LLDP_DOT3_MAU_25GBASESR, + "25GbaseSR - 25GBASE-R PCS/PMA over multimode fiber" }, + { LLDP_DOT3_MAU_25GBASET, + "25GbaseT - Four-pair twisted-pair balanced copper cabling" }, + { LLDP_DOT3_MAU_40GBASEER4, + "40GbaseER4 - 40GBASE-R PCS/PMA over 4 WDM lane single mode fiber" }, + { LLDP_DOT3_MAU_40GBASER, + "40GbaseR - 40GBASE-R PCS as over undefined PMA/PMD" }, + { LLDP_DOT3_MAU_40GBASET, + "40GbaseT - Four-pair twisted-pair balanced copper cabling" }, + { LLDP_DOT3_MAU_100GBASECR4, + "100GbaseCR4 - 100GBASE-R PCS/PMA over 4 lane shielded copper balanced cable" }, + { LLDP_DOT3_MAU_100GBASEKR4, + "100GbaseKR4 - 100GBASE-R PCS/PMA over an electrical backplane" }, + { LLDP_DOT3_MAU_100GBASEKP4, + "100GbaseKP4 - 100GBASE-P PCS/PMA over an electrical backplane PMD" }, + { LLDP_DOT3_MAU_100GBASER, + "100GbaseR - 100GBASE-R Multi-lane PCS over undefined PMA/PMD" }, + { LLDP_DOT3_MAU_100GBASESR4, + "100GbaseSR4 - 100GBASE-R PCS/PMA over 4 lane multimode fiber" }, + { LLDP_DOT3_MAU_2P5GIGT, + "2p5GigT - 2.5GBASE-T Four-pair twisted-pair balanced copper cabling PHY" }, + { LLDP_DOT3_MAU_5GIGT, + "5GigT - 5GBASE-T Four-pair twisted-pair balanced copper cabling PHY" }, + { LLDP_DOT3_MAU_100BASET1, + "100baseT1 - 100BASE-T1 Single balanced twisted-pair copper cabling PHY" }, + { LLDP_DOT3_MAU_1000BASERHA, + "1000baseRHA - 1000BASE-RHA Plastic optical fiber PHY" }, + { LLDP_DOT3_MAU_1000BASERHB, + "1000baseRHB - 1000BASE-RHB Plastic optical fiber PHY" }, + { LLDP_DOT3_MAU_1000BASERHC, + "1000baseRHC - 1000BASE-RHC Plastic optical fiber PHY" }, + { LLDP_DOT3_MAU_2P5GBASEKX, + "2p5GbaseKX - 2.5GBASE-X PMD over an electrical backplane" }, + { LLDP_DOT3_MAU_2P5GBASEX, + "2p5GbaseX - 2.5GBASE-X PCS/PMA over undefined PMD" }, + { LLDP_DOT3_MAU_5GBASEKR, + "5GbaseKR - 5GBASE-KR PMD over an electrical backplane" }, + { LLDP_DOT3_MAU_5GBASER, "5GbaseR - 5GBASE-R PCS/PMA over undefined PMD" }, + { LLDP_DOT3_MAU_10GPASSXR, + "10GpassXR - Coax cable distribution network PHY continuous downstream/burst mode upstream PHY" }, + { LLDP_DOT3_MAU_25GBASELR, + "25GbaseLR - 25GBASE-R PCS/PMA over single-mode fiber PMD, with long reach" }, + { LLDP_DOT3_MAU_25GBASEER, + "25GbaseER - 25GBASE-R PCS/PMA over single-mode fiber PMD, with extended reach" }, + { LLDP_DOT3_MAU_50GBASER, + "50GbaseR - 50GBASE-R Multi-lane PCS over undefined PMA/PMD" }, + { LLDP_DOT3_MAU_50GBASECR, + "50GbaseCR - 50GBASE-R PCS/PMA over shielded copper balanced cable PMD" }, + { LLDP_DOT3_MAU_50GBASEKR, + "50GbaseKR - 50GBASE-R PCS/PMA over an electrical backplane PMD" }, + { LLDP_DOT3_MAU_50GBASESR, + "50GbaseSR - 50GBASE-R PCS/PMA over multimode fiber PMD" }, + { LLDP_DOT3_MAU_50GBASEFR, + "50GbaseFR - 50GBASE-R PCS/PMA over single mode fiber PMD with reach up to at least 2 km" }, + { LLDP_DOT3_MAU_50GBASELR, + "50GbaseLR - 50GBASE-R PCS/PMA over single mode fiber PMD with reach up to at least 10 km" }, + { LLDP_DOT3_MAU_50GBASEER, + "50GbaseER - 50GBASE-R PCS/PMA over single-mode fiber PMD with reach up to at least 40 km" }, + { LLDP_DOT3_MAU_100GBASECR2, + "100GbaseCR2 - 100GBASE-R PCS/PMA over 2 lane shielded copper balanced cable PMD" }, + { LLDP_DOT3_MAU_100GBASEKR2, + "100GbaseKR2 - 100GBASE-R PCS/PMA over an electrical backplane PMD" }, + { LLDP_DOT3_MAU_100GBASESR2, + "100GbaseSR2 - 100GBASE-R PCS/PMA over 2 lane multimode fiber PMD" }, + { LLDP_DOT3_MAU_100GBASEDR, + "100GbaseDR - 100GBASE-R PCS/PMA over single mode fiber PMD" }, + { LLDP_DOT3_MAU_200GBASER, + "200GbaseR - 200GBASE-R Multi-lane PCS over undefined PMA/PMD" }, + { LLDP_DOT3_MAU_200GBASEDR4, + "200GbaseDR4 - 200GBASE-R PCS/PMA over 4-lane single-mode fiber PMD" }, + { LLDP_DOT3_MAU_200GBASEFR4, + "200GbaseFR4 - 200GBASE-R PCS/PMA over 4 WDM lane single-mode fiber PMD with reach up to at least 2 km" }, + { LLDP_DOT3_MAU_200GBASELR4, + "200GbaseLR4 - 200GBASE-R PCS/PMA over 4 WDM lane single-mode fiber PMD with reach up to at least 10 km" }, + { LLDP_DOT3_MAU_200GBASECR4, + "200GbaseCR4 - 200GBASE-R PCS/PMA over 4 lane shielded copper balanced cable PMD" }, + { LLDP_DOT3_MAU_200GBASEKR4, + "200GbaseKR4 - 200GBASE-R PCS/PMA over an electrical backplane PMD" }, + { LLDP_DOT3_MAU_200GBASESR4, + "200GbaseSR4 - 200GBASE-R PCS/PMA over 4 lane multimode fiber PMD" }, + { LLDP_DOT3_MAU_200GBASEER4, + "200GbaseER4 - 200GBASE-R PCS/PMA over 4 WDM lane single-mode fiber PMD with reach up to at least 40 km" }, + { LLDP_DOT3_MAU_400GBASER, + "400GbaseR - 400GBASE-R Multi-lane PCS over undefined PMA/PMD" }, + { LLDP_DOT3_MAU_400GBASESR16, + "400GbaseSR16 - 400GBASE-R PCS/PMA over 16-lane multimode fiber PMD" }, + { LLDP_DOT3_MAU_400GBASEDR4, + "400GbaseDR4 - 400GBASE-R PCS/PMA over 4-lane single-mode fiber PMD" }, + { LLDP_DOT3_MAU_400GBASEFR8, + "400GbaseFR8 - 400GBASE-R PCS/PMA over 8 WDM lane single-mode fiber PMD with reach up to at least 2 km" }, + { LLDP_DOT3_MAU_400GBASELR8, + "400GbaseLR8 - 400GBASE-R PCS/PMA over 8 WDM lane single-mode fiber PMD with reach up to at least 10 km" }, + { LLDP_DOT3_MAU_400GBASEER8, + "400GbaseER8 - 400GBASE-R PCS/PMA over 8 WDM lane single-mode fiber PMD with reach up to at least 40 km" }, + { LLDP_DOT3_MAU_10BASET1L, "10baseT1L - 10BASE-T1L Single balanced pair PHY" }, + { LLDP_DOT3_MAU_10BASET1SHD, + "10baseT1SHD - 10BASE-T1S Single balanced pair PHY, half duplex mode" }, + { LLDP_DOT3_MAU_10BASET1SMD, + "10baseT1SMD - 10BASE-T1S Single balanced pair PHY, multidrop mode" }, + { LLDP_DOT3_MAU_10BASET1SFD, + "10baseT1SFD - 10BASE-T1S Single balanced pair PHY, full duplex mode" }, { 0, NULL } }; #endif -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_iter_ports_list(lldpctl_atom_t *atom) { struct _lldpctl_atom_any_list_t *plist = (struct _lldpctl_atom_any_list_t *)atom; - return (lldpctl_atom_iter_t*)TAILQ_FIRST(&plist->parent->hardware->h_rports); + return (lldpctl_atom_iter_t *)TAILQ_FIRST(&plist->parent->hardware->h_rports); } -static lldpctl_atom_iter_t* +static lldpctl_atom_iter_t * _lldpctl_atom_next_ports_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct lldpd_port *port = (struct lldpd_port *)iter; - return (lldpctl_atom_iter_t*)TAILQ_NEXT(port, p_entries); + return (lldpctl_atom_iter_t *)TAILQ_NEXT(port, p_entries); } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_value_ports_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) { struct lldpd_port *port = (struct lldpd_port *)iter; @@ -240,20 +351,18 @@ _lldpctl_atom_value_ports_list(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter) static int _lldpctl_atom_new_port(lldpctl_atom_t *atom, va_list ap) { - struct _lldpctl_atom_port_t *port = - (struct _lldpctl_atom_port_t *)atom; + struct _lldpctl_atom_port_t *port = (struct _lldpctl_atom_port_t *)atom; port->local = va_arg(ap, int); - port->hardware = va_arg(ap, struct lldpd_hardware*); - port->port = va_arg(ap, struct lldpd_port*); - port->parent = va_arg(ap, struct _lldpctl_atom_port_t*); - if (port->parent) - lldpctl_atom_inc_ref((lldpctl_atom_t*)port->parent); + port->hardware = va_arg(ap, struct lldpd_hardware *); + port->port = va_arg(ap, struct lldpd_port *); + port->parent = va_arg(ap, struct _lldpctl_atom_port_t *); + if (port->parent) lldpctl_atom_inc_ref((lldpctl_atom_t *)port->parent); if (port->port) { /* Internal atom. We are the parent, but our reference count is * not incremented. */ port->chassis = _lldpctl_new_atom(atom->conn, atom_chassis, - port->port->p_chassis, port, 1); + port->port->p_chassis, port, 1); } return 1; } @@ -261,29 +370,26 @@ _lldpctl_atom_new_port(lldpctl_atom_t *atom, va_list ap) TAILQ_HEAD(chassis_list, lldpd_chassis); static void -add_chassis(struct chassis_list *chassis_list, - struct lldpd_chassis *chassis) +add_chassis(struct chassis_list *chassis_list, struct lldpd_chassis *chassis) { struct lldpd_chassis *one_chassis; - TAILQ_FOREACH(one_chassis, chassis_list, c_entries) { + TAILQ_FOREACH (one_chassis, chassis_list, c_entries) { if (one_chassis == chassis) return; } - TAILQ_INSERT_TAIL(chassis_list, - chassis, c_entries); + TAILQ_INSERT_TAIL(chassis_list, chassis, c_entries); } static void _lldpctl_atom_free_port(lldpctl_atom_t *atom) { - struct _lldpctl_atom_port_t *port = - (struct _lldpctl_atom_port_t *)atom; + struct _lldpctl_atom_port_t *port = (struct _lldpctl_atom_port_t *)atom; struct lldpd_hardware *hardware = port->hardware; - struct lldpd_chassis *one_chassis, *one_chassis_next; - struct lldpd_port *one_port; + struct lldpd_chassis *one_chassis, *one_chassis_next; + struct lldpd_port *one_port; /* Free internal chassis atom. Should be freed immediately since we * should have the only reference. */ - lldpctl_atom_dec_ref((lldpctl_atom_t*)port->chassis); + lldpctl_atom_dec_ref((lldpctl_atom_t *)port->chassis); /* We need to free the whole struct lldpd_hardware: local port, local * chassis and remote ports... The same chassis may be present several @@ -291,7 +397,8 @@ _lldpctl_atom_free_port(lldpctl_atom_t *atom) struct chassis_list chassis_list; TAILQ_INIT(&chassis_list); - if (port->parent) lldpctl_atom_dec_ref((lldpctl_atom_t*)port->parent); + if (port->parent) + lldpctl_atom_dec_ref((lldpctl_atom_t *)port->parent); else if (!hardware && port->port) { /* No parent, no hardware, we assume a single neighbor: one * port, one chassis. */ @@ -305,7 +412,7 @@ _lldpctl_atom_free_port(lldpctl_atom_t *atom) if (!hardware) return; add_chassis(&chassis_list, port->port->p_chassis); - TAILQ_FOREACH(one_port, &hardware->h_rports, p_entries) + TAILQ_FOREACH (one_port, &hardware->h_rports, p_entries) add_chassis(&chassis_list, one_port->p_chassis); /* Free hardware port */ @@ -314,20 +421,18 @@ _lldpctl_atom_free_port(lldpctl_atom_t *atom) free(port->hardware); /* Free list of chassis */ - for (one_chassis = TAILQ_FIRST(&chassis_list); - one_chassis != NULL; + for (one_chassis = TAILQ_FIRST(&chassis_list); one_chassis != NULL; one_chassis = one_chassis_next) { one_chassis_next = TAILQ_NEXT(one_chassis, c_entries); lldpd_chassis_cleanup(one_chassis, 1); } } -static lldpctl_atom_t* +static lldpctl_atom_t * _lldpctl_atom_get_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_port_t *p = - (struct _lldpctl_atom_port_t *)atom; - struct lldpd_port *port = p->port; + struct _lldpctl_atom_port_t *p = (struct _lldpctl_atom_port_t *)atom; + struct lldpd_port *port = p->port; struct lldpd_hardware *hardware = p->hardware; /* Local port only */ @@ -335,7 +440,8 @@ _lldpctl_atom_get_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key) switch (key) { case lldpctl_k_port_neighbors: return _lldpctl_new_atom(atom->conn, atom_ports_list, p); - default: break; + default: + break; } } @@ -350,27 +456,21 @@ _lldpctl_atom_get_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key) return NULL; #ifdef ENABLE_DOT3 case lldpctl_k_port_dot3_power: - return _lldpctl_new_atom(atom->conn, atom_dot3_power, - p); + return _lldpctl_new_atom(atom->conn, atom_dot3_power, p); #endif #ifdef ENABLE_DOT1 case lldpctl_k_port_vlans: - return _lldpctl_new_atom(atom->conn, atom_vlans_list, - p); + return _lldpctl_new_atom(atom->conn, atom_vlans_list, p); case lldpctl_k_port_ppvids: - return _lldpctl_new_atom(atom->conn, atom_ppvids_list, - p); + return _lldpctl_new_atom(atom->conn, atom_ppvids_list, p); case lldpctl_k_port_pis: - return _lldpctl_new_atom(atom->conn, atom_pis_list, - p); + return _lldpctl_new_atom(atom->conn, atom_pis_list, p); #endif #ifdef ENABLE_LLDPMED case lldpctl_k_port_med_policies: - return _lldpctl_new_atom(atom->conn, atom_med_policies_list, - p); + return _lldpctl_new_atom(atom->conn, atom_med_policies_list, p); case lldpctl_k_port_med_locations: - return _lldpctl_new_atom(atom->conn, atom_med_locations_list, - p); + return _lldpctl_new_atom(atom->conn, atom_med_locations_list, p); case lldpctl_k_port_med_power: return _lldpctl_new_atom(atom->conn, atom_med_power, p); #endif @@ -380,18 +480,17 @@ _lldpctl_atom_get_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key) #endif default: /* Compatibility: query the associated chassis too */ - if (port->p_chassis) - return lldpctl_atom_get(p->chassis, key); + if (port->p_chassis) return lldpctl_atom_get(p->chassis, key); SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); return NULL; } } -static lldpctl_atom_t* -_lldpctl_atom_set_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key, lldpctl_atom_t *value) +static lldpctl_atom_t * +_lldpctl_atom_set_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key, + lldpctl_atom_t *value) { - struct _lldpctl_atom_port_t *p = - (struct _lldpctl_atom_port_t *)atom; + struct _lldpctl_atom_port_t *p = (struct _lldpctl_atom_port_t *)atom; struct lldpd_hardware *hardware = p->hardware; struct lldpd_port_set set = {}; int rc; @@ -406,7 +505,7 @@ _lldpctl_atom_set_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key, lldpctl_ato struct _lldpctl_atom_med_location_t *mloc; #endif #ifdef ENABLE_CUSTOM - struct _lldpctl_atom_custom_t *custom; + struct _lldpctl_atom_custom_t *custom; #endif /* Local and default port only */ @@ -494,24 +593,22 @@ _lldpctl_atom_set_atom_port(lldpctl_atom_t *atom, lldpctl_key_t key, lldpctl_ato SET_ERROR(atom->conn, LLDPCTL_ERR_NOMEM); return NULL; } - rc = _lldpctl_do_something(atom->conn, - CONN_STATE_SET_PORT_SEND, CONN_STATE_SET_PORT_RECV, - canary, - SET_PORT, &set, &MARSHAL_INFO(lldpd_port_set), - NULL, NULL); + rc = _lldpctl_do_something(atom->conn, CONN_STATE_SET_PORT_SEND, + CONN_STATE_SET_PORT_RECV, canary, SET_PORT, &set, + &MARSHAL_INFO(lldpd_port_set), NULL, NULL); free(canary); if (rc == 0) return atom; return NULL; } -static const char* +static const char * _lldpctl_atom_get_str_port(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_port_t *p = - (struct _lldpctl_atom_port_t *)atom; - struct lldpd_port *port = p->port; + struct _lldpctl_atom_port_t *p = (struct _lldpctl_atom_port_t *)atom; + struct lldpd_port *port = p->port; struct lldpd_hardware *hardware = p->hardware; - char *ipaddress = NULL; size_t len; + char *ipaddress = NULL; + size_t len; /* Local port only */ switch (key) { @@ -519,14 +616,15 @@ _lldpctl_atom_get_str_port(lldpctl_atom_t *atom, lldpctl_key_t key) if (hardware != NULL) return hardware->h_ifname; break; case lldpctl_k_port_status: - if (p->local) return map_lookup(port_status_map.map, - LLDPD_RXTX_FROM_PORT(port)); + if (p->local) + return map_lookup(port_status_map.map, + LLDPD_RXTX_FROM_PORT(port)); + break; + default: break; - default: break; } - if (!port) - return NULL; + if (!port) return NULL; /* Local and remote port */ switch (key) { @@ -541,20 +639,25 @@ _lldpctl_atom_get_str_port(lldpctl_atom_t *atom, lldpctl_key_t key) case LLDP_PORTID_SUBTYPE_LOCAL: return port->p_id; case LLDP_PORTID_SUBTYPE_LLADDR: - return _lldpctl_dump_in_atom(atom, - (uint8_t*)port->p_id, port->p_id_len, - ':', 0); + return _lldpctl_dump_in_atom(atom, (uint8_t *)port->p_id, + port->p_id_len, ':', 0); case LLDP_PORTID_SUBTYPE_ADDR: switch (port->p_id[0]) { - case LLDP_MGMT_ADDR_IP4: len = INET_ADDRSTRLEN + 1; break; - case LLDP_MGMT_ADDR_IP6: len = INET6_ADDRSTRLEN + 1; break; - default: len = 0; + case LLDP_MGMT_ADDR_IP4: + len = INET_ADDRSTRLEN + 1; + break; + case LLDP_MGMT_ADDR_IP6: + len = INET6_ADDRSTRLEN + 1; + break; + default: + len = 0; } if (len > 0) { ipaddress = _lldpctl_alloc_in_atom(atom, len); if (!ipaddress) return NULL; - if (inet_ntop((port->p_id[0] == LLDP_MGMT_ADDR_IP4)? - AF_INET:AF_INET6, + if (inet_ntop((port->p_id[0] == LLDP_MGMT_ADDR_IP4) ? + AF_INET : + AF_INET6, &port->p_id[1], ipaddress, len) == NULL) break; return ipaddress; @@ -568,8 +671,7 @@ _lldpctl_atom_get_str_port(lldpctl_atom_t *atom, lldpctl_key_t key) #ifdef ENABLE_DOT3 case lldpctl_k_port_dot3_mautype: - return map_lookup(operational_mau_type_values, - port->p_macphy.mau_type); + return map_lookup(operational_mau_type_values, port->p_macphy.mau_type); #endif default: @@ -578,13 +680,11 @@ _lldpctl_atom_get_str_port(lldpctl_atom_t *atom, lldpctl_key_t key) } } -static lldpctl_atom_t* -_lldpctl_atom_set_int_port(lldpctl_atom_t *atom, lldpctl_key_t key, - long int value) +static lldpctl_atom_t * +_lldpctl_atom_set_int_port(lldpctl_atom_t *atom, lldpctl_key_t key, long int value) { - struct _lldpctl_atom_port_t *p = - (struct _lldpctl_atom_port_t *)atom; - struct lldpd_port *port = p->port; + struct _lldpctl_atom_port_t *p = (struct _lldpctl_atom_port_t *)atom; + struct lldpd_port *port = p->port; if (p->local) { switch (key) { @@ -611,23 +711,21 @@ _lldpctl_atom_set_int_port(lldpctl_atom_t *atom, lldpctl_key_t key, return _lldpctl_atom_set_atom_port(atom, key, NULL); } -static lldpctl_atom_t* -_lldpctl_atom_set_str_port(lldpctl_atom_t *atom, lldpctl_key_t key, - const char *value) +static lldpctl_atom_t * +_lldpctl_atom_set_str_port(lldpctl_atom_t *atom, lldpctl_key_t key, const char *value) { - struct _lldpctl_atom_port_t *p = - (struct _lldpctl_atom_port_t *)atom; - struct lldpd_port *port = p->port; + struct _lldpctl_atom_port_t *p = (struct _lldpctl_atom_port_t *)atom; + struct lldpd_port *port = p->port; - if (!value || !strlen(value)) - return NULL; + if (!value || !strlen(value)) return NULL; if (p->local) { switch (key) { case lldpctl_k_port_status: return _lldpctl_atom_set_int_port(atom, key, map_reverse_lookup(port_status_map.map, value)); - default: break; + default: + break; } } @@ -652,9 +750,8 @@ _lldpctl_atom_set_str_port(lldpctl_atom_t *atom, lldpctl_key_t key, static long int _lldpctl_atom_get_int_port(lldpctl_atom_t *atom, lldpctl_key_t key) { - struct _lldpctl_atom_port_t *p = - (struct _lldpctl_atom_port_t *)atom; - struct lldpd_port *port = p->port; + struct _lldpctl_atom_port_t *p = (struct _lldpctl_atom_port_t *)atom; + struct lldpd_port *port = p->port; struct lldpd_hardware *hardware = p->hardware; /* Local port only */ @@ -676,18 +773,19 @@ _lldpctl_atom_get_int_port(lldpctl_atom_t *atom, lldpctl_key_t key) return hardware->h_insert_cnt; case lldpctl_k_delete_cnt: return hardware->h_delete_cnt; - default: break; + default: + break; } } if (p->local) { switch (key) { case lldpctl_k_port_status: return LLDPD_RXTX_FROM_PORT(port); - default: break; + default: + break; } } - if (!port) - return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); + if (!port) return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); /* Local and remote port */ switch (key) { @@ -705,12 +803,10 @@ _lldpctl_atom_get_int_port(lldpctl_atom_t *atom, lldpctl_key_t key) return port->p_vlan_tx_enabled ? port->p_vlan_tx_tag : -1; #ifdef ENABLE_DOT3 case lldpctl_k_port_dot3_mfs: - if (port->p_mfs > 0) - return port->p_mfs; + if (port->p_mfs > 0) return port->p_mfs; break; case lldpctl_k_port_dot3_aggregid: - if (port->p_aggregid > 0) - return port->p_aggregid; + if (port->p_aggregid > 0) return port->p_aggregid; break; case lldpctl_k_port_dot3_autoneg_support: return port->p_macphy.autoneg_support; @@ -732,43 +828,34 @@ _lldpctl_atom_get_int_port(lldpctl_atom_t *atom, lldpctl_key_t key) return SET_ERROR(atom->conn, LLDPCTL_ERR_NOT_EXIST); } -static const uint8_t* +static const uint8_t * _lldpctl_atom_get_buf_port(lldpctl_atom_t *atom, lldpctl_key_t key, size_t *n) { - struct _lldpctl_atom_port_t *p = - (struct _lldpctl_atom_port_t *)atom; - struct lldpd_port *port = p->port; + struct _lldpctl_atom_port_t *p = (struct _lldpctl_atom_port_t *)atom; + struct lldpd_port *port = p->port; switch (key) { case lldpctl_k_port_id: *n = port->p_id_len; - return (uint8_t*)port->p_id; + return (uint8_t *)port->p_id; default: /* Compatibility: query the associated chassis too */ return lldpctl_atom_get_buffer(p->chassis, key, n); } } -static struct atom_builder ports_list = - { atom_ports_list, sizeof(struct _lldpctl_atom_any_list_t), - .init = _lldpctl_atom_new_any_list, - .free = _lldpctl_atom_free_any_list, - .iter = _lldpctl_atom_iter_ports_list, - .next = _lldpctl_atom_next_ports_list, - .value = _lldpctl_atom_value_ports_list }; - -static struct atom_builder port = - { atom_port, sizeof(struct _lldpctl_atom_port_t), - .init = _lldpctl_atom_new_port, - .free = _lldpctl_atom_free_port, - .get = _lldpctl_atom_get_atom_port, - .set = _lldpctl_atom_set_atom_port, - .get_str = _lldpctl_atom_get_str_port, - .set_str = _lldpctl_atom_set_str_port, - .get_int = _lldpctl_atom_get_int_port, - .set_int = _lldpctl_atom_set_int_port, - .get_buffer = _lldpctl_atom_get_buf_port }; +static struct atom_builder ports_list = { atom_ports_list, + sizeof(struct _lldpctl_atom_any_list_t), .init = _lldpctl_atom_new_any_list, + .free = _lldpctl_atom_free_any_list, .iter = _lldpctl_atom_iter_ports_list, + .next = _lldpctl_atom_next_ports_list, + .value = _lldpctl_atom_value_ports_list }; -ATOM_BUILDER_REGISTER(ports_list, 4); -ATOM_BUILDER_REGISTER(port, 5); +static struct atom_builder port = { atom_port, sizeof(struct _lldpctl_atom_port_t), + .init = _lldpctl_atom_new_port, .free = _lldpctl_atom_free_port, + .get = _lldpctl_atom_get_atom_port, .set = _lldpctl_atom_set_atom_port, + .get_str = _lldpctl_atom_get_str_port, .set_str = _lldpctl_atom_set_str_port, + .get_int = _lldpctl_atom_get_int_port, .set_int = _lldpctl_atom_set_int_port, + .get_buffer = _lldpctl_atom_get_buf_port }; +ATOM_BUILDER_REGISTER(ports_list, 4); +ATOM_BUILDER_REGISTER(port, 5); diff --git a/src/lib/connection.c b/src/lib/connection.c index e1acce0f..43f46cb0 100644 --- a/src/lib/connection.c +++ b/src/lib/connection.c @@ -27,7 +27,7 @@ #include "../ctl.h" #include "../log.h" -const char* +const char * lldpctl_get_default_transport(void) { return LLDPD_CTL_SOCKET; @@ -42,14 +42,12 @@ sync_connect(lldpctl_conn_t *lldpctl) /* Synchronously send data to remote end. */ static ssize_t -sync_send(lldpctl_conn_t *lldpctl, - const uint8_t *data, size_t length, void *user_data) +sync_send(lldpctl_conn_t *lldpctl, const uint8_t *data, size_t length, void *user_data) { struct lldpctl_conn_sync_t *conn = user_data; ssize_t nb; - if (conn->fd == -1 && - ((conn->fd = sync_connect(lldpctl)) == -1)) { + if (conn->fd == -1 && ((conn->fd = sync_connect(lldpctl)) == -1)) { return LLDPCTL_ERR_CANNOT_CONNECT; } @@ -62,24 +60,22 @@ sync_send(lldpctl_conn_t *lldpctl, /* Statically receive data from remote end. */ static ssize_t -sync_recv(lldpctl_conn_t *lldpctl, - const uint8_t *data, size_t length, void *user_data) +sync_recv(lldpctl_conn_t *lldpctl, const uint8_t *data, size_t length, void *user_data) { struct lldpctl_conn_sync_t *conn = user_data; ssize_t nb; size_t remain, offset = 0; - if (conn->fd == -1 && - ((conn->fd = sync_connect(lldpctl)) == -1)) { + if (conn->fd == -1 && ((conn->fd = sync_connect(lldpctl)) == -1)) { lldpctl->error = LLDPCTL_ERR_CANNOT_CONNECT; return LLDPCTL_ERR_CANNOT_CONNECT; } remain = length; do { - if ((nb = read(conn->fd, (unsigned char*)data + offset, remain)) == -1) { - if (errno == EAGAIN || errno == EINTR) - continue; + if ((nb = read(conn->fd, (unsigned char *)data + offset, remain)) == + -1) { + if (errno == EAGAIN || errno == EINTR) continue; return LLDPCTL_ERR_CALLBACK_FAILURE; } remain -= nb; @@ -88,14 +84,15 @@ sync_recv(lldpctl_conn_t *lldpctl, return offset; } -lldpctl_conn_t* +lldpctl_conn_t * lldpctl_new(lldpctl_send_callback send, lldpctl_recv_callback recv, void *user_data) { return lldpctl_new_name(lldpctl_get_default_transport(), send, recv, user_data); } -lldpctl_conn_t* -lldpctl_new_name(const char *ctlname, lldpctl_send_callback send, lldpctl_recv_callback recv, void *user_data) +lldpctl_conn_t * +lldpctl_new_name(const char *ctlname, lldpctl_send_callback send, + lldpctl_recv_callback recv, void *user_data) { lldpctl_conn_t *conn = NULL; struct lldpctl_conn_sync_t *data = NULL; @@ -104,8 +101,7 @@ lldpctl_new_name(const char *ctlname, lldpctl_send_callback send, lldpctl_recv_c if (send && !recv) return NULL; if (recv && !send) return NULL; - if ((conn = calloc(1, sizeof(lldpctl_conn_t))) == NULL) - return NULL; + if ((conn = calloc(1, sizeof(lldpctl_conn_t))) == NULL) return NULL; conn->ctlname = strdup(ctlname); if (conn->ctlname == NULL) { @@ -158,7 +154,7 @@ ssize_t _lldpctl_needs(lldpctl_conn_t *conn, size_t length) { uint8_t *buffer; - ssize_t rc; + ssize_t rc; if ((buffer = calloc(1, length)) == NULL) return SET_ERROR(conn, LLDPCTL_ERR_NOMEM); @@ -173,8 +169,7 @@ _lldpctl_needs(lldpctl_conn_t *conn, size_t length) } rc = lldpctl_recv(conn, buffer, rc); free(buffer); - if (rc < 0) - return SET_ERROR(conn, rc); + if (rc < 0) return SET_ERROR(conn, rc); RESET_ERROR(conn); return rc; } @@ -187,33 +182,36 @@ check_for_notification(lldpctl_conn_t *conn) int rc; lldpctl_change_t type; lldpctl_atom_t *interface = NULL, *neighbor = NULL; - rc = ctl_msg_recv_unserialized(&conn->input_buffer, - &conn->input_buffer_len, - NOTIFICATION, - &p, - &MARSHAL_INFO(lldpd_neighbor_change)); + rc = ctl_msg_recv_unserialized(&conn->input_buffer, &conn->input_buffer_len, + NOTIFICATION, &p, &MARSHAL_INFO(lldpd_neighbor_change)); if (rc != 0) return rc; change = p; /* We have a notification, call the callback */ if (conn->watch_cb || conn->watch_cb2) { switch (change->state) { - case NEIGHBOR_CHANGE_DELETED: type = lldpctl_c_deleted; break; - case NEIGHBOR_CHANGE_ADDED: type = lldpctl_c_added; break; - case NEIGHBOR_CHANGE_UPDATED: type = lldpctl_c_updated; break; + case NEIGHBOR_CHANGE_DELETED: + type = lldpctl_c_deleted; + break; + case NEIGHBOR_CHANGE_ADDED: + type = lldpctl_c_added; + break; + case NEIGHBOR_CHANGE_UPDATED: + type = lldpctl_c_updated; + break; default: log_warnx("control", "unknown notification type (%d)", change->state); goto end; } - interface = _lldpctl_new_atom(conn, atom_interface, - change->ifname); + interface = _lldpctl_new_atom(conn, atom_interface, change->ifname); if (interface == NULL) goto end; - neighbor = _lldpctl_new_atom(conn, atom_port, 0, - NULL, change->neighbor, NULL); + neighbor = + _lldpctl_new_atom(conn, atom_port, 0, NULL, change->neighbor, NULL); if (neighbor == NULL) goto end; if (conn->watch_cb) - conn->watch_cb(conn, type, interface, neighbor, conn->watch_data); + conn->watch_cb(conn, type, interface, neighbor, + conn->watch_data); else conn->watch_cb2(type, interface, neighbor, conn->watch_data); conn->watch_triggered = 1; @@ -222,7 +220,8 @@ check_for_notification(lldpctl_conn_t *conn) end: if (interface) lldpctl_atom_dec_ref(interface); - if (neighbor) lldpctl_atom_dec_ref(neighbor); + if (neighbor) + lldpctl_atom_dec_ref(neighbor); else { lldpd_chassis_cleanup(change->neighbor->p_chassis, 1); lldpd_port_cleanup(change->neighbor, 1); @@ -249,16 +248,17 @@ lldpctl_recv(lldpctl_conn_t *conn, const uint8_t *data, size_t length) if ((conn->input_buffer = malloc(length)) == NULL) return SET_ERROR(conn, LLDPCTL_ERR_NOMEM); } else { - uint8_t *new = realloc(conn->input_buffer, conn->input_buffer_len + length); - if (new == NULL) - return SET_ERROR(conn, LLDPCTL_ERR_NOMEM); + uint8_t *new = + realloc(conn->input_buffer, conn->input_buffer_len + length); + if (new == NULL) return SET_ERROR(conn, LLDPCTL_ERR_NOMEM); conn->input_buffer = new; } memcpy(conn->input_buffer + conn->input_buffer_len, data, length); conn->input_buffer_len += length; /* Read all notifications */ - while(!check_for_notification(conn)); + while (!check_for_notification(conn)) + ; RESET_ERROR(conn); @@ -286,8 +286,7 @@ lldpctl_send(lldpctl_conn_t *conn) RESET_ERROR(conn); if (!conn->output_buffer) return 0; - rc = conn->send(conn, - conn->output_buffer, conn->output_buffer_len, + rc = conn->send(conn, conn->output_buffer, conn->output_buffer_len, conn->user_data); if (rc < 0) return SET_ERROR(conn, rc); diff --git a/src/lib/errors.c b/src/lib/errors.c index 2f8638ee..899ca6fe 100644 --- a/src/lib/errors.c +++ b/src/lib/errors.c @@ -19,25 +19,39 @@ #include "atom.h" #include "../log.h" -const char* +const char * lldpctl_strerror(lldpctl_error_t error) { /* No default case to let the compiler warns us if we miss an error code. */ switch (error) { - case LLDPCTL_NO_ERROR: return "No error"; - case LLDPCTL_ERR_WOULDBLOCK: return "Requested operation would block"; - case LLDPCTL_ERR_EOF: return "End of file reached"; - case LLDPCTL_ERR_NOT_EXIST: return "The requested information does not exist"; - case LLDPCTL_ERR_CANNOT_CONNECT: return "Unable to connect to lldpd daemon"; - case LLDPCTL_ERR_INCORRECT_ATOM_TYPE: return "Provided atom is of incorrect type"; - case LLDPCTL_ERR_SERIALIZATION: return "Error while serializing or unserializing data"; - case LLDPCTL_ERR_INVALID_STATE: return "Other input/output operation already in progress"; - case LLDPCTL_ERR_CANNOT_ITERATE: return "Cannot iterate on this atom"; - case LLDPCTL_ERR_CANNOT_CREATE: return "Cannot create a new element for this atom"; - case LLDPCTL_ERR_BAD_VALUE: return "Provided value is invalid"; - case LLDPCTL_ERR_FATAL: return "Unexpected fatal error"; - case LLDPCTL_ERR_NOMEM: return "Not enough memory available"; - case LLDPCTL_ERR_CALLBACK_FAILURE: return "A failure occurred during callback processing"; + case LLDPCTL_NO_ERROR: + return "No error"; + case LLDPCTL_ERR_WOULDBLOCK: + return "Requested operation would block"; + case LLDPCTL_ERR_EOF: + return "End of file reached"; + case LLDPCTL_ERR_NOT_EXIST: + return "The requested information does not exist"; + case LLDPCTL_ERR_CANNOT_CONNECT: + return "Unable to connect to lldpd daemon"; + case LLDPCTL_ERR_INCORRECT_ATOM_TYPE: + return "Provided atom is of incorrect type"; + case LLDPCTL_ERR_SERIALIZATION: + return "Error while serializing or unserializing data"; + case LLDPCTL_ERR_INVALID_STATE: + return "Other input/output operation already in progress"; + case LLDPCTL_ERR_CANNOT_ITERATE: + return "Cannot iterate on this atom"; + case LLDPCTL_ERR_CANNOT_CREATE: + return "Cannot create a new element for this atom"; + case LLDPCTL_ERR_BAD_VALUE: + return "Provided value is invalid"; + case LLDPCTL_ERR_FATAL: + return "Unexpected fatal error"; + case LLDPCTL_ERR_NOMEM: + return "Not enough memory available"; + case LLDPCTL_ERR_CALLBACK_FAILURE: + return "A failure occurred during callback processing"; } return "Unknown error code"; } @@ -57,5 +71,5 @@ lldpctl_log_callback(void (*cb)(int severity, const char *msg)) void lldpctl_log_level(int level) { - if (level >= 1) log_level(level-1); + if (level >= 1) log_level(level - 1); } diff --git a/src/lib/fixedpoint.c b/src/lib/fixedpoint.c index e5184e7b..4df0b501 100644 --- a/src/lib/fixedpoint.c +++ b/src/lib/fixedpoint.c @@ -28,11 +28,11 @@ #ifdef ENABLE_LLDPMED -#ifndef ntohll -# define ntohll(x) \ - (((u_int64_t)(ntohl((int)(((x) << 32) >> 32))) << 32) | \ - (unsigned int)ntohl(((int)((x) >> 32)))) -#endif +# ifndef ntohll +# define ntohll(x) \ + (((u_int64_t)(ntohl((int)(((x) << 32) >> 32))) << 32) | \ + (unsigned int)ntohl(((int)((x) >> 32)))) +# endif /** * Convert a string to fixed point number. @@ -50,14 +50,11 @@ * part. */ struct fp_number -fp_strtofp(const char *repr, char **end, - unsigned intbits, unsigned fltbits) +fp_strtofp(const char *repr, char **end, unsigned intbits, unsigned fltbits) { char *endptr = NULL, *e2; - struct fp_number result = { - .integer = { 0, intbits }, - .fraction = { 0, fltbits, 0 } - }; + struct fp_number result = { .integer = { 0, intbits }, + .fraction = { 0, fltbits, 0 } }; result.integer.value = strtoll(repr, &endptr, 10); if (result.integer.value >= (1LL << (intbits - 1))) result.integer.value = (1LL << (intbits - 1)) - 1; @@ -74,10 +71,12 @@ fp_strtofp(const char *repr, char **end, * represent anything between 0 and 0.9999 with the same * precision. Therefore, we don't have only 4 bits of precision * but 14. */ - while (e2++ != endptr) precision *= 10; + while (e2++ != endptr) + precision *= 10; result.fraction.value <<= fltbits; result.fraction.value /= precision; - result.fraction.precision = (precision == 1)?1: + result.fraction.precision = (precision == 1) ? + 1 : (sizeof(precision) * 8 - __builtin_clzll(precision - 1)); if (result.fraction.precision > fltbits) result.fraction.precision = fltbits; @@ -115,19 +114,18 @@ fp_fptostr(struct fp_number fp, const char *suffix) } /* We did round-up, when converting from decimal. We round-down * to have some coherency. */ - precision /= 10; len -= 1; + precision /= 10; + len -= 1; if (precision == 0) precision = 1; decimal *= precision; decimal >>= fp.fraction.bits; - if (asprintf(&frac, ".%0*llu", len, decimal) == -1) - return NULL; + if (asprintf(&frac, ".%0*llu", len, decimal) == -1) return NULL; } - if (asprintf(&result, "%s%llu%s%c", - (suffix == NULL && negative) ? "-" : "", - (negative) ? (-fp.integer.value) : fp.integer.value, - frac, - (suffix && !negative) ? suffix[0] : - (suffix && negative) ? suffix[1] : ' ') == -1) { + if (asprintf(&result, "%s%llu%s%c", (suffix == NULL && negative) ? "-" : "", + (negative) ? (-fp.integer.value) : fp.integer.value, frac, + (suffix && !negative) ? suffix[0] : + (suffix && negative) ? suffix[1] : + ' ') == -1) { free(frac); return NULL; } @@ -153,21 +151,23 @@ fp_fptobuf(struct fp_number fp, unsigned char *buf, unsigned shift) unsigned long long value = (fp.integer.value >= 0) ? ((fp.integer.value << fp.fraction.bits) + fp.fraction.value) : (~(((unsigned long long)(-fp.integer.value) << fp.fraction.bits) + - fp.fraction.value) + 1); - unsigned long long ints[] = { fp.integer.bits + fp.fraction.precision, - value }; - unsigned int bits[] = { 6, - fp.integer.bits + fp.fraction.bits }; + fp.fraction.value) + + 1); + unsigned long long ints[] = { fp.integer.bits + fp.fraction.precision, value }; + unsigned int bits[] = { 6, fp.integer.bits + fp.fraction.bits }; unsigned i, obit, o; for (i = 0, obit = 8 - (shift % 8), o = shift / 8; i < 2;) { if (obit > bits[i]) { - /* We need to clear bits that will be overwritten but do not touch other bits */ + /* We need to clear bits that will be overwritten but do not + * touch other bits */ if (bits[i] != 0) { - buf[o] = buf[o] & (~((1 << obit) - 1) | - ((1 << (obit - bits[i])) - 1)); + buf[o] = buf[o] & + (~((1 << obit) - 1) | + ((1 << (obit - bits[i])) - 1)); buf[o] = buf[o] | - ((ints[i] & ((1 << bits[i]) - 1)) << (obit - bits[i])); + ((ints[i] & ((1 << bits[i]) - 1)) + << (obit - bits[i])); obit -= bits[i]; } i++; @@ -196,26 +196,25 @@ fp_fptobuf(struct fp_number fp, unsigned char *buf, unsigned shift) * The representation is the same as for @c fp_fptobuf(). */ struct fp_number -fp_buftofp(const unsigned char *buf, - unsigned intbits, unsigned fltbits, - unsigned shift) +fp_buftofp(const unsigned char *buf, unsigned intbits, unsigned fltbits, unsigned shift) { unsigned long long value = 0, precision = 0; - unsigned long long *ints[] = { &precision, - &value }; - unsigned int bits[] = { 6, - intbits + fltbits }; + unsigned long long *ints[] = { &precision, &value }; + unsigned int bits[] = { 6, intbits + fltbits }; unsigned o, ibit, i; for (o = 0, ibit = 8 - (shift % 8), i = shift / 8; o < 2;) { if (ibit > bits[o]) { if (bits[o] > 0) { - *ints[o] = *ints[o] | ((buf[i] >> (ibit - bits[o])) & ((1ULL << bits[o]) - 1)); + *ints[o] = *ints[o] | + ((buf[i] >> (ibit - bits[o])) & + ((1ULL << bits[o]) - 1)); ibit -= bits[o]; } o++; } else { - *ints[o] = *ints[o] | ((buf[i] & ((1ULL << ibit) - 1)) << (bits[o] - ibit)); + *ints[o] = *ints[o] | + ((buf[i] & ((1ULL << ibit) - 1)) << (bits[o] - ibit)); bits[o] -= ibit; ibit = 8; i++; @@ -230,10 +229,8 @@ fp_buftofp(const unsigned char *buf, int negative = !!(value & (1ULL << (intbits + fltbits - 1))); if (negative) value = (~value + 1) & ((1ULL << (intbits + fltbits - 1)) - 1); - struct fp_number result = { - .integer = { value >> fltbits, intbits }, - .fraction = { value & ((1ULL << fltbits) - 1), fltbits, precision } - }; + struct fp_number result = { .integer = { value >> fltbits, intbits }, + .fraction = { value & ((1ULL << fltbits) - 1), fltbits, precision } }; if (negative) result.integer.value = -result.integer.value; return result; diff --git a/src/lib/fixedpoint.h b/src/lib/fixedpoint.h index cc076439..8b4216c0 100644 --- a/src/lib/fixedpoint.h +++ b/src/lib/fixedpoint.h @@ -19,8 +19,8 @@ # include #endif -#if ! defined FIXEDPOINT_H && defined ENABLE_LLDPMED -#define FIXEDPOINT_H +#if !defined FIXEDPOINT_H && defined ENABLE_LLDPMED +# define FIXEDPOINT_H struct fp_number { struct { @@ -37,6 +37,6 @@ struct fp_number fp_strtofp(const char *, char **, unsigned, unsigned); struct fp_number fp_buftofp(const unsigned char *, unsigned, unsigned, unsigned); struct fp_number fp_negate(struct fp_number); char *fp_fptostr(struct fp_number, const char *); -void fp_fptobuf(struct fp_number, unsigned char *, unsigned); +void fp_fptobuf(struct fp_number, unsigned char *, unsigned); #endif diff --git a/src/lib/helpers.c b/src/lib/helpers.c index 2fa0f78a..973f8f46 100644 --- a/src/lib/helpers.c +++ b/src/lib/helpers.c @@ -25,7 +25,7 @@ #include "atom.h" #include "helpers.h" -const char* +const char * map_lookup(lldpctl_map_t *list, int n) { @@ -46,8 +46,7 @@ map_reverse_lookup(lldpctl_map_t *list, const char *string) if (!string) return -1; for (unsigned int i = 0; list[i].string != NULL; i++) { - if (!strcasecmp(list[i].string, string)) - return list[i].value; + if (!strcasecmp(list[i].string, string)) return list[i].value; } return -1; @@ -71,10 +70,9 @@ _lldpctl_atom_free_any_list(lldpctl_atom_t *atom) lldpctl_atom_dec_ref((lldpctl_atom_t *)plist->parent); } -char* +char * xstrdup(const char *str) { if (!str) return NULL; return strdup(str); } - diff --git a/src/lib/helpers.h b/src/lib/helpers.h index 8d63ec56..6f7ae0bd 100644 --- a/src/lib/helpers.h +++ b/src/lib/helpers.h @@ -22,4 +22,3 @@ int _lldpctl_atom_new_any_list(lldpctl_atom_t *atom, va_list ap); void _lldpctl_atom_free_any_list(lldpctl_atom_t *atom); char *xstrdup(const char *); - diff --git a/src/lib/lldpctl.h b/src/lib/lldpctl.h index 3b8fa328..f1cb1d04 100644 --- a/src/lib/lldpctl.h +++ b/src/lib/lldpctl.h @@ -57,7 +57,6 @@ * @{ */ - #ifdef __cplusplus extern "C" { #endif @@ -93,7 +92,7 @@ extern "C" { * * Currently, this is the default location of the Unix socket. */ -const char* lldpctl_get_default_transport(void); +const char *lldpctl_get_default_transport(void); /** * Structure referencing a connection with lldpd. @@ -115,8 +114,8 @@ typedef struct lldpctl_conn_t lldpctl_conn_t; * if no bytes can be sent without blocking or @c * LLDPCTL_ERR_CALLBACK_FAILURE for other errors. */ -typedef ssize_t (*lldpctl_send_callback)(lldpctl_conn_t *conn, - const uint8_t *data, size_t length, void *user_data); +typedef ssize_t (*lldpctl_send_callback)(lldpctl_conn_t *conn, const uint8_t *data, + size_t length, void *user_data); /** * Callback function invoked to receive data from lldpd. @@ -130,8 +129,8 @@ typedef ssize_t (*lldpctl_send_callback)(lldpctl_conn_t *conn, * @c LLDPCTL_ERR_CALLBACK_FAILURE for other errors or @c * LLDPCTL_ERR_EOF if end of file was reached. */ -typedef ssize_t (*lldpctl_recv_callback)(lldpctl_conn_t *conn, - const uint8_t *data, size_t length, void *user_data); +typedef ssize_t (*lldpctl_recv_callback)(lldpctl_conn_t *conn, const uint8_t *data, + size_t length, void *user_data); /** * Function invoked when additional data is available from lldpd. @@ -172,7 +171,6 @@ ssize_t lldpctl_send(lldpctl_conn_t *conn); */ int lldpctl_process_conn_buffer(lldpctl_conn_t *conn); - /** * Allocate a new handler for connecting to lldpd. * @@ -187,8 +185,8 @@ int lldpctl_process_conn_buffer(lldpctl_conn_t *conn); * provided parameters are both @c NULL, default synchronous callbacks will be * used. */ -lldpctl_conn_t *lldpctl_new(lldpctl_send_callback send, - lldpctl_recv_callback recv, void *user_data); +lldpctl_conn_t *lldpctl_new(lldpctl_send_callback send, lldpctl_recv_callback recv, + void *user_data); /** * Allocate a new handler for connecting to lldpd. @@ -301,24 +299,24 @@ typedef enum { /** * An error occurred during serialization of message. */ - LLDPCTL_ERR_SERIALIZATION = -506, + LLDPCTL_ERR_SERIALIZATION = -506, /** * The requested operation cannot be performed because we have another * operation already running. */ - LLDPCTL_ERR_INVALID_STATE = -507, + LLDPCTL_ERR_INVALID_STATE = -507, /** * The provided atom cannot be iterated. */ - LLDPCTL_ERR_CANNOT_ITERATE = -508, + LLDPCTL_ERR_CANNOT_ITERATE = -508, /** * The provided value is invalid. */ - LLDPCTL_ERR_BAD_VALUE = -509, + LLDPCTL_ERR_BAD_VALUE = -509, /** * No new element can be created for this element. */ - LLDPCTL_ERR_CANNOT_CREATE = -510, + LLDPCTL_ERR_CANNOT_CREATE = -510, /** * The library is under unexpected conditions and cannot process * any further data reliably. @@ -414,7 +412,7 @@ typedef struct lldpctl_atom_t lldpctl_atom_t; * @see lldpctl_key_get_map(). */ typedef const struct { - int value; + int value; char *string; } lldpctl_map_t; @@ -452,9 +450,9 @@ void lldpctl_atom_dec_ref(lldpctl_atom_t *atom); * @see lldpctl_watch_callback2 */ typedef enum { - lldpctl_c_deleted, /**< The neighbor has been deleted */ - lldpctl_c_updated, /**< The neighbor has been updated */ - lldpctl_c_added, /**< This is a new neighbor */ + lldpctl_c_deleted, /**< The neighbor has been deleted */ + lldpctl_c_updated, /**< The neighbor has been updated */ + lldpctl_c_added, /**< This is a new neighbor */ } lldpctl_change_t; /** @@ -476,11 +474,8 @@ typedef enum { * * @see lldpctl_watch_callback */ -typedef void (*lldpctl_change_callback)(lldpctl_conn_t *conn, - lldpctl_change_t type, - lldpctl_atom_t *interface, - lldpctl_atom_t *neighbor, - void *data); +typedef void (*lldpctl_change_callback)(lldpctl_conn_t *conn, lldpctl_change_t type, + lldpctl_atom_t *interface, lldpctl_atom_t *neighbor, void *data); /** * Callback function invoked when a change is detected. @@ -497,9 +492,7 @@ typedef void (*lldpctl_change_callback)(lldpctl_conn_t *conn, * @see lldpctl_watch_callback2 */ typedef void (*lldpctl_change_callback2)(lldpctl_change_t type, - lldpctl_atom_t *interface, - lldpctl_atom_t *neighbor, - void *data); + lldpctl_atom_t *interface, lldpctl_atom_t *neighbor, void *data); /** * Register a callback to be called on changes. @@ -520,9 +513,8 @@ typedef void (*lldpctl_change_callback2)(lldpctl_change_t type, * @deprecated This function is deprecated and lldpctl_watch_callback2 should be * used instead. */ -int lldpctl_watch_callback(lldpctl_conn_t *conn, - lldpctl_change_callback cb, - void *data) __attribute__ ((deprecated)); +int lldpctl_watch_callback(lldpctl_conn_t *conn, lldpctl_change_callback cb, void *data) + __attribute__((deprecated)); /** * Register a callback to be called on changes. @@ -540,8 +532,7 @@ int lldpctl_watch_callback(lldpctl_conn_t *conn, * anything else than receiving notifications. If you do, you will get a @c * LLDPCTL_ERR_INVALID_STATE error. */ -int lldpctl_watch_callback2(lldpctl_conn_t *conn, - lldpctl_change_callback2 cb, +int lldpctl_watch_callback2(lldpctl_conn_t *conn, lldpctl_change_callback2 cb, void *data); /** @@ -698,174 +689,233 @@ lldpctl_atom_t *lldpctl_get_default_port(lldpctl_conn_t *conn); * indirection, i.e first write to a (A,W), then to a (A,WO)). */ typedef enum { - lldpctl_k_config_tx_interval, /**< `(I,WO)` Transmit interval. When set to -1, it is meant to transmit now. */ - lldpctl_k_config_receiveonly, /**< `(I)` Receive only mode */ - lldpctl_k_config_mgmt_pattern, /**< `(S,WON)` Pattern to choose the management address */ + lldpctl_k_config_tx_interval, /**< `(I,WO)` Transmit interval. When set to -1, + it is meant to transmit now. */ + lldpctl_k_config_receiveonly, /**< `(I)` Receive only mode */ + lldpctl_k_config_mgmt_pattern, /**< `(S,WON)` Pattern to choose the management + address */ lldpctl_k_config_iface_pattern, /**< `(S,WON)` Pattern of enabled interfaces */ - lldpctl_k_config_cid_pattern, /**< `(S)` Interface pattern to choose the chassis ID */ - lldpctl_k_config_description, /**< `(S,WON)` Chassis description overridden */ - lldpctl_k_config_platform, /**< `(S,WON)` Platform description overridden (CDP) */ - lldpctl_k_config_hostname, /**< `(S,WON)` System name overridden */ - lldpctl_k_config_advertise_version, /**< `(I)` Advertise version */ + lldpctl_k_config_cid_pattern, /**< `(S)` Interface pattern to choose the chassis + ID */ + lldpctl_k_config_description, /**< `(S,WON)` Chassis description overridden */ + lldpctl_k_config_platform, /**< `(S,WON)` Platform description overridden (CDP) + */ + lldpctl_k_config_hostname, /**< `(S,WON)` System name overridden */ + lldpctl_k_config_advertise_version, /**< `(I)` Advertise version */ lldpctl_k_config_lldpmed_noinventory, /**< `(I)` Disable LLDP-MED inventory */ lldpctl_k_config_paused, /**< `(I,WO)` lldpd is paused */ - lldpctl_k_config_fast_start_enabled, /**< `(I,WO)` Is fast start enabled */ - lldpctl_k_config_fast_start_interval, /**< `(I,WO)` Start fast transmit interval */ - lldpctl_k_config_ifdescr_update, /**< `(I,WO)` Enable or disable setting interface description */ - lldpctl_k_config_iface_promisc, /**< `(I,WO)` Enable or disable promiscuous mode on interfaces */ - lldpctl_k_config_chassis_cap_advertise, /**< `(I,WO)` Enable or disable chassis capabilities advertisement */ - lldpctl_k_config_chassis_mgmt_advertise, /**< `(I,WO)` Enable or disable management addresses advertisement */ - lldpctl_k_config_cid_string, /**< `(S,WON)` User defined string for the chassis ID */ - lldpctl_k_config_perm_iface_pattern, /**< `(S,WON)` Pattern of permanent interfaces */ - lldpctl_k_config_tx_interval_ms, /**< `(I,WO)` Transmit interval in milliseconds. Set to -1 to transmit now. */ - lldpctl_k_config_chassis_cap_override, /**< `(I,WO)` Override chassis capabilities */ + lldpctl_k_config_fast_start_enabled, /**< `(I,WO)` Is fast start enabled */ + lldpctl_k_config_fast_start_interval, /**< `(I,WO)` Start fast transmit interval + */ + lldpctl_k_config_ifdescr_update, /**< `(I,WO)` Enable or disable setting + interface description */ + lldpctl_k_config_iface_promisc, /**< `(I,WO)` Enable or disable promiscuous mode + on interfaces */ + lldpctl_k_config_chassis_cap_advertise, /**< `(I,WO)` Enable or disable chassis + capabilities advertisement */ + lldpctl_k_config_chassis_mgmt_advertise, /**< `(I,WO)` Enable or disable + management addresses advertisement + */ + lldpctl_k_config_cid_string, /**< `(S,WON)` User defined string for the chassis + ID */ + lldpctl_k_config_perm_iface_pattern, /**< `(S,WON)` Pattern of permanent + interfaces */ + lldpctl_k_config_tx_interval_ms, /**< `(I,WO)` Transmit interval in + milliseconds. Set to -1 to transmit now. */ + lldpctl_k_config_chassis_cap_override, /**< `(I,WO)` Override chassis + capabilities */ lldpctl_k_interface_name = 1000, /**< `(S)` The interface name. */ - lldpctl_k_port_name = 1100, /**< `(S)` The port name. Only works for a local port. */ - lldpctl_k_port_index, /**< `(I)` The port index. Only works for a local port. */ + lldpctl_k_port_name = + 1100, /**< `(S)` The port name. Only works for a local port. */ + lldpctl_k_port_index, /**< `(I)` The port index. Only works for a local port. */ /** * `(AL)` The list of known neighbors for this port. * * A neighbor is in fact a remote port. */ lldpctl_k_port_neighbors = 1200, - lldpctl_k_port_protocol, /**< `(IS)` The protocol that was used to retrieve this information. */ - lldpctl_k_port_age, /**< `(I)` Age of information, seconds from epoch. */ + lldpctl_k_port_protocol, /**< `(IS)` The protocol that was used to retrieve this + information. */ + lldpctl_k_port_age, /**< `(I)` Age of information, seconds from epoch. */ lldpctl_k_port_id_subtype, /**< `(IS)` The subtype ID of this port. */ lldpctl_k_port_id, /**< `(BS,WO)` The ID of this port. */ lldpctl_k_port_descr, /**< `(S,WO)` The description of this port. */ - lldpctl_k_port_hidden, /**< `(I)` Is this port hidden (or should it be displayed?)? */ - lldpctl_k_port_status, /**< `(IS,WO)` Operational status of this (local) port */ - lldpctl_k_port_chassis, /**< `(A)` Chassis associated to the port */ - lldpctl_k_port_ttl, /**< `(I)` TTL for port, 0 if info is attached to chassis */ - lldpctl_k_port_vlan_tx, /**< `(I,W)` VLAN tag for TX on port, -1 VLAN disabled */ - - lldpctl_k_port_dot3_mfs = 1300, /**< `(I)` MFS */ - lldpctl_k_port_dot3_aggregid, /**< `(I)` Port aggregation ID */ - lldpctl_k_port_dot3_autoneg_support, /**< `(I)` Autonegotiation support. */ - lldpctl_k_port_dot3_autoneg_enabled, /**< `(I)` Autonegotiation enabled. */ - lldpctl_k_port_dot3_autoneg_advertised, /**< `(I)` Advertised protocols. See `LLDP_DOT3_LINK_AUTONEG_*` */ - lldpctl_k_port_dot3_mautype, /**< `(IS)` Current MAU type. See `LLDP_DOT3_MAU_*` */ + lldpctl_k_port_hidden, /**< `(I)` Is this port hidden (or should it be + displayed?)? */ + lldpctl_k_port_status, /**< `(IS,WO)` Operational status of this (local) port */ + lldpctl_k_port_chassis, /**< `(A)` Chassis associated to the port */ + lldpctl_k_port_ttl, /**< `(I)` TTL for port, 0 if info is attached to chassis */ + lldpctl_k_port_vlan_tx, /**< `(I,W)` VLAN tag for TX on port, -1 VLAN disabled + */ + + lldpctl_k_port_dot3_mfs = 1300, /**< `(I)` MFS */ + lldpctl_k_port_dot3_aggregid, /**< `(I)` Port aggregation ID */ + lldpctl_k_port_dot3_autoneg_support, /**< `(I)` Autonegotiation support. */ + lldpctl_k_port_dot3_autoneg_enabled, /**< `(I)` Autonegotiation enabled. */ + lldpctl_k_port_dot3_autoneg_advertised, /**< `(I)` Advertised protocols. See + `LLDP_DOT3_LINK_AUTONEG_*` */ + lldpctl_k_port_dot3_mautype, /**< `(IS)` Current MAU type. See `LLDP_DOT3_MAU_*` + */ lldpctl_k_port_dot3_power = 1400, /**< `(A,WO)` Dot3 power related stuff. */ - lldpctl_k_dot3_power_devicetype, /**< `(IS,W)` Device type. See `LLDP_DOT3_POWER_PSE/PD` */ - lldpctl_k_dot3_power_supported, /**< `(I,W)` Is MDI power supported. */ - lldpctl_k_dot3_power_enabled, /**< `(I,W)` Is MDI power enabled. */ + lldpctl_k_dot3_power_devicetype, /**< `(IS,W)` Device type. See + `LLDP_DOT3_POWER_PSE/PD` */ + lldpctl_k_dot3_power_supported, /**< `(I,W)` Is MDI power supported. */ + lldpctl_k_dot3_power_enabled, /**< `(I,W)` Is MDI power enabled. */ lldpctl_k_dot3_power_paircontrol, /**< `(I,W)` Pair-control enabled? */ - lldpctl_k_dot3_power_pairs, /**< `(IS,W)` See `LLDP_DOT3_POWERPAIRS_*` */ - lldpctl_k_dot3_power_class, /**< `(IS,W)` Power class. */ - lldpctl_k_dot3_power_type, /**< `(I,W)` 802.3AT power type */ - lldpctl_k_dot3_power_source, /**< `(IS,W)` 802.3AT power source */ - lldpctl_k_dot3_power_priority, /**< `(IS,W)` 802.3AT power priority */ - lldpctl_k_dot3_power_allocated, /**< `(I,W)` 802.3AT power allocated */ - lldpctl_k_dot3_power_requested, /**< `(I,W)` 802.3AT power requested */ + lldpctl_k_dot3_power_pairs, /**< `(IS,W)` See `LLDP_DOT3_POWERPAIRS_*` */ + lldpctl_k_dot3_power_class, /**< `(IS,W)` Power class. */ + lldpctl_k_dot3_power_type, /**< `(I,W)` 802.3AT power type */ + lldpctl_k_dot3_power_source, /**< `(IS,W)` 802.3AT power source */ + lldpctl_k_dot3_power_priority, /**< `(IS,W)` 802.3AT power priority */ + lldpctl_k_dot3_power_allocated, /**< `(I,W)` 802.3AT power allocated */ + lldpctl_k_dot3_power_requested, /**< `(I,W)` 802.3AT power requested */ /* 802.3bt additions */ - lldpctl_k_dot3_power_pd_4pid, /**< `(IS,W)` 802.3BT both modes supported? */ - lldpctl_k_dot3_power_requested_a, /**< `(I,W)` 802.3BT power value requested for A */ - lldpctl_k_dot3_power_requested_b, /**< `(I,W)` 802.3BT power value requested for B */ - lldpctl_k_dot3_power_allocated_a, /**< `(I,W)` 802.3BT power value allocated for A */ - lldpctl_k_dot3_power_allocated_b, /**< `(I,W)` 802.3BT power value allocated for B */ - lldpctl_k_dot3_power_pse_status, /**< `(IS,W)` 802.3BT PSE powering status */ - lldpctl_k_dot3_power_pd_status, /**< `(IS,W)` 802.3BT PD powering status */ + lldpctl_k_dot3_power_pd_4pid, /**< `(IS,W)` 802.3BT both modes supported? */ + lldpctl_k_dot3_power_requested_a, /**< `(I,W)` 802.3BT power value requested for + A */ + lldpctl_k_dot3_power_requested_b, /**< `(I,W)` 802.3BT power value requested for + B */ + lldpctl_k_dot3_power_allocated_a, /**< `(I,W)` 802.3BT power value allocated for + A */ + lldpctl_k_dot3_power_allocated_b, /**< `(I,W)` 802.3BT power value allocated for + B */ + lldpctl_k_dot3_power_pse_status, /**< `(IS,W)` 802.3BT PSE powering status */ + lldpctl_k_dot3_power_pd_status, /**< `(IS,W)` 802.3BT PD powering status */ lldpctl_k_dot3_power_pse_pairs_ext, /**< `(IS,W)` 802.3BT PSE power pairs */ - lldpctl_k_dot3_power_class_a, /**< `(IS,W)` 802.3BT power class for A */ - lldpctl_k_dot3_power_class_b, /**< `(IS,W)` 802.3BT power class for B */ - lldpctl_k_dot3_power_class_ext, /**< `(IS,W)` 802.3BT power class */ - lldpctl_k_dot3_power_type_ext, /**< `(IS,W)` 802.3BT power type */ - lldpctl_k_dot3_power_pd_load, /**< `(IS,W)` 802.3BT dualsig isolated? */ + lldpctl_k_dot3_power_class_a, /**< `(IS,W)` 802.3BT power class for A */ + lldpctl_k_dot3_power_class_b, /**< `(IS,W)` 802.3BT power class for B */ + lldpctl_k_dot3_power_class_ext, /**< `(IS,W)` 802.3BT power class */ + lldpctl_k_dot3_power_type_ext, /**< `(IS,W)` 802.3BT power type */ + lldpctl_k_dot3_power_pd_load, /**< `(IS,W)` 802.3BT dualsig isolated? */ lldpctl_k_dot3_power_pse_max, /**< `(I,W)` 802.3BT maximum available power */ lldpctl_k_port_vlan_pvid = 1500, /**< `(I)` Primary VLAN ID */ - lldpctl_k_port_vlans, /**< `(AL)` List of VLAN */ - lldpctl_k_vlan_id, /**< `(I)` VLAN ID */ - lldpctl_k_vlan_name, /**< `(S)` VLAN name */ + lldpctl_k_port_vlans, /**< `(AL)` List of VLAN */ + lldpctl_k_vlan_id, /**< `(I)` VLAN ID */ + lldpctl_k_vlan_name, /**< `(S)` VLAN name */ lldpctl_k_port_ppvids = 1600, /**< `(AL)` List of PPVIDs */ lldpctl_k_ppvid_status, /**< `(I)` Status of PPVID (see `LLDP_PPVID_CAP_*`) */ - lldpctl_k_ppvid_id, /**< `(I)` ID of PPVID */ + lldpctl_k_ppvid_id, /**< `(I)` ID of PPVID */ lldpctl_k_port_pis = 1700, /**< `(AL)` List of PIDs */ - lldpctl_k_pi_id, /**< `(B)` PID value */ - - lldpctl_k_chassis_index = 1800, /**< `(I)` The chassis index. */ - lldpctl_k_chassis_id_subtype, /**< `(IS)` The subtype ID of this chassis. */ - lldpctl_k_chassis_id, /**< `(BS)` The ID of this chassis. */ - lldpctl_k_chassis_name, /**< `(S)` The name of this chassis. */ - lldpctl_k_chassis_descr, /**< `(S)` The description of this chassis. */ - lldpctl_k_chassis_cap_available, /**< `(I)` Available capabilities (see `LLDP_CAP_*`) */ - lldpctl_k_chassis_cap_enabled, /**< `(I)` Enabled capabilities (see `LLDP_CAP_*`) */ + lldpctl_k_pi_id, /**< `(B)` PID value */ + + lldpctl_k_chassis_index = 1800, /**< `(I)` The chassis index. */ + lldpctl_k_chassis_id_subtype, /**< `(IS)` The subtype ID of this chassis. */ + lldpctl_k_chassis_id, /**< `(BS)` The ID of this chassis. */ + lldpctl_k_chassis_name, /**< `(S)` The name of this chassis. */ + lldpctl_k_chassis_descr, /**< `(S)` The description of this chassis. */ + lldpctl_k_chassis_cap_available, /**< `(I)` Available capabilities (see + `LLDP_CAP_*`) */ + lldpctl_k_chassis_cap_enabled, /**< `(I)` Enabled capabilities (see + `LLDP_CAP_*`) */ lldpctl_k_chassis_mgmt, /**< `(AL)` List of management addresses */ lldpctl_k_chassis_ttl, /**< Deprecated */ - lldpctl_k_chassis_med_type = 1900, /**< `(IS)` Chassis MED type. See `LLDP_MED_CLASS_*` */ - lldpctl_k_chassis_med_cap, /**< `(I)` Available MED capabilities. See `LLDP_MED_CAP_*` */ - lldpctl_k_chassis_med_inventory_hw, /**< `(S,W)` LLDP MED inventory "Hardware Revision" */ - lldpctl_k_chassis_med_inventory_sw, /**< `(S,W)` LLDP MED inventory "Software Revision" */ - lldpctl_k_chassis_med_inventory_fw, /**< `(S,W)` LLDP MED inventory "Firmware Revision" */ - lldpctl_k_chassis_med_inventory_sn, /**< `(S,W)` LLDP MED inventory "Serial Number" */ - lldpctl_k_chassis_med_inventory_manuf, /**< `(S,W)` LLDP MED inventory "Manufacturer" */ - lldpctl_k_chassis_med_inventory_model, /**< `(S,W)` LLDP MED inventory "Model" */ - lldpctl_k_chassis_med_inventory_asset, /**< `(S,W)` LLDP MED inventory "Asset ID" */ - - lldpctl_k_port_med_policies = 2000, /**< `(AL,WO)` MED policies attached to a port. */ - lldpctl_k_med_policy_type, /**< `(IS,W)` MED policy app type. See `LLDP_MED_APPTYPE_*`. 0 if a policy is not defined. */ + lldpctl_k_chassis_med_type = + 1900, /**< `(IS)` Chassis MED type. See `LLDP_MED_CLASS_*` */ + lldpctl_k_chassis_med_cap, /**< `(I)` Available MED capabilities. See + `LLDP_MED_CAP_*` */ + lldpctl_k_chassis_med_inventory_hw, /**< `(S,W)` LLDP MED inventory "Hardware + Revision" */ + lldpctl_k_chassis_med_inventory_sw, /**< `(S,W)` LLDP MED inventory "Software + Revision" */ + lldpctl_k_chassis_med_inventory_fw, /**< `(S,W)` LLDP MED inventory "Firmware + Revision" */ + lldpctl_k_chassis_med_inventory_sn, /**< `(S,W)` LLDP MED inventory "Serial + Number" */ + lldpctl_k_chassis_med_inventory_manuf, /**< `(S,W)` LLDP MED inventory + "Manufacturer" */ + lldpctl_k_chassis_med_inventory_model, /**< `(S,W)` LLDP MED inventory "Model" + */ + lldpctl_k_chassis_med_inventory_asset, /**< `(S,W)` LLDP MED inventory "Asset + ID" */ + + lldpctl_k_port_med_policies = + 2000, /**< `(AL,WO)` MED policies attached to a port. */ + lldpctl_k_med_policy_type, /**< `(IS,W)` MED policy app type. See + `LLDP_MED_APPTYPE_*`. 0 if a policy is not + defined. */ lldpctl_k_med_policy_unknown, /**< `(I,W)` Is MED policy defined? */ - lldpctl_k_med_policy_tagged, /**< `(I,W)` MED policy tagging */ - lldpctl_k_med_policy_vid, /**< `(I,W)` MED policy VID */ + lldpctl_k_med_policy_tagged, /**< `(I,W)` MED policy tagging */ + lldpctl_k_med_policy_vid, /**< `(I,W)` MED policy VID */ lldpctl_k_med_policy_priority, /**< `(I,W)` MED policy priority */ lldpctl_k_med_policy_dscp, /**< `(I,W)` MED policy DSCP */ - lldpctl_k_port_med_locations = 2100, /**< `(AL,WO)` MED locations attached to a port. */ - lldpctl_k_med_location_format, /**< `(IS,W)` MED location format. See - * `LLDP_MED_LOCFORMAT_*`. 0 if this - * location is not defined. When written, - * the following fields will be zeroed - * out. */ - lldpctl_k_med_location_geoid, /**< `(IS,W)` MED geoid. See `LLDP_MED_LOCATION_GEOID_*`. Only if format is COORD. */ - lldpctl_k_med_location_latitude, /**< `(S,W)` MED latitude. Only if format is COORD. */ - lldpctl_k_med_location_longitude, /**< `(S,W)` MED longitude. Only if format is COORD. */ - lldpctl_k_med_location_altitude, /**< `(S,W)` MED altitude. Only if format is COORD. */ - lldpctl_k_med_location_altitude_unit, /**< `(S,W)` MED altitude unit. See `LLDP_MED_LOCATION_ALTITUDE_UNIT_*`. + lldpctl_k_port_med_locations = + 2100, /**< `(AL,WO)` MED locations attached to a port. */ + lldpctl_k_med_location_format, /**< `(IS,W)` MED location format. See + * `LLDP_MED_LOCFORMAT_*`. 0 if this + * location is not defined. When written, + * the following fields will be zeroed + * out. */ + lldpctl_k_med_location_geoid, /**< `(IS,W)` MED geoid. See + `LLDP_MED_LOCATION_GEOID_*`. Only if format is + COORD. */ + lldpctl_k_med_location_latitude, /**< `(S,W)` MED latitude. Only if format is + COORD. */ + lldpctl_k_med_location_longitude, /**< `(S,W)` MED longitude. Only if format is + COORD. */ + lldpctl_k_med_location_altitude, /**< `(S,W)` MED altitude. Only if format is + COORD. */ + lldpctl_k_med_location_altitude_unit, /**< `(S,W)` MED altitude unit. See + * `LLDP_MED_LOCATION_ALTITUDE_UNIT_*`. * Only if format is COORD. */ - lldpctl_k_med_location_country = 2200, /**< `(S,W)` MED country. Only if format is CIVIC. */ + lldpctl_k_med_location_country = + 2200, /**< `(S,W)` MED country. Only if format is CIVIC. */ lldpctl_k_med_location_elin, /**< `(S,W)` MED ELIN. Only if format is ELIN. */ - lldpctl_k_med_location_ca_elements = 2300, /**< `(AL,WC)` MED civic address elements. Only if format is CIVIC */ - lldpctl_k_med_civicaddress_type, /**< `(IS,W)` MED civic address type. */ + lldpctl_k_med_location_ca_elements = + 2300, /**< `(AL,WC)` MED civic address elements. Only if format is CIVIC */ + lldpctl_k_med_civicaddress_type, /**< `(IS,W)` MED civic address type. */ lldpctl_k_med_civicaddress_value, /**< `(S,W)` MED civic address value. */ lldpctl_k_port_med_power = 2400, /**< `(A,WO)` LLDP-MED power related stuff. */ - lldpctl_k_med_power_type, /**< `(IS,W)` LLDP MED power device type. See `LLDP_MED_POW_TYPE_*` */ - lldpctl_k_med_power_source, /**< `(IS,W)` LLDP MED power source. See `LLDP_MED_POW_SOURCE_*` */ - lldpctl_k_med_power_priority, /**< `(IS,W)` LLDP MED power priority. See `LLDP_MED_POW_PRIO_*` */ - 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. */ - lldpctl_k_rx_discarded_cnt, /**< `(I)` discarded cnt. Only works for a local port. */ - lldpctl_k_rx_unrecognized_cnt, /**< `(I)` unrecognized cnt. Only works for a local port. */ - lldpctl_k_ageout_cnt, /**< `(I)` ageout cnt. Only works for a local port. */ - lldpctl_k_insert_cnt, /**< `(I)` insert cnt. Only works for a local port. */ - lldpctl_k_delete_cnt, /**< `(I)` delete cnt. Only works for a local port. */ + lldpctl_k_med_power_type, /**< `(IS,W)` LLDP MED power device type. See + `LLDP_MED_POW_TYPE_*` */ + lldpctl_k_med_power_source, /**< `(IS,W)` LLDP MED power source. See + `LLDP_MED_POW_SOURCE_*` */ + lldpctl_k_med_power_priority, /**< `(IS,W)` LLDP MED power priority. See + `LLDP_MED_POW_PRIO_*` */ + 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. */ + lldpctl_k_rx_discarded_cnt, /**< `(I)` discarded cnt. Only works for a local + port. */ + lldpctl_k_rx_unrecognized_cnt, /**< `(I)` unrecognized cnt. Only works for a + local port. */ + lldpctl_k_ageout_cnt, /**< `(I)` ageout cnt. Only works for a local port. */ + lldpctl_k_insert_cnt, /**< `(I)` insert cnt. Only works for a local port. */ + lldpctl_k_delete_cnt, /**< `(I)` delete cnt. Only works for a local port. */ lldpctl_k_config_tx_hold, /**< `(I,WO)` Transmit hold interval. */ - lldpctl_k_config_bond_slave_src_mac_type, /**< `(I,WO)` bond slave src mac type. */ + lldpctl_k_config_bond_slave_src_mac_type, /**< `(I,WO)` bond slave src mac type. + */ lldpctl_k_config_lldp_portid_type, /**< `(I,WO)` LLDP PortID TLV Subtype */ - lldpctl_k_config_lldp_agent_type, /**< `(I,WO)` LLDP agent type */ - lldpctl_k_config_max_neighbors, /**< `(I,WO)`Maximum number of neighbors per port. */ - - lldpctl_k_custom_tlvs = 5000, /**< `(AL)` custom TLVs */ - lldpctl_k_custom_tlvs_clear, /**< `(WO)` clear list of custom TLVs */ - lldpctl_k_custom_tlv, /**< `(AL,WO)` custom TLV **/ - lldpctl_k_custom_tlv_oui, /**< `(B,W)` custom TLV Organizationally Unique Identifier. Default is 0 (3 bytes) */ - lldpctl_k_custom_tlv_oui_subtype, /**< `(I,W)` custom TLV subtype. Default is 0 (1 byte) */ - lldpctl_k_custom_tlv_oui_info_string, /**< `(BS,W)` custom TLV Organizationally Unique Identifier Information String (up to 507 bytes) */ - lldpctl_k_custom_tlv_op, /**< `(S,W)` custom TLV operation */ + lldpctl_k_config_lldp_agent_type, /**< `(I,WO)` LLDP agent type */ + lldpctl_k_config_max_neighbors, /**< `(I,WO)`Maximum number of neighbors per + port. */ + + lldpctl_k_custom_tlvs = 5000, /**< `(AL)` custom TLVs */ + lldpctl_k_custom_tlvs_clear, /**< `(WO)` clear list of custom TLVs */ + lldpctl_k_custom_tlv, /**< `(AL,WO)` custom TLV **/ + lldpctl_k_custom_tlv_oui, /**< `(B,W)` custom TLV Organizationally Unique + Identifier. Default is 0 (3 bytes) */ + lldpctl_k_custom_tlv_oui_subtype, /**< `(I,W)` custom TLV subtype. Default is 0 + (1 byte) */ + lldpctl_k_custom_tlv_oui_info_string, /**< `(BS,W)` custom TLV Organizationally + Unique Identifier Information String + (up to 507 bytes) */ + lldpctl_k_custom_tlv_op, /**< `(S,W)` custom TLV operation */ } lldpctl_key_t; @@ -1080,7 +1130,8 @@ lldpctl_atom_iter_t *lldpctl_atom_iter(lldpctl_atom_t *atom); * As a convenience, if the provided atom is @c NULL, this function will return * @c NULL and no error will be raised. */ -lldpctl_atom_iter_t *lldpctl_atom_iter_next(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter); +lldpctl_atom_iter_t *lldpctl_atom_iter_next(lldpctl_atom_t *atom, + lldpctl_atom_iter_t *iter); /** * Return the value of an iterator. @@ -1091,7 +1142,8 @@ lldpctl_atom_iter_t *lldpctl_atom_iter_next(lldpctl_atom_t *atom, lldpctl_atom_i * * @see lldpctl_atom_iter(), lldpctl_atom_iter_next(). */ -lldpctl_atom_t *lldpctl_atom_iter_value(lldpctl_atom_t *atom, lldpctl_atom_iter_t *iter); +lldpctl_atom_t *lldpctl_atom_iter_value(lldpctl_atom_t *atom, + lldpctl_atom_iter_t *iter); /** * Convenience macro to iter over every value of an iterable object. @@ -1103,11 +1155,11 @@ lldpctl_atom_t *lldpctl_atom_iter_value(lldpctl_atom_t *atom, lldpctl_atom_iter_ * reference count of the provided value is decremented. If you need to use it * outside of the loop, you need to increment it. */ -#define lldpctl_atom_foreach(atom, value) \ - for (lldpctl_atom_iter_t *iter##_LINE_ = lldpctl_atom_iter(atom); \ - iter##_LINE_ && (value = lldpctl_atom_iter_value(atom, iter##_LINE_)); \ - iter##_LINE_ = lldpctl_atom_iter_next(atom, iter##_LINE_), \ - lldpctl_atom_dec_ref(value)) +#define lldpctl_atom_foreach(atom, value) \ + for (lldpctl_atom_iter_t *iter##_LINE_ = lldpctl_atom_iter(atom); \ + iter##_LINE_ && (value = lldpctl_atom_iter_value(atom, iter##_LINE_)); \ + iter##_LINE_ = lldpctl_atom_iter_next(atom, iter##_LINE_), \ + lldpctl_atom_dec_ref(value)) /** * Create a new value for an iterable element. diff --git a/src/lldp-const.h b/src/lldp-const.h index 3c3b09ac..454424d0 100644 --- a/src/lldp-const.h +++ b/src/lldp-const.h @@ -23,329 +23,330 @@ * constants that are useful in the context of lldpd and its clients. */ -#define LLDP_TLV_ORG 127 -#define LLDP_TLV_ORG_OUI_LEN 3 -#define LLDP_TLV_ORG_OUI_INFO_MAXLEN 507 +#define LLDP_TLV_ORG 127 +#define LLDP_TLV_ORG_OUI_LEN 3 +#define LLDP_TLV_ORG_OUI_INFO_MAXLEN 507 /* Chassis ID subtype */ -#define LLDP_CHASSISID_SUBTYPE_CHASSIS 1 -#define LLDP_CHASSISID_SUBTYPE_IFALIAS 2 -#define LLDP_CHASSISID_SUBTYPE_PORT 3 -#define LLDP_CHASSISID_SUBTYPE_LLADDR 4 -#define LLDP_CHASSISID_SUBTYPE_ADDR 5 -#define LLDP_CHASSISID_SUBTYPE_IFNAME 6 -#define LLDP_CHASSISID_SUBTYPE_LOCAL 7 +#define LLDP_CHASSISID_SUBTYPE_CHASSIS 1 +#define LLDP_CHASSISID_SUBTYPE_IFALIAS 2 +#define LLDP_CHASSISID_SUBTYPE_PORT 3 +#define LLDP_CHASSISID_SUBTYPE_LLADDR 4 +#define LLDP_CHASSISID_SUBTYPE_ADDR 5 +#define LLDP_CHASSISID_SUBTYPE_IFNAME 6 +#define LLDP_CHASSISID_SUBTYPE_LOCAL 7 /* Port ID subtype */ -#define LLDP_PORTID_SUBTYPE_UNKNOWN 0 -#define LLDP_PORTID_SUBTYPE_IFALIAS 1 -#define LLDP_PORTID_SUBTYPE_PORT 2 -#define LLDP_PORTID_SUBTYPE_LLADDR 3 -#define LLDP_PORTID_SUBTYPE_ADDR 4 -#define LLDP_PORTID_SUBTYPE_IFNAME 5 -#define LLDP_PORTID_SUBTYPE_AGENTCID 6 -#define LLDP_PORTID_SUBTYPE_LOCAL 7 -#define LLDP_PORTID_SUBTYPE_MAX LLDP_PORTID_SUBTYPE_LOCAL +#define LLDP_PORTID_SUBTYPE_UNKNOWN 0 +#define LLDP_PORTID_SUBTYPE_IFALIAS 1 +#define LLDP_PORTID_SUBTYPE_PORT 2 +#define LLDP_PORTID_SUBTYPE_LLADDR 3 +#define LLDP_PORTID_SUBTYPE_ADDR 4 +#define LLDP_PORTID_SUBTYPE_IFNAME 5 +#define LLDP_PORTID_SUBTYPE_AGENTCID 6 +#define LLDP_PORTID_SUBTYPE_LOCAL 7 +#define LLDP_PORTID_SUBTYPE_MAX LLDP_PORTID_SUBTYPE_LOCAL -/* Operational MAU Type field. See: https://www.iana.org/assignments/ianamau-mib/ianamau-mib */ -#define LLDP_DOT3_MAU_AUI 1 -#define LLDP_DOT3_MAU_10BASE5 2 -#define LLDP_DOT3_MAU_FOIRL 3 -#define LLDP_DOT3_MAU_10BASE2 4 -#define LLDP_DOT3_MAU_10BASET 5 -#define LLDP_DOT3_MAU_10BASEFP 6 -#define LLDP_DOT3_MAU_10BASEFB 7 -#define LLDP_DOT3_MAU_10BASEFL 8 -#define LLDP_DOT3_MAU_10BROAD36 9 -#define LLDP_DOT3_MAU_10BASETHD 10 -#define LLDP_DOT3_MAU_10BASETFD 11 -#define LLDP_DOT3_MAU_10BASEFLHD 12 -#define LLDP_DOT3_MAU_10BASEFLFD 13 -#define LLDP_DOT3_MAU_100BASET4 14 -#define LLDP_DOT3_MAU_100BASETXHD 15 -#define LLDP_DOT3_MAU_100BASETXFD 16 -#define LLDP_DOT3_MAU_100BASEFXHD 17 -#define LLDP_DOT3_MAU_100BASEFXFD 18 -#define LLDP_DOT3_MAU_100BASET2HD 19 -#define LLDP_DOT3_MAU_100BASET2FD 20 -#define LLDP_DOT3_MAU_1000BASEXHD 21 -#define LLDP_DOT3_MAU_1000BASEXFD 22 -#define LLDP_DOT3_MAU_1000BASELXHD 23 -#define LLDP_DOT3_MAU_1000BASELXFD 24 -#define LLDP_DOT3_MAU_1000BASESXHD 25 -#define LLDP_DOT3_MAU_1000BASESXFD 26 -#define LLDP_DOT3_MAU_1000BASECXHD 27 -#define LLDP_DOT3_MAU_1000BASECXFD 28 -#define LLDP_DOT3_MAU_1000BASETHD 29 -#define LLDP_DOT3_MAU_1000BASETFD 30 -#define LLDP_DOT3_MAU_10GIGBASEX 31 -#define LLDP_DOT3_MAU_10GIGBASELX4 32 -#define LLDP_DOT3_MAU_10GIGBASER 33 -#define LLDP_DOT3_MAU_10GIGBASEER 34 -#define LLDP_DOT3_MAU_10GIGBASELR 35 -#define LLDP_DOT3_MAU_10GIGBASESR 36 -#define LLDP_DOT3_MAU_10GIGBASEW 37 -#define LLDP_DOT3_MAU_10GIGBASEEW 38 -#define LLDP_DOT3_MAU_10GIGBASELW 39 -#define LLDP_DOT3_MAU_10GIGBASESW 40 -#define LLDP_DOT3_MAU_10GIGBASECX4 41 -#define LLDP_DOT3_MAU_2BASETL 42 -#define LLDP_DOT3_MAU_10PASSTS 43 -#define LLDP_DOT3_MAU_100BASEBX10D 44 -#define LLDP_DOT3_MAU_100BASEBX10U 45 -#define LLDP_DOT3_MAU_100BASELX10 46 -#define LLDP_DOT3_MAU_1000BASEBX10D 47 -#define LLDP_DOT3_MAU_1000BASEBX10U 48 -#define LLDP_DOT3_MAU_1000BASELX10 49 -#define LLDP_DOT3_MAU_1000BASEPX10D 50 -#define LLDP_DOT3_MAU_1000BASEPX10U 51 -#define LLDP_DOT3_MAU_1000BASEPX20D 52 -#define LLDP_DOT3_MAU_1000BASEPX20U 53 -#define LLDP_DOT3_MAU_10GBASET 54 -#define LLDP_DOT3_MAU_10GBASELRM 55 -#define LLDP_DOT3_MAU_1000BASEKX 56 -#define LLDP_DOT3_MAU_10GBASEKX4 57 -#define LLDP_DOT3_MAU_10GBASEKR 58 -#define LLDP_DOT3_MAU_10G1GBASEPRXD1 59 -#define LLDP_DOT3_MAU_10G1GBASEPRXD2 60 -#define LLDP_DOT3_MAU_10G1GBASEPRXD3 61 -#define LLDP_DOT3_MAU_10G1GBASEPRXU1 62 -#define LLDP_DOT3_MAU_10G1GBASEPRXU2 63 -#define LLDP_DOT3_MAU_10G1GBASEPRXU3 64 -#define LLDP_DOT3_MAU_10GBASEPRD1 65 -#define LLDP_DOT3_MAU_10GBASEPRD2 66 -#define LLDP_DOT3_MAU_10GBASEPRD3 67 -#define LLDP_DOT3_MAU_10GBASEPRU1 68 -#define LLDP_DOT3_MAU_10GBASEPRU3 69 -#define LLDP_DOT3_MAU_40GBASEKR4 70 -#define LLDP_DOT3_MAU_40GBASECR4 71 -#define LLDP_DOT3_MAU_40GBASESR4 72 -#define LLDP_DOT3_MAU_40GBASEFR 73 -#define LLDP_DOT3_MAU_40GBASELR4 74 -#define LLDP_DOT3_MAU_100GBASECR10 75 -#define LLDP_DOT3_MAU_100GBASESR10 76 -#define LLDP_DOT3_MAU_100GBASELR4 77 -#define LLDP_DOT3_MAU_100GBASEER4 78 -#define LLDP_DOT3_MAU_1000BASET1 79 -#define LLDP_DOT3_MAU_1000BASEPX30D 80 -#define LLDP_DOT3_MAU_1000BASEPX30U 81 -#define LLDP_DOT3_MAU_1000BASEPX40D 82 -#define LLDP_DOT3_MAU_1000BASEPX40U 83 -#define LLDP_DOT3_MAU_10G1GBASEPRXD4 84 -#define LLDP_DOT3_MAU_10G1GBASEPRXU4 85 -#define LLDP_DOT3_MAU_10GBASEPRD4 86 -#define LLDP_DOT3_MAU_10GBASEPRU4 87 -#define LLDP_DOT3_MAU_25GBASECR 88 -#define LLDP_DOT3_MAU_25GBASECRS 89 -#define LLDP_DOT3_MAU_25GBASEKR 90 -#define LLDP_DOT3_MAU_25GBASEKRS 91 -#define LLDP_DOT3_MAU_25GBASER 92 -#define LLDP_DOT3_MAU_25GBASESR 93 -#define LLDP_DOT3_MAU_25GBASET 94 -#define LLDP_DOT3_MAU_40GBASEER4 95 -#define LLDP_DOT3_MAU_40GBASER 96 -#define LLDP_DOT3_MAU_40GBASET 97 -#define LLDP_DOT3_MAU_100GBASECR4 98 -#define LLDP_DOT3_MAU_100GBASEKR4 99 -#define LLDP_DOT3_MAU_100GBASEKP4 100 -#define LLDP_DOT3_MAU_100GBASER 101 -#define LLDP_DOT3_MAU_100GBASESR4 102 -#define LLDP_DOT3_MAU_2P5GIGT 103 -#define LLDP_DOT3_MAU_5GIGT 104 -#define LLDP_DOT3_MAU_100BASET1 105 -#define LLDP_DOT3_MAU_1000BASERHA 106 -#define LLDP_DOT3_MAU_1000BASERHB 107 -#define LLDP_DOT3_MAU_1000BASERHC 108 -#define LLDP_DOT3_MAU_2P5GBASEKX 109 -#define LLDP_DOT3_MAU_2P5GBASEX 110 -#define LLDP_DOT3_MAU_5GBASEKR 111 -#define LLDP_DOT3_MAU_5GBASER 112 -#define LLDP_DOT3_MAU_10GPASSXR 113 -#define LLDP_DOT3_MAU_25GBASELR 114 -#define LLDP_DOT3_MAU_25GBASEER 115 -#define LLDP_DOT3_MAU_50GBASER 116 -#define LLDP_DOT3_MAU_50GBASECR 117 -#define LLDP_DOT3_MAU_50GBASEKR 118 -#define LLDP_DOT3_MAU_50GBASESR 119 -#define LLDP_DOT3_MAU_50GBASEFR 120 -#define LLDP_DOT3_MAU_50GBASELR 121 -#define LLDP_DOT3_MAU_50GBASEER 122 -#define LLDP_DOT3_MAU_100GBASECR2 123 -#define LLDP_DOT3_MAU_100GBASEKR2 124 -#define LLDP_DOT3_MAU_100GBASESR2 125 -#define LLDP_DOT3_MAU_100GBASEDR 126 -#define LLDP_DOT3_MAU_200GBASER 127 -#define LLDP_DOT3_MAU_200GBASEDR4 128 -#define LLDP_DOT3_MAU_200GBASEFR4 129 -#define LLDP_DOT3_MAU_200GBASELR4 130 -#define LLDP_DOT3_MAU_200GBASECR4 131 -#define LLDP_DOT3_MAU_200GBASEKR4 132 -#define LLDP_DOT3_MAU_200GBASESR4 133 -#define LLDP_DOT3_MAU_200GBASEER4 134 -#define LLDP_DOT3_MAU_400GBASER 135 -#define LLDP_DOT3_MAU_400GBASESR16 136 -#define LLDP_DOT3_MAU_400GBASEDR4 137 -#define LLDP_DOT3_MAU_400GBASEFR8 138 -#define LLDP_DOT3_MAU_400GBASELR8 139 -#define LLDP_DOT3_MAU_400GBASEER8 140 -#define LLDP_DOT3_MAU_10BASET1L 141 -#define LLDP_DOT3_MAU_10BASET1SHD 142 -#define LLDP_DOT3_MAU_10BASET1SMD 143 -#define LLDP_DOT3_MAU_10BASET1SFD 144 +/* Operational MAU Type field. See: + * https://www.iana.org/assignments/ianamau-mib/ianamau-mib */ +#define LLDP_DOT3_MAU_AUI 1 +#define LLDP_DOT3_MAU_10BASE5 2 +#define LLDP_DOT3_MAU_FOIRL 3 +#define LLDP_DOT3_MAU_10BASE2 4 +#define LLDP_DOT3_MAU_10BASET 5 +#define LLDP_DOT3_MAU_10BASEFP 6 +#define LLDP_DOT3_MAU_10BASEFB 7 +#define LLDP_DOT3_MAU_10BASEFL 8 +#define LLDP_DOT3_MAU_10BROAD36 9 +#define LLDP_DOT3_MAU_10BASETHD 10 +#define LLDP_DOT3_MAU_10BASETFD 11 +#define LLDP_DOT3_MAU_10BASEFLHD 12 +#define LLDP_DOT3_MAU_10BASEFLFD 13 +#define LLDP_DOT3_MAU_100BASET4 14 +#define LLDP_DOT3_MAU_100BASETXHD 15 +#define LLDP_DOT3_MAU_100BASETXFD 16 +#define LLDP_DOT3_MAU_100BASEFXHD 17 +#define LLDP_DOT3_MAU_100BASEFXFD 18 +#define LLDP_DOT3_MAU_100BASET2HD 19 +#define LLDP_DOT3_MAU_100BASET2FD 20 +#define LLDP_DOT3_MAU_1000BASEXHD 21 +#define LLDP_DOT3_MAU_1000BASEXFD 22 +#define LLDP_DOT3_MAU_1000BASELXHD 23 +#define LLDP_DOT3_MAU_1000BASELXFD 24 +#define LLDP_DOT3_MAU_1000BASESXHD 25 +#define LLDP_DOT3_MAU_1000BASESXFD 26 +#define LLDP_DOT3_MAU_1000BASECXHD 27 +#define LLDP_DOT3_MAU_1000BASECXFD 28 +#define LLDP_DOT3_MAU_1000BASETHD 29 +#define LLDP_DOT3_MAU_1000BASETFD 30 +#define LLDP_DOT3_MAU_10GIGBASEX 31 +#define LLDP_DOT3_MAU_10GIGBASELX4 32 +#define LLDP_DOT3_MAU_10GIGBASER 33 +#define LLDP_DOT3_MAU_10GIGBASEER 34 +#define LLDP_DOT3_MAU_10GIGBASELR 35 +#define LLDP_DOT3_MAU_10GIGBASESR 36 +#define LLDP_DOT3_MAU_10GIGBASEW 37 +#define LLDP_DOT3_MAU_10GIGBASEEW 38 +#define LLDP_DOT3_MAU_10GIGBASELW 39 +#define LLDP_DOT3_MAU_10GIGBASESW 40 +#define LLDP_DOT3_MAU_10GIGBASECX4 41 +#define LLDP_DOT3_MAU_2BASETL 42 +#define LLDP_DOT3_MAU_10PASSTS 43 +#define LLDP_DOT3_MAU_100BASEBX10D 44 +#define LLDP_DOT3_MAU_100BASEBX10U 45 +#define LLDP_DOT3_MAU_100BASELX10 46 +#define LLDP_DOT3_MAU_1000BASEBX10D 47 +#define LLDP_DOT3_MAU_1000BASEBX10U 48 +#define LLDP_DOT3_MAU_1000BASELX10 49 +#define LLDP_DOT3_MAU_1000BASEPX10D 50 +#define LLDP_DOT3_MAU_1000BASEPX10U 51 +#define LLDP_DOT3_MAU_1000BASEPX20D 52 +#define LLDP_DOT3_MAU_1000BASEPX20U 53 +#define LLDP_DOT3_MAU_10GBASET 54 +#define LLDP_DOT3_MAU_10GBASELRM 55 +#define LLDP_DOT3_MAU_1000BASEKX 56 +#define LLDP_DOT3_MAU_10GBASEKX4 57 +#define LLDP_DOT3_MAU_10GBASEKR 58 +#define LLDP_DOT3_MAU_10G1GBASEPRXD1 59 +#define LLDP_DOT3_MAU_10G1GBASEPRXD2 60 +#define LLDP_DOT3_MAU_10G1GBASEPRXD3 61 +#define LLDP_DOT3_MAU_10G1GBASEPRXU1 62 +#define LLDP_DOT3_MAU_10G1GBASEPRXU2 63 +#define LLDP_DOT3_MAU_10G1GBASEPRXU3 64 +#define LLDP_DOT3_MAU_10GBASEPRD1 65 +#define LLDP_DOT3_MAU_10GBASEPRD2 66 +#define LLDP_DOT3_MAU_10GBASEPRD3 67 +#define LLDP_DOT3_MAU_10GBASEPRU1 68 +#define LLDP_DOT3_MAU_10GBASEPRU3 69 +#define LLDP_DOT3_MAU_40GBASEKR4 70 +#define LLDP_DOT3_MAU_40GBASECR4 71 +#define LLDP_DOT3_MAU_40GBASESR4 72 +#define LLDP_DOT3_MAU_40GBASEFR 73 +#define LLDP_DOT3_MAU_40GBASELR4 74 +#define LLDP_DOT3_MAU_100GBASECR10 75 +#define LLDP_DOT3_MAU_100GBASESR10 76 +#define LLDP_DOT3_MAU_100GBASELR4 77 +#define LLDP_DOT3_MAU_100GBASEER4 78 +#define LLDP_DOT3_MAU_1000BASET1 79 +#define LLDP_DOT3_MAU_1000BASEPX30D 80 +#define LLDP_DOT3_MAU_1000BASEPX30U 81 +#define LLDP_DOT3_MAU_1000BASEPX40D 82 +#define LLDP_DOT3_MAU_1000BASEPX40U 83 +#define LLDP_DOT3_MAU_10G1GBASEPRXD4 84 +#define LLDP_DOT3_MAU_10G1GBASEPRXU4 85 +#define LLDP_DOT3_MAU_10GBASEPRD4 86 +#define LLDP_DOT3_MAU_10GBASEPRU4 87 +#define LLDP_DOT3_MAU_25GBASECR 88 +#define LLDP_DOT3_MAU_25GBASECRS 89 +#define LLDP_DOT3_MAU_25GBASEKR 90 +#define LLDP_DOT3_MAU_25GBASEKRS 91 +#define LLDP_DOT3_MAU_25GBASER 92 +#define LLDP_DOT3_MAU_25GBASESR 93 +#define LLDP_DOT3_MAU_25GBASET 94 +#define LLDP_DOT3_MAU_40GBASEER4 95 +#define LLDP_DOT3_MAU_40GBASER 96 +#define LLDP_DOT3_MAU_40GBASET 97 +#define LLDP_DOT3_MAU_100GBASECR4 98 +#define LLDP_DOT3_MAU_100GBASEKR4 99 +#define LLDP_DOT3_MAU_100GBASEKP4 100 +#define LLDP_DOT3_MAU_100GBASER 101 +#define LLDP_DOT3_MAU_100GBASESR4 102 +#define LLDP_DOT3_MAU_2P5GIGT 103 +#define LLDP_DOT3_MAU_5GIGT 104 +#define LLDP_DOT3_MAU_100BASET1 105 +#define LLDP_DOT3_MAU_1000BASERHA 106 +#define LLDP_DOT3_MAU_1000BASERHB 107 +#define LLDP_DOT3_MAU_1000BASERHC 108 +#define LLDP_DOT3_MAU_2P5GBASEKX 109 +#define LLDP_DOT3_MAU_2P5GBASEX 110 +#define LLDP_DOT3_MAU_5GBASEKR 111 +#define LLDP_DOT3_MAU_5GBASER 112 +#define LLDP_DOT3_MAU_10GPASSXR 113 +#define LLDP_DOT3_MAU_25GBASELR 114 +#define LLDP_DOT3_MAU_25GBASEER 115 +#define LLDP_DOT3_MAU_50GBASER 116 +#define LLDP_DOT3_MAU_50GBASECR 117 +#define LLDP_DOT3_MAU_50GBASEKR 118 +#define LLDP_DOT3_MAU_50GBASESR 119 +#define LLDP_DOT3_MAU_50GBASEFR 120 +#define LLDP_DOT3_MAU_50GBASELR 121 +#define LLDP_DOT3_MAU_50GBASEER 122 +#define LLDP_DOT3_MAU_100GBASECR2 123 +#define LLDP_DOT3_MAU_100GBASEKR2 124 +#define LLDP_DOT3_MAU_100GBASESR2 125 +#define LLDP_DOT3_MAU_100GBASEDR 126 +#define LLDP_DOT3_MAU_200GBASER 127 +#define LLDP_DOT3_MAU_200GBASEDR4 128 +#define LLDP_DOT3_MAU_200GBASEFR4 129 +#define LLDP_DOT3_MAU_200GBASELR4 130 +#define LLDP_DOT3_MAU_200GBASECR4 131 +#define LLDP_DOT3_MAU_200GBASEKR4 132 +#define LLDP_DOT3_MAU_200GBASESR4 133 +#define LLDP_DOT3_MAU_200GBASEER4 134 +#define LLDP_DOT3_MAU_400GBASER 135 +#define LLDP_DOT3_MAU_400GBASESR16 136 +#define LLDP_DOT3_MAU_400GBASEDR4 137 +#define LLDP_DOT3_MAU_400GBASEFR8 138 +#define LLDP_DOT3_MAU_400GBASELR8 139 +#define LLDP_DOT3_MAU_400GBASEER8 140 +#define LLDP_DOT3_MAU_10BASET1L 141 +#define LLDP_DOT3_MAU_10BASET1SHD 142 +#define LLDP_DOT3_MAU_10BASET1SMD 143 +#define LLDP_DOT3_MAU_10BASET1SFD 144 /* Dot3 Power Devicetype */ -#define LLDP_DOT3_POWER_PSE 1 -#define LLDP_DOT3_POWER_PD 2 +#define LLDP_DOT3_POWER_PSE 1 +#define LLDP_DOT3_POWER_PD 2 /* Dot3 Power Pairs (RFC 3621) */ -#define LLDP_DOT3_POWERPAIRS_SIGNAL 1 -#define LLDP_DOT3_POWERPAIRS_SPARE 2 +#define LLDP_DOT3_POWERPAIRS_SIGNAL 1 +#define LLDP_DOT3_POWERPAIRS_SPARE 2 /* Dot3 Power type (for 802.3at) */ -#define LLDP_DOT3_POWER_8023AT_OFF 0 -#define LLDP_DOT3_POWER_8023AT_TYPE1 1 -#define LLDP_DOT3_POWER_8023AT_TYPE2 2 +#define LLDP_DOT3_POWER_8023AT_OFF 0 +#define LLDP_DOT3_POWER_8023AT_TYPE1 1 +#define LLDP_DOT3_POWER_8023AT_TYPE2 2 /* 802.3bt additions */ -#define LLDP_DOT3_POWER_8023BT_OFF 0 -#define LLDP_DOT3_POWER_8023BT_TYPE3 1 -#define LLDP_DOT3_POWER_8023BT_TYPE4 2 +#define LLDP_DOT3_POWER_8023BT_OFF 0 +#define LLDP_DOT3_POWER_8023BT_TYPE3 1 +#define LLDP_DOT3_POWER_8023BT_TYPE4 2 /* Dot3 power source */ -#define LLDP_DOT3_POWER_SOURCE_UNKNOWN 0 -#define LLDP_DOT3_POWER_SOURCE_PRIMARY 1 -#define LLDP_DOT3_POWER_SOURCE_PSE 1 -#define LLDP_DOT3_POWER_SOURCE_BACKUP 2 -#define LLDP_DOT3_POWER_SOURCE_LOCAL 2 -#define LLDP_DOT3_POWER_SOURCE_BOTH 3 +#define LLDP_DOT3_POWER_SOURCE_UNKNOWN 0 +#define LLDP_DOT3_POWER_SOURCE_PRIMARY 1 +#define LLDP_DOT3_POWER_SOURCE_PSE 1 +#define LLDP_DOT3_POWER_SOURCE_BACKUP 2 +#define LLDP_DOT3_POWER_SOURCE_LOCAL 2 +#define LLDP_DOT3_POWER_SOURCE_BOTH 3 /* Dot3 power priority */ -#define LLDP_DOT3_POWER_PRIO_UNKNOWN 0 -#define LLDP_DOT3_POWER_PRIO_CRITICAL 1 -#define LLDP_DOT3_POWER_PRIO_HIGH 2 -#define LLDP_DOT3_POWER_PRIO_LOW 3 +#define LLDP_DOT3_POWER_PRIO_UNKNOWN 0 +#define LLDP_DOT3_POWER_PRIO_CRITICAL 1 +#define LLDP_DOT3_POWER_PRIO_HIGH 2 +#define LLDP_DOT3_POWER_PRIO_LOW 3 /* PMD Auto-Negotiation Advertised Capability field, from RFC 3636 (see * IANAifMauAutoNegCapBits). Unfortunately, we are limited to two bytes, so * higher speed capabilities will map to "other". */ -#define LLDP_DOT3_LINK_AUTONEG_OTHER 0x8000 -#define LLDP_DOT3_LINK_AUTONEG_10BASE_T 0x4000 -#define LLDP_DOT3_LINK_AUTONEG_10BASET_FD 0x2000 -#define LLDP_DOT3_LINK_AUTONEG_100BASE_T4 0x1000 -#define LLDP_DOT3_LINK_AUTONEG_100BASE_TX 0x0800 -#define LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD 0x0400 -#define LLDP_DOT3_LINK_AUTONEG_100BASE_T2 0x0200 -#define LLDP_DOT3_LINK_AUTONEG_100BASE_T2FD 0x0100 -#define LLDP_DOT3_LINK_AUTONEG_FDX_PAUSE 0x0080 -#define LLDP_DOT3_LINK_AUTONEG_FDX_APAUSE 0x0040 -#define LLDP_DOT3_LINK_AUTONEG_FDX_SPAUSE 0x0020 -#define LLDP_DOT3_LINK_AUTONEG_FDX_BPAUSE 0x0010 -#define LLDP_DOT3_LINK_AUTONEG_1000BASE_X 0x0008 -#define LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD 0x0004 -#define LLDP_DOT3_LINK_AUTONEG_1000BASE_T 0x0002 -#define LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD 0x0001 +#define LLDP_DOT3_LINK_AUTONEG_OTHER 0x8000 +#define LLDP_DOT3_LINK_AUTONEG_10BASE_T 0x4000 +#define LLDP_DOT3_LINK_AUTONEG_10BASET_FD 0x2000 +#define LLDP_DOT3_LINK_AUTONEG_100BASE_T4 0x1000 +#define LLDP_DOT3_LINK_AUTONEG_100BASE_TX 0x0800 +#define LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD 0x0400 +#define LLDP_DOT3_LINK_AUTONEG_100BASE_T2 0x0200 +#define LLDP_DOT3_LINK_AUTONEG_100BASE_T2FD 0x0100 +#define LLDP_DOT3_LINK_AUTONEG_FDX_PAUSE 0x0080 +#define LLDP_DOT3_LINK_AUTONEG_FDX_APAUSE 0x0040 +#define LLDP_DOT3_LINK_AUTONEG_FDX_SPAUSE 0x0020 +#define LLDP_DOT3_LINK_AUTONEG_FDX_BPAUSE 0x0010 +#define LLDP_DOT3_LINK_AUTONEG_1000BASE_X 0x0008 +#define LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD 0x0004 +#define LLDP_DOT3_LINK_AUTONEG_1000BASE_T 0x0002 +#define LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD 0x0001 /* Capabilities */ -#define LLDP_CAP_OTHER 0x01 -#define LLDP_CAP_REPEATER 0x02 -#define LLDP_CAP_BRIDGE 0x04 -#define LLDP_CAP_WLAN 0x08 -#define LLDP_CAP_ROUTER 0x10 -#define LLDP_CAP_TELEPHONE 0x20 -#define LLDP_CAP_DOCSIS 0x40 -#define LLDP_CAP_STATION 0x80 +#define LLDP_CAP_OTHER 0x01 +#define LLDP_CAP_REPEATER 0x02 +#define LLDP_CAP_BRIDGE 0x04 +#define LLDP_CAP_WLAN 0x08 +#define LLDP_CAP_ROUTER 0x10 +#define LLDP_CAP_TELEPHONE 0x20 +#define LLDP_CAP_DOCSIS 0x40 +#define LLDP_CAP_STATION 0x80 -#define LLDP_PPVID_CAP_SUPPORTED (1 << 1) -#define LLDP_PPVID_CAP_ENABLED (1 << 2) +#define LLDP_PPVID_CAP_SUPPORTED (1 << 1) +#define LLDP_PPVID_CAP_ENABLED (1 << 2) /* see http://www.iana.org/assignments/address-family-numbers */ -#define LLDP_MGMT_ADDR_NONE 0 -#define LLDP_MGMT_ADDR_IP4 1 -#define LLDP_MGMT_ADDR_IP6 2 +#define LLDP_MGMT_ADDR_NONE 0 +#define LLDP_MGMT_ADDR_IP4 1 +#define LLDP_MGMT_ADDR_IP6 2 #define LLDP_MGMT_IFACE_UNKNOWN 1 #define LLDP_MGMT_IFACE_IFINDEX 2 -#define LLDP_MGMT_IFACE_SYSPORT 3 +#define LLDP_MGMT_IFACE_SYSPORT 3 -#define LLDP_MED_CLASS_I 1 -#define LLDP_MED_CLASS_II 2 -#define LLDP_MED_CLASS_III 3 -#define LLDP_MED_NETWORK_DEVICE 4 +#define LLDP_MED_CLASS_I 1 +#define LLDP_MED_CLASS_II 2 +#define LLDP_MED_CLASS_III 3 +#define LLDP_MED_NETWORK_DEVICE 4 /* LLDP MED application ttpes */ -#define LLDP_MED_APPTYPE_UNDEFINED 0 -#define LLDP_MED_APPTYPE_VOICE 1 -#define LLDP_MED_APPTYPE_VOICESIGNAL 2 -#define LLDP_MED_APPTYPE_GUESTVOICE 3 -#define LLDP_MED_APPTYPE_GUESTVOICESIGNAL 4 -#define LLDP_MED_APPTYPE_SOFTPHONEVOICE 5 -#define LLDP_MED_APPTYPE_VIDEOCONFERENCE 6 -#define LLDP_MED_APPTYPE_VIDEOSTREAM 7 -#define LLDP_MED_APPTYPE_VIDEOSIGNAL 8 -#define LLDP_MED_APPTYPE_LAST LLDP_MED_APPTYPE_VIDEOSIGNAL +#define LLDP_MED_APPTYPE_UNDEFINED 0 +#define LLDP_MED_APPTYPE_VOICE 1 +#define LLDP_MED_APPTYPE_VOICESIGNAL 2 +#define LLDP_MED_APPTYPE_GUESTVOICE 3 +#define LLDP_MED_APPTYPE_GUESTVOICESIGNAL 4 +#define LLDP_MED_APPTYPE_SOFTPHONEVOICE 5 +#define LLDP_MED_APPTYPE_VIDEOCONFERENCE 6 +#define LLDP_MED_APPTYPE_VIDEOSTREAM 7 +#define LLDP_MED_APPTYPE_VIDEOSIGNAL 8 +#define LLDP_MED_APPTYPE_LAST LLDP_MED_APPTYPE_VIDEOSIGNAL /* LLDP MED location formats */ -#define LLDP_MED_LOCFORMAT_COORD 1 -#define LLDP_MED_LOCFORMAT_CIVIC 2 -#define LLDP_MED_LOCFORMAT_ELIN 3 -#define LLDP_MED_LOCFORMAT_LAST LLDP_MED_LOCFORMAT_ELIN +#define LLDP_MED_LOCFORMAT_COORD 1 +#define LLDP_MED_LOCFORMAT_CIVIC 2 +#define LLDP_MED_LOCFORMAT_ELIN 3 +#define LLDP_MED_LOCFORMAT_LAST LLDP_MED_LOCFORMAT_ELIN -#define LLDP_MED_LOCATION_GEOID_WGS84 1 -#define LLDP_MED_LOCATION_GEOID_NAD83 2 -#define LLDP_MED_LOCATION_GEOID_NAD83_MLLW 3 +#define LLDP_MED_LOCATION_GEOID_WGS84 1 +#define LLDP_MED_LOCATION_GEOID_NAD83 2 +#define LLDP_MED_LOCATION_GEOID_NAD83_MLLW 3 -#define LLDP_MED_LOCATION_ALTITUDE_UNIT_METER 1 -#define LLDP_MED_LOCATION_ALTITUDE_UNIT_FLOOR 2 +#define LLDP_MED_LOCATION_ALTITUDE_UNIT_METER 1 +#define LLDP_MED_LOCATION_ALTITUDE_UNIT_FLOOR 2 /* LLDP MED power related constants */ -#define LLDP_MED_POW_TYPE_PSE 1 -#define LLDP_MED_POW_TYPE_PD 2 -#define LLDP_MED_POW_TYPE_RESERVED 3 +#define LLDP_MED_POW_TYPE_PSE 1 +#define LLDP_MED_POW_TYPE_PD 2 +#define LLDP_MED_POW_TYPE_RESERVED 3 -#define LLDP_MED_POW_SOURCE_UNKNOWN 1 -#define LLDP_MED_POW_SOURCE_PRIMARY 2 -#define LLDP_MED_POW_SOURCE_BACKUP 3 -#define LLDP_MED_POW_SOURCE_RESERVED 4 -#define LLDP_MED_POW_SOURCE_PSE 5 -#define LLDP_MED_POW_SOURCE_LOCAL 6 -#define LLDP_MED_POW_SOURCE_BOTH 7 +#define LLDP_MED_POW_SOURCE_UNKNOWN 1 +#define LLDP_MED_POW_SOURCE_PRIMARY 2 +#define LLDP_MED_POW_SOURCE_BACKUP 3 +#define LLDP_MED_POW_SOURCE_RESERVED 4 +#define LLDP_MED_POW_SOURCE_PSE 5 +#define LLDP_MED_POW_SOURCE_LOCAL 6 +#define LLDP_MED_POW_SOURCE_BOTH 7 -#define LLDP_MED_POW_PRIO_UNKNOWN 0 -#define LLDP_MED_POW_PRIO_CRITICAL 1 -#define LLDP_MED_POW_PRIO_HIGH 2 -#define LLDP_MED_POW_PRIO_LOW 3 +#define LLDP_MED_POW_PRIO_UNKNOWN 0 +#define LLDP_MED_POW_PRIO_CRITICAL 1 +#define LLDP_MED_POW_PRIO_HIGH 2 +#define LLDP_MED_POW_PRIO_LOW 3 /* LLDP MED capabilities */ -#define LLDP_MED_CAP_CAP 0x01 -#define LLDP_MED_CAP_POLICY 0x02 -#define LLDP_MED_CAP_LOCATION 0x04 -#define LLDP_MED_CAP_MDI_PSE 0x08 -#define LLDP_MED_CAP_MDI_PD 0x10 -#define LLDP_MED_CAP_IV 0x20 +#define LLDP_MED_CAP_CAP 0x01 +#define LLDP_MED_CAP_POLICY 0x02 +#define LLDP_MED_CAP_LOCATION 0x04 +#define LLDP_MED_CAP_MDI_PSE 0x08 +#define LLDP_MED_CAP_MDI_PD 0x10 +#define LLDP_MED_CAP_IV 0x20 /* Protocol constants for multi-protocol lldpd */ -#define LLDPD_MODE_LLDP 1 -#define LLDPD_MODE_CDPV1 2 -#define LLDPD_MODE_CDPV2 3 -#define LLDPD_MODE_SONMP 4 -#define LLDPD_MODE_EDP 5 -#define LLDPD_MODE_FDP 6 -#define LLDPD_MODE_MAX LLDPD_MODE_FDP - +#define LLDPD_MODE_LLDP 1 +#define LLDPD_MODE_CDPV1 2 +#define LLDPD_MODE_CDPV2 3 +#define LLDPD_MODE_SONMP 4 +#define LLDPD_MODE_EDP 5 +#define LLDPD_MODE_FDP 6 +#define LLDPD_MODE_MAX LLDPD_MODE_FDP /* Bond slave src mac type constants */ -#define LLDP_BOND_SLAVE_SRC_MAC_TYPE_UNKNOWN 0 -#define LLDP_BOND_SLAVE_SRC_MAC_TYPE_REAL 1 -#define LLDP_BOND_SLAVE_SRC_MAC_TYPE_ZERO 2 -#define LLDP_BOND_SLAVE_SRC_MAC_TYPE_FIXED 3 +#define LLDP_BOND_SLAVE_SRC_MAC_TYPE_UNKNOWN 0 +#define LLDP_BOND_SLAVE_SRC_MAC_TYPE_REAL 1 +#define LLDP_BOND_SLAVE_SRC_MAC_TYPE_ZERO 2 +#define LLDP_BOND_SLAVE_SRC_MAC_TYPE_FIXED 3 #define LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED 4 -#define LLDP_BOND_SLAVE_SRC_MAC_TYPE_MAX LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED +#define LLDP_BOND_SLAVE_SRC_MAC_TYPE_MAX \ + LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED /* Agent types */ -#define LLDP_AGENT_TYPE_UNKNOWN 0 -#define LLDP_AGENT_TYPE_NEAREST_BRIDGE 1 -#define LLDP_AGENT_TYPE_NEAREST_NONTPMR_BRIDGE 2 -#define LLDP_AGENT_TYPE_NEAREST_CUSTOMER_BRIDGE 3 -#define LLDP_AGENT_TYPE_MAX LLDP_AGENT_TYPE_NEAREST_CUSTOMER_BRIDGE +#define LLDP_AGENT_TYPE_UNKNOWN 0 +#define LLDP_AGENT_TYPE_NEAREST_BRIDGE 1 +#define LLDP_AGENT_TYPE_NEAREST_NONTPMR_BRIDGE 2 +#define LLDP_AGENT_TYPE_NEAREST_CUSTOMER_BRIDGE 3 +#define LLDP_AGENT_TYPE_MAX LLDP_AGENT_TYPE_NEAREST_CUSTOMER_BRIDGE #endif /* _LLDP_H */ diff --git a/src/lldpd-structs.c b/src/lldpd-structs.c index f9db9ece..6b42713c 100644 --- a/src/lldpd-structs.c +++ b/src/lldpd-structs.c @@ -29,9 +29,7 @@ lldpd_chassis_mgmt_cleanup(struct lldpd_chassis *chassis) log_debug("alloc", "cleanup management addresses for chassis %s", chassis->c_name ? chassis->c_name : "(unknown)"); - for (mgmt = TAILQ_FIRST(&chassis->c_mgmt); - mgmt != NULL; - mgmt = mgmt_next) { + for (mgmt = TAILQ_FIRST(&chassis->c_mgmt); mgmt != NULL; mgmt = mgmt_next) { mgmt_next = TAILQ_NEXT(mgmt, m_entries); free(mgmt); } @@ -56,8 +54,7 @@ lldpd_chassis_cleanup(struct lldpd_chassis *chassis, int all) free(chassis->c_id); free(chassis->c_name); free(chassis->c_descr); - if (all) - free(chassis); + if (all) free(chassis); } #ifdef ENABLE_DOT1 @@ -65,9 +62,7 @@ void lldpd_vlan_cleanup(struct lldpd_port *port) { struct lldpd_vlan *vlan, *vlan_next; - for (vlan = TAILQ_FIRST(&port->p_vlans); - vlan != NULL; - vlan = vlan_next) { + for (vlan = TAILQ_FIRST(&port->p_vlans); vlan != NULL; vlan = vlan_next) { free(vlan->v_name); vlan_next = TAILQ_NEXT(vlan, v_entries); free(vlan); @@ -80,9 +75,7 @@ void lldpd_ppvid_cleanup(struct lldpd_port *port) { struct lldpd_ppvid *ppvid, *ppvid_next; - for (ppvid = TAILQ_FIRST(&port->p_ppvids); - ppvid != NULL; - ppvid = ppvid_next) { + for (ppvid = TAILQ_FIRST(&port->p_ppvids); ppvid != NULL; ppvid = ppvid_next) { ppvid_next = TAILQ_NEXT(ppvid, p_entries); free(ppvid); } @@ -93,9 +86,7 @@ void lldpd_pi_cleanup(struct lldpd_port *port) { struct lldpd_pi *pi, *pi_next; - for (pi = TAILQ_FIRST(&port->p_pids); - pi != NULL; - pi = pi_next) { + for (pi = TAILQ_FIRST(&port->p_pids); pi != NULL; pi = pi_next) { free(pi->p_pi); pi_next = TAILQ_NEXT(pi, p_entries); free(pi); @@ -117,7 +108,8 @@ lldpd_custom_tlv_add(struct lldpd_port *port, struct lldpd_custom *curr) TAILQ_INSERT_TAIL(&port->p_custom_list, custom, next); } else { free(custom); - log_warn("rpc", "could not allocate memory for custom TLV info"); + log_warn("rpc", + "could not allocate memory for custom TLV info"); } } } @@ -126,9 +118,8 @@ void lldpd_custom_tlv_cleanup(struct lldpd_port *port, struct lldpd_custom *curr) { struct lldpd_custom *custom, *custom_next; - for (custom = TAILQ_FIRST(&port->p_custom_list); - custom != NULL; - custom = custom_next) { + for (custom = TAILQ_FIRST(&port->p_custom_list); custom != NULL; + custom = custom_next) { custom_next = TAILQ_NEXT(custom, next); if (!memcmp(curr->oui, custom->oui, sizeof(curr->oui)) && curr->subtype == custom->subtype) { @@ -143,9 +134,8 @@ void lldpd_custom_list_cleanup(struct lldpd_port *port) { struct lldpd_custom *custom, *custom_next; - for (custom = TAILQ_FIRST(&port->p_custom_list); - custom != NULL; - custom = custom_next) { + for (custom = TAILQ_FIRST(&port->p_custom_list); custom != NULL; + custom = custom_next) { custom_next = TAILQ_NEXT(custom, next); free(custom->oui_info); free(custom); @@ -160,22 +150,17 @@ lldpd_custom_list_cleanup(struct lldpd_port *port) */ void lldpd_remote_cleanup(struct lldpd_hardware *hardware, - void(*expire)(struct lldpd_hardware *, struct lldpd_port *), - int all) + void (*expire)(struct lldpd_hardware *, struct lldpd_port *), int all) { struct lldpd_port *port, *port_next; int del; time_t now = time(NULL); - log_debug("alloc", "cleanup remote port on %s", - hardware->h_ifname); - for (port = TAILQ_FIRST(&hardware->h_rports); - port != NULL; - port = port_next) { + log_debug("alloc", "cleanup remote port on %s", hardware->h_ifname); + for (port = TAILQ_FIRST(&hardware->h_rports); port != NULL; port = port_next) { port_next = TAILQ_NEXT(port, p_entries); del = all; - if (!all && expire && - (now >= port->p_lastupdate + port->p_ttl)) { + if (!all && expire && (now >= port->p_lastupdate + port->p_ttl)) { if (port->p_ttl > 0) hardware->h_ageout_cnt++; del = 1; } @@ -188,7 +173,8 @@ lldpd_remote_cleanup(struct lldpd_hardware *hardware, if (!all) TAILQ_REMOVE(&hardware->h_rports, port, p_entries); hardware->h_delete_cnt++; - /* Register last removal to be able to report lldpStatsRemTablesLastChangeTime */ + /* Register last removal to be able to report + * lldpStatsRemTablesLastChangeTime */ hardware->h_lport.p_lastremove = time(NULL); lldpd_port_cleanup(port, 1); free(port); @@ -205,7 +191,7 @@ lldpd_port_cleanup(struct lldpd_port *port, int all) #ifdef ENABLE_LLDPMED int i; if (all) - for (i=0; i < LLDP_MED_LOCFORMAT_LAST; i++) + for (i = 0; i < LLDP_MED_LOCFORMAT_LAST; i++) free(port->p_med_location[i].data); #endif #ifdef ENABLE_DOT1 diff --git a/src/lldpd-structs.h b/src/lldpd-structs.h index 5a7d4538..5647c83f 100644 --- a/src/lldpd-structs.h +++ b/src/lldpd-structs.h @@ -29,9 +29,9 @@ * we may also need linux/if.h in some modules. And they conflict each others. */ #ifdef HOST_OS_LINUX -# include +# include #else -# include +# include #endif #include @@ -45,17 +45,17 @@ #ifdef ENABLE_DOT1 struct lldpd_ppvid { TAILQ_ENTRY(lldpd_ppvid) p_entries; - u_int8_t p_cap_status; - u_int16_t p_ppvid; + u_int8_t p_cap_status; + u_int16_t p_ppvid; }; MARSHAL_BEGIN(lldpd_ppvid) MARSHAL_TQE(lldpd_ppvid, p_entries) MARSHAL_END(lldpd_ppvid); struct lldpd_vlan { - TAILQ_ENTRY(lldpd_vlan) v_entries; - char *v_name; - u_int16_t v_vid; + TAILQ_ENTRY(lldpd_vlan) v_entries; + char *v_name; + u_int16_t v_vid; }; MARSHAL_BEGIN(lldpd_vlan) MARSHAL_TQE(lldpd_vlan, v_entries) @@ -63,9 +63,9 @@ MARSHAL_STR(lldpd_vlan, v_name) MARSHAL_END(lldpd_vlan); struct lldpd_pi { - TAILQ_ENTRY(lldpd_pi) p_entries; - char *p_pi; - int p_pi_len; + TAILQ_ENTRY(lldpd_pi) p_entries; + char *p_pi; + int p_pi_len; }; MARSHAL_BEGIN(lldpd_pi) MARSHAL_TQE(lldpd_pi, p_entries) @@ -75,72 +75,72 @@ MARSHAL_END(lldpd_pi); #ifdef ENABLE_LLDPMED struct lldpd_med_policy { - u_int8_t index; /* Not used. */ - u_int8_t type; - u_int8_t unknown; - u_int8_t tagged; - u_int16_t vid; - u_int8_t priority; - u_int8_t dscp; + u_int8_t index; /* Not used. */ + u_int8_t type; + u_int8_t unknown; + u_int8_t tagged; + u_int16_t vid; + u_int8_t priority; + u_int8_t dscp; }; MARSHAL(lldpd_med_policy); struct lldpd_med_loc { - u_int8_t index; /* Not used. */ - u_int8_t format; - char *data; - int data_len; + u_int8_t index; /* Not used. */ + u_int8_t format; + char *data; + int data_len; }; MARSHAL_BEGIN(lldpd_med_loc) MARSHAL_FSTR(lldpd_med_loc, data, data_len) MARSHAL_END(lldpd_med_loc); struct lldpd_med_power { - u_int8_t devicetype; /* PD or PSE */ - u_int8_t source; - u_int8_t priority; - u_int16_t val; + u_int8_t devicetype; /* PD or PSE */ + u_int8_t source; + u_int8_t priority; + u_int16_t val; }; MARSHAL(lldpd_med_power); #endif #ifdef ENABLE_DOT3 struct lldpd_dot3_macphy { - u_int8_t autoneg_support; - u_int8_t autoneg_enabled; - u_int16_t autoneg_advertised; - u_int16_t mau_type; + u_int8_t autoneg_support; + u_int8_t autoneg_enabled; + u_int16_t autoneg_advertised; + u_int16_t mau_type; }; struct lldpd_dot3_power { - u_int8_t devicetype; - u_int8_t supported; - u_int8_t enabled; - u_int8_t paircontrol; - u_int8_t pairs; - u_int8_t class; - u_int8_t powertype; /* If set to LLDP_DOT3_POWER_8023AT_OFF, - following fields have no meaning */ - u_int8_t source; - u_int8_t priority; - u_int16_t requested; - u_int16_t allocated; + u_int8_t devicetype; + u_int8_t supported; + u_int8_t enabled; + u_int8_t paircontrol; + u_int8_t pairs; + u_int8_t class; + u_int8_t powertype; /* If set to LLDP_DOT3_POWER_8023AT_OFF, + following fields have no meaning */ + u_int8_t source; + u_int8_t priority; + u_int16_t requested; + u_int16_t allocated; /* For 802.3BT */ - u_int8_t pd_4pid; - u_int16_t requested_a; - u_int16_t requested_b; - u_int16_t allocated_a; - u_int16_t allocated_b; - u_int16_t pse_status; - u_int8_t pd_status; - u_int8_t pse_pairs_ext; - u_int8_t class_a; - u_int8_t class_b; - u_int8_t class_ext; - u_int8_t type_ext; - u_int8_t pd_load; - u_int16_t pse_max; + u_int8_t pd_4pid; + u_int16_t requested_a; + u_int16_t requested_b; + u_int16_t allocated_a; + u_int16_t allocated_b; + u_int16_t pse_status; + u_int8_t pd_status; + u_int8_t pse_pairs_ext; + u_int8_t class_a; + u_int8_t class_b; + u_int8_t class_ext; + u_int8_t type_ext; + u_int8_t pd_load; + u_int16_t pse_max; }; MARSHAL(lldpd_dot3_power); #endif @@ -152,25 +152,20 @@ struct cdpv2_power { }; #endif -enum { - LLDPD_AF_UNSPEC = 0, - LLDPD_AF_IPV4, - LLDPD_AF_IPV6, - LLDPD_AF_LAST -}; +enum { LLDPD_AF_UNSPEC = 0, LLDPD_AF_IPV4, LLDPD_AF_IPV6, LLDPD_AF_LAST }; -#define LLDPD_MGMT_MAXADDRSIZE 16 /* sizeof(struct in6_addr) */ +#define LLDPD_MGMT_MAXADDRSIZE 16 /* sizeof(struct in6_addr) */ union lldpd_address { - struct in_addr inet; - struct in6_addr inet6; - u_int8_t octets[LLDPD_MGMT_MAXADDRSIZE]; /* network byte order! */ + struct in_addr inet; + struct in6_addr inet6; + u_int8_t octets[LLDPD_MGMT_MAXADDRSIZE]; /* network byte order! */ }; struct lldpd_mgmt { TAILQ_ENTRY(lldpd_mgmt) m_entries; - int m_family; - union lldpd_address m_addr; - size_t m_addrsize; - u_int32_t m_iface; + int m_family; + union lldpd_address m_addr; + size_t m_addrsize; + u_int32_t m_iface; }; MARSHAL_BEGIN(lldpd_mgmt) MARSHAL_TQE(lldpd_mgmt, m_entries) @@ -178,32 +173,31 @@ MARSHAL_END(lldpd_mgmt); struct lldpd_chassis { TAILQ_ENTRY(lldpd_chassis) c_entries; - u_int16_t c_refcount; /* Reference count by ports */ - u_int16_t c_index; /* Monotonic index */ - u_int8_t c_protocol; /* Protocol used to get this chassis */ - u_int8_t c_id_subtype; - char *c_id; - int c_id_len; - char *c_name; - char *c_descr; - - u_int16_t c_cap_available; - u_int16_t c_cap_enabled; + u_int16_t c_refcount; /* Reference count by ports */ + u_int16_t c_index; /* Monotonic index */ + u_int8_t c_protocol; /* Protocol used to get this chassis */ + u_int8_t c_id_subtype; + char *c_id; + int c_id_len; + char *c_name; + char *c_descr; + + u_int16_t c_cap_available; + u_int16_t c_cap_enabled; TAILQ_HEAD(, lldpd_mgmt) c_mgmt; #ifdef ENABLE_LLDPMED - u_int16_t c_med_cap_available; - u_int8_t c_med_type; - char *c_med_hw; - char *c_med_fw; - char *c_med_sw; - char *c_med_sn; - char *c_med_manuf; - char *c_med_model; - char *c_med_asset; + u_int16_t c_med_cap_available; + u_int8_t c_med_type; + char *c_med_hw; + char *c_med_fw; + char *c_med_sw; + char *c_med_sn; + char *c_med_manuf; + char *c_med_model; + char *c_med_asset; #endif - }; /* WARNING: any change to this structure should also be reflected into `lldpd_copy_chassis()` which is not using marshaling. */ @@ -227,22 +221,22 @@ MARSHAL_END(lldpd_chassis); #ifdef ENABLE_CUSTOM -#define CUSTOM_TLV_ADD 1 -#define CUSTOM_TLV_REPLACE 2 -#define CUSTOM_TLV_REMOVE 3 +# define CUSTOM_TLV_ADD 1 +# define CUSTOM_TLV_REPLACE 2 +# define CUSTOM_TLV_REMOVE 3 /* Custom TLV struct as defined on page 35 of IEEE 802.1AB-2005 */ struct lldpd_custom { - TAILQ_ENTRY(lldpd_custom) next; /* Pointer to next custom TLV */ + TAILQ_ENTRY(lldpd_custom) next; /* Pointer to next custom TLV */ /* Organizationally Unique Identifier */ - u_int8_t oui[LLDP_TLV_ORG_OUI_LEN]; + u_int8_t oui[LLDP_TLV_ORG_OUI_LEN]; /* Organizationally Defined Subtype */ - u_int8_t subtype; + u_int8_t subtype; /* Organizationally Defined Information String */ - u_int8_t *oui_info; + u_int8_t *oui_info; /* Organizationally Defined Information String length */ - int oui_info_len; + int oui_info_len; }; MARSHAL_BEGIN(lldpd_custom) MARSHAL_TQE(lldpd_custom, next) @@ -251,44 +245,45 @@ MARSHAL_END(lldpd_custom); #endif struct lldpd_port { - TAILQ_ENTRY(lldpd_port) p_entries; - struct lldpd_chassis *p_chassis; /* Attached chassis */ - time_t p_lastchange; /* Time of last change of values */ - time_t p_lastupdate; /* Time of last update received */ - time_t p_lastremove; /* Time of last removal of a remote port. Used for local ports only - * Used for deciding lldpStatsRemTablesLastChangeTime */ - struct lldpd_frame *p_lastframe; /* Frame received during last update */ - u_int8_t p_protocol; /* Protocol used to get this port */ - u_int8_t p_hidden_in:1; /* Considered as hidden for reception */ - u_int8_t p_hidden_out:1; /* Considered as hidden for emission */ - u_int8_t p_disable_rx:1; /* Should RX be disabled for this port? */ - u_int8_t p_disable_tx:1; /* Should TX be disabled for this port? */ + TAILQ_ENTRY(lldpd_port) p_entries; + struct lldpd_chassis *p_chassis; /* Attached chassis */ + time_t p_lastchange; /* Time of last change of values */ + time_t p_lastupdate; /* Time of last update received */ + time_t + p_lastremove; /* Time of last removal of a remote port. Used for local ports + * only Used for deciding lldpStatsRemTablesLastChangeTime */ + struct lldpd_frame *p_lastframe; /* Frame received during last update */ + u_int8_t p_protocol; /* Protocol used to get this port */ + u_int8_t p_hidden_in : 1; /* Considered as hidden for reception */ + u_int8_t p_hidden_out : 1; /* Considered as hidden for emission */ + u_int8_t p_disable_rx : 1; /* Should RX be disabled for this port? */ + u_int8_t p_disable_tx : 1; /* Should TX be disabled for this port? */ /* Important: all fields that should be ignored to check if a port has * been changed should be before this mark. */ #define LLDPD_PORT_START_MARKER (offsetof(struct lldpd_port, _p_hardware_flags)) - int _p_hardware_flags; /* This is a copy of hardware flags. Do not use it! */ - u_int8_t p_id_subtype; - char *p_id; - int p_id_len; - char *p_descr; - int p_descr_force; /* Description has been forced by user */ - u_int16_t p_mfs; - u_int16_t p_ttl; /* TTL for remote port */ - int p_vlan_tx_tag; - int p_vlan_tx_enabled; + int _p_hardware_flags; /* This is a copy of hardware flags. Do not use it! */ + u_int8_t p_id_subtype; + char *p_id; + int p_id_len; + char *p_descr; + int p_descr_force; /* Description has been forced by user */ + u_int16_t p_mfs; + u_int16_t p_ttl; /* TTL for remote port */ + int p_vlan_tx_tag; + int p_vlan_tx_enabled; #ifdef ENABLE_DOT3 /* Dot3 stuff */ - u_int32_t p_aggregid; + u_int32_t p_aggregid; struct lldpd_dot3_macphy p_macphy; - struct lldpd_dot3_power p_power; + struct lldpd_dot3_power p_power; #endif #ifdef ENABLE_LLDPMED - u_int16_t p_med_cap_enabled; - struct lldpd_med_policy p_med_policy[LLDP_MED_APPTYPE_LAST]; - struct lldpd_med_loc p_med_location[LLDP_MED_LOCFORMAT_LAST]; - struct lldpd_med_power p_med_power; + u_int16_t p_med_cap_enabled; + struct lldpd_med_policy p_med_policy[LLDP_MED_APPTYPE_LAST]; + struct lldpd_med_loc p_med_location[LLDP_MED_LOCFORMAT_LAST]; + struct lldpd_med_power p_med_power; #endif #if defined ENABLE_CDP || defined ENABLE_FDP @@ -296,10 +291,10 @@ struct lldpd_port { #endif #ifdef ENABLE_DOT1 - u_int16_t p_pvid; + u_int16_t p_pvid; TAILQ_HEAD(, lldpd_vlan) p_vlans; TAILQ_HEAD(, lldpd_ppvid) p_ppvids; - TAILQ_HEAD(, lldpd_pi) p_pids; + TAILQ_HEAD(, lldpd_pi) p_pids; #endif #ifdef ENABLE_CUSTOM TAILQ_HEAD(, lldpd_custom) p_custom_list; @@ -332,10 +327,11 @@ MARSHAL_END(lldpd_port); #define LLDPD_RXTX_RXONLY 2 #define LLDPD_RXTX_DISABLED 3 #define LLDPD_RXTX_BOTH 4 -#define LLDPD_RXTX_FROM_PORT(p) (((p)->p_disable_rx && (p)->p_disable_tx)?LLDPD_RXTX_DISABLED: \ - ((p)->p_disable_rx && !(p)->p_disable_tx)?LLDPD_RXTX_TXONLY: \ - (!(p)->p_disable_rx && (p)->p_disable_tx)?LLDPD_RXTX_RXONLY: \ - LLDPD_RXTX_BOTH) +#define LLDPD_RXTX_FROM_PORT(p) \ + (((p)->p_disable_rx && (p)->p_disable_tx) ? LLDPD_RXTX_DISABLED : \ + ((p)->p_disable_rx && !(p)->p_disable_tx) ? LLDPD_RXTX_TXONLY : \ + (!(p)->p_disable_rx && (p)->p_disable_tx) ? LLDPD_RXTX_RXONLY : \ + LLDPD_RXTX_BOTH) #define LLDPD_RXTX_RXENABLED(v) ((v) == LLDPD_RXTX_RXONLY || (v) == LLDPD_RXTX_BOTH) #define LLDPD_RXTX_TXENABLED(v) ((v) == LLDPD_RXTX_TXONLY || (v) == LLDPD_RXTX_BOTH) struct lldpd_port_set { @@ -347,14 +343,14 @@ struct lldpd_port_set { int vlan_tx_enabled; #ifdef ENABLE_LLDPMED struct lldpd_med_policy *med_policy; - struct lldpd_med_loc *med_location; - struct lldpd_med_power *med_power; + struct lldpd_med_loc *med_location; + struct lldpd_med_power *med_power; #endif #ifdef ENABLE_DOT3 struct lldpd_dot3_power *dot3_power; #endif #ifdef ENABLE_CUSTOM - struct lldpd_custom *custom; + struct lldpd_custom *custom; int custom_list_clear; int custom_tlv_op; #endif @@ -365,48 +361,46 @@ MARSHAL_STR(lldpd_port_set, local_id) MARSHAL_STR(lldpd_port_set, local_descr) #ifdef ENABLE_LLDPMED MARSHAL_POINTER(lldpd_port_set, lldpd_med_policy, med_policy) -MARSHAL_POINTER(lldpd_port_set, lldpd_med_loc, med_location) -MARSHAL_POINTER(lldpd_port_set, lldpd_med_power, med_power) +MARSHAL_POINTER(lldpd_port_set, lldpd_med_loc, med_location) +MARSHAL_POINTER(lldpd_port_set, lldpd_med_power, med_power) #endif #ifdef ENABLE_DOT3 MARSHAL_POINTER(lldpd_port_set, lldpd_dot3_power, dot3_power) #endif #ifdef ENABLE_CUSTOM -MARSHAL_POINTER(lldpd_port_set, lldpd_custom, custom) +MARSHAL_POINTER(lldpd_port_set, lldpd_custom, custom) #endif MARSHAL_END(lldpd_port_set); /* Smart mode / Hide mode */ -#define SMART_INCOMING_FILTER (1<<0) /* Incoming filtering enabled */ -#define SMART_INCOMING_ONE_PROTO (1<<1) /* On reception, keep only one proto */ -#define SMART_INCOMING_ONE_NEIGH (1<<2) /* On reception, keep only one neighbor */ -#define SMART_OUTGOING_FILTER (1<<3) /* Outgoing filtering enabled */ -#define SMART_OUTGOING_ONE_PROTO (1<<4) /* On emission, keep only one proto */ -#define SMART_OUTGOING_ONE_NEIGH (1<<5) /* On emission, consider only one neighbor */ -#define SMART_INCOMING (SMART_INCOMING_FILTER | \ - SMART_INCOMING_ONE_PROTO | \ - SMART_INCOMING_ONE_NEIGH) -#define SMART_OUTGOING (SMART_OUTGOING_FILTER | \ - SMART_OUTGOING_ONE_PROTO | \ - SMART_OUTGOING_ONE_NEIGH) +#define SMART_INCOMING_FILTER (1 << 0) /* Incoming filtering enabled */ +#define SMART_INCOMING_ONE_PROTO (1 << 1) /* On reception, keep only one proto */ +#define SMART_INCOMING_ONE_NEIGH (1 << 2) /* On reception, keep only one neighbor */ +#define SMART_OUTGOING_FILTER (1 << 3) /* Outgoing filtering enabled */ +#define SMART_OUTGOING_ONE_PROTO (1 << 4) /* On emission, keep only one proto */ +#define SMART_OUTGOING_ONE_NEIGH (1 << 5) /* On emission, only one neighbor */ +#define SMART_INCOMING \ + (SMART_INCOMING_FILTER | SMART_INCOMING_ONE_PROTO | SMART_INCOMING_ONE_NEIGH) +#define SMART_OUTGOING \ + (SMART_OUTGOING_FILTER | SMART_OUTGOING_ONE_PROTO | SMART_OUTGOING_ONE_NEIGH) struct lldpd_config { - int c_paused; /* lldpd is paused */ - int c_tx_interval; /* Transmit interval (in ms) */ - int c_ttl; /* TTL */ - int c_smart; /* Bitmask for smart configuration (see SMART_*) */ - int c_receiveonly; /* Receive only mode */ - int c_max_neighbors; /* Maximum number of neighbors (per protocol) */ - - char *c_mgmt_pattern; /* Pattern to match a management address */ - char *c_cid_pattern; /* Pattern to match interfaces to use for chassis ID */ - char *c_cid_string; /* User defined string for chassis ID */ - char *c_iface_pattern; /* Pattern to match interfaces to use */ - char *c_perm_ifaces; /* Pattern to match interfaces to keep */ - - char *c_platform; /* Override platform description (for CDP) */ - char *c_description; /* Override chassis description */ - char *c_hostname; /* Override system name */ + int c_paused; /* lldpd is paused */ + int c_tx_interval; /* Transmit interval (in ms) */ + int c_ttl; /* TTL */ + int c_smart; /* Bitmask for smart configuration (see SMART_*) */ + int c_receiveonly; /* Receive only mode */ + int c_max_neighbors; /* Maximum number of neighbors (per protocol) */ + + char *c_mgmt_pattern; /* Pattern to match a management address */ + char *c_cid_pattern; /* Pattern to match interfaces to use for chassis ID */ + char *c_cid_string; /* User defined string for chassis ID */ + char *c_iface_pattern; /* Pattern to match interfaces to use */ + char *c_perm_ifaces; /* Pattern to match interfaces to keep */ + + char *c_platform; /* Override platform description (for CDP) */ + char *c_description; /* Override chassis description */ + char *c_hostname; /* Override system name */ int c_advertise_version; /* Should the precise version be advertised? */ int c_set_ifdescr; /* Set interface description */ int c_promisc; /* Interfaces should be in promiscuous mode */ @@ -415,16 +409,16 @@ struct lldpd_config { int c_mgmt_advertise; /* Management addresses advertisement */ #ifdef ENABLE_LLDPMED - int c_noinventory; /* Don't send inventory with LLDP-MED */ + int c_noinventory; /* Don't send inventory with LLDP-MED */ int c_enable_fast_start; /* enable fast start */ - int c_tx_fast_init; /* Num of lldpd lldppdu's for fast start */ - int c_tx_fast_interval; /* Time intr between sends during fast start */ + int c_tx_fast_init; /* Num of lldpd lldppdu's for fast start */ + int c_tx_fast_interval; /* Time intr between sends during fast start */ #endif - int c_tx_hold; /* Transmit hold */ + int c_tx_hold; /* Transmit hold */ int c_bond_slave_src_mac_type; /* Src mac type in lldp frames over bond slaves */ - int c_lldp_portid_type; /* The PortID type */ - int c_lldp_agent_type; /* The agent type */ + int c_lldp_portid_type; /* The PortID type */ + int c_lldp_agent_type; /* The agent type */ }; MARSHAL_BEGIN(lldpd_config) MARSHAL_STR(lldpd_config, c_mgmt_pattern) @@ -445,13 +439,11 @@ struct lldpd_frame { struct lldpd_hardware; struct lldpd; struct lldpd_ops { - int(*send)(struct lldpd *, - struct lldpd_hardware*, - char *, size_t); /* Function to send a frame */ - int(*recv)(struct lldpd *, - struct lldpd_hardware*, - int, char *, size_t); /* Function to receive a frame */ - int(*cleanup)(struct lldpd *, struct lldpd_hardware *); /* Cleanup function. */ + int (*send)(struct lldpd *, struct lldpd_hardware *, char *, + size_t); /* Function to send a frame */ + int (*recv)(struct lldpd *, struct lldpd_hardware *, int, char *, + size_t); /* Function to receive a frame */ + int (*cleanup)(struct lldpd *, struct lldpd_hardware *); /* Cleanup function. */ }; /* An interface is uniquely identified by h_ifindex, h_ifname and h_ops. This @@ -459,57 +451,57 @@ struct lldpd_ops { * interface. The same applies for renaming and we include the index in case of * renaming to an existing interface. */ struct lldpd_hardware { - TAILQ_ENTRY(lldpd_hardware) h_entries; - - struct lldpd *h_cfg; /* Pointer to main configuration */ - void *h_recv; /* FD for reception */ - int h_sendfd; /* FD for sending, only used by h_ops */ - int h_mangle; /* 1 if we have to mangle the MAC address */ - struct lldpd_ops *h_ops; /* Hardware-dependent functions */ - void *h_data; /* Hardware-dependent data */ - void *h_timer; /* Timer for this port */ - - int h_mtu; - int h_flags; /* Packets will be sent only - if IFF_RUNNING. Will be - removed if this is left - to 0. */ - int h_ifindex; /* Interface index, used by SNMP */ - int h_ifindex_changed; /* Interface index has changed */ - char h_ifname[IFNAMSIZ]; /* Should be unique */ - u_int8_t h_lladdr[ETHER_ADDR_LEN]; - - u_int64_t h_tx_cnt; - u_int64_t h_rx_cnt; - u_int64_t h_rx_discarded_cnt; - u_int64_t h_rx_unrecognized_cnt; - u_int64_t h_ageout_cnt; - u_int64_t h_insert_cnt; - u_int64_t h_delete_cnt; - u_int64_t h_drop_cnt; + TAILQ_ENTRY(lldpd_hardware) h_entries; + + struct lldpd *h_cfg; /* Pointer to main configuration */ + void *h_recv; /* FD for reception */ + int h_sendfd; /* FD for sending, only used by h_ops */ + int h_mangle; /* 1 if we have to mangle the MAC address */ + struct lldpd_ops *h_ops; /* Hardware-dependent functions */ + void *h_data; /* Hardware-dependent data */ + void *h_timer; /* Timer for this port */ + + int h_mtu; + int h_flags; /* Packets will be sent only + if IFF_RUNNING. Will be + removed if this is left + to 0. */ + int h_ifindex; /* Interface index, used by SNMP */ + int h_ifindex_changed; /* Interface index has changed */ + char h_ifname[IFNAMSIZ]; /* Should be unique */ + u_int8_t h_lladdr[ETHER_ADDR_LEN]; + + u_int64_t h_tx_cnt; + u_int64_t h_rx_cnt; + u_int64_t h_rx_discarded_cnt; + u_int64_t h_rx_unrecognized_cnt; + u_int64_t h_ageout_cnt; + u_int64_t h_insert_cnt; + u_int64_t h_delete_cnt; + u_int64_t h_drop_cnt; /* Previous values of different stuff. */ /* Backup of the previous local port. Used to check if there was a * change to send an immediate update. All those are not marshalled to * the client. */ - void *h_lport_previous; - ssize_t h_lport_previous_len; + void *h_lport_previous; + ssize_t h_lport_previous_len; /* Backup of the previous chassis ID. Used to check if there was a * change and send an LLDP shutdown. */ - u_int8_t h_lchassis_previous_id_subtype; - char *h_lchassis_previous_id; - int h_lchassis_previous_id_len; + u_int8_t h_lchassis_previous_id_subtype; + char *h_lchassis_previous_id; + int h_lchassis_previous_id_len; /* Backup of the previous port ID. Used to check if there was a change * and send an LLDP shutdown. */ - u_int8_t h_lport_previous_id_subtype; - char *h_lport_previous_id; - int h_lport_previous_id_len; + u_int8_t h_lport_previous_id_subtype; + char *h_lport_previous_id; + int h_lport_previous_id_len; - struct lldpd_port h_lport; /* Port attached to this hardware port */ + struct lldpd_port h_lport; /* Port attached to this hardware port */ TAILQ_HEAD(, lldpd_port) h_rports; /* Remote ports */ #ifdef ENABLE_LLDPMED - int h_tx_fast; /* current tx fast start count */ + int h_tx_fast; /* current tx fast start count */ #endif }; MARSHAL_BEGIN(lldpd_hardware) @@ -532,7 +524,7 @@ MARSHAL_END(lldpd_hardware); struct lldpd_interface { TAILQ_ENTRY(lldpd_interface) next; - char *name; + char *name; }; MARSHAL_BEGIN(lldpd_interface) MARSHAL_TQE(lldpd_interface, next) @@ -544,8 +536,8 @@ MARSHAL_TQ(lldpd_interface_list, lldpd_interface); struct lldpd_neighbor_change { char *ifname; #define NEIGHBOR_CHANGE_DELETED -1 -#define NEIGHBOR_CHANGE_ADDED 1 -#define NEIGHBOR_CHANGE_UPDATED 0 +#define NEIGHBOR_CHANGE_ADDED 1 +#define NEIGHBOR_CHANGE_UPDATED 0 int state; struct lldpd_port *neighbor; }; @@ -555,22 +547,21 @@ MARSHAL_POINTER(lldpd_neighbor_change, lldpd_port, neighbor) MARSHAL_END(lldpd_neighbor_change); /* Cleanup functions */ -void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis *); -void lldpd_chassis_cleanup(struct lldpd_chassis *, int); -void lldpd_remote_cleanup(struct lldpd_hardware *, - void(*expire)(struct lldpd_hardware *, struct lldpd_port *), - int); -void lldpd_port_cleanup(struct lldpd_port *, int); -void lldpd_config_cleanup(struct lldpd_config *); +void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis *); +void lldpd_chassis_cleanup(struct lldpd_chassis *, int); +void lldpd_remote_cleanup(struct lldpd_hardware *, + void (*expire)(struct lldpd_hardware *, struct lldpd_port *), int); +void lldpd_port_cleanup(struct lldpd_port *, int); +void lldpd_config_cleanup(struct lldpd_config *); #ifdef ENABLE_DOT1 -void lldpd_ppvid_cleanup(struct lldpd_port *); -void lldpd_vlan_cleanup(struct lldpd_port *); -void lldpd_pi_cleanup(struct lldpd_port *); +void lldpd_ppvid_cleanup(struct lldpd_port *); +void lldpd_vlan_cleanup(struct lldpd_port *); +void lldpd_pi_cleanup(struct lldpd_port *); #endif #ifdef ENABLE_CUSTOM -void lldpd_custom_tlv_cleanup(struct lldpd_port *, struct lldpd_custom *); -void lldpd_custom_tlv_add(struct lldpd_port *, struct lldpd_custom *); -void lldpd_custom_list_cleanup(struct lldpd_port *); +void lldpd_custom_tlv_cleanup(struct lldpd_port *, struct lldpd_custom *); +void lldpd_custom_tlv_add(struct lldpd_port *, struct lldpd_custom *); +void lldpd_custom_list_cleanup(struct lldpd_port *); #endif #endif diff --git a/src/log.c b/src/log.c index ebf7c8f1..3fd6d100 100644 --- a/src/log.c +++ b/src/log.c @@ -28,18 +28,18 @@ #include /* By default, logging is done on stderr. */ -static int use_syslog = 0; +static int use_syslog = 0; /* Default debug level */ -static int debug = 0; +static int debug = 0; /* Logging can be modified by providing an appropriate log handler. */ static void (*logh)(int severity, const char *msg) = NULL; -static void vlog(int, const char *, const char *, va_list); -static void logit(int, const char *, const char *, ...); +static void vlog(int, const char *, const char *, va_list); +static void logit(int, const char *, const char *, ...); #define MAX_DBG_TOKENS 40 -static const char *tokens[MAX_DBG_TOKENS + 1] = {NULL}; +static const char *tokens[MAX_DBG_TOKENS + 1] = { NULL }; void log_init(int n_syslog, int n_debug, const char *progname) @@ -47,8 +47,7 @@ log_init(int n_syslog, int n_debug, const char *progname) use_syslog = n_syslog; debug = n_debug; - if (use_syslog) - openlog(progname, LOG_PID | LOG_NDELAY, LOG_DAEMON); + if (use_syslog) openlog(progname, LOG_PID | LOG_NDELAY, LOG_DAEMON); tzset(); } @@ -56,12 +55,11 @@ log_init(int n_syslog, int n_debug, const char *progname) void log_level(int n_debug) { - if (n_debug >= 0) - debug = n_debug; + if (n_debug >= 0) debug = n_debug; } void -log_register(void (*cb)(int, const char*)) +log_register(void (*cb)(int, const char *)) { logh = cb; } @@ -72,7 +70,7 @@ log_accept(const char *token) int i; for (i = 0; i < MAX_DBG_TOKENS; i++) { if (tokens[i] == NULL) { - tokens[i+1] = NULL; + tokens[i + 1] = NULL; tokens[i] = token; return; } @@ -82,7 +80,7 @@ log_accept(const char *token) static void logit(int pri, const char *token, const char *fmt, ...) { - va_list ap; + va_list ap; va_start(ap, fmt); vlog(pri, token, fmt, ap); @@ -103,31 +101,48 @@ date() static const char * translate(int fd, int priority) { - /* Translate a syslog priority to a string. With colors if the output is a terminal. */ + /* Translate a syslog priority to a string. With colors if the output is a + * terminal. */ int tty = isatty(fd); switch (tty) { case 1: switch (priority) { - case LOG_EMERG: return "\033[1;37;41m[EMRG"; - case LOG_ALERT: return "\033[1;37;41m[ALRT"; - case LOG_CRIT: return "\033[1;37;41m[CRIT"; - case LOG_ERR: return "\033[1;31m[ ERR"; - case LOG_WARNING: return "\033[1;33m[WARN"; - case LOG_NOTICE: return "\033[1;34m[NOTI"; - case LOG_INFO: return "\033[1;34m[INFO"; - case LOG_DEBUG: return "\033[36m[ DBG"; + case LOG_EMERG: + return "\033[1;37;41m[EMRG"; + case LOG_ALERT: + return "\033[1;37;41m[ALRT"; + case LOG_CRIT: + return "\033[1;37;41m[CRIT"; + case LOG_ERR: + return "\033[1;31m[ ERR"; + case LOG_WARNING: + return "\033[1;33m[WARN"; + case LOG_NOTICE: + return "\033[1;34m[NOTI"; + case LOG_INFO: + return "\033[1;34m[INFO"; + case LOG_DEBUG: + return "\033[36m[ DBG"; } break; default: switch (priority) { - case LOG_EMERG: return "[EMRG"; - case LOG_ALERT: return "[ALRT"; - case LOG_CRIT: return "[CRIT"; - case LOG_ERR: return "[ ERR"; - case LOG_WARNING: return "[WARN"; - case LOG_NOTICE: return "[NOTI"; - case LOG_INFO: return "[INFO"; - case LOG_DEBUG: return "[ DBG"; + case LOG_EMERG: + return "[EMRG"; + case LOG_ALERT: + return "[ALRT"; + case LOG_CRIT: + return "[CRIT"; + case LOG_ERR: + return "[ ERR"; + case LOG_WARNING: + return "[WARN"; + case LOG_NOTICE: + return "[NOTI"; + case LOG_INFO: + return "[INFO"; + case LOG_DEBUG: + return "[ DBG"; } } return "[UNKN]"; @@ -160,12 +175,9 @@ vlog(int pri, const char *token, const char *fmt, va_list ap) /* Log to standard error in all cases */ char *nfmt; /* best effort in out of mem situations */ - if (asprintf(&nfmt, "%s %s%s%s]%s %s\n", - date(), - translate(STDERR_FILENO, pri), + if (asprintf(&nfmt, "%s %s%s%s]%s %s\n", date(), translate(STDERR_FILENO, pri), token ? "/" : "", token ? token : "", - isatty(STDERR_FILENO) ? "\033[0m" : "", - fmt) == -1) { + isatty(STDERR_FILENO) ? "\033[0m" : "", fmt) == -1) { vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); } else { @@ -175,12 +187,11 @@ vlog(int pri, const char *token, const char *fmt, va_list ap) fflush(stderr); } - void log_warn(const char *token, const char *emsg, ...) { - char *nfmt; - va_list ap; + char *nfmt; + va_list ap; /* best effort to even work in out of memory situations */ if (emsg == NULL) @@ -203,7 +214,7 @@ log_warn(const char *token, const char *emsg, ...) void log_warnx(const char *token, const char *emsg, ...) { - va_list ap; + va_list ap; va_start(ap, emsg); vlog(LOG_WARNING, token, emsg, ap); @@ -213,7 +224,7 @@ log_warnx(const char *token, const char *emsg, ...) void log_info(const char *token, const char *emsg, ...) { - va_list ap; + va_list ap; if (use_syslog || debug > 0 || logh) { va_start(ap, emsg); @@ -227,11 +238,8 @@ log_debug_accept_token(const char *token) { int i; if (tokens[0] == NULL) return 1; - for (i = 0; - (i < MAX_DBG_TOKENS) && (tokens[i] != NULL); - i++) { - if (!strcmp(tokens[i], token)) - return 1; + for (i = 0; (i < MAX_DBG_TOKENS) && (tokens[i] != NULL); i++) { + if (!strcmp(tokens[i], token)) return 1; } return 0; } @@ -239,7 +247,7 @@ log_debug_accept_token(const char *token) void log_debug(const char *token, const char *emsg, ...) { - va_list ap; + va_list ap; if ((debug > 1 && log_debug_accept_token(token)) || logh) { va_start(ap, emsg); @@ -253,12 +261,11 @@ fatal(const char *token, const char *emsg) { if (emsg == NULL) logit(LOG_CRIT, token ? token : "fatal", "%s", strerror(errno)); + else if (errno) + logit(LOG_CRIT, token ? token : "fatal", "%s: %s", emsg, + strerror(errno)); else - if (errno) - logit(LOG_CRIT, token ? token : "fatal", "%s: %s", - emsg, strerror(errno)); - else - logit(LOG_CRIT, token ? token : "fatal", "%s", emsg); + logit(LOG_CRIT, token ? token : "fatal", "%s", emsg); exit(1); } diff --git a/src/log.h b/src/log.h index 45534464..a85ccbf9 100644 --- a/src/log.h +++ b/src/log.h @@ -21,19 +21,19 @@ #include /* log.c */ -void log_init(int, int, const char *); -void log_warn(const char *, const char *, ...) __attribute__ ((format (printf, 2, 3))); -void log_warnx(const char *, const char *, ...) __attribute__ ((format (printf, 2, 3))); -void log_info(const char *, const char *, ...) __attribute__ ((format (printf, 2, 3))); -void log_debug(const char *, const char *, ...) __attribute__ ((format (printf, 2, 3))); -void fatal(const char*, const char *) __attribute__((__noreturn__)); -void fatalx(const char *, const char *) __attribute__((__noreturn__)); +void log_init(int, int, const char *); +void log_warn(const char *, const char *, ...) __attribute__((format(printf, 2, 3))); +void log_warnx(const char *, const char *, ...) __attribute__((format(printf, 2, 3))); +void log_info(const char *, const char *, ...) __attribute__((format(printf, 2, 3))); +void log_debug(const char *, const char *, ...) __attribute__((format(printf, 2, 3))); +void fatal(const char *, const char *) __attribute__((__noreturn__)); +void fatalx(const char *, const char *) __attribute__((__noreturn__)); -void log_register(void (*cb)(int, const char*)); -void log_accept(const char *); -void log_level(int); +void log_register(void (*cb)(int, const char *)); +void log_accept(const char *); +void log_level(int); /* version.c */ -void version_display(FILE *, const char *, int); +void version_display(FILE *, const char *, int); #endif diff --git a/src/marshal.c b/src/marshal.c index 0cde547c..c6a25f7b 100644 --- a/src/marshal.c +++ b/src/marshal.c @@ -31,46 +31,54 @@ /* Stolen from CCAN */ #if HAVE_ALIGNOF -# define ALIGNOF(t) (__alignof__(t)) +# define ALIGNOF(t) (__alignof__(t)) #else -# define ALIGNOF(t) ((sizeof(t) > 1)?((char *)(&((struct { char c; t _h; } *)0)->_h) - (char *)0):1) +# define ALIGNOF(t) \ + ((sizeof(t) > 1) ? \ + ((char *)(&((struct { \ + char c; \ + t _h; \ + } *)0) \ + ->_h) - \ + (char *)0) : \ + 1) #endif /* A serialized object */ struct marshal_serialized { - void *orig; /* Original reference. Also enforce alignment. */ - size_t size; + void *orig; /* Original reference. Also enforce alignment. */ + size_t size; unsigned char object[0]; }; struct marshal_info marshal_info_string = { .name = "null string", .size = 0, - .pointers = {MARSHAL_SUBINFO_NULL}, + .pointers = { MARSHAL_SUBINFO_NULL }, }; struct marshal_info marshal_info_fstring = { .name = "fixed string", .size = 0, - .pointers = {MARSHAL_SUBINFO_NULL}, + .pointers = { MARSHAL_SUBINFO_NULL }, }; struct marshal_info marshal_info_ignore = { .name = "ignored", .size = 0, - .pointers = {MARSHAL_SUBINFO_NULL}, + .pointers = { MARSHAL_SUBINFO_NULL }, }; /* List of already seen pointers */ struct ref { TAILQ_ENTRY(ref) next; void *pointer; - uintptr_t dummy; /* To renumerate pointers */ + uintptr_t dummy; /* To renumerate pointers */ }; TAILQ_HEAD(ref_l, ref); /* Serialize the given object. */ ssize_t -marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input, - int skip, void *_refs, int osize) +marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input, int skip, + void *_refs, int osize) { struct ref_l *refs = _refs; struct ref *cref; @@ -86,41 +94,41 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input, if (!refs) { refs = calloc(1, sizeof(struct ref_l)); if (!refs) { - log_warnx("marshal", "unable to allocate memory for list of references"); + log_warnx("marshal", + "unable to allocate memory for list of references"); return -1; } TAILQ_INIT(refs); } - TAILQ_FOREACH(cref, refs, next) { - if (unserialized == cref->pointer) - return 0; + TAILQ_FOREACH (cref, refs, next) { + if (unserialized == cref->pointer) return 0; /* dummy should be higher than any existing dummy */ if (cref->dummy >= dummy) dummy = cref->dummy + 1; } /* Handle special cases. */ size = mi->size; - if (!strcmp(mi->name, "null string")) - /* We know we can't be called with NULL */ + if (!strcmp(mi->name, "null string")) /* We know we can't be called with NULL */ size = strlen((char *)unserialized) + 1; else if (!strcmp(mi->name, "fixed string")) size = osize; /* Allocate serialized structure */ - len = sizeof(struct marshal_serialized) + (skip?0:size); + len = sizeof(struct marshal_serialized) + (skip ? 0 : size); serialized = calloc(1, len); if (!serialized) { - log_warnx("marshal", "unable to allocate memory to serialize structure %s", - mi->name); + log_warnx("marshal", + "unable to allocate memory to serialize structure %s", mi->name); len = -1; goto marshal_error; } /* We don't use the original pointer but a dummy one. */ - serialized->orig = (unsigned char*)dummy; + serialized->orig = (unsigned char *)dummy; /* Append the new reference */ if (!(cref = calloc(1, sizeof(struct ref)))) { - log_warnx("marshal", "unable to allocate memory for list of references"); + log_warnx("marshal", + "unable to allocate memory for list of references"); free(serialized); len = -1; goto marshal_error; @@ -130,41 +138,43 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input, TAILQ_INSERT_TAIL(refs, cref, next); /* First, serialize the main structure */ - if (!skip) - memcpy(serialized->object, unserialized, size); + if (!skip) memcpy(serialized->object, unserialized, size); /* Then, serialize inner structures */ for (current = mi->pointers; current->mi; current++) { size_t sublen; size_t padlen; - void *source; - void *target = NULL; + void *source; + void *target = NULL; if (current->kind == ignore) continue; if (current->kind == pointer) { - memcpy(&source, - (unsigned char *)unserialized + current->offset, + memcpy(&source, (unsigned char *)unserialized + current->offset, sizeof(void *)); if (source == NULL) continue; } else - source = (void *)((unsigned char *)unserialized + current->offset); + source = + (void *)((unsigned char *)unserialized + current->offset); if (current->offset2) - memcpy(&osize, (unsigned char*)unserialized + current->offset2, sizeof(int)); + memcpy(&osize, (unsigned char *)unserialized + current->offset2, + sizeof(int)); target = NULL; - sublen = marshal_serialize_(current->mi, - source, &target, + sublen = marshal_serialize_(current->mi, source, &target, current->kind == substruct, refs, osize); if (sublen == -1) { - log_warnx("marshal", "unable to serialize substructure %s for %s", + log_warnx("marshal", + "unable to serialize substructure %s for %s", current->mi->name, mi->name); free(serialized); return -1; } /* We want to put the renumerated pointer instead of the real one. */ if (current->kind == pointer && !skip) { - TAILQ_FOREACH(cref, refs, next) { + TAILQ_FOREACH (cref, refs, next) { if (source == cref->pointer) { - void *fakepointer = (unsigned char*)cref->dummy; - memcpy((unsigned char *)serialized->object + current->offset, + void *fakepointer = + (unsigned char *)cref->dummy; + memcpy((unsigned char *)serialized->object + + current->offset, &fakepointer, sizeof(void *)); break; } @@ -176,7 +186,8 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input, padlen = (padlen - (len % padlen)) % padlen; new = realloc(serialized, len + padlen + sublen); if (!new) { - log_warnx("marshal", "unable to allocate more memory to serialize structure %s", + log_warnx("marshal", + "unable to allocate more memory to serialize structure %s", mi->name); free(serialized); free(target); @@ -195,9 +206,7 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input, marshal_error: if (refs && !_refs) { struct ref *cref, *cref_next; - for (cref = TAILQ_FIRST(refs); - cref != NULL; - cref = cref_next) { + for (cref = TAILQ_FIRST(refs); cref != NULL; cref = cref_next) { cref_next = TAILQ_NEXT(cref, next); TAILQ_REMOVE(refs, cref, next); free(cref); @@ -211,19 +220,18 @@ marshal_error: struct gc { TAILQ_ENTRY(gc) next; void *pointer; - void *orig; /* Original reference (not valid anymore !) */ + void *orig; /* Original reference (not valid anymore !) */ }; TAILQ_HEAD(gc_l, gc); -static void* +static void * marshal_alloc(struct gc_l *pointers, size_t len, void *orig) { struct gc *gpointer = NULL; void *result = calloc(1, len); if (!result) return NULL; - if ((gpointer = (struct gc *)calloc(1, - sizeof(struct gc))) == NULL) { + if ((gpointer = (struct gc *)calloc(1, sizeof(struct gc))) == NULL) { free(result); return NULL; } @@ -236,24 +244,20 @@ static void marshal_free(struct gc_l *pointers, int gconly) { struct gc *pointer, *pointer_next; - for (pointer = TAILQ_FIRST(pointers); - pointer != NULL; - pointer = pointer_next) { + for (pointer = TAILQ_FIRST(pointers); pointer != NULL; pointer = pointer_next) { pointer_next = TAILQ_NEXT(pointer, next); TAILQ_REMOVE(pointers, pointer, next); - if (!gconly) - free(pointer->pointer); + if (!gconly) free(pointer->pointer); free(pointer); } } - /* Unserialize the given object. */ size_t marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **output, void *_pointers, int skip, int osize) { - int total_len = sizeof(struct marshal_serialized) + (skip?0:mi->size); + int total_len = sizeof(struct marshal_serialized) + (skip ? 0 : mi->size); struct marshal_serialized *serialized = buffer; struct gc_l *pointers = _pointers; int size, already, extra = 0; @@ -264,8 +268,9 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o log_debug("marshal", "start unserialization of %s", mi->name); if (len < sizeof(struct marshal_serialized) || len < total_len) { - log_warnx("marshal", "data to deserialize is too small (%zu) for structure %s", - len, mi->name); + log_warnx("marshal", + "data to deserialize is too small (%zu) for structure %s", len, + mi->name); return 0; } @@ -273,7 +278,8 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o if (!pointers) { pointers = calloc(1, sizeof(struct gc_l)); if (!pointers) { - log_warnx("marshal", "unable to allocate memory for garbage collection"); + log_warnx("marshal", + "unable to allocate memory for garbage collection"); return 0; } TAILQ_INIT(pointers); @@ -283,13 +289,20 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o size = mi->size; if (!strcmp(mi->name, "null string") || !strcmp(mi->name, "fixed string")) { switch (mi->name[0]) { - case 'n': size = strnlen((char *)serialized->object, - len - sizeof(struct marshal_serialized)) + 1; break; - case 'f': size = osize; extra=1; break; /* The extra byte is to ensure that - the string is null terminated. */ + case 'n': + size = strnlen((char *)serialized->object, + len - sizeof(struct marshal_serialized)) + + 1; + break; + case 'f': + size = osize; + extra = 1; + break; /* The extra byte is to ensure that + the string is null terminated. */ } if (size > len - sizeof(struct marshal_serialized)) { - log_warnx("marshal", "data to deserialize contains a string too long"); + log_warnx("marshal", + "data to deserialize contains a string too long"); total_len = 0; goto unmarshal_error; } @@ -298,8 +311,10 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o /* First, the main structure */ if (!skip) { - if ((*output = marshal_alloc(pointers, size + extra, serialized->orig)) == NULL) { - log_warnx("marshal", "unable to allocate memory to unserialize structure %s", + if ((*output = marshal_alloc(pointers, size + extra, + serialized->orig)) == NULL) { + log_warnx("marshal", + "unable to allocate memory to unserialize structure %s", mi->name); total_len = 0; goto unmarshal_error; @@ -309,12 +324,12 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o /* Then, each substructure */ for (current = mi->pointers; current->mi; current++) { - size_t sublen; - size_t padlen; + size_t sublen; + size_t padlen; new = (unsigned char *)*output + current->offset; if (current->kind == ignore) { - memset((unsigned char *)*output + current->offset, - 0, sizeof(void *)); + memset((unsigned char *)*output + current->offset, 0, + sizeof(void *)); continue; } if (current->kind == pointer) { @@ -322,9 +337,10 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o /* Did we already see this reference? */ already = 0; - TAILQ_FOREACH(apointer, pointers, next) + TAILQ_FOREACH (apointer, pointers, next) if (apointer->orig == *(void **)new) { - memcpy((unsigned char *)*output + current->offset, + memcpy((unsigned char *)*output + + current->offset, &apointer->pointer, sizeof(void *)); already = 1; break; @@ -333,22 +349,25 @@ marshal_unserialize_(struct marshal_info *mi, void *buffer, size_t len, void **o } /* Deserialize */ if (current->offset2) - memcpy(&osize, (unsigned char *)*output + current->offset2, sizeof(int)); + memcpy(&osize, (unsigned char *)*output + current->offset2, + sizeof(int)); padlen = ALIGNOF(struct marshal_serialized); padlen = (padlen - (total_len % padlen)) % padlen; - if (len < total_len + padlen || ((sublen = marshal_unserialize_(current->mi, - (unsigned char *)buffer + total_len + padlen, - len - total_len - padlen, &new, pointers, - current->kind == substruct, osize)) == 0)) { - log_warnx("marshal", "unable to serialize substructure %s for %s", + if (len < total_len + padlen || + ((sublen = marshal_unserialize_(current->mi, + (unsigned char *)buffer + total_len + padlen, + len - total_len - padlen, &new, pointers, + current->kind == substruct, osize)) == 0)) { + log_warnx("marshal", + "unable to serialize substructure %s for %s", current->mi->name, mi->name); total_len = 0; goto unmarshal_error; } /* Link the result */ if (current->kind == pointer) - memcpy((unsigned char *)*output + current->offset, - &new, sizeof(void *)); + memcpy((unsigned char *)*output + current->offset, &new, + sizeof(void *)); total_len += sublen + padlen; } diff --git a/src/marshal.h b/src/marshal.h index 0a782d53..155288c3 100644 --- a/src/marshal.h +++ b/src/marshal.h @@ -29,17 +29,20 @@ enum marshal_subinfo_kind { ignore, }; #define MARSHAL_INFO_POINTER 1 -#define MARSHAL_INFO_SUB 2 +#define MARSHAL_INFO_SUB 2 struct marshal_subinfo { - size_t offset; /* Offset compared to parent structure */ - size_t offset2; /* Ancillary offset (for related data) */ + size_t offset; /* Offset compared to parent structure */ + size_t offset2; /* Ancillary offset (for related data) */ enum marshal_subinfo_kind kind; /* Kind of substructure */ - struct marshal_info *mi; + struct marshal_info *mi; }; -#define MARSHAL_SUBINFO_NULL { .offset = 0, .offset2 = 0, .kind = ignore, .mi = NULL } +#define MARSHAL_SUBINFO_NULL \ + { \ + .offset = 0, .offset2 = 0, .kind = ignore, .mi = NULL \ + } struct marshal_info { - char *name; /* Name of structure */ - size_t size; /* Size of the structure */ + char *name; /* Name of structure */ + size_t size; /* Size of the structure */ #if defined __GNUC__ && __GNUC__ < 3 /* With gcc 2.96, flexible arrays are not supported, even with * -std=gnu99. And with gcc 3.x, zero-sized arrays cannot be statically @@ -58,98 +61,96 @@ extern struct marshal_info marshal_info_ignore; marshal. The marshalled type has to be a structure. */ #define MARSHAL_INFO(type) marshal_info_##type #ifdef MARSHAL_EXPORT -#define MARSHAL_HELPER_FUNCTIONS(type, ttype) \ - ssize_t \ - type ## _serialize(ttype *source, void *buffer) { \ - return marshal_serialize(type, \ - source, buffer); \ - } \ - size_t \ - type ## _unserialize(void *buffer, size_t len, \ - ttype **destination) { \ - void *p; \ - size_t rc; \ - rc = marshal_unserialize(type, \ - buffer, len, &p); \ - if (rc <= 0) return rc; \ - *destination = p; \ - return rc; \ - } -#define MARSHAL_BEGIN(type) struct marshal_info MARSHAL_INFO(type) = \ - { \ - .name = #type, \ - .size = sizeof(struct type), \ - .pointers = { -#define MARSHAL_ADD(_kind, type, subtype, member) \ - { .offset = offsetof(struct type, member), \ - .offset2 = 0, \ - .kind = _kind, \ - .mi = &MARSHAL_INFO(subtype) }, -#define MARSHAL_FSTR(type, member, len) \ - { .offset = offsetof(struct type, member), \ - .offset2 = offsetof(struct type, len), \ - .kind = pointer, \ - .mi = &marshal_info_fstring }, -#define MARSHAL_END(type) MARSHAL_SUBINFO_NULL }}; \ - MARSHAL_HELPER_FUNCTIONS(type, struct type) +# define MARSHAL_HELPER_FUNCTIONS(type, ttype) \ + ssize_t type##_serialize(ttype *source, void *buffer) \ + { \ + return marshal_serialize(type, source, buffer); \ + } \ + size_t type##_unserialize(void *buffer, size_t len, ttype **destination) \ + { \ + void *p; \ + size_t rc; \ + rc = marshal_unserialize(type, buffer, len, &p); \ + if (rc <= 0) return rc; \ + *destination = p; \ + return rc; \ + } +# define MARSHAL_BEGIN(type) \ + struct marshal_info MARSHAL_INFO( \ + type) = { .name = #type, .size = sizeof(struct type), .pointers = { +# define MARSHAL_ADD(_kind, type, subtype, member) \ + { .offset = offsetof(struct type, member), \ + .offset2 = 0, \ + .kind = _kind, \ + .mi = &MARSHAL_INFO(subtype) }, +# define MARSHAL_FSTR(type, member, len) \ + { .offset = offsetof(struct type, member), \ + .offset2 = offsetof(struct type, len), \ + .kind = pointer, \ + .mi = &marshal_info_fstring }, +# define MARSHAL_END(type) \ + MARSHAL_SUBINFO_NULL \ + } \ + } \ + ; \ + MARSHAL_HELPER_FUNCTIONS(type, struct type) #else -#define MARSHAL_HELPER_FUNCTIONS(type, ttype) \ - ssize_t type ## _serialize(ttype*, void*); \ - size_t type ## _unserialize(void*, size_t, ttype**); -#define MARSHAL_BEGIN(type) extern struct marshal_info MARSHAL_INFO(type); -#define MARSHAL_ADD(...) -#define MARSHAL_FSTR(...) -#define MARSHAL_END(type) MARSHAL_HELPER_FUNCTIONS(type, struct type) +# define MARSHAL_HELPER_FUNCTIONS(type, ttype) \ + ssize_t type##_serialize(ttype *, void *); \ + size_t type##_unserialize(void *, size_t, ttype **); +# define MARSHAL_BEGIN(type) extern struct marshal_info MARSHAL_INFO(type); +# define MARSHAL_ADD(...) +# define MARSHAL_FSTR(...) +# define MARSHAL_END(type) MARSHAL_HELPER_FUNCTIONS(type, struct type) #endif /* Shortcuts */ #define MARSHAL_POINTER(...) MARSHAL_ADD(pointer, ##__VA_ARGS__) #define MARSHAL_SUBSTRUCT(...) MARSHAL_ADD(substruct, ##__VA_ARGS__) #define MARSHAL_STR(type, member) MARSHAL_ADD(pointer, type, string, member) #define MARSHAL_IGNORE(type, member) MARSHAL_ADD(ignore, type, ignore, member) -#define MARSHAL_TQE(type, field) \ - MARSHAL_POINTER(type, type, field.tqe_next) \ - MARSHAL_IGNORE(type, field.tqe_prev) +#define MARSHAL_TQE(type, field) \ + MARSHAL_POINTER(type, type, field.tqe_next) \ + MARSHAL_IGNORE(type, field.tqe_prev) /* Support for TAILQ list is partial. Access to last and previous elements is not available. Some operations are therefore not possible. However, TAILQ_FOREACH is still available. */ -#define MARSHAL_TQH(type, subtype) \ - MARSHAL_POINTER(type, subtype, tqh_first) \ - MARSHAL_IGNORE(type, tqh_last) -#define MARSHAL_SUBTQ(type, subtype, field) \ - MARSHAL_POINTER(type, subtype, field.tqh_first) \ - MARSHAL_IGNORE(type, field.tqh_last) -#define MARSHAL(type) \ - MARSHAL_BEGIN(type) \ - MARSHAL_END(type) -#define MARSHAL_TQ(type, subtype) \ - MARSHAL_BEGIN(type) \ - MARSHAL_TQH(type, subtype) \ - MARSHAL_END(type) +#define MARSHAL_TQH(type, subtype) \ + MARSHAL_POINTER(type, subtype, tqh_first) \ + MARSHAL_IGNORE(type, tqh_last) +#define MARSHAL_SUBTQ(type, subtype, field) \ + MARSHAL_POINTER(type, subtype, field.tqh_first) \ + MARSHAL_IGNORE(type, field.tqh_last) +#define MARSHAL(type) \ + MARSHAL_BEGIN(type) \ + MARSHAL_END(type) +#define MARSHAL_TQ(type, subtype) \ + MARSHAL_BEGIN(type) \ + MARSHAL_TQH(type, subtype) \ + MARSHAL_END(type) /* Serialization */ -ssize_t marshal_serialize_(struct marshal_info *, void *, void **, int, void *, int) - __attribute__((nonnull (1, 2, 3) )); -#define marshal_serialize(type, o, output) marshal_serialize_(&MARSHAL_INFO(type), o, output, 0, NULL, 0) +ssize_t marshal_serialize_(struct marshal_info *, void *, void **, int, void *, int) + __attribute__((nonnull(1, 2, 3))); +#define marshal_serialize(type, o, output) \ + marshal_serialize_(&MARSHAL_INFO(type), o, output, 0, NULL, 0) /* Unserialization */ -size_t marshal_unserialize_(struct marshal_info *, void *, size_t, void **, void*, int, int) - __attribute__((nonnull (1, 2, 4) )); +size_t marshal_unserialize_(struct marshal_info *, void *, size_t, void **, void *, int, + int) __attribute__((nonnull(1, 2, 4))); #define marshal_unserialize(type, o, l, input) \ - marshal_unserialize_(&MARSHAL_INFO(type), o, l, input, NULL, 0, 0) + marshal_unserialize_(&MARSHAL_INFO(type), o, l, input, NULL, 0, 0) -#define marshal_repair_tailq(type, head, field) \ - do { \ - struct type *__item, *__item_next; \ - (head)->tqh_last = &(head)->tqh_first; \ - for (__item = TAILQ_FIRST(head); \ - __item != NULL; \ - __item = __item_next) { \ - __item_next = TAILQ_NEXT(__item, field); \ - __item->field.tqe_prev = (head)->tqh_last; \ - *(head)->tqh_last = __item; \ - (head)->tqh_last = &__item->field.tqe_next; \ - } \ - } while(0) +#define marshal_repair_tailq(type, head, field) \ + do { \ + struct type *__item, *__item_next; \ + (head)->tqh_last = &(head)->tqh_first; \ + for (__item = TAILQ_FIRST(head); __item != NULL; __item = __item_next) { \ + __item_next = TAILQ_NEXT(__item, field); \ + __item->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = __item; \ + (head)->tqh_last = &__item->field.tqe_next; \ + } \ + } while (0) #endif diff --git a/src/version.c b/src/version.c index 4b88999e..b02b082b 100644 --- a/src/version.c +++ b/src/version.c @@ -16,7 +16,7 @@ */ #if HAVE_CONFIG_H -# include +# include #endif #include @@ -28,7 +28,7 @@ version_display_array(FILE *destination, const char *prefix, const char *const * fprintf(destination, "%s", prefix); size_t count = 0; for (const char *const *p = items; *p; p++, count++) - fprintf(destination, "%s%s", count?", ":"", *p); + fprintf(destination, "%s%s", count ? ", " : "", *p); if (count == 0) fprintf(destination, "(none)\n"); else @@ -56,7 +56,8 @@ version_display(FILE *destination, const char *progname, int verbose) #ifdef ENABLE_CUSTOM "Custom TLV", #endif - NULL}; + NULL + }; const char *const protocols[] = { #ifdef ENABLE_CDP "CDP", @@ -70,16 +71,13 @@ version_display(FILE *destination, const char *progname, int verbose) #ifdef ENABLE_SONMP "SONMP", #endif - NULL}; - const char *const output_formats[] = { - "TEXT", - "KV", - "JSON", + NULL + }; + const char *const output_formats[] = { "TEXT", "KV", "JSON", #ifdef USE_XML "XML", #endif - NULL}; - + NULL }; fprintf(destination, "%s %s\n", progname, PACKAGE_VERSION); fprintf(destination, " Built on " BUILD_DATE "\n"); @@ -98,32 +96,32 @@ version_display(FILE *destination, const char *progname, int verbose) #else "no\n" #endif - ); + ); #ifdef HOST_OS_LINUX fprintf(destination, "Old kernel support: " -#ifdef ENABLE_OLDIES +# ifdef ENABLE_OLDIES "yes" -#else +# else "no" -#endif +# endif " (Linux " MIN_LINUX_KERNEL_VERSION "+)\n"); #endif #ifdef ENABLE_PRIVSEP fprintf(destination, - "Privilege separation: " "enabled\n"); - fprintf(destination, - "Privilege separation user: " PRIVSEP_USER "\n"); + "Privilege separation: " + "enabled\n"); + fprintf(destination, "Privilege separation user: " PRIVSEP_USER "\n"); fprintf(destination, "Privilege separation group: " PRIVSEP_GROUP "\n"); fprintf(destination, "Privilege separation chroot: " PRIVSEP_CHROOT "\n"); #else fprintf(destination, - "Privilege separation: " "disabled\n"); + "Privilege separation: " + "disabled\n"); #endif - fprintf(destination, - "Configuration directory: " SYSCONFDIR "\n"); + fprintf(destination, "Configuration directory: " SYSCONFDIR "\n"); } if (!strcmp(progname, "lldpcli")) { @@ -134,9 +132,6 @@ version_display(FILE *destination, const char *progname, int verbose) fprintf(destination, "\n"); /* Build */ - fprintf(destination, - "C compiler command: %s\n", LLDP_CC); - fprintf(destination, - "Linker command: %s\n", LLDP_LD); - + fprintf(destination, "C compiler command: %s\n", LLDP_CC); + fprintf(destination, "Linker command: %s\n", LLDP_LD); } diff --git a/tests/check-compat.h b/tests/check-compat.h index 47abe6fd..3236d78d 100644 --- a/tests/check-compat.h +++ b/tests/check-compat.h @@ -1,14 +1,16 @@ #ifndef _CHECK_COMPAT_H #define _CHECK_COMPAT_H -#if (CHECK_MAJOR_VERSION == 0 && (CHECK_MINOR_VERSION < 9 || (CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION < 10))) -# define ck_assert_ptr_eq(X,Y) do { \ - void* _ck_x = (X); \ - void* _ck_y = (Y); \ - ck_assert_msg(_ck_x == _ck_y, \ - "Assertion '"#X"=="#Y"' failed: "#X"==%p, "#Y"==%p", \ - _ck_x, _ck_y); \ - } while (0) +#if (CHECK_MAJOR_VERSION == 0 && \ + (CHECK_MINOR_VERSION < 9 || \ + (CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION < 10))) +# define ck_assert_ptr_eq(X, Y) \ + do { \ + void *_ck_x = (X); \ + void *_ck_y = (Y); \ + ck_assert_msg(_ck_x == _ck_y, \ + "Assertion '" #X "==" #Y "' failed: " #X "==%p, " #Y "==%p", _ck_x, _ck_y); \ + } while (0) #endif #endif diff --git a/tests/check_bitmap.c b/tests/check_bitmap.c index dfaefd60..e45729a8 100644 --- a/tests/check_bitmap.c +++ b/tests/check_bitmap.c @@ -19,14 +19,16 @@ #include "../src/daemon/lldpd.h" -START_TEST(test_empty) { +START_TEST(test_empty) +{ uint32_t vlan_bmap[VLAN_BITMAP_LEN] = {}; ck_assert(bitmap_isempty(vlan_bmap)); ck_assert_int_eq(bitmap_numbits(vlan_bmap), 0); } END_TEST -START_TEST(test_first_bit) { +START_TEST(test_first_bit) +{ uint32_t vlan_bmap[VLAN_BITMAP_LEN] = {}; bitmap_set(vlan_bmap, 1); ck_assert_int_eq(vlan_bmap[0], 2); @@ -34,14 +36,15 @@ START_TEST(test_first_bit) { } END_TEST -START_TEST(test_some_bits) { +START_TEST(test_some_bits) +{ uint32_t vlan_bmap[VLAN_BITMAP_LEN] = {}; bitmap_set(vlan_bmap, 1); bitmap_set(vlan_bmap, 6); bitmap_set(vlan_bmap, 31); bitmap_set(vlan_bmap, 50); ck_assert_int_eq(vlan_bmap[0], (1UL << 1) | (1UL << 6) | (1UL << 31)); - ck_assert_int_eq(vlan_bmap[1], (1UL << (50-32))); + ck_assert_int_eq(vlan_bmap[1], (1UL << (50 - 32))); ck_assert_int_eq(vlan_bmap[2], 0); ck_assert_int_eq(bitmap_numbits(vlan_bmap), 4); } diff --git a/tests/check_cdp.c b/tests/check_cdp.c index dddd063c..eede3b79 100644 --- a/tests/check_cdp.c +++ b/tests/check_cdp.c @@ -26,11 +26,11 @@ char filenameprefix[] = "cdp_send"; #ifdef ENABLE_CDP -START_TEST (test_send_cdpv1) +START_TEST(test_send_cdpv1) { int n; /* Packet we should build: -IEEE 802.3 Ethernet +IEEE 802.3 Ethernet Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc) Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad) Length: 106 @@ -40,79 +40,69 @@ Logical-Link Control SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) - 000. 00.. = Command: Unnumbered Information (0x00) - .... ..11 = Frame type: Unnumbered frame (0x03) + 000. 00.. = Command: Unnumbered Information (0x00) + .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Cisco (0x00000c) PID: CDP (0x2000) Cisco Discovery Protocol Version: 1 TTL: 180 seconds Checksum: 0x3af7 [correct] - [Good: True] - [Bad : False] + [Good: True] + [Bad : False] Device ID: First chassis - Type: Device ID (0x0001) - Length: 17 - Device ID: First chassis + Type: Device ID (0x0001) + Length: 17 + Device ID: First chassis Addresses - Type: Addresses (0x0002) - Length: 17 - Number of addresses: 1 - IP address: 172.17.142.37 - Protocol type: NLPID - Protocol length: 1 - Protocol: IP - Address length: 4 - IP address: 172.17.142.37 + Type: Addresses (0x0002) + Length: 17 + Number of addresses: 1 + IP address: 172.17.142.37 + Protocol type: NLPID + Protocol length: 1 + Protocol: IP + Address length: 4 + IP address: 172.17.142.37 Port ID: FastEthernet 1/5 - Type: Port ID (0x0003) - Length: 20 - Sent through Interface: FastEthernet 1/5 + Type: Port ID (0x0003) + Length: 20 + Sent through Interface: FastEthernet 1/5 Capabilities - Type: Capabilities (0x0004) - Length: 8 - Capabilities: 0x00000011 - .... .... .... .... .... .... .... ...1 = Is a Router - .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge - .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge - .... .... .... .... .... .... .... 0... = Not a Switch - .... .... .... .... .... .... ...1 .... = Is a Host - .... .... .... .... .... .... ..0. .... = Not IGMP capable - .... .... .... .... .... .... .0.. .... = Not a Repeater + Type: Capabilities (0x0004) + Length: 8 + Capabilities: 0x00000011 + .... .... .... .... .... .... .... ...1 = Is a Router + .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge + .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge + .... .... .... .... .... .... .... 0... = Not a Switch + .... .... .... .... .... .... ...1 .... = Is a Host + .... .... .... .... .... .... ..0. .... = Not IGMP capable + .... .... .... .... .... .... .0.. .... = Not a Repeater Software Version - Type: Software version (0x0005) - Length: 23 - Software Version: Chassis description + Type: Software version (0x0005) + Length: 23 + Software Version: Chassis description Platform: Linux - Type: Platform (0x0006) - Length: 9 - Platform: Linux + Type: Platform (0x0006) + Length: 9 + Platform: Linux */ - char pkt1[] = { - 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10, - 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x6a, 0xaa, 0xaa, - 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x01, 0xb4, - 0x3a, 0xf7, 0x00, 0x01, 0x00, 0x11, 0x46, 0x69, - 0x72, 0x73, 0x74, 0x20, 0x63, 0x68, 0x61, 0x73, - 0x73, 0x69, 0x73, 0x00, 0x02, 0x00, 0x11, 0x00, - 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc, 0x00, 0x04, - 0xac, 0x11, 0x8e, 0x25, 0x00, 0x03, 0x00, 0x14, - 0x46, 0x61, 0x73, 0x74, 0x45, 0x74, 0x68, 0x65, - 0x72, 0x6e, 0x65, 0x74, 0x20, 0x31, 0x2f, 0x35, - 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x11, - 0x00, 0x05, 0x00, 0x17, 0x43, 0x68, 0x61, 0x73, - 0x73, 0x69, 0x73, 0x20, 0x64, 0x65, 0x73, 0x63, - 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, - 0x06, 0x00, 0x09, 0x4c, 0x69, 0x6e, 0x75, 0x78 }; + char pkt1[] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10, 0x8e, 0xe7, + 0x84, 0xad, 0x00, 0x6a, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, + 0x01, 0xb4, 0x3a, 0xf7, 0x00, 0x01, 0x00, 0x11, 0x46, 0x69, 0x72, 0x73, + 0x74, 0x20, 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00, 0x02, 0x00, + 0x11, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc, 0x00, 0x04, 0xac, 0x11, + 0x8e, 0x25, 0x00, 0x03, 0x00, 0x14, 0x46, 0x61, 0x73, 0x74, 0x45, 0x74, + 0x68, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x31, 0x2f, 0x35, 0x00, 0x04, + 0x00, 0x08, 0x00, 0x00, 0x00, 0x11, 0x00, 0x05, 0x00, 0x17, 0x43, 0x68, + 0x61, 0x73, 0x73, 0x69, 0x73, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, + 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00, 0x09, 0x4c, 0x69, 0x6e, + 0x75, 0x78 }; struct packet *pkt; in_addr_t addr; struct lldpd_mgmt *mgmt; - struct lldpd cfg = { - .g_config = { - .c_ttl = 180, - .c_platform = "Linux" - } - }; + struct lldpd cfg = { .g_config = { .c_ttl = 180, .c_platform = "Linux" } }; /* Populate port and chassis */ hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_IFNAME; @@ -127,10 +117,8 @@ Cisco Discovery Protocol chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER; TAILQ_INIT(&chassis.c_mgmt); addr = inet_addr("172.17.142.37"); - mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, - &addr, sizeof(in_addr_t), 0); - if (mgmt == NULL) - ck_abort(); + mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr, sizeof(in_addr_t), 0); + if (mgmt == NULL) ck_abort(); TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt, m_entries); /* Build packet */ @@ -150,11 +138,11 @@ Cisco Discovery Protocol } END_TEST -START_TEST (test_send_cdpv2) +START_TEST(test_send_cdpv2) { int n; /* Packet we should build: -IEEE 802.3 Ethernet +IEEE 802.3 Ethernet Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc) Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad) the factory default) @@ -165,89 +153,78 @@ Logical-Link Control SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) - 000. 00.. = Command: Unnumbered Information (0x00) - .... ..11 = Frame type: Unnumbered frame (0x03) + 000. 00.. = Command: Unnumbered Information (0x00) + .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Cisco (0x00000c) PID: CDP (0x2000) Cisco Discovery Protocol Version: 2 TTL: 180 seconds Checksum: 0x5926 [correct] - [Good: True] - [Bad : False] + [Good: True] + [Bad : False] Device ID: Second chassis - Type: Device ID (0x0001) - Length: 18 - Device ID: Second chassis + Type: Device ID (0x0001) + Length: 18 + Device ID: Second chassis Addresses - Type: Addresses (0x0002) - Length: 26 - Number of addresses: 2 - IP address: 172.17.142.36 - Protocol type: NLPID - Protocol length: 1 - Protocol: IP - Address length: 4 - IP address: 172.17.142.36 - IP address: 172.17.142.38 - Protocol type: NLPID - Protocol length: 1 - Protocol: IP - Address length: 4 - IP address: 172.17.142.38 + Type: Addresses (0x0002) + Length: 26 + Number of addresses: 2 + IP address: 172.17.142.36 + Protocol type: NLPID + Protocol length: 1 + Protocol: IP + Address length: 4 + IP address: 172.17.142.36 + IP address: 172.17.142.38 + Protocol type: NLPID + Protocol length: 1 + Protocol: IP + Address length: 4 + IP address: 172.17.142.38 Port ID: Gigabit Ethernet 5/8 - Type: Port ID (0x0003) - Length: 24 - Sent through Interface: Gigabit Ethernet 5/8 + Type: Port ID (0x0003) + Length: 24 + Sent through Interface: Gigabit Ethernet 5/8 Capabilities - Type: Capabilities (0x0004) - Length: 8 - Capabilities: 0x00000019 - .... .... .... .... .... .... .... ...1 = Is a Router - .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge - .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge - .... .... .... .... .... .... .... 1... = Is a Switch - .... .... .... .... .... .... ...1 .... = Is a Host - .... .... .... .... .... .... ..0. .... = Not IGMP capable - .... .... .... .... .... .... .0.. .... = Not a Repeater + Type: Capabilities (0x0004) + Length: 8 + Capabilities: 0x00000019 + .... .... .... .... .... .... .... ...1 = Is a Router + .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge + .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge + .... .... .... .... .... .... .... 1... = Is a Switch + .... .... .... .... .... .... ...1 .... = Is a Host + .... .... .... .... .... .... ..0. .... = Not IGMP capable + .... .... .... .... .... .... .0.. .... = Not a Repeater Software Version - Type: Software version (0x0005) - Length: 23 - Software Version: Chassis description + Type: Software version (0x0005) + Length: 23 + Software Version: Chassis description Platform: Linux - Type: Platform (0x0006) - Length: 9 - Platform: Linux + Type: Platform (0x0006) + Length: 9 + Platform: Linux */ - char pkt1[] = { - 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10, - 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x78, 0xaa, 0xaa, - 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4, - 0xc8, 0x67, 0x00, 0x01, 0x00, 0x12, 0x53, 0x65, - 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x63, 0x68, 0x61, - 0x73, 0x73, 0x69, 0x73, 0x00, 0x02, 0x00, 0x1a, - 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0xcc, 0x00, - 0x04, 0xac, 0x11, 0x8e, 0x24, 0x01, 0x01, 0xcc, - 0x00, 0x04, 0xac, 0x11, 0x8e, 0x26, 0x00, 0x03, - 0x00, 0x18, 0x47, 0x69, 0x67, 0x61, 0x62, 0x69, - 0x74, 0x20, 0x45, 0x74, 0x68, 0x65, 0x72, 0x6e, - 0x65, 0x74, 0x20, 0x35, 0x2f, 0x38, 0x00, 0x04, - 0x00, 0x08, 0x00, 0x00, 0x00, 0x19, 0x00, 0x05, - 0x00, 0x17, 0x43, 0x68, 0x61, 0x73, 0x73, 0x69, - 0x73, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, - 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00, - 0x09, 0x4c, 0x69, 0x6e, 0x75, 0x78 }; + char pkt1[] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10, 0x8e, 0xe7, + 0x84, 0xad, 0x00, 0x78, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, + 0x02, 0xb4, 0xc8, 0x67, 0x00, 0x01, 0x00, 0x12, 0x53, 0x65, 0x63, 0x6f, + 0x6e, 0x64, 0x20, 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00, 0x02, + 0x00, 0x1a, 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0xcc, 0x00, 0x04, 0xac, + 0x11, 0x8e, 0x24, 0x01, 0x01, 0xcc, 0x00, 0x04, 0xac, 0x11, 0x8e, 0x26, + 0x00, 0x03, 0x00, 0x18, 0x47, 0x69, 0x67, 0x61, 0x62, 0x69, 0x74, 0x20, + 0x45, 0x74, 0x68, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x35, 0x2f, 0x38, + 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x19, 0x00, 0x05, 0x00, 0x17, + 0x43, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x20, 0x64, 0x65, 0x73, 0x63, + 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00, 0x09, 0x4c, + 0x69, 0x6e, 0x75, 0x78 }; struct packet *pkt; in_addr_t addr1; in_addr_t addr2; struct lldpd_mgmt *mgmt1; struct lldpd_mgmt *mgmt2; - struct lldpd cfg = { - .g_config = { - .c_ttl = 180, - .c_platform = "Linux" - } - }; + struct lldpd cfg = { .g_config = { .c_ttl = 180, .c_platform = "Linux" } }; /* Populate port and chassis */ hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR; @@ -260,16 +237,13 @@ Cisco Discovery Protocol chassis.c_name = "Second chassis"; chassis.c_descr = "Chassis description"; chassis.c_cap_available = chassis.c_cap_enabled = - LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE; + LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE; TAILQ_INIT(&chassis.c_mgmt); addr1 = inet_addr("172.17.142.36"); addr2 = inet_addr("172.17.142.38"); - mgmt1 = lldpd_alloc_mgmt(LLDPD_AF_IPV4, - &addr1, sizeof(in_addr_t), 0); - mgmt2 = lldpd_alloc_mgmt(LLDPD_AF_IPV4, - &addr2, sizeof(in_addr_t), 0); - if (mgmt1 == NULL || mgmt2 == NULL) - ck_abort(); + mgmt1 = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr1, sizeof(in_addr_t), 0); + mgmt2 = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr2, sizeof(in_addr_t), 0); + if (mgmt1 == NULL || mgmt2 == NULL) ck_abort(); TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt1, m_entries); TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt2, m_entries); @@ -290,49 +264,36 @@ Cisco Discovery Protocol } END_TEST -START_TEST (test_recv_cdpv1) +START_TEST(test_recv_cdpv1) { - char pkt1[] = { - 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x00, 0xe0, - 0x1e, 0xd5, 0xd5, 0x15, 0x01, 0x1e, 0xaa, 0xaa, - 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x01, 0xb4, - 0xdf, 0xf0, 0x00, 0x01, 0x00, 0x06, 0x52, 0x31, - 0x00, 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, - 0x01, 0x01, 0xcc, 0x00, 0x04, 0xc0, 0xa8, 0x0a, - 0x01, 0x00, 0x03, 0x00, 0x0d, 0x45, 0x74, 0x68, - 0x65, 0x72, 0x6e, 0x65, 0x74, 0x30, 0x00, 0x04, - 0x00, 0x08, 0x00, 0x00, 0x00, 0x11, 0x00, 0x05, - 0x00, 0xd8, 0x43, 0x69, 0x73, 0x63, 0x6f, 0x20, - 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, - 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x4f, 0x70, 0x65, - 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x53, - 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x53, 0x6f, - 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x0a, - 0x49, 0x4f, 0x53, 0x20, 0x28, 0x74, 0x6d, 0x29, - 0x20, 0x31, 0x36, 0x30, 0x30, 0x20, 0x53, 0x6f, - 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x28, - 0x43, 0x31, 0x36, 0x30, 0x30, 0x2d, 0x4e, 0x59, - 0x2d, 0x4c, 0x29, 0x2c, 0x20, 0x56, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x31, 0x2e, - 0x32, 0x28, 0x31, 0x32, 0x29, 0x50, 0x2c, 0x20, - 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x20, - 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52, 0x45, - 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a, 0x43, - 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, - 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39, 0x38, - 0x36, 0x2d, 0x31, 0x39, 0x39, 0x38, 0x20, 0x62, - 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, - 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, 0x2c, - 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20, 0x54, - 0x75, 0x65, 0x20, 0x30, 0x33, 0x2d, 0x4d, 0x61, - 0x72, 0x2d, 0x39, 0x38, 0x20, 0x30, 0x36, 0x3a, - 0x33, 0x33, 0x20, 0x62, 0x79, 0x20, 0x64, 0x73, - 0x63, 0x68, 0x77, 0x61, 0x72, 0x74, 0x00, 0x06, - 0x00, 0x0e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, - 0x31, 0x36, 0x30, 0x31 }; + char pkt1[] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x00, 0xe0, 0x1e, 0xd5, + 0xd5, 0x15, 0x01, 0x1e, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, + 0x01, 0xb4, 0xdf, 0xf0, 0x00, 0x01, 0x00, 0x06, 0x52, 0x31, 0x00, 0x02, + 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc, 0x00, 0x04, 0xc0, + 0xa8, 0x0a, 0x01, 0x00, 0x03, 0x00, 0x0d, 0x45, 0x74, 0x68, 0x65, 0x72, + 0x6e, 0x65, 0x74, 0x30, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x11, + 0x00, 0x05, 0x00, 0xd8, 0x43, 0x69, 0x73, 0x63, 0x6f, 0x20, 0x49, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x4f, + 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x53, 0x79, 0x73, + 0x74, 0x65, 0x6d, 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, + 0x20, 0x0a, 0x49, 0x4f, 0x53, 0x20, 0x28, 0x74, 0x6d, 0x29, 0x20, 0x31, + 0x36, 0x30, 0x30, 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, + 0x20, 0x28, 0x43, 0x31, 0x36, 0x30, 0x30, 0x2d, 0x4e, 0x59, 0x2d, 0x4c, + 0x29, 0x2c, 0x20, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, + 0x31, 0x2e, 0x32, 0x28, 0x31, 0x32, 0x29, 0x50, 0x2c, 0x20, 0x52, 0x45, + 0x4c, 0x45, 0x41, 0x53, 0x45, 0x20, 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, + 0x52, 0x45, 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a, 0x43, 0x6f, 0x70, + 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, + 0x39, 0x38, 0x36, 0x2d, 0x31, 0x39, 0x39, 0x38, 0x20, 0x62, 0x79, 0x20, + 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, + 0x73, 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43, 0x6f, 0x6d, 0x70, + 0x69, 0x6c, 0x65, 0x64, 0x20, 0x54, 0x75, 0x65, 0x20, 0x30, 0x33, 0x2d, + 0x4d, 0x61, 0x72, 0x2d, 0x39, 0x38, 0x20, 0x30, 0x36, 0x3a, 0x33, 0x33, + 0x20, 0x62, 0x79, 0x20, 0x64, 0x73, 0x63, 0x68, 0x77, 0x61, 0x72, 0x74, + 0x00, 0x06, 0x00, 0x0e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, 0x31, 0x36, + 0x30, 0x31 }; /* This is: -IEEE 802.3 Ethernet +IEEE 802.3 Ethernet Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc) Source: Cisco_d5:d5:15 (00:e0:1e:d5:d5:15) Length: 286 @@ -342,80 +303,74 @@ Logical-Link Control SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) - 000. 00.. = Command: Unnumbered Information (0x00) - .... ..11 = Frame type: Unnumbered frame (0x03) + 000. 00.. = Command: Unnumbered Information (0x00) + .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Cisco (0x00000c) PID: CDP (0x2000) Cisco Discovery Protocol Version: 1 TTL: 180 seconds Checksum: 0xdff0 [correct] - [Good: True] - [Bad : False] + [Good: True] + [Bad : False] Device ID: R1 - Type: Device ID (0x0001) - Length: 6 - Device ID: R1 + Type: Device ID (0x0001) + Length: 6 + Device ID: R1 Addresses - Type: Addresses (0x0002) - Length: 17 - Number of addresses: 1 - IP address: 192.168.10.1 - Protocol type: NLPID - Protocol length: 1 - Protocol: IP - Address length: 4 - IP address: 192.168.10.1 + Type: Addresses (0x0002) + Length: 17 + Number of addresses: 1 + IP address: 192.168.10.1 + Protocol type: NLPID + Protocol length: 1 + Protocol: IP + Address length: 4 + IP address: 192.168.10.1 Port ID: Ethernet0 - Type: Port ID (0x0003) - Length: 13 - Sent through Interface: Ethernet0 + Type: Port ID (0x0003) + Length: 13 + Sent through Interface: Ethernet0 Capabilities - Type: Capabilities (0x0004) - Length: 8 - Capabilities: 0x00000011 - .... .... .... .... .... .... .... ...1 = Is a Router - .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge - .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge - .... .... .... .... .... .... .... 0... = Not a Switch - .... .... .... .... .... .... ...1 .... = Is a Host - .... .... .... .... .... .... ..0. .... = Not IGMP capable - .... .... .... .... .... .... .0.. .... = Not a Repeater + Type: Capabilities (0x0004) + Length: 8 + Capabilities: 0x00000011 + .... .... .... .... .... .... .... ...1 = Is a Router + .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge + .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge + .... .... .... .... .... .... .... 0... = Not a Switch + .... .... .... .... .... .... ...1 .... = Is a Host + .... .... .... .... .... .... ..0. .... = Not IGMP capable + .... .... .... .... .... .... .0.. .... = Not a Repeater Software Version - Type: Software version (0x0005) - Length: 216 - Software Version: Cisco Internetwork Operating System Software - IOS (tm) 1600 Software (C1600-NY-L), Version 11.2(12)P, RELEASE SOFTWARE (fc1) - Copyright (c) 1986-1998 by cisco Systems, Inc. - Compiled Tue 03-Mar-98 06:33 by dschwart - Platform: cisco 1601 - Type: Platform (0x0006) - Length: 14 - Platform: cisco 1601 + Type: Software version (0x0005) + Length: 216 + Software Version: Cisco Internetwork Operating System Software + IOS (tm) 1600 Software (C1600-NY-L), Version 11.2(12)P, +RELEASE SOFTWARE (fc1) Copyright (c) 1986-1998 by cisco Systems, Inc. Compiled Tue +03-Mar-98 06:33 by dschwart Platform: cisco 1601 Type: Platform (0x0006) Length: 14 + Platform: cisco 1601 */ struct lldpd_chassis *nchassis = NULL; struct lldpd_port *nport = NULL; fail_unless(cdpv1_guess(pkt1, sizeof(pkt1))); - fail_unless(cdp_decode(NULL, pkt1, sizeof(pkt1), &hardware, - &nchassis, &nport) != -1); + fail_unless( + cdp_decode(NULL, pkt1, sizeof(pkt1), &hardware, &nchassis, &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; } - ck_assert_int_eq(nchassis->c_id_subtype, - LLDP_CHASSISID_SUBTYPE_LOCAL); + ck_assert_int_eq(nchassis->c_id_subtype, LLDP_CHASSISID_SUBTYPE_LOCAL); ck_assert_int_eq(nchassis->c_id_len, 2); fail_unless(memcmp(nchassis->c_id, "R1", 2) == 0); ck_assert_str_eq(nchassis->c_name, "R1"); ck_assert_int_eq(TAILQ_FIRST(&nchassis->c_mgmt)->m_addr.inet.s_addr, (u_int32_t)inet_addr("192.168.10.1")); ck_assert_int_eq(TAILQ_FIRST(&nchassis->c_mgmt)->m_iface, 0); - ck_assert_int_eq(nport->p_id_subtype, - LLDP_PORTID_SUBTYPE_IFNAME); + ck_assert_int_eq(nport->p_id_subtype, LLDP_PORTID_SUBTYPE_IFNAME); ck_assert_int_eq(nport->p_id_len, strlen("Ethernet0")); - fail_unless(memcmp(nport->p_id, - "Ethernet0", strlen("Ethernet0")) == 0); + fail_unless(memcmp(nport->p_id, "Ethernet0", strlen("Ethernet0")) == 0); ck_assert_str_eq(nport->p_descr, "Ethernet0"); ck_assert_int_eq(nchassis->c_cap_enabled, LLDP_CAP_ROUTER); ck_assert_str_eq(nchassis->c_descr, @@ -427,51 +382,37 @@ Cisco Discovery Protocol } END_TEST -START_TEST (test_recv_cdpv2) +START_TEST(test_recv_cdpv2) { - char pkt1[] = { - 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0xca, 0x00, - 0x68, 0x46, 0x00, 0x00, 0x01, 0x30, 0xaa, 0xaa, - 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4, - 0x54, 0x27, 0x00, 0x01, 0x00, 0x0f, 0x72, 0x74, - 0x62, 0x67, 0x36, 0x74, 0x65, 0x73, 0x74, 0x30, - 0x31, 0x00, 0x05, 0x00, 0xd3, 0x43, 0x69, 0x73, - 0x63, 0x6f, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, - 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20, - 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, - 0x67, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, - 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, - 0x65, 0x20, 0x0a, 0x49, 0x4f, 0x53, 0x20, 0x28, - 0x74, 0x6d, 0x29, 0x20, 0x37, 0x32, 0x30, 0x30, - 0x20, 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, - 0x65, 0x20, 0x28, 0x43, 0x37, 0x32, 0x30, 0x30, - 0x2d, 0x50, 0x2d, 0x4d, 0x29, 0x2c, 0x20, 0x56, - 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, - 0x32, 0x2e, 0x32, 0x28, 0x34, 0x36, 0x29, 0x2c, - 0x20, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, - 0x20, 0x53, 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52, - 0x45, 0x20, 0x28, 0x66, 0x63, 0x31, 0x29, 0x0a, - 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, - 0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39, - 0x38, 0x36, 0x2d, 0x32, 0x30, 0x30, 0x37, 0x20, - 0x62, 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f, - 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, - 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x0a, 0x43, - 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20, - 0x54, 0x68, 0x75, 0x20, 0x32, 0x36, 0x2d, 0x41, - 0x70, 0x72, 0x2d, 0x30, 0x37, 0x20, 0x32, 0x31, - 0x3a, 0x35, 0x36, 0x20, 0x62, 0x79, 0x20, 0x70, - 0x77, 0x61, 0x64, 0x65, 0x00, 0x06, 0x00, 0x11, - 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, 0x37, 0x32, - 0x30, 0x36, 0x56, 0x58, 0x52, 0x00, 0x02, 0x00, - 0x11, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc, - 0x00, 0x04, 0xac, 0x42, 0x37, 0x03, 0x00, 0x03, - 0x00, 0x13, 0x46, 0x61, 0x73, 0x74, 0x45, 0x74, - 0x68, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x30, 0x2f, - 0x30, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x0b, 0x00, 0x05, 0x00 }; + char pkt1[] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0xca, 0x00, 0x68, 0x46, + 0x00, 0x00, 0x01, 0x30, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, + 0x02, 0xb4, 0x54, 0x27, 0x00, 0x01, 0x00, 0x0f, 0x72, 0x74, 0x62, 0x67, + 0x36, 0x74, 0x65, 0x73, 0x74, 0x30, 0x31, 0x00, 0x05, 0x00, 0xd3, 0x43, + 0x69, 0x73, 0x63, 0x6f, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, + 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, + 0x69, 0x6e, 0x67, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x53, + 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x0a, 0x49, 0x4f, 0x53, + 0x20, 0x28, 0x74, 0x6d, 0x29, 0x20, 0x37, 0x32, 0x30, 0x30, 0x20, 0x53, + 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, 0x20, 0x28, 0x43, 0x37, 0x32, + 0x30, 0x30, 0x2d, 0x50, 0x2d, 0x4d, 0x29, 0x2c, 0x20, 0x56, 0x65, 0x72, + 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x32, 0x2e, 0x32, 0x28, 0x34, 0x36, + 0x29, 0x2c, 0x20, 0x52, 0x45, 0x4c, 0x45, 0x41, 0x53, 0x45, 0x20, 0x53, + 0x4f, 0x46, 0x54, 0x57, 0x41, 0x52, 0x45, 0x20, 0x28, 0x66, 0x63, 0x31, + 0x29, 0x0a, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, + 0x28, 0x63, 0x29, 0x20, 0x31, 0x39, 0x38, 0x36, 0x2d, 0x32, 0x30, 0x30, + 0x37, 0x20, 0x62, 0x79, 0x20, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, 0x53, + 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73, 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, + 0x0a, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x20, 0x54, 0x68, + 0x75, 0x20, 0x32, 0x36, 0x2d, 0x41, 0x70, 0x72, 0x2d, 0x30, 0x37, 0x20, + 0x32, 0x31, 0x3a, 0x35, 0x36, 0x20, 0x62, 0x79, 0x20, 0x70, 0x77, 0x61, + 0x64, 0x65, 0x00, 0x06, 0x00, 0x11, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x20, + 0x37, 0x32, 0x30, 0x36, 0x56, 0x58, 0x52, 0x00, 0x02, 0x00, 0x11, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x01, 0xcc, 0x00, 0x04, 0xac, 0x42, 0x37, 0x03, + 0x00, 0x03, 0x00, 0x13, 0x46, 0x61, 0x73, 0x74, 0x45, 0x74, 0x68, 0x65, + 0x72, 0x6e, 0x65, 0x74, 0x30, 0x2f, 0x30, 0x00, 0x04, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x05, 0x00 }; /* This is: -IEEE 802.3 Ethernet +IEEE 802.3 Ethernet Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc) Source: ca:00:68:46:00:00 (ca:00:68:46:00:00) Length: 304 @@ -481,85 +422,69 @@ Logical-Link Control SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) - 000. 00.. = Command: Unnumbered Information (0x00) - .... ..11 = Frame type: Unnumbered frame (0x03) + 000. 00.. = Command: Unnumbered Information (0x00) + .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Cisco (0x00000c) PID: CDP (0x2000) Cisco Discovery Protocol Version: 2 TTL: 180 seconds Checksum: 0x5427 [correct] - [Good: True] - [Bad : False] + [Good: True] + [Bad : False] Device ID: rtbg6test01 - Type: Device ID (0x0001) - Length: 15 - Device ID: rtbg6test01 + Type: Device ID (0x0001) + Length: 15 + Device ID: rtbg6test01 Software Version - Type: Software version (0x0005) - Length: 211 - Software Version: Cisco Internetwork Operating System Software - IOS (tm) 7200 Software (C7200-P-M), Version 12.2(46), RELEASE SOFTWARE (fc1) - Copyright (c) 1986-2007 by cisco Systems, Inc. - Compiled Thu 26-Apr-07 21:56 by pwade - Platform: cisco 7206VXR - Type: Platform (0x0006) - Length: 17 - Platform: cisco 7206VXR - Addresses - Type: Addresses (0x0002) - Length: 17 - Number of addresses: 1 - IP address: 172.66.55.3 - Protocol type: NLPID - Protocol length: 1 - Protocol: IP - Address length: 4 - IP address: 172.66.55.3 - Port ID: FastEthernet0/0 - Type: Port ID (0x0003) - Length: 19 - Sent through Interface: FastEthernet0/0 + Type: Software version (0x0005) + Length: 211 + Software Version: Cisco Internetwork Operating System Software + IOS (tm) 7200 Software (C7200-P-M), Version 12.2(46), RELEASE +SOFTWARE (fc1) Copyright (c) 1986-2007 by cisco Systems, Inc. Compiled Thu 26-Apr-07 +21:56 by pwade Platform: cisco 7206VXR Type: Platform (0x0006) Length: 17 Platform: +cisco 7206VXR Addresses Type: Addresses (0x0002) Length: 17 Number of addresses: 1 IP +address: 172.66.55.3 Protocol type: NLPID Protocol length: 1 Protocol: IP Address +length: 4 IP address: 172.66.55.3 Port ID: FastEthernet0/0 Type: Port ID (0x0003) + Length: 19 + Sent through Interface: FastEthernet0/0 Capabilities - Type: Capabilities (0x0004) - Length: 8 - Capabilities: 0x00000000 - .... .... .... .... .... .... .... ...0 = Not a Router - .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge - .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge - .... .... .... .... .... .... .... 0... = Not a Switch - .... .... .... .... .... .... ...0 .... = Not a Host - .... .... .... .... .... .... ..0. .... = Not IGMP capable - .... .... .... .... .... .... .0.. .... = Not a Repeater + Type: Capabilities (0x0004) + Length: 8 + Capabilities: 0x00000000 + .... .... .... .... .... .... .... ...0 = Not a Router + .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge + .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge + .... .... .... .... .... .... .... 0... = Not a Switch + .... .... .... .... .... .... ...0 .... = Not a Host + .... .... .... .... .... .... ..0. .... = Not IGMP capable + .... .... .... .... .... .... .0.. .... = Not a Repeater Duplex: Half - Type: Duplex (0x000b) - Length: 5 - Duplex: Half + Type: Duplex (0x000b) + Length: 5 + Duplex: Half */ struct lldpd_chassis *nchassis = NULL; struct lldpd_port *nport = NULL; fail_unless(cdpv2_guess(pkt1, sizeof(pkt1))); - fail_unless(cdp_decode(NULL, pkt1, sizeof(pkt1), &hardware, - &nchassis, &nport) != -1); + fail_unless( + cdp_decode(NULL, pkt1, sizeof(pkt1), &hardware, &nchassis, &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; } - ck_assert_int_eq(nchassis->c_id_subtype, - LLDP_CHASSISID_SUBTYPE_LOCAL); + ck_assert_int_eq(nchassis->c_id_subtype, LLDP_CHASSISID_SUBTYPE_LOCAL); ck_assert_int_eq(nchassis->c_id_len, strlen("rtbg6test01")); - fail_unless(memcmp(nchassis->c_id, - "rtbg6test01", strlen("rtbg6test01")) == 0); + fail_unless(memcmp(nchassis->c_id, "rtbg6test01", strlen("rtbg6test01")) == 0); ck_assert_str_eq(nchassis->c_name, "rtbg6test01"); ck_assert_int_eq(TAILQ_FIRST(&nchassis->c_mgmt)->m_addr.inet.s_addr, (u_int32_t)inet_addr("172.66.55.3")); ck_assert_int_eq(TAILQ_FIRST(&nchassis->c_mgmt)->m_iface, 0); - ck_assert_int_eq(nport->p_id_subtype, - LLDP_PORTID_SUBTYPE_IFNAME); + ck_assert_int_eq(nport->p_id_subtype, LLDP_PORTID_SUBTYPE_IFNAME); ck_assert_int_eq(nport->p_id_len, strlen("FastEthernet0/0")); - fail_unless(memcmp(nport->p_id, - "FastEthernet0/0", strlen("FastEthernet0/0")) == 0); + fail_unless( + memcmp(nport->p_id, "FastEthernet0/0", strlen("FastEthernet0/0")) == 0); ck_assert_str_eq(nport->p_descr, "FastEthernet0/0"); ck_assert_int_eq(nchassis->c_cap_enabled, LLDP_CAP_STATION); ck_assert_str_eq(nchassis->c_descr, @@ -599,13 +524,13 @@ int main() { int number_failed; - Suite *s = cdp_suite (); - SRunner *sr = srunner_create (s); - srunner_set_fork_status (sr, CK_NOFORK); /* Can't fork because - we need to write - files */ - srunner_run_all (sr, CK_ENV); - number_failed = srunner_ntests_failed (sr); - srunner_free (sr); + Suite *s = cdp_suite(); + SRunner *sr = srunner_create(s); + srunner_set_fork_status(sr, CK_NOFORK); /* Can't fork because + we need to write + files */ + srunner_run_all(sr, CK_ENV); + number_failed = srunner_ntests_failed(sr); + srunner_free(sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/check_edp.c b/tests/check_edp.c index 126c5678..32849a32 100644 --- a/tests/check_edp.c +++ b/tests/check_edp.c @@ -26,7 +26,7 @@ char filenameprefix[] = "edp_send"; #ifdef ENABLE_EDP -START_TEST (test_send_basic) +START_TEST(test_send_basic) { int n; /* Packet we should build: @@ -35,52 +35,48 @@ Extreme Discovery Protocol Reserved: 0 Data length: 74 Checksum: 0xde22 [correct] - [Good: True] - [Bad : False] + [Good: True] + [Bad : False] Sequence number: 0 Machine ID type: MAC (0) Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad) Display: "First chassis" - Marker 0x99, length 18, type 1 = Display - TLV Marker: 0x99 - TLV type: Display (1) - TLV length: 18 - Name: First chassis + Marker 0x99, length 18, type 1 = Display + TLV Marker: 0x99 + TLV type: Display (1) + TLV length: 18 + Name: First chassis Info: Slot/Port: 1/4, Version: 7.6.4.99 - Marker 0x99, length 36, type 2 = Info - TLV Marker: 0x99 - TLV type: Info (2) - TLV length: 36 - Slot: 1 - Port: 4 - Virt chassis: 0 - Reserved: 000000000000 - Version: 7.6.4 Internal: 99 - Version: 0x07060463 - Version (major1): 7 - Version (major2): 6 - Version (sustaining): 4 - Version (internal): 99 - Connections: FFFFFFFF000000000000000000000000 + Marker 0x99, length 36, type 2 = Info + TLV Marker: 0x99 + TLV type: Info (2) + TLV length: 36 + Slot: 1 + Port: 4 + Virt chassis: 0 + Reserved: 000000000000 + Version: 7.6.4 Internal: 99 + Version: 0x07060463 + Version (major1): 7 + Version (major2): 6 + Version (sustaining): 4 + Version (internal): 99 + Connections: FFFFFFFF000000000000000000000000 Null - Marker 0x99, length 4, type 0 = Null - TLV Marker: 0x99 - TLV type: Null (0) - TLV length: 4 + Marker 0x99, length 4, type 0 = Null + TLV Marker: 0x99 + TLV type: Null (0) + TLV length: 4 */ - char pkt1[] = { - 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, - 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa, - 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00, - 0x00, 0x4a, 0xde, 0x22, 0x00, 0x00, 0x00, 0x00, - 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01, - 0x00, 0x12, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20, - 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00, - 0x99, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 }; + char pkt1[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, 0x8e, 0xe7, + 0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, + 0x01, 0x00, 0x00, 0x4a, 0xde, 0x22, 0x00, 0x00, 0x00, 0x00, 0x5e, 0x10, + 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01, 0x00, 0x12, 0x46, 0x69, 0x72, 0x73, + 0x74, 0x20, 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00, 0x99, 0x02, + 0x00, 0x24, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, + 0x00, 0x04 }; struct packet *pkt; /* Populate port and chassis */ @@ -111,8 +107,8 @@ Extreme Discovery Protocol } END_TEST -#ifdef ENABLE_DOT1 -START_TEST (test_send_vlans) +# ifdef ENABLE_DOT1 +START_TEST(test_send_vlans) { int n; /* Packets we should build: @@ -121,128 +117,118 @@ Extreme Discovery Protocol Reserved: 0 Data length: 74 Checksum: 0xde20 [correct] - [Good: True] - [Bad : False] + [Good: True] + [Bad : False] Sequence number: 2 Machine ID type: MAC (0) Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad) Display: "First chassis" - Marker 0x99, length 18, type 1 = Display - TLV Marker: 0x99 - TLV type: Display (1) - TLV length: 18 - Name: First chassis + Marker 0x99, length 18, type 1 = Display + TLV Marker: 0x99 + TLV type: Display (1) + TLV length: 18 + Name: First chassis Info: Slot/Port: 1/4, Version: 7.6.4.99 - Marker 0x99, length 36, type 2 = Info - TLV Marker: 0x99 - TLV type: Info (2) - TLV length: 36 - Slot: 1 - Port: 4 - Virt chassis: 0 - Reserved: 000000000000 - Version: 7.6.4 Internal: 99 - Version: 0x07060463 - Version (major1): 7 - Version (major2): 6 - Version (sustaining): 4 - Version (internal): 99 - Connections: FFFFFFFF000000000000000000000000 + Marker 0x99, length 36, type 2 = Info + TLV Marker: 0x99 + TLV type: Info (2) + TLV length: 36 + Slot: 1 + Port: 4 + Virt chassis: 0 + Reserved: 000000000000 + Version: 7.6.4 Internal: 99 + Version: 0x07060463 + Version (major1): 7 + Version (major2): 6 + Version (sustaining): 4 + Version (internal): 99 + Connections: FFFFFFFF000000000000000000000000 Null - Marker 0x99, length 4, type 0 = Null - TLV Marker: 0x99 - TLV type: Null (0) - TLV length: 4 + Marker 0x99, length 4, type 0 = Null + TLV Marker: 0x99 + TLV type: Null (0) + TLV length: 4 Extreme Discovery Protocol Version: 1 Reserved: 0 Data length: 102 Checksum: 0x28c4 [correct] - [Good: True] - [Bad : False] + [Good: True] + [Bad : False] Sequence number: 3 Machine ID type: MAC (0) Machine MAC: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad) Vlan: ID 157, Name "First VLAN" - Marker 0x99, length 27, type 5 = VL - TLV Marker: 0x99 - TLV type: VL (5) - TLV length: 27 - Flags: 0x00 - 0... .... = Flags-IP: Not set - .000 000. = Flags-reserved: 0x00 - .... ...0 = Flags-Unknown: Not set - Reserved1: 00 - Vlan ID: 157 - Reserved2: 00000000 - IP addr: 0.0.0.0 (0.0.0.0) - Name: First VLAN + Marker 0x99, length 27, type 5 = VL + TLV Marker: 0x99 + TLV type: VL (5) + TLV length: 27 + Flags: 0x00 + 0... .... = Flags-IP: Not set + .000 000. = Flags-reserved: 0x00 + .... ...0 = Flags-Unknown: Not set + Reserved1: 00 + Vlan ID: 157 + Reserved2: 00000000 + IP addr: 0.0.0.0 (0.0.0.0) + Name: First VLAN Vlan: ID 1247, Name "Second VLAN" - Marker 0x99, length 28, type 5 = VL - TLV Marker: 0x99 - TLV type: VL (5) - TLV length: 28 - Flags: 0x00 - 0... .... = Flags-IP: Not set - .000 000. = Flags-reserved: 0x00 - .... ...0 = Flags-Unknown: Not set - Reserved1: 00 - Vlan ID: 1247 - Reserved2: 00000000 - IP addr: 0.0.0.0 (0.0.0.0) - Name: Second VLAN + Marker 0x99, length 28, type 5 = VL + TLV Marker: 0x99 + TLV type: VL (5) + TLV length: 28 + Flags: 0x00 + 0... .... = Flags-IP: Not set + .000 000. = Flags-reserved: 0x00 + .... ...0 = Flags-Unknown: Not set + Reserved1: 00 + Vlan ID: 1247 + Reserved2: 00000000 + IP addr: 0.0.0.0 (0.0.0.0) + Name: Second VLAN Vlan: ID 741, Name "Third VLAN" - Marker 0x99, length 27, type 5 = VL - TLV Marker: 0x99 - TLV type: VL (5) - TLV length: 27 - Flags: 0x00 - 0... .... = Flags-IP: Not set - .000 000. = Flags-reserved: 0x00 - .... ...0 = Flags-Unknown: Not set - Reserved1: 00 - Vlan ID: 741 - Reserved2: 00000000 - IP addr: 0.0.0.0 (0.0.0.0) - Name: Third VLAN + Marker 0x99, length 27, type 5 = VL + TLV Marker: 0x99 + TLV type: VL (5) + TLV length: 27 + Flags: 0x00 + 0... .... = Flags-IP: Not set + .000 000. = Flags-reserved: 0x00 + .... ...0 = Flags-Unknown: Not set + Reserved1: 00 + Vlan ID: 741 + Reserved2: 00000000 + IP addr: 0.0.0.0 (0.0.0.0) + Name: Third VLAN Null - Marker 0x99, length 4, type 0 = Null - TLV Marker: 0x99 - TLV type: Null (0) - TLV length: 4 + Marker 0x99, length 4, type 0 = Null + TLV Marker: 0x99 + TLV type: Null (0) + TLV length: 4 */ - char pkt1[] = { - 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, - 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa, - 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00, - 0x00, 0x4a, 0xde, 0x20, 0x00, 0x02, 0x00, 0x00, - 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01, - 0x00, 0x12, 0x46, 0x69, 0x72, 0x73, 0x74, 0x20, - 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00, - 0x99, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 }; + char pkt1[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, 0x8e, 0xe7, + 0x84, 0xad, 0x00, 0x52, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, + 0x01, 0x00, 0x00, 0x4a, 0xde, 0x20, 0x00, 0x02, 0x00, 0x00, 0x5e, 0x10, + 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x01, 0x00, 0x12, 0x46, 0x69, 0x72, 0x73, + 0x74, 0x20, 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00, 0x99, 0x02, + 0x00, 0x24, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x07, 0x06, 0x04, 0x63, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, + 0x00, 0x04 }; - char pkt2[] = { - 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, - 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x6e, 0xaa, 0xaa, - 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00, - 0x00, 0x66, 0x28, 0xc4, 0x00, 0x03, 0x00, 0x00, - 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x05, - 0x00, 0x1b, 0x00, 0x00, 0x00, 0x9d, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x69, - 0x72, 0x73, 0x74, 0x20, 0x56, 0x4c, 0x41, 0x4e, - 0x00, 0x99, 0x05, 0x00, 0x1c, 0x00, 0x00, 0x04, - 0xdf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, - 0x56, 0x4c, 0x41, 0x4e, 0x00, 0x99, 0x05, 0x00, - 0x1b, 0x00, 0x00, 0x02, 0xe5, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x68, 0x69, - 0x72, 0x64, 0x20, 0x56, 0x4c, 0x41, 0x4e, 0x00, - 0x99, 0x00, 0x00, 0x04 }; + char pkt2[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x5e, 0x10, 0x8e, 0xe7, + 0x84, 0xad, 0x00, 0x6e, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, + 0x01, 0x00, 0x00, 0x66, 0x28, 0xc4, 0x00, 0x03, 0x00, 0x00, 0x5e, 0x10, + 0x8e, 0xe7, 0x84, 0xad, 0x99, 0x05, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x9d, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x69, 0x72, 0x73, + 0x74, 0x20, 0x56, 0x4c, 0x41, 0x4e, 0x00, 0x99, 0x05, 0x00, 0x1c, 0x00, + 0x00, 0x04, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, + 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x56, 0x4c, 0x41, 0x4e, 0x00, 0x99, + 0x05, 0x00, 0x1b, 0x00, 0x00, 0x02, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x54, 0x68, 0x69, 0x72, 0x64, 0x20, 0x56, 0x4c, 0x41, + 0x4e, 0x00, 0x99, 0x00, 0x00, 0x04 }; struct packet *pkt; struct lldpd_vlan vlan1, vlan2, vlan3; @@ -258,9 +244,12 @@ Extreme Discovery Protocol chassis.c_id = macaddress; chassis.c_id_len = ETHER_ADDR_LEN; chassis.c_name = "First chassis"; - vlan1.v_name = "First VLAN"; vlan1.v_vid = 157; - vlan2.v_name = "Second VLAN"; vlan2.v_vid = 1247; - vlan3.v_name = "Third VLAN"; vlan3.v_vid = 741; + vlan1.v_name = "First VLAN"; + vlan1.v_vid = 157; + vlan2.v_name = "Second VLAN"; + vlan2.v_vid = 1247; + vlan3.v_name = "Third VLAN"; + vlan3.v_vid = 741; TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan1, v_entries); TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan2, v_entries); TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan3, v_entries); @@ -288,56 +277,41 @@ Extreme Discovery Protocol fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than two packets sent"); } END_TEST -#endif +# endif -START_TEST (test_recv_edp) +START_TEST(test_recv_edp) { - char pkt1[] = { - 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04, - 0x96, 0x05, 0x44, 0x6f, 0x01, 0x44, 0xaa, 0xaa, - 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00, - 0x01, 0x3c, 0x05, 0xdf, 0x03, 0x0f, 0x00, 0x00, - 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f, 0x99, 0x02, - 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, - 0x04, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x99, 0x01, 0x01, 0x04, 0x6e, 0x65, - 0x30, 0x35, 0x30, 0x31, 0x73, 0x77, 0x2e, 0x58, - 0x58, 0x58, 0x58, 0x58, 0x58, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x03, 0x7b, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x79, 0x0d, 0xec, 0xff, 0xff, - 0xff, 0xff, 0x80, 0xa7, 0x8b, 0x24, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x17, 0x08, 0x7e, 0xe5, 0xe2, - 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0x00, 0x00, - 0x00, 0x02, 0x81, 0xb2, 0x19, 0xf0, 0x00, 0x00, - 0x00, 0x02, 0x80, 0xa5, 0x67, 0x20, 0xee, 0xee, - 0xee, 0xee, 0x80, 0xea, 0x8c, 0xac, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0xa4, 0x86, 0x2c, 0xee, 0xee, - 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, - 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0x00, 0x00, - 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0x00, 0xe0, - 0x2b, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, - 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, - 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0x99, 0x00, - 0x00, 0x04 }; + char pkt1[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04, 0x96, 0x05, + 0x44, 0x6f, 0x01, 0x44, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, + 0x01, 0x00, 0x01, 0x3c, 0x05, 0xdf, 0x03, 0x0f, 0x00, 0x00, 0x00, 0x04, + 0x96, 0x05, 0x44, 0x6f, 0x99, 0x02, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, 0x04, 0x00, + 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x99, 0x01, 0x01, 0x04, 0x6e, 0x65, 0x30, 0x35, + 0x30, 0x31, 0x73, 0x77, 0x2e, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x03, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x79, 0x0d, 0xec, + 0xff, 0xff, 0xff, 0xff, 0x80, 0xa7, 0x8b, 0x24, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x17, 0x08, 0x7e, 0xe5, 0xe2, 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, + 0x00, 0x00, 0x00, 0x02, 0x81, 0xb2, 0x19, 0xf0, 0x00, 0x00, 0x00, 0x02, + 0x80, 0xa5, 0x67, 0x20, 0xee, 0xee, 0xee, 0xee, 0x80, 0xea, 0x8c, 0xac, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x2b, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xa4, 0x86, 0x2c, + 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, + 0xee, 0xee, 0xee, 0xee, 0x00, 0x00, 0x00, 0x00, 0xee, 0xee, 0xee, 0xee, + 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, + 0x99, 0x00, 0x00, 0x04 }; /* This is: -IEEE 802.3 Ethernet +IEEE 802.3 Ethernet Destination: Extreme-EDP (00:e0:2b:00:00:00) Source: ExtremeN_05:44:6f (00:04:96:05:44:6f) Length: 324 @@ -347,8 +321,8 @@ Logical-Link Control SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) - 000. 00.. = Command: Unnumbered Information (0x00) - .... ..11 = Frame type: Unnumbered frame (0x03) + 000. 00.. = Command: Unnumbered Information (0x00) + .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Extreme Networks (0x00e02b) PID: EDP (0x00bb) Extreme Discovery Protocol @@ -356,87 +330,72 @@ Extreme Discovery Protocol Reserved: 0 Data length: 316 Checksum: 0xdf05 [correct] - [Good: True] - [Bad : False] + [Good: True] + [Bad : False] Sequence number: 783 Machine ID type: MAC (0) Machine MAC: ExtremeN_05:44:6f (00:04:96:05:44:6f) Info: Slot/Port: 1/1, Version: 7.6.4.0 - Marker 0x99, length 36, type 2 = Info - TLV Marker: 0x99 - TLV type: Info (2) - TLV length: 36 - Slot: 1 - Port: 1 - Virt chassis: 0 - Reserved: 000000000000 - Version: 7.6.4 Internal: 0 - Version: 0x07060400 - Version (major1): 7 - Version (major2): 6 - Version (sustaining): 4 - Version (internal): 0 - Connections: FFFF0000000000000000000000000000 + Marker 0x99, length 36, type 2 = Info + TLV Marker: 0x99 + TLV type: Info (2) + TLV length: 36 + Slot: 1 + Port: 1 + Virt chassis: 0 + Reserved: 000000000000 + Version: 7.6.4 Internal: 0 + Version: 0x07060400 + Version (major1): 7 + Version (major2): 6 + Version (sustaining): 4 + Version (internal): 0 + Connections: FFFF0000000000000000000000000000 Display: "ne0501sw.XXXXXX" - Marker 0x99, length 260, type 1 = Display - TLV Marker: 0x99 - TLV type: Display (1) - TLV length: 260 - Name: ne0501sw.XXXXXX + Marker 0x99, length 260, type 1 = Display + TLV Marker: 0x99 + TLV type: Display (1) + TLV length: 260 + Name: ne0501sw.XXXXXX Null - Marker 0x99, length 4, type 0 = Null - TLV Marker: 0x99 - TLV type: Null (0) - TLV length: 4 + Marker 0x99, length 4, type 0 = Null + TLV Marker: 0x99 + TLV type: Null (0) + TLV length: 4 */ -#ifdef ENABLE_DOT1 - char pkt2[] = { - 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04, - 0x96, 0x05, 0x44, 0x6f, 0x01, 0x48, 0xaa, 0xaa, - 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, 0x01, 0x00, - 0x01, 0x40, 0x73, 0x04, 0x03, 0x10, 0x00, 0x00, - 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f, 0x99, 0x05, - 0x00, 0x64, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x65, - 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00, 0x43, 0x61, - 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x61, 0x76, - 0x65, 0x20, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, - 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, - 0x20, 0x74, 0x6f, 0x20, 0x6e, 0x76, 0x20, 0x28, - 0x25, 0x64, 0x29, 0x0a, 0x00, 0x00, 0x4e, 0x6f, - 0x20, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x20, - 0x66, 0x6f, 0x72, 0x20, 0x73, 0x75, 0x70, 0x65, - 0x72, 0x42, 0x72, 0x69, 0x64, 0x67, 0x65, 0x49, - 0x6e, 0x73, 0x74, 0x20, 0x25, 0x64, 0x00, 0x00, - 0x00, 0x00, 0x99, 0x05, 0x00, 0x64, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x4d, 0x61, 0x63, 0x56, 0x6c, 0x61, - 0x6e, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, - 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0x05, - 0x00, 0x64, 0x80, 0x00, 0x00, 0x32, 0x00, 0x00, - 0x00, 0x00, 0x0a, 0x32, 0x00, 0x3f, 0x41, 0x64, - 0x6d, 0x69, 0x6e, 0x42, 0x32, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 }; +# ifdef ENABLE_DOT1 + char pkt2[] = { 0x00, 0xe0, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x04, 0x96, 0x05, + 0x44, 0x6f, 0x01, 0x48, 0xaa, 0xaa, 0x03, 0x00, 0xe0, 0x2b, 0x00, 0xbb, + 0x01, 0x00, 0x01, 0x40, 0x73, 0x04, 0x03, 0x10, 0x00, 0x00, 0x00, 0x04, + 0x96, 0x05, 0x44, 0x6f, 0x99, 0x05, 0x00, 0x64, 0x80, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x65, 0x66, 0x61, + 0x75, 0x6c, 0x74, 0x00, 0x43, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x73, + 0x61, 0x76, 0x65, 0x20, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x20, 0x64, + 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x6e, 0x76, + 0x20, 0x28, 0x25, 0x64, 0x29, 0x0a, 0x00, 0x00, 0x4e, 0x6f, 0x20, 0x62, + 0x72, 0x69, 0x64, 0x67, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x73, 0x75, + 0x70, 0x65, 0x72, 0x42, 0x72, 0x69, 0x64, 0x67, 0x65, 0x49, 0x6e, 0x73, + 0x74, 0x20, 0x25, 0x64, 0x00, 0x00, 0x00, 0x00, 0x99, 0x05, 0x00, 0x64, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4d, 0x61, 0x63, 0x56, 0x6c, 0x61, 0x6e, 0x44, 0x69, 0x73, 0x63, 0x6f, + 0x76, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x99, 0x05, 0x00, 0x64, 0x80, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, + 0x0a, 0x32, 0x00, 0x3f, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x42, 0x32, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x04 }; /* This is: -IEEE 802.3 Ethernet +IEEE 802.3 Ethernet Destination: Extreme-EDP (00:e0:2b:00:00:00) Source: ExtremeN_05:44:6f (00:04:96:05:44:6f) Length: 328 @@ -446,8 +405,8 @@ Logical-Link Control SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) - 000. 00.. = Command: Unnumbered Information (0x00) - .... ..11 = Frame type: Unnumbered frame (0x03) + 000. 00.. = Command: Unnumbered Information (0x00) + .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Extreme Networks (0x00e02b) PID: EDP (0x00bb) Extreme Discovery Protocol @@ -455,97 +414,95 @@ Extreme Discovery Protocol Reserved: 0 Data length: 320 Checksum: 0x7304 [correct] - [Good: True] - [Bad : False] + [Good: True] + [Bad : False] Sequence number: 784 Machine ID type: MAC (0) Machine MAC: ExtremeN_05:44:6f (00:04:96:05:44:6f) Vlan: ID 1, Name "Default" - Marker 0x99, length 100, type 5 = VL - TLV Marker: 0x99 - TLV type: VL (5) - TLV length: 100 - Flags: 0x80 - 1... .... = Flags-IP: Set - .000 000. = Flags-reserved: 0x00 - .... ...0 = Flags-Unknown: Not set - Reserved1: 00 - Vlan ID: 1 - Reserved2: 00000000 - IP addr: 0.0.0.0 (0.0.0.0) - Name: Default + Marker 0x99, length 100, type 5 = VL + TLV Marker: 0x99 + TLV type: VL (5) + TLV length: 100 + Flags: 0x80 + 1... .... = Flags-IP: Set + .000 000. = Flags-reserved: 0x00 + .... ...0 = Flags-Unknown: Not set + Reserved1: 00 + Vlan ID: 1 + Reserved2: 00000000 + IP addr: 0.0.0.0 (0.0.0.0) + Name: Default Vlan: ID 0, Name "MacVlanDiscover" - Marker 0x99, length 100, type 5 = VL - TLV Marker: 0x99 - TLV type: VL (5) - TLV length: 100 - Flags: 0x00 - 0... .... = Flags-IP: Not set - .000 000. = Flags-reserved: 0x00 - .... ...0 = Flags-Unknown: Not set - Reserved1: 00 - Vlan ID: 0 - Reserved2: 00000000 - IP addr: 0.0.0.0 (0.0.0.0) - Name: MacVlanDiscover + Marker 0x99, length 100, type 5 = VL + TLV Marker: 0x99 + TLV type: VL (5) + TLV length: 100 + Flags: 0x00 + 0... .... = Flags-IP: Not set + .000 000. = Flags-reserved: 0x00 + .... ...0 = Flags-Unknown: Not set + Reserved1: 00 + Vlan ID: 0 + Reserved2: 00000000 + IP addr: 0.0.0.0 (0.0.0.0) + Name: MacVlanDiscover Vlan: ID 50, Name "AdminB2" - Marker 0x99, length 100, type 5 = VL - TLV Marker: 0x99 - TLV type: VL (5) - TLV length: 100 - Flags: 0x80 - 1... .... = Flags-IP: Set - .000 000. = Flags-reserved: 0x00 - .... ...0 = Flags-Unknown: Not set - Reserved1: 00 - Vlan ID: 50 - Reserved2: 00000000 - IP addr: 10.50.0.63 (10.50.0.63) - Name: AdminB2 + Marker 0x99, length 100, type 5 = VL + TLV Marker: 0x99 + TLV type: VL (5) + TLV length: 100 + Flags: 0x80 + 1... .... = Flags-IP: Set + .000 000. = Flags-reserved: 0x00 + .... ...0 = Flags-Unknown: Not set + Reserved1: 00 + Vlan ID: 50 + Reserved2: 00000000 + IP addr: 10.50.0.63 (10.50.0.63) + Name: AdminB2 Null - Marker 0x99, length 4, type 0 = Null - TLV Marker: 0x99 - TLV type: Null (0) - TLV length: 4 + Marker 0x99, length 4, type 0 = Null + TLV Marker: 0x99 + TLV type: Null (0) + TLV length: 4 */ struct lldpd_vlan *vlan; -#endif +# endif struct lldpd_chassis *nchassis = NULL; struct lldpd_port *nport = NULL; struct lldpd cfg; char mac1[] = { 0x00, 0x04, 0x96, 0x05, 0x44, 0x6f }; cfg.g_config.c_mgmt_pattern = NULL; - fail_unless(edp_decode(&cfg, pkt1, sizeof(pkt1), &hardware, - &nchassis, &nport) != -1); + fail_unless( + edp_decode(&cfg, pkt1, sizeof(pkt1), &hardware, &nchassis, &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; } - ck_assert_int_eq(nchassis->c_id_subtype, - LLDP_CHASSISID_SUBTYPE_LLADDR); + ck_assert_int_eq(nchassis->c_id_subtype, LLDP_CHASSISID_SUBTYPE_LLADDR); ck_assert_int_eq(nchassis->c_id_len, ETHER_ADDR_LEN); fail_unless(memcmp(nchassis->c_id, mac1, ETHER_ADDR_LEN) == 0); - ck_assert_int_eq(nport->p_id_subtype, - LLDP_PORTID_SUBTYPE_IFNAME); + ck_assert_int_eq(nport->p_id_subtype, LLDP_PORTID_SUBTYPE_IFNAME); ck_assert_int_eq(nport->p_id_len, strlen("1/1")); - fail_unless(memcmp(nport->p_id, - "1/1", strlen("1/1")) == 0); + fail_unless(memcmp(nport->p_id, "1/1", strlen("1/1")) == 0); ck_assert_str_eq(nport->p_descr, "Slot 1 / Port 1"); ck_assert_str_eq(nchassis->c_name, "ne0501sw.XXXXXX"); ck_assert_str_eq(nchassis->c_descr, "EDP enabled device, version 7.6.4.0"); ck_assert_int_eq(nchassis->c_cap_enabled, 0); -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 /* Add this port to list of remote port for hardware port */ TAILQ_INSERT_TAIL(&hardware.h_rports, nport, p_entries); nport->p_chassis = nchassis; nport->p_protocol = LLDPD_MODE_EDP; /* Recept second packet */ - nchassis = NULL; nport = NULL; - fail_unless(edp_decode(&cfg, pkt2, sizeof(pkt2), &hardware, - &nchassis, &nport) == -1); + nchassis = NULL; + nport = NULL; + fail_unless( + edp_decode(&cfg, pkt2, sizeof(pkt2), &hardware, &nchassis, &nport) == -1); nport = TAILQ_FIRST(&hardware.h_rports); if (!nport) { fail("unable to find our previous port?"); @@ -576,7 +533,7 @@ Extreme Discovery Protocol ck_assert_str_eq(vlan->v_name, "AdminB2"); vlan = TAILQ_NEXT(vlan, v_entries); fail_unless(vlan == NULL); -#endif +# endif } END_TEST @@ -593,9 +550,9 @@ edp_suite(void) tcase_add_checked_fixture(tc_send, pcap_setup, pcap_teardown); tcase_add_test(tc_send, test_send_basic); -#ifdef ENABLE_DOT1 +# ifdef ENABLE_DOT1 tcase_add_test(tc_send, test_send_vlans); -#endif +# endif suite_add_tcase(s, tc_send); tcase_add_test(tc_receive, test_recv_edp); @@ -609,13 +566,13 @@ int main() { int number_failed; - Suite *s = edp_suite (); - SRunner *sr = srunner_create (s); - srunner_set_fork_status (sr, CK_NOFORK); /* Can't fork because - we need to write - files */ - srunner_run_all (sr, CK_ENV); - number_failed = srunner_ntests_failed (sr); - srunner_free (sr); + Suite *s = edp_suite(); + SRunner *sr = srunner_create(s); + srunner_set_fork_status(sr, CK_NOFORK); /* Can't fork because + we need to write + files */ + srunner_run_all(sr, CK_ENV); + number_failed = srunner_ntests_failed(sr); + srunner_free(sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/check_fixedpoint.c b/tests/check_fixedpoint.c index db889bba..74bfd1e8 100644 --- a/tests/check_fixedpoint.c +++ b/tests/check_fixedpoint.c @@ -22,7 +22,8 @@ #ifdef ENABLE_LLDPMED -START_TEST(test_string_parsing_suffix) { +START_TEST(test_string_parsing_suffix) +{ char *end; fp_strtofp("4541T", &end, 14, 8); ck_assert_int_eq(*end, 'T'); @@ -33,7 +34,8 @@ START_TEST(test_string_parsing_suffix) { } END_TEST -START_TEST(test_string_parsing_positive_int) { +START_TEST(test_string_parsing_positive_int) +{ struct fp_number fp = fp_strtofp("4541T", NULL, 14, 8); ck_assert_int_eq(fp.integer.bits, 14); ck_assert_int_eq(fp.integer.value, 4541); @@ -43,7 +45,8 @@ START_TEST(test_string_parsing_positive_int) { } END_TEST -START_TEST(test_string_parsing_negative_int) { +START_TEST(test_string_parsing_negative_int) +{ struct fp_number fp = fp_strtofp("-4214N", NULL, 14, 8); ck_assert_int_eq(fp.integer.bits, 14); ck_assert_int_eq(fp.integer.value, -4214); @@ -53,7 +56,8 @@ START_TEST(test_string_parsing_negative_int) { } END_TEST -START_TEST(test_string_parsing_positive_int_overflow) { +START_TEST(test_string_parsing_positive_int_overflow) +{ struct fp_number fp1 = fp_strtofp("4098", NULL, 13, 8); struct fp_number fp2 = fp_strtofp("4096", NULL, 13, 8); struct fp_number fp3 = fp_strtofp("4095", NULL, 13, 8); @@ -65,7 +69,8 @@ START_TEST(test_string_parsing_positive_int_overflow) { } END_TEST -START_TEST(test_string_parsing_negative_int_overflow) { +START_TEST(test_string_parsing_negative_int_overflow) +{ struct fp_number fp1 = fp_strtofp("-4097", NULL, 13, 8); struct fp_number fp2 = fp_strtofp("-4096", NULL, 13, 8); struct fp_number fp3 = fp_strtofp("-4095", NULL, 13, 8); @@ -77,7 +82,8 @@ START_TEST(test_string_parsing_negative_int_overflow) { } END_TEST -START_TEST(test_string_parsing_positive_float) { +START_TEST(test_string_parsing_positive_float) +{ struct fp_number fp1 = fp_strtofp("1542.6250E", NULL, 13, 20); ck_assert_int_eq(fp1.integer.value, 1542); ck_assert_int_eq(fp1.fraction.precision, 14); @@ -90,7 +96,8 @@ START_TEST(test_string_parsing_positive_float) { } END_TEST -START_TEST(test_string_parsing_negative_float) { +START_TEST(test_string_parsing_negative_float) +{ struct fp_number fp = fp_strtofp("-11542.6250N", NULL, 15, 4); ck_assert_int_eq(fp.integer.value, -11542); ck_assert_int_eq(fp.fraction.precision, 4); @@ -98,7 +105,8 @@ START_TEST(test_string_parsing_negative_float) { } END_TEST -START_TEST(test_string_parsing_no_fract_part) { +START_TEST(test_string_parsing_no_fract_part) +{ struct fp_number fp = fp_strtofp("11542.", NULL, 15, 4); ck_assert_int_eq(fp.integer.value, 11542); ck_assert_int_eq(fp.fraction.value, 0); @@ -106,7 +114,8 @@ START_TEST(test_string_parsing_no_fract_part) { } END_TEST -START_TEST(test_string_parsing_no_int_part) { +START_TEST(test_string_parsing_no_int_part) +{ struct fp_number fp = fp_strtofp(".6250E", NULL, 13, 4); ck_assert_int_eq(fp.integer.value, 0); ck_assert_int_eq(fp.fraction.precision, 4); @@ -114,8 +123,8 @@ START_TEST(test_string_parsing_no_int_part) { } END_TEST - -START_TEST(test_string_representation_positive_int) { +START_TEST(test_string_representation_positive_int) +{ struct fp_number fp1 = fp_strtofp("214", NULL, 9, 9); struct fp_number fp2 = fp_strtofp("11178.0000", NULL, 15, 9); ck_assert_str_eq(fp_fptostr(fp1, NULL), "214"); @@ -124,7 +133,8 @@ START_TEST(test_string_representation_positive_int) { } END_TEST -START_TEST(test_string_representation_negative_int) { +START_TEST(test_string_representation_negative_int) +{ struct fp_number fp1 = fp_strtofp("-214", NULL, 9, 9); struct fp_number fp2 = fp_strtofp("-11178.0000", NULL, 15, 9); ck_assert_str_eq(fp_fptostr(fp1, NULL), "-214"); @@ -133,21 +143,24 @@ START_TEST(test_string_representation_negative_int) { } END_TEST -START_TEST(test_string_representation_positive_float) { +START_TEST(test_string_representation_positive_float) +{ struct fp_number fp = fp_strtofp("214.6250", NULL, 9, 20); ck_assert_str_eq(fp_fptostr(fp, NULL), "214.6250"); ck_assert_str_eq(fp_fptostr(fp, "ES"), "214.6250E"); } END_TEST -START_TEST(test_string_representation_positive_float_with_leading_zero) { +START_TEST(test_string_representation_positive_float_with_leading_zero) +{ struct fp_number fp = fp_strtofp("214.06250", NULL, 9, 24); ck_assert_str_eq(fp_fptostr(fp, NULL), "214.06250"); ck_assert_str_eq(fp_fptostr(fp, "ES"), "214.06250E"); } END_TEST -START_TEST(test_string_representation_negative_float) { +START_TEST(test_string_representation_negative_float) +{ struct fp_number fp1 = fp_strtofp("-214.625", NULL, 22, 10); struct fp_number fp2 = fp_strtofp("-415.5", NULL, 22, 4); ck_assert_str_eq(fp_fptostr(fp1, NULL), "-214.625"); @@ -156,7 +169,8 @@ START_TEST(test_string_representation_negative_float) { } END_TEST -START_TEST(test_buffer_representation_positive_float) { +START_TEST(test_buffer_representation_positive_float) +{ unsigned char buffer[5] = {}; unsigned char expected[] = { 0x21 << 2, 47 << 1, 0x68, 0x00, 0x00 }; /* 47.2031250 = 47 + 2**-3 + 2**-4 + 2**-6, precision = 9+24 */ @@ -166,7 +180,8 @@ START_TEST(test_buffer_representation_positive_float) { } END_TEST -START_TEST(test_buffer_representation_negative_float) { +START_TEST(test_buffer_representation_negative_float) +{ unsigned char buffer[5] = {}; unsigned char expected[] = { (0x21 << 2) | 3, 0xa1, 0x98, 0x00, 0x00 }; /* 47.2031250 = 000101111.0011010000000000000000000 */ @@ -178,7 +193,8 @@ START_TEST(test_buffer_representation_negative_float) { } END_TEST -START_TEST(test_buffer_representation_with_shift) { +START_TEST(test_buffer_representation_with_shift) +{ unsigned char buffer[] = { 0x77, 0xc6, 0x0, 0x0, 0x0, 0x0, 0xc7 }; unsigned char expected[] = { 0x77, 0xc8, 0x45, 0xe6, 0x80, 0x00, 0x07 }; struct fp_number fp = fp_strtofp("47.2031250", NULL, 9, 25); @@ -187,7 +203,8 @@ START_TEST(test_buffer_representation_with_shift) { } END_TEST -START_TEST(test_buffer_representation_altitude) { +START_TEST(test_buffer_representation_altitude) +{ unsigned char buffer[5] = {}; unsigned char expected[] = { (22 + 4) << 2, 0, 0, 14 << 4 | 1 << 3, 0 }; struct fp_number fp = fp_strtofp("14.5", NULL, 22, 8); @@ -196,7 +213,8 @@ START_TEST(test_buffer_representation_altitude) { } END_TEST -START_TEST(test_buffer_parsing_positive_float) { +START_TEST(test_buffer_parsing_positive_float) +{ unsigned char buffer[] = { 0x21 << 2, 47 << 1, 0x68, 0x00, 0x00 }; struct fp_number fp = fp_buftofp(buffer, 9, 25, 0); ck_assert_int_eq(fp.integer.value, 47); @@ -207,7 +225,8 @@ START_TEST(test_buffer_parsing_positive_float) { } END_TEST -START_TEST(test_buffer_parsing_negative_float) { +START_TEST(test_buffer_parsing_negative_float) +{ unsigned char buffer[] = { (0x21 << 2) | 3, 0xa1, 0x98, 0x00, 0x00 }; struct fp_number fp = fp_buftofp(buffer, 9, 25, 0); ck_assert_int_eq(fp.integer.value, -47); @@ -219,14 +238,16 @@ START_TEST(test_buffer_parsing_negative_float) { END_TEST /* This is some corner case */ -START_TEST(test_buffer_parsing_positive_float_2) { +START_TEST(test_buffer_parsing_positive_float_2) +{ unsigned char buffer[] = { 0x40, 0x9c, 0x80, 0x00, 0x00 }; struct fp_number fp = fp_buftofp(buffer, 9, 25, 0); ck_assert_int_eq(fp.integer.value, 78); } END_TEST -START_TEST(test_buffer_parsing_positive_float_with_shift) { +START_TEST(test_buffer_parsing_positive_float_with_shift) +{ unsigned char buffer[] = { 0x77, 0xc8, 0x45, 0xe6, 0x80, 0x00, 0x07 }; struct fp_number fp = fp_buftofp(buffer, 9, 25, 12); ck_assert_int_eq(fp.integer.value, 47); @@ -237,8 +258,10 @@ START_TEST(test_buffer_parsing_positive_float_with_shift) { } END_TEST -START_TEST(test_buffer_parsing_negative_float_with_shift) { - unsigned char buffer[] = { 0x00, 0xff, (0x21 << 2) | 3, 0xa1, 0x98, 0x00, 0x00 }; +START_TEST(test_buffer_parsing_negative_float_with_shift) +{ + unsigned char buffer[] = { 0x00, 0xff, (0x21 << 2) | 3, 0xa1, 0x98, 0x00, + 0x00 }; struct fp_number fp = fp_buftofp(buffer, 9, 25, 16); ck_assert_int_eq(fp.integer.value, -47); ck_assert_int_eq(fp.integer.bits, 9); @@ -248,7 +271,8 @@ START_TEST(test_buffer_parsing_negative_float_with_shift) { } END_TEST -START_TEST(test_negate_positive) { +START_TEST(test_negate_positive) +{ struct fp_number fp = fp_strtofp("14.5", NULL, 9, 25); struct fp_number nfp = fp_negate(fp); ck_assert_int_eq(nfp.integer.value, -14); @@ -257,7 +281,8 @@ START_TEST(test_negate_positive) { } END_TEST -START_TEST(test_negate_negative) { +START_TEST(test_negate_negative) +{ struct fp_number fp = fp_strtofp("-14.5", NULL, 9, 25); struct fp_number nfp = fp_negate(fp); ck_assert_int_eq(nfp.integer.value, 14); @@ -287,7 +312,8 @@ fixedpoint_suite(void) tcase_add_test(tc_fp, test_string_representation_positive_int); tcase_add_test(tc_fp, test_string_representation_negative_int); tcase_add_test(tc_fp, test_string_representation_positive_float); - tcase_add_test(tc_fp, test_string_representation_positive_float_with_leading_zero); + tcase_add_test(tc_fp, + test_string_representation_positive_float_with_leading_zero); tcase_add_test(tc_fp, test_string_representation_negative_float); tcase_add_test(tc_fp, test_buffer_representation_positive_float); tcase_add_test(tc_fp, test_buffer_representation_negative_float); @@ -307,7 +333,9 @@ fixedpoint_suite(void) } /* Disable leak detection sanitizer */ -int __lsan_is_turned_off() { +int +__lsan_is_turned_off() +{ return 1; } diff --git a/tests/check_lldp.c b/tests/check_lldp.c index 5c7f38a4..afdea70b 100644 --- a/tests/check_lldp.c +++ b/tests/check_lldp.c @@ -24,20 +24,19 @@ char filenameprefix[] = "lldp_send"; -static struct lldpd test_lldpd = { - .g_config = { - .c_cap_advertise = 1, /* Chassis capabilities advertisement */ - .c_mgmt_advertise = 1, /* Management addresses advertisement */ - } -}; +static struct lldpd test_lldpd = { .g_config = { + .c_cap_advertise = + 1, /* Chassis capabilities advertisement */ + .c_mgmt_advertise = + 1, /* Management addresses advertisement */ + } }; #define ck_assert_str_eq_n(X, Y, N) \ - ck_assert_msg(!strncmp(X, Y, N), "Assertion '"#X"=="#Y"' failed: "#X"==\"%s\", "#Y"==\"%s\"", X, Y) + ck_assert_msg(!strncmp(X, Y, N), \ + "Assertion '" #X "==" #Y "' failed: " #X "==\"%s\", " #Y "==\"%s\"", X, Y) static void -check_received_port( - struct lldpd_port *sport, - struct lldpd_port *rport) +check_received_port(struct lldpd_port *sport, struct lldpd_port *rport) { ck_assert_int_eq(rport->p_id_subtype, sport->p_id_subtype); ck_assert_int_eq(rport->p_id_len, sport->p_id_len); @@ -49,9 +48,7 @@ check_received_port( } static void -check_received_chassis( - struct lldpd_chassis *schassis, - struct lldpd_chassis *rchassis) +check_received_chassis(struct lldpd_chassis *schassis, struct lldpd_chassis *rchassis) { ck_assert_int_eq(rchassis->c_id_subtype, schassis->c_id_subtype); ck_assert_int_eq(rchassis->c_id_len, schassis->c_id_len); @@ -64,52 +61,40 @@ check_received_chassis( #ifdef ENABLE_LLDPMED static void -check_received_port_med( - struct lldpd_port *sport, - struct lldpd_port *rport) +check_received_port_med(struct lldpd_port *sport, struct lldpd_port *rport) { ck_assert_int_eq(rport->p_med_cap_enabled, sport->p_med_cap_enabled); ck_assert_int_eq(rport->p_med_cap_enabled, sport->p_med_cap_enabled); + ck_assert_int_eq(rport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC - 1].format, + sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC - 1].format); + ck_assert_int_eq(rport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC - 1].data_len, + sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC - 1].data_len); + ck_assert_str_eq_n(rport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC - 1].data, + sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC - 1].data, + sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC - 1].data_len); + ck_assert_int_eq(rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].type, + sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].type); ck_assert_int_eq( - rport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].format, - sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].format); - ck_assert_int_eq( - rport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data_len, - sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data_len); - ck_assert_str_eq_n( - rport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data, - sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data, - sport->p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data_len); - ck_assert_int_eq( - rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].type, - sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].type); - ck_assert_int_eq( - rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].tagged, - sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].tagged); + rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].tagged, + sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].tagged); + ck_assert_int_eq(rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].vid, + sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].vid); ck_assert_int_eq( - rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].vid, - sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].vid); - ck_assert_int_eq( - rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].priority, - sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].priority); - ck_assert_int_eq( - rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].dscp, - sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].dscp); - ck_assert_int_eq( - rport->p_med_power.devicetype, sport->p_med_power.devicetype); + rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].priority, + sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].priority); + ck_assert_int_eq(rport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].dscp, + sport->p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].dscp); + ck_assert_int_eq(rport->p_med_power.devicetype, sport->p_med_power.devicetype); ck_assert_int_eq(rport->p_med_power.source, sport->p_med_power.source); - ck_assert_int_eq(rport->p_med_power.priority, - sport->p_med_power.priority); + ck_assert_int_eq(rport->p_med_power.priority, sport->p_med_power.priority); ck_assert_int_eq(rport->p_med_power.val, sport->p_med_power.val); } static void -check_received_chassis_med( - struct lldpd_chassis *schassis, - struct lldpd_chassis *rchassis) +check_received_chassis_med(struct lldpd_chassis *schassis, + struct lldpd_chassis *rchassis) { - ck_assert_int_eq(rchassis->c_med_cap_available, - schassis->c_med_cap_available); + ck_assert_int_eq(rchassis->c_med_cap_available, schassis->c_med_cap_available); ck_assert_int_eq(rchassis->c_med_type, schassis->c_med_type); ck_assert_str_eq(rchassis->c_med_hw, schassis->c_med_hw); ck_assert_str_eq(rchassis->c_med_fw, schassis->c_med_fw); @@ -120,22 +105,20 @@ check_received_chassis_med( #ifdef ENABLE_DOT3 static void -check_received_port_dot3( - struct lldpd_port *sport, - struct lldpd_port *rport) +check_received_port_dot3(struct lldpd_port *sport, struct lldpd_port *rport) { ck_assert_int_eq(rport->p_aggregid, sport->p_aggregid); ck_assert_int_eq(rport->p_macphy.autoneg_support, - sport->p_macphy.autoneg_support); + sport->p_macphy.autoneg_support); ck_assert_int_eq(rport->p_macphy.autoneg_enabled, - sport->p_macphy.autoneg_enabled); + sport->p_macphy.autoneg_enabled); ck_assert_int_eq(rport->p_macphy.autoneg_advertised, - sport->p_macphy.autoneg_advertised); + sport->p_macphy.autoneg_advertised); ck_assert_int_eq(rport->p_macphy.mau_type, sport->p_macphy.mau_type); } #endif -START_TEST (test_send_rcv_basic) +START_TEST(test_send_rcv_basic) { int n; struct packet *pkt; @@ -169,8 +152,8 @@ START_TEST (test_send_rcv_basic) fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent"); /* decode the retrieved packet calling lldp_decode() */ - fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware, - &nchassis, &nport) != -1); + fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware, &nchassis, + &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; @@ -184,7 +167,7 @@ END_TEST #define ETHERTYPE_OFFSET 2 * ETHER_ADDR_LEN #define VLAN_TAG_SIZE 2 -START_TEST (test_send_rcv_vlan_tx) +START_TEST(test_send_rcv_vlan_tx) { int n; struct packet *pkt; @@ -204,9 +187,8 @@ START_TEST (test_send_rcv_vlan_tx) hardware.h_lport.p_mfs = 1516; /* Assembly VLAN tag: Priority(3bits) | DEI(1bit) | VID(12bits) */ - vlan_tag = ((vlan_prio & 0x7) << 13) | - ((vlan_dei & 0x1) << 12) | - (vlan_id & 0xfff); + vlan_tag = + ((vlan_prio & 0x7) << 13) | ((vlan_dei & 0x1) << 12) | (vlan_id & 0xfff); hardware.h_lport.p_vlan_tx_tag = vlan_tag; hardware.h_lport.p_vlan_tx_enabled = 1; chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; @@ -230,23 +212,25 @@ START_TEST (test_send_rcv_vlan_tx) fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent"); /* Check ETHER_TYPE, should be VLAN */ - memcpy(&tmp, (unsigned char*) pkt->data + ETHERTYPE_OFFSET, ETHER_TYPE_LEN); - ck_assert_uint_eq(ntohl(tmp)>>16, ETHERTYPE_VLAN); + memcpy(&tmp, (unsigned char *)pkt->data + ETHERTYPE_OFFSET, ETHER_TYPE_LEN); + ck_assert_uint_eq(ntohl(tmp) >> 16, ETHERTYPE_VLAN); /* Check VLAN tag */ - memcpy(&tmp, (unsigned char*) pkt->data + ETHERTYPE_OFFSET + ETHER_TYPE_LEN, VLAN_TAG_SIZE); - ck_assert_uint_eq(ntohl(tmp)>>16, vlan_tag); + memcpy(&tmp, (unsigned char *)pkt->data + ETHERTYPE_OFFSET + ETHER_TYPE_LEN, + VLAN_TAG_SIZE); + ck_assert_uint_eq(ntohl(tmp) >> 16, vlan_tag); /* Remove VLAN ethertype and VLAN tag */ - memmove((unsigned char*) pkt->data + ETHERTYPE_OFFSET, - /* move all after VLAN tag */ - (unsigned char*) pkt->data + ETHERTYPE_OFFSET + ETHER_TYPE_LEN + VLAN_TAG_SIZE, - /* size without src and dst MAC, VLAN tag */ - pkt->size - (ETHERTYPE_OFFSET + ETHER_TYPE_LEN + VLAN_TAG_SIZE)); + memmove((unsigned char *)pkt->data + ETHERTYPE_OFFSET, + /* move all after VLAN tag */ + (unsigned char *)pkt->data + ETHERTYPE_OFFSET + ETHER_TYPE_LEN + + VLAN_TAG_SIZE, + /* size without src and dst MAC, VLAN tag */ + pkt->size - (ETHERTYPE_OFFSET + ETHER_TYPE_LEN + VLAN_TAG_SIZE)); /* Decode the packet without VLAN tag, calling lldp_decode() */ - fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware, - &nchassis, &nport) != -1); + fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware, &nchassis, + &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; @@ -260,10 +244,10 @@ START_TEST (test_send_rcv_vlan_tx) END_TEST #ifdef ENABLE_DOT1 -/* This test case tests send and receive of all DOT1 TLVs(2005 and 2009): +/* This test case tests send and receive of all DOT1 TLVs(2005 and 2009): Port Valn ID, VLAN, Port Protocol VLAN ID, Protocol Identity, VID Usage Digest, Management VID, and 802.1ax Link Aggregation TLVs */ -START_TEST (test_send_rcv_dot1_tlvs) +START_TEST(test_send_rcv_dot1_tlvs) { int n; struct lldpd_vlan *rvlan, vlan1, vlan2, vlan3; @@ -287,9 +271,12 @@ START_TEST (test_send_rcv_dot1_tlvs) chassis.c_descr = "Chassis description"; chassis.c_cap_available = LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE; chassis.c_cap_enabled = LLDP_CAP_ROUTER; - vlan1.v_name = "Voice"; vlan1.v_vid = 157; - vlan2.v_name = "Data"; vlan2.v_vid = 1247; - vlan3.v_name = "Control"; vlan3.v_vid = 741; + vlan1.v_name = "Voice"; + vlan1.v_vid = 157; + vlan2.v_name = "Data"; + vlan2.v_vid = 1247; + vlan3.v_name = "Control"; + vlan3.v_vid = 741; TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan1, v_entries); TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan2, v_entries); TAILQ_INSERT_TAIL(&hardware.h_lport.p_vlans, &vlan3, v_entries); @@ -317,8 +304,8 @@ START_TEST (test_send_rcv_dot1_tlvs) fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent"); /* decode the retrieved packet calling lldp_decode() */ - fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware, - &nchassis, &nport) != -1); + fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware, &nchassis, + &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; @@ -366,7 +353,7 @@ START_TEST (test_send_rcv_dot1_tlvs) rppvid = TAILQ_FIRST(&nport->p_ppvids); ck_assert_int_eq(rppvid->p_cap_status, ppvid.p_cap_status); ck_assert_int_eq(rppvid->p_ppvid, ppvid.p_ppvid); - + if (TAILQ_EMPTY(&nport->p_pids)) { fail("no Protocal Identity TLV"); return; @@ -390,7 +377,7 @@ END_TEST #endif #ifdef ENABLE_LLDPMED -START_TEST (test_send_rcv_med) +START_TEST(test_send_rcv_med) { int n; struct packet *pkt; @@ -411,29 +398,25 @@ START_TEST (test_send_rcv_med) chassis.c_cap_available = LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE; chassis.c_cap_enabled = LLDP_CAP_ROUTER; chassis.c_med_cap_available = LLDP_MED_CAP_CAP | LLDP_MED_CAP_POLICY | - LLDP_MED_CAP_LOCATION | LLDP_MED_CAP_MDI_PSE | - LLDP_MED_CAP_IV; + LLDP_MED_CAP_LOCATION | LLDP_MED_CAP_MDI_PSE | LLDP_MED_CAP_IV; chassis.c_med_type = LLDP_MED_CLASS_III; chassis.c_med_hw = "hardware rev 5"; chassis.c_med_fw = "47b5"; chassis.c_med_sw = "2.6.22b5"; chassis.c_med_sn = "SN 47842"; hardware.h_lport.p_med_cap_enabled = chassis.c_med_cap_available; - hardware.h_lport.p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].format = - LLDP_MED_LOCFORMAT_CIVIC; - hardware.h_lport.p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data = "Your favorite city"; - hardware.h_lport.p_med_location[LLDP_MED_LOCFORMAT_CIVIC-1].data_len = - sizeof("Your favorite city"); - hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].type = - LLDP_MED_APPTYPE_SOFTPHONEVOICE; - hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].tagged = - 1; - hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].vid = - 51; - hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].priority = - 6; - hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE-1].dscp = - 46; + hardware.h_lport.p_med_location[LLDP_MED_LOCFORMAT_CIVIC - 1].format = + LLDP_MED_LOCFORMAT_CIVIC; + hardware.h_lport.p_med_location[LLDP_MED_LOCFORMAT_CIVIC - 1].data = + "Your favorite city"; + hardware.h_lport.p_med_location[LLDP_MED_LOCFORMAT_CIVIC - 1].data_len = + sizeof("Your favorite city"); + hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].type = + LLDP_MED_APPTYPE_SOFTPHONEVOICE; + hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].tagged = 1; + hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].vid = 51; + hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].priority = 6; + hardware.h_lport.p_med_policy[LLDP_MED_APPTYPE_SOFTPHONEVOICE - 1].dscp = 46; hardware.h_lport.p_med_power.devicetype = LLDP_MED_POW_TYPE_PSE; hardware.h_lport.p_med_power.source = LLDP_MED_POW_SOURCE_PRIMARY; hardware.h_lport.p_med_power.priority = LLDP_MED_POW_PRIO_HIGH; @@ -453,8 +436,8 @@ START_TEST (test_send_rcv_med) fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent"); /* decode the retrieved packet calling lldp_decode() */ - fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware, - &nchassis, &nport) != -1); + fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware, &nchassis, + &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; @@ -472,7 +455,7 @@ END_TEST #endif #ifdef ENABLE_DOT3 -START_TEST (test_send_rcv_dot3) +START_TEST(test_send_rcv_dot3) { int n; struct lldpd_chassis *nchassis = NULL; @@ -489,15 +472,16 @@ START_TEST (test_send_rcv_dot3) hardware.h_lport.p_macphy.autoneg_support = 1; hardware.h_lport.p_macphy.autoneg_enabled = 1; hardware.h_lport.p_macphy.autoneg_advertised = LLDP_DOT3_LINK_AUTONEG_10BASE_T | - LLDP_DOT3_LINK_AUTONEG_10BASET_FD | LLDP_DOT3_LINK_AUTONEG_100BASE_TX | - LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD; + LLDP_DOT3_LINK_AUTONEG_10BASET_FD | LLDP_DOT3_LINK_AUTONEG_100BASE_TX | + LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD; hardware.h_lport.p_macphy.mau_type = LLDP_DOT3_MAU_100BASETXFD; chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; chassis.c_id = macaddress; chassis.c_id_len = ETHER_ADDR_LEN; chassis.c_name = "Fourth chassis"; chassis.c_descr = "Long chassis description"; - chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER | LLDP_CAP_WLAN; + chassis.c_cap_available = chassis.c_cap_enabled = + LLDP_CAP_ROUTER | LLDP_CAP_WLAN; /* Build packet */ n = lldp_send(&test_lldpd, &hardware); @@ -513,8 +497,8 @@ START_TEST (test_send_rcv_dot3) fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent"); /* decode the retrieved packet calling lldp_decode() */ - fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware, - &nchassis, &nport) != -1); + fail_unless(lldp_decode(NULL, pkt->data, pkt->size, &hardware, &nchassis, + &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; @@ -529,58 +513,51 @@ START_TEST (test_send_rcv_dot3) END_TEST #endif -START_TEST (test_recv_min) +START_TEST(test_recv_min) { - char pkt1[] = { - 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, 0x00, 0x17, - 0xd1, 0xa8, 0x35, 0xbe, 0x88, 0xcc, 0x02, 0x07, - 0x04, 0x00, 0x17, 0xd1, 0xa8, 0x35, 0xbf, 0x04, - 0x07, 0x03, 0x00, 0x17, 0xd1, 0xa8, 0x36, 0x02, - 0x06, 0x02, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 }; + char pkt1[] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, 0x00, 0x17, 0xd1, 0xa8, + 0x35, 0xbe, 0x88, 0xcc, 0x02, 0x07, 0x04, 0x00, 0x17, 0xd1, 0xa8, 0x35, + 0xbf, 0x04, 0x07, 0x03, 0x00, 0x17, 0xd1, 0xa8, 0x36, 0x02, 0x06, 0x02, + 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 }; /* This is: -Ethernet II, Src: Nortel_a8:35:be (00:17:d1:a8:35:be), Dst: LLDP_Multicast (01:80:c2:00:00:0e) - Destination: LLDP_Multicast (01:80:c2:00:00:0e) - Source: Nortel_a8:35:be (00:17:d1:a8:35:be) - Type: 802.1 Link Layer Discovery Protocol (LLDP) (0x88cc) -Link Layer Discovery Protocol - Chassis Subtype = MAC address - 0000 001. .... .... = TLV Type: Chassis Id (1) - .... ...0 0000 0111 = TLV Length: 7 - Chassis Id Subtype: MAC address (4) - Chassis Id: Nortel_a8:35:bf (00:17:d1:a8:35:bf) +Ethernet II, Src: Nortel_a8:35:be (00:17:d1:a8:35:be), Dst: LLDP_Multicast +(01:80:c2:00:00:0e) Destination: LLDP_Multicast (01:80:c2:00:00:0e) Source: +Nortel_a8:35:be (00:17:d1:a8:35:be) Type: 802.1 Link Layer Discovery Protocol (LLDP) +(0x88cc) Link Layer Discovery Protocol Chassis Subtype = MAC address 0000 001. .... .... += TLV Type: Chassis Id (1) + .... ...0 0000 0111 = TLV Length: 7 + Chassis Id Subtype: MAC address (4) + Chassis Id: Nortel_a8:35:bf (00:17:d1:a8:35:bf) Port Subtype = MAC address - 0000 010. .... .... = TLV Type: Port Id (2) - .... ...0 0000 0111 = TLV Length: 7 - Port Id Subtype: MAC address (3) - Port Id: Nortel_a8:36:02 (00:17:d1:a8:36:02) + 0000 010. .... .... = TLV Type: Port Id (2) + .... ...0 0000 0111 = TLV Length: 7 + Port Id Subtype: MAC address (3) + Port Id: Nortel_a8:36:02 (00:17:d1:a8:36:02) Time To Live = 120 sec - 0000 011. .... .... = TLV Type: Time to Live (3) - .... ...0 0000 0010 = TLV Length: 2 - Seconds: 120 + 0000 011. .... .... = TLV Type: Time to Live (3) + .... ...0 0000 0010 = TLV Length: 2 + Seconds: 120 End of LLDPDU - 0000 000. .... .... = TLV Type: End of LLDPDU (0) - .... ...0 0000 0000 = TLV Length: 0 + 0000 000. .... .... = TLV Type: End of LLDPDU (0) + .... ...0 0000 0000 = TLV Length: 0 */ struct lldpd_chassis *nchassis = NULL; struct lldpd_port *nport = NULL; char mac1[] = { 0x0, 0x17, 0xd1, 0xa8, 0x35, 0xbf }; char mac2[] = { 0x0, 0x17, 0xd1, 0xa8, 0x36, 0x02 }; - fail_unless(lldp_decode(NULL, pkt1, sizeof(pkt1), &hardware, - &nchassis, &nport) != -1); + fail_unless( + lldp_decode(NULL, pkt1, sizeof(pkt1), &hardware, &nchassis, &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; } - ck_assert_int_eq(nchassis->c_id_subtype, - LLDP_CHASSISID_SUBTYPE_LLADDR); + ck_assert_int_eq(nchassis->c_id_subtype, LLDP_CHASSISID_SUBTYPE_LLADDR); ck_assert_int_eq(nchassis->c_id_len, ETHER_ADDR_LEN); fail_unless(memcmp(mac1, nchassis->c_id, ETHER_ADDR_LEN) == 0); - ck_assert_int_eq(nport->p_id_subtype, - LLDP_PORTID_SUBTYPE_LLADDR); + ck_assert_int_eq(nport->p_id_subtype, LLDP_PORTID_SUBTYPE_LLADDR); ck_assert_int_eq(nport->p_id_len, ETHER_ADDR_LEN); fail_unless(memcmp(mac2, nport->p_id, ETHER_ADDR_LEN) == 0); ck_assert_ptr_eq(nchassis->c_name, NULL); @@ -590,202 +567,183 @@ Link Layer Discovery Protocol } END_TEST -START_TEST (test_recv_lldpd) +START_TEST(test_recv_lldpd) { /* This is a frame generated by lldpd */ - char pkt1[] = { - 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, 0x00, 0x16, - 0x17, 0x2f, 0xa1, 0xb6, 0x88, 0xcc, 0x02, 0x07, - 0x04, 0x00, 0x16, 0x17, 0x2f, 0xa1, 0xb6, 0x04, - 0x07, 0x03, 0x00, 0x16, 0x17, 0x2f, 0xa1, 0xb6, - 0x06, 0x02, 0x00, 0x78, 0x0a, 0x1a, 0x6e, 0x61, - 0x72, 0x75, 0x74, 0x6f, 0x2e, 0x58, 0x58, 0x58, - 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, - 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, - 0x0c, 0x3f, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x20, - 0x32, 0x2e, 0x36, 0x2e, 0x32, 0x39, 0x2d, 0x32, - 0x2d, 0x61, 0x6d, 0x64, 0x36, 0x34, 0x20, 0x23, - 0x31, 0x20, 0x53, 0x4d, 0x50, 0x20, 0x53, 0x75, - 0x6e, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x31, 0x37, - 0x20, 0x31, 0x37, 0x3a, 0x31, 0x35, 0x3a, 0x34, - 0x37, 0x20, 0x55, 0x54, 0x43, 0x20, 0x32, 0x30, - 0x30, 0x39, 0x20, 0x78, 0x38, 0x36, 0x5f, 0x36, - 0x34, 0x0e, 0x04, 0x00, 0x1c, 0x00, 0x14, 0x10, - 0x0c, 0x05, 0x01, 0x0a, 0xee, 0x50, 0x4b, 0x02, - 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x04, 0x65, - 0x74, 0x68, 0x30, 0xfe, 0x09, 0x00, 0x12, 0x0f, - 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x09, - 0x00, 0x12, 0x0f, 0x01, 0x03, 0x6c, 0x03, 0x00, - 0x10, 0xfe, 0x06, 0x00, 0x12, 0x0f, 0x04, 0x05, - 0xdc, 0xfe, 0x07, 0x00, 0x12, 0xbb, 0x01, 0x00, - 0x00, 0x00, 0xfe, 0x0f, 0x00, 0x12, 0xbb, 0x05, - 0x4e, 0x44, 0x39, 0x39, 0x31, 0x37, 0x38, 0x39, - 0x37, 0x30, 0x32, 0xfe, 0x0b, 0x00, 0x12, 0xbb, - 0x06, 0x30, 0x38, 0x30, 0x30, 0x31, 0x32, 0x20, - 0xfe, 0x12, 0x00, 0x12, 0xbb, 0x07, 0x32, 0x2e, - 0x36, 0x2e, 0x32, 0x39, 0x2d, 0x32, 0x2d, 0x61, - 0x6d, 0x64, 0x36, 0x34, 0xfe, 0x10, 0x00, 0x12, - 0xbb, 0x08, 0x31, 0x30, 0x35, 0x38, 0x32, 0x30, - 0x38, 0x35, 0x30, 0x30, 0x30, 0x39, 0xfe, 0x15, - 0x00, 0x12, 0xbb, 0x09, 0x4e, 0x45, 0x43, 0x20, - 0x43, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, - 0x73, 0x20, 0x53, 0x41, 0x53, 0xfe, 0x13, 0x00, - 0x12, 0xbb, 0x0a, 0x50, 0x4f, 0x57, 0x45, 0x52, - 0x4d, 0x41, 0x54, 0x45, 0x20, 0x56, 0x4c, 0x33, - 0x35, 0x30, 0xfe, 0x0d, 0x00, 0x12, 0xbb, 0x0b, - 0x31, 0x30, 0x30, 0x32, 0x30, 0x37, 0x31, 0x32, - 0x30, 0x00, 0x00 }; + char pkt1[] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, 0x00, 0x16, 0x17, 0x2f, + 0xa1, 0xb6, 0x88, 0xcc, 0x02, 0x07, 0x04, 0x00, 0x16, 0x17, 0x2f, 0xa1, + 0xb6, 0x04, 0x07, 0x03, 0x00, 0x16, 0x17, 0x2f, 0xa1, 0xb6, 0x06, 0x02, + 0x00, 0x78, 0x0a, 0x1a, 0x6e, 0x61, 0x72, 0x75, 0x74, 0x6f, 0x2e, 0x58, + 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, + 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x0c, 0x3f, 0x4c, 0x69, 0x6e, 0x75, + 0x78, 0x20, 0x32, 0x2e, 0x36, 0x2e, 0x32, 0x39, 0x2d, 0x32, 0x2d, 0x61, + 0x6d, 0x64, 0x36, 0x34, 0x20, 0x23, 0x31, 0x20, 0x53, 0x4d, 0x50, 0x20, + 0x53, 0x75, 0x6e, 0x20, 0x4d, 0x61, 0x79, 0x20, 0x31, 0x37, 0x20, 0x31, + 0x37, 0x3a, 0x31, 0x35, 0x3a, 0x34, 0x37, 0x20, 0x55, 0x54, 0x43, 0x20, + 0x32, 0x30, 0x30, 0x39, 0x20, 0x78, 0x38, 0x36, 0x5f, 0x36, 0x34, 0x0e, + 0x04, 0x00, 0x1c, 0x00, 0x14, 0x10, 0x0c, 0x05, 0x01, 0x0a, 0xee, 0x50, + 0x4b, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x04, 0x65, 0x74, 0x68, + 0x30, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, + 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x01, 0x03, 0x6c, 0x03, 0x00, 0x10, 0xfe, + 0x06, 0x00, 0x12, 0x0f, 0x04, 0x05, 0xdc, 0xfe, 0x07, 0x00, 0x12, 0xbb, + 0x01, 0x00, 0x00, 0x00, 0xfe, 0x0f, 0x00, 0x12, 0xbb, 0x05, 0x4e, 0x44, + 0x39, 0x39, 0x31, 0x37, 0x38, 0x39, 0x37, 0x30, 0x32, 0xfe, 0x0b, 0x00, + 0x12, 0xbb, 0x06, 0x30, 0x38, 0x30, 0x30, 0x31, 0x32, 0x20, 0xfe, 0x12, + 0x00, 0x12, 0xbb, 0x07, 0x32, 0x2e, 0x36, 0x2e, 0x32, 0x39, 0x2d, 0x32, + 0x2d, 0x61, 0x6d, 0x64, 0x36, 0x34, 0xfe, 0x10, 0x00, 0x12, 0xbb, 0x08, + 0x31, 0x30, 0x35, 0x38, 0x32, 0x30, 0x38, 0x35, 0x30, 0x30, 0x30, 0x39, + 0xfe, 0x15, 0x00, 0x12, 0xbb, 0x09, 0x4e, 0x45, 0x43, 0x20, 0x43, 0x6f, + 0x6d, 0x70, 0x75, 0x74, 0x65, 0x72, 0x73, 0x20, 0x53, 0x41, 0x53, 0xfe, + 0x13, 0x00, 0x12, 0xbb, 0x0a, 0x50, 0x4f, 0x57, 0x45, 0x52, 0x4d, 0x41, + 0x54, 0x45, 0x20, 0x56, 0x4c, 0x33, 0x35, 0x30, 0xfe, 0x0d, 0x00, 0x12, + 0xbb, 0x0b, 0x31, 0x30, 0x30, 0x32, 0x30, 0x37, 0x31, 0x32, 0x30, 0x00, + 0x00 }; /* This is: -Ethernet II, Src: Msi_2f:a1:b6 (00:16:17:2f:a1:b6), Dst: LLDP_Multicast (01:80:c2:00:00:0e) - Destination: LLDP_Multicast (01:80:c2:00:00:0e) - Source: Msi_2f:a1:b6 (00:16:17:2f:a1:b6) - Type: 802.1 Link Layer Discovery Protocol (LLDP) (0x88cc) -Link Layer Discovery Protocol - Chassis Subtype = MAC address - 0000 001. .... .... = TLV Type: Chassis Id (1) - .... ...0 0000 0111 = TLV Length: 7 - Chassis Id Subtype: MAC address (4) - Chassis Id: Msi_2f:a1:b6 (00:16:17:2f:a1:b6) +Ethernet II, Src: Msi_2f:a1:b6 (00:16:17:2f:a1:b6), Dst: LLDP_Multicast +(01:80:c2:00:00:0e) Destination: LLDP_Multicast (01:80:c2:00:00:0e) Source: Msi_2f:a1:b6 +(00:16:17:2f:a1:b6) Type: 802.1 Link Layer Discovery Protocol (LLDP) (0x88cc) Link Layer +Discovery Protocol Chassis Subtype = MAC address 0000 001. .... .... = TLV Type: Chassis +Id (1) + .... ...0 0000 0111 = TLV Length: 7 + Chassis Id Subtype: MAC address (4) + Chassis Id: Msi_2f:a1:b6 (00:16:17:2f:a1:b6) Port Subtype = MAC address - 0000 010. .... .... = TLV Type: Port Id (2) - .... ...0 0000 0111 = TLV Length: 7 - Port Id Subtype: MAC address (3) - Port Id: Msi_2f:a1:b6 (00:16:17:2f:a1:b6) + 0000 010. .... .... = TLV Type: Port Id (2) + .... ...0 0000 0111 = TLV Length: 7 + Port Id Subtype: MAC address (3) + Port Id: Msi_2f:a1:b6 (00:16:17:2f:a1:b6) Time To Live = 120 sec - 0000 011. .... .... = TLV Type: Time to Live (3) - .... ...0 0000 0010 = TLV Length: 2 - Seconds: 120 + 0000 011. .... .... = TLV Type: Time to Live (3) + .... ...0 0000 0010 = TLV Length: 2 + Seconds: 120 System Name = naruto.XXXXXXXXXXXXXXXXXXX - 0000 101. .... .... = TLV Type: System Name (5) - .... ...0 0001 1010 = TLV Length: 26 - System Name = naruto.bureau.b1.p.fti.net + 0000 101. .... .... = TLV Type: System Name (5) + .... ...0 0001 1010 = TLV Length: 26 + System Name = naruto.bureau.b1.p.fti.net System Description = Linux 2.6.29-2-amd64 #1 SMP Sun May 17 17:15:47 UTC 2009 x86_64 - 0000 110. .... .... = TLV Type: System Description (6) - .... ...0 0011 1111 = TLV Length: 63 - System Description = Linux 2.6.29-2-amd64 #1 SMP Sun May 17 17:15:47 UTC 2009 x86_64 - Capabilities - 0000 111. .... .... = TLV Type: System Capabilities (7) - .... ...0 0000 0100 = TLV Length: 4 - Capabilities: 0x001c - .... .... .... .1.. = Bridge - .... .... .... 1... = WLAN access point - .... .... ...1 .... = Router - Enabled Capabilities: 0x0014 - .... .... .... .1.. = Bridge - .... .... ...1 .... = Router + 0000 110. .... .... = TLV Type: System Description (6) + .... ...0 0011 1111 = TLV Length: 63 + System Description = Linux 2.6.29-2-amd64 #1 SMP Sun May 17 17:15:47 UTC 2009 +x86_64 Capabilities 0000 111. .... .... = TLV Type: System Capabilities (7) + .... ...0 0000 0100 = TLV Length: 4 + Capabilities: 0x001c + .... .... .... .1.. = Bridge + .... .... .... 1... = WLAN access point + .... .... ...1 .... = Router + Enabled Capabilities: 0x0014 + .... .... .... .1.. = Bridge + .... .... ...1 .... = Router Management Address - 0001 000. .... .... = TLV Type: Management Address (8) - .... ...0 0000 1100 = TLV Length: 12 - Address String Length: 5 - Address Subtype: IPv4 (1) - Management Address: 10.238.80.75 - Interface Subtype: ifIndex (2) - Interface Number: 3 - OID String Length: 0 + 0001 000. .... .... = TLV Type: Management Address (8) + .... ...0 0000 1100 = TLV Length: 12 + Address String Length: 5 + Address Subtype: IPv4 (1) + Management Address: 10.238.80.75 + Interface Subtype: ifIndex (2) + Interface Number: 3 + OID String Length: 0 Port Description = eth0 - 0000 100. .... .... = TLV Type: Port Description (4) - .... ...0 0000 0100 = TLV Length: 4 - Port Description: eth0 + 0000 100. .... .... = TLV Type: Port Description (4) + .... ...0 0000 0100 = TLV Length: 4 + Port Description: eth0 IEEE 802.3 - Link Aggregation - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0000 1001 = TLV Length: 9 - Organization Unique Code: IEEE 802.3 (0x00120f) - IEEE 802.3 Subtype: Link Aggregation (0x03) - Aggregation Status: 0x01 - .... ...1 = Aggregation Capability: Yes - .... ..0. = Aggregation Status: Not Enabled - Aggregated Port Id: 0 + 1111 111. .... .... = TLV Type: Organization Specific (127) + .... ...0 0000 1001 = TLV Length: 9 + Organization Unique Code: IEEE 802.3 (0x00120f) + IEEE 802.3 Subtype: Link Aggregation (0x03) + Aggregation Status: 0x01 + .... ...1 = Aggregation Capability: Yes + .... ..0. = Aggregation Status: Not Enabled + Aggregated Port Id: 0 IEEE 802.3 - MAC/PHY Configuration/Status - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0000 1001 = TLV Length: 9 - Organization Unique Code: IEEE 802.3 (0x00120f) - IEEE 802.3 Subtype: MAC/PHY Configuration/Status (0x01) - Auto-Negotiation Support/Status: 0x03 - .... ...1 = Auto-Negotiation: Supported - .... ..1. = Auto-Negotiation: Enabled - PMD Auto-Negotiation Advertised Capability: 0x6C03 - .... .... .... ...1 = 1000BASE-T (full duplex mode) - .... .... .... ..1. = 1000BASE-T (half duplex mode) - .... .1.. .... .... = 100BASE-TX (full duplex mode) - .... 1... .... .... = 100BASE-TX (half duplex mode) - ..1. .... .... .... = 10BASE-T (full duplex mode) - .1.. .... .... .... = 10BASE-T (half duplex mode) - Operational MAU Type: 100BaseTXFD - 2 pair category 5 UTP, full duplex mode (0x0010) - IEEE 802.3 - Maximum Frame Size - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0000 0110 = TLV Length: 6 - Organization Unique Code: IEEE 802.3 (0x00120f) - IEEE 802.3 Subtype: Maximum Frame Size (0x04) - Maximum Frame Size: 1500 + 1111 111. .... .... = TLV Type: Organization Specific (127) + .... ...0 0000 1001 = TLV Length: 9 + Organization Unique Code: IEEE 802.3 (0x00120f) + IEEE 802.3 Subtype: MAC/PHY Configuration/Status (0x01) + Auto-Negotiation Support/Status: 0x03 + .... ...1 = Auto-Negotiation: Supported + .... ..1. = Auto-Negotiation: Enabled + PMD Auto-Negotiation Advertised Capability: 0x6C03 + .... .... .... ...1 = 1000BASE-T (full duplex mode) + .... .... .... ..1. = 1000BASE-T (half duplex mode) + .... .1.. .... .... = 100BASE-TX (full duplex mode) + .... 1... .... .... = 100BASE-TX (half duplex mode) + ..1. .... .... .... = 10BASE-T (full duplex mode) + .1.. .... .... .... = 10BASE-T (half duplex mode) + Operational MAU Type: 100BaseTXFD - 2 pair category 5 UTP, full duplex mode +(0x0010) IEEE 802.3 - Maximum Frame Size 1111 111. .... .... = TLV Type: Organization +Specific (127) + .... ...0 0000 0110 = TLV Length: 6 + Organization Unique Code: IEEE 802.3 (0x00120f) + IEEE 802.3 Subtype: Maximum Frame Size (0x04) + Maximum Frame Size: 1500 TIA - Media Capabilities - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0000 0111 = TLV Length: 7 - Organization Unique Code: TIA (0x0012bb) - Media Subtype: Media Capabilities (0x01) - Capabilities: 0x0000 - Class Type: Type Not Defined + 1111 111. .... .... = TLV Type: Organization Specific (127) + .... ...0 0000 0111 = TLV Length: 7 + Organization Unique Code: TIA (0x0012bb) + Media Subtype: Media Capabilities (0x01) + Capabilities: 0x0000 + Class Type: Type Not Defined TIA - Inventory - Hardware Revision - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0000 1111 = TLV Length: 15 - Organization Unique Code: TIA (0x0012bb) - Media Subtype: Inventory - Hardware Revision (0x05) - Hardware Revision: ND991789702 + 1111 111. .... .... = TLV Type: Organization Specific (127) + .... ...0 0000 1111 = TLV Length: 15 + Organization Unique Code: TIA (0x0012bb) + Media Subtype: Inventory - Hardware Revision (0x05) + Hardware Revision: ND991789702 TIA - Inventory - Firmware Revision - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0000 1011 = TLV Length: 10 - Organization Unique Code: TIA (0x0012bb) - Media Subtype: Inventory - Firmware Revision (0x06) - Firmware Revision: 080012 + 1111 111. .... .... = TLV Type: Organization Specific (127) + .... ...0 0000 1011 = TLV Length: 10 + Organization Unique Code: TIA (0x0012bb) + Media Subtype: Inventory - Firmware Revision (0x06) + Firmware Revision: 080012 TIA - Inventory - Software Revision - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0001 0010 = TLV Length: 18 - Organization Unique Code: TIA (0x0012bb) - Media Subtype: Inventory - Software Revision (0x07) - Software Revision: 2.6.29-2-amd64 + 1111 111. .... .... = TLV Type: Organization Specific (127) + .... ...0 0001 0010 = TLV Length: 18 + Organization Unique Code: TIA (0x0012bb) + Media Subtype: Inventory - Software Revision (0x07) + Software Revision: 2.6.29-2-amd64 TIA - Inventory - Serial Number - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0001 0000 = TLV Length: 16 - Organization Unique Code: TIA (0x0012bb) - Media Subtype: Inventory - Serial Number (0x08) - Serial Number: 105820850009 + 1111 111. .... .... = TLV Type: Organization Specific (127) + .... ...0 0001 0000 = TLV Length: 16 + Organization Unique Code: TIA (0x0012bb) + Media Subtype: Inventory - Serial Number (0x08) + Serial Number: 105820850009 TIA - Inventory - Manufacturer Name - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0001 0101 = TLV Length: 21 - Organization Unique Code: TIA (0x0012bb) - Media Subtype: Inventory - Manufacturer Name (0x09) - Manufacturer Name: NEC Computers SAS + 1111 111. .... .... = TLV Type: Organization Specific (127) + .... ...0 0001 0101 = TLV Length: 21 + Organization Unique Code: TIA (0x0012bb) + Media Subtype: Inventory - Manufacturer Name (0x09) + Manufacturer Name: NEC Computers SAS TIA - Inventory - Model Name - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0001 0011 = TLV Length: 19 - Organization Unique Code: TIA (0x0012bb) - Media Subtype: Inventory - Model Name (0x0a) - Model Name: POWERMATE VL350 + 1111 111. .... .... = TLV Type: Organization Specific (127) + .... ...0 0001 0011 = TLV Length: 19 + Organization Unique Code: TIA (0x0012bb) + Media Subtype: Inventory - Model Name (0x0a) + Model Name: POWERMATE VL350 TIA - Inventory - Asset ID - 1111 111. .... .... = TLV Type: Organization Specific (127) - .... ...0 0000 1101 = TLV Length: 13 - Organization Unique Code: TIA (0x0012bb) - Media Subtype: Inventory - Asset ID (0x0b) - Asset ID: 100207120 + 1111 111. .... .... = TLV Type: Organization Specific (127) + .... ...0 0000 1101 = TLV Length: 13 + Organization Unique Code: TIA (0x0012bb) + Media Subtype: Inventory - Asset ID (0x0b) + Asset ID: 100207120 End of LLDPDU - 0000 000. .... .... = TLV Type: End of LLDPDU (0) - .... ...0 0000 0000 = TLV Length: 0 + 0000 000. .... .... = TLV Type: End of LLDPDU (0) + .... ...0 0000 0000 = TLV Length: 0 */ struct lldpd_chassis *nchassis = NULL; struct lldpd_port *nport = NULL; char mac1[] = { 0x00, 0x16, 0x17, 0x2f, 0xa1, 0xb6 }; - fail_unless(lldp_decode(NULL, pkt1, sizeof(pkt1), &hardware, - &nchassis, &nport) != -1); + fail_unless( + lldp_decode(NULL, pkt1, sizeof(pkt1), &hardware, &nchassis, &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; } - ck_assert_int_eq(nchassis->c_id_subtype, - LLDP_CHASSISID_SUBTYPE_LLADDR); + ck_assert_int_eq(nchassis->c_id_subtype, LLDP_CHASSISID_SUBTYPE_LLADDR); ck_assert_int_eq(nchassis->c_id_len, ETHER_ADDR_LEN); fail_unless(memcmp(mac1, nchassis->c_id, ETHER_ADDR_LEN) == 0); - ck_assert_int_eq(nport->p_id_subtype, - LLDP_PORTID_SUBTYPE_LLADDR); + ck_assert_int_eq(nport->p_id_subtype, LLDP_PORTID_SUBTYPE_LLADDR); ck_assert_int_eq(nport->p_id_len, ETHER_ADDR_LEN); fail_unless(memcmp(mac1, nport->p_id, ETHER_ADDR_LEN) == 0); ck_assert_int_eq(nport->p_ttl, 120); @@ -795,8 +753,7 @@ Link Layer Discovery Protocol ck_assert_str_eq(nport->p_descr, "eth0"); ck_assert_int_eq(nchassis->c_cap_available, LLDP_CAP_WLAN | LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE); - ck_assert_int_eq(nchassis->c_cap_enabled, - LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE); + ck_assert_int_eq(nchassis->c_cap_enabled, LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE); ck_assert_int_eq(nchassis->c_mgmt.tqh_first->m_addr.inet.s_addr, (u_int32_t)inet_addr("10.238.80.75")); ck_assert_int_eq(nchassis->c_mgmt.tqh_first->m_iface, 3); @@ -805,14 +762,11 @@ Link Layer Discovery Protocol ck_assert_int_eq(nport->p_macphy.autoneg_enabled, 1); ck_assert_int_eq(nport->p_macphy.autoneg_support, 1); ck_assert_int_eq(nport->p_macphy.autoneg_advertised, - LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD | - LLDP_DOT3_LINK_AUTONEG_1000BASE_T | - LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD | - LLDP_DOT3_LINK_AUTONEG_100BASE_TX | - LLDP_DOT3_LINK_AUTONEG_10BASET_FD | - LLDP_DOT3_LINK_AUTONEG_10BASE_T); - ck_assert_int_eq(nport->p_macphy.mau_type, - LLDP_DOT3_MAU_100BASETXFD); + LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD | LLDP_DOT3_LINK_AUTONEG_1000BASE_T | + LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD | + LLDP_DOT3_LINK_AUTONEG_100BASE_TX | LLDP_DOT3_LINK_AUTONEG_10BASET_FD | + LLDP_DOT3_LINK_AUTONEG_10BASE_T); + ck_assert_int_eq(nport->p_macphy.mau_type, LLDP_DOT3_MAU_100BASETXFD); ck_assert_int_eq(nport->p_mfs, 1500); #endif #ifdef ENABLE_LLDPMED @@ -869,13 +823,13 @@ int main() { int number_failed; - Suite *s = lldp_suite (); - SRunner *sr = srunner_create (s); - srunner_set_fork_status (sr, CK_NOFORK); /* Can't fork because - we need to write - files */ - srunner_run_all (sr, CK_ENV); - number_failed = srunner_ntests_failed (sr); - srunner_free (sr); + Suite *s = lldp_suite(); + SRunner *sr = srunner_create(s); + srunner_set_fork_status(sr, CK_NOFORK); /* Can't fork because + we need to write + files */ + srunner_run_all(sr, CK_ENV); + number_failed = srunner_ntests_failed(sr); + srunner_free(sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/check_marshal.c b/tests/check_marshal.c index 195078f8..2d808525 100644 --- a/tests/check_marshal.c +++ b/tests/check_marshal.c @@ -41,13 +41,14 @@ struct struct_simple { }; MARSHAL(struct_simple); -START_TEST(test_simple_structure) { +START_TEST(test_simple_structure) +{ struct struct_simple source = { .a1 = 78452, .a2 = 48751424, .a3 = 'h', .a4 = 784254, - .a5 = { 'A', 'B', 'C', 'D', 'E', 'F', 'G'}, + .a5 = { 'A', 'B', 'C', 'D', 'E', 'F', 'G' }, }; struct struct_simple *destination; void *buffer; @@ -84,7 +85,8 @@ MARSHAL_BEGIN(struct_sub) MARSHAL_SUBSTRUCT(struct_sub, struct_simple, e2) MARSHAL_END(struct_sub); -START_TEST(test_substruct_structure) { +START_TEST(test_substruct_structure) +{ struct struct_sub source = { .e1 = -5122, .e2 = { @@ -136,13 +138,14 @@ MARSHAL_BEGIN(struct_onepointer) MARSHAL_POINTER(struct_onepointer, struct_simple, b4) MARSHAL_END(struct_onepointer); -START_TEST(test_pointer_structure) { +START_TEST(test_pointer_structure) +{ struct struct_simple source_simple = { .a1 = 78452, .a2 = 48751424, .a3 = 'h', .a4 = 784254, - .a5 = { 'A', 'B', 'C', 'D', 'E', 'F', 'G'}, + .a5 = { 'A', 'B', 'C', 'D', 'E', 'F', 'G' }, }; struct struct_onepointer source = { .b1 = 18, @@ -179,7 +182,8 @@ START_TEST(test_pointer_structure) { ck_assert_int_eq(destination->b4->a5[5], 'F'); ck_assert_int_eq(destination->b4->a5[6], 'G'); ck_assert_int_eq(destination->b5, 333333); - free(destination->b4); free(destination); + free(destination->b4); + free(destination); } END_TEST @@ -195,20 +199,21 @@ MARSHAL_POINTER(struct_nestedpointers, struct_simple, c3) MARSHAL_POINTER(struct_nestedpointers, struct_onepointer, c4) MARSHAL_END(struct_nestedpointers); -START_TEST(test_several_pointers_structure) { +START_TEST(test_several_pointers_structure) +{ struct struct_simple source_simple1 = { .a1 = 78452, .a2 = 48751424, .a3 = 'h', .a4 = 784254, - .a5 = { 'A', 'B', 'C', 'D', 'E', 'F', 'G'}, + .a5 = { 'A', 'B', 'C', 'D', 'E', 'F', 'G' }, }; struct struct_simple source_simple2 = { .a1 = 451, .a2 = 451424, .a3 = 'o', .a4 = 74, - .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g'}, + .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' }, }; struct struct_onepointer source_onepointer = { .b1 = 18, @@ -262,19 +267,22 @@ START_TEST(test_several_pointers_structure) { ck_assert_int_eq(destination->c4->b4->a5[4], 'E'); ck_assert_int_eq(destination->c4->b4->a5[5], 'F'); ck_assert_int_eq(destination->c4->b4->a5[6], 'G'); - ck_assert_int_eq(destination->c4->b5, 333333); - free(destination->c3); free(destination->c4->b4); - free(destination->c4); free(destination); + ck_assert_int_eq(destination->c4->b5, 333333); + free(destination->c3); + free(destination->c4->b4); + free(destination->c4); + free(destination); } END_TEST -START_TEST(test_null_pointers) { +START_TEST(test_null_pointers) +{ struct struct_simple source_simple2 = { .a1 = 451, .a2 = 451424, .a3 = 'o', .a4 = 74, - .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g'}, + .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' }, }; struct struct_nestedpointers source = { .c1 = 4542, @@ -306,15 +314,16 @@ START_TEST(test_null_pointers) { ck_assert_int_eq(destination->c3->a5[4], 'e'); ck_assert_int_eq(destination->c3->a5[6], 'g'); ck_assert_ptr_eq(destination->c4, NULL); - free(destination->c3); free(destination); + free(destination->c3); + free(destination); } END_TEST struct struct_multipleref { int f1; - struct struct_simple* f2; - struct struct_simple* f3; - struct struct_nestedpointers* f4; + struct struct_simple *f2; + struct struct_simple *f3; + struct struct_nestedpointers *f4; }; MARSHAL_BEGIN(struct_multipleref) MARSHAL_POINTER(struct_multipleref, struct_simple, f2) @@ -322,13 +331,14 @@ MARSHAL_POINTER(struct_multipleref, struct_simple, f3) MARSHAL_POINTER(struct_multipleref, struct_nestedpointers, f4) MARSHAL_END(struct_multipleref); -START_TEST(test_multiple_references) { +START_TEST(test_multiple_references) +{ struct struct_simple source_simple = { .a1 = 451, .a2 = 451424, .a3 = 'o', .a4 = 74, - .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g'}, + .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' }, }; struct struct_nestedpointers source_nested = { .c3 = &source_simple, @@ -363,19 +373,22 @@ START_TEST(test_multiple_references) { ck_assert_int_eq(destination->f2->a3, 'o'); ck_assert_int_eq(destination->f2->a4, 74); ck_assert_ptr_eq(destination->f4->c4, NULL); - free(destination->f2); free(destination->f4); free(destination); + free(destination->f2); + free(destination->f4); + free(destination); } END_TEST struct struct_circularref { int g1; - struct struct_circularref* g2; + struct struct_circularref *g2; }; MARSHAL_BEGIN(struct_circularref) MARSHAL_POINTER(struct_circularref, struct_circularref, g2) MARSHAL_END(struct_circularref); -START_TEST(test_circular_references) { +START_TEST(test_circular_references) +{ struct struct_circularref source = { .g1 = 42, .g2 = &source, @@ -399,7 +412,8 @@ START_TEST(test_circular_references) { } END_TEST -START_TEST(test_too_small_unmarshal) { +START_TEST(test_too_small_unmarshal) +{ struct struct_simple source_simple1; struct struct_onepointer source_onepointer = { .b4 = &source_simple1, @@ -424,16 +438,19 @@ START_TEST(test_too_small_unmarshal) { /* Loop 30 times to ease debugging leaks with valgrind */ for (j = 0; j < 30; j++) { for (i = 0; i < len; i++) { - len2 = struct_nestedpointers_unserialize(buffer, 1, &destination); + len2 = + struct_nestedpointers_unserialize(buffer, 1, &destination); fail_unless(len2 == 0, - "Should not be able to deserialize, too small (%zu<%zu)", - i, len); + "Should not be able to deserialize, too small (%zu<%zu)", i, + len); } } len2 = struct_nestedpointers_unserialize(buffer, len + 5, &destination); fail_unless(len2 == len, "Deserialized too much"); free(destination->c3); - free(destination->c4); free(destination); free(buffer); + free(destination->c4); + free(destination); + free(buffer); log_register(NULL); } @@ -452,13 +469,14 @@ MARSHAL_END(struct_simpleentry); TAILQ_HEAD(list_simple, struct_simpleentry); MARSHAL_TQ(list_simple, struct_simpleentry); -START_TEST(test_simple_list) { +START_TEST(test_simple_list) +{ struct struct_simple source_simple = { .a1 = 451, .a2 = 451424, .a3 = 'o', .a4 = 74, - .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g'}, + .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' }, }; struct list_simple source; struct struct_simpleentry entry1 = { @@ -523,13 +541,14 @@ START_TEST(test_simple_list) { } END_TEST -START_TEST(test_simple_repaired_list) { +START_TEST(test_simple_repaired_list) +{ struct struct_simple source_simple = { .a1 = 451, .a2 = 451424, .a3 = 'o', .a4 = 74, - .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g'}, + .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' }, }; struct list_simple source; struct struct_simpleentry entry1 = { @@ -595,7 +614,8 @@ START_TEST(test_simple_repaired_list) { } END_TEST -START_TEST(test_empty_repaired_list) { +START_TEST(test_empty_repaired_list) +{ struct list_simple source; size_t len, len2; struct list_simple *destination; @@ -636,7 +656,8 @@ MARSHAL_BEGIN(struct_withlist) MARSHAL_SUBTQ(struct_withlist, struct_simpleentry, i2) MARSHAL_END(struct_withlist); -START_TEST(test_embedded_list) { +START_TEST(test_embedded_list) +{ struct struct_withlist source = { .i1 = 45424, .i3 = 4542, @@ -646,7 +667,7 @@ START_TEST(test_embedded_list) { .a2 = 451424, .a3 = 'o', .a4 = 74, - .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g'}, + .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' }, }; struct struct_simpleentry entry1 = { .g1 = 47, @@ -723,7 +744,8 @@ MARSHAL_STR(struct_string, s2) MARSHAL_STR(struct_string, s3) MARSHAL_END(struct_string); -START_TEST(test_string) { +START_TEST(test_string) +{ struct struct_string source = { .s1 = 44444, .s2 = "String 2", @@ -743,7 +765,8 @@ START_TEST(test_string) { ck_assert_int_eq(destination->s1, 44444); ck_assert_str_eq(destination->s2, "String 2"); ck_assert_str_eq(destination->s3, "String 3"); - free(destination->s2); free(destination->s3); + free(destination->s2); + free(destination->s3); free(destination); } END_TEST @@ -759,11 +782,12 @@ MARSHAL_FSTR(struct_fixedstring, s2, s2_len) MARSHAL_STR(struct_fixedstring, s3) MARSHAL_END(struct_fixedstring); -START_TEST(test_fixed_string) { +START_TEST(test_fixed_string) +{ struct struct_fixedstring source = { .s1 = 44444, .s2 = "String 2 Bla", - .s2_len = 8, /* Not 12! */ + .s2_len = 8, /* Not 12! */ .s3 = "String 3", }; struct struct_fixedstring *destination; @@ -785,9 +809,11 @@ START_TEST(test_fixed_string) { ck_assert_int_eq(destination->s2[5], 'g'); ck_assert_int_eq(destination->s2[6], ' '); ck_assert_int_eq(destination->s2[7], '2'); - ck_assert_int_eq(destination->s2[8], '\0'); /* fixed string are null-terminated too */ + ck_assert_int_eq(destination->s2[8], + '\0'); /* fixed string are null-terminated too */ ck_assert_str_eq(destination->s3, "String 3"); - free(destination->s2); free(destination->s3); + free(destination->s2); + free(destination->s3); free(destination); } END_TEST @@ -801,7 +827,8 @@ MARSHAL_BEGIN(struct_ignore) MARSHAL_IGNORE(struct_ignore, t2) MARSHAL_END(struct_ignore); -START_TEST(test_ignore) { +START_TEST(test_ignore) +{ struct struct_ignore source = { .t1 = 4544, .t2 = (void *)"String 2 Bla", @@ -825,13 +852,14 @@ START_TEST(test_ignore) { } END_TEST -START_TEST(test_equality) { +START_TEST(test_equality) +{ struct struct_simple source_simple1 = { .a1 = 451, .a2 = 451424, .a3 = 'o', .a4 = 74, - .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g'}, + .a5 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' }, }; struct struct_simpleentry entry1 = { .g1 = 47, @@ -850,8 +878,10 @@ START_TEST(test_equality) { fail_unless(len1 > 0, "Unable to serialize"); fail_unless(len2 > 0, "Unable to serialize"); ck_assert_int_eq(len1, len2); - fail_unless(!memcmp(buffer1, buffer2, len1), "Same content should give the same serialization"); - free(buffer1); free(buffer2); + fail_unless(!memcmp(buffer1, buffer2, len1), + "Same content should give the same serialization"); + free(buffer1); + free(buffer2); } END_TEST diff --git a/tests/check_pattern.c b/tests/check_pattern.c index 8d332deb..1ef33cf6 100644 --- a/tests/check_pattern.c +++ b/tests/check_pattern.c @@ -19,13 +19,15 @@ #include "../src/daemon/lldpd.h" -START_TEST(test_empty) { +START_TEST(test_empty) +{ ck_assert_int_eq(pattern_match("eth0", "", 0), 0); ck_assert_int_eq(pattern_match("eth0", "", 1), 1); } END_TEST -START_TEST(test_simple_match) { +START_TEST(test_simple_match) +{ ck_assert_int_eq(pattern_match("eth0", "eth0", 0), 2); ck_assert_int_eq(pattern_match("eth0", "eth0", 1), 2); ck_assert_int_eq(pattern_match("eth0", "eth1", 0), 0); @@ -33,7 +35,8 @@ START_TEST(test_simple_match) { } END_TEST -START_TEST(test_wildcard) { +START_TEST(test_wildcard) +{ ck_assert_int_eq(pattern_match("eth0", "eth*", 0), 1); ck_assert_int_eq(pattern_match("eth0", "eth*", 1), 1); ck_assert_int_eq(pattern_match("vlan0", "eth*", 0), 0); @@ -41,7 +44,8 @@ START_TEST(test_wildcard) { } END_TEST -START_TEST(test_match_list) { +START_TEST(test_match_list) +{ ck_assert_int_eq(pattern_match("eth0", "eth0,eth1,eth2", 0), 2); ck_assert_int_eq(pattern_match("eth1", "eth0,eth1,eth2", 0), 2); ck_assert_int_eq(pattern_match("eth3", "eth0,eth1,eth2", 0), 0); @@ -49,7 +53,8 @@ START_TEST(test_match_list) { } END_TEST -START_TEST(test_match_list_with_wildcards) { +START_TEST(test_match_list_with_wildcards) +{ ck_assert_int_eq(pattern_match("eth0", "eth0,eth*,eth2", 0), 2); ck_assert_int_eq(pattern_match("eth1", "eth0,eth*,eth2", 0), 1); ck_assert_int_eq(pattern_match("eth2", "eth0,eth*,eth2", 0), 2); @@ -59,7 +64,8 @@ START_TEST(test_match_list_with_wildcards) { } END_TEST -START_TEST(test_simple_denylist) { +START_TEST(test_simple_denylist) +{ ck_assert_int_eq(pattern_match("eth0", "!eth0", 0), 0); ck_assert_int_eq(pattern_match("eth0", "!eth0", 1), 0); ck_assert_int_eq(pattern_match("eth1", "!eth0", 0), 0); @@ -67,7 +73,8 @@ START_TEST(test_simple_denylist) { } END_TEST -START_TEST(test_match_and_denylist) { +START_TEST(test_match_and_denylist) +{ ck_assert_int_eq(pattern_match("eth0", "eth0,!eth0", 0), 0); ck_assert_int_eq(pattern_match("eth0", "eth0,!eth0", 1), 0); ck_assert_int_eq(pattern_match("eth1", "eth0,!eth0", 0), 0); @@ -75,7 +82,8 @@ START_TEST(test_match_and_denylist) { } END_TEST -START_TEST(test_denylist_wildcard) { +START_TEST(test_denylist_wildcard) +{ ck_assert_int_eq(pattern_match("eth0", "!eth*", 0), 0); ck_assert_int_eq(pattern_match("eth0", "!eth*", 1), 0); ck_assert_int_eq(pattern_match("eth1", "!eth*", 0), 0); @@ -87,7 +95,8 @@ START_TEST(test_denylist_wildcard) { } END_TEST -START_TEST(test_allowlist) { +START_TEST(test_allowlist) +{ ck_assert_int_eq(pattern_match("eth0", "!!eth0", 0), 2); ck_assert_int_eq(pattern_match("eth0", "!!eth0", 1), 2); ck_assert_int_eq(pattern_match("eth1", "!!eth0", 1), 1); diff --git a/tests/check_snmp.c b/tests/check_snmp.c index 3836ae5d..fb140979 100644 --- a/tests/check_snmp.c +++ b/tests/check_snmp.c @@ -30,81 +30,70 @@ extern struct timeval starttime; extern struct variable8 agent_lldp_vars[]; /* Our test config */ -struct lldpd test_cfg = { - .g_config = { - .c_tx_interval = 30000, - .c_tx_hold = 2, - .c_ttl = 60, - .c_smart = 0 - } -}; +struct lldpd test_cfg = { .g_config = { .c_tx_interval = 30000, + .c_tx_hold = 2, + .c_ttl = 60, + .c_smart = 0 } }; struct timeval test_starttime = { .tv_sec = 100, .tv_usec = 0 }; /* First chassis */ -struct lldpd_mgmt mgmt1 = { - .m_family = LLDPD_AF_IPV4, - .m_addr = { .octets = { 0xc0, 0, 0x2, 0xf } }, /* 192.0.2.15 */ - .m_addrsize = sizeof(struct in_addr), - .m_iface = 3 -}; +struct lldpd_mgmt mgmt1 = { .m_family = LLDPD_AF_IPV4, + .m_addr = { .octets = { 0xc0, 0, 0x2, 0xf } }, /* 192.0.2.15 */ + .m_addrsize = sizeof(struct in_addr), + .m_iface = 3 }; struct lldpd_chassis chassis1 = { - .c_index = 1, - .c_protocol = LLDPD_MODE_LLDP, - .c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR, - .c_id = "AAA012", - .c_id_len = 6, - .c_name = "chassis1.example.com", - .c_descr = "First chassis", + .c_index = 1, + .c_protocol = LLDPD_MODE_LLDP, + .c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR, + .c_id = "AAA012", + .c_id_len = 6, + .c_name = "chassis1.example.com", + .c_descr = "First chassis", .c_cap_available = LLDP_CAP_BRIDGE | LLDP_CAP_WLAN | LLDP_CAP_ROUTER, - .c_cap_enabled = LLDP_CAP_ROUTER, + .c_cap_enabled = LLDP_CAP_ROUTER, #ifdef ENABLE_LLDPMED - .c_med_cap_available = LLDP_MED_CAP_CAP | LLDP_MED_CAP_IV | \ - LLDP_MED_CAP_LOCATION | LLDP_MED_CAP_POLICY | \ - LLDP_MED_CAP_MDI_PSE | LLDP_MED_CAP_MDI_PD, - .c_med_type = LLDP_MED_CLASS_II, - .c_med_hw = "Hardware 1", + .c_med_cap_available = LLDP_MED_CAP_CAP | LLDP_MED_CAP_IV | + LLDP_MED_CAP_LOCATION | LLDP_MED_CAP_POLICY | LLDP_MED_CAP_MDI_PSE | + LLDP_MED_CAP_MDI_PD, + .c_med_type = LLDP_MED_CLASS_II, + .c_med_hw = "Hardware 1", /* We skip c_med_fw */ - .c_med_sw = "Software 1", - .c_med_sn = "00-00-0000-AAAA", - .c_med_manuf = "Manufacturer 1", - .c_med_model = "Model 1", - .c_med_asset = "Asset 1", + .c_med_sw = "Software 1", + .c_med_sn = "00-00-0000-AAAA", + .c_med_manuf = "Manufacturer 1", + .c_med_model = "Model 1", + .c_med_asset = "Asset 1", #endif }; /* Second chassis */ -struct lldpd_mgmt mgmt2 = { - .m_family = LLDPD_AF_IPV4, - .m_addr = { .octets = { 0xc0, 0, 0x2, 0x11 } }, /* 192.0.2.17 */ - .m_addrsize = sizeof(struct in_addr), - .m_iface = 5 -}; -struct lldpd_mgmt mgmt3 = { - .m_family = LLDPD_AF_IPV6, - .m_addr = { .octets = { 0x20, 0x01, 0x0d, 0xb8, - 0xca, 0xfe, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x17 } }, /* 2001:db8:cafe::17 */ - .m_addrsize = sizeof(struct in6_addr), - .m_iface = 5 -}; +struct lldpd_mgmt mgmt2 = { .m_family = LLDPD_AF_IPV4, + .m_addr = { .octets = { 0xc0, 0, 0x2, 0x11 } }, /* 192.0.2.17 */ + .m_addrsize = sizeof(struct in_addr), + .m_iface = 5 }; +struct lldpd_mgmt mgmt3 = { .m_family = LLDPD_AF_IPV6, + .m_addr = { .octets = { 0x20, 0x01, 0x0d, 0xb8, 0xca, 0xfe, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x17 } }, /* 2001:db8:cafe::17 */ + .m_addrsize = sizeof(struct in6_addr), + .m_iface = 5 }; struct lldpd_chassis chassis2 = { - .c_index = 4, - .c_protocol = LLDPD_MODE_LLDP, - .c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL, - .c_id = "chassis2", - .c_id_len = 6, - .c_name = "chassis2.example.com", - .c_descr = "Second chassis", + .c_index = 4, + .c_protocol = LLDPD_MODE_LLDP, + .c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL, + .c_id = "chassis2", + .c_id_len = 6, + .c_name = "chassis2.example.com", + .c_descr = "Second chassis", .c_cap_available = LLDP_CAP_ROUTER, - .c_cap_enabled = LLDP_CAP_ROUTER, + .c_cap_enabled = LLDP_CAP_ROUTER, #ifdef ENABLE_LLDPMED - .c_med_hw = "Hardware 2", + .c_med_hw = "Hardware 2", /* We skip c_med_fw */ - .c_med_sw = "Software 2", - .c_med_sn = "00-00-0000-AAAC", - .c_med_manuf = "Manufacturer 2", - .c_med_model = "Model 2", - .c_med_asset = "Asset 2", + .c_med_sw = "Software 2", + .c_med_sn = "00-00-0000-AAAC", + .c_med_manuf = "Manufacturer 2", + .c_med_model = "Model 2", + .c_med_asset = "Asset 2", #endif }; @@ -184,10 +173,10 @@ struct lldpd_hardware hardware1 = { .priority = LLDP_MED_POW_PRIO_HIGH, .val = 100 }, -#endif +#endif #ifdef ENABLE_DOT1 .p_pvid = 47, - /* Remaining is done is snmp_config */ +/* Remaining is done is snmp_config */ #endif } }; @@ -255,27 +244,27 @@ struct lldpd_hardware hardware2 = { struct lldpd_custom custom1 = { .oui = { 33, 44, 55 }, .subtype = 44, - .oui_info = (u_int8_t*)"OUI content", + .oui_info = (u_int8_t *)"OUI content", }; struct lldpd_custom custom2 = { .oui = { 33, 44, 55 }, .subtype = 44, - .oui_info = (u_int8_t*)"More content", + .oui_info = (u_int8_t *)"More content", }; struct lldpd_custom custom3 = { .oui = { 33, 44, 55 }, .subtype = 45, - .oui_info = (u_int8_t*)"More more content", + .oui_info = (u_int8_t *)"More more content", }; struct lldpd_custom custom4 = { .oui = { 33, 44, 56 }, .subtype = 44, - .oui_info = (u_int8_t*)"Even more content", + .oui_info = (u_int8_t *)"Even more content", }; struct lldpd_custom custom5 = { .oui = { 33, 44, 55 }, .subtype = 44, - .oui_info = (u_int8_t*)"Still more content", + .oui_info = (u_int8_t *)"Still more content", }; #endif @@ -312,13 +301,13 @@ struct lldpd_pi pi888e01 = { /* First port of second chassis */ struct lldpd_port port2 = { - .p_chassis = &chassis2, + .p_chassis = &chassis2, .p_lastchange = 180, - .p_protocol = LLDPD_MODE_LLDP, + .p_protocol = LLDPD_MODE_LLDP, .p_id_subtype = LLDP_PORTID_SUBTYPE_IFALIAS, - .p_id = "Giga1/7", - .p_id_len = 7, - .p_descr = "Gigabit Ethernet 1/7", + .p_id = "Giga1/7", + .p_id_len = 7, + .p_descr = "Gigabit Ethernet 1/7", }; void @@ -338,11 +327,11 @@ snmp_config() TAILQ_INSERT_TAIL(&test_cfg.g_hardware, &hardware1, h_entries); TAILQ_INSERT_TAIL(&test_cfg.g_hardware, &hardware2, h_entries); #ifdef ENABLE_CUSTOM - custom1.oui_info_len = strlen((char*)custom1.oui_info); - custom2.oui_info_len = strlen((char*)custom2.oui_info); - custom3.oui_info_len = strlen((char*)custom3.oui_info); - custom4.oui_info_len = strlen((char*)custom4.oui_info); - custom5.oui_info_len = strlen((char*)custom5.oui_info); + custom1.oui_info_len = strlen((char *)custom1.oui_info); + custom2.oui_info_len = strlen((char *)custom2.oui_info); + custom3.oui_info_len = strlen((char *)custom3.oui_info); + custom4.oui_info_len = strlen((char *)custom4.oui_info); + custom5.oui_info_len = strlen((char *)custom5.oui_info); TAILQ_INIT(&hardware1.h_lport.p_custom_list); TAILQ_INIT(&hardware2.h_lport.p_custom_list); TAILQ_INIT(&port2.p_custom_list); @@ -378,20 +367,22 @@ snmp_config() } /* Convert OID to a string. Static buffer. */ -char* +char * snmp_oidrepr(oid *name, size_t namelen) { - static char *buffer[4] = {NULL, NULL, NULL, NULL}; + static char *buffer[4] = { NULL, NULL, NULL, NULL }; static int current = 0; size_t i; - current = (current + 1)%4; - free(buffer[current]); buffer[current] = NULL; + current = (current + 1) % 4; + free(buffer[current]); + buffer[current] = NULL; for (i = 0; i < namelen; i++) { /* Not very efficient... */ char *newbuffer = NULL; - if (asprintf(&newbuffer, "%s.%lu", buffer[current]?buffer[current]:"", + if (asprintf(&newbuffer, "%s.%lu", + buffer[current] ? buffer[current] : "", (unsigned long)name[i]) == -1) { free(buffer[current]); buffer[current] = NULL; @@ -404,9 +395,9 @@ snmp_oidrepr(oid *name, size_t namelen) } struct tree_node { - oid name[MAX_OID_LEN]; + oid name[MAX_OID_LEN]; size_t namelen; - int type; /* ASN_* */ + int type; /* ASN_* */ union { unsigned long int integer; struct { @@ -416,501 +407,606 @@ struct tree_node { } value; }; -static oid zeroDotZero[2] = {0, 0}; -struct tree_node snmp_tree[] = { - { {1, 1, 1, 0}, 4, ASN_INTEGER, { .integer = 30 } }, /* lldpMessageTxInterval */ - { {1, 1, 2, 0}, 4, ASN_INTEGER, { .integer = 2 } }, /* lldpMessageTxHoldMultiplier */ - { {1, 1, 3, 0}, 4, ASN_INTEGER, { .integer = 1 } }, /* lldpReinitDelay */ - { {1, 1, 4, 0}, 4, ASN_INTEGER, { .integer = 1 } }, /* lldpTxDelay */ - { {1, 1, 5, 0}, 4, ASN_INTEGER, { .integer = 5 } }, /* lldpNotificationInterval */ - { {1, 2, 1, 0}, 4, ASN_TIMETICKS, { .integer = 10000 } },/* lldpStatsRemTablesLastChangeTime */ - { {1, 2, 2, 0}, 4, ASN_GAUGE, { .integer = 1100 } }, /* lldpStatsRemTablesInserts */ - { {1, 2, 3, 0}, 4, ASN_GAUGE, { .integer = 56 } }, /* lldpStatsRemTablesDeletes */ - { {1, 2, 4, 0}, 4, ASN_GAUGE, { .integer = 2 } }, /* lldpStatsRemTablesDrops */ - { {1, 2, 5, 0}, 4, ASN_GAUGE, { .integer = 230 } }, /* lldpStatsRemTablesAgeouts */ +static oid zeroDotZero[2] = { 0, 0 }; +struct tree_node snmp_tree[] = { { { 1, 1, 1, 0 }, 4, ASN_INTEGER, + { .integer = 30 } }, /* lldpMessageTxInterval */ + { { 1, 1, 2, 0 }, 4, ASN_INTEGER, + { .integer = 2 } }, /* lldpMessageTxHoldMultiplier */ + { { 1, 1, 3, 0 }, 4, ASN_INTEGER, { .integer = 1 } }, /* lldpReinitDelay */ + { { 1, 1, 4, 0 }, 4, ASN_INTEGER, { .integer = 1 } }, /* lldpTxDelay */ + { { 1, 1, 5, 0 }, 4, ASN_INTEGER, + { .integer = 5 } }, /* lldpNotificationInterval */ + { { 1, 2, 1, 0 }, 4, ASN_TIMETICKS, + { .integer = 10000 } }, /* lldpStatsRemTablesLastChangeTime */ + { { 1, 2, 2, 0 }, 4, ASN_GAUGE, + { .integer = 1100 } }, /* lldpStatsRemTablesInserts */ + { { 1, 2, 3, 0 }, 4, ASN_GAUGE, + { .integer = 56 } }, /* lldpStatsRemTablesDeletes */ + { { 1, 2, 4, 0 }, 4, ASN_GAUGE, + { .integer = 2 } }, /* lldpStatsRemTablesDrops */ + { { 1, 2, 5, 0 }, 4, ASN_GAUGE, + { .integer = 230 } }, /* lldpStatsRemTablesAgeouts */ - { {1, 2, 6, 1, 2, 3}, 6, ASN_COUNTER, { .integer = 1352 } }, /* lldpStatsTxPortFramesTotal.3 */ - { {1, 2, 6, 1, 2, 4}, 6, ASN_COUNTER, { .integer = 11352 } }, /* lldpStatsTxPortFramesTotal.4 */ - { {1, 2, 7, 1, 2, 3}, 6, ASN_COUNTER, { .integer = 5 } }, /* lldpStatsRxPortFramesDiscardedTotal.3 */ - { {1, 2, 7, 1, 2, 4}, 6, ASN_COUNTER, { .integer = 55 } }, /* lldpStatsRxPortFramesDiscardedTotal.4 */ - { {1, 2, 7, 1, 3, 3}, 6, ASN_COUNTER, { .integer = 5 } }, /* lldpStatsRxPortFramesError.3 */ - { {1, 2, 7, 1, 3, 4}, 6, ASN_COUNTER, { .integer = 55 } }, /* lldpStatsRxPortFramesError.4 */ - { {1, 2, 7, 1, 4, 3}, 6, ASN_COUNTER, { .integer = 1458 } }, /* lldpStatsRxPortFramesTotal.3 */ - { {1, 2, 7, 1, 4, 4}, 6, ASN_COUNTER, { .integer = 11458 } }, /* lldpStatsRxPortFramesTotal.4 */ - { {1, 2, 7, 1, 5, 3}, 6, ASN_COUNTER, { .integer = 4 } }, /* lldpStatsRxPortTLVsDiscardedTotal.3 */ - { {1, 2, 7, 1, 5, 4}, 6, ASN_COUNTER, { .integer = 14 } }, /* lldpStatsRxPortTLVsDiscardedTotal.4 */ - { {1, 2, 7, 1, 6, 3}, 6, ASN_COUNTER, { .integer = 4 } }, /* lldpStatsRxPortTLVsUnrecognizedTotal.3 */ - { {1, 2, 7, 1, 6, 4}, 6, ASN_COUNTER, { .integer = 14 } }, /* lldpStatsRxPortTLVsUnrecognizedTotal.4 */ - { {1, 2, 7, 1, 7, 3}, 6, ASN_GAUGE, { .integer = 20 } }, /* lldpStatsRxPortAgeoutsTotal.3 */ - { {1, 2, 7, 1, 7, 4}, 6, ASN_GAUGE, { .integer = 210 } }, /* lldpStatsRxPortAgeoutsTotal.4 */ + { { 1, 2, 6, 1, 2, 3 }, 6, ASN_COUNTER, + { .integer = 1352 } }, /* lldpStatsTxPortFramesTotal.3 */ + { { 1, 2, 6, 1, 2, 4 }, 6, ASN_COUNTER, + { .integer = 11352 } }, /* lldpStatsTxPortFramesTotal.4 */ + { { 1, 2, 7, 1, 2, 3 }, 6, ASN_COUNTER, + { .integer = 5 } }, /* lldpStatsRxPortFramesDiscardedTotal.3 */ + { { 1, 2, 7, 1, 2, 4 }, 6, ASN_COUNTER, + { .integer = 55 } }, /* lldpStatsRxPortFramesDiscardedTotal.4 */ + { { 1, 2, 7, 1, 3, 3 }, 6, ASN_COUNTER, + { .integer = 5 } }, /* lldpStatsRxPortFramesError.3 */ + { { 1, 2, 7, 1, 3, 4 }, 6, ASN_COUNTER, + { .integer = 55 } }, /* lldpStatsRxPortFramesError.4 */ + { { 1, 2, 7, 1, 4, 3 }, 6, ASN_COUNTER, + { .integer = 1458 } }, /* lldpStatsRxPortFramesTotal.3 */ + { { 1, 2, 7, 1, 4, 4 }, 6, ASN_COUNTER, + { .integer = 11458 } }, /* lldpStatsRxPortFramesTotal.4 */ + { { 1, 2, 7, 1, 5, 3 }, 6, ASN_COUNTER, + { .integer = 4 } }, /* lldpStatsRxPortTLVsDiscardedTotal.3 */ + { { 1, 2, 7, 1, 5, 4 }, 6, ASN_COUNTER, + { .integer = 14 } }, /* lldpStatsRxPortTLVsDiscardedTotal.4 */ + { { 1, 2, 7, 1, 6, 3 }, 6, ASN_COUNTER, + { .integer = 4 } }, /* lldpStatsRxPortTLVsUnrecognizedTotal.3 */ + { { 1, 2, 7, 1, 6, 4 }, 6, ASN_COUNTER, + { .integer = 14 } }, /* lldpStatsRxPortTLVsUnrecognizedTotal.4 */ + { { 1, 2, 7, 1, 7, 3 }, 6, ASN_GAUGE, + { .integer = 20 } }, /* lldpStatsRxPortAgeoutsTotal.3 */ + { { 1, 2, 7, 1, 7, 4 }, 6, ASN_GAUGE, + { .integer = 210 } }, /* lldpStatsRxPortAgeoutsTotal.4 */ - { {1, 3, 1, 0}, 4, ASN_INTEGER, { .integer = 4 } }, /* lldpLocChassisIdSubtype */ + { { 1, 3, 1, 0 }, 4, ASN_INTEGER, + { .integer = 4 } }, /* lldpLocChassisIdSubtype */ /* lldpLocChassisId */ - { {1, 3, 2, 0}, 4, ASN_OCTET_STR, { .string = { .octet = "AAA012", - .len = 6 } }}, + { { 1, 3, 2, 0 }, 4, ASN_OCTET_STR, + { .string = { .octet = "AAA012", .len = 6 } } }, /* lldpLocSysName */ - { {1, 3, 3, 0}, 4, ASN_OCTET_STR, { .string = { .octet = "chassis1.example.com", - .len = 20 } }}, + { { 1, 3, 3, 0 }, 4, ASN_OCTET_STR, + { .string = { .octet = "chassis1.example.com", .len = 20 } } }, /* lldpLocSysDesc */ - { {1, 3, 4, 0}, 4, ASN_OCTET_STR, { .string = { .octet = "First chassis", - .len = 13 } }}, + { { 1, 3, 4, 0 }, 4, ASN_OCTET_STR, + { .string = { .octet = "First chassis", .len = 13 } } }, /* lldpLocSysCapSupported */ - { {1, 3, 5, 0}, 4, ASN_OCTET_STR, { .string = { .octet = "\x38", - .len = 1 } }}, + { { 1, 3, 5, 0 }, 4, ASN_OCTET_STR, + { .string = { .octet = "\x38", .len = 1 } } }, /* lldpLocSysCapEnabled */ - { {1, 3, 6, 0}, 4, ASN_OCTET_STR, { .string = { .octet = "\x8", - .len = 1 } }}, + { { 1, 3, 6, 0 }, 4, ASN_OCTET_STR, + { .string = { .octet = "\x8", .len = 1 } } }, - { {1, 3, 7, 1, 2, 3}, 6, ASN_INTEGER, { .integer = 3 } }, /* lldpLocPortIdSubtype.3 */ - { {1, 3, 7, 1, 2, 4}, 6, ASN_INTEGER, { .integer = 5 } }, /* lldpLocPortIdSubtype.5 */ + { { 1, 3, 7, 1, 2, 3 }, 6, ASN_INTEGER, + { .integer = 3 } }, /* lldpLocPortIdSubtype.3 */ + { { 1, 3, 7, 1, 2, 4 }, 6, ASN_INTEGER, + { .integer = 5 } }, /* lldpLocPortIdSubtype.5 */ /* lldpLocPortId.3 */ - { {1, 3, 7, 1, 3, 3}, 6, ASN_OCTET_STR, { .string = { .octet = "AAA012", - .len = 6 } }}, + { { 1, 3, 7, 1, 3, 3 }, 6, ASN_OCTET_STR, + { .string = { .octet = "AAA012", .len = 6 } } }, /* lldpLocPortId.4 */ - { {1, 3, 7, 1, 3, 4}, 6, ASN_OCTET_STR, { .string = { .octet = "eth4", - .len = 4 } }}, + { { 1, 3, 7, 1, 3, 4 }, 6, ASN_OCTET_STR, + { .string = { .octet = "eth4", .len = 4 } } }, /* lldpLocPortDesc.3 */ - { {1, 3, 7, 1, 4, 3}, 6, ASN_OCTET_STR, { .string = { .octet = "eth2", - .len = 4 } }}, + { { 1, 3, 7, 1, 4, 3 }, 6, ASN_OCTET_STR, + { .string = { .octet = "eth2", .len = 4 } } }, /* lldpLocPortDesc.4 */ - { {1, 3, 7, 1, 4, 4}, 6, ASN_OCTET_STR, { .string = { .octet = "Intel 1000 GE", - .len = 13 } }}, + { { 1, 3, 7, 1, 4, 4 }, 6, ASN_OCTET_STR, + { .string = { .octet = "Intel 1000 GE", .len = 13 } } }, - { {1, 3, 8, 1, 3, 1, 4, 192, 0, 2, 15}, 11, ASN_INTEGER, { .integer = 5 } }, /* lldpLocManAddrLen */ - { {1, 3, 8, 1, 4, 1, 4, 192, 0, 2, 15}, 11, ASN_INTEGER, { .integer = 2 } }, /* lldpLocManAddrIfSubtype */ - { {1, 3, 8, 1, 5, 1, 4, 192, 0, 2, 15}, 11, ASN_INTEGER, { .integer = 3 } }, /* lldpLocManAddrIfId */ + { { 1, 3, 8, 1, 3, 1, 4, 192, 0, 2, 15 }, 11, ASN_INTEGER, + { .integer = 5 } }, /* lldpLocManAddrLen */ + { { 1, 3, 8, 1, 4, 1, 4, 192, 0, 2, 15 }, 11, ASN_INTEGER, + { .integer = 2 } }, /* lldpLocManAddrIfSubtype */ + { { 1, 3, 8, 1, 5, 1, 4, 192, 0, 2, 15 }, 11, ASN_INTEGER, + { .integer = 3 } }, /* lldpLocManAddrIfId */ /* lldpLocManAddrOID */ - { {1, 3, 8, 1, 6, 1, 4, 192, 0, 2, 15}, 11, ASN_OBJECT_ID, - { .string = { .octet = (char *)zeroDotZero, - .len = sizeof(zeroDotZero) }} }, + { { 1, 3, 8, 1, 6, 1, 4, 192, 0, 2, 15 }, 11, ASN_OBJECT_ID, + { .string = { .octet = (char *)zeroDotZero, + .len = sizeof(zeroDotZero) } } }, /* lldpRemChassisIdSubtype */ - { {1, 4, 1, 1, 4, 0, 3, 1 }, 8, ASN_INTEGER, { .integer = 4 } }, - { {1, 4, 1, 1, 4, 8000, 3, 4}, 8, ASN_INTEGER, { .integer = 7 } }, - { {1, 4, 1, 1, 4, 10000, 4, 1}, 8, ASN_INTEGER, { .integer = 4 } }, + { { 1, 4, 1, 1, 4, 0, 3, 1 }, 8, ASN_INTEGER, { .integer = 4 } }, + { { 1, 4, 1, 1, 4, 8000, 3, 4 }, 8, ASN_INTEGER, { .integer = 7 } }, + { { 1, 4, 1, 1, 4, 10000, 4, 1 }, 8, ASN_INTEGER, { .integer = 4 } }, /* lldpRemChassisId */ - { {1, 4, 1, 1, 5, 0, 3, 1 }, 8, ASN_OCTET_STR, { .string = { .octet = "AAA012", .len = 6 }} }, - { {1, 4, 1, 1, 5, 8000, 3, 4}, 8, ASN_OCTET_STR, { .string = - { .octet = "chassis2", - .len = 6 }} }, - { {1, 4, 1, 1, 5, 10000, 4, 1}, 8, ASN_OCTET_STR, { .string = { .octet = "AAA012", .len = 6 }} }, + { { 1, 4, 1, 1, 5, 0, 3, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "AAA012", .len = 6 } } }, + { { 1, 4, 1, 1, 5, 8000, 3, 4 }, 8, ASN_OCTET_STR, + { .string = { .octet = "chassis2", .len = 6 } } }, + { { 1, 4, 1, 1, 5, 10000, 4, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "AAA012", .len = 6 } } }, /* lldpRemPortIdSubtype */ - { {1, 4, 1, 1, 6, 0, 3, 1 }, 8, ASN_INTEGER, { .integer = 5 } }, - { {1, 4, 1, 1, 6, 8000, 3, 4}, 8, ASN_INTEGER, { .integer = 1 } }, - { {1, 4, 1, 1, 6, 10000, 4, 1}, 8, ASN_INTEGER, { .integer = 3 } }, + { { 1, 4, 1, 1, 6, 0, 3, 1 }, 8, ASN_INTEGER, { .integer = 5 } }, + { { 1, 4, 1, 1, 6, 8000, 3, 4 }, 8, ASN_INTEGER, { .integer = 1 } }, + { { 1, 4, 1, 1, 6, 10000, 4, 1 }, 8, ASN_INTEGER, { .integer = 3 } }, /* lldpRemPortId */ - { {1, 4, 1, 1, 7, 0, 3, 1 }, 8, ASN_OCTET_STR, { .string = { .octet = "eth4", .len = 4 }} }, - { {1, 4, 1, 1, 7, 8000, 3, 4}, 8, ASN_OCTET_STR, { .string = - { .octet = "Giga1/7", .len = 7 }} }, - { {1, 4, 1, 1, 7, 10000, 4, 1}, 8, ASN_OCTET_STR, { .string = { .octet = "AAA012", .len = 6 }} }, + { { 1, 4, 1, 1, 7, 0, 3, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "eth4", .len = 4 } } }, + { { 1, 4, 1, 1, 7, 8000, 3, 4 }, 8, ASN_OCTET_STR, + { .string = { .octet = "Giga1/7", .len = 7 } } }, + { { 1, 4, 1, 1, 7, 10000, 4, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "AAA012", .len = 6 } } }, /* lldpRemPortDesc */ - { {1, 4, 1, 1, 8, 0, 3, 1 }, 8, ASN_OCTET_STR, - { .string = { .octet = "Intel 1000 GE", .len = 13 }} }, - { {1, 4, 1, 1, 8, 8000, 3, 4}, 8, ASN_OCTET_STR, - { .string = { .octet = "Gigabit Ethernet 1/7", .len = 20 }} }, - { {1, 4, 1, 1, 8, 10000, 4, 1}, 8, ASN_OCTET_STR, - { .string = { .octet = "eth2", .len = 4 }} }, + { { 1, 4, 1, 1, 8, 0, 3, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "Intel 1000 GE", .len = 13 } } }, + { { 1, 4, 1, 1, 8, 8000, 3, 4 }, 8, ASN_OCTET_STR, + { .string = { .octet = "Gigabit Ethernet 1/7", .len = 20 } } }, + { { 1, 4, 1, 1, 8, 10000, 4, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "eth2", .len = 4 } } }, /* lldpRemSysName */ - { {1, 4, 1, 1, 9, 0, 3, 1 }, 8, ASN_OCTET_STR, - { .string = { .octet = "chassis1.example.com", .len = 20 }} }, - { {1, 4, 1, 1, 9, 8000, 3, 4}, 8, ASN_OCTET_STR, - { .string = { .octet = "chassis2.example.com", .len = 20 }} }, - { {1, 4, 1, 1, 9, 10000, 4, 1}, 8, ASN_OCTET_STR, - { .string = { .octet = "chassis1.example.com", .len = 20 }} }, + { { 1, 4, 1, 1, 9, 0, 3, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "chassis1.example.com", .len = 20 } } }, + { { 1, 4, 1, 1, 9, 8000, 3, 4 }, 8, ASN_OCTET_STR, + { .string = { .octet = "chassis2.example.com", .len = 20 } } }, + { { 1, 4, 1, 1, 9, 10000, 4, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "chassis1.example.com", .len = 20 } } }, /* lldpRemSysDesc */ - { {1, 4, 1, 1, 10, 0, 3, 1 }, 8, ASN_OCTET_STR, - { .string = { .octet = "First chassis", .len = 13 }} }, - { {1, 4, 1, 1, 10, 8000, 3, 4}, 8, ASN_OCTET_STR, - { .string = { .octet = "Second chassis", .len = 14 }} }, - { {1, 4, 1, 1, 10, 10000, 4, 1}, 8, ASN_OCTET_STR, - { .string = { .octet = "First chassis", .len = 13 }} }, + { { 1, 4, 1, 1, 10, 0, 3, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "First chassis", .len = 13 } } }, + { { 1, 4, 1, 1, 10, 8000, 3, 4 }, 8, ASN_OCTET_STR, + { .string = { .octet = "Second chassis", .len = 14 } } }, + { { 1, 4, 1, 1, 10, 10000, 4, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "First chassis", .len = 13 } } }, /* lldpRemSysCapSupported */ - { {1, 4, 1, 1, 11, 0, 3, 1 }, 8, ASN_OCTET_STR, - { .string = { .octet = "\x38", .len = 1 }} }, - { {1, 4, 1, 1, 11, 8000, 3, 4}, 8, ASN_OCTET_STR, - { .string = { .octet = "\x8", .len = 1 }} }, - { {1, 4, 1, 1, 11, 10000, 4, 1}, 8, ASN_OCTET_STR, - { .string = { .octet = "\x38", .len = 1 }} }, + { { 1, 4, 1, 1, 11, 0, 3, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "\x38", .len = 1 } } }, + { { 1, 4, 1, 1, 11, 8000, 3, 4 }, 8, ASN_OCTET_STR, + { .string = { .octet = "\x8", .len = 1 } } }, + { { 1, 4, 1, 1, 11, 10000, 4, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "\x38", .len = 1 } } }, /* lldpRemSysCapEnabled */ - { {1, 4, 1, 1, 12, 0, 3, 1 }, 8, ASN_OCTET_STR, - { .string = { .octet = "\x8", .len = 1 }} }, - { {1, 4, 1, 1, 12, 8000, 3, 4}, 8, ASN_OCTET_STR, - { .string = { .octet = "\x8", .len = 1 }} }, - { {1, 4, 1, 1, 12, 10000, 4, 1}, 8, ASN_OCTET_STR, - { .string = { .octet = "\x8", .len = 1 }} }, + { { 1, 4, 1, 1, 12, 0, 3, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "\x8", .len = 1 } } }, + { { 1, 4, 1, 1, 12, 8000, 3, 4 }, 8, ASN_OCTET_STR, + { .string = { .octet = "\x8", .len = 1 } } }, + { { 1, 4, 1, 1, 12, 10000, 4, 1 }, 8, ASN_OCTET_STR, + { .string = { .octet = "\x8", .len = 1 } } }, /* lldpRemManAddrIfSubtype */ - { {1, 4, 2, 1, 3, 0, 3, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_INTEGER, { .integer = 2 } }, - { {1, 4, 2, 1, 3, 8000, 3, 4, 1, 4, 192, 0, 2, 17 }, 14, ASN_INTEGER, { .integer = 2 } }, - { {1, 4, 2, 1, 3, 8000, 3, 4, 2, 16, - 0x20, 0x01, 0x0d, 0xb8, 0xca, 0xfe, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17 }, 26, ASN_INTEGER, { .integer = 2 } }, - { {1, 4, 2, 1, 3, 10000, 4, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_INTEGER, { .integer = 2 } }, + { { 1, 4, 2, 1, 3, 0, 3, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_INTEGER, + { .integer = 2 } }, + { { 1, 4, 2, 1, 3, 8000, 3, 4, 1, 4, 192, 0, 2, 17 }, 14, ASN_INTEGER, + { .integer = 2 } }, + { { 1, 4, 2, 1, 3, 8000, 3, 4, 2, 16, 0x20, 0x01, 0x0d, 0xb8, 0xca, 0xfe, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17 }, + 26, ASN_INTEGER, { .integer = 2 } }, + { { 1, 4, 2, 1, 3, 10000, 4, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_INTEGER, + { .integer = 2 } }, /* lldpRemManAddrIfId */ - { {1, 4, 2, 1, 4, 0, 3, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_INTEGER, { .integer = 3 } }, - { {1, 4, 2, 1, 4, 8000, 3, 4, 1, 4, 192, 0, 2, 17 }, 14, ASN_INTEGER, { .integer = 5 } }, - { {1, 4, 2, 1, 4, 8000, 3, 4, 2, 16, - 0x20, 0x01, 0x0d, 0xb8, 0xca, 0xfe, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17 }, 26, ASN_INTEGER, { .integer = 5 } }, - { {1, 4, 2, 1, 4, 10000, 4, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_INTEGER, { .integer = 3 } }, + { { 1, 4, 2, 1, 4, 0, 3, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_INTEGER, + { .integer = 3 } }, + { { 1, 4, 2, 1, 4, 8000, 3, 4, 1, 4, 192, 0, 2, 17 }, 14, ASN_INTEGER, + { .integer = 5 } }, + { { 1, 4, 2, 1, 4, 8000, 3, 4, 2, 16, 0x20, 0x01, 0x0d, 0xb8, 0xca, 0xfe, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17 }, + 26, ASN_INTEGER, { .integer = 5 } }, + { { 1, 4, 2, 1, 4, 10000, 4, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_INTEGER, + { .integer = 3 } }, /* lldpRemManAddrOID */ - { {1, 4, 2, 1, 5, 0, 3, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_OBJECT_ID, - { .string = { .octet = (char *)zeroDotZero, - .len = sizeof(zeroDotZero) }} }, - { {1, 4, 2, 1, 5, 8000, 3, 4, 1, 4, 192, 0, 2, 17 }, 14, ASN_OBJECT_ID, - { .string = { .octet = (char *)zeroDotZero, - .len = sizeof(zeroDotZero) }} }, - { {1, 4, 2, 1, 5, 8000, 3, 4, 2, 16, - 0x20, 0x01, 0x0d, 0xb8, 0xca, 0xfe, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17 }, 26, ASN_OBJECT_ID, - { .string = { .octet = (char *)zeroDotZero, - .len = sizeof(zeroDotZero) }} }, - { {1, 4, 2, 1, 5, 10000, 4, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_OBJECT_ID, - { .string = { .octet = (char *)zeroDotZero, - .len = sizeof(zeroDotZero) }} }, + { { 1, 4, 2, 1, 5, 0, 3, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_OBJECT_ID, + { .string = { .octet = (char *)zeroDotZero, + .len = sizeof(zeroDotZero) } } }, + { { 1, 4, 2, 1, 5, 8000, 3, 4, 1, 4, 192, 0, 2, 17 }, 14, ASN_OBJECT_ID, + { .string = { .octet = (char *)zeroDotZero, + .len = sizeof(zeroDotZero) } } }, + { { 1, 4, 2, 1, 5, 8000, 3, 4, 2, 16, 0x20, 0x01, 0x0d, 0xb8, 0xca, 0xfe, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17 }, + 26, ASN_OBJECT_ID, + { .string = { .octet = (char *)zeroDotZero, + .len = sizeof(zeroDotZero) } } }, + { { 1, 4, 2, 1, 5, 10000, 4, 1, 1, 4, 192, 0, 2, 15 }, 14, ASN_OBJECT_ID, + { .string = { .octet = (char *)zeroDotZero, + .len = sizeof(zeroDotZero) } } }, #ifdef ENABLE_CUSTOM /* lldpRemOrgDefInfo */ - { {1, 4, 4, 1, 4, 0, 3, 1, 33, 44, 55, 44, 1 }, 13, ASN_OCTET_STR, - { .string = { .octet = "OUI content", .len = 11 }} }, - { {1, 4, 4, 1, 4, 0, 3, 1, 33, 44, 55, 44, 2 }, 13, ASN_OCTET_STR, - { .string = { .octet = "More content", .len = 12 }} }, - { {1, 4, 4, 1, 4, 0, 3, 1, 33, 44, 55, 45, 3 }, 13, ASN_OCTET_STR, - { .string = { .octet = "More more content", .len = 17 }} }, - { {1, 4, 4, 1, 4, 0, 3, 1, 33, 44, 56, 44, 4 }, 13, ASN_OCTET_STR, - { .string = { .octet = "Even more content", .len = 17 }} }, - { {1, 4, 4, 1, 4, 10000, 4, 1, 33, 44, 55, 44, 1 }, 13, ASN_OCTET_STR, - { .string = { .octet = "Still more content", .len = 18 }} }, + { { 1, 4, 4, 1, 4, 0, 3, 1, 33, 44, 55, 44, 1 }, 13, ASN_OCTET_STR, + { .string = { .octet = "OUI content", .len = 11 } } }, + { { 1, 4, 4, 1, 4, 0, 3, 1, 33, 44, 55, 44, 2 }, 13, ASN_OCTET_STR, + { .string = { .octet = "More content", .len = 12 } } }, + { { 1, 4, 4, 1, 4, 0, 3, 1, 33, 44, 55, 45, 3 }, 13, ASN_OCTET_STR, + { .string = { .octet = "More more content", .len = 17 } } }, + { { 1, 4, 4, 1, 4, 0, 3, 1, 33, 44, 56, 44, 4 }, 13, ASN_OCTET_STR, + { .string = { .octet = "Even more content", .len = 17 } } }, + { { 1, 4, 4, 1, 4, 10000, 4, 1, 33, 44, 55, 44, 1 }, 13, ASN_OCTET_STR, + { .string = { .octet = "Still more content", .len = 18 } } }, #endif #ifdef ENABLE_DOT3 /* lldpXdot3LocPortAutoNegSupported */ - { {1, 5, 4623, 1, 2, 1, 1, 1, 3 }, 9, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4623, 1, 2, 1, 1, 1, 4 }, 9, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 2, 1, 1, 1, 3 }, 9, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 4623, 1, 2, 1, 1, 1, 4 }, 9, ASN_INTEGER, { .integer = 1 } }, /* lldpXdot3LocPortAutoNegEnabled */ - { {1, 5, 4623, 1, 2, 1, 1, 2, 3 }, 9, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4623, 1, 2, 1, 1, 2, 4 }, 9, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 2, 1, 1, 2, 3 }, 9, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 4623, 1, 2, 1, 1, 2, 4 }, 9, ASN_INTEGER, { .integer = 1 } }, /* lldpXdot3LocPortAutoNegAdvertisedCap */ - { {1, 5, 4623, 1, 2, 1, 1, 3, 3 }, 9, ASN_OCTET_STR, - { .string = { .octet = "\x0c\x00", .len = 2 }} }, - { {1, 5, 4623, 1, 2, 1, 1, 3, 4 }, 9, ASN_OCTET_STR, - { .string = { .octet = "\x04\x01", .len = 2 }} }, + { { 1, 5, 4623, 1, 2, 1, 1, 3, 3 }, 9, ASN_OCTET_STR, + { .string = { .octet = "\x0c\x00", .len = 2 } } }, + { { 1, 5, 4623, 1, 2, 1, 1, 3, 4 }, 9, ASN_OCTET_STR, + { .string = { .octet = "\x04\x01", .len = 2 } } }, /* lldpXdot3LocPortOperMauType */ - { {1, 5, 4623, 1, 2, 1, 1, 4, 3 }, 9, ASN_INTEGER, { .integer = 16 }}, - { {1, 5, 4623, 1, 2, 1, 1, 4, 4 }, 9, ASN_INTEGER, { .integer = 30 }}, + { { 1, 5, 4623, 1, 2, 1, 1, 4, 3 }, 9, ASN_INTEGER, { .integer = 16 } }, + { { 1, 5, 4623, 1, 2, 1, 1, 4, 4 }, 9, ASN_INTEGER, { .integer = 30 } }, /* lldpXdot3LocPowerPortClass */ - { {1, 5, 4623, 1, 2, 2, 1, 1, 3 }, 9, ASN_INTEGER, { .integer = 2 }}, + { { 1, 5, 4623, 1, 2, 2, 1, 1, 3 }, 9, ASN_INTEGER, { .integer = 2 } }, /* lldpXdot3LocPowerMDISupported */ - { {1, 5, 4623, 1, 2, 2, 1, 2, 3 }, 9, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 2, 2, 1, 2, 3 }, 9, ASN_INTEGER, { .integer = 1 } }, /* lldpXdot3LocPowerMDIEnabled */ - { {1, 5, 4623, 1, 2, 2, 1, 3, 3 }, 9, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 2, 2, 1, 3, 3 }, 9, ASN_INTEGER, { .integer = 1 } }, /* lldpXdot3LocPowerPairControlable */ - { {1, 5, 4623, 1, 2, 2, 1, 4, 3 }, 9, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 2, 2, 1, 4, 3 }, 9, ASN_INTEGER, { .integer = 1 } }, /* lldpXdot3LocPowerPairs */ - { {1, 5, 4623, 1, 2, 2, 1, 5, 3 }, 9, ASN_INTEGER, { .integer = 2 }}, + { { 1, 5, 4623, 1, 2, 2, 1, 5, 3 }, 9, ASN_INTEGER, { .integer = 2 } }, /* lldpXdot3LocPowerClass */ - { {1, 5, 4623, 1, 2, 2, 1, 6, 3 }, 9, ASN_INTEGER, { .integer = 3 }}, + { { 1, 5, 4623, 1, 2, 2, 1, 6, 3 }, 9, ASN_INTEGER, { .integer = 3 } }, /* As per 802.3at-2009, not sure of the OID... */ /* lldpXdot3LocPowerType */ - { {1, 5, 4623, 1, 2, 2, 1, 7, 3 }, 9, ASN_OCTET_STR, - { .string = { .octet = "\xC0", .len = 1 } }}, + { { 1, 5, 4623, 1, 2, 2, 1, 7, 3 }, 9, ASN_OCTET_STR, + { .string = { .octet = "\xC0", .len = 1 } } }, /* lldpXdot3LocPowerSource */ - { {1, 5, 4623, 1, 2, 2, 1, 8, 3 }, 9, ASN_OCTET_STR, - { .string = { .octet = "\xC0", .len = 1 } }}, + { { 1, 5, 4623, 1, 2, 2, 1, 8, 3 }, 9, ASN_OCTET_STR, + { .string = { .octet = "\xC0", .len = 1 } } }, /* lldpXdot3LocPowerPriority */ - { {1, 5, 4623, 1, 2, 2, 1, 9, 3 }, 9, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 2, 2, 1, 9, 3 }, 9, ASN_INTEGER, { .integer = 1 } }, /* lldpXdot3LocPDRequestedPowerValue */ - { {1, 5, 4623, 1, 2, 2, 1, 10, 3 }, 9, ASN_INTEGER, { .integer = 2000 }}, + { { 1, 5, 4623, 1, 2, 2, 1, 10, 3 }, 9, ASN_INTEGER, { .integer = 2000 } }, /* lldpXdot3LocPSEAllocatedPowerValue */ - { {1, 5, 4623, 1, 2, 2, 1, 11, 3 }, 9, ASN_INTEGER, { .integer = 2500 }}, + { { 1, 5, 4623, 1, 2, 2, 1, 11, 3 }, 9, ASN_INTEGER, { .integer = 2500 } }, /* lldpXdot3LocLinkAggStatus */ - { {1, 5, 4623, 1, 2, 3, 1, 1, 3 }, 9, ASN_OCTET_STR, - { .string = { .octet = "\x00", .len = 1 }} }, - { {1, 5, 4623, 1, 2, 3, 1, 1, 4 }, 9, ASN_OCTET_STR, - { .string = { .octet = "\xC0", .len = 1 }} }, + { { 1, 5, 4623, 1, 2, 3, 1, 1, 3 }, 9, ASN_OCTET_STR, + { .string = { .octet = "\x00", .len = 1 } } }, + { { 1, 5, 4623, 1, 2, 3, 1, 1, 4 }, 9, ASN_OCTET_STR, + { .string = { .octet = "\xC0", .len = 1 } } }, /* lldpXdot3LocLinkAggPortId */ - { {1, 5, 4623, 1, 2, 3, 1, 2, 3 }, 9, ASN_INTEGER, { .integer = 0 }}, - { {1, 5, 4623, 1, 2, 3, 1, 2, 4 }, 9, ASN_INTEGER, { .integer = 3 }}, + { { 1, 5, 4623, 1, 2, 3, 1, 2, 3 }, 9, ASN_INTEGER, { .integer = 0 } }, + { { 1, 5, 4623, 1, 2, 3, 1, 2, 4 }, 9, ASN_INTEGER, { .integer = 3 } }, /* lldpXdot3LocMaxFrameSize */ - { {1, 5, 4623, 1, 2, 4, 1, 1, 3 }, 9, ASN_INTEGER, { .integer = 1600 }}, - { {1, 5, 4623, 1, 2, 4, 1, 1, 4 }, 9, ASN_INTEGER, { .integer = 9000 }}, + { { 1, 5, 4623, 1, 2, 4, 1, 1, 3 }, 9, ASN_INTEGER, { .integer = 1600 } }, + { { 1, 5, 4623, 1, 2, 4, 1, 1, 4 }, 9, ASN_INTEGER, { .integer = 9000 } }, /* lldpXdot3RemPortAutoNegSupported */ - { {1, 5, 4623, 1, 3, 1, 1, 1, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4623, 1, 3, 1, 1, 1, 8000, 3, 4 }, 11, ASN_INTEGER, { .integer = 2 }}, - { {1, 5, 4623, 1, 3, 1, 1, 1, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 3, 1, 1, 1, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 4623, 1, 3, 1, 1, 1, 8000, 3, 4 }, 11, ASN_INTEGER, + { .integer = 2 } }, + { { 1, 5, 4623, 1, 3, 1, 1, 1, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 1 } }, /* lldpXdot3RemPortAutoNegEnabled */ - { {1, 5, 4623, 1, 3, 1, 1, 2, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4623, 1, 3, 1, 1, 2, 8000, 3, 4 }, 11, ASN_INTEGER, { .integer = 2 }}, - { {1, 5, 4623, 1, 3, 1, 1, 2, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 3, 1, 1, 2, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 4623, 1, 3, 1, 1, 2, 8000, 3, 4 }, 11, ASN_INTEGER, + { .integer = 2 } }, + { { 1, 5, 4623, 1, 3, 1, 1, 2, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 1 } }, /* lldpXdot3RemPortAutoNegAdvertisedCap */ - { {1, 5, 4623, 1, 3, 1, 1, 3, 0, 3, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\x04\x01", .len = 2 }} }, - { {1, 5, 4623, 1, 3, 1, 1, 3, 8000, 3, 4 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\x00\x00", .len = 2 }} }, - { {1, 5, 4623, 1, 3, 1, 1, 3, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\x0c\x00", .len = 2 }} }, + { { 1, 5, 4623, 1, 3, 1, 1, 3, 0, 3, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\x04\x01", .len = 2 } } }, + { { 1, 5, 4623, 1, 3, 1, 1, 3, 8000, 3, 4 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\x00\x00", .len = 2 } } }, + { { 1, 5, 4623, 1, 3, 1, 1, 3, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\x0c\x00", .len = 2 } } }, /* lldpXdot3RemPortOperMauType */ - { {1, 5, 4623, 1, 3, 1, 1, 4, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 30 }}, - { {1, 5, 4623, 1, 3, 1, 1, 4, 8000, 3, 4 }, 11, ASN_INTEGER, { .integer = 0 }}, - { {1, 5, 4623, 1, 3, 1, 1, 4, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 16 }}, + { { 1, 5, 4623, 1, 3, 1, 1, 4, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 30 } }, + { { 1, 5, 4623, 1, 3, 1, 1, 4, 8000, 3, 4 }, 11, ASN_INTEGER, + { .integer = 0 } }, + { { 1, 5, 4623, 1, 3, 1, 1, 4, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 16 } }, /* lldpXdot3RemPowerPortClass */ - { {1, 5, 4623, 1, 3, 2, 1, 1, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 2 }}, + { { 1, 5, 4623, 1, 3, 2, 1, 1, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 2 } }, /* lldpXdot3RemPowerMDISupported */ - { {1, 5, 4623, 1, 3, 2, 1, 2, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 3, 2, 1, 2, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 1 } }, /* lldpXdot3RemPowerMDIEnabled */ - { {1, 5, 4623, 1, 3, 2, 1, 3, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 3, 2, 1, 3, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 1 } }, /* lldpXdot3RemPowerPairControlable */ - { {1, 5, 4623, 1, 3, 2, 1, 4, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 3, 2, 1, 4, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 1 } }, /* lldpXdot3RemPowerPairs */ - { {1, 5, 4623, 1, 3, 2, 1, 5, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 2 }}, + { { 1, 5, 4623, 1, 3, 2, 1, 5, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 2 } }, /* lldpXdot3RemPowerClass */ - { {1, 5, 4623, 1, 3, 2, 1, 6, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 3 }}, + { { 1, 5, 4623, 1, 3, 2, 1, 6, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 3 } }, /* As per 802.3at-2009, not sure of the OID... */ /* lldpXdot3RemPowerType */ - { {1, 5, 4623, 1, 3, 2, 1, 7, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\xC0", .len = 1 } }}, + { { 1, 5, 4623, 1, 3, 2, 1, 7, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\xC0", .len = 1 } } }, /* lldpXdot3RemPowerSource */ - { {1, 5, 4623, 1, 3, 2, 1, 8, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\xC0", .len = 1 } }}, + { { 1, 5, 4623, 1, 3, 2, 1, 8, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\xC0", .len = 1 } } }, /* lldpXdot3RemPowerPriority */ - { {1, 5, 4623, 1, 3, 2, 1, 9, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4623, 1, 3, 2, 1, 9, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 1 } }, /* lldpXdot3RemPDRequestedPowerValue */ - { {1, 5, 4623, 1, 3, 2, 1, 10, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 2000 }}, + { { 1, 5, 4623, 1, 3, 2, 1, 10, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 2000 } }, /* lldpXdot3RemPSEAllocatedPowerValue */ - { {1, 5, 4623, 1, 3, 2, 1, 11, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 2500 }}, + { { 1, 5, 4623, 1, 3, 2, 1, 11, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 2500 } }, /* lldpXdot3RemLinkAggStatus */ - { {1, 5, 4623, 1, 3, 3, 1, 1, 0, 3, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\xC0", .len = 1 }} }, - { {1, 5, 4623, 1, 3, 3, 1, 1, 8000, 3, 4 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\x00", .len = 1 }} }, - { {1, 5, 4623, 1, 3, 3, 1, 1, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\x00", .len = 1 }} }, + { { 1, 5, 4623, 1, 3, 3, 1, 1, 0, 3, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\xC0", .len = 1 } } }, + { { 1, 5, 4623, 1, 3, 3, 1, 1, 8000, 3, 4 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\x00", .len = 1 } } }, + { { 1, 5, 4623, 1, 3, 3, 1, 1, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\x00", .len = 1 } } }, /* lldpXdot3RemLinkAggPortId */ - { {1, 5, 4623, 1, 3, 3, 1, 2, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 3 }}, - { {1, 5, 4623, 1, 3, 3, 1, 2, 8000, 3, 4 }, 11, ASN_INTEGER, { .integer = 0 }}, - { {1, 5, 4623, 1, 3, 3, 1, 2, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 0 }}, + { { 1, 5, 4623, 1, 3, 3, 1, 2, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 3 } }, + { { 1, 5, 4623, 1, 3, 3, 1, 2, 8000, 3, 4 }, 11, ASN_INTEGER, + { .integer = 0 } }, + { { 1, 5, 4623, 1, 3, 3, 1, 2, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 0 } }, /* lldpXdot3RemMaxFrameSize */ - { {1, 5, 4623, 1, 3, 4, 1, 1, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 9000 }}, - { {1, 5, 4623, 1, 3, 4, 1, 1, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 1600 }}, + { { 1, 5, 4623, 1, 3, 4, 1, 1, 0, 3, 1 }, 11, ASN_INTEGER, + { .integer = 9000 } }, + { { 1, 5, 4623, 1, 3, 4, 1, 1, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 1600 } }, #endif #ifdef ENABLE_LLDPMED /* lldpXMedLocDeviceClass */ - { {1, 5, 4795, 1, 1, 1, 0 }, 7, ASN_INTEGER, { .integer = 2 }}, + { { 1, 5, 4795, 1, 1, 1, 0 }, 7, ASN_INTEGER, { .integer = 2 } }, /* lldpXMedLocMediaPolicyVlanID */ - { {1, 5, 4795, 1, 2, 1, 1, 2, 3, 3 }, 10, ASN_INTEGER, { .integer = 475 }}, - { {1, 5, 4795, 1, 2, 1, 1, 2, 3, 7 }, 10, ASN_INTEGER, { .integer = 472 }}, - { {1, 5, 4795, 1, 2, 1, 1, 2, 4, 3 }, 10, ASN_INTEGER, { .integer = 475 }}, - { {1, 5, 4795, 1, 2, 1, 1, 2, 4, 6 }, 10, ASN_INTEGER, { .integer = 1007 }}, + { { 1, 5, 4795, 1, 2, 1, 1, 2, 3, 3 }, 10, ASN_INTEGER, { .integer = 475 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 2, 3, 7 }, 10, ASN_INTEGER, { .integer = 472 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 2, 4, 3 }, 10, ASN_INTEGER, { .integer = 475 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 2, 4, 6 }, 10, ASN_INTEGER, { .integer = 1007 } }, /* lldpXMedLocMediaPolicyPriority */ - { {1, 5, 4795, 1, 2, 1, 1, 3, 3, 3 }, 10, ASN_INTEGER, { .integer = 3 }}, - { {1, 5, 4795, 1, 2, 1, 1, 3, 3, 7 }, 10, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 2, 1, 1, 3, 4, 3 }, 10, ASN_INTEGER, { .integer = 3 }}, - { {1, 5, 4795, 1, 2, 1, 1, 3, 4, 6 }, 10, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4795, 1, 2, 1, 1, 3, 3, 3 }, 10, ASN_INTEGER, { .integer = 3 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 3, 3, 7 }, 10, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 3, 4, 3 }, 10, ASN_INTEGER, { .integer = 3 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 3, 4, 6 }, 10, ASN_INTEGER, { .integer = 1 } }, /* lldpXMedLocMediaPolicyDscp */ - { {1, 5, 4795, 1, 2, 1, 1, 4, 3, 3 }, 10, ASN_INTEGER, { .integer = 62 }}, - { {1, 5, 4795, 1, 2, 1, 1, 4, 3, 7 }, 10, ASN_INTEGER, { .integer = 60 }}, - { {1, 5, 4795, 1, 2, 1, 1, 4, 4, 3 }, 10, ASN_INTEGER, { .integer = 62 }}, - { {1, 5, 4795, 1, 2, 1, 1, 4, 4, 6 }, 10, ASN_INTEGER, { .integer = 49 }}, + { { 1, 5, 4795, 1, 2, 1, 1, 4, 3, 3 }, 10, ASN_INTEGER, { .integer = 62 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 4, 3, 7 }, 10, ASN_INTEGER, { .integer = 60 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 4, 4, 3 }, 10, ASN_INTEGER, { .integer = 62 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 4, 4, 6 }, 10, ASN_INTEGER, { .integer = 49 } }, /* lldpXMedLocMediaPolicyUnknown */ - { {1, 5, 4795, 1, 2, 1, 1, 5, 3, 3 }, 10, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 2, 1, 1, 5, 3, 7 }, 10, ASN_INTEGER, { .integer = 2 }}, - { {1, 5, 4795, 1, 2, 1, 1, 5, 4, 3 }, 10, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 2, 1, 1, 5, 4, 6 }, 10, ASN_INTEGER, { .integer = 2 }}, + { { 1, 5, 4795, 1, 2, 1, 1, 5, 3, 3 }, 10, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 5, 3, 7 }, 10, ASN_INTEGER, { .integer = 2 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 5, 4, 3 }, 10, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 5, 4, 6 }, 10, ASN_INTEGER, { .integer = 2 } }, /* lldpXMedLocMediaPolicyTagged */ - { {1, 5, 4795, 1, 2, 1, 1, 6, 3, 3 }, 10, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 2, 1, 1, 6, 3, 7 }, 10, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 2, 1, 1, 6, 4, 3 }, 10, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 2, 1, 1, 6, 4, 6 }, 10, ASN_INTEGER, { .integer = 2 }}, + { { 1, 5, 4795, 1, 2, 1, 1, 6, 3, 3 }, 10, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 6, 3, 7 }, 10, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 6, 4, 3 }, 10, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 4795, 1, 2, 1, 1, 6, 4, 6 }, 10, ASN_INTEGER, { .integer = 2 } }, /* lldpXMedLocHardwareRev */ - { {1, 5, 4795, 1, 2, 2, 0 }, 7, ASN_OCTET_STR, - { .string = { .octet = "Hardware 1", .len = 10 }} }, + { { 1, 5, 4795, 1, 2, 2, 0 }, 7, ASN_OCTET_STR, + { .string = { .octet = "Hardware 1", .len = 10 } } }, /* lldpXMedLocSoftwareRev */ - { {1, 5, 4795, 1, 2, 4, 0 }, 7, ASN_OCTET_STR, - { .string = { .octet = "Software 1", .len = 10 }} }, + { { 1, 5, 4795, 1, 2, 4, 0 }, 7, ASN_OCTET_STR, + { .string = { .octet = "Software 1", .len = 10 } } }, /* lldpXMedLocSerialNum */ - { {1, 5, 4795, 1, 2, 5, 0 }, 7, ASN_OCTET_STR, - { .string = { .octet = "00-00-0000-AAAA", .len = 15 }} }, + { { 1, 5, 4795, 1, 2, 5, 0 }, 7, ASN_OCTET_STR, + { .string = { .octet = "00-00-0000-AAAA", .len = 15 } } }, /* lldpXMedLocMfgName */ - { {1, 5, 4795, 1, 2, 6, 0 }, 7, ASN_OCTET_STR, - { .string = { .octet = "Manufacturer 1", .len = 14 }} }, + { { 1, 5, 4795, 1, 2, 6, 0 }, 7, ASN_OCTET_STR, + { .string = { .octet = "Manufacturer 1", .len = 14 } } }, /* lldpXMedLocModelName */ - { {1, 5, 4795, 1, 2, 7, 0 }, 7, ASN_OCTET_STR, - { .string = { .octet = "Model 1", .len = 7 }} }, + { { 1, 5, 4795, 1, 2, 7, 0 }, 7, ASN_OCTET_STR, + { .string = { .octet = "Model 1", .len = 7 } } }, /* lldpXMedLocAssetID */ - { {1, 5, 4795, 1, 2, 8, 0 }, 7, ASN_OCTET_STR, - { .string = { .octet = "Asset 1", .len = 7 }} }, + { { 1, 5, 4795, 1, 2, 8, 0 }, 7, ASN_OCTET_STR, + { .string = { .octet = "Asset 1", .len = 7 } } }, /* lldpXMedLocLocationInfo */ - { {1, 5, 4795, 1, 2, 9, 1, 2, 3, 3}, 10, ASN_OCTET_STR, - { .string = { .octet = "\x15" "\x02" "FR" "\x06" "\x0d" "Commercial Rd" "\x13" "\x01" "4", .len = 22 }} }, - { {1, 5, 4795, 1, 2, 9, 1, 2, 4, 2}, 10, ASN_OCTET_STR, - { .string = { .octet = "Not interpreted", .len = 15 }} }, + { { 1, 5, 4795, 1, 2, 9, 1, 2, 3, 3 }, 10, ASN_OCTET_STR, + { .string = { .octet = "\x15" + "\x02" + "FR" + "\x06" + "\x0d" + "Commercial Rd" + "\x13" + "\x01" + "4", + .len = 22 } } }, + { { 1, 5, 4795, 1, 2, 9, 1, 2, 4, 2 }, 10, ASN_OCTET_STR, + { .string = { .octet = "Not interpreted", .len = 15 } } }, /* lldpXMedLocXPoEDeviceType */ - { {1, 5, 4795, 1, 2, 10, 0 }, 7, ASN_INTEGER, { .integer = 3 }}, + { { 1, 5, 4795, 1, 2, 10, 0 }, 7, ASN_INTEGER, { .integer = 3 } }, /* lldpXMedLocXPoEPDPowerReq */ - { {1, 5, 4795, 1, 2, 13, 0 }, 7, ASN_GAUGE, { .integer = 100 }}, + { { 1, 5, 4795, 1, 2, 13, 0 }, 7, ASN_GAUGE, { .integer = 100 } }, /* lldpXMedLocXPoEPDPowerSource */ - { {1, 5, 4795, 1, 2, 14, 0 }, 7, ASN_INTEGER, { .integer = 3 }}, + { { 1, 5, 4795, 1, 2, 14, 0 }, 7, ASN_INTEGER, { .integer = 3 } }, /* lldpXMedLocXPoEPDPowerPriority */ - { {1, 5, 4795, 1, 2, 15, 0 }, 7, ASN_INTEGER, { .integer = 3 }}, + { { 1, 5, 4795, 1, 2, 15, 0 }, 7, ASN_INTEGER, { .integer = 3 } }, /* lldpXMedRemCapSupported */ - { {1, 5, 4795, 1, 3, 1, 1, 1, 0, 3, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\xFC", .len = 1 }} }, - { {1, 5, 4795, 1, 3, 1, 1, 1, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\xFC", .len = 1 }}}, + { { 1, 5, 4795, 1, 3, 1, 1, 1, 0, 3, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\xFC", .len = 1 } } }, + { { 1, 5, 4795, 1, 3, 1, 1, 1, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\xFC", .len = 1 } } }, /* lldpXMedRemCapCurrent */ - { {1, 5, 4795, 1, 3, 1, 1, 2, 0, 3, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\xFC", .len = 1 }} }, - { {1, 5, 4795, 1, 3, 1, 1, 2, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "\xEC", .len = 1 }}}, + { { 1, 5, 4795, 1, 3, 1, 1, 2, 0, 3, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\xFC", .len = 1 } } }, + { { 1, 5, 4795, 1, 3, 1, 1, 2, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "\xEC", .len = 1 } } }, /* lldpXMedRemDeviceClass */ - { {1, 5, 4795, 1, 3, 1, 1, 3, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 2 }}, - { {1, 5, 4795, 1, 3, 1, 1, 3, 10000, 4, 1 }, 11, ASN_INTEGER, { .integer = 2 }}, + { { 1, 5, 4795, 1, 3, 1, 1, 3, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 2 } }, + { { 1, 5, 4795, 1, 3, 1, 1, 3, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 2 } }, /* lldpXMedRemMediaPolicyVlanID */ - { {1, 5, 4795, 1, 3, 2, 1, 2, 0, 3, 1, 3 }, 12, ASN_INTEGER, { .integer = 475 }}, - { {1, 5, 4795, 1, 3, 2, 1, 2, 0, 3, 1, 6 }, 12, ASN_INTEGER, { .integer = 1007 }}, - { {1, 5, 4795, 1, 3, 2, 1, 2, 10000, 4, 1, 3 }, 12, ASN_INTEGER, { .integer = 475 }}, - { {1, 5, 4795, 1, 3, 2, 1, 2, 10000, 4, 1, 7 }, 12, ASN_INTEGER, { .integer = 472 }}, + { { 1, 5, 4795, 1, 3, 2, 1, 2, 0, 3, 1, 3 }, 12, ASN_INTEGER, + { .integer = 475 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 2, 0, 3, 1, 6 }, 12, ASN_INTEGER, + { .integer = 1007 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 2, 10000, 4, 1, 3 }, 12, ASN_INTEGER, + { .integer = 475 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 2, 10000, 4, 1, 7 }, 12, ASN_INTEGER, + { .integer = 472 } }, /* lldpXMedRemMediaPolicyPriority */ - { {1, 5, 4795, 1, 3, 2, 1, 3, 0, 3, 1, 3 }, 12, ASN_INTEGER, { .integer = 3 }}, - { {1, 5, 4795, 1, 3, 2, 1, 3, 0, 3, 1, 6 }, 12, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 3, 2, 1, 3, 10000, 4, 1, 3 }, 12, ASN_INTEGER, { .integer = 3 }}, - { {1, 5, 4795, 1, 3, 2, 1, 3, 10000, 4, 1, 7 }, 12, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4795, 1, 3, 2, 1, 3, 0, 3, 1, 3 }, 12, ASN_INTEGER, + { .integer = 3 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 3, 0, 3, 1, 6 }, 12, ASN_INTEGER, + { .integer = 1 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 3, 10000, 4, 1, 3 }, 12, ASN_INTEGER, + { .integer = 3 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 3, 10000, 4, 1, 7 }, 12, ASN_INTEGER, + { .integer = 1 } }, /* lldpXMedLocMediaPolicyDscp */ - { {1, 5, 4795, 1, 3, 2, 1, 4, 0, 3, 1, 3 }, 12, ASN_INTEGER, { .integer = 62 }}, - { {1, 5, 4795, 1, 3, 2, 1, 4, 0, 3, 1, 6 }, 12, ASN_INTEGER, { .integer = 49 }}, - { {1, 5, 4795, 1, 3, 2, 1, 4, 10000, 4, 1, 3 }, 12, ASN_INTEGER, { .integer = 62 }}, - { {1, 5, 4795, 1, 3, 2, 1, 4, 10000, 4, 1, 7 }, 12, ASN_INTEGER, { .integer = 60 }}, + { { 1, 5, 4795, 1, 3, 2, 1, 4, 0, 3, 1, 3 }, 12, ASN_INTEGER, + { .integer = 62 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 4, 0, 3, 1, 6 }, 12, ASN_INTEGER, + { .integer = 49 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 4, 10000, 4, 1, 3 }, 12, ASN_INTEGER, + { .integer = 62 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 4, 10000, 4, 1, 7 }, 12, ASN_INTEGER, + { .integer = 60 } }, /* lldpXMedLocMediaPolicyUnknown */ - { {1, 5, 4795, 1, 3, 2, 1, 5, 0, 3, 1, 3 }, 12, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 3, 2, 1, 5, 0, 3, 1, 6 }, 12, ASN_INTEGER, { .integer = 2 }}, - { {1, 5, 4795, 1, 3, 2, 1, 5, 10000, 4, 1, 3 }, 12, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 3, 2, 1, 5, 10000, 4, 1, 7 }, 12, ASN_INTEGER, { .integer = 2 }}, + { { 1, 5, 4795, 1, 3, 2, 1, 5, 0, 3, 1, 3 }, 12, ASN_INTEGER, + { .integer = 1 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 5, 0, 3, 1, 6 }, 12, ASN_INTEGER, + { .integer = 2 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 5, 10000, 4, 1, 3 }, 12, ASN_INTEGER, + { .integer = 1 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 5, 10000, 4, 1, 7 }, 12, ASN_INTEGER, + { .integer = 2 } }, /* lldpXMedLocMediaPolicyTagged */ - { {1, 5, 4795, 1, 3, 2, 1, 6, 0, 3, 1, 3 }, 12, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 3, 2, 1, 6, 0, 3, 1, 6 }, 12, ASN_INTEGER, { .integer = 2 }}, - { {1, 5, 4795, 1, 3, 2, 1, 6, 10000, 4, 1, 3 }, 12, ASN_INTEGER, { .integer = 1 }}, - { {1, 5, 4795, 1, 3, 2, 1, 6, 10000, 4, 1, 7 }, 12, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 4795, 1, 3, 2, 1, 6, 0, 3, 1, 3 }, 12, ASN_INTEGER, + { .integer = 1 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 6, 0, 3, 1, 6 }, 12, ASN_INTEGER, + { .integer = 2 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 6, 10000, 4, 1, 3 }, 12, ASN_INTEGER, + { .integer = 1 } }, + { { 1, 5, 4795, 1, 3, 2, 1, 6, 10000, 4, 1, 7 }, 12, ASN_INTEGER, + { .integer = 1 } }, /* lldpXMedRemHardwareRev */ - { {1, 5, 4795, 1, 3, 3, 1, 1, 0, 3, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "Hardware 1", .len = 10 }} }, - { {1, 5, 4795, 1, 3, 3, 1, 1, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "Hardware 1", .len = 10 }} }, + { { 1, 5, 4795, 1, 3, 3, 1, 1, 0, 3, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "Hardware 1", .len = 10 } } }, + { { 1, 5, 4795, 1, 3, 3, 1, 1, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "Hardware 1", .len = 10 } } }, /* lldpXMedRemSoftwareRev */ - { {1, 5, 4795, 1, 3, 3, 1, 3, 0, 3, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "Software 1", .len = 10 }} }, - { {1, 5, 4795, 1, 3, 3, 1, 3, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "Software 1", .len = 10 }} }, + { { 1, 5, 4795, 1, 3, 3, 1, 3, 0, 3, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "Software 1", .len = 10 } } }, + { { 1, 5, 4795, 1, 3, 3, 1, 3, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "Software 1", .len = 10 } } }, /* lldpXMedRemSerialNum */ - { {1, 5, 4795, 1, 3, 3, 1, 4, 0, 3, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "00-00-0000-AAAA", .len = 15 }} }, - { {1, 5, 4795, 1, 3, 3, 1, 4, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "00-00-0000-AAAA", .len = 15 }} }, + { { 1, 5, 4795, 1, 3, 3, 1, 4, 0, 3, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "00-00-0000-AAAA", .len = 15 } } }, + { { 1, 5, 4795, 1, 3, 3, 1, 4, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "00-00-0000-AAAA", .len = 15 } } }, /* lldpXMedRemMfgName */ - { {1, 5, 4795, 1, 3, 3, 1, 5, 0, 3, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "Manufacturer 1", .len = 14 }} }, - { {1, 5, 4795, 1, 3, 3, 1, 5, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "Manufacturer 1", .len = 14 }} }, + { { 1, 5, 4795, 1, 3, 3, 1, 5, 0, 3, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "Manufacturer 1", .len = 14 } } }, + { { 1, 5, 4795, 1, 3, 3, 1, 5, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "Manufacturer 1", .len = 14 } } }, /* lldpXMedRemModelName */ - { {1, 5, 4795, 1, 3, 3, 1, 6, 0, 3, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "Model 1", .len = 7 }} }, - { {1, 5, 4795, 1, 3, 3, 1, 6, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "Model 1", .len = 7 }} }, + { { 1, 5, 4795, 1, 3, 3, 1, 6, 0, 3, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "Model 1", .len = 7 } } }, + { { 1, 5, 4795, 1, 3, 3, 1, 6, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "Model 1", .len = 7 } } }, /* lldpXMedRemAssetID */ - { {1, 5, 4795, 1, 3, 3, 1, 7, 0, 3, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "Asset 1", .len = 7 }} }, - { {1, 5, 4795, 1, 3, 3, 1, 7, 10000, 4, 1 }, 11, ASN_OCTET_STR, - { .string = { .octet = "Asset 1", .len = 7 }} }, + { { 1, 5, 4795, 1, 3, 3, 1, 7, 0, 3, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "Asset 1", .len = 7 } } }, + { { 1, 5, 4795, 1, 3, 3, 1, 7, 10000, 4, 1 }, 11, ASN_OCTET_STR, + { .string = { .octet = "Asset 1", .len = 7 } } }, /* lldpXMedLocLocationInfo */ - { {1, 5, 4795, 1, 3, 4, 1, 2, 0, 3, 1, 2}, 12, ASN_OCTET_STR, - { .string = { .octet = "Not interpreted", .len = 15 }} }, - { {1, 5, 4795, 1, 3, 4, 1, 2, 10000, 4, 1, 3}, 12, ASN_OCTET_STR, - { .string = { .octet = "\x15" "\x02" "FR" "\x06" "\x0d" "Commercial Rd" "\x13" "\x01" "4", .len = 22 }} }, + { { 1, 5, 4795, 1, 3, 4, 1, 2, 0, 3, 1, 2 }, 12, ASN_OCTET_STR, + { .string = { .octet = "Not interpreted", .len = 15 } } }, + { { 1, 5, 4795, 1, 3, 4, 1, 2, 10000, 4, 1, 3 }, 12, ASN_OCTET_STR, + { .string = { .octet = "\x15" + "\x02" + "FR" + "\x06" + "\x0d" + "Commercial Rd" + "\x13" + "\x01" + "4", + .len = 22 } } }, /* lldpXMedRemXPoEDeviceType */ - { {1, 5, 4795, 1, 3, 5, 1, 1, 0, 3, 1}, 11, ASN_INTEGER, { .integer = 4 }}, - { {1, 5, 4795, 1, 3, 5, 1, 1, 10000, 4, 1}, 11, ASN_INTEGER, { .integer = 3 }}, + { { 1, 5, 4795, 1, 3, 5, 1, 1, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 4 } }, + { { 1, 5, 4795, 1, 3, 5, 1, 1, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 3 } }, /* lldpXMedRemXPoEPDPowerReq */ - { {1, 5, 4795, 1, 3, 7, 1, 1, 10000, 4, 1}, 11, ASN_GAUGE, { .integer = 100 }}, + { { 1, 5, 4795, 1, 3, 7, 1, 1, 10000, 4, 1 }, 11, ASN_GAUGE, + { .integer = 100 } }, /* lldpXMedRemXPoEPDPowerSource */ - { {1, 5, 4795, 1, 3, 7, 1, 2, 10000, 4, 1}, 11, ASN_INTEGER, { .integer = 3 }}, + { { 1, 5, 4795, 1, 3, 7, 1, 2, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 3 } }, /* lldpXMedRemXPoEPDPowerPriority */ - { {1, 5, 4795, 1, 3, 7, 1, 3, 10000, 4, 1}, 11, ASN_INTEGER, { .integer = 3 }}, + { { 1, 5, 4795, 1, 3, 7, 1, 3, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 3 } }, #endif #ifdef ENABLE_DOT1 /* lldpXdot1LocPortVlanId */ - { { 1, 5, 32962, 1, 2, 1, 1, 1, 3}, 9, ASN_INTEGER, { .integer = 47 }}, - { { 1, 5, 32962, 1, 2, 1, 1, 1, 4}, 9, ASN_INTEGER, { .integer = 0 }}, + { { 1, 5, 32962, 1, 2, 1, 1, 1, 3 }, 9, ASN_INTEGER, { .integer = 47 } }, + { { 1, 5, 32962, 1, 2, 1, 1, 1, 4 }, 9, ASN_INTEGER, { .integer = 0 } }, /* lldpXdot1LocProtoVlanSupported */ - { { 1, 5, 32962, 1, 2, 2, 1, 2, 3, 47}, 10, ASN_INTEGER, { .integer = 1 }}, - { { 1, 5, 32962, 1, 2, 2, 1, 2, 3, 118}, 10, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 32962, 1, 2, 2, 1, 2, 3, 47 }, 10, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 32962, 1, 2, 2, 1, 2, 3, 118 }, 10, ASN_INTEGER, { .integer = 1 } }, /* lldpXdot1LocProtoVlanEnabled */ - { { 1, 5, 32962, 1, 2, 2, 1, 3, 3, 47}, 10, ASN_INTEGER, { .integer = 1 }}, - { { 1, 5, 32962, 1, 2, 2, 1, 3, 3, 118}, 10, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 32962, 1, 2, 2, 1, 3, 3, 47 }, 10, ASN_INTEGER, { .integer = 1 } }, + { { 1, 5, 32962, 1, 2, 2, 1, 3, 3, 118 }, 10, ASN_INTEGER, { .integer = 1 } }, /* lldpXdot1LocVlanName */ - { { 1, 5, 32962, 1, 2, 3, 1, 2, 3, 47}, 10, ASN_OCTET_STR, - { .string = { .octet = "VLAN #47", .len = 8 }} }, - { { 1, 5, 32962, 1, 2, 3, 1, 2, 3, 49}, 10, ASN_OCTET_STR, - { .string = { .octet = "VLAN #49", .len = 8 }} }, - { { 1, 5, 32962, 1, 2, 3, 1, 2, 3, 1449}, 10, ASN_OCTET_STR, - { .string = { .octet = "VLAN #1449", .len = 10 }} }, + { { 1, 5, 32962, 1, 2, 3, 1, 2, 3, 47 }, 10, ASN_OCTET_STR, + { .string = { .octet = "VLAN #47", .len = 8 } } }, + { { 1, 5, 32962, 1, 2, 3, 1, 2, 3, 49 }, 10, ASN_OCTET_STR, + { .string = { .octet = "VLAN #49", .len = 8 } } }, + { { 1, 5, 32962, 1, 2, 3, 1, 2, 3, 1449 }, 10, ASN_OCTET_STR, + { .string = { .octet = "VLAN #1449", .len = 10 } } }, /* lldpXdot1LocProtocolId */ - { { 1, 5, 32962, 1, 2, 4, 1, 2, 3, 30321}, 10, ASN_OCTET_STR, - { .string = { .octet = "\x88\x8e\x01", .len = 3 } }}, - { { 1, 5, 32962, 1, 2, 4, 1, 2, 3, 30515}, 10, ASN_OCTET_STR, - { .string = { .octet = "\x88\xcc", .len = 2 } }}, + { { 1, 5, 32962, 1, 2, 4, 1, 2, 3, 30321 }, 10, ASN_OCTET_STR, + { .string = { .octet = "\x88\x8e\x01", .len = 3 } } }, + { { 1, 5, 32962, 1, 2, 4, 1, 2, 3, 30515 }, 10, ASN_OCTET_STR, + { .string = { .octet = "\x88\xcc", .len = 2 } } }, /* lldpXdot1RemPortVlanId */ - { { 1, 5, 32962, 1, 3, 1, 1, 1, 0, 3, 1}, 11, ASN_INTEGER, { .integer = 0 }}, - { { 1, 5, 32962, 1, 3, 1, 1, 1, 8000, 3, 4}, 11, ASN_INTEGER, { .integer = 0 }}, - { { 1, 5, 32962, 1, 3, 1, 1, 1, 10000, 4, 1}, 11, ASN_INTEGER, { .integer = 47 }}, + { { 1, 5, 32962, 1, 3, 1, 1, 1, 0, 3, 1 }, 11, ASN_INTEGER, { .integer = 0 } }, + { { 1, 5, 32962, 1, 3, 1, 1, 1, 8000, 3, 4 }, 11, ASN_INTEGER, + { .integer = 0 } }, + { { 1, 5, 32962, 1, 3, 1, 1, 1, 10000, 4, 1 }, 11, ASN_INTEGER, + { .integer = 47 } }, /* lldpXdot1RemProtoVlanSupported */ - { { 1, 5, 32962, 1, 3, 2, 1, 2, 10000, 4, 1, 47}, 12, ASN_INTEGER, { .integer = 1 }}, - { { 1, 5, 32962, 1, 3, 2, 1, 2, 10000, 4, 1, 118}, 12, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 32962, 1, 3, 2, 1, 2, 10000, 4, 1, 47 }, 12, ASN_INTEGER, + { .integer = 1 } }, + { { 1, 5, 32962, 1, 3, 2, 1, 2, 10000, 4, 1, 118 }, 12, ASN_INTEGER, + { .integer = 1 } }, /* lldpXdot1RemProtoVlanEnabled */ - { { 1, 5, 32962, 1, 3, 2, 1, 3, 10000, 4, 1, 47}, 12, ASN_INTEGER, { .integer = 1 }}, - { { 1, 5, 32962, 1, 3, 2, 1, 3, 10000, 4, 1, 118}, 12, ASN_INTEGER, { .integer = 1 }}, + { { 1, 5, 32962, 1, 3, 2, 1, 3, 10000, 4, 1, 47 }, 12, ASN_INTEGER, + { .integer = 1 } }, + { { 1, 5, 32962, 1, 3, 2, 1, 3, 10000, 4, 1, 118 }, 12, ASN_INTEGER, + { .integer = 1 } }, /* lldpXdot1RemVlanName */ - { { 1, 5, 32962, 1, 3, 3, 1, 2, 10000, 4, 1, 47}, 12, ASN_OCTET_STR, - { .string = { .octet = "VLAN #47", .len = 8 }} }, - { { 1, 5, 32962, 1, 3, 3, 1, 2, 10000, 4, 1, 49}, 12, ASN_OCTET_STR, - { .string = { .octet = "VLAN #49", .len = 8 }} }, - { { 1, 5, 32962, 1, 3, 3, 1, 2, 10000, 4, 1, 1449}, 12, ASN_OCTET_STR, - { .string = { .octet = "VLAN #1449", .len = 10 }} }, + { { 1, 5, 32962, 1, 3, 3, 1, 2, 10000, 4, 1, 47 }, 12, ASN_OCTET_STR, + { .string = { .octet = "VLAN #47", .len = 8 } } }, + { { 1, 5, 32962, 1, 3, 3, 1, 2, 10000, 4, 1, 49 }, 12, ASN_OCTET_STR, + { .string = { .octet = "VLAN #49", .len = 8 } } }, + { { 1, 5, 32962, 1, 3, 3, 1, 2, 10000, 4, 1, 1449 }, 12, ASN_OCTET_STR, + { .string = { .octet = "VLAN #1449", .len = 10 } } }, /* lldpXdot1RemProtocolId */ - { { 1, 5, 32962, 1, 3, 4, 1, 2, 10000, 4, 1, 30321}, 12, ASN_OCTET_STR, - { .string = { .octet = "\x88\x8e\x01", .len = 3 } }}, - { { 1, 5, 32962, 1, 3, 4, 1, 2, 10000, 4, 1, 30515}, 12, ASN_OCTET_STR, - { .string = { .octet = "\x88\xcc", .len = 2 } }} + { { 1, 5, 32962, 1, 3, 4, 1, 2, 10000, 4, 1, 30321 }, 12, ASN_OCTET_STR, + { .string = { .octet = "\x88\x8e\x01", .len = 3 } } }, + { { 1, 5, 32962, 1, 3, 4, 1, 2, 10000, 4, 1, 30515 }, 12, ASN_OCTET_STR, + { .string = { .octet = "\x88\xcc", .len = 2 } } } #endif }; -char* +char * tohex(char *str, size_t len) { static char *hex[] = { NULL, NULL }; static int which = 0; - free(hex[which]); hex[which] = NULL; + free(hex[which]); + hex[which] = NULL; hex[which] = malloc(len * 3 + 1); fail_unless(hex[which] != NULL, "Not enough memory?"); for (size_t i = 0; i < len; i++) - snprintf(hex[which] + 3*i, 4, "%02X ", (unsigned char)str[i]); + snprintf(hex[which] + 3 * i, 4, "%02X ", (unsigned char)str[i]); which = 1 - which; return hex[1 - which]; } @@ -919,170 +1015,150 @@ int snmp_is_prefix_of(struct variable8 *vp, struct tree_node *n, char *repr) { if (n->namelen < vp->namelen) return 0; - if (memcmp(n->name, - vp->name, - vp->namelen * sizeof(oid))) - return 0; + if (memcmp(n->name, vp->name, vp->namelen * sizeof(oid))) return 0; fail_unless(n->type == vp->type, "Inappropriate type for OID %s", repr); return 1; } void -snmp_merge(struct variable8 *v1, struct tree_node *n, struct variable *vp, - oid *target, size_t *targetlen) +snmp_merge(struct variable8 *v1, struct tree_node *n, struct variable *vp, oid *target, + size_t *targetlen) { vp->magic = v1->magic; vp->type = v1->type; vp->acl = v1->acl; vp->findVar = v1->findVar; - vp->namelen = v1->namelen + - sizeof(lldp_oid)/sizeof(oid); + vp->namelen = v1->namelen + sizeof(lldp_oid) / sizeof(oid); memcpy(vp->name, lldp_oid, sizeof(lldp_oid)); - memcpy(vp->name + sizeof(lldp_oid)/sizeof(oid), - v1->name, - v1->namelen*sizeof(oid)); - *targetlen = n->namelen + - sizeof(lldp_oid)/sizeof(oid); + memcpy(vp->name + sizeof(lldp_oid) / sizeof(oid), v1->name, + v1->namelen * sizeof(oid)); + *targetlen = n->namelen + sizeof(lldp_oid) / sizeof(oid); memcpy(target, lldp_oid, sizeof(lldp_oid)); - memcpy(target + sizeof(lldp_oid)/sizeof(oid), - n->name, - n->namelen * sizeof(oid)); + memcpy(target + sizeof(lldp_oid) / sizeof(oid), n->name, + n->namelen * sizeof(oid)); } void -snmp_compare(struct tree_node *n, - u_char *result, size_t varlen, - oid *target, size_t targetlen, char *repr) +snmp_compare(struct tree_node *n, u_char *result, size_t varlen, oid *target, + size_t targetlen, char *repr) { unsigned long int value; - fail_unless((targetlen == sizeof(lldp_oid)/sizeof(oid) + n->namelen) && - !memcmp(target, lldp_oid, sizeof(lldp_oid)) && - !memcmp(target + sizeof(lldp_oid)/sizeof(oid), - n->name, - n->namelen * sizeof(oid)), - "Bad OID returned when querying %s: got %s", repr, - snmp_oidrepr(target, targetlen)); + fail_unless((targetlen == sizeof(lldp_oid) / sizeof(oid) + n->namelen) && + !memcmp(target, lldp_oid, sizeof(lldp_oid)) && + !memcmp(target + sizeof(lldp_oid) / sizeof(oid), n->name, + n->namelen * sizeof(oid)), + "Bad OID returned when querying %s: got %s", repr, + snmp_oidrepr(target, targetlen)); switch (n->type) { case ASN_INTEGER: case ASN_TIMETICKS: case ASN_GAUGE: case ASN_COUNTER: fail_unless(varlen == sizeof(unsigned long int), - "Inappropriate length for integer type for OID %s", - repr); + "Inappropriate length for integer type for OID %s", repr); memcpy(&value, result, sizeof(value)); fail_unless(n->value.integer == value, - "For OID %s, expected value %u but got %u instead", - repr, - n->value.integer, - value); + "For OID %s, expected value %u but got %u instead", repr, + n->value.integer, value); break; default: fail_unless(((n->value.string.len == varlen) && - !memcmp(n->value.string.octet, - result, varlen)), - "OID %s: wanted %s, got %s", - repr, - tohex(n->value.string.octet, n->value.string.len), - tohex((char *)result, varlen)); + !memcmp(n->value.string.octet, result, varlen)), + "OID %s: wanted %s, got %s", repr, + tohex(n->value.string.octet, n->value.string.len), + tohex((char *)result, varlen)); } } -START_TEST (test_variable_order) +START_TEST(test_variable_order) { size_t i; for (i = 0; i < agent_lldp_vars_size() - 1; i++) { fail_unless(snmp_oid_compare(agent_lldp_vars[i].name, - agent_lldp_vars[i].namelen, - agent_lldp_vars[i+1].name, - agent_lldp_vars[i+1].namelen) < 0, - "Registered OID are out of orders (see %s and next one)", - snmp_oidrepr(agent_lldp_vars[i].name, - agent_lldp_vars[i].namelen)); + agent_lldp_vars[i].namelen, agent_lldp_vars[i + 1].name, + agent_lldp_vars[i + 1].namelen) < 0, + "Registered OID are out of orders (see %s and next one)", + snmp_oidrepr(agent_lldp_vars[i].name, agent_lldp_vars[i].namelen)); } } END_TEST -START_TEST (test_get) +START_TEST(test_get) { size_t j; - for (j = 0; - j < sizeof(snmp_tree)/sizeof(struct tree_node); - j++) { - size_t i; - int found = 0; + for (j = 0; j < sizeof(snmp_tree) / sizeof(struct tree_node); j++) { + size_t i; + int found = 0; struct variable vp; - oid target[MAX_OID_LEN]; - size_t targetlen; - size_t varlen; - u_char *result; - WriteMethod *wmethod; - char *repr = snmp_oidrepr(snmp_tree[j].name, - snmp_tree[j].namelen); + oid target[MAX_OID_LEN]; + size_t targetlen; + size_t varlen; + u_char *result; + WriteMethod *wmethod; + char *repr = snmp_oidrepr(snmp_tree[j].name, snmp_tree[j].namelen); for (i = 0; i < agent_lldp_vars_size(); i++) { /* Search for the appropriate prefix. */ if (!snmp_is_prefix_of(&agent_lldp_vars[i], &snmp_tree[j], - repr)) continue; + repr)) + continue; /* We have our prefix. Fill out the vp struct correctly. We need to complete OID with LLDP prefix. */ - snmp_merge(&agent_lldp_vars[i], &snmp_tree[j], &vp, target, &targetlen); + snmp_merge(&agent_lldp_vars[i], &snmp_tree[j], &vp, target, + &targetlen); /* Invoke the function */ - result = vp.findVar(&vp, target, &targetlen, 1, &varlen, &wmethod); + result = + vp.findVar(&vp, target, &targetlen, 1, &varlen, &wmethod); /* Check the result */ - fail_unless(result != NULL, - "No result when querying %s", repr); - snmp_compare(&snmp_tree[j], result, varlen, target, targetlen, repr); + fail_unless(result != NULL, "No result when querying %s", repr); + snmp_compare(&snmp_tree[j], result, varlen, target, targetlen, + repr); found = 1; break; } - if (!found) - fail("OID %s not found", repr); + if (!found) fail("OID %s not found", repr); } } END_TEST -START_TEST (test_getnext) +START_TEST(test_getnext) { size_t j; - size_t end = sizeof(snmp_tree)/sizeof(struct tree_node); - for (j = 0; - j < end; - j++) { - size_t i; + size_t end = sizeof(snmp_tree) / sizeof(struct tree_node); + for (j = 0; j < end; j++) { + size_t i; struct variable vp; - oid target[MAX_OID_LEN]; - size_t targetlen; - size_t varlen; - u_char *result = NULL; - WriteMethod *wmethod; - char *repr = snmp_oidrepr(snmp_tree[j].name, - snmp_tree[j].namelen); + oid target[MAX_OID_LEN]; + size_t targetlen; + size_t varlen; + u_char *result = NULL; + WriteMethod *wmethod; + char *repr = snmp_oidrepr(snmp_tree[j].name, snmp_tree[j].namelen); for (i = 0; i < agent_lldp_vars_size(); i++) { - snmp_merge(&agent_lldp_vars[i], &snmp_tree[j], &vp, target, &targetlen); - result = vp.findVar(&vp, target, &targetlen, 0, &varlen, &wmethod); + snmp_merge(&agent_lldp_vars[i], &snmp_tree[j], &vp, target, + &targetlen); + result = + vp.findVar(&vp, target, &targetlen, 0, &varlen, &wmethod); if (result) /* Check next! */ break; } if (!result) { - fail_unless(j == end - 1, - "No next result found for %s", repr); + fail_unless(j == end - 1, "No next result found for %s", repr); return; } - fail_unless(j < end - 1, - "More results after %s", repr); + fail_unless(j < end - 1, "More results after %s", repr); /* For unknown reasons, snmp_compare can be executed even when the above test fails... */ if (j < end - 1) - snmp_compare(&snmp_tree[j+1], result, varlen, target, targetlen, repr); - - } + snmp_compare(&snmp_tree[j + 1], result, varlen, target, + targetlen, repr); + } } END_TEST diff --git a/tests/check_sonmp.c b/tests/check_sonmp.c index b25f0e2f..92f5ab0a 100644 --- a/tests/check_sonmp.c +++ b/tests/check_sonmp.c @@ -26,11 +26,11 @@ char filenameprefix[] = "sonmp_send"; #ifdef ENABLE_SONMP -START_TEST (test_send_sonmp) +START_TEST(test_send_sonmp) { int n; /* Packet we should build: -IEEE 802.3 Ethernet +IEEE 802.3 Ethernet Destination: Bay-Networks-(Synoptics)-autodiscovery (01:00:81:00:01:00) Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad) Length: 19 @@ -40,8 +40,8 @@ Logical-Link Control SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) - 000. 00.. = Command: Unnumbered Information (0x00) - .... ..11 = Frame type: Unnumbered frame (0x03) + 000. 00.. = Command: Unnumbered Information (0x00) + .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Nortel Networks SONMP (0x000081) PID: SONMP segment hello (0x01a2) Nortel Networks / SynOptics Network Management Protocol @@ -52,7 +52,7 @@ Nortel Networks / SynOptics Network Management Protocol NMM state: New (3) Number of links: 1 -IEEE 802.3 Ethernet +IEEE 802.3 Ethernet Destination: Bay-Networks-(Synoptics)-autodiscovery (01:00:81:00:01:01) Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad) Length: 19 @@ -62,8 +62,8 @@ Logical-Link Control SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) - 000. 00.. = Command: Unnumbered Information (0x00) - .... ..11 = Frame type: Unnumbered frame (0x03) + 000. 00.. = Command: Unnumbered Information (0x00) + .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Nortel Networks SONMP (0x000081) PID: SONMP flatnet hello (0x01a1) Nortel Networks / SynOptics Network Management Protocol @@ -74,20 +74,14 @@ Nortel Networks / SynOptics Network Management Protocol NMM state: New (3) Number of links: 1 */ - char pkt1[] = { - 0x01, 0x00, 0x81, 0x00, 0x01, 0x00, 0x5e, 0x10, - 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x13, 0xaa, 0xaa, - 0x03, 0x00, 0x00, 0x81, 0x01, 0xa2, 0xac, 0x11, - 0x8e, 0x25, 0x00, 0x00, 0x04, 0x01, 0x0c, 0x03, - 0x01 }; - char pkt2[] = { - 0x01, 0x00, 0x81, 0x00, 0x01, 0x01, 0x5e, 0x10, - 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x13, 0xaa, 0xaa, - 0x03, 0x00, 0x00, 0x81, 0x01, 0xa1, 0xac, 0x11, - 0x8e, 0x25, 0x00, 0x00, 0x04, 0x01, 0x0c, 0x03, - 0x01 }; + char pkt1[] = { 0x01, 0x00, 0x81, 0x00, 0x01, 0x00, 0x5e, 0x10, 0x8e, 0xe7, + 0x84, 0xad, 0x00, 0x13, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x81, 0x01, 0xa2, + 0xac, 0x11, 0x8e, 0x25, 0x00, 0x00, 0x04, 0x01, 0x0c, 0x03, 0x01 }; + char pkt2[] = { 0x01, 0x00, 0x81, 0x00, 0x01, 0x01, 0x5e, 0x10, 0x8e, 0xe7, + 0x84, 0xad, 0x00, 0x13, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x81, 0x01, 0xa1, + 0xac, 0x11, 0x8e, 0x25, 0x00, 0x00, 0x04, 0x01, 0x0c, 0x03, 0x01 }; struct packet *pkt; - in_addr_t addr; + in_addr_t addr; struct lldpd_mgmt *mgmt; /* Populate port and chassis */ @@ -99,10 +93,8 @@ Nortel Networks / SynOptics Network Management Protocol chassis.c_id_len = ETHER_ADDR_LEN; TAILQ_INIT(&chassis.c_mgmt); addr = inet_addr("172.17.142.37"); - mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, - &addr, sizeof(in_addr_t), 0); - if (mgmt == NULL) - ck_abort(); + mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr, sizeof(in_addr_t), 0); + if (mgmt == NULL) ck_abort(); TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt, m_entries); /* Build packet */ @@ -129,19 +121,16 @@ Nortel Networks / SynOptics Network Management Protocol } END_TEST -START_TEST (test_recv_sonmp) +START_TEST(test_recv_sonmp) { - char pkt1[] = { - 0x01, 0x00, 0x81, 0x00, 0x01, 0x00, 0x00, 0x1b, - 0x25, 0x08, 0x50, 0x47, 0x00, 0x13, 0xaa, 0xaa, - 0x03, 0x00, 0x00, 0x81, 0x01, 0xa2, 0xac, 0x10, - 0x65, 0xa8, 0x00, 0x02, 0x08, 0x38, 0x0c, 0x02, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 }; + char pkt1[] = { 0x01, 0x00, 0x81, 0x00, 0x01, 0x00, 0x00, 0x1b, 0x25, 0x08, + 0x50, 0x47, 0x00, 0x13, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x81, 0x01, 0xa2, + 0xac, 0x10, 0x65, 0xa8, 0x00, 0x02, 0x08, 0x38, 0x0c, 0x02, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00 }; /* This is: -IEEE 802.3 Ethernet +IEEE 802.3 Ethernet Destination: Bay-Networks-(Synoptics)-autodiscovery (01:00:81:00:01:00) Source: Nortel_08:50:47 (00:1b:25:08:50:47) Length: 19 @@ -152,8 +141,8 @@ Logical-Link Control SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) - 000. 00.. = Command: Unnumbered Information (0x00) - .... ..11 = Frame type: Unnumbered frame (0x03) + 000. 00.. = Command: Unnumbered Information (0x00) + .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Nortel Networks SONMP (0x000081) PID: SONMP segment hello (0x01a2) Nortel Networks / SynOptics Network Management Protocol @@ -169,14 +158,13 @@ Nortel Networks / SynOptics Network Management Protocol char cid[5]; in_addr_t ip; - fail_unless(sonmp_decode(NULL, pkt1, sizeof(pkt1), &hardware, - &nchassis, &nport) != -1); + fail_unless( + sonmp_decode(NULL, pkt1, sizeof(pkt1), &hardware, &nchassis, &nport) != -1); if (!nchassis || !nport) { fail("unable to decode packet"); return; } - ck_assert_int_eq(nchassis->c_id_subtype, - LLDP_CHASSISID_SUBTYPE_ADDR); + ck_assert_int_eq(nchassis->c_id_subtype, LLDP_CHASSISID_SUBTYPE_ADDR); ck_assert_int_eq(nchassis->c_id_len, 5); cid[0] = 1; ip = inet_addr("172.16.101.168"); @@ -188,11 +176,9 @@ Nortel Networks / SynOptics Network Management Protocol (u_int32_t)inet_addr("172.16.101.168")); ck_assert_int_eq(TAILQ_FIRST(&nchassis->c_mgmt)->m_iface, 0); ck_assert_str_eq(nport->p_descr, "port 2/8"); - ck_assert_int_eq(nport->p_id_subtype, - LLDP_PORTID_SUBTYPE_LOCAL); + ck_assert_int_eq(nport->p_id_subtype, LLDP_PORTID_SUBTYPE_LOCAL); ck_assert_int_eq(nport->p_id_len, strlen("00-02-08")); - fail_unless(memcmp(nport->p_id, - "00-02-08", strlen("00-02-08")) == 0); + fail_unless(memcmp(nport->p_id, "00-02-08", strlen("00-02-08")) == 0); ck_assert_int_eq(nchassis->c_cap_enabled, 0); } END_TEST @@ -223,13 +209,13 @@ int main() { int number_failed; - Suite *s = sonmp_suite (); - SRunner *sr = srunner_create (s); - srunner_set_fork_status (sr, CK_NOFORK); /* Can't fork because - we need to write - files */ - srunner_run_all (sr, CK_ENV); - number_failed = srunner_ntests_failed (sr); - srunner_free (sr); + Suite *s = sonmp_suite(); + SRunner *sr = srunner_create(s); + srunner_set_fork_status(sr, CK_NOFORK); /* Can't fork because + we need to write + files */ + srunner_run_all(sr, CK_ENV); + number_failed = srunner_ntests_failed(sr); + srunner_free(sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/common.c b/tests/common.c index a077eb73..cf5ca344 100644 --- a/tests/common.c +++ b/tests/common.c @@ -33,8 +33,7 @@ struct lldpd_hardware hardware; struct lldpd_chassis chassis; int -pcap_send(struct lldpd *cfg, struct lldpd_hardware *hardware, - char *buffer, size_t size) +pcap_send(struct lldpd *cfg, struct lldpd_hardware *hardware, char *buffer, size_t size) { struct pcaprec_hdr hdr; struct packet *pkt; @@ -58,7 +57,8 @@ pcap_send(struct lldpd *cfg, struct lldpd_hardware *hardware, } /* Append to list of packets */ - pkt = (struct packet *)malloc(size + sizeof(TAILQ_HEAD(,packet)) + sizeof(int)); + pkt = + (struct packet *)malloc(size + sizeof(TAILQ_HEAD(, packet)) + sizeof(int)); if (!pkt) { fail("unable to allocate packet"); return -1; @@ -71,11 +71,10 @@ pcap_send(struct lldpd *cfg, struct lldpd_hardware *hardware, struct lldpd_ops pcap_ops = { .send = pcap_send, - .recv = NULL, /* Won't be used */ - .cleanup = NULL, /* Won't be used */ + .recv = NULL, /* Won't be used */ + .cleanup = NULL, /* Won't be used */ }; - void pcap_setup() { @@ -130,9 +129,7 @@ void pcap_teardown() { struct packet *npkt, *pkt; - for (pkt = TAILQ_FIRST(&pkts); - pkt != NULL; - pkt = npkt) { + for (pkt = TAILQ_FIRST(&pkts); pkt != NULL; pkt = npkt) { npkt = TAILQ_NEXT(pkt, next); TAILQ_REMOVE(&pkts, pkt, next); free(pkt); @@ -148,6 +145,8 @@ pcap_teardown() } /* Disable leak detection sanitizer */ -int __lsan_is_turned_off() { +int +__lsan_is_turned_off() +{ return 1; } diff --git a/tests/common.h b/tests/common.h index 03dd5fe5..76fec92c 100644 --- a/tests/common.h +++ b/tests/common.h @@ -29,10 +29,10 @@ struct packet { }; TAILQ_HEAD(pkts_t, packet); -extern int dump; /* Dump file descriptor in pcap format */ -extern char filenameprefix[]; /* Prefix for filename dumping */ -extern char *filename; /* Filename we are dumping to */ -extern char macaddress[]; /* MAC address we use to send */ +extern int dump; /* Dump file descriptor in pcap format */ +extern char filenameprefix[]; /* Prefix for filename dumping */ +extern char *filename; /* Filename we are dumping to */ +extern char macaddress[]; /* MAC address we use to send */ extern struct pkts_t pkts; /* List of sent packets */ extern struct lldpd_hardware hardware; diff --git a/tests/decode.c b/tests/decode.c index 6ab0829f..85e5a070 100644 --- a/tests/decode.c +++ b/tests/decode.c @@ -40,26 +40,30 @@ usage(void) exit(1); } -char* +char * tohex(char *str, size_t len) { static char *hex = NULL; - free(hex); hex = NULL; + free(hex); + hex = NULL; if ((hex = malloc(len * 3 + 1)) == NULL) return NULL; for (size_t i = 0; i < len; i++) - snprintf(hex + 3*i, 4, "%02X ", (unsigned char)str[i]); + snprintf(hex + 3 * i, 4, "%02X ", (unsigned char)str[i]); return hex; } /* We need an assert macro which doesn't abort */ -#define assert(x) while (!(x)) { \ - fprintf(stderr, "%s:%d: %s: Assertion `%s' failed.\n", \ - __FILE__, __LINE__, __func__, #x); \ - exit(5); \ - } +#define assert(x) \ + while (!(x)) { \ + fprintf(stderr, "%s:%d: %s: Assertion `%s' failed.\n", __FILE__, __LINE__, \ + __func__, #x); \ + exit(5); \ + } -int decode(char *frame, int size, - struct lldpd_hardware *hardware, struct lldpd_chassis **nchassis, struct lldpd_port **nport) { +int +decode(char *frame, int size, struct lldpd_hardware *hardware, + struct lldpd_chassis **nchassis, struct lldpd_port **nport) +{ /* For decoding, we only need a very basic hardware */ memset(hardware, 0, sizeof(struct lldpd_hardware)); hardware->h_mtu = 1500; @@ -101,20 +105,23 @@ int decode(char *frame, int size, #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -#define kMinInputLength 30 -#define kMaxInputLength 1500 +# define kMinInputLength 30 +# define kMaxInputLength 1500 -extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - if (size < kMinInputLength || size > kMaxInputLength){ +extern int +LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (size < kMinInputLength || size > kMaxInputLength) { return 0; } struct lldpd_hardware hardware; struct lldpd_chassis *nchassis = NULL; struct lldpd_port *nport = NULL; - if (!decode((char*)data, (int)size, &hardware, &nchassis, &nport)) { + if (!decode((char *)data, (int)size, &hardware, &nchassis, &nport)) { return -1; } - lldpd_port_cleanup(nport, 1); free(nport); + lldpd_port_cleanup(nport, 1); + free(nport); lldpd_chassis_cleanup(nchassis, 1); return 0; } @@ -124,10 +131,7 @@ extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { int main(int argc, char **argv) { - if (argc != 2 || - !strcmp(argv[1], "-h") || - !strcmp(argv[1], "--help")) - usage(); + if (argc != 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) usage(); int fd = open(argv[1], O_RDONLY); assert(fd != -1); @@ -153,7 +157,8 @@ main(int argc, char **argv) struct lldpd_hardware hardware; struct lldpd_chassis *nchassis = NULL; struct lldpd_port *nport = NULL; - if (!decode(buf + sizeof(hdr) + sizeof(rechdr), rechdr.incl_len, &hardware, &nchassis, &nport)) + if (!decode(buf + sizeof(hdr) + sizeof(rechdr), rechdr.incl_len, &hardware, + &nchassis, &nport)) exit(1); printf("Chassis:\n"); @@ -161,18 +166,19 @@ main(int argc, char **argv) printf(" Protocol: %" PRIu8 "\n", nchassis->c_protocol); printf(" ID subtype: %" PRIu8 "\n", nchassis->c_id_subtype); printf(" ID: %s\n", tohex(nchassis->c_id, nchassis->c_id_len)); - printf(" Name: %s\n", nchassis->c_name?nchassis->c_name:"(null)"); - printf(" Description: %s\n", nchassis->c_descr?nchassis->c_descr:"(null)"); + printf(" Name: %s\n", nchassis->c_name ? nchassis->c_name : "(null)"); + printf(" Description: %s\n", nchassis->c_descr ? nchassis->c_descr : "(null)"); printf(" Cap available: %" PRIu16 "\n", nchassis->c_cap_available); printf(" Cap enabled: %" PRIu16 "\n", nchassis->c_cap_enabled); struct lldpd_mgmt *mgmt; - TAILQ_FOREACH(mgmt, &nchassis->c_mgmt, m_entries) { + TAILQ_FOREACH (mgmt, &nchassis->c_mgmt, m_entries) { char ipaddress[INET6_ADDRSTRLEN + 1]; - int af; size_t alen; + int af; + size_t alen; switch (mgmt->m_family) { case LLDPD_AF_IPV4: alen = INET_ADDRSTRLEN + 1; - af = AF_INET; + af = AF_INET; break; case LLDPD_AF_IPV6: alen = INET6_ADDRSTRLEN + 1; @@ -182,33 +188,38 @@ main(int argc, char **argv) len = 0; } if (len == 0) continue; - if (inet_ntop(af, &mgmt->m_addr, ipaddress, alen) == NULL) - break; + if (inet_ntop(af, &mgmt->m_addr, ipaddress, alen) == NULL) break; printf(" mgmt: %s\n", ipaddress); } -#ifdef ENABLE_LLDPMED +# ifdef ENABLE_LLDPMED printf(" MED cap: %" PRIu16 "\n", nchassis->c_med_cap_available); printf(" MED type: %" PRIu8 "\n", nchassis->c_med_type); - printf(" MED HW: %s\n", nchassis->c_med_hw?nchassis->c_med_hw:"(null)"); - printf(" MED FW: %s\n", nchassis->c_med_fw?nchassis->c_med_fw:"(null)"); - printf(" MED SW: %s\n", nchassis->c_med_sw?nchassis->c_med_sw:"(null)"); - printf(" MED SN: %s\n", nchassis->c_med_sn?nchassis->c_med_sn:"(null)"); - printf(" MED manufacturer: %s\n", nchassis->c_med_manuf?nchassis->c_med_manuf:"(null)"); - printf(" MED model: %s\n", nchassis->c_med_model?nchassis->c_med_model:"(null)"); - printf(" MED asset: %s\n", nchassis->c_med_asset?nchassis->c_med_asset:"(null)"); -#endif + printf(" MED HW: %s\n", nchassis->c_med_hw ? nchassis->c_med_hw : "(null)"); + printf(" MED FW: %s\n", nchassis->c_med_fw ? nchassis->c_med_fw : "(null)"); + printf(" MED SW: %s\n", nchassis->c_med_sw ? nchassis->c_med_sw : "(null)"); + printf(" MED SN: %s\n", nchassis->c_med_sn ? nchassis->c_med_sn : "(null)"); + printf(" MED manufacturer: %s\n", + nchassis->c_med_manuf ? nchassis->c_med_manuf : "(null)"); + printf(" MED model: %s\n", + nchassis->c_med_model ? nchassis->c_med_model : "(null)"); + printf(" MED asset: %s\n", + nchassis->c_med_asset ? nchassis->c_med_asset : "(null)"); +# endif printf("Port:\n"); printf(" ID subtype: %" PRIu8 "\n", nport->p_id_subtype); printf(" ID: %s\n", tohex(nport->p_id, nport->p_id_len)); - printf(" Description: %s\n", nport->p_descr?nport->p_descr:"(null)"); + printf(" Description: %s\n", nport->p_descr ? nport->p_descr : "(null)"); printf(" MFS: %" PRIu16 "\n", nport->p_mfs); printf(" TTL: %" PRIu16 "\n", nport->p_ttl); -#ifdef ENABLE_DOT3 +# ifdef ENABLE_DOT3 printf(" Dot3 aggrID: %" PRIu32 "\n", nport->p_aggregid); - printf(" Dot3 MAC/phy autoneg supported: %" PRIu8 "\n", nport->p_macphy.autoneg_support); - printf(" Dot3 MAC/phy autoneg enabled: %" PRIu8 "\n", nport->p_macphy.autoneg_enabled); - printf(" Dot3 MAC/phy autoneg advertised: %" PRIu16 "\n", nport->p_macphy.autoneg_advertised); + printf(" Dot3 MAC/phy autoneg supported: %" PRIu8 "\n", + nport->p_macphy.autoneg_support); + printf(" Dot3 MAC/phy autoneg enabled: %" PRIu8 "\n", + nport->p_macphy.autoneg_enabled); + printf(" Dot3 MAC/phy autoneg advertised: %" PRIu16 "\n", + nport->p_macphy.autoneg_advertised); printf(" Dot3 MAC/phy MAU type: %" PRIu16 "\n", nport->p_macphy.mau_type); printf(" Dot3 power device type: %" PRIu8 "\n", nport->p_power.devicetype); printf(" Dot3 power supported: %" PRIu8 "\n", nport->p_power.supported); @@ -221,55 +232,60 @@ main(int argc, char **argv) printf(" Dot3 power priority: %" PRIu8 "\n", nport->p_power.priority); printf(" Dot3 power requested: %" PRIu16 "\n", nport->p_power.requested); printf(" Dot3 power allocated: %" PRIu16 "\n", nport->p_power.allocated); -#endif -#ifdef ENABLE_LLDPMED +# endif +# ifdef ENABLE_LLDPMED printf(" MED cap: %" PRIu16 "\n", nport->p_med_cap_enabled); for (int i = 0; i < LLDP_MED_APPTYPE_LAST; i++) { if (nport->p_med_policy[i].type == 0) continue; printf(" MED policy type: %" PRIu8 "\n", nport->p_med_policy[i].type); - printf(" MED policy unknown: %" PRIu8 "\n", nport->p_med_policy[i].unknown); - printf(" MED policy tagged: %" PRIu8 "\n", nport->p_med_policy[i].tagged); + printf(" MED policy unknown: %" PRIu8 "\n", + nport->p_med_policy[i].unknown); + printf(" MED policy tagged: %" PRIu8 "\n", + nport->p_med_policy[i].tagged); printf(" MED policy vid: %" PRIu16 "\n", nport->p_med_policy[i].vid); - printf(" MED policy priority: %" PRIu8 "\n", nport->p_med_policy[i].priority); + printf(" MED policy priority: %" PRIu8 "\n", + nport->p_med_policy[i].priority); printf(" MED policy dscp: %" PRIu8 "\n", nport->p_med_policy[i].dscp); } for (int i = 0; i < LLDP_MED_LOCFORMAT_LAST; i++) { if (nport->p_med_location[i].format == 0) continue; - printf(" MED location format: %" PRIu8 "\n", nport->p_med_location[i].format); - printf(" MED location: %s\n", tohex(nport->p_med_location[i].data, + printf(" MED location format: %" PRIu8 "\n", + nport->p_med_location[i].format); + printf(" MED location: %s\n", + tohex(nport->p_med_location[i].data, nport->p_med_location[i].data_len)); } printf(" MED power device type: %" PRIu8 "\n", nport->p_med_power.devicetype); printf(" MED power source: %" PRIu8 "\n", nport->p_med_power.source); printf(" MED power priority: %" PRIu8 "\n", nport->p_med_power.priority); printf(" MED power value: %" PRIu16 "\n", nport->p_med_power.val); -#endif -#ifdef ENABLE_DOT1 +# endif +# ifdef ENABLE_DOT1 printf(" Dot1 PVID: %" PRIu16 "\n", nport->p_pvid); struct lldpd_vlan *vlan; - TAILQ_FOREACH(vlan, &nport->p_vlans, v_entries) { + TAILQ_FOREACH (vlan, &nport->p_vlans, v_entries) { printf(" Dot1 VLAN: %s (%" PRIu16 ")\n", vlan->v_name, vlan->v_vid); } struct lldpd_ppvid *ppvid; - TAILQ_FOREACH(ppvid, &nport->p_ppvids, p_entries) { + TAILQ_FOREACH (ppvid, &nport->p_ppvids, p_entries) { printf(" Dot1 PPVID: %" PRIu16 " (status: %" PRIu8 ")\n", ppvid->p_ppvid, ppvid->p_cap_status); } struct lldpd_pi *pid; - TAILQ_FOREACH(pid, &nport->p_pids, p_entries) { + TAILQ_FOREACH (pid, &nport->p_pids, p_entries) { printf(" Dot1 PI: %s\n", tohex(pid->p_pi, pid->p_pi_len)); } -#endif -#ifdef ENABLE_CUSTOM +# endif +# ifdef ENABLE_CUSTOM struct lldpd_custom *custom; - TAILQ_FOREACH(custom, &nport->p_custom_list, next) { + TAILQ_FOREACH (custom, &nport->p_custom_list, next) { printf(" Custom OUI: %s\n", - tohex((char*)custom->oui, sizeof(custom->oui))); + tohex((char *)custom->oui, sizeof(custom->oui))); printf(" Custom subtype: %" PRIu8 "\n", custom->subtype); printf(" Custom info: %s\n", - tohex((char*)custom->oui_info, custom->oui_info_len)); + tohex((char *)custom->oui_info, custom->oui_info_len)); } -#endif +# endif exit(0); } diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 3a7209c6..d4eba38b 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,4 +1,4 @@ -pytest_plugins = ['helpers_namespace'] +pytest_plugins = ["helpers_namespace"] import pytest import scapy.all @@ -8,14 +8,14 @@ from fixtures.namespaces import * from fixtures.network import * -@pytest.fixture(autouse=True, scope='session') +@pytest.fixture(autouse=True, scope="session") def root(): """Ensure we are somewhat root.""" # We could do a user namespace but there are too many # restrictions: we cannot do arbitrary user mapping and therefore, # this doesn't play well with privilege separation and the use of # _lldpd. Just do a plain namespace. - with Namespace('pid', 'net', 'mnt', 'ipc', 'uts'): + with Namespace("pid", "net", "mnt", "ipc", "uts"): yield diff --git a/tests/integration/fixtures/namespaces.py b/tests/integration/fixtures/namespaces.py index 0ee40d38..248aff30 100644 --- a/tests/integration/fixtures/namespaces.py +++ b/tests/integration/fixtures/namespaces.py @@ -8,15 +8,17 @@ import signal import multiprocessing # All allowed namespace types -NAMESPACE_FLAGS = dict(mnt=0x00020000, - uts=0x04000000, - ipc=0x08000000, - user=0x10000000, - pid=0x20000000, - net=0x40000000) -STACKSIZE = 1024*1024 +NAMESPACE_FLAGS = dict( + mnt=0x00020000, + uts=0x04000000, + ipc=0x08000000, + user=0x10000000, + pid=0x20000000, + net=0x40000000, +) +STACKSIZE = 1024 * 1024 -libc = ctypes.CDLL('libc.so.6', use_errno=True) +libc = ctypes.CDLL("libc.so.6", use_errno=True) @contextlib.contextmanager @@ -30,15 +32,11 @@ def keep_directory(): def mount_sys(target="/sys"): - flags = [2 | 4 | 8] # MS_NOSUID | MS_NODEV | MS_NOEXEC - flags.append(1 << 18) # MS_PRIVATE - flags.append(1 << 19) # MS_SLAVE + flags = [2 | 4 | 8] # MS_NOSUID | MS_NODEV | MS_NOEXEC + flags.append(1 << 18) # MS_PRIVATE + flags.append(1 << 19) # MS_SLAVE for fl in flags: - ret = libc.mount(b"none", - target.encode('ascii'), - b"sysfs", - fl, - None) + ret = libc.mount(b"none", target.encode("ascii"), b"sysfs", fl, None) if ret == -1: e = ctypes.get_errno() raise OSError(e, os.strerror(e)) @@ -47,29 +45,21 @@ def mount_sys(target="/sys"): def mount_tmpfs(target, private=False): flags = [0] if private: - flags.append(1 << 18) # MS_PRIVATE - flags.append(1 << 19) # MS_SLAVE + flags.append(1 << 18) # MS_PRIVATE + flags.append(1 << 19) # MS_SLAVE for fl in flags: - ret = libc.mount(b"none", - target.encode('ascii'), - b"tmpfs", - fl, - None) + ret = libc.mount(b"none", target.encode("ascii"), b"tmpfs", fl, None) if ret == -1: e = ctypes.get_errno() raise OSError(e, os.strerror(e)) def _mount_proc(target): - flags = [2 | 4 | 8] # MS_NOSUID | MS_NODEV | MS_NOEXEC - flags.append(1 << 18) # MS_PRIVATE - flags.append(1 << 19) # MS_SLAVE + flags = [2 | 4 | 8] # MS_NOSUID | MS_NODEV | MS_NOEXEC + flags.append(1 << 18) # MS_PRIVATE + flags.append(1 << 19) # MS_SLAVE for fl in flags: - ret = libc.mount(b"proc", - target.encode('ascii'), - b"proc", - fl, - None) + ret = libc.mount(b"proc", target.encode("ascii"), b"proc", fl, None) if ret == -1: e = ctypes.get_errno() raise OSError(e, os.strerror(e)) @@ -106,8 +96,8 @@ class Namespace(object): child = ctypes.CFUNCTYPE(ctypes.c_int)(self.child) child_stack = ctypes.create_string_buffer(STACKSIZE) child_stack_pointer = ctypes.c_void_p( - ctypes.cast(child_stack, - ctypes.c_void_p).value + STACKSIZE) + ctypes.cast(child_stack, ctypes.c_void_p).value + STACKSIZE + ) flags = signal.SIGCHLD for ns in namespaces: flags |= NAMESPACE_FLAGS[ns] @@ -117,27 +107,29 @@ class Namespace(object): raise OSError(e, os.strerror(e)) # If a user namespace, map UID 0 to the current one - if 'user' in namespaces: - uid_map = '0 {} 1'.format(os.getuid()) - gid_map = '0 {} 1'.format(os.getgid()) - with open('/proc/{}/uid_map'.format(pid), 'w') as f: + if "user" in namespaces: + uid_map = "0 {} 1".format(os.getuid()) + gid_map = "0 {} 1".format(os.getgid()) + with open("/proc/{}/uid_map".format(pid), "w") as f: f.write(uid_map) - with open('/proc/{}/setgroups'.format(pid), 'w') as f: - f.write('deny') - with open('/proc/{}/gid_map'.format(pid), 'w') as f: + with open("/proc/{}/setgroups".format(pid), "w") as f: + f.write("deny") + with open("/proc/{}/gid_map".format(pid), "w") as f: f.write(gid_map) # Retrieve a file descriptor to this new namespace - self.next = [os.open('/proc/{}/ns/{}'.format(pid, x), - os.O_RDONLY) for x in namespaces] + self.next = [ + os.open("/proc/{}/ns/{}".format(pid, x), os.O_RDONLY) for x in namespaces + ] # Keep a file descriptor to our old namespaces - self.previous = [os.open('/proc/self/ns/{}'.format(x), - os.O_RDONLY) for x in namespaces] + self.previous = [ + os.open("/proc/self/ns/{}".format(x), os.O_RDONLY) for x in namespaces + ] # Tell the child all is done and let it die os.close(self.pipe[0]) - if 'pid' not in namespaces: + if "pid" not in namespaces: os.close(self.pipe[1]) self.pipe = None os.waitpid(pid, 0) @@ -160,16 +152,20 @@ class Namespace(object): os.close(self.pipe[1]) # For a network namespace, enable lo - if 'net' in self.namespaces: + if "net" in self.namespaces: with pyroute2.IPRoute() as ipr: - lo = ipr.link_lookup(ifname='lo')[0] - ipr.link('set', index=lo, state='up') + lo = ipr.link_lookup(ifname="lo")[0] + ipr.link("set", index=lo, state="up") # For a mount namespace, make it private - if 'mnt' in self.namespaces: - libc.mount(b"none", b"/", None, - # MS_REC | MS_PRIVATE - 16384 | (1 << 18), - None) + if "mnt" in self.namespaces: + libc.mount( + b"none", + b"/", + None, + # MS_REC | MS_PRIVATE + 16384 | (1 << 18), + None, + ) while True: try: @@ -206,7 +202,7 @@ class Namespace(object): raise err def __repr__(self): - return 'Namespace({})'.format(", ".join(self.namespaces)) + return "Namespace({})".format(", ".join(self.namespaces)) class NamespaceFactory(object): @@ -230,7 +226,7 @@ class NamespaceFactory(object): if ns in self.namespaces: return self.namespaces[ns] - self.namespaces[ns] = Namespace('ipc', 'net', 'mnt', 'uts') + self.namespaces[ns] = Namespace("ipc", "net", "mnt", "uts") with self.namespaces[ns]: mount_proc() mount_sys() diff --git a/tests/integration/fixtures/network.py b/tests/integration/fixtures/network.py index 50f6b128..81f66a97 100644 --- a/tests/integration/fixtures/network.py +++ b/tests/integration/fixtures/network.py @@ -9,8 +9,9 @@ from .namespaces import Namespace def int_to_mac(c): """Turn an int into a MAC address.""" - return ":".join(('{:02x}',)*6).format( - *struct.unpack('BBBBBB', c.to_bytes(6, byteorder='big'))) + return ":".join(("{:02x}",) * 6).format( + *struct.unpack("BBBBBB", c.to_bytes(6, byteorder="big")) + ) class LinksFactory(object): @@ -24,7 +25,7 @@ class LinksFactory(object): def __init__(self): # We create all those links in a dedicated namespace to avoid # conflict with other namespaces. - self.ns = Namespace('net') + self.ns = Namespace("net") self.count = 0 def __call__(self, *args, **kwargs): @@ -34,38 +35,32 @@ class LinksFactory(object): """Create a veth pair between two namespaces.""" with self.ns: # First, create a link - first = 'eth{}'.format(self.count) - second = 'eth{}'.format(self.count + 1) + first = "eth{}".format(self.count) + second = "eth{}".format(self.count + 1) with pyroute2.IPRoute() as ipr: - ipr.link('add', - ifname=first, - peer=second, - kind='veth') - idx = [ipr.link_lookup(ifname=x)[0] - for x in (first, second)] + ipr.link("add", ifname=first, peer=second, kind="veth") + idx = [ipr.link_lookup(ifname=x)[0] for x in (first, second)] # Set an easy to remember MAC address - ipr.link('set', index=idx[0], - address=int_to_mac(self.count + 1)) - ipr.link('set', index=idx[1], - address=int_to_mac(self.count + 2)) + ipr.link("set", index=idx[0], address=int_to_mac(self.count + 1)) + ipr.link("set", index=idx[1], address=int_to_mac(self.count + 2)) # Set MTU - ipr.link('set', index=idx[0], mtu=mtu) - ipr.link('set', index=idx[1], mtu=mtu) + ipr.link("set", index=idx[0], mtu=mtu) + ipr.link("set", index=idx[1], mtu=mtu) # Then, move each to the target namespace - ipr.link('set', index=idx[0], net_ns_fd=ns1.fd('net')) - ipr.link('set', index=idx[1], net_ns_fd=ns2.fd('net')) + ipr.link("set", index=idx[0], net_ns_fd=ns1.fd("net")) + ipr.link("set", index=idx[1], net_ns_fd=ns2.fd("net")) # And put them up with ns1: with pyroute2.IPRoute() as ipr: - ipr.link('set', index=idx[0], state='up') + ipr.link("set", index=idx[0], state="up") time.sleep(sleep) with ns2: with pyroute2.IPRoute() as ipr: - ipr.link('set', index=idx[1], state='up') + ipr.link("set", index=idx[1], state="up") self.count += 2 @@ -73,34 +68,29 @@ class LinksFactory(object): """Create a bridge.""" with pyroute2.IPRoute() as ipr: # Create the bridge - ipr.link('add', - ifname=name, - kind='bridge', - br_vlan_filtering=filtering) + ipr.link("add", ifname=name, kind="bridge", br_vlan_filtering=filtering) idx = ipr.link_lookup(ifname=name)[0] # Attach interfaces for iface in ifaces: port = ipr.link_lookup(ifname=iface)[0] - ipr.link('set', index=port, master=idx) + ipr.link("set", index=port, master=idx) # Put the bridge up - ipr.link('set', index=idx, state='up') + ipr.link("set", index=idx, state="up") return idx def _bond_or_team(self, kind, name, *ifaces): """Create a bond or a team.""" with pyroute2.RawIPRoute() as ipr: # Create the bond - ipr.link('add', - ifname=name, - kind=kind) + ipr.link("add", ifname=name, kind=kind) idx = ipr.link_lookup(ifname=name)[0] # Attach interfaces for iface in ifaces: slave = ipr.link_lookup(ifname=iface)[0] - ipr.link('set', index=slave, state='down') - ipr.link('set', index=slave, master=idx) + ipr.link("set", index=slave, state="down") + ipr.link("set", index=slave, master=idx) # Put the bond up - ipr.link('set', index=idx, state='up') + ipr.link("set", index=idx, state="up") return idx def team(self, name, *ifaces): @@ -116,22 +106,18 @@ class LinksFactory(object): def dummy(self, name): """Create a dummy interface.""" with pyroute2.IPRoute() as ipr: - ipr.link('add', ifname=name, kind='dummy') + ipr.link("add", ifname=name, kind="dummy") idx = ipr.link_lookup(ifname=name)[0] - ipr.link('set', index=idx, state='up') + ipr.link("set", index=idx, state="up") return idx def vlan(self, name, id, iface): """Create a VLAN.""" with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname=iface)[0] - ipr.link('add', - ifname=name, - kind='vlan', - vlan_id=id, - link=idx) + ipr.link("add", ifname=name, kind="vlan", vlan_id=id, link=idx) idx = ipr.link_lookup(ifname=name)[0] - ipr.link('set', index=idx, state='up') + ipr.link("set", index=idx, state="up") return idx def bridge_vlan(self, iface, vid, tagged=True, pvid=False, remove=False): @@ -139,38 +125,38 @@ class LinksFactory(object): idx = ipr.link_lookup(ifname=iface)[0] flags = [] if not tagged: - flags.append('untagged') + flags.append("untagged") if pvid: - flags.append('pvid') + flags.append("pvid") if not remove: - ipr.vlan_filter('del', index=idx, vlan_info={"vid": 1}) - ipr.vlan_filter('add' if not remove else 'del', index=idx, - vlan_info={'vid': vid, - 'flags': flags}) + ipr.vlan_filter("del", index=idx, vlan_info={"vid": 1}) + ipr.vlan_filter( + "add" if not remove else "del", + index=idx, + vlan_info={"vid": vid, "flags": flags}, + ) def up(self, name): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname=name)[0] - ipr.link('set', index=idx, state='up') + ipr.link("set", index=idx, state="up") def down(self, name): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname=name)[0] - ipr.link('set', index=idx, state='down') + ipr.link("set", index=idx, state="down") def remove(self, name): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname=name)[0] - ipr.link('del', index=idx) + ipr.link("del", index=idx) def unbridge(self, bridgename, name): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname=name)[0] s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) ifr = struct.pack("16si", b"br42", idx) - fcntl.ioctl(s, - 0x89a3, # SIOCBRDELIF - ifr) + fcntl.ioctl(s, 0x89A3, ifr) # SIOCBRDELIF s.close() diff --git a/tests/integration/fixtures/programs.py b/tests/integration/fixtures/programs.py index e389c011..de162f63 100644 --- a/tests/integration/fixtures/programs.py +++ b/tests/integration/fixtures/programs.py @@ -15,15 +15,13 @@ from collections import namedtuple from .namespaces import mount_proc, mount_tmpfs -libc = ctypes.CDLL('libc.so.6', use_errno=True) +libc = ctypes.CDLL("libc.so.6", use_errno=True) def mount_bind(source, target): - ret = libc.mount(source.encode('ascii'), - target.encode('ascii'), - None, - 4096, # MS_BIND - None) + ret = libc.mount( + source.encode("ascii"), target.encode("ascii"), None, 4096, None # MS_BIND + ) if ret == -1: e = ctypes.get_errno() raise OSError(e, os.strerror(e)) @@ -32,28 +30,22 @@ def mount_bind(source, target): def most_recent(*args): """Return the most recent files matching one of the provided glob expression.""" - candidates = [l - for location in args - for l in glob.glob(location)] + candidates = [l for location in args for l in glob.glob(location)] candidates.sort(key=lambda x: os.stat(x).st_mtime) assert len(candidates) > 0 return candidates[0] -libtool_location = most_recent('../../libtool', - '../../*/libtool') -lldpcli_location = most_recent('../../src/client/lldpcli', - '../../*/src/client/lldpcli') -lldpd_location = most_recent('../../src/daemon/lldpd', - '../../*/src/daemon/lldpd') +libtool_location = most_recent("../../libtool", "../../*/libtool") +lldpcli_location = most_recent("../../src/client/lldpcli", "../../*/src/client/lldpcli") +lldpd_location = most_recent("../../src/daemon/lldpd", "../../*/src/daemon/lldpd") def _replace_file(tmpdir, target, content): tmpname = str(uuid.uuid1()) with tmpdir.join(tmpname).open("w") as tmp: tmp.write(content) - mount_bind(str(tmpdir.join(tmpname)), - target) + mount_bind(str(tmpdir.join(tmpname)), target) @pytest.fixture @@ -64,17 +56,26 @@ def replace_file(tmpdir): def format_process_output(program, args, result): """Return a string representing the result of a process.""" - return "\n".join([ - 'P: {} {}'.format(program, " ".join(args)), - 'C: {}'.format(os.getcwd()), - '\n'.join(['O: {}'.format(l) - for l in result.stdout.decode( - 'ascii', 'ignore').strip().split('\n')]), - '\n'.join(['E: {}'.format(l) - for l in result.stderr.decode( - 'ascii', 'ignore').strip().split('\n')]), - 'S: {}'.format(result.returncode), - '']) + return "\n".join( + [ + "P: {} {}".format(program, " ".join(args)), + "C: {}".format(os.getcwd()), + "\n".join( + [ + "O: {}".format(l) + for l in result.stdout.decode("ascii", "ignore").strip().split("\n") + ] + ), + "\n".join( + [ + "E: {}".format(l) + for l in result.stderr.decode("ascii", "ignore").strip().split("\n") + ] + ), + "S: {}".format(result.returncode), + "", + ] + ) class LldpdFactory(object): @@ -83,9 +84,10 @@ class LldpdFactory(object): the background. On termination, output will be logged to temporary file. """ + def __init__(self, tmpdir, config): """Create a new wrapped program.""" - tmpdir.join('lldpd-outputs').ensure(dir=True) + tmpdir.join("lldpd-outputs").ensure(dir=True) self.tmpdir = tmpdir self.config = config self.pids = [] @@ -95,14 +97,18 @@ class LldpdFactory(object): def __call__(self, *args, sleep=3, silent=False): self.counter += 1 self.setup_namespace("ns-{}".format(self.counter)) - args = (self.config.option.verbose > 2 and "-dddd" or "-dd", - "-L", - lldpcli_location, - "-u", - str(self.tmpdir.join("ns", "lldpd.socket"))) + args - p = subprocess.Popen((libtool_location, 'execute', - lldpd_location) + args, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + args = ( + self.config.option.verbose > 2 and "-dddd" or "-dd", + "-L", + lldpcli_location, + "-u", + str(self.tmpdir.join("ns", "lldpd.socket")), + ) + args + p = subprocess.Popen( + (libtool_location, "execute", lldpd_location) + args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) self.pids.append(p.pid) t = multiprocessing.Process(target=self.run, args=(p, args, silent)) self.threads.append(t) @@ -114,18 +120,16 @@ class LldpdFactory(object): stdout, stderr = p.communicate() self.pids.remove(p.pid) if not silent: - o = format_process_output("lldpd", - args, - namedtuple('ProcessResult', - ['returncode', - 'stdout', - 'stderr'])( - p.returncode, - stdout, - stderr)) - self.tmpdir.join('lldpd-outputs', '{}-{}'.format( - os.getpid(), - p.pid)).write(o) + o = format_process_output( + "lldpd", + args, + namedtuple("ProcessResult", ["returncode", "stdout", "stderr"])( + p.returncode, stdout, stderr + ), + ) + self.tmpdir.join("lldpd-outputs", "{}-{}".format(os.getpid(), p.pid)).write( + o + ) def killall(self): for p in self.pids[:]: @@ -166,8 +170,7 @@ class LldpdFactory(object): for l in open("/etc/passwd", "r").readlines(): if not l.startswith("{}:".format(user)): passwd += l - passwd += "{}:x:39861:39861::{}:/bin/false\n".format( - user, chroot) + passwd += "{}:x:39861:39861::{}:/bin/false\n".format(user, chroot) fgroup = "" for l in open("/etc/group", "r").readlines(): if not l.startswith("{}:".format(group)): @@ -177,27 +180,37 @@ class LldpdFactory(object): _replace_file(tmpdir, "/etc/group", fgroup) # We also need a proper /etc/os-release - _replace_file(tmpdir, "/etc/os-release", - """PRETTY_NAME="Spectacular GNU/Linux 2016" + _replace_file( + tmpdir, + "/etc/os-release", + """PRETTY_NAME="Spectacular GNU/Linux 2016" NAME="Spectacular GNU/Linux" ID=spectacular HOME_URL="https://www.example.com/spectacular" SUPPORT_URL="https://www.example.com/spectacular/support" BUG_REPORT_URL="https://www.example.com/spectacular/bugs" -""") +""", + ) # We also need a proper name subprocess.check_call(["hostname", name]) # And we need to ensure name resolution is sane - _replace_file(tmpdir, "/etc/hosts", - """ + _replace_file( + tmpdir, + "/etc/hosts", + """ 127.0.0.1 localhost.localdomain localhost 127.0.1.1 {name}.example.com {name} ::1 ip6-localhost ip6-loopback -""".format(name=name)) - _replace_file(tmpdir, "/etc/nsswitch.conf", - """ +""".format( + name=name + ), + ) + _replace_file( + tmpdir, + "/etc/nsswitch.conf", + """ passwd: files group: files shadow: files @@ -205,7 +218,8 @@ hosts: files networks: files protocols: files services: files -""") +""", + ) # Remove any config path = os.path.join(self.config.lldpd.confdir, "lldpd.conf") @@ -240,25 +254,30 @@ def lldpcli(request, tmpdir): def run(*args): cargs = ("-u", str(socketdir)) + args - p = subprocess.Popen((libtool_location, 'execute', - lldpcli_location) + cargs, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + p = subprocess.Popen( + (libtool_location, "execute", lldpcli_location) + cargs, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) stdout, stderr = p.communicate(timeout=30) - result = namedtuple('ProcessResult', - ['returncode', 'stdout', 'stderr'])( - p.returncode, stdout, stderr) + result = namedtuple("ProcessResult", ["returncode", "stdout", "stderr"])( + p.returncode, stdout, stderr + ) request.node.add_report_section( - 'run', 'lldpcli output {}'.format(count[0]), - format_process_output("lldpcli", cargs, result)) + "run", + "lldpcli output {}".format(count[0]), + format_process_output("lldpcli", cargs, result), + ) count[0] += 1 # When keyvalue is requested, return a formatted result if args[:2] == ("-f", "keyvalue"): assert result.returncode == 0 out = {} - for k, v in [l.split('=', 2) - for l in result.stdout.decode('ascii').split("\n") - if '=' in l]: + for k, v in [ + l.split("=", 2) + for l in result.stdout.decode("ascii").split("\n") + if "=" in l + ]: if k in out: out[k] += [v] else: @@ -269,6 +288,7 @@ def lldpcli(request, tmpdir): return out # Otherwise, return the named tuple return result + return run @@ -281,35 +301,46 @@ def snmpd(request, tmpdir): conffile = tmpdir.join("ns", "snmpd.conf") pidfile = tmpdir.join("ns", "snmpd.pid") with conffile.open("w") as f: - f.write(""" + f.write( + """ rocommunity public rwcommunity private master agentx trap2sink 127.0.0.1 -""") - sargs = ("-I", - "snmp_mib,sysORTable" - ",usmConf,usmStats,usmUser" - ",vacm_conf,vacm_context,vacm_vars", - "-Ln", - "-p", str(pidfile), - "-C", "-c", str(conffile)) +""" + ) + sargs = ( + "-I", + "snmp_mib,sysORTable" + ",usmConf,usmStats,usmUser" + ",vacm_conf,vacm_context,vacm_vars", + "-Ln", + "-p", + str(pidfile), + "-C", + "-c", + str(conffile), + ) try: - p = subprocess.Popen(("snmpd",) + sargs + args, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + p = subprocess.Popen( + ("snmpd",) + sargs + args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) except OSError as e: if e.errno == os.errno.ENOENT: pytest.skip("snmpd not present") return raise e stdout, stderr = p.communicate(timeout=5) - result = namedtuple('ProcessResult', - ['returncode', 'stdout', 'stderr'])( - p.returncode, stdout, stderr) + result = namedtuple("ProcessResult", ["returncode", "stdout", "stderr"])( + p.returncode, stdout, stderr + ) request.node.add_report_section( - 'run', 'snmpd output {}'.format(count[0]), - format_process_output("snmpd", sargs, result)) + "run", + "snmpd output {}".format(count[0]), + format_process_output("snmpd", sargs, result), + ) count[0] += 1 time.sleep(1) @@ -319,6 +350,7 @@ trap2sink 127.0.0.1 os.kill(int(p.read())) except: pass + request.addfinalizer(kill) return run @@ -328,37 +360,50 @@ trap2sink 127.0.0.1 def snmpwalk(): def run(*args): try: - p = subprocess.Popen(("env", "MIBDIRS=", - "snmpwalk", - "-v2c", "-c", "private", - "-Ob", "-Oe", "-On", - "localhost") + args, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + p = subprocess.Popen( + ( + "env", + "MIBDIRS=", + "snmpwalk", + "-v2c", + "-c", + "private", + "-Ob", + "-Oe", + "-On", + "localhost", + ) + + args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) except OSError as e: if e.errno == os.errno.ENOENT: pytest.skip("snmpwalk not present") return raise e stdout, stderr = p.communicate(timeout=30) - result = namedtuple('ProcessResult', - ['returncode', 'stdout', 'stderr'])( - p.returncode, stdout, stderr) + result = namedtuple("ProcessResult", ["returncode", "stdout", "stderr"])( + p.returncode, stdout, stderr + ) # When keyvalue is requested, return a formatted result assert result.returncode == 0 out = {} - for k, v in [l.split(' = ', 2) - for l in result.stdout.decode('ascii').split("\n") - if ' = ' in l]: + for k, v in [ + l.split(" = ", 2) + for l in result.stdout.decode("ascii").split("\n") + if " = " in l + ]: out[k] = v return out + return run def pytest_runtest_makereport(item, call): """Collect outputs written to tmpdir and put them in report.""" # Only do that after tests are run, but not on teardown (too late) - if call.when != 'call': + if call.when != "call": return # We can't wait for teardown, kill any running lldpd daemon right # now. Otherwise, we won't get any output. @@ -367,106 +412,91 @@ def pytest_runtest_makereport(item, call): lldpd.killall() if "tmpdir" in item.fixturenames and "tmpdir" in item.funcargs: tmpdir = item.funcargs["tmpdir"] - if tmpdir.join('lldpd-outputs').check(dir=1): - for path in tmpdir.join('lldpd-outputs').visit(): + if tmpdir.join("lldpd-outputs").check(dir=1): + for path in tmpdir.join("lldpd-outputs").visit(): item.add_report_section( - call.when, - 'lldpd {}'.format(path.basename), - path.read()) + call.when, "lldpd {}".format(path.basename), path.read() + ) def pytest_configure(config): """Put lldpd/lldpcli configuration into the config object.""" output = subprocess.check_output([lldpcli_location, "-vv"]) - output = output.decode('ascii') - config.lldpcli = namedtuple( - 'lldpcli', - ['version', - 'outputs'])( - re.search( - r"^lldpcli (.*)$", output, - re.MULTILINE).group(1), - re.search( - r"^Additional output formats:\s+(.*)$", - output, - re.MULTILINE).group(1).split(", ")) + output = output.decode("ascii") + config.lldpcli = namedtuple("lldpcli", ["version", "outputs"])( + re.search(r"^lldpcli (.*)$", output, re.MULTILINE).group(1), + re.search(r"^Additional output formats:\s+(.*)$", output, re.MULTILINE) + .group(1) + .split(", "), + ) output = subprocess.check_output([lldpd_location, "-vv"]) - output = output.decode('ascii') - if {"enabled": True, - "disabled": False}[re.search(r"^Privilege separation:\s+(.*)$", - output, re.MULTILINE).group(1)]: - privsep = namedtuple('privsep', - ['user', - 'group', - 'chroot', - 'enabled'])( - re.search( - r"^Privilege separation user:\s+(.*)$", - output, - re.MULTILINE).group(1), - re.search( - r"^Privilege separation group:\s+(.*)$", - output, - re.MULTILINE).group(1), - re.search( - r"^Privilege separation chroot:\s(.*)$", - output, - re.MULTILINE).group(1), - True) + output = output.decode("ascii") + if {"enabled": True, "disabled": False}[ + re.search(r"^Privilege separation:\s+(.*)$", output, re.MULTILINE).group(1) + ]: + privsep = namedtuple("privsep", ["user", "group", "chroot", "enabled"])( + re.search( + r"^Privilege separation user:\s+(.*)$", output, re.MULTILINE + ).group(1), + re.search( + r"^Privilege separation group:\s+(.*)$", output, re.MULTILINE + ).group(1), + re.search( + r"^Privilege separation chroot:\s(.*)$", output, re.MULTILINE + ).group(1), + True, + ) else: - privsep = namedtuple('privsep', - ['enabled'])(False) - config.lldpd = namedtuple('lldpd', - ['features', - 'protocols', - 'confdir', - 'snmp', - 'privsep', - 'version'])( - re.search( - r"^Additional LLDP features:\s+(.*)$", - output, - re.MULTILINE).group(1).split(", "), - re.search( - r"^Additional protocols:\s+(.*)$", - output, - re.MULTILINE).group(1).split(", "), - re.search( - r"^Configuration directory:\s+(.*)$", - output, re.MULTILINE).group(1), - {"yes": True, - "no": False}[re.search( - r"^SNMP support:\s+(.*)$", - output, - re.MULTILINE).group(1)], - privsep, - re.search(r"^lldpd (.*)$", - output, re.MULTILINE).group(1)) + privsep = namedtuple("privsep", ["enabled"])(False) + config.lldpd = namedtuple( + "lldpd", ["features", "protocols", "confdir", "snmp", "privsep", "version"] + )( + re.search(r"^Additional LLDP features:\s+(.*)$", output, re.MULTILINE) + .group(1) + .split(", "), + re.search(r"^Additional protocols:\s+(.*)$", output, re.MULTILINE) + .group(1) + .split(", "), + re.search(r"^Configuration directory:\s+(.*)$", output, re.MULTILINE).group(1), + {"yes": True, "no": False}[ + re.search(r"^SNMP support:\s+(.*)$", output, re.MULTILINE).group(1) + ], + privsep, + re.search(r"^lldpd (.*)$", output, re.MULTILINE).group(1), + ) # Also retrieve some kernel capabilities features = [] for feature in ["rtnl-link-team"]: - ret = subprocess.call(["/sbin/modprobe", "--quiet", "--dry-run", - feature]) + ret = subprocess.call(["/sbin/modprobe", "--quiet", "--dry-run", feature]) if ret == 0: features.append(feature) - config.kernel = namedtuple('kernel', - ['features', - 'version'])( - features, - os.uname().release) + config.kernel = namedtuple("kernel", ["features", "version"])( + features, os.uname().release + ) def pytest_report_header(config): """Report lldpd/lldpcli version and configuration.""" - print('lldpd: {} {}'.format(config.lldpd.version, - ", ".join(config.lldpd.protocols + - config.lldpd.features))) - print('lldpcli: {} {}'.format(config.lldpcli.version, - ", ".join(config.lldpcli.outputs))) - print('kernel: {} {}'.format(config.kernel.version, - ", ".join(config.kernel.features))) - print('{}: {} {} {}'.format(platform.system().lower(), - platform.release(), - platform.version(), - platform.machine())) + print( + "lldpd: {} {}".format( + config.lldpd.version, + ", ".join(config.lldpd.protocols + config.lldpd.features), + ) + ) + print( + "lldpcli: {} {}".format( + config.lldpcli.version, ", ".join(config.lldpcli.outputs) + ) + ) + print( + "kernel: {} {}".format(config.kernel.version, ", ".join(config.kernel.features)) + ) + print( + "{}: {} {} {}".format( + platform.system().lower(), + platform.release(), + platform.version(), + platform.machine(), + ) + ) diff --git a/tests/integration/test_basic.py b/tests/integration/test_basic.py index c48ee24b..d237f219 100644 --- a/tests/integration/test_basic.py +++ b/tests/integration/test_basic.py @@ -4,31 +4,35 @@ import pyroute2 import scapy.all import scapy.contrib.lldp + def test_one_neighbor(lldpd1, lldpd, lldpcli, namespaces): with namespaces(2): lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") - assert out['lldp.eth0.age'].startswith('0 day, 00:00:') - assert out['lldp.eth0.chassis.descr'].startswith( - "Spectacular GNU/Linux 2016 Linux") - assert 'lldp.eth0.chassis.Router.enabled' in out - assert 'lldp.eth0.chassis.Station.enabled' in out - del out['lldp.eth0.age'] - del out['lldp.eth0.chassis.descr'] - del out['lldp.eth0.chassis.Router.enabled'] - del out['lldp.eth0.chassis.Station.enabled'] - assert out == {"lldp.eth0.via": "LLDP", - "lldp.eth0.rid": "1", - "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", - "lldp.eth0.port.descr": "eth1", - "lldp.eth0.port.ttl": "120"} + assert out["lldp.eth0.age"].startswith("0 day, 00:00:") + assert out["lldp.eth0.chassis.descr"].startswith( + "Spectacular GNU/Linux 2016 Linux" + ) + assert "lldp.eth0.chassis.Router.enabled" in out + assert "lldp.eth0.chassis.Station.enabled" in out + del out["lldp.eth0.age"] + del out["lldp.eth0.chassis.descr"] + del out["lldp.eth0.chassis.Router.enabled"] + del out["lldp.eth0.chassis.Station.enabled"] + assert out == { + "lldp.eth0.via": "LLDP", + "lldp.eth0.rid": "1", + "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", + "lldp.eth0.port.descr": "eth1", + "lldp.eth0.port.ttl": "120", + } @pytest.mark.parametrize("neighbors", (5, 10, 20)) @@ -37,14 +41,14 @@ def test_several_neighbors(lldpd, lldpcli, links, namespaces, neighbors): links(namespaces(1), namespaces(i)) for i in range(1, neighbors + 1): with namespaces(i): - lldpd(sleep=(i == 1 and 2 or 0), - silent=True) + lldpd(sleep=(i == 1 and 2 or 0), silent=True) time.sleep(10) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") for i in range(2, neighbors + 1): - assert out['lldp.eth{}.chassis.name'.format((i - 2)*2)] == \ - 'ns-{}.example.com'.format(i) + assert out[ + "lldp.eth{}.chassis.name".format((i - 2) * 2) + ] == "ns-{}.example.com".format(i) def test_one_interface(lldpd1, lldpd, lldpcli, namespaces): @@ -52,23 +56,26 @@ def test_one_interface(lldpd1, lldpd, lldpcli, namespaces): lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "interfaces") - assert out['lldp.eth0.chassis.descr'].startswith( - "Spectacular GNU/Linux 2016 Linux") - assert 'lldp.eth0.chassis.Router.enabled' in out - assert 'lldp.eth0.chassis.Station.enabled' in out - del out['lldp.eth0.chassis.descr'] - del out['lldp.eth0.chassis.Router.enabled'] - del out['lldp.eth0.chassis.Station.enabled'] - assert out == {"lldp.eth0.status": "RX and TX", - "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", - "lldp.eth0.port.descr": "eth0", - "lldp.eth0.ttl.ttl": "120"} + assert out["lldp.eth0.chassis.descr"].startswith( + "Spectacular GNU/Linux 2016 Linux" + ) + assert "lldp.eth0.chassis.Router.enabled" in out + assert "lldp.eth0.chassis.Station.enabled" in out + del out["lldp.eth0.chassis.descr"] + del out["lldp.eth0.chassis.Router.enabled"] + del out["lldp.eth0.chassis.Station.enabled"] + assert out == { + "lldp.eth0.status": "RX and TX", + "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", + "lldp.eth0.port.descr": "eth0", + "lldp.eth0.ttl.ttl": "120", + } @pytest.mark.parametrize("interfaces", (5, 10, 20)) @@ -81,10 +88,12 @@ def test_several_interfaces(lldpd, lldpcli, links, namespaces, interfaces): with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "interfaces") for i in range(2, interfaces + 1): - assert out['lldp.eth{}.chassis.mac'.format((i - 2)*2)] == \ - '00:00:00:00:00:01' - assert out['lldp.eth{}.port.mac'.format((i - 2)*2)] == \ - '00:00:00:00:00:{num:02x}'.format(num=(i - 2)*2 + 1) + assert ( + out["lldp.eth{}.chassis.mac".format((i - 2) * 2)] == "00:00:00:00:00:01" + ) + assert out[ + "lldp.eth{}.port.mac".format((i - 2) * 2) + ] == "00:00:00:00:00:{num:02x}".format(num=(i - 2) * 2 + 1) def test_different_mtu(lldpd, lldpcli, links, namespaces): @@ -96,8 +105,8 @@ def test_different_mtu(lldpd, lldpcli, links, namespaces): lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "interfaces") - assert out['lldp.eth0.chassis.mac'] == '00:00:00:00:00:01' - assert out['lldp.eth2.chassis.mac'] == '00:00:00:00:00:01' + assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:01" + assert out["lldp.eth2.chassis.mac"] == "00:00:00:00:00:01" def test_overrided_description(lldpd1, lldpd, lldpcli, namespaces): @@ -105,7 +114,7 @@ def test_overrided_description(lldpd1, lldpd, lldpcli, namespaces): lldpd("-S", "Modified description") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") - assert out['lldp.eth0.chassis.descr'] == "Modified description" + assert out["lldp.eth0.chassis.descr"] == "Modified description" def test_overrided_description2(lldpd1, lldpd, lldpcli, namespaces): @@ -116,7 +125,7 @@ def test_overrided_description2(lldpd1, lldpd, lldpcli, namespaces): time.sleep(1) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") - assert out['lldp.eth0.chassis.descr'] == "Modified description" + assert out["lldp.eth0.chassis.descr"] == "Modified description" def test_overrided_chassisid(lldpd1, lldpd, lldpcli, namespaces): @@ -127,7 +136,7 @@ def test_overrided_chassisid(lldpd1, lldpd, lldpcli, namespaces): time.sleep(1) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") - assert out['lldp.eth0.chassis.local'] == "Modified chassis ID" + assert out["lldp.eth0.chassis.local"] == "Modified chassis ID" def test_overrided_chassisid_kept(lldpd1, lldpd, lldpcli, namespaces, links): @@ -142,7 +151,7 @@ def test_overrided_chassisid_kept(lldpd1, lldpd, lldpcli, namespaces, links): time.sleep(1) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") - assert out['lldp.eth0.chassis.local'] == "Modified chassis ID" + assert out["lldp.eth0.chassis.local"] == "Modified chassis ID" def test_overrided_chassisid_reverse(lldpd1, lldpd, lldpcli, namespaces): @@ -154,7 +163,7 @@ def test_overrided_chassisid_reverse(lldpd1, lldpd, lldpcli, namespaces): time.sleep(1) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") - assert out['lldp.eth0.chassis.mac'] == "00:00:00:00:00:02" + assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02" def test_hide_kernel(lldpd1, lldpd, lldpcli, namespaces): @@ -162,8 +171,7 @@ def test_hide_kernel(lldpd1, lldpd, lldpcli, namespaces): lldpd("-k") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") - assert out["lldp.eth0.chassis.descr"] == \ - "Spectacular GNU/Linux 2016" + assert out["lldp.eth0.chassis.descr"] == "Spectacular GNU/Linux 2016" def test_listen_only(lldpd1, lldpd, lldpcli, namespaces): @@ -187,7 +195,7 @@ def test_forced_known_management_address(lldpd1, lldpd, lldpcli, namespaces): with namespaces(2): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname="eth1")[0] - ipr.addr('add', index=idx, address="192.168.14.2", mask=24) + ipr.addr("add", index=idx, address="192.168.14.2", mask=24) lldpd("-m", "192.168.14.2") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") @@ -199,8 +207,8 @@ def test_management_address(lldpd1, lldpd, lldpcli, links, namespaces): with namespaces(2): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname="eth1")[0] - ipr.addr('add', index=idx, address="192.168.14.2", mask=24) - ipr.addr('add', index=idx, address="172.25.21.47", mask=24) + ipr.addr("add", index=idx, address="192.168.14.2", mask=24) + ipr.addr("add", index=idx, address="172.25.21.47", mask=24) lldpd("-m", "172.25.*") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") @@ -213,14 +221,16 @@ def test_management_interface(lldpd1, lldpd, lldpcli, links, namespaces): with namespaces(2): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname="eth1")[0] - ipr.addr('add', index=idx, address="192.168.14.2", mask=24) + ipr.addr("add", index=idx, address="192.168.14.2", mask=24) idx = ipr.link_lookup(ifname="eth3")[0] - ipr.addr('add', index=idx, address="172.25.21.47", mask=24) + ipr.addr("add", index=idx, address="172.25.21.47", mask=24) lldpd("-m", "eth3") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") - assert out["lldp.eth0.chassis.mgmt-ip"] == ["172.25.21.47", - "fe80::200:ff:fe00:4"] + assert out["lldp.eth0.chassis.mgmt-ip"] == [ + "172.25.21.47", + "fe80::200:ff:fe00:4", + ] assert out["lldp.eth0.chassis.mgmt-iface"] == ["4", "4"] @@ -228,7 +238,7 @@ def test_change_management_address(lldpd1, lldpd, lldpcli, links, namespaces): with namespaces(2): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname="eth1")[0] - ipr.addr('add', index=idx, address="192.168.14.2", mask=24) + ipr.addr("add", index=idx, address="192.168.14.2", mask=24) lldpd("-m", "192.168.*") # We need a short TX interval as updating the IP address # doesn't trigger a resend. @@ -239,8 +249,8 @@ def test_change_management_address(lldpd1, lldpd, lldpcli, links, namespaces): assert out["lldp.eth0.chassis.mgmt-iface"] == "2" with namespaces(2): with pyroute2.IPRoute() as ipr: - ipr.addr('del', index=idx, address="192.168.14.2", mask=24) - ipr.addr('add', index=idx, address="192.168.14.5", mask=24) + ipr.addr("del", index=idx, address="192.168.14.2", mask=24) + ipr.addr("add", index=idx, address="192.168.14.5", mask=24) time.sleep(5) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") @@ -263,7 +273,7 @@ def test_portid_subtype_with_alias(lldpd1, lldpd, lldpcli, links, namespaces): with namespaces(2): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname="eth1")[0] - ipr.link('set', index=idx, ifalias="alias of eth1") + ipr.link("set", index=idx, ifalias="alias of eth1") lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") @@ -275,7 +285,7 @@ def test_portid_subtype_macaddress(lldpd1, lldpd, lldpcli, links, namespaces): with namespaces(2): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname="eth1")[0] - ipr.link('set', index=idx, ifalias="alias of eth1") + ipr.link("set", index=idx, ifalias="alias of eth1") lldpd() lldpcli("configure", "lldp", "portidsubtype", "macaddress") time.sleep(3) @@ -299,7 +309,15 @@ def test_portid_subtype_local(lldpd1, lldpd, lldpcli, namespaces): def test_portid_subtype_local_with_description(lldpd1, lldpd, lldpcli, namespaces): with namespaces(2): lldpd() - lldpcli("configure", "lldp", "portidsubtype", "local", "localname", "description", "localdescription") + lldpcli( + "configure", + "lldp", + "portidsubtype", + "local", + "localname", + "description", + "localdescription", + ) time.sleep(3) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") @@ -321,7 +339,7 @@ def test_portid_subtype_local_with_alias(lldpd1, lldpd, lldpcli, namespaces): with namespaces(2): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname="eth1")[0] - ipr.link('set', index=idx, ifalias="alias of eth1") + ipr.link("set", index=idx, ifalias="alias of eth1") lldpd() lldpcli("configure", "lldp", "portidsubtype", "local", "localname") time.sleep(3) @@ -398,11 +416,22 @@ def test_port_status_disabled(lldpd, lldpcli, namespaces, links): def test_port_vlan_tx(lldpd1, lldpd, lldpcli, namespaces): with namespaces(1): lldpd() - lldpcli("configure", "ports", "eth0", "lldp", "vlan-tx", "100", "priority", "5", "dei", "1") + lldpcli( + "configure", + "ports", + "eth0", + "lldp", + "vlan-tx", + "100", + "priority", + "5", + "dei", + "1", + ) out = lldpcli("-f", "keyvalue", "show", "interfaces", "ports", "eth0") - assert out["lldp.eth0.port.vlanTX.id"] == '100' - assert out["lldp.eth0.port.vlanTX.prio"] == '5' - assert out["lldp.eth0.port.vlanTX.dei"] == '1' + assert out["lldp.eth0.port.vlanTX.id"] == "100" + assert out["lldp.eth0.port.vlanTX.prio"] == "5" + assert out["lldp.eth0.port.vlanTX.dei"] == "1" # unconfigure VLAN TX lldpcli("unconfigure", "ports", "eth0", "lldp", "vlan-tx") out = lldpcli("-f", "keyvalue", "show", "interfaces", "ports", "eth0") @@ -418,8 +447,10 @@ def test_set_interface_alias(lldpd1, lldpd, lldpcli, namespaces): lldpd() with namespaces(1): with pyroute2.IPRoute() as ipr: - link = ipr.link('get', ifname='eth0')[0] - assert link.get_attr('IFLA_IFALIAS') == 'lldpd: connected to ns-2.example.com' + link = ipr.link("get", ifname="eth0")[0] + assert ( + link.get_attr("IFLA_IFALIAS") == "lldpd: connected to ns-2.example.com" + ) def test_lldpdu_shutdown(lldpd, lldpcli, namespaces, links): @@ -428,60 +459,71 @@ def test_lldpdu_shutdown(lldpd, lldpcli, namespaces, links): with namespaces(1): lldpd() # From https://github.com/lldpd/lldpd/issues/348 - frm_fa01 = scapy.all.Ether( - src='04:fe:7f:00:00:01', - dst=scapy.contrib.lldp.LLDP_NEAREST_BRIDGE_MAC) / \ - scapy.contrib.lldp.LLDPDUChassisID( + frm_fa01 = ( + scapy.all.Ether( + src="04:fe:7f:00:00:01", dst=scapy.contrib.lldp.LLDP_NEAREST_BRIDGE_MAC + ) + / scapy.contrib.lldp.LLDPDUChassisID( subtype=scapy.contrib.lldp.LLDPDUChassisID.SUBTYPE_MAC_ADDRESS, - id=b'\x04\xfe\x7f\x00\x00\x00') / \ - scapy.contrib.lldp.LLDPDUPortID( - subtype=scapy.contrib.lldp.LLDPDUPortID.SUBTYPE_INTERFACE_NAME, - id='Fa0/1') / \ - scapy.contrib.lldp.LLDPDUTimeToLive(ttl=65535) / \ - scapy.contrib.lldp.LLDPDUSystemName( - system_name='this info should not disappear') / \ - scapy.contrib.lldp.LLDPDUEndOfLLDPDU() + id=b"\x04\xfe\x7f\x00\x00\x00", + ) + / scapy.contrib.lldp.LLDPDUPortID( + subtype=scapy.contrib.lldp.LLDPDUPortID.SUBTYPE_INTERFACE_NAME, id="Fa0/1" + ) + / scapy.contrib.lldp.LLDPDUTimeToLive(ttl=65535) + / scapy.contrib.lldp.LLDPDUSystemName( + system_name="this info should not disappear" + ) + / scapy.contrib.lldp.LLDPDUEndOfLLDPDU() + ) frm_fa01 = frm_fa01.build() frm_fa01 = scapy.all.Ether(frm_fa01) - frm_fa02 = scapy.all.Ether( - src='04:fe:7f:00:00:02', - dst=scapy.contrib.lldp.LLDP_NEAREST_BRIDGE_MAC) / \ - scapy.contrib.lldp.LLDPDUChassisID( + frm_fa02 = ( + scapy.all.Ether( + src="04:fe:7f:00:00:02", dst=scapy.contrib.lldp.LLDP_NEAREST_BRIDGE_MAC + ) + / scapy.contrib.lldp.LLDPDUChassisID( subtype=scapy.contrib.lldp.LLDPDUChassisID.SUBTYPE_MAC_ADDRESS, - id=b'\x04\xfe\x7f\x00\x00\x00') / \ - scapy.contrib.lldp.LLDPDUPortID( - subtype=scapy.contrib.lldp.LLDPDUPortID.SUBTYPE_INTERFACE_NAME, - id='Fa0/2') / \ - scapy.contrib.lldp.LLDPDUTimeToLive(ttl=65535) / \ - scapy.contrib.lldp.LLDPDUSystemName( - system_name='this info should not disappear') / \ - scapy.contrib.lldp.LLDPDUEndOfLLDPDU() + id=b"\x04\xfe\x7f\x00\x00\x00", + ) + / scapy.contrib.lldp.LLDPDUPortID( + subtype=scapy.contrib.lldp.LLDPDUPortID.SUBTYPE_INTERFACE_NAME, id="Fa0/2" + ) + / scapy.contrib.lldp.LLDPDUTimeToLive(ttl=65535) + / scapy.contrib.lldp.LLDPDUSystemName( + system_name="this info should not disappear" + ) + / scapy.contrib.lldp.LLDPDUEndOfLLDPDU() + ) frm_fa02 = frm_fa02.build() frm_fa02 = scapy.all.Ether(frm_fa02) - frm_shut_fa01 = scapy.all.Ether( - src='04:fe:7f:00:00:01', - dst=scapy.contrib.lldp.LLDP_NEAREST_BRIDGE_MAC) / \ - scapy.contrib.lldp.LLDPDUChassisID( + frm_shut_fa01 = ( + scapy.all.Ether( + src="04:fe:7f:00:00:01", dst=scapy.contrib.lldp.LLDP_NEAREST_BRIDGE_MAC + ) + / scapy.contrib.lldp.LLDPDUChassisID( subtype=scapy.contrib.lldp.LLDPDUChassisID.SUBTYPE_MAC_ADDRESS, - id=b'\x04\xfe\x7f\x00\x00\x00') / \ - scapy.contrib.lldp.LLDPDUPortID( - subtype=scapy.contrib.lldp.LLDPDUPortID.SUBTYPE_INTERFACE_NAME, - id='Fa0/1') / \ - scapy.contrib.lldp.LLDPDUTimeToLive(ttl=0) / \ - scapy.contrib.lldp.LLDPDUEndOfLLDPDU() + id=b"\x04\xfe\x7f\x00\x00\x00", + ) + / scapy.contrib.lldp.LLDPDUPortID( + subtype=scapy.contrib.lldp.LLDPDUPortID.SUBTYPE_INTERFACE_NAME, id="Fa0/1" + ) + / scapy.contrib.lldp.LLDPDUTimeToLive(ttl=0) + / scapy.contrib.lldp.LLDPDUEndOfLLDPDU() + ) frm_shut_fa01 = frm_shut_fa01.build() frm_shut_fa01 = scapy.all.Ether(frm_shut_fa01) with namespaces(2): - scapy.all.sendp(frm_fa01, iface='eth1') - scapy.all.sendp(frm_fa02, iface='eth3') + scapy.all.sendp(frm_fa01, iface="eth1") + scapy.all.sendp(frm_fa02, iface="eth3") time.sleep(2) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") - del out['lldp.eth0.age'] - del out['lldp.eth2.age'] + del out["lldp.eth0.age"] + del out["lldp.eth2.age"] assert out == { "lldp.eth0.via": "LLDP", "lldp.eth0.rid": "1", @@ -494,17 +536,19 @@ def test_lldpdu_shutdown(lldpd, lldpcli, namespaces, links): "lldp.eth2.chassis.mac": "04:fe:7f:00:00:00", "lldp.eth2.chassis.name": "this info should not disappear", "lldp.eth2.port.ifname": "Fa0/2", - "lldp.eth2.port.ttl": "65535"} + "lldp.eth2.port.ttl": "65535", + } with namespaces(2): - scapy.all.sendp(frm_shut_fa01, iface='eth1') + scapy.all.sendp(frm_shut_fa01, iface="eth1") time.sleep(2) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors") - del out['lldp.eth2.age'] + del out["lldp.eth2.age"] assert out == { "lldp.eth2.via": "LLDP", "lldp.eth2.rid": "1", "lldp.eth2.chassis.mac": "04:fe:7f:00:00:00", "lldp.eth2.chassis.name": "this info should not disappear", "lldp.eth2.port.ifname": "Fa0/2", - "lldp.eth2.port.ttl": "65535"} + "lldp.eth2.port.ttl": "65535", + } diff --git a/tests/integration/test_configinventory.py b/tests/integration/test_configinventory.py index a3945410..76fbc0a1 100644 --- a/tests/integration/test_configinventory.py +++ b/tests/integration/test_configinventory.py @@ -4,63 +4,71 @@ import platform import time import shlex -@pytest.mark.skipif("'LLDP-MED' not in config.lldpd.features", - reason="LLDP-MED not supported") -class TestConfigInventory(object): - def test_configinventory(self, lldpd1, lldpd, lldpcli, namespaces, - replace_file): +@pytest.mark.skipif( + "'LLDP-MED' not in config.lldpd.features", reason="LLDP-MED not supported" +) +class TestConfigInventory(object): + def test_configinventory(self, lldpd1, lldpd, lldpcli, namespaces, replace_file): with namespaces(2): if os.path.isdir("/sys/class/dmi/id"): # /sys/class/dmi/id/* - for what, value in dict(product_version="1.14", - bios_version="1.10", - product_serial="45872512", - sys_vendor="Spectacular", - product_name="Workstation", - chassis_asset_tag="487122").items(): - replace_file("/sys/class/dmi/id/{}".format(what), - value) + for what, value in dict( + product_version="1.14", + bios_version="1.10", + product_serial="45872512", + sys_vendor="Spectacular", + product_name="Workstation", + chassis_asset_tag="487122", + ).items(): + replace_file("/sys/class/dmi/id/{}".format(what), value) lldpd("-M", "1") def test_default_inventory(namespaces, lldpcli): with namespaces(1): if os.path.isdir("/sys/class/dmi/id"): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.chassis.name'] == 'ns-2.example.com' - assert out['lldp.eth0.lldp-med.inventory.hardware'] == '1.14' - assert out['lldp.eth0.lldp-med.inventory.firmware'] == '1.10' - assert out['lldp.eth0.lldp-med.inventory.serial'] == '45872512' - assert out['lldp.eth0.lldp-med.inventory.manufacturer'] == \ - 'Spectacular' - assert out['lldp.eth0.lldp-med.inventory.model'] == 'Workstation' - assert out['lldp.eth0.lldp-med.inventory.asset'] == '487122' - assert out['lldp.eth0.lldp-med.inventory.software'] == \ - platform.release() + assert out["lldp.eth0.chassis.name"] == "ns-2.example.com" + assert out["lldp.eth0.lldp-med.inventory.hardware"] == "1.14" + assert out["lldp.eth0.lldp-med.inventory.firmware"] == "1.10" + assert out["lldp.eth0.lldp-med.inventory.serial"] == "45872512" + assert ( + out["lldp.eth0.lldp-med.inventory.manufacturer"] + == "Spectacular" + ) + assert out["lldp.eth0.lldp-med.inventory.model"] == "Workstation" + assert out["lldp.eth0.lldp-med.inventory.asset"] == "487122" + assert ( + out["lldp.eth0.lldp-med.inventory.software"] + == platform.release() + ) else: - assert 'lldp.eth0.lldp-med.inventory.hardware' not in out.items() - assert 'lldp.eth0.lldp-med.inventory.firmware' not in out.items() - assert 'lldp.eth0.lldp-med.inventory.serial' not in out.items() - assert 'lldp.eth0.lldp-med.inventory.manufacturer' not in out.items() - assert 'lldp.eth0.lldp-med.inventory.model' not in out.items() - assert 'lldp.eth0.lldp-med.inventory.asset' not in out.items() - assert 'lldp.eth0.lldp-med.inventory.software' not in out.items() + assert "lldp.eth0.lldp-med.inventory.hardware" not in out.items() + assert "lldp.eth0.lldp-med.inventory.firmware" not in out.items() + assert "lldp.eth0.lldp-med.inventory.serial" not in out.items() + assert ( + "lldp.eth0.lldp-med.inventory.manufacturer" not in out.items() + ) + assert "lldp.eth0.lldp-med.inventory.model" not in out.items() + assert "lldp.eth0.lldp-med.inventory.asset" not in out.items() + assert "lldp.eth0.lldp-med.inventory.software" not in out.items() test_default_inventory(namespaces, lldpcli) custom_values = [ - ('hardware-revision', 'hardware', 'SQRT2_1.41421356237309504880'), - ('software-revision', 'software', 'E_2.7182818284590452354'), - ('firmware-revision', 'firmware', 'PI_3.14159265358979323846'), - ('serial', 'serial', 'FIBO_112358'), - ('manufacturer', 'manufacturer', 'Cybertron'), - ('model', 'model', 'OptimusPrime'), - ('asset', 'asset', 'SQRT3_1.732050807568877') - ] + ("hardware-revision", "hardware", "SQRT2_1.41421356237309504880"), + ("software-revision", "software", "E_2.7182818284590452354"), + ("firmware-revision", "firmware", "PI_3.14159265358979323846"), + ("serial", "serial", "FIBO_112358"), + ("manufacturer", "manufacturer", "Cybertron"), + ("model", "model", "OptimusPrime"), + ("asset", "asset", "SQRT3_1.732050807568877"), + ] with namespaces(2): for what, pfx, value in custom_values: result = lldpcli( - *shlex.split("configure inventory {} {}".format(what, value))) + *shlex.split("configure inventory {} {}".format(what, value)) + ) assert result.returncode == 0 result = lldpcli("resume") assert result.returncode == 0 @@ -76,8 +84,7 @@ class TestConfigInventory(object): with namespaces(2): for what, pfx, value in custom_values: - result = lldpcli( - *shlex.split("unconfigure inventory {}".format(what))) + result = lldpcli(*shlex.split("unconfigure inventory {}".format(what))) assert result.returncode == 0 result = lldpcli("resume") assert result.returncode == 0 @@ -85,4 +92,3 @@ class TestConfigInventory(object): assert result.returncode == 0 test_default_inventory(namespaces, lldpcli) - diff --git a/tests/integration/test_custom.py b/tests/integration/test_custom.py index f01f0ea1..13471921 100644 --- a/tests/integration/test_custom.py +++ b/tests/integration/test_custom.py @@ -3,73 +3,114 @@ import shlex import time -@pytest.mark.skipif("'Custom TLV' not in config.lldpd.features", - reason="Custom TLV not supported") -@pytest.mark.parametrize("commands, expected", [ - (["oui 33,44,55 subtype 44"], - {'unknown-tlv.oui': '33,44,55', - 'unknown-tlv.subtype': '44', - 'unknown-tlv.len': '0'}), - (["oui 33,44,55 subtype 44 oui-info 45,45,45,45,45"], - {'unknown-tlv.oui': '33,44,55', - 'unknown-tlv.subtype': '44', - 'unknown-tlv.len': '5', - 'unknown-tlv': '45,45,45,45,45'}), - (["oui 33,44,55 subtype 44 oui-info 45,45,45,45,45", - "add oui 33,44,55 subtype 44 oui-info 55,55,55,55,55", - "add oui 33,44,55 subtype 55 oui-info 65,65,65,65,65"], - {'unknown-tlv.oui': ['33,44,55', '33,44,55', '33,44,55'], - 'unknown-tlv.subtype': ['44', '44', '55'], - 'unknown-tlv.len': ['5', '5', '5'], - 'unknown-tlv': ['45,45,45,45,45', - '55,55,55,55,55', - '65,65,65,65,65']}), - (["oui 33,44,55 subtype 44 oui-info 45,45,45,45,45", - "add oui 33,44,55 subtype 55 oui-info 65,65,65,65,65", - "replace oui 33,44,55 subtype 44 oui-info 66,66,66,66,66"], - {'unknown-tlv.oui': ['33,44,55', '33,44,55'], - 'unknown-tlv.subtype': ['55', '44'], - 'unknown-tlv.len': ['5', '5'], - 'unknown-tlv': ['65,65,65,65,65', - '66,66,66,66,66']}), - (["add oui 33,44,55 subtype 55 oui-info 65,65,65,65,65", - "replace oui 33,44,55 subtype 44 oui-info 66,66,66,66,66"], - {'unknown-tlv.oui': ['33,44,55', '33,44,55'], - 'unknown-tlv.subtype': ['55', '44'], - 'unknown-tlv.len': ['5', '5'], - 'unknown-tlv': ['65,65,65,65,65', - '66,66,66,66,66']}), - (["oui 33,44,55 subtype 44 oui-info 45,45,45,45,45", - "add oui 33,44,55 subtype 55 oui-info 55,55,55,55,55", - "-oui 33,44,55 subtype 55"], - {'unknown-tlv.oui': '33,44,55', - 'unknown-tlv.subtype': '44', - 'unknown-tlv.len': '5', - 'unknown-tlv': '45,45,45,45,45'}), - (["oui 33,44,55 subtype 44 oui-info 45,45,45,45,45", - "add oui 33,44,55 subtype 55 oui-info 65,65,65,65,65", - "-"], - {}), - (["oui 00,80,c2 subtype 18 oui-info 45,45,45,45,45"], - {'unknown-tlv.oui': '00,80,C2', - 'unknown-tlv.subtype': '18', - 'unknown-tlv.len': '5', - 'unknown-tlv': '45,45,45,45,45'})]) -def test_custom_tlv(lldpd1, lldpd, lldpcli, namespaces, - commands, expected): +@pytest.mark.skipif( + "'Custom TLV' not in config.lldpd.features", reason="Custom TLV not supported" +) +@pytest.mark.parametrize( + "commands, expected", + [ + ( + ["oui 33,44,55 subtype 44"], + { + "unknown-tlv.oui": "33,44,55", + "unknown-tlv.subtype": "44", + "unknown-tlv.len": "0", + }, + ), + ( + ["oui 33,44,55 subtype 44 oui-info 45,45,45,45,45"], + { + "unknown-tlv.oui": "33,44,55", + "unknown-tlv.subtype": "44", + "unknown-tlv.len": "5", + "unknown-tlv": "45,45,45,45,45", + }, + ), + ( + [ + "oui 33,44,55 subtype 44 oui-info 45,45,45,45,45", + "add oui 33,44,55 subtype 44 oui-info 55,55,55,55,55", + "add oui 33,44,55 subtype 55 oui-info 65,65,65,65,65", + ], + { + "unknown-tlv.oui": ["33,44,55", "33,44,55", "33,44,55"], + "unknown-tlv.subtype": ["44", "44", "55"], + "unknown-tlv.len": ["5", "5", "5"], + "unknown-tlv": ["45,45,45,45,45", "55,55,55,55,55", "65,65,65,65,65"], + }, + ), + ( + [ + "oui 33,44,55 subtype 44 oui-info 45,45,45,45,45", + "add oui 33,44,55 subtype 55 oui-info 65,65,65,65,65", + "replace oui 33,44,55 subtype 44 oui-info 66,66,66,66,66", + ], + { + "unknown-tlv.oui": ["33,44,55", "33,44,55"], + "unknown-tlv.subtype": ["55", "44"], + "unknown-tlv.len": ["5", "5"], + "unknown-tlv": ["65,65,65,65,65", "66,66,66,66,66"], + }, + ), + ( + [ + "add oui 33,44,55 subtype 55 oui-info 65,65,65,65,65", + "replace oui 33,44,55 subtype 44 oui-info 66,66,66,66,66", + ], + { + "unknown-tlv.oui": ["33,44,55", "33,44,55"], + "unknown-tlv.subtype": ["55", "44"], + "unknown-tlv.len": ["5", "5"], + "unknown-tlv": ["65,65,65,65,65", "66,66,66,66,66"], + }, + ), + ( + [ + "oui 33,44,55 subtype 44 oui-info 45,45,45,45,45", + "add oui 33,44,55 subtype 55 oui-info 55,55,55,55,55", + "-oui 33,44,55 subtype 55", + ], + { + "unknown-tlv.oui": "33,44,55", + "unknown-tlv.subtype": "44", + "unknown-tlv.len": "5", + "unknown-tlv": "45,45,45,45,45", + }, + ), + ( + [ + "oui 33,44,55 subtype 44 oui-info 45,45,45,45,45", + "add oui 33,44,55 subtype 55 oui-info 65,65,65,65,65", + "-", + ], + {}, + ), + ( + ["oui 00,80,c2 subtype 18 oui-info 45,45,45,45,45"], + { + "unknown-tlv.oui": "00,80,C2", + "unknown-tlv.subtype": "18", + "unknown-tlv.len": "5", + "unknown-tlv": "45,45,45,45,45", + }, + ), + ], +) +def test_custom_tlv(lldpd1, lldpd, lldpcli, namespaces, commands, expected): with namespaces(2): lldpd() for command in commands: result = lldpcli( - *shlex.split("{}configure lldp custom-tlv {}".format( - command.startswith("-") and "un" or "", - command.lstrip("-")))) + *shlex.split( + "{}configure lldp custom-tlv {}".format( + command.startswith("-") and "un" or "", command.lstrip("-") + ) + ) + ) assert result.returncode == 0 time.sleep(3) with namespaces(1): pfx = "lldp.eth0.unknown-tlvs." out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - out = {k[len(pfx):]: v - for k, v in out.items() - if k.startswith(pfx)} + out = {k[len(pfx) :]: v for k, v in out.items() if k.startswith(pfx)} assert out == expected diff --git a/tests/integration/test_dot1.py b/tests/integration/test_dot1.py index 502aff71..8abff00a 100644 --- a/tests/integration/test_dot1.py +++ b/tests/integration/test_dot1.py @@ -1,40 +1,41 @@ import pytest -@pytest.mark.skipif("'Dot1' not in config.lldpd.features", - reason="Dot1 not supported") +@pytest.mark.skipif("'Dot1' not in config.lldpd.features", reason="Dot1 not supported") class TestLldpDot1(object): - def test_one_vlan(self, lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): - links.vlan('vlan100', 100, 'eth1') + links.vlan("vlan100", 100, "eth1") lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.vlan'] == 'vlan100' - assert out['lldp.eth0.vlan.vlan-id'] == '100' + assert out["lldp.eth0.vlan"] == "vlan100" + assert out["lldp.eth0.vlan.vlan-id"] == "100" def test_several_vlans(self, lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): for v in [100, 200, 300, 4000]: - links.vlan('vlan{}'.format(v), v, 'eth1') + links.vlan("vlan{}".format(v), v, "eth1") lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") # We know that lldpd is walking interfaces in index order - assert out['lldp.eth0.vlan'] == \ - ['vlan100', 'vlan200', 'vlan300', 'vlan4000'] - assert out['lldp.eth0.vlan.vlan-id'] == \ - ['100', '200', '300', '4000'] + assert out["lldp.eth0.vlan"] == [ + "vlan100", + "vlan200", + "vlan300", + "vlan4000", + ] + assert out["lldp.eth0.vlan.vlan-id"] == ["100", "200", "300", "4000"] def test_too_many_vlans(self, lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): for v in range(100, 1000): - links.vlan('vlan{}'.format(v), v, 'eth1') + links.vlan("vlan{}".format(v), v, "eth1") lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert 'lldp.eth0.vlan' not in out - assert 'lldp.eth0.age' in out + assert "lldp.eth0.vlan" not in out + assert "lldp.eth0.age" in out # TODO: PI and PPVID (but lldpd doesn't know how to generate them) diff --git a/tests/integration/test_dot3.py b/tests/integration/test_dot3.py index 1eb5ee46..abeb86ef 100644 --- a/tests/integration/test_dot3.py +++ b/tests/integration/test_dot3.py @@ -3,58 +3,64 @@ import shlex import time -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - reason="Dot3 not supported") +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", reason="Dot3 not supported") class TestLldpDot3(object): - def test_aggregate(self, lldpd1, lldpd, lldpcli, namespaces, links): links(namespaces(3), namespaces(2)) # Another link to setup a bond with namespaces(2): - idx = links.bond('bond42', 'eth1', 'eth3') + idx = links.bond("bond42", "eth1", "eth3") lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.port.aggregation'] == str(idx) + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.port.aggregation"] == str(idx) # TODO: unfortunately, with veth, it's not possible to get an # interface with autoneg. - @pytest.mark.parametrize("command, expected", [ - ("pse supported enabled paircontrol powerpairs spare class class-3", - {'supported': 'yes', - 'enabled': 'yes', - 'paircontrol': 'yes', - 'device-type': 'PSE', - 'pairs': 'spare', - 'class': 'class 3'}), - ("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', - 'priority': 'low', - 'requested': '10000', - 'allocated': '15000'})]) - def test_power(self, lldpd1, lldpd, lldpcli, namespaces, - command, expected): + @pytest.mark.parametrize( + "command, expected", + [ + ( + "pse supported enabled paircontrol powerpairs spare class class-3", + { + "supported": "yes", + "enabled": "yes", + "paircontrol": "yes", + "device-type": "PSE", + "pairs": "spare", + "class": "class 3", + }, + ), + ( + "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", + "priority": "low", + "requested": "10000", + "allocated": "15000", + }, + ), + ], + ) + def test_power(self, lldpd1, lldpd, lldpcli, namespaces, command, expected): with namespaces(2): lldpd() - result = lldpcli( - *shlex.split("configure dot3 power {}".format(command))) + result = lldpcli(*shlex.split("configure dot3 power {}".format(command))) assert result.returncode == 0 time.sleep(3) with namespaces(1): pfx = "lldp.eth0.port.power." out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - out = {k[len(pfx):]: v - for k, v in out.items() - if k.startswith(pfx)} + out = {k[len(pfx) :]: v for k, v in out.items() if k.startswith(pfx)} assert out == expected def test_autoneg_power(self, links, lldpd, lldpcli, namespaces): @@ -64,38 +70,44 @@ class TestLldpDot3(object): with namespaces(2): lldpd() 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")) + *shlex.split( + "configure dot3 power pd " + "supported enabled paircontrol " + "powerpairs spare " + "class class-3 " + "type 1 source both priority low " + "requested 20000 allocated 5000" + ) + ) assert result.returncode == 0 time.sleep(2) with namespaces(1): # Did we receive the request? out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.power.requested'] == '20000' - assert out['lldp.eth0.port.power.allocated'] == '5000' + assert out["lldp.eth0.port.power.requested"] == "20000" + assert out["lldp.eth0.port.power.allocated"] == "5000" # Send an answer we agree to give almost that (this part # cannot be automated, lldpd cannot take this decision). result = lldpcli( - *shlex.split("configure dot3 power pse " - "supported enabled paircontrol powerpairs " - "spare class class-3 " - "type 1 source primary priority high " - "requested 20000 allocated 19000")) + *shlex.split( + "configure dot3 power pse " + "supported enabled paircontrol powerpairs " + "spare class class-3 " + "type 1 source primary priority high " + "requested 20000 allocated 19000" + ) + ) assert result.returncode == 0 time.sleep(2) with namespaces(2): # Did we receive that? out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth1.port.power.requested'] == '20000' - assert out['lldp.eth1.port.power.allocated'] == '19000' + assert out["lldp.eth1.port.power.requested"] == "20000" + assert out["lldp.eth1.port.power.allocated"] == "19000" with namespaces(1): # Did we get an echo back? This part is handled # automatically by lldpd: we confirm we received the # answer "immediately". out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.power.requested'] == '20000' - assert out['lldp.eth0.port.power.allocated'] == '19000' + assert out["lldp.eth0.port.power.requested"] == "20000" + assert out["lldp.eth0.port.power.allocated"] == "19000" diff --git a/tests/integration/test_interfaces.py b/tests/integration/test_interfaces.py index 064855de..ce0088ed 100644 --- a/tests/integration/test_interfaces.py +++ b/tests/integration/test_interfaces.py @@ -6,330 +6,302 @@ import time def test_simple_bridge(lldpd1, lldpd, lldpcli, namespaces, links): links(namespaces(3), namespaces(2)) # Another link to setup a bridge with namespaces(2): - links.bridge('br42', 'eth1', 'eth3') + links.bridge("br42", "eth1", "eth3") lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.chassis.Bridge.enabled'] == 'on' + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.chassis.Bridge.enabled"] == "on" def test_remove_bridge(lldpd, lldpcli, namespaces, links): links(namespaces(1), namespaces(2)) links(namespaces(3), namespaces(1)) # Another link to setup a bridge with namespaces(1): - links.bridge('br42', 'eth0', 'eth3') + links.bridge("br42", "eth0", "eth3") lldpd("-r") with namespaces(2): lldpd() time.sleep(2) - lldpcli("pause") # Prevent any updates + lldpcli("pause") # Prevent any updates with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' + assert out["lldp.eth0.port.descr"] == "eth1" # Remove from bridge. We don't use netlink because we wouldn't # get the wanted effect: we also get a RTM_NEWLINK by doing # that. Only the bridge ioctl() would prevent that. - links.unbridge('br42', 'eth0') + links.unbridge("br42", "eth0") time.sleep(1) # Check if we still have eth0 out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' + assert out["lldp.eth0.port.descr"] == "eth1" -@pytest.mark.skipif("'Dot1' not in config.lldpd.features", - reason="Dot1 not supported") -@pytest.mark.parametrize('when', ['before', 'after']) +@pytest.mark.skipif("'Dot1' not in config.lldpd.features", reason="Dot1 not supported") +@pytest.mark.parametrize("when", ["before", "after"]) def test_bridge_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links, when): links(namespaces(3), namespaces(2)) # Another link to setup a bridge with namespaces(2): - if when == 'after': + if when == "after": lldpd() - links.bridge('br42', 'eth1', 'eth3') - links.vlan('vlan100', 100, 'br42') - links.vlan('vlan200', 200, 'br42') - links.vlan('vlan300', 300, 'br42') - if when == 'before': + links.bridge("br42", "eth1", "eth3") + links.vlan("vlan100", 100, "br42") + links.vlan("vlan200", 200, "br42") + links.vlan("vlan300", 300, "br42") + if when == "before": lldpd() else: time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.vlan'] == \ - ['vlan100', 'vlan200', 'vlan300'] - assert out['lldp.eth0.vlan.vlan-id'] == \ - ['100', '200', '300'] - - -@pytest.mark.skipif("'Dot1' not in config.lldpd.features", - reason="Dot1 not supported") -@pytest.mark.parametrize('when', ['before', 'after']) -def test_vlan_aware_bridge_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links, - when): + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.vlan"] == ["vlan100", "vlan200", "vlan300"] + assert out["lldp.eth0.vlan.vlan-id"] == ["100", "200", "300"] + + +@pytest.mark.skipif("'Dot1' not in config.lldpd.features", reason="Dot1 not supported") +@pytest.mark.parametrize("when", ["before", "after"]) +def test_vlan_aware_bridge_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links, when): links(namespaces(3), namespaces(2)) # Another link to setup a bridge with namespaces(3): lldpd() with namespaces(2): - if when == 'after': + if when == "after": lldpd() - links.bridge('br42', 'eth1', 'eth3', filtering=True) - links.bridge_vlan('eth1', 100, pvid=True) - links.bridge_vlan('eth1', 200) - links.bridge_vlan('eth1', 300) - links.bridge_vlan('eth3', 400) - if when == 'before': + links.bridge("br42", "eth1", "eth3", filtering=True) + links.bridge_vlan("eth1", 100, pvid=True) + links.bridge_vlan("eth1", 200) + links.bridge_vlan("eth1", 300) + links.bridge_vlan("eth3", 400) + if when == "before": lldpd() else: time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.vlan'] == \ - ['vlan100', 'vlan200', 'vlan300'] - assert out['lldp.eth0.vlan.vlan-id'] == \ - ['100', '200', '300'] - assert out['lldp.eth0.vlan.pvid'] == \ - ['yes', 'no', 'no'] + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.vlan"] == ["vlan100", "vlan200", "vlan300"] + assert out["lldp.eth0.vlan.vlan-id"] == ["100", "200", "300"] + assert out["lldp.eth0.vlan.pvid"] == ["yes", "no", "no"] with namespaces(3): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth2.port.descr'] == 'eth3' - assert out['lldp.eth2.vlan'] == \ - 'vlan400' - assert out['lldp.eth2.vlan.vlan-id'] == \ - '400' - assert out['lldp.eth2.vlan.pvid'] == \ - 'no' - - -@pytest.mark.skipif("'Dot1' not in config.lldpd.features", - reason="Dot1 not supported") -@pytest.mark.parametrize('filtering', [False, True]) -def test_vlan_aware_bridge_filtering(lldpd1, lldpd, lldpcli, - namespaces, links, filtering): + assert out["lldp.eth2.port.descr"] == "eth3" + assert out["lldp.eth2.vlan"] == "vlan400" + assert out["lldp.eth2.vlan.vlan-id"] == "400" + assert out["lldp.eth2.vlan.pvid"] == "no" + + +@pytest.mark.skipif("'Dot1' not in config.lldpd.features", reason="Dot1 not supported") +@pytest.mark.parametrize("filtering", [False, True]) +def test_vlan_aware_bridge_filtering( + lldpd1, lldpd, lldpcli, namespaces, links, filtering +): links(namespaces(3), namespaces(2)) # Another link to setup a bridge with namespaces(2): - links.bridge('br42', 'eth1', 'eth3', filtering=filtering) - links.bridge_vlan('eth1', 100, pvid=True) - links.bridge_vlan('eth1', 200) - links.bridge_vlan('eth1', 300) - links.bridge_vlan('eth3', 400) - links.vlan('vlan400', 400, 'br42') + links.bridge("br42", "eth1", "eth3", filtering=filtering) + links.bridge_vlan("eth1", 100, pvid=True) + links.bridge_vlan("eth1", 200) + links.bridge_vlan("eth1", 300) + links.bridge_vlan("eth3", 400) + links.vlan("vlan400", 400, "br42") lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' + assert out["lldp.eth0.port.descr"] == "eth1" if filtering: - assert out['lldp.eth0.vlan'] == \ - ['vlan100', 'vlan200', 'vlan300'] - assert out['lldp.eth0.vlan.vlan-id'] == \ - ['100', '200', '300'] - assert out['lldp.eth0.vlan.pvid'] == \ - ['yes', 'no', 'no'] + assert out["lldp.eth0.vlan"] == ["vlan100", "vlan200", "vlan300"] + assert out["lldp.eth0.vlan.vlan-id"] == ["100", "200", "300"] + assert out["lldp.eth0.vlan.pvid"] == ["yes", "no", "no"] else: - assert out['lldp.eth0.vlan'] == \ - ['vlan100', 'vlan200', 'vlan300', 'vlan400'] - assert out['lldp.eth0.vlan.vlan-id'] == \ - ['100', '200', '300', '400'] - assert out['lldp.eth0.vlan.pvid'] == \ - ['yes', 'no', 'no', 'no'] + assert out["lldp.eth0.vlan"] == ["vlan100", "vlan200", "vlan300", "vlan400"] + assert out["lldp.eth0.vlan.vlan-id"] == ["100", "200", "300", "400"] + assert out["lldp.eth0.vlan.pvid"] == ["yes", "no", "no", "no"] -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - reason="Dot3 not supported") -@pytest.mark.parametrize('when', ['before', 'after']) +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", reason="Dot3 not supported") +@pytest.mark.parametrize("when", ["before", "after"]) def test_bond(lldpd1, lldpd, lldpcli, namespaces, links, when): links(namespaces(3), namespaces(2)) # Another link to setup a bond with namespaces(2): - if when == 'after': + if when == "after": lldpd() - idx = links.bond('bond42', 'eth3', 'eth1') + idx = links.bond("bond42", "eth3", "eth1") with pyroute2.IPRoute() as ipr: # The bond has the MAC of eth3 - assert ipr.get_links(idx)[0].get_attr('IFLA_ADDRESS') == \ - "00:00:00:00:00:04" - if when == 'before': + assert ipr.get_links(idx)[0].get_attr("IFLA_ADDRESS") == "00:00:00:00:00:04" + if when == "before": lldpd() else: time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.port.aggregation'] == str(idx) + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.port.aggregation"] == str(idx) # lldpd should be able to retrieve the right MAC - assert out['lldp.eth0.port.mac'] == '00:00:00:00:00:02' + assert out["lldp.eth0.port.mac"] == "00:00:00:00:00:02" -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - reason="Dot3 not supported") -@pytest.mark.skipif("'rtnl-link-team' not in config.kernel.features", - reason="No team support in kernel") -@pytest.mark.parametrize('when', ['before', 'after']) +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", reason="Dot3 not supported") +@pytest.mark.skipif( + "'rtnl-link-team' not in config.kernel.features", reason="No team support in kernel" +) +@pytest.mark.parametrize("when", ["before", "after"]) def test_team(lldpd1, lldpd, lldpcli, namespaces, links, when): links(namespaces(3), namespaces(2)) # Another link to setup a bond with namespaces(2): - if when == 'after': + if when == "after": lldpd() - idx = links.team('team42', 'eth3', 'eth1') - if when == 'before': + idx = links.team("team42", "eth3", "eth1") + if when == "before": lldpd() else: time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.port.aggregation'] == str(idx) + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.port.aggregation"] == str(idx) # Unfortunately, we cannot get the right MAC currently... So, # this bit will succeed by chance. - assert out['lldp.eth0.port.mac'] == '00:00:00:00:00:02' + assert out["lldp.eth0.port.mac"] == "00:00:00:00:00:02" -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - reason="Dot3 not supported") -@pytest.mark.skipif("'Dot1' not in config.lldpd.features", - reason="Dot1 not supported") -@pytest.mark.parametrize('when', ['before', 'after']) +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", reason="Dot3 not supported") +@pytest.mark.skipif("'Dot1' not in config.lldpd.features", reason="Dot1 not supported") +@pytest.mark.parametrize("when", ["before", "after"]) def test_bond_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links, when): links(namespaces(3), namespaces(2)) # Another link to setup a bond with namespaces(2): - if when == 'after': + if when == "after": lldpd() - links.bond('bond42', 'eth3', 'eth1') - links.vlan('vlan300', 300, 'bond42') - links.vlan('vlan301', 301, 'bond42') - links.vlan('vlan302', 302, 'bond42') - links.vlan('vlan303', 303, 'bond42') - if when == 'before': + links.bond("bond42", "eth3", "eth1") + links.vlan("vlan300", 300, "bond42") + links.vlan("vlan301", 301, "bond42") + links.vlan("vlan302", 302, "bond42") + links.vlan("vlan303", 303, "bond42") + if when == "before": lldpd() else: time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.vlan'] == \ - ['vlan300', 'vlan301', 'vlan302', 'vlan303'] - assert out['lldp.eth0.vlan.vlan-id'] == \ - ['300', '301', '302', '303'] + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.vlan"] == ["vlan300", "vlan301", "vlan302", "vlan303"] + assert out["lldp.eth0.vlan.vlan-id"] == ["300", "301", "302", "303"] -@pytest.mark.skipif("'Dot1' not in config.lldpd.features", - reason="Dot1 not supported") -@pytest.mark.parametrize('when', ['before', 'after']) +@pytest.mark.skipif("'Dot1' not in config.lldpd.features", reason="Dot1 not supported") +@pytest.mark.parametrize("when", ["before", "after"]) def test_just_vlan(lldpd1, lldpd, lldpcli, namespaces, links, when): with namespaces(2): - if when == 'after': + if when == "after": lldpd() - links.vlan('vlan300', 300, 'eth1') - links.vlan('vlan400', 400, 'eth1') - if when == 'before': + links.vlan("vlan300", 300, "eth1") + links.vlan("vlan400", 400, "eth1") + if when == "before": lldpd() else: time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.vlan'] == ['vlan300', 'vlan400'] - assert out['lldp.eth0.vlan.vlan-id'] == ['300', '400'] + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.vlan"] == ["vlan300", "vlan400"] + assert out["lldp.eth0.vlan.vlan-id"] == ["300", "400"] -@pytest.mark.skipif("'Dot1' not in config.lldpd.features", - reason="Dot1 not supported") -@pytest.mark.parametrize('kind', ['plain', 'bridge', 'vlan-aware-bridge', 'bond']) +@pytest.mark.skipif("'Dot1' not in config.lldpd.features", reason="Dot1 not supported") +@pytest.mark.parametrize("kind", ["plain", "bridge", "vlan-aware-bridge", "bond"]) def test_remove_vlan(lldpd1, lldpd, lldpcli, namespaces, links, kind): with namespaces(2): - if kind == 'bond': - iface = 'bond42' - links.bond(iface, 'eth1') - elif kind in ('bridge', 'vlan-aware-bridge'): - iface = 'bridge42' - links.bridge(iface, 'eth1') + if kind == "bond": + iface = "bond42" + links.bond(iface, "eth1") + elif kind in ("bridge", "vlan-aware-bridge"): + iface = "bridge42" + links.bridge(iface, "eth1") else: - assert kind == 'plain' - iface = 'eth1' - if kind != 'vlan-aware-bridge': - links.vlan('vlan300', 300, iface) - links.vlan('vlan400', 400, iface) - links.vlan('vlan500', 500, iface) + assert kind == "plain" + iface = "eth1" + if kind != "vlan-aware-bridge": + links.vlan("vlan300", 300, iface) + links.vlan("vlan400", 400, iface) + links.vlan("vlan500", 500, iface) lldpd() - links.remove('vlan300') + links.remove("vlan300") else: - links.bridge_vlan('eth1', 300, pvid=True) - links.bridge_vlan('eth1', 400) - links.bridge_vlan('eth1', 500) + links.bridge_vlan("eth1", 300, pvid=True) + links.bridge_vlan("eth1", 400) + links.bridge_vlan("eth1", 500) lldpd() - links.bridge_vlan('eth1', 300, remove=True) + links.bridge_vlan("eth1", 300, remove=True) time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.vlan'] == ['vlan400', 'vlan500'] - assert out['lldp.eth0.vlan.vlan-id'] == ['400', '500'] - assert out['lldp.eth0.vlan.pvid'] == ['no', 'no'] + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.vlan"] == ["vlan400", "vlan500"] + assert out["lldp.eth0.vlan.vlan-id"] == ["400", "500"] + assert out["lldp.eth0.vlan.pvid"] == ["no", "no"] -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - reason="Dot3 not supported") +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", reason="Dot3 not supported") def test_unenslave_bond(lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): - links.bond('bond42', 'eth1') + links.bond("bond42", "eth1") lldpd() - links.remove('bond42') - links.up('eth1') + links.remove("bond42") + links.up("eth1") time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert 'lldp.eth0.port.aggregation' not in out + assert out["lldp.eth0.port.descr"] == "eth1" + assert "lldp.eth0.port.aggregation" not in out -@pytest.mark.skipif("'Dot1' not in config.lldpd.features", - reason="Dot1 not supported") +@pytest.mark.skipif("'Dot1' not in config.lldpd.features", reason="Dot1 not supported") def test_unenslave_bond_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): - links.bond('bond42', 'eth1') - links.vlan('vlan300', 300, 'bond42') - links.vlan('vlan400', 400, 'eth1') + links.bond("bond42", "eth1") + links.vlan("vlan300", 300, "bond42") + links.vlan("vlan400", 400, "eth1") lldpd() - links.remove('bond42') - links.up('eth1') + links.remove("bond42") + links.up("eth1") time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.vlan'] == 'vlan400' - assert out['lldp.eth0.vlan.vlan-id'] == '400' + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.vlan"] == "vlan400" + assert out["lldp.eth0.vlan.vlan-id"] == "400" def test_down_then_up(lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): - links.down('eth1') + links.down("eth1") lldpd() with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") assert out == {} with namespaces(2): - links.up('eth1') + links.up("eth1") time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' + assert out["lldp.eth0.port.descr"] == "eth1" -@pytest.mark.skipif("'Dot1' not in config.lldpd.features", - reason="Dot1 not supported") +@pytest.mark.skipif("'Dot1' not in config.lldpd.features", reason="Dot1 not supported") def test_down_then_up_with_vlan(lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): - links.vlan('vlan300', 300, 'eth1') - links.vlan('vlan400', 400, 'eth1') - links.down('eth1') + links.vlan("vlan300", 300, "eth1") + links.vlan("vlan400", 400, "eth1") + links.down("eth1") lldpd() - links.up('eth1') + links.up("eth1") time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.vlan'] == ['vlan300', 'vlan400'] - assert out['lldp.eth0.vlan.vlan-id'] == ['300', '400'] + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.vlan"] == ["vlan300", "vlan400"] + assert out["lldp.eth0.vlan.vlan-id"] == ["300", "400"] def test_new_interface(lldpd1, lldpd, lldpcli, namespaces, links): @@ -339,28 +311,28 @@ def test_new_interface(lldpd1, lldpd, lldpcli, namespaces, links): time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth2.port.descr'] == 'eth3' - assert out['lldp.eth0.rid'] == out['lldp.eth2.rid'] # Same chassis + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth2.port.descr"] == "eth3" + assert out["lldp.eth0.rid"] == out["lldp.eth2.rid"] # Same chassis def test_remove_add_interface(lldpd, lldpcli, namespaces, links): links(namespaces(1), namespaces(2)) with namespaces(1): lldpd() - links.remove('eth0') - links.count = 0 # Ack to reset interface count + links.remove("eth0") + links.count = 0 # Ack to reset interface count links(namespaces(1), namespaces(2)) - time.sleep(2) # lldpd(1) should process the change + time.sleep(2) # lldpd(1) should process the change with namespaces(2): lldpd() with namespaces(1): lldpcli("update") - time.sleep(2) # lldpd(2) should receive the LLDPDU + time.sleep(2) # lldpd(2) should receive the LLDPDU with namespaces(2): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") print(1, "out", out) - assert out['lldp.eth1.port.descr'] == 'eth0' + assert out["lldp.eth1.port.descr"] == "eth0" def test_set_interface_description(lldpd, lldpcli, namespaces, links): @@ -381,13 +353,11 @@ def test_set_interface_description(lldpd, lldpcli, namespaces, links): assert alias == "lldpd: connected to ns-2.example.com" # We should see neighbor interface description out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.ifname'] == 'eth1' - assert out['lldp.eth0.port.descr'] == 'blip blop' + assert out["lldp.eth0.port.ifname"] == "eth1" + assert out["lldp.eth0.port.descr"] == "blip blop" # Our new alias should not be sent to neighbor lldpcli("update") time.sleep(1) with namespaces(2): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth1.port.descr'] == 'eth0' - - + assert out["lldp.eth1.port.descr"] == "eth0" diff --git a/tests/integration/test_lldpcli.py b/tests/integration/test_lldpcli.py index 098d2d26..3e964dfc 100644 --- a/tests/integration/test_lldpcli.py +++ b/tests/integration/test_lldpcli.py @@ -9,21 +9,24 @@ import xml.etree.ElementTree as ET if hasattr(ET, "canonicalize"): canonicalize = ET.canonicalize else: + def canonicalize(x): x -@pytest.fixture(scope='session') +@pytest.fixture(scope="session") def uname(): return "{} {} {} {}".format( - platform.system(), - platform.release(), - platform.version(), - platform.machine()) - -@pytest.mark.parametrize("command, expected", [ - ("neighbors", - """------------------------------------------------------------------------------- + platform.system(), platform.release(), platform.version(), platform.machine() + ) + + +@pytest.mark.parametrize( + "command, expected", + [ + ( + "neighbors", + """------------------------------------------------------------------------------- LLDP neighbors: ------------------------------------------------------------------------------- Interface: eth0, via: LLDP, RID: 1, Time: 0 day, 00:00:{seconds} @@ -42,9 +45,11 @@ Interface: eth0, via: LLDP, RID: 1, Time: 0 day, 00:00:{seconds} PortDescr: eth1 TTL: 120{dot3} ------------------------------------------------------------------------------- -"""), - ("interfaces", - """------------------------------------------------------------------------------- +""", + ), + ( + "interfaces", + """------------------------------------------------------------------------------- LLDP interfaces: ------------------------------------------------------------------------------- Interface: eth0 @@ -64,227 +69,309 @@ Interface: eth0 PortDescr: eth0{dot3} TTL: 120 ------------------------------------------------------------------------------- -""")], ids=["neighbors", "interfaces"]) -def test_text_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, - command, expected): +""", + ), + ], + ids=["neighbors", "interfaces"], +) +def test_text_output( + request, lldpd1, lldpd, lldpcli, namespaces, uname, command, expected +): with namespaces(2): lldpd() with namespaces(1): - result = lldpcli( - *shlex.split("show {} details".format(command))) + result = lldpcli(*shlex.split("show {} details".format(command))) assert result.returncode == 0 - out = result.stdout.decode('ascii') + out = result.stdout.decode("ascii") - if 'Dot3' in request.config.lldpd.features: + if "Dot3" in request.config.lldpd.features: dot3 = """ PMD autoneg: supported: no, enabled: no MAU oper type: 10GbaseT - Four-pair Category 6A or better, full duplex mode only""" else: dot3 = "" - out = result.stdout.decode('ascii') + out = result.stdout.decode("ascii") if command == "neighbors": - time = re.search(r'^Interface: .*Time: (.*)$', - out, - re.MULTILINE).group(1) - seconds = re.search(r'^Interface: .*(\d\d)$', - out, - re.MULTILINE).group(1) + time = re.search(r"^Interface: .*Time: (.*)$", out, re.MULTILINE).group(1) + seconds = re.search(r"^Interface: .*(\d\d)$", out, re.MULTILINE).group(1) else: time = None seconds = None - router = re.search(r'^ Capability: Router, (.*)$', - out, - re.MULTILINE).group(1) - station = re.search(r'^ Capability: Station, (.*)$', - out, - re.MULTILINE).group(1) - out = re.sub(r' *$', '', out, flags=re.MULTILINE) - assert out == expected.format(seconds=seconds, - time=time, - router=router, - station=station, - uname=uname, - dot3=dot3) - -@pytest.mark.skipif("'JSON' not in config.lldpcli.outputs", - reason="JSON not supported") -@pytest.mark.parametrize("command, expected", [ - ("neighbors", - {"lldp": { - "interface": { - "eth0": { - "via": "LLDP", - "rid": "1", - "chassis": { - "ns-2.example.com": { - "id": { - "type": "mac", - "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},]}}, - "port": { - "id": { - "type": "mac", - "value": "00:00:00:00:00:02"}, - "descr": "eth1", - "ttl": "120"}}}}}), - ("interfaces", - {"lldp": { - "interface": { - "eth0": { - "status": "RX and TX", - "chassis": { - "ns-1.example.com": { - "id": { - "type": "mac", - "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},]}}, - "port": { - "id": { - "type": "mac", - "value": "00:00:00:00:00:01"}, - "descr": "eth0"}, - "ttl": { - "ttl": "120"}}}}})], ids=["neighbors", "interfaces"]) -def test_json_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, - command, expected): + router = re.search( + r"^ Capability: Router, (.*)$", out, re.MULTILINE + ).group(1) + station = re.search( + r"^ Capability: Station, (.*)$", out, re.MULTILINE + ).group(1) + out = re.sub(r" *$", "", out, flags=re.MULTILINE) + assert out == expected.format( + seconds=seconds, + time=time, + router=router, + station=station, + uname=uname, + dot3=dot3, + ) + + +@pytest.mark.skipif("'JSON' not in config.lldpcli.outputs", reason="JSON not supported") +@pytest.mark.parametrize( + "command, expected", + [ + ( + "neighbors", + { + "lldp": { + "interface": { + "eth0": { + "via": "LLDP", + "rid": "1", + "chassis": { + "ns-2.example.com": { + "id": {"type": "mac", "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}, + ], + } + }, + "port": { + "id": {"type": "mac", "value": "00:00:00:00:00:02"}, + "descr": "eth1", + "ttl": "120", + }, + } + } + } + }, + ), + ( + "interfaces", + { + "lldp": { + "interface": { + "eth0": { + "status": "RX and TX", + "chassis": { + "ns-1.example.com": { + "id": {"type": "mac", "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}, + ], + } + }, + "port": { + "id": {"type": "mac", "value": "00:00:00:00:00:01"}, + "descr": "eth0", + }, + "ttl": {"ttl": "120"}, + } + } + } + }, + ), + ], + ids=["neighbors", "interfaces"], +) +def test_json_output( + request, lldpd1, lldpd, lldpcli, namespaces, uname, command, expected +): with namespaces(2): lldpd() with namespaces(1): - result = lldpcli( - *shlex.split("-f json show {} details".format(command))) + result = lldpcli(*shlex.split("-f json show {} details".format(command))) assert result.returncode == 0 - out = result.stdout.decode('ascii') + out = result.stdout.decode("ascii") j = json.loads(out) - eth0 = j['lldp']['interface']['eth0'] - name = next(k for k,v in eth0['chassis'].items() if k.startswith('ns')) + eth0 = j["lldp"]["interface"]["eth0"] + name = next(k for k, v in eth0["chassis"].items() if k.startswith("ns")) if command == "neighbors": - del eth0['age'] - del eth0['chassis'][name]['capability'][3] - del eth0['chassis'][name]['capability'][1] + del eth0["age"] + del eth0["chassis"][name]["capability"][3] + del eth0["chassis"][name]["capability"][1] descr = "Spectacular GNU/Linux 2016 {}".format(uname) - expected['lldp']['interface']['eth0']['chassis'][name]["descr"] = descr + expected["lldp"]["interface"]["eth0"]["chassis"][name]["descr"] = descr - if 'Dot3' in request.config.lldpd.features: - expected['lldp']['interface']['eth0']['port']['auto-negotiation'] = { + if "Dot3" in request.config.lldpd.features: + expected["lldp"]["interface"]["eth0"]["port"]["auto-negotiation"] = { "enabled": False, "supported": False, - "current": "10GbaseT - Four-pair Category 6A or better, full duplex mode only" + "current": "10GbaseT - Four-pair Category 6A or better, full duplex mode only", } assert j == expected -@pytest.mark.skipif("'JSON' not in config.lldpcli.outputs", - reason="JSON not supported") -@pytest.mark.parametrize("command, expected", [ - ("neighbors", - {"lldp": [{ - "interface": [{ - "name": "eth0", - "via": "LLDP", - "rid": "1", - "chassis": [{ - "id": [{ - "type": "mac", - "value": "00:00:00:00:00:02" - }], - "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}, - ]} - ], - "port": [{ - "id": [{ - "type": "mac", - "value": "00:00:00:00:00:02" - }], - "descr": [{"value": "eth1"}], - "ttl": [{"value": "120"}] - }] - }]} - ]}), - ("interfaces", - {"lldp": [{ - "interface": [{ - "name": "eth0", - "status": [{ - "value": "RX and TX", - }], - "chassis": [{ - "id": [{ - "type": "mac", - "value": "00:00:00:00:00:01" - }], - "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}, - ]} - ], - "port": [{ - "id": [{ - "type": "mac", - "value": "00:00:00:00:00:01" - }], - "descr": [{"value": "eth0"}] - }], - "ttl": [{"ttl": "120"}] - }]} - ]})], ids=["neighbors", "interfaces"]) -def test_json0_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, - command, expected): + +@pytest.mark.skipif("'JSON' not in config.lldpcli.outputs", reason="JSON not supported") +@pytest.mark.parametrize( + "command, expected", + [ + ( + "neighbors", + { + "lldp": [ + { + "interface": [ + { + "name": "eth0", + "via": "LLDP", + "rid": "1", + "chassis": [ + { + "id": [ + { + "type": "mac", + "value": "00:00:00:00:00:02", + } + ], + "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}, + ], + } + ], + "port": [ + { + "id": [ + { + "type": "mac", + "value": "00:00:00:00:00:02", + } + ], + "descr": [{"value": "eth1"}], + "ttl": [{"value": "120"}], + } + ], + } + ] + } + ] + }, + ), + ( + "interfaces", + { + "lldp": [ + { + "interface": [ + { + "name": "eth0", + "status": [ + { + "value": "RX and TX", + } + ], + "chassis": [ + { + "id": [ + { + "type": "mac", + "value": "00:00:00:00:00:01", + } + ], + "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}, + ], + } + ], + "port": [ + { + "id": [ + { + "type": "mac", + "value": "00:00:00:00:00:01", + } + ], + "descr": [{"value": "eth0"}], + } + ], + "ttl": [{"ttl": "120"}], + } + ] + } + ] + }, + ), + ], + ids=["neighbors", "interfaces"], +) +def test_json0_output( + request, lldpd1, lldpd, lldpcli, namespaces, uname, command, expected +): with namespaces(2): lldpd() with namespaces(1): - result = lldpcli( - *shlex.split("-f json0 show {} details".format(command))) + result = lldpcli(*shlex.split("-f json0 show {} details".format(command))) assert result.returncode == 0 - out = result.stdout.decode('ascii') + out = result.stdout.decode("ascii") j = json.loads(out) - eth0 = j['lldp'][0]['interface'][0] + eth0 = j["lldp"][0]["interface"][0] if command == "neighbors": - del eth0['age'] - del eth0['chassis'][0]['capability'][3] - del eth0['chassis'][0]['capability'][1] + del eth0["age"] + del eth0["chassis"][0]["capability"][3] + del eth0["chassis"][0]["capability"][1] descr = "Spectacular GNU/Linux 2016 {}".format(uname) - expected['lldp'][0]['interface'][0]['chassis'][0]["descr"][0]['value'] = descr - - if 'Dot3' in request.config.lldpd.features: - expected['lldp'][0]['interface'][0]['port'][0]['auto-negotiation'] = [{ - "enabled": False, - "supported": False, - "current": [{"value": - "10GbaseT - Four-pair Category 6A or better, full duplex mode only"}] - }] + expected["lldp"][0]["interface"][0]["chassis"][0]["descr"][0]["value"] = descr + + if "Dot3" in request.config.lldpd.features: + expected["lldp"][0]["interface"][0]["port"][0]["auto-negotiation"] = [ + { + "enabled": False, + "supported": False, + "current": [ + { + "value": "10GbaseT - Four-pair Category 6A or better, full duplex mode only" + } + ], + } + ] assert j == expected -@pytest.mark.skipif("'XML' not in config.lldpcli.outputs", - reason="XML not supported") -@pytest.mark.parametrize("command, expected", [ - ("neighbors", -""" +@pytest.mark.skipif("'XML' not in config.lldpcli.outputs", reason="XML not supported") +@pytest.mark.parametrize( + "command, expected", + [ + ( + "neighbors", + """ @@ -305,9 +392,11 @@ def test_json0_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, -"""), -("interfaces", -""" +""", + ), + ( + "interfaces", + """ RX and TX @@ -329,166 +418,185 @@ def test_json0_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, -""")], ids=["neighbors", "interfaces"]) -def test_xml_output(request, lldpd1, lldpd, lldpcli, namespaces, uname, - command, expected): +""", + ), + ], + ids=["neighbors", "interfaces"], +) +def test_xml_output( + request, lldpd1, lldpd, lldpcli, namespaces, uname, command, expected +): with namespaces(2): lldpd() with namespaces(1): - result = lldpcli( - *shlex.split("-f xml show {} details".format(command))) + result = lldpcli(*shlex.split("-f xml show {} details".format(command))) assert result.returncode == 0 - out = result.stdout.decode('ascii') + out = result.stdout.decode("ascii") xml = ET.fromstring(out) if command == "neighbors": - age = xml.findall('./interface[1]')[0].attrib['age'] + age = xml.findall("./interface[1]")[0].attrib["age"] else: age = None - router = xml.findall("./interface[1]/chassis/" - "capability[@type='Router']")[0].attrib['enabled'] - station = xml.findall("./interface[1]/chassis/" - "capability[@type='Station']")[0].attrib['enabled'] - if 'Dot3' in request.config.lldpd.features: + router = xml.findall("./interface[1]/chassis/" "capability[@type='Router']")[ + 0 + ].attrib["enabled"] + station = xml.findall("./interface[1]/chassis/" "capability[@type='Station']")[ + 0 + ].attrib["enabled"] + if "Dot3" in request.config.lldpd.features: dot3 = """ 10GbaseT - Four-pair Category 6A or better, full duplex mode only """ else: dot3 = "" - expected = ET.fromstring(expected.format(age=age, - router=router, - station=station, - uname=uname, - dot3=dot3)) + expected = ET.fromstring( + expected.format( + age=age, router=router, station=station, uname=uname, dot3=dot3 + ) + ) assert canonicalize(ET.tostring(xml)) == canonicalize(ET.tostring(expected)) -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - reason="Dot3 not supported") +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", reason="Dot3 not supported") def test_configure_one_port(lldpd1, lldpd, lldpcli, namespaces, links): links(namespaces(1), namespaces(2)) with namespaces(2): lldpd() - result = lldpcli(*("configure ports eth3 dot3 power " - "pse supported enabled paircontrol powerpairs " - "spare class class-3").split()) + result = lldpcli( + *( + "configure ports eth3 dot3 power " + "pse supported enabled paircontrol powerpairs " + "spare class class-3" + ).split() + ) assert result.returncode == 0 time.sleep(3) out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") - assert 'lldp.eth1.port.power.device-type' not in out - assert out['lldp.eth3.port.power.device-type'] == 'PSE' + assert "lldp.eth1.port.power.device-type" not in out + assert out["lldp.eth3.port.power.device-type"] == "PSE" with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert 'lldp.eth0.port.power.device-type' not in out - assert out['lldp.eth2.port.descr'] == 'eth3' - assert out['lldp.eth2.port.power.device-type'] == 'PSE' + assert out["lldp.eth0.port.descr"] == "eth1" + assert "lldp.eth0.port.power.device-type" not in out + assert out["lldp.eth2.port.descr"] == "eth3" + assert out["lldp.eth2.port.power.device-type"] == "PSE" -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - reason="Dot3 not supported") +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", reason="Dot3 not supported") def test_new_port_take_default(lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): lldpd() - result = lldpcli(*("configure dot3 power " - "pse supported enabled paircontrol powerpairs " - "spare class class-3").split()) + result = lldpcli( + *( + "configure dot3 power " + "pse supported enabled paircontrol powerpairs " + "spare class class-3" + ).split() + ) assert result.returncode == 0 time.sleep(3) out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") - assert out['lldp.eth1.port.power.device-type'] == 'PSE' + assert out["lldp.eth1.port.power.device-type"] == "PSE" with namespaces(1): # Check this worked out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.port.descr'] == 'eth1' - assert out['lldp.eth0.port.power.device-type'] == 'PSE' + assert out["lldp.eth0.port.descr"] == "eth1" + assert out["lldp.eth0.port.power.device-type"] == "PSE" links(namespaces(1), namespaces(2), 4) time.sleep(6) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth2.port.descr'] == 'eth3' - assert out['lldp.eth2.port.power.device-type'] == 'PSE' + assert out["lldp.eth2.port.descr"] == "eth3" + assert out["lldp.eth2.port.power.device-type"] == "PSE" with namespaces(2): out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") - assert out['lldp.eth3.port.power.device-type'] == 'PSE' + assert out["lldp.eth3.port.power.device-type"] == "PSE" -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - reason="Dot3 not supported") +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", reason="Dot3 not supported") def test_port_keep_configuration_when_down(lldpd, lldpcli, namespaces, links): with namespaces(1): - links.dummy('eth3') + links.dummy("eth3") lldpd() - result = lldpcli(*("configure ports eth3 dot3 power " - "pse supported enabled paircontrol powerpairs " - "spare class class-3").split()) + result = lldpcli( + *( + "configure ports eth3 dot3 power " + "pse supported enabled paircontrol powerpairs " + "spare class class-3" + ).split() + ) assert result.returncode == 0 time.sleep(3) - links.down('eth3') + links.down("eth3") time.sleep(4) # eth3 configuration is kept because the port still exists. out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") - assert out['lldp.eth3.port.power.device-type'] == 'PSE' + assert out["lldp.eth3.port.power.device-type"] == "PSE" - links.up('eth3') + links.up("eth3") time.sleep(4) # eth3 configuration is unchanged out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") - assert out['lldp.eth3.port.power.device-type'] == 'PSE' + assert out["lldp.eth3.port.power.device-type"] == "PSE" -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - reason="Dot3 not supported") -def test_port_forget_configuration(lldpd, lldpcli, - namespaces, links): +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", reason="Dot3 not supported") +def test_port_forget_configuration(lldpd, lldpcli, namespaces, links): with namespaces(1): - links.dummy('eth3') + links.dummy("eth3") lldpd() - result = lldpcli(*("configure dot3 power " - "pse supported enabled paircontrol powerpairs " - "spare class class-3").split()) + result = lldpcli( + *( + "configure dot3 power " + "pse supported enabled paircontrol powerpairs " + "spare class class-3" + ).split() + ) assert result.returncode == 0 time.sleep(3) - links.remove('eth3') + links.remove("eth3") time.sleep(4) # eth3 configuration was forgotten because it disappeared. out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") - assert 'lldp.eth3.port.power.device-type' not in out + assert "lldp.eth3.port.power.device-type" not in out -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - reason="Dot3 not supported") -def test_port_keep_configuration_of_permanent_ports(lldpd, lldpcli, - namespaces, links): +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", reason="Dot3 not supported") +def test_port_keep_configuration_of_permanent_ports(lldpd, lldpcli, namespaces, links): with namespaces(1): - links.dummy('eth3') - links.dummy('noteth3') + links.dummy("eth3") + links.dummy("noteth3") lldpd() result = lldpcli(*("configure system interface permanent e*").split()) assert result.returncode == 0 - result = lldpcli(*("configure dot3 power " - "pse supported enabled paircontrol powerpairs " - "spare class class-3").split()) + result = lldpcli( + *( + "configure dot3 power " + "pse supported enabled paircontrol powerpairs " + "spare class class-3" + ).split() + ) assert result.returncode == 0 time.sleep(3) - links.remove('eth3') - links.remove('noteth3') + links.remove("eth3") + links.remove("noteth3") time.sleep(4) # eth3 configuration is kept because it matches the permanent # port pattern. out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") - assert out['lldp.eth3.port.power.device-type'] == 'PSE' - assert 'lldp.noteth3.port.power.device-type' not in out + assert out["lldp.eth3.port.power.device-type"] == "PSE" + assert "lldp.noteth3.port.power.device-type" not in out - links.dummy('eth3') - links.dummy('noteth3') + links.dummy("eth3") + links.dummy("noteth3") time.sleep(4) # eth3 configuration is unchanged out = lldpcli("-f", "keyvalue", "show", "interfaces", "details") - assert out['lldp.eth3.port.power.device-type'] == 'PSE' + assert out["lldp.eth3.port.power.device-type"] == "PSE" # noteth3 inherited from default - assert out['lldp.noteth3.port.power.device-type'] == 'PSE' + assert out["lldp.noteth3.port.power.device-type"] == "PSE" def test_watch(lldpd1, lldpd, lldpcli, namespaces, links): @@ -497,72 +605,67 @@ def test_watch(lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(1): result = lldpcli("show", "neighbors") assert result.returncode == 0 - out = result.stdout.decode('ascii') + out = result.stdout.decode("ascii") assert "ns-2.example.com" in out # Put a link down and immediately watch for a change - links.down('eth0') + links.down("eth0") result = lldpcli("watch", "limit", "1") assert result.returncode == 0 - expected = out.replace('LLDP neighbors:', 'LLDP neighbor deleted:') - expected = re.sub(r', Time: 0 day, 00:.*$', '', expected, - flags=re.MULTILINE) - got = result.stdout.decode('ascii') - got = re.sub(r', Time: 0 day, 00:.*$', '', got, - flags=re.MULTILINE) + expected = out.replace("LLDP neighbors:", "LLDP neighbor deleted:") + expected = re.sub(r", Time: 0 day, 00:.*$", "", expected, flags=re.MULTILINE) + got = result.stdout.decode("ascii") + got = re.sub(r", Time: 0 day, 00:.*$", "", got, flags=re.MULTILINE) assert got == expected -@pytest.mark.skipif("'XML' not in config.lldpcli.outputs", - reason="XML not supported") +@pytest.mark.skipif("'XML' not in config.lldpcli.outputs", reason="XML not supported") def test_watch_xml(lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): lldpd() with namespaces(1): result = lldpcli("-f", "xml", "show", "neighbors") assert result.returncode == 0 - expected = result.stdout.decode('ascii') + expected = result.stdout.decode("ascii") expected = ET.fromstring(expected) - assert [x.text - for x in expected.findall("./interface/chassis/name")] == \ - ["ns-2.example.com"] + assert [x.text for x in expected.findall("./interface/chassis/name")] == [ + "ns-2.example.com" + ] # Put a link down and immediately watch for a change - links.down('eth0') + links.down("eth0") result = lldpcli("-f", "xml", "watch", "limit", "1") assert result.returncode == 0 - expected.tag = 'lldp-deleted' - expected.set('label', 'LLDP neighbor deleted') - expected.find('./interface').set('age', '') - got = result.stdout.decode('ascii') + expected.tag = "lldp-deleted" + expected.set("label", "LLDP neighbor deleted") + expected.find("./interface").set("age", "") + got = result.stdout.decode("ascii") got = ET.fromstring(got) - got.find('./interface').set('age', '') + got.find("./interface").set("age", "") assert canonicalize(ET.tostring(got)) == canonicalize(ET.tostring(expected)) -@pytest.mark.skipif("'JSON' not in config.lldpcli.outputs", - reason="JSON not supported") +@pytest.mark.skipif("'JSON' not in config.lldpcli.outputs", reason="JSON not supported") def test_watch_json(lldpd1, lldpd, lldpcli, namespaces, links): with namespaces(2): lldpd() with namespaces(1): result = lldpcli("-f", "json", "show", "neighbors") assert result.returncode == 0 - expected = result.stdout.decode('ascii') + expected = result.stdout.decode("ascii") expected = json.loads(expected) - assert 'ns-2.example.com' in \ - expected['lldp']['interface']['eth0']['chassis'] + assert "ns-2.example.com" in expected["lldp"]["interface"]["eth0"]["chassis"] # Put a link down and immediately watch for a change - links.down('eth0') + links.down("eth0") result = lldpcli("-f", "json", "watch", "limit", "1") assert result.returncode == 0 - got = result.stdout.decode('ascii') + got = result.stdout.decode("ascii") got = json.loads(got) - expected['lldp-deleted'] = expected['lldp'] - del expected['lldp'] - del expected['lldp-deleted']['interface']['eth0']['age'] - del got['lldp-deleted']['interface']['eth0']['age'] + expected["lldp-deleted"] = expected["lldp"] + del expected["lldp"] + del expected["lldp-deleted"]["interface"]["eth0"]["age"] + del got["lldp-deleted"]["interface"]["eth0"]["age"] assert got == expected @@ -576,55 +679,74 @@ def test_return_code(lldpd1, lldpcli, namespaces): assert result.returncode == 1 -@pytest.mark.parametrize("command, name, expected", [ - ("configure system max-neighbors 10", "max-neighbors", 10), - # get integral tx-delay from non-integral value (rounded up value) - ("configure lldp tx-interval 1500ms", "tx-delay", 2), - # get non-integral tx-delay-ms from non-integral value (exact value) - ("configure lldp tx-interval 2500ms", "tx-delay-ms", 2500), - ("configure lldp tx-interval 20", "tx-delay", 20), - ("configure lldp tx-hold 5", "tx-hold", 5), - ("configure lldp portidsubtype ifname", "lldp-portid-type", "ifname"), - pytest.param("unconfigure med fast-start", - "lldpmed-faststart", "no", - marks=pytest.mark.skipif( - "'LLDP-MED' not in config.lldpd.features", - reason="LLDP-MED not supported")), - pytest.param("configure med fast-start tx-interval 2", - "lldpmed-faststart-interval", 2, - marks=pytest.mark.skipif( - "'LLDP-MED' not in config.lldpd.features", - reason="LLDP-MED not supported")), - ("configure system interface pattern eth*", "iface-pattern", "eth*"), - ("configure system interface permanent eth*", - "perm-iface-pattern", "eth*"), - ("configure system ip management pattern 10.*", "mgmt-pattern", "10.*"), - ("configure system chassisid squid", "cid-string", "squid"), - ("configure system platform squid", "platform", "squid"), - ("configure system description squid", "description", "squid"), - ("configure system hostname squid", "hostname", "squid"), - ("configure system interface description", "ifdescr-update", "yes"), - ("configure system interface promiscuous", "iface-promisc", "yes"), - ("configure system bond-slave-src-mac-type fixed", - "bond-slave-src-mac-type", "fixed"), - ("configure system description " - "1234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890", - "description", - "1234567890123456789012345678901234567890" - "1234567890123456789012345678901234567890"), - ("configure lldp agent-type nearest-customer-bridge", - "lldp-agent-type", "nearest customer bridge")]) +@pytest.mark.parametrize( + "command, name, expected", + [ + ("configure system max-neighbors 10", "max-neighbors", 10), + # get integral tx-delay from non-integral value (rounded up value) + ("configure lldp tx-interval 1500ms", "tx-delay", 2), + # get non-integral tx-delay-ms from non-integral value (exact value) + ("configure lldp tx-interval 2500ms", "tx-delay-ms", 2500), + ("configure lldp tx-interval 20", "tx-delay", 20), + ("configure lldp tx-hold 5", "tx-hold", 5), + ("configure lldp portidsubtype ifname", "lldp-portid-type", "ifname"), + pytest.param( + "unconfigure med fast-start", + "lldpmed-faststart", + "no", + marks=pytest.mark.skipif( + "'LLDP-MED' not in config.lldpd.features", + reason="LLDP-MED not supported", + ), + ), + pytest.param( + "configure med fast-start tx-interval 2", + "lldpmed-faststart-interval", + 2, + marks=pytest.mark.skipif( + "'LLDP-MED' not in config.lldpd.features", + reason="LLDP-MED not supported", + ), + ), + ("configure system interface pattern eth*", "iface-pattern", "eth*"), + ("configure system interface permanent eth*", "perm-iface-pattern", "eth*"), + ("configure system ip management pattern 10.*", "mgmt-pattern", "10.*"), + ("configure system chassisid squid", "cid-string", "squid"), + ("configure system platform squid", "platform", "squid"), + ("configure system description squid", "description", "squid"), + ("configure system hostname squid", "hostname", "squid"), + ("configure system interface description", "ifdescr-update", "yes"), + ("configure system interface promiscuous", "iface-promisc", "yes"), + ( + "configure system bond-slave-src-mac-type fixed", + "bond-slave-src-mac-type", + "fixed", + ), + ( + "configure system description " + "1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890", + "description", + "1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890", + ), + ( + "configure lldp agent-type nearest-customer-bridge", + "lldp-agent-type", + "nearest customer bridge", + ), + ], +) def test_config_change(lldpd1, lldpcli, namespaces, command, name, expected): with namespaces(1): # Check initial value first out = lldpcli("-f", "keyvalue", "show", "configuration") - assert out['configuration.config.{}'.format(name)] != str(expected) + assert out["configuration.config.{}".format(name)] != str(expected) # Issue change and check new value result = lldpcli(*shlex.split(command)) assert result.returncode == 0 out = lldpcli("-f", "keyvalue", "show", "configuration") - assert out['configuration.config.{}'.format(name)] == str(expected) + assert out["configuration.config.{}".format(name)] == str(expected) def test_config_capabilities(lldpd1, lldpcli, namespaces): @@ -632,37 +754,37 @@ def test_config_capabilities(lldpd1, lldpcli, namespaces): out = lldpcli("-f", "keyvalue", "show", "chassis") # Save values to check after unconfigure - bridge = out['local-chassis.chassis.Bridge.enabled'] - router = out['local-chassis.chassis.Router.enabled'] - wlan = out['local-chassis.chassis.Wlan.enabled'] - station = out['local-chassis.chassis.Station.enabled'] + bridge = out["local-chassis.chassis.Bridge.enabled"] + router = out["local-chassis.chassis.Router.enabled"] + wlan = out["local-chassis.chassis.Wlan.enabled"] + station = out["local-chassis.chassis.Station.enabled"] # Configure only bridge capability lldpcli("configure", "system", "capabilities", "enabled", "bridge") # Check only bridge capability on out = lldpcli("-f", "keyvalue", "show", "chassis") - assert out['local-chassis.chassis.Bridge.enabled'] == "on" - assert out['local-chassis.chassis.Router.enabled'] == "off" - assert out['local-chassis.chassis.Wlan.enabled'] == "off" - assert out['local-chassis.chassis.Station.enabled'] == "off" + assert out["local-chassis.chassis.Bridge.enabled"] == "on" + assert out["local-chassis.chassis.Router.enabled"] == "off" + assert out["local-chassis.chassis.Wlan.enabled"] == "off" + assert out["local-chassis.chassis.Station.enabled"] == "off" # Configure router and wlan capabilities. lldpcli("configure", "system", "capabilities", "enabled", "router,wlan") # This shoud enable only router and wlan and set to off the bridge capability again out = lldpcli("-f", "keyvalue", "show", "chassis") - assert out['local-chassis.chassis.Bridge.enabled'] == "off" - assert out['local-chassis.chassis.Router.enabled'] == "on" - assert out['local-chassis.chassis.Wlan.enabled'] == "on" - assert out['local-chassis.chassis.Station.enabled'] == "off" + assert out["local-chassis.chassis.Bridge.enabled"] == "off" + assert out["local-chassis.chassis.Router.enabled"] == "on" + assert out["local-chassis.chassis.Wlan.enabled"] == "on" + assert out["local-chassis.chassis.Station.enabled"] == "off" # Unconfigure system capabilities and use again the kernel information to enable capabilities lldpcli("unconfigure", "system", "capabilities", "enabled") # Check if the capabilities have the same values as before start the configurations out = lldpcli("-f", "keyvalue", "show", "chassis") - assert out['local-chassis.chassis.Bridge.enabled'] == bridge - assert out['local-chassis.chassis.Router.enabled'] == router - assert out['local-chassis.chassis.Wlan.enabled'] == wlan - assert out['local-chassis.chassis.Station.enabled'] == station + assert out["local-chassis.chassis.Bridge.enabled"] == bridge + assert out["local-chassis.chassis.Router.enabled"] == router + assert out["local-chassis.chassis.Wlan.enabled"] == wlan + assert out["local-chassis.chassis.Station.enabled"] == station diff --git a/tests/integration/test_med.py b/tests/integration/test_med.py index 3f20e40e..d8bdffd2 100644 --- a/tests/integration/test_med.py +++ b/tests/integration/test_med.py @@ -5,127 +5,155 @@ import time import shlex -@pytest.mark.skipif("'LLDP-MED' not in config.lldpd.features", - reason="LLDP-MED not supported") +@pytest.mark.skipif( + "'LLDP-MED' not in config.lldpd.features", reason="LLDP-MED not supported" +) class TestLldpMed(object): - - @pytest.mark.parametrize("classe, expected", [ - (1, "Generic Endpoint (Class I)"), - (2, "Media Endpoint (Class II)"), - (3, "Communication Device Endpoint (Class III)"), - (4, "Network Connectivity Device")]) - def test_med_devicetype(self, lldpd1, lldpd, lldpcli, namespaces, - classe, expected): + @pytest.mark.parametrize( + "classe, expected", + [ + (1, "Generic Endpoint (Class I)"), + (2, "Media Endpoint (Class II)"), + (3, "Communication Device Endpoint (Class III)"), + (4, "Network Connectivity Device"), + ], + ) + def test_med_devicetype(self, lldpd1, lldpd, lldpcli, namespaces, classe, expected): with namespaces(2): lldpd("-M", str(classe)) with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.lldp-med.device-type'] == expected + assert out["lldp.eth0.lldp-med.device-type"] == expected def test_med_capabilities(self, lldpd1, lldpd, lldpcli, namespaces): with namespaces(2): lldpd("-M", "2") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - out = {k.split(".")[3]: v - for k, v in out.items() - if k.endswith('.available')} - assert out == {'Capabilities': 'yes', - 'Policy': 'yes', - 'Location': 'yes', - 'MDI/PSE': 'yes', - 'MDI/PD': 'yes', - 'Inventory': 'yes'} + out = { + k.split(".")[3]: v for k, v in out.items() if k.endswith(".available") + } + assert out == { + "Capabilities": "yes", + "Policy": "yes", + "Location": "yes", + "MDI/PSE": "yes", + "MDI/PD": "yes", + "Inventory": "yes", + } - @pytest.mark.skipif(not os.path.isdir("/sys/class/dmi/id"), - reason="/sys/class/dmi not available") - def test_med_inventory(self, lldpd1, lldpd, lldpcli, namespaces, - replace_file): + @pytest.mark.skipif( + not os.path.isdir("/sys/class/dmi/id"), reason="/sys/class/dmi not available" + ) + def test_med_inventory(self, lldpd1, lldpd, lldpcli, namespaces, replace_file): with namespaces(2): # /sys/class/dmi/id/* - for what, value in dict(product_version="1.14", - bios_version="1.10", - product_serial="45872512", - sys_vendor="Spectacular", - product_name="Workstation", - chassis_asset_tag="487122").items(): - replace_file("/sys/class/dmi/id/{}".format(what), - value) + for what, value in dict( + product_version="1.14", + bios_version="1.10", + product_serial="45872512", + sys_vendor="Spectacular", + product_name="Workstation", + chassis_asset_tag="487122", + ).items(): + replace_file("/sys/class/dmi/id/{}".format(what), value) lldpd("-M", "1") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.chassis.name'] == 'ns-2.example.com' - assert out['lldp.eth0.lldp-med.inventory.hardware'] == '1.14' - assert out['lldp.eth0.lldp-med.inventory.firmware'] == '1.10' - assert out['lldp.eth0.lldp-med.inventory.serial'] == '45872512' - assert out['lldp.eth0.lldp-med.inventory.manufacturer'] == \ - 'Spectacular' - assert out['lldp.eth0.lldp-med.inventory.model'] == 'Workstation' - assert out['lldp.eth0.lldp-med.inventory.asset'] == '487122' - assert out['lldp.eth0.lldp-med.inventory.software'] == \ - platform.release() + assert out["lldp.eth0.chassis.name"] == "ns-2.example.com" + assert out["lldp.eth0.lldp-med.inventory.hardware"] == "1.14" + assert out["lldp.eth0.lldp-med.inventory.firmware"] == "1.10" + assert out["lldp.eth0.lldp-med.inventory.serial"] == "45872512" + assert out["lldp.eth0.lldp-med.inventory.manufacturer"] == "Spectacular" + assert out["lldp.eth0.lldp-med.inventory.model"] == "Workstation" + assert out["lldp.eth0.lldp-med.inventory.asset"] == "487122" + assert out["lldp.eth0.lldp-med.inventory.software"] == platform.release() - @pytest.mark.parametrize("command, pfx, expected", [ - # Policies - ("policy application voice tagged vlan 500 priority voice dscp 46", - "policy", - {'apptype': 'Voice', - 'defined': 'yes', - 'priority': 'Voice', - 'pcp': '5', - 'dscp': '46', - 'vlan.vid': '500'}), - ("policy application video-conferencing unknown dscp 3 priority video", - "policy", - {'apptype': 'Video Conferencing', - 'defined': 'no', - 'priority': 'Video', - 'pcp': '4', - 'dscp': '3'}), - # Locations - ("location coordinate latitude 48.58667N longitude 2.2014E " - "altitude 117.47 m datum WGS84", - "Coordinates", - {'geoid': 'WGS84', - 'lat': '48.58666N', - 'lon': '2.2013E', - 'altitude.unit': 'm', - 'altitude': '117.46'}), - ('location address country US language en_US street ' - '"Commercial Road" city "Roseville"', - "Civic address", - {'country': 'US', - 'language': 'en_US', - 'city': 'Roseville', - 'street': 'Commercial Road'}), - ('location elin 911', - "ELIN", - {'ecs': '911'}), - # Power - ("power pd source pse priority high value 5000", - "poe", - {'device-type': 'PD', - 'source': 'PSE', - 'priority': 'high', - 'power': '5000'}), - ("power pse source backup priority critical value 300", - "poe", - {'device-type': 'PSE', - 'source': 'Backup Power Source / Power Conservation Mode', - 'priority': 'critical', - 'power': '300'})]) - def test_med_configuration(self, lldpd1, lldpd, lldpcli, namespaces, - command, pfx, expected): + @pytest.mark.parametrize( + "command, pfx, expected", + [ + # Policies + ( + "policy application voice tagged vlan 500 priority voice dscp 46", + "policy", + { + "apptype": "Voice", + "defined": "yes", + "priority": "Voice", + "pcp": "5", + "dscp": "46", + "vlan.vid": "500", + }, + ), + ( + "policy application video-conferencing unknown dscp 3 priority video", + "policy", + { + "apptype": "Video Conferencing", + "defined": "no", + "priority": "Video", + "pcp": "4", + "dscp": "3", + }, + ), + # Locations + ( + "location coordinate latitude 48.58667N longitude 2.2014E " + "altitude 117.47 m datum WGS84", + "Coordinates", + { + "geoid": "WGS84", + "lat": "48.58666N", + "lon": "2.2013E", + "altitude.unit": "m", + "altitude": "117.46", + }, + ), + ( + "location address country US language en_US street " + '"Commercial Road" city "Roseville"', + "Civic address", + { + "country": "US", + "language": "en_US", + "city": "Roseville", + "street": "Commercial Road", + }, + ), + ("location elin 911", "ELIN", {"ecs": "911"}), + # Power + ( + "power pd source pse priority high value 5000", + "poe", + { + "device-type": "PD", + "source": "PSE", + "priority": "high", + "power": "5000", + }, + ), + ( + "power pse source backup priority critical value 300", + "poe", + { + "device-type": "PSE", + "source": "Backup Power Source / Power Conservation Mode", + "priority": "critical", + "power": "300", + }, + ), + ], + ) + def test_med_configuration( + self, lldpd1, lldpd, lldpcli, namespaces, command, pfx, expected + ): with namespaces(2): lldpd("-M", "1") - result = lldpcli( - *shlex.split("configure med {}".format(command))) + result = lldpcli(*shlex.split("configure med {}".format(command))) assert result.returncode == 0 time.sleep(3) with namespaces(1): pfx = "lldp.eth0.lldp-med.{}.".format(pfx) out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - out = {k[len(pfx):]: v - for k, v in out.items() - if k.startswith(pfx)} + out = {k[len(pfx) :]: v for k, v in out.items() if k.startswith(pfx)} assert out == expected diff --git a/tests/integration/test_pcap.py b/tests/integration/test_pcap.py index 5f3c0b1a..5dfe7207 100644 --- a/tests/integration/test_pcap.py +++ b/tests/integration/test_pcap.py @@ -3,11 +3,11 @@ import pytest def test_cisco_sg200(request, lldpd1, lldpcli, namespaces): with namespaces(2): - pytest.helpers.send_pcap('data/sg200.pcap', 'eth1') + pytest.helpers.send_pcap("data/sg200.pcap", "eth1") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") - assert out['lldp.eth0.age'].startswith('0 day, 00:00:') - del out['lldp.eth0.age'] + assert out["lldp.eth0.age"].startswith("0 day, 00:00:") + del out["lldp.eth0.age"] expected = { "lldp.eth0.via": "LLDP", "lldp.eth0.rid": "1", @@ -15,100 +15,103 @@ def test_cisco_sg200(request, lldpd1, lldpcli, namespaces): "lldp.eth0.port.ttl": "120", "lldp.eth0.port.ifname": "g1", } - if 'Dot3' in request.config.lldpd.features: - expected.update({ - "lldp.eth0.port.auto-negotiation.supported": "yes", - "lldp.eth0.port.auto-negotiation.enabled": "yes", - "lldp.eth0.port.auto-negotiation.1000Base-T.hd": "no", - "lldp.eth0.port.auto-negotiation.1000Base-T.fd": "yes", - "lldp.eth0.port.auto-negotiation.current": "unknown", - }) - if 'LLDP-MED' in request.config.lldpd.features: - expected.update({ - "lldp.eth0.lldp-med.device-type": - "Network Connectivity Device", - "lldp.eth0.lldp-med.Capabilities.available": "yes", - "lldp.eth0.lldp-med.Policy.available": "yes", - "lldp.eth0.lldp-med.Location.available": "yes", - "lldp.eth0.lldp-med.MDI/PSE.available": "yes", - "lldp.eth0.lldp-med.Inventory.available": "yes", - "lldp.eth0.lldp-med.Civic address.country": "DE", - "lldp.eth0.lldp-med.Civic address.city": "Berlin", - "lldp.eth0.lldp-med.Civic address.street": - "Karl-Liebknecht-Strase", - "lldp.eth0.lldp-med.Civic address.building": "42", - "lldp.eth0.lldp-med.inventory.hardware": "V02", - "lldp.eth0.lldp-med.inventory.software": "1.0.8.3", - "lldp.eth0.lldp-med.inventory.firmware": "1.0.8.3", - "lldp.eth0.lldp-med.inventory.serial": "XXX11111ZZZ", - "lldp.eth0.lldp-med.inventory.manufacturer": "0xbc00", - "lldp.eth0.lldp-med.inventory.model": "SG 200-08P", - "lldp.eth0.lldp-med.inventory.asset": "1" - }) + if "Dot3" in request.config.lldpd.features: + expected.update( + { + "lldp.eth0.port.auto-negotiation.supported": "yes", + "lldp.eth0.port.auto-negotiation.enabled": "yes", + "lldp.eth0.port.auto-negotiation.1000Base-T.hd": "no", + "lldp.eth0.port.auto-negotiation.1000Base-T.fd": "yes", + "lldp.eth0.port.auto-negotiation.current": "unknown", + } + ) + if "LLDP-MED" in request.config.lldpd.features: + expected.update( + { + "lldp.eth0.lldp-med.device-type": "Network Connectivity Device", + "lldp.eth0.lldp-med.Capabilities.available": "yes", + "lldp.eth0.lldp-med.Policy.available": "yes", + "lldp.eth0.lldp-med.Location.available": "yes", + "lldp.eth0.lldp-med.MDI/PSE.available": "yes", + "lldp.eth0.lldp-med.Inventory.available": "yes", + "lldp.eth0.lldp-med.Civic address.country": "DE", + "lldp.eth0.lldp-med.Civic address.city": "Berlin", + "lldp.eth0.lldp-med.Civic address.street": "Karl-Liebknecht-Strase", + "lldp.eth0.lldp-med.Civic address.building": "42", + "lldp.eth0.lldp-med.inventory.hardware": "V02", + "lldp.eth0.lldp-med.inventory.software": "1.0.8.3", + "lldp.eth0.lldp-med.inventory.firmware": "1.0.8.3", + "lldp.eth0.lldp-med.inventory.serial": "XXX11111ZZZ", + "lldp.eth0.lldp-med.inventory.manufacturer": "0xbc00", + "lldp.eth0.lldp-med.inventory.model": "SG 200-08P", + "lldp.eth0.lldp-med.inventory.asset": "1", + } + ) assert out == expected -@pytest.mark.skipif("'Dot3' not in config.lldpd.features", - readon="Dot3 not supported") +@pytest.mark.skipif("'Dot3' not in config.lldpd.features", readon="Dot3 not supported") def test_8023bt(lldpd1, lldpcli, namespaces): with namespaces(2): - pytest.helpers.send_pcap('data/8023bt.pcap', 'eth1') + pytest.helpers.send_pcap("data/8023bt.pcap", "eth1") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") for k in list(out.keys()): if not k.startswith("lldp.eth0.port.power."): del out[k] assert out == { - 'lldp.eth0.port.power.supported': 'yes', - 'lldp.eth0.port.power.enabled': 'yes', - 'lldp.eth0.port.power.paircontrol': 'yes', - 'lldp.eth0.port.power.device-type': 'PSE', - 'lldp.eth0.port.power.pairs': 'signal', - 'lldp.eth0.port.power.class': 'class 4', - 'lldp.eth0.port.power.power-type': '2', - 'lldp.eth0.port.power.source': 'PSE', - 'lldp.eth0.port.power.priority': 'low', - 'lldp.eth0.port.power.requested': '71000', - 'lldp.eth0.port.power.allocated': '51000', - 'lldp.eth0.port.power.requested-a': '35500', - 'lldp.eth0.port.power.requested-b': '35500', - 'lldp.eth0.port.power.allocated-a': '25500', - 'lldp.eth0.port.power.allocated-b': '25500', - 'lldp.eth0.port.power.pse-powering-status': - '4-pair powering single-signature PD', - 'lldp.eth0.port.power.pd-powering-status': 'Unknown', - 'lldp.eth0.port.power.power-pairs-ext': 'Both alternatives', - 'lldp.eth0.port.power.power-class-ext-a': 'Class 4', - 'lldp.eth0.port.power.power-class-ext-b': 'Class 4', - 'lldp.eth0.port.power.power-class-ext': 'Dual-signature PD', - 'lldp.eth0.port.power.power-type-ext': 'Type 3 PSE', - 'lldp.eth0.port.power.pd-load': - ('PD is single- or dual-signature and power ' - 'is not electrically isolated'), - 'lldp.eth0.port.power.max-power': '51000' + "lldp.eth0.port.power.supported": "yes", + "lldp.eth0.port.power.enabled": "yes", + "lldp.eth0.port.power.paircontrol": "yes", + "lldp.eth0.port.power.device-type": "PSE", + "lldp.eth0.port.power.pairs": "signal", + "lldp.eth0.port.power.class": "class 4", + "lldp.eth0.port.power.power-type": "2", + "lldp.eth0.port.power.source": "PSE", + "lldp.eth0.port.power.priority": "low", + "lldp.eth0.port.power.requested": "71000", + "lldp.eth0.port.power.allocated": "51000", + "lldp.eth0.port.power.requested-a": "35500", + "lldp.eth0.port.power.requested-b": "35500", + "lldp.eth0.port.power.allocated-a": "25500", + "lldp.eth0.port.power.allocated-b": "25500", + "lldp.eth0.port.power.pse-powering-status": "4-pair powering single-signature PD", + "lldp.eth0.port.power.pd-powering-status": "Unknown", + "lldp.eth0.port.power.power-pairs-ext": "Both alternatives", + "lldp.eth0.port.power.power-class-ext-a": "Class 4", + "lldp.eth0.port.power.power-class-ext-b": "Class 4", + "lldp.eth0.port.power.power-class-ext": "Dual-signature PD", + "lldp.eth0.port.power.power-type-ext": "Type 3 PSE", + "lldp.eth0.port.power.pd-load": ( + "PD is single- or dual-signature and power " + "is not electrically isolated" + ), + "lldp.eth0.port.power.max-power": "51000", } -@pytest.mark.skipif("'LLDP-MED' not in config.lldpd.features", - readon="LLDP-MED not supported") + +@pytest.mark.skipif( + "'LLDP-MED' not in config.lldpd.features", readon="LLDP-MED not supported" +) def test_med_loc_malformed(lldpd1, lldpcli, namespaces): with namespaces(2): - pytest.helpers.send_pcap('data/med-loc-malformed.pcap', 'eth1') + pytest.helpers.send_pcap("data/med-loc-malformed.pcap", "eth1") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") for k in list(out.keys()): if not k.startswith("lldp.eth0.lldp-med."): del out[k] assert out == { - 'lldp.eth0.lldp-med.device-type': 'Communication Device Endpoint (Class III)', - 'lldp.eth0.lldp-med.Capabilities.available': 'yes', - 'lldp.eth0.lldp-med.Policy.available': 'yes', - 'lldp.eth0.lldp-med.Location.available': 'yes', - 'lldp.eth0.lldp-med.Inventory.available': 'yes', - 'lldp.eth0.lldp-med.policy.apptype': 'Voice', - 'lldp.eth0.lldp-med.policy.defined': 'yes', - 'lldp.eth0.lldp-med.policy.priority': 'Best effort', - 'lldp.eth0.lldp-med.policy.pcp': '0', - 'lldp.eth0.lldp-med.policy.dscp': '0', - 'lldp.eth0.lldp-med.Civic address.country': 'F5' + "lldp.eth0.lldp-med.device-type": "Communication Device Endpoint (Class III)", + "lldp.eth0.lldp-med.Capabilities.available": "yes", + "lldp.eth0.lldp-med.Policy.available": "yes", + "lldp.eth0.lldp-med.Location.available": "yes", + "lldp.eth0.lldp-med.Inventory.available": "yes", + "lldp.eth0.lldp-med.policy.apptype": "Voice", + "lldp.eth0.lldp-med.policy.defined": "yes", + "lldp.eth0.lldp-med.policy.priority": "Best effort", + "lldp.eth0.lldp-med.policy.pcp": "0", + "lldp.eth0.lldp-med.policy.dscp": "0", + "lldp.eth0.lldp-med.Civic address.country": "F5" # Truncated } diff --git a/tests/integration/test_protocols.py b/tests/integration/test_protocols.py index b47327de..6169cdfe 100644 --- a/tests/integration/test_protocols.py +++ b/tests/integration/test_protocols.py @@ -2,13 +2,9 @@ import pytest import pyroute2 -@pytest.mark.skipif("'CDP' not in config.lldpd.protocols", - reason="CDP not supported") -@pytest.mark.parametrize("argument, expected", [ - ("-cc", "CDPv1"), - ("-ccc", "CDPv2")]) -def test_cdp(lldpd, lldpcli, links, namespaces, - argument, expected): +@pytest.mark.skipif("'CDP' not in config.lldpd.protocols", reason="CDP not supported") +@pytest.mark.parametrize("argument, expected", [("-cc", "CDPv1"), ("-ccc", "CDPv2")]) +def test_cdp(lldpd, lldpcli, links, namespaces, argument, expected): links(namespaces(1), namespaces(2)) with namespaces(1): lldpd("-c", "-ll", "-r") @@ -20,13 +16,13 @@ def test_cdp(lldpd, lldpcli, links, namespaces, assert out["lldp.eth0.chassis.local"] == "ns-2.example.com" assert out["lldp.eth0.chassis.name"] == "ns-2.example.com" assert out["lldp.eth0.chassis.descr"].startswith( - "Linux running on Spectacular GNU/Linux 2016") + "Linux running on Spectacular GNU/Linux 2016" + ) assert out["lldp.eth0.port.ifname"] == "eth1" assert out["lldp.eth0.port.descr"] == "eth1" -@pytest.mark.skipif("'FDP' not in config.lldpd.protocols", - reason="FDP not supported") +@pytest.mark.skipif("'FDP' not in config.lldpd.protocols", reason="FDP not supported") def test_fdp(lldpd, lldpcli, links, namespaces): links(namespaces(1), namespaces(2)) with namespaces(1): @@ -39,13 +35,13 @@ def test_fdp(lldpd, lldpcli, links, namespaces): assert out["lldp.eth0.chassis.local"] == "ns-2.example.com" assert out["lldp.eth0.chassis.name"] == "ns-2.example.com" assert out["lldp.eth0.chassis.descr"].startswith( - "Linux running on Spectacular GNU/Linux 2016") + "Linux running on Spectacular GNU/Linux 2016" + ) assert out["lldp.eth0.port.ifname"] == "eth1" assert out["lldp.eth0.port.descr"] == "eth1" -@pytest.mark.skipif("'EDP' not in config.lldpd.protocols", - reason="EDP not supported") +@pytest.mark.skipif("'EDP' not in config.lldpd.protocols", reason="EDP not supported") def test_edp(lldpd, lldpcli, links, namespaces): links(namespaces(1), namespaces(2)) with namespaces(1): @@ -57,14 +53,14 @@ def test_edp(lldpd, lldpcli, links, namespaces): assert out["lldp.eth0.via"] == "EDP" assert out["lldp.eth0.chassis.mac"] == "00:00:00:00:00:02" assert out["lldp.eth0.chassis.name"] == "ns-2.example.com" - assert out["lldp.eth0.chassis.descr"] == \ - "EDP enabled device, version 7.6.4.99" + assert out["lldp.eth0.chassis.descr"] == "EDP enabled device, version 7.6.4.99" assert out["lldp.eth0.port.ifname"] == "1/2" assert out["lldp.eth0.port.descr"] == "Slot 1 / Port 2" -@pytest.mark.skipif("'SONMP' not in config.lldpd.protocols", - reason="SONMP not supported") +@pytest.mark.skipif( + "'SONMP' not in config.lldpd.protocols", reason="SONMP not supported" +) def test_sonmp(lldpd, lldpcli, links, namespaces): links(namespaces(1), namespaces(2)) with namespaces(1): @@ -72,7 +68,7 @@ def test_sonmp(lldpd, lldpcli, links, namespaces): with namespaces(2): with pyroute2.IPRoute() as ipr: idx = ipr.link_lookup(ifname="eth1")[0] - ipr.addr('add', index=idx, address="192.168.14.2", mask=24) + ipr.addr("add", index=idx, address="192.168.14.2", mask=24) lldpd("-ss", "-ll") with namespaces(1): out = lldpcli("-f", "keyvalue", "show", "neighbors", "details") diff --git a/tests/integration/test_snmp.py b/tests/integration/test_snmp.py index 6ce3e48c..9024ee4f 100644 --- a/tests/integration/test_snmp.py +++ b/tests/integration/test_snmp.py @@ -1,7 +1,6 @@ import pytest -pytestmark = pytest.mark.skipif("not config.lldpd.snmp", - reason="no SNMP support") +pytestmark = pytest.mark.skipif("not config.lldpd.snmp", reason="no SNMP support") def test_snmp_register(snmpd, snmpwalk, lldpd, namespaces): @@ -20,12 +19,12 @@ def test_snmp_one_neighbor(snmpd, snmpwalk, lldpd, namespaces): lldpd() with namespaces(1): out = snmpwalk(".1.0.8802.1.1.2.1") - assert out['.1.0.8802.1.1.2.1.2.1.0'].startswith( - "Timeticks: ") - assert out['.1.0.8802.1.1.2.1.3.2.0'] == 'STRING: "ns-1.example.com"' - assert out['.1.0.8802.1.1.2.1.3.3.0'] == 'STRING: "ns-1.example.com"' - assert out['.1.0.8802.1.1.2.1.3.4.0'].startswith( - 'STRING: "Spectacular GNU/Linux 2016 Linux') + assert out[".1.0.8802.1.1.2.1.2.1.0"].startswith("Timeticks: ") + assert out[".1.0.8802.1.1.2.1.3.2.0"] == 'STRING: "ns-1.example.com"' + assert out[".1.0.8802.1.1.2.1.3.3.0"] == 'STRING: "ns-1.example.com"' + assert out[".1.0.8802.1.1.2.1.3.4.0"].startswith( + 'STRING: "Spectacular GNU/Linux 2016 Linux' + ) def test_snmp_empty_sysname(snmpd, snmpwalk, lldpd, links, namespaces): @@ -41,7 +40,7 @@ def test_snmp_empty_sysname(snmpd, snmpwalk, lldpd, links, namespaces): with namespaces(3): # Packet without sysName lldpd("-r") - pytest.helpers.send_pcap('data/connectx.pcap', 'eth3') + pytest.helpers.send_pcap("data/connectx.pcap", "eth3") with namespaces(4): lldpd() with namespaces(1): @@ -51,8 +50,10 @@ def test_snmp_empty_sysname(snmpd, snmpwalk, lldpd, links, namespaces): # .1.0.8802.1.1.2.1.4.1.1.9.700.5.2 (not present) # .1.0.8802.1.1.2.1.4.1.1.9.1000.7.3 STRING: "ns-4.example.com" print(out) - assert list(out.values()) == ['STRING: "ns-2.example.com"', - 'STRING: "ns-4.example.com"'] + assert list(out.values()) == [ + 'STRING: "ns-2.example.com"', + 'STRING: "ns-4.example.com"', + ] oids = list(out.keys()) assert oids[0].endswith(".3.1") assert oids[1].endswith(".7.3") diff --git a/tests/pcap-hdr.h b/tests/pcap-hdr.h index 92de0f0f..a08905b7 100644 --- a/tests/pcap-hdr.h +++ b/tests/pcap-hdr.h @@ -7,19 +7,19 @@ * http://wiki.wireshark.org/Development/LibpcapFileFormat */ struct pcap_hdr { - uint32_t magic_number; /* magic number */ - uint16_t version_major; /* major version number */ - uint16_t version_minor; /* minor version number */ - uint32_t thiszone; /* GMT to local correction */ - uint32_t sigfigs; /* accuracy of timestamps */ - uint32_t snaplen; /* max length of captured packets, in octets */ - uint32_t network; /* data link type */ + uint32_t magic_number; /* magic number */ + uint16_t version_major; /* major version number */ + uint16_t version_minor; /* minor version number */ + uint32_t thiszone; /* GMT to local correction */ + uint32_t sigfigs; /* accuracy of timestamps */ + uint32_t snaplen; /* max length of captured packets, in octets */ + uint32_t network; /* data link type */ }; struct pcaprec_hdr { - uint32_t ts_sec; /* timestamp seconds */ - uint32_t ts_usec; /* timestamp microseconds */ - uint32_t incl_len; /* number of octets of packet saved in file */ - uint32_t orig_len; /* actual length of packet */ + uint32_t ts_sec; /* timestamp seconds */ + uint32_t ts_usec; /* timestamp microseconds */ + uint32_t incl_len; /* number of octets of packet saved in file */ + uint32_t orig_len; /* actual length of packet */ }; #endif -- 2.39.5