]> git.ipfire.org Git - thirdparty/lldpd.git/blobdiff - src/lldpd-structs.h
Separate daemon and client code. Provide a client library.
[thirdparty/lldpd.git] / src / lldpd-structs.h
similarity index 53%
rename from src/lldpd.h
rename to src/lldpd-structs.h
index 431001b8f2e1afa0814103c7320dc655dfa44c09..a0dfc6443de1874fc2edd6ddfa83b8e0de4a824f 100644 (file)
@@ -1,3 +1,4 @@
+/* -*- mode: c; c-file-style: "openbsd" -*- */
 /*
  * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
  *
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#ifndef _LLDPD_H
-#define _LLDPD_H
+#ifndef _LLDPD_STRUCTS_H
+#define _LLDPD_STRUCTS_H
 
 #if HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
-#ifdef HAVE_VALGRIND_VALGRIND_H
-# include <valgrind/valgrind.h>
-#else
-# define RUNNING_ON_VALGRIND 0
-#endif
-
-#define _GNU_SOURCE 1
-#include <stdlib.h>
-#include <stddef.h>
-#include <string.h>
-#include <sys/queue.h>
-#ifdef HAVE_SYS_TYPES_H
-#  include <sys/types.h>
-#endif
+#include <sys/types.h>
+#include <sys/socket.h>
 #ifndef INCLUDE_LINUX_IF_H
 #  include <net/if.h>
 #else
 #  include <arpa/inet.h>
 #  include <linux/if.h>
 #endif
-#if HAVE_GETIFADDRS
-#  include <ifaddrs.h>
-#endif
 #include <net/ethernet.h>
 #include <netinet/in.h>
-#include <linux/ethtool.h>
-#include <sys/un.h>
+#include <sys/queue.h>
 
-#include "compat.h"
-#include "lldp.h"
-#if defined (ENABLE_CDP) || defined (ENABLE_FDP)
-#  include "cdp.h"
-#endif
-#ifdef ENABLE_SONMP
-#  include "sonmp.h"
-#endif
-#ifdef ENABLE_EDP
-#  include "edp.h"
-#endif
+#include "compat/compat.h"
 #include "marshal.h"
-
-/* We don't want to import event2/event.h. We only need those as
-   opaque structs. */
-struct event;
-struct event_base;
-
-#define SYSFS_CLASS_NET "/sys/class/net/"
-#define SYSFS_CLASS_DMI "/sys/class/dmi/id/"
-#define LLDPD_TTL              120
-#define LLDPD_TX_DELAY         30
-#define LLDPD_TX_MSGDELAY      1
-#define LLDPD_CTL_SOCKET       "/var/run/lldpd.socket"
-#define LLDPD_PID_FILE         "/var/run/lldpd.pid"
-
-#define UNIX_PATH_MAX  108
-
-#define USING_AGENTX_SUBAGENT_MODULE 1
+#include "lldp-const.h"
 
 #ifdef ENABLE_DOT1
