Commit Graph

13 Commits

Author SHA1 Message Date
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