detach stdin/stdout/stderr from child processes, implement a separate logging pipe...
[project/netifd.git] / interface-ip.c
index d2e1461..a5efad5 100644 (file)
@@ -79,6 +79,78 @@ interface_update_proto_route(struct vlist_tree *tree,
        }
 }
 
        }
 }
 
+void
+interface_add_dns_server(struct interface *iface, const char *str)
+{
+       struct dns_server *s;
+
+       s = calloc(1, sizeof(*s));
+       s->af = AF_INET;
+       if (inet_pton(s->af, str, &s->addr.in))
+               goto add;
+
+       s->af = AF_INET6;
+       if (inet_pton(s->af, str, &s->addr.in))
+               goto add;
+
+       free(s);
+       return;
+
+add:
+       D(INTERFACE, "Add IPv%c DNS server: %s\n",
+         s->af == AF_INET6 ? '6' : '4', str);
+       list_add_tail(&s->list, &iface->proto_dns_servers);
+}
+
+void
+interface_add_dns_server_list(struct interface *iface, struct blob_attr *list)
+{
+       struct blob_attr *cur;
+       int rem;
+
+       blobmsg_for_each_attr(cur, list, rem) {
+               if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
+                       continue;
+
+               if (!blobmsg_check_attr(cur, NULL))
+                       continue;
+
+               interface_add_dns_server(iface, blobmsg_data(cur));
+       }
+}
+
+void
+interface_add_dns_search_domain(struct interface *iface, const char *str)
+{
+       struct dns_search_domain *s;
+       int len = strlen(str);
+
+       s = calloc(1, sizeof(*s) + len + 1);
+       if (!s)
+               return;
+
+       D(INTERFACE, "Add DNS search domain: %s\n", str);
+       memcpy(s->name, str, len);
+       list_add_tail(&s->list, &iface->proto_dns_search);
+}
+
+void
+interface_add_dns_search_list(struct interface *iface, struct blob_attr *list)
+{
+       struct blob_attr *cur;
+       int rem;
+
+       blobmsg_for_each_attr(cur, list, rem) {
+               if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
+                       continue;
+
+               if (!blobmsg_check_attr(cur, NULL))
+                       continue;
+
+               interface_add_dns_server(iface, blobmsg_data(cur));
+       }
+}
+
 static void
 interface_clear_dns_servers(struct interface *iface)
 {
 static void
 interface_clear_dns_servers(struct interface *iface)
 {
@@ -156,6 +228,21 @@ interface_write_resolv_conf(void)
 }
 
 void
 }
 
 void
+interface_ip_update_start(struct interface *iface)
+{
+       interface_clear_dns(iface);
+       vlist_update(&iface->proto_route);
+       vlist_update(&iface->proto_addr);
+}
+
+void
+interface_ip_update_complete(struct interface *iface)
+{
+       vlist_flush(&iface->proto_route);
+       vlist_flush(&iface->proto_addr);
+}
+
+void
 interface_ip_init(struct interface *iface)
 {
        vlist_init(&iface->proto_route, route_cmp, interface_update_proto_route,
 interface_ip_init(struct interface *iface)
 {
        vlist_init(&iface->proto_route, route_cmp, interface_update_proto_route,