-#define LLDPD_PPVID_CAP_SUPPORTED              (1 << 1)
-#define LLDPD_PPVID_CAP_ENABLED                        (1 << 2)
-
 struct lldpd_ppvid {
        TAILQ_ENTRY(lldpd_ppvid) p_entries;
        u_int8_t                p_cap_status;
@@ -115,6 +71,7 @@ MARSHAL_END;
 
 #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;
@@ -125,6 +82,7 @@ struct lldpd_med_policy {
 MARSHAL(lldpd_med_policy);
 
 struct lldpd_med_loc {
+       u_int8_t                 index; /* Not used. */
        u_int8_t                 format;
        char                    *data;
        int                      data_len;
@@ -178,14 +136,10 @@ inline 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;
        }
 }
 
@@ -280,8 +234,8 @@ struct lldpd_port {
 
 #ifdef ENABLE_LLDPMED
        u_int16_t                p_med_cap_enabled;
-       struct lldpd_med_policy  p_med_policy[LLDPMED_APPTYPE_LAST];
-       struct lldpd_med_loc     p_med_location[LLDPMED_LOCFORMAT_LAST];
+       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
 
@@ -403,222 +357,15 @@ MARSHAL_END;
 TAILQ_HEAD(lldpd_interface_list, lldpd_interface);
 MARSHAL_TQ(lldpd_interface_list, lldpd_interface);
 
-#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
-
-struct protocol {
-#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
-       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[ETH_ALEN];  /* Destination MAC address used by this protocol */
-};
-
-/* 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_HIDDEN(port) (port->p_hidden_in)
-
-struct lldpd {
-       int                      g_sock;
-       int                      g_delay;
-
-       struct event_base       *g_base;
-#ifdef USE_SNMP
-#endif
-
-       struct protocol         *g_protocols;
-       time_t                   g_lastsent;
-       int                      g_lastrid;
-       int                      g_smart;
-       int                      g_receiveonly;
-       struct event            *g_main_loop;
-#ifdef USE_SNMP
-       int                      g_snmp;
-       struct event            *g_snmp_timeout;
-       void                    *g_snmp_fds;
-       char                    *g_snmp_agentx;
-#endif /* USE_SNMP */
-
-       /* Unix socket handling */
-       int                      g_ctl;
-       struct event            *g_ctl_event;
-
-       char                    *g_mgmt_pattern;
-       char                    *g_cid_pattern;
-       char                    *g_interfaces;
-
-       char                    *g_descr_override;
-       char                    *g_platform_override;
-       char                    *g_lsb_release;
-       int                      g_advertise_version;
-#ifdef ENABLE_LLDPMED
-       int                      g_noinventory;
-#endif
-
-#define LOCAL_CHASSIS(cfg) ((struct lldpd_chassis *)(TAILQ_FIRST(&cfg->g_chassis)))
-       TAILQ_HEAD(, lldpd_chassis) g_chassis;
-       TAILQ_HEAD(, lldpd_hardware) g_hardware;
-};
-
-typedef void(*lldpd_ifhandlers)(struct lldpd *, struct ifaddrs *);
-
-enum hmsg_type {
-       NONE,
-       GET_INTERFACES,         /* Get list of interfaces */
-       GET_INTERFACE,          /* Get all information related to an interface */
-       SET_PORT,               /* Set port-related information (location, power, policy) */
-};
-
-/* lldpd.c */
-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 *);
+/* 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 *, int);
+void    lldpd_port_cleanup(struct lldpd_port *, int);
 #ifdef ENABLE_DOT1
 void    lldpd_ppvid_cleanup(struct lldpd_port *);
 void    lldpd_vlan_cleanup(struct lldpd_port *);
 void    lldpd_pi_cleanup(struct lldpd_port *);
 #endif
-void    lldpd_remote_cleanup(struct lldpd *, struct lldpd_hardware *, int);
-void    lldpd_port_cleanup(struct lldpd*, struct lldpd_port *, int);
-struct lldpd_mgmt *lldpd_alloc_mgmt(int family, void *addr, size_t addrsize, u_int32_t iface);
-void    lldpd_chassis_mgmt_cleanup(struct lldpd_chassis *);
-void    lldpd_chassis_cleanup(struct lldpd_chassis *, int);
-void    lldpd_recv(struct lldpd *, struct lldpd_hardware *, int);
-void    lldpd_loop(struct lldpd *);
-int     lldpd_main(int, char **);
-
-/* event.c */
-void    levent_loop(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 *);
-
-/* lldp.c */
-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);
-#endif
-#if defined (ENABLE_CDP) || defined (ENABLE_FDP)
-int     cdp_decode(PROTO_DECODE_SIG);
-#endif
-#ifdef ENABLE_FDP
-int     fdp_send(PROTO_SEND_SIG);
-#endif
-
-#ifdef ENABLE_SONMP
-/* sonmp.c */
-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);
-#endif
-
-/* ctl.c */
-int     ctl_create(char *);
-int     ctl_connect(char *);
-void    ctl_cleanup(char *);
-int     ctl_msg_send(int, enum hmsg_type, void *, size_t);
-int     ctl_msg_recv(int, enum hmsg_type *, void **);
-int     ctl_msg_send_recv(int, enum hmsg_type,
-    void *, struct marshal_info *, void **, struct marshal_info *);
-
-/* interfaces.c */
-void    lldpd_ifh_whitelist(struct lldpd *, struct ifaddrs *);
-void    lldpd_ifh_bond(struct lldpd *, struct ifaddrs *);
-void    lldpd_ifh_eth(struct lldpd *, struct ifaddrs *);
-#ifdef ENABLE_DOT1
-void    lldpd_ifh_vlan(struct lldpd *, struct ifaddrs *);
-#endif
-void    lldpd_ifh_mgmt(struct lldpd *, struct ifaddrs *);
-void    lldpd_ifh_chassis(struct lldpd *, struct ifaddrs *);
 
-/* dmi.c */
-#ifdef ENABLE_LLDPMED
-#if __i386__ || __amd64__
-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
 #endif
-
-/* log.c */
-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);
-void            agent_init(struct lldpd *, char *);
-
-/* agent_priv.c */
-void            agent_priv_register_domain(void);
-
-/* client.c */
-struct client_handle {
-       enum hmsg_type type;
-       int (*handle)(struct lldpd*, enum hmsg_type *,
-           void *, int, void **);
-};
-
-int     client_handle_client(struct lldpd *, int,
-    enum hmsg_type, void *, int);
-
-/* priv.c */
-void    priv_init(char*, int, uid_t, gid_t);
-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 *);
-int     priv_iface_multicast(const char *, u_int8_t *, int);
-int     priv_snmp_socket(struct sockaddr_un *);
-
-/* privsep_fdpass.c */
-int     receive_fd(int);
-void    send_fd(int, int);
-
-#endif /* _LLDPD_H */