AX_CFLAGS_GCC_OPTION([-Wdocumentation], [LLDP_CFLAGS])
AX_CFLAGS_GCC_OPTION([-Winline], [LLDP_CFLAGS])
AX_CFLAGS_GCC_OPTION([-Wpointer-arith], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wmissing-prototypes], [LLDP_CFLAGS])
AX_CFLAGS_GCC_OPTION([-Wno-cast-align], [LLDP_CFLAGS]) dnl clang is bad at this
AX_CFLAGS_GCC_OPTION([-Wno-unused-parameter], [LLDP_CFLAGS])
AX_CFLAGS_GCC_OPTION([-Wno-missing-field-initializers], [LLDP_CFLAGS])
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 *);
+ int (*validate)(struct cmd_env *, const void *),
+ int (*execute)(struct lldpctl_conn_t *, struct writer *, struct cmd_env *,
+ const void *),
+ const 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 *);
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_check_no_env(struct cmd_env *, const void *);
+int cmd_check_env(struct cmd_env *, const void *);
+int cmd_store_env(struct lldpctl_conn_t *, struct writer *, struct cmd_env *,
+ const void *);
int cmd_store_env_and_pop(struct lldpctl_conn_t *, struct writer *, struct cmd_env *,
- void *);
+ const void *);
int cmd_store_env_value(struct lldpctl_conn_t *, struct writer *, struct cmd_env *,
- void *);
+ const void *);
int cmd_store_env_value_and_pop(struct lldpctl_conn_t *, struct writer *,
- struct cmd_env *, void *);
+ struct cmd_env *, const void *);
int cmd_store_env_value_and_pop2(struct lldpctl_conn_t *, struct writer *,
- struct cmd_env *, void *);
+ struct cmd_env *, const 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 *);
+ struct cmd_env *, const void *);
+int cmd_store_something_env_value_and_pop2(const char *, struct cmd_env *,
+ const void *);
+int cmd_store_something_env_value(const char *, struct cmd_env *, const 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 **);
/* misc.c */
int contains(const char *, const char *);
-char *totag(const char *);
+const char *totag(const char *);
/* display.c */
#define DISPLAY_BRIEF 1
/**
* Function validating entry in this node. Can be @c NULL.
*/
- int (*validate)(struct cmd_env *, void *);
+ int (*validate)(struct cmd_env *, const 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 */
+ const void *);
+ const void *arg; /**< Magic argument for the previous two functions */
/* List of possible subentries */
TAILQ_HEAD(, cmd_node) subentries; /* List of subnodes */
*/
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)
+ int (*validate)(struct cmd_env *, const void *),
+ int (*execute)(struct lldpctl_conn_t *, struct writer *, struct cmd_env *,
+ const void *),
+ const void *arg)
{
struct cmd_node *new = calloc(1, sizeof(struct cmd_node));
if (new == NULL) fatalx("lldpctl", "out of memory");
* @return 1 if the environment does not contain the key. 0 otherwise.
*/
int
-cmd_check_no_env(struct cmd_env *env, void *key)
+cmd_check_no_env(struct cmd_env *env, const void *key)
{
return cmdenv_get(env, (const char *)key) == NULL;
}
* @return 1 if the environment does contain the key. 0 otherwise.
*/
int
-cmd_check_env(struct cmd_env *env, void *key)
+cmd_check_env(struct cmd_env *env, const void *key)
{
struct cmd_env_el *el;
const char *list = key;
*/
int
cmd_store_env(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *key)
+ const void *key)
{
return cmdenv_put(env, key, NULL) != -1;
}
*/
int
cmd_store_env_and_pop(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *key)
+ struct cmd_env *env, const void *key)
{
return (cmd_store_env(conn, w, env, key) != -1 && cmdenv_pop(env, 1) != -1);
}
*/
int
cmd_store_env_value_and_pop(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *key)
+ struct cmd_env *env, const void *key)
{
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)
+ struct cmd_env *env, const void *key)
{
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)
+ const void *key)
{
return (cmdenv_put(env, key, cmdenv_arg(env)) != -1);
}
int
cmd_store_env_value_and_pop3(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *key)
+ struct cmd_env *env, const void *key)
{
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)
+ const void *value)
{
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, const void *value)
{
return (cmdenv_put(env, what, value) != -1);
}
static int
cmd_inventory(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "configure inventory information");
return 0;
}
- char *action = arg;
+ const 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)) ||
static int
cmd_txdelay(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
const char *interval;
char interval_ms[8]; /* less than 2.5 hours */
static int
cmd_txhold(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "set transmit hold");
static int
cmd_status(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
lldpctl_atom_t *port;
const char *name;
static int
cmd_agent_type(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
const char *str = arg;
int value = -1;
static int
cmd_portid_type_local(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
lldpctl_atom_t *port;
const char *name;
static int
cmd_port_descr(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
lldpctl_atom_t *port;
const char *name;
static int
cmd_portid_type(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
- char *value_str;
+ const char *value_str = 0;
int value = -1;
log_debug("lldpctl", "lldp PortID TLV Subtype");
static int
cmd_chassis_cap_advertise(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
log_debug("lldpctl", "lldp capabilities-advertisements %s",
arg ? "enable" : "disable");
/* FIXME: see about compressing this with other functions */
static int
cmd_chassis_mgmt_advertise(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
log_debug("lldpctl", "lldp management-addresses-advertisements %s",
arg ? "enable" : "disable");
static int
cmd_vlan_tx(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
lldpctl_atom_t *port;
const char *name;
#ifdef ENABLE_CUSTOM
static int
cmd_custom_tlv_set(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
lldpctl_atom_t *port;
const char *s;
uint8_t oui_info[LLDP_TLV_ORG_OUI_INFO_MAXLEN];
int oui_info_len = 0;
uint16_t subtype = 0;
- char *op = "add";
+ const char *op = "add";
if (!arg || !strcmp(arg, "remove")) op = "remove";
}
static int
-cmd_check_no_add_env(struct cmd_env *env, void *arg)
+cmd_check_no_add_env(struct cmd_env *env, const void *arg)
{
const char *what = arg;
if (cmdenv_get(env, "add")) return 0;
}
static int
-cmd_check_no_replace_env(struct cmd_env *env, void *arg)
+cmd_check_no_replace_env(struct cmd_env *env, const void *arg)
{
const char *what = arg;
if (cmdenv_get(env, "replace")) return 0;
return 1;
}
-void
+static void
register_commands_configure_lldp_custom_tlvs(struct cmd_node *configure_lldp,
struct cmd_node *unconfigure_lldp)
{
static int
cmd_store_status_env_value(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *value)
+ struct cmd_env *env, const void *value)
{
return cmd_store_something_env_value("status", env, value);
}
static int
cmd_medlocation_coordinate(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
log_debug("lldpctl", "set MED location coordinate");
return _cmd_medlocation(conn, env, LLDP_MED_LOCFORMAT_COORD);
static int
cmd_medlocation_address(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
log_debug("lldpctl", "set MED location address");
return _cmd_medlocation(conn, env, LLDP_MED_LOCFORMAT_CIVIC);
static int
cmd_medlocation_elin(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const 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)
+ const void *arg)
{
log_debug("lldpctl", "set MED policy");
lldpctl_atom_t *iface;
}
static int
-cmd_check_application_but_no(struct cmd_env *env, void *arg)
+cmd_check_application_but_no(struct cmd_env *env, const void *arg)
{
const char *what = arg;
if (!cmdenv_get(env, "application")) return 0;
}
static int
cmd_store_app_env_value_and_pop2(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *value)
+ struct cmd_env *env, const void *value)
{
return cmd_store_something_env_value_and_pop2("application", env, value);
}
static int
cmd_store_prio_env_value_and_pop2(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *value)
+ struct cmd_env *env, const void *value)
{
return cmd_store_something_env_value_and_pop2("priority", env, value);
}
static int
cmd_faststart(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "configure fast interval support");
return 0;
}
- char *action = arg;
+ const char *action = arg;
if ((!strcmp(action, "enable") &&
(lldpctl_atom_set_int(config, lldpctl_k_config_fast_start_enabled, 1) ==
NULL)) ||
static int
cmd_medpower(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "set MED power");
lldpctl_atom_t *port;
static int
cmd_store_powerpairs_env_value_and_pop2(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *value)
+ struct cmd_env *env, const void *value)
{
return cmd_store_something_env_value_and_pop2("powerpairs", env, value);
}
static int
cmd_store_class_env_value_and_pop2(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *value)
+ struct cmd_env *env, const void *value)
{
return cmd_store_something_env_value_and_pop2("class", env, value);
}
static int
cmd_store_prio_env_value_and_pop2(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *value)
+ struct cmd_env *env, const void *value)
{
return cmd_store_something_env_value_and_pop2("priority", env, value);
}
static int
cmd_dot3power(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "set dot3 power");
lldpctl_atom_t *port;
}
static int
-cmd_check_type_but_no(struct cmd_env *env, void *arg)
+cmd_check_type_but_no(struct cmd_env *env, const void *arg)
{
const char *what = arg;
if (!cmdenv_get(env, "device-type")) return 0;
return 1;
}
static int
-cmd_check_typeat_but_no(struct cmd_env *env, void *arg)
+cmd_check_typeat_but_no(struct cmd_env *env, const void *arg)
{
const char *what = arg;
if (!cmdenv_get(env, "typeat")) return 0;
return (!strcmp(type, etype));
}
static int
-cmd_check_pse(struct cmd_env *env, void *arg)
+cmd_check_pse(struct cmd_env *env, const void *arg)
{
return cmd_check_type(env, "pse");
}
static int
-cmd_check_pd(struct cmd_env *env, void *arg)
+cmd_check_pd(struct cmd_env *env, const void *arg)
{
return cmd_check_type(env, "pd");
}
}
static int
-cmd_check_env_power(struct cmd_env *env, void *nothing)
+cmd_check_env_power(struct cmd_env *env, const void *nothing)
{
/* We need type and powerpair but if we have typeat, we also request
* source, priority, requested and allocated. */
static int
cmd_iface_pattern(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "set iface pattern");
static int
cmd_perm_iface_pattern(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
log_debug("lldpctl", "set permanent iface pattern");
static int
cmd_iface_promisc(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
lldpctl_atom_t *config = lldpctl_get_configuration(conn);
if (config == NULL) {
static int
cmd_system_description(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
int platform = 0;
const char *what = arg;
static int
cmd_system_chassisid(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
const char *value;
value = cmdenv_get(env, "description");
static int
cmd_management(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "set management pattern");
static int
cmd_hostname(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
struct utsname un;
log_debug("lldpctl", "set system name");
static int
cmd_capability(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "set capabilities");
static int
cmd_update_descriptions(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
lldpctl_atom_t *config = lldpctl_get_configuration(conn);
if (config == NULL) {
static int
cmd_bondslave_srcmac_type(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
- char *value_str;
+ const char *value_str = 0;
int value = -1;
log_debug("lldpctl", "bond slave src mac");
static int
cmd_maxneighs(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "set maximum neighbors");
#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, const char *symbol)
{
if (lldpctl_atom_get_int(chassis, lldpctl_k_chassis_cap_available) & bit) {
tag_start(w, "capability", "Capability");
}
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,
+ const char *desc)
{
if (!((advertised & bithd) || (advertised & bitfd))) return;
tag_end(w);
}
-void
+static void
display_stat(struct writer *w, const char *tag, const char *descr,
long unsigned int cnt)
{
char *prefix;
};
-void
+static void
kv_start(struct writer *w, const char *tag, const char *descr)
{
struct kv_writer_private *p = w->priv;
p->prefix = newprefix;
}
-void
+static void
kv_data(struct writer *w, const char *data)
{
struct kv_writer_private *p = w->priv;
free(value);
}
-void
+static void
kv_end(struct writer *w)
{
struct kv_writer_private *p = w->priv;
*dot = '\0';
}
-void
+static void
kv_attr(struct writer *w, const char *tag, const char *descr, const char *value)
{
if (!strcmp(tag, "name") || !strcmp(tag, "type")) {
}
}
-void
+static void
kv_finish(struct writer *w)
{
struct kv_writer_private *p = w->priv;
return (ctlname && access(ctlname, R_OK | W_OK) == 0);
}
-static char *
+static const char *
prompt()
{
#define CESC "\033"
* 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,
+ const void *arg)
{
log_info("lldpctl", "quit lldpcli");
must_exit = 1;
*/
static int
cmd_update(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_info("lldpctl", "ask for global update");
return 1;
}
static int
-cmd_pause(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env, void *arg)
+cmd_pause(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
+ const void *arg)
{
(void)w;
(void)env;
}
static int
cmd_resume(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
(void)w;
(void)env;
* @param value String to transform to a tag.
* @return The tagged value or the string "none" if @c value is @c NULL
*/
-char *
+const char *
totag(const char *value)
{
int i;
*/
static int
cmd_show_neighbors(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "show neighbors data (%s) %s hidden neighbors",
cmdenv_get(env, "summary") ? "summary" :
*/
static int
cmd_show_interfaces(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "show interfaces data (%s) %s hidden interfaces",
cmdenv_get(env, "summary") ? "summary" :
*/
static int
cmd_show_chassis(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
log_debug("lldpctl", "show chassis data (%s)",
cmdenv_get(env, "summary") ? "summary" :
*/
static int
cmd_show_interface_stats(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
log_debug("lldpctl", "show stats data");
if (cmdenv_get(env, "ports"))
}
static int
-cmd_check_no_detailed_nor_summary(struct cmd_env *env, void *arg)
+cmd_check_no_detailed_nor_summary(struct cmd_env *env, const void *arg)
{
if (cmdenv_get(env, "detailed")) return 0;
if (cmdenv_get(env, "summary")) return 0;
*/
static int
cmd_show_configuration(struct lldpctl_conn_t *conn, struct writer *w,
- struct cmd_env *env, void *arg)
+ struct cmd_env *env, const void *arg)
{
log_debug("lldpctl", "show running configuration");
display_configuration(conn, w);
*/
static int
cmd_watch_neighbors(struct lldpctl_conn_t *conn, struct writer *w, struct cmd_env *env,
- void *arg)
+ const void *arg)
{
struct watcharg wa = { .env = env, .w = w, .nb = 0 };
const char *limit_str = cmdenv_get(env, "limit");
/**
* Register common subcommands for `watch` and `show neighbors` and `show chassis'
*/
-void
+static void
register_common_commands(struct cmd_node *root, int neighbor)
{
/* With more details */
/**
* Register sub command summary
*/
-void
+static void
register_summary_command(struct cmd_node *root)
{
commands_new(root, "summary", "With less details",
{
int iargc = 0;
char **iargv = NULL;
- char *ifs = " \n\t";
- char *quotes = "'\"";
- char *escapes = "\\";
+ const char ifs[] = " \n\t";
+ const char quotes[] = "'\"";
+ const char escapes[] = "\\";
char empty = 2; /* Empty character, will be removed from output
* but will mark a word. */
*/
#include <stddef.h>
+#include "writer.h"
/*
* Validate a single UTF-8 character starting at @s.
#define _WRITER_H
#include <stdio.h>
+#include <config.h>
struct writer {
void *priv;
xmlDocPtr doc;
};
-void
+static void
xml_new_writer(struct xml_writer_private *priv)
{
priv->xw = xmlNewTextWriterDoc(&(priv->doc), 0);
fatalx("lldpctl", "cannot start xml document");
}
-void
+static void
xml_start(struct writer *w, const char *tag, const char *descr)
{
struct xml_writer_private *p = w->priv;
p->depth++;
}
-void
+static void
xml_attr(struct writer *w, const char *tag, const char *descr, const char *value)
{
struct xml_writer_private *p = w->priv;
value ? value : "(none)");
}
-void
+static void
xml_data(struct writer *w, const char *data)
{
struct xml_writer_private *p = w->priv;
data ? data : "(none)");
}
-void
+static void
xml_end(struct writer *w)
{
struct xml_writer_private *p = w->priv;
}
}
-void
+static void
xml_finish(struct writer *w)
{
struct xml_writer_private *p = w->priv;
return 0; /* No best match yet. */
}
-void *
+static void *
header_index_best()
{
if (header_idx.entity == NULL) return NULL;
}
# if HAVE_NETSNMP_TDOMAIN_F_CREATE_FROM_TSTRING_NEW
-netsnmp_transport *
+static netsnmp_transport *
agent_priv_unix_create_tstring_new(const char *string, int local,
const char *default_target)
{
return agent_priv_unix_transport(string, strlen(string), local);
}
# else
-netsnmp_transport *
+static netsnmp_transport *
agent_priv_unix_create_tstring(const char *string, int local)
{
if (!string) return NULL;
*/
static char *
-dmi_get(char *file)
+dmi_get(const char *file)
{
int dmi, s;
char buffer[100] = {};
#ifdef ENABLE_LLDPMED
-char *
+static char *
dmi_get(int what, const char *descr)
{
char result[100] = {};
#include <unistd.h>
-int
+static int
ip_forwarding_enabled(int af)
{
int fd, rc = -1;
- char *fname;
+ const char *fname;
char status;
if (af == LLDPD_AF_IPV4)
lldpd_get_lsb_release()
{
static char release[1024];
- char *const command[] = { "lsb_release", "-s", "-d", NULL };
+ char cmd[][12] = { "lsb_release", "-s", "-d" };
+ char *const command[] = { cmd[0], cmd[1], cmd[2], NULL };
int pid, status, devnull, count;
int pipefd[2];
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") };
+ char ready[] = "READY=1";
+ struct iovec iov = { .iov_base = ready, .iov_len = sizeof ready - 1 };
struct msghdr hdr = { .msg_name = &su,
.msg_namelen =
offsetof(struct sockaddr_un, sun_path) + strlen(notifysocket),
struct protocol {
int mode; /* > 0 mode identifier (unique per protocol) */
int enabled; /* Is this protocol enabled? */
- char *name; /* Name of protocol */
+ const 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 */
void priv_ctl_cleanup(const char *ctlname);
char *priv_gethostname(void);
#ifdef HOST_OS_LINUX
-int priv_open(char *);
+int priv_open(const char *);
void asroot_open(void);
#endif
int priv_iface_init(int, char *);
* Some properties may be absent in the new interface that should be copied over
* from the old one.
*/
-void
+static void
netlink_merge(struct interfaces_device *old, struct interfaces_device *new)
{
if (new->alias == NULL) {
/* Proxy for open */
int
-priv_open(char *file)
+priv_open(const char *file)
{
int len, rc;
enum priv_cmd cmd = PRIV_OPEN;
#endif
-void
+#ifdef ENABLE_PRIVSEP
+static void
priv_drop(uid_t uid, gid_t gid)
{
gid_t gidset[1];
gidset[0] = gid;
log_debug("privsep", "dropping privileges");
-#ifdef HAVE_SETRESGID
+# ifdef HAVE_SETRESGID
if (setresgid(gid, gid, gid) == -1) fatal("privsep", "setresgid() failed");
-#else
+# else
if (setregid(gid, gid) == -1) fatal("privsep", "setregid() failed");
-#endif
+# endif
if (setgroups(1, gidset) == -1) fatal("privsep", "setgroups() failed");
-#ifdef HAVE_SETRESUID
+# ifdef HAVE_SETRESUID
if (setresuid(uid, uid, uid) == -1) fatal("privsep", "setresuid() failed");
-#else
+# else
if (setreuid(uid, uid) == -1) fatal("privsep", "setreuid() failed");
-#endif
+# endif
}
-void
+static void
priv_caps(uid_t uid, gid_t gid)
{
-#ifdef HAVE_LINUX_CAPABILITIES
+# ifdef HAVE_LINUX_CAPABILITIES
cap_t caps;
const char *caps_strings[2] = {
"cap_dac_override,cap_net_raw,cap_net_admin,cap_setuid,cap_setgid=pe",
if (cap_set_proc(caps) == -1)
fatal("privsep", "unable to drop extra privileges");
cap_free(caps);
-#else
+# else
log_info("privsep", "no libcap support, running monitor as root");
-#endif
+# endif
}
+#endif
void
#ifdef ENABLE_PRIVSEP
u_int8_t mcastaddr[] = CDP_MULTICAST_ADDR;
u_int8_t llcorg[] = LLC_ORG_CISCO;
# ifdef ENABLE_FDP
- char *capstr;
+ const char *capstr;
# endif
u_int16_t checksum;
int length, i;
/* 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 };
+ const char *deviceslot[] = { "eth", "veth", "XXX", "XXX", "XXX", "XXX", "XXX",
+ "XXX", "", NULL };
log_debug("edp", "send EDP frame on port %s", hardware->h_ifname);
struct sonmp_chassis {
int type;
- char *description;
+ const char *description;
};
#define SONMP_TOPOLOGY_CHANGED 1
$(AM_V_GEN)(for f in $(ATOM_FILES:%=$(srcdir)/%); do \
$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $$f; done | \
- $(SED) -n 's+^void init_atom_builder_\([^(]*\)().*, \([0-9]*\)).*+\2 \1+p' | \
+ $(SED) -n 's+^void init_atom_builder_\([^(]*\)(void).*, \([0-9]*\)).*+\2 \1+p' | \
sort | \
$(AWK) '{ atoms[$$2] = 1 } \
END { for (atom in atoms) { print "void init_atom_builder_"atom"(void);" } \
- print "void init_atom_builder() {"; \
+ print "void init_atom_builder(void);"; \
+ print "void init_atom_builder(void) {"; \
print " static int init = 0; if (init) return; init++;"; \
for (atom in atoms) { print " init_atom_builder_"atom"();" } \
print "}"; }' && \
for f in $(ATOM_FILES:%=$(srcdir)/%); do \
$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $$f; done | \
- $(SED) -n 's+^void init_atom_map_\([^(]*\)().*, \([0-9]*\)).*+\2 \1+p' | \
+ $(SED) -n 's+^void init_atom_map_\([^(]*\)(void).*, \([0-9]*\)).*+\2 \1+p' | \
sort -n | \
$(AWK) '{ atoms[$$2] = 1 } \
END { for (atom in atoms) { print "void init_atom_map_"atom"(void);" } \
- print "void init_atom_map() {"; \
+ print "void init_atom_map(void);"; \
+ print "void init_atom_map(void) {"; \
print " static int init = 0; if (init) return; init++;"; \
for (atom in atoms) { print " init_atom_map_"atom"();" } \
print "}"; }' ) \
void init_atom_map(void);
#define ATOM_MAP_REGISTER(NAME, PRIO) \
- void init_atom_map_##NAME() \
+ void init_atom_map_##NAME(void); \
+ void init_atom_map_##NAME(void) \
{ \
atom_map_register(&NAME, PRIO); \
}
void init_atom_builder(void);
#define ATOM_BUILDER_REGISTER(NAME, PRIO) \
- void init_atom_builder_##NAME() \
+ void init_atom_builder_##NAME(void); \
+ void init_atom_builder_##NAME(void) \
{ \
atom_builder_register(&NAME, PRIO); \
}
return NULL;
}
- set.ifname = hardware ? hardware->h_ifname : "";
+ char empty_str[] = "";
+ set.ifname = hardware ? hardware->h_ifname : empty_str;
if (asprintf(&canary, "%d%p%s", key, value, set.ifname) == -1) {
SET_ERROR(atom->conn, LLDPCTL_ERR_NOMEM);
*/
typedef const struct {
int value;
- char *string;
+ const char *string;
} lldpctl_map_t;
/**
#include <string.h>
#include <errno.h>
#include <time.h>
+#include "log.h"
/* By default, logging is done on stderr. */
static int use_syslog = 0;
.offset = 0, .offset2 = 0, .kind = ignore, .mi = NULL \
}
struct marshal_info {
- char *name; /* Name of structure */
- size_t size; /* Size of the structure */
+ const 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
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_HELPER_FUNCTIONS(type, ttype) \
+ ssize_t type##_serialize(ttype *source, void *buffer); \
+ 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); \
+ 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( \
#include <stdio.h>
#include "compat/compat.h"
+#include "log.h"
static void
version_display_array(FILE *destination, const char *prefix, const char *const *items)
}
END_TEST
-Suite *
+static Suite *
bitmap_suite(void)
{
Suite *s = suite_create("Bitmap handling");
#endif
-Suite *
+static Suite *
cdp_suite(void)
{
Suite *s = suite_create("CDP");
#endif
-Suite *
+static Suite *
edp_suite(void)
{
Suite *s = suite_create("EDP");
#endif
-Suite *
+static Suite *
fixedpoint_suite(void)
{
Suite *s = suite_create("Fixed point representation");
}
/* Disable leak detection sanitizer */
+int __lsan_is_turned_off(void);
int
-__lsan_is_turned_off()
+__lsan_is_turned_off(void)
{
return 1;
}
}
END_TEST
-Suite *
+static Suite *
lldp_suite(void)
{
Suite *s = suite_create("LLDP");
*/
/* Use this callback to avoid some logs */
-void donothing(int pri, const char *msg) {};
+static void donothing(int pri, const char *msg) {};
struct struct_simple {
int a1;
}
END_TEST
-Suite *
+static Suite *
marshal_suite(void)
{
Suite *s = suite_create("Marshalling");
}
END_TEST
-Suite *
+static Suite *
pattern_suite(void)
{
Suite *s = suite_create("Pattern matching");
.p_descr = "Gigabit Ethernet 1/7",
};
-void
+static void
snmp_config()
{
starttime = test_starttime;
}
/* Convert OID to a string. Static buffer. */
-char *
+static char *
snmp_oidrepr(oid *name, size_t namelen)
{
static char *buffer[4] = { NULL, NULL, NULL, NULL };
#endif
};
-char *
+static char *
tohex(char *str, size_t len)
{
static char *hex[] = { NULL, NULL };
return hex[1 - which];
}
-int
+static int
snmp_is_prefix_of(struct variable8 *vp, struct tree_node *n, char *repr)
{
if (n->namelen < vp->namelen) return 0;
return 1;
}
-void
+static void
snmp_merge(struct variable8 *v1, struct tree_node *n, struct variable *vp, oid *target,
size_t *targetlen)
{
n->namelen * sizeof(oid));
}
-void
+static void
snmp_compare(struct tree_node *n, u_char *result, size_t varlen, oid *target,
size_t targetlen, char *repr)
{
}
END_TEST
-Suite *
+static Suite *
snmp_suite(void)
{
Suite *s = suite_create("SNMP");
#endif
-Suite *
+static Suite *
sonmp_suite(void)
{
Suite *s = suite_create("SONMP");
};
void
-pcap_setup()
+pcap_setup(void)
{
static int serial = 0;
struct pcap_hdr hdr;
}
/* Disable leak detection sanitizer */
+int __lsan_is_turned_off(void);
int
-__lsan_is_turned_off()
+__lsan_is_turned_off(void)
{
return 1;
}
extern struct lldpd_chassis chassis;
int pcap_send(struct lldpd *, struct lldpd_hardware *, char *, size_t);
-void pcap_setup();
-void pcap_teardown();
+void pcap_setup(void);
+void pcap_teardown(void);
#endif
#define BUFSIZE 2000
-char *
+static char *
tohex(char *str, size_t len)
{
static char *hex = NULL;
exit(5); \
}
-int
+static int
decode(char *frame, int size, struct lldpd_hardware *hardware,
struct lldpd_chassis **nchassis, struct lldpd_port **nport)
{