Commit graph

62 commits

Author SHA1 Message Date
Tom Gundersen eb7040ec50 udev: link-config - fix crash due to missing hwaddr
Reported by: master.nosferatu@gmail.com
2014-08-14 01:36:10 +02:00
Tom Gundersen 3c9b886068 networkd: link - split out dhcp4 handling 2014-08-12 20:42:59 +02:00
Tom Gundersen 68ba387706 udev: link-config - fix naming policy
Don't exit the name-finding loop when the 'kernel' policy is detected. We should
still find a fallback name if possible in the (very likely) case that no kernel
name is set at all.
2014-08-12 20:42:59 +02:00
Tom Gundersen 464cf22f17 udev: link-config - whitespace
Don't overflow 80 cols unneccessarily (we are ok with doing it when it improves readability, but that's not the case here).
2014-08-12 20:42:59 +02:00
Tom Gundersen 04b67d4925 udev: link_setup - respect kernel name assign policy
Newer kernels export meta-information about the origin of an ifname. Respect this
from the ifname rename logic. We do not rename any interfaces that was originally
named by userspace, nor once which have already been renamed from userspace.

Moreover, we optionally do not (the default) rename interfaces which the kernel
claims to have named in a predictable way.
2014-08-08 13:30:15 +02:00
Zbigniew Jędrzejewski-Szmek a2a5291b3f Reject invalid quoted strings
String which ended in an unfinished quote were accepted, potentially
with bad memory accesses.

Reject anything which ends in a unfished quote, or contains
non-whitespace characters right after the closing quote.

_FOREACH_WORD now returns the invalid character in *state. But this return
value is not checked anywhere yet.

Also, make 'word' and 'state' variables const pointers, and rename 'w'
to 'word' in various places. Things are easier to read if the same name
is used consistently.

mbiebl_> am I correct that something like this doesn't work
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-passwd "Unlock EncFS"'
mbiebl_> systemd seems to strip of the quotes
mbiebl_> systemctl status shows
mbiebl_> ExecStart=/usr/bin/encfs --extpass='/bin/systemd-ask-password Unlock EncFS  $RootDir $MountPoint
mbiebl_> which is pretty weird
2014-07-31 04:00:31 -04:00
Zbigniew Jędrzejewski-Szmek ed88bcfb7c Be more careful when checking for empty files
If we want to avoid reading a totally empty file, it seems better
to check after we have opened the file, not before.
2014-07-16 19:00:03 -04:00
Zbigniew Jędrzejewski-Szmek 36f822c4bd Let config_parse open file where applicable
Special care is needed so that we get an error message if the
file failed to parse, but not when it is missing. To avoid duplicating
the same error check in every caller, add an additional 'warn' boolean
to tell config_parse whether a message should be issued.
This makes things both shorter and more robust wrt. to error reporting.
2014-07-16 18:47:20 -04:00
Zbigniew Jędrzejewski-Szmek e9f3d2d508 Constify ConfigTableItem tables 2014-07-15 22:34:40 -04:00
Tom Gundersen a669ea9860 udev: link_config - ignore errors due to missing MAC address
Otherwis, we get misleading error messages on links with MACs.

Reported by Leonid Isaev.
2014-07-07 15:03:12 +02:00
Tom Gundersen 866ee36822 udev: net_setup_link - add a bit more logging 2014-07-03 11:00:02 +02:00
Andreas Henriksson f8a0bb5285 udev: fix invalid free() in enable_name_policy()
static bool enable_name_policy(...) in ./src/udev/net/link-config.c
calls proc_cmdline(...) to get "line" initialized, but
proc_cmdline(...) does not guarantee that atleast when both
conditions (detect_container(NULL) > 0) and
read_full_file(...) returned < 0.
2014-06-13 19:00:42 +02:00
Tom Gundersen edf029b7fd udev: link-config - fix mem leak
Reported by Kay.
2014-06-04 12:55:23 +02:00
Thomas Hindoe Paaboel Andersen 6e37cd2f4a silence warnings 2014-04-21 00:03:22 +02:00
Tom Gundersen 92d927f850 udev: link-config - treat any non-random mac address as persistent
The address may be already changed by other processes, or set
when creating the netdev from userspace.
2014-04-20 10:28:28 +02:00
Tom Gundersen 6916ec29af network: implement masking of .link, .network and .netdev files 2014-04-19 19:05:37 +02:00
Tom Gundersen 505f8da732 networkd: tie links to rtnl rather than udev
This essentially swaps the roles of rtnl and udev in networkd. After this
change libudev is only used for waiting for udev to initialize devices and
to get udev-specific information needed for some [Match] attributes.

