summaryrefslogtreecommitdiff
path: root/interface.c
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2015-01-12 20:07:55 +0100
committerSteven Barth <steven@midlink.org>2015-01-19 09:35:08 +0100
commit0b0e5e2fc5b065092644a5c4717c0a03a9098dcf (patch)
treed4bedf0e41e1a86faebe412fdf5abf656e8640b8 /interface.c
parente9d2014a478807c7fac0581bb4a145901a3f23b4 (diff)
downloadnetifd-0b0e5e2fc5b065092644a5c4717c0a03a9098dcf.tar.gz
netifd: Make interface identifier of delegated IPv6 address configurable
The ip6ifaceid UCI interface parameter makes the interface identifier of the delegated IPv6 address configurable. The parameter can have the following values: eui64 : Interface identifier is generated from the interface's MAC address random : Interface identifier is generated randomly fixed value : Interface identifier is a fixed value (eg ::1:2) The latter is the default value with a fixed value of ::1 for backwards compatibility Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> Signed-off-by: Joeri Barbarien <joeri.barbarien@gmail.com>
Diffstat (limited to 'interface.c')
-rw-r--r--interface.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/interface.c b/interface.c
index 83d7f94..4ab2431 100644
--- a/interface.c
+++ b/interface.c
@@ -43,6 +43,7 @@ enum {
IFACE_ATTR_IP6TABLE,
IFACE_ATTR_IP6CLASS,
IFACE_ATTR_DELEGATE,
+ IFACE_ATTR_IP6IFACEID,
IFACE_ATTR_FORCE_LINK,
IFACE_ATTR_MAX
};
@@ -63,6 +64,7 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
[IFACE_ATTR_IP6TABLE] = { .name = "ip6table", .type = BLOBMSG_TYPE_STRING },
[IFACE_ATTR_IP6CLASS] = { .name = "ip6class", .type = BLOBMSG_TYPE_ARRAY },
[IFACE_ATTR_DELEGATE] = { .name = "delegate", .type = BLOBMSG_TYPE_BOOL },
+ [IFACE_ATTR_IP6IFACEID] = { .name = "ip6ifaceid", .type = BLOBMSG_TYPE_STRING },
[IFACE_ATTR_FORCE_LINK] = { .name = "force_link", .type = BLOBMSG_TYPE_BOOL },
};
@@ -423,6 +425,10 @@ interface_merge_assignment_data(struct interface *old, struct interface *new)
{
bool changed = (old->assignment_hint != new->assignment_hint ||
old->assignment_length != new->assignment_length ||
+ old->assignment_iface_id_selection != new->assignment_iface_id_selection ||
+ (old->assignment_iface_id_selection == IFID_FIXED &&
+ memcmp(&old->assignment_fixed_iface_id, &new->assignment_fixed_iface_id,
+ sizeof(old->assignment_fixed_iface_id))) ||
list_empty(&old->assignment_classes) != list_empty(&new->assignment_classes));
struct interface_assignment_class *c;
@@ -455,6 +461,8 @@ interface_merge_assignment_data(struct interface *old, struct interface *new)
if (changed) {
old->assignment_hint = new->assignment_hint;
old->assignment_length = new->assignment_length;
+ old->assignment_iface_id_selection = new->assignment_iface_id_selection;
+ old->assignment_fixed_iface_id = new->assignment_fixed_iface_id;
interface_refresh_assignments(true);
}
}
@@ -703,6 +711,33 @@ interface_alloc(const char *name, struct blob_attr *config)
if ((cur = tb[IFACE_ATTR_IP6ASSIGN]))
iface->assignment_length = blobmsg_get_u32(cur);
+ /* defaults */
+ iface->assignment_iface_id_selection = IFID_FIXED;
+ iface->assignment_fixed_iface_id = in6addr_any;
+ iface->assignment_fixed_iface_id.s6_addr[15] = 1;
+
+ if ((cur = tb[IFACE_ATTR_IP6IFACEID])) {
+ const char *ifaceid = blobmsg_data(cur);
+ if (!strcmp(ifaceid, "random")) {
+ iface->assignment_iface_id_selection = IFID_RANDOM;
+ }
+ else if (!strcmp(ifaceid, "eui64")) {
+ iface->assignment_iface_id_selection = IFID_EUI64;
+ }
+ else {
+ /* we expect an IPv6 address with network id zero here -> fixed iface id
+ if we cannot parse -> revert to iface id 1 */
+ if (inet_pton(AF_INET6,ifaceid,&iface->assignment_fixed_iface_id) != 1 ||
+ iface->assignment_fixed_iface_id.s6_addr32[0] != 0 ||
+ iface->assignment_fixed_iface_id.s6_addr32[1] != 0) {
+ iface->assignment_fixed_iface_id = in6addr_any;
+ iface->assignment_fixed_iface_id.s6_addr[15] = 1;
+ netifd_log_message(L_WARNING, "Failed to parse ip6ifaceid for interface '%s', \
+ falling back to iface id 1.\n", iface->name);
+ }
+ }
+ }
+
iface->assignment_hint = -1;
if ((cur = tb[IFACE_ATTR_IP6HINT]))
iface->assignment_hint = strtol(blobmsg_get_string(cur), NULL, 16) &