Commit Graph

16307 Commits

Author SHA1 Message Date
Beniamino Galvani
5aea82d383 libnm-core: ensure a IP tunnel connection specifies a remote IP
The IP of the remote endpoint is always required.
2016-11-09 17:45:34 +01:00
Beniamino Galvani
75127b1348 libnm: add missing device includes in NetworkManager.h
And also sort the setting includes alphabetically.
2016-11-09 17:45:34 +01:00
Lubomir Rintel
ecc6040cd8 merge: branch 'lr/ipv6-sharing'
https://bugzilla.gnome.org/show_bug.cgi?id=773777
2016-11-09 17:26:21 +01:00
Lubomir Rintel
ec12fcf6bf policy: delegate IPv6 configuration to ipv6.method=shared connections
The policy listens to signals from shared devices that need subnets and
requesting devices that provide prefixes. Whenever a subnet is needed,
policy tries to obtain a subnets from all of default6 device's prefixes.
When it fails to get any, it asks for more prefixes.

This way we make it possible for the delegating router to either
provide us with a /64 for each of our shared interfaces, or provide a
larger prefix that we could subnet.

The policy also updates the shared device's DNS information to keep it in sync
with the best requesting device changes.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
479ad5065e device: add IPv6 configuration delegation machinery
There's two parts of the configuration involved: the subnet addresses
and the DNS information.

For the addressing, the shared (downlink) device signals the policy needs for a
/64 subnet. When it gets one, it merges it into the autoconf configuration and
forwards to the NDisc. When more prefixes are needed, the (uplink) device asks
the DHCP manager and eventually signals delegation (reception) of a prefix.
The NMDevice only provides the mechanism, the actual subnetting needs to
be done by the NMPolicy.

For the DNS configuration, the shared device just copies it from
whichever device the policy deems suitable.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
4ec37b0364 dhcp-manager: add ability to specify the number of IPv6 prefixes to request
Utilizes RFC 3633 prefix option in role of requesting router to ask the
delegating router for prefixes. In future we'll be able to use the
addresses from those prefixes on ipv6.method=shared connections.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
7d195856cc dhcp-manager: move the options logging one level up
It will make sense to log the options even if we're not creating an
ip6_config (e.g. we got a prefix option, not an address).

Also, guard it with a logging enable conditional. That way we save
precious microseconds so that we'll feel less guilty about the demise of
mankind and universe.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
d74e5e45e5 manager: allow ipv6.medhod=shared connections 2016-11-09 17:23:32 +01:00
Lubomir Rintel
bda1e880de device: enable the IPv6 forwarding for shared connections
Useful when they have  internet-routable prefixes, consistent with IPv4.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
46e63e03af device: announce the managed IPv6 configuration with ipv6.method=shared
This esentially causes us to announce the prefixes of the addresses we
own and the DNS configuration.

Currently the only way to get the IPv6 configuration on such device is
manual setting in the connection. This will change with IPv6 prefix
delegation.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
0e6d194060 settings: allow method=shared with manual IPv6 configuration
IPv4 already allows setting an address, reusing its prefix for the network
it shares connection with. Additionally, for IPv6, the NDP can also share
the DNS configuration.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
611870347a ifcfg: add ability to save/restore ipv6.method=shared
We use IPV6_AUTOCONF=shared for this.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
6387856602 ndisc/lndp: add ability to announce the managed IPv6 configuration
Announce the prefixes and DNS configuration.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
425ce65ed0 ndisc: rename the config-changed signal
The ndisc config can now be changed by NMDevice as well when the NDisc
is in ROUTER mode. But what we're really interested in is when we
receive a new one from the outside.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
87624a6c50 ndisc: add logic for acting as a router 2016-11-09 17:23:32 +01:00
Lubomir Rintel
be6a0c7ce5 ndisc: move the logging deduplication into a macro
We'll want to use it elsewhere.
2016-11-09 17:23:32 +01:00
Lubomir Rintel
aed2106d3e ndisc: avoid calling start() multiple times
It hooks on ndp event callbacks and we'll end up in them being done
redundantly, leaking them on dispose and potentially even calling them.
2016-11-09 17:23:31 +01:00
Lubomir Rintel
679f8dfc7d ndisc/trivial: move nm_ndisc_set_iid upwards 2016-11-09 17:23:31 +01:00
Lubomir Rintel
c84313a2b7 ndisc/lndp: drop an unused variable 2016-11-09 17:16:48 +01:00
Lubomir Rintel
d09aea62ee ndisc/trivial: add a couple of comments of where do the constants come from 2016-11-09 17:16:48 +01:00
Lubomir Rintel
f69b6c038e device: the domain list from DNSSL is in fact a search list 2016-11-09 17:16:48 +01:00
Lubomir Rintel
44fca246a7 rdisc: rename to ndisc
We'll soon not only do the router discovery, but announce ourselves as a
reouter. "Neighbor discovery" sounds to be a more appropriate name for
the class than "Router discovery".
2016-11-09 17:16:47 +01:00
Lubomir Rintel
aa71dbc6c4 device: avoid a crash when L3 configuration fails
Don't call the IP check until at either IPv4 or IPv6 is actually
configured.
2016-11-09 15:06:21 +01:00
Lubomir Rintel
2e8f40f2c9 ifcfg-rh: avoid parsing the IPV6_PRIVACY string twice
This saves a couple of CPU cycles that would be better used for
something more useful, such as looking for transmissions from aliens.
2016-11-09 15:06:20 +01:00
Lubomir Rintel
577ba42e18 ifcfg-rh: get rid of an extra unused variable
This saves a couple of bits we could instead use to save memories of the
better days.
2016-11-09 15:06:20 +01:00
Lubomir Rintel
b49c194f84 linux: don't assume short write when the kernel ignores the trailing whitespace
Certain sysctls don't appreciate the final newline. That's completely
fine.

  17941 open("/proc/sys/net/ipv6/conf/eth2/forwarding", O_WRONLY|O_TRUNC) = 21
  17941 write(21, "1\n", 2)               = 1
