+static int system_add_sit_tunnel(const char *name, const unsigned int link, struct blob_attr **tb)
+{
+ struct blob_attr *cur;
+ int ret = 0;
+
+ if (system_add_proto_tunnel(name, IPPROTO_IPV6, link, tb) < 0)
+ return -1;
+
+#ifdef SIOCADD6RD
+ if ((cur = tb[TUNNEL_ATTR_DATA])) {
+ struct blob_attr *tb_data[__SIXRD_DATA_ATTR_MAX];
+ unsigned int mask;
+ struct ip_tunnel_6rd p6;
+
+ blobmsg_parse(sixrd_data_attr_list.params, __SIXRD_DATA_ATTR_MAX, tb_data,
+ blobmsg_data(cur), blobmsg_len(cur));
+
+ memset(&p6, 0, sizeof(p6));
+
+ if ((cur = tb_data[SIXRD_DATA_PREFIX])) {
+ if (!parse_ip_and_netmask(AF_INET6, blobmsg_data(cur),
+ &p6.prefix, &mask) || mask > 128) {
+ ret = -EINVAL;
+ goto failure;
+ }
+
+ p6.prefixlen = mask;
+ }
+
+ if ((cur = tb[SIXRD_DATA_RELAY_PREFIX])) {
+ if (!parse_ip_and_netmask(AF_INET, blobmsg_data(cur),
+ &p6.relay_prefix, &mask) || mask > 32) {
+ ret = -EINVAL;
+ goto failure;
+ }
+
+ p6.relay_prefixlen = mask;
+ }
+
+ if (tunnel_ioctl(name, SIOCADD6RD, &p6) < 0) {
+ ret = -1;
+ goto failure;
+ }
+ }
+#endif
+
+ return ret;
+
+failure:
+ __system_del_ip_tunnel(name, tb);
+ return ret;
+}
+