summaryrefslogtreecommitdiff
path: root/accel-pppd/utils.c
AgeCommit message (Collapse)Author
2018-12-08utils: add IPv4 string parsing helpersGuillaume Nault
Define the IPv4 counterparts of u_ip6str() and u_parse_ip6cidr(). Also add the special u_parse_ip4range() which will be useful for parsing the [client-ip-range] section of accel-ppp.conf. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
2018-12-08utils: rework u_parse_ip4addr()Guillaume Nault
Redefine u_parse_ip4addr() to match the behaviour of other u_parse_*() functions: * Drop the err_msg parameter. * Return the number of bytes parsed instead of an error number. * Remove support for fancy IPv4 address notations. There is currently only one user of u_parse_ip4addr() (in iprange.c). Dropping the fancy IPv4 address representations is probably not going to harm anyone (quite the opposite as many users don't realise that leading 0 means octal and that plain integers can be considered IPv4 addresses). Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
2018-12-08utils: fix typo in description of u_parse_endstr()Guillaume Nault
u_parse_endstr() used to be u_parse_eos() in my internal repository. I forgot to update the documentation when I renamed it. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
2018-12-04utils: add string parsing helpersGuillaume Nault
Define parsers for IPv6 addresses and CIDR notations, unsigned integers, separators (variable number of space characters) and end of strings (variable number of spaces followed by '\0'). All of these functions work on constant string and return the number bytes parsed. If the input string doesn't have the expected format, these functions return 0 (no forward progress). Also implement a convenient wrapper around inet_ntop() that can be used easily in printf-like functions. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
2016-05-11iprange: rework ip range parsing functionsGuillaume Nault
The previous parsing functions had a few problems: * They did accept negative numbers in addresses (e.g. 192.0.2.-5). * They relied on C undefined behaviour for detecting /0 prefix length: "mask = htonl(~((1 << (32 - m)) - 1)" was wrong for m = 0, because that resulted in a left shift of 32 bits, on a 32 bit wide value (the right operand of a bitwise shift operator must be strictly smaller than the width of the promoted left operand). * They misinterpreted /32 prefixes as disable requests. In fact, due to the undefined behaviour described above, /0 and /32 prefix lengths were represented in the same way by parse1(), that is, with an iprange_t structure where ->begin == ->end. Therefore load_ranges() had no way to distinguish between them and did disable the module in both cases. This patch fixes these issues and brings the following improvements: * It uses getaddrinfo() to parse IP addresses, so it accept (almost) all IPv4 representations and is more easily extensible to IPv6 in the future. * It warns when the IP address used in CIDR notation is not the first address in the range (e.g. the first address of 192.0.2.1/24 is 192.0.2.0, not 192.0.2.1). * It doesn't _exit() on parsing failures, thus making the functions usable in an EV_CONFIG_RELOAD handler. While there, the unfinished tunnel_ranges code, which was already commented, has been removed. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
2014-06-03make IPv4 address to string conversions endian friendlyDmitry Kozlov
2013-04-17utils: Add random buffer generation functionGuillaume Nault
Define and export the u_randbuf() function that fills a buffer with random data. Convert L2TP's challenge generation code for using it. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
2013-02-06utils: Add function for strict str to int conversionGuillaume Nault
Define the u_readlong() function as a wrapper for strtol(). It performs stricter checks on the input value and let the caller specify an interval of acceptable values. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
2011-01-05rename accel-pptp to accel-pppDmitry Kozlov