This in particular simplifies the code in containers where udev is not really
useful, but also simplifies things and reduces round-trips in the non-container
case.
2014-04-19 18:41:58 +02:00
Zbigniew Jędrzejewski-Szmek ecb08ec6a5 Fix a few return codes in error paths 2014-04-05 00:55:19 -04:00
Tom Gundersen c6f7c917a1 libsystemd-network: move network-utils from src/shared
This does not belong in shared as it is mostly a detail of our networking subsystem.

Moreover, now we can use libudev here, which will simplify things.
2014-03-21 21:54:37 +01:00
Umut Tezduyar Lindskog b5db00e52e sd-ipv4ll/networkd: generate predictable addresses
Increase the chance of using the same link local address between reboots. The
pseudo random sequence of addresses we attempt is now seeded with data that is
very likely to stay the same between reboots, but at the same time be unique
to the specific machine/nic.

First we try to use the ID_NET_NAME_* data from the udev db combined with the
machin-id, which is guaranteed to be unique and persistent, if available. If
that is not possible (e.g., in containers where we don't have access to the
udev db) we fallback to using the MAC address of the interface, which is
guaranteed to be unique, and likely to be persistent.

[tomegun: three minor changes:

 - don't expose HASH_KEY in the siphash24 header
 - get rid of some compile-warnings (and some casts at the same time),
   by using uint8_t[8] rather than uint64_t in the api
 - added commit message]
2014-03-21 20:24:10 +01:00
Lennart Poettering 03e334a1c7 util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed,
and returns -1 unconditionally. This makes it easy to write lines like
this:

        fd = safe_close(fd);

Which will close an fd if it is open, and reset the fd variable
correctly.

By making use of this new scheme we can drop a > 200 lines of code that
was required to test for non-negative fds or to reset the closed fd
variable afterwards.
2014-03-18 19:31:34 +01:00
Daniel Mack 2c5859afec Make tables for DEFINE_STRING_TABLE_LOOKUP consistent
Bring some arrays that are used for DEFINE_STRING_TABLE_LOOKUP() in the
same order than the enums they reference.

Also, pass the corresponding _MAX value to the array initalizer where
appropriate.
2014-03-07 21:38:48 +01:00
Tom Gundersen 733f7a2c69 udev: net - allow MTU and Speed to be specified with units
This also changes the names to MTUBytes and BitsPerSecond, respectively. Notice
that the speed was mistakenly documented to be in bytes before this change.
2014-02-22 18:29:43 +01:00
Tom Gundersen bf175aafd2 net-util: match on the driver as exposed by ethtool if DRIVER not set
Also fix a copy-paste error that broke matching on interface name.
2014-02-21 22:59:29 +01:00
Tom Gundersen 847a8a5fed udev - link-setup - expose ID_NET_DRIVER
This is the same as shown by 'ethtool -i <ifname>', and is sometimes
set even though DRIVER is not.
2014-02-21 21:00:39 +01:00
Tom Gundersen edbb03e95a .network/.netdev/.link: allow to match on architecture 2014-02-21 16:05:02 +01:00
Tom Gundersen 2cc412b593 network/link: Match - filter on kernel cmdline, host and virt 2014-02-20 21:50:34 +01:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +01:00
Tom Gundersen e51660ae56 udev: net-config - allow interface names to be set from the hwdb 2014-02-19 23:29:51 +01:00
Tom Gundersen 9b1c2626ce net-match: fix Driver= match
It should match on the driver of the parent device.
2014-02-18 22:34:26 +01:00
Zbigniew Jędrzejewski-Szmek 2ad8416dd0 No need to canonicalize fixed paths 2014-01-08 22:15:27 -05:00
Lennart Poettering 9f6445e34a log: log_error() and friends add a newline after each line anyway, so avoid including it in the log strings 2013-12-24 16:39:37 +01:00
Lennart Poettering 9bf3b53533 shared: switch our hash table implementation over to SipHash
SipHash appears to be the new gold standard for hashing smaller strings
for hashtables these days, so let's make use of it.
2013-12-22 21:12:25 +01:00
Thomas Hindoe Paaboel Andersen 187dc6e554 udev link-config: add asserts to silence scan-build 2013-12-17 16:09:52 +01:00
Zbigniew Jędrzejewski-Szmek 2fd069b18e Fix a few resource leaks in error paths
https://bugzilla.redhat.com/show_bug.cgi?id=1043304
2013-12-15 17:49:28 -05:00
Thomas Hindoe Paaboel Andersen f168c27313 trivial coding style clean ups
- Add space between if/for and the opening parentheses
- Place the opening brace on same line as the function (not for  udev)