2016-11-09 15:06:20 +01:00
Lubomir Rintel
7279ea1317 client: don't do g_criticals
Also, be a bit more careful about the layers of errors. Just don't do this:

   (process:236): nmcli-CRITICAL **: Error: Could not create NMClient object:
     Permissions request failed: Authorization check failed:
     The name org.freedesktop.PolicyKit1 was not provided by any .service files.
2016-11-09 15:06:20 +01:00
Lubomir Rintel
2dd384c817 utils: allow valid_lft=0 addresses
We use the lifetime of 0 to indicate permanent addresses while
DHCP uses that lifetime to indicate the addresses should be removed.
Use the presence of a timestamp to differentiate the two.

  dhclient[10867]: XMT: Rebind on wls1, interval 1030ms.
  dhclient[10867]: RCV: Reply message on wls1 from fe80::21e:8cff:feec:3ca2.
  NetworkManager[10481]: <info>  [1478020967.7634] dhcp6 (wls1):   valid_lft 0
  NetworkManager[10481]: <info>  [1478020967.7634] dhcp6 (wls1):   preferred_lft 0
  NetworkManager[10481]: <info>  [1478020967.7636] dhcp6 (wls1):   address fd25:d463:2f14::927
  NetworkManager[10481]: <info>  [1478020967.7636] dhcp6 (wls1):   nameserver 'fe80::21e:8cff:feec:3ca2'
  NetworkManager[10481]: <info>  [1478020967.7637] dhcp (wls1):   domain search 'venom.'
  NetworkManager[10481]: <info>  [1478020967.7637] dhcp6 (wls1): state changed unknown -> bound, event ID="fa💿2c:86|1478020967"
  NetworkManager[10481]: ((src/nm-core-utils.c:3521)): assertion '<dropped>' failed
2016-11-09 15:06:20 +01:00
Lubomir Rintel
ccb789edc2 device: ipv6.method=link-local does not need slaves
It already waits for carrier, which is sufficient -- DAD won't start
until there's carrier.
2016-11-09 15:06:20 +01:00
Lubomir Rintel
f708184d6f device: don't fail the device if IPv4 forwarding fails
Just fail the IPv4 method.

Plus improve some comments.
2016-11-09 15:06:20 +01:00
Lubomir Rintel
888d8f4b10 ifcfg-rh: add parentheses
The code is now perfect.
2016-11-09 15:06:20 +01:00
Lubomir Rintel
c2ceacb419 device: make some asserts less harsh
We're terrible programmers, but we don't need anyone to notice!
2016-11-09 15:06:20 +01:00
Lubomir Rintel
90beb7689a ifcfg-rh: drop an unused variable
Fixes: ecda08e1d1
2016-11-09 15:06:00 +01:00
Thomas Haller
e3928c8c5e ifcfg-rh: merge branch 'th/ifcfg-rh-shell-parsing-rh1369380'
https://bugzilla.redhat.com/show_bug.cgi?id=1369380
2016-11-09 12:21:18 +01:00
Thomas Haller
92712d3b31 ifcfg-rh: optimize checking character types during svEscape()
I don't think that the compiler is able to optimize
  strchr($SET_AS_STR, $CHAR)
Use NM_IN_SET() which expands to something that should be
easy for the compiler to optimize.
2016-11-09 12:07:35 +01:00
Thomas Haller
c5ac66d392 ifcfg-rh: restore previous behavior for svUnescape() stripping backslash from double-quoting
Now we could parse simple shell variable assignment properly, but old versions
of svEscape() wrote invalid double-quoted strings.

Add a hack to restore the broken behavior for that case only.
2016-11-09 12:07:35 +01:00
Thomas Haller
ecda08e1d1 ifcfg-rh/tests: some refactoring of tests
When introducing the macro _svGetValue_check() we replace
the call to svGetValueString() with svGetValue().

