Commit Graph

113 Commits

Author SHA1 Message Date
Yu Watanabe 43e08c78c7 network: serialize/deserialize address family 2019-08-16 22:01:17 +09:00
Yu Watanabe 0aabccc87d network: refuse the case To= and From= are in different address family 2019-08-16 22:01:17 +09:00
Yu Watanabe 75a302b561 network: fix potential memleaks related to set_put() 2019-08-11 08:57:01 +09:00
Yu Watanabe 4ff296b024 network: make link enter failed state when a configuration fails
Some path of configuring address, route or etc., go to failed state, but
some do not. E.g., failure in address configuration which is provided by
DHCPv4 goes to failed state, but static address does not.

This is just for consistency. This should not change anything if
everything is fine.

This also voidify manager_rtnl_process_address().
2019-07-15 21:52:06 +09:00
Yu Watanabe b80a511b1b network: add missing entries in routing_policy_rule_{hash,compare}_func()
This also makes routing_policy_rule_get() or friends take
a RoutingPolicyRule object as an input.
2019-06-19 21:10:07 +09:00
Yu Watanabe 34715d8b03 network: make routing_policy_rule_get() require Manager 2019-06-18 13:10:23 +09:00
Yu Watanabe bafa964144 network: read link specific sysctl value
This introduce link_sysctl_ipv6_enabled() and replaces
manager_sysctl_ipv6_enabled() with it.
2019-06-15 14:56:42 +02:00
Yu Watanabe 7ef7e5509b network: ignore requested ipv6 routing policy rule when ipv6 is disabled by sysctl 2019-06-12 11:03:37 +09:00
Yu Watanabe 9ee92e7ed8 network: check stored object is euivalent to what we want to remove
When object A is stored in Manager::rules and B is in ::rules_foreign,
and compare function for the object cannot distinguish them,
then freeing A causes B to be removed from rules_foreign or vice versa.

Hopefully fixes #12731.
2019-06-06 00:45:46 +09:00
Yu Watanabe 9f08a578a8 network: remove unused argument in routing_policy_rule_configure() 2019-06-04 16:23:18 +09:00
Yu Watanabe d26267ddf1 network: fix double free on error path 2019-06-04 16:23:18 +09:00
Yu Watanabe fcbf4cb727 network: drop sections contain invalid settings in network_verify()
If e.g., an [Address] section has an invalid setting, then
previously assigned settings in the section is freed, and
only later settings are stored. That may cause partially broken
section stored in Network object.

This makes if an invalid setting is found, then set 'invalid' flag
instead of freeing it. And invalid sections are dropped later by
network_verify().
2019-03-13 11:59:18 +09:00
Yu Watanabe 031fb59a98 network: do not remove rule when it is requested by existing links
Otherwise, the first link once removes all saved rules in the foreign
rule database, and the second or later links create again...
2019-02-27 10:59:10 +09:00
Yu Watanabe 92cd00b974 network: remove routing policy rule from foreign rule database when it is removed
Previously, When the first link configures rules, it removes all saved
rules, which were configured by networkd previously, in the foreign rule
database, but the rules themselves are still in the database.
Thus, when the second or later link configures rules, it errnously
treats the rules already exist.
This is the root of issue #11280.

This removes rules from the foreign database when they are removed.

