Vincent Bernat [Thu, 11 Jul 2013 21:13:10 +0000 (23:13 +0200)]
priv: correctly declare `priv_cmd` type
`enum {} priv_cmd` was the declaration of a variable `priv_cmd` as an
anonymous enum. This is not what was expected. Instead, we want `enum
priv_cmd` to be a declaration of a named enum: `enum priv_cmd {}` (we
could also use `typedef enum {} priv_cmd`, but in lldpd, `typedef` is
seldomly used).
When `priv_cmd` was moved out of `priv.c`, its symbol was defined in
several objects. It seems that recent versions of gcc are able to cope
with that (because `priv_cmd` variable was not used, so it was
optimized out I think, not sure). However, some older versions like
4.2.1 complained about duplicate objects during the link phase.
Vincent Bernat [Tue, 2 Jul 2013 22:18:41 +0000 (00:18 +0200)]
interfaces: overwrite interface description with neighbor found
If no neighbor is found, interface name is `lldpd: no neighbor
found`. If one neighbor is found, this is `lldpd: connected to XXXXX`
and if several neighbors are found, this is `lldpd: XXX
neighbors`. Smart filter is used to count neighbors.
Currently, this is not possible to disable this. Works with FreeBSD,
OpenBSD and Linux.
Vincent Bernat [Tue, 2 Jul 2013 20:38:16 +0000 (22:38 +0200)]
privsep: separate OS specific code to dedicated files
Linux only stuff goes in `priv-linux.c`. This includes interface
handling, ethtool and ability to open files (which is not Linux
specific but only Linux requires this).
BSD stuff goes in `priv-bpf.c` since it only includes interface
handling.
Moreover, `privsep_fdpass.c` is merged into `privsep_io.c`, a new file
for almost everything about IO (read/write and passing FD). The global
`remote` object is put into this file.
This commit is mostly moving stuff around. This will enable the
ability to write interface aliases without putting too much #ifdef.
Vincent Bernat [Mon, 24 Jun 2013 23:25:04 +0000 (01:25 +0200)]
osx: don't try to build universal binaries
The use of multiple arch is not safe with autotools. I believe that
libevent compute some arch-dependent stuff at configure-time. Just say
in README.md that the package will only work for the same version of
OSX and the same architecture.
For the future:
- real universal binaries can be built by configuring and building
each arch into a separate directory, then merge the result with
`lipo`.
- building a package for an older versions of Max OS X can be done
by using `-mmacosx-version-min=10.6` and `-isysroot
/Developer/SDKs/MacOSX10.5.sdk` on both `CFLAGS` and `LDFLAGS`.
Vincent Bernat [Sun, 23 Jun 2013 21:26:05 +0000 (23:26 +0200)]
osx: add a target to build an OSX package
We use pkgbuild and productbuild (which seem to have superseded
PackageMaker). Those tools are shipped from OSX 10.6.6. There are only
a few examples of how to use those tools with daemons. You may also
look at Jenkins or ngircd.
See `README.md` for more information on how to invoke the build of a
package.
Vincent Bernat [Sun, 23 Jun 2013 12:26:53 +0000 (14:26 +0200)]
compat: include config.h in compat.h
Without this inclusion, no `HAVE_*` macro was defined. This was
triggered because with some libc, `strndup()` is defined by a macro
and therefore cannot be redefined as a function.
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.