00224679cc1337f0285726c94f5965b0d9734d6d
[cascardo/ovs.git] / lib / lldp / lldpd.h
1 /* -*- mode: c; c-file-style: "openbsd" -*- */
2 /*
3  * Copyright (c) 2015 Nicira, Inc.
4  * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18
19 #ifndef _LLDPD_H
20 #define _LLDPD_H
21
22 #ifndef _WIN32
23 #include <netinet/if_ether.h>
24 #include <netinet/in.h>
25 #endif
26 #include <stdlib.h>
27 #include <stddef.h>
28 #include <string.h>
29 #include <sys/types.h>
30 #include "dp-packet.h"
31 #include "list.h"
32 #include "lldpd-structs.h"
33 #include "lldp-tlv.h"
34 #include "packets.h"
35 #include "openvswitch/vlog.h"
36
37 #define ETHERTYPE_LLDP 0x88cc
38
39 #define LLDPD_TX_INTERVAL      5
40 #define LLDPD_TX_HOLD          4
41 #define LLDPD_TTL              (LLDPD_TX_INTERVAL * LLDPD_TX_HOLD)
42
43 #define PROTO_SEND_SIG struct lldpd *, struct lldpd_hardware *,struct dp_packet *
44 #define PROTO_DECODE_SIG struct lldpd *, char *, int, struct lldpd_hardware *,\
45     struct lldpd_chassis **, struct lldpd_port **
46 #define PROTO_GUESS_SIG char *, int
47
48 struct protocol {
49     int  mode;       /* > 0 mode identifier (unique per protocol) */
50     int  enabled;    /* Is this protocol enabled? */
51     char *name;      /* Name of protocol */
52     char arg;        /* Argument to enable this protocol */
53     int(*send)(PROTO_SEND_SIG);    /* How to send a frame */
54     int(*decode)(PROTO_DECODE_SIG); /* How to decode a frame */
55     int(*guess)(PROTO_GUESS_SIG);   /* Can be NULL, use MAC address in this
56                                      * case
57                                      */
58     u_int8_t mac[ETH_ADDR_LEN];  /* Destination MAC address used by this
59                                   * protocol
60                                   */
61 };
62
63 #define SMART_HIDDEN(port) (port->p_hidden_in)
64
65 struct lldpd {
66     struct lldpd_config g_config;
67     struct protocol     *g_protocols;
68     int                 g_lastrid;
69
70     struct ovs_list     g_chassis; /* Contains "struct lldp_chassis". */
71     struct ovs_list     g_hardware; /* Contains "struct lldpd_hardware". */
72 };
73
74 static inline struct lldpd_hardware *
75 lldpd_first_hardware(struct lldpd *lldpd)
76 {
77     return CONTAINER_OF(list_front(&lldpd->g_hardware),
78                         struct lldpd_hardware, h_entries);
79 }
80
81 /* lldpd.c */
82 struct lldpd_hardware *lldpd_get_hardware(struct lldpd *,
83     char *, int, struct lldpd_ops *);
84 struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, char *, int);
85 void lldpd_hardware_cleanup(struct lldpd*, struct lldpd_hardware *);
86 struct lldpd_mgmt *lldpd_alloc_mgmt(int family, void *addr, size_t addrsize,
87     u_int32_t iface);
88 void lldpd_recv(struct lldpd *, struct lldpd_hardware *, char *, size_t);
89 uint32_t lldpd_send(struct lldpd_hardware *, struct dp_packet *);
90 void lldpd_loop(struct lldpd *);
91
92 int lldpd_main(int, char **);
93 void lldpd_update_localports(struct lldpd *);
94 void lldpd_cleanup(struct lldpd *);
95
96 void lldpd_assign_cfg_to_protocols(struct lldpd *);
97
98 /* lldp.c */
99 int lldp_send(PROTO_SEND_SIG);
100 int lldp_decode(PROTO_DECODE_SIG);
101
102 #endif /* _LLDPD_H */