Fixes #11280.
2019-02-27 10:58:09 +09:00
Yu Watanabe 434094864c network: use netlink_message_append_{in_addr,sockaddr}_union() 2019-02-11 01:28:09 +09:00
Yu Watanabe d40b01e44b network: in_addr_is_null() may return negative errno
So, do not silently cast the returned value to boolean.
Exception is the case that family is trivially AF_INET or AF_INET6.
2019-02-11 01:28:09 +09:00
Susant Sahani 8b220643b1 networkd: RPDB rule - add support to configure inverted rule.
Closes #10706
2018-12-06 10:42:36 +05:30
Lennart Poettering 76b31bbb24
Merge pull request #10920 from yuwata/hashmap-destructor
hashmap: make hashmap_free() call destructors of key or value
2018-12-03 17:59:44 +01:00
Lennart Poettering a20f73221a
Merge pull request #10976 from yuwata/typesafe-netlink-call
netlink: introduce typesafe netlink functions
2018-12-03 17:55:00 +01:00
Yu Watanabe 7934dede41 network: drop unnecessary buffers 2018-12-03 12:15:26 +01:00
Yu Watanabe 7a08d314f2 tree-wide: make hash_ops typesafe 2018-12-02 07:53:27 +01:00
Yu Watanabe 302a796f5a network: use typesafe netlink_call_async() macro where applicable 2018-12-02 06:29:32 +01:00
Yu Watanabe 29889b4d24 network: set default callbacks for routing_policy_rule_configure() and routing_policy_rule_remove() 2018-12-02 06:23:45 +01:00
Yu Watanabe 3a269dcf51 network: make IPProtocol= also accept IP protocol number 2018-12-02 06:13:47 +01:00
Yu Watanabe 97f9df9e30 network: rename Protocol= in [RoutingPolicyRule] to IPProtocol= 2018-12-02 06:13:47 +01:00
Yu Watanabe da96ad5ae2 util: rename socket_protocol_{from,to}_name() to ip_protocol_{from,to}_name() 2018-12-02 05:48:27 +01:00
Susant Sahani 58a02e4c97 ip rule: fix clang warning.
```
[2/1209] Compiling C object 'src/network/src@network@@networkd-core@sta/networkd-routing-policy-rule.c.o'.
FAILED: src/network/src@network@@networkd-core@sta/networkd-routing-policy-rule.c.o
clang -Isrc/network/src@network@@networkd-core@sta -Isrc/network -I../src/network -Isrc/basic -I../src/basic -Isrc/shared -I../src/shared -Isrc/systemd -I../src/systemd -Isrc/journal -I../src/journal -Isrc/journal-remote -I../src/journal-remote -Isrc/nspawn -I../src/nspawn -Isrc/resolve -I../src/resolve -Isrc/timesync -I../src/timesync -I../src/time-wait-sync -Isrc/login -I../src/login -Isrc/udev -I../src/udev -Isrc/libudev -I../src/libudev -Isrc/core -I../src/core -I../src/libsystemd/sd-bus -I../src/libsystemd/sd-device -I../src/libsystemd/sd-event -I../src/libsystemd/sd-hwdb -I../src/libsystemd/sd-id128 -I../src/libsystemd/sd-netlink -I../src/libsystemd/sd-network -Isrc/libsystemd-network -I../src/libsystemd-network -I. -I../ -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=gnu99 -O0 -g -Wextra -Werror=undef -Wmissing-include-dirs -Wold-style-definition -Wpointer-arith -Winit-self -Wfloat-equal -Werror=missing-prototypes -Werror=implicit-function-declaration -Werror=missing-declarations -Werror=return-type -Werror=incompatible-pointer-types -Werror=format=2 -Wstrict-prototypes -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wstrict-aliasing=2 -Wwrite-strings -Werror=overflow -Werror=shift-count-overflow -Wdate-time -Wnested-externs -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-error=nonnull -ffast-math -fno-common -fdiagnostics-show-option -fno-strict-aliasing -fvisibility=hidden -fstack-protector -fstack-protector-strong --param=ssp-buffer-size=4 -fPIE -Wno-typedef-redefinition -Wno-gnu-variable-sized-type-not-at-end -Werror=shadow -include config.h -fPIC  -MD -MQ 'src/network/src@network@@networkd-core@sta/networkd-routing-policy-rule.c.o' -MF 'src/network/src@network@@networkd-core@sta/networkd-routing-policy-rule.c.o.d' -o 'src/network/src@network@@networkd-core@sta/networkd-routing-policy-rule.c.o' -c ../src/network/networkd-routing-policy-rule.c
../src/network/networkd-routing-policy-rule.c:1071:33: error: format specifies type 'unsigned char' but the argument has type '__u16' (aka 'unsigned short') [-Werror,-Wformat]
                                rule->sport.start, rule->sport.end);
                                ^~~~~~~~~~~~~~~~~
../src/network/networkd-routing-policy-rule.c:1071:52: error: format specifies type 'unsigned char' but the argument has type '__u16' (aka 'unsigned short') [-Werror,-Wformat]
                                rule->sport.start, rule->sport.end);
                                                   ^~~~~~~~~~~~~~~
../src/network/networkd-routing-policy-rule.c:1078:33: error: format specifies type 'unsigned char' but the argument has type '__u16' (aka 'unsigned short') [-Werror,-Wformat]
                                rule->dport.start, rule->dport.end);
                                ^~~~~~~~~~~~~~~~~
../src/network/networkd-routing-policy-rule.c:1078:52: error: format specifies type 'unsigned char' but the argument has type '__u16' (aka 'unsigned short') [-Werror,-Wformat]
                                rule->dport.start, rule->dport.end);
                                                   ^~~~~~~~~~~~~~~
4 errors generated.
```
2018-12-01 15:45:12 +01:00
Susant Sahani 926062f083 networkd: add support to configure ip rule port range and protocol.
Please see:

iprule: support for ip_proto, sport and dport match options
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f686f764682745daf6a93b0a6330ba42a961f858

