#define _LLDPD_H
#if HAVE_CONFIG_H
- #include <config.h>
+# include <config.h>
#endif
#define _GNU_SOURCE 1
#include <stdlib.h>
#include <string.h>
#include <sys/queue.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
#ifndef INCLUDE_LINUX_IF_H
-#include <net/if.h>
+# include <net/if.h>
#else
-#include <arpa/inet.h>
-#include <linux/if.h>
+# include <arpa/inet.h>
+# include <linux/if.h>
+#endif
+#if HAVE_GETIFADDRS
+# include <ifaddrs.h>
#endif
-#include <ifaddrs.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <linux/ethtool.h>
+#include <sys/un.h>
#include "compat.h"
#include "lldp.h"
#if defined (ENABLE_CDP) || defined (ENABLE_FDP)
-#include "cdp.h"
+# include "cdp.h"
#endif
#ifdef ENABLE_SONMP
-#include "sonmp.h"
+# include "sonmp.h"
#endif
#ifdef ENABLE_EDP
-#include "edp.h"
+# include "edp.h"
#endif
#define SYSFS_CLASS_NET "/sys/class/net/"
struct lldpd_frame {
int size;
- unsigned char frame[];
+ unsigned char frame[1];
};
struct lldpd_hardware;
int(*cleanup)(struct lldpd *, struct lldpd_hardware *); /* Cleanup function. */
};
+/* An interface is uniquely identified by h_ifindex, h_ifname and h_ops. This
+ * means if an interface becomes enslaved, it will be considered as a new
+ * 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;
};
#define STRUCT_LLDPD_INTERFACE "(Ls)"
-struct lldpd_client {
- TAILQ_ENTRY(lldpd_client) next;
- int fd;
-};
-
#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_GUESS_SIG char *, int
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[ETH_ALEN]; /* Destination MAC address used by this protocol */
- struct sock_filter *filter; /* BPF filter */
- size_t filterlen; /* Size of BPF filter */
+};
+
+#define CALLBACK_SIG struct lldpd*, struct lldpd_callback*
+struct lldpd_callback {
+ TAILQ_ENTRY(lldpd_callback) next;
+ int fd; /* FD that will trigger this callback */
+ void(*function)(CALLBACK_SIG); /* Function called */
+ void *data; /* Optional data for this callback*/
};
struct lldpd {
#ifdef ENABLE_LLDPMED
int g_noinventory;
#endif
+ int g_advertise_version;
time_t g_lastsent;
int g_lastrid;
/* Unix socket handling */
int g_ctl;
- TAILQ_HEAD(, lldpd_client) g_clients;
+
+ TAILQ_HEAD(, lldpd_callback) g_callbacks;
char *g_mgmt_pattern;
#define MAX_HMSGSIZE 8192
/* lldpd.c */
-struct lldpd_hardware *lldpd_get_hardware(struct lldpd *, char *, struct lldpd_ops *);
+struct lldpd_hardware *lldpd_get_hardware(struct lldpd *,
+ char *, int, struct lldpd_ops *);
struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, char *);
void lldpd_hardware_cleanup(struct lldpd*, struct lldpd_hardware *);
#ifdef ENABLE_DOT1
void lldpd_remote_cleanup(struct lldpd *, struct lldpd_hardware *, int);
void lldpd_port_cleanup(struct lldpd_port *, int);
void lldpd_chassis_cleanup(struct lldpd_chassis *, int);
+int lldpd_callback_add(struct lldpd *, int, void(*fn)(CALLBACK_SIG), void *);
+void lldpd_callback_del(struct lldpd *, int, void(*fn)(CALLBACK_SIG));
+int lldpd_main(int, char **);
/* lldp.c */
int lldp_send(PROTO_SEND_SIG);
int ctl_create(char *);
int ctl_connect(char *);
void ctl_cleanup(char *);
-int ctl_accept(struct lldpd *, int);
-int ctl_close(struct lldpd *, int);
+void ctl_accept(struct lldpd *, struct lldpd_callback *);
void ctl_msg_init(struct hmsg *, enum hmsg_type);
int ctl_msg_send(int, struct hmsg *);
int ctl_msg_recv(int, struct hmsg *);
/* dmi.c */
#ifdef ENABLE_LLDPMED
-char *dmi_hw();
-char *dmi_fw();
-char *dmi_sn();
-char *dmi_manuf();
-char *dmi_model();
-char *dmi_asset();
+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
/* log.c */
-void log_init(int);
-void log_warn(const char *, ...);
-#define LLOG_WARN(x,...) log_warn("%s: " x, __FUNCTION__, ##__VA_ARGS__)
-void log_warnx(const char *, ...);
-#define LLOG_WARNX(x,...) log_warnx("%s: " x, __FUNCTION__, ##__VA_ARGS__)
-void log_info(const char *, ...);
-#define LLOG_INFO(x,...) log_info("%s: " x, __FUNCTION__, ##__VA_ARGS__)
-void log_debug(const char *, ...);
-#define LLOG_DEBUG(x,...) log_debug("%s: " x, __FUNCTION__, ##__VA_ARGS__)
+void log_init(int, const char *);
+void log_warn(const char *, ...) __attribute__ ((format (printf, 1, 2)));
+#define LLOG_WARN(x,...) log_warn("%s: " x, __FUNCTION__ , ## __VA_ARGS__)
+void log_warnx(const char *, ...) __attribute__ ((format (printf, 1, 2)));
+#define LLOG_WARNX(x,...) log_warnx("%s: " x, __FUNCTION__ , ## __VA_ARGS__)
+void log_info(const char *, ...) __attribute__ ((format (printf, 1, 2)));
+#define LLOG_INFO(x,...) log_info("%s: " x, __FUNCTION__ , ## __VA_ARGS__)
+void log_debug(const char *, ...) __attribute__ ((format (printf, 1, 2)));
+#define LLOG_DEBUG(x,...) log_debug("%s: " x, __FUNCTION__ , ## __VA_ARGS__)
void fatal(const char *);
void fatalx(const char *);
/* agent.c */
-void agent_shutdown();
-void agent_init(struct lldpd *, int);
+void agent_shutdown(void);
+void agent_init(struct lldpd *, char *, int);
/* agent_priv.c */
-void agent_priv_register_domain();
-
-/* strlcpy.c */
-size_t strlcpy(char *, const char *, size_t);
+void agent_priv_register_domain(void);
/* client.c */
struct client_handle {
void (*handle)(struct lldpd*, struct hmsg*, struct hmsg*);
};
-void client_handle_client(struct lldpd *, struct lldpd_client *,
- char *, int);
+void client_handle_client(struct lldpd *, struct lldpd_callback *,
+ char *, int);
void client_handle_none(struct lldpd *, struct hmsg *,
struct hmsg *);
void client_handle_get_interfaces(struct lldpd *, struct hmsg *,
/* priv.c */
void priv_init(char*);
-int priv_ctl_create();
-void priv_ctl_cleanup();
-char *priv_gethostbyname();
+int priv_ctl_create(void);
+void priv_ctl_cleanup(void);
+char *priv_gethostbyname(void);
int priv_open(char*);
int priv_ethtool(char*, struct ethtool_cmd*);
int priv_iface_init(const char *);