2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-15 14:17:18 +00:00
Files
openvswitch/lib/lldp/lldpd.h
Jarno Rajahalme 74ff3298c8 userspace: Define and use struct eth_addr.
Define struct eth_addr and use it instead of a uint8_t array for all
ethernet addresses in OVS userspace.  The struct is always the right
size, and it can be assigned without an explicit memcpy, which makes
code more readable.

"struct eth_addr" is a good type name for this as many utility
functions are already named accordingly.

struct eth_addr can be accessed as bytes as well as ovs_be16's, which
makes the struct 16-bit aligned.  All use seems to be 16-bit aligned,
so some algorithms on the ethernet addresses can be made a bit more
efficient making use of this fact.

As the struct fits into a register (in 64-bit systems) we pass it by
value when possible.

This patch also changes the few uses of Linux specific ETH_ALEN to
OVS's own ETH_ADDR_LEN, and removes the OFP_ETH_ALEN, as it is no
longer needed.

This work stemmed from a desire to make all struct flow members
assignable for unrelated exploration purposes.  However, I think this
might be a nice code readability improvement by itself.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
2015-08-28 14:55:11 -07:00

100 lines
3.4 KiB
C

/* -*- mode: c; c-file-style: "openbsd" -*- */
/*
* Copyright (c) 2015 Nicira, Inc.
* Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
*
* 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 _LLDPD_H
#define _LLDPD_H
#ifndef _WIN32
#include <netinet/in.h>
#endif
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include "dp-packet.h"
#include "list.h"
#include "lldpd-structs.h"
#include "lldp-tlv.h"
#include "packets.h"
#include "openvswitch/vlog.h"
#define ETHERTYPE_LLDP 0x88cc
#define LLDPD_TX_INTERVAL 5
#define LLDPD_TX_HOLD 4
#define LLDPD_TTL (LLDPD_TX_INTERVAL * LLDPD_TX_HOLD)
#define PROTO_SEND_SIG struct lldpd *, struct lldpd_hardware *,struct dp_packet *
#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 {
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
*/
struct eth_addr mac; /* Destination MAC address used by this protocol */
};
#define SMART_HIDDEN(port) (port->p_hidden_in)
struct lldpd {
struct lldpd_config g_config;
struct protocol *g_protocols;
int g_lastrid;
struct ovs_list g_chassis; /* Contains "struct lldp_chassis". */
struct ovs_list g_hardware; /* Contains "struct lldpd_hardware". */
};
static inline struct lldpd_hardware *
lldpd_first_hardware(struct lldpd *lldpd)
{
return CONTAINER_OF(list_front(&lldpd->g_hardware),
struct lldpd_hardware, h_entries);
}
/* lldpd.c */
struct lldpd_hardware *lldpd_get_hardware(struct lldpd *,
char *, int, struct lldpd_ops *);
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 *, char *, size_t);
uint32_t lldpd_send(struct lldpd_hardware *, struct dp_packet *);
void lldpd_loop(struct lldpd *);
int lldpd_main(int, char **);
void lldpd_update_localports(struct lldpd *);
void lldpd_cleanup(struct lldpd *);
void lldpd_assign_cfg_to_protocols(struct lldpd *);
/* lldp.c */
int lldp_send(PROTO_SEND_SIG);
int lldp_decode(PROTO_DECODE_SIG);
#endif /* _LLDPD_H */