lldpd now also runs on FreeBSD. Tested on FreeBSD 8.3.
AC_MSG_CHECKING([if host OS is supported])
lldp_DEFINE_OS(linux*, Linux, LINUX)
- lldp_DEFINE_OS(freebsd*, FreeBSD, FREEBSD)
- lldp_DEFINE_OS(kfreebsd*, kFreeBSD, FREEBSD)
+ lldp_DEFINE_OS(freebsd*|kfreebsd*, FreeBSD, FREEBSD)
if test x$os = x; then
AC_MSG_RESULT(no)
#include <sys/socket.h>
#include <sys/un.h>
#include <arpa/inet.h>
+#include <string.h>
#include "../log.h"
#include "client.h"
#include <unistd.h>
#include <time.h>
#include <errno.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <string.h>
#include "ctl.h"
#include "marshal.h"
length = s;
pos = (u_int8_t*)frame;
- if (length < 2*ETH_ALEN + sizeof(u_int16_t) /* Ethernet */ +
+ if (length < 2*ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ +
8 /* LLC */ + 4 /* CDP header */) {
log_warn("cdp", "too short CDP/FDP frame received on %s", hardware->h_ifname);
goto malformed;
}
#endif
}
- PEEK_DISCARD(ETH_ALEN); /* Don't care of source address */
+ PEEK_DISCARD(ETHER_ADDR_LEN); /* Don't care of source address */
len_eth = PEEK_UINT16;
if (len_eth > length) {
log_warnx("cdp", "incorrect 802.3 frame size reported on %s",
cdp_guess(char *pos, int length, int version)
{
const u_int8_t mcastaddr[] = CDP_MULTICAST_ADDR;
- if (length < 2*ETH_ALEN + sizeof(u_int16_t) /* Ethernet */ +
+ if (length < 2*ETHER_ADDR_LEN + sizeof(u_int16_t) /* Ethernet */ +
8 /* LLC */ + 4 /* CDP header */)
return 0;
- if (PEEK_CMP(mcastaddr, ETH_ALEN) != 0)
+ if (PEEK_CMP(mcastaddr, ETHER_ADDR_LEN) != 0)
return 0;
- PEEK_DISCARD(ETH_ALEN); PEEK_DISCARD_UINT16; /* Ethernet */
+ PEEK_DISCARD(ETHER_ADDR_LEN); PEEK_DISCARD_UINT16; /* Ethernet */
PEEK_DISCARD(8); /* LLC */
return (PEEK_UINT8 == version);
}
goto toobig;
/* EDP header */
- if ((chassis->c_id_len != ETH_ALEN) ||
+ if ((chassis->c_id_len != ETHER_ADDR_LEN) ||
(chassis->c_id_subtype != LLDP_CHASSISID_SUBTYPE_LLADDR)) {
log_warnx("edp", "local chassis does not use MAC address as chassis ID!?");
free(packet);
POKE_UINT32(0) && /* Len + Checksum */
POKE_UINT16(seq) &&
POKE_UINT16(0) &&
- POKE_BYTES(chassis->c_id, ETH_ALEN)))
+ POKE_BYTES(chassis->c_id, ETHER_ADDR_LEN)))
goto toobig;
seq++;
length = s;
pos = (u_int8_t*)frame;
- if (length < 2*ETH_ALEN + sizeof(u_int16_t) + 8 /* LLC */ +
- 10 + ETH_ALEN /* EDP header */) {
+ if (length < 2*ETHER_ADDR_LEN + sizeof(u_int16_t) + 8 /* LLC */ +
+ 10 + ETHER_ADDR_LEN /* EDP header */) {
log_warnx("edp", "too short EDP frame received on %s", hardware->h_ifname);
goto malformed;
}
hardware->h_ifname);
goto malformed;
}
- PEEK_DISCARD(ETH_ALEN); PEEK_DISCARD_UINT16;
+ PEEK_DISCARD(ETHER_ADDR_LEN); PEEK_DISCARD_UINT16;
PEEK_DISCARD(6); /* LLC: DSAP + SSAP + control + org */
if (PEEK_UINT16 != LLC_PID_EDP) {
log_debug("edp", "incorrect LLC protocol ID received on %s",
}
chassis->c_ttl = LLDPD_TTL;
chassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
- chassis->c_id_len = ETH_ALEN;
- if ((chassis->c_id = (char *)malloc(ETH_ALEN)) == NULL) {
+ chassis->c_id_len = ETHER_ADDR_LEN;
+ if ((chassis->c_id = (char *)malloc(ETHER_ADDR_LEN)) == NULL) {
log_warn("edp", "unable to allocate memory for chassis ID");
goto malformed;
}
- PEEK_BYTES(chassis->c_id, ETH_ALEN);
+ PEEK_BYTES(chassis->c_id, ETHER_ADDR_LEN);
/* Let's check checksum */
if (frame_checksum(pos_edp, edp_len, 0) != 0) {
iface->flags = ifaddr->ifa_flags;
/* MAC address */
- iface->address = malloc(ETH_ALEN);
+ iface->address = malloc(ETHER_ADDR_LEN);
if (iface->address)
- memcpy(iface->address, LLADDR(saddrdl), ETH_ALEN);
+ memcpy(iface->address, LLADDR(saddrdl), ETHER_ADDR_LEN);
/* Grab description */
iface->alias = malloc(IFDESCRSIZE);
FILE *netbond;
const char const *slaveif = "Slave Interface: ";
const char const *hwaddr = "Permanent HW addr: ";
- u_int8_t mac[ETH_ALEN];
+ u_int8_t mac[ETHER_ADDR_LEN];
char path[SYSFS_PATH_MAX];
char line[100];
"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
&mac[0], &mac[1], &mac[2],
&mac[3], &mac[4], &mac[5]) !=
- ETH_ALEN) {
+ ETHER_ADDR_LEN) {
log_warn("interfaces", "unable to parse %s",
line + strlen(hwaddr));
fclose(netbond);
return;
}
memcpy(iface->address, mac,
- ETH_ALEN);
+ ETHER_ADDR_LEN);
fclose(netbond);
return;
}
* source MAC address to 0. */
log_debug("interfaces", "send PDU to bonded device %s",
hardware->h_ifname);
- if (size < 2 * ETH_ALEN) {
+ if (size < 2 * ETHER_ADDR_LEN) {
log_warnx("interfaces",
"packet to send on %s is too small!",
hardware->h_ifname);
return 0;
}
- memset(buffer + ETH_ALEN, 0, ETH_ALEN);
+ memset(buffer + ETHER_ADDR_LEN, 0, ETHER_ADDR_LEN);
return write(hardware->h_sendfd,
buffer, size);
}
iface->flags = 0;
/* Get local address */
- memcpy(&hardware->h_lladdr, iface->address, ETH_ALEN);
+ memcpy(&hardware->h_lladdr, iface->address, ETHER_ADDR_LEN);
/* Fill information about port */
interfaces_helper_port_name_desc(hardware, iface);
interface. */
/* Get local address */
- memcpy(&hardware->h_lladdr, iface->address, ETH_ALEN);
+ memcpy(&hardware->h_lladdr, iface->address, ETHER_ADDR_LEN);
/* Fill information about port */
interfaces_helper_port_name_desc(hardware, iface);
length = s;
pos = (u_int8_t*)frame;
- if (length < 2*ETH_ALEN + sizeof(u_int16_t)) {
+ if (length < 2*ETHER_ADDR_LEN + sizeof(u_int16_t)) {
log_warnx("lldp", "too short frame received on %s", hardware->h_ifname);
goto malformed;
}
- if (PEEK_CMP(lldpaddr, ETH_ALEN) != 0) {
+ if (PEEK_CMP(lldpaddr, ETHER_ADDR_LEN) != 0) {
log_info("lldp", "frame not targeted at LLDP multicast address received on %s",
hardware->h_ifname);
goto malformed;
}
- PEEK_DISCARD(ETH_ALEN); /* Skip source address */
+ PEEK_DISCARD(ETHER_ADDR_LEN); /* Skip source address */
if (PEEK_UINT16 != ETHERTYPE_LLDP) {
log_info("lldp", "non LLDP frame received on %s",
hardware->h_ifname);
#include <sys/time.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
+#include <net/ethernet.h>
#include <pwd.h>
#include <grp.h>
#ifdef HOST_OS_FREEBSD
lldpd_guess_type(struct lldpd *cfg, char *frame, int s)
{
int i;
- if (s < ETH_ALEN)
+ if (s < ETHER_ADDR_LEN)
return -1;
for (i=0; cfg->g_protocols[i].mode != 0; i++) {
if (!cfg->g_protocols[i].enabled)
continue;
if (cfg->g_protocols[i].guess == NULL) {
- if (memcmp(frame, cfg->g_protocols[i].mac, ETH_ALEN) == 0) {
+ if (memcmp(frame, cfg->g_protocols[i].mac, ETHER_ADDR_LEN) == 0) {
log_debug("decode", "guessed protocol is %s (from MAC address)",
cfg->g_protocols[i].name);
return cfg->g_protocols[i].mode;
log_debug("decode", "decode a received frame on %s",
hardware->h_ifname);
- if (s < sizeof(struct ethhdr) + 4)
+ if (s < sizeof(struct ether_header) + 4)
/* Too short, just discard it */
return;
/* Decapsulate VLAN frames */
- if (((struct ethhdr*)frame)->h_proto == htons(ETHERTYPE_VLAN)) {
+ if (((struct ether_header*)frame)->ether_type == htons(ETHERTYPE_VLAN)) {
/* VLAN decapsulation means to shift 4 bytes left the frame from
- * offset 2*ETH_ALEN */
- memmove(frame + 2*ETH_ALEN, frame + 2*ETH_ALEN + 4, s - 2*ETH_ALEN);
+ * offset 2*ETHER_ADDR_LEN */
+ memmove(frame + 2*ETHER_ADDR_LEN, frame + 2*ETHER_ADDR_LEN + 4, s - 2*ETHER_ADDR_LEN);
s -= 4;
}
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 */
+ u_int8_t mac[ETHER_ADDR_LEN]; /* Destination MAC address used by this protocol */
};
#define SMART_HIDDEN(port) (port->p_hidden_in)
#include <stdio.h>
#include <unistd.h>
+#include <signal.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/stat.h>
cmd = PRIV_IFACE_MULTICAST;
must_write(remote, &cmd, sizeof(int));
must_write(remote, name, IFNAMSIZ);
- must_write(remote, mac, ETH_ALEN);
+ must_write(remote, mac, ETHER_ADDR_LEN);
must_write(remote, &add, sizeof(int));
must_read(remote, &rc, sizeof(int));
return rc;
struct ifreq ifr = {};
must_read(remote, ifr.ifr_name, IFNAMSIZ);
#if defined HOST_OS_LINUX
- must_read(remote, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+ must_read(remote, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
#elif defined HOST_OS_FREEBSD
/* Black magic from mtest.c */
struct sockaddr_dl *dlp = (struct sockaddr_dl *)&ifr.ifr_addr;
dlp->sdl_family = AF_LINK;
dlp->sdl_index = 0;
dlp->sdl_nlen = 0;
- dlp->sdl_alen = ETH_ALEN;
+ dlp->sdl_alen = ETHER_ADDR_LEN;
dlp->sdl_slen = 0;
- must_read(remote, LLADDR(&dlp), ETH_ALEN);
+ must_read(remote, LLADDR(dlp), ETHER_ADDR_LEN);
#else
#error Unsupported OS
#endif
POKE_RESTORE(pos_pid); /* Modify LLC PID */
(void)POKE_UINT16(LLC_PID_SONMP_FLATNET);
POKE_RESTORE(packet); /* Go to the beginning */
- PEEK_DISCARD(ETH_ALEN - 1); /* Modify the last byte of the MAC address */
+ PEEK_DISCARD(ETHER_ADDR_LEN - 1); /* Modify the last byte of the MAC address */
(void)POKE_UINT8(1);
if (hardware->h_ops->send(global, hardware,
* them. */
goto malformed;
/* We skip to LLC PID */
- PEEK_DISCARD(ETH_ALEN); PEEK_DISCARD_UINT16;
+ PEEK_DISCARD(ETHER_ADDR_LEN); PEEK_DISCARD_UINT16;
PEEK_DISCARD(6);
if (PEEK_UINT16 != LLC_PID_SONMP_HELLO) {
log_debug("sonmp", "incorrect LLC protocol ID received for SONMP on %s",
#define LLC_ORG_NORTEL { 0x00, 0x00, 0x81 }
#define LLC_PID_SONMP_HELLO 0x01a2
#define LLC_PID_SONMP_FLATNET 0x01a1
-#define SONMP_SIZE (2*ETH_ALEN + sizeof(u_int16_t) + 8)
+#define SONMP_SIZE (2*ETHER_ADDR_LEN + sizeof(u_int16_t) + 8)
struct sonmp_chassis {
int type;
#include <unistd.h>
#include <errno.h>
+#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
hardware.h_lport.p_descr = "FastEthernet 1/5";
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
chassis.c_id = macaddress;
- chassis.c_id_len = ETH_ALEN;
+ chassis.c_id_len = ETHER_ADDR_LEN;
chassis.c_name = "First chassis";
chassis.c_descr = "Chassis description";
chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER;
/* Populate port and chassis */
hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR;
hardware.h_lport.p_id = macaddress;
- hardware.h_lport.p_id_len = ETH_ALEN;
+ hardware.h_lport.p_id_len = ETHER_ADDR_LEN;
hardware.h_lport.p_descr = "Gigabit Ethernet 5/8";
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
chassis.c_id = macaddress;
- chassis.c_id_len = ETH_ALEN;
+ chassis.c_id_len = ETHER_ADDR_LEN;
chassis.c_name = "Second chassis";
chassis.c_descr = "Chassis description";
chassis.c_cap_available = chassis.c_cap_enabled =
hardware.h_ifindex = 4;
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
chassis.c_id = macaddress;
- chassis.c_id_len = ETH_ALEN;
+ chassis.c_id_len = ETHER_ADDR_LEN;
chassis.c_name = "First chassis";
/* Build packet */
n = edp_send(NULL, &hardware);
hardware.h_ifindex = 4;
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
chassis.c_id = macaddress;
- chassis.c_id_len = ETH_ALEN;
+ chassis.c_id_len = ETHER_ADDR_LEN;
chassis.c_name = "First chassis";
vlan1.v_name = "First VLAN"; vlan1.v_vid = 157;
vlan2.v_name = "Second VLAN"; vlan2.v_vid = 1247;
}
ck_assert_int_eq(nchassis->c_id_subtype,
LLDP_CHASSISID_SUBTYPE_LLADDR);
- ck_assert_int_eq(nchassis->c_id_len, ETH_ALEN);
- fail_unless(memcmp(nchassis->c_id, mac1, ETH_ALEN) == 0);
+ ck_assert_int_eq(nchassis->c_id_len, ETHER_ADDR_LEN);
+ fail_unless(memcmp(nchassis->c_id, mac1, ETHER_ADDR_LEN) == 0);
ck_assert_int_eq(nport->p_id_subtype,
LLDP_PORTID_SUBTYPE_IFNAME);
ck_assert_int_eq(nport->p_id_len, strlen("1/1"));
hardware.h_lport.p_mfs = 1516;
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
chassis.c_id = macaddress;
- chassis.c_id_len = ETH_ALEN;
+ chassis.c_id_len = ETHER_ADDR_LEN;
chassis.c_name = "First chassis";
chassis.c_descr = "Chassis description";
chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER;
/* Populate port and chassis */
hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR;
hardware.h_lport.p_id = macaddress;
- hardware.h_lport.p_id_len = ETH_ALEN;
+ hardware.h_lport.p_id_len = ETHER_ADDR_LEN;
hardware.h_lport.p_descr = "Fake port description";
hardware.h_lport.p_mfs = 1516;
hardware.h_lport.p_pvid = 1500;
/* Populate port and chassis */
hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR;
hardware.h_lport.p_id = macaddress;
- hardware.h_lport.p_id_len = ETH_ALEN;
+ hardware.h_lport.p_id_len = ETHER_ADDR_LEN;
hardware.h_lport.p_descr = "Fake port description";
hardware.h_lport.p_mfs = 1516;
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL;
hardware.h_lport.p_macphy.mau_type = LLDP_DOT3_MAU_100BASETXFD;
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
chassis.c_id = macaddress;
- chassis.c_id_len = ETH_ALEN;
+ chassis.c_id_len = ETHER_ADDR_LEN;
chassis.c_name = "Fourth chassis";
chassis.c_descr = "Long chassis description";
chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER | LLDP_CAP_WLAN;
}
ck_assert_int_eq(nchassis->c_id_subtype,
LLDP_CHASSISID_SUBTYPE_LLADDR);
- ck_assert_int_eq(nchassis->c_id_len, ETH_ALEN);
- fail_unless(memcmp(mac1, nchassis->c_id, ETH_ALEN) == 0);
+ ck_assert_int_eq(nchassis->c_id_len, ETHER_ADDR_LEN);
+ fail_unless(memcmp(mac1, nchassis->c_id, ETHER_ADDR_LEN) == 0);
ck_assert_int_eq(nport->p_id_subtype,
LLDP_PORTID_SUBTYPE_LLADDR);
- ck_assert_int_eq(nport->p_id_len, ETH_ALEN);
- fail_unless(memcmp(mac2, nport->p_id, ETH_ALEN) == 0);
+ ck_assert_int_eq(nport->p_id_len, ETHER_ADDR_LEN);
+ fail_unless(memcmp(mac2, nport->p_id, ETHER_ADDR_LEN) == 0);
ck_assert_int_eq(nchassis->c_ttl, 120);
ck_assert_str_eq(nchassis->c_name, "Not received");
ck_assert_str_eq(nchassis->c_descr, "Not received");
}
ck_assert_int_eq(nchassis->c_id_subtype,
LLDP_CHASSISID_SUBTYPE_LLADDR);
- ck_assert_int_eq(nchassis->c_id_len, ETH_ALEN);
- fail_unless(memcmp(mac1, nchassis->c_id, ETH_ALEN) == 0);
+ ck_assert_int_eq(nchassis->c_id_len, ETHER_ADDR_LEN);
+ fail_unless(memcmp(mac1, nchassis->c_id, ETHER_ADDR_LEN) == 0);
ck_assert_int_eq(nport->p_id_subtype,
LLDP_PORTID_SUBTYPE_LLADDR);
- ck_assert_int_eq(nport->p_id_len, ETH_ALEN);
- fail_unless(memcmp(mac1, nport->p_id, ETH_ALEN) == 0);
+ ck_assert_int_eq(nport->p_id_len, ETHER_ADDR_LEN);
+ fail_unless(memcmp(mac1, nport->p_id, ETHER_ADDR_LEN) == 0);
ck_assert_int_eq(nchassis->c_ttl, 120);
ck_assert_str_eq(nchassis->c_name, "naruto.XXXXXXXXXXXXXXXXXXX");
ck_assert_str_eq(nchassis->c_descr,
hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id);
chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
chassis.c_id = macaddress;
- chassis.c_id_len = ETH_ALEN;
+ chassis.c_id_len = ETHER_ADDR_LEN;
TAILQ_INIT(&chassis.c_mgmt);
addr = inet_addr("172.17.142.37");
mgmt = lldpd_alloc_mgmt(LLDPD_AF_IPV4,
int dump = -1;
char *filename = NULL;
struct pkts_t pkts;
-char macaddress[ETH_ALEN] = { 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad };
+char macaddress[ETHER_ADDR_LEN] = { 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad };
struct lldpd_hardware hardware;
struct lldpd_chassis chassis;
hardware.h_mtu = 1500;
hardware.h_ifindex = 4;
strcpy(hardware.h_ifname, "test");
- memcpy(hardware.h_lladdr, macaddress, ETH_ALEN);
+ memcpy(hardware.h_lladdr, macaddress, ETHER_ADDR_LEN);
hardware.h_ops = &pcap_ops;
/* Prepare chassis */
memset(&chassis, 0, sizeof(struct lldpd_chassis));