From the CODING_STYLE
Try to use this:
    void foo() {
    }
instead of this:
    void foo()
    {
    }
2013-12-03 22:27:45 +01:00
Tom Gundersen ff83aac364 Revert "link-config: match length for kernel commandline option"
This reverts commit da66338e17.

It is superseeded by 70f75a523b
2013-11-28 20:06:42 +01:00
Tom Gundersen d2df0d0ed3 udev: net_setup_link - don't use Description as Alias
Use Description only internally, and allow Alias to be set
as a separate option. For instance SNMP uses ifalias for
a specific purpose, so let's not write to it by default.
2013-11-25 14:53:56 +01:00
Dave Reisner 489124365d link-config: Fix typo in log_warning 2013-11-08 09:38:50 -05:00
Dave Reisner da66338e17 link-config: match length for kernel commandline option
This prevents enable_name_policy() from invariably returning false when
it matches a zero length string at the end of /proc/cmdline.
2013-11-08 09:25:19 -05:00
Lennart Poettering 74df0fca09 util: unify reading of /proc/cmdline
Instead of individually checking for containers in each user do this
once in a new call proc_cmdline() that read the file only if we are not
in a container.
2013-11-06 03:15:16 +01:00
Tom Gundersen b3e0131486 net-util: don't use libudev
Should fix linking with old toolchain.
2013-11-05 01:39:46 +01:00
Tom Gundersen be32eb9b7f net-config: start split out matching and parsing logic
Move this to src/share/net-util.c, so it can be used elsewhere.
2013-11-04 23:00:12 +01:00
Dave Reisner c50e28a38c link-config: support --enable-split-usr 2013-10-30 11:00:46 -04:00
Tom Gundersen 98a375f6d5 udev: config-link - one less log_info 2013-10-30 15:47:29 +01:00
Tom Gundersen f61942250a udev: link-config - less verbose logging
Also reinstate print to kmsg when renaming netif.
2013-10-30 15:36:04 +01:00
Tom Gundersen 3e137a1b9a udev: link-config - let udevd set the ifname 2013-10-30 15:36:04 +01:00
Tom Gundersen 3aeb37bc4f rtnl: move set_link_properties to rtnl-utils 2013-10-29 21:26:22 +01:00
Tom Gundersen 977085794d udev: link-config - split connection to sockets from loading of configs
We want to load the config in _init, but not connect to the sockets before we are forked.
2013-10-29 17:57:21 +01:00
Tom Gundersen 98dd77e86e rtnl: introduce default timeout
We set it to 10 secs (as we are only communicating with the kernel,
it seems we should be able to bail out sooner than sd-bus, which
uses 25).

When passing timout 0, the default is used, use this in link-config.
2013-10-29 16:37:30 +01:00