Commit Graph

181 Commits

Author SHA1 Message Date
Roy Marples
26a52fe1a1 Use a dynamically sized buffer for reading route(4) messages on BSD
instead of a fixed 2048 byte buffer.
2016-09-01 14:37:48 +00:00
Roy Marples
b277b424d0 Add if_nametospec helper to decode and interface name such as bge1:2 into
device name, lun, ppa and driver name.
Use this function when discovering addresesses and when they arrive
via the kernel listening socket so they can be assigned to the correct
physical interface.

This change does also stop `dhcpcd eth0:1` working on Linux, but is needed
for basic Solaris support.
2016-07-18 10:53:45 +00:00
Roy Marples
b6f10046d8 Spit handlelink into smaller functions to increase read-ability. 2016-05-19 20:27:07 +00:00
Roy Marples
13247615a9 Move duid and ipv6 secret file reading code into a common function. 2016-05-06 16:01:54 +00:00
Roy Marples
7b8cfc534a Move packet buffer from dhcpcd context to a generic stack variable based on MTU_MAX. 2016-05-06 14:46:32 +00:00
Roy Marples
a67f0194df DHCP messages are really BOOTP so lets name the structure accordingly.
While here, stop making assumptions about the size of a DHCP packet based
on a fixed structure from a default MTU of 1500.
Instead, make it flexable and set the DHCP packet size to the interface MTU
less UDP and IP headers.
As a result, we need to know the size of the DHCP packet received
rather than just walking the old fixed DHCP message structure.

This makes Coverity happy about tainted scalar values when parsing DHCP
messages.
2016-05-06 13:26:41 +00:00
Roy Marples
9d3a9d1320 Remove useless range check. 2016-05-03 14:17:37 +00:00
Roy Marples
6b84d0e00a Fix a constant expression result. 2016-05-03 12:34:34 +00:00
Roy Marples
d306a8f2df Linux netlink nlmsg_pid is not process id - only the first socket opened
has that. So after opening the link socket, open a persistent route socket
and record the nlmsg_pid the kernel creates which is guaranteed unique
and won't clash with a process id which can then be ignored by testing it
directly and not that it's some large number.
2016-04-07 20:35:57 +00:00
Roy Marples
61f6ce0e11 Remove pidfile handling from dhcpcd and use pidfile_lock(3) from libutil
instead.
pidfile_lock(3) should be found in NetBSD 8.
Provide a compat shim, from an earlier implementation I wrote still based
around flock if not available on host OS.
2016-04-01 21:14:28 +00:00
Roy Marples
f5afdbdb72 Change IF_SSIDSIZE to IF_SSIDLEN to be more clear about it.
Store an extra char for a NULL terminator solely for debubgging purposes.
A better fix for [be2bbe6e37].
2016-02-11 16:06:26 +00:00
Roy Marples
598e6cc727 When activating an interface, bring up a basic config that does nothing.
Then apply enough of the config for the base protocol, passed via an
argument, to work.

This means that when a prefix is delegated to an inactive interface, it
won't magically start configuring IPv4 on it.
2016-02-04 21:42:14 +00:00
Roy Marples
b699cc3d5c Introduce IF_INACTIVE, IF_ACTIVE and IF_ACTIVE_USER flags. The intent is that IF_ACTIVE is an interface is active with a system config and IF_ACTIVE_USER with a user config. 2016-02-04 10:43:16 +00:00
Roy Marples
4507db9410 Fix delegation activating interfaces. 2016-01-20 19:08:12 +00:00
Roy Marples
64d13f9001 Updated in 2016 2016-01-06 14:06:40 +00:00
Roy Marples
3369605a5a If we are to add/delete/change a route but have not yet daemonised,
flag that we are to track the parent pid.
On successful route message, remember the sequence number.
Once daemonised, ignore messages from the parent pid until we find
the saved sequence number - at this point remove the flag to track parent pid.

This fixes an issue where we didn't correctly ignore messages we generated
before forking but catching them in the child process.
2016-01-06 10:54:36 +00:00
Roy Marples
98bdb38207 Set route/netlink seq number correctly. 2016-01-05 17:09:37 +00:00
Roy Marples
80e9033d45 Instead of maintaining a seperate list, instead mark each interface as active
dhcpcd will actively work on.
This will allow dhcpcd to move addresses around interfaces much more easily
as well.
2015-12-17 02:34:36 +00:00
Roy Marples
363c200a57 When parsing the routing table, create an interface for any interfaces dhcpcd
is not directly controling in ctx->oifaces.
This allows dhcpcd to manipulate the correct route at all times.

