Commit graph

51 commits

Author SHA1 Message Date
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Yu Watanabe ccea244865 in-addr-util: introduce in4_addr_is_local_multicast() 2020-09-17 00:04:22 +09:00
Yu Watanabe 5643cfc0d9 in-addr-util: introduce in6_addr_is_link_local_all_nodes() 2020-09-17 00:04:22 +09:00
Yu Watanabe badd49288d util: expose in6_addr_{hash,compare}_func() 2020-09-08 02:30:04 +09:00
Yu Watanabe c364cefb3a util: make in_addr_ifindex_to_string() an alias of in_addr_port_ifindex_name_to_string() 2020-09-04 20:05:58 +09:00
Yu Watanabe 3dbd8a15d5 util: use IN6_ARE_ADDR_EQUAL() macro 2020-07-22 19:55:15 +09:00
Yu Watanabe a723fb85da util: introduce in_addr_port_ifindex_name_from_string_auto() and in_addr_port_ifindex_name_to_string() 2020-07-21 03:55:34 +09:00
Andreas Rammhold 171f625b9e
in-addr-util: removed in_addr_prefix_next implementation
The in_addr_prefix_nth function does everything this function did and
more. We can substitute 100% of its users with the new function.
2020-05-26 12:41:22 +02:00
Andreas Rammhold 863b99cdd9
in-addr-util: introduce in_addr_prefix_nth 2020-05-26 12:35:49 +02:00
Zbigniew Jędrzejewski-Szmek 5c3fa98db6 util-lib: move things that parse ifnames to shared/
In subsequent commits, calls to if_nametoindex() will be replaced by a wrapper
that falls back to alternative name resolution over netlink. netlink support
requires libsystemd (for sd-netlink), and we don't want to add any functions
that require netlink in basic/. So stuff that calls if_nametoindex() for user
supplied interface names, and everything that depends on that, needs to be
moved.
2020-01-11 12:07:28 +01:00
Zbigniew Jędrzejewski-Szmek 597da51bae tree-wide: make parse_ifindex simply return the index
We don't need a seperate output parameter that is of type int.  glibc() says
that the type is "unsigned", but the kernel thinks it's "int".  And the
"alternative names" interface also uses ints. So let's standarize on ints,
since it's clearly not realisitic to have interface numbers in the upper half
of unsigned int range.
2020-01-11 12:06:08 +01:00
Yu Watanabe 6fa0524133
Merge pull request #12971 from yuwata/network-reassign-static-routes
network: reassign static routes and process reply address messages
2019-07-12 09:36:16 +09:00
Lennart Poettering 66855de739 tree-wide: make use of errno_or_else() everywhere 2019-07-11 23:20:31 +02:00
Yu Watanabe 9a897e22d4 util: introduce in4_addr_equal() 2019-07-11 22:37:00 +09:00
Yu Watanabe 2968913e64 util: introduce in6_addr_hash_ops 2019-05-18 12:27:27 +09:00
Zbigniew Jędrzejewski-Szmek ca78ad1de9 headers: remove unneeded includes from util.h
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Yu Watanabe d9143dac3e util: introduce in_addr_prefix_to_string() 2019-03-04 23:45:07 +09:00
Yu Watanabe 81260be12e util: use _cleanup_ attributes 2019-03-04 23:45:07 +09:00
Yu Watanabe c5236acdd7 util: introduce in_addr_random_prefix() 2019-03-01 16:27:51 +09:00
Thomas Haller 072320eab0 dhcp: move filtering of bogus DNS/NTP addresses out of DHCP client
The DHCP client should not pre-filter addresses beyond what RFC
requires. If a client's user (like networkd) wishes to skip/filter
certain addresses, it's their responsibility.

The point of this is that the DHCP library does not hide/abstract
information that might be relevant for certain users. For example,
NetworkManager exposes DHCP options in its API. When doing that, the
options should be close to the actual lease.

This is related to commit d9ec2e632d
(dhcp4: filter bogus DNS/NTP server addresses silently).
2019-02-18 13:34:22 +01:00
Yu Watanabe 9e0fdc211b util: add a new mode for in_addr_prefix_from_string_auto_internal() which refuses address without prefixlen
This also drops in_addr_default_prefix_from_string(), as it is only
used by test-in-addr.
2019-01-29 07:35:17 +01:00
Thomas Haller 1a35985264 in-addr-util: fix undefined result for in4_addr_netmask_to_prefixlen(<0.0.0.0>)
u32ctz() was undefined for zero due to __builtin_ctz() [1].
Explicitly check for zero to make the behavior defined.

Note that this issue only affected in4_addr_netmask_to_prefixlen()
which is the only caller.

It may seem slightly odd, to return 32 (bits) for utz(0). But that
is what in4_addr_netmask_to_prefixlen() needs, and it probably makes
the most sense here.

[1] https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