That makes a difference only when asserting against a %NULL
value. It's fair to assume that in such case we actually want
to assert that the value is unset, and not possibly empty.
2016-11-09 12:07:35 +01:00
Thomas Haller
01f0e35b69 ifcfg-rh: remove unused keyfile argument from writer_update_connection()
writer_update_connection() retrieves the keyfile name based on the ifcfg-name.
No need to pass it in separately, the argument was unused.
2016-11-09 12:07:35 +01:00
Thomas Haller
1b03b59ac0 ifcfg-rh: set errno in svGetValueInt64() in case key does not exist 2016-11-09 12:07:35 +01:00
Thomas Haller
264e519779 ifcfg-rh/tests: add test for handling multiple occurances of a variable
This tests commit "ifcfg-rh: handle multiple definitions of the same key".
2016-11-09 12:07:35 +01:00
Thomas Haller
c20b795547 ifcfg-rh: let reader create lineList in O(n) using g_list_prepend() and g_list_reverse() 2016-11-09 12:07:35 +01:00
Thomas Haller
eb307bbbb6 ifcfg-rh: let reader preserve the last line even without newline at end of file 2016-11-09 12:07:35 +01:00
Thomas Haller
82ccec22ca ifcfg-rh: modify svGetString() signature to avoid copying of temporary value
Modify the signature of svGetString() to allow getting the internal
string without cloning the string after unescaping.
2016-11-09 12:07:35 +01:00
Thomas Haller
08a22f2eea ifcfg-rh: avoid copying temporary value after unescaping
svUnescape() can return a pointer to the input argument
(if the input argument requires no unescaping or truncation).

That is actually the predominant case because most often we
store values that don't require escaping.

Optimize for that case.
2016-11-09 12:07:35 +01:00
Thomas Haller
9843da7ce5 ifcfg-rh: comment out invalid lines during svWriteFile
This is especially important because we don't support
line continuation. Thus, with

    FOO='val
      bar=3'
    wrong line
      F2=b
      F3='b
    XXX=adf'
      XXX2=val2
    '
we now write

    FOO=
    #NM: FOO='val
    bar=
    #NM:   bar=3'
    #NM: wrong line
      F2=b
    F3=
    #NM:   F3='b
    XXX=
    #NM: XXX=adf'
      XXX2=val2
    #NM: '

Basically, the writer will comment out any line that is

  - not all-whitespace
  - not a '#' comment (possibly proceeded by whitespace)
  - not a valid variable assignment

This avoids that writer writes lines that are not understood by
ifcfg-rh plugin, but interferes with initscripts. E.g.

  NAME=old-name'
  rm -rf /
  '

becomes

  NAME=new-name
  #NM: rm -rf /
  #NM: '
2016-11-09 12:07:35 +01:00
Thomas Haller
d8c465a3cd ifcfg-rh: fix svEscape() to properly handle double quoting
'\'', '~': must not be escaped with backslash.

Also, within double quotes the backslash escape character is only
removed before special caracters like '$' or '`'. Not in general.
Yes, it means that older versions of svEscape produced invalid escape
sequences that we now treat differently. But that is not realy
avoidable, it was a bug that needs to be fixed.
2016-11-09 12:07:34 +01:00
Thomas Haller
337fc582b2 ifcfg-rh: use macro _char_in_strset() for svEscape() 2016-11-09 12:07:34 +01:00
Thomas Haller
c55b7e866e ifcfg-rh: support storing newline '\n' and other ANSI control caracters
This is especially important for the team config JSON, which is expected
to contain newlines.

ANSI C quotation is bash specific, but initscripts already use #!/bin/bash.

Unfortunately, g_strescape() doesn't escape '\'' and can thus not be
used.

Also add a test that svEscape() and svUnescape() do a round-trip.

Not only consider \r and \n as candidates for ANSI C quotation, but all
ANSI control characters.
2016-11-09 12:07:34 +01:00
Thomas Haller
7b548fb9a8 ifcfg-rh: rework parsing of shell (svUnescape())
Better support parsing of shell. Now we support:

- combining values, like
    FOO=a"b"
    FOO=$'\n'b

- bash style ANSI C quotation ($''). This will allow us to properly
  handle newlines in string values.

- comments at the end of a line (after whitespace)
    FOO=val #comment
  Note that this is different from a # without space
    FOO=val#with#hashes

- trailing spaces are ignored like

    FOO=a[space]
    FOR=[space]

- history expansion via ! is not done (this is not new).

We don't support:

- line continuation like

    FOO='
    '
    FOO=a\
    b

- any form of shell expansion via $, ``.

    FOO="$a"

  Such values are recognized to name a variable FOO, but with an
  empty value, like

    FOO=%{nil}

  which is not the same as a valid empty value

    FOO=

- any other form of (unquoted) shell meta characters, like ; < > ( ).
  This especially means, that the command invocations are invalid, like

    ls -1
    LANG=C ls -1
    FOO1=a; FOO2=b

  This also means, that spaces immidiately after the assignment are invalid:

    FOO= val

Also, svUnescape() can now return %NULL to signal an invalid line like

    FOO='
2016-11-09 12:07:34 +01:00
Thomas Haller
f3c7d009b5 ifcfg-rh: handle multiple definitions of the same key
When

  - reading a key that is defined multiple times, accept
    the last occurrence.
  - when deleting such a key, delete all occurrences.
  - when overwriting such a key, overwrite the last occurrence
    and delete any previous definitions.
2016-11-09 12:07:34 +01:00