Closes 10622
2018-11-28 20:06:28 +05:30
Yu Watanabe 3e5700428e network: allocate hashmap objects when they are required 2018-11-12 16:32:11 +09:00
Yu Watanabe 0f7f27694e network: fixes related to NetworkConfigSection
- Do not allocate NetworkConfigSection when filename == NULL
- set .network element before calling hashmap_put()
- Always free NetworkConfigSection in each object.
2018-11-12 16:32:11 +09:00
Yu Watanabe cb700a11d9 network: drop white space in log message 2018-11-01 23:41:29 +09:00
Yu Watanabe 0d7febd002 network: fix hash function for routing policy rule 2018-11-01 23:40:56 +09:00
Yu Watanabe e6b65ab760 network: fix return value of routing_policy_rule_get()
To distinguish source of rule.
2018-11-01 23:38:11 +09:00
Yu Watanabe a6276f0f3f network: fix memleak in routing policy
As set_put() may fail if input is duplicated.
2018-11-01 23:24:20 +09:00
Yu Watanabe 8190a388a6 sd-netlink: make sd_netlink_slot take its description 2018-10-16 18:42:23 +09:00
Yu Watanabe ee38400bba sd-netlink: introduce sd_netlink_slot 2018-10-15 18:10:04 +09:00
Yu Watanabe 1046bf9b1a network: add destroy callbacks for asynchronous netlink calls 2018-10-10 14:43:05 +09:00
Yu Watanabe 545bab1f0a sd-netlink: add destroy_callback argument to sd_netlink_call_async() 2018-10-10 14:43:05 +09:00
Zbigniew Jędrzejewski-Szmek b87dadcdb2 networkd-routing-policy-rule.c: drop unnecessary check
set_get() already does that.
2018-09-27 18:14:56 +02:00
Yu Watanabe eeab051b28 network: strdup iif and oif when creating RoutingPolicyRule object 2018-09-27 17:48:34 +09:00
Yu Watanabe 8e37fcbd21 network: use TAKE_PTR() at one more place 2018-09-27 17:48:34 +09:00
Yu Watanabe 9d66b48c7c network: use structured initializer at one more place 2018-09-27 17:48:34 +09:00
Yu Watanabe 51517f9e09 network: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Filipe Brandenburger a0edd02e43 tree-wide: Convert compare_func's to use CMP() macro wherever possible.
Looked for definitions of functions using the *_compare_func() suffix.

Tested:
- Unit tests passed (ninja -C build/ test)
- Installed this build and booted with it.
2018-08-06 19:26:35 -07:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Lennart Poettering 8e766630f0 tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.

In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.

Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.

Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.

Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
2018-03-22 20:21:42 +01:00
Susant Sahani 6964cf4558 networkd: routing policy rules rename Manager object m to manager. 2018-01-24 20:27:53 +05:30
Susant Sahani 36e6e28bce Fix #7704 and #7708. (#7712)
Init rule variable iif oif and to, from

While foreign rules are added the network part is not attached.
attach manager to rules and use it in routing_policy_rule_free.
2017-12-21 21:27:45 +09:00
Saran Tunyasuvunakool 7715629e9a networkd: Fix race condition in [RoutingPolicyRule] handling (#7615)
The routing policy rule setup logic is moved to the routes setup phase (rather than the addresses setup phase as it is now). Additionally, a call to `link_check_ready` is added to the routing policy rules setup handler. This prevents a race condition with the routes setup handler.

Also give each async handler its own message counter to prevent race conditions when logging successes.

Fixes: #7614
2017-12-12 16:25:36 +01:00
Zbigniew Jędrzejewski-Szmek 93f9da6e0a networkd: plug some memleaks in rule serialization/deserialization
This fixes the (mostly theoretical, since we're only parsing data that we write
ourselves) memleak when iif or oif is deserialized multiple times. Unfortunately
it does not fix the memleak when rule is freed, but that'll require a bigger
effort.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 9491f55f74 networkd: fix serialization of {Incoming,Outgoing}Interface
Let's just say that the code wasn't fully functional ;(

Since we only had the parser for serialization, and not the writer, we are
free to change the format. So while at it, let's use shorter names in the
serialization format that match the surrounding style.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek e4aca57df8 networkd: parse the rvalue, not the option name
:(
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 458d8ae302 networkd: move rule loading to a separate function
No functional change.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek cfc4529b01 networkd: unbork rule serialization
We'd write something like

RULE=from=250.250.240.0/24 to=(null)/0 tos=0 fwmark=0/0 table=12
RULE=from=250.250.250.0/24 to=(null)/0 tos=0 fwmark=0/0 table=11
2017-11-27 10:06:55 +00:00
Susant Sahani 762e2659b9 networkd: support incoming/outgoing device for rule matching (#7223)
Closes #7210
2017-11-21 11:51:50 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek ac097c841e Remove a bunch of unused variables
gcc does not warn about those, because of the _cleanup_ usage.
clang is smarter here.
2017-11-01 23:06:44 +01:00
Susant Sahani bce67bbee3 networkd: add support to configure IP Rule (#5725)
Routing Policy rule manipulates rules in the routing policy database control the
route selection algorithm.

This work supports to configure Rule
```
[RoutingPolicyRule]
TypeOfService=0x08
Table=7
From= 192.168.100.18

```

```
ip rule show
0:	from all lookup local
0:	from 192.168.100.18 tos 0x08 lookup 7
```

V2 changes:

1. Added logic to handle duplicate rules.
2. If rules are changed or deleted and networkd restarted
   then those are deleted when networkd restarts next time

V3:

1. Add parse_fwmark_fwmask
2017-09-14 21:51:39 +02:00