summaryrefslogtreecommitdiff
path: root/src/basic/parse-util.h
Commit message (Collapse)AuthorAgeFilesLines
* fd-util: introduce parse_fd()David Tardon2023-05-051-0/+1
| | | | | It's a simple wrapper for safe_atoi() that returns error if the parsed fd is < 0 .
* repart: Allow configuring sector sizeDaan De Meyer2023-01-171-0/+1
| | | | | | Let's allow users to configure the (logical) sector size of their image. This is required when building images for a 4k sector size disk on a 512b sector size host or vice-versa.
* parse-util: make safe_atou8() just a wrapper around safe_atou8_full()Lennart Poettering2022-09-051-1/+5
| | | | | As in the previous commit: it's just a wrapper around the same strtoul(), hence let's just share some more code.
* Revert NFTSet featureYu Watanabe2022-06-221-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | This reverts PR #22587 and its follow-up commit. More specifically, 2299b1cae32c1fb8911da0ce26efced68032f4f8 (partially), e176f855278d5098d3fecc5aa24ba702147d42e0, ceb46a31a01b3d3d1d6095d857e29ea214a2776b, and 51bb9076ab8c050bebb64db5035852385accda35. The PR was merged without final approval, and has several issues: - OSS fuzz reported issues in the conf parser, - It calls synchrnous netlink call, it should not be especially in PID1, - The importance of NFTSet for CGroup and DynamicUser may be questionable, at least, there was no justification PID1 should support it. - For networkd, it should be implemented with Request object, - There is no test for the feature. Fixes #23711. Fixes #23717. Fixes #23719. Fixes #23720. Fixes #23721. Fixes #23759.
* network: firewall integration with NFT setsTopi Miettinen2022-06-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New directives `NFTSet=`, `IPv4NFTSet=` and `IPv6NFTSet=` provide a method for integrating configuration of dynamic networks into firewall rules with NFT sets. /etc/systemd/network/eth.network ``` [DHCPv4] ... NFTSet=netdev:filter:eth_ipv4_address ``` ``` table netdev filter { set eth_ipv4_address { type ipv4_addr flags interval } chain eth_ingress { type filter hook ingress device "eth0" priority filter; policy drop; ip saddr != @eth_ipv4_address drop accept } } ``` ``` sudo nft list set netdev filter eth_ipv4_address table netdev filter { set eth_ipv4_address { type ipv4_addr flags interval elements = { 10.0.0.0/24 } } } ```
* basic: split out dev_t related calls into new devno-util.[ch]Lennart Poettering2022-04-131-1/+0
| | | | | | | | | | | | | | No actual code changes, just splitting out of some dev_t handling related calls from stat-util.[ch], they are quite a number already, and deserve their own module now I think. Also, try to settle on the name "devnum" as the name for the concept, instead of "devno" or "dev" or "devid". "devnum" is the name exported in udev APIs, hence probably best to stick to that. (this just renames a few symbols to "devum", local variables are left untouched, to make the patch not too invasive) No actual code changes.
* tree-wide: move `unsigned` to the start of type declarationFrantisek Sumsal2022-02-101-6/+6
| | | | | | | | | | | | | | | | | Even though ISO C11 doesn't mandate in which order the type specifiers should appear, having `unsigned` at the beginning of each type declaration feels more natural and, more importantly, it unbreaks Coccinelle, which has a hard time parsing `long unsigned` and others: ``` init_defs_builtins: /usr/lib64/coccinelle/standard.h init_defs: /home/mrc0mmand/repos/systemd/coccinelle/macros.h HANDLING: src/shared/mount-util.c : 1: strange type1, maybe because of weird order: long unsigned ``` Most of the codebase already "complies", so let's fix the remaining "offenders".
* parse-util: prefix load average macros with LOAD_AVG_Luca Boccassi2021-09-271-4/+4
| | | | Follow-up for #20839
* basic: delete loadavg.h copyLuca Boccassi2021-09-251-1/+8
| | | | | | | | | | loadavg.h is an internal header of the Linux source repository, and as such it is licensed as GPLv2-only, without syscall exception. We use it only for 4 macros, which are simply doing some math calculations that cannot thus be subject to copyright. Reimplement the same calculations in another internal header and delete loadavg.h from our tree.
* util: move percent/permille/permyriad parser into percent-util.[ch]Lennart Poettering2021-02-181-9/+0
| | | | | | | A good chunk of parse-util.[ch] has been about parsing parts per hundred/thousand/ten-thousand. Let's split that out into its own file. No code changes, just some shuffling around.
* parse-util: add permyriad parsingAnita Zhang2021-02-021-0/+3
|
* util: move parse_syscall_and_errno() to seccomp-util.cYu Watanabe2021-01-191-3/+0
| | | | | This makes parse-util.c independent of seccomp-util.c, which is located in src/shared.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* parse-util: add parse_loadavg_fixed_pointAnita Zhang2020-10-071-4/+16
|
* exec: Add kill action to system call filtersTopi Miettinen2020-09-151-0/+2
| | | | | | | | | | | | | | | | | Define explicit action "kill" for SystemCallErrorNumber=. In addition to errno code, allow specifying "kill" as action for SystemCallFilter=. --- v7: seccomp_parse_errno_or_action() returns -EINVAL if !HAVE_SECCOMP v6: use streq_ptr(), let errno_to_name() handle bad values, kill processes, init syscall_errno v5: actually use seccomp_errno_or_action_to_string(), don't fail bus unit parsing without seccomp v4: fix build without seccomp v3: drop log action v2: action -> number
* parse-util: allow tweaking how to parse integersLennart Poettering2020-06-051-0/+6
| | | | | | | This allows disabling a few alternative ways to decode integers formatted as strings, for safety reasons. See: #15991
* basic/parse-util: add safe_atoux64()Zbigniew Jędrzejewski-Szmek2020-04-091-1/+11
|
* network: tc: support Hierarchy Token Bucket (HTB)Yu Watanabe2020-03-021-2/+6
|
* network: add SuppressPrefixLength option to RoutingPolicyRule (#14736)Naïm Favier2020-02-031-0/+2
| | | Closes #14724.
* Resolve alternative ifnames wherever we would resolve an interface nameZbigniew Jędrzejewski-Szmek2020-01-121-1/+0
| | | | To keep the names manageable, "ifname_or_ifindex" is replaced by "interface".
* tree-wide: make parse_ifindex simply return the indexZbigniew Jędrzejewski-Szmek2020-01-111-2/+2
| | | | | | | | 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.
* util: introduce format_bytes_full()Yu Watanabe2019-06-191-3/+0
| | | | And move it into format-util.c.
* util: introduce PTR_TO_MODE and MODE_TO_PTR macrosYu Watanabe2019-05-301-2/+0
|
* util: introduce parse_ifindex_or_ifname()Yu Watanabe2019-05-291-0/+1
|
* networkd: add support to configure ip rule port range and protocol.Susant Sahani2018-11-281-0/+1
| | | | | | | | | 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
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-4/+0
| | | | | | | | | | | 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.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | 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.
* parse-util: add permille parser + testsMarc Kleine-Budde2018-06-091-0/+3
|
* basic: split parsing of the OOM score adjust value into its own function in ↵Lennart Poettering2018-05-171-0/+2
| | | | | | | | | | parse-util.c And port config_parse_exec_oom_score_adjust() over to use it. While we are at it, let's also fix config_parse_exec_oom_score_adjust() to accept an empty string for turning off OOM score adjustments set earlier.
* parse-util: add explicit parsers for MTU valuesLennart Poettering2018-04-261-0/+1
| | | | | | | | | We use MTUs all over the place, let's add a unified, strict parser for it, that takes MTU ranges into account. We already have parse_ifindex() close-by, hence this appears to be a natural addition, in particular as the range checking is not entirely trivial to do, as it depends on the protocol used.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | 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.
* parse-util: similar to safe_atou16_full() add safe_atou_full()Lennart Poettering2018-03-211-1/+6
| | | | | | What's good for uint16_t is also good for unsigned. This is preparation for: #8140
* parse-util: introduce safe_atou16_full()Lennart Poettering2018-03-211-3/+10
| | | | | | | safe_atou16_full() is like safe_atou16() but also takes a base parameter. safe_atou16() is then implemented as inline function on top of it, passing 0 as base. Similar safe_atoux16() is reworked as inline function too, with 16 as base.
* Fix format-truncation compile failure by typecasting USB IDs (#8250)Patrick Uiterwijk2018-02-221-0/+2
| | | | | | | | | | | | | | This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit int, and uses that for parsing USB device and vendor IDs. This fixes a compile error with gcc-8 because while we know that USB IDs are 2 bytes, the compiler does not know that. ../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output may be truncated writing between 4 and 8 bytes into a region of size between 2 and 6 [-Werror=format-truncation=] Signed-off-by: Adam Williamson <awilliam@redhat.com> Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* parse-util: add parse_errno() and parse_syscall_and_errno()Yu Watanabe2017-11-111-0/+2
|
* parse-util: introduce parse_dev() helperFranck Bui2017-06-061-0/+1
|
* core: introduce parse_ip_port (#4825)Susant Sahani2016-12-061-0/+2
| | | | | 1. Listed in TODO. 2. Tree wide replace safe_atou16 with parse_ip_port incase it's used for ports.
* util-lib: unify parsing of nice level valuesLennart Poettering2016-08-051-0/+2
| | | | | | | | This adds parse_nice() that parses a nice level and ensures it is in the right range, via a new nice_is_valid() helper. It then ports over a number of users to this. No functional changes.
* util-lib: add parse_percent_unbounded() for percentages over 100% (#3886)David Michael2016-08-041-0/+1
| | | This permits CPUQuota to accept greater values as documented.
* util-lib: introduce parse_percent() for parsing percent specificationsLennart Poettering2016-06-141-0/+2
| | | | And port a couple of users over to it.
* parse-util: fix conversion from size_t on s390 (#3147)Lubomir Rintel2016-04-291-1/+1
| | | | | | | On s390 size_t is an unsigned long, nor an unsigned int. They both are of the same size and can be cast to each other safely, but the compiler still seems unhappy about incompatible pointers. Fixes: 7c2da2ca8
* test-compress-benchmark: fix argument parsing on 32bitZbigniew Jędrzejewski-Szmek2016-04-021-0/+12
| | | | | | The patch is not minimal, but a function to parse size_t is probably going to come in handy in other places, so I think it's nicer to define a proper parsing function than to open-code the cast.
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* basic: include only what we useThomas Hindoe Paaboel Andersen2015-11-301-0/+3
| | | | | This is a cleaned up result of running iwyu but without forward declarations on src/basic.
* calendarspec: sub-second support, v3Hristo Venev2015-11-171-0/+2
|
* parse-util: introduce parse_ifindex() and make use of it everywhereLennart Poettering2015-11-031-0/+1
| | | | | We have enough places where we parse an ifindex, hence introduce a proper parsing function for it, that verifies all parameters.
* parse-util: Introduce new parse_range functionFilipe Brandenburger2015-10-271-0/+1
| | | | | | | This function will be useful for CPUAffinity settings that involve ranges of CPUs. Make it generic and include test coverage to prevent regressions.
* macro.h: move definition of MODE_INVALID to parse-util.hLennart Poettering2015-10-271-0/+2
|
* util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]Lennart Poettering2015-10-271-0/+88