Fixes: ba91431154
2018-12-14 11:15:36 +01:00
Yu Watanabe 7a08d314f2 tree-wide: make hash_ops typesafe 2018-12-02 07:53:27 +01:00
Yu Watanabe c6d8bbb66e
in-addr-util: make in_addr_default_prefix_from_string() or friend set 0 to prefixlen when family == AF_INET6 (#10665)
Follow-up for a4798d4e6d.

Fixes #10662.
2018-11-07 15:31:26 +09:00
Yu Watanabe a4798d4e6d util: introduce in_addr_default_prefix_from_string() and friends
It is similar to in_addr_prefix_from_string() but it determines
the prefix length from address if it is not specified.
2018-11-05 16:46:26 +09:00
Yu Watanabe 67944f5c26 util: use strndup() instead of strndupa()
As the input string may be comes from command line or config files.
2018-11-05 16:46:00 +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
Yu Watanabe 2357724699 basic: use FAMILY_ADDRESS_SIZE() macro in hash_ops for in_addr_data 2018-08-02 17:07:25 +09:00
Yu Watanabe 6c39e02609 basic: introduce in_addr_data_hash_ops 2018-07-31 15:45:38 +09:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +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
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
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
Lennart Poettering 1274b6c687 ip-address-access: minimize IP address lists
Let's drop redundant items from the IP address list after parsing. Let's
also mask out redundant bits hidden by the prefixlength.
2017-09-22 15:24:55 +02:00
Lennart Poettering f4912f3a74 in-addr-util: add new helper call in_addr_prefix_from_string_auto()
This is much like in_addr_prefix_from_string(), but automatically
determines whether IPv4 or IPv6 addresses are specified. Also adds a
test for it.
2017-09-22 15:24:54 +02:00
Lennart Poettering 4e2d527361 in-addr-util: prefix return parameters with ret_ 2017-09-22 15:24:54 +02:00
Lennart Poettering 5a941f5f21 in-addr-util: be more systematic with naming our functions
Let's rename all our functions that process IPv4 in_addr structures
in4_addr_xyz(), following the already establishing naming logic for
this.

Leave the in_addr_xyz() prefix for functions that process the IPv4/IPv6
in_addr_union union instead.
2017-09-22 15:24:54 +02:00
Susant Sahani f7bf1abef9 socket-util: add parse_ip_prefix (#5867)
networkd: replace parse prefix with generic in_addr_prefix_from_string
2017-05-05 20:04:07 -04:00
Susant Sahani 85257f48be socket-util: introduce in_addr_is_multicast
This patch add support to test whether a internet
address is multicast or not.
2017-02-24 15:42:59 +05:30
Lennart Poettering fd18634de4 basic: make sure in_addr_from_string() can take NULL arguments
This way, we can use it for validating IP address strings.
2016-11-21 22:47:47 +01:00
Lennart Poettering fdedbe2676 basic: add explicit ipv4-specific in_addr classification calls
This adds in4_addr_is_localhost() and in4_addr_is_link_local() that only take
an IPv4 "struct in_addr", to match in_addr_is_localhost() and
in_addr_is_link_local() that that a "union in_addr_union".

This matches the existing in4_addr_is_null() call that already exists.

For IPv6 glibc already exports a set of macros, hence we don't add similar
functions in6_addr_is_localhost(). We also drop in6_addr_is_null() as
IN6_IS_ADDR_UNSPECIFIED() already provides that.
2016-11-21 22:47:47 +01:00
Martin Pitt 207c0b0ee3 Merge pull request #3432 from poettering/resolved-ll-ipv6
resolved: support IPv6 DNS servers on the local link
2016-06-09 10:18:07 +02:00
Lennart Poettering 34380032fb util: make it easier to check whether in_addr or in6_addr addresses are NULL 2016-06-06 19:59:09 +02:00
Lennart Poettering 2817157bb7 resolved: support IPv6 DNS servers on the local link
Make sure we can parse DNS server addresses that use the "zone id" syntax for
local link addresses, i.e. "fe80::c256:27ff:febb:12f%wlp3s0", when reading
/etc/resolv.conf.

Also make sure we spit this out correctly again when writing /etc/resolv.conf
and via the bus.

Fixes: #3359
2016-06-06 19:17:38 +02:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Zbigniew Jędrzejewski-Szmek f5e5c28f42 tree-wide: check if errno is greater then zero
gcc is confused by the common idiom of
  return errno ? -errno : -ESOMETHING
and thinks a positive value may be returned. Replace this condition
with errno > 0 to help gcc and avoid many spurious warnings. I filed
a gcc rfe a long time ago, but it hard to say if it will ever be
implemented [1].

Both conventions were used in the codebase, this change makes things
more consistent. This is a follow up to bcb161b023.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61846
2016-01-13 15:09:55 -05:00
Thomas Hindoe Paaboel Andersen 11c3a36649 basic: include only what we use
This is a cleaned up result of running iwyu but without forward
declarations on src/basic.
2015-11-30 21:51:03 +01:00
Mantas Mikulėnas db15affc05 resolved: fix typo in in_addr_is_localhost() 2015-11-27 08:36:37 +02:00
Lennart Poettering d830ebbdf6 resolved: never cache RRs originating from localhost
After all, this is likely a local DNS forwarder that caches anyway,
hence there's no point in caching twice.

Fixes #2038.
2015-11-27 00:46:51 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00