diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-11-09 08:41:17 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-11-09 16:04:52 +0100 |
commit | dd1b187075485414fc83c0d5615d78f4484ba712 (patch) | |
tree | ead4be7ca792fa6eca518cf0db36f057a9deb4df /src/libsystemd-network/sd-radv.c | |
parent | sd-radv: router lifetime is uint16_t (diff) | |
download | systemd-dd1b187075485414fc83c0d5615d78f4484ba712.tar.xz systemd-dd1b187075485414fc83c0d5615d78f4484ba712.zip |
sd-radv: refuse to set preference except medium when router lifetime is zero
Diffstat (limited to 'src/libsystemd-network/sd-radv.c')
-rw-r--r-- | src/libsystemd-network/sd-radv.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c index 5ad89ae7de..8beb845d79 100644 --- a/src/libsystemd-network/sd-radv.c +++ b/src/libsystemd-network/sd-radv.c @@ -506,17 +506,20 @@ _public_ int sd_radv_set_other_information(sd_radv *ra, int other) { } _public_ int sd_radv_set_preference(sd_radv *ra, unsigned preference) { - int r = 0; - assert_return(ra, -EINVAL); assert_return(IN_SET(preference, SD_NDISC_PREFERENCE_LOW, SD_NDISC_PREFERENCE_MEDIUM, SD_NDISC_PREFERENCE_HIGH), -EINVAL); + /* RFC 4191, Section 2.2, "...If the Router Lifetime is zero, the preference value MUST be set + * to (00) by the sender..." */ + if (ra->lifetime == 0 && preference != SD_NDISC_PREFERENCE_MEDIUM) + return -EINVAL; + ra->flags = (ra->flags & ~(0x3 << 3)) | (preference << 3); - return r; + return 0; } _public_ int sd_radv_add_prefix(sd_radv *ra, sd_radv_prefix *p, int dynamic) { |