Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
networkd / sd-netlink: add support for address label #5529
Conversation
| + } | ||
| + | ||
| + if (k == 0xffffffffUL) { | ||
| + log_syntax(unit, LOG_ERR, filename, line, r, "Adresss label is invalid, ignoring: %s", rvalue); |
poettering
added
the
network
label
Mar 31, 2017
| + <term><varname>Label=</varname></term> | ||
| + <listitem> | ||
| + <para> The label for the prefix (an unsigned integer). 0xffffffff is reserved. This | ||
| + key is mandatory. </para> |
| + <varlistentry> | ||
| + <term><varname>Prefix=</varname></term> | ||
| + <listitem> | ||
| + <para>IPv6 prefix separated by a <literal>/</literal> character. |
poettering
Mar 31, 2017
Owner
hmm, i think this deserves a few more words, i.e. a brief explanation what an ipv6 prefix is (i.e. an address with a prefix length, separated by a slash)
| @@ -30,6 +30,7 @@ | ||
| #include <linux/ip.h> | ||
| #include <linux/if_link.h> | ||
| #include <linux/if_tunnel.h> | ||
| +#include <linux/if_addrlabel.h> |
| + default: | ||
| + return false; | ||
| + } | ||
| +} |
poettering
Apr 24, 2017
Owner
this can be simplified further: please write this as:
bool rtnl_message_type_is_addrlabel(uint16_t type) {
return IN_SET(type, RTM_NEWADDRLABEL, RTM_DELADDRLABEL, RTM_GETADDRLABEL);
}
In fact, you could even move this to the header, and make it "static inline" there...
| @@ -20,6 +20,7 @@ | ||
| #include <netinet/in.h> | ||
| #include <stdbool.h> | ||
| #include <unistd.h> | ||
| +#include <linux/if_addrlabel.h> |
| + | ||
| + r = sd_rtnl_message_addrlabel_set_prefixlen(req, label->prefixlen); | ||
| + if (r < 0) | ||
| + return log_error_errno(r, "Could not set prefixlen: %m"); |
| + if (r < 0) { | ||
| + log_syntax(unit, LOG_ERR, filename, line, r, "Address label is invalid, ignoring assignment: %s", prefix); | ||
| + return 0; | ||
| + } |
poettering
Mar 31, 2017
Owner
wouldn't it be time to add an "in_addr_prefix_from_string()" helper or so, which parses an address and its prefixlength in one go? it appears to me we have the same code for this in place at various cases...
(can happen in a later PR)
poettering
added
the
reviewed/needs-rework
label
Mar 31, 2017
|
updated . |
poettering
requested changes
Apr 24, 2017
Sorry for the late review! A couple of more notes:
| @@ -796,6 +796,33 @@ | ||
| </variablelist> | ||
| </refsect1> | ||
| + <refsect1> | ||
| + <title>[AddressLabel] Section Options</title> |
poettering
Apr 24, 2017
Owner
if this is an IPv6-only concept I think this should be prefixed with "IPv6", i.e. become [IPv6AddressLabel] or so in the config files.
| + <term><varname>Label=</varname></term> | ||
| + <listitem> | ||
| + <para> The label for the prefix (an unsigned integer) in the range 0 to 65,535 or 0 to 4,294,967,295. | ||
| + depending on 2 or 4 bytes. 0xffffffff is reserved. This key is mandatory.</para> |
poettering
Apr 24, 2017
Owner
what does that mean: "depending on 2 or 4 bytes"? Can't make sense of it.
If 0xffffffff is reserved, what does that mean? If it is not an acceptable value, then you need to filter it out, and hence document that the valid range for this is 0..4294967294 instead of 0..4294967295
| #include <linux/if.h> | ||
| #include <linux/ip.h> | ||
| +#include <linux/if_addr.h> | ||
| +#include <linux/if_addrlabel.h> | ||
| +#include <linux/if_bridge.h> |
poettering
Apr 24, 2017
Owner
why this reorder? We usually try to keep includes in alphabetical order, unless the kernel headers are borked and don't permit that
| + default: | ||
| + return false; | ||
| + } | ||
| +} |
poettering
Apr 24, 2017
Owner
this can be simplified further: please write this as:
bool rtnl_message_type_is_addrlabel(uint16_t type) {
return IN_SET(type, RTM_NEWADDRLABEL, RTM_DELADDRLABEL, RTM_GETADDRLABEL);
}
In fact, you could even move this to the header, and make it "static inline" there...
| + if (!addrlabel) | ||
| + return -ENOMEM; | ||
| + | ||
| + addrlabel->family = AF_UNSPEC; |
poettering
Apr 24, 2017
Owner
isn't this an IPv6 concept? if so, why do we have a "family" field here?
| +} | ||
| + | ||
| + | ||
| +int config_parse_address_label_prefix(const char *unit, |
| + if (r < 0) { | ||
| + log_syntax(unit, LOG_ERR, filename, line, r, "Prefix length is invalid, ignoring assignment: %s", e + 1); | ||
| + return 0; | ||
| + } |
poettering
Apr 24, 2017
Owner
I figure you should check the valid range of the prefix range here, after all it is 0..128 only iirc?
Maybe eben turn that parser into a seperate function parse_ip_prefixlen() or so, similar to parse_ip_port()?
| + | ||
| + int family; | ||
| + unsigned char prefixlen; | ||
| + unsigned label; |
poettering
Apr 24, 2017
Owner
hmm, the kernel expects this as uint32_t, no? I so, I think we should store it as such.
In general: I think ew should store the stuff in the type the kernel wants it as whenever we can. Often the kernel isn't entirely congruent on that, but let's still try to find the most appropriate types for things, and then stick to that across our code base.
poettering
requested changes
Apr 25, 2017
There's one forgotten replacement, looks ready otherwise
| + <title>[IPv6AddressLabel] Section Options</title> | ||
| + | ||
| + <para>An <literal>[IPv6AddressLabel]</literal> section accepts the | ||
| + following keys. Specify several <literal>[AddressLabel]</literal> |
| @@ -32,6 +32,10 @@ bool rtnl_message_type_is_addr(uint16_t type); | ||
| bool rtnl_message_type_is_route(uint16_t type); | ||
| bool rtnl_message_type_is_neigh(uint16_t type); | ||
| +static inline bool rtnl_message_type_is_addrlabel(uint16_t type) { | ||
| + return (IN_SET(type, RTM_NEWADDRLABEL, RTM_DELADDRLABEL, RTM_GETADDRLABEL)); |
|
Updated. |
|
lgtm |
poettering
added
good-to-merge/waiting-for-ci
and removed
reviewed/needs-rework
labels
Apr 25, 2017
|
Added address label to meson build system. |
| @@ -27,6 +27,8 @@ sources = files(''' | ||
| netdev/vxlan.h | ||
| netdev/geneve.c | ||
| netdev/geneve.h | ||
| + networkd-address-label.h | ||
| + networkd-address-label.c | ||
| networkd-address-pool.c |
mbiebl
Apr 26, 2017
Contributor
Just a minor nitpick: @keszybz has apparently used .c before .h file consistently in all meson build files, so I would use that sorting for consistencies sake. Also, a small typo in the commit message: s/labbel/label/
poettering
Apr 29, 2017
Owner
yes, we generally try to sort the file lists in Makefile.am these days.
ssahani
added some commits
Apr 25, 2017
|
updated . thanks ! |
ssahani commentedMar 3, 2017
IPv6 address labels are used for address selection; they are described in RFC 3484.
Precedence is managed by userspace, and only the label itself is stored in the kernel.
enp0s25.network
[sus@maximus label]$ ip addrlabel list