]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-lease: add Root Path support
authorTom Gundersen <teg@jklm.no>
Mon, 3 Mar 2014 14:43:02 +0000 (15:43 +0100)
committerTom Gundersen <teg@jklm.no>
Mon, 3 Mar 2014 15:48:02 +0000 (16:48 +0100)
This is necessary when mounting /dev/nfs based on a DHCP lease.

src/libsystemd-network/dhcp-lease-internal.h
src/libsystemd-network/dhcp-protocol.h
src/libsystemd-network/sd-dhcp-lease.c
src/systemd/sd-dhcp-lease.h

index d12bcac2477502155c822c8ac70bb475620eac4b..1b157fd454d5325361a65cf64c172d807dd6d197 100644 (file)
@@ -46,6 +46,7 @@ struct sd_dhcp_lease {
         uint16_t mtu;
         char *domainname;
         char *hostname;
+        char *root_path;
 };
 
 int dhcp_lease_new(sd_dhcp_lease **ret);
index 81d36cef2793dda1b968f3fc53df893188a47323..9aa9618b44aa7a8876cf7b5163952f728edea64a 100644 (file)
@@ -105,6 +105,7 @@ enum {
         DHCP_OPTION_DOMAIN_NAME_SERVER          = 6,
         DHCP_OPTION_HOST_NAME                   = 12,
         DHCP_OPTION_DOMAIN_NAME                 = 15,
+        DHCP_OPTION_ROOT_PATH                   = 17,
         DHCP_OPTION_INTERFACE_MTU               = 26,
         DHCP_OPTION_NTP_SERVER                  = 42,
         DHCP_OPTION_REQUESTED_IP_ADDRESS        = 50,
index 0529b6d8fa3cb4f26bfac8aadd3a9253ba9b32c3..722dd0a419bae0c0f715ba2e0ecca36caad736d0 100644 (file)
@@ -96,6 +96,18 @@ int sd_dhcp_lease_get_hostname(sd_dhcp_lease *lease, const char **hostname) {
         return 0;
 }
 
+int sd_dhcp_lease_get_root_path(sd_dhcp_lease *lease, const char **root_path) {
+        assert_return(lease, -EINVAL);
+        assert_return(root_path, -EINVAL);
+
+        if (lease->root_path)
+                *root_path = lease->root_path;
+        else
+                return -ENOENT;
+
+        return 0;
+}
+
 int sd_dhcp_lease_get_router(sd_dhcp_lease *lease, struct in_addr *addr) {
         assert_return(lease, -EINVAL);
         assert_return(addr, -EINVAL);
@@ -212,6 +224,14 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
 
                 break;
 
+        case DHCP_OPTION_ROOT_PATH:
+                if (len >= 1) {
+                        free(lease->root_path);
+                        lease->root_path = strndup((const char *)option, len);
+                }
+
+                break;
+
         case DHCP_OPTION_RENEWAL_T1_TIME:
                 if (len == 4) {
                         memcpy(&val, option, 4);
@@ -323,6 +343,10 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
         if (r >= 0)
                 fprintf(f, "HOSTNAME=%s\n", string);
 
+        r = sd_dhcp_lease_get_root_path(lease, &string);
+        if (r >= 0)
+                fprintf(f, "ROOT_PATH=%s\n", string);
+
         r = 0;
 
         fflush(f);
@@ -361,6 +385,7 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
                            "MTU", &mtu,
                            "DOMAINNAME", &lease->domainname,
                            "HOSTNAME", &lease->hostname,
+                           "ROOT_PATH", &lease->root_path,
                            NULL);
         if (r < 0) {
                 if (r == -ENOENT)
index af687a673b8a53b89f290af312e44bd6b4a045d6..5b34b2a0709f8c8a5a91950ea5f6acb9a848a474 100644 (file)
@@ -37,5 +37,6 @@ int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, struct in_addr **addr, size_t *a
 int sd_dhcp_lease_get_mtu(sd_dhcp_lease *lease, uint16_t *mtu);
 int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname);
 int sd_dhcp_lease_get_hostname(sd_dhcp_lease *lease, const char **hostname);
+int sd_dhcp_lease_get_root_path(sd_dhcp_lease *lease, const char **root_path);
 
 #endif