Fixes [ebdb4b447a].
2015-12-17 00:25:03 +00:00
Roy Marples
57498a0821 Open sockets once instead of open/close each for each ioctl. 2015-08-06 13:07:15 +00:00
Roy Marples
1b34ac49dd When dropping IPv4LL state, remove the address and rebuild routes before
calling dhcpcd-run-hooks.
Ensure that the IPv4LL random state is only used when picking addresses
and the original state is restored.
2015-07-24 20:47:08 +00:00
Roy Marples
ba251d82a5 Move ARP state out of DHCP. 2015-06-19 14:01:25 +00:00
Roy Marples
accc0bb871 Stop making IPv4LL into a DHCP lease and treat it independantly from any
DHCP lease.
This allows us to manage IPv4LL and DHCP at the same time a lot easier.
2015-06-12 19:21:32 +00:00
Roy Marples
5b1f21d131 Remove if_oneup and replace with if_afwaited and af_waited.
If present, they will show the address family waiting for.
2015-06-09 19:47:53 +00:00
Roy Marples
17db9819bc Fix compile on FreeBSD 2015-05-15 21:08:14 +00:00
Roy Marples
2be15e8895 Handle ND options in the same way we handle DHCP and DHCPv6 options. 2015-05-14 19:46:21 +00:00
Roy Marples
33b106d08c Allow waitip to work per interface.
Remove ipwaited from dhcpcd-run-hooks as it's now redundant.
Fixes [2095791c47].
2015-05-14 09:17:37 +00:00
Roy Marples
70207f79e9 setting signals should require an explicit len rather than NULL termination. 2015-05-12 23:47:25 +00:00
Roy Marples
023b012352 eloop_ctx -> eloop 2015-05-12 14:53:38 +00:00
Roy Marples
8d3d5b8221 Remove dhcpcd specifics from eloop to make more portable. 2015-05-09 10:09:34 +00:00
Roy Marples
069e2f284f syslogd(8) may not always be running before dhcpcd so any startup errors are
lost. Also, it's output with LOG_PERROR is ugly and LOG_PERROR isn't portable.

logger is a new function to solve the above which is identical to syslog(3)
but takes a dhcpcd_ctx for context so it functions in the RTEMS OS.
When writing to stdout/stderr or a given logfile, logger will convert %m
into the error string based on errno, just like syslog(3) does.
If your libc supports %m via printf, then define HAVE_PRINTF_M to remove
a fair chunk of code. There is no way of working out if your libc supports
this, especially in cross-compiled environment.
If the logfile is rotated, send dhcpcd a SIGUSR2 and the logfile will be
re-opened.

This does add about an exta 4K on 64-bit platforms so for size constraints
this can be compiled out by defining USE_LOGFILE to 0.
2015-03-17 23:46:38 +00:00
Roy Marples
c04f00c975 Improve pseudo interface handling. 2015-03-14 11:06:19 +00:00
Roy Marples
8c3d363e8b Support kqueue(2). 2015-03-04 15:47:04 +00:00
Roy Marples
4d71774dba Stop using link_addr(3).
Instead just set the sdl_index to specify which interface the route is for.
2015-02-27 14:21:01 +00:00
Roy Marples
a19fe49202 After adding an address load the kernel routing table for the interface.
When routes are rebuilt try not to remove any existing routes if they
don't need changing.
2015-02-26 13:22:41 +00:00
Roy Marples
ff4df8e09a Move the pidfile into the dhcpcd context.
When dumping a lease by filename, store the filename in the pidfile.
Fixes an issue where the filename overflows the interface name size.
2015-02-20 08:28:04 +00:00
Roy Marples
91dbca7a9c Fix Linux define. 2015-02-08 12:57:38 +00:00
Roy Marples
16f1b54cd4 For Linux, keep the alias on the interface so we don't have to guess
all the time.
2015-01-22 20:10:18 +00:00
Roy Marples
f9584c9506 Update copyrights to 2015. 2015-01-02 20:03:28 +00:00
Roy Marples
4d91c2e720 If allowinterfaces is not specified, allow all configured interfaces
to work, such as loopback and ppp.
2014-11-18 12:06:08 +00:00
Roy Marples
bc09d81de2 TAILQ is now inlcuded via config.h either via sys/queue.h or compat/queue.h.
This allows dhcpcd to compile on systems that do not even supply sys/queue.h,
such as the musl C library.

Thanks to Juan RP.
2014-11-10 16:56:32 +00:00
Roy Marples
40683854e3 Fix compile on FreeBSD 2014-10-14 11:29:50 +00:00
Roy Marples
b594ce0ddf For the time being, linkaddr is FreeBSD only. 2014-10-11 00:44:59 +00:00
Roy Marples
91692ea1c7 Improve FreeBSD support by using the actual AF_LINK address. 2014-10-10 20:35:13 +00:00
Roy Marples
559da5b05d Re-introduce our loop to poll interface flags when the interface does
not support link states, but this time ensure we don't call IFF_UP inside
the loop. This now works nicely with PPP interfaces on NetBSD at least.
2014-10-08 12:30:27 +00:00
Roy Marples
9b72ef1ca1 Add an unprivileged control socket so that normal users can
obtain dhcpcd running state.
2014-09-14 19:12:57 +00:00
Roy Marples
71650ebcde Allow SSIDs with non printable characters to be used in ssid selection in
dhcpcd.conf and generate more accurate stable private addresses.
2014-09-10 10:00:08 +00:00
Roy Marples
67ed6c5fdc Use the nl80211 interface on Linux to get the wireless SSID.
If this is not found in the system headers, fall back to assuming WEXT.
This has been done because the WEXT module has been marked as deprecated
for a while now and I'm getting bored of people asking me why their
wireless wasn't working. Bloated dhcpcd by another 600 bytes as a result.
2014-09-10 01:46:58 +00:00
Roy Marples
2f4d126e24 Add variables if_oneup and if_ipwaited so hook scripts know the overall state of dhcpcd better. 2014-09-07 19:03:41 +00:00
Roy Marples
923e118097 Implement a send queue for each control fd.
Only one call to write(2) should be performed for each POLLOUT check
via poll(2) so we should never see EAGAIN when writing to control
sockets ever again.
Each fd queue is limited to 100 entries so we don't OOM with badly
written control subscribers.
2014-09-05 12:28:05 +00:00