Vincent Bernat [Sat, 22 Jun 2013 10:15:47 +0000 (12:15 +0200)]
bpf: on OpenBSD, invert the filter direction
From the manual page:
> Sets or gets the status of the `direction filter` flag. If
> non-zero, packets matching the specified direction (either
> `BPF_DIRECTION_IN` or `BPF_DIRECTION_OUT`) will be ignored.
Vincent Bernat [Fri, 21 Jun 2013 00:55:50 +0000 (02:55 +0200)]
build: use libbsd if available, also use `setproctitle()`
The monitor process will be titled "monitor", while the unprivileged
one will have the number of neighbors displayed. We provide an empty
fallback since this function is not essential.
On Linux, we expect `setproctitle()` to be available in `libbsd`. This
makes functions like `strlcpy()` and `fgetln()` also
available. However, the headers are `bsd/string.h`, so we either need
to declare the prototype or include those new headers (or use the
overlay system). A simple thing to do is to detect the usage of libbsd
and include the appropriate headers in this case.
Vincent Bernat [Thu, 20 Jun 2013 22:58:51 +0000 (00:58 +0200)]
lldpcli: `configure system interface pattern` instead of `configure lldp iface-pattern`
`configure system` will contain non-LLDP related stuff. Moreover, we
may add `configure system interface alias rewrite` to enable the
rewrite of ifalias (a long awaited feature).
Roopa Prabhu [Sat, 8 Jun 2013 08:30:43 +0000 (10:30 +0200)]
Fixed some boundary conditions in code that cleans
remote ports on ttl expiry.
Problem:
- ttl expires, cleanup check fails to detect that ttl has elapsed
and skips cleanup
- After that, The ttl timer set routine again ends up setting the timer to ttl
resulting in 2 * ttl time for the expired rport to get released
liblldpctl: fix infinite loop when user is reading fixed chunks
ISSUE:
_lldpctl_do_something() has the following loop for receiving a complete
message:
while ((bytes_needed = ctl_msg_recv_unserialized(...)) > 0) {
_lldpctl_needs(bytes_needed)
}
ctl_msg_recv_unserialized() processes the received message and determines
how many more bytes are needed. First time, it requests "header" worth of
bytes. Once it receives that, it looks at header->len to determine next
set of bytes.
_lldpctl_needs() calls the connection's receive() routine to receive a
chunk of data and copies that over the a buffer in the connection structure,
either by malloc/copy or realloc/memmove. This buffer is called
conn->input_buffer. conn->input_buffer_len stores how many bytes are
currently in conn->input_buffer.
The issue is with the following statement in _lldpctl_needs():
if (conn->input_buffer_len >= length) return 0;
where length is bytes_needed in the above illustration.
Suppose the message requires 16578 bytes. The connection's receive()
routine provided by the application reads in chunks of 1024 bytes.
With the above logic, the loop will execute successfully for 16 times
with the following resultant state:
conn->input_buffer_len = 16384
bytes_needed = 194
The above conditional statement in the beginning of _lldpctl_needs()
will cause it to return 0. ctl_msg_recv_unserialized() will keep asking
for 194 more bytes. The while() loop goes ad infinitum.
Vincent Bernat [Thu, 6 Jun 2013 21:54:23 +0000 (23:54 +0200)]
marshal: fix alignment issue when unserializing
On some archs (Sparc and sometimes ARM), unaligned access are
forbidden. Instead of copying unaligned structures with `memcpy()`, we
ensure that `struct marshal_serialized` structures are always
correctly aligned, including when they are serialized. This is done by
adding some padding before appending such a structure to a buffer.
Vincent Bernat [Thu, 6 Jun 2013 20:48:42 +0000 (22:48 +0200)]
marshal: don't declare serialize/unserialize helper for string
When using convenience library, this may lead to multiple definition
of this function. We are better off not defining it and using
`marshal_unserialize()` in `client.c` instead.
Vincent Bernat [Tue, 14 May 2013 07:23:21 +0000 (09:23 +0200)]
lib: keep space for new values in `lldpctl_key_t`
By inserting new values in the middle `lldpctl_key_t`, we break the
ABI of the library. To ensure future backward compatibility, we
introduce some space between each block. Unfortunately, this breaks
the current backward compatibility.
Vincent Bernat [Mon, 6 May 2013 19:31:42 +0000 (21:31 +0200)]
solaris: preliminary support
Basic functionalities are present. However, the interface support is
very poor. There is no way to detect bridges, VLAN and
aggregates. There is no MAC/PHY support. There is no detection of
wireless devices.
The code to detect IP forwarding is here but does not work inside the
chroot.
Vincent Bernat [Tue, 7 May 2013 20:05:01 +0000 (22:05 +0200)]
lib: use uint8_t instead of u_int8_t
`uint8_t` is part of C99 and comes from `stdint.h`. `u_int8_t` works
on many OS but not on some. There are many other occurrences but we
fix those here because this is the only public header.
Vincent Bernat [Fri, 3 May 2013 19:19:21 +0000 (21:19 +0200)]
netlink: fix IP address discovery
Since the switch to Netlink, the IP address was not advertised
correctly. Fix `netlink_send()`. Patch courtesy of Pradosh Mohapatra
from Cumulus Networks.
We can't request dh-autoreconf and have a buggy dh_installinit at the
same time. Let's remove this code about upstart. This only needs to be
fixed in backports.
Vincent Bernat [Sun, 31 Mar 2013 16:33:33 +0000 (18:33 +0200)]
lldpd: enforce TTL on remote chassis
Remote chassis were not expired in a timely manner. They were only
expired when a change happened on an interface. To fix this, we
maintain a timer that will be triggered when an interface is about to
expire. The timer is updated when a change happens and rescheduled
once it is run.
Vincent Bernat [Sun, 31 Mar 2013 10:59:09 +0000 (12:59 +0200)]
lldpd: limit the maximum of neighbors per port and per protocol
lldpd memory can be exhausted by adding too many neighbors. Moreover,
the communication with lldpcli is limited to a fixed number of
neighbors (packets may not exceed 1 << 19 in size). Therefore, we put
a hard limit to the number of neighbors accepted for a given port, for
a given protocol.
Vincent Bernat [Sat, 30 Mar 2013 14:42:51 +0000 (15:42 +0100)]
lib: fix sync_recv to handle segmentation
While it should not happen with Unix sockets, a read() can return only
partial data. Therefore, we continue to poll until we get the
appropriate length.
Vincent Bernat [Mon, 4 Feb 2013 07:38:08 +0000 (08:38 +0100)]
build: check if libevent as provided by pkg-config is working
If a user installs both libevent 2.0.x and libevent 1.4.x, pkg-config
may report libevent 2.0.x where it really is 1.4.x. The system is
broken in this case but we work-around this by using the shipped
libevent.
Vincent Bernat [Sun, 3 Feb 2013 08:38:19 +0000 (09:38 +0100)]
interfaces: whitelist an interface before being checking lower
Some whitelisted interfaces, like dsa, have a lower interface in
managed mode but we still want to advertise on it. Move the check for
lower interface after whitelisting.
Vincent Bernat [Tue, 29 Jan 2013 20:42:37 +0000 (21:42 +0100)]
libevent: produce smaller binaries when shipping libevent
When shipping libevent, we try to build smaller binaries by disabling
unneeded stuff (openssl, threading, malloc replacement, debug stuff)
and enabling `--gc-sections`. On various tests, this remove 80K from
lldpd size (stripping excluded).